{"text": "module Implicits.Resolution.Infinite.Expressiveness where\n\nopen import Prelude hiding (Bool)\n\nopen import Data.Fin.Substitution\nopen import Data.List\nopen import Data.List.Any\nopen Membership-≡\n\nopen import Extensions.ListFirst\nopen import SystemF.Everything as F using ()\n\nopen import Implicits.Resolution.Ambiguous.Resolution as A\nopen import Implicits.Resolution.Deterministic.Resolution as D\nopen import Implicits.Resolution.Infinite.Resolution as I\nopen import Implicits.Syntax\nopen import Implicits.Substitutions\n\nmodule Deterministic⊆Infinite where\n\n complete : ∀ {ν} {a : Type ν} {Δ : ICtx ν} → Δ D.⊢ᵣ a → Δ I.⊢ᵣ a\n complete (r-simp x r↓a) = r-simp (proj₁ $ first⟶∈ x) (lem r↓a)\n where\n lem : ∀ {ν} {Δ : ICtx ν} {r a} → Δ D.⊢ r ↓ a → Δ I.⊢ r ↓ a\n lem (i-simp a) = i-simp a\n lem (i-iabs x₁ x₂) = i-iabs (complete x₁) (lem x₂)\n lem (i-tabs b x₁) = i-tabs b (lem x₁)\n complete (r-iabs ρ₁ x) = r-iabs (complete x)\n complete (r-tabs x) = r-tabs (complete x)\n\nmodule Deterministic⊂Infinite where\n\n open import Implicits.Resolution.Deterministic.Incomplete as Inc\n\n -- We gave an example of a query that the det rules could not resolve\n -- ((Int ⇒ Bool) List.∷ Bool List.∷ List.[]) ⊢ᵣ Bool\n -- Here we derive it for the Infinite rules, to prove that we are strictly\n -- more expressive\n infinite-can : Δ I.⊢ᵣ Bool\n infinite-can = r-simp (there (here refl)) p\n where\n p : Δ I.⊢ Bool ↓ tc 0\n p = i-simp (tc 0)\n\nmodule Infinite⇔Ambiguous\n (nf : ∀ {ν n} {Γ : F.Ctx ν n} {t a} → Γ F.⊢ t ∈ a → ∃ λ (t₂ : F.Term ν n) → Γ F.⊢ t₂ ⇑ a)\n where\n\n open import Implicits.Resolution.Ambiguous.SystemFEquiv hiding (equivalent)\n open import Implicits.Resolution.Infinite.NormalFormEquiv hiding (equivalent)\n open import Implicits.Resolution.Embedding.Lemmas\n open import Function.Equivalence\n\n sound : ∀ {ν} {a : Type ν} {Δ : ICtx ν} → Δ I.⊢ᵣ a → Δ A.⊢ᵣ a\n sound (r-simp x p) = lem p (r-ivar x)\n where\n lem : ∀ {ν} {Δ : ICtx ν} {a τ} → Δ I.⊢ a ↓ τ → Δ A.⊢ᵣ a → Δ A.⊢ᵣ (simpl τ)\n lem (i-simp τ) ⊢y = ⊢y\n lem (i-iabs ⊢a b↓τ) ⊢b = lem b↓τ (r-iapp ⊢b (sound ⊢a))\n lem (i-tabs b a) ⊢y = lem a (r-tapp b ⊢y)\n sound (r-iabs p) = r-iabs (sound p)\n sound (r-tabs p) = r-tabs (sound p)\n\n complete : ∀ {ν} {a : Type ν} {Δ : ICtx ν} → Δ A.⊢ᵣ a → Δ I.⊢ᵣ a\n complete {a = a} p = subst₂ (λ Δ r → Δ I.⊢ᵣ r) (ctx→← _) (tp→← a) (from-⇑ (proj₂ (nf (to-⊢ p))))\n\n equivalent : ∀ {ν} (Δ : ICtx ν) r → Δ I.⊢ᵣ r ⇔ Δ A.⊢ᵣ r\n equivalent Δ r = equivalence sound complete\n", "meta": {"hexsha": "e0127839af4282d15185e7cd1fe7ad5893765c32", "size": 2514, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Implicits/Resolution/Infinite/Expressiveness.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/Infinite/Expressiveness.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/Infinite/Expressiveness.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": 36.4347826087, "max_line_length": 98, "alphanum_fraction": 0.6332537788, "num_tokens": 995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419704455588, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.3999975276654782}} {"text": "open import Agda.Builtin.List\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.Reflection\nopen import Agda.Builtin.Unit\nopen import Common.Product\n\n{-# TERMINATING #-}\n\nLoop : Set\nLoop = Loop\n\npostulate\n loop : Loop\n\ndata Box (A : Set) : Set where\n box : A → Box A\n\n{-# TERMINATING #-}\n\nBoxed-loop : Set\nBoxed-loop = Box Boxed-loop\n\npostulate\n boxed-loop : Boxed-loop\n\ntest₁ : Boxed-loop\ntest₁ = quoteGoal g in boxed-loop\n\ntest₂ : Term\ntest₂ = quoteTerm Loop\n\ntest₃ : Loop → List (Arg Term)\ntest₃ _ = quoteContext\n\nmacro\n\n m₄ : Term → Term → TC ⊤\n m₄ _ hole = unify hole (def (quote ⊤) [])\n\ntest₄ : Set\ntest₄ = m₄ Loop\n\nmacro\n\n m₅ : Term → TC ⊤\n m₅ hole = bindTC (inferType (def (quote loop) [])) λ A →\n unify hole A\n\ntest₅ : Set\ntest₅ = m₅\n\nmacro\n\n m₆ : Term → TC ⊤\n m₆ hole =\n bindTC (checkType (def (quote Loop) []) (agda-sort (lit 0))) λ A →\n unify hole A\n\ntest₆ : Set\ntest₆ = m₆\n\nmacro\n\n m₇ : Term → TC ⊤\n m₇ hole =\n bindTC (quoteTC Loop) λ A →\n unify hole A\n\ntest₇ : Set\ntest₇ = m₇\n\nVec : Set → Nat → Set\nVec A zero = ⊤\nVec A (suc n) = A × Vec A n\n\nmacro\n\n m₈ : Term → TC ⊤\n m₈ hole =\n bindTC (reduce V) λ V →\n unify hole V\n where\n varg = arg (arg-info visible relevant)\n V = def (quote Vec) (varg (def (quote Boxed-loop) []) ∷\n varg (lit (nat 1)) ∷\n [])\n\ntest₈ : Set\ntest₈ = m₈\n", "meta": {"hexsha": "97eda2536f2db7d98c197c20c1af5f557ed7187b", "size": 1401, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Less-normalisation-in-reflection-machinery.agda", "max_stars_repo_name": "hborum/agda", "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_issues_repo_path": "test/Succeed/Less-normalisation-in-reflection-machinery.agda", "max_issues_repo_name": "hborum/agda", "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "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/Succeed/Less-normalisation-in-reflection-machinery.agda", "max_forks_repo_name": "hborum/agda", "max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "avg_line_length": 15.5666666667, "max_line_length": 70, "alphanum_fraction": 0.5895788722, "num_tokens": 503, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.399960953793424}} {"text": "{-# OPTIONS --safe --experimental-lossy-unification #-}\n\nmodule Cubical.Algebra.Group.EilenbergMacLane.Base where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Equiv.HalfAdjoint\nopen import Cubical.Foundations.GroupoidLaws renaming (assoc to ∙assoc)\nopen import Cubical.Foundations.Path\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Foundations.Pointed\nopen import Cubical.Foundations.Transport\n\nopen import Cubical.Data.Unit\nopen import Cubical.Data.Sigma\nopen import Cubical.Algebra.Group.Base\nopen import Cubical.Algebra.Group.Properties\nopen import Cubical.Homotopy.Connected\nopen import Cubical.HITs.Truncation as Trunc renaming (rec to trRec; elim to trElim)\nopen import Cubical.HITs.EilenbergMacLane1 hiding (elim)\nopen import Cubical.Algebra.AbGroup.Base\nopen import Cubical.Data.Empty\n renaming (rec to ⊥-rec) hiding (elim)\nopen import Cubical.HITs.Truncation\n renaming (elim to trElim ; rec to trRec ; rec2 to trRec2)\nopen import Cubical.Data.Nat hiding (_·_ ; elim)\nopen import Cubical.HITs.Susp\nopen import Cubical.Functions.Morphism\nopen import Cubical.Foundations.Path\n\nprivate\n variable ℓ ℓ' : Level\n\n _* = AbGroup→Group\n\nEM-raw : (G : AbGroup ℓ) (n : ℕ) → Type ℓ\nEM-raw G zero = fst G\nEM-raw G (suc zero) = EM₁ (G *)\nEM-raw G (suc (suc n)) = Susp (EM-raw G (suc n))\n\nptEM-raw : {n : ℕ} {G : AbGroup ℓ} → EM-raw G n\nptEM-raw {n = zero} {G = G} = AbGroupStr.0g (snd G)\nptEM-raw {n = suc zero} {G = G} = embase\nptEM-raw {n = suc (suc n)} {G = G} = north\n\nraw-elim : (G : AbGroup ℓ) (n : ℕ) {A : EM-raw G (suc n) → Type ℓ'}\n → ((x : _) → isOfHLevel (suc n) (A x) )\n → A ptEM-raw\n → (x : _) → A x\nraw-elim G zero hlev b = elimProp _ hlev b\nraw-elim G (suc n) hlev b north = b\nraw-elim G (suc n) {A = A} hlev b south = subst A (merid ptEM-raw) b\nraw-elim G (suc n) {A = A} hlev b (merid a i) = help a i\n where\n help : (a : _) → PathP (λ i → A (merid a i)) b (subst A (merid ptEM-raw) b)\n help = raw-elim G n (λ _ → isOfHLevelPathP' (suc n) (hlev _) _ _)\n λ i → transp (λ j → A (merid ptEM-raw (j ∧ i))) (~ i) b\n\nEM : (G : AbGroup ℓ) (n : ℕ) → Type ℓ\nEM G zero = EM-raw G zero\nEM G (suc zero) = EM-raw G 1\nEM G (suc (suc n)) = hLevelTrunc (4 + n) (EM-raw G (suc (suc n)))\n\n0ₖ : {G : AbGroup ℓ} (n : ℕ) → EM G n\n0ₖ {G = G} zero = AbGroupStr.0g (snd G)\n0ₖ (suc zero) = embase\n0ₖ (suc (suc n)) = ∣ ptEM-raw ∣\n\nEM∙ : (G : AbGroup ℓ) (n : ℕ) → Pointed ℓ\nEM∙ G n = EM G n , (0ₖ n)\n\nEM-raw∙ : (G : AbGroup ℓ) (n : ℕ) → Pointed ℓ\nEM-raw∙ G n = EM-raw G n , ptEM-raw\n\nhLevelEM : (G : AbGroup ℓ) (n : ℕ) → isOfHLevel (2 + n) (EM G n)\nhLevelEM G zero = AbGroupStr.is-set (snd G)\nhLevelEM G (suc zero) = emsquash\nhLevelEM G (suc (suc n)) = isOfHLevelTrunc (4 + n)\n\nEM-raw→EM : (G : AbGroup ℓ) (n : ℕ) → EM-raw G n → EM G n\nEM-raw→EM G zero x = x\nEM-raw→EM G (suc zero) x = x\nEM-raw→EM G (suc (suc n)) = ∣_∣\n\nelim : {G : AbGroup ℓ} (n : ℕ) {A : EM G n → Type ℓ'}\n → ((x : _) → isOfHLevel (2 + n) (A x))\n → ((x : EM-raw G n) → A (EM-raw→EM G n x))\n → (x : _) → A x\nelim zero hlev hyp x = hyp x\nelim (suc zero) hlev hyp x = hyp x\nelim (suc (suc n)) hlev hyp = trElim (λ _ → hlev _) hyp\n", "meta": {"hexsha": "f4d56a4991d64dae6d6cb9c640f91cbffe8d3422", "size": 3315, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/Group/EilenbergMacLane/Base.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_issues_repo_path": "Cubical/Algebra/Group/EilenbergMacLane/Base.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/Group/EilenbergMacLane/Base.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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.2659574468, "max_line_length": 84, "alphanum_fraction": 0.6443438914, "num_tokens": 1294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.6039318337259584, "lm_q1q2_score": 0.3997562961972469}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-}\nmodule Cubical.ZCohomology.Groups.Wedge where\n\nopen import Cubical.ZCohomology.Base\nopen import Cubical.ZCohomology.Properties\nopen import Cubical.ZCohomology.MayerVietorisUnreduced\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Pointed\nopen import Cubical.Foundations.Function\nopen import Cubical.HITs.Wedge\nopen import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to pRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap)\nopen import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∣_∣ to ∣_∣₁)\nopen import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2)\nopen import Cubical.Data.Nat\nopen import Cubical.Algebra.Group\n\nopen import Cubical.ZCohomology.Groups.Unit\nopen import Cubical.ZCohomology.Groups.Sn\n\nopen import Cubical.HITs.Pushout\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Homotopy.Connected\nopen import Cubical.HITs.Susp\nopen import Cubical.HITs.S1\nopen import Cubical.HITs.Sn\nopen import Cubical.Foundations.Equiv\n\n\nmodule _ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ') where\n module I = MV (typ A) (typ B) Unit (λ _ → pt A) (λ _ → pt B)\n\n Hⁿ-⋁ : (n : ℕ) → GroupIso (coHomGr (suc n) (A ⋁ B)) (×coHomGr (suc n) (typ A) (typ B))\n Hⁿ-⋁ zero = BijectionIsoToGroupIso bijIso\n where\n surj-helper : (x : coHom 0 Unit) → isInIm _ _ (I.Δ 0) x\n surj-helper =\n sElim (λ _ → isOfHLevelSuc 1 propTruncIsProp)\n λ f → ∣ (∣ (λ _ → f tt) ∣₂ , 0ₕ 0) , cong ∣_∣₂ (funExt λ _ → -rUnitₖ 0 (f tt)) ∣₁\n\n helper : (x : coHom 1 (A ⋁ B)) → isInIm _ _ (I.d 0) x → x ≡ 0ₕ 1\n helper x inim =\n pRec (setTruncIsSet _ _)\n (λ p → sym (snd p) ∙\n MV.Im-Δ⊂Ker-d _ _ Unit (λ _ → pt A) (λ _ → pt B) 0 (fst p) (surj-helper (fst p)))\n inim\n\n bijIso : BijectionIso (coHomGr 1 (A ⋁ B)) (×coHomGr 1 (typ A) (typ B))\n BijectionIso.map' bijIso = I.i 1\n BijectionIso.inj bijIso =\n sElim (λ _ → isSetΠ λ _ → isProp→isSet (setTruncIsSet _ _))\n λ f inker → helper ∣ f ∣₂ (I.Ker-i⊂Im-d 0 ∣ f ∣₂ inker)\n BijectionIso.surj bijIso p = I.Ker-Δ⊂Im-i 1 p (isContr→isProp (isContrHⁿ-Unit 0) _ _)\n\n Hⁿ-⋁ (suc n) = Iso+Hom→GrIso mainIso\n (sElim2 (λ _ _ → isOfHLevelPath 2 (isOfHLevel× 2 setTruncIsSet setTruncIsSet) _ _)\n λ _ _ → refl)\n where\n helpIso : ∀ {ℓ'''} {C : Type ℓ'''} → Iso (A ⋁ B → C) (Σ[ f ∈ (typ A → C) × (typ B → C) ] (fst f) (pt A) ≡ (snd f) (pt B))\n Iso.fun helpIso f = ((λ x → f (inl x)) , λ x → f (inr x)) , cong f (push tt)\n Iso.inv helpIso ((f , g) , p) (inl x) = f x\n Iso.inv helpIso ((f , g) , p) (inr x) = g x\n Iso.inv helpIso ((f , g) , p) (push a i) = p i\n Iso.rightInv helpIso ((f , g) , p) = ΣPathP (ΣPathP (refl , refl) , refl)\n Iso.leftInv helpIso f = funExt λ {(inl a) → refl ; (inr a) → refl ; (push a i) → refl}\n\n mainIso : Iso (coHom (2 + n) (A ⋁ B))\n (coHom (2 + n) (typ A) × coHom (2 + n) (typ B))\n mainIso = compIso (setTruncIso helpIso) (compIso theIso setTruncOfProdIso)\n where\n forget : ∥ (Σ[ f ∈ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ] (fst f) (pt A) ≡ (snd f) (pt B)) ∥₂\n → ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂\n forget = sMap (λ {((f , g) , _) → f , g})\n\n isEq : (f : ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂) → isContr (fiber forget f)\n isEq = sElim (λ _ → isOfHLevelSuc 1 isPropIsContr) (uncurry λ f g → helper f g (f (pt A)) (g (pt B)) refl refl)\n where\n helper : (f : (typ A → coHomK (2 + n))) (g : (typ B → coHomK (2 + n))) (x y : coHomK (2 + n))\n → f (pt A) ≡ x\n → g (pt B) ≡ y\n → isContr (fiber forget ∣ f , g ∣₂)\n helper f g = trElim2 (λ _ _ → isProp→isOfHLevelSuc (3 + n)\n (isPropΠ2 λ _ _ → isPropIsContr))\n (suspToPropElim2 (ptSn (suc n))\n (λ _ _ → isPropΠ2 λ _ _ → isPropIsContr)\n λ p q → (∣ (f , g) , (p ∙ sym q) ∣₂\n , refl)\n , uncurry (sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 (isOfHLevelΣ 2 setTruncIsSet λ _ → isOfHLevelPath 2 setTruncIsSet _ _) _ _)\n λ { ((f' , g') , id1) y →\n Σ≡Prop (λ _ → setTruncIsSet _ _)\n (pRec (setTruncIsSet _ _)\n (λ id2 → trRec (setTruncIsSet _ _)\n (λ pathp → cong ∣_∣₂ (ΣPathP ((sym id2) , pathp)))\n (isConnectedPathP 1\n {A = λ i → (fst (id2 (~ i)) (pt A) ≡ snd (id2 (~ i)) (pt B))}\n (isConnectedPath 2 (isConnectedSubtr 3 n\n (subst (λ m → isConnected m (coHomK (2 + n))) (+-comm 3 n)\n (isConnectedKn (suc n)))) _ _)\n (p ∙ sym q) id1 .fst))\n (Iso.fun PathIdTrunc₀Iso y))}))\n theIso : Iso ∥ (Σ[ f ∈ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ] (fst f) (pt A) ≡ (snd f) (pt B)) ∥₂\n ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂\n theIso = equivToIso (forget , record { equiv-proof = isEq })\n\n {- Alternative, less direct proof :\n vSES→GroupIso _ _\n (ses (isOfHLevelSuc 0 (isContrHⁿ-Unit n))\n (isOfHLevelSuc 0 (isContrHⁿ-Unit (suc n)))\n (I.d (suc n))\n (I.Δ (suc (suc n)))\n (I.i (suc (suc n)))\n (I.Ker-i⊂Im-d (suc n))\n (I.Ker-Δ⊂Im-i (suc (suc n))))\n -}\n\n wedgeConnected : ((x : typ A) → ∥ pt A ≡ x ∥) → ((x : typ B) → ∥ pt B ≡ x ∥) → (x : A ⋁ B) → ∥ inl (pt A) ≡ x ∥\n wedgeConnected conA conB =\n PushoutToProp (λ _ → propTruncIsProp)\n (λ a → pRec propTruncIsProp (λ p → ∣ cong inl p ∣₁) (conA a))\n λ b → pRec propTruncIsProp (λ p → ∣ push tt ∙ cong inr p ∣₁) (conB b)\n", "meta": {"hexsha": "21767844e61b004b4cb871a036c3c19cd59f3169", "size": 6559, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/ZCohomology/Groups/Wedge.agda", "max_stars_repo_name": "ayberkt/cubical", "max_stars_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f", "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": "Cubical/ZCohomology/Groups/Wedge.agda", "max_issues_repo_name": "ayberkt/cubical", "max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f", "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": "Cubical/ZCohomology/Groups/Wedge.agda", "max_forks_repo_name": "ayberkt/cubical", "max_forks_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f", "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": 53.325203252, "max_line_length": 154, "alphanum_fraction": 0.49595975, "num_tokens": 2314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.546738151984614, "lm_q1q2_score": 0.3996976162726675}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Substitution.Reflexivity {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.LogicalRelation.Properties\nopen import Definition.LogicalRelation.Substitution\n\nopen import Tools.Product\n\n\n-- Reflexivity of valid types.\nreflᵛ : ∀ {A Γ l}\n ([Γ] : ⊩ᵛ Γ)\n ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])\n → Γ ⊩ᵛ⟨ l ⟩ A ≡ A / [Γ] / [A]\nreflᵛ [Γ] [A] ⊢Δ [σ] =\n reflEq (proj₁ ([A] ⊢Δ [σ]))\n\n-- Reflexivity of valid terms.\nreflᵗᵛ : ∀ {A t Γ l}\n ([Γ] : ⊩ᵛ Γ)\n ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])\n ([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A])\n → Γ ⊩ᵛ⟨ l ⟩ t ≡ t ∷ A / [Γ] / [A]\nreflᵗᵛ [Γ] [A] [t] ⊢Δ [σ] =\n reflEqTerm (proj₁ ([A] ⊢Δ [σ])) (proj₁ ([t] ⊢Δ [σ]))\n", "meta": {"hexsha": "c57d92a875d6b3161416206d91b6a25b6289fbfc", "size": 795, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Reflexivity.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/LogicalRelation/Substitution/Reflexivity.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/LogicalRelation/Substitution/Reflexivity.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": 26.5, "max_line_length": 85, "alphanum_fraction": 0.5320754717, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7310585786300048, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.3996976162726673}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\n\nmodule Reflective where\n\n record ReflectiveSubuniverse {ℓ} : Type (lsucc ℓ) where\n field\n\n P : Type ℓ → Type ℓ\n R : Type ℓ → Type ℓ\n\n η : (A : Type ℓ) → A → R A\n\n -- replete : (A B : Type ℓ) → P A → A ≃ B → P B\n \n", "meta": {"hexsha": "536bb4c0703ef50be4afc2f2f6efddda5d2533ce", "size": 301, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/stash/modalities/Reflective.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/stash/modalities/Reflective.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/stash/modalities/Reflective.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 17.7058823529, "max_line_length": 57, "alphanum_fraction": 0.5282392027, "num_tokens": 107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.39962294356047645}} {"text": "module nodcap.NF.Typing where\n\nopen import Data.Nat as ℕ using (ℕ; suc; zero)\nopen import Data.Pos as ℕ⁺ using (ℕ⁺; suc; _+_)\nopen import Data.Environment\nopen import Data.List as L using (List; []; _∷_; _++_)\nopen import Data.List.Any as LA using (Any; here; there)\nopen import Data.Sum using (_⊎_; inj₁; inj₂)\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\nopen import nodcap.Base\nopen import nodcap.Typing as FF using (⊢_)\n\n\n-- Typing Rules.\n\ninfix 1 ⊢ⁿᶠ_\n\ndata ⊢ⁿᶠ_ : Environment → Set where\n\n send : {Γ Δ : Environment} {A B : Type} →\n\n ⊢ⁿᶠ A ∷ Γ → ⊢ⁿᶠ B ∷ Δ →\n -------------------\n ⊢ⁿᶠ A ⊗ B ∷ Γ ++ Δ\n\n recv : {Γ : Environment} {A B : Type} →\n\n ⊢ⁿᶠ A ∷ B ∷ Γ →\n -------------\n ⊢ⁿᶠ A ⅋ B ∷ Γ\n\n sel₁ : {Γ : Environment} {A B : Type} →\n\n ⊢ⁿᶠ A ∷ Γ →\n -----------\n ⊢ⁿᶠ A ⊕ B ∷ Γ\n\n sel₂ : {Γ : Environment} {A B : Type} →\n\n ⊢ⁿᶠ B ∷ Γ →\n -----------\n ⊢ⁿᶠ A ⊕ B ∷ Γ\n\n case : {Γ : Environment} {A B : Type} →\n\n ⊢ⁿᶠ A ∷ Γ → ⊢ⁿᶠ B ∷ Γ →\n -------------------\n ⊢ⁿᶠ A & B ∷ Γ\n\n halt :\n\n --------\n ⊢ⁿᶠ 𝟏 ∷ []\n\n wait : {Γ : Environment} →\n\n ⊢ⁿᶠ Γ →\n -------\n ⊢ⁿᶠ ⊥ ∷ Γ\n\n loop : {Γ : Environment} →\n\n -------\n ⊢ⁿᶠ ⊤ ∷ Γ\n\n mk?₁ : {Γ : Environment} {A : Type} →\n\n ⊢ⁿᶠ A ∷ Γ →\n ---------------------\n ⊢ⁿᶠ ?[ 1 ] A ∷ Γ\n\n mk!₁ : {Γ : Environment} {A : Type} →\n\n ⊢ⁿᶠ A ∷ Γ →\n ---------------------\n ⊢ⁿᶠ ![ 1 ] A ∷ Γ\n\n cont : {Γ : Environment} {A : Type} {m n : ℕ⁺} →\n\n ⊢ⁿᶠ ?[ m ] A ∷ ?[ n ] A ∷ Γ →\n ------------------------------\n ⊢ⁿᶠ ?[ m + n ] A ∷ Γ\n\n pool : {Γ Δ : Environment} {A : Type} {m n : ℕ⁺} →\n\n ⊢ⁿᶠ ![ m ] A ∷ Γ → ⊢ⁿᶠ ![ n ] A ∷ Δ →\n -------------------------------------\n ⊢ⁿᶠ ![ m + n ] A ∷ Γ ++ Δ\n\n exch : {Γ Δ : Environment} →\n\n Γ ∼[ bag ] Δ → ⊢ⁿᶠ Γ →\n --------------------\n ⊢ⁿᶠ Δ\n\nfromNF : {Γ : Environment} → ⊢ⁿᶠ Γ → ⊢ Γ\nfromNF (send x y) = FF.send (fromNF x) (fromNF y)\nfromNF (recv x) = FF.recv (fromNF x)\nfromNF (sel₁ x) = FF.sel₁ (fromNF x)\nfromNF (sel₂ x) = FF.sel₂ (fromNF x)\nfromNF (case x y) = FF.case (fromNF x) (fromNF y)\nfromNF halt = FF.halt\nfromNF (wait x) = FF.wait (fromNF x)\nfromNF loop = FF.loop\nfromNF (mk?₁ x) = FF.mk?₁ (fromNF x)\nfromNF (mk!₁ x) = FF.mk!₁ (fromNF x)\nfromNF (cont x) = FF.cont (fromNF x)\nfromNF (pool x y) = FF.pool (fromNF x) (fromNF y)\nfromNF (exch x y) = FF.exch x (fromNF y)\n\n-- -}\n-- -}\n-- -}\n-- -}\n-- -}\n", "meta": {"hexsha": "7d40b95801054a17b7348d60452431aabb4c50e8", "size": 2529, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/cpnd1/nodcap/NF/Typing.agda", "max_stars_repo_name": "wenkokke/nodcap", "max_stars_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-09-05T08:58:11.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-24T20:16:35.000Z", "max_issues_repo_path": "src/cpnd1/nodcap/NF/Typing.agda", "max_issues_repo_name": "pepijnkokke/nodcap", "max_issues_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2", "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/cpnd1/nodcap/NF/Typing.agda", "max_forks_repo_name": "pepijnkokke/nodcap", "max_forks_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-09-05T08:58:13.000Z", "max_forks_repo_forks_event_max_datetime": "2018-09-05T08:58:13.000Z", "avg_line_length": 21.8017241379, "max_line_length": 66, "alphanum_fraction": 0.4325820482, "num_tokens": 1077, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943712746406, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3995974932971484}} {"text": "\nrecord _×_ (A B : Set) : Set where\n constructor _,_\n field\n fst : A\n snd : B\n\nopen _×_\ninfixr 1 _,_\n\n_∩_ : {I : Set} → (I → Set) → (I → Set) → I → Set\nP ∩ Q = λ i → P i × Q i\n\nrecord Preorder : Set₁ where\n no-eta-equality\n field I : Set\n\ninfix 4 _∈_\n\npostulate\n Ty World Cxt : Set\n All : (P : Ty → Set) → Cxt → Set\n _∈_ : Ty → World → Set\n\nmodule Monotone (pre : Preorder) where\n open Preorder pre\n\n postulate\n Monotone : (I → Set) → Set\n\n instance\n postulate\n all-monotone : {Γ : Cxt} {C : Ty → I → Set}\n ⦃ w : ∀ {ty} → Monotone (C ty) ⦄ →\n Monotone (λ W → All (λ ty → C ty W) Γ)\n\nmodule Monad (pre : Preorder) (let open Preorder pre)\n (M : (I → Set) → I → Set) where\n postulate\n _>>=_ : ∀ {P Q W} → M P W → (∀ {W'} → P W' → M Q W') → M Q W\n\npostulate\n M : (World → Set) → World → Set\n Val : World → Set\n\npreorder : Preorder\npreorder .Preorder.I = World\n\nmodule Inner (Dummy : Set) where -- Succeeds if no Dummy\n\n private\n -- Succeeds if type is given\n pre : _ -- Preorder\n pre = preorder\n\n open Monotone pre\n open Monad pre M\n\n postulate\n R : World → Set\n\n instance\n any-monotone : ∀ {ty} → Monotone (ty ∈_)\n\n local : ∀ Γ {W} → R W × All (_∈ W) Γ → M Val W\n ^ : ∀ {Q : World → Set} ⦃ m : Monotone Q ⦄ → ∀ {W} → Q W → M (R ∩ Q) W\n\n eval-method : ∀ Γ {W} → All (_∈ W) Γ → M Val W\n eval-method Γ args =\n ^ args >>= local _ -- Succeeds if giving Γ for _\n", "meta": {"hexsha": "68bfaf8a71d7cd8e10be953ff0de8f0669724be1", "size": 1479, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue3177a.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/Succeed/Issue3177a.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/Succeed/Issue3177a.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": 20.8309859155, "max_line_length": 78, "alphanum_fraction": 0.5226504395, "num_tokens": 564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802370707283, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.39955358145021375}} {"text": "-- Displayed SIP\n{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.DStructures.Base where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Equiv.Properties\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Foundations.Path\nopen import Cubical.Foundations.SIP\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Relation.Binary\n\n\nprivate\n variable\n ℓ ℓ' ℓ'' ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓA ℓ≅A ℓB ℓ≅B ℓC ℓ≅C ℓ≅ᴰ : Level\n\n-- a univalent reflexive graph structure on a type\nrecord URGStr (A : Type ℓA) (ℓ≅A : Level) : Type (ℓ-max ℓA (ℓ-suc ℓ≅A)) where\n no-eta-equality\n constructor urgstr\n field\n _≅_ : Rel A A ℓ≅A\n ρ : isRefl _≅_\n uni : isUnivalent _≅_ ρ\n\n-- another constructor for URGStr that uses that if the\n-- relational singleton is contractible, the relation is univalent\nmake-𝒮 : {A : Type ℓA} {_≅_ : Rel A A ℓ≅A}\n (ρ : isRefl _≅_) (contrTotal : contrRelSingl _≅_)\n → URGStr A ℓ≅A\nmake-𝒮 {_≅_ = _≅_} _ _ .URGStr._≅_ = _≅_\nmake-𝒮 ρ _ .URGStr.ρ = ρ\nmake-𝒮 {_≅_ = _≅_} ρ contrTotal .URGStr.uni = contrRelSingl→isUnivalent _≅_ ρ contrTotal\n\nmodule _ where\n open URGStr\n η-URGStr : {A : Type ℓA} {ℓ≅A : Level}\n (𝒮-A : URGStr A ℓ≅A) → urgstr (_≅_ 𝒮-A) (ρ 𝒮-A) (uni 𝒮-A) ≡ 𝒮-A\n _≅_ (η-URGStr 𝒮-A i) = _≅_ 𝒮-A\n ρ (η-URGStr 𝒮-A i) = ρ 𝒮-A\n uni (η-URGStr 𝒮-A i) = uni 𝒮-A\n\n\n-- a displayed univalent reflexive graph structure over a URGStr on a type\nrecord URGStrᴰ {A : Type ℓA} (𝒮-A : URGStr A ℓ≅A)\n (B : A → Type ℓB) (ℓ≅ᴰ : Level) : Type (ℓ-max (ℓ-max (ℓ-max ℓA ℓB) ℓ≅A) (ℓ-suc ℓ≅ᴰ)) where\n no-eta-equality\n constructor urgstrᴰ\n open URGStr 𝒮-A\n\n field\n _≅ᴰ⟨_⟩_ : {a a' : A} → B a → a ≅ a' → B a' → Type ℓ≅ᴰ\n ρᴰ : {a : A} → isRefl _≅ᴰ⟨ ρ a ⟩_\n uniᴰ : {a : A} → isUnivalent _≅ᴰ⟨ ρ a ⟩_ ρᴰ\n\nopen URGStrᴰ\n\n-- another constructor for URGStrᴰ, using contractability of relational singletons\n-- rather than univalence\nmake-𝒮ᴰ : {A : Type ℓA} {𝒮-A : URGStr A ℓ≅A}\n {B : A → Type ℓB}\n (_≅ᴰ⟨_⟩_ : {a a' : A} → B a → URGStr._≅_ 𝒮-A a a' → B a' → Type ℓ≅ᴰ)\n (ρᴰ : {a : A} → isRefl _≅ᴰ⟨ URGStr.ρ 𝒮-A a ⟩_)\n (contrTotal : (a : A) → contrRelSingl _≅ᴰ⟨ URGStr.ρ 𝒮-A a ⟩_)\n → URGStrᴰ 𝒮-A B ℓ≅ᴰ\nmake-𝒮ᴰ {A = A} {𝒮-A = 𝒮-A} _≅ᴰ⟨_⟩_ ρᴰ contrTotal ._≅ᴰ⟨_⟩_ = _≅ᴰ⟨_⟩_\nmake-𝒮ᴰ {A = A} {𝒮-A = 𝒮-A} _≅ᴰ⟨_⟩_ ρᴰ contrTotal .ρᴰ = ρᴰ\nmake-𝒮ᴰ {A = A} {𝒮-A = 𝒮-A} _≅ᴰ⟨_⟩_ ρᴰ contrTotal .uniᴰ {a} b b' = contrRelSingl→isUnivalent (_≅ᴰ⟨ URGStr.ρ 𝒮-A a ⟩_) (ρᴰ {a}) (contrTotal a) b b'\n\n-- abbreviation to obtain contractibility of total space\n𝒮→cTS : {A : Type ℓA} (StrA : URGStr A ℓ≅A) → contrRelSingl (URGStr._≅_ StrA)\n𝒮→cTS StrA = isUnivalent→contrRelSingl _≅_ ρ uni\n where open URGStr StrA\n", "meta": {"hexsha": "4ce63f09fd7e4bc25603c4ea15179dc45543fa08", "size": 2883, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/DStructures/Base.agda", "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/DStructures/Base.agda", "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/DStructures/Base.agda", "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": 36.0375, "max_line_length": 146, "alphanum_fraction": 0.6357960458, "num_tokens": 1419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850402140659, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.39948741462528714}} {"text": "------------------------------------------------------------------------\n-- A lemma\n------------------------------------------------------------------------\n\nopen import Mixfix.Expr\nopen import Mixfix.Acyclic.PrecedenceGraph using (acyclic)\n\nmodule Mixfix.Acyclic.Lemma\n (g : PrecedenceGraphInterface.PrecedenceGraph acyclic)\n where\n\nopen import Data.List using ([]; _∷_)\nopen import Data.List.NonEmpty as List⁺ using (List⁺; _∷_; foldl; _⁺∷ʳ_)\nopen import Data.Product using (uncurry)\nopen import Relation.Binary.PropositionalEquality\n using (_≡_; refl)\n\nopen PrecedenceCorrect acyclic g\nopen import Mixfix.Fixity\n\n-- A generalisation of Mixfix.Acyclic.Grammar.Prec.appˡ.\n\nappˡ : ∀ {p} → Outer p left → List⁺ (Outer p left → ExprIn p left) →\n ExprIn p left\nappˡ e fs = foldl (λ e f → f (similar e)) (λ f → f e) fs\n\nappˡ-∷ʳ : ∀ {p} (e : Outer p left) fs f →\n appˡ e (fs ⁺∷ʳ f) ≡ f (similar (appˡ e fs))\nappˡ-∷ʳ e (f′ ∷ fs) = helper e f′ fs\n where\n helper : ∀ {p} (e : Outer p left) f′ fs f →\n appˡ e ((f′ ∷ fs) ⁺∷ʳ f) ≡ f (similar (appˡ e (f′ ∷ fs)))\n helper e f′ [] f = refl\n helper e f′ (f″ ∷ fs) f = helper (similar (f′ e)) f″ fs f\n", "meta": {"hexsha": "cfbcb8f2f0618e66cd1d5aae94c34b02560c5f1f", "size": 1188, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Mixfix/Acyclic/Lemma.agda", "max_stars_repo_name": "yurrriq/parser-combinators", "max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z", "max_issues_repo_path": "Mixfix/Acyclic/Lemma.agda", "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z", "max_forks_repo_path": "Mixfix/Acyclic/Lemma.agda", "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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": 33.9428571429, "max_line_length": 72, "alphanum_fraction": 0.5505050505, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7520125848754472, "lm_q2_score": 0.5312093733737562, "lm_q1q2_score": 0.39947613398086496}} {"text": "------------------------------------------------------------------------\n-- Breadth-first labelling of trees\n------------------------------------------------------------------------\n\n-- This module just defines breadth-first labelling. For a full\n-- development including a specification and proof, see BreadthFirst.\n\nmodule BreadthFirstWithoutProof where\n\nopen import Codata.Musical.Notation\nopen import Codata.Musical.Stream\nopen import Data.Product\n\nopen import Tree using (Tree; leaf; node)\n\n------------------------------------------------------------------------\n-- Universe\n\ndata U : Set₁ where\n tree : (a : U) → U\n stream : (a : U) → U\n _⊗_ : (a b : U) → U\n ⌈_⌉ : (A : Set) → U\n\nEl : U → Set\nEl (tree a) = Tree (El a)\nEl (stream a) = Stream (El a)\nEl (a ⊗ b) = El a × El b\nEl ⌈ A ⌉ = A\n\n------------------------------------------------------------------------\n-- Programs\n\ninfixr 5 _∷_\ninfixr 4 _,_\n\nmutual\n\n data ElP : U → Set₁ where\n ↓ : ∀ {a} (w : ElW a) → ElP a\n fst : ∀ {a b} (p : ElP (a ⊗ b)) → ElP a\n snd : ∀ {a b} (p : ElP (a ⊗ b)) → ElP b\n lab : ∀ {A B} (t : Tree A) (bss : ElP (stream ⌈ Stream B ⌉)) →\n ElP (tree ⌈ B ⌉ ⊗ stream ⌈ Stream B ⌉)\n\n -- The term WHNF is a bit of a misnomer here; only recursive\n -- /coinductive/ arguments are suspended (in the form of programs).\n\n data ElW : U → Set₁ where\n leaf : ∀ {a} → ElW (tree a)\n node : ∀ {a}\n (l : ∞ (ElP (tree a))) (x : ElW a) (r : ∞ (ElP (tree a))) →\n ElW (tree a)\n _∷_ : ∀ {a} (x : ElW a) (xs : ∞ (ElP (stream a))) → ElW (stream a)\n _,_ : ∀ {a b} (x : ElW a) (y : ElW b) → ElW (a ⊗ b)\n ⌈_⌉ : ∀ {A} (x : A) → ElW ⌈ A ⌉\n\nfstW : ∀ {a b} → ElW (a ⊗ b) → ElW a\nfstW (x , y) = x\n\nsndW : ∀ {a b} → ElW (a ⊗ b) → ElW b\nsndW (x , y) = y\n\n-- Uses the n-th stream to label the n-th level in the tree. Returns\n-- the remaining stream elements (for every level).\n\nlabW : ∀ {A B} → Tree A → ElW (stream ⌈ Stream B ⌉) →\n ElW (tree ⌈ B ⌉ ⊗ stream ⌈ Stream B ⌉)\nlabW leaf bss = (leaf , bss)\nlabW (node l _ r) (⌈ b ∷ bs ⌉ ∷ bss) =\n (node (♯ fst x) ⌈ b ⌉ (♯ fst y) , ⌈ ♭ bs ⌉ ∷ ♯ snd y)\n where\n x = lab (♭ l) (♭ bss)\n y = lab (♭ r) (snd x)\n\nwhnf : ∀ {a} → ElP a → ElW a\nwhnf (↓ w) = w\nwhnf (fst p) = fstW (whnf p)\nwhnf (snd p) = sndW (whnf p)\nwhnf (lab t bss) = labW t (whnf bss)\n\nmutual\n\n ⟦_⟧W : ∀ {a} → ElW a → El a\n ⟦ leaf ⟧W = leaf\n ⟦ node l x r ⟧W = node (♯ ⟦ ♭ l ⟧P) ⟦ x ⟧W (♯ ⟦ ♭ r ⟧P)\n ⟦ x ∷ xs ⟧W = ⟦ x ⟧W ∷ ♯ ⟦ ♭ xs ⟧P\n ⟦ (x , y) ⟧W = (⟦ x ⟧W , ⟦ y ⟧W)\n ⟦ ⌈ x ⌉ ⟧W = x\n\n ⟦_⟧P : ∀ {a} → ElP a → El a\n ⟦ p ⟧P = ⟦ whnf p ⟧W\n\n------------------------------------------------------------------------\n-- Breadth-first labelling\n\nlabel′ : ∀ {A B} → Tree A → Stream B →\n ElP (tree ⌈ B ⌉ ⊗ stream ⌈ Stream B ⌉)\nlabel′ t bs = lab t (↓ (⌈ bs ⌉ ∷ ♯ snd (label′ t bs)))\n\nlabel : ∀ {A B} → Tree A → Stream B → Tree B\nlabel t bs = ⟦ fst (label′ t bs) ⟧P\n", "meta": {"hexsha": "f683d55ad84eb1710511e4c9232cfc1fe570b739", "size": 2972, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BreadthFirstWithoutProof.agda", "max_stars_repo_name": "nad/codata", "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_issues_repo_path": "BreadthFirstWithoutProof.agda", "max_issues_repo_name": "nad/codata", "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": "BreadthFirstWithoutProof.agda", "max_forks_repo_name": "nad/codata", "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": 28.854368932, "max_line_length": 72, "alphanum_fraction": 0.432705249, "num_tokens": 1204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.665410572017153, "lm_q2_score": 0.600188359260205, "lm_q1q2_score": 0.39937167945336954}} {"text": "{-# OPTIONS --cubical --safe #-}\n\nmodule TreeFold where\n\nopen import Prelude\nopen import Data.List\nopen import Algebra using (Associative)\nopen import Data.List.Properties using (foldr-fusion; foldl-fusion; foldl′-foldl)\n\ninfixr 5 _^_&_\ndata Spine (A : Type a) : Type a where\n &0 : Spine A\n _^_&_ : A → ℕ → Spine A → Spine A\n\nprivate variable n : ℕ\n\nmodule Cons (f : A → A → A) where\n infixr 5 _^_∹_\n _^_∹_ : A → ℕ → Spine A → Spine A\n x ^ n ∹ &0 = x ^ n & &0\n x ^ n ∹ y ^ zero & xs = f x y ^ suc n ∹ xs\n x ^ n ∹ y ^ suc m & xs = x ^ n & y ^ m & xs\n\n _∹_ : A → Spine A → Spine A\n _∹_ = _^ zero ∹_\n\nmodule TreeFoldR (f : A → A → A) (z : A) where\n open Cons f public\n\n fold : Spine A → A\n fold &0 = z\n fold (x ^ n & xs) = f x (fold xs)\n\n spine : List A → Spine A\n spine = foldr _∹_ &0\n\n treeFold : List A → A\n treeFold = fold ∘ spine\n\n ∹-hom : Associative f → ∀ x xs → fold (x ^ n ∹ xs) ≡ f x (fold xs)\n ∹-hom p x &0 = refl\n ∹-hom p x (y ^ zero & xs) = ∹-hom p (f x y) xs ; p x y (fold xs)\n ∹-hom p x (y ^ suc n & xs) = refl\n \n treeFoldHom : Associative f → ∀ xs → treeFold xs ≡ foldr f z xs\n treeFoldHom f-assoc = foldr-fusion fold &0 (∹-hom f-assoc)\n\nmodule TreeFold1 (f : A → A → A) where\n open import Data.Maybe\n open import Data.Maybe.Properties\n open import Data.List.Properties\n\n f? : Maybe A → Maybe A → Maybe A\n f? nothing = id\n f? (just x) = just ∘ maybe x (f x)\n\n open TreeFoldR f? nothing\n\n treeFoldMay : List A → Maybe A\n treeFoldMay = treeFold ∘ map just\n \n treeFoldMayHom : Associative f → ∀ xs → treeFoldMay xs ≡ foldrMay f xs\n treeFoldMayHom f-assoc xs = treeFoldHom f?-assoc (map just xs) ; map-fusion f? nothing just xs\n where\n f?-assoc : Associative f?\n f?-assoc nothing y z = refl\n f?-assoc (just x) nothing z = refl\n f?-assoc (just x) (just y) nothing = refl\n f?-assoc (just x) (just y) (just z) = cong just (f-assoc x y z)\n\n isJustSpine? : Spine (Maybe A) → Bool\n isJustSpine? &0 = false\n isJustSpine? (x ^ y & xs) = is-just x\n\n IsJustSpine : Spine (Maybe A) → Type\n IsJustSpine = T ∘ isJustSpine?\n\n isJust-cons : ∀ x n xs → IsJustSpine (just x ^ n ∹ xs)\n isJust-cons x n &0 = tt\n isJust-cons x n (y ^ zero & xs) = isJust-cons (maybe x (f x) y) (suc n) xs\n isJust-cons x n (y ^ suc m & xs) = tt\n\n isJust-spine : ∀ xs → NonEmpty xs → IsJustSpine (spine (map just xs))\n isJust-spine (x ∷ xs) p = isJust-cons x 0 (spine (map just xs))\n\n isJust-fold : ∀ xs → IsJustSpine xs → IsJust (fold xs)\n isJust-fold (just _ ^ _ & _) _ = tt\n\n isJust-treeFoldMay : ∀ xs → NonEmpty xs → IsJust (treeFoldMay xs)\n isJust-treeFoldMay xs xsne = isJust-fold (spine (map just xs)) (isJust-spine xs xsne)\n\n treeFold1 : (xs : List A) → ⦃ NonEmpty xs ⦄ → A\n treeFold1 xs ⦃ xsne ⦄ = fromJust (treeFoldMay xs)\n where instance _ = isJust-treeFoldMay xs xsne\n\n -- treeFold1-hom : Associative f → ∀ xs → ⦃ xsne : NonEmpty xs ⦄ → treeFold1 xs ≡ foldr1 f xs\n -- treeFold1-hom f-assoc xs ⦃ xsne ⦄ = {!!}\nopen TreeFold1 using (treeFoldMay; treeFoldMayHom; treeFold1) public\n\nopen TreeFoldR using (treeFold; treeFoldHom) public\n\nmodule TreeFoldL (f : A → A → A) (z : A) where\n open TreeFoldR (flip f) z using (_∹_; fold; ∹-hom) public\n\n spine : List A → Spine A\n spine = foldl (flip _∹_) &0\n\n treeFoldL : List A → A\n treeFoldL = fold ∘ spine\n\n treeFoldLHom : Associative f → ∀ xs → treeFoldL xs ≡ foldl f z xs\n treeFoldLHom p = foldl-fusion fold &0 (flip (∹-hom λ x y z → sym (p z y x)))\n\nopen TreeFoldL using (treeFoldL; treeFoldLHom) public\n\nmodule StrictCons (f : A → A → A) where\n infixr 5 _^_∹_\n _^_∹_ : A → ℕ → Spine A → Spine A\n x ^ n ∹ &0 = x ^ n & &0\n x ^ n ∹ y ^ zero & xs = (_^ suc n ∹ xs) $! (f x y)\n x ^ n ∹ y ^ suc m & xs = x ^ n & y ^ m & xs\n\n _∹_ : A → Spine A → Spine A\n _∹_ = _^ zero ∹_\n\n private module Lazy = Cons f\n\n strict-lazy-cons : ∀ x n xs → x ^ n ∹ xs ≡ x Lazy.^ n ∹ xs\n strict-lazy-cons x n &0 = refl\n strict-lazy-cons x n (y ^ zero & xs) = $!-≡ (_^ suc n ∹ xs) (f x y) ; strict-lazy-cons (f x y) (suc n) xs\n strict-lazy-cons x n (y ^ suc m & xs) = refl\n\nmodule TreeFoldL′ (f : A → A → A) (z : A) where\n open StrictCons (flip f)\n\n spine : List A → Spine A\n spine = foldl′ (flip _∹_) &0\n\n private module Lazy = TreeFoldL f z\n\n open Lazy using (fold)\n\n treeFoldL′ : List A → A\n treeFoldL′ = fold ∘ spine\n\n treeFoldL′Hom : Associative f → ∀ xs → treeFoldL′ xs ≡ foldl f z xs\n treeFoldL′Hom p xs =\n cong fold (foldl′-foldl (flip _∹_) &0 xs ; cong (λ c → foldl c &0 xs) (funExt λ ys → funExt λ y → strict-lazy-cons y 0 ys)) ;\n Lazy.treeFoldLHom p xs\n\nopen TreeFoldL′ using (treeFoldL′; treeFoldL′Hom) public\n", "meta": {"hexsha": "262193d7973291e82e6954a8c08ba0e446fa9c07", "size": 4632, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "TreeFold.agda", "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_issues_repo_path": "TreeFold.agda", "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "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": "TreeFold.agda", "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "avg_line_length": 30.4736842105, "max_line_length": 129, "alphanum_fraction": 0.6047063903, "num_tokens": 1822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6654105587468141, "lm_q2_score": 0.6001883592602049, "lm_q1q2_score": 0.39937167148866654}} {"text": "open import Nat\nopen import Prelude\nopen import List\n\nopen import contexts\nopen import core\n\nmodule results-checks where\n Coerce-preservation : ∀{Δ Σ' r v τ} →\n Δ , Σ' ⊢ r ·: τ →\n Coerce r := v →\n Σ' ⊢ v ::ⱽ τ\n Coerce-preservation (TAFix x x₁) ()\n Coerce-preservation (TAApp ta-r ta-r₁) ()\n Coerce-preservation TAUnit CoerceUnit = TSVUnit\n Coerce-preservation (TAPair ta-r1 ta-r2) (CoercePair c-r1 c-r2)\n = TSVPair (Coerce-preservation ta-r1 c-r1) (Coerce-preservation ta-r2 c-r2)\n Coerce-preservation (TAFst ta-r) ()\n Coerce-preservation (TASnd ta-r) ()\n Coerce-preservation (TACtor h1 h2 ta-r) (CoerceCtor c-r)\n = TSVCtor h1 h2 (Coerce-preservation ta-r c-r)\n Coerce-preservation (TACase x x₁ ta-r x₂ x₃) ()\n Coerce-preservation (TAHole x x₁) ()\n\n {- TODO : We should revive this - it's a good sanity check.\n Of course, we have to decide what version of \"complete\" we want to use\n for results\n -- all complete finals (that type-check) are values\n mutual\n complete-finals-values : ∀{Δ Σ' r τ} →\n Δ , Σ' ⊢ r ·: τ →\n r rcomplete →\n r final →\n r value\n complete-finals-values (TALam Γ⊢E _) (RCLam E-cmp e-cmp) (FLam E-fin) =\n VLam (env-complete-final-values Γ⊢E E-cmp E-fin) e-cmp\n complete-finals-values (TAFix Γ⊢E _) (RCFix E-cmp e-cmp) (FFix E-fin) =\n VFix (env-complete-final-values Γ⊢E E-cmp E-fin) e-cmp\n complete-finals-values (TAApp ta1 ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2)\n with complete-finals-values ta1 cmp1 fin1\n complete-finals-values (TAApp ta1 ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2) | VLam _ _ = abort (h1 refl)\n complete-finals-values (TAApp ta1 ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2) | VFix _ _ = abort (h2 refl)\n complete-finals-values (TAApp () ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2) | VTpl _\n complete-finals-values (TAApp () ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2) | VCon _\n complete-finals-values (TAApp ta1 ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2) | VPF _ = {!!}\n complete-finals-values (TATpl ∥rs⊫=∥τs∥ ta) (RCTpl h1) (FTpl h2) =\n VTpl λ {i} i<∥rs∥ → complete-finals-values (ta i<∥rs∥ (tr (λ y → i < y) ∥rs⊫=∥τs∥ i<∥rs∥)) (h1 i<∥rs∥) (h2 i<∥rs∥)\n complete-finals-values (TAGet i<∥τs∥ ta) (RCGet cmp) (FGet fin x) = {!!}\n complete-finals-values (TACtor _ _ ta) (RCCtor cmp) (FCon fin) =\n VCon (complete-finals-values ta cmp fin)\n complete-finals-values (TACase x x₁ ta x₂ x₃) (RCCase x₄ cmp x₅) (FCase fin x₆ x₇) = {!!}\n complete-finals-values (TAHole _ _) () fin\n complete-finals-values (TAPF x) (RCPF x₁) (FPF x₂) = {!!}\n\n env-complete-final-values : ∀{Δ Σ' Γ E} →\n Δ , Σ' , Γ ⊢ E →\n E env-complete →\n E env-final →\n E env-values\n env-complete-final-values ta (ENVC E-cmp) (EF E-fin) =\n EF (λ rx∈E → complete-finals-values (π2 (π2 (env-all-E ta rx∈E))) (E-cmp rx∈E) (E-fin rx∈E))\n -}\n", "meta": {"hexsha": "67d27ca86841f9ec697f44b4586a608b40a6e638", "size": 3189, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "results-checks.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": "results-checks.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": "results-checks.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": 50.619047619, "max_line_length": 120, "alphanum_fraction": 0.5772969583, "num_tokens": 1122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.39925780874908473}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- The lifting of a non-strict order to incorporate a new supremum\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\n-- This module is designed to be used with\n-- Relation.Nullary.Construct.Add.Supremum\n\nopen import Relation.Binary\n\nmodule Relation.Binary.Construct.Add.Supremum.NonStrict\n {a ℓ} {A : Set a} (_≤_ : Rel A ℓ) where\n\nopen import Level using (_⊔_)\nopen import Data.Sum as Sum\nopen import Relation.Nullary\nimport Relation.Nullary.Decidable as Dec\nimport Relation.Binary.PropositionalEquality as P\nopen import Relation.Nullary.Construct.Add.Supremum\nimport Relation.Binary.Construct.Add.Supremum.Equality as Equality\n\n------------------------------------------------------------------------\n-- Definition\n\ndata _≤⁺_ : Rel (A ⁺) (a ⊔ ℓ) where\n [_] : {k l : A} → k ≤ l → [ k ] ≤⁺ [ l ]\n _≤⊤⁺ : (k : A ⁺) → k ≤⁺ ⊤⁺\n\n------------------------------------------------------------------------\n-- Properties\n\n[≤]-injective : ∀ {k l} → [ k ] ≤⁺ [ l ] → k ≤ l\n[≤]-injective [ p ] = p\n\nmodule _ {e} {_≈_ : Rel A e} where\n\n open Equality _≈_\n\n ≤⁺-reflexive : (_≈_ ⇒ _≤_) → (_≈⁺_ ⇒ _≤⁺_)\n ≤⁺-reflexive ≤-reflexive [ p ] = [ ≤-reflexive p ]\n ≤⁺-reflexive ≤-reflexive ⊤⁺≈⊤⁺ = ⊤⁺ ≤⊤⁺\n\n ≤⁺-antisym : Antisymmetric _≈_ _≤_ → Antisymmetric _≈⁺_ _≤⁺_\n ≤⁺-antisym ≤-antisym [ p ] [ q ] = [ ≤-antisym p q ]\n ≤⁺-antisym ≤-antisym (⊤⁺ ≤⊤⁺) (⊤⁺ ≤⊤⁺) = ⊤⁺≈⊤⁺\n\n≤⁺-trans : Transitive _≤_ → Transitive _≤⁺_\n≤⁺-trans ≤-trans [ p ] [ q ] = [ ≤-trans p q ]\n≤⁺-trans ≤-trans p (l ≤⊤⁺) = _ ≤⊤⁺\n\n≤⁺-maximum : Maximum _≤⁺_ ⊤⁺\n≤⁺-maximum = _≤⊤⁺\n\n≤⁺-dec : Decidable _≤_ → Decidable _≤⁺_\n≤⁺-dec _≤?_ k ⊤⁺ = yes (k ≤⊤⁺)\n≤⁺-dec _≤?_ ⊤⁺ [ l ] = no (λ ())\n≤⁺-dec _≤?_ [ k ] [ l ] = Dec.map′ [_] [≤]-injective (k ≤? l)\n\n≤⁺-total : Total _≤_ → Total _≤⁺_\n≤⁺-total ≤-total k ⊤⁺ = inj₁ (k ≤⊤⁺)\n≤⁺-total ≤-total ⊤⁺ l = inj₂ (l ≤⊤⁺)\n≤⁺-total ≤-total [ k ] [ l ] = Sum.map [_] [_] (≤-total k l)\n\n≤⁺-irrelevant : Irrelevant _≤_ → Irrelevant _≤⁺_\n≤⁺-irrelevant ≤-irr [ p ] [ q ] = P.cong _ (≤-irr p q)\n≤⁺-irrelevant ≤-irr (k ≤⊤⁺) (k ≤⊤⁺) = P.refl\n\n------------------------------------------------------------------------\n-- Structures\n\nmodule _ {e} {_≈_ : Rel A e} where\n\n open Equality _≈_\n\n ≤⁺-isPreorder : IsPreorder _≈_ _≤_ → IsPreorder _≈⁺_ _≤⁺_\n ≤⁺-isPreorder ≤-isPreorder = record\n { isEquivalence = ≈⁺-isEquivalence isEquivalence\n ; reflexive = ≤⁺-reflexive reflexive\n ; trans = ≤⁺-trans trans\n } where open IsPreorder ≤-isPreorder\n\n ≤⁺-isPartialOrder : IsPartialOrder _≈_ _≤_ → IsPartialOrder _≈⁺_ _≤⁺_\n ≤⁺-isPartialOrder ≤-isPartialOrder = record\n { isPreorder = ≤⁺-isPreorder isPreorder\n ; antisym = ≤⁺-antisym antisym\n } where open IsPartialOrder ≤-isPartialOrder\n\n ≤⁺-isDecPartialOrder : IsDecPartialOrder _≈_ _≤_ → IsDecPartialOrder _≈⁺_ _≤⁺_\n ≤⁺-isDecPartialOrder ≤-isDecPartialOrder = record\n { isPartialOrder = ≤⁺-isPartialOrder isPartialOrder\n ; _≟_ = ≈⁺-dec _≟_\n ; _≤?_ = ≤⁺-dec _≤?_\n } where open IsDecPartialOrder ≤-isDecPartialOrder\n\n ≤⁺-isTotalOrder : IsTotalOrder _≈_ _≤_ → IsTotalOrder _≈⁺_ _≤⁺_\n ≤⁺-isTotalOrder ≤-isTotalOrder = record\n { isPartialOrder = ≤⁺-isPartialOrder isPartialOrder\n ; total = ≤⁺-total total\n } where open IsTotalOrder ≤-isTotalOrder\n\n ≤⁺-isDecTotalOrder : IsDecTotalOrder _≈_ _≤_ → IsDecTotalOrder _≈⁺_ _≤⁺_\n ≤⁺-isDecTotalOrder ≤-isDecTotalOrder = record\n { isTotalOrder = ≤⁺-isTotalOrder isTotalOrder\n ; _≟_ = ≈⁺-dec _≟_\n ; _≤?_ = ≤⁺-dec _≤?_\n } where open IsDecTotalOrder ≤-isDecTotalOrder\n", "meta": {"hexsha": "f74133fb54744965ce677c33a374ab6722ec9e24", "size": 3757, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Add/Supremum/NonStrict.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Add/Supremum/NonStrict.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Relation/Binary/Construct/Add/Supremum/NonStrict.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": 34.1545454545, "max_line_length": 80, "alphanum_fraction": 0.5318072931, "num_tokens": 1518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6688802735722128, "lm_q2_score": 0.5964331462646255, "lm_q1q2_score": 0.39894236604101835}} {"text": "------------------------------------------------------------------------\n-- A type soundness result\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nmodule Lambda.Delay-monad.Type-soundness where\n\nopen import Equality.Propositional\nopen import Prelude\nopen import Prelude.Size\n\nopen import Function-universe equality-with-J\nopen import Maybe equality-with-J\nopen import Monad equality-with-J\nopen import Vec.Function equality-with-J\n\nopen import Delay-monad.Always\nopen import Delay-monad.Bisimilarity\nopen import Delay-monad.Monad\n\nopen import Lambda.Delay-monad.Interpreter\nopen import Lambda.Syntax\n\nopen Closure Tm\n\n-- If we can prove □ ∞ (WF-MV σ) (run x), then x does not \"go wrong\".\n\ndoes-not-go-wrong : ∀ {σ} {x : M ∞ Value} →\n □ ∞ (WF-MV σ) (run x) → ¬ x ≈M fail\ndoes-not-go-wrong (now {x = nothing} ())\ndoes-not-go-wrong (now {x = just x} x-wf) ()\ndoes-not-go-wrong (later x-wf) (laterˡ x↯) =\n does-not-go-wrong (force x-wf) x↯\n\n-- A \"constructor\" for □ i ∘ WF-MV.\n\n_>>=-wf_ :\n ∀ {i σ τ} {x : M ∞ Value} {f : Value → M ∞ Value} →\n □ i (WF-MV σ) (run x) →\n (∀ {v} → WF-Value σ v → □ i (WF-MV τ) (run (f v))) →\n □ i (WF-MV τ) (MaybeT.run (x >>= f))\nx-wf >>=-wf f-wf =\n □->>= x-wf λ { {nothing} ()\n ; {just v} v-wf → f-wf v-wf\n }\n\n-- Well-typed programs do not \"go wrong\".\n\nmutual\n\n ⟦⟧-wf : ∀ {i n Γ} (t : Tm n) {σ} → Γ ⊢ t ∈ σ →\n ∀ {ρ} → WF-Env Γ ρ →\n □ i (WF-MV σ) (run (⟦ t ⟧ ρ))\n ⟦⟧-wf (con i) con ρ-wf = now con\n ⟦⟧-wf (var x) var ρ-wf = now (ρ-wf x)\n ⟦⟧-wf (ƛ t) (ƛ t∈) ρ-wf = now (ƛ t∈ ρ-wf)\n ⟦⟧-wf (t₁ · t₂) (t₁∈ · t₂∈) {ρ} ρ-wf =\n ⟦⟧-wf t₁ t₁∈ ρ-wf >>=-wf λ f-wf →\n ⟦⟧-wf t₂ t₂∈ ρ-wf >>=-wf λ v-wf →\n ∙-wf f-wf v-wf\n\n ∙-wf : ∀ {i σ τ f v} →\n WF-Value (σ ⇾ τ) f → WF-Value (force σ) v →\n □ i (WF-MV (force τ)) (run (f ∙ v))\n ∙-wf (ƛ t₁∈ ρ₁-wf) v₂-wf =\n later λ { .force → ⟦⟧-wf _ t₁∈ (cons-wf v₂-wf ρ₁-wf) }\n\ntype-soundness : ∀ {t : Tm 0} {σ} →\n nil ⊢ t ∈ σ → ¬ ⟦ t ⟧ nil ≈M fail\ntype-soundness {t} {σ} =\n nil ⊢ t ∈ σ ↝⟨ (λ t∈ → ⟦⟧-wf _ t∈ nil-wf) ⟩\n □ ∞ (WF-MV σ) (run (⟦ t ⟧ nil)) ↝⟨ does-not-go-wrong ⟩□\n ¬ ⟦ t ⟧ nil ≈M fail □\n", "meta": {"hexsha": "53a401ee354687dbd57ed58c8e6d6362c86a2744", "size": 2314, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Lambda/Delay-monad/Type-soundness.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/Type-soundness.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/Type-soundness.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": 30.8533333333, "max_line_length": 72, "alphanum_fraction": 0.4745030251, "num_tokens": 938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7401743505760728, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.39894155534390674}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- List Zippers, basic types and operations\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.List.Zipper where\n\nopen import Data.Nat.Base\nopen import Data.Maybe.Base as Maybe using (Maybe ; just ; nothing)\nopen import Data.List.Base as List using (List ; [] ; _∷_)\nopen import Function\n\n\n-- Definition\n------------------------------------------------------------------------\n\n-- A List Zipper represents a List together with a particular sub-List\n-- in focus. The user can attempt to move the focus left or right, with\n-- a risk of failure if one has already reached the corresponding end.\n\n-- To make these operations efficient, the `context` the sub List in\n-- focus lives in is stored *backwards*. This is made formal by `toList`\n-- which returns the List a Zipper represents.\n\nrecord Zipper {a} (A : Set a) : Set a where\n constructor mkZipper\n field context : List A\n value : List A\n\n toList : List A\n toList = List.reverse context List.++ value\nopen Zipper public\n\n-- Embedding Lists as Zippers without any context\nfromList : ∀ {a} {A : Set a} → List A → Zipper A\nfromList = mkZipper []\n\n-- Fundamental operations of a Zipper: Moving around\n------------------------------------------------------------------------\n\nmodule _ {a} {A : Set a} where\n\n left : Zipper A → Maybe (Zipper A)\n left (mkZipper [] val) = nothing\n left (mkZipper (x ∷ ctx) val) = just (mkZipper ctx (x ∷ val))\n\n right : Zipper A → Maybe (Zipper A)\n right (mkZipper ctx []) = nothing\n right (mkZipper ctx (x ∷ val)) = just (mkZipper (x ∷ ctx) val)\n\n\n-- Focus-respecting operations\n------------------------------------------------------------------------\n\nmodule _ {a} {A : Set a} where\n\n reverse : Zipper A → Zipper A\n reverse (mkZipper ctx val) = mkZipper val ctx\n\n -- If we think of a List [x₁⋯xₘ] split into a List [xₙ₊₁⋯xₘ] in focus\n -- of another list [x₁⋯xₙ] then there are 4 places (marked {k} here) in\n -- which we can insert new values: [{1}x₁⋯xₙ{2}][{3}xₙ₊₁⋯xₘ{4}]\n\n -- The following 4 functions implement these 4 insertions.\n\n -- `xs ˢ++ zp` inserts `xs` on the `s` side of the context of the Zipper `zp`\n -- `zp ++ˢ xs` insert `xs` on the `s` side of the value in focus of the Zipper `zp`\n\n infixr 5 _ˡ++_ _ʳ++_\n infixl 5 _++ˡ_ _++ʳ_\n -- {1}\n _ˡ++_ : List A → Zipper A → Zipper A\n xs ˡ++ mkZipper ctx val = mkZipper (ctx List.++ List.reverse xs) val\n\n -- {2}\n _ʳ++_ : List A → Zipper A → Zipper A\n xs ʳ++ mkZipper ctx val = mkZipper (List.reverse xs List.++ ctx) val\n\n -- {3}\n _++ˡ_ : Zipper A → List A → Zipper A\n mkZipper ctx val ++ˡ xs = mkZipper ctx (xs List.++ val)\n\n -- {4}\n _++ʳ_ : Zipper A → List A → Zipper A\n mkZipper ctx val ++ʳ xs = mkZipper ctx (val List.++ xs)\n\n\n-- List-like operations\n------------------------------------------------------------------------\n\nmodule _ {a} {A : Set a} where\n\n length : Zipper A → ℕ\n length (mkZipper ctx val) = List.length ctx + List.length val\n\nmodule _ {a b} {A : Set a} {B : Set b} where\n\n map : (A → B) → Zipper A → Zipper B\n map f (mkZipper ctx val) = (mkZipper on List.map f) ctx val\n\n foldr : (A → B → B) → B → Zipper A → B\n foldr c n (mkZipper ctx val) = List.foldl (flip c) (List.foldr c n val) ctx\n\n\n-- Generating all the possible foci of a list\n------------------------------------------------------------------------\n\nmodule _ {a} {A : Set a} where\n\n allFociIn : List A → List A → List (Zipper A)\n allFociIn ctx [] = List.[ mkZipper ctx [] ]\n allFociIn ctx xxs@(x ∷ xs) = mkZipper ctx xxs ∷ allFociIn (x ∷ ctx) xs\n\n allFoci : List A → List (Zipper A)\n allFoci = allFociIn []\n", "meta": {"hexsha": "51e24e14a42645846e1ef7c9be8fc290d7a5438d", "size": 3736, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Zipper.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Zipper.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Data/List/Zipper.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 31.3949579832, "max_line_length": 84, "alphanum_fraction": 0.5629014989, "num_tokens": 1100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442251064863695, "lm_q2_score": 0.6187804337438502, "lm_q1q2_score": 0.3986338908203138}} {"text": "data D : Set where\n\nrecord R : Set where\n constructor d\n field x : D\n\nrecord R′ : Set where\n coinductive\n constructor d\n field r : R′\n\nf : R → D\nf r = let d x = r in x\n", "meta": {"hexsha": "e9580003edd5ea43de44b6ce4f1850e6e69de04e", "size": 173, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/interaction/Issue1064.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_issues_repo_path": "test/interaction/Issue1064.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_forks_repo_path": "test/interaction/Issue1064.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "avg_line_length": 12.3571428571, "max_line_length": 22, "alphanum_fraction": 0.612716763, "num_tokens": 62, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.39852653661407966}} {"text": "open import Level using (Level; _⊔_)\nopen import Function using (id; case_of_)\nopen import Data.Nat using (ℕ; suc)\nopen import Data.Fin using (Fin; suc; zero)\nopen import Data.Vec as Vec using (Vec) renaming (_∷_ to _,_; [] to ∅)\nopen import Data.List using (_∷_; [])\nopen import Data.List as List using (List; _++_) renaming (_∷_ to _,_; [] to ∅)\nopen import Data.Product as Product using (∃; _×_; _,_)\nopen import Relation.Binary.PropositionalEquality as P using (_≡_; refl; sym; cong)\n\nmodule IntuitionisticLogic (U : Set) (⟦_⟧ᵁ : U → Set) where\n\ninfix 30 _⊗_\ninfixr 20 _⇒_\n\ndata Type : Set where\n el : (A : U) → Type\n _⊗_ : Type → Type → Type\n _⇒_ : Type → Type → Type\n\nmodule Implicit where\n\n infix 4 _⊢_\n\n data _⊢_ : ∀ {k} (Γ : Vec Type k) (A : Type) → Set where\n var : ∀ {k} {Γ : Vec Type k} (x : Fin k) → Γ ⊢ Vec.lookup x Γ\n abs : ∀ {A B} {k} {Γ : Vec Type k} → A , Γ ⊢ B → Γ ⊢ A ⇒ B\n app : ∀ {A B} {k} {Γ : Vec Type k} → Γ ⊢ A ⇒ B → Γ ⊢ A → Γ ⊢ B\n pair : ∀ {A B} {k} {Γ : Vec Type k} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ⊗ B\n case : ∀ {A B C} {k} {Γ : Vec Type k} → Γ ⊢ A ⊗ B → A , B , Γ ⊢ C → Γ ⊢ C\n\n swap : ∀ {A B} {k} {Γ : Vec Type k} → Γ ⊢ A ⊗ B ⇒ B ⊗ A\n swap = abs (case (var zero) (pair (var (suc zero)) (var zero)))\n\n Vec-exch : ∀ {k} (i : Fin k) → Vec Type (suc k) → Vec Type (suc k)\n Vec-exch zero (A , B , Γ) = B , A , Γ\n Vec-exch (suc i) (A , Γ) = A , (Vec-exch i Γ)\n\n lemma-var : ∀ {k} {Γ : Vec Type (suc k)} → ∀ i x → ∃ λ y → Vec.lookup x Γ ≡ Vec.lookup y (Vec-exch i Γ)\n lemma-var {Γ = A , B , Γ} zero zero = suc zero , refl\n lemma-var {Γ = A , B , Γ} zero (suc zero) = zero , refl\n lemma-var {Γ = A , B , Γ} zero (suc (suc x)) = suc (suc x) , refl\n lemma-var {Γ = A , Γ} (suc i) zero = zero , refl\n lemma-var {Γ = A , Γ} (suc i) (suc x) = Product.map suc id (lemma-var {Γ = Γ} i x)\n\n exch : ∀ {k} {Γ : Vec Type (suc k)} {A} → ∀ i → Γ ⊢ A → Vec-exch i Γ ⊢ A\n exch {Γ = Γ} i (var x) with lemma-var {Γ = Γ} i x\n exch {Γ = Γ} i (var x) | y , p rewrite p = var y\n exch i (abs t) = abs (exch (suc i) t)\n exch i (app s t) = app (exch i s) (exch i t)\n exch i (pair s t) = pair (exch i s) (exch i t)\n exch i (case s t) = case (exch i s) (exch (suc (suc i)) t)\n\nmodule Explicit where\n\n infix 4 _⊢_\n\n data _⊢_ : ∀ (X : List Type) (A : Type) → Set where\n var : ∀ {A} → A , ∅ ⊢ A\n abs : ∀ {X A B} → A , X ⊢ B → X ⊢ A ⇒ B\n app : ∀ {X Y A B} → X ⊢ A ⇒ B → Y ⊢ A → X ++ Y ⊢ B\n pair : ∀ {X Y A B} → X ⊢ A → Y ⊢ B → X ++ Y ⊢ A ⊗ B\n case : ∀ {X Y A B C} → X ⊢ A ⊗ B → A , B , Y ⊢ C → X ++ Y ⊢ C\n weak : ∀ {X Y A} → X ⊢ A → X ++ Y ⊢ A\n cont : ∀ {X A B} → A , A , X ⊢ B → A , X ⊢ B\n exch : ∀ {X Y Z W A} → (X ++ Z) ++ (Y ++ W) ⊢ A\n → (X ++ Y) ++ (Z ++ W) ⊢ A\n\n exch₀ : ∀ {X A B C} → B , A , X ⊢ C → A , B , X ⊢ C\n exch₀ {X} {A} {B} = exch {∅} {A , ∅} {B , ∅} {X}\n\n swap : ∀ {X A B} → X ⊢ A ⊗ B ⇒ B ⊗ A\n swap {X} {A} {B} = abs (case var (exch₀ (pair var (weak {A , ∅} {X} var))))\n\n record Reify {a b : Level} (A : Set a) (B : Set b) : Set (a ⊔ b) where\n field\n ⟦_⟧ : A → B\n\n instance\n ReifyType : Reify Type Set\n ReifyType = record { ⟦_⟧ = ⟦_⟧ }\n where\n\n ⟦_⟧ : Type → Set\n ⟦ el A ⟧ = ⟦ A ⟧ᵁ\n ⟦ A ⊗ B ⟧ = ⟦ A ⟧ × ⟦ B ⟧\n ⟦ A ⇒ B ⟧ = ⟦ A ⟧ → ⟦ B ⟧\n\n data Ctxt : ∀ (X : List Set) → Set₁ where\n ∅ : Ctxt ∅\n _,_ : ∀ {A X} → A → Ctxt X → Ctxt (A , X)\n\n open Reify {{...}} using (⟦_⟧)\n\n instance\n ReifyCtxt : Reify (List Type) (List Set)\n ReifyCtxt = record { ⟦_⟧ = List.map ⟦_⟧ }\n\n Ctxt-insert : {A : Type} {X Y : List Type} → ⟦ A ⟧ → Ctxt ⟦ X ++ Y ⟧ → Ctxt ⟦ X ++ (A , Y) ⟧\n Ctxt-insert {A} {∅} {Y} A′ E = A′ , E\n Ctxt-insert {A} {B , X} {Y} A′ (B′ , E) = B′ , Ctxt-insert {A} {X} {Y} A′ E\n\n Ctxt-exch : {X Y Z W : List Type} → Ctxt ⟦ (X ++ Y) ++ (Z ++ W) ⟧ → Ctxt ⟦ (X ++ Z) ++ (Y ++ W) ⟧\n Ctxt-exch {X = ∅} {Y = ∅} {Z} {W} E = E\n Ctxt-exch {X = ∅} {Y = A , Y} {Z} {W} (A′ , E) = Ctxt-insert {A} {Z} {Y ++ W} A′ (Ctxt-exch {∅} {Y} {Z} {W} E)\n Ctxt-exch {X = A , X} {Y} {Z} {W} (A′ , E) = A′ , Ctxt-exch {X} {Y} {Z} {W} E\n\n Ctxt-split : {X Y : List Type} → Ctxt ⟦ X ++ Y ⟧ → Ctxt ⟦ X ⟧ × Ctxt ⟦ Y ⟧\n Ctxt-split {∅} {Y} E = ∅ , E\n Ctxt-split {A , X} {Y} (A′ , E) with Ctxt-split {X} {Y} E\n ... | Eˣ , Eʸ = ((A′ , Eˣ) , Eʸ)\n\n reify : {A : Type} {X : List Type} → X ⊢ A → (Ctxt ⟦ X ⟧ → ⟦ A ⟧)\n reify var (x , ∅) = x\n reify (abs t) E = λ x → reify t (x , E)\n reify (app s t) E with Ctxt-split E\n ... | Eˢ , Eᵗ = (reify s Eˢ) (reify t Eᵗ)\n reify (pair s t) E with Ctxt-split E\n ... | Eˢ , Eᵗ = (reify s Eˢ , reify t Eᵗ)\n reify (case s t) E with Ctxt-split E\n ... | Eˢ , Eᵗ = case reify s Eˢ of λ{ (x , y) → reify t (x , y , Eᵗ)}\n reify (weak {X} s) E with Ctxt-split {X} E\n ... | Eˢ , Eᵗ = reify s Eˢ\n reify (cont t) (x , E) = reify t (x , x , E)\n reify (exch {X} {Y} {Z} {W} t) E = reify t (Ctxt-exch {X} {Y} {Z} {W} E)\n\n [_] : {A : Type} {X : List Type} → X ⊢ A → (Ctxt ⟦ X ⟧ → ⟦ A ⟧)\n [_] = reify\n\n swap′ : ∀ {A B} → ⟦ A ⟧ × ⟦ B ⟧ → ⟦ B ⟧ × ⟦ A ⟧\n swap′ {A} {B} = [ swap {∅} {A} {B} ] ∅\n\n", "meta": {"hexsha": "193d04150ed4cffcaa58844c841b10f1cacdbcdb", "size": 5267, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/IntuitionisticLogic.agda", "max_stars_repo_name": "wenkokke/msla2014", "max_stars_repo_head_hexsha": "b880cf25ed8e81b9a965ea9aad18377008d68a9f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-11-17T23:04:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-29T09:07:45.000Z", "max_issues_repo_path": "src/IntuitionisticLogic.agda", "max_issues_repo_name": "wenkokke/msla2014", "max_issues_repo_head_hexsha": "b880cf25ed8e81b9a965ea9aad18377008d68a9f", "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/IntuitionisticLogic.agda", "max_forks_repo_name": "wenkokke/msla2014", "max_forks_repo_head_hexsha": "b880cf25ed8e81b9a965ea9aad18377008d68a9f", "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.6015037594, "max_line_length": 112, "alphanum_fraction": 0.4400987279, "num_tokens": 2509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.39852653661407966}} {"text": "module Coverage where\n\ninfixr 40 _::_\ndata List (A : Set) : Set where\n [] : List A\n _::_ : A -> List A -> List A\n\ndata D : Set where\n c1 : D -> D\n c2 : D\n c3 : D -> D -> D -> D\n c4 : D -> D -> D\n\nf : D -> D -> D -> D -> List D\nf (c3 a (c1 b) (c1 c2)) (c1 (c1 c)) d (c1 (c1 (c1 e))) = a :: b :: c :: d :: e :: []\nf (c3 (c4 c2 a) (c1 b) (c1 c)) d (c1 (c1 e)) (c1 (c1 (c1 f))) = a :: b :: c :: d :: e :: f :: []\nf a b (c1 c) (c3 d (c1 e) (c1 f)) = a :: b :: c :: d :: e :: f :: []\nf (c3 (c4 a c2) b (c1 c)) (c1 d) (c1 (c1 (c1 e))) (c1 (c1 (c1 f))) = a :: b :: c :: d :: e :: f :: []\n-- f (c3 a (c1 b) c) (c1 (c1 (c1 d))) (c1 (c1 (c1 e))) f = a :: b :: c :: d :: e :: f :: []\n-- f a b (c1 (c1 c)) (c1 (c1 (c1 c2))) = a :: b :: c :: []\nf a b c d = a :: b :: c :: d :: []\n\n", "meta": {"hexsha": "bc00f588a0c86f47d77c28c66ef70945a57a9103", "size": 775, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "benchmark/misc/Coverage.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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": "benchmark/misc/Coverage.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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": "benchmark/misc/Coverage.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 33.6956521739, "max_line_length": 101, "alphanum_fraction": 0.3651612903, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.734119526900183, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3985265366140796}} {"text": "module BasicIS4.Metatheory.DyadicGentzen-TarskiGluedDyadicImplicit where\n\nopen import BasicIS4.Syntax.DyadicGentzen public\nopen import BasicIS4.Semantics.TarskiGluedDyadicImplicit public\n\nopen ImplicitSyntax (_⊢_) public\n\n\n-- Soundness with respect to all models, or evaluation.\n\n-- FIXME\npostulate\n reify⋆ : ∀ {{_ : Model}} {Ξ Γ Δ} → Γ ⁏ Δ ⊩⋆ Ξ → Γ ⁏ Δ ⊢⋆ Ξ\n\neval : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊨ A\neval (var i) γ δ = lookup i γ\neval (lam t) γ δ = λ ψ a → eval t (mono²⊩⋆ ψ γ , a) (mono²⊩⋆ ψ δ)\neval (app {A} {B} t u) γ δ = _⟪$⟫_ {A} {B} (eval t γ δ) (eval u γ δ)\neval (mvar i) γ δ = mlookup i δ\neval (box t) γ δ = λ ψ → let δ′ = mono²⊩⋆ ψ δ\n in mmulticut (reify⋆ δ′) (box t) ⅋\n eval t ∙ δ′\neval (unbox t u) γ δ = eval u γ (δ , λ ψ →\n let γ′ = mono²⊩⋆ ψ γ\n δ′ = mono²⊩⋆ ψ δ\n in multicut² (reify⋆ γ′) (reify⋆ δ′) t ⅋\n ⟪↓⟫ (eval t γ′ δ′))\neval (pair t u) γ δ = eval t γ δ , eval u γ δ\neval (fst t) γ δ = π₁ (eval t γ δ)\neval (snd t) γ δ = π₂ (eval t γ δ)\neval unit γ δ = ∙\n\n\n-- TODO: Correctness of evaluation with respect to conversion.\n\n\n-- The canonical model.\n\nprivate\n instance\n canon : Model\n canon = record\n { _⊩ᵅ_ = λ Π P → Π ⊢ α P\n ; mono²⊩ᵅ = mono²⊢\n }\n\n\n-- Soundness and completeness with respect to the canonical model.\n\nmutual\n reflectᶜ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊩ A\n reflectᶜ {α P} t = t\n reflectᶜ {A ▻ B} t = λ ψ → let t′ = mono²⊢ ψ t\n in λ a → reflectᶜ (app t′ (reifyᶜ a))\n reflectᶜ {□ A} t = λ ψ → let t′ = mono²⊢ ψ t\n in t′ ⅋ reflectᶜ (down t′)\n reflectᶜ {A ∧ B} t = reflectᶜ (fst t) , reflectᶜ (snd t)\n reflectᶜ {⊤} t = ∙\n\n reifyᶜ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊩ A → Γ ⁏ Δ ⊢ A\n reifyᶜ {α P} s = s\n reifyᶜ {A ▻ B} s = lam (reifyᶜ (s (weak⊆²₁) (reflectᶜ {A} v₀)))\n reifyᶜ {□ A} s = syn (s refl⊆²)\n reifyᶜ {A ∧ B} s = pair (reifyᶜ (π₁ s)) (reifyᶜ (π₂ s))\n reifyᶜ {⊤} s = unit\n\nreflectᶜ⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ ⊩⋆ Ξ\nreflectᶜ⋆ {∅} ∙ = ∙\nreflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t\n\nreifyᶜ⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊩⋆ Ξ → Γ ⁏ Δ ⊢⋆ Ξ\nreifyᶜ⋆ {∅} ∙ = ∙\nreifyᶜ⋆ {Ξ , A} (ts , t) = reifyᶜ⋆ ts , reifyᶜ t\n\n\n-- Reflexivity and transitivity.\n\nrefl⊩⋆ : ∀ {Γ Δ} → Γ ⁏ Δ ⊩⋆ Γ\nrefl⊩⋆ = reflectᶜ⋆ refl⊢⋆\n\nmrefl⊩⋆ : ∀ {Γ Δ} → Γ ⁏ Δ ⊩⋆ □⋆ Δ\nmrefl⊩⋆ = reflectᶜ⋆ mrefl⊢⋆\n\ntrans⊩⋆ : ∀ {Γ Γ′ Δ Δ′ Ξ} → Γ ⁏ Δ ⊩⋆ Γ′ ⧺ (□⋆ Δ′) → Γ′ ⁏ Δ′ ⊩⋆ Ξ → Γ ⁏ Δ ⊩⋆ Ξ\ntrans⊩⋆ ts us = reflectᶜ⋆ (trans⊢⋆ (reifyᶜ⋆ ts) (reifyᶜ⋆ us))\n\n\n-- Completeness with respect to all models, or quotation.\n\nquot : ∀ {A Γ Δ} → Γ ⁏ Δ ⊨ A → Γ ⁏ Δ ⊢ A\nquot s = reifyᶜ (s refl⊩⋆ mrefl⊩⋆)\n\n\n-- Normalisation by evaluation.\n\nnorm : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ A\nnorm = quot ∘ eval\n\n\n-- TODO: Correctness of normalisation with respect to conversion.\n", "meta": {"hexsha": "1a3a6b01e159cb89dfc9c01f08d696c48533c814", "size": 3049, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BasicIS4/Metatheory/DyadicGentzen-TarskiGluedDyadicImplicit.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/Metatheory/DyadicGentzen-TarskiGluedDyadicImplicit.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/Metatheory/DyadicGentzen-TarskiGluedDyadicImplicit.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": 30.1881188119, "max_line_length": 77, "alphanum_fraction": 0.4811413578, "num_tokens": 1469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195152660687, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3985265302983461}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule F1b where\n\nopen import Data.Unit\nopen import Data.Sum hiding (map; [_,_])\nopen import Data.Product hiding (map; ,_)\nopen import Function using (flip)\nopen import Relation.Binary.Core using (IsEquivalence; Reflexive; Symmetric; Transitive)\nopen import Relation.Binary\n\nopen import Groupoid\n\ninfixr 90 _⊗_\ninfixr 80 _⊕_\ninfixr 60 _∘_\ninfix 30 _⟷_\n\n---------------------------------------------------------------------------\n-- Paths\n\n-- Path relation should be an equivalence \ndata Path {A : Set} : A → A → Set where\n _⇛_ : (x : A) → (y : A) → Path x y\n\ndata _≣⇛_ {A : Set} {a b : A} (x : Path a b) : Path a b → Set where\n refl⇛ : x ≣⇛ x\n\nid⇛ : {A : Set} → (a : A) → Path a a\nid⇛ a = a ⇛ a\n\nap : {A B : Set} → (f : A → B) → {a a' : A} → Path a a' → Path (f a) (f a')\nap f (a ⇛ a') = (f a) ⇛ (f a')\n\n_∙⇛_ : {A : Set} {a b c : A} → Path b c → Path a b → Path a c\n(b ⇛ c) ∙⇛ (a ⇛ .b) = a ⇛ c\n\n_⇚ : {A : Set} {a b : A} → Path a b → Path b a\n(x ⇛ y) ⇚ = y ⇛ x\n\nlid⇛ : {A : Set} {x y : A} (α : Path x y) → (id⇛ y ∙⇛ α) ≣⇛ α\nlid⇛ (x ⇛ y) = refl⇛\n\nrid⇛ : {A : Set} {x y : A} (α : Path x y) → (α ∙⇛ id⇛ x) ≣⇛ α\nrid⇛ (x ⇛ y) = refl⇛\n\nassoc⇛ : {A : Set} {w x y z : A} (α : Path y z) (β : Path x y) (δ : Path w x) → ((α ∙⇛ β) ∙⇛ δ) ≣⇛ (α ∙⇛ (β ∙⇛ δ))\nassoc⇛ (y ⇛ z) (x ⇛ .y) (w ⇛ .x) = refl⇛\n\nl⇚ : {A : Set} {x y : A} (α : Path x y) → ((α ⇚) ∙⇛ α) ≣⇛ id⇛ x\nl⇚ (x ⇛ y) = refl⇛\n\nr⇚ : {A : Set} {x y : A} (α : Path x y) → (α ∙⇛ (α ⇚)) ≣⇛ id⇛ y\nr⇚ (x ⇛ y) = refl⇛\n\nsym⇛ : {A : Set} {x y : A} {α β : Path x y} → α ≣⇛ β → β ≣⇛ α\nsym⇛ refl⇛ = refl⇛\n\ntrans⇛ : {A : Set} {x y : A} {α β δ : Path x y} → α ≣⇛ β → β ≣⇛ δ → α ≣⇛ δ\ntrans⇛ refl⇛ refl⇛ = refl⇛\n \nequiv≣⇛ : {A : Set} {x y : A} → IsEquivalence {_} {_} {Path x y} (_≣⇛_)\nequiv≣⇛ = record { refl = refl⇛; sym = sym⇛; trans = trans⇛ }\n\nresp≣⇛ : {A : Set} {x y z : A} {f h : Path y z} {g i : Path x y} →\n f ≣⇛ h → g ≣⇛ i → (f ∙⇛ g) ≣⇛ (h ∙⇛ i)\nresp≣⇛ refl⇛ refl⇛ = refl⇛\n\n------------------------------------------------------------------------------\n-- pi types with exactly one level of reciprocals\n\ndata B0 : Set where\n ONE : B0\n PLUS0 : B0 → B0 → B0\n TIMES0 : B0 → B0 → B0\n\n-- interpretation of B0 as discrete groupoids\n\nrecord 0-type : Set₁ where\n constructor G₀\n field\n ∣_∣₀ : Set\n\nopen 0-type public\n\nplus : 0-type → 0-type → 0-type\nplus t₁ t₂ = G₀ (∣ t₁ ∣₀ ⊎ ∣ t₂ ∣₀) \n\ntimes : 0-type → 0-type → 0-type\ntimes t₁ t₂ = G₀ (∣ t₁ ∣₀ × ∣ t₂ ∣₀)\n\n⟦_⟧₀ : B0 → 0-type\n⟦ ONE ⟧₀ = G₀ ⊤ \n⟦ PLUS0 b₁ b₂ ⟧₀ = plus ⟦ b₁ ⟧₀ ⟦ b₂ ⟧₀\n⟦ TIMES0 b₁ b₂ ⟧₀ = times ⟦ b₁ ⟧₀ ⟦ b₂ ⟧₀\n\nı₀ : B0 → Set\nı₀ b = ∣ ⟦ b ⟧₀ ∣₀ \n\npoint : (b : B0) → ı₀ b\npoint ONE = tt\npoint (PLUS0 b _) = inj₁ (point b)\npoint (TIMES0 b₀ b₁) = point b₀ , point b₁ \n\n-- isos\n\ndata _⟷_ : B0 → B0 → Set where\n -- + \n swap₊ : { b₁ b₂ : B0 } → PLUS0 b₁ b₂ ⟷ PLUS0 b₂ b₁\n assocl₊ : { b₁ b₂ b₃ : B0 } → PLUS0 b₁ (PLUS0 b₂ b₃) ⟷ PLUS0 (PLUS0 b₁ b₂) b₃\n assocr₊ : { b₁ b₂ b₃ : B0 } → PLUS0 (PLUS0 b₁ b₂) b₃ ⟷ PLUS0 b₁ (PLUS0 b₂ b₃)\n -- *\n unite⋆ : { b : B0 } → TIMES0 ONE b ⟷ b\n uniti⋆ : { b : B0 } → b ⟷ TIMES0 ONE b\n swap⋆ : { b₁ b₂ : B0 } → TIMES0 b₁ b₂ ⟷ TIMES0 b₂ b₁\n assocl⋆ : { b₁ b₂ b₃ : B0 } → TIMES0 b₁ (TIMES0 b₂ b₃) ⟷ TIMES0 (TIMES0 b₁ b₂) b₃\n assocr⋆ : { b₁ b₂ b₃ : B0 } → TIMES0 (TIMES0 b₁ b₂) b₃ ⟷ TIMES0 b₁ (TIMES0 b₂ b₃)\n -- * distributes over + \n dist : { b₁ b₂ b₃ : B0 } → \n TIMES0 (PLUS0 b₁ b₂) b₃ ⟷ PLUS0 (TIMES0 b₁ b₃) (TIMES0 b₂ b₃) \n factor : { b₁ b₂ b₃ : B0 } → \n PLUS0 (TIMES0 b₁ b₃) (TIMES0 b₂ b₃) ⟷ TIMES0 (PLUS0 b₁ b₂) b₃\n -- congruence\n id⟷ : { b : B0 } → b ⟷ b\n sym : { b₁ b₂ : B0 } → (b₁ ⟷ b₂) → (b₂ ⟷ b₁)\n _∘_ : { b₁ b₂ b₃ : B0 } → (b₁ ⟷ b₂) → (b₂ ⟷ b₃) → (b₁ ⟷ b₃)\n _⊕_ : { b₁ b₂ b₃ b₄ : B0 } → \n (b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (PLUS0 b₁ b₂ ⟷ PLUS0 b₃ b₄)\n _⊗_ : { b₁ b₂ b₃ b₄ : B0 } → \n (b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (TIMES0 b₁ b₂ ⟷ TIMES0 b₃ b₄)\n{--\n--}\n\n-- interpret isos as paths\n\neval0 : {b₁ b₂ : B0} → (c : b₁ ⟷ b₂) → (x : ı₀ b₁) → ı₀ b₂\neval0 _ = {!!}\n\n--comb0 : {b₁ b₂ : B0} → (c : b₁ ⟷ b₂) → (x : ı₀ b₁) → Path x (eval0 c x)\n--comb0 _ = ?\n\n------------------------------------------------------------------------------\n-- interpretation of B1 types as 1-groupoids\n\ndata B1 : Set where\n LIFT0 : B0 → B1\n PLUS1 : B1 → B1 → B1\n TIMES1 : B1 → B1 → B1\n RECIP1 : B0 → B1\n\nopen 1Groupoid\n\nallPaths : Set → 1Groupoid\nallPaths a = record\n { set = a\n ; _↝_ = Path\n ; _≈_ = _≣⇛_\n ; id = λ {x} → id⇛ x\n ; _∘_ = _∙⇛_\n ; _⁻¹ = _⇚\n ; lneutr = lid⇛\n ; rneutr = rid⇛\n ; assoc = assoc⇛\n ; linv = l⇚\n ; rinv = r⇚\n ; equiv = equiv≣⇛ \n ; ∘-resp-≈ = resp≣⇛}\n\n⟦_⟧₁ : B1 → 1Groupoid\n⟦ LIFT0 b0 ⟧₁ = discrete (ı₀ b0) \n⟦ PLUS1 b₁ b₂ ⟧₁ = ⟦ b₁ ⟧₁ ⊎G ⟦ b₂ ⟧₁\n⟦ TIMES1 b₁ b₂ ⟧₁ = ⟦ b₁ ⟧₁ ×G ⟦ b₂ ⟧₁\n⟦ RECIP1 b0 ⟧₁ = allPaths (ı₀ b0)\n\nı₁ : B1 → Set\nı₁ b = set ⟦ b ⟧₁\n\ntest10 = ⟦ LIFT0 ONE ⟧₁\ntest11 = ⟦ LIFT0 (PLUS0 ONE ONE) ⟧₁\ntest12 = ⟦ RECIP1 (PLUS0 ONE ONE) ⟧₁\n\n-- interpret isos as functors\n\ndata _⟷₁_ : B1 → B1 → Set where\n -- + \n swap₊ : { b₁ b₂ : B1 } → PLUS1 b₁ b₂ ⟷₁ PLUS1 b₂ b₁\n{--\n assocl₊ : { b₁ b₂ b₃ : B1 } → PLUS b₁ (PLUS b₂ b₃) ⟷₁ PLUS (PLUS b₁ b₂) b₃\n assocr₊ : { b₁ b₂ b₃ : B1 } → PLUS (PLUS b₁ b₂) b₃ ⟷₁ PLUS b₁ (PLUS b₂ b₃)\n -- *\n--}\n unite⋆ : { b : B1 } → TIMES1 (LIFT0 ONE) b ⟷₁ b\n uniti⋆ : { b : B1 } → b ⟷₁ TIMES1 (LIFT0 ONE) b\n{--\n swap⋆ : { b₁ b₂ : B } → TIMES b₁ b₂ ⟷₁ TIMES b₂ b₁\n assocl⋆ : { b₁ b₂ b₃ : B } → TIMES b₁ (TIMES b₂ b₃) ⟷₁ TIMES (TIMES b₁ b₂) b₃\n assocr⋆ : { b₁ b₂ b₃ : B } → TIMES (TIMES b₁ b₂) b₃ ⟷₁ TIMES b₁ (TIMES b₂ b₃)\n -- * distributes over + \n dist : { b₁ b₂ b₃ : B } → \n TIMES (PLUS b₁ b₂) b₃ ⟷₁ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) \n factor : { b₁ b₂ b₃ : B } → \n PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ⟷₁ TIMES (PLUS b₁ b₂) b₃\n -- congruence\n id⟷₁ : { b : B } → b ⟷₁ b\n sym : { b₁ b₂ : B } → (b₁ ⟷₁ b₂) → (b₂ ⟷₁ b₁)\n _∘_ : { b₁ b₂ b₃ : B } → (b₁ ⟷₁ b₂) → (b₂ ⟷₁ b₃) → (b₁ ⟷₁ b₃)\n _⊕_ : { b₁ b₂ b₃ b₄ : B } → \n (b₁ ⟷₁ b₃) → (b₂ ⟷₁ b₄) → (PLUS b₁ b₂ ⟷₁ PLUS b₃ b₄)\n _⊗_ : { b₁ b₂ b₃ b₄ : B } → \n (b₁ ⟷₁ b₃) → (b₂ ⟷₁ b₄) → (TIMES b₁ b₂ ⟷₁ TIMES b₃ b₄)\n η⋆ : (b : B0) → LIFT0 ONE ⟷₁ TIMES1 (LIFT0 b) (RECIP1 b)\n ε⋆ : (b : B0) → TIMES1 (LIFT0 b) (RECIP1 b) ⟷₁ LIFT0 ONE\n--}\n\nrecord 1-functor (A B : 1Groupoid) : Set where\n constructor 1F\n private module A = 1Groupoid A\n private module B = 1Groupoid B\n\n field\n F₀ : set A → set B\n F₁ : ∀ {X Y : set A} → A [ X , Y ] → B [ F₀ X , F₀ Y ]\n -- identity : ∀ {X} → B._≈_ (F₁ (A.id {X})) B.id\n -- F-resp-≈ : ∀ {X Y} {F G : A [ X , Y ]} → A._≈_ F G → B._≈_ (F₁ F) (F₁ G)\n\nopen 1-functor public\n\nipath : (b : B1) → ı₁ b → ı₁ b → Set\nipath b x y = Path {ı₁ b} x y\n\nswap⊎ : {A B : Set} → A ⊎ B → B ⊎ A\nswap⊎ (inj₁ a) = inj₂ a\nswap⊎ (inj₂ b) = inj₁ b\n\nintro1⋆ : {b : B1} {x y : ı₁ b} → ipath b x y → ipath (TIMES1 (LIFT0 ONE) b) (tt , x) (tt , y)\nintro1⋆ (y ⇛ z) = (tt , y) ⇛ (tt , z)\n\nobjη⋆ : (b : B0) → ı₁ (LIFT0 ONE) → ı₁ (TIMES1 (LIFT0 b) (RECIP1 b))\nobjη⋆ b tt = point b , point b\n\nobjε⋆ : (b : B0) → ı₁ (TIMES1 (LIFT0 b) (RECIP1 b)) → ı₁ (LIFT0 ONE)\nobjε⋆ b (x , y) = tt\n\nelim1∣₁ : (b : B1) → ı₁ (TIMES1 (LIFT0 ONE) b) → ı₁ b\nelim1∣₁ b (tt , x) = x\n\nintro1∣₁ : (b : B1) → ı₁ b → ı₁ (TIMES1 (LIFT0 ONE) b)\nintro1∣₁ b x = (tt , x)\n\nswapF : {b₁ b₂ : B1} →\n let G = ⟦ b₁ ⟧₁ ⊎G ⟦ b₂ ⟧₁\n G' = ⟦ b₂ ⟧₁ ⊎G ⟦ b₁ ⟧₁ in\n {X Y : set G} → G [ X , Y ] → G' [ swap⊎ X , swap⊎ Y ]\nswapF {X = inj₁ _} {inj₁ _} f = f\nswapF {X = inj₁ _} {inj₂ _} ()\nswapF {X = inj₂ _} {inj₁ _} ()\nswapF {X = inj₂ _} {inj₂ _} f = f\n\n{-\neta : (b : B0) → List (ipath (LIFT0 ONE)) → List (ipath (TIMES1 (LIFT0 b) (RECIP1 b)))\n-- note how the input list is not used at all!\neta b _ = prod (λ a a' → _↝_ (a , tt) (a' , tt)) (elems0 b) (elems0 b)\n\neps : (b : B0) → ipath (TIMES1 (LIFT0 b) (RECIP1 b)) → ipath (LIFT0 ONE)\neps b0 (a ⇛ b) = tt ⇛ tt\n-}\n\nFunite⋆ : {b₁ : B1} → ∀ {X Y : set (discrete (ı₀ ONE) ×G ⟦ b₁ ⟧₁)} → DPath (proj₁ X) (proj₁ Y) × (_↝_ ⟦ b₁ ⟧₁) (proj₂ X) (proj₂ Y) → _↝_ ⟦ b₁ ⟧₁ (proj₂ X) (proj₂ Y) \nFunite⋆ {b₁} {tt , _} {tt , _} (reflD , y) = y\n\nFuniti⋆ : {b₁ : B1} → ∀ {X Y : set (discrete (ı₀ ONE) ×G ⟦ b₁ ⟧₁)} → _↝_ ⟦ b₁ ⟧₁ (proj₂ X) (proj₂ Y) → DPath (proj₁ X) (proj₁ Y) × (_↝_ ⟦ b₁ ⟧₁) (proj₂ X) (proj₂ Y)\nFuniti⋆ y = reflD , y\n\nmutual\n eval : {b₁ b₂ : B1} → (b₁ ⟷₁ b₂) → 1-functor ⟦ b₁ ⟧₁ ⟦ b₂ ⟧₁\n eval (swap₊ {b₁} {b₂}) = 1F swap⊎ (λ {X Y} → swapF {b₁} {b₂} {X} {Y}) \n eval (unite⋆ {b}) = 1F (elim1∣₁ b) (Funite⋆ {b})\n eval (uniti⋆ {b}) = 1F (intro1∣₁ b) (Funiti⋆ {b})\n-- eval (η⋆ b) = F₁ (objη⋆ b) (eta b )\n-- eval (ε⋆ b) = F₁ (objε⋆ b) (map (eps b))\n\n evalB : {b₁ b₂ : B1} → (b₁ ⟷₁ b₂) → 1-functor ⟦ b₂ ⟧₁ ⟦ b₁ ⟧₁\n evalB (swap₊ {b₁} {b₂}) = 1F swap⊎ ((λ {X Y} → swapF {b₂} {b₁} {X} {Y}))\n evalB (unite⋆ {b}) = 1F (intro1∣₁ b) (Funiti⋆ {b})\n evalB (uniti⋆ {b}) = 1F (elim1∣₁ b) (Funite⋆ {b})\n-- evalB (η⋆ b) = F₁ (objε⋆ b) (map (eps b))\n-- evalB (ε⋆ b) = F₁ (objη⋆ b) (eta b)\n\n{- eval assocl₊ = ? -- : { b₁ b₂ b₃ : B } → PLUS b₁ (PLUS b₂ b₃) ⟷₁ PLUS (PLUS b₁ b₂) b₃\neval assocr₊ = ? -- : { b₁ b₂ b₃ : B } → PLUS (PLUS b₁ b₂) b₃ ⟷₁ PLUS b₁ (PLUS b₂ b₃)\neval uniti⋆ = ? -- : { b : B } → b ⟷₁ TIMES ONE b\neval swap⋆ = ? -- : { b₁ b₂ : B } → TIMES b₁ b₂ ⟷₁ TIMES b₂ b₁\neval assocl⋆ = ? -- : { b₁ b₂ b₃ : B } → TIMES b₁ (TIMES b₂ b₃) ⟷₁ TIMES (TIMES b₁ b₂) b₃\neval assocr⋆ = ? -- : { b₁ b₂ b₃ : B } → TIMES (TIMES b₁ b₂) b₃ ⟷₁ TIMES b₁ (TIMES b₂ b₃)\neval dist = ? -- : { b₁ b₂ b₃ : B } → TIMES (PLUS b₁ b₂) b₃ ⟷₁ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) \neval factor = ? -- : { b₁ b₂ b₃ : B } → PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ⟷₁ TIMES (PLUS b₁ b₂) b₃\neval id⟷₁ = ? -- : { b : B } → b ⟷₁ b\neval (sym c) = ? -- : { b₁ b₂ : B } → (b₁ ⟷₁ b₂) → (b₂ ⟷₁ b₁)\neval (c₁ ∘ c₂) = ? -- : { b₁ b₂ b₃ : B } → (b₁ ⟷₁ b₂) → (b₂ ⟷₁ b₃) → (b₁ ⟷₁ b₃)\neval (c₁ ⊕ c₂) = ? -- : { b₁ b₂ b₃ b₄ : B } → (b₁ ⟷₁ b₃) → (b₂ ⟷₁ b₄) → (PLUS b₁ b₂ ⟷₁ PLUS b₃ b₄)\neval (c₁ ⊗ c₂) = ? -- : { b₁ b₂ b₃ b₄ : B } → (b₁ ⟷₁ b₃) → (b₂ ⟷₁ b₄) → (TIMES b₁ b₂ ⟷₁ TIMES b₃ b₄)\n\n---------------------------------------------------------------------------\n--}\n", "meta": {"hexsha": "059c2bc4e7654b4e491f812490b96dce2b712ec6", "size": 10071, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "F1b.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "F1b.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "F1b.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 33.0196721311, "max_line_length": 168, "alphanum_fraction": 0.4762188462, "num_tokens": 5461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544335934766, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3984719929963473}} {"text": "{-# OPTIONS --without-K --exact-split --allow-unsolved-metas #-}\n\nmodule 14-image where\n\nimport 13-propositional-truncation\nopen 13-propositional-truncation public\n\n{- We introduce the image inclusion of a map. -}\n\nprecomp-emb :\n { l1 l2 l3 l4 : Level} {X : UU l1} {A : UU l2} (f : A → X)\n {B : UU l3} ( i : B ↪ X) (q : hom-slice f (map-emb i)) →\n {C : UU l4} ( j : C ↪ X) (r : hom-slice (map-emb i) (map-emb j)) →\n hom-slice f (map-emb j)\nprecomp-emb f i q j r =\n pair\n ( ( map-hom-slice (map-emb i) (map-emb j) r) ∘\n ( map-hom-slice f (map-emb i) q))\n ( ( triangle-hom-slice f (map-emb i) q) ∙h\n ( ( triangle-hom-slice (map-emb i) (map-emb j) r) ·r\n ( map-hom-slice f (map-emb i) q)))\n\nis-prop-hom-slice :\n { l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →\n { B : UU l3} (i : B ↪ X) → is-prop (hom-slice f (map-emb i))\nis-prop-hom-slice {X = X} f i =\n is-prop-is-equiv\n ( (x : X) → fib f x → fib (map-emb i) x)\n ( fiberwise-hom-hom-slice f (map-emb i))\n ( is-equiv-fiberwise-hom-hom-slice f (map-emb i))\n ( is-prop-Π\n ( λ x → is-prop-Π\n ( λ p → is-prop-map-is-emb (map-emb i) (is-emb-map-emb i) x)))\n\nuniversal-property-image :\n ( l : Level) {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →\n { B : UU l3} (i : B ↪ X) (q : hom-slice f (map-emb i)) →\n UU (lsuc l ⊔ l1 ⊔ l2 ⊔ l3)\nuniversal-property-image l {X = X} f i q =\n ( C : UU l) (j : C ↪ X) → is-equiv (precomp-emb f i q j)\n\nuniversal-property-image' :\n ( l : Level) {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →\n { B : UU l3} (i : B ↪ X) (q : hom-slice f (map-emb i)) →\n UU (lsuc l ⊔ l1 ⊔ l2 ⊔ l3)\nuniversal-property-image' l {X = X} f i q =\n ( C : UU l) (j : C ↪ X) →\n hom-slice f (map-emb j) → hom-slice (map-emb i) (map-emb j)\n\nuniversal-property-image-universal-property-image' :\n ( l : Level) {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →\n { B : UU l3} (i : B ↪ X) (q : hom-slice f (map-emb i)) →\n universal-property-image' l f i q → universal-property-image l f i q\nuniversal-property-image-universal-property-image' l f i q up' C j =\n is-equiv-is-prop\n ( is-prop-hom-slice (map-emb i) j)\n ( is-prop-hom-slice f j)\n ( up' C j)\n \n-- Section 13.4\n\nis-small :\n (l : Level) {l1 : Level} (A : UU l1) → UU (lsuc l ⊔ l1)\nis-small l A = Σ (UU l) (λ X → A ≃ X)\n\nis-small-map :\n (l : Level) {l1 l2 : Level} {A : UU l1} {B : UU l2} →\n (A → B) → UU (lsuc l ⊔ (l1 ⊔ l2))\nis-small-map l {B = B} f = (b : B) → is-small l (fib f b)\n\nis-locally-small :\n (l : Level) {l1 : Level} (A : UU l1) → UU (lsuc l ⊔ l1)\nis-locally-small l A = (x y : A) → is-small l (Id x y)\n\ntotal-subtype :\n {l1 l2 : Level} {A : UU l1} (P : A → UU-Prop l2) → UU (l1 ⊔ l2)\ntotal-subtype {A = A} P = Σ A (λ x → pr1 (P x))\n\nequiv-subtype-equiv :\n {l1 l2 l3 l4 : Level}\n {A : UU l1} {B : UU l2} (e : A ≃ B)\n (C : A → UU-Prop l3) (D : B → UU-Prop l4) →\n ((x : A) → (C x) ↔ (D (map-equiv e x))) →\n total-subtype C ≃ total-subtype D\nequiv-subtype-equiv e C D H =\n equiv-toto (λ y → type-Prop (D y)) e\n ( λ x → equiv-iff (C x) (D (map-equiv e x)) (H x))\n\nequiv-comp-equiv' :\n {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} →\n (A ≃ B) → (C : UU l3) → (B ≃ C) ≃ (A ≃ C)\nequiv-comp-equiv' e C =\n equiv-subtype-equiv\n ( equiv-precomp-equiv e C)\n ( is-equiv-Prop)\n ( is-equiv-Prop)\n ( λ g →\n pair\n ( is-equiv-comp' g (map-equiv e) (is-equiv-map-equiv e))\n ( λ is-equiv-eg →\n is-equiv-left-factor'\n g (map-equiv e) is-equiv-eg (is-equiv-map-equiv e)))\n\nis-prop-is-small :\n (l : Level) {l1 : Level} (A : UU l1) → is-prop (is-small l A)\nis-prop-is-small l A =\n is-prop-is-contr-if-inh\n ( λ Xe →\n is-contr-equiv'\n ( Σ (UU l) (λ Y → (pr1 Xe) ≃ Y))\n ( equiv-tot ((λ Y → equiv-comp-equiv' (pr2 Xe) Y)))\n ( is-contr-total-equiv (pr1 Xe)))\n\nis-prop-is-locally-small :\n (l : Level) {l1 : Level} (A : UU l1) → is-prop (is-locally-small l A)\nis-prop-is-locally-small l A =\n is-prop-Π (λ x → is-prop-Π (λ y → is-prop-is-small l (Id x y)))\n", "meta": {"hexsha": "8598df054fd8413f472a20c194491313debb99bc", "size": 4049, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Agda/14-image.agda", "max_stars_repo_name": "hemangandhi/HoTT-Intro", "max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_stars_repo_licenses": ["CC-BY-4.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": "Agda/14-image.agda", "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_licenses": ["CC-BY-4.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": "Agda/14-image.agda", "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.313559322, "max_line_length": 71, "alphanum_fraction": 0.5334650531, "num_tokens": 1734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723317123102956, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.3984685499762407}} {"text": "\nmodule _ where\n\nmodule First where\n postulate\n C : Set → Set\n it : {A : Set} ⦃ _ : C A ⦄ → A\n X : Set\n\nmodule Second where\n open First\n postulate instance iCX : C X\n\nmodule Nested where\n open First\n x : X\n x = it -- Second.iCX is in scope\n", "meta": {"hexsha": "26ed20577ea662c16d48dd60ad126e6ad5b7e761", "size": 259, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue2489.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/Succeed/Issue2489.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/Succeed/Issue2489.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": 14.3888888889, "max_line_length": 36, "alphanum_fraction": 0.5984555985, "num_tokens": 92, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6723316991792861, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.39846854219392996}} {"text": "module Esterel.CompletionCode where\n\nopen import Data.Nat\n using (ℕ ; zero ; suc) renaming (_≟_ to _≟ℕ_ ; _⊔_ to _⊔ℕ_ ; _≤_ to _≤N_ ; _≤?_ to _≤?N_)\nopen import Data.Nat.Properties\n using (⊔-⊓-isCommutativeSemiringWithoutOne)\nopen import Function\n using (_∘_)\nopen import Relation.Nullary\n using (Dec ; yes ; no)\nopen import Relation.Binary\n using (Decidable)\nopen import Relation.Binary.PropositionalEquality\n using (_≡_ ; refl ; cong)\nimport Level\nimport Relation.Binary\nopen import Data.List using (List ; _∷_ ; [] ; _++_)\nopen import Data.List.Any.Properties using (++⁻)\n renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)\nopen import Data.Sum using (_⊎_ ; inj₁ ; inj₂)\nopen import Data.Empty using (⊥-elim)\nimport Data.Bool\nopen import Algebra.Structures\n using (IsCommutativeSemiringWithoutOne ; IsCommutativeMonoid)\n\nopen import utility\n\ndata CompletionCode : Set where\n nothin : CompletionCode\n pause : CompletionCode\n exit : ℕ → CompletionCode\n\n↓* : CompletionCode → CompletionCode\n↓* nothin = nothin\n↓* pause = pause\n↓* (exit zero) = nothin\n↓* (exit (suc n)) = exit n\n\nexit-injective : ∀{n m} → exit n ≡ exit m → n ≡ m\nexit-injective refl = refl\n\n_≟_ : Decidable {A = CompletionCode} _≡_\nnothin ≟ nothin = yes refl\nnothin ≟ pause = no λ()\nnothin ≟ exit _ = no λ()\npause ≟ nothin = no λ()\npause ≟ pause = yes refl\npause ≟ exit _ = no λ()\nexit _ ≟ nothin = no λ()\nexit _ ≟ pause = no λ()\nexit n ≟ exit m with n ≟ℕ m\n... | yes n≡m = yes (cong exit n≡m)\n... | no ¬n≡m = no (¬n≡m ∘ exit-injective)\n\nopen ListSet _≟_\n\n_⊔_ : CompletionCode → CompletionCode → CompletionCode\nnothin ⊔ r = r\npause ⊔ nothin = pause\npause ⊔ r = r\nexit n ⊔ nothin = exit n\nexit n ⊔ pause = exit n\nexit n ⊔ exit m = exit (n ⊔ℕ m)\n\n⊔-comm : ∀ c₁ c₂ → c₁ ⊔ c₂ ≡ c₂ ⊔ c₁\n⊔-comm nothin nothin = refl\n⊔-comm nothin pause = refl\n⊔-comm nothin (exit m) = refl\n⊔-comm pause nothin = refl\n⊔-comm pause pause = refl\n⊔-comm pause (exit m) = refl\n⊔-comm (exit n) nothin = refl\n⊔-comm (exit n) pause = refl\n⊔-comm (exit n) (exit m)\n rewrite IsCommutativeMonoid.comm\n (IsCommutativeSemiringWithoutOne.+-isCommutativeMonoid\n ⊔-⊓-isCommutativeSemiringWithoutOne) n m\n = refl\n\ndata _≤_ : Relation.Binary.Rel CompletionCode Level.zero where\n nothin≤c : ∀ {c} -> nothin ≤ c\n pause≤pause : pause ≤ pause\n pause≤exit : ∀ {n} -> pause ≤ exit n\n exit≤exit : ∀ {n} {m} -> (n ≤N m) -> exit n ≤ exit m\n\n_≤?_ : Decidable _≤_\nnothin ≤? c2 = yes nothin≤c\npause ≤? nothin = no (λ ())\npause ≤? pause = yes pause≤pause\npause ≤? exit x = yes pause≤exit\nexit n ≤? nothin = no (λ ())\nexit n ≤? pause = no (λ ())\nexit n ≤? exit m with n ≤?N m\nexit n ≤? exit m | yes n≤m = yes (exit≤exit n≤m)\nexit n ≤? exit m | no ¬n≤m = no ¬≤ where\n ¬≤ : Relation.Nullary.¬ (exit n ≤ exit m)\n ¬≤ (exit≤exit n) = ¬n≤m n\n\ncodessub : (List CompletionCode) → (List CompletionCode) → Set\ncodessub codes' codes = (∀ a → a ∈ codes' → a ∈ codes)\ncodesub++ll : ∀{a b c} → codessub a b → codessub a (b ++ c)\ncodesub++ll sub a a∈ = ++ˡ (sub a a∈)\n\ncodesub++both : ∀{a b c d} → codessub a c → codessub b d → codessub (a ++ b) (c ++ d)\ncodesub++both{a}{b}{c}{d} a⊂c b⊂d z z∈ with ++⁻ a z∈\n... | inj₁ z∈1 = ++ˡ (a⊂c z z∈1) \n... | inj₂ z∈2 = ++ʳ c (b⊂d z z∈2) \n\ncodesub- : ∀{a b} z → codessub a b → codessub (set-remove a z) (set-remove b z)\ncodesub-{a}{b} z a⊂b x x∈ with z ≟ x\n... | yes refl = ⊥-elim (set-remove-removed{x}{a} x∈)\n... | no ¬refl = set-remove-not-removed ¬refl (a⊂b x (set-remove-mono-∈ z x∈)) \n", "meta": {"hexsha": "2ef6db7f3ba8bf114042e351c32557504a4580b6", "size": 3599, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda/Esterel/CompletionCode.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/Esterel/CompletionCode.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/Esterel/CompletionCode.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": 31.8495575221, "max_line_length": 91, "alphanum_fraction": 0.6054459572, "num_tokens": 1417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.3984685421939299}} {"text": "-- Andreas, 2016-10-01, issue #2231\n-- The termination checker should not always see through abstract definitions.\n\nabstract\n data Nat : Set where\n zero' : Nat\n suc' : Nat → Nat\n\n -- abstract hides constructor nature of zero and suc.\n zero = zero'\n suc = suc'\n\ndata D : Nat → Set where\n c1 : ∀ n → D n → D (suc n)\n c2 : ∀ n → D n → D n\n\n-- To see that this is terminating the termination checker has to look at the\n-- natural number index, which is in a dot pattern.\nf : ∀ n → D n → Nat\nf .(suc n) (c1 n d) = f n (c2 n (c2 n d))\nf n (c2 .n d) = f n d\n\n-- Termination checking based on dot patterns should fail,\n-- since suc is abstract.\n", "meta": {"hexsha": "43853de0cae4f6ac6d710571383ecb4dbac973a5", "size": 659, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue2231.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_issues_repo_path": "test/Fail/Issue2231.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_forks_repo_path": "test/Fail/Issue2231.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "avg_line_length": 26.36, "max_line_length": 78, "alphanum_fraction": 0.6297420334, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943805178139, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3984393602836625}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\n\nmodule Cubical.Categories.Structures where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.HLevels using (isSetΣ)\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Categories.Category\n\n_∋_ : ∀ {ℓ} → (A : Type ℓ) → A → A\n_∋_ A x = x\n\nprivate\n variable\n ℓ ℓ' ℓ'' ℓ''' : Level\n 𝒞 : Precategory ℓ ℓ'\n\nrecord StructureOver (𝒞 : Precategory ℓ ℓ') ℓ'' ℓ''' : Type (ℓ-suc (ℓ-max (ℓ-max ℓ ℓ') (ℓ-max ℓ'' ℓ'''))) where\n field\n Struct : 𝒞 .ob → Type ℓ''\n IsHomo : ∀ {x y} → Struct x → Struct y → 𝒞 .hom x y → Type ℓ'''\n isPropIsHomo : ∀ {x y α β f} → isProp (IsHomo {x} {y} α β f)\n\n idnIsHomo : ∀ {x} (α : Struct x) → IsHomo α α (𝒞 .idn x)\n homoSeq : ∀ {x y z α β γ} {f : 𝒞 .hom x y} {g : 𝒞 .hom y z} →\n IsHomo α β f → IsHomo β γ g → IsHomo α γ (𝒞 .seq f g)\n\n _⊆_ : ∀ {x} → Struct x → Struct x → Type ℓ'''\n _⊆_ {x} α β = IsHomo α β (𝒞 .idn x)\n\nopen StructureOver public renaming (_⊆_ to _[_⊆_])\n\nrecord StrIsUnivalent {𝒞 : Precategory ℓ ℓ'} (S : StructureOver 𝒞 ℓ'' ℓ''') : Type (ℓ-suc (ℓ-max (ℓ-max ℓ ℓ') (ℓ-max ℓ'' ℓ'''))) where\n field\n subAntisym : ∀ {x} {α β : S .Struct x} → S [ α ⊆ β ] → S [ β ⊆ α ] → α ≡ β\n\nopen StrIsUnivalent public\n\nisPropP : {A : I → Type ℓ} {x : A i0} {y : A i1} → isProp (A i1) → PathP A x y\nisPropP Aprop = toPathP (Aprop _ _)\n\nSTRUCTURES : (𝒞 : Precategory ℓ ℓ') → StructureOver 𝒞 ℓ'' ℓ''' → Precategory (ℓ-max ℓ ℓ'') (ℓ-max ℓ' ℓ''')\nSTRUCTURES 𝒞 S .ob = Σ (𝒞 .ob) (S .Struct)\nSTRUCTURES 𝒞 S .hom (x , α) (y , β) = Σ (𝒞 .hom x y) (S .IsHomo α β)\nSTRUCTURES 𝒞 S .idn (x , α) = 𝒞 .idn x , S .idnIsHomo α\nSTRUCTURES 𝒞 S .seq (f , hᶠ) (g , hᵍ) = 𝒞 .seq f g , S .homoSeq hᶠ hᵍ\nSTRUCTURES 𝒞 S .seq-λ (f , hᶠ) = cong₂ _,_ (𝒞 .seq-λ f) (toPathP (S .isPropIsHomo _ _))\nSTRUCTURES 𝒞 S .seq-ρ (f , hᶠ) = cong₂ _,_ (𝒞 .seq-ρ f) (toPathP (S .isPropIsHomo _ _))\nSTRUCTURES 𝒞 S .seq-α (f , hᶠ) (g , hᵍ) (h , hʰ) = cong₂ _,_ (𝒞 .seq-α f g h) (toPathP (S .isPropIsHomo _ _))\n\nSTRUCTURESisCat : ⦃ 𝒞-cat : isCategory 𝒞 ⦄ {S : StructureOver 𝒞 ℓ'' ℓ'''} → isCategory (STRUCTURES 𝒞 S)\nSTRUCTURESisCat {{𝒞-cat}} {S = S} .homIsSet {x = x , α} {y = y , β} = isSetΣ (𝒞-cat .homIsSet) (λ _ → isProp→isSet (S .isPropIsHomo))\n\nSIP : ∀ ⦃ 𝒞-cat : isCategory 𝒞 ⦄ ⦃ 𝒞-univ : isUnivalent 𝒞 ⦄ → (S : StructureOver 𝒞 ℓ'' ℓ''') → ⦃ S-univ : StrIsUnivalent S ⦄ → isUnivalent (STRUCTURES 𝒞 S)\nSIP {𝒞 = 𝒞} {{𝒞-cat}} {{𝒞-univ}} S {{S-univ}} .univ (x , α) (y , β) = isoToIsEquiv (iso (pathToIso (x , α) (y , β)) catisoToPath sect ret)\n where\n catisoToPath : ∀ {x y : 𝒞 .ob} {α : S .Struct x} {β : S .Struct y} → CatIso (STRUCTURES 𝒞 S) (x , α) (y , β) → (x , α) ≡ (y , β)\n catisoToPath {x = x} {y} {α} {β} (catiso (f , hᶠ) (g , hᵍ) sec ret) = ΣPathTransport→PathΣ _ _ (x≡y , α≡β x≡y α β (subst (S .IsHomo α β) f≡h hᶠ) (subst (S .IsHomo β α) g≡h⁻¹ hᵍ))\n where\n x≅y : CatIso 𝒞 x y\n x≅y = catiso f g (cong fst sec) (cong fst ret)\n\n x≡y : x ≡ y\n x≡y = uva 𝒞-univ x≅y\n\n f≡h : f ≡ pathMor 𝒞 x≡y\n f≡h = sym (uvaPathMor 𝒞-univ x≅y)\n\n g≡h⁻¹ : g ≡ pathMor⁻ 𝒞 x≡y\n g≡h⁻¹ = sym (uvaPathMor⁻ 𝒞-univ x≅y)\n\n α≡β : ∀ {x y : 𝒞 .ob} (p : x ≡ y)\n (α : S .Struct x) (β : S .Struct y)\n (h⇒ : S .IsHomo α β (pathMor 𝒞 p)) (h⇐ : S .IsHomo β α (pathMor⁻ 𝒞 p))\n → subst (S .Struct) p α ≡ β\n α≡β {x} {y} =\n J (λ z q → ∀ (α : S .Struct x) (β : S .Struct z) (h⇒ : S .IsHomo α β (pathMor 𝒞 q)) (h⇐ : S .IsHomo β α (pathMor⁻ 𝒞 q)) → subst (S .Struct) q α ≡ β)\n (λ α β h⇒ h⇐ → transportRefl α ∙ subAntisym S-univ (subst (S .IsHomo α β) (pathMorRefl {𝒞 = 𝒞}) h⇒) (subst (S .IsHomo β α) (pathMor⁻Refl {𝒞 = 𝒞}) h⇐))\n\n sect : section (pathToIso (x , α) (y , β)) catisoToPath\n sect (catiso h h⁻¹ sec ret) = {! !}\n\n ret : retract (pathToIso (x , α) (y , β)) catisoToPath\n ret = J (λ z q → catisoToPath (pathToIso (x , α) z q) ≡ q)\n (subst {y = (pathToIso (x , α) (x , α) refl)} (λ x → catisoToPath x ≡ refl) (sym (JRefl (λ z _ → (x , α) ≅ z) ?)))\n", "meta": {"hexsha": "45de89b9b4fd55d453b9b0511517760272c238dc", "size": 4120, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Categories/Structures.agda", "max_stars_repo_name": "bijan2005/univalent-foundations", "max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "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": "Cubical/Categories/Structures.agda", "max_issues_repo_name": "bijan2005/univalent-foundations", "max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "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": "Cubical/Categories/Structures.agda", "max_forks_repo_name": "bijan2005/univalent-foundations", "max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "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": 46.8181818182, "max_line_length": 182, "alphanum_fraction": 0.5432038835, "num_tokens": 2010, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943805178139, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3984393602836625}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule PointedPi where\n\nopen import Level using (_⊔_) renaming (zero to l0; suc to lsuc)\nopen import Universe using (Universe)\n\nopen import Categories.Category using (Category)\nopen import Categories.Groupoid using (Groupoid)\nopen import Categories.Functor using (Functor)\n\nopen import Data.Empty using (⊥)\nopen import Data.Unit using (⊤; tt)\nopen import Data.Sum hiding ([_,_])\nopen import Data.Product\nopen import Relation.Binary.PropositionalEquality as P\nopen import Function using (flip)\nopen import Data.Nat using (ℕ; zero; suc)\nopen import Data.Nat.Properties.Simple using (+-right-identity)\nopen import Data.Integer using (ℤ;+_;-[1+_]) renaming (suc to ℤsuc; -_ to ℤ-; _+_ to _ℤ+_)\n\nopen import Data.List using (List; foldr; replicate; _++_) renaming (map to Lmap; [] to nil; _∷_ to _∷:_)\nopen import Data.List.Any using (module Membership-≡; here; there)\nopen Membership-≡\nopen import Data.List.Properties using ()\n\nopen import Categories.Groupoid.Sum using () renaming (Sum to GSum)\nopen import Categories.Groupoid.Product using () renaming (Product to GProduct)\n\nopen import PiU using (U; ZERO; ONE; PLUS; TIMES; toℕ)\nopen import PiLevel0\nopen import PiLevel1\nopen import PiEquiv renaming (eval to ap; evalB to apB)\nopen import Equiv\n\nopen import PiIter\n\ndata Pointed (t : U) : Set where\n ∙ : ⟦ t ⟧ → Pointed t\n\n-- yes, re-use name eval on purpose here\neval : {t₁ t₂ : U} → (t₁ ⟷ t₂) → Pointed t₁ → Pointed t₂\neval c (∙ x) = ∙ (ap c x)\n\n-- all our values will be 'subtypes' of this:\nrecord V (t : U) : Set where\n constructor v\n field\n pt : ⟦ t ⟧\n auto : t ⟷ t\n\nevalV : {t₁ t₂ : U} → (t₁ ⟷ t₂) → V t₁ → V t₂\nevalV c (v pt auto) = v (ap c pt) (! c ◎ auto ◎ c)\n\n-- V equivalence\nrecord _≈_ {t : U} (a : V t) (b : V t) : Set where\n constructor veq\n field\n pt-eq : V.pt a P.≡ V.pt b\n auto-eq : V.auto a ⇔ V.auto b\n \n-- and in general, all our morphisms will be 'subtypes' of\nrecord H {s t : U} (a : V s) (b : V t) : Set where\n constructor mor\n field\n transp : s ⟷ t\n t-eq : evalV transp a ≈ b\n\n--- Generating sets: lists of combinators over a type\nGenSet : U → Set\nGenSet t = List (t ⟷ t)\n\n-- We will need to use a choice between 3 things. Don't want\n-- to abuse ⊎. The 3 things can be understood as\n-- Forward, Backward and Neutral. So we name it ⇕.\ninfix 30 _⇕_\n\ndata _⇕_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where\n Fwd : (x : A) → A ⇕ B\n Bwd : (y : B) → A ⇕ B\n Neu : A ⇕ B\n \n-- note that this uses ≡ (inside ∈), not ⇔. On purpose.\ninGS : {t : U} → GenSet t → Set\ninGS {t} S = Σ (t ⟷ t) (λ p → (p ∈ S) ⇕ (p ∈ S))\n\n-- flip a ⇕\nflip⇕ : ∀ {a b} {A : Set a} {B : Set b} → A ⇕ B → B ⇕ A\nflip⇕ (Fwd x) = Bwd x\nflip⇕ (Bwd y) = Fwd y\nflip⇕ Neu = Neu\n\n-- type of sequences of applications from GenSet\nCombS : {t : U} → GenSet t → Set\nCombS {t} S = List ( inGS S )\n\nextract : {t : U} {S : GenSet t} → inGS S → (t ⟷ t)\nextract (p , Fwd x) = p\nextract (p , Bwd y) = ! p\nextract (p , Neu ) = id⟷\n\ninterp : {t : U} {S : GenSet t} → CombS S → (t ⟷ t)\ninterp l = foldr _◎_ id⟷ (Lmap extract l)\n\n-- the combinator (CombS S) acts as a sort of reference point\ndata U↑ : Set where\n ↑ : U → U↑\n # : {τ : U} → (S : GenSet τ) → CombS S → U↑\n 1/ : {τ : U} → (S : GenSet τ) → CombS S → U↑\n _⊞_ : U↑ → U↑ → U↑\n _⊠_ : U↑ → U↑ → U↑\n \ninfix 40 _⇿_\n\ndata _⇿_ : U↑ → U↑ → Set where\n ↑ : {t₁ t₂ : U} → t₁ ⟷ t₂ → ↑ t₁ ⇿ ↑ t₂\n ev : {t₁ : U} {S : GenSet t₁} → (q : CombS S) → ((# S q) ⊠ (1/ S q)) ⇿ ↑ ONE\n coev : {t₁ : U} {S : GenSet t₁} → (q : CombS S) → ↑ ONE ⇿ ((# S q) ⊠ (1/ S q))\n id⇿ : {t₁ : U↑} → t₁ ⇿ t₁ -- needed for coev of ⊠\n\nUG : Universe l0 (lsuc l0)\nUG = record {\n U = U↑\n ; El = λ T → Σ[ ℂ ∈ Category l0 l0 l0 ] (Groupoid ℂ)\n }\n\n-- for convenience, create some types which are embedable into V\nD : U → Set\nD t = ⟦ t ⟧\n\nembedD : {t : U} → D t → V t\nembedD w = v w id⟷\n\n-- and D equality lifts to ≈\nembedDeq : {τ : U} → (s t : D τ) → s ≡ t → embedD s ≈ embedD t\nembedDeq s .s P.refl = veq P.refl id⇔\n\n-- even more to the point, it lifts to describing Hom sets\n-- note how we can't use embedDeq directly!\nembedDHom : {τ : U} → (s t : D τ) → s ≡ t → H (embedD s) (embedD t)\nembedDHom s .s P.refl = mor id⟷ (veq P.refl (trans⇔ idl◎l idl◎l))\n\n-- this is the same as in 2DTypes/groupoid\ndiscreteC : U → Category _ _ _\ndiscreteC t = record {\n Obj = D t\n ; _⇒_ = λ s₁ s₂ → s₁ P.≡ s₂ -- see embedDHom\n ; _≡_ = λ _ _ → ⊤ -- hard-code proof-irrelevance\n ; id = P.refl \n ; _∘_ = flip P.trans\n ; assoc = tt \n ; identityˡ = tt \n ; identityʳ = tt\n ; equiv = record { refl = tt ; sym = λ _ → tt ; trans = λ _ _ → tt } \n ; ∘-resp-≡ = λ _ _ → tt\n }\n-- ditto\ndiscreteG : (t : U) → Groupoid (discreteC t)\ndiscreteG S = record\n { _⁻¹ = λ { {A} {.A} refl → P.refl }\n ; iso = record { isoˡ = tt; isoʳ = tt }\n }\n\n-----------\n\n--- Structure theorems for ⇕\nextract-GS[]≡id⟷ : ∀ {t : U} → (gs : GenSet t) → gs ≡ nil →\n (∀ (y : inGS gs) → extract y ≡ id⟷)\nextract-GS[]≡id⟷ .nil refl (p , Fwd ())\nextract-GS[]≡id⟷ .nil refl (p , Bwd ())\nextract-GS[]≡id⟷ .nil refl (p , Neu) = refl\n\nprivate\n Iter→CombS : ∀ {τ : U} (c : τ ⟷ τ) → Iter c → CombS (c ∷: nil)\n Iter→CombS p (iter (+_ n) _ _) = replicate n (p , Fwd (here refl))\n Iter→CombS p (iter (-[1+_] n) _ _) = replicate (suc n) (p , Bwd (here refl))\n\n CombS→Iter : ∀ {τ : U} (c : τ ⟷ τ) → CombS (c ∷: nil) → Iter c\n CombS→Iter p nil = iter (+ 0) id⟷ id⇔\n CombS→Iter p (x ∷: xs) with CombS→Iter p xs\n CombS→Iter p ((.p , Fwd (here refl)) ∷: xs) | iter i q pf =\n iter (ℤsuc i) (p ◎ q) (trans⇔ (id⇔ ⊡ pf)\n (trans⇔ (idr◎r ⊡ id⇔) (2! (lower (+ 1) i))))\n CombS→Iter p ((p' , Fwd (there ())) ∷: xs) | iter i q pf\n CombS→Iter p ((.p , Bwd (here refl)) ∷: xs) | iter i q pf =\n iter (i ℤ+ -[1+ 0 ]) (q ◎ (! p))\n (trans⇔ (pf ⊡ id⇔) (2! (lower i -[1+ 0 ])))\n CombS→Iter p ((p' , Bwd (there ())) ∷: xs) | iter i q pf\n CombS→Iter p ((p' , Neu) ∷: xs) | iter i q pf = iter i q pf\n\n -- split Fwd case from Bwd\n preserve-iter : ∀ {τ : U} (c : τ ⟷ τ) → (n : ℕ) →\n let p = CombS→Iter c (replicate n (c , Fwd (here refl))) in\n Iter.i p ≡ + n\n preserve-iter c zero = refl\n preserve-iter c (suc n) = cong ℤsuc (preserve-iter c n)\n\n preserve-iterB : ∀ {τ : U} (c : τ ⟷ τ) → (n : ℕ) →\n let p = CombS→Iter c (replicate (suc n) (c , Bwd (here refl))) in\n Iter.i p ≡ -[1+ n ]\n preserve-iterB c zero = refl\n preserve-iterB c (suc i) = P.trans\n (cong (λ z → z ℤ+ -[1+ 0 ]) (preserve-iterB c i))\n (cong (λ z → -[1+ (suc z) ]) (+-right-identity i))\n\n P2C2P : ∀ {τ : U} (c : τ ⟷ τ) → (p : Iter c) → (CombS→Iter c (Iter→CombS c p)) ≡c p\n P2C2P c (iter (+_ zero) p' p'⇔p^i) = eqc refl (2! p'⇔p^i)\n P2C2P c (iter (+_ (suc n)) p' p'⇔p^i) with CombS→Iter c (replicate n (c , Fwd (here refl))) | P.inspect (λ nn → CombS→Iter c (replicate nn (c , Fwd (here refl)))) n\n ... | iter i q pf | [ eq ] =\n let i=n = (P.trans (cong Iter.i (P.sym eq)) (preserve-iter c n)) in\n eqc (cong ℤsuc i=n) (trans⇔ (id⇔ {c = c} ⊡ pf)\n (trans⇔ (id⇔ ⊡ P.subst (λ j → c ^ i ⇔ c ^ j) i=n (id⇔ {c = c ^ i})) (2! p'⇔p^i)))\n P2C2P c (iter (-[1+_] n) p' p'⇔p^i) with CombS→Iter c (replicate (suc n) (c , Bwd (here refl))) | P.inspect (λ nn → CombS→Iter c (replicate (suc nn) (c , Bwd (here refl)))) n\n ... | iter i q pf | [ eq ] = \n let i=n = P.trans (cong Iter.i (P.sym eq)) (preserve-iterB c n) in\n eqc i=n (trans⇔ (P.subst (λ j → q ⇔ c ^ j) i=n pf) (2! p'⇔p^i))\n\n C2P2C : ∀ {τ : U} (c : τ ⟷ τ) → (q : CombS (c ∷: nil)) →\n interp (Iter→CombS c (CombS→Iter c q)) ⇔ interp q\n C2P2C c nil = id⇔\n C2P2C c (x ∷: q) with CombS→Iter c q | (C2P2C c) q\n C2P2C c ((.c , Fwd (here refl)) ∷: q) | iter (+_ n) p' pf | pf2 = id⇔ ⊡ pf2\n C2P2C c ((.c , Fwd (here refl)) ∷: q) | iter (-[1+_] zero) p' pf | pf2 =\n trans⇔ (linv◎r {c = c}) (id⇔ ⊡ trans⇔ idr◎r pf2) \n C2P2C c ((.c , Fwd (here refl)) ∷: q) | iter (-[1+_] (suc n)) p' pf | pf2 =\n trans⇔ (trans⇔ idl◎r (linv◎r ⊡ id⇔)) (trans⇔ assoc◎r (id⇔ ⊡ pf2))\n C2P2C c ((comb , Fwd (there ())) ∷: q) | iter i p' pf | pf2\n C2P2C c ((.c , Bwd (here refl)) ∷: q) | iter (+_ zero) p' pf | pf2 = id⇔ ⊡ pf2\n C2P2C c ((.c , Bwd (here refl)) ∷: q) | iter (+_ (suc n)) p' pf | pf2 = \n trans⇔ (trans⇔ idl◎r (rinv◎r ⊡ id⇔)) (trans⇔ assoc◎r (id⇔ ⊡ pf2))\n C2P2C c ((.c , Bwd (here refl)) ∷: q) | iter (-[1+_] n) p' pf | pf2 =\n id⇔ {c = ! c} ⊡ (P.subst (λ j → ! c ◎ foldr _◎_ id⟷ (Lmap extract (replicate j (c , Bwd (here refl)))) ⇔ foldr _◎_ id⟷ (Lmap extract q)) (P.sym (+-right-identity n)) pf2)\n C2P2C c ((comb , Bwd (there ())) ∷: q) | iter i p' pf | pf2\n C2P2C c ((comb , Neu) ∷: q) | iter i p' pf | pf2 = trans⇔ pf2 idl◎r\n \n-- we would like to say:\n-- Iter[p]≃CombS[p] : ∀ {τ : U} (p : τ ⟷ τ) → Iter p ≃ CombS (p ∷: nil)\n-- but the homotopies have the wrong type (≡ rather than ≡c and ⇔).\n\n-----------\n-- Generalization of # p to # S.\n\norderC : {τ : U} → (S : GenSet τ) → Category _ _ _\norderC {τ} S = record {\n Obj = CombS S\n ; _⇒_ = λ q₁ q₂ → interp q₁ ⇔ interp q₂\n ; _≡_ = λ _ _ → ⊤ \n ; id = id⇔\n ; _∘_ = flip trans⇔\n ; assoc = tt\n ; identityˡ = tt\n ; identityʳ = tt \n ; equiv = record { refl = tt; sym = λ _ → tt; trans = λ _ _ → tt }\n ; ∘-resp-≡ = λ _ _ → tt\n }\n\norderG : {τ : U} → (S : GenSet τ) → Groupoid (orderC S)\norderG {τ} S = record {\n _⁻¹ = 2!\n ; iso = record {\n isoˡ = tt\n ; isoʳ = tt\n }\n }\n\ncommute-interp-++ : ∀ {τ : U} {S : GenSet τ} (f g : CombS S) →\n interp (f ++ g) ⇔ interp f ◎ interp g\ncommute-interp-++ nil g = idl◎r\ncommute-interp-++ (x ∷: f) g = trans⇔ (id⇔ ⊡ commute-interp-++ f g) assoc◎l\n\n1/orderC : {τ : U} → (S : GenSet τ) → Category _ _ _\n1/orderC S = record {\n Obj = ⊤\n ; _⇒_ = λ _ _ → CombS S\n ; _≡_ = λ p q → interp p ⇔ interp q\n ; id = nil\n ; _∘_ = _++_\n ; assoc = λ { {f = f} {g} {h} → trans⇔ (commute-interp-++ (h ++ g) f) (\n trans⇔ (commute-interp-++ h g ⊡ id⇔) (\n trans⇔ assoc◎r (\n trans⇔ (id⇔ ⊡ (2! (commute-interp-++ g f))) (\n 2! (commute-interp-++ h (g ++ f)))))) }\n ; identityˡ = id⇔ -- could also use idl◎l like below\n ; identityʳ = λ { {f = f} → trans⇔ (commute-interp-++ f nil) idr◎l }\n ; equiv = record { refl = id⇔ ; sym = 2! ; trans = trans⇔ }\n ; ∘-resp-≡ = λ { {f = f} {h} {g} {i} f⇔h g⇔i →\n trans⇔ (commute-interp-++ f g) (trans⇔ (f⇔h ⊡ g⇔i) (2! (commute-interp-++ h i))) }\n }\n\nflipGS : {τ : U} {S : GenSet τ} → inGS S → inGS S\nflipGS (c , pf) = c , flip⇕ pf\n\ninvert-CombS : {τ : U} {S : GenSet τ} → CombS S → CombS S\ninvert-CombS pl = Data.List.map flipGS (Data.List.reverse pl)\n\n-- sometimes we need to do some list manipulations under interp \nlift-≡ : {t₁ t₂ : U} {p q : t₁ ⟷ t₂} → p ≡ q → p ⇔ q\nlift-≡ refl = id⇔\n\ninterp-invert : {τ : U} {S : GenSet τ} → (x : inGS S) → (f : CombS S) →\n interp (invert-CombS (x ∷: f)) ⇔ interp (invert-CombS f) ◎ extract (flipGS x)\ninterp-invert (c , Fwd x) f = {!!}\ninterp-invert (c , Bwd y) f = {!!}\ninterp-invert (c , Neu) f = {!!}\n\nextract-flipGS : {τ : U} {S : GenSet τ} → (x : inGS S) → extract (flipGS x) ⇔ ! (extract x)\nextract-flipGS (proj₁ , Fwd x) = id⇔\nextract-flipGS (proj₁ , Bwd y) = 2! !!⇔id\nextract-flipGS (proj₁ , Neu) = id⇔\n\nprivate\n left-invCS : {τ : U} {S : GenSet τ} (f : CombS S) → interp (invert-CombS f ++ f) ⇔ id⟷\n left-invCS nil = id⇔\n left-invCS (x ∷: f) = trans⇔\n (commute-interp-++ (invert-CombS (x ∷: f)) (x ∷: f)) (trans⇔\n (interp-invert x f ⊡ id⇔) (trans⇔\n assoc◎r (trans⇔\n (id⇔ ⊡ assoc◎l) (trans⇔\n (id⇔ ⊡ trans⇔ (trans⇔ (extract-flipGS x ⊡ id⇔) rinv◎l ⊡ id⇔) idl◎l) (trans⇔\n (2! (commute-interp-++ (invert-CombS f) f)) (left-invCS f))))))\n\n right-invCS : {τ : U} {S : GenSet τ} (f : CombS S) → interp (f ++ invert-CombS f) ⇔ id⟷\n right-invCS l = {!!}\n \n1/orderG : {τ : U} → (S : GenSet τ) → Groupoid (1/orderC S)\n1/orderG s = record {\n _⁻¹ = invert-CombS\n ; iso = λ {_} {_} {f} → record {\n isoˡ = left-invCS f\n ; isoʳ = right-invCS f\n }\n }\n \n-----------\n--- Our semantics into groupoids\n⟦_⟧↑ : (T : U↑) → Universe.El UG T\n⟦ ↑ S ⟧↑ = , discreteG S\n⟦ # S q ⟧↑ = , orderG S -- the base point doesn't matter here?\n⟦ 1/ S q ⟧↑ = , 1/orderG S -- ditto?\n⟦ x ⊞ y ⟧↑ with ⟦ x ⟧↑ | ⟦ y ⟧↑\n... | (_ , G₁) | (_ , G₂) = , GSum G₁ G₂\n⟦ x ⊠ y ⟧↑ with ⟦ x ⟧↑ | ⟦ y ⟧↑\n... | (_ , G₁) | (_ , G₂) = , GProduct G₁ G₂\n\nrecord W (t : U↑) : Set where\n constructor w\n field\n pt : Category.Obj (proj₁ ⟦ t ⟧↑)\n auto : Category._⇒_ (proj₁ ⟦ t ⟧↑) pt pt\n\nevalW : {s t : U↑} → s ⇿ t → W s → W t\nevalW (↑ x) (w pt auto) = w (ap x pt) refl\nevalW (ev q) (w (cc , tt) (cc⇔cc-pf , cc')) = w tt refl -- this is cheating, cc <=> cc' ??\nevalW (coev q) (w tt refl) = w (q , tt) (id⇔ , q) -- but this isn't.\nevalW id⇿ (w pt auto) = w pt auto\n\n-- This should actually be Hom-set inhabitation, aka categorical equivalence\n-- (as we are in a groupoid setting).\nObjEq : (t : U↑) → Category.Obj (proj₁ ⟦ t ⟧↑) → Category.Obj (proj₁ ⟦ t ⟧↑) → Set\nObjEq (↑ x) a b = a P.≡ b\nObjEq (# S x) a b = interp a ⇔ interp b\nObjEq (1/ S x) a b = ⊤\nObjEq (s ⊞ t) (inj₁ x) (inj₁ y) = ObjEq s x y\nObjEq (s ⊞ t) (inj₁ x) (inj₂ y) = ⊥\nObjEq (s ⊞ t) (inj₂ y) (inj₁ x) = ⊥\nObjEq (s ⊞ t) (inj₂ x) (inj₂ y) = ObjEq t x y\nObjEq (s ⊠ t) (a , b) (c , d) = ObjEq s a c × ObjEq t b d\n\nHomEq : (t : U↑) → (a b : Category.Obj (proj₁ ⟦ t ⟧↑)) →\n Category._⇒_ (proj₁ ⟦ t ⟧↑) a b → Category._⇒_ (proj₁ ⟦ t ⟧↑) a b → Set\nHomEq (↑ x) a b h1 h2 = ⊤ -- this is basically proof-irrelevance h1 h2\nHomEq (# S x) a b h1 h2 = ⊤ -- because h1 and h2 are the exact same ⇔\nHomEq (1/ S x) tt tt h1 h2 = interp h1 ⇔ interp h2 -- here!\nHomEq (s ⊞ t) (inj₁ x) (inj₁ x₁) h1 h2 = HomEq s x x₁ h1 h2\nHomEq (s ⊞ t) (inj₁ x) (inj₂ y) (Level.lift ()) h2\nHomEq (s ⊞ t) (inj₂ y) (inj₁ x) (Level.lift ()) h2\nHomEq (s ⊞ t) (inj₂ y) (inj₂ y₁) h1 h2 = HomEq t y y₁ h1 h2\nHomEq (s ⊠ t) (a , b) (c , d) (a⇒c , b⇒d) (a⇒c' , b⇒d') =\n HomEq s a c a⇒c a⇒c' × HomEq t b d b⇒d b⇒d'\n\n-- W equivalence; note that transp is restricted to be the Homs of cat\n-- we might want to restrict that more.\nrecord _≈W_ {t : U↑} (a : W t) (b : W t) : Set where\n constructor weq\n cat = proj₁ ⟦ t ⟧↑\n gpd = proj₂ ⟦ t ⟧↑\n _∘_ = Category._∘_ cat\n field\n pt-eq : ObjEq t (W.pt a) (W.pt b)\n transp : Category._⇒_ cat (W.pt a) (W.pt b)\n auto-eq : HomEq t (W.pt a) (W.pt b) (W.auto b ∘ (transp ∘ (W.auto a))) transp\n", "meta": {"hexsha": "384153d0994d6905e18597d967092ab4b65bbab6", "size": 14285, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Univalence/PointedPi.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "Univalence/PointedPi.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "Univalence/PointedPi.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 36.4413265306, "max_line_length": 176, "alphanum_fraction": 0.5391669583, "num_tokens": 6419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6513548782017745, "lm_q2_score": 0.6113819732941511, "lm_q1q2_score": 0.3982266307497724}} {"text": "------------------------------------------------------------------------\n-- Extra lemmas about substitutions\n------------------------------------------------------------------------\n\nmodule Data.Fin.Substitution.ExtraLemmas where\n\nopen import Data.Fin as Fin using (Fin; zero; suc)\nopen import Data.Fin.Substitution\nopen import Data.Fin.Substitution.Lemmas\nopen import Data.Nat using (ℕ; zero; suc; _+_)\nopen import Data.Star using (Star; ε; _◅_; _▻_)\nopen import Data.Vec using (Vec; _∷_; lookup; map)\nopen import Data.Vec.All hiding (lookup; map)\nopen import Data.Vec.Properties using (lookup-map; map-cong; map-∘)\nopen import Function using (_∘_; _$_; flip)\nopen import Relation.Binary.PropositionalEquality as PropEq hiding (subst)\nopen PropEq.≡-Reasoning\n\n-- Simple extension of substitutions.\n--\n-- FIXME: this should go into Data.Fin.Substitution.\nrecord Extension (T : ℕ → Set) : Set where\n infixr 5 _/∷_\n\n field weaken : ∀ {n} → T n → T (suc n) -- Weakens Ts.\n\n -- Extension.\n _/∷_ : ∀ {m n} → T (suc n) → Sub T m n → Sub T (suc m) (suc n)\n t /∷ ρ = t ∷ map weaken ρ\n\n-- Helper module\nmodule SimpleExt {T} (simple : Simple T) where\n open Simple simple public\n\n extension : Extension T\n extension = record { weaken = weaken }\n open Extension extension public hiding (weaken)\n\n-- An generalized version of Data.Fin.Lemmas.Lemmas₀\n--\n-- FIXME: this should go into Data.Fin.Substitution.Lemmas.\nmodule ExtLemmas₀ {T} (lemmas₀ : Lemmas₀ T) where\n\n open Lemmas₀ lemmas₀ public hiding (lookup-map-weaken-↑⋆)\n open SimpleExt simple\n\n -- A generalized variant of Lemmas₀.lookup-map-weaken-↑⋆.\n lookup-map-weaken-↑⋆ : ∀ {m n} k x {ρ : Sub T m n} {t} →\n lookup x (map weaken ρ ↑⋆ k) ≡\n lookup (Fin.lift k suc x) ((t /∷ ρ) ↑⋆ k)\n lookup-map-weaken-↑⋆ zero x = refl\n lookup-map-weaken-↑⋆ (suc k) zero = refl\n lookup-map-weaken-↑⋆ (suc k) (suc x) {ρ} {t} = begin\n lookup x (map weaken (map weaken ρ ↑⋆ k))\n ≡⟨ lookup-map x weaken _ ⟩\n weaken (lookup x (map weaken ρ ↑⋆ k))\n ≡⟨ cong weaken (lookup-map-weaken-↑⋆ k x) ⟩\n weaken (lookup (Fin.lift k suc x) ((t /∷ ρ) ↑⋆ k))\n ≡⟨ sym (lookup-map (Fin.lift k suc x) weaken _) ⟩\n lookup (Fin.lift k suc x) (map weaken ((t /∷ ρ) ↑⋆ k))\n ∎\n\n-- A generalized version of Data.Fin.Lemmas.Lemmas₄\n--\n-- FIXME: this should go into Data.Fin.Substitution.Lemmas.\nmodule ExtLemmas₄ {T} (lemmas₄ : Lemmas₄ T) where\n\n open Lemmas₄ lemmas₄ public hiding (⊙-wk; wk-commutes)\n open Lemmas₃ lemmas₃ using (lookup-wk-↑⋆-⊙; /✶-↑✶′)\n open SimpleExt simple using (_/∷_)\n open ExtLemmas₀ lemmas₀ using (lookup-map-weaken-↑⋆)\n\n private\n\n ⊙-wk′ : ∀ {m n} {ρ : Sub T m n} {t} k →\n ρ ↑⋆ k ⊙ wk ↑⋆ k ≡ wk ↑⋆ k ⊙ (t /∷ ρ) ↑⋆ k\n ⊙-wk′ {ρ = ρ} {t} k = sym (begin\n wk ↑⋆ k ⊙ (t /∷ ρ) ↑⋆ k ≡⟨ lemma ⟩\n map weaken ρ ↑⋆ k ≡⟨ cong (λ ρ′ → ρ′ ↑⋆ k) map-weaken ⟩\n (ρ ⊙ wk) ↑⋆ k ≡⟨ ↑⋆-distrib k ⟩\n ρ ↑⋆ k ⊙ wk ↑⋆ k ∎)\n where\n lemma = extensionality λ x → begin\n lookup x (wk ↑⋆ k ⊙ (t /∷ ρ) ↑⋆ k)\n ≡⟨ lookup-wk-↑⋆-⊙ k ⟩\n lookup (Fin.lift k suc x) ((t /∷ ρ) ↑⋆ k)\n ≡⟨ sym (lookup-map-weaken-↑⋆ k x) ⟩\n lookup x (map weaken ρ ↑⋆ k)\n ∎\n\n ⊙-wk : ∀ {m n} {ρ : Sub T m n} {t} → ρ ⊙ wk ≡ wk ⊙ (t /∷ ρ)\n ⊙-wk = ⊙-wk′ zero\n\n wk-commutes : ∀ {m n} {ρ : Sub T m n} {t′} t →\n t / ρ / wk ≡ t / wk / (t′ /∷ ρ)\n wk-commutes {ρ = ρ} {t} = /✶-↑✶′ (ε ▻ ρ ▻ wk) (ε ▻ wk ▻ (t /∷ ρ)) ⊙-wk′ zero\n\n -- A handy helper lemma: weakening commutes with substitution.\n weaken-/ : ∀ {m n} {ρ : Sub T m n} {t′} t →\n weaken (t / ρ) ≡ weaken t / (t′ /∷ ρ)\n weaken-/ {ρ = ρ} {t′} t = begin\n weaken (t / ρ) ≡⟨ sym /-wk ⟩\n t / ρ / wk ≡⟨ wk-commutes t ⟩\n t / wk / (t′ /∷ ρ) ≡⟨ cong₂ _/_ /-wk refl ⟩\n weaken t / (t′ /∷ ρ) ∎\n\n-- A generalize version of Data.Fin.Lemmas.AppLemmas\n--\n-- FIXME: this should go into Data.Fin.Substitution.Lemmas.\nmodule ExtAppLemmas {T₁ T₂} (appLemmas : AppLemmas T₁ T₂) where\n\n open AppLemmas appLemmas public hiding (wk-commutes)\n open SimpleExt simple using (_/∷_)\n private module L₄ = ExtLemmas₄ lemmas₄\n\n wk-commutes : ∀ {m n} {ρ : Sub T₂ m n} {t′} t →\n t / ρ / wk ≡ t / wk / (t′ /∷ ρ)\n wk-commutes {ρ = ρ} {t} = ⨀→/✶ (ε ▻ ρ ▻ wk) (ε ▻ wk ▻ (t /∷ ρ)) L₄.⊙-wk\n\n-- Lemmas relating T₃ substitutions in T₁ and T₂.\nrecord LiftAppLemmas (T₁ T₂ T₃ : ℕ → Set) : Set where\n field\n lift : ∀ {n} → T₃ n → T₂ n\n application₁₃ : Application T₁ T₃\n application₂₃ : Application T₂ T₃\n lemmas₂ : Lemmas₄ T₂\n lemmas₃ : Lemmas₄ T₃\n\n private\n module L₂ = ExtLemmas₄ lemmas₂\n module L₃ = ExtLemmas₄ lemmas₃\n module A₁ = Application application₁₃\n module A₂ = Application application₂₃\n\n field\n -- Lifting commutes with application of T₃ substitutions.\n lift-/ : ∀ {m n} t {σ : Sub T₃ m n} → lift (t L₃./ σ) ≡ lift t A₂./ σ\n\n -- Lifting preserves variables.\n lift-var : ∀ {n} (x : Fin n) → lift (L₃.var x) ≡ L₂.var x\n\n -- Sequences of T₃ substitutions are equivalent when applied to\n -- T₁s if they are equivalent when applied to T₂ variables.\n /✶-↑✶ :\n ∀ {m n} (σs₁ σs₂ : Subs T₃ m n) →\n (∀ k x → L₂.var x A₂./✶ σs₁ L₃.↑✶ k ≡ L₂.var x A₂./✶ σs₂ L₃.↑✶ k) →\n ∀ k t → t A₁./✶ σs₁ L₃.↑✶ k ≡ t A₁./✶ σs₂ L₃.↑✶ k\n\n lift-lookup-⊙ : ∀ {m n k} x {σ₁ : Sub T₃ m n} {σ₂ : Sub T₃ n k} →\n lift (lookup x (σ₁ L₃.⊙ σ₂)) ≡ lift (lookup x σ₁) A₂./ σ₂\n lift-lookup-⊙ x {σ₁} {σ₂} = begin\n lift (lookup x (σ₁ L₃.⊙ σ₂)) ≡⟨ cong lift (L₃.lookup-⊙ x) ⟩\n lift (lookup x σ₁ L₃./ σ₂) ≡⟨ lift-/ _ ⟩\n lift (lookup x σ₁) A₂./ σ₂ ∎\n\n lift-lookup-⨀ : ∀ {m n} x (σs : Subs T₃ m n) →\n lift (lookup x (L₃.⨀ σs)) ≡ L₂.var x A₂./✶ σs\n lift-lookup-⨀ x ε = begin\n lift (lookup x L₃.id) ≡⟨ cong lift (L₃.lookup-id x) ⟩\n lift (L₃.var x) ≡⟨ lift-var x ⟩\n L₂.var x ∎\n lift-lookup-⨀ x (σ ◅ ε) = begin\n lift (lookup x σ) ≡⟨ cong lift (sym L₃.var-/) ⟩\n lift (L₃.var x L₃./ σ) ≡⟨ lift-/ _ ⟩\n lift (L₃.var x) A₂./ σ ≡⟨ cong₂ A₂._/_ (lift-var x) refl ⟩\n L₂.var x A₂./ σ ∎\n lift-lookup-⨀ x (σ ◅ (σ′ ◅ σs′)) = begin\n lift (lookup x (L₃.⨀ σs L₃.⊙ σ))\n ≡⟨ lift-lookup-⊙ x ⟩\n lift (lookup x (L₃.⨀ σs)) A₂./ σ\n ≡⟨ cong₂ A₂._/_ (lift-lookup-⨀ x (σ′ ◅ σs′)) refl ⟩\n L₂.var x A₂./✶ σs A₂./ σ\n ∎\n where σs = σ′ ◅ σs′\n\n -- Sequences of T₃ substitutions are equivalent when applied to\n -- T₁s if they are equivalent when applied as composites.\n /✶-↑✶′ : ∀ {m n} (σs₁ σs₂ : Subs T₃ m n) →\n (∀ k → L₃.⨀ (σs₁ L₃.↑✶ k) ≡ L₃.⨀ (σs₂ L₃.↑✶ k)) →\n ∀ k t → t A₁./✶ σs₁ L₃.↑✶ k ≡ t A₁./✶ σs₂ L₃.↑✶ k\n /✶-↑✶′ σs₁ σs₂ hyp = /✶-↑✶ σs₁ σs₂ (λ k x → begin\n L₂.var x A₂./✶ σs₁ L₃.↑✶ k\n ≡⟨ sym (lift-lookup-⨀ x (σs₁ L₃.↑✶ k)) ⟩\n lift (lookup x (L₃.⨀ (σs₁ L₃.↑✶ k)))\n ≡⟨ cong (lift ∘ lookup x) (hyp k) ⟩\n lift (lookup x (L₃.⨀ (σs₂ L₃.↑✶ k)))\n ≡⟨ lift-lookup-⨀ x (σs₂ L₃.↑✶ k) ⟩\n L₂.var x A₂./✶ σs₂ L₃.↑✶ k\n ∎)\n\n -- Derived lemmas about applications of T₃ substitutions to T₁s.\n appLemmas : AppLemmas T₁ T₃\n appLemmas = record\n { application = application₁₃\n ; lemmas₄ = lemmas₃\n ; id-vanishes = /✶-↑✶′ (ε ▻ L₃.id) ε L₃.id-↑⋆ 0\n ; /-⊙ = /✶-↑✶′ (ε ▻ _ L₃.⊙ _) (ε ▻ _ ▻ _) L₃.↑⋆-distrib 0\n }\n open ExtAppLemmas appLemmas public\n hiding (application; lemmas₂; lemmas₃; var; weaken; subst; simple)\n\n-- Lemmas relating T₂ and T₃ substitutions in T₁.\nrecord LiftSubLemmas (T₁ T₂ T₃ : ℕ → Set) : Set where\n field\n application₁₂ : Application T₁ T₂\n liftAppLemmas : LiftAppLemmas T₁ T₂ T₃\n\n open LiftAppLemmas liftAppLemmas hiding (/✶-↑✶; /-wk)\n private\n module L₃ = ExtLemmas₄ lemmas₃\n module L₂ = ExtLemmas₄ lemmas₂\n module A₁₂ = Application application₁₂\n module A₁₃ = Application (AppLemmas.application appLemmas)\n module A₂₃ = Application application₂₃\n\n field\n -- Weakening commutes with lifting.\n weaken-lift : ∀ {n} (t : T₃ n) → L₂.weaken (lift t) ≡ lift (L₃.weaken t)\n\n -- Applying a composition of T₂ substitutions to T₁s\n -- corresponds to two consecutive applications.\n /-⊙₂ : ∀ {m n k} {σ₁ : Sub T₂ m n} {σ₂ : Sub T₂ n k} t →\n t A₁₂./ σ₁ L₂.⊙ σ₂ ≡ t A₁₂./ σ₁ A₁₂./ σ₂\n\n -- Sequences of T₃ substitutions are equivalent to T₂\n -- substitutions when applied to T₁s if they are equivalent when\n -- applied to variables.\n /✶-↑✶₁ :\n ∀ {m n} (σs₁ : Subs T₃ m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → L₂.var x A₂₃./✶ σs₁ ↑✶ k ≡ L₂.var x L₂./✶ σs₂ L₂.↑✶ k) →\n ∀ k t → t A₁₃./✶ σs₁ ↑✶ k ≡ t A₁₂./✶ σs₂ L₂.↑✶ k\n\n -- Sequences of T₃ substitutions are equivalent to T₂\n -- substitutions when applied to T₂s if they are equivalent when\n -- applied to variables.\n /✶-↑✶₂ :\n ∀ {m n} (σs₁ : Subs T₃ m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → L₂.var x A₂₃./✶ σs₁ ↑✶ k ≡ L₂.var x L₂./✶ σs₂ L₂.↑✶ k) →\n ∀ k t → t A₂₃./✶ σs₁ ↑✶ k ≡ t L₂./✶ σs₂ L₂.↑✶ k\n\n -- Lifting of T₃ substitutions to T₂ substitutions.\n liftSub : ∀ {m n} → Sub T₃ m n → Sub T₂ m n\n liftSub σ = map lift σ\n\n -- The two types of lifting commute.\n liftSub-↑⋆ : ∀ {m n} (σ : Sub T₃ m n) k →\n liftSub σ L₂.↑⋆ k ≡ liftSub (σ ↑⋆ k)\n liftSub-↑⋆ σ zero = refl\n liftSub-↑⋆ σ (suc k) = cong₂ _∷_ (sym (lift-var _)) (begin\n map L₂.weaken (liftSub σ L₂.↑⋆ k) ≡⟨ cong (map _) (liftSub-↑⋆ σ k) ⟩\n map L₂.weaken (map lift (σ ↑⋆ k)) ≡⟨ sym (map-∘ _ _ _) ⟩\n map (L₂.weaken ∘ lift) (σ ↑⋆ k) ≡⟨ map-cong weaken-lift _ ⟩\n map (lift ∘ L₃.weaken) (σ ↑⋆ k) ≡⟨ map-∘ _ _ _ ⟩\n map lift (map L₃.weaken (σ ↑⋆ k)) ∎)\n\n -- The identity substitutions are equivalent up to lifting.\n liftSub-id : ∀ {n} → liftSub (L₃.id {n}) ≡ L₂.id {n}\n liftSub-id {zero} = refl\n liftSub-id {suc n} = begin\n liftSub (L₃.id L₃.↑) ≡⟨ sym (liftSub-↑⋆ L₃.id 1) ⟩\n liftSub L₃.id L₂.↑ ≡⟨ cong L₂._↑ liftSub-id ⟩\n L₂.id ∎\n\n -- Weakening is equivalent up to lifting.\n liftSub-wk⋆ : ∀ k {n} → liftSub (L₃.wk⋆ k {n}) ≡ L₂.wk⋆ k {n}\n liftSub-wk⋆ zero = liftSub-id\n liftSub-wk⋆ (suc k) = begin\n liftSub (map L₃.weaken (L₃.wk⋆ k)) ≡⟨ sym (map-∘ _ _ _) ⟩\n map (lift ∘ L₃.weaken) (L₃.wk⋆ k) ≡⟨ sym (map-cong weaken-lift _) ⟩\n map (L₂.weaken ∘ lift) (L₃.wk⋆ k) ≡⟨ map-∘ _ _ _ ⟩\n map L₂.weaken (liftSub (L₃.wk⋆ k)) ≡⟨ cong (map _) (liftSub-wk⋆ k) ⟩\n map L₂.weaken (L₂.wk⋆ k) ∎\n\n -- Weakening is equivalent up to lifting.\n liftSub-wk : ∀ {n} → liftSub (L₃.wk {n}) ≡ L₂.wk {n}\n liftSub-wk = liftSub-wk⋆ 1\n\n -- Single variable substitution is equivalent up to lifting.\n liftSub-sub : ∀ {n} (t : T₃ n) → liftSub (L₃.sub t) ≡ L₂.sub (lift t)\n liftSub-sub t = cong₂ _∷_ refl liftSub-id\n\n -- Lifting commutes with application to variables.\n var-/-liftSub-↑⋆ : ∀ {m n} (σ : Sub T₃ m n) k x →\n L₂.var x A₂₃./ σ ↑⋆ k ≡ L₂.var x L₂./ liftSub σ L₂.↑⋆ k\n var-/-liftSub-↑⋆ σ k x = begin\n L₂.var x A₂₃./ σ ↑⋆ k\n ≡⟨ cong₂ A₂₃._/_ (sym (lift-var x)) refl ⟩\n lift (L₃.var x) A₂₃./ σ ↑⋆ k\n ≡⟨ sym (lift-/ _) ⟩\n lift (L₃.var x L₃./ σ ↑⋆ k)\n ≡⟨ cong lift L₃.var-/ ⟩\n lift (lookup x (σ ↑⋆ k))\n ≡⟨ sym (lookup-map x _ _) ⟩\n lookup x (liftSub (σ ↑⋆ k))\n ≡⟨ sym L₂.var-/ ⟩\n L₂.var x L₂./ liftSub (σ ↑⋆ k)\n ≡⟨ cong (L₂._/_ (L₂.var x)) (sym (liftSub-↑⋆ σ k)) ⟩\n L₂.var x L₂./ liftSub σ L₂.↑⋆ k\n ∎\n\n -- Lifting commutes with application.\n /-liftSub : ∀ {m n} t {σ : Sub T₃ m n} →\n t A₁₃./ σ ≡ t A₁₂./ liftSub σ\n /-liftSub t {σ} = /✶-↑✶₁ (ε ▻ σ) (ε ▻ liftSub σ)\n (var-/-liftSub-↑⋆ σ) zero t\n\n -- Weakening is equivalent up to choice of application.\n /-wk : ∀ {n} {t : T₁ n} → t A₁₃./ L₃.wk ≡ t A₁₂./ L₂.wk\n /-wk {t = t} = begin\n t A₁₃./ L₃.wk ≡⟨ /-liftSub t ⟩\n t A₁₂./ liftSub L₃.wk ≡⟨ cong₂ A₁₂._/_ refl liftSub-wk ⟩\n t A₁₂./ L₂.wk ∎\n\n -- Single-variable substitution is equivalent up to choice of\n -- application.\n /-sub : ∀ {n} t (s : T₃ n) →\n t A₁₃./ L₃.sub s ≡ t A₁₂./ L₂.sub (lift s)\n /-sub t s = begin\n t A₁₃./ L₃.sub s ≡⟨ /-liftSub t ⟩\n t A₁₂./ liftSub (L₃.sub s) ≡⟨ cong₂ A₁₂._/_ refl (liftSub-sub s) ⟩\n t A₁₂./ L₂.sub (lift s) ∎\n\n -- Lifting commutes with application.\n /-sub-↑ : ∀ {m n} t s (σ : Sub T₃ m n) →\n t A₁₂./ L₂.sub s A₁₃./ σ ≡ (t A₁₃./ σ ↑) A₁₂./ L₂.sub (s A₂₃./ σ)\n /-sub-↑ t s σ = begin\n t A₁₂./ L₂.sub s A₁₃./ σ\n ≡⟨ /-liftSub _ ⟩\n t A₁₂./ L₂.sub s A₁₂./ liftSub σ\n ≡⟨ sym (/-⊙₂ t) ⟩\n t A₁₂./ (L₂.sub s L₂.⊙ liftSub σ)\n ≡⟨ cong₂ A₁₂._/_ refl (L₂.sub-⊙ s) ⟩\n t A₁₂./ (liftSub σ L₂.↑ L₂.⊙ L₂.sub (s L₂./ liftSub σ))\n ≡⟨ /-⊙₂ t ⟩\n t A₁₂./ liftSub σ L₂.↑ A₁₂./ L₂.sub (s L₂./ liftSub σ)\n ≡⟨ cong₂ (A₁₂._/_ ∘ A₁₂._/_ t) (liftSub-↑⋆ _ 1)\n (cong L₂.sub (sym (/-liftSub₂ s))) ⟩\n t A₁₂./ liftSub (σ ↑) A₁₂./ L₂.sub (s A₂₃./ σ)\n ≡⟨ cong₂ A₁₂._/_ (sym (/-liftSub t)) refl ⟩\n t A₁₃./ σ ↑ A₁₂./ L₂.sub (s A₂₃./ σ)\n ∎\n where\n /-liftSub₂ : ∀ {m n} s {σ : Sub T₃ m n} →\n s A₂₃./ σ ≡ s L₂./ liftSub σ\n /-liftSub₂ s {σ} = /✶-↑✶₂ (ε ▻ σ) (ε ▻ liftSub σ)\n (var-/-liftSub-↑⋆ σ) zero s\n\n-- Lemmas for a term-like T₁ derived from term lemmas for T₂\nrecord TermLikeLemmas (T₁ T₂ : ℕ → Set) : Set₁ where\n field\n app : ∀ {T₃} → Lift T₃ T₂ → ∀ {m n} → T₁ m → Sub T₃ m n → T₁ n\n termLemmas : TermLemmas T₂\n\n open TermLemmas termLemmas using (termSubst)\n open TermSubst termSubst using (var; termLift; varLift; module Lifted)\n\n field /✶-↑✶₁ : ∀ {T₃} {lift : Lift T₃ T₂} →\n let open Application (record { _/_ = app lift })\n using () renaming (_/✶_ to _/✶₁_)\n open Lifted lift\n using (_↑✶_) renaming (_/✶_ to _/✶₂_)\n in\n ∀ {m n} (σs₁ : Subs T₃ m n) (σs₂ : Subs T₃ m n) →\n (∀ k x → var x /✶₂ σs₁ ↑✶ k ≡ var x /✶₂ σs₂ ↑✶ k) →\n ∀ k t → t /✶₁ σs₁ ↑✶ k ≡ t /✶₁ σs₂ ↑✶ k\n\n termApplication : Application T₁ T₂\n termApplication = record { _/_ = app termLift }\n\n varApplication : Application T₁ Fin\n varApplication = record { _/_ = app varLift }\n\n field /✶-↑✶₂ : let open Application varApplication\n using () renaming (_/✶_ to _/✶₁₃_)\n open Application termApplication\n using () renaming (_/✶_ to _/✶₁₂_)\n open Lifted varLift\n using () renaming (_↑✶_ to _↑✶₃_; _/✶_ to _/✶₂₃_)\n open TermSubst termSubst\n using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂₂_)\n in\n ∀ {m n} (σs₁ : Subs Fin m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → var x /✶₂₃ σs₁ ↑✶₃ k ≡ var x /✶₂₂ σs₂ ↑✶₂ k) →\n ∀ k t → t /✶₁₃ σs₁ ↑✶₃ k ≡ t /✶₁₂ σs₂ ↑✶₂ k\n\n -- An instantiation of the above lemmas for T₂ substitutions in T₁s.\n termLiftAppLemmas : LiftAppLemmas T₁ T₂ T₂\n termLiftAppLemmas = record\n { lift = Lift.lift termLift\n ; application₁₃ = termApplication\n ; application₂₃ = TermLemmas.application termLemmas\n ; lemmas₂ = TermLemmas.lemmas₄ termLemmas\n ; lemmas₃ = TermLemmas.lemmas₄ termLemmas\n ; lift-/ = λ _ → refl\n ; lift-var = λ _ → refl\n ; /✶-↑✶ = /✶-↑✶₁\n }\n\n open LiftAppLemmas termLiftAppLemmas public hiding (/-wk)\n\n -- An instantiation of the above lemmas for variable substitutions\n -- (renamings) in T₁s.\n varLiftSubLemmas : LiftSubLemmas T₁ T₂ Fin\n varLiftSubLemmas = record\n { application₁₂ = termApplication\n ; liftAppLemmas = record\n { lift = Lift.lift varLift\n ; application₁₃ = varApplication\n ; application₂₃ = Lifted.application varLift\n ; lemmas₂ = TermLemmas.lemmas₄ termLemmas\n ; lemmas₃ = VarLemmas.lemmas₄\n ; lift-/ = λ _ → sym (TermLemmas.app-var termLemmas)\n ; lift-var = λ _ → refl\n ; /✶-↑✶ = /✶-↑✶₁\n }\n ; weaken-lift = λ _ → TermLemmas.weaken-var termLemmas\n ; /-⊙₂ = AppLemmas./-⊙ appLemmas\n ; /✶-↑✶₁ = /✶-↑✶₂\n ; /✶-↑✶₂ = TermLemmas./✶-↑✶ termLemmas\n }\n\n open Application varApplication public using () renaming (_/_ to _/Var_)\n open LiftSubLemmas varLiftSubLemmas public hiding (/✶-↑✶₁; /✶-↑✶₂)\n renaming (liftAppLemmas to varLiftAppLemmas)\n\n -- Weakening of T₁s.\n weaken : ∀ {n} → T₁ n → T₁ (suc n)\n weaken t = t /Var VarSubst.wk\n\n -- A version of wk-sub-vanishes for T₁s.\n weaken-sub : ∀ {n t′} → (t : T₁ n) → weaken t / sub t′ ≡ t\n weaken-sub t = begin\n weaken t / sub _ ≡⟨ cong₂ _/_ /-wk refl ⟩\n t / wk / sub _ ≡⟨ wk-sub-vanishes t ⟩\n t ∎\n", "meta": {"hexsha": "ed6b6d0d00329f5aef2dc099012a1873bdb6a478", "size": 17064, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Data/Fin/Substitution/ExtraLemmas.agda", "max_stars_repo_name": "asr/pts-agda", "max_stars_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2016-05-13T12:11:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-31T10:47:57.000Z", "max_issues_repo_path": "src/Data/Fin/Substitution/ExtraLemmas.agda", "max_issues_repo_name": "asr/pts-agda", "max_issues_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-21T14:48:09.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-21T16:01:50.000Z", "max_forks_repo_path": "src/Data/Fin/Substitution/ExtraLemmas.agda", "max_forks_repo_name": "asr/pts-agda", "max_forks_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-08-20T10:29:44.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-11T23:28:33.000Z", "avg_line_length": 39.1376146789, "max_line_length": 78, "alphanum_fraction": 0.5268401313, "num_tokens": 7365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6113819732941511, "lm_q2_score": 0.6513548782017745, "lm_q1q2_score": 0.3982266307497724}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.HITs.Sn.Properties where\n\nopen import Cubical.Data.Int hiding (_+_)\nopen import Cubical.Data.Bool\nopen import Cubical.Foundations.Pointed\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Transport\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.GroupoidLaws\nopen import Cubical.Foundations.Univalence\nopen import Cubical.HITs.S1 hiding (inv)\nopen import Cubical.Data.Nat\nopen import Cubical.Data.Prod\nopen import Cubical.HITs.Sn.Base\nopen import Cubical.HITs.Susp\nopen import Cubical.Data.Unit\nopen import Cubical.HITs.Join\nopen import Cubical.HITs.Pushout\nopen import Cubical.HITs.SmashProduct\nopen import Cubical.HITs.PropositionalTruncation\n\nopen Iso\n\nprivate\n variable\n ℓ ℓ' : Level\n A : Type ℓ\n B : Type ℓ'\n\n--- Some silly lemmas on S1 ---\n\nS¹≡S1 : S₊ 1 ≡ S¹\nS¹≡S1 = cong Susp (sym (ua Bool≃Susp⊥)) ∙ sym S¹≡SuspBool\n\nisOfHLevelS1 : isOfHLevel 3 (S₊ 1)\nisOfHLevelS1 = transport (λ i → isOfHLevel 3 (S¹≡S1 (~ i)))\n λ x y → J (λ y p → (q : x ≡ y) → isProp (p ≡ q))\n (transport (λ i → isSet (basedΩS¹≡Int x (~ i))) isSetInt refl)\n\nisGroupoidS1 : isGroupoid (S₊ 1)\nisGroupoidS1 = transport (λ i → isGroupoid (S¹≡S1 (~ i))) isGroupoidS¹\n\nisConnectedS1 : (x : S₊ 1) → ∥ north ≡ x ∥\nisConnectedS1 x = rec propTruncIsProp\n (λ p → ∣ cong (transport (sym (S¹≡S1))) p ∙ transport⁻Transport (S¹≡S1) x ∣)\n (isConnectedS¹ (transport S¹≡S1 x))\n\n\nSuspBool→S1 : Susp Bool → S₊ 1\nSuspBool→S1 north = north\nSuspBool→S1 south = south\nSuspBool→S1 (merid false i) = merid south i\nSuspBool→S1 (merid true i) = merid north i\n\nS1→SuspBool : S₊ 1 → Susp Bool\nS1→SuspBool north = north\nS1→SuspBool south = south\nS1→SuspBool (merid north i) = merid true i\nS1→SuspBool (merid south i) = merid false i\n\nSuspBool→S1-sect : section SuspBool→S1 S1→SuspBool\nSuspBool→S1-sect north = refl\nSuspBool→S1-sect south = refl\nSuspBool→S1-sect (merid north i) = refl\nSuspBool→S1-sect (merid south i) = refl\n\nSuspBool→S1-retr : retract SuspBool→S1 S1→SuspBool\nSuspBool→S1-retr north = refl\nSuspBool→S1-retr south = refl\nSuspBool→S1-retr (merid false i) = refl\nSuspBool→S1-retr (merid true i) = refl\n\nS1→S¹ : S₊ 1 → S¹\nS1→S¹ x = SuspBool→S¹ (S1→SuspBool x)\n\nS¹→S1 : S¹ → S₊ 1\nS¹→S1 x = SuspBool→S1 (S¹→SuspBool x)\n\nS1→S¹-sect : section S1→S¹ S¹→S1\nS1→S¹-sect x =\n cong SuspBool→S¹ (SuspBool→S1-retr (S¹→SuspBool x))\n ∙ S¹→SuspBool→S¹ x\n\nS1→S¹-retr : retract S1→S¹ S¹→S1\nS1→S¹-retr x =\n cong SuspBool→S1 (SuspBool→S¹→SuspBool (S1→SuspBool x))\n ∙ SuspBool→S1-sect x\n\nSuspBoolIsoS1 : Iso (Susp Bool) (S₊ 1)\nfun SuspBoolIsoS1 = SuspBool→S1\ninv SuspBoolIsoS1 = S1→SuspBool\nrightInv SuspBoolIsoS1 north = refl\nrightInv SuspBoolIsoS1 south = refl\nrightInv SuspBoolIsoS1 (merid north i) = refl\nrightInv SuspBoolIsoS1 (merid south i) = refl\nleftInv SuspBoolIsoS1 north = refl\nleftInv SuspBoolIsoS1 south = refl\nleftInv SuspBoolIsoS1 (merid false i) = refl\nleftInv SuspBoolIsoS1 (merid true i) = refl\n\nSuspBool≃S1 : Susp Bool ≃ S₊ 1\nSuspBool≃S1 = isoToEquiv SuspBoolIsoS1\n\n-- map between S¹ ∧ A and Susp A.\nprivate\n f' : {a : A} → A → S₊ 1 → Susp A\n f' {a = pt} A north = north\n f' {a = pt} A south = north\n f' {a = pt} a (merid p i) = ((merid a) ∙ sym (merid pt)) i\n\n proj' : {A : Pointed ℓ} {B : Pointed ℓ'} → typ A → typ B → A ⋀ B\n proj' a b = inr (a , b)\n\nmodule smashS1→susp {(A , pt) : Pointed ℓ} where\n f : (S₊ 1 , north) ⋀ (A , pt) → (Susp A)\n f (inl tt) = north\n f (inr (x , x₁)) = f' {a = pt} x₁ x\n f (push (inl north) i) = north\n f (push (inl south) i) = north\n f (push (inl (merid a i₁)) i) = rCancel (merid pt) (~ i) i₁\n f (push (inr x) i) = north\n f (push (push tt i₁) i) = north\n\n f⁻ : Susp A → (S₊ 1 , north) ⋀ (A , pt)\n f⁻ north = inl tt\n f⁻ south = inl tt\n f⁻ (merid a i) =\n (push (inr a) ∙∙ cong (λ x → proj' {A = S₊ 1 , north} {B = A , pt} x a) (merid south ∙ sym (merid north)) ∙∙ sym (push (inr a))) i\n\n {- TODO : Prove that they cancel out -}\n\n{- Map used in definition of cup product. Maybe mover there later -}\nsphereSmashMap : (n m : ℕ) → (S₊ (suc n) , north) ⋀ (S₊ (suc m) , north) → S₊ (2 + n + m)\nsphereSmashMap zero m = smashS1→susp.f\nsphereSmashMap (suc n) m =\n smashS1→susp.f ∘\n (idfun∙ _ ⋀→ (sphereSmashMap n m , refl)) ∘\n ⋀-associate ∘\n ((smashS1→susp.f⁻ , refl) ⋀→ idfun∙ _)\n", "meta": {"hexsha": "b840b3a948a227932461d9dff136c2c97c05b5b2", "size": 4736, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/HITs/Sn/Properties.agda", "max_stars_repo_name": "knrafto/cubical", "max_stars_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "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": "Cubical/HITs/Sn/Properties.agda", "max_issues_repo_name": "knrafto/cubical", "max_issues_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "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": "Cubical/HITs/Sn/Properties.agda", "max_forks_repo_name": "knrafto/cubical", "max_forks_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "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": 32.8888888889, "max_line_length": 134, "alphanum_fraction": 0.6347128378, "num_tokens": 1846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548646660543, "lm_q2_score": 0.6113819732941511, "lm_q1q2_score": 0.39822662247427704}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nmodule Dodo.Unary.Equality where\n\n-- Stdlib imports\nimport Relation.Binary.PropositionalEquality as Eq\nopen Eq using (_≡_; refl)\nopen import Level using (Level; _⊔_)\nopen import Function using (_∘_)\nopen import Relation.Unary using (Pred)\n\n\n-- # Definitions\n\ninfix 4 _⊆₁'_ _⊆₁_ _⇔₁_\n\n-- Binary relation subset helper. Generally, use `_⊆₁_` (below).\n_⊆₁'_ : {a ℓ₁ ℓ₂ : Level} {A : Set a}\n → (P : Pred A ℓ₁)\n → (R : Pred A ℓ₂)\n → Set (a ⊔ ℓ₁ ⊔ ℓ₂)\n_⊆₁'_ {A = A} P R = ∀ (x : A) → P x → R x\n\n-- Somehow, Agda cannot infer P and R from `P ⇒ R`, and requires them explicitly passed.\n-- For proof convenience, wrap the proof in this structure, which explicitly conveys P and R\n-- to the type-checker.\ndata _⊆₁_ {a ℓ₁ ℓ₂ : Level} {A : Set a} (P : Pred A ℓ₁) (R : Pred A ℓ₂) : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where\n ⊆: : P ⊆₁' R → P ⊆₁ R\n\ndata _⇔₁_ {a ℓ₁ ℓ₂ : Level} {A : Set a} (P : Pred A ℓ₁) (R : Pred A ℓ₂) : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where\n ⇔: : P ⊆₁' R → R ⊆₁' P → P ⇔₁ R\n\n\n-- # Helpers\n\n⇔₁-intro : {a ℓ₁ ℓ₂ : Level} {A : Set a}\n → {P : Pred A ℓ₁} {R : Pred A ℓ₂}\n → P ⊆₁ R\n → R ⊆₁ P\n → P ⇔₁ R\n⇔₁-intro (⊆: P⊆R) (⊆: R⊆P) = ⇔: P⊆R R⊆P\n\n⇔₁-compose : ∀ {a b ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b}\n {P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred B ℓ₃} {S : Pred B ℓ₄}\n → ( P ⊆₁ Q → R ⊆₁ S )\n → ( Q ⊆₁ P → S ⊆₁ R )\n → P ⇔₁ Q\n → R ⇔₁ S\n⇔₁-compose ⊆-proof ⊇-proof (⇔: P⊆Q R⊆S) = ⇔₁-intro (⊆-proof (⊆: P⊆Q)) (⊇-proof (⊆: R⊆S))\n\n\n-- # Properties\n\n-- ## Properties: ⊆₁\n\nmodule _ {a ℓ : Level} {A : Set a} {R : Pred A ℓ} where\n\n ⊆₁-refl : R ⊆₁ R\n ⊆₁-refl = ⊆: (λ _ Rx → Rx)\n\nmodule _ {a ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred A ℓ₃} where\n\n ⊆₁-trans : P ⊆₁ Q → Q ⊆₁ R → P ⊆₁ R\n ⊆₁-trans (⊆: P⊆Q) (⊆: Q⊆R) = ⊆: (λ x Qx → Q⊆R x (P⊆Q x Qx))\n \n\n-- ## Properties: ⇔₁\n\nmodule _ {a ℓ : Level} {A : Set a} {R : Pred A ℓ} where\n\n ⇔₁-refl : R ⇔₁ R\n ⇔₁-refl = ⇔₁-intro ⊆₁-refl ⊆₁-refl\n\nmodule _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {Q : Pred A ℓ₁} {R : Pred A ℓ₂} where\n\n ⇔₁-sym : Q ⇔₁ R → R ⇔₁ Q\n -- WARNING: Do *NOT* use `Symmetric _⇔_`. It messes up the universe levels.\n ⇔₁-sym (⇔: Q⊆R R⊆Q) = ⇔: R⊆Q Q⊆R\n\nmodule _ {a ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a}\n {P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred A ℓ₃} where\n\n ⇔₁-trans : P ⇔₁ Q → Q ⇔₁ R → P ⇔₁ R\n ⇔₁-trans (⇔: P⊆Q Q⊆P) (⇔: Q⊆R R⊆Q) = ⇔₁-intro (⊆₁-trans (⊆: P⊆Q) (⊆: Q⊆R)) (⊆₁-trans (⊆: R⊆Q) (⊆: Q⊆P))\n\n\n-- # Operations\n\n-- ## Operations: ⇔₁ and ⊆₁ conversion\n\nun-⊆₁ : ∀ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Pred A ℓ₁} {R : Pred A ℓ₂}\n → P ⊆₁ R\n → P ⊆₁' R\nun-⊆₁ (⊆: P⊆R) = P⊆R\n\nunlift-⊆₁ : ∀ {a b ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b}\n {P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred B ℓ₃} {S : Pred B ℓ₄}\n → ( P ⊆₁ Q → R ⊆₁ S )\n → ( P ⊆₁' Q → R ⊆₁' S )\nunlift-⊆₁ f P⊆Q = un-⊆₁ (f (⊆: P⊆Q))\n\nlift-⊆₁ : ∀ {a b ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b}\n {P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred B ℓ₃} {S : Pred B ℓ₄}\n → ( P ⊆₁' Q → R ⊆₁' S )\n → ( P ⊆₁ Q → R ⊆₁ S )\nlift-⊆₁ f (⊆: P⊆Q) = ⊆: (f P⊆Q)\n\n⇔₁-to-⊆₁ : {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Pred A ℓ₁} {Q : Pred A ℓ₂}\n → P ⇔₁ Q\n ------\n → P ⊆₁ Q\n⇔₁-to-⊆₁ (⇔: P⊆Q _) = ⊆: P⊆Q\n\n⇔₁-to-⊇₁ : {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Pred A ℓ₁} {Q : Pred A ℓ₂}\n → P ⇔₁ Q\n ------\n → Q ⊆₁ P\n⇔₁-to-⊇₁ (⇔: _ Q⊆P) = ⊆: Q⊆P\n\n\n-- ## Operations: ⊆₁\n\n⊆₁-apply : ∀ {a ℓ₁ ℓ₂ : Level} {A : Set a}\n {P : Pred A ℓ₁} {Q : Pred A ℓ₂}\n → P ⊆₁ Q\n → {x : A}\n → P x\n -------\n → Q x\n⊆₁-apply (⊆: P⊆Q) {x} = P⊆Q x\n\n⊆₁-substˡ : ∀ {a ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a}\n {P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred A ℓ₃} {x : A}\n → P ⇔₁ Q\n → P ⊆₁ R\n ------\n → Q ⊆₁ R\n⊆₁-substˡ (⇔: _ Q⊆P) P⊆R = ⊆₁-trans (⊆: Q⊆P) P⊆R\n\n⊆₁-substʳ : ∀ {a ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a}\n {P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : Pred A ℓ₃}\n → Q ⇔₁ R\n → P ⊆₁ Q\n ------\n → P ⊆₁ R\n⊆₁-substʳ (⇔: Q⊆R _) P⊆Q = ⊆₁-trans P⊆Q (⊆: Q⊆R)\n\n≡-to-⊆₁ : {a b ℓ : Level} {A : Set a}\n {P : Pred A ℓ} {Q : Pred A ℓ}\n → P ≡ Q\n ------\n → P ⊆₁ Q\n≡-to-⊆₁ refl = ⊆: (λ _ Px → Px)\n\n\n-- ## Operations: ⇔₁\n\n⇔₁-apply-⊆₁ : {a ℓ₁ ℓ₂ : Level} {A : Set a}\n {P : Pred A ℓ₁} {Q : Pred A ℓ₂}\n → P ⇔₁ Q\n → {x : A}\n → P x\n -------\n → Q x\n⇔₁-apply-⊆₁ = ⊆₁-apply ∘ ⇔₁-to-⊆₁\n\n⇔₁-apply-⊇₁ : {a ℓ₁ ℓ₂ : Level} {A : Set a}\n {P : Pred A ℓ₁} {Q : Pred A ℓ₂}\n → P ⇔₁ Q\n → {x : A}\n → Q x\n -------\n → P x\n⇔₁-apply-⊇₁ = ⊆₁-apply ∘ ⇔₁-to-⊇₁\n\n≡-to-⇔₁ : {a ℓ : Level} {A : Set a}\n {P : Pred A ℓ} {Q : Pred A ℓ}\n → P ≡ Q\n ------\n → P ⇔₁ Q\n≡-to-⇔₁ refl = ⇔₁-intro ⊆₁-refl ⊆₁-refl\n\n\n-- # Reasoning\n\n-- ## Reasoning: ⊆₁\n\nmodule ⊆₁-Reasoning {a ℓ₁ : Level} {A : Set a} where\n\n infix 3 _⊆₁∎\n infixr 2 step-⊆₁\n infix 1 begin⊆₁_\n\n begin⊆₁_ : {ℓ₂ : Level} {P : Pred A ℓ₁} {Q : Pred A ℓ₂}\n → P ⊆₁ Q\n ------\n → P ⊆₁ Q\n begin⊆₁_ P⊆Q = P⊆Q\n\n step-⊆₁ : ∀ {ℓ₂ ℓ₃ : Level}\n → (P : Pred A ℓ₁)\n → {Q : Pred A ℓ₂}\n → {R : Pred A ℓ₃}\n → Q ⊆₁ R\n → P ⊆₁ Q\n ------\n → P ⊆₁ R\n step-⊆₁ P Q⊆R P⊆Q = ⊆₁-trans P⊆Q Q⊆R\n\n _⊆₁∎ : ∀ (P : Pred A ℓ₁) → P ⊆₁ P\n _⊆₁∎ _ = ⊆₁-refl\n\n syntax step-⊆₁ P Q⊆R P⊆Q = P ⊆₁⟨ P⊆Q ⟩ Q⊆R\n\n\n-- ## Reasoning: ⇔₁\n\nmodule ⇔₁-Reasoning {a ℓ₁ : Level} {A : Set a} where\n\n infix 3 _⇔₁∎\n infixr 2 _⇔₁⟨⟩_ step-⇔₁\n infix 1 begin⇔₁_\n\n begin⇔₁_ : {ℓ₂ : Level} {P : Pred A ℓ₁} {Q : Pred A ℓ₂}\n → P ⇔₁ Q\n ------\n → P ⇔₁ Q\n begin⇔₁_ P⇔Q = P⇔Q\n\n _⇔₁⟨⟩_ : {ℓ₂ : Level}\n (P : Pred A ℓ₁)\n → {Q : Pred A ℓ₂}\n → P ⇔₁ Q\n ---------------\n → P ⇔₁ Q\n _ ⇔₁⟨⟩ x≡y = x≡y\n\n step-⇔₁ : ∀ {ℓ₂ ℓ₃ : Level}\n → (P : Pred A ℓ₁)\n → {Q : Pred A ℓ₂}\n → {R : Pred A ℓ₃}\n → Q ⇔₁ R\n → P ⇔₁ Q\n ---------------\n → P ⇔₁ R\n step-⇔₁ _ Q⇔R P⇔Q = ⇔₁-trans P⇔Q Q⇔R\n\n _⇔₁∎ : ∀ (P : Pred A ℓ₁) → P ⇔₁ P\n _⇔₁∎ _ = ⇔₁-refl\n\n syntax step-⇔₁ P Q⇔R P⇔Q = P ⇔₁⟨ P⇔Q ⟩ Q⇔R\n", "meta": {"hexsha": "9dbb5bc235547a69f75a5ed064778825198ad2fb", "size": 5739, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Dodo/Unary/Equality.agda", "max_stars_repo_name": "sourcedennis/agda-dodo", "max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "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": "src/Dodo/Unary/Equality.agda", "max_issues_repo_name": "sourcedennis/agda-dodo", "max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "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": "src/Dodo/Unary/Equality.agda", "max_forks_repo_name": "sourcedennis/agda-dodo", "max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "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": 22.7738095238, "max_line_length": 105, "alphanum_fraction": 0.4535633386, "num_tokens": 3386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548511303336, "lm_q2_score": 0.6113819732941511, "lm_q1q2_score": 0.3982266141987814}} {"text": "open import Data.Product using ( ∃ ; _×_ ; _,_ )\nopen import Data.Sum using ( inj₁ ; inj₂ )\nopen import Relation.Nullary using ( Dec ; yes ; no )\nopen import Relation.Unary using ( _∈_ ; _∉_ ; ∅ ; U ; _∪_ ; _∩_ ; ∁ )\nopen import Web.Semantic.DL.Concept using ( Concept ; ⟨_⟩ ; ¬⟨_⟩ ; ⊤ ; ⊥ ; _⊓_ ; _⊔_ ; ∀[_]_ ; ∃⟨_⟩_ ; ≤1 ; >1 ; neg )\nopen import Web.Semantic.DL.Role.Model using ( _⟦_⟧₂ ; ⟦⟧₂-resp-≈ ; ⟦⟧₂-resp-≲ ; ⟦⟧₂-galois )\nopen import Web.Semantic.DL.Signature using ( Signature )\nopen import Web.Semantic.DL.TBox.Interp using ( Interp ; Δ ; _⊨_≈_ ; _⊨_≉_ ; con ; con-≈ ; ≈-refl ; ≈-sym ; ≈-trans )\nopen import Web.Semantic.DL.TBox.Interp.Morphism using ( _≲_ ; _≃_ ; ≲-resp-con ; ≲-resp-≈ ; ≃-impl-≲ ; ≃-impl-≳ ; ≃-iso ; ≃-iso⁻¹ ; ≃-image ; ≃-image⁻¹ ; ≃-refl-≈ ; ≃-sym )\nopen import Web.Semantic.Util using ( Subset ; tt ; _∘_ ; ExclMiddle ; elim )\n\nmodule Web.Semantic.DL.Concept.Model {Σ : Signature} where\n\n_⟦_⟧₁ : ∀ (I : Interp Σ) → Concept Σ → Subset (Δ I)\nI ⟦ ⟨ c ⟩ ⟧₁ = con I c\nI ⟦ ¬⟨ c ⟩ ⟧₁ = ∁ (con I c)\nI ⟦ ⊤ ⟧₁ = U\nI ⟦ ⊥ ⟧₁ = ∅\nI ⟦ C ⊓ D ⟧₁ = I ⟦ C ⟧₁ ∩ I ⟦ D ⟧₁\nI ⟦ C ⊔ D ⟧₁ = I ⟦ C ⟧₁ ∪ I ⟦ D ⟧₁\nI ⟦ ∀[ R ] C ⟧₁ = λ x → ∀ y → ((x , y) ∈ I ⟦ R ⟧₂) → (y ∈ I ⟦ C ⟧₁)\nI ⟦ ∃⟨ R ⟩ C ⟧₁ = λ x → ∃ λ y → ((x , y) ∈ I ⟦ R ⟧₂) × (y ∈ I ⟦ C ⟧₁)\nI ⟦ ≤1 R ⟧₁ = λ x → ∀ y z → ((x , y) ∈ I ⟦ R ⟧₂) → ((x , z) ∈ I ⟦ R ⟧₂) → (I ⊨ y ≈ z)\nI ⟦ >1 R ⟧₁ = λ x → ∃ λ y → ∃ λ z → ((x , y) ∈ I ⟦ R ⟧₂) × ((x , z) ∈ I ⟦ R ⟧₂) × (I ⊨ y ≉ z)\n\n⟦⟧₁-resp-≈ : ∀ I C {x y} → (x ∈ I ⟦ C ⟧₁) → (I ⊨ x ≈ y) → (y ∈ I ⟦ C ⟧₁) \n⟦⟧₁-resp-≈ I ⟨ c ⟩ x∈⟦c⟧ x≈y = \n con-≈ I c x∈⟦c⟧ x≈y\n⟦⟧₁-resp-≈ I ¬⟨ c ⟩ x∉⟦c⟧ x≈y = \n λ y∈⟦c⟧ → x∉⟦c⟧ (con-≈ I c y∈⟦c⟧ (≈-sym I x≈y))\n⟦⟧₁-resp-≈ I ⊤ x∈⊤ x≈y = \n tt\n⟦⟧₁-resp-≈ I (C ⊓ D) (x∈⟦C⟧ , x∈⟦D⟧) x≈y =\n (⟦⟧₁-resp-≈ I C x∈⟦C⟧ x≈y , ⟦⟧₁-resp-≈ I D x∈⟦D⟧ x≈y)\n⟦⟧₁-resp-≈ I (C ⊔ D) (inj₁ x∈⟦C⟧) x≈y =\n inj₁ (⟦⟧₁-resp-≈ I C x∈⟦C⟧ x≈y)\n⟦⟧₁-resp-≈ I (C ⊔ D) (inj₂ x∈⟦D⟧) x≈y =\n inj₂ (⟦⟧₁-resp-≈ I D x∈⟦D⟧ x≈y)\n⟦⟧₁-resp-≈ I (∀[ R ] C) x∈⟦∀RC⟧ x≈y =\n λ z yz∈⟦R⟧ → x∈⟦∀RC⟧ z (⟦⟧₂-resp-≈ I R x≈y yz∈⟦R⟧ (≈-refl I))\n⟦⟧₁-resp-≈ I (∃⟨ R ⟩ C) (z , xz∈⟦R⟧ , z∈⟦C⟧) x≈y =\n (z , ⟦⟧₂-resp-≈ I R (≈-sym I x≈y) xz∈⟦R⟧ (≈-refl I) , z∈⟦C⟧)\n⟦⟧₁-resp-≈ I (≤1 R) x∈⟦≤1R⟧ x≈y =\n λ w z yw∈⟦R⟧ yz∈⟦R⟧ → x∈⟦≤1R⟧ w z \n (⟦⟧₂-resp-≈ I R x≈y yw∈⟦R⟧ (≈-refl I)) \n (⟦⟧₂-resp-≈ I R x≈y yz∈⟦R⟧ (≈-refl I))\n⟦⟧₁-resp-≈ I (>1 R) (w , z , xw∈⟦R⟧ , xz∈⟦R⟧ , w≉z) x≈y =\n ( w , z \n , ⟦⟧₂-resp-≈ I R (≈-sym I x≈y) xw∈⟦R⟧ (≈-refl I)\n , ⟦⟧₂-resp-≈ I R (≈-sym I x≈y) xz∈⟦R⟧ (≈-refl I)\n , w≉z)\n⟦⟧₁-resp-≈ I ⊥ () x≈y\n\nmutual\n\n ⟦⟧₁-refl-≃ : ∀ {I J : Interp Σ} → (I≃J : I ≃ J) → ∀ {x} C → (≃-image⁻¹ I≃J x ∈ I ⟦ C ⟧₁) → (x ∈ J ⟦ C ⟧₁)\n ⟦⟧₁-refl-≃ {I} {J} I≃J {x} C x∈⟦C⟧ = ⟦⟧₁-resp-≈ J C (⟦⟧₁-resp-≃ I≃J C x∈⟦C⟧) (≃-iso⁻¹ I≃J x)\n\n ⟦⟧₁-resp-≃ : ∀ {I J : Interp Σ} → (I≃J : I ≃ J) → ∀ {x} C → (x ∈ I ⟦ C ⟧₁) → (≃-image I≃J x ∈ J ⟦ C ⟧₁)\n ⟦⟧₁-resp-≃ {I} {J} I≃J ⟨ c ⟩ x∈⟦c⟧ = \n ≲-resp-con (≃-impl-≲ I≃J) x∈⟦c⟧\n ⟦⟧₁-resp-≃ {I} {J} I≃J {x} ¬⟨ c ⟩ x∉⟦c⟧ = \n λ x∈⟦c⟧ → x∉⟦c⟧ (con-≈ I c (≲-resp-con (≃-impl-≳ I≃J) x∈⟦c⟧) (≃-iso I≃J x))\n ⟦⟧₁-resp-≃ {I} {J} I≃J ⊤ _ = \n tt\n ⟦⟧₁-resp-≃ {I} {J} I≃J ⊥ ()\n ⟦⟧₁-resp-≃ {I} {J} I≃J (C ⊓ D) (x∈⟦C⟧ , x∈⟦D⟧) = \n (⟦⟧₁-resp-≃ I≃J C x∈⟦C⟧ , ⟦⟧₁-resp-≃ I≃J D x∈⟦D⟧)\n ⟦⟧₁-resp-≃ {I} {J} I≃J (C ⊔ D) (inj₁ x∈⟦C⟧) = \n inj₁ (⟦⟧₁-resp-≃ I≃J C x∈⟦C⟧)\n ⟦⟧₁-resp-≃ {I} {J} I≃J (C ⊔ D) (inj₂ x∈⟦D⟧) = \n inj₂ (⟦⟧₁-resp-≃ I≃J D x∈⟦D⟧)\n ⟦⟧₁-resp-≃ {I} {J} I≃J (∀[ R ] C) x∈⟦∀RC⟧ = \n λ y xy∈⟦R⟧ → ⟦⟧₁-refl-≃ I≃J C \n (x∈⟦∀RC⟧ (≃-image⁻¹ I≃J y) (⟦⟧₂-galois (≃-sym I≃J) R xy∈⟦R⟧))\n ⟦⟧₁-resp-≃ {I} {J} I≃J (∃⟨ R ⟩ C) (y , xy∈⟦R⟧ , y∈⟦C⟧) = \n ( ≃-image I≃J y \n , ⟦⟧₂-resp-≲ (≃-impl-≲ I≃J) R xy∈⟦R⟧ \n , ⟦⟧₁-resp-≃ I≃J C y∈⟦C⟧ )\n ⟦⟧₁-resp-≃ {I} {J} I≃J (≤1 R) x∈⟦≤1R⟧ = \n λ y z xy∈⟦R⟧ xz∈⟦R⟧ → ≃-refl-≈ I≃J \n (x∈⟦≤1R⟧ (≃-image⁻¹ I≃J y) (≃-image⁻¹ I≃J z) \n (⟦⟧₂-galois (≃-sym I≃J) R xy∈⟦R⟧) (⟦⟧₂-galois (≃-sym I≃J) R xz∈⟦R⟧))\n ⟦⟧₁-resp-≃ {I} {J} I≃J (>1 R) (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z) = \n ( ≃-image I≃J y , ≃-image I≃J z \n , ⟦⟧₂-resp-≲ (≃-impl-≲ I≃J) R xy∈⟦R⟧\n , ⟦⟧₂-resp-≲ (≃-impl-≲ I≃J) R xz∈⟦R⟧\n , y≉z ∘ ≃-refl-≈ (≃-sym I≃J) )\n\nneg-sound : ∀ I {x} C → (x ∈ I ⟦ neg C ⟧₁) → (x ∉ I ⟦ C ⟧₁)\nneg-sound I ⟨ c ⟩ x∉⟦c⟧ x∈⟦c⟧ = x∉⟦c⟧ x∈⟦c⟧\nneg-sound I ¬⟨ c ⟩ x∈⟦c⟧ x∉⟦c⟧ = x∉⟦c⟧ x∈⟦c⟧\nneg-sound I ⊤ () _\nneg-sound I ⊥ _ ()\nneg-sound I (C ⊓ D) (inj₁ x∈⟦¬C⟧) (x∈⟦C⟧ , x∈⟦D⟧) = neg-sound I C x∈⟦¬C⟧ x∈⟦C⟧\nneg-sound I (C ⊓ D) (inj₂ x∈⟦¬D⟧) (x∈⟦C⟧ , x∈⟦D⟧) = neg-sound I D x∈⟦¬D⟧ x∈⟦D⟧\nneg-sound I (C ⊔ D) (x∈⟦¬C⟧ , x∈⟦¬D⟧) (inj₁ x∈⟦C⟧) = neg-sound I C x∈⟦¬C⟧ x∈⟦C⟧\nneg-sound I (C ⊔ D) (x∈⟦¬C⟧ , x∈⟦¬D⟧) (inj₂ x∈⟦D⟧) = neg-sound I D x∈⟦¬D⟧ x∈⟦D⟧\nneg-sound I (∀[ R ] C) (y , xy∈⟦R⟧ , y∈⟦¬C⟧) x∈⟦∀RC⟧ = neg-sound I C y∈⟦¬C⟧ (x∈⟦∀RC⟧ y xy∈⟦R⟧)\nneg-sound I (∃⟨ R ⟩ C) x∈⟦∀R¬C⟧ (y , xy∈⟦R⟧ , y∈⟦C⟧) = neg-sound I C (x∈⟦∀R¬C⟧ y xy∈⟦R⟧) y∈⟦C⟧\nneg-sound I (≤1 R) (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z) x∈⟦≤1R⟧ = y≉z (x∈⟦≤1R⟧ y z xy∈⟦R⟧ xz∈⟦R⟧)\nneg-sound I (>1 R) x∈⟦≤1R⟧ (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z) = y≉z (x∈⟦≤1R⟧ y z xy∈⟦R⟧ xz∈⟦R⟧)\n\nneg-complete : ExclMiddle → ∀ I {x} C → (x ∉ I ⟦ C ⟧₁) → (x ∈ I ⟦ neg C ⟧₁)\nneg-complete excl-middle I ⟨ c ⟩ x∉⟦c⟧ = x∉⟦c⟧\nneg-complete excl-middle I {x} ¬⟨ c ⟩ ¬x∉⟦c⟧ with excl-middle (x ∈ con I c)\nneg-complete excl-middle I ¬⟨ c ⟩ ¬x∉⟦c⟧ | yes x∈⟦c⟧ = x∈⟦c⟧\nneg-complete excl-middle I ¬⟨ c ⟩ ¬x∉⟦c⟧ | no x∉⟦c⟧ = elim (¬x∉⟦c⟧ x∉⟦c⟧)\nneg-complete excl-middle I ⊤ x∉⟦⊤⟧ = x∉⟦⊤⟧ tt\nneg-complete excl-middle I ⊥ x∉⟦⊥⟧ = tt\nneg-complete excl-middle I {x} (C ⊓ D) x∉⟦C⊓D⟧ with excl-middle (x ∈ I ⟦ C ⟧₁)\nneg-complete excl-middle I (C ⊓ D) x∉⟦C⊓D⟧ | yes x∈⟦C⟧ =\n inj₂ (neg-complete excl-middle I D (λ x∈⟦D⟧ → x∉⟦C⊓D⟧ (x∈⟦C⟧ , x∈⟦D⟧)))\nneg-complete excl-middle I (C ⊓ D) x∉⟦C⊓D⟧ | no x∉⟦C⟧ = \n inj₁ (neg-complete excl-middle I C x∉⟦C⟧)\nneg-complete excl-middle I (C ⊔ D) x∉⟦C⊔D⟧ = \n ( neg-complete excl-middle I C (x∉⟦C⊔D⟧ ∘ inj₁)\n , neg-complete excl-middle I D (x∉⟦C⊔D⟧ ∘ inj₂))\nneg-complete excl-middle I {x} (∀[ R ] C) x∉⟦∀RC⟧ \n with excl-middle (∃ λ y → ((x , y) ∈ I ⟦ R ⟧₂) × (y ∉ I ⟦ C ⟧₁))\nneg-complete excl-middle I {x} (∀[ R ] C) x∉⟦∀RC⟧ | yes (y , xy∈⟦R⟧ , y∉⟦C⟧) =\n (y , xy∈⟦R⟧ , neg-complete excl-middle I C y∉⟦C⟧)\nneg-complete excl-middle I {x} (∀[ R ] C) x∉⟦∀RC⟧ | no ∄xy∈⟦R⟧∙y∉⟦C⟧ =\n elim (x∉⟦∀RC⟧ lemma) where\n lemma : x ∈ I ⟦ ∀[ R ] C ⟧₁\n lemma y xy∈⟦R⟧ with excl-middle (y ∈ I ⟦ C ⟧₁)\n lemma y xy∈⟦R⟧ | yes y∈⟦C⟧ = y∈⟦C⟧\n lemma y xy∈⟦R⟧ | no y∉⟦C⟧ = elim (∄xy∈⟦R⟧∙y∉⟦C⟧ (y , xy∈⟦R⟧ , y∉⟦C⟧))\nneg-complete excl-middle I (∃⟨ R ⟩ C) x∉⟦∃RC⟧ = \n λ y xy∈⟦R⟧ → neg-complete excl-middle I C \n (λ y∈⟦C⟧ → x∉⟦∃RC⟧ (y , xy∈⟦R⟧ , y∈⟦C⟧))\nneg-complete excl-middle I {x} (≤1 R) x∉⟦≤1R⟧ = lemma where\n lemma : x ∈ I ⟦ >1 R ⟧₁\n lemma with excl-middle (x ∈ I ⟦ >1 R ⟧₁)\n lemma | yes x∈⟦>1R⟧ = x∈⟦>1R⟧\n lemma | no x∉⟦>1R⟧ = elim (x∉⟦≤1R⟧ lemma′) where\n lemma′ : x ∈ I ⟦ ≤1 R ⟧₁\n lemma′ y z xy∈⟦R⟧ xz∈⟦R⟧ with excl-middle (I ⊨ y ≈ z)\n lemma′ y z xy∈⟦R⟧ xz∈⟦R⟧ | yes y≈z = y≈z\n lemma′ y z xy∈⟦R⟧ xz∈⟦R⟧ | no y≉z =\n elim (x∉⟦>1R⟧ (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z))\nneg-complete excl-middle I {x} (>1 R) x∉⟦>1R⟧ = lemma where\n lemma : x ∈ I ⟦ ≤1 R ⟧₁\n lemma y z xy∈⟦R⟧ xz∈⟦R⟧ with excl-middle (I ⊨ y ≈ z)\n lemma y z xy∈⟦R⟧ xz∈⟦R⟧ | yes y≈z = y≈z\n lemma y z xy∈⟦R⟧ xz∈⟦R⟧ | no y≉z = \n elim (x∉⟦>1R⟧ (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z))\n\n", "meta": {"hexsha": "d623d08b7490942095bec66a5dd1bc102e86f945", "size": 7548, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Web/Semantic/DL/Concept/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/Concept/Model.agda", "max_issues_repo_name": "bblfish/agda-web-semantic", "max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "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/Concept/Model.agda", "max_forks_repo_name": "bblfish/agda-web-semantic", "max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "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": 50.6577181208, "max_line_length": 173, "alphanum_fraction": 0.421436142, "num_tokens": 5130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8152324938410784, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.39806449004821237}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Basics\nopen import lib.cubical.Square\nopen import lib.types.Bool\nopen import lib.types.Cofiber\nopen import lib.types.Lift\nopen import lib.types.Paths\nopen import lib.types.Pointed\nopen import lib.types.PushoutFmap\nopen import lib.types.Sigma\nopen import lib.types.Span\nopen import lib.types.Suspension\nopen import lib.types.Wedge\n\nmodule lib.types.BigWedge where\n\nmodule _ {i j} {A : Type i} where\n\n {- the function for cofiber -}\n bigwedge-f : (X : A → Ptd j) → A → Σ A (de⊙ ∘ X)\n bigwedge-f X a = a , pt (X a)\n\n bigwedge-span : (A → Ptd j) → Span\n bigwedge-span X = cofiber-span (bigwedge-f X)\n\n BigWedge : (A → Ptd j) → Type (lmax i j)\n BigWedge X = Cofiber (bigwedge-f X)\n\n bwbase : {X : A → Ptd j} → BigWedge X\n bwbase = cfbase\n\n bwin : {X : A → Ptd j} → (a : A) → de⊙ (X a) → BigWedge X\n bwin = curry cfcod\n\n ⊙BigWedge : (A → Ptd j) → Ptd (lmax i j)\n ⊙BigWedge X = ⊙[ BigWedge X , bwbase ]\n\n bwglue : {X : A → Ptd j} → (a : A) → bwbase {X} == bwin a (pt (X a))\n bwglue = cfglue\n\n ⊙bwin : {X : A → Ptd j} → (a : A) → X a ⊙→ ⊙BigWedge X\n ⊙bwin a = (bwin a , ! (bwglue a))\n\n module BigWedgeElim {X : A → Ptd j} {k} {P : BigWedge X → Type k}\n (base* : P bwbase) (in* : (a : A) (x : de⊙ (X a)) → P (bwin a x))\n (glue* : (a : A) → base* == in* a (pt (X a)) [ P ↓ bwglue a ])\n = CofiberElim {f = bigwedge-f X} {P = P} base* (uncurry in*) glue*\n\n BigWedge-elim = BigWedgeElim.f\n\n module BigWedgeRec {X : A → Ptd j} {k} {C : Type k}\n (base* : C) (in* : (a : A) → de⊙ (X a) → C)\n (glue* : (a : A) → base* == in* a (pt (X a)))\n = CofiberRec {f = bigwedge-f X} {C = C} base* (uncurry in*) glue*\n\nmodule _ {i j₀ j₁} {A : Type i} {X₀ : A → Ptd j₀} {X₁ : A → Ptd j₁}\n (Xeq : ∀ a → X₀ a ⊙≃ X₁ a) where\n\n bigwedge-span-emap-r : SpanEquiv (cofiber-span (bigwedge-f X₀)) (cofiber-span (bigwedge-f X₁))\n bigwedge-span-emap-r = span-map (idf _) (Σ-fmap-r λ a → fst (⊙–> (Xeq a))) (idf _)\n (comm-sqr λ _ → idp) (comm-sqr λ a → pair= idp (⊙–>-pt (Xeq a))) ,\n idf-is-equiv _ , Σ-isemap-r (λ a → snd (Xeq a)) , idf-is-equiv _\n\n BigWedge-emap-r : BigWedge X₀ ≃ BigWedge X₁\n BigWedge-emap-r = Pushout-emap bigwedge-span-emap-r\n\n ⊙BigWedge-emap-r : ⊙BigWedge X₀ ⊙≃ ⊙BigWedge X₁\n ⊙BigWedge-emap-r = ≃-to-⊙≃ BigWedge-emap-r idp\n\nmodule _ {i₀ i₁ j} {A₀ : Type i₀} {A₁ : Type i₁}\n (X : A₁ → Ptd j) (Aeq : A₀ ≃ A₁) where\n\n bigwedge-span-emap-l : SpanEquiv (cofiber-span (bigwedge-f (X ∘ –> Aeq))) (cofiber-span (bigwedge-f X))\n bigwedge-span-emap-l = span-map (idf _) (Σ-fmap-l (de⊙ ∘ X) (–> Aeq)) (–> Aeq)\n (comm-sqr λ _ → idp) (comm-sqr λ _ → idp) ,\n idf-is-equiv _ , Σ-isemap-l (de⊙ ∘ X) (snd Aeq) , snd Aeq\n\n BigWedge-emap-l : BigWedge (X ∘ –> Aeq) ≃ BigWedge X\n BigWedge-emap-l = Pushout-emap bigwedge-span-emap-l\n\n ⊙BigWedge-emap-l : ⊙BigWedge (X ∘ –> Aeq) ⊙≃ ⊙BigWedge X\n ⊙BigWedge-emap-l = ≃-to-⊙≃ BigWedge-emap-l idp\n\nmodule _ {i j} {A : Type i} (X : A → Ptd j) where\n\n extract-glue-from-BigWedge-is-const :\n ∀ bw → extract-glue {s = bigwedge-span X} bw == north\n extract-glue-from-BigWedge-is-const = BigWedge-elim\n idp\n (λ x y → ! (merid x))\n (↓-='-from-square ∘ λ x →\n ExtractGlue.glue-β x ∙v⊡\n tr-square (merid x)\n ⊡v∙ ! (ap-cst north (cfglue x)))\n\n{- A BigWedge indexed by Bool is just a binary Wedge -}\nmodule _ {i} (Pick : Bool → Ptd i) where\n\n BigWedge-Bool-equiv-Wedge : BigWedge Pick ≃ Wedge (Pick true) (Pick false)\n BigWedge-Bool-equiv-Wedge = equiv f g f-g g-f\n where\n module F = BigWedgeRec {X = Pick}\n {C = Wedge (Pick true) (Pick false)}\n (winl (pt (Pick true)))\n (λ {true → winl; false → winr})\n (λ {true → idp; false → wglue})\n\n module G = WedgeRec {X = Pick true} {Y = Pick false}\n {C = BigWedge Pick}\n (bwin true)\n (bwin false)\n (! (bwglue true) ∙ bwglue false)\n\n f = F.f\n g = G.f\n\n abstract\n f-g : ∀ w → f (g w) == w\n f-g = Wedge-elim\n (λ _ → idp)\n (λ _ → idp)\n (↓-∘=idf-in' f g $\n ap f (ap g wglue)\n =⟨ ap (ap f) G.glue-β ⟩\n ap f (! (bwglue true) ∙ bwglue false)\n =⟨ ap-∙ f (! (bwglue true)) (bwglue false) ⟩\n ap f (! (bwglue true)) ∙ ap f (bwglue false)\n =⟨ ap-! f (bwglue true)\n |in-ctx (λ w → w ∙ ap f (bwglue false)) ⟩\n ! (ap f (bwglue true)) ∙ ap f (bwglue false)\n =⟨ F.glue-β true\n |in-ctx (λ w → ! w ∙ ap f (bwglue false)) ⟩\n ap f (bwglue false)\n =⟨ F.glue-β false ⟩\n wglue =∎)\n\n g-f : ∀ bw → g (f bw) == bw\n g-f = BigWedge-elim\n (! (bwglue true))\n (λ {true → λ _ → idp; false → λ _ → idp})\n (λ {true → ↓-∘=idf-from-square g f $\n ap (ap g) (F.glue-β true) ∙v⊡\n bl-square (bwglue true);\n false → ↓-∘=idf-from-square g f $\n (ap (ap g) (F.glue-β false) ∙ G.glue-β) ∙v⊡\n lt-square (! (bwglue true)) ⊡h vid-square})\n\nmodule _ {i j} {A : Type i} (dec : has-dec-eq A) {X : Ptd j} where\n\n {- The dependent version increases the complexity significantly\n and we do not need it. -}\n\n ⊙bwproj-in : A → A → X ⊙→ X\n ⊙bwproj-in a a' with dec a a'\n ... | inl _ = ⊙idf _\n ... | inr _ = ⊙cst\n\n module BigWedgeProj (a : A) = BigWedgeRec\n {X = λ _ → X}\n (pt X)\n (λ a' → fst (⊙bwproj-in a a'))\n (λ a' → ! (snd (⊙bwproj-in a a')))\n\n bwproj : A → BigWedge (λ _ → X) → de⊙ X\n bwproj = BigWedgeProj.f\n\n ⊙bwproj : A → ⊙BigWedge (λ _ → X) ⊙→ X\n ⊙bwproj a = bwproj a , idp\n\n abstract\n bwproj-bwin-diag : (a : A) → bwproj a ∘ bwin a ∼ idf (de⊙ X)\n bwproj-bwin-diag a x with dec a a\n ... | inl _ = idp\n ... | inr a≠a with a≠a idp\n ... | ()\n\n bwproj-bwin-≠ : {a a' : A} → a ≠ a' → bwproj a ∘ bwin a' ∼ cst (pt X)\n bwproj-bwin-≠ {a} {a'} a≠a' x with dec a a'\n ... | inr _ = idp\n ... | inl a=a' with a≠a' a=a'\n ... | ()\n\nmodule _ {i j k} {A : Type i} (dec : has-dec-eq A) {X : Ptd j} (a : A) where\n\n abstract\n private\n bwproj-BigWedge-emap-r-lift-in : ∀ a'\n → bwproj dec {X = ⊙Lift {j = k} X} a ∘ bwin a' ∘ lift\n ∼ lift {j = k} ∘ bwproj dec {X = X} a ∘ bwin a'\n bwproj-BigWedge-emap-r-lift-in a' with dec a a'\n ... | inl _ = λ _ → idp\n ... | inr _ = λ _ → idp\n\n bwproj-BigWedge-emap-r-lift-glue' : ∀ (a' : A)\n → ap (lift {j = k}) (! (snd (⊙bwproj-in dec {X = X} a a')))\n == ! (snd (⊙bwproj-in dec {X = ⊙Lift {j = k} X} a a')) ∙' bwproj-BigWedge-emap-r-lift-in a' (pt X)\n bwproj-BigWedge-emap-r-lift-glue' a' with dec a a'\n ... | inl _ = idp\n ... | inr _ = idp\n\n bwproj-BigWedge-emap-r-lift-glue : ∀ (a' : A)\n → idp == bwproj-BigWedge-emap-r-lift-in a' (pt X)\n [ (λ x → bwproj dec {X = ⊙Lift {j = k} X} a (–> (BigWedge-emap-r (λ _ → ⊙lift-equiv {j = k})) x)\n == lift {j = k} (bwproj dec {X = X} a x)) ↓ bwglue a' ]\n bwproj-BigWedge-emap-r-lift-glue a' = ↓-='-in' $\n ap (lift {j = k} ∘ bwproj dec a) (bwglue a')\n =⟨ ap-∘ (lift {j = k}) (bwproj dec a) (bwglue a') ⟩\n ap (lift {j = k}) (ap (bwproj dec a) (bwglue a'))\n =⟨ ap (ap (lift {j = k})) $ BigWedgeProj.glue-β dec a a' ⟩\n ap (lift {j = k}) (! (snd (⊙bwproj-in dec a a')))\n =⟨ bwproj-BigWedge-emap-r-lift-glue' a' ⟩\n ! (snd (⊙bwproj-in dec a a')) ∙' bwproj-BigWedge-emap-r-lift-in a' (pt X)\n =⟨ ap (_∙' bwproj-BigWedge-emap-r-lift-in a' (pt X)) $\n ( ! $ BigWedgeProj.glue-β dec a a') ⟩\n ap (bwproj dec a) (bwglue a') ∙' bwproj-BigWedge-emap-r-lift-in a' (pt X)\n =⟨ ap (λ p → ap (bwproj dec a) p\n ∙' bwproj-BigWedge-emap-r-lift-in a' (pt X)) $\n (! $ PushoutFmap.glue-β (fst (bigwedge-span-emap-r (λ _ → ⊙lift-equiv {j = k}))) a') ⟩\n ap (bwproj dec a) (ap (–> (BigWedge-emap-r (λ _ → ⊙lift-equiv {j = k}))) (bwglue a'))\n ∙' bwproj-BigWedge-emap-r-lift-in a' (pt X)\n =⟨ ap (_∙' bwproj-BigWedge-emap-r-lift-in a' (pt X)) $\n (∘-ap (bwproj dec a) (–> (BigWedge-emap-r (λ _ → ⊙lift-equiv {j = k}))) (bwglue a')) ⟩\n ap (bwproj dec a ∘ –> (BigWedge-emap-r (λ _ → ⊙lift-equiv {j = k}))) (bwglue a')\n ∙' bwproj-BigWedge-emap-r-lift-in a' (pt X)\n =∎\n\n bwproj-BigWedge-emap-r-lift :\n bwproj dec {X = ⊙Lift {j = k} X} a ∘ –> (BigWedge-emap-r (λ _ → ⊙lift-equiv {j = k}))\n ∼ lift {j = k} ∘ bwproj dec a\n bwproj-BigWedge-emap-r-lift =\n BigWedge-elim {X = λ _ → X} idp\n bwproj-BigWedge-emap-r-lift-in\n bwproj-BigWedge-emap-r-lift-glue\n", "meta": {"hexsha": "a65149a5ce43f8509fecf9fe5e4be74a8613e1d2", "size": 8582, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/types/BigWedge.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "core/lib/types/BigWedge.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "core/lib/types/BigWedge.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 36.5191489362, "max_line_length": 106, "alphanum_fraction": 0.5228384992, "num_tokens": 3623, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.39801195162502384}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Products\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.Product where\n\nopen import Function\nopen import Level\nopen import Relation.Nullary\nopen import Agda.Builtin.Equality\n\ninfixr 4 _,′_\ninfix 4 -,_\ninfixr 2 _×_ _-×-_ _-,-_\n\n------------------------------------------------------------------------\n-- Definition\n\nopen import Agda.Builtin.Sigma hiding (module Σ) public renaming (fst to proj₁; snd to proj₂)\n\nmodule Σ = Agda.Builtin.Sigma.Σ renaming (fst to proj₁; snd to proj₂)\n\n-- The syntax declaration below is attached to Σ-syntax, to make it\n-- easy to import Σ without the special syntax.\n\ninfix 2 Σ-syntax\n\nΣ-syntax : ∀ {a b} (A : Set a) → (A → Set b) → Set (a ⊔ b)\nΣ-syntax = Σ\n\nsyntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B\n\n∃ : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)\n∃ = Σ _\n\n∃-syntax : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)\n∃-syntax = ∃\n\nsyntax ∃-syntax (λ x → B) = ∃[ x ] B\n\n∄ : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)\n∄ P = ¬ ∃ P\n\n∄-syntax : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)\n∄-syntax = ∄\n\nsyntax ∄-syntax (λ x → B) = ∄[ x ] B\n\n∃₂ : ∀ {a b c} {A : Set a} {B : A → Set b}\n (C : (x : A) → B x → Set c) → Set (a ⊔ b ⊔ c)\n∃₂ C = ∃ λ a → ∃ λ b → C a b\n\n_×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a ⊔ b)\nA × B = Σ[ x ∈ A ] B\n\n_,′_ : ∀ {a b} {A : Set a} {B : Set b} → A → B → A × B\n_,′_ = _,_\n\n------------------------------------------------------------------------\n-- Unique existence\n\n-- Parametrised on the underlying equality.\n\n∃! : ∀ {a b ℓ} {A : Set a} →\n (A → A → Set ℓ) → (A → Set b) → Set (a ⊔ b ⊔ ℓ)\n∃! _≈_ B = ∃ λ x → B x × (∀ {y} → B y → x ≈ y)\n\n------------------------------------------------------------------------\n-- Functions\n\n-- Sometimes the first component can be inferred.\n\n-,_ : ∀ {a b} {A : Set a} {B : A → Set b} {x} → B x → ∃ B\n-, y = _ , y\n\n<_,_> : ∀ {a b c} {A : Set a} {B : A → Set b} {C : ∀ {x} → B x → Set c}\n (f : (x : A) → B x) → ((x : A) → C (f x)) →\n ((x : A) → Σ (B x) C)\n< f , g > x = (f x , g x)\n\nmap : ∀ {a b p q}\n {A : Set a} {B : Set b} {P : A → Set p} {Q : B → Set q} →\n (f : A → B) → (∀ {x} → P x → Q (f x)) →\n Σ A P → Σ B Q\nmap f g (x , y) = (f x , g y)\n\nmap₁ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →\n (A → B) → A × C → B × C\nmap₁ f = map f id\n\nmap₂ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : A → Set c} →\n (∀ {x} → B x → C x) → Σ A B → Σ A C\nmap₂ f = map id f\n\nzip : ∀ {a b c p q r}\n {A : Set a} {B : Set b} {C : Set c}\n {P : A → Set p} {Q : B → Set q} {R : C → Set r} →\n (_∙_ : A → B → C) →\n (∀ {x y} → P x → Q y → R (x ∙ y)) →\n Σ A P → Σ B Q → Σ C R\nzip _∙_ _∘_ (a , p) (b , q) = ((a ∙ b) , (p ∘ q))\n\nswap : ∀ {a b} {A : Set a} {B : Set b} → A × B → B × A\nswap (x , y) = (y , x)\n\n_-×-_ : ∀ {a b i j} {A : Set a} {B : Set b} →\n (A → B → Set i) → (A → B → Set j) → (A → B → Set _)\nf -×- g = f -[ _×_ ]- g\n\n_-,-_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →\n (A → B → C) → (A → B → D) → (A → B → C × D)\nf -,- g = f -[ _,_ ]- g\n\ncurry : ∀ {a b c} {A : Set a} {B : A → Set b} {C : Σ A B → Set c} →\n ((p : Σ A B) → C p) →\n ((x : A) → (y : B x) → C (x , y))\ncurry f x y = f (x , y)\n\ncurry′ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →\n (A × B → C) → (A → B → C)\ncurry′ = curry\n\nuncurry : ∀ {a b c} {A : Set a} {B : A → Set b} {C : Σ A B → Set c} →\n ((x : A) → (y : B x) → C (x , y)) →\n ((p : Σ A B) → C p)\nuncurry f (x , y) = f x y\n\nuncurry′ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →\n (A → B → C) → (A × B → C)\nuncurry′ = uncurry\n", "meta": {"hexsha": "13a7711e4f124b1618b713d99240a893e9c3747c", "size": 3787, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Product.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": "test/asset/agda-stdlib-1.0/Data/Product.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Data/Product.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": 28.0518518519, "max_line_length": 93, "alphanum_fraction": 0.3741748086, "num_tokens": 1621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.6548947425132315, "lm_q1q2_score": 0.3979554151424856}} {"text": "module Sets.IterativeSet.Oper.Proofs where\n\nimport Lvl\nopen import Data\nopen import Data.Boolean\nopen import Data.Boolean.Stmt\nopen import Data.Either as Either using (_‖_)\nopen import Data.Tuple as Tuple using ()\nopen import Functional\nopen import Logic\nopen import Logic.Propositional\nopen import Logic.Predicate\nopen import Relator.Equals using () renaming (_≡_ to Id ; [≡]-intro to intro)\nopen import Sets.IterativeSet.Oper\nopen import Sets.IterativeSet.Relator\nopen import Sets.IterativeSet.Relator.Proofs\nopen import Sets.IterativeSet\nopen import Structure.Function.Domain\nopen import Structure.Function\nopen import Structure.Relator.Properties\nopen import Structure.Relator\nopen import Syntax.Function\nopen import Syntax.Transitivity\nopen import Type.Dependent\nopen import Type.Properties.Decidable\nopen import Type.Properties.Decidable.Proofs\n\nmodule _ where\n private variable {ℓ ℓ₁ ℓ₂} : Lvl.Level\n open Iset\n\n -- If there is an element in the empty set, then there exists an instance of the empty type by definition, and that is false by definition.\n ∅-membership : ∀{x : Iset{ℓ₁}} → (x ∉ ∅ {ℓ₂})\n ∅-membership ()\n\n -- There is a bijection between (A ‖ B) and ∃{Lvl.Up Bool}(\\{(Lvl.up 𝐹) → A ; (Lvl.up 𝑇) → B}).\n pair-membership : ∀{a b x : Iset{ℓ}} → (x ∈ pair a b) ↔ (x ≡ a)∨(x ≡ b)\n Tuple.left (pair-membership {a = a} {x}) ([∨]-introₗ p) = [∃]-intro (Lvl.up 𝐹) ⦃ p ⦄\n Tuple.left (pair-membership {a = a} {x}) ([∨]-introᵣ p) = [∃]-intro (Lvl.up 𝑇) ⦃ p ⦄\n Tuple.right (pair-membership {a = a} {x}) ([∃]-intro (Lvl.up 𝐹) ⦃ eq ⦄) = [∨]-introₗ eq\n Tuple.right (pair-membership {a = a} {x}) ([∃]-intro (Lvl.up 𝑇) ⦃ eq ⦄) = [∨]-introᵣ eq\n\n -- There is a bijection between (A) and ∃{Unit}(\\{<> → A}).\n singleton-membership : ∀{a x : Iset{ℓ}} → (x ∈ singleton(a)) ↔ (x ≡ a)\n Tuple.left (singleton-membership {a = a} {x}) xin = [∃]-intro <> ⦃ xin ⦄\n Tuple.right (singleton-membership {a = a} {x}) ([∃]-intro i ⦃ eq ⦄ ) = eq\n\n [∪]-membership : ∀{A B x : Iset{ℓ}} → (x ∈ (A ∪ B)) ↔ (x ∈ A)∨(x ∈ B)\n Tuple.left ([∪]-membership {A = A} {B} {x}) ([∨]-introₗ ([∃]-intro ia)) = [∃]-intro (Either.Left ia)\n Tuple.left ([∪]-membership {A = A} {B} {x}) ([∨]-introᵣ ([∃]-intro ib)) = [∃]-intro (Either.Right ib)\n Tuple.right ([∪]-membership {A = A} {B} {x}) ([∃]-intro ([∨]-introₗ ia)) = [∨]-introₗ ([∃]-intro ia)\n Tuple.right ([∪]-membership {A = A} {B} {x}) ([∃]-intro ([∨]-introᵣ ib)) = [∨]-introᵣ ([∃]-intro ib)\n\n [⋃]-membership : ∀{A x : Iset{ℓ}} → (x ∈ (⋃ A)) ↔ ∃(a ↦ (a ∈ A) ∧ (x ∈ a))\n Σ.left (∃.witness (Tuple.left ([⋃]-membership {A = A} {x}) ([∃]-intro a ⦃ [∧]-intro ([∃]-intro iA) _ ⦄))) = iA\n Σ.right (∃.witness (Tuple.left ([⋃]-membership {A = A} {x}) ([∃]-intro a ⦃ [∧]-intro ([∃]-intro iA ⦃ aA ⦄) ([∃]-intro ia) ⦄))) = _⊆_.map (Tuple.right aA) ia\n ∃.proof (Tuple.left ([⋃]-membership {A = A} {x}) ([∃]-intro a ⦃ [∧]-intro ([∃]-intro iA ⦃ aA ⦄) ([∃]-intro ia ⦃ xa ⦄) ⦄)) = [≡]-transitivity-raw xa ([⊆]-with-elem (sub₂(_≡_)(_⊆_) aA) {ia})\n ∃.witness (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄)) = elem(A)(iA)\n Tuple.left (∃.proof (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄))) = [∈]-of-elem {A = A}\n ∃.witness (Tuple.right (∃.proof (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄)))) = ia\n ∃.proof (Tuple.right (∃.proof (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄)))) = proof\n\n module _ {A : Iset{ℓ}} where\n open import Relator.Equals.Proofs.Equivalence using ([≡]-equiv)\n instance _ = [≡]-equiv {T = Index(A)}\n\n module _ {P : Index(A) → Stmt{ℓ}} where\n indexFilter-elem-membershipₗ : ∀{i : Index(A)} → (elem(A)(i) ∈ indexFilter A P) ← P(i)\n Σ.left (∃.witness ((indexFilter-elem-membershipₗ {i = i}) pi)) = i\n Σ.right(∃.witness ((indexFilter-elem-membershipₗ {i = i}) pi)) = pi\n Tuple.left (∃.proof (indexFilter-elem-membershipₗ pi)) = intro id [≡]-reflexivity-raw\n Tuple.right (∃.proof (indexFilter-elem-membershipₗ pi)) = intro id [≡]-reflexivity-raw\n\n module _\n ⦃ _ : Injective(elem A) ⦄ -- TODO: Is this satisfiable?\n {P : Index(A) → Stmt{ℓ}}\n ⦃ unaryRelator-P : UnaryRelator(P) ⦄\n where\n\n indexFilter-elem-membership : ∀{i : Index(A)} → (elem(A)(i) ∈ indexFilter A P) ↔ P(i)\n Tuple.left indexFilter-elem-membership = indexFilter-elem-membershipₗ\n Tuple.right (indexFilter-elem-membership {i = i}) ([∃]-intro (intro iA PiA) ⦃ pp ⦄) = substitute₁(P) (injective(elem A) (symmetry(_≡_) pp)) PiA\n\n filter-elem-membership : ∀{A : Iset{ℓ}}{P} ⦃ _ : UnaryRelator(P) ⦄ {i : Index(A)} → (elem(A)(i) ∈ filter A P) ↔ P(elem(A)(i))\n Tuple.left (filter-elem-membership {A = A}{P = P}) = indexFilter-elem-membershipₗ {A = A}{P = P ∘ elem(A)}\n Tuple.right (filter-elem-membership {P = P}) ([∃]-intro (intro iA PiA) ⦃ pp ⦄) = substitute₁(P) (symmetry(_≡_) pp) PiA\n\n filter-membership : ∀{A : Iset{ℓ}}{P} ⦃ _ : UnaryRelator(P) ⦄ {x : Iset{ℓ}} → (x ∈ filter A P) ↔ ((x ∈ A) ∧ P(x))\n ∃.witness (Tuple.left(filter-membership {P = P}) ([∧]-intro ([∃]-intro i ⦃ p ⦄) pb)) = intro i (substitute₁(P) p pb)\n ∃.proof (Tuple.left(filter-membership) ([∧]-intro ([∃]-intro i ⦃ p ⦄) pb)) = p\n ∃.witness (Tuple.left (Tuple.right(filter-membership) ([∃]-intro (intro iA PiA) ⦃ pp ⦄))) = iA\n ∃.proof (Tuple.left (Tuple.right(filter-membership) ([∃]-intro (intro iA PiA) ⦃ pp ⦄))) = pp\n Tuple.right (Tuple.right(filter-membership {P = P}) ([∃]-intro (intro iA PiA) ⦃ pp ⦄)) = substitute₁(P) (symmetry(_≡_) pp) PiA\n\n mapSet-membership : ∀{A : Iset{ℓ}}{f} ⦃ _ : Function(f) ⦄ {y : Iset{ℓ}} → (y ∈ mapSet f(A)) ↔ ∃(x ↦ (x ∈ A) ∧ (y ≡ f(x)))\n ∃.witness (Tuple.left (mapSet-membership) ([∃]-intro x ⦃ [∧]-intro xA fxy ⦄)) = [∃]-witness xA\n ∃.proof (Tuple.left (mapSet-membership {A = A} {f = f} {y = y}) ([∃]-intro x ⦃ [∧]-intro xA fxy ⦄)) =\n y 🝖[ _≡_ ]-[ fxy ]\n f(x) 🝖[ _≡_ ]-[ congruence₁(f) ([∃]-proof xA) ]\n f(elem(A) ([∃]-witness xA)) 🝖[ _≡_ ]-[]\n elem (mapSet f(A)) ([∃]-witness xA) 🝖[ _≡_ ]-end\n ∃.witness (Tuple.right (mapSet-membership {A = A}) ([∃]-intro iA)) = elem(A) iA\n Tuple.left (∃.proof (Tuple.right (mapSet-membership {A = A}) ([∃]-intro iA ⦃ p ⦄))) = [∈]-of-elem {A = A} {ia = iA}\n Tuple.right (∃.proof (Tuple.right mapSet-membership ([∃]-intro iA ⦃ p ⦄))) = p\n\n open import Logic.Classical\n module _ ⦃ classical : ∀{ℓ}{P} → Classical{ℓ}(P) ⦄ where\n instance _ = classical-to-decidable\n instance _ = classical-to-decider\n\n indexFilterBool-subset : ∀{A : Iset{ℓ}}{P} → (indexFilterBool A P ⊆ A)\n _⊇_.map indexFilterBool-subset (intro iA _) = iA\n _⊇_.proof (indexFilterBool-subset {ℓ = ℓ}{A = A}{P = P}) {intro iA (Lvl.up PiA)} =\n elem (indexFilterBool A P) (intro iA (Lvl.up PiA)) 🝖[ _≡_ ]-[]\n elem (indexFilter A (Lvl.Up ∘ IsTrue ∘ P)) (intro iA (Lvl.up PiA)) 🝖[ _≡_ ]-[]\n elem A (Σ.left {B = Lvl.Up{ℓ} ∘ IsTrue ∘ P} (intro iA (Lvl.up PiA))) 🝖[ _≡_ ]-[]\n elem A iA 🝖[ _≡_ ]-end\n\n ℘-membershipₗ : ∀{A : Iset{ℓ}}{B : Iset{ℓ}} → (B ∈ ℘(A)) ← (B ⊆ A)\n ∃.witness (℘-membershipₗ {A = A}{B = B} BA) iA = decide(0)(∃(iB ↦ Id(_⊆_.map BA iB) iA))\n _⊇_.map (Tuple.left (∃.proof (℘-membershipₗ {A = A} {B = B} _))) (intro iA (Lvl.up mapiBiA)) = [∃]-witness([↔]-to-[←] decider-true mapiBiA)\n _⊇_.proof (Tuple.left (∃.proof (℘-membershipₗ {ℓ = ℓ} {A = A} {B = B} BA))) {intro iA (Lvl.up mapiBiA)} =\n elem (elem (℘ A) f) (intro iA (Lvl.up mapiBiA)) 🝖[ _≡_ ]-[]\n elem (indexFilterBool A f) (intro iA (Lvl.up mapiBiA)) 🝖[ _≡_ ]-[]\n elem (indexFilter A (Lvl.Up ∘ IsTrue ∘ f)) (intro iA (Lvl.up mapiBiA)) 🝖[ _≡_ ]-[]\n elem A (Σ.left {B = Lvl.Up{ℓ} ∘ IsTrue ∘ f} (intro iA (Lvl.up mapiBiA))) 🝖[ _≡_ ]-[]\n elem A iA 🝖[ _≡_ ]-[ [≡]-to-equivalence(congruence₁(elem A) ([∃]-proof emapiBiA)) ]-sym\n elem A (_⊆_.map BA ([∃]-witness emapiBiA)) 🝖[ _≡_ ]-[ _⊆_.proof BA {[∃]-witness emapiBiA} ]-sym\n elem B ([∃]-witness emapiBiA) 🝖[ _≡_ ]-end\n where\n f = \\iA → decide(0)(∃(iB ↦ Id(_⊆_.map BA iB) iA))\n emapiBiA = [↔]-to-[←] decider-true mapiBiA\n open import Relator.Equals.Proofs.Equiv using ([≡]-to-equivalence)\n _⊇_.map (Tuple.right (∃.proof (℘-membershipₗ {A = A} {B = B} BA))) iB = intro (_⊆_.map BA iB) (Lvl.up ([↔]-to-[→] decider-true ([∃]-intro iB ⦃ intro ⦄)))\n _⊇_.proof (Tuple.right (∃.proof (℘-membershipₗ {A = A} {B = B} BA))) = _⊆_.proof BA\n\n ℘-membershipᵣ : ∀{A : Iset{ℓ}}{B : Iset{ℓ}} → (B ∈ ℘(A)) → (B ⊆ A)\n ℘-membershipᵣ ([∃]-intro witness ⦃ b≡indexFilterBool ⦄) = substitute₂ₗ(_⊆_) (symmetry(_≡_) b≡indexFilterBool) indexFilterBool-subset\n\n ℘-membership : ∀{A : Iset{ℓ}}{x : Iset{ℓ}} → (x ∈ ℘(A)) ↔ (x ⊆ A)\n ℘-membership = [↔]-intro ℘-membershipₗ ℘-membershipᵣ\n", "meta": {"hexsha": "c573dbad1d832f5089982df95bc455a8cea47bf9", "size": 9110, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Sets/IterativeSet/Oper/Proofs.agda", "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_issues_repo_path": "Sets/IterativeSet/Oper/Proofs.agda", "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": "Sets/IterativeSet/Oper/Proofs.agda", "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": 64.1549295775, "max_line_length": 190, "alphanum_fraction": 0.5540065862, "num_tokens": 3767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872243177517, "lm_q2_score": 0.5312093733737562, "lm_q1q2_score": 0.3979221550321192}} {"text": "module Structure.Categorical.Proofs where\n\nopen import Data\nopen import Functional\nopen import Logic.Propositional\nimport Lvl\nopen import Structure.Setoid\nopen import Structure.Categorical.Properties\nimport Structure.Relator.Names as Names\nopen import Structure.Relator.Properties\nopen import Type\n\nprivate variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓₘ ℓₑ : Lvl.Level\nprivate variable Obj A B : Type{ℓ}\nprivate variable _▫_ : Obj → Obj → Type{ℓ}\nprivate variable f : A → B\n\nempty-morphism : ∀{ℓₘ ℓ} → Empty{ℓ} → Empty{ℓ} → Type{ℓₘ}\nempty-morphism{ℓₘ}{ℓ} = empty{T = Empty{ℓ} → Type{ℓₘ}}\n\nempty-id : Names.Reflexivity(empty-morphism{ℓₘ}{ℓ})\nempty-id {x = ()}\n\nempty-comp : Names.SwappedTransitivity(empty-morphism{ℓₘ}{ℓ})\nempty-comp {x = ()}\n\nempty-inv : Names.Symmetry(empty-morphism{ℓₘ}{ℓ})\nempty-inv {x = ()}\n\nmodule _ ⦃ empty-equiv : ∀{x y} → Equiv{ℓₑ}(empty-morphism{ℓₘ}{ℓ} x y) ⦄ where\n instance\n empty-associativity : Morphism.Associativity{Morphism = empty-morphism} ⦃ empty-equiv ⦄ empty-comp\n empty-associativity = Morphism.intro \\{}\n\n instance\n empty-identityₗ : Morphism.Identityₗ{Morphism = empty-morphism} ⦃ empty-equiv ⦄ empty-comp empty-id\n empty-identityₗ = Morphism.intro \\{}\n\n instance\n empty-identityᵣ : Morphism.Identityᵣ{Morphism = empty-morphism} ⦃ empty-equiv ⦄ empty-comp empty-id\n empty-identityᵣ = Morphism.intro \\{}\n\n empty-identity : Morphism.Identity empty-comp empty-id\n empty-identity = [∧]-intro empty-identityₗ empty-identityᵣ\n\n instance\n empty-inverterₗ : Polymorphism.Inverterₗ {Morphism = empty-morphism} ⦃ empty-equiv ⦄ empty-comp empty-id empty-inv\n empty-inverterₗ = Polymorphism.intro \\{}\n\n instance\n empty-inverterᵣ : Polymorphism.Inverterᵣ {Morphism = empty-morphism} ⦃ empty-equiv ⦄ empty-comp empty-id empty-inv\n empty-inverterᵣ = Polymorphism.intro \\{}\n\n empty-inverter : Polymorphism.Inverter empty-comp empty-id empty-inv\n empty-inverter = [∧]-intro empty-inverterₗ empty-inverterᵣ\n\nsingle-morphism : ∀{ℓₘ ℓ} → Unit{ℓ} → Unit{ℓ} → Type{ℓₘ}\nsingle-morphism <> <> = Unit\n\nsingle-id : Names.Reflexivity(single-morphism{ℓₘ}{ℓ})\nsingle-id = <>\n\nsingle-comp : Names.SwappedTransitivity(single-morphism{ℓₘ}{ℓ})\nsingle-comp <> <> = <>\n\nsingle-inv : Names.Symmetry(single-morphism{ℓₘ}{ℓ})\nsingle-inv <> = <>\n\nmodule _ ⦃ single-equiv : ∀{x y} → Equiv{ℓₑ}(single-morphism{ℓₘ}{ℓ} x y) ⦄ where\n instance\n single-associativity : Morphism.Associativity{Morphism = single-morphism{ℓₘ}{ℓ₁}} ⦃ single-equiv ⦄ (single-comp{ℓ = ℓ₂})\n Morphism.Associativity.proof single-associativity {<>}{<>}{<>}{<>}{<>}{<>}{<>} = Reflexivity.proof(Equiv.reflexivity (single-equiv {<>}{<>}))\n\n instance\n single-identityₗ : Morphism.Identityₗ{Morphism = single-morphism{ℓₘ}{ℓ₁}} ⦃ single-equiv ⦄ (single-comp{ℓ = ℓ₂}) (single-id{ℓ = ℓ₃})\n Morphism.Identityₗ.proof single-identityₗ {<>}{<>}{<>} = Reflexivity.proof(Equiv.reflexivity (single-equiv {<>}{<>}))\n\n instance\n single-identityᵣ : Morphism.Identityᵣ{Morphism = single-morphism{ℓₘ}{ℓ₁}} ⦃ single-equiv ⦄ (single-comp{ℓ = ℓ₂}) (single-id{ℓ = ℓ₃})\n Morphism.Identityᵣ.proof single-identityᵣ {<>}{<>}{<>} = Reflexivity.proof(Equiv.reflexivity (single-equiv {<>}{<>}))\n\n single-identity : Morphism.Identity{Morphism = single-morphism{ℓₘ}{ℓ₁}} (single-comp{ℓ = ℓ₂}) (single-id{ℓ = ℓ₃})\n single-identity{ℓ₁}{ℓ₂}{ℓ₃} = [∧]-intro (single-identityₗ{ℓ₁}{ℓ₂}{ℓ₃}) (single-identityᵣ{ℓ₁}{ℓ₂}{ℓ₃})\n\n instance\n single-inverterₗ : Polymorphism.Inverterₗ {Morphism = single-morphism{ℓₘ}{ℓ₁}} ⦃ single-equiv ⦄ (single-comp{ℓ = ℓ₂}) (single-id{ℓ = ℓ₃}) (single-inv{ℓ = ℓ₄})\n Polymorphism.Inverterₗ.proof single-inverterₗ {<>}{<>}{<>} = Reflexivity.proof(Equiv.reflexivity (single-equiv {<>}{<>}))\n\n instance\n single-inverterᵣ : Polymorphism.Inverterᵣ {Morphism = single-morphism{ℓₘ}{ℓ₁}} ⦃ single-equiv ⦄ (single-comp{ℓ = ℓ₂}) (single-id{ℓ = ℓ₃}) (single-inv{ℓ = ℓ₄})\n Polymorphism.Inverterᵣ.proof single-inverterᵣ {<>}{<>}{<>} = Reflexivity.proof(Equiv.reflexivity (single-equiv {<>}{<>}))\n\n single-inverter : Polymorphism.Inverter {Morphism = single-morphism{ℓₘ}{ℓ₁}} ⦃ single-equiv ⦄ (single-comp{ℓ = ℓ₂}) (single-id{ℓ = ℓ₃}) (single-inv{ℓ = ℓ₄})\n single-inverter{ℓ₁}{ℓ₂}{ℓ₃}{ℓ₄} = [∧]-intro (single-inverterₗ{ℓ₁}{ℓ₂}{ℓ₃}{ℓ₄}) (single-inverterᵣ{ℓ₁}{ℓ₂}{ℓ₃}{ℓ₄})\n\nmodule _ {Morphism : B → B → Type{ℓₘ}} ⦃ morphism-equiv : ∀{x y} → Equiv{ℓₑ}(Morphism x y) ⦄ (f : A → B) where\n module _ {comp : Names.SwappedTransitivity(Morphism)} where\n on₂-associativity : Morphism.Associativity{Morphism = Morphism} ⦃ morphism-equiv ⦄ comp → Morphism.Associativity{Morphism = Morphism on₂ f} comp\n Morphism.Associativity.proof (on₂-associativity p) = Morphism.Associativity.proof p\n\n module _ {id : Names.Reflexivity(Morphism)} where\n on₂-identityₗ : Morphism.Identityₗ{Morphism = Morphism} ⦃ morphism-equiv ⦄ comp id → Morphism.Identityₗ{Morphism = Morphism on₂ f} comp id\n Morphism.Identityₗ.proof (on₂-identityₗ p) = Morphism.Identityₗ.proof p\n\n on₂-identityᵣ : Morphism.Identityᵣ{Morphism = Morphism} ⦃ morphism-equiv ⦄ comp id → Morphism.Identityᵣ{Morphism = Morphism on₂ f} comp id\n Morphism.Identityᵣ.proof (on₂-identityᵣ p) = Morphism.Identityᵣ.proof p\n\n on₂-identity : Morphism.Identity{Morphism = Morphism} ⦃ morphism-equiv ⦄ comp id → Morphism.Identity{Morphism = Morphism on₂ f} comp id\n on₂-identity ([∧]-intro l r) = [∧]-intro (on₂-identityₗ l) (on₂-identityᵣ r)\n\n module _ {inv : Names.Symmetry(Morphism)} where\n on₂-inverterₗ : Polymorphism.Inverterₗ {Morphism = Morphism} ⦃ morphism-equiv ⦄ comp id inv → Polymorphism.Inverterₗ {Morphism = Morphism on₂ f} comp id inv\n Polymorphism.Inverterₗ.proof (on₂-inverterₗ p) = Polymorphism.Inverterₗ.proof p\n\n on₂-inverterᵣ : Polymorphism.Inverterᵣ {Morphism = Morphism} ⦃ morphism-equiv ⦄ comp id inv → Polymorphism.Inverterᵣ {Morphism = Morphism on₂ f} comp id inv\n Polymorphism.Inverterᵣ.proof (on₂-inverterᵣ p) = Polymorphism.Inverterᵣ.proof p\n\n on₂-inverter : Polymorphism.Inverter{Morphism = Morphism} ⦃ morphism-equiv ⦄ comp id inv → Polymorphism.Inverter{Morphism = Morphism on₂ f} comp id inv\n on₂-inverter ([∧]-intro l r) = [∧]-intro (on₂-inverterₗ l) (on₂-inverterᵣ r)\n", "meta": {"hexsha": "148173474682af919183eda62b2b4e5bcc2d957e", "size": 6227, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Structure/Categorical/Proofs.agda", "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_issues_repo_path": "Structure/Categorical/Proofs.agda", "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": "Structure/Categorical/Proofs.agda", "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": 51.8916666667, "max_line_length": 164, "alphanum_fraction": 0.7001766501, "num_tokens": 2284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.5350984286266116, "lm_q1q2_score": 0.3976680336141068}} {"text": "open import Prelude\n\nmodule Implicits.Substitutions.Context where\n\nopen import Implicits.Syntax.Type\nopen import Implicits.Syntax.Context\nopen import Implicits.Substitutions.Type as TS using ()\n\nopen import Data.Fin.Substitution\nopen import Data.Star as Star hiding (map)\nopen import Data.Star.Properties\nopen import Data.Vec\nopen import Data.List as List using ()\n\nktx-map : ∀ {ν μ n} → (Type ν → Type μ) → Ktx ν n → Ktx μ n\nktx-map f (Γ , Δ) = map f Γ , List.map f Δ\n\n_/_ : ∀ {ν μ n} → Ktx ν n → Sub Type ν μ → Ktx μ n\nK / σ = ktx-map (λ t → t TS./ σ) K\n\n_/Var_ : ∀ {ν m n} → Sub Fin n m → Ktx ν m → Ktx ν n\nσ /Var (Γ , Δ) = map (λ x → lookup x Γ) σ , Δ\n\nictx-weaken : ∀ {ν} → ICtx ν → ICtx (suc ν)\nictx-weaken Δ = List.map (flip TS._/_ TS.wk) Δ\n\nctx-weaken : ∀ {ν n} → Ctx ν n → Ctx (suc ν) n\nctx-weaken Γ = map (flip TS._/_ TS.wk) Γ\n\nweaken : ∀ {ν n} → Ktx ν n → Ktx (suc ν) n\nweaken K = K / TS.wk\n", "meta": {"hexsha": "ba80ddcf724bd50875674da760d84939f87f52ed", "size": 903, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Implicits/Substitutions/Context.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/Substitutions/Context.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/Substitutions/Context.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": 28.21875, "max_line_length": 60, "alphanum_fraction": 0.6367663344, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.3976584546950499}} {"text": "open import Nat\nopen import Prelude\nopen import List\nopen import Hazelnut-core\n\nmodule Hazelnut-checks where\n -----------------------------------------------------------------------------\n\n -- these theorems aren't listed in the draft, but have been discussed\n -- since submission. broadly speaking, they act as sanity checks on the\n -- rules. if these properties can't be proven for any extensions to the\n -- language, then the rules are not good.\n\n -----------------------------------------------------------------------------\n\n -- movement doesn't change the term other than moving the focus around.\n moveerase : {e e' : ê} {δ : direction} {t : τ̇} →\n (e + move δ +>e e') →\n (e ◆e) == (e' ◆e)\n moveerase EMAscFirstChild = refl\n moveerase EMAscParent1 = refl\n moveerase EMAscParent2 = refl\n moveerase EMAscNextSib = refl\n moveerase EMAscPrevSib = refl\n moveerase EMLamFirstChild = refl\n moveerase EMLamParent = refl\n moveerase EMPlusFirstChild = refl\n moveerase EMPlusParent1 = refl\n moveerase EMPlusParent2 = refl\n moveerase EMPlusNextSib = refl\n moveerase EMPlusPrevSib = refl\n moveerase EMApFirstChild = refl\n moveerase EMApParent1 = refl\n moveerase EMApParent2 = refl\n moveerase EMApNextSib = refl\n moveerase EMApPrevSib = refl\n moveerase EMFHoleFirstChild = refl\n moveerase EMFHoleParent = refl\n\n -- describes lists of action whose semantics are composable\n data iterok : Set where\n\n -- iterates a list of actions that can be composed\n data iterate : iterok → ê → ê → Set where\n\n --constructability\n mutual\n constructable1 : {Γ : ·ctx} {e : ê} {t : τ̇} →\n (wt : Γ ⊢ (e ◆e) => t) →\n Σ[ αs ∈ iterok ]\n (Σ[ e' ∈ ê ] ((iterate αs (▹ <||> ◃) e') ×\n ((e ◆e) == (e' ◆e))))\n constructable1 = {!!}\n\n constructable2 : {Γ : ·ctx} {e : ê} {t : τ̇} →\n (wt : Γ ⊢ (e ◆e) <= t) →\n Σ[ αs ∈ iterok ]\n (Σ[ e' ∈ ê ] ((iterate αs (▹ <||> ◃) e') ×\n ((e ◆e) == (e' ◆e))))\n constructable2 = {!!}\n\n --reachability\n mutual\n reachable1 : {Γ : ·ctx} {e e' : ê} {t : τ̇}\n (wt : Γ ⊢ (e ◆e) <= t) →\n (wt' : Γ ⊢ (e' ◆e) <= t) →\n (p : (e ◆e) == (e' ◆e)) →\n Σ[ αs ∈ iterok ] (iterate αs e e')\n reachable1 = {!!}\n\n reachable2 : {Γ : ·ctx} {e e' : ê} {t : τ̇}\n (wt : Γ ⊢ (e ◆e) => t) →\n (wt' : Γ ⊢ (e' ◆e) => t) →\n (p : (e ◆e) == (e' ◆e)) →\n Σ[ αs ∈ iterok ] (iterate αs e e')\n reachable2 = {!!}\n", "meta": {"hexsha": "3033241692107d6a9b0fe7c7479f72fcf1f5631c", "size": 2691, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Hazelnut-checks.agda", "max_stars_repo_name": "ivoysey/agda-tfp16", "max_stars_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-09T13:35:22.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-14T02:19:58.000Z", "max_issues_repo_path": "Hazelnut-checks.agda", "max_issues_repo_name": "ivoysey/agda-tfp16", "max_issues_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb", "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": "Hazelnut-checks.agda", "max_forks_repo_name": "ivoysey/agda-tfp16", "max_forks_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb", "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": 34.9480519481, "max_line_length": 79, "alphanum_fraction": 0.4871794872, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300698514778, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.3976450410685483}} {"text": "{-\n\nThis file contains:\n - The equivalence \"James X ≃ Ω Σ X\" for any connected pointed type X.\n (KANG Rongji, Feb. 2022)\n\n-}\n{-# OPTIONS --safe #-}\nmodule Cubical.HITs.James.LoopSuspEquiv where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.GroupoidLaws\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Equiv.Fiberwise\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Pointed\n\nopen import Cubical.Data.Unit\nopen import Cubical.Data.Sigma\nopen import Cubical.HITs.Pushout\nopen import Cubical.HITs.Pushout.Flattening\nopen import Cubical.HITs.Susp\nopen import Cubical.HITs.James.Base\n renaming (James to JamesContruction ; James∙ to JamesContruction∙)\nopen import Cubical.HITs.Truncation\n\nopen import Cubical.Homotopy.Connected\nopen import Cubical.Homotopy.Loopspace\n\nprivate\n variable\n ℓ : Level\n\nmodule _\n ((X , x₀) : Pointed ℓ) where\n\n private\n James = JamesContruction (X , x₀)\n James∙ = JamesContruction∙ (X , x₀)\n\n Total : Type ℓ\n Total = Pushout {A = X × James} snd (λ (x , xs) → x ∷ xs)\n\n private\n flipSquare : (xs : James)(i j : I) → James\n flipSquare xs i j =\n hcomp (λ k → λ\n { (i = i0) → unit xs (j ∨ k)\n ; (i = i1) → unit (x₀ ∷ xs) j\n ; (j = i0) → unit xs (i ∨ k)\n ; (j = i1) → x₀ ∷ (unit xs i) })\n (unit (unit xs i) j)\n\n square1 : (x : X)(xs : James)(i j : I) → Total\n square1 x xs i j =\n hfill (λ j → λ\n { (i = i0) → push (x , xs) (~ j)\n ; (i = i1) → push (x₀ , x ∷ xs) (~ j) })\n (inS (inr (unit (x ∷ xs) i))) j\n\n square2 : (xs : James)(i j : I) → Total\n square2 xs i j =\n hcomp (λ k → λ\n { (i = i0) → push (x₀ , xs) (~ k)\n ; (i = i1) → square1 x₀ xs j k\n ; (j = i0) → push (x₀ , xs) (~ k)\n ; (j = i1) → push (x₀ , unit xs i) (~ k) })\n (inr (flipSquare xs i j))\n\n center : Total\n center = inl []\n\n pathL : (xs : James) → center ≡ inl xs\n pathL [] = refl\n pathL (x ∷ xs) = pathL xs ∙ (λ i → square1 x xs i i1)\n pathL (unit xs i) j =\n hcomp (λ k → λ\n { (i = i0) → pathL xs j\n ; (i = i1) → compPath-filler (pathL xs) (λ i → square1 x₀ xs i i1) k j\n ; (j = i0) → inl []\n ; (j = i1) → square2 xs i k })\n (pathL xs j)\n\n isContrTotal : isContr Total\n isContrTotal .fst = center\n isContrTotal .snd (inl xs) = pathL xs\n isContrTotal .snd (inr xs) = pathL xs ∙∙ push (x₀ , xs) ∙∙ (λ i → inr (unit xs (~ i)))\n isContrTotal .snd (push (x , xs) i) j =\n hcomp (λ k → λ\n { (i = i0) → compPath-filler' (pathL xs) (λ i → square1 x xs i i1) (~ j) (~ k)\n ; (i = i1) → doubleCompPath-filler (pathL (x ∷ xs)) (push (x₀ , x ∷ xs)) (λ i → inr (unit (x ∷ xs) (~ i))) k j\n ; (j = i0) → pathL (x ∷ xs) (~ k)\n ; (j = i1) → square1 x xs (~ k) (~ i) })\n (push (x₀ , x ∷ xs) (i ∧ j))\n\n module _\n (conn : isConnected 2 X) where\n\n private\n isEquivx₀∷ : isEquiv {A = James} (x₀ ∷_)\n isEquivx₀∷ = subst isEquiv (λ i xs → unit xs i) (idIsEquiv _)\n\n ∣isEquiv∣ : hLevelTrunc 2 X → Type ℓ\n ∣isEquiv∣ x = rec isSetHProp (λ x → isEquiv {A = James} (x ∷_) , isPropIsEquiv _) x .fst\n\n isEquiv∷ : (x : X) → isEquiv {A = James} (x ∷_)\n isEquiv∷ x = subst ∣isEquiv∣ (sym (conn .snd ∣ x₀ ∣) ∙ (conn .snd ∣ x ∣)) isEquivx₀∷\n\n Code : Susp X → Type ℓ\n Code north = James\n Code south = James\n Code (merid x i) = ua (_ , isEquiv∷ x) i\n\n private\n open FlatteningLemma (λ _ → tt) (λ _ → tt) (λ tt → James) (λ tt → James) (λ x → _ , isEquiv∷ x)\n\n Total≃ : Pushout Σf Σg ≃ Total\n Total≃ = pushoutEquiv _ _ _ _ (idEquiv _) (ΣUnit _) (ΣUnit _) refl refl\n\n PushoutSuspCode : (x : PushoutSusp X) → E x ≃ Code (PushoutSusp→Susp x)\n PushoutSuspCode (inl tt) = idEquiv _\n PushoutSuspCode (inr tt) = idEquiv _\n PushoutSuspCode (push x i) = idEquiv _\n\n ΣCode≃' : _ ≃ Σ _ Code\n ΣCode≃' = Σ-cong-equiv PushoutSusp≃Susp PushoutSuspCode\n\n ΣCode≃ : Total ≃ Σ _ Code\n ΣCode≃ = compEquiv (invEquiv Total≃) (compEquiv (invEquiv flatten) ΣCode≃')\n\n isContrΣCode : isContr (Σ _ Code)\n isContrΣCode = isOfHLevelRespectEquiv _ ΣCode≃ isContrTotal\n\n ΩΣ≃J : Ω (Susp∙ X) .fst ≃ James\n ΩΣ≃J = recognizeId Code [] isContrΣCode _\n\n ΩΣ≃∙J : Ω (Susp∙ X) ≃∙ James∙\n ΩΣ≃∙J = ΩΣ≃J , refl\n\n J≃ΩΣ : James ≃ Ω (Susp∙ X) .fst\n J≃ΩΣ = invEquiv ΩΣ≃J\n\n J≃∙ΩΣ : James∙ ≃∙ Ω (Susp∙ X)\n J≃∙ΩΣ = invEquiv∙ ΩΣ≃∙J\n", "meta": {"hexsha": "e2b6ea08f720fd11210e03891507d904ebb3b76a", "size": 4497, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/HITs/James/LoopSuspEquiv.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_issues_repo_path": "Cubical/HITs/James/LoopSuspEquiv.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/HITs/James/LoopSuspEquiv.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": 30.801369863, "max_line_length": 116, "alphanum_fraction": 0.5690460307, "num_tokens": 1829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300449389326, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.3976450269675859}} {"text": "open import Agda.Builtin.List\nopen import Agda.Builtin.Unit\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.String\n renaming (primShowNat to show)\nopen import Agda.Builtin.Reflection\n renaming (bindTC to _>>=_; returnTC to return)\n\npattern vArg t = arg (arg-info visible relevant) t\npattern var₀ x = var x []\n\ninfixr 10 _++_\n_++_ = primStringAppend\n\npostulate\n whatever : ∀ {a} {A : Set a} → A\n\nmacro\n test1 : Nat → Term → TC _\n test1 n _ =\n extendContext (vArg (quoteTerm Nat)) do\n var₀ i ← quoteTC n where _ → whatever\n m ← unquoteTC {A = Nat} (var₀ 0)\n var₀ j ← quoteTC m where _ → whatever\n extendContext (vArg (quoteTerm Nat)) do\n var₀ k ← quoteTC n where _ → whatever\n var₀ l ← quoteTC m where _ → whatever\n typeError (strErr (show i ++ show k ++ show j ++ show l) ∷ [])\n\n test2 : Term → TC _\n test2 hole = do\n st ← quoteTC Set\n t ← extendContext (vArg st) do\n v ← unquoteTC {A = Set} (var₀ zero)\n extendContext (vArg (var₀ zero)) do\n _ ← unquoteTC {A = v} (var₀ zero)\n return tt\n u ← quoteTC t\n unify hole u\n\n test3 : Nat → Term → TC _\n test3 n _ = do\n m ← extendContext (vArg (quoteTerm Nat)) (return n)\n var₀ i ← quoteTC m where _ → whatever\n typeError (strErr (show i) ∷ [])\n\n localvar : Term → TC _\n localvar _ = do\n m ← extendContext (vArg (quoteTerm Nat)) (unquoteTC {A = Nat} (var₀ 0))\n typeError (strErr (show m) ∷ [])\n", "meta": {"hexsha": "8c1f7d2d2fc1b3d02a86e0f778696125dc00cff2", "size": 1451, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/interaction/Issue3831.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z", "max_issues_repo_path": "test/interaction/Issue3831.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_forks_repo_path": "test/interaction/Issue3831.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z", "avg_line_length": 28.4509803922, "max_line_length": 75, "alphanum_fraction": 0.622329428, "num_tokens": 470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.39735374981948346}} {"text": "{-# OPTIONS --without-K #-}\n\n{-\n This file lists some basic facts about equivalences\n that have to be put in a separate file due to dependency.\n-}\n\nopen import Types\nopen import Functions\nopen import Paths\nopen import HLevel\nopen import Equivalences\nopen import Univalence\nopen import HLevelBis\n\nmodule EquivalenceLemmas where\n\n equiv-eq : ∀ {i} {A B : Set i} {f g : A ≃ B} → π₁ f ≡ π₁ g → f ≡ g\n equiv-eq p = Σ-eq p $ prop-has-all-paths (is-equiv-is-prop _) _ _\n", "meta": {"hexsha": "c302b8c79843fb0ada626142fd93bd336cd356fa", "size": 467, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "old/EquivalenceLemmas.agda", "max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda", "max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "old/EquivalenceLemmas.agda", "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "old/EquivalenceLemmas.agda", "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 23.35, "max_line_length": 68, "alphanum_fraction": 0.7002141328, "num_tokens": 143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.39735374981948346}} {"text": "-- Andreas, 2020-09-26, issue #4946.\n-- More liberal type signatures for constructors of sized types.\n\n-- {-# OPTIONS -v tc.polarity:20 #-}\n\nopen import Agda.Builtin.Size\n\nvariable\n i : Size\n A : Set\n\ndata T : Size → Set → Set where\n c : A → T i A → T (↑ i) A\n\n-- The type of the constructor c is elaborated to\n--\n-- c : {A : Set} {i : Set} → A → T i A → T (↑ i) A\n--\n-- Thus, the size argument i is not the first.\n-- Nevertheless, Agda recognize the first argument of T\n-- as covariant.\n\ntest : T i A → T ∞ A\ntest x = x\n\n-- Should pass.\n", "meta": {"hexsha": "fcbde800ade2b3587943f7ac5e38323fd64bdc80", "size": 543, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue4946.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/Succeed/Issue4946.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/Succeed/Issue4946.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": 20.1111111111, "max_line_length": 64, "alphanum_fraction": 0.6132596685, "num_tokens": 176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6619228625116081, "lm_q2_score": 0.6001883592602051, "lm_q1q2_score": 0.3972783968076604}} {"text": "\nmodule _ where\n\nopen import Common.Prelude hiding (_>>=_)\nopen import Common.Reflection\nopen import Agda.Builtin.Sigma\n\ninfix -100 This:_ this:_\ndata This:_ {a} {A : Set a} : A → Set where\n this:_ : ∀ x → This: x\n\nmacro\n runT : Tactic → Tactic\n runT m = m\n\n evalT : ∀ {a} {A : Set a} → TC A → Tactic\n evalT m hole = m >>= quoteTC >>= unify hole\n\n-- The context on the rhs of each of the two functions below is the same, a single String\n\nΓ : Telescope\nΓ = (\"s\" , vArg (def (quote String) [])) ∷ []\n\ncontext-Γ₀ : String → This: Γ\ncontext-Γ₀ s = this: evalT getContext\n\nmodule _ (S : String) where\n Γ' : Telescope\n Γ' = (\"S\" , vArg (def (quote String) [])) ∷ []\n\n context-Γ₁ : This: Γ'\n context-Γ₁ = this: evalT getContext\n\ndownMap : {A : Set} → (Nat → A) → Nat → List A\ndownMap f zero = []\ndownMap f (suc n) = f n ∷ downMap f n\n\nf-type : Term\nf-type = def (quote String) []\n\nf-tel : Nat → List (Σ String λ _ → Arg Type)\nf-tel n = downMap (λ _ → \"_\" , vArg unknown) n\n\nf-pats : Nat → List (Arg Pattern)\nf-pats n = downMap (λ x → vArg (var x)) n\n\nf-term : Nat → Term\nf-term n = var n []\n\ndefineFresh : Nat → Nat → TC QName\ndefineFresh #pats #term =\n freshName \"f\" >>= λ f →\n define (vArg f) (funDef f-type (clause (f-tel #pats) (f-pats #pats) (f-term #term) ∷ [])) >>= λ _ →\n returnTC f\n\nfreshFun : Nat → Nat → TC Bool\nfreshFun #pats #term =\n catchTC (defineFresh #pats #term >>= λ _ → returnTC true)\n (returnTC false)\n\n-- Check that the pattern list must be of length 0\n-- and the context features 1 available variable.\n\ndefine-Γ₀-0-0 : String → This: true\ndefine-Γ₀-0-0 s = this: evalT (freshFun 0 0)\n\ndefine-Γ₀-1-0 : String → This: false\ndefine-Γ₀-1-0 s = this: evalT (freshFun 1 0)\n\ndefine-Γ₀-1-1 : String → This: false\ndefine-Γ₀-1-1 s = this: evalT (freshFun 0 1)\n\nmodule _ (S : String) where\n define-Γ₁-0-0 : This: true\n define-Γ₁-0-0 = this: evalT (freshFun 0 0)\n\n define-Γ₁-0-1 : This: false\n define-Γ₁-0-1 = this: evalT (freshFun 0 1)\n\n define-Γ₁-1-0 : This: false\n define-Γ₁-1-0 = this: evalT (freshFun 1 0)\n\nf₀ : String → String\nf₀ s = runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])\n\nf₁ : String → String\nf₁ = λ s → runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])\n\nf₂ : String → String\nf₂ s = runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])\n where x = 0\n", "meta": {"hexsha": "c5d3f6d008b8d44e74c85ea6d1e2d8948635f273", "size": 2337, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1833.agda", "max_stars_repo_name": "KDr2/agda", "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-05T00:25:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:25:14.000Z", "max_issues_repo_path": "test/Succeed/Issue1833.agda", "max_issues_repo_name": "KDr2/agda", "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_forks_repo_path": "test/Succeed/Issue1833.agda", "max_forks_repo_name": "KDr2/agda", "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.402173913, "max_line_length": 101, "alphanum_fraction": 0.620453573, "num_tokens": 881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.661922862511608, "lm_q2_score": 0.600188359260205, "lm_q1q2_score": 0.39727839680766025}} {"text": "open import Categories\nopen import Functors\nopen import RMonads\n\nmodule RMonads.CatofRAdj {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}\n (M : RMonad J) where\n\nopen import Library\n\nopen import RAdjunctions\n\nopen Fun\nopen Cat\n\n\nrecord ObjAdj {e f} : Set ((a ⊔ b ⊔ c ⊔ d ⊔ lsuc e ⊔ lsuc f)) where\n open RMonad M\n field E : Cat {e}{f}\n adj : RAdj J E\n open RAdj adj\n field law : R ○ L ≅ TFun M\n ηlaw : ∀{X} → left (iden E {OMap L X}) ≅ η {X}\n bindlaw : ∀{X Y}{f : Hom D (OMap J X) (T Y)} → \n HMap R (right (subst (Hom D (OMap J X)) \n (fcong Y (cong OMap (sym law))) f)) \n ≅ bind f \nopen ObjAdj\n\nrecord HomAdj {e f}(A B : ObjAdj {e}{f}) : Set (a ⊔ b ⊔ c ⊔ d ⊔ lsuc (e ⊔ f))\n where\n constructor homadj\n open RAdj\n field K : Fun (E A) (E B)\n Llaw : K ○ L (adj A) ≅ L (adj B) \n Rlaw : R (adj A) ≅ R (adj B) ○ K\n rightlaw : {X : Obj C}{Y : Obj (E A)}\n {f : Hom D (OMap J X) (OMap (R (adj A)) Y)} → \n HMap K (right (adj A) {X}{Y} f) \n ≅ \n right (adj B)\n {X}\n {OMap K Y}\n (subst (Hom D (OMap J X)) \n (fcong Y (cong OMap Rlaw)) \n f)\n\nopen HomAdj\n\nHomAdjEq : ∀{a b}{A B : ObjAdj {a}{b}}\n (f g : HomAdj A B) → K f ≅ K g → f ≅ g\nHomAdjEq {A = A}{B} (homadj K _ _ _) (homadj .K _ _ _) refl =\n cong₃ (homadj K)\n (ir _ _)\n (ir _ _)\n (iext λ _ → iext λ _ → iext λ _ → hir refl)\n\nrightlawlem : ∀{e f}{E : Cat {e}{f}}(R : Fun E D)(L : Fun C E) → \n (p : OMap R ≅ OMap (R ○ (IdF E))) → \n (right : {X : Obj C} {Y : Obj E} → \n Hom D (OMap J X) (OMap R Y) → Hom E (OMap L X) Y) →\n {X : Obj C}{Y : Obj E}{f : Hom D (OMap J X) (OMap R Y)} →\n right f ≅ right (subst (Hom D (OMap J X)) (fcong Y p) f)\nrightlawlem R L refl right = refl\n\nidLlaw : ∀{e f}(X : ObjAdj {e}{f}) → \n IdF (E X) ○ RAdj.L (adj X) ≅ RAdj.L (adj X)\nidLlaw X = FunctorEq _ _ refl refl\n\nidRlaw : ∀{e f}(X : ObjAdj {e}{f}) → \n RAdj.R (adj X) ≅ RAdj.R (adj X) ○ IdF (E X)\nidRlaw X = FunctorEq _ _ refl refl\n\nidrightlaw : ∀{e f}\n (X : ObjAdj {e}{f}) → \n {X₁ : Obj C} {Y : Obj (E X)}\n {f : Hom D (OMap J X₁) (OMap (RAdj.R (adj X)) Y)} →\n HMap (IdF (E X)) (RAdj.right (adj X) f) \n ≅ \n RAdj.right (adj X) \n (subst (Hom D (OMap J X₁)) \n (fcong Y (cong OMap (idRlaw X))) \n f)\nidrightlaw X = \n rightlawlem (R (adj X)) \n (L (adj X)) \n (cong OMap\n (FunctorEq (R (adj X))\n (R (adj X) ○ IdF (E X))\n refl\n refl))\n (right (adj X)) \n where open RAdj\n\nidHomAdj : ∀{e f}{X : ObjAdj {e}{f}} → HomAdj X X\nidHomAdj {X = X} = record { \n K = IdF (E X); \n Llaw = idLlaw X; \n Rlaw = idRlaw X; \n rightlaw = idrightlaw X }\n\nHMaplem : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{X X' Y Y' : Obj C} → \n X ≅ X' → Y ≅ Y' → \n {f : Hom C X Y}{f' : Hom C X' Y'} → f ≅ f' → (F : Fun C D) → \n HMap F {X}{Y} f ≅ HMap F {X'}{Y'} f'\nHMaplem refl refl refl F = refl\n\nrightlawlem2 : ∀{e f g h i j}{E : Cat {e}{f}}{F : Cat {g}{h}}{G : Cat {i}{j}}\n (J : Fun C D)\n (RX : Fun E D)(LX : Fun C E)\n (RY : Fun F D)(LY : Fun C F)\n (RZ : Fun G D)(LZ : Fun C G)\n (KA : Fun E F)(KB : Fun F G) → \n (rightX : {X : Obj C}{Y : Obj E} → \n Hom D (OMap J X) (OMap RX Y) → Hom E (OMap LX X) Y)\n (rightY : {X : Obj C}{Y : Obj F} → \n Hom D (OMap J X) (OMap RY Y) → Hom F (OMap LY X) Y)\n (rightZ : {X : Obj C}{Y : Obj G} → \n Hom D (OMap J X) (OMap RZ Y) → Hom G (OMap LZ X) Y) → \n (p : RY ≅ RZ ○ KB)(q : RX ≅ RY ○ KA) →\n (p' : KA ○ LX ≅ LY) → \n (r : {X : Obj C}{Y : Obj F}{f : Hom D (OMap J X) (OMap RY Y)} →\n HMap KB (rightY f) \n ≅ \n rightZ (subst (Hom D (OMap J X)) \n (fcong Y (cong OMap p)) \n f)) →\n (s : {X : Obj C}{Y : Obj E}{f : Hom D (OMap J X) (OMap RX Y)} →\n HMap KA (rightX f) \n ≅ \n rightY (subst (Hom D (OMap J X)) \n (fcong Y (cong OMap q)) \n f)) →\n ∀{A B}(h : Hom D (OMap J A) (OMap RX B)) → \n HMap (KB ○ KA) (rightX h) ≅\n rightZ\n (subst (Hom D (OMap J A)) \n (fcong B (cong OMap (trans q (cong (λ F₁ → F₁ ○ KA) p)))) \n h)\nrightlawlem2 J .((RZ ○ KB) ○ KA) LX .(RZ ○ KB) .(KA ○ LX) RZ LZ KA KB \n rightX rightY rightZ refl refl refl r s h = trans (cong (HMap KB) s) r\n\ncompLlaw : ∀{e f}{X Y Z : ObjAdj {e}{f}} → \n (f : HomAdj Y Z)(g : HomAdj X Y) →\n (K f ○ K g) ○ RAdj.L (adj X) ≅ RAdj.L (adj Z)\ncompLlaw f g = FunctorEq \n _ \n _\n (ext (λ A → trans \n (cong (OMap (K f)) (cong (λ F → OMap F A) (Llaw g)))\n (cong (λ F → OMap F A) (Llaw f))))\n (iext λ A → iext λ B → ext λ h → trans \n (HMaplem \n (cong (λ F → OMap F A) (Llaw g)) \n (cong (λ F → OMap F B) (Llaw g)) \n (cong (λ F → HMap F h) (Llaw g)) \n (K f))\n (cong (λ F → HMap F h) (Llaw f)))\n\ncompRlaw : ∀{e f}{X Y Z : ObjAdj {e}{f}} → \n (f : HomAdj Y Z)(g : HomAdj X Y) →\n RAdj.R (adj X) ≅ RAdj.R (adj Z) ○ (K f ○ K g)\ncompRlaw f g = FunctorEq \n _ \n _\n (ext (λ A → trans \n (cong (λ F → OMap F A) (Rlaw g))\n (cong (λ F → OMap F (OMap (K g) A)) (Rlaw f))))\n (iext λ A → iext λ B → ext λ h → trans \n (cong (λ F → HMap F h) (Rlaw g))\n (cong (λ F → HMap F (HMap (K g) h)) (Rlaw f)))\n\ncomprightlaw : ∀{e f}{X Y Z : ObjAdj {e}{f}} → \n (f : HomAdj Y Z)(g : HomAdj X Y) →\n {A : Obj C} {B : Obj (E X)}\n {h : Hom D (OMap J A) (OMap (RAdj.R (adj X)) B)} →\n HMap (K f ○ K g) (RAdj.right (adj X) h) \n ≅\n RAdj.right (adj Z)\n (subst (Hom D (OMap J A)) \n (fcong B (cong OMap (compRlaw f g)))\n h)\ncomprightlaw {X = X}{Y}{Z} f g {A}{B}{h} = trans\n (rightlawlem2 J (R (adj X)) (L (adj X)) (R (adj Y)) (L (adj Y))\n (R (adj Z)) (L (adj Z)) (K g) (K f) (right (adj X)) (right (adj Y))\n (right (adj Z)) (Rlaw f) (Rlaw g) (Llaw g) (rightlaw f)\n (rightlaw g) h) (cong (right (adj Z)) (trans (stripsubst (Hom D (OMap J A)) h (fcong B (cong OMap (trans (Rlaw g) (cong (λ F → F ○ K g) (Rlaw f)))))) (sym (stripsubst (Hom D (OMap J A)) h (fcong B (cong OMap (compRlaw f g))))))) where open RAdj\n\ncompHomAdj : ∀{e f}{X Y Z : ObjAdj {e}{f}} → \n HomAdj Y Z → HomAdj X Y → HomAdj X Z\ncompHomAdj f g = record { \n K = K f ○ K g; \n Llaw = compLlaw f g;\n Rlaw = compRlaw f g; \n rightlaw = comprightlaw f g }\n\nidlHomAdj : ∀{e f}{X Y : ObjAdj {e}{f}}\n {f : HomAdj X Y} → compHomAdj idHomAdj f ≅ f\nidlHomAdj = HomAdjEq _ _ (FunctorEq _ _ refl refl)\n\nidrHomAdj : ∀{e f}{X Y : ObjAdj {e}{f}}\n {f : HomAdj X Y} → compHomAdj f idHomAdj ≅ f\nidrHomAdj = HomAdjEq _ _ (FunctorEq _ _ refl refl)\n\nassHomAdj : ∀{a b}{W X Y Z : ObjAdj {a}{b}}\n {f : HomAdj Y Z} {g : HomAdj X Y} {h : HomAdj W X} →\n compHomAdj (compHomAdj f g) h ≅ compHomAdj f (compHomAdj g h)\nassHomAdj = HomAdjEq _ _ (FunctorEq _ _ refl refl)\n\nCatofAdj : ∀{a b} → Cat\nCatofAdj {a}{b} = record{\n Obj = ObjAdj {a}{b};\n Hom = HomAdj;\n iden = idHomAdj;\n comp = compHomAdj;\n idl = idlHomAdj;\n idr = idrHomAdj;\n ass = λ{_ _ _ _ f g h} → \n assHomAdj {f = f}{g}{h}}\n\n", "meta": {"hexsha": "5bf2a7448adb57eed901b4b665ed52e931e0a917", "size": 7682, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "RMonads/CatofRAdj.agda", "max_stars_repo_name": "jmchapman/Relative-Monads", "max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z", "max_issues_repo_path": "RMonads/CatofRAdj.agda", "max_issues_repo_name": "jmchapman/Relative-Monads", "max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z", "max_forks_repo_path": "RMonads/CatofRAdj.agda", "max_forks_repo_name": "jmchapman/Relative-Monads", "max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z", "avg_line_length": 34.9181818182, "max_line_length": 247, "alphanum_fraction": 0.4455870867, "num_tokens": 3109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.4843800842769844, "lm_q1q2_score": 0.3971400074113113}} {"text": "\nmodule _ where\n\ndata Unit : Set where\n unit : Unit\n\nmodule M (_ : Unit) where\n\n record R₁ (A : Set) : Set₁ where\n no-eta-equality\n\n postulate\n x : A\n\n open R₁ ⦃ … ⦄ public\n\n record R₂ (A : Set) : Set₁ where\n field\n instance\n r₁ : R₁ A\n\n open R₂ ⦃ … ⦄\n\nopen M unit\n\npostulate\n A : Set\n\ninstance\n postulate\n m : R₁ A\n\na : A\na = x\n", "meta": {"hexsha": "b0aa14e1480ff0fa1daf821ba8fedd2bfa6ad89a", "size": 365, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue2008b.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue2008b.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue2008b.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 10.4285714286, "max_line_length": 34, "alphanum_fraction": 0.5534246575, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.5621765008857982, "lm_q1q2_score": 0.39677575732699666}} {"text": "{-\nThis second-order term syntax was created from the following second-order syntax description:\n\nsyntax Ring | R\n\ntype\n * : 0-ary\n\nterm\n zero : * | 𝟘\n add : * * -> * | _⊕_ l20\n one : * | 𝟙\n mult : * * -> * | _⊗_ l30\n neg : * -> * | ⊖_ r50\n\ntheory\n (𝟘U⊕ᴸ) a |> add (zero, a) = a\n (𝟘U⊕ᴿ) a |> add (a, zero) = a\n (⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c))\n (⊕C) a b |> add(a, b) = add(b, a)\n (𝟙U⊗ᴸ) a |> mult (one, a) = a\n (𝟙U⊗ᴿ) a |> mult (a, one) = a\n (⊗A) a b c |> mult (mult(a, b), c) = mult (a, mult(b, c))\n (⊗D⊕ᴸ) a b c |> mult (a, add (b, c)) = add (mult(a, b), mult(a, c))\n (⊗D⊕ᴿ) a b c |> mult (add (a, b), c) = add (mult(a, c), mult(b, c))\n (𝟘X⊗ᴸ) a |> mult (zero, a) = zero\n (𝟘X⊗ᴿ) a |> mult (a, zero) = zero\n (⊖N⊕ᴸ) a |> add (neg (a), a) = zero\n (⊖N⊕ᴿ) a |> add (a, neg (a)) = zero\n-}\n\n\nmodule Ring.Syntax where\n\nopen import SOAS.Common\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.Families.Core\nopen import SOAS.Construction.Structure\nopen import SOAS.ContextMaps.Inductive\n\nopen import SOAS.Metatheory.Syntax\n\nopen import Ring.Signature\n\nprivate\n variable\n Γ Δ Π : Ctx\n α : *T\n 𝔛 : Familyₛ\n\n-- Inductive term declaration\nmodule R:Terms (𝔛 : Familyₛ) where\n\n data R : Familyₛ where\n var : ℐ ⇾̣ R\n mvar : 𝔛 α Π → Sub R Π Γ → R α Γ\n\n 𝟘 : R * Γ\n _⊕_ : R * Γ → R * Γ → R * Γ\n 𝟙 : R * Γ\n _⊗_ : R * Γ → R * Γ → R * Γ\n ⊖_ : R * Γ → R * Γ\n\n infixl 20 _⊕_\n infixl 30 _⊗_\n infixr 50 ⊖_\n\n open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛\n\n Rᵃ : MetaAlg R\n Rᵃ = record\n { 𝑎𝑙𝑔 = λ where\n (zeroₒ ⋮ _) → 𝟘\n (addₒ ⋮ a , b) → _⊕_ a b\n (oneₒ ⋮ _) → 𝟙\n (multₒ ⋮ a , b) → _⊗_ a b\n (negₒ ⋮ a) → ⊖_ a\n ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }\n\n module Rᵃ = MetaAlg Rᵃ\n\n module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where\n\n open MetaAlg 𝒜ᵃ\n\n 𝕤𝕖𝕞 : R ⇾̣ 𝒜\n 𝕊 : Sub R Π Γ → Π ~[ 𝒜 ]↝ Γ\n 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t\n 𝕊 (t ◂ σ) (old v) = 𝕊 σ v\n 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)\n 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v\n\n 𝕤𝕖𝕞 𝟘 = 𝑎𝑙𝑔 (zeroₒ ⋮ tt)\n 𝕤𝕖𝕞 (_⊕_ a b) = 𝑎𝑙𝑔 (addₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 𝟙 = 𝑎𝑙𝑔 (oneₒ ⋮ tt)\n 𝕤𝕖𝕞 (_⊗_ a b) = 𝑎𝑙𝑔 (multₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 (⊖_ a) = 𝑎𝑙𝑔 (negₒ ⋮ 𝕤𝕖𝕞 a)\n\n 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Rᵃ 𝒜ᵃ 𝕤𝕖𝕞\n 𝕤𝕖𝕞ᵃ⇒ = record\n { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }\n ; ⟨𝑣𝑎𝑟⟩ = refl\n ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }\n where\n open ≡-Reasoning\n ⟨𝑎𝑙𝑔⟩ : (t : ⅀ R α Γ) → 𝕤𝕖𝕞 (Rᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)\n ⟨𝑎𝑙𝑔⟩ (zeroₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (addₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (oneₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (multₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (negₒ ⋮ _) = refl\n\n 𝕊-tab : (mε : Π ~[ R ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)\n 𝕊-tab mε new = refl\n 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v\n\n module _ (g : R ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Rᵃ 𝒜ᵃ g) where\n\n open MetaAlg⇒ gᵃ⇒\n\n 𝕤𝕖𝕞! : (t : R α Γ) → 𝕤𝕖𝕞 t ≡ g t\n 𝕊-ix : (mε : Sub R Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)\n 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x\n 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v\n 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))\n = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))\n 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩\n\n 𝕤𝕖𝕞! 𝟘 = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (_⊕_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! 𝟙 = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (_⊗_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (⊖_ a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n\n\n-- Syntax instance for the signature\nR:Syn : Syntax\nR:Syn = record\n { ⅀F = ⅀F\n ; ⅀:CS = ⅀:CompatStr\n ; mvarᵢ = R:Terms.mvar\n ; 𝕋:Init = λ 𝔛 → let open R:Terms 𝔛 in record\n { ⊥ = R ⋉ Rᵃ\n ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }\n ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }\n\n-- Instantiation of the syntax and metatheory\nopen Syntax R:Syn public\nopen R:Terms public\nopen import SOAS.Families.Build public\nopen import SOAS.Syntax.Shorthands Rᵃ public\nopen import SOAS.Metatheory R:Syn public\n", "meta": {"hexsha": "6bc95c421b5892229c3d00b214c0635a9056342d", "size": 4030, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "out/Ring/Syntax.agda", "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_issues_repo_path": "out/Ring/Syntax.agda", "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_forks_repo_path": "out/Ring/Syntax.agda", "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "avg_line_length": 26.1688311688, "max_line_length": 93, "alphanum_fraction": 0.4965260546, "num_tokens": 2662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239836484143, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.39668146885737743}} {"text": "module Luau.OpSem where\n\nopen import Agda.Builtin.Equality using (_≡_)\nopen import FFI.Data.Maybe using (just)\nopen import Luau.Heap using (Heap; _≡_⊕_↦_; lookup; function_⟨_⟩_end)\nopen import Luau.Substitution using (_[_/_]ᴮ)\nopen import Luau.Syntax using (Expr; Stat; Block; nil; addr; var; function⟨_⟩_end; _$_; block_is_end; local_←_; _∙_; done; function_⟨_⟩_end; return)\nopen import Luau.Value using (addr; val)\n\ndata _⊢_⟶ᴮ_⊣_ : Heap → Block → Block → Heap → Set\ndata _⊢_⟶ᴱ_⊣_ : Heap → Expr → Expr → Heap → Set\n\ndata _⊢_⟶ᴱ_⊣_ where\n\n nil : ∀ {H} →\n\n -------------------\n H ⊢ nil ⟶ᴱ nil ⊣ H\n\n function : ∀ {H H′ a x B} →\n\n H′ ≡ H ⊕ a ↦ (function \"anon\" ⟨ x ⟩ B end) →\n -------------------------------------------\n H ⊢ (function⟨ x ⟩ B end) ⟶ᴱ (addr a) ⊣ H′\n\n app : ∀ {H H′ M M′ N} →\n \n H ⊢ M ⟶ᴱ M′ ⊣ H′ →\n -----------------------------\n H ⊢ (M $ N) ⟶ᴱ (M′ $ N) ⊣ H′\n\n beta : ∀ {H M a f x B} →\n \n (lookup H a) ≡ just(function f ⟨ x ⟩ B end) →\n -----------------------------------------------------\n H ⊢ (addr a $ M) ⟶ᴱ (block f is local x ← M ∙ B end) ⊣ H\n\n block : ∀ {H H′ B B′ b} →\n \n H ⊢ B ⟶ᴮ B′ ⊣ H′ →\n ----------------------------------------------------\n H ⊢ (block b is B end) ⟶ᴱ (block b is B′ end) ⊣ H′\n\n return : ∀ {H V B b} →\n \n --------------------------------------------------------\n H ⊢ (block b is return (val V) ∙ B end) ⟶ᴱ (val V) ⊣ H\n\n done : ∀ {H b} →\n \n ---------------------------------\n H ⊢ (block b is done end) ⟶ᴱ nil ⊣ H\n \ndata _⊢_⟶ᴮ_⊣_ where\n\n local : ∀ {H H′ x M M′ B} →\n \n H ⊢ M ⟶ᴱ M′ ⊣ H′ →\n -------------------------------------------------\n H ⊢ (local x ← M ∙ B) ⟶ᴮ (local x ← M′ ∙ B) ⊣ H′\n\n subst : ∀ {H x v B} →\n \n -------------------------------------------------\n H ⊢ (local x ← val v ∙ B) ⟶ᴮ (B [ v / x ]ᴮ) ⊣ H\n\n function : ∀ {H H′ a f x B C} →\n \n H′ ≡ H ⊕ a ↦ (function f ⟨ x ⟩ C end) →\n --------------------------------------------------------------\n H ⊢ (function f ⟨ x ⟩ C end ∙ B) ⟶ᴮ (B [ addr a / f ]ᴮ) ⊣ H′\n\n return : ∀ {H H′ M M′ B} →\n \n H ⊢ M ⟶ᴱ M′ ⊣ H′ →\n --------------------------------------------\n H ⊢ (return M ∙ B) ⟶ᴮ (return M′ ∙ B) ⊣ H′\n\ndata _⊢_⟶*_⊣_ : Heap → Block → Block → Heap → Set where\n\n refl : ∀ {H B} →\n\n ----------------\n H ⊢ B ⟶* B ⊣ H\n \n step : ∀ {H H′ H″ B B′ B″} →\n H ⊢ B ⟶ᴮ B′ ⊣ H′ →\n H′ ⊢ B′ ⟶* B″ ⊣ H″ →\n ------------------\n H ⊢ B ⟶* B″ ⊣ H″\n\n\n", "meta": {"hexsha": "dcd474bf834f389f776539f848f3a78ff5a73950", "size": 2450, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "prototyping/Luau/OpSem.agda", "max_stars_repo_name": "FreakingBarbarians/luau", "max_stars_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-11T21:30:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T21:30:17.000Z", "max_issues_repo_path": "prototyping/Luau/OpSem.agda", "max_issues_repo_name": "FreakingBarbarians/luau", "max_issues_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f", "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/Luau/OpSem.agda", "max_forks_repo_name": "FreakingBarbarians/luau", "max_forks_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f", "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": 26.3440860215, "max_line_length": 148, "alphanum_fraction": 0.3587755102, "num_tokens": 1001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7577943822145998, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.396644999960752}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Basics\nopen import lib.NType2\nopen import lib.types.Sigma\n\nmodule lib.types.Modality where\n\n -- Where to put this? Or maybe there's\n -- a simpler proof from some library function?\n !ᵈ-inv-l-out : ∀ {ℓ} {A : Type ℓ} {P : A → Type ℓ}\n {a₀ a₁ : A} {p : a₀ == a₁} {x₀ x₁ : P a₁} \n → (q : x₀ == x₁ [ P ↓ ! p ∙ p ])\n → x₀ == x₁\n !ᵈ-inv-l-out {p = idp} q = q\n\n record Modality ℓ : Type (lsucc ℓ) where\n field\n\n is-local : Type ℓ → Type ℓ\n is-local-is-prop : {A : Type ℓ} → is-prop (is-local A)\n\n ◯ : Type ℓ → Type ℓ\n ◯-is-local : {A : Type ℓ} → is-local (◯ A)\n\n η : {A : Type ℓ} → A → ◯ A\n\n ◯-elim : {A : Type ℓ} {B : ◯ A → Type ℓ}\n (B-local : (x : ◯ A) → is-local (B x))\n → Π A (B ∘ η) → Π (◯ A) B\n\n ◯-elim-β : {A : Type ℓ} {B : ◯ A → Type ℓ}\n (B-local : (x : ◯ A) → is-local (B x)) (f : Π A (B ∘ η))\n → (a : A) → ◯-elim B-local f (η a) == f a\n\n ◯-=-is-local : {A : Type ℓ} (a₀ a₁ : ◯ A) → is-local (a₀ == a₁)\n\n ◯-Type : Type (lsucc ℓ)\n ◯-Type = Σ (Type ℓ) is-local\n\n {- elimination rules -}\n\n module ◯Elim {A : Type ℓ} {B : ◯ A → Type ℓ}\n (B-local : (x : ◯ A) → is-local (B x)) (η* : Π A (B ∘ η)) where\n\n f = ◯-elim B-local η*\n η-β = ◯-elim-β B-local η*\n\n module ◯Rec {A : Type ℓ} {B : Type ℓ}\n (B-local : is-local B) (η* : A → B)\n = ◯Elim (λ _ → B-local) η*\n ◯-rec = ◯Rec.f\n ◯-rec-β = ◯Rec.η-β\n\n {- functoriality -}\n\n module ◯Fmap {A B : Type ℓ} (f : A → B) =\n ◯Rec ◯-is-local (η ∘ f)\n ◯-fmap = ◯Fmap.f\n ◯-fmap-β = ◯Fmap.η-β\n\n ◯-isemap : {A B : Type ℓ} (f : A → B) → is-equiv f → is-equiv (◯-fmap f)\n ◯-isemap f f-ise = is-eq _ (◯-fmap g) to-from from-to where\n open is-equiv f-ise\n abstract\n to-from : ∀ ◯b → ◯-fmap f (◯-fmap g ◯b) == ◯b\n to-from = ◯-elim\n (λ ◯b → ◯-=-is-local (◯-fmap f (◯-fmap g ◯b)) ◯b)\n (λ b → ap (◯-fmap f) (◯-fmap-β g b) ∙ ◯-fmap-β f (g b) ∙ ap η (f-g b))\n from-to : ∀ ◯a → ◯-fmap g (◯-fmap f ◯a) == ◯a\n from-to = ◯-elim\n (λ ◯a → ◯-=-is-local (◯-fmap g (◯-fmap f ◯a)) ◯a)\n (λ a → ap (◯-fmap g) (◯-fmap-β f a) ∙ ◯-fmap-β g (f a) ∙ ap η (g-f a))\n\n ◯-emap : {A B : Type ℓ} → A ≃ B → ◯ A ≃ ◯ B\n ◯-emap (f , f-ise) = ◯-fmap f , ◯-isemap f f-ise\n\n {- equivalences preserve locality -}\n\n\n -- This is the only appearence of univalence, but ...\n local-is-replete : {A B : Type ℓ} → is-local A → A ≃ B → is-local B\n local-is-replete w eq = transport is-local (ua eq) w\n\n -- This name aligns with the current codebase better.\n equiv-preserves-local : {A B : Type ℓ} → A ≃ B → is-local A → is-local B\n equiv-preserves-local e A-is-loc = local-is-replete A-is-loc e\n\n {- locality and [η] being an equivalence -}\n\n local-implies-η-equiv : {A : Type ℓ} → is-local A → is-equiv (η {A})\n local-implies-η-equiv {A} w = is-eq (η {A}) η-inv inv-l inv-r\n\n where η-inv : ◯ A → A\n η-inv = ◯-rec w (idf A)\n\n abstract\n inv-r : (a : A) → η-inv (η a) == a\n inv-r = ◯-rec-β w (idf A)\n\n inv-l : (a : ◯ A) → η (η-inv a) == a\n inv-l = ◯-elim (λ a₀ → ◯-=-is-local _ _)\n (λ a₀ → ap η (inv-r a₀))\n\n abstract\n η-equiv-implies-local : {A : Type ℓ} → is-equiv (η {A}) → is-local A\n η-equiv-implies-local {A} eq = local-is-replete {◯ A} {A} ◯-is-local ((η , eq) ⁻¹)\n\n retract-is-local : {A B : Type ℓ} (w : is-local A)\n (f : A → B) (g : B → A) (r : (b : B) → f (g b) == b) →\n is-local B\n retract-is-local {A} {B} w f g r = η-equiv-implies-local (is-eq η η-inv inv-l inv-r)\n\n where η-inv : ◯ B → B\n η-inv = f ∘ (◯-rec w g)\n\n inv-r : (b : B) → η-inv (η b) == b\n inv-r b = ap f (◯-rec-β w g b) ∙ r b\n\n inv-l : (b : ◯ B) → η (η-inv b) == b\n inv-l = ◯-elim (λ b → ◯-=-is-local _ _) (λ b → ap η (inv-r b))\n\n {- locality of identification -}\n\n abstract\n =-preserves-local : {A : Type ℓ} → is-local A → {a₀ a₁ : A} → is-local (a₀ == a₁)\n =-preserves-local {A} w {a₀} {a₁} = local-is-replete\n (◯-=-is-local (η a₀) (η a₁)) (ap-equiv (η , local-implies-η-equiv w) a₀ a₁ ⁻¹)\n\n {- ◯-connectness and ◯-equivalences -}\n\n is-◯-connected : Type ℓ → Type ℓ\n is-◯-connected A = is-contr (◯ A)\n\n is-◯-connected-is-prop : ∀ {A} → is-prop (is-◯-connected A)\n is-◯-connected-is-prop {A} = is-contr-is-prop\n \n is-◯-equiv : {A B : Type ℓ} → (A → B) → Type ℓ\n is-◯-equiv {B = B} f = (b : B) → is-◯-connected (hfiber f b)\n\n has-◯-conn-fibers = is-◯-equiv\n\n is-lex : Type (lsucc ℓ)\n is-lex = {A B : Type ℓ} (f : A → B)\n → is-◯-connected A → is-◯-connected B → is-◯-equiv f\n\n equiv-preserves-◯-conn : {A B : Type ℓ} → A ≃ B → is-◯-connected A → is-◯-connected B\n equiv-preserves-◯-conn e c = equiv-preserves-level (◯-emap e) {{c}}\n\n total-◯-equiv : {A : Type ℓ} {P Q : A → Type ℓ} (φ : ∀ a → P a → Q a) → \n (∀ a → is-◯-equiv (φ a)) → is-◯-equiv (Σ-fmap-r φ)\n total-◯-equiv φ e (a , q) = equiv-preserves-◯-conn (hfiber-Σ-fmap-r φ q ⁻¹) (e a q)\n\n module _ {A B : Type ℓ} {h : A → B} (c : is-◯-equiv h) (P : B → ◯-Type) where\n abstract\n pre∘-◯-conn-is-equiv : is-equiv (λ (s : Π B (fst ∘ P)) → s ∘ h)\n pre∘-◯-conn-is-equiv = is-eq f g f-g g-f\n\n where f : Π B (fst ∘ P) → Π A (fst ∘ P ∘ h)\n f k a = k (h a)\n\n helper : Π A (fst ∘ P ∘ h) → (b : B) → ◯ (Σ A (λ a → h a == b)) → (fst (P b))\n helper t b = ◯-rec (snd (P b)) (λ x → transport (fst ∘ P) (snd x) (t (fst x)))\n\n helper-β : (t : Π A (fst ∘ P ∘ h)) → (b : B) → (r : hfiber h b) →\n helper t b (η r) == transport (fst ∘ P) (snd r) (t (fst r))\n helper-β t b = ◯-rec-β (snd (P b)) (λ x → transport (fst ∘ P) (snd x) (t (fst x)))\n\n g : Π A (fst ∘ P ∘ h) → Π B (fst ∘ P)\n g t b = helper t b (contr-center (c b))\n\n f-g : ∀ t → f (g t) == t\n f-g t = λ= $ λ a → transport\n (λ r → ◯-rec (snd (P (h a))) _ r == t a)\n (! (contr-path (c (h a)) (η (a , idp))))\n (◯-rec-β (snd (P (h a))) _ (a , idp))\n\n g-f : ∀ k → g (f k) == k\n g-f k = λ= λ (b : B) →\n ◯-elim {A = hfiber h b}\n (λ r → =-preserves-local (snd (P b)) {g (f k) b})\n (λ r → lemma₁ (fst r) b (snd r))\n (contr-center (c b))\n\n where lemma₀ : (a : A) → (b : B) → (p : h a == b) →\n helper (k ∘ h) b (η (a , p)) == k b\n lemma₀ a .(h a) idp = helper-β (k ∘ h) (h a) (a , idp)\n\n lemma₁ : (a : A) → (b : B) → (p : h a == b) →\n helper (k ∘ h) b (contr-center (c b)) == k b\n lemma₁ a b p = transport! (λ r → helper (k ∘ h) b r == k b)\n (contr-path (c b) (η (a , p))) (lemma₀ a b p)\n\n ◯-extend : Π A (fst ∘ P ∘ h) → Π B (fst ∘ P)\n ◯-extend = is-equiv.g pre∘-◯-conn-is-equiv\n\n ◯-extend-β : ∀ f a → ◯-extend f (h a) == f a\n ◯-extend-β f = app= (is-equiv.f-g pre∘-◯-conn-is-equiv f)\n\n {- locality of function types -}\n\n abstract\n Π-is-local : {A : Type ℓ} {B : A → Type ℓ} (w : (a : A) → is-local (B a)) → is-local (Π A B)\n Π-is-local {A} {B} w = retract-is-local {◯ (Π A B)} {Π A B} ◯-is-local η-inv η r\n\n where η-inv : ◯ (Π A B) → Π A B\n η-inv φ' a = ◯-rec (w a) (λ φ → φ a) φ'\n\n r : (φ : Π A B) → η-inv (η φ) == φ\n r φ = λ= (λ a → ◯-rec-β (w a) (λ φ₀ → φ₀ a) φ)\n\n →-is-local : {A B : Type ℓ} → is-local B → is-local (A → B)\n →-is-local w = Π-is-local (λ _ → w)\n\n -- Fmap2 because of locality of function types\n module ◯Fmap2 {A B C : Type ℓ} (η* : A → B → C) where\n private module M = ◯Rec (→-is-local ◯-is-local) (◯-fmap ∘ η*)\n f = M.f\n η-β : ∀ a b → f (η a) (η b) == η (η* a b)\n η-β a b = app= (M.η-β a) (η b) ∙ ◯-fmap-β (η* a) b\n ◯-fmap2 = ◯Fmap2.f\n ◯-fmap2-β = ◯Fmap2.η-β\n\n {- locality of sigma types -}\n\n abstract\n Σ-is-local : {A : Type ℓ} (B : A → Type ℓ)\n → is-local A → ((a : A) → is-local (B a))\n → is-local (Σ A B)\n Σ-is-local {A} B lA lB = retract-is-local {◯ (Σ A B)} {Σ A B} ◯-is-local η-inv η r\n\n where h : ◯ (Σ A B) → A\n h = ◯-rec lA fst\n\n h-β : (ab : Σ A B) → h (η ab) == fst ab\n h-β = ◯-rec-β lA fst\n\n k : (w : ◯ (Σ A B)) → B (h w)\n k = ◯-elim (lB ∘ h) λ ab → transport! B (h-β ab) (snd ab)\n\n k-β : (ab : Σ A B) → k (η ab) == snd ab [ B ↓ h-β ab ]\n k-β ab = from-transp! B (h-β ab) $\n ◯-elim-β (lB ∘ h) (λ ab → transport! B (h-β ab) (snd ab)) ab\n\n η-inv : ◯ (Σ A B) → Σ A B\n η-inv w = h w , k w\n\n r : (x : Σ A B) → η-inv (η x) == x\n r ab = pair= (h-β ab) (k-β ab)\n\n ×-is-local : {A B : Type ℓ}\n → is-local A → is-local B → is-local (A × B)\n ×-is-local {B = B} lA lB = Σ-is-local (λ _ → B) lA (λ _ → lB)\n\n ◯-×-econv : {A B : Type ℓ} → ◯ (A × B) ≃ ◯ A × ◯ B\n ◯-×-econv {A} {B} = equiv ◯-split ◯-pair inv-l inv-r\n\n where ◯-fst : ◯ (A × B) → ◯ A\n ◯-fst = ◯-fmap fst\n\n ◯-fst-β : (ab : A × B) → ◯-fst (η ab) == η (fst ab)\n ◯-fst-β = ◯-fmap-β fst\n\n ◯-snd : ◯ (A × B) → ◯ B\n ◯-snd = ◯-fmap snd\n\n ◯-snd-β : (ab : A × B) → ◯-snd (η ab) == η (snd ab)\n ◯-snd-β = ◯-fmap-β snd\n\n ◯-split : ◯ (A × B) → ◯ A × ◯ B\n ◯-split = fanout ◯-fst ◯-snd\n\n ◯-pair : ◯ A × ◯ B → ◯ (A × B)\n ◯-pair = uncurry (◯-fmap2 _,_)\n\n ◯-pair-β : (a : A) (b : B) → ◯-pair (η a , η b) == η (a , b)\n ◯-pair-β = ◯-fmap2-β _,_\n\n abstract\n inv-l : (ab : ◯ A × ◯ B) → ◯-split (◯-pair ab) == ab\n inv-l = uncurry $\n ◯-elim (λ _ → Π-is-local λ _ → =-preserves-local (×-is-local ◯-is-local ◯-is-local))\n (λ a → ◯-elim (λ _ → =-preserves-local (×-is-local ◯-is-local ◯-is-local))\n (λ b → ap ◯-split (◯-pair-β a b)\n ∙ pair×= (◯-fst-β (a , b)) (◯-snd-β (a , b))))\n\n inv-r : (ab : ◯ (A × B)) → ◯-pair (◯-split ab) == ab\n inv-r = ◯-elim (λ _ → ◯-=-is-local _ _)\n (λ ab → ap ◯-pair (pair×= (◯-fst-β ab) (◯-snd-β ab)) ∙ ◯-pair-β (fst ab) (snd ab))\n\n", "meta": {"hexsha": "c7b40b41c557889beedf15d31cfedae58d341107", "size": 10788, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/types/Modality.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "core/lib/types/Modality.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "core/lib/types/Modality.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 37.0721649485, "max_line_length": 111, "alphanum_fraction": 0.4124953652, "num_tokens": 4527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.6297745935070806, "lm_q1q2_score": 0.39661604737919576}} {"text": "-- 2017-05-11, Reported by Ulf\n-- Implicit absurd matches should be treated in the same way as explicit ones\n-- when it comes to being used/unused.\n\nopen import Agda.Builtin.Bool\nopen import Agda.Builtin.Equality\n\ndata ⊥ : Set where\nrecord ⊤ : Set where\n\nabort : (A : Set) {_ : ⊥} → A\nabort A {}\n\ntest : (x y : ⊥) → abort Bool {x} ≡ abort Bool {y}\ntest x y = refl\n", "meta": {"hexsha": "85858559f1b3966e4818fee4dee864e76d886548", "size": 364, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue2580.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/Issue2580.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/Issue2580.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": 22.75, "max_line_length": 77, "alphanum_fraction": 0.6703296703, "num_tokens": 116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6334102636778403, "lm_q2_score": 0.6261241702517975, "lm_q1q2_score": 0.39659347577425996}} {"text": "open import Categories\nopen import Functors\nopen import RMonads\n\nmodule RMonads.REM {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}\n (M : RMonad J) where\nopen import Library\nopen RMonad M\nopen Fun\n\nrecord RAlg : Set (a ⊔ c ⊔ d) where\n constructor ralg\n open Cat D\n field acar : Obj\n astr : ∀ {Z} → Hom (OMap J Z) acar → Hom (T Z) acar\n alaw1 : ∀ {Z}{f : Hom (OMap J Z) acar} →\n f ≅ comp (astr f) η\n alaw2 : ∀{Z}{W}{k : Hom (OMap J Z) (T W)}\n {f : Hom (OMap J W) acar} →\n astr (comp (astr f) k) ≅ comp (astr f) (bind k)\n\nAlgEq : {X Y : RAlg} → RAlg.acar X ≅ RAlg.acar Y → \n ((λ {Z} → RAlg.astr X {Z}) ≅ (λ {Z} → RAlg.astr Y {Z})) → \n X ≅ Y\nAlgEq {ralg acar astr _ _}{ralg .acar .astr _ _} refl refl = let open Cat in\n cong₂ (ralg acar astr)\n (iext λ _ → iext λ _ → ir _ _)\n (iext λ _ → iext λ _ → iext λ _ → iext λ _ → ir _ _)\n\nastrnat : ∀(alg : RAlg){X Y}\n (f : Cat.Hom C X Y) → \n (g : Cat.Hom D (OMap J X) (RAlg.acar alg))\n (g' : Cat.Hom D (OMap J Y) (RAlg.acar alg)) →\n Cat.comp D g' (HMap J f) ≅ g → \n Cat.comp D (RAlg.astr alg g') \n (RMonad.bind M (Cat.comp D (RMonad.η M) (HMap J f))) \n ≅ \n RAlg.astr alg g\nastrnat alg f g g' p = let \n open RAlg alg; open Cat D in\n proof\n comp (astr g') (bind (comp η (HMap J f))) \n ≅⟨ sym alaw2 ⟩\n astr (comp (astr g') (comp η (HMap J f)))\n ≅⟨ cong astr (sym ass) ⟩\n astr (comp (comp (astr g') η) (HMap J f))\n ≅⟨ cong (λ g₁ → astr (comp g₁ (HMap J f))) (sym alaw1) ⟩ \n astr (comp g' (HMap J f))\n ≅⟨ cong astr p ⟩\n astr g ∎\n\n\nrecord RAlgMorph (A B : RAlg) : Set (a ⊔ c ⊔ d) \n where\n constructor ralgmorph\n open Cat D\n open RAlg\n field amor : Hom (acar A) (acar B)\n ahom : ∀{Z}{f : Hom (OMap J Z) (acar A)} → \n comp amor (astr A f) ≅ astr B (comp amor f)\nopen RAlgMorph\n\nRAlgMorphEq : ∀{X Y : RAlg}{f g : RAlgMorph X Y} → amor f ≅ amor g → f ≅ g\nRAlgMorphEq {X}{Y}{ralgmorph amor _}{ralgmorph .amor _} refl =\n cong (ralgmorph amor) (iext λ _ → iext λ _ → ir _ _)\n\nlemZ : ∀{X X' Y Y' : RAlg}\n {f : RAlgMorph X Y}{g : RAlgMorph X' Y'} → X ≅ X' → Y ≅ Y' → \n amor f ≅ amor g → f ≅ g\nlemZ refl refl = RAlgMorphEq\n\nIdMorph : ∀{A : RAlg} → RAlgMorph A A\nIdMorph {A} = let open Cat D; open RAlg A in record {\n amor = iden;\n ahom = λ {_ f} → \n proof \n comp iden (astr f)\n ≅⟨ idl ⟩ \n astr f\n ≅⟨ cong astr (sym idl) ⟩ \n astr (comp iden f) \n ∎}\n\nCompMorph : ∀{X Y Z : RAlg} → \n RAlgMorph Y Z → RAlgMorph X Y → RAlgMorph X Z\nCompMorph {X}{Y}{Z} f g = let open Cat D; open RAlg in record {\n amor = comp (amor f) (amor g);\n ahom = λ {_ f'} → \n proof\n comp (comp (amor f) (amor g)) (astr X f') \n ≅⟨ ass ⟩\n comp (amor f) (comp (amor g) (astr X f'))\n ≅⟨ cong (comp (amor f)) (ahom g) ⟩\n comp (amor f) (astr Y (comp (amor g) f'))\n ≅⟨ ahom f ⟩\n astr Z (comp (amor f) (comp (amor g) f'))\n ≅⟨ cong (astr Z) (sym ass) ⟩\n astr Z (comp (comp (amor f) (amor g)) f') \n ∎}\n\nidlMorph : {X Y : RAlg}{f : RAlgMorph X Y} →\n CompMorph IdMorph f ≅ f\nidlMorph = RAlgMorphEq (Cat.idl D)\n\nidrMorph : ∀{X Y : RAlg}{f : RAlgMorph X Y} →\n CompMorph f IdMorph ≅ f\nidrMorph = RAlgMorphEq (Cat.idr D) \n\nassMorph : ∀{W X Y Z : RAlg}\n {f : RAlgMorph Y Z}{g : RAlgMorph X Y}{h : RAlgMorph W X} →\n CompMorph (CompMorph f g) h ≅ CompMorph f (CompMorph g h)\nassMorph = RAlgMorphEq (Cat.ass D)\n\nEM : Cat\nEM = record{\n Obj = RAlg;\n Hom = RAlgMorph;\n iden = IdMorph;\n comp = CompMorph;\n idl = idlMorph;\n idr = idrMorph;\n ass = λ{_ _ _ _ f g h} → assMorph {f = f}{g}{h}}\n\n", "meta": {"hexsha": "116a9d74eb27a9da5b8db966536e91480a937f3d", "size": 3736, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "RMonads/REM.agda", "max_stars_repo_name": "jmchapman/Relative-Monads", "max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z", "max_issues_repo_path": "RMonads/REM.agda", "max_issues_repo_name": "jmchapman/Relative-Monads", "max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z", "max_forks_repo_path": "RMonads/REM.agda", "max_forks_repo_name": "jmchapman/Relative-Monads", "max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z", "avg_line_length": 30.1290322581, "max_line_length": 76, "alphanum_fraction": 0.5230192719, "num_tokens": 1570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7520125737597974, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.39654865593273664}} {"text": "{-# OPTIONS --cubical --safe #-}\n\nopen import Cubical.Core.Everything\nopen import Cubical.Foundations.Everything\nopen import Agda.Primitive using (lzero)\n\nmodule Cubical.Data.DescendingList.Strict.Properties\n (A : Type₀)\n (_>_ : A → A → Type₀)\n where\n\nopen import Cubical.Data.DescendingList.Strict A _>_\nopen import Cubical.HITs.ListedFiniteSet renaming (_∈_ to _∈ʰ_)\n\nimport Cubical.Data.Empty as Empty\nopen Empty using (⊥-elim)\nopen import Cubical.Relation.Nullary.DecidableEq\n\nopen import Cubical.Relation.Nullary using (Dec; Discrete) renaming (¬_ to Type¬_)\n\nunsort : SDL → LFSet A\nunsort [] = []\nunsort (cons x xs x>xs) = x ∷ unsort xs\n\nmodule _ where\n open import Cubical.Relation.Nullary\n data Tri (A B C : Set) : Set where\n tri-< : A → ¬ B → ¬ C → Tri A B C\n tri-≡ : ¬ A → B → ¬ C → Tri A B C\n tri-> : ¬ A → ¬ B → C → Tri A B C\n\nmodule IsoToLFSet\n (A-discrete : Discrete A)\n (>-isProp : ∀ {x y} → isProp (x > y))\n (tri : ∀ x y → Tri (y > x) (x ≡ y) (x > y))\n (>-trans : ∀ {x y z} → x > y → y > z → x > z)\n (>-irreflexive : ∀ {x} → Type¬ x > x)\n where\n\n Tri' : A → A → Set\n Tri' x y = Tri (y > x) (x ≡ y) (x > y)\n\n open import Cubical.Foundations.Logic\n open import Cubical.HITs.PropositionalTruncation\n\n -- Membership is defined via `LFSet`.\n -- This computes just as well as a direct inductive definition,\n -- and additionally lets us use the extra `comm` and `dup` paths to prove\n -- things about membership.\n _∈ˡ_ : A → SDL → hProp lzero\n a ∈ˡ l = a ∈ʰ unsort l\n\n Memˡ : SDL → A → hProp lzero\n Memˡ l a = a ∈ˡ l\n\n Memʰ : LFSet A → A → hProp lzero\n Memʰ l a = a ∈ʰ l\n\n >ᴴ-trans : ∀ x y zs → x > y → y >ᴴ zs → x >ᴴ zs\n >ᴴ-trans x y [] x>y y>zs = >ᴴ[]\n >ᴴ-trans x y (cons z zs _) x>y (>ᴴcons y>z) = >ᴴcons (>-trans x>y y>z)\n\n ≡ₚ-sym : ∀ {A : Set} {x y : A} → [ x ≡ₚ y ] → [ y ≡ₚ x ]\n ≡ₚ-sym p = recPropTrunc squash (λ p → ∣ sym p ∣) p\n\n >-all : ∀ x l → x >ᴴ l → ∀ a → [ a ∈ˡ l ] → x > a\n >-all x (cons y zs y>zs) (>ᴴcons x>y) a a∈l =\n ⊔-elim (a ≡ₚ y) (a ∈ˡ zs) (λ _ → (x > a) , >-isProp {x} {a})\n (λ a≡ₚy → substₚ (λ q → x > q , >-isProp) (≡ₚ-sym a≡ₚy) x>y)\n (λ a∈zs → >-all x zs (>ᴴ-trans x y zs x>y y>zs) a a∈zs)\n a∈l\n\n >-absent : ∀ x l → x >ᴴ l → [ ¬ (x ∈ˡ l) ]\n >-absent x l x>l x∈l = ⊥-elim (>-irreflexive (>-all x l x>l x x∈l))\n\n >ᴴ-isProp : ∀ x xs → isProp (x >ᴴ xs)\n >ᴴ-isProp x _ >ᴴ[] >ᴴ[] = refl\n >ᴴ-isProp x _ (>ᴴcons p) (>ᴴcons q) = cong >ᴴcons (>-isProp p q)\n\n SDL-isSet : isSet SDL\n SDL-isSet = isSetDL.isSetDL A _>_ >-isProp A-discrete where\n open import Cubical.Data.DescendingList.Properties\n\n insert : A → SDL → SDL\n >ᴴinsert : {x y : A} {u : SDL} → y >ᴴ u → (y > x) → y >ᴴ insert x u\n insert x [] = cons x [] >ᴴ[]\n insert x (cons y zs good) with tri x y\n insert x (cons y zs good) | tri-< xᴴinsert good x _ _ x>y = cons x (cons y zs good) (>ᴴcons x>y)\n >ᴴinsert >ᴴ[] y>x = >ᴴcons y>x\n >ᴴinsert {x} (>ᴴcons {y} y>ys) y>x with tri x y\n >ᴴinsert {x} {y} (>ᴴcons {z} z>zs) y>x | tri-< _ _ e = >ᴴcons z>zs\n >ᴴinsert {x} (>ᴴcons {y} y>ys) y>x | tri-≡ _ _ e = >ᴴcons y>ys\n >ᴴinsert {x} (>ᴴcons {y} y>ys) y>x | tri-> _ _ _ = >ᴴcons y>x\n\n insert-correct : ∀ x ys → unsort (insert x ys) ≡ (x ∷ unsort ys)\n insert-correct x [] = refl\n insert-correct x (cons y zs y>zs) with tri x y\n ... | tri-< _ _ _ =\n y ∷ unsort (insert x zs) ≡⟨ (λ i → y ∷ (insert-correct x zs i)) ⟩\n y ∷ x ∷ unsort zs ≡⟨ comm _ _ _ ⟩\n x ∷ y ∷ unsort zs ∎\n ... | tri-≡ _ x≡y _ = sym (dup y (unsort zs)) ∙ (λ i → (x≡y (~ i)) ∷ y ∷ unsort zs)\n ... | tri-> _ _ _ = refl\n\n insert-correct₂ : ∀ x y zs → unsort (insert x (insert y zs)) ≡ (x ∷ y ∷ unsort zs)\n insert-correct₂ x y zs =\n insert-correct x (insert y zs)\n ∙ cong (λ q → x ∷ q) (insert-correct y zs)\n\n abstract\n -- for some reason, making [exclude] non-abstract makes\n -- typechecking noticeably slower\n exclude : A → (A → hProp lzero) → (A → hProp lzero)\n exclude x h a = ¬ a ≡ₚ x ⊓ h a\n\n >-excluded : ∀ x xs → x >ᴴ xs → exclude x (Memʰ (x ∷ unsort xs)) ≡ Memˡ xs\n >-excluded x xs x>xs = funExt (λ a → ⇔toPath (to a) (from a)) where\n\n import Cubical.Data.Prod as D\n import Cubical.Data.Sum as D\n\n from : ∀ a → [ a ∈ˡ xs ] → [ ¬ a ≡ₚ x ⊓ (a ≡ₚ x ⊔ a ∈ˡ xs) ]\n from a a∈xs = (recPropTrunc (snd ⊥) a≢x) D., inr a∈xs where\n a≢x : Type¬ (a ≡ x)\n a≢x = λ a≡x → (>-absent x xs x>xs (transport (λ i → [ a≡x i ∈ˡ xs ]) a∈xs ))\n\n to : ∀ a → [ ¬ a ≡ₚ x ⊓ (a ≡ₚ x ⊔ a ∈ˡ xs) ] → [ a ∈ˡ xs ]\n to a (a≢x D., x) = recPropTrunc (snd (a ∈ˡ xs)) (λ {\n (D.inl a≡x) → ⊥-elim (a≢x a≡x);\n (D.inr x) → x }) x\n\n cons-eq : ∀ x xs x>xs y ys y>ys → x ≡ y → xs ≡ ys → cons x xs x>xs ≡ cons y ys y>ys\n cons-eq x xs x>xs y ys y>ys x≡y xs≡ys i = cons (x≡y i) (xs≡ys i)\n (>ᴴ-isProp (x≡y i) (xs≡ys i)\n (transp (λ j → (x≡y (i ∧ j)) >ᴴ (xs≡ys) (i ∧ j)) (~ i) x>xs)\n (transp (λ j → (x≡y (i ∨ ~ j)) >ᴴ (xs≡ys) (i ∨ ~ j)) i y>ys)\n i)\n\n Memˡ-inj-cons : ∀ x xs x>xs y ys y>ys → x ≡ y → Memˡ (cons x xs x>xs) ≡ Memˡ (cons y ys y>ys) → Memˡ xs ≡ Memˡ ys\n Memˡ-inj-cons x xs x>xs y ys y>ys x≡y e =\n Memˡ xs ≡⟨\n sym (>-excluded x xs x>xs)\n ⟩ exclude x (Memʰ (x ∷ unsort xs)) ≡⟨\n (λ i → exclude (x≡y i) (e i))\n ⟩ exclude y (Memʰ (y ∷ unsort ys)) ≡⟨\n (>-excluded y ys y>ys)\n ⟩ Memˡ ys ∎\n\n Memˡ-inj : ∀ l₁ l₂ → Memˡ l₁ ≡ Memˡ l₂ → l₁ ≡ l₂\n Memˡ-inj [] [] eq = refl\n Memˡ-inj [] (cons y ys y>ys) eq = ⊥-elim (transport (λ i → [ eq (~ i) y ]) (inl ∣ refl ∣))\n Memˡ-inj (cons y ys y>ys) [] eq = ⊥-elim (transport (λ i → [ eq i y ]) (inl ∣ refl ∣))\n Memˡ-inj (cons x xs x>xs) (cons y ys y>ys) e =\n ⊔-elim (x ≡ₚ y) (x ∈ʰ unsort ys)\n (λ _ → ((cons x xs x>xs) ≡ (cons y ys y>ys)) , SDL-isSet _ _)\n (recPropTrunc (SDL-isSet _ _) with-x≡y)\n (⊥-elim ∘ x∉ys)\n (transport (λ i → [ e i x ]) (inl ∣ refl ∣)) where\n\n xxs = cons x xs x>xs\n\n x∉ys : [ ¬ x ∈ˡ ys ]\n x∉ys x∈ys = ⊥-elim (>-irreflexive y>y) where\n y>x : y > x\n y>x = (>-all y ys y>ys x x∈ys)\n\n y∈xxs : [ y ∈ˡ (cons x xs x>xs) ]\n y∈xxs = (transport (λ i → [ e (~ i) y ]) (inl ∣ refl ∣))\n\n y>y : y > y\n y>y = >-all y xxs (>ᴴcons y>x) y y∈xxs\n\n with-x≡y : x ≡ y → (cons x xs x>xs) ≡ (cons y ys y>ys)\n with-x≡y x≡y = cons-eq x xs x>xs y ys y>ys x≡y r where\n\n r : xs ≡ ys\n r = Memˡ-inj _ _ (Memˡ-inj-cons x xs x>xs y ys y>ys x≡y e)\n\n unsort-inj : ∀ x y → unsort x ≡ unsort y → x ≡ y\n unsort-inj x y e = Memˡ-inj x y λ i a → a ∈ʰ (e i)\n\n insert-swap : (x y : A) (zs : SDL) → insert x (insert y zs) ≡ insert y (insert x zs)\n insert-swap x y zs =\n unsort-inj (insert x (insert y zs)) (insert y (insert x zs))\n (unsort (insert x (insert y zs))\n ≡⟨ (λ i → insert-correct₂ x y zs i) ⟩\n x ∷ y ∷ unsort zs\n ≡⟨ (λ i → comm x y (unsort zs) i) ⟩\n y ∷ x ∷ unsort zs\n ≡⟨ (λ i → insert-correct₂ y x zs (~ i)) ⟩\n unsort (insert y (insert x zs)) ∎)\n\n insert-dup : (x : A) (ys : SDL) → insert x (insert x ys) ≡ insert x ys\n insert-dup x ys = unsort-inj (insert x (insert x ys)) (insert x ys)\n (\n unsort (insert x (insert x ys))\n ≡⟨ (λ i → insert-correct₂ x x ys i) ⟩\n x ∷ x ∷ unsort ys\n ≡⟨ dup x (unsort ys) ⟩\n x ∷ unsort ys\n ≡⟨ (λ i → insert-correct x ys (~ i)) ⟩\n unsort (insert x ys) ∎\n )\n\n sort : LFSet A → SDL\n sort = LFSetRec.f [] insert insert-swap insert-dup SDL-isSet\n\n unsort∘sort : ∀ x → unsort (sort x) ≡ x\n unsort∘sort =\n LFPropElim.f (λ x → unsort (sort x) ≡ x)\n refl\n (λ x {ys} ys-hyp → insert-correct x (sort ys) ∙ cong (λ q → x ∷ q) ys-hyp)\n (λ xs → trunc (unsort (sort xs)) xs)\n\n sort∘unsort : ∀ x → sort (unsort x) ≡ x\n sort∘unsort x = unsort-inj (sort (unsort x)) x (unsort∘sort (unsort x))\n\n SDL-LFSet-iso : Iso SDL (LFSet A)\n SDL-LFSet-iso = (iso unsort sort unsort∘sort sort∘unsort)\n\n SDL≡LFSet : SDL ≡ LFSet A\n SDL≡LFSet = ua (isoToEquiv SDL-LFSet-iso)\n", "meta": {"hexsha": "14a11f2496af691122eeac5c57b0300abe89b3d3", "size": 8134, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Data/DescendingList/Strict/Properties.agda", "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": "Cubical/Data/DescendingList/Strict/Properties.agda", "max_issues_repo_name": "limemloh/cubical", "max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": "Cubical/Data/DescendingList/Strict/Properties.agda", "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": 36.1511111111, "max_line_length": 115, "alphanum_fraction": 0.5263093189, "num_tokens": 3620, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6370307944803831, "lm_q2_score": 0.6224593312018546, "lm_q1q2_score": 0.39652576228724534}} {"text": "module RMonads.RMonadMorphs where\n\nopen import Library\nopen import Functors\nopen import Categories\nopen import RMonads\n\nopen Fun\nopen RMonad\n\nrecord RMonadMorph {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}\n (M M' : RMonad J) : Set (a ⊔ b ⊔ c ⊔ d) where\n constructor rmonadmorph\n open Cat D\n field morph : ∀ {X} → Hom (T M X) (T M' X)\n lawη : ∀ {X} → comp morph (η M {X}) ≅ η M' {X}\n lawbind : ∀ {X Y}{k : Hom (OMap J X) (T M Y)} → \n comp (morph {Y}) (bind M k) \n ≅ \n comp (bind M' (comp (morph {Y}) k)) (morph {X})\n\n\nRMonadMorphEq : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}\n {M M' : RMonad J}(α α' : RMonadMorph M M') ->\n (λ {X} -> RMonadMorph.morph α {X}) ≅ (λ {X} -> RMonadMorph.morph α' {X}) →\n α ≅ α'\nRMonadMorphEq (rmonadmorph m lη lbind) (rmonadmorph .m lη' lbind') refl =\n cong₂ (rmonadmorph m)\n (iext λ _ → hir refl)\n (iext λ _ → iext λ _ → iext λ _ → hir refl)\n\nIdRMonadMorph : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}\n (M : RMonad J) → RMonadMorph M M\nIdRMonadMorph {D = D} M = rmonadmorph\n iden\n idl\n (trans idl (trans (cong (bind M) (sym idl)) (sym idr)))\n where open Cat D\n\nCompRMonadMorph : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}\n {M M' M'' : RMonad J} →\n RMonadMorph M' M'' → RMonadMorph M M' → RMonadMorph M M''\nCompRMonadMorph {D = D}{M'' = M''}\n (rmonadmorph f lawηf lawbindf)\n (rmonadmorph g lawηg lawbindg) =\n rmonadmorph\n (comp f g)\n (trans ass (trans (cong (comp f) lawηg) lawηf))\n \\ {_ _ k} -> trans\n ass\n (trans (cong (comp f) lawbindg)\n (trans (trans (sym ass)\n (cong (λ f → comp f g)\n (trans (lawbindf {k = comp g k})\n (cong (λ g → comp (bind M'' g) f)\n (sym ass)))))\n ass))\n where open Cat D\n\nidr : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}{M M' : RMonad J}\n (f : RMonadMorph M M') → CompRMonadMorph f (IdRMonadMorph _) ≅ f\nidr {D = D} f = RMonadMorphEq _ _ (iext λ _ → Cat.idr D)\n\nidl : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}{M M' : RMonad J}\n (f : RMonadMorph M M') → CompRMonadMorph (IdRMonadMorph _) f ≅ f\nidl {D = D} f = RMonadMorphEq _ _ (iext λ _ → Cat.idl D)\n\nass : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}\n {J : Fun C D}{M M' M'' M''' : RMonad J}\n (f : RMonadMorph M'' M''')(g : RMonadMorph M' M'')(h : RMonadMorph M M') →\n CompRMonadMorph (CompRMonadMorph f g) h\n ≅\n CompRMonadMorph f (CompRMonadMorph g h)\nass {D = D} f g h = RMonadMorphEq _ _ (iext λ _ → Cat.ass D)\n\n", "meta": {"hexsha": "e0a25a0d555a4ac27025270e905f8fb415eb27d6", "size": 2721, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "RMonads/RMonadMorphs.agda", "max_stars_repo_name": "jmchapman/Relative-Monads", "max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z", "max_issues_repo_path": "RMonads/RMonadMorphs.agda", "max_issues_repo_name": "jmchapman/Relative-Monads", "max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z", "max_forks_repo_path": "RMonads/RMonadMorphs.agda", "max_forks_repo_name": "jmchapman/Relative-Monads", "max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z", "avg_line_length": 35.8026315789, "max_line_length": 78, "alphanum_fraction": 0.5112091143, "num_tokens": 1094, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.3965226005775443}} {"text": "\nmodule Tactic.Reflection.Substitute where\n\nopen import Prelude hiding (abs)\nopen import Builtin.Reflection\nopen import Tactic.Reflection.DeBruijn\n\npatternArgsVars : List (Arg Pattern) → Nat\n\npatternVars : Pattern → Nat\npatternVars (con _ ps) = patternArgsVars ps\npatternVars dot = 1\npatternVars (var _) = 1\npatternVars (lit x) = 0\npatternVars (proj _) = 0\npatternVars absurd = 0\n\npatternArgsVars [] = 0\npatternArgsVars (arg _ p ∷ ps) = patternVars p + patternArgsVars ps\n\nIsSafe : Term → Set\nIsSafe (lam _ _) = ⊥\nIsSafe _ = ⊤\n\ndata SafeTerm : Set where\n safe : (v : Term) (p : IsSafe v) → SafeTerm\n\nmaybeSafe : Term → Maybe SafeTerm\nmaybeSafe (var x args) = just (safe (var x args) _)\nmaybeSafe (con c args) = just (safe (con c args) _)\nmaybeSafe (def f args) = just (safe (def f args) _)\nmaybeSafe (meta x args) = just (safe (meta x args) _)\nmaybeSafe (lam v t) = nothing\nmaybeSafe (pat-lam cs args) = just (safe (pat-lam cs args) _)\nmaybeSafe (pi a b) = just (safe (pi a b) _)\nmaybeSafe (agda-sort s) = just (safe (agda-sort s) _)\nmaybeSafe (lit l) = just (safe (lit l) _)\nmaybeSafe unknown = just (safe unknown _)\n\ninstance\n DeBruijnSafeTerm : DeBruijn SafeTerm\n strengthenFrom {{DeBruijnSafeTerm}} k n (safe v _) = do\n -- Strengthening or weakening safe terms always results in safe terms,\n -- but proving that is a bit of a bother, thus maybeSafe.\n v₁ ← strengthenFrom k n v\n maybeSafe v₁\n weakenFrom {{DeBruijnSafeTerm}} k n (safe v p) =\n maybe (safe unknown _) id (maybeSafe (weakenFrom k n v))\n\nsafe-term : SafeTerm → Term\nsafe-term (safe v _) = v\n\napplyTerm : SafeTerm → List (Arg Term) → Term\napplyTerm v [] = safe-term v\napplyTerm (safe (var x args) _) args₁ = var x (args ++ args₁)\napplyTerm (safe (con c args) _) args₁ = con c (args ++ args₁)\napplyTerm (safe (def f args) _) args₁ = def f (args ++ args₁)\napplyTerm (safe (meta x args) _) args₁ = meta x (args ++ args₁)\napplyTerm (safe (lam v t) ()) args\napplyTerm (safe (pat-lam cs args) _) args₁ = pat-lam cs (args ++ args₁)\napplyTerm (safe (pi a b) _) _ = pi a b\napplyTerm (safe (agda-sort s) _) _ = agda-sort s\napplyTerm (safe (lit l) _) _ = lit l\napplyTerm (safe unknown _) _ = unknown\n\nSubst : Set → Set\nSubst A = List SafeTerm → A → A\n\nsubstTerm : Subst Term\nsubstArgs : Subst (List (Arg Term))\nsubstArg : Subst (Arg Term)\nsubstAbs : Subst (Abs Term)\nsubstSort : Subst Sort\nsubstClauses : Subst (List Clause)\nsubstClause : Subst Clause\n\nsubstTerm σ (var x args) =\n case index σ x of λ\n { nothing → var (x - length σ) (substArgs σ args)\n ; (just v) → applyTerm v (substArgs σ args) }\nsubstTerm σ (con c args) = con c (substArgs σ args)\nsubstTerm σ (def f args) = def f (substArgs σ args)\nsubstTerm σ (meta x args) = meta x (substArgs σ args)\nsubstTerm σ (lam v b) = lam v (substAbs σ b)\nsubstTerm σ (pat-lam cs args) = pat-lam (substClauses σ cs) (substArgs σ args)\nsubstTerm σ (pi a b) = pi (substArg σ a) (substAbs σ b)\nsubstTerm σ (agda-sort s) = agda-sort (substSort σ s)\nsubstTerm σ (lit l) = lit l\nsubstTerm σ unknown = unknown\n\nsubstSort σ (set t) = set (substTerm σ t)\nsubstSort σ (lit n) = lit n\nsubstSort σ unknown = unknown\n\nsubstClauses σ [] = []\nsubstClauses σ (c ∷ cs) = substClause σ c ∷ substClauses σ cs\n\nsubstClause σ (clause ps b) =\n case patternArgsVars ps of λ\n { zero → clause ps (substTerm σ b)\n ; (suc n) → clause ps (substTerm (reverse (map (λ i → safe (var i []) _) (from 0 to n)) ++ weaken (suc n) σ) b)\n }\nsubstClause σ (absurd-clause ps) = absurd-clause ps\n\nsubstArgs σ [] = []\nsubstArgs σ (x ∷ args) = substArg σ x ∷ substArgs σ args\nsubstArg σ (arg i x) = arg i (substTerm σ x)\nsubstAbs σ (abs x v) = abs x $ substTerm (safe (var 0 []) _ ∷ weaken 1 σ) v\n\nprivate\n toArgs : Nat → List (Arg SafeTerm) → List (Arg Term)\n toArgs k = map (λ x → weaken k (fmap safe-term x))\n\n SafeApplyType : Set → Set\n SafeApplyType A = List SafeTerm → Nat → A → List (Arg SafeTerm) → A\n\n safeApplyAbs : SafeApplyType (Abs Term)\n safeApplyArg : SafeApplyType (Arg Term)\n safeApplySort : SafeApplyType Sort\n\n -- safeApply′ env |Θ| v args = v′\n -- where Γ, Δ, Θ ⊢ v\n -- Γ ⊢ env : Δ\n -- Γ ⊢ args\n -- Γ, Θ ⊢ v′\n safeApply′ : List SafeTerm → Nat → Term → List (Arg SafeTerm) → Term\n safeApply′ env k (var x args) args₁ =\n if x t2) with construct-type t1 | construct-type t2\n ... | (l1 , ih1) | (l2 , ih2) = l1 ++ construct arrow :: l2 ++ [ move parent ] ,\n runtype++ ih1\n (DoType TMConArrow\n (runtype++ (ziplem-tmarr2 ih2)\n (DoType TMArrParent2 DoRefl)))\n\n mutual\n -- construction of expressions in synthetic positions\n construct-synth : {Γ : ·ctx} {t : τ̇} {e : ė} → (Γ ⊢ e => t) →\n Σ[ L ∈ List action ]\n runsynth Γ ▹ ⦇-⦈ ◃ ⦇-⦈ L ▹ e ◃ t\n -- the three base cases\n construct-synth (SVar x) = [ construct (var _) ] , DoSynth (SAConVar x) DoRefl\n construct-synth SNum = [ construct (numlit _) ] , DoSynth SAConNumlit DoRefl\n construct-synth SEHole = [ del ] , DoSynth SADel DoRefl\n\n -- the inductive cases\n construct-synth {t = t} (SAsc x) with construct-type t | construct-ana x\n ... | (l1 , ih1) | (l2 , ih2) = construct asc :: (l1 ++ move parent :: move (child 1) :: (l2 ++ [ move parent ])) ,\n DoSynth SAConAsc\n (runsynth++ (ziplem-asc2 ETTop ETTop ih1)\n (DoSynth (SAMove EMAscParent2)\n (DoSynth (SAMove EMAscChild1)\n (runsynth++ (ziplem-asc1 ih2)\n (DoSynth (SAMove EMAscParent1) DoRefl)))))\n\n construct-synth (SAp e1 m e2) with construct-synth e1 | construct-ana e2\n ... | (l1 , ih1) | (l2 , ih2) = l1 ++ construct ap :: (l2 ++ [ move parent ]) ,\n runsynth++ ih1\n (DoSynth (SAConApArr m)\n (runsynth++ (ziplem-ap2 e1 m ih2)\n (DoSynth (SAMove EMApParent2) DoRefl)))\n\n construct-synth (SPlus e1 e2 ) with construct-ana e1 | construct-ana e2\n ... | (l1 , ih1) | (l2 , ih2) = construct plus :: (l2 ++ move parent :: move (child 1) :: (l1 ++ [ move parent ])) ,\n DoSynth (SAConPlus1 TCHole2)\n (runsynth++ (ziplem-plus2 ih2)\n (DoSynth (SAMove EMPlusParent2)\n (DoSynth (SAMove EMPlusChild1)\n (runsynth++ (ziplem-plus1 ih1)\n (DoSynth (SAMove EMPlusParent1) DoRefl)))))\n\n construct-synth (SNEHole wt) with construct-synth wt\n ... | (l , ih) = l ++ construct nehole :: move parent :: [] ,\n runsynth++ ih\n (DoSynth SAConNEHole (DoSynth (SAMove EMNEHoleParent) DoRefl))\n\n -- construction of expressions in analytic positions\n construct-ana : {Γ : ·ctx} {t : τ̇} {e : ė} → (Γ ⊢ e <= t) →\n Σ[ L ∈ List action ]\n runana Γ ▹ ⦇-⦈ ◃ L ▹ e ◃ t\n construct-ana (ASubsume x c) with construct-synth x\n ... | (l , ih) = construct nehole :: l ++ (move parent :: finish :: []) ,\n DoAna (AASubsume EETop SEHole SAConNEHole TCHole1)\n (runana++ (ziplem-nehole-b SEHole c ih)\n (DoAna (AAMove EMNEHoleParent)\n (DoAna (AAFinish (ASubsume x c)) DoRefl)))\n\n construct-ana (ALam a m e) with construct-ana e\n ... | (l , ih) = construct (lam _) :: (l ++ [ move parent ]) ,\n DoAna (AAConLam1 a m)\n (runana++ (ziplem-lam a m ih)\n (DoAna (AAMove EMLamParent) DoRefl))\n", "meta": {"hexsha": "28609445dd5ad3ec714e1daea084645b55335831", "size": 4774, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "constructability.agda", "max_stars_repo_name": "hazelgrove/agda-popl17", "max_stars_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-07-01T22:44:11.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-11T12:30:50.000Z", "max_issues_repo_path": "constructability.agda", "max_issues_repo_name": "hazelgrove/agda-popl17", "max_issues_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2016-07-07T16:23:11.000Z", "max_issues_repo_issues_event_max_datetime": "2016-11-09T18:13:55.000Z", "max_forks_repo_path": "constructability.agda", "max_forks_repo_name": "hazelgrove/agda-popl17", "max_forks_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-03T03:45:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-03T03:45:07.000Z", "avg_line_length": 54.8735632184, "max_line_length": 120, "alphanum_fraction": 0.4953917051, "num_tokens": 1302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.39631423522549386}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Properties related to bag and set equality\n------------------------------------------------------------------------\n\n-- Bag and set equality are defined in Data.List.Any.\n\nmodule Data.List.Any.BagAndSetEquality where\n\nopen import Algebra\nopen import Algebra.FunctionProperties\nopen import Category.Monad\nopen import Data.List as List\nimport Data.List.Properties as LP\nopen import Data.List.Any as Any using (Any); open Any.Any\nopen import Data.List.Any.Properties\nopen import Data.Product\nopen import Data.Sum\nopen import Function\nopen import Function.Equality using (_⟨$⟩_)\nimport Function.Equivalence as FE\nopen import Function.Inverse as Inv using (_↔_; module Inverse)\nopen import Function.Related as Related using (↔⇒; ⌊_⌋; ⌊_⌋→; ⇒→)\nopen import Function.Related.TypeIsomorphisms\nopen import Relation.Binary\nimport Relation.Binary.EqReasoning as EqR\nopen import Relation.Binary.PropositionalEquality as P\n using (_≡_; _≗_)\nopen import Relation.Binary.Sum\nopen import Relation.Nullary\n\nopen Any.Membership-≡\nprivate\n module Eq {k a} {A : Set a} = Setoid ([ k ]-Equality A)\n module Ord {k a} {A : Set a} = Preorder ([ k ]-Order A)\n module ×⊎ {k ℓ} = CommutativeSemiring (×⊎-CommutativeSemiring k ℓ)\n open module ListMonad {ℓ} = RawMonad (List.monad {ℓ = ℓ})\n module ListMonoid {a} {A : Set a} = Monoid (List.monoid A)\n\n------------------------------------------------------------------------\n-- Congruence lemmas\n\n-- _∷_ is a congruence.\n\n∷-cong : ∀ {a k} {A : Set a} {x₁ x₂ : A} {xs₁ xs₂} →\n x₁ ≡ x₂ → xs₁ ∼[ k ] xs₂ → x₁ ∷ xs₁ ∼[ k ] x₂ ∷ xs₂\n∷-cong {x₂ = x} {xs₁} {xs₂} P.refl xs₁≈xs₂ {y} =\n y ∈ x ∷ xs₁ ↔⟨ sym $ ∷↔ (_≡_ y) ⟩\n (y ≡ x ⊎ y ∈ xs₁) ∼⟨ (y ≡ x ∎) ⊎-cong xs₁≈xs₂ ⟩\n (y ≡ x ⊎ y ∈ xs₂) ↔⟨ ∷↔ (_≡_ y) ⟩\n y ∈ x ∷ xs₂ ∎\n where open Related.EquationalReasoning\n\n-- List.map is a congruence.\n\nmap-cong : ∀ {ℓ k} {A B : Set ℓ} {f₁ f₂ : A → B} {xs₁ xs₂} →\n f₁ ≗ f₂ → xs₁ ∼[ k ] xs₂ →\n List.map f₁ xs₁ ∼[ k ] List.map f₂ xs₂\nmap-cong {ℓ} {f₁ = f₁} {f₂} {xs₁} {xs₂} f₁≗f₂ xs₁≈xs₂ {x} =\n x ∈ List.map f₁ xs₁ ↔⟨ sym $ map↔ {a = ℓ} {b = ℓ} {p = ℓ} ⟩\n Any (λ y → x ≡ f₁ y) xs₁ ∼⟨ Any-cong (↔⇒ ∘ helper) xs₁≈xs₂ ⟩\n Any (λ y → x ≡ f₂ y) xs₂ ↔⟨ map↔ {a = ℓ} {b = ℓ} {p = ℓ} ⟩\n x ∈ List.map f₂ xs₂ ∎\n where\n open Related.EquationalReasoning\n\n helper : ∀ y → x ≡ f₁ y ↔ x ≡ f₂ y\n helper y = record\n { to = P.→-to-⟶ (λ x≡f₁y → P.trans x≡f₁y ( f₁≗f₂ y))\n ; from = P.→-to-⟶ (λ x≡f₂y → P.trans x≡f₂y (P.sym $ f₁≗f₂ y))\n ; inverse-of = record\n { left-inverse-of = λ _ → P.proof-irrelevance _ _\n ; right-inverse-of = λ _ → P.proof-irrelevance _ _\n }\n }\n\n-- _++_ is a congruence.\n\n++-cong : ∀ {a k} {A : Set a} {xs₁ xs₂ ys₁ ys₂ : List A} →\n xs₁ ∼[ k ] xs₂ → ys₁ ∼[ k ] ys₂ →\n xs₁ ++ ys₁ ∼[ k ] xs₂ ++ ys₂\n++-cong {a} {xs₁ = xs₁} {xs₂} {ys₁} {ys₂} xs₁≈xs₂ ys₁≈ys₂ {x} =\n x ∈ xs₁ ++ ys₁ ↔⟨ sym $ ++↔ {a = a} {p = a} ⟩\n (x ∈ xs₁ ⊎ x ∈ ys₁) ∼⟨ xs₁≈xs₂ ⊎-cong ys₁≈ys₂ ⟩\n (x ∈ xs₂ ⊎ x ∈ ys₂) ↔⟨ ++↔ {a = a} {p = a} ⟩\n x ∈ xs₂ ++ ys₂ ∎\n where open Related.EquationalReasoning\n\n-- concat is a congruence.\n\nconcat-cong : ∀ {a k} {A : Set a} {xss₁ xss₂ : List (List A)} →\n xss₁ ∼[ k ] xss₂ → concat xss₁ ∼[ k ] concat xss₂\nconcat-cong {a} {xss₁ = xss₁} {xss₂} xss₁≈xss₂ {x} =\n x ∈ concat xss₁ ↔⟨ sym $ concat↔ {a = a} {p = a} ⟩\n Any (Any (_≡_ x)) xss₁ ∼⟨ Any-cong (λ _ → _ ∎) xss₁≈xss₂ ⟩\n Any (Any (_≡_ x)) xss₂ ↔⟨ concat↔ {a = a} {p = a} ⟩\n x ∈ concat xss₂ ∎\n where open Related.EquationalReasoning\n\n-- The list monad's bind is a congruence.\n\n>>=-cong : ∀ {ℓ k} {A B : Set ℓ} {xs₁ xs₂} {f₁ f₂ : A → List B} →\n xs₁ ∼[ k ] xs₂ → (∀ x → f₁ x ∼[ k ] f₂ x) →\n (xs₁ >>= f₁) ∼[ k ] (xs₂ >>= f₂)\n>>=-cong {ℓ} {xs₁ = xs₁} {xs₂} {f₁} {f₂} xs₁≈xs₂ f₁≈f₂ {x} =\n x ∈ (xs₁ >>= f₁) ↔⟨ sym $ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩\n Any (λ y → x ∈ f₁ y) xs₁ ∼⟨ Any-cong (λ x → f₁≈f₂ x) xs₁≈xs₂ ⟩\n Any (λ y → x ∈ f₂ y) xs₂ ↔⟨ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩\n x ∈ (xs₂ >>= f₂) ∎\n where open Related.EquationalReasoning\n\n-- _⊛_ is a congruence.\n\n⊛-cong : ∀ {ℓ k} {A B : Set ℓ} {fs₁ fs₂ : List (A → B)} {xs₁ xs₂} →\n fs₁ ∼[ k ] fs₂ → xs₁ ∼[ k ] xs₂ → fs₁ ⊛ xs₁ ∼[ k ] fs₂ ⊛ xs₂\n⊛-cong fs₁≈fs₂ xs₁≈xs₂ =\n >>=-cong fs₁≈fs₂ λ f →\n >>=-cong xs₁≈xs₂ λ x →\n _ ∎\n where open Related.EquationalReasoning\n\n-- _⊗_ is a congruence.\n\n⊗-cong : ∀ {ℓ k} {A B : Set ℓ} {xs₁ xs₂ : List A} {ys₁ ys₂ : List B} →\n xs₁ ∼[ k ] xs₂ → ys₁ ∼[ k ] ys₂ →\n (xs₁ ⊗ ys₁) ∼[ k ] (xs₂ ⊗ ys₂)\n⊗-cong {ℓ} xs₁≈xs₂ ys₁≈ys₂ =\n ⊛-cong (⊛-cong (Ord.refl {x = [ _,_ {a = ℓ} {b = ℓ} ]})\n xs₁≈xs₂)\n ys₁≈ys₂\n\n------------------------------------------------------------------------\n-- Other properties\n\n-- _++_ and [] form a commutative monoid, with either bag or set\n-- equality as the underlying equality.\n\ncommutativeMonoid : ∀ {a} → Symmetric-kind → Set a →\n CommutativeMonoid _ _\ncommutativeMonoid {a} k A = record\n { Carrier = List A\n ; _≈_ = λ xs ys → xs ∼[ ⌊ k ⌋ ] ys\n ; _∙_ = _++_\n ; ε = []\n ; isCommutativeMonoid = record\n { isSemigroup = record\n { isEquivalence = Eq.isEquivalence\n ; assoc = λ xs ys zs →\n Eq.reflexive (ListMonoid.assoc xs ys zs)\n ; ∙-cong = ++-cong\n }\n ; identityˡ = λ xs {x} → x ∈ xs ∎\n ; comm = λ xs ys {x} →\n x ∈ xs ++ ys ↔⟨ ++↔++ {a = a} {p = a} xs ys ⟩\n x ∈ ys ++ xs ∎\n }\n }\n where open Related.EquationalReasoning\n\n-- The only list which is bag or set equal to the empty list (or a\n-- subset or subbag of the list) is the empty list itself.\n\nempty-unique : ∀ {k a} {A : Set a} {xs : List A} →\n xs ∼[ ⌊ k ⌋→ ] [] → xs ≡ []\nempty-unique {xs = []} _ = P.refl\nempty-unique {xs = _ ∷ _} ∷∼[] with ⇒→ ∷∼[] (here P.refl)\n... | ()\n\n-- _++_ is idempotent (under set equality).\n\n++-idempotent : ∀ {a} {A : Set a} →\n Idempotent (λ (xs ys : List A) → xs ∼[ set ] ys) _++_\n++-idempotent {a} xs {x} =\n x ∈ xs ++ xs ∼⟨ FE.equivalence ([ id , id ]′ ∘ _⟨$⟩_ (Inverse.from $ ++↔ {a = a} {p = a}))\n (_⟨$⟩_ (Inverse.to $ ++↔ {a = a} {p = a}) ∘ inj₁) ⟩\n x ∈ xs ∎\n where open Related.EquationalReasoning\n\n-- The list monad's bind distributes from the left over _++_.\n\n>>=-left-distributive :\n ∀ {ℓ} {A B : Set ℓ} (xs : List A) {f g : A → List B} →\n (xs >>= λ x → f x ++ g x) ∼[ bag ] (xs >>= f) ++ (xs >>= g)\n>>=-left-distributive {ℓ} xs {f} {g} {y} =\n y ∈ (xs >>= λ x → f x ++ g x) ↔⟨ sym $ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩\n Any (λ x → y ∈ f x ++ g x) xs ↔⟨ sym (Any-cong (λ _ → ++↔ {a = ℓ} {p = ℓ}) (_ ∎)) ⟩\n Any (λ x → y ∈ f x ⊎ y ∈ g x) xs ↔⟨ sym $ ⊎↔ {a = ℓ} {p = ℓ} {q = ℓ} ⟩\n (Any (λ x → y ∈ f x) xs ⊎ Any (λ x → y ∈ g x) xs) ↔⟨ >>=↔ {ℓ = ℓ} {p = ℓ} ⟨ ×⊎.+-cong {ℓ = ℓ} ⟩ >>=↔ {ℓ = ℓ} {p = ℓ} ⟩\n (y ∈ (xs >>= f) ⊎ y ∈ (xs >>= g)) ↔⟨ ++↔ {a = ℓ} {p = ℓ} ⟩\n y ∈ (xs >>= f) ++ (xs >>= g) ∎\n where open Related.EquationalReasoning\n\n-- The same applies to _⊛_.\n\n⊛-left-distributive :\n ∀ {ℓ} {A B : Set ℓ} (fs : List (A → B)) xs₁ xs₂ →\n fs ⊛ (xs₁ ++ xs₂) ∼[ bag ] (fs ⊛ xs₁) ++ (fs ⊛ xs₂)\n⊛-left-distributive {B = B} fs xs₁ xs₂ = begin\n fs ⊛ (xs₁ ++ xs₂) ≡⟨ P.refl ⟩\n (fs >>= λ f → xs₁ ++ xs₂ >>= return ∘ f) ≡⟨ (LP.Monad.cong (P.refl {x = fs}) λ f →\n LP.Monad.right-distributive xs₁ xs₂ (return ∘ f)) ⟩\n (fs >>= λ f → (xs₁ >>= return ∘ f) ++\n (xs₂ >>= return ∘ f)) ≈⟨ >>=-left-distributive fs ⟩\n\n (fs >>= λ f → xs₁ >>= return ∘ f) ++\n (fs >>= λ f → xs₂ >>= return ∘ f) ≡⟨ P.refl ⟩\n\n (fs ⊛ xs₁) ++ (fs ⊛ xs₂) ∎\n where open EqR ([ bag ]-Equality B)\n\nprivate\n\n -- If x ∷ xs is set equal to x ∷ ys, then xs and ys are not\n -- necessarily set equal.\n\n ¬-drop-cons :\n ∀ {a} {A : Set a} {x : A} →\n ¬ (∀ {xs ys} → x ∷ xs ∼[ set ] x ∷ ys → xs ∼[ set ] ys)\n ¬-drop-cons {x = x} drop-cons\n with FE.Equivalence.to x∼[] ⟨$⟩ here P.refl\n where\n x,x≈x : (x ∷ x ∷ []) ∼[ set ] [ x ]\n x,x≈x = ++-idempotent [ x ]\n\n x∼[] : [ x ] ∼[ set ] []\n x∼[] = drop-cons x,x≈x\n ... | ()\n\n-- However, the corresponding property does hold for bag equality.\n\ndrop-cons : ∀ {a} {A : Set a} {x : A} {xs ys} →\n x ∷ xs ∼[ bag ] x ∷ ys → xs ∼[ bag ] ys\ndrop-cons {A = A} {x} {xs} {ys} x∷xs≈x∷ys {z} = record\n { to = P.→-to-⟶ $ f x∷xs≈x∷ys\n ; from = P.→-to-⟶ $ f $ Inv.sym x∷xs≈x∷ys\n ; inverse-of = record\n { left-inverse-of = f∘f x∷xs≈x∷ys\n ; right-inverse-of = f∘f $ Inv.sym x∷xs≈x∷ys\n }\n }\n where\n open Inverse\n open P.≡-Reasoning\n\n f : ∀ {xs ys z} → (z ∈ x ∷ xs) ↔ (z ∈ x ∷ ys) → z ∈ xs → z ∈ ys\n f inv z∈xs with to inv ⟨$⟩ there z∈xs | left-inverse-of inv (there z∈xs)\n f inv z∈xs | there z∈ys | left⁺ = z∈ys\n f inv z∈xs | here z≡x | left⁺ with to inv ⟨$⟩ here z≡x | left-inverse-of inv (here z≡x)\n f inv z∈xs | here z≡x | left⁺ | there z∈ys | left⁰ = z∈ys\n f inv z∈xs | here P.refl | left⁺ | here P.refl | left⁰ with begin\n here P.refl ≡⟨ P.sym left⁰ ⟩\n from inv ⟨$⟩ here P.refl ≡⟨ left⁺ ⟩\n there z∈xs ∎\n ... | ()\n\n f∘f : ∀ {xs ys z}\n (inv : (z ∈ x ∷ xs) ↔ (z ∈ x ∷ ys)) (p : z ∈ xs) →\n f (Inv.sym inv) (f inv p) ≡ p\n f∘f inv z∈xs with to inv ⟨$⟩ there z∈xs | left-inverse-of inv (there z∈xs)\n f∘f inv z∈xs | there z∈ys | left⁺ with from inv ⟨$⟩ there z∈ys | right-inverse-of inv (there z∈ys)\n f∘f inv z∈xs | there z∈ys | P.refl | .(there z∈xs) | _ = P.refl\n f∘f inv z∈xs | here z≡x | left⁺ with to inv ⟨$⟩ here z≡x | left-inverse-of inv (here z≡x)\n f∘f inv z∈xs | here z≡x | left⁺ | there z∈ys | left⁰ with from inv ⟨$⟩ there z∈ys | right-inverse-of inv (there z∈ys)\n f∘f inv z∈xs | here z≡x | left⁺ | there z∈ys | P.refl | .(here z≡x) | _ with from inv ⟨$⟩ here z≡x\n | right-inverse-of inv (here z≡x)\n f∘f inv z∈xs | here z≡x | P.refl | there z∈ys | P.refl | .(here z≡x) | _ | .(there z∈xs) | _ = P.refl\n f∘f inv z∈xs | here P.refl | left⁺ | here P.refl | left⁰ with begin\n here P.refl ≡⟨ P.sym left⁰ ⟩\n from inv ⟨$⟩ here P.refl ≡⟨ left⁺ ⟩\n there z∈xs ∎\n ... | ()\n", "meta": {"hexsha": "bbda405f93ddd2daa596a0214097db43f8951040", "size": 10675, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Data/List/Any/BagAndSetEquality.agda", "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_issues_repo_path": "agda-stdlib-0.9/src/Data/List/Any/BagAndSetEquality.agda", "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_licenses": ["Apache-2.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": "agda-stdlib-0.9/src/Data/List/Any/BagAndSetEquality.agda", "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.1025641026, "max_line_length": 125, "alphanum_fraction": 0.4731615925, "num_tokens": 4543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6150878696277513, "lm_q2_score": 0.6442251064863697, "lm_q1q2_score": 0.3962550483094123}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\n\nmodule Cubical.Papers.HigherGroupsViaDURG where\n\n-- Johannes Schipp von Branitz,\n-- \"Higher Groups via Displayed Univalent Reflexive Graphs in Cubical Type Theory\".\n\nimport Cubical.Algebra.Group as Group\n\nimport Cubical.Core.Glue as Glue\n\nimport Cubical.Data.Sigma.Properties as Sigma\nimport Cubical.Data.Unit as Unit\n\nimport Cubical.DStructures.Base as DSBase\n\nimport Cubical.DStructures.Meta.Properties as DSProperties\nimport Cubical.DStructures.Meta.Isomorphism as DSIsomorphism\n\nimport Cubical.DStructures.Structures.Action as DSAction\nimport Cubical.DStructures.Structures.Category as DSCategory\nimport Cubical.DStructures.Structures.Constant as DSConstant\nimport Cubical.DStructures.Structures.Group as DSGroup\nimport Cubical.DStructures.Structures.Higher as DSHigher\nimport Cubical.DStructures.Structures.Nat as DSNat\nimport Cubical.DStructures.Structures.PeifferGraph as DSPeifferGraph\nimport Cubical.DStructures.Structures.ReflGraph as DSReflGraph\nimport Cubical.DStructures.Structures.SplitEpi as DSSplitEpi\nimport Cubical.DStructures.Structures.Strict2Group as DSStrict2Group\nimport Cubical.DStructures.Structures.Type as DSType\nimport Cubical.DStructures.Structures.Universe as DSUniverse\nimport Cubical.DStructures.Structures.VertComp as DSVertComp\nimport Cubical.DStructures.Structures.XModule as DSXModule\nimport Cubical.DStructures.Equivalences.GroupSplitEpiAction as DSGroupSplitEpiAction\nimport Cubical.DStructures.Equivalences.PreXModReflGraph as DSPreXModReflGraph\nimport Cubical.DStructures.Equivalences.XModPeifferGraph as DSXModPeifferGraph\nimport Cubical.DStructures.Equivalences.PeifferGraphS2G as DSPeifferGraphS2G\n\nimport Cubical.Foundations.GroupoidLaws as GroupoidLaws\nimport Cubical.Foundations.Equiv as Equiv\nimport Cubical.Foundations.Equiv.Fiberwise as Fiberwise\nimport Cubical.Foundations.Filler as Filler\nimport Cubical.Foundations.HLevels as HLevels\nimport Cubical.Foundations.HLevels' as HLevels'\nimport Cubical.Foundations.Isomorphism as Isomorphism\nimport Cubical.Foundations.Prelude as Prelude\nimport Cubical.Foundations.Path as FPath\nimport Cubical.Foundations.Pointed as Pointed\nimport Cubical.Foundations.Univalence as Univalence\nimport Cubical.Foundations.Transport as Transport\n\nimport Cubical.Functions.FunExtEquiv as FunExtEquiv\nimport Cubical.Functions.Fibration as Fibration\n\nimport Cubical.Relation.Binary as Binary\n\nimport Cubical.HITs.EilenbergMacLane1 as EM1\n\nimport Cubical.Homotopy.Base as HomotopyBase\nimport Cubical.Homotopy.Connected as Connected\nimport Cubical.Homotopy.PointedFibration as PointedFibration\nimport Cubical.Homotopy.Loopspace as Loopspace\n\nimport Cubical.Structures.Subtype as Subtype\n\nimport Cubical.HITs.Truncation as Truncation\n\n----------------------------------------------------------------------------\n-- 2. Cubical Type Theory\n-- 2.1 Dependent Type Theory\n-- 2.2 Path Types\n-- 2.3 Cubical Groupoid Laws\n-- 2.4 Functions, Equivalences and Univalence\n-- 2.5 Truncated and Connected Types\n-- 2.6 Groups\n----------------------------------------------------------------------------\n\n\n-- 2.2 Path Types\n\n\n-- Example 2.1\nopen Sigma using (ΣPath≡PathΣ) public\n\nopen Prelude using (transport) public\n\n-- Proposition 2.2\nopen FPath using (PathP≡Path) public\n\n\n-- 2.3 Cubical Groupoid Laws\n\nopen Prelude using (refl;\n transportRefl;\n subst;\n J) public\n renaming (cong to ap) public\nopen Prelude using (_∙∙_∙∙_;\n doubleCompPath-filler;\n compPath-unique) public\nopen Prelude using (_∙_) public\n\n-- Lemma 2.5\nopen FPath using (PathP≡doubleCompPathˡ) public\n\n-- Lemma 2.5\nopen GroupoidLaws using (doubleCompPath-elim) public\n\n-- Lemma 2.6\nopen Filler using (cube-cong) public\n\n\n-- 2.4 Functions, Equivalences and Univalence\n\n\nopen Unit renaming (Unit to 𝟙) public\nopen Prelude using (isContr) public\nopen Unit using (isContrUnit) public\n\n-- Proposition 2.7\nopen Prelude using (singl;\n isContrSingl) public\n\n-- Definition 2.8\nopen Equiv renaming (fiber to fib) public\nopen Glue using (isEquiv;\n _≃_;\n equivFun) public\nopen Isomorphism using (Iso) public\n\n-- Proposition 2.9\nopen Transport using (isEquivTransport) public\n\n-- Proposition 2.10\nopen Fiberwise using (fiberEquiv;\n totalEquiv) public\n\n-- Proposition 2.11\nopen Sigma using (Σ-cong-equiv) public\n\n-- Definition 2.12\nopen HomotopyBase using (_∼_) public\n\n-- Theorem 2.13\nopen FunExtEquiv using (funExtEquiv) public\n\n-- Theorem 2.14\nopen Univalence using (univalence) public\n renaming (ua to idToEquiv⁻¹;\n uaβ to idToEquiv-β;\n uaη to idToEquiv-η) public\n\n-- Lemma 2.15\nopen Univalence using (ua→) public\n\n\n-- 2.5 Truncated and Connected Types\n\n\nopen Prelude using (isProp;\n isSet) public\nopen HLevels using (isOfHLevel;\n TypeOfHLevel) public\n\n-- Lemma 2.16\nopen Sigma using (Σ-contractFst;\n Σ-contractSnd) public\n\n-- Lemma 2.17\nopen Prelude using (isProp→PathP) public\n\n-- Lemma 2.18\nopen Subtype using (subtypeWitnessIrrelevance) public\nopen Sigma using (Σ≡Prop) public\n\n-- Definition 2.19\nopen HLevels using (isOfHLevelDep) public\n\n-- Proposition 2.20\nopen HLevels' using (truncSelfId→truncId) public\n\n-- Proposition 2.21\nopen HLevels using (isOfHLevelΣ) public\n\n-- Proposition 2.22\nopen HLevels using (isPropIsOfHLevel) public\n\n-- Proposition 2.23\nopen HLevels using (isOfHLevelΠ) public\n\n-- Theorem 2.24\nopen Truncation using (∥_∥_;\n rec;\n elim) public\n\n-- Definition 2.25\nopen Connected using (isConnected;\n isConnectedFun) public\n\n-- Lemma 2.26\nopen Connected using (isConnectedPoint) public\n\n\n-- 2.6 Groups\n\n-- Proposition 2.28\nopen Group using (isPropIsGroupHom;\n isSetGroupHom) public\n\n-- Proposition 2.29\nopen Group.Kernel using (ker) public\n\n-- Proposition 2.30\nopen Group using (GroupMorphismExt) public\n\n-- Theorem 2.31\nopen Group using (GroupPath) public\n\n-- Definition 2.32\nopen Group using (isGroupSplitEpi) public\n\n-- Definition 2.33\nopen Group using (GroupAction;\n IsGroupAction) public\n\n-- Proposition 2.34\nopen Group using (semidirectProd) public\n\n\n-----------------------------------------------------------------------------\n-- 3. Displayed Structures\n-- 3.1 Motivation\n-- 3.2 Displayed Categories\n-- 3.3 Univalent Reflexive Graphs\n-- 3.4 Displayed Univalent Reflexive Graphs\n-- 3.5 Operations on Displayed Univalent Reflexive Graphs\n-- 3.6 Constructing Equivalences Using Displayed Univalent Reflexive Graphs\n-----------------------------------------------------------------------------\n\n-- 3.1 Motivation\n\n-- Proposition 3.1\nopen Fibration using (dispTypeIso) public\n\n-- 3.2 Displayed Categories\n\n-- Definition 3.2\n-- not implemented\n\n-- Theorem 3.3\n-- not implemented\n\n-- 3.3 Univalent Reflexive Graphs\n\n-- Definition 3.4, 3.5\nopen DSBase using (URGStr) public\n\n-- Example 3.6\nopen DSGroup using (𝒮-group) public\n\n-- Example 3.7\nopen DSCategory using (Cat→𝒮) public\n\n-- Proposition 3.8\n-- not implemented\n\n-- Example 3.9\nopen DSNat using (𝒮-Nat) public\n\n-- Theorem 3.10\nopen Binary using (contrRelSingl→isUnivalent;\n isUnivalent→contrRelSingl) public\n\n-- Example 3.11\nopen DSType using (𝒮-type) public\nopen DSUniverse using (𝒮-universe) public\n\n-- Proposition 3.12\nopen DSType using (𝒮-uniqueness) public\n\n\n-- 3.4 Displayed Univalent Reflexive Graphs\n\n\n-- Proposition 3.13\nopen DSBase using (URGStrᴰ) public\n\nopen DSBase using (make-𝒮ᴰ) public\n\n-- Proposition 3.14\nopen DSType using (Subtype→Sub-𝒮ᴰ) public\n\n-- Example 3.15\nopen DSHigher using (𝒮ᴰ-connected;\n 𝒮ᴰ-truncated) public\n\n\n-- 3.5 Operations on Displayed Univalent Reflexive Graphs\n\n\n-- Theorem 3.16\nopen DSProperties using (∫⟨_⟩_) public\n\n-- Corollary 3.17\nopen DSConstant using (𝒮ᴰ-const) public\n\n-- Definition 3.18\nopen DSConstant using (_×𝒮_) public\n\n-- Theorem 3.19\nopen DSProperties using (splitTotal-𝒮ᴰ) public\n\n-- Proposition 3.20\nopen DSProperties using (VerticalLift-𝒮ᴰ) public\n\n-- Corollary 3.21\nopen DSProperties using (combine-𝒮ᴰ) public\n\n\n-- 3.6 Constructing Equivalences Using Displayed Univalent Reflexive Graphs\n\n\n-- Definition 3.22\nopen Binary using (RelIso) public\n\n-- Proposition 3.23\nopen DSIsomorphism using (𝒮-PIso;\n 𝒮-PIso→Iso) public\n\n-- Definition 3.24, Theorem 3.25\nopen Binary using (RelFiberIsoOver→Iso) public\nopen DSIsomorphism using (𝒮ᴰ-♭PIso-Over→TotalIso) public\n\n-----------------------------------------------------------------------------\n-- 4. Equivalence of Strict 2-Groups and Crossed Modules\n-- 4.1 Strict 2-Groups\n-- 4.2 Crossed Modules\n-- 4.3 Group Actions and Split Monomorphisms\n-- 4.4 Precrossed Modules and Internal Reflexive Graphs\n-- 4.5 Crossed Modules and Peiffer Graphs\n-- 4.6 Peiffer Graphs and Strict 2-Groups\n----------------------------------------------------------------------------\n\n\n-- 4.1 Strict 2-Groups\n\n\n-- Example 4.1\n-- not implemented\n\n\n-- 4.2 Crossed Modules\n\n\n-- Definition 4.2, Example 4.3\n-- not implemented\n\n\n-- 4.3 Group Actions and Split Monomorphisms\n\n\n-- Proposition 4.4\nopen DSGroup using (𝒮ᴰ-G²\\F;\n 𝒮ᴰ-G²\\B;\n 𝒮ᴰ-G²\\FB) public\n\n-- Lemma 4.5\nopen DSSplitEpi using (𝒮ᴰ-SplitEpi) public\n\n-- Lemma 4.6\nopen DSAction using (𝒮ᴰ-G²\\Las) public\n\n-- Lemma 4.7\nopen DSAction using (𝒮ᴰ-G²Las\\Action) public\n\n\n-- Proposition 4.8, Proposition 4.9, Lemma 4.10, Theorem 4.11\nopen DSGroupSplitEpiAction using (𝒮ᴰ-Iso-GroupAct-SplitEpi-*;\n IsoActionSplitEpi) public\n\n\n-- 4.4 Precrossed Modules and Internal Reflexive Graphs\n\n\n-- Lemma 4.12\nopen DSXModule using (𝒮ᴰ-Action\\PreXModuleStr) public\n\n-- Definition 4.13\nopen DSXModule using (isEquivariant;\n isPropIsEquivariant;\n PreXModule) public\n\n-- Lemma 4.14\nopen DSSplitEpi using (𝒮ᴰ-G²FBSplit\\B) public\n\n-- Lemma 4.15\nopen DSReflGraph using (𝒮ᴰ-ReflGraph; ReflGraph) public\n\n-- Lemma 4.16, Lemma 4.17, Lemma 4.18, Theorem 4.19\nopen DSPreXModReflGraph using (𝒮ᴰ-♭PIso-PreXModule'-ReflGraph';\n Iso-PreXModule-ReflGraph) public\n\n\n-- 4.5 Crossed Modules and Peiffer Graphs\n\n-- Definition 4.20\nopen DSXModule using (XModule;\n isPeiffer;\n isPropIsPeiffer) public\n\n-- Definition 4.21\nopen DSPeifferGraph using (isPeifferGraph;\n isPropIsPeifferGraph) public\n\n-- Lemma 4.22, Lemma 4.2.3, Theorem 4.24\nopen DSXModPeifferGraph public\n\n\n-- 4.6 Peiffer Graphs and Strict 2-Groups\n\n\n-- Definition 4.25\nopen DSVertComp using (VertComp) public\n\n-- Proposition 4.26\nopen DSVertComp using (VertComp→+₁) public\n\n-- Proposition 4.27\nopen DSVertComp using (isPropVertComp) public\n\n-- Proposition 4.28, Proposition 4.29, Theorem 4.30\nopen DSPeifferGraphS2G public\n\n\n\n\n--------------------------------------------------------\n-- 5. Higher Groups in Cubical Type Theory\n-- 5.1 Pointed Types\n-- 5.2 Homotopy Groups\n-- 5.3 Higher Groups\n-- 5.4 Eilenberg-MacLane-Spaces\n-- 5.5 Delooping Groups\n-------------------------------------------------------\n\n\n-- 5.1 Pointed Types\n\n\n-- Proposition 5.1\nopen DSUniverse using (𝒮ᴰ-pointed) public\n\n-- Definition 5.2\nopen Pointed using (Π∙) public\n\n-- Definition 5.3\nopen Pointed using (_∙∼_;\n _∙∼P_) public\n\n-- Proposition 5.4\nopen Pointed using (∙∼≃∙∼P) public\n\n-- Theorem 5.5\nopen Pointed using (funExt∙≃) public\n\n-- Theorem 5.6\nopen PointedFibration using (sec∙Trunc') public\n\n\n-- 5.2 Homotopy Groups\n\n\n-- Definition 5.7\nopen Loopspace using (Ω) public\n\n-- Definition 5.8\nopen Group using (π₁-1BGroup) public\n\n\n-- 5.3 Higher Groups\n\n\n-- Lemma 5.9\nopen DSHigher using (𝒮-BGroup) public\n\n-- Definition 5.10\nopen Group using (BGroup) public\n\n-- Proposition 5.11\nopen DSHigher using (𝒮ᴰ-BGroupHom) public\n\n-- Corollary 5.12\n-- not implemented\n\n\n-- 5.4 Eilenberg-MacLane-Spaces\n\n\n-- Definition 5.13\nopen EM1 using (EM₁) public\n\n-- Lemma 5.14\nopen EM1 using (emloop-comp) public\n\n-- Lemma 5.15\nopen EM1 using (elimEq) public\n\n-- Theorem 5.16\nopen EM1 renaming (elim to EM₁-elim;\n rec to EM₁-rec) public\n\n-- Lemma 5.17\nopen Group using (emloop-id;\n emloop-inv) public\n\n-- Theorem 5.18\nopen Group using (π₁EM₁≃) public\n\n-- 5.5 Delooping Groups\n\n-- Proposition 5.19, Theorem 5.20\nopen DSHigher using (𝒮-Iso-BGroup-Group) public\n", "meta": {"hexsha": "96441e8809db775de1dcbf659bd54d1d3986fd06", "size": 12503, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Papers/HigherGroupsViaDURG.agda", "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/Papers/HigherGroupsViaDURG.agda", "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/Papers/HigherGroupsViaDURG.agda", "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": 23.9063097514, "max_line_length": 84, "alphanum_fraction": 0.6939934416, "num_tokens": 3758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442250928250375, "lm_q2_score": 0.6150878555160665, "lm_q1q2_score": 0.39625503081539115}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- The universe polymorphic unit type and ordering relation\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.Unit.Polymorphic.Base where\n\nopen import Level\n\n------------------------------------------------------------------------\n-- A unit type defined as a record type\n\nrecord ⊤ {ℓ : Level} : Set ℓ where\n constructor tt\n", "meta": {"hexsha": "b29faea0eaecabdc8aedbd205c5782b2900c1bf8", "size": 501, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib/src/Data/Unit/Polymorphic/Base.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "agda-stdlib/src/Data/Unit/Polymorphic/Base.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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-stdlib/src/Data/Unit/Polymorphic/Base.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 27.8333333333, "max_line_length": 72, "alphanum_fraction": 0.4031936128, "num_tokens": 76, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6723317123102956, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.3959288376500581}} {"text": "\n-- Typing contexts and environments\nmodule Syntax.Context where\n\nopen import Syntax.Types\n\nopen import Relation.Binary using (IsPreorder)\nopen import Relation.Binary.PropositionalEquality hiding ([_])\nopen import Data.Sum\n\n-- | Data types\n\n-- A type judgement with temporal qualifiers:\n-- a type is either inhabited now, or always\ndata Judgement : Set where\n _now : Type -> Judgement\n _always : Type -> Judgement\ninfixl 60 _now\ninfixl 60 _always\n\n-- Typing context as a list of types\ndata Context : Set where\n ∙ : Context\n _,_ : Context -> Judgement -> Context\ninfixl 50 _,_\n\n\n-- | Context operations and predicates\n\n-- Singleton context\n[_] : Judgement -> Context\n[ A ] = ∙ , A\n\n-- Concatenation of contexts\n_⌊⌋_ : Context -> Context -> Context\nΓ ⌊⌋ ∙ = Γ\nΓ ⌊⌋ (Γ′ , A) = (Γ ⌊⌋ Γ′) , A\ninfixl 45 _⌊⌋_\n\n-- Type in the middle of a context\n_⌊_⌋_ : Context -> Judgement -> Context -> Context\nΓ ⌊ A ⌋ Γ′ = Γ , A ⌊⌋ Γ′\ninfixl 45 _⌊_⌋_\n\n-- Stabilise the context by filtering out the stable types\n_ˢ : Context -> Context\n∙ ˢ = ∙\n(Γ , A now) ˢ = Γ ˢ\n(Γ , A always) ˢ = Γ ˢ , A always\ninfixl 60 _ˢ\n\n\n-- Predicate for context membership\ndata _∈_ : Judgement -> Context -> Set where\n top : ∀{Γ A} -> A ∈ Γ , A\n pop : ∀{Γ A B} -> A ∈ Γ -> A ∈ Γ , B\ninfix 35 _∈_\n\n-- Predicate for context subset relation\ndata _⊆_ : Context -> Context -> Set where\n refl : ∀{Γ} -> Γ ⊆ Γ\n keep : ∀{Γ Γ′ A} -> Γ ⊆ Γ′ -> Γ , A ⊆ Γ′ , A\n drop : ∀{Γ Γ′ A} -> Γ ⊆ Γ′ -> Γ ⊆ Γ′ , A\ninfix 30 _⊆_\n\n\n-- || Context lemmas\n\n-- | Element and subcontext relations\n\n-- Element of a subset is an element of a set.\n∈-⊆-monotone : ∀{Γ Γ′ A} -> Γ ⊆ Γ′ -> A ∈ Γ -> A ∈ Γ′\n∈-⊆-monotone refl e = e\n∈-⊆-monotone (keep p) top = top\n∈-⊆-monotone (keep p) (pop e) = pop (∈-⊆-monotone p e)\n∈-⊆-monotone (drop p) e = pop (∈-⊆-monotone p e)\n\n-- Subset relation is reflexive\n⊆-refl-eq : ∀{Γ Γ′} -> Γ ≡ Γ′ -> Γ ⊆ Γ′\n⊆-refl-eq refl = refl\n\n-- Subset relation is transitive\n⊆-trans : ∀{Γ Δ Ξ} -> Γ ⊆ Δ -> Δ ⊆ Ξ -> Γ ⊆ Ξ\n⊆-trans refl c2 = c2\n⊆-trans c1 refl = c1\n⊆-trans c1 (drop c2) = drop (⊆-trans c1 c2)\n⊆-trans (keep c1) (keep c2) = keep (⊆-trans c1 c2)\n⊆-trans (drop c1) (keep c2) = drop (⊆-trans c1 c2)\n\n-- Subset relation is a preorder\n⊆-po : IsPreorder _≡_ _⊆_\n⊆-po = record\n { isEquivalence = isEquivalence\n ; reflexive = ⊆-refl-eq\n ; trans = ⊆-trans\n }\n\n-- | Concatenation\n\n-- Concatenation of two contexts is a superset of one of the contexts\nΓ⊆Γ⌊⌋Δ : ∀(Γ Δ : Context) -> Γ ⊆ Γ ⌊⌋ Δ\nΓ⊆Γ⌊⌋Δ Γ ∙ = refl\nΓ⊆Γ⌊⌋Δ Γ (Δ , x) = drop (Γ⊆Γ⌊⌋Δ Γ Δ)\n\n-- Concatenation of two contexts is associative\n⌊⌋-assoc : ∀(Γ Δ Ξ : Context) -> (Γ ⌊⌋ Δ) ⌊⌋ Ξ ≡ Γ ⌊⌋ (Δ ⌊⌋ Ξ)\n⌊⌋-assoc Γ Δ ∙ = refl\n⌊⌋-assoc Γ Δ (Ξ , C) = cong (_, C) (⌊⌋-assoc Γ Δ Ξ)\n\n-- Concatenation of two spliced contexts is associative\n⌊A⌋-assoc : ∀(Γ Δ Ξ : Context) A B -> (Γ ⌊ A ⌋ Δ) ⌊ B ⌋ Ξ ≡ Γ ⌊ A ⌋ (Δ ⌊ B ⌋ Ξ)\n⌊A⌋-assoc Γ Δ ∙ A B = refl\n⌊A⌋-assoc Γ Δ (Ξ , C) A B = cong (_, C) (⌊A⌋-assoc Γ Δ Ξ A B)\n\n\n-- | Stabilisation\n\n-- Stabilised context is a subset of the full context\nΓˢ⊆Γ : ∀ Γ -> Γ ˢ ⊆ Γ\nΓˢ⊆Γ ∙ = refl\nΓˢ⊆Γ (Γ , A now) = drop (Γˢ⊆Γ Γ)\nΓˢ⊆Γ (Γ , A always) = keep (Γˢ⊆Γ Γ)\n\n-- Stabilised spliced context is subset of full spliced context\nΓˢ⊆Γ-mid : ∀ (Γ Γ′ : Context) {A} -> Γ ˢ ⌊ A ⌋ Γ′ ˢ ⊆ Γ ⌊ A ⌋ Γ′\nΓˢ⊆Γ-mid Γ ∙ = keep (Γˢ⊆Γ Γ)\nΓˢ⊆Γ-mid Γ (Γ′ , B now) = drop (Γˢ⊆Γ-mid Γ Γ′)\nΓˢ⊆Γ-mid Γ (Γ′ , B always) = keep (Γˢ⊆Γ-mid Γ Γ′)\n\n-- Stabilisation is idempotent\nˢ-idemp : ∀ Γ -> Γ ˢ ˢ ≡ Γ ˢ\nˢ-idemp ∙ = refl\nˢ-idemp (Γ , A now) = ˢ-idemp Γ\nˢ-idemp (Γ , A always) rewrite ˢ-idemp Γ = refl\n\n-- Stabilisation preserves concatenation\nˢ-pres-⌊⌋ : ∀ (Γ Γ′ : Context) -> (Γ ⌊⌋ Γ′) ˢ ≡ Γ ˢ ⌊⌋ Γ′ ˢ\nˢ-pres-⌊⌋ Γ ∙ = refl\nˢ-pres-⌊⌋ Γ (Γ′ , A now) = ˢ-pres-⌊⌋ Γ Γ′\nˢ-pres-⌊⌋ Γ (Γ′ , A always) rewrite ˢ-pres-⌊⌋ Γ Γ′ = refl\n\n-- Stabilisation preserves subcontext relation\nˢ-⊆-monotone : ∀{Γ Γ′} -> Γ ⊆ Γ′ -> Γ ˢ ⊆ Γ′ ˢ\nˢ-⊆-monotone refl = refl\nˢ-⊆-monotone (keep {Γ} {Γ′} {A now} s) = ˢ-⊆-monotone s\nˢ-⊆-monotone (keep {Γ} {Γ′} {A always} s) = keep (ˢ-⊆-monotone s)\nˢ-⊆-monotone (drop {Γ} {Γ′} {A now} s) = ˢ-⊆-monotone s\nˢ-⊆-monotone (drop {Γ} {Γ′} {A always} s) = drop (ˢ-⊆-monotone s)\n\n-- The context of stable variables can be stabilised\nˢ-∈-always : ∀{Γ A} -> A always ∈ Γ -> A always ∈ Γ ˢ\nˢ-∈-always {.(_ , _ always)} top = top\nˢ-∈-always {Γ , B now} (pop e) = ˢ-∈-always e\nˢ-∈-always {Γ , B always} (pop e) = pop (ˢ-∈-always e)\n\n-- | Other lemmas\n\n-- If B ∈ Γ ⌊ A ⌋ Γ′ then either B is equal to A, or B is in Γ ⌊⌋ Γ′\nvar-disjoint : ∀(Γ Γ′ : Context) {A B} -> B ∈ Γ ⌊ A ⌋ Γ′ -> (B ≡ A) ⊎ (B ∈ Γ ⌊⌋ Γ′)\nvar-disjoint Γ ∙ top = inj₁ refl\nvar-disjoint Γ ∙ (pop e) = inj₂ e\nvar-disjoint Γ (Γ′ , C) top = inj₂ top\nvar-disjoint Γ (Γ′ , C) (pop e) with var-disjoint Γ Γ′ e\nvar-disjoint Γ (Γ′ , C) (pop e) | inj₁ B≡A = inj₁ B≡A\nvar-disjoint Γ (Γ′ , C) (pop e) | inj₂ y = inj₂ (pop y)\n", "meta": {"hexsha": "6cee085a0d0a6968791a2b8bfb4b4a90554a6fd7", "size": 4863, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Syntax/Context.agda", "max_stars_repo_name": "DimaSamoz/temporal-type-systems", "max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z", "max_issues_repo_path": "src/Syntax/Context.agda", "max_issues_repo_name": "DimaSamoz/temporal-type-systems", "max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "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/Syntax/Context.agda", "max_forks_repo_name": "DimaSamoz/temporal-type-systems", "max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "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": 29.2951807229, "max_line_length": 84, "alphanum_fraction": 0.5718692165, "num_tokens": 2445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723317123102956, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.3959288376500581}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Pointwise sum\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.Sum.Relation.Binary.Pointwise where\n\nopen import Data.Product using (_,_)\nopen import Data.Sum as Sum\nopen import Data.Sum.Properties\nopen import Level using (_⊔_)\nopen import Function using (_∘_; id)\nopen import Function.Inverse using (Inverse)\nopen import Relation.Nullary\nimport Relation.Nullary.Decidable as Dec\nopen import Relation.Binary\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\n\n----------------------------------------------------------------------\n-- Definition\n\ndata Pointwise {a b c d r s}\n {A : Set a} {B : Set b} {C : Set c} {D : Set d}\n (R : REL A C r) (S : REL B D s)\n : REL (A ⊎ B) (C ⊎ D) (a ⊔ b ⊔ c ⊔ d ⊔ r ⊔ s) where\n inj₁ : ∀ {a c} → R a c → Pointwise R S (inj₁ a) (inj₁ c)\n inj₂ : ∀ {b d} → S b d → Pointwise R S (inj₂ b) (inj₂ d)\n\n----------------------------------------------------------------------\n-- Relational properties\n\nmodule _ {a₁ a₂ ℓ₁ ℓ₂} {A₁ : Set a₁} {A₂ : Set a₂}\n {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂}\n where\n\n drop-inj₁ : ∀ {x y} → Pointwise ∼₁ ∼₂ (inj₁ x) (inj₁ y) → ∼₁ x y\n drop-inj₁ (inj₁ x) = x\n\n drop-inj₂ : ∀ {x y} → Pointwise ∼₁ ∼₂ (inj₂ x) (inj₂ y) → ∼₂ x y\n drop-inj₂ (inj₂ x) = x\n\n ⊎-refl : Reflexive ∼₁ → Reflexive ∼₂ →\n Reflexive (Pointwise ∼₁ ∼₂)\n ⊎-refl refl₁ refl₂ {inj₁ x} = inj₁ refl₁\n ⊎-refl refl₁ refl₂ {inj₂ y} = inj₂ refl₂\n\n ⊎-symmetric : Symmetric ∼₁ → Symmetric ∼₂ →\n Symmetric (Pointwise ∼₁ ∼₂)\n ⊎-symmetric sym₁ sym₂ (inj₁ x) = inj₁ (sym₁ x)\n ⊎-symmetric sym₁ sym₂ (inj₂ x) = inj₂ (sym₂ x)\n\n ⊎-transitive : Transitive ∼₁ → Transitive ∼₂ →\n Transitive (Pointwise ∼₁ ∼₂)\n ⊎-transitive trans₁ trans₂ (inj₁ x) (inj₁ y) = inj₁ (trans₁ x y)\n ⊎-transitive trans₁ trans₂ (inj₂ x) (inj₂ y) = inj₂ (trans₂ x y)\n\n ⊎-asymmetric : Asymmetric ∼₁ → Asymmetric ∼₂ →\n Asymmetric (Pointwise ∼₁ ∼₂)\n ⊎-asymmetric asym₁ asym₂ (inj₁ x) = λ { (inj₁ y) → asym₁ x y }\n ⊎-asymmetric asym₁ asym₂ (inj₂ x) = λ { (inj₂ y) → asym₂ x y }\n\n ⊎-substitutive : ∀ {ℓ₃} → Substitutive ∼₁ ℓ₃ → Substitutive ∼₂ ℓ₃ →\n Substitutive (Pointwise ∼₁ ∼₂) ℓ₃\n ⊎-substitutive subst₁ subst₂ P (inj₁ x) = subst₁ (P ∘ inj₁) x\n ⊎-substitutive subst₁ subst₂ P (inj₂ x) = subst₂ (P ∘ inj₂) x\n\n ⊎-decidable : Decidable ∼₁ → Decidable ∼₂ →\n Decidable (Pointwise ∼₁ ∼₂)\n ⊎-decidable _≟₁_ _≟₂_ (inj₁ x) (inj₁ y) = Dec.map′ inj₁ drop-inj₁ (x ≟₁ y)\n ⊎-decidable _≟₁_ _≟₂_ (inj₁ x) (inj₂ y) = no λ()\n ⊎-decidable _≟₁_ _≟₂_ (inj₂ x) (inj₁ y) = no λ()\n ⊎-decidable _≟₁_ _≟₂_ (inj₂ x) (inj₂ y) = Dec.map′ inj₂ drop-inj₂ (x ≟₂ y)\n\nmodule _ {a₁ a₂} {A₁ : Set a₁} {A₂ : Set a₂}\n {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {≈₁ : Rel A₁ ℓ₂}\n {ℓ₃ ℓ₄} {∼₂ : Rel A₂ ℓ₃} {≈₂ : Rel A₂ ℓ₄} where\n\n ⊎-reflexive : ≈₁ ⇒ ∼₁ → ≈₂ ⇒ ∼₂ →\n (Pointwise ≈₁ ≈₂) ⇒ (Pointwise ∼₁ ∼₂)\n ⊎-reflexive refl₁ refl₂ (inj₁ x) = inj₁ (refl₁ x)\n ⊎-reflexive refl₁ refl₂ (inj₂ x) = inj₂ (refl₂ x)\n\n ⊎-irreflexive : Irreflexive ≈₁ ∼₁ → Irreflexive ≈₂ ∼₂ →\n Irreflexive (Pointwise ≈₁ ≈₂) (Pointwise ∼₁ ∼₂)\n ⊎-irreflexive irrefl₁ irrefl₂ (inj₁ x) (inj₁ y) = irrefl₁ x y\n ⊎-irreflexive irrefl₁ irrefl₂ (inj₂ x) (inj₂ y) = irrefl₂ x y\n\n ⊎-antisymmetric : Antisymmetric ≈₁ ∼₁ → Antisymmetric ≈₂ ∼₂ →\n Antisymmetric (Pointwise ≈₁ ≈₂) (Pointwise ∼₁ ∼₂)\n ⊎-antisymmetric antisym₁ antisym₂ (inj₁ x) (inj₁ y) = inj₁ (antisym₁ x y)\n ⊎-antisymmetric antisym₁ antisym₂ (inj₂ x) (inj₂ y) = inj₂ (antisym₂ x y)\n\n ⊎-respectsˡ : ∼₁ Respectsˡ ≈₁ → ∼₂ Respectsˡ ≈₂ →\n (Pointwise ∼₁ ∼₂) Respectsˡ (Pointwise ≈₁ ≈₂)\n ⊎-respectsˡ resp₁ resp₂ (inj₁ x) (inj₁ y) = inj₁ (resp₁ x y)\n ⊎-respectsˡ resp₁ resp₂ (inj₂ x) (inj₂ y) = inj₂ (resp₂ x y)\n\n ⊎-respectsʳ : ∼₁ Respectsʳ ≈₁ → ∼₂ Respectsʳ ≈₂ →\n (Pointwise ∼₁ ∼₂) Respectsʳ (Pointwise ≈₁ ≈₂)\n ⊎-respectsʳ resp₁ resp₂ (inj₁ x) (inj₁ y) = inj₁ (resp₁ x y)\n ⊎-respectsʳ resp₁ resp₂ (inj₂ x) (inj₂ y) = inj₂ (resp₂ x y)\n\n ⊎-respects₂ : ∼₁ Respects₂ ≈₁ → ∼₂ Respects₂ ≈₂ →\n (Pointwise ∼₁ ∼₂) Respects₂ (Pointwise ≈₁ ≈₂)\n ⊎-respects₂ (r₁ , l₁) (r₂ , l₂) = ⊎-respectsʳ r₁ r₂ , ⊎-respectsˡ l₁ l₂\n\n----------------------------------------------------------------------\n-- Structures\n\nmodule _ {a₁ a₂} {A₁ : Set a₁} {A₂ : Set a₂}\n {ℓ₁ ℓ₂} {≈₁ : Rel A₁ ℓ₁} {≈₂ : Rel A₂ ℓ₂}\n where\n\n ⊎-isEquivalence : IsEquivalence ≈₁ → IsEquivalence ≈₂ →\n IsEquivalence (Pointwise ≈₁ ≈₂)\n ⊎-isEquivalence eq₁ eq₂ = record\n { refl = ⊎-refl (refl eq₁) (refl eq₂)\n ; sym = ⊎-symmetric (sym eq₁) (sym eq₂)\n ; trans = ⊎-transitive (trans eq₁) (trans eq₂)\n }\n where open IsEquivalence\n\n ⊎-isDecEquivalence : IsDecEquivalence ≈₁ → IsDecEquivalence ≈₂ →\n IsDecEquivalence (Pointwise ≈₁ ≈₂)\n ⊎-isDecEquivalence eq₁ eq₂ = record\n { isEquivalence =\n ⊎-isEquivalence (isEquivalence eq₁) (isEquivalence eq₂)\n ; _≟_ = ⊎-decidable (_≟_ eq₁) (_≟_ eq₂)\n }\n where open IsDecEquivalence\n\nmodule _ {a₁ a₂} {A₁ : Set a₁} {A₂ : Set a₂}\n {ℓ₁ ℓ₂} {≈₁ : Rel A₁ ℓ₁} {∼₁ : Rel A₁ ℓ₂}\n {ℓ₃ ℓ₄} {≈₂ : Rel A₂ ℓ₃} {∼₂ : Rel A₂ ℓ₄} where\n\n ⊎-isPreorder : IsPreorder ≈₁ ∼₁ → IsPreorder ≈₂ ∼₂ →\n IsPreorder (Pointwise ≈₁ ≈₂) (Pointwise ∼₁ ∼₂)\n ⊎-isPreorder pre₁ pre₂ = record\n { isEquivalence =\n ⊎-isEquivalence (isEquivalence pre₁) (isEquivalence pre₂)\n ; reflexive = ⊎-reflexive (reflexive pre₁) (reflexive pre₂)\n ; trans = ⊎-transitive (trans pre₁) (trans pre₂)\n }\n where open IsPreorder\n\n ⊎-isPartialOrder : IsPartialOrder ≈₁ ∼₁ →\n IsPartialOrder ≈₂ ∼₂ →\n IsPartialOrder\n (Pointwise ≈₁ ≈₂) (Pointwise ∼₁ ∼₂)\n ⊎-isPartialOrder po₁ po₂ = record\n { isPreorder = ⊎-isPreorder (isPreorder po₁) (isPreorder po₂)\n ; antisym = ⊎-antisymmetric (antisym po₁) (antisym po₂)\n }\n where open IsPartialOrder\n\n ⊎-isStrictPartialOrder : IsStrictPartialOrder ≈₁ ∼₁ →\n IsStrictPartialOrder ≈₂ ∼₂ →\n IsStrictPartialOrder\n (Pointwise ≈₁ ≈₂) (Pointwise ∼₁ ∼₂)\n ⊎-isStrictPartialOrder spo₁ spo₂ = record\n { isEquivalence =\n ⊎-isEquivalence (isEquivalence spo₁) (isEquivalence spo₂)\n ; irrefl = ⊎-irreflexive (irrefl spo₁) (irrefl spo₂)\n ; trans = ⊎-transitive (trans spo₁) (trans spo₂)\n ; <-resp-≈ = ⊎-respects₂ (<-resp-≈ spo₁) (<-resp-≈ spo₂)\n }\n where open IsStrictPartialOrder\n\n------------------------------------------------------------------------\n-- Packages\n\nmodule _ {a b c d} where\n\n ⊎-setoid : Setoid a b → Setoid c d → Setoid _ _\n ⊎-setoid s₁ s₂ = record\n { isEquivalence =\n ⊎-isEquivalence (isEquivalence s₁) (isEquivalence s₂)\n } where open Setoid\n\n ⊎-decSetoid : DecSetoid a b → DecSetoid c d → DecSetoid _ _\n ⊎-decSetoid ds₁ ds₂ = record\n { isDecEquivalence =\n ⊎-isDecEquivalence (isDecEquivalence ds₁) (isDecEquivalence ds₂)\n } where open DecSetoid\n\n -- Some additional notation for combining setoids\n infix 4 _⊎ₛ_\n _⊎ₛ_ : Setoid a b → Setoid c d → Setoid _ _\n _⊎ₛ_ = ⊎-setoid\n\nmodule _ {a b c d e f} where\n\n ⊎-preorder : Preorder a b c → Preorder d e f → Preorder _ _ _\n ⊎-preorder p₁ p₂ = record\n { isPreorder =\n ⊎-isPreorder (isPreorder p₁) (isPreorder p₂)\n } where open Preorder\n\n ⊎-poset : Poset a b c → Poset a b c → Poset _ _ _\n ⊎-poset po₁ po₂ = record\n { isPartialOrder =\n ⊎-isPartialOrder (isPartialOrder po₁) (isPartialOrder po₂)\n } where open Poset\n\n------------------------------------------------------------------------\n-- The propositional equality setoid over products can be\n-- decomposed using Pointwise\n\nmodule _ {a b} {A : Set a} {B : Set b} where\n\n Pointwise-≡⇒≡ : (Pointwise _≡_ _≡_) ⇒ _≡_ {A = A ⊎ B}\n Pointwise-≡⇒≡ (inj₁ x) = P.cong inj₁ x\n Pointwise-≡⇒≡ (inj₂ x) = P.cong inj₂ x\n\n ≡⇒Pointwise-≡ : _≡_ {A = A ⊎ B} ⇒ (Pointwise _≡_ _≡_)\n ≡⇒Pointwise-≡ P.refl = ⊎-refl P.refl P.refl\n\nPointwise-≡↔≡ : ∀ {a b} (A : Set a) (B : Set b) →\n Inverse (P.setoid A ⊎ₛ P.setoid B)\n (P.setoid (A ⊎ B))\nPointwise-≡↔≡ _ _ = record\n { to = record { _⟨$⟩_ = id; cong = Pointwise-≡⇒≡ }\n ; from = record { _⟨$⟩_ = id; cong = ≡⇒Pointwise-≡ }\n ; inverse-of = record\n { left-inverse-of = λ _ → ⊎-refl P.refl P.refl\n ; right-inverse-of = λ _ → P.refl\n }\n }\n\n------------------------------------------------------------------------\n-- DEPRECATED NAMES\n------------------------------------------------------------------------\n-- Please use the new names as continuing support for the old names is\n-- not guaranteed.\n\n-- Version 1.0\n\nmodule _ {a b c d r s}\n {A : Set a} {B : Set b} {C : Set c} {D : Set d}\n {R : REL A C r} {S : REL B D s}\n where\n\n ₁∼₁ : ∀ {a c} → R a c → Pointwise R S (inj₁ a) (inj₁ c)\n ₁∼₁ = inj₁\n {-# WARNING_ON_USAGE ₁∼₁\n \"Warning: ₁∼₁ was deprecated in v1.0.\n Please use inj₁ in `Data.Sum.Properties` instead.\"\n #-}\n\n ₂∼₂ : ∀ {b d} → S b d → Pointwise R S (inj₂ b) (inj₂ d)\n ₂∼₂ = inj₂\n {-# WARNING_ON_USAGE ₂∼₂\n \"Warning: ₂∼₂ was deprecated in v1.0.\n Please use inj₂ in `Data.Sum.Properties` instead.\"\n #-}\n\n_⊎-≟_ : ∀ {a b} {A : Set a} {B : Set b} →\n Decidable {A = A} _≡_ → Decidable {A = B} _≡_ →\n Decidable {A = A ⊎ B} _≡_\n(dec₁ ⊎-≟ dec₂) s₁ s₂ = Dec.map′ Pointwise-≡⇒≡ ≡⇒Pointwise-≡ (s₁ ≟ s₂)\n where\n open DecSetoid (⊎-decSetoid (P.decSetoid dec₁) (P.decSetoid dec₂))\n{-# WARNING_ON_USAGE _⊎-≟_\n\"Warning: _⊎-≟_ was deprecated in v1.0.\nPlease use ≡-dec in `Data.Sum.Properties` instead.\"\n#-}\n", "meta": {"hexsha": "ace2bf50b585066bfb71d91944b00601255726b1", "size": 9995, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Sum/Relation/Binary/Pointwise.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": "test/asset/agda-stdlib-1.0/Data/Sum/Relation/Binary/Pointwise.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Data/Sum/Relation/Binary/Pointwise.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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.0185185185, "max_line_length": 76, "alphanum_fraction": 0.5422711356, "num_tokens": 3969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723316991792861, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.39592882991734935}} {"text": "\nmodule Oscar.Instance where\n\nopen import Oscar.Class.Associativity\nopen import Oscar.Class.Congruity\nopen import Oscar.Class.Equivalence\nopen import Oscar.Class.Extensionality\nopen import Oscar.Class.Injectivity\nopen import Oscar.Class.Preservativity\nopen import Oscar.Class.Reflexivity\nopen import Oscar.Class.Semifunctor\nopen import Oscar.Class.Semigroup\nopen import Oscar.Class.Symmetry\nopen import Oscar.Class.Transitivity\nopen import Oscar.Data.Equality\nopen import Oscar.Data.Fin\nopen import Oscar.Data.Nat\nopen import Oscar.Function\nopen import Oscar.Relation\n\nopen import Oscar.Data.Equality.properties\n using (≡̇-sym; ≡̇-trans)\n renaming (sym to ≡-sym\n ;trans to ≡-trans)\n\ninstance InjectivityFinSuc : ∀ {n} → Injectivity _≡_ _≡_ (Fin.suc {n}) suc\nInjectivity.injectivity InjectivityFinSuc refl = refl\n\ndata D : Set where\n d1 : Nat → D\n d2 : Nat → Nat → D\n\npattern d2l r l = d2 l r\n\ninstance InjectivityDd1 : Injectivity _≡_ _≡_ d1 d1\nInjectivity.injectivity InjectivityDd1 refl = refl\n\ninstance InjectivityD2l : ∀ {r1 r2} → Injectivity _≡_ _≡_ (d2l r1) (flip d2 r2)\nInjectivity.injectivity InjectivityD2l refl = refl\n\ninstance InjectivityoidD2l : ∀ {r1} {r2} → Injectivityoid _ _ _ _ _\nInjectivityoid.A InjectivityoidD2l = D\nInjectivityoid.B InjectivityoidD2l = D\nInjectivityoid._≋₁_ InjectivityoidD2l = _≡_\nInjectivityoid.I InjectivityoidD2l = Nat\nInjectivityoid._≋₂_ InjectivityoidD2l = _≡_\nInjectivityoid.μₗ (InjectivityoidD2l {r1} {r2}) = d2l r1\nInjectivityoid.μᵣ (InjectivityoidD2l {r1} {r2}) = flip d2 r2\nInjectivityoid.`injectivity InjectivityoidD2l refl = refl\n\ninstance InjectivityoidD2r : ∀ {r1} {r2} → Injectivityoid _ _ _ _ _\nInjectivityoid.A InjectivityoidD2r = D\nInjectivityoid.B InjectivityoidD2r = D\nInjectivityoid._≋₁_ InjectivityoidD2r = _≡_\nInjectivityoid.I InjectivityoidD2r = Nat\nInjectivityoid._≋₂_ InjectivityoidD2r = _≡_\nInjectivityoid.μₗ (InjectivityoidD2r {r1} {r2}) = d2 r1\nInjectivityoid.μᵣ (InjectivityoidD2r {r1} {r2}) = d2 r2\nInjectivityoid.`injectivity InjectivityoidD2r refl = refl\n\nopen Injectivityoid ⦃ … ⦄ using (`injectivity)\n\ninstance InjectivityD2r : ∀ {l1 l2} → Injectivity _≡_ _≡_ (d2 l1) (d2 l2)\nInjectivity.injectivity InjectivityD2r refl = refl\n\npattern d2' {l} r = d2 l r\n\ninjectivity-test : (k l m n : Nat) → (d2 k m ≡ d2 l n) → (d1 k ≡ d1 l) → Set\ninjectivity-test k l m n eq1 eq2 with injectivity {_≋₁_ = _≡_} {_≋₂_ = _≡_} {f = d2'} eq1\ninjectivity-test k l m n eq1 eq2 | ref with injectivity {_≋₁_ = _≡_} {_≋₂_ = _≡_} {f = d1} eq2\n… | ref2 = {!!}\n-- with `injectivity ⦃ ? ⦄ eq2\n-- … | ref3 = {!ref!}\n\ninstance\n\n ≡-Reflexivity : ∀\n {a} {A : Set a}\n → Reflexivity (_≡_ {A = A})\n Reflexivity.reflexivity ≡-Reflexivity = refl\n\n ≡̇-Reflexivity : ∀\n {a} {A : Set a} {b} {B : A → Set b}\n → Reflexivity (_≡̇_ {B = B})\n Reflexivity.reflexivity ≡̇-Reflexivity _ = refl\n\n ≡-flip≡-Extensionality : ∀\n {a} {A : Set a}\n → Extensionality {B = const A} _≡_ (λ ⋆ → flip _≡_ ⋆) id id\n Extensionality.extensionality ≡-flip≡-Extensionality = ≡-sym\n\n ≡̇-flip≡̇-Extensionality : ∀\n {a} {A : Set a} {b} {B : A → Set b}\n → Extensionality {B = const ((x : A) → B x)} _≡̇_ (λ ⋆ → flip _≡̇_ ⋆) id id\n Extensionality.extensionality ≡̇-flip≡̇-Extensionality = ≡̇-sym\n\n ≡-Transitivity : ∀ {a} {A : Set a} → Transitivity {A = A} _≡_\n Transitivity.transitivity ≡-Transitivity = λ ⋆ → ≡-trans ⋆\n\n ≡̇-Transitivity : ∀ {a} {A : Set a} {b} {B : A → Set b} → Transitivity {A = (x : A) → B x} _≡̇_\n Transitivity.transitivity ≡̇-Transitivity = ≡̇-trans\n\n ≡-Congruity : ∀\n {a} {A : Set a} {b} {B : Set b} {ℓ₂} {_≋₂_ : B → B → Set ℓ₂}\n ⦃ _ : Reflexivity _≋₂_ ⦄\n → Congruity (_≡_ {A = A}) _≋₂_\n Congruity.congruity ≡-Congruity μ refl = reflexivity\n\nmodule Term {𝔣} (FunctionName : Set 𝔣) where\n\n open import Oscar.Data.Term FunctionName\n open import Oscar.Data.Term.internal.SubstituteAndSubstitution FunctionName as ⋆\n\n instance\n\n ◇-≡̇-Associativity : Associativity _◇_ _≡̇_\n Associativity.associativity ◇-≡̇-Associativity = ◇-associativity\n\n ∘-≡̇-Associativity : ∀ {a} {A : Set a} {b} {B : A → Set b} → Associativity {_►_ = _⟨ B ⟩→_} (λ ⋆ → _∘_ ⋆) _≡̇_\n Associativity.associativity ∘-≡̇-Associativity _ _ _ _ = refl\n\n ◇-∘-≡̇-◃-◃-◃-Preservativity : ∀ {l m n} → Preservativity (λ ⋆ → _◇_ (m ⊸ n ∋ ⋆)) (_∘′_ {A = Term l}) _≡̇_ _◃_ _◃_ _◃_\n Preservativity.preservativity ◇-∘-≡̇-◃-◃-◃-Preservativity g f τ = symmetry (◃-associativity τ f g)\n\n ≡̇-≡̇-◃-◃-Extensionality : ∀ {m n} → Extensionality _≡̇_ (λ ⋆ → _≡̇_ ⋆) (_◃_ {m} {n}) (λ ⋆ → _◃_ ⋆)\n Extensionality.extensionality ≡̇-≡̇-◃-◃-Extensionality = ◃-extensionality\n\n semifunctor-◃ : Semifunctor _◇_ _≡̇_ (λ ⋆ → _∘_ ⋆) _≡̇_ id _◃_\n semifunctor-◃ = it\n\n open import Oscar.Data.AList FunctionName\n\n postulate\n _++_ : ∀ {m n} → AList m n → ∀ {l} → AList l m → AList l n\n sub : ∀ {m n} → AList m n → m ⊸ n\n ++-assoc : ∀ {l m n o} (ρ : AList l m) (σ : AList n _) (τ : AList o _) → ρ ++ (σ ++ τ) ≡ (ρ ++ σ) ++ τ\n subfact1 : ∀ {l m n} (ρ : AList m n) (σ : AList l m) → sub (ρ ++ σ) ≡̇ (sub ρ ◇ sub σ)\n\n instance\n\n ++-≡-Associativity : Associativity _++_ _≡_\n Associativity.associativity ++-≡-Associativity f g h = ++-assoc h g f\n\n ++-◇-sub-sub-sub : ∀ {l m n} → Preservativity (λ ⋆ → _++_ (AList m n ∋ ⋆)) (λ ⋆ → _◇_ ⋆ {l = l}) _≡̇_ sub sub sub\n Preservativity.preservativity ++-◇-sub-sub-sub = subfact1\n\n semifunctor-sub : Semifunctor _++_ _≡_ _◇_ _≡̇_ id sub\n semifunctor-sub = it\n\n-- ≡̇-extension : ∀\n-- {a} {A : Set a} {b} {B : A → Set b}\n-- {ℓ₁} {_≤₁_ : (x : A) → B x → Set ℓ₁}\n-- {c} {C : Set c}\n-- {d} {D : C → Set d}\n-- {μ₁ : A → (z : C) → D z}\n-- {μ₂ : ∀ {x} → B x → (z : C) → D z}\n-- ⦃ _ : Extensionality _≤₁_ (λ ⋆ → _≡̇_ ⋆) μ₁ μ₂ ⦄\n-- {x} {y : B x}\n-- → x ≤₁ y → μ₁ x ≡̇ μ₂ y\n-- ≡̇-extension = extension (λ ⋆ → _≡̇_ ⋆)\n\n-- test-◃-extensionality : ∀ {m n} {f g : m ⊸ n} → f ≡̇ g → f ◃_ ≡̇ g ◃_\n-- test-◃-extensionality = ≡̇-extension -- ≡̇-extension -- ⦃ ? ⦄ -- extension (λ ⋆ → _≡̇_ ⋆)\n\n-- postulate\n-- R : Set\n-- S : Set\n-- _◀_ : ∀ {m n} → m ⊸ n → R → S\n-- _◀'_ : ∀ {m n} → m ⊸ n → R → S\n-- _◆_ : ∀ {m n} → m ⊸ n → ∀ {l} → l ⊸ m → l ⊸ n\n\n-- instance ≡̇-≡̇-◀-◀'-Extensionality : ∀ {m n} → Extensionality _≡̇_ (λ ⋆ → _≡̇_ ⋆) ((m ⊸ n → _) ∋ _◀_) _◀'_\n-- instance ≡̇-≡̇-◀-◀-Extensionality : ∀ {m n} → Extensionality _≡̇_ (λ ⋆ → _≡̇_ ⋆) ((m ⊸ n → _) ∋ _◀_) _◀_\n-- instance ◆-◇-≡̇-Associativity : ∀ {k} → Associativity _◆_ (λ ⋆ → _◇_ ⋆) ((k ⊸ _ → _) ∋ _≡̇_)\n-- instance ◆-◇-≡̇-Associativity' : ∀ {k} → Associativity _◇_ (λ ⋆ → _◆_ ⋆) ((k ⊸ _ → _) ∋ _≡̇_)\n\n-- test-◀-extensionality : ∀ {m n} {f g : m ⊸ n} → f ≡̇ g → f ◀_ ≡̇ g ◀_\n-- test-◀-extensionality {m} {n} = ≡̇-extension\n-- -- extensionality {_≤₁_ = _≡̇_} {μ₁ = ((m ⊸ n → _) ∋ _◀_)} {μ₂ = _◀_}\n\n-- test-◀'-extensionality : ∀ {m n} {f g : m ⊸ n} → f ≡̇ g → f ◀_ ≡̇ g ◀'_\n-- test-◀'-extensionality = ≡̇-extension\n\n-- test-◃-associativity : ∀ {l} (t : Term l) {m} (f : l ⊸ m) {n} (g : m ⊸ n) → g ◃ (f ◃ t) ≡ (g ◇ f) ◃ t\n-- test-◃-associativity = association _◇_ _≡_\n\n-- test-◇-associativity : ∀ {k l} (f : k ⊸ l) {m} (g : l ⊸ m) {n} (h : m ⊸ n) → h ◇ (g ◇ f) ≡̇ (h ◇ g) ◇ f\n-- test-◇-associativity = association _◇_ _≡̇_\n\n-- test-◆-associativity : ∀ {k l} (f : k ⊸ l) {m} (g : l ⊸ m) {n} (h : m ⊸ n) → h ◇ (g ◇ f) ≡̇ (h ◆ g) ◇ f\n-- test-◆-associativity = association _◆_ _≡̇_\n\n-- test-◆-associativity' : ∀ {k l} (f : k ⊸ l) {m} (g : l ⊸ m) {n} (h : m ⊸ n) → h ◆ (g ◆ f) ≡̇ (h ◇ g) ◆ f\n-- test-◆-associativity' = association _◇_ _≡̇_\n", "meta": {"hexsha": "6e54c7487f5e4e4792f3a211968b528608637a63", "size": 7594, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "archive/agda-2/Oscar/Instance.agda", "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "archive/agda-2/Oscar/Instance.agda", "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_forks_repo_path": "archive/agda-2/Oscar/Instance.agda", "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9435897436, "max_line_length": 121, "alphanum_fraction": 0.5817750856, "num_tokens": 3462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723316860482762, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.3959288221846403}} {"text": "{-# OPTIONS --without-K #-}\n-- Constructions on top of exploration functions\n\nopen import Level.NP\nopen import Type hiding (★)\nopen import Type.Identities\nopen import Function.NP\nopen import Function.Extensionality\nopen import Algebra.FunctionProperties.NP\nopen import Data.Two.Base\nopen import Data.Indexed\nopen import Data.Nat.NP hiding (_⊔_)\nopen import Data.Nat.Properties\nopen import Data.Fin using (Fin) renaming (zero to fzero)\nopen import Data.Maybe.NP\nopen import Algebra\nopen import Data.Product.NP renaming (map to ×-map) hiding (first)\nopen import Data.Sum.NP renaming (map to ⊎-map)\nopen import Data.Zero using (𝟘)\nopen import Data.One using (𝟙)\nopen import Data.Tree.Binary\nimport Data.List as List\nopen List using (List; _++_)\nopen import Relation.Nullary.Decidable\nopen import Relation.Nullary.NP\nopen import Relation.Binary\nopen import Relation.Binary.Sum using (_⊎-cong_)\nopen import Relation.Binary.Product.Pointwise using (_×-cong_)\nimport Function.Related as FR\nimport Relation.Binary.PropositionalEquality.NP as ≡\nopen import HoTT\nopen Equivalences\nopen ≡ using (_≡_)\n\nopen import Explore.Core\nopen import Explore.Properties\nimport Explore.Monad as EM\n\nmodule Explore.Explorable where\n\nmodule _ {m a} {A : ★ a} where\n open EM {a} m\n gfilter-explore : ∀ {B} → (A →? B) → Explore m A → Explore m B\n gfilter-explore f eᴬ = eᴬ >>= λ x → maybe (λ η → point-explore η) empty-explore (f x)\n\n filter-explore : (A → 𝟚) → Explore m A → Explore m A\n filter-explore p = gfilter-explore λ x → [0: nothing 1: just x ] (p x)\n\n -- monoidal exploration: explore A with a monoid M\n explore-monoid : ∀ {ℓ} → Explore m A → ExploreMon m ℓ A\n explore-monoid eᴬ M = eᴬ ε _·_ where open Mon M renaming (_∙_ to _·_)\n\n explore-endo : Explore m A → Explore m A\n explore-endo eᴬ ε op f = eᴬ id _∘′_ (op ∘ f) ε\n\n explore-endo-monoid : ∀ {ℓ} → Explore m A → ExploreMon m ℓ A\n explore-endo-monoid = explore-monoid ∘ explore-endo\n\n explore-backward : Explore m A → Explore m A\n explore-backward eᴬ ε _∙_ f = eᴬ ε (flip _∙_) f\n\n -- explore-backward ∘ explore-backward = id\n -- (m : a comm monoid) → explore-backward m = explore m\n\nprivate\n module FindForward {a} {A : ★ a} (explore : Explore a A) where\n find? : Find? A\n find? = explore nothing (M?._∣_ _)\n\n first : Maybe A\n first = find? just\n\n findKey : FindKey A\n findKey pred = find? (λ x → [0: nothing 1: just x ] (pred x))\n\nmodule ExplorePlug {ℓ a} {A : ★ a} where\n record ExploreIndKit p (P : Explore ℓ A → ★ p) : ★ (a ⊔ ₛ ℓ ⊔ p) where\n constructor mk\n field\n Pε : P empty-explore\n P∙ : ∀ {e₀ e₁ : Explore ℓ A} → P e₀ → P e₁ → P (merge-explore e₀ e₁)\n Pf : ∀ x → P (point-explore x)\n\n _$kit_ : ∀ {p} {P : Explore ℓ A → ★ p} {e : Explore ℓ A}\n → ExploreInd p e → ExploreIndKit p P → P e\n _$kit_ {P = P} ind (mk Pε P∙ Pf) = ind P Pε P∙ Pf\n\n _,-kit_ : ∀ {p} {P : Explore ℓ A → ★ p}{Q : Explore ℓ A → ★ p}\n → ExploreIndKit p P → ExploreIndKit p Q → ExploreIndKit p (P ×° Q)\n Pk ,-kit Qk = mk (Pε Pk , Pε Qk)\n (λ x y → P∙ Pk (fst x) (fst y) , P∙ Qk (snd x) (snd y))\n (λ x → Pf Pk x , Pf Qk x)\n where open ExploreIndKit\n\n ExploreInd-Extra : ∀ p → Explore ℓ A → ★ _\n ExploreInd-Extra p exp =\n ∀ (Q : Explore ℓ A → ★ p)\n (Q-kit : ExploreIndKit p Q)\n (P : Explore ℓ A → ★ p)\n (Pε : P empty-explore)\n (P∙ : ∀ {e₀ e₁ : Explore ℓ A} → Q e₀ → Q e₁ → P e₀ → P e₁\n → P (merge-explore e₀ e₁))\n (Pf : ∀ x → P (point-explore x))\n → P exp\n\n to-extra : ∀ {p} {e : Explore ℓ A} → ExploreInd p e → ExploreInd-Extra p e\n to-extra e-ind Q Q-kit P Pε P∙ Pf =\n snd (e-ind (Q ×° P)\n (Qε , Pε)\n (λ { (a , b) (c , d) → Q∙ a c , P∙ a c b d })\n (λ x → Qf x , Pf x))\n where open ExploreIndKit Q-kit renaming (Pε to Qε; P∙ to Q∙; Pf to Qf)\n\n ExplorePlug : ∀ {m} (M : Monoid ℓ m) (e : Explore _ A) → ★ _\n ExplorePlug M e = ∀ f x → e∘ ε _∙_ f ∙ x ≈ e∘ x _∙_ f\n where open Mon M\n e∘ = explore-endo e\n\n plugKit : ∀ {m} (M : Monoid ℓ m) → ExploreIndKit _ (ExplorePlug M)\n plugKit M = mk (λ _ → fst identity)\n (λ Ps Ps' f x →\n trans (∙-cong (! Ps _ _) refl)\n (trans (assoc _ _ _)\n (trans (∙-cong refl (Ps' _ x)) (Ps _ _))))\n (λ x f _ → ∙-cong (snd identity (f x)) refl)\n where open Mon M\n\nmodule FromExplore\n {a} {A : ★ a}\n (explore : ∀ {ℓ} → Explore ℓ A) where\n\n module _ {ℓ} where\n with-monoid : ∀ {m} → ExploreMon ℓ m A\n with-monoid = explore-monoid explore\n\n with∘ : Explore ℓ A\n with∘ = explore-endo explore\n\n with-endo-monoid : ∀ {m} → ExploreMon ℓ m A\n with-endo-monoid = explore-endo-monoid explore\n\n backward : Explore ℓ A\n backward = explore-backward explore\n\n gfilter : ∀ {B} → (A →? B) → Explore ℓ B\n gfilter f = gfilter-explore f explore\n\n filter : (A → 𝟚) → Explore ℓ A\n filter p = filter-explore p explore\n\n sum : Sum A\n sum = explore 0 _+_\n\n Card : ℕ\n Card = sum (const 1)\n\n count : Count A\n count f = sum (𝟚▹ℕ ∘ f)\n\n product : (A → ℕ) → ℕ\n product = explore 1 _*_\n\n big-∧ big-∨ big-xor : (A → 𝟚) → 𝟚\n\n big-∧ = explore 1₂ _∧_\n and = big-∧\n all = big-∧\n\n big-∨ = explore 0₂ _∨_\n or = big-∨\n any = big-∨\n\n big-xor = explore 0₂ _xor_\n\n big-lift∧ big-lift∨ : Level → (A → 𝟚) → 𝟚\n big-lift∧ ℓ f = lower (explore {ℓ} (lift 1₂) (lift-op₂ _∧_) (lift ∘ f))\n big-lift∨ ℓ f = lower (explore {ℓ} (lift 0₂) (lift-op₂ _∨_) (lift ∘ f))\n\n bin-tree : BinTree A\n bin-tree = explore empty fork leaf\n\n list : List A\n list = explore List.[] _++_ List.[_]\n\n module FindBackward = FindForward backward\n\n findLast? : Find? A\n findLast? = FindBackward.find?\n\n last : Maybe A\n last = FindBackward.first\n\n findLastKey : FindKey A\n findLastKey = FindBackward.findKey\n\n open FindForward explore public\n\nmodule FromLookup\n {a} {A : ★ a}\n {explore : ∀ {ℓ} → Explore ℓ A}\n (lookup : ∀ {ℓ} → Lookup {ℓ} explore)\n where\n\n module CheckDec! {ℓ}{P : A → ★ ℓ}(decP : ∀ x → Dec (P x)) where\n CheckDec! : ★ _\n CheckDec! = explore (Lift 𝟙) _×_ λ x → ✓ ⌊ decP x ⌋\n\n checkDec! : {p✓ : CheckDec!} → ∀ x → P x\n checkDec! {p✓} x = toWitness (lookup p✓ x)\n\nmodule FromExploreInd\n {a} {A : ★ a}\n {explore : ∀ {ℓ} → Explore ℓ A}\n (explore-ind : ∀ {p ℓ} → ExploreInd {ℓ} p explore)\n where\n\n open FromExplore explore public\n\n module _ {ℓ p} where\n explore-mon-ext : ExploreMonExt {ℓ} p explore\n explore-mon-ext m {f} {g} f≈°g = explore-ind (λ s → s _ _ f ≈ s _ _ g) refl ∙-cong f≈°g\n where open Mon m\n\n explore-mono : ExploreMono {ℓ} p explore\n explore-mono _⊆_ z⊆ _∙-mono_ {f} {g} f⊆°g =\n explore-ind (λ e → e _ _ f ⊆ e _ _ g) z⊆ _∙-mono_ f⊆°g\n\n open ExplorePlug {ℓ} {a} {A}\n\n explore∘-plug : (M : Monoid ℓ ℓ) → ExplorePlug M explore\n explore∘-plug M = explore-ind $kit plugKit M\n\n module _ (M : Monoid ℓ ℓ)\n (open Mon M)\n (f : A → C)\n where\n explore-endo-monoid-spec′ : ∀ z → explore ε _∙_ f ∙ z ≈ explore-endo explore z _∙_ f\n explore-endo-monoid-spec′ = explore-ind (λ e → ∀ z → e ε _∙_ f ∙ z ≈ explore-endo e z _∙_ f)\n (fst identity) (λ P₀ P₁ z → trans (assoc _ _ _) (trans (∙-cong refl (P₁ z)) (P₀ _))) (λ _ _ → refl)\n\n explore-endo-monoid-spec : with-monoid M f ≈ with-endo-monoid M f\n explore-endo-monoid-spec = trans (! snd identity _) (explore-endo-monoid-spec′ ε)\n\n explore∘-ind : ∀ (M : Monoid ℓ ℓ) → BigOpMonInd ℓ M (with-endo-monoid M)\n explore∘-ind M P Pε P∙ Pf P≈ =\n snd (explore-ind (λ e → ExplorePlug M e × P (λ f → e id _∘′_ (_∙_ ∘ f) ε))\n (const (fst identity) , Pε)\n (λ {e} {s'} Ps Ps' → ExploreIndKit.P∙ (plugKit M) {e} {s'} (fst Ps) (fst Ps')\n , P≈ (λ f → fst Ps f _) (P∙ (snd Ps) (snd Ps')))\n (λ x → ExploreIndKit.Pf (plugKit M) x\n , P≈ (λ f → ! snd identity _) (Pf x)))\n where open Mon M\n\n explore-swap : ∀ {b} → ExploreSwap {ℓ} p explore {b}\n explore-swap mon {eᴮ} eᴮ-ε pf f =\n explore-ind (λ e → e _ _ (eᴮ ∘ f) ≈ eᴮ (e _ _ ∘ flip f))\n (! eᴮ-ε)\n (λ p q → trans (∙-cong p q) (! pf _ _))\n (λ _ → refl)\n where open Mon mon\n\n explore-ε : Exploreε {ℓ} p explore\n explore-ε M = explore-ind (λ e → e ε _ (const ε) ≈ ε)\n refl\n (λ x≈ε y≈ε → trans (∙-cong x≈ε y≈ε) (fst identity ε))\n (λ _ → refl)\n where open Mon M\n\n explore-hom : ExploreHom {ℓ} p explore\n explore-hom cm f g = explore-ind (λ e → e _ _ (f ∙° g) ≈ e _ _ f ∙ e _ _ g)\n (! fst identity ε)\n (λ p₀ p₁ → trans (∙-cong p₀ p₁) (∙-interchange _ _ _ _))\n (λ _ → refl)\n where open CMon cm\n\n explore-linˡ : ExploreLinˡ {ℓ} p explore\n explore-linˡ m _◎_ f k ide dist = explore-ind (λ e → e ε _∙_ (λ x → k ◎ f x) ≈ k ◎ e ε _∙_ f) (! ide) (λ x x₁ → trans (∙-cong x x₁) (! dist k _ _)) (λ x → refl)\n where open Mon m\n\n explore-linʳ : ExploreLinʳ {ℓ} p explore\n explore-linʳ m _◎_ f k ide dist = explore-ind (λ e → e ε _∙_ (λ x → f x ◎ k) ≈ e ε _∙_ f ◎ k) (! ide) (λ x x₁ → trans (∙-cong x x₁) (! dist k _ _)) (λ x → refl)\n where open Mon m\n\n module ProductMonoid\n {M : ★₀} (εₘ : M) (_⊕ₘ_ : Op₂ M)\n {N : ★₀} (εₙ : N) (_⊕ₙ_ : Op₂ N)\n where\n ε = (εₘ , εₙ)\n _⊕_ : Op₂ (M × N)\n (xₘ , xₙ) ⊕ (yₘ , yₙ) = (xₘ ⊕ₘ yₘ , xₙ ⊕ₙ yₙ)\n\n explore-product-monoid :\n ∀ fₘ fₙ → explore ε _⊕_ < fₘ , fₙ > ≡ (explore εₘ _⊕ₘ_ fₘ , explore εₙ _⊕ₙ_ fₙ)\n explore-product-monoid fₘ fₙ =\n explore-ind (λ e → e ε _⊕_ < fₘ , fₙ > ≡ (e εₘ _⊕ₘ_ fₘ , e εₙ _⊕ₙ_ fₙ)) ≡.refl (≡.ap₂ _⊕_) (λ _ → ≡.refl)\n {-\n empty-explore:\n ε ≡ (εₘ , εₙ) ✓\n point-explore (x , y):\n < fₘ , fₙ > (x , y) ≡ (fₘ x , fₙ y) ✓\n merge-explore e₀ e₁:\n e₀ ε _⊕_ < fₘ , fₙ > ⊕ e₁ ε _⊕_ < fₘ , fₙ >\n ≡\n (e₀ εₘ _⊕ₘ_ fₘ , e₀ εₙ _⊕ₙ_ fₙ) ⊕ (e₁ εₘ _⊕ₘ_ fₘ , e₁ εₙ _⊕ₙ_ fₙ)\n ≡\n (e₀ εₘ _⊕ₘ_ fₘ ⊕ e₁ εₘ _⊕ₘ_ fₘ , e₀ εₙ _⊕ₙ_ fₙ ⊕ e₁ εₙ _⊕ₙ_ fₙ)\n -}\n\n module _ {ℓ} where\n reify : Reify {ℓ} explore\n reify = explore-ind (λ eᴬ → Πᵉ eᴬ _) _ _,_\n\n unfocus : Unfocus {ℓ} explore\n unfocus = explore-ind Unfocus (λ{ (lift ()) }) (λ P Q → [ P , Q ]) (λ η → _,_ η)\n\n module _ {ℓᵣ aᵣ} {Aᵣ : A → A → ★ aᵣ}\n (Aᵣ-refl : Reflexive Aᵣ) where\n ⟦explore⟧ : ⟦Explore⟧ ℓᵣ Aᵣ (explore {ℓ}) (explore {ℓ})\n ⟦explore⟧ Mᵣ zᵣ ∙ᵣ fᵣ = explore-ind (λ e → Mᵣ (e _ _ _) (e _ _ _)) zᵣ (λ η → ∙ᵣ η) (λ η → fᵣ Aᵣ-refl)\n\n explore-ext : ExploreExt {ℓ} explore\n explore-ext ε op = explore-ind (λ e → e _ _ _ ≡ e _ _ _) ≡.refl (≡.ap₂ op)\n\n module LiftHom\n {m p}\n {S T : ★ m}\n (_≈_ : T → T → ★ p)\n (≈-refl : Reflexive _≈_)\n (≈-trans : Transitive _≈_)\n (zero : S)\n (_+_ : Op₂ S)\n (one : T)\n (_*_ : Op₂ T)\n (≈-cong-* : _*_ Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_)\n (f : S → T)\n (g : A → S)\n (hom-0-1 : f zero ≈ one)\n (hom-+-* : ∀ {x y} → (f (x + y)) ≈ (f x * f y))\n where\n\n lift-hom : f (explore zero _+_ g) ≈ explore one _*_ (f ∘ g)\n lift-hom = explore-ind (λ e → f (e zero _+_ g) ≈ e one _*_ (f ∘ g))\n hom-0-1\n (λ p q → ≈-trans hom-+-* (≈-cong-* p q))\n (λ _ → ≈-refl)\n\n module _ {ℓ} {P : A → ★_ ℓ} where\n open LiftHom {S = ★_ ℓ} {★_ ℓ} (λ A B → B → A) id _∘′_\n (Lift 𝟘) _⊎_ (Lift 𝟙) _×_\n (λ f g → ×-map f g) Dec P (const (no (λ{ (lift ()) })))\n (uncurry Dec-⊎)\n public renaming (lift-hom to lift-Dec)\n\n module FromFocus {p} (focus : Focus {p} explore) where\n Dec-Σ : ∀ {P} → Π A (Dec ∘ P) → Dec (Σ A P)\n Dec-Σ = map-Dec unfocus focus ∘ lift-Dec ∘ reify\n\n lift-hom-≡ :\n ∀ {m} {S T : ★ m}\n (zero : S)\n (_+_ : Op₂ S)\n (one : T)\n (_*_ : Op₂ T)\n (f : S → T)\n (g : A → S)\n (hom-0-1 : f zero ≡ one)\n (hom-+-* : ∀ {x y} → f (x + y) ≡ f x * f y)\n → f (explore zero _+_ g) ≡ explore one _*_ (f ∘ g)\n lift-hom-≡ z _+_ o _*_ = LiftHom.lift-hom _≡_ ≡.refl ≡.trans z _+_ o _*_ (≡.ap₂ _*_)\n\n -- Since so far S and T should have the same level, we get this mess of resizing\n -- There is a later version based on ⟦explore⟧.\n module _ (f : A → 𝟚) {{_ : UA}} where\n lift-✓all-Πᵉ : ✓ (big-lift∧ ₁ f) ≡ Πᵉ explore (✓ ∘ f)\n lift-✓all-Πᵉ = lift-hom-≡ (lift 1₂) (lift-op₂ _∧_) (Lift 𝟙) _×_ (✓ ∘ lower) (lift ∘ f) (≡.! Lift≡id) (✓-∧-× _ _)\n\n module _ (f : A → 𝟚) where\n lift-✓any↔Σᵉ : ✓ (big-lift∨ ₁ f) ↔ Σᵉ explore (✓ ∘ f)\n lift-✓any↔Σᵉ = LiftHom.lift-hom _↔_ (id , id) (zip (flip _∘′_) _∘′_)\n (lift 0₂) (lift-op₂ _∨_) (Lift 𝟘) _⊎_\n (zip ⊎-map ⊎-map) (✓ ∘ lower) (lift ∘ f)\n ((λ()) , λ{(lift())}) (✓∨-⊎ , ⊎-✓∨)\n\n sum-ind : SumInd sum\n sum-ind P P0 P+ Pf = explore-ind (λ e → P (e 0 _+_)) P0 P+ Pf\n\n sum-ext : SumExt sum\n sum-ext = explore-ext 0 _+_\n\n sum-zero : SumZero sum\n sum-zero = explore-ε ℕ+.monoid\n\n sum-hom : SumHom sum\n sum-hom = explore-hom ℕ°.+-commutativeMonoid\n\n sum-mono : SumMono sum\n sum-mono = explore-mono _≤_ z≤n _+-mono_\n\n sum-swap' : SumSwap sum\n sum-swap' {sumᴮ = sᴮ} sᴮ-0 hom f =\n sum-ind (λ s → s (sᴮ ∘ f) ≡ sᴮ (s ∘ flip f))\n (! sᴮ-0)\n (λ p q → (ap₂ _+_ p q) ∙ (! hom _ _)) (λ _ → refl)\n where open ≡\n\n sum-lin : SumLin sum\n sum-lin f zero = sum-zero\n sum-lin f (suc k) = ≡.trans (sum-hom f (λ x → k * f x)) (≡.ap₂ _+_ (≡.refl {x = sum f}) (sum-lin f k))\n\n sum-const : SumConst sum\n sum-const x = sum-ext (λ _ → ! snd ℕ°.*-identity x) ∙ sum-lin (const 1) x ∙ ℕ°.*-comm x Card\n where open ≡\n\n exploreStableUnder→sumStableUnder : ∀ {p} → StableUnder explore p → SumStableUnder sum p\n exploreStableUnder→sumStableUnder SU-p = SU-p 0 _+_\n\n count-ext : CountExt count\n count-ext f≗g = sum-ext (≡.cong 𝟚▹ℕ ∘ f≗g)\n\n sumStableUnder→countStableUnder : ∀ {p} → SumStableUnder sum p → CountStableUnder count p\n sumStableUnder→countStableUnder sumSU-p f = sumSU-p (𝟚▹ℕ ∘ f)\n\n diff-list = with-endo-monoid (List.monoid A) List.[_]\n\n {-\n list≡diff-list : list ≡ diff-list\n list≡diff-list = {!explore-endo-monoid-spec (List.monoid A) List.[_]!}\n -}\n\n lift-sum : ∀ ℓ → Sum A\n lift-sum ℓ f = lower {₀} {ℓ} (explore (lift 0) (lift-op₂ _+_) (lift ∘ f))\n\n Fin-lower-sum≡Σᵉ-Fin : ∀ {{_ : UA}}(f : A → ℕ) → Fin (lift-sum _ f) ≡ Σᵉ explore (Fin ∘ f)\n Fin-lower-sum≡Σᵉ-Fin f = lift-hom-≡ (lift 0) (lift-op₂ _+_) (Lift 𝟘) _⊎_ (Fin ∘ lower) (lift ∘ f) (Fin0≡𝟘 ∙ ! Lift≡id) (! Fin-⊎-+)\n where open ≡\n\nmodule FromTwoExploreInd\n {a} {A : ★ a}\n {eᴬ : ∀ {ℓ} → Explore ℓ A}\n (eᴬ-ind : ∀ {p ℓ} → ExploreInd {ℓ} p eᴬ)\n {b} {B : ★ b}\n {eᴮ : ∀ {ℓ} → Explore ℓ B}\n (eᴮ-ind : ∀ {p ℓ} → ExploreInd {ℓ} p eᴮ)\n where\n\n module A = FromExploreInd eᴬ-ind\n module B = FromExploreInd eᴮ-ind\n\n module _ {c ℓ}(cm : CommutativeMonoid c ℓ) where\n open CMon cm\n\n opᴬ = eᴬ ε _∙_\n opᴮ = eᴮ ε _∙_\n\n -- TODO use lift-hom\n explore-swap' : ∀ f → opᴬ (opᴮ ∘ f) ≈ opᴮ (opᴬ ∘ flip f)\n explore-swap' = A.explore-swap m (B.explore-ε m) (B.explore-hom cm)\n\n sum-swap : ∀ f → A.sum (B.sum ∘ f) ≡ B.sum (A.sum ∘ flip f)\n sum-swap = explore-swap' ℕ°.+-commutativeMonoid\n\nmodule FromTwoAdequate-sum\n {{_ : UA}}{{_ : FunExt}}\n {A}{B}\n {sumᴬ : Sum A}{sumᴮ : Sum B}\n (open Adequacy _≡_)\n (sumᴬ-adq : Adequate-sum sumᴬ)\n (sumᴮ-adq : Adequate-sum sumᴮ) where\n\n open ≡\n sumStableUnder : (p : A ≃ B)(f : B → ℕ)\n → sumᴬ (f ∘ ·→ p) ≡ sumᴮ f\n sumStableUnder p f = Fin-injective (sumᴬ-adq (f ∘ ·→ p)\n ∙ Σ-fst≃ p _\n ∙ ! sumᴮ-adq f)\n\n sumStableUnder′ : (p : A ≃ B)(f : A → ℕ)\n → sumᴬ f ≡ sumᴮ (f ∘ <– p)\n sumStableUnder′ p f = Fin-injective (sumᴬ-adq f\n ∙ Σ-fst≃′ p _\n ∙ ! sumᴮ-adq (f ∘ <– p))\n\nmodule FromAdequate-sum\n {A}\n {sum : Sum A}\n (open Adequacy _≡_)\n (sum-adq : Adequate-sum sum)\n {{_ : UA}}{{_ : FunExt}}\n where\n\n open FromTwoAdequate-sum sum-adq sum-adq public\n open ≡\n\n sum-ext : SumExt sum\n sum-ext = ap sum ∘ λ=\n\n private\n count : Count A\n count f = sum (𝟚▹ℕ ∘ f)\n\n private\n module M {p q : A → 𝟚}(same-count : count p ≡ count q) where\n private\n\n P = λ x → p x ≡ 1₂\n Q = λ x → q x ≡ 1₂\n ¬P = λ x → p x ≡ 0₂\n ¬Q = λ x → q x ≡ 0₂\n\n π : Σ A P ≡ Σ A Q\n π = ! Σ=′ _ (count-≡ p)\n ∙ ! (sum-adq (𝟚▹ℕ ∘ p))\n ∙ ap Fin same-count\n ∙ sum-adq (𝟚▹ℕ ∘ q)\n ∙ Σ=′ _ (count-≡ q)\n\n lem1 : ∀ px qx → 𝟚▹ℕ qx ≡ (𝟚▹ℕ (px ∧ qx)) + 𝟚▹ℕ (not px) * 𝟚▹ℕ qx\n lem1 1₂ 1₂ = ≡.refl\n lem1 1₂ 0₂ = ≡.refl\n lem1 0₂ 1₂ = ≡.refl\n lem1 0₂ 0₂ = ≡.refl\n\n lem2 : ∀ px qx → 𝟚▹ℕ px ≡ (𝟚▹ℕ (px ∧ qx)) + 𝟚▹ℕ px * 𝟚▹ℕ (not qx)\n lem2 1₂ 1₂ = ≡.refl\n lem2 1₂ 0₂ = ≡.refl\n lem2 0₂ 1₂ = ≡.refl\n lem2 0₂ 0₂ = ≡.refl\n\n lemma1 : ∀ px qx → (qx ≡ 1₂) ≡ (Fin (𝟚▹ℕ (px ∧ qx)) ⊎ (px ≡ 0₂ × qx ≡ 1₂))\n lemma1 px qx = ! Fin-≡-≡1₂ qx\n ∙ ap Fin (lem1 px qx)\n ∙ ! Fin-⊎-+\n ∙ ⊎= refl (! Fin-×-* ∙ ×= (Fin-≡-≡0₂ px) (Fin-≡-≡1₂ qx))\n\n lemma2 : ∀ px qx → (Fin (𝟚▹ℕ (px ∧ qx)) ⊎ (px ≡ 1₂ × qx ≡ 0₂)) ≡ (px ≡ 1₂)\n lemma2 px qx = ! ⊎= refl (! Fin-×-* ∙ ×= (Fin-≡-≡1₂ px) (Fin-≡-≡0₂ qx)) ∙ Fin-⊎-+ ∙ ap Fin (! lem2 px qx) ∙ Fin-≡-≡1₂ px\n\n π' : (Fin (sum (λ x → 𝟚▹ℕ (p x ∧ q x))) ⊎ Σ A (λ x → P x × ¬Q x))\n ≡ (Fin (sum (λ x → 𝟚▹ℕ (p x ∧ q x))) ⊎ Σ A (λ x → ¬P x × Q x))\n π' = ⊎= (sum-adq (λ x → 𝟚▹ℕ (p x ∧ q x))) refl\n ∙ ! Σ⊎-split\n ∙ Σ=′ _ (λ x → lemma2 (p x) (q x))\n ∙ π\n ∙ Σ=′ _ (λ x → lemma1 (p x) (q x))\n ∙ Σ⊎-split\n ∙ ! ⊎= (sum-adq (λ x → 𝟚▹ℕ (p x ∧ q x))) refl\n\n π'' : Σ A (P ×° ¬Q) ≡ Σ A (¬P ×° Q)\n π'' = Fin⊎-injective (sum (λ x → 𝟚▹ℕ (p x ∧ q x))) π'\n\n open EquivalentSubsets π'' public\n\n same-count→iso : ∀{p q : A → 𝟚}(same-count : count p ≡ count q) → p ≡ q ∘ M.π {p} {q} same-count\n same-count→iso {p} {q} sc = M.prop {p} {q} sc\n\nmodule From⟦Explore⟧\n {-a-} {A : ★₀ {- a-}}\n {explore : ∀ {ℓ} → Explore ℓ A}\n (⟦explore⟧ : ∀ {ℓ₀ ℓ₁} ℓᵣ → ⟦Explore⟧ {ℓ₀} {ℓ₁} ℓᵣ _≡_ explore explore)\n {{_ : UA}}\n where\n open FromExplore explore\n\n module AlsoInFromExploreInd\n {ℓ}(M : Monoid ℓ ℓ)\n (open Mon M)\n (f : A → C)\n where\n explore-endo-monoid-spec′ : ∀ z → explore ε _∙_ f ∙ z ≈ explore-endo explore z _∙_ f\n explore-endo-monoid-spec′ = ⟦explore⟧ ₀ {C} {C → C}\n (λ r s → ∀ z → r ∙ z ≈ s z)\n (fst identity)\n (λ P₀ P₁ z → trans (assoc _ _ _) (trans (∙-cong refl (P₁ z)) (P₀ _)))\n (λ xᵣ _ → ∙-cong (reflexive (≡.ap f xᵣ)) refl)\n\n explore-endo-monoid-spec : with-monoid M f ≈ with-endo-monoid M f\n explore-endo-monoid-spec = trans (! snd identity _) (explore-endo-monoid-spec′ ε)\n\n open ≡\n module _ (f : A → ℕ) where\n sum⇒Σᵉ : Fin (explore 0 _+_ f) ≡ explore (Lift 𝟘) _⊎_ (Fin ∘ f)\n sum⇒Σᵉ = ⟦explore⟧ {₀} {₁} ₁\n (λ n X → Fin n ≡ X)\n (Fin0≡𝟘 ∙ ! Lift≡id)\n (λ p q → ! Fin-⊎-+ ∙ ⊎= p q)\n (ap (Fin ∘ f))\n\n product⇒Πᵉ : Fin (explore 1 _*_ f) ≡ explore (Lift 𝟙) _×_ (Fin ∘ f)\n product⇒Πᵉ = ⟦explore⟧ {₀} {₁} ₁\n (λ n X → Fin n ≡ X)\n (Fin1≡𝟙 ∙ ! Lift≡id)\n (λ p q → ! Fin-×-* ∙ ×= p q)\n (ap (Fin ∘ f))\n\n module _ (f : A → 𝟚) where\n ✓all-Πᵉ : ✓ (all f) ≡ Πᵉ explore (✓ ∘ f)\n ✓all-Πᵉ = ⟦explore⟧ {₀} {₁} ₁\n (λ b X → ✓ b ≡ X)\n (! Lift≡id)\n (λ p q → ✓-∧-× _ _ ∙ ×= p q)\n (ap (✓ ∘ f))\n\n ✓any→Σᵉ : ✓ (any f) → Σᵉ explore (✓ ∘ f)\n ✓any→Σᵉ p = ⟦explore⟧ {₀} {ₛ ₀} ₁\n (λ b (X : ★₀) → Lift (✓ b) → X)\n (λ x → lift (lower x))\n (λ { {0₂} {x₁} xᵣ {y₀} {y₁} yᵣ zᵣ → inr (yᵣ zᵣ)\n ; {1₂} {x₁} xᵣ {y₀} {y₁} yᵣ zᵣ → inl (xᵣ _) })\n (λ xᵣ x → tr (✓ ∘ f) xᵣ (lower x)) (lift p)\n\n module FromAdequate-Σᵉ\n (adequate-Σᵉ : ∀ {ℓ} → Adequate-Σ {ℓ} (Σᵉ explore))\n where\n open Adequacy\n\n adequate-sum : Adequate-sum _≡_ sum\n adequate-sum f = sum⇒Σᵉ f ∙ adequate-Σᵉ (Fin ∘ f)\n\n open FromAdequate-sum adequate-sum public\n\n adequate-any : Adequate-any -→- any\n adequate-any f e = coe (adequate-Σᵉ (✓ ∘ f)) (✓any→Σᵉ f e)\n\n module FromAdequate-Πᵉ\n (adequate-Πᵉ : ∀ {ℓ} → Adequate-Π {ℓ} (Πᵉ explore))\n where\n open Adequacy\n\n adequate-product : Adequate-product _≡_ product\n adequate-product f = product⇒Πᵉ f ∙ adequate-Πᵉ (Fin ∘ f)\n\n adequate-all : Adequate-all _≡_ all\n adequate-all f = ✓all-Πᵉ f ∙ adequate-Πᵉ _\n\n check! : (f : A → 𝟚) {pf : ✓ (all f)} → (∀ x → ✓ (f x))\n check! f {pf} = coe (adequate-all f) pf\n\n{-\nmodule ExplorableRecord where\n record Explorable A : ★₁ where\n constructor mk\n field\n explore : Explore₀ A\n explore-ind : ExploreInd₀ explore\n\n open FromExploreInd explore-ind\n field\n adequate-sum : Adequate-sum sum\n -- adequate-product : AdequateProduct product\n\n open FromExploreInd explore-ind public\n\n open Explorable public\n\n ExploreForFun : ★₀ → ★₁\n ExploreForFun A = ∀ {X} → Explorable X → Explorable (A → X)\n\n record Funable A : ★₂ where\n constructor _,_\n field\n explorable : Explorable A\n negative : ExploreForFun A\n\n module DistFun {A} (μA : Explorable A)\n (μA→ : ExploreForFun A)\n {B} (μB : Explorable B){X}\n (_≈_ : X → X → ★ ₀)\n (0′ : X)\n (_+_ : X → X → X)\n (_*_ : X → X → X) where\n\n Σᴮ = explore μB 0′ _+_\n Π' = explore μA 0′ _*_\n Σ' = explore (μA→ μB) 0′ _+_\n\n DistFun = ∀ f → Π' (Σᴮ ∘ f) ≈ Σ' (Π' ∘ _ˢ_ f)\n\n DistFun : ∀ {A} → Explorable A → ExploreForFun A → ★₁\n DistFun μA μA→ = ∀ {B} (μB : Explorable B) c → let open CMon {₀}{₀} c in\n ∀ _*_ → Zero _≈_ ε _*_ → _DistributesOver_ _≈_ _*_ _∙_ → _*_ Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_\n → DistFun.DistFun μA μA→ μB _≈_ ε _∙_ _*_\n\n DistFunable : ∀ {A} → Funable A → ★₁\n DistFunable (μA , μA→) = DistFun μA μA→\n\n module _ {{_ : UA}}{{_ : FunExt}} where\n μ-iso : ∀ {A B} → (A ≃ B) → Explorable A → Explorable B\n μ-iso {A}{B} A≃B μA = mk (EM.map _ A→B (explore μA)) (EM.map-ind _ A→B (explore-ind μA)) ade\n where\n open ≡\n A→B = –> A≃B\n ade = λ f → adequate-sum μA (f ∘ A→B) ∙ Σ-fst≃ A≃B _\n\n -- I guess this could be more general\n μ-iso-preserve : ∀ {A B} (A≃B : A ≃ B) f (μA : Explorable A) → sum μA f ≡ sum (μ-iso A≃B μA) (f ∘ <– A≃B)\n μ-iso-preserve A≃B f μA = sum-ext μA (λ x → ap f (! (<–-inv-l A≃B x)))\n where open ≡\n\n {-\n μLift : ∀ {A} → Explorable A → Explorable (Lift A)\n μLift = μ-iso {!(! Lift↔id)!}\n where open ≡\n -}\n-- -}\n-- -}\n-- -}\n-- -}\n", "meta": {"hexsha": "e0bf0cec777158bbba22ff7e33e5aab70750c16a", "size": 23939, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lib/Explore/Explorable.agda", "max_stars_repo_name": "crypto-agda/explore", "max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z", "max_issues_repo_path": "lib/Explore/Explorable.agda", "max_issues_repo_name": "crypto-agda/explore", "max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z", "max_forks_repo_path": "lib/Explore/Explorable.agda", "max_forks_repo_name": "crypto-agda/explore", "max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "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": 33.8121468927, "max_line_length": 164, "alphanum_fraction": 0.4935878692, "num_tokens": 9941, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191460821871, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.3958645287583013}} {"text": "open import MJ.Types as Types\nimport MJ.Classtable.Core as Core\n\nmodule MJ.Semantics.Environments {c}(Ct : Core.Classtable c) where\n\nopen import Prelude\nopen import Data.List\nopen import Data.List.Membership.Propositional\nopen import Data.List.Relation.Unary.All as All\nopen import Data.List.Relation.Unary.Any\n\nopen import MJ.LexicalScope c\n\n{-\nWe equip MJ with mutable lexical environments.\nWe could choose to model this directly, moving the environment from\nthe Reader part of the evaluation monad to the State part.\n\nInstead we choose to keep our environments immutable and model\nmutability of the values in it by an indirection via the mutable store.\nThis greatly simplifies the treatment of environments in the interpreter\nand keeps the representation lightweight, even though we support block scopes.\n-}\nEnv : ∀ (Γ : Ctx)(W : World c) → Set\nEnv Γ W = All (λ a → vty a ∈ W) Γ\n\n_⊕_ : ∀ {Γ W a} → Env Γ W → (vty a) ∈ W → Env (Γ +local a) W\n_⊕_ E v = v ∷ E\n\nopen import Data.List.Any\ngetvar : ∀ {Γ W a} → Var Γ a → Env Γ W → vty a ∈ W\ngetvar px E = All.lookup E px\n", "meta": {"hexsha": "2c20d49f8964ed234f49550d0fa3b0490547b5c9", "size": 1068, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/MJ/Semantics/Environments.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/Semantics/Environments.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/Semantics/Environments.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": 32.3636363636, "max_line_length": 78, "alphanum_fraction": 0.7406367041, "num_tokens": 302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7090191337850933, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.3958645218925019}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Properties related to AllPairs\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.List.Relation.Unary.AllPairs.Properties where\n\nopen import Data.List hiding (any)\nopen import Data.List.Relation.Unary.All as All using (All; []; _∷_)\nimport Data.List.Relation.Unary.All.Properties as All\nopen import Data.List.Relation.Unary.AllPairs as AllPairs using (AllPairs; []; _∷_)\nopen import Data.Bool.Base using (true; false)\nopen import Data.Fin.Base using (Fin)\nopen import Data.Fin.Properties using (suc-injective)\nopen import Data.Nat.Base using (zero; suc; _<_; z≤n; s≤s)\nopen import Data.Nat.Properties using (≤-refl; ≤-step)\nopen import Function using (_∘_; flip)\nopen import Relation.Binary using (Rel; DecSetoid)\nopen import Relation.Binary.PropositionalEquality using (_≢_)\nopen import Relation.Unary using (Pred; Decidable)\nopen import Relation.Nullary using (does)\n\n------------------------------------------------------------------------\n-- Introduction (⁺) and elimination (⁻) rules for list operations\n------------------------------------------------------------------------\n-- map\n\nmodule _ {a b ℓ} {A : Set a} {B : Set b} {R : Rel A ℓ} {f : B → A} where\n\n map⁺ : ∀ {xs} → AllPairs (λ x y → R (f x) (f y)) xs →\n AllPairs R (map f xs)\n map⁺ [] = []\n map⁺ (x∉xs ∷ xs!) = All.map⁺ x∉xs ∷ map⁺ xs!\n\n------------------------------------------------------------------------\n-- ++\n\nmodule _ {a ℓ} {A : Set a} {R : Rel A ℓ} where\n\n ++⁺ : ∀ {xs ys} → AllPairs R xs → AllPairs R ys →\n All (λ x → All (R x) ys) xs → AllPairs R (xs ++ ys)\n ++⁺ [] Rys _ = Rys\n ++⁺ (px ∷ Rxs) Rys (Rxys ∷ Rxsys) = All.++⁺ px Rxys ∷ ++⁺ Rxs Rys Rxsys\n\n------------------------------------------------------------------------\n-- concat\n\nmodule _ {a ℓ} {A : Set a} {R : Rel A ℓ} where\n\n concat⁺ : ∀ {xss} → All (AllPairs R) xss →\n AllPairs (λ xs ys → All (λ x → All (R x) ys) xs) xss →\n AllPairs R (concat xss)\n concat⁺ [] [] = []\n concat⁺ (pxs ∷ pxss) (Rxsxss ∷ Rxss) = ++⁺ pxs (concat⁺ pxss Rxss)\n (All.map All.concat⁺ (All.All-swap Rxsxss))\n\n------------------------------------------------------------------------\n-- take and drop\n\nmodule _ {a ℓ} {A : Set a} {R : Rel A ℓ} where\n\n take⁺ : ∀ {xs} n → AllPairs R xs → AllPairs R (take n xs)\n take⁺ zero pxs = []\n take⁺ (suc n) [] = []\n take⁺ (suc n) (px ∷ pxs) = All.take⁺ n px ∷ take⁺ n pxs\n\n drop⁺ : ∀ {xs} n → AllPairs R xs → AllPairs R (drop n xs)\n drop⁺ zero pxs = pxs\n drop⁺ (suc n) [] = []\n drop⁺ (suc n) (_ ∷ pxs) = drop⁺ n pxs\n\n------------------------------------------------------------------------\n-- applyUpTo\n\nmodule _ {a ℓ} {A : Set a} {R : Rel A ℓ} where\n\n applyUpTo⁺₁ : ∀ f n → (∀ {i j} → i < j → j < n → R (f i) (f j)) → AllPairs R (applyUpTo f n)\n applyUpTo⁺₁ f zero Rf = []\n applyUpTo⁺₁ f (suc n) Rf =\n All.applyUpTo⁺₁ _ n (Rf (s≤s z≤n) ∘ s≤s) ∷\n applyUpTo⁺₁ _ n (λ i≤j j>>_ : ∀ {i : Size} {ℓ₁ ℓ₂} {a b c Cl : Set ℓ₂} {C : Container ℓ₁} {cl : FStream C Cl} → ClSF {i} C cl a b → ClSF {i} C cl b c → ClSF {i} C cl a c\n_>>>_ = {!!}\n\n-- runClock : ∀ {i : Size} {ℓ₁ ℓ₂} {Cl B : Set ℓ₂} {C : Container ℓ₁} → (cl : FStream C Cl) → ClSF {i} C cl A B → FStream {i} C A -> FStream {i} C B \nrunClock : ∀ {i : Size} {ℓ₁ ℓ₂} {A B Cl : Set ℓ₂} {C : Container ℓ₁} → (cl : FStream C Cl) → ClSF {i} C cl A B → FStream {i} C A -> FStream {i} C B \nrunClock = {!!}\n", "meta": {"hexsha": "5f21abbea22dd6db9bdcd9d81f6b520f120cf4f8", "size": 1008, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "FStream/Clocked.agda", "max_stars_repo_name": "Aerate/condatis", "max_stars_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-13T16:52:28.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-13T16:52:28.000Z", "max_issues_repo_path": "FStream/Clocked.agda", "max_issues_repo_name": "zimbatm/condatis", "max_issues_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-06-03T20:02:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-01T16:52:07.000Z", "max_forks_repo_path": "FStream/Clocked.agda", "max_forks_repo_name": "zimbatm/condatis", "max_forks_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-13T15:56:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-13T15:56:38.000Z", "avg_line_length": 40.32, "max_line_length": 149, "alphanum_fraction": 0.5525793651, "num_tokens": 456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7853085808877581, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.39572183967877683}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import Base\n\nmodule Algebra.FreeGroupAsReducedWords {i} (A : Set i) (eq : has-dec-eq A) where\n\nA-is-set : is-set A\nA-is-set = dec-eq-is-set eq\n\ndata word : Set i where\n ε : word\n _∷_ : A → word → word\n _′∷_ : A → word → word\n\nis-reduced : word → Set i\nis-reduced ε = unit\nis-reduced (x ∷ ε) = unit\nis-reduced (x ∷ (y ∷ w)) = is-reduced (y ∷ w)\nis-reduced (x ∷ (y ′∷ w)) = (x ≢ y) × is-reduced (y ′∷ w)\nis-reduced (x ′∷ ε) = unit\nis-reduced (x ′∷ (y ∷ w)) = (x ≢ y) × is-reduced (y ∷ w)\nis-reduced (x ′∷ (y ′∷ w)) = is-reduced (y ′∷ w)\n\nis-reduced-is-prop : (w : word) → is-prop (is-reduced w)\nis-reduced-is-prop ε = unit-is-prop\nis-reduced-is-prop (x ∷ ε) = unit-is-prop\nis-reduced-is-prop (x ∷ (y ∷ w)) = is-reduced-is-prop (y ∷ w)\nis-reduced-is-prop (x ∷ (y ′∷ w)) =\n ×-is-truncated _ (Π-is-truncated _ (λ _ → λ ())) (is-reduced-is-prop (y ′∷ w))\nis-reduced-is-prop (x ′∷ ε) = unit-is-prop\nis-reduced-is-prop (x ′∷ (y ∷ w)) =\n ×-is-truncated _ (Π-is-truncated _ (λ _ → λ ())) (is-reduced-is-prop (y ∷ w))\nis-reduced-is-prop (x ′∷ (y ′∷ w)) = is-reduced-is-prop (y ′∷ w)\n\nreduced-word : Set i\nreduced-word = Σ word is-reduced\n\nword-total-path : {x y : A} (p : x ≡ y) {v w : word} (q : v ≡ w)\n → (x ∷ v ≡ y ∷ w)\nword-total-path refl refl = refl\n\nword'-total-path : {x y : A} (p : x ≡ y) {v w : word} (q : v ≡ w)\n → (x ′∷ v ≡ y ′∷ w)\nword'-total-path refl refl = refl\n\n-- The following six functions prove things like if [x ∷ v ≡ y ∷ w],\n-- then [x ≡ y].\n-- This is not as easy as it sounds, you cannot directly induct on the equality\n-- (because [x ∷ v] is not a general element of type word), so you have to\n-- extract the head, but it’s not always possible…\n\nword-comp-path-type : (v w : word) → Set i\nword-comp-path-type ε ε = unit\nword-comp-path-type ε (y ∷ w) = ⊥\nword-comp-path-type ε (y ′∷ w) = ⊥\nword-comp-path-type (x ∷ v) ε = ⊥\nword-comp-path-type (x ∷ v) (y ∷ w) = (x ≡ y) × (v ≡ w)\nword-comp-path-type (x ∷ v) (y ′∷ w) = ⊥\nword-comp-path-type (x ′∷ v) ε = ⊥\nword-comp-path-type (x ′∷ v) (y ∷ w) = ⊥\nword-comp-path-type (x ′∷ v) (y ′∷ w) = (x ≡ y) × (v ≡ w)\n\nword-comp-path : {v w : word} (p : v ≡ w) → word-comp-path-type v w\nword-comp-path {v = ε} refl = tt\nword-comp-path {v = x ∷ v} refl = (refl , refl)\nword-comp-path {v = x ′∷ v} refl = (refl , refl)\n\nword-base-path : {x y : A} {v w : word} (p : x ∷ v ≡ y ∷ w) → x ≡ y\nword-base-path p = π₁ (word-comp-path p)\n\nword-fiber-path : {x y : A} {v w : word} (p : x ∷ v ≡ y ∷ w) → v ≡ w\nword-fiber-path p = π₂ (word-comp-path p)\n\nword'-base-path : {x y : A} {v w : word} (p : x ′∷ v ≡ y ′∷ w) → x ≡ y\nword'-base-path p = π₁ (word-comp-path p)\n\nword'-fiber-path : {x y : A} {v w : word} (p : x ′∷ v ≡ y ′∷ w) → v ≡ w\nword'-fiber-path p = π₂ (word-comp-path p)\n\n-- This one goes to Set and is used to prove that the constructors of [word] are\n-- disjoint\nword-cst-dis : (v w : word) → Set\nword-cst-dis ε ε = unit\nword-cst-dis ε (y ∷ w) = ⊥\nword-cst-dis ε (y ′∷ w) = ⊥\nword-cst-dis (x ∷ v) ε = ⊥\nword-cst-dis (x ∷ v) (y ∷ w) = unit\nword-cst-dis (x ∷ v) (y ′∷ w) = ⊥\nword-cst-dis (x ′∷ v) ε = ⊥\nword-cst-dis (x ′∷ v) (y ∷ w) = ⊥\nword-cst-dis (x ′∷ v) (y ′∷ w) = unit\n\nword-has-dec-eq : has-dec-eq word\nword-has-dec-eq ε ε = inl refl\nword-has-dec-eq ε (x ∷ w) = inr (λ p → transport (word-cst-dis ε) p tt)\nword-has-dec-eq ε (x ′∷ w) = inr (λ p → transport (word-cst-dis ε) p tt)\nword-has-dec-eq (x ∷ v) ε = inr (λ p → transport (word-cst-dis (x ∷ v)) p tt)\nword-has-dec-eq (x ∷ v) (y ∷ w) with (eq x y)\nword-has-dec-eq (x ∷ v) (y ∷ w) | inl x≡y with (word-has-dec-eq v w)\nword-has-dec-eq (x ∷ v) (y ∷ w) | inl x≡y | inl v≡w =\n inl (word-total-path x≡y v≡w)\nword-has-dec-eq (x ∷ v) (y ∷ w) | inl x≡y | inr v≢w =\n inr (λ p → v≢w (word-fiber-path p))\nword-has-dec-eq (x ∷ v) (y ∷ w) | inr x≢y = inr (λ p → x≢y (word-base-path p))\nword-has-dec-eq (x ∷ v) (y ′∷ w) =\n inr (λ p → transport (word-cst-dis (x ∷ v)) p tt)\nword-has-dec-eq (x ′∷ v) ε = inr (λ p → transport (word-cst-dis (x ′∷ v)) p tt)\nword-has-dec-eq (x ′∷ v) (y ∷ w) =\n inr (λ p → transport (word-cst-dis (x ′∷ v)) p tt)\nword-has-dec-eq (x ′∷ v) (y ′∷ w) with (eq x y)\nword-has-dec-eq (x ′∷ v) (y ′∷ w) | inl x≡y with (word-has-dec-eq v w)\nword-has-dec-eq (x ′∷ v) (y ′∷ w) | inl x≡y | inl v≡w =\n inl (word'-total-path x≡y v≡w)\nword-has-dec-eq (x ′∷ v) (y ′∷ w) | inl x≡y | inr v≢w =\n inr (λ p → v≢w (word'-fiber-path p))\nword-has-dec-eq (x ′∷ v) (y ′∷ w) | inr x≢y =\n inr (λ p → x≢y (word'-base-path p))\n\nword-is-set : is-set word\nword-is-set = dec-eq-is-set word-has-dec-eq\n\nabstract\n reduced-is-set : is-set reduced-word\n reduced-is-set =\n subtype-truncated-S-is-truncated-S _ word-is-set is-reduced-is-prop\n\ntail-is-reduced : (x : A) (w : word) (r : is-reduced (x ∷ w)) → is-reduced w\ntail-is-reduced x ε red = tt\ntail-is-reduced x (y ∷ w) red = red\ntail-is-reduced x (y ′∷ w) red = π₂ red\n\ntail'-is-reduced : (x : A) (w : word) (r : is-reduced (x ′∷ w)) → is-reduced w\ntail'-is-reduced x ε red = tt\ntail'-is-reduced x (y ∷ w) red = π₂ red\ntail'-is-reduced x (y ′∷ w) red = red\n\nimport Algebra.FreeGroup as F\nopen F A\nimport Algebra.FreeGroupProps as Fp\nopen Fp A\n\nreduced-to-freegroup : reduced-word → freegroup\nreduced-to-freegroup (ε , _) = e\nreduced-to-freegroup ((x ∷ w) , r) =\n x · reduced-to-freegroup (w , tail-is-reduced x w r)\nreduced-to-freegroup ((x ′∷ w) , r) =\n x ⁻¹· reduced-to-freegroup (w , tail'-is-reduced x w r)\n\nmul-reduce : A → reduced-word → reduced-word\nmul-reduce x (ε , red) = ((x ∷ ε) , tt)\nmul-reduce x ((y ∷ w) , red) = ((x ∷ (y ∷ w)) , red)\nmul-reduce x ((y ′∷ w) , red) with (eq x y)\nmul-reduce x ((y ′∷ w) , red) | inl equal = (w , tail'-is-reduced y w red)\nmul-reduce x ((y ′∷ w) , red) | inr different =\n ((x ∷ (y ′∷ w)) , (different , red))\n\nmul'-reduce : A → reduced-word → reduced-word\nmul'-reduce x (ε , red) = ((x ′∷ ε) , tt)\nmul'-reduce x ((y ∷ w) , red) with (eq x y)\nmul'-reduce x ((y ∷ w) , red) | inl equal = (w , tail-is-reduced y w red)\nmul'-reduce x ((y ∷ w) , red) | inr different =\n ((x ′∷ (y ∷ w)) , (different , red))\nmul'-reduce x ((y ′∷ w) , red) = (x ′∷ (y ′∷ w)) , red\n\nabstract\n mul-mul'-reduce : (x : A) (w : reduced-word)\n → mul-reduce x (mul'-reduce x w) ≡ w\n mul-mul'-reduce x (ε , red) with (eq x x)\n mul-mul'-reduce x (ε , red) | inl obvious = refl\n mul-mul'-reduce x (ε , red) | inr absurd = abort-nondep (absurd refl)\n mul-mul'-reduce x ((y ∷ w) , red) with (eq x y)\n mul-mul'-reduce x ((y ∷ ε) , red) | inl equal = ap _ equal\n mul-mul'-reduce x ((y ∷ (z ∷ w)) , red) | inl equal = ap _ equal\n mul-mul'-reduce x ((y ∷ (z ′∷ w)) , red) | inl equal with (eq x z)\n mul-mul'-reduce x ((y ∷ (z ′∷ w)) , red) | inl equal | inl absurd =\n abort-nondep (π₁ red (! equal ∘ absurd))\n mul-mul'-reduce x ((y ∷ (z ′∷ w)) , red) | inl equal | inr obvious =\n Σ-eq (ap _ equal) (π₁ (is-reduced-is-prop (y ∷ (z ′∷ w)) _ _))\n mul-mul'-reduce x ((y ∷ w) , red) | inr different with (eq x x)\n mul-mul'-reduce x ((y ∷ w) , red) | inr different | inl obvious = refl\n mul-mul'-reduce x ((y ∷ w) , red) | inr different | inr absurd =\n abort-nondep (absurd refl)\n mul-mul'-reduce x ((y ′∷ w) , red) with (eq x x)\n mul-mul'-reduce x ((y ′∷ w) , red) | inl obvious = refl\n mul-mul'-reduce x ((y ′∷ w) , red) | inr absurd =\n abort-nondep (absurd refl)\n\nabstract\n mul'-mul-reduce : (x : A) (w : reduced-word)\n → mul'-reduce x (mul-reduce x w) ≡ w\n mul'-mul-reduce x (ε , red) with (eq x x)\n mul'-mul-reduce x (ε , red) | inl obvious = refl\n mul'-mul-reduce x (ε , red) | inr absurd = abort-nondep (absurd refl)\n mul'-mul-reduce x ((y ′∷ w) , red) with (eq x y)\n mul'-mul-reduce x ((y ′∷ ε) , red) | inl equal = ap _ equal\n mul'-mul-reduce x ((y ′∷ (z ′∷ w)) , red) | inl equal = ap _ equal\n mul'-mul-reduce x ((y ′∷ (z ∷ w)) , red) | inl equal with (eq x z)\n mul'-mul-reduce x ((y ′∷ (z ∷ w)) , red) | inl equal | inl absurd =\n abort-nondep (π₁ red (! equal ∘ absurd))\n mul'-mul-reduce x ((y ′∷ (z ∷ w)) , red) | inl equal | inr obvious =\n Σ-eq (ap _ equal) (π₁ (is-reduced-is-prop (y ′∷ (z ∷ w)) _ _))\n mul'-mul-reduce x ((y ′∷ w) , red) | inr different with (eq x x)\n mul'-mul-reduce x ((y ′∷ w) , red) | inr different | inl obvious = refl\n mul'-mul-reduce x ((y ′∷ w) , red) | inr different | inr absurd =\n abort-nondep (absurd refl)\n mul'-mul-reduce x ((y ∷ w) , red) with (eq x x)\n mul'-mul-reduce x ((y ∷ w) , red) | inl obvious = refl\n mul'-mul-reduce x ((y ∷ w) , red) | inr absurd =\n abort-nondep (absurd refl)\n\nfreegroup-to-reduced : freegroup → reduced-word\nfreegroup-to-reduced = freegroup-rec-nondep reduced-word\n (ε , tt)\n mul-reduce\n mul'-reduce\n mul-mul'-reduce\n mul'-mul-reduce\n reduced-is-set\n\nabstract\n mul-reduce-reduced : (x : A) (w : word) (red : is-reduced (x ∷ w))\n → mul-reduce x (w , tail-is-reduced x w red) ≡ ((x ∷ w) , red)\n mul-reduce-reduced x ε red = refl\n mul-reduce-reduced x (y ∷ w) red = refl\n mul-reduce-reduced x (y ′∷ w) red with (eq x y)\n mul-reduce-reduced x (y ′∷ w) red | inl absurd = abort-nondep (π₁ red absurd)\n mul-reduce-reduced x (y ′∷ w) red | inr obvious =\n Σ-eq refl (π₁ (is-reduced-is-prop (x ∷ (y ′∷ w)) _ _))\n\nabstract\n mul'-reduce-reduced : (x : A) (w : word) (red : is-reduced (x ′∷ w))\n → mul'-reduce x (w , tail'-is-reduced x w red) ≡ ((x ′∷ w) , red)\n mul'-reduce-reduced x ε red = refl\n mul'-reduce-reduced x (y ∷ w) red with (eq x y)\n mul'-reduce-reduced x (y ∷ w) red | inl absurd = abort-nondep (π₁ red absurd)\n mul'-reduce-reduced x (y ∷ w) red | inr obvious =\n Σ-eq refl (π₁ (is-reduced-is-prop (x ′∷ (y ∷ w)) _ _))\n mul'-reduce-reduced x (y ′∷ w) red = refl\n\ninv₁ : (w : reduced-word) → freegroup-to-reduced (reduced-to-freegroup w) ≡ w\ninv₁ (ε , red) = refl\ninv₁ ((x ∷ w) , red) = ap (mul-reduce x) (inv₁ (w , tail-is-reduced x w red))\n ∘ mul-reduce-reduced x w red\ninv₁ ((x ′∷ w) , red) =\n ap (mul'-reduce x) (inv₁ (w , tail'-is-reduced x w red))\n ∘ mul'-reduce-reduced x w red\n\nreduced-to-freegroup-mul-reduce : (x : A) (v : reduced-word)\n → reduced-to-freegroup (mul-reduce x v) ≡ x · (reduced-to-freegroup v)\nreduced-to-freegroup-mul-reduce x (ε , red) = refl\nreduced-to-freegroup-mul-reduce x ((y ∷ v) , red) = refl\nreduced-to-freegroup-mul-reduce x ((y ′∷ v) , red) with (eq x y)\nreduced-to-freegroup-mul-reduce x ((.x ′∷ v) , red) | inl refl =\n ! (right-inverse-· x (reduced-to-freegroup (v , tail'-is-reduced x v red)))\nreduced-to-freegroup-mul-reduce x ((y ′∷ v) , red) | inr different = refl\n\nreduced-to-freegroup-mul'-reduce : (x : A) (v : reduced-word)\n → reduced-to-freegroup (mul'-reduce x v) ≡ x ⁻¹· (reduced-to-freegroup v)\nreduced-to-freegroup-mul'-reduce x (ε , red) = refl\nreduced-to-freegroup-mul'-reduce x ((y ∷ v) , red) with (eq x y)\nreduced-to-freegroup-mul'-reduce x ((.x ∷ v) , red) | inl refl =\n ! (left-inverse-· x (reduced-to-freegroup (v , tail-is-reduced x v red)))\nreduced-to-freegroup-mul'-reduce x ((y ∷ v) , red) | inr different = refl\nreduced-to-freegroup-mul'-reduce x ((y ′∷ v) , red) = refl\n\ninv₂ : (a : freegroup) → reduced-to-freegroup (freegroup-to-reduced a) ≡ a\ninv₂ = freegroup-rec _\n refl\n (λ x u p → reduced-to-freegroup-mul-reduce x (freegroup-to-reduced u)\n ∘ ap (λ t → x · t) {y = u} p)\n (λ x u p → reduced-to-freegroup-mul'-reduce x (freegroup-to-reduced u)\n ∘ ap (λ t → x ⁻¹· t) {y = u} p)\n (λ x u t → π₁ (freegroup-is-set _ _ _ _))\n (λ x u t → π₁ (freegroup-is-set _ _ _ _))\n (λ u → truncated-is-truncated-S _ (freegroup-is-set _ _))\n\nfreegroup-equiv-reduced : freegroup ≃ reduced-word\nfreegroup-equiv-reduced =\n (freegroup-to-reduced , iso-is-eq _ reduced-to-freegroup inv₁ inv₂)\n", "meta": {"hexsha": "0e6a9aa1ef2e36f2dfd66ad80034cbf7ef4f7dff", "size": 11669, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "old/Algebra/FreeGroupAsReducedWords.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "old/Algebra/FreeGroupAsReducedWords.agda", "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "old/Algebra/FreeGroupAsReducedWords.agda", "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 41.675, "max_line_length": 80, "alphanum_fraction": 0.5769131888, "num_tokens": 4865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.734119526900183, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3956781069783796}} {"text": "module Impure.LFRef.Eval where\n\nopen import Prelude\nopen import Data.Fin using (fromℕ≤)\nopen import Data.List hiding ([_])\nopen import Data.List.All\nopen import Data.List.Any\nopen import Data.Vec hiding (map; _∷ʳ_)\nopen import Data.Maybe hiding (All; Any)\nopen import Extensions.List as L\n\nopen import Impure.LFRef.Syntax hiding (subst)\nopen import Impure.LFRef.Welltyped\n\n-- machine configuration: expression to reduce and a store\nConfig : Set\nConfig = Exp 0 × Store\n\n!load : ∀ {i} → (μ : Store) → i < length μ → Term 0\n!load {i = i} [] ()\n!load {i = zero} (x ∷ μ) (s≤s p) = proj₁ x\n!load {i = suc i} (x ∷ μ) (s≤s p) = !load μ p\n\n!store : ∀ {i e} → (μ : Store) → i < length μ → Val e → Store\n!store [] () v\n!store {i = zero} (x ∷ μ) (s≤s p) v = (, v) ∷ μ\n!store {i = suc i} (x ∷ μ) (s≤s p) v = (, v) ∷ (!store μ p v)\n\n!call : ∀ {n m} → Exp m → (l : List (Term n)) → length l ≡ m → Exp n\n!call e ts p = e exp/ subst (Vec _) p (fromList ts)\n\n-- small steps for expressions\ninfix 1 _⊢_≻_\ndata _⊢_≻_ (𝕊 : Sig) : (t t' : Config) → Set where\n\n funapp-β : ∀ {fn ts μ φ} →\n (Sig.funs 𝕊) L.[ fn ]= φ →\n (p : length ts ≡ Fun.m φ) →\n -------------------------\n 𝕊 ⊢ fn ·★ ts , μ ≻ (!call (Fun.body φ) ts p) , μ\n\n ref-val : ∀ {t μ} →\n (v : Val t) →\n ----------------------------------------------------\n 𝕊 ⊢ ref (tm t) , μ ≻ (tm (loc (length μ))) , (μ ∷ʳ (, v))\n\n ≔-val : ∀ {i e μ} →\n (p : i < length μ) →\n (v : Val e) →\n --------------------------------------------\n 𝕊 ⊢ (tm (loc i)) ≔ (tm e) , μ ≻ (tm unit) , (μ L.[ fromℕ≤ p ]≔ (, v))\n\n !-val : ∀ {i μ} →\n (p : i < length μ) →\n -----------------------------------------\n 𝕊 ⊢ ! (tm (loc i)) , μ ≻ tm (!load μ p) , μ\n\n\n ref-clos : ∀ {e e' μ μ'} →\n 𝕊 ⊢ e , μ ≻ e' , μ' →\n ---------------------------\n 𝕊 ⊢ ref e , μ ≻ ref e' , μ'\n\n !-clos : ∀ {e e' μ μ'} →\n 𝕊 ⊢ e , μ ≻ e' , μ' →\n -----------------------\n 𝕊 ⊢ ! e , μ ≻ ! e' , μ'\n\n ≔-clos₁ : ∀ {x x' e μ μ'} →\n 𝕊 ⊢ x , μ ≻ x' , μ' →\n --------------------------\n 𝕊 ⊢ x ≔ e , μ ≻ x' ≔ e , μ'\n\n ≔-clos₂ : ∀ {x e e' μ μ'} →\n ExpVal x →\n 𝕊 ⊢ e , μ ≻ e' , μ' →\n --------------------------\n 𝕊 ⊢ x ≔ e , μ ≻ x ≔ e' , μ'\n\ninfix 1 _⊢_≻ₛ_\ndata _⊢_≻ₛ_ (𝕊 : Sig) : (t t' : SeqExp 0 × Store) → Set where\n\n -- reductions\n lett-β : ∀ {t e μ} →\n ----------------------------------------------\n 𝕊 ⊢ (lett (tm t) e) , μ ≻ₛ (e seq/ (sub t)) , μ\n\n -- contextual closure\n ret-clos : ∀ {e μ e' μ'} →\n 𝕊 ⊢ e , μ ≻ e' , μ' →\n -------------------------------------\n 𝕊 ⊢ (ret e) , μ ≻ₛ (ret e') , μ'\n\n lett-clos : ∀ {x e x' μ μ'} →\n 𝕊 ⊢ x , μ ≻ x' , μ' →\n -------------------------------------\n 𝕊 ⊢ (lett x e) , μ ≻ₛ (lett x' e) , μ'\n\n-- reflexive-transitive closure of ≻\nopen import Data.Star\ninfix 1 _⊢_≻⋆_\n_⊢_≻⋆_ : (Sig) → (c c' : SeqExp 0 × Store) → Set\n𝕊 ⊢ c ≻⋆ c' = Star (_⊢_≻ₛ_ 𝕊) c c'\n", "meta": {"hexsha": "2fd9458b0f60fe475fe6857c0ec27dd12f08e07c", "size": 3172, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Impure/LFRef/Eval.agda", "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "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/Impure/LFRef/Eval.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/Impure/LFRef/Eval.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": 30.5, "max_line_length": 79, "alphanum_fraction": 0.3653846154, "num_tokens": 1231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943805178139, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.39566335874534153}} {"text": "------------------------------------------------------------------------------\n-- Properties related with the forest type\n------------------------------------------------------------------------------\n\n{-# OPTIONS --exact-split #-}\n{-# OPTIONS --no-sized-types #-}\n{-# OPTIONS --no-universe-polymorphism #-}\n{-# OPTIONS --without-K #-}\n\nmodule FOTC.Program.Mirror.Forest.PropertiesATP where\n\nopen import Common.FOL.Relation.Binary.EqReasoning\n\nopen import FOTC.Base\nopen import FOTC.Base.List\nopen import FOTC.Base.List.PropertiesATP using ( ∷-rightCong )\nopen import FOTC.Data.List\nopen import FOTC.Data.List.PropertiesATP\n using ( ++-leftIdentity\n ; mapCong₂\n ; ++-leftCong\n ; reverse-[x]≡[x]\n )\nopen import FOTC.Program.Mirror.Forest.TotalityATP\nopen import FOTC.Program.Mirror.Type\n\n------------------------------------------------------------------------------\n\n++-rightIdentity : ∀ {xs} → Forest xs → xs ++ [] ≡ xs\n++-rightIdentity fnil = ++-leftIdentity []\n++-rightIdentity (fcons {x} {xs} Tx Fxs) =\n prf (++-rightIdentity Fxs)\n where postulate prf : xs ++ [] ≡ xs → (x ∷ xs) ++ [] ≡ x ∷ xs\n {-# ATP prove prf #-}\n\n++-assoc : ∀ {xs} → Forest xs → ∀ ys zs → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs)\n++-assoc fnil ys zs = prf\n where postulate prf : ([] ++ ys) ++ zs ≡ [] ++ ys ++ zs\n {-# ATP prove prf #-}\n\n++-assoc (fcons {x} {xs} Tx Fxs) ys zs = prf (++-assoc Fxs ys zs)\n where postulate prf : (xs ++ ys) ++ zs ≡ xs ++ ys ++ zs →\n ((x ∷ xs) ++ ys) ++ zs ≡ (x ∷ xs) ++ ys ++ zs\n {-# ATP prove prf #-}\n\n-- We don't use an automatic proof, because it is necessary to erase a\n-- proof term which we don't know how to erase.\nmap-++ : ∀ f {xs} → (∀ {x} → Tree x → Tree (f · x)) →\n Forest xs →\n ∀ ys → map f (xs ++ ys) ≡ map f xs ++ map f ys\nmap-++ f h fnil ys =\n map f ([] ++ ys)\n ≡⟨ mapCong₂ (++-leftIdentity ys) ⟩\n map f ys\n ≡⟨ sym (++-leftIdentity (map f ys)) ⟩\n [] ++ map f ys\n ≡⟨ ++-leftCong (sym (map-[] f)) ⟩\n map f [] ++ map f ys ∎\n\nmap-++ f h (fcons {x} {xs} Tx Fxs) ys =\n map f ((x ∷ xs) ++ ys)\n ≡⟨ mapCong₂ (++-∷ x xs ys) ⟩\n map f (x ∷ xs ++ ys)\n ≡⟨ map-∷ f x (xs ++ ys) ⟩\n f · x ∷ map f (xs ++ ys)\n ≡⟨ ∷-rightCong (map-++ f h Fxs ys) ⟩\n f · x ∷ (map f xs ++ map f ys)\n ≡⟨ sym (++-∷ (f · x) (map f xs) (map f ys)) ⟩\n (f · x ∷ map f xs) ++ map f ys\n ≡⟨ ++-leftCong (sym (map-∷ f x xs)) ⟩\n map f (x ∷ xs) ++ map f ys ∎\n\nrev-++ : ∀ {xs} → Forest xs → ∀ ys → rev xs ys ≡ rev xs [] ++ ys\nrev-++ fnil ys = prf\n where postulate prf : rev [] ys ≡ rev [] [] ++ ys\n {-# ATP prove prf #-}\n\nrev-++ (fcons {x} {xs} Tx Fxs) ys =\n prf (rev-++ Fxs (x ∷ ys))\n (rev-++ Fxs (x ∷ []))\n where postulate prf : rev xs (x ∷ ys) ≡ rev xs [] ++ x ∷ ys →\n rev xs (x ∷ []) ≡ rev xs [] ++ x ∷ [] →\n rev (x ∷ xs) ys ≡ rev (x ∷ xs) [] ++ ys\n {-# ATP prove prf ++-assoc rev-Forest #-}\n\nreverse-++ : ∀ {xs ys} → Forest xs → Forest ys →\n reverse (xs ++ ys) ≡ reverse ys ++ reverse xs\nreverse-++ {ys = ys} fnil Fys = prf\n where postulate prf : reverse ([] ++ ys) ≡ reverse ys ++ reverse []\n {-# ATP prove prf ++-rightIdentity reverse-Forest #-}\n\nreverse-++ (fcons {x} {xs} Tx Fxs) fnil = prf\n where\n postulate prf : reverse ((x ∷ xs) ++ []) ≡ reverse [] ++ reverse (x ∷ xs)\n {-# ATP prove prf ++-rightIdentity #-}\n\nreverse-++ (fcons {x} {xs} Tx Fxs) (fcons {y} {ys} Ty Fys) =\n prf (reverse-++ Fxs (fcons Ty Fys))\n where\n postulate prf : reverse (xs ++ y ∷ ys) ≡ reverse (y ∷ ys) ++\n reverse xs →\n reverse ((x ∷ xs) ++ y ∷ ys) ≡ reverse (y ∷ ys) ++\n reverse (x ∷ xs)\n {-# ATP prove prf reverse-Forest ++-Forest rev-++ ++-assoc #-}\n\nreverse-∷ : ∀ {x ys} → Tree x → Forest ys →\n reverse (x ∷ ys) ≡ reverse ys ++ (x ∷ [])\nreverse-∷ {x} Tx fnil = prf\n where postulate prf : reverse (x ∷ []) ≡ reverse [] ++ x ∷ []\n {-# ATP prove prf #-}\n\nreverse-∷ {x} Tx (fcons {y} {ys} Ty Fys) = prf\n where postulate prf : reverse (x ∷ y ∷ ys) ≡ reverse (y ∷ ys) ++ x ∷ []\n {-# ATP prove prf reverse-[x]≡[x] reverse-++ #-}\n", "meta": {"hexsha": "2c949a9f71498c4769c475b4ed8d73bbf0b7dce3", "size": 4271, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/fot/FOTC/Program/Mirror/Forest/PropertiesATP.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": "src/fot/FOTC/Program/Mirror/Forest/PropertiesATP.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": "src/fot/FOTC/Program/Mirror/Forest/PropertiesATP.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": 37.1391304348, "max_line_length": 78, "alphanum_fraction": 0.4687426832, "num_tokens": 1453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6039318479832805, "lm_q2_score": 0.6548947425132315, "lm_q1q2_score": 0.39551179208055054}} {"text": "module Data.Collection where\n\nopen import Data.Collection.Core public\nopen import Data.Collection.Equivalence\nopen import Data.Collection.Inclusion\nopen import Relation.Nullary\n\n--------------------------------------------------------------------------------\n-- Singleton\n--------------------------------------------------------------------------------\n\nsingleton : String → Collection\nsingleton x = x ∷ []\n\n--------------------------------------------------------------------------------\n-- Delete\n--------------------------------------------------------------------------------\n\ndelete : String → Collection → Collection\ndelete x [] = []\ndelete x (a ∷ A) with x ≟ a\ndelete x (a ∷ A) | yes p = delete x A -- keep deleting, because there might be many of them\ndelete x (a ∷ A) | no ¬p = a ∷ delete x A\n\n--------------------------------------------------------------------------------\n-- Union\n--------------------------------------------------------------------------------\n\nunion : Collection → Collection → Collection\nunion [] B = B\nunion (a ∷ A) B with a ∈? B\nunion (a ∷ A) B | yes p = union A B\nunion (a ∷ A) B | no ¬p = a ∷ union A B\n\n\n--\n-- open import Data.List\n-- open import Data.String hiding (setoid)\n-- open import Data.List using ([]; _∷_) public\n-- open import Data.Product\n-- open import Data.Sum renaming (map to mapSum)\n-- -- open import Data.Bool using (Bool; true; false; T; not)\n-- open import Level renaming (zero to lvl0)\n-- open import Function using (_∘_; id; flip; _on_)\n-- open import Function.Equivalence using (_⇔_; Equivalence; equivalence)\n--\n-- open import Function.Equality using (_⟨$⟩_) renaming (cong to cong≈)\n-- open import Relation.Nullary\n-- open import Relation.Unary\n-- open import Relation.Nullary.Negation\n-- open import Relation.Nullary.Decidable renaming (map to mapDec; map′ to mapDec′)\n-- open import Relation.Binary hiding (_⇒_)\n-- open import Relation.Binary.PropositionalEquality\n-- -- open ≡-Reasoning\n--\n--\n-- -- I know this notation is a bit confusing\n-- _⊈_ : ∀ {a ℓ₁ ℓ₂} {A : Set a} → Pred A ℓ₁ → Pred A ℓ₂ → Set _\n-- P ⊈ Q = ∀ {x} → x ∉ P → x ∉ Q\n--\n--\n-- ⊆-IsPreorder : IsPreorder _≋_ _⊆_\n-- ⊆-IsPreorder = record\n-- { isEquivalence = {! !}\n-- ; reflexive = {! !}\n-- ; trans = {! !}\n-- }\n--\n--\n-- []-empty : Empty c[ [] ]\n-- []-empty = λ x → λ ()\n--\n-- here-respects-≡ : ∀ {A} → (λ x → x ∈ c[ A ]) Respects _≡_\n-- here-respects-≡ refl = id\n--\n-- there-respects-≡ : ∀ {x A} → (λ a → x ∈ c[ a ∷ A ]) Respects _≡_\n-- there-respects-≡ refl = id\n--\n-- ∈-respects-≡ : ∀ {x} → (λ P → x ∈ c[ P ]) Respects _≡_\n-- ∈-respects-≡ refl = id\n--\n-- there-if-not-here : ∀ {x a A} → x ≢ a → x ∈ c[ a ∷ A ] → x ∈ c[ A ]\n-- there-if-not-here x≢a here = contradiction refl x≢a\n-- there-if-not-here x≢a (there x∈a∷A) = x∈a∷A\n--\n-- here-if-not-there : ∀ {x a A} → x ∉ c[ A ] → x ∈ c[ a ∷ A ] → x ≡ a\n-- here-if-not-there x∉A here = refl\n-- here-if-not-there x∉A (there x∈A) = contradiction x∈A x∉A\n\n--\n-- map-¬∷ : ∀ {x a A B} → (x ∉ c[ A ] → x ∉ c[ B ]) → x ≢ a → x ∉ c[ a ∷ A ] → x ∉ c[ a ∷ B ]\n-- map-¬∷ f x≢x x∉a∷A here = contradiction refl x≢x\n-- map-¬∷ f x≢a x∉a∷A (there x∈B) = f (x∉a∷A ∘ there) x∈B\n--\n-- still-not-there : ∀ {x y} A → x ≢ y → x ∉ c[ A ] → x ∉ c[ y ∷ A ]\n-- still-not-there [] x≢y x∉[y] here = x≢y refl\n-- still-not-there [] x≢y x∉[y] (there ())\n-- still-not-there (a ∷ A) x≢y x∉a∷A here = x≢y refl\n-- still-not-there (a ∷ A) x≢y x∉a∷A (there x∈a∷A) = x∉a∷A x∈a∷A\n--\n-- --------------------------------------------------------------------------------\n-- -- Union\n-- --------------------------------------------------------------------------------\n--\n-- union : Collection → Collection → Collection\n-- union [] B = B\n-- union (a ∷ A) B with a ∈? B\n-- union (a ∷ A) B | yes p = union A B\n-- union (a ∷ A) B | no ¬p = a ∷ union A B\n--\n-- in-right-union : ∀ A B → c[ B ] ⊆ c[ union A B ]\n-- in-right-union [] B x∈B = x∈B\n-- in-right-union (a ∷ A) B x∈B with a ∈? B\n-- in-right-union (a ∷ A) B x∈B | yes p = in-right-union A B x∈B\n-- in-right-union (a ∷ A) B x∈B | no ¬p = there (in-right-union A B x∈B)\n--\n-- in-left-union : ∀ A B → c[ A ] ⊆ c[ union A B ]\n-- in-left-union [] B ()\n-- in-left-union (a ∷ A) B x∈A with a ∈? B\n-- in-left-union (a ∷ A) B here | yes p = in-right-union A B p\n-- in-left-union (a ∷ A) B (there x∈A) | yes p = in-left-union A B x∈A\n-- in-left-union (a ∷ A) B here | no ¬p = here\n-- in-left-union (a ∷ A) B (there x∈A) | no ¬p = there (in-left-union A B x∈A)\n--\n-- ∪-left-identity : ∀ A → c[ [] ] ∪ c[ A ] ≋ c[ A ]\n-- ∪-left-identity A = equivalence to inj₂\n-- where\n-- to : c[ [] ] ∪ c[ A ] ⊆ c[ A ]\n-- to (inj₁ ())\n-- to (inj₂ ∈A) = ∈A\n--\n-- ∪-right-identity : ∀ A → c[ A ] ∪ c[ [] ] ≋ c[ A ]\n-- ∪-right-identity A = equivalence to inj₁\n-- where\n-- to : c[ A ] ∪ c[ [] ] ⊆ c[ A ]\n-- to (inj₁ ∈A) = ∈A\n-- to (inj₂ ())\n--\n-- in-either : ∀ A B → c[ union A B ] ⊆ c[ A ] ∪ c[ B ]\n-- in-either [] B x∈A∪B = inj₂ x∈A∪B\n-- in-either (a ∷ A) B x∈A∪B with a ∈? B\n-- in-either (a ∷ A) B x∈A∪B | yes p = mapSum there id (in-either A B x∈A∪B)\n-- in-either (a ∷ A) B here | no ¬p = inj₁ here\n-- in-either (a ∷ A) B (there x∈A∪B) | no ¬p = mapSum there id (in-either A B x∈A∪B)\n--\n-- ∪-union : ∀ A B → c[ A ] ∪ c[ B ] ≋ c[ union A B ]\n-- ∪-union A B = equivalence to (in-either A B)\n-- where to : ∀ {x} → x ∈ c[ A ] ∪ c[ B ] → x ∈ c[ union A B ]\n-- to (inj₁ ∈A) = in-left-union A B ∈A\n-- to (inj₂ ∈B) = in-right-union A B ∈B\n--\n-- -- map-⊆-union : ∀ {A B C} → c[ A ] ⊆ c[ B ] → c[ B ] ⊆ c[ C ] → c[ ] ⊆ c[ union C D ]\n-- -- map-⊆-union f g ∈union = {! !}\n--\n--\n-- union-branch-1 : ∀ {x a} A B → a ∈ c[ B ] → x ∈ c[ union (a ∷ A) B ] → x ∈ c[ union A B ]\n-- union-branch-1 {x} {a} A B a∈B x∈union with a ∈? B\n-- union-branch-1 A B a∈B x∈union | yes p = x∈union\n-- union-branch-1 A B a∈B x∈union | no ¬p = contradiction a∈B ¬p\n--\n-- there-left-union-coherence : ∀ {x} {a} A B → x ∈ c[ a ∷ A ] → x ∈c a ∷ union A B\n-- there-left-union-coherence A B here = here\n-- there-left-union-coherence A B (there x∈a∷A) = there (in-left-union A B x∈a∷A)\n--\n--\n-- in-neither : ∀ {x} A B → x ∉c union A B → x ∉ c[ A ] × x ∉ c[ B ]\n-- in-neither [] B x∉A∪B = (λ ()) , x∉A∪B\n-- in-neither (a ∷ A) B x∉A∪B with a ∈? B\n-- in-neither (a ∷ A) B x∉A∪B | yes a∈B = (contraposition (union-branch-1 A B a∈B ∘ in-left-union (a ∷ A) B) x∉A∪B) , (contraposition (in-right-union A B) x∉A∪B)\n-- in-neither (a ∷ A) B x∉A∪B | no a∉B = (contraposition (there-left-union-coherence A B) x∉A∪B) , contraposition (there ∘ in-right-union A B) x∉A∪B\n--\n--\n-- delete : String → Collection → Collection\n-- delete x [] = []\n-- delete x (a ∷ A) with x ≟ a\n-- delete x (a ∷ A) | yes p = delete x A -- keep deleting, because there might be many of them\n-- delete x (a ∷ A) | no ¬p = a ∷ delete x A\n--\n-- ∉-after-deleted : ∀ x A → x ∉ c[ delete x A ]\n-- ∉-after-deleted x [] ()\n-- ∉-after-deleted x (a ∷ A) with x ≟ a\n-- ∉-after-deleted x (a ∷ A) | yes p = ∉-after-deleted x A\n-- ∉-after-deleted x (a ∷ A) | no ¬p = still-not-there (delete x A) ¬p (∉-after-deleted x A)\n--\n--\n-- still-∈-after-deleted : ∀ {x} y A → x ≢ y → x ∈ c[ A ] → x ∈ c[ delete y A ]\n-- still-∈-after-deleted y [] x≢y ()\n-- still-∈-after-deleted y (a ∷ A) x≢y x∈A with y ≟ a\n-- still-∈-after-deleted y (.y ∷ A) x≢y x∈A | yes refl = still-∈-after-deleted y A x≢y (there-if-not-here x≢y x∈A)\n-- still-∈-after-deleted y (a ∷ A) x≢y x∈A | no ¬p = ∷-⊆-monotone {! !} {! x∈A !}\n-- -- still-∈-after-deleted y (a ∷ A) x≢y x∈A | no ¬p = ∷-⊆-monotone (still-∈-after-deleted y A x≢y) x∈A\n--\n-- -- still-∉-after-deleted : ∀ {x} y A → x ≢ y → x ∉ c[ A ] → x ∉ c[ delete y A ]\n-- -- still-∉-after-deleted y [] x≢y x∉A = x∉A\n-- -- still-∉-after-deleted y (a ∷ A) x≢y x∉A with y ≟ a\n-- -- still-∉-after-deleted y (.y ∷ A) x≢y x∉A | yes refl = still-∉-after-deleted y A x≢y (x∉A ∘ there)\n-- -- still-∉-after-deleted {x} y (a ∷ A) x≢y x∉A | (no ¬p) with x ≟ a\n-- -- still-∉-after-deleted y (x ∷ A) x≢y x∉A | no ¬p | yes refl = contradiction here x∉A\n-- -- still-∉-after-deleted y (a ∷ A) x≢y x∉A | no ¬p | no ¬q = map-¬∷ (still-∉-after-deleted y A x≢y) ¬q x∉A\n-- --\n-- -- still-∉-after-recovered : ∀ {x} y A → x ≢ y → x ∉c delete y A → x ∉ c[ A ]\n-- -- still-∉-after-recovered y [] x≢y x∉deleted ()\n-- -- still-∉-after-recovered y (a ∷ A) x≢y x∉deleted x∈a∷A with y ≟ a\n-- -- still-∉-after-recovered y (.y ∷ A) x≢y x∉deleted x∈a∷A | yes refl = still-∉-after-recovered y A x≢y x∉deleted (there-if-not-here x≢y x∈a∷A)\n-- -- still-∉-after-recovered {x} y (a ∷ A) x≢y x∉deleted x∈a∷A | no ¬p with x ≟ a\n-- -- still-∉-after-recovered y (x ∷ A) x≢y x∉deleted x∈a∷A | no ¬p | yes refl = contradiction here x∉deleted\n-- -- still-∉-after-recovered y (a ∷ A) x≢y x∉deleted x∈a∷A | no ¬p | no ¬q = x∉deleted (∷-⊆-monotone (still-∈-after-deleted y A x≢y) x∈a∷A)\n--\n-- singleton : String → Collection\n-- singleton x = x ∷ []\n--\n-- singleton-≡ : ∀ {x y} → x ∈ c[ singleton y ] → x ≡ y\n-- singleton-≡ here = refl\n-- singleton-≡ (there ())\n", "meta": {"hexsha": "332f22f4a36a57ed8f7e7986a681faf46fbcfc47", "size": 9203, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Data/Collection.agda", "max_stars_repo_name": "banacorn/lambda-calculus", "max_stars_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a", "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": "Data/Collection.agda", "max_issues_repo_name": "banacorn/lambda-calculus", "max_issues_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a", "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": "Data/Collection.agda", "max_forks_repo_name": "banacorn/lambda-calculus", "max_forks_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a", "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.8046511628, "max_line_length": 161, "alphanum_fraction": 0.4879930457, "num_tokens": 3721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947425132315, "lm_q2_score": 0.6039318337259583, "lm_q1q2_score": 0.3955117827435052}} {"text": "-- Copyright: (c) 2016 Ertugrul Söylemez\n-- License: BSD3\n-- Maintainer: Ertugrul Söylemez \n\nmodule Data.Nat.Core where\n\nopen import Agda.Builtin.Nat public\n renaming (Nat to ℕ)\n using (suc; zero)\n renaming (_+_ to _+ℕ_; _*_ to _*ℕ_)\nopen import Classes\nopen import Core\n\n\ninstance\n ℕ-Number : Number ℕ\n ℕ-Number =\n record {\n Constraint = λ _ → ⊤;\n fromNat = λ n → n\n }\n\n ℕ-Plus : Plus ℕ\n ℕ-Plus = record { _+_ = _+ℕ_ }\n\n ℕ-Times : Times ℕ\n ℕ-Times = record { _*_ = _*ℕ_ }\n\n ℕ,≡ : Equiv ℕ\n ℕ,≡ = PropEq ℕ\n\n module ℕ,≡ = Equiv ℕ,≡\n\n\ndata _≤_ : ℕ → ℕ → Set where\n instance 0≤s : ∀ {y} → 0 ≤ y\n instance s≤s : ∀ {x y} → x ≤ y → suc x ≤ suc y\n\ninfix 4 _≤_\n\nℕ,≤ : TotalOrder ℕ\nℕ,≤ =\n record {\n partialOrder = record {\n Eq = PropEq ℕ;\n _≤_ = _≤_;\n antisym = antisym;\n refl' = refl';\n trans = trans\n };\n total = total\n }\n\n where\n antisym : {x y : ℕ} → x ≤ y → y ≤ x → x ≡ y\n antisym 0≤s 0≤s = ≡-refl\n antisym (s≤s p) (s≤s q) = cong suc (antisym p q)\n\n refl' : {x y : ℕ} → x ≡ y → x ≤ y\n refl' {zero} ≡-refl = 0≤s\n refl' {suc x} ≡-refl = s≤s (refl' ≡-refl)\n\n trans : {x y z : ℕ} → x ≤ y → y ≤ z → x ≤ z\n trans 0≤s q = 0≤s\n trans (s≤s p) (s≤s q) = s≤s (trans p q)\n\n total : (x y : ℕ) → Either (x ≤ y) (y ≤ x)\n total zero y = Left 0≤s\n total (suc x) zero = Right 0≤s\n total (suc x) (suc y) with total x y\n total (suc x) (suc y) | Left p = Left (s≤s p)\n total (suc x) (suc y) | Right p = Right (s≤s p)\n\nmodule ℕ,≤ = TotalOrder ℕ,≤\n\n_≤?_ : ∀ x y → Decision (x ≤ y)\nzero ≤? y = yes 0≤s\nsuc x ≤? zero = no (λ ())\nsuc x ≤? suc y with x ≤? y\nsuc x ≤? suc y | yes p = yes (s≤s p)\nsuc x ≤? suc y | no np = no (λ { (s≤s p) → np p })\n\n\n_multiple-of_ : ℕ → ℕ → Set\nx multiple-of y = ∃ (λ k → k * y ≡ x)\n\n\nmodule Props where\n open Equiv (PropEq ℕ)\n\n private\n _!+!_ : ∀ {x1 x2 y1 y2 : ℕ} → x1 ≡ x2 → y1 ≡ y2 → x1 + y1 ≡ x2 + y2\n _!+!_ = cong2 _+_\n R = λ x → refl {x = x}\n\n infixl 6 _!+!_\n\n +-assoc : ∀ x y z → (x + y) + z ≈ x + (y + z)\n +-assoc zero y z = refl\n +-assoc (suc x) y z = cong suc (+-assoc x y z)\n\n +-left-id : ∀ x → 0 + x ≈ x\n +-left-id _ = refl\n\n +-right-id : ∀ x → x + 0 ≈ x\n +-right-id zero = refl\n +-right-id (suc x) = cong suc (+-right-id x)\n\n +-comm : ∀ x y → x + y ≈ y + x\n +-comm zero y = sym (+-right-id y)\n +-comm (suc x) y =\n begin\n suc x + y ≈[ cong suc (+-comm x y) ]\n suc y + x ≈[ sym (one-comm y x) ]\n y + suc x\n qed\n\n where\n one-comm : ∀ x y → x + suc y ≈ suc x + y\n one-comm zero _ = refl\n one-comm (suc x) y = cong suc (one-comm x y)\n\n +-suc-assoc : ∀ x y → x + suc y ≈ suc (x + y)\n +-suc-assoc x y =\n begin\n x + suc y ≈[ sym (+-assoc x 1 y) ]\n (x + 1) + y ≈[ +-comm x 1 !+! R y ]\n suc (x + y)\n qed\n\n *-+-left-dist : ∀ x a b → x * (a + b) ≈ x * a + x * b\n *-+-left-dist zero a b = refl\n *-+-left-dist (suc x) a b =\n begin\n a + b + x * (a + b) ≈[ R (a + b) !+! *-+-left-dist x a b ]\n a + b + (x * a + x * b) ≈[ +-assoc a b _ ]\n a + (b + (x * a + x * b)) ≈[\n cong (a +_) $\n b + (x * a + x * b) ≈[ sym (+-assoc b (x * a) (x * b)) ]\n b + x * a + x * b ≈[ +-comm b _ !+! R (x * b) ]\n x * a + b + x * b ≈[ +-assoc (x * a) _ _ ]\n x * a + (b + x * b)\n qed ]\n a + (x * a + (b + x * b)) ≈[ sym (+-assoc a _ _) ]\n a + x * a + (b + x * b)\n qed\n\n *-+-right-dist : ∀ a b x → (a + b) * x ≈ a * x + b * x\n *-+-right-dist zero b x = refl\n *-+-right-dist (suc a) b x =\n begin\n x + (a + b) * x ≈[ R x !+! *-+-right-dist a b x ]\n x + (a * x + b * x) ≈[ sym (+-assoc x (a * x) (b * x)) ]\n (x + a * x) + b * x\n qed\n\n *-assoc : ∀ x y z → (x * y) * z ≈ x * (y * z)\n *-assoc zero y z = refl\n *-assoc (suc x) y z =\n begin\n (y + x * y) * z ≈[ *-+-right-dist y (x * y) z ]\n y * z + (x * y) * z ≈[ R (y * z) !+! *-assoc x y z ]\n y * z + x * (y * z)\n qed\n\n *-left-id : ∀ x → 1 * x ≈ x\n *-left-id = +-right-id\n\n *-right-id : ∀ x → x * 1 ≈ x\n *-right-id zero = refl\n *-right-id (suc x) = cong suc (*-right-id x)\n\n *-right-zero : ∀ x → x * 0 ≈ 0\n *-right-zero zero = refl\n *-right-zero (suc x) = *-right-zero x\n\n *-comm : ∀ x y → x * y ≈ y * x\n *-comm zero y = sym (*-right-zero y)\n *-comm (suc x) zero = *-comm x zero\n *-comm (suc x) (suc y) =\n cong suc $\n begin\n y + x * suc y ≈[ R y !+! (*-+-left-dist x 1 y) ]\n y + (x * 1 + x * y) ≈[ R y !+! (*-right-id x !+! R (x * y)) ]\n y + (x + x * y) ≈[ sym (+-assoc y x (x * y)) ]\n y + x + x * y ≈[ +-comm y x !+! *-comm x y ]\n x + y + y * x ≈[ +-assoc x y (y * x) ]\n x + (y + y * x) ≈[ R x !+! (sym (*-right-id y) !+! R (y * x)) ]\n x + (y * 1 + y * x) ≈[ R x !+! sym (*-+-left-dist y 1 x) ]\n x + y * suc x\n qed\n\n suc-inj : ∀ {x y} → suc x ≈ suc y → x ≈ y\n suc-inj ≡-refl = refl\n\n sum-mult : ∀ {x1 x2 y} → x1 multiple-of y → x2 multiple-of y → (x1 + x2) multiple-of y\n sum-mult {x1} {x2} {y} (k1 , p1) (k2 , p2) =\n k1 + k2\n because:\n (k1 + k2) * y ≈[ *-+-right-dist k1 k2 y ]\n k1 * y + k2 * y ≈[ p1 !+! p2 ]\n x1 + x2\n qed\n", "meta": {"hexsha": "873fe2469322d3a5e6ff8b0259e8644835c358c3", "size": 5182, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Data/Nat/Core.agda", "max_stars_repo_name": "esoeylemez/agda-simple", "max_stars_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-07T17:36:42.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-07T17:36:42.000Z", "max_issues_repo_path": "Data/Nat/Core.agda", "max_issues_repo_name": "esoeylemez/agda-simple", "max_issues_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "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": "Data/Nat/Core.agda", "max_forks_repo_name": "esoeylemez/agda-simple", "max_forks_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "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": 25.4019607843, "max_line_length": 88, "alphanum_fraction": 0.4303357777, "num_tokens": 2358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056167854461, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.39543974848554464}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Many properties which hold for _∼_ also hold for _∼_ on f\n------------------------------------------------------------------------\n\nopen import Relation.Binary\n\nmodule Relation.Binary.On where\n\nopen import Function\nopen import Data.Product\n\nmodule _ {a b} {A : Set a} {B : Set b} (f : B → A) where\n\n implies : ∀ {ℓ₁ ℓ₂} (≈ : Rel A ℓ₁) (∼ : Rel A ℓ₂) →\n ≈ ⇒ ∼ → (≈ on f) ⇒ (∼ on f)\n implies _ _ impl = impl\n\n reflexive : ∀ {ℓ} (∼ : Rel A ℓ) → Reflexive ∼ → Reflexive (∼ on f)\n reflexive _ refl = refl\n\n irreflexive : ∀ {ℓ₁ ℓ₂} (≈ : Rel A ℓ₁) (∼ : Rel A ℓ₂) →\n Irreflexive ≈ ∼ → Irreflexive (≈ on f) (∼ on f)\n irreflexive _ _ irrefl = irrefl\n\n symmetric : ∀ {ℓ} (∼ : Rel A ℓ) → Symmetric ∼ → Symmetric (∼ on f)\n symmetric _ sym = sym\n\n transitive : ∀ {ℓ} (∼ : Rel A ℓ) → Transitive ∼ → Transitive (∼ on f)\n transitive _ trans = trans\n\n antisymmetric : ∀ {ℓ₁ ℓ₂} (≈ : Rel A ℓ₁) (≤ : Rel A ℓ₂) →\n Antisymmetric ≈ ≤ → Antisymmetric (≈ on f) (≤ on f)\n antisymmetric _ _ antisym = antisym\n\n asymmetric : ∀ {ℓ} (< : Rel A ℓ) → Asymmetric < → Asymmetric (< on f)\n asymmetric _ asym = asym\n\n respects : ∀ {ℓ p} (∼ : Rel A ℓ) (P : A → Set p) →\n P Respects ∼ → (P ∘ f) Respects (∼ on f)\n respects _ _ resp = resp\n\n respects₂ : ∀ {ℓ₁ ℓ₂} (∼₁ : Rel A ℓ₁) (∼₂ : Rel A ℓ₂) →\n ∼₁ Respects₂ ∼₂ → (∼₁ on f) Respects₂ (∼₂ on f)\n respects₂ _ _ (resp₁ , resp₂) =\n ((λ {_} {_} {_} → resp₁) , λ {_} {_} {_} → resp₂)\n\n decidable : ∀ {ℓ} (∼ : Rel A ℓ) → Decidable ∼ → Decidable (∼ on f)\n decidable _ dec = λ x y → dec (f x) (f y)\n\n total : ∀ {ℓ} (∼ : Rel A ℓ) → Total ∼ → Total (∼ on f)\n total _ tot = λ x y → tot (f x) (f y)\n\n trichotomous : ∀ {ℓ₁ ℓ₂} (≈ : Rel A ℓ₁) (< : Rel A ℓ₂) →\n Trichotomous ≈ < → Trichotomous (≈ on f) (< on f)\n trichotomous _ _ compare = λ x y → compare (f x) (f y)\n\n isEquivalence : ∀ {ℓ} {≈ : Rel A ℓ} →\n IsEquivalence ≈ → IsEquivalence (≈ on f)\n isEquivalence {≈ = ≈} eq = record\n { refl = reflexive ≈ Eq.refl\n ; sym = symmetric ≈ Eq.sym\n ; trans = transitive ≈ Eq.trans\n }\n where module Eq = IsEquivalence eq\n\n isPreorder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {∼ : Rel A ℓ₂} →\n IsPreorder ≈ ∼ → IsPreorder (≈ on f) (∼ on f)\n isPreorder {≈ = ≈} {∼} pre = record\n { isEquivalence = isEquivalence Pre.isEquivalence\n ; reflexive = implies ≈ ∼ Pre.reflexive\n ; trans = transitive ∼ Pre.trans\n }\n where module Pre = IsPreorder pre\n\n isDecEquivalence : ∀ {ℓ} {≈ : Rel A ℓ} →\n IsDecEquivalence ≈ → IsDecEquivalence (≈ on f)\n isDecEquivalence {≈ = ≈} dec = record\n { isEquivalence = isEquivalence Dec.isEquivalence\n ; _≟_ = decidable ≈ Dec._≟_\n }\n where module Dec = IsDecEquivalence dec\n\n isPartialOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →\n IsPartialOrder ≈ ≤ →\n IsPartialOrder (≈ on f) (≤ on f)\n isPartialOrder {≈ = ≈} {≤} po = record\n { isPreorder = isPreorder Po.isPreorder\n ; antisym = antisymmetric ≈ ≤ Po.antisym\n }\n where module Po = IsPartialOrder po\n\n isDecPartialOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →\n IsDecPartialOrder ≈ ≤ →\n IsDecPartialOrder (≈ on f) (≤ on f)\n isDecPartialOrder dpo = record\n { isPartialOrder = isPartialOrder DPO.isPartialOrder\n ; _≟_ = decidable _ DPO._≟_\n ; _≤?_ = decidable _ DPO._≤?_\n }\n where module DPO = IsDecPartialOrder dpo\n\n isStrictPartialOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {< : Rel A ℓ₂} →\n IsStrictPartialOrder ≈ < →\n IsStrictPartialOrder (≈ on f) (< on f)\n isStrictPartialOrder {≈ = ≈} {<} spo = record\n { isEquivalence = isEquivalence Spo.isEquivalence\n ; irrefl = irreflexive ≈ < Spo.irrefl\n ; trans = transitive < Spo.trans\n ; <-resp-≈ = respects₂ < ≈ Spo.<-resp-≈\n }\n where module Spo = IsStrictPartialOrder spo\n\n isTotalOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →\n IsTotalOrder ≈ ≤ →\n IsTotalOrder (≈ on f) (≤ on f)\n isTotalOrder {≈ = ≈} {≤} to = record\n { isPartialOrder = isPartialOrder To.isPartialOrder\n ; total = total ≤ To.total\n }\n where module To = IsTotalOrder to\n\n isDecTotalOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {≤ : Rel A ℓ₂} →\n IsDecTotalOrder ≈ ≤ →\n IsDecTotalOrder (≈ on f) (≤ on f)\n isDecTotalOrder {≈ = ≈} {≤} dec = record\n { isTotalOrder = isTotalOrder Dec.isTotalOrder\n ; _≟_ = decidable ≈ Dec._≟_\n ; _≤?_ = decidable ≤ Dec._≤?_\n }\n where module Dec = IsDecTotalOrder dec\n\n isStrictTotalOrder : ∀ {ℓ₁ ℓ₂} {≈ : Rel A ℓ₁} {< : Rel A ℓ₂} →\n IsStrictTotalOrder ≈ < →\n IsStrictTotalOrder (≈ on f) (< on f)\n isStrictTotalOrder {≈ = ≈} {<} sto = record\n { isEquivalence = isEquivalence Sto.isEquivalence\n ; trans = transitive < Sto.trans\n ; compare = trichotomous ≈ < Sto.compare\n ; <-resp-≈ = respects₂ < ≈ Sto.<-resp-≈\n }\n where module Sto = IsStrictTotalOrder sto\n\npreorder : ∀ {p₁ p₂ p₃ b} {B : Set b} (P : Preorder p₁ p₂ p₃) →\n (B → Preorder.Carrier P) → Preorder _ _ _\npreorder P f = record\n { isPreorder = isPreorder f (Preorder.isPreorder P)\n }\n\nsetoid : ∀ {s₁ s₂ b} {B : Set b} (S : Setoid s₁ s₂) →\n (B → Setoid.Carrier S) → Setoid _ _\nsetoid S f = record\n { isEquivalence = isEquivalence f (Setoid.isEquivalence S)\n }\n\ndecSetoid : ∀ {d₁ d₂ b} {B : Set b} (D : DecSetoid d₁ d₂) →\n (B → DecSetoid.Carrier D) → DecSetoid _ _\ndecSetoid D f = record\n { isDecEquivalence = isDecEquivalence f (DecSetoid.isDecEquivalence D)\n }\n\nposet : ∀ {p₁ p₂ p₃ b} {B : Set b} (P : Poset p₁ p₂ p₃) →\n (B → Poset.Carrier P) → Poset _ _ _\nposet P f = record\n { isPartialOrder = isPartialOrder f (Poset.isPartialOrder P)\n }\n\ndecPoset : ∀ {d₁ d₂ d₃ b} {B : Set b} (D : DecPoset d₁ d₂ d₃) →\n (B → DecPoset.Carrier D) → DecPoset _ _ _\ndecPoset D f = record\n { isDecPartialOrder =\n isDecPartialOrder f (DecPoset.isDecPartialOrder D)\n }\n\nstrictPartialOrder :\n ∀ {s₁ s₂ s₃ b} {B : Set b} (S : StrictPartialOrder s₁ s₂ s₃) →\n (B → StrictPartialOrder.Carrier S) → StrictPartialOrder _ _ _\nstrictPartialOrder S f = record\n { isStrictPartialOrder =\n isStrictPartialOrder f (StrictPartialOrder.isStrictPartialOrder S)\n }\n\ntotalOrder : ∀ {t₁ t₂ t₃ b} {B : Set b} (T : TotalOrder t₁ t₂ t₃) →\n (B → TotalOrder.Carrier T) → TotalOrder _ _ _\ntotalOrder T f = record\n { isTotalOrder = isTotalOrder f (TotalOrder.isTotalOrder T)\n }\n\ndecTotalOrder :\n ∀ {d₁ d₂ d₃ b} {B : Set b} (D : DecTotalOrder d₁ d₂ d₃) →\n (B → DecTotalOrder.Carrier D) → DecTotalOrder _ _ _\ndecTotalOrder D f = record\n { isDecTotalOrder = isDecTotalOrder f (DecTotalOrder.isDecTotalOrder D)\n }\n\nstrictTotalOrder :\n ∀ {s₁ s₂ s₃ b} {B : Set b} (S : StrictTotalOrder s₁ s₂ s₃) →\n (B → StrictTotalOrder.Carrier S) → StrictTotalOrder _ _ _\nstrictTotalOrder S f = record\n { isStrictTotalOrder =\n isStrictTotalOrder f (StrictTotalOrder.isStrictTotalOrder S)\n }\n", "meta": {"hexsha": "67180c21da9c5e5cfec82e1a89414e041b411bfb", "size": 7331, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Binary/On.agda", "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Binary/On.agda", "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_licenses": ["Apache-2.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": "agda-stdlib-0.9/src/Relation/Binary/On.agda", "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.9362745098, "max_line_length": 73, "alphanum_fraction": 0.5555858682, "num_tokens": 2672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757646010190475, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.39539064802593066}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import HoTT\nopen import cohomology.Exactness\nopen import cohomology.FunctionOver\nopen import cohomology.ProductRepr\nopen import cohomology.Theory\nopen import cohomology.WedgeCofiber\n\n{- For the cohomology group of a suspension ΣX, the group inverse has the\n - explicit form Cⁿ(flip-susp) : Cⁿ(ΣX) → Cⁿ(ΣX).\n -}\n\nmodule cohomology.InverseInSusp {i} (CT : CohomologyTheory i)\n (n : ℤ) {X : Ptd i} where\n\nopen CohomologyTheory CT\nopen import cohomology.Functor CT\nopen import cohomology.BaseIndependence CT\nopen import cohomology.Wedge CT\n\nprivate\n module CW = CWedge n (⊙Susp X) (⊙Susp X)\n\n module Subtract = SuspensionRec (fst X) {C = fst (⊙Susp X ⊙∨ ⊙Susp X)}\n (winl (south _))\n (winr (south _))\n (λ x → ap winl (! (merid _ x)) ∙ wglue ∙ ap winr (merid _ x))\n\n subtract = Subtract.f\n\n ⊙subtract : fst (⊙Susp X ⊙→ ⊙Susp X ⊙∨ ⊙Susp X)\n ⊙subtract = (subtract , ! (ap winl (merid _ (snd X))))\n\n projl-subtract : ∀ σ → projl _ _ (subtract σ) == flip-susp σ\n projl-subtract = Suspension-elim (fst X) idp idp $\n ↓-='-from-square ∘ vert-degen-square ∘ λ x →\n ap-∘ (projl _ _) subtract (merid _ x)\n ∙ ap (ap (projl _ _)) (Subtract.glue-β x)\n ∙ ap-∙ (projl _ _) (ap winl (! (merid _ x))) (wglue ∙ ap winr (merid _ x))\n ∙ ((∘-ap (projl _ _) winl (! (merid _ x))\n ∙ ap-idf _)\n ∙2 (ap-∙ (projl _ _) wglue (ap winr (merid _ x))\n ∙ (Projl.glue-β _ _\n ∙2 (∘-ap (projl _ _) winr (merid _ x) ∙ ap-cst _ _))))\n ∙ ∙-unit-r _\n ∙ ! (FlipSusp.glue-β x)\n\n projr-subtract : ∀ σ → projr _ _ (subtract σ) == σ\n projr-subtract = Suspension-elim (fst X) idp idp $\n ↓-∘=idf-in (projr _ _) subtract ∘ λ x →\n ap (ap (projr _ _)) (Subtract.glue-β x)\n ∙ ap-∙ (projr _ _) (ap winl (! (merid _ x))) (wglue ∙ ap winr (merid _ x))\n ∙ ((∘-ap (projr _ _) winl (! (merid _ x)) ∙ ap-cst _ _)\n ∙2 (ap-∙ (projr _ _) wglue (ap winr (merid _ x))\n ∙ (Projr.glue-β _ _\n ∙2 (∘-ap (projr _ _) winr (merid _ x) ∙ ap-idf _))))\n\n fold-subtract : ∀ σ → fold (subtract σ) == south _\n fold-subtract = Suspension-elim (fst X) idp idp $\n ↓-app=cst-in ∘ ! ∘ λ x →\n ∙-unit-r _\n ∙ ap-∘ fold subtract (merid _ x)\n ∙ ap (ap fold) (Subtract.glue-β x)\n ∙ ap-∙ fold (ap winl (! (merid _ x))) (wglue ∙ ap winr (merid _ x))\n ∙ ((∘-ap fold winl (! (merid _ x)) ∙ ap-idf _)\n ∙2 (ap-∙ fold wglue (ap winr (merid _ x))\n ∙ (Fold.glue-β\n ∙2 (∘-ap fold winr (merid _ x) ∙ ap-idf _))))\n ∙ !-inv-l (merid _ x)\n\n cancel :\n ×ᴳ-sum-hom (C-abelian n _) (CF-hom n (⊙flip-susp X)) (idhom _) ∘ᴳ ×ᴳ-diag\n == cst-hom\n cancel =\n ap2 (λ φ ψ → ×ᴳ-sum-hom (C-abelian n _) φ ψ ∘ᴳ ×ᴳ-diag)\n (! (CF-λ= n projl-subtract))\n (! (CF-ident n) ∙ ! (CF-λ= n projr-subtract))\n ∙ transport (λ {(G , φ , ψ) → φ ∘ᴳ ψ == cst-hom})\n (pair= (CW.path) $ ↓-×-in\n (CW.wedge-in-over ⊙subtract)\n (CW.⊙wedge-rec-over (⊙idf _) (⊙idf _)\n ▹ ap2 ×ᴳ-hom-in (CF-ident n) (CF-ident n)))\n (! (CF-comp n ⊙fold ⊙subtract)\n ∙ CF-λ= n (λ σ → fold-subtract σ ∙ ! (merid _ (snd X)))\n ∙ CF-cst n)\n\nC-flip-susp-is-inv :\n CF-hom n (⊙flip-susp X) == inv-hom (C n (⊙Susp X)) (C-abelian _ _)\nC-flip-susp-is-inv = hom= _ _ $ λ= $ λ g →\n ! (group-inv-unique-l (C n (⊙Susp X)) _ g (app= (ap GroupHom.f cancel) g))\n", "meta": {"hexsha": "48a40f599b5c8d19f992e491b3735a0916f6a453", "size": 3419, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "cohomology/InverseInSusp.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": "cohomology/InverseInSusp.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": "cohomology/InverseInSusp.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": 37.1630434783, "max_line_length": 80, "alphanum_fraction": 0.5466510676, "num_tokens": 1396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.803173791645582, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.3953126111698417}} {"text": "------------------------------------------------------------------------\n-- Termination\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nopen import Prelude\n\nmodule Delay-monad.Termination {a} {A : Type a} where\n\nopen import Equality.Propositional\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude.Size\n\nopen import Bijection equality-with-J using (_↔_)\nopen import Double-negation equality-with-J\nopen import Monad equality-with-J\n\nopen import Delay-monad\nopen import Delay-monad.Bisimilarity hiding (_∎; step-≡ˡ)\n\n-- Termination predicates.\n\nTerminates : Size → Delay A ∞ → A → Type a\nTerminates i x y = [ i ] now y ≈ x\n\ninfix 4 _⇓_\n\n_⇓_ : Delay A ∞ → A → Type a\n_⇓_ = Terminates ∞\n\n-- Terminates i is pointwise isomorphic to Terminates ∞.\n--\n-- Note that Terminates carves out an \"inductive fragment\" of [_]_≈_:\n-- the only \"coinductive\" constructor, later, does not target\n-- Terminates.\n\nTerminates↔⇓ : ∀ {i x y} → Terminates i x y ↔ x ⇓ y\nTerminates↔⇓ = record\n { surjection = record\n { logical-equivalence = record\n { to = to\n ; from = from _\n }\n ; right-inverse-of = to∘from\n }\n ; left-inverse-of = from∘to\n }\n where\n to : ∀ {i x y} → Terminates i x y → x ⇓ y\n to now = now\n to (laterʳ p) = laterʳ (to p)\n\n from : ∀ i {x y} → x ⇓ y → Terminates i x y\n from _ now = now\n from _ (laterʳ p) = laterʳ (from _ p)\n\n to∘from : ∀ {i x y} (p : x ⇓ y) → to (from i p) ≡ p\n to∘from now = refl\n to∘from (laterʳ p) = cong laterʳ (to∘from p)\n\n from∘to : ∀ {i x y} (p : Terminates i x y) → from i (to p) ≡ p\n from∘to now = refl\n from∘to (laterʳ p) = cong laterʳ (from∘to p)\n\n-- The termination relation respects weak bisimilarity.\n--\n-- This function cannot be made size-preserving in its second argument\n-- (unless A is uninhabited), see Delay-monad.Bisimilarity.Negative.\n\n⇓-respects-≈ : ∀ {i x y z} →\n Terminates i x z → x ≈ y → Terminates i y z\n⇓-respects-≈ = transitive-≈-now\n\n-- If a computation does not terminate, then it is weakly bisimilar\n-- to never.\n\n¬⇓→⇑ : ∀ {i} x → ¬ (∃ λ y → x ⇓ y) → [ i ] never ≈ x\n¬⇓→⇑ (now x) ¬⇓ = ⊥-elim (¬⇓ (_ , now))\n¬⇓→⇑ (later x) ¬⇓ = later λ { .force → ¬⇓→⇑ _ (¬⇓ ∘ Σ-map id laterʳ) }\n\n-- In the double-negation monad every computation is weakly\n-- bisimilar to either never or now something.\n\n¬¬[⇑⊎⇓] : ∀ x → ¬¬ (never ≈ x ⊎ ∃ λ y → x ⇓ y)\n¬¬[⇑⊎⇓] x = [ inj₂ , inj₁ ∘ ¬⇓→⇑ _ ] ⟨$⟩ excluded-middle\n\n-- If A is a set, then the termination predicate is propositional.\n\nTerminates-propositional :\n Is-set A → ∀ {i x y} → Is-proposition (Terminates i x y)\nTerminates-propositional A-set {i} = λ p q → irr p q refl\n where\n irr :\n ∀ {x y y′}\n (p : [ i ] now y ≈ x)\n (q : [ i ] now y′ ≈ x)\n (y≡y′ : y ≡ y′) →\n subst (([ i ]_≈ x) ∘ now) y≡y′ p ≡ q\n irr (laterʳ p) (laterʳ q) refl = cong laterʳ (irr p q refl)\n irr {y = y} now now y≡y =\n subst (([ i ]_≈ now y) ∘ now) y≡y now ≡⟨ cong (λ eq → subst (([ i ]_≈ now y) ∘ now) eq _) (A-set y≡y refl) ⟩\n subst (([ i ]_≈ now y) ∘ now) refl now ≡⟨⟩\n now ∎\n\n-- If x terminates with y and z, then y is equal to z.\n\ntermination-value-unique :\n ∀ {i x y z} → Terminates i x y → Terminates i x z → y ≡ z\ntermination-value-unique now now = refl\ntermination-value-unique (laterʳ p) (laterʳ q) =\n termination-value-unique p q\n\n-- If A is a set, then ∃ λ y → x ⇓ y is propositional.\n\n∃-Terminates-propositional :\n Is-set A → ∀ {i x} → Is-proposition (∃ (Terminates i x))\n∃-Terminates-propositional A-set (y₁ , x⇓y₁) (y₂ , x⇓y₂) =\n Σ-≡,≡→≡\n (termination-value-unique x⇓y₁ x⇓y₂)\n (Terminates-propositional A-set _ _)\n", "meta": {"hexsha": "90a9c56d4e5697ac2e2f0caaedc335263a2d64cd", "size": 3747, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Delay-monad/Termination.agda", "max_stars_repo_name": "nad/delay-monad", "max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Termination.agda", "max_issues_repo_name": "nad/delay-monad", "max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Termination.agda", "max_forks_repo_name": "nad/delay-monad", "max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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": 30.7131147541, "max_line_length": 114, "alphanum_fraction": 0.5641846811, "num_tokens": 1410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.727975460709318, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3951911486696774}} {"text": "{-# OPTIONS --rewriting #-}\n\ndata _≡_ {ℓ} {A : Set ℓ} (x : A) : A → Set ℓ where\n instance refl : x ≡ x\n\n{-# BUILTIN REWRITE _≡_ #-}\n\npostulate\n admit : ∀ {ℓ} {A : Set ℓ} → A\n X : Set\n\npostulate\n Wrap : Set → Set\n\n wrap : {A : Set} → A → Wrap A\n\n rec : (A : Set) (P : Set) → (A → P) → Wrap A → P\n\n Rec : (A : Set) (P : Set₁) → (A → P) → Wrap A → P\n\n Rec-β : {A : Set} (P : Set₁) → ∀ f → (a : A) → Rec A P f (wrap a) ≡ f a\n\n {-# REWRITE Rec-β #-} -- bug disappears without this\n\nrecord Σ {ℓ} (A : Set ℓ) (B : A → Set) : Set ℓ where\n constructor _,_\n field\n fst : A\n snd : B fst\n\nopen Σ public\n\n-- bug disappears if Comp or isFib is not wrapped in a record\n\nrecord Comp (A : X → Set) : Set where\n field\n comp : ∀ s → A s\n\nopen Comp public\n\nrecord isFib {Γ : Set} (A : Γ → Set) : Set where\n field\n lift : (p : X → Γ) → Comp (λ x → A (p x))\n\nopen isFib public\n\ncompSys : (ψ : X → Set)\n (A : Σ X (λ x → Wrap (ψ x)) → Set)\n (u : ∀ s → Wrap (ψ s)) (s : X)\n → A (s , u s)\ncompSys ψ A u s =\n rec (∀ i → ψ i) (A (s , u s))\n (λ v →\n subst (λ s → wrap (v s)) (λ s → u s) admit\n .lift (λ s → s) .comp s)\n admit\n where\n subst : (w w' : ∀ i → Wrap (ψ i)) → isFib (λ s → A (s , w s)) → isFib (λ s → A (s , w' s))\n subst = admit\n\n-- bug disappears if ×id is inlined\n×id : {A A' : Set} {B : A' → Set} (f : A → A') → Σ A (λ x → B (f x)) → Σ A' B\n×id f (a , b) = (f a , b)\n\nfib : (ψ : X → Set) (A : Σ X (λ x → Wrap (ψ x)) → Set) → isFib A\nfib ψ A .lift p .comp =\n compSys (λ x → ψ (p x .fst)) (λ xu → A (×id (λ x → p x .fst) xu)) (λ x → p x .snd)\n\n-- bug seems to disappear if the underscore in (Σ Set _) is filled in\ntemplate : (ψ : X → Set) → X → Σ (Σ X (λ x → Wrap (ψ x)) → Set) isFib\ntemplate ψ n =\n (_ , fib ψ (λ b → Rec (ψ (b .fst)) (Σ Set _) (λ _ → admit) (b .snd) .fst))\n\neq : {B : Set₁} (f : X → B) {x y : X} → f x ≡ f y\neq = admit\n\ntemplateEq : (ψ : X → Set) (n₀ : X) → template ψ n₀ ≡ template ψ n₀\ntemplateEq ψ n₀ = eq (template ψ)\n", "meta": {"hexsha": "347582945ec4c8a4e04be35bc1616f68153d8f57", "size": 1973, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue3882.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/Issue3882.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/Issue3882.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": 24.9746835443, "max_line_length": 92, "alphanum_fraction": 0.489102889, "num_tokens": 870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3951911422620773}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import groups.KernelImage\n\nmodule groups.KernelImageEmap where\n\nmodule _ {i₀ i₁ j₀ j₁ k₀ k₁}\n {G₀ : Group i₀} {H₀ : Group j₀} {K₀ : Group k₀}\n {G₁ : Group i₁} {H₁ : Group j₁} {K₁ : Group k₁}\n {ψ₀ : H₀ →ᴳ K₀} {φ₀ : G₀ →ᴳ H₀} (H₀-ab : is-abelian H₀)\n {ψ₁ : H₁ →ᴳ K₁} {φ₁ : G₁ →ᴳ H₁} (H₁-ab : is-abelian H₁)\n {ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁} {ξK : K₀ →ᴳ K₁}\n (ψ₀∼ψ₁ : CommSquareᴳ ψ₀ ψ₁ ξH ξK) \n (φ₀∼φ₁ : CommSquareᴳ φ₀ φ₁ ξG ξH) \n where\n\n module ξG = GroupHom ξG\n module ξH = GroupHom ξH\n module ξK = GroupHom ξK\n module ψ₀ = GroupHom ψ₀\n module ψ₁ = GroupHom ψ₁\n module φ₀ = GroupHom φ₀\n module φ₁ = GroupHom φ₁\n\n private\n f : Ker/Im.El ψ₀ φ₀ H₀-ab → Ker/Im.El ψ₁ φ₁ H₁-ab\n f = SetQuot-rec to pres-rel\n where\n abstract\n ξh-in-Ker : ∀ h (ψ₀h=0 : ψ₀.f h == Group.ident K₀)\n → ψ₁.f (ξH.f h) == Group.ident K₁\n ξh-in-Ker h ψ₀h=0 = (! $ ψ₀∼ψ₁ □$ᴳ h) ∙ ap ξK.f ψ₀h=0 ∙ ξK.pres-ident \n\n to : Ker.El ψ₀ → Ker/Im.El ψ₁ φ₁ H₁-ab\n to (h , ψ₀h=0) = q[ ξH.f h , ξh-in-Ker h ψ₀h=0 ]\n\n abstract\n pres-rel : ∀ {h h'} \n → ker/im-rel ψ₀ φ₀ H₀-ab h h'\n → to h == to h'\n pres-rel {(h , _)} {(h' , _)} = Trunc-rec\n λ{(g , φg=h-h') → quot-rel\n [ ξG.f g , (! $ φ₀∼φ₁ □$ᴳ g) ∙ ap ξH.f φg=h-h' ∙ ξH.pres-diff h h' ]}\n\n abstract\n f-is-hom : preserves-comp (Ker/Im.comp ψ₀ φ₀ H₀-ab) (Ker/Im.comp ψ₁ φ₁ H₁-ab) f\n f-is-hom = SetQuot-elim\n (λ{(h , _) → SetQuot-elim\n (λ{(h' , _) → ap q[_] (Ker.El=-out ψ₁ (ξH.pres-comp h h'))})\n (λ _ → prop-has-all-paths-↓)})\n (λ _ → prop-has-all-paths-↓)\n\n Ker/Im-fmap : Ker/Im ψ₀ φ₀ H₀-ab →ᴳ Ker/Im ψ₁ φ₁ H₁-ab\n Ker/Im-fmap = group-hom f f-is-hom\n\nmodule _ {i₀ i₁ j₀ j₁ k₀ k₁}\n {G₀ : Group i₀} {H₀ : Group j₀} {K₀ : Group k₀}\n {G₁ : Group i₁} {H₁ : Group j₁} {K₁ : Group k₁}\n {ψ₀ : H₀ →ᴳ K₀} {φ₀ : G₀ →ᴳ H₀} (H₀-ab : is-abelian H₀)\n {ψ₁ : H₁ →ᴳ K₁} {φ₁ : G₁ →ᴳ H₁} (H₁-ab : is-abelian H₁)\n {ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁} {ξK : K₀ →ᴳ K₁}\n (ψ₀∼ψ₁ : CommSquareᴳ ψ₀ ψ₁ ξH ξK)\n (φ₀∼φ₁ : CommSquareᴳ φ₀ φ₁ ξG ξH)\n (ξG-ise : is-equiv (GroupHom.f ξG))\n (ξH-ise : is-equiv (GroupHom.f ξH))\n (ξK-ise : is-equiv (GroupHom.f ξK))\n where\n\n private\n to : Ker/Im.El ψ₀ φ₀ H₀-ab → Ker/Im.El ψ₁ φ₁ H₁-ab\n to = GroupHom.f (Ker/Im-fmap H₀-ab H₁-ab ψ₀∼ψ₁ φ₀∼φ₁)\n \n from : Ker/Im.El ψ₁ φ₁ H₁-ab → Ker/Im.El ψ₀ φ₀ H₀-ab\n from = GroupHom.f (Ker/Im-fmap H₁-ab H₀-ab (CommSquareᴳ-inverse-v ψ₀∼ψ₁ ξH-ise ξK-ise) (CommSquareᴳ-inverse-v φ₀∼φ₁ ξG-ise ξH-ise))\n\n abstract\n to-from : ∀ x → to (from x) == x\n to-from = SetQuot-elim\n {{=-preserves-level ⟨⟩}}\n (λ{(h , _) → ap q[_] $ Ker.El=-out ψ₁ $ is-equiv.f-g ξH-ise h})\n (λ {h} {h'} _ → prop-has-all-paths-↓ {{has-level-apply SetQuot-is-set (to (from q[ h' ])) q[ h' ]}})\n\n from-to : ∀ x → from (to x) == x\n from-to = SetQuot-elim\n {{=-preserves-level ⟨⟩}}\n (λ{(h , _) → ap q[_] $ Ker.El=-out ψ₀ $ is-equiv.g-f ξH-ise h})\n (λ {h} {h'} _ → prop-has-all-paths-↓ {{has-level-apply SetQuot-is-set (from (to q[ h' ])) q[ h' ]}})\n\n Ker/Im-emap : Ker/Im ψ₀ φ₀ H₀-ab ≃ᴳ Ker/Im ψ₁ φ₁ H₁-ab\n Ker/Im-emap = Ker/Im-fmap H₀-ab H₁-ab ψ₀∼ψ₁ φ₀∼φ₁ ,\n is-eq to from to-from from-to\n", "meta": {"hexsha": "be5aed9548777c351a19aa777b0a5c17d2d5fdf1", "size": 3345, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/groups/KernelImageEmap.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/groups/KernelImageEmap.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/groups/KernelImageEmap.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 35.9677419355, "max_line_length": 135, "alphanum_fraction": 0.535426009, "num_tokens": 1634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676284, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.3951378658435145}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule sets.int.definition where\n\nopen import sum\nopen import equality\nopen import function\nopen import sets.nat.core\nopen import hott.level\n\nprivate\n data Z : Set where\n mk-int : ℕ → ℕ → Z\n\nℤ : Set\nℤ = Z\n\n_[-]_ : ℕ → ℕ → ℤ\n_[-]_ = mk-int\n\npostulate\n eq-ℤ : (n m d : ℕ) → n [-] m ≡ (d + n) [-] (d + m)\n hℤ : h 2 ℤ\n\nIsAlg-ℤ : ∀ {i} → Set i → Set _\nIsAlg-ℤ X = Σ (ℕ → ℕ → X) λ f\n → (∀ n m d → f n m ≡ f (d + n) (d + m))\n\naℤ : IsAlg-ℤ ℤ\naℤ = _[-]_ , eq-ℤ\n\nmap-Alg-ℤ : ∀ {i j}{X : Set i}{Y : Set j}\n → (X → Y) → IsAlg-ℤ X → IsAlg-ℤ Y\nmap-Alg-ℤ {X = X}{Y} h (f , u) = (g , v)\n where\n g : ℕ → ℕ → Y\n g n m = h (f n m)\n\n v : ∀ n m d → g n m ≡ g (d + n) (d + m)\n v n m d = ap h (u n m d)\n\nmap-Alg-ℤ-id : ∀ {i}{X : Set i}(aX : IsAlg-ℤ X)\n → map-Alg-ℤ (λ x → x) aX ≡ aX\nmap-Alg-ℤ-id aX = unapΣ (refl ,\n funext λ n → funext λ m → funext λ d → ap-id _)\n\nmap-Alg-ℤ-hom : ∀ {i j k}{X : Set i}{Y : Set j}{Z : Set k}\n → (f : Y → Z)(g : X → Y)(aX : IsAlg-ℤ X)\n → map-Alg-ℤ (f ∘' g) aX\n ≡ map-Alg-ℤ f (map-Alg-ℤ g aX)\nmap-Alg-ℤ-hom f g aX = unapΣ (refl , funext λ n → funext λ m → funext λ d\n → sym (ap-hom g f _))\n\nHom-ℤ : ∀ {i j}{X : Set i}{Y : Set j}\n → IsAlg-ℤ X → IsAlg-ℤ Y → Set _\nHom-ℤ {X = X}{Y} aX aY = Σ (X → Y) λ h → map-Alg-ℤ h aX ≡ aY\n\nid-ℤ : ∀ {i}{X : Set i}(aX : IsAlg-ℤ X) → Hom-ℤ aX aX\nid-ℤ aX = (λ x → x) , map-Alg-ℤ-id aX\n\n_⋆ℤ_ : ∀ {i j k}{X : Set i}{Y : Set j}{Z : Set k}\n → {aX : IsAlg-ℤ X}{aY : IsAlg-ℤ Y}{aZ : IsAlg-ℤ Z}\n → Hom-ℤ aY aZ → Hom-ℤ aX aY → Hom-ℤ aX aZ\n_⋆ℤ_ {aX = aX} (f , u) (g , v) = f ∘' g , map-Alg-ℤ-hom f g aX · ap (map-Alg-ℤ f) v · u\n\nmodule _ {i}{X : Set i}(hX : h 2 X)(aX : IsAlg-ℤ X) where\n\n elim-ℤ : ℤ → X\n elim-ℤ (mk-int n n') = proj₁ aX n n'\n\n postulate elim-β-ℤ : ∀ n m d → ap elim-ℤ (eq-ℤ n m d) ≡ proj₂ aX n m d\n\n elim-Alg-β-ℤ : map-Alg-ℤ elim-ℤ aℤ ≡ aX\n elim-Alg-β-ℤ = unapΣ (refl , funext λ n → funext λ m → funext λ d → elim-β-ℤ n m d)\n\n elim-Alg-ℤ : Hom-ℤ aℤ aX\n elim-Alg-ℤ = elim-ℤ , elim-Alg-β-ℤ\n\n postulate univ-ℤ : (h : Hom-ℤ aℤ aX) → elim-Alg-ℤ ≡ h\n\n Hom-ℤ-contr : contr (Hom-ℤ aℤ aX)\n Hom-ℤ-contr = elim-Alg-ℤ , univ-ℤ\n\nelim-prop-ℤ : ∀ {i}{X : ℤ → Set i} → (∀ n → h 1 (X n))\n → (f : ∀ n m → X (n [-] m))\n → ∀ n → X n\nelim-prop-ℤ {X = X} hX f n = subst X (i-β₀ n) (proj₂ (s₀ n))\n where\n Y : Set _\n Y = Σ ℤ X\n\n hY : h 2 Y\n hY = Σ-level hℤ λ n → h↑ (hX n)\n\n aY : IsAlg-ℤ Y\n aY = (λ n m → (n [-] m , f n m))\n , (λ n m d → unapΣ (eq-ℤ n m d , h1⇒prop (hX ((d + n) [-] (d + m))) _ _))\n\n pY : Hom-ℤ aY aℤ\n pY = proj₁ , unapΣ (refl , h1⇒prop\n (Π-level λ n → Π-level λ m → Π-level λ p → hℤ _ _) _ _)\n\n s : Hom-ℤ aℤ aY\n s = elim-Alg-ℤ hY aY\n\n s₀ : ℤ → Y\n s₀ = proj₁ s\n\n i-β₀ : ∀ n → proj₁ (s₀ n) ≡ n\n i-β₀ n = ap (λ f → proj₁ f n)\n (contr⇒prop (Hom-ℤ-contr hℤ aℤ) (pY ⋆ℤ s) (id-ℤ aℤ))\n", "meta": {"hexsha": "061b75c72676979b98dd5d943097984987a1546f", "size": 2913, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/sets/int/definition.agda", "max_stars_repo_name": "pcapriotti/agda-base", "max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z", "max_issues_repo_path": "src/sets/int/definition.agda", "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_forks_repo_path": "src/sets/int/definition.agda", "max_forks_repo_name": "pcapriotti/agda-base", "max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z", "avg_line_length": 26.0089285714, "max_line_length": 87, "alphanum_fraction": 0.4723652592, "num_tokens": 1535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.39511626366706515}} {"text": "module Krivine (Atom Const : Set) where\n\nopen import Data.Nat\nopen import Data.Sum\nopen import Data.Vec as Vec using (Vec; _∷_; [])\n\n\ndata Type : Set where\n atom : Atom → Type\n _⇒_ : Type → Type → Type\n\n\nBasis : ℕ → Set\nBasis = Vec Type\n\ndata Var : ∀ {n} → Basis n → Type → Set where\n vzero : ∀ {n} {Γ : Basis n} {τ} → Var (τ ∷ Γ) τ\n vsuc : ∀ {n} {Γ : Basis n} {σ τ} → Var Γ τ → Var (σ ∷ Γ) τ\n\ndata Term (Σ : Const → Type) {n} (Γ : Basis n) : Type → Set where\n app : ∀ {σ τ} → Term Σ Γ (σ ⇒ τ) → Term Σ Γ σ → Term Σ Γ τ\n lam : ∀ {σ τ} → Term Σ (σ ∷ Γ) τ → Term Σ Γ (σ ⇒ τ)\n var : ∀ {τ} → Var Γ τ → Term Σ Γ τ\n\n\nmutual\n data Subst (A : ∀ {n} (Γ : Basis n) → Type → Set) : ∀ {n₁} (Γ₁ : Basis n₁) {n₂} (Γ₂ : Basis n₂) → Set where\n comp : ∀ {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {n₃} {Γ₃ : Basis n₃} → Subst A Γ₁ Γ₂ → Subst A Γ₂ Γ₃ → Subst A Γ₁ Γ₃\n cons : ∀ {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {τ} → A Γ₂ τ → Subst A Γ₁ Γ₂ → Subst A (τ ∷ Γ₁) Γ₂\n id : ∀ {n} {Γ : Basis n} → Subst A Γ Γ\n lift : ∀ {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {τ} → Subst A Γ₁ Γ₂ → Subst A (τ ∷ Γ₁) (τ ∷ Γ₂)\n shift : ∀ {n} {Γ : Basis n} {τ} → Subst A Γ (τ ∷ Γ)\n\n data Thunk (A : ∀ {n} (Γ : Basis n) → Type → Set) {n} (Γ : Basis n) τ : Set where\n thunk : ∀ {n'} {Γ' : Basis n'} → A Γ' τ → Subst (Thunk A) Γ' Γ → Thunk A Γ τ\n\nlookup : ∀ {A : ∀ {n} (Γ : Basis n) → Type → Set} → (∀ {n} {Γ : Basis n} {σ} → Var Γ σ → Thunk A Γ σ) → (∀ {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {τ}\n → Thunk A Γ₁ τ → Subst (Thunk A) Γ₁ Γ₂ → Thunk A Γ₂ τ) → ∀ {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {τ} → Var Γ₁ τ → Subst (Thunk A) Γ₁ Γ₂ → Thunk A Γ₂ τ\nlookup {A} box under = lookup'\n where\n lookup' : ∀ {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {τ} → Var Γ₁ τ → Subst (Thunk A) Γ₁ Γ₂ → Thunk A Γ₂ τ\n lookup' v (comp ρ σ) = under (lookup' v ρ) σ\n lookup' vzero (cons x _) = x\n lookup' (vsuc v) (cons _ σ) = lookup' v σ\n lookup' v id = box v\n lookup' vzero (lift _) = box vzero\n lookup' (vsuc v) (lift σ) = under (lookup' v σ) shift\n lookup' v shift = box (vsuc v)\n\n\nboxvar : ∀ {Σ : Const → Type} {n} {Γ : Basis n} {τ} → Var Γ τ → Thunk (Term Σ) Γ τ\nboxvar v = thunk (var v) id\n\nclose : ∀ {Σ : Const → Type} {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {τ} → Thunk (Term Σ) Γ₁ τ → Subst (Thunk (Term Σ)) Γ₁ Γ₂ → Thunk (Term Σ) Γ₂ τ\nclose (thunk t ρ) σ = thunk t (comp ρ σ)\n\n\nmutual\n subst : ∀ {Σ : Const → Type} {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {τ} → Term Σ Γ₁ τ → Subst (Thunk (Term Σ)) Γ₁ Γ₂ → Term Σ Γ₂ τ\n subst (app s t) σ = app (subst s σ) (subst t σ)\n subst (lam t) σ = lam (subst t (lift σ))\n subst (var v) id = var v\n subst (var v) σ = force (lookup boxvar close v σ)\n\n force : ∀ {Σ : Const → Type} {n} {Γ : Basis n} {τ} → Thunk (Term Σ) Γ τ → Term Σ Γ τ\n force (thunk t ρ) = subst t ρ\n\n\ndata Context (A : ∀ {n} (Γ : Basis n) → Type → Set) : ∀ {n₁} (Γ₁ : Basis n₁) {n₂} (Γ₂ : Basis n₂) → Type → Type → Set where\n app₁ : ∀ {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {ρ σ τ} → Context A Γ₁ Γ₂ σ τ → A Γ₁ ρ → Context A Γ₁ Γ₂ (ρ ⇒ σ) τ\n app₂ : ∀ {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {ρ σ τ} → A Γ₁ (ρ ⇒ σ) → Context A Γ₁ Γ₂ σ τ → Context A Γ₁ Γ₂ ρ τ\n lam₁ : ∀ {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {ρ σ τ} → Context A Γ₁ Γ₂ (ρ ⇒ σ) τ → Context A (ρ ∷ Γ₁) Γ₂ σ τ\n top : ∀ {n} {Γ : Basis n} {τ} → Context A Γ Γ τ τ\n\nfoldctx : ∀ {A : ∀ {n} (Γ : Basis n) → Type → Set} {Σ : Const → Type} {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {σ τ}\n → (∀ {n} {Γ : Basis n} {ρ} → A Γ ρ → Term Σ Γ ρ) → Term Σ Γ₁ σ → Context A Γ₁ Γ₂ σ τ → Term Σ Γ₂ τ\nfoldctx f z (app₁ ctx y) = foldctx f (app z (f y)) ctx\nfoldctx f z (app₂ x ctx) = foldctx f (app (f x) z) ctx\nfoldctx f z (lam₁ ctx) = foldctx f (lam z) ctx\nfoldctx _ z top = z\n\n\ndata Head (Σ : Const → Type) {n} (Γ : Basis n) : Type → Set where\n var : ∀ {τ} → Var Γ τ → Head Σ Γ τ\n\ndata Spine (Σ : Const → Type) (A : (∀ {n} (Γ : Basis n) → Type → Set) → ∀ {n} (Γ : Basis n) → Type → Set) {n} (Γ : Basis n) τ : Set where\n spine : ∀ {n'} {Γ' : Basis n'} {σ} → Head Σ Γ' σ → Context (A (Term Σ)) Γ' Γ σ τ → Spine Σ A Γ τ\n\neval : ∀ {Σ : Const → Type} {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {σ τ} → Thunk (Term Σ) Γ₁ σ → Context (Thunk (Term Σ)) Γ₁ Γ₂ σ τ → Spine Σ Thunk Γ₂ τ\neval (thunk (app s t) σ) ctx = eval (thunk s σ) (app₁ ctx (thunk t σ))\neval (thunk (lam t) σ) (app₁ ctx x) = eval (thunk t (cons x σ)) ctx\neval (thunk (lam t) σ) ctx = eval (thunk t (lift σ)) (lam₁ ctx)\neval (thunk (var v) id) ctx = spine (var v) ctx\neval (thunk (var v) σ) ctx = eval (lookup boxvar close v σ) ctx\n\n\ndata Subst' (A : ∀ {n} (Γ : Basis n) → Type → Set) : ∀ {n₁} (Γ₁ : Basis n₁) {n₂} (Γ₂ : Basis n₂) → Set where\n comp : ∀ {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} {n₃} {Γ₃ : Basis n₃} → Subst A Γ₁ Γ₂ → Subst' A Γ₂ Γ₃ → Subst' A Γ₁ Γ₃\n id : ∀ {n} {Γ : Basis n} → Subst' A Γ Γ\n\ndata Thunk' (A : ∀ {n} (Γ : Basis n) → Type → Set) {n} (Γ : Basis n) τ : Set where\n thunk : ∀ {n'} {Γ' : Basis n'} → A Γ' τ → Subst' (Thunk' A) Γ' Γ → Thunk' A Γ τ\n\ndata Machine (Σ : Const → Type) {n} (Γ : Basis n) τ : Set where\n machine : ∀ {n'} {Γ' : Basis n'} {σ} → Thunk' (Term Σ) Γ' σ → Context (Thunk' (Term Σ)) Γ' Γ σ τ → Machine Σ Γ τ\n\ncoerce : ∀ {A : ∀ {n} (Γ : Basis n) → Type → Set} {n₁} {Γ₁ : Basis n₁} {n₂} {Γ₂ : Basis n₂} → Subst' A Γ₁ Γ₂ → Subst A Γ₁ Γ₂\ncoerce (comp ρ σ) = comp ρ (coerce σ)\ncoerce id = id\n\nstep : ∀ {Σ : Const → Type} {n} {Γ : Basis n} {τ} → Machine Σ Γ τ → Spine Σ Thunk' Γ τ ⊎ Machine Σ Γ τ\nstep (machine (thunk (var v) (comp shift σ)) ctx) = inj₂ (machine (thunk (var (vsuc v)) σ) ctx)\nstep (machine (thunk (var vzero) (comp (cons (thunk u π) _) σ)) ctx) = inj₂ (machine (thunk u (comp (coerce π) σ)) ctx)\nstep (machine (thunk (var vzero) (comp (lift _) σ)) ctx) = inj₂ (machine (thunk (var vzero) σ) ctx)\nstep (machine (thunk (var (vsuc v)) (comp (cons (thunk _ _) ρ) σ)) ctx) = inj₂ (machine (thunk (var v) (comp ρ σ)) ctx)\nstep (machine (thunk (var (vsuc v)) (comp (lift ρ) σ)) ctx) = inj₂ (machine (thunk (var v) (comp ρ (comp shift σ))) ctx)\nstep (machine (thunk t (comp (comp π ρ) σ)) ctx) = inj₂ (machine (thunk t (comp π (comp ρ σ))) ctx)\nstep (machine (thunk t (comp id σ)) ctx) = inj₂ (machine (thunk t σ) ctx)\nstep (machine (thunk t σ) (app₂ (thunk s ρ) ctx)) = inj₂ (machine (thunk s ρ) (app₁ ctx (thunk t σ)))\nstep (machine (thunk (app s (var v)) σ) ctx) = inj₂ (machine (thunk (var v) σ) (app₂ (thunk s σ) ctx))\nstep (machine (thunk (app s t) σ) ctx) = inj₂ (machine (thunk s σ) (app₁ ctx (thunk t σ)))\nstep (machine (thunk (lam t) σ) (app₁ ctx x)) = inj₂ (machine (thunk t (comp (cons x (coerce σ)) id)) ctx)\nstep (machine (thunk (lam t) σ) ctx) = inj₂ (machine (thunk t (comp (lift (coerce σ)) id)) (lam₁ ctx))\nstep (machine (thunk (var v) id) ctx) = inj₁ (spine (var v) ctx)\n\nreduce : ∀ {Σ : Const → Type} {n} {Γ : Basis n} {τ} → Machine Σ Γ τ → Spine Σ Thunk' Γ τ\nreduce m with step m\n... | inj₁ x = x\n... | inj₂ m' = reduce m'\n", "meta": {"hexsha": "a99c87ea36792756e94ba739caefb9d2ddc57840", "size": 7930, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Krivine.agda", "max_stars_repo_name": "cls/strong-krivine", "max_stars_repo_head_hexsha": "46b3960841fd45d7db9e92906c3c2be562df0385", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-01-31T07:10:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-13T23:05:34.000Z", "max_issues_repo_path": "Krivine.agda", "max_issues_repo_name": "cls/strong-krivine", "max_issues_repo_head_hexsha": "46b3960841fd45d7db9e92906c3c2be562df0385", "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": "Krivine.agda", "max_forks_repo_name": "cls/strong-krivine", "max_forks_repo_head_hexsha": "46b3960841fd45d7db9e92906c3c2be562df0385", "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": 61.0, "max_line_length": 161, "alphanum_fraction": 0.4793190416, "num_tokens": 3255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.39500606492774704}} {"text": "{-# OPTIONS --universe-polymorphism --allow-unsolved-metas #-}\n\nmodule Issue209 where\n\npostulate\n Level : Set\n zero : Level\n suc : Level → Level\n _⊔_ : Level -> Level -> Level\n\n{-# BUILTIN LEVEL Level #-}\n{-# BUILTIN LEVELZERO zero #-}\n{-# BUILTIN LEVELSUC suc #-}\n{-# BUILTIN LEVELMAX _⊔_ #-}\n\ndata _≡_ {a} {A : Set a} (x : A) : A → Set where\n refl : x ≡ x\n\ndata _≅_ {a} {A : Set a} (x : A) : ∀ {b} {B : Set b} → B → Set where\n refl : x ≅ x\n\nsubst : ∀ {a p} {A : Set a} (P : A → Set p) {x y} → x ≡ y → P x → P y\nsubst P refl p = p\n\nlemma : ∀ {A} (P : A → Set) {x y} (eq : x ≡ y) z →\n subst P eq z ≅ z\nlemma P refl z = refl\n\n-- An internal error has occurred. Please report this as a bug.\n-- Location of the error: src/full/Agda/TypeChecking/Telescope.hs:51\n\n-- The problematic call to reorderTel is\n-- reorderTel tel3\n-- in Agda.TypeChecking.Rules.LHS.Instantiate.", "meta": {"hexsha": "bff931cd27d9941f9b80f3673dec9534c5aa50bf", "size": 889, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/succeed/Issue209.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/succeed/Issue209.agda", "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "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/succeed/Issue209.agda", "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "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": 26.1470588235, "max_line_length": 69, "alphanum_fraction": 0.5871766029, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.3949651340771981}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.ZCohomology.Properties where\n\nopen import Cubical.ZCohomology.Base\nopen import Cubical.HITs.S1\nopen import Cubical.HITs.Sn\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Pointed\nopen import Cubical.Foundations.Transport\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.GroupoidLaws\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Data.Empty\nopen import Cubical.Data.Sigma hiding (_×_)\nopen import Cubical.HITs.Susp\nopen import Cubical.HITs.Wedge\nopen import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2)\nopen import Cubical.HITs.Nullification\nopen import Cubical.Data.Int hiding (_+_)\nopen import Cubical.Data.Nat\nopen import Cubical.Data.Prod\nopen import Cubical.HITs.Truncation renaming (elim to trElim ; map to trMap ; rec to trRec ; elim3 to trElim3)\nopen import Cubical.Homotopy.Loopspace\nopen import Cubical.Homotopy.Connected\nopen import Cubical.Homotopy.Freudenthal\nopen import Cubical.HITs.SmashProduct.Base\nopen import Cubical.Structures.Group\n\n\nopen import Cubical.HITs.Pushout\nopen import Cubical.Data.Sum.Base\nopen import Cubical.Data.HomotopyGroup\nopen import Cubical.Data.Bool hiding (_⊕_)\n\nopen import Cubical.ZCohomology.KcompPrelims\n\nprivate\n variable\n ℓ ℓ' : Level\n A : Type ℓ\n B : Type ℓ'\n A' : Pointed ℓ\n\n\n{- Equivalence between cohomology of A and reduced cohomology of (A + 1) -}\ncoHomRed+1Equiv : (n : ℕ) →\n (A : Type ℓ) →\n (coHom n A) ≡ (coHomRed n ((A ⊎ Unit , inr (tt))))\ncoHomRed+1Equiv zero A i = ∥ helpLemma {C = (Int , pos 0)} i ∥₂\n module coHomRed+1 where\n helpLemma : {C : Pointed ℓ} → ( (A → (typ C)) ≡ ((((A ⊎ Unit) , inr (tt)) →∙ C)))\n helpLemma {C = C} = isoToPath (iso map1\n map2\n (λ b → linvPf b)\n (λ _ → refl))\n where\n map1 : (A → typ C) → ((((A ⊎ Unit) , inr (tt)) →∙ C))\n map1 f = map1' , refl\n module helpmap where\n map1' : A ⊎ Unit → fst C\n map1' (inl x) = f x\n map1' (inr x) = pt C\n\n map2 : ((((A ⊎ Unit) , inr (tt)) →∙ C)) → (A → typ C)\n map2 (g , pf) x = g (inl x)\n\n linvPf : (b :((((A ⊎ Unit) , inr (tt)) →∙ C))) → map1 (map2 b) ≡ b\n linvPf (f , snd) i = (λ x → helper x i) , λ j → snd ((~ i) ∨ j)\n where\n helper : (x : A ⊎ Unit) → ((helpmap.map1') (map2 (f , snd)) x) ≡ f x\n helper (inl x) = refl\n helper (inr tt) = sym snd\n\ncoHomRed+1Equiv (suc n) A i = ∥ coHomRed+1.helpLemma A i {C = ((coHomK (suc n)) , ∣ north ∣)} i ∥₂\n\n-----------\n\nKn→ΩKn+1 : (n : ℕ) → coHomK n → typ (Ω (coHomK-ptd (suc n)))\nKn→ΩKn+1 n = Iso.fun (Iso2-Kn-ΩKn+1 n)\n\nΩKn+1→Kn : {n : ℕ} → typ (Ω (coHomK-ptd (suc n))) → coHomK n\nΩKn+1→Kn {n = n} = Iso.inv (Iso2-Kn-ΩKn+1 n)\n\nKn≃ΩKn+1 : {n : ℕ} → coHomK n ≃ typ (Ω (coHomK-ptd (suc n)))\nKn≃ΩKn+1 {n = n} = isoToEquiv (Iso-Kn-ΩKn+1 n)\n\n---------- Algebra/Group stuff --------\n\n0ₖ : {n : ℕ} → coHomK n\n0ₖ {n = zero} = pt (coHomK-ptd 0)\n0ₖ {n = suc n} = pt (coHomK-ptd (suc n))\n\ninfixr 35 _+ₖ_\n\n_+ₖ_ : {n : ℕ} → coHomK n → coHomK n → coHomK n\n_+ₖ_ {n = n} x y = ΩKn+1→Kn (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y)\n\n-ₖ_ : {n : ℕ} → coHomK n → coHomK n\n-ₖ_ {n = n} x = ΩKn+1→Kn (sym (Kn→ΩKn+1 n x))\n\n\nKn→ΩKn+10ₖ : (n : ℕ) → Kn→ΩKn+1 n 0ₖ ≡ refl\nKn→ΩKn+10ₖ zero = refl\nKn→ΩKn+10ₖ (suc n) = (λ i → cong ∣_∣ (rCancel (merid north) i))\n\nrUnitₖ : {n : ℕ} (x : coHomK n) → x +ₖ 0ₖ ≡ x\nrUnitₖ {n = zero} x = cong ΩKn+1→Kn (sym (rUnit (Kn→ΩKn+1 zero x))) ∙\n Iso.leftInv (Iso2-Kn-ΩKn+1 zero) x\nrUnitₖ {n = suc n} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) x ∙ Kn→ΩKn+10ₖ (suc n) i)) ∙\n (λ i → ΩKn+1→Kn (rUnit (Kn→ΩKn+1 (suc n) x) (~ i))) ∙\n Iso.leftInv (Iso2-Kn-ΩKn+1 (suc n)) x\n\nlUnitₖ : {n : ℕ} (x : coHomK n) → 0ₖ +ₖ x ≡ x\nlUnitₖ {n = zero} x = cong ΩKn+1→Kn (sym (lUnit (Kn→ΩKn+1 zero x))) ∙\n Iso.leftInv (Iso2-Kn-ΩKn+1 zero) x\nlUnitₖ {n = suc n} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc n) i ∙ Kn→ΩKn+1 (suc n) x)) ∙\n (λ i → ΩKn+1→Kn (lUnit (Kn→ΩKn+1 (suc n) x) (~ i))) ∙\n Iso.leftInv (Iso2-Kn-ΩKn+1 (suc n)) x\n\nrCancelₖ : {n : ℕ} (x : coHomK n) → x +ₖ (-ₖ x) ≡ 0ₖ\nrCancelₖ {n = zero} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 zero x ∙ Iso.rightInv (Iso2-Kn-ΩKn+1 zero) (sym (Kn→ΩKn+1 zero x)) i)) ∙\n cong ΩKn+1→Kn (rCancel (Kn→ΩKn+1 zero x))\nrCancelₖ {n = suc zero} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 1 x ∙ Iso.rightInv (Iso2-Kn-ΩKn+1 1) (sym (Kn→ΩKn+1 1 x)) i)) ∙\n cong ΩKn+1→Kn (rCancel (Kn→ΩKn+1 1 x))\nrCancelₖ {n = suc (suc n)} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 (2 + n) x ∙ Iso.rightInv (Iso2-Kn-ΩKn+1 (2 + n)) (sym (Kn→ΩKn+1 (2 + n) x)) i)) ∙\n cong ΩKn+1→Kn (rCancel (Kn→ΩKn+1 (2 + n) x)) ∙\n (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc (suc n)) (~ i))) ∙\n Iso.leftInv (Iso2-Kn-ΩKn+1 (suc (suc n))) 0ₖ\n\nlCancelₖ : {n : ℕ} (x : coHomK n) → (-ₖ x) +ₖ x ≡ 0ₖ\nlCancelₖ {n = zero} x = (λ i → ΩKn+1→Kn (Iso.rightInv (Iso2-Kn-ΩKn+1 zero) (sym (Kn→ΩKn+1 zero x)) i ∙ Kn→ΩKn+1 zero x)) ∙\n cong ΩKn+1→Kn (lCancel (Kn→ΩKn+1 zero x))\nlCancelₖ {n = suc zero} x = ((λ i → ΩKn+1→Kn (Iso.rightInv (Iso2-Kn-ΩKn+1 1) (sym (Kn→ΩKn+1 1 x)) i ∙ Kn→ΩKn+1 1 x))) ∙\n cong ΩKn+1→Kn (lCancel (Kn→ΩKn+1 1 x))\nlCancelₖ {n = suc (suc n)} x = (λ i → ΩKn+1→Kn (Iso.rightInv (Iso2-Kn-ΩKn+1 (2 + n)) (sym (Kn→ΩKn+1 (2 + n) x)) i ∙ Kn→ΩKn+1 (2 + n) x)) ∙\n cong ΩKn+1→Kn (lCancel (Kn→ΩKn+1 (2 + n) x)) ∙\n (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc (suc n)) (~ i))) ∙\n Iso.leftInv (Iso2-Kn-ΩKn+1 (suc (suc n))) 0ₖ\n\n\nassocₖ : {n : ℕ} (x y z : coHomK n) → ((x +ₖ y) +ₖ z) ≡ (x +ₖ (y +ₖ z))\nassocₖ {n = n} x y z = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 n (ΩKn+1→Kn (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y)) ∙ Kn→ΩKn+1 n z)) ∙\n (λ i → ΩKn+1→Kn (Iso.rightInv (Iso2-Kn-ΩKn+1 n) (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y) i ∙ Kn→ΩKn+1 n z)) ∙\n (λ i → ΩKn+1→Kn (assoc (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) (Kn→ΩKn+1 n z) (~ i))) ∙\n (λ i → ΩKn+1→Kn ((Kn→ΩKn+1 n x) ∙ Iso.rightInv (Iso2-Kn-ΩKn+1 n) ((Kn→ΩKn+1 n y ∙ Kn→ΩKn+1 n z)) (~ i)))\n\ncommₖ : {n : ℕ} (x y : coHomK n) → (x +ₖ y) ≡ (y +ₖ x)\ncommₖ {n = n} x y i = ΩKn+1→Kn (EH-instance (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) i)\n where\n EH-instance : (p q : typ (Ω ((∥ S₊ (suc n) ∥ (2 + (suc n))) , ∣ north ∣))) → p ∙ q ≡ q ∙ p\n EH-instance = transport (λ i → (p q : K-Id n (~ i)) → p ∙ q ≡ q ∙ p)\n λ p q → Eckmann-Hilton 0 p q\n where\n K-Id : (n : HLevel) → typ (Ω (hLevelTrunc (3 + n) (S₊ (1 + n)) , ∣ north ∣)) ≡ typ ((Ω^ 2) (hLevelTrunc (4 + n) (S₊ (2 + n)) , ∣ north ∣ ))\n K-Id n = (λ i → typ (Ω (isoToPath (Iso2-Kn-ΩKn+1 (suc n)) i , hcomp (λ k → λ { (i = i0) → ∣ north ∣\n ; (i = i1) → transportRefl (λ j → ∣ rCancel (merid north) k j ∣) k})\n (transp (λ j → isoToPath (Iso2-Kn-ΩKn+1 (suc n)) (i ∧ j)) (~ i) ∣ north ∣))))\n\n-distrₖ : {n : ℕ} → (x y : coHomK n) → -ₖ (x +ₖ y) ≡ (-ₖ x) +ₖ (-ₖ y)\n-distrₖ {n = n} x y = (λ i → ΩKn+1→Kn (sym (Kn→ΩKn+1 n (ΩKn+1→Kn (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y))))) ∙\n (λ i → ΩKn+1→Kn (sym (Iso.rightInv (Iso2-Kn-ΩKn+1 n) (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y) i))) ∙\n (λ i → ΩKn+1→Kn (symDistr (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) i)) ∙\n (λ i → ΩKn+1→Kn (Iso.rightInv (Iso2-Kn-ΩKn+1 n) (sym (Kn→ΩKn+1 n y)) (~ i) ∙ (Iso.rightInv (Iso2-Kn-ΩKn+1 n) (sym (Kn→ΩKn+1 n x)) (~ i)))) ∙\n commₖ (-ₖ y) (-ₖ x)\n\n\n---- Group structure of cohomology groups ---\n\nprivate\n § : isSet ∥ A ∥₂\n § = setTruncIsSet\n\n_+ₕ_ : {n : ℕ} → coHom n A → coHom n A → coHom n A\n_+ₕ_ = sElim2 (λ _ _ → §) λ a b → ∣ (λ x → a x +ₖ b x) ∣₂\n\n-ₕ : {n : ℕ} → coHom n A → coHom n A\n-ₕ = sRec § λ a → ∣ (λ x → -ₖ a x) ∣₂\n\n0ₕ : {n : ℕ} → coHom n A\n0ₕ = ∣ (λ _ → 0ₖ) ∣₂\n\nrUnitₕ : {n : ℕ} (x : coHom n A) → x +ₕ 0ₕ ≡ x\nrUnitₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))\n λ a i → ∣ funExt (λ x → rUnitₖ (a x)) i ∣₂\n\nlUnitₕ : {n : ℕ} (x : coHom n A) → 0ₕ +ₕ x ≡ x\nlUnitₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))\n λ a i → ∣ funExt (λ x → lUnitₖ (a x)) i ∣₂\n\nrCancelₕ : {n : ℕ} (x : coHom n A) → x +ₕ (-ₕ x) ≡ 0ₕ\nrCancelₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))\n λ a i → ∣ funExt (λ x → rCancelₖ (a x)) i ∣₂\n\nlCancelₕ : {n : ℕ} (x : coHom n A) → (-ₕ x) +ₕ x ≡ 0ₕ\nlCancelₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))\n λ a i → ∣ funExt (λ x → lCancelₖ (a x)) i ∣₂\n\nassocₕ : {n : ℕ} (x y z : coHom n A) → ((x +ₕ y) +ₕ z) ≡ (x +ₕ (y +ₕ z))\nassocₕ = elim3 (λ _ _ _ → isOfHLevelPath 1 (§ _ _))\n λ a b c i → ∣ funExt (λ x → assocₖ (a x) (b x) (c x)) i ∣₂\n\ncommₕ : {n : ℕ} (x y : coHom n A) → (x +ₕ y) ≡ (y +ₕ x)\ncommₕ {n = n} = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _))\n λ a b i → ∣ funExt (λ x → commₖ (a x) (b x)) i ∣₂\n\n\n\n---- Group structure of reduced cohomology groups (in progress - might need K to compute properly first) ---\n\n+ₕ∙ : {A : Pointed ℓ} (n : ℕ) → coHomRed n A → coHomRed n A → coHomRed n A\n+ₕ∙ zero = sElim2 (λ _ _ → §) λ { (a , pa) (b , pb) → ∣ (λ x → a x +ₖ b x) , (λ i → (pa i +ₖ pb i)) ∣₂ }\n+ₕ∙ (suc n) = sElim2 (λ _ _ → §) λ { (a , pa) (b , pb) → ∣ (λ x → a x +ₖ b x) , (λ i → pa i +ₖ pb i) ∙ lUnitₖ 0ₖ ∣₂ }\n\n-ₕ∙ : {A : Pointed ℓ} (n : ℕ) → coHomRed n A → coHomRed n A\n-ₕ∙ zero = sRec § λ {(a , pt) → ∣ (λ x → -ₖ a x ) , (λ i → -ₖ (pt i)) ∣₂}\n-ₕ∙ (suc zero) = sRec § λ {(a , pt) → ∣ (λ x → -ₖ a x ) , (λ i → -ₖ (pt i)) ∙ (λ i → ΩKn+1→Kn (sym (Kn→ΩKn+10ₖ (suc zero) i))) ∣₂}\n-ₕ∙ (suc (suc n)) = sRec § λ {(a , pt) → ∣ (λ x → -ₖ a x ) , (λ i → -ₖ (pt i)) ∙\n (λ i → ΩKn+1→Kn (sym (Kn→ΩKn+10ₖ (suc (suc n)) i))) ∙\n (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc (suc n)) (~ i))) ∙\n Iso.leftInv (Iso2-Kn-ΩKn+1 (suc (suc n))) ∣ north ∣ ∣₂}\n\n0ₕ∙ : {A : Pointed ℓ} (n : ℕ) → coHomRed n A\n0ₕ∙ zero = ∣ (λ _ → 0ₖ) , refl ∣₂\n0ₕ∙ (suc n) = ∣ (λ _ → 0ₖ) , refl ∣₂\n", "meta": {"hexsha": "ac57dd851fec3d86e4f0df80c2bd26208a93c1e5", "size": 10593, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/ZCohomology/Properties.agda", "max_stars_repo_name": "bijan2005/univalent-foundations", "max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "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": "Cubical/ZCohomology/Properties.agda", "max_issues_repo_name": "bijan2005/univalent-foundations", "max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "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": "Cubical/ZCohomology/Properties.agda", "max_forks_repo_name": "bijan2005/univalent-foundations", "max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "avg_line_length": 46.6651982379, "max_line_length": 162, "alphanum_fraction": 0.4911734164, "num_tokens": 4917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321964553657, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.394911717128393}} {"text": "module Text.Lex where\n\nopen import Prelude\n\nrecord TokenDFA {s} (A : Set) (Tok : Set) : Set (lsuc s) where\n field\n State : Set s\n initial : State\n accept : State → Maybe Tok\n consume : A → State → Maybe State\n\ninstance\n FunctorTokenDFA : ∀ {s} {A : Set} → Functor (TokenDFA {s = s} A)\n TokenDFA.State (fmap {{FunctorTokenDFA}} f dfa) = TokenDFA.State dfa\n TokenDFA.initial (fmap {{FunctorTokenDFA}} f dfa) = TokenDFA.initial dfa\n TokenDFA.accept (fmap {{FunctorTokenDFA}} f dfa) s = f <$> TokenDFA.accept dfa s\n TokenDFA.consume (fmap {{FunctorTokenDFA}} f dfa) = TokenDFA.consume dfa\n\nkeywordToken : {A : Set} {{EqA : Eq A}} → List A → TokenDFA A ⊤\nTokenDFA.State (keywordToken {A = A} kw) = List A\nTokenDFA.initial (keywordToken kw) = kw\nTokenDFA.accept (keywordToken kw) [] = just _\nTokenDFA.accept (keywordToken kw) (_ ∷ _) = nothing\nTokenDFA.consume (keywordToken kw) _ [] = nothing\nTokenDFA.consume (keywordToken kw) y (x ∷ xs) = ifYes (x == y) then just xs else nothing\n\nmatchToken : ∀ {A : Set} (p : A → Bool) → TokenDFA A (List (Σ A (IsTrue ∘ p)))\nTokenDFA.State (matchToken {A = A} p) = List (Σ A (IsTrue ∘ p))\nTokenDFA.initial (matchToken _) = []\nTokenDFA.accept (matchToken _) xs = just (reverse xs)\nTokenDFA.consume (matchToken p) x xs = if′ p x then just ((x , it) ∷ xs) else nothing\n\nnatToken : TokenDFA Char Nat\nnatToken = pNat <$> matchToken isDigit\n where pNat = foldl (λ { n (d , _) → 10 * n + (charToNat d - charToNat '0') }) 0\n\nidentToken : ∀ {A : Set} → (A → Bool) → (A → Bool) → TokenDFA A (List A)\nTokenDFA.State (identToken {A = A} _ _) = Maybe (List A)\nTokenDFA.initial (identToken _ _) = nothing\nTokenDFA.accept (identToken _ _) = fmap reverse\nTokenDFA.consume (identToken first _) x nothing = if first x then just (just [ x ]) else nothing\nTokenDFA.consume (identToken _ then) x (just xs) = if then x then just (just (x ∷ xs)) else nothing\n\nmodule _ {s : Level} {A Tok : Set} where\n private\n DFA = TokenDFA {s = s} A Tok\n open TokenDFA\n\n init : DFA → Σ DFA State\n init d = d , initial d\n\n feed : A → Σ DFA State → Either DFA (Σ DFA State)\n feed x (d , s) = maybe (left d) (right ∘ _,_ d) (consume d x s)\n\n accepts : List (Σ DFA State) → List Tok\n accepts = concatMap (λ { (d , s) → maybe [] [_] (accept d s) })\n\n tokenize-loop : List DFA → List (Σ DFA State) → List A → List Tok\n tokenize-loop idle active [] =\n case accepts active of λ where\n [] → [] -- not quite right if there are active DFAs\n (t ∷ _) → [ t ]\n tokenize-loop idle [] (x ∷ xs) =\n flip uncurry (partitionMap (feed x) (map init idle)) λ where\n idle₁ [] → []\n idle₁ active₁ → tokenize-loop idle₁ active₁ xs\n tokenize-loop idle active (x ∷ xs) =\n flip uncurry (partitionMap (feed x) active) λ where\n idle₁ [] →\n case accepts active of λ where\n [] → []\n (t ∷ _) →\n flip uncurry (partitionMap (feed x) (map init (idle ++ idle₁))) λ where\n _ [] → t ∷ []\n idle₂ active₂ → t List.∷ tokenize-loop idle₂ active₂ xs\n idle₁ active₁ → tokenize-loop (idle ++ idle₁) active₁ xs\n\n tokenize : List (TokenDFA {s = s} A Tok) → List A → List Tok\n tokenize dfas xs = tokenize-loop dfas [] xs\n", "meta": {"hexsha": "0266e1640b9c8848f6e875e49d9c5f305d6a5ef5", "size": 3342, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Text/Lex.agda", "max_stars_repo_name": "t-more/agda-prelude", "max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "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/Text/Lex.agda", "max_issues_repo_name": "t-more/agda-prelude", "max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "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/Text/Lex.agda", "max_forks_repo_name": "t-more/agda-prelude", "max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "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": 41.775, "max_line_length": 101, "alphanum_fraction": 0.6038300419, "num_tokens": 1085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.39491171035474965}} {"text": "{-\nThis second-order term syntax was created from the following second-order syntax description:\n\nsyntax CommRing | CR\n\ntype\n * : 0-ary\n\nterm\n zero : * | 𝟘\n add : * * -> * | _⊕_ l20\n one : * | 𝟙\n mult : * * -> * | _⊗_ l30\n neg : * -> * | ⊖_ r50\n\ntheory\n (𝟘U⊕ᴸ) a |> add (zero, a) = a\n (𝟘U⊕ᴿ) a |> add (a, zero) = a\n (⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c))\n (⊕C) a b |> add(a, b) = add(b, a)\n (𝟙U⊗ᴸ) a |> mult (one, a) = a\n (𝟙U⊗ᴿ) a |> mult (a, one) = a\n (⊗A) a b c |> mult (mult(a, b), c) = mult (a, mult(b, c))\n (⊗D⊕ᴸ) a b c |> mult (a, add (b, c)) = add (mult(a, b), mult(a, c))\n (⊗D⊕ᴿ) a b c |> mult (add (a, b), c) = add (mult(a, c), mult(b, c))\n (𝟘X⊗ᴸ) a |> mult (zero, a) = zero\n (𝟘X⊗ᴿ) a |> mult (a, zero) = zero\n (⊖N⊕ᴸ) a |> add (neg (a), a) = zero\n (⊖N⊕ᴿ) a |> add (a, neg (a)) = zero\n (⊗C) a b |> mult(a, b) = mult(b, a)\n-}\n\n\nmodule CommRing.Syntax where\n\nopen import SOAS.Common\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.Families.Core\nopen import SOAS.Construction.Structure\nopen import SOAS.ContextMaps.Inductive\n\nopen import SOAS.Metatheory.Syntax\n\nopen import CommRing.Signature\n\nprivate\n variable\n Γ Δ Π : Ctx\n α : *T\n 𝔛 : Familyₛ\n\n-- Inductive term declaration\nmodule CR:Terms (𝔛 : Familyₛ) where\n\n data CR : Familyₛ where\n var : ℐ ⇾̣ CR\n mvar : 𝔛 α Π → Sub CR Π Γ → CR α Γ\n\n 𝟘 : CR * Γ\n _⊕_ : CR * Γ → CR * Γ → CR * Γ\n 𝟙 : CR * Γ\n _⊗_ : CR * Γ → CR * Γ → CR * Γ\n ⊖_ : CR * Γ → CR * Γ\n\n infixl 20 _⊕_\n infixl 30 _⊗_\n infixr 50 ⊖_\n\n open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛\n\n CRᵃ : MetaAlg CR\n CRᵃ = record\n { 𝑎𝑙𝑔 = λ where\n (zeroₒ ⋮ _) → 𝟘\n (addₒ ⋮ a , b) → _⊕_ a b\n (oneₒ ⋮ _) → 𝟙\n (multₒ ⋮ a , b) → _⊗_ a b\n (negₒ ⋮ a) → ⊖_ a\n ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }\n\n module CRᵃ = MetaAlg CRᵃ\n\n module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where\n\n open MetaAlg 𝒜ᵃ\n\n 𝕤𝕖𝕞 : CR ⇾̣ 𝒜\n 𝕊 : Sub CR Π Γ → Π ~[ 𝒜 ]↝ Γ\n 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t\n 𝕊 (t ◂ σ) (old v) = 𝕊 σ v\n 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)\n 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v\n\n 𝕤𝕖𝕞 𝟘 = 𝑎𝑙𝑔 (zeroₒ ⋮ tt)\n 𝕤𝕖𝕞 (_⊕_ a b) = 𝑎𝑙𝑔 (addₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 𝟙 = 𝑎𝑙𝑔 (oneₒ ⋮ tt)\n 𝕤𝕖𝕞 (_⊗_ a b) = 𝑎𝑙𝑔 (multₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 (⊖_ a) = 𝑎𝑙𝑔 (negₒ ⋮ 𝕤𝕖𝕞 a)\n\n 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ CRᵃ 𝒜ᵃ 𝕤𝕖𝕞\n 𝕤𝕖𝕞ᵃ⇒ = record\n { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }\n ; ⟨𝑣𝑎𝑟⟩ = refl\n ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }\n where\n open ≡-Reasoning\n ⟨𝑎𝑙𝑔⟩ : (t : ⅀ CR α Γ) → 𝕤𝕖𝕞 (CRᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)\n ⟨𝑎𝑙𝑔⟩ (zeroₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (addₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (oneₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (multₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (negₒ ⋮ _) = refl\n\n 𝕊-tab : (mε : Π ~[ CR ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)\n 𝕊-tab mε new = refl\n 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v\n\n module _ (g : CR ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ CRᵃ 𝒜ᵃ g) where\n\n open MetaAlg⇒ gᵃ⇒\n\n 𝕤𝕖𝕞! : (t : CR α Γ) → 𝕤𝕖𝕞 t ≡ g t\n 𝕊-ix : (mε : Sub CR Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)\n 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x\n 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v\n 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))\n = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))\n 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩\n\n 𝕤𝕖𝕞! 𝟘 = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (_⊕_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! 𝟙 = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (_⊗_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (⊖_ a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n\n\n-- Syntax instance for the signature\nCR:Syn : Syntax\nCR:Syn = record\n { ⅀F = ⅀F\n ; ⅀:CS = ⅀:CompatStr\n ; mvarᵢ = CR:Terms.mvar\n ; 𝕋:Init = λ 𝔛 → let open CR:Terms 𝔛 in record\n { ⊥ = CR ⋉ CRᵃ\n ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }\n ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }\n\n-- Instantiation of the syntax and metatheory\nopen Syntax CR:Syn public\nopen CR:Terms public\nopen import SOAS.Families.Build public\nopen import SOAS.Syntax.Shorthands CRᵃ public\nopen import SOAS.Metatheory CR:Syn public\n", "meta": {"hexsha": "659af290ca653a205aba9307ac867e1586dbff20", "size": 4121, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "out/CommRing/Syntax.agda", "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_issues_repo_path": "out/CommRing/Syntax.agda", "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_forks_repo_path": "out/CommRing/Syntax.agda", "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "avg_line_length": 26.5870967742, "max_line_length": 93, "alphanum_fraction": 0.5020626062, "num_tokens": 2686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.5964331462646254, "lm_q1q2_score": 0.39479274342774107}} {"text": "{-# OPTIONS --safe #-}\n\nopen import Cubical.Foundations.Everything renaming (Iso to _≅_)\nopen import Cubical.Data.List\nopen import Cubical.Data.Unit\nopen import Cubical.Data.Prod hiding (map)\nopen import Cubical.Data.Nat\n\nmodule Cubical.Data.List.Dependent where\n\nopen _≅_\n\ndata ListP {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) : (as : List A) → Type (ℓ-max ℓA ℓB) where\n [] : ListP B []\n _∷_ : {x : A} (y : B x) {xs : List A} (ys : ListP B xs) → ListP B (x ∷ xs)\n\n-- Represent ListP via known operations in order to derive properties more easily.\nRepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → Type (ℓ-max ℓA ℓB)\nRepListP B [] = Lift Unit\nRepListP B (a ∷ as) = B a × RepListP B as\n\nisoRepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → ListP B as ≅ RepListP B as\nfun (isoRepListP B []) bs = lift tt\ninv (isoRepListP B []) u = []\nrightInv (isoRepListP B []) u = refl\nleftInv (isoRepListP B []) [] = refl\nfun (isoRepListP B (a ∷ as)) (b ∷ bs) = b , fun (isoRepListP B as) bs\ninv (isoRepListP B (a ∷ as)) (b , br) = b ∷ inv (isoRepListP B as) br\nrightInv (isoRepListP B (a ∷ as)) (b , br) i = b , rightInv (isoRepListP B as) br i\nleftInv (isoRepListP B (a ∷ as)) (b ∷ bs) i = b ∷ leftInv (isoRepListP B as) bs i\n\nequivRepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → ListP B as ≃ RepListP B as\nequivRepListP B as = isoToEquiv (isoRepListP B as)\n\npathRepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → ListP B as ≡ RepListP B as\npathRepListP B as = ua (equivRepListP B as)\n\nprivate\n isOfHLevelSucSuc-RepListP : ∀ {ℓA ℓB} (n : HLevel)\n → {A : Type ℓA}\n → {B : A → Type ℓB} → ((a : A) → isOfHLevel (suc (suc n)) (B a))\n → (as : List A)\n → isOfHLevel (suc (suc n)) (RepListP B as)\n isOfHLevelSucSuc-RepListP n isHB [] = isOfHLevelLift (suc (suc n)) (isOfHLevelUnit (suc (suc n)))\n isOfHLevelSucSuc-RepListP n isHB (a ∷ as) = isOfHLevelProd (suc (suc n)) (isHB a) (isOfHLevelSucSuc-RepListP n isHB as)\n\nisOfHLevelSucSuc-ListP : ∀ {ℓA ℓB} (n : HLevel)\n → {A : Type ℓA}\n → {B : A → Type ℓB} → ((a : A) → isOfHLevel (suc (suc n)) (B a))\n → {as : List A}\n → isOfHLevel (suc (suc n)) (ListP B as)\nisOfHLevelSucSuc-ListP n {A} {B} isHB {as} =\n subst⁻ (isOfHLevel (suc (suc n))) (pathRepListP B as) (isOfHLevelSucSuc-RepListP n isHB as)\n\n--------------------------\n\nmapP : ∀ {ℓA ℓA' ℓB ℓB'} {A : Type ℓA} {A' : Type ℓA'} {B : A → Type ℓB} {B' : A' → Type ℓB'}\n (f : A → A') (g : (a : A) → B a → B' (f a)) → ∀ as → ListP B as → ListP B' (map f as)\nmapP f g [] [] = []\nmapP f g (a ∷ as) (b ∷ bs) = g _ b ∷ mapP f g as bs\n\nmapOverIdfun : ∀ {ℓA ℓB ℓB'} {A : Type ℓA} {B : A → Type ℓB} {B' : A → Type ℓB'}\n (g : (a : A) → B a → B' a) → ∀ as → ListP B as → ListP B' as\nmapOverIdfun g [] [] = []\nmapOverIdfun g (a ∷ as) (b ∷ bs) = g a b ∷ mapOverIdfun g as bs\n\nmapOverIdfun-idfun : ∀ {ℓA ℓB} {A : Type ℓA} {B : A → Type ℓB} as → mapOverIdfun (λ a → idfun _) as ≡ (idfun (ListP B as))\nmapOverIdfun-idfun [] i [] = []\nmapOverIdfun-idfun (a ∷ as) i (b ∷ bs) = b ∷ mapOverIdfun-idfun as i bs\n\nmapOverIdfun-∘ : ∀ {ℓA ℓB ℓB' ℓB''} {A : Type ℓA} {B : A → Type ℓB} {B' : A → Type ℓB'} {B'' : A → Type ℓB''}\n (h : (a : A) → B' a → B'' a) (g : (a : A) → B a → B' a) → ∀ as\n → mapOverIdfun (λ a → h a ∘ g a) as ≡ mapOverIdfun h as ∘ mapOverIdfun g as\nmapOverIdfun-∘ h g [] i [] = []\nmapOverIdfun-∘ h g (a ∷ as) i (b ∷ bs) = h a (g a b) ∷ mapOverIdfun-∘ h g as i bs\n\n", "meta": {"hexsha": "1ee3b7c85d5ad571157aa99355376c0f43e357bf", "size": 3435, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Data/List/Dependent.agda", "max_stars_repo_name": "howsiyu/cubical", "max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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": "Cubical/Data/List/Dependent.agda", "max_issues_repo_name": "howsiyu/cubical", "max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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": "Cubical/Data/List/Dependent.agda", "max_forks_repo_name": "howsiyu/cubical", "max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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": 44.6103896104, "max_line_length": 122, "alphanum_fraction": 0.5781659389, "num_tokens": 1565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.661922862511608, "lm_q2_score": 0.5964331462646254, "lm_q1q2_score": 0.39479273547228544}} {"text": "module CTL.Modalities.AN where\n\nopen import FStream.Core\nopen import Library\n\n-- Always (in) Next : p ⊧ φ ⇔ p[1] ⊧ φ\nAN' : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁}\n → FStream' C (Set ℓ₂) → Set (ℓ₁ ⊔ ℓ₂)\nAN' props = APred head (inF (tail props))\n\nAN : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁}\n → FStream C (Set ℓ₂) → Set (ℓ₁ ⊔ ℓ₂)\nAN props = APred AN' (inF props)\n\nmutual\n AN'ₛ : ∀ {i} {ℓ₁ ℓ₂} {C : Container ℓ₁}\n → FStream' C (Set ℓ₂) → FStream' {i} C (Set (ℓ₁ ⊔ ℓ₂))\n head (AN'ₛ props) = AN' props\n tail (AN'ₛ props) = ANₛ (tail props)\n\n ANₛ : ∀ {i} {ℓ₁ ℓ₂} {C : Container ℓ₁}\n → FStream C (Set ℓ₂) → FStream {i} C (Set (ℓ₁ ⊔ ℓ₂))\n inF (ANₛ props) = fmap AN'ₛ (inF props)\n", "meta": {"hexsha": "94e12ae1995a067cc3adce5a806aa3a4fa161661", "size": 670, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "CTL/Modalities/AN.agda", "max_stars_repo_name": "Aerate/condatis", "max_stars_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-13T16:52:28.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-13T16:52:28.000Z", "max_issues_repo_path": "CTL/Modalities/AN.agda", "max_issues_repo_name": "zimbatm/condatis", "max_issues_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-06-03T20:02:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-01T16:52:07.000Z", "max_forks_repo_path": "CTL/Modalities/AN.agda", "max_forks_repo_name": "zimbatm/condatis", "max_forks_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-13T15:56:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-13T15:56:38.000Z", "avg_line_length": 27.9166666667, "max_line_length": 61, "alphanum_fraction": 0.5671641791, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3947220916070867}} {"text": "module HelpDefs where\n\n-- open import Relation.Binary.PropositionalEquality\n\nopen import StdLibStuff\n\nopen import Syntax\nopen import FSC\nopen import STT\nopen import DerivedProps\n\n\nm-weak-h : ∀ {n} Γ₁ Γ₂ {t} → {Γ₃ : Ctx n} → Form (Γ₃ ++ Γ₁) t → Form (Γ₃ ++ (Γ₂ r++ Γ₁)) t\nm-weak-h {n} Γ₁ ε = λ f → f\nm-weak-h {n} Γ₁ (t' ∷ Γ₂) {t} {Γ₃} = λ f → m-weak-h {n} (t' ∷ Γ₁) Γ₂ {t} {Γ₃} (weak-i Γ₃ Γ₁ f)\n\nm-weak2 : ∀ {n Γ₁} Γ₂ → {t : Type n} → Form Γ₁ t → Form (Γ₂ ++ Γ₁) t\nm-weak2 {n} {Γ₁} ε f = f\nm-weak2 {n} {Γ₁} (t' ∷ Γ₂) f = weak (m-weak2 {n} {Γ₁} Γ₂ f)\n\nhypos-i-h : ∀ {n Γ-t₁ Γ-t₂ Γ-t₃} → FSC-Ctx n Γ-t₁ → Form (Γ-t₃ ++ (Γ-t₂ r++ Γ-t₁)) $o → Form (Γ-t₃ ++ (Γ-t₂ r++ Γ-t₁)) $o\nhypos-i-h ε = λ f → f\nhypos-i-h {n} {Γ-t₁} {Γ-t₂} {Γ-t₃} (h ∷h Γ) = λ f → hypos-i-h {n} {Γ-t₁} {Γ-t₂} {Γ-t₃} Γ (m-weak-h Γ-t₁ Γ-t₂ {$o} {Γ-t₃} (m-weak2 Γ-t₃ h) => f)\nhypos-i-h {n} {.(t ∷ _)} {Γ-t₂} {Γ-t₃} (t ∷ Γ) = hypos-i-h {n} {_} {t ∷ Γ-t₂} {Γ-t₃} Γ\n\n\nm-weak : ∀ {n Γ₁ Γ₂ t} → Form Γ₁ t → Form (Γ₂ r++ Γ₁) t\nm-weak {n} {Γ₁} {Γ₂} {t} = m-weak-h {n} Γ₁ Γ₂ {t} {ε}\n\nhypos-i : ∀ {n Γ-t₁ Γ-t₂} → FSC-Ctx n Γ-t₁ → Form (Γ-t₂ r++ Γ-t₁) $o → Form (Γ-t₂ r++ Γ-t₁) $o\nhypos-i {n} {Γ-t₁} {Γ-t₂} = hypos-i-h {n} {Γ-t₁} {Γ-t₂} {ε}\n\nhypos : ∀ {n Γ-t} → FSC-Ctx n Γ-t → Form Γ-t $o → Form Γ-t $o\nhypos {n} {Γ-t} = hypos-i {n} {Γ-t} {ε}\n\n\n-- Props\n\n\neq-1-i : ∀ {n} Γ₁ Γ₂ → (t : Type n) (X₁ : Form (t ∷ Γ₁) $o) (X₂ : Form Γ₁ $o) →\n X₁ ≡ weak-i {n} {$o} {t} ε Γ₁ X₂ →\n m-weak-h Γ₁ Γ₂ {$o} {t ∷ ε} X₁ ≡ weak-i {n} {$o} {t} ε (Γ₂ r++ Γ₁) (m-weak-h Γ₁ Γ₂ {$o} {ε} X₂)\neq-1-i Γ₁ ε t X₁ X₂ = λ h → h\neq-1-i Γ₁ (u ∷ Γ₂) t X₁ X₂ = λ h → eq-1-i (u ∷ Γ₁) Γ₂ t (weak-i {_} {$o} {u} (t ∷ ε) Γ₁ X₁) (weak-i {_} {$o} {u} ε Γ₁ X₂) (trans (cong (weak-i {_} {$o} {u} (t ∷ ε) Γ₁) h) (weak-weak-p-1 Γ₁ t u $o X₂))\n\neq-1 : ∀ {n} Γ₁ Γ₂ → (t : Type n) (X : Form Γ₁ $o) →\n m-weak-h Γ₁ Γ₂ {$o} {t ∷ ε} (weak-i {n} {$o} {t} ε Γ₁ X) ≡ weak-i {n} {$o} {t} ε (Γ₂ r++ Γ₁) (m-weak-h Γ₁ Γ₂ {$o} {ε} X)\neq-1 Γ₁ Γ₂ t X = eq-1-i Γ₁ Γ₂ t (weak-i {_} {$o} {t} ε Γ₁ X) X refl\n\n\neq-2-2 : ∀ n → (Γ-t Γ' : Ctx n) → (t : Type n) (X₁ : Form (t ∷ Γ-t) $o) (X₂ : Form Γ-t $o) →\n weak-i {n} {$o} {t} ε Γ-t X₂ ≡ X₁ →\n (h₂ : t ∷ (Γ' r++ Γ-t) ≡ (Γ' ++ (t ∷ ε)) r++ Γ-t) →\n m-weak-h Γ-t (Γ' ++ (t ∷ ε)) {$o} {ε} X₂ ≡\n subst (λ z → Form z $o) h₂ (m-weak-h Γ-t Γ' {$o} {t ∷ ε} X₁)\neq-2-2 n Γ-t ε t X₁ X₂ h refl = h\neq-2-2 n Γ-t (u ∷ Γ') t X₁ X₂ h h₂ = eq-2-2 n (u ∷ Γ-t) Γ' t (weak-i {_} {$o} {u} (t ∷ ε) Γ-t X₁) (weak-i {_} {$o} {u} ε Γ-t X₂) (\n trans (sym (weak-weak-p-1 Γ-t t u $o X₂)) (cong (weak-i {_} {$o} {u} (t ∷ ε) Γ-t) h))\n h₂\n\neq-2-1 : ∀ n → (Γ-t Γ' : Ctx n) → (t : Type n) (h : Form Γ-t $o) (F : Form (t ∷ (Γ' r++ Γ-t)) $o) →\n (Γ'' : Ctx n)\n (h₁₁ : Γ'' ≡ (Γ' ++ (t ∷ ε)) r++ Γ-t) →\n (h₁₂ : t ∷ (Γ' r++ Γ-t) ≡ Γ'') →\n app (app A (app N (m-weak-h Γ-t (Γ' ++ (t ∷ ε)) {$o} {ε} h))) (subst (λ z → Form z $o) h₁₁ (subst (λ z → Form z $o) h₁₂ F)) ≡\n subst (λ z → Form z $o) h₁₁ (app (app A (app N (subst (λ z → Form z $o) h₁₂ (m-weak-h Γ-t Γ' {$o} {t ∷ ε} (weak-i ε Γ-t h))))) (subst (λ z → Form z $o) h₁₂ F))\neq-2-1 n Γ-t Γ' t h F .((Γ' ++ (t ∷ ε)) r++ Γ-t) refl h₁₂ = cong (λ z → app (app A (app N z)) (subst (λ z → Form z $o) h₁₂ F)) (eq-2-2 n Γ-t Γ' t (weak-i {_} {$o} {t} ε Γ-t h) h refl h₁₂)\n\neq-2-i : ∀ {n} Γ-t → (t : Type n) (Γ : FSC-Ctx n Γ-t) (Γ' : Ctx n) (F : Form (t ∷ (Γ' r++ Γ-t)) $o) →\n (h₁ : t ∷ (ε ++ (Γ' r++ Γ-t)) ≡ (Γ' ++ (t ∷ ε)) r++ Γ-t) →\n hypos-i-h {n} {Γ-t} {Γ' ++ (t ∷ ε)} {ε} Γ (subst (λ z → Form z $o) h₁ F) ≡ subst (λ z → Form z $o) h₁ (hypos-i-h {n} {Γ-t} {Γ'} {t ∷ ε} Γ F)\neq-2-i .ε t ε Γ' F h₁ = refl\neq-2-i .(u ∷ _) t (u ∷ Γ) Γ' F h₁ = eq-2-i _ t Γ (u ∷ Γ') F h₁\neq-2-i Γ-t t (h ∷h Γ) Γ' F h₁ = trans (cong (hypos-i-h {_} {Γ-t} {Γ' ++ (t ∷ ε)} {ε} Γ) (eq-2-1 _ Γ-t Γ' t h F _ h₁ refl)) (eq-2-i Γ-t t Γ Γ' (app (app A (app N (m-weak-h Γ-t Γ' {$o} {t ∷ ε} (weak-i ε Γ-t h)))) F) h₁)\n\neq-2 : ∀ {n Γ-t} → (t : Type n) (Γ : FSC-Ctx n Γ-t) (F : Form (t ∷ Γ-t) $o) →\n hypos-i-h {n} {Γ-t} {t ∷ ε} {ε} Γ F ≡ hypos-i-h {n} {Γ-t} {ε} {t ∷ ε} Γ F\neq-2 {_} {Γ-t} t Γ F = eq-2-i {_} Γ-t t Γ ε F refl\n\n\n\ntraverse-hypos-i : ∀ {n Γ-t₁ Γ-t₂} → (F G : Form (Γ-t₂ r++ Γ-t₁) $o) (Γ : FSC-Ctx n Γ-t₁) → (⊢ (F => G)) → ⊢ (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ F => hypos-i {n} {Γ-t₁} {Γ-t₂} Γ G)\ntraverse-hypos-i F G ε h = h\ntraverse-hypos-i {n} {Γ-t₁} {Γ-t₂} F G (X ∷h Γ) h = traverse-hypos-i {n} {Γ-t₁} {Γ-t₂} (m-weak {n} {Γ-t₁} {Γ-t₂} X => F) (m-weak {n} {Γ-t₁} {Γ-t₂} X => G) Γ (inf-V ax-4-s h)\ntraverse-hypos-i {n} {.(t ∷ _)} {Γ-t₂} F G (t ∷ Γ) h = traverse-hypos-i {n} {_} {t ∷ Γ-t₂} F G Γ h\n\ntraverse-hypos : ∀ {n Γ-t} → (F G : Form Γ-t $o) (Γ : FSC-Ctx n Γ-t) → (⊢ (F => G)) → ⊢ (hypos Γ F => hypos Γ G)\ntraverse-hypos {n} {Γ-t} = traverse-hypos-i {n} {Γ-t} {ε}\n\n\n\ntraverse-hypos-pair-I-i : ∀ {n Γ-t₁ Γ-t₂} → (F G : Form (Γ-t₂ r++ Γ-t₁) $o) (Γ : FSC-Ctx n Γ-t₁) → ⊢ (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ F => (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ G => hypos-i {n} {Γ-t₁} {Γ-t₂} Γ (F & G)))\ntraverse-hypos-pair-I-i F G ε = lemb1 F G\ntraverse-hypos-pair-I-i {n} {Γ-t₁} {Γ-t₂} F G (x ∷h Γ) = inf-V (inf-V (ax-4-s {_} {_} {(hypos-i {n} {Γ-t₁} {Γ-t₂} Γ (m-weak {n} {Γ-t₁} {Γ-t₂} x => G) => (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ ((m-weak {n} {Γ-t₁} {Γ-t₂} x => F) & (m-weak {n} {Γ-t₁} {Γ-t₂} x => G))))})\n (inf-V (ax-4-s {_} {_} {(hypos-i {n} {Γ-t₁} {Γ-t₂} Γ ((m-weak {n} {Γ-t₁} {Γ-t₂} x => F) & (m-weak {n} {Γ-t₁} {Γ-t₂} x => G)))}) (traverse-hypos-i {n} {Γ-t₁} {Γ-t₂} ((m-weak {n} {Γ-t₁} {Γ-t₂} x => F) & (m-weak {n} {Γ-t₁} {Γ-t₂} x => G)) (m-weak {n} {Γ-t₁} {Γ-t₂} x => (F & G)) Γ (lem2 (m-weak {n} {Γ-t₁} {Γ-t₂} x) F G))))\n (traverse-hypos-pair-I-i {n} {Γ-t₁} {Γ-t₂} (m-weak {n} {Γ-t₁} {Γ-t₂} x => F) (m-weak {n} {Γ-t₁} {Γ-t₂} x => G) Γ)\ntraverse-hypos-pair-I-i {n} {.(t ∷ _)} {Γ-t₂} F G (t ∷ Γ) = traverse-hypos-pair-I-i {n} {_} {t ∷ Γ-t₂} F G Γ\n\ntraverse-hypos-pair-I : ∀ {n Γ-t} → (F G : Form Γ-t $o) (Γ : FSC-Ctx n Γ-t) → ⊢ (hypos Γ F => (hypos Γ G => hypos Γ (F & G)))\ntraverse-hypos-pair-I {n} {Γ-t} = traverse-hypos-pair-I-i {n} {Γ-t} {ε}\n\n\ntraverse-hypos-elim-i : ∀ {n Γ-t₁ Γ-t₂} → (F : Form (Γ-t₂ r++ Γ-t₁) $o) (Γ : FSC-Ctx n Γ-t₁) (x : HVar Γ) → ⊢ (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ (m-weak {n} {Γ-t₁} {Γ-t₂} (lookup-hyp Γ x) => F) => hypos-i {n} {Γ-t₁} {Γ-t₂} Γ F)\ntraverse-hypos-elim-i {n} {Γ-t₁} {Γ-t₂} F .(h ∷h Γ) (zero {._} {h} {Γ}) = traverse-hypos-i {n} {Γ-t₁} {Γ-t₂} (m-weak {n} {Γ-t₁} {Γ-t₂} h => (m-weak {n} {Γ-t₁} {Γ-t₂} h => F)) (m-weak {n} {Γ-t₁} {Γ-t₂} h => F) Γ (lem3 (m-weak {n} {Γ-t₁} {Γ-t₂} h) F)\ntraverse-hypos-elim-i {n} {Γ-t₁} {Γ-t₂} F .(h ∷h Γ) (succ {._} {h} {Γ} x) = inf-V ax-3-s (inf-V (inf-V (ax-4-s {_} {_} {~ (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ (m-weak {n} {Γ-t₁} {Γ-t₂} (lookup-hyp Γ x) => (m-weak {n} {Γ-t₁} {Γ-t₂} h => F)))}) (inf-V (lem5 (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ (m-weak {n} {Γ-t₁} {Γ-t₂} h => (m-weak {n} {Γ-t₁} {Γ-t₂} (lookup-hyp Γ x) => F))) (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ (m-weak {n} {Γ-t₁} {Γ-t₂} (lookup-hyp Γ x) => (m-weak {n} {Γ-t₁} {Γ-t₂} h => F)))) (traverse-hypos-i {n} {Γ-t₁} {Γ-t₂} (m-weak {n} {Γ-t₁} {Γ-t₂} h => (m-weak {n} {Γ-t₁} {Γ-t₂} (lookup-hyp Γ x) => F)) (m-weak {n} {Γ-t₁} {Γ-t₂} (lookup-hyp Γ x) => (m-weak {n} {Γ-t₁} {Γ-t₂} h => F)) Γ (lem4 (m-weak {n} {Γ-t₁} {Γ-t₂} h) (m-weak {n} {Γ-t₁} {Γ-t₂} (lookup-hyp Γ x)) F)))) (inf-V ax-3-s (traverse-hypos-elim-i {n} {Γ-t₁} {Γ-t₂} (m-weak {n} {Γ-t₁} {Γ-t₂} h => F) Γ x)))\ntraverse-hypos-elim-i {n} {.(t ∷ _)} {Γ-t₂} F (t ∷ Γ) (skip x) = traverse-hypos-elim-i {n} {_} {t ∷ Γ-t₂} F Γ x\n\ntraverse-hypos-elim : ∀ {n Γ-t} → (F : Form Γ-t $o) (Γ : FSC-Ctx n Γ-t) (x : HVar Γ) → ⊢ (hypos Γ (lookup-hyp Γ x => F) => hypos Γ F)\ntraverse-hypos-elim {n} {Γ-t} = traverse-hypos-elim-i {n} {Γ-t} {ε}\n\n\ntraverse-hypos-use-i : ∀ {n Γ-t₁ Γ-t₂} → (F : Form (Γ-t₂ r++ Γ-t₁) $o) (Γ : FSC-Ctx n Γ-t₁) → ⊢ (F) → ⊢ (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ F)\ntraverse-hypos-use-i F ε h = h\ntraverse-hypos-use-i {n} {Γ-t₁} {Γ-t₂} F (X ∷h Γ) h = traverse-hypos-use-i {n} {Γ-t₁} {Γ-t₂} (m-weak {n} {Γ-t₁} {Γ-t₂} X => F) Γ (inf-V ax-3-s (inf-V ax-2-s h))\ntraverse-hypos-use-i {n} {.(t ∷ _)} {Γ-t₂} F (t ∷ Γ) h = traverse-hypos-use-i {n} {_} {t ∷ Γ-t₂} F Γ h\n\ntraverse-hypos-use : ∀ {n Γ-t} → (F : Form Γ-t $o) (Γ : FSC-Ctx n Γ-t) → ⊢ (F) → ⊢ (hypos Γ F)\ntraverse-hypos-use {n} {Γ-t} = traverse-hypos-use-i {n} {Γ-t} {ε}\n\n\ntraverse-hypos2-i : ∀ {n Γ-t₁ Γ-t₂} → (F G H : Form (Γ-t₂ r++ Γ-t₁) $o) (Γ : FSC-Ctx n Γ-t₁) → (⊢ (F => (G => H))) → ⊢ (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ F => (hypos-i {n} {Γ-t₁} {Γ-t₂}Γ G => hypos-i {n} {Γ-t₁} {Γ-t₂} Γ H))\ntraverse-hypos2-i F G H ε imp = imp\ntraverse-hypos2-i {n} {Γ-t₁} {Γ-t₂} F G H (X ∷h Γ) imp = traverse-hypos2-i {n} {Γ-t₁} {Γ-t₂} (m-weak {n} {Γ-t₁} {Γ-t₂} X => F) (m-weak {n} {Γ-t₁} {Γ-t₂} X => G) (m-weak {n} {Γ-t₁} {Γ-t₂} X => H) Γ (inf-V (lem8 (m-weak {n} {Γ-t₁} {Γ-t₂} X) F G H) imp)\ntraverse-hypos2-i {n} {.(t ∷ _)} {Γ-t₂} F G H (t ∷ Γ) imp = traverse-hypos2-i {n} {_} {t ∷ Γ-t₂} F G H Γ imp\n\ntraverse-hypos2 : ∀ {n Γ-t} → (F G H : Form Γ-t $o) (Γ : FSC-Ctx n Γ-t) → (⊢ (F => (G => H))) → ⊢ (hypos Γ F => (hypos Γ G => hypos Γ H))\ntraverse-hypos2 {n} {Γ-t} = traverse-hypos2-i {n} {Γ-t} {ε}\n\ntraverse-hypos3-i : ∀ {n Γ-t₁ Γ-t₂} → (F G H I : Form (Γ-t₂ r++ Γ-t₁) $o) (Γ : FSC-Ctx n Γ-t₁) → (⊢ (F => (G => (H => I)))) → ⊢ (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ F => (hypos-i {n} {Γ-t₁} {Γ-t₂}Γ G => (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ H => hypos-i {n} {Γ-t₁} {Γ-t₂} Γ I)))\ntraverse-hypos3-i F G H I ε imp = imp\ntraverse-hypos3-i {n} {Γ-t₁} {Γ-t₂} F G H I (X ∷h Γ) imp = traverse-hypos3-i {n} {Γ-t₁} {Γ-t₂} (m-weak {n} {Γ-t₁} {Γ-t₂} X => F) (m-weak {n} {Γ-t₁} {Γ-t₂} X => G) (m-weak {n} {Γ-t₁} {Γ-t₂} X => H) (m-weak {n} {Γ-t₁} {Γ-t₂} X => I) Γ (inf-V (lem8-3 (m-weak {n} {Γ-t₁} {Γ-t₂} X) F G H I) imp)\ntraverse-hypos3-i {n} {.(t ∷ _)} {Γ-t₂} F G H I (t ∷ Γ) imp = traverse-hypos3-i {n} {_} {t ∷ Γ-t₂} F G H I Γ imp\n\ntraverse-hypos3 : ∀ {n Γ-t} → (F G H I : Form Γ-t $o) (Γ : FSC-Ctx n Γ-t) → (⊢ (F => (G => (H => I)))) → ⊢ (hypos Γ F => (hypos Γ G => (hypos Γ H => hypos Γ I)))\ntraverse-hypos3 {n} {Γ-t} = traverse-hypos3-i {n} {Γ-t} {ε}\n\n\ntraverse-=>-I-dep-i : ∀ {n Γ-t₁ Γ-t₂} → (t : Type n) (F : Form (t ∷ (Γ-t₂ r++ Γ-t₁)) $o) (Γ : FSC-Ctx n Γ-t₁) → \n ⊢ (![ t ] hypos-i-h {n} {Γ-t₁} {Γ-t₂} {t ∷ ε} Γ F) →\n ⊢ (hypos-i {n} {Γ-t₁} {Γ-t₂} Γ (![ t ] F))\ntraverse-=>-I-dep-i t F ε h = h\ntraverse-=>-I-dep-i {n} {Γ-t₁} {Γ-t₂} t F (X ∷h Γ) h = inf-V (traverse-hypos-i {n} {Γ-t₁} {Γ-t₂} (![ t ] (weak (m-weak {n} {Γ-t₁} {Γ-t₂} X) => F)) (m-weak {n} {Γ-t₁} {Γ-t₂} X => (![ t ] F)) Γ (ax-6-s {_} {_} {_} {~ (m-weak {n} {Γ-t₁} {Γ-t₂} X)} {F})) (traverse-=>-I-dep-i {n} {Γ-t₁} {Γ-t₂} t (weak (m-weak {n} {Γ-t₁} {Γ-t₂} X) => F) Γ\n (subst (λ z → ⊢_ {n} {_r++_ {n} Γ-t₂ Γ-t₁} (app {n} {_>_ {_} t ($o {_})} {$o {_}} {_r++_ {n} Γ-t₂ Γ-t₁} (Π {n} {t} {_r++_ {n} Γ-t₂ Γ-t₁}) (lam {n} {$o {_}} {_r++_ {n} Γ-t₂ Γ-t₁} t ((hypos-i-h {n} {Γ-t₁} {Γ-t₂} {_∷_ {_} t (ε {_})} Γ (_=>_ {_} {_∷_ {_} t (_r++_ {n} Γ-t₂ Γ-t₁)} z F))))))\n (eq-1 {n} Γ-t₁ Γ-t₂ t X) h))\ntraverse-=>-I-dep-i {n} {.(t' ∷ _)} {Γ-t₂} t F (t' ∷ Γ) h = traverse-=>-I-dep-i {n} {_} {t' ∷ Γ-t₂} t F Γ h\n\ntraverse-=>-I-dep : ∀ {n Γ-t} → (t : Type n) (F : Form (t ∷ Γ-t) $o) (Γ : FSC-Ctx n Γ-t) → \n ⊢ (![ t ] hypos (t ∷ Γ) F) → ⊢ (hypos Γ (![ t ] F))\ntraverse-=>-I-dep {n} {Γ-t} t F Γ h = traverse-=>-I-dep-i {n} {Γ-t} {ε} t F Γ (subst (λ z → ⊢ app Π (lam t (z))) (eq-2 t Γ F) h)\n\n\ntraverse-=>-I-dep'-I2 : ∀ {n Γ-t₁ Γ-t₂} → (t : Type n) (F : Form (t ∷ (Γ-t₂ r++ Γ-t₁)) $o) (G : Form (Γ-t₂ r++ Γ-t₁) $o) (Γ : FSC-Ctx n Γ-t₁) → \n (⊢ (F => weak-i ε (Γ-t₂ r++ Γ-t₁) G)) →\n ⊢ (hypos-i-h {n} {Γ-t₁} {Γ-t₂} {t ∷ ε} Γ F => weak-i ε (Γ-t₂ r++ Γ-t₁) (hypos-i-h {n} {Γ-t₁} {Γ-t₂} {ε} Γ G))\ntraverse-=>-I-dep'-I2 t F G ε h = h\ntraverse-=>-I-dep'-I2 {n} {t' ∷ Γ-t₁} {Γ-t₂} t F G (.t' ∷ Γ) h = traverse-=>-I-dep'-I2 {n} {Γ-t₁} {t' ∷ Γ-t₂} t F G Γ h\ntraverse-=>-I-dep'-I2 {n} {Γ-t₁} {Γ-t₂} t F G (X ∷h Γ) h = traverse-=>-I-dep'-I2 {n} {Γ-t₁} {Γ-t₂} t (m-weak-h Γ-t₁ Γ-t₂ {$o} {t ∷ ε} (weak-i ε Γ-t₁ X) => F) (m-weak-h Γ-t₁ Γ-t₂ {$o} {ε} X => G) Γ (\n subst (λ z → ⊢ ((m-weak-h Γ-t₁ Γ-t₂ {$o} {t ∷ ε} (weak-i ε Γ-t₁ X) => F) => (z => weak-i ε (Γ-t₂ r++ Γ-t₁) G))) (eq-1 Γ-t₁ Γ-t₂ t X) (inf-V ax-4-s h))\n\ntraverse-=>-I-dep'-I : ∀ {n Γ-t} → (t : Type n) (F : Form (t ∷ Γ-t) $o) (G : Form Γ-t $o) (Γ : FSC-Ctx n Γ-t) → \n (⊢ (F => weak-i ε Γ-t G)) →\n ⊢ (hypos (t ∷ Γ) F => weak-i ε Γ-t (hypos Γ G))\ntraverse-=>-I-dep'-I {n} {Γ-t} t F G Γ h = subst (λ z → ⊢ (z => weak-i ε Γ-t (hypos Γ G))) (sym (eq-2 t Γ F)) (traverse-=>-I-dep'-I2 {n} {Γ-t} {ε} t F G Γ h)\n\ntraverse-=>-I-dep' : ∀ {n Γ-t} → (t : Type n) (F : Form Γ-t (t > $o)) (Γ : FSC-Ctx n Γ-t) → \n ⊢ hypos (t ∷ Γ) (weak F · $ this {refl}) → ⊢ (hypos Γ (!'[ t ] F))\ntraverse-=>-I-dep' t F Γ h = extend-context t (inf-V (traverse-=>-I-dep'-I t (weak F · $ this {refl}) (!'[ t ] F) Γ (inf-VI this (occurs-p-2 F) refl)) h)\n\n\n-- -----------------------------------\n\ntraverse-hypos-eq-=>-I-i : ∀ {n Γ-t₁ Γ-t₂} → {t : Type n} → (F : Form (t ∷ (Γ-t₂ r++ Γ-t₁)) $o) (G : Form (Γ-t₂ r++ Γ-t₁) $o) (Γ : FSC-Ctx n Γ-t₁) → (⊢ (F => weak G)) → ⊢ hypos-i-h {n} {Γ-t₁} {Γ-t₂} {t ∷ ε} Γ F → ⊢ hypos-i {n} {Γ-t₁} {Γ-t₂} Γ G\ntraverse-hypos-eq-=>-I-i {n} {.ε} {Γ-t₂} {t} F G ε = λ z z' → extend-context t (inf-V z z')\ntraverse-hypos-eq-=>-I-i {n} {Γ-t₁} {Γ-t₂} {t} F G (X ∷h Γ) = λ h → traverse-hypos-eq-=>-I-i {n} {Γ-t₁} {Γ-t₂} {t} (m-weak-h {_} Γ-t₁ Γ-t₂ {_} {t ∷ ε} (m-weak2 (t ∷ ε) X) => F) (m-weak-h {_} Γ-t₁ Γ-t₂ {_} {ε} (m-weak2 ε X) => G) Γ (subst (λ z → ⊢ ((m-weak-h {_} Γ-t₁ Γ-t₂ {_} {t ∷ ε} (m-weak2 (t ∷ ε) X) => F) => (z => weak G))) (eq-1 Γ-t₁ Γ-t₂ t X) (inf-V ax-4-s h))\ntraverse-hypos-eq-=>-I-i {n} {t₁ ∷ Γ-t₁} {Γ-t₂} {t} F G ((.t₁) ∷ Γ) = traverse-hypos-eq-=>-I-i {n} {Γ-t₁} {t₁ ∷ Γ-t₂} {t} F G Γ\n\ntraverse-hypos-eq-=>-I'' : ∀ {n Γ-t} → {t : Type n} (F : Form (t ∷ Γ-t) $o) (G : Form Γ-t $o) (Γ : FSC-Ctx n Γ-t) →\n ⊢ (F => weak G) →\n ⊢ hypos (t ∷ Γ) F → ⊢ hypos Γ G\ntraverse-hypos-eq-=>-I'' {n} {Γ-t} F G Γ = λ h₁ h₂ → traverse-hypos-eq-=>-I-i {n} {Γ-t} {ε} F G Γ h₁ (subst (λ z → ⊢ z) (eq-2 _ Γ F) h₂)\n\ntst3-ε : ∀ {n} → (Γ₁ Γ₂ : Ctx n) (F : Form Γ₁ $o)\n (eq : Γ₁ ≡ Γ₂) →\n ⊢_ {n} {Γ₂} (subst (λ z → Form z $o) eq F) →\n ⊢_ {n} {Γ₁} F\ntst3-ε .Γ₂ Γ₂ F refl p = p -- rewrite eq = p\n\ntst3b : ∀ {n} → {t u : Type n} → (Γ-t₁ Γ-t₂ : Ctx n) (X : Form Γ-t₁ u) →\n (eq2 : t ∷ (Γ-t₂ r++ Γ-t₁) ≡ (Γ-t₂ ++ (t ∷ ε)) r++ Γ-t₁) →\n m-weak-h Γ-t₁ (Γ-t₂ ++ (t ∷ ε)) {_} {ε} X ≡\n subst (λ z → Form z u) eq2 (weak-i ε (Γ-t₂ r++ Γ-t₁) (m-weak-h Γ-t₁ Γ-t₂ {_} {ε} X))\ntst3b Γ-t₁ ε X refl = refl\ntst3b Γ-t₁ (v ∷ Γ-t₂) X eq2 = tst3b (v ∷ Γ-t₁) Γ-t₂ (weak-i ε Γ-t₁ X) eq2\n\ntst3'-∷h : ∀ {n Γ-t₁ Γ-t₂} → {t : Type n} (F : Form (t ∷ (Γ-t₂ r++ Γ-t₁)) $o) (Γ : FSC-Ctx n Γ-t₁) →\n (X : Form Γ-t₁ $o)\n (Γ1 : Ctx n)\n (eq1 : Γ1 ≡ (Γ-t₂ ++ (t ∷ ε)) r++ Γ-t₁)\n (eq2 : t ∷ (Γ-t₂ r++ Γ-t₁) ≡ Γ1)\n (p : ⊢ hypos-i-h {n} {Γ-t₁} {Γ-t₂ ++ (t ∷ ε)} {ε} Γ (app (app A (app N (m-weak-h {n} Γ-t₁ (Γ-t₂ ++ (t ∷ ε)) {$o} {ε} X))) (subst (λ z → Form z $o) eq1 (subst (λ z → Form z $o) eq2 F)))) →\n ⊢ hypos-i-h {n} {Γ-t₁} {Γ-t₂ ++ (t ∷ ε)} {ε} Γ (subst (λ z → Form z $o) eq1 (app (app A (app N (subst (λ z → Form z $o) eq2 (weak-i ε (Γ-t₂ r++ Γ-t₁) (m-weak-h Γ-t₁ Γ-t₂ {$o} {ε} X))))) (subst (λ z → Form z $o) eq2 F)))\ntst3'-∷h {n} {Γ-t₁} {Γ-t₂} {t} F Γ X .((Γ-t₂ ++ (t ∷ ε)) r++ Γ-t₁) refl eq2 p = subst (λ z → ⊢ hypos-i-h {n} {Γ-t₁} {Γ-t₂ ++ (t ∷ ε)} {ε} Γ (app (app A (app N z)) (subst (λ z → Form z $o) eq2 F))) (tst3b {n} {t} Γ-t₁ Γ-t₂ X eq2) p\n\ntst3' : ∀ {n Γ-t₁ Γ-t₂} → {t : Type n} (F : Form (t ∷ (Γ-t₂ r++ Γ-t₁)) $o) (Γ : FSC-Ctx n Γ-t₁) →\n (eq : t ∷ (Γ-t₂ r++ Γ-t₁) ≡ (Γ-t₂ ++ (t ∷ ε)) r++ Γ-t₁) →\n ⊢ hypos-i-h {n} {Γ-t₁} {Γ-t₂ ++ (t ∷ ε)} {ε} Γ (subst (λ z → Form z $o) eq F) →\n ⊢ hypos-i-h {n} {Γ-t₁} {Γ-t₂} {ε} Γ (![ t ] F)\ntst3' {n} {ε} {Γ-t₂} {t} F ε eq = λ p → inf-VI-s (tst3-ε {n} (t ∷ (Γ-t₂ r++ ε)) ((Γ-t₂ ++ (t ∷ ε)) r++ ε) F eq p)\ntst3' {n} {t' ∷ Γ-t₁} {Γ-t₂} F ((.t') ∷ Γ) eq = tst3' {n} {Γ-t₁} {t' ∷ Γ-t₂} F Γ eq \ntst3' {n} {Γ-t₁} {Γ-t₂} {t} F (X ∷h Γ) eq = λ p → inf-V (traverse-hypos-i {n} {Γ-t₁} {Γ-t₂} (![ t ] (weak (~ (m-weak-h Γ-t₁ Γ-t₂ {_} {ε} X)) || F)) (m-weak-h {n} Γ-t₁ Γ-t₂ {$o} {ε} X => ![ t ] F) Γ (inf-V (inf-V ax-4-s ax-6-s) (lem2h2hb _))) (tst3' {n} {Γ-t₁} {Γ-t₂} {t} (weak (~ (m-weak-h Γ-t₁ Γ-t₂ {_} {ε} X)) || F) Γ eq (tst3'-∷h {n} {Γ-t₁} {Γ-t₂} {t} F Γ X (t ∷ (Γ-t₂ r++ Γ-t₁)) eq refl p))\n\n\ntraverse-hypos-eq-=>-I : ∀ {n Γ-t} → {t₁ t₂ : Type n} (F₁ F₂ : Form (t₁ ∷ Γ-t) t₂) (Γ : FSC-Ctx n Γ-t) →\n ⊢ hypos (t₁ ∷ Γ) (F₁ == F₂) →\n ⊢ hypos Γ (lam t₁ F₁ == lam t₁ F₂)\ntraverse-hypos-eq-=>-I {_} {Γ-t} {t₁} {t₂} F₁ F₂ Γ p = inf-V (traverse-hypos (![ t₁ ] (F₁ == F₂)) (lam t₁ F₁ == lam t₁ F₂) Γ ax-10-b-s) (tst3' {_} {Γ-t} {ε} (F₁ == F₂) Γ refl p)\n\n", "meta": {"hexsha": "08ba8d1c37ffef5ff908314ac7c7b41c9caaa6fd", "size": 16736, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "soundness/HelpDefs.agda", "max_stars_repo_name": "frelindb/agsyHOL", "max_stars_repo_head_hexsha": "032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2015-09-04T14:38:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-19T20:53:45.000Z", "max_issues_repo_path": "soundness/HelpDefs.agda", "max_issues_repo_name": "frelindb/agsyHOL", "max_issues_repo_head_hexsha": "032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7", "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": "soundness/HelpDefs.agda", "max_forks_repo_name": "frelindb/agsyHOL", "max_forks_repo_head_hexsha": "032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-17T20:28:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T11:51:19.000Z", "avg_line_length": 76.7706422018, "max_line_length": 851, "alphanum_fraction": 0.4545291587, "num_tokens": 9479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624789529375, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.39438845258597177}} {"text": "module snoc where\n\nopen import unit\nopen import empty\nopen import bool\nopen import product\n\ndata Snoc (A : Set) : Set where\n [] : Snoc A\n _::_ : Snoc A → A → Snoc A\n\ninfixl 6 _::_ _++_\n\n[_] : {A : Set} → A → Snoc A\n[ x ] = [] :: x\n\n_++_ : {A : Set} → Snoc A → Snoc A → Snoc A\n[] ++ l₂ = l₂\n(l₁ :: x) ++ l₂ = (l₁ ++ l₂) :: x\n\nmember : {A : Set} → (A → A → 𝔹) → A → Snoc A → 𝔹\nmember _=A_ x (l :: y) with x =A y\n... | tt = tt\n... | ff = ff\nmember _=A_ x _ = ff\n\ninPairSnocFst : {A B : Set} → (A → A → 𝔹) → A → Snoc (A × B) → Set\ninPairSnocFst _=A_ x [] = ⊥\ninPairSnocFst _=A_ x (l :: (a , _)) with x =A a\n... | tt = ⊤\n... | ff = inPairSnocFst _=A_ x l\n", "meta": {"hexsha": "1a22659c24196e266f3d4e01ee2fe52740ea1beb", "size": 652, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "snoc.agda", "max_stars_repo_name": "heades/AUGL", "max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": "snoc.agda", "max_issues_repo_name": "heades/AUGL", "max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": "snoc.agda", "max_forks_repo_name": "heades/AUGL", "max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": 20.375, "max_line_length": 66, "alphanum_fraction": 0.504601227, "num_tokens": 304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6654105720171531, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.39436662129089883}} {"text": "\n-- Kit instances and generic term traversals\nmodule Syntax.Substitution.Instances where\n\nopen import Syntax.Types\nopen import Syntax.Context\nopen import Syntax.Terms\nopen import Syntax.Substitution.Kits\n\nopen import Data.Sum\nopen import Relation.Binary.PropositionalEquality as ≡\n using (_≡_ ; refl ; sym ; cong ; subst)\nopen import Function using (id ; flip ; _∘_)\nopen ≡.≡-Reasoning\n\n-- | Variable and term schemas\nVar : Schema\nVar = flip _∈_\n\nTerm : Schema\nTerm = _⊢_\n\n-- | Variable kit\n\n-- Variable kit\n𝒱ar : Kit Var\n𝒱ar = record\n { 𝓋 = id\n ; 𝓉 = var\n ; 𝓌 = pop\n ; 𝒶 = 𝒶-var\n }\n where\n 𝒶-var : ∀{A Γ} → Var Γ (A always) → Var (Γ ˢ) (A always)\n 𝒶-var top = top\n 𝒶-var (pop {B = B now} v) = 𝒶-var v\n 𝒶-var (pop {B = B always} v) = pop (𝒶-var v)\n\n-- Generic substitution in a variable to any schema\nsubst-var : ∀ {𝒮 Γ Δ A} -> Subst 𝒮 Γ Δ → Var Γ A → 𝒮 Δ A\nsubst-var ● ()\nsubst-var (σ ▸ T) top = T\nsubst-var (σ ▸ T) (pop v) = subst-var σ v\n\n-- Substitutable variable kit\n𝒱arₛ : SubstKit Var\n𝒱arₛ = record { 𝓀 = 𝒱ar ; 𝓈 = subst-var }\n\n-- | Term traversal\n\nmodule K {𝒮 : Schema} (k : Kit 𝒮) where\n open Kit k\n\n -- | Type-preserving term traversal\n -- | Traverses the syntax tree of the term, applying\n -- | the given substitution to the variables.\n mutual\n traverse : ∀{Γ Δ A} -> Subst 𝒮 Γ Δ -> Γ ⊢ A -> Δ ⊢ A\n traverse σ (var x) = 𝓉 (subst-var σ x)\n traverse σ (lam M) = lam (traverse (σ ↑ k) M)\n traverse σ (M $ N) = traverse σ M $ traverse σ N\n traverse σ unit = unit\n traverse σ [ M ,, N ] = [ traverse σ M ,, traverse σ N ]\n traverse σ (fst M) = fst (traverse σ M)\n traverse σ (snd M) = snd (traverse σ M)\n traverse σ (inl M) = inl (traverse σ M)\n traverse σ (inr M) = inr (traverse σ M)\n traverse σ (case M inl↦ N₁ ||inr↦ N₂)\n = case traverse σ M\n inl↦ traverse (σ ↑ k) N₁\n ||inr↦ traverse (σ ↑ k) N₂\n traverse σ (sample M) = sample (traverse σ M)\n traverse σ (stable M) = stable (traverse (σ ↓ˢ k) M)\n traverse σ (sig M) = sig (traverse σ M)\n traverse σ (letSig S In M) = letSig traverse σ S\n In traverse (σ ↑ k) M\n traverse σ (event E) = event (traverse′ σ E)\n\n traverse′ : ∀{Γ Δ A} -> Subst 𝒮 Γ Δ -> Γ ⊨ A -> Δ ⊨ A\n traverse′ σ (pure M) = pure (traverse σ M)\n traverse′ σ (letSig S InC C) = letSig traverse σ S\n InC traverse′ (σ ↑ k) C\n traverse′ σ (letEvt E In C) = letEvt traverse σ E\n In traverse′ (σ ↓ˢ k ↑ k) C\n traverse′ σ (select E₁ ↦ C₁ || E₂ ↦ C₂ ||both↦ C₃) =\n select traverse σ E₁ ↦ traverse′ (σ ↓ˢ k ↑ k ↑ k) C₁\n || traverse σ E₂ ↦ traverse′ (σ ↓ˢ k ↑ k ↑ k) C₂\n ||both↦ traverse′ (σ ↓ˢ k ↑ k ↑ k) C₃\nopen K\n\n\n-- Renaming is a term traversal with variable substitutions\nrename : ∀{A Γ Δ} -> Subst Var Γ Δ -> Γ ⊢ A -> Δ ⊢ A\nrename = traverse 𝒱ar\n\n-- Weakening is a renaming with a weakening substitution\nweaken-top : ∀{B Γ A} -> Γ ⊢ A → Γ , B ⊢ A\nweaken-top = rename (weak-topₛ 𝒱arₛ)\n\n-- Weakening is a renaming with a weakening substitution\nweaken′-top : ∀{B Γ A} -> Γ ⊨ A → Γ , B ⊨ A\nweaken′-top = traverse′ 𝒱ar (weak-topₛ 𝒱arₛ)\n\n\n-- | Term kit\n\n-- Term kit\n𝒯erm : Kit Term\n𝒯erm = record\n { 𝓋 = var\n ; 𝓉 = id\n ; 𝓌 = weaken-top\n ; 𝒶 = 𝒶-term\n }\n where\n 𝒶-term : {Γ : Context} {A : Type} → Γ ⊢ A always → Γ ˢ ⊢ A always\n 𝒶-term {∙} M = M\n 𝒶-term {Γ , B now} (var (pop x)) = 𝒶-term (var x)\n 𝒶-term {Γ , B always} (var top) = var top\n 𝒶-term {Γ , B always} (var {A = A} (pop x)) = weaken-top (𝒶-term (var x))\n 𝒶-term {Γ , B now} (stable M) = 𝒶-term {Γ} (stable M)\n 𝒶-term {Γ , B always} (stable {A = A} M) =\n stable (subst (λ x → x , B always ⊢ A now) (sym (ˢ-idemp Γ)) M)\n\n-- Substitution is a traversal with term substitutions\nsubstitute : ∀{Γ Δ A} -> Subst Term Γ Δ -> Γ ⊢ A -> Δ ⊢ A\nsubstitute = traverse 𝒯erm\n\n-- Computational substitution is a traversal with term substitutions\nsubstitute′ : ∀{Γ Δ A} -> Subst Term Γ Δ -> Γ ⊨ A -> Δ ⊨ A\nsubstitute′ = traverse′ 𝒯erm\n\n-- Substitutable term kit\n𝒯ermₛ : SubstKit Term\n𝒯ermₛ = record { 𝓀 = 𝒯erm ; 𝓈 = substitute }\n", "meta": {"hexsha": "7a1995ae19a3817281e9eb11f325b7999481903d", "size": 4436, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Syntax/Substitution/Instances.agda", "max_stars_repo_name": "DimaSamoz/temporal-type-systems", "max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z", "max_issues_repo_path": "src/Syntax/Substitution/Instances.agda", "max_issues_repo_name": "DimaSamoz/temporal-type-systems", "max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "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/Syntax/Substitution/Instances.agda", "max_forks_repo_name": "DimaSamoz/temporal-type-systems", "max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "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": 32.6176470588, "max_line_length": 77, "alphanum_fraction": 0.5432822362, "num_tokens": 1573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6654105720171531, "lm_q2_score": 0.5926665999540697, "lm_q1q2_score": 0.3943666212908988}} {"text": "{-# OPTIONS --cubical --safe #-}\n\nmodule Cubical.HITs.Cylinder.Base where\n\nopen import Cubical.Core.Everything\n\nopen import Cubical.Foundations.Everything\n\nopen import Cubical.HITs.PropositionalTruncation\n\nimport Cubical.Data.Everything as Data\nopen Data hiding (inl; inr)\n\nopen import Cubical.HITs.Interval\n\n-- Cylinder A is a cylinder object in the category of cubical types.\n--\n-- https://ncatlab.org/nlab/show/cylinder+object\ndata Cylinder {ℓ} (A : Type ℓ) : Type ℓ where\n inl : A → Cylinder A\n inr : A → Cylinder A\n cross : ∀ x → inl x ≡ inr x\n\n-- Dual to this is the cocylinder or path space object.\n--\n-- https://ncatlab.org/nlab/show/path+space+object\nCocylinder : ∀ {ℓ} → Type ℓ → Type ℓ\nCocylinder A = Interval → A\n\nmodule _ {ℓ} {A : Type ℓ} where\n -- The cylinder is part of a factorization of the obvious mapping\n -- of type A ⊎ A → A into a pair of mappings:\n --\n -- A ⊎ A → Cylinder A ≃ A\n --\n -- include is the first part of the factorization.\n include : A ⊎ A → Cylinder A\n include (Data.inl x) = inl x\n include (Data.inr x) = inr x\n\n -- The above inclusion is surjective\n includeSurjective : ∀ c → ∥ Σ[ s ∈ A ⊎ A ] include s ≡ c ∥\n includeSurjective (inl x) = ∣ Data.inl x , refl ∣\n includeSurjective (inr x) = ∣ Data.inr x , refl ∣\n includeSurjective (cross x i) =\n squash\n ∣ Data.inl x , (λ j → cross x (i ∧ j)) ∣\n ∣ Data.inr x , (λ j → cross x (i ∨ ~ j)) ∣\n i\n\n elimCyl\n : ∀{ℓ'} {B : Cylinder A → Type ℓ'}\n → (f : (x : A) → B (inl x))\n → (g : (x : A) → B (inr x))\n → (p : ∀ x → PathP (λ i → B (cross x i)) (f x) (g x))\n → (c : Cylinder A) → B c\n elimCyl f _ _ (inl x) = f x\n elimCyl _ g _ (inr x) = g x\n elimCyl _ _ p (cross x i) = p x i\n\n private\n out : Cylinder A → A\n out (inl x) = x\n out (inr x) = x\n out (cross x i) = x\n\n inl-out : (c : Cylinder A) → inl (out c) ≡ c\n inl-out (inl x) = refl\n inl-out (inr x) = cross x\n inl-out (cross x i) = λ j → cross x (i ∧ j)\n\n out-inl : ∀(x : A) → out (inl x) ≡ x\n out-inl x = refl\n\n -- The second part of the factorization above.\n CylinderA≃A : Cylinder A ≃ A\n CylinderA≃A = isoToEquiv (iso out inl out-inl inl-out)\n\n -- The cocylinder has a similar equivalence that is part\n -- of factorizing the diagonal mapping.\n private\n inco : A → Cocylinder A\n inco x _ = x\n\n outco : Cocylinder A → A\n outco f = f zero\n\n A→CocylinderA→A : (x : A) → outco (inco x) ≡ x\n A→CocylinderA→A x = refl\n\n CocylinderA→A→CocylinderA : (c : Cocylinder A) → inco (outco c) ≡ c\n CocylinderA→A→CocylinderA c j zero = c zero\n CocylinderA→A→CocylinderA c j one = c (seg j)\n CocylinderA→A→CocylinderA c j (seg i) = c (seg (j ∧ i))\n\n A≃CocylinderA : A ≃ Cocylinder A\n A≃CocylinderA =\n isoToEquiv (iso inco outco CocylinderA→A→CocylinderA A→CocylinderA→A)\n\n project : Cocylinder A → A × A\n project c = c zero , c one\n\n\n-- Since we can construct cylinders for every type, Cylinder actually\n-- constitutes a cylinder functor:\n--\n-- https://ncatlab.org/nlab/show/cylinder+functor\n--\n-- e₀ = inl\n-- e₁ = inr\n-- σ = out\nmodule Functorial where\n private\n variable\n ℓa ℓb ℓc : Level\n A : Type ℓa\n B : Type ℓb\n C : Type ℓc\n\n mapCylinder : (A → B) → Cylinder A → Cylinder B\n mapCylinder f (inl x) = inl (f x)\n mapCylinder f (inr x) = inr (f x)\n mapCylinder f (cross x i) = cross (f x) i\n\n mapCylinderId : mapCylinder (λ(x : A) → x) ≡ (λ x → x)\n mapCylinderId i (inl x) = inl x\n mapCylinderId i (inr x) = inr x\n mapCylinderId i (cross x j) = cross x j\n\n mapCylinder∘\n : (f : A → B) → (g : B → C)\n → mapCylinder (λ x → g (f x)) ≡ (λ x → mapCylinder g (mapCylinder f x))\n mapCylinder∘ f g i (inl x) = inl (g (f x))\n mapCylinder∘ f g i (inr x) = inr (g (f x))\n mapCylinder∘ f g i (cross x j) = cross (g (f x)) j\n\n -- There is an adjunction between the cylinder and coyclinder\n -- functors.\n --\n -- Cylinder ⊣ Cocylinder\n adj₁ : (Cylinder A → B) → A → Cocylinder B\n adj₁ f x zero = f (inl x)\n adj₁ f x one = f (inr x)\n adj₁ f x (seg i) = f (cross x i)\n\n adj₂ : (A → Cocylinder B) → Cylinder A → B\n adj₂ g (inl x) = g x zero\n adj₂ g (inr x) = g x one\n adj₂ g (cross x i) = g x (seg i)\n\n adj₁₂ : (g : A → Cocylinder B) → adj₁ (adj₂ g) ≡ g\n adj₁₂ g _ x zero = g x zero\n adj₁₂ g _ x one = g x one\n adj₁₂ g _ x (seg i) = g x (seg i)\n\n adj₂₁ : (f : Cylinder A → B) → adj₂ (adj₁ f) ≡ f\n adj₂₁ f j (inl x) = f (inl x)\n adj₂₁ f j (inr x) = f (inr x)\n adj₂₁ f j (cross x i) = f (cross x i)\n\nmodule IntervalEquiv where\n -- There is an equivalence between the interval and the\n -- cylinder over the unit type.\n Interval→CylinderUnit : Interval → Cylinder Unit\n Interval→CylinderUnit zero = inl _\n Interval→CylinderUnit one = inr _\n Interval→CylinderUnit (seg i) = cross _ i\n\n CylinderUnit→Interval : Cylinder Unit → Interval\n CylinderUnit→Interval (inl _) = zero\n CylinderUnit→Interval (inr _) = one\n CylinderUnit→Interval (cross _ i) = seg i\n\n Interval→CylinderUnit→Interval\n : ∀ i → CylinderUnit→Interval (Interval→CylinderUnit i) ≡ i\n Interval→CylinderUnit→Interval zero = refl\n Interval→CylinderUnit→Interval one = refl\n Interval→CylinderUnit→Interval (seg i) = refl\n\n CylinderUnit→Interval→CylinderUnit\n : ∀ c → Interval→CylinderUnit (CylinderUnit→Interval c) ≡ c\n CylinderUnit→Interval→CylinderUnit (inl _) = refl\n CylinderUnit→Interval→CylinderUnit (inr _) = refl\n CylinderUnit→Interval→CylinderUnit (cross _ i) = refl\n\n CylinderUnit≃Interval : Cylinder Unit ≃ Interval\n CylinderUnit≃Interval =\n isoToEquiv (iso CylinderUnit→Interval Interval→CylinderUnit Interval→CylinderUnit→Interval CylinderUnit→Interval→CylinderUnit)\n\n\n -- More generally, there is an equivalence between the cylinder\n -- over any type A and the product of A and the interval.\n module _ {ℓ} {A : Type ℓ} where\n private\n Cyl : Type ℓ\n Cyl = A × Interval\n\n CylinderA→A×Interval : Cylinder A → Cyl\n CylinderA→A×Interval (inl x) = x , zero\n CylinderA→A×Interval (inr x) = x , one\n CylinderA→A×Interval (cross x i) = x , seg i\n\n A×Interval→CylinderA : Cyl → Cylinder A\n A×Interval→CylinderA (x , zero) = inl x\n A×Interval→CylinderA (x , one) = inr x\n A×Interval→CylinderA (x , seg i) = cross x i\n\n A×Interval→CylinderA→A×Interval\n : ∀ c → CylinderA→A×Interval (A×Interval→CylinderA c) ≡ c\n A×Interval→CylinderA→A×Interval (x , zero) = refl\n A×Interval→CylinderA→A×Interval (x , one) = refl\n A×Interval→CylinderA→A×Interval (x , seg i) = refl\n\n CylinderA→A×Interval→CylinderA\n : ∀ c → A×Interval→CylinderA (CylinderA→A×Interval c) ≡ c\n CylinderA→A×Interval→CylinderA (inl x) = refl\n CylinderA→A×Interval→CylinderA (inr x) = refl\n CylinderA→A×Interval→CylinderA (cross x i) = refl\n\n CylinderA≃A×Interval : Cylinder A ≃ Cyl\n CylinderA≃A×Interval =\n isoToEquiv\n (iso CylinderA→A×Interval\n A×Interval→CylinderA\n A×Interval→CylinderA→A×Interval\n CylinderA→A×Interval→CylinderA)\n\n-- The cylinder is also the pushout of the identity on A with itself.\nmodule Push {ℓ} {A : Type ℓ} where\n open import Cubical.HITs.Pushout\n\n private\n Push : Type ℓ\n Push = Pushout (λ(x : A) → x) (λ x → x)\n\n Cyl : Type ℓ\n Cyl = Cylinder A\n\n Cylinder→Pushout : Cyl → Push\n Cylinder→Pushout (inl x) = inl x\n Cylinder→Pushout (inr x) = inr x\n Cylinder→Pushout (cross x i) = push x i\n\n Pushout→Cylinder : Push → Cyl\n Pushout→Cylinder (inl x) = inl x\n Pushout→Cylinder (inr x) = inr x\n Pushout→Cylinder (push x i) = cross x i\n\n Pushout→Cylinder→Pushout : ∀ p → Cylinder→Pushout (Pushout→Cylinder p) ≡ p\n Pushout→Cylinder→Pushout (inl x) = refl\n Pushout→Cylinder→Pushout (inr x) = refl\n Pushout→Cylinder→Pushout (push x i) = refl\n\n Cylinder→Pushout→Cylinder : ∀ c → Pushout→Cylinder (Cylinder→Pushout c) ≡ c\n Cylinder→Pushout→Cylinder (inl x) = refl\n Cylinder→Pushout→Cylinder (inr x) = refl\n Cylinder→Pushout→Cylinder (cross x i) = refl\n\n Pushout≃Cylinder : Push ≃ Cyl\n Pushout≃Cylinder =\n isoToEquiv\n (iso Pushout→Cylinder\n Cylinder→Pushout\n Cylinder→Pushout→Cylinder\n Pushout→Cylinder→Pushout)\n\n", "meta": {"hexsha": "0d1dfc6f0bd0a10b5af550998d07bb75fed46d33", "size": 8173, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/HITs/Cylinder/Base.agda", "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": "Cubical/HITs/Cylinder/Base.agda", "max_issues_repo_name": "limemloh/cubical", "max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": "Cubical/HITs/Cylinder/Base.agda", "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": 30.6104868914, "max_line_length": 130, "alphanum_fraction": 0.6373424691, "num_tokens": 2971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6297746074044135, "lm_q2_score": 0.6261241772283034, "lm_q1q2_score": 0.39431710790036617}} {"text": "\nmodule Oscar.Data.Permutation where\n\n--open import Data.Permutation public\nimport Data.Permutation as P\nopen import Data.Permutation renaming (delete to deleteP; _∘_ to _∘P_; enum to allInj)\n\nopen import Oscar.Data.Vec renaming (delete to deleteV; map to mapV)\n\n\nopen import Relation.Binary.PropositionalEquality\nopen import Data.Product\nopen import Data.Fin renaming (inject to injectF)\n\nopen ≡-Reasoning\n\nopen import Data.Permutation.Properties\n\nopen import Oscar.Data.Vec.Properties\nopen import Function\n\nopen import Data.Sum\nopen import Agda.Builtin.Nat\n\n<>-inv : ∀ {n} (ps : Permutation n) i → i ≡ < ps > (< ps ⁻¹ > i)\n<>-inv ps i =\n trans\n (sym (id-is-id i))\n (subst (< P.id > _ ≡_)\n (inj-correct (ps ⁻¹) ps i)\n (cong (flip <_> _)\n (sym (inv-left ps))))\n\n_⋟_÷_ : ∀ {a m n} {A : Set a} → Vec A n → Vec A m → Inj m n → Set a\nx ⋟ px ÷ p = ∀ i → lookup i px ≡ lookup (< p > i) x\n\nlookup-ext : ∀ {a n} {A : Set a} {pv₁ pv₂ : Vec A n} → (∀ i → lookup i pv₁ ≡ lookup i pv₂) → pv₁ ≡ pv₂\nlookup-ext {pv₁ = []} {[]} x = refl\nlookup-ext {pv₁ = x₁ ∷ pv₁} {x₂ ∷ pv₂} x with lookup-ext {pv₁ = pv₁} {pv₂} (x ∘ suc) | x zero\n… | refl | refl = refl\n\ninjected-inj : ∀ {a n m} {A : Set a} {v : Vec A m} {pv₁ pv₂ : Vec A n} {p : Inj n m} → v ⋟ pv₁ ÷ p → v ⋟ pv₂ ÷ p → pv₁ ≡ pv₂\ninjected-inj {pv₁ = pv₁} {pv₂} v⋟pv₁÷p v⋟pv₂÷p = lookup-ext foo where\n foo : (i : Fin _) → lookup i pv₁ ≡ lookup i pv₂\n foo i = trans (v⋟pv₁÷p i) (sym (v⋟pv₂÷p i))\n\npermuted-inj : ∀ {a n} {A : Set a} {v : Vec A n} {pv₁ pv₂ : Vec A n} {p : Permutation n} → v ⋟ pv₁ ÷ p → v ⋟ pv₂ ÷ p → pv₁ ≡ pv₂\npermuted-inj {pv₁ = pv₁} {pv₂} v⋟pv₁÷p v⋟pv₂÷p = lookup-ext foo where\n foo : (i : Fin _) → lookup i pv₁ ≡ lookup i pv₂\n foo i = trans (v⋟pv₁÷p i) (sym (v⋟pv₂÷p i))\n\npermutedLookup : ∀ {a n} {A : Set a} → Permutation n → Vec A n → Fin n → A\npermutedLookup p v = flip lookup v ∘ < p >\n\ninject : ∀ {a n m} {A : Set a} → (p : Inj n m) → (v : Vec A m) → Vec A n\ninject p v = tabulate (flip lookup v ∘ < p >)\n\npermute : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) → Vec A n\npermute p v = tabulate (flip lookup v ∘ < p >)\n\ninject-correct : ∀ {a n m} {A : Set a} → (p : Inj n m) → (v : Vec A m) →\n v ⋟ inject p v ÷ p\ninject-correct p v = lookup∘tabulate (flip lookup v ∘ < p >)\n\npermute-correct : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) →\n v ⋟ permute p v ÷ p\npermute-correct p v = lookup∘tabulate (flip lookup v ∘ < p >)\n\nPermute : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) →\n ∃ (v ⋟_÷ p)\nPermute p v = permute p v , permute-correct p v\n\n_⋟_÷? : ∀ {a m n} {A : Set a} → Vec A n → Vec A m → Set a\n_⋟_÷? x px = ∃ (x ⋟ px ÷_)\n\n∈-allInj : ∀ {n m} (i : Inj n m) → i ∈ allInj n m\n∈-allInj {zero} [] = here\n∈-allInj {suc n} (i ∷ is) = ∈-map₂ _∷_ (∈-allFin i) (∈-allInj is)\n\ntabulate₂ : ∀ {n m a} {A : Set a} → (Inj n m → A) → Vec A (size n m)\ntabulate₂ f = mapV f (allInj _ _)\n\n∈-tabulate₂ : ∀ {n m a} {A : Set a} (f : Inj n m → A) i → f i ∈ tabulate₂ f\n∈-tabulate₂ f i = ∈-map f (∈-allInj i)\n\nENUM₂ : ∀ {a n} {A : Set a} → (v : Vec A n) → Vec (∃ (v ⋟_÷?)) (size n n)\nENUM₂ v = tabulate₂ (λ p → permute p v , p , permute-correct p v)\n\nenumᵢ : ∀ {a n m} {A : Set a} → Vec A m → Vec (Vec A n) (size n m)\nenumᵢ v = tabulate₂ (flip inject v)\n\nenum₂ : ∀ {a n} {A : Set a} → Vec A n → Vec (Vec A n) (size n n)\nenum₂ v = tabulate₂ (flip permute v)\n\nenumᵢ-sound : ∀ {a} {A : Set a} {n m} (x : Vec A m) (px : Vec A n) → px ∈ enumᵢ x → x ⋟ px ÷?\nenumᵢ-sound x _ px∈enum₂x with map-∈ px∈enum₂x\nenumᵢ-sound x _ _ | p , refl = p , inject-correct p x\n\nenum₂-sound : ∀ {a} {A : Set a} {n} (x px : Vec A n) → px ∈ enum₂ x → x ⋟ px ÷?\nenum₂-sound x _ px∈enum₂x with map-∈ px∈enum₂x\nenum₂-sound x _ _ | p , refl = p , permute-correct p x\n\nremove-÷-zero : ∀ {n a} {A : Set a} {x : A} {xs : Vec A n} {px : A}\n {pxs : Vec A n} {ps : Inj n n} →\n (x ∷ xs) ⋟ px ∷ pxs ÷ (zero ∷ ps) →\n xs ⋟ pxs ÷ ps\nremove-÷-zero f i = f (suc i)\n\nenumᵢ-complete : ∀ {a} {A : Set a} {n m} (x : Vec A m) (px : Vec A n) → x ⋟ px ÷? → px ∈ enumᵢ x\nenumᵢ-complete x px (p , x⋟px÷p) = proof where\n p∈allInj : p ∈ allInj _ _\n p∈allInj = ∈-allInj p\n permutepx∈enum₂x : inject p x ∈ enumᵢ x\n permutepx∈enum₂x = ∈-map (flip inject x) p∈allInj\n x⋟permutepx÷p : x ⋟ inject p x ÷ p\n x⋟permutepx÷p = inject-correct p x\n proof : px ∈ enumᵢ x\n proof = subst (_∈ _) (injected-inj {p = p} x⋟permutepx÷p x⋟px÷p) permutepx∈enum₂x\n\nenum₂-complete : ∀ {a} {A : Set a} {n} (x px : Vec A n) → x ⋟ px ÷? → px ∈ enum₂ x\nenum₂-complete x px (p , x⋟px÷p) = proof where\n p∈allInj : p ∈ allInj _ _\n p∈allInj = ∈-allInj p\n permutepx∈enum₂x : permute p x ∈ enum₂ x\n permutepx∈enum₂x = ∈-map (flip permute x) p∈allInj\n x⋟permutepx÷p : x ⋟ permute p x ÷ p\n x⋟permutepx÷p = permute-correct p x\n proof : px ∈ enum₂ x\n proof = subst (_∈ _) (permuted-inj {p = p} x⋟permutepx÷p x⋟px÷p) permutepx∈enum₂x\n\nEnum₂ : ∀ {a n} {A : Set a} → (x : Vec A n) → Σ[ pxs ∈ Vec (Vec A n) (size n n) ] (∀ px → (px ∈ pxs → x ⋟ px ÷?) × (x ⋟ px ÷? → px ∈ pxs))\nEnum₂ x = enum₂ x , (λ px → enum₂-sound x px , enum₂-complete x px)\n\n_∃⊎∀_ : ∀ {a} {A : Set a} {l r} (L : A → Set l) (R : A → Set r) {p} (P : A → Set p) → Set _\n(L ∃⊎∀ R) P = (∃ λ x → P x × L x) ⊎ (∀ x → P x → R x)\n\nopen import Agda.Primitive\n\nstepDecide∃⊎∀ : ∀ {a} {A : Set a} {l r} {L : A → Set l} {R : A → Set r} → (∀ y → L y ⊎ R y) → ∀ {p} (P : A → Set p) →\n ∀ {d} (done : Vec A d) {nd} (not-done : Vec A nd) →\n (∀ y → y ∈ done ⊎ y ∈ not-done → P y) →\n (∀ y → P y → y ∈ done ⊎ y ∈ not-done) →\n (∀ y → y ∈ done → R y) →\n (L ∃⊎∀ R) P\nstepDecide∃⊎∀ dec P done {zero} not-done dnd-sound dnd-complete done-R = inj₂ (λ y Py → done-R y (dnd-done y Py)) where\n dnd-done : ∀ y → P y → y ∈ done\n dnd-done y Py with dnd-complete y Py\n dnd-done y Py | inj₁ y∈done = y∈done\n dnd-done y Py | inj₂ ()\nstepDecide∃⊎∀ dec P done {suc nd} (step ∷ not-dones) dnd-sound dnd-complete done-R with dec step\n… | inj₁ l = inj₁ (step , (dnd-sound step (inj₂ here)) , l)\n… | inj₂ r = stepDecide∃⊎∀ dec P (step ∷ done) not-dones stepdnd-sound stepdnd-complete (stepdone-R r) where\n stepdnd-sound : ∀ y → y ∈ step ∷ done ⊎ y ∈ not-dones → P y\n stepdnd-sound _ (inj₁ here) = dnd-sound step (inj₂ here)\n stepdnd-sound y (inj₁ (there y∈done)) = dnd-sound y (inj₁ y∈done)\n stepdnd-sound y (inj₂ y∈not-dones) = dnd-sound y (inj₂ (there y∈not-dones))\n\n stepdnd-complete : ∀ y → P y → y ∈ step ∷ done ⊎ y ∈ not-dones\n stepdnd-complete y Py with dnd-complete y Py\n stepdnd-complete y Py | inj₁ y∈done = inj₁ (there y∈done)\n stepdnd-complete y Py | inj₂ here = inj₁ here\n stepdnd-complete y Py | inj₂ (there y∈not-dones) = inj₂ y∈not-dones\n\n stepdone-R : _ → ∀ y → y ∈ step ∷ done → _\n stepdone-R Rstep _ here = Rstep\n stepdone-R Rstep y (there y∈done) = done-R y y∈done\n\ndecide∃⊎∀ : ∀ {a} {A : Set a} {l r} {L : A → Set l} {R : A → Set r} → (∀ y → L y ⊎ R y) → ∀ {p} (P : A → Set p) →\n ∀ {nd} (not-done : Vec A nd) →\n (∀ y → y ∈ not-done → P y) →\n (∀ y → P y → y ∈ not-done) →\n (L ∃⊎∀ R) P\ndecide∃⊎∀ dec P not-done nd-sound nd-complete = stepDecide∃⊎∀ dec P [] not-done []nd-sound []nd-complete (λ {_ ()}) where\n []nd-sound : ∀ y → y ∈ [] ⊎ y ∈ not-done → P y\n []nd-sound y (inj₁ ())\n []nd-sound y (inj₂ y∈not-done) = nd-sound y y∈not-done\n\n []nd-complete : ∀ y → P y → y ∈ [] ⊎ y ∈ not-done\n []nd-complete y Py = inj₂ (nd-complete y Py)\n\ndecidePermutations : ∀ {a n} {A : Set a} {l r} {L : Vec A n → Set l} {R : Vec A n → Set r} → ∀ x → (∀ y → L y ⊎ R y) →\n (L ∃⊎∀ R) (x ⋟_÷?)\ndecidePermutations x f = decide∃⊎∀ f _ (enum₂ x) (enum₂-sound x) (enum₂-complete x)\n\ndecideInjections : ∀ {a n m} {A : Set a} {l r} {L : Vec A n → Set l} {R : Vec A n → Set r} → ∀ (x : Vec A m) → (∀ y → L y ⊎ R y) →\n (L ∃⊎∀ R) (x ⋟_÷?)\ndecideInjections x f = decide∃⊎∀ f _ (enumᵢ x) (enumᵢ-sound x) (enumᵢ-complete x)\n\n-- -- sym-⋟∣ : ∀ {a n} {A : Set a} → (y x : Vec A n) → (p : Permutation n) →\n-- -- y ⋟ x ∣ p → x ⋟ y ∣ (p ⁻¹)\n-- -- sym-⋟∣ y x ps y⋟x∣p i =\n-- -- trans (cong (flip lookup x) {x = i} {y = < ps > (< ps ⁻¹ > i)} (<>-inv ps i)) (sym (y⋟x∣p (< ps ⁻¹ > i)))\n\n-- -- open import Oscar.Data.Vec.Properties\n\n-- -- Permute : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) →\n-- -- ∃ λ w → w ⋟ v ∥ p\n-- -- Permute [] v = v , λ ()\n-- -- Permute p@(p' ∷ ps) v@(v' ∷ vs) =\n-- -- let ws , [vs≡ws]ps = Permute ps (deleteV p' v)\n-- -- w = lookup p' v ∷ ws\n-- -- [v≡w]p : w ⋟ v ∥ p\n-- -- [v≡w]p = {!!}\n-- -- {-\n-- -- [v≡w]p = λ\n-- -- { zero → here\n-- -- ; (suc f) → there (subst (ws [ f ]=_)\n-- -- (lookup-delete-thin p' (< ps > f) v)\n-- -- ([vs≡ws]ps f)) }\n-- -- -}\n-- -- in\n-- -- w , [v≡w]p\n\n-- -- -- permute : ∀ {a n} {A : Set a} → Permutation n → Vec A n → Vec A n\n-- -- -- permute p v = proj₁ (Permute p v)\n\n-- -- -- permute-correct : ∀ {a n} {A : Set a} → (p : Permutation n) → (v : Vec A n) → v ⋟ permute p v ∥ p\n-- -- -- permute-correct p v = proj₂ (Permute p v)\n\n-- -- -- open import Function\n\n-- -- -- --∈-map-proj₁ : mapV proj₁ (mapV (λ p → F p , G p) xs) ≡ mapV F xs\n-- -- -- open import Data.Nat\n\n-- -- -- ∈-enum : ∀ {n m} (i : Inj n m) → i ∈ enum n m\n-- -- -- ∈-enum {zero} [] = here\n-- -- -- ∈-enum {suc n} (i ∷ is) = ∈-map₂ _∷_ (∈-allFin i) (∈-enum is)\n\n-- -- -- open import Data.Permutation.Properties\n\n-- -- -- [thin]=→delete[]= : ∀ {a n} {A : Set a} {i j} {v : Vec A (suc n)} {x} → v [ thin i j ]= x → deleteV i v [ j ]= x\n-- -- -- [thin]=→delete[]= {i = zero} {v = x ∷ v} (there x₂) = x₂\n-- -- -- [thin]=→delete[]= {n = zero} {i = suc ()} x₁\n-- -- -- [thin]=→delete[]= {n = suc n} {i = suc i} {zero} {x ∷ v} here = here\n-- -- -- [thin]=→delete[]= {n = suc n} {i = suc i} {suc j} {x ∷ v} (there v[thinij]=?) = there ([thin]=→delete[]= {i = i} v[thinij]=?)\n\n-- -- -- delete≡Permutation : ∀ {a n} {A : Set a} {v₀ : A} {v₊ : Vec A n} {w : Vec A (suc n)} {p : Permutation (suc n)} →\n-- -- -- (v₀ ∷ v₊) ⋟ w ∥ p →\n-- -- -- v₊ ⋟ deleteV (annihilator p) w ∥ delete (annihilator p) p\n-- -- -- delete≡Permutation {v₀ = v₀} {v₊} {w} {p} [v₀∷v₊≡w]p f = [thin]=→delete[]= {i = annihilator p} {j = f} qux where\n-- -- -- foo : thin (< p > (annihilator p)) (< delete (annihilator p) p > f) ≡ < p > (thin (annihilator p) f)\n-- -- -- foo = inj-thin p (annihilator p) f\n\n-- -- -- foo2 : suc (< delete (annihilator p) p > f) ≡ < p > (thin (annihilator p) f)\n-- -- -- foo2 = subst (λ y → thin y (< delete (annihilator p) p > f) ≡ < p > (thin (annihilator p) f)) (ann-correct p) foo\n\n-- -- -- bar : w [ thin (annihilator p) f ]= lookup (< p > (thin (annihilator p) f)) (v₀ ∷ v₊)\n-- -- -- bar = [v₀∷v₊≡w]p (thin (annihilator p) f)\n\n-- -- -- qux : w [ thin (annihilator p) f ]= lookup (< delete (annihilator p) p > f) v₊\n-- -- -- qux = subst (λ y → w [ thin (annihilator p) f ]= lookup y (v₀ ∷ v₊)) (sym foo2) bar\n\n-- -- -- permute-complete-step : ∀ {a n} {A : Set a} {v₀ : A} {w : Vec A (suc n)} {v₊ : Vec A n} (x : Fin (suc n)) →\n-- -- -- w [ x ]= v₀ →\n-- -- -- deleteV x w ∈ mapV (flip permute v₊) (enum n n) →\n-- -- -- w ∈ mapV (flip permute (v₀ ∷ v₊)) (enum (suc n) (suc n))\n-- -- -- permute-complete-step {n = zero} {w = x₃ ∷ []} {[]} zero here here = here\n-- -- -- permute-complete-step {n = zero} {w = x₃ ∷ []} {[]} zero x₁ (there ())\n-- -- -- permute-complete-step {n = zero} {w = x₃ ∷ []} {[]} (suc ()) x₁ x₂\n-- -- -- permute-complete-step {n = suc n} {w = w ∷ ws} x w∷ws[x]=v₀ x₂ = {!!}\n\n-- -- -- permute-lemma : ∀ {a n} {A : Set a} (v w : Vec A n) (p : Permutation n) →\n-- -- -- v ⋟ w ∥ p →\n-- -- -- w ≡ permute (p ⁻¹) v\n-- -- -- permute-lemma v w p x = {!permute-correct p w!}\n\n-- -- -- {-\n-- -- -- permute-complete' : ∀ {a n} {A : Set a} (v w : Vec A n) (p : Permutation n) →\n-- -- -- v ⋟ w ∥ p →\n-- -- -- ∀ {m} {ps : Vec (Permutation n) m} → p ∈ ps →\n-- -- -- w ≡ permute p v\n-- -- -- w ∈ mapV (flip\n-- -- -- -}\n\n-- -- -- permute-complete : ∀ {a n} {A : Set a} (v w : Vec A n) →\n-- -- -- v ∃≡Permutation w →\n-- -- -- w ∈ mapV (flip permute v) (enum n n)\n-- -- -- permute-complete [] [] (p , [v≡w]p) = here\n-- -- -- permute-complete {n = suc n} v@(v₀ ∷ v₊) w (p , [v≡w]p) = permute-complete-step (annihilator p) w[ap]=v₀ pc' where\n-- -- -- w[ap]=v₀ : w [ annihilator p ]= v₀\n-- -- -- w[ap]=v₀ = {![v≡w]p (annihilator p)!}\n-- -- -- pc' : deleteV (annihilator p) w ∈ mapV (flip permute v₊) (enum n n)\n-- -- -- pc' = permute-complete v₊ (deleteV (annihilator p) w) (delete (annihilator p) p , delete≡Permutation {p = p} [v≡w]p)\n\n-- -- -- EnumPermutations : ∀ {a n} {A : Set a} → (v : Vec A n) →\n-- -- -- Σ (Vec (∃ (v ∃≡Permutation_)) (size n n)) λ ws\n-- -- -- → ∀ w → (v ∃≡Permutation w → w ∈ mapV proj₁ ws)\n-- -- -- EnumPermutations {n = n} v = mapV (λ p → permute p v , p , permute-correct p v) (enum n n) , (λ w v∃≡Pw → subst (w ∈_) (map-∘ proj₁ (λ p → permute p v , p , permute-correct p v) (enum n n)) (permute-complete v w v∃≡Pw))\n\n-- -- -- enumPermutations : ∀ {a n} {A : Set a} → Vec A n → Vec (Vec A n) (size n n)\n-- -- -- enumPermutations {n = n} xs = mapV (λ p → permute p xs) (enum n n)\n\n-- -- -- tryPermutations : ∀ {a n} {A : Set a} {l r} {L : Vec A n → Set l} {R : Vec A n → Set r} → ∀ x → (f : ∀ y → L y ⊎ R y) → Vec (∃ λ y → x ∃≡Permutation y × L y ⊎ R y) (size n n)\n-- -- -- tryPermutations x f = mapV (λ x₁ → x₁ , {!!}) (enumPermutations x)\n", "meta": {"hexsha": "0e9b90e1cff47752e8d5e3241056316a6623cde0", "size": 13698, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "archive/agda-2/Oscar/Data/Permutation.agda", "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "archive/agda-2/Oscar/Data/Permutation.agda", "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_forks_repo_path": "archive/agda-2/Oscar/Data/Permutation.agda", "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.4338983051, "max_line_length": 228, "alphanum_fraction": 0.5015330705, "num_tokens": 6038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.6370307806984444, "lm_q1q2_score": 0.3941821827887669}} {"text": "------------------------------------------------------------------------\n-- Code related to the paper \"Partiality, Revisited: The Partiality\n-- Monad as a Quotient Inductive-Inductive Type\"\n--\n-- Thorsten Altenkirch, Nils Anders Danielsson and Nicolai Kraus\n------------------------------------------------------------------------\n\n-- Note that this is a version of the code that does not quite match\n-- the description in the paper. Some key changes (there might be\n-- others):\n--\n-- * The partiality monad is not postulated, but defined as a QIIT\n-- (Agda's cubical features are used). The types and eliminators are\n-- marked as \"abstract\", so the eliminators do not compute.\n--\n-- * Rewrite rules are no longer used. Instead the propositional\n-- truncation and set quotient operators are defined as\n-- (non-abstract) QITs.\n--\n-- * The set quotient operator that is used can be applied to\n-- arbitrary binary relations, not only propositional ones.\n\n{-# OPTIONS --cubical --sized-types #-}\n\nmodule README where\n\n-- Note that our definition of the partiality monad and some of the\n-- results are heavily inspired by the section on Cauchy reals in the\n-- HoTT book (first edition).\n\n-- The partiality algebra code uses ideas and concepts from \"Inductive\n-- types in homotopy type theory\" by Awodey, Gambino and Sojakova,\n-- \"Inductive Types in Homotopy Type Theory\" by Sojakova, \"Quotient\n-- inductive-inductive types\" by Altenkirch, Capriotti, Dijkstra and\n-- Nordvall Forsberg, and Gabe Dijkstra's PhD thesis.\n\n------------------------------------------------------------------------\n-- Pointers to results from the paper\n\n-- In order to more easily find code corresponding to results from the\n-- paper, see the following module. Note that some of the code\n-- referenced below is not discussed at all in the paper.\n\nimport README.Pointers-to-results-from-the-paper\n\n------------------------------------------------------------------------\n-- Partiality algebras\n\n-- Partiality algebras.\n\nimport Partiality-algebra\n\n-- Some partiality algebra properties.\n\nimport Partiality-algebra.Properties\n\n-- Partiality algebra categories.\n\nimport Partiality-algebra.Category\n\n-- Eliminators and initiality.\n\nimport Partiality-algebra.Eliminators\n\n-- Monotone functions.\n\nimport Partiality-algebra.Monotone\n\n-- ω-continuous functions.\n\nimport Partiality-algebra.Omega-continuous\n\n-- Strict ω-continuous functions.\n\nimport Partiality-algebra.Strict-omega-continuous\n\n-- Fixpoint combinators.\n\nimport Partiality-algebra.Fixpoints\n\n-- Pi with partiality algebra families as codomains.\n\nimport Partiality-algebra.Pi\n\n------------------------------------------------------------------------\n-- The partiality monad\n\n-- A quotient inductive-inductive definition of the partiality monad.\n\nimport Partiality-monad.Inductive\n\n-- Specialised eliminators.\n\nimport Partiality-monad.Inductive.Eliminators\n\n-- A function that runs computations.\n\nimport Partiality-monad.Inductive.Approximate\n\n-- An alternative characterisation of the information ordering, along\n-- with related results.\n\nimport Partiality-monad.Inductive.Alternative-order\n\n-- Monotone functions.\n\nimport Partiality-monad.Inductive.Monotone\n\n-- ω-continuous functions.\n\nimport Partiality-monad.Inductive.Omega-continuous\n\n-- The partiality monad's monad instance.\n\nimport Partiality-monad.Inductive.Monad\n\n-- The partiality monad's monad instance, defined via an adjunction.\n\nimport Partiality-monad.Inductive.Monad.Adjunction\n\n-- Strict ω-continuous functions.\n\nimport Partiality-monad.Inductive.Strict-omega-continuous\n\n-- Fixpoint combinators.\n\nimport Partiality-monad.Inductive.Fixpoints\n\n------------------------------------------------------------------------\n-- Some examples\n\n-- A function that, given a stream, tries to find an element\n-- satisfying a predicate.\n\nimport Search\n\n-- Examples involving simple λ-calculi.\n\nimport README.Lambda\n\n------------------------------------------------------------------------\n-- An alternative definition of the delay monad\n\n-- The delay monad, defined using increasing sequences of potential\n-- values.\n\nimport Delay-monad.Alternative\n\n-- Various properties.\n\nimport Delay-monad.Alternative.Properties\n\n-- Theorems relating the coinductive definition of the delay\n-- monad to the alternative one and to another type.\n\nimport Delay-monad.Alternative.Equivalence\n\n-- Termination predicates.\n\nimport Delay-monad.Alternative.Termination\n\n-- Information orderings.\n\nimport Delay-monad.Alternative.Partial-order\n\n-- Weak bisimilarity.\n\nimport Delay-monad.Alternative.Weak-bisimilarity\n\n-- Two eliminators for Delay-monad.Alternative.Delay (A / R).\n\nimport Delay-monad.Alternative.Eliminators\n\n------------------------------------------------------------------------\n-- The delay monad quotiented by weak bisimilarity\n\n-- The delay monad quotiented by weak bisimilarity.\n\nimport Partiality-monad.Coinductive\n\n-- A partial order.\n\nimport Partiality-monad.Coinductive.Partial-order\n\n-- An alternative definition of the partiality monad: a variant of the\n-- delay monad quotiented by a notion of weak bisimilarity.\n\nimport Partiality-monad.Coinductive.Alternative\n\n------------------------------------------------------------------------\n-- A proof of equivalence\n\n-- The partiality monads in Partiality-monad.Inductive and\n-- Partiality-monad.Coinductive are pointwise equivalent, for sets,\n-- assuming extensionality and countable choice.\n\nimport Partiality-monad.Equivalence\n\n------------------------------------------------------------------------\n-- ω-cpos\n\n-- Pointed and non-pointed ω-cpos.\n\nimport Omega-cpo\n\n-- The code in the following three modules is based on a suggestion\n-- from Paolo Capriotti.\n\n-- A quotient inductive-inductive definition of the lifting\n-- construction on ω-cpos.\n\nimport Lifting\n\n-- An alternative but equivalent definition of the partiality monad\n-- (but only for sets), based on the lifting construction in Lifting.\n\nimport Lifting.Partiality-monad\n", "meta": {"hexsha": "4fd78d0a3994ddeb8e2b2c79f9c9db5995fac11c", "size": 5978, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "README.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": "README.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": "README.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": 27.4220183486, "max_line_length": 72, "alphanum_fraction": 0.6870190699, "num_tokens": 1279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.3940588332391471}} {"text": "{-# OPTIONS --without-K #-}\nmodule Explore.Examples where\n\nopen import Type\nopen import Level.NP\nopen import Data.Maybe.NP\nopen import Data.List\nopen import Data.Zero\nopen import Data.One\nopen import Data.Two\nopen import Data.Product\nopen import Data.Sum.NP\nopen import HoTT using (UA)\nopen import Function.NP\nopen import Function.Extensionality using (FunExt)\nopen import Relation.Binary.PropositionalEquality hiding ([_])\n\nopen import Explore.Core\nopen import Explore.Explorable\nopen import Explore.Universe.Type {𝟘}\nopen import Explore.Universe.Base\nopen import Explore.Monad {₀} ₀ public renaming (map to map-explore)\nopen import Explore.Two\nopen import Explore.Product\nopen Explore.Product.Operators\n\nmodule E where\n open FromExplore public\n\nmodule M {Msg Digest : ★}\n (_==_ : Digest → Digest → 𝟚)\n (H : Msg → Digest)\n (exploreMsg : ∀ {ℓ} → Explore ℓ Msg)\n (d : Digest) where\n\n module V1 where\n list-H⁻¹ : List Msg\n list-H⁻¹ = exploreMsg [] _++_ (λ m → [0: [] 1: [ m ] ] (H m == d))\n\n module ExploreMsg = FromExplore {A = Msg} exploreMsg\n\n module V2 where\n first-H⁻¹ : Maybe Msg\n first-H⁻¹ = ExploreMsg.findKey (λ m → H m == d)\n\n module V3 where\n explore-H⁻¹ : Explore ₀ Msg\n explore-H⁻¹ ε _⊕_ f = exploreMsg ε _⊕_ (λ m → [0: ε 1: f m ] (H m == d))\n\n module V4 where\n explore-H⁻¹ : Explore ₀ Msg\n explore-H⁻¹ = exploreMsg >>= λ m → [0: empty-explore 1: point-explore m ] (H m == d)\n\n module V5 where\n\n explore-H⁻¹ : ∀ {ℓ} → Explore ℓ Msg\n explore-H⁻¹ = filter-explore (λ m → H m == d) exploreMsg\n\n list-H⁻¹ : List Msg\n list-H⁻¹ = E.list explore-H⁻¹\n\n first-H⁻¹ : Maybe Msg\n first-H⁻¹ = E.first explore-H⁻¹\n\n module V6 where\n explore-H⁻¹ : ∀ {ℓ} → Explore ℓ Msg\n explore-H⁻¹ = explore-endo (filter-explore (λ m → H m == d) exploreMsg)\n\n list-H⁻¹ : List Msg\n list-H⁻¹ = E.list explore-H⁻¹\n\n first-H⁻¹ : Maybe Msg\n first-H⁻¹ = E.first explore-H⁻¹\n\n last-H⁻¹ : Maybe Msg\n last-H⁻¹ = E.last explore-H⁻¹\n\nMsg = 𝟚 × 𝟚\nDigest = 𝟚\n-- _==_ : Digest → Digest → 𝟚\nH : Msg → Digest\nH (x , y) = x xor y\nMsgᵉ : ∀ {ℓ} → Explore ℓ Msg\nMsgᵉ = 𝟚ᵉ ×ᵉ 𝟚ᵉ\nmodule N5 = M.V5 _==_ H Msgᵉ\nmodule N6 = M.V6 _==_ H Msgᵉ\ntest5 = N5.list-H⁻¹\ntest6-list : N6.list-H⁻¹ 0₂ ≡ (0₂ , 0₂) ∷ (1₂ , 1₂) ∷ []\ntest6-list = refl\ntest6-rev-list : E.list (E.backward (N6.explore-H⁻¹ 0₂)) ≡ (1₂ , 1₂) ∷ (0₂ , 0₂) ∷ []\ntest6-rev-list = refl\ntest6-first : N6.first-H⁻¹ 0₂ ≡ just (0₂ , 0₂)\ntest6-first = refl\ntest6-last : N6.last-H⁻¹ 0₂ ≡ just (1₂ , 1₂)\ntest6-last = refl\n-- -}\n\n𝟛ᵁ : U\n𝟛ᵁ = 𝟙ᵁ ⊎ᵁ 𝟚ᵁ\n\nprop-∧-comm : 𝟚 × 𝟚 → 𝟚\nprop-∧-comm (x , y) = x ∧ y == y ∧ x\n\nmodule _ {{_ : UA}}{{_ : FunExt}} where\n check-∧-comm : ∀ x y → ✓ (x ∧ y == y ∧ x)\n check-∧-comm x y = check! (𝟚ᵁ ×ᵁ 𝟚ᵁ) prop-∧-comm (x , y)\n\nprop-∧-∨-distr : 𝟚 × 𝟚 × 𝟚 → 𝟚\nprop-∧-∨-distr (x , y , z) = x ∧ (y ∨ z) == x ∧ y ∨ x ∧ z\n\nmodule _ {{_ : UA}}{{_ : FunExt}} where\n check-∧-∨-distr : ∀ x y z → ✓ (x ∧ (y ∨ z) == x ∧ y ∨ x ∧ z)\n check-∧-∨-distr x y z =\n check! (𝟚ᵁ ×ᵁ 𝟚ᵁ ×ᵁ 𝟚ᵁ) prop-∧-∨-distr (x , y , z)\n\nlist22 = list (𝟚ᵁ →ᵁ 𝟚ᵁ)\nlist33 = list (𝟛ᵁ →ᵁ 𝟛ᵁ)\n\n{-\nmodule _ {{_ : UA}}{{_ : FunExt}} where\n module _ (fᵁ : El (𝟚ᵁ →ᵁ 𝟚ᵁ)) x where\n f = →ᵁ→→ 𝟚ᵁ 𝟚ᵁ fᵁ\n check22 : ✓ (f x == f (f (f x)))\n check22 = check! ((𝟚ᵁ →ᵁ 𝟚ᵁ) ×ᵁ 𝟚ᵁ) (λ { (f , x) → let f' = →ᵁ→→ 𝟚ᵁ 𝟚ᵁ f in f' x == f' (f' (f' x)) }) {{!!}} ((f 0₂ , f 1₂) , x)\n {-\n check22 : ∀ (f : 𝟚 → 𝟚) x → ✓ (f x == f (f (f x)))\n check22 f x = let k = check! ((𝟚ᵁ →ᵁ 𝟚ᵁ) ×ᵁ 𝟚ᵁ) (λ { (f , x) → let f' = →ᵁ→→ 𝟚ᵁ 𝟚ᵁ f in f' x == f' (f' (f' x)) }) {{!!}} ((f 0₂ , f 1₂) , x) in {!k!}\n-- -}\n-- -}\n-- -}\n-- -}\n", "meta": {"hexsha": "5a7ea1b35c03dac349d4f041f492ab22484a1155", "size": 3605, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lib/Explore/Examples.agda", "max_stars_repo_name": "crypto-agda/explore", "max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z", "max_issues_repo_path": "lib/Explore/Examples.agda", "max_issues_repo_name": "crypto-agda/explore", "max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z", "max_forks_repo_path": "lib/Explore/Examples.agda", "max_forks_repo_name": "crypto-agda/explore", "max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "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": 27.3106060606, "max_line_length": 151, "alphanum_fraction": 0.5672676838, "num_tokens": 1699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.640635868562172, "lm_q2_score": 0.6150878414043814, "lm_q1q2_score": 0.39404733352012744}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import homotopy.HSpace renaming (HSpaceStructure to HSS)\nopen import homotopy.Freudenthal\nopen import homotopy.IterSuspensionStable\nopen import homotopy.Pi2HSusp\nopen import homotopy.EM1HSpace\nopen import homotopy.EilenbergMacLane1\n\nmodule homotopy.EilenbergMacLane where\n\nprivate\n -- helper\n kle : (n : ℕ) → ⟨ S (S n) ⟩ ≤T ⟨ n ⟩ +2+ ⟨ n ⟩\n kle O = inl idp\n kle (S n) = ≤T-trans (≤T-ap-S (kle n))\n (≤T-trans (inl (! (+2+-βr ⟨ n ⟩ ⟨ n ⟩)))\n (inr ltS))\n\n-- EM(G,n) when G is π₁(A,a₀)\nmodule EMImplicit {i} {X : Ptd i} {{_ : is-connected 0 (de⊙ X)}}\n {{X-level : has-level 1 (de⊙ X)}} (H-X : HSS X) where\n\n private\n A = de⊙ X\n a₀ = pt X\n\n ⊙EM : (n : ℕ) → Ptd i\n ⊙EM O = ⊙Ω X\n ⊙EM (S n) = ⊙Trunc ⟨ S n ⟩ (⊙Susp^ n X)\n\n module _ (n : ℕ) where\n EM = de⊙ (⊙EM n)\n\n EM-level : (n : ℕ) → has-level ⟨ n ⟩ (EM n)\n EM-level O = has-level-apply X-level _ _\n EM-level (S n) = Trunc-level\n\n instance\n EM-conn : (n : ℕ) → is-connected ⟨ n ⟩ (EM (S n))\n EM-conn n = Trunc-preserves-conn (⊙Susp^-conn' n)\n\n {-\n π (S k) (EM (S n)) (embase (S n)) == π k (EM n) (embase n)\n where k > 0 and n = S (S n')\n -}\n module Stable (k n : ℕ) (indexing : S k ≤ S (S n))\n where\n\n private\n SSn : ℕ\n SSn = S (S n)\n\n lte : ⟨ S k ⟩ ≤T ⟨ SSn ⟩\n lte = ⟨⟩-monotone-≤ $ indexing\n\n Skle : S k ≤ (S n) *2\n Skle = ≤-trans indexing (lemma n)\n where lemma : (n' : ℕ) → S (S n') ≤ (S n') *2\n lemma O = inl idp\n lemma (S n') = ≤-trans (≤-ap-S (lemma n')) (inr ltS)\n\n private\n module SS = Susp^StableSucc k (S n) Skle (⊙Susp^ (S n) X) {{⊙Susp^-conn' (S n)}}\n\n abstract\n stable : πS (S k) (⊙EM (S SSn)) ≃ᴳ πS k (⊙EM SSn)\n stable =\n πS (S k) (⊙EM (S SSn))\n ≃ᴳ⟨ πS-Trunc-fuse-≤-iso _ _ _ (≤T-ap-S lte) ⟩\n πS (S k) (⊙Susp^ SSn X)\n ≃ᴳ⟨ SS.stable ⟩\n πS k (⊙Susp^ (S n) X)\n ≃ᴳ⟨ πS-Trunc-fuse-≤-iso _ _ _ lte ⁻¹ᴳ ⟩\n πS k (⊙EM SSn)\n ≃ᴳ∎\n\n module BelowDiagonal where\n\n π₁ : (n : ℕ) → πS 0 (⊙EM (S (S n))) ≃ᴳ 0ᴳ\n π₁ n =\n contr-iso-0ᴳ (πS 0 (⊙EM (S (S n))))\n (connected-at-level-is-contr\n {{raise-level-≤T (≤T-ap-S (≤T-ap-S (-2≤T ⟨ n ⟩₋₂)))\n (Trunc-level {n = 0})}})\n\n -- some clutter here arises from the definition of <;\n -- any simple way to avoid this?\n πS-below : (k n : ℕ) → (S k < n)\n → πS k (⊙EM n) ≃ᴳ 0ᴳ\n πS-below 0 .2 ltS = π₁ 0\n πS-below 0 .3 (ltSR ltS) = π₁ 1\n πS-below 0 (S (S n)) (ltSR (ltSR _)) = π₁ n\n πS-below (S k) ._ ltS =\n πS-below k _ ltS\n ∘eᴳ Stable.stable k k (inr ltS)\n πS-below (S k) ._ (ltSR ltS) =\n πS-below k _ (ltSR ltS)\n ∘eᴳ Stable.stable k (S k) (inr (ltSR ltS))\n πS-below (S k) ._ (ltSR (ltSR ltS)) =\n πS-below k _ (ltSR (ltSR ltS))\n ∘eᴳ Stable.stable k (S (S k)) (inr (ltSR (ltSR ltS)))\n πS-below (S k) (S (S (S n))) (ltSR (ltSR (ltSR lt))) =\n πS-below k _ (<-cancel-S (ltSR (ltSR (ltSR lt))))\n ∘eᴳ Stable.stable k n (inr (<-cancel-S (ltSR (ltSR (ltSR lt)))))\n\n\n module OnDiagonal where\n\n π₁ : πS 0 (⊙EM 1) ≃ᴳ πS 0 X\n π₁ = πS-Trunc-fuse-≤-iso 0 1 X ≤T-refl\n\n private\n module Π₂ = Pi2HSusp H-X\n\n π₂ : πS 1 (⊙EM 2) ≃ᴳ πS 0 X\n π₂ = Π₂.π₂-Susp\n ∘eᴳ πS-Trunc-fuse-≤-iso 1 2 (⊙Susp (de⊙ X)) ≤T-refl\n\n πS-diag : (n : ℕ) → πS n (⊙EM (S n)) ≃ᴳ πS 0 X\n πS-diag 0 = π₁\n πS-diag 1 = π₂\n πS-diag (S (S n)) = πS-diag (S n)\n ∘eᴳ Stable.stable (S n) n ≤-refl\n\n module AboveDiagonal where\n\n πS-above : ∀ (k n : ℕ) → (n < S k)\n → πS k (⊙EM n) ≃ᴳ 0ᴳ\n πS-above k n lt =\n contr-iso-0ᴳ (πS k (⊙EM n))\n (inhab-prop-is-contr\n [ idp^ (S k) ]\n {{Trunc-preserves-level 0 (Ω^-level -1 (S k) _\n (raise-level-≤T (lemma lt) (EM-level n)))}})\n where lemma : {k n : ℕ} → n < k → ⟨ n ⟩ ≤T (⟨ k ⟩₋₂ +2+ -1)\n lemma ltS = inl (! (+2+-comm _ -1))\n lemma (ltSR lt) = ≤T-trans (lemma lt) (inr ltS)\n\n module Spectrum where\n\n private\n module Π₂ = Pi2HSusp H-X\n\n spectrum0 : ⊙Ω (⊙EM 1) ⊙≃ ⊙EM 0\n spectrum0 =\n ⊙Ω (⊙EM 1)\n ⊙≃⟨ ⊙Ω-⊙Trunc-comm 0 X ⟩\n ⊙Trunc 0 (⊙Ω X)\n ⊙≃⟨ ⊙unTrunc-equiv (⊙Ω X) ⟩\n ⊙Ω X ⊙≃∎\n\n spectrum1 : ⊙Ω (⊙EM 2) ⊙≃ ⊙EM 1\n spectrum1 =\n ⊙Ω (⊙EM 2)\n ⊙≃⟨ ⊙Ω-⊙Trunc-comm 1 (⊙Susp (de⊙ X)) ⟩\n ⊙Trunc 1 (⊙Ω (⊙Susp (de⊙ X)))\n ⊙≃⟨ Π₂.⊙eq ⟩\n ⊙EM 1 ⊙≃∎\n\n sconn : (n : ℕ) → is-connected ⟨ S n ⟩ (de⊙ (⊙Susp^ (S n) X))\n sconn n = ⊙Susp^-conn' (S n)\n\n module FS (n : ℕ) =\n FreudenthalEquiv ⟨ n ⟩₋₁ ⟨ S (S n) ⟩ (kle n)\n (⊙Susp^ (S n) X) {{sconn n}}\n\n Trunc-fmap-σloop-is-equiv : ∀ (n : ℕ)\n → is-equiv (Trunc-fmap {n = ⟨ S n ⟩} (σloop (⊙Susp^ n X)))\n Trunc-fmap-σloop-is-equiv O = snd (Π₂.eq ⁻¹)\n Trunc-fmap-σloop-is-equiv (S n) = snd (FS.eq n)\n\n spectrumSS : (n : ℕ)\n → ⊙Ω (⊙EM (S (S (S n)))) ⊙≃ ⊙EM (S (S n))\n spectrumSS n =\n ⊙Ω (⊙EM (S (S (S n))))\n ⊙≃⟨ ⊙Ω-⊙Trunc-comm ⟨ S (S n) ⟩ (⊙Susp^ (S (S n)) X) ⟩\n ⊙Trunc ⟨ S (S n) ⟩ (⊙Ω (⊙Susp^ (S (S n)) X))\n ⊙≃⟨ FS.⊙eq n ⊙⁻¹ ⟩\n ⊙EM (S (S n)) ⊙≃∎\n\n ⊙–>-spectrumSS : ∀ (n : ℕ)\n → ⊙–> (spectrumSS n) ◃⊙idf\n =⊙∘\n FS.⊙encodeN n ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm ⟨ S (S n) ⟩ (⊙Susp^ (S (S n)) X)) ◃⊙idf\n ⊙–>-spectrumSS n =\n ⊙–> (spectrumSS n) ◃⊙idf\n =⊙∘⟨ =⊙∘-in {gs = ⊙<– (FS.⊙eq n) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm ⟨ S (S n) ⟩ (⊙Susp^ (S (S n)) X)) ◃⊙idf} $\n ⊙λ= (⊙∘-unit-l _) ⟩\n ⊙<– (FS.⊙eq n) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm ⟨ S (S n) ⟩ (⊙Susp^ (S (S n)) X)) ◃⊙idf\n =⊙∘₁⟨ 0 & 1 & FS.⊙<–-⊙eq n ⟩\n FS.⊙encodeN n ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm ⟨ S (S n) ⟩ (⊙Susp^ (S (S n)) X)) ◃⊙idf ∎⊙∘\n\n spectrum : (n : ℕ) → ⊙Ω (⊙EM (S n)) ⊙≃ ⊙EM n\n spectrum 0 = spectrum0\n spectrum 1 = spectrum1\n spectrum (S (S n)) = spectrumSS n\n\nmodule EMImplicitMap {i} {j} {X : Ptd i} {Y : Ptd j} (f : X ⊙→ Y)\n {{_ : is-connected 0 (de⊙ X)}} {{_ : is-connected 0 (de⊙ Y)}}\n {{X-level : has-level 1 (de⊙ X)}} {{Y-level : has-level 1 (de⊙ Y)}}\n (H-X : HSS X) (H-Y : HSS Y) where\n\n ⊙EM-fmap : ∀ n → EMImplicit.⊙EM H-X n ⊙→ EMImplicit.⊙EM H-Y n\n ⊙EM-fmap O = ⊙Ω-fmap f\n ⊙EM-fmap (S n) = ⊙Trunc-fmap (⊙Susp^-fmap n f)\n\nmodule SpectrumNatural {i} {X Y : Ptd i} (f : X ⊙→ Y)\n {{_ : is-connected 0 (de⊙ X)}} {{_ : is-connected 0 (de⊙ Y)}}\n {{X-level : has-level 1 (de⊙ X)}} {{Y-level : has-level 1 (de⊙ Y)}}\n (H-X : HSS X) (H-Y : HSS Y) where\n\n open EMImplicitMap f H-X H-Y\n\n open EMImplicit.Spectrum\n\n ⊙–>-spectrum0-natural :\n ⊙–> (spectrum0 H-Y) ◃⊙∘\n ⊙Ω-fmap (⊙Trunc-fmap f) ◃⊙idf\n =⊙∘\n ⊙Ω-fmap f ◃⊙∘\n ⊙–> (spectrum0 H-X) ◃⊙idf\n ⊙–>-spectrum0-natural =\n ⊙–> (spectrum0 H-Y) ◃⊙∘\n ⊙Ω-fmap (⊙Trunc-fmap f) ◃⊙idf\n =⊙∘⟨ 0 & 1 & ⊙expand (⊙–> (⊙unTrunc-equiv (⊙Ω Y)) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm 0 Y) ◃⊙idf) ⟩\n ⊙–> (⊙unTrunc-equiv (⊙Ω Y)) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm 0 Y) ◃⊙∘\n ⊙Ω-fmap (⊙Trunc-fmap f) ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙–>-⊙Ω-⊙Trunc-comm-natural-=⊙∘ 0 f ⟩\n ⊙–> (⊙unTrunc-equiv (⊙Ω Y)) ◃⊙∘\n ⊙Trunc-fmap (⊙Ω-fmap f) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm (S (S ⟨-2⟩)) X) ◃⊙idf\n =⊙∘⟨ 0 & 2 & ⊙–>-⊙unTrunc-equiv-natural-=⊙∘ (⊙Ω-fmap f) ⟩\n ⊙Ω-fmap f ◃⊙∘\n ⊙–> (⊙unTrunc-equiv (⊙Ω X)) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm (S (S ⟨-2⟩)) X) ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙contract ⟩\n ⊙Ω-fmap f ◃⊙∘\n ⊙–> (spectrum0 H-X) ◃⊙idf ∎⊙∘\n\n ⊙–>-spectrum1-natural :\n ⊙–> (spectrum1 H-Y) ◃⊙∘\n ⊙Ω-fmap (⊙Trunc-fmap (⊙Susp-fmap (fst f))) ◃⊙idf\n =⊙∘\n ⊙Trunc-fmap f ◃⊙∘\n ⊙–> (spectrum1 H-X) ◃⊙idf\n ⊙–>-spectrum1-natural =\n ⊙–> (spectrum1 H-Y) ◃⊙∘\n ⊙Ω-fmap (⊙Trunc-fmap (⊙Susp-fmap (fst f))) ◃⊙idf\n =⊙∘⟨ 0 & 1 & ⊙expand (⊙–> (Pi2HSusp.⊙eq H-Y) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm 1 (⊙Susp (de⊙ Y))) ◃⊙idf) ⟩\n ⊙–> (Pi2HSusp.⊙eq H-Y) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm 1 (⊙Susp (de⊙ Y))) ◃⊙∘\n ⊙Ω-fmap (⊙Trunc-fmap (⊙Susp-fmap (fst f))) ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙–>-⊙Ω-⊙Trunc-comm-natural-=⊙∘ 1 (⊙Susp-fmap (fst f)) ⟩\n ⊙–> (Pi2HSusp.⊙eq H-Y) ◃⊙∘\n ⊙Trunc-fmap (⊙Ω-fmap (⊙Susp-fmap (fst f))) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm 1 (⊙Susp (de⊙ X))) ◃⊙idf\n =⊙∘⟨ 0 & 2 & Pi2HSuspNaturality.⊙encodeN-natural f H-X H-Y ⟩\n ⊙Trunc-fmap f ◃⊙∘\n ⊙–> (Pi2HSusp.⊙eq H-X) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm (S (S (S ⟨-2⟩))) (⊙Susp (de⊙ X))) ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙contract ⟩\n ⊙Trunc-fmap f ◃⊙∘\n ⊙–> (spectrum1 H-X) ◃⊙idf ∎⊙∘\n\n ⊙–>-spectrumSS-natural : ∀ (n : ℕ)\n → ⊙–> (spectrumSS H-Y n) ◃⊙∘\n ⊙Ω-fmap (⊙Trunc-fmap (⊙Susp^-fmap (S (S n)) f)) ◃⊙idf\n =⊙∘\n ⊙Trunc-fmap (⊙Susp^-fmap (S n) f) ◃⊙∘\n ⊙–> (spectrumSS H-X n) ◃⊙idf\n ⊙–>-spectrumSS-natural n =\n ⊙–> (spectrumSS H-Y n) ◃⊙∘\n ⊙Ω-fmap (⊙Trunc-fmap (⊙Susp^-fmap (S (S n)) f)) ◃⊙idf\n =⊙∘⟨ 0 & 1 & ⊙–>-spectrumSS H-Y n ⟩\n FS.⊙encodeN H-Y n ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm ⟨ S (S n) ⟩ (⊙Susp^ (S (S n)) Y)) ◃⊙∘\n ⊙Ω-fmap (⊙Trunc-fmap (⊙Susp^-fmap (S (S n)) f)) ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙–>-⊙Ω-⊙Trunc-comm-natural-=⊙∘ ⟨ S (S n) ⟩ (⊙Susp^-fmap (S (S n)) f) ⟩\n FS.⊙encodeN H-Y n ◃⊙∘\n ⊙Trunc-fmap (⊙Ω-fmap (⊙Susp^-fmap (S (S n)) f)) ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm ⟨ S (S n) ⟩ (⊙Susp^ (S (S n)) X)) ◃⊙idf\n =⊙∘⟨ 0 & 2 & FreudenthalEquivNatural.⊙encodeN-natural\n ⟨ n ⟩₋₁ ⟨ S (S n) ⟩ (kle n)\n {X = ⊙Susp^ (S n) X} {Y = ⊙Susp^ (S n) Y} (⊙Susp^-fmap (S n) f)\n {{sconn H-X n}} {{sconn H-Y n}} ⟩\n ⊙Trunc-fmap (⊙Susp^-fmap (S n) f) ◃⊙∘\n FS.⊙encodeN H-X n ◃⊙∘\n ⊙–> (⊙Ω-⊙Trunc-comm ⟨ S (S n) ⟩ (⊙Susp^ (S (S n)) X)) ◃⊙idf\n =⊙∘⟨ 1 & 2 & !⊙∘ $ ⊙–>-spectrumSS H-X n ⟩\n ⊙Trunc-fmap (⊙Susp^-fmap (S n) f) ◃⊙∘\n ⊙–> (spectrumSS H-X n) ◃⊙idf ∎⊙∘\n\n abstract\n ⊙–>-spectrum-natural : ∀ (n : ℕ)\n → ⊙–> (spectrum H-Y n) ◃⊙∘\n ⊙Ω-fmap (⊙EM-fmap (S n)) ◃⊙idf\n =⊙∘\n ⊙EM-fmap n ◃⊙∘\n ⊙–> (spectrum H-X n) ◃⊙idf\n ⊙–>-spectrum-natural 0 = ⊙–>-spectrum0-natural\n ⊙–>-spectrum-natural 1 = ⊙–>-spectrum1-natural\n ⊙–>-spectrum-natural (S (S n)) = ⊙–>-spectrumSS-natural n\n\n ⊙<–-spectrum-natural : ∀ (n : ℕ)\n → ⊙<– (spectrum H-Y n) ◃⊙∘\n ⊙EM-fmap n ◃⊙idf\n =⊙∘\n ⊙Ω-fmap (⊙EM-fmap (S n)) ◃⊙∘\n ⊙<– (spectrum H-X n) ◃⊙idf\n ⊙<–-spectrum-natural n =\n ⊙<– (spectrum H-Y n) ◃⊙∘\n ⊙EM-fmap n ◃⊙idf\n =⊙∘⟨ 2 & 0 & !⊙∘ $ ⊙<–-inv-r-=⊙∘ (spectrum H-X n) ⟩\n ⊙<– (spectrum H-Y n) ◃⊙∘\n ⊙EM-fmap n ◃⊙∘\n ⊙–> (spectrum H-X n) ◃⊙∘\n ⊙<– (spectrum H-X n) ◃⊙idf\n =⊙∘⟨ 1 & 2 & !⊙∘ (⊙–>-spectrum-natural n) ⟩\n ⊙<– (spectrum H-Y n) ◃⊙∘\n ⊙–> (spectrum H-Y n) ◃⊙∘\n ⊙Ω-fmap (⊙Trunc-fmap (⊙Susp^-fmap n f)) ◃⊙∘\n ⊙<– (spectrum H-X n) ◃⊙idf\n =⊙∘⟨ 0 & 2 & ⊙<–-inv-l-=⊙∘ (spectrum H-Y n) ⟩\n ⊙Ω-fmap (⊙Trunc-fmap (⊙Susp^-fmap n f)) ◃⊙∘\n ⊙<– (spectrum H-X n) ◃⊙idf ∎⊙∘\n\nmodule EMExplicit {i} (G : AbGroup i) where\n module HSpace = EM₁HSpace G\n open EMImplicit\n {X = ⊙EM₁ (AbGroup.grp G)}\n {{EM₁-conn}}\n {{EM₁-level₁ (AbGroup.grp G)}}\n HSpace.H-⊙EM₁ public\n\n open BelowDiagonal public using (πS-below)\n\n πS-diag : (n : ℕ) → πS n (⊙EM (S n)) ≃ᴳ AbGroup.grp G\n πS-diag n = π₁-EM₁ (AbGroup.grp G) ∘eᴳ OnDiagonal.πS-diag n\n\n open AboveDiagonal public using (πS-above)\n\n abstract\n spectrum : (n : ℕ) → ⊙Ω (⊙EM (S n)) ⊙≃ ⊙EM n\n spectrum = Spectrum.spectrum\n\n spectrum-def : ∀ n → spectrum n == Spectrum.spectrum n\n spectrum-def n = idp\n", "meta": {"hexsha": "51b159ab902061b4604978eddba266fa3152e5f9", "size": 11505, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/EilenbergMacLane.agda", "max_stars_repo_name": "AntoineAllioux/HoTT-Agda", "max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/homotopy/EilenbergMacLane.agda", "max_issues_repo_name": "AntoineAllioux/HoTT-Agda", "max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/homotopy/EilenbergMacLane.agda", "max_forks_repo_name": "AntoineAllioux/HoTT-Agda", "max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 32.2268907563, "max_line_length": 89, "alphanum_fraction": 0.4579747936, "num_tokens": 6361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585903489891, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.39402831353769646}} {"text": "module Data.Num.Bijective.Properties where\n\nopen import Data.Num.Bijective\n\nopen import Data.Nat\nopen import Data.Nat.DM\nopen import Data.Nat.Properties\nopen import Data.Nat.Properties.Simple\nopen import Data.Nat.Properties.Extra\nopen import Data.Fin as Fin using (Fin)\nopen import Data.Fin.Extra\nopen import Data.Fin.Properties as FinP hiding (_≟_)\n renaming (toℕ-injective to Fin-toℕ-injective)\nopen import Data.Fin.Properties.Extra as FinPX\n renaming (cancel-suc to Fin-cancel-suc)\n\nopen import Data.Product\nopen import Function\nopen import Function.Injection hiding (_∘_)\nopen import Relation.Nullary\nopen import Relation.Nullary.Negation using (contradiction)\nopen import Relation.Binary.PropositionalEquality as PropEq\nopen ≡-Reasoning\n\n-- begin\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ∎\n\n\n------------------------------------------------------------------------\n-- Various ≡-related lemmata\n------------------------------------------------------------------------\n\n1+-never-∙ : ∀ {b} xs → 1+ {b} xs ≢ ∙\n1+-never-∙ ∙ ()\n1+-never-∙ {b} (x ∷ xs) +1xs≡∙ with full x\n1+-never-∙ (x ∷ xs) () | yes p\n1+-never-∙ (x ∷ xs) () | no ¬p\n\nfromℕ-∙-0 : ∀ {b} n → fromℕ {b} n ≡ ∙ → n ≡ 0\nfromℕ-∙-0 zero p = refl\nfromℕ-∙-0 (suc n) p = contradiction p (1+-never-∙ (fromℕ n))\n\ntoℕ-∙-0 : ∀ {b} xs → toℕ {suc b} xs ≡ 0 → xs ≡ ∙\ntoℕ-∙-0 ∙ p = refl\ntoℕ-∙-0 (x ∷ xs) ()\n\ndigit+1-never-0 : ∀ {b} (x : Fin (suc b)) → (¬p : Fin.toℕ x ≢ b) → digit+1 x ¬p ≢ Fin.zero\ndigit+1-never-0 {b} x ¬p eq with Fin.toℕ x ≟ b\ndigit+1-never-0 {b} x ¬p eq | yes q = contradiction q ¬p\ndigit+1-never-0 {zero} Fin.zero ¬p eq | no ¬q = contradiction refl ¬p\ndigit+1-never-0 {suc b} Fin.zero ¬p eq | no ¬q = contradiction eq (λ ())\ndigit+1-never-0 {zero} (Fin.suc ()) ¬p eq | no ¬q\ndigit+1-never-0 {suc b} (Fin.suc x) ¬p () | no ¬q\n\nFin⇒ℕ-digit+1 : ∀ {b}\n → (x : Fin (suc b))\n → (¬p : Fin.toℕ x ≢ b)\n → Fin.toℕ (digit+1 x ¬p) ≡ suc (Fin.toℕ x)\nFin⇒ℕ-digit+1 {b} x ¬p = toℕ-fromℕ≤ (s≤s (digit+1-lemma (Fin.toℕ x) b (bounded x) ¬p))\n\n------------------------------------------------------------------------\n-- injectivity\n------------------------------------------------------------------------\n\n∷-injective : ∀ {b}\n → {x y : Fin (suc b)}\n → {xs ys : Bij (suc b)}\n → x ∷ xs ≡ y ∷ ys\n → x ≡ y × xs ≡ ys\n∷-injective refl = refl , refl\n\ndigit+1-injective : ∀ {b} (x y : Fin (suc b))\n → (¬p : Fin.toℕ x ≢ b)\n → (¬q : Fin.toℕ y ≢ b)\n → digit+1 x ¬p ≡ digit+1 y ¬q\n → x ≡ y\ndigit+1-injective Fin.zero Fin.zero ¬p ¬q eq = refl\ndigit+1-injective {zero} Fin.zero (Fin.suc ()) ¬p ¬q eq\ndigit+1-injective {suc b} Fin.zero (Fin.suc y) ¬p ¬q eq = Fin-toℕ-injective (cancel-suc eq')\n where eq' : Fin.toℕ {suc (suc b)} (digit+1 Fin.zero ¬p) ≡ suc (Fin.toℕ {suc (suc b)} (Fin.suc y))\n eq' = begin\n Fin.toℕ {suc (suc b)} (Fin.suc Fin.zero)\n ≡⟨ cong Fin.toℕ eq ⟩\n suc (Fin.toℕ (Fin.fromℕ≤ (s≤s (digit+1-lemma (Fin.toℕ y) b (bounded y) (¬q ∘ cong suc)))))\n ≡⟨ cong suc (toℕ-fromℕ≤ (s≤s (digit+1-lemma (Fin.toℕ y) b (bounded y) (¬q ∘ cong suc)))) ⟩\n suc (Fin.toℕ {suc (suc b)} (Fin.suc y))\n ∎\ndigit+1-injective {zero} (Fin.suc ()) Fin.zero ¬p ¬q eq\ndigit+1-injective {suc b} (Fin.suc x) Fin.zero ¬p ¬q eq = Fin-toℕ-injective (cancel-suc eq')\n where eq' : suc (Fin.toℕ {suc (suc b)} (Fin.suc x)) ≡ Fin.toℕ {suc (suc b)} (digit+1 Fin.zero ¬q)\n eq' = begin\n suc (Fin.toℕ {suc (suc b)} (Fin.suc x))\n ≡⟨ cong suc (sym (toℕ-fromℕ≤ (s≤s (digit+1-lemma (Fin.toℕ x) b (bounded x) (¬p ∘ cong suc))))) ⟩\n suc (Fin.toℕ (Fin.fromℕ≤ (s≤s (digit+1-lemma (Fin.toℕ x) b (bounded x) (¬p ∘ cong suc)))))\n ≡⟨ cong Fin.toℕ eq ⟩\n Fin.toℕ {suc (suc b)} (Fin.suc Fin.zero)\n ∎\ndigit+1-injective {zero} (Fin.suc ()) (Fin.suc y) ¬p ¬q eq\ndigit+1-injective {suc b} (Fin.suc x) (Fin.suc y) ¬p ¬q eq = cong Fin.suc (digit+1-injective x y (¬p ∘ cong suc) (¬q ∘ cong suc) (Fin-cancel-suc eq))\n where open import Data.Fin.Properties.Extra\n\n1+-injective : ∀ b → (xs ys : Bij (suc b)) → 1+ xs ≡ 1+ ys → xs ≡ ys\n1+-injective b ∙ ∙ eq = refl\n1+-injective b ∙ (y ∷ ys) eq with full y\n1+-injective b ∙ (y ∷ ys) eq | yes p = contradiction (proj₂ (∷-injective (sym eq))) (1+-never-∙ ys)\n1+-injective b ∙ (y ∷ ys) eq | no ¬p = contradiction (proj₁ (∷-injective (sym eq))) (digit+1-never-0 y ¬p)\n1+-injective b (x ∷ xs) ∙ eq with full x\n1+-injective b (x ∷ xs) ∙ eq | yes p = contradiction (proj₂ (∷-injective eq)) (1+-never-∙ xs)\n1+-injective b (x ∷ xs) ∙ eq | no ¬p = contradiction (proj₁ (∷-injective eq)) (digit+1-never-0 x ¬p)\n1+-injective b (x ∷ xs) (y ∷ ys) eq with full x | full y\n1+-injective b (x ∷ xs) (y ∷ ys) eq | yes p | yes q = cong₂ _∷_ x≡y xs≡ys\n where\n x≡y : x ≡ y\n x≡y = Fin-toℕ-injective (trans p (sym q))\n xs≡ys : xs ≡ ys\n xs≡ys = 1+-injective b xs ys (proj₂ (∷-injective eq))\n1+-injective b (x ∷ xs) (y ∷ ys) eq | yes p | no ¬q = contradiction (sym (proj₁ (∷-injective eq))) (digit+1-never-0 y ¬q)\n1+-injective b (x ∷ xs) (y ∷ ys) eq | no ¬p | yes q = contradiction (proj₁ (∷-injective eq)) (digit+1-never-0 x ¬p)\n1+-injective b (x ∷ xs) (y ∷ ys) eq | no ¬p | no ¬q = cong₂ _∷_ (digit+1-injective x y ¬p ¬q (proj₁ (∷-injective eq))) (proj₂ (∷-injective eq))\n\n\ntoℕ-injective : ∀ {b} → (xs ys : Bij (suc b)) → toℕ xs ≡ toℕ ys → xs ≡ ys\ntoℕ-injective ∙ ∙ eq = refl\ntoℕ-injective ∙ (y ∷ ys) ()\ntoℕ-injective (x ∷ xs) ∙ ()\ntoℕ-injective (x ∷ xs) (y ∷ ys) eq =\n cong₂ _∷_ (proj₁ ind) (toℕ-injective xs ys (proj₂ ?))\n where\n ind : x ≡ y × toℕ xs ≡ toℕ ys\n ind = some-lemma x y (toℕ xs) (toℕ ys) (cancel-suc eq)\n\nfromℕ-injective : ∀ b m n → fromℕ {b} m ≡ fromℕ {b} n → m ≡ n\nfromℕ-injective b zero zero eq = refl\nfromℕ-injective b zero (suc n) eq = contradiction (sym eq) (1+-never-∙ (fromℕ n))\nfromℕ-injective b (suc m) zero eq = contradiction eq (1+-never-∙ (fromℕ m))\nfromℕ-injective b (suc m) (suc n) eq = cong suc (fromℕ-injective b m n (1+-injective b (fromℕ m) (fromℕ n) eq))\n\n\n--\n-- xs ─── 1+ ──➞ 1+ xs\n-- | |\n-- toℕ toℕ\n-- ↓ ↓\n-- n ─── suc ──➞ suc n\n--\ntoℕ-1+ : ∀ b xs → toℕ {suc b} (1+ xs) ≡ suc (toℕ xs)\ntoℕ-1+ b ∙ = refl\ntoℕ-1+ b (x ∷ xs) with full x\ntoℕ-1+ b (x ∷ xs) | yes p =\n begin\n toℕ (Fin.zero ∷ 1+ xs)\n ≡⟨ cong (λ w → suc (w * suc b)) (toℕ-1+ b xs) ⟩\n suc (suc (b + toℕ xs * suc b))\n ≡⟨ cong (λ w → suc (suc (w + toℕ xs * suc b))) (sym p) ⟩\n suc (toℕ (x ∷ xs))\n ∎\ntoℕ-1+ b (x ∷ xs) | no ¬p =\n cong (λ w → suc w + toℕ xs * suc b) (toℕ-fromℕ≤ (s≤s (digit+1-lemma (Fin.toℕ x) b (bounded x) ¬p)))\n\n--\n-- xs ── n+ n ──➞ n+ n xs\n-- | |\n-- toℕ toℕ\n-- ↓ ↓\n-- m ── n + ──➞ n + m\n--\n\ntoℕ-n+ : ∀ b n xs → toℕ {suc b} (n+ n xs) ≡ n + (toℕ xs)\ntoℕ-n+ b zero xs = refl\ntoℕ-n+ b (suc n) xs = begin\n toℕ (1+ (n+ n xs))\n ≡⟨ toℕ-1+ b (n+ n xs) ⟩\n suc (toℕ (n+ n xs))\n ≡⟨ cong suc (toℕ-n+ b n xs) ⟩\n suc (n + toℕ xs)\n ∎\n\n\n\ntoℕ-fromℕ : ∀ b n → toℕ {suc b} (fromℕ {b} n) ≡ n\ntoℕ-fromℕ b zero = refl\ntoℕ-fromℕ b (suc n) with fromℕ {b} n | inspect (fromℕ {b}) n\ntoℕ-fromℕ b (suc n) | ∙ | [ eq ] = cong suc (sym (fromℕ-∙-0 n eq))\ntoℕ-fromℕ b (suc n) | x ∷ xs | [ eq ] with full x\ntoℕ-fromℕ b (suc n) | x ∷ xs | [ eq ] | yes p =\n begin\n toℕ (Fin.zero ∷ 1+ xs)\n ≡⟨ refl ⟩\n suc (toℕ (1+ xs) * suc b)\n ≡⟨ cong (λ w → suc (w * suc b)) (toℕ-1+ b xs) ⟩\n suc (suc (b + toℕ xs * suc b))\n ≡⟨ cong (λ w → suc (suc (w + toℕ xs * suc b))) (sym p) ⟩\n suc (suc (Fin.toℕ x) + toℕ xs * suc b)\n ≡⟨ cong (λ w → suc (toℕ w)) (sym eq) ⟩\n suc (toℕ (fromℕ n))\n ≡⟨ cong suc (toℕ-fromℕ b n) ⟩\n suc n\n ∎\ntoℕ-fromℕ b (suc n) | x ∷ xs | [ eq ] | no ¬p =\n begin\n toℕ (digit+1 x ¬p ∷ xs)\n ≡⟨ cong (λ w → suc (w + toℕ xs * suc b)) (toℕ-fromℕ≤ (s≤s (digit+1-lemma (Fin.toℕ x) b (bounded x) ¬p))) ⟩\n suc (suc (Fin.toℕ x + toℕ xs * suc b))\n ≡⟨ cong (λ w → suc (toℕ w)) (sym eq) ⟩\n suc (toℕ (fromℕ n))\n ≡⟨ cong suc (toℕ-fromℕ b n) ⟩\n suc n\n ∎\n\nfromℕ-toℕ : ∀ {b} xs → fromℕ {b} (toℕ {suc b} xs) ≡ xs\nfromℕ-toℕ {b} xs = toℕ-injective (fromℕ (toℕ xs)) xs (toℕ-fromℕ b (toℕ xs))\n\n\ntoℕ-fromℕ-reverse : ∀ b {m} {n} → toℕ (fromℕ {b} m) ≡ n → m ≡ n\ntoℕ-fromℕ-reverse b {m} {n} eq = begin\n m\n ≡⟨ sym (toℕ-fromℕ b m) ⟩\n toℕ (fromℕ m)\n ≡⟨ eq ⟩\n n\n ∎\n\nfromℕ-toℕ-reverse : ∀ b {xs} {ys} → fromℕ {b} (toℕ {suc b} xs) ≡ ys → xs ≡ ys\nfromℕ-toℕ-reverse b {xs} {ys} eq = begin\n xs\n ≡⟨ sym (fromℕ-toℕ xs) ⟩\n fromℕ (toℕ xs)\n ≡⟨ eq ⟩\n ys\n ∎\n\n------------------------------------------------------------------------\n-- surjectivity\n------------------------------------------------------------------------\n\ntoℕ-surjective : ∀ b n → Σ[ xs ∈ Bij (suc b) ] toℕ xs ≡ n\ntoℕ-surjective b zero = ∙ , refl\ntoℕ-surjective b (suc n) = (fromℕ (suc n)) , toℕ-fromℕ b (suc n)\n\n\nfromℕ-surjective : ∀ {b} (xs : Bij (suc b)) → Σ[ n ∈ ℕ ] fromℕ n ≡ xs\nfromℕ-surjective ∙ = zero , refl\nfromℕ-surjective (x ∷ xs) = toℕ (x ∷ xs) , fromℕ-toℕ (x ∷ xs)\n\n\n------------------------------------------------------------------------\n-- _⊹_\n------------------------------------------------------------------------\n\n\ntoℕ-⊹-homo : ∀ {b} (xs ys : Bij (suc b)) → toℕ (xs ⊹ ys) ≡ toℕ xs + toℕ ys\ntoℕ-⊹-homo {b} ∙ ys = refl\ntoℕ-⊹-homo {b} (x ∷ xs) ∙ = sym (+-right-identity (suc (Fin.toℕ x + toℕ xs * suc b)))\ntoℕ-⊹-homo {b} (x ∷ xs) (y ∷ ys) with suc (Fin.toℕ x + Fin.toℕ y) divMod (suc b)\ntoℕ-⊹-homo {b} (x ∷ xs) (y ∷ ys) | result quotient remainder property div-eq mod-eq\n rewrite div-eq | mod-eq\n = begin\n suc (Fin.toℕ remainder + toℕ (n+ quotient (xs ⊹ ys)) * suc b)\n -- apply \"toℕ-n+\" to remove \"n+\"\n ≡⟨ cong (λ w → suc (Fin.toℕ remainder + w * suc b)) (toℕ-n+ b quotient (xs ⊹ ys)) ⟩\n suc (Fin.toℕ remainder + (quotient + toℕ (xs ⊹ ys)) * suc b)\n -- the induction hypothesis\n ≡⟨ cong (λ w → suc (Fin.toℕ remainder + (quotient + w) * suc b)) (toℕ-⊹-homo xs ys) ⟩\n suc (Fin.toℕ remainder + (quotient + (toℕ xs + toℕ ys)) * suc b)\n ≡⟨ cong (λ w → suc (Fin.toℕ remainder) + w) (distribʳ-*-+ (suc b) quotient (toℕ xs + toℕ ys)) ⟩\n suc (Fin.toℕ remainder + (quotient * suc b + (toℕ xs + toℕ ys) * suc b))\n ≡⟨ cong suc (sym (+-assoc (Fin.toℕ remainder) (quotient * suc b) ((toℕ xs + toℕ ys) * suc b))) ⟩\n suc (Fin.toℕ remainder + quotient * suc b + (toℕ xs + toℕ ys) * suc b)\n -- apply \"property\"\n ≡⟨ cong (λ w → suc (w + (toℕ xs + toℕ ys) * suc b)) (sym property) ⟩\n suc (suc (Fin.toℕ x + Fin.toℕ y + (toℕ xs + toℕ ys) * suc b))\n ≡⟨ cong (λ w → suc (suc (Fin.toℕ x + Fin.toℕ y + w))) (distribʳ-*-+ (suc b) (toℕ xs) (toℕ ys)) ⟩\n suc (suc (Fin.toℕ x + Fin.toℕ y + (toℕ xs * suc b + toℕ ys * suc b)))\n ≡⟨ cong (λ w → suc (suc w)) (+-assoc (Fin.toℕ x) (Fin.toℕ y) (toℕ xs * suc b + toℕ ys * suc b)) ⟩\n suc (suc (Fin.toℕ x + (Fin.toℕ y + (toℕ xs * suc b + toℕ ys * suc b))))\n ≡⟨ cong (λ w → suc (suc (Fin.toℕ x + w))) (sym (+-assoc (Fin.toℕ y) (toℕ xs * suc b) (toℕ ys * suc b))) ⟩\n suc (suc (Fin.toℕ x + (Fin.toℕ y + toℕ xs * suc b + toℕ ys * suc b)))\n ≡⟨ cong (λ w → suc (suc (Fin.toℕ x + (w + toℕ ys * suc b)))) (+-comm (Fin.toℕ y) (toℕ xs * suc b)) ⟩\n suc (suc (Fin.toℕ x + (toℕ xs * suc b + Fin.toℕ y + toℕ ys * suc b)))\n ≡⟨ cong (λ w → suc (suc (Fin.toℕ x + w))) (+-assoc (toℕ xs * suc b) (Fin.toℕ y) (toℕ ys * suc b)) ⟩\n suc (suc (Fin.toℕ x + (toℕ xs * suc b + (Fin.toℕ y + toℕ ys * suc b))))\n ≡⟨ cong (λ w → suc (suc w)) (sym (+-assoc (Fin.toℕ x) (toℕ xs * suc b) (Fin.toℕ y + toℕ ys * suc b))) ⟩\n suc (suc ((Fin.toℕ x + toℕ xs * suc b) + (Fin.toℕ y + toℕ ys * suc b)))\n ≡⟨ cong suc (sym (+-suc (Fin.toℕ x + toℕ xs * suc b) (Fin.toℕ y + toℕ ys * suc b))) ⟩\n suc (Fin.toℕ x + toℕ xs * suc b + suc (Fin.toℕ y + toℕ ys * suc b))\n ≡⟨ refl ⟩\n toℕ (x ∷ xs) + toℕ (y ∷ ys)\n ∎\n\nfromℕ-⊹-homo : ∀ {b} (m n : ℕ) → fromℕ {b} (m + n) ≡ fromℕ m ⊹ fromℕ n\nfromℕ-⊹-homo {b} m n = toℕ-injective (fromℕ (m + n)) (fromℕ m ⊹ fromℕ n) $\n begin\n toℕ (fromℕ (m + n))\n ≡⟨ toℕ-fromℕ b (m + n) ⟩\n m + n\n ≡⟨ sym (cong₂ _+_ (toℕ-fromℕ b m) (toℕ-fromℕ b n)) ⟩\n toℕ (fromℕ m) + toℕ (fromℕ n)\n ≡⟨ sym (toℕ-⊹-homo (fromℕ m) (fromℕ n)) ⟩\n toℕ (fromℕ m ⊹ fromℕ n)\n ∎\n\n⊹-1+ : ∀ {b} (xs ys : Bij (suc b)) → (1+ xs) ⊹ ys ≡ 1+ (xs ⊹ ys)\n⊹-1+ {b} xs ys = toℕ-injective (1+ xs ⊹ ys) (1+ (xs ⊹ ys)) $\n begin\n toℕ (1+ xs ⊹ ys)\n ≡⟨ toℕ-⊹-homo (1+ xs) ys ⟩\n toℕ (1+ xs) + toℕ ys\n ≡⟨ cong (λ w → w + toℕ ys) (toℕ-1+ b xs) ⟩\n suc (toℕ xs + toℕ ys)\n ≡⟨ cong suc (sym (toℕ-⊹-homo xs ys)) ⟩\n suc (toℕ (xs ⊹ ys))\n ≡⟨ sym (toℕ-1+ b (xs ⊹ ys)) ⟩\n toℕ (1+ (xs ⊹ ys))\n ∎\n\n⊹-assoc : ∀ {b} (xs ys zs : Bij (suc b)) → (xs ⊹ ys) ⊹ zs ≡ xs ⊹ (ys ⊹ zs)\n⊹-assoc xs ys zs = toℕ-injective (xs ⊹ ys ⊹ zs) (xs ⊹ (ys ⊹ zs)) $\n begin\n toℕ (xs ⊹ ys ⊹ zs)\n ≡⟨ toℕ-⊹-homo (xs ⊹ ys) zs ⟩\n toℕ (xs ⊹ ys) + toℕ zs\n ≡⟨ cong (λ w → w + toℕ zs) (toℕ-⊹-homo xs ys) ⟩\n toℕ xs + toℕ ys + toℕ zs\n ≡⟨ +-assoc (toℕ xs) (toℕ ys) (toℕ zs) ⟩\n toℕ xs + (toℕ ys + toℕ zs)\n ≡⟨ cong (λ w → toℕ xs + w) (sym (toℕ-⊹-homo ys zs)) ⟩\n toℕ xs + toℕ (ys ⊹ zs)\n ≡⟨ sym (toℕ-⊹-homo xs (ys ⊹ zs)) ⟩\n toℕ (xs ⊹ (ys ⊹ zs))\n ∎\n\n⊹-comm : ∀ {b} (xs ys : Bij (suc b)) → xs ⊹ ys ≡ ys ⊹ xs\n⊹-comm xs ys = toℕ-injective (xs ⊹ ys) (ys ⊹ xs) $\n begin\n toℕ (xs ⊹ ys)\n ≡⟨ toℕ-⊹-homo xs ys ⟩\n toℕ xs + toℕ ys\n ≡⟨ +-comm (toℕ xs) (toℕ ys) ⟩\n toℕ ys + toℕ xs\n ≡⟨ sym (toℕ-⊹-homo ys xs) ⟩\n toℕ (ys ⊹ xs)\n ∎\n\n\n\nincrease-base-lemma : ∀ b\n → (xs : Bij (suc b))\n → toℕ (increase-base xs) ≡ toℕ xs\nincrease-base-lemma b ∙ = refl\nincrease-base-lemma b (x ∷ xs) with fromℕ {suc b} (toℕ (increase-base xs) * suc b) | inspect (λ ws → fromℕ {suc b} (toℕ ws * suc b)) (increase-base xs)\nincrease-base-lemma b (x ∷ xs) | ∙ | [ eq ] = cong suc $\n begin\n Fin.toℕ (Fin.inject₁ x) + 0\n ≡⟨ cong (λ w → w + 0) (FinP.inject₁-lemma x) ⟩\n Fin.toℕ x + 0\n ≡⟨ cong (λ w → Fin.toℕ x + w) $\n begin\n zero\n ≡⟨ cong toℕ (sym eq) ⟩\n toℕ (fromℕ (toℕ (increase-base xs) * suc b))\n ≡⟨ toℕ-fromℕ (suc b) (toℕ (increase-base xs) * suc b) ⟩\n toℕ (increase-base xs) * suc b\n ∎ ⟩\n Fin.toℕ x + toℕ (increase-base xs) * suc b\n ≡⟨ cong (λ w → Fin.toℕ x + w * suc b) (increase-base-lemma b xs) ⟩\n Fin.toℕ x + toℕ xs * suc b\n ∎\nincrease-base-lemma b (x ∷ xs) | y ∷ ys | [ eq ] with (suc (Fin.toℕ x + Fin.toℕ y)) divMod (suc (suc b))\nincrease-base-lemma b (x ∷ xs) | y ∷ ys | [ eq ] | result quotient remainder property div-eq mod-eq\n rewrite div-eq | mod-eq\n = cong suc $ begin\n Fin.toℕ remainder + toℕ (n+ quotient ys) * suc (suc b)\n ≡⟨ cong (λ w → Fin.toℕ remainder + w * suc (suc b)) (toℕ-n+ (suc b) quotient ys) ⟩\n Fin.toℕ remainder + (quotient + toℕ ys) * suc (suc b)\n ≡⟨ cong (λ w → Fin.toℕ remainder + w) (distribʳ-*-+ (suc (suc b)) quotient (toℕ ys)) ⟩\n Fin.toℕ remainder + (quotient * suc (suc b) + toℕ ys * suc (suc b))\n ≡⟨ sym (+-assoc (Fin.toℕ remainder) (quotient * suc (suc b)) (toℕ ys * suc (suc b))) ⟩\n Fin.toℕ remainder + quotient * suc (suc b) + toℕ ys * suc (suc b)\n ≡⟨ cong (λ w → w + toℕ ys * suc (suc b)) (sym property) ⟩\n suc (Fin.toℕ x + Fin.toℕ y + toℕ ys * suc (suc b))\n ≡⟨ cong suc (+-assoc (Fin.toℕ x) (Fin.toℕ y) (toℕ ys * suc (suc b))) ⟩\n suc (Fin.toℕ x + (Fin.toℕ y + toℕ ys * suc (suc b)))\n ≡⟨ sym (+-suc (Fin.toℕ x) (Fin.toℕ y + toℕ ys * suc (suc b))) ⟩\n Fin.toℕ x + suc (Fin.toℕ y + toℕ ys * suc (suc b))\n ≡⟨ cong (λ w → Fin.toℕ x + toℕ w) (sym eq) ⟩\n Fin.toℕ x + toℕ (fromℕ (toℕ (increase-base xs) * suc b))\n ≡⟨ cong (λ w → Fin.toℕ x + w) (toℕ-fromℕ (suc b) (toℕ (increase-base xs) * suc b)) ⟩\n Fin.toℕ x + toℕ (increase-base xs) * suc b\n ≡⟨ cong (λ w → Fin.toℕ x + w * suc b) (increase-base-lemma b xs) ⟩\n Fin.toℕ x + toℕ xs * suc b\n ∎\n\ndecrease-base-lemma : ∀ b → (xs : Bij (suc (suc b))) → toℕ (decrease-base xs) ≡ toℕ xs\ndecrease-base-lemma b ∙ = refl\ndecrease-base-lemma b (x ∷ xs) with fromℕ {b} (toℕ (decrease-base xs) * suc (suc b))\n | inspect (λ ws → fromℕ {b} (toℕ ws * suc (suc b))) (decrease-base xs)\ndecrease-base-lemma b (x ∷ xs) | ∙ | [ eq ] with full x\ndecrease-base-lemma b (x ∷ xs) | ∙ | [ eq ] | yes p = cong suc $\n begin\n suc (b + 0)\n ≡⟨ cong (λ w → w + 0) (sym p)⟩\n Fin.toℕ x + zero\n ≡⟨ cong (λ w → Fin.toℕ x + w) $\n begin\n zero\n ≡⟨ cong toℕ (sym eq) ⟩\n toℕ (fromℕ (toℕ (decrease-base xs) * suc (suc b)))\n ≡⟨ toℕ-fromℕ b (toℕ (decrease-base xs) * suc (suc b)) ⟩\n toℕ (decrease-base xs) * suc (suc b)\n ∎ ⟩\n Fin.toℕ x + toℕ (decrease-base xs) * suc (suc b)\n ≡⟨ cong (λ w → Fin.toℕ x + w * suc (suc b)) (decrease-base-lemma b xs) ⟩\n Fin.toℕ x + toℕ xs * suc (suc b)\n ∎\ndecrease-base-lemma b (x ∷ xs) | ∙ | [ eq ] | no ¬p = cong suc $\n begin\n Fin.toℕ (inject-1 x ¬p) + 0\n ≡⟨ cong (λ w → w + 0) (inject-1-lemma x ¬p) ⟩\n Fin.toℕ x + 0\n ≡⟨ cong (λ w → Fin.toℕ x + w) $\n begin\n zero\n ≡⟨ cong toℕ (sym eq) ⟩\n toℕ (fromℕ (toℕ (decrease-base xs) * suc (suc b)))\n ≡⟨ toℕ-fromℕ b (toℕ (decrease-base xs) * suc (suc b)) ⟩\n toℕ (decrease-base xs) * suc (suc b)\n ∎ ⟩\n Fin.toℕ x + toℕ (decrease-base xs) * suc (suc b)\n ≡⟨ cong (λ w → Fin.toℕ x + w * suc (suc b)) (decrease-base-lemma b xs) ⟩\n Fin.toℕ x + toℕ xs * suc (suc b)\n ∎\ndecrease-base-lemma b (x ∷ xs) | y ∷ ys | [ eq ] with (suc (Fin.toℕ x + Fin.toℕ y)) divMod (suc b)\ndecrease-base-lemma b (x ∷ xs) | y ∷ ys | [ eq ] | result quotient remainder property div-eq mod-eq\n rewrite div-eq | mod-eq = cong suc $ begin\n Fin.toℕ remainder + toℕ (n+ quotient ys) * suc b\n ≡⟨ cong (λ w → Fin.toℕ remainder + w * suc b) (toℕ-n+ b quotient ys) ⟩\n Fin.toℕ remainder + (quotient + toℕ ys) * suc b\n ≡⟨ cong (λ w → Fin.toℕ remainder + w) (distribʳ-*-+ (suc b) quotient (toℕ ys)) ⟩\n Fin.toℕ remainder + (quotient * suc b + toℕ ys * suc b)\n ≡⟨ sym (+-assoc (Fin.toℕ remainder) (quotient * suc b) (toℕ ys * suc b)) ⟩\n Fin.toℕ remainder + quotient * suc b + toℕ ys * suc b\n ≡⟨ cong (λ w → w + toℕ ys * suc b) (sym property) ⟩\n suc (Fin.toℕ x + Fin.toℕ y + toℕ ys * suc b)\n ≡⟨ cong suc (+-assoc (Fin.toℕ x) (Fin.toℕ y) (toℕ ys * suc b)) ⟩\n suc (Fin.toℕ x + (Fin.toℕ y + toℕ ys * suc b))\n ≡⟨ sym (+-suc (Fin.toℕ x) (Fin.toℕ y + toℕ ys * suc b)) ⟩\n Fin.toℕ x + suc (Fin.toℕ y + toℕ ys * suc b)\n ≡⟨ cong (λ w → Fin.toℕ x + toℕ w) (sym eq) ⟩\n Fin.toℕ x + toℕ (fromℕ (toℕ (decrease-base xs) * suc (suc b)))\n ≡⟨ cong (λ w → Fin.toℕ x + w) (toℕ-fromℕ b (toℕ (decrease-base xs) * suc (suc b))) ⟩\n Fin.toℕ x + toℕ (decrease-base xs) * suc (suc b)\n ≡⟨ cong (λ w → Fin.toℕ x + w * suc (suc b)) (decrease-base-lemma b xs) ⟩\n Fin.toℕ x + toℕ xs * suc (suc b)\n ∎\n\n -- begin\n -- {! !}\n -- ≡⟨ {! !} ⟩\n -- {! !}\n -- ≡⟨ {! !} ⟩\n -- {! !}\n -- ≡⟨ {! !} ⟩\n -- {! !}\n -- ≡⟨ {! !} ⟩\n -- {! !}\n -- ∎\n", "meta": {"hexsha": "0a4af4e4dc7f105e318a9979062e5c0cdc3c39b1", "size": 20370, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Data/Num/Bijective/Properties.agda", "max_stars_repo_name": "banacorn/numeral", "max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z", "max_issues_repo_path": "Data/Num/Bijective/Properties.agda", "max_issues_repo_name": "banacorn/numeral", "max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "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": "Data/Num/Bijective/Properties.agda", "max_forks_repo_name": "banacorn/numeral", "max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z", "max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z", "avg_line_length": 42.7941176471, "max_line_length": 151, "alphanum_fraction": 0.4724594993, "num_tokens": 8838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.538983220687684, "lm_q1q2_score": 0.3940283072213605}} {"text": "module Measure where\n\nimport Data.Nat as ℕ\nimport Data.Nat.Coprimality as Coprimality\nimport Data.Nat.GCD as GCD\nimport Data.Nat.Show as ℕshow\nimport Data.Nat.Divisibility as Divisibility\n\nopen ℕ using (ℕ; suc; zero)\nopen Coprimality using (Coprime)\nopen Divisibility using (divides)\n\nopen import Relation.Nullary.Decidable using (True; False; toWitness; fromWitness)\nopen import Data.Product using (_,_; ∃; proj₁; proj₂)\nopen import Data.String as String using (String)\nopen import Relation.Binary.PropositionalEquality as ≡ using (_≡_; _≢_; cong; sym; refl)\n\nopen import Data.Empty as ⊥ using (⊥)\n\nrecord ℙ : Set where\n field\n numerator : ℕ\n denominator-1 : ℕ\n .coprime : Coprime numerator (suc denominator-1)\n\n denominator : ℕ\n denominator = suc denominator-1\nopen ℙ\n\ninfixl 7 _÷₌_\n_÷₌_ : (n : ℕ) → (d : ℕ) → .{coprime : Coprime n d} → .{≢0 : False (d ℕ.≟ 0)} → ∃ (λ p → denominator p ≡ d)\nnumerator (proj₁ (n ÷₌ _)) = n\ndenominator-1 (proj₁ ((_ ÷₌ zero) {≢0 = ()}))\ndenominator-1 (proj₁ (_ ÷₌ suc d)) = d\ncoprime (proj₁ ((_ ÷₌ zero) {≢0 = ()}))\ncoprime (proj₁ ((_ ÷₌ suc d) {coprime})) = coprime\nproj₂ ((n ÷₌ zero) {≢0 = ()})\nproj₂ (n ÷₌ suc d) = refl\n\ninfixl 7 _÷_\n_÷_ : (n d : ℕ) → .{coprime : Coprime n d} → .{≢0 : False (d ℕ.≟ 0)} → ℙ\nnumerator (n ÷ d) = n\ndenominator-1 ((n ÷ zero) {≢0 = ()})\ndenominator-1 (n ÷ suc d-1) = d-1\ncoprime ((n ÷ zero) {≢0 = ()})\ncoprime ((n ÷ suc d-1) {coprime}) = coprime\n\nfromNat : ℕ → ℙ\nnumerator (fromNat n) = n\ndenominator-1 (fromNat _) = 0\ncoprime (fromNat n) = Coprimality.sym (Coprimality.1-coprimeTo n)\n\nprivate 1+≢*0 : ∀ x y → suc x ≢ y ℕ.* 0\n 1+≢*0 x zero ()\n 1+≢*0 x (suc y) = 1+≢*0 x y\n\ninfixl 7 _?÷₌_\n_?÷₌_ : ∀ x y → .{≢0 : False (y ℕ.≟ 0)} → ∃ (λ p → x ℕ.* denominator p ≡ numerator p ℕ.* y)\n_?÷₌_ x zero {≢0 = ()}\n_?÷₌_ x (suc y-1) with GCD.Bézout.lemma x (suc y-1)\n_?÷₌_ x (suc y-1) | GCD.Bézout.result 0 (GCD.GCD.is (_ , divides y′ y-eq) _) _ = ⊥.⊥-elim (1+≢*0 y-1 y′ y-eq)\n_?÷₌_ x (suc y-1) | GCD.Bézout.result (suc d-1) (GCD.GCD.is (divides x′ x-eq , divides y′ y-eq) _) bézout = proj₁ frac , eq-prf\n where\n open import Data.Nat using (_*_)\n\n y = suc y-1\n d = suc d-1\n\n bézout′ : GCD.Bézout.Identity d (x′ * d) (y′ * d)\n bézout′ = ≡.subst₂ (GCD.Bézout.Identity d) x-eq y-eq bézout\n\n\n coprime-prf : Coprime x′ y′\n coprime-prf = Coprimality.Bézout-coprime bézout′\n\n open ≡.≡-Reasoning\n open import Data.Nat.Properties.Simple\n\n y′≢0 : False (y′ ℕ.≟ 0)\n y′≢0 = Relation.Nullary.Decidable.fromWitnessFalse wtns\n where\n suc-≢0 : {n : ℕ} → (suc n ≡ 0) → ⊥\n suc-≢0 {n} ()\n\n open import Relation.Nullary using (¬_)\n wtns : ¬ (y′ ≡ 0)\n wtns refl = suc-≢0 {y-1} y-eq\n\n frac : ∃ (λ p → denominator p ≡ y′)\n frac = (x′ ÷₌ y′) {coprime = coprime-prf} {≢0 = y′≢0}\n\n eq-prf : x * denominator (proj₁ frac) ≡ numerator (proj₁ frac) * suc y-1\n eq-prf = begin\n x * denominator (proj₁ frac) ≡⟨ cong (λ z → x * z) (proj₂ frac) ⟩\n x * y′ ≡⟨ cong (λ z → z * y′) x-eq ⟩\n x′ * d * y′ ≡⟨ *-assoc x′ d y′ ⟩\n x′ * (d * y′) ≡⟨ sym (cong (_*_ x′) (*-comm y′ d)) ⟩\n x′ * (y′ * d) ≡⟨ sym (cong (_*_ x′) y-eq) ⟩\n x′ * y ∎\n\ninfixl 7 _?÷_\n_?÷_ : (x y : ℕ) → .{≢0 : False (y ℕ.≟ 0)} → ℙ\n(x ?÷ zero) {≢0 = ()}\nx ?÷ suc y-1 with GCD.Bézout.lemma x (suc y-1)\n(n ?÷ suc y-1) | GCD.Bézout.result 0 (GCD.GCD.is (_ , divides y′ y-eq) _) _ = ⊥.⊥-elim (1+≢*0 y-1 y′ y-eq)\n(n ?÷ suc y-1) | GCD.Bézout.result (suc d-1) (GCD.GCD.is (divides x′ x-eq , divides y′ y-eq) _) bézout = (x′ ÷ y′) {coprime = coprime-prf} {≢0 = y′≢0}\n where\n open import Data.Nat using (_*_)\n\n y = suc y-1\n d = suc d-1\n\n bézout′ : GCD.Bézout.Identity d (x′ * d) (y′ * d)\n bézout′ = ≡.subst₂ (GCD.Bézout.Identity d) x-eq y-eq bézout\n\n coprime-prf : Coprime x′ y′\n coprime-prf = Coprimality.Bézout-coprime bézout′\n\n y′≢0 : False (y′ ℕ.≟ 0)\n y′≢0 = Relation.Nullary.Decidable.fromWitnessFalse wtns\n where\n suc-≢0 : {n : ℕ} → (suc n ≡ 0) → ⊥\n suc-≢0 {n} ()\n\n open import Relation.Nullary using (¬_)\n wtns : ¬ (y′ ≡ 0)\n wtns refl = suc-≢0 {y-1} y-eq\n\n_+_ : ℙ → ℙ → ℙ\nx + y = ((numerator x ℕ.* denominator y) ℕ.+ (numerator y ℕ.* denominator x)) ?÷ (denominator x ℕ.* denominator y)\n\n_*_ : ℙ → ℙ → ℙ\nx * y = (numerator x ℕ.* numerator y) ?÷ (denominator x ℕ.* denominator y)\n\nshow : ℙ → String\nshow p = ℕshow (numerator p) ++ \"÷\" ++ ℕshow (denominator p)\n where\n open String using (_++_)\n open import Data.Nat.Show renaming (show to ℕshow)\n", "meta": {"hexsha": "8e11da2db0409cde0ff3d2b3efc5394ce40c6417", "size": 4594, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "probability/Measure.agda", "max_stars_repo_name": "oisdk/prob-presentation", "max_stars_repo_head_hexsha": "880217ca51ab62f6feee58ccacdb39bfade43101", "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": "probability/Measure.agda", "max_issues_repo_name": "oisdk/prob-presentation", "max_issues_repo_head_hexsha": "880217ca51ab62f6feee58ccacdb39bfade43101", "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": "probability/Measure.agda", "max_forks_repo_name": "oisdk/prob-presentation", "max_forks_repo_head_hexsha": "880217ca51ab62f6feee58ccacdb39bfade43101", "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": 32.8142857143, "max_line_length": 150, "alphanum_fraction": 0.5589899869, "num_tokens": 2041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3939655978214473}} {"text": "{-# OPTIONS --allow-unsolved-metas #-} \n\nmodule finiteSetUtil where\n\nopen import Data.Nat hiding ( _≟_ )\nopen import Data.Fin renaming ( _<_ to _<<_ ; _>_ to _f>_ ; _≟_ to _f≟_ ) hiding (_≤_ )\nopen import Data.Fin.Properties hiding ( <-trans ) renaming ( <-cmp to <-fcmp )\nopen import Data.Empty\nopen import Relation.Nullary\nopen import Relation.Binary.Definitions\nopen import Relation.Binary.PropositionalEquality\nopen import logic\nopen import nat\nopen import finiteSet\nopen import fin\nopen import Data.Nat.Properties as NatP hiding ( _≟_ )\nopen import Relation.Binary.HeterogeneousEquality as HE using (_≅_ ) \n\nrecord Found ( Q : Set ) (p : Q → Bool ) : Set where\n field\n found-q : Q\n found-p : p found-q ≡ true\n\nopen Bijection\n\nopen import Axiom.Extensionality.Propositional\nopen import Level hiding (suc ; zero)\npostulate f-extensionality : { n : Level} → Axiom.Extensionality.Propositional.Extensionality n n -- (Level.suc n)\n\nmodule _ {Q : Set } (F : FiniteSet Q) where\n open FiniteSet F\n equal?-refl : { x : Q } → equal? x x ≡ true \n equal?-refl {x} with F←Q x ≟ F←Q x\n ... | yes refl = refl\n ... | no ne = ⊥-elim (ne refl)\n equal→refl : { x y : Q } → equal? x y ≡ true → x ≡ y\n equal→refl {q0} {q1} eq with F←Q q0 ≟ F←Q q1\n equal→refl {q0} {q1} refl | yes eq = begin\n q0\n ≡⟨ sym ( finiso→ q0) ⟩\n Q←F (F←Q q0)\n ≡⟨ cong (λ k → Q←F k ) eq ⟩\n Q←F (F←Q q1)\n ≡⟨ finiso→ q1 ⟩\n q1\n ∎ where open ≡-Reasoning\n eqP : (x y : Q) → Dec ( x ≡ y )\n eqP x y with F←Q x ≟ F←Q y\n ... | yes eq = yes (subst₂ (λ j k → j ≡ k ) (finiso→ x) (finiso→ y) (cong Q←F eq) )\n ... | no n = no (λ eq → n (cong F←Q eq))\n End : (m : ℕ ) → (p : Q → Bool ) → Set\n End m p = (i : Fin finite) → m ≤ toℕ i → p (Q←F i ) ≡ false \n first-end : ( p : Q → Bool ) → End finite p\n first-end p i i>n = ⊥-elim (nat-≤> i>n (fin ¬a ¬b c = ⊥-elim ( nat-≤> m ¬a ¬b c = i-phase2 qs p\n i-phase1 : (qs : List Q) → fin-phase1 (F←Q finq q) (map (F←Q finq) qs) ≡ true \n → phase1 finq q qs ≡ true \n i-phase1 (x ∷ qs) p with equal? finq q x | inspect (equal? finq q ) x | <-fcmp (F←Q finq q) (F←Q finq x)\n ... | true | record { eq = eq } | tri< a ¬b ¬c = ⊥-elim ( nat-≡< (cong (λ x → toℕ (F←Q finq x)) ( equal→refl finq eq )) a )\n ... | true | _ | tri≈ ¬a b ¬c = i-phase2 qs p\n ... | true | record { eq = eq} | tri> ¬a ¬b c = ⊥-elim ( nat-≡< (cong (λ x → toℕ (F←Q finq x)) (sym ( equal→refl finq eq ))) c )\n ... | false | _ | tri< a ¬b ¬c = i-phase1 qs p\n ... | false | record {eq = eq} | tri≈ ¬a b ¬c = ⊥-elim (¬-bool eq\n (subst₂ (λ j k → equal? finq j k ≡ true) (finiso→ finq q) (subst (λ k → Q←F finq k ≡ x) (sym b) (finiso→ finq x)) ( equal?-refl finq )))\n ... | false | _ | tri> ¬a ¬b c = i-phase1 qs p\n\nrecord Dup-in-list {Q : Set } (finq : FiniteSet Q) (qs : List Q) : Set where\n field\n dup : Q\n is-dup : dup-in-list finq dup qs ≡ true\n\ndup-in-list>n : {Q : Set } → (finq : FiniteSet Q) → (qs : List Q) → (len> : length qs > finite finq ) → Dup-in-list finq qs\ndup-in-list>n {Q} finq qs lt = record { dup = Q←F finq (FDup-in-list.dup dl)\n ; is-dup = dup-in-list+fin finq (Q←F finq (FDup-in-list.dup dl)) qs dl01 } where\n maplen : (qs : List Q) → length (map (F←Q finq) qs) ≡ length qs\n maplen [] = refl\n maplen (x ∷ qs) = cong suc (maplen qs)\n dl : FDup-in-list (finite finq ) (map (F←Q finq) qs)\n dl = fin-dup-in-list>n (map (F←Q finq) qs) (subst (λ k → k > finite finq ) (sym (maplen qs)) lt)\n dl01 : fin-dup-in-list (F←Q finq (Q←F finq (FDup-in-list.dup dl))) (map (F←Q finq) qs) ≡ true\n dl01 = subst (λ k → fin-dup-in-list k (map (F←Q finq) qs) ≡ true )\n (sym (finiso← finq _)) ( FDup-in-list.is-dup dl )\n", "meta": {"hexsha": "ccf51ffdad96f2ff78bcd841fcd0c2bf12b0ddd1", "size": 27298, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/finiteSetUtil.agda", "max_stars_repo_name": "shinji-kono/automaton-in-agda", "max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "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/finiteSetUtil.agda", "max_issues_repo_name": "shinji-kono/automaton-in-agda", "max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "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/finiteSetUtil.agda", "max_forks_repo_name": "shinji-kono/automaton-in-agda", "max_forks_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "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.4007092199, "max_line_length": 159, "alphanum_fraction": 0.5169243168, "num_tokens": 11571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583376458152, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.3939253188317981}} {"text": "\n\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.Equality\n\nrecord R : Set where\n field\n r1 r2 : Nat\n\ntest : (x : R) → R.r1 x ≡ 0 → Nat\ntest x refl = 0\n", "meta": {"hexsha": "97d69cf4ac80283cb3e3a057ad523e195ea7b280", "size": 162, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/PartiallyInstantiatedVariable.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/PartiallyInstantiatedVariable.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/PartiallyInstantiatedVariable.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 13.5, "max_line_length": 33, "alphanum_fraction": 0.6419753086, "num_tokens": 62, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6959583124210897, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.39392530455413594}} {"text": "------------------------------------------------------------------------\n-- INCREMENTAL λ-CALCULUS\n--\n-- Change evaluation (Def 3.6 and Fig. 4h).\n------------------------------------------------------------------------\n\nimport Parametric.Syntax.Type as Type\nimport Parametric.Syntax.Term as Term\nimport Parametric.Denotation.Value as Value\nimport Parametric.Denotation.Evaluation as Evaluation\nimport Parametric.Change.Validity as Validity\n\nmodule Parametric.Change.Specification\n {Base : Type.Structure}\n (Const : Term.Structure Base)\n (⟦_⟧Base : Value.Structure Base)\n (⟦_⟧Const : Evaluation.Structure Const ⟦_⟧Base)\n {{validity-structure : Validity.Structure ⟦_⟧Base}}\n where\n\nopen Type.Structure Base\nopen Term.Structure Base Const\nopen Value.Structure Base ⟦_⟧Base\nopen Evaluation.Structure Const ⟦_⟧Base ⟦_⟧Const\nopen Validity.Structure ⟦_⟧Base {{validity-structure}}\n\nopen import Base.Denotation.Notation\nopen import Relation.Binary.PropositionalEquality\nopen import Theorem.CongApp\nopen import Postulate.Extensionality\n\nmodule Structure where\n ---------------\n -- Interface --\n ---------------\n\n -- We provide: Derivatives of terms.\n ⟦_⟧Δ : ∀ {τ Γ} → (t : Term Γ τ) (ρ : ⟦ Γ ⟧) (dρ : Δ₍ Γ ₎ ρ) → Δ₍ τ ₎ (⟦ t ⟧ ρ)\n\n -- And we provide correctness proofs about the derivatives.\n correctness : ∀ {τ Γ} (t : Term Γ τ) →\n IsDerivative₍ Γ , τ ₎ ⟦ t ⟧ ⟦ t ⟧Δ\n\n --------------------\n -- Implementation --\n --------------------\n open import Base.Change.Equivalence\n open import Base.Change.Equivalence.Realizers\n\n module _ {σ τ : Type} {Γ : Context} (t : Term (σ • Γ) τ) where\n instance\n cΓ : ChangeAlgebra ⟦ Γ ⟧Context\n cΓ = change-algebra₍ Γ ₎\n cσ : ChangeAlgebra ⟦ σ ⟧Type\n cσ = change-algebra σ\n cτ : ChangeAlgebra ⟦ τ ⟧Type\n cτ = change-algebra τ\n\n private\n ⟦⟧Δλ = nil {{changeAlgebraFun {{cΓ}} {{change-algebra₍ σ ⇒ τ ₎}}}} ⟦ abs t ⟧\n\n ⟦⟧Δλ-realizer : ∀\n (ρ : ⟦ Γ ⟧) (dρ : Δ₍ Γ ₎ ρ)\n (v : ⟦ σ ⟧) (dv : Δ₍ σ ₎ v) →\n Δ₍ τ ₎ (⟦ t ⟧ (v • ρ))\n ⟦⟧Δλ-realizer ρ dρ v dv = ⟦ t ⟧Δ (v • ρ) (dv • dρ)\n\n ⟦⟧Δλ-realizer-correct :\n equiv-hp-binary {{cΓ}} {{cσ}} {{cτ}} (⟦ abs t ⟧) ⟦⟧Δλ ⟦⟧Δλ-realizer\n ⟦⟧Δλ-realizer-correct ρ dρ v dv =\n begin\n ⟦ t ⟧ (v ⊞₍ σ ₎ dv • ρ ⊞₍ Γ ₎ dρ) ⊟₍ τ ₎ ⟦ t ⟧ (v • ρ)\n ≙⟨ equiv-cancel-2 {{change-algebra τ}}\n (⟦ t ⟧ (v ⊞₍ σ ₎ dv • ρ ⊞₍ Γ ₎ dρ))\n (⟦ t ⟧Δ (v • ρ) (dv • dρ))\n (sym (correctness t (v • ρ) (dv • dρ)))\n ⟩\n ⟦ t ⟧Δ (v • ρ) (dv • dρ)\n ∎ where open ≙-Reasoning\n\n ⟦_⟧Δλ′-faster = proj₁ (equiv-raw-change-to-change-binary {{cΓ}} {{cσ}} {{cτ}} ⟦ abs t ⟧ ⟦⟧Δλ ⟦⟧Δλ-realizer ⟦⟧Δλ-realizer-correct)\n where\n open import Data.Product\n\n ⟦_⟧ΔVar : ∀ {τ Γ} → (x : Var Γ τ) → (ρ : ⟦ Γ ⟧) → Δ₍ Γ ₎ ρ → Δ₍ τ ₎ (⟦ x ⟧Var ρ)\n ⟦ this ⟧ΔVar (v • ρ) (dv • dρ) = dv\n ⟦ that x ⟧ΔVar (v • ρ) (dv • dρ) = ⟦ x ⟧ΔVar ρ dρ\n\n ⟦_⟧Δ (const {τ} c) ρ dρ = nil₍ τ ₎ (⟦ c ⟧Const)\n ⟦_⟧Δ (var x) ρ dρ = ⟦ x ⟧ΔVar ρ dρ\n ⟦_⟧Δ (app {σ} {τ} s t) ρ dρ =\n call-change {σ} {τ} (⟦ s ⟧Δ ρ dρ) (⟦ t ⟧ ρ) (⟦ t ⟧Δ ρ dρ)\n ⟦_⟧Δ (abs {σ} {τ} t) ρ dρ = apply ⟦ t ⟧Δλ′-faster ρ dρ\n\n correctVar : ∀ {τ Γ} (x : Var Γ τ) →\n IsDerivative₍ Γ , τ ₎ ⟦ x ⟧ ⟦ x ⟧ΔVar\n correctVar (this) (v • ρ) (dv • dρ) = refl\n correctVar (that y) (v • ρ) (dv • dρ) = correctVar y ρ dρ\n\n correctness (const {τ} c) ρ dρ = update-nil₍ τ ₎ ⟦ c ⟧Const\n correctness {τ} (var x) ρ dρ = correctVar {τ} x ρ dρ\n correctness (app {σ} {τ} s t) ρ dρ =\n let\n f₁ = ⟦ s ⟧ ρ\n f₂ = ⟦ s ⟧ (after-env dρ)\n Δf = ⟦ s ⟧Δ ρ dρ\n u₁ = ⟦ t ⟧ ρ\n u₂ = ⟦ t ⟧ (after-env dρ)\n Δu = ⟦ t ⟧Δ ρ dρ\n in\n begin\n f₁ u₁ ⊞₍ τ ₎ call-change {σ} {τ} Δf u₁ Δu\n ≡⟨ sym (is-valid {σ} {τ} Δf u₁ Δu) ⟩\n (f₁ ⊞₍ σ ⇒ τ ₎ Δf) (u₁ ⊞₍ σ ₎ Δu)\n ≡⟨ correctness {σ ⇒ τ} s ρ dρ ⟨$⟩ correctness {σ} t ρ dρ ⟩\n f₂ u₂\n ∎ where open ≡-Reasoning\n correctness {σ ⇒ τ} {Γ} (abs t) ρ dρ = equiv-raw-deriv-to-deriv-binary {{change-algebra₍ Γ ₎}} {{change-algebra σ}} ⟦ abs t ⟧Term (⟦⟧Δλ-realizer t) (⟦⟧Δλ-realizer-correct t) ρ dρ\n\n -- Corollary: (f ⊞ df) (v ⊞ dv) = f v ⊞ df v dv\n\n corollary : ∀ {σ τ Γ}\n (s : Term Γ (σ ⇒ τ)) (t : Term Γ σ) (ρ : ⟦ Γ ⟧) (dρ : Δ₍ Γ ₎ ρ) →\n (⟦ s ⟧ ρ ⊞₍ σ ⇒ τ ₎ ⟦ s ⟧Δ ρ dρ)\n (⟦ t ⟧ ρ ⊞₍ σ ₎ ⟦ t ⟧Δ ρ dρ)\n ≡ (⟦ s ⟧ ρ) (⟦ t ⟧ ρ)\n ⊞₍ τ ₎\n (call-change {σ} {τ} (⟦ s ⟧Δ ρ dρ)) (⟦ t ⟧ ρ) (⟦ t ⟧Δ ρ dρ)\n\n corollary {σ} {τ} s t ρ dρ =\n is-valid {σ} {τ} (⟦ s ⟧Δ ρ dρ) (⟦ t ⟧ ρ) (⟦ t ⟧Δ ρ dρ)\n\n corollary-closed : ∀ {σ τ} (t : Term ∅ (σ ⇒ τ))\n (v : ⟦ σ ⟧) (dv : Δ₍ σ ₎ v)\n → ⟦ t ⟧ ∅ (after₍ σ ₎ dv)\n ≡ ⟦ t ⟧ ∅ v ⊞₍ τ ₎ call-change {σ} {τ} (⟦ t ⟧Δ ∅ ∅) v dv\n\n corollary-closed {σ} {τ} t v dv =\n let\n f = ⟦ t ⟧ ∅\n Δf = ⟦ t ⟧Δ ∅ ∅\n in\n begin\n f (after₍ σ ₎ dv)\n ≡⟨ cong (λ hole → hole (after₍ σ ₎ dv))\n (sym (correctness {σ ⇒ τ} t ∅ ∅)) ⟩\n (f ⊞₍ σ ⇒ τ ₎ Δf) (after₍ σ ₎ dv)\n ≡⟨ is-valid {σ} {τ} (⟦ t ⟧Δ ∅ ∅) v dv ⟩\n f (before₍ σ ₎ dv) ⊞₍ τ ₎ call-change {σ} {τ} Δf v dv\n ∎ where open ≡-Reasoning\n", "meta": {"hexsha": "707fdddb385608c92491a532ee0e83b92a516cc7", "size": 5103, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Parametric/Change/Specification.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/Change/Specification.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/Change/Specification.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": 33.7947019868, "max_line_length": 180, "alphanum_fraction": 0.4879482657, "num_tokens": 2384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583124210897, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.39392530455413594}} {"text": "{-\n\nDescriptor language for easily defining structures\n\n-}\n{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}\nmodule Cubical.Structures.Macro where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.SIP\nopen import Cubical.Functions.FunExtEquiv\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Maybe\n\nopen import Cubical.Structures.Constant\nopen import Cubical.Structures.Maybe\nopen import Cubical.Structures.NAryOp\nopen import Cubical.Structures.Parameterized\nopen import Cubical.Structures.Pointed\nopen import Cubical.Structures.Product\nopen import Cubical.Structures.Functorial\n\ndata FuncDesc (ℓ : Level) : Typeω where\n -- constant structure: X ↦ A\n constant : ∀ {ℓ'} → Type ℓ' → FuncDesc ℓ\n -- pointed structure: X ↦ X\n var : FuncDesc ℓ\n -- join of structures S,T : X ↦ (S X × T X)\n _,_ : FuncDesc ℓ → FuncDesc ℓ → FuncDesc ℓ\n -- structure S parameterized by constant A : X ↦ (A → S X)\n param : ∀ {ℓ'} → (A : Type ℓ') → FuncDesc ℓ → FuncDesc ℓ\n -- structure S parameterized by variable argument: X ↦ (X → S X)\n maybe : FuncDesc ℓ → FuncDesc ℓ\n\ndata Desc (ℓ : Level) : Typeω where\n -- constant structure: X ↦ A\n constant : ∀ {ℓ'} → Type ℓ' → Desc ℓ\n -- pointed structure: X ↦ X\n var : Desc ℓ\n -- join of structures S,T : X ↦ (S X × T X)\n _,_ : Desc ℓ → Desc ℓ → Desc ℓ\n -- structure S parameterized by constant A : X ↦ (A → S X)\n param : ∀ {ℓ'} → (A : Type ℓ') → Desc ℓ → Desc ℓ\n -- structure S parameterized by variable argument: X ↦ (X → S X)\n recvar : Desc ℓ → Desc ℓ\n -- Maybe on a structure S: X ↦ Maybe (S X)\n maybe : Desc ℓ → Desc ℓ\n -- SNS from functorial action\n functorial : FuncDesc ℓ → Desc ℓ\n -- arbitrary standard notion of structure\n foreign : ∀ {ℓ' ℓ''} {S : Type ℓ → Type ℓ'} (ι : StrEquiv S ℓ'') → UnivalentStr S ι → Desc ℓ\n\ninfixr 4 _,_\n\n{- Functorial structures -}\n\nfuncMacroLevel : ∀ {ℓ} → FuncDesc ℓ → Level\nfuncMacroLevel (constant {ℓ'} x) = ℓ'\nfuncMacroLevel {ℓ} var = ℓ\nfuncMacroLevel {ℓ} (d₀ , d₁) = ℓ-max (funcMacroLevel d₀) (funcMacroLevel d₁)\nfuncMacroLevel (param {ℓ'} A d) = ℓ-max ℓ' (funcMacroLevel d)\nfuncMacroLevel (maybe d) = funcMacroLevel d\n\n-- Structure defined by a functorial descriptor\nFuncMacroStructure : ∀ {ℓ} (d : FuncDesc ℓ) → Type ℓ → Type (funcMacroLevel d)\nFuncMacroStructure (constant A) X = A\nFuncMacroStructure var X = X\nFuncMacroStructure (d₀ , d₁) X = FuncMacroStructure d₀ X × FuncMacroStructure d₁ X\nFuncMacroStructure (param A d) X = A → FuncMacroStructure d X\nFuncMacroStructure (maybe d) = MaybeStructure (FuncMacroStructure d)\n\n-- Action defined by a functorial descriptor\nfuncMacroAction : ∀ {ℓ} (d : FuncDesc ℓ)\n {X Y : Type ℓ} → (X → Y) → FuncMacroStructure d X → FuncMacroStructure d Y\nfuncMacroAction (constant A) _ = idfun A\nfuncMacroAction var f = f\nfuncMacroAction (d₀ , d₁) f (s₀ , s₁) = funcMacroAction d₀ f s₀ , funcMacroAction d₁ f s₁\nfuncMacroAction (param A d) f s a = funcMacroAction d f (s a)\nfuncMacroAction (maybe d) f = map-Maybe (funcMacroAction d f)\n\n-- Proof that the action preserves the identity\nfuncMacroId : ∀ {ℓ} (d : FuncDesc ℓ)\n {X : Type ℓ} → ∀ s → funcMacroAction d (idfun X) s ≡ s\nfuncMacroId (constant A) _ = refl\nfuncMacroId var _ = refl\nfuncMacroId (d₀ , d₁) (s₀ , s₁) = ΣPath≃PathΣ .fst (funcMacroId d₀ s₀ , funcMacroId d₁ s₁)\nfuncMacroId (param A d) s = funExt λ a → funcMacroId d (s a)\nfuncMacroId (maybe d) s = cong₂ map-Maybe (funExt (funcMacroId d)) refl ∙ map-Maybe-id s\n\n{- General structures -}\n\nmacroStrLevel : ∀ {ℓ} → Desc ℓ → Level\nmacroStrLevel (constant {ℓ'} x) = ℓ'\nmacroStrLevel {ℓ} var = ℓ\nmacroStrLevel {ℓ} (d₀ , d₁) = ℓ-max (macroStrLevel d₀) (macroStrLevel d₁)\nmacroStrLevel (param {ℓ'} A d) = ℓ-max ℓ' (macroStrLevel d)\nmacroStrLevel {ℓ} (recvar d) = ℓ-max ℓ (macroStrLevel d)\nmacroStrLevel (maybe d) = macroStrLevel d\nmacroStrLevel (functorial d) = funcMacroLevel d\nmacroStrLevel (foreign {ℓ'} _ _) = ℓ'\n\nmacroEquivLevel : ∀ {ℓ} → Desc ℓ → Level\nmacroEquivLevel (constant {ℓ'} x) = ℓ'\nmacroEquivLevel {ℓ} var = ℓ\nmacroEquivLevel {ℓ} (d₀ , d₁) = ℓ-max (macroEquivLevel d₀) (macroEquivLevel d₁)\nmacroEquivLevel (param {ℓ'} A d) = ℓ-max ℓ' (macroEquivLevel d)\nmacroEquivLevel {ℓ} (recvar d) = ℓ-max ℓ (macroEquivLevel d)\nmacroEquivLevel (maybe d) = macroEquivLevel d\nmacroEquivLevel (functorial d) = funcMacroLevel d\nmacroEquivLevel (foreign {ℓ'' = ℓ''} _ _) = ℓ''\n\n-- Structure defined by a descriptor\nMacroStructure : ∀ {ℓ} (d : Desc ℓ) → Type ℓ → Type (macroStrLevel d)\nMacroStructure (constant A) X = A\nMacroStructure var X = X\nMacroStructure (d₀ , d₁) X = MacroStructure d₀ X × MacroStructure d₁ X\nMacroStructure (param A d) X = A → MacroStructure d X\nMacroStructure (recvar d) X = X → MacroStructure d X\nMacroStructure (maybe d) = MaybeStructure (MacroStructure d)\nMacroStructure (functorial d) = FuncMacroStructure d\nMacroStructure (foreign {S = S} _ _) = S\n\n-- Notion of structured equivalence defined by a descriptor\nMacroEquivStr : ∀ {ℓ} → (d : Desc ℓ) → StrEquiv {ℓ} (MacroStructure d) (macroEquivLevel d)\nMacroEquivStr (constant A) = ConstantEquivStr A\nMacroEquivStr var = PointedEquivStr\nMacroEquivStr (d₀ , d₁) = ProductEquivStr (MacroEquivStr d₀) (MacroEquivStr d₁)\nMacroEquivStr (param A d) = ParamEquivStr A λ _ → MacroEquivStr d\nMacroEquivStr (recvar d) = UnaryFunEquivStr (MacroEquivStr d)\nMacroEquivStr (maybe d) = MaybeEquivStr (MacroEquivStr d)\nMacroEquivStr (functorial d) = FunctorialEquivStr (funcMacroAction d)\nMacroEquivStr (foreign ι _) = ι\n\n-- Proof that structure induced by descriptor is univalent\nMacroUnivalentStr : ∀ {ℓ} → (d : Desc ℓ) → UnivalentStr (MacroStructure d) (MacroEquivStr d)\nMacroUnivalentStr (constant A) = constantUnivalentStr A\nMacroUnivalentStr var = pointedUnivalentStr\nMacroUnivalentStr (d₀ , d₁) =\n ProductUnivalentStr (MacroEquivStr d₀) (MacroUnivalentStr d₀) (MacroEquivStr d₁) (MacroUnivalentStr d₁)\nMacroUnivalentStr (param A d) = ParamUnivalentStr A (λ _ → MacroEquivStr d) (λ _ → MacroUnivalentStr d)\nMacroUnivalentStr (recvar d) = unaryFunUnivalentStr (MacroEquivStr d) (MacroUnivalentStr d)\nMacroUnivalentStr (maybe d) = maybeUnivalentStr (MacroEquivStr d) (MacroUnivalentStr d)\nMacroUnivalentStr (functorial d) = functorialUnivalentStr (funcMacroAction d) (funcMacroId d)\nMacroUnivalentStr (foreign _ θ) = θ\n\n-- Module for easy importing\nmodule Macro ℓ (d : Desc ℓ) where\n\n structure = MacroStructure d\n equiv = MacroEquivStr d\n univalent = MacroUnivalentStr d\n", "meta": {"hexsha": "98695c81057006811476a25861bc1a6ddb43d7c4", "size": 6545, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Structures/Macro.agda", "max_stars_repo_name": "RobertHarper/cubical", "max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "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": "Cubical/Structures/Macro.agda", "max_issues_repo_name": "RobertHarper/cubical", "max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "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": "Cubical/Structures/Macro.agda", "max_forks_repo_name": "RobertHarper/cubical", "max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "avg_line_length": 42.2258064516, "max_line_length": 105, "alphanum_fraction": 0.7214667685, "num_tokens": 2213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6688802603710085, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.39389631511764434}} {"text": "------------------------------------------------------------------------\n-- This file contains the definition of a preorder as a category with --\n-- additional properties. --\n------------------------------------------------------------------------\nmodule Category.Preorder where\n\nopen import Level renaming (suc to lsuc)\nopen import Data.Empty\n\nopen import Setoid.Total\nopen import Category.Category\nopen import Equality.Eq\n\nrecord PO {l : Level} : Set (lsuc l) where\n field\n -- The underlying category.\n ℙ : Cat {l}\n\n -- The preorder axiom.\n POax : ∀{A B}{f g : el (Hom ℙ A B)} → ⟨ Hom ℙ A B ⟩[ f ≡ g ]\n\nopen PO public renaming (ℙ to po-cat)\n\n-- A PO with 4 objects.\nmodule 4PO where\n -- The objects.\n data 4Obj {l : Level} : Set l where\n i₁ : 4Obj\n i₂ : 4Obj\n i₃ : 4Obj\n i₄ : 4Obj\n\n -- The PreHom.\n data 4PHom {l : Level} : 4Obj {l} → 4Obj {l} → Set l where\n id₁ : 4PHom i₁ i₁\n f₁ : 4PHom i₁ i₂ \n f₂ : 4PHom i₁ i₃ \n id₂ : 4PHom i₂ i₂\n f₃ : 4PHom i₂ i₄ \n id₃ : 4PHom i₃ i₃ \n f₄ : 4PHom i₃ i₄ \n f₅ : 4PHom i₁ i₄\n id₄ : 4PHom i₄ i₄ \n \n -- The Hom.\n 4Hom : {l : Level} → 4Obj {l} → 4Obj {l} → Setoid {l}\n 4Hom i₁ i₁ = record { el = 4PHom i₁ i₁; eq = λ a b → a ≅ b; eqRpf = isEqRel }\n 4Hom i₁ i₂ = record { el = 4PHom i₁ i₂; eq = λ a b → a ≅ b; eqRpf = isEqRel }\n 4Hom i₁ i₃ = record { el = 4PHom i₁ i₃; eq = λ a b → a ≅ b; eqRpf = isEqRel }\n 4Hom i₁ i₄ = record { el = 4PHom i₁ i₄; eq = λ a b → a ≅ b; eqRpf = isEqRel } \n 4Hom i₂ i₂ = record { el = 4PHom i₂ i₂; eq = λ a b → a ≅ b; eqRpf = isEqRel }\n 4Hom i₂ i₄ = record { el = 4PHom i₂ i₄; eq = λ a b → a ≅ b; eqRpf = isEqRel }\n 4Hom i₃ i₃ = record { el = 4PHom i₃ i₃; eq = λ a b → a ≅ b; eqRpf = isEqRel }\n 4Hom i₃ i₄ = record { el = 4PHom i₃ i₄; eq = λ a b → a ≅ b; eqRpf = isEqRel }\n 4Hom i₄ i₄ = record { el = 4PHom i₄ i₄; eq = λ a b → a ≅ b; eqRpf = isEqRel }\n 4Hom _ _ = EmptySetoid\n \n 4Comp : {l : Level}{a b c : 4Obj {l}} → BinSetoidFun (4Hom a b) (4Hom b c) (4Hom a c)\n 4Comp {_} {i₁} {i₂} {i₁} = record { appT = λ x → record { appT = λ x₁ → id₁; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₁} {i₁} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₂} {i₁} {i₂} = record { appT = λ x → record { appT = λ x₁ → id₂; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₁} {i₃} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₂} {i₁} {i₄} = record { appT = λ x → record { appT = λ x₁ → f₃; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₁} {i₁} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₃} {i₂} {i₁} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₁} {i₂} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₃} {i₁} {i₃} = record { appT = λ x → record { appT = λ x₁ → id₃; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₁} {i₄} = record { appT = λ x → record { appT = λ x₁ → f₄; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₄} {i₁} {i₁} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₄} {i₂} {i₁} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₄} {i₁} {i₂} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₄} {i₁} {i₃} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₄} {i₃} {i₃} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₄} {i₁} {i₄} = record { appT = λ x → record { appT = λ x₁ → ⊥-poly-elim x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₄} {i₄} {i₃} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₄} {i₄} {i₂} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₄} {i₄} {i₁} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₄} {i₃} {i₄} = record { appT = λ x → record { appT = λ x₁ → id₄; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₄} {i₃} {i₂} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₄} {i₃} {i₁} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₄} {i₂} {i₄} = record { appT = λ x → record { appT = λ x₁ → id₄; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₄} {i₂} {i₃} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₄} {i₂} {i₂} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₃} {i₄} {i₃} = record { appT = λ x → record { appT = λ x₁ → id₃; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₄} {i₂} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₄} {i₁} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₃} {i₄} = record { appT = λ x → record { appT = λ x₁ → f₄; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₃} {i₂} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₃} {i₁} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₂} {i₄} = record { appT = λ x → record { appT = λ x₁ → f₄; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₂} {i₃} = record { appT = λ x → record { appT = λ x₁ → id₃; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₃} {i₂} {i₂} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₃} {i₄} {i₄} = record { appT = λ x → record { appT = λ x₁ → f₄; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₄} {i₃} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₄} {i₂} = record { appT = λ x → record { appT = λ x₁ → id₂; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₄} {i₁} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₃} {i₄} = record { appT = λ x → record { appT = λ x₁ → f₃; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₃} {i₂} = record { appT = λ x → record { appT = λ x₁ → id₂; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₃} {i₁} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₂} {i₂} {i₄} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₂} {i₃} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₂} {i₂} = record { appT = λ x → record { appT = λ x₁ → id₂; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₂} {i₃} {i₃} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₂} {i₄} {i₄} = record { appT = λ x → record { appT = λ x₁ → x; extT = λ x₂ → refl }; extT = λ x₁ x₂ → x₁ }\n 4Comp {_} {i₁} {i₄} {i₃} = record { appT = λ x → record { appT = λ x₁ → f₂; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₁} {i₄} {i₂} = record { appT = λ x → record { appT = λ x₁ → f₁; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₁} {i₄} {i₁} = record { appT = λ x → record { appT = λ x₁ → id₁; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₁} {i₃} {i₄} = record { appT = λ x → record { appT = λ x₁ → f₅; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₁} {i₃} {i₂} = record { appT = λ x → record { appT = λ x₁ → f₁; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₁} {i₃} {i₁} = record { appT = λ x → record { appT = λ x₁ → id₁; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₁} {i₂} {i₄} = record { appT = λ x → record { appT = λ x₁ → f₅; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₁} {i₂} {i₃} = record { appT = λ x → record { appT = λ x₁ → f₂; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₁} {i₂} {i₂} = record { appT = λ x → record { appT = λ x₁ → f₁; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₁} {i₃} {i₃} = record { appT = λ x → record { appT = λ x₁ → f₂; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {_} {i₁} {i₄} {i₄} = record { appT = λ x → record { appT = λ x₁ → f₅; extT = λ x₂ → refl }; extT = λ x₁ x₂ → refl }\n 4Comp {l} {i₁} {i₁} {c} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refPf (eqRpf (4Hom i₁ c)) {x₂} }\n 4Comp {l} {i₂} {i₂} {c} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refPf (eqRpf (4Hom i₂ c)) {x₂} }\n 4Comp {l} {i₃} {i₃} {c} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refPf (eqRpf (4Hom i₃ c)) {x₂} } \n 4Comp {l} {i₄} {i₄} {c} = record { appT = λ x → record { appT = λ x₁ → x₁; extT = λ x₂ → x₂ }; extT = λ x₁ x₂ → refPf (eqRpf (4Hom i₄ c)) {x₂} }\n\n 4Id : {l : Level}{A : 4Obj {l}} → el (4Hom A A)\n 4Id {_}{i₁} = id₁\n 4Id {_}{i₂} = id₂\n 4Id {_}{i₃} = id₃\n 4Id {_}{i₄} = id₄\n\n 4PO-ax : ∀{l}{A B : 4Obj {l}}{f g : el (4Hom A B)} → eq (4Hom A B) f g\n 4PO-ax {A = i₁} {i₁} {id₁} {id₁} = refl\n 4PO-ax {A = i₁} {i₂} {f₁} {f₁} = refl\n 4PO-ax {A = i₁} {i₃} {f₂} {f₂} = refl\n 4PO-ax {A = i₁} {i₄} {f₅} {f₅} = refl\n 4PO-ax {A = i₂} {i₂} {id₂} {id₂} = refl\n 4PO-ax {A = i₂} {i₄} {f₃} {f₃} = refl \n 4PO-ax {A = i₃} {i₃} {id₃} {id₃} = refl\n 4PO-ax {A = i₃} {i₄} {f₄} {f₄} = refl\n 4PO-ax {A = i₄} {i₄} {id₄} {id₄} = refl\n 4PO-ax {A = i₂} {i₁} {f} = ⊥-poly-elim f\n 4PO-ax {A = i₃} {i₁} {f} = ⊥-poly-elim f\n 4PO-ax {A = i₄} {i₁} {f} = ⊥-poly-elim f \n 4PO-ax {A = i₃} {i₂} {f} = ⊥-poly-elim f\n 4PO-ax {A = i₄} {i₂} {f} = ⊥-poly-elim f\n 4PO-ax {A = i₂} {i₃} {f} = ⊥-poly-elim f \n 4PO-ax {A = i₄} {i₃} {f} = ⊥-poly-elim f\n\n 4AssocPf : ∀{l}{A B C D : 4Obj {l}} {f : el (4Hom A B)} {g : el (4Hom B C)}{h : el (4Hom C D)} \n → ⟨ 4Hom A D ⟩[ f ○[ 4Comp {l} {A}{B}{D} ] (g ○[ 4Comp {l}{B}{C}{D} ] h) ≡ (f ○[ 4Comp {l} {A}{B}{C} ] g) ○[ 4Comp {l}{A}{C}{D} ] h ]\n 4AssocPf {l}{A}{B}{C}{D} {f}{g} = 4PO-ax {l} {A} {D}\n \n 4IdPF : {l : Level}{A B : 4Obj {l}} {f : el (4Hom A B)} \n → ⟨ 4Hom A B ⟩[ (4Id {l}{A}) ○[ 4Comp {l}{A}{A}{B} ] f ≡ f ○[ 4Comp {l}{A}{B}{B} ] (4Id {l}{B}) ]\n 4IdPF {l}{A}{B}{f} = 4PO-ax {l} {A} {B}\n\n -- We have a category.\n 4cat : {l : Level} → Cat {l}\n 4cat {l} = record { Obj = 4Obj {l};\n Hom = 4Hom;\n comp = λ {A} {B} {C} → 4Comp {l} {A}{B}{C};\n id = λ {A} → 4Id {l}{A};\n assocPf = λ {A} {B} {C} {D} {f} {g} {h} → 4AssocPf {l}{A}{B}{C}{D}{f}{g}{h};\n idPfCom = λ {A} {B} {f} → 4IdPF {l}{A}{B}{f};\n idPf = λ {A} {B} {f} → 4PO-ax {l} {A} {B}}\n\n -- We have a preorder.\n 4po : {l : Level} → PO {l}\n 4po {l} = record { ℙ = 4cat;\n POax = λ {A} {B} {f} {g} → 4PO-ax {l} {A} {B} {f} {g} }\n", "meta": {"hexsha": "d133120730a5fd5d64dc7f5641da412c6b88a673", "size": 12043, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "setoid-cats/Category/Preorder.agda", "max_stars_repo_name": "heades/AUGL", "max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": "setoid-cats/Category/Preorder.agda", "max_issues_repo_name": "heades/AUGL", "max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": "setoid-cats/Category/Preorder.agda", "max_forks_repo_name": "heades/AUGL", "max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": 72.1137724551, "max_line_length": 150, "alphanum_fraction": 0.4745495308, "num_tokens": 5852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.3937367399201701}} {"text": "\nmodule Issue59 where\n\ndata Nat : Set where\n zero : Nat\n suc : Nat → Nat\n\n-- This no longer termination checks with the\n-- new rules for with.\nbad : Nat → Nat\nbad n with n\n... | zero = zero\n... | suc m = bad m\n\n-- This shouldn't termination check.\nbad₂ : Nat → Nat\nbad₂ n with bad₂ n\n... | m = m\n", "meta": {"hexsha": "7a392c95a11369318f2a0eb900cfbc4b438f0e62", "size": 300, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue59.agda", "max_stars_repo_name": "alhassy/agda", "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_issues_repo_path": "test/Fail/Issue59.agda", "max_issues_repo_name": "alhassy/agda", "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "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/Issue59.agda", "max_forks_repo_name": "alhassy/agda", "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "avg_line_length": 15.7894736842, "max_line_length": 45, "alphanum_fraction": 0.6266666667, "num_tokens": 94, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8128673087708698, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.39373673552843935}} {"text": "open import Oscar.Prelude\nopen import Oscar.Class.Successor₀\nopen import Oscar.Class.Successor₁\nopen import Oscar.Class.Injectivity\nopen import Oscar.Class.Thickandthin\nopen import Oscar.Class.Congruity\nopen import Oscar.Class.Fmap\nopen import Oscar.Data.¶\nopen import Oscar.Data.Fin\nopen import Oscar.Data.Proposequality\nopen import Oscar.Data.Maybe\nimport Oscar.Property.Monad.Maybe\nimport Oscar.Class.Congruity.Proposequality\n\nmodule Oscar.Property.Thickandthin.FinFinProposequalityMaybeProposequality where\n\ninstance\n\n 𝓢uccessor₀¶ : 𝓢uccessor₀ ¶\n 𝓢uccessor₀¶ .𝓢uccessor₀.successor₀ = ↑_\n\n [𝓢uccessor₁]Fin : [𝓢uccessor₁] Fin\n [𝓢uccessor₁]Fin = ∁\n\n 𝓢uccessor₁Fin : 𝓢uccessor₁ Fin\n 𝓢uccessor₁Fin .𝓢uccessor₁.successor₁ = ↑_\n\n [𝓘njectivity₁]Fin : ∀ {m} → [𝓘njectivity₁] (λ (_ : Fin m) → Fin (⇑₀ m)) Proposequality Proposequality\n [𝓘njectivity₁]Fin = ∁\n\n 𝓘njectivity₁Fin : ∀ {m} → 𝓘njectivity₁ (λ (_ : Fin m) → Fin (⇑₀ m)) Proposequality Proposequality\n 𝓘njectivity₁Fin .𝓘njectivity₁.injectivity₁ ∅ = ∅\n\n [𝓣hick]Fin,Fin : [𝓣hick] Fin Fin\n [𝓣hick]Fin,Fin = ∁\n\n 𝓣hickFin,Fin : 𝓣hick Fin Fin\n 𝓣hickFin,Fin .𝓣hick.thick {∅} () ∅\n 𝓣hickFin,Fin .𝓣hick.thick {↑ _} _ ∅ = ∅\n 𝓣hickFin,Fin .𝓣hick.thick ∅ (↑ y) = y\n 𝓣hickFin,Fin .𝓣hick.thick (↑ x) (↑ y) = ↑ thick x y\n\n [𝓣hin]Fin,Fin : [𝓣hin] Fin Fin\n [𝓣hin]Fin,Fin = ∁\n\n 𝓣hinFin,Fin : 𝓣hin Fin Fin\n 𝓣hinFin,Fin .𝓣hin.thin ∅ = ↑_\n 𝓣hinFin,Fin .𝓣hin.thin (↑ x) ∅ = ∅\n 𝓣hinFin,Fin .𝓣hin.thin (↑ x) (↑ y) = ↑ (thin x y)\n\n [𝓘njectivity₂,₁]ThinFinFin : ∀ {m} → [𝓘njectivity₂,₁] (𝔱hin Fin Fin m) Proposequality Proposequality\n [𝓘njectivity₂,₁]ThinFinFin = ∁\n\n 𝓘njectivity₂,₁ThinFinFin : ∀ {m} → 𝓘njectivity₂,₁ (𝔱hin Fin Fin m) Proposequality Proposequality\n 𝓘njectivity₂,₁ThinFinFin .𝓘njectivity₂,₁.injectivity₂,₁ ∅ ∅ = ∅\n 𝓘njectivity₂,₁ThinFinFin .𝓘njectivity₂,₁.injectivity₂,₁ (↑ _) {∅} {∅} _ = ∅\n 𝓘njectivity₂,₁ThinFinFin .𝓘njectivity₂,₁.injectivity₂,₁ (↑ _) {∅} {↑ _} ()\n 𝓘njectivity₂,₁ThinFinFin .𝓘njectivity₂,₁.injectivity₂,₁ (↑ _) {↑ _} {∅} ()\n 𝓘njectivity₂,₁ThinFinFin .𝓘njectivity₂,₁.injectivity₂,₁ (↑ x) {↑ _} {↑ _} = congruity ↑_ ∘ injectivity₂,₁ x ∘ injectivity₁[ Proposequality ]\n\n [𝓒heck]FinFinMaybe : [𝓒heck] Fin Fin Maybe\n [𝓒heck]FinFinMaybe = ∁\n\n 𝓒heckFinFinMaybe : 𝓒heck Fin Fin Maybe\n 𝓒heckFinFinMaybe .𝓒heck.check ∅ ∅ = ∅\n 𝓒heckFinFinMaybe .𝓒heck.check ∅ (↑ y) = ↑ y\n 𝓒heckFinFinMaybe .𝓒heck.check {∅} (↑ ()) _\n 𝓒heckFinFinMaybe .𝓒heck.check {↑ _} (↑ x) ∅ = ↑ ∅\n 𝓒heckFinFinMaybe .𝓒heck.check {↑ _} (↑ x) (↑ y) = fmap′ ¶⟨<_⟩.↑_ $ check x y\n\n [𝓣hick/thin=1]FinFin : [𝓣hick/thin=1] Fin Fin Proposequality\n [𝓣hick/thin=1]FinFin = ∁\n\n 𝓣hick/thin=1FinFin : 𝓣hick/thin=1 Fin Fin Proposequality\n 𝓣hick/thin=1FinFin .𝓣hick/thin=1.thick/thin=1 x ∅ = ∅\n 𝓣hick/thin=1FinFin .𝓣hick/thin=1.thick/thin=1 ∅ (↑ y) = ∅\n 𝓣hick/thin=1FinFin .𝓣hick/thin=1.thick/thin=1 (↑ x) (↑ y) = congruity ↑_ (thick/thin=1 x y)\n\n [𝓒heck/thin=1FinFin] : [𝓒heck/thin=1] Fin Fin Maybe Proposequality\n [𝓒heck/thin=1FinFin] = ∁\n\n 𝓒heck/thin=1FinFin : 𝓒heck/thin=1 Fin Fin Maybe Proposequality\n 𝓒heck/thin=1FinFin .𝓒heck/thin=1.check/thin=1 ∅ y = ∅\n 𝓒heck/thin=1FinFin .𝓒heck/thin=1.check/thin=1 (↑ x) ∅ = ∅\n 𝓒heck/thin=1FinFin .𝓒heck/thin=1.check/thin=1 (↑ x) (↑ y) rewrite check/thin=1 {_≈_ = Proposequality⟦ Maybe _ ⟧} x y = ∅\n\n IsThickandthinFinFin : IsThickandthin Fin Fin Proposequality Maybe Proposequality\n IsThickandthinFinFin = ∁\n\nThickandthinFinFin : Thickandthin _ _ _ _ _ _\nThickandthinFinFin = ∁ Fin Fin Proposequality Maybe Proposequality\n", "meta": {"hexsha": "e42512a8de4a39bd7196ceb26f4d36e94225f8d0", "size": 3531, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "archive/agda-3/src/Oscar/Property/Thickandthin/FinFinProposequalityMaybeProposequality.agda", "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "archive/agda-3/src/Oscar/Property/Thickandthin/FinFinProposequalityMaybeProposequality.agda", "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_forks_repo_path": "archive/agda-3/src/Oscar/Property/Thickandthin/FinFinProposequalityMaybeProposequality.agda", "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.3804347826, "max_line_length": 143, "alphanum_fraction": 0.6966864911, "num_tokens": 1639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174789, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.3936674393694684}} {"text": "{-# OPTIONS --safe #-}\n\nopen import Generics.Prelude hiding (lookup; pi; curry)\nopen import Generics.Telescope\nopen import Generics.Desc\nopen import Generics.All\nopen import Generics.HasDesc\nimport Generics.Helpers as Helpers\n\nopen import Relation.Binary.HeterogeneousEquality.Core using (_≅_; refl)\n\nmodule Generics.Constructions.Cong\n {P I ℓ} {A : Indexed P I ℓ} (H : HasDesc {P} {I} {ℓ} A)\n {p}\n where\n\nopen HasDesc H\n\nprivate\n variable\n V : ExTele P\n i i₁ i₂ : ⟦ I ⟧tel p\n v v₁ v₂ : ⟦ V ⟧tel p\n\n\n-----------------------\n-- Type of congruences\n\nlevelCongCon : (C : ConDesc P V I) → Level\nlevelCongCon (var _) = ℓ\nlevelCongCon (π {ℓ} _ _ C) = ℓ ⊔ levelCongCon C\nlevelCongCon (A ⊗ B) = levelIndArg A ℓ ⊔ levelCongCon B\n\nCongCon : (C : ConDesc P V I)\n (mk₁ : ∀ {i₁} → ⟦ C ⟧Con A′ (p , v₁ , i₁) → ⟦ D ⟧Data A′ (p , i₁))\n (mk₂ : ∀ {i₂} → ⟦ C ⟧Con A′ (p , v₂ , i₂) → ⟦ D ⟧Data A′ (p , i₂))\n → Set (levelCongCon C)\n-- If non-inductive arguments are equal\nCongCon (π (n , ai) S C) mk₁ mk₂\n = {s₁ : < relevance ai > S _}\n {s₂ : < relevance ai > S _}\n → s₁ ≅ s₂\n → CongCon C (λ x → mk₁ (s₁ , x))\n (λ x → mk₂ (s₂ , x))\n-- And inductive arguments are equal\nCongCon (A ⊗ B) mk₁ mk₂ \n = {f₁ : ⟦ A ⟧IndArg A′ _}\n {f₂ : ⟦ A ⟧IndArg A′ _}\n → f₁ ≅ f₂\n → CongCon B (λ x → mk₁ (f₁ , x))\n (λ x → mk₂ (f₂ , x))\n-- Then applying the constructor to both sets should lead\n-- to equal values\nCongCon (var f) mk₁ mk₂ \n = constr (mk₁ refl) ≅ constr (mk₂ refl) \n\nCong : ∀ k → Set (levelCongCon (lookupCon D k))\nCong k = CongCon (lookupCon D k) (k ,_) (k ,_)\n\n\n----------------------\n-- Generic congruence\n\nderiveCong : ∀ k → Cong k\nderiveCong k = congCon (lookupCon D k)\n where\n congCon : (C : ConDesc P V I)\n {mk : ∀ {i} → ⟦ C ⟧Con A′ (p , v , i) → ⟦ D ⟧Data A′ (p , i)}\n → CongCon C mk mk\n congCon (var f) = refl\n congCon (π ai S C) refl = congCon C\n congCon (A ⊗ B) refl = congCon B\n", "meta": {"hexsha": "1e5d5f9a8e48b21a88b838de4821164c72146144", "size": 1986, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Generics/Constructions/Cong.agda", "max_stars_repo_name": "flupe/generics", "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_issues_repo_path": "src/Generics/Constructions/Cong.agda", "max_issues_repo_name": "flupe/generics", "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_forks_repo_path": "src/Generics/Constructions/Cong.agda", "max_forks_repo_name": "flupe/generics", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "avg_line_length": 27.2054794521, "max_line_length": 76, "alphanum_fraction": 0.5594159114, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837743174788, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.3936674393694683}} {"text": "\nmodule _ where\n\nopen import Common.Prelude hiding (_>>=_)\nopen import Common.Reflection\n\ninfix -100 This:_ this:_\ndata This:_ {a} {A : Set a} : A → Set where\n this:_ : ∀ x → This: x\n\nmacro\n runT : Tactic → Tactic\n runT m = m\n\n evalT : ∀ {a} {A : Set a} → TC A → Tactic\n evalT m hole = m >>= quoteTC >>= unify hole\n\n-- The context on the rhs of each of the two functions below is the same, a single String\n\nΓ = vArg (def (quote String) []) ∷ []\n\ncontext-Γ₀ : String → This: Γ\ncontext-Γ₀ s = this: evalT getContext\n\nmodule _ (S : String) where\n context-Γ₁ : This: Γ\n context-Γ₁ = this: evalT getContext\n\nreplicate : {A : Set} → Nat → A → List A\nreplicate zero x = []\nreplicate (suc n) x = x ∷ replicate n x\n\nf-type : Term\nf-type = def (quote String) []\n\nf-pats : Nat → List (Arg Pattern)\nf-pats n = replicate n (vArg (var \"_\"))\n\nf-term : Nat → Term\nf-term n = var n []\n\ndefineFresh : Nat → Nat → TC QName\ndefineFresh #pats #term =\n freshName \"f\" >>= λ f →\n define (vArg f) (funDef f-type (clause (f-pats #pats) (f-term #term) ∷ [])) >>= λ _ →\n returnTC f\n\nfreshFun : Nat → Nat → TC Bool\nfreshFun #pats #term =\n catchTC (defineFresh #pats #term >>= λ _ → returnTC true)\n (returnTC false)\n\n-- Check that the pattern list must be of length 0\n-- and the context features 1 available variable.\n\ndefine-Γ₀-0-0 : String → This: true\ndefine-Γ₀-0-0 s = this: evalT (freshFun 0 0)\n\ndefine-Γ₀-1-0 : String → This: false\ndefine-Γ₀-1-0 s = this: evalT (freshFun 1 0)\n\ndefine-Γ₀-1-1 : String → This: false\ndefine-Γ₀-1-1 s = this: evalT (freshFun 0 1)\n\nmodule _ (S : String) where\n define-Γ₁-0-0 : This: true\n define-Γ₁-0-0 = this: evalT (freshFun 0 0)\n\n define-Γ₁-0-1 : This: false\n define-Γ₁-0-1 = this: evalT (freshFun 0 1)\n\n define-Γ₁-1-0 : This: false\n define-Γ₁-1-0 = this: evalT (freshFun 1 0)\n\nf₀ : String → String\nf₀ s = runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])\n\nf₁ : String → String\nf₁ = λ s → runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])\n\nf₂ : String → String\nf₂ s = runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])\n where x = 0\n", "meta": {"hexsha": "e0ed097006e690db524deea6bb30ffe866b89d6c", "size": 2102, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1833.agda", "max_stars_repo_name": "hborum/agda", "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_issues_repo_path": "test/Succeed/Issue1833.agda", "max_issues_repo_name": "hborum/agda", "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_forks_repo_path": "test/Succeed/Issue1833.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "avg_line_length": 25.0238095238, "max_line_length": 89, "alphanum_fraction": 0.6303520457, "num_tokens": 779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982315512489, "lm_q2_score": 0.6076631698328916, "lm_q1q2_score": 0.39364312679657343}} {"text": "open import Prelude\n\nmodule Implicits.Semantics.Preservation where\n\nopen import Implicits.Syntax\nopen import Implicits.WellTyped\nopen import Implicits.Semantics.Type\nopen import Implicits.Semantics.Context\nopen import Implicits.Semantics.Lemmas\nopen import Implicits.Semantics.RewriteContext\nopen import Implicits.Semantics.Term\nopen import SystemF.Everything as F using ()\n\nmodule Preservation\n (_⊢ᵣ_ : ∀ {ν} → ICtx ν → Type ν → Set)\n (⟦_,_⟧r : ∀ {ν n} {K : Ktx ν n} {a} → (proj₂ K) ⊢ᵣ a → K# K →\n ∃ λ t → ⟦ proj₁ K ⟧ctx→ F.⊢ t ∈ ⟦ a ⟧tp→) where\n\n open TypingRules _⊢ᵣ_\n open TermSemantics _⊢ᵣ_ ⟦_,_⟧r\n\n -- interpretation of well-typed terms in System F preserves type\n ⟦⟧-preserves-tp : ∀ {ν n} {K : Ktx ν n} {t a} → (wt-t : K ⊢ t ∈ a) → (m : K# K) →\n ⟦ proj₁ K ⟧ctx→ F.⊢ ⟦ wt-t , m ⟧ ∈ ⟦ a ⟧tp→\n ⟦⟧-preserves-tp {K = K} (var x) m = subst-wt-var (sym $ lookup-⟦⟧ctx→ (proj₁ K) x) (F.var x)\n where\n subst-wt-var = subst (λ a → ⟦ proj₁ K ⟧ctx→ F.⊢ (F.var x) ∈ a)\n ⟦⟧-preserves-tp {K = K} {a = ∀' a} (Λ wt-e) m with ⟦⟧-preserves-tp wt-e (#tvar m)\n ... | ih = F.Λ (subst-wt-ctx (⟦weaken⟧ctx→ (proj₁ K)) ih)\n where\n subst-wt-ctx = subst (λ c → c F.⊢ ⟦ wt-e , #tvar m ⟧ ∈ ⟦ a ⟧tp→)\n ⟦⟧-preserves-tp (λ' a wt-e) m with ⟦⟧-preserves-tp wt-e (#var a m)\n ⟦⟧-preserves-tp (λ' a wt-e) m | ih = F.λ' ⟦ a ⟧tp→ ih\n ⟦⟧-preserves-tp {K = K} (_[_] {a = a} wt-tc b) m with ⟦⟧-preserves-tp wt-tc m\n ... | ih = subst-tp (sym $ ⟦a/sub⟧tp→ a b) (ih F.[ ⟦ b ⟧tp→ ])\n where\n subst-tp = subst (λ c → ⟦ proj₁ K ⟧ctx→ F.⊢ ⟦ wt-tc [ b ] , m ⟧ ∈ c) \n ⟦⟧-preserves-tp (wt-f · wt-e) m with ⟦⟧-preserves-tp wt-f m | ⟦⟧-preserves-tp wt-e m\n ⟦⟧-preserves-tp (wt-f · wt-e) m | ih | y = ih F.· y\n ⟦⟧-preserves-tp (ρ {a = a} unamb-a wt-e) m with ⟦⟧-preserves-tp wt-e (#ivar a m)\n ⟦⟧-preserves-tp (ρ {a = a} unamb-a wt-e) m | ih = F.λ' ⟦ a ⟧tp→ ih\n ⟦⟧-preserves-tp (wt-r ⟨ e ⟩) m with ⟦⟧-preserves-tp wt-r m\n ⟦⟧-preserves-tp (wt-r ⟨ e ⟩) m | f-wt-r = f-wt-r F.· (proj₂ ⟦ e , m ⟧r)\n ⟦⟧-preserves-tp (wt-r with' wt-e ) m with ⟦⟧-preserves-tp wt-r m | ⟦⟧-preserves-tp wt-e m\n ⟦⟧-preserves-tp (wt-r with' wt-e ) m | f-wt-r | f-wt-e = f-wt-r F.· f-wt-e\n \n", "meta": {"hexsha": "1b70a3a797e8affb007b27e2e3c37106740ed8f0", "size": 2189, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Implicits/Semantics/Preservation.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/Semantics/Preservation.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/Semantics/Preservation.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": 46.5744680851, "max_line_length": 94, "alphanum_fraction": 0.5619004111, "num_tokens": 1042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.6076631698328916, "lm_q1q2_score": 0.39364311853287776}} {"text": "{-# OPTIONS --without-K --exact-split --safe #-}\n\nmodule Fragment.Extensions.Semigroup where\n\nopen import Fragment.Equational.Theory.Bundles\n\nopen import Fragment.Algebra.Signature\nopen import Fragment.Algebra.Homomorphism Σ-magma\nopen import Fragment.Algebra.Free Σ-magma hiding (_~_)\nopen import Fragment.Algebra.Algebra Σ-magma\n using (Algebra; IsAlgebra; Interpretation; Congruence; algebra)\n\nopen import Fragment.Equational.FreeExtension Θ-semigroup\nopen import Fragment.Equational.Model Θ-semigroup\n\nopen import Fragment.Setoid.Morphism using (_↝_)\n\nopen import Level using (Level; _⊔_)\n\nopen import Data.Nat using (ℕ)\nopen import Data.Fin using (Fin; #_)\nopen import Data.Vec using (Vec; []; _∷_; map)\nopen import Data.Vec.Relation.Binary.Pointwise.Inductive using ([]; _∷_)\n\nimport Relation.Binary.Reasoning.Setoid as Reasoning\nopen import Relation.Binary using (Setoid; IsEquivalence)\nopen import Relation.Binary.PropositionalEquality as PE using (_≡_)\n\nprivate\n variable\n a ℓ : Level\n\nmodule _ (A : Model {a} {ℓ}) (n : ℕ) where\n\n private\n\n open module A = Setoid ∥ A ∥/≈\n\n _·_ : ∥ A ∥ → ∥ A ∥ → ∥ A ∥\n x · y = A ⟦ • ⟧ (x ∷ y ∷ [])\n\n ·-cong : ∀ {x y z w} → x ≈ y → z ≈ w → x · z ≈ y · w\n ·-cong x≈y z≈w = (A ⟦ • ⟧-cong) (x≈y ∷ z≈w ∷ [])\n\n ·-assoc : ∀ (x y z : ∥ A ∥) → (x · y) · z ≈ x · (y · z)\n ·-assoc x y z = ∥ A ∥ₐ-models assoc (env {A = ∥ A ∥ₐ} (x ∷ y ∷ z ∷ []))\n\n mutual\n\n data STree : Set a where\n leaf : ∥ A ∥ → STree\n cons : ∥ A ∥ → DTree → STree\n\n data DTree : Set a where\n leaf : Fin n → DTree\n cons : Fin n → Tree → DTree\n\n data Tree : Set a where\n sta : STree → Tree\n dyn : DTree → Tree\n\n mutual\n\n infix 6 _≋_ _≋⟨s⟩_ _≋⟨d⟩_\n\n data _≋⟨s⟩_ : STree → STree → Set (a ⊔ ℓ) where\n leaf : ∀ {x y} → x ≈ y → leaf x ≋⟨s⟩ leaf y\n cons : ∀ {x y xs ys} → x ≈ y → xs ≋⟨d⟩ ys\n → cons x xs ≋⟨s⟩ cons y ys\n\n data _≋⟨d⟩_ : DTree → DTree → Set (a ⊔ ℓ) where\n leaf : ∀ {x y} → x ≡ y → leaf x ≋⟨d⟩ leaf y\n cons : ∀ {x y xs ys} → x ≡ y → xs ≋ ys\n → cons x xs ≋⟨d⟩ cons y ys\n\n data _≋_ : Tree → Tree → Set (a ⊔ ℓ) where\n sta : ∀ {x y} → x ≋⟨s⟩ y → sta x ≋ sta y\n dyn : ∀ {x y} → x ≋⟨d⟩ y → dyn x ≋ dyn y\n\n mutual\n\n ≋⟨s⟩-refl : ∀ {x} → x ≋⟨s⟩ x\n ≋⟨s⟩-refl {leaf x} = leaf A.refl\n ≋⟨s⟩-refl {cons x xs} = cons A.refl ≋⟨d⟩-refl\n\n ≋⟨d⟩-refl : ∀ {x} → x ≋⟨d⟩ x\n ≋⟨d⟩-refl {leaf x} = leaf PE.refl\n ≋⟨d⟩-refl {cons x xs} = cons PE.refl ≋-refl\n\n ≋-refl : ∀ {x} → x ≋ x\n ≋-refl {sta x} = sta ≋⟨s⟩-refl\n ≋-refl {dyn x} = dyn ≋⟨d⟩-refl\n\n mutual\n\n ≋⟨s⟩-sym : ∀ {x y} → x ≋⟨s⟩ y → y ≋⟨s⟩ x\n ≋⟨s⟩-sym (leaf p) = leaf (A.sym p)\n ≋⟨s⟩-sym (cons p ps) = cons (A.sym p) (≋⟨d⟩-sym ps)\n\n ≋⟨d⟩-sym : ∀ {x y} → x ≋⟨d⟩ y → y ≋⟨d⟩ x\n ≋⟨d⟩-sym (leaf p) = leaf (PE.sym p)\n ≋⟨d⟩-sym (cons p ps) = cons (PE.sym p) (≋-sym ps)\n\n ≋-sym : ∀ {x y} → x ≋ y → y ≋ x\n ≋-sym (sta p) = sta (≋⟨s⟩-sym p)\n ≋-sym (dyn p) = dyn (≋⟨d⟩-sym p)\n\n mutual\n\n ≋⟨s⟩-trans : ∀ {x y z} → x ≋⟨s⟩ y → y ≋⟨s⟩ z → x ≋⟨s⟩ z\n ≋⟨s⟩-trans (leaf p) (leaf q) = leaf (A.trans p q)\n ≋⟨s⟩-trans (cons p ps) (cons q qs) = cons (A.trans p q) (≋⟨d⟩-trans ps qs)\n\n ≋⟨d⟩-trans : ∀ {x y z} → x ≋⟨d⟩ y → y ≋⟨d⟩ z → x ≋⟨d⟩ z\n ≋⟨d⟩-trans (leaf p) (leaf q) = leaf (PE.trans p q)\n ≋⟨d⟩-trans (cons p ps) (cons q qs) = cons (PE.trans p q) (≋-trans ps qs)\n\n ≋-trans : ∀ {x y z} → x ≋ y → y ≋ z → x ≋ z\n ≋-trans (sta p) (sta q) = sta (≋⟨s⟩-trans p q)\n ≋-trans (dyn p) (dyn q) = dyn (≋⟨d⟩-trans p q)\n\n ≋-isEquivalence : IsEquivalence _≋_\n ≋-isEquivalence = record { refl = ≋-refl\n ; sym = ≋-sym\n ; trans = ≋-trans\n }\n\n Tree/≋ : Setoid _ _\n Tree/≋ = record { Carrier = Tree\n ; _≈_ = _≋_\n ; isEquivalence = ≋-isEquivalence\n }\n\n mutual\n\n _++⟨d⟩_ : DTree → Tree → DTree\n (leaf x) ++⟨d⟩ y = cons x y\n (cons x xs) ++⟨d⟩ y = cons x (xs ++ y)\n\n _++_ : Tree → Tree → Tree\n sta (leaf x) ++ sta (leaf y) = sta (leaf (x · y))\n sta (leaf x) ++ sta (cons y ys) = sta (cons (x · y) ys)\n sta (leaf x) ++ dyn y = sta (cons x y)\n sta (cons x xs) ++ y = sta (cons x (xs ++⟨d⟩ y))\n dyn x ++ y = dyn (x ++⟨d⟩ y)\n\n mutual\n\n ++⟨d⟩-assoc : ∀ x y z → (x ++⟨d⟩ y) ++⟨d⟩ z ≋⟨d⟩ x ++⟨d⟩ (y ++ z)\n ++⟨d⟩-assoc (leaf x) y z = ≋⟨d⟩-refl\n ++⟨d⟩-assoc (cons x xs) y z = cons PE.refl (++-assoc xs y z)\n\n ++-assoc : ∀ x y z → (x ++ y) ++ z ≋ x ++ (y ++ z)\n ++-assoc (sta (leaf x)) (sta (leaf y)) (sta (leaf z)) = sta (leaf (·-assoc x y z))\n ++-assoc (sta (leaf x)) (sta (leaf y)) (sta (cons z zs)) = sta (cons (·-assoc x y z) ≋⟨d⟩-refl)\n ++-assoc (sta (leaf x)) (sta (leaf y)) (dyn z) = ≋-refl\n ++-assoc (sta (leaf x)) (sta (cons y ys)) z = ≋-refl\n ++-assoc (sta (leaf x)) (dyn y) z = ≋-refl\n ++-assoc (sta (cons x xs)) y z = sta (cons A.refl (++⟨d⟩-assoc xs y z))\n ++-assoc (dyn x) y z = dyn (++⟨d⟩-assoc x y z)\n\n mutual\n\n ++⟨d⟩-cong : ∀ {x y z w} → x ≋⟨d⟩ y → z ≋ w → x ++⟨d⟩ z ≋⟨d⟩ y ++⟨d⟩ w\n ++⟨d⟩-cong (leaf p) q = cons p q\n ++⟨d⟩-cong (cons p ps) q = cons p (++-cong ps q)\n\n ++-cong : ∀ {x y z w} → x ≋ y → z ≋ w → x ++ z ≋ y ++ w\n ++-cong (sta (leaf p)) (sta (leaf q)) = sta (leaf (·-cong p q))\n ++-cong (sta (leaf p)) (sta (cons q qs)) = sta (cons (·-cong p q) qs)\n ++-cong (sta (leaf p)) (dyn q) = sta (cons p q)\n ++-cong (sta (cons p ps)) q = sta (cons p (++⟨d⟩-cong ps q))\n ++-cong (dyn p) q = dyn (++⟨d⟩-cong p q)\n\n Tree⟦_⟧ : Interpretation Tree/≋\n Tree⟦ • ⟧ (x ∷ y ∷ []) = x ++ y\n\n Tree⟦_⟧-cong : Congruence Tree/≋ Tree⟦_⟧\n Tree⟦ • ⟧-cong (p ∷ q ∷ []) = ++-cong p q\n\n Tree/≋-isAlgebra : IsAlgebra Tree/≋\n Tree/≋-isAlgebra = record { ⟦_⟧ = Tree⟦_⟧\n ; ⟦⟧-cong = Tree⟦_⟧-cong\n }\n\n Tree/≋-algebra : Algebra\n Tree/≋-algebra = record { ∥_∥/≈ = Tree/≋\n ; ∥_∥/≈-isAlgebra = Tree/≋-isAlgebra\n }\n\n Tree/≋-models : Models Tree/≋-algebra\n Tree/≋-models assoc θ = ++-assoc (θ (# 0)) (θ (# 1)) (θ (# 2))\n\n Tree/≋-isModel : IsModel Tree/≋\n Tree/≋-isModel = record { isAlgebra = Tree/≋-isAlgebra\n ; models = Tree/≋-models\n }\n\n Frex : Model\n Frex = record { ∥_∥/≈ = Tree/≋\n ; isModel = Tree/≋-isModel\n }\n\n ∣inl∣ : ∥ A ∥ → ∥ Frex ∥\n ∣inl∣ x = sta (leaf x)\n\n ∣inl∣-cong : Congruent _≈_ _≋_ ∣inl∣\n ∣inl∣-cong p = sta (leaf p)\n\n ∣inl∣⃗ : ∥ A ∥/≈ ↝ ∥ Frex ∥/≈\n ∣inl∣⃗ = record { ∣_∣ = ∣inl∣\n ; ∣_∣-cong = ∣inl∣-cong\n }\n\n ∣inl∣-hom : Homomorphic ∥ A ∥ₐ ∥ Frex ∥ₐ ∣inl∣\n ∣inl∣-hom • (x ∷ y ∷ []) = ≋-refl\n\n inl : ∥ A ∥ₐ ⟿ ∥ Frex ∥ₐ\n inl = record { ∣_∣⃗ = ∣inl∣⃗\n ; ∣_∣-hom = ∣inl∣-hom\n }\n\n inr : ∥ J n ∥ₐ ⟿ ∥ Frex ∥ₐ\n inr = interp Frex (λ k → dyn (leaf k))\n\n module _ {b ℓ} (X : Model {b} {ℓ}) where\n\n private\n\n open module X = Setoid ∥ X ∥/≈ renaming (_≈_ to _~_)\n\n _⊕_ : ∥ X ∥ → ∥ X ∥ → ∥ X ∥\n x ⊕ y = X ⟦ • ⟧ (x ∷ y ∷ [])\n\n ⊕-cong : ∀ {x y z w} → x ~ y → z ~ w → x ⊕ z ~ y ⊕ w\n ⊕-cong p q = (X ⟦ • ⟧-cong) (p ∷ q ∷ [])\n\n ⊕-assoc : ∀ (x y z : ∥ X ∥) → (x ⊕ y) ⊕ z ~ x ⊕ (y ⊕ z)\n ⊕-assoc x y z = ∥ X ∥ₐ-models assoc (env {A = ∥ X ∥ₐ} (x ∷ y ∷ z ∷ []))\n\n module _\n (f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ)\n (g : ∥ J n ∥ₐ ⟿ ∥ X ∥ₐ)\n where\n\n ∣resid∣ : ∥ Frex ∥ → ∥ X ∥\n ∣resid∣ (sta (leaf x)) = ∣ f ∣ x\n ∣resid∣ (sta (cons x xs)) = ∣ f ∣ x ⊕ ∣resid∣ (dyn xs)\n ∣resid∣ (dyn (leaf x)) = ∣ g ∣ (atom (dyn x))\n ∣resid∣ (dyn (cons x xs)) = ∣ g ∣ (atom (dyn x)) ⊕ ∣resid∣ xs\n\n ∣resid∣-cong : Congruent _≋_ _~_ ∣resid∣\n ∣resid∣-cong (sta (leaf p)) = ∣ f ∣-cong p\n ∣resid∣-cong (sta (cons p ps)) = ⊕-cong (∣ f ∣-cong p) (∣resid∣-cong (dyn ps))\n ∣resid∣-cong (dyn (leaf p)) = ∣ g ∣-cong (inherit (atom (dyn p)))\n ∣resid∣-cong (dyn (cons p ps)) =\n ⊕-cong (∣ g ∣-cong (inherit (atom (dyn p)))) (∣resid∣-cong ps)\n\n open Reasoning ∥ X ∥/≈\n\n ∣resid∣-hom : Homomorphic ∥ Frex ∥ₐ ∥ X ∥ₐ ∣resid∣\n ∣resid∣-hom • (sta (leaf x) ∷ sta (leaf y) ∷ []) = ∣ f ∣-hom • (x ∷ y ∷ [])\n ∣resid∣-hom • (sta (leaf x) ∷ sta (cons y ys) ∷ []) = begin\n ∣ f ∣ x ⊕ (∣ f ∣ y ⊕ ∣resid∣ (dyn ys))\n ≈⟨ X.sym (⊕-assoc (∣ f ∣ x) (∣ f ∣ y) _) ⟩\n (∣ f ∣ x ⊕ ∣ f ∣ y) ⊕ ∣resid∣ (dyn ys)\n ≈⟨ ⊕-cong (∣ f ∣-hom • (x ∷ y ∷ [])) X.refl ⟩\n ∣ f ∣ (x · y) ⊕ ∣resid∣ (dyn ys)\n ∎\n ∣resid∣-hom • (sta (leaf x) ∷ dyn y ∷ []) = X.refl\n ∣resid∣-hom • (sta (cons x xs) ∷ y ∷ []) = begin\n (∣ f ∣ x ⊕ ∣resid∣ (dyn xs)) ⊕ ∣resid∣ y\n ≈⟨ ⊕-assoc (∣ f ∣ x) _ (∣resid∣ y) ⟩\n ∣ f ∣ x ⊕ (∣resid∣ (dyn xs) ⊕ ∣resid∣ y)\n ≈⟨ ⊕-cong X.refl (∣resid∣-hom • (dyn xs ∷ y ∷ [])) ⟩\n ∣ f ∣ x ⊕ ∣resid∣ (dyn xs ++ y)\n ∎\n ∣resid∣-hom • (dyn (leaf x) ∷ y ∷ []) = X.refl\n ∣resid∣-hom • (dyn (cons x xs) ∷ y ∷ []) = begin\n (∣ g ∣ (atom (dyn x)) ⊕ ∣resid∣ xs) ⊕ ∣resid∣ y\n ≈⟨ ⊕-assoc _ (∣resid∣ xs) (∣resid∣ y) ⟩\n ∣ g ∣ (atom (dyn x)) ⊕ (∣resid∣ xs ⊕ ∣resid∣ y)\n ≈⟨ ⊕-cong X.refl (∣resid∣-hom • (xs ∷ y ∷ [])) ⟩\n ∣ g ∣ (atom (dyn x)) ⊕ ∣resid∣ (xs ++ y)\n ∎\n\n ∣resid∣⃗ : ∥ Frex ∥/≈ ↝ ∥ X ∥/≈\n ∣resid∣⃗ = record { ∣_∣ = ∣resid∣\n ; ∣_∣-cong = ∣resid∣-cong\n }\n\n _[_,_] : ∥ Frex ∥ₐ ⟿ ∥ X ∥ₐ\n _[_,_] = record { ∣_∣⃗ = ∣resid∣⃗\n ; ∣_∣-hom = ∣resid∣-hom\n }\n\n module _ {b ℓ} {X : Model {b} {ℓ}} where\n\n private\n\n open module X = Setoid ∥ X ∥/≈ renaming (_≈_ to _~_)\n\n _⊕_ : ∥ X ∥ → ∥ X ∥ → ∥ X ∥\n x ⊕ y = X ⟦ • ⟧ (x ∷ y ∷ [])\n\n ⊕-cong : ∀ {x y z w} → x ~ y → z ~ w → x ⊕ z ~ y ⊕ w\n ⊕-cong p q = (X ⟦ • ⟧-cong) (p ∷ q ∷ [])\n\n ⊕-assoc : ∀ (x y z : ∥ X ∥) → (x ⊕ y) ⊕ z ~ x ⊕ (y ⊕ z)\n ⊕-assoc x y z = ∥ X ∥ₐ-models assoc (env {A = ∥ X ∥ₐ} (x ∷ y ∷ z ∷ []))\n\n module _\n {f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ}\n {g : ∥ J n ∥ₐ ⟿ ∥ X ∥ₐ}\n where\n\n commute₁ : X [ f , g ] ⊙ inl ≗ f\n commute₁ = X.refl\n\n open Reasoning ∥ X ∥/≈\n\n commute₂ : X [ f , g ] ⊙ inr ≗ g\n commute₂ {atom (dyn k)} =\n ∣ X [ f , g ] ∣-cong (≋-refl {x = dyn (leaf k)})\n commute₂ {t@(term • (x ∷ y ∷ []))} = begin\n ∣ X [ f , g ] ∣ (∣ inr ∣ t)\n ≈⟨ ∣ X [ f , g ] ∣-cong (∣ inr ∣-hom • (x ∷ y ∷ [])) ⟩\n ∣ X [ f , g ] ∣ (∣ inr ∣ x ++ ∣ inr ∣ y)\n ≈⟨ X.sym (∣ X [ f , g ] ∣-hom • (∣ inr ∣ x ∷ ∣ inr ∣ y ∷ [])) ⟩\n ∣ X [ f , g ] ∣ (∣ inr ∣ x) ⊕ ∣ X [ f , g ] ∣ (∣ inr ∣ y)\n ≈⟨ ⊕-cong commute₂ commute₂ ⟩\n ∣ g ∣ x ⊕ ∣ g ∣ y\n ≈⟨ ∣ g ∣-hom • (x ∷ y ∷ []) ⟩\n ∣ g ∣ t\n ∎\n\n module _ {h : ∥ Frex ∥ₐ ⟿ ∥ X ∥ₐ}\n (c₁ : h ⊙ inl ≗ f)\n (c₂ : h ⊙ inr ≗ g)\n where\n\n universal : X [ f , g ] ≗ h\n universal {sta (leaf x)} = X.sym c₁\n universal {dyn (leaf x)} = X.sym c₂\n universal {sta (cons x xs)} = begin\n ∣ f ∣ x ⊕ ∣ X [ f , g ] ∣ (dyn xs)\n ≈⟨ ⊕-cong (X.sym c₁) universal ⟩\n ∣ h ∣ (sta (leaf x)) ⊕ ∣ h ∣ (dyn xs)\n ≈⟨ ∣ h ∣-hom • (sta (leaf x) ∷ dyn xs ∷ []) ⟩\n ∣ h ∣ (sta (leaf x) ++ dyn xs)\n ∎\n universal {dyn (cons x xs)} = begin\n ∣ g ∣ (atom (dyn x)) ⊕ ∣ X [ f , g ] ∣ xs\n ≈⟨ ⊕-cong (X.sym c₂) universal ⟩\n ∣ h ∣ (dyn (leaf x)) ⊕ ∣ h ∣ xs\n ≈⟨ ∣ h ∣-hom • (dyn (leaf x) ∷ xs ∷ []) ⟩\n ∣ h ∣ (dyn (leaf x) ++ xs)\n ∎\n\nSemigroupFrex : FreeExtension\nSemigroupFrex = record { _[_] = Frex\n ; _[_]-isFrex = isFrex\n }\n where isFrex : IsFreeExtension Frex\n isFrex A n =\n record { inl = inl A n\n ; inr = inr A n\n ; _[_,_] = _[_,_] A n\n ; commute₁ = λ {_ _ X f g} → commute₁ A n {X = X} {f} {g}\n ; commute₂ = λ {_ _ X f g} → commute₂ A n {X = X} {f} {g}\n ; universal = λ {_ _ X f g h} → universal A n {X = X} {f} {g} {h}\n }\n", "meta": {"hexsha": "f720073db43aca89049faf4e21c7afbb749ada81", "size": 12782, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Fragment/Extensions/Semigroup.agda", "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_issues_repo_path": "src/Fragment/Extensions/Semigroup.agda", "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_forks_repo_path": "src/Fragment/Extensions/Semigroup.agda", "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "avg_line_length": 34.2680965147, "max_line_length": 107, "alphanum_fraction": 0.4039273979, "num_tokens": 5829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.6076631698328916, "lm_q1q2_score": 0.39364311853287776}} {"text": "-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇.\n-- Non-canonical model equipment for Kripke-style semantics.\n\nmodule BasicIS4.Equipment.KripkeDyadicNonCanonical where\n\nopen import BasicIS4.Syntax.Common public\n\n\n\n\nmodule Syntax\n (_⊢_ : Cx² Ty Ty → Ty → Set)\n (mono²⊢ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊢ A → Π′ ⊢ A)\n (up : ∀ {A Π} → Π ⊢ (□ A) → Π ⊢ (□ □ A))\n (down : ∀ {A Π} → Π ⊢ (□ A) → Π ⊢ A)\n (lift : ∀ {A Γ Δ} → (Γ ⁏ Δ) ⊢ A → (□⋆ Γ ⁏ Δ) ⊢ (□ A))\n where\n\n\n -- Worlds.\n\n Worldᶜ : Set\n Worldᶜ = Cx² Ty Ty\n\n\n -- Intuitionistic accessibility.\n\n infix 3 _≤ᶜ_\n _≤ᶜ_ : Worldᶜ → Worldᶜ → Set\n _≤ᶜ_ = _⊆²_\n\n refl≤ᶜ : ∀ {w} → w ≤ᶜ w\n refl≤ᶜ = refl⊆²\n\n trans≤ᶜ : ∀ {w w′ w″} → w ≤ᶜ w′ → w′ ≤ᶜ w″ → w ≤ᶜ w″\n trans≤ᶜ = trans⊆²\n\n bot≤ᶜ : ∀ {w} → ∅² ≤ᶜ w\n bot≤ᶜ = bot⊆²\n\n\n -- Not the canonical modal accessibility, based on the 4 axiom.\n\n infix 3 _Яᶜ_\n _Яᶜ_ : Worldᶜ → Worldᶜ → Set\n w Яᶜ w′ = ∀ {A} → w ⊢ (□ A) → w′ ⊢ (□ □ A)\n\n reflЯᶜ : ∀ {w} → w Яᶜ w\n reflЯᶜ = up\n\n transЯᶜ : ∀ {w w′ w″} → w Яᶜ w′ → w′ Яᶜ w″ → w Яᶜ w″\n transЯᶜ ζ ζ′ = down ∘ ζ′ ∘ ζ\n\n botЯᶜ : ∀ {w} → ∅² Яᶜ w\n botЯᶜ = mono²⊢ bot≤ᶜ ∘ up\n\n liftЯᶜ : ∀ {Γ Δ} → Γ ⁏ Δ Яᶜ □⋆ Γ ⁏ Δ\n liftЯᶜ = down ∘ lift ∘ up\n\n\n -- Composition of accessibility.\n\n infix 3 _≤⨾Яᶜ_\n _≤⨾Яᶜ_ : Worldᶜ → Worldᶜ → Set\n _≤⨾Яᶜ_ = _≤ᶜ_ ⨾ _Яᶜ_\n\n infix 3 _Я⨾≤ᶜ_\n _Я⨾≤ᶜ_ : Worldᶜ → Worldᶜ → Set\n _Я⨾≤ᶜ_ = _Яᶜ_ ⨾ _≤ᶜ_\n\n refl≤⨾Яᶜ : ∀ {w} → w ≤⨾Яᶜ w\n refl≤⨾Яᶜ {w} = w , (refl≤ᶜ , reflЯᶜ)\n\n reflЯ⨾≤ᶜ : ∀ {w} → w Я⨾≤ᶜ w\n reflЯ⨾≤ᶜ {w} = w , (reflЯᶜ , refl≤ᶜ)\n\n\n -- Persistence condition, after Iemhoff; included by Ono.\n --\n -- w′ v′ → v′\n -- ◌───Я───● → ●\n -- │ → ╱\n -- ≤ ξ,ζ → Я\n -- │ → ╱\n -- ● → ●\n -- w → w\n\n ≤⨾Я→Яᶜ : ∀ {v′ w} → w ≤⨾Яᶜ v′ → w Яᶜ v′\n ≤⨾Я→Яᶜ (w′ , (ξ , ζ)) = ζ ∘ mono²⊢ ξ\n\n\n -- Brilliance condition, after Iemhoff.\n --\n -- v′ → v′\n -- ● → ●\n -- │ → ╱\n -- ζ,ξ ≤ → Я\n -- │ → ╱\n -- ●───Я───◌ → ●\n -- w v → w\n\n Я⨾≤→Яᶜ : ∀ {w v′} → w Я⨾≤ᶜ v′ → w Яᶜ v′\n Я⨾≤→Яᶜ (v , (ζ , ξ)) = mono²⊢ ξ ∘ ζ\n\n\n -- Minor persistence condition, included by Božić and Došen.\n --\n -- w′ v′ → v′\n -- ◌───Я───● → ●\n -- │ → │\n -- ≤ ξ,ζ → ≤\n -- │ → │\n -- ● → ●───Я───◌\n -- w → w v\n --\n -- w″ → w″\n -- ● → ●\n -- │ → │\n -- ξ′,ζ′ ≤ → │\n -- │ → │\n -- ●───R───◌ → ≤\n -- │ v′ → │\n -- ξ,ζ ≤ → │\n -- │ → │\n -- ●───R───◌ → ●───────R───────◌\n -- w v → w v″\n\n ≤⨾Я→Я⨾≤ᶜ : ∀ {v′ w} → w ≤⨾Яᶜ v′ → w Я⨾≤ᶜ v′\n ≤⨾Я→Я⨾≤ᶜ {v′} ξ,ζ = v′ , (≤⨾Я→Яᶜ ξ,ζ , refl≤ᶜ)\n\n transЯ⨾≤ᶜ : ∀ {w′ w w″} → w Я⨾≤ᶜ w′ → w′ Я⨾≤ᶜ w″ → w Я⨾≤ᶜ w″\n transЯ⨾≤ᶜ {w′} (v , (ζ , ξ)) (v′ , (ζ′ , ξ′)) = let v″ , (ζ″ , ξ″) = ≤⨾Я→Я⨾≤ᶜ (w′ , (ξ , ζ′))\n in v″ , (transЯᶜ ζ ζ″ , trans≤ᶜ ξ″ ξ′)\n\n ≤→Яᶜ : ∀ {v′ w} → w ≤ᶜ v′ → w Яᶜ v′\n ≤→Яᶜ {v′} ξ = ≤⨾Я→Яᶜ (v′ , (ξ , reflЯᶜ))\n\n\n -- Minor brilliance condition, included by Ewald and Alechina et al.\n --\n -- v′ → w′ v′\n -- ● → ◌───Я───●\n -- │ → │\n -- ζ,ξ ≤ → ≤\n -- │ → │\n -- ●───Я───◌ → ●\n -- w v → w\n --\n -- v′ w″ → v″ w″\n -- ◌───R───● → ◌───────R───────●\n -- │ → │\n -- ≤ ξ′,ζ′ → │\n -- v │ → │\n -- ◌───R───● → ≤\n -- │ w′ → │\n -- ≤ ξ,ζ → │\n -- │ → │\n -- ● → ●\n -- w → w\n\n Я⨾≤→≤⨾Яᶜ : ∀ {w v′} → w Я⨾≤ᶜ v′ → w ≤⨾Яᶜ v′\n Я⨾≤→≤⨾Яᶜ {w} ζ,ξ = w , (refl≤ᶜ , Я⨾≤→Яᶜ ζ,ξ)\n\n trans≤⨾Яᶜ : ∀ {w′ w w″} → w ≤⨾Яᶜ w′ → w′ ≤⨾Яᶜ w″ → w ≤⨾Яᶜ w″\n trans≤⨾Яᶜ {w′} (v , (ξ , ζ)) (v′ , (ξ′ , ζ′)) = let v″ , (ξ″ , ζ″) = Я⨾≤→≤⨾Яᶜ (w′ , (ζ , ξ′))\n in v″ , (trans≤ᶜ ξ ξ″ , transЯᶜ ζ″ ζ′)\n\n ≤→Яᶜ′ : ∀ {w v′} → w ≤ᶜ v′ → w Яᶜ v′\n ≤→Яᶜ′ {w} ξ = Я⨾≤→Яᶜ (w , (reflЯᶜ , ξ))\n\n\n -- Infimum (greatest lower bound) of accessibility.\n --\n -- w′\n -- ●\n -- │\n -- ≤ ξ,ζ\n -- │\n -- ◌───R───●\n -- w v\n\n infix 3 _≤⊓Яᶜ_\n _≤⊓Яᶜ_ : Worldᶜ → Worldᶜ → Set\n _≤⊓Яᶜ_ = _≤ᶜ_ ⊓ _Яᶜ_\n\n infix 3 _Я⊓≤ᶜ_\n _Я⊓≤ᶜ_ : Worldᶜ → Worldᶜ → Set\n _Я⊓≤ᶜ_ = _Яᶜ_ ⊓ _≤ᶜ_\n\n ≤⊓Я→Я⊓≤ᶜ : ∀ {w′ v} → w′ ≤⊓Яᶜ v → v Я⊓≤ᶜ w′\n ≤⊓Я→Я⊓≤ᶜ (w , (ξ , ζ)) = w , (ζ , ξ)\n\n Я⊓≤→≤⊓Яᶜ : ∀ {w′ v} → v Я⊓≤ᶜ w′ → w′ ≤⊓Яᶜ v\n Я⊓≤→≤⊓Яᶜ (w , (ζ , ξ)) = w , (ξ , ζ)\n\n\n -- Supremum (least upper bound) of accessibility.\n --\n -- w′ v′\n -- ●───R───◌\n -- │\n -- ξ,ζ ≤\n -- │\n -- ●\n -- v\n\n infix 3 _≤⊔Яᶜ_\n _≤⊔Яᶜ_ : Worldᶜ → Worldᶜ → Set\n _≤⊔Яᶜ_ = _≤ᶜ_ ⊔ _Яᶜ_\n\n infix 3 _Я⊔≤ᶜ_\n _Я⊔≤ᶜ_ : Worldᶜ → Worldᶜ → Set\n _Я⊔≤ᶜ_ = _Яᶜ_ ⊔ _≤ᶜ_\n\n ≤⊔Я→Я⊔≤ᶜ : ∀ {w′ v} → w′ ≤⊔Яᶜ v → v Я⊔≤ᶜ w′\n ≤⊔Я→Я⊔≤ᶜ (v′ , (ξ , ζ)) = v′ , (ζ , ξ)\n\n Я⊔≤→≤⊔Яᶜ : ∀ {w′ v} → v Я⊔≤ᶜ w′ → w′ ≤⊔Яᶜ v\n Я⊔≤→≤⊔Яᶜ (v′ , (ζ , ξ)) = v′ , (ξ , ζ)\n\n\n -- Infimum-to-supremum condition, included by Ewald.\n --\n -- w′ → w′ v′\n -- ● → ●───Я───◌\n -- │ → │\n -- ≤ ξ,ζ → ≤\n -- │ → │\n -- ◌───Я───● → ●\n -- w v → v\n\n -- NOTE: This could be more precise.\n ≤⊓Я→≤⊔Яᶜ : ∀ {v w′} → w′ ≤⊓Яᶜ v → v ≤⊔Яᶜ w′\n ≤⊓Я→≤⊔Яᶜ {v} {w′} (w , (ξ , ζ)) =\n (w′ ⧺² v) , (weak⊆²⧺₂ , mono²⊢ (weak⊆²⧺₁ v) ∘ up)\n\n\n -- Supremum-to-infimum condition.\n --\n -- w′ v′ → w′\n -- ●───Я───◌ → ●\n -- │ → │\n -- ξ,ζ ≤ → ≤\n -- │ → │\n -- ● → ◌───Я───●\n -- v → w v\n\n -- NOTE: This could be more precise.\n ≤⊔Я→≤⊓Яᶜ : ∀ {w′ v} → v ≤⊔Яᶜ w′ → w′ ≤⊓Яᶜ v\n ≤⊔Я→≤⊓Яᶜ (v′ , (ξ , ζ)) = ∅² , (bot≤ᶜ , botЯᶜ)\n", "meta": {"hexsha": "678865a48df5f008bd1c2447150944b73d207691", "size": 6411, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BasicIS4/Equipment/KripkeDyadicNonCanonical.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/Equipment/KripkeDyadicNonCanonical.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/Equipment/KripkeDyadicNonCanonical.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": 25.5418326693, "max_line_length": 95, "alphanum_fraction": 0.2912182187, "num_tokens": 3738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702880639791, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3935054644526113}} {"text": "{-# OPTIONS --allow-unsolved-metas #-} \nopen import Level\nopen import Ordinals\nmodule ODUtil {n : Level } (O : Ordinals {n} ) where\n\nopen import zf\nopen import Data.Nat renaming ( zero to Zero ; suc to Suc ; ℕ to Nat ; _⊔_ to _n⊔_ ) \nopen import Relation.Binary.PropositionalEquality hiding ( [_] )\nopen import Data.Nat.Properties \nopen import Data.Empty\nopen import Relation.Nullary\nopen import Relation.Binary hiding ( _⇔_ )\n\nopen import logic\nopen import nat\n\nopen Ordinals.Ordinals O\nopen Ordinals.IsOrdinals isOrdinal\nopen Ordinals.IsNext isNext\nimport OrdUtil\nopen OrdUtil O\n\nimport OD\nopen OD O\nopen OD.OD\nopen ODAxiom odAxiom\n\nopen HOD\nopen _⊆_\nopen _∧_\nopen _==_\n\ncseq : HOD → HOD \ncseq x = record { od = record { def = λ y → odef x (osuc y) } ; odmax = osuc (odmax x) ; ¬a ¬b c | record { eq = eq1 } = next< (subst (λ k → k o< next o ) (sym eq1) (osucz → subst (λ k → def (od y) k ) &iso (incl lt (d→∋ x x>z)))\n\nsubset-lemma : {A x : HOD } → ( {y : HOD } → x ∋ y → (A ∩ x ) ∋ y ) ⇔ ( x ⊆ A )\nsubset-lemma {A} {x} = record {\n proj1 = λ lt → record { incl = λ x∋z → proj1 (lt x∋z) }\n ; proj2 = λ x⊆A lt → ⟪ incl x⊆A lt , lt ⟫\n } \n\n\nω (c<→o< {* y} {* u} (proj2 t)) (subst₂ (λ j k → j o< k )\n (trans (sym &iso) (trans (sym u=x) (sym &iso)) ) (sym &iso) x ¬a ¬b c = ⊥-elim (ω-prev-eq1 (sym eq) c)\n\nω-∈s : (x : HOD) → Union ( x , (x , x)) ∋ x\nω-∈s x not = not (& (x , x)) ⟪ case2 refl , subst (λ k → odef k (& x) ) (sym *iso) (case1 refl) ⟫\n\nωs≠0 : (x : HOD) → ¬ ( Union ( x , (x , x)) ≡ od∅ )\nωs≠0 y eq = ⊥-elim ( ¬x<0 (subst (λ k → & y o< k ) ord-od∅ (c<→o< (subst (λ k → odef k (& y )) eq (ω-∈s y) ))) )\n\nnat→ω-iso : {i : HOD} → (lt : infinite ∋ i ) → nat→ω ( ω→nat i lt ) ≡ i\nnat→ω-iso {i} = ε-induction {λ i → (lt : infinite ∋ i ) → nat→ω ( ω→nat i lt ) ≡ i } ind i where\n ind : {x : HOD} → ({y : HOD} → x ∋ y → (lt : infinite ∋ y) → nat→ω (ω→nat y lt) ≡ y) →\n (lt : infinite ∋ x) → nat→ω (ω→nat x lt) ≡ x\n ind {x} prev lt = ind1 lt *iso where\n ind1 : {ox : Ordinal } → (ltd : infinite-d ox ) → * ox ≡ x → nat→ω (ω→nato ltd) ≡ x\n ind1 {o∅} iφ refl = sym o∅≡od∅\n ind1 (isuc {x₁} ltd) ox=x = begin\n nat→ω (ω→nato (isuc ltd) ) \n ≡⟨⟩\n Union (nat→ω (ω→nato ltd) , (nat→ω (ω→nato ltd) , nat→ω (ω→nato ltd)))\n ≡⟨ cong (λ k → Union (k , (k , k ))) lemma ⟩\n Union (* x₁ , (* x₁ , * x₁))\n ≡⟨ trans ( sym *iso) ox=x ⟩\n x \n ∎ where\n open ≡-Reasoning \n lemma0 : x ∋ * x₁\n lemma0 = subst (λ k → odef k (& (* x₁))) (trans (sym *iso) ox=x) (λ not → not \n (& (* x₁ , * x₁)) ⟪ pair2 , subst (λ k → odef k (& (* x₁))) (sym *iso) pair1 ⟫ )\n lemma1 : infinite ∋ * x₁\n lemma1 = subst (λ k → odef infinite k) (sym &iso) ltd\n lemma3 : {x y : Ordinal} → (ltd : infinite-d x ) (ltd1 : infinite-d y ) → y ≡ x → ltd ≅ ltd1\n lemma3 iφ iφ refl = HE.refl\n lemma3 iφ (isuc {y} ltd1) eq = ⊥-elim ( ¬x<0 (subst₂ (λ j k → j o< k ) &iso eq (c<→o< (ω-∈s (* y)) )))\n lemma3 (isuc {y} ltd) iφ eq = ⊥-elim ( ¬x<0 (subst₂ (λ j k → j o< k ) &iso (sym eq) (c<→o< (ω-∈s (* y)) )))\n lemma3 (isuc {x} ltd) (isuc {y} ltd1) eq with lemma3 ltd ltd1 (ω-prev-eq (sym eq))\n ... | t = HE.cong₂ (λ j k → isuc {j} k ) (HE.≡-to-≅ (ω-prev-eq eq)) t \n lemma2 : {x y : Ordinal} → (ltd : infinite-d x ) (ltd1 : infinite-d y ) → y ≡ x → ω→nato ltd ≡ ω→nato ltd1\n lemma2 {x} {y} ltd ltd1 eq = lemma6 eq (lemma3 {x} {y} ltd ltd1 eq) where\n lemma6 : {x y : Ordinal} → {ltd : infinite-d x } {ltd1 : infinite-d y } → y ≡ x → ltd ≅ ltd1 → ω→nato ltd ≡ ω→nato ltd1\n lemma6 refl HE.refl = refl\n lemma : nat→ω (ω→nato ltd) ≡ * x₁\n lemma = trans (cong (λ k → nat→ω k) (lemma2 {x₁} {_} ltd (subst (λ k → infinite-d k ) (sym &iso) ltd) &iso ) ) ( prev {* x₁} lemma0 lemma1 )\n\nω→nat-iso : {i : Nat} → ω→nat ( nat→ω i ) (ω∋nat→ω {i}) ≡ i\nω→nat-iso {i} = lemma i (ω∋nat→ω {i}) *iso where\n lemma : {x : Ordinal } → ( i : Nat ) → (ltd : infinite-d x ) → * x ≡ nat→ω i → ω→nato ltd ≡ i\n lemma {x} Zero iφ eq = refl\n lemma {x} (Suc i) iφ eq = ⊥-elim ( ωs≠0 (nat→ω i) (trans (sym eq) o∅≡od∅ )) -- Union (nat→ω i , (nat→ω i , nat→ω i)) ≡ od∅\n lemma Zero (isuc {x} ltd) eq = ⊥-elim ( ωs≠0 (* x) (subst (λ k → k ≡ od∅ ) *iso eq ))\n lemma (Suc i) (isuc {x} ltd) eq = cong (λ k → Suc k ) (lemma i ltd (lemma1 eq) ) where -- * x ≡ nat→ω i\n lemma1 : * (& (Union (* x , (* x , * x)))) ≡ Union (nat→ω i , (nat→ω i , nat→ω i)) → * x ≡ nat→ω i\n lemma1 eq = subst (λ k → * x ≡ k ) *iso (cong (λ k → * k)\n ( ω-prev-eq (subst (λ k → _ ≡ k ) &iso (cong (λ k → & k ) (sym\n (subst (λ k → _ ≡ Union ( k , ( k , k ))) (sym *iso ) eq ))))))\n\n", "meta": {"hexsha": "f2201ab226fc431f31e91b94ebab871b10912796", "size": 8807, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/ODUtil.agda", "max_stars_repo_name": "shinji-kono/zf-in-agda", "max_stars_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-10-02T13:46:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-10T13:27:48.000Z", "max_issues_repo_path": "src/ODUtil.agda", "max_issues_repo_name": "shinji-kono/zf-in-agda", "max_issues_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "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/ODUtil.agda", "max_forks_repo_name": "shinji-kono/zf-in-agda", "max_forks_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "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.9277777778, "max_line_length": 159, "alphanum_fraction": 0.4753037357, "num_tokens": 3838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389817407016, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.39345141380947707}} {"text": "{-# OPTIONS --rewriting --prop --confluence-check #-}\n\nopen import Agda.Primitive\nopen import Agda.Builtin.Bool\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Equality.Rewrite\nopen import Agda.Builtin.Sigma\nopen import Agda.Builtin.Unit\nopen import Data.Vec.Base\nopen import Data.Bool\nopen import Data.Sum\n\nvariable ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level\n\n{- \n Axiomatisation of ExTT\n-}\n\npostulate raise : (A : Set ℓ) → A\n\n-- we now state rewrite rules for raise\n\npostulate raise-Pi : (A : Set ℓ) (B : A → Set ℓ₁) →\n raise ((a : A) → B a) ≡ λ a → raise (B a)\n\n{-# REWRITE raise-Pi #-}\n\npostulate raise-Sigma : (A : Set ℓ) (B : A → Set ℓ₁) →\n raise (Σ A B) ≡ (raise A , raise (B (raise A)))\n\n{-# REWRITE raise-Sigma #-}\n\nnat-rec : (P : Nat → Set ℓ) (P0 : P 0) (PS : (n : Nat) → P n → P (suc n)) → (n : Nat) → P n \nnat-rec P P0 PS zero = P0\nnat-rec P P0 PS (suc n) = PS n (nat-rec P P0 PS n)\n\npostulate raise-nat-rec : (P : Nat → Set ℓ) (P0 : P 0) (PS : (n : Nat) → P n → P (suc n)) →\n nat-rec P P0 PS (raise Nat) ≡ raise (P (raise Nat))\n \n{-# REWRITE raise-nat-rec #-}\n\npostulate catch-nat : (P : Nat → Set ℓ) (P0 : P 0) (PS : (n : Nat) → P n → P (suc n)) →\n (Praise : P (raise Nat)) → (n : Nat) → P n \n\npostulate catch-nat-zero : (P : Nat → Set ℓ) (P0 : P 0) (PS : (n : Nat) → P n → P (suc n)) →\n (Praise : P (raise Nat)) → catch-nat P P0 PS Praise 0 ≡ P0\n\npostulate catch-nat-suc : (P : Nat → Set ℓ) (P0 : P 0) (PS : (n : Nat) → P n → P (suc n)) →\n (Praise : P (raise Nat)) → (n : Nat) →\n catch-nat P P0 PS Praise (suc n) ≡ PS n (catch-nat P P0 PS Praise n)\n\npostulate catch-nat-raise : (P : Nat → Set ℓ) (P0 : P 0) (PS : (n : Nat) → P n → P (suc n)) →\n (Praise : P (raise Nat)) → catch-nat P P0 PS Praise (raise Nat) ≡ Praise\n\n{-# REWRITE catch-nat-zero #-}\n{-# REWRITE catch-nat-suc #-}\n{-# REWRITE catch-nat-raise #-}\n\nrecord Unk ℓ : Set (lsuc ℓ) where\n constructor box\n field\n type : Set ℓ\n elem : type\n\npostulate raise-Unk : ∀ ℓ → raise (Unk ℓ) ≡ box (raise (Set ℓ)) (raise _)\n\n{-# REWRITE raise-Unk #-}\n\n", "meta": {"hexsha": "c2b923af194b56e7dbda99101998847720c54cc8", "size": 2278, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-rr/ett-rr.agda", "max_stars_repo_name": "kyoDralliam/exceptional-tt", "max_stars_repo_head_hexsha": "77e54713836af48f5f8091373ae888feadc3d077", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "agda-rr/ett-rr.agda", "max_issues_repo_name": "kyoDralliam/exceptional-tt", "max_issues_repo_head_hexsha": "77e54713836af48f5f8091373ae888feadc3d077", "max_issues_repo_licenses": ["WTFPL"], "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-rr/ett-rr.agda", "max_forks_repo_name": "kyoDralliam/exceptional-tt", "max_forks_repo_head_hexsha": "77e54713836af48f5f8091373ae888feadc3d077", "max_forks_repo_licenses": ["WTFPL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0845070423, "max_line_length": 100, "alphanum_fraction": 0.5425812116, "num_tokens": 816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.39338205319721986}} {"text": "------------------------------------------------------------------------\n-- Up-to techniques for the standard coinductive definition of weak\n-- bisimilarity\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nopen import Labelled-transition-system\n\nmodule Bisimilarity.Weak.Up-to {ℓ} (lts : LTS ℓ) where\n\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude\nopen import Prelude.Size\n\nopen import Bisimilarity.Weak lts\nimport Bisimilarity.Weak.Equational-reasoning-instances\nopen import Equational-reasoning\nopen import Expansion lts as E using (Expansion; _≲_; ≳:_)\nimport Expansion.Equational-reasoning-instances\nopen import Indexed-container\nopen import Relation\nimport Similarity.Weak lts as S\nimport Up-to\n\nopen LTS lts\n\nimport Similarity.Step lts _[_]⇒̂_ as SS\n\n------------------------------------------------------------------------\n-- The general up-to machinery, instantiated with the StepC container\n\nopen Up-to StepC public\n\n------------------------------------------------------------------------\n-- Up to expansion\n\n-- Up to expansion.\n--\n-- I took this definition from \"Enhancements of the bisimulation proof\n-- method\" by Pous and Sangiorgi.\n\nUp-to-expansion : Trans₂ ℓ Proc\nUp-to-expansion R = Expansion ∞ ⊙ R ⊙ Expansion ∞ ⁻¹\n\n-- Up to expansion is monotone.\n\nup-to-expansion-monotone : Monotone Up-to-expansion\nup-to-expansion-monotone R⊆S =\n Σ-map id (Σ-map id (Σ-map id (Σ-map R⊆S id)))\n\n-- Up to expansion is size-preserving.\n\nup-to-expansion-size-preserving : Size-preserving Up-to-expansion\nup-to-expansion-size-preserving =\n _⇔_.from (monotone→⇔ up-to-expansion-monotone)\n (λ where\n {x = p , q} (r , p≳r , s , r≈s , s≲q) →\n p ∼⟨ p≳r ⟩\n r ∼′⟨ r≈s ⟩ ≳:\n s ∽⟨ s≲q ⟩■\n q)\n\n------------------------------------------------------------------------\n-- A generalisation of up to expansion\n\nmutual\n\n -- A monolithic implementation of a non-symmetric variant of up to\n -- expansion, based on the technique presented in Section 6.5.2.4 of\n -- \"Enhancements of the bisimulation proof method\" by Pous and\n -- Sangiorgi.\n --\n -- It is at the time of writing not clear to me if there is some\n -- size-preserving proof that matches this technique.\n\n 6-5-2-4 :\n {R : Rel₂ ℓ Proc} →\n (∀ {P P′ Q μ} →\n R (P , Q) → P [ μ ]⟶ P′ →\n ∃ λ Q′ → Q [ μ ]⇒̂ Q′ ×\n (Expansion ∞ ⊙ R ⊙ Weak-bisimilarity ∞) (P′ , Q′)) →\n (∀ {P Q Q′ μ} →\n R (P , Q) → Q [ μ ]⟶ Q′ →\n ∃ λ P′ → P [ μ ]⇒̂ P′ ×\n (Weak-bisimilarity ∞ ⊙ R ⊙ Expansion ∞ ⁻¹) (P′ , Q′)) →\n R ⊆ Weak-bisimilarity ∞\n 6-5-2-4 {R} lr⟶ rl⟶ =\n 6-5-2-4′ (λ PRQ → S.⟨ lr⟶ PRQ ⟩)\n (λ PR⁻¹Q → S.⟨ Σ-map id (Σ-map id lemma) ∘ rl⟶ PR⁻¹Q ⟩)\n where\n lemma :\n Weak-bisimilarity ∞ ⊙ R ⊙ Expansion ∞ ⁻¹ ⊆\n (Expansion ∞ ⊙ R ⁻¹ ⊙ Weak-bisimilarity ∞) ⁻¹\n lemma (_ , P₁≈P₂ , _ , P₂RP₃ , P₃≲P₄) =\n (_ , P₃≲P₄ , _ , P₂RP₃ , symmetric P₁≈P₂)\n\n -- A variant of 6-5-2-4.\n\n 6-5-2-4′ :\n let Prog = λ (R : Rel₂ ℓ Proc) →\n R ⊆ ⟦ S.StepC ⟧ (Expansion ∞ ⊙ R ⊙ Weak-bisimilarity ∞) in\n ∀ {R} → Prog R → Prog (R ⁻¹) → R ⊆ Weak-bisimilarity ∞\n 6-5-2-4′ {R} lr⟶ rl⟶ =\n R ⊆⟨ ⊆≈≈ ⟩\n ≈ R ≈ ⊆⟨ unfold _ (λ P≈R≈Q →\n StepC.⟨ SS.Step.challenge (lemma lr⟶ P≈R≈Q)\n , Σ-map id (Σ-map id ≈≈-sym) ∘\n SS.Step.challenge (lemma rl⟶ (≈≈-sym P≈R≈Q))\n ⟩) ⟩∎\n Weak-bisimilarity ∞ ∎\n where\n ≈_≈ : Rel₂ ℓ Proc → Rel₂ ℓ Proc\n ≈ R ≈ = Weak-bisimilarity ∞ ⊙ R ⊙ Weak-bisimilarity ∞\n\n ⊆≈≈ : ∀ {R} → R ⊆ ≈ R ≈\n ⊆≈≈ r = _ , reflexive , _ , r , reflexive\n\n ≳_≈ : Rel₂ ℓ Proc → Rel₂ ℓ Proc\n ≳ R ≈ = Expansion ∞ ⊙ R ⊙ Weak-bisimilarity ∞\n\n ⊆≳≈ : ∀ {R} → R ⊆ ≳ R ≈\n ⊆≳≈ r = _ , reflexive , _ , r , reflexive\n\n ≈≈-sym : ∀ {R} → ≈ R ≈ ⊆ ≈ R ⁻¹ ≈ ⁻¹\n ≈≈-sym (_ , P₁≈P₂ , _ , P₂RP₃ , P₃≈P₄) =\n (_ , symmetric P₃≈P₄ , _ , P₂RP₃ , symmetric P₁≈P₂)\n\n lemma : ∀ {R} → R ⊆ ⟦ S.StepC ⟧ ≳ R ≈ → ≈ R ≈ ⊆ SS.Step ≈ R ≈\n lemma {R} lr⟶ = λ where\n (P₁ , P≈P₁ , Q₁ , P₁RQ₁ , Q₁≈Q) .SS.Step.challenge P⟶P₁ →\n let P₁′ , P₁⟶̂P₁′ , P′≈′P₁′ = left-to-right P≈P₁ P⟶P₁\n Q₁′ , Q₁⇒̂Q₁′ , P₁″ ,\n P₁′≳P₁″ , Q₁″ ,\n P₁″RQ₁″ , Q₁″≈Q₁′ = lr≳≈⇒̂ (⊆≳≈ P₁RQ₁) P₁⟶̂P₁′\n Q′ , Q⇒̂Q′ , Q₁′≈Q′ = weak-is-weak⇒̂ Q₁≈Q Q₁⇒̂Q₁′\n in Q′ , Q⇒̂Q′ , P₁″\n , transitive′ {a = ℓ} (force P′≈′P₁′) P₁′≳P₁″\n , Q₁″ , P₁″RQ₁″ , transitive {a = ℓ} Q₁″≈Q₁′ Q₁′≈Q′\n where\n lr⟶̂ :\n ∀ {P P′ Q μ} →\n R (P , Q) → P [ μ ]⟶̂ P′ → ∃ λ Q′ → Q [ μ ]⇒̂ Q′ × ≳ R ≈ (P′ , Q′)\n lr⟶̂ PRQ (done s) = _ , silent s done , ⊆≳≈ PRQ\n lr⟶̂ PRQ (step P⟶P′) = S.challenge (lr⟶ PRQ) P⟶P′\n\n lr≳≈⟶ :\n ∀ {P P′ Q μ} →\n ≳ R ≈ (P , Q) → P [ μ ]⟶ P′ →\n ∃ λ Q′ → Q [ μ ]⇒̂ Q′ × ≳ R ≈ (P′ , Q′)\n lr≳≈⟶ (P₁ , P≳P₁ , Q₁ , P₁RQ₁ , Q₁≈Q) P⟶P′ =\n let P₁′ , P₁⟶̂P₁′ , P′≳P₁′ = E.left-to-right P≳P₁ P⟶P′\n Q₁′ , Q₁⇒̂Q₁′ , P₁″ , P₁′≳P₁″ ,\n Q₁″ , P₁″RQ₁″ , Q₁″≈Q₁′ = lr⟶̂ P₁RQ₁ P₁⟶̂P₁′\n Q′ , Q⇒̂Q′ , Q₁′≈Q′ = weak-is-weak⇒̂ Q₁≈Q Q₁⇒̂Q₁′\n in Q′ , Q⇒̂Q′ ,\n P₁″ , transitive {a = ℓ} P′≳P₁′ P₁′≳P₁″ ,\n Q₁″ , P₁″RQ₁″ , transitive {a = ℓ} Q₁″≈Q₁′ Q₁′≈Q′\n\n lr≳≈⇒ :\n ∀ {P P′ Q} →\n ≳ R ≈ (P , Q) → P ⇒ P′ → ∃ λ Q′ → Q ⇒ Q′ × ≳ R ≈ (P′ , Q′)\n lr≳≈⇒ P≳R≈Q done = _ , done , P≳R≈Q\n lr≳≈⇒ P≳R≈Q (step s P⟶P′ P′⇒P″) =\n let Q′ , Q⇒̂Q′ , P′≳R≈Q′ = lr≳≈⟶ P≳R≈Q P⟶P′\n Q″ , Q′⇒Q″ , P″≳R≈Q″ = lr≳≈⇒ P′≳R≈Q′ P′⇒P″\n in Q″ , ⇒-transitive (⇒̂→⇒ s Q⇒̂Q′) Q′⇒Q″ , P″≳R≈Q″\n\n lr≳≈[]⇒ :\n ∀ {P P′ Q μ} →\n ¬ Silent μ →\n ≳ R ≈ (P , Q) → P [ μ ]⇒ P′ →\n ∃ λ Q′ → Q [ μ ]⇒ Q′ × ≳ R ≈ (P′ , Q′)\n lr≳≈[]⇒ ¬s P≳R≈Q (steps P⇒P′ P′⟶P″ P″⇒P‴) =\n let Q′ , Q⇒Q′ , P′≳R≈Q′ = lr≳≈⇒ P≳R≈Q P⇒P′\n Q″ , Q′⇒̂Q″ , P″≳R≈Q″ = lr≳≈⟶ P′≳R≈Q′ P′⟶P″\n Q‴ , Q″⇒Q‴ , P‴≳R≈Q‴ = lr≳≈⇒ P″≳R≈Q″ P″⇒P‴\n in Q‴\n , []⇒⇒-transitive (⇒[]⇒-transitive Q⇒Q′ (⇒̂→[]⇒ ¬s Q′⇒̂Q″)) Q″⇒Q‴\n , P‴≳R≈Q‴\n\n lr≳≈⇒̂ :\n ∀ {P P′ Q μ} →\n ≳ R ≈ (P , Q) → P [ μ ]⇒̂ P′ →\n ∃ λ Q′ → Q [ μ ]⇒̂ Q′ × ≳ R ≈ (P′ , Q′)\n lr≳≈⇒̂ PRQ = λ where\n (silent s P⇒P′) → Σ-map id (Σ-map (silent s) id)\n (lr≳≈⇒ PRQ P⇒P′)\n (non-silent ¬s P⇒P′) → Σ-map id (Σ-map (non-silent ¬s) id)\n (lr≳≈[]⇒ ¬s PRQ P⇒P′)\n\n------------------------------------------------------------------------\n-- Up to weak bisimilarity\n\n-- Up to weak bisimilarity.\n--\n-- I based this definition on Definition 4.2.13 in Milner's\n-- \"Operational and Algebraic Semantics of Concurrent Processes\".\n\nUp-to-weak-bisimilarity : Trans₂ ℓ Proc\nUp-to-weak-bisimilarity R =\n Weak-bisimilarity ∞ ⊙ R ⊙ Weak-bisimilarity ∞\n\n-- Up to weak bisimilarity is monotone.\n\nup-to-weak-bisimilarity-monotone : Monotone Up-to-weak-bisimilarity\nup-to-weak-bisimilarity-monotone R⊆S =\n Σ-map id (Σ-map id (Σ-map id (Σ-map R⊆S id)))\n\n-- If transitivity of weak bisimilarity is size-preserving in the\n-- first argument, then \"up to weak bisimilarity\" is size-preserving.\n\nsize-preserving-transitivity→up-to-weak-bisimilarity-size-preserving :\n (∀ {i x y z} → [ i ] x ≈ y → [ ∞ ] y ≈ z → [ i ] x ≈ z) →\n Size-preserving Up-to-weak-bisimilarity\nsize-preserving-transitivity→up-to-weak-bisimilarity-size-preserving\n trans =\n _⇔_.from (monotone→⇔ up-to-weak-bisimilarity-monotone) λ where\n {x = p , q} (r , p≈r , s , r≈s , s≈q) →\n p ≈∞⟨ p≈r ⟩\n r ≈⟨ r≈s ⟩∞\n s ∼⟨ s≈q ⟩■\n q\n where\n infixr -2 _≈⟨_⟩∞_ _≈∞⟨_⟩_\n\n _≈⟨_⟩∞_ : ∀ {i} x {y z} → [ i ] x ≈ y → [ ∞ ] y ≈ z → [ i ] x ≈ z\n _ ≈⟨ p ⟩∞ q = trans p q\n\n _≈∞⟨_⟩_ : ∀ {i} x {y z} → [ ∞ ] x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z\n _ ≈∞⟨ p ⟩ q = symmetric (trans (symmetric q) (symmetric p))\n\n-- If transitivity of weak bisimilarity is size-preserving in both\n-- arguments, then weak bisimulations up to weak bisimilarity are\n-- contained in weak bisimilarity.\n\nsize-preserving-transitivity→up-to-weak-bisimilarity-up-to :\n (∀ {i x y z} → [ i ] x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z) →\n Up-to-technique Up-to-weak-bisimilarity\nsize-preserving-transitivity→up-to-weak-bisimilarity-up-to =\n size-preserving→up-to ∘\n size-preserving-transitivity→up-to-weak-bisimilarity-size-preserving\n", "meta": {"hexsha": "5e574ef391ab29ed216d5e6a07a26934398ae1c9", "size": 8598, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Bisimilarity/Weak/Up-to.agda", "max_stars_repo_name": "nad/up-to", "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Bisimilarity/Weak/Up-to.agda", "max_issues_repo_name": "nad/up-to", "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Bisimilarity/Weak/Up-to.agda", "max_forks_repo_name": "nad/up-to", "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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.3827160494, "max_line_length": 94, "alphanum_fraction": 0.4672016748, "num_tokens": 3867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.39338205319721986}} {"text": "{-# OPTIONS --without-K --safe --overlapping-instances #-}\n\n\n-- Reference to check out\n--\n-- Simply Typed Lambda Calculus in Agda, without Shortcuts\n-- https://gergo.erdi.hu/blog/2013-05-01-simply_typed_lambda_calculus_in_agda,_without_shortcuts/\n\n\nmodule InterpreterWithConstants where\n\nopen import Data.Char hiding (_≤_)\nopen import Data.Bool hiding (_≤_)\nopen import Data.Nat hiding (_≤_)\nopen import Data.Unit\nimport Data.Nat as N\nopen import Data.Product\nopen import Data.Sum\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Nullary\nimport Data.String as Str\nopen import Data.Nat.Show\nimport Data.List as List\nopen import Data.Empty\n\ninfix 3 _:::_,_\ninfix 2 _∈_\ninfix 2 _∉_\n\ninfix 1 _⊢_\n\ndata `Set : Set where\n `Bool : `Set\n _`⇨_ : `Set → `Set → `Set\n `⊤ : `Set\n _`×_ : `Set → `Set → `Set\ninfixr 2 _`⇨_\n\ndata Var : Set where\n x' : Var\n y' : Var\n z' : Var\n\n-- Inequality proofs on variables\ndata _≠_ : Var → Var → Set where\n x≠y : x' ≠ y'\n x≠z : x' ≠ z'\n y≠x : y' ≠ x'\n y≠z : y' ≠ z'\n z≠x : z' ≠ x'\n z≠y : z' ≠ y'\n\ninstance\n xy : x' ≠ y'\n xy = x≠y\n\n xz : x' ≠ z'\n xz = x≠z\n\n yx : y' ≠ x'\n yx = y≠x\n\n yz : y' ≠ z'\n yz = y≠z\n\n zx : z' ≠ x'\n zx = z≠x\n\n zy : z' ≠ y'\n zy = z≠y\n\n⟦_⟧ : `Set → Set\n⟦ `Bool ⟧ = Bool\n⟦ (t `⇨ s) ⟧ = ⟦ t ⟧ → ⟦ s ⟧\n⟦ `⊤ ⟧ = ⊤\n⟦ (t `× s) ⟧ = ⟦ t ⟧ × ⟦ s ⟧\n\ndata Γ : Set where\n · : Γ\n _:::_,_ : Var → `Set → Γ → Γ\n\ndata _∈_ : Var → Γ → Set where\n H : ∀ {x Δ t } → x ∈ x ::: t , Δ\n TH : ∀ {x y Δ t} → ⦃ prf : x ∈ Δ ⦄ → ⦃ neprf : x ≠ y ⦄ → x ∈ y ::: t , Δ\n\ninstance\n ∈_type₁ : ∀ {x Δ t} → x ∈ x ::: t , Δ\n ∈_type₁ = H\n\n ∈_type₂ : ∀ {x y Δ t} → ⦃ prf : x ∈ Δ ⦄ → ⦃ x ≠ y ⦄ → x ∈ y ::: t , Δ\n ∈_type₂ = TH\n\ndata _∉_ : Var → Γ → Set where\n H : ∀ {x} → x ∉ ·\n TH : ∀ {x y Δ t} → ⦃ prf : x ∉ Δ ⦄ → ⦃ neprf : x ≠ y ⦄ → x ∉ y ::: t , Δ\n\ninstance\n ∉_type₁ : ∀ {x} → x ∉ ·\n ∉_type₁ = H\n\n ∉_type₂ : ∀ {x y Δ t} → ⦃ prf : x ∉ Δ ⦄ → ⦃ x ≠ y ⦄ → x ∉ y ::: t , Δ\n ∉_type₂ = TH\n\n!Γ_[_] : ∀ {x} → (Δ : Γ) → x ∈ Δ → `Set\n!Γ_[_] · ()\n!Γ _ ::: t , Δ [ H ] = t\n!Γ _ ::: _ , Δ [ TH ⦃ prf = i ⦄ ] = !Γ Δ [ i ]\n\n\ninfix 30 `v_\ninfix 30 `c_\n\ninfix 24 _`,_\ninfixl 22 _`₋_\n\ndata Constant : `Set → Set where\n `not : Constant (`Bool `⇨ `Bool)\n `∧ : Constant (`Bool `× `Bool `⇨ `Bool)\n `∨ : Constant (`Bool `× `Bool `⇨ `Bool)\n `xor : Constant (`Bool `× `Bool `⇨ `Bool)\n\ndata _⊢_ : Γ → `Set → Set where\n `false : ∀ {Δ} → Δ ⊢ `Bool\n `true : ∀ {Δ} → Δ ⊢ `Bool\n `v_ : ∀ {Δ} → (x : Var) → ⦃ i : x ∈ Δ ⦄ → Δ ⊢ !Γ Δ [ i ]\n `c_ : ∀ {Δ t} → Constant t → Δ ⊢ t\n _`₋_ : ∀ {Δ t s} → Δ ⊢ t `⇨ s → Δ ⊢ t → Δ ⊢ s --application\n `λ_`:_⇨_ : ∀ {Δ tr} → (x : Var) → (tx : `Set)\n → x ::: tx , Δ ⊢ tr → Δ ⊢ tx `⇨ tr\n\n _`,_ : ∀ {Δ t s} → Δ ⊢ t → Δ ⊢ s → Δ ⊢ t `× s\n `fst : ∀ {Δ t s} → Δ ⊢ t `× s → Δ ⊢ t\n `snd : ∀ {Δ t s} → Δ ⊢ t `× s → Δ ⊢ s\n `tt : ∀ {Δ} → Δ ⊢ `⊤\n\ndata ⟨_⟩ : Γ → Set₁ where\n [] : ⟨ · ⟩\n _∷_ : ∀ {x t Δ} → ⟦ t ⟧ → ⟨ Δ ⟩ → ⟨ x ::: t , Δ ⟩\n\n!_[_] : ∀ {x Δ} → ⟨ Δ ⟩ → (i : x ∈ Δ) → ⟦ !Γ Δ [ i ] ⟧\n!_[_] [] ()\n!_[_] (val ∷ env) H = val\n!_[_] (val ∷ env) (TH ⦃ prf = i ⦄) = ! env [ i ]\n\n\ninterpretConstant : ∀ {t} → Constant t → ⟦ t ⟧\ninterpretConstant `not = not\ninterpretConstant `∧ = uncurry _∧_\ninterpretConstant `∨ = uncurry _∨_\ninterpretConstant `xor = uncurry _xor_\n\n\ninterpret : ∀ {t} → · ⊢ t → ⟦ t ⟧\ninterpret = interpret' []\n where interpret' : ∀ {Δ t} → ⟨ Δ ⟩ → Δ ⊢ t → ⟦ t ⟧\n interpret' env `true = true\n interpret' env `false = false\n interpret' env `tt = tt\n interpret' env ((`v x) ⦃ i = idx ⦄) = ! env [ idx ]\n interpret' env (f `₋ x) = (interpret' env f) (interpret' env x)\n interpret' env (`λ _ `: tx ⇨ body) = λ (x : ⟦ tx ⟧) → interpret' (x ∷ env) body\n interpret' env (`c f) = interpretConstant f\n interpret' env (f `, s) = interpret' env f ,′ interpret' env s\n interpret' env (`fst p) with interpret' env p\n interpret' env (`fst p) | f , s = f\n interpret' env (`snd p) with interpret' env p\n interpret' env (`snd p) | f , s = s\n\n-----\n\nand₁ : · ⊢ `Bool `× `Bool `⇨ `Bool\nand₁ = `λ x' `: `Bool `× `Bool ⇨ `c `∧ `₋ `v x'\n\nand₂ : · ⊢ `Bool `× `Bool `⇨ `Bool\nand₂ = `c `∧\n\n\n{-\n\nI want to write a function called eta-reduce that one could prove the following:\n\npf : eta-reduce and₁ ≡ and₂\npf = refl\n\nThis function will eta-reduce when it can, and do nothing when it can't.\nFor instance the following should be true:\n\n eta-reduce-constant : ∀ {c} → eta-reduce (`c c) ≡ `c c\n\nHowever, I get stuck even on this case. Uncomment the definition below and try to \ntype check this module:\n\n-}\n\n-- eta-reduce : ∀ {t₁ t₂} → · ⊢ t₁ `⇨ t₂ → · ⊢ t₁ `⇨ t₂\n-- eta-reduce (`c c) = ?\n\n{-\n\nYou will get the following error message: \n\n I'm not sure if there should be a case for the constructor `v_,\n because I get stuck when trying to solve the following unification\n problems (inferred index ≟ expected index):\n Δ ≟ ·\n !Γ Δ [ i ] ≟ t₁ `⇨ t₂\n when checking the definition of eta-reduce\n\nI did a bit of searching on the Internet and the only source I could find\nthat I could understand was this one: https://doisinkidney.com/posts/2018-09-20-agda-tips.html\n\nIt seems to be suggesting that one of the indices for a type is not in constructor form but is,\nrather, a function.\n\nLooking at the definition of _⊢_ we see that the `v_` constructor is most likely at fault: \n\n `v_ : ∀ {Δ} → (x : Var) → ⦃ i : x ∈ Δ ⦄ → Δ ⊢ !Γ Δ [ i ]\n\nThe result type is `Δ ⊢ !Γ Δ [ i ]`. Clearly the index `!Γ Δ [ i ]` is referring to a \nuser-defined function.\n\nMy question is, \"how can I fix this?\". How would I modify the _⊢_ data structure \n\n\n- I would be open to an alternative interpreter for the Simply Typed Lambda Calculus\n- This interpreter is a modified form of this code base. ttps://github.com/ahmadsalim/well-typed-agda-interpreter\n It has had instance declarations added and the syntactic form of terms has changed a little. I pulled out\n the constant functions into their own data structure called `Constant` and changed their types a little to work\n on products (_×_) instead of a curried form.\n\n\n-}\n\n\n\n\n{-\nThe instance based searching for _∈_ proofs might be a problem. I'm uncomfortable\nwith the use of --overlapping-instances\n\n\n\n\n-}\n\n-- eta-reduce : ∀ {t₁ t₂} → · ⊢ t₁ `⇨ t₂ → · ⊢ t₁ `⇨ t₂\n-- eta-reduce (`λ x `: _ ⇨ f `₋ y) = {!!}\n-- eta-reduce t = t\n\n\n\n", "meta": {"hexsha": "18601ac944ba24cd8cd923ef865baa7050a8cf84", "size": 6618, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "InterpreterWithConstants.agda", "max_stars_repo_name": "sseefried/well-typed-agda-interpreter", "max_stars_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-06-18T12:06:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T12:37:46.000Z", "max_issues_repo_path": "InterpreterWithConstants.agda", "max_issues_repo_name": "sseefried/well-typed-agda-interpreter", "max_issues_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c", "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": "InterpreterWithConstants.agda", "max_forks_repo_name": "sseefried/well-typed-agda-interpreter", "max_forks_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-18T06:14:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-18T12:31:11.000Z", "avg_line_length": 26.2619047619, "max_line_length": 113, "alphanum_fraction": 0.5265941372, "num_tokens": 2605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.39338205319721986}} {"text": "open import Agda.Primitive using (lsuc; _⊔_)\nopen import Data.Fin using (Fin)\n\nopen import MultiSorted.AlgebraicTheory\n\nmodule MultiSorted.Substitution {ℓ} {𝓈 ℴ} {Σ : Signature {𝓈} {ℴ}} (T : Theory ℓ Σ) where\n\n open Theory T\n\n -- an equality is preserved by the action of the identity\n eq-id-action : ∀ {Γ : Context} {A} {u v : Term Γ A} → (⊢ Γ ∥ (u [ id-s ]s) ≈ (v [ id-s ]s) ⦂ A) → (⊢ Γ ∥ u ≈ v ⦂ A)\n eq-id-action {u = u} {v = v} p = eq-tran (id-action {a = u}) (eq-tran p (eq-symm (id-action {a = v})))\n\n -- equality of substitutions\n _≈s_ : ∀ {Γ Δ : Context} → Γ ⇒s Δ → Γ ⇒s Δ → Set (lsuc (ℓ ⊔ 𝓈 ⊔ ℴ))\n _≈s_ {Γ} {Δ} σ ρ = ∀ x → ⊢ Γ ∥ σ x ≈ ρ x ⦂ sort-of Δ x\n\n infix 5 _≈s_\n\n -- reflexivity of the equality of substitutions\n refl-subst : ∀ {γ δ : Context} {f : γ ⇒s δ} → f ≈s f\n refl-subst = λ x → eq-refl\n\n -- symmetry of the equality of substitutions\n symm-subst : ∀ {Γ Δ : Context} {f g : Γ ⇒s Δ} → f ≈s g → g ≈s f\n symm-subst {Γ} {Δ} {f} {g} p = λ x → eq-symm (p x)\n\n -- transitivity of the equality of substitutions\n trans-subst : ∀ {Γ Δ : Context} {f g h : Γ ⇒s Δ} → f ≈s g → g ≈s h → f ≈s h\n trans-subst {Γ} {Δ} {f} {g} {h} p q = λ x → eq-tran (p x) (q x)\n\n -- neutrality of tm-var\n tm-var-id : ∀ {Γ} {A} {t : Term Γ A} → ⊢ Γ ∥ t [ id-s ]s ≈ t ⦂ A\n tm-var-id {t = tm-var x} = eq-refl\n tm-var-id {t = tm-oper f ts} = eq-congr (λ i → tm-var-id)\n\n -- any two substitutions into the empty context are equal\n empty-ctx-subst-unique : ∀ {Γ : Context} {σ ρ : Γ ⇒s ctx-empty} → σ ≈s ρ\n empty-ctx-subst-unique ()\n\n -- composition of substitutions is functorial\n subst-∘s : ∀ {Γ Δ Θ} {ρ : Δ ⇒s Γ} {σ : Θ ⇒s Δ} {A} (t : Term Γ A) →\n ⊢ Θ ∥ (t [ ρ ]s) [ σ ]s ≈ t [ ρ ∘s σ ]s ⦂ A\n subst-∘s (tm-var x) = eq-refl\n subst-∘s (tm-oper f ts) = eq-congr (λ i → subst-∘s (ts i))\n\n -- substitution preserves equality\n eq-subst : ∀ {Γ Δ : Context} {σ : Γ ⇒s Δ} {A} {u v : Term Δ A} →\n ⊢ Δ ∥ u ≈ v ⦂ A → ⊢ Γ ∥ u [ σ ]s ≈ v [ σ ]s ⦂ A\n eq-subst eq-refl = eq-refl\n eq-subst (eq-symm ξ) = eq-symm (eq-subst ξ)\n eq-subst (eq-tran ζ ξ) = eq-tran (eq-subst ζ) (eq-subst ξ)\n eq-subst (eq-congr ξ) = eq-congr (λ i → eq-subst (ξ i))\n eq-subst {σ = σ} (eq-axiom ε ρ) = eq-tran (subst-∘s (ax-lhs ε)) (eq-tran (eq-axiom ε (ρ ∘s σ)) (eq-symm (subst-∘s (ax-rhs ε))))\n\n -- equivalent substitutions act the same on terms\n equiv-subst : ∀ {Γ Δ : Context} {σ τ : Γ ⇒s Δ} {A} (u : Term Δ A) →\n σ ≈s τ → ⊢ Γ ∥ u [ σ ]s ≈ u [ τ ]s ⦂ A\n equiv-subst (tm-var x) ξ = ξ x\n equiv-subst (tm-oper f ts) ξ = eq-congr (λ i → equiv-subst (ts i) ξ)\n\n -- equivalent substitution preserve equality\n equiv-eq-subst : ∀ {Γ Δ : Context} {σ τ : Γ ⇒s Δ} {A} {u v : Term Δ A} →\n σ ≈s τ → ⊢ Δ ∥ u ≈ v ⦂ A → ⊢ Γ ∥ u [ σ ]s ≈ v [ τ ]s ⦂ A\n equiv-eq-subst {u = u} p eq-refl = equiv-subst u p\n equiv-eq-subst p (eq-symm q) = eq-symm (equiv-eq-subst (symm-subst p) q)\n equiv-eq-subst p (eq-tran q r) = eq-tran (eq-subst q) (equiv-eq-subst p r)\n equiv-eq-subst p (eq-congr ξ) = eq-congr λ i → equiv-eq-subst p (ξ i)\n equiv-eq-subst {σ = σ} {τ = τ} p (eq-axiom ε θ) = eq-tran (eq-subst (eq-axiom ε θ)) (equiv-subst (ax-rhs ε [ θ ]s) p)\n\n -- the pairing of two substitutions\n ⟨_,_⟩s : ∀ {Γ Δ Θ} (σ : Γ ⇒s Δ) (ρ : Γ ⇒s Θ) → Γ ⇒s ctx-concat Δ Θ\n ⟨ σ , ρ ⟩s (var-inl x) = σ x\n ⟨ σ , ρ ⟩s (var-inr y) = ρ y\n\n -- composition of substitutions preserves equality\n ∘s-resp-≈s : ∀ {Γ Δ Θ} {σ₁ σ₂ : Γ ⇒s Δ} {τ₁ τ₂ : Δ ⇒s Θ} →\n τ₁ ≈s τ₂ → σ₁ ≈s σ₂ → τ₁ ∘s σ₁ ≈s τ₂ ∘s σ₂\n ∘s-resp-≈s ξ ζ z = equiv-eq-subst ζ (ξ z)\n\n -- the action of a substitution on an equation\n open Equation\n _[_]s-eq : ∀ (ε : Equation Σ) {Γ : Context} ( σ : Γ ⇒s (eq-ctx ε)) → Equation Σ\n _[_]s-eq ε {Γ} σ = Γ ∥ ((eq-lhs ε) [ σ ]s) ≈ ((eq-rhs ε) [ σ ]s) ⦂ (eq-sort ε)\n", "meta": {"hexsha": "ea02a930c3d4f6f5d851092143807a60c383bd55", "size": 3788, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/MultiSorted/Substitution.agda", "max_stars_repo_name": "cilinder/formaltt", "max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z", "max_issues_repo_path": "src/MultiSorted/Substitution.agda", "max_issues_repo_name": "andrejbauer/formaltt", "max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z", "max_forks_repo_path": "src/MultiSorted/Substitution.agda", "max_forks_repo_name": "andrejbauer/formaltt", "max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z", "avg_line_length": 44.5647058824, "max_line_length": 129, "alphanum_fraction": 0.5364308342, "num_tokens": 1716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723316860482763, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.39338204551425093}} {"text": "-- Andreas, 2011-10-04, transcription of Dan Doel's post on the Agda list\n{-# OPTIONS --experimental-irrelevance #-}\nmodule IrrelevantMatchRefl where\n\nimport Common.Level\nopen import Common.Equality hiding (subst)\n\n-- irrelevant subst should be rejected, because it suggests\n-- that the equality proof is irrelevant also for reduction\nsubst : ∀ {i j}{A : Set i}(P : A → Set j){a b : A} → .(a ≡ b) → P a → P b\nsubst P refl x = x\n\npostulate\n D : Set\n lie : (D → D) ≡ D\n\n-- the following two substs may not reduce! ...\nabs : (D → D) → D\nabs f = subst (λ T → T) lie f\n\napp : D → D → D\napp d = subst (λ T → T) (sym lie) d\n\nω : D\nω = abs (λ d → app d d)\n\n-- ... otherwise Ω loops\nΩ : D\nΩ = app ω ω\n\n-- ... and this would be a real fixed-point combinator\nY : (D → D) → D\nY f = app δ δ\n where δ = abs (λ x → f (app x x))\n\nK : D → D\nK x = abs (λ y → x)\n\nK∞ : D\nK∞ = Y K\n\nmayloop : K∞ ≡ abs (λ y → K∞)\nmayloop = refl\n-- gives error D != D → D\n", "meta": {"hexsha": "f37ed6e5ac5a8fd2a5b236d3b61d156d15bdb8f8", "size": 938, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/IrrelevantMatchRefl.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/IrrelevantMatchRefl.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/IrrelevantMatchRefl.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 20.8444444444, "max_line_length": 73, "alphanum_fraction": 0.5948827292, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.39337682059538287}} {"text": "{-# OPTIONS --safe #-}\nmodule Cubical.Algebra.DirectSum.DirectSumHIT.Properties where\n\nopen import Cubical.Foundations.Prelude\n\nopen import Cubical.Data.Empty as ⊥\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Relation.Nullary\n\nopen import Cubical.Algebra.Group\nopen import Cubical.Algebra.AbGroup\nopen import Cubical.Algebra.DirectSum.DirectSumHIT.Base\n\nprivate variable\n ℓ ℓ' : Level\n\nmodule AbGroupProperties\n (Idx : Type ℓ)\n (P : Idx → Type ℓ')\n (AGP : (r : Idx) → AbGroupStr (P r))\n where\n\n inv : ⊕HIT Idx P AGP → ⊕HIT Idx P AGP\n inv = DS-Rec-Set.f Idx P AGP (⊕HIT Idx P AGP) trunc\n -- elements\n neutral\n (λ r a → base r (AbGroupStr.-_ (AGP r) a))\n (λ xs ys → xs add ys)\n -- eq group\n (λ xs ys zs → addAssoc xs ys zs)\n (λ xs → addRid xs)\n (λ xs ys → addComm xs ys)\n -- eq base\n (λ r → let open AbGroupStr (AGP r) in\n let open GroupTheory (P r , AbGroupStr→GroupStr (AGP r)) in\n (cong (base r) inv1g) ∙ (base-neutral r))\n (λ r a b → let open AbGroupStr (AGP r) in\n let open GroupTheory (P r , AbGroupStr→GroupStr (AGP r)) in\n ((base r (- a) add base r (- b)) ≡⟨ (base-add r (- a) (- b)) ⟩\n base r ((- a) + (- b)) ≡⟨ (cong (base r) (sym (invDistr b a))) ⟩\n base r (- (b + a)) ≡⟨ cong (base r) (cong (-_) (+Comm b a)) ⟩\n base r (- (a + b)) ∎))\n\n\n\n rinv : (z : ⊕HIT Idx P AGP) → z add (inv z) ≡ neutral\n rinv = DS-Ind-Prop.f Idx P AGP (λ z → z add (inv z) ≡ neutral) (λ _ → trunc _ _)\n -- elements\n (addRid neutral)\n (λ r a → let open AbGroupStr (AGP r) in\n ((base r a add base r (- a)) ≡⟨ base-add r a (- a) ⟩\n base r (a + - a) ≡⟨ cong (base r) (+InvR a) ⟩\n base r 0g ≡⟨ base-neutral r ⟩\n neutral ∎))\n (λ {x} {y} p q →\n (((x add y) add ((inv x) add (inv y))) ≡⟨ cong (λ X → X add ((inv x) add (inv y))) (addComm x y) ⟩\n ((y add x) add (inv x add inv y)) ≡⟨ sym (addAssoc y x (inv x add inv y)) ⟩\n (y add (x add (inv x add inv y))) ≡⟨ cong (λ X → y add X) (addAssoc x (inv x) (inv y)) ⟩\n (y add ((x add inv x) add inv y)) ≡⟨ cong (λ X → y add (X add (inv y))) (p) ⟩\n (y add (neutral add inv y)) ≡⟨ cong (λ X → y add X) (addComm neutral (inv y)) ⟩\n (y add (inv y add neutral)) ≡⟨ cong (λ X → y add X) (addRid (inv y)) ⟩\n (y add inv y) ≡⟨ q ⟩\n neutral ∎))\n\nmodule SubstLemma\n (Idx : Type ℓ)\n (G : Idx → Type ℓ')\n (Gstr : (r : Idx) → AbGroupStr (G r))\n where\n\n open AbGroupStr\n\n subst0g : {l k : Idx} → (p : l ≡ k) → subst G p (0g (Gstr l)) ≡ 0g (Gstr k)\n subst0g {l} {k} p = J (λ k p → subst G p (0g (Gstr l)) ≡ 0g (Gstr k)) (transportRefl _) p\n\n subst+ : {l : Idx} → (a b : G l) → {k : Idx} → (p : l ≡ k) →\n Gstr k ._+_ (subst G p a) (subst G p b) ≡ subst G p (Gstr l ._+_ a b)\n subst+ {l} a b {k} p = J (λ k p → Gstr k ._+_ (subst G p a) (subst G p b) ≡ subst G p (Gstr l ._+_ a b))\n (cong₂ (Gstr l ._+_) (transportRefl _) (transportRefl _) ∙ sym (transportRefl _))\n p\n\nmodule DecIndec-BaseProperties\n (Idx : Type ℓ)\n (decIdx : Discrete Idx)\n (G : Idx → Type ℓ')\n (Gstr : (r : Idx) → AbGroupStr (G r))\n where\n\n open AbGroupStr\n open SubstLemma Idx G Gstr\n\n πₖ : (k : Idx) → ⊕HIT Idx G Gstr → G k\n πₖ k = DS-Rec-Set.f _ _ _ _ (is-set (Gstr k))\n (0g (Gstr k))\n base-trad\n (_+_ (Gstr k))\n (+Assoc (Gstr k))\n (+IdR (Gstr k))\n (+Comm (Gstr k))\n base-neutral-eq\n base-add-eq\n where\n base-trad : (l : Idx) → (a : G l) → G k\n base-trad l a with decIdx l k\n ... | yes p = subst G p a\n ... | no ¬p = 0g (Gstr k)\n\n base-neutral-eq : _\n base-neutral-eq l with decIdx l k\n ... | yes p = subst0g p\n ... | no ¬p = refl\n\n base-add-eq : _\n base-add-eq l a b with decIdx l k\n ... | yes p = subst+ a b p\n ... | no ¬p = +IdR (Gstr k) _\n\n πₖ-id : {k : Idx} → (a : G k) → πₖ k (base k a) ≡ a\n πₖ-id {k} a with decIdx k k\n ... | yes p = cong (λ X → subst G X a) (Discrete→isSet decIdx _ _ _ _) ∙ transportRefl _\n ... | no ¬p = rec (¬p refl)\n\n πₖ-0g : {k l : Idx} → (a : G l) → (p : k ≡ l → ⊥) → πₖ k (base l a) ≡ 0g (Gstr k)\n πₖ-0g {k} {l} a ¬q with decIdx l k\n ... | yes p = rec (¬q (sym p))\n ... | no ¬p = refl\n\n base-inj : {k : Idx} → {a b : G k} → base {AGP = Gstr} k a ≡ base k b → a ≡ b\n base-inj {k} {a} {b} p = sym (πₖ-id a) ∙ cong (πₖ k) p ∙ πₖ-id b\n\n base-≢ : {k : Idx} → {a : G k} → {l : Idx} → {b : G l} → (p : k ≡ l → ⊥) →\n base {AGP = Gstr} k a ≡ base {AGP = Gstr} l b → (a ≡ 0g (Gstr k)) × (b ≡ 0g (Gstr l))\n base-≢ {k} {a} {l} {b} ¬p q = helper1 , helper2\n where\n helper1 : a ≡ 0g (Gstr k)\n helper1 = sym (πₖ-id a) ∙ cong (πₖ k) q ∙ πₖ-0g b ¬p\n\n helper2 : b ≡ 0g (Gstr l)\n helper2 = sym (πₖ-id b) ∙ cong (πₖ l) (sym q) ∙ πₖ-0g a (λ x → ¬p (sym x))\n", "meta": {"hexsha": "38f6a06370610af26b0777e5ed5f4221debf43f8", "size": 5395, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/DirectSum/DirectSumHIT/Properties.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/DirectSum/DirectSumHIT/Properties.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/DirectSum/DirectSumHIT/Properties.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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.2624113475, "max_line_length": 124, "alphanum_fraction": 0.4574606117, "num_tokens": 2065, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548646660542, "lm_q2_score": 0.6039318337259584, "lm_q1q2_score": 0.3933739378240936}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule common where\nopen import Agda.Primitive public\n using (Level; _⊔_; lzero; lsuc)\n\ninfixl 1 _,_\ninfixl 1 _≡_\ninfixr 2 _∧_\ninfixr 2 _×_\ninfixl 2 _+_\n\ndata bool : Set where\n true : bool\n false : bool\n\n_∧_ : bool → bool → bool\ntrue ∧ true = true\ntrue ∧ false = false\nfalse ∧ true = false\nfalse ∧ false = false\n\nrecord Σ {ℓ ℓ′} (A : Set ℓ) (P : A → Set ℓ′) : Set (ℓ ⊔ ℓ′) where\n constructor _,_\n field\n proj₁ : A\n proj₂ : P proj₁\n\n_×_ : ∀ {ℓ ℓ′} (A : Set ℓ) (B : Set ℓ′) → Set (ℓ ⊔ ℓ′)\nA × B = Σ A (λ _ → B)\n\nif_then_else_ : ∀ {ℓ} {A : Set ℓ} → (b : bool) → A → A → A\nif true then t else f = t\nif false then t else f = f\n\ndata Lifted {a b} (A : Set a) : Set (b ⊔ a) where\n lift : A → Lifted A\n\nlower : ∀ {a b A} → Lifted {a} {b} A → A\nlower (lift x) = x\n\ndata Maybe {ℓ : Level} (A : Set ℓ) : Set ℓ where\n just : (x : A) → Maybe A\n nothing : Maybe A\n\nMaybe-elim : ∀ {ℓ ℓ′} {A : Set ℓ} (P : Maybe A → Set ℓ′)\n → ((x : A) → P (just x))\n → P nothing\n → (x : Maybe A)\n → P x\nMaybe-elim P Pjust Pnothing (just x) = Pjust x\nMaybe-elim P Pjust Pnothing nothing = Pnothing\n\noption-map : ∀ {ℓ ℓ′} {A : Set ℓ} {B : Set ℓ′}\n → (A → B)\n → Maybe A → Maybe B\noption-map f (just x) = just (f x)\noption-map f nothing = nothing\n\n\noption-bind : ∀ {ℓ ℓ′} {A : Set ℓ} {B : Set ℓ′}\n → Maybe A\n → (A → Maybe B)\n → Maybe B\noption-bind (just x) f = option-map (λ x₁ → x₁) (f x)\noption-bind nothing f = nothing\n\ndata ⊥ {ℓ : Level} : Set ℓ where\n\n⊥-elim : {ℓ ℓ′ : Level} → ⊥ {ℓ} → {A : Set ℓ′} → A\n⊥-elim ()\n\n¬_ : ∀ {ℓ} → Set ℓ → Set ℓ\n¬ T = T → ⊥ {lzero}\n\nrecord ⊤ {ℓ : Level} : Set ℓ where\n constructor tt\n\ninfixr 1 _⊎_\n\ndata _⊎_ (A : Set) (B : Set) : Set where\n inj₁ : (x : A) → A ⊎ B\n inj₂ : (y : B) → A ⊎ B\n\ndata _≡_ {ℓ} {A : Set ℓ} (x : A) : A → Set ℓ where\n refl : x ≡ x\n\n_≢_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ\nx ≢ y = x ≡ y → ⊥ {lzero}\n\ndec-eq-on : {A : Set} → (x : A) → (y : A) → Set\ndec-eq-on x y = (x ≡ y) ⊎ (x ≢ y)\n\ndec-eq : Set → Set\ndec-eq A = (x : A) → (y : A) → dec-eq-on x y\n\nsym : {A : Set} → {x : A} → {y : A} → x ≡ y → y ≡ x\nsym refl = refl\n\ntrans : {A : Set} → {x y z : A} → x ≡ y → y ≡ z → x ≡ z\ntrans refl refl = refl\n\ntransport : ∀ {A : Set} {x : A} {y : A} → (P : A → Set) → x ≡ y → P x → P y\ntransport P refl v = v\n\ntransport2 : ∀ {A : Set} {B : A → Set} {x x' : A} {y : B x} {y' : B x'} → (P : (x : A) → B x → Set) → (p : x ≡ x') → transport B p y ≡ y' → P x y → P x' y'\ntransport2 P refl = transport (P _)\n\ntransport3 : ∀ {A : Set} {B : A → Set} {C : (x : A) → (y : B x) → Set} {x x' : A} {y : B x} {y' : B x'} {z : C x y} {z' : C x' y'} → (P : (x : A) → (y : B x) → C x y → Set) → (p : x ≡ x') → (q : transport B p y ≡ y') → transport2 C p q z ≡ z' → P x y z → P x' y' z'\ntransport3 P refl = transport2 (P _)\n\ntransport4 : ∀ {A : Set} {B : A → Set} {C : (x : A) → (y : B x) → Set} {D : (x : A) → (y : B x) → (z : C x y) → Set} {x x' : A} {y : B x} {y' : B x'} {z : C x y} {z' : C x' y'} {w : D x y z} {w' : D x' y' z'} → (P : (x : A) → (y : B x) → (z : C x y) → D x y z → Set) → (p : x ≡ x') → (q : transport B p y ≡ y') → (r : transport2 C p q z ≡ z') → transport3 D p q r w ≡ w' → P x y z w → P x' y' z' w'\ntransport4 P refl = transport3 (P _)\n\n\nMaybe-code : {A : Set} → Maybe A → Maybe A → Set\nMaybe-code (just x) (just x₁) = x ≡ x₁\nMaybe-code (just x) nothing = ⊥\nMaybe-code nothing (just x) = ⊥\nMaybe-code nothing nothing = ⊤\n\nMaybe-encode : ∀ {A} {x y : Maybe A} → x ≡ y → Maybe-code x y\nMaybe-encode {A} {just x} refl = refl\nMaybe-encode {A} {nothing} refl = tt\n\nMaybe-decode : ∀ {A} {x y : Maybe A} → Maybe-code x y → x ≡ y\nMaybe-decode {A} {just .x₁} {just x₁} refl = refl\nMaybe-decode {A} {just x} {nothing} ()\nMaybe-decode {A} {nothing} {just x} ()\nMaybe-decode {A} {nothing} {nothing} tt = refl\n\nMaybe-deencode : ∀ {A} {x y : Maybe A} {p : x ≡ y} → Maybe-decode (Maybe-encode p) ≡ p\nMaybe-deencode {A} {just x} {.(just x)} {refl} = refl\nMaybe-deencode {A} {nothing} {.nothing} {refl} = refl\n\nMaybe-endecode : ∀ {A} {x y : Maybe A} (p : Maybe-code x y) → Maybe-encode {A} {x} {y} (Maybe-decode p) ≡ p\nMaybe-endecode {A} {just .x'} {just x'} refl = refl\nMaybe-endecode {A} {just x} {nothing} ()\nMaybe-endecode {A} {nothing} {just x} ()\nMaybe-endecode {A} {nothing} {nothing} tt = refl\n\n\ndata ℕ : Set where\n zero : ℕ\n suc : (n : ℕ) → ℕ\n\n{-# BUILTIN NATURAL ℕ #-}\n\nmax : ℕ → ℕ → ℕ\nmax 0 y = y\nmax x 0 = x\nmax (suc x) (suc y) = suc (max x y)\n\n_+_ : ℕ → ℕ → ℕ\n0 + b = b\nsuc a + b = suc (a + b)\n", "meta": {"hexsha": "c1d65248f3145e248d9573e81bb9f0e66fe80e0a", "size": 4469, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "internal/common.agda", "max_stars_repo_name": "JasonGross/lob", "max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z", "max_issues_repo_path": "internal/common.agda", "max_issues_repo_name": "JasonGross/lob", "max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z", "max_forks_repo_path": "internal/common.agda", "max_forks_repo_name": "JasonGross/lob", "max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z", "avg_line_length": 28.4649681529, "max_line_length": 398, "alphanum_fraction": 0.5097337212, "num_tokens": 2006, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548511303336, "lm_q2_score": 0.6039318337259583, "lm_q1q2_score": 0.39337392964944096}} {"text": "{-# OPTIONS --without-K #-}\n\n\nopen import lib.Basics hiding (_⊔_)\nopen import lib.types.Sigma\nopen import lib.NType2\n\nopen import Preliminaries\nopen import Truncation_Level_Criteria\nopen import Anonymous_Existence_CollSplit\n\nopen wtrunc\nopen with-weak-trunc\n\n\nmodule Weakly_Constant_Functions where\n\n-- Definition 5.1.1\nfactorizes-through : ∀ {i j} {X : Type i} {Y : Type j} → Type i → (X → Y) → Type (i ⊔ j)\nfactorizes-through {X = X} {Y = Y} Z f = Σ (X → Z) λ f₁ → Σ (Z → Y) λ f₂ → (x : X) → f₂ (f₁ x) == f x\n\n-- Definition 5.1.1 addendum: 'factorizes through the truncation'\n-- In the theory of the thesis, universes are cumulative.\n-- Here, we ask all the types to be in the same universe.\nfactorizes : ∀ {i} {X : Type i} {Y : Type i} → (X → Y) → Type i\nfactorizes {X = X} = factorizes-through (∣∣ X ∣∣)\n\n-- Principle 5.2.1\nfactorize-helper : ∀ {i} {X : Type i} {Y : Type i} → (f : X → Y) → (P : Type i) → (X → is-prop P) → (factorizes-through P f) → factorizes f\nfactorize-helper {X = X} {Y = Y} f P xpp (f₁ , f₂ , q) = f₁' , f₂' , q' where\n f₁' : X → ∣∣ X ∣∣\n f₁' = ∣_∣\n\n f₂' : ∣∣ X ∣∣ → Y\n f₂' z = f₂ (tr-rec {X = X} (tr-rec is-prop-is-prop xpp z) f₁ z)\n\n q' : (x : X) → f₂' (f₁' x) == f x\n q' x =\n f₂' (f₁' x) =⟨ idp ⟩\n f₂' ∣ x ∣ =⟨ idp ⟩ \n f₂ (tr-rec _ f₁ ∣ x ∣ ) =⟨ ap f₂ (trunc-β _ f₁ x) ⟩\n f₂ (f₁ x) =⟨ q x ⟩ \n f x ∎ \n\n-- Proposition 5.2.2\nmodule st522 {i : ULevel} {X : Type i} {Y : Type i} (f : X → Y) (c : const f) where\n One = ¬ X\n Two = X\n Three = ∣∣ X ∣∣ → X\n Four = coll X\n Five = Y → X\n\n One→Three : One → Three\n One→Three nx z = Empty-elim {P = λ _ → X} (tr-rec Empty-elim nx z)\n\n Two→Three : Two → Three\n Two→Three x = λ _ → x\n\n Five→Four : Five → Four\n Five→Four g = g ∘ f , (λ x₁ x₂ → ap g (c x₁ x₂))\n\n Three↔Four : Three ↔ Four\n Three↔Four = snd coll↔splitSup , fst coll↔splitSup\n\n Three→factorizes : Three → factorizes f\n Three→factorizes s = ∣_∣ , f ∘ s , (λ x → c _ _)\n\n-- Proposition 5.2.3 preparation\n-- as a small preparation, let us define a function that applies the truncation tr-recursor twice.\n-- Because of how we have defined the operator ∣∣_∣∣, we need everything to happen in the same universe\ndouble-tr-rec : ∀ {i} {X₁ X₂ P : Type i} → (is-prop P) → (X₁ → X₂ → P) → ∣∣ X₁ ∣∣ → ∣∣ X₂ ∣∣ → P\ndouble-tr-rec {i} {X₁} {X₂} {P} pp f z₁ z₂ = next-step z₁ z₂ where\n step : X₁ → ∣∣ X₂ ∣∣ → P \n step x₁ = tr-rec {X = X₂} {P = P} pp (f x₁)\n step-switch : ∣∣ X₂ ∣∣ → X₁ → P\n step-switch z₂ x₁ = step x₁ z₂\n next-step : ∣∣ X₁ ∣∣ → ∣∣ X₂ ∣∣ → P\n next-step z₁ z₂ = tr-rec pp (step-switch z₂) z₁ -- tr-rec pp (step-switch z₂)\n\n-- now, the actual Proposition 5.2.3\nfactorize-codomain-set : ∀ {i} {X : Type i} {Y : Type i} → (f : X → Y) → const f → is-set Y → factorizes f\nfactorize-codomain-set {i} {X} {Y} f c h = factorize-helper f P (λ _ → pp) fact-through-p where\n P : Type i \n P = Σ Y λ y → ∣∣ (Σ X λ x → f x == y) ∣∣\n\n pp : is-prop P\n pp = all-paths-is-prop all-paths where\n all-paths : has-all-paths P\n all-paths (y₁ , t₁) (y₂ , t₂) = pair= ys ts where\n ys = double-tr-rec {P = y₁ == y₂} (h _ _) (λ {(x₁ , p₁) (x₂ , p₂) → ! p₁ ∙ c _ _ ∙ p₂}) t₁ t₂\n ts = from-transp _ ys (prop-has-all-paths tr-is-prop _ _)\n\n fact-through-p : factorizes-through P f\n fact-through-p = f₁ , f₂ , q where\n f₁ : X → P\n f₁ x = f x , ∣ x , idp ∣ \n f₂ : P → Y\n f₂ = fst\n q : (x : X) → f₂ (f₁ x) == f x\n q x = idp\n\n-- Theorem 5.2.6\n-- We need function extensionality and thus import \n-- the following:\nopen import lib.types.Pi\n\n-- A general auxiliary function which switches the second \n-- and third component of a Σ-type with four components\n-- (provided that it is possible).\n-- We formulate this explicitly as we will need it several times:\nswitch23 : ∀ {i} {X : Type i} → {Y Z : X → Type i} → {W : (x : X) → (Y x) → (Z x) → Type i} → \n (Σ X λ x → Σ (Y x) λ y → Σ (Z x) λ z → (W x y z)) ≃ \n (Σ X λ x → Σ (Z x) λ z → Σ (Y x) λ y → (W x y z))\nswitch23 = equiv (λ {(y , s , t , coh) → (y , t , s , coh)}) (λ {(y , t , s , coh) → (y , s , t , coh)}) (λ _ → idp) (λ _ → idp)\n\n-- Theorem 5.2.6, with the 'equivalence reasoning' tactic:\nmodule thm526 {i : ULevel} {Q R Y : Type i} (qq : is-prop Q) (rr : is-prop R) (f : Coprod Q R → Y) (c : const f) where\n\n P : Type i\n P = Σ Y λ y →\n Σ ((q : Q) → y == f(inl q)) λ s → \n Σ ((r : R) → y == f(inr r)) λ t →\n (q : Q) → (r : R) → ! (s q) ∙ (t r) == c (inl q) (inr r)\n\n -- This is going to be tedious: if q₀ : Q is given, we can show that P is equivalent to the Unit type.\n given-q-reduce-P : Q → P ≃ Unit\n given-q-reduce-P q₀ = \n\n P \n\n ≃⟨ switch23 ⟩\n\n (Σ Y λ y →\n Σ ((r : R) → y == f(inr r)) λ t →\n Σ ((q : Q) → y == f(inl q)) λ s → \n (q : Q) → (r : R) → ! (s q) ∙ (t r) == c (inl q) (inr r))\n\n ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ t → choice ⁻¹)) ⟩\n\n (Σ Y λ y →\n Σ ((r : R) → y == f(inr r)) λ t →\n (q : Q) → Σ (y == f(inl q)) λ s-reduced → \n (r : R) → ! s-reduced ∙ (t r) == c (inl q) (inr r))\n\n ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ t → Π₁-contr (q₀ , prop-has-all-paths qq q₀))) ⟩ \n\n (Σ Y λ y →\n Σ ((r : R) → y == f(inr r)) λ t →\n Σ (y == f(inl q₀)) λ s-reduced → \n (r : R) → ! s-reduced ∙ (t r) == c (inl q₀) (inr r))\n\n ≃⟨ switch23 ⟩ \n\n (Σ Y λ y →\n Σ (y == f(inl q₀)) λ s-reduced → \n Σ ((r : R) → y == f(inr r)) λ t →\n (r : R) → ! s-reduced ∙ (t r) == c (inl q₀) (inr r))\n\n ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ t → choice ⁻¹)) ⟩ \n\n (Σ Y λ y →\n Σ (y == f(inl q₀)) λ s-reduced → \n (r : R) → Σ (y == f(inr r)) λ t-reduced → \n ! s-reduced ∙ t-reduced == c (inl q₀) (inr r))\n\n ≃⟨ Σ-assoc ⁻¹ ⟩ \n\n (Σ (Σ Y λ y → (y == f(inl q₀))) λ {(y , s-reduced) → \n (r : R) → Σ (y == f(inr r)) λ t-reduced → \n ! s-reduced ∙ t-reduced == c (inl q₀) (inr r)})\n\n ≃⟨ Σ₁-contr (pathto-is-contr _) ⟩ \n\n ((r : R) → Σ (f(inl q₀) == f(inr r)) λ t-reduced →\n idp ∙ t-reduced == c (inl q₀) (inr r))\n\n ≃⟨ Π₂-contr (λ r → pathto-is-contr _) ⟩ \n\n Unit ≃∎\n\n\n\n given-r-reduce-P : R → P ≃ Unit\n given-r-reduce-P r₀ =\n\n P \n\n ≃⟨ equiv-Σ-snd (λ _ → equiv-Σ-snd (λ _ → equiv-Σ-snd (λ _ → switch-args))) ⟩\n\n (Σ Y λ y →\n Σ ((q : Q) → y == f(inl q)) λ s → \n Σ ((r : R) → y == f(inr r)) λ t →\n (r : R) → (q : Q) → ! (s q) ∙ (t r) == c (inl q) (inr r))\n\n ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ s → choice ⁻¹)) ⟩\n\n (Σ Y λ y →\n Σ ((q : Q) → y == f(inl q)) λ s →\n (r : R) → Σ (y == f(inr r)) λ t-reduced → \n (q : Q) → ! (s q) ∙ t-reduced == c (inl q) (inr r))\n\n\n ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ t → Π₁-contr (r₀ , prop-has-all-paths rr r₀))) ⟩ \n\n (Σ Y λ y →\n Σ ((q : Q) → y == f(inl q)) λ s →\n Σ (y == f(inr r₀)) λ t-reduced → \n (q : Q) → ! (s q) ∙ t-reduced == c (inl q) (inr r₀))\n\n ≃⟨ switch23 ⟩\n\n (Σ Y λ y →\n Σ (y == f(inr r₀)) λ t-reduced → \n Σ ((q : Q) → y == f(inl q)) λ s →\n (q : Q) → ! (s q) ∙ t-reduced == c (inl q) (inr r₀))\n\n\n ≃⟨ equiv-Σ-snd (λ y → equiv-Σ-snd (λ s → choice ⁻¹)) ⟩ \n\n (Σ Y λ y →\n Σ (y == f(inr r₀)) λ t-reduced → \n (q : Q) → Σ (y == f(inl q)) λ s-reduced → \n ! s-reduced ∙ t-reduced == c (inl q) (inr r₀))\n\n\n ≃⟨ Σ-assoc ⁻¹ ⟩ \n\n (Σ (Σ Y λ y → (y == f(inr r₀))) λ {(y , t-reduced) → \n (q : Q) → Σ (y == f(inl q)) λ s-reduced → \n ! s-reduced ∙ t-reduced == c (inl q) (inr r₀)})\n\n ≃⟨ Σ₁-contr (pathto-is-contr _) ⟩\n\n ((q : Q) → Σ (f(inr r₀) == f(inl q)) λ s-reduced → \n ! s-reduced ∙ idp == c (inl q) (inr r₀))\n\n ≃⟨ equiv-Π-r (λ q → equiv-Σ-snd (λ proof → \n ! proof ∙ idp == c (inl q) (inr r₀) ≃⟨ delete-idp _ _ ⟩\n ! proof == c (inl q) (inr r₀) ≃⟨ reverse-paths _ _ ⟩\n proof == ! (c (inl q) (inr r₀)) ≃∎\n )) ⟩\n\n ((q : Q) → Σ (f(inr r₀) == f(inl q)) λ s-reduced → \n s-reduced == ! (c (inl q) (inr r₀)))\n\n ≃⟨ Π₂-contr (λ q → pathto-is-contr _) ⟩ \n\n Unit ≃∎\n\n\n\n given-q+r-reduce-P : Coprod Q R → P ≃ Unit\n given-q+r-reduce-P (inl q) = given-q-reduce-P q\n given-q+r-reduce-P (inr r) = given-r-reduce-P r\n\n Q+R→P : Coprod Q R → P\n Q+R→P x = <– (given-q+r-reduce-P x) _ \n\n P→Y : P → Y\n P→Y = fst\n\n open import lib.types.Unit\n\n -- Finally : the statement of Theorem 5.2.6\n factorize-f : factorizes f\n factorize-f = factorize-helper f P (λ x → equiv-preserves-level ((given-q+r-reduce-P x) ⁻¹) Unit-is-prop) (Q+R→P , P→Y , proof) where\n proof : (x : Coprod Q R) → P→Y (Q+R→P x) == f x\n proof (inl q) = idp\n proof (inr r) = idp\n\n-- and Theorem 5.2.6 again (outside of a specialized module)\nTheorem526 : ∀ {i} {Q R Y : Type i} → (is-prop Q) → (is-prop R) → (f : Coprod Q R → Y) → (const f) → factorizes f\nTheorem526 = thm526.factorize-f \n", "meta": {"hexsha": "8805dc1b92d52a12c74de7ea026896de6fb4fa4b", "size": 9451, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "nicolai/thesis/Weakly_Constant_Functions.agda", "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolai/thesis/Weakly_Constant_Functions.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": "nicolai/thesis/Weakly_Constant_Functions.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": 34.4927007299, "max_line_length": 139, "alphanum_fraction": 0.4604803724, "num_tokens": 3899, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.6513548646660543, "lm_q1q2_score": 0.3933739285375174}} {"text": "module Optics where\nopen import Agda.Primitive using (_⊔_; lsuc)\nopen import Data.Maybe using (Maybe; just)\nopen import Data.Sum using (_⊎_; inj₁)\nopen import Function using (const; id)\nopen import Category.Functor.Arr\nopen import Category.Functor.Const\nopen import Category.Functor.Either\nopen import Category.Profunctor.Joker\nopen import Category.Profunctor.Star\n\nOptic : ∀ {l p} (c : (Set l → Set l → Set l) → Set p) (s t a b : Set l) → Set (lsuc l ⊔ p)\nOptic {l} c s t a b = ∀ {p : Set l → Set l → Set l} (isClass : c p) → p a b → p s t\n\nsetOptic : ∀ {l p} (S T A B : Set l) {c : (Set l → Set l → Set l) → Set p} (isClass : c (Star (Arr B))) → Optic c S T A B → S → B → T\nsetOptic _ _ _ _ isClass l = l isClass (const id)\n\nputOptic : ∀ {l p} (S T A B : Set l) {c : (Set l → Set l → Set l) → Set p} (isClass : c (Joker (Arr B))) → Optic c S T A B → B → T\nputOptic _ _ _ _ isClass l = l isClass id\n\ngetOptic : ∀ {l p} (S T A B : Set l) {c : (Set l → Set l → Set l) → Set p} (isClass : c (Star (Const A))) → Optic c S T A B → S → A\ngetOptic _ _ _ _ isClass l = l isClass id\n\nmatchingOptic : ∀ {l p} (S T A B : Set l) {c : (Set l → Set l → Set l) → Set p} (isClass : c (Star (Either A))) → Optic c S T A B → S → A ⊎ T\nmatchingOptic _ _ _ _ isClass l = l isClass inj₁\n\npreviewOptic : ∀ {l p} (S T A B : Set l) {c : (Set l → Set l → Set l) → Set p} (isClass : c (Star (Const (Maybe A)))) → Optic c S T A B → S → Maybe A\npreviewOptic _ _ _ _ isClass l = l isClass just\n\n", "meta": {"hexsha": "f72f2e388ba43a0478d85e97a1e9b39d59099658", "size": 1467, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Optics.agda", "max_stars_repo_name": "crisoagf/agda-optics", "max_stars_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74", "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": "src/Optics.agda", "max_issues_repo_name": "crisoagf/agda-optics", "max_issues_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74", "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": "src/Optics.agda", "max_forks_repo_name": "crisoagf/agda-optics", "max_forks_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74", "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": 48.9, "max_line_length": 149, "alphanum_fraction": 0.6053169734, "num_tokens": 568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3933426323524849}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nimport homotopy.WedgeExtension as WedgeExt\nimport homotopy.SuspAdjointLoop as SAL\n\nmodule homotopy.Freudenthal where\n\n{- lemma (move this where?) -}\nprivate\n move1-left-on-left : ∀ {i} {A : Type i} {x y : A} (p : x == y) (q : x == y)\n → ((! q) ∙ p == idp → p == q)\n move1-left-on-left p idp h = h\n\nmodule FreudenthalEquiv\n {i} (n k : ℕ₋₂) (kle : k ≤T S n +2+ S n)\n (X : Ptd i) {{cX : is-connected (S (S n)) (de⊙ X)}} where\n\n Q : Susp (de⊙ X) → Type i\n Q x = Trunc k (north == x)\n\n ⊙up : X ⊙→ ⊙Ω (⊙Susp X)\n ⊙up = SAL.η _\n\n up = fst ⊙up\n\n Codes-mer-args : WedgeExt.args {a₀ = pt X} {b₀ = [_] {n = k} (pt X)}\n Codes-mer-args = record {n = S n; m = S n;\n P = λ _ _ → (Trunc k (de⊙ X) , raise-level-≤T kle Trunc-level);\n f = [_]; g = idf _; p = idp}\n\n Codes-mer : de⊙ X → Trunc k (de⊙ X) → Trunc k (de⊙ X)\n Codes-mer = WedgeExt.ext Codes-mer-args\n\n Codes-mer-β-l : (λ a → Codes-mer a [ pt X ]) == [_]\n Codes-mer-β-l = λ= $ WedgeExt.β-l {r = Codes-mer-args}\n\n Codes-mer-β-r : (λ b → Codes-mer (pt X) b) == idf _\n Codes-mer-β-r = λ= $ WedgeExt.β-r {r = Codes-mer-args}\n\n Codes-mer-coh : app= Codes-mer-β-l (pt X) == app= Codes-mer-β-r [ pt X ]\n Codes-mer-coh =\n app= Codes-mer-β-l (pt X)\n =⟨ app=-β (WedgeExt.β-l {r = Codes-mer-args}) (pt X) ⟩\n WedgeExt.β-l {r = Codes-mer-args} (pt X)\n =⟨ ! (move1-left-on-left _ _ (WedgeExt.coh {r = Codes-mer-args})) ⟩\n WedgeExt.β-r {r = Codes-mer-args} [ pt X ]\n =⟨ ! (app=-β (WedgeExt.β-r {r = Codes-mer-args}) [ pt X ]) ⟩\n app= Codes-mer-β-r [ pt X ] ∎\n\n Codes-mer-is-equiv : (x : de⊙ X) → is-equiv (Codes-mer x)\n Codes-mer-is-equiv =\n conn-extend (pointed-conn-out {n = S n} (de⊙ X) (pt X))\n (λ x' → (is-equiv (Codes-mer x') , is-equiv-level))\n (λ tt → transport is-equiv (! (Codes-mer-β-r)) (idf-is-equiv _))\n\n Codes-mer-equiv : (x : de⊙ X) → Trunc k (de⊙ X) ≃ Trunc k (de⊙ X)\n Codes-mer-equiv x = (Codes-mer x , Codes-mer-is-equiv x)\n\n Codes-mer-inv-x₀ : <– (Codes-mer-equiv (pt X)) == idf _\n Codes-mer-inv-x₀ =\n ap is-equiv.g (conn-extend-β\n (pointed-conn-out (de⊙ X) (pt X))\n (λ x' → (is-equiv (Codes-mer x') , is-equiv-level))\n _ unit)\n ∙ lemma (! (Codes-mer-β-r)) (snd $ ide _)\n where lemma : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B}\n (α : f == g) (e : is-equiv f)\n → is-equiv.g (transport is-equiv α e) == is-equiv.g e\n lemma idp e = idp\n\n Codes : Susp (de⊙ X) → Type i\n Codes = SuspRec.f (Trunc k (de⊙ X)) (Trunc k (de⊙ X)) (ua ∘ Codes-mer-equiv)\n\n Codes-has-level : (x : Susp (de⊙ X)) → has-level k (Codes x)\n Codes-has-level = Susp-elim Trunc-level Trunc-level\n (λ _ → prop-has-all-paths-↓)\n\n {-\n favonia:\n\n This equation should be true: [⊙Trunc-fmap ⊙up = (decodeN , decodeN-pt)].\n Maybe there is a way to refactor the following code so that\n pointedness is handled more elegantly.\n -}\n\n decodeN : Codes north → Trunc k (north' (de⊙ X) == north)\n decodeN = Trunc-fmap up\n\n decodeN-pt : decodeN [ pt X ] == [ idp ]\n decodeN-pt = snd (⊙Trunc-fmap ⊙up)\n\n decodeS : Codes south → Q south\n decodeS = Trunc-fmap merid\n\n encode₀ : {x : Susp (de⊙ X)} → north == x → Codes x\n encode₀ α = transport Codes α [ pt X ]\n\n encode : {x : Susp (de⊙ X)} → Trunc k (north == x) → Codes x\n encode {x} tα = Trunc-rec {{Codes-has-level x}} encode₀ tα\n\n abstract\n encode-decodeN : (c : Codes north) → encode (decodeN c) == c\n encode-decodeN = Trunc-elim\n {{λ _ → =-preserves-level Trunc-level}}\n (λ x →\n encode (decodeN [ x ])\n =⟨ idp ⟩\n coe (ap Codes (merid x ∙ ! (merid (pt X)))) [ pt X ]\n =⟨ ap-∙ Codes (merid x) (! (merid (pt X))) |in-ctx (λ w → coe w [ pt X ]) ⟩\n coe (ap Codes (merid x) ∙ ap Codes (! (merid (pt X)))) [ pt X ]\n =⟨ coe-∙ (ap Codes (merid x)) (ap Codes (! (merid (pt X)))) [ pt X ] ⟩\n coe (ap Codes (! (merid (pt X)))) (coe (ap Codes (merid x)) [ pt X ])\n =⟨ SuspRec.merid-β _ _ (ua ∘ Codes-mer-equiv) x\n |in-ctx (λ w → coe (ap Codes (! (merid (pt X)))) (coe w [ pt X ])) ⟩\n coe (ap Codes (! (merid (pt X)))) (coe (ua (Codes-mer-equiv x)) [ pt X ])\n =⟨ coe-β (Codes-mer-equiv x) [ pt X ]\n |in-ctx (λ w → coe (ap Codes (! (merid (pt X)))) w) ⟩\n coe (ap Codes (! (merid (pt X)))) (Codes-mer x [ pt X ])\n =⟨ app= Codes-mer-β-l x\n |in-ctx (λ w → coe (ap Codes (! (merid (pt X)))) w) ⟩\n coe (ap Codes (! (merid (pt X)))) [ x ]\n =⟨ coe-ap-! Codes (merid (pt X)) [ x ] ⟩\n coe! (ap Codes (merid (pt X))) [ x ]\n =⟨ SuspRec.merid-β _ _ (ua ∘ Codes-mer-equiv) (pt X)\n |in-ctx (λ w → coe! w [ x ]) ⟩\n coe! (ua (Codes-mer-equiv (pt X))) [ x ]\n =⟨ coe!-β (Codes-mer-equiv (pt X)) [ x ] ⟩\n <– (Codes-mer-equiv (pt X)) [ x ]\n =⟨ app= Codes-mer-inv-x₀ [ x ] ⟩\n [ x ] ∎)\n\n decode : {x : Susp (de⊙ X)} → Codes x → Q x\n decode {x} = Susp-elim\n {P = λ y → Codes y → Q y}\n decodeN decodeS\n (λ x' → ↓-→-from-transp (λ= (STS x')))\n x\n where\n abstract\n coh : {s₁ s₂ : Susp (de⊙ X)} (p : s₁ == s₂)\n → (ap (λ s → s ∙ p) (!-inv-r p))\n == ∙-assoc p (! p) p ∙ ap (λ s → p ∙ s) (!-inv-l p) ∙ ∙-unit-r p\n coh idp = idp\n\n P : de⊙ X → de⊙ X → (S (n +2+ (S n))) -Type (lmax i i)\n P = λ x₁ x₂ →\n ((transport Q (merid x₁) (Trunc-fmap up [ x₂ ])\n == Trunc-fmap merid (transport Codes (merid x₁) [ x₂ ])),\n =-preserves-level (raise-level-≤T kle Trunc-level))\n\n f : (a : de⊙ X) → fst (P a (pt X))\n f a =\n transport Q (merid a) [ up (pt X) ]\n =⟨ transport-Trunc (north ==_) (merid a) (up (pt X)) ⟩\n [ transport (north ==_) (merid a) (up (pt X)) ]\n =⟨ ap [_] $ transp-cst=idf {A = Susp (de⊙ X)} (merid a) (up (pt X)) ⟩\n [ (merid (pt X) ∙ ! (merid (pt X))) ∙ merid a ]\n =⟨ ap [_] $ ap (λ s → s ∙ merid a) (!-inv-r (merid (pt X))) ⟩\n [ merid a ]\n =⟨ idp ⟩\n Trunc-fmap merid [ a ]\n =⟨ ap (Trunc-fmap merid) (! (app= Codes-mer-β-l a)) ⟩\n Trunc-fmap merid (Codes-mer a [ pt X ])\n =⟨ ap (Trunc-fmap merid) (! (coe-β (Codes-mer-equiv a) [ pt X ])) ⟩\n Trunc-fmap merid (coe (ua (Codes-mer-equiv a)) [ pt X ])\n =⟨ ! (SuspRec.merid-β _ _ (ua ∘ Codes-mer-equiv) a)\n |in-ctx (λ w → Trunc-fmap merid (coe w [ pt X ])) ⟩\n Trunc-fmap merid (transport Codes (merid a) [ pt X ]) ∎\n\n g : (b : de⊙ X) → fst (P (pt X) b)\n g b =\n transport Q (merid (pt X)) [ up b ]\n =⟨ transport-Trunc (north ==_) (merid (pt X)) (up b) ⟩\n [ transport (north ==_) (merid (pt X)) (up b) ]\n =⟨ ap [_] $ transp-cst=idf {A = Susp (de⊙ X)} (merid (pt X)) (up b) ⟩\n [ (merid b ∙ ! (merid (pt X))) ∙ merid (pt X) ]\n =⟨ ap [_] $ ∙-assoc (merid b) (! (merid (pt X))) (merid (pt X))\n ∙ ap (λ s → merid b ∙ s) (!-inv-l (merid (pt X)))\n ∙ ∙-unit-r (merid b) ⟩\n [ merid b ]\n =⟨ idp ⟩\n Trunc-fmap merid [ b ]\n =⟨ ap (Trunc-fmap merid) (! (app= Codes-mer-β-r [ b ])) ⟩\n Trunc-fmap merid (Codes-mer (pt X) [ b ])\n =⟨ ap (Trunc-fmap merid) (! (coe-β (Codes-mer-equiv (pt X)) [ b ])) ⟩\n Trunc-fmap merid (coe (ua (Codes-mer-equiv (pt X))) [ b ])\n =⟨ ! (SuspRec.merid-β _ _ (ua ∘ Codes-mer-equiv) (pt X))\n |in-ctx (λ w → Trunc-fmap merid (coe w [ b ])) ⟩\n Trunc-fmap merid (transport Codes (merid (pt X)) [ b ]) ∎\n\n p : f (pt X) == g (pt X)\n p = ap2\n (λ p₁ p₂ →\n transport Q (merid (pt X)) [ up (pt X) ]\n =⟨ transport-Trunc (north ==_) (merid (pt X)) (up (pt X)) ⟩\n [ transport (north ==_) (merid (pt X)) (up (pt X)) ]\n =⟨ ap [_] $ transp-cst=idf {A = Susp (de⊙ X)} (merid (pt X)) (up (pt X)) ⟩\n [ (merid (pt X) ∙ ! (merid (pt X))) ∙ merid (pt X) ]\n =⟨ ap [_] p₁ ⟩\n [ merid (pt X) ]\n =⟨ idp ⟩\n Trunc-fmap merid [ pt X ]\n =⟨ ap (Trunc-fmap merid) (! p₂) ⟩\n Trunc-fmap merid (Codes-mer (pt X) [ pt X ])\n =⟨ ap (Trunc-fmap merid) (! (coe-β (Codes-mer-equiv (pt X)) [ pt X ])) ⟩\n Trunc-fmap merid (coe (ua (Codes-mer-equiv (pt X))) [ pt X ])\n =⟨ ! (SuspRec.merid-β _ _ (ua ∘ Codes-mer-equiv) (pt X))\n |in-ctx (λ w → Trunc-fmap merid (coe w [ pt X ])) ⟩\n Trunc-fmap merid (transport Codes (merid (pt X)) [ pt X ]) ∎)\n (coh (merid (pt X))) Codes-mer-coh\n\n STS-args : WedgeExt.args {a₀ = pt X} {b₀ = pt X}\n STS-args =\n record {n = S n; m = S n; P = P; f = f; g = g; p = p}\n\n STS : (x' : de⊙ X) (c : Codes north) →\n transport Q (merid x') (Trunc-fmap up c)\n == Trunc-fmap merid (transport Codes (merid x') c)\n STS x' = Trunc-elim {{λ _ → =-preserves-level Trunc-level}}\n (WedgeExt.ext STS-args x')\n\n abstract\n decode-encode : {x : Susp (de⊙ X)} (tα : Q x)\n → decode {x} (encode {x} tα) == tα\n decode-encode {x} = Trunc-elim\n {P = λ tα → decode {x} (encode {x} tα) == tα}\n {{λ _ → =-preserves-level Trunc-level}}\n (J (λ y p → decode {y} (encode {y} [ p ]) == [ p ])\n (ap [_] (!-inv-r (merid (pt X)))))\n\n eq : Trunc k (de⊙ X) ≃ Trunc k (north' (de⊙ X) == north)\n eq = equiv decodeN encode decode-encode encode-decodeN\n\n ⊙eq : ⊙Trunc k X ⊙≃ ⊙Trunc k (⊙Ω (⊙Susp X))\n ⊙eq = ≃-to-⊙≃ eq (ap [_] (!-inv-r (merid (pt X))))\n\n path : Trunc k (de⊙ X) == Trunc k (north' (de⊙ X) == north)\n path = ua eq\n\n ⊙path : ⊙Trunc k X == ⊙Trunc k (⊙Ω (⊙Susp X))\n ⊙path = ⊙ua ⊙eq\n\n{- Used to prove stability in iterated suspensions -}\nmodule FreudenthalIso\n {i} (n : ℕ₋₂) (k : ℕ) (kle : ⟨ S k ⟩ ≤T S n +2+ S n)\n (X : Ptd i) {{_ : is-connected (S (S n)) (de⊙ X)}} where\n\n open FreudenthalEquiv n ⟨ S k ⟩ kle X public\n\n hom : Ω^S-group k (⊙Trunc ⟨ S k ⟩ X)\n →ᴳ Ω^S-group k (⊙Trunc ⟨ S k ⟩ (⊙Ω (⊙Susp X)))\n hom = Ω^S-group-fmap k (decodeN , decodeN-pt)\n\n iso : Ω^S-group k (⊙Trunc ⟨ S k ⟩ X)\n ≃ᴳ Ω^S-group k (⊙Trunc ⟨ S k ⟩ (⊙Ω (⊙Susp X)))\n iso = Ω^S-group-emap k ⊙eq\n", "meta": {"hexsha": "c06bc44e66da5674c7b1af6e7ea18ed60866a3ca", "size": 10275, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/Freudenthal.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/homotopy/Freudenthal.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/homotopy/Freudenthal.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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.8255813953, "max_line_length": 86, "alphanum_fraction": 0.4861313869, "num_tokens": 4177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743563075447, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.3931875560014542}} {"text": "{-# OPTIONS --safe --experimental-lossy-unification #-}\nmodule Cubical.ZCohomology.CohomologyRings.Coproduct where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.HLevels\n\nopen import Cubical.Data.Nat renaming (_+_ to _+n_ ; _·_ to _·n_ ; snotz to nsnotz)\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Sum\n\nopen import Cubical.Algebra.Group\nopen import Cubical.Algebra.Group.Morphisms\nopen import Cubical.Algebra.Group.MorphismProperties\nopen import Cubical.Algebra.Group.DirProd\nopen import Cubical.Algebra.AbGroup\nopen import Cubical.Algebra.Ring\nopen import Cubical.Algebra.Ring.DirectProd\nopen import Cubical.Algebra.DirectSum.DirectSumHIT.Base\n\nopen import Cubical.HITs.SetTruncation as ST\n\nopen import Cubical.ZCohomology.Base\nopen import Cubical.ZCohomology.GroupStructure\nopen import Cubical.ZCohomology.Groups.Coproduct\nopen import Cubical.ZCohomology.RingStructure.CupProduct\nopen import Cubical.ZCohomology.RingStructure.CohomologyRing\n\nprivate variable\n ℓ ℓ' : Level\n\nmodule Equiv-Coproduct-Properties\n {X : Type ℓ}\n {Y : Type ℓ'}\n where\n\n open Iso\n open IsGroupHom\n open GroupStr\n open PlusBis\n\n open RingStr (snd (H*R X)) using ()\n renaming\n ( 0r to 0H*X\n ; 1r to 1H*X\n ; _+_ to _+H*X_\n ; -_ to -H*X_\n ; _·_ to _cupX_\n ; +Assoc to +H*XAssoc\n ; +IdL to +H*XIdL\n ; +IdR to +H*XIdR\n ; +Comm to +H*XComm\n ; ·Assoc to ·H*XAssoc\n ; ·IdL to ·H*XIdL\n ; ·IdR to ·H*XIdR\n ; is-set to isSetH*X )\n\n open RingStr (snd (H*R Y)) using ()\n renaming\n ( 0r to 0H*Y\n ; 1r to 1H*Y\n ; _+_ to _+H*Y_\n ; -_ to -H*Y_\n ; _·_ to _cupY_\n ; +Assoc to +H*YAssoc\n ; +IdL to +H*YIdL\n ; +IdR to +H*YIdR\n ; +Comm to +H*YComm\n ; ·Assoc to ·H*YAssoc\n ; ·IdL to ·H*YIdL\n ; ·IdR to ·H*YIdR\n ; is-set to isSetH*Y )\n\n -- warning this does not open H*(X×Y) !\n -- This just a notation shorter and pratical\n open RingStr (snd (DirectProd-Ring (H*R X) (H*R Y))) using ()\n renaming\n ( 0r to 0H*X×Y\n ; 1r to 1H*X×Y\n ; _+_ to _+H*X×Y_\n ; -_ to -H*X×Y_\n ; _·_ to _cupX×Y_\n ; +Assoc to +H*X×YAssoc\n ; +IdL to +H*X×YIdL\n ; +IdR to +H*X×YIdR\n ; +Comm to +H*X×YComm\n ; ·Assoc to ·H*X×YAssoc\n ; ·IdL to ·H*X×YIdL\n ; ·IdR to ·H*X×YIdR\n ; is-set to isSetH*X×Y )\n\n open RingStr (snd (H*R (X ⊎ Y))) using ()\n renaming\n ( 0r to 0H*X⊎Y\n ; 1r to 1H*X⊎Y\n ; _+_ to _+H*X⊎Y_\n ; -_ to -H*X⊎Y_\n ; _·_ to _cupX⊎Y_\n ; +Assoc to +H*X⊎YAssoc\n ; +IdL to +H*X⊎YIdL\n ; +IdR to +H*X⊎YIdR\n ; +Comm to +H*X⊎YComm\n ; ·Assoc to ·H*X⊎YAssoc\n ; ·IdL to ·H*X⊎YIdL\n ; ·IdR to ·H*X⊎YIdR\n ; is-set to isSetH*X⊎Y )\n\n\n-----------------------------------------------------------------------------\n-- Notation needed for type checking\n-- indeed several base coexists and two cannot be inferef without implicit argument\n-- it is clearer to add a notation\n\n baseX : (n : ℕ) → (x : coHom n X) → H* X\n baseX n x = base n x\n\n baseY : (n : ℕ) → (x : coHom n Y) → H* Y\n baseY n x = base n x\n\n-----------------------------------------------------------------------------\n-- Direct Sens\n\n H*-X⊎Y→H*-X×H*-Y : H* (X ⊎ Y) → (H* X) × (H* Y)\n H*-X⊎Y→H*-X×H*-Y =\n DS-Rec-Set.f _ _ _ _\n isSetH*X×Y\n (0H*X , 0H*Y)\n (λ n a → (base n (fst (fun (fst Equiv-Coproduct-CoHom) a))) , (base n (snd (fun (fst Equiv-Coproduct-CoHom) a))))\n _+H*X×Y_\n +H*X×YAssoc\n +H*X×YIdR\n +H*X×YComm\n (λ n → ≡-× ((cong (λ A → baseX n (fst A)) (pres1 (snd Equiv-Coproduct-CoHom))) ∙ base-neutral n)\n (((cong (λ B → baseY n (snd B)) (pres1 (snd Equiv-Coproduct-CoHom))) ∙ base-neutral n)))\n λ n a b → sym (≡-× (cong (λ A → baseX n (fst A)) (pres· (snd Equiv-Coproduct-CoHom) a b)\n ∙ cong (base n) (helper1 _ _ _)\n ∙ sym (base-add n _ _))\n (cong (λ B → baseY n (snd B)) (pres· (snd Equiv-Coproduct-CoHom) a b)\n ∙ cong (base n) (helper2 _ _ _)\n ∙ sym (base-add n _ _)))\n where\n helper1 : (n : ℕ) → (x y : coHom n X × coHom n Y)\n → fst ((DirProd (coHomGr n X) (coHomGr n Y) .snd GroupStr.· x) y) ≡ ((fst x) +ₕ (fst y))\n helper1 n (fst₁ , snd₁) (fst₂ , snd₂) = refl\n\n helper2 : (n : ℕ) → (x y : coHom n X × coHom n Y)\n → snd ((DirProd (coHomGr n X) (coHomGr n Y) .snd GroupStr.· x) y) ≡ ((snd x) +ₕ (snd y))\n helper2 n (fst₁ , snd₁) (fst₂ , snd₂) = refl\n\n-----------------------------------------------------------------------------\n-- Converse Sens\n\n-- One need to convert seperatly the X an Y\n-- Otherwise the traduction fails in the case base n a , 0\n-- because one need then to lift x + 0 ≡ 0\n-- which doesn't work because the + being lifted is on H*(Y) and not H*(X)×H*(Y)\n\n H*-X→H*-X⊎Y : H*(X) → H*(X ⊎ Y)\n H*-X→H*-X⊎Y = DS-Rec-Set.f _ _ _ _ isSetH*X⊎Y\n 0H*X⊎Y\n (λ n a → base n (inv (fst Equiv-Coproduct-CoHom) (a , (0ₕ n))))\n _+H*X⊎Y_\n +H*X⊎YAssoc\n +H*X⊎YIdR\n +H*X⊎YComm\n (λ n → cong (base n) (pres1 (snd (invGroupIso Equiv-Coproduct-CoHom))) ∙ base-neutral n)\n λ n a a' → base-add _ _ _\n ∙ cong (base n) (sym (pres· (snd (invGroupIso Equiv-Coproduct-CoHom)) _ _))\n ∙ cong (base n) (cong (inv (fst Equiv-Coproduct-CoHom))\n (≡-× refl (AbGroupStr.+IdL (snd (coHomGroup n Y)) (0ₕ n))))\n\n H*-Y→H*-X⊎Y : H*(Y) → H*(X ⊎ Y)\n H*-Y→H*-X⊎Y = DS-Rec-Set.f _ _ _ _ isSetH*X⊎Y\n 0H*X⊎Y\n (λ m b → base m (inv (fst Equiv-Coproduct-CoHom) (0ₕ m , b)))\n _+H*X⊎Y_\n +H*X⊎YAssoc\n +H*X⊎YIdR\n +H*X⊎YComm\n (λ m → cong (base m) (pres1 (snd (invGroupIso Equiv-Coproduct-CoHom))) ∙ base-neutral m)\n λ m b b' → base-add _ _ _\n ∙ cong (base m) (sym (pres· (snd (invGroupIso Equiv-Coproduct-CoHom)) (0ₕ m , b) (0ₕ m , b')))\n ∙ cong (base m) (cong (inv (fst Equiv-Coproduct-CoHom)) (≡-× (AbGroupStr.+IdL (snd (coHomGroup m X)) (0ₕ m)) refl))\n\n\n H*-X×H*-Y→H*-X⊎Y : H*(X) × H*(Y) → H*(X ⊎ Y)\n H*-X×H*-Y→H*-X⊎Y (x , y) = (H*-X→H*-X⊎Y x) +H*X⊎Y (H*-Y→H*-X⊎Y y)\n\n H*-X×H*-Y→H*-X⊎Y-pres+ : (x y : H*(X) × H*(Y)) → H*-X×H*-Y→H*-X⊎Y (x +H*X×Y y) ≡ ((H*-X×H*-Y→H*-X⊎Y x) +H*X⊎Y (H*-X×H*-Y→H*-X⊎Y y))\n H*-X×H*-Y→H*-X⊎Y-pres+ (x , y) (x' , y') = RingTheory.+ShufflePairs (H*R (X ⊎ Y)) _ _ _ _\n\n-----------------------------------------------------------------------------\n-- Section Sens\n\n e-sectX : (x : H* X) → H*-X⊎Y→H*-X×H*-Y (H*-X→H*-X⊎Y x) ≡ (x , 0H*Y)\n e-sectX = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X×Y _ _)\n refl\n (λ n a → ≡-× (cong (base n) (cong fst (rightInv (fst Equiv-Coproduct-CoHom) (a , 0ₕ n))))\n (cong (base n) (cong snd (rightInv (fst Equiv-Coproduct-CoHom) (a , 0ₕ n))))\n ∙ ≡-× refl (base-neutral n))\n λ {U V} ind-U ind-V → cong₂ _+H*X×Y_ ind-U ind-V ∙ ≡-× refl (+H*YIdR _)\n\n e-sectY : (y : H* Y) → (H*-X⊎Y→H*-X×H*-Y (H*-Y→H*-X⊎Y y)) ≡ (0H*X , y)\n e-sectY = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X×Y _ _)\n refl\n (λ m b → ≡-× (cong (base m) (cong fst (rightInv (fst Equiv-Coproduct-CoHom) (0ₕ m , b))))\n (cong (base m) (cong snd (rightInv (fst Equiv-Coproduct-CoHom) (0ₕ m , b))))\n ∙ ≡-× (base-neutral m) refl)\n λ {U V} ind-U ind-V → cong₂ _+H*X×Y_ ind-U ind-V ∙ ≡-× (+H*XIdR _) refl\n\n e-sect : (z : H*(X) × H*(Y)) → H*-X⊎Y→H*-X×H*-Y (H*-X×H*-Y→H*-X⊎Y z) ≡ z\n e-sect (x , y) = cong₂ _+H*X×Y_ (e-sectX x) (e-sectY y) ∙ ≡-× (+H*XIdR x) (+H*YIdL y)\n\n\n\n-----------------------------------------------------------------------------\n-- Retraction Sens\n\n e-retr : (x : H*(X ⊎ Y)) → H*-X×H*-Y→H*-X⊎Y (H*-X⊎Y→H*-X×H*-Y x) ≡ x\n e-retr = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X⊎Y _ _)\n (+H*X⊎YIdR _)\n (λ n a → ((base n (T⁻ ((fst (T a)) , 0ₕ n))) +H*X⊎Y (base n (T⁻ (0ₕ n , snd (T a)))))\n ≡⟨ base-add n _ _ ⟩\n base n ((T⁻ ((fst (T a)) , 0ₕ n)) +ₕ (T⁻ (0ₕ n , snd (T a))))\n ≡⟨ cong (base n) (sym (pres· (snd (invGroupIso Equiv-Coproduct-CoHom)) ((fst (T a)) , 0ₕ n) (0ₕ n , snd (T a)))) ⟩\n base n (T⁻ ( fst (T a) +ₕ 0ₕ n , 0ₕ n +ₕ snd (T a)))\n ≡⟨ cong (base n) (cong T⁻ (≡-× (rUnitₕ n (fst (T a))) (lUnitₕ n (snd (T a))))) ⟩\n base n (T⁻ ( fst (T a) , snd (T a)))\n ≡⟨ cong (base n) (cong T⁻ (helper1 _ _ (T a))) ⟩\n base n (T⁻ (T a))\n ≡⟨ cong (base n) (leftInv (fst Equiv-Coproduct-CoHom) a) ⟩\n base n a ∎)\n λ {U V} ind-U ind-V → (H*-X×H*-Y→H*-X⊎Y-pres+ _ _) ∙ (cong₂ _+H*X⊎Y_ ind-U ind-V)\n\n where\n T : {n : ℕ} → coHom n (X ⊎ Y) → coHom n X × coHom n Y\n T {n} = fun (fst (Equiv-Coproduct-CoHom))\n\n T⁻ : {n : ℕ} → coHom n X × coHom n Y → coHom n (X ⊎ Y)\n T⁻ {n} = inv (fst (Equiv-Coproduct-CoHom))\n\n helper1 : (A : Type ℓ) → (B : Type ℓ') → (x : A × B) → (fst x , snd x) ≡ x\n helper1 A B (fst₁ , snd₁) = refl\n\n-----------------------------------------------------------------------------\n-- Ring Equiv-Coproduct-CoHomphism\n\n H*-X⊎Y→H*-X×H*-Y-pres1 : H*-X⊎Y→H*-X×H*-Y 1H*X⊎Y ≡ (1H*X , 1H*Y)\n H*-X⊎Y→H*-X×H*-Y-pres1 = refl\n\n H*-X⊎Y→H*-X×H*-Y-pres+ : (x y : H* (X ⊎ Y)) →\n H*-X⊎Y→H*-X×H*-Y ( x +H*X⊎Y y)\n ≡ H*-X⊎Y→H*-X×H*-Y x +H*X×Y H*-X⊎Y→H*-X×H*-Y y\n H*-X⊎Y→H*-X×H*-Y-pres+ x y = refl\n\n H*-X⊎Y→H*-X×H*-Y-pres· : (x y : H* (X ⊎ Y)) →\n H*-X⊎Y→H*-X×H*-Y ( x cupX⊎Y y)\n ≡ H*-X⊎Y→H*-X×H*-Y x cupX×Y H*-X⊎Y→H*-X×H*-Y y\n H*-X⊎Y→H*-X×H*-Y-pres· = DS-Ind-Prop.f _ _ _ _ (λ x p q i y → isSetH*X×Y _ _ (p y) (q y) i)\n (λ y → refl)\n (λ n a → DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH*X×Y _ _)\n refl\n (λ m b → (base (n +' m) (fst (T (a ⌣ b)))) , base (n +' m) (snd (T (a ⌣ b)))\n ≡⟨ ≡-× (cong (base (n +' m)) (helperX a b))\n (cong (base (n +' m)) (helperY a b)) ⟩\n (base (n +' m) ((fst (T a)) ⌣ (fst (T b)))) , base (n +' m) ((snd (T a)) ⌣ (snd (T b))) ∎ )\n λ {U V} ind-U ind-V → cong₂ _+H*X×Y_ ind-U ind-V)\n (λ {U V} ind-U ind-V y → cong₂ _+H*X×Y_ (ind-U y) (ind-V y))\n\n where\n T : {n : ℕ} → coHom n (X ⊎ Y) → coHom n X × coHom n Y\n T {n} = fun (fst (Equiv-Coproduct-CoHom))\n\n helperX : {n : ℕ} → {m : ℕ} → (a : coHom n (X ⊎ Y)) → (b : coHom m (X ⊎ Y))\n → fst (T (a ⌣ b)) ≡ (fst (T a)) ⌣ (fst (T b))\n helperX = ST.elim (λ x → isProp→isSet λ u v i y → squash₂ _ _ (u y) (v y) i )\n λ g → ST.elim (λ _ → isProp→isSet (squash₂ _ _))\n (λ h → refl)\n\n helperY : {n : ℕ} → {m : ℕ} → (a : coHom n (X ⊎ Y)) → (b : coHom m (X ⊎ Y))\n → snd (T (a ⌣ b)) ≡ (snd (T a)) ⌣ (snd (T b))\n helperY = ST.elim (λ x → isProp→isSet λ u v i y → squash₂ _ _ (u y) (v y) i )\n λ g → ST.elim (λ _ → isProp→isSet (squash₂ _ _))\n (λ h → refl)\n\n\n\n-----------------------------------------------------------------------------\n-- Computation of the Cohomology Ring\n\nmodule _\n (X : Type ℓ)\n (Y : Type ℓ')\n where\n\n open Equiv-Coproduct-Properties\n open Iso\n open RingEquivs\n\n CohomologyRing-Coproduct : RingEquiv (H*R(X ⊎ Y)) (DirectProd-Ring (H*R X) (H*R Y))\n fst (CohomologyRing-Coproduct) = isoToEquiv is\n where\n is : Iso (H* (X ⊎ Y)) (H* X × H* Y)\n fun is = H*-X⊎Y→H*-X×H*-Y\n inv is = H*-X×H*-Y→H*-X⊎Y\n rightInv is = e-sect\n leftInv is = e-retr\n snd (CohomologyRing-Coproduct) = makeIsRingHom\n H*-X⊎Y→H*-X×H*-Y-pres1\n H*-X⊎Y→H*-X×H*-Y-pres+\n H*-X⊎Y→H*-X×H*-Y-pres·\n", "meta": {"hexsha": "12c5b4efb8bd04eabb4ce3ea7409e70a7fe45fa1", "size": 12453, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/ZCohomology/CohomologyRings/Coproduct.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/ZCohomology/CohomologyRings/Coproduct.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/ZCohomology/CohomologyRings/Coproduct.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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.785942492, "max_line_length": 141, "alphanum_fraction": 0.4548301614, "num_tokens": 5033, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191460821871, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3931301755940354}} {"text": "------------------------------------------------------------------------\n-- Encoder and decoder instances\n------------------------------------------------------------------------\n\nopen import Atom\n\nmodule Coding.Instances (atoms : χ-atoms) where\n\nopen import Prelude\n\nopen import Chi atoms\nopen import Free-variables atoms\nopen import Values atoms\n\nopen χ-atoms atoms\n\nopen import Coding atoms as Coding using (Rep; module Code)\n\ninstance\n\n rep-Consts-Exp : ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ →\n Rep A Exp\n rep-Consts-Exp = Coding.rep-Consts-Exp\n\n rep-Consts-Closed-exp :\n ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ → Rep A Closed-exp\n rep-Consts-Closed-exp = Coding.rep-Consts-Closed-exp\n\n rep-Bool : Rep Bool Consts\n rep-Bool = Code.rep Coding.code-Bool\n\n rep-ℕ : Rep ℕ Consts\n rep-ℕ = Code.rep Coding.code-ℕ\n\n rep-Var : Rep Var Consts\n rep-Var = Code.rep Coding.code-Var\n\n rep-Const : Rep Const Consts\n rep-Const = Code.rep Coding.code-Const\n\n rep-× : ∀ {a b} {A : Type a} {B : Type b}\n ⦃ c : Rep A Consts ⦄ ⦃ d : Rep B Consts ⦄ →\n Rep (A × B) Consts\n rep-× = Coding.rep-×\n\n rep-Var⋆ : Rep (List Var) Consts\n rep-Var⋆ = Code.rep Coding.code-Var⋆\n\n rep-Exp : Rep Exp Consts\n rep-Exp = Code.rep Coding.code-Exp\n\n rep-Br : Rep Br Consts\n rep-Br = Code.rep Coding.code-Br\n\n rep-Exps : Rep (List Exp) Consts\n rep-Exps = Code.rep Coding.code-Exps\n\n rep-Brs : Rep (List Br) Consts\n rep-Brs = Code.rep Coding.code-Brs\n\n rep-Closed : Rep Closed-exp Consts\n rep-Closed = Code.rep Coding.code-Closed\n", "meta": {"hexsha": "e37e6d2f764d6c2e802d6291cdd41a765aecfcb2", "size": 1580, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Coding/Instances.agda", "max_stars_repo_name": "nad/chi", "max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z", "max_issues_repo_path": "src/Coding/Instances.agda", "max_issues_repo_name": "nad/chi", "max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z", "max_forks_repo_path": "src/Coding/Instances.agda", "max_forks_repo_name": "nad/chi", "max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "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": 25.0793650794, "max_line_length": 72, "alphanum_fraction": 0.582278481, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7090191337850933, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3931301687756601}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.HITs.Rationals.QuoQ.Properties where\n\nopen import Cubical.Foundations.Everything hiding (_⁻¹)\n\nopen import Cubical.HITs.Ints.QuoInt as ℤ using (ℤ; Sign; signed; pos; neg; posneg; sign)\nopen import Cubical.HITs.SetQuotients as SetQuotient using () renaming (_/_ to _//_)\n\nopen import Cubical.Data.Nat as ℕ using (ℕ; zero; suc)\nopen import Cubical.Data.NatPlusOne\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Data.Sum\nopen import Cubical.Relation.Nullary\n\nopen import Cubical.HITs.Rationals.QuoQ.Base\n\nℚ-cancelˡ : ∀ {a b} (c : ℕ₊₁) → [ ℕ₊₁→ℤ c ℤ.· a / c ·₊₁ b ] ≡ [ a / b ]\nℚ-cancelˡ {a} {b} c = eq/ _ _\n (cong (ℤ._· ℕ₊₁→ℤ b) (ℤ.·-comm (ℕ₊₁→ℤ c) a) ∙ sym (ℤ.·-assoc a (ℕ₊₁→ℤ c) (ℕ₊₁→ℤ b)))\n\nℚ-cancelʳ : ∀ {a b} (c : ℕ₊₁) → [ a ℤ.· ℕ₊₁→ℤ c / b ·₊₁ c ] ≡ [ a / b ]\nℚ-cancelʳ {a} {b} c = eq/ _ _\n (sym (ℤ.·-assoc a (ℕ₊₁→ℤ c) (ℕ₊₁→ℤ b)) ∙ cong (a ℤ.·_) (ℤ.·-comm (ℕ₊₁→ℤ c) (ℕ₊₁→ℤ b)))\n\n-- useful functions for defining operations on ℚ\n\nonCommonDenom :\n (g : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → ℤ)\n (g-eql : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : a ℤ.· ℕ₊₁→ℤ d ≡ c ℤ.· ℕ₊₁→ℤ b)\n → ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) ≡ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)))\n (g-eqr : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : c ℤ.· ℕ₊₁→ℤ f ≡ e ℤ.· ℕ₊₁→ℤ d)\n → (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f ≡ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d)\n → ℚ → ℚ → ℚ\nonCommonDenom g g-eql g-eqr = SetQuotient.rec2 isSetℚ\n (λ { (a , b) (c , d) → [ g (a , b) (c , d) / b ·₊₁ d ] })\n (λ { (a , b) (c , d) (e , f) p → eql (a , b) (c , d) (e , f) p })\n (λ { (a , b) (c , d) (e , f) p → eqr (a , b) (c , d) (e , f) p })\n where eql : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : a ℤ.· ℕ₊₁→ℤ d ≡ c ℤ.· ℕ₊₁→ℤ b)\n → [ g (a , b) (e , f) / b ·₊₁ f ] ≡ [ g (c , d) (e , f) / d ·₊₁ f ]\n eql (a , b) (c , d) (e , f) p =\n [ g (a , b) (e , f) / b ·₊₁ f ]\n ≡⟨ sym (ℚ-cancelˡ d) ⟩\n [ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) / d ·₊₁ (b ·₊₁ f) ]\n ≡[ i ]⟨ [ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) / ·₊₁-assoc d b f i ] ⟩\n [ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) / (d ·₊₁ b) ·₊₁ f ]\n ≡[ i ]⟨ [ g-eql (a , b) (c , d) (e , f) p i / ·₊₁-comm d b i ·₊₁ f ] ⟩\n [ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)) / (b ·₊₁ d) ·₊₁ f ]\n ≡[ i ]⟨ [ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)) / ·₊₁-assoc b d f (~ i) ] ⟩\n [ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)) / b ·₊₁ (d ·₊₁ f) ]\n ≡⟨ ℚ-cancelˡ b ⟩\n [ g (c , d) (e , f) / d ·₊₁ f ] ∎\n eqr : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : c ℤ.· ℕ₊₁→ℤ f ≡ e ℤ.· ℕ₊₁→ℤ d)\n → [ g (a , b) (c , d) / b ·₊₁ d ] ≡ [ g (a , b) (e , f) / b ·₊₁ f ]\n eqr (a , b) (c , d) (e , f) p =\n [ g (a , b) (c , d) / b ·₊₁ d ]\n ≡⟨ sym (ℚ-cancelʳ f) ⟩\n [ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f / (b ·₊₁ d) ·₊₁ f ]\n ≡[ i ]⟨ [ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f / ·₊₁-assoc b d f (~ i) ] ⟩\n [ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f / b ·₊₁ (d ·₊₁ f) ]\n ≡[ i ]⟨ [ g-eqr (a , b) (c , d) (e , f) p i / b ·₊₁ ·₊₁-comm d f i ] ⟩\n [ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d / b ·₊₁ (f ·₊₁ d) ]\n ≡[ i ]⟨ [ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d / ·₊₁-assoc b f d i ] ⟩\n [ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d / (b ·₊₁ f) ·₊₁ d ]\n ≡⟨ ℚ-cancelʳ d ⟩\n [ g (a , b) (e , f) / b ·₊₁ f ] ∎\n\nonCommonDenomSym :\n (g : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → ℤ)\n (g-sym : ∀ x y → g x y ≡ g y x)\n (g-eql : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : a ℤ.· ℕ₊₁→ℤ d ≡ c ℤ.· ℕ₊₁→ℤ b)\n → ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) ≡ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)))\n → ℚ → ℚ → ℚ\nonCommonDenomSym g g-sym g-eql = onCommonDenom g g-eql q-eqr\n where q-eqr : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : c ℤ.· ℕ₊₁→ℤ f ≡ e ℤ.· ℕ₊₁→ℤ d)\n → (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f ≡ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d\n q-eqr (a , b) (c , d) (e , f) p =\n (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f ≡[ i ]⟨ ℤ.·-comm (g-sym (a , b) (c , d) i) (ℕ₊₁→ℤ f) i ⟩\n ℕ₊₁→ℤ f ℤ.· (g (c , d) (a , b)) ≡⟨ g-eql (c , d) (e , f) (a , b) p ⟩\n ℕ₊₁→ℤ d ℤ.· (g (e , f) (a , b)) ≡[ i ]⟨ ℤ.·-comm (ℕ₊₁→ℤ d) (g-sym (e , f) (a , b) i) i ⟩\n (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d ∎\n\nonCommonDenomSym-comm : ∀ {g} g-sym {g-eql} (x y : ℚ)\n → onCommonDenomSym g g-sym g-eql x y ≡\n onCommonDenomSym g g-sym g-eql y x\nonCommonDenomSym-comm g-sym = SetQuotient.elimProp2 (λ _ _ → isSetℚ _ _)\n (λ { (a , b) (c , d) i → [ g-sym (a , b) (c , d) i / ·₊₁-comm b d i ] })\n\n\n-- basic arithmetic operations on ℚ\n\ninfixl 6 _+_\ninfixl 7 _·_\n\nprivate\n lem₁ : ∀ a b c d e (p : a ℤ.· b ≡ c ℤ.· d) → b ℤ.· (a ℤ.· e) ≡ d ℤ.· (c ℤ.· e)\n lem₁ a b c d e p = ℤ.·-assoc b a e\n ∙ cong (ℤ._· e) (ℤ.·-comm b a ∙ p ∙ ℤ.·-comm c d)\n ∙ sym (ℤ.·-assoc d c e)\n\n lem₂ : ∀ a b c → a ℤ.· (b ℤ.· c) ≡ c ℤ.· (b ℤ.· a)\n lem₂ a b c = cong (a ℤ.·_) (ℤ.·-comm b c) ∙ ℤ.·-assoc a c b\n ∙ cong (ℤ._· b) (ℤ.·-comm a c) ∙ sym (ℤ.·-assoc c a b)\n ∙ cong (c ℤ.·_) (ℤ.·-comm a b)\n\n_+_ : ℚ → ℚ → ℚ\n_+_ = onCommonDenomSym\n (λ { (a , b) (c , d) → a ℤ.· (ℕ₊₁→ℤ d) ℤ.+ c ℤ.· (ℕ₊₁→ℤ b) })\n (λ { (a , b) (c , d) → ℤ.+-comm (a ℤ.· (ℕ₊₁→ℤ d)) (c ℤ.· (ℕ₊₁→ℤ b)) })\n (λ { (a , b) (c , d) (e , f) p →\n ℕ₊₁→ℤ d ℤ.· (a ℤ.· ℕ₊₁→ℤ f ℤ.+ e ℤ.· ℕ₊₁→ℤ b)\n ≡⟨ sym (ℤ.·-distribˡ (ℕ₊₁→ℤ d) (a ℤ.· ℕ₊₁→ℤ f) (e ℤ.· ℕ₊₁→ℤ b)) ⟩\n ℕ₊₁→ℤ d ℤ.· (a ℤ.· ℕ₊₁→ℤ f) ℤ.+ ℕ₊₁→ℤ d ℤ.· (e ℤ.· ℕ₊₁→ℤ b)\n ≡[ i ]⟨ lem₁ a (ℕ₊₁→ℤ d) c (ℕ₊₁→ℤ b) (ℕ₊₁→ℤ f) p i ℤ.+ lem₂ (ℕ₊₁→ℤ d) e (ℕ₊₁→ℤ b) i ⟩\n ℕ₊₁→ℤ b ℤ.· (c ℤ.· ℕ₊₁→ℤ f) ℤ.+ ℕ₊₁→ℤ b ℤ.· (e ℤ.· ℕ₊₁→ℤ d)\n ≡⟨ ℤ.·-distribˡ (ℕ₊₁→ℤ b) (c ℤ.· ℕ₊₁→ℤ f) (e ℤ.· ℕ₊₁→ℤ d) ⟩\n ℕ₊₁→ℤ b ℤ.· (c ℤ.· ℕ₊₁→ℤ f ℤ.+ e ℤ.· ℕ₊₁→ℤ d) ∎ })\n\n+-comm : ∀ x y → x + y ≡ y + x\n+-comm = onCommonDenomSym-comm\n (λ { (a , b) (c , d) → ℤ.+-comm (a ℤ.· (ℕ₊₁→ℤ d)) (c ℤ.· (ℕ₊₁→ℤ b)) })\n\n+-identityˡ : ∀ x → 0 + x ≡ x\n+-identityˡ = SetQuotient.elimProp (λ _ → isSetℚ _ _)\n (λ { (a , b) i → [ ℤ.·-identityʳ a i / ·₊₁-identityˡ b i ] })\n\n+-identityʳ : ∀ x → x + 0 ≡ x\n+-identityʳ x = +-comm x _ ∙ +-identityˡ x\n\n+-assoc : ∀ x y z → x + (y + z) ≡ (x + y) + z\n+-assoc = SetQuotient.elimProp3 (λ _ _ _ → isSetℚ _ _)\n (λ { (a , b) (c , d) (e , f) i → [ eq a (ℕ₊₁→ℤ b) c (ℕ₊₁→ℤ d) e (ℕ₊₁→ℤ f) i / ·₊₁-assoc b d f i ] })\n where eq₁ : ∀ a b c → (a ℤ.· b) ℤ.· c ≡ a ℤ.· (c ℤ.· b)\n eq₁ a b c = sym (ℤ.·-assoc a b c) ∙ cong (a ℤ.·_) (ℤ.·-comm b c)\n eq₂ : ∀ a b c → (a ℤ.· b) ℤ.· c ≡ (a ℤ.· c) ℤ.· b\n eq₂ a b c = eq₁ a b c ∙ ℤ.·-assoc a c b\n\n eq : ∀ a b c d e f → Path ℤ _ _\n eq a b c d e f =\n a ℤ.· (d ℤ.· f) ℤ.+ (c ℤ.· f ℤ.+ e ℤ.· d) ℤ.· b\n ≡[ i ]⟨ a ℤ.· (d ℤ.· f) ℤ.+ ℤ.·-distribʳ (c ℤ.· f) (e ℤ.· d) b (~ i) ⟩\n a ℤ.· (d ℤ.· f) ℤ.+ ((c ℤ.· f) ℤ.· b ℤ.+ (e ℤ.· d) ℤ.· b)\n ≡[ i ]⟨ ℤ.+-assoc (ℤ.·-assoc a d f i) (eq₂ c f b i) (eq₁ e d b i) i ⟩\n ((a ℤ.· d) ℤ.· f ℤ.+ (c ℤ.· b) ℤ.· f) ℤ.+ e ℤ.· (b ℤ.· d)\n ≡[ i ]⟨ ℤ.·-distribʳ (a ℤ.· d) (c ℤ.· b) f i ℤ.+ e ℤ.· (b ℤ.· d) ⟩\n (a ℤ.· d ℤ.+ c ℤ.· b) ℤ.· f ℤ.+ e ℤ.· (b ℤ.· d) ∎\n\n\n_·_ : ℚ → ℚ → ℚ\n_·_ = onCommonDenomSym\n (λ { (a , _) (c , _) → a ℤ.· c })\n (λ { (a , _) (c , _) → ℤ.·-comm a c })\n (λ { (a , b) (c , d) (e , _) p → lem₁ a (ℕ₊₁→ℤ d) c (ℕ₊₁→ℤ b) e p })\n\n·-comm : ∀ x y → x · y ≡ y · x\n·-comm = onCommonDenomSym-comm (λ { (a , _) (c , _) → ℤ.·-comm a c })\n\n·-identityˡ : ∀ x → 1 · x ≡ x\n·-identityˡ = SetQuotient.elimProp (λ _ → isSetℚ _ _)\n (λ { (a , b) i → [ ℤ.·-identityˡ a i / ·₊₁-identityˡ b i ] })\n\n·-identityʳ : ∀ x → x · 1 ≡ x\n·-identityʳ = SetQuotient.elimProp (λ _ → isSetℚ _ _)\n (λ { (a , b) i → [ ℤ.·-identityʳ a i / ·₊₁-identityʳ b i ] })\n\n·-zeroˡ : ∀ x → 0 · x ≡ 0\n·-zeroˡ = SetQuotient.elimProp (λ _ → isSetℚ _ _)\n (λ { (a , b) → (λ i → [ p a b i / 1 ·₊₁ b ]) ∙ ℚ-cancelʳ b })\n where p : ∀ a b → 0 ℤ.· a ≡ 0 ℤ.· ℕ₊₁→ℤ b\n p a b = ℤ.·-zeroˡ {ℤ.spos} a ∙ sym (ℤ.·-zeroˡ {ℤ.spos} (ℕ₊₁→ℤ b))\n\n·-zeroʳ : ∀ x → x · 0 ≡ 0\n·-zeroʳ = SetQuotient.elimProp (λ _ → isSetℚ _ _)\n (λ { (a , b) → (λ i → [ p a b i / b ·₊₁ 1 ]) ∙ ℚ-cancelˡ b })\n where p : ∀ a b → a ℤ.· 0 ≡ ℕ₊₁→ℤ b ℤ.· 0\n p a b = ℤ.·-zeroʳ {ℤ.spos} a ∙ sym (ℤ.·-zeroʳ {ℤ.spos} (ℕ₊₁→ℤ b))\n\n·-assoc : ∀ x y z → x · (y · z) ≡ (x · y) · z\n·-assoc = SetQuotient.elimProp3 (λ _ _ _ → isSetℚ _ _)\n (λ { (a , b) (c , d) (e , f) i → [ ℤ.·-assoc a c e i / ·₊₁-assoc b d f i ] })\n\n·-distribˡ : ∀ x y z → (x · y) + (x · z) ≡ x · (y + z)\n·-distribˡ = SetQuotient.elimProp3 (λ _ _ _ → isSetℚ _ _)\n (λ { (a , b) (c , d) (e , f) → eq a b c d e f })\n where lem : ∀ {ℓ} {A : Type ℓ} (_·_ : A → A → A)\n (·-comm : ∀ x y → x · y ≡ y · x)\n (·-assoc : ∀ x y z → x · (y · z) ≡ (x · y) · z)\n a c b d\n → (a · c) · (b · d) ≡ (a · (c · d)) · b\n lem _·_ ·-comm ·-assoc a c b d =\n (a · c) · (b · d) ≡[ i ]⟨ (a · c) · ·-comm b d i ⟩\n (a · c) · (d · b) ≡⟨ ·-assoc (a · c) d b ⟩\n ((a · c) · d) · b ≡[ i ]⟨ ·-assoc a c d (~ i) · b ⟩\n (a · (c · d)) · b ∎\n\n lemℤ = lem ℤ._·_ ℤ.·-comm ℤ.·-assoc\n lemℕ₊₁ = lem _·₊₁_ ·₊₁-comm ·₊₁-assoc\n\n eq : ∀ a b c d e f →\n [ (a ℤ.· c) ℤ.· ℕ₊₁→ℤ (b ·₊₁ f) ℤ.+ (a ℤ.· e) ℤ.· ℕ₊₁→ℤ (b ·₊₁ d)\n / (b ·₊₁ d) ·₊₁ (b ·₊₁ f) ]\n ≡ [ a ℤ.· (c ℤ.· ℕ₊₁→ℤ f ℤ.+ e ℤ.· ℕ₊₁→ℤ d)\n / b ·₊₁ (d ·₊₁ f) ]\n eq a b c d e f =\n (λ i → [ lemℤ a c (ℕ₊₁→ℤ b) (ℕ₊₁→ℤ f) i ℤ.+ lemℤ a e (ℕ₊₁→ℤ b) (ℕ₊₁→ℤ d) i\n / lemℕ₊₁ b d b f i ]) ∙\n (λ i → [ ℤ.·-distribʳ (a ℤ.· (c ℤ.· ℕ₊₁→ℤ f)) (a ℤ.· (e ℤ.· ℕ₊₁→ℤ d)) (ℕ₊₁→ℤ b) i\n / (b ·₊₁ (d ·₊₁ f)) ·₊₁ b ]) ∙\n ℚ-cancelʳ {a ℤ.· (c ℤ.· ℕ₊₁→ℤ f) ℤ.+ a ℤ.· (e ℤ.· ℕ₊₁→ℤ d)} {b ·₊₁ (d ·₊₁ f)} b ∙\n (λ i → [ ℤ.·-distribˡ a (c ℤ.· ℕ₊₁→ℤ f) (e ℤ.· ℕ₊₁→ℤ d) i\n / b ·₊₁ (d ·₊₁ f) ])\n\n·-distribʳ : ∀ x y z → (x · z) + (y · z) ≡ (x + y) · z\n·-distribʳ x y z = (λ i → ·-comm x z i + ·-comm y z i) ∙ ·-distribˡ z x y ∙ ·-comm z (x + y)\n\n\n-_ : ℚ → ℚ\n- x = -1 · x\n\nnegate-invol : ∀ x → - - x ≡ x\nnegate-invol x = ·-assoc -1 -1 x ∙ ·-identityˡ x\n\nnegateEquiv : ℚ ≃ ℚ\nnegateEquiv = isoToEquiv (iso -_ -_ negate-invol negate-invol)\n\nnegateEq : ℚ ≡ ℚ\nnegateEq = ua negateEquiv\n\n+-inverseˡ : ∀ x → (- x) + x ≡ 0\n+-inverseˡ x = (λ i → (-1 · x) + ·-identityˡ x (~ i)) ∙ ·-distribʳ -1 1 x ∙ ·-zeroˡ x\n\n_-_ : ℚ → ℚ → ℚ\nx - y = x + (- y)\n\n+-inverseʳ : ∀ x → x - x ≡ 0\n+-inverseʳ x = +-comm x (- x) ∙ +-inverseˡ x\n\n+-injˡ : ∀ x y z → x + y ≡ x + z → y ≡ z\n+-injˡ x y z p = sym (q y) ∙ cong ((- x) +_) p ∙ q z\n where q : ∀ y → (- x) + (x + y) ≡ y\n q y = +-assoc (- x) x y ∙ cong (_+ y) (+-inverseˡ x) ∙ +-identityˡ y\n\n+-injʳ : ∀ x y z → x + y ≡ z + y → x ≡ z\n+-injʳ x y z p = +-injˡ y x z (+-comm y x ∙ p ∙ +-comm z y)\n\n", "meta": {"hexsha": "7095a27720c8c3202c831cbb7f9f161630773ad8", "size": 10841, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/HITs/Rationals/QuoQ/Properties.agda", "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": "Cubical/HITs/Rationals/QuoQ/Properties.agda", "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_forks_repo_path": "Cubical/HITs/Rationals/QuoQ/Properties.agda", "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": 44.0691056911, "max_line_length": 102, "alphanum_fraction": 0.3828060142, "num_tokens": 6259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191337850933, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3931301687756601}} {"text": "----------------------------------------------------------------------\n-- Functional big-step evaluation of terms in the partiality monad\n-- (alternative version not productivity checker workarounds)\n----------------------------------------------------------------------\n\nmodule SystemF.Eval.NoWorkarounds where\n\nopen import Codata.Musical.Notation using (∞; ♯_; ♭)\nopen import Category.Monad\nopen import Category.Monad.Partiality.All\nopen import Data.Fin using (Fin; zero; suc)\nopen import Data.Maybe as Maybe using (just; nothing)\nopen import Data.Maybe.Relation.Unary.Any as MaybeAny using (just)\nopen import Data.Nat using (_+_)\nopen import Data.Vec using ([])\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\nopen import Relation.Nullary\n\nopen import PartialityAndFailure as PF\nopen PF.Equality hiding (fail)\nprivate\n open module M {f} = RawMonad (PF.monad {f}) using (return; _>>=_)\n\nopen import SystemF.Type\nopen import SystemF.Term\nopen import SystemF.WtTerm\n\nopen TypeSubst using () renaming (_[/_] to _[/tp_])\nopen TermTypeSubst using () renaming (_[/_] to _[/tmTp_])\nopen TermTermSubst using () renaming (_[/_] to _[/tmTm_])\nopen WtTermTypeSubst using () renaming (_[/_]′ to _[/⊢tmTp_])\nopen WtTermTermSubst using () renaming (_[/_] to _[/⊢tmTm_])\n\nopen import SystemF.Eval as E\n using (Comp; _⊢comp_∈_; does-not-fail)\n\n\n----------------------------------------------------------------------\n-- Functional big-step semantics (alternative version)\n--\n-- The evaluation function _⇓ given below differs from that in\n-- SystemF.Eval in that it evaluates terms directly in the\n-- partiality-and-failure monad (rather than first evaluating them in\n-- PartialityAndFailure.Workaround._?⊥P and subsequently interpreting\n-- the result in PartialityAndFailure._?⊥). This is achieved by\n-- manually expanding and inlining every application of the monadic\n-- bind operation.\n--\n-- We give a separate type soundness proof formulated with respect to\n-- the alternative semantics, as well as a proof that the two\n-- semantics are equivalent (i.e. the two evaluations of any given\n-- term are bisimilar).\n--\n-- The definition of the alternative semantics is more verbose and\n-- arguably less readable. However the associated type soundness\n-- proof is simpler in that it requires no additional compositionality\n-- lemmas.\n\nmodule _ where\n open M\n\n mutual\n\n infix 7 _⇓ _[_]⇓ _·⇓_\n\n -- Evaluation of untyped (open) terms.\n _⇓ : ∀ {m n} → Term m n → Comp m n\n var x ⇓ = fail\n Λ t ⇓ = return (Λ t)\n λ' a t ⇓ = return (λ' a t)\n μ a t ⇓ = later (♯ (t [/tmTm μ a t ] ⇓))\n (t [ a ]) ⇓ with t ⇓\n ... | c = c [ a ]⇓\n (s · t) ⇓ with s ⇓ | t ⇓\n ... | f | c = f ·⇓ c\n fold a t ⇓ with t ⇓\n ... | c = fold⇓ a c\n unfold a t ⇓ with t ⇓\n ... | c = unfold⇓ a c\n\n -- Evaluation of type application.\n _[_]⇓ : ∀ {m n} → Comp m n → Type n → Comp m n\n now (just (Λ t)) [ a ]⇓ = later (♯ (t [/tmTp a ] ⇓))\n now (just _) [ _ ]⇓ = fail\n now nothing [ _ ]⇓ = fail\n later c [ a ]⇓ = later (♯ ((♭ c) [ a ]⇓))\n\n -- Evaluation of term application.\n _·⇓_ : ∀ {m n} → Comp m n → Comp m n → Comp m n\n now (just (λ' _ t)) ·⇓ now (just v) = later (♯ (t [/tmTm ⌜ v ⌝ ] ⇓))\n now (just _) ·⇓ now _ = fail\n now nothing ·⇓ _ = fail\n now f ·⇓ later c = later (♯ (now f ·⇓ (♭ c)))\n later f ·⇓ c = later (♯ ((♭ f) ·⇓ c))\n\n -- Evaluation of recursive type folding.\n fold⇓ : ∀ {m n} → Type (1 + n) → Comp m n → Comp m n\n fold⇓ a (now (just v)) = now (just (fold a v))\n fold⇓ _ (now nothing) = fail\n fold⇓ a (later c) = later (♯ fold⇓ a (♭ c))\n\n -- Evaluation of recursive type unfolding.\n unfold⇓ : ∀ {m n} → Type (1 + n) → Comp m n → Comp m n\n unfold⇓ _ (now (just (fold _ v))) = now (just v)\n unfold⇓ a (now (just _)) = fail\n unfold⇓ a (now nothing) = fail\n unfold⇓ a (later c) = later (♯ unfold⇓ a (♭ c))\n\n\n----------------------------------------------------------------------\n-- Type soundness wrt. to the alternative semantics\n\ninfix 4 ⊢comp_∈_\n\n-- Short hand for closed well-typed computations.\n⊢comp_∈_ : Comp 0 0 → Type 0 → Set\n⊢comp c ∈ a = [] ⊢comp c ∈ a\n\nmutual\n\n infix 7 ⊢_⇓ ⊢_[_]⇓ ⊢_·⇓_\n\n -- Evaluation of closed terms preserves well-typedness.\n ⊢_⇓ : ∀ {t a} → [] ⊢ t ∈ a → ⊢comp t ⇓ ∈ a\n ⊢ var () ⇓\n ⊢ Λ ⊢t ⇓ = now (just (Λ ⊢t))\n ⊢ λ' a ⊢t ⇓ = now (just (λ' a ⊢t))\n ⊢ μ a ⊢t ⇓ = later (♯ ⊢ ⊢t [/⊢tmTm μ a ⊢t ] ⇓)\n ⊢ ⊢t [ a ] ⇓ with ⊢ ⊢t ⇓\n ... | ⊢c = ⊢ ⊢c [ a ]⇓\n ⊢ ⊢s · ⊢t ⇓ with ⊢ ⊢s ⇓ | ⊢ ⊢t ⇓\n ... | ⊢f | ⊢c = ⊢ ⊢f ·⇓ ⊢c\n ⊢ fold a ⊢t ⇓ with ⊢ ⊢t ⇓\n ... | ⊢c = ⊢fold⇓ a ⊢c\n ⊢ unfold a ⊢t ⇓ with ⊢ ⊢t ⇓\n ... | ⊢c = ⊢unfold⇓ a ⊢c\n\n -- Evaluation of type application preserves well-typedness.\n ⊢_[_]⇓ : ∀ {c a} → ⊢comp c ∈ ∀' a → ∀ b → ⊢comp c [ b ]⇓ ∈ a [/tp b ]\n ⊢ now (just (Λ ⊢t)) [ a ]⇓ = later (♯ ⊢ ⊢t [/⊢tmTp a ] ⇓)\n ⊢ later ⊢c [ a ]⇓ = later (♯ ⊢ (♭ ⊢c) [ a ]⇓)\n\n -- Evaluation of term application preserves well-typedness.\n ⊢_·⇓_ : ∀ {f c a b} → ⊢comp f ∈ a →' b → ⊢comp c ∈ a → ⊢comp f ·⇓ c ∈ b\n ⊢ now (just (λ' a ⊢t)) ·⇓ now (just ⊢v) =\n later (♯ (⊢ ⊢t [/⊢tmTm ⊢⌜ ⊢v ⌝ ] ⇓))\n ⊢ now (just (λ' a ⊢t)) ·⇓ later ⊢c =\n later (♯ (⊢ now (just (λ' a ⊢t)) ·⇓ ♭ ⊢c))\n ⊢ later ⊢f ·⇓ ⊢c = later (♯ (⊢ ♭ ⊢f ·⇓ ⊢c))\n\n -- Evaluation of recursive type folding preserves well-typedness.\n ⊢fold⇓ : ∀ {c} a → ⊢comp c ∈ a [/tp μ a ] → ⊢comp fold⇓ a c ∈ μ a\n ⊢fold⇓ a (now (just ⊢v)) = now (just (fold a ⊢v))\n ⊢fold⇓ a (later ⊢c) = later (♯ ⊢fold⇓ a (♭ ⊢c))\n\n -- Evaluation of recursive type unfolding preserves well-typedness.\n ⊢unfold⇓ : ∀ {c} a → ⊢comp c ∈ μ a → ⊢comp unfold⇓ a c ∈ a [/tp μ a ]\n ⊢unfold⇓ _ (now (just (fold ._ ⊢v))) = now (just ⊢v)\n ⊢unfold⇓ a (later ⊢c) = later (♯ ⊢unfold⇓ a (♭ ⊢c))\n\n-- Type soundness: evaluation of well-typed terms does not fail.\ntype-soundness : ∀ {t a} → [] ⊢ t ∈ a → ¬ t ⇓ ≈ fail\ntype-soundness ⊢t = does-not-fail ⊢ ⊢t ⇓\n\n\n----------------------------------------------------------------------\n-- Equivalence (bisimilarity) of big-step semantics\n\nopen PF.Workaround using (⟦_⟧P)\nopen PF.Equivalence hiding (sym)\nopen PF.AlternativeEquality\n renaming (return to returnP; fail to failP; _>>=_ to _>>=P_)\n\n-- Bind-expanded variants of the various helpers of of _⇓.\n\n_[_]⇓′ : ∀ {m n} → Comp m n → Type n → Comp m n\nc [ a ]⇓′ = c >>= λ v → (return v) [ a ]⇓\n\n_·⇓′_ : ∀ {m n} → Comp m n → Comp m n → Comp m n\nc ·⇓′ d = c >>= λ f → d >>= λ v → (return f) ·⇓ (return v)\n\nfold⇓′ : ∀ {m n} → Type (1 + n) → Comp m n → Comp m n\nfold⇓′ a c = c >>= λ v → fold⇓ a (return v)\n\nunfold⇓′ : ∀ {m n} → Type (1 + n) → Comp m n → Comp m n\nunfold⇓′ a c = c >>= λ v → unfold⇓ a (return v)\n\n-- The two variants of _[_]⇓ are strongly bisimilar.\n_[_]⇓≅ : ∀ {m n} (c : Comp m n) (a : Type n) → c [ a ]⇓ ≅ c [ a ]⇓′\nnow (just _) [ _ ]⇓≅ = refl P.refl\nnow nothing [ _ ]⇓≅ = now P.refl\nlater c [ a ]⇓≅ = later (♯ ((♭ c) [ a ]⇓≅))\n\n-- The two variants of _·⇓_ are strongly bisimilar.\n_·⇓≅_ : ∀ {m n} (c : Comp m n) (d : Comp m n) → c ·⇓ d ≅ c ·⇓′ d\nnow (just _) ·⇓≅ now (just _) = refl P.refl\nnow (just (Λ t)) ·⇓≅ now nothing = now P.refl\nnow (just (λ' a t)) ·⇓≅ now nothing = now P.refl\nnow (just (fold a t)) ·⇓≅ now nothing = now P.refl\nnow nothing ·⇓≅ now v = now P.refl\nnow (just (Λ t)) ·⇓≅ later d = later (♯ (now (just (Λ t)) ·⇓≅ ♭ d))\nnow (just (λ' a t)) ·⇓≅ later d = later (♯ (now (just (λ' a t)) ·⇓≅ ♭ d))\nnow (just (fold a t)) ·⇓≅ later d = later (♯ (now (just (fold a t)) ·⇓≅ ♭ d))\nnow nothing ·⇓≅ later d = now P.refl\nlater c ·⇓≅ d = later (♯ ((♭ c) ·⇓≅ d))\n\n-- The two variants of fold⇓ are strongly bisimilar.\nfold⇓≅ : ∀ {m n} (a : Type (1 + n)) (c : Comp m n) → fold⇓ a c ≅ fold⇓′ a c\nfold⇓≅ a (now (just v)) = now P.refl\nfold⇓≅ a (now nothing) = now P.refl\nfold⇓≅ a (later c) = later (♯ fold⇓≅ a (♭ c))\n\n-- The two variants of unfold⇓ are strongly bisimilar.\nunfold⇓≅ : ∀ {m n} (a : Type (1 + n)) (c : Comp m n) →\n unfold⇓ a c ≅ unfold⇓′ a c\nunfold⇓≅ a (now (just v)) = refl P.refl\nunfold⇓≅ a (now nothing) = now P.refl\nunfold⇓≅ a (later c) = later (♯ unfold⇓≅ a (♭ c))\n\nmutual\n\n -- Helper lemma relating the two semantics of type application.\n []-E⇓≅⇓′ : ∀ {m n} (v : Val m n) (a : Type n) →\n ⟦ v E.[ a ]′ ⟧P ≅P (return v) [ a ]⇓\n []-E⇓≅⇓′ (Λ t) a = later (♯ E⇓≅⇓′ (t [/tmTp a ] ))\n []-E⇓≅⇓′ (λ' _ _) _ = failP\n []-E⇓≅⇓′ (fold _ _) _ = failP\n\n -- Helper lemma relating the two semantics of term application.\n ·-E⇓≅⇓′ : ∀ {m n} (f : Val m n) (v : Val m n) →\n ⟦ f E.·′ v ⟧P ≅P (return f) ·⇓ (return v)\n ·-E⇓≅⇓′ (Λ _) _ = failP\n ·-E⇓≅⇓′ (λ' a t) v = later (♯ E⇓≅⇓′ (t [/tmTm ⌜ v ⌝ ]))\n ·-E⇓≅⇓′ (fold _ _) _ = failP\n\n -- Helper lemma relating the two semantics of recursive type\n -- unfolding.\n unfold-E⇓≅⇓′ : ∀ {m n} (a : Type (1 + n)) (v : Val m n) →\n ⟦ E.unfold′ a v ⟧P ≅P unfold⇓ a (return v)\n unfold-E⇓≅⇓′ _ (Λ _) = failP\n unfold-E⇓≅⇓′ _ (λ' _ _) = failP\n unfold-E⇓≅⇓′ _ (fold _ _) = returnP P.refl\n\n -- The two semantics are ≅P-equivalent.\n E⇓≅⇓′ : ∀ {m n} (t : Term m n) → t E.⇓ ≅P t ⇓\n E⇓≅⇓′ (var x) = failP\n E⇓≅⇓′ (Λ t) = returnP P.refl\n E⇓≅⇓′ (λ' a t) = returnP P.refl\n E⇓≅⇓′ (μ a t) = later (♯ E⇓≅⇓′ (t [/tmTm μ a t ]))\n E⇓≅⇓′ (t [ a ]) =\n t [ a ] E.⇓ ≅⟨ complete (E.[]-comp t a) ⟩\n (t E.⇓) E.[ a ]⇓ ≅⟨ (E⇓≅⇓′ t >>=P λ v → []-E⇓≅⇓′ v a) ⟩\n (t ⇓) [ a ]⇓′ ≅⟨ sym (complete ((t ⇓) [ a ]⇓≅)) ⟩\n t [ a ] ⇓ ∎\n E⇓≅⇓′ (s · t) =\n s · t E.⇓ ≅⟨ complete (E.·-comp s t) ⟩\n (s E.⇓) E.·⇓ (t E.⇓) ≅⟨ (E⇓≅⇓′ s >>=P λ f → E⇓≅⇓′ t >>=P λ v →\n ·-E⇓≅⇓′ f v) ⟩\n (s ⇓) ·⇓′ (t ⇓) ≅⟨ sym (complete ((s ⇓) ·⇓≅ (t ⇓))) ⟩\n s · t ⇓ ∎\n E⇓≅⇓′ (fold a t) =\n fold a t E.⇓ ≅⟨ complete (E.fold-comp a t) ⟩\n E.fold⇓ a (t E.⇓) ≅⟨ (E⇓≅⇓′ t >>=P λ v → return (fold a v) ∎) ⟩\n fold⇓′ a (t ⇓) ≅⟨ sym (complete (fold⇓≅ a (t ⇓))) ⟩\n fold a t ⇓ ∎\n E⇓≅⇓′ (unfold a t) =\n unfold a t E.⇓ ≅⟨ complete (E.unfold-comp a t) ⟩\n E.unfold⇓ a (t E.⇓) ≅⟨ (E⇓≅⇓′ t >>=P λ v → unfold-E⇓≅⇓′ a v) ⟩\n unfold⇓′ a (t ⇓) ≅⟨ sym (complete (unfold⇓≅ a (t ⇓))) ⟩\n unfold a t ⇓ ∎\n\n-- The two big-step semantics are strongly bisimliar.\nE⇓≅⇓ : ∀ {m n} (t : Term m n) → t E.⇓ ≅ t ⇓\nE⇓≅⇓ t = sound (E⇓≅⇓′ t)\n", "meta": {"hexsha": "ae0f8e39dc6b305fad21d749c96046a283942a8d", "size": 10740, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/SystemF/Eval/NoWorkarounds.agda", "max_stars_repo_name": "sstucki/system-f-agda", "max_stars_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 68, "max_stars_repo_stars_event_min_datetime": "2015-05-26T13:12:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T01:25:16.000Z", "max_issues_repo_path": "src/SystemF/Eval/NoWorkarounds.agda", "max_issues_repo_name": "sstucki/system-f-agda", "max_issues_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-30T06:43:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T19:23:26.000Z", "max_forks_repo_path": "src/SystemF/Eval/NoWorkarounds.agda", "max_forks_repo_name": "sstucki/system-f-agda", "max_forks_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2015-05-29T12:24:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T23:12:48.000Z", "avg_line_length": 39.0545454545, "max_line_length": 77, "alphanum_fraction": 0.4878957169, "num_tokens": 4640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191337850932, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.39313016877566004}} {"text": "module Tensor where\n\nopen import Basics\nopen import Ix\nopen import All\nopen import Perm\nopen import Cutting\nopen import Recutter\n\nopen _|>_\nopen RECUTTER\nopen SUBCOLLECTLEMMA\n\n_><_ : forall {I J} -> (I |> I) -> (J |> J) -> (I * J) |> (I * J)\nCuts (C >< D) (i , j) = Cuts C i + Cuts D j\ninners (C >< D) {i , j} (inl c) = list (_, j) (inners C c)\ninners (C >< D) {i , j} (inr d) = list (i ,_) (inners D d)\n\nmodule TENSORRECUT {I J}(C : I |> I)(D : J |> J)(rec : Recutter C)(red : Recutter D) where\n\n cartLeftLemma : (is : List I)(j : J)(d : Cuts D j) -> subCollect (C >< D) (list (_, j) is)\n (allRe (_, j) is\n (allPu (\\ _ -> inr (inr d)) is)) == cart is (inners D d)\n cartLeftLemma [] j d = refl []\n cartLeftLemma (i ,- is) j d = refl (list (i ,_) (inners D d) +L_) =$= cartLeftLemma is j d\n\n cartRightLemma : (i : I)(c : Cuts C i)(js : List J) ->\n subCollect (C >< D) (list (i ,_) js)\n (allRe (i ,_) js (allPu (\\ _ -> inr (inl c)) js)) ==\n list swap (cart js (inners C c))\n cartRightLemma i c [] = refl []\n cartRightLemma i c (j ,- js)\n rewrite sym (catNatural swap (list (j ,_) (inners C c)) (cart js (inners C c)))\n | listlist swap (j ,_) (_, j) (\\ i -> refl (i , j)) (inners C c)\n = refl (list (_, j) (inners C c) +L_) =$= cartRightLemma i c js\n\n TensorRecut : Recutter (C >< D)\n\n -- both cuts in left dimension\n TensorRecut (i , j) (inl c) (inl c') with rec i c c'\n ... | x , y , m\n = allRe (_, j) (inners C c) (all (\\ _ -> id +map inl) _ x)\n , allRe (_, j) (inners C c') (all (\\ _ -> id +map inl) _ y)\n , lemma where\n lemma : subCollect (C >< D) (list (_, j) (inners C c))\n (allRe (_, j) (inners C c) (all (\\ _ -> id +map inl) (inners C c) x))\n ~\n subCollect (C >< D) (list (_, j) (inners C c'))\n (allRe (_, j) (inners C c') (all (\\ _ -> id +map inl) (inners C c') y))\n lemma rewrite subCollectLemma C (C >< D) (_, j) (\\ _ -> inl) (\\ i c -> refl _)\n (inners C c) x\n | subCollectLemma C (C >< D) (_, j) (\\ _ -> inl) (\\ i c -> refl _)\n (inners C c') y\n = permap (_, j) m\n\n -- left to right\n fst (TensorRecut (i , j) (inl c) (inr d)) =\n allRe (_, j) (inners C c) (allPu (\\ i -> inr (inr d)) (inners C c))\n fst (snd (TensorRecut (i , j) (inl c) (inr d))) =\n allRe (i ,_) (inners D d) (allPu (\\ i -> inr (inl c)) (inners D d))\n snd (snd (TensorRecut (i , j) (inl c) (inr d)))\n rewrite cartLeftLemma (inners C c) j d\n | cartRightLemma i c (inners D d)\n = cartLemma (inners C c) (inners D d)\n\n -- right to left\n fst (TensorRecut (i , j) (inr d) (inl c)) =\n allRe (i ,_) (inners D d) (allPu (\\ i -> inr (inl c)) (inners D d))\n fst (snd (TensorRecut (i , j) (inr d) (inl c))) =\n allRe (_, j) (inners C c) (allPu (\\ i -> inr (inr d)) (inners C c))\n snd (snd (TensorRecut (i , j) (inr d) (inl c)))\n rewrite cartLeftLemma (inners C c) j d\n | cartRightLemma i c (inners D d)\n = symP (cartLemma (inners C c) (inners D d))\n\n -- both cuts in right dimension\n TensorRecut (i , j) (inr d) (inr d') with red j d d'\n ... | x , y , m\n = allRe (i ,_) (inners D d) (all (\\ _ -> id +map inr) _ x)\n , allRe (i ,_) (inners D d') (all (\\ _ -> id +map inr) _ y)\n , lemma where\n lemma : subCollect (C >< D) (list (i ,_) (inners D d))\n (allRe (i ,_) (inners D d) (all (\\ _ -> id +map inr) (inners D d) x))\n ~\n subCollect (C >< D) (list (i ,_) (inners D d'))\n (allRe (i ,_) (inners D d') (all (\\ _ -> id +map inr) (inners D d') y))\n lemma rewrite subCollectLemma D (C >< D) (i ,_) (\\ _ -> inr) (\\ i d -> refl _)\n (inners D d) x\n | subCollectLemma D (C >< D) (i ,_) (\\ _ -> inr) (\\ i d -> refl _)\n (inners D d') y\n = permap (i ,_) m\n\nmodule RECTANGLE where\n\n RectCut = NatCut >< NatCut\n\n open NATRECUT\n open TENSORRECUT NatCut NatCut NatRecut NatRecut\n\n RectRecut = TensorRecut\n\n", "meta": {"hexsha": "9c7fcca4841ac645fe5bf309aef199feb38f9d9e", "size": 4169, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Tensor.agda", "max_stars_repo_name": "pigworker/InteriorDesign", "max_stars_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-06-18T15:25:39.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-31T02:00:13.000Z", "max_issues_repo_path": "Tensor.agda", "max_issues_repo_name": "pigworker/InteriorDesign", "max_issues_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c", "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": "Tensor.agda", "max_forks_repo_name": "pigworker/InteriorDesign", "max_forks_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c", "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": 40.8725490196, "max_line_length": 92, "alphanum_fraction": 0.4890861118, "num_tokens": 1505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.39304323540691805}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nmodule Definition.Conversion.Universe 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.Reduction\nopen import Definition.Conversion.Lift\n\nimport Tools.PropositionalEquality as PE\n\n\n-- Algorithmic equality of terms in WHNF of type U are equal as types.\nunivConv↓ : ∀ {A B Γ}\n → Γ ⊢ A [conv↓] B ∷ U\n → Γ ⊢ A [conv↓] B\nunivConv↓ (ne-ins t u () x)\nunivConv↓ (univ x x₁ x₂) = x₂\n\n-- Algorithmic equality of terms of type U are equal as types.\nunivConv↑ : ∀ {A B Γ}\n → Γ ⊢ A [conv↑] B ∷ U\n → Γ ⊢ A [conv↑] B\nunivConv↑ ([↑]ₜ B₁ t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u)\n rewrite PE.sym (whnfRed* D Uₙ) =\n reductionConv↑ (univ* d) (univ* d′) (liftConv (univConv↓ t<>u))\n", "meta": {"hexsha": "94696de098ec3a221effa932d2b74c36c8c467ac", "size": 892, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Conversion/Universe.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/Universe.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/Universe.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": 29.7333333333, "max_line_length": 70, "alphanum_fraction": 0.6748878924, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.392882970220696}} {"text": "module Models where\n\nopen import Data.Nat\nopen import Terms\n\n\n-- The (complete) Herbrand universe for Σ\nU' : {n m : ℕ} → (Signature n m) → Set\nU' Σ = GTerm Σ\n\n-- The (complete) μ-Herbrand base for Σ\n\nB'μ : {n m : ℕ} → (Signature n m) → Set\nB'μ Σ = GAtom Σ μ\n\nB'ν : {n m : ℕ} → (Signature n m) → Set\nB'ν Σ = GAtom Σ ν\n\n\nopen import Relation.Unary as U\nopen import Level\n\n-- a (complete) Herbrand interpretation\nrecord Interp {n m : ℕ} (Σ : Signature n m) : Set₁ where\n field\n Carrier-μ : Pred (B'μ Σ) Level.zero\n Carrier-ν : Pred (B'ν Σ) Level.zero\nopen Interp\n\n\n_∩ᵢ_ : {n m : ℕ} → {Σ : Signature n m} → Interp Σ → Interp Σ\n → Interp Σ\ni₁ ∩ᵢ i₂ = record\n { Carrier-μ = Carrier-μ i₁ ∩ Carrier-μ i₂\n ; Carrier-ν = Carrier-ν i₁ ∩ Carrier-ν i₂\n }\n\n_∪ᵢ_ : {n m : ℕ} → {Σ : Signature n m} → Interp Σ → Interp Σ\n → Interp Σ\ni₁ ∪ᵢ i₂ = record\n { Carrier-μ = Carrier-μ i₁ ∪ Carrier-μ i₂\n ; Carrier-ν = Carrier-ν i₁ ∪ Carrier-ν i₂\n }\n\nopen import Data.List as L\nopen import Data.List.All as LAl\nopen import Data.List.Any as LAn\nopen import Relation.Binary.Core\n\nopen Program\n\n-- | Inductive model\nrecord IsIModel {n m : ℕ} {Σ : Signature n m} {var : Set}\n (i : Interp Σ) (P : Program Σ var) : Set₂ where\n field\n forwClosed :\n (bs'μ : List (GAtom Σ μ))\n → All (λ b → b ∈ Carrier-μ i) bs'μ\n → (bs'ν : List (GAtom Σ ν))\n → All (λ b → b ∈ Carrier-ν i) bs'ν\n → (σ : GSubst Σ var)\n → (a : Atom Σ var μ)\n → (bsμ : List (Atom Σ var μ))\n → (bsν : List (Atom Σ var ν))\n → Any (λ cl → cl ≡ (a :- bsμ , bsν)) (prg-μ P)\n → (L.map (appA σ) bsμ) ≡ bs'μ\n → (L.map (appA σ) bsν) ≡ bs'ν\n → (appA σ a ∈ Carrier-μ i)\nopen IsIModel\nopen import Data.Product\n\nhA : {A : Set} {B : Set₁} → A × B → A\nhA = proj₁\n\nhBsμ : {A B : Set} {C : Set₁} → A × B × C → B\nhBsμ (_ , a , _) = a\n\nhBsν : {A B C : Set} {D : Set₁} → A × B × C × D → C\nhBsν (_ , _ , a , _) = a\n\nhσ : {A B C : Set} {D : Set₁} → A × B × C × D → D\nhσ (_ , _ , _ , a) = a\nopen import Data.List.All.Properties -- using (All-map)\n\n-- | model intersection property for a pair of models\nprop_model_intersection_pair : {n m : ℕ} → {Σ : Signature n m} {var : Set} →\n (P : Program Σ var)\n → (m₁ : Interp Σ)\n → (m₂ : Interp Σ)\n → Carrier-ν m₁ ≡ Carrier-ν m₂\n → (mp₁ : IsIModel m₁ P)\n → (mp₂ : IsIModel m₂ P)\n → IsIModel (m₁ ∩ᵢ m₂) P\nprop_model_intersection_pair P m₁ m₂ eq mp₁ mp₂ =\n record { forwClosed = λ bs'μ x bs'ν y σ a bsμ bsν pcls pμ pν →\n ( forwClosed mp₁ bs'μ (LAl.map proj₁ x) bs'ν\n (LAl.map proj₁ y) σ a bsμ bsν pcls pμ pν\n , forwClosed mp₂ bs'μ (LAl.map proj₂ x) bs'ν\n (LAl.map proj₂ y) σ a bsμ bsν pcls pμ pν\n )}\n\n\n-- | Coinductive model\nrecord IsCModel {n m : ℕ} {Σ : Signature n m} {var : Set}\n (i : Interp Σ) (P : Program Σ var) : Set₁ where\n field\n backClosed :\n --→\n (a' : GAtom Σ ν)\n → a' ∈ Carrier-ν i\n → ∃ (λ ( w : (Atom Σ var ν) -- a\n × (List (Atom Σ var μ)) -- bs-μ\n × (List (Atom Σ var ν)) -- bs-ν\n × GSubst Σ var) → -- σ\n\n (Any (λ c → (hA w) :- (hBsμ w) , (hBsν w) ≡ c) (prg-ν P))\n × appA (hσ w) (hA w) ≡ a'\n × All (λ c → c ∈ Carrier-μ i) (L.map (appA (hσ w)) (hBsμ w))\n × All (λ c → c ∈ Carrier-ν i) (L.map (appA (hσ w)) (hBsν w))\n )\nopen IsCModel\n\n\nopen import Data.Sum\nopen import Data.Product as DP\nopen Interp\n\nopen import Relation.Binary.PropositionalEquality\n\n-- | model union property for a pair of models\nprop_model_union_pair : {n m : ℕ} → {Σ : Signature n m} → {var : Set}\n (P : Program Σ var)\n → (m₁ : Interp Σ)\n → (m₂ : Interp Σ)\n → Carrier-μ m₁ ≡ Carrier-μ m₂\n → (mp₁ : IsCModel m₁ P)\n → (mp₂ : IsCModel m₂ P)\n → IsCModel (m₁ ∪ᵢ m₂) P\nprop_model_union_pair P m₁ m₂ eq mp₁ mp₂ {-with (sym eq) -- | (Carrier-μ m₁)\n... | eq' {-| dm₁-}-} = record { backClosed = λ\n { a' (inj₁ x) → DP.map\n (λ atm → atm)\n (DP.map\n (λ any → any)\n (λ w → DP.map (λ eq₁ → eq₁) (λ x₃\n → LAl.map inj₁ (proj₁ (proj₂ w))\n , LAl.map inj₁ (proj₂ (proj₂ w))) w))\n (backClosed mp₁ a' x)\n ; a' (inj₂ y) → DP.map\n (λ atm → atm)\n (DP.map\n (λ any → any)\n (λ w → DP.map (λ eq → eq) (λ x₁\n → LAl.map inj₂ (proj₁ (proj₂ w))\n , LAl.map inj₂ (proj₂ (proj₂ w))) w))\n (backClosed mp₂ a' y)\n } }\n\n", "meta": {"hexsha": "97780aace4557a2859ff974eeed25b91bbbece88", "size": 4368, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Mixed/Models.agda", "max_stars_repo_name": "frantisekfarka/lp-mod", "max_stars_repo_head_hexsha": "411ca7970b6f64857a36ebcf648c9a58b90bb4b2", "max_stars_repo_licenses": ["BSD-2-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": "Mixed/Models.agda", "max_issues_repo_name": "frantisekfarka/lp-mod", "max_issues_repo_head_hexsha": "411ca7970b6f64857a36ebcf648c9a58b90bb4b2", "max_issues_repo_licenses": ["BSD-2-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": "Mixed/Models.agda", "max_forks_repo_name": "frantisekfarka/lp-mod", "max_forks_repo_head_hexsha": "411ca7970b6f64857a36ebcf648c9a58b90bb4b2", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4716981132, "max_line_length": 76, "alphanum_fraction": 0.5368589744, "num_tokens": 1780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.392882970220696}} {"text": "module test where\n\nopen import Relation.Binary.PropositionalEquality\n\nmodule NewCodata where\n open import Data.Nat\n open import Data.List\n open import Data.Maybe\n record Pair (A B : Set) : Set where\n field\n fst : A\n snd : B\n\n record Stream (A : Set) : Set where\n coinductive\n field\n hd : A\n tl : Stream A\n\n open Stream\n\n repeat : ∀ {A : Set} → A → Stream A\n hd (repeat x) = x\n tl (repeat x) = repeat x\n\n nth : ∀ {A : Set} → ℕ → Stream A → A\n nth zero s = hd s\n nth (suc n) s = nth n (tl s)\n\n mutual\n data μColist (A : Set) : Set where\n [] : μColist A\n _∷_ : (x : A) (xs : νColist A) → μColist A\n record νColist (A : Set) : Set where\n coinductive\n field out : μColist A\n\n open νColist\n\n record νTree (A : Set) : Set where\n coinductive\n field label : A\n subs : List (νTree A)\n open νTree\n\n append : {A : Set} → List A → νColist A → νColist A\n out (append [] ys) = out ys\n out (append (x ∷ xs) ys) = x ∷ append xs ys\n\n\n appendS : {A : Set} → List A → Stream A → Stream A\n hd (appendS [] s) = hd s\n hd (appendS (x ∷ xs) s) = x\n tl (appendS [] s) = tl s\n tl (appendS (x ∷ xs) s) = tl (appendS xs s)\n\n record Pi (A : Set) (B : A → Set) : Set where\n field _$_ : (x : A) → B x\n infixl 20 _$_\n\n open Pi\n\n _→'_ : Set → Set → Set\n A →' B = Pi A (λ _ → B)\n\n infixr 20 _→'_\n\n plus2 : ℕ →' ℕ\n plus2 $ x = suc (suc x)\n\n plus : ℕ →' ℕ →' ℕ\n plus $ 0 $ m = m\n plus $ (suc n) $ m = suc (plus $ n $ m)\n\n data Vec (A : Set) : ℕ → Set where\n nil : Vec A 0\n _:::_ : {n : ℕ} → A → Vec A n → Vec A (suc n)\n\n test : Vec ℕ 2\n test = 2 ::: (2 ::: nil)\n\n repeat2V : Pi ℕ (λ n → Vec ℕ n)\n repeat2V $ 0 = nil\n repeat2V $ suc n = 2 ::: (repeat2V $ n)\n\n\n {-\n bf : {A : Set} → List (νTree A) → νColist A\n out (bf []) = []\n out (bf (t ∷ ts)) = label t ∷\n append (map label ts)\n (bf (concatMap subs (t ∷ ts)))\n -}\n\n record ℕ∞ : Set where\n coinductive\n field\n pred∞ : Maybe ℕ∞\n open ℕ∞\n\n infinity : ℕ∞\n pred∞ infinity = just infinity\n\n zero∞ : ℕ∞\n pred∞ zero∞ = nothing\n\n one∞ : ℕ∞\n pred∞ one∞ = just zero∞\n\n suc∞ : ℕ∞ → ℕ∞\n pred∞ (suc∞ x) = just x\n\n plus∞ : ℕ∞ → ℕ∞ → ℕ∞\n pred∞ (plus∞ n m) with pred∞ n\n ... | nothing = pred∞ m\n ... | just n' = just (plus∞ n' m)\n\n {-\n record PStr (A : Set) (n : ℕ∞) : Set where\n coinductive\n field\n phd : (k : ℕ∞) → PStr A (suc∞ k) → A\n ptl : (k : ℕ∞) → PStr A (suc∞ k) → PStr A k\n -}\n\nmodule OldCodata where\n open import Codata.Musical.Notation\n open import Data.Nat\n\n data Stream (A : Set) : Set where\n cons : A → ∞ (Stream A) → Stream A\n\n repeat : {A : Set} → A → Stream A\n repeat x = cons x (♯ (repeat x))\n\n nth : {A : Set} → ℕ → Stream A → A\n nth 0 (cons x _) = x\n nth (suc n) (cons _ xs) = nth n (♭ xs)\n\n data ℕ∞ : Set where\n zero∞ : ℕ∞\n suc∞ : ∞ (ℕ∞) → ℕ∞\n\n infinity : ℕ∞\n infinity = suc∞ (♯ infinity)\n\nmodule NonTerminating where\n open import Data.Nat\n\n {-\n _/_ : ℕ → ℕ → ℕ\n zero / y = zero\n suc x / y = suc ( (x ∸ y) / y)\n -}\n\nmodule PositiveSizedTypes where\n open import Agda.Builtin.Size\n\n data ℕ : Size → Set where\n zero : {i : Size} → ℕ i\n suc : {i : Size} → ℕ i → ℕ (↑ i)\n\n one : ℕ ∞\n one = suc zero\n two : ℕ ∞\n two = suc one\n three : ℕ ∞\n three = suc two\n four : ℕ ∞\n four = suc three\n five : ℕ ∞\n five = suc four\n\n _-_ : {i : Size} → ℕ i → ℕ ∞ → ℕ i\n zero - _ = zero\n n - zero = n\n (suc n) - (suc m) = n - m\n infixl 20 _-_\n\n -test₁ : five - two ≡ three\n -test₁ = refl\n\n _/_ : {i : Size} → ℕ i → ℕ ∞ → ℕ i\n zero / _ = zero\n suc x / y = suc ( (x - y) / y)\n infixl 30 _/_\n\n _+_ : ℕ ∞ → ℕ ∞ → ℕ ∞\n zero + y = y\n suc x + y = suc (x + y)\n infixl 20 _+_\n\n _*_ : ℕ ∞ → ℕ ∞ → ℕ ∞\n zero * _ = zero\n suc x * y = x + x * y\n infixl 30 _*_\n\n min : {i : Size} → ℕ i → ℕ i → ℕ i\n min zero _ = zero\n min _ zero = zero\n min (suc m) (suc n) = suc (min m n)\n\n test₁ : zero / zero ≡ zero\n test₁ = refl\n test₂ : zero / five ≡ zero\n test₂ = refl\n test₃ : one / one ≡ one\n test₃ = refl\n test₄ : two / two ≡ one\n test₄ = refl\n test₅ : five / five ≡ one\n test₅ = refl\n test₆ : one / zero ≡ one\n test₆ = refl\n test₇ : two / one ≡ one\n test₇ = refl\n test₈ : four / two ≡ two\n test₈ = refl\n\nmodule NegativSizedTypes where\n open import Agda.Builtin.Size\n open import Data.Nat\n open import Data.Bool using (if_then_else_)\n open import Relation.Nullary.Decidable using (⌊_⌋)\n\n record Stream (i : Size) (A : Set) : Set where\n coinductive\n field\n hd : A\n tl : ∀ {j : Size< i} → Stream j A\n open Stream\n\n cons : {i : Size} {A : Set} → A -> Stream i A → Stream i A\n hd (cons x _) = x\n tl (cons _ xs) = xs\n\n map : {A B : Set} {i : Size} → (A → B) → Stream i A → Stream i B\n hd (map f xs) = f (hd xs)\n tl (map f xs) = map f (tl xs)\n\n merge : {i : Size} → Stream i ℕ → Stream i ℕ → Stream i ℕ\n hd (merge xs ys) = hd xs ⊓ hd ys\n tl (merge xs ys) = if ⌊ hd xs ≤? hd ys ⌋\n then cons (hd ys) (merge (tl xs) (tl ys))\n else cons (hd xs) (merge (tl xs) (tl ys))\n\n ham : {i : Size} → Stream i ℕ\n hd ham = 1\n tl ham = (merge (map (_*_ 2) ham) (map (_*_ 3) ham))\n", "meta": {"hexsha": "1aff282ebdecfdb8002d87d17de46eb12a9401fd", "size": 5318, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "doc/test.agda", "max_stars_repo_name": "StillerHarpo/masterarbeit", "max_stars_repo_head_hexsha": "68afff2b0a7183751737ef20e713df1fef3d4cf2", "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": "doc/test.agda", "max_issues_repo_name": "StillerHarpo/masterarbeit", "max_issues_repo_head_hexsha": "68afff2b0a7183751737ef20e713df1fef3d4cf2", "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": "doc/test.agda", "max_forks_repo_name": "StillerHarpo/masterarbeit", "max_forks_repo_head_hexsha": "68afff2b0a7183751737ef20e713df1fef3d4cf2", "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.272, "max_line_length": 66, "alphanum_fraction": 0.503948853, "num_tokens": 2141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757646140788307, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.3928240587120859}} {"text": "-- Type-checker for the simply-typed lambda calculus\n--\n-- Where we make sure that failing to typecheck a term is justified by\n-- an \"ill-typing judgment\", which erases to the original term.\n\nopen import Data.Empty\nopen import Data.Unit hiding (_≟_)\nopen import Data.List hiding ([_])\nopen import Data.Nat hiding (_*_ ; _+_ ; _≟_)\nopen import Data.Product\n\nopen import Relation.Nullary\nopen import Relation.Binary hiding (_⇒_)\nopen import Relation.Binary.PropositionalEquality hiding ([_])\n\ninfix 5 _⊢?_∋_\ninfix 5 _⊢?_∈\ninfix 19 _↪_\ninfixr 30 _+_\ninfixr 35 _*_\ninfixr 40 _⇒_\ninfix 50 _∈_\ninfix 50 _∈\ninfix 50 _∋_\ninfixl 150 _▹_\n\n-- * Types\n\ndata type : Set where\n unit nat : type\n _*_ _+_ _⇒_ : (A B : type) → type\n\nbool : type\nbool = unit + unit\n\n\n-- TODO: automate this definition using reflection of Agda in Agda\n-- see https://github.com/UlfNorell/agda-prelude/blob/master/src/Tactic/Deriving/Eq.agda\n_≟_ : Decidable {A = type} _≡_\nunit ≟ unit = yes refl\nnat ≟ nat = yes refl\n(A₁ + B₁) ≟ (A₂ + B₂)\n with A₁ ≟ A₂ | B₁ ≟ B₂\n... | yes refl | yes refl = yes refl\n... | yes refl | no ¬p = no (λ { refl → ¬p refl })\n... | no ¬p | _ = no (λ { refl → ¬p refl })\n(A₁ ⇒ B₁) ≟ (A₂ ⇒ B₂)\n with A₁ ≟ A₂ | B₁ ≟ B₂\n... | yes refl | yes refl = yes refl\n... | yes _ | no ¬p = no λ { refl → ¬p refl }\n... | no ¬p | _ = no λ { refl → ¬p refl }\n(A₁ * B₁) ≟ (A₂ * B₂)\n with A₁ ≟ A₂ | B₁ ≟ B₂\n... | yes refl | yes refl = yes refl\n... | yes _ | no ¬p = no λ { refl → ¬p refl }\n... | no ¬p | q₂ = no λ { refl → ¬p refl }\nunit ≟ (_ ⇒ _) = no λ {()}\nunit ≟ (_ * _) = no λ {()}\nunit ≟ nat = no λ {()}\nunit ≟ (_ + _) = no λ {()}\nnat ≟ (_ ⇒ _) = no λ {()}\nnat ≟ (_ * _) = no λ {()}\nnat ≟ unit = no λ {()}\nnat ≟ (_ + _) = no λ {()}\n(_ + _) ≟ (_ ⇒ _) = no λ {()}\n(_ + _) ≟ (_ * _) = no λ {()}\n(_ + _) ≟ nat = no λ {()}\n(_ + _) ≟ unit = no λ {()}\n(_ ⇒ _) ≟ unit = no λ {()}\n(_ ⇒ _) ≟ nat = no λ {()}\n(_ ⇒ _) ≟ (_ * _) = no λ {()}\n(_ ⇒ _) ≟ (_ + _) = no λ {()}\n(_ * _) ≟ unit = no λ {()}\n(_ * _) ≟ nat = no λ {()}\n(_ * _) ≟ (_ ⇒ _) = no λ {()}\n(_ * _) ≟ (_ + _) = no λ {()}\n\n\n-- * Syntax of terms\n\ndata dir : Set where\n ⇑ ⇓ : dir\n\ndata can (T : Set) : Set where\n tt : can T\n pair : (t₁ t₂ : T) → can T\n lam : (b : T) → can T\n ze : can T\n su : (t : T) → can T\n inj₁ inj₂ : (t : T) → can T\n\ndata elim (T : Set) : dir → Set where\n apply : (s : T) → elim T ⇑\n fst snd : elim T ⇑\n split : (c₁ c₂ : T) → elim T ⇓\n\ndata term : dir → Set where\n C : (c : can (term ⇓)) → term ⇓\n inv : (t : term ⇑) → term ⇓\n var : (k : ℕ) → term ⇑\n _#_ : ∀ {d} → (n : term ⇑)(args : elim (term ⇓) d) → term d\n [_:∋:_] : (T : type)(t : term ⇓) → term ⇑\n\npattern Ctt = C tt\npattern Cze = C ze\npattern Csu x = C (su x)\npattern Cpair x y = C (pair x y)\npattern Clam b = C (lam b)\npattern Cinj₁ x = C (inj₁ x)\npattern Cinj₂ x = C (inj₂ x)\n\n-- ** Tests\n\ntrue : term ⇓\ntrue = Cinj₁ Ctt\n\nfalse : term ⇓\nfalse = Cinj₂ Ctt\n\nt1 : term ⇓\nt1 = inv ([ nat ⇒ nat :∋: Clam {- x -} (inv (var {- x -} 0)) ] # apply (Csu (Csu Cze)))\n\nt2 : term ⇓\nt2 = Clam {-x-} (var {- x -} 0 # split true false)\n\n-- * Type system\n\ncontext = List type\n\npattern _▹_ Γ T = T ∷ Γ\npattern ε = []\n\ndata _∈_ (T : type) : context → Set where\n here : ∀ {Γ} →\n\n ---------\n T ∈ Γ ▹ T\n\n there : ∀ {Γ T'} →\n\n T ∈ Γ\n → ----------\n T ∈ Γ ▹ T'\n\nmutual\n\n data _C⊢[_]_ : context → dir → type → Set where\n lam : ∀ {Γ A B} →\n\n Γ ▹ A ⊢[ ⇓ ] B\n → ---------------\n Γ C⊢[ ⇓ ] A ⇒ B\n\n tt : ∀ {Γ} →\n\n --------------\n Γ C⊢[ ⇓ ] unit\n\n ze : ∀ {Γ} →\n\n -------------\n Γ C⊢[ ⇓ ] nat\n\n su : ∀ {Γ} →\n\n Γ ⊢[ ⇓ ] nat\n → -------------\n Γ C⊢[ ⇓ ] nat\n\n inj₁ : ∀ {Γ A B} →\n\n Γ ⊢[ ⇓ ] A\n → ---------------\n Γ C⊢[ ⇓ ] A + B\n\n inj₂ : ∀ {Γ A B} →\n\n Γ ⊢[ ⇓ ] B\n → ---------------\n Γ C⊢[ ⇓ ] A + B\n\n pair : ∀ {Γ A B} →\n\n Γ ⊢[ ⇓ ] A →\n Γ ⊢[ ⇓ ] B\n → ---------------\n Γ C⊢[ ⇓ ] A * B\n\n data _E⊢[_]_↝_ : context → dir → type → type → Set where\n apply : ∀ {Γ A B} →\n\n Γ ⊢[ ⇓ ] A\n → -------------------\n Γ E⊢[ ⇑ ] A ⇒ B ↝ B\n\n fst : ∀ {Γ A B} →\n\n -------------------\n Γ E⊢[ ⇑ ] A * B ↝ A\n\n snd : ∀ {Γ A B} →\n\n -------------------\n Γ E⊢[ ⇑ ] A * B ↝ B\n\n iter : ∀ {Γ A} →\n\n Γ ▹ A ⊢[ ⇓ ] A →\n Γ ⊢[ ⇓ ] A\n → -----------------\n Γ E⊢[ ⇓ ] nat ↝ A\n\n case : ∀ {Γ A B C} →\n\n Γ ▹ A ⊢[ ⇓ ] C →\n Γ ▹ B ⊢[ ⇓ ] C\n → -------------------\n Γ E⊢[ ⇓ ] A + B ↝ C\n\n data _⊢[_]_ : context → dir → type → Set where\n\n C : ∀ {Γ d T} →\n\n Γ C⊢[ d ] T\n → -----------\n Γ ⊢[ d ] T\n\n inv : ∀ {Γ T} →\n\n Γ ⊢[ ⇑ ] T\n → ----------\n Γ ⊢[ ⇓ ] T\n\n var : ∀ {Γ T} →\n\n T ∈ Γ\n → ----------\n Γ ⊢[ ⇑ ] T\n\n _#_ : ∀ {Γ d I O} →\n\n Γ ⊢[ ⇑ ] I →\n Γ E⊢[ d ] I ↝ O\n → ---------------\n Γ ⊢[ d ] O\n\n [_:∋:_by_] : ∀ {Γ A} →\n\n (B : type) → Γ ⊢[ ⇓ ] B → A ≡ B\n → -------------------------------\n Γ ⊢[ ⇑ ] A\n\n-- ** Tests\n\n⊢true : [] ⊢[ ⇓ ] bool\n⊢true = C (inj₁ (C tt))\n\n⊢false : [] ⊢[ ⇓ ] bool\n⊢false = C (inj₂ (C tt))\n\n⊢t1 : [] ⊢[ ⇓ ] nat\n⊢t1 = inv ([ (nat ⇒ nat) :∋: (C (lam (inv (var here)))) by refl ]\n # (apply (C (su (C (su (C ze)))))))\n\n-- * Relating typing and terms\n\nrecord _↪_ (S T : Set) : Set where\n field\n ⌊_⌋ : S → T\n\nopen _↪_ {{...}} public\n\ninstance\n VarRaw : ∀ {T Γ} → T ∈ Γ ↪ ℕ\n ⌊_⌋ {{ VarRaw }} here = zero\n ⌊_⌋ {{ VarRaw }} (there x) = suc ⌊ x ⌋\n\n OTermRaw : ∀ {Γ T d} → Γ ⊢[ d ] T ↪ term d\n ⌊_⌋ {{OTermRaw}} (C (lam b)) = C (lam ⌊ b ⌋)\n ⌊_⌋ {{OTermRaw}} (C tt) = C tt\n ⌊_⌋ {{OTermRaw}} (C ze) = C ze\n ⌊_⌋ {{OTermRaw}} (C (su t)) = C (su ⌊ t ⌋)\n ⌊_⌋ {{OTermRaw}} (C (inj₁ t)) = C (inj₁ ⌊ t ⌋)\n ⌊_⌋ {{OTermRaw}} (C (inj₂ t)) = C (inj₂ ⌊ t ⌋)\n ⌊_⌋ {{OTermRaw}} (C (pair t₁ t₂)) = C (pair ⌊ t₁ ⌋ ⌊ t₂ ⌋)\n ⌊_⌋ {{OTermRaw}} (inv t) = inv ⌊ t ⌋\n ⌊_⌋ {{OTermRaw}} (var x) = var ⌊ x ⌋\n ⌊_⌋ {{OTermRaw}} (f # (apply s)) = ⌊ f ⌋ # apply ⌊ s ⌋\n ⌊_⌋ {{OTermRaw}} (p # fst) = ⌊ p ⌋ # fst\n ⌊_⌋ {{OTermRaw}} (p # snd) = ⌊ p ⌋ # snd\n ⌊_⌋ {{OTermRaw}} (t # case x y) = ⌊ t ⌋ # split ⌊ x ⌋ ⌊ y ⌋\n ⌊_⌋ {{OTermRaw}} (t # iter fs fz) = ⌊ t ⌋ # split ⌊ fs ⌋ ⌊ fz ⌋\n ⌊_⌋ {{OTermRaw}} [ T :∋: t by refl ] = [ T :∋: ⌊ t ⌋ ]\n\ndata _⊢_∋_ (Γ : context)(T : type){d} : term d → Set where\n well-typed : (Δ : Γ ⊢[ d ] T ) → Γ ⊢ T ∋ ⌊ Δ ⌋\n\n-- TODO: one could prove that `Γ ⊢ T ∋ t` is H-prop when `t : term ⇓`, ie. we have\n-- lemma-proof-irr : ∀ {Γ T}{t : term ⇓} → ∀ (pf₁ pf₂ : Γ ⊢ T ∋ t) → → pf₁ ≅ pf₂\n-- but this requires proving that `⌊_⌋` is injective.\n\n-- TODO: conversely, one should be able to prove that `Γ ⊢ T ∋ t` is\n-- equivalent to `type` when `t : term ⇑` but I haven't tried.\n\n-- ** Tests\n\nbool∋true : [] ⊢ bool ∋ true\nbool∋true = well-typed ⊢true\n\nbool∋false : [] ⊢ bool ∋ false\nbool∋false = well-typed ⊢false\n\nnat∋t1 : [] ⊢ nat ∋ t1\nnat∋t1 = well-typed ⊢t1\n\n-- * Ill-type system\n\ndata Canonical {X} : type → can X → Set where\n can-unit-tt : Canonical unit tt\n can-nat-ze : Canonical nat ze\n can-nat-su : ∀ {a} → Canonical nat (su a)\n can-sum-inj₁ : ∀ {A B a} → Canonical (A + B) (inj₁ a)\n can-sum-inj₂ : ∀ {A B b} → Canonical (A + B) (inj₂ b)\n can-prod-pair : ∀ {A B a b} → Canonical (A * B) (pair a b)\n\ndata IsProduct : type → Set where\n is-product : ∀ {A B} → IsProduct (A * B)\n\ndata IsArrow : type → Set where\n is-arrow : ∀ {A B} → IsArrow (A ⇒ B)\n\ndata IsSplit : type → Set where\n is-split-nat : IsSplit nat\n is-split-sum : ∀ {A B} → IsSplit (A + B)\n\nmtype : dir → Set\nmtype ⇑ = ⊤\nmtype ⇓ = type\n\ndata _B⊬[_]_ (Γ : context) : (d : dir) → mtype d → Set where\n not-canonical : ∀ {c : can (term ⇓)}{T} →\n\n ¬ Canonical T c\n → ---------------\n Γ B⊬[ ⇓ ] T\n\n unsafe-inv : ∀ {A B} →\n\n Γ ⊢[ ⇑ ] A → A ≢ B\n → -------------------\n Γ B⊬[ ⇓ ] B\n\n bad-split : ∀ {A B}{c₁ c₂ : term ⇓} →\n\n Γ ⊢[ ⇑ ] A → ¬ IsSplit A\n → -------------------------\n Γ B⊬[ ⇓ ] B\n\n out-of-scope : ∀ {x : ℕ} →\n\n x ≥ length Γ\n → ------------\n Γ B⊬[ ⇑ ] _\n\n bad-function : ∀ {T}{s : term ⇓} →\n\n Γ ⊢[ ⇑ ] T → ¬ IsArrow T\n → ------------------------\n Γ B⊬[ ⇑ ] _\n\n bad-fst : ∀ {T} →\n\n Γ ⊢[ ⇑ ] T → ¬ IsProduct T\n → --------------------------\n Γ B⊬[ ⇑ ] _\n\n bad-snd : ∀ {T} →\n\n Γ ⊢[ ⇑ ] T → ¬ IsProduct T\n → --------------------------\n Γ B⊬[ ⇑ ] _\n\n-- TODO: automate this \"trisection & free monad\" construction by meta-programming\n-- see: \"The gentle art of levitation\", Chapman et al. for the free monad\n-- see: \"Clowns to the left of me, jokers to the right\", McBride for the dissection\nmutual\n data _C⊬[_]_ : context → (d : dir) → mtype d → Set where\n lam : ∀ {Γ A B} → Γ ▹ A ⊬[ ⇓ ] B → Γ C⊬[ ⇓ ] A ⇒ B\n su : ∀ {Γ} → Γ ⊬[ ⇓ ] nat → Γ C⊬[ ⇓ ] nat\n inj₁ : ∀ {Γ A B} → Γ ⊬[ ⇓ ] A → Γ C⊬[ ⇓ ] A + B\n inj₂ : ∀ {Γ A B} → Γ ⊬[ ⇓ ] B → Γ C⊬[ ⇓ ] A + B\n pair₁ : ∀ {Γ A B} → Γ ⊬[ ⇓ ] A → term ⇓ → Γ C⊬[ ⇓ ] A * B\n pair₂ : ∀ {Γ A B} → Γ ⊢[ ⇓ ] A → Γ ⊬[ ⇓ ] B → Γ C⊬[ ⇓ ] A * B\n\n data _E⊬[_]_↝_ : context → (d : dir) → type → mtype d → Set where\n apply : ∀ {Γ A B} → Γ ⊬[ ⇓ ] A → Γ E⊬[ ⇑ ] A ⇒ B ↝ _\n iter₁ : ∀ {Γ T} → Γ ▹ T ⊬[ ⇓ ] T → term ⇓ → Γ E⊬[ ⇓ ] nat ↝ T\n iter₂ : ∀ {Γ T} → Γ ▹ T ⊢[ ⇓ ] T → Γ ⊬[ ⇓ ] T → Γ E⊬[ ⇓ ] nat ↝ T\n case₁ : ∀ {Γ A B C} → Γ ▹ A ⊬[ ⇓ ] C → term ⇓ → Γ E⊬[ ⇓ ] A + B ↝ C\n case₂ : ∀ {Γ A B C} → Γ ▹ A ⊢[ ⇓ ] C → Γ ▹ B ⊬[ ⇓ ] C → Γ E⊬[ ⇓ ] A + B ↝ C\n\n data _⊬[_]_ : context → (d : dir) → mtype d → Set where\n because : ∀ {Γ d T} → Γ B⊬[ d ] T → Γ ⊬[ d ] T\n C : ∀ {Γ d T} → Γ C⊬[ d ] T → Γ ⊬[ d ] T\n inv : ∀ {Γ T} → Γ ⊬[ ⇑ ] _ → Γ ⊬[ ⇓ ] T\n _#₁_ : ∀ {Γ d T} → Γ ⊬[ ⇑ ] _ → elim (term ⇓) d → Γ ⊬[ d ] T\n _#₂_ : ∀ {Γ d I O} → Γ ⊢[ ⇑ ] I → Γ E⊬[ d ] I ↝ O → Γ ⊬[ d ] O\n [_:∋:_] : ∀ {Γ} → (T : type) → Γ ⊬[ ⇓ ] T → Γ ⊬[ ⇑ ] _\n\ninstance\n BTermRaw : ∀ {Γ d T} → Γ B⊬[ d ] T ↪ term d\n ⌊_⌋ {{BTermRaw}} (not-canonical {c} x) = C c\n ⌊_⌋ {{BTermRaw}} (unsafe-inv q _) = inv ⌊ q ⌋\n ⌊_⌋ {{BTermRaw}} (bad-split {c₁ = c₁} {c₂} t _) = ⌊ t ⌋ # split c₁ c₂\n ⌊_⌋ {{BTermRaw}} (out-of-scope {x} _) = var x\n ⌊_⌋ {{BTermRaw}} (bad-function {s = s} f _) = ⌊ f ⌋ # apply s\n ⌊_⌋ {{BTermRaw}} (bad-fst p _) = ⌊ p ⌋ # fst\n ⌊_⌋ {{BTermRaw}} (bad-snd p _) = ⌊ p ⌋ # snd\n\n ETermRaw : ∀ {Γ d T} → Γ ⊬[ d ] T ↪ term d\n ⌊_⌋ {{ETermRaw}} (because e) = ⌊ e ⌋\n ⌊_⌋ {{ETermRaw}} (C (lam b)) = C (lam ⌊ b ⌋)\n ⌊_⌋ {{ETermRaw}} (C (su t)) = C (su ⌊ t ⌋)\n ⌊_⌋ {{ETermRaw}} (C (inj₁ t)) = C (inj₁ ⌊ t ⌋)\n ⌊_⌋ {{ETermRaw}} (C (inj₂ t)) = C (inj₂ ⌊ t ⌋)\n ⌊_⌋ {{ETermRaw}} (C (pair₁ t₁ t₂)) = C (pair ⌊ t₁ ⌋ t₂)\n ⌊_⌋ {{ETermRaw}} (C (pair₂ t₁ t₂)) = C (pair ⌊ t₁ ⌋ ⌊ t₂ ⌋)\n ⌊_⌋ {{ETermRaw}} (inv t) = inv ⌊ t ⌋\n ⌊_⌋ {{ETermRaw}} [ T :∋: t ] = [ T :∋: ⌊ t ⌋ ]\n ⌊_⌋ {{ETermRaw}} (t #₁ e) = ⌊ t ⌋ # e\n ⌊_⌋ {{ETermRaw}} (t #₂ apply x) = ⌊ t ⌋ # apply ⌊ x ⌋\n ⌊_⌋ {{ETermRaw}} (t #₂ iter₁ fs fz) = ⌊ t ⌋ # split ⌊ fs ⌋ fz\n ⌊_⌋ {{ETermRaw}} (t #₂ iter₂ fs fz) = ⌊ t ⌋ # split ⌊ fs ⌋ ⌊ fz ⌋\n ⌊_⌋ {{ETermRaw}} (t #₂ case₁ cX cY) = ⌊ t ⌋ # split ⌊ cX ⌋ cY\n ⌊_⌋ {{ETermRaw}} (t #₂ case₂ cX cY) = ⌊ t ⌋ # split ⌊ cX ⌋ ⌊ cY ⌋\n\n-- * Type-checking\n\n-- ** View on variable lookup\n\ndata _∈-view_ : ℕ → context → Set where\n yes : ∀ {T Γ} → (x : T ∈ Γ) → ⌊ x ⌋ ∈-view Γ\n no : ∀ {Γ n} → n ≥ length Γ → n ∈-view Γ\n\n_∈?_ : ∀ n Γ → n ∈-view Γ\n_ ∈? ε = no z≤n\nzero ∈? Γ ▹ T = yes here\nsuc n ∈? Γ ▹ T\n with n ∈? Γ\n... | yes t = yes (there t)\n... | no q = no (s≤s q)\n\n-- ** View on typing\n\ndata Dir : dir → Set where\n _∈ : term ⇑ → Dir ⇑\n _∋_ : type → term ⇓ → Dir ⇓\n\ninstance\n DirRaw : ∀ {Γ d T} → Γ ⊢[ d ] T ↪ Dir d\n ⌊_⌋ {{DirRaw {d = ⇑}}} e = ⌊ e ⌋ ∈\n ⌊_⌋ {{DirRaw {d = ⇓}{T}}} e = T ∋ ⌊ e ⌋\n\n EDirRaw : ∀ {Γ d T} → Γ ⊬[ d ] T ↪ Dir d\n ⌊_⌋ {{EDirRaw {d = ⇑}}} e = ⌊ e ⌋ ∈\n ⌊_⌋ {{EDirRaw {d = ⇓}{T}}} e = T ∋ ⌊ e ⌋\n\ndata _⊢[_]-view_ (Γ : context)(d : dir) : Dir d → Set where\n yes : ∀ {T} (Δ : Γ ⊢[ d ] T) → Γ ⊢[ d ]-view ⌊ Δ ⌋\n no : ∀ {T} (¬Δ : Γ ⊬[ d ] T) → Γ ⊢[ d ]-view ⌊ ¬Δ ⌋\n\nisYes : ∀ {Γ T t} → Γ ⊢[ ⇓ ]-view T ∋ t → Set\nisYes (yes Δ) = ⊤\nisYes (no ¬Δ) = ⊥\n\nlemma : ∀ {Γ T t} → (pf : Γ ⊢[ ⇓ ]-view T ∋ t) → isYes pf → Γ ⊢ T ∋ t\nlemma (yes Δ) tt = well-typed Δ\nlemma (no _) ()\n\n-- XXX: Mutually-recursive to please the termination checker\n_⊢?_∋_ : (Γ : context)(T : type)(t : term ⇓) → Γ ⊢[ ⇓ ]-view T ∋ t\n_⊢?_∈ : (Γ : context)(t : term ⇑) → Γ ⊢[ ⇑ ]-view t ∈\n\n_⊢?_∋C_ : (Γ : context)(T : type)(t : can (term ⇓)) → Γ ⊢[ ⇓ ]-view T ∋ C t\n\n_!_∋_⊢?_∋#_ : (Γ : context)(I : type)(Δt : Γ ⊢[ ⇑ ] I)(T : type)(e : elim (term ⇓) ⇓) → Γ ⊢[ ⇓ ]-view T ∋ (⌊ Δt ⌋ # e)\n_!_∋_⊢?_∈# : (Γ : context)(T : type)(Δt : Γ ⊢[ ⇑ ] T)(e : elim (term ⇓) ⇑) → Γ ⊢[ ⇑ ]-view (⌊ Δt ⌋ # e) ∈\n\n\nΓ ⊢? T ∋ C t = Γ ⊢? T ∋C t \nΓ ⊢? T ∋ inv t\n with Γ ⊢? t ∈\n... | no ¬Δ = no (inv ¬Δ)\n... | yes {T'} Δ\n with T' ≟ T\n... | yes refl = yes (inv Δ)\n... | no ¬p = no (because (unsafe-inv Δ ¬p))\nΓ ⊢? A ∋ t # e\n with Γ ⊢? t ∈\n... | no ¬Δt = no (¬Δt #₁ e)\n... | yes {T} Δt = Γ ! T ∋ Δt ⊢? A ∋# e \n\n\nΓ ⊢? var k ∈\n with k ∈? Γ\n... | yes x = yes (var x)\n... | no ¬q = no (because (out-of-scope ¬q))\nΓ ⊢? t # e ∈ \n with Γ ⊢? t ∈\n... | no ¬Δt = no (¬Δt #₁ e)\n... | yes {T} Δt = Γ ! T ∋ Δt ⊢? e ∈#\nΓ ⊢? [ T :∋: t ] ∈\n with Γ ⊢? T ∋ t\n... | yes Δt = yes [ T :∋: Δt by refl ]\n... | no ¬Δt = no [ T :∋: ¬Δt ]\n\n\nΓ ⊢? unit ∋C tt = yes (C tt)\nΓ ⊢? unit ∋C pair _ _ = no (because (not-canonical (λ {()})))\nΓ ⊢? unit ∋C lam _ = no (because (not-canonical (λ {()})))\nΓ ⊢? unit ∋C ze = no (because (not-canonical (λ {()})))\nΓ ⊢? unit ∋C su _ = no (because (not-canonical (λ {()})))\nΓ ⊢? unit ∋C inj₁ _ = no (because (not-canonical (λ {()})))\nΓ ⊢? unit ∋C inj₂ _ = no (because (not-canonical (λ {()})))\n\nΓ ⊢? A * B ∋C pair t₁ t₂\n with Γ ⊢? A ∋ t₁ | Γ ⊢? B ∋ t₂\n... | yes Δ₁ | yes Δ₂ = yes (C (pair Δ₁ Δ₂))\n... | yes Δ₁ | no ¬Δ₂ = no (C (pair₂ Δ₁ ¬Δ₂))\n... | no ¬Δ₁ | _ = no (C (pair₁ ¬Δ₁ t₂))\nΓ ⊢? A * B ∋C tt = no (because (not-canonical (λ {()})))\nΓ ⊢? A * B ∋C lam _ = no (because (not-canonical (λ {()})))\nΓ ⊢? A * B ∋C ze = no (because (not-canonical (λ {()})))\nΓ ⊢? A * B ∋C su _ = no (because (not-canonical (λ {()})))\nΓ ⊢? A * B ∋C inj₁ _ = no (because (not-canonical (λ {()})))\nΓ ⊢? A * B ∋C inj₂ _ = no (because (not-canonical (λ {()})))\n\nΓ ⊢? A ⇒ B ∋C lam b\n with Γ ▹ A ⊢? B ∋ b\n... | yes Δ = yes (C (lam Δ))\n... | no ¬Δ = no (C (lam ¬Δ))\nΓ ⊢? A ⇒ B ∋C tt = no (because (not-canonical (λ {()})))\nΓ ⊢? A ⇒ B ∋C ze = no (because (not-canonical (λ {()})))\nΓ ⊢? A ⇒ B ∋C su x = no (because (not-canonical (λ {()})))\nΓ ⊢? A ⇒ B ∋C pair _ _ = no (because (not-canonical (λ {()})))\nΓ ⊢? A ⇒ B ∋C inj₁ _ = no (because (not-canonical (λ {()})))\nΓ ⊢? A ⇒ B ∋C inj₂ _ = no (because (not-canonical (λ {()})))\n\nΓ ⊢? nat ∋C ze = yes (C ze)\nΓ ⊢? nat ∋C su n\n with Γ ⊢? nat ∋ n\n... | yes Δ = yes (C (su Δ))\n... | no ¬Δ = no (C (su ¬Δ))\nΓ ⊢? nat ∋C tt = no (because (not-canonical (λ {()})))\nΓ ⊢? nat ∋C pair _ _ = no (because (not-canonical (λ {()})))\nΓ ⊢? nat ∋C lam _ = no (because (not-canonical (λ {()})))\nΓ ⊢? nat ∋C inj₁ _ = no (because (not-canonical (λ {()})))\nΓ ⊢? nat ∋C inj₂ _ = no (because (not-canonical (λ {()})))\n\nΓ ⊢? A + B ∋C inj₁ t\n with Γ ⊢? A ∋ t\n... | yes Δ = yes (C (inj₁ Δ))\n... | no ¬Δ = no (C (inj₁ ¬Δ))\nΓ ⊢? A + B ∋C inj₂ t\n with Γ ⊢? B ∋ t\n... | yes Δ = yes (C (inj₂ Δ))\n... | no ¬Δ = no (C (inj₂ ¬Δ))\nΓ ⊢? A + B ∋C tt = no (because (not-canonical (λ {()})))\nΓ ⊢? A + B ∋C pair _ _ = no (because (not-canonical (λ {()})))\nΓ ⊢? A + B ∋C lam _ = no (because (not-canonical (λ {()})))\nΓ ⊢? A + B ∋C ze = no (because (not-canonical (λ {()})))\nΓ ⊢? A + B ∋C su _ = no (because (not-canonical (λ {()})))\n\n\nΓ ! nat ∋ Δt ⊢? A ∋# split fs fz\n with Γ ▹ A ⊢? A ∋ fs | Γ ⊢? A ∋ fz\n... | yes Δfs | yes Δfz = yes (Δt # iter Δfs Δfz)\n... | yes Δfs | no ¬Δfz = no (Δt #₂ iter₂ Δfs ¬Δfz)\n... | no ¬Δfs | _ = no (Δt #₂ iter₁ ¬Δfs fz)\nΓ ! X + Y ∋ Δt ⊢? A ∋# split cX cY \n with (X ∷ Γ) ⊢? A ∋ cX | (Y ∷ Γ) ⊢? A ∋ cY\n... | yes ΔcX | yes ΔcY = yes (Δt # case ΔcX ΔcY)\n... | yes ΔcX | no ¬ΔcY = no (Δt #₂ case₂ ΔcX ¬ΔcY)\n... | no ¬ΔcX | _ = no (Δt #₂ case₁ ¬ΔcX cY)\nΓ ! unit ∋ Δt ⊢? A ∋# split _ _ = no (because (bad-split Δt (λ {()})))\nΓ ! _ ⇒ _ ∋ Δt ⊢? A ∋# split _ _ = no (because (bad-split Δt (λ {()})))\nΓ ! _ * _ ∋ Δt ⊢? A ∋# split _ _ = no (because (bad-split Δt (λ {()})))\n\n\nΓ ! A ⇒ B ∋ Δf ⊢? apply s ∈# \n with Γ ⊢? A ∋ s\n... | yes Δs = yes (Δf # apply Δs)\n... | no ¬Δs = no (Δf #₂ apply ¬Δs)\nΓ ! unit ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))\nΓ ! nat ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))\nΓ ! _ + _ ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))\nΓ ! _ * _ ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))\n\nΓ ! A * B ∋ Δp ⊢? fst ∈# = yes (Δp # fst)\nΓ ! unit ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))\nΓ ! nat ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))\nΓ ! _ + _ ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))\nΓ ! _ ⇒ _ ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))\n\nΓ ! A * B ∋ Δp ⊢? snd ∈# = yes (Δp # snd)\nΓ ! unit ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))\nΓ ! nat ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))\nΓ ! _ + _ ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))\nΓ ! _ ⇒ _ ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))\n\n-- ** Tests\n\nnat∋t1' : [] ⊢ nat ∋ t1\nnat∋t1' = lemma ([] ⊢? nat ∋ t1) tt\n\nT1 : type\nT1 = nat ⇒ (unit + unit)\n\nT2 : type\nT2 = (nat + unit) ⇒ (unit + unit)\n\nT1∋t2 : [] ⊢ T1 ∋ t2\nT1∋t2 = lemma ([] ⊢? T1 ∋ t2) tt\n\nT2∋t2 : [] ⊢ T2 ∋ t2\nT2∋t2 = lemma ([] ⊢? T2 ∋ t2) tt\n", "meta": {"hexsha": "120d854e6656ddba8e65afe476a6736c14b8edde", "size": 18919, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "STLC.agda", "max_stars_repo_name": "pedagand/typechecker-evolution", "max_stars_repo_head_hexsha": "f807a85ccd570905d3dd834b5966efcf6f215e64", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 43, "max_stars_repo_stars_event_min_datetime": "2018-02-14T20:50:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T11:13:36.000Z", "max_issues_repo_path": "STLC.agda", "max_issues_repo_name": "pedagand/typechecker-evolution", "max_issues_repo_head_hexsha": "f807a85ccd570905d3dd834b5966efcf6f215e64", "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": "STLC.agda", "max_forks_repo_name": "pedagand/typechecker-evolution", "max_forks_repo_head_hexsha": "f807a85ccd570905d3dd834b5966efcf6f215e64", "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": 30.1738437002, "max_line_length": 119, "alphanum_fraction": 0.3955283049, "num_tokens": 8774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056167854461, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3928026333598574}} {"text": "------------------------------------------------------------------------\n-- A relational semantics which uses closures and environments\n------------------------------------------------------------------------\n\nmodule Lambda.Closure.Relational where\n\nopen import Codata.Musical.Notation\nopen import Data.Empty\nopen import Data.List hiding (lookup)\nopen import Data.Product\nopen import Data.Vec using (Vec; _∷_; []; lookup)\nopen import Function.Base\nopen import\n Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\nopen import Relation.Nullary\n\nopen import Lambda.Syntax using (Tm; con; var; ƛ; _·_)\nopen Lambda.Syntax.Closure Tm\nopen import Lambda.VirtualMachine as VM\nopen VM.Relational\nopen StarReasoning _⟶_\nopen InfiniteSequence\n\n------------------------------------------------------------------------\n-- Big-step semantics\n\n-- For terminating computations.\n\ninfix 4 _⊢_⇓_\n\ndata _⊢_⇓_ {n} (ρ : Env n) : Tm n → Value → Set where\n var : ∀ {x} → ρ ⊢ var x ⇓ lookup ρ x\n con : ∀ {i} → ρ ⊢ con i ⇓ con i\n ƛ : ∀ {t} → ρ ⊢ ƛ t ⇓ ƛ t ρ\n app : ∀ {t₁ t₂ n t} {ρ′ : Env n} {v v′}\n (t₁⇓ : ρ ⊢ t₁ ⇓ ƛ t ρ′)\n (t₂⇓ : ρ ⊢ t₂ ⇓ v′)\n (t₁t₂⇓ : v′ ∷ ρ′ ⊢ t ⇓ v) →\n ρ ⊢ t₁ · t₂ ⇓ v\n\n-- For non-terminating computations.\n\ninfix 4 _⊢_⇑\n\ndata _⊢_⇑ {n} (ρ : Env n) : Tm n → Set where\n app : ∀ {t₁ t₂ n t} {ρ′ : Env n} {v′}\n (t₁⇓ : ρ ⊢ t₁ ⇓ ƛ t ρ′)\n (t₂⇓ : ρ ⊢ t₂ ⇓ v′)\n (t₁t₂⇑ : ∞ (v′ ∷ ρ′ ⊢ t ⇑)) →\n ρ ⊢ t₁ · t₂ ⇑\n ·ˡ : ∀ {t₁ t₂}\n (t₁⇑ : ∞ (ρ ⊢ t₁ ⇑)) →\n ρ ⊢ t₁ · t₂ ⇑\n ·ʳ : ∀ {t₁ t₂ v}\n (t₁⇓ : ρ ⊢ t₁ ⇓ v)\n (t₂⇑ : ∞ (ρ ⊢ t₂ ⇑)) →\n ρ ⊢ t₁ · t₂ ⇑\n\n-- For crashing computations.\n\ninfix 4 _⊢_↯\n\n_⊢_↯ : ∀ {n} → Env n → Tm n → Set\nρ ⊢ t ↯ = ¬ (∃ λ v → ρ ⊢ t ⇓ v) × ¬ (ρ ⊢ t ⇑)\n\n------------------------------------------------------------------------\n-- The semantics is deterministic\n\ndeterministic⇓ : ∀ {n} {ρ : Env n} {t v₁ v₂} →\n ρ ⊢ t ⇓ v₁ → ρ ⊢ t ⇓ v₂ → v₁ ≡ v₂\ndeterministic⇓ var var = P.refl\ndeterministic⇓ con con = P.refl\ndeterministic⇓ ƛ ƛ = P.refl\ndeterministic⇓ (app t₁⇓ t₂⇓ t₁t₂⇓) (app t₁⇓′ t₂⇓′ t₁t₂⇓′)\n with deterministic⇓ t₁⇓ t₁⇓′ | deterministic⇓ t₂⇓ t₂⇓′\n... | P.refl | P.refl = deterministic⇓ t₁t₂⇓ t₁t₂⇓′\n\ndeterministic⇓⇑ : ∀ {n} {ρ : Env n} {t v} →\n ρ ⊢ t ⇓ v → ρ ⊢ t ⇑ → ⊥\ndeterministic⇓⇑ var ()\ndeterministic⇓⇑ con ()\ndeterministic⇓⇑ ƛ ()\ndeterministic⇓⇑ (app t₁⇓ t₂⇓ t₁t₂⇓) (app t₁⇓′ t₂⇓′ t₁t₂⇑)\n with deterministic⇓ t₁⇓ t₁⇓′ | deterministic⇓ t₂⇓ t₂⇓′\n... | P.refl | P.refl = deterministic⇓⇑ t₁t₂⇓ (♭ t₁t₂⇑)\ndeterministic⇓⇑ (app t₁⇓ t₂⇓ t₁t₂⇓) (·ˡ t₁⇑) =\n deterministic⇓⇑ t₁⇓ (♭ t₁⇑)\ndeterministic⇓⇑ (app t₁⇓ t₂⇓ t₁t₂⇓) (·ʳ t₁⇓′ t₂⇑) =\n deterministic⇓⇑ t₂⇓ (♭ t₂⇑)\n\n------------------------------------------------------------------------\n-- Compiler \"correctness\"\n\n-- The proofs below establish that the compiler in\n-- Lambda.VirtualMachine preserves the semantics above (_⊢_⇓_ and\n-- _⊢_⇑, not necessarily _⊢_↯), given that the virtual machine is\n-- deterministic.\n\ncorrect⇓′ : ∀ {n ρ c s v} {t : Tm n} →\n ρ ⊢ t ⇓ v →\n ⟨ comp t c , s , comp-env ρ ⟩ ⟶⋆\n ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩\ncorrect⇓′ {ρ = ρ} {c} {s} (var {x}) = begin\n ⟨ var x ∷ c , s , comp-env ρ ⟩ ⟶⟨ var ⟩\n ⟨ c , val (lookup (comp-env ρ) x) ∷ s , comp-env ρ ⟩ ≡⟨ P.cong (λ v → ⟨ c , val v ∷ s , comp-env ρ ⟩)\n (lookup-hom x ρ) ⟩\n ⟨ c , val (comp-val (lookup ρ x)) ∷ s , comp-env ρ ⟩ ∎\ncorrect⇓′ {ρ = ρ} {c} {s} (con {i}) = begin\n ⟨ con i ∷ c , s , comp-env ρ ⟩ ⟶⟨ con ⟩\n ⟨ c , val (Lambda.Syntax.Closure.con i) ∷ s , comp-env ρ ⟩ ∎\ncorrect⇓′ {ρ = ρ} {c} {s} (ƛ {t}) = begin\n ⟨ clo (comp t [ ret ]) ∷ c , s , comp-env ρ ⟩ ⟶⟨ clo ⟩\n ⟨ c , val (comp-val (ƛ t ρ)) ∷ s , comp-env ρ ⟩ ∎\ncorrect⇓′ {ρ = ρ} {c} {s} {v} (app {t₁} {t₂} {t = t} {ρ′} {v′ = v′} t₁⇓ t₂⇓ t₁t₂⇓) = begin\n ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ⟶⋆⟨ correct⇓′ t₁⇓ ⟩\n ⟨ comp t₂ (app ∷ c) , val (comp-val (ƛ t ρ′)) ∷ s , comp-env ρ ⟩ ⟶⋆⟨ correct⇓′ t₂⇓ ⟩\n ⟨ app ∷ c , val (comp-val v′) ∷ val (comp-val (ƛ t ρ′)) ∷ s , comp-env ρ ⟩ ⟶⟨ app ⟩\n ⟨ comp t [ ret ] , ret c (comp-env ρ) ∷ s , comp-val v′ ∷ comp-env ρ′ ⟩ ⟶⋆⟨ correct⇓′ t₁t₂⇓ ⟩\n ⟨ [ ret ] , val (comp-val v) ∷ ret c (comp-env ρ) ∷ s , comp-val v′ ∷ comp-env ρ′ ⟩ ⟶⟨ ret ⟩\n ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ∎\n\ncorrect⇑′ : ∀ {n ρ c s} {t : Tm n} →\n ρ ⊢ t ⇑ → ⟨ comp t c , s , comp-env ρ ⟩ ⟶∞′\ncorrect⇑′ {ρ = ρ} {c} {s} (app {t₁} {t₂} {t = t} {ρ′} {v′} t₁⇓ t₂⇓ t₁t₂⇑) =\n ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ⟶⋆⟨ correct⇓′ t₁⇓ ⟩′\n ⟨ comp t₂ (app ∷ c) , val (comp-val (ƛ t ρ′)) ∷ s , comp-env ρ ⟩ ⟶⋆⟨ correct⇓′ t₂⇓ ⟩′\n ⟨ app ∷ c , val (comp-val v′) ∷ val (comp-val (ƛ t ρ′)) ∷ s , comp-env ρ ⟩ ⟶⟨ app ⟩′ ♯\n (⟨ comp t [ ret ] , ret c (comp-env ρ) ∷ s , comp-val v′ ∷ comp-env ρ′ ⟩ ⟶∞⟨ correct⇑′ (♭ t₁t₂⇑) ⟩)\ncorrect⇑′ {ρ = ρ} {c} {s} (·ˡ {t₁} {t₂} t₁⇑) =\n ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ⟶∞⟨ correct⇑′ (♭ t₁⇑) ⟩\ncorrect⇑′ {ρ = ρ} {c} {s} (·ʳ {t₁} {t₂} {v} t₁⇓ t₂⇑) =\n ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ⟶⋆⟨ correct⇓′ t₁⇓ ⟩′\n ⟨ comp t₂ (app ∷ c) , val (comp-val v) ∷ s , comp-env ρ ⟩ ⟶∞⟨ correct⇑′ (♭ t₂⇑) ⟩\n\ncorrect⇓ : ∀ {t v} →\n [] ⊢ t ⇓ v →\n ∃ λ s → ⟨ comp t [] , [] , [] ⟩ ⟶⋆ s × s ⇓ comp-val v\ncorrect⇓ t⇓ = (_ , correct⇓′ t⇓ , final)\n\ncorrect⇑ : ∀ {t} → [] ⊢ t ⇑ → ⟨ comp t [] , [] , [] ⟩ ⟶∞\ncorrect⇑ = InfiniteSequence.sound ∘ correct⇑′\n", "meta": {"hexsha": "4563dc1c5145e7851a354ec1706b7dbe3a9d0271", "size": 6313, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Lambda/Closure/Relational.agda", "max_stars_repo_name": "nad/codata", "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_issues_repo_path": "Lambda/Closure/Relational.agda", "max_issues_repo_name": "nad/codata", "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": "Lambda/Closure/Relational.agda", "max_forks_repo_name": "nad/codata", "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": 44.1468531469, "max_line_length": 138, "alphanum_fraction": 0.4153334389, "num_tokens": 2779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056040203135, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3928026260856127}} {"text": "-- {-# OPTIONS --show-implicit --show-irrelevant #-}\nmodule Data.QuadTree.LensProofs.Valid-LensGo where\n\nopen import Haskell.Prelude renaming (zero to Z; suc to S)\nopen import Data.Lens.Lens\nopen import Data.Logic\nopen import Data.QuadTree.InternalAgda\nopen import Agda.Primitive\nopen import Data.Lens.Proofs.LensLaws\nopen import Data.Lens.Proofs.LensPostulates\nopen import Data.Lens.Proofs.LensComposition\nopen import Data.QuadTree.LensProofs.Valid-LensLeaf\nopen import Data.QuadTree.LensProofs.Valid-LensA\nopen import Data.QuadTree.LensProofs.Valid-LensBCD\nopen import Axiom.Extensionality.Propositional\nopen import Data.QuadTree.Implementation.QuadrantLenses\nopen import Data.QuadTree.Implementation.Definition\nopen import Data.QuadTree.Implementation.ValidTypes\nopen import Data.QuadTree.Implementation.SafeFunctions\nopen import Data.QuadTree.Implementation.PublicFunctions\nopen import Data.QuadTree.Implementation.DataLenses\n\n{-\nI spend close to 50 hours on this file, at the time of writing more than the rest of the lens proofs combined.\nThe file still looks horrible and there is very serious code duplication, but I honestly wish to never look at this file again.\n\nIn order to proof this we need some form of Extensionality\nBecause this is quite a complicated application of Extensionality, I did not proof it from generic Extensionality, but just postulated it seperately.\nIt is needed because Agda eagerly applies implicit arguments at the start of a function, which I don't want it to do\nThis can be used to reverse agda doing that\n-}\n\n\n\npostulate\n FunctorExtensionality : \n {t : Set} {{eqT : Eq t}} -> {deps : Nat} ->\n {la lb : Lens (VQuadrant t {S deps}) t}\n -> ({f : Set -> Set} -> {{ff : Functor f}} -> (la {f} {{ff}} ≡ lb {f} {{ff}}))\n -> (λ {f} ⦃ ff ⦄ → la {f} {{ff}}) ≡ (λ {f} ⦃ ff ⦄ → lb {f} {{ff}})\n\n---- Lens laws for go\n\nValidLens-go-ViewSet : \n {t : Set} {{eqT : Eq t}}\n -> (loc : Nat × Nat) -> (dep : Nat)\n -> {ins : IsTrue (isInsidePow loc dep)}\n -> ViewSet (go {t} loc dep {ins})\nValidLens-go-SetView : \n {t : Set} {{eqT : Eq t}}\n -> (loc : Nat × Nat) -> (dep : Nat)\n -> {ins : IsTrue (isInsidePow loc dep)}\n -> SetView (go {t} loc dep {ins})\nValidLens-go-SetSet : \n {t : Set} {{eqT : Eq t}}\n -> (loc : Nat × Nat) -> (dep : Nat)\n -> {ins : IsTrue (isInsidePow loc dep)}\n -> SetSet (go {t} loc dep {ins})\n\nValidLens-go : {t : Set} {{eqT : Eq t}}\n -> (loc : Nat × Nat) -> (dep : Nat)\n -> {IsTrue (isInsidePow loc dep)}\n -> ValidLens (VQuadrant t {dep}) t\nValidLens-go {t} {{eqT}} loc dep {ins} = CValidLens (go loc dep {ins}) (ValidLens-go-ViewSet loc dep {ins}) (ValidLens-go-SetView loc dep {ins}) (ValidLens-go-SetSet loc dep {ins})\n\n\nValidLens-go-ViewSet loc Z v cvq@(CVQuadrant (Leaf x) {p}) = refl\nValidLens-go-ViewSet {t} (x , y) dep@(S deps) {ins} v cvq@(CVQuadrant qd {p}) =\n ifc y < mid then (λ {{py}} ->\n ifc x < mid then (λ {{px}} ->\n trans \n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> view g (set g v cvq)) \n -- Select only the lensA branch\n (FunctorExtensionality (trans (ifTrue (y < mid) py) (ifTrue (x < mid) px))))\n -- Then use the property of composition to proof the law\n (prop-Composition-ViewSet (ValidLens-LensA) (ValidLens-go (mod x mid , mod y mid) deps {andCombine (modLt x mid {pow_not_zero_cv deps}) (modLt y mid {pow_not_zero_cv deps})}) v cvq)\n ) else (λ {{px}} ->\n trans \n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> view g (set g v cvq)) \n -- Select only the lensB branch\n (FunctorExtensionality (trans (ifTrue (y < mid) py) (ifFalse (x < mid) px))))\n -- Then use the property of composition to proof the law\n (prop-Composition-ViewSet (ValidLens-LensB) (ValidLens-go (mod x mid , mod y mid) deps {andCombine (modLt x mid {pow_not_zero_cv deps}) (modLt y mid {pow_not_zero_cv deps})}) v cvq)\n )\n ) else (λ {{py}} ->\n ifc x < mid then (λ {{px}} ->\n trans \n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> view g (set g v cvq)) \n -- Select only the lensC branch\n (FunctorExtensionality (trans (ifFalse (y < mid) py) (ifTrue (x < mid) px))))\n -- Then use the property of composition to proof the law\n (prop-Composition-ViewSet (ValidLens-LensC) (ValidLens-go (mod x mid , mod y mid) deps {andCombine (modLt x mid {pow_not_zero_cv deps}) (modLt y mid {pow_not_zero_cv deps})}) v cvq)\n ) else (λ {{px}} ->\n trans \n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> view g (set g v cvq)) \n -- Select only the lensD branch\n (FunctorExtensionality (trans (ifFalse (y < mid) py) (ifFalse (x < mid) px))))\n -- Then use the property of composition to proof the law\n (prop-Composition-ViewSet (ValidLens-LensD) (ValidLens-go (mod x mid , mod y mid) deps {andCombine (modLt x mid {pow_not_zero_cv deps}) (modLt y mid {pow_not_zero_cv deps})}) v cvq)\n )\n )\n where\n mid = pow 2 deps\n\nValidLens-go-SetView loc Z cvq@(CVQuadrant (Leaf x) {p}) = refl\nValidLens-go-SetView {t} (x , y) dep@(S deps) {ins} cvq@(CVQuadrant qd {p}) =\n ifc y < mid then (λ {{py}} ->\n ifc x < mid then (λ {{px}} ->\n trans \n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> set g (view g cvq) cvq) \n -- Select only the lensA branch\n (FunctorExtensionality (trans (ifTrue (y < mid) py) (ifTrue (x < mid) px))))\n -- Then use the property of composition to proof the law\n (prop-Composition-SetView (ValidLens-LensA) (ValidLens-go (mod x mid , mod y mid) deps {andCombine (modLt x mid {pow_not_zero_cv deps}) (modLt y mid {pow_not_zero_cv deps})}) cvq)\n ) else (λ {{px}} ->\n trans \n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> set g (view g cvq) cvq) \n -- Select only the lensB branch\n (FunctorExtensionality (trans (ifTrue (y < mid) py) (ifFalse (x < mid) px))))\n -- Then use the property of composition to proof the law\n (prop-Composition-SetView (ValidLens-LensB) (ValidLens-go (mod x mid , mod y mid) deps {andCombine (modLt x mid {pow_not_zero_cv deps}) (modLt y mid {pow_not_zero_cv deps})}) cvq)\n )\n ) else (λ {{py}} ->\n ifc x < mid then (λ {{px}} ->\n trans \n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> set g (view g cvq) cvq) \n -- Select only the lensC branch\n (FunctorExtensionality (trans (ifFalse (y < mid) py) (ifTrue (x < mid) px))))\n -- Then use the property of composition to proof the law\n (prop-Composition-SetView (ValidLens-LensC) (ValidLens-go (mod x mid , mod y mid) deps {andCombine (modLt x mid {pow_not_zero_cv deps}) (modLt y mid {pow_not_zero_cv deps})}) cvq)\n ) else (λ {{px}} ->\n trans \n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> set g (view g cvq) cvq) \n -- Select only the lensD branch\n (FunctorExtensionality (trans (ifFalse (y < mid) py) (ifFalse (x < mid) px))))\n -- Then use the property of composition to proof the law\n (prop-Composition-SetView (ValidLens-LensD) (ValidLens-go (mod x mid , mod y mid) deps {andCombine (modLt x mid {pow_not_zero_cv deps}) (modLt y mid {pow_not_zero_cv deps})}) cvq)\n )\n )\n where\n mid = pow 2 deps\n\nValidLens-go-SetSet loc Z v1 v2 cvq@(CVQuadrant (Leaf x) {p}) = refl\nValidLens-go-SetSet {t} (x , y) dep@(S deps) {ins} v1 v2 cvq@(CVQuadrant qd {p}) =\n ifc y < mid then (λ {{py}} ->\n ifc x < mid then (λ {{px}} ->\n trans\n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> set g v2 (set g v1 cvq)) \n -- Select only the lensA branch\n (FunctorExtensionality (trans (ifTrue (y < mid) py) (ifTrue (x < mid) px))))\n (trans\n -- Then use the property of composition to proof the law\n (prop-Composition-SetSet (ValidLens-LensA) (ValidLens-go (mod x mid , mod y mid) deps {modproof}) v1 v2 cvq)\n -- Finally, cong back over the law, applying the transformation to go\n (sym $ cong {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}}} \n (λ (g : Lens (VQuadrant t {dep}) t) -> set g v2 cvq) \n (FunctorExtensionality (trans (ifTrue (y < mid) py) (ifTrue (x < mid) px)))))\n ) else (λ {{px}} ->\n trans\n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> set g v2 (set g v1 cvq)) \n -- Select only the lensB branch\n (FunctorExtensionality (trans (ifTrue (y < mid) py) (ifFalse (x < mid) px))))\n (trans\n -- Then use the property of composition to proof the law\n (prop-Composition-SetSet (ValidLens-LensB) (ValidLens-go (mod x mid , mod y mid) deps {modproof}) v1 v2 cvq)\n -- Finally, cong back over the law, applying the transformation to go\n (sym $ cong {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}}} \n (λ (g : Lens (VQuadrant t {dep}) t) -> set g v2 cvq) \n (FunctorExtensionality (trans (ifTrue (y < mid) py) (ifFalse (x < mid) px)))))\n )\n ) else (λ {{py}} ->\n ifc x < mid then (λ {{px}} ->\n trans\n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> set g v2 (set g v1 cvq)) \n -- Select only the lensC branch\n (FunctorExtensionality (trans (ifFalse (y < mid) py) (ifTrue (x < mid) px))))\n (trans\n -- Then use the property of composition to proof the law\n (prop-Composition-SetSet (ValidLens-LensC) (ValidLens-go (mod x mid , mod y mid) deps {modproof}) v1 v2 cvq)\n -- Finally, cong back over the law, applying the transformation to go\n (sym $ cong {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}}} \n (λ (g : Lens (VQuadrant t {dep}) t) -> set g v2 cvq) \n (FunctorExtensionality (trans (ifFalse (y < mid) py) (ifTrue (x < mid) px)))))\n ) else (λ {{px}} ->\n trans\n (cong \n -- We need to explicitly provide the x, otherwise agda gets confused\n {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}} } \n -- We cong over the law, applying the transformation to go\n (λ (g : Lens (VQuadrant t {dep}) t) -> set g v2 (set g v1 cvq)) \n -- Select only the lensD branch\n (FunctorExtensionality (trans (ifFalse (y < mid) py) (ifFalse (x < mid) px))))\n (trans\n -- Then use the property of composition to proof the law\n (prop-Composition-SetSet (ValidLens-LensD) (ValidLens-go (mod x mid , mod y mid) deps {modproof}) v1 v2 cvq)\n -- Finally, cong back over the law, applying the transformation to go\n (sym $ cong {x = λ {f} ⦃ ff ⦄ → go (x , y) (S deps) {ins} {f} {{ff}}} \n (λ (g : Lens (VQuadrant t {dep}) t) -> set g v2 cvq) \n (FunctorExtensionality (trans (ifFalse (y < mid) py) (ifFalse (x < mid) px)))))\n )\n )\n\n where\n mid = pow 2 deps\n modproof = andCombine (modLt x mid {pow_not_zero_cv deps}) (modLt y mid {pow_not_zero_cv deps})\n", "meta": {"hexsha": "c671be28e88076a420d56e798f9d671b47dcd0c9", "size": 14843, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Data/QuadTree/LensProofs/Valid-LensGo.agda", "max_stars_repo_name": "JonathanBrouwer/research-project", "max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z", "max_issues_repo_path": "src/Data/QuadTree/LensProofs/Valid-LensGo.agda", "max_issues_repo_name": "JonathanBrouwer/research-project", "max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_issues_repo_licenses": ["Unlicense"], "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/Data/QuadTree/LensProofs/Valid-LensGo.agda", "max_forks_repo_name": "JonathanBrouwer/research-project", "max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.372, "max_line_length": 197, "alphanum_fraction": 0.5327763929, "num_tokens": 4238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754607093178, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3923665583947088}} {"text": "{-# OPTIONS --without-K --exact-split #-}\n\nmodule free-group where\n\nimport 15-groups\nopen 15-groups public\n\n{- We state the universal property of the free group on a set X -}\n\nprecomp-universal-property-free-group :\n {l1 l2 l3 : Level} (X : UU-Set l1) (F : Group l2) (G : Group l3)\n (f : type-hom-Set X (set-Group F)) →\n hom-Group F G → type-hom-Set X (set-Group G)\nprecomp-universal-property-free-group X F G f g = (map-hom-Group F G g) ∘ f\n\nuniversal-property-free-group :\n (l : Level) {l1 l2 : Level} (X : UU-Set l1) (F : Group l2)\n (f : type-hom-Set X (set-Group F)) → UU (lsuc l ⊔ l1 ⊔ l2)\nuniversal-property-free-group l X F f =\n (G : Group l) → is-equiv (precomp-universal-property-free-group X F G f)\n\n{- We state the universal property of the initial set equipped with a point\n and an automorphism for each x : X. -}\n\nuniversal-property-initial-pset-with-automorphisms :\n (l : Level) {l1 l2 : Level} (X : UU-Set l1) (Y : UU-Set l2)\n (pt-Y : type-Set Y) (f : type-Set X → (type-Set Y ≃ type-Set Y)) →\n UU (lsuc l ⊔ l1 ⊔ l2)\nuniversal-property-initial-pset-with-automorphisms l X Y pt-Y f =\n (Z : UU-Set l) (pt-Z : type-Set Z) (g : type-Set X → (type-Set Z ≃ type-Set Z)) →\n is-contr\n ( Σ ( type-hom-Set Y Z)\n ( λ h →\n ( Id (h pt-Y) pt-Z) ×\n ( (x : type-Set X) (y : type-Set Y) →\n Id (h (map-equiv (f x) y)) (map-equiv (g x) (h y)))))\n\nmap-initial-pset-with-automorphisms :\n { l1 l2 l3 : Level} (X : UU-Set l1) (Y : UU-Set l2) (pt-Y : type-Set Y)\n ( f : type-Set X → (type-Set Y ≃ type-Set Y)) →\n ( {l : Level} →\n universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →\n ( Z : UU-Set l3) (pt-Z : type-Set Z)\n ( g : type-Set X → (type-Set Z ≃ type-Set Z)) →\n type-hom-Set Y Z\nmap-initial-pset-with-automorphisms\n X Y pt-Y f up-Y Z pt-Z g = pr1 (center (up-Y Z pt-Z g))\n\npreserves-point-map-initial-pset-with-automorphisms :\n { l1 l2 l3 : Level} (X : UU-Set l1) (Y : UU-Set l2) (pt-Y : type-Set Y)\n ( f : type-Set X → (type-Set Y ≃ type-Set Y)) →\n ( up-Y : {l : Level} →\n universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →\n ( Z : UU-Set l3) (pt-Z : type-Set Z)\n ( g : type-Set X → (type-Set Z ≃ type-Set Z)) →\n Id (map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g pt-Y) pt-Z\npreserves-point-map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g =\n pr1 (pr2 (center (up-Y Z pt-Z g)))\n\nhtpy-map-initial-pset-with-automorphisms :\n { l1 l2 l3 : Level} (X : UU-Set l1) (Y : UU-Set l2) (pt-Y : type-Set Y)\n ( f : type-Set X → (type-Set Y ≃ type-Set Y)) →\n ( up-Y : {l : Level} →\n universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →\n ( Z : UU-Set l3) (pt-Z : type-Set Z)\n ( g : type-Set X → (type-Set Z ≃ type-Set Z)) →\n ( x : type-Set X) (y : type-Set Y) →\n Id ( map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g\n ( map-equiv (f x) y))\n ( map-equiv (g x)\n ( map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g y))\nhtpy-map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g =\n pr2 (pr2 (center (up-Y Z pt-Z g)))\n\n{- We show a dependent elimination property for the initial pointed set with\n an automorphism for each x : X. -}\n\ndependent-up-initial-pset-with-automorphisms :\n { l1 l2 l3 l4 : Level} (X : UU-Set l1) (Y : UU-Set l2) (pt-Y : type-Set Y)\n ( f : type-Set X → (type-Set Y ≃ type-Set Y)) →\n ( up-Y : {l : Level} →\n universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →\n ( Z : UU-Set l3) (pt-Z : type-Set Z)\n ( g : type-Set X → (type-Set Z ≃ type-Set Z)) →\n ( P : type-Set Z → UU-Set l4)\n ( p : type-Set (P pt-Z))\n ( e : (x : type-Set X) (z : type-Set Z) →\n type-Set (P z) ≃ type-Set (P (map-equiv (g x) z))) →\n ( y : type-Set Y) →\n type-Set (P (map-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g y))\ndependent-up-initial-pset-with-automorphisms X Y pt-Y f up-Y Z pt-Z g P p e =\n {!!}\n \n \n{- We show that the initial set equipped with a point and an automorphism for\n each x : X is a group. -}\n\nmul-initial-pset-with-automorphisms :\n {l1 l2 : Level} (X : UU-Set l1) (Y : UU-Set l2)\n (pt-Y : type-Set Y) (f : type-Set X → (type-Set Y ≃ type-Set Y)) →\n ( {l : Level} →\n universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →\n type-Set Y → type-Set Y → type-Set Y\nmul-initial-pset-with-automorphisms {l1} {l2} X Y pt-Y f up-Y =\n map-initial-pset-with-automorphisms\n X Y pt-Y f up-Y (hom-Set Y Y) id\n ( λ x → equiv-postcomp (type-Set Y) (f x))\n\nassociative-mul-initial-pset-with-automorphisms :\n {l1 l2 : Level} (X : UU-Set l1) (Y : UU-Set l2)\n (pt-Y : type-Set Y) (f : type-Set X → (type-Set Y ≃ type-Set Y)) →\n ( up-Y : {l : Level} →\n universal-property-initial-pset-with-automorphisms l X Y pt-Y f) →\n ( x y z : type-Set Y) →\n Id ( mul-initial-pset-with-automorphisms X Y pt-Y f up-Y\n ( mul-initial-pset-with-automorphisms X Y pt-Y f up-Y x y) z)\n ( mul-initial-pset-with-automorphisms X Y pt-Y f up-Y x\n ( mul-initial-pset-with-automorphisms X Y pt-Y f up-Y y z))\nassociative-mul-initial-pset-with-automorphisms X Y pt-Y f up-Y x y z = {!refl!}\n", "meta": {"hexsha": "1d3b53b038626f851b43c2dbbd8b2c21db6764af", "size": 5144, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Agda/free-group.agda", "max_stars_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_stars_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 333, "max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z", "max_issues_repo_path": "Agda/free-group.agda", "max_issues_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_issues_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z", "max_forks_repo_path": "Agda/free-group.agda", "max_forks_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_forks_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z", "avg_line_length": 42.8666666667, "max_line_length": 83, "alphanum_fraction": 0.6069206843, "num_tokens": 1961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300698514778, "lm_q2_score": 0.5583269943353744, "lm_q1q2_score": 0.39224150233039623}} {"text": "{-# OPTIONS --safe #-}\nmodule Cubical.Categories.Limits.Pullback where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.HLevels\nopen import Cubical.HITs.PropositionalTruncation.Base\n\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Categories.Category\nopen import Cubical.Categories.Functor\nopen import Cubical.Categories.Instances.Cospan\n\nprivate\n variable\n ℓ ℓ' : Level\n\nmodule _ (C : Category ℓ ℓ') where\n\n open Category C\n open Functor\n\n record Cospan : Type (ℓ-max ℓ ℓ') where\n constructor cospan\n field\n l m r : ob\n s₁ : C [ l , m ]\n s₂ : C [ r , m ]\n\n open Cospan\n\n isPullback : (cspn : Cospan) →\n {c : ob} (p₁ : C [ c , cspn .l ]) (p₂ : C [ c , cspn .r ])\n (H : p₁ ⋆ cspn .s₁ ≡ p₂ ⋆ cspn .s₂) → Type (ℓ-max ℓ ℓ')\n isPullback cspn {c} p₁ p₂ H =\n ∀ {d} (h : C [ d , cspn .l ]) (k : C [ d , cspn .r ])\n (H' : h ⋆ cspn .s₁ ≡ k ⋆ cspn .s₂)\n → ∃![ hk ∈ C [ d , c ] ] (h ≡ hk ⋆ p₁) × (k ≡ hk ⋆ p₂)\n\n isPropIsPullback : (cspn : Cospan) →\n {c : ob} (p₁ : C [ c , cspn .l ]) (p₂ : C [ c , cspn .r ])\n (H : p₁ ⋆ cspn .s₁ ≡ p₂ ⋆ cspn .s₂) → isProp (isPullback cspn p₁ p₂ H)\n isPropIsPullback cspn p₁ p₂ H =\n isPropImplicitΠ (λ x → isPropΠ3 λ h k H' → isPropIsContr)\n\n record Pullback (cspn : Cospan) : Type (ℓ-max ℓ ℓ') where\n field\n pbOb : ob\n pbPr₁ : C [ pbOb , cspn .l ]\n pbPr₂ : C [ pbOb , cspn .r ]\n pbCommutes : pbPr₁ ⋆ cspn .s₁ ≡ pbPr₂ ⋆ cspn .s₂\n univProp : isPullback cspn pbPr₁ pbPr₂ pbCommutes\n\n open Pullback\n\n pullbackArrow :\n {cspn : Cospan} (pb : Pullback cspn)\n {c : ob} (p₁ : C [ c , cspn .l ]) (p₂ : C [ c , cspn .r ])\n (H : p₁ ⋆ cspn .s₁ ≡ p₂ ⋆ cspn .s₂) → C [ c , pb . pbOb ]\n pullbackArrow pb p₁ p₂ H = pb .univProp p₁ p₂ H .fst .fst\n\n pullbackArrowPr₁ :\n {cspn : Cospan} (pb : Pullback cspn)\n {c : ob} (p₁ : C [ c , cspn .l ]) (p₂ : C [ c , cspn .r ])\n (H : p₁ ⋆ cspn .s₁ ≡ p₂ ⋆ cspn .s₂) →\n p₁ ≡ pullbackArrow pb p₁ p₂ H ⋆ pbPr₁ pb\n pullbackArrowPr₁ pb p₁ p₂ H = pb .univProp p₁ p₂ H .fst .snd .fst\n\n pullbackArrowPr₂ :\n {cspn : Cospan} (pb : Pullback cspn)\n {c : ob} (p₁ : C [ c , cspn .l ]) (p₂ : C [ c , cspn .r ])\n (H : p₁ ⋆ cspn .s₁ ≡ p₂ ⋆ cspn .s₂) →\n p₂ ≡ pullbackArrow pb p₁ p₂ H ⋆ pbPr₂ pb\n pullbackArrowPr₂ pb p₁ p₂ H = pb .univProp p₁ p₂ H .fst .snd .snd\n\n pullbackArrowUnique :\n {cspn : Cospan} (pb : Pullback cspn)\n {c : ob} (p₁ : C [ c , cspn .l ]) (p₂ : C [ c , cspn .r ])\n (H : p₁ ⋆ cspn .s₁ ≡ p₂ ⋆ cspn .s₂)\n (pbArrow' : C [ c , pb .pbOb ])\n (H₁ : p₁ ≡ pbArrow' ⋆ pbPr₁ pb) (H₂ : p₂ ≡ pbArrow' ⋆ pbPr₂ pb)\n → pullbackArrow pb p₁ p₂ H ≡ pbArrow'\n pullbackArrowUnique pb p₁ p₂ H pbArrow' H₁ H₂ =\n cong fst (pb .univProp p₁ p₂ H .snd (pbArrow' , (H₁ , H₂)))\n\n Pullbacks : Type (ℓ-max ℓ ℓ')\n Pullbacks = (cspn : Cospan) → Pullback cspn\n\n hasPullbacks : Type (ℓ-max ℓ ℓ')\n hasPullbacks = ∥ Pullbacks ∥\n\n\n-- TODO: finish the following show that this definition of Pullback\n-- is equivalent to the Cospan limit\nmodule _ {C : Category ℓ ℓ'} where\n open Category C\n open Functor\n\n Cospan→Func : Cospan C → Functor CospanCat C\n Cospan→Func (cospan l m r f g) .F-ob ⓪ = l\n Cospan→Func (cospan l m r f g) .F-ob ① = m\n Cospan→Func (cospan l m r f g) .F-ob ② = r\n Cospan→Func (cospan l m r f g) .F-hom {⓪} {①} k = f\n Cospan→Func (cospan l m r f g) .F-hom {②} {①} k = g\n Cospan→Func (cospan l m r f g) .F-hom {⓪} {⓪} k = id\n Cospan→Func (cospan l m r f g) .F-hom {①} {①} k = id\n Cospan→Func (cospan l m r f g) .F-hom {②} {②} k = id\n Cospan→Func (cospan l m r f g) .F-id {⓪} = refl\n Cospan→Func (cospan l m r f g) .F-id {①} = refl\n Cospan→Func (cospan l m r f g) .F-id {②} = refl\n Cospan→Func (cospan l m r f g) .F-seq {⓪} {⓪} {⓪} φ ψ = sym (⋆IdL _)\n Cospan→Func (cospan l m r f g) .F-seq {⓪} {⓪} {①} φ ψ = sym (⋆IdL _)\n Cospan→Func (cospan l m r f g) .F-seq {⓪} {①} {①} φ ψ = sym (⋆IdR _)\n Cospan→Func (cospan l m r f g) .F-seq {①} {①} {①} φ ψ = sym (⋆IdL _)\n Cospan→Func (cospan l m r f g) .F-seq {②} {②} {②} φ ψ = sym (⋆IdL _)\n Cospan→Func (cospan l m r f g) .F-seq {②} {②} {①} φ ψ = sym (⋆IdL _)\n Cospan→Func (cospan l m r f g) .F-seq {②} {①} {①} φ ψ = sym (⋆IdR _)\n", "meta": {"hexsha": "47c665c6711c8b3db70765c92a87f8c4f7011df9", "size": 4198, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Categories/Limits/Pullback.agda", "max_stars_repo_name": "lpw25/cubical", "max_stars_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7", "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": "Cubical/Categories/Limits/Pullback.agda", "max_issues_repo_name": "lpw25/cubical", "max_issues_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7", "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": "Cubical/Categories/Limits/Pullback.agda", "max_forks_repo_name": "lpw25/cubical", "max_forks_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7", "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.5762711864, "max_line_length": 74, "alphanum_fraction": 0.5717008099, "num_tokens": 1974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300449389326, "lm_q2_score": 0.5583269943353744, "lm_q1q2_score": 0.3922414884210497}} {"text": "open import Prelude\nopen import core\n\nmodule lemmas-consistency where\n -- type consistency is symmetric\n ~sym : {t1 t2 : htyp} → t1 ~ t2 → t2 ~ t1\n ~sym TCRefl = TCRefl\n ~sym TCHole1 = TCHole2\n ~sym TCHole2 = TCHole1\n ~sym (TCArr p1 p2) = TCArr (~sym p1) (~sym p2)\n\n -- type consistency isn't transitive\n not-trans : ((t1 t2 t3 : htyp) → t1 ~ t2 → t2 ~ t3 → t1 ~ t3) → ⊥\n not-trans t with t (b ==> b) ⦇-⦈ b TCHole1 TCHole2\n ... | ()\n\n -- every pair of types is either consistent or not consistent\n ~dec : (t1 t2 : htyp) → ((t1 ~ t2) + (t1 ~̸ t2))\n -- this takes care of all hole cases, so we don't consider them below\n ~dec _ ⦇-⦈ = Inl TCHole1\n ~dec ⦇-⦈ _ = Inl TCHole2\n -- num cases\n ~dec b b = Inl TCRefl\n ~dec b (t2 ==> t3) = Inr ICBaseArr1\n -- arrow cases\n ~dec (t1 ==> t2) b = Inr ICBaseArr2\n ~dec (t1 ==> t2) (t3 ==> t4) with ~dec t1 t3 | ~dec t2 t4\n ... | Inl x | Inl y = Inl (TCArr x y)\n ... | Inl _ | Inr y = Inr (ICArr2 y)\n ... | Inr x | _ = Inr (ICArr1 x)\n\n -- no pair of types is both consistent and not consistent\n ~apart : {t1 t2 : htyp} → (t1 ~̸ t2) → (t1 ~ t2) → ⊥\n ~apart ICBaseArr1 ()\n ~apart ICBaseArr2 ()\n ~apart (ICArr1 x) TCRefl = ~apart x TCRefl\n ~apart (ICArr1 x) (TCArr y y₁) = ~apart x y\n ~apart (ICArr2 x) TCRefl = ~apart x TCRefl\n ~apart (ICArr2 x) (TCArr y y₁) = ~apart x y₁\n", "meta": {"hexsha": "84cc732f16923d5bda0d3539e401319110f01626", "size": 1347, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lemmas-consistency.agda", "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_issues_repo_path": "lemmas-consistency.agda", "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_forks_repo_path": "lemmas-consistency.agda", "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "avg_line_length": 33.675, "max_line_length": 73, "alphanum_fraction": 0.5812917595, "num_tokens": 602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.3922225509067182}} {"text": "{-# OPTIONS --safe #-}\n\nopen import Generics.Prelude hiding (lookup)\nopen import Generics.Telescope\nopen import Generics.Desc\nopen import Generics.All\nopen import Generics.HasDesc\nimport Generics.Helpers as Helpers\n\n\nmodule Generics.Constructions.Recursion\n {P I ℓ} {A : Indexed P I ℓ}\n (H : HasDesc A) (open HasDesc H)\n {p c} (Pr : Pred′ I (λ i → A′ (p , i) → Set c))\n where\n\nprivate\n variable\n V : ExTele P\n i : ⟦ I ⟧tel p\n v : ⟦ V ⟧tel p\n\nPr′ : A′ (p , i) → Set c\nPr′ {i} = unpred′ I _ Pr i\n\nBelow : (x : A′ (p , i)) → Acc x → Setω\n\nBelowIndArg : (C : ConDesc P V I)\n (x : ⟦ C ⟧IndArg A′ (p , v))\n → AllIndArgω Acc C x\n → Setω\nBelowIndArg (var _) x = Below x\nBelowIndArg (π ai S C) x a = ∀ s → BelowIndArg C (app< ai > x s) (a s)\nBelowIndArg (A ⊗ B) (x , y) (ax , ay)\n = BelowIndArg A x ax ×ω BelowIndArg B y ay\n\nBelowCon : (C : ConDesc P V I)\n (x : ⟦ C ⟧Con A′ (p , v , i))\n → AllConω Acc C x\n → Setω\nBelowCon (var _) x _ = ⊤ω\nBelowCon (π ai S C) (s , x) = BelowCon C x\nBelowCon (A ⊗ B) (f , x) (af , ax)\n = BelowIndArg A f af\n ×ω BelowCon B x ax\n\nBelow x (acc a) with split x\n... | (k , x) = BelowCon _ x a\n\nmodule _ (f : ∀ {i} (x : A′ (p , i)) (a : Acc x) → Below x a → Pr′ x) where\n\n\n below : (x : A′ (p , i)) (a : Acc x) → Below x a\n below x (acc a) with split x\n ... | (k , x) = belowCon _ x a\n where\n belowIndArg : (C : ConDesc P V I)\n (x : ⟦ C ⟧IndArg A′ (p , v))\n (a : AllIndArgω Acc C x)\n → BelowIndArg C x a\n belowIndArg (var _) x a = below x a\n belowIndArg (π ai _ C) x a s =\n belowIndArg C (app< ai > x s) (a s)\n belowIndArg (A ⊗ B) (x , y) (ax , ay)\n = belowIndArg A x ax\n , belowIndArg B y ay\n\n belowCon : (C : ConDesc P V I)\n (x : ⟦ C ⟧Con A′ (p , v , i))\n (a : AllConω Acc C x)\n → BelowCon C x a\n belowCon (var _) _ _ = tt\n belowCon (π _ _ C) (_ , x) a = belowCon C x a\n belowCon (A ⊗ B) (f , x) (af , ax)\n = belowIndArg A f af\n , belowCon B x ax\n\n rec : (x : A′ (p , i)) → Pr′ x\n rec x = f x (wf x) (below x (wf x))\n", "meta": {"hexsha": "dda8867a10e57d458827418e642c1343e034e9c0", "size": 2200, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Generics/Constructions/Recursion.agda", "max_stars_repo_name": "flupe/generics", "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_issues_repo_path": "src/Generics/Constructions/Recursion.agda", "max_issues_repo_name": "flupe/generics", "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_forks_repo_path": "src/Generics/Constructions/Recursion.agda", "max_forks_repo_name": "flupe/generics", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "avg_line_length": 27.5, "max_line_length": 75, "alphanum_fraction": 0.5, "num_tokens": 836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506635289835, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.3922066310234704}} {"text": "open import Categories.Category\nopen import Categories.Category.CartesianClosed\n\nopen import Theory\n\nmodule Categories.Category.Construction.Models\n {ℓ₁ ℓ₂ ℓ₃}\n (Th : Theory.Theory ℓ₁ ℓ₂ ℓ₃)\n {o ℓ e}\n (𝒞 : Category o ℓ e)\n (cartesianClosed : CartesianClosed 𝒞)\n where\n\n open import Categories.Category.Cartesian 𝒞\n open import Categories.Category.BinaryProducts 𝒞\n open import Categories.Object.Terminal 𝒞\n import Categories.Object.Product 𝒞 as P\n open import Categories.Morphism 𝒞\n open import Categories.Functor.Construction.Product using (Product)\n open import Categories.Functor.Construction.Exponential using (Exp)\n open import Categories.Functor.Properties using ([_]-resp-≅)\n\n open Category 𝒞\n open CartesianClosed cartesianClosed\n open Cartesian cartesian\n open BinaryProducts products\n module T = Terminal terminal\n open HomReasoning\n open import Categories.Morphism.Reasoning 𝒞\n\n open import Syntax\n open Theory.Theory Th\n open import Semantics 𝒞 cartesianClosed Sg\n open Signature Sg\n\n open import Data.Product using (Σ; Σ-syntax; proj₁; proj₂; _,_)\n\n open import Relation.Binary using (Rel; IsEquivalence)\n\n open import Level using (_⊔_)\n\n ⁂-id : forall {A B} -> id {A = A} ⁂ id {A = B} ≈ id\n ⁂-id = Equiv.trans (⟨⟩-cong₂ identityˡ identityˡ) η\n\n module Homomorphism {M N : Model 𝒞 cartesianClosed Th}\n (h : (g : Gr) -> ⟦ g ⟧G (proj₁ M) ≅ ⟦ g ⟧G (proj₁ N))\n where\n open _≅_\n open Iso\n\n H : (A : Type) -> ⟦ A ⟧T (proj₁ M) ≅ ⟦ A ⟧T (proj₁ N)\n H ⌊ g ⌋ = h g\n H Unit = up-to-iso terminal terminal\n H (A * A₁) = [ Product 𝒞 cartesian ]-resp-≅\n (record\n { from = from (H A) , from (H A₁)\n ; to = to (H A) , to (H A₁)\n ; iso = record { isoˡ = isoˡ (iso (H A)) , isoˡ (iso (H A₁)) ; isoʳ = isoʳ (iso (H A)) , isoʳ (iso (H A₁)) }\n })\n H (A => A₁) = [ Exp 𝒞 cartesianClosed ]-resp-≅\n (record\n { from = from (H A₁) , to (H A)\n ; to = to (H A₁) , from (H A)\n ; iso = record { isoˡ = isoˡ (iso (H A₁)) , isoˡ (iso (H A)) ; isoʳ = isoʳ (iso (H A₁)) , isoʳ (iso (H A)) }\n })\n\n record homomorphism (M N : Model 𝒞 cartesianClosed Th) : Set (ℓ₁ ⊔ ℓ₂ ⊔ ℓ ⊔ e) where\n field\n h : (g : Gr) -> ⟦ g ⟧G (proj₁ M) ≅ ⟦ g ⟧G (proj₁ N)\n\n open Homomorphism {M} {N} h public\n\n field\n comm : (f : Func) -> _≅_.from (H (cod f)) ∘ ⟦ f ⟧F (proj₁ M) ≈ ⟦ f ⟧F (proj₁ N) ∘ _≅_.from (H (dom f))\n\n module _ {M N : Model 𝒞 cartesianClosed Th} where\n _≗_ : Rel (homomorphism M N) (ℓ₁ ⊔ e)\n _≗_ x y = (g : Gr) -> _≅_.from (homomorphism.h x g) ≈ _≅_.from (homomorphism.h y g)\n\n module Id {M : Model 𝒞 cartesianClosed Th} where\n open Homomorphism {M} {M} (λ _ → IsEquivalence.refl ≅-isEquivalence)\n open Structure (proj₁ M)\n\n -- The components of the homomorphism generated by identity morphisms are also identities.\n H-id : forall A -> _≅_.from (H A) ≈ Category.id 𝒞\n H-id˘ : forall A -> _≅_.to (H A) ≈ Category.id 𝒞\n\n H-id ⌊ x ⌋ = Equiv.refl\n H-id Unit = T.!-unique (Category.id 𝒞)\n H-id (A * A₁) =\n begin\n _≅_.from (H A) ⁂ _≅_.from (H A₁)\n ≈⟨ ⁂-cong₂ (H-id A) (H-id A₁) ⟩\n Category.id 𝒞 ⁂ Category.id 𝒞\n ≈⟨ ⟨⟩-cong₂ identityˡ identityˡ ⟩\n ⟨ π₁ , π₂ ⟩\n ≈⟨ η ⟩\n Category.id 𝒞\n ∎\n H-id (A => A₁) =\n begin\n λg (_≅_.from (H A₁) ∘ eval′ ∘ (id ⁂ _≅_.to (H A)))\n ≈⟨ λ-cong (∘-resp-≈ˡ (H-id A₁)) ⟩\n λg (id ∘ eval′ ∘ (id ⁂ _≅_.to (H A)))\n ≈⟨ λ-cong (pullˡ identityˡ) ⟩\n λg (eval′ ∘ (id ⁂ _≅_.to (H A)))\n ≈⟨ λ-cong (∘-resp-≈ʳ (⁂-cong₂ Equiv.refl (H-id˘ A))) ⟩\n λg (eval′ ∘ (id ⁂ id))\n ≈⟨ λ-cong (elimʳ ⁂-id) ⟩\n λg eval′\n ≈⟨ η-id′ ⟩\n id\n ∎\n\n H-id˘ ⌊ x ⌋ = Equiv.refl\n H-id˘ Unit = T.!-unique id\n H-id˘ (A * A₁) =\n begin\n _≅_.to (H A) ⁂ _≅_.to (H A₁)\n ≈⟨ ⁂-cong₂ (H-id˘ A) (H-id˘ A₁) ⟩\n id ⁂ id\n ≈⟨ ⁂-id ⟩\n id\n ∎\n H-id˘ (A => A₁) =\n begin\n λg (_≅_.to (H A₁) ∘ eval′ ∘ (id ⁂ _≅_.from (H A)))\n ≈⟨ λ-cong (elimˡ (H-id˘ A₁)) ⟩\n λg (eval′ ∘ (id ⁂ _≅_.from (H A)))\n ≈⟨ λ-cong (∘-resp-≈ʳ (⁂-cong₂ Equiv.refl (H-id A))) ⟩\n λg (eval′ ∘ (id ⁂ id))\n ≈⟨ λ-cong (elimʳ ⁂-id) ⟩\n λg eval′\n ≈⟨ η-id′ ⟩\n id\n ∎\n\n comm : (f : Func) -> _≅_.from (H (cod f)) ∘ ⟦ f ⟧F ≈ ⟦ f ⟧F ∘ _≅_.from (H (dom f))\n comm f =\n begin\n _≅_.from (H (cod f)) ∘ ⟦ f ⟧F\n ≈⟨ elimˡ (H-id (cod f)) ⟩\n ⟦ f ⟧F\n ≈˘⟨ elimʳ (H-id (dom f)) ⟩\n ⟦ f ⟧F ∘ _≅_.from (H (dom f))\n ∎\n\n id′ : homomorphism M M\n id′ = record { h = λ _ → IsEquivalence.refl ≅-isEquivalence ; comm = comm }\n\n module Compose {M N O : Model 𝒞 cartesianClosed Th} where\n open _≅_\n\n compose : homomorphism N O -> homomorphism M N -> homomorphism M O\n compose x y = record\n { h = h\n ; comm = λ f →\n begin\n from (MO.H (cod f)) ∘ ⟦ f ⟧F (proj₁ M)\n ≈⟨ pushˡ (H-compose (cod f)) ⟩\n from (NO.H (cod f)) ∘ from (MN.H (cod f)) ∘ ⟦ f ⟧F (proj₁ M)\n ≈⟨ ∘-resp-≈ʳ (MN.comm f) ⟩\n from (NO.H (cod f)) ∘ ⟦ f ⟧F (proj₁ N) ∘ from (MN.H (dom f))\n ≈⟨ pullˡ (NO.comm f) ⟩\n (⟦ f ⟧F (proj₁ O) ∘ from (NO.H (dom f))) ∘ from (MN.H (dom f))\n ≈˘⟨ pushʳ (H-compose (dom f)) ⟩\n ⟦ f ⟧F (proj₁ O) ∘ from (MO.H (dom f))\n ∎\n }\n where\n h = λ g → IsEquivalence.trans ≅-isEquivalence (homomorphism.h y g) (homomorphism.h x g)\n module MO = Homomorphism h\n module MN = homomorphism y\n module NO = homomorphism x\n\n H-compose : forall A -> from (MO.H A) ≈ from (NO.H A) ∘ from (MN.H A)\n H-compose˘ : forall A -> to (MO.H A) ≈ to (MN.H A) ∘ to (NO.H A)\n\n H-compose ⌊ x ⌋ = Equiv.refl\n H-compose Unit = T.!-unique₂\n H-compose (A * A₁) = Equiv.trans (⁂-cong₂ (H-compose A) (H-compose A₁)) (Equiv.sym ⁂∘⁂)\n H-compose (A => A₁) =\n begin\n λg (from (MO.H A₁) ∘ eval′ ∘ (id ⁂ to (MO.H A)))\n ≈⟨ λ-cong (∘-resp-≈ˡ (H-compose A₁)) ⟩\n λg ((from (NO.H A₁) ∘ from (MN.H A₁)) ∘ eval′ ∘ (id ⁂ to (MO.H A)))\n ≈⟨ λ-cong assoc ⟩\n λg (from (NO.H A₁) ∘ from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MO.H A)))\n ≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ Equiv.refl (H-compose˘ A))))) ⟩\n λg (from (NO.H A₁) ∘ from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A) ∘ to (NO.H A)))\n ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (∘-resp-≈ʳ second∘second))) ⟩\n λg (from (NO.H A₁) ∘ from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A)) ∘ (id ⁂ to (NO.H A)))\n ≈˘⟨ λ-cong (∘-resp-≈ʳ assoc²') ⟩\n λg (from (NO.H A₁) ∘ (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ∘ (id ⁂ to (NO.H A)))\n ≈˘⟨ λ-cong (∘-resp-≈ʳ (pullˡ β′)) ⟩\n λg (from (NO.H A₁) ∘ eval′ ∘ (λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ⁂ id) ∘ (id ⁂ to (NO.H A)))\n ≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ ⁂∘⁂)) ⟩\n λg (from (NO.H A₁) ∘ eval′ ∘ (λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ∘ id ⁂ id ∘ to (NO.H A)))\n ≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ identityʳ identityˡ))) ⟩\n λg (from (NO.H A₁) ∘ eval′ ∘ (λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ⁂ to (NO.H A)))\n ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ identityˡ identityʳ))) ⟩\n λg (from (NO.H A₁) ∘ eval′ ∘ (id ∘ λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ⁂ to (NO.H A) ∘ id))\n ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ ⁂∘⁂)) ⟩\n λg (from (NO.H A₁) ∘ eval′ ∘ (id ⁂ to (NO.H A)) ∘ (λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ⁂ id))\n ≈˘⟨ λ-cong assoc²' ⟩\n λg ((from (NO.H A₁) ∘ eval′ ∘ (id ⁂ to (NO.H A))) ∘ (λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ⁂ id))\n ≈˘⟨ CartesianClosed.exp.subst cartesianClosed product product ⟩\n λg (from (NO.H A₁) ∘ eval′ ∘ (id ⁂ to (NO.H A))) ∘ λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A)))\n ≈⟨ Equiv.refl ⟩\n from (NO.H (A => A₁)) ∘ from (MN.H (A => A₁))\n ∎\n\n H-compose˘ ⌊ x ⌋ = Equiv.refl\n H-compose˘ Unit = T.!-unique₂\n H-compose˘ (A * A₁) = Equiv.trans (⁂-cong₂ (H-compose˘ A) (H-compose˘ A₁)) (Equiv.sym ⁂∘⁂)\n H-compose˘ (A => A₁) =\n begin\n λg (to (MO.H A₁) ∘ eval′ ∘ (id ⁂ from (MO.H A)))\n ≈⟨ λ-cong (∘-resp-≈ˡ (H-compose˘ A₁)) ⟩\n λg ((to (MN.H A₁) ∘ to (NO.H A₁)) ∘ eval′ ∘ (id ⁂ from (MO.H A)))\n ≈⟨ λ-cong assoc ⟩\n λg (to (MN.H A₁) ∘ to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (MO.H A)))\n ≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ Equiv.refl (H-compose A))))) ⟩\n λg (to (MN.H A₁) ∘ to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A) ∘ from (MN.H A)))\n ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (∘-resp-≈ʳ second∘second))) ⟩\n λg (to (MN.H A₁) ∘ to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A)) ∘ (id ⁂ from (MN.H A)))\n ≈˘⟨ λ-cong (∘-resp-≈ʳ assoc²') ⟩\n λg (to (MN.H A₁) ∘ (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ∘ (id ⁂ from (MN.H A)))\n ≈˘⟨ λ-cong (∘-resp-≈ʳ (pullˡ β′)) ⟩\n λg (to (MN.H A₁) ∘ eval′ ∘ (λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ⁂ id) ∘ (id ⁂ from (MN.H A)))\n ≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ ⁂∘⁂)) ⟩\n λg (to (MN.H A₁) ∘ eval′ ∘ (λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ∘ id ⁂ id ∘ from (MN.H A)))\n ≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ identityʳ identityˡ))) ⟩\n λg (to (MN.H A₁) ∘ eval′ ∘ (λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ⁂ from (MN.H A)))\n ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ identityˡ identityʳ))) ⟩\n λg (to (MN.H A₁) ∘ eval′ ∘ (id ∘ λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ⁂ from (MN.H A) ∘ id))\n ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ ⁂∘⁂)) ⟩\n λg (to (MN.H A₁) ∘ eval′ ∘ (id ⁂ from (MN.H A)) ∘ (λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ⁂ id))\n ≈˘⟨ λ-cong assoc²' ⟩\n λg ((to (MN.H A₁) ∘ eval′ ∘ (id ⁂ from (MN.H A))) ∘ (λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ⁂ id))\n ≈˘⟨ CartesianClosed.exp.subst cartesianClosed product product ⟩\n λg (to (MN.H A₁) ∘ eval′ ∘ (id ⁂ from (MN.H A))) ∘ λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A)))\n ≈⟨ Equiv.refl ⟩\n to (MN.H (A => A₁)) ∘ to (NO.H (A => A₁))\n ∎\n\n Models : Category (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃ ⊔ o ⊔ ℓ ⊔ e) (ℓ₁ ⊔ ℓ₂ ⊔ ℓ ⊔ e) (ℓ₁ ⊔ e)\n Models = record\n { Obj = Model 𝒞 cartesianClosed Th\n ; _⇒_ = homomorphism\n ; _≈_ = _≗_\n ; id = Id.id′\n ; _∘_ = Compose.compose\n ; assoc = λ _ → assoc\n ; sym-assoc = λ _ → sym-assoc\n ; identityˡ = λ _ → identityˡ\n ; identityʳ = λ _ → identityʳ\n ; identity² = λ _ → identity²\n ; equiv = record { refl = λ _ → IsEquivalence.refl equiv ; sym = λ x g → IsEquivalence.sym equiv (x g) ; trans = λ x x₁ g → IsEquivalence.trans equiv (x g) (x₁ g) }\n ; ∘-resp-≈ = λ x x₁ g → ∘-resp-≈ (x g) (x₁ g)\n }\n", "meta": {"hexsha": "66a4425c53c4dd5895f1a908ecfe0e1d900b44e4", "size": 11122, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Categories/Category/Construction/Models.agda", "max_stars_repo_name": "elpinal/exsub-ccc", "max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z", "max_issues_repo_path": "Categories/Category/Construction/Models.agda", "max_issues_repo_name": "elpinal/exsub-ccc", "max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9", "max_issues_repo_licenses": ["Apache-2.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": "Categories/Category/Construction/Models.agda", "max_forks_repo_name": "elpinal/exsub-ccc", "max_forks_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.4503816794, "max_line_length": 177, "alphanum_fraction": 0.4759036145, "num_tokens": 5000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7606506635289835, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.3922066310234704}} {"text": "{-# OPTIONS --without-K #-}\nmodule LeftCancellation where\n\nopen import Data.Empty\nopen import Data.Unit\nopen import Data.Sum\nopen import Data.Product using (_,_; _,′_; proj₁; proj₂)\nopen import Function renaming (_∘_ to _○_)\n\n-- explicit 'using', to show how little of HoTT is needed\nopen import SimpleHoTT using (refl; ap; _∘_; !; _≡_; _≡⟨_⟩_ ; _∎) \nopen import Equivalences\nopen import TypeEquivalences using (swap₊)\nopen import Inspect\n\n----------------------------------------------------------------------------\n-- Very complex proof that we can cancel units on the left of ⊎\n\n-- Some repeated patterns:\n-- use injectivity of equivalences to go from f x ≡ f y to x ≡ y\ninjectivity : {A B : Set} (equiv : (⊤ ⊎ A) ≃ (⊤ ⊎ B)) → (a : A) → equiv ⋆ inj₁ tt ≡ equiv ⋆ inj₂ a → (inj₁ tt ≡ inj₂ a) \ninjectivity equiv x path = inj≃ equiv (inj₁ tt) (inj₂ x) path\n\n-- Use that disjoint unions are, well, disjoint, to derive a contradiction\nbad-path : {A : Set} → (x : A) → inj₁ tt ≡ inj₂ x → ⊥\nbad-path x path = proj₁ (thm2-12-5 tt (inj₂ x)) path\n\nleft-cancel-⊤ : {A B : Set} → ((⊤ ⊎ A) ≃ (⊤ ⊎ B)) → A ≃ B\nleft-cancel-⊤ {A} {B} (f₁ , mkisequiv g₁ α₁ h₁ β₁) with f₁ (inj₁ tt) | inspect f₁ (inj₁ tt) | g₁ (inj₁ tt) | inspect g₁ (inj₁ tt)\nleft-cancel-⊤ {A} {B} (f₁ , mkisequiv g₁ α₁ h₁ β₁) | inj₁ tt | ⟪ eq₁ ⟫ | inj₁ tt | ⟪ eq₂ ⟫ = f , equiv₁ (mkqinv g α β)\n where equiv = (f₁ , mkisequiv g₁ α₁ h₁ β₁)\n f : A → B\n f a with f₁ (inj₂ a) | inspect f₁ (inj₂ a)\n f a | inj₂ b | _ = b\n f a | inj₁ tt | ⟪ eq ⟫ with bad-path a inject\n where inject = injectivity equiv a (eq₁ ∘ ! eq)\n f a | inj₁ tt | ⟪ eq ⟫ | ()\n g : B → A\n g b with g₁ (inj₂ b) | inspect g₁ (inj₂ b)\n g b | inj₂ a | _ = a\n g b | inj₁ tt | ⟪ eq ⟫ with bad-path b inject\n where inject = injectivity (sym≃ equiv) b (eq₂ ∘ ! eq) \n g b | inj₁ tt | ⟪ eq ⟫ | () \n α : f ○ g ∼ id\n α b with g₁ (inj₂ b) | inspect g₁ (inj₂ b)\n α b | inj₁ tt | ⟪ eq ⟫ with bad-path b inject \n where inject = injectivity (sym≃ equiv) b (eq₂ ∘ ! eq) \n α b | inj₁ tt | ⟪ eq ⟫ | ()\n α b | inj₂ a | ⟪ eq ⟫ with f₁ (inj₂ a) | inspect f₁ (inj₂ a) \n α b | inj₂ a | ⟪ eq ⟫ | inj₁ tt | ⟪ eq₃ ⟫ with bad-path a inject\n where inject = injectivity equiv a (eq₁ ∘ ! eq₃)\n α b | inj₂ a | ⟪ eq ⟫ | inj₁ tt | ⟪ eq₃ ⟫ | ()\n α b | inj₂ a | ⟪ eq ⟫ | inj₂ b′ | ⟪ eq₃ ⟫ = \n proj₁ (inj₁₁path b′ b) (ap swap₊ (! (ap f₁ eq ∘ eq₃) ∘ α₁ (inj₂ b)))\n β : g ○ f ∼ id\n β a with f₁ (inj₂ a) | inspect f₁ (inj₂ a) \n β a | inj₁ tt | ⟪ eq ⟫ with bad-path a inject\n where inject = injectivity equiv a (! (eq ∘ ! eq₁))\n ... | ()\n β a | inj₂ b | ⟪ eq ⟫ with g₁ (inj₂ b) | inspect g₁ (inj₂ b)\n ... | inj₁ tt | ⟪ eq₃ ⟫ with bad-path a inject\n where inject = injectivity equiv a (! (ap f₁ eq₃) ∘ (α₁ (inj₂ b)) ∘ ! eq)\n β a | inj₂ b | ⟪ eq ⟫ | inj₁ tt | ⟪ eq₃ ⟫ | ()\n β a | inj₂ b | ⟪ eq ⟫ | inj₂ a′ | ⟪ eq₃ ⟫ = proj₁ (inj₁₁path a′ a) (ap swap₊ ((! eq₃) ∘ ap g₁ (! eq) ∘ β₂ (inj₂ a)))\n where module EQ = qinv (equiv₂ {f = f₁} (proj₂ equiv))\n β₂ = EQ.β\n\nleft-cancel-⊤ (f₁ , mkisequiv g α h β) | inj₁ tt | ⟪ eq₁ ⟫ | inj₂ a | ⟪ eq₂ ⟫ with bad-path a inject\n where equiv = (f₁ , mkisequiv g α h β)\n inject = injectivity equiv a (eq₁ ∘ ! (α (inj₁ tt)) ∘ (ap f₁ eq₂))\nleft-cancel-⊤ (f₁ , mkisequiv g α h β) | inj₁ tt | ⟪ eq₁ ⟫ | inj₂ a | ⟪ eq₂ ⟫ | ()\n\nleft-cancel-⊤ (f₁ , mkisequiv g α h β) | inj₂ b | ⟪ eq₁ ⟫ | inj₁ tt | ⟪ eq₂ ⟫ with bad-path b (! (α (inj₁ tt)) ∘ (ap f₁ eq₂) ∘ eq₁ )\n... | ()\nleft-cancel-⊤ {A} {B} (f₁ , mkisequiv g₁ α₁ h₁ β₁) | inj₂ b₁ | ⟪ eq₁ ⟫ | inj₂ a₁ | ⟪ eq₂ ⟫ = f , equiv₁ (mkqinv g α β)\n where equiv = (f₁ ,′ mkisequiv g₁ α₁ h₁ β₁)\n module EQ = qinv (equiv₂ {f = f₁} (proj₂ equiv))\n β₂ = EQ.β\n f : A → B\n f a with f₁ (inj₂ a)\n f a | inj₂ b′ = b′\n f a | inj₁ tt = b₁\n g : B → A\n g b with g₁ (inj₂ b)\n g b | inj₂ a′ = a′\n g b | inj₁ tt = a₁\n α : f ○ g ∼ id\n α b with g₁ (inj₂ b) | inspect g₁ (inj₂ b)\n ... | inj₂ a′ | ⟪ eq ⟫ with f₁ (inj₂ a′) | inspect f₁ (inj₂ a′)\n ... | inj₂ b′ | ⟪ eq₃ ⟫ = ! (proj₁ (inj₁₁path b b′) (ap swap₊ (! (α₁ (inj₂ b)) ∘ ap f₁ eq ∘ eq₃)))\n ... | inj₁ tt | ⟪ eq₃ ⟫ with bad-path b (! (! (α₁ (inj₂ b)) ∘ (ap f₁ eq) ∘ eq₃))\n α b | inj₂ a′ | ⟪ eq ⟫ | inj₁ tt | ⟪ eq₃ ⟫ | ()\n α b | inj₁ tt | ⟪ eq ⟫ with f₁ (inj₂ a₁) | inspect f₁ (inj₂ a₁)\n α b | inj₁ tt | ⟪ eq ⟫ | inj₁ tt | ⟪ eq₃ ⟫ = proj₁ (inj₁₁path b₁ b) (ap swap₊ (!(! (α₁ (inj₂ b)) ∘ ap f₁ eq ∘ eq₁)))\n α b | inj₁ tt | ⟪ eq ⟫ | inj₂ b′ | ⟪ eq₃ ⟫ with bad-path b′ (! (α₁ (inj₁ tt)) ∘ ap f₁ eq₂ ∘ eq₃)\n ... | ()\n β : g ○ f ∼ id\n β a with f₁ (inj₂ a) | inspect f₁ (inj₂ a)\n β a | inj₁ tt | ⟪ eq ⟫ with g₁ (inj₂ b₁) | inspect g₁ (inj₂ b₁)\n ... | inj₁ tt | ⟪ eq₃ ⟫ = proj₁ (inj₁₁path a₁ a) (ap swap₊ (! eq₂ ∘ ! (ap g₁ eq) ∘ β₂ (inj₂ a)))\n β a | inj₁ tt | ⟪ eq ⟫ | inj₂ a′ | ⟪ eq₃ ⟫ with bad-path a′ ((! (β₂ (inj₁ tt)) ∘ ap g₁ eq₁) ∘ eq₃)\n ... | () \n β a | inj₂ b | ⟪ eq ⟫ with g₁ (inj₂ b) | inspect g₁ (inj₂ b)\n β a | inj₂ b | ⟪ eq₃ ⟫ | inj₁ tt | ⟪ eq ⟫ with bad-path a (! eq ∘ ap g₁ (! eq₃) ∘ β₂ (inj₂ a))\n ... | ()\n β a | inj₂ b | ⟪ eq₃ ⟫ | inj₂ a′ | ⟪ eq ⟫ = proj₁ (inj₁₁path a′ a) (ap swap₊ (! eq ∘ ap g₁ (! eq₃) ∘ β₂ (inj₂ a)))\n\n", "meta": {"hexsha": "6f765490d640fb73cbdd414c2858748daff576d7", "size": 5519, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Univalence/OldUnivalence/LeftCancellation.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "Univalence/OldUnivalence/LeftCancellation.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "Univalence/OldUnivalence/LeftCancellation.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 51.1018518519, "max_line_length": 132, "alphanum_fraction": 0.4906685994, "num_tokens": 2356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7606506418255927, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.3922066198327699}} {"text": "module PredicateLifting where\n\nimport Level\nopen import Data.Empty\nopen import Data.Unit as Unit\nopen import Data.Nat\nopen import Data.List as List renaming ([] to Ø; [_] to [_]L)\nopen import NonEmptyList as NList\nopen import Data.Fin hiding (_+_)\nopen import Data.Vec as Vec renaming ([_] to [_]V; _++_ to _++V_)\nopen import Data.Product as Prod\nopen import Function\n\nopen import Relation.Binary.PropositionalEquality as PE hiding ([_])\nopen import Relation.Binary\nopen ≡-Reasoning\n\nopen import Common.Context as Context\n\nopen import Algebra\nopen Monoid {{ ... }} hiding (refl)\n\nopen import SyntaxRaw\nopen import Syntax\n\n-- | Extend the parameter context of each type variable in the given\n-- type context by one extra variable. We need this to specify the new\n-- type variable context, in which the predicate lifting of a type lives.\n-- See predL below for the correspond typing rule.\nliftTyCtx : ∀ {Θ} → TyCtxMorP Ø Θ → TyCtx\nliftTyCtx {Ø} f = Ø\nliftTyCtx {Γ ∷ Θ} (A , f) = (∗ ∷ Γ) ∷ liftTyCtx f\n\n-- | Extend a parameter context by a variable of the given type.\nextTyVarParams : (Γ₂ : RawCtx) → PreType Ø Ø Γ₂ → RawCtx\nextTyVarParams Γ₂ A = ∗ ∷ Γ₂\n\n-- | Get the Yᵢ : (Γᵢ, xᵢ : Bᵢ) ⊸ ∗ corresponding to Xᵢ : Γᵢ ⊸ ∗ in\n-- the lifted context, c.f. the typing rule for predL below.\nliftTyVar : ∀{Θ Γ₂} → (f : TyCtxMorP Ø Θ) (X : TyVar Θ Γ₂) →\n TyVar (liftTyCtx f) (extTyVarParams Γ₂ (getTy f X))\nliftTyVar f zero = zero\nliftTyVar (A , f) (succ Γ X) =\n succ (extTyVarParams Γ (getTy f X)) (liftTyVar f X)\n\n-- | Turn an instantiation into a substitution.\ninstToSubst : ∀{Γ₁} (A : U) (Γ₂ : RawCtx) → PreTerm Γ₁ Ø →\n CtxMorP (∗ ∷ Γ₂ ++ Γ₁) (∗ ∷ (Γ₂ ↑ A) ++ Γ₁)\ninstToSubst {Γ₁} A Γ₂ t =\n let f = weakenPO' (∗ ∷ Γ₂) t ∷ ctxProjP Γ₁ (∗ ∷ Γ₂)\n in subst (CtxMorP (∗ ∷ Γ₂ ++ Γ₁))\n (PE.sym (cong (_∷_ ∗ ) (assoc Γ₂ (A ∷ Ø) Γ₁)))\n (extendProj (∗ ∷ Γ₂) Ø f)\n\n-- | Auxiliary function to define predL below.\npredL₀ : ∀ {Θ Γ₁ Γ₂} →\n (A : Raw Θ Γ₁ Γ₂) → DecentType A → (f : TyCtxMorP Ø Θ) →\n liftTyCtx f ∣ ∗ ∷ Γ₂ ++ Γ₁ / Ø ⊸Ty\npredL₀ ._ (DT-⊤ Θ Γ) f =\n ⊤-PT (liftTyCtx f) (∗ ∷ Ø ++ Γ)\npredL₀ ._ (DT-tyVar Γ₁ X) f =\n tyVarPT _ (liftTyVar f X) §ₜ ctxProjP' Ø _ Γ₁\npredL₀ ._ (DT-inst {Γ₂ = Γ₂} B t B-dec t-dec) f =\n let B' = predL₀ B B-dec f\n in substPT B' (instToSubst _ Γ₂ (mkPreTerm t-dec))\npredL₀ ._ (DT-paramAbstr {Γ₂ = Γ₂} {B = B} Γ₁ A-dec) f =\n subst (λ u → PreType (liftTyCtx f) u Ø)\n (cong (_∷_ ∗) (PE.sym (assoc Γ₂ (B ∷ Ø) Γ₁)))\n (predL₀ _ A-dec f)\npredL₀ {Θ} {.Γ₁} {Γ₂} ._ (DT-fp Γ₁ ρ D p) f =\n fpPT (∗ ∷ Γ₂ ++ Γ₁) ρ (mkD' D p 0) §ₜ f'\n where\n f' : CtxMorP (∗ ∷ Γ₂ ++ Γ₁) (∗ ∷ Γ₂)\n f' = extendP ∗ (ctxProjP' Ø Γ₂ Γ₁)\n\n mkD' : (D : FpData Raw Θ Γ₂) → DecentFpData D → ℕ →\n FpDataP (liftTyCtx f) (∗ ∷ Γ₂)\n mkD' [ Γ , g , A ] (g-dec , A-dec) k =\n let A' = predL₀ A A-dec (substTy (fpPT Ø ρ (mkFpDataP {D = D} p)) f , f)\n in\n [ ( (∗ ∷ Γ)\n , (α (∗ ∷ Γ) Γ ∗ k §ₘ ctxidP (∗ ∷ Γ))\n ∷ (mkCtxMorP {Γ} {Γ₂} {g} g-dec • ctxProjP Γ (∗ ∷ Ø))\n , A' ) ]\n mkD' ((Γ , g , A) ∷ D₁) ((g-dec , A-dec) , q) k =\n let A' = predL₀ A A-dec (substTy (fpPT Ø ρ (mkFpDataP {D = D} p)) f , f)\n in ( ∗ ∷ Γ\n , (α (∗ ∷ Γ) Γ ∗ k §ₘ ctxidP (∗ ∷ Γ))\n ∷ (mkCtxMorP {Γ} {Γ₂} {g} g-dec • ctxProjP Γ (∗ ∷ Ø))\n , A' )\n ∷ mkD' D₁ q (suc k)\n\n-- | Lift an open type A to predicates. More specifically, predL\n-- implements the following rule, in which we write Ā for predL A.\n-- X₁ : Δ₁ ⊸ Ty, ..., Xₙ : Δₙ ⊸ Ty | Γ₁ ⊢ A : Γ₂ ⊸ Ty\n-- B₁ : Δ₁ ⊸ Ty\n-- ...\n-- Bₙ : Δ₁ ⊸ Ty\n-- ================================================================= (predL)\n-- Y₁ : (Δ₁, x₁ : B₁ ⊙ id) ⊸ Ty, ..., (Yₙ : Δₙ, xₙ : Bₙ ⊙ id) ⊸ Ty\n-- | Γ₁, Γ₂, z : A[B₁/X₁, ..., Bₙ/Xₙ] ⊙ id\n-- ⊢ Ā : Ty\npredL : ∀ {Θ Γ₁ Γ₂} →\n PreType Θ Γ₁ Γ₂ →\n (f : TyCtxMorP Ø Θ) →\n-- ===========================================================\n liftTyCtx f ∣ ∗ ∷ Γ₂ ++ Γ₁ / Ø ⊸Ty\npredL (A , A-dec) = predL₀ A A-dec\n\n-- | Special instance of the predicate lifting for types with one\n-- free variable and no parameters.\n-- X : Δ ⊸ Ty | Γ ⊢ A : Ty B : Δ ⊸ Ty\n-- =============================================================== (predL₁)\n-- Y : (Δ, x : B ⊙ id) ⊸ ∗ | Γ, z : A[B/X] ⊢ Ā : Ty\npredL₁ : ∀ {Δ Γ} →\n ((Δ ∷ Ø) ∣ Γ / Ø ⊸Ty) → (Ø ∣ Ø / Δ ⊸Ty) →\n-- ===========================================================\n ((∗ ∷ Δ) ∷ Ø) ∣ ∗ ∷ Γ / Ø ⊸Ty\npredL₁ A B = predL A (B , tt)\n", "meta": {"hexsha": "4efca6a30c542ca6d9e849822196401523d9c25f", "size": 4657, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Syntax/PredicateLifting.agda", "max_stars_repo_name": "StillerHarpo/CoindDepTypes", "max_stars_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-27T14:45:11.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-06T02:10:49.000Z", "max_issues_repo_path": "Syntax/PredicateLifting.agda", "max_issues_repo_name": "StillerHarpo/CoindDepTypes", "max_issues_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-24T12:53:30.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-24T12:53:30.000Z", "max_forks_repo_path": "Syntax/PredicateLifting.agda", "max_forks_repo_name": "StillerHarpo/CoindDepTypes", "max_forks_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-24T10:54:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-24T10:54:38.000Z", "avg_line_length": 38.8083333333, "max_line_length": 78, "alphanum_fraction": 0.5020399399, "num_tokens": 1854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321964553657, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.3921602933396667}} {"text": "\npostulate\n A : Set\n\nworks : Set\nworks = let B : {X : Set} → Set\n B = let _ = Set in A\n in A\n\nfails : Set\nfails = let B : {X : Set} → Set\n B = A -- Set !=< {X : Set} → Set\n in A\n", "meta": {"hexsha": "bc2e081bca9d14c6ee67095a8484c60b64a5d52c", "size": 217, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue4131.agda", "max_stars_repo_name": "cagix/agda", "max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_stars_repo_licenses": ["BSD-2-Clause"], "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/Succeed/Issue4131.agda", "max_issues_repo_name": "cagix/agda", "max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_issues_repo_licenses": ["BSD-2-Clause"], "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/Succeed/Issue4131.agda", "max_forks_repo_name": "cagix/agda", "max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_forks_repo_licenses": ["BSD-2-Clause"], "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": 15.5, "max_line_length": 46, "alphanum_fraction": 0.4147465438, "num_tokens": 78, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.39216028661321656}} {"text": "----------------------------------------------------------------------\n-- Functional big-step evaluation of terms in the partiality monad\n----------------------------------------------------------------------\n\nmodule SystemF.Eval where\n\nopen import Codata.Musical.Notation\nopen import Category.Monad\nopen import Category.Monad.Partiality.All as All using (All; now; later)\nopen import Data.Fin using (Fin; zero; suc)\nopen import Data.Maybe as Maybe using (just; nothing)\nopen import Data.Maybe.Relation.Unary.Any as MaybeAny using (just)\nopen import Data.Nat using (_+_)\nopen import Data.Vec using ([])\nopen import Function\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\nopen import Relation.Nullary\n\nopen import PartialityAndFailure as PF hiding (fail)\nopen PF.Equality hiding (fail)\nopen PF.Equivalence\nprivate module M {f} = RawMonad (PF.monad {f})\n\nopen import SystemF.Type\nopen import SystemF.Term\nopen import SystemF.WtTerm\n\nopen TypeSubst using () renaming (_[/_] to _[/tp_])\nopen TermTypeSubst using () renaming (_[/_] to _[/tmTp_])\nopen TermTermSubst using () renaming (_[/_] to _[/tmTm_])\nopen WtTermTypeSubst using () renaming (_[/_]′ to _[/⊢tmTp_])\nopen WtTermTermSubst using () renaming (_[/_] to _[/⊢tmTm_])\n\n----------------------------------------------------------------------\n-- Functional call-by-value big-step semantics\n\n-- The functional presentation of the big-step semantics below is\n-- heavily inspired by Danielsson's ICFP'12 paper \"Operational\n-- Semantics Using the Partiality Monad\". While the paper describes a\n-- closure-based semantics, the semantics given below is\n-- substitution-based. This simplifies the evaluation of recursive\n-- terms, i.e those involving fixpoint combinators, which would\n-- otherwise have to be evaluated in a cyclic evironment, i.e. one\n-- already containing the value of the recursive term being evaluated.\n--\n-- NB: while it is not described in detail in the paper, Danielsson\n-- actually provides an alternative, substitution-based implementation\n-- in the accompanying code, which can be found at\n--\n-- http://www.cse.chalmers.se/~nad/publications/danielsson-semantics-partiality-monad.tgz\n--\n-- As pointed out in Danielsson's paper, the functional presentation\n-- of the big-step semantics feels rather natural in that it follows\n-- the form of an interpreter, and it has the added advantage of\n-- proving that the semantics are deterministic and computable \"for\n-- free\".\n--\n-- For more information about Danielson's paper see\n--\n-- http://www.cse.chalmers.se/~nad/publications/danielsson-semantics-partiality-monad.html\n\n\n----------------------------------------------------------------------\n-- Semantic domain and evaluation\n\n-- Computations with potential failure and partiality effects.\nComp : ∀ m n → Set\nComp m n = (Val m n) ?⊥\n\n-- Following Danielsson's approach, we formulate the evaluation\n-- function _⇓′ in an \"embedded language\" to work around the\n-- limitations of Agda's guarded coinduction. The function _⇓′\n-- returns \"programs\", i.e. instances of the type _?⊥P which\n-- internalizes the monadic bind operation as a constructor. In a\n-- second step, these programs are interpreted in the\n-- partiality-and-failure monad by the function _⇓.\n--\n-- For details about this technique, see e.g. Danielsson's PAR'10\n-- paper \"Beating the Productivity Checker Using Embedded Languages\".\n--\n-- SystemF.Eval.NoWorkarounds contains an alternative version of the\n-- semantics which does not use the above-mentioned workaround. The\n-- alternative definition, while (provably) equivalent to the one\n-- given below, is more verbose and arguably less readable. However\n-- the associated type soundness proof is simpler in that it requires\n-- no additional compositionality lemmas.\nmodule _ where\n open PF.Workaround\n\n -- Computation \"programs\".\n CompP : ∀ m n → Set₁\n CompP m n = (Val m n) ?⊥P\n\n mutual\n\n infix 7 _⇓′ _[_]′ _·′_\n\n -- Evaluation of untyped (open) terms in _?⊥P.\n _⇓′ : ∀ {m n} → Term m n → CompP m n\n var x ⇓′ = fail\n Λ t ⇓′ = return (Λ t)\n λ' a t ⇓′ = return (λ' a t)\n μ a t ⇓′ = later (♯ (t [/tmTm μ a t ] ⇓′))\n (t [ a ]) ⇓′ = t ⇓′ >>= λ v → v [ a ]′\n (s · t) ⇓′ = s ⇓′ >>= λ f → t ⇓′ >>= λ v → f ·′ v\n fold a t ⇓′ = t ⇓′ >>= λ v → return (fold a v)\n unfold a t ⇓′ = t ⇓′ >>= λ v → unfold′ a v\n\n -- Call-by-value evaluation of type application in _?⊥P.\n _[_]′ : ∀ {m n} → Val m n → Type n → CompP m n\n (Λ t) [ a ]′ = later (♯ (t [/tmTp a ] ⇓′))\n _ [ _ ]′ = fail\n\n -- Call-by-value Evaluation of term application in _?⊥P.\n _·′_ : ∀ {m n} → Val m n → Val m n → CompP m n\n (λ' _ t) ·′ v = later (♯ (t [/tmTm ⌜ v ⌝ ] ⇓′))\n _ ·′ _ = fail\n\n -- Evaluation of recursive type unfolding in _?⊥P.\n unfold′ : ∀ {m n} → Type (1 + n) → Val m n → CompP m n\n unfold′ _ (fold _ v) = return v\n unfold′ a _ = fail\n\n infix 7 _⇓\n\n -- Evaluation of untyped (open) terms in the partiality monad.\n _⇓ : ∀ {m n} → Term m n → Comp m n\n t ⇓ = ⟦ t ⇓′ ⟧P\n\n\n----------------------------------------------------------------------\n-- The semantics _⇓ is compositional\n\nmodule _ where\n open M\n open PF.Reasoning\n open PF.Workaround using (⟦_⟧P) renaming (_>>=_ to _>>=P_)\n open PF.Workaround.Correct\n\n infix 7 _[_]⇓ _·⇓_\n\n -- Short hands for relating the semantics of composite terms to the\n -- semantics of their subterms.\n\n _[_]⇓ : ∀ {m n} → Comp m n → Type n → Comp m n\n c [ a ]⇓ = c >>= λ v → ⟦ v [ a ]′ ⟧P\n\n _·⇓_ : ∀ {m n} → Comp m n → Comp m n → Comp m n\n c ·⇓ d = c >>= λ f → d >>= λ v → ⟦ f ·′ v ⟧P\n\n fold⇓ : ∀ {m n} → Type (1 + n) → Comp m n → Comp m n\n fold⇓ a c = c >>= λ v → return (fold a v)\n\n unfold⇓ : ∀ {m n} → Type (1 + n) → Comp m n → Comp m n\n unfold⇓ a c = c >>= λ v → ⟦ unfold′ a v ⟧P\n\n -- The semantics of type application is compositional.\n []-comp : ∀ {m n} (t : Term m n) (a : Type n) → t [ a ] ⇓ ≅ (t ⇓) [ a ]⇓\n []-comp t a = >>=-hom (t ⇓′) _\n\n -- The semantics of term application is compositional.\n ·-comp : ∀ {m n} (s t : Term m n) → s · t ⇓ ≅ (s ⇓) ·⇓ (t ⇓)\n ·-comp s t =\n s · t ⇓\n ≅⟨ >>=-hom (s ⇓′) _ ⟩\n (s ⇓ >>= λ f → ⟦ t ⇓′ >>=P (λ v → f ·′ v) ⟧P)\n ≅⟨ (s ⇓ ∎ >>=-cong λ _ → >>=-hom (t ⇓′) _) ⟩\n (s ⇓) ·⇓ (t ⇓)\n ∎\n\n -- The semantics of recursive type folding is compositional.\n fold-comp : ∀ {m n} (a : Type (1 + n)) (t : Term m n) →\n fold a t ⇓ ≅ fold⇓ a (t ⇓)\n fold-comp a t = >>=-hom (t ⇓′) _\n\n -- The semantics of recursive type unfolding is compositional.\n unfold-comp : ∀ {m n} (a : Type (1 + n)) (t : Term m n) →\n unfold a t ⇓ ≅ unfold⇓ a (t ⇓)\n unfold-comp a t = >>=-hom (t ⇓′) _\n\n\n----------------------------------------------------------------------\n-- Type soundness\n\nopen PF using (fail)\n\ninfix 4 _⊢comp_∈_\n\n-- A computation is well-typed if it is a well-typed value or it takes\n-- a step towards a well-typed computation. Note that we exclude the\n-- case of failing well-typed computations through the use of\n-- Maybe.Any.\n_⊢comp_∈_ : ∀ {m n} → Ctx m n → Comp m n → Type n → Set\nΓ ⊢comp c ∈ a = All (MaybeAny.Any (λ v → Γ ⊢val v ∈ a)) c\n\n-- Well-typed computations do not fail.\ndoes-not-fail : ∀ {m n} {Γ : Ctx m n} {c a} → Γ ⊢comp c ∈ a → ¬ c ≈ fail\ndoes-not-fail (now (MaybeAny.just _)) (now ())\ndoes-not-fail (later ⊢c) (laterˡ c-fails) = does-not-fail (♭ ⊢c) c-fails\n\n-- It remains to prove that well-typed terms evaluate to well-typed\n-- computations. The proof ⊢_⇓ follows the same structure as _⇓ and\n-- uses an analogous workaround to deal with guarded coinduction. It\n-- is formulated in the language AllP of of Partiality.All \"programs\"\n-- defined in All.Alternative.\nopen All.Alternative\nopen PF.Workaround using (⟦_⟧P)\n\ninfix 4 ⊢compP_∈_ ⊢val_∈_\n\n-- Closed well-typed computation \"programs\".\n⊢compP_∈_ : Comp 0 0 → Type 0 → Set₁\n⊢compP c ∈ a = AllP (MaybeAny.Any (λ v → [] ⊢val v ∈ a)) c\n\n-- A short hand for closed well-typed values.\n⊢val_∈_ : Val 0 0 → Type 0 → Set\n⊢val v ∈ a = [] ⊢val v ∈ a\n\nmutual\n\n infix 7 ⊢_⇓′ ⊢_[_]′ ⊢_·′_\n\n -- Evaluation of closed terms preserves well-typedness in AllP.\n ⊢_⇓′ : ∀ {t a} → [] ⊢ t ∈ a → ⊢compP t ⇓ ∈ a\n ⊢ var () ⇓′\n ⊢ Λ ⊢t ⇓′ = now (just (Λ ⊢t))\n ⊢ λ' a ⊢t ⇓′ = now (just (λ' a ⊢t))\n ⊢ μ a ⊢t ⇓′ = later (♯ ⊢ ⊢t [/⊢tmTm μ a ⊢t ] ⇓′)\n ⊢_⇓′ {t [ a ]} (⊢t [ .a ] ) =\n t [ a ] ⇓ ≅⟨ []-comp t a ⟩P\n (t ⇓) [ a ]⇓ ⟨ ⊢ ⊢t ⇓′ >>=-congP (λ { .{_} (just ⊢v) →\n ⊢ ⊢v [ a ]′ }) ⟩P\n ⊢_⇓′ {s · t} (⊢s · ⊢t) =\n s · t ⇓ ≅⟨ ·-comp s t ⟩P\n (s ⇓) ·⇓ (t ⇓) ⟨ (⊢ ⊢s ⇓′ >>=-congP λ { .{_} (just ⊢f) →\n ⊢ ⊢t ⇓′ >>=-congP λ { .{_} (just ⊢v) →\n ⊢ ⊢f ·′ ⊢v }}) ⟩P\n ⊢_⇓′ {fold a t} (fold .a ⊢t) =\n fold a t ⇓ ≅⟨ fold-comp a t ⟩P\n fold⇓ a (t ⇓) ⟨ (⊢ ⊢t ⇓′ >>=-congP λ { .{_} (just ⊢v) →\n now (just (fold a ⊢v)) }) ⟩P\n ⊢_⇓′ {unfold a t} (unfold .a ⊢t) =\n unfold a t ⇓ ≅⟨ unfold-comp a t ⟩P\n unfold⇓ a (t ⇓) ⟨ (⊢ ⊢t ⇓′ >>=-congP λ { .{_} (just ⊢v) →\n ⊢unfold′ a ⊢v }) ⟩P\n\n -- Evaluation of type application preserves well-typedness in AllP.\n ⊢_[_]′ : ∀ {v a} → ⊢val v ∈ ∀' a → ∀ b → ⊢compP ⟦ v [ b ]′ ⟧P ∈ a [/tp b ]\n ⊢ Λ ⊢t [ a ]′ = later (♯ ⊢ ⊢t [/⊢tmTp a ] ⇓′)\n\n -- Evaluation of term application preserves well-typedness in AllP.\n ⊢_·′_ : ∀ {f v a b} → ⊢val f ∈ a →' b → ⊢val v ∈ a → ⊢compP ⟦ f ·′ v ⟧P ∈ b\n ⊢ λ' a ⊢t ·′ ⊢v = later (♯ ⊢ ⊢t [/⊢tmTm ⊢⌜ ⊢v ⌝ ] ⇓′)\n\n -- Evaluation of recursive type unfolding preserves well-typedness in AllP.\n ⊢unfold′ : ∀ {v} a → ⊢val v ∈ μ a → ⊢compP ⟦ unfold′ a v ⟧P ∈ a [/tp μ a ]\n ⊢unfold′ _ (fold ._ ⊢v) = now (just ⊢v)\n\ninfix 7 ⊢_⇓\n\n-- Evaluation of closed terms preserves well-typedness.\n⊢_⇓ : ∀ {t a} → [] ⊢ t ∈ a → [] ⊢comp t ⇓ ∈ a\n⊢_⇓ = sound ∘ ⊢_⇓′\n\n-- Type soundness: evaluation of well-typed terms does not fail.\ntype-soundness : ∀ {t a} → [] ⊢ t ∈ a → ¬ t ⇓ ≈ fail\ntype-soundness ⊢t = does-not-fail ⊢ ⊢t ⇓\n", "meta": {"hexsha": "77f9877dee4b955b7c45ff1b0d9c421eac22c50b", "size": 10061, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/SystemF/Eval.agda", "max_stars_repo_name": "sstucki/system-f-agda", "max_stars_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 68, "max_stars_repo_stars_event_min_datetime": "2015-05-26T13:12:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T01:25:16.000Z", "max_issues_repo_path": "src/SystemF/Eval.agda", "max_issues_repo_name": "sstucki/system-f-agda", "max_issues_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-30T06:43:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T19:23:26.000Z", "max_forks_repo_path": "src/SystemF/Eval.agda", "max_forks_repo_name": "sstucki/system-f-agda", "max_forks_repo_head_hexsha": "ea262cf7714cdb762643f10275c568596f57cd1d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2015-05-29T12:24:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T23:12:48.000Z", "avg_line_length": 37.5410447761, "max_line_length": 92, "alphanum_fraction": 0.5606798529, "num_tokens": 3590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.5506073655352403, "lm_q1q2_score": 0.39216028661321645}} {"text": "{-# OPTIONS --without-K --allow-unsolved-metas #-}\n\nmodule subuniverses where\n\nimport 14-univalence\nopen 14-univalence public\n\n{-\nis-local :\n {l1 l2 l3 l4 : Level}\n {I : UU l1} {A : I → UU l2} {B : I → UU l3} (f : (i : I) → A i → B i)\n (X : UU l4) → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ l4)))\nis-local {I = I} {B = B} f X =\n (i : I) → is-equiv (λ (h : B i → X) → h ∘ (f i))\n\nis-subuniverse-is-local :\n {l1 l2 l3 l4 : Level}\n {I : UU l1} {A : I → UU l2} {B : I → UU l3} (f : (i : I) → A i → B i) →\n is-subuniverse (is-local {l4 = l4} f)\nis-subuniverse-is-local f X = is-prop-Π (λ i → is-subtype-is-equiv _)\n-}\n\nuniversal-property-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2)\n (X : UU l1) (Y : total-subuniverse P) (l : X → pr1 Y) →\n UU ((lsuc l1) ⊔ l2)\nuniversal-property-localization {l1} (pair P H) X (pair Y p) l =\n (Z : UU l1) (q : P Z) → is-equiv (λ (h : Y → Z) → h ∘ l)\n\nuniversal-property-localization' :\n (l : Level) (α : Level → Level) (P : (l : Level) → subuniverse l (α l))\n (g : (l1 l2 : Level) → is-global-subuniverse α P l1 l2)\n {l1 l2 : Level} (X : UU l1) (Y : total-subuniverse (P l2)) (f : X → pr1 Y) →\n UU ((lsuc l) ⊔ ((α l) ⊔ (l1 ⊔ l2)))\nuniversal-property-localization' l α P g X Y f =\n (Z : total-subuniverse (P l)) → is-equiv (λ (h : (pr1 Y) → (pr1 Z)) → h ∘ f)\n\nis-prop-universal-property-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1)\n (Y : total-subuniverse P) (l : X → pr1 Y) →\n is-prop (universal-property-localization P X Y l)\nis-prop-universal-property-localization (pair P H) X (pair Y p) l =\n is-prop-Π (λ Z → is-prop-Π (λ q → is-subtype-is-equiv _))\n\nhas-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n UU ((lsuc l1) ⊔ l2)\nhas-localization {l1} P X =\n Σ ( total-subuniverse P)\n ( λ Y → Σ (X → pr1 Y) (universal-property-localization P X Y))\n\nEq-localizations :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n ( s t : has-localization P X) → UU l1\nEq-localizations (pair P H) X\n (pair (pair Y p) (pair l up)) t =\n let Y' = pr1 (pr1 t)\n p' = pr1 (pr1 t)\n l' = pr1 (pr2 t)\n up' = pr2 (pr2 t)\n in\n Σ ( Y ≃ Y')\n ( λ e → ((map-equiv e) ∘ l) ~ l' )\n\nreflexive-Eq-localizations :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (s : has-localization P X) → Eq-localizations P X s s\nreflexive-Eq-localizations (pair P H) X (pair (pair Y p) (pair l up)) =\n pair (equiv-id Y) (htpy-refl l)\n\nEq-localizations-eq :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n ( s t : has-localization P X) → Id s t → Eq-localizations P X s t\nEq-localizations-eq P X s s refl = reflexive-Eq-localizations P X s\n\nis-contr-total-Eq-localizations :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1)\n (s : has-localization P X) →\n is-contr (Σ (has-localization P X) (Eq-localizations P X s))\nis-contr-total-Eq-localizations\n (pair P H) X (pair (pair Y p) (pair l up)) =\n is-contr-total-Eq-structure\n ( λ Y' l' e → ((map-equiv e) ∘ l) ~ (pr1 l'))\n ( is-contr-total-Eq-total-subuniverse (pair P H) (pair Y p))\n ( pair (pair Y p) (equiv-id Y))\n ( is-contr-total-Eq-substructure\n ( is-contr-total-htpy l)\n ( is-prop-universal-property-localization (pair P H) X (pair Y p))\n ( l)\n ( htpy-refl _)\n ( up))\n\nis-equiv-Eq-localizations-eq :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n ( s t : has-localization P X) → is-equiv (Eq-localizations-eq P X s t)\nis-equiv-Eq-localizations-eq P X s =\n fundamental-theorem-id s\n ( reflexive-Eq-localizations P X s)\n ( is-contr-total-Eq-localizations P X s)\n ( Eq-localizations-eq P X s)\n\neq-Eq-localizations :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1)\n ( s t : has-localization P X) → (Eq-localizations P X s t) → Id s t\neq-Eq-localizations P X s t =\n inv-is-equiv (is-equiv-Eq-localizations-eq P X s t)\n\nuniqueness-localizations :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n ( s t : has-localization P X) → Eq-localizations P X s t\nuniqueness-localizations (pair P H) X\n (pair (pair Y p) (pair l up)) (pair (pair Y' p') (pair l' up')) =\n pair\n ( pair\n ( inv-is-equiv (up Y' p') l')\n ( is-equiv-has-inverse\n ( pair\n ( inv-is-equiv (up' Y p) l)\n ( pair\n ( htpy-eq\n ( ap\n ( pr1 {B = λ h → Id (h ∘ l') l'})\n ( center\n ( is-prop-is-contr\n ( is-contr-map-is-equiv (up' Y' p') l')\n ( pair\n ( ( inv-is-equiv (up Y' p') l') ∘\n ( inv-is-equiv (up' Y p) l))\n ( ( ap\n ( λ t → (inv-is-equiv (up Y' p') l') ∘ t)\n ( issec-inv-is-equiv (up' Y p) l)) ∙\n ( issec-inv-is-equiv (up Y' p') l')))\n ( pair id refl)))))\n ( htpy-eq\n ( ap\n ( pr1 {B = λ h → Id (h ∘ l) l})\n ( center\n ( is-prop-is-contr\n ( is-contr-map-is-equiv (up Y p) l)\n ( pair\n ( ( inv-is-equiv (up' Y p) l) ∘\n ( inv-is-equiv (up Y' p') l'))\n ( ( ap\n ( λ t → (inv-is-equiv (up' Y p) l) ∘ t)\n ( issec-inv-is-equiv (up Y' p') l')) ∙\n issec-inv-is-equiv (up' Y p) l))\n ( pair id refl)))))))))\n ( htpy-eq (issec-inv-is-equiv (up Y' p') l'))\n\nis-prop-localizations :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n is-prop (has-localization P X)\nis-prop-localizations P X =\n is-prop-is-prop'\n ( λ Y Y' → eq-Eq-localizations P X Y Y'\n ( uniqueness-localizations P X Y Y'))\n\nuniversal-property-localization-equiv-is-local :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (Y : UU l1) (p : (pr1 P) Y) (l : X → Y) →\n is-equiv l → universal-property-localization P X (pair Y p) l\nuniversal-property-localization-equiv-is-local\n (pair P H) X Y p l is-equiv-l Z q =\n is-equiv-precomp-is-equiv l is-equiv-l Z\n\nuniversal-property-localization-id-is-local :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) (q : (pr1 P) X) →\n universal-property-localization P X (pair X q) id\nuniversal-property-localization-id-is-local P X q =\n universal-property-localization-equiv-is-local P X X q id (is-equiv-id X)\n\nis-equiv-localization-is-local :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n ( Y : has-localization P X) → (pr1 P) X → is-equiv (pr1 (pr2 Y))\nis-equiv-localization-is-local\n (pair P H) X (pair (pair Y p) (pair l up)) q =\n is-equiv-right-factor\n ( id)\n ( inv-is-equiv (up X q) id)\n ( l)\n ( htpy-eq (inv (issec-inv-is-equiv (up X q) id)))\n ( pr2\n ( pr1\n ( uniqueness-localizations (pair P H) X\n ( pair (pair Y p) (pair l up))\n ( pair\n ( pair X q)\n ( pair id\n ( universal-property-localization-id-is-local\n (pair P H) X q))))))\n ( is-equiv-id X)\n\nis-local-is-equiv-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n ( Y : has-localization P X) → is-equiv (pr1 (pr2 Y)) → (pr1 P) X\nis-local-is-equiv-localization\n (pair P H) X (pair (pair Y p) (pair l up)) is-equiv-l =\n in-subuniverse-equiv' P (pair l is-equiv-l) p\n\nstrong-retraction-property-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (Y : total-subuniverse P) (l : X → pr1 Y) → UU l1\nstrong-retraction-property-localization (pair P H) X (pair Y p) l =\n is-equiv (λ (h : Y → X) → h ∘ l)\n\nretraction-property-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (Y : total-subuniverse P) (l : X → pr1 Y) → UU l1\nretraction-property-localization (pair P H) X (pair Y p) l =\n retr l\n\nstrong-retraction-property-localization-is-equiv-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (Y : total-subuniverse P) (l : X → pr1 Y) →\n is-equiv l → strong-retraction-property-localization P X Y l\nstrong-retraction-property-localization-is-equiv-localization\n (pair P H) X (pair Y p) l is-equiv-l =\n is-equiv-precomp-is-equiv l is-equiv-l X\n\nretraction-property-localization-strong-retraction-property-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (Y : total-subuniverse P) (l : X → pr1 Y) →\n strong-retraction-property-localization P X Y l →\n retraction-property-localization P X Y l\nretraction-property-localization-strong-retraction-property-localization\n (pair P H) X (pair Y p) l s =\n tot (λ h → htpy-eq) (center (is-contr-map-is-equiv s id))\n\nis-equiv-localization-retraction-property-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (Y : has-localization P X) →\n retraction-property-localization P X (pr1 Y) (pr1 (pr2 Y)) →\n is-equiv (pr1 (pr2 Y))\nis-equiv-localization-retraction-property-localization\n (pair P H) X (pair (pair Y p) (pair l up)) (pair g isretr-g) =\n is-equiv-has-inverse\n ( pair g\n ( pair\n ( htpy-eq\n ( ap\n ( pr1 {B = λ (h : Y → Y) → Id (h ∘ l) l})\n ( center\n ( is-prop-is-contr\n ( is-contr-map-is-equiv (up Y p) l)\n ( pair (l ∘ g) (ap (λ t → l ∘ t) (eq-htpy isretr-g)))\n ( pair id refl)))))\n ( isretr-g)))\n\nis-local-retraction-property-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (Y : has-localization P X) →\n retraction-property-localization P X (pr1 Y) (pr1 (pr2 Y)) →\n (pr1 P) X\nis-local-retraction-property-localization P X Y r =\n is-local-is-equiv-localization P X Y\n ( is-equiv-localization-retraction-property-localization P X Y r)\n\nis-local-has-localization-is-contr :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n is-contr X → has-localization P X → (pr1 P) X\nis-local-has-localization-is-contr\n (pair P H) X is-contr-X (pair (pair Y p) (pair l up)) =\n is-local-retraction-property-localization (pair P H) X\n ( pair (pair Y p) (pair l up))\n ( pair\n ( λ _ → center is-contr-X)\n ( contraction is-contr-X))\n\nhas-localization-is-local-is-contr :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n is-contr X → (pr1 P) X → has-localization P X\nhas-localization-is-local-is-contr (pair P H) X is-contr-X p =\n pair\n ( pair X p)\n ( pair id (universal-property-localization-id-is-local (pair P H) X p))\n\nis-contr-raise-unit :\n (l : Level) → is-contr (raise l unit)\nis-contr-raise-unit l =\n is-contr-is-equiv' unit\n ( map-raise l unit)\n ( is-equiv-map-raise l unit)\n ( is-contr-unit)\n\nis-local-unit-localization-unit :\n {l1 l2 : Level} (P : subuniverse l1 l2) →\n (Y : has-localization P (raise l1 unit)) →\n (pr1 P) (raise l1 unit)\nis-local-unit-localization-unit P Y =\n is-local-has-localization-is-contr P (raise _ unit) (is-contr-raise-unit _) Y\n\ntoto-dependent-elimination-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (has-loc-X : has-localization P X) →\n let Y = pr1 (pr1 has-loc-X)\n l = pr1 (pr2 has-loc-X)\n in\n (Z : Y → UU l1) →\n Σ (Y → Y) (λ h → (y : Y) → Z (h y)) →\n Σ (X → Y) (λ h → (x : X) → Z (h x))\ntoto-dependent-elimination-localization (pair P H) X\n (pair (pair Y p) (pair l up)) Z =\n toto\n ( λ (h : X → Y) → (x : X) → Z (h x))\n ( λ h → h ∘ l)\n ( λ h h' x → h' (l x))\n\nsquare-dependent-elimination-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (has-loc-X : has-localization P X) →\n let Y = pr1 (pr1 has-loc-X)\n l = pr1 (pr2 has-loc-X)\n in\n (Z : Y → UU l1) (q : (pr1 P) (Σ _ Z)) →\n ( ( λ (h : Y → Σ Y Z) → h ∘ l) ∘\n ( inv-choice-∞)) ~\n ( ( inv-choice-∞) ∘\n ( toto-dependent-elimination-localization P X has-loc-X Z))\nsquare-dependent-elimination-localization\n (pair P H) X (pair (pair Y p) (pair l up)) Z q =\n htpy-refl\n\nis-equiv-toto-dependent-elimination-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) (X : UU l1) →\n (has-loc-X : has-localization P X)\n (Z : pr1 (pr1 has-loc-X) → UU l1) (q : (pr1 P) (Σ _ Z)) →\n is-equiv (toto-dependent-elimination-localization P X has-loc-X Z)\nis-equiv-toto-dependent-elimination-localization\n (pair P H) X (pair (pair Y p) (pair l up)) Z q =\n is-equiv-top-is-equiv-bottom-square\n ( inv-choice-∞)\n ( inv-choice-∞)\n ( toto-dependent-elimination-localization\n (pair P H) X (pair (pair Y p) (pair l up)) Z)\n ( λ h → h ∘ l)\n ( square-dependent-elimination-localization\n (pair P H) X (pair (pair Y p) (pair l up)) Z q)\n ( is-equiv-inv-choice-∞)\n ( is-equiv-inv-choice-∞)\n ( up (Σ Y Z) q)\n\ndependent-elimination-localization :\n {l1 l2 : Level} (P : subuniverse l1 l2) →\n (X : UU l1) (Y : has-localization P X) →\n (Z : (pr1 (pr1 Y)) → UU l1) (q : (pr1 P) (Σ _ Z)) →\n is-equiv (λ (h : (y : (pr1 (pr1 Y))) → (Z y)) → λ x → h (pr1 (pr2 Y) x))\ndependent-elimination-localization (pair P H) X (pair (pair Y p) (pair l up)) Z q =\n is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map\n ( λ (h : X → Y) → (x : X) → Z (h x))\n ( λ (h : Y → Y) → h ∘ l)\n ( λ (h : Y → Y) (h' : (y : Y) → Z (h y)) (x : X) → h' (l x))\n ( up Y p)\n ( is-equiv-toto-dependent-elimination-localization\n (pair P H) X (pair (pair Y p) (pair l up)) Z q)\n ( id)\n\nis-reflective-subuniverse :\n {l1 l2 : Level} (P : subuniverse l1 l2) → UU ((lsuc l1) ⊔ l2)\nis-reflective-subuniverse {l1} P = (X : UU l1) → has-localization P X\n\nreflective-subuniverse :\n (l1 l2 : Level) → UU ((lsuc l1) ⊔ (lsuc l2))\nreflective-subuniverse l1 l2 = Σ (subuniverse l1 l2) is-reflective-subuniverse\n\nis-local :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2) →\n UU l1 → UU l2\nis-local L = pr1 (pr1 L)\n\nis-prop-is-local :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2) →\n (X : UU l1) → is-prop (is-local L X)\nis-prop-is-local L = pr2 (pr1 L)\n\ntotal-reflective-subuniverse :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2) → UU ((lsuc l1) ⊔ l2)\ntotal-reflective-subuniverse L = total-subuniverse (pr1 L)\n\nlocal-type-localization :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2)\n (X : UU l1) → total-reflective-subuniverse L\nlocal-type-localization L X = pr1 ((pr2 L) X)\n\ntype-localization :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2) →\n UU l1 → UU l1\ntype-localization L X = pr1 (local-type-localization L X)\n\nis-local-type-localization :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2)\n (X : UU l1) → is-local L (type-localization L X)\nis-local-type-localization L X = pr2 (local-type-localization L X)\n\nuniversal-map-localization :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2) (X : UU l1) →\n Σ ( X → type-localization L X)\n ( universal-property-localization (pr1 L) X (local-type-localization L X))\nuniversal-map-localization L X = pr2 ((pr2 L) X)\n\nunit-localization :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2)\n (X : UU l1) → X → type-localization L X\nunit-localization L X = pr1 (universal-map-localization L X)\n\nuniversal-property-map-localization :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2) (X : UU l1) → \n universal-property-localization (pr1 L) X\n ( local-type-localization L X)\n ( unit-localization L X)\nuniversal-property-map-localization L X = pr2 (universal-map-localization L X)\n\ndependent-elimination-reflective-subuniverse :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2) (X : UU l1) →\n (Y : type-localization L X → UU l1)\n (is-loc-total-Y : is-local L (Σ _ Y)) →\n is-equiv\n ( λ (h : (x' : type-localization L X) → Y x') x → h (unit-localization L X x))\ndependent-elimination-reflective-subuniverse L X =\n dependent-elimination-localization (pr1 L) X ((pr2 L) X)\n\nis-contr-square-localization :\n {l1 l2 : Level} (L : reflective-subuniverse l1 l2) {X Y : UU l1} (f : X → Y) →\n is-contr\n ( Σ (type-localization L X → type-localization L Y)\n ( λ Lf → coherence-square (unit-localization L X) f Lf (unit-localization L Y)))\nis-contr-square-localization L f = {!!}\n", "meta": {"hexsha": "ada21654d68355a2e75f39555392b669c1a413e0", "size": 15963, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Agda/subuniverses.agda", "max_stars_repo_name": "tmoux/HoTT-Intro", "max_stars_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29", "max_stars_repo_licenses": ["CC-BY-4.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": "Agda/subuniverses.agda", "max_issues_repo_name": "tmoux/HoTT-Intro", "max_issues_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29", "max_issues_repo_licenses": ["CC-BY-4.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": "Agda/subuniverses.agda", "max_forks_repo_name": "tmoux/HoTT-Intro", "max_forks_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.3840749415, "max_line_length": 86, "alphanum_fraction": 0.5829104805, "num_tokens": 5811, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321720225278, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.39216027988676616}} {"text": "------------------------------------------------------------------------\n-- Abstract typing contexts\n------------------------------------------------------------------------\n\n{-# OPTIONS --safe --without-K #-}\n\nmodule Data.Context where\n\nopen import Data.Fin using (Fin)\nopen import Data.Fin.Substitution\nopen import Data.Fin.Substitution.ExtraLemmas\nopen import Data.Nat using (ℕ; zero; suc; _+_)\nopen import Data.Vec as Vec using (Vec; []; _∷_)\nopen import Relation.Unary using (Pred)\n\n\n------------------------------------------------------------------------\n-- Abstract typing contexts and context extensions.\n\ninfixr 5 _∷_\n\n-- Typing contexts.\n--\n-- A |Ctx T n| is an indexed sequences of T-typed bindings mapping n\n-- variables to T-types with 0 to (n - 1) free variables each. Like\n-- lists (Data.List) and vectors (Data.Vec), contexts are cons\n-- sequences, i.e. new bindings are added to the front (rather than\n-- the back, as is more common in the literature). For example, a\n-- typing context Γ represented in the usual notation as\n--\n-- Γ = xᵢ: Aᵢ, ..., x₁: A₁, x₀: A₀\n--\n-- is represented here by a term |Γ : Ctx Type i| of the form\n--\n-- Γ = A₀ ∷ A₁ ∷ ... ∷ Aᵢ\n--\n-- which is consistent with A₀ being the 0-th element of Γ, and with\n-- the de Bruijn convention that the 0-th variable corresponds to the\n-- closest binding.\n\ndata Ctx {ℓ} (T : Pred ℕ ℓ) : ℕ → Set ℓ where\n [] : Ctx T zero\n _∷_ : ∀ {n} → T n → Ctx T n → Ctx T (suc n)\n\nmodule _ {ℓ} {T : Pred ℕ ℓ} where\n\n head : ∀ {n} → Ctx T (suc n) → T n\n head (t ∷ ts) = t\n\n tail : ∀ {n} → Ctx T (suc n) → Ctx T n\n tail (t ∷ ts) = ts\n\n -- Drop the m innermost elements of a context Γ.\n\n drop : ∀ {n} m → Ctx T (m + n) → Ctx T n\n drop zero Γ = Γ\n drop (suc m) (_ ∷ Γ) = drop m Γ\n\n-- A map function that changes the entries in a context pointwise.\n\nmap : ∀ {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} {n} →\n (∀ {k} → T₁ k → T₂ k) → Ctx T₁ n → Ctx T₂ n\nmap f [] = []\nmap f (t ∷ Γ) = f t ∷ map f Γ\n\n-- Extensions of typing contexts.\n--\n-- Context extensions are indexed sequences of bindings that can be\n-- concatenated to the front of a typing context. A |CtxExt T m n| is\n-- an extension mapping n variables to T-types with m to (n + m - 1)\n-- free variables each.\n--\n-- NOTE. It is tempting to define contexts as just a special case of\n-- context extensions, i.e. as\n--\n-- Ctx T n = CtxExt T zero n\n--\n-- But this leads to problems when defining e.g. concatenation because\n-- of the way context extensions are indexed. This could be remedied\n-- by indexing context extensions differently, but then the definition\n-- of |mapExt| below becomes difficult. An earlier version of this\n-- module contained two different (but equivalent) representations for\n-- context extensions, but this complicated (rather than simplified)\n-- the development overall.\n\ndata CtxExt {ℓ} (T : Pred ℕ ℓ) (m : ℕ) : ℕ → Set ℓ where\n [] : CtxExt T m zero\n _∷_ : ∀ {l} → T (l + m) → CtxExt T m l → CtxExt T m (suc l)\n\ninfixr 5 _++_\n\n-- Concatenation of context extensions with contexts.\n\n_++_ : ∀ {ℓ} {T : Pred ℕ ℓ} {m n} → CtxExt T m n → Ctx T m → Ctx T (n + m)\n[] ++ Γ = Γ\n(t ∷ Δ) ++ Γ = t ∷ (Δ ++ Γ)\n\n-- A map function that point-wise re-indexes and changes the entries\n-- in a context extension.\n\nmapExt : ∀ {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} {m n k} →\n (∀ l → T₁ (l + m) → T₂ (l + n)) → CtxExt T₁ m k → CtxExt T₂ n k\nmapExt f [] = []\nmapExt f (_∷_ {l} t Γ) = f l t ∷ mapExt (λ l → f l) Γ\n\n-- Operations on contexts that require weakening of types.\n\nmodule WeakenOps {ℓ} {T : Pred ℕ ℓ} (extension : Extension T) where\n\n -- Weakening of types.\n\n open Extension extension public\n\n -- Convert a context or context extension to its vector representation.\n\n toVec : ∀ {n} → Ctx T n → Vec (T n) n\n toVec [] = []\n toVec (t ∷ Γ) = weaken t /∷ toVec Γ\n\n extToVec : ∀ {k m n} → CtxExt T m n → Vec (T m) k → Vec (T (n + m)) (n + k)\n extToVec [] ts = ts\n extToVec (t ∷ Γ) ts = weaken t /∷ extToVec Γ ts\n\n -- Lookup the type of a variable in a context or context extension.\n\n lookup : ∀ {n} → Ctx T n → Fin n → T n\n lookup Γ x = Vec.lookup (toVec Γ) x\n\n extLookup : ∀ {k m n} → CtxExt T m n → Vec (T m) k → Fin (n + k) → T (n + m)\n extLookup Δ ts x = Vec.lookup (extToVec Δ ts) x\n\n-- Operations on contexts that require substitutions in types.\n\nmodule SubstOps {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂}\n (application : Application T₁ T₂)\n (simple : Simple T₂)\n where\n\n open Application application public -- Application of T′ substitutions to Ts.\n open Simple simple public -- Simple T′ substitutions.\n\n -- Application of substitutions to context extensions.\n\n _E/_ : ∀ {k m n} → CtxExt T₁ m k → Sub T₂ m n → CtxExt T₁ n k\n Γ E/ σ = mapExt (λ l t → t / σ ↑⋆ l) Γ\n", "meta": {"hexsha": "c56dfb936920b21f666733b2eb8dee04b800bd83", "size": 4916, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Data/Context.agda", "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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/Data/Context.agda", "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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/Data/Context.agda", "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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": 33.6712328767, "max_line_length": 79, "alphanum_fraction": 0.5840113914, "num_tokens": 1574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6224593171945416, "lm_q2_score": 0.6297746213017459, "lm_q1q2_score": 0.39200908076193575}} {"text": "{-\nPlease do not move this file. Changes should only be made if necessary.\n\nThis file contains pointers to the code examples and main results from the paper:\n\nInternalizing Representation Independence with Univalence\n\nCarlo Angiuli, Evan Cavallo, Anders Mörtberg, Max Zeuner\n\nPreprint: https://arxiv.org/abs/2009.05547\n\n-}\n{-# OPTIONS --safe #-}\nmodule Cubical.Papers.RepresentationIndependence where\n\n\n-- 2.1\nimport Agda.Builtin.Cubical.Path as Path\nimport Cubical.Foundations.Prelude as Prelude\n-- 2.2\nimport Cubical.Foundations.Univalence as Univalence\nimport Cubical.Foundations.HLevels as HLevels\nimport Cubical.Foundations.Equiv as Equivalences\nimport Cubical.Data.Sigma.Properties as Sigma\n-- 2.3\nimport Cubical.HITs.PropositionalTruncation as PropositionalTruncation\nimport Cubical.HITs.Cost.Base as CostMonad\nimport Cubical.HITs.SetQuotients as SetQuotients\nimport Cubical.HITs.Rationals.QuoQ as SetQuoQ\nimport Cubical.HITs.Rationals.SigmaQ as SigmaQ\n-- 3.1\nimport Cubical.Foundations.SIP as SIP\nimport Cubical.Structures.Axioms as Axioms\nimport Cubical.Algebra.Semigroup.Base as Semigroup\nopen import Cubical.Data.Sigma.Base\n-- 3.2\nimport Cubical.Structures.Pointed as PointedStr\nimport Cubical.Structures.Constant as ConstantStr\nimport Cubical.Structures.Product as ProductStr\nimport Cubical.Structures.Function as FunctionStr\nimport Cubical.Structures.Maybe as MaybeStr\nimport Cubical.Foundations.Structure as Structure\nimport Cubical.Structures.Auto as Auto\nopen import Cubical.Data.Maybe.Base\n-- 4.1\nimport Cubical.Data.Vec.Base as Vector\nimport Cubical.Algebra.Matrix as Matrices\nimport Cubical.Data.FinData.Base as Finite\nopen import Cubical.Algebra.AbGroup.Base\nopen import Cubical.Data.Bool.Base\n-- 4.2\nimport Cubical.Structures.Queue as Queues\nimport Cubical.Data.Queue.Truncated2List as BatchedQueues\n-- 5.1\nimport Cubical.Relation.Binary.Base as BinRel\nimport Cubical.Relation.ZigZag.Base as QER\nimport Cubical.Relation.ZigZag.Applications.MultiSet\n as MultiSets\n-- 5.2\nimport Cubical.Foundations.RelationalStructure as RelStructure\nimport Cubical.Structures.Relational.Function as RelFunction\n\n\n\n-------------------------------------------------------------------------\n-- 2. Programming in Cubical Type Theory\n-- 2.1 Equalities as Paths\n-- 2.2 Univalence\n-- 2.3 Higher Inductive Types\n-------------------------------------------------------------------------\n\n\n-- 2.1 Equalities as Paths\nopen Path using (PathP) public\nopen Prelude using (_≡_ ; refl ; cong ; funExt\n ; transport ; subst ; J) public\n\n\n-- 2.2 Univalence\nopen Univalence using (ua ; uaβ) public\n\n-- Sets and Propositions\nopen Prelude using (isProp ; isSet) public\nopen HLevels using (isPropΠ) public\nopen Prelude using (isContr) public\n\n-- Equivalences and Isomorphisms\nopen Equivalences using (isEquiv ; _≃_) public\nopen Equivalences renaming (fiber to preim) public\nopen Sigma using (ΣPath≃PathΣ) public\nopen Equivalences renaming (propBiimpl→Equiv to prop≃) public\n\n\n-- 2.3 Higher Inductive Types\n-- Propositional Truncation\nopen PropositionalTruncation using (∥_∥ ; map) public\nopen CostMonad using (Cost ; Cost≡ ; _>>=_ ; return\n ; fib ; fibTail) public\n-- Computation\n_ : fib 20 ≡ (6765 , PropositionalTruncation.∣ 21890 ∣)\n_ = refl\n\n_ : fibTail 20 ≡ (6765 , PropositionalTruncation.∣ 19 ∣)\n_ = refl\n\n-- Set Quotients\nopen SetQuotients using (_/_ ; setQuotUniversal) public\n-- Rational Numbers\nopen SetQuoQ using (_∼_ ; ℚ) public\nopen SigmaQ renaming (ℚ to ℚ') public\n\n\n\n-------------------------------------------------------------------------\n-- 3. The Structure Identity Principle\n-- 3.1 Structures\n-- 3.2 Building Strucutres\n-------------------------------------------------------------------------\n\n-- 3.1 Structures\nopen SIP using (TypeWithStr ; StrEquiv ; _≃[_]_\n ; UnivalentStr ; SIP ; sip) public\n\n-- the last two terms above correspond to lemma 3.3\n-- and corollary 3.4 respectively\nopen Axioms using ( AxiomsStructure ; AxiomsEquivStr\n ; axiomsUnivalentStr ; transferAxioms) public\n\n-- Monoids are defined using records and Σ-types in the library\n\nRawMonoidStructure : Type → Type\nRawMonoidStructure X = X × (X → X → X)\n\nMonoidAxioms : (M : Type) → RawMonoidStructure M → Type\nMonoidAxioms M (e , _·_) = Semigroup.IsSemigroup _·_\n × ((x : M) → (x · e ≡ x) × (e · x ≡ x))\n\nMonoidStructure : Type → Type\nMonoidStructure = AxiomsStructure RawMonoidStructure MonoidAxioms\n\nMonoid : Type₁\nMonoid = TypeWithStr ℓ-zero MonoidStructure\n\nMonoidEquiv : (M N : Monoid) → fst M ≃ fst N → Type\nMonoidEquiv (_ , (εᴹ , _·_) , _) (_ , (εᴺ , _∗_) , _) (φ , _) =\n (φ εᴹ ≡ εᴺ) × (∀ x y → φ (x · y) ≡ (φ x) ∗ (φ y))\n\n\n-- 3.2 Building Structures\n-- Constant and Pointed Structures\nopen PointedStr using (PointedStructure ; PointedEquivStr\n ; pointedUnivalentStr) public\nopen ConstantStr using (ConstantStructure ; ConstantEquivStr\n ; constantUnivalentStr) public\n\n-- Product Structures\nopen ProductStr using (ProductStructure ; ProductEquivStr\n ; productUnivalentStr) public\n\n-- Function Structures\nopen FunctionStr using (FunctionEquivStr) public\n\n-- Maybe Structures\nopen MaybeStr using (MaybeEquivStr) public\n\n-- Transport Structures\nopen Structure using (EquivAction) public\nopen SIP using (TransportStr ; TransportStr→UnivalentStr\n ; UnivalentStr→TransportStr) public\nopen Structure using (EquivAction→StrEquiv) public\nopen FunctionStr using (FunctionEquivStr+) public\n\n-- Monoids Revisited\n\nRawMonoid : Type₁\nRawMonoid = TypeWithStr _ RawMonoidStructure\n\nMonoid→RawMonoid : Monoid → RawMonoid\nMonoid→RawMonoid (A , r , _) = (A , r)\n\nRawMonoidEquivStr = Auto.AutoEquivStr RawMonoidStructure\n\nrawMonoidUnivalentStr : UnivalentStr _ RawMonoidEquivStr\nrawMonoidUnivalentStr = Auto.autoUnivalentStr RawMonoidStructure\n\nisPropMonoidAxioms : (M : Type) (s : RawMonoidStructure M) → isProp (MonoidAxioms M s)\nisPropMonoidAxioms M (e , _·_) =\n HLevels.isPropΣ\n (Semigroup.isPropIsSemigroup _·_)\n (λ α → isPropΠ λ _ →\n HLevels.isProp×\n (Semigroup.IsSemigroup.is-set α _ _)\n (Semigroup.IsSemigroup.is-set α _ _))\n\nMonoidEquivStr : StrEquiv MonoidStructure ℓ-zero\nMonoidEquivStr = AxiomsEquivStr RawMonoidEquivStr MonoidAxioms\n\nmonoidUnivalentStr : UnivalentStr MonoidStructure MonoidEquivStr\nmonoidUnivalentStr = axiomsUnivalentStr _ isPropMonoidAxioms rawMonoidUnivalentStr\n\nMonoidΣPath : (M N : Monoid) → (M ≃[ MonoidEquivStr ] N) ≃ (M ≡ N)\nMonoidΣPath = SIP monoidUnivalentStr\n\nInducedMonoid : (M : Monoid) (N : RawMonoid) (e : M .fst ≃ N .fst)\n → RawMonoidEquivStr (Monoid→RawMonoid M) N e → Monoid\nInducedMonoid M N e r =\n Axioms.inducedStructure rawMonoidUnivalentStr M N (e , r)\n\nInducedMonoidPath : (M : Monoid) (N : RawMonoid) (e : M .fst ≃ N .fst)\n (E : RawMonoidEquivStr (Monoid→RawMonoid M) N e)\n → M ≡ InducedMonoid M N e E\nInducedMonoidPath M N e E =\n MonoidΣPath M (InducedMonoid M N e E) .fst (e , E)\n\n-- Automation\nopen Auto using (Transp[_] ; AutoEquivStr ; autoUnivalentStr) public\nmodule _ (A : Type) (Aset : isSet A) where\n RawQueueEquivStr =\n AutoEquivStr (λ (X : Type) → X × (A → X → X) × (X → Transp[ Maybe (X × A) ]))\n\n\n\n-------------------------------------------------------------------------\n-- 4. Representation Independence through the SIP\n-- 4.1 Matrices\n-- 4.2 Queues\n-------------------------------------------------------------------------\n\n\n-- 4.1 Matrices\nopen Vector using (Vec) public\nopen Finite using (Fin ; _==_) public\nopen Matrices using (VecMatrix ; FinMatrix ; FinMatrix≡VecMatrix\n ; FinMatrix≃VecMatrix) public\nopen Matrices.FinMatrixAbGroup using (addFinMatrix ; addFinMatrixComm) public\n\n-- example (not in the library)\nopen import Cubical.Data.Int renaming (Int to ℤ ; isSetInt to isSetℤ) hiding (-_)\n\nℤ-AbGroup : AbGroup ℓ-zero\nℤ-AbGroup = makeAbGroup {G = ℤ} 0 _+_ -_ isSetℤ +-assoc (λ x _ → x) rem +-comm\n where\n -_ : ℤ → ℤ\n - x = 0 - x\n rem : (x : ℤ) → x + (- x) ≡ 0\n rem x = +-comm x (pos 0 - x) Prelude.∙ minusPlus x 0\n\nmodule experiment where\n open Prelude\n\n M : FinMatrix ℤ 2 2\n M i j = if i == j then 1 else 0\n\n N : FinMatrix ℤ 2 2\n N i j = if i == j then 0 else 1\n\n replaceGoal : {A B : Type} {x y : A} → (e : A ≃ B)\n (h : invEq e (equivFun e x) ≡ invEq e (equivFun e y)) → x ≡ y\n replaceGoal e h = sym (retEq e _) ∙∙ h ∙∙ retEq e _\n\n _ : addFinMatrix ℤ-AbGroup M N ≡ (λ _ _ → 1)\n _ = replaceGoal (FinMatrix≃VecMatrix) refl\n\n\n-- 4.2 Queues\nopen Queues.Queues-on using (RawQueueStructure ; QueueAxioms) public\nopen BatchedQueues.Truncated2List renaming (Q to BatchedQueueHIT)\n using (Raw-1≡2 ; WithLaws) public\n\n\n\n-------------------------------------------------------------------------\n-- 5. Structured Equivalences from Structured Relations\n-- 5.1 Quasi-Equivalence Relations\n-- 5.2 Structured Relations\n-------------------------------------------------------------------------\n\n\n-- 5.1 Quasi-Equivalence Relations\n--Lemma (5.1)\nopen BinRel using (idPropRel ; invPropRel\n ; compPropRel ; graphRel) public\n-- Definitions (5.2) and (5.3)\nopen QER using (isZigZagComplete ; isQuasiEquivRel) public\n-- Lemma (5.4)\nopen QER.QER→Equiv using (Thm ; bwd≡ToRel) public\n-- Multisets\nopen MultiSets renaming (AList to AssocList) public\nopen MultiSets.Lists&ALists using (addIfEq ; R ; φ ; ψ\n ; List/Rᴸ≃AList/Rᴬᴸ) public\nopen MultiSets.Lists&ALists.L using (insert ; union ; count)\nopen MultiSets.Lists&ALists.AL using (insert ; union ; count)\n\n\n-- 5.2 Structured Relations\nopen RelStructure using (StrRel) public\n-- Definition (5.6)\nopen RelStructure using (SuitableStrRel) public\n-- Theorem (5.7)\nopen RelStructure using (structuredQER→structuredEquiv) public\n-- Definition (5.9)\nopen RelStructure using (StrRelAction) public\n-- Lemma (5.10)\nopen RelStructure using (strRelQuotientComparison) public\n-- Definition (5.11)\nopen RelStructure using (PositiveStrRel) public\n-- Theorem (5.12)\nopen RelFunction using (functionSuitableRel) public\n-- Multisets\n-- (main is applying 5.7 to the example)\nopen MultiSets.Lists&ALists using (multisetShape ; isStructuredR ; main ; List/Rᴸ≡AList/Rᴬᴸ)\n renaming ( hasAssociativeUnion to unionAssocAxiom\n ; LQassoc to LUnionAssoc\n ; ALQassoc to ALUnionAssoc) public\n", "meta": {"hexsha": "4131eadba26c7a758ad5239ae4cc8047f7e3248d", "size": 11056, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Papers/RepresentationIndependence.agda", "max_stars_repo_name": "LuuBluum/cubical", "max_stars_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621", "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": "Cubical/Papers/RepresentationIndependence.agda", "max_issues_repo_name": "LuuBluum/cubical", "max_issues_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621", "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": "Cubical/Papers/RepresentationIndependence.agda", "max_forks_repo_name": "LuuBluum/cubical", "max_forks_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-12T20:08:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-12T20:08:45.000Z", "avg_line_length": 35.0984126984, "max_line_length": 92, "alphanum_fraction": 0.6420043415, "num_tokens": 3146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.6187804267137441, "lm_q1q2_score": 0.3919418732434391}} {"text": "{-# OPTIONS --safe #-}\n\nmodule Definition.Typed where\n\nopen import Definition.Untyped\n\nopen import Tools.Nat using (Nat)\nopen import Tools.Product\nimport Tools.PropositionalEquality as PE\n\ninfixl 30 _∙_\ninfix 30 Πⱼ_▹_▹_▹_\n\n-- Well-typed variables\ndata _∷_^_∈_ : (x : Nat) (A : Term) (r : TypeInfo) (Γ : Con Term) → Set where\n here : ∀ {Γ A r} → 0 ∷ wk1 A ^ r ∈ (Γ ∙ A ^ r )\n there : ∀ {Γ A rA B rB x} (h : x ∷ A ^ rA ∈ Γ) → Nat.suc x ∷ wk1 A ^ rA ∈ (Γ ∙ B ^ rB)\n\nmutual\n -- Well-formed context\n data ⊢_ : Con Term → Set where\n ε : ⊢ ε\n _∙_ : ∀ {Γ A r}\n → ⊢ Γ\n → Γ ⊢ A ^ r\n → ⊢ Γ ∙ A ^ r\n\n -- Well-formed type\n data _⊢_^_ (Γ : Con Term) : Term → TypeInfo → Set where\n Uⱼ : ∀ {r} → ⊢ Γ → Γ ⊢ Univ r ¹ ^ [ ! , ∞ ]\n univ : ∀ {A r l}\n → Γ ⊢ A ∷ Univ r l ^ [ ! , next l ]\n → Γ ⊢ A ^ [ r , ι l ]\n\n -- Well-formed term of a type\n data _⊢_∷_^_ (Γ : Con Term) : Term → Term → TypeInfo → Set where\n univ : ∀ {r l l'}\n → l < l'\n → ⊢ Γ\n → Γ ⊢ (Univ r l) ∷ (Univ ! l') ^ [ ! , next l' ]\n ℕⱼ : ⊢ Γ → Γ ⊢ ℕ ∷ U ⁰ ^ [ ! , ι ¹ ]\n Emptyⱼ : ∀ {l} → ⊢ Γ → Γ ⊢ Empty l ∷ SProp l ^ [ ! , next l ]\n Πⱼ_▹_▹_▹_ : ∀ {F rF lF G lG r l}\n → lF ≤ l\n → lG ≤ l\n → Γ ⊢ F ∷ (Univ rF lF) ^ [ ! , next lF ]\n → Γ ∙ F ^ [ rF , ι lF ] ⊢ G ∷ (Univ r lG) ^ [ ! , next lG ]\n → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° l ∷ (Univ r l) ^ [ ! , next l ]\n ∃ⱼ_▹_ : ∀ {F G l}\n → Γ ⊢ F ∷ SProp l ^ [ ! , next l ]\n → Γ ∙ F ^ [ % , ι l ] ⊢ G ∷ SProp l ^ [ ! , next l ]\n → Γ ⊢ ∃ F ▹ G ∷ SProp l ^ [ ! , next l ]\n var : ∀ {A rl x}\n → ⊢ Γ\n → x ∷ A ^ rl ∈ Γ\n → Γ ⊢ var x ∷ A ^ rl\n lamⱼ : ∀ {F r l rF lF G lG t}\n → lF ≤ l\n → lG ≤ l\n → Γ ⊢ F ^ [ rF , ι lF ]\n → Γ ∙ F ^ [ rF , ι lF ] ⊢ t ∷ G ^ [ r , ι lG ]\n → Γ ⊢ lam F ▹ t ^ l ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ r , ι l ]\n _∘ⱼ_ : ∀ {g a F rF lF G lG r lΠ}\n → Γ ⊢ g ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ r , ι lΠ ]\n → Γ ⊢ a ∷ F ^ [ rF , ι lF ]\n → Γ ⊢ g ∘ a ^ lΠ ∷ G [ a ] ^ [ r , ι lG ]\n ⦅_,_,_,_⦆ⱼ : ∀ {l F G t u}\n → Γ ⊢ F ^ [ % , ι l ]\n → Γ ∙ F ^ [ % , ι l ] ⊢ G ^ [ % , ι l ]\n → Γ ⊢ t ∷ F ^ [ % , ι l ]\n → Γ ⊢ u ∷ G [ t ] ^ [ % , ι l ]\n → Γ ⊢ ⦅ G , t , u ⦆ ∷ ∃ F ▹ G ^ [ % , ι l ]\n fstⱼ : ∀ {F G t l}\n → Γ ⊢ F ∷ SProp l ^ [ ! , next l ]\n → Γ ∙ F ^ [ % , ι l ] ⊢ G ∷ SProp l ^ [ ! , next l ]\n → Γ ⊢ t ∷ ∃ F ▹ G ^ [ % , ι l ]\n → Γ ⊢ fst t ∷ F ^ [ % , ι l ]\n sndⱼ : ∀ {F G t l}\n → Γ ⊢ F ∷ SProp l ^ [ ! , next l ]\n → Γ ∙ F ^ [ % , ι l ] ⊢ G ∷ SProp l ^ [ ! , next l ]\n → Γ ⊢ t ∷ ∃ F ▹ G ^ [ % , ι l ]\n → Γ ⊢ snd t ∷ G [ fst t ] ^ [ % , ι l ]\n zeroⱼ : ⊢ Γ\n → Γ ⊢ zero ∷ ℕ ^ [ ! , ι ⁰ ]\n sucⱼ : ∀ {n}\n → Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ suc n ∷ ℕ ^ [ ! , ι ⁰ ]\n natrecⱼ : ∀ {G rG lG s z n}\n → Γ ∙ ℕ ^ [ ! , ι ⁰ ] ⊢ G ^ [ rG , ι lG ]\n → Γ ⊢ z ∷ G [ zero ] ^ [ rG , ι lG ]\n → Γ ⊢ s ∷ Π ℕ ^ ! ° ⁰ ▹ (G ^ rG ° lG ▹▹ G [ suc (var Nat.zero) ]↑ ° lG ° lG) ° lG ° lG ^ [ rG , ι lG ]\n → Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ natrec lG G z s n ∷ G [ n ] ^ [ rG , ι lG ]\n Emptyrecⱼ : ∀ {A l lA rA e}\n → Γ ⊢ A ^ [ rA , ι lA ] → Γ ⊢ e ∷ Empty l ^ [ % , ι l ] -> Γ ⊢ Emptyrec lA l A e ∷ A ^ [ rA , ι lA ]\n Idⱼ : ∀ {A l t u}\n → Γ ⊢ A ∷ U l ^ [ ! , next l ]\n → Γ ⊢ t ∷ A ^ [ ! , ι l ]\n → Γ ⊢ u ∷ A ^ [ ! , ι l ]\n → Γ ⊢ Id A t u ∷ SProp l ^ [ ! , next l ]\n Idreflⱼ : ∀ {A l t}\n → Γ ⊢ t ∷ A ^ [ ! , ι l ]\n → Γ ⊢ Idrefl A t ∷ (Id A t t) ^ [ % , ι l ]\n transpⱼ : ∀ {A l P t s u e}\n → Γ ⊢ A ^ [ ! , l ]\n → Γ ∙ A ^ [ ! , l ] ⊢ P ^ [ % , l ]\n → Γ ⊢ t ∷ A ^ [ ! , l ]\n → Γ ⊢ s ∷ P [ t ] ^ [ % , l ]\n → Γ ⊢ u ∷ A ^ [ ! , l ]\n → Γ ⊢ e ∷ (Id A t u) ^ [ % , l ]\n → Γ ⊢ transp A P t s u e ∷ P [ u ] ^ [ % , l ]\n castⱼ : ∀ {A B r e t}\n → Γ ⊢ A ∷ Univ r ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ B ∷ Univ r ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ e ∷ (Id (Univ r ⁰) A B) ^ [ % , next ⁰ ]\n → Γ ⊢ t ∷ A ^ [ r , ι ⁰ ]\n → Γ ⊢ cast ⁰ A B e t ∷ B ^ [ r , ι ⁰ ]\n castreflⱼ : ∀ {A t}\n → Γ ⊢ A ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ t ∷ A ^ [ ! , ι ⁰ ]\n → Γ ⊢ castrefl A t ∷ (Id A t (cast ⁰ A A (Idrefl (U ⁰) A) t)) ^ [ % , ι ⁰ ]\n conv : ∀ {t A B r}\n → Γ ⊢ t ∷ A ^ r\n → Γ ⊢ A ≡ B ^ r\n → Γ ⊢ t ∷ B ^ r\n\n -- Type equality\n data _⊢_≡_^_ (Γ : Con Term) : Term → Term → TypeInfo → Set where\n univ : ∀ {A B r l}\n → Γ ⊢ A ≡ B ∷ (Univ r l) ^ [ ! , next l ]\n → Γ ⊢ A ≡ B ^ [ r , ι l ]\n refl : ∀ {A r}\n → Γ ⊢ A ^ r\n → Γ ⊢ A ≡ A ^ r\n sym : ∀ {A B r}\n → Γ ⊢ A ≡ B ^ r\n → Γ ⊢ B ≡ A ^ r\n trans : ∀ {A B C r}\n → Γ ⊢ A ≡ B ^ r\n → Γ ⊢ B ≡ C ^ r\n → Γ ⊢ A ≡ C ^ r\n\n\n -- Term equality\n data _⊢_≡_∷_^_ (Γ : Con Term) : Term → Term → Term → TypeInfo → Set where\n refl : ∀ {t A l}\n → Γ ⊢ t ∷ A ^ [ ! , l ]\n → Γ ⊢ t ≡ t ∷ A ^ [ ! , l ]\n sym : ∀ {t u A l}\n → Γ ⊢ t ≡ u ∷ A ^ [ ! , l ]\n → Γ ⊢ u ≡ t ∷ A ^ [ ! , l ]\n trans : ∀ {t u v A l}\n → Γ ⊢ t ≡ u ∷ A ^ [ ! , l ]\n → Γ ⊢ u ≡ v ∷ A ^ [ ! , l ]\n → Γ ⊢ t ≡ v ∷ A ^ [ ! , l ]\n conv : ∀ {A B r t u}\n → Γ ⊢ t ≡ u ∷ A ^ r\n → Γ ⊢ A ≡ B ^ r\n → Γ ⊢ t ≡ u ∷ B ^ r\n Π-cong : ∀ {E F G H rF lF rG lG l}\n → lF ≤ l\n → lG ≤ l\n → Γ ⊢ F ^ [ rF , ι lF ]\n → Γ ⊢ F ≡ H ∷ (Univ rF lF) ^ [ ! , next lF ]\n → Γ ∙ F ^ [ rF , ι lF ] ⊢ G ≡ E ∷ (Univ rG lG) ^ [ ! , next lG ]\n → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° l ≡ Π H ^ rF ° lF ▹ E ° lG ° l ∷ (Univ rG l) ^ [ ! , next l ]\n ∃-cong : ∀ {E F G H l}\n → Γ ⊢ F ^ [ % , ι l ]\n → Γ ⊢ F ≡ H ∷ SProp l ^ [ ! , next l ]\n → Γ ∙ F ^ [ % , ι l ] ⊢ G ≡ E ∷ SProp l ^ [ ! , next l ]\n → Γ ⊢ ∃ F ▹ G ≡ ∃ H ▹ E ∷ SProp l ^ [ ! , next l ]\n app-cong : ∀ {a b f g F G rF lF lG l}\n → Γ ⊢ f ≡ g ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , ι l ]\n → Γ ⊢ a ≡ b ∷ F ^ [ rF , ι lF ]\n → Γ ⊢ f ∘ a ^ l ≡ g ∘ b ^ l ∷ G [ a ] ^ [ ! , ι lG ]\n β-red : ∀ {a t F rF lF G lG l}\n → lF ≤ l\n → lG ≤ l\n → Γ ⊢ F ^ [ rF , ι lF ]\n → Γ ∙ F ^ [ rF , ι lF ] ⊢ t ∷ G ^ [ ! , ι lG ]\n → Γ ⊢ a ∷ F ^ [ rF , ι lF ]\n → Γ ⊢ (lam F ▹ t ^ l) ∘ a ^ l ≡ t [ a ] ∷ G [ a ] ^ [ ! , ι lG ]\n η-eq : ∀ {f g F rF lF lG l G}\n → lF ≤ l\n → lG ≤ l\n → Γ ⊢ F ^ [ rF , ι lF ]\n → Γ ⊢ f ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , ι l ]\n → Γ ⊢ g ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , ι l ]\n → Γ ∙ F ^ [ rF , ι lF ] ⊢ wk1 f ∘ var Nat.zero ^ l ≡ wk1 g ∘ var Nat.zero ^ l ∷ G ^ [ ! , ι lG ]\n → Γ ⊢ f ≡ g ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , ι l ]\n suc-cong : ∀ {m n}\n → Γ ⊢ m ≡ n ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ suc m ≡ suc n ∷ ℕ ^ [ ! , ι ⁰ ]\n natrec-cong : ∀ {z z′ s s′ n n′ F F′ l}\n → Γ ∙ ℕ ^ [ ! , ι ⁰ ] ⊢ F ≡ F′ ^ [ ! , ι l ]\n → Γ ⊢ z ≡ z′ ∷ F [ zero ] ^ [ ! , ι l ]\n → Γ ⊢ s ≡ s′ ∷ Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° l ▹▹ F [ suc (var Nat.zero) ]↑ ° l ° l) ° l ° l ^ [ ! , ι l ]\n → Γ ⊢ n ≡ n′ ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ natrec l F z s n ≡ natrec l F′ z′ s′ n′ ∷ F [ n ] ^ [ ! , ι l ]\n natrec-zero : ∀ {z s F l}\n → Γ ∙ ℕ ^ [ ! , ι ⁰ ] ⊢ F ^ [ ! , ι l ]\n → Γ ⊢ z ∷ F [ zero ] ^ [ ! , ι l ]\n → Γ ⊢ s ∷ Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° l ▹▹ F [ suc (var Nat.zero) ]↑ ° l ° l) ° l ° l ^ [ ! , ι l ]\n → Γ ⊢ natrec l F z s zero ≡ z ∷ F [ zero ] ^ [ ! , ι l ]\n natrec-suc : ∀ {n z s F l}\n → Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ∙ ℕ ^ [ ! , ι ⁰ ] ⊢ F ^ [ ! , ι l ]\n → Γ ⊢ z ∷ F [ zero ] ^ [ ! , ι l ]\n → Γ ⊢ s ∷ Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° l ▹▹ F [ suc (var Nat.zero) ]↑ ° l ° l) ° l ° l ^ [ ! , ι l ]\n → Γ ⊢ natrec l F z s (suc n) ≡ (s ∘ n ^ l) ∘ (natrec l F z s n) ^ l\n ∷ F [ suc n ] ^ [ ! , ι l ]\n Emptyrec-cong : ∀ {A A' l lEmpty e e'}\n → Γ ⊢ A ≡ A' ^ [ ! , ι l ]\n → Γ ⊢ e ∷ Empty lEmpty ^ [ % , ι lEmpty ]\n → Γ ⊢ e' ∷ Empty lEmpty ^ [ % , ι lEmpty ]\n → Γ ⊢ Emptyrec l lEmpty A e ≡ Emptyrec l lEmpty A' e' ∷ A ^ [ ! , ι l ]\n proof-irrelevance : ∀ {t u A l}\n → Γ ⊢ t ∷ A ^ [ % , l ]\n → Γ ⊢ u ∷ A ^ [ % , l ]\n → Γ ⊢ t ≡ u ∷ A ^ [ % , l ]\n Id-cong : ∀ {A A' l t t' u u'}\n → Γ ⊢ A ≡ A' ∷ Univ ! l ^ [ ! , next l ]\n → Γ ⊢ t ≡ t' ∷ A ^ [ ! , ι l ]\n → Γ ⊢ u ≡ u' ∷ A ^ [ ! , ι l ]\n → Γ ⊢ Id A t u ≡ Id A' t' u' ∷ SProp l ^ [ ! , next l ]\n Id-Π : ∀ {A rA lA lB l B t u}\n → lA ≤ l\n → lB ≤ l\n → Γ ⊢ A ∷ Univ rA lA ^ [ ! , next lA ]\n → Γ ∙ A ^ [ rA , ι lA ] ⊢ B ∷ Univ ! lB ^ [ ! , next lB ]\n → Γ ⊢ t ∷ (Π A ^ rA ° lA ▹ B ° lB ° l) ^ [ ! , ι l ]\n → Γ ⊢ u ∷ (Π A ^ rA ° lA ▹ B ° lB ° l) ^ [ ! , ι l ]\n → Γ ⊢ (Id (Π A ^ rA ° lA ▹ B ° lB ° l) t u)\n ≡ Π A ^ rA ° lA ▹ (Id B ((wk1 t) ∘ (var 0) ^ l) ((wk1 u) ∘ (var 0) ^ l)) ° lB ° l\n ∷ SProp l ^ [ ! , next l ]\n Id-ℕ-00 : ⊢ Γ\n → Γ ⊢ (Id ℕ zero zero)\n ≡ Unit {⁰}\n ∷ SProp ⁰ ^ [ ! , next ⁰ ]\n Id-ℕ-SS : ∀ {m n}\n → Γ ⊢ m ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ (Id ℕ (suc m) (suc n))\n ≡ (Id ℕ m n)\n ∷ SProp ⁰ ^ [ ! , next ⁰ ]\n Id-U-ΠΠ : ∀ {A A' rA B B'}\n → Γ ⊢ A ∷ (Univ rA ⁰) ^ [ ! , next ⁰ ]\n → Γ ∙ A ^ [ rA , ι ⁰ ] ⊢ B ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ A' ∷ (Univ rA ⁰) ^ [ ! , next ⁰ ]\n → Γ ∙ A' ^ [ rA , ι ⁰ ] ⊢ B' ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ (Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) (Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰))\n ≡ ∃ (Id (Univ rA ⁰) A A') ▹\n (Π (wk1 A') ^ rA ° ⁰ ▹ Id (U ⁰)\n ((wk (lift (step id)) B) [ cast ⁰ (wk1 (wk1 A')) (wk1 (wk1 A)) (Idsym (Univ rA ⁰) (wk1 (wk1 A)) (wk1 (wk1 A')) (var 1)) (var 0) ]↑)\n (wk (lift (step id)) B') ° ¹ ° ¹)\n ∷ SProp ¹ ^ [ ! , next ¹ ]\n Id-U-ℕℕ : ⊢ Γ\n → Γ ⊢ Id (U ⁰) ℕ ℕ\n ≡ Unit {¹}\n ∷ (SProp ¹) ^ [ ! , next ¹ ]\n Id-SProp : ∀ {A B}\n → Γ ⊢ A ∷ SProp ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ B ∷ SProp ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ Id (SProp ⁰) A B\n ≡ (A ^ % ° ⁰ ▹▹ B ° ⁰ ° ¹) ×× (B ^ % ° ⁰ ▹▹ A ° ⁰ ° ¹)\n ∷ SProp ¹ ^ [ ! , next ¹ ]\n Id-ℕ-0S : ∀ {t}\n → Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ Id ℕ zero (suc t) ≡ Empty ⁰ ∷ (SProp ⁰) ^ [ ! , next ⁰ ]\n Id-ℕ-S0 : ∀ {t}\n → Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ Id ℕ (suc t) zero ≡ Empty ⁰ ∷ (SProp ⁰) ^ [ ! , next ⁰ ]\n Id-U-ℕΠ : ∀ {A rA B}\n → Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ]\n → Γ ∙ A ^ [ rA , ι ⁰ ] ⊢ B ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ Id (U ⁰) ℕ (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) ≡ Empty ¹ ∷ SProp ¹ ^ [ ! , next ¹ ]\n Id-U-Πℕ : ∀ {A rA B}\n → Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ]\n → Γ ∙ A ^ [ rA , ι ⁰ ] ⊢ B ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) ℕ ≡ Empty ¹ ∷ SProp ¹ ^ [ ! , next ¹ ]\n Id-U-ΠΠ!% : ∀ {A rA B A' rA' B' }\n → rA PE.≢ rA'\n → Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ]\n → Γ ∙ A ^ [ rA , ι ⁰ ] ⊢ B ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ A' ∷ Univ rA' ⁰ ^ [ ! , next ⁰ ]\n → Γ ∙ A' ^ [ rA' , ι ⁰ ] ⊢ B' ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) (Π A' ^ rA' ° ⁰ ▹ B' ° ⁰ ° ⁰) ≡ Empty ¹ ∷ SProp ¹ ^ [ ! , next ¹ ]\n cast-cong : ∀ {A A' B B' e e' t t'} → let l = ⁰ in\n Γ ⊢ A ≡ A' ∷ U l ^ [ ! , next l ]\n → Γ ⊢ B ≡ B' ∷ U l ^ [ ! , next l ]\n → Γ ⊢ t ≡ t' ∷ A ^ [ ! , ι l ]\n → Γ ⊢ e ∷ (Id (U ⁰) A B) ^ [ % , next ⁰ ]\n → Γ ⊢ e' ∷ (Id (U ⁰) A' B') ^ [ % , next ⁰ ]\n → Γ ⊢ cast l A B e t ≡ cast l A' B' e' t' ∷ B ^ [ ! , ι l ]\n cast-Π : ∀ {A A' rA B B' e f} → let l = ⁰ in let lA = ⁰ in let lB = ⁰ in\n Γ ⊢ A ∷ (Univ rA lA) ^ [ ! , next lA ]\n → Γ ∙ A ^ [ rA , ι lA ] ⊢ B ∷ U lB ^ [ ! , next lB ]\n → Γ ⊢ A' ∷ (Univ rA lA) ^ [ ! , next lA ]\n → Γ ∙ A' ^ [ rA , ι lA ] ⊢ B' ∷ U lB ^ [ ! , next lB ]\n → Γ ⊢ e ∷ Id (U l) (Π A ^ rA ° lA ▹ B ° lB ° l) (Π A' ^ rA ° lA ▹ B' ° lB ° l) ^ [ % , next l ]\n → Γ ⊢ f ∷ (Π A ^ rA ° lA ▹ B ° lB ° l) ^ [ ! , ι l ]\n → Γ ⊢ (cast l (Π A ^ rA ° lA ▹ B ° lB ° l) (Π A' ^ rA ° lA ▹ B' ° lB ° l) e f)\n ≡ (lam A' ▹\n (let a = cast l (wk1 A') (wk1 A) (Idsym (Univ rA l) (wk1 A) (wk1 A') (fst (wk1 e))) (var 0) in\n cast l (B [ a ]↑) B' ((snd (wk1 e)) ∘ (var 0) ^ ¹) ((wk1 f) ∘ a ^ l))\n ^ l)\n ∷ Π A' ^ rA ° lA ▹ B' ° lB ° l ^ [ ! , ι l ]\n cast-ℕ-0 : ∀ {e}\n → Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ]\n → Γ ⊢ cast ⁰ ℕ ℕ e zero\n ≡ zero\n ∷ ℕ ^ [ ! , ι ⁰ ]\n cast-ℕ-S : ∀ {e n}\n → Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ]\n → Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ cast ⁰ ℕ ℕ e (suc n)\n ≡ suc (cast ⁰ ℕ ℕ e n)\n ∷ ℕ ^ [ ! , ι ⁰ ]\n\nmutual\n data _⊢_⇒_∷_^_ (Γ : Con Term) : Term → Term → Term → TypeLevel → Set where\n conv : ∀ {A B l t u}\n → Γ ⊢ t ⇒ u ∷ A ^ l\n → Γ ⊢ A ≡ B ^ [ ! , l ]\n → Γ ⊢ t ⇒ u ∷ B ^ l\n app-subst : ∀ {A B t u a rA lA lB l}\n → Γ ⊢ t ⇒ u ∷ Π A ^ rA ° lA ▹ B ° lB ° l ^ ι l\n → Γ ⊢ a ∷ A ^ [ rA , ι lA ]\n → Γ ⊢ t ∘ a ^ l ⇒ u ∘ a ^ l ∷ B [ a ] ^ ι lB\n β-red : ∀ {A B lA lB a t rA l}\n → lA ≤ l\n → lB ≤ l\n → Γ ⊢ A ^ [ rA , ι lA ]\n → Γ ∙ A ^ [ rA , ι lA ] ⊢ t ∷ B ^ [ ! , ι lB ]\n → Γ ⊢ a ∷ A ^ [ rA , ι lA ]\n → Γ ⊢ (lam A ▹ t ^ l) ∘ a ^ l ⇒ t [ a ] ∷ B [ a ] ^ ι lB\n natrec-subst : ∀ {z s n n′ F l}\n → Γ ∙ ℕ ^ [ ! , ι ⁰ ] ⊢ F ^ [ ! , ι l ]\n → Γ ⊢ z ∷ F [ zero ] ^ [ ! , ι l ]\n → Γ ⊢ s ∷ Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° l ▹▹ F [ suc (var Nat.zero) ]↑ ° l ° l) ° l ° l ^ [ ! , ι l ]\n → Γ ⊢ n ⇒ n′ ∷ ℕ ^ ι ⁰\n → Γ ⊢ natrec l F z s n ⇒ natrec l F z s n′ ∷ F [ n ] ^ ι l\n natrec-zero : ∀ {z s F l }\n → Γ ∙ ℕ ^ [ ! , ι ⁰ ] ⊢ F ^ [ ! , ι l ]\n → Γ ⊢ z ∷ F [ zero ] ^ [ ! , ι l ]\n → Γ ⊢ s ∷ Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° l ▹▹ F [ suc (var Nat.zero) ]↑ ° l ° l ) ° l ° l ^ [ ! , ι l ]\n → Γ ⊢ natrec l F z s zero ⇒ z ∷ F [ zero ] ^ ι l\n natrec-suc : ∀ {n z s F l}\n → Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ∙ ℕ ^ [ ! , ι ⁰ ] ⊢ F ^ [ ! , ι l ]\n → Γ ⊢ z ∷ F [ zero ] ^ [ ! , ι l ]\n → Γ ⊢ s ∷ Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° l ▹▹ F [ suc (var Nat.zero) ]↑ ° l ° l) ° l ° l ^ [ ! , ι l ]\n → Γ ⊢ natrec l F z s (suc n) ⇒ (s ∘ n ^ l) ∘ (natrec l F z s n) ^ l\n ∷ F [ suc n ] ^ ι l\n Id-subst : ∀ {A A' l t u}\n → Γ ⊢ A ⇒ A' ∷ Univ ! l ^ next l\n → Γ ⊢ t ∷ A ^ [ ! , ι l ]\n → Γ ⊢ u ∷ A ^ [ ! , ι l ]\n → Γ ⊢ Id A t u ⇒ Id A' t u ∷ SProp l ^ next l\n Id-ℕ-subst : ∀ {m m' n}\n → Γ ⊢ m ⇒ m' ∷ ℕ ^ ι ⁰\n → Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ Id ℕ m n ⇒ Id ℕ m' n ∷ SProp ⁰ ^ next ⁰\n Id-ℕ-0-subst : ∀ {n n'}\n → Γ ⊢ n ⇒ n' ∷ ℕ ^ ι ⁰\n → Γ ⊢ Id ℕ zero n ⇒ Id ℕ zero n' ∷ SProp ⁰ ^ next ⁰\n Id-ℕ-S-subst : ∀ {m n n'}\n → Γ ⊢ m ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ n ⇒ n' ∷ ℕ ^ ι ⁰\n → Γ ⊢ Id ℕ (suc m) n ⇒ Id ℕ (suc m) n' ∷ SProp ⁰ ^ next ⁰\n Id-U-subst : ∀ {A A' B}\n → Γ ⊢ A ⇒ A' ∷ U ⁰ ^ next ⁰\n → Γ ⊢ B ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ Id (U ⁰ ) A B ⇒ Id (U ⁰) A' B ∷ SProp ¹ ^ next ¹\n Id-U-ℕ-subst : ∀ {B B'}\n → Γ ⊢ B ⇒ B' ∷ U ⁰ ^ next ⁰\n → Γ ⊢ Id (U ⁰) ℕ B ⇒ Id (U ⁰) ℕ B' ∷ SProp ¹ ^ next ¹\n Id-U-Π-subst : ∀ {A rA P B B'}\n → Γ ⊢ A ∷ (Univ rA ⁰) ^ [ ! , next ⁰ ]\n → Γ ∙ A ^ [ rA , ι ⁰ ] ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ B ⇒ B' ∷ U ⁰ ^ next ⁰\n → Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) B ⇒ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) B' ∷ SProp ¹ ^ next ¹\n Id-Π : ∀ {A rA lA lB l B t u}\n → lA ≤ l\n → lB ≤ l\n → Γ ⊢ A ∷ Univ rA lA ^ [ ! , next lA ]\n → Γ ∙ A ^ [ rA , ι lA ] ⊢ B ∷ Univ ! lB ^ [ ! , next lB ]\n → Γ ⊢ t ∷ (Π A ^ rA ° lA ▹ B ° lB ° l) ^ [ ! , ι l ]\n → Γ ⊢ u ∷ (Π A ^ rA ° lA ▹ B ° lB ° l) ^ [ ! , ι l ]\n → Γ ⊢ (Id (Π A ^ rA ° lA ▹ B ° lB ° l) t u)\n ⇒ Π A ^ rA ° lA ▹ (Id B ((wk1 t) ∘ (var 0) ^ l) ((wk1 u) ∘ (var 0) ^ l)) ° lB ° l\n ∷ SProp l ^ next l\n Id-ℕ-00 : ⊢ Γ\n → Γ ⊢ (Id ℕ zero zero)\n ⇒ Unit {⁰}\n ∷ SProp ⁰ ^ next ⁰\n Id-ℕ-SS : ∀ {m n}\n → Γ ⊢ m ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ (Id ℕ (suc m) (suc n))\n ⇒ (Id ℕ m n)\n ∷ SProp ⁰ ^ next ⁰\n Id-U-ΠΠ : ∀ {A A' rA B B'}\n → Γ ⊢ A ∷ (Univ rA ⁰) ^ [ ! , next ⁰ ]\n → Γ ∙ A ^ [ rA , ι ⁰ ] ⊢ B ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ A' ∷ (Univ rA ⁰) ^ [ ! , next ⁰ ]\n → Γ ∙ A' ^ [ rA , ι ⁰ ] ⊢ B' ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ (Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) (Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰))\n ⇒ ∃ (Id (Univ rA ⁰) A A') ▹\n (Π (wk1 A') ^ rA ° ⁰ ▹ Id (U ⁰)\n ((wk1d B) [ cast ⁰ (wk1 (wk1 A')) (wk1 (wk1 A)) (Idsym (Univ rA ⁰) (wk1 (wk1 A)) (wk1 (wk1 A')) (var 1)) (var 0) ]↑)\n (wk1d B') ° ¹ ° ¹)\n ∷ SProp ¹ ^ next ¹\n Id-U-ℕℕ : ⊢ Γ\n → Γ ⊢ (Id (U ⁰) ℕ ℕ)\n ⇒ Unit {¹}\n ∷ SProp ¹ ^ next ¹\n Id-SProp : ∀ {A B}\n → Γ ⊢ A ∷ SProp ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ B ∷ SProp ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ Id (SProp ⁰) A B\n ⇒ (A ^ % ° ⁰ ▹▹ B ° ⁰ ° ¹) ×× (B ^ % ° ⁰ ▹▹ A ° ⁰ ° ¹)\n ∷ SProp ¹ ^ next ¹\n Id-ℕ-0S : ∀ {t}\n → Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ Id ℕ zero (suc t) ⇒ Empty ⁰ ∷ SProp ⁰ ^ next ⁰\n Id-ℕ-S0 : ∀ {t}\n → Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ Id ℕ (suc t) zero ⇒ Empty ⁰ ∷ SProp ⁰ ^ next ⁰\n Id-U-ℕΠ : ∀ {A rA B}\n → Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ]\n → Γ ∙ A ^ [ rA , ι ⁰ ] ⊢ B ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ Id (U ⁰) ℕ (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) ⇒ Empty ¹ ∷ SProp ¹ ^ next ¹\n Id-U-Πℕ : ∀ {A rA B}\n → Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ]\n → Γ ∙ A ^ [ rA , ι ⁰ ] ⊢ B ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) ℕ ⇒ Empty ¹ ∷ SProp ¹ ^ next ¹\n Id-U-ΠΠ!% : ∀ {A rA B A' rA' B' }\n → rA PE.≢ rA'\n → Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ]\n → Γ ∙ A ^ [ rA , ι ⁰ ] ⊢ B ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ A' ∷ Univ rA' ⁰ ^ [ ! , next ⁰ ]\n → Γ ∙ A' ^ [ rA' , ι ⁰ ] ⊢ B' ∷ U ⁰ ^ [ ! , next ⁰ ]\n → Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) (Π A' ^ rA' ° ⁰ ▹ B' ° ⁰ ° ⁰) ⇒ Empty ¹ ∷ SProp ¹ ^ next ¹\n cast-subst : ∀ {A A' B e t} → let l = ⁰ in\n Γ ⊢ A ⇒ A' ∷ U l ^ next l\n → Γ ⊢ B ∷ U l ^ [ ! , next l ]\n → Γ ⊢ e ∷ Id (U l) A B ^ [ % , next l ]\n → Γ ⊢ t ∷ A ^ [ ! , ι l ]\n → Γ ⊢ cast l A B e t ⇒ cast l A' B e t ∷ B ^ ι l\n cast-ℕ-subst : ∀ {B B' e t}\n → Γ ⊢ B ⇒ B' ∷ U ⁰ ^ next ⁰\n → Γ ⊢ e ∷ Id (U ⁰) ℕ B ^ [ % , next ⁰ ]\n → Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ cast ⁰ ℕ B e t ⇒ cast ⁰ ℕ B' e t ∷ B ^ ι ⁰\n cast-Π-subst : ∀ {A rA P B B' e t} → let l = ⁰ in let lA = ⁰ in let lP = ⁰ in\n Γ ⊢ A ∷ (Univ rA lA) ^ [ ! , next lA ]\n → Γ ∙ A ^ [ rA , ι lA ] ⊢ P ∷ U lP ^ [ ! , next lA ]\n → Γ ⊢ B ⇒ B' ∷ U l ^ next l\n → Γ ⊢ e ∷ Id (U l) (Π A ^ rA ° lA ▹ P ° lP ° l) B ^ [ % , next l ]\n → Γ ⊢ t ∷ (Π A ^ rA ° lA ▹ P ° lP ° l) ^ [ ! , ι l ]\n → Γ ⊢ cast l (Π A ^ rA ° lA ▹ P ° lP ° l) B e t ⇒ cast l (Π A ^ rA ° lA ▹ P ° lP ° l) B' e t ∷ B ^ ι l\n cast-Π : ∀ {A A' rA B B' e f} → let l = ⁰ in\n Γ ⊢ A ∷ (Univ rA l) ^ [ ! , next l ]\n → Γ ∙ A ^ [ rA , ι l ] ⊢ B ∷ U l ^ [ ! , next l ]\n → Γ ⊢ A' ∷ (Univ rA l) ^ [ ! , next l ]\n → Γ ∙ A' ^ [ rA , ι l ] ⊢ B' ∷ U l ^ [ ! , next l ]\n → Γ ⊢ e ∷ Id (U l) (Π A ^ rA ° l ▹ B ° l ° l) (Π A' ^ rA ° l ▹ B' ° l ° l) ^ [ % , next l ]\n → Γ ⊢ f ∷ (Π A ^ rA ° l ▹ B ° l ° l) ^ [ ! , ι l ]\n → Γ ⊢ (cast l (Π A ^ rA ° l ▹ B ° l ° l) (Π A' ^ rA ° l ▹ B' ° l ° l) e f)\n ⇒ (lam A' ▹\n (let a = cast l (wk1 A') (wk1 A) (Idsym (Univ rA l) (wk1 A) (wk1 A') (fst (wk1 e))) (var 0)\n in cast l (B [ a ]↑) B' ((snd (wk1 e)) ∘ (var 0) ^ ¹) ((wk1 f) ∘ a ^ l))\n ^ l )\n ∷ Π A' ^ rA ° l ▹ B' ° l ° l ^ ι l\n cast-ℕ-0 : ∀ {e}\n → Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ]\n → Γ ⊢ cast ⁰ ℕ ℕ e zero\n ⇒ zero\n ∷ ℕ ^ ι ⁰\n cast-ℕ-S : ∀ {e n}\n → Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ]\n → Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]\n → Γ ⊢ cast ⁰ ℕ ℕ e (suc n)\n ⇒ suc (cast ⁰ ℕ ℕ e n)\n ∷ ℕ ^ ι ⁰\n\n cast-ℕ-cong : ∀ {e t u}\n → Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ]\n → Γ ⊢ t ⇒ u ∷ ℕ ^ ι ⁰\n → Γ ⊢ cast ⁰ ℕ ℕ e t\n ⇒ cast ⁰ ℕ ℕ e u\n ∷ ℕ ^ ι ⁰\n\n -- Type reduction\n data _⊢_⇒_^_ (Γ : Con Term) : Term → Term → TypeInfo → Set where\n univ : ∀ {A B r l}\n → Γ ⊢ A ⇒ B ∷ (Univ r l) ^ next l\n → Γ ⊢ A ⇒ B ^ [ r , ι l ]\n\n-- Term reduction closure\ndata _⊢_⇒*_∷_^_ (Γ : Con Term) : Term → Term → Term → TypeLevel → Set where\n id : ∀ {A l t}\n → Γ ⊢ t ∷ A ^ [ ! , l ]\n → Γ ⊢ t ⇒* t ∷ A ^ l\n _⇨_ : ∀ {A l t t′ u}\n → Γ ⊢ t ⇒ t′ ∷ A ^ l\n → Γ ⊢ t′ ⇒* u ∷ A ^ l\n → Γ ⊢ t ⇒* u ∷ A ^ l\n\n-- Type reduction closure\ndata _⊢_⇒*_^_ (Γ : Con Term) : Term → Term → TypeInfo → Set where\n id : ∀ {A r}\n → Γ ⊢ A ^ r\n → Γ ⊢ A ⇒* A ^ r\n _⇨_ : ∀ {A A′ B r}\n → Γ ⊢ A ⇒ A′ ^ r\n → Γ ⊢ A′ ⇒* B ^ r\n → Γ ⊢ A ⇒* B ^ r\n\n-- Type reduction to whnf\n_⊢_↘_^_ : (Γ : Con Term) → Term → Term → TypeInfo → Set\nΓ ⊢ A ↘ B ^ r = Γ ⊢ A ⇒* B ^ r × Whnf B\n\n-- Term reduction to whnf\n_⊢_↘_∷_^_ : (Γ : Con Term) → Term → Term → Term → TypeLevel → Set\nΓ ⊢ t ↘ u ∷ A ^ l = Γ ⊢ t ⇒* u ∷ A ^ l × Whnf u\n\n-- Type equality with well-formed types\n_⊢_:≡:_^_ : (Γ : Con Term) → Term → Term → TypeInfo → Set\nΓ ⊢ A :≡: B ^ r = Γ ⊢ A ^ r × Γ ⊢ B ^ r × (Γ ⊢ A ≡ B ^ r)\n\n-- Term equality with well-formed terms\n_⊢_:≡:_∷_^_ : (Γ : Con Term) → Term → Term → Term → TypeInfo → Set\nΓ ⊢ t :≡: u ∷ A ^ r = Γ ⊢ t ∷ A ^ r × Γ ⊢ u ∷ A ^ r × (Γ ⊢ t ≡ u ∷ A ^ r)\n\n-- Type reduction closure with well-formed types\nrecord _⊢_:⇒*:_^_ (Γ : Con Term) (A B : Term) (r : TypeInfo) : Set where\n constructor [[_,_,_]]\n field\n ⊢A : Γ ⊢ A ^ r\n ⊢B : Γ ⊢ B ^ r\n D : Γ ⊢ A ⇒* B ^ r\n\nopen _⊢_:⇒*:_^_ using () renaming (D to red) public\n\n-- Term reduction closure with well-formed terms\nrecord _⊢_:⇒*:_∷_^_ (Γ : Con Term) (t u A : Term) (l : TypeLevel) : Set where\n constructor [[_,_,_]]\n field\n ⊢t : Γ ⊢ t ∷ A ^ [ ! , l ]\n ⊢u : Γ ⊢ u ∷ A ^ [ ! , l ]\n d : Γ ⊢ t ⇒* u ∷ A ^ l\n\nopen _⊢_:⇒*:_∷_^_ using () renaming (d to redₜ) public\n\n-- Well-formed substitutions.\ndata _⊢ˢ_∷_ (Δ : Con Term) (σ : Subst) : (Γ : Con Term) → Set where\n id : Δ ⊢ˢ σ ∷ ε\n _,_ : ∀ {Γ A rA}\n → Δ ⊢ˢ tail σ ∷ Γ\n → Δ ⊢ head σ ∷ subst (tail σ) A ^ rA\n → Δ ⊢ˢ σ ∷ Γ ∙ A ^ rA\n\n-- Conversion of well-formed substitutions.\ndata _⊢ˢ_≡_∷_ (Δ : Con Term) (σ σ′ : Subst) : (Γ : Con Term) → Set where\n id : Δ ⊢ˢ σ ≡ σ′ ∷ ε\n _,_ : ∀ {Γ A rA}\n → Δ ⊢ˢ tail σ ≡ tail σ′ ∷ Γ\n → Δ ⊢ head σ ≡ head σ′ ∷ subst (tail σ) A ^ rA\n → Δ ⊢ˢ σ ≡ σ′ ∷ Γ ∙ A ^ rA\n\n-- Note that we cannot use the well-formed substitutions.\n-- For that, we need to prove the fundamental theorem for substitutions.\n\n-- Some derivable rules\nUnitⱼ : ∀ {Γ l} (⊢Γ : ⊢ Γ)\n → Γ ⊢ Unit ∷ SProp l ^ [ ! , next l ]\nUnitⱼ ⊢Γ = Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ Emptyⱼ ⊢Γ ▹ Emptyⱼ (⊢Γ ∙ univ (Emptyⱼ ⊢Γ))\n\ntypeUnit : ∀ {l} → Type (Unit {l})\ntypeUnit = Πₙ\n\nUgenⱼ : ∀ {r Γ l} → ⊢ Γ → Γ ⊢ Univ r l ^ [ ! , next l ]\nUgenⱼ {l = ⁰} ⊢Γ = univ (univ 0<1 ⊢Γ)\nUgenⱼ {l = ¹} ⊢Γ = Uⱼ ⊢Γ\n", "meta": {"hexsha": "9e3d8832db62e4752b0befc79ac958ab425b0559", "size": 26343, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Typed.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/Typed.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/Typed.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": 44.8773424191, "max_line_length": 155, "alphanum_fraction": 0.2900201192, "num_tokens": 12312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3918847705884498}} {"text": "{-# OPTIONS --cubical --safe #-}\nmodule Cubical.HITs.Hopf where\n\nopen import Cubical.Core.Glue\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Isomorphism\n\nopen import Cubical.Data.Int\nopen import Cubical.Data.Prod\n\nopen import Cubical.HITs.S1\nopen import Cubical.HITs.S2\nopen import Cubical.HITs.S3\nopen import Cubical.HITs.Susp\nopen import Cubical.HITs.Join\nopen import Cubical.HITs.Interval\n renaming ( zero to I0 ; one to I1 )\n\nBorder : (x : S¹) → (j : I) → Partial (j ∨ ~ j) (Σ Type₀ (λ T → T ≃ S¹))\nBorder x j (j = i0) = S¹ , rot x , rotIsEquiv x\nBorder x j (j = i1) = S¹ , idEquiv S¹\n\n-- Hopf fibration using SuspS¹\nHopfSuspS¹ : SuspS¹ → Type₀\nHopfSuspS¹ north = S¹\nHopfSuspS¹ south = S¹\nHopfSuspS¹ (merid x j) = Glue S¹ (Border x j)\n\n-- Hopf fibration using S²\n-- TODO : prove that it is equivalent to HopfSuspS¹\nHopfS² : S² → Type₀\nHopfS² base = S¹\nHopfS² (surf i j) = Glue S¹ (λ { (i = i0) → _ , idEquiv S¹\n ; (i = i1) → _ , idEquiv S¹\n ; (j = i0) → _ , idEquiv S¹\n ; (j = i1) → _ , _ , rotIsEquiv (loop i) } )\n\n-- Hopf fibration using more direct definition of the rot equivalence\n-- TODO : prove that it is equivalent to HopfSuspS¹\nHopfS²' : S² → Type₀\nHopfS²' base = S¹\nHopfS²' (surf i j) = Glue S¹ (λ { (i = i0) → _ , rotLoopEquiv i0\n ; (i = i1) → _ , rotLoopEquiv i0\n ; (j = i0) → _ , rotLoopEquiv i0\n ; (j = i1) → _ , rotLoopEquiv i } )\n\n-- Total space of the fibration\nTotalHopf : Type₀\nTotalHopf = Σ SuspS¹ HopfSuspS¹\n\n-- Forward direction\nfiller-1 : I → (j : I) → (y : S¹) → Glue S¹ (Border y j) → join S¹ S¹\nfiller-1 i j y x = hfill (λ t → λ { (j = i0) → inl (rotInv-1 x y t)\n ; (j = i1) → inr x })\n (inS (push ((unglue (j ∨ ~ j) x) * inv y) (unglue (j ∨ ~ j) x) j)) i\n\nTotalHopf→JoinS¹S¹ : TotalHopf → join S¹ S¹\nTotalHopf→JoinS¹S¹ (north , x) = inl x\nTotalHopf→JoinS¹S¹ (south , x) = inr x\nTotalHopf→JoinS¹S¹ (merid y j , x) = filler-1 i1 j y x\n\n-- Backward direction\nJoinS¹S¹→TotalHopf : join S¹ S¹ → TotalHopf\nJoinS¹S¹→TotalHopf (inl x) = (north , x)\nJoinS¹S¹→TotalHopf (inr x) = (south , x)\nJoinS¹S¹→TotalHopf (push y x j) =\n (merid (inv y * x) j\n , glue (λ { (j = i0) → y ; (j = i1) → x }) (rotInv-2 x y j))\n\n-- Now for the homotopies, we will need to fill squares indexed by x y : S¹ with value in S¹\n-- Some will be extremeley tough, but happen to be easy when x = y = base\n-- therefore, we fill them for x = y = base and then use the connectedness of S¹ × S¹ and\n-- the discreteness of ΩS¹ to get general fillers.\n\n-- To proceed with that strategy, we first need a lemma :\n-- the sections of the trivial fibration λ (_ : S¹) (_ : S¹) → Int are constant\n\n-- this should be generalized to a constant fibration over a connected space with\n-- discrete fiber\nfibInt : S¹ → S¹ → Type₀\nfibInt _ _ = Int\n\nS¹→HSet : (A : Type₀) (p : isSet A) (F : S¹ → A) (x : S¹) → F base ≡ F x\nS¹→HSet A p F base = refl {x = F base}\nS¹→HSet A p F (loop i) = f' i\n where\n f : PathP (λ i → F base ≡ F (loop i)) refl (cong F loop)\n f i = λ j → F (loop (i ∧ j))\n L : cong F loop ≡ refl\n L = p (F base) (F base) (f i1) refl\n f' : PathP (λ i → F base ≡ F (loop i)) (refl {x = F base}) (refl {x = F base})\n f' = transport (λ i → PathP (λ j → F base ≡ F (loop j)) refl (L i)) f\n\nconstant-loop : (F : S¹ → S¹ → Int) → (x y : S¹) → F base base ≡ F x y\nconstant-loop F x y = L0 ∙ L1\n where\n p : isSet (S¹ → Int)\n p = hLevelPi 2 (λ _ → isSetInt)\n L : F base ≡ F x\n L = S¹→HSet (S¹ → Int) p F x\n L0 : F base base ≡ F x base\n L0 i = L i base\n L1 : F x base ≡ F x y\n L1 = S¹→HSet Int isSetInt (F x) y\n\ndiscretefib : (F : S¹ → S¹ → Type₀) → Type₀\ndiscretefib F = (a : (x y : S¹) → F x y) →\n (b : (x y : S¹) → F x y) →\n (a base base ≡ b base base) →\n (x y : S¹) → a x y ≡ b x y\n\ndiscretefib-fibInt : discretefib fibInt\ndiscretefib-fibInt a b h x y i =\n hcomp (λ t → λ { (i = i0) → constant-loop a x y t\n ; (i = i1) → constant-loop b x y t })\n (h i)\n\n-- first homotopy\n\nassocFiller-3-aux : I → I → I → I → S¹\nassocFiller-3-aux x y j i =\n hfill (λ t → λ { (i = i0) → rotInv-1 (loop y) (loop (~ y) * loop x) t\n ; (i = i1) → rotInv-3 (loop y) (loop x) t\n ; (x = i0) (y = i0) → base\n ; (x = i0) (y = i1) → base\n ; (x = i1) (y = i0) → base\n ; (x = i1) (y = i1) → base })\n (inS ((rotInv-2 (loop x) (loop y) i) * (inv (loop (~ y) * loop x)))) j\n\n-- assocFiller-3-endpoint is used only in the type of the next function, to specify the\n-- second endpoint.\n-- However, I only need the first endpoint, but I cannot specify only one of them as is.\n-- TODO : use cubical extension types when available to remove assocFiller-3-endpoint\nassocFiller-3-endpoint : (x : S¹) → (y : S¹) → y ≡ y\nassocFiller-3-endpoint base base i = base\nassocFiller-3-endpoint (loop x) base i = assocFiller-3-aux x i0 i1 i\nassocFiller-3-endpoint base (loop y) i = assocFiller-3-aux i0 y i1 i\nassocFiller-3-endpoint (loop x) (loop y) i = assocFiller-3-aux x y i1 i\n\nassocFiller-3 : (x : S¹) → (y : S¹) →\n PathP (λ j → rotInv-1 y (inv y * x) j ≡ rotInv-3 y x j)\n (λ i → ((rotInv-2 x y i) * (inv (inv y * x))))\n (assocFiller-3-endpoint x y)\nassocFiller-3 base base j i = base\nassocFiller-3 (loop x) base j i = assocFiller-3-aux x i0 j i\nassocFiller-3 base (loop y) j i = assocFiller-3-aux i0 y j i\nassocFiller-3 (loop x) (loop y) j i = assocFiller-3-aux x y j i\n\nassoc-3 : (_ y : S¹) → basedΩS¹ y\nassoc-3 x y i = assocFiller-3 x y i1 i\n\nfibInt≡fibAssoc-3 : fibInt ≡ (λ _ y → basedΩS¹ y)\nfibInt≡fibAssoc-3 i = λ x y → basedΩS¹≡Int y (~ i)\n\ndiscretefib-fibAssoc-3 : discretefib (λ _ y → basedΩS¹ y)\ndiscretefib-fibAssoc-3 =\n transp (λ i → discretefib (fibInt≡fibAssoc-3 i)) i0 discretefib-fibInt\n\nassocConst-3 : (x y : S¹) → assoc-3 x y ≡ refl\nassocConst-3 x y = discretefib-fibAssoc-3 assoc-3 (λ _ _ → refl) refl x y\n\nassocSquare-3 : I → I → S¹ → S¹ → S¹\nassocSquare-3 i j x y = hcomp (λ t → λ { (i = i0) → assocFiller-3 x y j i0\n ; (i = i1) → assocFiller-3 x y j i1\n ; (j = i0) → assocFiller-3 x y i0 i\n ; (j = i1) → assocConst-3 x y t i })\n (assocFiller-3 x y j i)\n\nfiller-3 : I → I → S¹ → S¹ → join S¹ S¹\nfiller-3 i j y x =\n hcomp (λ t → λ { (i = i0) → filler-1 t j (inv y * x)\n (glue (λ { (j = i0) → y ; (j = i1) → x })\n (rotInv-2 x y j))\n ; (i = i1) → push (rotInv-3 y x t) x j\n ; (j = i0) → inl (assocSquare-3 i t x y)\n ; (j = i1) → inr x })\n (push ((rotInv-2 x y (i ∨ j)) * (inv (inv y * x))) (rotInv-2 x y (i ∨ j)) j)\n\nJoinS¹S¹→TotalHopf→JoinS¹S¹ : ∀ x → TotalHopf→JoinS¹S¹ (JoinS¹S¹→TotalHopf x) ≡ x\nJoinS¹S¹→TotalHopf→JoinS¹S¹ (inl x) i = inl x\nJoinS¹S¹→TotalHopf→JoinS¹S¹ (inr x) i = inr x\nJoinS¹S¹→TotalHopf→JoinS¹S¹ (push y x j) i = filler-3 i j y x\n\n-- Second homotopy\n\n-- This HIT is the total space of the Hopf fibration but the ends of SuspS¹ have not been\n-- glued together yet — which makes it into a cylinder.\n-- This allows to write compositions that do not properly match at the endpoints. However,\n-- I suspect it is unnecessary. TODO : do without PseudoHopf\n\nPseudoHopf : Type₀\nPseudoHopf = (S¹ × Interval) × S¹\n\nPseudoHopf-π1 : PseudoHopf → S¹\nPseudoHopf-π1 ((y , _) , _) = y\n\nPseudoHopf-π2 : PseudoHopf → S¹\nPseudoHopf-π2 (_ , x) = x\n\nassocFiller-4-aux : I → I → I → I → S¹\nassocFiller-4-aux x y j i =\n hfill (λ t → λ { (i = i0) → ((inv (loop y * loop x * loop (~ y))) * (loop y * loop x))\n * (rotInv-1 (loop x) (loop y) t)\n ; (i = i1) → (rotInv-4 (loop y) (loop y * loop x) (~ t)) * loop x\n ; (x = i0) (y = i0) → base\n ; (x = i0) (y = i1) → base\n ; (x = i1) (y = i0) → base\n ; (x = i1) (y = i1) → base })\n (inS (rotInv-2 (loop y * loop x) (loop y * loop x * loop (~ y)) i)) j\n\n-- See assocFiller-3-endpoint\n-- TODO : use cubical extension types when available to remove assocFiller-4-endpoint\nassocFiller-4-endpoint : (x y : S¹) → basedΩS¹ (((inv (y * x * inv y)) * (y * x)) * x)\nassocFiller-4-endpoint base base i = base\nassocFiller-4-endpoint (loop x) base i = assocFiller-4-aux x i0 i1 i\nassocFiller-4-endpoint base (loop y) i = assocFiller-4-aux i0 y i1 i\nassocFiller-4-endpoint (loop x) (loop y) i = assocFiller-4-aux x y i1 i\n\nassocFiller-4 : (x y : S¹) →\n PathP (λ j → ((inv (y * x * inv y)) * (y * x)) * (rotInv-1 x y j) ≡ (rotInv-4 y (y * x) (~ j)) * x)\n (λ i → (rotInv-2 (y * x) (y * x * inv y) i))\n (assocFiller-4-endpoint x y)\nassocFiller-4 base base j i = base\nassocFiller-4 (loop x) base j i = assocFiller-4-aux x i0 j i\nassocFiller-4 base (loop y) j i = assocFiller-4-aux i0 y j i\nassocFiller-4 (loop x) (loop y) j i = assocFiller-4-aux x y j i\n\nassoc-4 : (x y : S¹) → basedΩS¹ (((inv (y * x * inv y)) * (y * x)) * x)\nassoc-4 x y i = assocFiller-4 x y i1 i\n\nfibInt≡fibAssoc-4 : fibInt ≡ (λ x y → basedΩS¹ (((inv (y * x * inv y)) * (y * x)) * x))\nfibInt≡fibAssoc-4 i = λ x y → basedΩS¹≡Int (((inv (y * x * inv y)) * (y * x)) * x) (~ i)\n\ndiscretefib-fibAssoc-4 : discretefib (λ x y → basedΩS¹ (((inv (y * x * inv y)) * (y * x)) * x))\ndiscretefib-fibAssoc-4 =\n transp (λ i → discretefib (fibInt≡fibAssoc-4 i)) i0 discretefib-fibInt\n\nassocConst-4 : (x y : S¹) → assoc-4 x y ≡ refl\nassocConst-4 x y = discretefib-fibAssoc-4 assoc-4 (λ _ _ → refl) refl x y\n\nassocSquare-4 : I → I → S¹ → S¹ → S¹\nassocSquare-4 i j x y =\n hcomp (λ t → λ { (i = i0) → assocFiller-4 x y j i0\n ; (i = i1) → assocFiller-4 x y j i1\n ; (j = i0) → assocFiller-4 x y i0 i\n ; (j = i1) → assocConst-4 x y t i })\n (assocFiller-4 x y j i)\n\nfiller-4-0 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → PseudoHopf\nfiller-4-0 i j y x =\n let x' = unglue (j ∨ ~ j) x in\n hfill (λ t → λ { (j = i0) → ((inv (y * x * inv y) * (y * x) , I0)\n , inv (y * x * inv y) * (y * x) * (rotInv-1 x y t))\n ; (j = i1) → ((inv (x * inv y) * x , I1) , x) })\n (inS ((inv (x' * inv y) * x' , seg j) , rotInv-2 x' (x' * inv y) j)) i\n\nfiller-4-1 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → PseudoHopf\nfiller-4-1 i j y x =\n let x' = unglue (j ∨ ~ j) x in\n hfill (λ t → λ { (j = i0) → ((inv (y * x * inv y) * (y * x) , I0)\n , (rotInv-4 y (y * x) (~ t)) * x)\n ; (j = i1) → ((inv (x * inv y) * x , I1) , x) })\n (inS ((inv (x' * inv y) * x' , seg j) , unglue (j ∨ ~ j) x)) i\n\nfiller-4-2 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → TotalHopf\nfiller-4-2 i j y x =\n let x' = unglue (j ∨ ~ j) x in\n hcomp (λ t → λ { (i = i0) → JoinS¹S¹→TotalHopf (filler-1 t j y x)\n ; (i = i1) → (merid (PseudoHopf-π1 (filler-4-0 t j y x)) j\n , glue (λ { (j = i0) → rotInv-1 x y t ; (j = i1) → x })\n (PseudoHopf-π2 (filler-4-0 t j y x)))\n ; (j = i0) → (north , rotInv-1 x y t)\n ; (j = i1) → (south , x) })\n (merid (inv (x' * inv y) * x') j\n , glue (λ { (j = i0) → y * x * inv y ; (j = i1) → x }) (rotInv-2 x' (x' * inv y) j))\n\nfiller-4-3 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → PseudoHopf\nfiller-4-3 i j y x =\n let x' = unglue (j ∨ ~ j) x in\n hcomp (λ t → λ { (i = i0) → filler-4-0 t j y x\n ; (i = i1) → filler-4-1 t j y x\n ; (j = i0) → ((inv (y * x * inv y) * (y * x) , I0) , assocSquare-4 i t x y)\n ; (j = i1) → ((inv (x * inv y) * x , I1) , x) })\n ((inv (x' * inv y) * x' , seg j) , rotInv-2 x' (x' * inv y) (i ∨ j))\n\nfiller-4-4 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → PseudoHopf\nfiller-4-4 i j y x =\n let x' = unglue (j ∨ ~ j) x in\n hcomp (λ t → λ { (i = i0) → filler-4-1 t j y x\n ; (i = i1) → ((y , seg j) , unglue (j ∨ ~ j) x)\n ; (j = i0) → ((rotInv-4 y (y * x) i , I0)\n , (rotInv-4 y (y * x) (i ∨ ~ t)) * x)\n ; (j = i1) → ((rotInv-4 y x i , I1) , x) })\n ((rotInv-4 y x' i , seg j) , x')\n\nfiller-4-5 : (_ j : I) → (y : S¹) → Glue S¹ (Border y j) → TotalHopf\nfiller-4-5 i j y x =\n hcomp (λ t → λ { (i = i0) → filler-4-2 (~ t) j y x\n ; (i = i1) → (merid (PseudoHopf-π1 (filler-4-4 t j y x)) j\n , glue (λ { (j = i0) → x ; (j = i1) → x })\n (PseudoHopf-π2 (filler-4-4 t j y x)))\n ; (j = i0) → (north , x)\n ; (j = i1) → (south , x) })\n (merid (PseudoHopf-π1 (filler-4-3 i j y x)) j\n , glue (λ { (j = i0) → x ; (j = i1) → x }) (PseudoHopf-π2 (filler-4-3 i j y x)))\n\nTotalHopf→JoinS¹S¹→TotalHopf : ∀ x → JoinS¹S¹→TotalHopf (TotalHopf→JoinS¹S¹ x) ≡ x\nTotalHopf→JoinS¹S¹→TotalHopf (north , x) i = (north , x)\nTotalHopf→JoinS¹S¹→TotalHopf (south , x) i = (south , x)\nTotalHopf→JoinS¹S¹→TotalHopf (merid y j , x) i = filler-4-5 i j y x\n\n\nJoinS¹S¹≡TotalHopf : join S¹ S¹ ≡ TotalHopf\nJoinS¹S¹≡TotalHopf = isoToPath (iso JoinS¹S¹→TotalHopf\n TotalHopf→JoinS¹S¹\n TotalHopf→JoinS¹S¹→TotalHopf\n JoinS¹S¹→TotalHopf→JoinS¹S¹)\n\nS³≡TotalHopf : S³ ≡ TotalHopf\nS³≡TotalHopf = S³≡joinS¹S¹ ∙ JoinS¹S¹≡TotalHopf\n", "meta": {"hexsha": "389c5d9288523a6f6e9c8a244ad54f8b6d6ce5be", "size": 13894, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/HITs/Hopf.agda", "max_stars_repo_name": "cj-xu/cubical", "max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "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": "Cubical/HITs/Hopf.agda", "max_issues_repo_name": "cj-xu/cubical", "max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "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": "Cubical/HITs/Hopf.agda", "max_forks_repo_name": "cj-xu/cubical", "max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "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.8827160494, "max_line_length": 115, "alphanum_fraction": 0.5230315244, "num_tokens": 5557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.3918530455441487}} {"text": "open import Data.Product using ( ∃ ; _×_ ; _,_ ; proj₁ ; proj₂ )\nopen import Relation.Unary using ( _∈_ )\nopen import Web.Semantic.DL.ABox using ( ABox )\nopen import Web.Semantic.DL.ABox.Model using ( _⊨a_ ; _⊨b_ ; ⊨a-resp-≲ ; ⊨b-resp-≲ )\nopen import Web.Semantic.DL.ABox.Interp using ( Interp ; ⌊_⌋ ; _*_ )\nopen import Web.Semantic.DL.ABox.Interp.Morphism using ( _≲_ ; ≲-refl )\nopen import Web.Semantic.DL.KB using ( _,_ )\nopen import Web.Semantic.DL.KB.Model using ( _⊨_ )\nopen import Web.Semantic.DL.Integrity using ( Initial ; _⊕_⊨_ ; extension ; ext-init ; ext-⊨ ; ext✓ ; init-≲ ; init-⊨ ; init-med ; med-≲ )\nopen import Web.Semantic.DL.Signature using ( Signature )\nopen import Web.Semantic.DL.TBox using ( TBox ; _,_ )\nopen import Web.Semantic.DL.TBox.Model using ( _⊨t_ )\nopen import Web.Semantic.DL.Category.Object using ( Object ; _,_ ; IN ; iface )\nopen import Web.Semantic.Util using ( _⊕_⊕_ ; inode ; enode )\n\nmodule Web.Semantic.DL.Category.Morphism {Σ : Signature} {S T : TBox Σ} where\n\ninfixr 4 _,_\n\n-- A morphism A ⇒ B is an abox F such that for every I ⊨ S , T , A\n-- there is a J which is the initial extension of I satisfying (S , F),\n-- and moreover J satisfies (T , B).\n\ndata _⇒_w/_ (A B : Object S T) (V : Set) : Set₁ where\n _,_ : (F : ABox Σ (IN A ⊕ V ⊕ IN B)) →\n (∀ I → (I ⊨ (S , T) , iface A) → (I ⊕ (S , F) ⊨ (T , iface B))) →\n (A ⇒ B w/ V)\n\ndata _⇒_ (A B : Object S T) : Set₁ where\n _,_ : ∀ V → (A ⇒ B w/ V) → (A ⇒ B)\n\nBN : ∀ {A B} → (F : A ⇒ B) → Set\nBN (V , F,F✓) = V\n\nimpl : ∀ {A B} → (F : A ⇒ B) → ABox Σ (IN A ⊕ BN F ⊕ IN B)\nimpl (V , F , F✓) = F\n\nimpl✓ : ∀ {A B} → (F : A ⇒ B) → ∀ I → (I ⊨ (S , T) , iface A) → (I ⊕ (S , impl F) ⊨ (T , iface B))\nimpl✓ (V , F , F✓) = F✓\n\napply : ∀ {A B} (F : A ⇒ B) I → (I ⊨ (S , T) , iface A) → \n Interp Σ (IN A ⊕ BN F ⊕ IN B)\napply F I I⊨STA = extension (impl✓ F I I⊨STA)\n\napply-init : ∀ {A B} (F : A ⇒ B) I I⊨STA →\n (apply F I I⊨STA ∈ Initial I (S , impl F))\napply-init F I I⊨STA = ext-init (impl✓ F I I⊨STA)\n\napply-⊨ : ∀ {A B} (F : A ⇒ B) I I⊨STA →\n (enode * (apply F I I⊨STA) ⊨ (T , iface B))\napply-⊨ F I I⊨STA = ext-⊨ (impl✓ F I I⊨STA)\n\napply-≲ : ∀ {A B} (F : A ⇒ B) I I⊨STA → (I ⊨a impl F) →\n (apply F (inode * I) I⊨STA ≲ I)\napply-≲ F I ((I⊨S , I⊨T) , I⊨A) I⊨F = \n med-≲ (init-med \n (apply-init F (inode * I) ((I⊨S , I⊨T) , I⊨A)) \n I \n (≲-refl (inode * I)) \n (I⊨S , I⊨F))\n\napply✓ : ∀ {A B} (F : A ⇒ B) I I⊨STA →\n (enode * apply F I I⊨STA ⊨ (S , T) , iface B)\napply✓ F I I⊨STA = ext✓ (impl✓ F I I⊨STA)\n\n-- Morphisms F and G are equivalent whenever\n-- in any interpretation I ⊨ S,T\n-- we have I ⊨ F iff I ⊨ G.\n\ninfix 2 _⊑_ _⊑′_ _≣_\n\n_⊑_ : ∀ {A B : Object S T} → (A ⇒ B) → (A ⇒ B) → Set₁\n_⊑_ {A} F G = \n ∀ I → (inode * I ⊨ (S , T) , iface A) → (I ⊨a impl F) → (I ⊨b impl G)\n\ndata _≣_ {A B : Object S T} (F G : A ⇒ B) : Set₁ where\n _,_ : (F ⊑ G) → (G ⊑ F) → (F ≣ G)\n\n-- An alternative characterization, which may be easier\n-- to work with.\n\n_⊑′_ : ∀ {A B : Object S T} → (A ⇒ B) → (A ⇒ B) → Set₁\nF ⊑′ G = ∀ I I⊨STA → (apply F I I⊨STA) ⊨b (impl G)\n \n⊑′-impl-⊑ : ∀ {A B : Object S T} → (F G : A ⇒ B) → (F ⊑′ G) → (F ⊑ G)\n⊑′-impl-⊑ F G F⊑′G I I⊨STA I⊨F = \n ⊨b-resp-≲ (apply-≲ F I I⊨STA I⊨F) (impl G) (F⊑′G (inode * I) I⊨STA)\n\n⊑-impl-⊑′ : ∀ {A B : Object S T} → (F G : A ⇒ B) → (F ⊑ G) → (F ⊑′ G)\n⊑-impl-⊑′ {A} {B} F G F⊑G I (I⊨ST , I⊨A) = J⊨G where\n\n J : Interp Σ (IN A ⊕ BN F ⊕ IN B)\n J = apply F I (I⊨ST , I⊨A)\n\n J⊨S : ⌊ J ⌋ ⊨t S\n J⊨S = proj₁ (init-⊨ (apply-init F I (I⊨ST , I⊨A)))\n\n J⊨T : ⌊ J ⌋ ⊨t T\n J⊨T = proj₁ (apply-⊨ F I (I⊨ST , I⊨A))\n\n J⊨A : inode * J ⊨a iface A\n J⊨A = ⊨a-resp-≲ (init-≲ (apply-init F I (I⊨ST , I⊨A))) (iface A) I⊨A\n\n J⊨F : J ⊨a impl F\n J⊨F = proj₂ (init-⊨ (apply-init F I (I⊨ST , I⊨A)))\n\n J⊨G : J ⊨b impl G\n J⊨G = F⊑G J ((J⊨S , J⊨T) , J⊨A) J⊨F\n\n", "meta": {"hexsha": "0a7809a1d4b0fe2cd701e1484b053c029517c84d", "size": 3784, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Web/Semantic/DL/Category/Morphism.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/Category/Morphism.agda", "max_issues_repo_name": "bblfish/agda-web-semantic", "max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "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/Category/Morphism.agda", "max_forks_repo_name": "bblfish/agda-web-semantic", "max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "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": 34.4, "max_line_length": 138, "alphanum_fraction": 0.5179704017, "num_tokens": 1928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.39180788657816473}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule Pif where\n\nopen import Relation.Binary.PropositionalEquality \n using (_≡_; refl; sym; trans; subst; subst₂; cong; cong₂; setoid; \n proof-irrelevance; module ≡-Reasoning)\nopen import Data.Nat.Properties using (m≢1+m+n; i+j≡0⇒i≡0; i+j≡0⇒j≡0)\nopen import Data.Nat.Properties.Simple \n using (+-right-identity; +-suc; +-assoc; +-comm; \n *-assoc; *-comm; *-right-zero; distribʳ-*-+)\nopen import Relation.Binary.Core using (Transitive)\n\nopen import Data.String using (String)\n renaming (_++_ to _++S_)\nopen import Data.Nat.Show using (show)\nopen import Data.Bool using (Bool; false; true; _∧_; _∨_)\nopen import Data.Nat using (ℕ; suc; _+_; _∸_; _*_; _<_; _≮_; _≤_; _≰_; \n z≤n; s≤s; _≟_; _≤?_; module ≤-Reasoning)\nopen import Data.Fin \n using (Fin; zero; suc; toℕ; fromℕ; _ℕ-_; _≺_;\n raise; inject+; inject₁; inject≤; _≻toℕ_) \n renaming (_+_ to _F+_)\n\nopen import Data.Vec \n using (Vec; tabulate; []; _∷_ ; tail; lookup; zip; zipWith; splitAt;\n _[_]≔_; allFin; toList)\n renaming (_++_ to _++V_; map to mapV; concat to concatV)\n\nopen import Data.Empty using (⊥; ⊥-elim)\nopen import Data.Unit using (⊤; tt)\nopen import Data.Sum using (_⊎_; inj₁; inj₂)\nopen import Data.Product using (_×_; _,_; proj₁; proj₂)\n\nopen import PiLevel0\nopen import Cauchy\nopen import Perm\nopen import Proofs\nopen import CauchyProofs\nopen import CauchyProofsT\nopen import CauchyProofsS\nopen import Groupoid\n\n------------------------------------------------------------------------------\n-- A combinator t₁ ⟷ t₂ denotes a permutation.\n\nc2cauchy : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → Cauchy (size t₁)\n-- the cases that do not inspect t₁ and t₂ should be at the beginning\n-- so that Agda would unfold them\nc2cauchy (c₁ ◎ c₂) = \n scompcauchy \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) (c2cauchy c₂)) \nc2cauchy (c₁ ⊕ c₂) = pcompcauchy (c2cauchy c₁) (c2cauchy c₂) \nc2cauchy (c₁ ⊗ c₂) = tcompcauchy (c2cauchy c₁) (c2cauchy c₂) \nc2cauchy {PLUS ZERO t} unite₊ = idcauchy (size t)\nc2cauchy {t} uniti₊ = idcauchy (size t)\nc2cauchy {PLUS t₁ t₂} swap₊ = swap+cauchy (size t₁) (size t₂)\nc2cauchy {PLUS t₁ (PLUS t₂ t₃)} assocl₊ = \n idcauchy (size t₁ + (size t₂ + size t₃))\nc2cauchy {PLUS (PLUS t₁ t₂) t₃} assocr₊ = \n idcauchy ((size t₁ + size t₂) + size t₃)\nc2cauchy {TIMES ONE t} unite⋆ = \n subst Cauchy (sym (+-right-identity (size t))) (idcauchy (size t))\nc2cauchy {t} uniti⋆ = idcauchy (size t)\nc2cauchy {TIMES t₁ t₂} {TIMES .t₂ .t₁} swap⋆ = swap⋆cauchy (size t₁) (size t₂)\nc2cauchy {TIMES t₁ (TIMES t₂ t₃)} assocl⋆ = \n idcauchy (size t₁ * (size t₂ * size t₃))\nc2cauchy {TIMES (TIMES t₁ t₂) t₃} assocr⋆ = \n idcauchy ((size t₁ * size t₂) * size t₃)\nc2cauchy {TIMES ZERO t} distz = []\nc2cauchy factorz = []\nc2cauchy {TIMES (PLUS t₁ t₂) t₃} dist = \n idcauchy ((size t₁ + size t₂) * size t₃)\nc2cauchy {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} factor = \n idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))\nc2cauchy {t} id⟷ = idcauchy (size t)\n\nc2perm : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → Permutation (size t₁)\n-- the cases that do not inspect t₁ and t₂ should be at the beginning\n-- so that Agda would unfold them\nc2perm (c₁ ◎ c₂) = \n scompperm \n (c2perm c₁) \n (subst Permutation (size≡! c₁) (c2perm c₂)) \nc2perm (c₁ ⊕ c₂) = pcompperm (c2perm c₁) (c2perm c₂) \nc2perm (c₁ ⊗ c₂) = tcompperm (c2perm c₁) (c2perm c₂) \nc2perm unfoldBool = idperm 2\nc2perm foldBool = idperm 2\nc2perm {PLUS ZERO t} unite₊ = idperm (size t)\nc2perm {t} uniti₊ = idperm (size t)\nc2perm {PLUS t₁ t₂} swap₊ = swap+perm (size t₁) (size t₂)\nc2perm {PLUS t₁ (PLUS t₂ t₃)} assocl₊ = \n idperm (size t₁ + (size t₂ + size t₃))\nc2perm {PLUS (PLUS t₁ t₂) t₃} assocr₊ = \n idperm ((size t₁ + size t₂) + size t₃)\nc2perm {TIMES ONE t} unite⋆ = \n subst Permutation (sym (+-right-identity (size t))) (idperm (size t))\nc2perm {t} uniti⋆ = idperm (size t)\nc2perm {TIMES t₁ t₂} {TIMES .t₂ .t₁} swap⋆ = swap⋆perm (size t₁) (size t₂) \nc2perm {TIMES t₁ (TIMES t₂ t₃)} assocl⋆ = \n idperm (size t₁ * (size t₂ * size t₃))\nc2perm {TIMES (TIMES t₁ t₂) t₃} assocr⋆ = \n idperm ((size t₁ * size t₂) * size t₃)\nc2perm {TIMES ZERO t} distz = emptyperm\nc2perm factorz = emptyperm\nc2perm {TIMES (PLUS t₁ t₂) t₃} dist = \n idperm ((size t₁ + size t₂) * size t₃)\nc2perm {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} factor = \n idperm ((size t₁ * size t₃) + (size t₂ * size t₃))\nc2perm {t} id⟷ = idperm (size t)\n\n-- Looking forward to Sec. 2.2 (Functions are functors). The\n-- corresponding statement to Lemma 2.2.1 in our setting would be the\n-- following. Given any *size preserving* function f : U → U, it is\n-- the case that a combinator (path) c : t₁ ⟷ t₂ maps to a combinator\n-- (path) ap_f(c) : f(t₁) ⟷ f(t₂).\n\n------------------------------------------------------------------------------\n-- Extensional equivalence of combinators\n\n-- Two combinators are equivalent if they denote the same\n-- permutation. Generally we would require that the two permutations\n-- map the same value x to values y and z that have a path between\n-- them, but because the internals of each type are discrete\n-- groupoids, this reduces to saying that y and z are identical, and\n-- hence that the permutations are identical.\n\ninfix 10 _∼_ \n\n_∼_ : {t₁ t₂ : U} → (c₁ c₂ : t₁ ⟷ t₂) → Set\nc₁ ∼ c₂ = (c2cauchy c₁ ≡ c2cauchy c₂)\n\n-- The relation ~ is an equivalence relation\n\nrefl∼ : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (c ∼ c)\nrefl∼ = refl \n\nsym∼ : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ∼ c₂) → (c₂ ∼ c₁)\nsym∼ = sym\n\ntrans∼ : {t₁ t₂ : U} {c₁ c₂ c₃ : t₁ ⟷ t₂} → (c₁ ∼ c₂) → (c₂ ∼ c₃) → (c₁ ∼ c₃)\ntrans∼ = trans\n\nassoc∼ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₃ ⟷ t₄} → \n c₁ ◎ (c₂ ◎ c₃) ∼ (c₁ ◎ c₂) ◎ c₃\nassoc∼ {t₁} {t₂} {t₃} {t₄} {c₁} {c₂} {c₃} = \n begin (c2cauchy (c₁ ◎ (c₂ ◎ c₃))\n ≡⟨ refl ⟩ \n scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁)\n (scompcauchy\n (c2cauchy c₂)\n (subst Cauchy (size≡! c₂) (c2cauchy c₃))))\n ≡⟨ cong \n (scompcauchy (c2cauchy c₁))\n (subst-dist \n scompcauchy \n (size≡! c₁) \n (c2cauchy c₂)\n (subst Cauchy (size≡! c₂) (c2cauchy c₃))) ⟩ \n scompcauchy\n (c2cauchy c₁)\n (scompcauchy\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))\n (subst Cauchy (size≡! c₁)\n (subst Cauchy (size≡! c₂) (c2cauchy c₃))))\n ≡⟨ cong (λ x → \n scompcauchy \n (c2cauchy c₁)\n (scompcauchy \n (subst Cauchy (size≡! c₁) (c2cauchy c₂))\n x))\n (subst-trans (size≡! c₁) (size≡! c₂) (c2cauchy c₃)) ⟩ \n scompcauchy\n (c2cauchy c₁)\n (scompcauchy\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))\n (subst Cauchy (trans (size≡! c₂) (size≡! c₁)) (c2cauchy c₃)))\n ≡⟨ scompassoc \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) (c2cauchy c₂)) \n (subst Cauchy (trans (size≡! c₂) (size≡! c₁)) (c2cauchy c₃)) ⟩\n scompcauchy \n (scompcauchy \n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₂)))\n (subst Cauchy (trans (size≡! c₂) (size≡! c₁)) (c2cauchy c₃))\n ≡⟨ refl ⟩ \n c2cauchy ((c₁ ◎ c₂) ◎ c₃) ∎)\n where open ≡-Reasoning\n\n-- The combinators c : t₁ ⟷ t₂ are paths; we can transport\n-- size-preserving properties across c. In particular, for some\n-- appropriate P we want P(t₁) to map to P(t₂) via c.\n\n-- The relation ~ validates the groupoid laws\n\nc◎id∼c : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ◎ id⟷ ∼ c\nc◎id∼c {t₁} {t₂} {c} = \n begin (c2cauchy (c ◎ id⟷)\n ≡⟨ refl ⟩ \n scompcauchy \n (c2cauchy c)\n (subst Cauchy (size≡! c) (allFin (size t₂)))\n ≡⟨ cong (λ x → scompcauchy (c2cauchy c) x) \n (congD! {B = Cauchy} allFin (size≡! c)) ⟩ \n scompcauchy (c2cauchy c) (allFin (size t₁))\n ≡⟨ scomprid (c2cauchy c) ⟩ \n c2cauchy c ∎)\n where open ≡-Reasoning\n\nid◎c∼c : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → id⟷ ◎ c ∼ c\nid◎c∼c {t₁} {t₂} {c} = \n begin (c2cauchy (id⟷ ◎ c)\n ≡⟨ refl ⟩ \n scompcauchy \n (allFin (size t₁))\n (subst Cauchy refl (c2cauchy c))\n ≡⟨ refl ⟩ \n scompcauchy (allFin (size t₁)) (c2cauchy c)\n ≡⟨ scomplid (c2cauchy c) ⟩ \n c2cauchy c ∎)\n where open ≡-Reasoning\n\nlinv∼ : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ◎ ! c ∼ id⟷\nlinv∼ {PLUS ZERO t} {.t} {unite₊} = \n begin (c2cauchy {PLUS ZERO t} (unite₊ ◎ uniti₊)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy (size t)) (idcauchy (size t))\n ≡⟨ scomplid (idcauchy (size t)) ⟩ \n c2cauchy {PLUS ZERO t} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {t} {PLUS ZERO .t} {uniti₊} = \n begin (c2cauchy {t} (uniti₊ ◎ unite₊)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy (size t)) (idcauchy (size t))\n ≡⟨ scomplid (idcauchy (size t)) ⟩ \n c2cauchy {t} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {PLUS t₁ t₂} {PLUS .t₂ .t₁} {swap₊} =\n begin (c2cauchy {PLUS t₁ t₂} (swap₊ ◎ swap₊)\n ≡⟨ refl ⟩ \n scompcauchy \n (swap+cauchy (size t₁) (size t₂))\n (subst Cauchy (+-comm (size t₂) (size t₁)) \n (swap+cauchy (size t₂) (size t₁)))\n ≡⟨ swap+idemp (size t₁) (size t₂) ⟩ \n c2cauchy {PLUS t₁ t₂} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {PLUS t₁ (PLUS t₂ t₃)} {PLUS (PLUS .t₁ .t₂) .t₃} {assocl₊} = \n begin (c2cauchy {PLUS t₁ (PLUS t₂ t₃)} (assocl₊ ◎ assocr₊)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃)))\n (subst Cauchy (+-assoc (size t₁) (size t₂) (size t₃))\n (idcauchy ((size t₁ + size t₂) + size t₃)))\n ≡⟨ cong \n (scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃))))\n (congD! idcauchy (+-assoc (size t₁) (size t₂) (size t₃))) ⟩ \n scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃)))\n (idcauchy (size t₁ + (size t₂ + size t₃)))\n ≡⟨ scomplid (idcauchy (size t₁ + (size t₂ + size t₃))) ⟩ \n c2cauchy {PLUS t₁ (PLUS t₂ t₃)} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {PLUS (PLUS t₁ t₂) t₃} {PLUS .t₁ (PLUS .t₂ .t₃)} {assocr₊} = \n begin (c2cauchy {PLUS (PLUS t₁ t₂) t₃} (assocr₊ ◎ assocl₊)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃))\n (subst Cauchy (sym (+-assoc (size t₁) (size t₂) (size t₃)))\n (idcauchy (size t₁ + (size t₂ + size t₃))))\n ≡⟨ cong \n (scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃)))\n (congD! idcauchy (sym (+-assoc (size t₁) (size t₂) (size t₃)))) ⟩\n scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃))\n (idcauchy ((size t₁ + size t₂) + size t₃))\n ≡⟨ scomplid (idcauchy ((size t₁ + size t₂) + size t₃)) ⟩ \n c2cauchy {PLUS (PLUS t₁ t₂) t₃} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {TIMES ONE t} {.t} {unite⋆} = \n begin (c2cauchy {TIMES ONE t} (unite⋆ ◎ uniti⋆)\n ≡⟨ refl ⟩ \n scompcauchy \n (subst Cauchy (sym (+-right-identity (size t))) (idcauchy (size t)))\n (subst Cauchy (sym (+-right-identity (size t))) (idcauchy (size t)))\n ≡⟨ cong \n (λ x → scompcauchy x x) \n (congD! idcauchy (sym (+-right-identity (size t)))) ⟩ \n scompcauchy (idcauchy (size t + 0)) (idcauchy (size t + 0))\n ≡⟨ scomplid (idcauchy (size t + 0)) ⟩ \n c2cauchy {TIMES ONE t} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {t} {TIMES ONE .t} {uniti⋆} = \n begin (c2cauchy {t} (uniti⋆ ◎ unite⋆)\n ≡⟨ refl ⟩ \n scompcauchy \n (idcauchy (size t))\n (subst Cauchy (+-right-identity (size t))\n (subst Cauchy (sym (+-right-identity (size t))) \n (idcauchy (size t))))\n ≡⟨ cong \n (scompcauchy (idcauchy (size t)))\n (subst-trans \n (+-right-identity (size t))\n (sym (+-right-identity (size t))) \n (idcauchy (size t))) ⟩ \n scompcauchy \n (idcauchy (size t))\n (subst Cauchy (trans (sym (+-right-identity (size t)))\n (+-right-identity (size t)))\n (idcauchy (size t)))\n ≡⟨ cong \n (λ x → scompcauchy \n (idcauchy (size t))\n (subst Cauchy x (idcauchy (size t))))\n (trans-syml (+-right-identity (size t))) ⟩ \n scompcauchy \n (idcauchy (size t))\n (subst Cauchy refl (idcauchy (size t)))\n ≡⟨ scomplid (idcauchy (size t)) ⟩ \n c2cauchy {t} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {TIMES t₁ t₂} {TIMES .t₂ .t₁} {swap⋆} = \n begin (c2cauchy {TIMES t₁ t₂} (swap⋆ ◎ swap⋆)\n ≡⟨ refl ⟩ \n scompcauchy \n (swap⋆cauchy (size t₁) (size t₂))\n (subst Cauchy (*-comm (size t₂) (size t₁)) \n (swap⋆cauchy (size t₂) (size t₁)))\n ≡⟨ swap⋆idemp (size t₁) (size t₂) ⟩\n c2cauchy {TIMES t₁ t₂} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {TIMES t₁ (TIMES t₂ t₃)} {TIMES (TIMES .t₁ .t₂) .t₃} {assocl⋆} = \n begin (c2cauchy {TIMES t₁ (TIMES t₂ t₃)} (assocl⋆ ◎ assocr⋆)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃)))\n (subst Cauchy (*-assoc (size t₁) (size t₂) (size t₃))\n (idcauchy ((size t₁ * size t₂) * size t₃)))\n ≡⟨ cong \n (scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃))))\n (congD! idcauchy (*-assoc (size t₁) (size t₂) (size t₃))) ⟩ \n scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃)))\n (idcauchy (size t₁ * (size t₂ * size t₃)))\n ≡⟨ scomplid (idcauchy (size t₁ * (size t₂ * size t₃))) ⟩ \n c2cauchy {TIMES t₁ (TIMES t₂ t₃)} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {TIMES (TIMES t₁ t₂) t₃} {TIMES .t₁ (TIMES .t₂ .t₃)} {assocr⋆} = \n begin (c2cauchy {TIMES (TIMES t₁ t₂) t₃} (assocr⋆ ◎ assocl⋆)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃))\n (subst Cauchy (sym (*-assoc (size t₁) (size t₂) (size t₃)))\n (idcauchy (size t₁ * (size t₂ * size t₃))))\n ≡⟨ cong \n (scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃)))\n (congD! idcauchy (sym (*-assoc (size t₁) (size t₂) (size t₃)))) ⟩\n scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃))\n (idcauchy ((size t₁ * size t₂) * size t₃))\n ≡⟨ scomplid (idcauchy ((size t₁ * size t₂) * size t₃)) ⟩ \n c2cauchy {TIMES (TIMES t₁ t₂) t₃} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {TIMES ZERO t} {ZERO} {distz} = refl\nlinv∼ {ZERO} {TIMES ZERO t} {factorz} = refl\nlinv∼ {TIMES (PLUS t₁ t₂) t₃} {PLUS (TIMES .t₁ .t₃) (TIMES .t₂ .t₃)} {dist} = \n begin (c2cauchy {TIMES (PLUS t₁ t₂) t₃} (dist ◎ factor)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃))\n (subst Cauchy (sym (distribʳ-*-+ (size t₃) (size t₁) (size t₂)))\n (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))))\n ≡⟨ cong \n (scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃)))\n (congD! idcauchy \n (sym (distribʳ-*-+ (size t₃) (size t₁) (size t₂)))) ⟩ \n scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃))\n (idcauchy ((size t₁ + size t₂) * size t₃))\n ≡⟨ scomplid (idcauchy ((size t₁ + size t₂) * size t₃)) ⟩ \n c2cauchy {TIMES (PLUS t₁ t₂) t₃} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} {TIMES (PLUS .t₁ .t₂) .t₃} {factor} = \n begin (c2cauchy {PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)} (factor ◎ dist)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))\n (subst Cauchy (distribʳ-*-+ (size t₃) (size t₁) (size t₂))\n (idcauchy ((size t₁ + size t₂) * size t₃)))\n ≡⟨ cong \n (scompcauchy \n (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))))\n (congD! idcauchy \n (distribʳ-*-+ (size t₃) (size t₁) (size t₂))) ⟩ \n scompcauchy (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))\n (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))\n ≡⟨ scomplid (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))) ⟩ \n c2cauchy {PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {t} {.t} {id⟷} = \n begin (c2cauchy {t} (id⟷ ◎ id⟷)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy (size t)) (idcauchy (size t))\n ≡⟨ scomplid (idcauchy (size t)) ⟩ \n c2cauchy {t} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {t₁} {t₃} {_◎_ {t₂ = t₂} c₁ c₂} = \n begin (c2cauchy {t₁} ((c₁ ◎ c₂) ◎ ((! c₂) ◎ (! c₁)))\n ≡⟨ refl ⟩ \n scompcauchy \n (scompcauchy \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) (c2cauchy c₂)))\n (subst Cauchy (trans (size≡! c₂) (size≡! c₁))\n (scompcauchy \n (c2cauchy (! c₂)) \n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))\n ≡⟨ sym (scompassoc \n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))\n (subst Cauchy (trans (size≡! c₂) (size≡! c₁))\n (scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))) ⟩ \n scompcauchy \n (c2cauchy c₁) \n (scompcauchy \n (subst Cauchy (size≡! c₁) (c2cauchy c₂))\n (subst Cauchy (trans (size≡! c₂) (size≡! c₁))\n (scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))))\n ≡⟨ cong\n (λ x → scompcauchy\n (c2cauchy c₁)\n (scompcauchy \n (subst Cauchy (size≡! c₁) (c2cauchy c₂))\n x))\n (sym (subst-trans (size≡! c₁) (size≡! c₂)\n (scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))) ⟩ \n scompcauchy \n (c2cauchy c₁) \n (scompcauchy \n (subst Cauchy (size≡! c₁) (c2cauchy c₂))\n (subst Cauchy (size≡! c₁) \n (subst Cauchy (size≡! c₂)\n (scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))))\n ≡⟨ cong \n (scompcauchy (c2cauchy c₁))\n (sym (subst-dist scompcauchy (size≡! c₁)\n (c2cauchy c₂)\n (subst Cauchy (size≡! c₂)\n (scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) \n (c2cauchy (! c₁))))))) ⟩ \n scompcauchy \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) \n (scompcauchy \n (c2cauchy c₂)\n (subst Cauchy (size≡! c₂)\n (scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))))\n ≡⟨ cong\n (λ x → scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁)\n (scompcauchy (c2cauchy c₂) x)))\n (subst-dist scompcauchy (size≡! c₂)\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))) ⟩ \n scompcauchy \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) \n (scompcauchy \n (c2cauchy c₂)\n (scompcauchy\n (subst Cauchy (size≡! c₂) (c2cauchy (! c₂)))\n (subst Cauchy (size≡! c₂) \n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))))\n ≡⟨ cong\n (λ x → scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) x))\n (scompassoc \n (c2cauchy c₂)\n (subst Cauchy (size≡! c₂) (c2cauchy (! c₂)))\n (subst Cauchy (size≡! c₂) \n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))) ⟩ \n scompcauchy \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) \n (scompcauchy \n (scompcauchy\n (c2cauchy c₂)\n (subst Cauchy (size≡! c₂) (c2cauchy (! c₂))))\n (subst Cauchy (size≡! c₂) \n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))))\n ≡⟨ cong\n (λ x → scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁)\n (scompcauchy \n x\n (subst Cauchy (size≡! c₂)\n (subst Cauchy (size≡! (! c₂)) \n (c2cauchy (! c₁)))))))\n (linv∼ {t₂} {t₃} {c₂}) ⟩ \n scompcauchy \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) \n (scompcauchy \n (allFin (size t₂))\n (subst Cauchy (size≡! c₂) \n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))))\n ≡⟨ cong \n (λ x → scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) x))\n (scomplid\n (subst Cauchy (size≡! c₂) \n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))) ⟩ \n scompcauchy \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) \n (subst Cauchy (size≡! c₂) \n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))\n ≡⟨ cong \n (λ x → scompcauchy \n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) x))\n (subst-trans (size≡! c₂) (size≡! (! c₂))\n (c2cauchy (! c₁))) ⟩ \n scompcauchy \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) \n (subst Cauchy (trans (size≡! (! c₂)) (size≡! c₂))\n (c2cauchy (! c₁))))\n ≡⟨ cong \n (λ x → scompcauchy \n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) \n (subst Cauchy x (c2cauchy (! c₁)))))\n (trans \n (cong (λ y → trans y (size≡! c₂)) (size≡!! c₂)) \n (trans-syml (size≡! c₂))) ⟩ \n scompcauchy \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) (c2cauchy (! c₁)))\n ≡⟨ linv∼ {t₁} {t₂} {c₁} ⟩ \n c2cauchy {t₁} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {PLUS t₁ t₂} {PLUS t₃ t₄} {c₁ ⊕ c₂} = \n begin (c2cauchy {PLUS t₁ t₂} ((c₁ ⊕ c₂) ◎ ((! c₁) ⊕ (! c₂)))\n ≡⟨ refl ⟩ \n scompcauchy\n (pcompcauchy (c2cauchy c₁) (c2cauchy c₂))\n (subst Cauchy (cong₂ _+_ (size≡! c₁) (size≡! c₂))\n (pcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂))))\n ≡⟨ cong \n (scompcauchy (pcompcauchy (c2cauchy c₁) (c2cauchy c₂)))\n (subst₂+ \n (size≡! c₁) (size≡! c₂) \n (c2cauchy (! c₁)) (c2cauchy (! c₂))\n pcompcauchy) ⟩\n scompcauchy\n (pcompcauchy (c2cauchy c₁) (c2cauchy c₂))\n (pcompcauchy \n (subst Cauchy (size≡! c₁) (c2cauchy (! c₁)))\n (subst Cauchy (size≡! c₂) (c2cauchy (! c₂))))\n ≡⟨ pcomp-dist \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) (c2cauchy (! c₁)))\n (c2cauchy c₂) (subst Cauchy (size≡! c₂) (c2cauchy (! c₂))) ⟩\n pcompcauchy \n (scompcauchy \n (c2cauchy c₁) \n (subst Cauchy (size≡! c₁) (c2cauchy (! c₁))))\n (scompcauchy \n (c2cauchy c₂) \n (subst Cauchy (size≡! c₂) (c2cauchy (! c₂))))\n ≡⟨ cong₂ pcompcauchy (linv∼ {t₁} {t₃} {c₁}) (linv∼ {t₂} {t₄} {c₂}) ⟩\n pcompcauchy (c2cauchy {t₁} id⟷) (c2cauchy {t₂} id⟷)\n ≡⟨ pcomp-id {size t₁} {size t₂} ⟩ \n c2cauchy {PLUS t₁ t₂} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {TIMES t₁ t₂} {TIMES t₃ t₄} {c₁ ⊗ c₂} = \n begin (c2cauchy {TIMES t₁ t₂} ((c₁ ⊗ c₂) ◎ ((! c₁) ⊗ (! c₂)))\n ≡⟨ refl ⟩ \n scompcauchy\n (tcompcauchy (c2cauchy c₁) (c2cauchy c₂))\n (subst Cauchy (cong₂ _*_ (size≡! c₁) (size≡! c₂))\n (tcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂))))\n ≡⟨ cong \n (scompcauchy (tcompcauchy (c2cauchy c₁) (c2cauchy c₂)))\n (subst₂*\n (size≡! c₁) (size≡! c₂)\n (c2cauchy (! c₁)) (c2cauchy (! c₂))\n tcompcauchy) ⟩ \n scompcauchy \n (tcompcauchy (c2cauchy c₁) (c2cauchy c₂))\n (tcompcauchy\n (subst Cauchy (size≡! c₁) (c2cauchy (! c₁)))\n (subst Cauchy (size≡! c₂) (c2cauchy (! c₂))))\n ≡⟨ tcomp-dist\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy (! c₁))) \n (c2cauchy c₂)\n (subst Cauchy (size≡! c₂) (c2cauchy (! c₂))) ⟩\n tcompcauchy\n (scompcauchy \n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy (! c₁))))\n (scompcauchy \n (c2cauchy c₂)\n (subst Cauchy (size≡! c₂) (c2cauchy (! c₂))))\n ≡⟨ cong₂ tcompcauchy (linv∼ {t₁} {t₃} {c₁}) (linv∼ {t₂} {t₄} {c₂}) ⟩ \n tcompcauchy (c2cauchy {t₁} id⟷) (c2cauchy {t₂} id⟷)\n ≡⟨ tcomp-id {size t₁} {size t₂} ⟩\n c2cauchy {TIMES t₁ t₂} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {PLUS ONE ONE} {BOOL} {foldBool} = \n begin (c2cauchy {PLUS ONE ONE} (foldBool ◎ unfoldBool)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy 2) (idcauchy 2)\n ≡⟨ scomplid (idcauchy 2) ⟩ \n c2cauchy {PLUS ONE ONE} id⟷ ∎)\n where open ≡-Reasoning\nlinv∼ {BOOL} {PLUS ONE ONE} {unfoldBool} = \n begin (c2cauchy {BOOL} (unfoldBool ◎ foldBool)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy 2) (idcauchy 2)\n ≡⟨ scomplid (idcauchy 2) ⟩ \n c2cauchy {BOOL} id⟷ ∎)\n where open ≡-Reasoning\n\nrinv∼ : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → ! c ◎ c ∼ id⟷\nrinv∼ {PLUS ZERO t} {.t} {unite₊} = \n begin (c2cauchy {t} (uniti₊ ◎ unite₊)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy (size t)) (idcauchy (size t))\n ≡⟨ scomplid (idcauchy (size t)) ⟩ \n c2cauchy {t} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {t} {PLUS ZERO .t} {uniti₊} = \n begin (c2cauchy {PLUS ZERO t} (unite₊ ◎ uniti₊)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy (size t)) (idcauchy (size t))\n ≡⟨ scomplid (idcauchy (size t)) ⟩ \n c2cauchy {PLUS ZERO t} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {PLUS t₁ t₂} {PLUS .t₂ .t₁} {swap₊} =\n begin (c2cauchy {PLUS t₂ t₁} (swap₊ ◎ swap₊)\n ≡⟨ refl ⟩ \n scompcauchy \n (swap+cauchy (size t₂) (size t₁))\n (subst Cauchy (+-comm (size t₁) (size t₂)) \n (swap+cauchy (size t₁) (size t₂)))\n ≡⟨ swap+idemp (size t₂) (size t₁) ⟩ \n c2cauchy {PLUS t₂ t₁} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {PLUS t₁ (PLUS t₂ t₃)} {PLUS (PLUS .t₁ .t₂) .t₃} {assocl₊} = \n begin (c2cauchy {PLUS (PLUS t₁ t₂) t₃} (assocr₊ ◎ assocl₊)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃))\n (subst Cauchy (sym (+-assoc (size t₁) (size t₂) (size t₃)))\n (idcauchy (size t₁ + (size t₂ + size t₃))))\n ≡⟨ cong \n (scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃)))\n (congD! idcauchy (sym (+-assoc (size t₁) (size t₂) (size t₃)))) ⟩\n scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃))\n (idcauchy ((size t₁ + size t₂) + size t₃))\n ≡⟨ scomplid (idcauchy ((size t₁ + size t₂) + size t₃)) ⟩ \n c2cauchy {PLUS (PLUS t₁ t₂) t₃} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {PLUS (PLUS t₁ t₂) t₃} {PLUS .t₁ (PLUS .t₂ .t₃)} {assocr₊} = \n begin (c2cauchy {PLUS t₁ (PLUS t₂ t₃)} (assocl₊ ◎ assocr₊)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃)))\n (subst Cauchy (+-assoc (size t₁) (size t₂) (size t₃))\n (idcauchy ((size t₁ + size t₂) + size t₃)))\n ≡⟨ cong \n (scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃))))\n (congD! idcauchy (+-assoc (size t₁) (size t₂) (size t₃))) ⟩ \n scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃)))\n (idcauchy (size t₁ + (size t₂ + size t₃)))\n ≡⟨ scomplid (idcauchy (size t₁ + (size t₂ + size t₃))) ⟩ \n c2cauchy {PLUS t₁ (PLUS t₂ t₃)} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {TIMES ONE t} {.t} {unite⋆} = \n begin (c2cauchy {t} (uniti⋆ ◎ unite⋆)\n ≡⟨ refl ⟩ \n scompcauchy \n (idcauchy (size t))\n (subst Cauchy (+-right-identity (size t))\n (subst Cauchy (sym (+-right-identity (size t))) \n (idcauchy (size t))))\n ≡⟨ cong \n (scompcauchy (idcauchy (size t)))\n (subst-trans \n (+-right-identity (size t))\n (sym (+-right-identity (size t))) \n (idcauchy (size t))) ⟩ \n scompcauchy \n (idcauchy (size t))\n (subst Cauchy (trans (sym (+-right-identity (size t)))\n (+-right-identity (size t)))\n (idcauchy (size t)))\n ≡⟨ cong \n (λ x → scompcauchy \n (idcauchy (size t))\n (subst Cauchy x (idcauchy (size t))))\n (trans-syml (+-right-identity (size t))) ⟩ \n scompcauchy \n (idcauchy (size t))\n (subst Cauchy refl (idcauchy (size t)))\n ≡⟨ scomplid (idcauchy (size t)) ⟩ \n c2cauchy {t} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {t} {TIMES ONE .t} {uniti⋆} = \n begin (c2cauchy {TIMES ONE t} (unite⋆ ◎ uniti⋆)\n ≡⟨ refl ⟩ \n scompcauchy \n (subst Cauchy (sym (+-right-identity (size t))) (idcauchy (size t)))\n (subst Cauchy (sym (+-right-identity (size t))) (idcauchy (size t)))\n ≡⟨ cong \n (λ x → scompcauchy x x) \n (congD! idcauchy (sym (+-right-identity (size t)))) ⟩ \n scompcauchy (idcauchy (size t + 0)) (idcauchy (size t + 0))\n ≡⟨ scomplid (idcauchy (size t + 0)) ⟩ \n c2cauchy {TIMES ONE t} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {TIMES t₁ t₂} {TIMES .t₂ .t₁} {swap⋆} =\n begin (c2cauchy {TIMES t₂ t₁} (swap⋆ ◎ swap⋆)\n ≡⟨ refl ⟩ \n scompcauchy \n (swap⋆cauchy (size t₂) (size t₁))\n (subst Cauchy (*-comm (size t₁) (size t₂)) \n (swap⋆cauchy (size t₁) (size t₂)))\n ≡⟨ swap⋆idemp (size t₂) (size t₁) ⟩\n c2cauchy {TIMES t₂ t₁} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {TIMES t₁ (TIMES t₂ t₃)} {TIMES (TIMES .t₁ .t₂) .t₃} {assocl⋆} = \n begin (c2cauchy {TIMES (TIMES t₁ t₂) t₃} (assocr⋆ ◎ assocl⋆)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃))\n (subst Cauchy (sym (*-assoc (size t₁) (size t₂) (size t₃)))\n (idcauchy (size t₁ * (size t₂ * size t₃))))\n ≡⟨ cong \n (scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃)))\n (congD! idcauchy (sym (*-assoc (size t₁) (size t₂) (size t₃)))) ⟩\n scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃))\n (idcauchy ((size t₁ * size t₂) * size t₃))\n ≡⟨ scomplid (idcauchy ((size t₁ * size t₂) * size t₃)) ⟩ \n c2cauchy {TIMES (TIMES t₁ t₂) t₃} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {TIMES (TIMES t₁ t₂) t₃} {TIMES .t₁ (TIMES .t₂ .t₃)} {assocr⋆} = \n begin (c2cauchy {TIMES t₁ (TIMES t₂ t₃)} (assocl⋆ ◎ assocr⋆)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃)))\n (subst Cauchy (*-assoc (size t₁) (size t₂) (size t₃))\n (idcauchy ((size t₁ * size t₂) * size t₃)))\n ≡⟨ cong \n (scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃))))\n (congD! idcauchy (*-assoc (size t₁) (size t₂) (size t₃))) ⟩ \n scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃)))\n (idcauchy (size t₁ * (size t₂ * size t₃)))\n ≡⟨ scomplid (idcauchy (size t₁ * (size t₂ * size t₃))) ⟩ \n c2cauchy {TIMES t₁ (TIMES t₂ t₃)} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {TIMES ZERO t} {ZERO} {distz} = refl\nrinv∼ {ZERO} {TIMES ZERO t} {factorz} = refl\nrinv∼ {TIMES (PLUS t₁ t₂) t₃} {PLUS (TIMES .t₁ .t₃) (TIMES .t₂ .t₃)} {dist} = \n begin (c2cauchy {PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)} (factor ◎ dist)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))\n (subst Cauchy (distribʳ-*-+ (size t₃) (size t₁) (size t₂))\n (idcauchy ((size t₁ + size t₂) * size t₃)))\n ≡⟨ cong \n (scompcauchy \n (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))))\n (congD! idcauchy \n (distribʳ-*-+ (size t₃) (size t₁) (size t₂))) ⟩ \n scompcauchy (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))\n (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))\n ≡⟨ scomplid (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))) ⟩ \n c2cauchy {PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} {TIMES (PLUS .t₁ .t₂) .t₃} {factor} = \n begin (c2cauchy {TIMES (PLUS t₁ t₂) t₃} (dist ◎ factor)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃))\n (subst Cauchy (sym (distribʳ-*-+ (size t₃) (size t₁) (size t₂)))\n (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))))\n ≡⟨ cong \n (scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃)))\n (congD! idcauchy \n (sym (distribʳ-*-+ (size t₃) (size t₁) (size t₂)))) ⟩ \n scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃))\n (idcauchy ((size t₁ + size t₂) * size t₃))\n ≡⟨ scomplid (idcauchy ((size t₁ + size t₂) * size t₃)) ⟩ \n c2cauchy {TIMES (PLUS t₁ t₂) t₃} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {t} {.t} {id⟷} = \n begin (c2cauchy {t} (id⟷ ◎ id⟷)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy (size t)) (idcauchy (size t))\n ≡⟨ scomplid (idcauchy (size t)) ⟩ \n c2cauchy {t} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {t₁} {t₃} {_◎_ {t₂ = t₂} c₁ c₂} = \n begin (c2cauchy {t₃} (((! c₂) ◎ (! c₁)) ◎ (c₁ ◎ c₂))\n ≡⟨ refl ⟩ \n scompcauchy\n (scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))\n (subst Cauchy (trans (size≡! (! c₁)) (size≡! (! c₂)))\n (scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))))\n ≡⟨ sym (scompassoc\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))\n (subst Cauchy (trans (size≡! (! c₁)) (size≡! (! c₂)))\n (scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))))) ⟩ \n scompcauchy\n (c2cauchy (! c₂))\n (scompcauchy\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))\n (subst Cauchy (trans (size≡! (! c₁)) (size≡! (! c₂)))\n (scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₂)))))\n ≡⟨ cong\n (λ x → scompcauchy\n (c2cauchy (! c₂))\n (scompcauchy\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))\n x))\n (sym (subst-trans (size≡! (! c₂)) (size≡! (! c₁))\n (scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))))) ⟩ \n scompcauchy\n (c2cauchy (! c₂))\n (scompcauchy\n (subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))\n (subst Cauchy (size≡! (! c₂))\n (subst Cauchy (size≡! (! c₁))\n (scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))))))\n ≡⟨ cong\n (scompcauchy (c2cauchy (! c₂)))\n (sym (subst-dist scompcauchy (size≡! (! c₂))\n (c2cauchy (! c₁))\n (subst Cauchy (size≡! (! c₁))\n (scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₂)))))) ⟩ \n scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂))\n (scompcauchy\n (c2cauchy (! c₁))\n (subst Cauchy (size≡! (! c₁))\n (scompcauchy\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))))))\n ≡⟨ cong \n (λ x → scompcauchy \n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂))\n (scompcauchy (c2cauchy (! c₁)) x)))\n (subst-dist scompcauchy (size≡! (! c₁))\n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))) ⟩ \n scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂))\n (scompcauchy\n (c2cauchy (! c₁))\n (scompcauchy\n (subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))\n (subst Cauchy (size≡! (! c₁))\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))))))\n ≡⟨ cong\n (λ x → scompcauchy \n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) x))\n (scompassoc\n (c2cauchy (! c₁))\n (subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))\n (subst Cauchy (size≡! (! c₁))\n (subst Cauchy (size≡! c₁) (c2cauchy c₂)))) ⟩\n scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂))\n (scompcauchy\n (scompcauchy\n (c2cauchy (! c₁))\n (subst Cauchy (size≡! (! c₁)) (c2cauchy c₁)))\n (subst Cauchy (size≡! (! c₁))\n (subst Cauchy (size≡! c₁) (c2cauchy c₂)))))\n ≡⟨ cong\n (λ x → scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂))\n (scompcauchy \n x\n (subst Cauchy (size≡! (! c₁))\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))))))\n (rinv∼ {t₁} {t₂} {c₁}) ⟩ \n scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂))\n (scompcauchy\n (allFin (size t₂))\n (subst Cauchy (size≡! (! c₁))\n (subst Cauchy (size≡! c₁) (c2cauchy c₂)))))\n ≡⟨ cong\n (λ x → scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) x))\n (scomplid\n (subst Cauchy (size≡! (! c₁))\n (subst Cauchy (size≡! c₁) (c2cauchy c₂)))) ⟩ \n scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂))\n (subst Cauchy (size≡! (! c₁))\n (subst Cauchy (size≡! c₁) (c2cauchy c₂))))\n ≡⟨ cong\n (λ x → scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) x))\n (subst-trans (size≡! (! c₁)) (size≡! c₁) (c2cauchy c₂)) ⟩ \n scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂))\n (subst Cauchy (trans (size≡! c₁) (size≡! (! c₁))) \n (c2cauchy c₂)))\n ≡⟨ cong\n (λ x → scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂))\n (subst Cauchy x (c2cauchy c₂))))\n (trans\n (cong (λ y → trans (size≡! c₁) y) (size≡!! c₁))\n (trans-symr (size≡! c₁))) ⟩ \n scompcauchy\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy c₂))\n ≡⟨ rinv∼ {t₂} {t₃} {c₂} ⟩ \n c2cauchy {t₃} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {PLUS t₁ t₂} {PLUS t₃ t₄} {c₁ ⊕ c₂} =\n begin (c2cauchy {PLUS t₃ t₄} (((! c₁) ⊕ (! c₂)) ◎ (c₁ ⊕ c₂))\n ≡⟨ refl ⟩ \n scompcauchy\n (pcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂)))\n (subst Cauchy (cong₂ _+_ (size≡! (! c₁)) (size≡! (! c₂)))\n (pcompcauchy (c2cauchy c₁) (c2cauchy c₂)))\n ≡⟨ cong \n (scompcauchy (pcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂))))\n (subst₂+ \n (size≡! (! c₁)) (size≡! (! c₂))\n (c2cauchy c₁) (c2cauchy c₂)\n pcompcauchy) ⟩\n scompcauchy\n (pcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂)))\n (pcompcauchy \n (subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)))\n ≡⟨ pcomp-dist \n (c2cauchy (! c₁))\n (subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))\n (c2cauchy (! c₂)) (subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)) ⟩\n pcompcauchy \n (scompcauchy \n (c2cauchy (! c₁))\n (subst Cauchy (size≡! (! c₁)) (c2cauchy c₁)))\n (scompcauchy \n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)))\n ≡⟨ cong₂ pcompcauchy (rinv∼ {t₁} {t₃} {c₁}) (rinv∼ {t₂} {t₄} {c₂}) ⟩\n pcompcauchy (c2cauchy {t₃} id⟷) (c2cauchy {t₄} id⟷)\n ≡⟨ pcomp-id {size t₃} {size t₄} ⟩ \n c2cauchy {PLUS t₃ t₄} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {TIMES t₁ t₂} {TIMES t₃ t₄} {c₁ ⊗ c₂} =\n begin (c2cauchy {TIMES t₃ t₄} (((! c₁) ⊗ (! c₂)) ◎ (c₁ ⊗ c₂))\n ≡⟨ refl ⟩ \n scompcauchy\n (tcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂)))\n (subst Cauchy (cong₂ _*_ (size≡! (! c₁)) (size≡! (! c₂)))\n (tcompcauchy (c2cauchy c₁) (c2cauchy c₂)))\n ≡⟨ cong \n (scompcauchy (tcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂))))\n (subst₂*\n (size≡! (! c₁)) (size≡! (! c₂))\n (c2cauchy c₁) (c2cauchy c₂)\n tcompcauchy) ⟩ \n scompcauchy \n (tcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂)))\n (tcompcauchy\n (subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)))\n ≡⟨ tcomp-dist\n (c2cauchy (! c₁))\n (subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))\n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)) ⟩\n tcompcauchy\n (scompcauchy \n (c2cauchy (! c₁))\n (subst Cauchy (size≡! (! c₁)) (c2cauchy c₁)))\n (scompcauchy \n (c2cauchy (! c₂))\n (subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)))\n ≡⟨ cong₂ tcompcauchy (rinv∼ {t₁} {t₃} {c₁}) (rinv∼ {t₂} {t₄} {c₂}) ⟩ \n tcompcauchy (c2cauchy {t₃} id⟷) (c2cauchy {t₄} id⟷)\n ≡⟨ tcomp-id {size t₃} {size t₄} ⟩\n c2cauchy {TIMES t₃ t₄} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {PLUS ONE ONE} {BOOL} {foldBool} = \n begin (c2cauchy {BOOL} (unfoldBool ◎ foldBool)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy 2) (idcauchy 2)\n ≡⟨ scomplid (idcauchy 2) ⟩ \n c2cauchy {BOOL} id⟷ ∎)\n where open ≡-Reasoning\nrinv∼ {BOOL} {PLUS ONE ONE} {unfoldBool} = \n begin (c2cauchy {PLUS ONE ONE} (foldBool ◎ unfoldBool)\n ≡⟨ refl ⟩ \n scompcauchy (idcauchy 2) (idcauchy 2)\n ≡⟨ scomplid (idcauchy 2) ⟩ \n c2cauchy {PLUS ONE ONE} id⟷ ∎)\n where open ≡-Reasoning\n\nresp∼ : {t₁ t₂ t₃ : U} {c₁ c₂ : t₁ ⟷ t₂} {c₃ c₄ : t₂ ⟷ t₃} → \n (c₁ ∼ c₂) → (c₃ ∼ c₄) → (c₁ ◎ c₃ ∼ c₂ ◎ c₄)\nresp∼ {t₁} {t₂} {t₃} {c₁} {c₂} {c₃} {c₄} c₁∼c₂ c₃∼c₄ = \n begin (c2cauchy (c₁ ◎ c₃)\n ≡⟨ refl ⟩ \n scompcauchy \n (c2cauchy c₁)\n (subst Cauchy (size≡! c₁) (c2cauchy c₃))\n ≡⟨ cong₂ \n (λ x y → scompcauchy x (subst Cauchy (size≡! c₁) y))\n c₁∼c₂ c₃∼c₄ ⟩ \n scompcauchy \n (c2cauchy c₂)\n (subst Cauchy (size≡! c₁) (c2cauchy c₄))\n ≡⟨ cong \n (λ x → scompcauchy (c2cauchy c₂) (subst Cauchy x (c2cauchy c₄)))\n (size∼! c₁ c₂) ⟩ \n scompcauchy \n (c2cauchy c₂)\n (subst Cauchy (size≡! c₂) (c2cauchy c₄))\n ≡⟨ refl ⟩ \n c2cauchy (c₂ ◎ c₄) ∎)\n where open ≡-Reasoning\n\n-- The equivalence ∼ of paths makes U a 1groupoid: the points are\n-- types (t : U); the 1paths are ⟷; and the 2paths between them are\n-- based on extensional equivalence ∼\n\nG : 1Groupoid\nG = record\n { set = U\n ; _↝_ = _⟷_\n ; _≈_ = _∼_\n ; id = id⟷\n ; _∘_ = λ p q → q ◎ p\n ; _⁻¹ = !\n ; lneutr = λ c → c◎id∼c {c = c}\n ; rneutr = λ c → id◎c∼c {c = c}\n ; assoc = λ c₃ c₂ c₁ → assoc∼ {c₁ = c₁} {c₂ = c₂} {c₃ = c₃} \n ; equiv = record { \n refl = λ {c} → refl∼ {c = c}\n ; sym = λ {c₁} {c₂} → sym∼ {c₁ = c₁} {c₂ = c₂}\n ; trans = λ {c₁} {c₂} {c₃} → trans∼ {c₁ = c₁} {c₂ = c₂} {c₃ = c₃} \n }\n ; linv = λ c → linv∼ {c = c} \n ; rinv = λ c → rinv∼ {c = c} \n ; ∘-resp-≈ = λ {t₁} {t₂} {t₃} {p} {q} {r} {s} p∼q r∼s → \n resp∼ {t₁} {t₂} {t₃} {r} {s} {p} {q} r∼s p∼q \n }\n\n-- There are additional laws that should hold:\n-- \n-- assoc⊕∼ : {t₁ t₂ t₃ t₄ t₅ t₆ : U} \n-- {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → \n-- c₁ ⊕ (c₂ ⊕ c₃) ∼ assocl₊ ◎ ((c₁ ⊕ c₂) ⊕ c₃) ◎ assocr₊\n-- \n-- assoc⊗∼ : {t₁ t₂ t₃ t₄ t₅ t₆ : U} \n-- {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → \n-- c₁ ⊗ (c₂ ⊗ c₃) ∼ assocl⋆ ◎ ((c₁ ⊗ c₂) ⊗ c₃) ◎ assocr⋆\n-- \n-- but we will turn our attention to completeness below (in Pif2) in a more\n-- systematic way.\n\n------------------------------------------------------------------------------\n", "meta": {"hexsha": "d3c5b30a83d3d6e2bb5d7e6beda3ed76c869d830", "size": 47084, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Univalence/Obsolete/Pif.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "Univalence/Obsolete/Pif.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "Univalence/Obsolete/Pif.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 42.4945848375, "max_line_length": 81, "alphanum_fraction": 0.4673349758, "num_tokens": 19037, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6113819874558603, "lm_q2_score": 0.640635854839898, "lm_q1q2_score": 0.39167322216750083}} {"text": "open import Data.Nat\nopen import Data.List as List hiding (null)\nopen import Data.List.Membership.Propositional\nopen import Data.List.Relation.Unary.Any\nopen import Data.List.Relation.Unary.All\nopen import Data.List.Prefix\nopen import Data.Integer\nopen import Data.Product\n\n-- This file contains the definition of values for the definitional\n-- interpreter for MJ using scopes and frames, described in Section 5\n-- of the paper.\n\nmodule MJSF.Values (k : ℕ) where\n\nopen import MJSF.Syntax k\nopen import ScopesFrames.ScopesFrames k Ty\n\nmodule ValuesG (g : Graph) where\n\n open SyntaxG g\n open UsesGraph g public\n open import Common.Weakening\n\n ------------\n -- VALUES --\n ------------\n\n -- The values used in our interpreter at run time are either:\n --\n -- * object references `ref`, represented in terms of a frame scoped\n -- by a class scope;\n --\n -- * null values (`ref` typed);\n --\n -- * an integer number literal (`int` typed); or\n --\n -- * `void` (`void typed -- note that there is no expression syntax\n -- for producing a `void` value directly, but method bodies still\n -- return `void`; we regard `void` as a unit type)\n\n data Val : VTy → List Scope → Set where\n ref : ∀ {s s' Σ} → s <: s' → Frame s Σ → Val (ref s') Σ\n null : ∀ {s Σ} → Val (ref s) Σ\n num : ∀ {Σ} → ℤ → Val int Σ\n void : ∀ {Σ} → Val void Σ\n\n -- There are three kinds of values stored in frame slots at run\n -- time, corresponding to each of the three kinds of declarations\n -- defined in `MJSF.Syntax`:\n --\n -- * values, as defined above;\n --\n -- * methods, where a method records a \"self\" frame `Frame s Σ` and\n -- a well-typed method definition `Meth s ts rt`, such that the\n -- scope of the method corresponds to the \"self\"; and\n --\n -- * classes which record a well-typed class definition and a\n -- witness that the class has a finite inheritance chain, both\n -- used for initializing new object instances, as well as a frame\n -- pointer to the root frame (class table).\n\n data Valᵗ : Ty → List Scope → Set where\n vᵗ : ∀ {t Σ} → Val t Σ → Valᵗ (vᵗ t) Σ\n mᵗ : ∀ {s ts rt Σ} → (self : Frame s Σ) → (body : Meth s ts rt) → Valᵗ (mᵗ ts rt) Σ\n cᵗ : ∀ {sʳ s s' Σ} → (class-def : Class sʳ s) → (ic : Inherits s s') → (root : Frame sʳ Σ) → Valᵗ (cᵗ sʳ s) Σ\n\n\n ---------------\n -- WEAKENING --\n ---------------\n\n -- We define notions of weakening for each of the values summarized above:\n\n val-weaken : ∀ {t Σ Σ'} → Σ ⊑ Σ' → Val t Σ → Val t Σ'\n val-weaken ext (num i) = num i\n val-weaken ext (ref i f) = ref i (wk ext f)\n val-weaken ext null = null\n val-weaken ext void = void\n\n instance\n val-weakenable : ∀ {t} → Weakenable (Val t)\n val-weakenable = record { wk = val-weaken }\n\n valᵗ-weaken : ∀ {t Σ Σ'} → Σ ⊑ Σ' → Valᵗ t Σ → Valᵗ t Σ'\n valᵗ-weaken ext (vᵗ v) = vᵗ (val-weaken ext v)\n valᵗ-weaken ext (mᵗ f m) = mᵗ (wk ext f) m\n valᵗ-weaken ext (cᵗ c ic f) = cᵗ c ic (wk ext f)\n\n -- And pass these to the scope graph definition:\n\n open UsesVal Valᵗ valᵗ-weaken renaming (getFrame to getFrame')\n\n\n --------------\n -- COERCION --\n --------------\n\n -- Our definition of sub-typing gives rise to a notion of sub-type\n -- coercion, defined below. Coercions essentially traverse the\n -- inheritance links of the frame hierarchy for an object instance,\n -- as described in the paper.\n\n upcastRef : ∀ {t t' Σ} → t <: t' → Val (ref t) Σ → Val (ref t') Σ\n upcastRef i (ref i' f) = ref (concatₚ i' i) f\n upcastRef i null = null\n", "meta": {"hexsha": "6f6a8740306779b0285318b7c020d05a3755ebd0", "size": 3529, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/MJSF/Values.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/MJSF/Values.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/MJSF/Values.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": 32.9813084112, "max_line_length": 113, "alphanum_fraction": 0.6217058657, "num_tokens": 1166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.39158532564733245}} {"text": "-- This code is based on \"Parallel Parsing Processes\" by Koen\n-- Claessen.\n\n-- This module is a variant of Parallel in which Parser uses mixed\n-- induction/coinduction.\n\nmodule Parallel2 {Tok : Set} where\n\nopen import Coinduction\nopen import Data.Bool\nimport Data.Bool.Properties as Bool\nopen import Algebra\nopen import Data.Product\nopen import Data.Function\nimport Data.List as List\nopen List using (List; []; _∷_)\nopen import Data.Vec using ([]; _∷_)\nopen import Data.Fin using (#_)\nopen import Category.Monad.State\nopen import Relation.Binary.PropositionalEquality\nopen ≡-Reasoning\n\n------------------------------------------------------------------------\n-- Boring lemma\n\nprivate\n\n lem₁ : ∀ b₁ b₂ → b₁ ∨ b₂ ∧ b₁ ≡ b₁\n lem₁ b₁ b₂ = begin\n b₁ ∨ b₂ ∧ b₁ ≡⟨ cong (_∨_ b₁) (B.∧-comm b₂ b₁) ⟩\n b₁ ∨ b₁ ∧ b₂ ≡⟨ proj₁ B.absorptive b₁ b₂ ⟩\n b₁ ∎\n where module B = BooleanAlgebra Bool.booleanAlgebra\n\n------------------------------------------------------------------------\n-- Parser monad\n\nP : Set → Set\nP = StateT (List Tok) List\n\n------------------------------------------------------------------------\n-- Basic parsers (no CPS)\n\n-- Note that the recursive argument of symbolBind is coinductive,\n-- while that of returnPlus is inductive. An infinite choice is not\n-- acceptable, but an infinite tree of potential parsers is fine.\n\ndata Parser (R : Set) : Bool → Set where\n symbolBind : {e : Tok → Bool} →\n (f : (x : Tok) → ∞ (Parser R (e x))) → Parser R false\n fail : Parser R false\n returnPlus : ∀ {e} (x : R) (p : Parser R e) → Parser R true\n\nparse : ∀ {R e} → Parser R e → P R\nparse (symbolBind f) [] = []\nparse (symbolBind f) (x ∷ xs) = parse (♭ (f x)) xs\nparse fail _ = []\nparse (returnPlus x p) xs = (x , xs) ∷ parse p xs\n\ncast : ∀ {R e₁ e₂} → e₁ ≡ e₂ → Parser R e₁ → Parser R e₂\ncast refl = id\n\nreturn : ∀ {R} → R → Parser R true\nreturn x = returnPlus x fail\n\nmodule DirectImplementations where\n\n -- The definition of _∣_ is fine, but is the definition of _>>=_\n -- acceptable?\n\n infixl 1 _>>=_\n infixl 0 _∣_\n\n _∣_ : ∀ {R e₁ e₂} → Parser R e₁ → Parser R e₂ → Parser R (e₁ ∨ e₂)\n symbolBind f₁ ∣ symbolBind f₂ = symbolBind (λ x → ♯ (♭ (f₁ x) ∣ ♭ (f₂ x)))\n\n fail ∣ p₂ = p₂\n symbolBind f₁ ∣ fail = symbolBind f₁\n returnPlus x₁ p₁ ∣ fail = returnPlus x₁ p₁\n\n returnPlus x₁ p₁ ∣ p₂ = returnPlus x₁ (p₁ ∣ p₂)\n symbolBind f₁ ∣ returnPlus x₂ p₂ = returnPlus x₂ (symbolBind f₁ ∣ p₂)\n\n _>>=_ : ∀ {R₁ R₂ e₁ e₂} →\n Parser R₁ e₁ → (R₁ → Parser R₂ e₂) → Parser R₂ (e₁ ∧ e₂)\n symbolBind f₁ >>= f₂ = symbolBind (λ x → ♯ (♭ (f₁ x) >>= f₂))\n fail >>= f₂ = fail\n returnPlus {e} x₁ p₁ >>= f₂ = cast (lem₁ _ e) (f₂ x₁ ∣ p₁ >>= f₂)\n\n -- Implementing _!>>=_ seems tricky.\n\n -- _!>>=_ : ∀ {R₁ R₂} {e₂ : R₁ → Bool} →\n -- Parser R₁ false → ((x : R₁) → Parser R₂ (e₂ x)) →\n -- Parser R₂ false\n -- symbolBind f !>>= p₂ = symbolBind (λ x → ♯ {!♭ (f x) !>>= p₂!})\n -- fail !>>= p₂ = fail\n\nmodule IndirectImplementations where\n\n -- Can _>>=_ be implemented by using the productivity trick?\n\n infixl 1 _>>=_\n infixl 0 _∣_\n\n data PProg : Set → Bool → Set1 where\n symbolBind : ∀ {R} {e : Tok → Bool} →\n (f : (x : Tok) → ∞₁ (PProg R (e x))) → PProg R false\n fail : ∀ {R} → PProg R false\n returnPlus : ∀ {R e} (x : R) (p : PProg R e) → PProg R true\n _∣_ : ∀ {R e₁ e₂}\n (p₁ : PProg R e₁) (p₂ : PProg R e₂) → PProg R (e₁ ∨ e₂)\n _>>=_ : ∀ {R₁ R₂ e₁ e₂}\n (p₁ : PProg R₁ e₁) (f₂ : R₁ → PProg R₂ e₂) →\n PProg R₂ (e₁ ∧ e₂)\n\n data PWHNF (R : Set) : Bool → Set1 where\n symbolBind : {e : Tok → Bool} →\n (f : (x : Tok) → PProg R (e x)) → PWHNF R false\n fail : PWHNF R false\n returnPlus : ∀ {e} (x : R) (p : PWHNF R e) → PWHNF R true\n\n -- _∣_ is a program, so implementing whnf seems challenging.\n\n whnf : ∀ {R e} → PProg R e → PWHNF R e\n whnf (symbolBind f) = symbolBind (λ x → ♭₁ (f x))\n whnf fail = fail\n whnf (returnPlus x p) = returnPlus x (whnf p)\n\n whnf (p₁ ∣ p₂) with whnf p₁\n ... | fail = whnf p₂\n ... | returnPlus x₁ p₁′ = returnPlus x₁ {!(p₁′ ∣ p₂)!} -- (p₁′ ∣ p₂)\n ... | symbolBind f₁ with whnf p₂\n ... | symbolBind f₂ = symbolBind (λ x → f₁ x ∣ f₂ x)\n ... | fail = symbolBind f₁\n ... | returnPlus x₂ p₂′ = returnPlus x₂ {!!} -- (symbolBind f₁ ∣ p₂′)\n\n whnf (p₁ >>= f₂) with whnf p₁\n ... | symbolBind f₁ = symbolBind (λ x → f₁ x >>= f₂)\n ... | fail = fail\n ... | returnPlus x₁ p₁′ = {!f₂ x₁ ∣ p₁′ >>= f₂!}\n\n mutual\n\n value : ∀ {R e} → PWHNF R e → Parser R e\n value (symbolBind f) = symbolBind (λ x → ♯ ⟦ f x ⟧)\n value fail = fail\n value (returnPlus x p) = returnPlus x (value p)\n\n ⟦_⟧ : ∀ {R e} → PProg R e → Parser R e\n ⟦ p ⟧ = value (whnf p)\n", "meta": {"hexsha": "47ae8a776119e343f012567ee2c6ac1d8cf80650", "size": 5005, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "misc/Parallel2.agda", "max_stars_repo_name": "yurrriq/parser-combinators", "max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z", "max_issues_repo_path": "misc/Parallel2.agda", "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z", "max_forks_repo_path": "misc/Parallel2.agda", "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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": 33.1456953642, "max_line_length": 82, "alphanum_fraction": 0.5218781219, "num_tokens": 1760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737344123242, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.3915778129265744}} {"text": "------------------------------------------------------------------------\n-- Internal coding\n------------------------------------------------------------------------\n\nmodule Internal-coding where\n\nopen import Equality.Propositional\nopen import Prelude hiding (const)\nopen import Tactic.By.Propositional\n\n-- To simplify the development, let's work with actual natural numbers\n-- as variables and constants (see\n-- Atom.one-can-restrict-attention-to-χ-ℕ-atoms).\n\nopen import Atom\n\nopen import Chi χ-ℕ-atoms\nopen import Coding χ-ℕ-atoms\nopen import Constants χ-ℕ-atoms\nopen import Free-variables χ-ℕ-atoms\nopen import Reasoning χ-ℕ-atoms\n\nopen χ-atoms χ-ℕ-atoms\n\nimport Coding.Instances.Nat\n\nabstract\n\n -- Some auxiliary definitions.\n\n private\n\n cd : Var → Exp\n cd x = apply (var v-internal-code) (var x)\n\n nullary-branch : Const → Br\n nullary-branch c =\n branch c [] (\n const c-const (⌜ c ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []))\n\n unary-branch : Const → Br\n unary-branch c =\n branch c (v-x ∷ []) (\n const c-const (⌜ c ⌝ ∷\n const c-cons (cd v-x ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []))\n\n binary-branch : Const → Br\n binary-branch c =\n branch c (v-x ∷ v-y ∷ []) (\n const c-const (⌜ c ⌝ ∷\n const c-cons (cd v-x ∷\n const c-cons (cd v-y ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []))\n\n trinary-branch : Const → Br\n trinary-branch c =\n branch c (v-x ∷ v-y ∷ v-z ∷ []) (\n const c-const (⌜ c ⌝ ∷\n const c-cons (cd v-x ∷\n const c-cons (cd v-y ∷\n const c-cons (cd v-z ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ∷ []))\n\n branches : List Br\n branches =\n nullary-branch c-zero ∷\n unary-branch c-suc ∷\n nullary-branch c-nil ∷\n binary-branch c-cons ∷\n binary-branch c-apply ∷\n binary-branch c-lambda ∷\n binary-branch c-case ∷\n binary-branch c-rec ∷\n unary-branch c-var ∷\n binary-branch c-const ∷\n trinary-branch c-branch ∷\n []\n\n -- Internal coding.\n\n internal-code : Exp\n internal-code =\n rec v-internal-code (lambda v-p (case (var v-p) branches))\n\n internal-code-closed : Closed internal-code\n internal-code-closed = from-⊎ (closed? internal-code)\n\n -- The internal coder encodes natural numbers correctly.\n\n internal-code-correct-ℕ :\n (n : ℕ) → apply internal-code ⌜ n ⌝ ⇓ ⌜ ⌜ n ⌝ ⦂ Exp ⌝\n internal-code-correct-ℕ n =\n apply internal-code ⌜ n ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep n) ⟩\n case ⌜ n ⌝ branches′ ⇓⟨ lemma n ⟩■\n ⌜ ⌜ n ⌝ ⦂ Exp ⌝\n where\n branches′ : List Br\n branches′ = branches [ v-internal-code ← internal-code ]B⋆\n\n lemma : (n : ℕ) → case ⌜ n ⌝ branches′ ⇓ ⌜ ⌜ n ⌝ ⦂ Exp ⌝\n lemma zero =\n case ⌜ zero ⌝ branches′ ⇓⟨ case (rep⇓rep zero) here [] (rep⇓rep (⌜ zero ⌝ ⦂ Exp)) ⟩■\n ⌜ ⌜ zero ⌝ ⦂ Exp ⌝\n\n lemma (suc n) =\n case ⌜ suc n ⌝ branches′ ⟶⟨ case (rep⇓rep (suc n)) (there (λ ()) here) (∷ []) ⟩\n\n const c-const (⌜ c-suc ⌝ ∷\n const c-cons (apply internal-code ⌜ n ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-suc ∷\n const (internal-code-correct-ℕ n ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ suc n ⌝ ⦂ Exp ⌝\n\n -- The internal coder encodes lists of variables correctly.\n\n internal-code-correct-Var⋆ :\n (xs : List Var) →\n apply internal-code ⌜ xs ⌝ ⇓ ⌜ ⌜ xs ⌝ ⦂ Exp ⌝\n internal-code-correct-Var⋆ xs =\n apply internal-code ⌜ xs ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep xs) ⟩\n case ⌜ xs ⌝ branches′ ⇓⟨ lemma xs ⟩■\n ⌜ ⌜ xs ⌝ ⦂ Exp ⌝\n where\n branches′ : List Br\n branches′ = branches [ v-internal-code ← internal-code ]B⋆\n\n lemma : (xs : List Var) →\n case ⌜ xs ⌝ branches′ ⇓ ⌜ ⌜ xs ⌝ ⦂ Exp ⌝\n lemma [] =\n case ⌜ [] ⦂ List Var ⌝ branches′ ⇓⟨ case (rep⇓rep ([] ⦂ List Var)) (there (λ ()) (there (λ ()) here)) []\n (rep⇓rep (⌜ [] ⦂ List Var ⌝ ⦂ Exp)) ⟩■\n ⌜ ⌜ [] ⦂ List Var ⌝ ⦂ Exp ⌝\n\n lemma (x ∷ xs) =\n case ⌜ x List.∷ xs ⌝ branches′ ⟶⟨ case (rep⇓rep (x List.∷ xs))\n (there (λ ()) (there (λ ()) (there (λ ()) here))) (∷ ∷ []) ⟩\n const c-const (⌜ c-cons ⌝ ∷\n const c-cons (apply internal-code ⌜ x ⌝ ∷\n const c-cons (apply internal-code ⟨ ⌜ xs ⌝ [ v-x ← ⌜ x ⌝ ] ⟩ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep xs) ⟩⟶\n\n const c-const (⌜ c-cons ⌝ ∷\n const c-cons (apply internal-code ⌜ x ⌝ ∷\n const c-cons (apply internal-code ⌜ xs ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-cons ∷\n const (internal-code-correct-ℕ x ∷\n const (internal-code-correct-Var⋆ xs ∷\n rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ x List.∷ xs ⌝ ⦂ Exp ⌝\n\n mutual\n\n -- The internal coder encodes expressions correctly.\n\n internal-code-correct :\n (p : Exp) → apply internal-code ⌜ p ⌝ ⇓ ⌜ ⌜ p ⌝ ⦂ Exp ⌝\n internal-code-correct p =\n apply internal-code ⌜ p ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep p) ⟩\n case ⌜ p ⌝ branches′ ⇓⟨ lemma p ⟩■\n ⌜ ⌜ p ⌝ ⦂ Exp ⌝\n where\n branches′ : List Br\n branches′ = branches [ v-internal-code ← internal-code ]B⋆\n\n lemma : (p : Exp) → case ⌜ p ⌝ branches′ ⇓ ⌜ ⌜ p ⌝ ⦂ Exp ⌝\n lemma (apply p₁ p₂) =\n case ⌜ Exp.apply p₁ p₂ ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.apply p₁ p₂))\n (there (λ ()) (there (λ ()) (there (λ ())\n (there (λ ()) here))))\n (∷ ∷ []) ⟩\n const c-const (⌜ c-apply ⌝ ∷\n const c-cons (apply internal-code ⌜ p₁ ⌝ ∷\n const c-cons (apply internal-code ⟨ ⌜ p₂ ⌝ [ v-x ← ⌜ p₁ ⌝ ] ⟩ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep p₂) ⟩⟶\n\n const c-const (⌜ c-apply ⌝ ∷\n const c-cons (apply internal-code ⌜ p₁ ⌝ ∷\n const c-cons (apply internal-code ⌜ p₂ ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-apply ∷\n const (internal-code-correct p₁ ∷\n const (internal-code-correct p₂ ∷\n rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ Exp.apply p₁ p₂ ⌝ ⦂ Exp ⌝\n\n lemma (lambda x p) =\n case ⌜ Exp.lambda x p ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.lambda x p))\n (there (λ ()) (there (λ ()) (there (λ ())\n (there (λ ()) (there (λ ()) here)))))\n (∷ ∷ []) ⟩\n const c-const (⌜ c-lambda ⌝ ∷\n const c-cons (apply internal-code ⌜ x ⌝ ∷\n const c-cons (apply internal-code ⟨ ⌜ p ⌝ [ v-x ← ⌜ x ⌝ ] ⟩ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep p) ⟩⟶\n\n const c-const (⌜ c-lambda ⌝ ∷\n const c-cons (apply internal-code ⌜ x ⌝ ∷\n const c-cons (apply internal-code ⌜ p ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-lambda ∷\n const (internal-code-correct-ℕ x ∷\n const (internal-code-correct p ∷\n rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ Exp.lambda x p ⌝ ⦂ Exp ⌝\n\n lemma (case p bs) =\n case ⌜ Exp.case p bs ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.case p bs))\n (there (λ ()) (there (λ ()) (there (λ ())\n (there (λ ()) (there (λ ()) (there (λ ()) here))))))\n (∷ ∷ []) ⟩\n const c-const (⌜ c-case ⌝ ∷\n const c-cons (apply internal-code ⌜ p ⌝ ∷\n const c-cons (apply internal-code ⟨ ⌜ bs ⌝ [ v-x ← ⌜ p ⌝ ] ⟩ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep bs) ⟩⟶\n\n const c-const (⌜ c-case ⌝ ∷\n const c-cons (apply internal-code ⌜ p ⌝ ∷\n const c-cons (apply internal-code ⌜ bs ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-case ∷\n const (internal-code-correct p ∷\n const (internal-code-correct-B⋆ bs ∷\n rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ Exp.case p bs ⌝ ⦂ Exp ⌝\n\n lemma (rec x p) =\n case ⌜ Exp.rec x p ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.rec x p))\n (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ())\n (there (λ ()) (there (λ ()) (there (λ ()) here)))))))\n (∷ ∷ []) ⟩\n const c-const (⌜ c-rec ⌝ ∷\n const c-cons (apply internal-code ⌜ x ⌝ ∷\n const c-cons (apply internal-code ⟨ ⌜ p ⌝ [ v-x ← ⌜ x ⌝ ] ⟩ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep p) ⟩⟶\n const c-const (⌜ c-rec ⌝ ∷\n const c-cons (apply internal-code ⌜ x ⌝ ∷\n const c-cons (apply internal-code ⌜ p ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-rec ∷\n const (internal-code-correct-ℕ x ∷\n const (internal-code-correct p ∷\n rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ Exp.rec x p ⌝ ⦂ Exp ⌝\n\n lemma (var x) =\n case ⌜ Exp.var x ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.var x))\n (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ())\n (there (λ ()) (there (λ ()) (there (λ ()) here))))))))\n (∷ []) ⟩\n const c-const (⌜ c-var ⌝ ∷\n const c-cons (apply internal-code ⌜ x ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-var ∷\n const (internal-code-correct-ℕ x ∷ rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ Exp.var x ⌝ ⦂ Exp ⌝\n\n lemma (const c ps) =\n case ⌜ Exp.const c ps ⌝ branches′ ⟶⟨ case (rep⇓rep (Exp.const c ps))\n (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ())\n (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ())\n (there (λ ()) here)))))))))\n (∷ ∷ []) ⟩\n const c-const (⌜ c-const ⌝ ∷\n const c-cons (apply internal-code ⌜ c ⌝ ∷\n const c-cons (apply internal-code ⟨ ⌜ ps ⌝ [ v-x ← ⌜ c ⌝ ] ⟩ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep ps) ⟩⟶\n\n const c-const (⌜ c-const ⌝ ∷\n const c-cons (apply internal-code ⌜ c ⌝ ∷\n const c-cons (apply internal-code ⌜ ps ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-const ∷\n const (internal-code-correct-ℕ c ∷\n const (internal-code-correct-⋆ ps ∷\n rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ Exp.const c ps ⌝ ⦂ Exp ⌝\n\n -- The internal coder encodes branches correctly.\n\n internal-code-correct-B :\n (b : Br) → apply internal-code ⌜ b ⌝ ⇓ ⌜ ⌜ b ⌝ ⦂ Exp ⌝\n internal-code-correct-B (branch c xs e) =\n apply internal-code ⌜ branch c xs e ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep (branch c xs e)) ⟩\n\n case ⌜ branch c xs e ⌝ branches′ ⟶⟨ case (rep⇓rep (branch c xs e))\n (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ())\n (there (λ ()) (there (λ ()) (there (λ ()) (there (λ ())\n (there (λ ()) (there (λ ()) here))))))))))\n (∷ ∷ ∷ []) ⟩\n const c-const (⌜ c-branch ⌝ ∷\n const c-cons (apply internal-code ⌜ c ⌝ ∷\n const c-cons (apply internal-code ⌜ xs ⌝ [ v-x ← ⌜ c ⌝ ] ∷\n const c-cons (apply internal-code ⟨ ⌜ e ⌝ [ v-y ← ⌜ xs ⌝ ]\n [ v-x ← ⌜ c ⌝ ] ⟩ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (substs-rep e ((v-x , ⌜ c ⌝) ∷ (v-y , ⌜ xs ⌝) ∷ [])) ⟩⟶\n\n const c-const (⌜ c-branch ⌝ ∷\n const c-cons (apply internal-code ⌜ c ⌝ ∷\n const c-cons (apply internal-code ⟨ ⌜ xs ⌝ [ v-x ← ⌜ c ⌝ ] ⟩ ∷\n const c-cons (apply internal-code ⌜ e ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep xs) ⟩⟶\n\n const c-const (⌜ c-branch ⌝ ∷\n const c-cons (apply internal-code ⌜ c ⌝ ∷\n const c-cons (apply internal-code ⌜ xs ⌝ ∷\n const c-cons (apply internal-code ⌜ e ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-branch ∷\n const (internal-code-correct-ℕ c ∷\n const (internal-code-correct-Var⋆ xs ∷\n const (internal-code-correct e ∷\n rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ branch c xs e ⌝ ⦂ Exp ⌝\n where\n branches′ : List Br\n branches′ = branches [ v-internal-code ← internal-code ]B⋆\n\n -- The internal coder encodes lists of expressions correctly.\n\n internal-code-correct-⋆ :\n (ps : List Exp) →\n apply internal-code ⌜ ps ⌝ ⇓ ⌜ ⌜ ps ⌝ ⦂ Exp ⌝\n internal-code-correct-⋆ ps =\n apply internal-code ⌜ ps ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep ps) ⟩\n case ⌜ ps ⌝ branches′ ⇓⟨ lemma ps ⟩■\n ⌜ ⌜ ps ⌝ ⦂ Exp ⌝\n where\n branches′ : List Br\n branches′ = branches [ v-internal-code ← internal-code ]B⋆\n\n lemma : (ps : List Exp) →\n case ⌜ ps ⌝ branches′ ⇓ ⌜ ⌜ ps ⌝ ⦂ Exp ⌝\n lemma [] =\n case ⌜ [] ⦂ List Exp ⌝ branches′ ⇓⟨ case (rep⇓rep ([] ⦂ List Exp)) (there (λ ()) (there (λ ()) here)) []\n (rep⇓rep (⌜ [] ⦂ List Exp ⌝ ⦂ Exp)) ⟩■\n ⌜ ⌜ [] ⦂ List Exp ⌝ ⦂ Exp ⌝\n\n lemma (p ∷ ps) =\n case ⌜ p List.∷ ps ⌝ branches′ ⟶⟨ case (rep⇓rep (p List.∷ ps))\n (there (λ ()) (there (λ ()) (there (λ ()) here))) (∷ ∷ []) ⟩\n const c-const (⌜ c-cons ⌝ ∷\n const c-cons (apply internal-code ⌜ p ⌝ ∷\n const c-cons (apply internal-code ⟨ ⌜ ps ⌝ [ v-x ← ⌜ p ⌝ ] ⟩ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep ps) ⟩⟶\n const c-const (⌜ c-cons ⌝ ∷\n const c-cons (apply internal-code ⌜ p ⌝ ∷\n const c-cons (apply internal-code ⌜ ps ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-cons ∷\n const (internal-code-correct p ∷\n const (internal-code-correct-⋆ ps ∷\n rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ p List.∷ ps ⌝ ⦂ Exp ⌝\n\n -- The internal coder encodes lists of branches correctly.\n\n internal-code-correct-B⋆ :\n (bs : List Br) →\n apply internal-code ⌜ bs ⌝ ⇓ ⌜ ⌜ bs ⌝ ⦂ Exp ⌝\n internal-code-correct-B⋆ bs =\n apply internal-code ⌜ bs ⌝ ⟶⟨ apply (rec lambda) (rep⇓rep bs) ⟩\n case ⌜ bs ⌝ branches′ ⇓⟨ lemma bs ⟩■\n ⌜ ⌜ bs ⌝ ⦂ Exp ⌝\n where\n branches′ : List Br\n branches′ = branches [ v-internal-code ← internal-code ]B⋆\n\n lemma : (bs : List Br) →\n case ⌜ bs ⌝ branches′ ⇓ ⌜ ⌜ bs ⌝ ⦂ Exp ⌝\n lemma [] =\n case ⌜ [] ⦂ List Br ⌝ branches′ ⇓⟨ case (rep⇓rep ([] ⦂ List Br)) (there (λ ()) (there (λ ()) here)) []\n (rep⇓rep (⌜ [] ⦂ List Br ⌝ ⦂ Exp)) ⟩■\n ⌜ ⌜ [] ⦂ List Br ⌝ ⦂ Exp ⌝\n\n lemma (b ∷ bs) =\n case ⌜ b List.∷ bs ⌝ branches′ ⟶⟨ case (rep⇓rep (b List.∷ bs))\n (there (λ ()) (there (λ ()) (there (λ ()) here))) (∷ ∷ []) ⟩\n const c-const (⌜ c-cons ⌝ ∷\n const c-cons (apply internal-code ⌜ b ⌝ ∷\n const c-cons (apply internal-code ⟨ ⌜ bs ⌝ [ v-x ← ⌜ b ⌝ ] ⟩ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ≡⟨ ⟨by⟩ (subst-rep bs) ⟩⟶\n const c-const (⌜ c-cons ⌝ ∷\n const c-cons (apply internal-code ⌜ b ⌝ ∷\n const c-cons (apply internal-code ⌜ bs ⌝ ∷\n ⌜ [] ⦂ List Exp ⌝ ∷ []) ∷ []) ∷ []) ⇓⟨ const (rep⇓rep c-cons ∷\n const (internal-code-correct-B b ∷\n const (internal-code-correct-B⋆ bs ∷\n rep⇓rep ([] ⦂ List Exp) ∷ []) ∷ []) ∷ []) ⟩■\n ⌜ ⌜ b List.∷ bs ⌝ ⦂ Exp ⌝\n", "meta": {"hexsha": "a891e27d58ceccb68bf9a26617dc884038e29194", "size": 20255, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Internal-coding.agda", "max_stars_repo_name": "nad/chi", "max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z", "max_issues_repo_path": "src/Internal-coding.agda", "max_issues_repo_name": "nad/chi", "max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z", "max_forks_repo_path": "src/Internal-coding.agda", "max_forks_repo_name": "nad/chi", "max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "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": 52.7473958333, "max_line_length": 144, "alphanum_fraction": 0.3418415206, "num_tokens": 6121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7057850278370111, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.39133695254689566}} {"text": "module Generic.Property.Eq where\n\nopen import Generic.Core\n\nSemEq : ∀ {i β} {I : Set i} -> Desc I β -> Set\nSemEq (var i) = ⊤\nSemEq (π i q C) = ⊥\nSemEq (D ⊛ E) = SemEq D × SemEq E\n\nmutual\n ExtendEq : ∀ {i β} {I : Set i} -> Desc I β -> Set β\n ExtendEq (var i) = ⊤\n ExtendEq (π i q C) = ExtendEqᵇ i C q\n ExtendEq (D ⊛ E) = SemEq D × ExtendEq E\n\n ExtendEqᵇ : ∀ {ι α β γ q} {I : Set ι} i -> Binder α β γ i q I -> α ≤ℓ β -> Set β\n ExtendEqᵇ (arg-info v r) (coerce (A , D)) q = Coerce′ q $ RelEq r A × ∀ {x} -> ExtendEq (D x)\n\ninstance\n {-# TERMINATING #-} -- Why?\n DataEq : ∀ {i β} {I : Set i} {D : Data (Desc I β)} {j}\n {{eqD : All ExtendEq (consTypes D)}} -> Eq (μ D j)\n DataEq {ι} {β} {I} {D₀} = record { _≟_ = decMu } where\n mutual\n decSem : ∀ D {{eqD : SemEq D}} -> IsSet (⟦ D ⟧ (μ D₀))\n decSem (var i) d₁ d₂ = decMu d₁ d₂\n decSem (π i q C) {{()}}\n decSem (D ⊛ E) {{eqD , eqE}} p₁ p₂ =\n decProd (decSem D {{eqD}}) (decSem E {{eqE}}) p₁ p₂\n\n decExtend : ∀ {j} D {{eqD : ExtendEq D}} -> IsSet (Extend D (μ D₀) j)\n decExtend (var i) lrefl lrefl = yes refl\n decExtend (π i q C) p₁ p₂ = decExtendᵇ i C q p₁ p₂\n decExtend (D ⊛ E) {{eqD , eqE}} p₁ p₂ =\n decProd (decSem D {{eqD}}) (decExtend E {{eqE}}) p₁ p₂\n\n decExtendᵇ : ∀ {α γ q j} i (C : Binder α β γ i q I) q {{eqC : ExtendEqᵇ i C q}}\n -> IsSet (Extendᵇ i C q (μ D₀) j)\n decExtendᵇ (arg-info v r) (coerce (A , D)) q {{eqC}} p₁ p₂ =\n split q eqC λ eqA eqD ->\n decCoerce′ q (decProd (_≟_ {{EqRelValue {{eqA}}}}) (decExtend (D _) {{eqD}})) p₁ p₂\n\n decAny : ∀ {j} (Ds : List (Desc I β)) {{eqD : All ExtendEq Ds}}\n -> ∀ d a b ns -> IsSet (Node D₀ (packData d a b Ds ns) j)\n decAny [] d a b tt () ()\n decAny (D ∷ []) {{eqD , _}} d a b (_ , ns) e₁ e₂ = decExtend D {{eqD}} e₁ e₂\n decAny (D ∷ E ∷ Ds) {{eqD , eqDs}} d a b (_ , ns) s₁ s₂ =\n decSum (decExtend D {{eqD}}) (decAny (E ∷ Ds) {{eqDs}} d a b ns) s₁ s₂\n\n decMu : ∀ {j} -> IsSet (μ D₀ j)\n decMu (node e₁) (node e₂) = dcong node node-inj $ decAny (consTypes D₀)\n (dataName D₀)\n (parsTele D₀)\n (indsTele D₀)\n (consNames D₀)\n e₁\n e₂\n", "meta": {"hexsha": "c5a11a07833c6e96f2bc423c7d62f0a7b8a25a65", "size": 2681, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Generic/Property/Eq.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/Property/Eq.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/Property/Eq.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": 46.224137931, "max_line_length": 95, "alphanum_fraction": 0.4192465498, "num_tokens": 960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7826624738835051, "lm_q2_score": 0.5, "lm_q1q2_score": 0.39133123694175254}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Vectors\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.Vec where\n\nopen import Data.Nat\nopen import Data.Fin using (Fin; zero; suc)\nopen import Data.List.Base as List using (List)\nopen import Data.Product as Prod using (∃; ∃₂; _×_; _,_)\nopen import Data.These as These using (These; this; that; these)\nopen import Function\nopen import Relation.Binary.PropositionalEquality using (_≡_; refl)\nopen import Relation.Nullary using (yes; no)\nopen import Relation.Unary using (Pred; Decidable)\n\n------------------------------------------------------------------------\n-- Types\n\ninfixr 5 _∷_\n\ndata Vec {a} (A : Set a) : ℕ → Set a where\n [] : Vec A zero\n _∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n)\n\ninfix 4 _[_]=_\n\ndata _[_]=_ {a} {A : Set a} :\n {n : ℕ} → Vec A n → Fin n → A → Set a where\n here : ∀ {n} {x} {xs : Vec A n} → x ∷ xs [ zero ]= x\n there : ∀ {n} {i} {x y} {xs : Vec A n}\n (xs[i]=x : xs [ i ]= x) → y ∷ xs [ suc i ]= x\n\n------------------------------------------------------------------------\n-- Basic operations\n\nmodule _ {a} {A : Set a} where\n\n head : ∀ {n} → Vec A (1 + n) → A\n head (x ∷ xs) = x\n\n tail : ∀ {n} → Vec A (1 + n) → Vec A n\n tail (x ∷ xs) = xs\n\n lookup : ∀ {n} → Vec A n → Fin n → A\n lookup (x ∷ xs) zero = x\n lookup (x ∷ xs) (suc i) = lookup xs i\n\n insert : ∀ {n} → Vec A n → Fin (suc n) → A → Vec A (suc n)\n insert xs zero v = v ∷ xs\n insert [] (suc ()) v\n insert (x ∷ xs) (suc i) v = x ∷ insert xs i v\n\n remove : ∀ {n} → Vec A (suc n) → Fin (suc n) → Vec A n\n remove (_ ∷ xs) zero = xs\n remove (x ∷ []) (suc ())\n remove (x ∷ y ∷ xs) (suc i) = x ∷ remove (y ∷ xs) i\n\n updateAt : ∀ {n} → Fin n → (A → A) → Vec A n → Vec A n\n updateAt zero f (x ∷ xs) = f x ∷ xs\n updateAt (suc i) f (x ∷ xs) = x ∷ updateAt i f xs\n\n -- xs [ i ]%= f modifies the i-th element of xs according to f\n\n infixl 6 _[_]%=_\n\n _[_]%=_ : ∀ {n} → Vec A n → Fin n → (A → A) → Vec A n\n xs [ i ]%= f = updateAt i f xs\n\n -- xs [ i ]≔ y overwrites the i-th element of xs with y\n\n infixl 6 _[_]≔_\n\n _[_]≔_ : ∀ {n} → Vec A n → Fin n → A → Vec A n\n xs [ i ]≔ y = xs [ i ]%= const y\n\n------------------------------------------------------------------------\n-- Operations for transforming vectors\n\nmap : ∀ {a b n} {A : Set a} {B : Set b} →\n (A → B) → Vec A n → Vec B n\nmap f [] = []\nmap f (x ∷ xs) = f x ∷ map f xs\n\n-- Concatenation.\n\ninfixr 5 _++_\n\n_++_ : ∀ {a m n} {A : Set a} → Vec A m → Vec A n → Vec A (m + n)\n[] ++ ys = ys\n(x ∷ xs) ++ ys = x ∷ (xs ++ ys)\n\nconcat : ∀ {a m n} {A : Set a} →\n Vec (Vec A m) n → Vec A (n * m)\nconcat [] = []\nconcat (xs ∷ xss) = xs ++ concat xss\n\n-- Align and Zip.\n\nmodule _ {a b c} {A : Set a} {B : Set b} {C : Set c} where\n\n alignWith : ∀ {m n} → (These A B → C) → Vec A m → Vec B n → Vec C (m ⊔ n)\n alignWith f [] bs = map (f ∘′ that) bs\n alignWith f as@(_ ∷ _) [] = map (f ∘′ this) as\n alignWith f (a ∷ as) (b ∷ bs) = f (these a b) ∷ alignWith f as bs\n\n zipWith : ∀ {n} → (A → B → C) → Vec A n → Vec B n → Vec C n\n zipWith f [] [] = []\n zipWith f (x ∷ xs) (y ∷ ys) = f x y ∷ zipWith f xs ys\n\n unzipWith : ∀ {n} → (A → B × C) → Vec A n → Vec B n × Vec C n\n unzipWith f [] = [] , []\n unzipWith f (a ∷ as) = Prod.zip _∷_ _∷_ (f a) (unzipWith f as)\n\nmodule _ {a b} {A : Set a} {B : Set b} where\n\n align : ∀ {m n} → Vec A m → Vec B n → Vec (These A B) (m ⊔ n)\n align = alignWith id\n\n zip : ∀ {n} → Vec A n → Vec B n → Vec (A × B) n\n zip = zipWith _,_\n\n unzip : ∀ {n} → Vec (A × B) n → Vec A n × Vec B n\n unzip = unzipWith id\n\n-- Interleaving.\n\ninfixr 5 _⋎_\n\n_⋎_ : ∀ {a m n} {A : Set a} →\n Vec A m → Vec A n → Vec A (m +⋎ n)\n[] ⋎ ys = ys\n(x ∷ xs) ⋎ ys = x ∷ (ys ⋎ xs)\n\n-- Pointwise application\n\ninfixl 4 _⊛_\n\n_⊛_ : ∀ {a b n} {A : Set a} {B : Set b} →\n Vec (A → B) n → Vec A n → Vec B n\n[] ⊛ _ = []\n(f ∷ fs) ⊛ (x ∷ xs) = f x ∷ (fs ⊛ xs)\n\n-- Multiplication\n\ninfixl 1 _>>=_\n\n_>>=_ : ∀ {a b m n} {A : Set a} {B : Set b} →\n Vec A m → (A → Vec B n) → Vec B (m * n)\nxs >>= f = concat (map f xs)\n\ninfixl 4 _⊛*_\n\n_⊛*_ : ∀ {a b m n} {A : Set a} {B : Set b} →\n Vec (A → B) m → Vec A n → Vec B (m * n)\nfs ⊛* xs = fs >>= λ f → map f xs\n\nallPairs : ∀ {a b m n} {A : Set a} {B : Set b} →\n Vec A m → Vec B n → Vec (A × B) (m * n)\nallPairs xs ys = map _,_ xs ⊛* ys\n\n------------------------------------------------------------------------\n-- Operations for reducing vectors\n\nfoldr : ∀ {a b} {A : Set a} (B : ℕ → Set b) {m} →\n (∀ {n} → A → B n → B (suc n)) →\n B zero →\n Vec A m → B m\nfoldr b _⊕_ n [] = n\nfoldr b _⊕_ n (x ∷ xs) = x ⊕ foldr b _⊕_ n xs\n\nfoldr₁ : ∀ {a} {A : Set a} {m} →\n (A → A → A) → Vec A (suc m) → A\nfoldr₁ _⊕_ (x ∷ []) = x\nfoldr₁ _⊕_ (x ∷ y ∷ ys) = x ⊕ foldr₁ _⊕_ (y ∷ ys)\n\nfoldl : ∀ {a b} {A : Set a} (B : ℕ → Set b) {m} →\n (∀ {n} → B n → A → B (suc n)) →\n B zero →\n Vec A m → B m\nfoldl b _⊕_ n [] = n\nfoldl b _⊕_ n (x ∷ xs) = foldl (λ n → b (suc n)) _⊕_ (n ⊕ x) xs\n\nfoldl₁ : ∀ {a} {A : Set a} {m} →\n (A → A → A) → Vec A (suc m) → A\nfoldl₁ _⊕_ (x ∷ xs) = foldl _ _⊕_ x xs\n\n-- Special folds\n\nsum : ∀ {n} → Vec ℕ n → ℕ\nsum = foldr _ _+_ 0\n\ncount : ∀ {a p} {A : Set a} {P : Pred A p} → Decidable P →\n ∀ {n} → Vec A n → ℕ\ncount P? [] = zero\ncount P? (x ∷ xs) with P? x\n... | yes _ = suc (count P? xs)\n... | no _ = count P? xs\n\n------------------------------------------------------------------------\n-- Operations for building vectors\n\n[_] : ∀ {a} {A : Set a} → A → Vec A 1\n[ x ] = x ∷ []\n\nreplicate : ∀ {a n} {A : Set a} → A → Vec A n\nreplicate {n = zero} x = []\nreplicate {n = suc n} x = x ∷ replicate x\n\ntabulate : ∀ {n a} {A : Set a} → (Fin n → A) → Vec A n\ntabulate {zero} f = []\ntabulate {suc n} f = f zero ∷ tabulate (f ∘ suc)\n\nallFin : ∀ n → Vec (Fin n) n\nallFin _ = tabulate id\n\n------------------------------------------------------------------------\n-- Operations for dividing vectors\n\nsplitAt : ∀ {a} {A : Set a} m {n} (xs : Vec A (m + n)) →\n ∃₂ λ (ys : Vec A m) (zs : Vec A n) → xs ≡ ys ++ zs\nsplitAt zero xs = ([] , xs , refl)\nsplitAt (suc m) (x ∷ xs) with splitAt m xs\nsplitAt (suc m) (x ∷ .(ys ++ zs)) | (ys , zs , refl) =\n ((x ∷ ys) , zs , refl)\n\ntake : ∀ {a} {A : Set a} m {n} → Vec A (m + n) → Vec A m\ntake m xs with splitAt m xs\ntake m .(ys ++ zs) | (ys , zs , refl) = ys\n\ndrop : ∀ {a} {A : Set a} m {n} → Vec A (m + n) → Vec A n\ndrop m xs with splitAt m xs\ndrop m .(ys ++ zs) | (ys , zs , refl) = zs\n\ngroup : ∀ {a} {A : Set a} n k (xs : Vec A (n * k)) →\n ∃ λ (xss : Vec (Vec A k) n) → xs ≡ concat xss\ngroup zero k [] = ([] , refl)\ngroup (suc n) k xs with splitAt k xs\ngroup (suc n) k .(ys ++ zs) | (ys , zs , refl) with group n k zs\ngroup (suc n) k .(ys ++ concat zss) | (ys , ._ , refl) | (zss , refl) =\n ((ys ∷ zss) , refl)\n\nsplit : ∀ {a n} {A : Set a} → Vec A n → Vec A ⌈ n /2⌉ × Vec A ⌊ n /2⌋\nsplit [] = ([] , [])\nsplit (x ∷ []) = (x ∷ [] , [])\nsplit (x ∷ y ∷ xs) = Prod.map (x ∷_) (y ∷_) (split xs)\n\n------------------------------------------------------------------------\n-- Operations for converting between lists\n\ntoList : ∀ {a n} {A : Set a} → Vec A n → List A\ntoList [] = List.[]\ntoList (x ∷ xs) = List._∷_ x (toList xs)\n\nfromList : ∀ {a} {A : Set a} → (xs : List A) → Vec A (List.length xs)\nfromList List.[] = []\nfromList (List._∷_ x xs) = x ∷ fromList xs\n\n------------------------------------------------------------------------\n-- Operations for reversing vectors\n\nreverse : ∀ {a n} {A : Set a} → Vec A n → Vec A n\nreverse {A = A} = foldl (Vec A) (λ rev x → x ∷ rev) []\n\ninfixl 5 _∷ʳ_\n\n_∷ʳ_ : ∀ {a n} {A : Set a} → Vec A n → A → Vec A (1 + n)\n[] ∷ʳ y = [ y ]\n(x ∷ xs) ∷ʳ y = x ∷ (xs ∷ʳ y)\n\ninitLast : ∀ {a n} {A : Set a} (xs : Vec A (1 + n)) →\n ∃₂ λ (ys : Vec A n) (y : A) → xs ≡ ys ∷ʳ y\ninitLast {n = zero} (x ∷ []) = ([] , x , refl)\ninitLast {n = suc n} (x ∷ xs) with initLast xs\ninitLast {n = suc n} (x ∷ .(ys ∷ʳ y)) | (ys , y , refl) =\n ((x ∷ ys) , y , refl)\n\ninit : ∀ {a n} {A : Set a} → Vec A (1 + n) → Vec A n\ninit xs with initLast xs\ninit .(ys ∷ʳ y) | (ys , y , refl) = ys\n\nlast : ∀ {a n} {A : Set a} → Vec A (1 + n) → A\nlast xs with initLast xs\nlast .(ys ∷ʳ y) | (ys , y , refl) = y\n", "meta": {"hexsha": "373f8dbedec17fe9c103bde8f60f86b64f8495a0", "size": 8644, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": "test/asset/agda-stdlib-1.0/Data/Vec.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Data/Vec.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": 29.9100346021, "max_line_length": 75, "alphanum_fraction": 0.4265386395, "num_tokens": 3414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6001883735630721, "lm_q2_score": 0.6513548646660542, "lm_q1q2_score": 0.390935616836314}} {"text": "------------------------------------------------------------------------\n-- INCREMENTAL λ-CALCULUS\n--\n-- The syntax of function types (Fig. 1a).\n------------------------------------------------------------------------\n\nmodule Parametric.Syntax.Type where\n\nopen import Base.Data.DependentList\n\n-- This is a module in the Parametric.* hierarchy, so it defines\n-- an extension point for plugins. In this case, the plugin can\n-- choose the syntax for data types. We always provide a binding\n-- called \"Structure\" that defines the type of the value that has\n-- to be provided by the plugin. In this case, the plugin has to\n-- provide a type, so we say \"Structure = Set\".\n\nStructure : Set₁\nStructure = Set\n\n-- Here is the parametric module that defines the syntax of\n-- simply types in terms of the syntax of base types. In the\n-- Parametric.* hierarchy, we always call these parametric\n-- modules \"Structure\". Note that in Agda, there is a separate\n-- namespace for module names and for other bindings, so this\n-- doesn't clash with the \"Structure\" above.\n--\n-- The idea behind all these structures is that the parametric\n-- module lifts some structure of the plugin to the corresponding\n-- structure in the full language. In this case, we lift the\n-- structure of base types to the structure of simple types.\n-- Maybe not the best choice of names, but it seemed clever at\n-- the time.\n\nmodule Structure (Base : Structure) where\n infixr 5 _⇒_\n\n -- A simple type is either a base type or a function types.\n -- Note that we can use our module parameter \"Base\" here just\n -- like any other type.\n data Type : Set where\n base : (ι : Base) → Type\n _⇒_ : (σ : Type) → (τ : Type) → Type\n\n -- We also provide the definitions of contexts of the newly\n -- defined simple types, variables as de Bruijn indices\n -- pointing into such a context, and sets of bound variables.\n open import Base.Syntax.Context Type public\n open import Base.Syntax.Vars Type public\n\n -- Internalize a context to a type.\n --\n -- Is there a better name for this function?\n internalizeContext : (Σ : Context) (τ′ : Type) → Type\n internalizeContext ∅ τ′ = τ′\n internalizeContext (τ • Σ) τ′ = τ ⇒ internalizeContext Σ τ′\n", "meta": {"hexsha": "1f617666cf5fc0d7a05ae55ccabac118f8a6072f", "size": 2200, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Parametric/Syntax/Type.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/Syntax/Type.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/Syntax/Type.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": 38.5964912281, "max_line_length": 72, "alphanum_fraction": 0.6731818182, "num_tokens": 531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548646660543, "lm_q2_score": 0.600188359260205, "lm_q1q2_score": 0.390935607520072}} {"text": "-- Limits.\n-- Heavily inspired by https://github.com/UniMath/UniMath/blob/master/UniMath/CategoryTheory/limits/graphs/limits.v\n-- (except we're using categories instead of graphs to index limits)\n\n{-# OPTIONS --safe #-}\nmodule Cubical.Categories.Limits.Limits where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.HLevels\n\nopen import Cubical.Data.Sigma.Base\n\nopen import Cubical.Categories.Category\nopen import Cubical.Categories.Functor\n\nopen import Cubical.HITs.PropositionalTruncation.Base\n\nmodule _ {ℓJ ℓJ' ℓC ℓC' : Level} {J : Category ℓJ ℓJ'} {C : Category ℓC ℓC'} where\n open Category\n open Functor\n\n private\n ℓ = ℓ-max (ℓ-max (ℓ-max ℓJ ℓJ') ℓC) ℓC'\n\n record Cone (D : Functor J C) (c : ob C) : Type (ℓ-max (ℓ-max ℓJ ℓJ') ℓC') where\n constructor cone\n\n field\n coneOut : (v : ob J) → C [ c , F-ob D v ]\n coneOutCommutes : {u v : ob J} (e : J [ u , v ]) →\n coneOut u ⋆⟨ C ⟩ D .F-hom e ≡ coneOut v\n\n open Cone\n\n cone≡ : {D : Functor J C} {c : ob C} → {c1 c2 : Cone D c}\n → ((v : ob J) → coneOut c1 v ≡ coneOut c2 v) → c1 ≡ c2\n coneOut (cone≡ h i) v = h v i\n coneOutCommutes (cone≡ {D} {_} {c1} {c2} h i) {u} {v} e =\n isProp→PathP (λ j → isSetHom C (h u j ⋆⟨ C ⟩ D .F-hom e) (h v j))\n (coneOutCommutes c1 e) (coneOutCommutes c2 e) i\n\n -- TODO: can we automate this a bit?\n isSetCone : (D : Functor J C) (c : ob C) → isSet (Cone D c)\n isSetCone D c = isSetRetract toConeΣ fromConeΣ (λ _ → refl)\n (isSetΣSndProp (isSetΠ (λ _ → isSetHom C))\n (λ _ → isPropImplicitΠ2 (λ _ _ → isPropΠ (λ _ → isSetHom C _ _))))\n where\n ConeΣ = Σ[ f ∈ ((v : ob J) → C [ c , F-ob D v ]) ]\n ({u v : ob J} (e : J [ u , v ]) → f u ⋆⟨ C ⟩ D .F-hom e ≡ f v)\n\n toConeΣ : Cone D c → ConeΣ\n fst (toConeΣ x) = coneOut x\n snd (toConeΣ x) = coneOutCommutes x\n\n fromConeΣ : ConeΣ → Cone D c\n coneOut (fromConeΣ x) = fst x\n coneOutCommutes (fromConeΣ x) = snd x\n\n isConeMor : {c1 c2 : ob C} {D : Functor J C}\n (cc1 : Cone D c1) (cc2 : Cone D c2)\n → C [ c1 , c2 ] → Type (ℓ-max ℓJ ℓC')\n isConeMor cc1 cc2 f = (v : ob J) → f ⋆⟨ C ⟩ coneOut cc2 v ≡ coneOut cc1 v\n\n isPropIsConeMor : {c1 c2 : ob C} {D : Functor J C}\n (cc1 : Cone D c1) (cc2 : Cone D c2) (f : C [ c1 , c2 ])\n → isProp (isConeMor cc1 cc2 f)\n isPropIsConeMor cc1 cc2 f = isPropΠ (λ _ → isSetHom C _ _)\n\n isLimCone : (D : Functor J C) (c0 : ob C) → Cone D c0 → Type ℓ\n isLimCone D c0 cc0 = (c : ob C) → (cc : Cone D c)\n → ∃![ f ∈ C [ c , c0 ] ] isConeMor cc cc0 f\n\n isPropIsLimCone : (D : Functor J C) (c0 : ob C) (cc0 : Cone D c0)\n → isProp (isLimCone D c0 cc0)\n isPropIsLimCone D c0 cc0 = isPropΠ2 λ _ _ → isProp∃!\n\n record LimCone (D : Functor J C) : Type ℓ where\n constructor climCone\n\n field\n lim : ob C\n limCone : Cone D lim\n univProp : isLimCone D lim limCone\n\n limOut : (v : ob J) → C [ lim , D .F-ob v ]\n limOut = coneOut limCone\n\n limOutCommutes : {u v : ob J} (e : J [ u , v ])\n → limOut u ⋆⟨ C ⟩ D .F-hom e ≡ limOut v\n limOutCommutes = coneOutCommutes limCone\n\n limArrow : (c : ob C) → (cc : Cone D c) → C [ c , lim ]\n limArrow c cc = univProp c cc .fst .fst\n\n limArrowCommutes : (c : ob C) → (cc : Cone D c) (u : ob J)\n → limArrow c cc ⋆⟨ C ⟩ limOut u ≡ coneOut cc u\n limArrowCommutes c cc = univProp c cc .fst .snd\n\n limArrowUnique : (c : ob C) → (cc : Cone D c) (k : C [ c , lim ])\n → isConeMor cc limCone k → limArrow c cc ≡ k\n limArrowUnique c cc k hk = cong fst (univProp c cc .snd (k , hk))\n\n open LimCone\n limOfArrows : (D₁ D₂ : Functor J C)\n (CC₁ : LimCone D₁) (CC₂ : LimCone D₂)\n (f : (u : ob J) → C [ D₁ .F-ob u , D₂ .F-ob u ])\n (fNat : {u v : ob J} (e : J [ u , v ])\n → f u ⋆⟨ C ⟩ D₂ .F-hom e ≡ D₁ .F-hom e ⋆⟨ C ⟩ f v)\n → C [ CC₁ .lim , CC₂ .lim ]\n limOfArrows D₁ D₂ CC₁ CC₂ f fNat = limArrow CC₂ (CC₁ .lim) coneD₂Lim₁\n where\n coneD₂Lim₁ : Cone D₂ (CC₁ .lim)\n coneOut coneD₂Lim₁ v = limOut CC₁ v ⋆⟨ C ⟩ f v\n coneOutCommutes coneD₂Lim₁ {u = u} {v = v} e =\n limOut CC₁ u ⋆⟨ C ⟩ f u ⋆⟨ C ⟩ D₂ .F-hom e ≡⟨ ⋆Assoc C _ _ _ ⟩\n limOut CC₁ u ⋆⟨ C ⟩ (f u ⋆⟨ C ⟩ D₂ .F-hom e) ≡⟨ cong (λ x → seq' C (limOut CC₁ u) x) (fNat e) ⟩\n limOut CC₁ u ⋆⟨ C ⟩ (D₁ .F-hom e ⋆⟨ C ⟩ f v) ≡⟨ sym (⋆Assoc C _ _ _) ⟩\n limOut CC₁ u ⋆⟨ C ⟩ D₁ .F-hom e ⋆⟨ C ⟩ f v ≡⟨ cong (λ x → x ⋆⟨ C ⟩ f v) (limOutCommutes CC₁ e) ⟩\n limOut CC₁ v ⋆⟨ C ⟩ f v ∎\n\n-- A category is complete if it has all limits\nLimits : {ℓJ ℓJ' ℓC ℓC' : Level} → Category ℓC ℓC' → Type _\nLimits {ℓJ} {ℓJ'} C = (J : Category ℓJ ℓJ') → (D : Functor J C) → LimCone D\n\nhasLimits : {ℓJ ℓJ' ℓC ℓC' : Level} → Category ℓC ℓC' → Type _\nhasLimits {ℓJ} {ℓJ'} C = (J : Category ℓJ ℓJ') → (D : Functor J C) → ∥ LimCone D ∥\n\n-- Limits of a specific shape J in a category C\nLimitsOfShape : {ℓJ ℓJ' ℓC ℓC' : Level} → Category ℓJ ℓJ' → Category ℓC ℓC' → Type _\nLimitsOfShape J C = (D : Functor J C) → LimCone D\n\n\n-- Preservation of limits\n\nmodule _ {ℓJ ℓJ' ℓC1 ℓC1' ℓC2 ℓC2' : Level}\n {C1 : Category ℓC1 ℓC1'} {C2 : Category ℓC2 ℓC2'}\n (F : Functor C1 C2) where\n open Category\n open Functor\n open Cone\n\n private\n ℓ = ℓ-max (ℓ-max (ℓ-max (ℓ-max (ℓ-max ℓJ ℓJ') ℓC1) ℓC1') ℓC2) ℓC2'\n\n mapCone : {J : Category ℓJ ℓJ'} (D : Functor J C1) {x : ob C1} (ccx : Cone D x) → Cone (funcComp F D) (F .F-ob x)\n coneOut (mapCone D ccx) v = F .F-hom (coneOut ccx v)\n coneOutCommutes (mapCone D ccx) e =\n sym (F-seq F (coneOut ccx _) (D ⟪ e ⟫)) ∙ cong (F .F-hom) (coneOutCommutes ccx e)\n\n preservesLimit : {J : Category ℓJ ℓJ'} (D : Functor J C1)\n → (L : ob C1) → Cone D L → Type ℓ\n preservesLimit D L ccL =\n isLimCone D L ccL → isLimCone (funcComp F D) (F .F-ob L) (mapCone D ccL)\n\n -- TODO: prove that right adjoints preserve limits\n", "meta": {"hexsha": "8ba2e7db0befe6a6a7caa1cc3811a409013f178e", "size": 6081, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Categories/Limits/Limits.agda", "max_stars_repo_name": "howsiyu/cubical", "max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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": "Cubical/Categories/Limits/Limits.agda", "max_issues_repo_name": "howsiyu/cubical", "max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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": "Cubical/Categories/Limits/Limits.agda", "max_forks_repo_name": "howsiyu/cubical", "max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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.9807692308, "max_line_length": 115, "alphanum_fraction": 0.5507317875, "num_tokens": 2553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081926, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3908901156725146}} {"text": "------------------------------------------------------------------------\n-- Identity and composition for higher lenses\n------------------------------------------------------------------------\n\n{-# OPTIONS --cubical #-}\n\nimport Equality.Path as P\n\nmodule Lens.Non-dependent.Higher.Combinators\n {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where\n\nopen P.Derived-definitions-and-properties eq\n\nimport Bi-invertibility\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude as P hiding (id) renaming (_∘_ to _⊚_)\n\nopen import Bijection equality-with-J as Bij using (_↔_)\nopen import Category equality-with-J as C using (Category; Precategory)\nimport Circle eq as Circle\nopen import Equality.Path.Isomorphisms eq\nopen import Equivalence equality-with-J as Eq\n using (_≃_; Is-equivalence)\nopen import Function-universe equality-with-J as F hiding (id; _∘_)\nopen import H-level equality-with-J as H-level\nopen import H-level.Closure equality-with-J\nopen import H-level.Truncation.Propositional eq as Trunc\nopen import Surjection equality-with-J using (_↠_)\nopen import Univalence-axiom equality-with-J\n\nopen import Lens.Non-dependent.Higher eq\nimport Lens.Non-dependent.Traditional eq as Traditional\nopen import Lens.Non-dependent.Traditional.Combinators eq as TC\n using (Naive-category; Univalent)\n\nprivate\n variable\n a b c d : Level\n A B C : Type a\n\n------------------------------------------------------------------------\n-- Lens combinators\n\n-- The definition of the identity lens is unique, if the get\n-- function is required to be the identity (assuming univalence).\n\nid-unique :\n {A : Type a} →\n Univalence a →\n (l₁ l₂ : Lens A A) →\n Lens.get l₁ ≡ P.id →\n Lens.get l₂ ≡ P.id →\n l₁ ≡ l₂\nid-unique {A = A} univ l₁ l₂ get-l₁≡id get-l₂≡id = $⟨ trans get-l₁≡id (sym get-l₂≡id) ⟩\n _≃_.to (_≃_.from f l₁′) ≡ _≃_.to (_≃_.from f l₂′) ↝⟨ Eq.lift-equality ext ⟩\n _≃_.from f l₁′ ≡ _≃_.from f l₂′ ↝⟨ _≃_.to $ Eq.≃-≡ (inverse f) {x = l₁′} {y = l₂′} ⟩\n l₁′ ≡ l₂′ ↝⟨ cong proj₁ ⟩□\n l₁ ≡ l₂ □\n where\n open Lens\n\n f : (A ≃ A) ≃ (∃ λ (l : Lens A A) → Is-equivalence (Lens.get l))\n f = ≃-≃-Σ-Lens-Is-equivalence-get univ\n\n is-equiv :\n (l : Lens A A) →\n get l ≡ P.id → Is-equivalence (get l)\n is-equiv _ get≡id =\n Eq.respects-extensional-equality\n (ext⁻¹ $ sym get≡id)\n (_≃_.is-equivalence Eq.id)\n\n l₁′ l₂′ : ∃ λ (l : Lens A A) → Is-equivalence (Lens.get l)\n l₁′ = l₁ , is-equiv l₁ get-l₁≡id\n l₂′ = l₂ , is-equiv l₂ get-l₂≡id\n\n-- The result of composing two lenses is unique if the codomain type\n-- is inhabited whenever it is merely inhabited, and we require that\n-- the resulting setter function is defined in a certain way\n-- (assuming univalence).\n\n∘-unique :\n let open Lens in\n {A : Type a} {C : Type c} →\n Univalence (a ⊔ c) →\n (∥ C ∥ → C) →\n ((comp₁ , _) (comp₂ , _) :\n ∃ λ (comp : Lens B C → Lens A B → Lens A C) →\n ∀ l₁ l₂ a c →\n set (comp l₁ l₂) a c ≡ set l₂ a (set l₁ (get l₂ a) c)) →\n comp₁ ≡ comp₂\n∘-unique {A = A} {C = C} univ ∥C∥→C\n (comp₁ , set₁) (comp₂ , set₂) =\n ⟨ext⟩ λ l₁ → ⟨ext⟩ λ l₂ →\n lenses-equal-if-setters-equal univ\n (comp₁ l₁ l₂) (comp₂ l₁ l₂) (λ _ → ∥C∥→C) $\n ⟨ext⟩ λ a → ⟨ext⟩ λ c →\n set (comp₁ l₁ l₂) a c ≡⟨ set₁ _ _ _ _ ⟩\n set l₂ a (set l₁ (get l₂ a) c) ≡⟨ sym $ set₂ _ _ _ _ ⟩∎\n set (comp₂ l₁ l₂) a c ∎\n where\n open Lens\n\n-- Identity lens.\n\nid : Block \"id\" → Lens A A\nid {A = A} ⊠ = record\n { R = ∥ A ∥\n ; equiv = A ↔⟨ inverse ∥∥×↔ ⟩□\n ∥ A ∥ × A □\n ; inhabited = P.id\n }\n\n-- Composition of lenses.\n--\n-- Note that the domains are required to be at least as large as the\n-- codomains; this should match many use-cases. Without this\n-- restriction I failed to find a satisfactory definition of\n-- composition. (I suspect that if Agda had had cumulativity, then\n-- the domain and codomain could have lived in the same universe\n-- without any problems.)\n--\n-- The composition operation matches on the lenses to ensure that it\n-- does not unfold when applied to neutral lenses.\n--\n-- See also Lens.Non-dependent.Equivalent-preimages.⟨_⟩_⊚_.\n\ninfix 9 ⟨_,_⟩_∘_\n\n⟨_,_⟩_∘_ :\n ∀ a b {A : Type (a ⊔ b ⊔ c)} {B : Type (b ⊔ c)} {C : Type c} →\n Lens B C → Lens A B → Lens A C\n⟨_,_⟩_∘_ _ _ {A = A} {B} {C} l₁@(⟨ _ , _ , _ ⟩) l₂@(⟨ _ , _ , _ ⟩) =\n record\n { R = R l₂ × R l₁\n ; equiv = A ↝⟨ equiv l₂ ⟩\n R l₂ × B ↝⟨ F.id ×-cong equiv l₁ ⟩\n R l₂ × (R l₁ × C) ↔⟨ ×-assoc ⟩□\n (R l₂ × R l₁) × C □\n ; inhabited = ∥∥-map (get l₁) ⊚ inhabited l₂ ⊚ proj₁\n }\n where\n open Lens\n\n-- The composition operation implements set in a certain way.\n\n∘-set :\n let open Lens in\n ∀ ℓa ℓb {A : Type (ℓa ⊔ ℓb ⊔ c)} {B : Type (ℓb ⊔ c)} {C : Type c}\n (l₁ : Lens B C) (l₂ : Lens A B) a c →\n set (⟨ ℓa , ℓb ⟩ l₁ ∘ l₂) a c ≡ set l₂ a (set l₁ (get l₂ a) c)\n∘-set _ _ ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ _ _ = refl _\n\n-- A variant of composition for lenses between types with the same\n-- universe level.\n\ninfixr 9 _∘_\n\n_∘_ :\n {A B C : Type a} →\n Lens B C → Lens A B → Lens A C\nl₁ ∘ l₂ = ⟨ lzero , lzero ⟩ l₁ ∘ l₂\n\n-- Other definitions of composition match ⟨_,_⟩_∘_, if the codomain\n-- type is inhabited whenever it is merely inhabited, and the\n-- resulting setter function is defined in a certain way (assuming\n-- univalence).\n\ncomposition≡∘ :\n let open Lens in\n ∀ a b {A : Type (a ⊔ b ⊔ c)} {B : Type (b ⊔ c)} {C : Type c} →\n Univalence (a ⊔ b ⊔ c) →\n (∥ C ∥ → C) →\n (comp : Lens B C → Lens A B → Lens A C) →\n (∀ l₁ l₂ a c →\n set (comp l₁ l₂) a c ≡ set l₂ a (set l₁ (get l₂ a) c)) →\n comp ≡ ⟨ a , b ⟩_∘_\ncomposition≡∘ _ _ univ ∥C∥→C comp set-comp =\n ∘-unique univ ∥C∥→C (comp , set-comp)\n (_ , λ { ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ _ _ → refl _ })\n\n-- Identity and composition form a kind of precategory (assuming\n-- univalence).\n\nassociativity :\n ∀ a b c\n {A : Type (a ⊔ b ⊔ c ⊔ d)} {B : Type (b ⊔ c ⊔ d)}\n {C : Type (c ⊔ d)} {D : Type d} →\n Univalence (a ⊔ b ⊔ c ⊔ d) →\n (l₁ : Lens C D) (l₂ : Lens B C) (l₃ : Lens A B) →\n ⟨ a ⊔ b , c ⟩ l₁ ∘ (⟨ a , b ⟩ l₂ ∘ l₃) ≡\n ⟨ a , b ⊔ c ⟩ (⟨ b , c ⟩ l₁ ∘ l₂) ∘ l₃\nassociativity _ _ _ univ ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ =\n _↔_.from (equality-characterisation₁ ⊠ univ)\n (Eq.↔⇒≃ (inverse ×-assoc) , λ _ → refl _)\n\nleft-identity :\n ∀ bi a {A : Type (a ⊔ b)} {B : Type b} →\n Univalence (a ⊔ b) →\n (l : Lens A B) →\n ⟨ a , lzero ⟩ id bi ∘ l ≡ l\nleft-identity ⊠ _ {B = B} univ l@(⟨ _ , _ , _ ⟩) =\n _↔_.from (equality-characterisation₁ ⊠ univ)\n ( (R × ∥ B ∥ ↔⟨ lemma ⟩□\n R □)\n , λ _ → refl _\n )\n where\n open Lens l\n\n lemma : R × ∥ B ∥ ↔ R\n lemma = record\n { surjection = record\n { logical-equivalence = record\n { to = proj₁\n ; from = λ r → r , inhabited r\n }\n ; right-inverse-of = refl\n }\n ; left-inverse-of = λ { (r , _) →\n cong (λ x → r , x) $ truncation-is-proposition _ _ }\n }\n\nright-identity :\n ∀ bi a {A : Type (a ⊔ b)} {B : Type b} →\n Univalence (a ⊔ b) →\n (l : Lens A B) →\n ⟨ lzero , a ⟩ l ∘ id bi ≡ l\nright-identity ⊠ _ {A = A} univ l@(⟨ _ , _ , _ ⟩) =\n _↔_.from (equality-characterisation₁ ⊠ univ)\n ( (∥ A ∥ × R ↔⟨ lemma ⟩□\n R □)\n , λ _ → refl _\n )\n where\n open Lens l\n\n lemma : ∥ A ∥ × R ↔ R\n lemma = record\n { surjection = record\n { logical-equivalence = record\n { to = proj₂\n ; from = λ r → ∥∥-map (λ b → _≃_.from equiv (r , b))\n (inhabited r)\n , r\n }\n ; right-inverse-of = refl\n }\n ; left-inverse-of = λ { (_ , r) →\n cong (λ x → x , r) $ truncation-is-proposition _ _ }\n }\n\n------------------------------------------------------------------------\n-- Isomorphisms expressed using lens quasi-inverses\n\nprivate\n module B {a} (b : Block \"id\") =\n Bi-invertibility equality-with-J (Type a) Lens (id b) _∘_\n module BM {a} (b : Block \"id\") (univ : Univalence a) = B.More\n b\n (left-identity b _ univ)\n (right-identity b _ univ)\n (associativity _ _ _ univ)\n\n-- A form of isomorphism between types, expressed using lenses.\n\nopen B public\n using ()\n renaming (_≅_ to [_]_≅_;\n Has-quasi-inverse to Has-quasi-inverse)\n\n-- Lenses with quasi-inverses can be converted to equivalences.\n\n≅→≃ : ∀ b → [ b ] A ≅ B → A ≃ B\n≅→≃\n ⊠\n (l@(⟨ _ , _ , _ ⟩) , l⁻¹@(⟨ _ , _ , _ ⟩) , l∘l⁻¹≡id , l⁻¹∘l≡id) =\n Eq.↔⇒≃ (record\n { surjection = record\n { logical-equivalence = record\n { to = get l\n ; from = get l⁻¹\n }\n ; right-inverse-of = λ b → cong (λ l → get l b) l∘l⁻¹≡id\n }\n ; left-inverse-of = λ a → cong (λ l → get l a) l⁻¹∘l≡id\n })\n where\n open Lens\n\n-- There is a split surjection from [ b ] A ≅ B to A ≃ B (assuming\n-- univalence).\n\n≅↠≃ :\n {A B : Type a}\n (b : Block \"id\") →\n Univalence a →\n ([ b ] A ≅ B) ↠ (A ≃ B)\n≅↠≃ {A = A} {B = B} b univ = record\n { logical-equivalence = record\n { to = ≅→≃ b\n ; from = from b\n }\n ; right-inverse-of = ≅→≃∘from b\n }\n where\n from : ∀ b → A ≃ B → [ b ] A ≅ B\n from b A≃B = l , l⁻¹ , l∘l⁻¹≡id b , l⁻¹∘l≡id b\n where\n l = ≃→lens′ A≃B\n l⁻¹ = ≃→lens′ (inverse A≃B)\n\n l∘l⁻¹≡id : ∀ b → l ∘ l⁻¹ ≡ id b\n l∘l⁻¹≡id ⊠ = _↔_.from (equality-characterisation₁ ⊠ univ)\n ( (∥ A ∥ × ∥ B ∥ ↝⟨ Eq.⇔→≃\n (×-closure 1 truncation-is-proposition\n truncation-is-proposition)\n truncation-is-proposition\n proj₂\n (λ b → ∥∥-map (_≃_.from A≃B) b , b) ⟩\n ∥ B ∥ □)\n , λ _ → cong₂ _,_\n (truncation-is-proposition _ _)\n (_≃_.right-inverse-of A≃B _)\n )\n\n l⁻¹∘l≡id : ∀ b → l⁻¹ ∘ l ≡ id b\n l⁻¹∘l≡id ⊠ = _↔_.from (equality-characterisation₁ ⊠ univ)\n ( (∥ B ∥ × ∥ A ∥ ↝⟨ Eq.⇔→≃\n (×-closure 1 truncation-is-proposition\n truncation-is-proposition)\n truncation-is-proposition\n proj₂\n (λ a → ∥∥-map (_≃_.to A≃B) a , a) ⟩\n ∥ A ∥ □)\n , λ _ → cong₂ _,_\n (truncation-is-proposition _ _)\n (_≃_.left-inverse-of A≃B _)\n )\n\n ≅→≃∘from : ∀ b A≃B → ≅→≃ b (from b A≃B) ≡ A≃B\n ≅→≃∘from ⊠ _ = Eq.lift-equality ext (refl _)\n\n-- There is not necessarily a split surjection from\n-- Is-equivalence (Lens.get l) to Has-quasi-inverse l, if l is a\n-- lens between types in the same universe (assuming univalence).\n\n¬Is-equivalence-get↠Has-quasi-inverse :\n (b : Block \"id\") →\n Univalence a →\n ¬ ({A B : Type a}\n (l : Lens A B) →\n Is-equivalence (Lens.get l) ↠ Has-quasi-inverse b l)\n¬Is-equivalence-get↠Has-quasi-inverse b univ surj =\n $⟨ ⊤-contractible ⟩\n Contractible ⊤ ↝⟨ H-level.respects-surjection lemma₃ 0 ⟩\n Contractible ((z : Z) → z ≡ z) ↝⟨ mono₁ 0 ⟩\n Is-proposition ((z : Z) → z ≡ z) ↝⟨ ¬-prop ⟩□\n ⊥ □\n where\n open Lens\n\n Z,¬-prop = Circle.¬-type-of-refl-propositional\n Z = proj₁ Z,¬-prop\n ¬-prop = proj₂ Z,¬-prop\n\n lemma₂ :\n ∀ b →\n (∃ λ (eq : R (id b) ≃ R (id b)) →\n (∀ z → _≃_.to eq (remainder (id b) z) ≡ remainder (id b) z)\n ×\n ((z : Z) → get (id b) z ≡ get (id b) z)) ≃\n ((z : Z) → z ≡ z)\n lemma₂ ⊠ =\n (∃ λ (eq : ∥ Z ∥ ≃ ∥ Z ∥) →\n ((z : Z) → _≃_.to eq ∣ z ∣ ≡ ∣ z ∣)\n ×\n ((z : Z) → z ≡ z)) ↔⟨ (∃-cong λ _ → drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $\n Π-closure ext 0 λ _ →\n +⇒≡ truncation-is-proposition) ⟩\n\n (∥ Z ∥ ≃ ∥ Z ∥) × ((z : Z) → z ≡ z) ↔⟨ drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $\n propositional⇒inhabited⇒contractible\n (Eq.left-closure ext 0 truncation-is-proposition)\n F.id ⟩□\n ((z : Z) → z ≡ z) □\n\n lemma₃ =\n ⊤ ↔⟨ inverse $ _⇔_.to contractible⇔↔⊤ $\n propositional⇒inhabited⇒contractible\n (Eq.propositional ext _)\n (_≃_.is-equivalence Eq.id) ⟩\n\n Is-equivalence P.id ↔⟨ ≡⇒↝ equivalence $ cong Is-equivalence $\n unblock b (λ b → _ ≡ get (id b)) (refl _) ⟩\n\n Is-equivalence (get (id b)) ↝⟨ surj (id b) ⟩\n\n Has-quasi-inverse b (id b) ↔⟨ BM.Has-quasi-inverse≃id≡id-domain b univ\n (id b , left-identity b _ univ _ , right-identity b _ univ _) ⟩\n\n id b ≡ id b ↔⟨ equality-characterisation₂ ⊠ univ ⟩\n\n (∃ λ (eq : R (id b) ≃ R (id b)) →\n (∀ z → _≃_.to eq (remainder (id b) z) ≡ remainder (id b) z)\n ×\n (∀ z → get (id b) z ≡ get (id b) z)) ↔⟨ lemma₂ b ⟩□\n\n ((z : Z) → z ≡ z) □\n\n-- See also ≃≃≅ below.\n\n------------------------------------------------------------------------\n-- Equivalences expressed using bi-invertibility for lenses\n\n-- A form of equivalence between types, expressed using lenses.\n\nopen B public\n using ()\n renaming (_≊_ to [_]_≊_;\n Has-left-inverse to Has-left-inverse;\n Has-right-inverse to Has-right-inverse;\n Is-bi-invertible to Is-bi-invertible)\nopen BM public\n using ()\n renaming (equality-characterisation-≊ to equality-characterisation-≊)\n\n-- Lenses with left inverses have propositional remainder types.\n\nhas-left-inverse→remainder-propositional :\n (b : Block \"id\")\n (l : Lens A B) →\n Has-left-inverse b l →\n Is-proposition (Lens.R l)\nhas-left-inverse→remainder-propositional\n ⊠ l@(⟨ _ , _ , _ ⟩) (l⁻¹@(⟨ _ , _ , _ ⟩) , l⁻¹∘l≡id) =\n $⟨ get≡id→remainder-propositional\n (l⁻¹ ∘ l)\n (λ a → cong (flip get a) l⁻¹∘l≡id) ⟩\n Is-proposition (R (l⁻¹ ∘ l)) ↔⟨⟩\n Is-proposition (R l × R l⁻¹) ↝⟨ H-level-×₁ (∥∥-map (remainder l⁻¹) ⊚ inhabited l) 1 ⟩□\n Is-proposition (R l) □\n where\n open Lens\n\n-- Lenses with right inverses have propositional remainder types.\n\nhas-right-inverse→remainder-propositional :\n (b : Block \"id\")\n (l : Lens A B) →\n Has-right-inverse b l →\n Is-proposition (Lens.R l)\nhas-right-inverse→remainder-propositional\n ⊠ l@(⟨ _ , _ , _ ⟩) (l⁻¹@(⟨ _ , _ , _ ⟩) , l∘l⁻¹≡id) =\n $⟨ get≡id→remainder-propositional\n (l ∘ l⁻¹)\n (λ a → cong (flip get a) l∘l⁻¹≡id) ⟩\n Is-proposition (R (l ∘ l⁻¹)) ↔⟨⟩\n Is-proposition (R l⁻¹ × R l) ↝⟨ H-level-×₂ (∥∥-map (remainder l⁻¹) ⊚ inhabited l) 1 ⟩□\n Is-proposition (R l) □\n where\n open Lens\n\n-- There is an equivalence between A ≃ B and [ b ] A ≊ B (assuming\n-- univalence).\n\n≃≃≊ :\n {A B : Type a}\n (b : Block \"id\") →\n Univalence a →\n (A ≃ B) ≃ ([ b ] A ≊ B)\n≃≃≊ {A = A} {B = B} b univ = Eq.↔⇒≃ (record\n { surjection = record\n { logical-equivalence = record\n { to = to b\n ; from = from b\n }\n ; right-inverse-of = to∘from b\n }\n ; left-inverse-of = from∘to b\n })\n where\n open Lens\n\n to : ∀ b → A ≃ B → [ b ] A ≊ B\n to b = B.≅→≊ b ⊚ _↠_.from (≅↠≃ b univ)\n\n from : ∀ b → [ b ] A ≊ B → A ≃ B\n from b = _↠_.to (≅↠≃ b univ) ⊚ _↠_.from (BM.≅↠≊ b univ)\n\n to∘from : ∀ b A≊B → to b (from b A≊B) ≡ A≊B\n to∘from b A≊B =\n _≃_.from (equality-characterisation-≊ b univ _ _) $\n _↔_.from (equality-characterisation₂ b univ)\n ( ∥B∥≃R b A≊B\n , lemma₁ b A≊B\n , lemma₂ b A≊B\n )\n where\n l′ : ∀ b (A≊B : [ b ] A ≊ B) → Lens A B\n l′ b A≊B = proj₁ (to b (from b A≊B))\n\n ∥B∥≃R : ∀ b (A≊B@(l , _) : [ b ] A ≊ B) → ∥ B ∥ ≃ R l\n ∥B∥≃R b (l , (l-inv@(l⁻¹ , _) , _)) = Eq.⇔→≃\n truncation-is-proposition\n R-prop\n (Trunc.rec R-prop (remainder l ⊚ get l⁻¹))\n (inhabited l)\n where\n R-prop = has-left-inverse→remainder-propositional b l l-inv\n\n lemma₁ :\n ∀ b (A≊B@(l , _) : [ b ] A ≊ B) a →\n _≃_.to (∥B∥≃R b A≊B) (remainder (l′ b A≊B) a) ≡ remainder l a\n lemma₁\n ⊠\n ( l@(⟨ _ , _ , _ ⟩)\n , (l⁻¹@(⟨ _ , _ , _ ⟩) , l⁻¹∘l≡id)\n , (⟨ _ , _ , _ ⟩ , _)\n ) a =\n remainder l (get l⁻¹ (get l a)) ≡⟨⟩\n remainder l (get (l⁻¹ ∘ l) a) ≡⟨ cong (λ l′ → remainder l (get l′ a)) l⁻¹∘l≡id ⟩\n remainder l (get (id ⊠) a) ≡⟨⟩\n remainder l a ∎\n\n lemma₂ :\n ∀ b (A≊B@(l , _) : [ b ] A ≊ B) a →\n get (l′ b A≊B) a ≡ get l a\n lemma₂ ⊠\n (⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) _ =\n refl _\n\n from∘to :\n ∀ b A≃B →\n _↠_.to (≅↠≃ b univ) (_↠_.from (BM.≅↠≊ b univ)\n (B.≅→≊ b (_↠_.from (≅↠≃ b univ) A≃B))) ≡\n A≃B\n from∘to ⊠ _ = Eq.lift-equality ext (refl _)\n\n-- The right-to-left direction of ≃≃≊ maps bi-invertible lenses to\n-- their getter functions.\n\nto-from-≃≃≊≡get :\n (b : Block \"id\")\n (univ : Univalence a)\n (A≊B@(l , _) : [ b ] A ≊ B) →\n _≃_.to (_≃_.from (≃≃≊ b univ) A≊B) ≡ Lens.get l\nto-from-≃≃≊≡get\n ⊠ _ (⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =\n refl _\n\n-- A variant of ≃≃≊ that works even if A and B live in different\n-- universes.\n--\n-- This variant came up in a discussion with Andrea Vezzosi.\n\n≃≃≊′ :\n {A : Type a} {B : Type b}\n (b-id : Block \"id\") →\n Univalence (a ⊔ b) →\n (A ≃ B) ≃ ([ b-id ] ↑ b A ≊ ↑ a B)\n≃≃≊′ {a = a} {b = b} {A = A} {B = B} b-id univ =\n A ≃ B ↔⟨ inverse $ Eq.≃-preserves-bijections ext Bij.↑↔ Bij.↑↔ ⟩\n ↑ b A ≃ ↑ a B ↝⟨ ≃≃≊ b-id univ ⟩□\n [ b-id ] ↑ b A ≊ ↑ a B □\n\n-- The right-to-left direction of ≃≃≊′ maps bi-invertible lenses to a\n-- variant of their getter functions.\n\nto-from-≃≃≊′≡get :\n {A : Type a} {B : Type b}\n (b-id : Block \"id\")\n (univ : Univalence (a ⊔ b)) →\n (A≊B@(l , _) : [ b-id ] ↑ b A ≊ ↑ a B) →\n _≃_.to (_≃_.from (≃≃≊′ b-id univ) A≊B) ≡ lower ⊚ Lens.get l ⊚ lift\nto-from-≃≃≊′≡get\n ⊠ _ (⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =\n refl _\n\n-- The getter function of a bi-invertible lens is an equivalence\n-- (assuming univalence).\n\nIs-bi-invertible→Is-equivalence-get :\n {A : Type a}\n (b : Block \"id\") →\n Univalence a →\n (l : Lens A B) →\n Is-bi-invertible b l → Is-equivalence (Lens.get l)\nIs-bi-invertible→Is-equivalence-get\n b@⊠ univ l@(⟨ _ , _ , _ ⟩)\n is-bi-inv@((⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =\n _≃_.is-equivalence (_≃_.from (≃≃≊ b univ) (l , is-bi-inv))\n\n-- If l is a lens between types in the same universe, then there is an\n-- equivalence between \"l is bi-invertible\" and \"the getter of l is an\n-- equivalence\" (assuming univalence).\n\nIs-bi-invertible≃Is-equivalence-get :\n {A B : Type a}\n (b : Block \"id\") →\n Univalence a →\n (l : Lens A B) →\n Is-bi-invertible b l ≃ Is-equivalence (Lens.get l)\nIs-bi-invertible≃Is-equivalence-get b univ l = Eq.⇔→≃\n (BM.Is-bi-invertible-propositional b univ l)\n (Eq.propositional ext _)\n (Is-bi-invertible→Is-equivalence-get b univ l)\n (λ is-equiv →\n\n let l′ = ≃→lens′ Eq.⟨ get l , is-equiv ⟩ in\n\n $⟨ proj₂ (_≃_.to (≃≃≊ b univ) Eq.⟨ _ , is-equiv ⟩) ⟩\n Is-bi-invertible b l′ ↝⟨ subst (Is-bi-invertible b) (sym $ get-equivalence→≡≃→lens′ univ l is-equiv) ⟩□\n Is-bi-invertible b l □)\n where\n open Lens\n\n-- If A is a set, then there is an equivalence between [ b ] A ≊ B and\n-- [ b ] A ≅ B (assuming univalence).\n\n≊≃≅ :\n {A B : Type a}\n (b : Block \"id\") →\n Univalence a →\n Is-set A →\n ([ b ] A ≊ B) ≃ ([ b ] A ≅ B)\n≊≃≅ b univ A-set =\n ∃-cong λ _ →\n BM.Is-bi-invertible≃Has-quasi-inverse-domain\n b univ\n (Is-set-closed-domain univ A-set)\n\n------------------------------------------------------------------------\n-- A category\n\n-- If A is a set, then there is an equivalence between A ≃ B and\n-- [ b ] A ≅ B (assuming univalence).\n\n≃≃≅ :\n {A B : Type a}\n (b : Block \"≃≃≅\") →\n Univalence a →\n Is-set A →\n (A ≃ B) ≃ ([ b ] A ≅ B)\n≃≃≅ {A = A} {B = B} b@⊠ univ A-set =\n A ≃ B ↝⟨ ≃≃≊ b univ ⟩\n [ b ] A ≊ B ↝⟨ ≊≃≅ b univ A-set ⟩□\n [ b ] A ≅ B □\n\n-- The equivalence ≃≃≅ maps identity to identity.\n\n≃≃≅-id≡id :\n {A : Type a}\n (b : Block \"≃≃≅\") (univ : Univalence a) (A-set : Is-set A) →\n proj₁ (_≃_.to (≃≃≅ b univ A-set) F.id) ≡ id b\n≃≃≅-id≡id ⊠ univ _ =\n _↔_.from (equality-characterisation₁ ⊠ univ)\n (F.id , λ _ → refl _)\n\n-- Lenses between sets in the same universe form a precategory\n-- (assuming univalence).\n\nprivate\n\n precategory′ :\n Block \"id\" →\n Univalence a →\n C.Precategory′ (lsuc a) (lsuc a)\n precategory′ {a = a} b univ =\n Set a\n , (λ (A , A-set) (B , _) →\n Lens A B\n , Is-set-closed-domain univ A-set)\n , id b\n , _∘_\n , left-identity b lzero univ _\n , right-identity b lzero univ _\n , (λ {_ _ _ _ l₁ l₂ l₃} →\n associativity lzero lzero lzero univ l₃ l₂ l₁)\n\nprecategory :\n Block \"precategory\" →\n Univalence a →\n Precategory (lsuc a) (lsuc a)\nprecategory ⊠ univ .C.Precategory.precategory =\n block λ b → precategory′ b univ\n\n-- Lenses between sets in the same universe form a category\n-- (assuming univalence).\n\ncategory :\n Block \"category\" →\n Univalence a →\n Category (lsuc a) (lsuc a)\ncategory ⊠ univ =\n block λ b →\n C.precategory-with-Set-to-category\n ext\n (λ _ _ → univ)\n (proj₂ $ precategory′ b univ)\n (λ (_ , A-set) _ → ≃≃≅ b univ A-set)\n (λ (_ , A-set) → ≃≃≅-id≡id b univ A-set)\n\n-- The precategory defined here is equal to the one defined in\n-- Traditional, if the latter one is lifted (assuming univalence).\n\nprecategory≡precategory :\n (b : Block \"precategory\") →\n Univalence (lsuc a) →\n (univ : Univalence a) →\n precategory b univ ≡\n C.lift-precategory-Hom _ TC.precategory\nprecategory≡precategory ⊠ univ⁺ univ =\n block λ b →\n _↔_.to (C.equality-characterisation-Precategory ext univ⁺ univ⁺)\n ( F.id\n , (λ (X , X-set) (Y , _) →\n Lens X Y ↔⟨ Lens↔Traditional-lens b univ X-set ⟩\n Traditional.Lens X Y ↔⟨ inverse Bij.↑↔ ⟩□\n ↑ _ (Traditional.Lens X Y) □)\n , (λ (_ , X-set) → cong lift $ _↔_.from\n (Traditional.equality-characterisation-for-sets X-set)\n (refl _))\n , (λ (_ , X-set) (_ , Y-set) _ (lift l₁) (lift l₂) →\n cong lift (∘-lemma b X-set Y-set l₁ l₂))\n )\n where\n ∘-lemma :\n ∀ b (A-set : Is-set A) (B-set : Is-set B)\n (l₁ : Traditional.Lens B C) (l₂ : Traditional.Lens A B) →\n Lens.traditional-lens\n (_↠_.from (Lens↠Traditional-lens b B-set) l₁ ∘\n _↠_.from (Lens↠Traditional-lens b A-set) l₂) ≡\n l₁ TC.∘ l₂\n ∘-lemma ⊠ A-set _ _ _ =\n _↔_.from (Traditional.equality-characterisation-for-sets A-set)\n (refl _)\n\n-- The category defined here is equal to the one defined in\n-- Traditional, if the latter one is lifted (assuming univalence).\n\ncategory≡category :\n (b : Block \"category\") →\n Univalence (lsuc a) →\n (univ : Univalence a) →\n category b univ ≡\n C.lift-category-Hom _ (TC.category univ)\ncategory≡category b univ⁺ univ =\n _↔_.from (C.≡↔precategory≡precategory ext)\n (Category.precategory (category b univ) ≡⟨ lemma b ⟩\n\n precategory b univ ≡⟨ precategory≡precategory b univ⁺ univ ⟩∎\n\n Category.precategory\n (C.lift-category-Hom _ (TC.category univ)) ∎)\n where\n lemma :\n ∀ b →\n Category.precategory (category b univ) ≡\n precategory b univ\n lemma ⊠ = refl _\n\n-- Types in a fixed universe and higher lenses between them form a\n-- naive category (assuming univalence).\n\nnaive-category :\n Block \"id\" →\n Univalence a →\n Naive-category (lsuc a) (lsuc a)\nnaive-category {a = a} b univ =\n Type a\n , Lens\n , id b\n , _∘_\n , left-identity b lzero univ\n , right-identity b lzero univ\n , associativity lzero lzero lzero univ\n\n-- This category is univalent.\n--\n-- An anonymous reviewer asked if something like this could be proved,\n-- given ≃≃≊. The proof of this result is due to Andrea Vezzosi.\n\nunivalent :\n (b : Block \"id\")\n (univ : Univalence a) →\n Univalent (naive-category b univ)\nunivalent b univ =\n BM.≡≃≊→Univalence-≊ b univ λ {A B} →\n A ≡ B ↝⟨ ≡≃≃ univ ⟩\n A ≃ B ↝⟨ ≃≃≊ b univ ⟩□\n [ b ] A ≊ B □\n", "meta": {"hexsha": "89bc669948aa7a089a907cdcbe8358a07b943e19", "size": 25032, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Lens/Non-dependent/Higher/Combinators.agda", "max_stars_repo_name": "nad/dependent-lenses", "max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z", "max_issues_repo_path": "src/Lens/Non-dependent/Higher/Combinators.agda", "max_issues_repo_name": "nad/dependent-lenses", "max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "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/Lens/Non-dependent/Higher/Combinators.agda", "max_forks_repo_name": "nad/dependent-lenses", "max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z", "avg_line_length": 31.5662042875, "max_line_length": 136, "alphanum_fraction": 0.4999600511, "num_tokens": 9466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3906929160345561}} {"text": "-- Andreas, 2011-10-04, transcription of Dan Doel's post on the Agda list\n{-# OPTIONS --experimental-irrelevance #-}\nmodule IrrelevantMatchRefl where\n\npostulate\n Level : Set\n lzero : Level\n lsuc : (i : Level) → Level\n _⊔_ : Level -> Level -> Level\n\n{-# BUILTIN LEVEL Level #-}\n{-# BUILTIN LEVELZERO lzero #-}\n{-# BUILTIN LEVELSUC lsuc #-}\n{-# BUILTIN LEVELMAX _⊔_ #-}\n\ninfixl 6 _⊔_\n\ndata _≡_ {i : Level}{A : Set i}(a : A) : A → Set where\n refl : a ≡ a\n\nsym : ∀ {i}{A B : Set i} → A ≡ B → B ≡ A\nsym refl = refl\n\n-- irrelevant subst should be rejected, because it suggests\n-- that the equality proof is irrelevant also for reduction\nsubst : ∀ {i j}{A : Set i}(P : A → Set j){a b : A} → .(a ≡ b) → P a → P b\nsubst P refl x = x\n\npostulate\n D : Set\n lie : (D → D) ≡ D\n\n-- the following two substs may not reduce! ...\nabs : (D → D) → D\nabs f = subst (λ T → T) lie f\n\napp : D → D → D\napp d = subst (λ T → T) (sym lie) d\n\nω : D\nω = abs (λ d → app d d)\n\n-- ... otherwise Ω loops\nΩ : D\nΩ = app ω ω\n\n-- ... and this would be a real fixed-point combinator\nY : (D → D) → D\nY f = app δ δ\n where δ = abs (λ x → f (app x x)) \n\nK : D → D\nK x = abs (λ y → x)\n\nK∞ : D\nK∞ = Y K \n\nmayloop : K∞ ≡ abs (λ y → K∞)\nmayloop = refl\n-- gives error D != D → D\n", "meta": {"hexsha": "c75f369bff6e2f168a8325bd19c8b1f9f42fdb7b", "size": 1253, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/fail/IrrelevantMatchRefl.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-27T07:26:06.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-27T07:26:06.000Z", "max_issues_repo_path": "test/fail/IrrelevantMatchRefl.agda", "max_issues_repo_name": "dagit/agda", "max_issues_repo_head_hexsha": "4383a3d20328a6c43689161496cee8eb479aca08", "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/IrrelevantMatchRefl.agda", "max_forks_repo_name": "dagit/agda", "max_forks_repo_head_hexsha": "4383a3d20328a6c43689161496cee8eb479aca08", "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": 20.5409836066, "max_line_length": 73, "alphanum_fraction": 0.5642458101, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837635542924, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.3906873192327603}} {"text": "\n-- By Philipp Hausmann.\n\nopen import Agda.Builtin.Bool\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Float\n\ndata ⊥ : Set where\n\n_/_ = primFloatDiv\n_<_ = primFloatNumericalLess\n\ncong : {A B : Set} {x y : A} (f : A → B) → x ≡ y → f x ≡ f y\ncong f refl = refl\n\n0eq : 0.0 ≡ -0.0\n0eq = refl\n\nbug : ⊥\nbug = f (cong (λ x → (1.0 / x) < 0.0) 0eq)\n where\n f : false ≡ true → ⊥\n f ()\n", "meta": {"hexsha": "5371388c8a861cba9170149414fe7fb279fbe078", "size": 394, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue2169.agda", "max_stars_repo_name": "hborum/agda", "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_issues_repo_path": "test/Fail/Issue2169.agda", "max_issues_repo_name": "hborum/agda", "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_forks_repo_path": "test/Fail/Issue2169.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "avg_line_length": 16.4166666667, "max_line_length": 60, "alphanum_fraction": 0.5888324873, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.752012562644147, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.3906865606694684}} {"text": "------------------------------------------------------------------------\n-- Strong bisimilarity for partially defined values, along with a\n-- proof showing that this relation is pointwise isomorphic to path\n-- equality\n------------------------------------------------------------------------\n\n{-# OPTIONS --cubical --sized-types #-}\n\nmodule Delay-monad.Bisimilarity.For-all-sizes where\n\nopen import Equality.Path hiding (ext)\nopen import Prelude\nopen import Prelude.Size\n\nopen import Bijection equality-with-J using (_↔_)\n\nopen import Delay-monad\n\nprivate\n variable\n a : Level\n A : Type a\n x : A\n i : Size\n\nmutual\n\n -- A variant of strong bisimilarity that relates values of any size,\n -- not only those of size ∞.\n --\n -- Note: I have not managed to prove that this relation is pointwise\n -- isomorphic to strong bisimilarity as defined in\n -- Delay-monad.Bisimilarity (when the relation is restricted to\n -- fully defined values).\n\n infix 4 [_]_∼ˢ_ [_]_∼ˢ′_\n\n data [_]_∼ˢ_ {A : Type a} (i : Size) :\n Delay A i → Delay A i → Type a where\n now : [ i ] now x ∼ˢ now x\n later : {x y : Delay′ A i} →\n [ i ] x ∼ˢ′ y → [ i ] later x ∼ˢ later y\n\n record [_]_∼ˢ′_ {A : Type a}\n (i : Size) (x y : Delay′ A i) : Type a where\n coinductive\n field\n force : {j : Size< i} → [ j ] x .force ∼ˢ y .force\n\nopen [_]_∼ˢ′_ public\n\nmutual\n\n -- Strong bisimilarity is reflexive. Note that the proof is\n -- size-preserving.\n\n reflexiveˢ : (x : Delay A i) → [ i ] x ∼ˢ x\n reflexiveˢ (now x) = now\n reflexiveˢ (later x) = later (reflexiveˢ′ x)\n\n reflexiveˢ′ : (x : Delay′ A i) → [ i ] x ∼ˢ′ x\n reflexiveˢ′ x .force = reflexiveˢ (x .force)\n\nmutual\n\n -- Extensionality: Strong bisimilarity implies equality.\n\n ext : {x y : Delay A i} →\n [ i ] x ∼ˢ y → x ≡ y\n ext now = refl\n ext (later p) = cong later (ext′ p)\n\n ext′ : {x y : Delay′ A i} →\n [ i ] x ∼ˢ′ y → x ≡ y\n ext′ p i .force = ext (p .force) i\n\nmutual\n\n -- The extensionality proof maps reflexivity to reflexivity.\n\n ext-reflexiveˢ :\n (x : Delay A i) →\n ext (reflexiveˢ x) ≡ refl {x = x}\n ext-reflexiveˢ (now x) = refl\n ext-reflexiveˢ {i = i} (later x) =\n ext (reflexiveˢ (later x)) ≡⟨⟩\n cong later (ext′ (reflexiveˢ′ x)) ≡⟨ cong (cong later) (ext′-reflexiveˢ′ x) ⟩\n cong later refl ≡⟨⟩\n refl ∎\n\n ext′-reflexiveˢ′ :\n (x : Delay′ A i) →\n ext′ (reflexiveˢ′ x) ≡ refl {x = x}\n ext′-reflexiveˢ′ x i j .force = ext-reflexiveˢ (x .force) i j\n\n-- Equality implies strong bisimilarity.\n\n≡⇒∼ : {x y : Delay A i} → x ≡ y → [ i ] x ∼ˢ y\n≡⇒∼ {x = x} eq = subst ([ _ ] x ∼ˢ_) eq (reflexiveˢ x)\n\n≡⇒∼′ : {x y : Delay′ A i} → x ≡ y → [ i ] x ∼ˢ′ y\n≡⇒∼′ eq .force = ≡⇒∼ (cong (λ x → x .force) eq)\n\nprivate\n\n ≡⇒∼″ : {x y : Delay′ A i} → x ≡ y → [ i ] x ∼ˢ′ y\n ≡⇒∼″ {x = x} eq = subst ([ _ ] x ∼ˢ′_) eq (reflexiveˢ′ x)\n\n-- The three lemmas above map reflexivity to reflexivity.\n\n≡⇒∼-refl :\n {x : Delay A i} →\n ≡⇒∼ (refl {x = x}) ≡ reflexiveˢ x\n≡⇒∼-refl {x = x} =\n ≡⇒∼ refl ≡⟨⟩\n subst ([ _ ] x ∼ˢ_) refl (reflexiveˢ x) ≡⟨ subst-refl ([ _ ] x ∼ˢ_) (reflexiveˢ x) ⟩∎\n reflexiveˢ x ∎\n\n≡⇒∼′-refl :\n {x : Delay′ A i} →\n ≡⇒∼′ (refl {x = x}) ≡ reflexiveˢ′ x\n≡⇒∼′-refl i .force = ≡⇒∼-refl i\n\nprivate\n\n ≡⇒∼″-refl :\n {x : Delay′ A i} →\n ≡⇒∼″ (refl {x = x}) ≡ reflexiveˢ′ x\n ≡⇒∼″-refl {x = x} =\n ≡⇒∼″ refl ≡⟨⟩\n subst ([ _ ] x ∼ˢ′_) refl (reflexiveˢ′ x) ≡⟨ subst-refl ([ _ ] x ∼ˢ′_) (reflexiveˢ′ x) ⟩∎\n reflexiveˢ′ x ∎\n\n -- ≡⇒∼′ and ≡⇒″ are pointwise equal.\n\n ≡⇒∼′≡≡⇒∼″ :\n {x y : Delay′ A i} {eq : x ≡ y} →\n ≡⇒∼′ eq ≡ ≡⇒∼″ eq\n ≡⇒∼′≡≡⇒∼″ = elim\n (λ eq → ≡⇒∼′ eq ≡ ≡⇒∼″ eq)\n (λ x →\n ≡⇒∼′ refl ≡⟨ ≡⇒∼′-refl ⟩\n reflexiveˢ′ x ≡⟨ sym ≡⇒∼″-refl ⟩∎\n ≡⇒∼″ refl ∎)\n _\n\nprivate\n\n -- Extensionality and ≡⇒∼/≡⇒∼′ are inverses.\n\n ext∘≡⇒∼ :\n {x y : Delay A i}\n (eq : x ≡ y) → ext (≡⇒∼ eq) ≡ eq\n ext∘≡⇒∼ = elim\n (λ eq → ext (≡⇒∼ eq) ≡ eq)\n (λ x → ext (≡⇒∼ refl) ≡⟨ cong ext ≡⇒∼-refl ⟩\n ext (reflexiveˢ x) ≡⟨ ext-reflexiveˢ x ⟩∎\n refl ∎)\n\n ext′∘≡⇒∼′ :\n {x y : Delay′ A i}\n (eq : x ≡ y) → ext′ (≡⇒∼′ eq) ≡ eq\n ext′∘≡⇒∼′ = elim\n (λ eq → ext′ (≡⇒∼′ eq) ≡ eq)\n (λ x → ext′ (≡⇒∼′ refl) ≡⟨ cong ext′ ≡⇒∼′-refl ⟩\n ext′ (reflexiveˢ′ x) ≡⟨ ext′-reflexiveˢ′ x ⟩∎\n refl ∎)\n\n mutual\n\n ≡⇒∼∘ext :\n {x y : Delay A i}\n (eq : [ i ] x ∼ˢ y) →\n ≡⇒∼ (ext eq) ≡ eq\n ≡⇒∼∘ext now =\n ≡⇒∼ (ext now) ≡⟨⟩\n ≡⇒∼ refl ≡⟨ ≡⇒∼-refl ⟩∎\n now ∎\n ≡⇒∼∘ext (later {x = x} {y = y} p) =\n ≡⇒∼ (ext (later p)) ≡⟨⟩\n\n ≡⇒∼ (cong later (ext′ p)) ≡⟨⟩\n\n subst ([ _ ] later x ∼ˢ_) (cong later (ext′ p))\n (later (reflexiveˢ′ x)) ≡⟨ sym $ subst-∘ ([ _ ] later x ∼ˢ_) later _ {p = later (reflexiveˢ′ x)} ⟩\n\n subst (λ y → [ _ ] later x ∼ˢ later y) (ext′ p)\n (later (reflexiveˢ′ x)) ≡⟨ elim¹\n (λ eq → subst (λ y → [ _ ] later x ∼ˢ later y) eq (later (reflexiveˢ′ x)) ≡\n later (subst ([ _ ] x ∼ˢ′_) eq (reflexiveˢ′ x))) (\n subst (λ y → [ _ ] later x ∼ˢ later y) refl\n (later (reflexiveˢ′ x)) ≡⟨ subst-refl (λ y → [ _ ] later x ∼ˢ later y) _ ⟩\n\n later (reflexiveˢ′ x) ≡⟨ cong later $ sym $ subst-refl ([ _ ] x ∼ˢ′_) _ ⟩∎\n\n later (subst ([ _ ] x ∼ˢ′_) refl (reflexiveˢ′ x)) ∎)\n (ext′ p) ⟩\n later (subst ([ _ ] x ∼ˢ′_) (ext′ p) (reflexiveˢ′ x)) ≡⟨⟩\n\n later (≡⇒∼″ (ext′ p)) ≡⟨ cong later $ sym ≡⇒∼′≡≡⇒∼″ ⟩\n\n later (≡⇒∼′ (ext′ p)) ≡⟨ cong later (≡⇒∼′∘ext′ p) ⟩∎\n\n later p ∎\n\n ≡⇒∼′∘ext′ :\n {x y : Delay′ A i}\n (eq : [ i ] x ∼ˢ′ y) →\n ≡⇒∼′ (ext′ eq) ≡ eq\n ≡⇒∼′∘ext′ eq i .force = ≡⇒∼∘ext (eq .force) i\n\n-- Strong bisimilarity and equality are pointwise isomorphic.\n\n∼↔≡ : {x y : Delay A i} → [ i ] x ∼ˢ y ↔ x ≡ y\n∼↔≡ = record\n { surjection = record\n { logical-equivalence = record\n { to = ext\n ; from = ≡⇒∼\n }\n ; right-inverse-of = ext∘≡⇒∼\n }\n ; left-inverse-of = ≡⇒∼∘ext\n }\n\n∼′↔≡ : {x y : Delay′ A i} → [ i ] x ∼ˢ′ y ↔ x ≡ y\n∼′↔≡ = record\n { surjection = record\n { logical-equivalence = record\n { to = ext′\n ; from = ≡⇒∼′\n }\n ; right-inverse-of = ext′∘≡⇒∼′\n }\n ; left-inverse-of = ≡⇒∼′∘ext′\n }\n", "meta": {"hexsha": "994d4ba1f3799d16e280b203e2481e725304ba69", "size": 6985, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Delay-monad/Bisimilarity/For-all-sizes.agda", "max_stars_repo_name": "nad/delay-monad", "max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Bisimilarity/For-all-sizes.agda", "max_issues_repo_name": "nad/delay-monad", "max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Bisimilarity/For-all-sizes.agda", "max_forks_repo_name": "nad/delay-monad", "max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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": 29.4725738397, "max_line_length": 141, "alphanum_fraction": 0.4276306371, "num_tokens": 3001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.5964331462646254, "lm_q1q2_score": 0.3906009237147155}} {"text": "\nmodule _ where\n\nopen import Agda.Builtin.Nat\n\nmodule M (n : Nat) where\n\n postulate A : Set\n\nmodule M₁ (m : Nat) where\n\n open module Mm = M m\n\n -- bar : M.A (m + 1)\n -- bar = m -- Nat !=< M.A (m + 1)\n\npostulate\n n : Nat\n\nfoo : M.A n\nfoo = n -- Nat !=< M.A n\n", "meta": {"hexsha": "e5715b5c415a747a024ad4aaa7cddcc5832e2abc", "size": 264, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue2067b.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Issue2067b.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Issue2067b.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 12.0, "max_line_length": 36, "alphanum_fraction": 0.5416666667, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.39056541430294517}} {"text": "{-# OPTIONS --cubical --safe --postfix-projections #-}\n\nmodule Data.Array where\n\nopen import Data.Binary\nopen import Prelude\n\nprivate\n variable\n ns : 𝔹\n\nrecord 2× {a} (A : Type a) : Type a where\n eta-equality\n constructor _⊛_\n field\n pr₁ pr₂ : A\nopen 2× public\n\ninfixr 5 _∷₁_ _∷₂_ _∷_\n\nmutual\n record Array0ᵇ {a} : Type a where\n eta-equality\n constructor []\n\n record Array1ᵇ {a} (A : Type a) (ns : 𝔹) : Type a where\n eta-equality\n inductive\n constructor _∷₁_\n field\n head1ᵇ : A\n tail1ᵇ : Array (2× A) ns\n\n record Array2ᵇ {a} (A : Type a) (ns : 𝔹) : Type a where\n eta-equality\n inductive\n constructor _∷₂_\n field\n head2ᵇ : 2× A\n tail2ᵇ : Array (2× A) ns\n\n Array : Type a → 𝔹 → Type a\n Array A 0ᵇ = Array0ᵇ\n Array A (1ᵇ ns) = Array1ᵇ A ns\n Array A (2ᵇ ns) = Array2ᵇ A ns\n\n_∷_ : A → Array A ns → Array A (inc ns)\n_∷_ {ns = 0ᵇ} x xs = x ∷₁ xs\n_∷_ {ns = 1ᵇ ns} x₁ (x₂ ∷₁ xs) = (x₁ ⊛ x₂) ∷₂ xs\n_∷_ {ns = 2ᵇ ns} x₁ (x₂ ∷₂ xs) = x₁ ∷₁ x₂ ∷ xs\n\nopen import Lens\n\n⦅head1ᵇ⦆ : Lens (Array A (1ᵇ ns)) A\n⦅head1ᵇ⦆ .fst (x ∷₁ xs) = lens-part x (_∷₁ xs)\n⦅head1ᵇ⦆ .snd .get-set xs v i = v\n⦅head1ᵇ⦆ .snd .set-get xs i = xs\n⦅head1ᵇ⦆ .snd .set-set (x ∷₁ xs) v₁ v₂ i = v₂ ∷₁ xs\n\n⦅head2ᵇ⦆ : Lens (Array A (2ᵇ ns)) (2× A)\n⦅head2ᵇ⦆ .fst (x ∷₂ xs) = lens-part x (_∷₂ xs)\n⦅head2ᵇ⦆ .snd .get-set (x ∷₂ xs) v i = v\n⦅head2ᵇ⦆ .snd .set-get (x ∷₂ xs) i = x ∷₂ xs\n⦅head2ᵇ⦆ .snd .set-set (x ∷₂ xs) v₁ v₂ i = v₂ ∷₂ xs\n\n⦅tail1ᵇ⦆ : Lens (Array A (1ᵇ ns)) (Array (2× A) ns)\n⦅tail1ᵇ⦆ .fst (x ∷₁ xs) = lens-part xs (x ∷₁_)\n⦅tail1ᵇ⦆ .snd .get-set (x ∷₁ xs) v i = v\n⦅tail1ᵇ⦆ .snd .set-get (x ∷₁ xs) i = x ∷₁ xs\n⦅tail1ᵇ⦆ .snd .set-set (x ∷₁ xs) v₁ v₂ i = x ∷₁ v₂\n\n⦅tail2ᵇ⦆ : Lens (Array A (2ᵇ ns)) (Array (2× A) ns)\n⦅tail2ᵇ⦆ .fst (x ∷₂ xs) = lens-part xs (x ∷₂_)\n⦅tail2ᵇ⦆ .snd .get-set (x ∷₂ xs) v i = v\n⦅tail2ᵇ⦆ .snd .set-get (x ∷₂ xs) i = x ∷₂ xs\n⦅tail2ᵇ⦆ .snd .set-set (x ∷₂ xs) v₁ v₂ i = x ∷₂ v₂\n\n⦅pr₁⦆ : Lens (2× A) A\n⦅pr₁⦆ .fst (x ⊛ y) = lens-part x (_⊛ y)\n⦅pr₁⦆ .snd .get-set s v i = v\n⦅pr₁⦆ .snd .set-get s i = s\n⦅pr₁⦆ .snd .set-set s v₁ v₂ i = v₂ ⊛ s .pr₂\n\n⦅pr₂⦆ : Lens (2× A) A\n⦅pr₂⦆ .fst (x ⊛ y) = lens-part y (x ⊛_)\n⦅pr₂⦆ .snd .get-set s v i = v\n⦅pr₂⦆ .snd .set-get s i = s\n⦅pr₂⦆ .snd .set-set s v₁ v₂ i = s .pr₁ ⊛ v₂\n\nopen import Data.Binary.Order\n\nmutual\n index : ∀ is {js} → is < js → Lens (Array A js) A\n index 0ᵇ {1ᵇ js} p = ⦅head1ᵇ⦆\n index 0ᵇ {2ᵇ js} p = ⦅head2ᵇ⦆ ⋯ ⦅pr₁⦆\n index (1ᵇ is) {js} p = ind₂1ᵇ is p\n index (2ᵇ is) {1ᵇ js} p = ⦅tail1ᵇ⦆ ⋯ index is p ⋯ ⦅pr₂⦆\n index (2ᵇ is) {2ᵇ js} p = ⦅tail2ᵇ⦆ ⋯ index is p ⋯ ⦅pr₁⦆\n\n ind₂1ᵇ : ∀ is {js} → 1ᵇ is < js → Lens (Array A js) A\n ind₂1ᵇ is {1ᵇ js} p = ⦅tail1ᵇ⦆ ⋯ index is p ⋯ ⦅pr₁⦆\n ind₂1ᵇ 0ᵇ {2ᵇ js} p = ⦅head2ᵇ⦆ ⋯ ⦅pr₂⦆\n ind₂1ᵇ (1ᵇ is) {2ᵇ js} p = ⦅tail2ᵇ⦆ ⋯ ind₃ is p ⋯ ⦅pr₂⦆\n ind₂1ᵇ (2ᵇ is) {2ᵇ js} p = ⦅tail2ᵇ⦆ ⋯ ind₂2ᵇ is p ⋯ ⦅pr₂⦆\n\n ind₂2ᵇ : ∀ is {js} → 2ᵇ is ≤ js → Lens (Array A js) A\n ind₂2ᵇ is {1ᵇ js} p = ⦅tail1ᵇ⦆ ⋯ index is p ⋯ ⦅pr₁⦆\n ind₂2ᵇ 0ᵇ {2ᵇ js} p = ⦅head2ᵇ⦆ ⋯ ⦅pr₂⦆\n ind₂2ᵇ (1ᵇ is) {2ᵇ js} p = ⦅tail2ᵇ⦆ ⋯ ind₃ is p ⋯ ⦅pr₂⦆\n ind₂2ᵇ (2ᵇ is) {2ᵇ js} p = ⦅tail2ᵇ⦆ ⋯ ind₂2ᵇ is p ⋯ ⦅pr₂⦆\n\n ind₃ : ∀ is {js} → 1ᵇ is ≤ js → Lens (Array A js) A\n ind₃ 0ᵇ {1ᵇ js} p = ⦅head1ᵇ⦆\n ind₃ 0ᵇ {2ᵇ js} p = ⦅head2ᵇ⦆ ⋯ ⦅pr₁⦆\n ind₃ (1ᵇ is) {1ᵇ js} p = ⦅tail1ᵇ⦆ ⋯ ind₃ is p ⋯ ⦅pr₂⦆\n ind₃ (1ᵇ is) {2ᵇ js} p = ⦅tail2ᵇ⦆ ⋯ ind₃ is p ⋯ ⦅pr₁⦆\n ind₃ (2ᵇ is) {1ᵇ js} p = ⦅tail1ᵇ⦆ ⋯ ind₂2ᵇ is p ⋯ ⦅pr₂⦆\n ind₃ (2ᵇ is) {2ᵇ js} p = ⦅tail2ᵇ⦆ ⋯ ind₂2ᵇ is p ⋯ ⦅pr₁⦆\n\nat : ∀ is {js} → {p : is < js} → Lens (Array A js) A\nat is {p = p} = index is p\n\nimport Data.Nat as ℕ\n\nfoldrP : ∀ {p} (P : ℕ → Type p) → (∀ {n} → A → P n → P (suc n)) → P zero → Array A ns → P ⟦ ns ⇓⟧\nfoldrP {ns = 0ᵇ} P f b [] = b\nfoldrP {ns = 1ᵇ ns} P f b (x ∷₁ xs) = f x (foldrP (λ n → P (n ℕ.* 2)) (λ { (x₁ ⊛ x₂) b → f x₁ (f x₂ b) }) b xs)\nfoldrP {ns = 2ᵇ ns} P f b ((x₁ ⊛ x₂) ∷₂ xs) = f x₁ (f x₂ (foldrP (λ n → P (n ℕ.* 2)) (λ { (x₁ ⊛ x₂) b → f x₁ (f x₂ b)}) b xs))\n\nfoldr : (A → B → B) → B → Array A ns → B\nfoldr f b = foldrP (λ _ → _) f b\n\nmap : (A → B) → Array A ns → Array B ns\nmap {ns = 0ᵇ} f xs = []\nmap {ns = 1ᵇ ns} f (x ∷₁ xs) = f x ∷₁ map (λ { (x₁ ⊛ x₂) → f x₁ ⊛ f x₂ }) xs\nmap {ns = 2ᵇ ns} f ((x₁ ⊛ x₂) ∷₂ xs) = (f x₁ ⊛ f x₂) ∷₂ map (λ { (x₁ ⊛ x₂) → f x₁ ⊛ f x₂ }) xs\n\nimport Data.List as List\nopen import Data.List using (List)\n\ntoList : Array A ns → List.List A\ntoList = foldr List._∷_ List.[]\n\nfromList : (xs : List A) → Array A ⟦ List.length xs ⇑⟧\nfromList List.[] = []\nfromList (x List.∷ xs) = x ∷ fromList xs\n\n-- Lens laws are satisfied definitionally:\n\n-- get-set\n_ : (xs : Array ℕ ⟦ 10 ⇑⟧) (n : ℕ) → (xs [ at ⟦ 5 ⇑⟧ ]≔ n [ at ⟦ 5 ⇑⟧ ]) ≡ n\n_ = λ xs n → refl\n\n-- set-get\n_ : (xs : Array ℕ ⟦ 10 ⇑⟧) → (xs [ at ⟦ 5 ⇑⟧ ]≔ (xs [ at ⟦ 5 ⇑⟧ ])) ≡ xs\n_ = λ xs → refl\n\n-- set-set\n_ : (xs : Array ℕ ⟦ 10 ⇑⟧) (n m : ℕ) → (xs [ at ⟦ 5 ⇑⟧ ]≔ n [ at ⟦ 5 ⇑⟧ ]≔ m) ≡ (xs [ at ⟦ 5 ⇑⟧ ]≔ m)\n_ = λ xs n m → refl\n", "meta": {"hexsha": "68eefa73ebcda4ab879f53a40e0ef809a35a986e", "size": 4926, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Data/Array.agda", "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_issues_repo_path": "Data/Array.agda", "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "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": "Data/Array.agda", "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "avg_line_length": 30.5962732919, "max_line_length": 126, "alphanum_fraction": 0.5255785627, "num_tokens": 3016, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.39054806359171806}} {"text": "------------------------------------------------------------------------\n-- A type-checker\n------------------------------------------------------------------------\n\nimport Axiom.Extensionality.Propositional as E\nimport Level\nopen import Data.Universe\n\n-- The code makes use of the assumption that propositional equality of\n-- functions is extensional.\n\nmodule README.DependentlyTyped.Type-checker\n (Uni₀ : Universe Level.zero Level.zero)\n (ext : E.Extensionality Level.zero Level.zero)\n where\n\nopen import Category.Monad\nopen import Data.Maybe hiding (_>>=_)\nimport Data.Maybe.Categorical as Maybe\nopen import Data.Nat using (ℕ; zero; suc; pred)\nopen import Data.Product as Prod\nopen import Function as F hiding (_∋_) renaming (_∘_ to _⊚_)\nimport README.DependentlyTyped.Equality-checker as EC; open EC Uni₀ ext\nimport README.DependentlyTyped.NBE as NBE; open NBE Uni₀ ext\nimport README.DependentlyTyped.NormalForm as NF\nopen NF Uni₀ hiding (⌊_⌋; no)\nimport README.DependentlyTyped.Raw-term as RT; open RT Uni₀\nimport README.DependentlyTyped.Term as Term; open Term Uni₀\nimport README.DependentlyTyped.Term.Substitution as S; open S Uni₀\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\nopen import Relation.Nullary\nimport Relation.Nullary.Decidable as Dec\nopen import Relation.Nullary.Product\n\nopen P.≡-Reasoning\nopen RawMonadZero (Maybe.monadZero {f = Level.zero})\n\n-- Computes a syntactic type for a variable from a matching syntactic\n-- context.\n\ntype-of-var : ∀ {Γ σ} → Γ ∋ σ → Γ ctxt → Γ ⊢ σ type\ntype-of-var zero (Γ′ ▻ σ′) = σ′ /⊢t wk\ntype-of-var (suc x) (Γ′ ▻ σ′) = type-of-var x Γ′ /⊢t wk\n\n-- Infers the type of a variable, if possible.\n\ninfer-var : (Γ : Ctxt) (x : ℕ) →\n Dec (∃₂ λ σ (x′ : Γ ∋ σ) → position x′ ≡ x)\ninfer-var ε x = no helper\n where\n helper : ¬ ∃₂ λ σ (x′ : ε ∋ σ) → position x′ ≡ x\n helper (_ , () , _)\ninfer-var (Γ ▻ σ) zero = yes (σ /̂ ŵk , zero , P.refl)\ninfer-var (Γ ▻ σ) (suc x) =\n Dec.map′ (Prod.map (λ σ → σ /̂ ŵk) (Prod.map suc (P.cong suc)))\n helper\n (infer-var Γ x)\n where\n helper : (∃₂ λ τ (x′ : Γ ▻ σ ∋ τ) → position x′ ≡ suc x) →\n (∃₂ λ τ (x′ : Γ ∋ τ) → position x′ ≡ x)\n helper (._ , zero , ())\n helper (._ , suc x′ , eq) = (_ , x′ , P.cong pred eq)\n\n-- Infers the /syntactic/ type of a variable, if possible.\n\ninfer-var-syntactic :\n ∀ {Γ} → Γ ctxt → (x : ℕ) →\n Dec (∃ λ σ → Γ ⊢ σ type × ∃ λ (x′ : Γ ∋ σ) → position x′ ≡ x)\ninfer-var-syntactic {Γ} Γ′ x = Dec.map′\n (Prod.map F.id (λ p → type-of-var (proj₁ p) Γ′ , proj₁ p , proj₂ p))\n (Prod.map F.id proj₂)\n (infer-var Γ x)\n\nmutual\n\n -- Tries to infer a well-typed form of a raw type.\n\n infer-ty :\n ∀ {Γ} → Γ ctxt → (σ : Raw-ty) →\n Maybe (∃₂ λ σ′ (σ″ : Γ ⊢ σ′ type) → ⌊ σ″ ⌋ty ≡ ⌊ σ ⌋raw-ty)\n infer-ty Γ′ ⋆ = return (_ , ⋆ , P.refl)\n infer-ty Γ′ (el t) =\n check Γ′ ⋆ t >>= λ { (t′ , eq) →\n return (_ , el t′ , P.cong el eq) }\n infer-ty Γ′ (π σ′₁ σ′₂) =\n infer-ty Γ′ σ′₁ >>= λ { (_ , σ′₁′ , eq₁) →\n infer-ty (Γ′ ▻ σ′₁′) σ′₂ >>= λ { (_ , σ′₂′ , eq₂) →\n return (_ , π σ′₁′ σ′₂′ , P.cong₂ π eq₁ eq₂) }}\n\n -- Tries to infer a type for a term. In the case of success a\n -- well-typed term is returned.\n\n infer :\n ∀ {Γ} → Γ ctxt → (t : Raw) →\n Maybe (∃ λ σ → Γ ⊢ σ type × ∃ λ (t′ : Γ ⊢ σ) → ⌊ t′ ⌋ ≡ ⌊ t ⌋raw)\n infer Γ′ (var x) with infer-var-syntactic Γ′ x\n ... | yes (_ , σ′ , x′ , eq) = return (_ , σ′ , var x′ , P.cong var eq)\n ... | no _ = ∅\n infer Γ′ (ƛ t) = ∅\n infer Γ′ (t₁ · t₂) =\n infer Γ′ t₁ >>=\n λ { (._ , π σ′₁ σ′₂ , t₁′ , eq₁) →\n check Γ′ σ′₁ t₂ >>= λ { (t₂′ , eq₂) →\n return (_ , σ′₂ /⊢t sub t₂′ , t₁′ · t₂′ ,\n P.cong₂ _·_ eq₁ eq₂) }\n ; _ → ∅\n }\n infer Γ′ (t ∶ σ) =\n infer-ty Γ′ σ >>= λ { (_ , σ′ , eq) →\n check Γ′ σ′ t >>= λ { (t′ , eq) →\n return (_ , σ′ , t′ , eq) }}\n\n -- Tries to type-check a term. In the case of success a well-typed\n -- term is returned.\n\n check : ∀ {Γ σ} → Γ ctxt → (σ′ : Γ ⊢ σ type) (t : Raw) →\n Maybe (∃ λ (t′ : Γ ⊢ σ) → ⌊ t′ ⌋ ≡ ⌊ t ⌋raw)\n check Γ′ (π σ′₁ σ′₂) (ƛ t) =\n check (Γ′ ▻ σ′₁) σ′₂ t >>= λ { (t′ , eq) →\n return (ƛ t′ , P.cong ƛ eq) }\n check Γ′ σ′ t =\n infer Γ′ t >>= λ { (_ , τ′ , t′ , eq₁) →\n τ′ ≟-Type σ′ >>= λ eq₂ →\n return (P.subst (_⊢_ _) (≅-Type-⇒-≡ eq₂) t′ , (begin\n ⌊ P.subst (_⊢_ _) (≅-Type-⇒-≡ eq₂) t′ ⌋ ≡⟨ ⌊⌋-cong $ drop-subst-⊢ F.id (≅-Type-⇒-≡ eq₂) ⟩\n ⌊ t′ ⌋ ≡⟨ eq₁ ⟩\n ⌊ t ⌋raw ∎)) }\n\n-- Tries to establish that the given raw term has the given raw type\n-- (in the empty context).\n\ninfix 4 _∋?_\n\n_∋?_ : (σ : Raw-ty) (t : Raw) →\n Maybe (∃₂ λ (σ′ : Type ε) (σ″ : ε ⊢ σ′ type) →\n ∃ λ (t′ : ε ⊢ σ′) →\n ⌊ σ″ ⌋ty ≡ ⌊ σ ⌋raw-ty × ⌊ t′ ⌋ ≡ ⌊ t ⌋raw)\nσ ∋? t = infer-ty ε σ >>= λ { (σ′ , σ″ , eq₁) →\n check ε σ″ t >>= λ { (t′ , eq₂) →\n return (σ′ , σ″ , t′ , eq₁ , eq₂) }}\n\n------------------------------------------------------------------------\n-- Examples\n\nprivate\n\n σ₁ : Raw-ty\n σ₁ = π ⋆ ⋆\n\n σ₁′ : Type ε\n σ₁′ = proj₁ $ from-just $ infer-ty ε σ₁\n\n t₁ : Raw\n t₁ = ƛ (var zero)\n\n t₁′ : ε ⊢ σ₁′\n t₁′ = proj₁ $ proj₂ $ proj₂ $ from-just $ σ₁ ∋? t₁\n\n t₂ : ε ▻ (⋆ , _) ⊢ (⋆ , _)\n t₂ = proj₁ $ proj₂ $ proj₂ $ from-just $ infer (ε ▻ ⋆) (var zero)\n\n t₃ : Raw\n t₃ = (ƛ (var zero) ∶ π ⋆ ⋆) · var zero\n\n t₃′ : ε ▻ (⋆ , _) ⊢ (⋆ , _)\n t₃′ = proj₁ $ proj₂ $ proj₂ $ from-just $ infer (ε ▻ ⋆) t₃\n", "meta": {"hexsha": "f20c0579b63177c0123fcc0a7d80f759cbe3ac23", "size": 5811, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "README/DependentlyTyped/Type-checker.agda", "max_stars_repo_name": "nad/dependently-typed-syntax", "max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z", "max_issues_repo_path": "README/DependentlyTyped/Type-checker.agda", "max_issues_repo_name": "nad/dependently-typed-syntax", "max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "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": "README/DependentlyTyped/Type-checker.agda", "max_forks_repo_name": "nad/dependently-typed-syntax", "max_forks_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "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": 34.7964071856, "max_line_length": 104, "alphanum_fraction": 0.4759938049, "num_tokens": 2226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.3905443320871532}} {"text": "{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}\n\nmodule Light.Library.Relation.Decidable where\n\nopen import Light.Level using (Setω ; Level)\nopen import Light.Variable.Levels\nopen import Light.Variable.Sets\nopen import Light.Library.Relation using (Base ; Kind ; Style)\nopen import Light.Indexed using (Indexed ; thing ; indexed)\nopen import Light.Package using (Package)\n\nrecord Dependencies : Setω where\n\nrecord Library (dependencies : Dependencies) : Setω where\n field base : Base\n \n open Style (base .Base.style) using (True ; False)\n open Kind (base .Base.kind) using (Index ; Proposition)\n \n field\n ℓf : Index → Level\n Decidable : ∀ {i} → Proposition i → Set (ℓf i)\n kind : Kind\n kind = record { Index = Indexed Index Proposition ; Proposition = λ i → Decidable (thing i) }\n field\n instance style : Style kind\n if′_then_else_ : ∀ {i} {𝕒 : Proposition i} → Decidable 𝕒 → 𝕓 → 𝕓 → 𝕓\n if_then_else_ :\n ∀ {i} {𝕒 : Proposition i}\n → Decidable 𝕒\n → (∀ ⦃ witness : True 𝕒 ⦄ → 𝕓)\n → (∀ ⦃ witness : False 𝕒 ⦄ → 𝕓)\n → 𝕓\n \n to‐witness : ∀ {i} {𝕒 : Proposition i} {a? : Decidable 𝕒} ⦃ truth : Style.True style a? ⦄ → True 𝕒\n to‐false‐witness : ∀ {i} {𝕒 : Proposition i} {a? : Decidable 𝕒} ⦃ falsehood : Style.False style a? ⦄ → False 𝕒\n \n ⦃ from‐witness ⦄ : ∀ {i} {𝕒 : Proposition i} {a? : Decidable 𝕒} ⦃ witness : True 𝕒 ⦄ → Style.True style a?\n ⦃ from‐false‐witness ⦄ : ∀ {i} {𝕒 : Proposition i} {a? : Decidable 𝕒} ⦃ witness : False 𝕒 ⦄ → Style.False style a?\n \n yes : ∀ {i} {𝕒 : Proposition i} → True 𝕒 → Decidable 𝕒\n no : ∀ {i} {𝕒 : Proposition i} → False 𝕒 → Decidable 𝕒\n instance base′ = record { kind = kind ; style = style }\n\nopen Library ⦃ ... ⦄ public\n", "meta": {"hexsha": "a86e59a44bf546d17b37c2c7aa4975f159dfa7f1", "size": 1976, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Light/Library/Relation/Decidable.agda", "max_stars_repo_name": "zamfofex/lightlib", "max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z", "max_issues_repo_path": "Light/Library/Relation/Decidable.agda", "max_issues_repo_name": "Zambonifofex/lightlib", "max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Light/Library/Relation/Decidable.agda", "max_forks_repo_name": "Zambonifofex/lightlib", "max_forks_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.9565217391, "max_line_length": 126, "alphanum_fraction": 0.5607287449, "num_tokens": 609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.746138993030751, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.39054433208715317}} {"text": "{-# OPTIONS --safe #-}\nmodule Cubical.Algebra.CommRingSolver.Solver where\n\nopen import Cubical.Foundations.Prelude\n\nopen import Cubical.Data.FinData\nopen import Cubical.Data.Nat using (ℕ)\nopen import Cubical.Data.Nat.Order using (zero-≤)\nopen import Cubical.Data.Vec.Base\nopen import Cubical.Algebra.CommRing\nopen import Cubical.Algebra.Ring\nopen import Cubical.Algebra.CommRingSolver.RawAlgebra renaming (⟨_⟩ to ⟨_⟩ᵣ)\nopen import Cubical.Algebra.CommRingSolver.AlgebraExpression\nopen import Cubical.Algebra.CommRingSolver.IntAsRawRing\nopen import Cubical.Algebra.CommRingSolver.HornerForms\nopen import Cubical.Algebra.CommRingSolver.EvalHom\nopen import Cubical.Algebra.CommRingSolver.HornerEval\n\nprivate\n variable\n ℓ : Level\n\nmodule EqualityToNormalform (R : CommRing ℓ) where\n νR = CommRing→RawℤAlgebra R\n open CommRingStr (snd R)\n open RingTheory (CommRing→Ring R)\n open Eval ℤAsRawRing νR\n open IteratedHornerOperations νR\n open HomomorphismProperties R\n\n ℤExpr : (n : ℕ) → Type _\n ℤExpr = Expr ℤAsRawRing (fst R)\n\n normalize : {n : ℕ} → ℤExpr n → IteratedHornerForms νR n\n normalize {n = n} (K r) = Constant n νR r\n normalize {n = n} (∣ k) = Variable n νR k\n normalize (x +' y) =\n (normalize x) +ₕ (normalize y)\n normalize (x ·' y) =\n (normalize x) ·ₕ (normalize y)\n normalize (-' x) = -ₕ (normalize x)\n\n isEqualToNormalform :\n {n : ℕ} (e : ℤExpr n) (xs : Vec (fst R) n)\n → eval (normalize e) xs ≡ ⟦ e ⟧ xs\n isEqualToNormalform (K r) [] = refl\n isEqualToNormalform {n = ℕ.suc n} (K r) (x ∷ xs) =\n eval (Constant (ℕ.suc n) νR r) (x ∷ xs) ≡⟨ refl ⟩\n eval (0ₕ ·X+ Constant n νR r) (x ∷ xs) ≡⟨ combineCasesEval R 0ₕ (Constant n νR r) x xs ⟩\n eval 0ₕ (x ∷ xs) · x + eval (Constant n νR r) xs ≡⟨ cong (λ u → u · x + eval (Constant n νR r) xs)\n (Eval0H (x ∷ xs)) ⟩\n 0r · x + eval (Constant n νR r) xs ≡⟨ cong\n (λ u → u + eval (Constant n νR r) xs)\n (0LeftAnnihilates _) ⟩\n 0r + eval (Constant n νR r) xs ≡⟨ +IdL _ ⟩\n eval (Constant n νR r) xs ≡⟨ isEqualToNormalform (K r) xs ⟩\n _ ∎\n\n isEqualToNormalform (∣ zero) (x ∷ xs) =\n eval (1ₕ ·X+ 0ₕ) (x ∷ xs) ≡⟨ combineCasesEval R 1ₕ 0ₕ x xs ⟩\n eval 1ₕ (x ∷ xs) · x + eval 0ₕ xs ≡⟨ cong (λ u → u · x + eval 0ₕ xs)\n (Eval1ₕ (x ∷ xs)) ⟩\n 1r · x + eval 0ₕ xs ≡⟨ cong (λ u → 1r · x + u ) (Eval0H xs) ⟩\n 1r · x + 0r ≡⟨ +IdR _ ⟩\n 1r · x ≡⟨ ·IdL _ ⟩\n x ∎\n isEqualToNormalform {n = ℕ.suc n} (∣ (suc k)) (x ∷ xs) =\n eval (0ₕ ·X+ Variable n νR k) (x ∷ xs) ≡⟨ combineCasesEval R 0ₕ (Variable n νR k) x xs ⟩\n eval 0ₕ (x ∷ xs) · x + eval (Variable n νR k) xs ≡⟨ cong (λ u → u · x + eval (Variable n νR k) xs)\n (Eval0H (x ∷ xs)) ⟩\n 0r · x + eval (Variable n νR k) xs ≡⟨ cong (λ u → u + eval (Variable n νR k) xs)\n (0LeftAnnihilates _) ⟩\n 0r + eval (Variable n νR k) xs ≡⟨ +IdL _ ⟩\n eval (Variable n νR k) xs ≡⟨ isEqualToNormalform (∣ k) xs ⟩\n ⟦ ∣ (suc k) ⟧ (x ∷ xs) ∎\n\n isEqualToNormalform (-' e) [] =\n eval (-ₕ (normalize e)) [] ≡⟨ -EvalDist (normalize e) [] ⟩\n - eval (normalize e) [] ≡⟨ cong -_ (isEqualToNormalform e [] ) ⟩\n - ⟦ e ⟧ [] ∎\n isEqualToNormalform (-' e) (x ∷ xs) =\n eval (-ₕ (normalize e)) (x ∷ xs) ≡⟨ -EvalDist (normalize e) (x ∷ xs) ⟩\n - eval (normalize e) (x ∷ xs) ≡⟨ cong -_ (isEqualToNormalform e (x ∷ xs) ) ⟩\n - ⟦ e ⟧ (x ∷ xs) ∎\n\n isEqualToNormalform (e +' e₁) [] =\n eval (normalize e +ₕ normalize e₁) []\n ≡⟨ +Homeval (normalize e) _ [] ⟩\n eval (normalize e) []\n + eval (normalize e₁) []\n ≡⟨ cong (λ u → u + eval (normalize e₁) [])\n (isEqualToNormalform e []) ⟩\n ⟦ e ⟧ []\n + eval (normalize e₁) []\n ≡⟨ cong (λ u → ⟦ e ⟧ [] + u) (isEqualToNormalform e₁ []) ⟩\n ⟦ e ⟧ [] + ⟦ e₁ ⟧ [] ∎\n isEqualToNormalform (e +' e₁) (x ∷ xs) =\n eval (normalize e +ₕ normalize e₁) (x ∷ xs)\n ≡⟨ +Homeval (normalize e) _ (x ∷ xs) ⟩\n eval (normalize e) (x ∷ xs) + eval (normalize e₁) (x ∷ xs)\n ≡⟨ cong (λ u → u + eval (normalize e₁) (x ∷ xs))\n (isEqualToNormalform e (x ∷ xs)) ⟩\n ⟦ e ⟧ (x ∷ xs) + eval (normalize e₁) (x ∷ xs)\n ≡⟨ cong (λ u → ⟦ e ⟧ (x ∷ xs) + u) (isEqualToNormalform e₁ (x ∷ xs)) ⟩\n ⟦ e ⟧ (x ∷ xs) + ⟦ e₁ ⟧ (x ∷ xs) ∎\n\n isEqualToNormalform (e ·' e₁) [] =\n eval (normalize e ·ₕ normalize e₁) []\n ≡⟨ ·Homeval (normalize e) _ [] ⟩\n eval (normalize e) [] · eval (normalize e₁) []\n ≡⟨ cong (λ u → u · eval (normalize e₁) [])\n (isEqualToNormalform e []) ⟩\n ⟦ e ⟧ [] · eval (normalize e₁) []\n ≡⟨ cong (λ u → ⟦ e ⟧ [] · u) (isEqualToNormalform e₁ []) ⟩\n ⟦ e ⟧ [] · ⟦ e₁ ⟧ [] ∎\n\n isEqualToNormalform (e ·' e₁) (x ∷ xs) =\n eval (normalize e ·ₕ normalize e₁) (x ∷ xs)\n ≡⟨ ·Homeval (normalize e) _ (x ∷ xs) ⟩\n eval (normalize e) (x ∷ xs) · eval (normalize e₁) (x ∷ xs)\n ≡⟨ cong (λ u → u · eval (normalize e₁) (x ∷ xs))\n (isEqualToNormalform e (x ∷ xs)) ⟩\n ⟦ e ⟧ (x ∷ xs) · eval (normalize e₁) (x ∷ xs)\n ≡⟨ cong (λ u → ⟦ e ⟧ (x ∷ xs) · u) (isEqualToNormalform e₁ (x ∷ xs)) ⟩\n ⟦ e ⟧ (x ∷ xs) · ⟦ e₁ ⟧ (x ∷ xs) ∎\n\n solve :\n {n : ℕ} (e₁ e₂ : ℤExpr n) (xs : Vec (fst R) n)\n (p : eval (normalize e₁) xs ≡ eval (normalize e₂) xs)\n → ⟦ e₁ ⟧ xs ≡ ⟦ e₂ ⟧ xs\n solve e₁ e₂ xs p =\n ⟦ e₁ ⟧ xs ≡⟨ sym (isEqualToNormalform e₁ xs) ⟩\n eval (normalize e₁) xs ≡⟨ p ⟩\n eval (normalize e₂) xs ≡⟨ isEqualToNormalform e₂ xs ⟩\n ⟦ e₂ ⟧ xs ∎\n\nℤExpr : (R : CommRing ℓ) (n : ℕ)\n → _\nℤExpr R n = EqualityToNormalform.ℤExpr R n\n\nsolve : (R : CommRing ℓ)\n {n : ℕ} (e₁ e₂ : ℤExpr R n) (xs : Vec (fst R) n)\n (p : eval (EqualityToNormalform.normalize R e₁) xs ≡ eval (EqualityToNormalform.normalize R e₂) xs)\n → _\nsolve R = EqualityToNormalform.solve R\n", "meta": {"hexsha": "8f7d7d5f43494f1ce09b757822143b70de568e96", "size": 6354, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/CommRingSolver/Solver.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/CommRingSolver/Solver.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/CommRingSolver/Solver.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": 43.5205479452, "max_line_length": 107, "alphanum_fraction": 0.5062952471, "num_tokens": 2382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.746138993030751, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.39054433208715317}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Base\nopen import lib.PathGroupoid\nopen import lib.types.Empty\nopen import lib.types.Nat\n\nmodule lib.types.TLevel where\n\n⟨_⟩₋₁ : ℕ → ℕ₋₂\n⟨ n ⟩₋₁ = S ⟨ n ⟩₋₂\n\n⟨_⟩ : ℕ → ℕ₋₂\n⟨ n ⟩ = S (S ⟨ n ⟩₋₂)\n\ninfixl 80 _+2+_\n_+2+_ : ℕ₋₂ → ℕ₋₂ → ℕ₋₂\n⟨-2⟩ +2+ n = n\nS m +2+ n = S (m +2+ n)\n\n+2+-unit-r : (m : ℕ₋₂) → m +2+ ⟨-2⟩ == m\n+2+-unit-r ⟨-2⟩ = idp\n+2+-unit-r (S m) = ap S (+2+-unit-r m)\n\n+2+-βr : (m n : ℕ₋₂) → m +2+ (S n) == S (m +2+ n)\n+2+-βr ⟨-2⟩ n = idp\n+2+-βr (S m) n = ap S (+2+-βr m n)\n\n+2+-comm : (m n : ℕ₋₂) → m +2+ n == n +2+ m\n+2+-comm m ⟨-2⟩ = +2+-unit-r m\n+2+-comm m (S n) = +2+-βr m n ∙ ap S (+2+-comm m n)\n\n+2+0 : (n : ℕ₋₂) → n +2+ 0 == S (S n)\n+2+0 n = +2+-comm n 0\n\n{- Inequalities -}\ninfix 40 _ Vfin) ∘ π₀ ; π₁ = (–> Vfin) ∘ π₁ }\n\n coeq-equiv : (V / E) ≃ (Fin (S n) / E)\n coeq-equiv = Coeq-emap Vfin (ide E) (λ _ → idp) λ _ → idp\n\n instance\n conn' : gph-is-connected gph'\n conn' = equiv-preserves-level (Trunc-emap coeq-equiv )\n\n\n{- We can now prove the finite index version of the Nielsen-Schreier theorem. -}\nnielsen-schreier-finite-index :\n (A : Type i) (Adec : has-dec-eq A) -- we are given a type A with decidable equality\n (X : (FreeGroup A) → Type i) -- together with a covering space over the free group on A, that is a family of types X ...\n ⦃ conn : is-connected 0 (Σ (FreeGroup A) X) ⦄ -- such that the total space is connected\n (n : ℕ) (Xfin : X (base) ≃ Fin (S n)) → -- here we do the finite index case\n ∥ Σ (Type i) (λ B → Σ (FreeGroup A) X ≃ FreeGroup B) ∥ -- then the total space is a free group\n \nnielsen-schreier-finite-index A Adec X n Xfin =\n Trunc-fmap (λ {(B , e) → B , e ∘e to-free-gpd}) -- we compose the two equivalences from earlier\n (fin-free-gpd-is-free-gp n (A × X base) (×-has-dec-eq Adec (equiv-preserves-dec-eq Xfin Fin-has-dec-eq)) (X base) Xfin)\n -- earlier we showed that free groupoids with finite vertex set are merely equivalent to free groups\n where\n open SubGroupsOfFreeGroups A X -- contains our proof that the subgroup is a free groupoid\n\n instance -- we use that X is a set and the free groupoid is connected\n Xset : {z : (FreeGroup A)} → is-set (X z)\n Xset {z} = Trunc-elim {P = λ z → is-set (X z)}\n (Coeq-elim (λ z → is-set (X [ z ]))\n (λ {unit → equiv-preserves-level (Xfin ⁻¹) ⦃ Fin-is-set ⦄}) λ _ → prop-has-all-paths-↓) z\n\n\n conn2 : is-connected 0 (X base / (A × X base))\n conn2 = equiv-preserves-level e\n where\n e : ∥ Σ (FreeGroup A) X ∥₀ ≃ ∥ X base / (A × X base) ∥₀\n e =\n ∥ Σ (FreeGroup A) X ∥₀\n ≃⟨ Trunc-emap (to-free-gpd ) ⟩\n ∥ ∥ X base / (A × X base) ∥₁ ∥₀\n ≃⟨ Trunc-fuse _ 0 1 ⟩\n ∥ X base / (A × X base) ∥₀\n ≃∎\n", "meta": {"hexsha": "0d8fa65c284151ee79b0304ce020a846e37fa492", "size": 6758, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "main/NielsenSchreier.agda", "max_stars_repo_name": "awswan/nielsenschreier-hott", "max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "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": "main/NielsenSchreier.agda", "max_issues_repo_name": "awswan/nielsenschreier-hott", "max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "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": "main/NielsenSchreier.agda", "max_forks_repo_name": "awswan/nielsenschreier-hott", "max_forks_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "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": 41.2073170732, "max_line_length": 132, "alphanum_fraction": 0.5836046168, "num_tokens": 2451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.774583389368527, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.3903173494921301}} {"text": "module Common.Nat where\n\nopen import Agda.Builtin.Nat public\n using ( Nat; zero; suc; _+_; _*_ )\n renaming ( _-_ to _∸_ )\n\n{-# COMPILED_JS Nat function (x,v) { return (x < 1? v.zero(): v.suc(x-1)); } #-}\n{-# COMPILED_JS zero 0 #-}\n{-# COMPILED_JS suc function (x) { return x+1; } #-}\n\n{-# COMPILED_JS _+_ function (x) { return function (y) { return x+y; }; } #-}\n{-# COMPILED_JS _*_ function (x) { return function (y) { return x*y; }; } #-}\n{-# COMPILED_JS _∸_ function (x) { return function (y) { return Math.max(0,x-y); }; } #-}\n\npred : Nat → Nat\npred zero = zero\npred (suc n) = n\n\n", "meta": {"hexsha": "ad4cb53c8315cedde13f1f7bd51defd878ffa113", "size": 592, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Common/Nat.agda", "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "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/Common/Nat.agda", "max_issues_repo_name": "redfish64/autonomic-agda", "max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "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/Common/Nat.agda", "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "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": 31.1578947368, "max_line_length": 89, "alphanum_fraction": 0.5861486486, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.39030617128510314}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.DStructures.Equivalences.XModPeifferGraph where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Univalence\n\nopen import Cubical.Functions.FunExtEquiv\n\nopen import Cubical.Homotopy.Base\n\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Unit\n\nopen import Cubical.Relation.Binary\n\nopen import Cubical.Structures.Subtype\nopen import Cubical.Algebra.Group\nopen import Cubical.Structures.LeftAction\nopen import Cubical.Algebra.Group.Semidirect\n\nopen import Cubical.DStructures.Base\nopen import Cubical.DStructures.Meta.Properties\n\nopen import Cubical.DStructures.Meta.Isomorphism\nopen import Cubical.DStructures.Structures.Constant\nopen import Cubical.DStructures.Structures.Type\nopen import Cubical.DStructures.Structures.Group\nopen import Cubical.DStructures.Structures.Action\nopen import Cubical.DStructures.Structures.XModule\nopen import Cubical.DStructures.Structures.ReflGraph\nopen import Cubical.DStructures.Structures.PeifferGraph\nopen import Cubical.DStructures.Equivalences.GroupSplitEpiAction\nopen import Cubical.DStructures.Equivalences.PreXModReflGraph\n\n\nprivate\n variable\n ℓ ℓ' ℓ'' ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓA ℓA' ℓ≅A ℓ≅A' ℓB ℓB' ℓ≅B ℓC ℓ≅C ℓ≅ᴰ ℓ≅ᴰ' ℓ≅B' : Level\n\nopen Kernel\nopen GroupHom -- such .fun!\nopen GroupLemmas\nopen MorphismLemmas\nopen ActionLemmas\n\nmodule _ (ℓ ℓ' : Level) where\n private\n ℓℓ' = ℓ-max ℓ ℓ'\n\n ℱ = Iso-PreXModule-ReflGraph ℓ ℓℓ'\n F = Iso.fun ℱ\n\n 𝒮ᴰ-S2G = 𝒮ᴰ-ReflGraph\\Peiffer\n\n 𝒮ᴰ-♭PIso-XModule-Strict2Group : 𝒮ᴰ-♭PIso F (𝒮ᴰ-XModule ℓ ℓℓ') (𝒮ᴰ-S2G ℓ ℓℓ')\n RelIso.fun (𝒮ᴰ-♭PIso-XModule-Strict2Group (((((G₀' , H) , _α_) , isAct) , φ) , isEqui)) isPeif a b = q\n where\n -- G₀ = G₀', but the former is introduced in ReflGraphNotation as well\n open GroupNotationᴴ H\n -- open GroupNotation₀ G₀\n f = GroupHom.fun φ\n A = groupaction _α_ isAct\n open ActionNotationα A using (α-assoc ; α-hom)\n\n SG = F (((((G₀' , H) , _α_) , isAct) , φ) , isEqui)\n -- H⋊G : Group {ℓℓ'}\n H⋊G = snd (fst (fst (fst (fst SG))))\n -- open GroupNotation₁ H⋊G\n open ReflGraphNotation SG\n -- σ : GroupHom H⋊G G₀\n -- ι : GroupHom G₀ H⋊G\n -- τ : GroupHom H⋊G G₀\n u = fst a\n v = snd a\n x = fst b\n y = snd b\n abstract\n -- alright folks, let's do some simple arithmetic with a `twist`, that is Peiffer identities and equivariance\n r = ((0ᴴ +ᴴ (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ)))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α (((-₀ y) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ y) α x)))) +ᴴ (((y +₀ (v +₀ (-₀ (f u +₀ v)))) +₀ ((-₀ y) +₀ y)) α 0ᴴ)\n ≡⟨ cong (((0ᴴ +ᴴ (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ)))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α (((-₀ y) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ y) α x)))) +ᴴ_)\n (actOnUnit A ((y +₀ (v +₀ (-₀ (f u +₀ v)))) +₀ ((-₀ y) +₀ y))) ⟩\n ((0ᴴ +ᴴ (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ)))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α (((-₀ y) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ y) α x)))) +ᴴ 0ᴴ\n ≡⟨ rIdᴴ ((0ᴴ +ᴴ (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ)))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α (((-₀ y) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ y) α x)))) ⟩\n (0ᴴ +ᴴ (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ)))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α (((-₀ y) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ y) α x)))\n ≡⟨ cong (_+ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α (((-₀ y) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ y) α x))))\n (lIdᴴ (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ)))))) ⟩\n (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α (((-₀ y) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ y) α x)))\n ≡⟨ cong (λ z → (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α (z +ᴴ ((-₀ y) α x))))\n (actOn-Unit A (-₀ y)) ⟩\n (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α (0ᴴ +ᴴ ((-₀ y) α x)))\n ≡⟨ cong (λ z → (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α z))\n (lIdᴴ ((-₀ y) α x)) ⟩\n (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α ((-₀ y) α x))\n ≡⟨ cong (λ z → (y α (u +ᴴ (v α z))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α ((-₀ y) α x)))\n (actOn-Unit A (-₀ ((f u) +₀ v))) ⟩\n (y α (u +ᴴ (v α 0ᴴ))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α ((-₀ y) α x))\n ≡⟨ cong (λ z → (y α (u +ᴴ z)) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α ((-₀ y) α x)))\n (actOnUnit A v) ⟩\n (y α (u +ᴴ 0ᴴ)) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α ((-₀ y) α x))\n ≡⟨ cong (λ z → (y α z) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α ((-₀ y) α x)))\n (rIdᴴ u) ⟩\n (y α u) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α ((-₀ y) α x))\n ≡⟨ cong (λ z → (y α u) +ᴴ ((y +₀ (v +₀ z)) α ((-₀ y) α x)))\n (invDistr G₀ (f u) v) ⟩\n (y α u) +ᴴ ((y +₀ (v +₀ ((-₀ v) +₀ (-₀ (f u))))) α ((-₀ y) α x))\n ≡⟨ cong (λ z → (y α u) +ᴴ ((y +₀ z) α ((-₀ y) α x)))\n (assoc-rCancel G₀ v (-₀ f u)) ⟩\n (y α u) +ᴴ ((y +₀ (-₀ (f u))) α ((-₀ y) α x))\n ≡⟨ cong ((y α u) +ᴴ_)\n (sym (α-assoc (y +₀ (-₀ f u)) (-₀ y) x)) ⟩\n (y α u) +ᴴ (((y +₀ (-₀ (f u))) +₀ (-₀ y)) α x)\n ≡⟨ cong (λ z → (y α u) +ᴴ (((y +₀ z) +₀ (-₀ y)) α x))\n (sym (mapInv φ u)) ⟩\n (y α u) +ᴴ (((y +₀ (f (-ᴴ u))) -₀ y) α x)\n -- apply equivariance here\n ≡⟨ cong (λ z → (y α u) +ᴴ (z α x))\n (sym (isEqui y (-ᴴ u))) ⟩\n (y α u) +ᴴ ((f (y α (-ᴴ u))) α x)\n -- apply peiffer condition here\n ≡⟨ cong ((y α u) +ᴴ_)\n (isPeif (y α (-ᴴ u)) x) ⟩\n (y α u) +ᴴ (((y α (-ᴴ u)) +ᴴ x) +ᴴ (-ᴴ (y α (-ᴴ u))))\n ≡⟨ cong (λ z → (y α u) +ᴴ ((z +ᴴ x) +ᴴ (-ᴴ z)))\n (actOn- A y u) ⟩\n (y α u) +ᴴ (((-ᴴ (y α u)) +ᴴ x) +ᴴ (-ᴴ (-ᴴ (y α u))))\n ≡⟨ cong (λ z → (y α u) +ᴴ (((-ᴴ (y α u)) +ᴴ x) +ᴴ z))\n (invInvo H (y α u)) ⟩\n (y α u) +ᴴ (((-ᴴ (y α u)) +ᴴ x) +ᴴ (y α u))\n ≡⟨ assoc-assoc H (y α u) (-ᴴ (y α u)) x (y α u) ⟩\n (((y α u) +ᴴ (-ᴴ (y α u))) +ᴴ x) +ᴴ (y α u)\n ≡⟨ cong (_+ᴴ (y α u))\n (rCancel-lId H (y α u) x) ⟩\n x +ᴴ (y α u) ∎\n\n r' = ((y +₀ (v +₀ (-₀ (f u +₀ v)))) +₀ ((-₀ y) +₀ y)) +₀ (f u +₀ v)\n ≡⟨ cong (_+₀ (f u +₀ v))\n (lCancel-rId G₀ (y +₀ (v +₀ (-₀ (f u +₀ v)))) y) ⟩\n (y +₀ (v +₀ (-₀ (f u +₀ v)))) +₀ (f u +₀ v)\n ≡⟨ cong (λ z → (y +₀ (v +₀ z)) +₀ (f u +₀ v))\n (invDistr G₀ (f u) v) ⟩\n (y +₀ (v +₀ ((-₀ v) +₀ (-₀ f u)))) +₀ (f u +₀ v)\n ≡⟨ cong (λ z → (y +₀ z) +₀ (f u +₀ v))\n (assoc-rCancel G₀ v (-₀ f u)) ⟩\n (y +₀ (-₀ f u)) +₀ (f u +₀ v)\n ≡⟨ assoc⁻-assocr-lCancel-lId G₀ y (f u) v ⟩\n y +₀ v ∎\n\n q = ((is b +₁ (a +₁ -it a)) +₁ (-is b +₁ b)) +₁ it a\n ≡⟨ refl ⟩\n ((0ᴴ +ᴴ (y α (u +ᴴ (v α ((-₀ ((f u) +₀ v)) α (-ᴴ 0ᴴ)))))) +ᴴ ((y +₀ (v +₀ (-₀ (f u +₀ v)))) α (((-₀ y) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ y) α x)))) +ᴴ (((y +₀ (v +₀ (-₀ (f u +₀ v)))) +₀ ((-₀ y) +₀ y)) α 0ᴴ)\n , ((y +₀ (v +₀ (-₀ (f u +₀ v)))) +₀ ((-₀ y) +₀ y)) +₀ (f u +₀ v)\n ≡⟨ ΣPathP (r , r') ⟩\n x +ᴴ (y α u) , y +₀ v\n ≡⟨ refl ⟩\n b +₁ a ∎\n RelIso.inv (𝒮ᴰ-♭PIso-XModule-Strict2Group (((((G₀' , H) , _α_) , isAct) , φ) , isEqui)) ♭isPeif h h' = q\n where\n open GroupNotationᴴ H\n f = GroupHom.fun φ\n A = groupaction _α_ isAct\n open ActionNotationα A using (α-assoc ; α-hom ; α-id)\n\n SG = F (((((G₀' , H) , _α_) , isAct) , φ) , isEqui)\n -- H⋊G : Group {ℓℓ'}\n H⋊G = snd (fst (fst (fst (fst SG))))\n -- open GroupNotation₁ H⋊G\n open ReflGraphNotation SG\n -- σ : GroupHom H⋊G G₀\n -- ι : GroupHom G₀ H⋊G\n -- τ : GroupHom H⋊G G₀\n -h = -ᴴ h\n abstract\n r₁ = ((0ᴴ +ᴴ (0₀ α (-h +ᴴ (0₀ α ((-₀ ((f -h) +₀ 0₀)) α (-ᴴ 0ᴴ)))))) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h')))) +ᴴ (((0₀ +₀ (0₀ +₀ (-₀ ((f -h) +₀ 0₀)))) +₀ ((-₀ 0₀) +₀ 0₀)) α 0ᴴ)\n ≡⟨ cong fst\n (♭isPeif (-h , 0₀) (h' , 0₀)) ⟩\n h' +ᴴ (0₀ α -h)\n ≡⟨ cong (h' +ᴴ_)\n (α-id -h) ⟩\n h' +ᴴ -h ∎\n\n r₂ = ((0ᴴ +ᴴ (0₀ α (-h +ᴴ (0₀ α ((-₀ ((f -h) +₀ 0₀)) α (-ᴴ 0ᴴ)))))) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h'))))\n +ᴴ (((0₀ +₀ (0₀ +₀ (-₀ ((f -h) +₀ 0₀)))) +₀ ((-₀ 0₀) +₀ 0₀)) α 0ᴴ)\n ≡⟨ cong (((0ᴴ +ᴴ (0₀ α (-h +ᴴ (0₀ α ((-₀ ((f -h) +₀ 0₀)) α (-ᴴ 0ᴴ)))))) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h')))) +ᴴ_)\n (actOnUnit A (((0₀ +₀ (0₀ +₀ (-₀ ((f -h) +₀ 0₀)))) +₀ ((-₀ 0₀) +₀ 0₀))))\n ∙ rIdᴴ _ ⟩\n (0ᴴ +ᴴ (0₀ α (-h +ᴴ (0₀ α ((-₀ ((f -h) +₀ 0₀)) α (-ᴴ 0ᴴ)))))) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h')))\n ≡⟨ cong (λ z → (0ᴴ +ᴴ (0₀ α (-h +ᴴ (0₀ α z)))) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h'))))\n (actOn-Unit A (-₀ ((f -h) +₀ 0₀))) ⟩\n (0ᴴ +ᴴ (0₀ α (-h +ᴴ (0₀ α 0ᴴ)))) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h')))\n ≡⟨ cong (λ z → (0ᴴ +ᴴ (0₀ α (-h +ᴴ z))) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h'))))\n (actOnUnit A 0₀) ⟩\n (0ᴴ +ᴴ (0₀ α (-h +ᴴ 0ᴴ))) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h')))\n ≡⟨ cong (λ z → (0ᴴ +ᴴ (0₀ α z)) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h'))))\n (rIdᴴ -h) ⟩\n (0ᴴ +ᴴ (0₀ α -h)) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h')))\n ≡⟨ cong (λ z → (0ᴴ +ᴴ z) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h'))))\n (α-id -h) ⟩\n (0ᴴ +ᴴ -h) +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h')))\n ≡⟨ cong (_+ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h'))))\n (lIdᴴ -h) ⟩\n -h +ᴴ ((0₀ +₀ (0₀ +₀ (-₀ (f -h +₀ 0₀)))) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h')))\n ≡⟨ cong (λ z → -h +ᴴ (z α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h'))))\n (lId-lId G₀ (-₀ (f -h +₀ 0₀))) ⟩\n -h +ᴴ ((-₀ (f -h +₀ 0₀)) α (((-₀ 0₀) α (-ᴴ 0ᴴ)) +ᴴ ((-₀ 0₀) α h')))\n ≡⟨ cong (λ z → -h +ᴴ ((-₀ (f -h +₀ 0₀)) α (z +ᴴ ((-₀ 0₀) α h'))))\n (actOn-Unit A (-₀ 0₀)) ⟩\n -h +ᴴ ((-₀ (f -h +₀ 0₀)) α (0ᴴ +ᴴ ((-₀ 0₀) α h')))\n ≡⟨ cong (λ z → -h +ᴴ ((-₀ (f -h +₀ 0₀)) α z))\n (lIdᴴ ((-₀ 0₀) α h')) ⟩\n -h +ᴴ ((-₀ (f -h +₀ 0₀)) α ((-₀ 0₀) α h'))\n ≡⟨ cong (λ z → -h +ᴴ ((-₀ (f -h +₀ 0₀)) α z))\n (-idAct A h') ⟩\n -h +ᴴ ((-₀ (f -h +₀ 0₀)) α h')\n ≡⟨ cong (λ z → -h +ᴴ ((-₀ z) α h'))\n (rId₀ (f -h)) ⟩\n -h +ᴴ ((-₀ (f -h)) α h')\n ≡⟨ cong (λ z → -h +ᴴ (z α h'))\n (cong -₀_ (mapInv φ h) ∙ invInvo G₀ (f h)) ⟩\n -h +ᴴ (f h α h') ∎\n\n q = f h α h'\n ≡⟨ sym (lIdᴴ (f h α h'))\n ∙∙ sym (cong (_+ᴴ (f h α h')) (rCancelᴴ h))\n ∙∙ sym (assocᴴ h -h (f h α h')) ⟩\n h +ᴴ (-h +ᴴ (f h α h'))\n ≡⟨ cong (h +ᴴ_)\n (sym r₂ ∙ r₁) ⟩\n h +ᴴ (h' +ᴴ -h)\n ≡⟨ assocᴴ h h' -h ⟩\n (h +ᴴ h') +ᴴ (-ᴴ h) ∎\n\n RelIso.leftInv (𝒮ᴰ-♭PIso-XModule-Strict2Group _) _ = tt\n RelIso.rightInv (𝒮ᴰ-♭PIso-XModule-Strict2Group _) _ = tt\n\n\n Iso-XModule-PeifferGraph : Iso (XModule ℓ ℓℓ') (PeifferGraph ℓ ℓℓ')\n Iso-XModule-PeifferGraph = 𝒮ᴰ-♭PIso-Over→TotalIso ℱ (𝒮ᴰ-XModule ℓ ℓℓ') (𝒮ᴰ-S2G ℓ ℓℓ') 𝒮ᴰ-♭PIso-XModule-Strict2Group\n", "meta": {"hexsha": "46fd70ab0addb62477a8c45adb6a820c2b03a674", "size": 12932, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/DStructures/Equivalences/XModPeifferGraph.agda", "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/DStructures/Equivalences/XModPeifferGraph.agda", "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/DStructures/Equivalences/XModPeifferGraph.agda", "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": 53.6597510373, "max_line_length": 226, "alphanum_fraction": 0.3761212496, "num_tokens": 6285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.39030617128510314}} {"text": "-- Andreas, 2018-05-09, issue 2636, reported by nad\n\n-- {-# OPTIONS -v tc.pos:10 #-}\n\nid : (A : Set₁) → A → A\nid A x = x\n\nA : Set₁\nA = Set\n where\n F : Set₁ → Set₁\n F X = X\n\n data D : Set₁ where\n c : F D → D\n\n lemma : F (D → Set) → D → Set\n lemma fp d = id (F (D → Set)) fp d\n\n-- Problem was:\n-- Positivity checker for D complained when lemma was present.\n", "meta": {"hexsha": "43d754f32d616b014889d1742f3524a0e80f325a", "size": 364, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Bugs/Issue2636.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/Bugs/Issue2636.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/Bugs/Issue2636.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": 16.5454545455, "max_line_length": 62, "alphanum_fraction": 0.5549450549, "num_tokens": 139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757646140788307, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.3902509325871035}} {"text": "{-# OPTIONS --safe -W ignore #-}\n\nmodule Map where\n\nopen import Data.String\nopen import Data.String.Properties using (_==_)\nopen import Data.Bool\nopen import Relation.Binary.PropositionalEquality\nopen import Agda.Builtin.Unit\nopen import Data.Empty\nopen import Relation.Nullary using (¬_)\nimport Relation.Nullary.Decidable.Core\nimport Data.List.Relation.Binary.Pointwise\nimport Data.List.Relation.Binary.Pointwise.Properties\nimport Agda.Builtin.Char.Properties\nimport Agda.Builtin.Char\nimport Data.Nat.Properties\n\n-- The empty map\nK : {A : Set} → (v : A) → (String → A)\nK v = (λ _ → v)\n\n-- Storing in map \"m\" with value \"v\" into key \"k\"\nStore : {A : Set} → (m : (String → A)) → (k : String)\n → (v : A) → (String → A)\nStore m k v = λ k' → if (k' == k) then v else m k'\n\n-- Unit tests\nopen import Data.Nat\n\n-- Example of initialising the variable stack\nS : (String → ℕ)\nS = K 0\n\n-- Example of adding values to a stack\nS1 : (String → ℕ)\nS1 = Store S \"a\" 10\n\n-- Adding the second variable\nS2 : (String → ℕ)\nS2 = Store S1 \"b\" 11\n\n-- Getting the value of a from stack S2\nA : ℕ\nA = S2 \"a\"\n\n-- Getting the value of b from stack S2\nB : ℕ\nB = S2 \"b\"\n\n-- Try to get a string that is not in stack, gives the default value\nC : ℕ\nC = S2 \"c\"\n\n-- Important properties\n\n-- Lemma needed to prove the side condition between stacks after\n-- function call\nlemma-stack-eq : {A : Set} → ∀ (stm stf : (String → A)) → (X Y : String)\n → (Store stm Y (stf X)) Y ≡ (stf X)\nlemma-stack-eq stm stf X Y with (Y Data.String.≟ Y)\n... | .true Relation.Nullary.because Relation.Nullary.ofʸ p = refl\n... | .false Relation.Nullary.because Relation.Nullary.ofⁿ ¬p = ⊥-elim (¬p refl)\n\n-- Now a very important property for proving the constancy rule\nt-update-neq : {A : Set} → ∀ (st : (String → A)) → (x1 x2 : String)\n → (v : A) → ((x2 ≡ x1) → ⊥) → (Store st x1 v) x2 ≡ (st x2)\nt-update-neq st x1 x2 v p with (Relation.Nullary.Decidable.Core.map′\n (λ x →\n Data.String.Properties.toList-injective x2 x1\n (Data.List.Relation.Binary.Pointwise.Pointwise-≡⇒≡ x))\n (λ x →\n Data.List.Relation.Binary.Pointwise.≡⇒Pointwise-≡ (cong toList x))\n (Data.List.Relation.Binary.Pointwise.Properties.decidable\n (λ x y →\n Relation.Nullary.Decidable.Core.map′\n (Agda.Builtin.Char.Properties.primCharToNatInjective x y)\n (cong Agda.Builtin.Char.primCharToNat)\n (Relation.Nullary.Decidable.Core.map′\n (Data.Nat.Properties.≡ᵇ⇒≡ (Agda.Builtin.Char.primCharToNat x)\n (Agda.Builtin.Char.primCharToNat y))\n (Data.Nat.Properties.≡⇒≡ᵇ (Agda.Builtin.Char.primCharToNat x)\n (Agda.Builtin.Char.primCharToNat y))\n (T?\n (Agda.Builtin.Char.primCharToNat x ≡ᵇ\n Agda.Builtin.Char.primCharToNat y))))\n (toList x2) (toList x1)))\n... | false Relation.Nullary.because Relation.Nullary.ofⁿ ¬p = refl\n... | true Relation.Nullary.because Relation.Nullary.ofʸ refl = ⊥-elim (p refl)\n\n-- Testing lookup with nested stores\ntest : {A : Set} → ∀ (x1 x2 y : String) → (st st' : (String → A))\n → (v1 v2 : A) → (y ≡ x1 → ⊥) → (y ≡ x2 → ⊥)\n → (st' ≡ (Store (Store st x1 v1) x2 v2))\n → st' y ≡ st y\ntest x1 x2 y st st' v1 v2 p1 p2 q rewrite q \n | t-update-neq (Store st x1 v1) x2 y v2 p2\n | t-update-neq st x1 y v1 p1 = refl\n\n\n-- Partial map\nopen import Data.Maybe\n\nKP : {A : Set} → (String → Maybe A)\nKP = (λ _ → nothing)\n\nStoreP : {A : Set} → (st : (String → Maybe A))\n → (x : String) → (v : A)\n → (String → Maybe A)\nStoreP st x v = λ x' → if x == x' then just v else st x'\n", "meta": {"hexsha": "424da367552ff5b5e28a996d1db1305b308778c8", "size": 3657, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Map.agda", "max_stars_repo_name": "amal029/compositional-real-time-contracts", "max_stars_repo_head_hexsha": "bff8c271b54f55ceac550c603e468f68838a07ee", "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": "Map.agda", "max_issues_repo_name": "amal029/compositional-real-time-contracts", "max_issues_repo_head_hexsha": "bff8c271b54f55ceac550c603e468f68838a07ee", "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": "Map.agda", "max_forks_repo_name": "amal029/compositional-real-time-contracts", "max_forks_repo_head_hexsha": "bff8c271b54f55ceac550c603e468f68838a07ee", "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": 32.9459459459, "max_line_length": 80, "alphanum_fraction": 0.6152584085, "num_tokens": 1187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757646140788307, "lm_q2_score": 0.5774953651858117, "lm_q1q2_score": 0.3902509325871034}} {"text": "{-# OPTIONS --cubical #-}\n\nopen import Formalization.PredicateLogic.Signature\n\nmodule Formalization.PredicateLogic.Constructive.SequentCalculus (𝔏 : Signature) where\nopen Signature(𝔏)\n\nopen import Data.Option\nopen import Data.List\nopen import Data.List.Functions using (map) renaming (singleton to · ; _++_ to _∪_)\nopen import Data.List.Relation.Permutation\nimport Data.ListSized as S\nopen import Formalization.PredicateLogic.Syntax(𝔏)\nopen import Formalization.PredicateLogic.Syntax.Substitution(𝔏)\nopen import Functional as Fn using ()\nimport Lvl\nopen import Numeral.Natural\nopen import Type\n\nprivate variable ℓ : Lvl.Level\nprivate variable args n vars vars₁ vars₂ : ℕ\nprivate variable Γ Γ₁ Γ₂ Γ₃ : List(Formula(vars))\nprivate variable Δ Δ₁ Δ₂ Δ₃ : Option(Formula(vars))\nprivate variable φ φ₁ φ₂ ψ A B C : Formula(vars)\nprivate variable p : Prop(n)\nprivate variable f : Prop(args)\nprivate variable x : S.List(Term(vars))(args)\n\n_∪·_ : ∀{T : Type{ℓ}} → List(T) → T → List(T)\n_∪·_ = Fn.swap(_⊰_)\ninfixl 1000 _∪·_\n\nmodule Variant1 where\n data _⇒_ : List(Formula(vars)) → Option(Formula(vars)) → Type{Lvl.𝐒(ℓₚ Lvl.⊔ ℓₒ)} where\n axiom : ((· φ) ⇒ Some(φ))\n\n weakenₗ : (Γ ⇒ Δ) → ((Γ ∪· A) ⇒ Δ)\n permuteₗ : (Γ₁ permutes Γ₂) → (Γ₁ ⇒ Δ) → (Γ₂ ⇒ Δ)\n contractₗ : ((Γ ∪· A ∪· A) ⇒ Δ) → ((Γ ∪· A) ⇒ Δ)\n ⊥ₗ : (Γ ∪· ⊥) ⇒ None\n ∧ₗₗ : ((Γ ∪· A) ⇒ Δ) → ((Γ ∪· (A ∧ B)) ⇒ Δ)\n ∧ₗᵣ : ((Γ ∪· B) ⇒ Δ) → ((Γ ∪· (A ∧ B)) ⇒ Δ)\n ∨ₗ : ((Γ ∪· A) ⇒ Δ) → ((Γ ∪· B) ⇒ Δ) → ((Γ ∪· (A ∨ B)) ⇒ Δ)\n ⟶ₗ : (Γ ⇒ Some(A)) → ((Γ ∪· B) ⇒ Δ) → ((Γ ∪· (A ⟶ B)) ⇒ Δ)\n Ɐₗ : ∀{t} → ((Γ ∪· (substitute0 t A)) ⇒ Δ) → ((Γ ∪· (Ɐ A)) ⇒ Δ)\n ∃ₗ : ∀{v}{n} → ((Γ ∪· (substituteN n (var v) A)) ⇒ Δ) → ((Γ ∪· (∃ A)) ⇒ Δ)\n\n weakenᵣ : (Γ ⇒ None) → (Γ ⇒ Some(A))\n ⊤ᵣ : ∅ ⇒ Some(⊤ {vars})\n ∧ᵣ : (Γ ⇒ Some(A)) → (Γ ⇒ Some(B)) → (Γ ⇒ Some(A ∧ B))\n ∨ᵣₗ : (Γ ⇒ Some(A)) → (Γ ⇒ Some(A ∨ B))\n ∨ᵣᵣ : (Γ ⇒ Some(B)) → (Γ ⇒ Some(A ∨ B))\n ⟶ᵣ : ((Γ ∪· A) ⇒ Some(B)) → (Γ ⇒ Some(A ⟶ B))\n Ɐᵣ : ∀{v}{n} → (Γ ⇒ Some((substituteN n (var v) A))) → (Γ ⇒ Some(Ɐ A))\n ∃ᵣ : ∀{t} → (Γ ⇒ Some((substitute0 t A))) → (Γ ⇒ Some(∃ A))\n\n import Logic.Propositional as Meta\n\n no-empty-refl : Meta.¬(∅ ⇒ None{T = Formula vars})\n no-empty-refl (permuteₗ perm p) rewrite Proofs.permutes-on-empty perm = no-empty-refl p\n\n {-\n no-callCC : Meta.¬(∅ ⇒ Some(((A ⟶ B) ⟶ A) ⟶ A))\n no-callCC (permuteₗ perm p) rewrite permutes-on-empty perm = no-callCC p\n no-callCC (weakenᵣ (permuteₗ perm p)) rewrite permutes-on-empty perm = no-empty-refl p\n no-callCC (⟶ᵣ p) = no-callCC {!!}\n {-no-callCC (⟶ᵣ (weakenₗ p)) = {!!}\n no-callCC (⟶ᵣ (permuteₗ x p)) = {!!}\n no-callCC (⟶ᵣ (contractₗ p)) = {!!}\n no-callCC (⟶ᵣ (⟶ₗ p p₁)) = {!!}\n no-callCC (⟶ᵣ (weakenᵣ p)) = {!!}\n no-callCC (⟶ᵣ (∧ᵣ p p₁)) = {!!}\n no-callCC (⟶ᵣ (∨ᵣₗ p)) = {!!}\n no-callCC (⟶ᵣ (∨ᵣᵣ p)) = {!!}\n no-callCC (⟶ᵣ (⟶ᵣ p)) = {!!}\n no-callCC (⟶ᵣ (Ɐᵣ p)) = {!!}\n no-callCC (⟶ᵣ (∃ᵣ p)) = {!!}\n -}\n -}\n\nmodule Variant3 where\n -- Note: Because this formalization is non-standard, a problem arises for Formula(𝟎): It it missing some of the quantification rules because it has no variables.\n data _⇒_ : List(Formula(vars)) → Formula(vars) → Type{Lvl.𝐒(ℓₚ Lvl.⊔ ℓₒ)} where\n axiom : ((Γ ∪· (f $ x)) ⇒ (f $ x))\n\n permuteₗ : (Γ₁ permutes Γ₂) → (Γ₁ ⇒ C) → (Γ₂ ⇒ C)\n ⊥ₗ : (Γ ∪· ⊥) ⇒ A\n ∧ₗ : ((Γ ∪· A ∪· B) ⇒ C) → ((Γ ∪· (A ∧ B)) ⇒ C)\n ∨ₗ : ((Γ ∪· A) ⇒ C) → ((Γ ∪· B) ⇒ C) → ((Γ ∪· (A ∨ B)) ⇒ C)\n ⟶ₗ : ((Γ ∪· (A ⟶ B)) ⇒ A) → ((Γ ∪· B) ⇒ C) → ((Γ ∪· (A ⟶ B)) ⇒ C)\n Ɐₗ : ∀{t} → ((Γ ∪· (substitute0 t A) ∪· (Ɐ A)) ⇒ C) → ((Γ ∪· (Ɐ A)) ⇒ C)\n ∃ₗ : ∀{n}{v} → ((Γ ∪· (substituteN n (var v) A)) ⇒ C) → ((Γ ∪· (∃ A)) ⇒ C)\n\n ⊤ᵣ : Γ ⇒ (⊤ {vars})\n ∧ᵣ : (Γ ⇒ A) → (Γ ⇒ B) → (Γ ⇒ (A ∧ B))\n ∨ᵣₗ : (Γ ⇒ A) → (Γ ⇒ (A ∨ B))\n ∨ᵣᵣ : (Γ ⇒ B) → (Γ ⇒ (A ∨ B))\n ⟶ᵣ : ((Γ ∪· A) ⇒ B) → (Γ ⇒ (A ⟶ B))\n Ɐᵣ : ∀{n}{v} → (Γ ⇒ (substituteN n (var v) A)) → (Γ ⇒ (Ɐ A))\n ∃ᵣ : ∀{t} → (Γ ⇒ (substitute0 t A)) → (Γ ⇒ (∃ A))\n\n import Logic.Propositional as Meta\n open import Numeral.Finite\n open import Type.Properties.Inhabited\n\n weakenₗ : (Γ ⇒ ψ) → ((Γ ∪· φ) ⇒ ψ)\n weakenₗ axiom = permuteₗ swap axiom\n weakenₗ (permuteₗ x p) = permuteₗ (prepend x) (weakenₗ p)\n weakenₗ ⊥ₗ = permuteₗ swap ⊥ₗ\n weakenₗ (∧ₗ p) = permuteₗ swap (∧ₗ(permuteₗ (trans swap (prepend swap)) (weakenₗ p)))\n weakenₗ (∨ₗ p q) = permuteₗ swap (∨ₗ (permuteₗ swap (weakenₗ p)) (permuteₗ swap (weakenₗ q)))\n weakenₗ (⟶ₗ p q) = permuteₗ swap (⟶ₗ (permuteₗ swap (weakenₗ p)) (permuteₗ swap (weakenₗ q)))\n weakenₗ (Ɐₗ p) = permuteₗ swap (Ɐₗ (permuteₗ (trans swap (prepend swap)) (weakenₗ p)))\n weakenₗ (∃ₗ{n = n} p) = permuteₗ swap (∃ₗ{n = n} (permuteₗ swap (weakenₗ p)))\n weakenₗ ⊤ᵣ = ⊤ᵣ\n weakenₗ (∧ᵣ p q) = ∧ᵣ (weakenₗ p) (weakenₗ q)\n weakenₗ (∨ᵣₗ p) = ∨ᵣₗ (weakenₗ p)\n weakenₗ (∨ᵣᵣ p) = ∨ᵣᵣ (weakenₗ p)\n weakenₗ (⟶ᵣ p) = ⟶ᵣ (permuteₗ swap (weakenₗ p))\n weakenₗ (Ɐᵣ{n = n} p) = Ɐᵣ{n = n} (weakenₗ p)\n weakenₗ (∃ᵣ p) = ∃ᵣ (weakenₗ p)\n\n weaken-union : (Γ₂ ⇒ φ) → ((Γ₁ ∪ Γ₂) ⇒ φ)\n weaken-union {Γ₁ = ∅} p = p\n weaken-union {Γ₁ = φ ⊰ Γ₁} p = weakenₗ (weaken-union {Γ₁ = Γ₁} p)\n\n open import Formalization.PredicateLogic.Syntax.Tree(𝔏)\n open import Numeral.Natural.Relation.Order\n open import Numeral.Natural.Relation.Order.Proofs\n open import Relator.Equals\n open import Relator.Equals.Proofs\n open import Structure.Function\n open import Structure.Relator.Properties\n open import Syntax.Function\n\n direct₊ : ∀{φ : Formula(𝐒(vars))} → ((Γ ∪· φ) ⇒ φ)\n direct₊{Γ = Γ}{φ = φ} = induction-on-height(P) (\\{vars}{φ} → proof{vars}{φ}) \\() where\n P = \\{vars} (φ : Formula(vars)) → (vars ≢ 𝟎) → ∀{Γ} → (Γ ∪· φ) ⇒ φ\n proof : ∀{φ : Formula(vars)} → (∀{vars}{ψ : Formula(vars)} → (height ψ < height φ) → P(ψ)) → P(φ)\n proof {𝟎} _ nz with () ← nz [≡]-intro\n proof {𝐒 _} {φ = f $ x} prev _ = axiom\n proof {𝐒 _} {φ = ⊤} prev _ = weakenₗ ⊤ᵣ\n proof {𝐒 _} {φ = ⊥} prev _ = ⊥ₗ\n proof {𝐒 _} {φ = φ ∧ ψ} prev nz = ∧ᵣ (∧ₗ (permuteₗ swap (prev (∧-height-orderₗ{φ = φ}{ψ = ψ}) nz))) (∧ₗ (prev (∧-height-orderᵣ{ψ = ψ}{φ = φ}) nz))\n proof {𝐒 _} {φ = φ ∨ ψ} prev nz = ∨ₗ (∨ᵣₗ (prev (∨-height-orderₗ{φ = φ}{ψ = ψ}) nz)) (∨ᵣᵣ (prev (∨-height-orderᵣ{ψ = ψ}{φ = φ}) nz))\n proof {𝐒 _} {φ = φ ⟶ ψ} prev nz = ⟶ᵣ (permuteₗ swap (⟶ₗ (permuteₗ swap (prev (⟶-height-orderₗ{φ = φ}{ψ = ψ}) nz)) (prev (⟶-height-orderᵣ{ψ = ψ}{φ = φ}) nz)))\n proof {𝐒 v} {φ = Ɐ φ} prev nz = Ɐᵣ{n = 𝟎}{v = 𝟎} (Ɐₗ{t = var 𝟎} (weakenₗ (prev (subtransitivityₗ(_≤_)(_≡_) (congruence₁(𝐒) (substitute-height{φ = φ})) (Ɐ-height-order{φ = φ})) nz)))\n proof {𝐒 v} {φ = ∃ φ} prev nz = ∃ᵣ{t = var 𝟎} (∃ₗ{n = 𝟎}{v = 𝟎} (prev (subtransitivityₗ(_≤_)(_≡_) (congruence₁(𝐒) (substitute-height{φ = φ})) (Ɐ-height-order{φ = φ})) nz))\n\n no-empty-refl : Meta.¬(∅ ⇒ (⊥ {vars}))\n no-empty-refl (permuteₗ perm p) rewrite Proofs.permutes-on-empty perm = no-empty-refl p\n\n no-empty-axiomₗ : Meta.¬(·(p $ x) ⇒ ⊥)\n no-empty-axiomₗ (permuteₗ perm p) rewrite Proofs.permutes-on-singleton perm = no-empty-axiomₗ p\n\n no-empty-axiomᵣ : Meta.¬(∅ ⇒ (p $ x))\n no-empty-axiomᵣ (permuteₗ perm p) rewrite Proofs.permutes-on-empty perm = no-empty-axiomᵣ p\n\n no-negated-axiomᵣ : Meta.¬(∅ ⇒ (¬(p $ x)))\n no-negated-axiomᵣ (permuteₗ perm p) rewrite Proofs.permutes-on-empty perm = no-negated-axiomᵣ p\n no-negated-axiomᵣ (⟶ᵣ p) = no-empty-axiomₗ p\n\n -- 3.5.2\n substitute-proof : ∀{t : 𝕟(vars₁) → Term(vars₂)} → (Γ ⇒ φ) → ((map(substitute t) Γ) ⇒ (substitute t φ))\n substitute-proof p = {!!}\n\n module _ ⦃ pos-prop : ◊(Prop(0)) ⦄ where\n no-excludedMiddle : Meta.¬(∀{A : Formula(vars)} → (∅ ⇒ (A ∨ (¬ A))))\n no-excludedMiddle as = proof(as{[◊]-existence $ S.∅}) where\n proof : Meta.¬(∅ ⇒ ((p $ x) ∨ ¬(p $ x)))\n proof (permuteₗ perm q) rewrite Proofs.permutes-on-empty perm = proof q\n proof (∨ᵣₗ (permuteₗ perm q)) rewrite Proofs.permutes-on-empty perm = no-empty-axiomᵣ q\n proof (∨ᵣᵣ (permuteₗ perm q)) rewrite Proofs.permutes-on-empty perm = no-negated-axiomᵣ q\n proof (∨ᵣᵣ (permuteₗ perm (⟶ᵣ q))) rewrite Proofs.permutes-on-empty perm = no-empty-axiomₗ q\n proof (∨ᵣᵣ (⟶ᵣ (permuteₗ perm q))) rewrite Proofs.permutes-on-singleton perm = no-empty-axiomₗ q\n\n no-doubleNegation : Meta.¬(∀{A : Formula(vars)} → (∅ ⇒ ((¬ ¬ A) ⟶ A)))\n no-doubleNegation as = proof(as{[◊]-existence $ S.∅}) where\n proof : Meta.¬(∅ ⇒ ((¬ ¬(p $ x)) ⟶ (p $ x)))\n proof (permuteₗ perm q) rewrite Proofs.permutes-on-empty perm = proof q\n proof (⟶ᵣ (permuteₗ perm q)) = {!!}\n proof (⟶ᵣ (⟶ₗ q (permuteₗ perm q₁))) = {!!}\n proof (⟶ᵣ (⟶ₗ (permuteₗ perm q) ⊥ₗ)) = {!!}\n proof (⟶ᵣ (⟶ₗ (⟶ₗ q q₁) ⊥ₗ)) = {!!}\n proof (⟶ᵣ (⟶ₗ (⟶ᵣ q) ⊥ₗ)) = {!!}\n\n test : ∀{T : Type{ℓ}} → (Γ₁ permutes Γ₂) → ((Γ₁ ⇒ φ) → T) → ((Γ₂ ⇒ φ) → T)\n test perm p1 p2 = p1 (permuteₗ (symmetry(_permutes_) perm) p2)\n {-# INLINE test #-}\n\n no-callCC : Meta.¬(∀{A B : Formula(vars)} → (∅ ⇒ ((A ⟶ B) ⟶ A) ⟶ A))\n no-callCC as = proof(as{[◊]-existence $ S.∅}{⊥}) where\n proof2 : Meta.¬((∅ ∪· ((p $ x ⟶ ⊥) ⟶ p $ x) ∪· p $ x) ⇒ ⊥)\n proof2 (permuteₗ x t) = {!t!}\n\n proof3 : Meta.¬((∅ ∪· p $ x ∪· ((p $ x ⟶ ⊥) ⟶ p $ x)) ⇒ ⊥)\n proof3 (permuteₗ perm p) = {!!}\n proof3 (⟶ₗ p q) = {!!}\n\n proof : Meta.¬(∅ ⇒ (((p $ x) ⟶ ⊥) ⟶ (p $ x)) ⟶ (p $ x))\n proof (permuteₗ perm q) rewrite Proofs.permutes-on-empty perm = proof q\n proof (⟶ᵣ (permuteₗ perm q)) rewrite Proofs.permutes-on-singleton perm = {!!}\n proof (⟶ᵣ (⟶ₗ (permuteₗ perm q) q₁)) = {!!}\n proof (⟶ᵣ (⟶ₗ (⟶ₗ q (permuteₗ x r)) s)) = {!!}\n proof (⟶ᵣ (⟶ₗ (⟶ₗ q (⟶ᵣ r)) s)) = no-empty-axiomₗ (contract-axiom-bottom r) where\n contract-axiom-bottom : ((·(p $ x) ∪· (p $ x)) ⇒ ⊥) → (·(p $ x) ⇒ ⊥)\n contract-axiom-bottom (permuteₗ x p) = {!!}\n proof (⟶ᵣ (⟶ₗ (⟶ᵣ (permuteₗ perm q)) r)) = proof2 (permuteₗ perm q)\n\n -- proof (⟶ᵣ (⟶ₗ (⟶ᵣ (permuteₗ perm q)) r)) = test (trans swap (symmetry(_permutes_) perm)) (proof ↦ {!⟶ᵣ proof!}) q\n {-proof (⟶ᵣ (⟶ₗ (⟶ᵣ (permuteₗ perm q)) r)) = test (symmetry(_permutes_) perm) proof2 q where\n proof2 : Meta.¬((∅ ∪· ((p $ x ⟶ ⊥) ⟶ p $ x) ∪· p $ x) ⇒ ⊥)\n proof2 (permuteₗ perm p) = test (symmetry(_permutes_) perm) proof2 p-}\n \n {-proof (⟶ᵣ (⟶ₗ (⟶ᵣ (permuteₗ (prepend perm) q)) r)) rewrite permutes-on-singleton perm = {!!}\n proof (⟶ᵣ (⟶ₗ (⟶ᵣ (permuteₗ swap (permuteₗ perm q))) r)) = {!!}\n proof (⟶ᵣ (⟶ₗ (⟶ᵣ (permuteₗ swap (⟶ₗ q₁ (permuteₗ perm q₂)))) r)) = {!!}\n proof (⟶ᵣ (⟶ₗ (⟶ᵣ (permuteₗ (trans perm₁ perm₂) q)) r)) = {!!}-}\n\n --⟶ₗ : ((Γ ∪· (A ⟶ B)) ⇒ A) → ((Γ ∪· B) ⇒ A) → ((Γ ∪· (A ⟶ B)) ⇒ A)\n", "meta": {"hexsha": "cb260a46db03f960209d8b5747026cbb8a41487f", "size": 10743, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Formalization/PredicateLogic/Constructive/SequentCalculus.agda", "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_issues_repo_path": "Formalization/PredicateLogic/Constructive/SequentCalculus.agda", "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": "Formalization/PredicateLogic/Constructive/SequentCalculus.agda", "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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.6108597285, "max_line_length": 187, "alphanum_fraction": 0.528344038, "num_tokens": 5083, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.39025092504513925}} {"text": "{-# OPTIONS --without-K #-}\n\n{- This module serves to develop some basic theory about pointed types.\n After defining the usual notions of pointed types, pointed equivalences,\n and loop spaces, we derive a version of univalence for pointed equivalences\n and observe that univalence between identical types is a pointed equivalence.\n\n We define pointed versions of dependent sums and products using the usual\n notion of pointed families and observe that they commute in a certain sense\n with taking loop spaces. -}\n\nmodule Pointed where\n\nopen import lib.Basics hiding (_⊔_)\nopen import lib.NType2\nopen import lib.types.Nat hiding (_+_)\nopen import lib.types.Pi\nopen import lib.types.Sigma\nopen import lib.types.TLevel\n\nopen import Preliminaries\nopen import UniverseOfNTypes\n\n{- This file contains \n 2.2.15: Fam•\n and \n 2.2.17: has-level-equiv-contr-loops (see end of file)\n-}\n\n{- Pointed types.\n A pointed type is a type (base) together with a chosen element (pt).\n The loop space construction Ω takes a pointed type and returns the type\n of all loops at the given basepoint. The trivial loop is taken as\n canonical element, thus forming a new pointed type. -}\nType• : (i : ULevel) → Type (lsucc i)\nType• i = Σ (Type i) (idf _)\n\nmodule _ {i} (X : Type• i) where\n base = fst X\n pt = snd X\n\n-- Definition 2.2.15\n{- Pointed families.\n A pointed family over a pointed type is a family over the base\n together with a inhabitant of the family at the point.\n Note that pointed types are equivalent to pointed families\n over the pointed unit type (not shown here). -}\nFam• : ∀ {i} (X : Type• i) (j : ULevel) → Type (i ⊔ lsucc j)\nFam• X j = Σ (base X → Type j) (λ P → P (pt X))\n\n\n-- Alternate definition: Σ (n -Type i) ⟦_⟧\n_-Type•_ : (n : ℕ₋₂) (i : ULevel) → Type (lsucc i)\nn -Type• i = Σ (Type• i) (has-level n ∘ base)\n\n-- For alternate definition: Σ-≤ (n -Type-≤ i) raise\n_-Type•-≤_ : (n : ℕ₋₂) (i : ULevel) → S n -Type lsucc i\nn -Type•-≤ i = ((n -Type• i)\n , equiv-preserves-level Σ-comm-snd\n (snd (Σ-≤ (n -Type-≤ i) raise)))\n\n{- Pointed equivalences.\n An equivalence of pointed types is an equivalences of the bases\n that preserves the points -}\n_≃•_ : ∀ {i j} → Type• i → Type• j → Set (i ⊔ j)\nA ≃• B = Σ (base A ≃ base B) (λ f → –> f (pt A) == pt B)\n\nide• : ∀ {i} (X : Type• i) → X ≃• X\nide• _ = ide _ , idp\n\n_∘e•_ : ∀ {i j k} {X : Type• i} {Y : Type• j} {Z : Type• k}\n → Y ≃• Z → X ≃• Y → X ≃• Z\n(u , p) ∘e• (v , q) = (u ∘e v , ap (–> u) q ∙ p)\n\n_⁻¹• : ∀ {i j} {X : Type• i} {Y : Type• j} → X ≃• Y → Y ≃• X\n(u , p) ⁻¹• = u ⁻¹ , ap (<– u) (! p) ∙ <–-inv-l u _\n\n-- Equational reasoning for pointed equivalences.\ninfix 2 _≃•∎\ninfixr 2 _≃•⟨_⟩_\n\n_≃•⟨_⟩_ : ∀ {i j k} (X : Type• i) {Y : Type• j} {Z : Type• k}\n → X ≃• Y → Y ≃• Z → X ≃• Z\n_ ≃•⟨ u ⟩ v = v ∘e• u\n\n_≃•∎ : ∀ {i} (X : Type• i) → X ≃• X\n_≃•∎ = ide•\n\n\n-- The loop space construction.\nΩ : ∀ {i} → Type• i → Type• i\nΩ (A , a) = ((a == a) , idp)\n\nΩ-≤ : ∀ {i} {n : ℕ₋₂} → (S n) -Type• i → n -Type• i\nΩ-≤ ((A , a) , t) = (Ω (A , a) , t a a)\n\n-- Loop spaces are preserved by pointed equivalences.\nequiv-Ω : ∀ {i j} {X : Type• i} {Y : Type• j} → X ≃• Y → Ω X ≃• Ω Y\nequiv-Ω (u , p) = split u p where\n split : ∀ u {a} {b} → –> u a == b → Ω (_ , a) ≃• Ω (_ , b)\n split u idp = (equiv-ap u _ _ , idp)\n\nequiv-Ω^ : ∀ {i j} {X : Type• i} {Y : Type• j} (n : ℕ)\n → X ≃• Y → (Ω ^ n) X ≃• (Ω ^ n) Y\nequiv-Ω^ 0 e = e\nequiv-Ω^ (S n) e = equiv-Ω^ n (equiv-Ω e)\n\n\n{- We call a pointed type n-truncated if its base is.\n Constructing the loop space decrements the truncation level. -}\nhas-level• : ∀ {i} → ℕ₋₂ → Type• i → Type i\nhas-level• n = has-level n ∘ base\n\ntrunc-many : ∀ {i} {X : Type• i} {k : ℕ} (n : ℕ)\n → has-level• ((k + n) -2) X\n → has-level• (k -2) ((Ω ^ n) X)\ntrunc-many 0 t = t\ntrunc-many (S n) t = trunc-many n (t _ _)\n\n--Ω^-≤ : ∀ {i} {k : ℕ} (n : ℕ) → (k + n -2) -Type• i → (k -2) -Type• i\n--Ω^-≤ O X = X\n--Ω^-≤ (S n) X = Ω^-≤ n (Ω-≤ X)\n\nΩ^-≤ : ∀ {i} {k : ℕ} (n : ℕ) → ((k + n) -2) -Type• i → (k -2) -Type• i\nΩ^-≤ n (X , t) = ((Ω ^ n) X , trunc-many n t)\n\nΩ^-≤' : ∀ {i} {k : ℕ} (n : ℕ) → ((n + k) -2) -Type• i → (k -2) -Type• i\nΩ^-≤' n (X , t) =\n ((Ω ^ n) X , trunc-many n (transport (λ z → has-level• (z -2) X)\n (+-comm _ n) t))\n\n\n{- Pointedness allows for a more direct notion of contractibility.\n Beware that is-contr• will be equivalent --- not definitionally equal ---\n to has-level∙ ⟨-2⟩. -}\nmodule _ {i} (X : Type• i) where\n is-contr• : Type i\n is-contr• = ∀ a → pt X == a\n\n{- Since pointed types are always inhabited,\n being contractible and propositional is equivalent. -}\nmodule _ {i} {X : Type• i} where\n contr•-equiv-contr : is-contr• X ≃ is-contr (base X)\n contr•-equiv-contr = prop-equiv'\n (λ c → Π-level (λ a → raise-level- f (pt A) == pt B)\n ≃⟨ equiv-Σ-fst _ (snd (ua-equiv ⁻¹)) ⁻¹ ⟩\n Σ (base A == base B) (λ q → coe q (pt A) == pt B)\n ≃⟨ equiv-Σ-snd (λ q → coe-equiv (ap (λ f → coe f (pt A) == pt B)\n (! (ap-idf q)))) ⟩\n Σ (base A == base B) (λ q → coe (ap (idf _) q) (pt A) == pt B)\n ≃⟨ equiv-Σ-snd (λ q → to-transp-equiv _ q ⁻¹) ⟩\n Σ (base A == base B) (λ q → pt A == pt B [ idf _ ↓ q ])\n ≃⟨ =Σ-eqv _ _ ⟩\n A == B\n ≃∎\n\n ua• : A ≃• B → A == B\n ua• = –> ua•-equiv\n\n coe•-equiv : A == B → A ≃• B\n coe•-equiv = <– ua•-equiv\n\n-- Normal univalence can be made pointed in the endo-setting.\nmodule _ {i} {A : Type i} where\n ua-equiv• : ((A ≃ A) , ide _) ≃• ((A == A) , idp)\n ua-equiv• = ((ua-equiv ⁻¹) , idp) ⁻¹•\n\n\n-- Lemma 2.2.17\n{- The induction step for Lemma 7.2.9 in the HoTT Book is\n more complicated than necesarry. Associating iterated loop spaces in\n the reverse order, we can do it with the prerequisites 7.2.7 and 7.2.8\n (of the book) as well as further auxiliary steps. -}\nhas-level-equiv-contr-loops : ∀ {i} {n : ℕ} {A : Type i}\n → has-level (n -1) A\n ≃ ((a : A) → is-contr• ((Ω ^ n) (A , a)))\nhas-level-equiv-contr-loops {n = O} {A} =\n is-prop A ≃⟨ prop-equiv-inhab-to-contr ⟩\n (A → is-contr A) ≃⟨ equiv-Π-r (λ _ → contr•-equiv-contr ⁻¹) ⟩\n ((a : A) → is-contr• (A , a)) ≃∎\nhas-level-equiv-contr-loops {n = S n} {A} = equiv-Π-r lem where\n lem = λ a →\n (((b : A) → has-level (n -1) (a == b)))\n ≃⟨ equiv-Π-r (λ _ → has-level-equiv-contr-loops) ⟩\n (((b : A) (p : a == b) → is-contr• ((Ω ^ n) ((a == b) , p))))\n ≃⟨ Π₁-contr (pathfrom-is-contr _) ∘e curry-equiv ⁻¹ ⟩\n is-contr• ((Ω ^ n) ((a == a) , idp))\n ≃∎\n\n\n", "meta": {"hexsha": "38fef0777b93adc285a90c4fdba5fdc9b7305c74", "size": 7977, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "nicolai/thesis/Pointed.agda", "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolai/thesis/Pointed.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": "nicolai/thesis/Pointed.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": 35.4533333333, "max_line_length": 80, "alphanum_fraction": 0.5196189044, "num_tokens": 3038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.5774953651858117, "lm_q1q2_score": 0.3902509250451392}} {"text": "module OpAppP where\n\ndata Bool\n : Set\n where\n\n false\n : Bool\n\n true\n : Bool\n\n_&&_\n : Bool\n → Bool\n → Bool\nfalse && _\n = false\ntrue && b\n = b\n\n", "meta": {"hexsha": "6ec4a0f18ef4ceb9ae47116db71168ea2365ff02", "size": 157, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "data/pattern/OpAppP.agda", "max_stars_repo_name": "msuperdock/agda-unused", "max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z", "max_issues_repo_path": "data/pattern/OpAppP.agda", "max_issues_repo_name": "msuperdock/agda-unused", "max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "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": "data/pattern/OpAppP.agda", "max_forks_repo_name": "msuperdock/agda-unused", "max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z", "avg_line_length": 7.1363636364, "max_line_length": 19, "alphanum_fraction": 0.5159235669, "num_tokens": 60, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.3902220614081495}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import HoTT\n\n{- A proof that (A * B) * C ≃ (C * B) * A, which combined with commutativity\n - proves associativity.\n -\n - Agda has a hard time compiling this but sometimes it succeeds.\n -\n - Favonia (2016 May): I have consistent success in compiling this file.\n -\n -}\n\nopen import homotopy.JoinComm\n\nmodule homotopy.JoinAssocCubical where\n\n{- Square and cube lemmas. Some of these are probably generally useful -}\nprivate\n\n app=cst-square : ∀ {i j} {A : Type i} {B : Type j}\n {b : B} {f : A → B} (p : ∀ a → f a == b)\n {a₁ a₂ : A} (q : a₁ == a₂)\n → Square (p a₁) (ap f q) idp (p a₂)\n app=cst-square p idp = hid-square\n\n app=cst-square= : ∀ {i j} {A : Type i} {B : Type j}\n {b : B} {f : A → B} {p₁ p₂ : ∀ a → f a == b}\n (α : ∀ a → p₁ a == p₂ a) {a₁ a₂ : A} (q : a₁ == a₂)\n → Cube (app=cst-square p₁ q)\n (app=cst-square p₂ q)\n (horiz-degen-square $ α a₁)\n hid-square\n hid-square\n (horiz-degen-square $ α a₂)\n app=cst-square= α idp = y-degen-cube idp\n\n app=cst-square-β : ∀ {i j} {A : Type i} {B : Type j} {b : B} {f : A → B}\n (g : (a : A) → f a == b) {x y : A} (p : x == y)\n {sq : Square (g x) (ap f p) idp (g y)}\n → apd g p == ↓-app=cst-from-square sq\n → app=cst-square g p == sq\n app=cst-square-β g idp α =\n ! horiz-degen-square-idp ∙ ap horiz-degen-square α ∙ horiz-degen-square-β _\n\n ap-∘-app=cst-square : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}\n {b : B} {f : A → B} (h : B → C) (g : (a : A) → f a == b)\n {x y : A} (p : x == y)\n → Cube (app=cst-square (ap h ∘ g) p)\n (ap-square h (app=cst-square g p))\n hid-square\n (horiz-degen-square $ ap-∘ h f p)\n ids\n hid-square\n ap-∘-app=cst-square h g idp =\n cube-shift-right (! ap-square-hid) $\n cube-shift-top (! horiz-degen-square-idp) $\n x-degen-cube idp\n\n cube-to-↓-rtriangle : ∀ {i j} {A : Type i} {B : Type j}\n {b₀ b₁ : A → B} {b : B} {p₀₁ : (a : A) → b₀ a == b₁ a}\n {p₀ : (a : A) → b₀ a == b} {p₁ : (a : A) → b₁ a == b}\n {x y : A} {q : x == y}\n {sqx : Square (p₀₁ x) (p₀ x) (p₁ x) idp}\n {sqy : Square (p₀₁ y) (p₀ y) (p₁ y) idp}\n → Cube sqx sqy (natural-square p₀₁ q) (app=cst-square p₀ q)\n (app=cst-square p₁ q) ids\n → sqx == sqy [ (λ z → Square (p₀₁ z) (p₀ z) (p₁ z) idp) ↓ q ]\n cube-to-↓-rtriangle {q = idp} cu = x-degen-cube-out cu\n\n{- approximately, [massage] describes the action of\n - [switch : (A * B) * C → (C * B) * A] on the level of squares -}\nprivate\n\n massage : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}\n {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n → Square p₀₋ p₋₀ p₋₁ p₁₋\n → Square (! p₀₋) (p₋₁ ∙ ! p₁₋) idp (! p₋₀)\n massage ids = ids\n\n massage-massage : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₁₋ : a₁₀ == a₀₁}\n (sq : Square p₀₋ p₋₀ idp p₁₋)\n → Cube (massage (massage sq)) sq\n (horiz-degen-square (!-! p₀₋)) (horiz-degen-square (!-! p₋₀))\n ids (horiz-degen-square (!-! p₁₋))\n massage-massage = square-bot-J\n (λ sq → Cube (massage (massage sq)) sq\n (horiz-degen-square (!-! _)) (horiz-degen-square (!-! _))\n ids (horiz-degen-square (!-! _)))\n idc\n\n ap-square-massage : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)\n {a₀₀ a₀₁ a₁₀ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₁₋ : a₁₀ == a₀₁}\n (sq : Square p₀₋ p₋₀ idp p₁₋)\n → Cube (ap-square f (massage sq)) (massage (ap-square f sq))\n (horiz-degen-square (ap-! f p₀₋))\n (horiz-degen-square (ap-! f p₁₋))\n ids\n (horiz-degen-square (ap-! f p₋₀))\n ap-square-massage f = square-bot-J\n (λ sq → Cube (ap-square f (massage sq)) (massage (ap-square f sq))\n (horiz-degen-square (ap-! f _))\n (horiz-degen-square (ap-! f _))\n ids\n (horiz-degen-square (ap-! f _)))\n idc\n\n massage-cube : ∀ {i} {A : Type i}\n {a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}\n {p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}\n {p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}\n {sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left\n\n {p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}\n {p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}\n {sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- right\n\n {p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}\n {p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}\n {sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back\n {sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁} -- top\n {sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁} -- bottom\n {sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front\n → Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋\n → Cube (massage sq₋₋₀) (massage sq₋₋₁)\n (!□v sq₀₋₋) (sq₋₁₋ ⊡v !□v sq₁₋₋) vid-square (!□v sq₋₀₋)\n massage-cube idc = idc\n\nprivate\n module _ {i j k} {A : Type i} {B : Type j} {C : Type k} where\n\n {- Define an involutive map [switch] -}\n\n module SwitchLeft = PushoutRec {d = *-span A B} {D = (C * B) * A}\n (λ a → right a)\n (λ b → left (right b))\n (λ {(a , b) → ! (glue (right b , a))})\n\n switch-coh-fill : (a : A) (b : B) (c : C) → Σ\n (Square (! (glue (left c , a))) (ap SwitchLeft.f (glue (a , b)))\n idp (! (ap left (glue (c , b)))))\n (λ sq → Cube\n sq (massage $ app=cst-square (λ j → glue (j , a)) (glue (c , b)))\n hid-square (horiz-degen-square (SwitchLeft.glue-β (a , b)))\n ids hid-square)\n switch-coh-fill a b c = fill-cube-left _ _ _ _ _\n\n module SwitchCoh (c : C) = PushoutElim {d = *-span A B}\n {P = λ k → SwitchLeft.f k == left (left c)}\n (λ a → ! (glue (left c , a)))\n (λ b → ! (ap left (glue (c , b))))\n (↓-app=cst-from-square ∘ λ {(a , b) → fst (switch-coh-fill a b c)})\n\n module Switch = PushoutRec {d = *-span (A * B) C} {D = (C * B) * A}\n SwitchLeft.f\n (λ c → left (left c))\n (λ {(k , c) → SwitchCoh.f c k})\n\n switch = Switch.f\n\n module _ {i j k} {A : Type i} {B : Type j} {C : Type k} where\n\n {- Proof that [switch] is involutive. There are three squares involved:\n - one indexed by A × B, one indexed by A × C, and one by B × C.\n - These are related by a cube indexed by A × B × C.\n - We get the squares for free by defining the cube, as long as\n - we make sure the right faces are dependent on the right types. -}\n\n {- Three big square terms follow; unfortunately Agda can't figure out\n - what these have to be on its own. Don't worry about the defns. -}\n\n switch-inv-left-square : (a : A) (b : B)\n → Square idp (ap (switch {A = C} ∘ SwitchLeft.f) (glue (a , b)))\n (ap left (glue (a , b))) idp\n switch-inv-left-square a b = square-symmetry $\n (horiz-degen-square (ap-∘ switch SwitchLeft.f (glue (a , b))))\n ⊡h ap-square switch (horiz-degen-square (SwitchLeft.glue-β (a , b)))\n ⊡h horiz-degen-square (ap-! switch (glue (right b , a)))\n ⊡h !□v (!□h hid-square)\n ⊡h !□v (horiz-degen-square (Switch.glue-β (right b , a)))\n ⊡h !□v hid-square\n ⊡h horiz-degen-square (!-! _)\n\n switch-inv-coh-left : (c : C) (a : A)\n → Square idp (ap (switch {B = B}) (SwitchCoh.f c (left a)))\n (glue (left a , c)) idp\n switch-inv-coh-left c a = square-symmetry $\n hid-square\n ⊡h ap-square switch hid-square\n ⊡h horiz-degen-square (ap-! switch (glue (left c , a)))\n ⊡h !□v (!□h hid-square)\n ⊡h !□v (horiz-degen-square (Switch.glue-β (left c , a)))\n ⊡h !□v hid-square\n ⊡h horiz-degen-square (!-! _)\n\n switch-inv-coh-right : (c : C) (b : B)\n → Square idp (ap (switch {C = A}) (SwitchCoh.f c (right b)))\n (glue (right b , c)) idp\n switch-inv-coh-right c b = square-symmetry $\n hid-square\n ⊡h ap-square switch hid-square\n ⊡h horiz-degen-square (ap-! switch (ap left (glue (c , b))))\n ⊡h !□v (!□h (horiz-degen-square (ap-∘ switch left (glue (c , b)))))\n ⊡h !□v hid-square\n ⊡h !□v (horiz-degen-square (SwitchLeft.glue-β (c , b)))\n ⊡h horiz-degen-square (!-! _)\n\n module SwitchInvLeft = PushoutElim {d = *-span A B}\n {P = λ k → switch {A = C} (switch (left k)) == left k}\n (λ a → idp)\n (λ b → idp)\n (↓-='-from-square ∘ uncurry switch-inv-left-square)\n\n {- In very small steps, build up the cube -}\n module Coh (a : A) (b : B) (c : C) where\n\n step₁ : Cube\n (app=cst-square (ap switch ∘ SwitchCoh.f c) (glue (a , b)))\n (ap-square switch (app=cst-square (SwitchCoh.f c) (glue (a , b))))\n _ _ _ _\n step₁ = ap-∘-app=cst-square switch (SwitchCoh.f c) (glue (a , b))\n\n step₂ : Cube\n (ap-square switch (app=cst-square (SwitchCoh.f c) (glue (a , b))))\n (ap-square switch $ massage $\n app=cst-square (λ j → glue (j , a)) (glue (c , b)))\n _ _ _ _\n step₂ =\n cube-shift-left\n (! (ap (ap-square switch)\n (app=cst-square-β (SwitchCoh.f c) (glue (a , b))\n (SwitchCoh.glue-β c (a , b)))))\n (ap-cube switch (snd (switch-coh-fill a b c)))\n\n step₃ : Cube\n (ap-square switch $ massage $\n app=cst-square (λ j → glue (j , a)) (glue (c , b)))\n (massage $ ap-square switch $\n app=cst-square (λ j → glue (j , a)) (glue (c , b)))\n _ _ _ _\n step₃ = ap-square-massage switch\n (app=cst-square (λ j → glue (j , a)) (glue (c , b)))\n\n step₄ : Cube\n (massage $ ap-square switch $\n app=cst-square (λ j → glue (j , a)) (glue (c , b)))\n (massage $\n app=cst-square (λ j → ap switch (glue (j , a))) (glue (c , b)))\n _ _ _ _\n step₄ = massage-cube $ cube-!-x $\n ap-∘-app=cst-square switch (λ j → glue (j , a)) (glue (c , b))\n\n step₅ : Cube\n (massage $\n app=cst-square (λ j → ap switch (glue (j , a))) (glue (c , b)))\n (massage $ app=cst-square (SwitchCoh.f a) (glue (c , b)))\n _ _ _ _\n step₅ = massage-cube $\n app=cst-square= (λ j → Switch.glue-β (j , a)) (glue (c , b))\n\n step₆ : Cube\n (massage $ app=cst-square (SwitchCoh.f a) (glue (c , b)))\n (massage $ massage $\n app=cst-square (λ k → glue (k , c)) (glue (a , b)))\n _ _ _ _\n step₆ = massage-cube $\n cube-shift-left\n (! (app=cst-square-β (SwitchCoh.f a) (glue (c , b))\n (SwitchCoh.glue-β a (c , b))))\n (snd (switch-coh-fill c b a))\n\n step₇ : Cube\n (massage $ massage $\n app=cst-square (λ k → glue {d = *-span (A * B) C} (k , c))\n (glue (a , b)))\n (app=cst-square (λ k → glue (k , c)) (glue (a , b)))\n _ _ _ _\n step₇ = massage-massage _\n\n switch-inv-cube : Cube\n (switch-inv-coh-left c a) (switch-inv-coh-right c b)\n (switch-inv-left-square a b)\n (app=cst-square (ap switch ∘ SwitchCoh.f c) (glue (a , b)))\n (app=cst-square (λ k → glue (k , c)) (glue (a , b)))\n ids\n switch-inv-cube = cube-rotate-x→z $\n step₁ ∙³x step₂ ∙³x step₃ ∙³x step₄ ∙³x step₅ ∙³x step₆ ∙³x step₇\n\n\n module SwitchInvCoh (c : C) = PushoutElim {d = *-span A B}\n {P = λ k → Square (SwitchInvLeft.f k) (ap switch (SwitchCoh.f c k))\n (glue (k , c)) idp}\n (switch-inv-coh-left c)\n (switch-inv-coh-right c)\n (cube-to-↓-rtriangle ∘ λ {(a , b) →\n cube-shift-back\n (! (natural-square-β SwitchInvLeft.f (glue (a , b))\n (SwitchInvLeft.glue-β (a , b))))\n (Coh.switch-inv-cube a b c)})\n\n abstract\n switch-inv : (l : (A * B) * C) → switch (switch l) == l\n switch-inv = Pushout-elim\n SwitchInvLeft.f\n (λ c → idp)\n (↓-∘=idf-from-square switch switch ∘ λ {(k , c) →\n ap (ap switch) (Switch.glue-β (k , c)) ∙v⊡ SwitchInvCoh.f c k})\n\nmodule _ {i j k} {A : Type i} {B : Type j} {C : Type k} where\n\n join-rearrange-equiv : (A * B) * C ≃ (C * B) * A\n join-rearrange-equiv = equiv switch switch switch-inv switch-inv\n\n join-rearrange-path : (A * B) * C == (C * B) * A\n join-rearrange-path = ua join-rearrange-equiv\n\n join-assoc-path : (A * B) * C == A * (B * C)\n join-assoc-path = join-rearrange-path ∙ swap-path ∙ ap (A *_) swap-path\n\n *-assoc = join-assoc-path\n\nmodule _ {i j k} (X : Ptd i) (Y : Ptd j) (Z : Ptd k) where\n\n join-rearrange-⊙path : (X ⊙* Y) ⊙* Z == (Z ⊙* Y) ⊙* X\n join-rearrange-⊙path =\n ⊙ua (⊙≃-in join-rearrange-equiv (! (glue (left (snd Z), snd X))))\n", "meta": {"hexsha": "c8ca03dc25e822b5bff671b02e223f1162aad094", "size": 12554, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/JoinAssocCubical.agda", "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "theorems/homotopy/JoinAssocCubical.agda", "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "theorems/homotopy/JoinAssocCubical.agda", "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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.1580547112, "max_line_length": 79, "alphanum_fraction": 0.506292815, "num_tokens": 4897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056295505783, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.39015976274064484}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Homomorphism proofs for variables and constants over polynomials\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nopen import Tactic.RingSolver.Core.Polynomial.Parameters\n\nmodule Tactic.RingSolver.Core.Polynomial.Homomorphism.Variables\n {r₁ r₂ r₃ r₄}\n (homo : Homomorphism r₁ r₂ r₃ r₄)\n where\n\nopen import Data.Product using (_,_)\nopen import Data.Vec.Base as Vec using (Vec)\nopen import Data.Fin using (Fin)\nopen import Data.List.Kleene\n\nopen Homomorphism homo\n\nopen import Tactic.RingSolver.Core.Polynomial.Homomorphism.Lemmas homo\nopen import Tactic.RingSolver.Core.Polynomial.Base (Homomorphism.from homo)\nopen import Tactic.RingSolver.Core.Polynomial.Reasoning (Homomorphism.to homo)\nopen import Tactic.RingSolver.Core.Polynomial.Semantics homo\n\nopen import Algebra.Operations.Ring rawRing\n\nι-hom : ∀ {n} (i : Fin n) (Ρ : Vec Carrier n) → ⟦ ι i ⟧ Ρ ≈ Vec.lookup Ρ i\nι-hom i Ρ′ = let (ρ , Ρ) = drop-1 (space≤′n i) Ρ′ in begin\n ⟦ (κ Raw.1# Δ 1 ∷↓ []) ⊐↓ space≤′n i ⟧ Ρ′ ≈⟨ ⊐↓-hom (κ Raw.1# Δ 1 ∷↓ []) (space≤′n i) Ρ′ ⟩\n ⅀?⟦ κ Raw.1# Δ 1 ∷↓ [] ⟧ (ρ , Ρ) ≈⟨ ∷↓-hom-s (κ Raw.1#) 0 [] ρ Ρ ⟩\n ρ * ⟦ κ Raw.1# ⟧ Ρ ≈⟨ *≫ 1-homo ⟩\n ρ * 1# ≈⟨ *-identityʳ ρ ⟩\n ρ ≡⟨ drop-1⇒lookup i Ρ′ ⟩\n Vec.lookup Ρ′ i ∎\n", "meta": {"hexsha": "d57760c0e3271033cc6e0d793f90b03cd6b1c5d6", "size": 1538, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Homomorphism/Variables.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "agda-stdlib/src/Tactic/RingSolver/Core/Polynomial/Homomorphism/Variables.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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-stdlib/src/Tactic/RingSolver/Core/Polynomial/Homomorphism/Variables.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 40.4736842105, "max_line_length": 93, "alphanum_fraction": 0.5377113134, "num_tokens": 505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.39009851122036704}} {"text": "open import Relation.Binary.PropositionalEquality using \n ( _≡_ ; refl ; sym ; trans ; subst ; subst₂ ; cong ; cong₂ )\n\nopen import AssocFree.Util using ( δsubst₂ )\n\nimport AssocFree.STLambdaC.Typ\nimport AssocFree.STLambdaC.Exp\nimport AssocFree.STLambdaC.NF\nimport AssocFree.STLambdaC.Redn\n\nmodule AssocFree.STLambdaC.Eval\n (TConst : Set) \n (Const : AssocFree.STLambdaC.Typ.Typ TConst → Set) where\n\nopen Relation.Binary.PropositionalEquality.≡-Reasoning using ( begin_ ; _≡⟨_⟩_ ; _∎ )\n\nopen module Typ = AssocFree.STLambdaC.Typ TConst using \n ( Typ ; Ctxt ; const ; _⇝_ ; [_] ; [] ; _∷_ ; _++_ ; _∈_ ; uniq\n ; Case ; case ; inj₁ ; inj₂ ; case-≫ ; _≪_ ; _≫_ )\n\nopen module Exp = AssocFree.STLambdaC.Exp TConst Const using \n ( Exp ; exp ; const ; abs ; app ; var ; var₀ \n ; Substn ; substn+ ; substn* ; xsubstn+ ; weaken+ ; weaken* ; weakens* \n ; ⟨_⟩ ; choose ; _◁_ ; id\n ; weaken*-[] ; weaken*-++ ; substn*-◁ ; substn*-id )\n\nopen module NF = AssocFree.STLambdaC.NF TConst Const using \n ( Atom ; NF ; var ; const ; app ; abs ; atom ; atom₀ ; aweaken* )\n\nopen module Redn = AssocFree.STLambdaC.Redn TConst Const using \n ( _⇒_ ; _⇓ ; _⇓′ ; eta ; beta ; lhs ; atom ; nf ; redn ; tgt ; ⇓abs ; ⇓app ; rweaken* )\n\n-- Values\n\ndata cVal {Γ C} : Exp Γ (const C) → Set where\n atom : ∀ {M} → Atom M → cVal M\n redn : ∀ {M N} → (M ⇒ N) → cVal N → cVal M\n\ndata fVal {Γ T U} (F : ∀ {Γ} → Exp Γ T → Set) (G : ∀ {Γ} → Exp Γ U → Set) : Exp Γ (T ⇝ U) → Set where\n fun : ∀ {M} → (∀ Δ → {N : Exp (Δ ++ Γ) T} → F N → G (app (weaken* Δ {Γ} M) N)) → fVal F G M\n redn : ∀ {M N} → (M ⇒ N) → fVal F G N → fVal F G M\n\nVal : ∀ {Γ T} → Exp Γ T → Set\nVal {Γ} {const C} M = cVal M\nVal {Γ} {T ⇝ U} M = fVal Val Val M\n\n-- Values are closed under reduction and application\n\nvredn : ∀ {Γ T} {M N : Exp Γ T} → (M ⇒ N) → Val N → Val M\nvredn {Γ} {const C} = redn\nvredn {Γ} {T ⇝ U} = redn\n\nvapp : ∀ {Γ T U} {M : Exp Γ (T ⇝ U)} {N : Exp Γ T} → Val M → Val N → Val (app M N)\nvapp {Γ} {T} {U} {M} {N} (fun f) W = subst (λ X → Val (app X N)) (weaken*-[] M) (f [] W)\nvapp (redn M⇒N V) W = vredn (lhs M⇒N) (vapp V W)\n\n-- Reification and reflection\n\nmutual\n\n reify : ∀ {Γ T} {M : Exp Γ T} → Val M → (M ⇓)\n reify {Γ} {const C} (atom N) = nf (atom N)\n reify {Γ} {const C} (redn M⇒N V) = redn M⇒N (reify V)\n reify {Γ} {T ⇝ U} {M} (fun f) = redn (eta M) (⇓abs {Γ} T (reify (f [ T ] (reflect (atom (atom₀ {Γ}))))))\n reify {Γ} {T ⇝ U} (redn M⇒N V) = redn M⇒N (reify V)\n\n reflect : ∀ {Γ T} {M : Exp Γ T} → (M ⇓′) → Val M\n reflect {Γ} {const C} (atom M) = atom M\n reflect {Γ} {T ⇝ U} (atom M) = fun (λ Δ V → reflect (⇓app (atom (aweaken* Δ M)) (reify V)))\n reflect (redn M⇒N N⇓) = vredn M⇒N (reflect N⇓)\n\n-- Value substitutions\n\nVals : ∀ {Γ Δ} → Substn (exp var) Γ Δ → Set\nVals {Γ} {Δ} σ = ∀ {T} (x : T ∈ Δ) → Val (σ x)\n\n⟪_⟫ : ∀ {Γ T} {N : Exp Γ T} → Val N → Vals ⟨ N ⟩\n⟪ V ⟫ x = δsubst₂ (λ X Y → Val {T = X} Y) (uniq x) refl V\n\nvchoose : ∀ {Γ Δ E} {σ : Substn (exp var) Γ Δ} {τ : Substn (exp var) Γ E} → Vals σ → Vals τ →\n ∀ {T} (x : Case T Δ E) → Val (choose σ τ x)\nvchoose Vs Ws (inj₁ x) = Vs x\nvchoose Vs Ws (inj₂ x) = Ws x\n\n_◂_ : ∀ {Γ Δ T} {N : Exp Γ T} {σ : Substn (exp var) Γ Δ} → Val N → Vals σ → Vals (N ◁ σ)\n_◂_ {Γ} {Δ} {T} V Vs x = vchoose ⟪ V ⟫ Vs (case [ T ] Δ x)\n\n-- Weakening\n\nvweaken* : ∀ {Γ} Δ {U} {M : Exp Γ U} → Val M → Val (weaken* Δ M)\nvweaken* Δ {const C} (atom N) = atom (aweaken* Δ N)\nvweaken* Δ {const C} (redn M⇒N V) = redn (rweaken* Δ M⇒N) (vweaken* Δ V)\nvweaken* Δ {T ⇝ U} {M} (fun f) = fun (λ Φ {N} V → subst (λ X → Val (app X N)) (sym (weaken*-++ Φ Δ _ M)) (f (Φ ++ Δ) V))\nvweaken* Δ {T ⇝ U} (redn M⇒N V) = redn (rweaken* Δ M⇒N) (vweaken* Δ V)\n\nvweakens* : ∀ {Γ Δ} E {σ : Substn (exp var) Γ Δ} → Vals σ → Vals (weakens* E σ)\nvweakens* E {σ} Vs x = vweaken* E (Vs x)\n\n-- Evaluation\n\neval : ∀ {Γ Δ T} (M : Exp Γ T) → {σ : Substn (exp var) Δ Γ} → \n Vals σ → Val (substn* σ M)\neval (const {T} c) Vs = reflect (atom (const c))\neval {Γ} {Δ} (var x) {σ} Vs =\n subst Val (begin\n σ x\n ≡⟨ sym (weaken*-[] (σ x)) ⟩\n weaken* [] (σ x)\n ≡⟨ cong (xsubstn+ [] Δ Γ σ) (sym (case-≫ [] x)) ⟩\n substn* σ (var x)\n ∎) (Vs x)\neval {Γ} {Δ} (abs T M) {σ} Vs = \n fun (λ E {N} V → \n vredn (beta {E ++ Δ} (weaken+ [ T ] E Δ (substn+ [ T ] Δ Γ σ M)) N) \n (subst Val \n (substn*-◁ Γ Δ E M N σ) \n (eval M (V ◂ vweakens* E {σ} Vs))))\neval (app M N) Vs = vapp (eval M Vs) (eval N Vs)\n\nvid : ∀ Γ → Vals (id Γ)\nvid Γ x = reflect (atom (var x))\n\nnormalize : ∀ {Γ T} → (M : Exp Γ T) → (M ⇓)\nnormalize {Γ} M = reify (subst Val (substn*-id M) (eval M (vid Γ)))\n\nnormal : ∀ {Γ T} → Exp Γ T → Exp Γ T\nnormal M = tgt (normalize M)\n", "meta": {"hexsha": "4350e0f776976a3839e95218c6fb4b6494b08d6e", "size": 4687, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/AssocFree/STLambdaC/Eval.agda", "max_stars_repo_name": "agda/agda-assoc-free", "max_stars_repo_head_hexsha": "08337fdb8375137a52cc9b3ade766305191b2394", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-11-22T11:48:31.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-27T20:56:20.000Z", "max_issues_repo_path": "src/AssocFree/STLambdaC/Eval.agda", "max_issues_repo_name": "agda/agda-assoc-free", "max_issues_repo_head_hexsha": "08337fdb8375137a52cc9b3ade766305191b2394", "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/AssocFree/STLambdaC/Eval.agda", "max_forks_repo_name": "agda/agda-assoc-free", "max_forks_repo_head_hexsha": "08337fdb8375137a52cc9b3ade766305191b2394", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-03-03T04:39:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:38:44.000Z", "avg_line_length": 36.6171875, "max_line_length": 125, "alphanum_fraction": 0.5299765308, "num_tokens": 2119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.39009851122036704}} {"text": "open import Data.Product using ( proj₁ ; proj₂ )\nopen import Data.Sum using ( inj₁ ; inj₂ )\nopen import Relation.Binary.PropositionalEquality using\n ( _≡_ ; refl ; sym ; cong )\nopen import Relation.Unary using ( _⊆_ )\nopen import Web.Semantic.DL.ABox using ( ABox ; ⟨ABox⟩ ; Assertions )\nopen import Web.Semantic.DL.ABox.Interp using ( ⌊_⌋ ; ind )\nopen import Web.Semantic.DL.ABox.Model using ( _⊨a_ ; bnodes ; _,_ )\nopen import Web.Semantic.DL.Category.Object using ( Object ; IN ; fin ; iface )\nopen import Web.Semantic.DL.Category.Morphism using ( impl ; _≣_ ; _⊑_ ; _,_ )\nopen import Web.Semantic.DL.Category.Tensor using ( _⊗_ ; _⟨⊗⟩_ )\nopen import Web.Semantic.DL.Category.Properties.Tensor.Lemmas using\n ( tensor-up ; tensor-down ; tensor-resp-⊨a )\nopen import Web.Semantic.DL.Category.Wiring using\n ( wiring ; wires-≈ ; wires-≈⁻¹ ; identity ; id✓ )\nopen import Web.Semantic.DL.Signature using ( Signature )\nopen import Web.Semantic.DL.TBox using ( TBox )\nopen import Web.Semantic.DL.TBox.Interp using\n ( Δ ; _⊨_≈_ ; ≈-refl ; ≈-refl′ ; ≈-trans )\nopen import Web.Semantic.Util using\n ( id ; _∘_ ; False ; elim ; inj⁻¹ ; _⊕_⊕_ ; inode ; bnode ; enode )\n\nmodule Web.Semantic.DL.Category.Properties.Tensor.RespectsWiring\n {Σ : Signature} {S T : TBox Σ} where\n \ntensor-resp-wiring : ∀ (A₁ A₂ B₁ B₂ : Object S T) →\n (f₁ : IN B₁ → IN A₁) → \n (f₁✓ : Assertions (⟨ABox⟩ f₁ (iface B₁)) ⊆ Assertions (iface A₁)) → \n (f₂ : IN B₂ → IN A₂) →\n (f₂✓ : Assertions (⟨ABox⟩ f₂ (iface B₂)) ⊆ Assertions (iface A₂)) → \n (g : IN (B₁ ⊗ B₂) → IN (A₁ ⊗ A₂)) →\n (g✓ : Assertions (⟨ABox⟩ g (iface (B₁ ⊗ B₂))) ⊆ Assertions (iface (A₁ ⊗ A₂))) → \n (∀ x → inj₁ (f₁ x) ≡ g (inj₁ x)) → \n (∀ x → inj₂ (f₂ x) ≡ g (inj₂ x)) → \n ((wiring A₁ B₁ f₁ f₁✓ ⟨⊗⟩ wiring A₂ B₂ f₂ f₂✓) ≣ \n (wiring (A₁ ⊗ A₂) (B₁ ⊗ B₂) g g✓))\ntensor-resp-wiring A₁ A₂ B₁ B₂ f₁ f₁✓ f₂ f₂✓ g g✓ f₁≡g₁ f₂≡g₂ = \n (LHS⊑RHS , RHS⊑LHS) where\n\n LHS⊑RHS : \n wiring A₁ B₁ f₁ f₁✓ ⟨⊗⟩ wiring A₂ B₂ f₂ f₂✓ ⊑ \n wiring (A₁ ⊗ A₂) (B₁ ⊗ B₂) g g✓\n LHS⊑RHS I I⊨STA I⊨F = (elim , I⊨RHS) where\n\n lemma : ∀ x → ⌊ I ⌋ ⊨ ind I (inode (g x)) ≈ ind I (enode x)\n lemma (inj₁ x) = ≈-trans ⌊ I ⌋ \n (≈-refl′ ⌊ I ⌋ (cong (ind I ∘ inode) (sym (f₁≡g₁ x))))\n (wires-≈ f₁ (proj₂ (fin B₁) x) \n (tensor-up (wiring A₁ B₁ f₁ f₁✓) (wiring A₂ B₂ f₂ f₂✓) I I⊨F))\n lemma (inj₂ x) = ≈-trans ⌊ I ⌋ \n (≈-refl′ ⌊ I ⌋ (cong (ind I ∘ inode) (sym (f₂≡g₂ x)))) \n (wires-≈ f₂ (proj₂ (fin B₂) x) \n (tensor-down (wiring A₁ B₁ f₁ f₁✓) (wiring A₂ B₂ f₂ f₂✓) I I⊨F))\n\n I⊨RHS : bnodes I elim ⊨a impl (wiring (A₁ ⊗ A₂) (B₁ ⊗ B₂) g g✓)\n I⊨RHS = wires-≈⁻¹ g lemma (proj₁ (fin (B₁ ⊗ B₂)))\n\n RHS⊑LHS : \n wiring (A₁ ⊗ A₂) (B₁ ⊗ B₂) g g✓ ⊑\n wiring A₁ B₁ f₁ f₁✓ ⟨⊗⟩ wiring A₂ B₂ f₂ f₂✓\n RHS⊑LHS I I⊨STA I⊨F = (elim ∘ inj⁻¹ , I⊨LHS) where\n\n lemma₁ : ∀ x → ⌊ I ⌋ ⊨ ind I (inode (inj₁ (f₁ x))) ≈ ind I (enode (inj₁ x))\n lemma₁ x = ≈-trans ⌊ I ⌋ \n (≈-refl′ ⌊ I ⌋ (cong (ind I ∘ inode) (f₁≡g₁ x))) \n (wires-≈ g (proj₂ (fin (B₁ ⊗ B₂)) (inj₁ x)) I⊨F)\n\n lemma₂ : ∀ x → ⌊ I ⌋ ⊨ ind I (inode (inj₂ (f₂ x))) ≈ ind I (enode (inj₂ x))\n lemma₂ x = ≈-trans ⌊ I ⌋ \n (≈-refl′ ⌊ I ⌋ (cong (ind I ∘ inode) (f₂≡g₂ x))) \n (wires-≈ g (proj₂ (fin (B₁ ⊗ B₂)) (inj₂ x)) I⊨F)\n\n I⊨LHS : bnodes I (elim ∘ inj⁻¹) ⊨a impl (wiring A₁ B₁ f₁ f₁✓ ⟨⊗⟩ wiring A₂ B₂ f₂ f₂✓)\n I⊨LHS = tensor-resp-⊨a (wiring A₁ B₁ f₁ f₁✓) (wiring A₂ B₂ f₂ f₂✓) (bnodes I (elim ∘ inj⁻¹)) \n (wires-≈⁻¹ f₁ lemma₁ (proj₁ (fin B₁))) (wires-≈⁻¹ f₂ lemma₂ (proj₁ (fin B₂))) \n", "meta": {"hexsha": "b04bc840873ec9bc65772a38243d9aff2dd3b8b4", "size": 3538, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Web/Semantic/DL/Category/Properties/Tensor/RespectsWiring.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/Category/Properties/Tensor/RespectsWiring.agda", "max_issues_repo_name": "bblfish/agda-web-semantic", "max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "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/Category/Properties/Tensor/RespectsWiring.agda", "max_forks_repo_name": "bblfish/agda-web-semantic", "max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "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": 46.5526315789, "max_line_length": 97, "alphanum_fraction": 0.5715093273, "num_tokens": 1716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943805178139, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.39009850467721296}} {"text": "module Pi-.Category where\nopen import Relation.Binary.PropositionalEquality\nopen import Categories.Category.Monoidal\nopen import Categories.Category.Monoidal.Braided\nopen import Categories.Category.Monoidal.Symmetric\nopen import Categories.Category.Monoidal.Rigid\nopen import Categories.Category.Monoidal.CompactClosed\nopen import Categories.Functor.Bifunctor\nopen import Categories.Category\nopen import Categories.Category.Inverse\nopen import Categories.Category.Product\nopen import Data.Product\nopen import Data.Sum\nopen import Data.Empty\nopen import Relation.Nullary\nopen import Base\nopen import Pi-.Syntax\nopen import Pi-.Opsem\nopen import Pi-.Eval\nopen import Pi-.NoRepeat\nopen import Pi-.Interp\nopen import Pi-.Properties\nopen import Pi-.Invariants\nopen import Pi-.Examples\n\nPi- : Category _ _ _ \nPi- = record {\n Obj = 𝕌\n ; _⇒_ = _↔_\n ; _≈_ = λ c₁ c₂ → eval c₁ ∼ eval c₂\n ; id = id↔\n ; _∘_ = λ f g → g ⨾ f\n\n ; assoc = assoc\n ; sym-assoc = λ x → sym (assoc x)\n ; identityˡ = identityˡ _\n ; identityʳ = identityʳ _\n ; identity² = λ {(v ⃗) → refl ; (v ⃖) → refl}\n ; equiv = record { refl = λ a → refl\n ; sym = λ f~g a → sym (f~g a)\n ; trans = λ f~g g~h a → trans (f~g a) (g~h a) } \n ; ∘-resp-≈ = ∘-resp-≈\n }\n where\n identityˡ : ∀ {A B} (c : A ↔ B) (v : Val A B) → eval (c ⨾ id↔) v ≡ eval c v\n identityˡ c v rewrite eval≡interp (c ⨾ id↔) v | eval≡interp c v = lem c v\n where\n lem : ∀ {A B} (c : A ↔ B) (v : Val A B) → interp (c ⨾ id↔) v ≡ interp c v\n lem c (x ⃗) with interp c (x ⃗)\n ... | x₁ ⃗ = refl\n ... | x₁ ⃖ = refl\n lem c (x ⃖) with interp c (x ⃖)\n ... | x₁ ⃗ = refl\n ... | x₁ ⃖ = refl\n\n identityʳ : ∀ {A B} (c : A ↔ B) (v : Val A B) → eval (id↔ ⨾ c) v ≡ eval c v\n identityʳ c v rewrite eval≡interp (id↔ ⨾ c) v | eval≡interp c v = lem c v\n where\n lem : ∀ {A B} (c : A ↔ B) (v : Val A B) → interp (id↔ ⨾ c) v ≡ interp c v\n lem c (x ⃗) with interp c (x ⃗)\n ... | x₁ ⃗ = refl\n ... | x₁ ⃖ = refl\n lem c (x ⃖) with interp c (x ⃖)\n ... | x₁ ⃗ = refl\n ... | x₁ ⃖ = refl\n\nPi-Monoidal : Monoidal Pi-\nPi-Monoidal = record {\n ⊗ = record { F₀ = λ {(A , B) → A +ᵤ B}\n ; F₁ = λ {(c₁ , c₂) → c₁ ⊕ c₂ }\n ; identity = λ { (inj₁ v ⃗) → refl\n ; (inj₂ v ⃗) → refl\n ; (inj₁ v ⃖) → refl\n ; (inj₂ v ⃖) → refl}\n ; homomorphism = homomorphism\n ; F-resp-≈ = λ {(A , B)} {(C , D)} {(f , g)} {(f' , g')} (f~f' , g~g')\n → F-resp-≈ f f' g g' f~f' g~g'}\n ; unit = 𝟘\n ; unitorˡ = record { from = unite₊l\n ; to = uniti₊l\n ; iso = record { isoˡ = λ { (inj₂ v ⃗) → refl\n ; (inj₂ v ⃖) → refl}\n ; isoʳ = λ { (v ⃗) → refl\n ; (v ⃖) → refl}}}\n ; unitorʳ = record { from = unite₊r\n ; to = uniti₊r\n ; iso = record { isoˡ = λ { (inj₁ v ⃗) → refl\n ; (inj₁ v ⃖) → refl}\n ; isoʳ = λ { (v ⃗) → refl\n ; (v ⃖) → refl}}}\n ; associator = record { from = assocr₊\n ; to = assocl₊\n ; iso = record { isoˡ = λ { (inj₁ (inj₁ v) ⃗) → refl\n ; (inj₁ (inj₂ v) ⃗) → refl\n ; (inj₂ v ⃗) → refl\n ; (inj₁ (inj₁ v) ⃖) → refl\n ; (inj₁ (inj₂ v) ⃖) → refl\n ; (inj₂ v ⃖) → refl}\n ; isoʳ = λ { (inj₁ v ⃗) → refl\n ; (inj₂ (inj₁ v) ⃗) → refl\n ; (inj₂ (inj₂ v) ⃗) → refl\n ; (inj₁ v ⃖) → refl\n ; (inj₂ (inj₁ v) ⃖) → refl\n ; (inj₂ (inj₂ v) ⃖) → refl}}}\n ; unitorˡ-commute-from = unitorˡ-commute-from _\n ; unitorˡ-commute-to = unitorˡ-commute-to _\n ; unitorʳ-commute-from = unitorʳ-commute-from _\n ; unitorʳ-commute-to = unitorʳ-commute-to _\n ; assoc-commute-from = assoc-commute-from _ _ _\n ; assoc-commute-to = assoc-commute-to _ _ _\n ; triangle = λ { (inj₁ (inj₁ v) ⃗) → refl\n ; (inj₂ v ⃗) → refl\n ; (inj₁ v ⃖) → refl\n ; (inj₂ v ⃖) → refl}\n ; pentagon = λ { (inj₁ (inj₁ (inj₁ v)) ⃗) → refl\n ; (inj₁ (inj₁ (inj₂ v)) ⃗) → refl\n ; (inj₁ (inj₂ v) ⃗) → refl\n ; (inj₂ v ⃗) → refl\n ; (inj₁ v ⃖) → refl\n ; (inj₂ (inj₁ v) ⃖) → refl\n ; (inj₂ (inj₂ (inj₁ v)) ⃖) → refl\n ; (inj₂ (inj₂ (inj₂ v)) ⃖) → refl}\n }\n where\n F-resp-≈ : ∀ {A B C D} (f f' : A ↔ B) (g g' : C ↔ D) → (eval f ∼ eval f') → (eval g ∼ eval g')\n → (eval (f ⊕ g) ∼ eval (f' ⊕ g'))\n F-resp-≈ f f' g g' f~f' g~g' x rewrite eval≡interp (f ⊕ g) x | eval≡interp (f' ⊕ g') x =\n lem f f' g g' (λ x → trans (sym (eval≡interp f x)) (trans (f~f' x) (eval≡interp f' x)))\n (λ x → trans (sym (eval≡interp g x)) (trans (g~g' x) (eval≡interp g' x))) x\n where\n lem : ∀ {A B C D} (f f' : A ↔ B) (g g' : C ↔ D) → (interp f ∼ interp f') → (interp g ∼ interp g')\n → (interp (f ⊕ g) ∼ interp (f' ⊕ g'))\n lem f f' g g' f~f' g~g' (inj₁ x ⃗) with f~f' (x ⃗) | interp f' (x ⃗) | inspect (interp f') (x ⃗)\n ... | eq | x' ⃗ | [ eq' ] rewrite eq | eq' = refl\n ... | eq | x' ⃖ | [ eq' ] rewrite eq | eq' = refl\n lem f f' g g' f~f' g~g' (inj₂ y ⃗) with g~g' (y ⃗) | interp g' (y ⃗) | inspect (interp g') (y ⃗)\n ... | eq | y' ⃗ | [ eq' ] rewrite eq | eq' = refl\n ... | eq | y' ⃖ | [ eq' ] rewrite eq | eq' = refl\n lem f f' g g' f~f' g~g' (inj₁ x ⃖) with f~f' (x ⃖) | interp f' (x ⃖) | inspect (interp f') (x ⃖)\n ... | eq | x' ⃗ | [ eq' ] rewrite eq | eq' = refl\n ... | eq | x' ⃖ | [ eq' ] rewrite eq | eq' = refl\n lem f f' g g' f~f' g~g' (inj₂ y ⃖) with g~g' (y ⃖) | interp g' (y ⃖) | inspect (interp g') (y ⃖)\n ... | eq | y' ⃗ | [ eq' ] rewrite eq | eq' = refl\n ... | eq | y' ⃖ | [ eq' ] rewrite eq | eq' = refl\n \n unitorˡ-commute-from : ∀ {A B} (f : A ↔ B) (x : _) → eval ((id↔ ⊕ f) ⨾ unite₊l) x ≡ eval (unite₊l ⨾ f) x\n unitorˡ-commute-from f x rewrite eval≡interp ((id↔ ⊕ f) ⨾ unite₊l) x | eval≡interp (unite₊l ⨾ f) x = lem f x\n where\n lem : ∀ {A B} (f : A ↔ B) (x : _) → interp ((id↔ ⊕ f) ⨾ unite₊l) x ≡ interp (unite₊l ⨾ f) x\n lem f (inj₂ y ⃗) with interp f (y ⃗)\n ... | x ⃗ = refl\n ... | x ⃖ = refl\n lem f (x ⃖) with interp f (x ⃖)\n ... | x₁ ⃗ = refl\n ... | x₁ ⃖ = refl\n\n unitorˡ-commute-to : ∀ {A B} (f : A ↔ B) (x : _) → eval (f ⨾ uniti₊l) x ≡ eval (uniti₊l ⨾ (id↔ ⊕ f)) x\n unitorˡ-commute-to f x rewrite eval≡interp (f ⨾ uniti₊l) x | eval≡interp (uniti₊l ⨾ (id↔ ⊕ f)) x = lem f x\n where\n lem : ∀ {A B} (f : A ↔ B) (x : _) → interp (f ⨾ uniti₊l) x ≡ interp (uniti₊l ⨾ (id↔ ⊕ f)) x\n lem f (x ⃗) with interp f (x ⃗)\n ... | x₁ ⃗ = refl\n ... | x₁ ⃖ = refl\n lem f (inj₂ y ⃖) with interp f (y ⃖)\n ... | x ⃗ = refl\n ... | x ⃖ = refl\n\n unitorʳ-commute-from : ∀ {A B} (f : A ↔ B) (x : _) → eval ((f ⊕ id↔) ⨾ swap₊ ⨾ unite₊l) x ≡ eval ((swap₊ ⨾ unite₊l) ⨾ f) x\n unitorʳ-commute-from f x rewrite eval≡interp ((f ⊕ id↔) ⨾ swap₊ ⨾ unite₊l) x | eval≡interp ((swap₊ ⨾ unite₊l) ⨾ f) x = lem f x\n where\n lem : ∀ {A B} (f : A ↔ B) (x : _) → interp ((f ⊕ id↔) ⨾ swap₊ ⨾ unite₊l) x ≡ interp ((swap₊ ⨾ unite₊l) ⨾ f) x\n lem f (inj₁ x ⃗) with interp f (x ⃗)\n ... | x₁ ⃗ = refl\n ... | x₁ ⃖ = refl\n lem f (x ⃖) with interp f (x ⃖)\n ... | x₁ ⃗ = refl\n ... | x₁ ⃖ = refl\n \n unitorʳ-commute-to : ∀ {A B} (f : A ↔ B) (x : _) → eval (f ⨾ uniti₊l ⨾ swap₊) x ≡ eval ((uniti₊l ⨾ swap₊) ⨾ (f ⊕ id↔)) x\n unitorʳ-commute-to f x rewrite eval≡interp (f ⨾ uniti₊l ⨾ swap₊) x | eval≡interp ((uniti₊l ⨾ swap₊) ⨾ (f ⊕ id↔)) x = lem f x\n where\n lem : ∀ {A B} (f : A ↔ B) (x : _) → interp (f ⨾ uniti₊l ⨾ swap₊) x ≡ interp ((uniti₊l ⨾ swap₊) ⨾ (f ⊕ id↔)) x\n lem f (x ⃗) with interp f (x ⃗)\n ... | x₁ ⃗ = refl\n ... | x₁ ⃖ = refl\n lem f (inj₁ x ⃖) with interp f (x ⃖)\n ... | x₁ ⃗ = refl\n ... | x₁ ⃖ = refl\n \n assoc-commute-from : ∀ {A B C D E F} (f : A ↔ B) (g : C ↔ D) (h : E ↔ F) (x : _) → eval (((f ⊕ g) ⊕ h) ⨾ assocr₊) x ≡ eval (assocr₊ ⨾ (f ⊕ (g ⊕ h))) x\n assoc-commute-from f g h x rewrite eval≡interp (((f ⊕ g) ⊕ h) ⨾ assocr₊) x | eval≡interp (assocr₊ ⨾ (f ⊕ (g ⊕ h))) x = lem f g h x\n where\n lem : ∀ {A B C D E F} (f : A ↔ B) (g : C ↔ D) (h : E ↔ F) (x : _) → interp (((f ⊕ g) ⊕ h) ⨾ assocr₊) x ≡ interp (assocr₊ ⨾ (f ⊕ (g ⊕ h))) x\n lem f g h (inj₁ (inj₁ x) ⃗) with interp f (x ⃗)\n ... | x' ⃗ = refl\n ... | x' ⃖ = refl\n lem f g h (inj₁ (inj₂ y) ⃗) with interp g (y ⃗)\n ... | y' ⃗ = refl\n ... | y' ⃖ = refl\n lem f g h (inj₂ z ⃗) with interp h (z ⃗)\n ... | z' ⃗ = refl\n ... | z' ⃖ = refl\n lem f g h (inj₁ x ⃖) with interp f (x ⃖)\n ... | x' ⃗ = refl\n ... | x' ⃖ = refl\n lem f g h (inj₂ (inj₁ y) ⃖) with interp g (y ⃖)\n ... | y' ⃗ = refl\n ... | y' ⃖ = refl\n lem f g h (inj₂ (inj₂ z) ⃖) with interp h (z ⃖)\n ... | z' ⃗ = refl\n ... | z' ⃖ = refl\n \n assoc-commute-to : ∀ {A B C D E F} (f : A ↔ B) (g : C ↔ D) (h : E ↔ F) (x : _) → eval ((f ⊕ (g ⊕ h)) ⨾ assocl₊) x ≡ eval (assocl₊ ⨾ ((f ⊕ g) ⊕ h)) x\n assoc-commute-to f g h x rewrite eval≡interp ((f ⊕ (g ⊕ h)) ⨾ assocl₊) x | eval≡interp (assocl₊ ⨾ ((f ⊕ g) ⊕ h)) x = lem f g h x\n where\n lem : ∀ {A B C D E F} (f : A ↔ B) (g : C ↔ D) (h : E ↔ F) (x : _) → interp ((f ⊕ (g ⊕ h)) ⨾ assocl₊) x ≡ interp (assocl₊ ⨾ ((f ⊕ g) ⊕ h)) x\n lem f g h (inj₁ x ⃗) with interp f (x ⃗)\n ... | x' ⃗ = refl\n ... | x' ⃖ = refl\n lem f g h (inj₂ (inj₁ y) ⃗) with interp g (y ⃗)\n ... | y' ⃗ = refl\n ... | y' ⃖ = refl\n lem f g h (inj₂ (inj₂ z) ⃗) with interp h (z ⃗)\n ... | z' ⃗ = refl\n ... | z' ⃖ = refl\n lem f g h (inj₁ (inj₁ x) ⃖) with interp f (x ⃖)\n ... | x' ⃗ = refl\n ... | x' ⃖ = refl\n lem f g h (inj₁ (inj₂ y) ⃖) with interp g (y ⃖)\n ... | y' ⃗ = refl\n ... | y' ⃖ = refl\n lem f g h (inj₂ z ⃖) with interp h (z ⃖)\n ... | z' ⃗ = refl\n ... | z' ⃖ = refl\n \nPi-Braided : Braided Pi-Monoidal\nPi-Braided = record { braiding = record { F⇒G = record { η = λ _ → swap₊\n ; commute = λ {(f , g) x → commute f g x}\n ; sym-commute = λ {(f , g) x → sym (commute f g x)}}\n ; F⇐G = record { η = λ _ → swap₊\n ; commute = λ { (f , g) x → commute g f x}\n ; sym-commute = λ {(f , g) x → sym (commute g f x)}}\n ; iso = λ _ → record { isoˡ = λ { (inj₁ v ⃗) → refl\n ; (inj₂ v ⃗) → refl\n ; (inj₁ v ⃖) → refl\n ; (inj₂ v ⃖) → refl}\n ; isoʳ = λ { (inj₁ v ⃗) → refl\n ; (inj₂ v ⃗) → refl\n ; (inj₁ v ⃖) → refl\n ; (inj₂ v ⃖) → refl} } }\n ; hexagon₁ = λ { (inj₁ (inj₁ v) ⃗) → refl\n ; (inj₁ (inj₂ v) ⃗) → refl\n ; (inj₂ v ⃗) → refl\n ; (inj₁ v ⃖) → refl\n ; (inj₂ (inj₁ v) ⃖) → refl\n ; (inj₂ (inj₂ v) ⃖) → refl}\n ; hexagon₂ = λ { (inj₁ (inj₁ v) ⃖) → refl\n ; (inj₁ (inj₂ v) ⃖) → refl\n ; (inj₂ v ⃖) → refl\n ; (inj₁ v ⃗) → refl\n ; (inj₂ (inj₁ v) ⃗) → refl\n ; (inj₂ (inj₂ v) ⃗) → refl}}\n where\n commute : ∀ {A B C D} (f : A ↔ C) (g : B ↔ D) (x : _)\n → eval ((f ⊕ g) ⨾ swap₊) x ≡ eval (swap₊ ⨾ (g ⊕ f)) x\n commute f g x rewrite eval≡interp ((f ⊕ g) ⨾ swap₊) x | eval≡interp (swap₊ ⨾ (g ⊕ f)) x = lem f g x\n where\n lem : ∀ {A B C D} (f : A ↔ C) (g : B ↔ D) (x : _)\n → interp ((f ⊕ g) ⨾ swap₊) x ≡ interp (swap₊ ⨾ (g ⊕ f)) x\n lem f g (inj₁ x ⃗) with interp f (x ⃗)\n ... | _ ⃗ = refl\n ... | _ ⃖ = refl\n lem f g (inj₂ y ⃗) with interp g (y ⃗)\n ... | _ ⃗ = refl\n ... | _ ⃖ = refl\n lem f g (inj₁ y ⃖) with interp g (y ⃖)\n ... | _ ⃗ = refl\n ... | _ ⃖ = refl\n lem f g (inj₂ x ⃖) with interp f (x ⃖)\n ... | _ ⃗ = refl\n ... | _ ⃖ = refl\n\nPi-Symmetric : Symmetric Pi-Monoidal\nPi-Symmetric = record { braided = Pi-Braided\n ; commutative = λ { (inj₁ v ⃗) → refl\n ; (inj₂ v ⃗) → refl\n ; (inj₁ v ⃖) → refl\n ; (inj₂ v ⃖) → refl}}\n\nPi-Rigid : LeftRigid Pi-Monoidal\nPi-Rigid = record { _⁻¹ = -_\n ; η = η₊\n ; ε = swap₊ ⨾ ε₊\n ; snake₁ = λ { (v ⃗) → refl\n ; (v ⃖) → refl}\n ; snake₂ = λ { ((- v) ⃗) → refl\n ; ((- v) ⃖) → refl}}\n\nPi-CompactClosed : CompactClosed Pi-Monoidal\nPi-CompactClosed = record { symmetric = Pi-Symmetric\n ; rigid = inj₁ Pi-Rigid}\n\n¬Pi-Inverse : ¬(Inverse Pi-)\n¬Pi-Inverse record { _⁻¹ = _⁻¹ } with (ε₊ {𝟙} ⊕ id↔ {𝟙}) ⁻¹\n... | c , (_ , _) , uniq = contr\n where\n c₁ c₂ : 𝟘 +ᵤ 𝟙 ↔ (𝟙 +ᵤ - 𝟙) +ᵤ 𝟙\n c₁ = η₊ ⊕ id↔\n c₂ = (η₊ ⊕ id↔) ⨾ swap₊ ⨾ (id↔ ⊕ swap₊) ⨾ assocl₊\n \n c₁pinv : (eval (((ε₊ {𝟙} ⊕ id↔) ⨾ c₁) ⨾ (ε₊ ⊕ id↔)) ∼ eval (ε₊ ⊕ id↔))\n × (eval ((c₁ ⨾ (ε₊ ⊕ id↔)) ⨾ c₁) ∼ eval c₁)\n c₁pinv = p₁ , p₂\n where\n p₁ : eval (((ε₊ {𝟙} ⊕ id↔) ⨾ c₁) ⨾ (ε₊ ⊕ id↔)) ∼ eval (ε₊ ⊕ id↔)\n p₁ (inj₁ (inj₁ tt) ⃗) = refl\n p₁ (inj₁ (inj₂ (- tt)) ⃗) = refl\n p₁ (inj₂ tt ⃗) = refl\n p₁ (inj₂ tt ⃖) = refl\n\n p₂ : eval ((c₁ ⨾ (ε₊ ⊕ id↔)) ⨾ c₁) ∼ eval c₁\n p₂ (inj₂ tt ⃗) = refl\n p₂ (inj₁ (inj₁ tt) ⃖) = refl\n p₂ (inj₁ (inj₂ (- tt)) ⃖) = refl\n p₂ (inj₂ tt ⃖) = refl\n\n c₂pinv : (eval (((ε₊ {𝟙} ⊕ id↔) ⨾ c₂) ⨾ (ε₊ ⊕ id↔)) ∼ eval (ε₊ ⊕ id↔))\n × (eval ((c₂ ⨾ (ε₊ ⊕ id↔)) ⨾ c₂) ∼ eval c₂)\n c₂pinv = p₁ , p₂\n where\n p₁ : eval (((ε₊ {𝟙} ⊕ id↔) ⨾ c₂) ⨾ (ε₊ ⊕ id↔)) ∼ eval (ε₊ ⊕ id↔)\n p₁ (inj₁ (inj₁ tt) ⃗) = refl\n p₁ (inj₁ (inj₂ (- tt)) ⃗) = refl\n p₁ (inj₂ tt ⃗) = refl\n p₁ (inj₂ tt ⃖) = refl\n\n p₂ : eval ((c₂ ⨾ (ε₊ ⊕ id↔)) ⨾ c₂) ∼ eval c₂\n p₂ (inj₂ tt ⃗) = refl\n p₂ (inj₁ (inj₁ tt) ⃖) = refl\n p₂ (inj₁ (inj₂ (- tt)) ⃖) = refl\n p₂ (inj₂ tt ⃖) = refl\n\n c∼c₁ : eval c ∼ eval c₁\n c∼c₁ = uniq c₁pinv\n\n c∼c₂ : eval c ∼ eval c₂\n c∼c₂ = uniq c₂pinv\n\n contr : ⊥\n contr with trans (sym (c∼c₁ (inj₂ _ ⃗))) (c∼c₂ (inj₂ _ ⃗))\n ... | ()\n\nIHom : ∀ {A B C} → C ↔ (- A +ᵤ B) → (C +ᵤ A) ↔ B\nIHom f = (f ⊕ id↔) ⨾ [A+B]+C=[A+C]+B ⨾ (swap₊ ⊕ id↔) ⨾ (ε₊ ⊕ id↔) ⨾ unite₊l\n\nIHom' : ∀ {A B C} → C +ᵤ A ↔ B → C ↔ - A +ᵤ B\nIHom' f = uniti₊l ⨾ (η₊ ⊕ id↔) ⨾ (swap₊ ⊕ id↔) ⨾ (assocr₊ ⨾ id↔ ⊕ swap₊) ⨾ id↔ ⊕ f\n\nIHom'∘IHom : ∀ {A B C} → (f : C ↔ (- A +ᵤ B)) → interp f ∼ interp (IHom' (IHom f))\nIHom'∘IHom f (c ⃗) with interp f (c ⃗)\nIHom'∘IHom f (c ⃗) | inj₁ (- a) ⃗ = refl\nIHom'∘IHom f (c ⃗) | inj₂ b ⃗ = refl\nIHom'∘IHom f (c ⃗) | (c' ⃖) = refl\nIHom'∘IHom f (inj₁ (- a) ⃖) with interp f (inj₁ (- a) ⃖)\nIHom'∘IHom f (inj₁ (- a) ⃖) | inj₁ (- a') ⃗ = refl\nIHom'∘IHom f (inj₁ (- a) ⃖) | inj₂ b ⃗ = refl\nIHom'∘IHom f (inj₁ (- a) ⃖) | c ⃖ = refl\nIHom'∘IHom f (inj₂ b ⃖) with interp f (inj₂ b ⃖)\nIHom'∘IHom f (inj₂ b ⃖) | inj₁ (- a) ⃗ = refl\nIHom'∘IHom f (inj₂ b ⃖) | inj₂ b' ⃗ = refl\nIHom'∘IHom f (inj₂ b ⃖) | c ⃖ = refl\n\nIHom∘IHom' : ∀ {A B C} → (f : (C +ᵤ A) ↔ B) → interp f ∼ interp (IHom (IHom' f))\nIHom∘IHom' f (inj₁ c ⃗) with interp f (inj₁ c ⃗)\nIHom∘IHom' f (inj₁ c ⃗) | b ⃗ = refl\nIHom∘IHom' f (inj₁ c ⃗) | inj₁ c' ⃖ = refl\nIHom∘IHom' f (inj₁ c ⃗) | inj₂ a ⃖ = refl\nIHom∘IHom' f (inj₂ a ⃗) with interp f (inj₂ a ⃗)\nIHom∘IHom' f (inj₂ a ⃗) | b ⃗ = refl\nIHom∘IHom' f (inj₂ a ⃗) | inj₁ c ⃖ = refl\nIHom∘IHom' f (inj₂ a ⃗) | inj₂ a' ⃖ = refl\nIHom∘IHom' f (b ⃖) with interp f (b ⃖)\nIHom∘IHom' f (b ⃖) | b' ⃗ = refl\nIHom∘IHom' f (b ⃖) | inj₁ c ⃖ = refl\nIHom∘IHom' f (b ⃖) | inj₂ a ⃖ = refl\n\nEv : ∀ {A B} → (- A +ᵤ B) +ᵤ A ↔ B\nEv = [A+B]+C=[A+C]+B ⨾ ((swap₊ ⨾ ε₊) ⊕ id↔) ⨾ unite₊l\n\nhof : ∀ {A B} → (𝟘 ↔ (- A +ᵤ B)) → (A ↔ B)\nhof f = uniti₊l ⨾ (f ⊕ id↔) ⨾ [A+B]+C=[A+C]+B ⨾ (swap₊ ⨾ ε₊) ⊕ id↔ ⨾ unite₊l\n\nhof' : ∀ {A B} → (A ↔ B) → (𝟘 ↔ (- A +ᵤ B))\nhof' f = η₊ ⨾ (f ⊕ id↔) ⨾ swap₊\n\nhof'∘hof : ∀ {A B} → (f : 𝟘 ↔ (- A +ᵤ B)) → interp f ∼ interp (hof' (hof f))\nhof'∘hof f (inj₁ (- a) ⃖) with interp f (inj₁ (- a) ⃖)\nhof'∘hof f (inj₁ (- a) ⃖) | inj₁ (- a') ⃗ = refl\nhof'∘hof f (inj₁ (- a) ⃖) | inj₂ b ⃗ = refl\nhof'∘hof f (inj₂ b ⃖) with interp f (inj₂ b ⃖)\nhof'∘hof f (inj₂ b ⃖) | inj₁ (- a) ⃗ = refl\nhof'∘hof f (inj₂ b ⃖) | inj₂ b' ⃗ = refl\n\nhof∘hof' : ∀ {A B} → (f : A ↔ B) → interp f ∼ interp (hof (hof' f))\nhof∘hof' f (a ⃗) with interp f (a ⃗)\nhof∘hof' f (a ⃗) | b ⃗ = refl\nhof∘hof' f (a ⃗) | a' ⃖ = refl\nhof∘hof' f (b ⃖) with interp f (b ⃖)\nhof∘hof' f (b ⃖) | b' ⃗ = refl\nhof∘hof' f (b ⃖) | a ⃖ = refl\n", "meta": {"hexsha": "2c41c4fbf624b192cf69583c34ed6de2b4ca1b42", "size": 18525, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Pi-/Category.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "Pi-/Category.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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": "Pi-/Category.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 45.0729927007, "max_line_length": 152, "alphanum_fraction": 0.3881241565, "num_tokens": 8057, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.389741349914944}} {"text": "\n{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.DStructures.Equivalences.PeifferGraphS2G where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Structure\n\nopen import Cubical.Functions.FunExtEquiv\n\nopen import Cubical.Homotopy.Base\n\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Unit\n\nopen import Cubical.Relation.Binary\n\n\nopen import Cubical.Structures.Subtype\nopen import Cubical.Algebra.Group\nopen import Cubical.Structures.LeftAction\nopen import Cubical.Algebra.Group.Semidirect\n\nopen import Cubical.DStructures.Base\nopen import Cubical.DStructures.Meta.Properties\n\nopen import Cubical.DStructures.Meta.Isomorphism\nopen import Cubical.DStructures.Structures.Constant\nopen import Cubical.DStructures.Structures.Type\nopen import Cubical.DStructures.Structures.Group\nopen import Cubical.DStructures.Structures.Action\nopen import Cubical.DStructures.Structures.XModule\nopen import Cubical.DStructures.Structures.ReflGraph\nopen import Cubical.DStructures.Structures.VertComp\nopen import Cubical.DStructures.Structures.PeifferGraph\nopen import Cubical.DStructures.Structures.Strict2Group\nopen import Cubical.DStructures.Equivalences.GroupSplitEpiAction\nopen import Cubical.DStructures.Equivalences.PreXModReflGraph\n\n\nprivate\n variable\n ℓ ℓ' ℓ'' ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓA ℓA' ℓ≅A ℓ≅A' ℓB ℓB' ℓ≅B ℓC ℓ≅C ℓ≅ᴰ ℓ≅ᴰ' ℓ≅B' : Level\n\nopen Kernel\nopen GroupHom -- such .fun!\nopen GroupLemmas\nopen MorphismLemmas\nopen ActionLemmas\n\nmodule _ (ℓ ℓ' : Level) where\n ℓℓ' = ℓ-max ℓ ℓ'\n\n 𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group : 𝒮ᴰ-♭PIso (idfun (ReflGraph ℓ ℓℓ')) (𝒮ᴰ-ReflGraph\\Peiffer ℓ ℓℓ') (𝒮ᴰ-Strict2Group ℓ ℓℓ')\n\n RelIso.fun (𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group 𝒢) isPeifferGraph = 𝒱\n where\n open ReflGraphNotation 𝒢\n open ReflGraphLemmas 𝒢\n open VertComp\n _⊙_ = λ (g f : ⟨ G₁ ⟩) → (g -₁ (𝒾s g)) +₁ f\n\n 𝒱 : VertComp 𝒢\n vcomp 𝒱 g f _ = g ⊙ f\n σ-∘ 𝒱 g f c = r\n where\n isg = 𝒾s g\n abstract\n r = s ((g -₁ isg) +₁ f)\n ≡⟨ (σ .isHom (g -₁ isg) f) ⟩\n s (g -₁ isg) +₀ s f\n ≡⟨ cong (_+₀ s f) (σ-g--isg g) ⟩\n 0₀ +₀ s f\n ≡⟨ lId₀ (s f) ⟩\n s f ∎\n τ-∘ 𝒱 g f c = r\n where\n isg = 𝒾s g\n -isg = -₁ (𝒾s g)\n abstract\n r = t ((g -₁ isg) +₁ f)\n ≡⟨ τ .isHom (g -₁ isg) f ⟩\n t (g -₁ isg) +₀ t f\n ≡⟨ cong (_+₀ t f)\n (τ .isHom g (-₁ isg)) ⟩\n (t g +₀ t -isg) +₀ t f\n ≡⟨ cong ((t g +₀ t -isg) +₀_)\n (sym c) ⟩\n (t g +₀ t -isg) +₀ s g\n ≡⟨ cong (λ z → (t g +₀ z) +₀ s g)\n (mapInv τ isg) ⟩\n (t g -₀ (t isg)) +₀ s g\n ≡⟨ cong (λ z → (t g -₀ z) +₀ s g)\n (τι-≡-fun (s g)) ⟩\n (t g -₀ (s g)) +₀ s g\n ≡⟨ (sym (assoc₀ (t g) (-₀ s g) (s g))) ∙ (cong (t g +₀_) (lCancel₀ (s g))) ⟩\n t g +₀ 0₀\n ≡⟨ rId₀ (t g) ⟩\n t g ∎\n isHom-∘ 𝒱 g f c-gf g' f' _ _ = r\n where\n isg = 𝒾s g\n -isg = -₁ (𝒾s g)\n isg' = 𝒾s g'\n -isg' = -₁ (𝒾s g')\n itf = 𝒾t f\n -itf = -₁ (𝒾t f)\n abstract\n r = (g +₁ g') ⊙ (f +₁ f')\n ≡⟨ assoc₁ ((g +₁ g') -₁ 𝒾s (g +₁ g')) f f' ⟩\n (((g +₁ g') -₁ 𝒾s (g +₁ g')) +₁ f) +₁ f'\n ≡⟨ cong (λ z → (z +₁ f) +₁ f')\n (sym (assoc₁ g g' (-₁ (𝒾s (g +₁ g'))))) ⟩\n ((g +₁ (g' -₁ (𝒾s (g +₁ g')))) +₁ f) +₁ f'\n ≡⟨ cong (_+₁ f')\n (sym (assoc₁ g (g' -₁ (𝒾s (g +₁ g'))) f)) ⟩\n (g +₁ ((g' -₁ (𝒾s (g +₁ g'))) +₁ f)) +₁ f'\n ≡⟨ cong (λ z → (g +₁ z) +₁ f')\n ((g' -₁ (𝒾s (g +₁ g'))) +₁ f\n ≡⟨ cong (λ z → (g' -₁ z) +₁ f)\n (ι∘σ .isHom g g') ⟩\n (g' -₁ (isg +₁ isg')) +₁ f\n ≡⟨ cong (λ z → (g' +₁ z) +₁ f)\n (invDistr G₁ isg isg') ⟩\n (g' +₁ (-isg' +₁ -isg)) +₁ f\n ≡⟨ assoc-c--r- G₁ g' -isg' -isg f ⟩\n g' +₁ (-isg' +₁ (-isg +₁ f))\n ≡⟨ cong (λ z → g' +₁ (-isg' +₁ ((-₁ (𝒾 z)) +₁ f)))\n c-gf ⟩\n g' +₁ (-isg' +₁ (-itf +₁ f))\n ≡⟨ isPeifferGraph4 𝒢 isPeifferGraph f g' ⟩\n -itf +₁ (f +₁ (g' +₁ -isg'))\n ≡⟨ cong (λ z → (-₁ (𝒾 z)) +₁ (f +₁ (g' +₁ -isg')))\n (sym c-gf) ⟩\n -isg +₁ (f +₁ (g' +₁ -isg')) ∎) ⟩\n (g +₁ (-isg +₁ (f +₁ (g' +₁ -isg')))) +₁ f'\n ≡⟨ cong (_+₁ f')\n (assoc₁ g -isg (f +₁ (g' -₁ isg'))) ⟩\n ((g +₁ -isg) +₁ (f +₁ (g' +₁ -isg'))) +₁ f'\n ≡⟨ cong (_+₁ f') (assoc₁ (g -₁ isg) f (g' -₁ isg')) ⟩\n (((g -₁ isg) +₁ f) +₁ (g' -₁ isg')) +₁ f'\n ≡⟨ sym (assoc₁ ((g -₁ isg) +₁ f) (g' -₁ isg') f') ⟩\n ((g -₁ isg) +₁ f) +₁ ((g' -₁ isg') +₁ f')\n ≡⟨ refl ⟩\n (g ⊙ f) +₁ (g' ⊙ f') ∎\n -- behold! use of symmetry is lurking around the corner\n -- (in stark contrast to composability proofs)\n assoc-∘ 𝒱 h g f _ _ _ _ = sym r\n where\n isg = 𝒾s g\n ish = 𝒾s h\n -ish = -₁ 𝒾s h\n abstract\n r = (h ⊙ g) ⊙ f\n ≡⟨ cong (λ z → (((h -₁ ish) +₁ g) -₁ z) +₁ f)\n (ι∘σ .isHom (h -₁ ish) g) ⟩\n (((h -₁ ish) +₁ g) -₁ (𝒾s (h -₁ ish) +₁ 𝒾s g)) +₁ f\n ≡⟨ cong (λ z → (((h -₁ ish) +₁ g) -₁ (z +₁ 𝒾s g)) +₁ f)\n (ι∘σ .isHom h (-₁ ish)) ⟩\n (((h -₁ ish) +₁ g) -₁ ((𝒾s h +₁ (𝒾s -ish)) +₁ 𝒾s g)) +₁ f\n ≡⟨ cong (λ z → (((h -₁ ish) +₁ g) -₁ ((𝒾s h +₁ z) +₁ 𝒾s g)) +₁ f)\n (ισ-ι (s h)) ⟩\n (((h -₁ ish) +₁ g) -₁ ((ish -₁ ish) +₁ isg)) +₁ f\n ≡⟨ cong (λ z → (((h -₁ ish) +₁ g) -₁ z) +₁ f)\n (rCancel-lId G₁ ish isg) ⟩\n (((h -₁ ish) +₁ g) -₁ isg) +₁ f\n ≡⟨ (cong (_+₁ f) (sym (assoc₁ (h -₁ ish) g (-₁ isg)))) ∙ (sym (assoc₁ (h -₁ ish) (g -₁ isg) f)) ⟩\n h ⊙ (g ⊙ f) ∎\n lid-∘ 𝒱 f _ = r\n where\n itf = 𝒾t f\n abstract\n r = itf ⊙ f\n ≡⟨ cong (λ z → (itf -₁ (𝒾 z)) +₁ f) (σι-≡-fun (t f)) ⟩\n (itf -₁ itf) +₁ f\n ≡⟨ rCancel-lId G₁ itf f ⟩\n f ∎\n rid-∘ 𝒱 g _ = r\n where\n isg = 𝒾s g\n -isg = -₁ (𝒾s g)\n abstract\n r = g ⊙ isg\n ≡⟨ sym (assoc₁ g -isg isg) ⟩\n g +₁ (-isg +₁ isg)\n ≡⟨ lCancel-rId G₁ g isg ⟩\n g ∎\n\n RelIso.inv (𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group 𝒢) 𝒞 = isPf\n where\n open ReflGraphNotation 𝒢\n open VertComp 𝒞\n\n abstract\n isPf : isPeifferGraph 𝒢\n isPf f g = ((isg +₁ (f -₁ itf)) +₁ (-isg +₁ g)) +₁ itf\n ≡⟨ cong (_+₁ itf)\n (sym (assoc₁ isg (f -₁ itf) (-isg +₁ g))) ⟩\n (isg +₁ ((f -₁ itf) +₁ (-isg +₁ g))) +₁ itf\n ≡⟨ cong (λ z → (isg +₁ z) +₁ itf)\n (sym (assoc₁ f -itf (-isg +₁ g))) ⟩\n (isg +₁ (f +₁ (-itf +₁ (-isg +₁ g)))) +₁ itf\n ≡⟨ cong (λ z → (isg +₁ (f +₁ z)) +₁ itf)\n (assoc₁ -itf -isg g) ⟩\n (isg +₁ (f +₁ ((-itf -₁ isg) +₁ g))) +₁ itf\n ≡⟨ cong (λ z → (isg +₁ z) +₁ itf)\n (IC5 𝒞 g f) ⟩\n (isg +₁ ((-isg +₁ g) +₁ (f -₁ itf))) +₁ itf\n ≡⟨ cong (_+₁ itf)\n (assoc₁ isg (-isg +₁ g) (f -₁ itf)) ⟩\n ((isg +₁ (-isg +₁ g)) +₁ (f -₁ itf)) +₁ itf\n ≡⟨ cong (λ z → (z +₁ (f -₁ itf)) +₁ itf)\n (assoc₁ isg -isg g ∙ rCancel-lId G₁ isg g) ⟩\n (g +₁ (f -₁ itf)) +₁ itf\n ≡⟨ sym (assoc₁ g (f -₁ itf) itf) ⟩\n g +₁ ((f -₁ itf) +₁ itf)\n ≡⟨ cong (g +₁_) ((sym (assoc₁ _ _ _)) ∙ (lCancel-rId G₁ f itf)) ⟩\n g +₁ f ∎\n where\n isg = 𝒾s g\n -isg = -₁ (𝒾s g)\n itf = 𝒾t f\n -itf = -it f\n\n RelIso.leftInv (𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group _) _ = tt\n RelIso.rightInv (𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group _) _ = tt\n\n Iso-PeifferGraph-Strict2Group : Iso (PeifferGraph ℓ ℓℓ') (Strict2Group ℓ ℓℓ')\n Iso-PeifferGraph-Strict2Group = 𝒮ᴰ-♭PIso-Over→TotalIso idIso (𝒮ᴰ-ReflGraph\\Peiffer ℓ ℓℓ') (𝒮ᴰ-Strict2Group ℓ ℓℓ') 𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group\n\n open import Cubical.DStructures.Equivalences.XModPeifferGraph\n Iso-XModule-Strict2Group : Iso (XModule ℓ ℓℓ') (Strict2Group ℓ ℓℓ')\n Iso-XModule-Strict2Group = compIso (Iso-XModule-PeifferGraph ℓ ℓℓ') Iso-PeifferGraph-Strict2Group\n", "meta": {"hexsha": "f3f08f6b0739a9d8f1583d2f051c0756962de629", "size": 9531, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/DStructures/Equivalences/PeifferGraphS2G.agda", "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/DStructures/Equivalences/PeifferGraphS2G.agda", "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/DStructures/Equivalences/PeifferGraphS2G.agda", "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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.0462184874, "max_line_length": 150, "alphanum_fraction": 0.4261882279, "num_tokens": 3748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.798186768138228, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.38974134522674314}} {"text": "data ⊥ : Set where\n\np0 : Set → Set\np0 A = A\n\np1 : ⊥ → Set\np1 ()\n\np2 : ⊥ → ⊥\np2 ()\n\np3 : Set → ⊥\np3 = ?\n", "meta": {"hexsha": "5510f683b3fb14886071d8f018fa026eac4c1431", "size": 103, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda/implication.agda", "max_stars_repo_name": "anqurvanillapy/fpl", "max_stars_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-24T22:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-24T22:47:47.000Z", "max_issues_repo_path": "agda/implication.agda", "max_issues_repo_name": "anqurvanillapy/fpl", "max_issues_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2", "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/implication.agda", "max_forks_repo_name": "anqurvanillapy/fpl", "max_forks_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2", "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": 7.3571428571, "max_line_length": 18, "alphanum_fraction": 0.4077669903, "num_tokens": 55, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7981867585368344, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.3897413405385421}} {"text": "------------------------------------------------------------------------\n-- Binary relations lifted to substitutions\n------------------------------------------------------------------------\n\n{-# OPTIONS --safe --without-K #-}\n\nmodule Data.Fin.Substitution.Relation where\n\nopen import Data.Fin using (Fin; zero; suc)\nopen import Data.Fin.Substitution\nopen import Data.Fin.Substitution.ExtraLemmas\nopen import Data.Nat using (ℕ; zero; suc)\nopen import Data.Vec.Relation.Binary.Pointwise.Inductive hiding (refl)\nimport Function as Fun\nopen import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)\n\n\n-- Term relations.\n--\n-- A term relation R : TermRel T₁ T₂ is a ℕ-indexed family of binary\n-- relations relating T₁-terms to T₂-terms.\nTermRel : (ℕ → Set) → (ℕ → Set) → Set₁\nTermRel T₁ T₂ = ∀ {n} → T₁ n → T₂ n → Set\n\n-- Substitution relations.\n--\n-- A substitution relation R : SubRel T₁ T₂ is a ℕ²-indexed family\n-- of binary relations relating T₁-substitutions to T₂-substitutions.\nSubRel : (ℕ → Set) → (ℕ → Set) → Set₁\nSubRel T₁ T₂ = ∀ {m n} → Sub T₁ m n → Sub T₂ m n → Set\n\nmodule LiftTermRel (T₁ T₂ : ℕ → Set) where\n\n -- Term relations lifted point-wise to corresponding substitutions.\n --\n -- Given a relation R on T₁ and T₂ terms, the family of relations\n -- (lift R) relates T₁ and T₂ substitutions point-wise.\n lift : TermRel T₁ T₂ → SubRel T₁ T₂\n lift P σ₁ σ₂ = Pointwise P σ₁ σ₂\n\n infix 4 _⟨_⟩_\n\n -- Syntactic sugar: and infix version of lifting.\n _⟨_⟩_ : ∀ {m n} → Sub T₁ m n → TermRel T₁ T₂ → Sub T₂ m n → Set\n σ₁ ⟨ R ⟩ σ₂ = lift R σ₁ σ₂\n\n\n------------------------------------------------------------------------\n-- Generic substitutions lifted to relations\n\nmodule _ {T₁ T₂} (_∼_ : TermRel T₁ T₂) where\n open LiftTermRel T₁ T₂ using (_⟨_⟩_)\n\n -- Extensions of substitutions lifted to relations.\n record RelExtension (ext₁ : Extension T₁) (ext₂ : Extension T₂) : Set where\n private\n module E₁ = Extension ext₁\n module E₂ = Extension ext₂\n\n -- Weakening lifted to _∼_.\n field weaken : ∀ {n} {t₁ : T₁ n} {t₂ : T₂ n} →\n t₁ ∼ t₂ → E₁.weaken t₁ ∼ E₂.weaken t₂\n\n infixr 5 _/∷_\n\n -- Extension.\n _/∷_ : ∀ {m n t₁ t₂} {σ₁ : Sub T₁ m n} {σ₂ : Sub T₂ m n} →\n t₁ ∼ t₂ → σ₁ ⟨ _∼_ ⟩ σ₂ → t₁ E₁./∷ σ₁ ⟨ _∼_ ⟩ t₂ E₂./∷ σ₂\n t₁∼t₂ /∷ σ₁∼σ₂ = t₁∼t₂ ∷ map⁺ weaken σ₁∼σ₂\n\n -- Simple substitutions lifted to relations.\n record RelSimple (simple₁ : Simple T₁) (simple₂ : Simple T₂) : Set where\n private\n module S₁ = SimpleExt simple₁\n module S₂ = SimpleExt simple₂\n\n field\n extension : RelExtension S₁.extension S₂.extension\n\n -- Relates variables.\n var : ∀ {n} (x : Fin n) → S₁.var x ∼ S₂.var x\n\n open RelExtension extension public\n\n infix 10 _↑\n infixl 10 _↑⋆_\n\n -- Lifting.\n\n _↑ : ∀ {m n} {σ₁ : Sub T₁ m n} {σ₂ : Sub T₂ m n} →\n σ₁ ⟨ _∼_ ⟩ σ₂ → σ₁ S₁.↑ ⟨ _∼_ ⟩ σ₂ S₂.↑\n σ₁∼σ₂ ↑ = var zero /∷ σ₁∼σ₂\n\n _↑⋆_ : ∀ {m n} {σ₁ : Sub T₁ m n} {σ₂ : Sub T₂ m n} →\n σ₁ ⟨ _∼_ ⟩ σ₂ → ∀ k → σ₁ S₁.↑⋆ k ⟨ _∼_ ⟩ σ₂ S₂.↑⋆ k\n σ₁∼σ₂ ↑⋆ zero = σ₁∼σ₂\n σ₁∼σ₂ ↑⋆ suc k = (σ₁∼σ₂ ↑⋆ k) ↑\n\n -- The identity substitution.\n id : ∀ {n} → S₁.id {n} ⟨ _∼_ ⟩ S₂.id {n}\n id {zero} = []\n id {suc n} = id ↑\n\n -- Weakening.\n\n wk⋆ : ∀ k {n} → S₁.wk⋆ k {n} ⟨ _∼_ ⟩ S₂.wk⋆ k {n}\n wk⋆ zero = id\n wk⋆ (suc k) = map⁺ weaken (wk⋆ k)\n\n wk : ∀ {n} → S₁.wk {n} ⟨ _∼_ ⟩ S₂.wk {n}\n wk = wk⋆ 1\n\n -- A substitution which only replaces the first variable.\n sub : ∀ {n} {t₁ : T₁ n} {t₂} → t₁ ∼ t₂ → S₁.sub t₁ ⟨ _∼_ ⟩ S₂.sub t₂\n sub t₁~t₂ = t₁~t₂ ∷ id\n\n -- Application of substitutions lifted to relations.\n record RelApplication {T₁′ T₂′} (R : TermRel T₁′ T₂′)\n (app₁ : Application T₁ T₁′)\n (app₂ : Application T₂ T₂′) : Set where\n private\n module A₁ = Application app₁\n module A₂ = Application app₂\n open LiftTermRel T₁′ T₂′ using () renaming (_⟨_⟩_ to _⟨_⟩′_)\n\n infixl 8 _/_\n infixl 9 _⊙_\n\n -- Post-application of substitutions to things.\n field _/_ : ∀ {m n t₁ t₂} {σ₁ : Sub T₁′ m n} {σ₂ : Sub T₂′ m n} →\n t₁ ∼ t₂ → σ₁ ⟨ R ⟩′ σ₂ → (t₁ A₁./ σ₁) ∼ (t₂ A₂./ σ₂)\n\n -- Reverse composition. (Fits well with post-application.)\n _⊙_ : ∀ {m n k} {σ₁ : Sub T₁ m n} {σ₂} {σ₁′ : Sub T₁′ n k} {σ₂′} →\n σ₁ ⟨ _∼_ ⟩ σ₂ → σ₁′ ⟨ R ⟩′ σ₂′ → σ₁ A₁.⊙ σ₁′ ⟨ _∼_ ⟩ σ₂ A₂.⊙ σ₂′\n σ₁∼σ₂ ⊙ σ₁∼σ₂′ = map⁺ (λ t₁∼t₂ → t₁∼t₂ / σ₁∼σ₂′) σ₁∼σ₂\n\n -- A combination of the two records above.\n record RelSubst (subst₁ : Subst T₁) (subst₂ : Subst T₂) : Set where\n private\n module S₁ = Subst subst₁\n module S₂ = Subst subst₂\n\n field\n simple : RelSimple S₁.simple S₂.simple\n application : RelApplication _∼_ S₁.application S₂.application\n\n open RelSimple simple public\n open RelApplication application public\n\n------------------------------------------------------------------------\n-- Instantiations and code for facilitating instantiations\n\n-- Liftings from TermRel T₁ T₂ to TermRel T₁′ T₂′.\nrecord RelLift {T₁ T₂ T₁′ T₂′} (_∼_ : TermRel T₁ T₂) (_∼′_ : TermRel T₁′ T₂′)\n (l₁ : Lift T₁ T₁′) (l₂ : Lift T₂ T₂′) : Set where\n private\n module L₁ = Lift l₁\n module L₂ = Lift l₂\n\n field\n simple : RelSimple _∼_ L₁.simple L₂.simple\n lift : ∀ {n} {t₁ : T₁ n} {t₂} → t₁ ∼ t₂ → L₁.lift t₁ ∼′ L₂.lift t₂\n\n open RelSimple simple public\n\n-- Variable substitutions (renamings) lifted to equality.\nmodule VarEqSubst where\n private module V = VarSubst\n\n infix 4 _⟨≡⟩_\n\n _⟨≡⟩_ : SubRel Fin Fin\n _⟨≡⟩_ = LiftTermRel.lift Fin Fin _≡_\n\n subst : RelSubst _≡_ V.subst V.subst\n subst = record\n { simple = record { extension = extension; var = λ _ → refl }\n ; application = record { _/_ = _/_ }\n }\n where\n extension = record { weaken = cong suc }\n\n _/_ : ∀ {m n x₁ x₂} {σ₁ σ₂ : Sub Fin n m} →\n x₁ ≡ x₂ → σ₁ ⟨≡⟩ σ₂ → x₁ V./ σ₁ ≡ x₂ V./ σ₂\n _/_ {x₁ = x} refl σ₁≡σ₂ = lookup σ₁≡σ₂ x\n\n open RelSubst subst public\n\n-- \"Term\" substitutions lifted to relations.\nrecord TermRelSubst {T₁ T₂ : ℕ → Set} (_∼_ : TermRel T₁ T₂)\n (ts₁ : TermSubst T₁) (ts₂ : TermSubst T₂) : Set₁ where\n private\n module S₁ = TermSubst ts₁\n module S₂ = TermSubst ts₂\n module V = VarEqSubst\n\n field\n var : ∀ {n} (x : Fin n) → S₁.var x ∼ S₂.var x\n app : ∀ {T₁′ T₂′} (R : TermRel T₁′ T₂′)\n (l₁ : Lift T₁′ T₁) (l₂ : Lift T₂′ T₂) → RelLift R _∼_ l₁ l₂ →\n let open LiftTermRel T₁′ T₂′ using (_⟨_⟩_) in\n ∀ {m n t₁ t₂} {σ₁ : Sub T₁′ m n} {σ₂ : Sub T₂′ m n} →\n t₁ ∼ t₂ → σ₁ ⟨ R ⟩ σ₂ → S₁.app l₁ t₁ σ₁ ∼ S₂.app l₂ t₂ σ₂\n\n module RelLifted {T₁′ T₂′} (R : TermRel T₁′ T₂′)\n (l₁ : Lift T₁′ T₁) (l₂ : Lift T₂′ T₂)\n (lift : RelLift R _∼_ l₁ l₂) where\n private\n module L₁ = S₁.Lifted l₁\n module L₂ = S₂.Lifted l₂\n\n application : RelApplication _∼_ R L₁.application L₂.application\n application = record { _/_ = app R l₁ l₂ lift }\n\n varLift : RelLift _≡_ _∼_ S₁.varLift S₂.varLift\n varLift = record { simple = V.simple; lift = lift }\n where\n lift : ∀ {n} {x₁ x₂ : Fin n} → x₁ ≡ x₂ → S₁.var x₁ ∼ S₂.var x₂\n lift {x₁ = x} refl = var x\n\n infix 8 _/Var_\n\n _/Var_ : ∀ {m n t₁ t₂} {σ₁ σ₂ : Sub Fin m n} →\n t₁ ∼ t₂ → σ₁ V.⟨≡⟩ σ₂ → (t₁ S₁./Var σ₁) ∼ (t₂ S₂./Var σ₂)\n _/Var_ = app _≡_ S₁.varLift S₂.varLift varLift\n\n simple : RelSimple _∼_ S₁.simple S₂.simple\n simple = record\n { extension = record { weaken = λ t₁∼t₂ → t₁∼t₂ /Var V.wk }\n ; var = var\n }\n\n termLift : RelLift _∼_ _∼_ S₁.termLift S₂.termLift\n termLift = record { simple = simple; lift = Fun.id }\n\n subst : RelSubst _∼_ S₁.subst S₂.subst\n subst = record\n { simple = simple\n ; application = RelLifted.application _∼_ S₁.termLift S₂.termLift termLift\n }\n\n open LiftTermRel T₁ T₂ public using (_⟨_⟩_)\n open RelSubst subst public hiding (var; simple)\n", "meta": {"hexsha": "0ad1592dc4b2ebd78d32ede2fa4368f837446813", "size": 7982, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Data/Fin/Substitution/Relation.agda", "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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/Data/Fin/Substitution/Relation.agda", "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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/Data/Fin/Substitution/Relation.agda", "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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": 32.5795918367, "max_line_length": 78, "alphanum_fraction": 0.5611375595, "num_tokens": 3056, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6224593312018545, "lm_q2_score": 0.6261241772283034, "lm_q1q2_score": 0.3897368366068411}} {"text": "------------------------------------------------------------------------\n-- Some omniscience principles\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nopen import Equality\n\nmodule Omniscience {c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where\n\nopen Derived-definitions-and-properties eq\n\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude\n\nopen import Equality.Decision-procedures eq\nopen import Excluded-middle eq\nopen import Function-universe eq hiding (id; _∘_)\nopen import H-level eq\nopen import H-level.Closure eq\nopen import Nat eq\n\n-- I don't know who first stated LPO and WLPO, or who first proved\n-- various properties about these principles.\n\n-- The limited principle of omniscience.\n\nLPO : Type\nLPO = (f : ℕ → Bool) → (∀ n → f n ≡ false) ⊎ (∃ λ n → f n ≡ true)\n\n-- The weak limited principle of omniscience.\n\nWLPO : Type\nWLPO = (f : ℕ → Bool) → Dec (∀ n → f n ≡ false)\n\n-- WLPO is propositional (assuming extensionality).\n\nWLPO-propositional :\n Extensionality lzero lzero →\n Is-proposition WLPO\nWLPO-propositional ext =\n Π-closure ext 1 λ f →\n Dec-closure-propositional ext\n (Π-closure ext 1 λ _ →\n Bool-set)\n\n-- LPO implies WLPO.\n\nLPO→WLPO : LPO → WLPO\nLPO→WLPO LPO f =\n ⊎-map id\n (uncurry λ n fn≡true ∀n→fn≡false → Bool.true≢false (\n true ≡⟨ sym fn≡true ⟩\n f n ≡⟨ ∀n→fn≡false n ⟩∎\n false ∎))\n (LPO f)\n\n-- WLPO follows from excluded middle (assuming extensionality).\n--\n-- This follows from LPO→WLPO and LEM→LPO (see below), but this proof\n-- is less complicated.\n\nLEM→WLPO : Extensionality lzero lzero → Excluded-middle lzero → WLPO\nLEM→WLPO ext em = λ _ → em (Π-closure ext 1 λ _ →\n Bool-set)\n\nmutual\n\n -- There is a propositional property that is logically equivalent to\n -- LPO (assuming extensionality).\n --\n -- I think that Escardo has proved some variant of this property. The\n -- proof below uses a technique suggested by Exercise 3.19 in the HoTT\n -- book.\n\n LPO⇔propositional :\n Extensionality lzero lzero →\n ∃ λ (P : Type) → Is-proposition P × (LPO ⇔ P)\n LPO⇔propositional ext =\n let P , P-prop , LPO⇔ = LPO⇔propositional′ ext in\n\n (∀ f → P f ⊎ ¬ P f)\n , (Π-closure ext 1 λ f →\n ⊎-closure-propositional\n (flip _$_) (P-prop f) (¬-propositional ext))\n , LPO⇔\n\n -- A variant of the previous property.\n\n LPO⇔propositional′ :\n Extensionality lzero lzero →\n ∃ λ (P : (ℕ → Bool) → Type) →\n (∀ f → Is-proposition (P f)) ×\n (LPO ⇔ ∀ f → P f ⊎ ¬ P f)\n LPO⇔propositional′ ext =\n P\n , P-prop\n , (((f : ℕ → Bool) → (∀ n → f n ≡ false) ⊎ (∃ λ n → f n ≡ true)) ↝⟨ (∀-cong _ λ _ →\n record { to = ≡false→¬P; from = ¬P→≡false }\n ⊎-cong\n record { to = ≡true→P; from = Σ-map id proj₁ }) ⟩\n ((f : ℕ → Bool) → ¬ P f ⊎ P f) ↝⟨ (∀-cong _ λ _ → from-bijection ⊎-comm) ⟩□\n ((f : ℕ → Bool) → P f ⊎ ¬ P f) □)\n where\n P = λ (f : ℕ → Bool) →\n ∃ λ n → f n ≡ true × ∀ {m} → m < n → f m ≡ false\n\n P-prop : ∀ f → Is-proposition (P f)\n P-prop f (n₁ , fn₁≡true , n₂ of λ where\n (inj₁ n₁n₂)) → ⊥-elim (Bool.true≢false (\n true ≡⟨ sym fn₂≡true ⟩\n f n₂ ≡⟨ n₂ ⟩∎\n false ∎)))\n (×-closure 1\n (Bool-set)\n (implicit-Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n Bool-set)\n _ _)\n\n ¬P→≡false : ∀ {f} → ¬ (P f) → (∀ n → f n ≡ false)\n ¬P→≡false {f} ¬Pf =\n well-founded-elim _ λ n hyp →\n case inspect (f n) of λ where\n (false , fn≡false) → fn≡false\n (true , fn≡true) → ⊥-elim (¬Pf (n , fn≡true , hyp))\n\n ≡false→¬P : ∀ {f} → (∀ n → f n ≡ false) → ¬ (P f)\n ≡false→¬P {f} ≡false (n , ≡true , _) = Bool.true≢false (\n true ≡⟨ sym ≡true ⟩\n f n ≡⟨ ≡false n ⟩∎\n false ∎)\n\n ≡true→P : ∀ {f} → (∃ λ n → f n ≡ true) → P f\n ≡true→P {f} (n , fn≡true) =\n helper (≤→≤↑ (zero≤ _)) (λ o<0 → ⊥-elim (≮0 _ o<0))\n where\n helper : ∀ {m} → m ≤↑ n → (∀ {o} → o < m → f o ≡ false) → P f\n helper {m} (≤↑-refl m≡n) <→≡false = n , fn≡true , λ {o} →\n o < n ↝⟨ subst (o <_) (sym m≡n) ⟩\n o < m ↝⟨ <→≡false ⟩□\n f o ≡ false □\n helper {m} (≤↑-step m d ⊣ Δ →\n fresh x d\n fresh-elab-synth1 _ FRHConst ESConst = FConst\n fresh-elab-synth1 apt (FRHAsc frsh) (ESAsc x₁) = FCast (fresh-elab-ana1 apt frsh x₁)\n fresh-elab-synth1 _ (FRHVar x₂) (ESVar x₃) = FVar x₂\n fresh-elab-synth1 {Γ = Γ} apt (FRHLam2 x₂ frsh) (ESLam x₃ exp) = FLam x₂ (fresh-elab-synth1 (apart-extend1 Γ x₂ apt) frsh exp)\n fresh-elab-synth1 apt FRHEHole ESEHole = FHole (EFId apt)\n fresh-elab-synth1 apt (FRHNEHole frsh) (ESNEHole x₁ exp) = FNEHole (EFId apt) (fresh-elab-synth1 apt frsh exp)\n fresh-elab-synth1 apt (FRHAp frsh frsh₁) (ESAp x₁ x₂ x₃ x₄ x₅ x₆) =\n FAp (FCast (fresh-elab-ana1 apt frsh x₅))\n (FCast (fresh-elab-ana1 apt frsh₁ x₆))\n fresh-elab-synth1 apt (FRHLam1 x₁ frsh) ()\n fresh-elab-synth1 apt (FRHFst frsh) (ESFst s m esana) = FFst (FCast (fresh-elab-ana1 apt frsh esana))\n fresh-elab-synth1 apt (FRHSnd frsh) (ESSnd s m esana) = FSnd (FCast (fresh-elab-ana1 apt frsh esana))\n fresh-elab-synth1 apt (FRHPair frsh frsh₁) (ESPair x₁ x₂ exp exp₁) = FPair (fresh-elab-synth1 apt frsh exp)\n (fresh-elab-synth1 apt frsh₁ exp₁)\n\n fresh-elab-ana1 : ∀{ x e τ d τ' Γ Δ} →\n x # Γ →\n freshe x e →\n Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →\n fresh x d\n fresh-elab-ana1 {Γ = Γ} apt (FRHLam1 x₁ frsh) (EALam x₂ x₃ exp) = FLam x₁ (fresh-elab-ana1 (apart-extend1 Γ x₁ apt) frsh exp )\n fresh-elab-ana1 apt frsh (EASubsume x₁ x₂ x₃ x₄) = fresh-elab-synth1 apt frsh x₃\n fresh-elab-ana1 apt FRHEHole EAEHole = FHole (EFId apt)\n fresh-elab-ana1 apt (FRHNEHole frsh) (EANEHole x₁ x₂) = FNEHole (EFId apt) (fresh-elab-synth1 apt frsh x₂)\n\n -- if x is fresh in the expansion of an eexp, it's fresh in that eexp\n mutual\n fresh-elab-synth2 : ∀{x e τ d Γ Δ} →\n fresh x d →\n Γ ⊢ e ⇒ τ ~> d ⊣ Δ →\n freshe x e\n fresh-elab-synth2 FConst ESConst = FRHConst\n fresh-elab-synth2 (FVar x₂) (ESVar x₃) = FRHVar x₂\n fresh-elab-synth2 (FLam x₂ frsh) (ESLam x₃ exp) = FRHLam2 x₂ (fresh-elab-synth2 frsh exp)\n fresh-elab-synth2 (FHole x₁) ESEHole = FRHEHole\n fresh-elab-synth2 (FNEHole x₁ frsh) (ESNEHole x₂ exp) = FRHNEHole (fresh-elab-synth2 frsh exp)\n fresh-elab-synth2 (FAp (FCast frsh) (FCast frsh₁)) (ESAp x₁ x₂ x₃ x₄ x₅ x₆) =\n FRHAp (fresh-elab-ana2 frsh x₅)\n (fresh-elab-ana2 frsh₁ x₆)\n fresh-elab-synth2 (FCast frsh) (ESAsc x₁) = FRHAsc (fresh-elab-ana2 frsh x₁)\n fresh-elab-synth2 (FFailedCast frsh) ()\n fresh-elab-synth2 (FFst (FCast frsh)) (ESFst s m esana) = FRHFst (fresh-elab-ana2 frsh esana)\n fresh-elab-synth2 (FSnd (FCast frsh)) (ESSnd s m esana) = FRHSnd (fresh-elab-ana2 frsh esana)\n fresh-elab-synth2 (FPair frsh frsh₁) (ESPair x₁ x₂ exp exp₁) = FRHPair (fresh-elab-synth2 frsh exp) (fresh-elab-synth2 frsh₁ exp₁)\n\n fresh-elab-ana2 : ∀{ x e τ d τ' Γ Δ} →\n fresh x d →\n Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →\n freshe x e\n fresh-elab-ana2 (FLam x₁ frsh) (EALam x₂ x₃ exp) = FRHLam1 x₁ (fresh-elab-ana2 frsh exp)\n fresh-elab-ana2 frsh (EASubsume x₁ x₂ x₃ x₄) = fresh-elab-synth2 frsh x₃\n fresh-elab-ana2 (FHole x₁) EAEHole = FRHEHole\n fresh-elab-ana2 (FNEHole x₁ frsh) (EANEHole x₂ x₃) = FRHNEHole (fresh-elab-synth2 frsh x₃)\n", "meta": {"hexsha": "cbef682b7bca326b7ed0bf44fe1b7869519fe899", "size": 3896, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lemmas-freshness.agda", "max_stars_repo_name": "hazelgrove/hazel-palette-agda", "max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z", "max_issues_repo_path": "lemmas-freshness.agda", "max_issues_repo_name": "hazelgrove/hazel-palette-agda", "max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z", "max_forks_repo_path": "lemmas-freshness.agda", "max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda", "max_forks_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a", "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": 57.2941176471, "max_line_length": 134, "alphanum_fraction": 0.5875256674, "num_tokens": 1479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.749087201911703, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.38916677339456224}} {"text": "{-# OPTIONS --safe #-}\n{-\n This is inspired by/copied from:\n https://github.com/agda/agda-stdlib/blob/master/src/Tactic/MonoidSolver.agda\n\n Boilerplate code for calling the ring solver is constructed automatically\n with agda's reflection features.\n-}\nmodule Cubical.Algebra.NatSolver.Reflection where\n\nopen import Cubical.Foundations.Prelude hiding (Type)\nopen import Cubical.Functions.Logic\n\nopen import Agda.Builtin.Reflection hiding (Type)\nopen import Agda.Builtin.String\n\nopen import Cubical.Reflection.Base\n\nopen import Cubical.Data.Maybe\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.List\nopen import Cubical.Data.Nat.Literals\nopen import Cubical.Data.Nat\nopen import Cubical.Data.FinData using () renaming (zero to fzero; suc to fsuc)\nopen import Cubical.Data.Bool\nopen import Cubical.Data.Bool.SwitchStatement\nopen import Cubical.Data.Vec using (Vec) renaming ([] to emptyVec; _∷_ to _∷vec_) public\n\nopen import Cubical.Algebra.NatSolver.NatExpression\nopen import Cubical.Algebra.NatSolver.Solver\n\nopen EqualityToNormalform renaming (solve to natSolve)\nprivate\n variable\n ℓ : Level\n\n _==_ = primQNameEquality\n {-# INLINE _==_ #-}\n\n record VarInfo : Type ℓ-zero where\n field\n varName : String\n varType : Arg Term\n index : ℕ\n\n {-\n `getLastTwoArgsOf` maps a term 'def n (z₁ ∷ … ∷ zₙ ∷ x ∷ y ∷ [])' to the pair '(x,y)'\n non-visible arguments are ignored.\n -}\n getLastTwoArgsOf : Name → Term → Maybe (Term × Term)\n getLastTwoArgsOf n' (def n xs) =\n if n == n'\n then go xs\n else nothing\n where\n go : List (Arg Term) → Maybe (Term × Term)\n go (varg x ∷ varg y ∷ []) = just (x , y)\n go (x ∷ xs) = go xs\n go _ = nothing\n getLastTwoArgsOf n' _ = nothing\n\n {-\n `getArgs` maps a term 'x ≡ y' to the pair '(x,y)'\n -}\n getArgs : Term → Maybe (Term × Term)\n getArgs = getLastTwoArgsOf (quote PathP)\n\n\n firstVisibleArg : List (Arg Term) → Maybe Term\n firstVisibleArg [] = nothing\n firstVisibleArg (varg x ∷ l) = just x\n firstVisibleArg (x ∷ l) = firstVisibleArg l\n\n {-\n If the solver needs to be applied during equational reasoning,\n the right hand side of the equation to solve cannot be given to\n the solver directly. The folllowing function extracts this term y\n from a more complex expression as in:\n x ≡⟨ solve ... ⟩ (y ≡⟨ ... ⟩ z ∎)\n -}\n getRhs : Term → Maybe Term\n getRhs reasoningToTheRight@(def n xs) =\n if n == (quote _∎)\n then firstVisibleArg xs\n else (if n == (quote _≡⟨_⟩_)\n then firstVisibleArg xs\n else nothing)\n getRhs _ = nothing\n\n\n private\n solverCallAsTerm : Arg Term → Term → Term → Term\n solverCallAsTerm varList lhs rhs =\n def\n (quote natSolve)\n (varg lhs ∷ varg rhs\n ∷ varList\n ∷ varg (def (quote refl) []) ∷ [])\n\n solverCallWithLambdas : ℕ → List VarInfo → Term → Term → Term\n solverCallWithLambdas n varInfos lhs rhs =\n encloseWithIteratedLambda\n (map VarInfo.varName varInfos)\n (solverCallAsTerm (variableList (rev varInfos)) lhs rhs)\n where\n encloseWithIteratedLambda : List String → Term → Term\n encloseWithIteratedLambda (varName ∷ xs) t = lam visible (abs varName (encloseWithIteratedLambda xs t))\n encloseWithIteratedLambda [] t = t\n\n variableList : List VarInfo → Arg Term\n variableList [] = varg (con (quote emptyVec) [])\n variableList (varInfo ∷ varInfos)\n = varg (con (quote _∷vec_) (varg (var (VarInfo.index varInfo) []) ∷ (variableList varInfos) ∷ []))\n\n solverCallByVarIndices : ℕ → List ℕ → Term → Term → Term → Term\n solverCallByVarIndices n varIndices R lhs rhs =\n solverCallAsTerm (variableList (rev varIndices)) lhs rhs\n where\n variableList : List ℕ → Arg Term\n variableList [] = varg (con (quote emptyVec) [])\n variableList (varIndex ∷ varIndices)\n = varg (con (quote _∷vec_) (varg (var (varIndex) []) ∷ (variableList varIndices) ∷ []))\n\n\n\nmodule pr {n : ℕ} where\n 0' : Expr n\n 0' = K 0\n\n 1' : Expr n\n 1' = K 1\n\nmodule _ where\n open pr\n\n `0` : List (Arg Term) → Term\n `0` [] = def (quote 0') []\n `0` (varg fstcring ∷ xs) = `0` xs\n `0` (harg _ ∷ xs) = `0` xs\n `0` _ = unknown\n\n `1` : List (Arg Term) → Term\n `1` [] = def (quote 1') []\n `1` (varg fstcring ∷ xs) = `1` xs\n `1` (harg _ ∷ xs) = `1` xs\n `1` _ = unknown\n\n mutual\n\n `_·_` : List (Arg Term) → Term\n `_·_` (harg _ ∷ xs) = `_·_` xs\n `_·_` (varg x ∷ varg y ∷ []) =\n con\n (quote _·'_) (varg (buildExpression x) ∷ varg (buildExpression y) ∷ [])\n `_·_` _ = unknown\n\n `_+_` : List (Arg Term) → Term\n `_+_` (harg _ ∷ xs) = `_+_` xs\n `_+_` (varg x ∷ varg y ∷ []) =\n con\n (quote _+'_) (varg (buildExpression x) ∷ varg (buildExpression y) ∷ [])\n `_+_` _ = unknown\n\n K' : List (Arg Term) → Term\n K' xs = con (quote K) xs\n\n finiteNumberAsTerm : ℕ → Term\n finiteNumberAsTerm ℕ.zero = con (quote fzero) []\n finiteNumberAsTerm (ℕ.suc n) = con (quote fsuc) (varg (finiteNumberAsTerm n) ∷ [])\n\n buildExpression : Term → Term\n buildExpression (var index _) = con (quote ∣) (varg (finiteNumberAsTerm index) ∷ [])\n buildExpression t@(lit n) = K' (varg t ∷ [])\n buildExpression t@(def n xs) =\n switch (n ==_) cases\n case (quote _·_) ⇒ `_·_` xs break\n case (quote _+_) ⇒ `_+_` xs break\n default⇒ (K' xs)\n buildExpression t@(con n xs) =\n switch (n ==_) cases\n case (quote _·_) ⇒ `_·_` xs break\n case (quote _+_) ⇒ `_+_` xs break\n default⇒ (K' xs)\n buildExpression t = unknown\n\n toAlgebraExpression : Maybe (Term × Term) → Maybe (Term × Term)\n toAlgebraExpression nothing = nothing\n toAlgebraExpression (just (lhs , rhs)) = just (buildExpression lhs , buildExpression rhs)\n\nprivate\n adjustDeBruijnIndex : (n : ℕ) → Term → Term\n adjustDeBruijnIndex n (var k args) = var (k + n) args\n adjustDeBruijnIndex n _ = unknown\n\n extractVarIndices : Maybe (List Term) → Maybe (List ℕ)\n extractVarIndices (just ((var index _) ∷ l)) with extractVarIndices (just l)\n ... | just indices = just (index ∷ indices)\n ... | nothing = nothing\n extractVarIndices (just []) = just []\n extractVarIndices _ = nothing\n\n getVarsAndEquation : Term → Maybe (List VarInfo × Term)\n getVarsAndEquation t =\n let\n (rawVars , equationTerm) = extractVars t\n maybeVars = addIndices (length rawVars) rawVars\n in map-Maybe (_, equationTerm) maybeVars\n where\n extractVars : Term → List (String × Arg Term) × Term\n extractVars (pi argType (abs varName t)) with extractVars t\n ... | xs , equation\n = (varName , argType) ∷ xs , equation\n extractVars equation = [] , equation\n\n addIndices : ℕ → List (String × Arg Term) → Maybe (List VarInfo)\n addIndices ℕ.zero [] = just []\n addIndices (ℕ.suc countVar) ((varName , argType) ∷ list) =\n map-Maybe (λ varList → record { varName = varName ; varType = argType ; index = countVar }\n ∷ varList)\n (addIndices countVar list)\n addIndices _ _ = nothing\n\n toListOfTerms : Term → Maybe (List Term)\n toListOfTerms (con c []) = if (c == (quote [])) then just [] else nothing\n toListOfTerms (con c (varg t ∷ varg s ∷ args)) with toListOfTerms s\n ... | just terms = if (c == (quote _∷_)) then just (t ∷ terms) else nothing\n ... | nothing = nothing\n toListOfTerms (con c (harg t ∷ args)) = toListOfTerms (con c args)\n toListOfTerms _ = nothing\n\n solve-macro : Term → TC Unit\n solve-macro hole =\n do\n hole′ ← inferType hole >>= normalise\n just (varInfos , equation) ← returnTC (getVarsAndEquation hole′)\n where\n nothing\n → typeError (strErr \"Something went wrong when getting the variable names in \"\n ∷ termErr hole′ ∷ [])\n just (lhs , rhs) ← returnTC (toAlgebraExpression (getArgs equation))\n where\n nothing\n → typeError(\n strErr \"Error while trying to build ASTs for the equation \" ∷\n termErr equation ∷ [])\n let solution = solverCallWithLambdas (length varInfos) varInfos lhs rhs\n unify hole solution\n\nmacro\n solve : Term → TC _\n solve = solve-macro\n", "meta": {"hexsha": "86b26eefa8a75f000339ca6d2014a15b5fe71f03", "size": 8419, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/NatSolver/Reflection.agda", "max_stars_repo_name": "FernandoLarrain/cubical", "max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z", "max_issues_repo_path": "Cubical/Algebra/NatSolver/Reflection.agda", "max_issues_repo_name": "Seanpm2001-web/cubical", "max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "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": "Cubical/Algebra/NatSolver/Reflection.agda", "max_forks_repo_name": "Seanpm2001-web/cubical", "max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "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": 33.4087301587, "max_line_length": 109, "alphanum_fraction": 0.6113552678, "num_tokens": 2520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.6039318337259583, "lm_q1q2_score": 0.38906804989261395}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nmodule Base where\n\n{-\nWith the HoTT-Agda library, the following import can be used instead:\n\nopen import HoTT using\n (Type; lmax; lsucc;\n _==_; idp; !;\n ap; apd;\n Square; ids; vid-square; hid-square; SquareOver; ↓-ap-in; apd-square;\n app=; λ=; app=-β;\n transport;\n ℕ; O; S; ℕ-reader;\n _×_; _,_; fst; snd;\n _∘_; ap-∘; ap-!;\n PathOver; ↓-cst-in; apd=cst-in; ap-idf; ap-cst; square-symmetry; uncurry; ap-square;\n Cube; idc; ap-cube;\n is-contr) public\n-}\n\nopen import Agda.Primitive public using (lzero)\n renaming (Level to ULevel; lsuc to lsucc; _⊔_ to lmax)\n\nType : (i : ULevel) → Set (lsucc i)\nType i = Set i\n\nType₀ : Set (lsucc lzero)\nType₀ = Type lzero\n\ninfix 30 _==_\ndata _==_ {i} {A : Type i} (a : A) : A → Type i where\n idp : a == a\n\nPathOver : ∀ {i j} {A : Type i} (B : A → Type j)\n {x y : A} (p : x == y) (u : B x) (v : B y) → Type j\nPathOver B idp u v = (u == v)\n\ninfix 30 PathOver\nsyntax PathOver B p u v =\n u == v [ B ↓ p ]\n\nap : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y : A}\n → (x == y → f x == f y)\nap f idp = idp\n\napd : ∀ {i j} {A : Type i} {B : A → Type j} (f : (a : A) → B a) {x y : A}\n → (p : x == y) → f x == f y [ B ↓ p ]\napd f idp = idp\n\ntransport : ∀ {i j} {A : Type i} (B : A → Type j) {x y : A} (p : x == y)\n → (B x → B y)\ntransport B idp u = u\n\ninfixr 60 _,_\n\nrecord Σ {i j} (A : Type i) (B : A → Type j) : Type (lmax i j) where\n constructor _,_\n field\n fst : A\n snd : B fst\nopen Σ public\n\n_×_ : ∀ {i j} (A : Type i) (B : Type j) → Type (lmax i j)\nA × B = Σ A (λ _ → B)\n\ndata ℕ : Type lzero where\n O : ℕ\n S : (n : ℕ) → ℕ\n\nNat = ℕ\n\n{-# BUILTIN NATURAL ℕ #-}\n\ninfixr 80 _∘_\n\n_∘_ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → (B a → Type k)}\n → (g : {a : A} → (x : B a) → (C a x)) → (f : (x : A) → B x) → (x : A) → C x (f x)\ng ∘ f = λ x → g (f x)\n\nuncurry : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (x : A) → B x → Type k}\n → (∀ x y → C x y) → (∀ s → C (fst s) (snd s))\nuncurry f (x , y) = f x y\n\nrecord FromNat {i} (A : Type i) : Type (lsucc i) where\n field\n in-range : ℕ → Type i\n read : ∀ n → ⦃ _ : in-range n ⦄ → A\n\nopen FromNat ⦃...⦄ public using () renaming (read to from-nat)\n\n{-# BUILTIN FROMNAT from-nat #-}\n\nrecord ⊤ : Type lzero where\n instance constructor unit\n\nUnit = ⊤\n\ninstance\n ℕ-reader : FromNat ℕ\n FromNat.in-range ℕ-reader _ = ⊤\n FromNat.read ℕ-reader n = n\n\n! : ∀ {i} {A : Type i} {x y : A} → x == y → y == x\n! idp = idp\n\ndata Square {i} {A : Type i} {a₀₀ : A} : {a₀₁ a₁₀ a₁₁ : A}\n → a₀₀ == a₀₁ → a₀₀ == a₁₀ → a₀₁ == a₁₁ → a₁₀ == a₁₁ → Type i\n where\n ids : Square idp idp idp idp\n\nhid-square : ∀ {i} {A : Type i} {a₀₀ a₀₁ : A} {p : a₀₀ == a₀₁}\n → Square p idp idp p\nhid-square {p = idp} = ids\n\nvid-square : ∀ {i} {A : Type i} {a₀₀ a₁₀ : A} {p : a₀₀ == a₁₀}\n → Square idp p p idp\nvid-square {p = idp} = ids\n\nap-square : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)\n {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n → Square p₀₋ p₋₀ p₋₁ p₁₋\n → Square (ap f p₀₋) (ap f p₋₀) (ap f p₋₁) (ap f p₁₋)\nap-square f ids = ids\n\nSquareOver : ∀ {i j} {A : Type i} (B : A → Type j) {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n (sq : Square p₀₋ p₋₀ p₋₁ p₁₋)\n {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}\n (q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]) (q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ])\n (q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]) (q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ])\n → Type j\nSquareOver B ids = Square\n\napd-square : ∀ {i j} {A : Type i} {B : A → Type j} (f : (x : A) → B x)\n {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n (sq : Square p₀₋ p₋₀ p₋₁ p₁₋)\n → SquareOver B sq (apd f p₀₋) (apd f p₋₀) (apd f p₋₁) (apd f p₁₋)\napd-square f ids = ids\n\nsquare-symmetry : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n → Square p₀₋ p₋₀ p₋₁ p₁₋ → Square p₋₀ p₀₋ p₁₋ p₋₁\nsquare-symmetry ids = ids\n\nmodule _ {i j k} {A : Type i} {B : Type j} (C : B → Type k) (f : A → B) where\n\n ↓-ap-in : {x y : A} {p : x == y} {u : C (f x)} {v : C (f y)}\n → u == v [ C ∘ f ↓ p ]\n → u == v [ C ↓ ap f p ]\n ↓-ap-in {p = idp} idp = idp\n\n-- We postulate function extensionality\n\nmodule _ {i j} {A : Type i} {P : A → Type j} {f g : (x : A) → P x} where\n\n app= : (p : f == g) (x : A) → f x == g x\n app= p x = ap (λ u → u x) p\n\n postulate\n λ= : (h : (x : A) → f x == g x) → f == g\n app=-β : (h : (x : A) → f x == g x) (x : A) → app= (λ= h) x == h x\n\nap-∘ : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} (g : B → C) (f : A → B)\n {x y : A} (p : x == y) → ap (g ∘ f) p == ap g (ap f p)\nap-∘ f g idp = idp\n\nap-cst : ∀ {i j} {A : Type i} {B : Type j} (b : B) {x y : A} (p : x == y)\n → ap (λ _ → b) p == idp\nap-cst b idp = idp\n\nap-idf : ∀ {i} {A : Type i} {u v : A} (p : u == v) → ap (λ x → x) p == p\nap-idf idp = idp\n\nmodule _ {i j} {A : Type i} {B : Type j} (f : A → B) where\n\n ap-! : {x y : A} (p : x == y)\n → ap f (! p) == ! (ap f p)\n ap-! idp = idp\n\nmodule _ {i j} {A : Type i} {B : Type j} where\n\n ↓-cst-in : {x y : A} {p : x == y} {u v : B}\n → u == v\n → u == v [ (λ _ → B) ↓ p ]\n ↓-cst-in {p = idp} q = q\n\n{- Used for defining the recursor from the eliminator for 1-HIT -}\napd=cst-in : ∀ {i j} {A : Type i} {B : Type j} {f : A → B}\n {a a' : A} {p : a == a'} {q : f a == f a'}\n → apd f p == ↓-cst-in q → ap f p == q\napd=cst-in {p = idp} x = x\n\ndata Cube {i} {A : Type i} {a₀₀₀ : A} :\n {a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}\n {p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}\n {p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}\n (sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀) -- left\n\n {p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}\n {p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}\n (sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁) -- right\n\n {p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}\n {p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}\n (sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁) -- back\n (sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁) -- top\n (sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁) -- bottom\n (sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁) -- front\n → Type i\n\n where\n idc : Cube ids ids ids ids ids ids\n\nap-cube : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)\n {a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}\n {p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}\n {p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}\n {sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left\n\n {p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}\n {p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}\n {sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- right\n\n {p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}\n {p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}\n {sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back\n {sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁} -- top\n {sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁} -- bottom\n {sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front\n → Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋\n → Cube (ap-square f sq₋₋₀) (ap-square f sq₋₋₁) (ap-square f sq₀₋₋)\n (ap-square f sq₋₀₋) (ap-square f sq₋₁₋) (ap-square f sq₁₋₋)\nap-cube f idc = idc\n", "meta": {"hexsha": "3e54989c09bb0f652bd00d9188d7d4ab14e53037", "size": 7093, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Base.agda", "max_stars_repo_name": "guillaumebrunerie/JamesConstruction", "max_stars_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2016-12-07T04:34:52.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-16T22:10:16.000Z", "max_issues_repo_path": "Base.agda", "max_issues_repo_name": "guillaumebrunerie/JamesConstruction", "max_issues_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b", "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": "Base.agda", "max_forks_repo_name": "guillaumebrunerie/JamesConstruction", "max_forks_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b", "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": 29.8025210084, "max_line_length": 87, "alphanum_fraction": 0.4858311011, "num_tokens": 3790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.6442251133170357, "lm_q1q2_score": 0.3890680448329456}} {"text": "module Silica where\n open import Agda.Builtin.Bool public\n open import Data.Bool using (true; false) public\n open import Prelude public\n open import Data.Nat public\n open import Data.List public\n open import Data.Nat.Properties public\n open import Relation.Nullary using (¬_; Dec; yes; no) public\n open import Relation.Binary using (module StrictTotalOrder; DecSetoid; IsDecEquivalence) public\n open import Data.Maybe using (just) public\n import Relation.Binary.PropositionalEquality as Eq\n import Relation.Binary.Core\n import Relation.Binary.HeterogeneousEquality\n open Eq using (_≡_; _≢_; refl; cong; sym) public\n open Eq.≡-Reasoning public\n open import Data.Product using (_×_; proj₁; proj₂; ∃-syntax; ∃) renaming (_,_ to ⟨_,_⟩) public\n import Context\n open import Data.List.Membership.DecSetoid ≡-decSetoid\n import Data.List.Membership.DecSetoid\n import Data.List.Relation.Binary.Subset.Setoid using (_⊆_)\n import Data.List.Relation.Binary.Equality.DecPropositional using (_≡?_)\n open import Data.List.Relation.Unary.Any\n open import Data.List.All\n open import Data.Empty\n open import Data.Sum\n open import Level\n\n import Data.Fin\n\n\n -------------- Syntax ------------\n Id : Set\n Id = ℕ\n\n -- State sets\n σ : Set\n σ = List ℕ\n\n -- List of ℕ subset\n _⊆_ : σ → σ → Set\n _⊆_ = Data.List.Relation.Binary.Subset.Setoid._⊆_ (DecSetoid.setoid ≡-decSetoid)\n\n -- List of ℕ decidable equality\n _≟l_ : Relation.Binary.Core.Decidable {A = σ} _≡_\n _≟l_ = Data.List.Relation.Binary.Equality.DecPropositional._≡?_ _≟_\n \n\n data Perm : Set where\n Owned : Perm\n Unowned : Perm\n Shared : Perm\n S : σ → Perm\n\n record Tc : Set where\n constructor tc\n field\n contractName : Id\n perm : Perm\n\n data Tbase : Set where\n Void : Tbase\n Boolean : Tbase\n\n data Type : Set where\n base : Tbase -> Type\n contractType : Tc -> Type\n\n SInjective : (l₁ l₂ : σ)\n → l₁ ≢ l₂\n → S l₁ ≢ S l₂\n SInjective l₁ .l₁ lsEq refl = lsEq refl\n\n TCInjectiveContractName : ∀ {p₁ p₂}\n → (cn₁ cn₂ : Id)\n → cn₁ ≢ cn₂\n → tc cn₁ p₁ ≢ tc cn₂ p₂\n TCInjectiveContractName cn₁ cn₂ nEq refl = nEq refl\n\n TCInjectivePermission : ∀ {cn₁ cn₂}\n → (p₁ p₂ : Perm)\n → p₁ ≢ p₂\n → tc cn₁ p₁ ≢ tc cn₂ p₂\n TCInjectivePermission cn₁ cn₂ nEq refl = nEq refl \n\n contractTypeInjective : ∀ {tc₁ tc₂}\n → tc₁ ≢ tc₂\n → contractType tc₁ ≢ contractType tc₂\n\n contractTypeInjective nEq refl = nEq refl\n\n -- Decidable equality for permissions\n infix 4 _≟p_\n _≟p_ : Relation.Binary.Core.Decidable {A = Perm} _≡_\n Owned ≟p Owned = yes refl\n Owned ≟p Unowned = no (λ ())\n Owned ≟p Shared = no (λ ())\n Owned ≟p S x = no (λ ())\n Unowned ≟p Owned = no (λ ())\n Unowned ≟p Unowned = yes refl\n Unowned ≟p Shared = no (λ ())\n Unowned ≟p S x = no (λ ())\n Shared ≟p Owned = no (λ ())\n Shared ≟p Unowned = no (λ ())\n Shared ≟p Shared = yes refl\n Shared ≟p S x = no (λ ())\n S x ≟p Owned = no (λ ())\n S x ≟p Unowned = no (λ ())\n S x ≟p Shared = no (λ ())\n S s1 ≟p S s2 with s1 ≟l s2\n ... | yes eq = yes (Eq.cong S eq)\n ... | no nEq = no λ sEq → SInjective s1 s2 nEq sEq \n\n -- Decidable equality for types\n infix 4 _≟t_\n _≟t_ : Relation.Binary.Core.Decidable {A = Type} _≡_\n base Void ≟t base Void = yes refl\n base Void ≟t base Boolean = no (λ ())\n base Boolean ≟t base Void = no (λ ())\n base Boolean ≟t base Boolean = yes refl\n base x ≟t contractType x₁ = no (λ ())\n contractType x ≟t base x₁ = no (λ ())\n contractType (tc contractName p₁) ≟t contractType (tc contractName₁ p₂) with contractName ≟ contractName₁ | p₁ ≟p p₂\n ... | yes eqNames | yes eqPerms = yes (Eq.cong₂ (λ a → λ b → contractType (tc a b)) eqNames eqPerms)\n ... | no nEqNames | _ = no (contractTypeInjective (TCInjectiveContractName contractName contractName₁ nEqNames))\n ... | _ | no nEqPerms = no (contractTypeInjective (TCInjectivePermission p₁ p₂ nEqPerms))\n\n ≟tIsEquivalence : Relation.Binary.IsEquivalence {A = Type} _≡_ -- _≟t_\n ≟tIsEquivalence = Eq.isEquivalence \n\n ≡t-isDecEquivalence : IsDecEquivalence (_≡_ {A = Type})\n ≡t-isDecEquivalence = record\n { isEquivalence = ≟tIsEquivalence\n ; _≟_ = _≟t_\n }\n\n ≡t-decSetoid : DecSetoid 0ℓ 0ℓ\n ≡t-decSetoid = record\n { Carrier = Type\n ; _≈_ = _≡_\n ; isDecEquivalence = ≡t-isDecEquivalence\n }\n\n\n module tDecSetoid = Data.List.Membership.DecSetoid ≡t-decSetoid\n _∈ₜ_ : Type → List Type → Set\n _∈ₜ_ = tDecSetoid._∈_\n\n isShared : Type → Bool\n isShared (contractType (record {contractName = _ ; perm = Shared})) = true\n isShared _ = false\n\n eqContractTypes : ∀ {t₁ : Tc}\n → ∀ {t₂ : Tc}\n → Tc.perm t₁ ≡ Tc.perm t₂\n → Tc.contractName t₁ ≡ Tc.contractName t₂\n → t₁ ≡ t₂\n eqContractTypes {t₁} {t₂} refl refl = refl\n\n record State : Set where\n field\n field₁ : Tc\n field₂ : Tc\n isAsset : Bool\n\n data Targ : Set where\n arg-trans : Tc -> Perm -> Targ\n base : Tbase -> Targ\n\n IndirectRef : Set\n IndirectRef = Id\n\n ObjectRef : Set\n ObjectRef = Id\n\n data SimpleExpr : Set where\n var : Id -> SimpleExpr\n loc : IndirectRef -> SimpleExpr\n\n record Object : Set where\n field\n contractName : Id\n stateName : Id\n x₁ : SimpleExpr\n x₂ : SimpleExpr\n\n data Value : Set where\n boolVal : (b : Bool)\n ------------\n → Value\n\n voidVal : Value \n\n objVal : ∀ (o : ObjectRef)\n --------------\n → Value\n\n data Expr : Set where\n valExpr : Value → Expr\n simpleExpr : SimpleExpr → Expr\n fieldAccess : Id → Expr -- All field accesses are to 'this', so the field name suffices.\n assertₓ : Id → σ → Expr\n assertₗ : IndirectRef → σ → Expr\n new : Id → Id → SimpleExpr → SimpleExpr → Expr -- Contract, state, field values (always two of them).\n -- TODO: add the rest of the expressions\n\n\n objValInjective : ∀ {o o'}\n → o ≢ o'\n → objVal o ≢ objVal o'\n objValInjective {o} {.o} oNeqo' refl = oNeqo' refl\n\n objValInjectiveContrapositive : ∀ {o o'}\n → objVal o ≡ objVal o'\n → o ≡ o'\n objValInjectiveContrapositive {o} {o'} refl = refl \n\n record PublicTransaction : Set where\n constructor publicTransaction\n field\n retType : Type\n name : Id\n argType : Targ\n argName : Id\n initialState : Perm\n finalState : Perm\n expr : Expr\n\n -- TODO: add private transactions\n\n record Contract : Set where\n constructor contract\n field\n isAsset : Bool\n name : Id\n states : List State\n transactions : List PublicTransaction\n\n\n data Program : Set where\n program : List Contract -> Expr -> Program\n\n --============= Utilities ================\n data FreeLocations : Expr → List IndirectRef → Set where\n boolFL : ∀ {b : Bool} → FreeLocations (valExpr (boolVal b)) []\n varFL : ∀ {x : Id} → FreeLocations (simpleExpr (var x)) []\n voidFL : FreeLocations (valExpr voidVal) []\n objValFL : ∀ {o : ObjectRef} → FreeLocations (valExpr (objVal o)) []\n locFL : ∀ (l : IndirectRef) → FreeLocations (simpleExpr (loc l)) [ l ]\n\n freeLocationsOfSimpleExpr : SimpleExpr → List IndirectRef\n freeLocationsOfSimpleExpr (var x) = []\n freeLocationsOfSimpleExpr (loc l) = [ l ]\n \n freeLocations : Expr → List IndirectRef\n freeLocations (valExpr (boolVal b)) = []\n freeLocations (simpleExpr (se)) = freeLocationsOfSimpleExpr se\n freeLocations (valExpr voidVal) = []\n freeLocations (valExpr (objVal o)) = []\n freeLocations (fieldAccess x) = []\n freeLocations (assertₓ x x₁) = []\n freeLocations (assertₗ l x₁) = [ l ]\n freeLocations (new _ _ f₁ f₂) = (freeLocationsOfSimpleExpr f₁) ++ (freeLocationsOfSimpleExpr f₂)\n\n\n\n data FreeVariables : Expr → List Id → Set where\n boolFL : ∀ {b : Bool} → FreeVariables (valExpr (boolVal b)) []\n varFL : ∀ {x : Id} → FreeVariables (simpleExpr (var x)) [ x ]\n voidFL : FreeVariables (valExpr voidVal) []\n objValFL : ∀ {o : ObjectRef} → FreeVariables (valExpr (objVal o)) []\n locFL : ∀ (l : IndirectRef) → FreeVariables (simpleExpr (loc l)) []\n\n data Closed : Expr → Set where\n closed : ∀ (e : Expr)\n → FreeVariables e []\n --------------------\n → Closed e\n\n freeVariablesOfSimpleExpr : SimpleExpr → List IndirectRef\n freeVariablesOfSimpleExpr (var x) = [ x ]\n freeVariablesOfSimpleExpr (loc l) = []\n\n freeVariables : Expr → List IndirectRef\n freeVariables (valExpr (boolVal b)) = []\n freeVariables (simpleExpr se) = freeVariablesOfSimpleExpr se\n freeVariables (valExpr voidVal) = []\n freeVariables (valExpr (objVal o)) = []\n freeVariables (fieldAccess x) = []\n freeVariables (assertₓ x x₁) = [ x ]\n freeVariables (assertₗ l x₁) = []\n freeVariables (new _ _ f₁ f₂) = (freeVariablesOfSimpleExpr f₁) ++ (freeVariablesOfSimpleExpr f₂)\n\n --=============== Static Semantics ================\n -- A ContractEnv (written Γ) maps from Ids to contract definitions.\n module ContractEnv = Context Contract\n\n module TypeEnvContext = Context Type\n TypeEnv = TypeEnvContext.ctx\n open TypeEnvContext\n\n record StaticEnv : Set where\n constructor se\n field\n varEnv : TypeEnv\n locEnv : TypeEnv\n objEnv : TypeEnv\n\n _,ₓ_⦂_ : StaticEnv → Id → Type → StaticEnv\n Δ ,ₓ x ⦂ T = record Δ {varEnv = (StaticEnv.varEnv Δ) , x ⦂ T}\n\n _,ₗ_⦂_ : StaticEnv → Id → Type → StaticEnv\n Δ ,ₗ l ⦂ T = record Δ {locEnv = (StaticEnv.locEnv Δ) , l ⦂ T}\n\n _,ₒ_⦂_ : StaticEnv → Id → Type → StaticEnv\n Δ ,ₒ o ⦂ T = record Δ {objEnv = (StaticEnv.objEnv Δ) , o ⦂ T}\n\n\n\n\n -- Subtyping --\n data _<:_ : Type → Type → Set where\n <:-refl : ∀ {T : Type}\n ----------------\n → T <: T\n -- TODO: add more subtyping judgments\n\n -- Helper judgments --\n\n --data _⊢_NotAsset : ContractEnv.ctx → Id → Set where\n data NotAsset : ContractEnv.ctx → Id → Set where\n inContext :\n {Γ : ContractEnv.ctx}\n → {id : Id}\n → (contr : Contract)\n → (p : Contract.isAsset contr ≡ false)\n → (q : (Γ ContractEnv.∋ id ⦂ contr))\n -------------\n → NotAsset Γ id\n\n -- Context strength --\n data _<ₗ_ : TypeEnv → TypeEnv → Set where\n empty< : ∀ { Δ Δ' : TypeEnv}\n → (Δ' ≡ ∅)\n --------------\n → Δ <ₗ Δ'\n\n nonempty< : ∀ {Δ Δ' Δ'' Δ''' : TypeEnv}\n → ∀ {l : ℕ}\n → ∀ {T T' : Type}\n → Δ' ≡ (Δ'' , l ⦂ T')\n → Δ ≡ (Δ''' , l ⦂ T)\n → T <: T'\n → Δ''' <ₗ Δ''\n -------------\n → Δ <ₗ Δ'\n\n data _<*_ : StaticEnv → StaticEnv → Set where\n * : ∀ {Δ Δ'}\n → (StaticEnv.locEnv Δ) <ₗ (StaticEnv.locEnv Δ')\n -----------------------------------------------\n → Δ <* Δ'\n\n <ₗ-refl : ∀ {Δ : TypeEnv}\n → Δ <ₗ Δ\n <ₗ-refl {Context.∅} = empty< refl\n <ₗ-refl {Δ , x ⦂ x₁} = nonempty< refl refl (<:-refl) (<ₗ-refl {Δ})\n\n <*-refl : ∀ {Δ : StaticEnv}\n → Δ <* Δ\n\n <*-refl = * <ₗ-refl\n\n <*-o-extension : ∀ {Δ o T}\n → (Δ ,ₒ o ⦂ T) <* Δ\n <*-o-extension {Δ} {o} {T} = * <ₗ-refl\n\n -- Splitting --\n record SplitType : Set where\n constructor _⇛_/_\n field\n t₁ : Type\n t₂ : Type\n t₃ : Type\n\n infix 4 _⊢_\n data _⊢_ : ContractEnv.ctx -> SplitType -> Set where\n voidSplit : ∀ {Γ : ContractEnv.ctx}\n ---------------\n → Γ ⊢ (base Void) ⇛ (base Void) / (base Void)\n\n booleanSplit : ∀ {Γ : ContractEnv.ctx}\n --------------\n → Γ ⊢ base Boolean ⇛ base Boolean / base Boolean\n\n -- split Unowned off of anything.\n unownedSplit : ∀ {Γ : ContractEnv.ctx}\n → ∀ {t1 t2 t3 : Tc}\n → (Tc.contractName t1) ≡ (Tc.contractName t2)\n → Tc.contractName t1 ≡ Tc.contractName t3\n → (Tc.perm t1) ≡ (Tc.perm t2)\n → Tc.perm t3 ≡ Unowned\n --------------\n → Γ ⊢ contractType t1 ⇛ contractType t2 / contractType t3\n\n shared-shared-shared : ∀ {Γ : ContractEnv.ctx}\n → ∀ {t : Tc}\n → Tc.perm t ≡ Shared\n --------------------------------------------------------\n → Γ ⊢ contractType t ⇛ contractType t / contractType t\n\n owned-shared :\n ∀ {c : Id}\n → ∀ {Γ : ContractEnv.ctx}\n → NotAsset Γ c\n --------------\n → Γ ⊢ contractType (tc c Owned) ⇛ contractType (tc c Shared) / contractType (tc c Shared)\n\n states-shared :\n ∀ {s : σ}\n → ∀ {c : Id}\n → ∀ {Γ : ContractEnv.ctx}\n → NotAsset Γ c\n --------------\n → Γ ⊢ contractType ( record {perm = S s ; contractName = c} ) ⇛ contractType ( record {perm = Shared ; contractName = c} ) / contractType ( record {perm = Shared ; contractName = c} )\n\n splitType : ∀ {Γ : ContractEnv.ctx}\n → ∀ {t1 t2 t3 : Type}\n → Γ ⊢ t1 ⇛ t2 / t3\n → SplitType\n\n splitType voidSplit = (base Void) ⇛ (base Void) / (base Void)\n splitType booleanSplit = base Boolean ⇛ base Boolean / base Boolean\n splitType (unownedSplit {Γ} {t1} {t2} {t3} eqNames1 eqNames2 eqPerms eqUnownedPerm) = contractType t1 ⇛ contractType t2 / contractType t3\n splitType (shared-shared-shared {Γ} {t} _) = contractType t ⇛ contractType t / contractType t\n splitType (owned-shared {c} x) = contractType ( record {perm = Owned ; contractName = c} ) ⇛ contractType ( record {perm = Shared ; contractName = c} ) / contractType ( record {perm = Shared ; contractName = c} )\n splitType (states-shared {s} {c} x) = contractType ( record {perm = S s ; contractName = c} ) ⇛ contractType ( record {perm = Shared ; contractName = c} ) / contractType ( record {perm = Shared ; contractName = c} )\n\n splitTypeCorrect : ∀ {Γ}\n → ∀ {t1 t2 t3 : Type}\n → ∀ (p : Γ ⊢ t1 ⇛ t2 / t3)\n → splitType p ≡ t1 ⇛ t2 / t3\n splitTypeCorrect voidSplit = refl\n splitTypeCorrect booleanSplit = refl\n splitTypeCorrect (unownedSplit x _ _ _) = refl\n splitTypeCorrect (shared-shared-shared _) = refl\n splitTypeCorrect (owned-shared x) = refl\n splitTypeCorrect (states-shared x) = refl\n\n \n\n ------------ Type judgments ----------------\n data _⊢_⦂_⊣_ : StaticEnv → Expr → Type → StaticEnv → Set where\n varTy : ∀ {Γ : ContractEnv.ctx}\n → ∀ {Δ : StaticEnv}\n → ∀ {T₁ T₂ T₃ : Type}\n → ∀ (x : Id)\n → Γ ⊢ T₁ ⇛ T₂ / T₃\n -----------------------------------\n → (Δ ,ₓ x ⦂ T₁) ⊢ (simpleExpr (var x)) ⦂ T₂ ⊣ (Δ ,ₓ x ⦂ T₃)\n\n locTy : ∀ {Γ : ContractEnv.ctx}\n → ∀ {Δ : StaticEnv}\n → ∀ {T₁ T₂ T₃ : Type}\n → ∀ (l : IndirectRef)\n → Γ ⊢ T₁ ⇛ T₂ / T₃\n ------------------------------------\n → (Δ ,ₗ l ⦂ T₁) ⊢ (simpleExpr (loc l)) ⦂ T₂ ⊣ (Δ ,ₗ l ⦂ T₃)\n\n objTy : ∀ {Γ : ContractEnv.ctx}\n → ∀ {Δ : StaticEnv}\n → ∀ {T₁ T₂ T₃ : Type}\n → ∀ (o : ObjectRef)\n → Γ ⊢ T₁ ⇛ T₂ / T₃\n ------------------------------------\n → (Δ ,ₒ o ⦂ T₁) ⊢ (valExpr (objVal o)) ⦂ T₂ ⊣ (Δ ,ₒ o ⦂ T₃)\n\n boolTy : ∀ {Γ : ContractEnv.ctx}\n → ∀ {Δ : StaticEnv}\n → ∀ (b : Bool)\n ------------------------------------\n → Δ ⊢ (valExpr (boolVal b)) ⦂ (base Boolean) ⊣ Δ\n\n voidTy : ∀ {Γ : ContractEnv.ctx}\n → ∀ {Δ : StaticEnv}\n --------------------\n → Δ ⊢ (valExpr voidVal) ⦂ base Void ⊣ Δ\n\n\n assertTyₓ : ∀ {Γ : ContractEnv.ctx}\n → ∀ {Δ : StaticEnv}\n → ∀ {s₁ s₂ : σ}\n → ∀ {tc : Tc}\n → ∀ {x : Id}\n → Tc.perm tc ≡ S s₁\n → s₁ ⊆ s₂\n --------------------------\n → (Δ ,ₓ x ⦂ (contractType tc)) ⊢ assertₓ x s₁ ⦂ base Void ⊣ (Δ ,ₓ x ⦂ (contractType tc))\n\n assertTyₗ : ∀ {Γ : ContractEnv.ctx}\n → ∀ {Δ : StaticEnv}\n → ∀ {s₁ s₂ : σ}\n → ∀ {tc : Tc}\n → ∀ {l : IndirectRef}\n → Tc.perm tc ≡ S s₁\n → s₁ ⊆ s₂\n --------------------------\n → (Δ ,ₗ l ⦂ (contractType tc)) ⊢ assertₗ l s₁ ⦂ base Void ⊣ (Δ ,ₗ l ⦂ (contractType tc))\n\n newTy : ∀ {Γ Δ Δ' Δ''}\n → {states : List State}\n → {C st : Id}\n → {x₁ x₂ : SimpleExpr}\n → {T₁ T₂ Tf₁ Tf₂ : Tc}\n → ∀ {isCAsset isSAsset transactions}\n → (stOK : st < (length states))\n → Δ ⊢ simpleExpr x₁ ⦂ (contractType T₁) ⊣ Δ'\n → Δ' ⊢ simpleExpr x₂ ⦂ (contractType T₂) ⊣ Δ''\n → Γ ContractEnv.∋ C ⦂ (contract isCAsset C states transactions)\n → (Data.List.lookup states (Data.Fin.fromℕ≤ stOK)) ≡ record {field₁ = Tf₁ ; field₂ = Tf₂ ; isAsset = isSAsset}\n --------------------------\n → Δ ⊢ new C st x₁ x₂ ⦂ (contractType (tc C (S [ st ]))) ⊣ Δ''\n \n ------------ DYNAMIC SEMANTICS --------------\n\n -- μ\n module ObjectRefContext = Context Object\n ObjectRefEnv = ObjectRefContext.ctx\n\n -- ρ\n module IndirectRefContext = Context Value -- TODO: require that these are all values\n IndirectRefEnv = IndirectRefContext.ctx\n\n -- φ\n module StateLockingContext = Context Bool\n StateLockingEnv = StateLockingContext.ctx\n\n -- ψ\n module ReentrancyContext = Context Bool\n ReentrancyEnv = ReentrancyContext.ctx\n\n\n record RuntimeEnv : Set where\n constructor re\n field\n μ : ObjectRefEnv\n ρ : IndirectRefEnv\n φ : StateLockingEnv\n ψ : ReentrancyEnv\n\n\n ----------- Reduction Rules ------------\n data _,_⟶_,_ : RuntimeEnv → Expr → RuntimeEnv → Expr → Set where\n SElookup : -- of locations (i.e. let-bound variables)\n ∀ {Σ : RuntimeEnv}\n → ∀ {Δ Δ' : StaticEnv}\n → ∀ {T : Type}\n → ∀ {l : IndirectRef}\n → ∀ {v : Value}\n → Δ ⊢ (simpleExpr (loc l)) ⦂ T ⊣ Δ'\n → RuntimeEnv.ρ Σ IndirectRefContext.∋ l ⦂ v\n -----------------------------------------------------------\n → (Σ , (simpleExpr (loc l)) ⟶ Σ , valExpr v)\n\n SEassertₓ :\n ∀ {Σ : RuntimeEnv}\n → ∀ (x : Id)\n → ∀ (s : σ)\n --------------\n → (Σ , assertₓ x s ⟶ Σ , valExpr voidVal)\n\n SEassertₗ :\n ∀ {Σ : RuntimeEnv}\n → ∀ (l : IndirectRef)\n → ∀ (s : σ)\n --------------\n → (Σ , assertₗ l s ⟶ Σ , valExpr voidVal)\n\n SEnew :\n ∀ {Σ μ' Σ' C st x₁ x₂ o}\n → o ObjectRefContext.∉dom (RuntimeEnv.μ Σ)\n → μ' ≡ (RuntimeEnv.μ Σ) ObjectRefContext., o ⦂ record { contractName = C ; stateName = st ; x₁ = x₁ ; x₂ = x₂ }\n → Σ' ≡ record Σ {μ = μ'}\n -------------\n → (Σ , new C st x₁ x₂ ⟶ Σ' , valExpr (objVal o))\n", "meta": {"hexsha": "4ed3de585ac35d4362ebbba301bc024ba4e1bfa7", "size": 18837, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "formalization/silica.agda", "max_stars_repo_name": "ivoysey/Obsidian", "max_stars_repo_head_hexsha": "bda0fac3aadfbce2eacdb89095d100125fa4fdd6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 79, "max_stars_repo_stars_event_min_datetime": "2017-08-19T16:24:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T10:34:28.000Z", "max_issues_repo_path": "formalization/silica.agda", "max_issues_repo_name": "ivoysey/Obsidian", "max_issues_repo_head_hexsha": "bda0fac3aadfbce2eacdb89095d100125fa4fdd6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 259, "max_issues_repo_issues_event_min_datetime": "2017-08-18T19:50:41.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T18:20:05.000Z", "max_forks_repo_path": "formalization/silica.agda", "max_forks_repo_name": "ivoysey/Obsidian", "max_forks_repo_head_hexsha": "bda0fac3aadfbce2eacdb89095d100125fa4fdd6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2018-05-24T08:20:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-09T18:40:19.000Z", "avg_line_length": 32.2, "max_line_length": 218, "alphanum_fraction": 0.5345861868, "num_tokens": 5967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.3889367012438587}} {"text": "{-# OPTIONS --without-K #-}\n\n{- This module serves to develop some basic theory about pointed types.\n After defining the usual notions of pointed types, pointed equivalences,\n and loop spaces, we derive a version of univalence for pointed equivalences\n and observe that univalence between identical types is a pointed equivalence.\n\n We define pointed versions of dependent sums and products using the usual\n notion of pointed families and observe that they commute in a certain sense\n with taking loop spaces.\n\n We finish by deriving a generalization to n-truncation and n-th loop spaces\n of the fact allowing us to 'forget' contractible components in a dependent\n sum type that will be needed in the Hierarchy module. -}\nmodule Universe.Utility.Pointed where\n\nopen import lib.Basics\nopen import lib.NType2\nopen import lib.types.Nat hiding (_+_)\nopen import lib.types.Pi\nopen import lib.types.Sigma\nopen import lib.types.TLevel\n\nopen import Universe.Utility.General\nopen import Universe.Utility.TruncUniverse\n\n\n{- Pointed types.\n A pointed type is a type (base) together with a chosen element (pt).\n The loop space construction Ω takes a pointed type and returns the type\n of all loops at the given basepoint. The trivial loop is taken as\n canonical element, thus forming a new pointed type. -}\nType• : (i : ULevel) → Type (lsucc i)\nType• i = Σ (Type i) (idf _)\n\nmodule _ {i} (X : Type• i) where\n base = fst X\n pt = snd X\n\n-- Alternate definition: Σ (n -Type i) ⟦_⟧\n_-Type•_ : (n : ℕ₋₂) (i : ULevel) → Type (lsucc i)\nn -Type• i = Σ (Type• i) (has-level n ∘ base)\n\n-- For alternate definition: Σ-≤ (n -Type-≤ i) raise\n_-Type•-≤_ : (n : ℕ₋₂) (i : ULevel) → S n -Type lsucc i\nn -Type•-≤ i = (n -Type• i\n , equiv-preserves-level Σ-comm-snd\n (snd (Σ-≤ (n -Type-≤ i) raise)))\n\n{- Pointed equivalences.\n An equivalence of pointed types is an equivalences of the bases\n that preserves the points -}\n_≃•_ : ∀ {i j} → Type• i → Type• j → Set (i ⊔ j)\nA ≃• B = Σ (base A ≃ base B) (λ f → –> f (pt A) == pt B)\n\nide• : ∀ {i} (X : Type• i) → X ≃• X\nide• _ = ide _ , idp\n\n_∘e•_ : ∀ {i j k} {X : Type• i} {Y : Type• j} {Z : Type• k}\n → Y ≃• Z → X ≃• Y → X ≃• Z\n(u , p) ∘e• (v , q) = (u ∘e v , ap (–> u) q ∙ p)\n\n_⁻¹• : ∀ {i j} {X : Type• i} {Y : Type• j} → X ≃• Y → Y ≃• X\n(u , p) ⁻¹• = (u ⁻¹ , ap (<– u) (! p) ‌∙ <–-inv-l u _)\n\n-- Equational reasoning for pointed equivalences.\ninfix 2 _≃•∎\ninfixr 2 _≃•⟨_⟩_\n\n_≃•⟨_⟩_ : ∀ {i j k} (X : Type• i) {Y : Type• j} {Z : Type• k}\n → X ≃• Y → Y ≃• Z → X ≃• Z\n_ ≃•⟨ u ⟩ v = v ∘e• u\n\n_≃•∎ : ∀ {i} (X : Type• i) → X ≃• X\n_≃•∎ = ide•\n\n\n-- The loop space construction.\nΩ : ∀ {i} → Type• i → Type• i\nΩ (A , a) = (a == a , idp)\n\nΩ-≤ : ∀ {i} {n : ℕ₋₂} → (S n) -Type• i → n -Type• i\nΩ-≤ ((A , a) , t) = (Ω (A , a) , t a a)\n\n-- Loop spaces are preserved by pointed equivalences.\nequiv-Ω : ∀ {i j} {X : Type• i} {Y : Type• j} → X ≃• Y → Ω X ≃• Ω Y\nequiv-Ω (u , p) = split u p where\n split : ∀ u {a} {b} → –> u a == b → Ω (_ , a) ≃• Ω (_ , b)\n split u idp = (equiv-ap u _ _ , idp)\n\nequiv-Ω^ : ∀ {i j} {X : Type• i} {Y : Type• j} (n : ℕ)\n → X ≃• Y → (Ω ^ n) X ≃• (Ω ^ n) Y\nequiv-Ω^ 0 e = e\nequiv-Ω^ (S n) e = equiv-Ω^ n (equiv-Ω e)\n\n\n{- We call a pointed type n-truncated if its base is.\n Constructing the loop space decrements the truncation level. -}\nhas-level• : ∀ {i} → ℕ₋₂ → Type• i → Type i\nhas-level• n = has-level n ∘ base\n\ntrunc-many : ∀ {i} {X : Type• i} {k : ℕ} (n : ℕ)\n → has-level• (k + n -2) X\n → has-level• (k -2) ((Ω ^ n) X)\ntrunc-many 0 t = t\ntrunc-many (S n) t = trunc-many n (t _ _)\n\n--Ω^-≤ : ∀ {i} {k : ℕ} (n : ℕ) → (k + n -2) -Type• i → (k -2) -Type• i\n--Ω^-≤ O X = X\n--Ω^-≤ (S n) X = Ω^-≤ n (Ω-≤ X)\n\nΩ^-≤ : ∀ {i} {k : ℕ} (n : ℕ) → (k + n -2) -Type• i → (k -2) -Type• i\nΩ^-≤ n (X , t) = ((Ω ^ n) X , trunc-many n t)\n\nΩ^-≤' : ∀ {i} {k : ℕ} (n : ℕ) → (n + k -2) -Type• i → (k -2) -Type• i\nΩ^-≤' n (X , t) =\n ((Ω ^ n) X , trunc-many n (transport (λ z → has-level• (z -2) X)\n (+-comm _ n) t))\n\n\n{- Pointedness allows for a more direct notion of contractibility.\n Beware that is-contr• will be equivalent --- not definitionally equal ---\n to has-level∙ ⟨-2⟩. -}\nmodule _ {i} (X : Type• i) where\n is-contr• : Type i\n is-contr• = ∀ a → pt X == a\n\n{- Since pointed types are always inhabited,\n being contractible and propositional is equivalent. -}\nmodule _ {i} {X : Type• i} where\n contr•-equiv-contr : is-contr• X ≃ is-contr (base X)\n contr•-equiv-contr = prop-equiv'\n (λ c → Π-level (λ a → raise-level- f (pt A) == pt B)\n ≃⟨ equiv-Σ-fst _ (snd (ua-equiv ⁻¹)) ⁻¹ ⟩\n Σ (base A == base B) (λ q → coe q (pt A) == pt B)\n ≃⟨ equiv-Σ-snd (λ q → coe-equiv (ap (λ f → coe f (pt A) == pt B)\n (! (ap-idf q)))) ⟩\n Σ (base A == base B) (λ q → coe (ap (idf _) q) (pt A) == pt B)\n ≃⟨ equiv-Σ-snd (λ q → to-transp-equiv _ q ⁻¹) ⟩\n Σ (base A == base B) (λ q → pt A == pt B [ idf _ ↓ q ])\n ≃⟨ =Σ-eqv _ _ ⟩\n A == B\n ≃∎\n\n ua• : A ≃• B → A == B\n ua• = –> ua•-equiv\n\n coe•-equiv : A == B → A ≃• B\n coe•-equiv = <– ua•-equiv\n\n-- Normal univalence can be made pointed in the endo-setting.\nmodule _ {i} {A : Type i} where\n ua-equiv• : (A ≃ A , ide _) ≃• (A == A , idp)\n ua-equiv• = ((ua-equiv ⁻¹) , idp) ⁻¹•\n\n\n-- *** Definition 4.1 ***\n{- Pointed families.\n A pointed family over a pointed type is a family over the base\n together with a inhabitant of the family at the point.\n Note that pointed types are equivalent to pointed families\n over the pointed unit type (not shown here). -}\nFam• : ∀ {i} (X : Type• i) (j : ULevel) → Type (i ⊔ lsucc j)\nFam• X j = Σ (base X → Type j) (λ P → P (pt X))\n\n-- We have fibered notions of the loop space contruction and n-truncatedness.\nmodule _ {i} {X : Type• i} {j} where\n -- *** Definition 4.3 ***\n {- Note that the definition of the family of path types differs slightly from\n that of the article, which would correspond to transport P p x == x.\n We use dependent paths since this follows the design of the HoTT\n community's Agda library. Clearly, both types are equivalent. -}\n Ω̃ : Fam• X j → Fam• (Ω X) j\n Ω̃ (P , x) = ((λ p → x == x [ P ↓ p ]) , idp)\n\n fam-has-level : ℕ₋₂ → Fam• X j → Type (i ⊔ j)\n fam-has-level n Q = (a : base X) → has-level n (fst Q a)\n\n\n{- == Pointed dependent sums ==\n Pointed families as defined above enable us to introduce a Σ-connective\n for pointed types. Because of the abstract nature of some of our lemmata, we\n give Σ• in its uncurried form and first define the type of its parameter. -}\nΣ•-param : ∀ i j → Type (lsucc (i ⊔ j))\nΣ•-param i j = Σ (Type• i) (λ X → Fam• X j)\n\nmodule _ {i j} where\n Ω-Σ•-param : Σ•-param i j → Σ•-param i j\n Ω-Σ•-param (X , W) = (Ω X , Ω̃ W)\n\n -- *** Definition 4.4 ***\n Σ• : Σ•-param i j → Type• (i ⊔ j)\n Σ• (X , Q) = (Σ (base X) (fst Q) , (pt X , snd Q))\n \n -- *** Lemma 4.5 ***\n {- Commutativity of pointed dependent sums and the loop space construction\n will become an important technical tool, enabling us to work at a more\n abstract level later on. -}\n Ω-Σ•-comm : (R : Σ•-param i j) → Ω (Σ• R) ≃• Σ• (Ω-Σ•-param R)\n Ω-Σ•-comm _ = (=Σ-eqv _ _ , idp) ⁻¹•\n\n\n{- Pointed dependent products.\n This is not quite the equivalent of Π for pointed types: the domain parameter\n is just an ordinary non-pointed type. However, to enable our goal of\n abstractly working with pointed types, defining this notion is useful. -}\nΠ•-param : ∀ i j → Type (lsucc (i ⊔ j))\nΠ•-param i j = Σ (Type i) (λ A → A → Type• j)\n\nmodule _ {i j} where\n Ω-Π•-param : Π•-param i j → Π•-param i j\n Ω-Π•-param (A , F) = (A , Ω ∘ F)\n\n -- *** Definition 4.6 ***\n Π• : Π•-param i j → Type• (i ⊔ j)\n Π• (A , Y) = (Π A (base ∘ Y) , pt ∘ Y)\n\n -- *** Lemma 4.7 ***\n {- Pointed dependent products and loop space construction on\n its codomain parameter commute as well. -}\n Ω-Π•-comm : (R : Π•-param i j) → Ω (Π• R) ≃• Π• (Ω-Π•-param R)\n Ω-Π•-comm _ = (app=-equiv , idp)\n\n Ω^-Π•-comm : (C : Type i) (F : C → Type• j) (n : ℕ)\n → (Ω ^ n) (Π• (C , F)) ≃• Π• (C , Ω ^ n ∘ F)\n Ω^-Π•-comm C F 0 = ide• _\n Ω^-Π•-comm C F (S n) = Ω^-Π•-comm C _ n ∘e• equiv-Ω^ n (Ω-Π•-comm _)\n\nequiv-Π• : ∀ {i₀ i₁ j₀ j₁} {R₀ : Π•-param i₀ j₀} {R₁ : Π•-param i₁ j₁}\n → Σ (fst R₀ ≃ fst R₁) (λ u → ∀ a → snd R₀ (<– u a) ≃• snd R₁ a)\n → Π• R₀ ≃• Π• R₁\nequiv-Π• (u , v) = (equiv-Π u (fst ∘ v) , λ= (snd ∘ v))\n\n\n-- *** Lemma 5.1 ***\n-- In an n-th loop space, we can forget components of truncation level n.\nforget-Ω^-Σ•₂ : ∀ {i j} {X : Type• i} (Q : Fam• X j) (n : ℕ)\n → fam-has-level (n -2) Q → (Ω ^ n) (Σ• (X , Q)) ≃• (Ω ^ n) X\nforget-Ω^-Σ•₂ {X = X} Q O h = (Σ₂-contr h , idp)\nforget-Ω^-Σ•₂ {i} {X = X} Q (S n) h =\n (Ω ^ (S n)) (Σ• (X , Q)) ≃•⟨ equiv-Ω^ n (Ω-Σ•-comm _) ⟩\n (Ω ^ n) (Σ• (Ω X , Ω̃ Q)) ≃•⟨ forget-Ω^-Σ•₂ {i} _ n (λ _ → =-[-↓-]-level h) ⟩\n (Ω ^ (S n)) X ≃•∎\n", "meta": {"hexsha": "d351796aae7bc69d24ac21029e9619860841b70b", "size": 11344, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Universe/Utility/Pointed.agda", "max_stars_repo_name": "sattlerc/HoTT-Agda", "max_stars_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37", "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": "Universe/Utility/Pointed.agda", "max_issues_repo_name": "sattlerc/HoTT-Agda", "max_issues_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37", "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": "Universe/Utility/Pointed.agda", "max_forks_repo_name": "sattlerc/HoTT-Agda", "max_forks_repo_head_hexsha": "c8fb8da3354fc9e0c430ac14160161759b4c5b37", "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.1952861953, "max_line_length": 80, "alphanum_fraction": 0.5310296192, "num_tokens": 4433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.737158174177441, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3887156855880776}} {"text": "{-# OPTIONS --rewriting --without-K #-}\n\nopen import Agda.Primitive\nopen import Prelude\nimport GSeTT.Rules\nimport GSeTT.Typed-Syntax\nimport Globular-TT.Syntax\nimport Globular-TT.Rules\n\n{- Decidability of type cheking for the type theory for globular sets -}\nmodule Globular-TT.Dec-Type-Checking {l} (index : Set l) (rule : index → GSeTT.Typed-Syntax.Ctx × (Globular-TT.Syntax.Pre-Ty index))\n (assumption : Globular-TT.Rules.well-founded index rule)\n (eqdec-index : eqdec index) where\n open import Globular-TT.Syntax index\n open import Globular-TT.Eqdec-syntax index eqdec-index\n open import Globular-TT.Rules index rule\n open import Globular-TT.CwF-Structure index rule\n\n\n dec-∈ : ∀ (n : ℕ) (A : Pre-Ty) (Γ : Pre-Ctx) → dec (n # A ∈ Γ)\n dec-∈ n A ⊘ = inr λ{()}\n dec-∈ n A (Γ ∙ x # B) with dec-∈ n A Γ\n ... | inl n∈Γ = inl (inl n∈Γ)\n ... | inr n∉Γ with eqdecℕ n x | eqdec-Ty A B\n ... | inl idp | inl idp = inl (inr (idp , idp))\n ... | inr n≠x | _ = inr λ{(inl n∈Γ) → n∉Γ n∈Γ; (inr (idp , idp)) → n≠x idp}\n ... | inl idp | inr A≠B_ = inr λ{(inl n∈Γ) → n∉Γ n∈Γ; (inr (_ , A=B)) → A≠B A=B}\n\n {- Decidability in the fragment of the theory with only globular contexts -}\n -- termination is really tricky, and involves reasonning both on depth and dimension at the same time !\n dec-G⊢T : ∀ (Γ : GSeTT.Typed-Syntax.Ctx) n A → dim A ≤ n → dec (GPre-Ctx (fst Γ) ⊢T A)\n dec-G⊢t : ∀ (Γ : GSeTT.Typed-Syntax.Ctx) n d A t → dim A ≤ n → depth t ≤ d → dec (GPre-Ctx (fst Γ) ⊢t t # A)\n dec-G⊢S : ∀ (Δ Γ : GSeTT.Typed-Syntax.Ctx) n d γ → dimC (GPre-Ctx (fst Γ)) ≤ n → depthS γ ≤ d → dec (GPre-Ctx (fst Δ) ⊢S γ > GPre-Ctx (fst Γ))\n\n dec-G⊢T Γ _ ∗ _ = inl (ob (GCtx _ (snd Γ)))\n dec-G⊢T Γ (S n) (⇒ A t u) (S≤ i) with dec-G⊢T Γ n A i | dec-G⊢t Γ n _ A t i (n≤n _) | dec-G⊢t Γ n _ A u i (n≤n _)\n ... | inl Γ⊢A | inl Γ⊢t:A | inl Γ⊢u:A = inl (ar Γ⊢A Γ⊢t:A Γ⊢u:A)\n ... | inr Γ⊬A | _ | _ = inr λ{(ar Γ⊢A _ _) → Γ⊬A Γ⊢A}\n ... | inl _ | inr Γ⊬t:A | _ = inr λ{(ar _ Γ⊢t:A _) → Γ⊬t:A Γ⊢t:A}\n ... | inl _ | inl _ | inr Γ⊬u:A = inr λ{(ar _ _ Γ⊢u:A) → Γ⊬u:A Γ⊢u:A}\n\n dec-G⊢t Γ n _ A (Var x) _ (0≤ _) with dec-∈ x A (GPre-Ctx (fst Γ))\n ... | inl x∈Γ = inl (var (GCtx _ (snd Γ)) x∈Γ)\n ... | inr x∉Γ = inr λ {(var _ x∈Γ) → x∉Γ x∈Γ}\n dec-G⊢t Γ n (S d) A (Tm-constructor i γ) dimA≤n (S≤ dγ≤d) with eqdec-Ty A (Ti i [ γ ]Pre-Ty )\n ... | inr A≠Ti = inr λ{(tm _ _ idp) → A≠Ti idp}\n ... | inl idp\n with dec-G⊢T (fst (rule i)) n (Ti i) (=-≤ (dim[] _ _ ^) dimA≤n)\n ... | inr Ci⊬Ti = inr λ t → Ci⊬Ti (Γ⊢tm→Ci⊢Ti t)\n ... | inl Ci⊢Ti with dec-G⊢S Γ (fst (rule i)) n d γ\n (≤T (≤-= (assumption i Ci⊢Ti) (dim[] _ _ ^)) dimA≤n) -- dim Ci ≤ dim A\n dγ≤d -- depth γ ≤ d\n ... | inr Γ⊬γ = inr λ t → Γ⊬γ (Γ⊢tm→Γ⊢γ t)\n ... | inl Γ⊢γ = inl (tm Ci⊢Ti Γ⊢γ idp)\n\n\n dec-G⊢S Δ (nil , _) _ _ <> (0≤ _) _ = inl (es (GCtx _ (snd Δ)))\n dec-G⊢S Δ ((Γ :: _) , _) _ _ <> _ _ = inr λ {()}\n dec-G⊢S Δ (nil , _) _ _ < γ , x ↦ t > _ _ = inr λ {()}\n dec-G⊢S Δ ((Γ :: (y , A)) , Γ+⊢@(GSeTT.Rules.cc Γ⊢ Γ⊢A idp)) n d < γ , x ↦ t > dimΓ+≤n dγ+≤d with dec-G⊢S Δ (Γ , Γ⊢) n d γ\n (≤T (n≤max (dimC (GPre-Ctx Γ)) (dim (GPre-Ty A))) dimΓ+≤n) -- dim Γ ≤ n\n (≤T (n≤max (depthS γ) (depth t)) dγ+≤d) -- depth γ ≤ d\n | dec-G⊢t Δ n d ((GPre-Ty A) [ γ ]Pre-Ty) t\n ((≤T (=-≤ (dim[] _ _) (m≤max (dimC (GPre-Ctx Γ)) (dim (GPre-Ty A)))) dimΓ+≤n)) -- dim A[γ] ≤ n\n (≤T (m≤max (depthS γ) (depth t)) dγ+≤d) -- depth t ≤ d\n | eqdecℕ y x\n ... | inl Δ⊢γ:Γ | inl Δ⊢t | inl idp = inl (sc Δ⊢γ:Γ (GCtx _ Γ+⊢) Δ⊢t idp)\n ... | inr Δ⊬γ:Γ | _ | _ = inr λ {(sc Δ⊢γ:Γ _ _ idp) → Δ⊬γ:Γ Δ⊢γ:Γ}\n ... | inl _ | inr Δ⊬t | _ = inr λ {(sc _ _ Δ⊢t idp) → Δ⊬t Δ⊢t}\n ... | inl _ | inl _ | inr n≠x = inr λ {(sc _ _ _ idp) → n≠x idp}\n\n\n {- Decidability of judgments for contexts, types, terms and substitution towards a glaobular context -}\n dec-⊢C : ∀ Γ → dec (Γ ⊢C)\n dec-⊢T : ∀ Γ A → dec (Γ ⊢T A)\n dec-⊢t : ∀ Γ A t → dec (Γ ⊢t t # A)\n dec-⊢S:G : ∀ Δ (Γ : GSeTT.Typed-Syntax.Ctx) γ → dec (Δ ⊢S γ > GPre-Ctx (fst Γ))\n\n dec-⊢T Γ ∗ with dec-⊢C Γ\n ... | inl Γ⊢ = inl (ob Γ⊢)\n ... | inr Γ⊬ = inr λ {(ob Γ⊢) → Γ⊬ Γ⊢}\n\n dec-⊢T Γ (⇒ A t u) with dec-⊢T Γ A | dec-⊢t Γ A t | dec-⊢t Γ A u\n ... | inl Γ⊢A | inl Γ⊢t:A | inl Γ⊢u:A = inl (ar Γ⊢A Γ⊢t:A Γ⊢u:A)\n ... | inr Γ⊬A | _ | _ = inr λ {(ar Γ⊢A _ _) → Γ⊬A Γ⊢A}\n ... | inl _ | inr Γ⊬t:A | _ = inr λ {(ar _ Γ⊢t:A _) → Γ⊬t:A Γ⊢t:A}\n ... | inl _ | inl _ | inr Γ⊬u:A = inr λ {(ar _ _ Γ⊢u:A) → Γ⊬u:A Γ⊢u:A}\n\n dec-⊢t Γ A (Var x) with dec-⊢C Γ | dec-∈ x A Γ\n ... | inl Γ⊢ | inl x∈Γ = inl (var Γ⊢ x∈Γ)\n ... | inr Γ⊬ | _ = inr λ {(var Γ⊢ _) → Γ⊬ Γ⊢}\n ... | inl _ | inr x∉Γ = inr λ {(var _ x∈Γ) → x∉Γ x∈Γ}\n dec-⊢t Γ A (Tm-constructor i γ) with eqdec-Ty A (Ti i [ γ ]Pre-Ty)\n ... | inr A≠Ti = inr λ{(tm _ _ idp) → A≠Ti idp}\n ... | inl idp\n with dec-G⊢T (fst (rule i)) _ (Ti i) (n≤n _) | dec-⊢S:G Γ (fst (rule i)) γ\n ... | inl Ci⊢Ti | inl Γ⊢γ = inl (tm Ci⊢Ti Γ⊢γ idp)\n ... | inr Ci⊬Ti | _ = inr λ t → Ci⊬Ti (Γ⊢tm→Ci⊢Ti t)\n ... | inl _ | inr Γ⊬γ = inr λ t → Γ⊬γ (Γ⊢tm→Γ⊢γ t)\n\n\n dec-⊢C ⊘ = inl ec\n dec-⊢C (Γ ∙ n # A) with dec-⊢C Γ | dec-⊢T Γ A | eqdecℕ n (C-length Γ)\n ... | inl Γ⊢ | inl Γ⊢A | inl idp = inl (cc Γ⊢ Γ⊢A idp)\n ... | inr Γ⊬ | _ | _ = inr λ {(cc Γ⊢ _ idp) → Γ⊬ Γ⊢}\n ... | inl _ | inr Γ⊬A | _ = inr λ {(cc _ Γ⊢A idp) → Γ⊬A Γ⊢A}\n ... | inl _ | inl _ | inr n≠l = inr λ {(cc _ _ idp) → n≠l idp}\n\n\n dec-⊢S:G Δ (nil , _) <> with (dec-⊢C Δ)\n ... | inl Δ⊢ = inl (es Δ⊢)\n ... | inr Δ⊬ = inr λ{(es Δ⊢) → Δ⊬ Δ⊢}\n dec-⊢S:G Δ (nil , _) < γ , x ↦ x₁ > = inr λ{()}\n dec-⊢S:G Δ ((Γ :: _) , _) <> = inr λ{()}\n dec-⊢S:G Δ ((Γ :: (v , A)) , Γ+⊢@(GSeTT.Rules.cc Γ⊢ Γ⊢A idp)) < γ , x ↦ t > with dec-⊢S:G Δ (Γ , Γ⊢) γ | dec-⊢t Δ ((GPre-Ty A) [ γ ]Pre-Ty) t | eqdecℕ x (length Γ)\n ... | inl Δ⊢γ | inl Δ⊢t | inl idp = inl (sc Δ⊢γ (GCtx _ Γ+⊢) Δ⊢t idp)\n ... | inr Δ⊬γ | _ | _ = inr λ{(sc Δ⊢γ _ _ idp) → Δ⊬γ Δ⊢γ}\n ... | inl _ | inr Δ⊬t | _ = inr λ{(sc _ _ Δ⊢t idp) → Δ⊬t Δ⊢t}\n ... | inl _ | inl _ | inr x≠x = inr λ{(sc _ _ _ idp) → x≠x idp}\n\n\n {- Decidability of substitution -}\n dec-⊢S : ∀ Δ Γ γ → dec (Δ ⊢S γ > Γ)\n dec-⊢S Δ ⊘ <> with (dec-⊢C Δ)\n ... | inl Δ⊢ = inl (es Δ⊢)\n ... | inr Δ⊬ = inr λ{(es Δ⊢) → Δ⊬ Δ⊢}\n dec-⊢S Δ ⊘ < γ , x ↦ x₁ > = inr λ{()}\n dec-⊢S Δ (Γ ∙ _ # _) <> = inr λ{()}\n dec-⊢S Δ (Γ ∙ v # A) < γ , x ↦ t > with dec-⊢S Δ Γ γ | dec-⊢C (Γ ∙ v # A) | dec-⊢t Δ (A [ γ ]Pre-Ty) t | eqdecℕ x v\n ... | inl Δ⊢γ | inl Γ+⊢ | inl Δ⊢t | inl idp = inl (sc Δ⊢γ Γ+⊢ Δ⊢t idp)\n ... | inr Δ⊬γ | _ | _ | _ = inr λ{(sc Δ⊢γ _ _ idp) → Δ⊬γ Δ⊢γ}\n ... | inl _ | inr Γ+⊬ | _ | _ = inr λ{(sc _ Γ⊢ _ idp) → Γ+⊬ Γ⊢}\n ... | inl _ | inl _ | inr Δ⊬t | _ = inr λ{(sc _ _ Δ⊢t idp) → Δ⊬t Δ⊢t}\n ... | inl _ | inl _ | inl _ | inr x≠x = inr λ{(sc _ _ _ idp) → x≠x idp}\n", "meta": {"hexsha": "1ada383eb52dd269dc675f02a3598ba2040b6143", "size": 9475, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Globular-TT/Dec-Type-Checking.agda", "max_stars_repo_name": "thibautbenjamin/catt-formalization", "max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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": "Globular-TT/Dec-Type-Checking.agda", "max_issues_repo_name": "thibautbenjamin/catt-formalization", "max_issues_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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": "Globular-TT/Dec-Type-Checking.agda", "max_forks_repo_name": "thibautbenjamin/catt-formalization", "max_forks_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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": 70.1851851852, "max_line_length": 196, "alphanum_fraction": 0.3448021108, "num_tokens": 3858, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850402140659, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.3886104416264505}} {"text": "{-# OPTIONS --rewriting #-}\n\n-- Syntax\n\nopen import Library\n\nmodule Derivations (Base : Set) where\n\nimport Formulas; private open module Form = Formulas Base\n-- open import Formulas Base public\n\n-- Derivations\n\ninfix 2 _⊢_\n\ndata _⊢_ (Γ : Cxt) : (A : Form) → Set where\n hyp : ∀{A} (x : Hyp A Γ) → Γ ⊢ A\n impI : ∀{A B} (t : Γ ∙ A ⊢ B) → Γ ⊢ A ⇒ B\n impE : ∀{A B} (t : Γ ⊢ A ⇒ B) (u : Γ ⊢ A) → Γ ⊢ B\n andI : ∀{A B} (t : Γ ⊢ A) (u : Γ ⊢ B) → Γ ⊢ A ∧ B\n andE₁ : ∀{A B} (t : Γ ⊢ A ∧ B) → Γ ⊢ A\n andE₂ : ∀{A B} (t : Γ ⊢ A ∧ B) → Γ ⊢ B\n orI₁ : ∀{A B} (t : Γ ⊢ A) → Γ ⊢ A ∨ B\n orI₂ : ∀{A B} (t : Γ ⊢ B) → Γ ⊢ A ∨ B\n orE : ∀{A B C} (t : Γ ⊢ A ∨ B) (u : Γ ∙ A ⊢ C) (v : Γ ∙ B ⊢ C) → Γ ⊢ C\n falseE : ∀{C} (t : Γ ⊢ False) → Γ ⊢ C\n trueI : Γ ⊢ True\n\n-- Example derivation\n\nandComm : ∀{A B} → ε ⊢ A ∧ B ⇒ B ∧ A\nandComm = impI (andI (andE₂ (hyp top)) (andE₁ (hyp top)))\n\n-- Weakening\n\nTm = λ A Γ → Γ ⊢ A\n\nmonD : ∀{A} → Mon (Tm A)\nmonD τ (hyp x) = hyp (monH τ x)\nmonD τ (impI t) = impI (monD (lift τ) t)\nmonD τ (impE t u) = impE (monD τ t) (monD τ u)\nmonD τ (andI t u) = andI (monD τ t) (monD τ u)\nmonD τ (andE₁ t) = andE₁ (monD τ t)\nmonD τ (andE₂ t) = andE₂ (monD τ t)\nmonD τ (orI₁ t) = orI₁ (monD τ t)\nmonD τ (orI₂ t) = orI₂ (monD τ t)\nmonD τ (orE t u v) = orE (monD τ t) (monD (lift τ) u) (monD (lift τ) v)\nmonD τ (falseE t) = falseE (monD τ t)\nmonD τ trueI = trueI\n\nmonD-id : ∀{Γ A} (t : Γ ⊢ A) → monD id≤ t ≡ t\nmonD-id (hyp x) = refl\nmonD-id (impI t) = cong impI (monD-id t) -- REWRITE lift-id≤\nmonD-id (impE t u) = cong₂ impE (monD-id t) (monD-id u)\nmonD-id (andI t u) = cong₂ andI (monD-id t) (monD-id u)\nmonD-id (andE₁ t) = cong andE₁ (monD-id t)\nmonD-id (andE₂ t) = cong andE₂ (monD-id t)\nmonD-id (orI₁ t) = cong orI₁ (monD-id t)\nmonD-id (orI₂ t) = cong orI₂ (monD-id t)\nmonD-id (orE t u v) = cong₃ orE (monD-id t) (monD-id u) (monD-id v)\nmonD-id (falseE t) = cong falseE (monD-id t)\nmonD-id trueI = refl\n\n-- For normal forms, we use the standard presentation.\n-- Normal forms are not unique.\n\n-- Normality as predicate\n\nmutual\n data Neutral {Γ} {A} : (t : Γ ⊢ A) → Set where\n hyp : (x : Hyp A Γ) → Neutral (hyp x)\n impE : ∀{B} {t : Γ ⊢ B ⇒ A} {u : Γ ⊢ B} (ne : Neutral t) (nf : Normal u) → Neutral (impE t u)\n andE₁ : ∀{B} {t : Γ ⊢ A ∧ B} (ne : Neutral t) → Neutral (andE₁ t)\n andE₂ : ∀{B} {t : Γ ⊢ B ∧ A} (ne : Neutral t) → Neutral (andE₂ t)\n\n data Normal {Γ} : ∀{A} (t : Γ ⊢ A) → Set where\n ne : ∀{A} {t : Γ ⊢ A} (ne : Neutral t) → Normal t\n impI : ∀{A B} (t : Γ ∙ A ⊢ B) (nf : Normal t) → Normal (impI t)\n andI : ∀{A B} (t : Γ ⊢ A) (u : Γ ⊢ B) (nf₁ : Normal t) (nf₂ : Normal u) → Normal (andI t u)\n orI₁ : ∀{A B} {t : Γ ⊢ A} (nf : Normal t) → Normal (orI₁ {Γ} {A} {B} t)\n orI₂ : ∀{A B} {t : Γ ⊢ B} (nf : Normal t) → Normal (orI₂ {Γ} {A} {B} t)\n orE : ∀{A B C} {t : Γ ⊢ A ∨ B} {u : Γ ∙ A ⊢ C} {v : Γ ∙ B ⊢ C}\n (ne : Neutral t) (nf₁ : Normal u) (nf₂ : Normal v) → Normal (orE t u v)\n falseE : ∀{A} {t : Γ ⊢ False} (ne : Neutral t) → Normal (falseE {Γ} {A} t)\n trueI : Normal trueI\n\n-- Intrinsic normality\n\nmutual\n data Ne (Γ : Cxt) (A : Form) : Set where\n hyp : ∀ (x : Hyp A Γ) → Ne Γ A\n impE : ∀{B} (t : Ne Γ (B ⇒ A)) (u : Nf Γ B) → Ne Γ A\n andE₁ : ∀{B} (t : Ne Γ (A ∧ B)) → Ne Γ A\n andE₂ : ∀{B} (t : Ne Γ (B ∧ A)) → Ne Γ A\n\n data Nf (Γ : Cxt) : (A : Form) → Set where\n -- ne : ∀{A} (t : Ne Γ A) → Nf Γ A -- allows η-short nfs\n ne : ∀{P} (t : Ne Γ (Atom P)) → Nf Γ (Atom P)\n impI : ∀{A B} (t : Nf (Γ ∙ A) B) → Nf Γ (A ⇒ B)\n andI : ∀{A B} (t : Nf Γ A) (u : Nf Γ B) → Nf Γ (A ∧ B)\n orI₁ : ∀{A B} (t : Nf Γ A) → Nf Γ (A ∨ B)\n orI₂ : ∀{A B} (t : Nf Γ B) → Nf Γ (A ∨ B)\n orE : ∀{A B C} (t : Ne Γ (A ∨ B)) (u : Nf (Γ ∙ A) C) (v : Nf (Γ ∙ B) C) → Nf Γ C\n falseE : ∀{A} (t : Ne Γ False) → Nf Γ A\n trueI : Nf Γ True\n\n-- Presheaf-friendly argument order\n\nNe' = λ A Γ → Ne Γ A\nNf' = λ A Γ → Nf Γ A\n\n-- Admissible false-Elimination from a normal proof of false (using case splits)\n\nfalseE! : ∀{A} → Nf' False →̇ Nf' A\n-- falseE! (ne t) = falseE t -- only for η-short\nfalseE! (orE t t₁ t₂) = orE t (falseE! t₁) (falseE! t₂)\nfalseE! (falseE t) = falseE t\n\n-- Ne' and Nf' are presheaves over (Cxt, ≤)\n\nmutual\n\n monNe : ∀{A} → Mon (Ne' A)\n monNe τ (hyp x) = hyp (monH τ x)\n monNe τ (impE t u) = impE (monNe τ t) (monNf τ u)\n monNe τ (andE₁ t) = andE₁ (monNe τ t)\n monNe τ (andE₂ t) = andE₂ (monNe τ t)\n\n monNf : ∀{A} → Mon (Nf' A)\n monNf τ (ne t) = ne (monNe τ t)\n monNf τ (impI t) = impI (monNf (lift τ) t)\n monNf τ (andI t u) = andI (monNf τ t) (monNf τ u)\n monNf τ (orI₁ t) = orI₁ (monNf τ t)\n monNf τ (orI₂ t) = orI₂ (monNf τ t)\n monNf τ (orE t u v) = orE (monNe τ t) (monNf (lift τ) u) (monNf (lift τ) v)\n monNf τ (falseE t) = falseE (monNe τ t)\n monNf τ trueI = trueI\n\n-- Forgetting normality\n\nmutual\n ne[_] : ∀{Γ A} (t : Ne Γ A) → Γ ⊢ A\n ne[ hyp x ] = hyp x\n ne[ impE t u ] = impE ne[ t ] nf[ u ]\n ne[ andE₁ t ] = andE₁ ne[ t ]\n ne[ andE₂ t ] = andE₂ ne[ t ]\n\n nf[_] : ∀{Γ A} (t : Nf Γ A) → Γ ⊢ A\n nf[ ne t ] = ne[ t ]\n nf[ impI t ] = impI nf[ t ]\n nf[ andI t u ] = andI nf[ t ] nf[ u ]\n nf[ orI₁ t ] = orI₁ nf[ t ]\n nf[ orI₂ t ] = orI₂ nf[ t ]\n nf[ orE t u v ] = orE ne[ t ] nf[ u ] nf[ v ]\n nf[ falseE t ] = falseE ne[ t ]\n nf[ trueI ] = trueI\n\nmutual\n\n monD-ne : ∀{Γ Δ A} (τ : Δ ≤ Γ) (t : Ne Γ A) → ne[ monNe τ t ] ≡ monD τ ne[ t ]\n monD-ne τ (hyp x) = refl\n monD-ne τ (impE t u) = cong₂ impE (monD-ne τ t) (monD-nf τ u)\n monD-ne τ (andE₁ t) = cong andE₁ (monD-ne τ t)\n monD-ne τ (andE₂ t) = cong andE₂ (monD-ne τ t)\n\n monD-nf : ∀{Γ Δ A} (τ : Δ ≤ Γ) (t : Nf Γ A) → nf[ monNf τ t ] ≡ monD τ nf[ t ]\n monD-nf τ (ne t) = monD-ne τ t\n monD-nf τ (impI t) = cong impI (monD-nf (lift τ) t)\n monD-nf τ (andI t u) = cong₂ andI (monD-nf τ t) (monD-nf τ u)\n monD-nf τ (orI₁ t) = cong orI₁ (monD-nf τ t)\n monD-nf τ (orI₂ t) = cong orI₂ (monD-nf τ t)\n monD-nf τ (orE t u v) = cong₃ orE (monD-ne τ t) (monD-nf (lift τ) u) (monD-nf (lift τ) v)\n monD-nf τ (falseE t) = cong falseE (monD-ne τ t)\n monD-nf τ trueI = refl\n\n -- monD-ne : ∀{Γ Δ A} (τ : Δ ≤ Γ) (t : Ne Γ A) → monD τ ne[ t ] ≡ ne[ monNe τ t ]\n -- monD-ne τ (hyp x) = refl\n -- monD-ne τ (impE t u) = cong₂ impE (monD-ne τ t) (monD-nf τ u)\n -- monD-ne τ (andE₁ t) = cong andE₁ (monD-ne τ t)\n -- monD-ne τ (andE₂ t) = cong andE₂ (monD-ne τ t)\n\n -- monD-nf : ∀{Γ Δ A} (τ : Δ ≤ Γ) (t : Nf Γ A) → monD τ nf[ t ] ≡ nf[ monNf τ t ]\n -- monD-nf τ (ne t) = monD-ne τ t\n -- monD-nf τ (impI t) = cong impI (monD-nf (lift τ) t)\n -- monD-nf τ (andI t u) = cong₂ andI (monD-nf τ t) (monD-nf τ u)\n -- monD-nf τ (orI₁ t) = cong orI₁ (monD-nf τ t)\n -- monD-nf τ (orI₂ t) = cong orI₂ (monD-nf τ t)\n -- monD-nf τ (orE t u v) = cong₃ orE (monD-ne τ t) (monD-nf (lift τ) u) (monD-nf (lift τ) v)\n -- monD-nf τ (falseE t) = cong falseE (monD-ne τ t)\n -- monD-nf τ trueI = refl\n\n{-# REWRITE monD-ne monD-nf #-}\n", "meta": {"hexsha": "b132ff794810466b4d97399d6481a14ffef5553a", "size": 7100, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Derivations.agda", "max_stars_repo_name": "andreasabel/ipl", "max_stars_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2018-05-16T08:08:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T19:10:49.000Z", "max_issues_repo_path": "src/Derivations.agda", "max_issues_repo_name": "andreasabel/ipl", "max_issues_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_issues_repo_licenses": ["Unlicense"], "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/Derivations.agda", "max_forks_repo_name": "andreasabel/ipl", "max_forks_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-11-13T16:01:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-25T20:39:03.000Z", "avg_line_length": 36.7875647668, "max_line_length": 97, "alphanum_fraction": 0.5007042254, "num_tokens": 3430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583250334527, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.38857231979860923}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.DStructures.Structures.SplitEpi where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Structure\nopen import Cubical.Functions.FunExtEquiv\n\nopen import Cubical.Homotopy.Base\n\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Relation.Binary\n\nopen import Cubical.Algebra.Group\nopen import Cubical.Structures.LeftAction\n\nopen import Cubical.DStructures.Base\nopen import Cubical.DStructures.Meta.Properties\n\nopen import Cubical.DStructures.Structures.Type\nopen import Cubical.DStructures.Structures.Constant\nopen import Cubical.DStructures.Structures.Group\n\nprivate\n variable\n ℓ ℓ' : Level\n\nopen URGStr\n\n---------------------------------------------\n-- URG structures on the type of split epis,\n-- and displayed structures over that\n--\n-- B\n-- |\n-- isSplit\n-- |\n-- G²FB\n---------------------------------------------\n\nmodule _ (ℓ ℓ' : Level) where\n\n -- type of Split epimorphisms\n SplitEpi = Σ[ ((G , H) , f , b) ∈ G²FB ℓ ℓ' ] isGroupSplitEpi f b\n SplitEpi' = Σ[ G ∈ Group {ℓ} ] Σ[ H ∈ Group {ℓ'} ] Σ[ (f , b) ∈ (GroupHom G H) × (GroupHom H G) ] isGroupSplitEpi f b\n\n IsoSplitEpi' : Iso SplitEpi' SplitEpi\n IsoSplitEpi' = compIso (invIso Σ-assoc-Iso)\n (invIso Σ-assoc-Iso)\n\n -- split epimorphisms + a map back\n SplitEpiB = Σ[ (((G , H) , f , b) , isRet) ∈ SplitEpi ] GroupHom H G\n\n -- split epimorphisms displayed over pairs of groups\n 𝒮ᴰ-SplitEpi : URGStrᴰ (𝒮-G²FB ℓ ℓ')\n (λ ((G , H) , (f , b)) → isGroupSplitEpi f b)\n ℓ-zero\n 𝒮ᴰ-SplitEpi =\n Subtype→Sub-𝒮ᴰ (λ ((G , H) , (f , b)) → isGroupSplitEpi f b , isPropIsGroupSplitEpi f b)\n (𝒮-G²FB ℓ ℓ')\n\n -- URG structure on type of split epimorphisms\n 𝒮-SplitEpi : URGStr SplitEpi (ℓ-max ℓ ℓ')\n 𝒮-SplitEpi = ∫⟨ 𝒮-G²FB ℓ ℓ' ⟩ 𝒮ᴰ-SplitEpi\n\n -- morphisms back displayed over split epimorphisms,\n -- obtained by lifting the morphisms back over\n -- 𝒮-G² twice\n 𝒮ᴰ-G²FBSplit\\B : URGStrᴰ 𝒮-SplitEpi\n (λ (((G , H) , _) , _) → GroupHom H G)\n (ℓ-max ℓ ℓ')\n 𝒮ᴰ-G²FBSplit\\B =\n VerticalLift2-𝒮ᴰ (𝒮-group ℓ ×𝒮 𝒮-group ℓ')\n (𝒮ᴰ-G²\\B ℓ ℓ')\n (𝒮ᴰ-G²\\FB ℓ ℓ')\n 𝒮ᴰ-SplitEpi\n\n -- URG structure on split epis with an extra\n -- morphism back\n 𝒮-SplitEpiB : URGStr SplitEpiB (ℓ-max ℓ ℓ')\n 𝒮-SplitEpiB = ∫⟨ 𝒮-SplitEpi ⟩ 𝒮ᴰ-G²FBSplit\\B\n\n 𝒮ᴰ-G\\GFBSplitEpi : URGStrᴰ (𝒮-group ℓ)\n (λ G → Σ[ H ∈ Group {ℓ'} ] Σ[ (f , b) ∈ (GroupHom G H) × (GroupHom H G) ] isGroupSplitEpi f b )\n (ℓ-max ℓ ℓ')\n 𝒮ᴰ-G\\GFBSplitEpi =\n splitTotal-𝒮ᴰ (𝒮-group ℓ)\n (𝒮ᴰ-const (𝒮-group ℓ) (𝒮-group ℓ'))\n (splitTotal-𝒮ᴰ (𝒮-group ℓ ×𝒮 𝒮-group ℓ')\n (𝒮ᴰ-G²\\FB ℓ ℓ')\n 𝒮ᴰ-SplitEpi)\n\n--------------------------------------------------\n-- This module introduces convenient notation\n-- when working with a single split epimorphism\n---------------------------------------------------\n\nmodule SplitEpiNotation {G₀ : Group {ℓ}} {G₁ : Group {ℓ'}}\n (ι : GroupHom G₀ G₁) (σ : GroupHom G₁ G₀)\n (split : isGroupSplitEpi ι σ) where\n open GroupNotation₀ G₀\n open GroupNotation₁ G₁\n ι∘σ : GroupHom G₁ G₁\n ι∘σ = compGroupHom σ ι\n s = GroupHom.fun σ\n -- i is reserved for an interval variable (i : I) so we use 𝒾 instead\n 𝒾 = GroupHom.fun ι\n -i = λ (x : ⟨ G₀ ⟩) → -₁ (𝒾 x)\n s- = λ (x : ⟨ G₁ ⟩) → s (-₁ x)\n si = λ (x : ⟨ G₀ ⟩) → s (𝒾 x)\n is = λ (x : ⟨ G₁ ⟩) → 𝒾 (s x)\n -si = λ (x : ⟨ G₀ ⟩) → -₀ (si x)\n -is = λ (x : ⟨ G₁ ⟩) → -₁ (is x)\n si- = λ (x : ⟨ G₀ ⟩) → si (-₀ x)\n is- = λ (x : ⟨ G₁ ⟩) → is (-₁ x)\n s-i = λ (x : ⟨ G₀ ⟩) → s (-₁ (𝒾 x))\n isi = λ (x : ⟨ G₀ ⟩) → 𝒾 (s (𝒾 x))\n", "meta": {"hexsha": "c81ea2543261f2aa47c634a3c5b50d8165b389e9", "size": 4021, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/DStructures/Structures/SplitEpi.agda", "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/DStructures/Structures/SplitEpi.agda", "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/DStructures/Structures/SplitEpi.agda", "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": 33.2314049587, "max_line_length": 124, "alphanum_fraction": 0.5476249689, "num_tokens": 1523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583250334526, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.3885723197986092}} {"text": "module Semantics where\n\nopen import Data.Nat hiding (_⊔_; _⊓_)\nopen import Data.Product\nopen import Data.Sum\nopen import Data.String using (String)\nopen import Data.Unit hiding (_≟_)\nopen import Data.Empty\n\nopen import Relation.Nullary\nimport Relation.Binary.PropositionalEquality as Eq\nopen Eq using (_≡_;_≢_; refl)\nopen Eq.≡-Reasoning\nopen import Level hiding (_⊔_) renaming (zero to lzero; suc to lsuc)\n\n{- TODO:\n* subtyping of refinement types\n* union types\n* intersection types\n-}\n\nId = String\n\nvariable\n x y : Id\n ℓ : Level\n\ndata Expr : Set where\n Nat : ℕ → Expr\n Var : Id → Expr\n Lam : Id → Expr → Expr\n App : Expr → Expr → Expr\n Pair : Expr → Expr → Expr\n Fst Snd : Expr → Expr\n Inl Inr : Expr → Expr\n Case : Expr → Id → Expr → Id → Expr → Expr\n\ndata RawType : Set where\n Nat : RawType\n _⇒_ _⋆_ _⊹_ : RawType → RawType → RawType\n\nss⇒tt : ∀ {S S₁ T T₁ : RawType} → (S ⇒ S₁) ≡ (T ⇒ T₁) → (S ≡ T × S₁ ≡ T₁)\nss⇒tt refl = refl , refl\n\nss⋆tt : ∀ {S S₁ T T₁ : RawType} → (S ⋆ S₁) ≡ (T ⋆ T₁) → (S ≡ T × S₁ ≡ T₁)\nss⋆tt refl = refl , refl\n\nss⊹tt : ∀ {S S₁ T T₁ : RawType} → (S ⊹ S₁) ≡ (T ⊹ T₁) → (S ≡ T × S₁ ≡ T₁)\nss⊹tt refl = refl , refl\n\n\ndata Type : Set₁ where\n Base : (P : ℕ → Set) → Type -- refinement\n Nat : Type\n _⇒_ : Type → Type → Type\n _⋆_ : Type → Type → Type\n _⊹_ : Type → Type → Type\n\nT-Nat = Base (λ n → ⊤) -- all natural numbers\n\ndata ne : Type → Set where\n ne-base : ∀ {P} → (∃P : Σ ℕ P) → ne (Base P)\n ne-nat : ne Nat\n ne-⇒ : ∀ {S T} → ne S → ne T → ne (S ⇒ T)\n ne-⋆ : ∀ {S T} → ne S → ne T → ne (S ⋆ T)\n ne-⊹L : ∀ {S T} → ne S → ne (S ⊹ T)\n ne-⊹R : ∀ {S T} → ne T → ne (S ⊹ T)\n\ndata Env (A : Set ℓ) : Set ℓ where\n · : Env A\n _,_⦂_ : Env A → (x : Id) → (a : A) → Env A\n\n∥_∥ : Type → RawType\n∥ Base P ∥ = Nat\n∥ Nat ∥ = Nat\n∥ S ⇒ S₁ ∥ = ∥ S ∥ ⇒ ∥ S₁ ∥\n∥ S ⋆ S₁ ∥ = ∥ S ∥ ⋆ ∥ S₁ ∥\n∥ S ⊹ S₁ ∥ = ∥ S ∥ ⊹ ∥ S₁ ∥\n\n\n_∨_ : (P Q : ℕ → Set) → ℕ → Set\nP ∨ Q = λ n → P n ⊎ Q n\n\n_∧_ : (P Q : ℕ → Set) → ℕ → Set\nP ∧ Q = λ n → P n × Q n\n\nimplies : ∀ {P Q : ℕ → Set} → (n : ℕ) → P n → (P n ⊎ Q n)\nimplies n Pn = inj₁ Pn\n\np*q->p : ∀ {P Q : ℕ → Set} → (n : ℕ) → (P n × Q n) → P n\np*q->p n (Pn , Qn) = Pn\n\n_⊔_ _⊓_ : (S T : Type) {r : ∥ S ∥ ≡ ∥ T ∥} → Type\n\n(Base P ⊔ Base P₁) {refl} = Base (P ∨ P₁)\n(Base P ⊔ Nat) = Nat\n(Nat ⊔ Base P) = Nat\n(Nat ⊔ Nat) = Nat\n((S ⇒ S₁) ⊔ (T ⇒ T₁)) {r} with ss⇒tt r\n... | sss , ttt = (S ⊓ T){sss} ⇒ (S₁ ⊔ T₁){ttt}\n((S ⋆ S₁) ⊔ (T ⋆ T₁)) {r} with ss⋆tt r\n... | sss , ttt = (S ⊔ T){sss} ⋆ (S₁ ⊔ T₁){ttt}\n((S ⊹ S₁) ⊔ (T ⊹ T₁)) {r} with ss⊹tt r\n... | sss , ttt = (S ⊔ T){sss} ⊹ (S₁ ⊔ T₁){ttt}\n\nBase P ⊓ Base P₁ = Base (P ∧ P₁)\nBase P ⊓ Nat = Base P\nNat ⊓ Base P = Base P\nNat ⊓ Nat = Nat\n((S ⇒ S₁) ⊓ (T ⇒ T₁)){r} with ss⇒tt r\n... | sss , ttt = (S ⊔ T){sss} ⇒ (S₁ ⊓ T₁){ttt}\n((S ⋆ S₁) ⊓ (T ⋆ T₁)){r} with ss⋆tt r\n... | sss , ttt = (S ⊓ T){sss} ⋆ (S₁ ⊓ T₁){ttt}\n((S ⊹ S₁) ⊓ (T ⊹ T₁)){r} with ss⊹tt r\n... | sss , ttt = (S ⊓ T){sss} ⊹ (S₁ ⊓ T₁){ttt}\n\n\nvariable\n S T U S′ T′ U′ U″ : Type\n Γ Γ₁ Γ₂ : Env Type\n L M N : Expr\n n : ℕ\n P : ℕ → Set\n\ndata Split {A : Set ℓ} : Env A → Env A → Env A → Set ℓ where\n nil : Split · · ·\n lft : ∀ {a : A}{Γ Γ₁ Γ₂ : Env A} → Split Γ Γ₁ Γ₂ → Split (Γ , x ⦂ a) (Γ₁ , x ⦂ a) Γ₂\n rgt : ∀ {a : A}{Γ Γ₁ Γ₂ : Env A} → Split Γ Γ₁ Γ₂ → Split (Γ , x ⦂ a) Γ₁ (Γ₂ , x ⦂ a)\n\ndata _⦂_∈_ {A : Set ℓ} : Id → A → Env A → Set ℓ where\n\n found : ∀ {a : A}{E : Env A} →\n x ⦂ a ∈ (E , x ⦂ a)\n\n there : ∀ {a a' : A}{E : Env A} →\n x ⦂ a ∈ E →\n -- x ≢ y →\n x ⦂ a ∈ (E , y ⦂ a')\n\ndata _<:_ : Type → Type → Set where\n\n <:-refl :\n T <: T\n\n <:-base : \n (P Q : ℕ → Set) →\n (p→q : ∀ n → P n → Q n) →\n Base P <: Base Q\n\n <:-base-nat :\n Base P <: Nat\n \n <:-⇒ :\n S′ <: S →\n T <: T′ →\n (S ⇒ T) <: (S′ ⇒ T′)\n \n <:-⋆ :\n S <: S′ →\n T <: T′ →\n (S ⋆ T) <: (S′ ⋆ T′)\n\n <:-⊹ :\n S <: S′ →\n T <: T′ →\n (S ⊹ T) <: (S′ ⊹ T′)\n\n-- subtyping is compatible with raw types\n\n<:-raw : S <: T → ∥ S ∥ ≡ ∥ T ∥\n<:-raw <:-refl = refl\n<:-raw (<:-base P Q p→q) = refl\n<:-raw <:-base-nat = refl\n<:-raw (<:-⇒ s<:t s<:t₁) = Eq.cong₂ _⇒_ (Eq.sym (<:-raw s<:t)) (<:-raw s<:t₁)\n<:-raw (<:-⋆ s<:t s<:t₁) = Eq.cong₂ _⋆_ (<:-raw s<:t) (<:-raw s<:t₁)\n<:-raw (<:-⊹ s<:t s<:t₁) = Eq.cong₂ _⊹_ (<:-raw s<:t) (<:-raw s<:t₁)\n\n<:-⊔ : ∀ S T → {c : ∥ S ∥ ≡ ∥ T ∥} → S <: (S ⊔ T){c}\n<:-⊓ : ∀ S T → {c : ∥ S ∥ ≡ ∥ T ∥} → (S ⊓ T){c} <: S\n\n<:-⊔ (Base P) (Base P₁) {refl} = <:-base P (P ∨ P₁) implies\n<:-⊔ (Base P) Nat = <:-base-nat\n<:-⊔ Nat (Base P) = <:-refl\n<:-⊔ Nat Nat = <:-refl\n<:-⊔ (S ⇒ S₁) (T ⇒ T₁) {c} with ss⇒tt c\n... | c1 , c2 = <:-⇒ (<:-⊓ S T) (<:-⊔ S₁ T₁)\n<:-⊔ (S ⋆ S₁) (T ⋆ T₁) {c} with ss⋆tt c\n... | c1 , c2 = <:-⋆ (<:-⊔ S T) (<:-⊔ S₁ T₁)\n<:-⊔ (S ⊹ S₁) (T ⊹ T₁) {c} with ss⊹tt c\n... | c1 , c2 = <:-⊹ (<:-⊔ S T) (<:-⊔ S₁ T₁)\n\n<:-⊓ (Base P) (Base P₁) {refl} = <:-base (P ∧ P₁) P p*q->p\n<:-⊓ (Base P) Nat = <:-refl\n<:-⊓ Nat (Base P) = <:-base-nat\n<:-⊓ Nat Nat = <:-refl\n<:-⊓ (S ⇒ S₁) (T ⇒ T₁) {c} with ss⇒tt c\n... | c1 , c2 = <:-⇒ (<:-⊔ S T) (<:-⊓ S₁ T₁)\n<:-⊓ (S ⋆ S₁) (T ⋆ T₁) {c} with ss⋆tt c\n... | c1 , c2 = <:-⋆ (<:-⊓ S T) (<:-⊓ S₁ T₁)\n<:-⊓ (S ⊹ S₁) (T ⊹ T₁) {c} with ss⊹tt c\n... | c1 , c2 = <:-⊹ (<:-⊓ S T) (<:-⊓ S₁ T₁)\n\n-- should be in terms of RawType for evaluation\n\ndata _⊢_⦂_ : Env Type → Expr → Type → Set₁ where\n\n nat' :\n Γ ⊢ Nat n ⦂ Base (_≡_ n)\n\n var :\n (x∈ : x ⦂ T ∈ Γ) →\n --------------------\n Γ ⊢ Var x ⦂ T\n\n lam :\n (Γ , x ⦂ S) ⊢ M ⦂ T →\n --------------------\n Γ ⊢ Lam x M ⦂ (S ⇒ T)\n\n app :\n Γ ⊢ M ⦂ (S ⇒ T) →\n Γ ⊢ N ⦂ S →\n --------------------\n Γ ⊢ App M N ⦂ T\n\n pair :\n Γ ⊢ M ⦂ S →\n Γ ⊢ N ⦂ T →\n --------------------\n Γ ⊢ Pair M N ⦂ (S ⋆ T)\n\n pair-E1 :\n Γ ⊢ M ⦂ (S ⋆ T) →\n --------------------\n Γ ⊢ Fst M ⦂ S\n\n pair-E2 :\n Γ ⊢ M ⦂ (S ⋆ T) →\n --------------------\n Γ ⊢ Snd M ⦂ T\n\n sum-I1 :\n Γ ⊢ M ⦂ S →\n --------------------\n Γ ⊢ Inl M ⦂ (S ⊹ T)\n\n sum-I2 :\n Γ ⊢ N ⦂ T →\n --------------------\n Γ ⊢ Inl N ⦂ (S ⊹ T)\n \n sum-E :\n Γ ⊢ L ⦂ (S ⊹ T) →\n (Γ , x ⦂ S) ⊢ M ⦂ U →\n (Γ , y ⦂ T) ⊢ N ⦂ U →\n --------------------\n Γ ⊢ Case L x M y N ⦂ U\n\nsplit-sym : Split Γ Γ₁ Γ₂ → Split Γ Γ₂ Γ₁\nsplit-sym nil = nil\nsplit-sym (lft sp) = rgt (split-sym sp)\nsplit-sym (rgt sp) = lft (split-sym sp)\n\nweaken-∈ : Split Γ Γ₁ Γ₂ → x ⦂ T ∈ Γ₁ → x ⦂ T ∈ Γ\nweaken-∈ (lft sp) found = found\nweaken-∈ (rgt sp) found = there (weaken-∈ sp found)\nweaken-∈ (lft sp) (there x∈) = there (weaken-∈ sp x∈)\nweaken-∈ (rgt sp) (there x∈) = there (weaken-∈ sp (there x∈))\n\nweaken : Split Γ Γ₁ Γ₂ → Γ₁ ⊢ M ⦂ T → Γ ⊢ M ⦂ T\nweaken sp (nat') = nat'\nweaken sp (var x∈) = var (weaken-∈ sp x∈)\nweaken sp (lam ⊢M) = lam (weaken (lft sp) ⊢M)\nweaken sp (app ⊢M ⊢N) = app (weaken sp ⊢M) (weaken sp ⊢N)\nweaken sp (pair ⊢M ⊢N) = pair (weaken sp ⊢M) (weaken sp ⊢N)\nweaken sp (pair-E1 ⊢M) = pair-E1 (weaken sp ⊢M)\nweaken sp (pair-E2 ⊢M) = pair-E2 (weaken sp ⊢M)\nweaken sp (sum-I1 ⊢M) = sum-I1 (weaken sp ⊢M)\nweaken sp (sum-I2 ⊢N) = sum-I2 (weaken sp ⊢N)\nweaken sp (sum-E ⊢L ⊢M ⊢N) = sum-E (weaken sp ⊢L) (weaken (lft sp) ⊢M) (weaken (lft sp) ⊢N)\n\n-- incorrectness typing\n\nP=n : ℕ → ℕ → Set\nP=n = λ n x → n ≡ x\n\ndata _⊢_÷_ : Env Type → Expr → Type → Set₁ where\n\n nat' :\n --------------------\n · ⊢ Nat n ÷ Base (_≡_ n)\n\n var1 :\n ( · , x ⦂ T) ⊢ Var x ÷ T\n\n{-\n var :\n x ⦂ T ∈ Γ →\n --------------------\n Γ ⊢ Var x ÷ T\n-}\n\n lam :\n (· , x ⦂ S) ⊢ M ÷ T →\n --------------------\n · ⊢ Lam x M ÷ (S ⇒ T)\n\n pair :\n Split Γ Γ₁ Γ₂ →\n Γ₁ ⊢ M ÷ S →\n Γ₂ ⊢ N ÷ T →\n --------------------\n Γ ⊢ Pair M N ÷ (S ⋆ T)\n\n pair-E1 :\n Γ ⊢ M ÷ (S ⋆ T) →\n --------------------\n Γ ⊢ Fst M ÷ S\n\n pair-E2 :\n Γ ⊢ M ÷ (S ⋆ T) →\n --------------------\n Γ ⊢ Snd M ÷ T\n\n sum-E :\n Split Γ Γ₁ Γ₂ →\n Γ₁ ⊢ L ÷ (S ⊹ T) →\n (Γ₂ , x ⦂ S) ⊢ M ÷ U →\n (Γ₂ , y ⦂ T) ⊢ N ÷ U →\n --------------------\n Γ ⊢ Case L x M y N ÷ U\n\n sum-E′ : ∀ {ru′=ru″} →\n Split Γ Γ₁ Γ₂ →\n Γ₁ ⊢ L ÷ (S ⊹ T) →\n (Γ₂ , x ⦂ S) ⊢ M ÷ U′ →\n (Γ₂ , y ⦂ T) ⊢ N ÷ U″ →\n U ≡ (U′ ⊔ U″){ru′=ru″} →\n --------------------\n Γ ⊢ Case L x M y N ÷ U\n\n{-\n `sub` :\n Γ ⊢ M ÷ S →\n T <: S → \n --------------------\n Γ ⊢ M ÷ T\n-}\n\nrecord _←_ (A B : Set) : Set where\n field\n func : A → B\n back : ∀ (b : B) → ∃ λ (a : A) → func a ≡ b\n\nopen _←_\n\nT⟦_⟧ : Type → Set\nT⟦ Base P ⟧ = Σ ℕ P\nT⟦ Nat ⟧ = ℕ\nT⟦ S ⇒ T ⟧ = T⟦ S ⟧ → T⟦ T ⟧\nT⟦ S ⋆ T ⟧ = T⟦ S ⟧ × T⟦ T ⟧\nT⟦ S ⊹ T ⟧ = T⟦ S ⟧ ⊎ T⟦ T ⟧\n\nT'⟦_⟧ : Type → Set\nT'⟦ Base P ⟧ = Σ ℕ P\nT'⟦ Nat ⟧ = ℕ\nT'⟦ S ⇒ T ⟧ = T'⟦ S ⟧ ← T'⟦ T ⟧\nT'⟦ S ⋆ T ⟧ = T'⟦ S ⟧ × T'⟦ T ⟧\nT'⟦ S ⊹ T ⟧ = T'⟦ S ⟧ ⊎ T'⟦ T ⟧\n\n \nE⟦_⟧ : Env Type → Env Set\nE⟦ · ⟧ = ·\nE⟦ Γ , x ⦂ T ⟧ = E⟦ Γ ⟧ , x ⦂ T⟦ T ⟧\n\ndata iEnv : Env Set → Set where\n · : iEnv ·\n _,_⦂_ : ∀ {E}{A} → iEnv E → (x : Id) → (a : A) → iEnv (E , x ⦂ A)\n\nlookup : (x ⦂ T ∈ Γ) → iEnv E⟦ Γ ⟧ → T⟦ T ⟧\nlookup found (γ , _ ⦂ a) = a\nlookup (there x∈) (γ , _ ⦂ a) = lookup x∈ γ\n\neval : Γ ⊢ M ⦂ T → iEnv E⟦ Γ ⟧ → T⟦ T ⟧\neval (nat'{n = n}) γ = n , refl\neval (var x∈) γ = lookup x∈ γ\neval (lam ⊢M) γ = λ s → eval ⊢M (γ , _ ⦂ s)\neval (app ⊢M ⊢N) γ = eval ⊢M γ (eval ⊢N γ)\neval (pair ⊢M ⊢N) γ = (eval ⊢M γ) , (eval ⊢N γ)\neval (pair-E1 ⊢M) γ = proj₁ (eval ⊢M γ)\neval (pair-E2 ⊢M) γ = proj₂ (eval ⊢M γ)\neval (sum-I1 ⊢M) γ = inj₁ (eval ⊢M γ)\neval (sum-I2 ⊢N) γ = inj₂ (eval ⊢N γ)\neval (sum-E{S = S}{T = T}{U = U} ⊢L ⊢M ⊢N) γ =\n [ (λ s → eval ⊢M (γ , _ ⦂ s)) , (λ t → eval ⊢N (γ , _ ⦂ t)) ] (eval ⊢L γ)\n\n\ncorr : Γ ⊢ M ÷ T → Γ ⊢ M ⦂ T\ncorr (nat') = nat'\ncorr var1 = var found\n-- corr (var x) = var x\ncorr (lam ⊢M) = lam (corr ⊢M)\ncorr (pair-E1 ÷M) = pair-E1 (corr ÷M)\ncorr (pair-E2 ÷M) = pair-E2 (corr ÷M)\ncorr (pair sp ÷M ÷N) = pair (weaken sp (corr ÷M)) (weaken (split-sym sp) (corr ÷N))\ncorr (sum-E sp ÷L ÷M ÷N) = sum-E (weaken sp (corr ÷L)) (weaken (lft (split-sym sp)) (corr ÷M)) (weaken (lft (split-sym sp)) (corr ÷N))\ncorr (sum-E′ sp ÷L ÷M ÷N U≡U′⊔U″) =\n sum-E (weaken sp (corr ÷L)) (weaken (lft (split-sym sp)) (corr {!!})) (weaken (lft (split-sym sp)) (corr {!!}))\n{-\ncorr (`sub` ÷M T>=′_\n\n_>>=′_ : ∀ {i a b} {A : Type a} {B : Type b} →\n Delay A i → (A → Delay B i) → Delay B i\nx >>=′ f = join (map′ f x)\n\ninstance\n\n -- A raw monad instance.\n\n delay-raw-monad : ∀ {a i} → Raw-monad (λ (A : Type a) → Delay A i)\n Raw-monad.return delay-raw-monad = now\n Raw-monad._>>=_ delay-raw-monad = _>>=′_\n\n------------------------------------------------------------------------\n-- Monad laws\n\nleft-identity′ :\n ∀ {a b} {A : Type a} {B : Type b} x (f : A → Delay B ∞) →\n return x >>=′ f ∼ f x\nleft-identity′ x f = reflexive (f x)\n\nright-identity′ : ∀ {a i} {A : Type a} (x : Delay A ∞) →\n [ i ] x >>= return ∼ x\nright-identity′ (now x) = now\nright-identity′ (later x) = later λ { .force →\n right-identity′ (force x) }\n\nassociativity′ :\n ∀ {a b c i} {A : Type a} {B : Type b} {C : Type c} →\n (x : Delay A ∞) (f : A → Delay B ∞) (g : B → Delay C ∞) →\n [ i ] x >>=′ (λ x → f x >>=′ g) ∼ x >>=′ f >>=′ g\nassociativity′ (now x) f g = reflexive (f x >>=′ g)\nassociativity′ (later x) f g = later λ { .force →\n associativity′ (force x) f g }\n\n-- The delay monad is a monad (assuming extensionality).\n\ndelay-monad :\n ∀ {a} → B.Extensionality a → Monad (λ (A : Type a) → Delay A ∞)\nMonad.raw-monad (delay-monad ext) = delay-raw-monad\nMonad.left-identity (delay-monad ext) x f = ext (left-identity′ x f)\nMonad.right-identity (delay-monad ext) x = ext (right-identity′ x)\nMonad.associativity (delay-monad ext) x f g = ext (associativity′ x f g)\n\n------------------------------------------------------------------------\n-- The functions map′, join and _>>=′_ preserve strong and weak\n-- bisimilarity and expansion\n\nmap-cong : ∀ {k i a b} {A : Type a} {B : Type b}\n (f : A → B) {x y : Delay A ∞} →\n [ i ] x ⟨ k ⟩ y → [ i ] map′ f x ⟨ k ⟩ map′ f y\nmap-cong f now = now\nmap-cong f (later p) = later λ { .force → map-cong f (force p) }\nmap-cong f (laterˡ p) = laterˡ (map-cong f p)\nmap-cong f (laterʳ p) = laterʳ (map-cong f p)\n\njoin-cong : ∀ {k i a} {A : Type a} {x y : Delay (Delay A ∞) ∞} →\n [ i ] x ⟨ k ⟩ y → [ i ] join x ⟨ k ⟩ join y\njoin-cong now = reflexive _\njoin-cong (later p) = later λ { .force → join-cong (force p) }\njoin-cong (laterˡ p) = laterˡ (join-cong p)\njoin-cong (laterʳ p) = laterʳ (join-cong p)\n\ninfixl 5 _>>=-cong_\n\n_>>=-cong_ :\n ∀ {k i a b} {A : Type a} {B : Type b}\n {x y : Delay A ∞} {f g : A → Delay B ∞} →\n [ i ] x ⟨ k ⟩ y → (∀ z → [ i ] f z ⟨ k ⟩ g z) →\n [ i ] x >>=′ f ⟨ k ⟩ y >>=′ g\nnow >>=-cong q = q _\nlater p >>=-cong q = later λ { .force → force p >>=-cong q }\nlaterˡ p >>=-cong q = laterˡ (p >>=-cong q)\nlaterʳ p >>=-cong q = laterʳ (p >>=-cong q)\n\n------------------------------------------------------------------------\n-- A lemma\n\n-- The function map′ can be expressed using _>>=′_ and now.\n\nmap∼>>=-now :\n ∀ {i a b} {A : Type a} {B : Type b} {f : A → B} (x : Delay A ∞) →\n [ i ] map′ f x ∼ x >>=′ now ∘ f\nmap∼>>=-now (now x) = now\nmap∼>>=-now (later x) = later λ { .force → map∼>>=-now (x .force) }\n\n------------------------------------------------------------------------\n-- Some lemmas relating monadic combinators to steps\n\n-- Use of map′ does not affect the number of steps in the computation.\n\nsteps-map′ :\n ∀ {i a b} {A : Type a} {B : Type b} {f : A → B}\n (x : Delay A ∞) →\n Conat.[ i ] steps (map′ f x) ∼ steps x\nsteps-map′ (now x) = zero\nsteps-map′ (later x) = suc λ { .force → steps-map′ (x .force) }\n\n-- Use of _⟨$⟩_ does not affect the number of steps in the\n-- computation.\n\nsteps-⟨$⟩ :\n ∀ {i ℓ} {A B : Type ℓ} {f : A → B}\n (x : Delay A ∞) →\n Conat.[ i ] steps (f ⟨$⟩ x) ∼ steps x\nsteps-⟨$⟩ (now x) = zero\nsteps-⟨$⟩ (later x) = suc λ { .force → steps-⟨$⟩ (x .force) }\n", "meta": {"hexsha": "3ca82384cd5f4110f88c91af29a02018dc3a833a", "size": 4839, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Delay-monad/Monad.agda", "max_stars_repo_name": "nad/delay-monad", "max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Monad.agda", "max_issues_repo_name": "nad/delay-monad", "max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Monad.agda", "max_forks_repo_name": "nad/delay-monad", "max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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": 33.1438356164, "max_line_length": 73, "alphanum_fraction": 0.4860508369, "num_tokens": 1658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548646660542, "lm_q2_score": 0.5964331462646254, "lm_q1q2_score": 0.388489631267544}} {"text": "module BasicIPC.Metatheory.Hilbert-TarskiConcreteGluedImplicit where\n\nopen import BasicIPC.Syntax.Hilbert public\nopen import BasicIPC.Semantics.TarskiConcreteGluedImplicit public\n\nopen ImplicitSyntax (_⊢_) public\n\n\n-- Completeness with respect to a particular model.\n\nmodule _ {{_ : Model}} where\n reify : ∀ {A w} → w ⊩ A → unwrap w ⊢ A\n reify {α P} s = syn s\n reify {A ▻ B} s = syn s\n reify {A ∧ B} s = pair (reify (π₁ s)) (reify (π₂ s))\n reify {⊤} s = unit\n\n reify⋆ : ∀ {Ξ w} → w ⊩⋆ Ξ → unwrap w ⊢⋆ Ξ\n reify⋆ {∅} ∙ = ∙\n reify⋆ {Ξ , A} (ts , t) = reify⋆ ts , reify t\n\n\n-- Additional useful equipment.\n\nmodule _ {{_ : Model}} where\n ⟪K⟫ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A\n ⟪K⟫ {A} a = app ck (reify a) ⅋ K a\n\n ⟪S⟫′ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ (A ▻ B) ▻ A ▻ C\n ⟪S⟫′ {A} {B} {C} s₁ = app cs (syn s₁) ⅋ λ s₂ →\n app (app cs (syn s₁)) (syn s₂) ⅋ ⟪S⟫ s₁ s₂\n\n _⟪,⟫′_ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A ∧ B\n _⟪,⟫′_ {A} a = app cpair (reify a) ⅋ _,_ a\n\n\n-- Soundness with respect to all models, or evaluation.\n\neval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A\neval (var i) γ = lookup i γ\neval (app t u) γ = eval t γ ⟪$⟫ eval u γ\neval ci γ = ci ⅋ I\neval ck γ = ck ⅋ ⟪K⟫\neval cs γ = cs ⅋ ⟪S⟫′\neval cpair γ = cpair ⅋ _⟪,⟫′_\neval cfst γ = cfst ⅋ π₁\neval csnd γ = csnd ⅋ π₂\neval unit γ = ∙\n\n\n-- TODO: Correctness of evaluation with respect to conversion.\n\n\n-- The canonical model.\n\nprivate\n instance\n canon : Model\n canon = record\n { _⊩ᵅ_ = λ w P → unwrap w ⊢ α P\n }\n\n\n-- Soundness with respect to the canonical model.\n\nreflectᶜ : ∀ {A w} → unwrap w ⊢ A → w ⊩ A\nreflectᶜ {α P} t = t ⅋ t\nreflectᶜ {A ▻ B} t = t ⅋ λ a → reflectᶜ (app t (reify a))\nreflectᶜ {A ∧ B} t = reflectᶜ (fst t) , reflectᶜ (snd t)\nreflectᶜ {⊤} t = ∙\n\nreflectᶜ⋆ : ∀ {Ξ w} → unwrap w ⊢⋆ Ξ → w ⊩⋆ Ξ\nreflectᶜ⋆ {∅} ∙ = ∙\nreflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t\n\n\n-- Reflexivity and transitivity.\n\nrefl⊩⋆ : ∀ {w} → w ⊩⋆ unwrap w\nrefl⊩⋆ = reflectᶜ⋆ refl⊢⋆\n\ntrans⊩⋆ : ∀ {w w′ w″} → w ⊩⋆ unwrap w′ → w′ ⊩⋆ unwrap w″ → w ⊩⋆ unwrap w″\ntrans⊩⋆ ts us = reflectᶜ⋆ (trans⊢⋆ (reify⋆ ts) (reify⋆ us))\n\n\n-- Completeness with respect to all models, or quotation.\n\nquot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A\nquot s = reify (s refl⊩⋆)\n\n\n-- Normalisation by evaluation.\n\nnorm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A\nnorm = quot ∘ eval\n\n\n-- TODO: Correctness of normalisation with respect to conversion.\n", "meta": {"hexsha": "41c5d63c53d74313252afac2bf7073ea0ddc89ee", "size": 2441, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BasicIPC/Metatheory/Hilbert-TarskiConcreteGluedImplicit.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": "BasicIPC/Metatheory/Hilbert-TarskiConcreteGluedImplicit.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": "BasicIPC/Metatheory/Hilbert-TarskiConcreteGluedImplicit.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": 24.6565656566, "max_line_length": 73, "alphanum_fraction": 0.5415813191, "num_tokens": 1130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239836484143, "lm_q2_score": 0.5428632831725053, "lm_q1q2_score": 0.38837741262373093}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import lib.Basics\nopen import lib.types.Pi\nopen import lib.types.Paths\nopen import lib.types.Sigma\n\nmodule lib.types.Flattening {i j k}\n (A : Type i) (B : Type j) (f g : B → A)\n (C : A → Type k) (D : (b : B) → C (f b) ≃ C (g b)) where\n\n{- The base HIT -}\n\nimport lib.types.Generic1HIT as Generic1HIT\n\nmodule W = Generic1HIT A B f g\nopen W public using (cc; pp)\n renaming (T to W)\n\nmodule P = W.RecType C D\nopen P public -- using (↓-pp-in; ↓-pp-out; ↓-pp-β)\n renaming (f to P)\n\n{- The flattened HIT -}\n\nAt : Type _\nAt = Σ A C\n\nBt : Type _\nBt = Σ B (C ∘ f)\n\nft : Bt → At\nft (b , d) = (f b , d)\n\ngt : Bt → At\ngt (b , d) = (g b , –> (D b) d)\n\nmodule Wt = Generic1HIT At Bt ft gt\nopen Wt public using ()\n renaming (T to Wt)\n\ncct = curry Wt.cc\nppt = curry Wt.pp\n\nprivate\n {- Flattening -}\n\n module _ where\n paths-flatten :\n (b : B) → (cct (f b) == cct (g b) [ (λ w → (P w → Wt)) ↓ pp b ])\n paths-flatten b =\n ↓-app→cst-in (λ q → ppt b _ ∙' ap (cct (g b)) (↓-pp-out q))\n\n module FlattenCurried = W.Elim cct paths-flatten\n\n flatten-curried : (w : W) → (P w → Wt)\n flatten-curried = W.Elim.f cct paths-flatten\n\n flatten : Σ W P → Wt\n flatten (w , x) = flatten-curried w x\n\n {- Unflattening -}\n\n\n unflatten-cc : (ac : At) → Σ W P\n unflatten-cc (a , c) = (cc a , c)\n\n unflatten-pp : (bd : Bt) → unflatten-cc (ft bd) == unflatten-cc (gt bd)\n unflatten-pp (b , d) = pair= (pp b) (↓-pp-in idp)\n\n module Unflatten = Wt.Rec unflatten-cc unflatten-pp\n\n unflatten : Wt → Σ W P\n unflatten = Unflatten.f\n\n {- First composition -}\n\n flatten-unflatten : (w : Wt) → flatten (unflatten w) == w\n flatten-unflatten = Wt.elim\n (λ _ → idp)\n (λ bd → let (b , d) = bd in\n ↓-∘=idf-in flatten unflatten\n (ap flatten (ap unflatten (ppt b d))\n =⟨ Unflatten.pp-β bd |in-ctx ap flatten ⟩\n ap flatten (pair= (pp b) (↓-pp-in idp))\n =⟨ split-ap2 flatten (pp b) (↓-pp-in idp) ⟩\n ↓-app→cst-out (apd flatten-curried (pp b)) (↓-pp-in idp)\n =⟨ FlattenCurried.pp-β b\n |in-ctx (λ u → ↓-app→cst-out u (↓-pp-in idp)) ⟩\n ↓-app→cst-out (paths-flatten b) (↓-pp-in idp)\n =⟨ idp ⟩\n ↓-app→cst-out (↓-app→cst-in\n (λ q → ppt b _ ∙' ap (cct (g b)) (↓-pp-out q))) (↓-pp-in idp)\n =⟨ ↓-app→cst-β (λ q → ppt b _ ∙' ap (cct (g b)) (↓-pp-out q))\n (↓-pp-in idp) ⟩\n ppt b d ∙' ap (cct (g b)) (↓-pp-out (↓-pp-in idp))\n =⟨ ↓-pp-β idp |in-ctx (λ u → ppt b d ∙' ap (cct (g b)) u) ⟩\n ppt b d ∎))\n\n {- Second composition -}\n\n unflatten-flatten-curried : (w : W) (x : P w)\n → unflatten (flatten-curried w x) == (w , x)\n unflatten-flatten-curried = W.elim\n (λ a x → idp)\n (λ b → ↓-Π-in\n (λ q → ↓-∘=idf-in unflatten flatten\n (ap unflatten (ap flatten (pair= (pp b) q))\n =⟨ split-ap2 flatten (pp b) q |in-ctx ap unflatten ⟩\n ap unflatten (↓-app→cst-out (apd flatten-curried (pp b)) q)\n =⟨ FlattenCurried.pp-β b\n |in-ctx (λ u → ap unflatten (↓-app→cst-out u q)) ⟩\n ap unflatten (↓-app→cst-out (paths-flatten b) q)\n =⟨ idp ⟩\n ap unflatten (↓-app→cst-out (↓-app→cst-in (λ qq → ppt b _ ∙' ap (cct (g b)) (↓-pp-out qq))) q)\n =⟨ ↓-app→cst-β (λ qq → ppt b _ ∙' ap (cct (g b)) (↓-pp-out qq)) q |in-ctx ap unflatten ⟩\n ap unflatten (ppt b _ ∙' ap (cct (g b)) (↓-pp-out q))\n =⟨ ap-∙' unflatten (ppt b _) (ap (cct (g b)) (↓-pp-out q)) ⟩\n ap unflatten (ppt b _) ∙' ap unflatten (ap (cct (g b)) (↓-pp-out q))\n =⟨ Unflatten.pp-β (b , _) |in-ctx (λ u → u ∙' ap unflatten (ap (cct (g b)) (↓-pp-out q))) ⟩\n pair= (pp b) (↓-pp-in idp) ∙' ap unflatten (ap (cct (g b)) (↓-pp-out q))\n =⟨ ∘-ap unflatten (cct (g b)) (↓-pp-out q) |in-ctx (λ u → (pair= (pp b) (↓-pp-in idp) ∙' u)) ⟩\n pair= (pp b) (↓-pp-in idp) ∙' ap (unflatten ∘ cct (g b)) (↓-pp-out q)\n =⟨ idp ⟩\n pair= (pp b) (↓-pp-in idp) ∙' ap (λ x → (cc (g b), x)) (↓-pp-out q)\n =⟨ ap-cst,id P (↓-pp-out q) |in-ctx (λ u → pair= (pp b) (↓-pp-in idp) ∙' u) ⟩\n pair= (pp b) (↓-pp-in idp) ∙' pair= idp (↓-pp-out q)\n =⟨ Σ-∙' (↓-pp-in idp) (↓-pp-out q) ⟩\n pair= (pp b) (↓-pp-in idp ∙'ᵈ ↓-pp-out q)\n =⟨ to-transp-weird q (coe-pp-β _ _) |in-ctx pair= (pp b) ⟩\n pair= (pp b) q ∎)))\n\n unflatten-flatten : (wx : Σ W P) → unflatten (flatten wx) == wx\n unflatten-flatten (w , x) = unflatten-flatten-curried w x\n\n{- The equivalence -}\n\nabstract\n flattening-equiv : Σ W P ≃ Wt\n flattening-equiv = equiv flatten unflatten flatten-unflatten unflatten-flatten\n", "meta": {"hexsha": "a4db40cef5956e7bb3cc32546f3903afbc423dbd", "size": 4800, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lib/types/Flattening.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": "lib/types/Flattening.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": "lib/types/Flattening.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": 34.0425531915, "max_line_length": 111, "alphanum_fraction": 0.5010416667, "num_tokens": 1904, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.5312093733737562, "lm_q1q2_score": 0.38834516945355374}} {"text": "{-# OPTIONS --cubical --no-import-sorts #-}\n\nmodule Number.Instances.QuoQ.Instance where\n\n\nopen import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)\nopen import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)\nopen import Cubical.Foundations.Logic renaming (inl to inlᵖ; inr to inrᵖ)\n\nopen import Cubical.Relation.Nullary.Base renaming (¬_ to ¬ᵗ_)\nopen import Cubical.Relation.Binary.Base\nopen import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_)\nopen import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Bool as Bool using (Bool; not; true; false)\nopen import Cubical.Data.Empty renaming (elim to ⊥-elim; ⊥ to ⊥⊥) -- `⊥` and `elim`\nopen import Cubical.Foundations.Logic renaming (¬_ to ¬ᵖ_; inl to inlᵖ; inr to inrᵖ)\nopen import Function.Base using (it; _∋_; _$_)\nopen import Cubical.Foundations.Isomorphism\n\nopen import Cubical.HITs.PropositionalTruncation renaming (elim to ∣∣-elim)\n\nopen import Utils using (!_; !!_)\nopen import MoreLogic.Reasoning\nopen import MoreLogic.Definitions\nopen import MoreLogic.Properties\nopen import MorePropAlgebra.Definitions hiding (_≤''_)\nopen import MorePropAlgebra.Structures\nopen import MorePropAlgebra.Bundles\nopen import MorePropAlgebra.Consequences\nopen import Number.Structures2\nopen import Number.Bundles2\n\nopen import Cubical.Data.NatPlusOne using (HasFromNat; 1+_; ℕ₊₁; ℕ₊₁→ℕ) renaming\n ( _*₊₁_ to _·₊₁_\n ; *₊₁-comm to ·₊₁-comm\n ; *₊₁-assoc to ·₊₁-assoc\n ; *₊₁-identityˡ to ·₊₁-identityˡ\n ; *₊₁-identityʳ to ·₊₁-identityʳ\n )\nopen import Cubical.HITs.SetQuotients as SetQuotient using () renaming (_/_ to _//_)\n\nopen import Cubical.Data.Nat.Literals\nopen import Cubical.Data.Bool\nopen import Number.Prelude.Nat\nopen import Number.Prelude.QuoInt\nopen import Cubical.HITs.Ints.QuoInt using (HasFromNat)\nopen import Number.Instances.QuoQ.Definitions\nopen import Cubical.HITs.Rationals.QuoQ using\n ( ℚ\n ; HasFromNat\n ; isSetℚ\n ; onCommonDenom\n ; onCommonDenomSym\n ; eq/\n ; eq/⁻¹\n ; _//_\n ; _∼_\n ; [_/_]\n ) renaming\n ( [_] to [_]ᶠ\n ; ℕ₊₁→ℤ to [1+_ⁿ]ᶻ\n ; _*_ to _·_\n ; *-comm to ·-comm\n ; *-assoc to ·-assoc\n )\n\n{-# DISPLAY [_/_] (pos 1) (1+ 0) = 1 #-}\n{-# DISPLAY [_/_] (pos 0) (1+ 0) = 0 #-}\n\nprivate\n ·ᶻ-commʳ : ∀ a b c → (a ·ᶻ b) ·ᶻ c ≡ (a ·ᶻ c) ·ᶻ b\n ·ᶻ-commʳ a b c = (a ·ᶻ b) ·ᶻ c ≡⟨ sym $ ·ᶻ-assoc a b c ⟩\n a ·ᶻ (b ·ᶻ c) ≡⟨ (λ i → a ·ᶻ ·ᶻ-comm b c i) ⟩\n a ·ᶻ (c ·ᶻ b) ≡⟨ ·ᶻ-assoc a c b ⟩\n (a ·ᶻ c) ·ᶻ b ∎\n\n ·ᶻ-commˡ : ∀ a b c → a ·ᶻ (b ·ᶻ c) ≡ b ·ᶻ (a ·ᶻ c)\n ·ᶻ-commˡ a b c = ·ᶻ-comm a (b ·ᶻ c) ∙ sym (·ᶻ-commʳ b a c) ∙ sym (·ᶻ-assoc b a c)\n\n is-0<ⁿᶻ : ∀{aⁿ} → [ 0 <ᶻ [1+ aⁿ ⁿ]ᶻ ]\n is-0<ⁿᶻ {aⁿ} = ℕ₊₁.n aⁿ , +ⁿ-comm (ℕ₊₁.n aⁿ) 1\n\n is-0≤ⁿᶻ : ∀{aⁿ} → [ 0 ≤ᶻ [1+ aⁿ ⁿ]ᶻ ]\n is-0≤ⁿᶻ (k , p) = snotzⁿ $ sym (+ⁿ-suc k _) ∙ p\n\n<-irrefl : ∀ a → [ ¬(a < a) ]\n<-irrefl = SetQuotient.elimProp {R = _∼_} (λ a → isProp[] (¬(a < a))) γ where\n γ : (a : ℤ × ℕ₊₁) → [ ¬([ a ]ᶠ < [ a ]ᶠ) ]\n γ a@(aᶻ , aⁿ) = κ where\n aⁿᶻ = [1+ aⁿ ⁿ]ᶻ\n κ : [ ¬((aᶻ ·ᶻ aⁿᶻ) <ᶻ (aᶻ ·ᶻ aⁿᶻ)) ]\n κ = <ᶻ-irrefl (aᶻ ·ᶻ aⁿᶻ)\n\n\n<-trans : (a b c : ℚ) → [ a < b ] → [ b < c ] → [ a < c ]\n<-trans = SetQuotient.elimProp3 {R = _∼_} (λ a b c → isProp[] ((a < b) ⇒ (b < c) ⇒ (a < c))) γ where\n γ : (a b c : ℤ × ℕ₊₁) → [ [ a ]ᶠ < [ b ]ᶠ ] → [ [ b ]ᶠ < [ c ]ᶠ ] → [ [ a ]ᶠ < [ c ]ᶠ ]\n γ a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) c@(cᶻ , cⁿ) = κ where\n aⁿᶻ = [1+ aⁿ ⁿ]ᶻ\n bⁿᶻ = [1+ bⁿ ⁿ]ᶻ\n cⁿᶻ = [1+ cⁿ ⁿ]ᶻ\n 0*_ : (A → B) * → A * → B *\n _+<*>*_ : (A → B) + → A * → B *\n _*<*>+_ : (A → B) * → A + → B *\n _+<*>+_ : (A → B) + → A + → B +\n\n [] *<*>* xs = []\n (∹ fs) *<*>* xs = fs +<*>* xs\n\n fs +<*>* xs = map* (head fs) xs ++* (tail fs *<*>* xs)\n\n [] *<*>+ xs = []\n (∹ fs) *<*>+ xs = ∹ fs +<*>+ xs\n\n fs +<*>+ xs = map+ (head fs) xs Concat.+++* (tail fs *<*>+ xs)\nopen Apply public using () renaming (_*<*>*_ to _<*>*_; _+<*>+_ to _<*>+_)\n\n------------------------------------------------------------------------\n-- Monadic Operations\n\nmodule Bind where\n _+>>=+_ : A + → (A → B +) → B +\n _+>>=*_ : A + → (A → B *) → B *\n _*>>=+_ : A * → (A → B +) → B *\n _*>>=*_ : A * → (A → B *) → B *\n\n (x & xs) +>>=+ k = k x Concat.+++* (xs *>>=+ k)\n\n (x & xs) +>>=* k = k x Concat.*++* (xs *>>=* k)\n\n [] *>>=* k = []\n (∹ xs) *>>=* k = xs +>>=* k\n\n [] *>>=+ k = []\n (∹ xs) *>>=+ k = ∹ xs +>>=+ k\nopen Bind public using () renaming (_*>>=*_ to _>>=*_; _+>>=+_ to _>>=+_)\n\n------------------------------------------------------------------------\n-- Scans\n\nmodule Scanr (f : A → B → B) (b : B) where\n cons : A → B + → B +\n head (cons x xs) = f x (head xs)\n tail (cons x xs) = ∹ xs\n\n scanr+ : A + → B +\n scanr* : A * → B +\n\n scanr* = foldr* cons (b & [])\n scanr+ = foldr+ cons (b & [])\nopen Scanr public using (scanr+; scanr*)\n\nmodule _ (f : B → A → B) where\n scanl* : B → A * → B +\n head (scanl* b xs) = b\n tail (scanl* b []) = []\n tail (scanl* b (∹ xs)) = ∹ scanl* (f b (head xs)) (tail xs)\n\n scanl+ : B → A + → B +\n head (scanl+ b xs) = b\n tail (scanl+ b xs) = ∹ scanl* (f b (head xs)) (tail xs)\n\n scanl₁ : B → A + → B +\n scanl₁ b xs = scanl* (f b (head xs)) (tail xs)\n\n------------------------------------------------------------------------\n-- Accumulating maps\n\nmodule _ (f : B → A → (B × C)) where\n mapAccumˡ* : B → A * → (B × C *)\n mapAccumˡ+ : B → A + → (B × C +)\n\n mapAccumˡ* b [] = b , []\n mapAccumˡ* b (∹ xs) = map₂ ∹_ (mapAccumˡ+ b xs)\n\n mapAccumˡ+ b (x & xs) =\n let y , ys = f b x\n z , zs = mapAccumˡ* y xs\n in z , ys & zs\n\nmodule _ (f : A → B → (C × B)) (b : B) where\n mapAccumʳ* : A * → (C * × B)\n mapAccumʳ+ : A + → (C + × B)\n\n mapAccumʳ* [] = [] , b\n mapAccumʳ* (∹ xs) = map₁ ∹_ (mapAccumʳ+ xs)\n\n mapAccumʳ+ (x & xs) =\n let ys , y = mapAccumʳ* xs\n zs , z = f x y\n in zs & ys , z\n\n------------------------------------------------------------------------\n-- Non-Empty Folds\n\nlast : A + → A\nlast (x & []) = x\nlast (_ & ∹ xs) = last xs\n\nmodule _ (f : A → A → A) where\n foldr₁ : A + → A\n foldr₁ (x & []) = x\n foldr₁ (x & ∹ xs) = f x (foldr₁ xs)\n\n foldl₁ : A + → A\n foldl₁ (x & xs) = foldl* f x xs\n\nmodule _ (f : A → Maybe B → B) where\n foldrMaybe* : A * → Maybe B\n foldrMaybe+ : A + → B\n\n foldrMaybe* [] = nothing\n foldrMaybe* (∹ xs) = just (foldrMaybe+ xs)\n\n foldrMaybe+ xs = f (head xs) (foldrMaybe* (tail xs))\n\n------------------------------------------------------------------------\n-- Indexing\n\n_[_]* : A * → ℕ → Maybe A\n_[_]+ : A + → ℕ → Maybe A\n\n[] [ _ ]* = nothing\n(∹ xs) [ i ]* = xs [ i ]+\n\nxs [ zero ]+ = just (head xs)\nxs [ suc i ]+ = tail xs [ i ]*\n\napplyUpTo* : (ℕ → A) → ℕ → A *\napplyUpTo+ : (ℕ → A) → ℕ → A +\n\napplyUpTo* f zero = []\napplyUpTo* f (suc n) = ∹ applyUpTo+ f n\n\nhead (applyUpTo+ f n) = f zero\ntail (applyUpTo+ f n) = applyUpTo* (f ∘ suc) n\n\nupTo* : ℕ → ℕ *\nupTo* = applyUpTo* id\n\nupTo+ : ℕ → ℕ +\nupTo+ = applyUpTo+ id\n\n------------------------------------------------------------------------\n-- Manipulation\n\nmodule ZipWith (f : A → B → C) where\n +zipWith+ : A + → B + → C +\n *zipWith+ : A * → B + → C *\n +zipWith* : A + → B * → C *\n *zipWith* : A * → B * → C *\n\n head (+zipWith+ xs ys) = f (head xs) (head ys)\n tail (+zipWith+ xs ys) = *zipWith* (tail xs) (tail ys)\n\n *zipWith+ [] ys = []\n *zipWith+ (∹ xs) ys = ∹ +zipWith+ xs ys\n\n +zipWith* xs [] = []\n +zipWith* xs (∹ ys) = ∹ +zipWith+ xs ys\n\n *zipWith* [] ys = []\n *zipWith* (∹ xs) ys = +zipWith* xs ys\nopen ZipWith public renaming (+zipWith+ to zipWith+; *zipWith* to zipWith*)\n\nmodule Unzip (f : A → B × C) where\n cons : B × C → B * × C * → B + × C +\n cons = Product.zip′ _&_ _&_\n\n unzipWith* : A * → B * × C *\n unzipWith+ : A + → B + × C +\n\n unzipWith* = foldr* (λ x xs → Product.map ∹_ ∹_ (cons (f x) xs)) ([] , [])\n\n unzipWith+ xs = cons (f (head xs)) (unzipWith* (tail xs))\nopen Unzip using (unzipWith+; unzipWith*) public\n\nmodule Partition (f : A → B ⊎ C) where\n cons : B ⊎ C → B * × C * → B * × C *\n proj₁ (cons (inj₁ x) xs) = ∹ x & proj₁ xs\n proj₂ (cons (inj₁ x) xs) = proj₂ xs\n proj₂ (cons (inj₂ x) xs) = ∹ x & proj₂ xs\n proj₁ (cons (inj₂ x) xs) = proj₁ xs\n\n partitionSumsWith* : A * → B * × C *\n partitionSumsWith+ : A + → B * × C *\n\n partitionSumsWith* = foldr* (cons ∘ f) ([] , [])\n\n partitionSumsWith+ = foldr+ (cons ∘ f) ([] , [])\nopen Partition using (partitionSumsWith+; partitionSumsWith*) public\n\ntails* : A * → (A +) *\ntails+ : A + → (A +) +\n\nhead (tails+ xs) = xs\ntail (tails+ xs) = tails* (tail xs)\n\ntails* [] = []\ntails* (∹ xs) = ∹ tails+ xs\n\nreverse* : A * → A *\nreverse* = foldl* (λ xs x → ∹ x & xs) []\n\nreverse+ : A + → A +\nreverse+ (x & xs) = foldl* (λ ys y → y & ∹ ys) (x & []) xs\n", "meta": {"hexsha": "221bb494bd8f86f5e1c2c742c8475bb449ebee36", "size": 9156, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib/src/Data/List/Kleene/Base.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "agda-stdlib/src/Data/List/Kleene/Base.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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-stdlib/src/Data/List/Kleene/Base.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 25.4333333333, "max_line_length": 78, "alphanum_fraction": 0.4377457405, "num_tokens": 3277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.6297746213017459, "lm_q1q2_score": 0.38736672127493377}} {"text": "module Implicits.Resolution.Ambiguous.SystemFEquiv where\n\nopen import Prelude\n\nopen import Function.Equivalence using (_⇔_; equivalence)\nopen import Data.List.Properties\nopen import Relation.Binary.HeterogeneousEquality as H using ()\nopen import Data.Vec.Properties as VP using ()\nopen import Data.Vec hiding ([_])\nopen import Extensions.Vec\nopen import Data.List as List using ()\nopen import Data.Product hiding (map)\n\nopen import Implicits.Syntax\nopen import Implicits.Resolution.Ambiguous.Resolution\nopen import Implicits.Resolution.Embedding\nopen import Implicits.Resolution.Embedding.Lemmas\n\nopen import SystemF.Everything\n as F using ()\n\n⟦_⟧term→ : ∀ {ν} {Δ : ICtx ν} {r} → Δ ⊢ᵣ r → F.Term ν (List.length (List.map ⟦_⟧tp→ Δ))\n⟦_⟧term→ {ν} {Δ} (r-tabs x) = F.Λ (subst (F.Term (suc ν)) (length-weaken-Δ Δ) ⟦ x ⟧term→)\n⟦ r-tapp a x ⟧term→ = ⟦ x ⟧term→ F.[ ⟦ a ⟧tp→ ]\n⟦_⟧term→ {Δ = Δ} (r-ivar x) =\n F.var (subst Fin (sym $ length-map _ Δ) (proj₁ $ ∈⟶index (VP.List-∈⇒∈ x)))\n⟦ r-iabs {a = a} x ⟧term→ = F.λ' ⟦ a ⟧tp→ ⟦ x ⟧term→\n⟦ r-iapp f e ⟧term→ = ⟦ f ⟧term→ F.· ⟦ e ⟧term→\n\nfrom-⊢ : ∀ {ν n t a} {Γ : F.Ctx ν n} → Γ F.⊢ t ∈ a → ⟦ Γ ⟧ctx← ⊢ᵣ ⟦ a ⟧tp←\nfrom-⊢ (F.var x) = r-ivar (lookup-∈ x _)\nfrom-⊢ {Γ = Γ} (F.Λ x) = r-tabs (subst (λ u → u ⊢ᵣ _) (⟦weaken⟧ctx← Γ) (from-⊢ x))\nfrom-⊢ (F.λ' {b = b} a x) = r-iabs (from-⊢ x)\nfrom-⊢ {Γ = Γ} (F._[_] {a = a} x b) = subst\n (λ u → ⟦ Γ ⟧ctx← ⊢ᵣ u)\n (sym (⟦a/sub⟧tp← a b))\n (r-tapp ⟦ b ⟧tp← (from-⊢ x))\nfrom-⊢ (a F.· b) = r-iapp (from-⊢ a) (from-⊢ b)\n\nto-⊢ : ∀ {ν} {Δ : ICtx ν} {r} → (p : Δ ⊢ᵣ r) → ⟦ Δ ⟧ctx→ F.⊢ ⟦ p ⟧term→ ∈ ⟦ r ⟧tp→\nto-⊢ {Δ = Δ} (r-tabs {r = r} p) with to-⊢ p\nto-⊢ {Δ = Δ} (r-tabs {r = r} p) | x =\n F.Λ (⊢subst-n (length-weaken-Δ Δ) (H.sym (⟦weaken⟧ctx→ Δ)) x)\nto-⊢ (r-tapp a p) with to-⊢ p\nto-⊢ {Δ = Δ} (r-tapp {r = a} b p) | x =\n subst\n (λ u → ⟦ Δ ⟧ctx→ F.⊢ ⟦ p ⟧term→ F.[ ⟦ b ⟧tp→ ] ∈ u)\n (sym $ ⟦a/sub⟧tp→ a b)\n (x F.[ ⟦ b ⟧tp→ ])\nto-⊢ {Δ = Δ} {r = r} (r-ivar x) =\n let i , eq = ∈⟶index (VP.List-∈⇒∈ x) in\n let i' = (subst Fin (sym $ length-map _ Δ) i) in\n subst (λ u → ⟦ Δ ⟧ctx→ F.⊢ (F.var i') ∈ u) (lookup⟦⟧ Δ i eq) (F.var i')\nto-⊢ (r-iabs {a = a} p) = F.λ' ⟦ a ⟧tp→ (to-⊢ p)\nto-⊢ (r-iapp p p₁) = (to-⊢ p) F.· (to-⊢ p₁)\n\nequivalent : ∀ {ν} (Δ : ICtx ν) r → Δ ⊢ᵣ r ⇔ (∃ λ t → ⟦ Δ ⟧ctx→ F.⊢ t ∈ ⟦ r ⟧tp→)\nequivalent Δ r = equivalence\n (λ x → , (to-⊢ x))\n (λ x → subst₂ (λ Δ' r' → Δ' ⊢ᵣ r') (ctx→← _) (tp→← r) (from-⊢ (proj₂ x)))\n\n⊢subst : ∀ {ν n n'} {a a' : F.Type ν} {Γ : F.Ctx ν n} {Γ' : F.Ctx ν n'} →\n n ≡ n' → a ≡ a' → Γ H.≅ Γ' →\n (∃ λ t → Γ F.⊢ t ∈ a) →\n ∃ λ t → Γ' F.⊢ t ∈ a'\n⊢subst refl refl H.refl p = p\n\nequivalent' : ∀ {ν n} (Γ : F.Ctx ν n) r → ⟦ Γ ⟧ctx← ⊢ᵣ ⟦ r ⟧tp← ⇔ (∃ λ t → Γ F.⊢ t ∈ r)\nequivalent' Γ r = equivalence\n (λ x → ⊢subst\n (length-map-toList (map ⟦_⟧tp← Γ)) (tp←→ r) (ctx←→ Γ) (, to-⊢ x))\n (λ x → (from-⊢ (proj₂ x)))\n", "meta": {"hexsha": "b0ab24b0eb67e95629fc8ea5c585c5b58946538d", "size": 2872, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Implicits/Resolution/Ambiguous/SystemFEquiv.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/Ambiguous/SystemFEquiv.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/Ambiguous/SystemFEquiv.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": 39.3424657534, "max_line_length": 89, "alphanum_fraction": 0.5156685237, "num_tokens": 1473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6150878414043814, "lm_q2_score": 0.6297746004557471, "lm_q1q2_score": 0.38736669956563224}} {"text": "open import Data.Product using ( ∃ ; _×_ ; _,_ ; proj₁ ; proj₂ )\nopen import Relation.Unary using ( _∈_ )\nopen import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ; cong )\nopen import Web.Semantic.DL.ABox.Interp using ( Interp ; _,_ ; ⌊_⌋ ; ind ; _*_ )\nopen import Web.Semantic.DL.Signature using ( Signature )\nopen import Web.Semantic.DL.TBox.Interp using \n ( Δ ; _⊨_≈_ ; ≈-refl ; ≈-sym ; ≈-trans ) renaming\n ( Interp to Interp′ )\nopen import Web.Semantic.DL.TBox.Interp.Morphism using \n ( ≲-image ; ≃-image ; ≃-image⁻¹ ; ≲-resp-≈ ; ≃-resp-≈ ; ≃-iso ) renaming \n ( _≲_ to _≲′_ ; _≃_ to _≃′_ \n ; ≲-refl to ≲′-refl ; ≲-trans to ≲′-trans\n ; ≃-refl to ≃′-refl ; ≃-sym to ≃′-sym ; ≃-trans to ≃′-trans \n ; ≃-impl-≲ to ≃-impl-≲′ )\nopen import Web.Semantic.Util using\n ( _∘_ ; _⊕_⊕_ ; inode ; bnode ; enode ; →-dist-⊕ )\n\nmodule Web.Semantic.DL.ABox.Interp.Morphism {Σ : Signature} where\n\ninfix 2 _≲_ _≃_ _≋_\ninfixr 4 _,_\ninfix 5 _**_ \n\ndata _≲_ {X} (I J : Interp Σ X) : Set where\n _,_ : ∀ (I≲J : ⌊ I ⌋ ≲′ ⌊ J ⌋) → \n (i≲j : ∀ x → (⌊ J ⌋ ⊨ ≲-image I≲J (ind I x) ≈ ind J x)) → \n (I ≲ J)\n\n≲⌊_⌋ : ∀ {X} {I J : Interp Σ X} → (I ≲ J) → (⌊ I ⌋ ≲′ ⌊ J ⌋)\n≲⌊_⌋ (I≲J , i≲j) = I≲J\n\n≲-resp-ind : ∀ {X} {I J : Interp Σ X} → (I≲J : I ≲ J) →\n ∀ x → (⌊ J ⌋ ⊨ ≲-image ≲⌊ I≲J ⌋ (ind I x) ≈ ind J x)\n≲-resp-ind (I≲J , i≲j) = i≲j\n\n≲-refl : ∀ {X} (I : Interp Σ X) → (I ≲ I)\n≲-refl I = (≲′-refl ⌊ I ⌋ , λ x → ≈-refl ⌊ I ⌋)\n\n≲-trans : ∀ {X} {I J K : Interp Σ X} → (I ≲ J) → (J ≲ K) → (I ≲ K)\n≲-trans {X} {I} {J} {K} I≲J J≲K =\n (≲′-trans ≲⌊ I≲J ⌋ ≲⌊ J≲K ⌋ , λ x → ≈-trans ⌊ K ⌋ (≲-resp-≈ ≲⌊ J≲K ⌋ (≲-resp-ind I≲J x)) (≲-resp-ind J≲K x))\n\n≡-impl-≈ : ∀ {X : Set} (I : Interp′ Σ) {i j : X → Δ I} → \n (i ≡ j) → (∀ x → I ⊨ i x ≈ j x)\n≡-impl-≈ I refl x = ≈-refl I\n\n≡³-impl-≈ : ∀ {V X Y : Set} (I : Interp′ Σ) (i j : (X ⊕ V ⊕ Y) → Δ I) →\n (→-dist-⊕ i ≡ →-dist-⊕ j) → (∀ x → I ⊨ i x ≈ j x)\n≡³-impl-≈ I i j i≡j (inode x) = ≡-impl-≈ I (cong proj₁ i≡j) x\n≡³-impl-≈ I i j i≡j (bnode v) = ≡-impl-≈ I (cong proj₁ (cong proj₂ i≡j)) v\n≡³-impl-≈ I i j i≡j (enode y) = ≡-impl-≈ I (cong proj₂ (cong proj₂ i≡j)) y\n\n≡-impl-≲ : ∀ {X : Set} (I : Interp Σ X) j →\n (ind I ≡ j) → (I ≲ (⌊ I ⌋ , j))\n≡-impl-≲ (I , i) .i refl = ≲-refl (I , i)\n\n≡³-impl-≲ : ∀ {V X Y : Set} (I : Interp Σ (X ⊕ V ⊕ Y)) j →\n (→-dist-⊕ (ind I) ≡ →-dist-⊕ j) → (I ≲ (⌊ I ⌋ , j))\n≡³-impl-≲ (I , i) j i≡j = (≲′-refl I , ≡³-impl-≈ I i j i≡j)\n\n_**_ : ∀ {X Y I J} (f : Y → X) → (I ≲ J) → (f * I ≲ f * J)\nf ** I≲J = (≲⌊ I≲J ⌋ , λ x → ≲-resp-ind I≲J (f x))\n\n_≋_ : ∀ {X} {I J : Interp Σ X} → (I ≲ J) → (I ≲ J) → Set\n_≋_ {X} {I} {J} I≲₁J I≲₂J = ∀ x → (⌊ J ⌋ ⊨ ≲-image ≲⌊ I≲₁J ⌋ x ≈ ≲-image ≲⌊ I≲₂J ⌋ x)\n\ndata _≃_ {X} (I J : Interp Σ X) : Set₁ where\n _,_ : (I≃J : ⌊ I ⌋ ≃′ ⌊ J ⌋) → \n (∀ x → (⌊ J ⌋ ⊨ ≃-image I≃J (ind I x) ≈ ind J x)) →\n (I ≃ J)\n\n≃⌊_⌋ : ∀ {X} {I J : Interp Σ X} → (I ≃ J) → (⌊ I ⌋ ≃′ ⌊ J ⌋)\n≃⌊_⌋ (I≃J , i≃j) = I≃J\n\n≃-impl-≲ : ∀ {X} {I J : Interp Σ X} → (I ≃ J) → (I ≲ J)\n≃-impl-≲ (I≃J , i≃j) = (≃-impl-≲′ I≃J , i≃j)\n\n≃-resp-ind : ∀ {X} {I J : Interp Σ X} → (I≃J : I ≃ J) →\n ∀ x → (⌊ J ⌋ ⊨ ≃-image ≃⌊ I≃J ⌋ (ind I x) ≈ ind J x)\n≃-resp-ind (I≃J , i≃j) = i≃j\n\n≃-resp-ind⁻¹ : ∀ {X} {I J : Interp Σ X} → (I≃J : I ≃ J) →\n ∀ x → (⌊ I ⌋ ⊨ ≃-image⁻¹ ≃⌊ I≃J ⌋ (ind J x) ≈ ind I x)\n≃-resp-ind⁻¹ {X} {I , i} {J , j} (I≃J , i≃j) x =\n ≈-trans I (≃-resp-≈ (≃′-sym I≃J) (≈-sym J (i≃j x))) (≃-iso I≃J (i x))\n\n≃-refl : ∀ {X} (I : Interp Σ X) → (I ≃ I)\n≃-refl (I , i) = (≃′-refl I , λ x → ≈-refl I)\n\n≃-symm : ∀ {X} {I J : Interp Σ X} → (I ≃ J) → (J ≃ I)\n≃-symm {X} {I , i} {J , j} (I≃J , i≃j) =\n (≃′-sym I≃J , ≃-resp-ind⁻¹ {X} {I , i} {J , j} (I≃J , i≃j))\n\n≃-trans : ∀ {X} {I J K : Interp Σ X} → (I ≃ J) → (J ≃ K) → (I ≃ K)\n≃-trans {X} {I , i} {J , j} {K , k} (I≃J , i≃j) (J≃K , j≃k) =\n (≃′-trans I≃J J≃K , λ x → ≈-trans K (≃-resp-≈ J≃K (i≃j x)) (j≃k x))\n\n", "meta": {"hexsha": "945bf224457e61c63382c05e77bd57b72866e583", "size": 3809, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Web/Semantic/DL/ABox/Interp/Morphism.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/Interp/Morphism.agda", "max_issues_repo_name": "bblfish/agda-web-semantic", "max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "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/Interp/Morphism.agda", "max_forks_repo_name": "bblfish/agda-web-semantic", "max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "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": 38.8673469388, "max_line_length": 110, "alphanum_fraction": 0.4321344185, "num_tokens": 2387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.38726046667351066}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import homotopy.EilenbergMacLane\nopen import homotopy.EilenbergMacLane1\nopen import homotopy.EilenbergMacLaneFunctor\nopen import homotopy.EM1HSpaceAssoc\nopen import lib.types.TwoSemiCategory\nopen import lib.two-semi-categories.FunCategory\nopen import lib.two-semi-categories.FundamentalCategory\n\nmodule cohomology.CupProduct.OnEM.InLowDegrees {i} {j} (G : AbGroup i) (H : AbGroup j) where\n\nprivate\n module G = AbGroup G\n module H = AbGroup H\n module G⊗H = TensorProduct G H\n open G⊗H using (_⊗_)\n open EMExplicit\n\n⊙×-cp₀₀' : G.⊙El ⊙× H.⊙El ⊙→ G⊗H.⊙El\n⊙×-cp₀₀' = uncurry G⊗H._⊗_ , G⊗H.⊗-unit-l H.ident\n\n⊙×-cp₀₀-seq : (⊙EM G 0 ⊙× ⊙EM H 0) ⊙–→ ⊙EM G⊗H.abgroup 0\n⊙×-cp₀₀-seq =\n ⊙–> (⊙emloop-equiv G⊗H.grp) ◃⊙∘\n ⊙×-cp₀₀' ◃⊙∘\n ⊙×-fmap (⊙<– (⊙emloop-equiv G.grp)) (⊙<– (⊙emloop-equiv H.grp)) ◃⊙idf\n\n⊙×-cp₀₀ : ⊙EM G 0 ⊙× ⊙EM H 0 ⊙→ ⊙EM G⊗H.abgroup 0\n⊙×-cp₀₀ = ⊙compose ⊙×-cp₀₀-seq\n\n×-cp₀₀ : EM G 0 × EM H 0 → EM G⊗H.abgroup 0\n×-cp₀₀ = fst ⊙×-cp₀₀\n\nopen EM₁HSpaceAssoc G⊗H.abgroup hiding (comp-functor) renaming (mult to EM₁-mult) public\n\ncp₀₁ : G.El → EM₁ H.grp → EM₁ G⊗H.grp\ncp₀₁ g = EM₁-fmap (G⊗H.ins-r-hom g)\n\nabstract\n cp₀₁-emloop-β : ∀ g h → ap (cp₀₁ g) (emloop h) == emloop (g ⊗ h)\n cp₀₁-emloop-β g = EM₁-fmap-emloop-β (G⊗H.ins-r-hom g)\n\ncp₀₁-distr-l : (g₁ g₂ : G.El) (y : EM₁ H.grp)\n → cp₀₁ (G.comp g₁ g₂) y == EM₁-mult (cp₀₁ g₁ y) (cp₀₁ g₂ y)\ncp₀₁-distr-l g₁ g₂ =\n EM₁-set-elim\n {P = λ x → f x == g x}\n {{λ x → has-level-apply (EM₁-level₁ G⊗H.grp) _ _}}\n idp loop'\n where\n f : EM₁ H.grp → EM₁ G⊗H.grp\n f x = cp₀₁ (G.comp g₁ g₂) x\n g : EM₁ H.grp → EM₁ G⊗H.grp\n g x = EM₁-mult (cp₀₁ g₁ x) (cp₀₁ g₂ x)\n abstract\n loop' : (h : H.El) → idp == idp [ (λ x → f x == g x) ↓ emloop h ]\n loop' h = ↓-='-in {f = f} {g = g} {p = emloop h} {u = idp} {v = idp} $\n idp ∙' ap g (emloop h)\n =⟨ ∙'-unit-l (ap g (emloop h)) ⟩\n ap g (emloop h)\n =⟨ ! (ap2-diag (λ x y → EM₁-mult (cp₀₁ g₁ x) (cp₀₁ g₂ y)) (emloop h)) ⟩\n ap2 (λ x y → EM₁-mult (cp₀₁ g₁ x) (cp₀₁ g₂ y)) (emloop h) (emloop h)\n =⟨ =ₛ-out $ ap2-out (λ x y → EM₁-mult (cp₀₁ g₁ x) (cp₀₁ g₂ y)) (emloop h) (emloop h) ⟩\n ap (λ x → EM₁-mult (cp₀₁ g₁ x) embase) (emloop h) ∙ ap (cp₀₁ g₂) (emloop h)\n =⟨ ap2 _∙_ part (cp₀₁-emloop-β g₂ h) ⟩\n emloop (g₁ ⊗ h) ∙ emloop (g₂ ⊗ h)\n =⟨ ! (emloop-comp (g₁ ⊗ h) (g₂ ⊗ h)) ⟩\n emloop (G⊗H.comp (g₁ ⊗ h) (g₂ ⊗ h))\n =⟨ ap emloop (! (G⊗H.⊗-lin-l g₁ g₂ h)) ⟩\n emloop (G.comp g₁ g₂ ⊗ h)\n =⟨ ! (cp₀₁-emloop-β (G.comp g₁ g₂) h) ⟩\n ap f (emloop h)\n =⟨ ! (∙-unit-r (ap f (emloop h))) ⟩\n ap f (emloop h) ∙ idp =∎\n where\n part : ap (λ x → EM₁-mult (cp₀₁ g₁ x) embase) (emloop h) == emloop (g₁ ⊗ h)\n part =\n ap (λ x → EM₁-mult (cp₀₁ g₁ x) embase) (emloop h)\n =⟨ ap-∘ (λ u → EM₁-mult u embase) (cp₀₁ g₁) (emloop h) ⟩\n ap (λ u → EM₁-mult u embase) (ap (cp₀₁ g₁) (emloop h))\n =⟨ ap (ap (λ u → EM₁-mult u embase)) (cp₀₁-emloop-β g₁ h) ⟩\n ap (λ u → EM₁-mult u embase) (emloop (g₁ ⊗ h))\n =⟨ mult-emloop-β (g₁ ⊗ h) embase ⟩\n emloop (g₁ ⊗ h) =∎\n\nmodule _ (g₁ g₂ g₃ : G.El) (y : EM₁ H.grp) where\n\n cp₀₁-distr-l₁ : cp₀₁ (G.comp (G.comp g₁ g₂) g₃) y =-=\n EM₁-mult (cp₀₁ g₁ y) (EM₁-mult (cp₀₁ g₂ y) (cp₀₁ g₃ y))\n cp₀₁-distr-l₁ =\n cp₀₁ (G.comp (G.comp g₁ g₂) g₃) y\n =⟪ cp₀₁-distr-l (G.comp g₁ g₂) g₃ y ⟫\n EM₁-mult (cp₀₁ (G.comp g₁ g₂) y) (cp₀₁ g₃ y)\n =⟪ ap (λ s → EM₁-mult s (cp₀₁ g₃ y)) (cp₀₁-distr-l g₁ g₂ y) ⟫\n EM₁-mult (EM₁-mult (cp₀₁ g₁ y) (cp₀₁ g₂ y)) (cp₀₁ g₃ y)\n =⟪ H-⊙EM₁-assoc (cp₀₁ g₁ y) (cp₀₁ g₂ y) (cp₀₁ g₃ y) ⟫\n EM₁-mult (cp₀₁ g₁ y) (EM₁-mult (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ∎∎\n\n cp₀₁-distr-l₂ : cp₀₁ (G.comp (G.comp g₁ g₂) g₃) y =-=\n EM₁-mult (cp₀₁ g₁ y) (EM₁-mult (cp₀₁ g₂ y) (cp₀₁ g₃ y))\n cp₀₁-distr-l₂ =\n cp₀₁ (G.comp (G.comp g₁ g₂) g₃) y\n =⟪ ap (λ s → cp₀₁ s y) (G.assoc g₁ g₂ g₃) ⟫\n cp₀₁ (G.comp g₁ (G.comp g₂ g₃)) y\n =⟪ cp₀₁-distr-l g₁ (G.comp g₂ g₃) y ⟫\n EM₁-mult (cp₀₁ g₁ y) (cp₀₁ (G.comp g₂ g₃) y)\n =⟪ ap (EM₁-mult (cp₀₁ g₁ y)) (cp₀₁-distr-l g₂ g₃ y) ⟫\n EM₁-mult (cp₀₁ g₁ y) (EM₁-mult (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ∎∎\n\nabstract\n cp₀₁-distr-l-coh : (g₁ g₂ g₃ : G.El) (y : EM₁ H.grp)\n → cp₀₁-distr-l₁ g₁ g₂ g₃ y =ₛ cp₀₁-distr-l₂ g₁ g₂ g₃ y\n cp₀₁-distr-l-coh g₁ g₂ g₃ =\n EM₁-prop-elim\n {P = λ y → cp₀₁-distr-l₁ g₁ g₂ g₃ y =ₛ cp₀₁-distr-l₂ g₁ g₂ g₃ y}\n {{λ y → =ₛ-level (EM₁-level₁ G⊗H.grp)}} $\n idp ◃∙ idp ◃∙ idp ◃∎\n =ₛ₁⟨ 0 & 1 & ! (ap-cst embase (G.assoc g₁ g₂ g₃)) ⟩\n ap (cst embase) (G.assoc g₁ g₂ g₃) ◃∙ idp ◃∙ idp ◃∎ ∎ₛ\n\ncp₀₁-functor :\n TwoSemiFunctor\n (group-to-cat G.grp)\n (fun-cat (EM₁ H.grp) EM₁-2-semi-category)\ncp₀₁-functor =\n record\n { F₀ = λ _ _ → unit\n ; F₁ = λ g x → cp₀₁ g x\n ; pres-comp = λ g₁ g₂ → λ= (cp₀₁-distr-l g₁ g₂)\n ; pres-comp-coh = λ g₁ g₂ g₃ → pres-comp-coh g₁ g₂ g₃\n -- TODO: for some reason, this last field takes a really long time to check\n -- it is recommended to comment it out\n }\n where\n abstract\n pres-comp-coh : ∀ g₁ g₂ g₃ →\n λ= (cp₀₁-distr-l (G.comp g₁ g₂) g₃) ◃∙\n ap (λ s y → EM₁-mult (s y) (cp₀₁ g₃ y)) (λ= (cp₀₁-distr-l g₁ g₂)) ◃∙\n λ= (λ y → H-⊙EM₁-assoc (cp₀₁ g₁ y) (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ◃∎\n =ₛ\n ap (λ s → cp₀₁ s) (G.assoc g₁ g₂ g₃) ◃∙\n λ= (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) ◃∙\n ap (λ s y → EM₁-mult (cp₀₁ g₁ y) (s y)) (λ= (cp₀₁-distr-l g₂ g₃)) ◃∎\n pres-comp-coh g₁ g₂ g₃ =\n λ= (cp₀₁-distr-l (G.comp g₁ g₂) g₃) ◃∙\n ap (λ s y → EM₁-mult (s y) (cp₀₁ g₃ y)) (λ= (cp₀₁-distr-l g₁ g₂)) ◃∙\n λ= (λ y → H-⊙EM₁-assoc (cp₀₁ g₁ y) (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ◃∎\n =ₛ₁⟨ 1 & 1 & λ=-ap (λ y s → EM₁-mult s (cp₀₁ g₃ y)) (cp₀₁-distr-l g₁ g₂) ⟩\n λ= (cp₀₁-distr-l (G.comp g₁ g₂) g₃) ◃∙\n λ= (λ y → ap (λ s → EM₁-mult s (cp₀₁ g₃ y)) (cp₀₁-distr-l g₁ g₂ y)) ◃∙\n λ= (λ y → H-⊙EM₁-assoc (cp₀₁ g₁ y) (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ◃∎\n =ₛ⟨ ∙∙-λ= (cp₀₁-distr-l (G.comp g₁ g₂) g₃)\n (λ y → ap (λ s → EM₁-mult s (cp₀₁ g₃ y)) (cp₀₁-distr-l g₁ g₂ y))\n (λ y → H-⊙EM₁-assoc (cp₀₁ g₁ y) (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ⟩\n λ= (λ y → ↯ (cp₀₁-distr-l₁ g₁ g₂ g₃ y)) ◃∎\n =ₛ₁⟨ ap λ= (λ= (λ y → =ₛ-out (cp₀₁-distr-l-coh g₁ g₂ g₃ y))) ⟩\n λ= (λ y → ↯ (cp₀₁-distr-l₂ g₁ g₂ g₃ y)) ◃∎\n =ₛ⟨ λ=-∙∙ (λ y → ap (λ s → cp₀₁ s y) (G.assoc g₁ g₂ g₃))\n (cp₀₁-distr-l g₁ (G.comp g₂ g₃))\n (λ y → ap (EM₁-mult (cp₀₁ g₁ y)) (cp₀₁-distr-l g₂ g₃ y)) ⟩\n λ= (λ y → ap (λ s → cp₀₁ s y) (G.assoc g₁ g₂ g₃)) ◃∙\n λ= (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) ◃∙\n λ= (λ y → ap (EM₁-mult (cp₀₁ g₁ y)) (cp₀₁-distr-l g₂ g₃ y)) ◃∎\n =ₛ₁⟨ 0 & 1 & ap λ= (λ= (λ y → ap-∘ (λ f → f y) cp₀₁ (G.assoc g₁ g₂ g₃))) ⟩\n λ= (app= (ap (λ s → cp₀₁ s) (G.assoc g₁ g₂ g₃))) ◃∙\n λ= (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) ◃∙\n λ= (λ y → ap (EM₁-mult (cp₀₁ g₁ y)) (cp₀₁-distr-l g₂ g₃ y)) ◃∎\n =ₛ₁⟨ 0 & 1 & ! (λ=-η (ap (λ s → cp₀₁ s) (G.assoc g₁ g₂ g₃))) ⟩\n ap (λ s → cp₀₁ s) (G.assoc g₁ g₂ g₃) ◃∙\n λ= (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) ◃∙\n λ= (λ y → ap (EM₁-mult (cp₀₁ g₁ y)) (cp₀₁-distr-l g₂ g₃ y)) ◃∎\n =ₛ₁⟨ 2 & 1 & ! (λ=-ap (λ y s → EM₁-mult (cp₀₁ g₁ y) s) (cp₀₁-distr-l g₂ g₃)) ⟩\n ap (λ s → cp₀₁ s) (G.assoc g₁ g₂ g₃) ◃∙\n λ= (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) ◃∙\n ap (λ s y → EM₁-mult (cp₀₁ g₁ y) (s y)) (λ= (cp₀₁-distr-l g₂ g₃)) ◃∎ ∎ₛ\n\ncomp-functor :\n TwoSemiFunctor\n EM₁-2-semi-category\n (=ₜ-fundamental-cat (Susp (EM₁ G⊗H.grp)))\ncomp-functor =\n record\n { F₀ = λ _ → [ north ]\n ; F₁ = λ x → [ η x ]\n ; pres-comp = comp\n ; pres-comp-coh = comp-coh\n }\n -- this is *exactly* the same as\n -- `EM₁HSpaceAssoc.comp-functor G⊗H.abgroup`\n -- inlined but Agda chokes on this shorter definition\n\nmodule _ where\n\n private\n T : TwoSemiCategory (lmax i j) (lmax i j)\n T = fun-cat (EM₁ H.grp) (=ₜ-fundamental-cat (Susp (EM₁ G⊗H.grp)))\n\n module T = TwoSemiCategory T\n cst-north : T.El\n cst-north = λ _ → [ north ]\n T-comp' = T.comp {x = cst-north} {y = cst-north} {z = cst-north}\n T-assoc' = T.assoc {x = cst-north} {y = cst-north} {z = cst-north} {w = cst-north}\n\n group-to-EM₁→EM₂ : TwoSemiFunctor (group-to-cat G.grp) T\n group-to-EM₁→EM₂ =\n cp₀₁-functor –F→\n fun-functor-map (EM₁ H.grp) comp-functor\n\n abstract\n app=-group-to-EM₁→EM₂-pres-comp-embase : ∀ g₁ g₂ →\n app= (TwoSemiFunctor.pres-comp group-to-EM₁→EM₂ g₁ g₂) embase ==\n comp embase embase\n app=-group-to-EM₁→EM₂-pres-comp-embase g₁ g₂ = =ₛ-out $\n app= (TwoSemiFunctor.pres-comp group-to-EM₁→EM₂ g₁ g₂) embase ◃∎\n =ₛ⟨ ap-seq-=ₛ (λ f → f embase) (comp-functors-pres-comp-β cp₀₁-functor G₁₂ g₁ g₂) ⟩\n app= (ap (TwoSemiFunctor.F₁ G₁₂) (TwoSemiFunctor.pres-comp cp₀₁-functor g₁ g₂)) embase ◃∙\n app= (TwoSemiFunctor.pres-comp G₁₂ (cp₀₁ g₁) (cp₀₁ g₂)) embase ◃∎\n =ₛ⟨ 0 & 1 & =ₛ-in {t = []} $\n app= (ap (λ f x → [ η (f x) ]) (λ= (cp₀₁-distr-l g₁ g₂))) embase\n =⟨ ap (λ w → app= w embase) (λ=-ap (λ _ y → [ η y ]) (cp₀₁-distr-l g₁ g₂)) ⟩\n app= (λ= (λ a → ap (λ y → [ η y ]) (cp₀₁-distr-l g₁ g₂ a))) embase\n =⟨ app=-β (λ a → ap (λ y → [ η y ]) (cp₀₁-distr-l g₁ g₂ a)) embase ⟩\n idp =∎\n ⟩\n app= (TwoSemiFunctor.pres-comp G₁₂ (cp₀₁ g₁) (cp₀₁ g₂)) embase ◃∎\n =ₛ₁⟨ app=-β (λ y → comp (cp₀₁ g₁ y) (cp₀₁ g₂ y)) embase ⟩\n comp embase embase ◃∎ ∎ₛ\n where\n G₁₂ = fun-functor-map (EM₁ H.grp) comp-functor\n\nmodule CP₁₁ where\n\n private\n C : Type (lmax i j)\n C = EM₁ H.grp → EM G⊗H.abgroup 2\n\n C-level : has-level 2 C\n C-level = Π-level (λ _ → EM-level G⊗H.abgroup 2)\n\n D₀ : TwoSemiCategory lzero i\n D₀ = group-to-cat G.grp\n\n D₁' : TwoSemiCategory (lmax i j) (lmax i j)\n D₁' = =ₜ-fundamental-cat (Susp (EM₁ G⊗H.grp))\n\n D₁ : TwoSemiCategory (lmax i j) (lmax i j)\n D₁ = fun-cat (EM₁ H.grp) D₁'\n\n D₂' : TwoSemiCategory (lmax i j) (lmax i j)\n D₂' = 2-type-fundamental-cat (EM G⊗H.abgroup 2)\n\n D₂ : TwoSemiCategory (lmax i j) (lmax i j)\n D₂ = fun-cat (EM₁ H.grp) D₂'\n\n D₃ : TwoSemiCategory (lmax i j) (lmax i j)\n D₃ = 2-type-fundamental-cat (EM₁ H.grp → EM G⊗H.abgroup 2) {{C-level}}\n\n F₀₁ : TwoSemiFunctor D₀ D₁\n F₀₁ = group-to-EM₁→EM₂\n\n F₁₂' : TwoSemiFunctor D₁' D₂'\n F₁₂' = =ₜ-to-2-type-fundamental-cat (Susp (EM₁ G⊗H.grp))\n\n F₁₂ : TwoSemiFunctor D₁ D₂\n F₁₂ = fun-functor-map (EM₁ H.grp) F₁₂'\n\n F₀₂ : TwoSemiFunctor D₀ D₂\n F₀₂ = F₀₁ –F→ F₁₂\n\n module F₂₃-Funext = FunextFunctors (EM₁ H.grp) (EM G⊗H.abgroup 2) {{⟨⟩}}\n F₂₃ : TwoSemiFunctor D₂ D₃\n F₂₃ = F₂₃-Funext.λ=-functor\n\n module F₀₂ = TwoSemiFunctor F₀₂\n module F₂₃ = TwoSemiFunctor F₂₃\n\n private\n module F₀₃-Comp = FunctorComposition F₀₂ F₂₃\n F₀₃ : TwoSemiFunctor D₀ D₃\n F₀₃ = F₀₃-Comp.composition\n\n module F₀₁ = TwoSemiFunctor F₀₁\n module F₁₂ = TwoSemiFunctor F₁₂\n module F₁₂' = TwoSemiFunctor F₁₂'\n module F₀₃ = TwoSemiFunctor F₀₃\n\n module CP₁₁-Rec = EM₁Rec {G = G.grp} {C = C} {{C-level}} F₀₃\n\n abstract\n cp₁₁ : EM₁ G.grp → EM₁ H.grp → EM G⊗H.abgroup 2\n cp₁₁ = CP₁₁-Rec.f\n\n cp₁₁-embase-β : cp₁₁ embase ↦ (λ _ → [ north ])\n cp₁₁-embase-β = CP₁₁-Rec.embase-β\n {-# REWRITE cp₁₁-embase-β #-}\n\n cp₁₁-emloop-β : ∀ g → ap cp₁₁ (emloop g) == λ= (λ y → ap [_] (η (cp₀₁ g y)))\n cp₁₁-emloop-β g = CP₁₁-Rec.emloop-β g\n\n app=-F₀₂-pres-comp-embase-β : ∀ g₁ g₂ →\n app= (F₀₂.pres-comp g₁ g₂) embase ◃∎\n =ₛ\n ap (ap [_]) (comp-l embase) ◃∙\n ap-∙ [_] (η embase) (η embase) ◃∎\n app=-F₀₂-pres-comp-embase-β g₁ g₂ =\n app= (F₀₂.pres-comp g₁ g₂) embase ◃∎\n =ₛ⟨ ap-seq-=ₛ (λ f → f embase) (comp-functors-pres-comp-β F₀₁ F₁₂ g₁ g₂) ⟩\n app= (ap (λ α y → <– (=ₜ-equiv [ north ] [ north ]) (α y))\n (F₀₁.pres-comp g₁ g₂)) embase ◃∙\n app= (F₁₂.pres-comp {x = λ _ → [ north ]} {y = λ _ → [ north ]} {z = λ _ → [ north ]}\n (λ y → [ η (cp₀₁ g₁ y) ]₁) (λ y → [ η (cp₀₁ g₂ y) ]₁)) embase ◃∎\n =ₛ₁⟨ 0 & 1 & step₂ ⟩\n ap (ap [_]) (comp-l embase) ◃∙\n app= (F₁₂.pres-comp {x = λ _ → [ north ]} {y = λ _ → [ north ]} {z = λ _ → [ north ]}\n (λ y → [ η (cp₀₁ g₁ y) ]₁) (λ y → [ η (cp₀₁ g₂ y) ]₁)) embase ◃∎\n =ₛ₁⟨ 1 & 1 & step₃ ⟩\n ap (ap [_]) (comp-l embase) ◃∙\n ap-∙ [_] (η embase) (η embase) ◃∎ ∎ₛ\n where\n step₂ :\n app= (ap (λ α y → <– (=ₜ-equiv [ north ] [ north ]) (α y))\n (F₀₁.pres-comp g₁ g₂)) embase\n == ap (ap [_]) (comp-l embase)\n step₂ =\n app= (ap (λ α y → <– (=ₜ-equiv [ north ] [ north ]) (α y)) (F₀₁.pres-comp g₁ g₂)) embase\n =⟨ ∘-ap (λ f → f embase)\n (λ α y → <– (=ₜ-equiv [ north ] [ north ]) (α y))\n (F₀₁.pres-comp g₁ g₂) ⟩\n ap (λ α → <– (=ₜ-equiv [ north ] [ north ]) (α embase))\n (F₀₁.pres-comp g₁ g₂)\n =⟨ ap-∘ (<– (=ₜ-equiv [ north ] [ north ]))\n (λ f → f embase)\n (F₀₁.pres-comp g₁ g₂) ⟩\n ap (<– (=ₜ-equiv [ north ] [ north ]))\n (app= (F₀₁.pres-comp g₁ g₂) embase)\n =⟨ ap (ap (<– (=ₜ-equiv [ north ] [ north ])))\n (app=-group-to-EM₁→EM₂-pres-comp-embase g₁ g₂) ⟩\n ap (<– (=ₜ-equiv [ north ] [ north ])) (comp embase embase)\n =⟨ ap (ap (<– (=ₜ-equiv [ north ] [ north ])))\n (comp-unit-l embase) ⟩\n ap (<– (=ₜ-equiv [ north ] [ north ]))\n (comp-l₁ embase)\n =⟨ ∘-ap (<– (=ₜ-equiv [ north ] [ north ])) [_]₁ (comp-l embase) ⟩\n ap (ap [_]) (comp-l embase) =∎\n step₃ :\n app= (F₁₂.pres-comp {x = λ _ → [ north ]₂} {y = λ _ → [ north ]₂} {z = λ _ → [ north ]₂}\n (λ y → [ η (cp₀₁ g₁ y) ]₁) (λ y → [ η (cp₀₁ g₂ y) ]₁)) embase\n == ap-∙ [_] (η embase) (η embase)\n step₃ =\n app= (F₁₂.pres-comp {x = λ _ → [ north ]} {y = λ _ → [ north ]} {z = λ _ → [ north ]}\n (λ y → [ η (cp₀₁ g₁ y) ]₁) (λ y → [ η (cp₀₁ g₂ y) ]₁)) embase\n =⟨ app=-β (λ y → F₁₂'.pres-comp {x = [ north ]} {y = [ north ]} {z = [ north ]}\n [ η (cp₀₁ g₁ y) ]₁ [ η (cp₀₁ g₂ y) ]₁) embase ⟩\n F₁₂'.pres-comp {x = [ north ]} {y = [ north ]} {z = [ north ]} [ η embase ]₁ [ η embase ]₁\n =⟨ =ₜ-to-2-type-fundamental-cat-pres-comp-β (Susp (EM₁ G⊗H.grp)) (η embase) (η embase) ⟩\n ap-∙ [_] (η embase) (η embase) =∎\n\n app=-F₀₂-pres-comp-embase-coh : ∀ g₁ g₂ →\n app= (F₀₂.pres-comp g₁ g₂) embase ◃∙\n ap2 _∙_ (ap (ap [_]) (!-inv-r (merid embase)))\n (ap (ap [_]) (!-inv-r (merid embase))) ◃∎\n =ₛ\n ap (ap [_]) (!-inv-r (merid embase)) ◃∎\n app=-F₀₂-pres-comp-embase-coh g₁ g₂ =\n app= (F₀₂.pres-comp g₁ g₂) embase ◃∙\n ap2 _∙_ (ap (ap [_]) (!-inv-r (merid embase)))\n (ap (ap [_]) (!-inv-r (merid embase))) ◃∎\n =ₛ⟨ 0 & 1 & app=-F₀₂-pres-comp-embase-β g₁ g₂ ⟩\n ap (ap [_]) (comp-l embase) ◃∙\n ap-∙ [_] (η embase) (η embase) ◃∙\n ap2 _∙_ (ap (ap [_]) (!-inv-r (merid embase)))\n (ap (ap [_]) (!-inv-r (merid embase))) ◃∎\n =ₛ₁⟨ 2 & 1 & ap2-ap-lr _∙_ (ap [_]) (ap [_]) (!-inv-r (merid embase)) (!-inv-r (merid embase)) ⟩\n ap (ap [_]) (comp-l embase) ◃∙\n ap-∙ [_] (η embase) (η embase) ◃∙\n ap2 (λ s t → ap [_] s ∙ ap [_] t) (!-inv-r (merid embase)) (!-inv-r (merid embase)) ◃∎\n =ₛ⟨ 1 & 2 & !ₛ $\n homotopy-naturality2 (λ s t → ap [_] (s ∙ t))\n (λ s t → ap [_] s ∙ ap [_] t)\n (ap-∙ [_])\n (!-inv-r (merid embase))\n (!-inv-r (merid embase)) ⟩\n ap (ap [_]) (comp-l embase) ◃∙\n ap2 (λ s t → ap [_] (s ∙ t)) (!-inv-r (merid embase)) (!-inv-r (merid embase)) ◃∙\n idp ◃∎\n =ₛ⟨ 2 & 1 & expand [] ⟩\n ap (ap [_]) (comp-l embase) ◃∙\n ap2 (λ s t → ap [_] (s ∙ t)) (!-inv-r (merid embase)) (!-inv-r (merid embase)) ◃∎\n =ₛ₁⟨ 1 & 1 & ! (ap-ap2 (ap [_]) _∙_ (!-inv-r (merid embase)) (!-inv-r (merid embase))) ⟩\n ap (ap [_]) (comp-l embase) ◃∙\n ap (ap [_]) (ap2 _∙_ (!-inv-r (merid embase)) (!-inv-r (merid embase))) ◃∎\n =ₛ⟨ ap-seq-=ₛ (ap [_]) step₇' ⟩\n ap (ap [_]) (!-inv-r (merid embase)) ◃∎ ∎ₛ\n where\n helper : ∀ {i} {A : Type i} {a₀ a₁ : A} (p : a₀ == a₁)\n → add-path-inverse-l (p ∙ ! p) p ◃∙ ap2 _∙_ (!-inv-r p) (!-inv-r p) ◃∎\n =ₛ !-inv-r p ◃∎\n helper idp = =ₛ-in idp\n step₇' : comp-l embase ◃∙ ap2 _∙_ (!-inv-r (merid embase)) (!-inv-r (merid embase)) ◃∎\n =ₛ !-inv-r (merid embase) ◃∎\n step₇' = helper (merid embase)\n\n app=-ap-cp₁₁-seq : ∀ g y → app= (ap cp₁₁ (emloop g)) y =-= ap [_] (η (cp₀₁ g y))\n app=-ap-cp₁₁-seq g y =\n app= (ap cp₁₁ (emloop g)) y\n =⟪ ap (λ p → app= p y) (cp₁₁-emloop-β g) ⟫\n app= (λ= (λ x → ap [_] (η (cp₀₁ g x)))) y\n =⟪ app=-β (λ x → ap [_] (η (cp₀₁ g x))) y ⟫\n ap [_] (η (cp₀₁ g y)) ∎∎\n\n app=-ap-cp₁₁ : ∀ g y → app= (ap cp₁₁ (emloop g)) y == ap [_] (η (cp₀₁ g y))\n app=-ap-cp₁₁ g y = ↯ (app=-ap-cp₁₁-seq g y)\n\n app=-ap-cp₁₁-coh-seq₁ : ∀ g₁ g₂ y →\n app= (ap cp₁₁ (emloop (G.comp g₁ g₂))) y =-= ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y))\n app=-ap-cp₁₁-coh-seq₁ g₁ g₂ y =\n app= (ap cp₁₁ (emloop (G.comp g₁ g₂))) y\n =⟪ ap (λ u → app= (ap cp₁₁ u) y) (emloop-comp g₁ g₂) ⟫\n app= (ap cp₁₁ (emloop g₁ ∙ emloop g₂)) y\n =⟪ ap (λ u → app= u y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ⟫\n app= (ap cp₁₁ (emloop g₁) ∙ ap cp₁₁ (emloop g₂)) y\n =⟪ ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ⟫\n app= (ap cp₁₁ (emloop g₁)) y ∙ app= (ap cp₁₁ (emloop g₂)) y\n =⟪ ap2 _∙_ (app=-ap-cp₁₁ g₁ y) (app=-ap-cp₁₁ g₂ y) ⟫\n ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) ∎∎\n\n app=-ap-cp₁₁-coh-seq₂ : ∀ g₁ g₂ y →\n app= (ap cp₁₁ (emloop (G.comp g₁ g₂))) y =-= ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y))\n app=-ap-cp₁₁-coh-seq₂ g₁ g₂ y =\n app= (ap cp₁₁ (emloop (G.comp g₁ g₂))) y\n =⟪ app=-ap-cp₁₁ (G.comp g₁ g₂) y ⟫\n ap [_] (η (cp₀₁ (G.comp g₁ g₂) y))\n =⟪ app= (F₀₂.pres-comp g₁ g₂) y ⟫\n ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) ∎∎\n\n abstract\n app=-ap-cp₁₁-coh : ∀ g₁ g₂ y →\n app=-ap-cp₁₁-coh-seq₁ g₁ g₂ y =ₛ app=-ap-cp₁₁-coh-seq₂ g₁ g₂ y\n app=-ap-cp₁₁-coh g₁ g₂ y =\n ap (λ u → app= (ap cp₁₁ u) y) (emloop-comp g₁ g₂) ◃∙\n ap (λ u → app= u y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙\n ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ◃∙\n ap2 _∙_ (app=-ap-cp₁₁ g₁ y) (app=-ap-cp₁₁ g₂ y) ◃∎\n =ₛ⟨ 3 & 2 & ap2-seq-∙ _∙_ (app=-ap-cp₁₁-seq g₁ y) (app=-ap-cp₁₁-seq g₂ y) ⟩\n ap (λ u → app= (ap cp₁₁ u) y) (emloop-comp g₁ g₂) ◃∙\n ap (λ u → app= u y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙\n ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ◃∙\n ap2 _∙_ (ap (λ z → app= z y) (cp₁₁-emloop-β g₁)) (ap (λ z → app= z y) (cp₁₁-emloop-β g₂)) ◃∙\n ap2 _∙_ (app=-β (λ x → ap [_] (η (cp₀₁ g₁ x))) y) (app=-β (λ x → ap [_] (η (cp₀₁ g₂ x))) y) ◃∎\n =ₛ₁⟨ 3 & 1 & ap2-ap-lr _∙_ (λ z → app= z y) (λ z → app= z y) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ⟩\n ap (λ u → app= (ap cp₁₁ u) y) (emloop-comp g₁ g₂) ◃∙\n ap (λ u → app= u y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙\n ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ◃∙\n ap2 (λ a b → app= a y ∙ app= b y) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ◃∙\n ap2 _∙_ (app=-β (λ x → ap [_] (η (cp₀₁ g₁ x))) y) (app=-β (λ x → ap [_] (η (cp₀₁ g₂ x))) y) ◃∎\n =ₛ⟨ 2 & 2 & !ₛ $\n homotopy-naturality2 (λ a b → app= (a ∙ b) y)\n (λ a b → app= a y ∙ app= b y)\n (ap-∙ (λ f → f y))\n (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ⟩\n ap (λ u → app= (ap cp₁₁ u) y) (emloop-comp g₁ g₂) ◃∙\n ap (λ u → app= u y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙\n ap2 (λ a b → app= (a ∙ b) y) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ◃∙\n ap-∙ (λ f → f y) (λ= (λ y' → ap [_] (η (cp₀₁ g₁ y')))) (λ= (λ y' → ap [_] (η (cp₀₁ g₂ y')))) ◃∙\n ap2 _∙_ (app=-β (λ x → ap [_] (η (cp₀₁ g₁ x))) y) (app=-β (λ x → ap [_] (η (cp₀₁ g₂ x))) y) ◃∎\n =ₛ⟨ 3 & 2 &\n app=-β-coh (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))) y ⟩\n ap (λ x → app= (ap cp₁₁ x) y) (emloop-comp g₁ g₂) ◃∙\n ap (λ p → app= p y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙\n ap2 (λ a b → app= (a ∙ b) y) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ◃∙\n ap (λ p → app= p y) (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))))) ◃∙\n app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎\n =ₛ₁⟨ 0 & 1 & ap-∘ (λ p → app= p y) (ap cp₁₁) (emloop-comp g₁ g₂) ⟩\n ap (λ p → app= p y) (ap (ap cp₁₁) (emloop-comp g₁ g₂)) ◃∙\n ap (λ p → app= p y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙\n ap2 (λ a b → app= (a ∙ b) y) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ◃∙\n ap (λ p → app= p y) (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))))) ◃∙\n app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎\n =ₛ₁⟨ 2 & 1 & ! (ap-ap2 (λ p → app= p y) _∙_ (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂)) ⟩\n ap (λ p → app= p y) (ap (ap cp₁₁) (emloop-comp g₁ g₂)) ◃∙\n ap (λ p → app= p y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙\n ap (λ p → app= p y) (ap2 _∙_ (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂)) ◃∙\n ap (λ p → app= p y) (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))))) ◃∙\n app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎\n =ₛ⟨ 0 & 3 & ap-seq-=ₛ (λ p → app= p y) (CP₁₁-Rec.emloop-comp-path g₁ g₂) ⟩\n ap (λ p → app= p y) (cp₁₁-emloop-β (G.comp g₁ g₂)) ◃∙\n ap (λ p → app= p y) (F₀₃.pres-comp g₁ g₂) ◃∙\n ap (λ p → app= p y) (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))))) ◃∙\n app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎\n =ₛ⟨ 1 & 2 & step₈ ⟩\n ap (λ p → app= p y) (cp₁₁-emloop-β (G.comp g₁ g₂)) ◃∙\n ap (λ p → app= p y) (ap λ= (F₀₂.pres-comp g₁ g₂)) ◃∙\n app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎\n =ₛ₁⟨ 1 & 1 & ∘-ap (λ p → app= p y) λ= (F₀₂.pres-comp g₁ g₂) ⟩\n ap (λ p → app= p y) (cp₁₁-emloop-β (G.comp g₁ g₂)) ◃∙\n ap (λ γ → app= (λ= γ) y) (F₀₂.pres-comp g₁ g₂) ◃∙\n app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎\n =ₛ⟨ 1 & 2 &\n homotopy-naturality (λ γ → app= (λ= γ) y)\n (λ γ → γ y)\n (λ γ → app=-β γ y)\n (F₀₂.pres-comp g₁ g₂) ⟩\n ap (λ p → app= p y) (cp₁₁-emloop-β (G.comp g₁ g₂)) ◃∙\n app=-β (λ x → ap [_] (η (cp₀₁ (G.comp g₁ g₂) x))) y ◃∙\n app= (F₀₂.pres-comp g₁ g₂) y ◃∎\n =ₛ⟨ 0 & 2 & contract ⟩\n app=-ap-cp₁₁ (G.comp g₁ g₂) y ◃∙\n app= (F₀₂.pres-comp g₁ g₂) y ◃∎ ∎ₛ\n where\n step₈ :\n ap (λ p → app= p y) (F₀₃.pres-comp g₁ g₂) ◃∙\n ap (λ p → app= p y) (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))))) ◃∎\n =ₛ\n ap (λ p → app= p y) (ap λ= (F₀₂.pres-comp g₁ g₂)) ◃∎\n step₈ = ap-seq-=ₛ (λ p → app= p y) $\n F₀₃.pres-comp g₁ g₂ ◃∙\n =ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x)))) ◃∎\n =ₛ⟨ 0 & 1 & F₀₃-Comp.pres-comp-β g₁ g₂ ⟩\n ap λ= (F₀₂.pres-comp g₁ g₂) ◃∙\n F₂₃.pres-comp (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))) ◃∙\n =ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x)))) ◃∎\n =ₛ₁⟨ 1 & 1 & F₂₃-Funext.λ=-functor-pres-comp=λ=-∙ (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))) ⟩\n ap λ= (F₀₂.pres-comp g₁ g₂) ◃∙\n =ₛ-out (λ=-∙ (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x)))) ◃∙\n =ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x)))) ◃∎\n =ₛ⟨ 1 & 2 & seq-!-inv-l (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x)))) ◃∎) ⟩\n ap λ= (F₀₂.pres-comp g₁ g₂) ◃∎ ∎ₛ\n\n ap-cp₁₁-seq : ∀ g y → ap (λ x → cp₁₁ x y) (emloop g) =-= ap [_] (η (cp₀₁ g y))\n ap-cp₁₁-seq g y =\n ap (λ x → cp₁₁ x y) (emloop g)\n =⟪ ap-∘ (λ f → f y) cp₁₁ (emloop g) ⟫\n ap (λ f → f y) (ap cp₁₁ (emloop g))\n =⟪ app=-ap-cp₁₁ g y ⟫\n ap [_] (η (cp₀₁ g y)) ∎∎\n\n ap-cp₁₁ : ∀ g y → ap (λ x → cp₁₁ x y) (emloop g) == ap [_] (η (cp₀₁ g y))\n ap-cp₁₁ g y = ↯ (ap-cp₁₁-seq g y)\n\n ap-cp₁₁-coh-seq₁ : ∀ g₁ g₂ y →\n ap (λ x → cp₁₁ x y) (emloop (G.comp g₁ g₂)) =-= ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y))\n ap-cp₁₁-coh-seq₁ g₁ g₂ y =\n ap (λ x → cp₁₁ x y) (emloop (G.comp g₁ g₂))\n =⟪ ap (ap (λ x → cp₁₁ x y)) (emloop-comp g₁ g₂) ⟫\n ap (λ x → cp₁₁ x y) (emloop g₁ ∙ emloop g₂)\n =⟪ ap-∙ (λ x → cp₁₁ x y) (emloop g₁) (emloop g₂) ⟫\n ap (λ x → cp₁₁ x y) (emloop g₁) ∙ ap (λ x → cp₁₁ x y) (emloop g₂)\n =⟪ ap2 _∙_ (ap-cp₁₁ g₁ y) (ap-cp₁₁ g₂ y) ⟫\n ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) ∎∎\n\n ap-cp₁₁-coh-seq₂ : ∀ g₁ g₂ y →\n ap (λ x → cp₁₁ x y) (emloop (G.comp g₁ g₂)) =-= ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y))\n ap-cp₁₁-coh-seq₂ g₁ g₂ y =\n ap (λ x → cp₁₁ x y) (emloop (G.comp g₁ g₂))\n =⟪ ap-cp₁₁ (G.comp g₁ g₂) y ⟫\n ap [_] (η (cp₀₁ (G.comp g₁ g₂) y))\n =⟪ app= (F₀₂.pres-comp g₁ g₂) y ⟫\n ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) ∎∎\n\n abstract\n ap-cp₁₁-coh : ∀ g₁ g₂ y →\n ap-cp₁₁-coh-seq₁ g₁ g₂ y =ₛ ap-cp₁₁-coh-seq₂ g₁ g₂ y\n ap-cp₁₁-coh g₁ g₂ y =\n ap (ap (λ x → cp₁₁ x y)) (emloop-comp g₁ g₂) ◃∙\n ap-∙ (λ x → cp₁₁ x y) (emloop g₁) (emloop g₂) ◃∙\n ap2 _∙_ (ap-cp₁₁ g₁ y) (ap-cp₁₁ g₂ y) ◃∎\n =ₛ⟨ 2 & 1 & ap2-seq-∙ _∙_ (ap-cp₁₁-seq g₁ y) (ap-cp₁₁-seq g₂ y) ⟩\n ap (ap (λ x → cp₁₁ x y)) (emloop-comp g₁ g₂) ◃∙\n ap-∙ (λ x → cp₁₁ x y) (emloop g₁) (emloop g₂) ◃∙\n ap2 _∙_ (ap-∘ (λ f → f y) cp₁₁ (emloop g₁)) (ap-∘ (λ f → f y) cp₁₁ (emloop g₂)) ◃∙\n ap2 _∙_ (app=-ap-cp₁₁ g₁ y) (app=-ap-cp₁₁ g₂ y) ◃∎\n =ₛ⟨ 1 & 2 & ap-∘-∙-coh (λ f → f y) cp₁₁ (emloop g₁) (emloop g₂) ⟩\n ap (ap (λ x → cp₁₁ x y)) (emloop-comp g₁ g₂) ◃∙\n ap-∘ (λ f → f y) cp₁₁ (emloop g₁ ∙ emloop g₂) ◃∙\n ap (ap (λ f → f y)) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙\n ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ◃∙\n ap2 _∙_ (app=-ap-cp₁₁ g₁ y) (app=-ap-cp₁₁ g₂ y) ◃∎\n =ₛ⟨ 0 & 2 & homotopy-naturality {A = embase' G.grp == embase} {B = cp₁₁ embase y == cp₁₁ embase y}\n (ap (λ x → cp₁₁ x y)) (λ p → app= (ap cp₁₁ p) y)\n (ap-∘ (λ f → f y) cp₁₁) (emloop-comp g₁ g₂) ⟩\n ap-∘ (λ f → f y) cp₁₁ (emloop (G.comp g₁ g₂)) ◃∙\n ap (λ p → app= (ap cp₁₁ p) y) (emloop-comp g₁ g₂) ◃∙\n ap (ap (λ f → f y)) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙\n ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ◃∙\n ap2 _∙_ (app=-ap-cp₁₁ g₁ y) (app=-ap-cp₁₁ g₂ y) ◃∎\n =ₛ⟨ 1 & 4 & app=-ap-cp₁₁-coh g₁ g₂ y ⟩\n ap-∘ (λ f → f y) cp₁₁ (emloop (G.comp g₁ g₂)) ◃∙\n app=-ap-cp₁₁ (G.comp g₁ g₂) y ◃∙\n app= (F₀₂.pres-comp g₁ g₂) y ◃∎\n =ₛ₁⟨ 0 & 2 & idp ⟩\n ap-cp₁₁ (G.comp g₁ g₂) y ◃∙\n app= (F₀₂.pres-comp g₁ g₂) y ◃∎ ∎ₛ\n\n ap-cp₁₁-embase-seq : ∀ g →\n ap (λ x → cp₁₁ x embase) (emloop g) =-= idp\n ap-cp₁₁-embase-seq g =\n ap (λ x → cp₁₁ x embase) (emloop g)\n =⟪ ap-cp₁₁ g embase ⟫\n ap [_] (η (cp₀₁ g embase))\n =⟪idp⟫\n ap [_] (η embase)\n =⟪ ap (ap [_]) (!-inv-r (merid embase)) ⟫\n ap [_] (idp {a = north})\n =⟪idp⟫\n idp ∎∎\n\n ap-cp₁₁-embase : ∀ g →\n ap (λ x → cp₁₁ x embase) (emloop g) == idp\n ap-cp₁₁-embase g = ↯ (ap-cp₁₁-embase-seq g)\n\n ap-cp₁₁-embase-coh-seq : ∀ g₁ g₂ →\n ap (λ x → cp₁₁ x embase) (emloop (G.comp g₁ g₂)) =-= idp\n ap-cp₁₁-embase-coh-seq g₁ g₂ =\n ap (λ x → cp₁₁ x embase) (emloop (G.comp g₁ g₂))\n =⟪ ap (ap (λ x → cp₁₁ x embase)) (emloop-comp g₁ g₂) ⟫\n ap (λ x → cp₁₁ x embase) (emloop g₁ ∙ emloop g₂)\n =⟪ ap-∙ (λ x → cp₁₁ x embase) (emloop g₁) (emloop g₂) ⟫\n ap (λ x → cp₁₁ x embase) (emloop g₁) ∙ ap (λ x → cp₁₁ x embase) (emloop g₂)\n =⟪ ap2 _∙_ (ap-cp₁₁-embase g₁) (ap-cp₁₁-embase g₂) ⟫\n idp ∎∎\n\n ap-cp₁₁-embase-coh : ∀ g₁ g₂ →\n ap-cp₁₁-embase (G.comp g₁ g₂) ◃∎ =ₛ ap-cp₁₁-embase-coh-seq g₁ g₂\n ap-cp₁₁-embase-coh g₁ g₂ =\n ap-cp₁₁-embase (G.comp g₁ g₂) ◃∎\n =ₛ⟨ expand (ap-cp₁₁-embase-seq (G.comp g₁ g₂)) ⟩\n ap-cp₁₁ (G.comp g₁ g₂) embase ◃∙\n ap (ap [_]) (!-inv-r (merid embase)) ◃∎\n =ₛ⟨ 1 & 1 & !ₛ (app=-F₀₂-pres-comp-embase-coh g₁ g₂) ⟩\n ap-cp₁₁ (G.comp g₁ g₂) embase ◃∙\n app= (F₀₂.pres-comp g₁ g₂) embase ◃∙\n ap2 _∙_ (ap (ap [_]) (!-inv-r (merid embase))) (ap (ap [_]) (!-inv-r (merid embase))) ◃∎\n =ₛ⟨ 0 & 2 & !ₛ (ap-cp₁₁-coh g₁ g₂ embase) ⟩\n ap (ap (λ x → cp₁₁ x embase)) (emloop-comp g₁ g₂) ◃∙\n ap-∙ (λ x → cp₁₁ x embase) (emloop g₁) (emloop g₂) ◃∙\n ap2 _∙_ (ap-cp₁₁ g₁ embase) (ap-cp₁₁ g₂ embase) ◃∙\n ap2 _∙_ (ap (ap [_]) (!-inv-r (merid embase))) (ap (ap [_]) (!-inv-r (merid embase))) ◃∎\n =ₛ⟨ 2 & 2 & ∙-ap2-seq _∙_ (ap-cp₁₁-embase-seq g₁) (ap-cp₁₁-embase-seq g₂) ⟩\n ap (ap (λ x → cp₁₁ x embase)) (emloop-comp g₁ g₂) ◃∙\n ap-∙ (λ x → cp₁₁ x embase) (emloop g₁) (emloop g₂) ◃∙\n ap2 _∙_ (ap-cp₁₁-embase g₁) (ap-cp₁₁-embase g₂) ◃∎ ∎ₛ\n\nopen CP₁₁ public\n", "meta": {"hexsha": "fd59ca1e8e8fd37e1ee0c998863e04aa91a08403", "size": 29614, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/cohomology/CupProduct/OnEM/InLowDegrees.agda", "max_stars_repo_name": "AntoineAllioux/HoTT-Agda", "max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/cohomology/CupProduct/OnEM/InLowDegrees.agda", "max_issues_repo_name": "AntoineAllioux/HoTT-Agda", "max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/cohomology/CupProduct/OnEM/InLowDegrees.agda", "max_forks_repo_name": "AntoineAllioux/HoTT-Agda", "max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 45.8421052632, "max_line_length": 123, "alphanum_fraction": 0.4851759303, "num_tokens": 14856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3871133566700572}} {"text": "open import Prelude\nopen import Data.List.Properties\nopen import Data.List.Any hiding (map)\nopen import Extensions.Vec\nopen import Data.Vec\nopen import Data.List.All as All hiding (map; lookup)\n\nmodule Implicits.Resolution.Infinite.Semantics where\n\nopen import Implicits.Syntax\nopen import Implicits.Resolution.Infinite.Resolution\nopen import Implicits.Substitutions\nopen import Implicits.Substitutions.Lemmas\nopen import Implicits.Semantics\nopen import Implicits.Semantics.Lemmas\n\nopen import SystemF.Everything as F using ()\n\nmodule DerivationSemantics where\n\n ⟦_,_⟧r : ∀ {ν n} {Δ : ICtx ν} {Γ : Ctx ν n} {a} → Δ ⊢ᵣ a → Γ # Δ →\n ∃ λ t → ⟦ Γ ⟧ctx→ F.⊢ t ∈ ⟦ a ⟧tp→\n ⟦_,_⟧r {Γ = Γ} (r-simp {r = r} r∈Δ r↓τ) m with ∈⟶index (All.lookup m r∈Δ)\n ⟦_,_⟧r {Γ = Γ} (r-simp {r = r} r∈Δ r↓τ) m | i , lookup-i≡r =\n ⟦ subst (λ u → _ F.⊢ F.var i ∈ u) eq (F.var i) , r↓τ , m ⟧r↓\n where\n eq = begin\n lookup i ⟦ Γ ⟧ctx→\n ≡⟨ sym $ lookup-⟦⟧ctx→ Γ i ⟩\n ⟦ lookup i Γ ⟧tp→\n ≡⟨ cong ⟦_⟧tp→ lookup-i≡r ⟩\n ⟦ r ⟧tp→ ∎\n\n ⟦_,_,_⟧r↓ : ∀ {ν n} {Δ : ICtx ν} {Γ : Ctx ν n} {a ta τ} →\n ⟦ Γ ⟧ctx→ F.⊢ ta ∈ ⟦ a ⟧tp→ → Δ ⊢ a ↓ τ → Γ # Δ →\n ∃ λ tτ → ⟦ Γ ⟧ctx→ F.⊢ tτ ∈ ⟦ simpl τ ⟧tp→\n ⟦ ⊢ta , i-simp τ , m ⟧r↓ = , ⊢ta\n ⟦ ⊢ta , i-iabs {ρ₁ = a} ⊢ᵣa b↓τ , m ⟧r↓ =\n , (proj₂ ⟦ ⊢ta F.· (proj₂ ⟦ ⊢ᵣa , m ⟧r) , b↓τ , m ⟧r↓)\n ⟦ ⊢ta , i-tabs {ρ = a} b p , m ⟧r↓ =\n ⟦ subst (λ u → _ F.⊢ _ ∈ u) (sym $ ⟦a/sub⟧tp→ a b) (⊢ta F.[ ⟦ b ⟧tp→ ]) , p , m ⟧r↓\n\n ⟦ r-iabs {ρ₁ = a} {ρ₂ = b} ⊢b , m ⟧r = , F.λ' ⟦ a ⟧tp→ (proj₂ ⟦ ⊢b , #ivar a m ⟧r)\n\n ⟦_,_⟧r {Γ = Γ} (r-tabs {ρ = r} p) m with ⟦ p , #tvar m ⟧r\n ⟦_,_⟧r {Δ = Δ} {Γ = Γ} (r-tabs {ρ = r} p) m | _ , x =\n , F.Λ (subst (λ u → u F.⊢ _ ∈ ⟦ r ⟧tp→) (⟦weaken⟧ctx→ Γ) x)\n\nopen Semantics _⊢ᵣ_ DerivationSemantics.⟦_,_⟧r public\n", "meta": {"hexsha": "db46eb50d598924519cc7c31f95c045313b4f332", "size": 1856, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Implicits/Resolution/Infinite/Semantics.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/Infinite/Semantics.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/Infinite/Semantics.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": 37.12, "max_line_length": 91, "alphanum_fraction": 0.5140086207, "num_tokens": 896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.38703178250911585}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import lib.Basics\nopen import lib.NType2\nopen import lib.PathGroupoid\n\nopen import lib.types.Bool\nopen import lib.types.IteratedSuspension\nopen import lib.types.Lift\nopen import lib.types.LoopSpace\nopen import lib.types.Nat\nopen import lib.types.Paths\nopen import lib.types.Pi\nopen import lib.types.Pointed\nopen import lib.types.Sigma\nopen import lib.types.Suspension\nopen import lib.types.TLevel\nopen import lib.types.Unit\n\nopen SuspensionRec public using () renaming (f to Susp-rec)\n\nopen import nicolai.pseudotruncations.Preliminary-definitions\nopen import nicolai.pseudotruncations.Liblemmas\nopen import nicolai.pseudotruncations.pointed-O-Sphere\n\n\nmodule nicolai.pseudotruncations.LoopsAndSpheres where\n\n{- We greatly benefit from Evan Cavallo's code - thank you! -}\nopen import homotopy.PtdAdjoint\nopen import homotopy.SuspAdjointLoop\n\n\n\n\nisNull : ∀ {i j} {A : Type i} {B : Type j} (b : B) (f : A → B) → Type _\nisNull {A = A} b f = (a : A) → f a == b\n\n\nmodule null {i} {j} { : Ptd i} {B̂ : Ptd j} (ĝ :  →̇ B̂) where\n\n A = fst Â\n a₀ = snd  \n B = fst B̂\n b₀ = snd B̂\n g = fst ĝ\n p = snd ĝ \n\n -- derived isNull\n isNulld = (a : fst Â) → g a == b₀ \n\n -- pointed isNull; we state it in the equivalence form (slightly easier to handle)\n isNull∙' = Σ ((a : A) → g a == b₀) λ pr → pr a₀ == p\n\n -- the 'real' pointed isNull\n isNull∙ = ĝ == ((λ _ → b₀) , idp)\n\n {- The two versions are equivalent -}\n isNull-equiv : isNull∙ ≃ isNull∙'\n isNull-equiv =\n ĝ == ((λ _ → b₀) , idp)\n ≃⟨ (=Σ-eqv _ _) ⁻¹ ⟩\n =Σ ĝ ((λ _ → b₀) , idp)\n ≃⟨ equiv-Σ' {A₀ = g == λ _ → b₀}\n app=-equiv\n (λ h → (p == idp [ (λ f → f a₀ == b₀) ↓ h ])\n ≃⟨ to-transp-equiv _ _ ⟩\n (transport (λ f → f a₀ == b₀) h p) == idp\n ≃⟨ coe-equiv\n (ap (λ x → x == idp)\n (trans-ap₁ (λ f → f a₀)\n b₀ h p)) ⟩\n (! (app= h a₀) ∙ p) == idp\n ≃⟨ adhoc-=-eqv (app= h a₀) p ⟩\n (app= h a₀ == p)\n ≃∎) ⟩ \n (Σ ((a : A) → g a == b₀) λ pr → pr a₀ == p)\n ≃∎ \n\n-- Lemma 4.4: pointed and non-pointed 'nullness' are logically equivalent;\n-- First, one direction:\n null-lequiv : isNulld → isNull∙'\n null-lequiv isnull = (λ a → isnull a ∙ ! (isnull a₀) ∙ p) , (\n isnull a₀ ∙ ! (isnull a₀) ∙ p\n =⟨ ! (∙-assoc (isnull a₀) _ _) ⟩\n (isnull a₀ ∙ ! (isnull a₀)) ∙ p\n =⟨ ap (λ t → t ∙ p) (!-inv-r (isnull a₀)) ⟩\n p\n ∎)\n\n-- The other direction is very easy; we do it using the non-prime variant:\n null-lequiv-easy : isNull∙ → isNulld\n null-lequiv-easy isn = app= (ap fst isn)\n\n\n\n\n\n-- uncomment this if you want to wait forever for typechecking...\n-- Σ⊣Ω-unitCounit : CounitUnitAdjoint Σ⊣Ω.SuspFunctor Σ⊣Ω.LoopFunctor\nΣ⊣Ω-unitCounit = Σ⊣Ω.adj\n\nΣ⊣Ω-homset : ∀ {i} → HomAdjoint {i} {i} Σ⊣Ω.SuspFunctor Σ⊣Ω.LoopFunctor\nΣ⊣Ω-homset = counit-unit-to-hom Σ⊣Ω-unitCounit\n\nmodule hom-adjoint {i} ( : Ptd i) (B̂ : Ptd i) where\n\n A = fst Â\n B = fst B̂\n a₀ = snd Â\n b₀ = snd B̂\n\n Φeq : (⊙Susp  →̇ B̂) ≃ ( →̇ ⊙Ω B̂)\n Φeq = HomAdjoint.eq Σ⊣Ω-homset  B̂ \n\n {- This is Lemma 4.1 -}\n Φ : (⊙Susp  →̇ B̂) → ( →̇ ⊙Ω B̂)\n Φ = –> Φeq \n\n Φ⁻¹ : ( →̇ ⊙Ω B̂) → (⊙Susp  →̇ B̂)\n Φ⁻¹ = <– Φeq\n \n\n open PtdFunctor\n open Σ⊣Ω\n open CounitUnitAdjoint\n\n {- Some lemmas which are easy on paper and thus not explicitly \n mentioned in the paper. It still takes some effort to\n formalize them. -}\n module simplify where\n\n simpl-⊙ap : (⊙ap {X = obj SuspFunctor Â} ((λ _ → b₀) , idp))\n ==\n ((λ _ → idp) , idp)\n simpl-⊙ap = →̇-maps-to\n ⊙ap ((λ _ → b₀) , idp)\n ((λ _ → idp) , idp)\n (λ= (λ _ → ap-cst b₀ _))\n\n ((app= (λ= (λ _ → ap-cst b₀ _)) _) ∙ idp\n =⟨ ∙-unit-r _ ⟩\n app= (λ= (λ _ → ap-cst b₀ _)) _\n =⟨ app=-β _ _ ⟩\n ap-cst b₀ (idp {a = snd B̂}) \n =⟨ idp ⟩ -- !\n idp\n =⟨ idp ⟩ -- ! \n snd (⊙ap {X = obj SuspFunctor Â} ((λ _ → b₀) , idp))\n ∎ )\n\n simpl-comp : ((λ (_ : Ω (⊙Susp Â)) → idp {a = b₀}) , idp)\n ⊙∘ (⊙η Â)\n ==\n (λ _ → idp) , idp\n simpl-comp = pair= idp ((ap-cst idp (snd (⊙η Â))) ∙ᵣ idp)\n\n\n open simplify\n\n {- Lemma 4.2 -}\n Φ-is-pointed-map : Φ ((λ _ → b₀) , idp) == ((λ _ → idp) , idp)\n Φ-is-pointed-map = Φ ((λ _ → b₀) , idp)\n =⟨ idp ⟩\n ( arr LoopFunctor ((λ _ → b₀) , idp)\n ⊙∘ (CounitUnitAdjoint.η adj Â))\n =⟨ idp ⟩ \n ( (⊙ap {X = obj SuspFunctor Â} ((λ _ → b₀) , idp)\n ⊙∘ (⊙η Â)))\n =⟨ ap (λ f → f ⊙∘ (⊙η Â)) simpl-⊙ap ⟩\n ((λ _ → idp) , idp) ⊙∘ (⊙η Â)\n =⟨ simpl-comp ⟩ \n (λ _ → idp) , idp\n ∎ \n\n-- fix i\nmodule _ {i} where\n\n open hom-adjoint\n\n open HomAdjoint\n open null\n\n -- Lemma 4.3\n Φ-snd-nat : { B̂ Ĉ : Ptd i} (f : ⊙Susp  →̇ B̂) (g : B̂ →̇ Ĉ)\n → Φ Â Ĉ (g ⊙∘ f) == ⊙ap g ⊙∘ Φ Â B̂ f\n Φ-snd-nat {Â} {B̂} {Ĉ} f g = ! (nat-cod Σ⊣Ω-homset  {B̂} {Ĉ} g f)\n\n -- Lemma 4.4 is above (before 4.2).\n\n -- Lemma 4.5\n isnull-Φ : { B̂ : Ptd i} (g : ⊙Susp  →̇ B̂) → (isNull∙ g) ≃ isNull∙ (Φ Â B̂ g)\n isnull-Φ {Â} {B̂} g =\n isNull∙ g\n ≃⟨ equiv-ap (Φeq  B̂) _ _ ⟩\n (Φ Â B̂ g) == Φ Â B̂ ((λ _ → snd B̂) , idp)\n ≃⟨ coe-equiv\n {A = (Φ Â B̂ g) == Φ Â B̂ ((λ _ → snd B̂) , idp)}\n {B = (Φ Â B̂ g) == (λ _ → idp) , idp}\n (ap (λ q → (Φ Â B̂ g == q)) (Φ-is-pointed-map _ _ )) ⟩\n (Φ Â B̂ g) == (λ _ → idp) , idp\n ≃∎ \n\n\n -- combination of 4.3 and 4.5\n combine-isnull-nat : { B̂ Ĉ : Ptd i} (f : ⊙Susp  →̇ B̂) (g : B̂ →̇ Ĉ)\n → (isNull∙ (g ⊙∘ f)) ≃ (isNull∙ (⊙ap g ⊙∘ Φ Â B̂ f)) -- \n combine-isnull-nat {Â} {B̂} {Ĉ} f g = \n isNull∙ (g ⊙∘ f)\n ≃⟨ isnull-Φ _ ⟩\n isNull∙ (Φ Â Ĉ (g ⊙∘ f))\n ≃⟨ coe-equiv (ap (λ q → isNull∙ q) (Φ-snd-nat f g)) ⟩\n isNull∙ (⊙ap g ⊙∘ Φ Â B̂ f)\n ≃∎\n\n combine-isnull-nat' : { B̂ Ĉ : Ptd i} (f :  →̇ ⊙Ω B̂) (g : B̂ →̇ Ĉ)\n → (isNull∙ (g ⊙∘ (Φ⁻¹  B̂ f))) ≃ (isNull∙ (⊙ap g ⊙∘ f))\n combine-isnull-nat' {Â} {B̂} {Ĉ} f g = \n isNull∙ (g ⊙∘ (Φ⁻¹  B̂ f))\n ≃⟨ combine-isnull-nat (Φ⁻¹  B̂ f) g ⟩\n isNull∙ (⊙ap g ⊙∘ (Φ Â B̂ (Φ⁻¹  B̂ f)))\n ≃⟨ coe-equiv (ap (λ h → isNull∙ (⊙ap g ⊙∘ h)) (<–-inv-r (Φeq  B̂) f)) ⟩\n isNull∙ (⊙ap g ⊙∘ f)\n ≃∎ \n \n \n\n\nmodule _ {i} where\n\n open hom-adjoint\n\n -- This was tricky (todo: could explain why)\n Φ-iter : ( B̂ : Ptd i) (n : Nat)\n → ((⊙Susp-iter' n Â) →̇ B̂)\n → ( →̇ (⊙Ω^ n B̂))\n Φ-iter  B̂ O f = f\n Φ-iter  B̂ (S n) f = Φ Â (⊙Ω^ n B̂) (Φ-iter (⊙Susp Â) B̂ n f)\n\n Φ-iter-equiv : ( B̂ : Ptd i) (n : Nat) → is-equiv (Φ-iter  B̂ n)\n Φ-iter-equiv  B̂ O = snd (ide _)\n Φ-iter-equiv  B̂ (S n) =\n snd ((Φeq  (⊙Ω^ n B̂)) ∘e ((Φ-iter (⊙Susp Â) B̂ n) , Φ-iter-equiv (⊙Susp Â) B̂ n) )\n\n\n\nmodule _ {i} where\n\n open null\n open hom-adjoint\n \n -- Lemma 4.7 -- generalized, because we need to do it for Susp first before it works for Sphere!\n isNull-Φ-many : (m : Nat)\n → ( B̂ Ĉ : Ptd i)\n → (f : ⊙Susp-iter' m  →̇ B̂) (g : B̂ →̇ Ĉ)\n → isNull∙ (g ⊙∘ f)\n ≃\n isNull∙ ((ap^ m g) ⊙∘ Φ-iter  B̂ m f)\n isNull-Φ-many O  B̂ Ĉ f g = ide _\n isNull-Φ-many (S m)  B̂ Ĉ f g = \n isNull∙ (g ⊙∘ f)\n ≃⟨ isNull-Φ-many m (⊙Susp Â) B̂ Ĉ f g ⟩\n isNull∙ ((ap^ m g) ⊙∘ Φ-iter (⊙Susp Â) B̂ m f)\n ≃⟨ combine-isnull-nat (Φ-iter (⊙Susp Â) B̂ m f) (ap^ m g) ⟩\n (isNull∙\n (⊙ap (ap^ m g) ⊙∘\n Φ Â (⊙Ω^ m B̂)\n (Φ-iter (⊙Susp Â) B̂ m f)))\n ≃∎\n\n -- Lemma 4.7 (special with k = 0)\n module _ {B̂ Ĉ : Ptd i} (m : Nat)\n (f : ⊙Sphere' {i} m →̇ B̂) (g : B̂ →̇ Ĉ) where\n\n isNull-Φ-Sphere : isNull∙ (g ⊙∘ f)\n ≃\n isNull∙ ((ap^ m g) ⊙∘ Φ-iter (⊙Sphere' {i} O) B̂ m f)\n isNull-Φ-Sphere = isNull-Φ-many m _ _ _ f g\n\n\n open bool-neutral\n \n module _ {B̂ Ĉ : Ptd i} (m : Nat)\n (g : B̂ →̇ Ĉ) where\n\n c₀ = snd (⊙Ω^ m Ĉ)\n\n\n {- Lemma 4.8 -}\n null-on-pspaces :\n ((f : (⊙Sphere' {i} m) →̇ B̂) → isNull∙ (g ⊙∘ f))\n ≃\n isNulld (ap^ m g)\n \n null-on-pspaces = -- {!equiv-Π-l!}\n\n ((f : (⊙Sphere' {i} m) →̇ B̂) → isNull∙ (g ⊙∘ f))\n\n ≃⟨ equiv-Π-r (λ f → isNull-Φ-Sphere m f g) ⟩\n\n ((f : (⊙Sphere' {i} m) →̇ B̂) → isNull∙ ((ap^ m g) ⊙∘ Φ-iter (⊙Sphere' {i} O) B̂ m f))\n\n ≃⟨ equiv-Π-l\n {A = (⊙Sphere' {i} m) →̇ B̂}\n {B = (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)}\n (λ f' → isNull∙ ((ap^ m g) ⊙∘ f'))\n {h = Φ-iter (⊙Sphere' {i} O) B̂ m}\n (Φ-iter-equiv _ _ m)\n ⟩\n\n ((f' : (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)) → isNull∙ ((ap^ m g) ⊙∘ f'))\n\n ≃⟨ equiv-Π-r {A = ⊙Sphere' {i} O →̇ (⊙Ω^ m B̂)} (λ _ → isNull-equiv _) ⟩\n\n ((f' : (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)) → isNull∙' ((ap^ m g) ⊙∘ f'))\n \n ≃⟨ ide _ ⟩ \n\n ((f' : (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)) → Σ ((x : bool) → fst ((ap^ m g) ⊙∘ f') x == _) λ h → h tt₀ == _)\n \n ≃⟨ equiv-Π-r {A = ⊙Sphere' {i} O →̇ (⊙Ω^ m B̂)}\n (λ fp → reduction (λ b → fst (ap^ m g ⊙∘ fp) b == null.b₀ (ap^ m g ⊙∘ fp)) _) ⟩ \n\n ((f' : (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)) → fst ((ap^ m g) ⊙∘ f') ff₀ == _)\n\n ≃⟨ ide _ ⟩ \n\n ((f' : (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)) → fst (ap^ m g) (fst f' ff₀) == _)\n\n ≃⟨ equiv-Π-l {A = (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)}\n {B = fst (⊙Ω^ m B̂)}\n _\n (snd (reduction (λ _ → fst (⊙Ω^ m B̂)) _)) ⟩ \n\n ((x : fst (⊙Ω^ m B̂)) → fst (ap^ m g) x == c₀)\n\n ≃⟨ ide _ ⟩ \n\n isNulld (ap^ m g)\n ≃∎\n\n\n", "meta": {"hexsha": "2e9bb0b89120a95609ce5cacc69f08263c93b676", "size": 10731, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "nicolai/pseudotruncations/LoopsAndSpheres.agda", "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolai/pseudotruncations/LoopsAndSpheres.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": "nicolai/pseudotruncations/LoopsAndSpheres.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": 31.2857142857, "max_line_length": 110, "alphanum_fraction": 0.4069518218, "num_tokens": 4826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6791786861878392, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3870317751081239}} {"text": "open import Relation.Binary.Core\n\nmodule BBHeap.Push {A : Set}\n (_≤_ : A → A → Set)\n (tot≤ : Total _≤_) \n (trans≤ : Transitive _≤_) where\n\nopen import BBHeap _≤_\nopen import BBHeap.Equality _≤_\nopen import BBHeap.Equality.Properties _≤_\nopen import Bound.Lower A \nopen import Bound.Lower.Order _≤_\nopen import Bound.Lower.Order.Properties _≤_ trans≤\nopen import Data.Sum renaming (_⊎_ to _∨_)\nopen import Order.Total _≤_ tot≤ \n\nmutual\n push⋘ : {b : Bound}{x y : A}{l r : BBHeap (val y)} → LeB b (val x) → LeB b (val y) → l ⋘ r → BBHeap b \n push⋘ b≤x _ lf⋘ = left b≤x lf⋘\n push⋘ {x = x} b≤x b≤y (ll⋘ {x = y₁} {x' = y₂} y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂)\n with tot≤ y₁ y₂ | tot≤ x y₁ | tot≤ x y₂\n ... | inj₁ y₁≤y₂ | inj₁ x≤y₁ | _ = left b≤x (ll⋘ (lexy x≤y₁) (lexy (trans≤ x≤y₁ y₁≤y₂)) l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂)\n ... | inj₁ y₁≤y₂ | inj₂ y₁≤x | _ =\n let pl'≈l' = lemma-push⋘ (lexy y₁≤x) (lexy refl≤) l₁⋘r₁ ;\n l'⋘r' = ll⋘ (lexy refl≤) (lexy y₁≤y₂) l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;\n pl'⋘r' = lemma≈⋘ pl'≈l' l'⋘r'\n in left (transLeB b≤y y≤y₁) pl'⋘r'\n ... | inj₂ y₂≤y₁ | _ | inj₁ x≤y₂ = left b≤x (ll⋘ (lexy (trans≤ x≤y₂ y₂≤y₁)) (lexy x≤y₂) l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂)\n ... | inj₂ y₂≤y₁ | _ | inj₂ y₂≤x =\n let pr'≈r' = lemma-push⋘ (lexy y₂≤x) (lexy refl≤) l₂⋘r₂ ;\n r'≈pr' = sym≈ pr'≈r' ;\n l'⋘r' = ll⋘ (lexy y₂≤y₁) (lexy refl≤) l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;\n l'⋘pr' = lemma⋘≈ l'⋘r' r'≈pr'\n in left (transLeB b≤y y≤y₂) l'⋘pr'\n push⋘ {x = x} b≤x b≤y (lr⋘ {x = y₁} {x' = y₂} y≤y₁ y≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂)\n with tot≤ y₁ y₂ | tot≤ x y₁ | tot≤ x y₂\n ... | inj₁ y₁≤y₂ | inj₁ x≤y₁ | _ = left b≤x (lr⋘ (lexy x≤y₁) (lexy (trans≤ x≤y₁ y₁≤y₂)) l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂)\n ... | inj₁ y₁≤y₂ | inj₂ y₁≤x | _ =\n let pl'≈l' = lemma-push⋙ (lexy y₁≤x) (lexy refl≤) l₁⋙r₁ ;\n l'⋘r' = lr⋘ (lexy refl≤) (lexy y₁≤y₂) l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ ;\n pl'⋘r' = lemma≈⋘ pl'≈l' l'⋘r'\n in left (transLeB b≤y y≤y₁) pl'⋘r'\n ... | inj₂ y₂≤y₁ | _ | inj₁ x≤y₂ = left b≤x (lr⋘ (lexy (trans≤ x≤y₂ y₂≤y₁)) (lexy x≤y₂) l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂)\n ... | inj₂ y₂≤y₁ | _ | inj₂ y₂≤x =\n let pr'≈r' = lemma-push⋘ (lexy y₂≤x) (lexy refl≤) l₂⋘r₂ ;\n r'≈pr' = sym≈ pr'≈r' ;\n l'⋘r' = lr⋘ (lexy y₂≤y₁) (lexy refl≤) l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ ;\n l'⋘pr' = lemma⋘≈ l'⋘r' r'≈pr'\n in left (transLeB b≤y y≤y₂) l'⋘pr'\n\n push⋙ : {b : Bound}{x y : A}{l r : BBHeap (val y)} → LeB b (val x) → LeB b (val y) → l ⋙ r → BBHeap b \n push⋙ {x = x} b≤x b≤y (⋙lf {x = z} y≤z)\n with tot≤ x z\n ... | inj₁ x≤z = right b≤x (⋙lf (lexy x≤z))\n ... | inj₂ z≤x = right (transLeB b≤y y≤z) (⋙lf (lexy z≤x))\n push⋙ {x = x} b≤x b≤y (⋙rl {x = y₁} {x' = y₂} y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂)\n with tot≤ y₁ y₂ | tot≤ x y₁ | tot≤ x y₂\n ... | inj₁ y₁≤y₂ | inj₁ x≤y₁ | _ = right b≤x (⋙rl (lexy x≤y₁) (lexy (trans≤ x≤y₁ y₁≤y₂)) l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂)\n ... | inj₁ y₁≤y₂ | inj₂ y₁≤x | _ =\n let pl'≈l' = lemma-push⋘ (lexy y₁≤x) (lexy refl≤) l₁⋘r₁ ;\n l'⋙r' = ⋙rl (lexy refl≤) (lexy y₁≤y₂) l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂ ;\n pl'⋙r' = lemma≈⋙ pl'≈l' l'⋙r'\n in right (transLeB b≤y y≤y₁) pl'⋙r'\n ... | inj₂ y₂≤y₁ | _ | inj₁ x≤y₂ = right b≤x (⋙rl (lexy (trans≤ x≤y₂ y₂≤y₁)) (lexy x≤y₂) l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂)\n ... | inj₂ y₂≤y₁ | _ | inj₂ y₂≤x =\n let pr'≈r' = lemma-push⋘ (lexy y₂≤x) (lexy refl≤) l₂⋘r₂ ;\n r'≈pr' = sym≈ pr'≈r' ;\n l'⋙r' = ⋙rl (lexy y₂≤y₁) (lexy refl≤) l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂ ;\n l'⋙pr' = lemma⋙≈ l'⋙r' r'≈pr'\n in right (transLeB b≤y y≤y₂) l'⋙pr'\n push⋙ {x = x} b≤x b≤y (⋙rr {x = y₁} {x' = y₂} y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂)\n with tot≤ y₁ y₂ | tot≤ x y₁ | tot≤ x y₂\n ... | inj₁ y₁≤y₂ | inj₁ x≤y₁ | _ = right b≤x (⋙rr (lexy x≤y₁) (lexy (trans≤ x≤y₁ y₁≤y₂)) l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂)\n ... | inj₁ y₁≤y₂ | inj₂ y₁≤x | _ =\n let pl'≈l' = lemma-push⋘ (lexy y₁≤x) (lexy refl≤) l₁⋘r₁ ;\n l'⋙r' = ⋙rr (lexy refl≤) (lexy y₁≤y₂) l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂ ;\n pl'⋙r' = lemma≈⋙ pl'≈l' l'⋙r'\n in right (transLeB b≤y y≤y₁) pl'⋙r'\n ... | inj₂ y₂≤y₁ | _ | inj₁ x≤y₂ = right b≤x (⋙rr (lexy (trans≤ x≤y₂ y₂≤y₁)) (lexy x≤y₂) l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂)\n ... | inj₂ y₂≤y₁ | _ | inj₂ y₂≤x =\n let pr'≈r' = lemma-push⋙ (lexy y₂≤x) (lexy refl≤) l₂⋙r₂ ;\n r'≈pr' = sym≈ pr'≈r' ;\n l'⋙r' = ⋙rr (lexy y₂≤y₁) (lexy refl≤) l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂ ;\n l'⋙pr' = lemma⋙≈ l'⋙r' r'≈pr'\n in right (transLeB b≤y y≤y₂) l'⋙pr'\n\n lemma-push⋘ : {b : Bound}{x y : A}{l r : BBHeap (val y)}(b≤x : LeB b (val x))(b≤y : LeB b (val y))(l⋘r : l ⋘ r) → push⋘ b≤x b≤y l⋘r ≈ left b≤y l⋘r\n lemma-push⋘ b≤x b≤y lf⋘ = ≈left b≤x b≤y lf⋘ lf⋘ ≈leaf ≈leaf\n lemma-push⋘ {x = x} b≤x b≤y (ll⋘ {x = y₁} {x' = y₂} y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂)\n with tot≤ y₁ y₂ | tot≤ x y₁ | tot≤ x y₂\n ... | inj₁ y₁≤y₂ | inj₁ x≤y₁ | _ =\n let l⋘r = ll⋘ y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;\n x≤y₂ = lexy (trans≤ x≤y₁ y₁≤y₂) ;\n l'⋘r' = ll⋘ (lexy x≤y₁) x≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;\n l'≈l = ≈left (lexy x≤y₁) y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;\n r'≈r = ≈left x≤y₂ y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈\n in ≈left b≤x b≤y l'⋘r' l⋘r l'≈l r'≈r \n ... | inj₁ y₁≤y₂ | inj₂ y₁≤x | _ =\n let l⋘r = ll⋘ y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;\n pl'≈l' = lemma-push⋘ (lexy y₁≤x) (lexy refl≤) l₁⋘r₁ ;\n l'⋘r' = ll⋘ (lexy refl≤) (lexy y₁≤y₂) l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;\n pl'⋘r' = lemma≈⋘ pl'≈l' l'⋘r' ;\n l'≈l = ≈left (lexy refl≤) y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;\n pl'≈l = trans≈ pl'≈l' l'≈l ;\n r'≈r = ≈left (lexy y₁≤y₂) y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈\n in ≈left (transLeB b≤y y≤y₁) b≤y pl'⋘r' l⋘r pl'≈l r'≈r \n ... | inj₂ y₂≤y₁ | _ | inj₁ x≤y₂ = \n let l⋘r = ll⋘ y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;\n x≤y₁ = lexy (trans≤ x≤y₂ y₂≤y₁) ;\n l'⋘r' = ll⋘ x≤y₁ (lexy x≤y₂) l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;\n r'≈r = ≈left (lexy x≤y₂) y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈ ;\n l'≈l = ≈left x≤y₁ y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈\n in ≈left b≤x b≤y l'⋘r' l⋘r l'≈l r'≈r \n ... | inj₂ y₂≤y₁ | _ | inj₂ y₂≤x = \n let l⋘r = ll⋘ y≤y₁ y≤y₂ l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;\n pr'≈r' = lemma-push⋘ (lexy y₂≤x) (lexy refl≤) l₂⋘r₂ ;\n r'≈pr' = sym≈ pr'≈r' ;\n l'⋘r' = ll⋘ (lexy y₂≤y₁) (lexy refl≤) l₁⋘r₁ l₂⋘r₂ l₂≃r₂ r₁≃l₂ ;\n l'⋘pr' = lemma⋘≈ l'⋘r' r'≈pr' ;\n r'≈r = ≈left (lexy refl≤) y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈ ;\n pr'≈r = trans≈ pr'≈r' r'≈r ;\n l'≈l = ≈left (lexy y₂≤y₁) y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈\n in ≈left (transLeB b≤y y≤y₂) b≤y l'⋘pr' l⋘r l'≈l pr'≈r\n lemma-push⋘ {x = x} b≤x b≤y (lr⋘ {x = y₁} {x' = y₂} y≤y₁ y≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂)\n with tot≤ y₁ y₂ | tot≤ x y₁ | tot≤ x y₂\n ... | inj₁ y₁≤y₂ | inj₁ x≤y₁ | _ =\n let l⋘r = lr⋘ y≤y₁ y≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ ;\n x≤y₂ = lexy (trans≤ x≤y₁ y₁≤y₂) ;\n l'⋘r' = lr⋘ (lexy x≤y₁) x≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ ;\n l'≈l = ≈right (lexy x≤y₁) y≤y₁ l₁⋙r₁ l₁⋙r₁ refl≈ refl≈ ;\n r'≈r = ≈left x≤y₂ y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈\n in ≈left b≤x b≤y l'⋘r' l⋘r l'≈l r'≈r\n ... | inj₁ y₁≤y₂ | inj₂ y₁≤x | _ =\n let l⋘r = lr⋘ y≤y₁ y≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ ;\n pl'≈l' = lemma-push⋙ (lexy y₁≤x) (lexy refl≤) l₁⋙r₁ ;\n l'⋘r' = lr⋘ (lexy refl≤) (lexy y₁≤y₂) l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ ;\n pl'⋘r' = lemma≈⋘ pl'≈l' l'⋘r' ;\n l'≈l = ≈right (lexy refl≤) y≤y₁ l₁⋙r₁ l₁⋙r₁ refl≈ refl≈ ;\n pl'≈l = trans≈ pl'≈l' l'≈l ;\n r'≈r = ≈left (lexy y₁≤y₂) y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈\n in ≈left (transLeB b≤y y≤y₁) b≤y pl'⋘r' l⋘r pl'≈l r'≈r\n ... | inj₂ y₂≤y₁ | _ | inj₁ x≤y₂ =\n let l⋘r = lr⋘ y≤y₁ y≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ ;\n x≤y₁ = lexy (trans≤ x≤y₂ y₂≤y₁) ;\n l'⋘r' = lr⋘ x≤y₁ (lexy x≤y₂) l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ ;\n l'≈l = ≈right x≤y₁ y≤y₁ l₁⋙r₁ l₁⋙r₁ refl≈ refl≈ ;\n r'≈r = ≈left (lexy x≤y₂) y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈\n in ≈left b≤x b≤y l'⋘r' l⋘r l'≈l r'≈r\n ... | inj₂ y₂≤y₁ | _ | inj₂ y₂≤x =\n let l⋘r = lr⋘ y≤y₁ y≤y₂ l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ ;\n pr'≈r' = lemma-push⋘ (lexy y₂≤x) (lexy refl≤) l₂⋘r₂ ;\n r'≈pr' = sym≈ pr'≈r' ;\n l'⋘r' = lr⋘ (lexy y₂≤y₁) (lexy refl≤) l₁⋙r₁ l₂⋘r₂ l₂≃r₂ l₁⋗l₂ ;\n l'⋘pr' = lemma⋘≈ l'⋘r' r'≈pr' ;\n l'≈l = ≈right (lexy y₂≤y₁) y≤y₁ l₁⋙r₁ l₁⋙r₁ refl≈ refl≈ ;\n r'≈r = ≈left (lexy refl≤) y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈ ;\n pr'≈r = trans≈ pr'≈r' r'≈r\n in ≈left (transLeB b≤y y≤y₂) b≤y l'⋘pr' l⋘r l'≈l pr'≈r\n\n lemma-push⋙ : {b : Bound}{x y : A}{l r : BBHeap (val y)}(b≤x : LeB b (val x))(b≤y : LeB b (val y))(l⋙r : l ⋙ r) → push⋙ b≤x b≤y l⋙r ≈ right b≤y l⋙r\n lemma-push⋙ {x = x} b≤x b≤y (⋙lf {x = z} y≤z)\n with tot≤ x z\n ... | inj₁ x≤z = ≈right b≤x b≤y (⋙lf (lexy x≤z)) (⋙lf y≤z) (≈left (lexy x≤z) y≤z lf⋘ lf⋘ ≈leaf ≈leaf) ≈leaf\n ... | inj₂ z≤x = ≈right (transLeB b≤y y≤z) b≤y (⋙lf (lexy z≤x)) (⋙lf y≤z) (≈left (lexy z≤x) y≤z lf⋘ lf⋘ ≈leaf ≈leaf) ≈leaf\n lemma-push⋙ {x = x} b≤x b≤y (⋙rl {x = y₁} {x' = y₂} y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂)\n with tot≤ y₁ y₂ | tot≤ x y₁ | tot≤ x y₂\n ... | inj₁ y₁≤y₂ | inj₁ x≤y₁ | _ =\n let l⋙r = ⋙rl y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂ ;\n x≤y₂ = lexy (trans≤ x≤y₁ y₁≤y₂) ;\n l'⋙r' = ⋙rl (lexy x≤y₁) x≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂ ;\n l'≈l = ≈left (lexy x≤y₁) y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;\n r'≈r = ≈left x≤y₂ y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈\n in ≈right b≤x b≤y l'⋙r' l⋙r l'≈l r'≈r\n ... | inj₁ y₁≤y₂ | inj₂ y₁≤x | _ =\n let l⋙r = ⋙rl y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂ ;\n pl'≈l' = lemma-push⋘ (lexy y₁≤x) (lexy refl≤) l₁⋘r₁ ;\n l'⋙r' = ⋙rl (lexy refl≤) (lexy y₁≤y₂) l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂ ;\n pl'⋙r' = lemma≈⋙ pl'≈l' l'⋙r' ;\n l'≈l = ≈left (lexy refl≤) y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;\n pl'≈l = trans≈ pl'≈l' l'≈l ;\n r'≈r = ≈left (lexy y₁≤y₂) y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈\n in ≈right (transLeB b≤y y≤y₁) b≤y pl'⋙r' l⋙r pl'≈l r'≈r\n ... | inj₂ y₂≤y₁ | _ | inj₁ x≤y₂ =\n let l⋙r = ⋙rl y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂ ;\n x≤y₁ = lexy (trans≤ x≤y₂ y₂≤y₁) ;\n l'⋙r' = ⋙rl x≤y₁ (lexy x≤y₂) l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂ ;\n l'≈l = ≈left x≤y₁ y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;\n r'≈r = ≈left (lexy x≤y₂) y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈\n in ≈right b≤x b≤y l'⋙r' l⋙r l'≈l r'≈r\n ... | inj₂ y₂≤y₁ | _ | inj₂ y₂≤x =\n let l⋙r = ⋙rl y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂ ;\n pr'≈r' = lemma-push⋘ (lexy y₂≤x) (lexy refl≤) l₂⋘r₂ ;\n r'≈pr' = sym≈ pr'≈r' ;\n l'⋙r' = ⋙rl (lexy y₂≤y₁) (lexy refl≤) l₁⋘r₁ l₁≃r₁ l₂⋘r₂ l₁⋗r₂ ;\n l'⋙pr' = lemma⋙≈ l'⋙r' r'≈pr' ;\n l'≈l = ≈left (lexy y₂≤y₁) y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;\n r'≈r = ≈left (lexy refl≤) y≤y₂ l₂⋘r₂ l₂⋘r₂ refl≈ refl≈ ;\n pr'≈r = trans≈ pr'≈r' r'≈r\n in ≈right (transLeB b≤y y≤y₂) b≤y l'⋙pr' l⋙r l'≈l pr'≈r\n lemma-push⋙ {x = x} b≤x b≤y (⋙rr {x = y₁} {x' = y₂} y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂)\n with tot≤ y₁ y₂ | tot≤ x y₁ | tot≤ x y₂\n ... | inj₁ y₁≤y₂ | inj₁ x≤y₁ | _ =\n let l⋙r = ⋙rr y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂ ;\n x≤y₂ = lexy (trans≤ x≤y₁ y₁≤y₂) ;\n l'⋙r' = ⋙rr (lexy x≤y₁) x≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂ ;\n l'≈l = ≈left (lexy x≤y₁) y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;\n r'≈r = ≈right x≤y₂ y≤y₂ l₂⋙r₂ l₂⋙r₂ refl≈ refl≈ \n in ≈right b≤x b≤y l'⋙r' l⋙r l'≈l r'≈r\n ... | inj₁ y₁≤y₂ | inj₂ y₁≤x | _ =\n let l⋙r = ⋙rr y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂ ;\n pl'≈l' = lemma-push⋘ (lexy y₁≤x) (lexy refl≤) l₁⋘r₁ ;\n l'⋙r' = ⋙rr (lexy refl≤) (lexy y₁≤y₂) l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂ ;\n pl'⋙r' = lemma≈⋙ pl'≈l' l'⋙r' ;\n l'≈l = ≈left (lexy refl≤) y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;\n pl'≈l = trans≈ pl'≈l' l'≈l ;\n r'≈r = ≈right (lexy y₁≤y₂) y≤y₂ l₂⋙r₂ l₂⋙r₂ refl≈ refl≈\n in ≈right (transLeB b≤y y≤y₁) b≤y pl'⋙r' l⋙r pl'≈l r'≈r\n ... | inj₂ y₂≤y₁ | _ | inj₁ x≤y₂ =\n let l⋙r = ⋙rr y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂ ;\n x≤y₁ = lexy (trans≤ x≤y₂ y₂≤y₁) ;\n l'⋙r' = ⋙rr x≤y₁ (lexy x≤y₂) l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂ ;\n l'≈l = ≈left x≤y₁ y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;\n r'≈r = ≈right (lexy x≤y₂) y≤y₂ l₂⋙r₂ l₂⋙r₂ refl≈ refl≈\n in ≈right b≤x b≤y l'⋙r' l⋙r l'≈l r'≈r\n ... | inj₂ y₂≤y₁ | _ | inj₂ y₂≤x =\n let l⋙r = ⋙rr y≤y₁ y≤y₂ l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂ ;\n pr'≈r' = lemma-push⋙ (lexy y₂≤x) (lexy refl≤) l₂⋙r₂ ;\n r'≈pr' = sym≈ pr'≈r' ;\n l'⋙r' = ⋙rr (lexy y₂≤y₁) (lexy refl≤) l₁⋘r₁ l₁≃r₁ l₂⋙r₂ l₁≃l₂ ;\n l'⋙pr' = lemma⋙≈ l'⋙r' r'≈pr' ;\n l'≈l = ≈left (lexy y₂≤y₁) y≤y₁ l₁⋘r₁ l₁⋘r₁ refl≈ refl≈ ;\n r'≈r = ≈right (lexy refl≤) y≤y₂ l₂⋙r₂ l₂⋙r₂ refl≈ refl≈ ;\n pr'≈r = trans≈ pr'≈r' r'≈r \n in ≈right (transLeB b≤y y≤y₂) b≤y l'⋙pr' l⋙r l'≈l pr'≈r\n\npush : {b : Bound}{x : A} → LeB b (val x) → BBHeap b → BBHeap b\npush _ leaf = leaf\npush b≤x (left b≤y l⋘r) = push⋘ b≤x b≤y l⋘r\npush b≤x (right b≤y l⋙r) = push⋙ b≤x b≤y l⋙r\n", "meta": {"hexsha": "54e36cfef89235c2980b367681e943dbddef9c94", "size": 15128, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda/BBHeap/Push.agda", "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_issues_repo_path": "agda/BBHeap/Push.agda", "max_issues_repo_name": "bgbianchi/sorting", "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "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/BBHeap/Push.agda", "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "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": 63.0333333333, "max_line_length": 149, "alphanum_fraction": 0.415586991, "num_tokens": 8925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.3869496648471888}} {"text": "\nopen import Common.Prelude\nopen import Common.Reflect\n\nid : Nat → Nat\nid x = x\n\n-- Used to give error:\n-- unquote must be applied to a term\n-- when checking that the expression unquote has type _3 x\ni : Nat → Nat\ni x = unquote (def (quote id) []) x\n", "meta": {"hexsha": "936bdebf354136b60f8b4470d53774da9bc8bed5", "size": 250, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/succeed/Issue1210.agda", "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "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": "test/succeed/Issue1210.agda", "max_issues_repo_name": "larrytheliquid/agda", "max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "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/succeed/Issue1210.agda", "max_forks_repo_name": "larrytheliquid/agda", "max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "avg_line_length": 19.2307692308, "max_line_length": 58, "alphanum_fraction": 0.692, "num_tokens": 74, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.38680521434688236}} {"text": "\nmodule Issue512 where\n\nopen import Common.Equality\n\ndata A : Set where\n a b : A\n\nproof : a ≡ a\nproof = refl\n\nf : A → A → A\nf x y rewrite proof = {!!}\n\n-- gave error below (now complains about LEVELZERO instead of STRING):\n-- No binding for builtin thing STRING, use {-# BUILTIN STRING name #-} to bind it to 'name'\n-- when checking that the type of the generated with function\n-- (w : A) → _≡_ {\"Max []\"} {A} w w → (x y : A) → A is well-formed\n\n-- Andreas, 2014-05-17: After fixing 1110, there is no error any more,\n-- just an unsolved meta.\n", "meta": {"hexsha": "25cbd6a7d97ad7f838208c9e659ce54a9945202e", "size": 544, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue512.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/Issue512.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/Issue512.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": 24.7272727273, "max_line_length": 92, "alphanum_fraction": 0.65625, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.38680521434688236}} {"text": "------------------------------------------------------------------------\n-- The \"time complexity\" of the compiled program matches the one\n-- obtained from the instrumented interpreter\n------------------------------------------------------------------------\n\nopen import Prelude hiding (_+_; _*_)\n\nimport Lambda.Syntax\n\nmodule Lambda.Compiler-correctness.Steps-match\n {Name : Type}\n (open Lambda.Syntax Name)\n (def : Name → Tm 1)\n where\n\nimport Equality.Propositional as E\nopen import Logical-equivalence using (_⇔_)\nimport Tactic.By.Propositional as By\nopen import Prelude.Size\n\nopen import Conat E.equality-with-J as Conat\n using (Conat; zero; suc; force; ⌜_⌝; _+_; _*_; max;\n [_]_≤_; step-≤; step-∼≤; _∎≤)\nopen import Function-universe E.equality-with-J hiding (_∘_)\nopen import List E.equality-with-J using (_++_)\nopen import Monad E.equality-with-J using (return; _>>=_; _⟨$⟩_)\nopen import Vec.Data E.equality-with-J\n\nopen import Delay-monad\nopen import Delay-monad.Bisimilarity\nopen import Delay-monad.Quantitative-weak-bisimilarity\n\nopen import Lambda.Compiler def\nopen import Lambda.Delay-crash\nopen import Lambda.Interpreter.Steps def\nopen import Lambda.Virtual-machine.Instructions Name hiding (crash)\nopen import Lambda.Virtual-machine comp-name\n\nprivate\n module C = Closure Code\n module T = Closure Tm\n\n------------------------------------------------------------------------\n-- Some lemmas\n\n-- A rearrangement lemma for ⟦_⟧.\n\n⟦⟧-· :\n ∀ {n} (t₁ t₂ : Tm n) {ρ} {k : T.Value → Delay-crash C.Value ∞} →\n ⟦ t₁ · t₂ ⟧ ρ >>= k ∼\n ⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ >>= k\n⟦⟧-· t₁ t₂ {ρ} {k} =\n ⟦ t₁ · t₂ ⟧ ρ >>= k ∼⟨⟩\n\n (do v₁ ← ⟦ t₁ ⟧ ρ\n v₂ ← ⟦ t₂ ⟧ ρ\n v₁ ∙ v₂) >>= k ∼⟨ symmetric (associativity (⟦ t₁ ⟧ _) _ _) ⟩\n\n (do v₁ ← ⟦ t₁ ⟧ ρ\n (do v₂ ← ⟦ t₂ ⟧ ρ\n v₁ ∙ v₂) >>= k) ∼⟨ (⟦ t₁ ⟧ _ ∎) >>=-cong (λ _ → symmetric (associativity (⟦ t₂ ⟧ _) _ _)) ⟩\n\n (do v₁ ← ⟦ t₁ ⟧ ρ\n v₂ ← ⟦ t₂ ⟧ ρ\n v₁ ∙ v₂ >>= k) ∎\n\n-- Lemmas related to conatural numbers.\n\nprivate\n\n lemma₁ : ∀ {δ} → [ ∞ ] δ ≤ ⌜ 1 ⌝ + δ\n lemma₁ = Conat.≤suc\n\n lemma₂ : ∀ {δ} → [ ∞ ] δ ≤ max ⌜ 1 ⌝ δ\n lemma₂ = Conat.ʳ≤max ⌜ 1 ⌝ _\n\n lemma₃ : ∀ {δ} → [ ∞ ] max ⌜ 1 ⌝ δ ≤ max ⌜ 1 ⌝ δ + ⌜ 1 ⌝\n lemma₃ = Conat.m≤m+n\n\n lemma₄ : ∀ {δ} → [ ∞ ] δ ≤ max ⌜ 1 ⌝ δ + ⌜ 1 ⌝\n lemma₄ {δ} =\n δ ≤⟨ lemma₂ ⟩\n max ⌜ 1 ⌝ δ ≤⟨ lemma₃ {δ = δ} ⟩\n max ⌜ 1 ⌝ δ + ⌜ 1 ⌝ ∎≤\n\n lemma₅ : ∀ {δ} → [ ∞ ] ⌜ 1 ⌝ + δ ≤ δ + ⌜ 1 ⌝\n lemma₅ {δ} =\n ⌜ 1 ⌝ + δ ∼⟨ Conat.+-comm ⌜ 1 ⌝ ⟩≤\n δ + ⌜ 1 ⌝ ∎≤\n\n lemma₆ : ∀ {δ} → [ ∞ ] ⌜ 1 ⌝ + δ ≤ max ⌜ 1 ⌝ δ + ⌜ 1 ⌝\n lemma₆ {δ} =\n ⌜ 1 ⌝ + δ ≤⟨ lemma₅ ⟩\n δ + ⌜ 1 ⌝ ≤⟨ lemma₂ Conat.+-mono (⌜ 1 ⌝ ∎≤) ⟩\n max ⌜ 1 ⌝ δ + ⌜ 1 ⌝ ∎≤\n\n lemma₇ : ∀ {δ} → [ ∞ ] max ⌜ 1 ⌝ (⌜ 1 ⌝ + δ) ≤ ⌜ 1 ⌝ + δ\n lemma₇ {δ} = suc λ { .force →\n δ ∎≤ }\n\n lemma₈ : ∀ {δ} → [ ∞ ] max ⌜ 1 ⌝ (max ⌜ 1 ⌝ δ) ≤ max ⌜ 1 ⌝ δ\n lemma₈ {δ} = suc λ { .force →\n Conat.pred δ ∎≤ }\n\n lemma₉ :\n ∀ {δ} → [ ∞ ] max ⌜ 1 ⌝ (max ⌜ 1 ⌝ (max ⌜ 1 ⌝ δ)) ≤ max ⌜ 1 ⌝ δ\n lemma₉ {δ} =\n max ⌜ 1 ⌝ (max ⌜ 1 ⌝ (max ⌜ 1 ⌝ δ)) ≤⟨ lemma₈ ⟩\n max ⌜ 1 ⌝ (max ⌜ 1 ⌝ δ) ≤⟨ lemma₈ ⟩\n max ⌜ 1 ⌝ δ ∎≤\n\n lemma₁₀ : ∀ {δ} → [ ∞ ] ⌜ 1 ⌝ + ⌜ 0 ⌝ ≤ max ⌜ 1 ⌝ δ\n lemma₁₀ = suc λ { .force → zero }\n\n lemma₁₁ : Conat.[ ∞ ] max ⌜ 1 ⌝ ⌜ 1 ⌝ ∼ ⌜ 1 ⌝\n lemma₁₁ = suc λ { .force → zero }\n\n lemma₁₂ : Conat.[ ∞ ] ⌜ 1 ⌝ + ⌜ 1 ⌝ ∼ ⌜ 2 ⌝\n lemma₁₂ = Conat.symmetric-∼ (Conat.⌜⌝-+ 1)\n\n------------------------------------------------------------------------\n-- Well-formed continuations and stacks\n\n-- A continuation is OK with respect to a certain state and conatural\n-- number if the following property is satisfied.\n\nCont-OK :\n Size → State → (T.Value → Delay-crash C.Value ∞) → Conat ∞ → Type\nCont-OK i ⟨ c , s , ρ ⟩ k δ =\n ∀ v → [ i ∣ ⌜ 1 ⌝ ∣ δ ] exec ⟨ c , val (comp-val v) ∷ s , ρ ⟩ ≳ k v\n\n-- If the In-tail-context parameter indicates that we are in a tail\n-- context, then the stack must have a certain shape, and it must be\n-- related to the continuation and the conatural number in a certain\n-- way.\n\ndata Stack-OK\n (i : Size) (k : T.Value → Delay-crash C.Value ∞) (δ : Conat ∞) :\n In-tail-context → Stack → Type where\n unrestricted : ∀ {s} → Stack-OK i k δ false s\n restricted : ∀ {s n} {c : Code n} {ρ : C.Env n} →\n Cont-OK i ⟨ c , s , ρ ⟩ k δ →\n Stack-OK i k δ true (ret c ρ ∷ s)\n\n-- A lemma that can be used to show that certain stacks are OK.\n\nret-ok :\n ∀ {p i s n c} {ρ : C.Env n} {k δ} →\n Cont-OK i ⟨ c , s , ρ ⟩ k δ →\n Stack-OK i k (⌜ 1 ⌝ + δ) p (ret c ρ ∷ s)\nret-ok {true} c-ok = restricted (weakenˡ lemma₁ ∘ c-ok)\nret-ok {false} _ = unrestricted\n\n------------------------------------------------------------------------\n-- The semantics of the compiled program matches that of the source\n-- code\n\nmutual\n\n -- Some lemmas making up the main part of the compiler correctness\n -- result.\n\n ⟦⟧-correct :\n ∀ {i n} (t : Tm n) (ρ : T.Env n) {c s}\n {k : T.Value → Delay-crash C.Value ∞} {tc δ} →\n Stack-OK i k δ tc s →\n Cont-OK i ⟨ c , s , comp-env ρ ⟩ k δ →\n [ i ∣ ⌜ 1 ⌝ ∣ max ⌜ 1 ⌝ δ ]\n exec ⟨ comp tc t c , s , comp-env ρ ⟩ ≳ ⟦ t ⟧ ρ >>= k\n\n ⟦⟧-correct (var x) ρ {c} {s} {k} _ c-ok =\n exec ⟨ var x ∷ c , s , comp-env ρ ⟩ ≳⟨ later (λ { .force →\n exec ⟨ c , val By.⟨ index (comp-env ρ) x ⟩ ∷ s , comp-env ρ ⟩ ≡⟨ By.⟨by⟩ (comp-index ρ x) ⟩ˢ\n exec ⟨ c , val (comp-val (index ρ x)) ∷ s , comp-env ρ ⟩ ≳⟨ weakenˡ lemma₄ (c-ok (index ρ x)) ⟩ˢ\n k (index ρ x) ∎ }) ⟩ˢ\n ⟦ var x ⟧ ρ >>= k ∎\n\n ⟦⟧-correct (lam t) ρ {c} {s} {k} _ c-ok =\n exec ⟨ clo (comp-body t) ∷ c , s , comp-env ρ ⟩ ≳⟨ later (λ { .force →\n exec ⟨ c , val (comp-val (T.lam t ρ)) ∷ s , comp-env ρ ⟩ ≳⟨ weakenˡ lemma₄ (c-ok (T.lam t ρ)) ⟩ˢ\n k (T.lam t ρ) ∎ }) ⟩ˢ\n ⟦ lam t ⟧ ρ >>= k ∎\n\n ⟦⟧-correct (t₁ · t₂) ρ {c} {s} {k} _ c-ok =\n exec ⟨ comp false t₁ (comp false t₂ (app ∷ c))\n , s\n , comp-env ρ\n ⟩ ≳⟨ weakenˡ lemma₉ (⟦⟧-correct t₁ _ unrestricted λ v₁ →\n\n exec ⟨ comp false t₂ (app ∷ c)\n , val (comp-val v₁) ∷ s\n , comp-env ρ\n ⟩ ≳⟨ (⟦⟧-correct t₂ _ unrestricted λ v₂ →\n\n exec ⟨ app ∷ c\n , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s\n , comp-env ρ\n ⟩ ≳⟨ ∙-correct v₁ v₂ c-ok ⟩ˢ\n\n v₁ ∙ v₂ >>= k ∎) ⟩ˢ\n\n (⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ >>= k) ∎) ⟩ˢ\n\n (⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ >>= k) ∼⟨ symmetric (⟦⟧-· t₁ t₂) ⟩\n\n ⟦ t₁ · t₂ ⟧ ρ >>= k ∎\n\n ⟦⟧-correct (call f t) ρ {c} {s} {k} unrestricted c-ok =\n exec ⟨ comp false (call f t) c , s , comp-env ρ ⟩ ∼⟨⟩ˢ\n\n exec ⟨ comp false t (cal f ∷ c) , s , comp-env ρ ⟩ ≳⟨ (⟦⟧-correct t _ unrestricted λ v →\n\n exec ⟨ cal f ∷ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≳⟨ (later λ { .force → weakenˡ lemma₅ (\n\n exec ⟨ comp-name f\n , ret c (comp-env ρ) ∷ s\n , comp-val v ∷ []\n ⟩ ≳⟨ body-lemma (def f) [] c-ok ⟩ˢ\n\n (⟦ def f ⟧ (v ∷ []) >>= k) ∎) }) ⟩ˢ\n\n (T.lam (def f) [] ∙ v >>= k) ∎) ⟩ˢ\n\n (⟦ t ⟧ ρ >>= λ v → T.lam (def f) [] ∙ v >>= k) ∼⟨ associativity (⟦ t ⟧ ρ) _ _ ⟩\n\n (⟦ t ⟧ ρ >>= λ v → T.lam (def f) [] ∙ v) >>= k ∼⟨⟩\n\n ⟦ call f t ⟧ ρ >>= k ∎\n\n ⟦⟧-correct (call f t) ρ {c} {ret c′ ρ′ ∷ s} {k} (restricted c-ok) _ =\n exec ⟨ comp true (call f t) c , ret c′ ρ′ ∷ s , comp-env ρ ⟩ ∼⟨⟩ˢ\n\n exec ⟨ comp false t (tcl f ∷ c) , ret c′ ρ′ ∷ s , comp-env ρ ⟩ ≳⟨ (⟦⟧-correct t _ unrestricted λ v →\n\n exec ⟨ tcl f ∷ c\n , val (comp-val v) ∷ ret c′ ρ′ ∷ s\n , comp-env ρ\n ⟩ ≳⟨ (later λ { .force → weakenˡ lemma₅ (\n\n exec ⟨ comp-name f\n , ret c′ ρ′ ∷ s\n , comp-val v ∷ []\n ⟩ ≳⟨ body-lemma (def f) [] c-ok ⟩ˢ\n\n ⟦ def f ⟧ (v ∷ []) >>= k ∎) }) ⟩ˢ\n\n T.lam (def f) [] ∙ v >>= k ∎) ⟩ˢ\n\n (⟦ t ⟧ ρ >>= λ v → T.lam (def f) [] ∙ v >>= k) ∼⟨ associativity (⟦ t ⟧ ρ) _ _ ⟩\n\n (⟦ t ⟧ ρ >>= λ v → T.lam (def f) [] ∙ v) >>= k ∼⟨⟩\n\n ⟦ call f t ⟧ ρ >>= k ∎\n\n ⟦⟧-correct (con b) ρ {c} {s} {k} _ c-ok =\n exec ⟨ con b ∷ c , s , comp-env ρ ⟩ ≳⟨ later (λ { .force →\n exec ⟨ c , val (comp-val (T.con b)) ∷ s , comp-env ρ ⟩ ≳⟨ weakenˡ lemma₄ (c-ok (T.con b)) ⟩ˢ\n k (T.con b) ∎ }) ⟩ˢ\n ⟦ con b ⟧ ρ >>= k ∎\n\n ⟦⟧-correct (if t₁ t₂ t₃) ρ {c} {s} {k} {tc} s-ok c-ok =\n exec ⟨ comp false t₁ (bra (comp tc t₂ []) (comp tc t₃ []) ∷ c)\n , s\n , comp-env ρ\n ⟩ ≳⟨ weakenˡ lemma₈\n (⟦⟧-correct t₁ _ unrestricted λ v₁ → ⟦if⟧-correct v₁ t₂ t₃ s-ok c-ok) ⟩ˢ\n\n (⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦if⟧ v₁ t₂ t₃ ρ >>= k) ∼⟨ associativity (⟦ t₁ ⟧ ρ) _ _ ⟩\n\n (⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦if⟧ v₁ t₂ t₃ ρ) >>= k ∼⟨⟩\n\n ⟦ if t₁ t₂ t₃ ⟧ ρ >>= k ∎\n\n body-lemma :\n ∀ {i n n′} (t : Tm (suc n)) ρ {ρ′ : C.Env n′} {c s v}\n {k : T.Value → Delay-crash C.Value ∞} {δ} →\n Cont-OK i ⟨ c , s , ρ′ ⟩ k δ →\n [ i ∣ ⌜ 1 ⌝ ∣ ⌜ 1 ⌝ + δ ]\n exec ⟨ comp-body t , ret c ρ′ ∷ s , comp-val v ∷ comp-env ρ ⟩ ≳\n ⟦ t ⟧ (v ∷ ρ) >>= k\n body-lemma t ρ {ρ′} {c} {s} {v} {k} c-ok =\n exec ⟨ comp-body t , ret c ρ′ ∷ s , comp-val v ∷ comp-env ρ ⟩ ∼⟨⟩ˢ\n\n exec ⟨ comp-body t , ret c ρ′ ∷ s , comp-env (v ∷ ρ) ⟩ ≳⟨ weakenˡ lemma₇ (⟦⟧-correct t (_ ∷ _) (ret-ok c-ok) λ v′ →\n\n exec ⟨ ret ∷ []\n , val (comp-val v′) ∷ ret c ρ′ ∷ s\n , comp-env (v ∷ ρ)\n ⟩ ≳⟨⟩ˢ\n\n exec ⟨ c , val (comp-val v′) ∷ s , ρ′ ⟩ ≳⟨ c-ok v′ ⟩ˢ\n\n k v′ ∎) ⟩ˢ\n\n ⟦ t ⟧ (v ∷ ρ) >>= k ∎\n\n ∙-correct :\n ∀ {i n} v₁ v₂ {ρ : C.Env n} {c s}\n {k : T.Value → Delay-crash C.Value ∞} {δ} →\n Cont-OK i ⟨ c , s , ρ ⟩ k δ →\n [ i ∣ ⌜ 1 ⌝ ∣ max ⌜ 1 ⌝ δ ]\n exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s , ρ ⟩ ≳\n v₁ ∙ v₂ >>= k\n\n ∙-correct (T.lam t₁ ρ₁) v₂ {ρ} {c} {s} {k} c-ok =\n exec ⟨ app ∷ c\n , val (comp-val v₂) ∷ val (comp-val (T.lam t₁ ρ₁)) ∷ s\n , ρ\n ⟩ ≳⟨ later (λ { .force → weakenˡ lemma₆ (\n\n exec ⟨ comp-body t₁ , ret c ρ ∷ s , comp-val v₂ ∷ comp-env ρ₁ ⟩ ≳⟨ body-lemma t₁ _ c-ok ⟩ˢ\n\n ⟦ t₁ ⟧ (v₂ ∷ ρ₁) >>= k ∎) }) ⟩ˢ\n\n T.lam t₁ ρ₁ ∙ v₂ >>= k ∎\n\n ∙-correct (T.con b) v₂ {ρ} {c} {s} {k} _ = weakenˡ lemma₁₀ (\n exec ⟨ app ∷ c\n , val (comp-val v₂) ∷ val (comp-val (T.con b)) ∷ s\n , ρ\n ⟩ ≳⟨⟩ˢ\n\n crash ∼⟨⟩ˢ\n\n T.con b ∙ v₂ >>= k ∎ˢ)\n\n ⟦if⟧-correct :\n ∀ {i n} v₁ (t₂ t₃ : Tm n) {ρ : T.Env n} {c s}\n {k : T.Value → Delay-crash C.Value ∞} {tc δ} →\n Stack-OK i k δ tc s →\n Cont-OK i ⟨ c , s , comp-env ρ ⟩ k δ →\n [ i ∣ ⌜ 1 ⌝ ∣ max ⌜ 1 ⌝ δ ]\n exec ⟨ bra (comp tc t₂ []) (comp tc t₃ []) ∷ c\n , val (comp-val v₁) ∷ s\n , comp-env ρ\n ⟩ ≳\n ⟦if⟧ v₁ t₂ t₃ ρ >>= k\n\n ⟦if⟧-correct (T.lam t₁ ρ₁) t₂ t₃ {ρ} {c} {s} {k} {tc} _ _ =\n weakenˡ lemma₁₀ (\n\n exec ⟨ bra (comp tc t₂ []) (comp tc t₃ []) ∷ c\n , val (comp-val (T.lam t₁ ρ₁)) ∷ s\n , comp-env ρ\n ⟩ ≳⟨⟩ˢ\n\n crash ∼⟨⟩ˢ\n\n ⟦if⟧ (T.lam t₁ ρ₁) t₂ t₃ ρ >>= k ∎ˢ)\n\n ⟦if⟧-correct (T.con true) t₂ t₃ {ρ} {c} {s} {k} {tc} s-ok c-ok =\n exec ⟨ bra (comp tc t₂ []) (comp tc t₃ []) ∷ c\n , val (comp-val (T.con true)) ∷ s\n , comp-env ρ\n ⟩ ≳⟨ later (λ { .force → weakenˡ lemma₃ (\n\n exec ⟨ comp tc t₂ [] ++ c , s , comp-env ρ ⟩ ≡⟨ By.by (comp-++ _ t₂) ⟩ˢ\n\n exec ⟨ comp tc t₂ c , s , comp-env ρ ⟩ ≳⟨ ⟦⟧-correct t₂ _ s-ok c-ok ⟩ˢ\n\n ⟦ t₂ ⟧ ρ >>= k ∎) }) ⟩ˢ\n\n ⟦if⟧ (T.con true) t₂ t₃ ρ >>= k ∎\n\n ⟦if⟧-correct (T.con false) t₂ t₃ {ρ} {c} {s} {k} {tc} s-ok c-ok =\n exec ⟨ bra (comp tc t₂ []) (comp tc t₃ []) ∷ c\n , val (comp-val (T.con false)) ∷ s\n , comp-env ρ\n ⟩ ≳⟨ later (λ { .force → weakenˡ lemma₃ (\n\n exec ⟨ comp tc t₃ [] ++ c , s , comp-env ρ ⟩ ≡⟨ By.by (comp-++ _ t₃) ⟩ˢ\n\n exec ⟨ comp tc t₃ c , s , comp-env ρ ⟩ ≳⟨ ⟦⟧-correct t₃ _ s-ok c-ok ⟩ˢ\n\n ⟦ t₃ ⟧ ρ >>= k ∎) }) ⟩ˢ\n\n ⟦if⟧ (T.con false) t₂ t₃ ρ >>= k ∎\n\n-- The \"time complexity\" of the compiled program is linear in the time\n-- complexity obtained from the instrumented interpreter, and vice\n-- versa.\n\nsteps-match :\n (t : Tm 0) →\n [ ∞ ] steps (⟦ t ⟧ []) ≤ steps (exec ⟨ comp₀ t , [] , [] ⟩)\n ×\n [ ∞ ] steps (exec ⟨ comp₀ t , [] , [] ⟩) ≤\n ⌜ 1 ⌝ + ⌜ 2 ⌝ * steps (⟦ t ⟧ [])\nsteps-match t = $⟨ ⟦⟧-correct t [] unrestricted (λ v → laterˡ (return (comp-val v) ∎ˢ)) ⟩\n [ ∞ ∣ ⌜ 1 ⌝ ∣ max ⌜ 1 ⌝ ⌜ 1 ⌝ ]\n exec ⟨ comp₀ t , [] , [] ⟩ ≳ comp-val ⟨$⟩ ⟦ t ⟧ [] ↝⟨ proj₂ ∘ _⇔_.to ≳⇔≈×steps≤steps² ⟩\n\n [ ∞ ] steps (comp-val ⟨$⟩ ⟦ t ⟧ []) ≤\n steps (exec ⟨ comp₀ t , [] , [] ⟩) ×\n [ ∞ ] steps (exec ⟨ comp₀ t , [] , [] ⟩) ≤\n max ⌜ 1 ⌝ ⌜ 1 ⌝ +\n (⌜ 1 ⌝ + ⌜ 1 ⌝) * steps (comp-val ⟨$⟩ ⟦ t ⟧ []) ↝⟨ _⇔_.to (steps-⟨$⟩ Conat.≤-cong-∼ (_ Conat.∎∼)\n ×-cong\n (_ Conat.∎∼)\n Conat.≤-cong-∼\n lemma₁₁ Conat.+-cong lemma₁₂ Conat.*-cong steps-⟨$⟩) ⟩□\n [ ∞ ] steps (⟦ t ⟧ []) ≤ steps (exec ⟨ comp₀ t , [] , [] ⟩) ×\n [ ∞ ] steps (exec ⟨ comp₀ t , [] , [] ⟩) ≤\n ⌜ 1 ⌝ + ⌜ 2 ⌝ * steps (⟦ t ⟧ []) □\n", "meta": {"hexsha": "cb9287e951298f7a1571cb90cad92433c2fd7f47", "size": 15572, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Lambda/Compiler-correctness/Steps-match.agda", "max_stars_repo_name": "nad/definitional-interpreters", "max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96", "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/Lambda/Compiler-correctness/Steps-match.agda", "max_issues_repo_name": "nad/definitional-interpreters", "max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96", "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/Compiler-correctness/Steps-match.agda", "max_forks_repo_name": "nad/definitional-interpreters", "max_forks_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96", "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.449382716, "max_line_length": 145, "alphanum_fraction": 0.3702799897, "num_tokens": 6144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6654105454764746, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.38680520663279305}} {"text": "module _ where\n\nimport Agda.Builtin.Equality\nopen import Agda.Builtin.Sigma\nopen import Agda.Builtin.Unit\nopen import Agda.Primitive\nopen import Common.IO\n\ndata ⊥ : Set where\n\nrecord R₁ a : Set (lsuc a) where\n field\n R : {A : Set a} → A → A → Set a\n r : {A : Set a} (x : A) → R x x\n\n P : Set a → Set a\n P A = (x y : A) → R x y\n\nrecord R₂ (r : ∀ ℓ → R₁ ℓ) : Set₁ where\n field\n f :\n {X Y : Σ Set (R₁.P (r lzero))} →\n R₁.R (r (lsuc lzero)) X Y → fst X → fst Y\n\nmodule M (r₁ : ∀ ℓ → R₁ ℓ) (r₂ : R₂ r₁) where\n\n open module R₁′ {ℓ} = R₁ (r₁ ℓ) public using (P)\n open module R₂′ = R₂ r₂ public\n\n ⊥-elim : {A : Set} → ⊥ → A\n ⊥-elim ()\n\n p : P ⊥\n p x = ⊥-elim x\n\nopen Agda.Builtin.Equality\n\nr₁ : ∀ ℓ → R₁ ℓ\nR₁.R (r₁ _) = _≡_\nR₁.r (r₁ _) = λ _ → refl\n\nr₂ : R₂ r₁\nR₂.f r₂ refl x = x\n\nopen M r₁ r₂\n\ndata Unit : Set where\n unit : Unit\n\ng : Σ Unit λ _ → P (Σ Set P) → ⊥\ng = unit , λ h → f (h (⊤ , λ _ _ → refl) (⊥ , p)) tt\n\nmain : IO ⊤\nmain = return _\n", "meta": {"hexsha": "a0cd97c142725e09ae2d31bbcae32e057a06271c", "size": 976, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Compiler/simple/Issue4169-2.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Compiler/simple/Issue4169-2.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Compiler/simple/Issue4169-2.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 17.7454545455, "max_line_length": 52, "alphanum_fraction": 0.5338114754, "num_tokens": 436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419958239132, "lm_q2_score": 0.5583269943353744, "lm_q1q2_score": 0.3867207236788204}} {"text": "{-# OPTIONS --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Substitution.Introductions.Transp {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped as U hiding (wk)\nopen import Definition.Untyped.Properties\nopen import Definition.Typed\nopen import Definition.Typed.Properties\nopen import Definition.Typed.Weakening as T hiding (wk; wkTerm; wkEqTerm)\nopen import Definition.Typed.RedSteps\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.ShapeView\nopen import Definition.LogicalRelation.Irrelevance as I\nopen import Definition.LogicalRelation.Weakening\nopen import Definition.LogicalRelation.Properties\nopen import Definition.LogicalRelation.Application\nopen import Definition.LogicalRelation.Substitution\nopen import Definition.LogicalRelation.Substitution.Properties\nopen import Definition.LogicalRelation.Substitution.Irrelevance as S\nopen import Definition.LogicalRelation.Substitution.Reflexivity\nopen import Definition.LogicalRelation.Substitution.Introductions.Sigma\nopen import Definition.LogicalRelation.Substitution.Introductions.Fst\nopen import Definition.LogicalRelation.Substitution.Introductions.Pi\nopen import Definition.LogicalRelation.Substitution.Introductions.Lambda\nopen import Definition.LogicalRelation.Substitution.Introductions.Application\nopen import Definition.LogicalRelation.Substitution.Introductions.Cast\nopen import Definition.LogicalRelation.Substitution.Introductions.Id\nopen import Definition.LogicalRelation.Substitution.Introductions.SingleSubst\nopen import Definition.LogicalRelation.Substitution.MaybeEmbed\nopen import Definition.LogicalRelation.Substitution.Escape\nopen import Definition.LogicalRelation.Substitution.Introductions.Universe\nopen import Definition.LogicalRelation.Substitution.Reduction\nopen import Definition.LogicalRelation.Substitution.Weakening\nopen import Definition.LogicalRelation.Substitution.ProofIrrelevance\n\nopen import Tools.Product\nimport Tools.PropositionalEquality as PE\n\nIdSymᵗᵛ : ∀ {A l t u e Γ}\n ([Γ] : ⊩ᵛ Γ)\n ([U] : Γ ⊩ᵛ⟨ ∞ ⟩ U l ^ [ ! , next l ] / [Γ])\n ([AU] : Γ ⊩ᵛ⟨ ∞ ⟩ A ∷ U l ^ [ ! , next l ] / [Γ] / [U])\n ([A] : Γ ⊩ᵛ⟨ ∞ ⟩ A ^ [ ! , ι l ] / [Γ])\n ([t] : Γ ⊩ᵛ⟨ ∞ ⟩ t ∷ A ^ [ ! , ι l ] / [Γ] / [A])\n ([u] : Γ ⊩ᵛ⟨ ∞ ⟩ u ∷ A ^ [ ! , ι l ] / [Γ] / [A])\n ([Id] : Γ ⊩ᵛ⟨ ∞ ⟩ Id A t u ^ [ % , ι l ] / [Γ]) →\n ([Idinv] : Γ ⊩ᵛ⟨ ∞ ⟩ Id A u t ^ [ % , ι l ] / [Γ]) →\n ([e] : Γ ⊩ᵛ⟨ ∞ ⟩ e ∷ Id A t u ^ [ % , ι l ] / [Γ] / [Id] ) →\n Γ ⊩ᵛ⟨ ∞ ⟩ Idsym A t u e ∷ Id A u t ^ [ % , ι l ] / [Γ] / [Idinv]\nIdSymᵗᵛ {A} {l} {t} {u} {e} {Γ} [Γ] [U] [AU] [A] [t] [u] [Id] [Idinv] [e] = validityIrr {A = Id A u t} {t = Idsym A t u e} [Γ] [Idinv] λ {Δ} {σ} ⊢Δ [σ] →\n PE.subst (λ X → Δ ⊢ X ∷ subst σ (Id A u t) ^ [ % , ι l ] ) (PE.sym (subst-Idsym σ A t u e))\n (Idsymⱼ {A = subst σ A} {x = subst σ t} {y = subst σ u} (escapeTerm (proj₁ ([U] {Δ} {σ} ⊢Δ [σ])) (proj₁ ([AU] ⊢Δ [σ])))\n (escapeTerm (proj₁ ([A] {Δ} {σ} ⊢Δ [σ])) (proj₁ ([t] ⊢Δ [σ]))) \n (escapeTerm (proj₁ ([A] {Δ} {σ} ⊢Δ [σ])) (proj₁ ([u] ⊢Δ [σ])))\n (escapeTerm (proj₁ ([Id] {Δ} {σ} ⊢Δ [σ])) (proj₁ ([e] ⊢Δ [σ]))))\n\nabstract \n transpᵗᵛ : ∀ {A P l t s u e Γ}\n ([Γ] : ⊩ᵛ Γ)\n ([A] : Γ ⊩ᵛ⟨ ∞ ⟩ A ^ [ ! , l ] / [Γ])\n ([P] : Γ ∙ A ^ [ ! , l ] ⊩ᵛ⟨ ∞ ⟩ P ^ [ % , l ] / (_∙_ {A = A} [Γ] [A]))\n ([t] : Γ ⊩ᵛ⟨ ∞ ⟩ t ∷ A ^ [ ! , l ] / [Γ] / [A])\n ([s] : Γ ⊩ᵛ⟨ ∞ ⟩ s ∷ P [ t ] ^ [ % , l ] / [Γ] / substS {A} {P} {t} [Γ] [A] [P] [t])\n ([u] : Γ ⊩ᵛ⟨ ∞ ⟩ u ∷ A ^ [ ! , l ] / [Γ] / [A])\n ([Id] : Γ ⊩ᵛ⟨ ∞ ⟩ Id A t u ^ [ % , l ] / [Γ]) →\n ([e] : Γ ⊩ᵛ⟨ ∞ ⟩ e ∷ Id A t u ^ [ % , l ] / [Γ] / [Id] ) →\n Γ ⊩ᵛ⟨ ∞ ⟩ transp A P t s u e ∷ P [ u ] ^ [ % , l ] / [Γ] / substS {A} {P} {u} [Γ] [A] [P] [u]\n transpᵗᵛ {A} {P} {l} {t} {s} {u} {e} {Γ} [Γ] [A] [P] [t] [s] [u] [Id] [e] =\n validityIrr {A = P [ u ]} {t = transp A P t s u e } [Γ] (substS {A} {P} {u} [Γ] [A] [P] [u]) λ {Δ} {σ} ⊢Δ [σ] →\n let [liftσ] = liftSubstS {F = A} [Γ] ⊢Δ [A] [σ]\n [A]σ = proj₁ ([A] {Δ} {σ} ⊢Δ [σ])\n [P[t]]σ = I.irrelevance′ (singleSubstLift P t) (proj₁ (substS {A} {P} {t} [Γ] [A] [P] [t] {Δ} {σ} ⊢Δ [σ]))\n X = transpⱼ (escape [A]σ) (escape (proj₁ ([P] {Δ ∙ subst σ A ^ [ ! , l ]} {liftSubst σ} (⊢Δ ∙ (escape [A]σ)) [liftσ])))\n (escapeTerm [A]σ (proj₁ ([t] ⊢Δ [σ]))) (escapeTerm [P[t]]σ (I.irrelevanceTerm′ (singleSubstLift P t) PE.refl PE.refl (proj₁ (substS {A} {P} {t} [Γ] [A] [P] [t] {Δ} {σ} ⊢Δ [σ])) [P[t]]σ (proj₁ ([s] ⊢Δ [σ])))) \n (escapeTerm [A]σ (proj₁ ([u] ⊢Δ [σ]))) (escapeTerm (proj₁ ([Id] {Δ} {σ} ⊢Δ [σ])) (proj₁ ([e] ⊢Δ [σ])))\n in PE.subst (λ X → Δ ⊢ transp (subst σ A) ( subst (liftSubst σ) P) (subst σ t) (subst σ s) (subst σ u) (subst σ e) ∷ X ^ [ % , l ] ) (PE.sym (singleSubstLift P u)) X\n", "meta": {"hexsha": "7e209ba0ca1597da34023e7a9e18d3e819225535", "size": 4960, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Transp.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/LogicalRelation/Substitution/Introductions/Transp.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/LogicalRelation/Substitution/Introductions/Transp.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": 62.0, "max_line_length": 236, "alphanum_fraction": 0.5627016129, "num_tokens": 2029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.38672071659411034}} {"text": "------------------------------------------------------------------------\n-- Least upper bounds\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nmodule Delay-monad.Least-upper-bound where\n\nopen import Equality.Propositional\nopen import Prelude hiding (_⊔_)\nopen import Prelude.Size\n\nopen import Nat equality-with-J\n\nopen import Delay-monad\nopen import Delay-monad.Partial-order\n\nmodule _ {a} {A : Type a} where\n\n -- Least upper bounds (if they exist).\n\n infix 10 _⊔_\n\n _⊔_ : ∀ {i} → Delay A i → Delay A i → Delay A i\n now x ⊔ _ = now x\n later x ⊔ now y = now y\n later x ⊔ later y = later λ { .force → force x ⊔ force y }\n\n -- The computation x ⊔ y is smaller than or equal to every upper\n -- bound of x and y.\n\n ⊔-least-upper-bound : ∀ {i x y z} →\n [ i ] x ⊑ z → [ i ] y ⊑ z → [ i ] x ⊔ y ⊑ z\n ⊔-least-upper-bound now _ = now\n ⊔-least-upper-bound (laterʳ p) q = laterʳ (⊔-least-upper-bound p (laterʳ⁻¹ q))\n ⊔-least-upper-bound {y = now y} (laterˡ _) q = q\n ⊔-least-upper-bound {y = later y} (laterˡ p) q = laterˡ λ { .force →\n ⊔-least-upper-bound (force p) (laterˡ⁻¹ q) }\n\n -- If x and y have a lower bound, then this is also a lower bound of\n -- x ⊔ y.\n\n ⊔-lower-bound : ∀ {i x y z} → [ i ] z ⊑ x → [ i ] z ⊑ y → [ i ] z ⊑ x ⊔ y\n ⊔-lower-bound now _ = now\n ⊔-lower-bound (laterˡ p) q = laterˡ λ { .force →\n ⊔-lower-bound (force p) (laterˡ⁻¹ q) }\n ⊔-lower-bound {y = now y} (laterʳ _) q = q\n ⊔-lower-bound {y = later y} (laterʳ p) q = laterʳ (⊔-lower-bound p (laterʳ⁻¹ q))\n\n -- If x and y have an upper bound, then x ⊔ y is an upper bound\n -- of y.\n\n ⊔-upper-boundʳ : ∀ {i x y z} →\n [ i ] x ⊑ z → [ i ] y ⊑ z → [ i ] y ⊑ x ⊔ y\n ⊔-upper-boundʳ now q = q\n ⊔-upper-boundʳ (laterʳ p) q = ⊔-upper-boundʳ p (laterʳ⁻¹ q)\n ⊔-upper-boundʳ {y = now y} (laterˡ _) _ = now\n ⊔-upper-boundʳ {y = later y} (laterˡ p) q =\n later-cong λ { .force → ⊔-upper-boundʳ (force p) (laterˡ⁻¹ q) }\n\n -- If x and y have an upper bound, then x ⊔ y is an upper bound\n -- of x.\n\n ⊔-upper-boundˡ : ∀ {i x y z} →\n [ i ] x ⊑ z → [ i ] y ⊑ z → [ i ] x ⊑ x ⊔ y\n ⊔-upper-boundˡ now q = now\n ⊔-upper-boundˡ (laterʳ p) q = ⊔-upper-boundˡ p (laterʳ⁻¹ q)\n ⊔-upper-boundˡ {y = later y} (laterˡ p) q = later-cong λ { .force →\n ⊔-upper-boundˡ (force p) (laterˡ⁻¹ q) }\n ⊔-upper-boundˡ {y = now y} (laterˡ p) q = laterˡ λ { .force →\n ⊔-upper-boundʳ q (force p) }\n\n -- A variant of the lower/upper bound lemmas.\n\n ⊔-lower-upper-bound : ∀ {i x y z} →\n x ⊑ y → [ i ] y ⊑ z → [ i ] y ⊑ x ⊔ z\n ⊔-lower-upper-bound now _ = now\n ⊔-lower-upper-bound (laterʳ p) q = laterˡ λ { .force →\n ⊔-lower-upper-bound p (laterˡ⁻¹ q) }\n ⊔-lower-upper-bound (laterˡ p) (laterʳ q) = laterʳ (⊔-lower-upper-bound (force p) q)\n ⊔-lower-upper-bound {z = now z} (laterˡ _) q = q\n ⊔-lower-upper-bound {z = later z} (laterˡ p) (laterˡ q) = later-cong λ { .force →\n ⊔-lower-upper-bound\n (laterʳ⁻¹ (force p))\n (laterʳ⁻¹ (force q)) }\n\n -- If x terminates, then x ⊔ y also terminates.\n\n ⊔-⇓ˡ : ∀ {i x y} {z : A} →\n Terminates i x z → ∃ λ z′ → Terminates i (x ⊔ y) z′\n ⊔-⇓ˡ now = _ , now\n ⊔-⇓ˡ {y = now y} (laterʳ p) = _ , now\n ⊔-⇓ˡ {y = later y} (laterʳ p) = Σ-map id laterʳ (⊔-⇓ˡ p)\n\n -- If y terminates, then x ⊔ y also terminates.\n\n ⊔-⇓ʳ : ∀ {i} x {y} {z : A} →\n Terminates i y z → ∃ λ z′ → Terminates i (x ⊔ y) z′\n ⊔-⇓ʳ (now x) _ = _ , now\n ⊔-⇓ʳ (later x) now = _ , now\n ⊔-⇓ʳ (later x) (laterʳ p) = Σ-map id laterʳ (⊔-⇓ʳ (force x) p)\n\n-- Increasing sequences.\n\nIncreasing-sequence : ∀ {a} → Type a → Type a\nIncreasing-sequence A =\n ∃ λ (f : ℕ → Delay A ∞) → ∀ n → f n ⊑ f (suc n)\n\nmodule _ {a} {A : Type a} where\n\n -- The tail of an increasing sequence.\n\n tailˢ : Increasing-sequence A → Increasing-sequence A\n tailˢ = Σ-map (_∘ suc) (_∘ suc)\n\n -- Later sequence elements are larger.\n\n later-larger : (s : Increasing-sequence A) →\n ∀ {m n} → m ≤ n → proj₁ s m ⊑ proj₁ s n\n later-larger s (≤-refl′ refl) = reflexive _\n later-larger s (≤-step′ p refl) =\n transitive (later-larger s p) (proj₂ s _)\n\n -- Least upper bounds of increasing sequences.\n\n ⨆ : ∀ {i} → Increasing-sequence A → Delay A i\n ⨆ s = proj₁ s 0 ⊔ later λ { .force → ⨆ (tailˢ s) }\n\n -- ⨆ s is smaller than or equal to every upper bound of s.\n\n ⨆-least-upper-bound :\n ∀ {i} (s : Increasing-sequence A) ub →\n (∀ n → [ i ] proj₁ s n ⊑ ub) → [ i ] ⨆ s ⊑ ub\n ⨆-least-upper-bound s ub is-ub =\n ⊔-least-upper-bound\n (is-ub 0)\n (laterˡ λ { .force →\n ⨆-least-upper-bound (tailˢ s) ub (is-ub ∘ suc) })\n\n -- If every element in s terminates with a given value, then ⨆ s\n -- terminates with the same value.\n\n ⨆-⇓ : ∀ {i x} (s : Increasing-sequence A) →\n (∀ n → proj₁ s n ⇓ x) → Terminates i (⨆ s) x\n ⨆-⇓ s s-⇓ =\n ⊑now→⇓→⇓ (⨆-least-upper-bound s _ (λ n → symmetric (s-⇓ n)))\n (proj₂ (⊔-⇓ˡ (s-⇓ 0)))\n\n -- If s has a lower bound, then this is also a lower bound of ⨆ s.\n\n ⨆-lower-bound : ∀ {i} (s : Increasing-sequence A) lb →\n (∀ n → lb ⊑ proj₁ s n) → [ i ] lb ⊑ ⨆ s\n ⨆-lower-bound s (now x) is-lb = ⨆-⇓ s is-lb\n ⨆-lower-bound s (later lb) is-lb =\n ⊔-lower-bound\n (is-lb 0)\n (later-cong λ { .force →\n ⨆-lower-bound (tailˢ s) (force lb) λ n →\n laterˡ⁻¹ (transitive (is-lb n) (proj₂ s n)) })\n\n -- ⨆ s is an upper bound of s.\n\n ⨆-upper-bound : ∀ {i} (s : Increasing-sequence A) →\n ∀ n → [ i ] proj₁ s n ⊑ ⨆ s\n ⨆-upper-bound s zero = ⨆-lower-bound s (proj₁ s 0)\n (λ n → later-larger s (zero≤ n))\n ⨆-upper-bound s (suc n) = ⊔-lower-upper-bound\n (later-larger s (zero≤ (suc n)))\n (laterʳ (⨆-upper-bound (tailˢ s) n))\n", "meta": {"hexsha": "e9c98f914bf03d636301f545cda71e3777eb32d9", "size": 6580, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Delay-monad/Least-upper-bound.agda", "max_stars_repo_name": "nad/delay-monad", "max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Least-upper-bound.agda", "max_issues_repo_name": "nad/delay-monad", "max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Least-upper-bound.agda", "max_forks_repo_name": "nad/delay-monad", "max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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.7058823529, "max_line_length": 102, "alphanum_fraction": 0.4659574468, "num_tokens": 2413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.5583269943353744, "lm_q1q2_score": 0.3867207165941103}} {"text": "------------------------------------------------------------------------\n-- The two definitions of context extensions are isomorphic\n------------------------------------------------------------------------\n\nopen import Data.Universe.Indexed\n\nmodule deBruijn.Context.Extension.Isomorphic\n {i u e} (Uni : IndexedUniverse i u e) where\n\nimport deBruijn.Context.Basics as Basics\nimport deBruijn.Context.Extension.Left as Left\nimport deBruijn.Context.Extension.Right as Right\nopen import Function.Base\nopen import Function.Inverse using (_↔_)\nimport Relation.Binary.PropositionalEquality as P\n\nopen Basics Uni\nopen Left Uni\nopen Right Uni\nopen P.≡-Reasoning\n\n-- Ctxt₊-s can be turned into Ctxt⁺-s.\n\n₊-to-⁺ : ∀ {Γ} → Ctxt₊ Γ → Ctxt⁺ Γ\n₊-to-⁺ ε = ε\n₊-to-⁺ (σ ◅ Γ₊) = ε ▻ σ ⁺++⁺ ₊-to-⁺ Γ₊\n\nabstract\n\n -- The semantics is preserved.\n\n ++⁺-₊-to-⁺ : ∀ {Γ} (Γ₊ : Ctxt₊ Γ) → Γ ++₊ Γ₊ ≅-Ctxt Γ ++⁺ ₊-to-⁺ Γ₊\n ++⁺-₊-to-⁺ ε = P.refl\n ++⁺-₊-to-⁺ {Γ} (σ ◅ Γ₊) = begin\n Γ ▻ σ ++₊ Γ₊ ≡⟨ ++⁺-₊-to-⁺ Γ₊ ⟩\n Γ ▻ σ ++⁺ ₊-to-⁺ Γ₊ ≡⟨ ++⁺-++⁺ (ε ▻ σ) (₊-to-⁺ Γ₊) ⟩\n Γ ++⁺ (ε ▻ σ ⁺++⁺ ₊-to-⁺ Γ₊) ∎\n\nmutual\n\n -- Ctxt⁺-s can be turned into Ctxt₊-s.\n\n ⁺-to-₊ : ∀ {Γ} → Ctxt⁺ Γ → Ctxt₊ Γ\n ⁺-to-₊ ε = ε\n ⁺-to-₊ (Γ⁺ ▻ σ) =\n ⁺-to-₊ Γ⁺ ₊++₊ P.subst Ctxt₊ (++₊-⁺-to-₊ Γ⁺) (σ ◅ ε)\n\n abstract\n\n -- The semantics is preserved.\n\n ++₊-⁺-to-₊ : ∀ {Γ} (Γ⁺ : Ctxt⁺ Γ) → Γ ++⁺ Γ⁺ ≅-Ctxt Γ ++₊ ⁺-to-₊ Γ⁺\n ++₊-⁺-to-₊ ε = P.refl\n ++₊-⁺-to-₊ {Γ} (Γ⁺ ▻ σ) =\n let σ◅ε = P.subst Ctxt₊ (++₊-⁺-to-₊ Γ⁺) (σ ◅ ε)\n\n in begin\n Γ ++⁺ Γ⁺ ▻ σ ≡⟨ P.refl ⟩\n Γ ++⁺ Γ⁺ ++₊ (σ ◅ ε) ≡⟨ P.sym $ ++₊-cong $ drop-subst-Ctxt₊ id (++₊-⁺-to-₊ Γ⁺) ⟩\n Γ ++₊ ⁺-to-₊ Γ⁺ ++₊ σ◅ε ≡⟨ ++₊-++₊ (⁺-to-₊ Γ⁺) σ◅ε ⟩\n Γ ++₊ (⁺-to-₊ Γ⁺ ₊++₊ σ◅ε) ∎\n\n-- Some congruence lemmas.\n\n₊-to-⁺-cong : ∀ {Γ₁} {Γ₊₁ : Ctxt₊ Γ₁}\n {Γ₂} {Γ₊₂ : Ctxt₊ Γ₂} →\n Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ₊-to-⁺ Γ₊₁ ≅-Ctxt⁺ ₊-to-⁺ Γ₊₂\n₊-to-⁺-cong P.refl = P.refl\n\n⁺-to-₊-cong : ∀ {Γ₁} {Γ⁺₁ : Ctxt⁺ Γ₁}\n {Γ₂} {Γ⁺₂ : Ctxt⁺ Γ₂} →\n Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → ⁺-to-₊ Γ⁺₁ ≅-Ctxt₊ ⁺-to-₊ Γ⁺₂\n⁺-to-₊-cong P.refl = P.refl\n\n-- Ctxt⁺ and Ctxt₊ are isomorphic.\n\nCtxt⁺↔Ctxt₊ : ∀ Γ → Ctxt⁺ Γ ↔ Ctxt₊ Γ\nCtxt⁺↔Ctxt₊ Γ = record\n { to = P.→-to-⟶ ⁺-to-₊\n ; from = P.→-to-⟶ ₊-to-⁺\n ; inverse-of = record\n { left-inverse-of = λ Γ⁺ → ≅-Ctxt⁺-⇒-≡ $ ₊-to-⁺-⁺-to-₊ Γ⁺\n ; right-inverse-of = λ Γ₊ → ≅-Ctxt₊-⇒-≡ $ ⁺-to-₊-₊-to-⁺ Γ₊\n }\n }\n where\n abstract\n ₊-to-⁺-⁺-to-₊ : (Γ⁺ : Ctxt⁺ Γ) → ₊-to-⁺ (⁺-to-₊ Γ⁺) ≅-Ctxt⁺ Γ⁺\n ₊-to-⁺-⁺-to-₊ Γ⁺ = cancel-++⁺-left _ _ (begin\n Γ ++⁺ ₊-to-⁺ (⁺-to-₊ Γ⁺) ≡⟨ P.sym $ ++⁺-₊-to-⁺ (⁺-to-₊ Γ⁺) ⟩\n Γ ++₊ (⁺-to-₊ Γ⁺) ≡⟨ P.sym $ ++₊-⁺-to-₊ Γ⁺ ⟩\n Γ ++⁺ Γ⁺ ∎)\n\n ⁺-to-₊-₊-to-⁺ : (Γ₊ : Ctxt₊ Γ) → ⁺-to-₊ (₊-to-⁺ Γ₊) ≅-Ctxt₊ Γ₊\n ⁺-to-₊-₊-to-⁺ Γ₊ = cancel-++₊-left _ _ (begin\n Γ ++₊ ⁺-to-₊ (₊-to-⁺ Γ₊) ≡⟨ P.sym $ ++₊-⁺-to-₊ (₊-to-⁺ Γ₊) ⟩\n Γ ++⁺ (₊-to-⁺ Γ₊) ≡⟨ P.sym $ ++⁺-₊-to-⁺ Γ₊ ⟩\n Γ ++₊ Γ₊ ∎)\n", "meta": {"hexsha": "1a27eab9a6f7f53e2b7239e7f08d8cf14da28b0d", "size": 3093, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "deBruijn/Context/Extension/Isomorphic.agda", "max_stars_repo_name": "nad/dependently-typed-syntax", "max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z", "max_issues_repo_path": "deBruijn/Context/Extension/Isomorphic.agda", "max_issues_repo_name": "nad/dependently-typed-syntax", "max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "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": "deBruijn/Context/Extension/Isomorphic.agda", "max_forks_repo_name": "nad/dependently-typed-syntax", "max_forks_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "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": 31.2424242424, "max_line_length": 93, "alphanum_fraction": 0.388942774, "num_tokens": 1764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321842389469, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3866447019170793}} {"text": "------------------------------------------------------------------------\n-- Code related to the paper \"Bag Equivalence via a Proof-Relevant\n-- Membership Relation\"\n--\n-- Nils Anders Danielsson\n------------------------------------------------------------------------\n\n-- Note that the code does not follow the paper exactly. For instance,\n-- many definitions are universe-polymorphic, and in some cases where\n-- the paper contains both a specialised and a more general definition\n-- the code only contains the more general one. The code has also been\n-- changed after the paper was published.\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule README.Bag-equivalence where\n\n------------------------------------------------------------------------\n-- 2: Brief Introduction to Agda\n\n-- The prelude, containing List, ℕ, Fin, ⊥, ⊤, _⊎_ (written as _+_ in\n-- the paper), ∃, and _×_.\n\nimport Prelude\n\n-- Some list functions: length and index (called lookup in the paper).\n\nimport List\n\n-- Logical equivalences: _⇔_.\n\nimport Logical-equivalence\n\n-- Bijections: _↔_.\n\nimport Bijection\n\n-- Equality: _≡_.\n\nimport Equality.Propositional\n\n-- The K rule, and a proof showing that it implies proof-irrelevance.\n\nimport Equality\n\n-- Bijectional reasoning combinators (more general than those in the\n-- paper): inverse (written as sym in the paper), _□, and _↔⟨_⟩_.\n\nimport Function-universe\n\n------------------------------------------------------------------------\n-- 3: Bag Equivalence for Lists\n\n-- Any, _∈_, and the two definitions of bag equivalence.\n\nimport Bag-equivalence\n\n------------------------------------------------------------------------\n-- 4: Bijectional Reasoning\n\n-- Definitions of map, concat and _>>=_ (the latter as part of a monad\n-- instance).\n\nimport List\n\n-- Algebraic properties of type constructors (like ⊥ ⊎ A ↔ A).\n\nimport Function-universe\nimport Fin\n\n-- All the main lemmas from this section, including\n-- >>=-left-distributive.\n\nimport Bag-equivalence\n\n------------------------------------------------------------------------\n-- 5: The Definitions Are Equivalent\n\n-- The equivalence proof.\n\nimport Bag-equivalence\n\n-- There are infinitely many proofs of ℕ ≡ ℕ in homotopy type theory.\n\nimport Univalence-axiom\n\n------------------------------------------------------------------------\n-- 6: Bag Equivalence for Arbitrary Containers\n\n-- Containers, including Any, _∈_, the two definitions of bag\n-- equivalence, and a proof showing that the two definitions are\n-- logically equivalent.\n--\n-- There is also a proof which shows that the definitions are\n-- isomorphic (assuming extensionality), if \"bijection\" is replaced by\n-- the logically equivalent concept of \"(weak) equivalence\" in the\n-- definitions of bag equivalence.\n\nimport Container\nimport Equivalence\n\n-- The List, Stream and Tree containers. It is shown that the general\n-- definition of bag equivalence for containers, instantiated with the\n-- List container, is equivalent (in a certain sense) to the list-only\n-- definition given above.\n\nimport Container.List\nimport Container.Stream\nimport Container.Tree\n\n------------------------------------------------------------------------\n-- 7: More Bijectional Reasoning\n\n-- Three implementations of tree sort are provided.\n\n-- 1) An implementation of tree sort, formally proved to return a\n-- permutation of the input.\n\nimport Tree-sort.Partial\nimport Tree-sort.Examples\n\n-- 2) An implementation of tree sort, formally proved to return a\n-- /sorted/ permutation of the input.\n\nimport Tree-sort.Full\nimport Tree-sort.Examples\n\n-- 3) An implementation of tree sort which uses containers to\n-- represent trees and lists.\n--\n-- In the module Tree-sort.Full indexed types are used to enforce\n-- sortedness, but this development uses non-indexed containers, so\n-- sortedness is not enforced.\n--\n-- The implementation using containers has the advantage of uniform\n-- definitions of Any/membership/bag equivalence, but the other\n-- implementations use more direct definitions and are perhaps a\n-- bit \"leaner\".\n\nimport Container.Tree\nimport Container.Tree-sort\nimport Container.Tree-sort.Example\n\n------------------------------------------------------------------------\n-- 8: Set Equivalence, Subsets and Subbags\n\n-- Injections: _↣_.\n\nimport Injection\n\n-- The general definition of set and bag equivalence and the subset\n-- and subbag preorders, as well as preservation lemmas such as\n-- >>=-cong.\n\nimport Bag-equivalence\n\n------------------------------------------------------------------------\n-- 9: Related Work\n\n-- One of the definitions of bag equivalence from Coq's standard\n-- library has been replicated, and shown to be sound with respect to\n-- the other ones.\n\nimport Bag-equivalence\n\n------------------------------------------------------------------------\n-- 10: Conclusions\n\n-- Two proofs showing that cons is left cancellative, using different\n-- definitions of bag equivalence.\n\nimport Bag-equivalence\n", "meta": {"hexsha": "77a3836ddb9de81cbce69806a4970ebd2cb4ac98", "size": 4954, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "README/Bag-equivalence.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "README/Bag-equivalence.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": "README/Bag-equivalence.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": 28.6358381503, "max_line_length": 72, "alphanum_fraction": 0.6265643924, "num_tokens": 1011, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321842389469, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3866447019170793}} {"text": "module SN where\n\nopen import Relation.Unary using (_∈_; _⊆_)\nopen import Library\nopen import Terms\nopen import Substitution\nopen import TermShape public\n\n\n-- Inductive definition of strong normalization.\n\ninfix 7 _⟨_⟩⇒_ _⇒ˢ_\n\nmutual\n\n -- Strongly normalizing evaluation contexts\n\n SNhole : ∀ {i : Size} {Γ : Cxt} {a b : Ty} → Tm Γ b → ECxt Γ a b → Tm Γ a → Set\n SNhole {i} = PCxt (SN {i})\n\n -- Strongly neutral terms.\n\n SNe : ∀ {i : Size} {Γ} {b} → Tm Γ b → Set\n SNe {i} = PNe (SN {i})\n\n -- Strongly normalizing terms.\n\n data SN {i : Size}{Γ} : ∀ {a} → Tm Γ a → Set where\n\n ne : ∀ {j : Size< i} {a t}\n → (𝒏 : SNe {j} t)\n → SN {a = a} t\n\n abs : ∀ {j : Size< i} {a b}{t : Tm (a ∷ Γ) b}\n → (𝒕 : SN {j} t)\n → SN (abs t)\n\n exp : ∀ {j₁ j₂ : Size< i} {a t t′}\n → (t⇒ : t ⟨ j₁ ⟩⇒ t′) (𝒕′ : SN {j₂} t′)\n → SN {a = a} t\n\n _⟨_⟩⇒_ : ∀ {Γ a} → Tm Γ a → Size → Tm Γ a → Set\n t ⟨ i ⟩⇒ t′ = SN {i} / t ⇒ t′\n\n -- Strong head reduction\n\n _⇒ˢ_ : ∀ {i : Size} {Γ} {a} → Tm Γ a → Tm Γ a → Set\n _⇒ˢ_ {i} t t' = (SN {i}) / t ⇒ t'\n\n\n-- -- Inductive definition of strong normalization.\n\n-- mutual\n\n-- -- Strongly normalizing evaluation contexts\n\n-- data SNhole {i : Size} (n : ℕ) {Γ : Cxt} : {a b : Ty} → Tm Γ b → ECxt Γ a b → Tm Γ a → Set where\n\n-- appl : ∀ {a b t u}\n-- → (𝒖 : SN {i} n u)\n-- → SNhole n (app t u) (appl u) (t ∶ (a →̂ b))\n\n-- -- Strongly neutral terms.\n\n-- data SNe {i : Size} (n : ℕ) {Γ} {b} : Tm Γ b → Set where\n\n-- var : ∀ x → SNe n (var x)\n\n-- elim : ∀ {a} {t : Tm Γ a} {E Et}\n-- → (𝒏 : SNe {i} n t) (𝑬𝒕 : SNhole {i} n Et E t) → SNe n Et\n-- -- elim : ∀ {j₁ j₂ : Size< i}{a} {t : Tm Γ a} {E Et}\n-- -- → (𝒏 : SNe {j₁} n t) (𝑬𝒕 : SNhole {j₂} n Et E t) → SNe n Et\n\n-- -- Strongly normalizing terms.\n\n-- data SN {i : Size}{Γ} : ℕ → ∀ {a} → Tm Γ a → Set where\n\n-- ne : ∀ {j : Size< i} {a n t}\n-- → (𝒏 : SNe {j} n t)\n-- → SN n {a} t\n\n-- abs : ∀ {j : Size< i} {a b n}{t : Tm (a ∷ Γ) b}\n-- → (𝒕 : SN {j} n t)\n-- → SN n (abs t)\n\n-- exp : ∀ {j₁ j₂ : Size< i} {a n t t′}\n-- → (t⇒ : j₁ size t ⟨ n ⟩⇒ t′) (𝒕′ : SN {j₂} n t′)\n-- → SN n {a} t\n\n-- _size_⟨_⟩⇒_ : ∀ (i : Size) {Γ}{a} → Tm Γ a → ℕ → Tm Γ a → Set\n-- i size t ⟨ n ⟩⇒ t′ = _⟨_⟩⇒_ {i} t n t′\n\n-- -- Strong head reduction\n\n-- data _⟨_⟩⇒_ {i : Size} {Γ} : ∀ {a} → Tm Γ a → ℕ → Tm Γ a → Set where\n\n-- β : ∀ {a b}{t : Tm (a ∷ Γ) b}{u}\n-- → (𝒖 : SN {i} n u)\n-- → (app (abs t) u) ⟨ n ⟩⇒ subst0 u t\n\n-- cong : ∀ {a b t t' Et Et'}{E : ECxt Γ a b}\n-- → (𝑬𝒕 : Ehole Et E t)\n-- → (𝑬𝒕' : Ehole Et' E t')\n-- → (t⇒ : i size t ⟨ n ⟩⇒ t')\n-- → Et ⟨ n ⟩⇒ Et'\n\n -- β : ∀ {j : Size< i} {a b}{t : Tm (a ∷ Γ) b}{u}\n -- → (𝒖 : SN {j} n u)\n -- → (app (abs t) u) ⟨ n ⟩⇒ subst0 u t\n\n -- cong : ∀ {j : Size< i} {a b t t' Et Et'}{E : ECxt Γ a b}\n -- → (𝑬𝒕 : Ehole Et E t)\n -- → (𝑬𝒕' : Ehole Et' E t')\n -- → (t⇒ : j size t ⟨ n ⟩⇒ t')\n -- → Et ⟨ n ⟩⇒ Et'\n\n-- Strong head reduction is deterministic.\n\ndet⇒ : ∀ {a Γ} {t t₁ t₂ : Tm Γ a}\n → (t⇒₁ : t ⟨ _ ⟩⇒ t₁) (t⇒₂ : t ⟨ _ ⟩⇒ t₂) → t₁ ≡ t₂\ndet⇒ (β _) (β _) = ≡.refl\ndet⇒ (β _) (cong (appl u) (appl .u) (cong () _ _))\ndet⇒ (cong (appl u) (appl .u) (cong () _ _)) (β _)\ndet⇒ (cong (appl u) (appl .u) x) (cong (appl .u) (appl .u) y) = ≡.cong (λ t → app t u) (det⇒ x y)\n\n-- Strongly neutrals are closed under application.\n\nsneApp : ∀{Γ a b}{t : Tm Γ (a →̂ b)}{u : Tm Γ a} →\n SNe t → SN u → SNe (app t u)\nsneApp 𝒏 𝒖 = elim 𝒏 (appl 𝒖)\n\n-- Substituting strongly neutral terms\n\nrecord RenSubSNe {i} (vt : VarTm i) (Γ Δ : Cxt) : Set where\n constructor _,_\n field theSubst : RenSub vt Γ Δ\n isSNe : ∀ {a} (x : Var Γ a) → SNe (vt2tm _ (theSubst x))\nopen RenSubSNe\n\nRenSN = RenSubSNe `Var\nSubstSNe = RenSubSNe `Tm\n\n-- The singleton SNe substitution.\n-- Replaces the first variable by another variable.\n\nsgs-varSNe : ∀ {Γ a} → Var Γ a → SubstSNe (a ∷ Γ) Γ\ntheSubst (sgs-varSNe x) = sgs (var x)\nisSNe (sgs-varSNe x) (zero) = (var x)\nisSNe (sgs-varSNe x) (suc y) = var y\n\n\n-- The SN-notions are closed under SNe substitution.\n\nmutual\n substSNh : ∀ {i vt Γ Δ a b} → (σ : RenSubSNe {i} vt Γ Δ) → ∀ {E : ECxt Γ a b}{Et t} → (SNh : SNhole Et E t)\n → SNhole (subst (theSubst σ) Et) (substEC (theSubst σ) E) (subst (theSubst σ) t)\n substSNh σ (appl u) = appl (substSN σ u)\n\n subst⇒ : ∀ {i vt Γ Δ a} (σ : RenSubSNe {i} vt Γ Δ) {t t' : Tm Γ a} → t ⟨ _ ⟩⇒ t' → subst (theSubst σ) t ⟨ _ ⟩⇒ subst (theSubst σ) t'\n subst⇒ (σ , σ∈Ne) (β {t = t} {u = u} x) = ≡.subst (λ t' → app (abs (subst (lifts σ) t)) (subst σ u) ⟨ _ ⟩⇒ t')\n (sgs-lifts-term {σ = σ} {u} {t})\n (β {t = subst (lifts σ) t} (substSN (σ , σ∈Ne) x))\n\n subst⇒ σ (cong Eh Eh' t→t') = cong (substEh (theSubst σ) Eh) (substEh (theSubst σ) Eh') (subst⇒ σ t→t')\n\n -- Lifting a SNe substitution.\n\n liftsSNe : ∀ {i vt Γ Δ a} → RenSubSNe {i} vt Γ Δ → RenSubSNe {i} vt (a ∷ Γ) (a ∷ Δ)\n theSubst (liftsSNe σ) = lifts (theSubst σ)\n isSNe (liftsSNe {vt = `Var} (σ , σ∈SNe)) (zero) = var (zero)\n isSNe (liftsSNe {vt = `Var} (σ , σ∈SNe)) (suc y) = var (suc (σ y))\n isSNe (liftsSNe {vt = `Tm } (σ , σ∈SNe)) (zero) = var (zero)\n isSNe (liftsSNe {vt = `Tm } (σ , σ∈SNe)) (suc y) = substSNe {vt = `Var} (suc , (λ x → var (suc x))) (σ∈SNe y)\n\n substSNe : ∀ {i vt Γ Δ τ} → (σ : RenSubSNe {i} vt Γ Δ) → ∀ {t : Tm Γ τ} → SNe t → SNe (subst (theSubst σ) t)\n substSNe σ (var x) = isSNe σ x\n substSNe σ (elim t∈SNe E∈SNh) = elim (substSNe σ t∈SNe) (substSNh σ E∈SNh)\n\n substSN : ∀ {i vt Γ Δ τ} → (σ : RenSubSNe {i} vt Γ Δ) → ∀ {t : Tm Γ τ} → SN t → SN (subst (theSubst σ) t)\n substSN σ (ne t∈SNe) = ne (substSNe σ t∈SNe)\n substSN σ (abs t∈SN) = abs (substSN (liftsSNe σ) t∈SN)\n substSN σ (exp t→t' t'∈SN) = exp (subst⇒ σ t→t') (substSN σ t'∈SN)\n\n\n-- SN is closed under renaming.\n\nrenSN : ∀{Γ Δ} (ρ : Γ ≤ Δ) → RenSN Δ Γ\nrenSN ρ = (ρ , λ x → var (ρ x))\n\nrenameSNe : ∀{a Γ Δ} (ρ : Γ ≤ Δ) {t : Tm Δ a} →\n SNe t → SNe (rename ρ t)\nrenameSNe ρ = substSNe (renSN ρ)\n\nrenameSN : ∀{a Γ Δ} (ρ : Γ ≤ Δ) {t : Tm Δ a} →\n SN t → SN (rename ρ t)\nrenameSN ρ = substSN (renSN ρ)\n\n-- Variables are SN.\n\nvarSN : ∀{Γ a x} → var x ∈ SN {Γ = Γ} {a}\nvarSN = ne (var _)\n\n-- SN is closed under application to variables.\n\nappVarSN : ∀{Γ a b}{t : Tm Γ (a →̂ b)}{x} → t ∈ SN → app t (var x) ∈ SN\nappVarSN (ne t∈SNe) = ne (elim t∈SNe (appl varSN))\nappVarSN (abs t∈SN) = exp (β varSN) (substSN (sgs-varSNe _) t∈SN)\nappVarSN (exp t→t' t'∈SN) = exp (cong (appl (var _)) (appl (var _)) t→t') (appVarSN t'∈SN)\n\n-- Subterm properties of SN\n\n-- If app t u ∈ SN then u ∈ SN.\n\napprSN : ∀{i a b Γ}{t : Tm Γ (a →̂ b)}{u : Tm Γ a} → SN {i} (app t u) → SN {i} u\napprSN (ne (elim 𝒏 (appl 𝒖))) = 𝒖\napprSN (exp (β 𝒖) 𝒕) = 𝒖\napprSN (exp (cong (appl u) (appl .u) t⇒) 𝒕) = apprSN 𝒕\n", "meta": {"hexsha": "6cc6abff11b1c7cf168da5b3e2b24a7d35cd791c", "size": 7297, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-aplas14/SN.agda", "max_stars_repo_name": "ryanakca/strong-normalization", "max_stars_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2017-05-22T14:33:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-05T12:12:03.000Z", "max_issues_repo_path": "agda-aplas14/SN.agda", "max_issues_repo_name": "ryanakca/strong-normalization", "max_issues_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-02-14T16:42:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-20T14:54:18.000Z", "max_forks_repo_path": "agda-aplas14/SN.agda", "max_forks_repo_name": "ryanakca/strong-normalization", "max_forks_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-11-10T16:44:52.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-23T18:22:17.000Z", "avg_line_length": 33.4724770642, "max_line_length": 134, "alphanum_fraction": 0.4610113745, "num_tokens": 3309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.5964331462646255, "lm_q1q2_score": 0.3863683292777948}} {"text": "module Data.QuadTree.FoldableProofs.FoldableFunctorProof where\n\nopen import Haskell.Prelude renaming (zero to Z; suc to S)\nopen import Data.Logic\nopen import Data.QuadTree.Implementation.Definition\nopen import Data.QuadTree.Implementation.ValidTypes\nopen import Data.QuadTree.Implementation.QuadrantLenses\nopen import Data.QuadTree.Implementation.SafeFunctions\nopen import Data.QuadTree.Implementation.PropDepthRelation\nopen import Data.QuadTree.Implementation.Foldable\nopen import Data.QuadTree.Implementation.Functors\nopen import Data.QuadTree.FoldableProofs.FoldableProof\nopen import Data.QuadTree.FunctorProofs.Valid-QuadrantFunctor\n\nproof-foldfmap-list : {t s : Set} {{monT : Monoid t}} {{monS : Monoid s}} -> (l : List t )\n -> (f : t -> s)\n -> foldMap f l ≡ foldMap id (fmap f l)\nproof-foldfmap-list [] f = refl\nproof-foldfmap-list (x ∷ xs) f =\n begin\n f x <> foldMap f xs\n =⟨ cong (_<>_ (f x)) (proof-foldfmap-list xs f) ⟩\n f x <> foldMap id (fmap f xs)\n end\n\nfmap-replicate : {A B : Set} -> (f : A -> B) -> (v : A) -> (n : Nat)\n -> fmap f (replicateₙ n v) ≡ replicateₙ n (f v)\nfmap-replicate f v Z = refl\nfmap-replicate f v (S n) = cong (λ z → f v ∷ z) (fmap-replicate f v n)\n\nfmap-concat : {A B : Set} -> (f : A -> B) -> (l1 l2 : List A)\n -> fmap f (l1 ++ l2) ≡ fmap f l1 ++ fmap f l2\nfmap-concat f [] l2 = refl\nfmap-concat f (x ∷ l1) l2 = cong (λ z → f x ∷ z) (fmap-concat f l1 l2)\n\nfmap-concat4 : {A B : Set} -> (f : A -> B) -> (l1 l2 l3 l4 : List A)\n -> fmap f (l1 ++ l2 ++ l3 ++ l4) ≡ fmap f l1 ++ fmap f l2 ++ fmap f l3 ++ fmap f l4\nfmap-concat4 f l1 l2 l3 l4 =\n begin\n fmap f (l1 ++ l2 ++ l3 ++ l4)\n =⟨ fmap-concat f l1 (l2 ++ l3 ++ l4) ⟩\n fmap f l1 ++ fmap f (l2 ++ l3 ++ l4)\n =⟨ cong (_++_ (map f l1)) (fmap-concat f l2 (l3 ++ l4)) ⟩\n fmap f l1 ++ fmap f l2 ++ fmap f (l3 ++ l4)\n =⟨ cong (λ z → map f l1 ++ map f l2 ++ z) (fmap-concat f l3 l4) ⟩\n fmap f l1 ++ fmap f l2 ++ fmap f l3 ++ fmap f l4\n end\n\nfmap-expand : {A B : Set} {{eqA : Eq A}} {{eqB : Eq B}} -> (f : A -> B) -> (t : Tile A)\n -> fmap f (expand t) ≡ expand (fmap f t)\nfmap-expand f t@(TileC v (RegionC (x1 , y1) (x2 , y2))) = fmap-replicate f v (diff x2 x1 * diff y2 y1)\n\nfmap-concat-expand : {A B : Set} {{eqA : Eq A}} {{eqB : Eq B}} -> (f : A -> B) -> (l : List (Tile A))\n -> (fmap f $ concat $ map expand l) ≡ (concat $ map expand $ fmap (fmap f) l) \nfmap-concat-expand f [] = refl\nfmap-concat-expand f (x ∷ xs) =\n begin\n fmap f (expand x ++ concat (map expand xs))\n =⟨ fmap-concat f (expand x) _ ⟩\n fmap f (expand x) ++ fmap f (concat (map expand xs))\n =⟨ cong (_++_ (fmap f (expand x))) (fmap-concat-expand f xs) ⟩\n fmap f (expand x) ++ concat (map expand $ fmap (fmap f) xs)\n =⟨ cong (λ q -> q ++ concat (map expand $ fmap (fmap f) xs)) (fmap-expand f x) ⟩\n expand (fmap f x) ++ concat (map expand $ fmap (fmap f) xs)\n end\n\nreplicate-concat : {t : Set} -> (a b : Nat) -> (v : t)\n -> replicateₙ a v ++ replicateₙ b v ≡ replicateₙ (a + b) v\nreplicate-concat Z b v = refl\nreplicate-concat (S a) b v = cong (λ z → v ∷ z) (replicate-concat a b v)\n\nreplicate-concat4 : {t : Set} -> (a b c d : Nat) -> (v : t)\n -> replicateₙ a v ++ replicateₙ b v ++ replicateₙ c v ++ replicateₙ d v ≡ replicateₙ (a + b + c + d) v\nreplicate-concat4 a b c d v =\n begin\n replicateₙ a v ++ replicateₙ b v ++ (replicateₙ c v ++ replicateₙ d v)\n =⟨ cong (λ z → replicateₙ a v ++ replicateₙ b v ++ z) (replicate-concat c d v) ⟩\n replicateₙ a v ++ replicateₙ b v ++ replicateₙ (c + d) v\n =⟨ cong (_++_ (replicateₙ a v)) (replicate-concat b (c + d) v) ⟩\n replicateₙ a v ++ replicateₙ (b + (c + d)) v\n =⟨ replicate-concat a (b + (c + d)) v ⟩\n replicateₙ (a + (b + (c + d))) v\n =⟨ sym (cong (λ z → replicateₙ z v) (add-assoc a b (c + d))) ⟩\n replicateₙ (a + b + (c + d)) v\n =⟨ sym (cong (λ z → replicateₙ z v) (add-assoc (a + b) c d)) ⟩\n replicateₙ (a + b + c + d) v\n end\n\n++-assoc : {t : Set} -> (l1 l2 l3 : List t)\n -> (l1 ++ l2) ++ l3 ≡ l1 ++ (l2 ++ l3)\n++-assoc [] l2 l3 = refl\n++-assoc (x ∷ xs) l2 l3 = cong (λ z → x ∷ z) (++-assoc xs l2 l3)\n\nconcat-cme : {t : Set} -> (l1 l2 : List (Tile t))\n -> concat (map expand (l1 ++ l2)) ≡ (concat $ map expand l1) ++ (concat $ map expand l2)\nconcat-cme [] l2 = refl\nconcat-cme l1@(x ∷ xs) l2 = \n begin\n expand x ++ concat (map expand (xs ++ l2))\n =⟨ cong (_++_ (expand x)) (concat-cme xs l2) ⟩\n expand x ++ ((concat $ map expand xs) ++ (concat $ map expand l2))\n =⟨ sym $ ++-assoc (expand x) (concat $ map expand xs) (concat $ map expand l2) ⟩\n (expand x ++ concat (map expand xs)) ++ concat (map expand l2)\n end\n\nconcat-cme4 : {t : Set} -> (l1 l2 l3 l4 : List (Tile t))\n -> concat (map expand (l1 ++ l2 ++ l3 ++ l4)) ≡ (concat (map expand l1)) ++ (concat (map expand l2)) ++ (concat (map expand l3)) ++ (concat (map expand l4))\nconcat-cme4 l1 l2 l3 l4 =\n begin \n concat (map expand (l1 ++ (l2 ++ (l3 ++ l4))))\n =⟨ concat-cme l1 (l2 ++ (l3 ++ l4)) ⟩\n concat (map expand l1) ++ concat (map expand (l2 ++ (l3 ++ l4)))\n =⟨ cong (_++_ (concat (map expand l1))) (concat-cme l2 (l3 ++ l4)) ⟩\n concat (map expand l1) ++ concat (map expand l2) ++ concat (map expand (l3 ++ l4))\n =⟨ cong (λ q -> concat (map expand l1) ++ concat (map expand l2) ++ q) (concat-cme l3 l4) ⟩\n concat (map expand l1) ++ concat (map expand l2) ++ concat (map expand l3) ++ concat (map expand l4)\n end\n\ntilesQd-concat : {A : Set} {{eqA : Eq A}} -> (deps : Nat) -> (a b c d : VQuadrant A {deps}) -> (x1 y1 x2 y2 : Nat)\n -> IsTrue (x1 <= x2) -> IsTrue (y1 <= y2)\n -> ({a b : A} -> IsTrue (a == b) -> a ≡ b)\n -> (concat $ map expand $ (tilesQd deps a (RegionC (x1 , y1) (min x2 (pow 2 deps + x1) , min y2 (pow 2 deps + y1)))\n ++ tilesQd deps b (RegionC (min x2 (pow 2 deps + x1) , y1) (x2 , min y2 (pow 2 deps + y1)))\n ++ tilesQd deps c (RegionC (x1 , min y2 (pow 2 deps + y1)) (min x2 (pow 2 deps + x1) , y2) )\n ++ tilesQd deps d (RegionC (min x2 (pow 2 deps + x1) , min y2 (pow 2 deps + y1)) (x2 , y2) )))\n ≡ (concat $ map expand $ tilesQd (S deps) (combine a b c d) (RegionC (x1 , y1) (x2 , y2)))\ntilesQd-concat {A} deps a@(CVQuadrant (Leaf va)) b@(CVQuadrant (Leaf vb)) c@(CVQuadrant (Leaf vc)) d@(CVQuadrant (Leaf vd)) x1 y1 x2 y2 xp yp peq =\n ifc (va == vb && vb == vc && vc == vd) \n then (λ {{pc}} ->\n begin\n (cme $ TileC va rA ∷ TileC vb rB ∷ TileC vc rC ∷ TileC vd rD ∷ [])\n =⟨⟩\n replicateₙ (area rA) va ++ replicateₙ (area rB) vb ++ replicateₙ (area rC) vc ++ replicateₙ (area rD) vd ++ []\n =⟨ cong (λ q -> replicateₙ (area rA) va ++ replicateₙ (area rB) vb ++ replicateₙ (area rC) vc ++ q) (concat-nothing _) ⟩\n replicateₙ (area rA) (va) ++ replicateₙ (area rB) (vb) ++ replicateₙ (area rC) (vc) ++ replicateₙ (area rD) vd\n =⟨ cong (λ v -> replicateₙ (area rA) (va) ++ replicateₙ (area rB) (vb) ++ replicateₙ (area rC) (vc) ++ replicateₙ (area rD) v) \n (sym $ peq $ andSnd {vb == vc} $ andSnd {va == vb} pc) ⟩ \n replicateₙ (area rA) (va) ++ replicateₙ (area rB) (vb) ++ replicateₙ (area rC) (vc) ++ replicateₙ (area rD) (vc)\n =⟨ cong (λ v -> replicateₙ (area rA) (va) ++ replicateₙ (area rB) (vb) ++ replicateₙ (area rC) (v) ++ replicateₙ (area rD) (v)) \n (sym $ peq $ andFst {vb == vc} $ andSnd {va == vb} pc) ⟩\n replicateₙ (area rA) (va) ++ replicateₙ (area rB) (vb) ++ replicateₙ (area rC) (vb) ++ replicateₙ (area rD) (vb)\n =⟨ cong (λ v -> replicateₙ (area rA) (va) ++ replicateₙ (area rB) (v) ++ replicateₙ (area rC) (v) ++ replicateₙ (area rD) (v)) \n (sym $ peq $ andFst {va == vb} pc) ⟩\n replicateₙ (area rA) (va) ++ replicateₙ (area rB) (va) ++ replicateₙ (area rC) (va) ++ replicateₙ (area rD) (va)\n =⟨ replicate-concat4 (area rA) (area rB) (area rC) (area rD) (va) ⟩\n replicateₙ (area rA + area rB + area rC + area rD) (va)\n =⟨ cong (λ q -> replicateₙ q (va)) (square-split x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 \n (min-rel-1 x1 mid x2 xp) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) (min-rel-2 y2 (mid + y1))) ⟩\n replicateₙ (diff x2 x1 * diff y2 y1) (va)\n =⟨ sym $ concat-nothing (replicateₙ (diff x2 x1 * diff y2 y1) (va)) ⟩\n replicateₙ (diff x2 x1 * diff y2 y1) va ++ []\n =⟨⟩\n (cme $ TileC va (RegionC (x1 , y1) (x2 , y2)) ∷ [])\n =⟨ cong (λ q -> cme $ tilesQd (S deps) q (RegionC (x1 , y1) (x2 , y2))) (sym $ ifcTrue (va == vb && vb == vc && vc == vd) pc) ⟩\n (cme $ tilesQd (S deps) (ifc (va == vb && vb == vc && vc == vd) then CVQuadrant (Leaf va) else CVQuadrant (Node (Leaf va) (Leaf vb) (Leaf vc) (Leaf vd))) (RegionC (x1 , y1) (x2 , y2)))\n end) \n else (λ {{pc}} -> \n begin\n (concat $ map expand $ tilesQd (S deps) (CVQuadrant (Node (Leaf va) (Leaf vb) (Leaf vc) (Leaf vd)) {andCombine (zeroLteAny deps) (falseToNotTrue pc)}) (RegionC (x1 , y1) (x2 , y2)))\n =⟨ cong {x = CVQuadrant (Node (Leaf va) (Leaf vb) (Leaf vc) (Leaf vd)) {andCombine (zeroLteAny deps) (falseToNotTrue pc)}} (λ q -> concat $ map expand $ tilesQd (S deps) q (RegionC (x1 , y1) (x2 , y2))) (sym $ ifcFalse (va == vb && vb == vc && vc == vd) pc) ⟩\n (concat $ map expand $ tilesQd (S deps) (ifc (va == vb && vb == vc && vc == vd) then CVQuadrant (Leaf va) else CVQuadrant (Node (Leaf va) (Leaf vb) (Leaf vc) (Leaf vd))) (RegionC (x1 , y1) (x2 , y2)))\n end) where\n mid = pow 2 deps\n rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))\n rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))\n rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )\n rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )\n cme : List (Tile A) -> List A\n cme v = concat $ map expand $ v\n area : Region -> Nat\n area (RegionC (x1 , y1) (x2 , y2)) = diff x2 x1 * diff y2 y1\ntilesQd-concat deps (CVQuadrant (Leaf x)) (CVQuadrant (Leaf x₁)) (CVQuadrant (Leaf x₂)) (CVQuadrant (Node d d₁ d₂ d₃)) x1 y1 x2 y2 xp yp peq = refl\ntilesQd-concat deps (CVQuadrant (Leaf x)) (CVQuadrant (Leaf x₁)) (CVQuadrant (Node c c₁ c₂ c₃)) (CVQuadrant d) x1 y1 x2 y2 xp yp peq = refl\ntilesQd-concat deps (CVQuadrant (Leaf x)) (CVQuadrant (Node b b₁ b₂ b₃)) (CVQuadrant c) (CVQuadrant d) x1 y1 x2 y2 xp yp peq = refl\ntilesQd-concat deps (CVQuadrant (Node a a₁ a₂ a₃)) (CVQuadrant b) (CVQuadrant c) (CVQuadrant d) x1 y1 x2 y2 xp yp peq = refl\n\n\nfmap-tilesQd : {A B : Set} {{eqA : Eq A}} {{eqB : Eq B}} -> (f : A -> B) -> (dep : Nat) -> (vqd : VQuadrant A {dep}) -> (x1 y1 x2 y2 : Nat)\n -> IsTrue (x1 <= x2) -> IsTrue (y1 <= y2)\n -> ({a b : A} -> IsTrue (a == b) -> a ≡ b)\n -> ({a b : B} -> IsTrue (a == b) -> a ≡ b)\n -> (concat $ map expand $ fmap (fmap f) $ tilesQd dep vqd (RegionC (x1 , y1) (x2 , y2))) ≡ (concat $ map expand $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) (RegionC (x1 , y1) (x2 , y2)))\nfmap-tilesQd f dep (CVQuadrant (Leaf v) {p1}) x1 y1 x2 y2 px py peqA peqB = refl\nfmap-tilesQd {A} {B} f dep@(S deps) vqd@(CVQuadrant (Node a@(Leaf va) b@(Leaf vb) c@(Leaf vc) d@(Leaf vd)) {p1}) x1 y1 x2 y2 xp yp peqA peqB =\n ifc ((va == vb) && (vb == vc) && (vc == vd))\n then (λ {{pc}} -> \n (begin\n (cme $ fmap (fmap f) $ tilesQd dep vqd reg)\n =⟨⟩\n (cme $ TileC (f va) rA ∷ TileC (f vb) rB ∷ TileC (f vc) rC ∷ TileC (f vd) rD ∷ [])\n =⟨⟩\n replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vc) ++ replicateₙ (area rD) (f vd) ++ []\n =⟨ cong (λ q -> replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vc) ++ q) (concat-nothing _) ⟩\n replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vc) ++ replicateₙ (area rD) (f vd)\n =⟨ cong (λ v -> replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vc) ++ replicateₙ (area rD) (f v)) \n (sym $ peqA $ andSnd {vb == vc} $ andSnd {va == vb} pc) ⟩ \n replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vc) ++ replicateₙ (area rD) (f vc)\n =⟨ cong (λ v -> replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f v) ++ replicateₙ (area rD) (f v)) \n (sym $ peqA $ andFst {vb == vc} $ andSnd {va == vb} pc) ⟩\n replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f vb) ++ replicateₙ (area rC) (f vb) ++ replicateₙ (area rD) (f vb)\n =⟨ cong (λ v -> replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f v) ++ replicateₙ (area rC) (f v) ++ replicateₙ (area rD) (f v)) \n (sym $ peqA $ andFst {va == vb} pc) ⟩\n replicateₙ (area rA) (f va) ++ replicateₙ (area rB) (f va) ++ replicateₙ (area rC) (f va) ++ replicateₙ (area rD) (f va)\n =⟨ replicate-concat4 (area rA) (area rB) (area rC) (area rD) (f va) ⟩\n replicateₙ (area rA + area rB + area rC + area rD) (f va)\n =⟨ cong (λ q -> replicateₙ q (f va)) (square-split x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 \n (min-rel-1 x1 mid x2 xp) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) (min-rel-2 y2 (mid + y1))) ⟩\n replicateₙ (diff x2 x1 * diff y2 y1) (f va)\n =⟨ sym $ concat-nothing (replicateₙ (diff x2 x1 * diff y2 y1) (f va)) ⟩\n replicateₙ (diff x2 x1 * diff y2 y1) (f va) ++ []\n =⟨ cong (λ q -> cme $ tilesQd dep q reg) \n (sym $ ifcTrue ((f va == f vb) && (f vb == f vc) && (f vc == f vd)) \n (useEq (cong3 (λ e1 e2 e3 -> e1 && e2 && e3) (eq-subst f va vb) (eq-subst f vb vc) (eq-subst f vc vd)) pc)) ⟩\n (cme $ tilesQd dep (combine \n (fmapₑ (quadrantFunctor deps) f sA) \n (fmapₑ (quadrantFunctor deps) f sB) \n (fmapₑ (quadrantFunctor deps) f sC) \n (fmapₑ (quadrantFunctor deps) f sD)) reg)\n =⟨⟩\n (cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)\n end))\n else (λ {{pc}} -> \n (begin\n (cme $ fmap (fmap f) $ tilesQd dep vqd reg)\n =⟨⟩\n (cme $ TileC (f va) rA ∷ TileC (f vb) rB ∷ TileC (f vc) rC ∷ TileC (f vd) rD ∷ [])\n =⟨⟩\n (cme $ tilesQd dep (CVQuadrant (Node (Leaf (f va)) (Leaf (f vb)) (Leaf (f vc)) (Leaf (f vd))) \n {andCombine (zeroLteAny deps) (falseToNotTrue $ useEqFalse (cong3 (λ e1 e2 e3 -> e1 && e2 && e3) (eq-subst f va vb) (eq-subst f vb vc) (eq-subst f vc vd)) pc)}) reg)\n =⟨ cong {x = CVQuadrant (Node (Leaf (f va)) (Leaf (f vb)) (Leaf (f vc)) (Leaf (f vd))) \n {andCombine (zeroLteAny deps) (falseToNotTrue $ useEqFalse (cong3 (λ e1 e2 e3 -> e1 && e2 && e3) (eq-subst f va vb) (eq-subst f vb vc) (eq-subst f vc vd)) pc)}}\n (λ q -> cme $ tilesQd dep q reg) (sym $ ifcFalse ((f va == f vb) && (f vb == f vc) && (f vc == f vd))\n (useEqFalse (cong3 (λ e1 e2 e3 -> e1 && e2 && e3) (eq-subst f va vb) (eq-subst f vb vc) (eq-subst f vc vd)) pc)) ⟩\n (cme $ tilesQd dep (combine \n (fmapₑ (quadrantFunctor deps) f sA) \n (fmapₑ (quadrantFunctor deps) f sB) \n (fmapₑ (quadrantFunctor deps) f sC) \n (fmapₑ (quadrantFunctor deps) f sD)) reg)\n =⟨⟩\n (cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)\n end))\n \n where\n mid = pow 2 deps\n rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))\n rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))\n rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )\n rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )\n reg = (RegionC (x1 , y1) (x2 , y2))\n sA = CVQuadrant {dep = deps} a {aSub {dep = deps} a b c d p1}\n sB = CVQuadrant {dep = deps} b {bSub {dep = deps} a b c d p1}\n sC = CVQuadrant {dep = deps} c {cSub {dep = deps} a b c d p1}\n sD = CVQuadrant {dep = deps} d {dSub {dep = deps} a b c d p1}\n cme : List (Tile B) -> List B\n cme v = concat $ map expand $ v\n area : Region -> Nat\n area (RegionC (x1 , y1) (x2 , y2)) = diff x2 x1 * diff y2 y1\nfmap-tilesQd {A} {B} f dep@(S deps) vqd@(CVQuadrant (Node a@(Leaf _) b@(Leaf _) c@(Leaf _) d@(Node _ _ _ _)) {p1}) x1 y1 x2 y2 xp yp peqA peqB =\n begin\n (cme $ fmap (fmap f) $ tilesQd dep vqd reg)\n =⟨⟩\n (cme $ fmap (fmap f) $ (\n tilesQd deps sA rA ++ tilesQd deps sB rB ++ tilesQd deps sC rC ++ tilesQd deps sD rD\n ))\n =⟨ cong cme $ fmap-concat4 (fmap f) (tilesQd deps sA rA) (tilesQd deps sB rB) (tilesQd deps sC rC) (tilesQd deps sD rD) ⟩\n (cme (\n fmap (fmap f) (tilesQd deps sA rA) \n ++ fmap (fmap f) (tilesQd deps sB rB)\n ++ fmap (fmap f) (tilesQd deps sC rC)\n ++ fmap (fmap f) (tilesQd deps sD rD)\n ))\n =⟨ concat-cme4 (fmap (fmap f) (tilesQd deps sA rA)) (fmap (fmap f) (tilesQd deps sB rB)) (fmap (fmap f) (tilesQd deps sC rC)) (fmap (fmap f) (tilesQd deps sD rD)) ⟩\n (cme $ fmap (fmap f) (tilesQd deps sA rA))\n ++ (cme $ fmap (fmap f) (tilesQd deps sB rB))\n ++ (cme $ fmap (fmap f) (tilesQd deps sC rC))\n ++ (cme $ fmap (fmap f) (tilesQd deps sD rD))\n =⟨ cong4 (λ l1 l2 l3 l4 -> l1 ++ l2 ++ l3 ++ l4) \n (fmap-tilesQd f deps sA x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) (min-rel-1 x1 mid x2 xp) (min-rel-1 y1 mid y2 yp) peqA peqB) \n (fmap-tilesQd f deps sB (min x2 (mid + x1)) y1 x2 (min y2 (mid + y1)) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) peqA peqB) \n (fmap-tilesQd f deps sC x1 (min y2 (mid + y1)) (min x2 (mid + x1)) y2 (min-rel-1 x1 mid x2 xp) (min-rel-2 y2 (mid + y1)) peqA peqB) \n (fmap-tilesQd f deps sD (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 (min-rel-2 x2 (mid + x1)) (min-rel-2 y2 (mid + y1)) peqA peqB) ⟩\n\n (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD))\n =⟨ sym $ concat-cme4 (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD) ⟩\n (cme (\n tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD\n ))\n =⟨ tilesQd-concat deps (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD) x1 y1 x2 y2 xp yp peqB ⟩\n (cme $ tilesQd dep \n (combine (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD)) reg)\n =⟨⟩\n (cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)\n end where\n cme : List (Tile B) -> List B\n cme v = concat $ map expand $ v\n reg = (RegionC (x1 , y1) (x2 , y2))\n mid = pow 2 deps\n rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))\n rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))\n rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )\n rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )\n sA = CVQuadrant {dep = deps} a {aSub {dep = deps} a b c d p1}\n sB = CVQuadrant {dep = deps} b {bSub {dep = deps} a b c d p1}\n sC = CVQuadrant {dep = deps} c {cSub {dep = deps} a b c d p1}\n sD = CVQuadrant {dep = deps} d {dSub {dep = deps} a b c d p1}\nfmap-tilesQd {A} {B} f dep@(S deps) vqd@(CVQuadrant (Node a@(Leaf _) b@(Leaf _) c@(Node _ _ _ _) d) {p1}) x1 y1 x2 y2 xp yp peqA peqB =\n begin\n (cme $ fmap (fmap f) $ tilesQd dep vqd reg)\n =⟨⟩\n (cme $ fmap (fmap f) $ (\n tilesQd deps sA rA ++ tilesQd deps sB rB ++ tilesQd deps sC rC ++ tilesQd deps sD rD\n ))\n =⟨ cong cme $ fmap-concat4 (fmap f) (tilesQd deps sA rA) (tilesQd deps sB rB) (tilesQd deps sC rC) (tilesQd deps sD rD) ⟩\n (cme (\n fmap (fmap f) (tilesQd deps sA rA) \n ++ fmap (fmap f) (tilesQd deps sB rB)\n ++ fmap (fmap f) (tilesQd deps sC rC)\n ++ fmap (fmap f) (tilesQd deps sD rD)\n ))\n =⟨ concat-cme4 (fmap (fmap f) (tilesQd deps sA rA)) (fmap (fmap f) (tilesQd deps sB rB)) (fmap (fmap f) (tilesQd deps sC rC)) _ ⟩\n (cme $ fmap (fmap f) (tilesQd deps sA rA))\n ++ (cme $ fmap (fmap f) (tilesQd deps sB rB))\n ++ (cme $ fmap (fmap f) (tilesQd deps sC rC))\n ++ (cme $ fmap (fmap f) (tilesQd deps sD rD))\n =⟨ cong4 (λ l1 l2 l3 l4 -> l1 ++ l2 ++ l3 ++ l4) \n (fmap-tilesQd f deps sA x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) (min-rel-1 x1 mid x2 xp) (min-rel-1 y1 mid y2 yp) peqA peqB) \n (fmap-tilesQd f deps sB (min x2 (mid + x1)) y1 x2 (min y2 (mid + y1)) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) peqA peqB) \n (fmap-tilesQd f deps sC x1 (min y2 (mid + y1)) (min x2 (mid + x1)) y2 (min-rel-1 x1 mid x2 xp) (min-rel-2 y2 (mid + y1)) peqA peqB) \n (fmap-tilesQd f deps sD (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 (min-rel-2 x2 (mid + x1)) (min-rel-2 y2 (mid + y1)) peqA peqB) ⟩\n\n (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD))\n =⟨ sym $ concat-cme4 (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC) _ ⟩\n (cme (\n tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD\n ))\n =⟨ tilesQd-concat deps (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD) x1 y1 x2 y2 xp yp peqB ⟩\n (cme $ tilesQd dep \n (combine (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD)) reg)\n =⟨⟩\n (cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)\n end where\n cme : List (Tile B) -> List B\n cme v = concat $ map expand $ v\n reg = (RegionC (x1 , y1) (x2 , y2))\n mid = pow 2 deps\n rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))\n rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))\n rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )\n rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )\n sA = CVQuadrant {dep = deps} a {aSub {dep = deps} a b c d p1}\n sB = CVQuadrant {dep = deps} b {bSub {dep = deps} a b c d p1}\n sC = CVQuadrant {dep = deps} c {cSub {dep = deps} a b c d p1}\n sD = CVQuadrant {dep = deps} d {dSub {dep = deps} a b c d p1}\nfmap-tilesQd {A} {B} f dep@(S deps) vqd@(CVQuadrant (Node a@(Leaf _) b@(Node _ _ _ _) c d) {p1}) x1 y1 x2 y2 xp yp peqA peqB =\n begin\n (cme $ fmap (fmap f) $ tilesQd dep vqd reg)\n =⟨⟩\n (cme $ fmap (fmap f) $ (\n tilesQd deps sA rA ++ tilesQd deps sB rB ++ tilesQd deps sC rC ++ tilesQd deps sD rD\n ))\n =⟨ cong cme $ fmap-concat4 (fmap f) (tilesQd deps sA rA) (tilesQd deps sB rB) (tilesQd deps sC rC) (tilesQd deps sD rD) ⟩\n (cme (\n fmap (fmap f) (tilesQd deps sA rA) \n ++ fmap (fmap f) (tilesQd deps sB rB)\n ++ fmap (fmap f) (tilesQd deps sC rC)\n ++ fmap (fmap f) (tilesQd deps sD rD)\n ))\n =⟨ concat-cme4 (fmap (fmap f) (tilesQd deps sA rA)) (fmap (fmap f) (tilesQd deps sB rB)) (fmap (fmap f) (tilesQd deps sC rC)) _ ⟩\n (cme $ fmap (fmap f) (tilesQd deps sA rA))\n ++ (cme $ fmap (fmap f) (tilesQd deps sB rB))\n ++ (cme $ fmap (fmap f) (tilesQd deps sC rC))\n ++ (cme $ fmap (fmap f) (tilesQd deps sD rD))\n =⟨ cong4 (λ l1 l2 l3 l4 -> l1 ++ l2 ++ l3 ++ l4) \n (fmap-tilesQd f deps sA x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) (min-rel-1 x1 mid x2 xp) (min-rel-1 y1 mid y2 yp) peqA peqB) \n (fmap-tilesQd f deps sB (min x2 (mid + x1)) y1 x2 (min y2 (mid + y1)) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) peqA peqB) \n (fmap-tilesQd f deps sC x1 (min y2 (mid + y1)) (min x2 (mid + x1)) y2 (min-rel-1 x1 mid x2 xp) (min-rel-2 y2 (mid + y1)) peqA peqB) \n (fmap-tilesQd f deps sD (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 (min-rel-2 x2 (mid + x1)) (min-rel-2 y2 (mid + y1)) peqA peqB) ⟩\n\n (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD))\n =⟨ sym $ concat-cme4 (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC) _ ⟩\n (cme (\n tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD\n ))\n =⟨ tilesQd-concat deps (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD) x1 y1 x2 y2 xp yp peqB ⟩\n (cme $ tilesQd dep \n (combine (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD)) reg)\n =⟨⟩\n (cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)\n end where\n cme : List (Tile B) -> List B\n cme v = concat $ map expand $ v\n reg = (RegionC (x1 , y1) (x2 , y2))\n mid = pow 2 deps\n rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))\n rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))\n rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )\n rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )\n sA = CVQuadrant {dep = deps} a {aSub {dep = deps} a b c d p1}\n sB = CVQuadrant {dep = deps} b {bSub {dep = deps} a b c d p1}\n sC = CVQuadrant {dep = deps} c {cSub {dep = deps} a b c d p1}\n sD = CVQuadrant {dep = deps} d {dSub {dep = deps} a b c d p1}\nfmap-tilesQd {A} {B} f dep@(S deps) vqd@(CVQuadrant (Node a@(Node _ _ _ _) b c d) {p1}) x1 y1 x2 y2 xp yp peqA peqB =\n begin\n (cme $ fmap (fmap f) $ tilesQd dep vqd reg)\n =⟨⟩\n (cme $ fmap (fmap f) $ (\n tilesQd deps sA rA ++ tilesQd deps sB rB ++ tilesQd deps sC rC ++ tilesQd deps sD rD\n ))\n =⟨ cong cme $ fmap-concat4 (fmap f) (tilesQd deps sA rA) (tilesQd deps sB rB) (tilesQd deps sC rC) (tilesQd deps sD rD) ⟩\n (cme (\n fmap (fmap f) (tilesQd deps sA rA) \n ++ fmap (fmap f) (tilesQd deps sB rB)\n ++ fmap (fmap f) (tilesQd deps sC rC)\n ++ fmap (fmap f) (tilesQd deps sD rD)\n ))\n =⟨ concat-cme4 (fmap (fmap f) (tilesQd deps sA rA)) (fmap (fmap f) (tilesQd deps sB rB)) (fmap (fmap f) (tilesQd deps sC rC)) _ ⟩\n (cme $ fmap (fmap f) (tilesQd deps sA rA))\n ++ (cme $ fmap (fmap f) (tilesQd deps sB rB))\n ++ (cme $ fmap (fmap f) (tilesQd deps sC rC))\n ++ (cme $ fmap (fmap f) (tilesQd deps sD rD))\n =⟨ cong4 (λ l1 l2 l3 l4 -> l1 ++ l2 ++ l3 ++ l4) \n (fmap-tilesQd f deps sA x1 y1 (min x2 (mid + x1)) (min y2 (mid + y1)) (min-rel-1 x1 mid x2 xp) (min-rel-1 y1 mid y2 yp) peqA peqB) \n (fmap-tilesQd f deps sB (min x2 (mid + x1)) y1 x2 (min y2 (mid + y1)) (min-rel-2 x2 (mid + x1)) (min-rel-1 y1 mid y2 yp) peqA peqB) \n (fmap-tilesQd f deps sC x1 (min y2 (mid + y1)) (min x2 (mid + x1)) y2 (min-rel-1 x1 mid x2 xp) (min-rel-2 y2 (mid + y1)) peqA peqB) \n (fmap-tilesQd f deps sD (min x2 (mid + x1)) (min y2 (mid + y1)) x2 y2 (min-rel-2 x2 (mid + x1)) (min-rel-2 y2 (mid + y1)) peqA peqB) ⟩\n\n (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC))\n ++ (cme $ (tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD))\n =⟨ sym $ concat-cme4 (tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB) (tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC) _ ⟩\n (cme (\n tilesQd deps (fmapₑ (quadrantFunctor deps) f sA) rA\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sB) rB\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sC) rC\n ++ tilesQd deps (fmapₑ (quadrantFunctor deps) f sD) rD\n ))\n =⟨ tilesQd-concat deps (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD) x1 y1 x2 y2 xp yp peqB ⟩\n (cme $ tilesQd dep \n (combine (fmapₑ (quadrantFunctor deps) f sA) (fmapₑ (quadrantFunctor deps) f sB) (fmapₑ (quadrantFunctor deps) f sC) (fmapₑ (quadrantFunctor deps) f sD)) reg)\n =⟨⟩\n (cme $ tilesQd dep (fmapₑ (quadrantFunctor dep) f vqd) reg)\n end where\n cme : List (Tile B) -> List B\n cme v = concat $ map expand $ v\n reg = (RegionC (x1 , y1) (x2 , y2))\n mid = pow 2 deps\n rA = (RegionC (x1 , y1) (min x2 (mid + x1) , min y2 (mid + y1)))\n rB = (RegionC (min x2 (mid + x1) , y1) (x2 , min y2 (mid + y1)))\n rC = (RegionC (x1 , min y2 (mid + y1)) (min x2 (mid + x1) , y2) )\n rD = (RegionC (min x2 (mid + x1) , min y2 (mid + y1)) (x2 , y2) )\n sA = CVQuadrant {dep = deps} a {aSub {dep = deps} a b c d p1}\n sB = CVQuadrant {dep = deps} b {bSub {dep = deps} a b c d p1}\n sC = CVQuadrant {dep = deps} c {cSub {dep = deps} a b c d p1}\n sD = CVQuadrant {dep = deps} d {dSub {dep = deps} a b c d p1}\n\nqdToQt : {A : Set} {{eqA : Eq A}} -> (dep w h : Nat) -> (vqd : VQuadrant A {dep}) -> .(q : IsTrue (dep == log2up (if w < h then h else w)))\n -> tilesQd dep vqd (RegionC (0 , 0) (w , h)) ≡ tilesQt dep (toQt dep w h q vqd)\nqdToQt dep w h (CVQuadrant qd {p}) q = refl\n\nfmap-tilesQt : {A B : Set} {{eqA : Eq A}} {{eqB : Eq B}} -> (f : A -> B) -> (dep : Nat) -> (vqt : VQuadTree A {dep})\n -> ({a b : A} -> IsTrue (a == b) -> a ≡ b)\n -> ({a b : B} -> IsTrue (a == b) -> a ≡ b)\n -> (concat $ map expand $ fmap (fmap f) $ tilesQt dep vqt) ≡ (concat $ map expand $ tilesQt dep $ fmapₑ (quadtreeFunctor dep) f vqt)\nfmap-tilesQt f dep (CVQuadTree (Wrapper (w , h) (Leaf v))) peqA peqB = refl\nfmap-tilesQt {A} {B} f dep@(S deps) vqt@(CVQuadTree (Wrapper (w , h) qd@(Node a b c d)) {p1} {p2}) peqA peqB =\n begin\n (concat $ map expand $ fmap (fmap f) $ tilesQt dep vqt)\n =⟨⟩\n (concat $ map expand $ fmap (fmap f) $ tilesQd dep (CVQuadrant qd {p1}) (RegionC (0 , 0) (w , h)))\n =⟨ fmap-tilesQd f dep (CVQuadrant qd {p1}) 0 0 w h (zeroLteAny w) (zeroLteAny h) peqA peqB ⟩\n (concat $ map expand $ tilesQd dep (fmapₑ (quadrantFunctor dep) f (CVQuadrant qd {p1})) (RegionC (0 , 0) (w , h)))\n =⟨ cong (λ l -> concat $ map expand l) (qdToQt dep w h (combine (fmapₑ (quadrantFunctor deps) f (CVQuadrant a)) _ _ _) p2) ⟩\n (concat $ map expand $ tilesQt dep (fmapₑ (quadtreeFunctor dep) f vqt))\n end\n\nproof-foldfmap-qt : {t s : Set} {{eqT : Eq t}} {{eqS : Eq s}} {{monS : Monoid s}} {{monT : Monoid t}} (dep : Nat) -> (vqt : VQuadTree t {dep})\n -> (f : t -> s)\n -> ({a b : t} -> IsTrue (a == b) -> a ≡ b)\n -> ({a b : s} -> IsTrue (a == b) -> a ≡ b)\n -> foldMapₑ (quadtreeFoldable dep) f vqt ≡ foldMapₑ (quadtreeFoldable dep) id (fmapₑ (quadtreeFunctor dep) f vqt)\nproof-foldfmap-qt {t} {s} dep vqt@(CVQuadTree (Wrapper (w , h) (Leaf v)) {p} {q}) f peqA peqB = \n begin\n foldMapₑ (quadtreeFoldable dep) f vqt\n =⟨⟩\n foldMap f (replicateₙ (w * h) v ++ [])\n =⟨ cong (foldMap f) (concat-nothing (replicateₙ (w * h) v)) ⟩\n foldMap f (replicateₙ (w * h) v)\n =⟨ proof-foldfmap-list (replicateₙ (w * h) v) f ⟩\n foldMap id (fmap f (replicateₙ (w * h) v))\n =⟨ cong (foldMap id) (fmap-replicate f v (w * h)) ⟩\n foldMap id (replicateₙ (w * h) (f v))\n =⟨ cong (foldMap id) (sym $ concat-nothing (replicateₙ (w * h) (f v))) ⟩\n foldMap id (replicateₙ (w * h) (f v) ++ [])\n =⟨⟩\n foldMapₑ (quadtreeFoldable dep) id (fmapₑ (quadtreeFunctor dep) f vqt)\n end\nproof-foldfmap-qt {t} {s} dep vqt@(CVQuadTree (Wrapper (w , h) (Node qd qd₁ qd₂ qd₃)) {p} {q}) f peqA peqB =\n begin\n foldMapₑ (quadtreeFoldable dep) f vqt\n =⟨⟩\n (foldMap f $ concat $ map expand $ tilesQt dep vqt)\n =⟨ proof-foldfmap-list (concat $ map expand $ tilesQt dep vqt) f ⟩\n (foldMap id $ fmap f $ concat $ map expand $ tilesQt dep vqt)\n =⟨ cong (foldMap id) (fmap-concat-expand f (tilesQt dep vqt)) ⟩\n (foldMap id $ concat $ map expand $ fmap (fmap f) $ tilesQt dep vqt)\n =⟨ cong (foldMap id) (fmap-tilesQt f dep vqt peqA peqB) ⟩\n (foldMap id $ concat $ map expand $ tilesQt dep $ fmapₑ (quadtreeFunctor dep) f vqt)\n =⟨⟩ \n foldMapₑ (quadtreeFoldable dep) id (fmapₑ (quadtreeFunctor dep) f vqt)\n end", "meta": {"hexsha": "027bdedf47b1d23803a3121c5c3407d405aa7509", "size": 34467, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Data/QuadTree/FoldableProofs/FoldableFunctorProof.agda", "max_stars_repo_name": "JonathanBrouwer/research-project", "max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z", "max_issues_repo_path": "src/Data/QuadTree/FoldableProofs/FoldableFunctorProof.agda", "max_issues_repo_name": "JonathanBrouwer/research-project", "max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_issues_repo_licenses": ["Unlicense"], "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/Data/QuadTree/FoldableProofs/FoldableFunctorProof.agda", "max_forks_repo_name": "JonathanBrouwer/research-project", "max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.1550094518, "max_line_length": 268, "alphanum_fraction": 0.5498592857, "num_tokens": 14364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.682573734412324, "lm_q2_score": 0.5660185351961016, "lm_q1q2_score": 0.38634938531539653}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Boring lemmas used in Data.Nat.GCD and Data.Nat.Coprimality\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.Nat.GCD.Lemmas where\n\nopen import Data.Nat\nopen import Data.Nat.Properties\nopen import Data.Nat.Solver\nopen import Function\nopen import Relation.Binary.PropositionalEquality\n\nopen +-*-Solver\nopen ≡-Reasoning\n\nprivate\n distrib-comm : ∀ x k n → x * k + x * n ≡ x * (n + k)\n distrib-comm =\n solve 3 (λ x k n → x :* k :+ x :* n := x :* (n :+ k)) refl\n\n distrib-comm₂ : ∀ d x k n → d + x * (n + k) ≡ d + x * k + x * n\n distrib-comm₂ =\n solve 4 (λ d x k n → d :+ x :* (n :+ k) := d :+ x :* k :+ x :* n) refl\n\n-- Other properties\n-- TODO: Can this proof be simplified? An automatic solver which can\n-- handle ∸ would be nice...\nlem₀ : ∀ i j m n → i * m ≡ j * m + n → (i ∸ j) * m ≡ n\nlem₀ i j m n eq = begin\n (i ∸ j) * m ≡⟨ *-distribʳ-∸ m i j ⟩\n (i * m) ∸ (j * m) ≡⟨ cong (_∸ j * m) eq ⟩\n (j * m + n) ∸ (j * m) ≡⟨ cong (_∸ j * m) (+-comm (j * m) n) ⟩\n (n + j * m) ∸ (j * m) ≡⟨ m+n∸n≡m n (j * m) ⟩\n n ∎\n\nlem₁ : ∀ i j → 2 + i ≤′ 2 + j + i\nlem₁ i j = ≤⇒≤′ $ s≤s $ s≤s $ n≤m+n j i\n\nlem₂ : ∀ d x {k n} →\n d + x * k ≡ x * n → d + x * (n + k) ≡ 2 * x * n\nlem₂ d x {k} {n} eq = begin\n d + x * (n + k) ≡⟨ distrib-comm₂ d x k n ⟩\n d + x * k + x * n ≡⟨ cong₂ _+_ eq refl ⟩\n x * n + x * n ≡⟨ solve 3 (λ x n k → x :* n :+ x :* n\n := con 2 :* x :* n)\n refl x n k ⟩\n 2 * x * n ∎\n\nlem₃ : ∀ d x {i k n} →\n d + (1 + x + i) * k ≡ x * n →\n d + (1 + x + i) * (n + k) ≡ (1 + 2 * x + i) * n\nlem₃ d x {i} {k} {n} eq = begin\n d + y * (n + k) ≡⟨ distrib-comm₂ d y k n ⟩\n d + y * k + y * n ≡⟨ cong₂ _+_ eq refl ⟩\n x * n + y * n ≡⟨ solve 3 (λ x n i → x :* n :+ (con 1 :+ x :+ i) :* n\n := (con 1 :+ con 2 :* x :+ i) :* n)\n refl x n i ⟩\n (1 + 2 * x + i) * n ∎\n where y = 1 + x + i\n\nlem₄ : ∀ d y {k i} n →\n d + y * k ≡ (1 + y + i) * n →\n d + y * (n + k) ≡ (1 + 2 * y + i) * n\nlem₄ d y {k} {i} n eq = begin\n d + y * (n + k) ≡⟨ distrib-comm₂ d y k n ⟩\n d + y * k + y * n ≡⟨ cong₂ _+_ eq refl ⟩\n (1 + y + i) * n + y * n ≡⟨ solve 3 (λ y i n → (con 1 :+ y :+ i) :* n :+ y :* n\n := (con 1 :+ con 2 :* y :+ i) :* n)\n refl y i n ⟩\n (1 + 2 * y + i) * n ∎\n\nlem₅ : ∀ d x {n k} →\n d + x * n ≡ x * k →\n d + 2 * x * n ≡ x * (n + k)\nlem₅ d x {n} {k} eq = begin\n d + 2 * x * n ≡⟨ solve 3 (λ d x n → d :+ con 2 :* x :* n\n := d :+ x :* n :+ x :* n)\n refl d x n ⟩\n d + x * n + x * n ≡⟨ cong₂ _+_ eq refl ⟩\n x * k + x * n ≡⟨ distrib-comm x k n ⟩\n x * (n + k) ∎\n\nlem₆ : ∀ d x {n i k} →\n d + x * n ≡ (1 + x + i) * k →\n d + (1 + 2 * x + i) * n ≡ (1 + x + i) * (n + k)\nlem₆ d x {n} {i} {k} eq = begin\n d + (1 + 2 * x + i) * n ≡⟨ solve 4 (λ d x i n → d :+ (con 1 :+ con 2 :* x :+ i) :* n\n := d :+ x :* n :+ (con 1 :+ x :+ i) :* n)\n refl d x i n ⟩\n d + x * n + y * n ≡⟨ cong₂ _+_ eq refl ⟩\n y * k + y * n ≡⟨ distrib-comm y k n ⟩\n y * (n + k) ∎\n where y = 1 + x + i\n\nlem₇ : ∀ d y {i} n {k} →\n d + (1 + y + i) * n ≡ y * k →\n d + (1 + 2 * y + i) * n ≡ y * (n + k)\nlem₇ d y {i} n {k} eq = begin\n d + (1 + 2 * y + i) * n ≡⟨ solve 4 (λ d y i n → d :+ (con 1 :+ con 2 :* y :+ i) :* n\n := d :+ (con 1 :+ y :+ i) :* n :+ y :* n)\n refl d y i n ⟩\n d + (1 + y + i) * n + y * n ≡⟨ cong₂ _+_ eq refl ⟩\n y * k + y * n ≡⟨ distrib-comm y k n ⟩\n y * (n + k) ∎\n\nlem₈ : ∀ {i j k q} x y →\n 1 + y * j ≡ x * i → j * k ≡ q * i →\n k ≡ (x * k ∸ y * q) * i\nlem₈ {i} {j} {k} {q} x y eq eq′ =\n sym (lem₀ (x * k) (y * q) i k lemma)\n where\n lemma = begin\n x * k * i ≡⟨ solve 3 (λ x k i → x :* k :* i\n := x :* i :* k)\n refl x k i ⟩\n x * i * k ≡⟨ cong (_* k) (sym eq) ⟩\n (1 + y * j) * k ≡⟨ solve 3 (λ y j k → (con 1 :+ y :* j) :* k\n := y :* (j :* k) :+ k)\n refl y j k ⟩\n y * (j * k) + k ≡⟨ cong (λ n → y * n + k) eq′ ⟩\n y * (q * i) + k ≡⟨ solve 4 (λ y q i k → y :* (q :* i) :+ k\n := y :* q :* i :+ k)\n refl y q i k ⟩\n y * q * i + k ∎\n\nlem₉ : ∀ {i j k q} x y →\n 1 + x * i ≡ y * j → j * k ≡ q * i →\n k ≡ (y * q ∸ x * k) * i\nlem₉ {i} {j} {k} {q} x y eq eq′ =\n sym (lem₀ (y * q) (x * k) i k lemma)\n where\n lem = solve 3 (λ a b c → a :* b :* c := b :* c :* a) refl\n lemma = begin\n y * q * i ≡⟨ lem y q i ⟩\n q * i * y ≡⟨ cong (λ n → n * y) (sym eq′) ⟩\n j * k * y ≡⟨ sym (lem y j k) ⟩\n y * j * k ≡⟨ cong (λ n → n * k) (sym eq) ⟩\n (1 + x * i) * k ≡⟨ solve 3 (λ x i k → (con 1 :+ x :* i) :* k\n := x :* k :* i :+ k)\n refl x i k ⟩\n x * k * i + k ∎\n\nlem₁₀ : ∀ {a′} b c {d} e f → let a = suc a′ in\n a + b * (c * d * a) ≡ e * (f * d * a) →\n d ≡ 1\nlem₁₀ {a′} b c {d} e f eq =\n i*j≡1⇒j≡1 (e * f ∸ b * c) d\n (lem₀ (e * f) (b * c) d 1\n (*-cancelʳ-≡ (e * f * d) (b * c * d + 1) (begin\n e * f * d * a ≡⟨ solve 4 (λ e f d a → e :* f :* d :* a\n := e :* (f :* d :* a))\n refl e f d a ⟩\n e * (f * d * a) ≡⟨ sym eq ⟩\n a + b * (c * d * a) ≡⟨ solve 4 (λ a b c d → a :+ b :* (c :* d :* a)\n := (b :* c :* d :+ con 1) :* a)\n refl a b c d ⟩\n (b * c * d + 1) * a ∎)))\n where a = suc a′\n\nlem₁₁ : ∀ {i j m n k d} x y →\n 1 + y * j ≡ x * i → i * k ≡ m * d → j * k ≡ n * d →\n k ≡ (x * m ∸ y * n) * d\nlem₁₁ {i} {j} {m} {n} {k} {d} x y eq eq₁ eq₂ =\n sym (lem₀ (x * m) (y * n) d k (begin\n x * m * d ≡⟨ *-assoc x m d ⟩\n x * (m * d) ≡⟨ cong (x *_) (sym eq₁) ⟩\n x * (i * k) ≡⟨ sym (*-assoc x i k) ⟩\n x * i * k ≡⟨ cong₂ _*_ (sym eq) refl ⟩\n (1 + y * j) * k ≡⟨ solve 3 (λ y j k → (con 1 :+ y :* j) :* k\n := y :* (j :* k) :+ k)\n refl y j k ⟩\n y * (j * k) + k ≡⟨ cong (λ p → y * p + k) eq₂ ⟩\n y * (n * d) + k ≡⟨ cong₂ _+_ (sym $ *-assoc y n d) refl ⟩\n y * n * d + k ∎))\n", "meta": {"hexsha": "9658abce07d4be200cbb9cfd4c01111c9e4de219", "size": 7083, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/GCD/Lemmas.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": "test/asset/agda-stdlib-1.0/Data/Nat/GCD/Lemmas.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Data/Nat/GCD/Lemmas.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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.5698324022, "max_line_length": 93, "alphanum_fraction": 0.2963433573, "num_tokens": 3083, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6688802603710086, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.3862752502285365}} {"text": "{-# OPTIONS --without-K --safe #-}\nmodule Cats.Category.Presheaves.Facts.Exponential where\n\nopen import Data.Product using (_,_)\nopen import Relation.Binary using (Setoid)\n\nopen import Cats.Category\nopen import Cats.Category.Fun using (Fun ; ≈-intro ; ≈-elim)\nopen import Cats.Category.Presheaves using (Presheaves)\nopen import Cats.Category.Setoids as Setoids using (≈-intro ; ≈-elim)\nopen import Cats.Functor using (Functor)\nopen import Cats.Trans using (Trans ; component ; natural)\n\nimport Cats.Category.Fun.Facts.Product as Product\nimport Cats.Category.Setoids.Facts\n\nopen Functor\nopen HasBinaryProducts {{...}}\nopen Setoids._⇒_\n\n\nmodule _ {l} {ℂ : Category l l l} where\n\n private\n module ℂ = Category ℂ\n open Category (Presheaves ℂ l l)\n module $ (F : Obj) {x : Category.Obj ℂ} = Setoid (fobj F x)\n\n\n -- Could replace this with transposeBifunctor₂ HomF, but that would introduce\n -- even more redundant compositions with the identity.\n y : ℂ.Obj → Obj\n y d = record\n { fobj = λ c → ℂ.Hom c d\n ; fmap = λ f → record\n { arr = (ℂ._∘ f)\n ; resp = ℂ.∘-resp-l\n }\n ; fmap-resp = λ eq₁ → ≈-intro λ eq₂ → ℂ.∘-resp eq₂ eq₁\n ; fmap-id = ≈-intro λ eq → ℂ.≈.trans ℂ.id-r eq\n ; fmap-∘ = ≈-intro λ eq → ℂ.≈.trans ℂ.assoc (ℂ.∘-resp-l eq)\n }\n\n\n _↝_ : (F G : Obj) → Obj\n F ↝ G = record\n { fobj = λ d → Hom (y d × F) G\n ; fmap = λ {d} {d′} f → record\n { arr = λ α → record\n { component = λ d → record\n { arr = λ where\n (g , c) → arr (component α d) (f ℂ.∘ g , c)\n ; resp = λ where\n (eq₁ , eq₂) → resp (component α d) (ℂ.∘-resp-r eq₁ , eq₂)\n }\n ; natural = λ {e} {e′} {g} → ≈-intro λ where\n {h , c} {h′ , c′} (h≈h′ , c≈c′) →\n $.trans G (resp (component α e′) (ℂ.unassoc , $.refl F))\n (≈-elim (natural α) (ℂ.∘-resp-r h≈h′ , c≈c′))\n }\n ; resp = λ α≈β → ≈-intro (≈-intro λ where\n (f≈g , h≈i) → ≈-elim (≈-elim α≈β) (ℂ.∘-resp-r f≈g , h≈i))\n }\n ; fmap-resp = λ f≈g → ≈-intro λ α≈β → ≈-intro (≈-intro λ where\n (c≈d , h≈i) → ≈-elim (≈-elim α≈β) ((ℂ.∘-resp f≈g c≈d) , h≈i))\n ; fmap-id = ≈-intro λ α≈β → ≈-intro (≈-intro λ where\n (c≈d , h≈i) → ≈-elim (≈-elim α≈β) ((ℂ.≈.trans ℂ.id-l c≈d) , h≈i))\n ; fmap-∘ = ≈-intro λ α≈β → ≈-intro (≈-intro λ where\n (c≈d , h≈i) → ≈-elim (≈-elim α≈β) ((ℂ.≈.trans ℂ.unassoc (ℂ.∘-resp-r c≈d)) , h≈i))\n }\n\n\n Eval : ∀ F G → F ↝ G × F ⇒ G\n Eval F G = record\n { component = λ c → record\n { arr = λ where\n (α , x) → arr (component α c) (ℂ.id , x)\n ; resp = λ where\n (α≈β , f≈g) → ≈-elim (≈-elim α≈β) (ℂ.≈.refl , f≈g)\n }\n ; natural = λ {c} {d} → ≈-intro λ where\n {α , f} {β , g} (α≈β , f≈g) →\n $.trans G\n (≈-elim (≈-elim α≈β)\n (ℂ.≈.trans ℂ.id-r (ℂ.≈.sym ℂ.id-l) , resp (fmap F _) f≈g))\n (≈-elim (natural β) (ℂ.≈.refl , $.refl F))\n }\n\n\n Curry : ∀ E F G → E × F ⇒ G → E ⇒ F ↝ G\n Curry E F G α = record\n { component = λ d → record\n { arr = λ x → record\n { component = λ c → record\n { arr = λ where\n (f , y) → arr (component α c) (arr (fmap E f) x , y)\n ; resp = λ where\n (c≈d , x≈y) → resp (component α c)\n (≈-elim (fmap-resp E c≈d) ($.refl E) , x≈y)\n }\n ; natural = ≈-intro λ where\n (f≈g , x≈y) → $.trans G\n (resp (component α _)\n (($.sym E (≈-elim (fmap-∘ E) ($.refl E))) , ($.refl F)))\n (≈-elim (natural α) (≈-elim (fmap-resp E f≈g) ($.refl E) , x≈y))\n }\n ; resp = λ x≈y → ≈-intro (≈-intro λ where\n (f≈g , c≈d) → resp (component α _) ((≈-elim (fmap-resp E f≈g) x≈y) , c≈d))\n }\n ; natural = ≈-intro λ x≈y → ≈-intro (≈-intro λ where\n (f≈g , c≈d) → resp (component α _)\n ( $.trans E (≈-elim (fmap-∘ E) x≈y)\n (≈-elim (fmap-resp E (ℂ.∘-resp-r f≈g)) ($.refl E))\n , c≈d ))\n }\n\n\n instance\n hasExponentials : HasExponentials (Presheaves ℂ l l)\n hasExponentials = record\n { hasBinaryProducts = Product.hasBinaryProducts\n ; _↝′_ = λ F G → record\n { Cᴮ = F ↝ G\n ; eval = Eval F G\n ; curry′ = λ {E} α → record\n { arr = Curry E F G α\n ; prop = ≈-intro (≈-intro λ where\n (x≈y , u≈v) → resp (component α _) (≈-elim (fmap-id E) x≈y , u≈v))\n ; unique = λ {α} α≈ → ≈-intro (≈-intro (λ x≈y → ≈-intro (≈-intro (λ where\n (f≈g , u≈v) → $.trans G\n (≈-elim (≈-elim (≈.sym α≈)) (≈-elim (fmap-resp E f≈g) ($.refl E) , u≈v))\n ($.trans G\n (≈-elim (≈-elim (≈-elim (natural α) x≈y)) (ℂ.≈.refl , ($.refl F)))\n (resp (component (arr (component α _) _) _) (ℂ.id-r , ($.refl F))))))))\n }\n }\n }\n", "meta": {"hexsha": "3d4b4dfc4a4de3253c756cdef2b4deaee7f96ee1", "size": 4870, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cats/Category/Presheaves/Facts/Exponential.agda", "max_stars_repo_name": "JLimperg/cats", "max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z", "max_issues_repo_path": "Cats/Category/Presheaves/Facts/Exponential.agda", "max_issues_repo_name": "JLimperg/cats", "max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "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": "Cats/Category/Presheaves/Facts/Exponential.agda", "max_forks_repo_name": "JLimperg/cats", "max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z", "avg_line_length": 35.2898550725, "max_line_length": 89, "alphanum_fraction": 0.4726899384, "num_tokens": 1984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.38624428569540453}} {"text": "open import Agda.Primitive using (_⊔_)\n\nimport Categories.Category as Category\nimport Categories.Category.Cartesian as Cartesian\nimport MultiSorted.Interpretation as Interpretation\n\nopen import MultiSorted.AlgebraicTheory\nopen import MultiSorted.Substitution\nimport MultiSorted.Product as Product\n\nmodule MultiSorted.Model {o ℓ e ℓt}\n {𝓈 ℴ}\n {Σ : Signature {𝓈} {ℴ}}\n (T : Theory ℓt Σ)\n {𝒞 : Category.Category o ℓ e}\n {cartesian-𝒞 : Cartesian.Cartesian 𝒞} where\n\n -- Model of a theory\n\n record Is-Model (I : Interpretation.Interpretation Σ cartesian-𝒞) : Set (ℓt ⊔ o ⊔ ℓ ⊔ e) where\n\n open Theory T\n open Category.Category 𝒞\n open Interpretation.Interpretation I\n open HomReasoning\n\n field\n model-eq : ∀ (ε : ax) → ⊨ ax-eq (ε)\n\n -- Soundness of semantics\n module _ where\n open Product.Producted interp-ctx\n\n -- first we show that substitution preserves validity\n model-resp-[]s : ∀ {Γ Δ} {A} {u v : Term Γ A} {σ : Δ ⇒s Γ} →\n interp-term u ≈ interp-term v → interp-term (u [ σ ]s) ≈ interp-term (v [ σ ]s)\n model-resp-[]s {u = u} {v = v} {σ = σ} ξ =\n begin\n interp-term (u [ σ ]s) ≈⟨ interp-[]s {t = u} ⟩\n (interp-term u ∘ interp-subst σ) ≈⟨ ξ ⟩∘⟨refl ⟩\n (interp-term v ∘ interp-subst σ) ≈˘⟨ interp-[]s {t = v} ⟩\n interp-term (v [ σ ]s) ∎\n\n -- the soundness statement\n ⊢-⊨ : ∀ {ε : Equation Σ} → ⊢ ε → ⊨ ε\n ⊢-⊨ eq-refl = Equiv.refl\n ⊢-⊨ (eq-symm ξ) = ⟺ (⊢-⊨ ξ)\n ⊢-⊨ (eq-tran ξ θ) = ⊢-⊨ ξ ○ ⊢-⊨ θ\n ⊢-⊨ (eq-congr ξ) = ∘-resp-≈ʳ (unique λ i → project ○ ⟺ (⊢-⊨ (ξ i)))\n ⊢-⊨ (eq-axiom ε σ) = model-resp-[]s {u = ax-lhs ε} {v = ax-rhs ε} (model-eq ε)\n\n -- Every theory has the trivial model, whose carrier is the terminal object\n Trivial : Is-Model (Interpretation.Trivial Σ cartesian-𝒞)\n Trivial =\n let open Cartesian.Cartesian cartesian-𝒞 in\n record { model-eq = λ ε → !-unique₂ }\n", "meta": {"hexsha": "7cc22a641c625709108355f373b9b191b82d1d25", "size": 1979, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/MultiSorted/Model.agda", "max_stars_repo_name": "cilinder/formaltt", "max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z", "max_issues_repo_path": "src/MultiSorted/Model.agda", "max_issues_repo_name": "andrejbauer/formaltt", "max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z", "max_forks_repo_path": "src/MultiSorted/Model.agda", "max_forks_repo_name": "andrejbauer/formaltt", "max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z", "avg_line_length": 34.7192982456, "max_line_length": 102, "alphanum_fraction": 0.5795856493, "num_tokens": 733, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.38624428569540437}} {"text": "{-# OPTIONS --no-positivity-check #-}\n\n{- This file gives a standard example showing that if arguments to\n constructors can use the datatype in a negative position (to the\n left of one or an odd number of arrows), then termination and \n logical consistency is lost. -}\n\nmodule neg-datatype-nonterm where\n\nopen import empty\n\ndata Bad : Set where\n bad : (Bad → ⊥) → Bad\n\nbadFunc : Bad → ⊥\nbadFunc (bad f) = f (bad f)\n\n-- if you try to normalize the following, it will diverge\ninconsistency : ⊥\ninconsistency = badFunc (bad badFunc)\n", "meta": {"hexsha": "3826d52dde5dcbc4ac503df8db76163a6cd2d75e", "size": 537, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "neg-datatype-nonterm.agda", "max_stars_repo_name": "logicshan/IAL", "max_stars_repo_head_hexsha": "2ad96390a9be5c238e73709a21533c7354cedd0c", "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": "neg-datatype-nonterm.agda", "max_issues_repo_name": "logicshan/IAL", "max_issues_repo_head_hexsha": "2ad96390a9be5c238e73709a21533c7354cedd0c", "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": "neg-datatype-nonterm.agda", "max_forks_repo_name": "logicshan/IAL", "max_forks_repo_head_hexsha": "2ad96390a9be5c238e73709a21533c7354cedd0c", "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": 25.5714285714, "max_line_length": 67, "alphanum_fraction": 0.7132216015, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.749087201911703, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.3862442799189018}} {"text": "-- Idiom bracket notation.\nmodule Syntax.Idiom where\n\nimport Lvl\nopen import Type\n\nprivate variable ℓ ℓ₁ ℓ₂ : Lvl.Level\nprivate variable A B : Type{ℓ}\nprivate variable F : Type{ℓ₁} → Type{ℓ₂}\n\n-- The notation `⦇ f x₁ x₂ x₃ ⦈` will automatically be translated to `((pure f <*> x₁) <*> x₂) <*> x₃`.\nrecord IdiomBrackets (F : Type{ℓ₁} → Type{ℓ₂}) : Type{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂} where\n constructor intro\n field\n pure : (A → F(A))\n _<*>_ : F(A → B) → (F(A) → F(B))\nopen IdiomBrackets ⦃ … ⦄ using (pure ; _<*>_) public\n\n-- The notation `⦇⦈` will automatically be translated to `empty`.\nrecord IdiomBrackets₀ (F : Type{ℓ₁} → Type{ℓ₂}) : Type{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂} where\n constructor intro\n field\n empty : F(A)\nopen IdiomBrackets₀ ⦃ … ⦄ using (empty) public\n\n-- The notation `⦇ f₁ x₁ x₂ x₃ | f₂ y₁ y₂ | f₃ z₁ ⦈` will automatically be translated to `(((pure f <*> x₁) <*> x₂) <*> x₃) <|> (((pure f₂ <*> y₁) <*> y₂) <|> (pure f₃ <*> z₁))`.\nrecord IdiomBrackets₊ (F : Type{ℓ₁} → Type{ℓ₂}) ⦃ _ : IdiomBrackets(F) ⦄ : Type{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂} where\n constructor intro\n field\n _<|>_ : F(A) → F(A) → F(A)\nopen IdiomBrackets₊ ⦃ … ⦄ using (_<|>_) public\n", "meta": {"hexsha": "d2024c63a39ce328836380caf19df8d96e00a078", "size": 1154, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Syntax/Idiom.agda", "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_issues_repo_path": "Syntax/Idiom.agda", "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": "Syntax/Idiom.agda", "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": 36.0625, "max_line_length": 178, "alphanum_fraction": 0.6091854419, "num_tokens": 498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.38620365556177694}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import Base\nopen import Homotopy.PullbackDef\n\nmodule Homotopy.PullbackIsPullback {i} (d : pullback-diag i) where\n\nopen pullback-diag d\n\nimport Homotopy.PullbackUP as PullbackUP\nopen PullbackUP d (λ _ → unit)\n\npullback-cone : cone (pullback d)\npullback-cone = (pullback.a d , pullback.b d , pullback.h d)\n\nfactor-pullback : (E : Set i) → (cone E → (E → pullback d))\nfactor-pullback E (top→A , top→B , h) x = (top→A x , top→B x , h x)\n\npullback-is-pullback : is-pullback (pullback d) pullback-cone\npullback-is-pullback E = iso-is-eq _\n (factor-pullback E)\n (λ y → refl)\n (λ f → refl)\n", "meta": {"hexsha": "73d54c80009cf9a3bfc8ba809ca1473612b93874", "size": 619, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "old/Homotopy/PullbackIsPullback.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "old/Homotopy/PullbackIsPullback.agda", "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "old/Homotopy/PullbackIsPullback.agda", "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 25.7916666667, "max_line_length": 67, "alphanum_fraction": 0.6865912763, "num_tokens": 215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8376199471193039, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.3861568503086938}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\n{- Remember to keep CodeBP.agda in sync. -}\n\nopen import HoTT\nimport homotopy.RelativelyConstantToSetExtendsViaSurjection as SurjExt\n\nmodule homotopy.vankampen.CodeAP {i j k l}\n (span : Span {i} {j} {k})\n {D : Type l} (h : D → Span.C span) (h-is-surj : is-surj h) where\n\n open Span span\n\n data precodeAA (a₀ : A) : A → Type (lmax (lmax (lmax i j) k) l)\n data precodeAB (a₀ : A) (b₁ : B) : Type (lmax (lmax (lmax i j) k) l)\n\n data precodeAA a₀ where\n pc-a : ∀ {a₁} (pA : a₀ =₀ a₁) → precodeAA a₀ a₁\n pc-aba : ∀ d {a₁} (pc : precodeAB a₀ (g (h d))) (pA : f (h d) =₀ a₁) → precodeAA a₀ a₁\n\n infix 66 pc-a\n syntax pc-a p = ⟧a p\n infixl 65 pc-aba\n syntax pc-aba d pcAB pA = pcAB ab⟦ d ⟧a pA\n\n data precodeAB a₀ b₁ where\n pc-aab : ∀ d (pc : precodeAA a₀ (f (h d))) (pB : g (h d) =₀ b₁) → precodeAB a₀ b₁\n\n infixl 65 pc-aab\n syntax pc-aab d pcAA pB = pcAA aa⟦ d ⟧b pB\n\n data precodeAA-rel {a₀ : A} : {a₁ : A}\n → precodeAA a₀ a₁ → precodeAA a₀ a₁ → Type (lmax (lmax (lmax i j) k) l)\n data precodeAB-rel {a₀ : A} : {b₁ : B}\n → precodeAB a₀ b₁ → precodeAB a₀ b₁ → Type (lmax (lmax (lmax i j) k) l)\n data precodeAA-rel {a₀} where\n pcAAr-idp₀-idp₀ : ∀ {d} pcAA → precodeAA-rel (pcAA aa⟦ d ⟧b idp₀ ab⟦ d ⟧a idp₀) pcAA\n pcAAr-cong : ∀ {d a₁ pcAB₁ pcAB₂} (r : precodeAB-rel pcAB₁ pcAB₂) (pA : f (h d) =₀ a₁)\n → precodeAA-rel (pcAB₁ ab⟦ d ⟧a pA) (pcAB₂ ab⟦ d ⟧a pA)\n data precodeAB-rel {a₀} where\n pcABr-idp₀-idp₀ : ∀ {d} pcAB → precodeAB-rel (pcAB ab⟦ d ⟧a idp₀ aa⟦ d ⟧b idp₀) pcAB\n pcABr-switch : ∀ {d₀ d₁ : D} pcAB (pC : h d₀ =₀ h d₁)\n → precodeAB-rel (pcAB ab⟦ d₀ ⟧a ap₀ f pC aa⟦ d₁ ⟧b idp₀) (pcAB ab⟦ d₀ ⟧a idp₀ aa⟦ d₀ ⟧b ap₀ g pC)\n pcABr-cong : ∀ {d b₁ pcAA₁ pcAA₂} (r : precodeAA-rel pcAA₁ pcAA₂) (pB : g (h d) =₀ b₁)\n → precodeAB-rel (pcAA₁ aa⟦ d ⟧b pB) (pcAA₂ aa⟦ d ⟧b pB)\n\n codeAA : A → A → Type (lmax (lmax (lmax i j) k) l)\n codeAA a₀ a₁ = SetQuot (precodeAA-rel {a₀} {a₁})\n\n codeAB : A → B → Type (lmax (lmax (lmax i j) k) l)\n codeAB a₀ b₁ = SetQuot (precodeAB-rel {a₀} {b₁})\n\n c-aba : ∀ {a₀} d {a₁} (pc : codeAB a₀ (g (h d))) (pA : f (h d) =₀ a₁) → codeAA a₀ a₁\n c-aba d {a₁} c pA = SetQuot-rec SetQuot-is-set\n (λ pc → q[ pc-aba d pc pA ])\n (λ r → quot-rel $ pcAAr-cong r pA) c\n\n c-aab : ∀ {a₀} d {b₁} (pc : codeAA a₀ (f (h d))) (pB : g (h d) =₀ b₁) → codeAB a₀ b₁\n c-aab d {a₁} c pB = SetQuot-rec SetQuot-is-set\n (λ pc → q[ pc-aab d pc pB ])\n (λ r → quot-rel $ pcABr-cong r pB) c\n\n-- codeAP\n\n abstract\n pcAA-idp₀-idp₀-head : ∀ {d₀ a} (pA : f (h d₀) =₀ a)\n → q[ ⟧a idp₀ aa⟦ d₀ ⟧b idp₀ ab⟦ d₀ ⟧a pA ] == q[ ⟧a pA ] :> codeAA _ a\n pcAA-idp₀-idp₀-head {d₀} = Trunc-elim (λ _ → =-preserves-set SetQuot-is-set) lemma where\n lemma : ∀ {a} (pA : f (h d₀) == a)\n → q[ ⟧a idp₀ aa⟦ d₀ ⟧b idp₀ ab⟦ d₀ ⟧a [ pA ] ] == q[ ⟧a [ pA ] ] :> codeAA _ a\n lemma idp = quot-rel $ pcAAr-idp₀-idp₀ (⟧a idp₀)\n\n pcAA-prepend : ∀ {a₀} d₁ {a₂} → a₀ =₀ f (h d₁) → precodeAA (f (h d₁)) a₂ → precodeAA a₀ a₂\n pcAB-prepend : ∀ {a₀} d₁ {b₂} → a₀ =₀ f (h d₁) → precodeAB (f (h d₁)) b₂ → precodeAB a₀ b₂\n pcAA-prepend d₁ pA (pc-a pA₁) = pc-aba d₁ (pc-aab d₁ (pc-a pA) idp₀) pA₁\n pcAA-prepend d₁ pA (pc-aba d pc pA₁) = pc-aba d (pcAB-prepend d₁ pA pc) pA₁\n pcAB-prepend d₁ pA (pc-aab d pc pB) = pc-aab d (pcAA-prepend d₁ pA pc) pB\n\n abstract\n pcAA-prepend-idp₀ : ∀ {d₀ a₁} (pcAA : precodeAA (f (h d₀)) a₁)\n → q[ pcAA-prepend d₀ idp₀ pcAA ] == q[ pcAA ] :> codeAA (f (h d₀)) a₁\n pcAB-prepend-idp₀ : ∀ {d₀ b₁} (pcAB : precodeAB (f (h d₀)) b₁)\n → q[ pcAB-prepend d₀ idp₀ pcAB ] == q[ pcAB ] :> codeAB (f (h d₀)) b₁\n pcAA-prepend-idp₀ (pc-a pA) = pcAA-idp₀-idp₀-head pA\n pcAA-prepend-idp₀ (pc-aba d pc pA) = pcAB-prepend-idp₀ pc |in-ctx λ c → c-aba d c pA\n pcAB-prepend-idp₀ (pc-aab d pc pA) = pcAA-prepend-idp₀ pc |in-ctx λ c → c-aab d c pA\n\n transp-cAA-l : ∀ d {a₀ a₁} (p : f (h d) == a₀) (pcAA : precodeAA (f (h d)) a₁)\n → transport (λ x → codeAA x a₁) p q[ pcAA ] == q[ pcAA-prepend d [ ! p ] pcAA ]\n transp-cAA-l d idp pcAA = ! $ pcAA-prepend-idp₀ pcAA\n\n transp-cAB-l : ∀ d {a₀ b₁} (p : f (h d) == a₀) (pcAB : precodeAB (f (h d)) b₁)\n → transport (λ x → codeAB x b₁) p q[ pcAB ] == q[ pcAB-prepend d [ ! p ] pcAB ]\n transp-cAB-l d idp pcAB = ! $ pcAB-prepend-idp₀ pcAB\n\n transp-cAA-r : ∀ d {a₀ a₁} (p : f (h d) == a₁) (pcAA : precodeAA a₀ (f (h d)))\n → transport (λ x → codeAA a₀ x) p q[ pcAA ] == q[ pcAA aa⟦ d ⟧b idp₀ ab⟦ d ⟧a [ p ] ]\n transp-cAA-r d idp pcAA = ! $ quot-rel $ pcAAr-idp₀-idp₀ pcAA\n\n transp-cAB-r : ∀ d {a₀ b₁} (p : g (h d) == b₁) (pcAB : precodeAB a₀ (g (h d)))\n → transport (λ x → codeAB a₀ x) p q[ pcAB ] == q[ pcAB ab⟦ d ⟧a idp₀ aa⟦ d ⟧b [ p ] ]\n transp-cAB-r d idp pcAB = ! $ quot-rel $ pcABr-idp₀-idp₀ pcAB\n\n module CodeAAEquivCodeAB (a₀ : A) where\n\n eqv-on-image : (d : D) → codeAA a₀ (f (h d)) ≃ codeAB a₀ (g (h d))\n eqv-on-image d = equiv to from to-from from-to where\n to = λ c → c-aab d c idp₀\n from = λ c → c-aba d c idp₀\n\n abstract\n from-to : ∀ cAA → from (to cAA) == cAA\n from-to = SetQuot-elim\n (λ _ → =-preserves-set SetQuot-is-set)\n (λ pcAA → quot-rel (pcAAr-idp₀-idp₀ pcAA))\n (λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))\n\n to-from : ∀ cAB → to (from cAB) == cAB\n to-from = SetQuot-elim\n (λ _ → =-preserves-set SetQuot-is-set)\n (λ pcAB → quot-rel (pcABr-idp₀-idp₀ pcAB))\n (λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))\n\n abstract\n eqv-is-const : ∀ d₁ d₂ (p : h d₁ == h d₂)\n → eqv-on-image d₁ == eqv-on-image d₂\n [ (λ c → codeAA a₀ (f c) ≃ codeAB a₀ (g c)) ↓ p ]\n eqv-is-const d₁ d₂ p = ↓-Subtype-in (λ d → is-equiv-prop) $\n ↓-→-from-transp $ λ= $\n SetQuot-elim (λ _ → =-preserves-set SetQuot-is-set)\n (λ pcAA →\n transport (λ c → codeAB a₀ (g c)) p q[ pcAA aa⟦ d₁ ⟧b idp₀ ]\n =⟨ ap-∘ (codeAB a₀) g p |in-ctx (λ p → coe p q[ pcAA aa⟦ d₁ ⟧b idp₀ ]) ⟩\n transport (codeAB a₀) (ap g p) q[ pcAA aa⟦ d₁ ⟧b idp₀ ]\n =⟨ transp-cAB-r d₁ (ap g p) (pcAA aa⟦ d₁ ⟧b idp₀) ⟩\n q[ pcAA aa⟦ d₁ ⟧b idp₀ ab⟦ d₁ ⟧a idp₀ aa⟦ d₁ ⟧b [ ap g p ] ]\n =⟨ ! $ quot-rel $ pcABr-switch (pcAA aa⟦ d₁ ⟧b idp₀) [ p ] ⟩\n q[ pcAA aa⟦ d₁ ⟧b idp₀ ab⟦ d₁ ⟧a [ ap f p ] aa⟦ d₂ ⟧b idp₀ ]\n =⟨ ! $ transp-cAA-r d₁ (ap f p) pcAA |in-ctx (λ c → c-aab d₂ c idp₀) ⟩\n c-aab d₂ (transport (codeAA a₀) (ap f p) q[ pcAA ]) idp₀\n =⟨ ∘-ap (codeAA a₀) f p |in-ctx (λ p → coe p q[ pcAA ]) |in-ctx (λ c → c-aab d₂ c idp₀) ⟩\n c-aab d₂ (transport (λ c → codeAA a₀ (f c)) p q[ pcAA ]) idp₀\n =∎)\n (λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))\n\n module SE = SurjExt\n (λ c → ≃-is-set SetQuot-is-set SetQuot-is-set)\n h h-is-surj\n eqv-on-image\n eqv-is-const\n\n abstract\n eqv : ∀ c → codeAA a₀ (f c) ≃ codeAB a₀ (g c)\n eqv = SE.ext\n\n eqv-β : ∀ d → eqv (h d) == eqv-on-image d\n eqv-β = SE.β\n\n module CodeAP (a₀ : A) = PushoutRec (codeAA a₀) (codeAB a₀)\n (ua ∘ CodeAAEquivCodeAB.eqv a₀)\n\n codeAP : A → Pushout span → Type (lmax (lmax (lmax i j) k) l)\n codeAP = CodeAP.f\n\n abstract\n codeAP-level : ∀ {a₀ p₁} → is-set (codeAP a₀ p₁)\n codeAP-level {a₀} {p₁} = Pushout-elim\n {P = λ p₁ → is-set (codeAP a₀ p₁)}\n (λ a₁ → SetQuot-is-set)\n (λ b₁ → SetQuot-is-set)\n (λ c₁ → prop-has-all-paths-↓ is-set-is-prop)\n p₁\n codeAP-is-set = codeAP-level\n\n abstract\n transp-cAP-glue : ∀ {a₀} d₁ (pcAA : precodeAA a₀ (f (h d₁)))\n → transport (codeAP a₀) (glue (h d₁)) q[ pcAA ] == q[ pcAA aa⟦ d₁ ⟧b idp₀ ]\n transp-cAP-glue {a₀} d₁ pcAA =\n transport (codeAP a₀) (glue (h d₁)) q[ pcAA ]\n =⟨ ap (λ e → coe e q[ pcAA ]) (CodeAP.glue-β a₀ (h d₁) ∙ ap ua (CodeAAEquivCodeAB.eqv-β a₀ d₁)) ⟩\n coe (ua (CodeAAEquivCodeAB.eqv-on-image a₀ d₁)) q[ pcAA ]\n =⟨ coe-β (CodeAAEquivCodeAB.eqv-on-image a₀ d₁) q[ pcAA ] ⟩\n q[ pcAA aa⟦ d₁ ⟧b idp₀ ]\n =∎\n\n transp-cAP-!glue : ∀ {a₀} d₁ (pcAB : precodeAB a₀ (g (h d₁)))\n → transport (codeAP a₀) (! (glue (h d₁))) q[ pcAB ] == q[ pcAB ab⟦ d₁ ⟧a idp₀ ]\n transp-cAP-!glue {a₀} d₁ pcAB =\n transport (codeAP a₀) (! (glue (h d₁))) q[ pcAB ]\n =⟨ ap (λ e → coe e q[ pcAB ]) (ap-! (codeAP a₀) (glue (h d₁)))\n ∙ coe-! (ap (codeAP a₀) (glue (h d₁))) q[ pcAB ] ⟩\n transport! (codeAP a₀) (glue (h d₁)) q[ pcAB ]\n =⟨ ap (λ e → coe! e q[ pcAB ]) (CodeAP.glue-β a₀ (h d₁) ∙ ap ua (CodeAAEquivCodeAB.eqv-β a₀ d₁)) ⟩\n coe! (ua (CodeAAEquivCodeAB.eqv-on-image a₀ d₁)) q[ pcAB ]\n =⟨ coe!-β (CodeAAEquivCodeAB.eqv-on-image a₀ d₁) q[ pcAB ] ⟩\n q[ pcAB ab⟦ d₁ ⟧a idp₀ ]\n =∎\n\n -- code to path\n pcAA-to-path : ∀ {a₀ a₁} → precodeAA a₀ a₁ → left a₀ =₀ left a₁ :> Pushout span\n pcAB-to-path : ∀ {a₀ b₁} → precodeAB a₀ b₁ → left a₀ =₀ right b₁ :> Pushout span\n pcAA-to-path (pc-a pA) = ap₀ left pA\n pcAA-to-path (pc-aba d pc pA) = pcAB-to-path pc ∙₀' !₀ [ glue (h d) ] ∙₀' ap₀ left pA\n pcAB-to-path (pc-aab d pc pB) = pcAA-to-path pc ∙₀' [ glue (h d) ] ∙₀' ap₀ right pB\n\n abstract\n pcAA-to-path-rel : ∀ {a₀ a₁} {pcAA₀ pcAA₁ : precodeAA a₀ a₁}\n → precodeAA-rel pcAA₀ pcAA₁ → pcAA-to-path pcAA₀ == pcAA-to-path pcAA₁\n pcAB-to-path-rel : ∀ {a₀ b₁} {pcAB₀ pcAB₁ : precodeAB a₀ b₁}\n → precodeAB-rel pcAB₀ pcAB₁ → pcAB-to-path pcAB₀ == pcAB-to-path pcAB₁\n pcAA-to-path-rel (pcAAr-idp₀-idp₀ pcAA) =\n ∙₀'-assoc (pcAA-to-path pcAA) [ glue (h _) ] [ ! (glue (h _)) ]\n ∙ ap (λ p → pcAA-to-path pcAA ∙₀' [ p ]) (!-inv'-r (glue (h _)))\n ∙ ∙₀'-unit-r (pcAA-to-path pcAA)\n pcAA-to-path-rel (pcAAr-cong pcAB pA) = pcAB-to-path-rel pcAB |in-ctx _∙₀' !₀ [ glue (h _) ] ∙₀' ap₀ left pA\n pcAB-to-path-rel (pcABr-idp₀-idp₀ pcAB) =\n ∙₀'-assoc (pcAB-to-path pcAB) [ ! (glue (h _)) ] [ glue (h _) ]\n ∙ ap (λ p → pcAB-to-path pcAB ∙₀' [ p ]) (!-inv'-l (glue (h _)))\n ∙ ∙₀'-unit-r (pcAB-to-path pcAB)\n pcAB-to-path-rel (pcABr-switch pcAB pC) =\n ap (_∙₀' [ glue (h _) ]) (! (∙₀'-assoc (pcAB-to-path pcAB) [ ! (glue (h _)) ] (ap₀ left (ap₀ f pC))))\n ∙ ∙₀'-assoc (pcAB-to-path pcAB ∙₀' [ ! (glue (h _)) ]) (ap₀ left (ap₀ f pC)) [ glue (h _) ]\n ∙ ap ((pcAB-to-path pcAB ∙₀' [ ! (glue (h _)) ]) ∙₀'_) (natural₀ pC)\n where\n natural : ∀ {c₀ c₁} (p : c₀ == c₁)\n → (ap left (ap f p) ∙' glue c₁) == (glue c₀ ∙' ap right (ap g p))\n :> (left (f c₀) == right (g c₁) :> Pushout span)\n natural idp = ∙'-unit-l (glue _)\n\n natural₀ : ∀ {c₀ c₁} (p : c₀ =₀ c₁)\n → (ap₀ left (ap₀ f p) ∙₀' [ glue c₁ ]) == ([ glue c₀ ] ∙₀' ap₀ right (ap₀ g p))\n :> (left (f c₀) =₀ right (g c₁) :> Pushout span)\n natural₀ = Trunc-elim (λ _ → =-preserves-set Trunc-level) (ap [_] ∘ natural)\n pcAB-to-path-rel (pcABr-cong pcAA pB) = pcAA-to-path-rel pcAA |in-ctx _∙₀' [ glue (h _) ] ∙₀' ap₀ right pB\n\n decodeAA : ∀ {a₀ a₁} → codeAA a₀ a₁ → left a₀ =₀ left a₁ :> Pushout span\n decodeAB : ∀ {a₀ b₁} → codeAB a₀ b₁ → left a₀ =₀ right b₁ :> Pushout span\n decodeAA = SetQuot-rec Trunc-level pcAA-to-path pcAA-to-path-rel\n decodeAB = SetQuot-rec Trunc-level pcAB-to-path pcAB-to-path-rel\n\n abstract\n decodeAA-is-decodeAB : ∀ {a₀} c₁ →\n decodeAA {a₀} {f c₁} == decodeAB {a₀} {g c₁}\n [ (λ p₁ → codeAP a₀ p₁ → left a₀ =₀ p₁) ↓ glue c₁ ]\n decodeAA-is-decodeAB {a₀ = a₀} = SurjExt.ext\n (λ _ → ↓-preserves-level $ Π-is-set λ _ → Trunc-level) h h-is-surj\n (λ d₁ → ↓-→-from-transp $ λ= $ SetQuot-elim\n {P = λ cAA → transport (left a₀ =₀_) (glue (h d₁)) (decodeAA cAA)\n == decodeAB (transport (codeAP a₀) (glue (h d₁)) cAA)}\n (λ _ → =-preserves-set Trunc-level)\n (λ pcAA →\n transport (left a₀ =₀_) (glue (h d₁)) (pcAA-to-path pcAA)\n =⟨ transp₀-cst=₀idf [ glue (h d₁) ] (pcAA-to-path pcAA) ⟩\n pcAA-to-path pcAA ∙₀' [ glue (h d₁) ]\n =⟨ ! $ ap (λ e → decodeAB (–> e q[ pcAA ])) (CodeAAEquivCodeAB.eqv-β a₀ d₁) ⟩\n decodeAB (–> (CodeAAEquivCodeAB.eqv a₀ (h d₁)) q[ pcAA ])\n =⟨ ! $ ap decodeAB (coe-β (CodeAAEquivCodeAB.eqv a₀ (h d₁)) q[ pcAA ]) ⟩\n decodeAB (coe (ua (CodeAAEquivCodeAB.eqv a₀ (h d₁))) q[ pcAA ])\n =⟨ ! $ ap (λ p → decodeAB (coe p q[ pcAA ])) (CodeAP.glue-β a₀ (h d₁)) ⟩\n decodeAB (transport (codeAP a₀) (glue (h d₁)) q[ pcAA ])\n =∎)\n (λ _ → prop-has-all-paths-↓ $ Trunc-level {n = 0} _ _))\n (λ _ _ _ → prop-has-all-paths-↓ $ ↓-level $ Π-is-set λ _ → Trunc-level)\n\n decodeAP : ∀ {a₀ p₁} → codeAP a₀ p₁ → left a₀ =₀ p₁\n decodeAP {p₁ = p₁} = Pushout-elim\n (λ a₁ → decodeAA) (λ b₁ → decodeAB)\n decodeAA-is-decodeAB\n p₁\n", "meta": {"hexsha": "9131de1c9617bb44170c717ee9a533ef39130001", "size": 12875, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/vankampen/CodeAP.agda", "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/homotopy/vankampen/CodeAP.agda", "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/homotopy/vankampen/CodeAP.agda", "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "avg_line_length": 47.6851851852, "max_line_length": 112, "alphanum_fraction": 0.5404271845, "num_tokens": 5715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.38614009518822395}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\n\n{- Useful lemmas for computing the effect of transporting a function\n - across an equivalence in the domain or codomain.\n - TODO move these lemmas into lib.types.Pi or lib.types.PointedPi -}\n\n-- XXX Naming convensions?\n\nmodule stash.homotopy.FunctionOver where\n\n{- transporting a ptd function along a equivalence or path in the domain -}\nmodule _ {i} {j} {Y : Ptd i} {Z : Ptd j} (g : Y ⊙→ Z) where\n\n domain-over-⊙path : {X : Ptd i} (p : de⊙ X == de⊙ Y)\n (q : coe p (pt X) == pt Y)\n → g ⊙∘ (coe p , q) == g [ (λ W → W ⊙→ Z) ↓ ptd= p (↓-idf-in p q) ]\n domain-over-⊙path idp idp = idp\n\n domain-over-⊙equiv : {X : Ptd i} (e : X ⊙≃ Y)\n → g ⊙∘ ⊙–> e == g [ (λ W → W ⊙→ Z) ↓ ⊙ua e ]\n domain-over-⊙equiv {X = X} e =\n ap (λ w → g ⊙∘ w) (! $ ⊙λ= (coe-β (⊙≃-to-≃ e)) (↓-idf=cst-in idp))\n ◃ domain-over-⊙path (ua (⊙≃-to-≃ e))\n (coe-β (⊙≃-to-≃ e) (pt X) ∙ snd (⊙–> e))\n\nmodule _ {i} {j} {X : Ptd i} {Z : Ptd j} (f : X ⊙→ Z) where\n\n domain!-over-⊙path : {Y : Ptd i} (p : de⊙ X == de⊙ Y)\n (q : coe p (pt X) == pt Y)\n → f == f ⊙∘ (coe! p , ap (coe! p) (! q) ∙ coe!-inv-l p (pt X))\n [ (λ W → W ⊙→ Z) ↓ ptd= p (↓-idf-in p q) ]\n domain!-over-⊙path idp idp = idp\n\n domain!-over-⊙equiv : {Y : Ptd i} (e : X ⊙≃ Y)\n → f == f ⊙∘ (⊙<– e) [ (λ W → W ⊙→ Z) ↓ ⊙ua e ]\n domain!-over-⊙equiv {Y = Y} e =\n (! (ap (λ w → f ⊙∘ w) (⊙<–-inv-l e)) ∙ ! (⊙∘-assoc f _ (⊙–> e)))\n ◃ domain-over-⊙equiv (f ⊙∘ (⊙<– e)) e\n\n{- transporting a ptd function along a equivalence or path in the codomain -}\nmodule _ {i} {j} {X : Ptd i} {Y : Ptd j} (f : X ⊙→ Y) where\n\n codomain-over-⊙path : {Z : Ptd j} (p : de⊙ Y == de⊙ Z)\n (q : coe p (pt Y) == pt Z)\n → f == (coe p , q) ⊙∘ f [ (λ W → X ⊙→ W) ↓ ptd= p (↓-idf-in p q) ]\n codomain-over-⊙path idp idp = pair= idp (! (∙-unit-r _ ∙ ap-idf (snd f)))\n\n codomain-over-⊙equiv : {Z : Ptd j} (e : Y ⊙≃ Z)\n → f == (⊙–> e) ⊙∘ f [ (λ W → X ⊙→ W) ↓ ⊙ua e ]\n codomain-over-⊙equiv {Z = Z} e =\n codomain-over-⊙path (ua (⊙≃-to-≃ e))\n (coe-β (⊙≃-to-≃ e) (pt Y) ∙ snd (⊙–> e))\n ▹ ap (λ w → w ⊙∘ f) (⊙λ= (coe-β (⊙≃-to-≃ e)) (↓-idf=cst-in idp))\n\nmodule _ {i} {j} {X : Ptd i} {Z : Ptd j} (g : X ⊙→ Z) where\n\n codomain!-over-⊙path : {Y : Ptd j} (p : de⊙ Y == de⊙ Z)\n (q : coe p (pt Y) == pt Z)\n → (coe! p , ap (coe! p) (! q) ∙ coe!-inv-l p (pt Y)) ⊙∘ g == g\n [ (λ W → X ⊙→ W) ↓ ptd= p (↓-idf-in p q) ]\n codomain!-over-⊙path idp idp = pair= idp (∙-unit-r _ ∙ ap-idf (snd g))\n\n codomain!-over-⊙equiv : {Y : Ptd j} (e : Y ⊙≃ Z)\n → (⊙<– e) ⊙∘ g == g [ (λ W → X ⊙→ W) ↓ ⊙ua e ]\n codomain!-over-⊙equiv {Y = Y} e =\n codomain-over-⊙equiv (⊙<– e ⊙∘ g) e\n ▹ ! (⊙∘-assoc (⊙–> e) _ g) ∙ ap (λ w → w ⊙∘ g) (⊙<–-inv-r e) ∙ ⊙∘-unit-l g\n\n{- transporting a group homomorphism along an isomorphism -}\n\ndomain-over-iso : ∀ {i j} {G H : Group i} {K : Group j}\n {φ : G →ᴳ H} {ie : is-equiv (GroupHom.f φ)} {ψ : G →ᴳ K} {χ : H →ᴳ K}\n → GroupHom.f ψ == GroupHom.f χ\n [ (λ A → A → Group.El K) ↓ ua (GroupHom.f φ , ie) ]\n → ψ == χ [ (λ J → J →ᴳ K) ↓ uaᴳ (φ , ie) ]\ndomain-over-iso {K = K} {φ = φ} {ie} {ψ} {χ} p =\n group-hom=-↓ $ ↓-ap-out _ Group.El _ $\n transport\n (λ q → GroupHom.f ψ == GroupHom.f χ [ (λ A → A → Group.El K) ↓ q ])\n (! (El=-β (φ , ie)))\n p\n\ncodomain-over-iso : ∀ {i j} {G : Group i} {H K : Group j}\n {φ : H →ᴳ K} {ie : is-equiv (GroupHom.f φ)} {ψ : G →ᴳ H} {χ : G →ᴳ K}\n → GroupHom.f ψ == GroupHom.f χ\n [ (λ A → Group.El G → A) ↓ ua (GroupHom.f φ , ie) ]\n → ψ == χ [ (λ J → G →ᴳ J) ↓ uaᴳ (φ , ie) ]\ncodomain-over-iso {G = G} {φ = φ} {ie} {ψ} {χ} p =\n group-hom=-↓ $ ↓-ap-out _ Group.El _ $\n transport\n (λ q → GroupHom.f ψ == GroupHom.f χ [ (λ A → Group.El G → A) ↓ q ])\n (! (El=-β (φ , ie)))\n p\n", "meta": {"hexsha": "3cb460e53fc8f712970094746760d6121d2f75b5", "size": 3788, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/stash/homotopy/FunctionOver.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/stash/homotopy/FunctionOver.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/stash/homotopy/FunctionOver.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 39.4583333333, "max_line_length": 78, "alphanum_fraction": 0.4662090813, "num_tokens": 1869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548646660543, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.3860362730051737}} {"text": "open import Coinduction using ( ∞ ; ♯_ ; ♭ )\nopen import Data.Product using ( _,_ )\nopen import FRP.LTL.ISet.Core using ( ISet ; M⟦_⟧ ; splitM⟦_⟧ ; ⟦_⟧ ; ⌈_⌉ ; [_] )\nopen import FRP.LTL.ISet.Product using ( _∧_ )\nopen import FRP.LTL.ISet.Stateless using ( _⇒_ )\nopen import FRP.LTL.Time.Bound using ( Time∞ ; fin ; +∞ ; _≼_ ; _≺_ ; ≼-refl ; ≺-impl-≼ ; ≺-impl-⋡ ; _≺-trans_ ; _≼-case_ ; lt ; eq ; gt ; t≺+∞ )\nopen import FRP.LTL.Time.Interval using ( [_⟩ )\nopen import FRP.LTL.Util using ( ⊥-elim ; ≡-relevant )\nopen import Relation.Binary.PropositionalEquality using ( _≡_ ; refl )\n\nmodule FRP.LTL.ISet.Decoupled where\n\ndata _∙_⊷_∙_ (A : ISet) (s : Time∞) (B : ISet) (u : Time∞) : Set where\n inp : .(s ≺ u) → .(u ≺ +∞) → \n (∀ {t} .(s≺t : s ≺ t) → M⟦ A ⟧ [ s≺t ⟩ → ∞ (A ∙ t ⊷ B ∙ u)) → \n (A ∙ s ⊷ B ∙ u)\n out : ∀ {v} .(u≺v : u ≺ v) → \n M⟦ B ⟧ [ u≺v ⟩ → ∞ (A ∙ s ⊷ B ∙ v) → \n (A ∙ s ⊷ B ∙ u)\n done : .(u ≡ +∞) → \n (A ∙ s ⊷ B ∙ u)\n\n_▹_ : ISet → ISet → ISet\nA ▹ B = ⌈ (λ t → A ∙ fin t ⊷ B ∙ fin t) ⌉\n\n_/_/_ : ∀ {A B s t u} → (A ∙ s ⊷ B ∙ u) → .(s≺t : s ≺ t) → M⟦ A ⟧ [ s≺t ⟩ → (A ∙ t ⊷ B ∙ u)\ninp s≺u u≺∞ P / s≺t / σ = ♭ (P s≺t σ)\nout u≺v τ P / s≺t / σ = out u≺v τ (♯ (♭ P / s≺t / σ))\ndone u≡∞ / s≺t / σ = done u≡∞\n\nmutual\n\n ≻-tr : ∀ {A B C s u} .(s≻u : u ≺ s) → M⟦ B ⟧ [ s≻u ⟩ → \n ((A ∧ B) ∙ u ⊷ (A ∧ C) ∙ u) → (B ∙ s ⊷ C ∙ u)\n ≻-tr s≻u σ (inp u≺u u≺∞ P) = ⊥-elim (≺-impl-⋡ u≺u ≼-refl)\n ≻-tr {A} {B} {C} {s} {u} s≻u σ (out {v} u≺v [ ρ , τ ] P) \n with s ≼-case v\n ≻-tr {A} {B} {C} s≻u σ (out u≺v [ ρ , τ ] P) | lt s≺v \n with splitM⟦ A ⟧ [ s≻u ⟩ [ s≺v ⟩ refl ρ \n ≻-tr {A} {B} {C} s≻u σ (out u≺v [ ρ , τ ] P) | lt s≺v | (ρ₁ , ρ₂) = \n out u≺v τ (♯ ≺-tr s≺v ρ₂ (♭ P / s≻u / [ ρ₁ , σ ]))\n ≻-tr {A} {B} {C} s≻u σ (out u≺v [ ρ , τ ] P) | eq s≡v \n with ≡-relevant s≡v\n ≻-tr {A} {B} {C} s≻u σ (out u≺v [ ρ , τ ] P) | eq s≡v | refl =\n out u≺v τ (♯ tr (♭ P / s≻u / [ ρ , σ ]))\n ≻-tr {A} {B} {C} s≻u σ (out u≺v [ ρ , τ ] P) | gt s≻v \n with splitM⟦ B ⟧ [ u≺v ⟩ [ s≻v ⟩ refl σ\n ≻-tr {A} {B} {C} s≻u σ (out u≺v [ ρ , τ ] P) | gt s≻v | (σ₁ , σ₂) = \n out u≺v τ (♯ ≻-tr s≻v σ₂ (♭ P / u≺v / [ ρ , σ₁ ]))\n ≻-tr s≻u σ (done u≡∞) = done u≡∞\n\n ≺-tr : ∀ {A B C s u} .(s≺u : s ≺ u) → M⟦ A ⟧ [ s≺u ⟩ → \n ((A ∧ B) ∙ s ⊷ (A ∧ C) ∙ u) → (B ∙ s ⊷ C ∙ u)\n ≺-tr {A} {B} {C} {s} {+∞} s≺u ρ P = done refl\n ≺-tr {A} {B} {C} {s} {fin u} s≺u ρ P = inp s≺u t≺+∞ Q where\n\n Q : ∀ {t} .(s≺t : s ≺ t) → M⟦ B ⟧ [ s≺t ⟩ → ∞ (B ∙ t ⊷ C ∙ fin u)\n Q {t} s≺t σ with t ≼-case (fin u)\n Q s≺t σ | lt t≺u with splitM⟦ _ ⟧ [ s≺t ⟩ [ t≺u ⟩ refl ρ\n Q s≺t σ | lt t≺u | (ρ₁ , ρ₂) = ♯ ≺-tr t≺u ρ₂ (P / s≺t / [ ρ₁ , σ ])\n Q s≺t σ | eq t≡u with ≡-relevant t≡u\n Q s≺t σ | eq t≡u | refl = ♯ tr (P / s≺u / [ ρ , σ ])\n Q s≺t σ | gt t≻u with splitM⟦ _ ⟧ [ s≺u ⟩ [ t≻u ⟩ refl σ\n Q s≺t σ | gt t≻u | (σ₁ , σ₂) = ♯ (≻-tr t≻u σ₂ (P / s≺u / [ ρ , σ₁ ]))\n\n tr : ∀ {A B C s} → ((A ∧ B) ∙ s ⊷ (A ∧ C) ∙ s) → (B ∙ s ⊷ C ∙ s)\n tr (inp s≺s s≺∞ P) = ⊥-elim (≺-impl-⋡ s≺s ≼-refl)\n tr (out s≺u [ ρ , τ ] P) = out s≺u τ (♯ ≺-tr s≺u ρ (♭ P))\n tr (done s≡∞) = done s≡∞\n\nloop : ∀ {A B C} → ⟦ ((A ∧ B) ▹ (A ∧ C)) ⇒ (B ▹ C) ⟧\nloop [ [ f ] ] = [ (λ t t∈i → tr (f t t∈i)) ]", "meta": {"hexsha": "98024255a47e4145e0eb0876b8ed550b653c1568", "size": 3202, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/FRP/LTL/ISet/Decoupled.agda", "max_stars_repo_name": "agda/agda-frp-ltl", "max_stars_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-07-02T20:25:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-15T02:51:13.000Z", "max_issues_repo_path": "src/FRP/LTL/ISet/Decoupled.agda", "max_issues_repo_name": "agda/agda-frp-ltl", "max_issues_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-03-01T07:01:31.000Z", "max_issues_repo_issues_event_max_datetime": "2015-03-02T15:23:53.000Z", "max_forks_repo_path": "src/FRP/LTL/ISet/Decoupled.agda", "max_forks_repo_name": "agda/agda-frp-ltl", "max_forks_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-03-01T07:33:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:04.000Z", "avg_line_length": 44.4722222222, "max_line_length": 146, "alphanum_fraction": 0.3975640225, "num_tokens": 1957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3859217489195373}} {"text": "module Syntax where\n\nopen import Stack public\n\n\n-- Abstract symbols, or atoms.\n\nabstract\n Atom : Set\n Atom = Nat\n\n\n-- Types, or propositions in constructive logic.\n\ninfixl 9 _⩕_\ninfixr 7 _⇒_\ndata Type : Set where\n α_ : Atom → Type\n _⇒_ : Type → Type → Type\n _⩕_ : Type → Type → Type\n ⫪ : Type\n\n\n-- Contexts, or stacks of types.\n\nContext : Set\nContext = Stack Type\n\n\n-- Derivations, or syntactic entailment.\n\ninfix 3 _⊢_\ndata _⊢_ : Context → Type → Set where\n var : ∀ {A Γ} → A ∈ Γ → Γ ⊢ A\n lam : ∀ {A B Γ} → Γ , A ⊢ B → Γ ⊢ A ⇒ B\n app : ∀ {A B Γ} → Γ ⊢ A ⇒ B → Γ ⊢ A → Γ ⊢ B\n pair : ∀ {A B Γ} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ⩕ B\n fst : ∀ {A B Γ} → Γ ⊢ A ⩕ B → Γ ⊢ A\n snd : ∀ {A B Γ} → Γ ⊢ A ⩕ B → Γ ⊢ B\n unit : ∀ {Γ} → Γ ⊢ ⫪\n\n\n-- Shorthand for variables.\n\nv₀ : ∀ {A Γ} → Γ , A ⊢ A\nv₀ = var i₀\n\nv₁ : ∀ {A B Γ} → Γ , A , B ⊢ A\nv₁ = var i₁\n\nv₂ : ∀ {A B C Γ} → Γ , A , B , C ⊢ A\nv₂ = var i₂\n\n\n-- Stacks of derivations, or simultaneous syntactic entailment.\n\ninfix 3 _⊢⋆_\n_⊢⋆_ : Context → Stack Type → Set\nΓ ⊢⋆ ∅ = ⊤\nΓ ⊢⋆ Ξ , A = Γ ⊢⋆ Ξ ∧ Γ ⊢ A\n\n\n-- Monotonicity of syntactic entailment with respect to context inclusion.\n\nmono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A\nmono⊢ p (var i) = var (mono∈ p i)\nmono⊢ p (lam d) = lam (mono⊢ (keep p) d)\nmono⊢ p (app d e) = app (mono⊢ p d) (mono⊢ p e)\nmono⊢ p (pair d e) = pair (mono⊢ p d) (mono⊢ p e)\nmono⊢ p (fst d) = fst (mono⊢ p d)\nmono⊢ p (snd d) = snd (mono⊢ p d)\nmono⊢ p unit = unit\n\nmono⊢⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ Ξ → Γ′ ⊢⋆ Ξ\nmono⊢⋆ {∅} p ∙ = ∙\nmono⊢⋆ {Ξ , A} p (ζ , d) = mono⊢⋆ p ζ , mono⊢ p d\n\n\n-- TODO: Naming things.\n\nidmono⊢ : ∀ {A Γ} → (d : Γ ⊢ A) → mono⊢ refl⊆ d ≡ d\nidmono⊢ (var {A} i) = cong var (idmono∈ i)\nidmono⊢ (lam d) = cong lam (idmono⊢ d)\nidmono⊢ (app d e) = cong² app (idmono⊢ d) (idmono⊢ e)\nidmono⊢ (pair d e) = cong² pair (idmono⊢ d) (idmono⊢ e)\nidmono⊢ (fst d) = cong fst (idmono⊢ d)\nidmono⊢ (snd d) = cong snd (idmono⊢ d)\nidmono⊢ unit = refl\n\nidmono⊢⋆ : ∀ {Ξ Γ} → (ζ : Γ ⊢⋆ Ξ) → mono⊢⋆ refl⊆ ζ ≡ ζ\nidmono⊢⋆ {∅} ∙ = refl\nidmono⊢⋆ {Ξ , A} (ζ , d) = cong² _,_ (idmono⊢⋆ ζ) (idmono⊢ d)\n\n\n-- Reflexivity of simultaneous syntactic entailment.\n\nrefl⊢⋆ : ∀ {Γ} → Γ ⊢⋆ Γ\nrefl⊢⋆ {∅} = ∙\nrefl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀\n\n\n-- Substitution.\n\n[_≔_]∈_ : ∀ {A C Γ} → (i : C ∈ Γ) → Γ ∖ i ⊢ C → A ∈ Γ → Γ ∖ i ⊢ A\n[ i ≔ c ]∈ j with i ≟∈ j\n[ i ≔ c ]∈ .i | same = c\n[ i ≔ c ]∈ ._ | diff j = var j\n\n[_≔_]_ : ∀ {A C Γ} → (i : C ∈ Γ) → Γ ∖ i ⊢ C → Γ ⊢ A → Γ ∖ i ⊢ A\n[ i ≔ c ] var j = [ i ≔ c ]∈ j\n[ i ≔ c ] lam d = lam ([ pop i ≔ mono⊢ weak⊆ c ] d)\n[ i ≔ c ] app d e = app ([ i ≔ c ] d) ([ i ≔ c ] e)\n[ i ≔ c ] pair d e = pair ([ i ≔ c ] d) ([ i ≔ c ] e)\n[ i ≔ c ] fst d = fst ([ i ≔ c ] d)\n[ i ≔ c ] snd d = snd ([ i ≔ c ] d)\n[ i ≔ c ] unit = unit\n\n\n-- Grafting of derivation trees, or simultaneous substitution, or cut.\n\ngraft∈ : ∀ {A Ξ Γ} → Γ ⊢⋆ Ξ → A ∈ Ξ → Γ ⊢ A\ngraft∈ (ζ , d) top = d\ngraft∈ (ζ , d) (pop i) = graft∈ ζ i\n\ngraft⊢ : ∀ {A Ξ Γ} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A\ngraft⊢ ζ (var i) = graft∈ ζ i\ngraft⊢ ζ (lam d) = lam (graft⊢ (mono⊢⋆ weak⊆ ζ , v₀) d)\ngraft⊢ ζ (app d e) = app (graft⊢ ζ d) (graft⊢ ζ e)\ngraft⊢ ζ (pair d e) = pair (graft⊢ ζ d) (graft⊢ ζ e)\ngraft⊢ ζ (fst d) = fst (graft⊢ ζ d)\ngraft⊢ ζ (snd d) = snd (graft⊢ ζ d)\ngraft⊢ ζ unit = unit\n\n\n-- Derivations, or syntactic entailment, in normal form.\n\nmutual\n infix 3 _⊢ⁿᶠ_\n data _⊢ⁿᶠ_ : Context → Type → Set where\n neⁿᶠ : ∀ {A Γ} → Γ ⊢ⁿᵉ A → Γ ⊢ⁿᶠ A\n lamⁿᶠ : ∀ {A B Γ} → Γ , A ⊢ⁿᶠ B → Γ ⊢ⁿᶠ A ⇒ B\n pairⁿᶠ : ∀ {A B Γ} → Γ ⊢ⁿᶠ A → Γ ⊢ⁿᶠ B → Γ ⊢ⁿᶠ A ⩕ B\n unitⁿᶠ : ∀ {Γ} → Γ ⊢ⁿᶠ ⫪\n\n infix 3 _⊢ⁿᵉ_\n data _⊢ⁿᵉ_ : Context → Type → Set where\n varⁿᵉ : ∀ {A Γ} → A ∈ Γ → Γ ⊢ⁿᵉ A\n appⁿᵉ : ∀ {A B Γ} → Γ ⊢ⁿᵉ A ⇒ B → Γ ⊢ⁿᶠ A → Γ ⊢ⁿᵉ B\n fstⁿᵉ : ∀ {A B Γ} → Γ ⊢ⁿᵉ A ⩕ B → Γ ⊢ⁿᵉ A\n sndⁿᵉ : ∀ {A B Γ} → Γ ⊢ⁿᵉ A ⩕ B → Γ ⊢ⁿᵉ B\n\n\n-- Shorthand for variables.\n\nv₀ⁿᵉ : ∀ {A Γ} → Γ , A ⊢ⁿᵉ A\nv₀ⁿᵉ = varⁿᵉ top\n\n\n-- Stacks of derivations, or simultaneous syntactic entailment, in normal form.\n\ninfix 3 _⊢⋆ⁿᵉ_\n_⊢⋆ⁿᵉ_ : Context → Stack Type → Set\nΓ ⊢⋆ⁿᵉ ∅ = ⊤\nΓ ⊢⋆ⁿᵉ Ξ , A = Γ ⊢⋆ⁿᵉ Ξ ∧ Γ ⊢ⁿᵉ A\n\n\n-- Translation from normal form to arbitrary form.\n\nmutual\n nf→af : ∀ {A Γ} → Γ ⊢ⁿᶠ A → Γ ⊢ A\n nf→af (neⁿᶠ d) = ne→af d\n nf→af (lamⁿᶠ d) = lam (nf→af d)\n nf→af (pairⁿᶠ d e) = pair (nf→af d) (nf→af e)\n nf→af unitⁿᶠ = unit\n\n ne→af : ∀ {A Γ} → Γ ⊢ⁿᵉ A → Γ ⊢ A\n ne→af (varⁿᵉ i) = var i\n ne→af (appⁿᵉ d e) = app (ne→af d) (nf→af e)\n ne→af (fstⁿᵉ d) = fst (ne→af d)\n ne→af (sndⁿᵉ d) = snd (ne→af d)\n\n\n-- Monotonicity of syntactic entailment with respect to context inclusion, in normal form.\n\nmutual\n mono⊢ⁿᶠ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ⁿᶠ A → Γ′ ⊢ⁿᶠ A\n mono⊢ⁿᶠ p (neⁿᶠ d) = neⁿᶠ (mono⊢ⁿᵉ p d)\n mono⊢ⁿᶠ p (lamⁿᶠ d) = lamⁿᶠ (mono⊢ⁿᶠ (keep p) d)\n mono⊢ⁿᶠ p (pairⁿᶠ d e) = pairⁿᶠ (mono⊢ⁿᶠ p d) (mono⊢ⁿᶠ p e)\n mono⊢ⁿᶠ p unitⁿᶠ = unitⁿᶠ\n\n mono⊢ⁿᵉ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ⁿᵉ A → Γ′ ⊢ⁿᵉ A\n mono⊢ⁿᵉ p (varⁿᵉ i) = varⁿᵉ (mono∈ p i)\n mono⊢ⁿᵉ p (appⁿᵉ d e) = appⁿᵉ (mono⊢ⁿᵉ p d) (mono⊢ⁿᶠ p e)\n mono⊢ⁿᵉ p (fstⁿᵉ d) = fstⁿᵉ (mono⊢ⁿᵉ p d)\n mono⊢ⁿᵉ p (sndⁿᵉ d) = sndⁿᵉ (mono⊢ⁿᵉ p d)\n\nmono⊢⋆ⁿᵉ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ⁿᵉ Ξ → Γ′ ⊢⋆ⁿᵉ Ξ\nmono⊢⋆ⁿᵉ {∅} p ∙ = ∙\nmono⊢⋆ⁿᵉ {Ξ , A} p (ζ , d) = mono⊢⋆ⁿᵉ p ζ , mono⊢ⁿᵉ p d\n\n\n-- TODO: Naming things.\n\nmutual\n idmono⊢ⁿᶠ : ∀ {A Γ} → (d : Γ ⊢ⁿᶠ A) → mono⊢ⁿᶠ refl⊆ d ≡ d\n idmono⊢ⁿᶠ (neⁿᶠ d) = cong neⁿᶠ (idmono⊢ⁿᵉ d)\n idmono⊢ⁿᶠ (lamⁿᶠ d) = cong lamⁿᶠ (idmono⊢ⁿᶠ d)\n idmono⊢ⁿᶠ (pairⁿᶠ d e) = cong² pairⁿᶠ (idmono⊢ⁿᶠ d) (idmono⊢ⁿᶠ e)\n idmono⊢ⁿᶠ unitⁿᶠ = refl\n\n idmono⊢ⁿᵉ : ∀ {A Γ} → (d : Γ ⊢ⁿᵉ A) → mono⊢ⁿᵉ refl⊆ d ≡ d\n idmono⊢ⁿᵉ (varⁿᵉ i) = cong varⁿᵉ (idmono∈ i)\n idmono⊢ⁿᵉ (appⁿᵉ d e) = cong² appⁿᵉ (idmono⊢ⁿᵉ d) (idmono⊢ⁿᶠ e)\n idmono⊢ⁿᵉ (fstⁿᵉ d) = cong fstⁿᵉ (idmono⊢ⁿᵉ d)\n idmono⊢ⁿᵉ (sndⁿᵉ d) = cong sndⁿᵉ (idmono⊢ⁿᵉ d)\n\nidmono⊢⋆ⁿᵉ : ∀ {Ξ Γ} → (ζ : Γ ⊢⋆ⁿᵉ Ξ) → mono⊢⋆ⁿᵉ refl⊆ ζ ≡ ζ\nidmono⊢⋆ⁿᵉ {∅} ∙ = refl\nidmono⊢⋆ⁿᵉ {Ξ , A} (ζ , d) = cong² _,_ (idmono⊢⋆ⁿᵉ ζ) (idmono⊢ⁿᵉ d)\n\n\n-- Reflexivity of simultaneous syntactic entailment, in normal form.\n\nrefl⊢⋆ⁿᵉ : ∀ {Γ} → Γ ⊢⋆ⁿᵉ Γ\nrefl⊢⋆ⁿᵉ {∅} = ∙\nrefl⊢⋆ⁿᵉ {Γ , A} = mono⊢⋆ⁿᵉ weak⊆ refl⊢⋆ⁿᵉ , v₀ⁿᵉ\n", "meta": {"hexsha": "3f4acfad961f1d1768d8544b1d9efffebbe7b43d", "size": 6302, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Syntax.agda", "max_stars_repo_name": "mietek/nbe-correctness", "max_stars_repo_head_hexsha": "54e9a83a8db4e33a33bf5dae5b2d651ad38aa3d5", "max_stars_repo_licenses": ["X11"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-03-23T06:25:23.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-23T18:51:34.000Z", "max_issues_repo_path": "src/Syntax.agda", "max_issues_repo_name": "mietek/nbe-correctness", "max_issues_repo_head_hexsha": "54e9a83a8db4e33a33bf5dae5b2d651ad38aa3d5", "max_issues_repo_licenses": ["X11"], "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/Syntax.agda", "max_forks_repo_name": "mietek/nbe-correctness", "max_forks_repo_head_hexsha": "54e9a83a8db4e33a33bf5dae5b2d651ad38aa3d5", "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": 27.6403508772, "max_line_length": 90, "alphanum_fraction": 0.4974611235, "num_tokens": 3898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850154599562, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.38587959505100855}} {"text": "{-# OPTIONS --safe #-}\n\nopen import Generics.Prelude\nopen import Generics.Telescope\nopen import Generics.Desc\nopen import Generics.HasDesc\nopen import Generics.All\n\nmodule Generics.Constructions.Mu\n {P I ℓ} (A : Indexed P I ℓ) (H : HasDesc A)\n (open HasDesc H)\n {p} where\n\nprivate\n variable\n V : ExTele P\n i : ⟦ I ⟧tel p\n v : ⟦ V ⟧tel p\n\nopen import Generics.Mu public\n\ntoData : (x : ⟦ D ⟧Data A′ (p , i)) → AllDataω Acc D x → μ D (p , i)\n\nto-wf : (x : A′ (p , i)) → Acc x → μ D (p , i)\nto-wf x (acc a) = toData (split x) a\n\ntoData (k , x) a = ⟨ k , toCon (lookupCon D k) x a ⟩\n where\n toIndArg : (C : ConDesc P V I)\n (x : ⟦ C ⟧IndArg A′ (p , v))\n → AllIndArgω Acc C x\n → ⟦ C ⟧IndArgω (μ D) (p , v)\n toIndArg (var _) x a = to-wf x a\n toIndArg (π ai _ C) x a s = toIndArg C (app< ai > x s) (a s)\n toIndArg (A ⊗ B) (xa , xb) (aa , ab)\n = toIndArg A xa aa , toIndArg B xb ab\n\n toCon : (C : ConDesc P V I)\n (x : ⟦ C ⟧Con A′ (p , v , i))\n → AllConω Acc C x\n → ⟦ C ⟧Conω (μ D) (p , v , i)\n toCon (var _) refl _ = liftω refl\n toCon (π _ _ C) (s , x) a = s , toCon C x a\n toCon (A ⊗ B) (xa , xb) (aa , ab)\n = toIndArg A xa aa , toCon B xb ab\n\nto : A′ (p , i) → μ D (p , i)\nto x = to-wf x (wf x)\n\n\nfrom : μ D (p , i) → A′ (p , i)\n\nfromIndArg : (C : ConDesc P V I)\n → ⟦ C ⟧IndArgω (μ D) (p , v)\n → ⟦ C ⟧IndArg A′ (p , v)\nfromIndArg (var _) x = from x\nfromIndArg (π ai S C) x = fun< ai > λ s → fromIndArg C (x s)\nfromIndArg (A ⊗ B) (xa , xb) = fromIndArg A xa , fromIndArg B xb\n\nfromCon : (C : ConDesc P V I)\n → ⟦ C ⟧Conω (μ D) (p , v , i)\n → ⟦ C ⟧Con A′ (p , v , i)\nfromCon (var _) (liftω refl) = refl\nfromCon (π _ S C) (s , x) = s , fromCon C x\nfromCon (A ⊗ B) (xa , xb) = fromIndArg A xa , fromCon B xb\n\nfrom ⟨ k , x ⟩ = constr (k , fromCon (lookupCon D k) x)\n", "meta": {"hexsha": "264b4d77b85dddc84f2b698eec009a3af17ff95a", "size": 1901, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Generics/Constructions/Mu.agda", "max_stars_repo_name": "flupe/generics", "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_issues_repo_path": "src/Generics/Constructions/Mu.agda", "max_issues_repo_name": "flupe/generics", "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_forks_repo_path": "src/Generics/Constructions/Mu.agda", "max_forks_repo_name": "flupe/generics", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "avg_line_length": 27.9558823529, "max_line_length": 68, "alphanum_fraction": 0.5113098369, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.737158174177441, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.3858435887492197}} {"text": "\nmodule Issue756a where\n\ndata Nat : Set where\n zero : Nat\n suc : Nat → Nat\n\ndata T : Nat → Set where\n [_] : ∀ n → T n\n\nbad : ∀ n → T n → Nat\nbad .zero [ zero ] = zero\nbad .(suc (let x = n in x)) [ suc n ] = zero\n", "meta": {"hexsha": "8ebfa597b3086f551ff9dce042f48826478e4a34", "size": 235, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue756a.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Issue756a.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Issue756a.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 16.7857142857, "max_line_length": 44, "alphanum_fraction": 0.4978723404, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.3857754329391083}} {"text": "{-# OPTIONS --without-K --exact-split --safe #-}\n\nopen import Fragment.Equational.Theory\n\nmodule Fragment.Equational.Model.Properties (Θ : Theory) where\n\nopen import Fragment.Equational.Model.Base Θ\nopen import Fragment.Equational.Model.Synthetic Θ\nopen import Fragment.Algebra.Homomorphism (Σ Θ)\nopen import Fragment.Algebra.Free (Σ Θ)\nopen import Fragment.Setoid.Morphism using (_↝_)\n\nopen import Level using (Level)\nopen import Function using (_∘_)\n\nopen import Data.Nat using (ℕ; zero; suc)\nopen import Data.Fin using (Fin; zero; suc; fromℕ)\nopen import Data.Vec using (Vec; []; _∷_; map)\nopen import Data.Product using (proj₁; proj₂)\nopen import Data.Vec.Relation.Binary.Pointwise.Inductive\n using (Pointwise; []; _∷_)\n\nopen import Relation.Binary using (Setoid)\nimport Relation.Binary.Reasoning.Setoid as Reasoning\n\nprivate\n variable\n a ℓ : Level\n\nmodule _ {n} (A : Model {a} {ℓ}) (θ : Env ∥ A ∥ₐ n) where\n\n private\n\n module S = Setoid ∥ A ∥/≈\n open Reasoning ∥ A ∥/≈\n\n mutual\n map-∣interp∣-cong : ∀ {m} {xs ys : Vec ∥ J n ∥ m}\n → Pointwise ≈[ J n ] xs ys\n → Pointwise ≈[ A ] (map ∣ inst ∥ A ∥ₐ θ ∣ xs)\n (map ∣ inst ∥ A ∥ₐ θ ∣ ys)\n map-∣interp∣-cong [] = []\n map-∣interp∣-cong (p ∷ ps) = ∣interp∣-cong p ∷ map-∣interp∣-cong ps\n\n ∣interp∣-cong : Congruent ≈[ J n ] ≈[ A ] ∣ inst ∥ A ∥ₐ θ ∣\n ∣interp∣-cong refl = S.refl\n ∣interp∣-cong (sym p) = S.sym (∣interp∣-cong p)\n ∣interp∣-cong (trans p q) = S.trans (∣interp∣-cong p) (∣interp∣-cong q)\n ∣interp∣-cong (inherit p) = ∣ inst ∥ A ∥ₐ θ ∣-cong p\n ∣interp∣-cong (cong f {xs = xs} {ys = ys} ps) = begin\n ∣ inst ∥ A ∥ₐ θ ∣ (term f xs)\n ≈⟨ S.sym (∣ inst ∥ A ∥ₐ θ ∣-hom f xs) ⟩\n A ⟦ f ⟧ (map ∣ inst ∥ A ∥ₐ θ ∣ xs)\n ≈⟨ (A ⟦ f ⟧-cong) (map-∣interp∣-cong ps) ⟩\n A ⟦ f ⟧ (map ∣ inst ∥ A ∥ₐ θ ∣ ys)\n ≈⟨ ∣ inst ∥ A ∥ₐ θ ∣-hom f ys ⟩\n ∣ inst ∥ A ∥ₐ θ ∣ (term f ys)\n ∎\n ∣interp∣-cong (axiom eq θ') = begin\n ∣ inst ∥ A ∥ₐ θ ∣ (∣ inst (F n) θ' ∣ lhs)\n ≈⟨ inst-assoc (F n) θ' (inst ∥ A ∥ₐ θ) {x = lhs} ⟩\n ∣ inst ∥ A ∥ₐ (∣ inst ∥ A ∥ₐ θ ∣ ∘ θ') ∣ lhs\n ≈⟨ ∥ A ∥ₐ-models eq _ ⟩\n ∣ inst ∥ A ∥ₐ (∣ inst ∥ A ∥ₐ θ ∣ ∘ θ') ∣ rhs\n ≈⟨ S.sym (inst-assoc (F n) θ' (inst ∥ A ∥ₐ θ) {x = rhs}) ⟩\n ∣ inst ∥ A ∥ₐ θ ∣ (∣ inst (F n) θ' ∣ rhs)\n ∎\n where lhs = proj₁ (Θ ⟦ eq ⟧ₑ)\n rhs = proj₂ (Θ ⟦ eq ⟧ₑ)\n\n ∣interp∣⃗ : ∥ J n ∥/≈ ↝ ∥ A ∥/≈\n ∣interp∣⃗ = record { ∣_∣ = ∣ inst ∥ A ∥ₐ θ ∣\n ; ∣_∣-cong = ∣interp∣-cong\n }\n\n interp : ∥ J n ∥ₐ ⟿ ∥ A ∥ₐ\n interp = record { ∣_∣⃗ = ∣interp∣⃗\n ; ∣_∣-hom = ∣ inst ∥ A ∥ₐ θ ∣-hom\n }\n\natomise : (n : ℕ) → ∥ J (suc n) ∥\natomise n = atom (dyn (fromℕ n))\n\nup : ∀ {n} → Fin n → Fin (suc n)\nup zero = zero\nup (suc n) = suc (up n)\n\nraise : ∀ {n} → ∥ J n ∥ₐ ⟿ ∥ J (suc n) ∥ₐ\nraise {n} = interp (J (suc n)) (λ k → atom (dyn (up k)))\n\nstep : ∀ {n} → ∥ J n ∥ₐ ⟿ ∥ J (suc n) ∥ₐ\nstep {n} = interp (J (suc n)) (λ k → atom (dyn (suc k)))\n\nmutual\n\n map-step-raise : ∀ {n m} → (xs : Vec ∥ J n ∥ m)\n → Pointwise ≈[ J (suc (suc n)) ]\n (map ∣ step {suc n} ⊙ raise {n} ∣ xs)\n (map ∣ raise {suc n} ⊙ step {n} ∣ xs)\n map-step-raise [] = []\n map-step-raise (x ∷ xs) = step-raise {x = x} ∷ map-step-raise xs\n\n step-raise : ∀ {n} → step {suc n} ⊙ raise {n} ≗ raise {suc n} ⊙ step {n}\n step-raise {n} {atom (dyn k)} = refl\n step-raise {n} {term f xs} = begin\n ∣ step ⊙ raise ∣ (term f xs)\n ≈⟨ sym (∣ step ⊙ raise ∣-hom f xs) ⟩\n term f (map ∣ step ⊙ raise ∣ xs)\n ≈⟨ cong f (map-step-raise xs) ⟩\n term f (map ∣ raise ⊙ step ∣ xs)\n ≈⟨ ∣ raise ⊙ step ∣-hom f xs ⟩\n ∣ raise ⊙ step ∣ (term f xs)\n ∎\n where open Reasoning ∥ J (suc (suc n)) ∥/≈\n", "meta": {"hexsha": "eee8ace0a25a52cb2d3738acb48c02a11f701d39", "size": 4019, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Fragment/Equational/Model/Properties.agda", "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_issues_repo_path": "src/Fragment/Equational/Model/Properties.agda", "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_forks_repo_path": "src/Fragment/Equational/Model/Properties.agda", "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "avg_line_length": 34.947826087, "max_line_length": 79, "alphanum_fraction": 0.4809654143, "num_tokens": 1749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723317123102956, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.3857021859979893}} {"text": "module cry.gfp where\n\n-- open import Agda.Primitive using (lsuc; _⊔_)\nopen import Level\n\n-- import Agda.Builtin.FromNat\nopen import Agda.Builtin.Bool\nopen import Agda.Builtin.Equality\nopen import Algebra.FunctionProperties.Core using (Op₁; Op₂)\nopen import Relation.Nullary\n-- open import Relation.Binary.Core using (Rel; Decidable; Substitutive)\n-- open import Relation.Binary.PropositionalEquality.Core using (subst)\nRel : ∀ {a} → Set a → (ℓ : Level) → Set (a ⊔ suc ℓ)\nRel A ℓ = A → A → Set ℓ\nDecidable : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Set _\nDecidable _∼_ = ∀ x y → Dec (x ∼ y)\n_Respects_ : ∀ {a ℓ₁ ℓ₂} {A : Set a} → (A → Set ℓ₁) → Rel A ℓ₂ → Set _\nP Respects _∼_ = ∀ {x y} → x ∼ y → P x → P y\nSubstitutive : ∀ {a ℓ₁} {A : Set a} → Rel A ℓ₁ → (ℓ₂ : Level) → Set _\nSubstitutive {A = A} _∼_ p = (P : A → Set p) → P Respects _∼_\n\nsubst : ∀ {a p} {A : Set a} → Substitutive (_≡_ {A = A}) p\nsubst P refl p = p\n\nrecord RawField c ℓ : Set (suc (c ⊔ ℓ)) where\n infix 10 _⁻¹\n infix 9 -_\n infixl 8 _²\n infixl 7 _*_\n infixl 6 _+_ _-_\n infix 4 _≈_ _≈?_\n field\n Carrier : Set c\n _≈_ : Rel Carrier ℓ\n _≈?_ : Decidable _≈_\n _?≈_ : Carrier → Carrier → Bool\n _+_ : Op₂ Carrier\n _-_ : Op₂ Carrier\n _*_ : Op₂ Carrier\n _² : Op₁ Carrier\n -_ : Op₁ Carrier\n _⁻¹ : Op₁ Carrier\n 0# : Carrier\n 1# : Carrier\n\nopen import Agda.Builtin.Nat as N using () renaming (Nat to ℕ)\n\n_mod_ : (dividend divisor : ℕ) → ℕ\n(d mod 0) = 0\n(d mod N.suc s) = N.mod-helper 0 s d s\n\n_div_ : (dividend divisor : ℕ) → ℕ\n(d div 0) = 0\n(d div N.suc s) = N.div-helper 0 s d s\n\n{-# TERMINATING #-}\ntimes : ∀ {a} {A : Set a} →\n (one : A) (dbl : A → A) (add : A → A → A) →\n A → ℕ → A\ntimes {A = A} one dbl add = mul where\n mul : A → ℕ → A\n f : A → ℕ → A\n -- f u n = uⁿ\n g : A → A → ℕ → A\n -- g t u n = uⁿ t\n\n mul x 0 = one\n mul x n = f x n\n\n f u 1 = u\n f u n with n mod 2\n ... | 0 = f (dbl u) (n div 2)\n ... | _ = g u (dbl u) ((n N.- 1) div 2)\n\n g t u 1 = add t u\n g t u n with n mod 2\n ... | 0 = g t (dbl u) (n div 2)\n ... | _ = g (add t u) (dbl u) ((n N.- 1) div 2)\n\n\nmodule 𝔽ₚ (p : ℕ) where\n 𝔽 : Set\n 𝔽 = ℕ\n\n to𝔽 : ℕ → 𝔽\n to𝔽 i = i mod p\n\n _==_ : 𝔽 → 𝔽 → Set\n x == y = x ≡ y\n\n open N using (zero; suc)\n pred : ℕ → ℕ\n pred zero = 0\n pred (suc n) = n\n\n _≟_ : (x y : 𝔽) → Dec (x == y)\n zero ≟ zero = yes refl\n suc m ≟ suc n with m ≟ n\n suc m ≟ suc .m | yes refl = yes refl\n suc m ≟ suc n | no prf = no λ x → prf ((λ p → subst (λ x → m ≡ pred x) p refl) x)\n zero ≟ suc n = no λ()\n suc m ≟ zero = no λ()\n\n infix 10 _⁻¹\n infix 9 -_\n infixl 8 _²\n infixl 7 _*_\n infixl 6 _+_ _-_\n\n _+_ : 𝔽 → 𝔽 → 𝔽\n n + m = to𝔽 (n N.+ m)\n\n _*_ : 𝔽 → 𝔽 → 𝔽\n n * m = to𝔽 (n N.* m)\n\n _² : 𝔽 → 𝔽\n x ² = x * x\n\n -_ : 𝔽 → 𝔽\n - 0 = 0\n - N.suc n = (p N.- N.suc n)\n\n _-_ : 𝔽 → 𝔽 → 𝔽\n x - y = x + (- y)\n\n 0# : 𝔽\n 0# = 0\n\n 1# : 𝔽\n 1# = 1\n\n _^_ : 𝔽 → ℕ → 𝔽\n _^_ = times 1# _² _*_\n\n _⁻¹ : 𝔽 → 𝔽\n x ⁻¹ = x ^ (p N.- 2)\n\ngfp : ℕ → RawField _ _\ngfp p = record\n { Carrier = 𝔽\n ; _≈_ = _==_\n ; _≈?_ = _≟_\n ; _?≈_ = N._==_\n ; _+_ = _+_\n ; _-_ = _-_\n ; _*_ = _*_\n ; _² = _²\n ; -_ = -_\n ; _⁻¹ = _⁻¹\n ; 0# = 0#\n ; 1# = 1#\n } where open 𝔽ₚ p\n", "meta": {"hexsha": "89100d1ae5c6c8f24ea1f832a96b5a7a6fdbabdc", "size": 3300, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/cry/gfp.agda", "max_stars_repo_name": "semenov-vladyslav/cry-agda", "max_stars_repo_head_hexsha": "44297e5099d12dea7f3165c1f1d53924736ec058", "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/cry/gfp.agda", "max_issues_repo_name": "semenov-vladyslav/cry-agda", "max_issues_repo_head_hexsha": "44297e5099d12dea7f3165c1f1d53924736ec058", "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/cry/gfp.agda", "max_forks_repo_name": "semenov-vladyslav/cry-agda", "max_forks_repo_head_hexsha": "44297e5099d12dea7f3165c1f1d53924736ec058", "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": 21.568627451, "max_line_length": 88, "alphanum_fraction": 0.4827272727, "num_tokens": 1542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.38566038773005334}} {"text": "{-# OPTIONS --without-K --rewriting --exact-split #-}\n\nopen import lib.Basics\nopen import lib.types.Paths\nopen import lib.types.Coproduct\n\nopen import Graphs.Definition\n\nopen import Coequalizers.Definition\n\nmodule Coequalizers.TrivialExtension where\n\nmodule TExtensionCoeq-l {i : ULevel} {V : Type i} (v : V) where\n instance\n tegph : Graph ⊤ (V ⊔ ⊤)\n tegph = record { π₀ = λ _ → inl v ; π₁ = λ _ → inr unit }\n\n extn-equiv : V ≃ ((V ⊔ ⊤) / ⊤)\n extn-equiv = equiv ((c[_] ∘ inl)) (((Coeq-rec (⊔-rec (idf V) (λ _ → v)) λ e → idp))) ((Coeq-elim _ (λ { (inl v') → idp ; (inr x) → quot x}) λ {unit → ↓-app=idf-in (∙'-unit-l _ ∙ ! lem ∙ᵣ quot unit)}))\n λ _ → idp\n where\n lem : ap (c[_] ∘ inl ∘ (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp ))) (quot unit) == idp\n lem =\n ap (c[_] ∘ inl ∘ (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp ))) (quot unit)\n =⟨ ap-∘ (c[_] ∘ inl) (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp )) (quot unit) ⟩\n ap (c[_] ∘ inl) (ap (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp )) (quot unit))\n =⟨ ap (ap (c[_] ∘ inl)) (Coeq-rec-β= _ _ _) ⟩\n ap (c[_] ∘ inl) idp\n =⟨ idp ⟩\n idp\n =∎\n\nmodule TExtensionCoeq-r {i : ULevel} {V : Type i} (v : V) where\n instance\n tegph : Graph ⊤ (V ⊔ ⊤)\n tegph = record { π₀ = λ _ → inr unit ; π₁ = λ _ → inl v }\n\n extn-equiv : V ≃ ((V ⊔ ⊤) / ⊤)\n extn-equiv = equiv ((c[_] ∘ inl)) (((Coeq-rec (⊔-rec (idf V) (λ _ → v)) λ e → idp))) ((Coeq-elim _ (λ { (inl v') → idp ; (inr x) → ! (quot x)}) λ {unit → ↓-app=idf-in ((!-inv'-l (quot unit) ∙ ! lem ∙ ! (∙-unit-r _)))}))\n λ _ → idp\n where\n lem : ap (c[_] ∘ inl ∘ (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp ))) (quot unit) == idp\n lem =\n ap (c[_] ∘ inl ∘ (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp ))) (quot unit)\n =⟨ ap-∘ (c[_] ∘ inl) (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp )) (quot unit) ⟩\n ap (c[_] ∘ inl) (ap (Coeq-rec (⊔-rec (λ x → x) (λ _ → v)) (λ e → idp )) (quot unit))\n =⟨ ap (ap (c[_] ∘ inl)) (Coeq-rec-β= _ _ _) ⟩\n ap (c[_] ∘ inl) idp\n =⟨ idp ⟩\n idp\n =∎\n", "meta": {"hexsha": "bfde01ddda97276041b3c86b3862933a10f2c5d5", "size": 2203, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "main/Coequalizers/TrivialExtension.agda", "max_stars_repo_name": "awswan/nielsenschreier-hott", "max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "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": "main/Coequalizers/TrivialExtension.agda", "max_issues_repo_name": "awswan/nielsenschreier-hott", "max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "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": "main/Coequalizers/TrivialExtension.agda", "max_forks_repo_name": "awswan/nielsenschreier-hott", "max_forks_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d", "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.3653846154, "max_line_length": 221, "alphanum_fraction": 0.4552882433, "num_tokens": 987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.3856136647773666}} {"text": "module Relation.Ternary.Separation.Monad.Reader where\n\nopen import Level\nopen import Function using (_∘_; case_of_)\nopen import Relation.Binary.PropositionalEquality using (refl)\nopen import Relation.Unary\nopen import Relation.Unary.PredicateTransformer using (PT)\nopen import Relation.Ternary.Separation\nopen import Relation.Ternary.Separation.Morphisms\nopen import Relation.Ternary.Separation.Monad\nopen import Relation.Ternary.Separation.Allstar\n\nopen import Data.Product\nopen import Data.List hiding (concat; lookup)\nopen import Data.Unit\n\nprivate\n variable\n ℓv : Level\n A : Set ℓv\n Γ Γ₁ Γ₂ Γ₃ : List A\n\n{- Something not unlike a indexed relative monad transformer in a bicartesian closed category -}\nmodule ReaderTransformer {ℓ}\n -- types\n {T : Set ℓ}\n -- runtime resource\n {C : Set ℓ} {{rc : RawSep C}} {u} {{sc : IsUnitalSep rc u}} {{cc : IsConcattative rc}}\n --\n {B : Set ℓ} {{rb : RawSep B}}\n (j : Morphism C B) {{sb : IsUnitalSep rb (Morphism.j j u)}}\n (V : T → Pred C ℓ) -- values\n (M : PT C B ℓ ℓ)\n {{monad : Monads.Monad {{jm = j}} ⊤ ℓ (λ _ _ → M) }} \n where\n\n open Morphism j hiding (j) public\n open Monads {{jm = j}} using (Monad; str; typed-str)\n open import Relation.Ternary.Separation.Construct.List T\n\n module _ where\n open Monad monad\n\n variable\n P Q R : Pred C ℓ\n\n Reader : ∀ (Γ₁ Γ₂ : List T) (P : Pred C ℓ) → Pred B ℓ\n Reader Γ₁ Γ₂ P = J (Allstar V Γ₁) ─✴ M (P ✴ Allstar V Γ₂)\n\n instance\n reader-monad : Monad (List T) _ Reader\n app (Monad.return reader-monad px) (inj e) s = return px &⟨ s ⟩ e\n app (app (Monad.bind reader-monad f) mp σ₁) env σ₂ =\n let _ , σ₃ , σ₄ = ⊎-assoc σ₁ σ₂ in\n app (bind (wand λ where\n (px ×⟨ σ₅ ⟩ env') σ₆ →\n let _ , τ₁ , τ₂ = ⊎-unassoc σ₆ (j-⊎ σ₅) in\n app (app f px τ₁) (inj env') τ₂)) (app mp env σ₄) σ₃\n\n frame : Γ₁ ⊎ Γ₃ ≣ Γ₂ → ∀[ Reader Γ₁ ε P ⇒ Reader Γ₂ Γ₃ P ]\n app (frame sep c) (inj env) σ = do\n let E₁ ×⟨ σ₁ ⟩ E₂ = repartition sep env\n let Φ , σ₂ , σ₃ = ⊎-unassoc σ (j-⊎ σ₁)\n (v ×⟨ σ₄ ⟩ nil) ×⟨ σ₅ ⟩ E₃ ← app c (inj E₁) σ₂ &⟨ Allstar _ _ ∥ σ₃ ⟩ E₂\n case ⊎-id⁻ʳ σ₄ of λ where\n refl → return (v ×⟨ σ₅ ⟩ E₃)\n\n ask : ε[ Reader Γ ε (Allstar V Γ) ]\n app ask (inj env) σ with ⊎-id⁻ˡ σ\n ... | refl = return (env ×⟨ ⊎-idʳ ⟩ nil)\n\n prepend : ∀[ Allstar V Γ₁ ⇒ⱼ Reader Γ₂ (Γ₁ ∙ Γ₂) Emp ]\n app (prepend env₁) (inj env₂) s with j-⊎⁻ s\n ... | _ , refl , s' = return (empty ×⟨ ⊎-idˡ ⟩ (concat (env₁ ×⟨ s' ⟩ env₂)))\n\n append : ∀[ Allstar V Γ₁ ⇒ⱼ Reader Γ₂ (Γ₂ ∙ Γ₁) Emp ]\n app (append env₁) (inj env₂) s with j-⊎⁻ s\n ... | _ , refl , s' = return (empty ×⟨ ⊎-idˡ ⟩ (concat (✴-swap (env₁ ×⟨ s' ⟩ env₂))))\n \n liftM : ∀[ M P ⇒ Reader Γ Γ P ]\n app (liftM mp) (inj env) σ = do\n mp &⟨ σ ⟩ env\n\n runReader : ∀[ Allstar V Γ ⇒ⱼ Reader Γ ε P ─✴ M P ]\n app (runReader env) mp σ = do\n px ×⟨ σ ⟩ nil ← app mp (inj env) (⊎-comm σ)\n case ⊎-id⁻ʳ σ of λ where\n refl → return px \n\n module _ where\n open Monad reader-monad\n\n lookup : ∀ {a} → ε[ Reader [ a ] [] (V a) ]\n lookup = do\n v :⟨ σ ⟩: nil ← ask\n case ⊎-id⁻ʳ σ of λ where\n refl → return v\n\nmodule ReaderMonad {ℓ}\n -- types\n {T : Set ℓ}\n -- runtime resource\n {C : Set ℓ} {{rc : RawSep C}} {u} {{sc : IsUnitalSep rc u}} {{cc : IsConcattative rc}}\n -- values\n (V : T → Pred C ℓ)\n where\n\n open import Relation.Ternary.Separation.Monad.Identity\n open ReaderTransformer id-morph V Identity.Id {{ monad = Identity.id-monad }} public\n", "meta": {"hexsha": "b68f49e29e1984caebf792ee1b8c476e4fac4a38", "size": 3543, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Relation/Ternary/Separation/Monad/Reader.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/Relation/Ternary/Separation/Monad/Reader.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/Relation/Ternary/Separation/Monad/Reader.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": 32.2090909091, "max_line_length": 96, "alphanum_fraction": 0.5862263618, "num_tokens": 1367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7956580952177051, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.38540093521721686}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import homotopy.3x3.Common\nopen import homotopy.3x3.PushoutPushout\n\nmodule homotopy.3x3.Transpose where\n\nopen M using (Pushout^2)\n\ntype-of : ∀ {i} {A : Type i} (u : A) → Type i\ntype-of {A = A} _ = A\n\nmodule _ {i} (d : Span^2 {i}) where\n\n open Span^2 d\n\n transpose-f : (f : type-of H₁₁ → _) (g : type-of H₃₃ → _) → Span^2\n transpose-f f g = span^2 A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄\n f₁₀ f₃₀ f₁₂ f₃₂ f₁₄ f₃₄ f₀₁ f₀₃ f₂₁ f₂₃ f₄₁ f₄₃\n (f H₁₁) H₃₁ H₁₃ (g H₃₃)\n\n transpose : Span^2\n transpose = span^2 A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄\n f₁₀ f₃₀ f₁₂ f₃₂ f₁₄ f₃₄ f₀₁ f₀₃ f₂₁ f₂₃ f₄₁ f₄₃\n (! ∘ H₁₁) H₃₁ H₁₃ (! ∘ H₃₃)\n\nch1 : ∀ {i j} {A : Type i} {x y : A} {p : x == y} {f g : A → Type j} {a : f x → g x} {b : f y → g y}\n → (a == b [ (λ u → f u → g u) ↓ p ]) → (a == b [ (λ u → fst u → snd u) ↓ pair×= (ap f p) (ap g p)])\nch1 {p = idp} α = α\n\nch2 : ∀ {i j} {X : Type i} {x y : X} {p : x == y}\n {A B₁ B₂ C : X → Type j}\n {f₁ : (x : X) → A x → B₁ x} {g₁ : (x : X) → B₁ x → C x}\n {f₂ : (x : X) → A x → B₂ x} {g₂ : (x : X) → B₂ x → C x}\n {a : _} {b : _}\n → (a == b [ (λ z → (x : A z) → g₁ z (f₁ z x) == g₂ z (f₂ z x)) ↓ p ])\n → (a == b [ (λ u → (x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x))\n ↓ square=-raw (ap A p) (ap B₁ p) (ap B₂ p) (ap C p) (ch1 (apd f₁ p)) (ch1 (apd f₂ p)) (ch1 (apd g₁ p)) (ch1 (apd g₂ p)) ])\nch2 {p = idp} α = α\n\nap-span^2=-priv : ∀ {i} {d d' : Span^2 {i}} (p : d == d')\n → ap transpose p == span^2=-raw (ap Span^2.A₀₀ p) (ap Span^2.A₂₀ p) (ap Span^2.A₄₀ p)\n (ap Span^2.A₀₂ p) (ap Span^2.A₂₂ p) (ap Span^2.A₄₂ p)\n (ap Span^2.A₀₄ p) (ap Span^2.A₂₄ p) (ap Span^2.A₄₄ p)\n (ch1 (apd Span^2.f₁₀ p)) (ch1 (apd Span^2.f₃₀ p))\n (ch1 (apd Span^2.f₁₂ p)) (ch1 (apd Span^2.f₃₂ p))\n (ch1 (apd Span^2.f₁₄ p)) (ch1 (apd Span^2.f₃₄ p))\n (ch1 (apd Span^2.f₀₁ p)) (ch1 (apd Span^2.f₀₃ p))\n (ch1 (apd Span^2.f₂₁ p)) (ch1 (apd Span^2.f₂₃ p))\n (ch1 (apd Span^2.f₄₁ p)) (ch1 (apd Span^2.f₄₃ p))\n (ch2 (ap↓ (λ u → ! ∘ u) (apd Span^2.H₁₁ p))) (ch2 (apd Span^2.H₃₁ p))\n (ch2 (apd Span^2.H₁₃ p)) (ch2 (ap↓ (λ u → ! ∘ u) (apd Span^2.H₃₃ p)))\nap-span^2=-priv {i} {d} {.d} idp = idp\n\nap-span^2=-priv2 : ∀ {i}\n {A₀₀ A₀₀' : Type i} (eq-A₀₀ : A₀₀ == A₀₀')\n {A₀₂ A₀₂' : Type i} (eq-A₀₂ : A₀₂ == A₀₂')\n {A₀₄ A₀₄' : Type i} (eq-A₀₄ : A₀₄ == A₀₄')\n {A₂₀ A₂₀' : Type i} (eq-A₂₀ : A₂₀ == A₂₀')\n {A₂₂ A₂₂' : Type i} (eq-A₂₂ : A₂₂ == A₂₂')\n {A₂₄ A₂₄' : Type i} (eq-A₂₄ : A₂₄ == A₂₄')\n {A₄₀ A₄₀' : Type i} (eq-A₄₀ : A₄₀ == A₄₀')\n {A₄₂ A₄₂' : Type i} (eq-A₄₂ : A₄₂ == A₄₂')\n {A₄₄ A₄₄' : Type i} (eq-A₄₄ : A₄₄ == A₄₄')\n {f₀₁ : A₀₂ → A₀₀} {f₀₁' : A₀₂' → A₀₀'} (eq-f₀₁ : f₀₁ == f₀₁' [ (λ u → fst u → snd u) ↓ pair×= eq-A₀₂ eq-A₀₀ ])\n {f₀₃ : A₀₂ → A₀₄} {f₀₃' : A₀₂' → A₀₄'} (eq-f₀₃ : f₀₃ == f₀₃' [ (λ u → fst u → snd u) ↓ pair×= eq-A₀₂ eq-A₀₄ ])\n {f₂₁ : A₂₂ → A₂₀} {f₂₁' : A₂₂' → A₂₀'} (eq-f₂₁ : f₂₁ == f₂₁' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₂₀ ])\n {f₂₃ : A₂₂ → A₂₄} {f₂₃' : A₂₂' → A₂₄'} (eq-f₂₃ : f₂₃ == f₂₃' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₂₄ ])\n {f₄₁ : A₄₂ → A₄₀} {f₄₁' : A₄₂' → A₄₀'} (eq-f₄₁ : f₄₁ == f₄₁' [ (λ u → fst u → snd u) ↓ pair×= eq-A₄₂ eq-A₄₀ ])\n {f₄₃ : A₄₂ → A₄₄} {f₄₃' : A₄₂' → A₄₄'} (eq-f₄₃ : f₄₃ == f₄₃' [ (λ u → fst u → snd u) ↓ pair×= eq-A₄₂ eq-A₄₄ ])\n {f₁₀ : A₂₀ → A₀₀} {f₁₀' : A₂₀' → A₀₀'} (eq-f₁₀ : f₁₀ == f₁₀' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₀ eq-A₀₀ ])\n {f₃₀ : A₂₀ → A₄₀} {f₃₀' : A₂₀' → A₄₀'} (eq-f₃₀ : f₃₀ == f₃₀' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₀ eq-A₄₀ ])\n {f₁₂ : A₂₂ → A₀₂} {f₁₂' : A₂₂' → A₀₂'} (eq-f₁₂ : f₁₂ == f₁₂' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₀₂ ])\n {f₃₂ : A₂₂ → A₄₂} {f₃₂' : A₂₂' → A₄₂'} (eq-f₃₂ : f₃₂ == f₃₂' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₂ eq-A₄₂ ])\n {f₁₄ : A₂₄ → A₀₄} {f₁₄' : A₂₄' → A₀₄'} (eq-f₁₄ : f₁₄ == f₁₄' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₄ eq-A₀₄ ])\n {f₃₄ : A₂₄ → A₄₄} {f₃₄' : A₂₄' → A₄₄'} (eq-f₃₄ : f₃₄ == f₃₄' [ (λ u → fst u → snd u) ↓ pair×= eq-A₂₄ eq-A₄₄ ])\n {H₁₁ : (x : A₂₂) → f₁₀ (f₂₁ x) == f₀₁ (f₁₂ x)} {H₁₁' : (x : A₂₂') → f₁₀' (f₂₁' x) == f₀₁' (f₁₂' x)}\n (eq-H₁₁ : H₁₁ == H₁₁' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x)))\n ↓ square=-raw eq-A₂₂ eq-A₂₀ eq-A₀₂ eq-A₀₀ eq-f₂₁ eq-f₁₂ eq-f₁₀ eq-f₀₁ ])\n {H₁₃ : (x : A₂₂) → f₀₃ (f₁₂ x) == f₁₄ (f₂₃ x)} {H₁₃' : (x : A₂₂') → f₀₃' (f₁₂' x) == f₁₄' (f₂₃' x)}\n (eq-H₁₃ : H₁₃ == H₁₃' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x)))\n ↓ square=-raw eq-A₂₂ eq-A₀₂ eq-A₂₄ eq-A₀₄ eq-f₁₂ eq-f₂₃ eq-f₀₃ eq-f₁₄ ])\n {H₃₁ : (x : A₂₂) → f₃₀ (f₂₁ x) == f₄₁ (f₃₂ x)} {H₃₁' : (x : A₂₂') → f₃₀' (f₂₁' x) == f₄₁' (f₃₂' x)}\n (eq-H₃₁ : H₃₁ == H₃₁' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x)))\n ↓ square=-raw eq-A₂₂ eq-A₂₀ eq-A₄₂ eq-A₄₀ eq-f₂₁ eq-f₃₂ eq-f₃₀ eq-f₄₁ ])\n {H₃₃ : (x : A₂₂) → f₄₃ (f₃₂ x) == f₃₄ (f₂₃ x)} {H₃₃' : (x : A₂₂') → f₄₃' (f₃₂' x) == f₃₄' (f₂₃' x)}\n (eq-H₃₃ : H₃₃ == H₃₃' [ (λ u → ((x : SquareFunc.A u) → SquareFunc.g₁ u (SquareFunc.f₁ u x) == SquareFunc.g₂ u (SquareFunc.f₂ u x)))\n ↓ square=-raw eq-A₂₂ eq-A₄₂ eq-A₂₄ eq-A₄₄ eq-f₃₂ eq-f₂₃ eq-f₄₃ eq-f₃₄ ])\n → ap transpose (span^2=-raw eq-A₀₀ eq-A₀₂ eq-A₀₄ eq-A₂₀ eq-A₂₂ eq-A₂₄ eq-A₄₀ eq-A₄₂ eq-A₄₄ eq-f₀₁ eq-f₀₃ eq-f₂₁ eq-f₂₃ eq-f₄₁ eq-f₄₃ eq-f₁₀ eq-f₃₀ eq-f₁₂ eq-f₃₂ eq-f₁₄ eq-f₃₄ eq-H₁₁ eq-H₁₃ eq-H₃₁ eq-H₃₃)\n == span^2=-raw eq-A₀₀ eq-A₂₀ eq-A₄₀ eq-A₀₂ eq-A₂₂ eq-A₄₂ eq-A₀₄ eq-A₂₄ eq-A₄₄ eq-f₁₀ eq-f₃₀ eq-f₁₂ eq-f₃₂ eq-f₁₄ eq-f₃₄ eq-f₀₁ eq-f₀₃ eq-f₂₁ eq-f₂₃ eq-f₄₁ eq-f₄₃ (square-thing _ _ _ _ _ _ _ _ (ap↓ (λ u → ! ∘ u) eq-H₁₁)) eq-H₃₁ eq-H₁₃ (square-thing _ _ _ _ _ _ _ _ (ap↓ (λ u → ! ∘ u) eq-H₃₃))\nap-span^2=-priv2 idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp = idp\n\nmodule _ {i} (d : Span^2 {i}) where\n\n open Span^2 d\n\n transpose-transpose : transpose (transpose d) == d\n transpose-transpose = span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp\n (λ= (!-! ∘ Span^2.H₁₁ d)) idp idp (λ= (!-! ∘ Span^2.H₃₃ d))\n\nmodule _ {i} (d : Span^2 {i}) where\n\n transpose-equiv : Span^2 {i} ≃ Span^2\n transpose-equiv = equiv transpose transpose transpose-transpose transpose-transpose\n\nmodule _ {i} (d : Span^2 {i}) where\n\n open Span^2 d\n\n d' : (H₁₁' : type-of H₁₁) (H₃₃' : type-of H₃₃) → Span^2\n d' H₁₁' H₃₃' = record d {H₁₁ = H₁₁'; H₃₃ = H₃₃'}\n\n e : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃') (c : M.A₂∙ (d' H₁₁' H₃₃'))\n → left (M.f₁∙ (d' H₁₁' H₃₃') c) == right (M.f₃∙ (d' H₁₁' H₃₃') c)\n e {H₁₁'} eq₁ {H₃₃'} eq₃ = E.f module _ where\n\n e-glue : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃') (c : Span^2.A₂₂ (d' H₁₁' H₃₃'))\n → glue (left (f₂₁ c)) == glue (right (f₂₃ c)) [ (λ z → left (M.f₁∙ (d' H₁₁' H₃₃') z) == right (M.f₃∙ (d' H₁₁' H₃₃') z)) ↓ glue c ]\n e-glue idp idp c = apd glue (glue c)\n\n module E = PushoutElim {P = λ c → left (M.f₁∙ (d' H₁₁' H₃₃') c) == right (M.f₃∙ (d' H₁₁' H₃₃') c) :> Pushout^2 d} (glue ∘ left) (glue ∘ right) (e-glue eq₁ eq₃)\n\n module F {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃')\n = PushoutRec {d = M.v-h-span (d' H₁₁' H₃₃')} {D = Pushout^2 d}\n left right (e eq₁ eq₃)\n\n tr-tr-fun : Pushout^2 (transpose (transpose d)) → Pushout^2 d\n tr-tr-fun = F.f (! (λ= (!-! ∘ H₁₁))) (! (λ= (!-! ∘ H₃₃)))\n\n lemma12 : (c : M.A₂∙ d) → e idp idp c == glue c\n lemma12 = Pushout-elim (λ a → idp) (λ b → idp) (λ c → ↓-=-in (! (E.glue-β idp idp c)))\n\n result' : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁ == H₁₁') {H₃₃' : type-of H₃₃} (eq₃ : H₃₃ == H₃₃') (x : Pushout^2 (d' H₁₁' H₃₃'))\n → transport Pushout^2 (span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp (! eq₁) idp idp (! eq₃) :> (d' H₁₁' H₃₃' == d)) x == F.f eq₁ eq₃ x\n result' idp idp = Pushout-elim (λ a → idp) (λ b → idp) (λ c → ↓-='-in (F.glue-β idp idp c ∙ lemma12 c ∙ ! (ap-idf (glue c))))\n\n result : {H₁₁' : type-of H₁₁} (eq₁ : H₁₁' == H₁₁) {H₃₃' : type-of H₃₃} (eq₃ : H₃₃' == H₃₃) (x : Pushout^2 (d' H₁₁' H₃₃'))\n → transport Pushout^2 (span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp eq₁ idp idp eq₃ :> (d' H₁₁' H₃₃' == d)) x == F.f (! eq₁) (! eq₃) x\n result eq₁ eq₃ x = ap (λ u → transport Pushout^2 (span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp\n idp idp idp idp idp idp idp idp (fst u) idp idp (snd u) :> (_ == d)) x)\n (pair×= (! (!-! eq₁)) (! (!-! eq₃)))\n ∙ result' (! eq₁) (! eq₃) x\n\n result2 : (x : Pushout^2 (transpose (transpose d))) → transport Pushout^2 (transpose-transpose d) x == tr-tr-fun x\n result2 = result (λ= (!-! ∘ Span^2.H₁₁ d)) (λ= (!-! ∘ Span^2.H₃₃ d))\n\n-- module _ {i} where\n\n-- postulate\n-- to : (d : Span^2 {i}) → Pushout^2 d → Pushout^2 (transpose d)\n\n-- from : (d : Span^2 {i}) → Pushout^2 (transpose d) → Pushout^2 d\n-- from d = tr-tr-fun d ∘ to (transpose d)\n\n-- postulate\n-- from-to : (d : Span^2 {i}) (x : Pushout^2 d) → from d (to d x) == x\n\n-- lemma3 : {d d' : Span^2 {i}} (p : d == d') (x : Pushout^2 d) → transport (Pushout^2 ∘ transpose) p (to d x) == to d' (transport Pushout^2 p x)\n-- lemma3 {d} {.d} idp x = idp\n\n-- lemma34 : (d : Span^2 {i}) (x : Pushout^2 (transpose (transpose d))) → transport (Pushout^2 ∘ transpose) (transpose-transpose d) (to (transpose (transpose d)) x) == to d (tr-tr-fun d x)\n-- lemma34 d x = lemma3 (transpose-transpose d) x ∙ ap (to d) (result2 d x)\n\n-- lm2 : (d : Span^2 {i}) → ap transpose (transpose-transpose d) == transpose-transpose (transpose d)\n-- lm2 d = ap-span^2=-priv2 idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp\n-- (! (! (λ= (!-! ∘ Span^2.H₁₁ d)))) idp idp (! (! (λ= (!-! ∘ Span^2.H₃₃ d)))) ∙ ap (λ u → span^2=-raw idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp idp (fst u) idp idp (snd u)) (pair×= (lm3 (Span^2.H₁₁ d)) (lm3 (Span^2.H₃₃ d))) where\n\n-- lm3 : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B} (p : (a : A) → f a == g a)\n-- → ap (λ f → ! ∘ f) (! (! (λ= (!-! ∘ p)))) == ! (! (λ= (!-! ∘ ! ∘ p)))\n-- lm3 p = transport (λ u → ap (λ f → ! ∘ f) (! (! (λ= (!-! ∘ u)))) == ! (! (λ= (!-! ∘ ! ∘ u)))) (λ= (app=-β p)) (lm3' (λ= p)) where\n\n-- lm3' : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B} (p : f == g)\n-- → ap (λ f → ! ∘ f) (! (! (λ= (!-! ∘ app= p)))) == ! (! (λ= (!-! ∘ ! ∘ app= p)))\n-- lm3' idp = ap (λ u → ap (λ u → ! ∘ u) (! (! u))) (! (λ=-η idp)) ∙ ap (! ∘ !) (λ=-η idp)\n\n-- lemma345 : (d : Span^2 {i}) (x : Pushout^2 (transpose (transpose (transpose d))))\n-- → transport (Pushout^2 ∘ transpose) (transpose-transpose d) x == tr-tr-fun (transpose d) x\n-- lemma345 d x =\n-- transport (Pushout^2 ∘ transpose) (transpose-transpose d) x\n-- =⟨ ap (λ u → coe u x) (ap-∘ Pushout^2 transpose (transpose-transpose d)) ⟩\n-- transport Pushout^2 (ap transpose (transpose-transpose d)) x\n-- =⟨ ap (λ u → transport Pushout^2 u x) (lm2 d) ⟩\n-- transport Pushout^2 (transpose-transpose (transpose d)) x\n-- =⟨ result2 (transpose d) x ⟩\n-- tr-tr-fun (transpose d) x ∎\n\n-- to-from : (d : Span^2 {i}) (x : Pushout^2 (transpose d)) → to d (from d x) == x\n-- to-from d x =\n-- to d (tr-tr-fun d (to (transpose d) x))\n-- =⟨ ! (lemma34 d (to (transpose d) x)) ⟩\n-- transport (Pushout^2 ∘ transpose) (transpose-transpose d) (to (transpose (transpose d)) (to (transpose d) x))\n-- =⟨ lemma345 d (to (transpose (transpose d)) (to (transpose d) x)) ⟩\n-- tr-tr-fun (transpose d) (to (transpose (transpose d)) (to (transpose d) x))\n-- =⟨ from-to (transpose d) x ⟩\n-- x ∎\n", "meta": {"hexsha": "22cfacdd9945131f2e169d8532962c055c6df568", "size": 12475, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "homotopy/3x3/Transpose.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/Transpose.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/Transpose.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": 63.6479591837, "max_line_length": 294, "alphanum_fraction": 0.5030861723, "num_tokens": 6244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.38534693156465966}} {"text": "module Show where\n\nopen import Data.Char hiding (show)\nopen import Data.List\nopen import Data.String hiding (show)\nopen import Function\n\nrecord Show (A : Set) : Set where\n field\n show : A → String\n\nopen Show {{...}} public\n\nfromHaskell : {A : Set} → (A → List Char) → Show A\nfromHaskell primShow = record { show = fromList ∘ primShow }\n", "meta": {"hexsha": "32a6da2fa4c053c3ecbe04931d301e78259331fc", "size": 340, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Show.agda", "max_stars_repo_name": "cruhland/agda-editor", "max_stars_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945", "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/Show.agda", "max_issues_repo_name": "cruhland/agda-editor", "max_issues_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945", "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/Show.agda", "max_forks_repo_name": "cruhland/agda-editor", "max_forks_repo_head_hexsha": "c5ffd117f6d5a98f7c68a2a6b9be54a150c70945", "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": 21.25, "max_line_length": 60, "alphanum_fraction": 0.6911764706, "num_tokens": 94, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.3852408395262473}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Some properties about subsets\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.Fin.Subset.Properties where\n\nimport Algebra.Definitions as AlgebraicDefinitions\nimport Algebra.Structures as AlgebraicStructures\nopen import Algebra.Bundles\nimport Algebra.Properties.Lattice as L\nimport Algebra.Properties.DistributiveLattice as DL\nimport Algebra.Properties.BooleanAlgebra as BA\nopen import Data.Bool.Base using (not)\nopen import Data.Bool.Properties\nopen import Data.Fin.Base using (Fin; suc; zero)\nopen import Data.Fin.Subset\nopen import Data.Fin.Properties using (any?; decFinSubset)\nopen import Data.Nat.Base\nimport Data.Nat.Properties as ℕₚ\nopen import Data.Product as Product using (∃; ∄; _×_; _,_; proj₁)\nopen import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂; [_,_]′)\nopen import Data.Vec.Base\nopen import Data.Vec.Properties\nopen import Function.Base using (_∘_; const; id; case_of_)\nopen import Function.Equivalence using (_⇔_; equivalence)\nopen import Relation.Binary as B hiding (Decidable)\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Nullary using (Dec; yes; no)\nimport Relation.Nullary.Decidable as Dec\nopen import Relation.Nullary.Negation using (contradiction)\nopen import Relation.Nullary.Sum using (_⊎-dec_)\nopen import Relation.Unary using (Pred; Decidable; Satisfiable)\n\n------------------------------------------------------------------------\n-- Constructor mangling\n\ndrop-there : ∀ {s n x} {p : Subset n} → suc x ∈ s ∷ p → x ∈ p\ndrop-there (there x∈p) = x∈p\n\ndrop-not-there : ∀ {s n x} {p : Subset n} → suc x ∉ s ∷ p → x ∉ p\ndrop-not-there x∉sp x∈p = contradiction (there x∈p) x∉sp\n\ndrop-∷-⊆ : ∀ {n s₁ s₂} {p₁ p₂ : Subset n} → s₁ ∷ p₁ ⊆ s₂ ∷ p₂ → p₁ ⊆ p₂\ndrop-∷-⊆ p₁s₁⊆p₂s₂ x∈p₁ = drop-there (p₁s₁⊆p₂s₂ (there x∈p₁))\n\ndrop-∷-⊂ : ∀ {n s} {p₁ p₂ : Subset n} → s ∷ p₁ ⊂ s ∷ p₂ → p₁ ⊂ p₂\ndrop-∷-⊂ {s = inside} (_ , zero , x∈sp₂ , x∉sp₁) = contradiction here x∉sp₁\ndrop-∷-⊂ {s} (sp₁⊆sp₂ , suc x , there x∈p₂ , x∉sp₁) = drop-∷-⊆ sp₁⊆sp₂ , x , x∈p₂ , drop-not-there x∉sp₁\n\nmodule _ {n} {p q : Subset n} where\n\n out⊆ : ∀ {y} → p ⊆ q → outside ∷ p ⊆ y ∷ q\n out⊆ p⊆q (there ∈p) = there (p⊆q ∈p)\n\n out⊆-⇔ : ∀ {y} → p ⊆ q ⇔ outside ∷ p ⊆ y ∷ q\n out⊆-⇔ = equivalence out⊆ drop-∷-⊆\n\n in⊆in : p ⊆ q → inside ∷ p ⊆ inside ∷ q\n in⊆in p⊆q here = here\n in⊆in p⊆q (there ∈p) = there (p⊆q ∈p)\n\n in⊆in-⇔ : p ⊆ q ⇔ inside ∷ p ⊆ inside ∷ q\n in⊆in-⇔ = equivalence in⊆in drop-∷-⊆\n\n s⊆s : ∀ {s} → p ⊆ q → s ∷ p ⊆ s ∷ q\n s⊆s p⊆q here = here\n s⊆s p⊆q (there ∈p) = there (p⊆q ∈p)\n\n out⊂ : ∀ {y} → p ⊂ q → outside ∷ p ⊂ y ∷ q\n out⊂ (p⊆q , x , x∈q , x∉p) = out⊆ p⊆q , suc x , there x∈q , x∉p ∘ drop-there\n\n out⊂in : p ⊆ q → outside ∷ p ⊂ inside ∷ q\n out⊂in p⊆q = out⊆ p⊆q , zero , here , λ ()\n\n out⊂in-⇔ : p ⊆ q ⇔ outside ∷ p ⊂ inside ∷ q\n out⊂in-⇔ = equivalence out⊂in (drop-∷-⊆ ∘ proj₁)\n\n out⊂out-⇔ : p ⊂ q ⇔ outside ∷ p ⊂ outside ∷ q\n out⊂out-⇔ = equivalence out⊂ drop-∷-⊂\n\n in⊂in : p ⊂ q → inside ∷ p ⊂ inside ∷ q\n in⊂in (p⊆q , x , x∈q , x∉p) = in⊆in p⊆q , suc x , there x∈q , x∉p ∘ drop-there\n\n in⊂in-⇔ : p ⊂ q ⇔ inside ∷ p ⊂ inside ∷ q\n in⊂in-⇔ = equivalence in⊂in drop-∷-⊂\n\n------------------------------------------------------------------------\n-- _∈_\n\ninfix 4 _∈?_\n_∈?_ : ∀ {n} x (p : Subset n) → Dec (x ∈ p)\nzero ∈? inside ∷ p = yes here\nzero ∈? outside ∷ p = no λ()\nsuc n ∈? s ∷ p = Dec.map′ there drop-there (n ∈? p)\n\n------------------------------------------------------------------------\n-- Empty\n\ndrop-∷-Empty : ∀ {n s} {p : Subset n} → Empty (s ∷ p) → Empty p\ndrop-∷-Empty ¬∃∈ (x , x∈p) = ¬∃∈ (suc x , there x∈p)\n\nEmpty-unique : ∀ {n} {p : Subset n} → Empty p → p ≡ ⊥\nEmpty-unique {_} {[]} ¬∃∈ = refl\nEmpty-unique {_} {inside ∷ p} ¬∃∈ = contradiction (zero , here) ¬∃∈\nEmpty-unique {_} {outside ∷ p} ¬∃∈ =\n cong (outside ∷_) (Empty-unique (drop-∷-Empty ¬∃∈))\n\nnonempty? : ∀ {n} → Decidable (Nonempty {n})\nnonempty? p = any? (_∈? p)\n\n------------------------------------------------------------------------\n-- ∣_∣\n\n∣p∣≤n : ∀ {n} (p : Subset n) → ∣ p ∣ ≤ n\n∣p∣≤n = count≤n (_≟ inside)\n\n------------------------------------------------------------------------\n-- ⊥\n\n∉⊥ : ∀ {n} {x : Fin n} → x ∉ ⊥\n∉⊥ (there p) = ∉⊥ p\n\n⊥⊆ : ∀ {n} {p : Subset n} → ⊥ ⊆ p\n⊥⊆ x∈⊥ = contradiction x∈⊥ ∉⊥\n\n∣⊥∣≡0 : ∀ n → ∣ ⊥ {n = n} ∣ ≡ 0\n∣⊥∣≡0 zero = refl\n∣⊥∣≡0 (suc n) = ∣⊥∣≡0 n\n\n------------------------------------------------------------------------\n-- ⊤\n\n∈⊤ : ∀ {n} {x : Fin n} → x ∈ ⊤\n∈⊤ {x = zero} = here\n∈⊤ {x = suc x} = there ∈⊤\n\n⊆⊤ : ∀ {n} {p : Subset n} → p ⊆ ⊤\n⊆⊤ = const ∈⊤\n\n∣⊤∣≡n : ∀ n → ∣ ⊤ {n = n} ∣ ≡ n\n∣⊤∣≡n zero = refl\n∣⊤∣≡n (suc n) = cong suc (∣⊤∣≡n n)\n\n∣p∣≡n⇒p≡⊤ : ∀ {n} {p : Subset n} → ∣ p ∣ ≡ n → p ≡ ⊤\n∣p∣≡n⇒p≡⊤ {p = []} _ = refl\n∣p∣≡n⇒p≡⊤ {p = outside ∷ p} |p|≡n = contradiction |p|≡n (ℕₚ.<⇒≢ (s≤s (∣p∣≤n p)))\n∣p∣≡n⇒p≡⊤ {p = inside ∷ p} |p|≡n = cong (inside ∷_) (∣p∣≡n⇒p≡⊤ (ℕₚ.suc-injective |p|≡n))\n\n------------------------------------------------------------------------\n-- ⁅_⁆\n\nx∈⁅x⁆ : ∀ {n} (x : Fin n) → x ∈ ⁅ x ⁆\nx∈⁅x⁆ zero = here\nx∈⁅x⁆ (suc x) = there (x∈⁅x⁆ x)\n\nx∈⁅y⁆⇒x≡y : ∀ {n x} (y : Fin n) → x ∈ ⁅ y ⁆ → x ≡ y\nx∈⁅y⁆⇒x≡y zero here = refl\nx∈⁅y⁆⇒x≡y zero (there p) = contradiction p ∉⊥\nx∈⁅y⁆⇒x≡y (suc y) (there p) = cong suc (x∈⁅y⁆⇒x≡y y p)\n\nx∈⁅y⁆⇔x≡y : ∀ {n} {x y : Fin n} → x ∈ ⁅ y ⁆ ⇔ x ≡ y\nx∈⁅y⁆⇔x≡y {_} {x} {y} = equivalence\n (x∈⁅y⁆⇒x≡y y)\n (λ x≡y → subst (λ y → x ∈ ⁅ y ⁆) x≡y (x∈⁅x⁆ x))\n\nx≢y⇒x∉⁅y⁆ : ∀ {n} {x y : Fin n} → x ≢ y → x ∉ ⁅ y ⁆\nx≢y⇒x∉⁅y⁆ x≢y = x≢y ∘ x∈⁅y⁆⇒x≡y _\n\nx∉⁅y⁆⇒x≢y : ∀ {n} {x y : Fin n} → x ∉ ⁅ y ⁆ → x ≢ y\nx∉⁅y⁆⇒x≢y x∉⁅x⁆ refl = x∉⁅x⁆ (x∈⁅x⁆ _)\n\n∣⁅x⁆∣≡1 : ∀ {n} (i : Fin n) → ∣ ⁅ i ⁆ ∣ ≡ 1\n∣⁅x⁆∣≡1 {suc n} zero = cong suc (∣⊥∣≡0 n)\n∣⁅x⁆∣≡1 {_} (suc i) = ∣⁅x⁆∣≡1 i\n\n------------------------------------------------------------------------\n-- _⊆_\n\n⊆-refl : ∀ {n} → Reflexive (_⊆_ {n})\n⊆-refl = id\n\n⊆-reflexive : ∀ {n} → _≡_ ⇒ (_⊆_ {n})\n⊆-reflexive refl = ⊆-refl\n\n⊆-trans : ∀ {n} → Transitive (_⊆_ {n})\n⊆-trans p⊆q q⊆r x∈p = q⊆r (p⊆q x∈p)\n\n⊆-antisym : ∀ {n} → Antisymmetric _≡_ (_⊆_ {n})\n⊆-antisym {i = []} {[]} p⊆q q⊆p = refl\n⊆-antisym {i = x ∷ xs} {y ∷ ys} p⊆q q⊆p with x | y\n... | inside | inside = cong₂ _∷_ refl (⊆-antisym (drop-∷-⊆ p⊆q) (drop-∷-⊆ q⊆p))\n... | inside | outside = contradiction (p⊆q here) λ()\n... | outside | inside = contradiction (q⊆p here) λ()\n... | outside | outside = cong₂ _∷_ refl (⊆-antisym (drop-∷-⊆ p⊆q) (drop-∷-⊆ q⊆p))\n\n⊆-min : ∀ {n} → Minimum (_⊆_ {n}) ⊥\n⊆-min (x ∷ xs) (there v∈⊥) = there (⊆-min xs v∈⊥)\n\n⊆-max : ∀ {n} → Maximum (_⊆_ {n}) ⊤\n⊆-max (inside ∷ xs) here = here\n⊆-max (x ∷ xs) (there v∈xs) = there (⊆-max xs v∈xs)\n\ninfix 4 _⊆?_\n_⊆?_ : ∀ {n} → B.Decidable (_⊆_ {n = n})\n[] ⊆? [] = yes id\noutside ∷ p ⊆? y ∷ q = Dec.map out⊆-⇔ (p ⊆? q)\ninside ∷ p ⊆? outside ∷ q = no (λ p⊆q → case (p⊆q here) of λ())\ninside ∷ p ⊆? inside ∷ q = Dec.map in⊆in-⇔ (p ⊆? q)\n\nmodule _ (n : ℕ) where\n\n ⊆-isPreorder : IsPreorder _≡_ (_⊆_ {n})\n ⊆-isPreorder = record\n { isEquivalence = isEquivalence\n ; reflexive = ⊆-reflexive\n ; trans = ⊆-trans\n }\n\n ⊆-preorder : Preorder _ _ _\n ⊆-preorder = record\n { isPreorder = ⊆-isPreorder\n }\n\n ⊆-isPartialOrder : IsPartialOrder _≡_ (_⊆_ {n})\n ⊆-isPartialOrder = record\n { isPreorder = ⊆-isPreorder\n ; antisym = ⊆-antisym\n }\n\n ⊆-poset : Poset _ _ _\n ⊆-poset = record\n { isPartialOrder = ⊆-isPartialOrder\n }\n\np⊆q⇒∣p∣≤∣q∣ : ∀ {n} {p q : Subset n} → p ⊆ q → ∣ p ∣ ≤ ∣ q ∣\np⊆q⇒∣p∣≤∣q∣ {p = []} {[]} p⊆q = z≤n\np⊆q⇒∣p∣≤∣q∣ {p = outside ∷ p} {outside ∷ q} p⊆q = p⊆q⇒∣p∣≤∣q∣ (drop-∷-⊆ p⊆q)\np⊆q⇒∣p∣≤∣q∣ {p = outside ∷ p} {inside ∷ q} p⊆q = ℕₚ.≤-step (p⊆q⇒∣p∣≤∣q∣ (drop-∷-⊆ p⊆q))\np⊆q⇒∣p∣≤∣q∣ {p = inside ∷ p} {outside ∷ q} p⊆q = contradiction (p⊆q here) λ()\np⊆q⇒∣p∣≤∣q∣ {p = inside ∷ p} {inside ∷ q} p⊆q = s≤s (p⊆q⇒∣p∣≤∣q∣ (drop-∷-⊆ p⊆q))\n\n\n------------------------------------------------------------------------\n-- _⊂_\n\np⊂q⇒p⊆q : ∀ {n} → {p q : Subset n} → p ⊂ q → p ⊆ q\np⊂q⇒p⊆q = proj₁\n\n⊂-trans : ∀ {n} → Transitive (_⊂_ {n})\n⊂-trans (p⊆q , x , x∈q , x∉p) (q⊆r , _ , _ , _) = ⊆-trans p⊆q q⊆r , x , q⊆r x∈q , x∉p\n\n⊂-⊆-trans : ∀ {n} → Trans {A = Subset n} _⊂_ _⊆_ _⊂_\n⊂-⊆-trans (p⊆q , x , x∈q , x∉p) q⊆r = ⊆-trans p⊆q q⊆r , x , q⊆r x∈q , x∉p\n\n⊆-⊂-trans : ∀ {n} → Trans {A = Subset n} _⊆_ _⊂_ _⊂_\n⊆-⊂-trans p⊆q (q⊆r , x , x∈r , x∉q) = ⊆-trans p⊆q q⊆r , x , x∈r , x∉q ∘ p⊆q\n\n⊂-irref : ∀ {n} → Irreflexive _≡_ (_⊂_ {n})\n⊂-irref refl (_ , x , x∈p , x∉q) = contradiction x∈p x∉q\n\n⊂-antisym : ∀ {n} → Antisymmetric _≡_ (_⊂_ {n})\n⊂-antisym (p⊆q , _) (q⊆p , _) = ⊆-antisym p⊆q q⊆p\n\n⊂-asymmetric : ∀ {n} → Asymmetric (_⊂_ {n})\n⊂-asymmetric (p⊆q , _) (_ , x , x∈p , x∉q) = contradiction (p⊆q x∈p) x∉q\n\ninfix 4 _⊂?_\n\n_⊂?_ : ∀ {n} → B.Decidable (_⊂_ {n = n})\n[] ⊂? [] = no λ ()\noutside ∷ p ⊂? outside ∷ q = Dec.map out⊂out-⇔ (p ⊂? q)\noutside ∷ p ⊂? inside ∷ q = Dec.map out⊂in-⇔ (p ⊆? q)\ninside ∷ p ⊂? outside ∷ q = no (λ {(p⊆q , _) → case (p⊆q here) of λ ()})\ninside ∷ p ⊂? inside ∷ q = Dec.map in⊂in-⇔ (p ⊂? q)\n\nmodule _ (n : ℕ) where\n\n ⊂-isStrictPartialOrder : IsStrictPartialOrder _≡_ (_⊂_ {n})\n ⊂-isStrictPartialOrder = record\n { isEquivalence = isEquivalence\n ; irrefl = ⊂-irref\n ; trans = ⊂-trans\n ; <-resp-≈ = (λ {refl → id}) , (λ {refl → id})\n }\n\n ⊂-strictPartialOrder : StrictPartialOrder _ _ _\n ⊂-strictPartialOrder = record\n { isStrictPartialOrder = ⊂-isStrictPartialOrder\n }\n\n ⊂-isDecStrictPartialOrder : IsDecStrictPartialOrder _≡_ (_⊂_ {n})\n ⊂-isDecStrictPartialOrder = record\n { isStrictPartialOrder = ⊂-isStrictPartialOrder\n ; _≟_ = ≡-dec _≟_\n ; _>= :\n ∀ {k} {A B : Type ℓ} {P : B → Type p} {f : A → List B} {xs : List A} →\n (ext : Extensionality? k ℓ (ℓ ⊔ p)) →\n All P (xs >>= f) ↝[ k ] All (All P ∘ f) xs\nAll->>= {P = P} {f = f} {xs = xs} ext =\n All P (L.concat (L.map f xs)) ↝⟨ All-concat ext ⟩\n All (All P) (L.map f xs) ↝⟨ All-map ext ⟩□\n All (All P ∘ f) xs □\n\nAll-const :\n {A : Type a} {B : Type b} {xs : List B} →\n Extensionality? k b a →\n All (const A) xs ↝[ k ] Vec A (L.length xs)\nAll-const {A = A} {xs = xs} ext =\n (∀ x → x ∈ xs → A) ↔⟨ inverse currying ⟩\n (∃ (_∈ xs) → A) ↝⟨ →-cong₁ ext (Fin-length _) ⟩□\n (Fin (L.length xs) → A) □\n\nprivate\n\n -- The following lemma that relates All-const and Fin-length holds\n -- by definition.\n\n All-const-Fin-length :\n ∀ {xs : List A} {bs : All (const B) xs} {i} →\n All-const _ bs i ≡\n uncurry bs (_↔_.from (Fin-length xs) i)\n All-const-Fin-length = refl _\n\nAll-const-replicate :\n {A : Type a} →\n Extensionality? k lzero a →\n All (const A) (L.replicate n tt) ↝[ k ] Vec A n\nAll-const-replicate {n = n} {A = A} ext =\n All (const A) (L.replicate n tt) ↝⟨ All-const ext ⟩\n Vec A (L.length (L.replicate n tt)) ↝⟨ →-cong₁ ext $ ≡⇒↝ bijection $ cong Fin (L.length-replicate _) ⟩□\n Vec A n □\n\nAll-Σ :\n {A : Type a} {P : A → Type p} {Q : ∀ x → P x → Type q} {xs : List A} →\n Extensionality? k a (a ⊔ p ⊔ q) →\n All (λ x → Σ (P x) (Q x)) xs ↝[ k ]\n ∃ λ (ps : All P xs) → ∀ x (x∈xs : x ∈ xs) → Q x (ps x x∈xs)\nAll-Σ {P = P} {Q = Q} {xs = xs} ext =\n All (λ x → Σ (P x) (Q x)) xs ↔⟨⟩\n\n (∀ x → x ∈ xs → Σ (P x) (Q x)) ↝⟨ (∀-cong ext λ _ → from-isomorphism ΠΣ-comm) ⟩\n\n (∀ x → ∃ λ (ps : x ∈ xs → P x) →\n (x∈xs : x ∈ xs) → Q x (ps x∈xs)) ↔⟨ ΠΣ-comm ⟩\n\n (∃ λ (ps : ∀ x → x ∈ xs → P x) →\n ∀ x (x∈xs : x ∈ xs) → Q x (ps x x∈xs)) ↔⟨⟩\n\n (∃ λ (ps : All P xs) → ∀ x (x∈xs : x ∈ xs) → Q x (ps x x∈xs)) □\n\n-- Some abbreviations.\n\nnil : All P []\nnil {P = P} = _⇔_.from (All-[] P _) _\n\ncons : P x → All P xs → All P (x ∷ xs)\ncons = curry (_⇔_.from (All-∷ _))\n\nhead : All P (x ∷ xs) → P x\nhead = proj₁ ∘ _⇔_.to (All-∷ _)\n\ntail : All P (x ∷ xs) → All P xs\ntail = proj₂ ∘ _⇔_.to (All-∷ _)\n\nappend : All P xs → All P ys → All P (xs ++ ys)\nappend = curry (_⇔_.from (All-++ _))\n\n-- All preserves h-levels (assuming extensionality).\n\nH-level-All :\n {A : Type a} {P : A → Type p} →\n Extensionality a (a ⊔ p) →\n ∀ n →\n (∀ x → H-level n (P x)) →\n (∀ xs → H-level n (All P xs))\nH-level-All {a = a} ext n h xs =\n Π-closure ext n λ _ →\n Π-closure (lower-extensionality a a ext) n λ _ →\n h _\n\n-- Some lemmas related to append.\n\nappend-Any-++-inj₁ :\n ∀ {xs ys} {ps : All P xs} {qs : All P ys}\n (x∈xs : x ∈ xs) →\n append ps qs _ (_↔_.from (Any-++ _ _ _) (inj₁ x∈xs)) ≡\n ps _ x∈xs\nappend-Any-++-inj₁ {P = P} {x = x} {ps = ps} {qs} x∈xs =\n append ps qs _ (_↔_.from (Any-++ _ _ _) (inj₁ x∈xs)) ≡⟨⟩\n\n [ ps _ , qs _ ] (_↔_.to (Any-++ _ _ _)\n (_↔_.from (Any-++ _ _ _) (inj₁ x∈xs))) ≡⟨ cong [ ps _ , qs _ ] (_↔_.right-inverse-of (Any-++ _ _ _) _) ⟩\n\n [_,_] {C = λ _ → P x} (ps _) (qs _) (inj₁ x∈xs) ≡⟨⟩\n\n ps _ x∈xs ∎\n\nappend-Any-++-inj₂ :\n ∀ xs {ys} {ps : All P xs} {qs : All P ys} {y∈ys : y ∈ ys} →\n append ps qs _ (_↔_.from (Any-++ _ xs _) (inj₂ y∈ys)) ≡\n qs _ y∈ys\nappend-Any-++-inj₂ {P = P} {y = y} xs {ps = ps} {qs} {y∈ys} =\n append ps qs _ (_↔_.from (Any-++ _ xs _) (inj₂ y∈ys)) ≡⟨⟩\n\n [ ps _ , qs _ ] (_↔_.to (Any-++ _ _ _)\n (_↔_.from (Any-++ _ xs _) (inj₂ y∈ys))) ≡⟨ cong [ ps _ , qs _ ] (_↔_.right-inverse-of (Any-++ _ _ _) _) ⟩\n\n [_,_] {C = λ _ → P y} (ps _) (qs _) (inj₂ y∈ys) ≡⟨⟩\n\n qs _ y∈ys ∎\n\n-- Some congruence lemmas.\n\nAll-cong :\n ∀ {k} {A : Type a} {P : A → Type p} {Q : A → Type q} {xs ys} →\n Extensionality? ⌊ k ⌋-sym a (a ⊔ p ⊔ q) →\n (∀ x → P x ↝[ ⌊ k ⌋-sym ] Q x) →\n xs ∼[ ⌊ k ⌋-sym ] ys →\n All P xs ↝[ ⌊ k ⌋-sym ] All Q ys\nAll-cong {a = a} {k = k} {P = P} {Q} {xs} {ys} ext P↝Q xs∼ys =\n All P xs ↔⟨⟩\n (∀ x → x ∈ xs → P x) ↝⟨ ∀-cong ext (λ _ → →-cong (lower-extensionality? ⌊ k ⌋-sym a a ext) (xs∼ys _) (P↝Q _)) ⟩\n (∀ x → x ∈ ys → Q x) ↔⟨⟩\n All Q ys □\n\nAll-cong-→ :\n (∀ x → P x → Q x) →\n ys ∼[ implication ] xs →\n All P xs → All Q ys\nAll-cong-→ {P = P} {Q = Q} {ys = ys} {xs = xs} P→Q ys∼xs =\n All P xs ↔⟨⟩\n (∀ x → x ∈ xs → P x) ↝⟨ ∀-cong _ (λ _ → →-cong-→ (ys∼xs _) (P→Q _)) ⟩\n (∀ x → x ∈ ys → Q x) ↔⟨⟩\n All Q ys □\n\nmap : (∀ x → P x → Q x) → ys ⊆ xs → All P xs → All Q ys\nmap P→Q ys∼xs = All-cong-→ P→Q ys∼xs\n\nmap₁ : (∀ x → P x → Q x) → All P xs → All Q xs\nmap₁ P→Q = map P→Q (λ _ → id)\n\nmap₂ : ys ⊆ xs → All P xs → All P ys\nmap₂ ys⊆xs = map (λ _ → id) ys⊆xs\n\nprivate\n\n map₁-∘ :\n ∀ {P : A → Type p} {xs} {f : ∀ x → P x → Q x} {ps : All P xs} →\n map₁ f ps ≡ λ _ → f _ ∘ ps _\n map₁-∘ = refl _\n\n map₂-∘ :\n ∀ {xs ys} {ys⊆xs : ys ⊆ xs} {ps : All P xs} →\n map₂ ys⊆xs ps ≡ λ _ → ps _ ∘ ys⊆xs _\n map₂-∘ = refl _\n\n-- Some properties that hold by definition.\n\nmap₂∘map₂ :\n ∀ {xs ys zs} {xs⊆ys : xs ⊆ ys} {ys⊆zs : ys ⊆ zs} {ps : All P zs} →\n map₂ xs⊆ys (map₂ ys⊆zs ps) ≡ map₂ (map₁ ys⊆zs xs⊆ys) ps\nmap₂∘map₂ = refl _\n\nmap₂-inj₂-∘ :\n ∀ {xs ys} {f : ys ⊆ xs} {p : P x} {ps : All P xs} →\n map₂ (λ _ → inj₂ ∘ f _) (cons p ps) ≡ map₂ f ps\nmap₂-inj₂-∘ = refl _\n\nmap₂-id :\n ∀ {xs} {ps : All P xs} →\n map₂ (λ _ → id) ps ≡ ps\nmap₂-id = refl _\n\nmap₂-inj₂ :\n ∀ {xs} {p : P x} {ps : All P xs} →\n map₂ (λ _ → inj₂) (cons p ps) ≡ ps\nmap₂-inj₂ = refl _\n\n-- Some rearrangement lemmas for map₂.\n\nmap₂-⊎-map-id :\n {A : Type a} {P : A → Type p} →\n Extensionality a (a ⊔ p) →\n ∀ {x xs ys} {f : ys ⊆ xs} {p : P x} {ps : All P xs} →\n map₂ (λ _ → ⊎-map id (f _)) (cons p ps) ≡ cons p (map₂ f ps)\nmap₂-⊎-map-id {a = a} ext {f = f} {p} {ps} =\n apply-ext ext λ _ →\n apply-ext (lower-extensionality lzero a ext)\n [ (λ _ → refl _) , (λ _ → refl _) ]\n\nmap₂-⊎-map-id-inj₂ :\n {A : Type a} {P : A → Type p} →\n Extensionality a (a ⊔ p) →\n ∀ {x y xs} {p : P x} {q : P y} {ps : All P xs} →\n map₂ (λ _ → ⊎-map id inj₂) (cons p (cons q ps)) ≡ cons p ps\nmap₂-⊎-map-id-inj₂ ext {p = p} {q} {ps} =\n map₂ (λ _ → ⊎-map id inj₂) (cons p (cons q ps)) ≡⟨ map₂-⊎-map-id ext ⟩\n cons p (map₂ (λ _ → inj₂) (cons q ps)) ≡⟨⟩\n cons p ps ∎\n\nmap₂-++-cong :\n {A : Type a} {P : A → Type p} →\n Extensionality a (a ⊔ p) →\n ∀ xs₁ {ys₁ xs₂ ys₂} {ps : All P xs₂} {qs : All P ys₂}\n {f : xs₁ ⊆ xs₂} {g : ys₁ ⊆ ys₂} →\n map₂ (++-cong f g) (append ps qs) ≡\n append (map₂ f ps) (map₂ g qs)\nmap₂-++-cong {a = a} ext _ {ps = ps} {qs} {f} {g} =\n apply-ext ext λ _ →\n apply-ext (lower-extensionality lzero a ext) λ x∈ →\n\n let lemma : ∀ x → [ ps _ , qs _ ] (⊎-map (f _) (g _) x) ≡\n [ ps _ ∘ f _ , qs _ ∘ g _ ] x\n lemma = [ (λ _ → refl _) , (λ _ → refl _) ]\n in\n\n [ ps _ , qs _ ] (_↔_.to (Any-++ _ _ _) (_↔_.from (Any-++ _ _ _)\n (⊎-map (f _) (g _) (_↔_.to (Any-++ _ _ _) x∈)))) ≡⟨ cong [ ps _ , qs _ ] (_↔_.right-inverse-of (Any-++ _ _ _) _) ⟩\n\n [ ps _ , qs _ ] (⊎-map (f _) (g _) (_↔_.to (Any-++ _ _ _) x∈)) ≡⟨ lemma (_↔_.to (Any-++ _ _ _) x∈) ⟩∎\n\n [ ps _ ∘ f _ , qs _ ∘ g _ ] (_↔_.to (Any-++ _ _ _) x∈) ∎\n", "meta": {"hexsha": "3c34c445c3bc8e5700dd45dd8261bf7018da4323", "size": 12760, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/List/All.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/List/All.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/List/All.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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.5431754875, "max_line_length": 138, "alphanum_fraction": 0.440830721, "num_tokens": 5704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804196836383, "lm_q2_score": 0.6224593241981982, "lm_q1q2_score": 0.38516564186335495}} {"text": "\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Reflection renaming (bindTC to _>>=_)\nopen import Agda.Builtin.Bool\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.Sigma\n\ndata Unit : Set where\n unit : Unit\n\ndata Empty : Set where\n\nqq : ∀ {a} {A : Set a} → A → Term → TC _\nqq t hole = withNormalisation true do\n `t ← quoteTC t\n ``t ← quoteTC `t\n unify hole ``t\n\nmacro\n\n qU = qq {A = Unit → Set → Set}\n qE = qq {A = Empty → Set → Set}\n qA = qq {A = Set → Set}\n\ncase_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B\ncase x of f = f x\n\npattern vArg x = arg (arg-info visible relevant) x\npattern [_] x = x ∷ []\n\nmap : {A B : Set} → (A → B) → List A → List B\nmap f [] = []\nmap f (x ∷ xs) = f x ∷ map f xs\n\nmkArgs : List Nat → List (Arg Term)\nmkArgs = map λ i → vArg (var i [])\n\nunit,X=>_∙_ : Nat → List Nat → Term\nunit,X=> n ∙ args =\n pat-lam [ clause [ \"X\" , vArg (agda-sort (lit 0)) ]\n (vArg (con (quote unit) []) ∷ vArg (var 0) ∷ [])\n (var n []) ]\n (mkArgs args)\n\nabs,X=>∙_ : List Nat → Term\nabs,X=>∙ is = pat-lam [ absurd-clause ( (\"()\" , vArg (def (quote Empty) [])) ∷ (\"X\" , vArg (agda-sort (lit 0))) ∷ [])\n (vArg absurd ∷ vArg (var 0) ∷ []) ]\n (mkArgs is)\n\nabs=>∙_ : List Nat → Term\nabs=>∙ is = pat-lam [ absurd-clause [ \"()\" , vArg (def (quote Empty) []) ] (vArg absurd ∷ []) ]\n (mkArgs is)\n\n_ : qU (λ { unit X → X }) ≡ unit,X=> 0 ∙ []\n_ = refl\n\n_ : (B : Set) → qU (λ { unit X → B }) ≡ unit,X=> 1 ∙ []\n_ = λ _ → refl\n\n_ : qE (λ { () X }) ≡ abs,X=>∙ []\n_ = refl\n\n_ : (B : Set) → qE (λ { () X }) ≡ abs,X=>∙ []\n_ = λ _ → refl\n\n_ : (u : Unit) → qA (case u of λ { unit X → X }) ≡ (unit,X=> 0 ∙ [ 0 ])\n_ = λ _ → refl\n\n_ : (B : Set) (u : Unit) → qA (case u of λ { unit X → B }) ≡ unit,X=> 2 ∙ [ 0 ]\n_ = λ _ _ → refl\n\n_ : (B : Set) (e : Empty) → qA (case e of λ { () X }) ≡ abs,X=>∙ [ 0 ]\n_ = λ _ _ → refl\n\n_ : qE (λ ()) ≡ abs=>∙ []\n_ = refl\n\n_ : (B : Set) → qE (λ ()) ≡ abs=>∙ []\n_ = λ _ → refl\n\n_ : (B : Set) (e : Empty) → qA (case e of λ ()) ≡ abs=>∙ [ 0 ]\n_ = λ _ _ → refl\n\nmodule _ (A : Set) where\n\n _ : qU (λ { unit X → X }) ≡ unit,X=> 0 ∙ []\n _ = refl\n\n _ : (B : Set) → qU (λ { unit X → B }) ≡ unit,X=> 1 ∙ []\n _ = λ _ → refl\n\n _ : qE (λ { () X }) ≡ abs,X=>∙ []\n _ = refl\n\n _ : (u : Unit) → qA (case u of λ { unit X → X }) ≡ (unit,X=> 0 ∙ [ 0 ])\n _ = λ _ → refl\n\n _ : (B : Set) (u : Unit) → qA (case u of λ { unit X → B }) ≡ unit,X=> 2 ∙ [ 0 ]\n _ = λ _ _ → refl\n\n _ : (B : Set) (e : Empty) → qA (case e of λ { () X }) ≡ abs,X=>∙ [ 0 ]\n _ = λ _ _ → refl\n\n _ : qE (λ ()) ≡ abs=>∙ []\n _ = refl\n\n _ : (B : Set) → qE (λ ()) ≡ abs=>∙ []\n _ = λ _ → refl\n\n _ : (B : Set) (e : Empty) → qA (case e of λ ()) ≡ abs=>∙ [ 0 ]\n _ = λ _ _ → refl\n", "meta": {"hexsha": "1fa1c3e46933fac7d8bd17b5cedf32225c37bee2", "size": 2838, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue2618.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/Succeed/Issue2618.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/Succeed/Issue2618.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": 25.1150442478, "max_line_length": 118, "alphanum_fraction": 0.4527836505, "num_tokens": 1178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.6261241772283034, "lm_q1q2_score": 0.3851213774581187}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import cw.CW\nopen import cw.FinCW\nopen import cw.FinBoundary\nopen import cohomology.Theory\n\nmodule cw.cohomology.cochainequiv.FirstCoboundaryCommSquare (OT : OrdinaryTheory lzero)\n (⊙fin-skel : ⊙FinSkeleton 1) where\n\nopen OrdinaryTheory OT\nopen import cw.cohomology.WedgeOfCells OT ⊙⦉ ⊙fin-skel ⦊\nopen import cw.cohomology.reconstructed.TipAndAugment OT ⊙⦉ ⊙fcw-init ⊙fin-skel ⦊\nopen import cw.cohomology.reconstructed.TipCoboundary OT ⊙⦉ ⊙fin-skel ⦊\nopen import cw.cohomology.cochainequiv.DualizedFirstBoundary OT ⊙fin-skel\nopen import cw.cohomology.cochainequiv.FirstCoboundary OT ⊙fin-skel\n\nprivate\n fin-skel = ⊙FinSkeleton.skel ⊙fin-skel\n I = AttachedFinSkeleton.numCells fin-skel\n ac = ⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero\n\n ⊙fin-skel₋₁ = ⊙fcw-init ⊙fin-skel\n fin-skel₋₁ = ⊙FinSkeleton.skel ⊙fin-skel₋₁\n ac₋₁ = ⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel₋₁ lzero\n\nabstract\n rephrase-dualized-first-boundary-comm-sqr :\n CommSquareEquiv\n (λ g Bool) -> LMap -> ℕ\nocount p [] = 0\nocount p (just x ∷ m) with p x\nocount p (just x ∷ m) | false = ocount p m\nocount p (just x ∷ m) | true = suc (ocount p m)\nocount p (nothing ∷ m) = ocount p m\n\nchange-one-ocount-goes-down :\n ∀ (m : LMap) ->\n (p : Value -> Bool) ->\n (n : ℕ) ->\n (k∈ : n ∈ (Dom' m)) ->\n p (deref n m k∈) ≡ true ->\n (v : Value) ->\n p v ≡ false ->\n ocount p m ≡ suc (ocount p (m-insert (just v) n m))\nchange-one-ocount-goes-down = f where\n f : ∀ (m : LMap) ->\n (p : Value -> Bool) ->\n (n : ℕ) ->\n (k∈ : n ∈ (Dom' m)) ->\n p (deref n m k∈) ≡ true ->\n (v : Value) ->\n p v ≡ false ->\n ocount p m ≡ suc (ocount p (m-insert (just v) n m))\n f [] p zero () p[derefnmk∈]≡true v pv≡false\n f (just x ∷ m) p zero k∈ p[derefnmk∈]≡true v pv≡false with p x\n ... | true with p v\n f (just x ∷ m) p zero k∈ p[derefnmk∈]≡true v () | true | true\n ... | false = refl\n f (just x ∷ m) p zero k∈ () v pv≡false | false\n f (nothing ∷ m) p zero k∈ p[derefnmk∈]≡true v pv≡false = ⊥-elim (0∈S k∈)\n f [] p (suc n) () p[derefnmk∈]≡true v pv≡false\n f (just x ∷ m) p (suc n) k∈ p[derefnmk∈]≡true v pv≡false with p x\n ... | true = cong suc (f m p n\n (n∈S{x = just x}{l = m} k∈)\n p[derefnmk∈]≡true v pv≡false)\n ... | false = f m p n (n∈S{x = just x}{l = m} k∈)\n p[derefnmk∈]≡true v pv≡false\n f (nothing ∷ m) p (suc n) k∈ p[derefnmk∈]≡true v pv≡false\n = f m p n (n∈S{x = nothing}{l = m} k∈) p[derefnmk∈]≡true v pv≡false \n\nchange-nothing-ocount-stays-same :\n ∀ (m : LMap) ->\n (p : Value -> Bool) ->\n (n : ℕ) ->\n (k∈ : n ∈ (Dom' m)) ->\n (v : Value) ->\n p (deref n m k∈) ≡ p v ->\n ocount p m ≡ ocount p (m-insert (just v) n m)\nchange-nothing-ocount-stays-same = f where\n\n f : ∀ (m : LMap) ->\n (p : Value -> Bool) ->\n (n : ℕ) ->\n (k∈ : n ∈ (Dom' m)) ->\n (v : Value) ->\n p (deref n m k∈) ≡ p v ->\n ocount p m ≡ ocount p (m-insert (just v) n m)\n f [] p zero () v pold≡pv\n f (just x ∷ m) p zero k∈ v pold≡pv with p x | p v\n f (just x ∷ m) p zero k∈ v pold≡pv | false | false = refl\n f (just x ∷ m) p zero k∈ v () | false | true\n f (just x ∷ m) p zero k∈ v () | true | false\n f (just x ∷ m) p zero k∈ v pold≡pv | true | true = refl\n f (nothing ∷ m) p zero k∈ v pold≡pv with p v\n f (nothing ∷ m) p zero k∈ v pold≡pv | false = refl\n f (nothing ∷ m) p zero k∈ v pold≡pv | true = ⊥-elim (0∈S k∈)\n f [] p (suc n) () v pold≡pv\n f (just x ∷ m) p (suc n) k∈ v pold≡pv with p x\n f (just x ∷ m) p (suc n) k∈ v pold≡pv | true =\n cong suc (f m p n (n∈S{x = just x}{l = m} k∈) v pold≡pv)\n f (just x ∷ m) p (suc n) k∈ v pold≡pv | false =\n f m p n (n∈S{x = just x}{l = m} k∈) v pold≡pv\n f (nothing ∷ m) p (suc n) k∈ v pold≡pv =\n f m p n (n∈S{x = nothing}{l = m} k∈) v pold≡pv\n\n\nocount-merge≤′sum-ocount :\n ∀ (m1 m2 : LMap) ->\n (p : Value -> Bool) ->\n ocount p (m1 U m2) ≤′ ocount p m1 + ocount p m2\nocount-merge≤′sum-ocount = f where\n\n f : ∀ (m1 m2 : LMap) ->\n (p : Value -> Bool) ->\n ocount p (m1 U m2) ≤′ ocount p m1 + ocount p m2\n f [] [] p = ≤′-refl\n f [] (x ∷ m2) p = ≤′-refl\n f (x ∷ m1) [] p = ≤⇒≤′ (m≤m+n (ocount p (x ∷ m1)) 0)\n f (just x ∷ m1) (just x₁ ∷ m2) p with p x | p x₁ | f m1 m2 p\n f (just x ∷ m1) (just x₁ ∷ m2) p | false | false | R = R\n f (just x ∷ m1) (just x₁ ∷ m2) p | false | true | R =\n ≤′-trans {y = suc (ocount p m1 + ocount p m2)}\n (s≤′s R) (≡is≤′ (sym (+-suc (ocount p m1) (ocount p m2))))\n f (just x ∷ m1) (just x₁ ∷ m2) p | true | false | R =\n ≤′-step R\n f (just x ∷ m1) (just x₁ ∷ m2) p | true | true | R =\n s≤′s (≤′-trans {y = ocount p m1 + ocount p m2}\n R\n (≤′+r {ocount p m2} {suc (ocount p m2)} {ocount p m1} (≤′-step ≤′-refl)))\n f (just x ∷ m1) (nothing ∷ m2) p with p x | f m1 m2 p\n f (just x ∷ m1) (nothing ∷ m2) p | false | R = R\n f (just x ∷ m1) (nothing ∷ m2) p | true | R = s≤′s R\n f (nothing ∷ m1) (just x ∷ m2) p with p x | f m1 m2 p\n f (nothing ∷ m1) (just x ∷ m2) p | false | R = R\n f (nothing ∷ m1) (just x ∷ m2) p | true | R =\n ≤′-trans {y = suc (ocount p m1 + ocount p m2)}\n (s≤′s R) (≡is≤′ (sym (+-suc (ocount p m1) (ocount p m2)))) \n f (nothing ∷ m1) (nothing ∷ m2) p with f m1 m2 p\n ... | R = R\n\n\nDom'+∈ : (L : LMap) → List (∃[ n ] (n ∈ (Dom' L)))\nDom'+∈ L = help (Dom' L)\n where\n help : (x : List ℕ) → (List (∃[ y ] (y ∈ x)))\n help [] = []\n help (x ∷ x₁) = (x , here refl) ∷ map (λ {(a , b) → a , there b}) (help x₁)\n", "meta": {"hexsha": "99b641b568276939e34479591206845158f5d3bc", "size": 46495, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda/Data/OrderedListMap.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/Data/OrderedListMap.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/Data/OrderedListMap.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": 49.62113127, "max_line_length": 187, "alphanum_fraction": 0.5347456716, "num_tokens": 22584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6113819591324416, "lm_q2_score": 0.6297746074044134, "lm_q1q2_score": 0.38503283328677457}} {"text": "module Data.Unsigned where\n\nopen import Data.Bit using\n (Bit\n ; b0\n ; b1\n ; Bits-num\n ; Overflowing\n ; _overflow:_\n ; result\n ; carry\n ; WithCarry\n ; _with-carry:_\n ; toBool\n ; tryToFinₙ\n ; !ₙ\n ) renaming\n ( _+_ to bit+\n ; _-_ to bit-\n ; ! to bit!\n ; _&_ to bit&\n ; _~|_ to bit|\n ; _^_ to bit^\n ; _>>_ to bit>>\n ; _<<_ to bit<<\n )\nopen import Data.Unit using (⊤)\nopen import Data.Nat using (ℕ)\nopen import Data.Vec using (Vec; head; replicate)\nopen import Data.Nat.Literal using (Number)\nopen import Data.Maybe using (just; nothing)\n\ninfixl 8 _-_ _+_\ninfixl 7 _<<_ _>>_\ninfixl 6 _&_\ninfixl 5 _^_\ninfixl 4 _~|_\n\nrecord Unsigned (n : ℕ) : Set where\n constructor mk-uint\n field\n bits : Vec Bit n\n\nopen Unsigned public\n\ninstance\n Unsigned-num : {m : ℕ} → Number (Unsigned m)\n Unsigned-num {m} .Number.Constraint = Number.Constraint (Bits-num {m})\n Unsigned-num {m} .Number.fromNat n ⦃ p ⦄ = mk-uint (mk-bits p) where\n mk-bits : Number.Constraint (Bits-num {m}) n → Vec Bit m\n mk-bits p = Number.fromNat Bits-num n ⦃ p ⦄\n\n_+_ : {n : ℕ} → Unsigned n → Unsigned n → Overflowing (Unsigned n)\np + q = mk-uint (result sum) overflow: toBool (head (carry sum)) where\n sum = bit+ (bits p) (bits q)\n\n_-_ : {n : ℕ} → Unsigned n → Unsigned n → Overflowing (Unsigned n)\np - q = mk-uint (result sub) overflow: toBool (bit! (head (carry sub))) where\n sub = bit- (bits p) (bits q)\n\nrotr : {n : ℕ} → Unsigned n → Unsigned n → WithCarry (Unsigned n) (Unsigned n)\nrotr {n} (mk-uint ps) (mk-uint qs) = new-result with-carry: new-carry where\n shifted : WithCarry (Vec Bit n) (Vec Bit n)\n shifted with tryToFinₙ qs\n ... | just i = bit>> ps i\n ... | nothing = replicate b0 with-carry: ps \n new-result : Unsigned n\n new-result = mk-uint (result shifted)\n new-carry : Unsigned n\n new-carry = mk-uint (carry shifted)\n\nrotl : {n : ℕ} → Unsigned n → Unsigned n → WithCarry (Unsigned n) (Unsigned n)\nrotl {n} (mk-uint ps) (mk-uint qs) = new-result with-carry: new-carry where\n shifted : WithCarry (Vec Bit n) (Vec Bit n)\n shifted with tryToFinₙ qs\n ... | just i = bit<< ps i\n ... | nothing = replicate b0 with-carry: ps\n new-result : Unsigned n\n new-result = mk-uint (result shifted)\n new-carry : Unsigned n\n new-carry = mk-uint (carry shifted)\n\n_>>_ : {n : ℕ} → Unsigned n → Unsigned n → Unsigned n\nps >> qs = result (rotr ps qs)\n\n_<<_ : {n : ℕ} → Unsigned n → Unsigned n → Unsigned n\nps << qs = result (rotl ps qs)\n\n! : {n : ℕ} → Unsigned n → Unsigned n\n! (mk-uint ps) = mk-uint (!ₙ ps)\n\n_&_ : {n : ℕ} → Unsigned n → Unsigned n → Unsigned n\n(mk-uint ps) & (mk-uint qs) = mk-uint (bit& ps qs)\n\n_~|_ : {n : ℕ} → Unsigned n → Unsigned n → Unsigned n\n(mk-uint ps) ~| (mk-uint qs) = mk-uint (bit| ps qs)\n\n_^_ : {n : ℕ} → Unsigned n → Unsigned n → Unsigned n\n(mk-uint ps) ^ (mk-uint qs) = mk-uint (bit^ ps qs)\n", "meta": {"hexsha": "7c9bad78a86a82edd29eaa3b08f868fc4ec30cc1", "size": 2858, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "formalization/Data/Unsigned.agda", "max_stars_repo_name": "brunoczim/Celeste", "max_stars_repo_head_hexsha": "9f5129d97ee7b89fb8e43136779a78806b7506ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-16T17:31:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-16T17:31:57.000Z", "max_issues_repo_path": "formalization/Data/Unsigned.agda", "max_issues_repo_name": "brunoczim/Celeste", "max_issues_repo_head_hexsha": "9f5129d97ee7b89fb8e43136779a78806b7506ab", "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": "formalization/Data/Unsigned.agda", "max_forks_repo_name": "brunoczim/Celeste", "max_forks_repo_head_hexsha": "9f5129d97ee7b89fb8e43136779a78806b7506ab", "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": 28.58, "max_line_length": 78, "alphanum_fraction": 0.6175647306, "num_tokens": 1012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544085240401, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.38501462771632444}} {"text": "{-# OPTIONS --safe --experimental-lossy-unification #-}\nmodule Cubical.Homotopy.Group.SuspensionMap where\n\nopen import Cubical.Homotopy.Group.Base\nopen import Cubical.Homotopy.Loopspace\nopen import Cubical.Homotopy.Freudenthal\nopen import Cubical.Homotopy.Connected\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Pointed\nopen import Cubical.Foundations.Pointed.Homogeneous\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.GroupoidLaws renaming (assoc to ∙assoc)\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Path\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Transport\n\nopen import Cubical.Functions.Morphism\n\nopen import Cubical.HITs.Sn\nopen import Cubical.HITs.Susp renaming (toSusp to σ ; toSuspPointed to σ∙)\nopen import Cubical.HITs.S1\n\nopen import Cubical.Data.Bool hiding (_≟_)\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Nat\nopen import Cubical.Data.Nat.Order\n\nopen import Cubical.Algebra.Group\nopen import Cubical.Algebra.Group.Morphisms\nopen import Cubical.Algebra.Group.MorphismProperties\nopen import Cubical.Algebra.Semigroup\nopen import Cubical.Algebra.Monoid\n\n\nopen import Cubical.HITs.PropositionalTruncation\n renaming (rec to pRec ; rec2 to pRec2 ; elim to pElim)\nopen import Cubical.HITs.SetTruncation\n renaming (rec to sRec ; rec2 to sRec2 ; elim to sElim\n ; elim2 to sElim2 ; elim3 to sElim3 ; map to sMap)\nopen import Cubical.HITs.Truncation\n renaming (rec to trRec)\n\nopen Iso\nopen IsGroup\nopen IsSemigroup\nopen IsMonoid\nopen GroupStr\n\n{-\nThis file concerns the suspension maps\nsuspMapΩ : πₙA → πₙ₊₁ΣA and\nsuspMap : π'ₙA → π'ₙ₊₁ΣA\nFor instance, we want to transport freudenthal\nfor suspMapΩ to suspMap by establishing a dependent\npath between the two functions.\n\nThis gives, in particular, surjectivity of\nπₙ₊₁(Sⁿ) → πₙ₊₂(Sⁿ⁺¹) for n ≥ 2.\n-}\n\n-- Definition of the suspension functions\nsuspMap : ∀ {ℓ} {A : Pointed ℓ}(n : ℕ)\n → S₊∙ (suc n) →∙ A\n → S₊∙ (suc (suc n)) →∙ Susp∙ (typ A)\nfst (suspMap n f) north = north\nfst (suspMap n f) south = north\nfst (suspMap {A = A} n f) (merid a i) =\n (merid (fst f a) ∙ sym (merid (pt A))) i\nsnd (suspMap n f) = refl\n\nsuspMapΩ∙ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → ((Ω^ n) A)\n →∙ ((Ω^ (suc n)) (Susp∙ (typ A)))\nfst (suspMapΩ∙ {A = A} zero) a = merid a ∙ sym (merid (pt A))\nsnd (suspMapΩ∙ {A = A} zero) = rCancel (merid (pt A))\nsuspMapΩ∙ {A = A} (suc n) = Ω→ (suspMapΩ∙ {A = A} n)\n\nsuspMapΩ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → typ ((Ω^ n) A) → typ ((Ω^ (suc n)) (Susp∙ (typ A)))\nsuspMapΩ {A = A} n = suspMapΩ∙ {A = A} n .fst\n\n\nsuspMapπ' : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ}\n → π' (suc n) A\n → π' (suc (suc n)) (Susp∙ (typ A))\nsuspMapπ' n = sMap (suspMap n)\n\nsuspMapπ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → π n A → π (suc n) (Susp∙ (typ A))\nsuspMapπ n = sMap (suspMapΩ n)\n\n{- suspMapΩ\n Ωⁿ A --------------------> Ω¹⁺ⁿ (Susp A)\n | |\n | = | ≃ flipΩ\n | Ωⁿ→ σ v\nΩⁿ A -------------------> Ωⁿ (Ω (Susp A))\n | |\n | |\n | ≃ Ω→SphereMap | ≃ Ω→SphereMap\n | |\n v post∘∙ . σ v\n (Sⁿ →∙ A) -------------- > (Sⁿ →∙ Ω (Susp A))\n | |\n | = | ≃ botᵣ\n | |\n v suspMap v\n (Sⁿ →∙ A) -------------- > (Sⁿ⁺¹→∙ Susp A)\n -}\n\nbotᵣ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → (S₊∙ n →∙ Ω (Susp∙ (typ A)))\n → S₊∙ (suc n) →∙ Susp∙ (typ A)\nfst (botᵣ zero (f , p)) base = north\nfst (botᵣ zero (f , p)) (loop i) = f false i\nsnd (botᵣ zero (f , p)) = refl\nfst (botᵣ (suc n) (f , p)) north = north\nfst (botᵣ (suc n) (f , p)) south = north\nfst (botᵣ (suc n) (f , p)) (merid a i) = f a i\nsnd (botᵣ (suc n) (f , p)) = refl\n\n----- Top square filler -----\ntop□ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → Ω^→ (suc n) (σ∙ A)\n ≡ (((Iso.fun (flipΩIso (suc n))) , flipΩrefl n)\n ∘∙ suspMapΩ∙ (suc n))\ntop□ {A = A} zero =\n →∙Homogeneous≡ (isHomogeneousPath _ _)\n (funExt λ p → sym (transportRefl _))\ntop□ {A = A} (suc n) =\n cong Ω→ (top□ {A = A} n)\n ∙ →∙Homogeneous≡\n (isHomogeneousPath _ _)\n (funExt λ x\n → Ω→∘ (fun (flipΩIso (suc n)) , flipΩrefl n) (suspMapΩ∙ (suc n)) x)\n\n----- Middle square filler -----\nmodule _ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ')\n (homogB : isHomogeneous B) (f : A →∙ B) where\n nat = isNaturalΩSphereMap A B homogB f\n mutual\n isNatural-Ω→SphereMap : ∀ n p → f ∘∙ Ω→SphereMap n p\n ≡ Ω→SphereMap n (Ω^→ n f .fst p)\n isNatural-Ω→SphereMap 0 p =\n →∙Homogeneous≡ homogB (funExt λ {true → f .snd; false → refl})\n isNatural-Ω→SphereMap (n@(suc n')) p =\n cong (f ∘∙_) (Ω→SphereMap-split n' p)\n ∙ nat n' (Ω→SphereMapSplit₁ n' p)\n ∙ cong (ΩSphereMap n') inner\n ∙ sym (Ω→SphereMap-split n' (Ω^→ n f .fst p))\n where\n inner : Ω→ (post∘∙ (S₊∙ n') f) .fst (Ω→ (Ω→SphereMap∙ n') .fst p)\n ≡ Ω→ (Ω→SphereMap∙ n') .fst (Ω^→ (suc n') f .fst p)\n inner =\n sym (Ω→∘ (post∘∙ (S₊∙ n') f) (Ω→SphereMap∙ n') p)\n ∙ cong (λ g∙ → Ω→ g∙ .fst p) (isNatural-Ω→SphereMap∙ n')\n ∙ Ω→∘ (Ω→SphereMap∙ n') (Ω^→ n' f) p\n\n isNatural-Ω→SphereMap∙ : ∀ n\n → post∘∙ (S₊∙ n) f ∘∙ (Ω→SphereMap∙ n)\n ≡ (Ω→SphereMap∙ n {A = B} ∘∙ Ω^→ n f)\n isNatural-Ω→SphereMap∙ n =\n →∙Homogeneous≡ (isHomogeneous→∙ homogB)\n (funExt (isNatural-Ω→SphereMap n))\n\nmid□ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → (p : typ ((Ω^ (suc n)) A))\n → fst (post∘∙ (S₊∙ (suc n)) (σ∙ A)) (Ω→SphereMap (suc n) p)\n ≡ Ω→SphereMap (suc n) (fst (Ω^→ (suc n) (σ∙ A)) p)\nmid□ {A = A} n p =\n funExt⁻\n (cong fst\n (isNatural-Ω→SphereMap∙\n A (Ω (Susp∙ (typ A)))\n (isHomogeneousPath _ _)\n (σ∙ A) (suc n))) p\n\n----- Bottom square filler -----\nbot□ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (f : (S₊∙ (suc n) →∙ A))\n → suspMap n f\n ≡ botᵣ {A = A} (suc n) (post∘∙ (S₊∙ (suc n)) (σ∙ A) .fst f)\nbot□ {A = A} n f =\n ΣPathP ((funExt (λ { north → refl\n ; south → refl\n ; (merid a i) → refl}))\n , refl)\n\n-- We prove that botᵣ is an equivalence\nbotᵣ⁻' : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → S₊∙ (suc n) →∙ Susp∙ (typ A) → (S₊ n → typ (Ω (Susp∙ (typ A))))\nbotᵣ⁻' zero f false =\n sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f\nbotᵣ⁻' zero f true = refl\nbotᵣ⁻' (suc n) f x =\n sym (snd f)\n ∙∙ cong (fst f) (merid x ∙ sym (merid (ptSn (suc n))))\n ∙∙ snd f\n\nbotᵣ⁻ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → S₊∙ (suc n) →∙ Susp∙ (typ A)\n → (S₊∙ n →∙ Ω (Susp∙ (typ A)))\nfst (botᵣ⁻ {A = A} n f) = botᵣ⁻' {A = A} n f\nsnd (botᵣ⁻ {A = A} zero f) = refl\nsnd (botᵣ⁻ {A = A} (suc n) f) =\n cong (sym (snd f) ∙∙_∙∙ snd f)\n (cong (cong (fst f)) (rCancel (merid (ptSn _))))\n ∙ ∙∙lCancel (snd f)\n\nbotᵣIso : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → Iso (S₊∙ n →∙ Ω (Susp∙ (typ A)))\n (S₊∙ (suc n) →∙ Susp∙ (typ A))\nbotᵣIso {A = A} n = (iso (botᵣ {A = A} n) (botᵣ⁻ {A = A} n) (h n) (retr n))\n where\n h : (n : ℕ) → section (botᵣ {A = A} n) (botᵣ⁻ {A = A} n)\n h zero (f , p) =\n ΣPathP (funExt (λ { base → sym p\n ; (loop i) j → doubleCompPath-filler\n (sym p) (cong f loop) p (~ j) i})\n , λ i j → p (~ i ∨ j))\n h (suc n) (f , p) =\n ΣPathP (funExt (λ { north → sym p\n ; south → sym p ∙ cong f (merid (ptSn _))\n ; (merid a i) j\n → hcomp (λ k\n → λ { (i = i0) → p (~ j ∧ k)\n ; (i = i1) → compPath-filler'\n (sym p) (cong f (merid (ptSn _))) k j\n ; (j = i1) → f (merid a i)})\n (f (compPath-filler\n (merid a) (sym (merid (ptSn _))) (~ j) i))})\n , λ i j → p (~ i ∨ j))\n\n retr : (n : ℕ) → retract (botᵣ {A = A} n) (botᵣ⁻ {A = A} n)\n retr zero (f , p) =\n ΣPathP ((funExt (λ { false → sym (rUnit _) ; true → sym p}))\n , λ i j → p (~ i ∨ j))\n retr (suc n) (f , p) =\n →∙Homogeneous≡ (isHomogeneousPath _ _)\n (funExt λ x → (λ i\n → rUnit (cong-∙ (fst ((botᵣ {A = A}(suc n) (f , p))))\n (merid x)\n (sym (merid (ptSn (suc n)))) i) (~ i))\n ∙∙ (λ i → f x ∙ sym (p i) )\n ∙∙ sym (rUnit (f x)))\n\n-- Right hand composite iso\nIsoΩSphereMapᵣ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → Iso (typ ((Ω^ (suc n)) (Susp∙ (typ A)))) ((S₊∙ (suc n) →∙ Susp∙ (typ A)))\nIsoΩSphereMapᵣ {A = A} n =\n compIso (flipΩIso n)\n (compIso (IsoΩSphereMap n) (botᵣIso {A = A} n))\n\n-- The dependent path between the two suspension functions\nsuspMapPathP : ∀ {ℓ} (A : Pointed ℓ) (n : ℕ)\n → (typ ((Ω^ (suc n)) A) → (typ ((Ω^ (suc (suc n))) (Susp∙ (typ A)))))\n ≡ ((S₊∙ (suc n) →∙ A) → S₊∙ (suc (suc n)) →∙ (Susp∙ (typ A)))\nsuspMapPathP A n i =\n isoToPath (IsoΩSphereMap {A = A} (suc n)) i\n → isoToPath (IsoΩSphereMapᵣ {A = A} (suc n)) i\n\nΩσ→suspMap : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → PathP (λ i → suspMapPathP A n i)\n (suspMapΩ (suc n))\n (suspMap n)\nΩσ→suspMap {A = A} n =\n toPathP (funExt (λ p →\n (λ i → transportRefl\n (Iso.fun (IsoΩSphereMapᵣ {A = A} (suc n))\n (suspMapΩ {A = A} (suc n)\n (Iso.inv (IsoΩSphereMap {A = A} (suc n))\n (transportRefl p i)))) i)\n ∙∙ cong (botᵣ {A = A} (suc n))\n (cong (Ω→SphereMap (suc n) {A = Ω (Susp∙ (typ A)) })\n ((sym (funExt⁻ (cong fst (top□ {A = A} n))\n (invEq (Ω→SphereMap (suc n)\n , isEquiv-Ω→SphereMap (suc n)) p))))\n ∙ (sym (mid□ n (invEq (Ω→SphereMap (suc n)\n , isEquiv-Ω→SphereMap (suc n)) p))\n ∙ cong (σ∙ (fst A , snd A) ∘∙_)\n (secEq (Ω→SphereMap (suc n)\n , isEquiv-Ω→SphereMap (suc n)) p)))\n ∙∙ sym (bot□ n p)))\n\n-- Connectedness of suspFunΩ (Freudenthal)\nsuspMapΩ-connected : ∀ {ℓ} (n : HLevel) (m : ℕ) {A : Pointed ℓ}\n (connA : isConnected (suc (suc n)) (typ A))\n → isConnectedFun ((suc n + suc n) ∸ m) (suspMapΩ {A = A} m)\nsuspMapΩ-connected n zero {A = A} connA = isConnectedσ n connA\nsuspMapΩ-connected n (suc m) {A = A} connA with ((n + suc n) ≟ m)\n... | (lt p) = subst (λ x → isConnectedFun x (suspMapΩ {A = A} (suc m)))\n (sym (n∸m≡0 _ m (<-weaken p)))\n λ b → tt* , (λ {tt* → refl})\n... | (eq q) = subst (λ x → isConnectedFun x (suspMapΩ {A = A} (suc m)))\n (sym (n∸n≡0 m) ∙ cong (_∸ m) (sym q))\n λ b → tt* , (λ {tt* → refl})\n... | (gt p) = isConnectedCong' (n + suc n ∸ m) (suspMapΩ {A = A} m)\n (subst (λ x → isConnectedFun x (suspMapΩ {A = A} m))\n (sym (suc∸-fst (n + suc n) m p))\n (suspMapΩ-connected n m connA))\n (snd (suspMapΩ∙ m))\n\n-- We prove that the right iso is structure preserving\nprivate\n invComp : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → S₊∙ n →∙ Ω (Susp∙ (typ A))\n → S₊∙ n →∙ Ω (Susp∙ (typ A))\n → S₊∙ n →∙ Ω (Susp∙ (typ A))\n fst (invComp n f g) x = (fst f x) ∙ (fst g x)\n snd (invComp n f g) = cong₂ _∙_ (snd f) (snd g) ∙ sym (rUnit refl)\n\n -- We prove that it agrees with ∙Π\n ∙Π≡invComp : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → (f g : S₊∙ (suc n) →∙ Ω (Susp∙ (typ A)))\n → ∙Π f g ≡ invComp {A = A} (suc n) f g\n ∙Π≡invComp zero f g =\n →∙Homogeneous≡ (isHomogeneousPath _ _)\n (funExt (λ { base → rUnit refl\n ∙ sym (cong (_∙ fst g (snd (S₊∙ 1))) (snd f)\n ∙ cong (refl ∙_) (snd g))\n ; (loop i) j →\n hcomp (λ k →\n λ { (i = i0) → (rUnit refl\n ∙ sym (cong (_∙ fst g (snd (S₊∙ 1))) (snd f)\n ∙ cong (refl ∙_) (snd g))) j\n ; (i = i1) → (rUnit refl\n ∙ sym (cong (_∙ fst g (snd (S₊∙ 1))) (snd f)\n ∙ cong (refl ∙_) (snd g))) j\n ; (j = i0) → ((sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f)\n ∙ (sym (snd g) ∙∙ cong (fst g) loop ∙∙ snd g)) i\n ; (j = i1) → cong₂Funct _∙_\n (cong (fst f) loop) (cong (fst g) loop) (~ k) i})\n (hcomp (λ k →\n λ { (i = i0) → (rUnit refl\n ∙ sym (cong (_∙ snd g (~ k)) (λ j → snd f (j ∨ ~ k))\n ∙ cong (refl ∙_) (λ j → snd g (j ∨ ~ k)))) j\n ; (i = i1) → (rUnit refl\n ∙ sym (cong (_∙ snd g (~ k)) (λ j → snd f (j ∨ ~ k))\n ∙ cong (refl ∙_) (λ j → snd g (j ∨ ~ k)))) j\n ; (j = i0) → ((sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f)\n ∙ (sym (snd g) ∙∙ cong (fst g) loop ∙∙ snd g)) i\n ; (j = i1) → (cong (_∙ snd g (~ k))\n (doubleCompPath-filler (sym (snd f))\n (cong (fst f) loop)\n (snd f) (~ k)) ∙\n cong ((snd f (~ k)) ∙_)\n (doubleCompPath-filler (sym (snd g))\n (cong (fst g) loop) (snd g) (~ k))) i})\n (hcomp (λ k →\n λ { (i = i0) → (rUnit (rUnit refl)\n ∙ cong (rUnit refl ∙_) (cong sym (rUnit refl))) k j\n ; (i = i1) → (rUnit (rUnit refl)\n ∙ cong (rUnit refl ∙_) (cong sym (rUnit refl))) k j\n ; (j = i0) → ((sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f)\n ∙ (sym (snd g) ∙∙ cong (fst g) loop ∙∙ snd g)) i\n ; (j = i1) → (cong (_∙ refl)\n ((sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f))\n ∙ cong (refl ∙_)\n (sym (snd g) ∙∙ cong (fst g) loop ∙∙ snd g)) i})\n ((cong (λ x → rUnit x j)\n (sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f)\n ∙ cong (λ x → lUnit x j)\n (sym (snd g) ∙∙ cong (fst g) loop ∙∙ snd g)) i)))}))\n ∙Π≡invComp {A = A} (suc n) f g =\n →∙Homogeneous≡ (isHomogeneousPath _ _)\n (funExt λ { north → rUnit refl\n ∙ sym (cong (fst f north ∙_) (snd g)\n ∙ cong (_∙ refl) (snd f))\n ; south → rUnit refl\n ∙ sym (cong₂ _∙_\n (cong (fst f) (sym (merid (ptSn _))) ∙ snd f)\n (cong (fst g) (sym (merid (ptSn _))) ∙ snd g))\n ; (merid a i) j → p a i j})\n where\n module _ (a : S₊ (suc n)) where\n f-n = fst f north\n g-n = fst g north\n cong-f = (cong (fst f) (merid a ∙ sym (merid (ptSn _))))\n cong-g = (cong (fst g) (merid a ∙ sym (merid (ptSn _))))\n c-f = sym (snd f) ∙∙ cong-f ∙∙ snd f\n c-g = sym (snd g) ∙∙ cong-g ∙∙ snd g\n\n p : I → I → fst (Ω (Susp∙ (typ A)))\n p i j =\n hcomp (λ k →\n λ { (i = i0) → (rUnit (λ _ → snd (Susp∙ (typ A)))\n ∙ sym ((cong (fst f north ∙_) (snd g)\n ∙ cong (_∙ refl) (snd f)))) j\n ; (i = i1) → (rUnit refl\n ∙ sym (cong₂ _∙_\n (compPath-filler'\n (cong (fst f) (sym (merid (ptSn _)))) (snd f) k)\n (compPath-filler'\n (cong (fst g) (sym (merid (ptSn _)))) (snd g) k))) j\n ; (j = i0) → (c-f ∙ c-g) i\n ; (j = i1) → fst f (compPath-filler\n (merid a)\n (sym (merid (ptSn _))) (~ k) i)\n ∙ fst g (compPath-filler\n (merid a)\n (sym (merid (ptSn _))) (~ k) i)})\n (hcomp (λ k →\n λ {(i = i0) → (rUnit (λ _ → snd (Susp∙ (typ A)))\n ∙ sym ((cong (fst f north ∙_) (snd g)\n ∙ cong (_∙ refl) (snd f)))) j\n ; (i = i1) → (rUnit refl ∙ sym (cong₂ _∙_ (snd f) (snd g))) j\n ; (j = i0) → (c-f ∙ c-g) i\n ; (j = i1) → cong₂Funct _∙_ cong-f cong-g (~ k) i})\n (hcomp (λ k →\n λ {(i = i0) → (rUnit refl\n ∙ sym (compPath-filler'\n ((cong (fst f north ∙_) (snd g)))\n (cong (_∙ refl) (snd f)) k)) j\n ; (i = i1) → (rUnit refl\n ∙ sym (cong₂ _∙_ (λ i → snd f (i ∨ ~ k)) (snd g))) j\n ; (j = i0) → (c-f ∙ c-g) i\n ; (j = i1) → (cong (λ x → x ∙ snd g (~ k))\n (doubleCompPath-filler refl\n cong-f (snd f) (~ k))\n ∙ cong ((snd f (~ k)) ∙_)\n (doubleCompPath-filler\n (sym (snd g)) cong-g refl (~ k))) i})\n (hcomp (λ k →\n λ {(i = i0) → compPath-filler\n (rUnit (λ _ → snd (Susp∙ (typ A))))\n (sym ((cong (_∙ refl) (snd f)))) k j\n ; (i = i1) → compPath-filler\n (rUnit refl)\n (sym (cong (refl ∙_) (snd g))) k j\n ; (j = i0) → (c-f ∙ c-g) i\n ; (j = i1) → (cong (_∙ refl)\n ((λ j → snd f (~ j ∧ ~ k)) ∙∙ cong-f ∙∙ snd f)\n ∙ cong (refl ∙_)\n (sym (snd g) ∙∙ cong-g ∙∙ (λ j → snd g (j ∧ ~ k)))) i})\n (((cong (λ x → rUnit x j) c-f) ∙ (cong (λ x → lUnit x j) c-g)) i))))\n\nhom-botᵣ⁻ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → (f g : S₊∙ (suc n) →∙ Susp∙ (typ A))\n → botᵣ⁻ {A = A} n (∙Π f g)\n ≡ invComp {A = A} n (botᵣ⁻ {A = A} n f) (botᵣ⁻ {A = A} n g)\nhom-botᵣ⁻ zero f g =\n ΣPathP ((funExt (λ { false → sym (rUnit _)\n ; true → (rUnit _)}))\n , ((λ i j → rUnit refl (i ∧ ~ j))\n ▷ lUnit (sym (rUnit refl))))\nhom-botᵣ⁻ (suc n) f g =\n →∙Homogeneous≡ (isHomogeneousPath _ _)\n (funExt (λ x → (sym (rUnit (cong (fst (∙Π f g)) (merid x ∙ sym (merid (ptSn _))))))\n ∙∙ cong-∙ (fst (∙Π f g)) (merid x) (sym (merid (ptSn _)))\n ∙∙ cong (cong (fst (∙Π f g)) (merid x) ∙_) (cong sym lem)\n ∙ sym (rUnit (cong (fst (∙Π f g)) (merid x)))))\n where\n lem : cong (fst (∙Π f g)) (merid (ptSn (suc n))) ≡ refl\n lem = (λ i → (sym (snd f) ∙∙ cong (fst f) (rCancel (merid (ptSn _)) i) ∙∙ snd f)\n ∙ (sym (snd g) ∙∙ cong (fst g) (rCancel (merid (ptSn _)) i) ∙∙ snd g))\n ∙ (λ i → ∙∙lCancel (snd f) i ∙ ∙∙lCancel (snd g) i)\n ∙ sym (rUnit refl)\n\n-- We get that botᵣ⁻ (and hence botᵣ) is homomorphism\nhom-botᵣ⁻' : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → (f g : S₊∙ (suc (suc n)) →∙ Susp∙ (typ A))\n → botᵣ⁻ {A = A} (suc n) (∙Π f g)\n ≡ ∙Π (botᵣ⁻ {A = A} (suc n) f) (botᵣ⁻ {A = A} (suc n) g)\nhom-botᵣ⁻' {A = A} n f g =\n hom-botᵣ⁻ {A = A} (suc n) f g\n ∙ sym (∙Π≡invComp {A = A} _ (botᵣ⁻ {A = A} _ f) (botᵣ⁻ {A = A} _ g))\n\nhom-botᵣ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → (f g : S₊∙ (suc n) →∙ Ω (Susp∙ (typ A)))\n → botᵣ {A = A} (suc n) (∙Π f g)\n ≡ ∙Π (botᵣ {A = A} (suc n) f) (botᵣ {A = A} (suc n) g)\nhom-botᵣ {A = A} n f g =\n morphLemmas.isMorphInv ∙Π ∙Π (botᵣ⁻ {A = A} (suc n))\n (hom-botᵣ⁻' {A = A} n)\n (botᵣ {A = A} (suc n))\n (leftInv (botᵣIso {A = A} (suc n)))\n (rightInv (botᵣIso {A = A} (suc n)))\n f g\n\nisHom-IsoΩSphereMapᵣ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n (p q : typ ((Ω^ (2 + n)) (Susp∙ (typ A))))\n → Iso.fun (IsoΩSphereMapᵣ (suc n)) (p ∙ q)\n ≡ ∙Π (Iso.fun (IsoΩSphereMapᵣ (suc n)) p)\n (Iso.fun (IsoΩSphereMapᵣ (suc n)) q)\nisHom-IsoΩSphereMapᵣ {A = A} n p q =\n cong (botᵣ {A = A} (suc n))\n (cong (Ω→SphereMap (suc n) {A = Ω (Susp∙ (typ A))})\n (flipΩIsopres· n p q)\n ∙ isHom-Ω→SphereMap n (fun (flipΩIso (suc n)) p)\n (fun (flipΩIso (suc n)) q))\n ∙ hom-botᵣ n _ _\n\nsuspMapΩ→hom : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (p q : typ ((Ω^ (suc n)) A))\n → suspMapΩ (suc n) (p ∙ q)\n ≡ suspMapΩ (suc n) p ∙ suspMapΩ (suc n) q\nsuspMapΩ→hom {A = A} n p q =\n cong (sym (snd (suspMapΩ∙ {A = A} n)) ∙∙_∙∙ snd (suspMapΩ∙ {A = A} n))\n (cong-∙ (fst (suspMapΩ∙ {A = A} n)) p q)\n ∙ help (snd (suspMapΩ∙ {A = A} n)) _ _\n where\n help : ∀ {ℓ} {A : Type ℓ} {x y : A} (p : x ≡ y) (q s : x ≡ x)\n → sym p ∙∙ (q ∙ s) ∙∙ p\n ≡ (sym p ∙∙ q ∙∙ p) ∙ (sym p ∙∙ s ∙∙ p)\n help {x = x} =\n J (λ y p → (q s : x ≡ x)\n → sym p ∙∙ (q ∙ s) ∙∙ p\n ≡ (sym p ∙∙ q ∙∙ p ) ∙ (sym p ∙∙ s ∙∙ p))\n λ q s → sym (rUnit (q ∙ s))\n ∙ cong₂ _∙_ (rUnit q) (rUnit s)\n\nprivate\n transportLem : ∀ {ℓ} {A B : Type ℓ}\n (_+A_ : A → A → A) (_+B_ : B → B → B)\n → (e : Iso A B)\n → ((x y : A) → fun e (x +A y) ≡ fun e x +B fun e y)\n → PathP (λ i → isoToPath e i → isoToPath e i → isoToPath e i)\n _+A_ _+B_\n transportLem _+A_ _+B_ e hom =\n toPathP (funExt (λ p → funExt λ q →\n (λ i → transportRefl\n (fun e (inv e (transportRefl p i)\n +A inv e (transportRefl q i))) i)\n ∙∙ hom (inv e p) (inv e q)\n ∙∙ cong₂ _+B_ (rightInv e p) (rightInv e q)))\n\n pₗ : ∀ {ℓ} (A : Pointed ℓ) (n : ℕ)\n → typ (Ω ((Ω^ n) A)) ≡ (S₊∙ (suc n) →∙ A)\n pₗ A n = isoToPath (IsoΩSphereMap {A = A} (suc n))\n\n pᵣ : ∀ {ℓ} (A : Pointed ℓ) (n : ℕ)\n → typ ((Ω^ (2 + n)) (Susp∙ (typ A)))\n ≡ (S₊∙ (suc (suc n)) →∙ Susp∙ (typ A))\n pᵣ A n = isoToPath (IsoΩSphereMapᵣ {A = A} (suc n))\n\n∙Π→∙ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → PathP (λ i → pₗ A n i → pₗ A n i → pₗ A n i) _∙_ ∙Π\n∙Π→∙ {A = A} n =\n transportLem _∙_ ∙Π (IsoΩSphereMap {A = A} (suc n)) (isHom-Ω→SphereMap n)\n\n∙Π→∙ᵣ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → PathP (λ i → pᵣ A n i → pᵣ A n i → pᵣ A n i) _∙_ ∙Π\n∙Π→∙ᵣ {A = A} n =\n transportLem _∙_ ∙Π (IsoΩSphereMapᵣ {A = A} (suc n)) (isHom-IsoΩSphereMapᵣ n)\n\nisHom-suspMap : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (f g : S₊∙ (suc n) →∙ A)\n → suspMap n (∙Π f g)\n ≡ ∙Π (suspMap n f) (suspMap n g)\nisHom-suspMap {A = A} n =\n transport (λ i → (f g : isoToPath (IsoΩSphereMap {A = A} (suc n)) i)\n → Ωσ→suspMap n i (∙Π→∙ n i f g)\n ≡ ∙Π→∙ᵣ n i (Ωσ→suspMap n i f) (Ωσ→suspMap n i g))\n (suspMapΩ→hom n)\n\nsuspMapπHom : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → GroupHom (πGr n A) (πGr (suc n) (Susp∙ (typ A)))\nfst (suspMapπHom {A = A} n) = suspMapπ (suc n)\nsnd (suspMapπHom {A = A} n) =\n makeIsGroupHom\n (sElim2 (λ _ _ → isSetPathImplicit)\n λ p q → cong ∣_∣₂ (suspMapΩ→hom n p q))\n\nsuspMapπ'Hom : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)\n → GroupHom (π'Gr n A) (π'Gr (suc n) (Susp∙ (typ A)))\nfst (suspMapπ'Hom {A = A} n) = suspMapπ' n\nsnd (suspMapπ'Hom {A = A} n) =\n makeIsGroupHom (sElim2 (λ _ _ → isSetPathImplicit)\n λ f g → cong ∣_∣₂ (isHom-suspMap n f g))\n\nπGr≅π'Grᵣ : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ)\n → GroupIso (πGr (suc n) (Susp∙ (typ A)))\n (π'Gr (suc n) (Susp∙ (typ A)))\nfst (πGr≅π'Grᵣ n A) = setTruncIso (IsoΩSphereMapᵣ (suc n))\nsnd (πGr≅π'Grᵣ n A) =\n makeIsGroupHom (sElim2 (λ _ _ → isSetPathImplicit)\n λ f g → cong ∣_∣₂ (isHom-IsoΩSphereMapᵣ n f g))\n\nprivate\n isConnectedPres : ∀ {ℓ} {A : Pointed ℓ} (con n : ℕ)\n → isConnectedFun con (suspMapΩ∙ {A = A} (suc n) .fst)\n → isConnectedFun con (suspMap {A = A} n)\n isConnectedPres {A = A} con n hyp =\n transport (λ i → isConnectedFun con (Ωσ→suspMap {A = A} n i)) hyp\n\nisConnectedSuspMap : (n m : ℕ)\n → isConnectedFun ((m + suc m) ∸ n) (suspMap {A = S₊∙ (suc m)} n)\nisConnectedSuspMap n m =\n isConnectedPres _ _ (suspMapΩ-connected m (suc n) (sphereConnected (suc m)))\n\nisSurjectiveSuspMap : (n : ℕ)\n → isSurjective (suspMapπ'Hom {A = S₊∙ (2 + n)} (2 + n))\nisSurjectiveSuspMap n =\n sElim (λ _ → isProp→isSet squash₁)\n λ f →\n trRec\n ((subst (λ x → isOfHLevel x (isInIm (suspMapπ'Hom (2 + n)) ∣ f ∣₂))\n (sym (snd (lem n n)))\n (isProp→isOfHLevelSuc {A = isInIm (suspMapπ'Hom (2 + n)) ∣ f ∣₂}\n (fst (lem n n)) squash₁)))\n (λ p → ∣ ∣ fst p ∣₂ , (cong ∣_∣₂ (snd p)) ∣₁)\n (fst (isConnectedSuspMap (2 + n) (suc n) f))\n where\n lem : (m n : ℕ) → Σ[ x ∈ ℕ ] ((m + suc (suc n) ∸ suc n) ≡ suc x)\n lem zero zero = 0 , refl\n lem (suc m) zero = suc m , +-comm m 2\n lem zero (suc n) = lem zero n\n lem (suc m) (suc n) = fst (lem (suc m) n) , (cong (_∸ (suc n)) (+-comm m (3 + n))\n ∙∙ cong (_∸ n) (+-comm (suc (suc n)) m)\n ∙∙ snd (lem (suc m) n))\n", "meta": {"hexsha": "768171a5cfcadf93823587833b2c3d3de4fdc85c", "size": 25193, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Homotopy/Group/SuspensionMap.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Homotopy/Group/SuspensionMap.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Homotopy/Group/SuspensionMap.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": 41.232405892, "max_line_length": 87, "alphanum_fraction": 0.442146628, "num_tokens": 10404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.709019146082187, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3849004614743421}} {"text": "open import FRP.JS.Maybe using ( Maybe ; just ; nothing )\nopen import FRP.JS.Bool using ( Bool ; true ; false ; _∨_ ; _∧_ )\nopen import FRP.JS.True using ( True ; tt ; contradiction ; ∧-intro ; ∧-elim₁ ; ∧-elim₂ )\nopen import FRP.JS.Nat using ( ℕ ; _+_ ; _∸_ )\nopen import FRP.JS.Keys using ( Keys ; IKeys ; _; swap)\nimport Function.Equality\n-- open import Relation.Binary using (Setoid)\n-- import Relation.Binary.Reasoning.Setoid as SetoidR\n\nimport Categories.Category\nimport Categories.Functor\nimport Categories.Category.Instance.Setoids\nimport Categories.Monad.Relative\nimport Categories.Category.Equivalence\nimport Categories.Category.Cocartesian\nimport Categories.Category.Construction.Functors\nimport Categories.Category.Product\nimport Categories.NaturalTransformation\nimport Categories.NaturalTransformation.NaturalIsomorphism\n\nimport SecondOrder.Arity\nimport SecondOrder.Signature\nimport SecondOrder.Metavariable\nimport SecondOrder.VRenaming\nimport SecondOrder.MRenaming\nimport SecondOrder.Term\nimport SecondOrder.Substitution\nimport SecondOrder.RelativeMonadMorphism\nimport SecondOrder.Instantiation\nimport SecondOrder.IndexedCategory\nimport SecondOrder.RelativeKleisli\n\n\nmodule SecondOrder.Mslot\n {ℓ}\n {𝔸 : SecondOrder.Arity.Arity}\n (Σ : SecondOrder.Signature.Signature ℓ 𝔸)\n where\n\n open SecondOrder.Signature.Signature Σ\n open SecondOrder.Metavariable Σ\n open SecondOrder.Term Σ\n open SecondOrder.VRenaming Σ\n open SecondOrder.MRenaming Σ\n -- open SecondOrder.Substitution Σ\n -- open import SecondOrder.RelativeMonadMorphism\n -- open SecondOrder.Instantiation\n open Categories.Category\n open Categories.Functor using (Functor)\n open Categories.NaturalTransformation renaming (id to idNt)\n open Categories.NaturalTransformation.NaturalIsomorphism renaming (refl to reflNt; sym to symNt; trans to transNt)\n open Categories.Category.Construction.Functors\n open Categories.Category.Instance.Setoids\n open Categories.Category.Product\n open Function.Equality using () renaming (setoid to Π-setoid)\n open SecondOrder.IndexedCategory\n -- open import SecondOrder.RelativeKleisli\n\n MTele = MContexts\n VTele = VContexts\n\n -- the codomain category of the MSlots functor. It should be equivalent to the\n -- functor category [ MTele x VTele , < Setoid >ₛₒᵣₜ ]\n -- objects are functors, which are really pairs of functions, one on objects\n -- one on morphisms\n -- morphisms in this category are natural transformations\n\n module _ where\n open Category\n open NaturalTransformation\n open Function.Equality renaming (_∘_ to _∙_)\n\n Mslots : Functor MContexts (IndexedCategory VContext (IndexedCategory sort (Setoids ℓ ℓ)))\n Mslots = \n let open Categories.NaturalTransformation in\n let open NaturalTransformation in\n let open Relation.Binary.PropositionalEquality.≡-Reasoning in\n record\n { F₀ = λ Θ Γ A → setoid ([ Γ , A ]∈ Θ)\n ; F₁ = λ ι Γ A → record { _⟨$⟩_ = λ M → ι M ; cong = λ M≡N → cong ι M≡N }\n ; identity = λ {Θ} Γ A {M} {N} M≡N → cong idᵐ M≡N\n ; homomorphism = λ {Θ} {Ψ} {Ξ} {ι} {μ} Γ A M≡N → cong (μ ∘ᵐ ι) M≡N\n ; F-resp-≈ = λ {Θ} {Ψ} {ι} {μ} ι≡ᵐμ Γ A {M} {N} M≡N →\n begin\n ι M ≡⟨ cong ι M≡N ⟩\n ι N ≡⟨ ι≡ᵐμ N ⟩\n μ N\n ∎\n }\n", "meta": {"hexsha": "27ffbcca21fd109e5a7d3d3d390b99381925fcd3", "size": 3269, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/SecondOrder/Mslot.agda", "max_stars_repo_name": "cilinder/formaltt", "max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z", "max_issues_repo_path": "src/SecondOrder/Mslot.agda", "max_issues_repo_name": "cilinder/formaltt", "max_issues_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z", "max_forks_repo_path": "src/SecondOrder/Mslot.agda", "max_forks_repo_name": "cilinder/formaltt", "max_forks_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z", "avg_line_length": 36.3222222222, "max_line_length": 116, "alphanum_fraction": 0.7280513919, "num_tokens": 939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7634837527911056, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.3847241741301372}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import cohomology.ChainComplex\nopen import cohomology.Theory\nopen import groups.KernelImage\nopen import cw.CW\n\nmodule cw.cohomology.ReconstructedCochainComplex {i : ULevel} (OT : OrdinaryTheory i) where\n\n open OrdinaryTheory OT\n import cw.cohomology.TipAndAugment OT as TAA\n import cw.cohomology.TipCoboundary OT as TC\n import cw.cohomology.HigherCoboundary OT as HC\n open import cw.cohomology.WedgeOfCells OT\n\n cochain-template : ∀ {n} (⊙skel : ⊙Skeleton {i} n) {m}\n → Dec (m ≤ n) → AbGroup i\n cochain-template ⊙skel (inr _) = Lift-abgroup {j = i} Unit-abgroup\n cochain-template ⊙skel {m = 0} (inl 0≤n) = TAA.C2×CX₀-abgroup (⊙cw-take 0≤n ⊙skel) 0\n cochain-template ⊙skel {m = S m} (inl Sm≤n) = CXₙ/Xₙ₋₁-abgroup (⊙cw-take Sm≤n ⊙skel) (ℕ-to-ℤ (S m))\n\n cochain-is-abelian-template : ∀ {n} (⊙skel : ⊙Skeleton {i} n) {m} m≤n?\n → is-abelian (AbGroup.grp (cochain-template ⊙skel {m} m≤n?))\n cochain-is-abelian-template ⊙skel m≤n? = AbGroup.comm (cochain-template ⊙skel m≤n?)\n\n abstract\n private\n coboundary-first-template : ∀ {n} (⊙skel : ⊙Skeleton {i} n)\n → (0≤n : 0 ≤ n) (1≤n : 1 ≤ n)\n → ⊙cw-init (⊙cw-take 1≤n ⊙skel) == ⊙cw-take (≤-trans lteS 1≤n) ⊙skel\n → ⊙cw-take (≤-trans lteS 1≤n) ⊙skel == ⊙cw-take 0≤n ⊙skel\n → TAA.C2×CX₀ (⊙cw-take 0≤n ⊙skel) 0 →ᴳ CXₙ/Xₙ₋₁ (⊙cw-take 1≤n ⊙skel) 1\n coboundary-first-template ⊙skel 0≤n 1≤n path₀ path₁ =\n TC.cw-co∂-head (⊙cw-take 1≤n ⊙skel)\n ∘ᴳ transport!ᴳ (λ ⊙skel → TAA.C2×CX₀ ⊙skel 0) (path₀ ∙ path₁)\n\n coboundary-higher-template : ∀ {n} (⊙skel : ⊙Skeleton {i} n)\n → {m : ℕ} (Sm≤n : S m ≤ n) (SSm≤n : S (S m) ≤ n)\n → ⊙cw-init (⊙cw-take SSm≤n ⊙skel) == ⊙cw-take (≤-trans lteS SSm≤n) ⊙skel\n → ⊙cw-take (≤-trans lteS SSm≤n) ⊙skel == ⊙cw-take Sm≤n ⊙skel\n → CXₙ/Xₙ₋₁ (⊙cw-take Sm≤n ⊙skel) (ℕ-to-ℤ (S m))\n →ᴳ CXₙ/Xₙ₋₁ (⊙cw-take SSm≤n ⊙skel) (ℕ-to-ℤ (S (S m)))\n coboundary-higher-template ⊙skel {m} Sm≤n SSm≤n path₀ path₁ =\n HC.cw-co∂-last (⊙cw-take SSm≤n ⊙skel)\n ∘ᴳ transport!ᴳ (λ ⊙skel → CXₙ/Xₙ₋₁ ⊙skel (ℕ-to-ℤ (S m))) (path₀ ∙ path₁)\n\n coboundary-template : ∀ {n} (⊙skel : ⊙Skeleton {i} n)\n → {m : ℕ} (m≤n? : Dec (m ≤ n)) (Sm≤n? : Dec (S m ≤ n))\n → AbGroup.grp (cochain-template ⊙skel m≤n?)\n →ᴳ AbGroup.grp (cochain-template ⊙skel Sm≤n?)\n coboundary-template ⊙skel _ (inr _) = cst-hom\n coboundary-template ⊙skel (inr m≰n) (inl Sm≤n) = ⊥-rec $ m≰n (≤-trans lteS Sm≤n)\n coboundary-template ⊙skel {m = 0} (inl 0≤n) (inl 1≤n) =\n coboundary-first-template ⊙skel 0≤n 1≤n (⊙cw-init-take 1≤n ⊙skel)\n (ap (λ 0≤n → ⊙cw-take 0≤n ⊙skel) (≤-has-all-paths (≤-trans lteS 1≤n) 0≤n))\n coboundary-template ⊙skel {m = S m} (inl Sm≤n) (inl SSm≤n) =\n coboundary-higher-template ⊙skel Sm≤n SSm≤n (⊙cw-init-take SSm≤n ⊙skel)\n (ap (λ Sm≤n → ⊙cw-take Sm≤n ⊙skel) (≤-has-all-paths (≤-trans lteS SSm≤n) Sm≤n))\n\n cochain-complex : ∀ {n} → ⊙Skeleton {i} n → CochainComplex i\n cochain-complex {n} ⊙skel = record {M} where\n module M where\n head : AbGroup i\n head = C-abgroup 0 (⊙Lift ⊙Bool)\n\n cochain : ℕ → AbGroup i\n cochain m = cochain-template ⊙skel (≤-dec m n)\n\n augment : C 0 (⊙Lift ⊙Bool) →ᴳ AbGroup.grp (cochain 0)\n augment = TAA.cw-coε (⊙cw-take (O≤ n) ⊙skel)\n\n coboundary : ∀ m → (AbGroup.grp (cochain m) →ᴳ AbGroup.grp (cochain (S m)))\n coboundary m = coboundary-template ⊙skel (≤-dec m n) (≤-dec (S m) n)\n\n {- Properties of coboundaries -}\n\n {- lemmas of paths -}\n private\n abstract\n path-lemma₀ : ∀ {n} (⊙skel : ⊙Skeleton {i} (S n)) {m} (m τ →\n τ tcomplete\n comp-synth gc ec SConst = TCBase\n comp-synth gc (ECAsc x ec) (SAsc x₁) = x\n comp-synth gc ec (SVar x) = gc _ _ x\n comp-synth gc (ECAp ec ec₁) (SAp _ wt MAHole x₁) with comp-synth gc ec wt\n ... | ()\n comp-synth gc (ECAp ec ec₁) (SAp _ wt MAArr x₁) with comp-synth gc ec wt\n comp-synth gc (ECAp ec ec₁) (SAp _ wt MAArr x₁) | TCArr qq qq₁ = qq₁\n comp-synth gc () SEHole\n comp-synth gc () (SNEHole _ wt)\n comp-synth gc (ECLam2 ec x₁) (SLam x₂ wt) = TCArr x₁ (comp-synth (gcomp-extend gc x₁ x₂) ec wt)\n comp-synth gc (ECFst ec) (SFst wt MPHole) = comp-synth gc ec wt\n comp-synth gc (ECFst ec) (SFst wt MPProd) = lem-comp-prod1 (comp-synth gc ec wt)\n comp-synth gc (ECSnd ec) (SSnd wt MPHole) = comp-synth gc ec wt\n comp-synth gc (ECSnd ec) (SSnd wt MPProd) = lem-comp-prod2 (comp-synth gc ec wt)\n comp-synth gc (ECPair ec ec₁) (SPair x wt wt₁) = TCProd (comp-synth gc ec wt) (comp-synth gc ec₁ wt₁)\n\n -- complete boxed values are just values\n lem-comp-boxed-val : {Δ : hctx} {d : iexp} {τ : typ} {Γ : tctx} →\n Δ , Γ ⊢ d :: τ →\n d dcomplete →\n d boxedval →\n d val\n lem-comp-boxed-val wt comp (BVVal VConst) = VConst\n lem-comp-boxed-val wt comp (BVVal VLam) = VLam\n lem-comp-boxed-val wt comp (BVVal (VPair x x₁)) = VPair x x₁\n lem-comp-boxed-val (TAPair wt wt₁) (DCPair comp comp₁) (BVPair bv bv₁) = VPair (lem-comp-boxed-val wt comp bv)\n (lem-comp-boxed-val wt₁ comp₁ bv₁)\n lem-comp-boxed-val (TACast wt x₃) (DCCast comp x₁ x₂) (BVArrCast x bv) = abort (x (complete-consistency x₃ x₁ x₂))\n lem-comp-boxed-val (TACast wt x₁) (DCCast comp x₂ x₃) (BVProdCast x bv) = abort (x (complete-consistency x₁ x₂ x₃))\n lem-comp-boxed-val (TACast wt x₁) (DCCast comp x₂ ()) (BVHoleCast x bv)\n", "meta": {"hexsha": "c8691e6a7901ffcacef193b73e35f5ba0bc48f4a", "size": 5229, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lemmas-complete.agda", "max_stars_repo_name": "hazelgrove/hazel-palette-agda", "max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z", "max_issues_repo_path": "lemmas-complete.agda", "max_issues_repo_name": "hazelgrove/hazel-palette-agda", "max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z", "max_forks_repo_path": "lemmas-complete.agda", "max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda", "max_forks_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a", "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": 50.7669902913, "max_line_length": 117, "alphanum_fraction": 0.6326257411, "num_tokens": 1868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.3845187302845596}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Basics\nopen import lib.types.Sigma\nopen import lib.types.Group\nopen import lib.types.CommutingSquare\nopen import lib.groups.Homomorphism\nopen import lib.groups.Isomorphism\n\nmodule lib.groups.CommutingSquare where\n\n-- A new type to keep the parameters.\nrecord CommSquareᴳ {i₀ i₁ j₀ j₁}\n {G₀ : Group i₀} {G₁ : Group i₁} {H₀ : Group j₀} {H₁ : Group j₁}\n (φ₀ : G₀ →ᴳ H₀) (φ₁ : G₁ →ᴳ H₁) (ξG : G₀ →ᴳ G₁) (ξH : H₀ →ᴳ H₁)\n : Type (lmax (lmax i₀ i₁) (lmax j₀ j₁)) where\n constructor comm-sqrᴳ\n field\n commutesᴳ : ∀ g₀ → GroupHom.f (ξH ∘ᴳ φ₀) g₀ == GroupHom.f (φ₁ ∘ᴳ ξG) g₀\n\ninfixr 0 _□$ᴳ_\n_□$ᴳ_ = CommSquareᴳ.commutesᴳ\n\nis-csᴳ-equiv : ∀ {i₀ i₁ j₀ j₁}\n {G₀ : Group i₀} {G₁ : Group i₁} {H₀ : Group j₀} {H₁ : Group j₁}\n {φ₀ : G₀ →ᴳ H₀} {φ₁ : G₁ →ᴳ H₁} {ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁}\n → CommSquareᴳ φ₀ φ₁ ξG ξH → Type (lmax (lmax i₀ i₁) (lmax j₀ j₁))\nis-csᴳ-equiv {ξG = ξG} {ξH} _ = is-equiv (GroupHom.f ξG) × is-equiv (GroupHom.f ξH)\n\nCommSquareEquivᴳ : ∀ {i₀ i₁ j₀ j₁}\n {G₀ : Group i₀} {G₁ : Group i₁} {H₀ : Group j₀} {H₁ : Group j₁}\n (φ₀ : G₀ →ᴳ H₀) (φ₁ : G₁ →ᴳ H₁) (ξG : G₀ →ᴳ G₁) (ξH : H₀ →ᴳ H₁)\n → Type (lmax (lmax i₀ i₁) (lmax j₀ j₁))\nCommSquareEquivᴳ φ₀ φ₁ ξG ξH = Σ (CommSquareᴳ φ₀ φ₁ ξG ξH) is-csᴳ-equiv\n\nabstract\n CommSquareᴳ-∘v : ∀ {i₀ i₁ i₂ j₀ j₁ j₂}\n {G₀ : Group i₀} {G₁ : Group i₁} {G₂ : Group i₂}\n {H₀ : Group j₀} {H₁ : Group j₁} {H₂ : Group j₂}\n {φ : G₀ →ᴳ H₀} {ψ : G₁ →ᴳ H₁} {χ : G₂ →ᴳ H₂}\n {ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁}\n {μA : G₁ →ᴳ G₂} {μB : H₁ →ᴳ H₂}\n → CommSquareᴳ ψ χ μA μB\n → CommSquareᴳ φ ψ ξG ξH\n → CommSquareᴳ φ χ (μA ∘ᴳ ξG) (μB ∘ᴳ ξH)\n CommSquareᴳ-∘v {ξG = ξG} {μB = μB} (comm-sqrᴳ □₁₂) (comm-sqrᴳ □₀₁) =\n comm-sqrᴳ λ g₀ → ap (GroupHom.f μB) (□₀₁ g₀) ∙ □₁₂ (GroupHom.f ξG g₀)\n\nCommSquareEquivᴳ-inverse-v : ∀ {i₀ i₁ j₀ j₁}\n {G₀ : Group i₀} {G₁ : Group i₁} {H₀ : Group j₀} {H₁ : Group j₁}\n {φ₀ : G₀ →ᴳ H₀} {φ₁ : G₁ →ᴳ H₁} {ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁}\n → (cse : CommSquareEquivᴳ φ₀ φ₁ ξG ξH)\n → CommSquareEquivᴳ φ₁ φ₀ (GroupIso.g-hom (ξG , fst (snd cse))) (GroupIso.g-hom (ξH , snd (snd cse)))\nCommSquareEquivᴳ-inverse-v (comm-sqrᴳ cs , ise)\n with CommSquareEquiv-inverse-v (comm-sqr cs , ise)\n... | (comm-sqr cs' , ise') = cs'' , ise' where abstract cs'' = comm-sqrᴳ cs'\n\nCommSquareᴳ-inverse-v : ∀ {i₀ i₁ j₀ j₁}\n {G₀ : Group i₀} {G₁ : Group i₁} {H₀ : Group j₀} {H₁ : Group j₁}\n {φ₀ : G₀ →ᴳ H₀} {φ₁ : G₁ →ᴳ H₁} {ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁}\n → CommSquareᴳ φ₀ φ₁ ξG ξH\n → (ξG-ise : is-equiv (GroupHom.f ξG)) (ξH-ise : is-equiv (GroupHom.f ξH))\n → CommSquareᴳ φ₁ φ₀ (GroupIso.g-hom (ξG , ξG-ise)) (GroupIso.g-hom (ξH , ξH-ise))\nCommSquareᴳ-inverse-v cs ξG-ise ξH-ise = fst (CommSquareEquivᴳ-inverse-v (cs , ξG-ise , ξH-ise))\n\n-- basic facts nicely represented in commuting squares\n\ninv-hom-natural-comm-sqr : ∀ {i j} (G : AbGroup i) (H : AbGroup j)\n (φ : AbGroup.grp G →ᴳ AbGroup.grp H)\n → CommSquareᴳ φ φ (inv-hom G) (inv-hom H)\ninv-hom-natural-comm-sqr _ _ φ = comm-sqrᴳ λ g → ! (GroupHom.pres-inv φ g)\n", "meta": {"hexsha": "5ea33d09d727cb53460e9178794fe92df7e84cce", "size": 3037, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/groups/CommutingSquare.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "core/lib/groups/CommutingSquare.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "core/lib/groups/CommutingSquare.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 42.1805555556, "max_line_length": 102, "alphanum_fraction": 0.6094830425, "num_tokens": 1591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.3845187302845595}} {"text": "{- Jesper Cockx, 26-05-2014\n Issue 1023\n Example by Maxime Denes, adapted by Andreas Abel\n-}\n\n{-# OPTIONS --cubical-compatible --guardedness #-}\n\nmodule CoinductionAndUnivalence where\n\nopen import Common.Coinduction\nopen import Common.Equality\n\nprop = Set\n\ndata False : prop where\n\nmagic : ∀ {a} {A : Set a} → False → A\nmagic ()\n\ndata Pandora : prop where\n C : ∞ False → Pandora\n\npostulate\n ext : (f : False → Pandora) → (g : Pandora → False) →\n (∀ x → f (g x) ≡ x) → (∀ y → g (f y) ≡ y) →\n False ≡ Pandora\n\nfoo : False ≡ Pandora\nfoo = ext f g fg gf\n where\n f : False → Pandora\n f ()\n\n g : Pandora → False\n g (C c) = ♭ c\n\n fg : ∀ x → f (g x) ≡ x\n fg x = magic (g x)\n\n gf : ∀ y → g (f y) ≡ y\n gf ()\n\nloop : False\nloop rewrite foo = C (♯ loop)\n", "meta": {"hexsha": "63624c2ef762ef67411066979f573b6d9ae87db7", "size": 787, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/CoinductionAndUnivalence.agda", "max_stars_repo_name": "KDr2/agda", "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": ["BSD-2-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/CoinductionAndUnivalence.agda", "max_issues_repo_name": "KDr2/agda", "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_forks_repo_path": "test/Fail/CoinductionAndUnivalence.agda", "max_forks_repo_name": "KDr2/agda", "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.4888888889, "max_line_length": 55, "alphanum_fraction": 0.5667090216, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8198933183101077, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.3843583024572657}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Substitution.Introductions.Application {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped\nopen import Definition.Untyped.Properties\nopen import Definition.Typed\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.Irrelevance\nopen import Definition.LogicalRelation.Properties\nopen import Definition.LogicalRelation.Application\nopen import Definition.LogicalRelation.Substitution\nopen import Definition.LogicalRelation.Substitution.Introductions.SingleSubst\n\nopen import Tools.Product\nimport Tools.PropositionalEquality as PE\n\n\n-- Application of valid terms.\nappᵛ : ∀ {F G t u Γ l}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])\n ([ΠFG] : Γ ⊩ᵛ⟨ l ⟩ Π F ▹ G / [Γ])\n ([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ Π F ▹ G / [Γ] / [ΠFG])\n ([u] : Γ ⊩ᵛ⟨ l ⟩ u ∷ F / [Γ] / [F])\n → Γ ⊩ᵛ⟨ l ⟩ t ∘ u ∷ G [ u ] / [Γ] / substSΠ {F} {G} {u} [Γ] [F] [ΠFG] [u]\nappᵛ {F} {G} {t} {u} [Γ] [F] [ΠFG] [t] [u] {σ = σ} ⊢Δ [σ] =\n let [G[u]] = substSΠ {F} {G} {u} [Γ] [F] [ΠFG] [u]\n [σF] = proj₁ ([F] ⊢Δ [σ])\n [σΠFG] = proj₁ ([ΠFG] ⊢Δ [σ])\n [σt] = proj₁ ([t] ⊢Δ [σ])\n [σu] = proj₁ ([u] ⊢Δ [σ])\n [σG[u]] = proj₁ ([G[u]] ⊢Δ [σ])\n [σG[u]]′ = irrelevance′ (singleSubstLift G u) [σG[u]]\n in irrelevanceTerm′ (PE.sym (singleSubstLift G u))\n [σG[u]]′ [σG[u]]\n (appTerm [σF] [σG[u]]′ [σΠFG] [σt] [σu])\n , (λ [σ′] [σ≡σ′] →\n let [σu′] = convTerm₂ [σF] (proj₁ ([F] ⊢Δ [σ′]))\n (proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′])\n (proj₁ ([u] ⊢Δ [σ′]))\n in irrelevanceEqTerm′ (PE.sym (singleSubstLift G u))\n [σG[u]]′ [σG[u]]\n (app-congTerm [σF] [σG[u]]′ [σΠFG]\n (proj₂ ([t] ⊢Δ [σ]) [σ′] [σ≡σ′])\n [σu] [σu′]\n (proj₂ ([u] ⊢Δ [σ]) [σ′] [σ≡σ′])))\n\n-- Application congurence of valid terms.\napp-congᵛ : ∀ {F G t u a b Γ l}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])\n ([ΠFG] : Γ ⊩ᵛ⟨ l ⟩ Π F ▹ G / [Γ])\n ([t≡u] : Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ Π F ▹ G / [Γ] / [ΠFG])\n ([a] : Γ ⊩ᵛ⟨ l ⟩ a ∷ F / [Γ] / [F])\n ([b] : Γ ⊩ᵛ⟨ l ⟩ b ∷ F / [Γ] / [F])\n ([a≡b] : Γ ⊩ᵛ⟨ l ⟩ a ≡ b ∷ F / [Γ] / [F])\n → Γ ⊩ᵛ⟨ l ⟩ t ∘ a ≡ u ∘ b ∷ G [ a ] / [Γ]\n / substSΠ {F} {G} {a} [Γ] [F] [ΠFG] [a]\napp-congᵛ {F} {G} {a = a} [Γ] [F] [ΠFG] [t≡u] [a] [b] [a≡b] ⊢Δ [σ] =\n let [σF] = proj₁ ([F] ⊢Δ [σ])\n [G[a]] = proj₁ (substSΠ {F} {G} {a} [Γ] [F] [ΠFG] [a] ⊢Δ [σ])\n [G[a]]′ = irrelevance′ (singleSubstLift G a) [G[a]]\n [σΠFG] = proj₁ ([ΠFG] ⊢Δ [σ])\n [σa] = proj₁ ([a] ⊢Δ [σ])\n [σb] = proj₁ ([b] ⊢Δ [σ])\n in irrelevanceEqTerm′ (PE.sym (singleSubstLift G a)) [G[a]]′ [G[a]]\n (app-congTerm [σF] [G[a]]′ [σΠFG] ([t≡u] ⊢Δ [σ])\n [σa] [σb] ([a≡b] ⊢Δ [σ]))\n", "meta": {"hexsha": "e3b62dbe8a4a2cb67d7dff9d8118e74bea099e20", "size": 3156, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Application.agda", "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Substitution/Introductions/Application.agda", "max_issues_repo_name": "loic-p/logrel-mltt", "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Substitution/Introductions/Application.agda", "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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": 43.2328767123, "max_line_length": 99, "alphanum_fraction": 0.4321926489, "num_tokens": 1381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.3842715136219864}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nmodule Definition.Typed.RedSteps where\n\nopen import Definition.Untyped\nopen import Definition.Typed\n\n\n-- Concatenation of type reduction closures\n_⇨*_ : ∀ {Γ A B C} → Γ ⊢ A ⇒* B → Γ ⊢ B ⇒* C → Γ ⊢ A ⇒* C\nid ⊢B ⇨* B⇒C = B⇒C\n(A⇒A′ ⇨ A′⇒B) ⇨* B⇒C = A⇒A′ ⇨ (A′⇒B ⇨* B⇒C)\n\n-- Concatenation of term reduction closures\n_⇨∷*_ : ∀ {Γ A t u r} → Γ ⊢ t ⇒* u ∷ A → Γ ⊢ u ⇒* r ∷ A → Γ ⊢ t ⇒* r ∷ A\nid ⊢u ⇨∷* u⇒r = u⇒r\n(t⇒t′ ⇨ t′⇒u) ⇨∷* u⇒r = t⇒t′ ⇨ (t′⇒u ⇨∷* u⇒r)\n\n-- Conversion of reduction closures\nconv* : ∀ {Γ A B t u} → Γ ⊢ t ⇒* u ∷ A → Γ ⊢ A ≡ B → Γ ⊢ t ⇒* u ∷ B\nconv* (id x) A≡B = id (conv x A≡B)\nconv* (x ⇨ d) A≡B = conv x A≡B ⇨ conv* d A≡B\n\n-- Universe of reduction closures\nuniv* : ∀ {Γ A B} → Γ ⊢ A ⇒* B ∷ U → Γ ⊢ A ⇒* B\nuniv* (id x) = id (univ x)\nuniv* (x ⇨ A⇒B) = univ x ⇨ univ* A⇒B\n\n-- Application substitution of reduction closures\napp-subst* : ∀ {Γ A B t t′ a} → Γ ⊢ t ⇒* t′ ∷ Π A ▹ B → Γ ⊢ a ∷ A\n → Γ ⊢ t ∘ a ⇒* t′ ∘ a ∷ B [ a ]\napp-subst* (id x) a₁ = id (x ∘ⱼ a₁)\napp-subst* (x ⇨ t⇒t′) a₁ = app-subst x a₁ ⇨ app-subst* t⇒t′ a₁\n", "meta": {"hexsha": "7e16c6aa2a473328e0c91d4c480cbb8a3444b247", "size": 1078, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Typed/RedSteps.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/Typed/RedSteps.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/Typed/RedSteps.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": 31.7058823529, "max_line_length": 72, "alphanum_fraction": 0.4990723562, "num_tokens": 584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6654105454764747, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.384271505958427}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import cohomology.Theory\nopen import cohomology.PtdMapSequence\nopen import groups.ExactSequence\nopen import groups.Exactness\nopen import groups.HomSequence\nopen import groups.KernelImageUniqueFactorization\n\nopen import cw.CW\n\nmodule cw.cohomology.FirstCohomologyGroup {i} (OT : OrdinaryTheory i)\n (⊙skel : ⊙Skeleton {i} 2) (ac : ⊙has-cells-with-choice 0 ⊙skel i) where\n\nopen OrdinaryTheory OT\nopen import cw.cohomology.TipAndAugment OT (⊙cw-take (lteSR lteS) ⊙skel)\nopen import cw.cohomology.WedgeOfCells OT\nopen import cw.cohomology.TipCoboundary OT (⊙cw-init ⊙skel)\nopen import cw.cohomology.HigherCoboundary OT ⊙skel\nopen import cw.cohomology.HigherCoboundaryGrid OT ⊙skel ac\nopen import cw.cohomology.GridPtdMap (⊙cw-incl-last (⊙cw-init ⊙skel)) (⊙cw-incl-last ⊙skel)\nopen import cw.cohomology.TipGrid OT (⊙cw-init ⊙skel) (⊙init-has-cells-with-choice ⊙skel ac)\nopen import cw.cohomology.TopGrid OT 1 (⊙cw-incl-last (⊙cw-init ⊙skel)) (⊙cw-incl-last ⊙skel)\nopen import cohomology.LongExactSequence cohomology-theory\n\nprivate\n 0≤2 : 0 ≤ 2\n 0≤2 = lteSR lteS\n\n ac₀ = ⊙take-has-cells-with-choice 0≤2 ⊙skel ac\n\n{-\n H\n Coker ≃ C(X₁)<------C(X₂) = C(X)\n ^ ^\n | |\n | |\n C(X₁/X₀)<---C(X₂/X₀) ≃ Ker\n WoC G\n\n WoC := Wedges of Cells\n-}\n\nprivate\n G : Group i\n G = C 1 (⊙Cofiber (⊙cw-incl-tail 0≤2 ⊙skel))\n\n G-iso-Ker : G ≃ᴳ Ker.grp cw-co∂-last\n G-iso-Ker = Ker-cw-co∂-last\n\n H : Group i\n H = C 1 ⊙⟦ ⊙cw-init ⊙skel ⟧\n\n Coker-iso-H : CokerCo∂Head.grp ≃ᴳ H\n Coker-iso-H = Coker-cw-co∂-head\n\n G-to-C-cw : G →ᴳ C 1 ⊙⟦ ⊙skel ⟧\n G-to-C-cw = C-fmap 1 (⊙cfcod' (⊙cw-incl-tail 0≤2 ⊙skel))\n\n abstract\n G-to-C-cw-is-surj : is-surjᴳ G-to-C-cw\n G-to-C-cw-is-surj = Exact.K-trivial-implies-φ-is-surj\n (exact-seq-index 2 $ C-cofiber-exact-seq 0 (⊙cw-incl-tail 0≤2 ⊙skel))\n (CX₀-≠-is-trivial (pos-≠ (ℕ-S≠O 0)) ac₀)\n\n C-cw-to-H : C 1 ⊙⟦ ⊙skel ⟧ →ᴳ H\n C-cw-to-H = C-fmap 1 (⊙cw-incl-last ⊙skel)\n\n abstract\n C-cw-to-H-is-inj : is-injᴳ C-cw-to-H\n C-cw-to-H-is-inj = Exact.G-trivial-implies-ψ-is-inj\n (exact-seq-index 2 $ C-cofiber-exact-seq 0 (⊙cw-incl-last ⊙skel))\n (CXₙ/Xₙ₋₁-<-is-trivial ⊙skel ltS ac)\n\n C-WoC : Group i\n C-WoC = C 1 (⊙Cofiber (⊙cw-incl-last (⊙cw-init ⊙skel)))\n\n G-to-C-WoC : G →ᴳ C-WoC\n G-to-C-WoC = C-fmap 1 Y/X-to-Z/X\n\n C-WoC-to-H : C-WoC →ᴳ H\n C-WoC-to-H = C-fmap 1 (⊙cfcod' (⊙cw-incl-last (⊙cw-init ⊙skel)))\n\nopen import groups.KernelImage cw-co∂-last cw-co∂-head CX₁/X₀-is-abelian\n\nC-cw-iso-ker/im : C 1 ⊙⟦ ⊙skel ⟧ ≃ᴳ Ker/Im\nC-cw-iso-ker/im = H-iso-Ker/Im\n cw-co∂-last cw-co∂-head CX₁/X₀-is-abelian\n φ₁ φ₁-is-surj φ₂ φ₂-is-inj lemma-comm\n where\n φ₁ = G-to-C-cw ∘ᴳ GroupIso.g-hom G-iso-Ker\n abstract\n φ₁-is-surj : is-surjᴳ φ₁\n φ₁-is-surj = ∘-is-surj G-to-C-cw-is-surj (equiv-is-surj (GroupIso.g-is-equiv G-iso-Ker))\n\n φ₂ = GroupIso.g-hom Coker-iso-H ∘ᴳ C-cw-to-H\n abstract\n φ₂-is-inj : is-injᴳ φ₂\n φ₂-is-inj = ∘-is-inj (equiv-is-inj (GroupIso.g-is-equiv Coker-iso-H)) C-cw-to-H-is-inj\n\n abstract\n lemma-comm : ∀ g →\n GroupIso.g Coker-iso-H (GroupHom.f (C-cw-to-H ∘ᴳ G-to-C-cw) (GroupIso.g G-iso-Ker g))\n == q[ fst g ]\n lemma-comm g =\n GroupIso.g Coker-iso-H (GroupHom.f C-cw-to-H (GroupHom.f G-to-C-cw (GroupIso.g G-iso-Ker g)))\n =⟨ ap (GroupIso.g Coker-iso-H) (! (C-top-grid-commutes □$ᴳ GroupIso.g G-iso-Ker g)) ⟩\n GroupIso.g Coker-iso-H (GroupHom.f C-WoC-to-H (GroupHom.f G-to-C-WoC (GroupIso.g G-iso-Ker g)))\n =⟨ ap (GroupIso.g Coker-iso-H ∘ GroupHom.f C-WoC-to-H ∘ fst) (GroupIso.f-g G-iso-Ker g) ⟩\n GroupIso.g Coker-iso-H (GroupHom.f C-WoC-to-H (fst g))\n =⟨ GroupIso.g-f Coker-iso-H q[ fst g ] ⟩\n q[ fst g ]\n =∎\n", "meta": {"hexsha": "3e6b3b632c2d653f654bd57a170637e11b6488ae", "size": 3875, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/cw/cohomology/FirstCohomologyGroup.agda", "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/cw/cohomology/FirstCohomologyGroup.agda", "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/cw/cohomology/FirstCohomologyGroup.agda", "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "avg_line_length": 33.6956521739, "max_line_length": 103, "alphanum_fraction": 0.6129032258, "num_tokens": 1682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.3841647227376775}} {"text": "{-\n\nTheory about path split equivalences.\nThey are convenient to construct localization HITs as in\n(the \"modalities paper\")\nhttps://arxiv.org/abs/1706.07526\n\n- there are construction from and to equivalences ([pathSplitToEquiv] , [equivToPathSplit])\n- the structure of a path split equivalence is actually a proposition ([isPropIsPathSplitEquiv])\n\nThe module starts with a couple of general facts about equivalences:\n\n- if f is an equivalence then (cong f) is an equivalence ([equivCong])\n- if f is an equivalence then pre- and postcomposition with f are equivalences ([preCompEquiv], [postCompEquiv])\n\n(those are not in 'Equiv.agda' because they need Univalence.agda (which imports Equiv.agda))\n-}\n{-# OPTIONS --cubical --safe #-}\nmodule Cubical.Foundations.PathSplitEquiv where\n\nopen import Cubical.Core.Everything\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Foundations.Isomorphism\n\nopen import Cubical.Foundations.Equiv.Properties\n\nrecord isPathSplitEquiv {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (f : A → B) : Type (ℓ-max ℓ ℓ') where\n field\n s : B → A\n sec : section f s\n secCong : (x y : A) → Σ[ s' ∈ (f(x) ≡ f(y) → x ≡ y) ] section (cong f) s'\n\nPathSplitEquiv : ∀ {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ')\nPathSplitEquiv A B = Σ[ f ∈ (A → B) ] isPathSplitEquiv f\n\nopen isPathSplitEquiv\n\nidIsPathSplitEquiv : ∀ {ℓ} {A : Type ℓ} → isPathSplitEquiv (λ (x : A) → x)\ns idIsPathSplitEquiv x = x\nsec idIsPathSplitEquiv x = refl\nsecCong idIsPathSplitEquiv = λ x y → (λ p → p) , λ p _ → p\n\nmodule _ {ℓ} {A B : Type ℓ} where\n toIsEquiv : (f : A → B) → isPathSplitEquiv f → isEquiv f\n toIsEquiv f record { s = s ; sec = sec ; secCong = secCong } =\n (isoToEquiv (iso f s sec (λ x → (secCong (s (f x)) x).fst (sec (f x))))) .snd\n\n sectionOfEquiv' : (f : A → B) → isEquiv f → B → A\n sectionOfEquiv' f record { equiv-proof = all-fibers-contractible } x =\n all-fibers-contractible x .fst .fst\n\n isSec : (f : A → B) → (pf : isEquiv f) → section f (sectionOfEquiv' f pf)\n isSec f record { equiv-proof = all-fibers-contractible } x =\n all-fibers-contractible x .fst .snd\n\n sectionOfEquiv : (f : A → B) → isEquiv f → Σ (B → A) (section f)\n sectionOfEquiv f e = sectionOfEquiv' f e , isSec f e\n\nmodule _ {ℓ} {A B : Type ℓ} where\n abstract\n fromIsEquiv : (f : A → B) → isEquiv f → isPathSplitEquiv f\n s (fromIsEquiv f pf) = sectionOfEquiv' f pf\n sec (fromIsEquiv f pf) = isSec f pf\n secCong (fromIsEquiv f pf) x y = sectionOfEquiv cong-f eq-cong\n where\n cong-f : x ≡ y → f x ≡ f y\n cong-f = λ (p : x ≡ y) → cong f p\n eq-cong : isEquiv cong-f\n eq-cong = isEquivCong (f , pf)\n\n pathSplitToEquiv : PathSplitEquiv A B → A ≃ B\n fst (pathSplitToEquiv (f , _)) = f\n snd (pathSplitToEquiv (_ , e)) = toIsEquiv _ e\n\n equivToPathSplit : A ≃ B → PathSplitEquiv A B\n fst (equivToPathSplit (f , _)) = f\n snd (equivToPathSplit (_ , e)) = fromIsEquiv _ e\n\n equivHasUniqueSection : (f : A → B)\n → isEquiv f → isContr (Σ (B → A) (section f))\n equivHasUniqueSection f eq = helper'\n where\n idB = λ (x : B) → x\n abstract\n helper : isContr (fiber (λ (φ : B → A) → f ∘ φ) idB)\n helper = (equiv-proof (snd (postCompEquiv (f , eq)))) idB\n helper' : isContr (Σ[ φ ∈ (B → A) ] ((x : B) → f (φ x) ≡ x))\n fst helper' = (φ , λ x i → η i x)\n where φ = fst (fst helper)\n η : f ∘ φ ≡ idB\n η = snd (fst helper)\n (snd helper') y i = (fst (η i) , λ b j → snd (η i) j b)\n where η = (snd helper) (fst y , λ i b → snd y b i)\n\n{-\n PathSplitEquiv is a proposition and the type\n of path split equivs is equivalent to the type of equivalences\n-}\nisPropIsPathSplitEquiv : ∀ {ℓ} {A B : Type ℓ} (f : A → B)\n → isProp (isPathSplitEquiv f)\nisPropIsPathSplitEquiv {_} {A} {B} f\n record { s = φ ; sec = sec-φ ; secCong = secCong-φ }\n record { s = ψ ; sec = sec-ψ ; secCong = secCong-ψ } i\n =\n record {\n s = fst (sectionsAreEqual i) ;\n sec = snd (sectionsAreEqual i) ;\n secCong = λ x y → congSectionsAreEqual x y (secCong-φ x y) (secCong-ψ x y) i\n }\n where\n φ' = record { s = φ ; sec = sec-φ ; secCong = secCong-φ }\n ψ' = record { s = ψ ; sec = sec-ψ ; secCong = secCong-ψ }\n sectionsAreEqual : (φ , sec-φ) ≡ (ψ , sec-ψ)\n sectionsAreEqual = (sym (contraction (φ , sec-φ))) ∙ (contraction (ψ , sec-ψ))\n where contraction = snd (equivHasUniqueSection f (toIsEquiv f φ'))\n congSectionsAreEqual : (x y : A) (l u : Σ (f(x) ≡ f(y) → x ≡ y) (section (cong f))) → l ≡ u\n congSectionsAreEqual x y l u = (sym (contraction l)) ∙ (contraction u)\n where contraction = snd (equivHasUniqueSection\n (λ (p : x ≡ y) → cong f p)\n (isEquivCong (pathSplitToEquiv (f , φ'))))\n\nmodule _ {ℓ} {A B : Type ℓ} where\n isEquivIsPathSplitToIsEquiv : (f : A → B) → isEquiv (fromIsEquiv f)\n isEquivIsPathSplitToIsEquiv f =\n isoToIsEquiv\n (iso (fromIsEquiv f) (toIsEquiv f) (λ b → isPropIsPathSplitEquiv f _ _) (λ a → isPropIsEquiv f _ _ ))\n\n isEquivPathSplitToEquiv : isEquiv (pathSplitToEquiv {A = A} {B = B})\n isEquivPathSplitToEquiv =\n isoToIsEquiv\n (iso pathSplitToEquiv equivToPathSplit\n (λ {(f , e) i → (f , isPropIsEquiv f (toIsEquiv f (fromIsEquiv f e)) e i)})\n (λ {(f , e) i → (f , isPropIsPathSplitEquiv f (fromIsEquiv f (toIsEquiv f e)) e i)}))\n\n equivPathSplitToEquiv : (PathSplitEquiv A B) ≃ (A ≃ B)\n equivPathSplitToEquiv = (pathSplitToEquiv , isEquivPathSplitToEquiv)\n", "meta": {"hexsha": "4907841979bddfbb27d14ada1ded097ffb67f7c1", "size": 5670, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Foundations/PathSplitEquiv.agda", "max_stars_repo_name": "cj-xu/cubical", "max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "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": "Cubical/Foundations/PathSplitEquiv.agda", "max_issues_repo_name": "cj-xu/cubical", "max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "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": "Cubical/Foundations/PathSplitEquiv.agda", "max_forks_repo_name": "cj-xu/cubical", "max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "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.2127659574, "max_line_length": 112, "alphanum_fraction": 0.6239858907, "num_tokens": 2045, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419958239131, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3840495294756034}} {"text": "module Base.Change.Equivalence.Realizers where\n\nopen import Relation.Binary.PropositionalEquality\nopen import Base.Change.Algebra\nopen import Level\nopen import Data.Unit\nopen import Data.Product\nopen import Function\nopen import Postulate.Extensionality\n\nopen import Base.Change.Equivalence\n\n-- Here we give lemmas about realizers for function changes. Using these lemmas,\n-- you can simply write a \"realizer\" for a derivative for f (that is, the\n-- computational part of the derivative, without any embedded proof), show\n-- separately that it's change-equivalent to the nil change for f and get a\n-- proper function change; this code proves the needed validity lemmas.\n--\n-- Given a type of codes for types, such lemmas should be provable by induction\n-- on those types; something similar is done in the proof of erasure, though\n-- details are quite different.\n--\n-- For now, we do something close to unrolling the induction manually for\n-- functions of arity 1, 2 and 3 since those are actually used in the codebase.\n-- I didn't actually write the induction though, and I'm not sure how to do it.\n--\n-- So there are two attempts which might give ideas; one is\n-- equiv-raw-change-to-change-binary and equiv-raw-change-to-change-ternary, the\n-- other is equiv-raw-change-to-change-binary′ and\n-- equiv-raw-change-to-change-ternary′.\nmodule _\n {a} {A : Set a} {{CA : ChangeAlgebra A}}\n {b} {B : Set b} {{CB : ChangeAlgebra B}}\n (f : A → B)\n where\n private\n Set′ = Set (a ⊔ b)\n\n equiv₁ : ∀ (df′ : Δ f) (df-realizer : RawChange f) → Set′\n equiv₁ df′ df-realizer = apply df′ ≡ df-realizer\n\n equiv-raw-change-to-change-ResType :\n ∀ (df-realizer : RawChange f) → Set′\n equiv-raw-change-to-change-ResType df-realizer =\n Σ[ df′ ∈ Δ f ] equiv₁ df′ df-realizer\n\n equiv-hp :\n ∀ (df : Δ f) (df-realizer : RawChange f) → Set′\n equiv-hp df df-realizer = (∀ a da → apply df a da ≙₍ f a ₎ df-realizer a da)\n\n -- This is sort of the \"base case\" of the proof mentioned above.\n equiv-raw-change-to-change :\n ∀ (df : Δ f) (df-realizer : RawChange f) →\n equiv-hp df df-realizer →\n equiv-raw-change-to-change-ResType df-realizer\n equiv-raw-change-to-change df df-realizer ≙df = record { apply = df-realizer ; correct = df-realizer-correct} , refl\n where\n df-realizer-correct : ∀ a da → f (a ⊞ da) ⊞ df-realizer (a ⊞ da) (nil (a ⊞ da)) ≡ f a ⊞ df-realizer a da\n df-realizer-correct a da\n rewrite sym (proof (≙df a da))\n | sym (proof (≙df (a ⊞ da) (nil (a ⊞ da))))\n = correct df a da\n\n equiv-raw-deriv-to-deriv :\n ∀ (df-realizer : RawChange f) →\n equiv-hp (nil f) df-realizer →\n IsDerivative f df-realizer\n equiv-raw-deriv-to-deriv df-realizer ≙df with equiv-raw-change-to-change (nil f) df-realizer ≙df\n equiv-raw-deriv-to-deriv .(FunctionChanges.apply nil-f) ≙df | nil-f , refl =\n equiv-nil-is-derivative nil-f (delta-ext ≙df)\n\nmodule _\n {a} {A : Set a} {{CA : ChangeAlgebra A}}\n {b} {B : Set b} {{CB : ChangeAlgebra B}}\n {c} {C : Set c} {{CC : ChangeAlgebra C}}\n (f : A → B → C) where\n private\n Set′ = Set (a ⊔ b ⊔ c)\n\n -- This is, sort of, an instance of the inductive step in the proof mentioned above.\n RawChangeBinary :\n Set′\n RawChangeBinary = ∀ a (da : Δ a) → RawChange (f a)\n\n equiv-hp-binary : ∀ (df : Δ f) (df-realizer : RawChangeBinary) → Set′\n equiv-hp-binary df df-realizer =\n ∀ a da → equiv-hp (f a) (apply df a da) (df-realizer a da)\n\n equiv₂ : ∀ (df′ : Δ f) (df-realizer : RawChangeBinary) → Set′\n equiv₂ df′ df-realizer = ∀ a da → equiv₁ (f a) (apply df′ a da) (df-realizer a da)\n\n equiv-raw-change-to-change-binary-ResType :\n ∀ (df-realizer : RawChangeBinary) → Set′\n equiv-raw-change-to-change-binary-ResType df-realizer =\n Σ[ df′ ∈ Δ f ] equiv₂ df′ df-realizer\n\n equiv-raw-change-to-change-binary equiv-raw-change-to-change-binary′ :\n ∀ (df : Δ f) (df-realizer : RawChangeBinary) →\n equiv-hp-binary df df-realizer →\n equiv-raw-change-to-change-binary-ResType df-realizer\n equiv-raw-change-to-change-binary df df-realizer ≙df = proj₁ (equiv-raw-change-to-change f df df₁′ ≙df₁′) , λ a da → refl\n where\n module _ (a : A) (da : Δ a) where\n f₁ = f a\n df₁ : Δ f₁\n df₁ = apply df a da\n df-realizer₁ = df-realizer a da\n ≙df₁ = ≙df a da\n df-realizer₁-correct : ∀ b db → f₁ (b ⊞ db) ⊞ df-realizer₁ (b ⊞ db) (nil (b ⊞ db)) ≡ f₁ b ⊞ df-realizer₁ b db\n df-realizer₁-correct b db\n rewrite sym (proof (≙df₁ b db))\n | sym (proof (≙df₁ (b ⊞ db) (nil (b ⊞ db))))\n = correct df₁ b db\n df₁′ : Δ f₁\n df₁′ = record { apply = df-realizer₁ ; correct = df-realizer₁-correct }\n ≙df₁′ : df₁ ≙₍ f₁ ₎ df₁′\n ≙df₁′ = delta-ext ≙df₁\n\n equiv-raw-change-to-change-binary′ df df-realizer ≙df = record { apply = df₁′ ; correct = λ a da → ext (df-realizer-correct a da) } , λ a da → refl\n where\n module _ (a : A) (da : Δ a) where\n f₁ = f a\n df₁ : Δ f₁\n df₁ = apply df a da\n df-realizer₁ = df-realizer a da\n ≙df₁ = ≙df a da\n df₁′ = proj₁ (equiv-raw-change-to-change f₁ df₁ df-realizer₁ ≙df₁)\n df-realizer-correct : ∀ b → f (a ⊞ da) b ⊞ df-realizer (a ⊞ da) (nil (a ⊞ da)) b (nil b) ≡ f a b ⊞ df-realizer a da b (nil b)\n df-realizer-correct b\n rewrite sym (proof (≙df a da b (nil b)))\n | sym (proof (≙df (a ⊞ da) (nil (a ⊞ da)) b (nil b)))\n = cong (λ □ → □ b) (correct df a da)\n\n equiv-raw-deriv-to-deriv-binary :\n ∀ (df-realizer : RawChangeBinary) →\n (≙df : equiv-hp-binary (nil f) df-realizer) →\n IsDerivative f (apply (proj₁ (equiv-raw-change-to-change-binary (nil f) df-realizer ≙df)))\n equiv-raw-deriv-to-deriv-binary df-realizer ≙df a da with equiv-raw-change-to-change-binary (nil f) df-realizer ≙df\n ... | nil-f , nil-f≡df with sym (nil-f≡df a da)\n ... | df-a-da≡nil-f-a-da rewrite df-a-da≡nil-f-a-da = equiv-nil-is-derivative nil-f (delta-ext {df = nil f} {dg = nil-f} (λ a da → doe (ext (lemma a da)))) a da\n where\n lemma : ∀ a da b → (f a ⊞ apply (nil f) a da) b ≡ (f a ⊞ apply nil-f a da) b\n lemma a da b rewrite nil-f≡df a da = proof (≙df a da b (nil b))\n\nmodule _\n {a} {A : Set a} {{CA : ChangeAlgebra A}}\n {b} {B : Set b} {{CB : ChangeAlgebra B}}\n {c} {C : Set c} {{CC : ChangeAlgebra C}}\n {d} {D : Set d} {{CD : ChangeAlgebra D}}\n (f : A → B → C → D)\n where\n private\n Set′ = Set (a ⊔ b ⊔ c ⊔ d)\n\n -- This is an adapted copy of the above \"inductive step\".\n RawChangeTernary : Set′\n RawChangeTernary = ∀ a (da : Δ a) → RawChangeBinary (f a)\n\n equiv-hp-ternary : ∀ (df : Δ f) (df-realizer : RawChangeTernary) → Set′\n equiv-hp-ternary df df-realizer =\n ∀ a da → equiv-hp-binary (f a) (apply df a da) (df-realizer a da)\n\n equiv₃ : ∀ (df′ : Δ f) (df-realizer : RawChangeTernary) → Set′\n equiv₃ df′ df-realizer = ∀ a da → equiv₂ (f a) (apply df′ a da) (df-realizer a da)\n\n equiv-raw-change-to-change-ternary-ResType :\n ∀ (df-realizer : RawChangeTernary) → Set′\n equiv-raw-change-to-change-ternary-ResType df-realizer =\n Σ[ df′ ∈ Δ f ] equiv₃ df′ df-realizer\n\n equiv-raw-change-to-change-ternary equiv-raw-change-to-change-ternary′ :\n ∀ (df : Δ f) (df-realizer : RawChangeTernary) →\n equiv-hp-ternary df df-realizer →\n equiv-raw-change-to-change-ternary-ResType df-realizer\n\n equiv-raw-change-to-change-ternary df df-realizer ≙df =\n proj₁ (equiv-raw-change-to-change-binary f df df₁′ ≙df₁′) , λ a da b db → refl\n where\n module _ (a : A) (da : Δ a) (b : B) (db : Δ b) where\n f₁ = f a b\n df₁ : Δ f₁\n df₁ = apply (apply df a da) b db\n df-realizer₁ = df-realizer a da b db\n ≙df₁ = ≙df a da b db\n\n df-realizer₁-correct : ∀ c dc → f₁ (c ⊞ dc) ⊞ df-realizer₁ (c ⊞ dc) (nil (c ⊞ dc)) ≡ f₁ c ⊞ df-realizer₁ c dc\n df-realizer₁-correct c dc\n rewrite sym (proof (≙df₁ c dc))\n | sym (proof (≙df₁ (c ⊞ dc) (nil (c ⊞ dc))))\n = correct df₁ c dc\n df₁′ : Δ f₁\n df₁′ = record { apply = df-realizer₁ ; correct = df-realizer₁-correct }\n ≙df₁′ : df₁ ≙₍ f₁ ₎ df₁′\n ≙df₁′ = delta-ext ≙df₁\n\n equiv-raw-change-to-change-ternary′ df df-realizer ≙df = record { apply = df₁′ ; correct = λ a da → ext (λ b → ext (df-realizer-correct a da b)) } , λ a da b db → refl\n where\n module _ (a : A) (da : Δ a) where\n f₁ = f a\n df₁ : Δ f₁\n df₁ = apply df a da\n df-realizer₁ = df-realizer a da\n ≙df₁ = ≙df a da\n df₁′ = proj₁ (equiv-raw-change-to-change-binary f₁ df₁ df-realizer₁ ≙df₁)\n df-realizer-correct : ∀ b c → f (a ⊞ da) b c ⊞ df-realizer (a ⊞ da) (nil (a ⊞ da)) b (nil b) c (nil c) ≡ f a b c ⊞ df-realizer a da b (nil b) c (nil c)\n df-realizer-correct b c\n rewrite sym (proof (≙df a da b (nil b) c (nil c)))\n | sym (proof (≙df (a ⊞ da) (nil (a ⊞ da)) b (nil b) c (nil c)))\n = cong (λ □ → □ b c) (correct df a da)\n", "meta": {"hexsha": "ed604b5fb595b9d3c5a71b3a96b9492e5f765315", "size": 8970, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Base/Change/Equivalence/Realizers.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": "Base/Change/Equivalence/Realizers.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": "Base/Change/Equivalence/Realizers.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": 42.7142857143, "max_line_length": 169, "alphanum_fraction": 0.6061315496, "num_tokens": 3099, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321842389469, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3838811965385316}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Substitution.Reduction {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.LogicalRelation.Properties\nopen import Definition.LogicalRelation.Substitution\n\nopen import Tools.Product\n\n\n-- Weak head expansion of valid terms.\nredSubstTermᵛ : ∀ {A t u l Γ}\n → ([Γ] : ⊩ᵛ Γ)\n → Γ ⊩ᵛ t ⇒ u ∷ A / [Γ]\n → ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])\n → Γ ⊩ᵛ⟨ l ⟩ u ∷ A / [Γ] / [A]\n → (Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A])\n ×ω₃ (Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A])\nredSubstTermᵛ [Γ] t⇒u [A] [u] =\n (λ ⊢Δ [σ] →\n let [σA] = proj₁ ([A] ⊢Δ [σ])\n [σt] , [σt≡σu] = redSubstTerm (t⇒u ⊢Δ [σ])\n (proj₁ ([A] ⊢Δ [σ]))\n (proj₁ ([u] ⊢Δ [σ]))\n in [σt]\n , (λ [σ′] [σ≡σ′] →\n let [σ′A] = proj₁ ([A] ⊢Δ [σ′])\n [σA≡σ′A] = proj₂ ([A] ⊢Δ [σ]) [σ′] [σ≡σ′]\n [σ′t] , [σ′t≡σ′u] = redSubstTerm (t⇒u ⊢Δ [σ′])\n (proj₁ ([A] ⊢Δ [σ′]))\n (proj₁ ([u] ⊢Δ [σ′]))\n in transEqTerm [σA] [σt≡σu]\n (transEqTerm [σA] ((proj₂ ([u] ⊢Δ [σ])) [σ′] [σ≡σ′])\n (convEqTerm₂ [σA] [σ′A] [σA≡σ′A]\n (symEqTerm [σ′A] [σ′t≡σ′u])))))\n , (λ ⊢Δ [σ] → proj₂ (redSubstTerm (t⇒u ⊢Δ [σ])\n (proj₁ ([A] ⊢Δ [σ]))\n (proj₁ ([u] ⊢Δ [σ]))))\n", "meta": {"hexsha": "f3df8fd7797e8882a62d50f711d6b01057a7586d", "size": 1687, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Reduction.agda", "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Substitution/Reduction.agda", "max_issues_repo_name": "loic-p/logrel-mltt", "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Substitution/Reduction.agda", "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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.1666666667, "max_line_length": 85, "alphanum_fraction": 0.3586247777, "num_tokens": 649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321720225278, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.38388118995408665}} {"text": "-- Basic intuitionistic propositional calculus, without ∨ or ⊥.\n-- Kripke-style semantics with contexts as concrete worlds, and glueing for α and ▻.\n-- Implicit syntax.\n\nmodule BasicIPC.Semantics.KripkeConcreteGluedImplicit where\n\nopen import BasicIPC.Syntax.Common public\nopen import Common.Semantics public\n\nopen ConcreteWorlds (Ty) public\n\n\n-- Partial intuitionistic Kripke models.\n\nrecord Model : Set₁ where\n infix 3 _⊩ᵅ_\n field\n -- Forcing for atomic propositions; monotonic.\n _⊩ᵅ_ : World → Atom → Set\n mono⊩ᵅ : ∀ {P w w′} → w ≤ w′ → w ⊩ᵅ P → w′ ⊩ᵅ P\n\nopen Model {{…}} public\n\n\n\n\nmodule ImplicitSyntax\n (_[⊢]_ : Cx Ty → Ty → Set)\n (mono[⊢] : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ [⊢] A → Γ′ [⊢] A)\n where\n\n\n -- Forcing in a particular world of a particular model.\n\n module _ {{_ : Model}} where\n infix 3 _⊩_\n _⊩_ : World → Ty → Set\n w ⊩ α P = Glue (unwrap w [⊢] (α P)) (w ⊩ᵅ P)\n w ⊩ A ▻ B = Glue (unwrap w [⊢] (A ▻ B)) (∀ {w′} → w ≤ w′ → w′ ⊩ A → w′ ⊩ B)\n w ⊩ A ∧ B = w ⊩ A × w ⊩ B\n w ⊩ ⊤ = 𝟙\n\n infix 3 _⊩⋆_\n _⊩⋆_ : World → Cx Ty → Set\n w ⊩⋆ ∅ = 𝟙\n w ⊩⋆ Ξ , A = w ⊩⋆ Ξ × w ⊩ A\n\n\n -- Monotonicity with respect to context inclusion.\n\n module _ {{_ : Model}} where\n mono⊩ : ∀ {A w w′} → w ≤ w′ → w ⊩ A → w′ ⊩ A\n mono⊩ {α P} ξ s = mono[⊢] (unwrap≤ ξ) (syn s) ⅋ mono⊩ᵅ ξ (sem s)\n mono⊩ {A ▻ B} ξ s = mono[⊢] (unwrap≤ ξ) (syn s) ⅋ λ ξ′ → sem s (trans≤ ξ ξ′)\n mono⊩ {A ∧ B} ξ s = mono⊩ {A} ξ (π₁ s) , mono⊩ {B} ξ (π₂ s)\n mono⊩ {⊤} ξ s = ∙\n\n mono⊩⋆ : ∀ {Ξ w w′} → w ≤ w′ → w ⊩⋆ Ξ → w′ ⊩⋆ Ξ\n mono⊩⋆ {∅} ξ ∙ = ∙\n mono⊩⋆ {Ξ , A} ξ (ts , t) = mono⊩⋆ {Ξ} ξ ts , mono⊩ {A} ξ t\n\n\n -- Additional useful equipment.\n\n module _ {{_ : Model}} where\n _⟪$⟫_ : ∀ {A B w} → w ⊩ A ▻ B → w ⊩ A → w ⊩ B\n s ⟪$⟫ a = sem s refl≤ a\n\n ⟪S⟫ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ A ▻ B → w ⊩ A → w ⊩ C\n ⟪S⟫ s₁ s₂ a = (s₁ ⟪$⟫ a) ⟪$⟫ (s₂ ⟪$⟫ a)\n\n\n -- Forcing in a particular world of a particular model, for sequents.\n\n module _ {{_ : Model}} where\n infix 3 _⊩_⇒_\n _⊩_⇒_ : World → Cx Ty → Ty → Set\n w ⊩ Γ ⇒ A = w ⊩⋆ Γ → w ⊩ A\n\n infix 3 _⊩_⇒⋆_\n _⊩_⇒⋆_ : World → Cx Ty → Cx Ty → Set\n w ⊩ Γ ⇒⋆ Ξ = w ⊩⋆ Γ → w ⊩⋆ Ξ\n\n\n -- Entailment, or forcing in all worlds of all models, for sequents.\n\n infix 3 _⊨_\n _⊨_ : Cx Ty → Ty → Set₁\n Γ ⊨ A = ∀ {{_ : Model}} {w : World} → w ⊩ Γ ⇒ A\n\n infix 3 _⊨⋆_\n _⊨⋆_ : Cx Ty → Cx Ty → Set₁\n Γ ⊨⋆ Ξ = ∀ {{_ : Model}} {w : World} → w ⊩ Γ ⇒⋆ Ξ\n\n\n -- Additional useful equipment, for sequents.\n\n module _ {{_ : Model}} where\n lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩ Γ ⇒ A\n lookup top (γ , a) = a\n lookup (pop i) (γ , b) = lookup i γ\n\n _⟦$⟧_ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ▻ B → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B\n (s₁ ⟦$⟧ s₂) γ = s₁ γ ⟪$⟫ s₂ γ\n\n ⟦S⟧ : ∀ {A B C Γ w} → w ⊩ Γ ⇒ A ▻ B ▻ C → w ⊩ Γ ⇒ A ▻ B → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ C\n ⟦S⟧ s₁ s₂ a γ = ⟪S⟫ (s₁ γ) (s₂ γ) (a γ)\n\n _⟦,⟧_ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B → w ⊩ Γ ⇒ A ∧ B\n (a ⟦,⟧ b) γ = a γ , b γ\n\n ⟦π₁⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ∧ B → w ⊩ Γ ⇒ A\n ⟦π₁⟧ s γ = π₁ (s γ)\n\n ⟦π₂⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ∧ B → w ⊩ Γ ⇒ B\n ⟦π₂⟧ s γ = π₂ (s γ)\n", "meta": {"hexsha": "7a273241a123b95c6f1488dd00e9ab0121e42fb1", "size": 3134, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BasicIPC/Semantics/KripkeConcreteGluedImplicit.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": "BasicIPC/Semantics/KripkeConcreteGluedImplicit.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": "BasicIPC/Semantics/KripkeConcreteGluedImplicit.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": 26.7863247863, "max_line_length": 84, "alphanum_fraction": 0.4610721123, "num_tokens": 1612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3838734828227797}} {"text": "-- Andreas, 2013-03-22\nmodule Issue473a where\n\ndata D : Set where\n d : D\n\ndata P : D → Set where\n p : P d\n\nrecord Rc : Set where\n constructor c\n field f : D\n\nworks : {r : Rc} → P (Rc.f r) → Set\nworks p = D\n\nworks' : (r : Rc) → P (Rc.f r) → Set\nworks' (c .d) p = D\n\n-- If we remove the constructor, the example fails:\n\nrecord R : Set where\n field f : D\n\nfails : {r : R} → P (R.f r) → Set\nfails p = D\n\n-- d != R.f r of type D\n-- when checking that the pattern p has type P (R.f r)\n\n-- The error is justified since there is no pattern we could write down\n-- for r. It would have to look like\n--\n-- record { f = .d }\n--\n-- but anonymous record patterns are not supported.\n", "meta": {"hexsha": "e3e8fee8b3f78d035db1b2615e54013cbfa95bf9", "size": 676, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/fail/Issue473a.agda", "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z", "max_issues_repo_path": "test/fail/Issue473a.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/Issue473a.agda", "max_forks_repo_name": "masondesu/agda", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "avg_line_length": 18.2702702703, "max_line_length": 71, "alphanum_fraction": 0.6079881657, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7279754371026367, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3838734765986831}} {"text": "{-# OPTIONS --rewriting --prop #-}\n\nopen import common hiding (_===_)\n\n{- Syntax of term- and type-expressions, using de Bruijn indices -}\n\nvariable\n {n} {m} {k} : ℕ\n\ndata Expr : SyntaxSort → ℕ → Set\n\nTyExpr = Expr Ty\nTmExpr = Expr Tm\n\ndata Expr where\n uu : {n : ℕ} → TyExpr n\n el : {n : ℕ} (v : TmExpr n) → TyExpr n\n pi : {n : ℕ} (A : TyExpr n) (B : TyExpr (suc n)) → TyExpr n\n\n var : {n : ℕ} (x : VarPos n) → TmExpr n\n lam : {n : ℕ} (A : TyExpr n) (B : TyExpr (suc n)) (u : TmExpr (suc n)) → TmExpr n\n app : {n : ℕ} (A : TyExpr n) (B : TyExpr (suc n)) (f : TmExpr n) (a : TmExpr n) → TmExpr n\n\ndata Ctx : ℕ → Set where\n ◇ : Ctx 0\n _,_ : {n : ℕ} (Γ : Ctx n) (A : TyExpr n) → Ctx (suc n)\n\n{- The four different forms of (pre)judgments. -}\n\ndata Judgment : Set where\n _⊢_ : {n : ℕ} (Γ : Ctx n) → TyExpr n → Judgment\n _⊢_:>_ : {n : ℕ} (Γ : Ctx n) → TmExpr n → TyExpr n → Judgment\n _⊢_==_ : {n : ℕ} (Γ : Ctx n) → TyExpr n → TyExpr n → Judgment\n _⊢_==_:>_ : {n : ℕ} (Γ : Ctx n) → TmExpr n → TmExpr n → TyExpr n → Judgment\n\n-- weakenV : {n : ℕ} (p : WeakPos n) → VarPos n → VarPos (suc n)\n-- weakenV last x = prev x\n-- weakenV (prev p) last = last\n-- weakenV (prev p) (prev x) = prev (weakenV p x)\n\nweaken : {n : ℕ} {k : SyntaxSort} (p : WeakPos n) → Expr k n → Expr k (suc n)\nweaken p uu = uu\nweaken p (el v) = el (weaken p v)\nweaken p (pi A B) = pi (weaken p A) (weaken (prev p) B)\nweaken p (var x) = var (weakenV p x)\nweaken p (lam A B u) = lam (weaken p A) (weaken (prev p) B) (weaken (prev p) u)\nweaken p (app A B f a) = app (weaken p A) (weaken (prev p) B) (weaken p f) (weaken p a)\n\n-- data Mor (n m : ℕ) : ℕ → Set where \n-- ◇ : Mor n m 0\n-- _,_ : {k : ℕ} (δ : Mor n m k) (u : TmExpr (n + m)) → Mor n m (suc k)\n\n-- weakenMor : Mor n m k → Mor n (suc m) k\n-- weakenMor ◇ = ◇\n-- weakenMor (δ , u) = (weakenMor δ , weaken last u)\n\n-- weakenMor+ : Mor n m k → Mor n (suc m) (suc k)\n-- weakenMor+ δ = weakenMor δ , var last\n\ndata Mor (m : ℕ) : ℕ → Set where \n ◇ : Mor m 0\n _,_ : {k : ℕ} (δ : Mor m k) (u : TmExpr m) → Mor m (suc k)\n\nweakenMor : Mor m k → Mor (suc m) k\nweakenMor ◇ = ◇\nweakenMor (δ , u) = (weakenMor δ , weaken last u)\n\nweakenMor+ : Mor m k → Mor (suc m) (suc k)\nweakenMor+ δ = weakenMor δ , var last\n\nweakV : {n m : ℕ} → VarPos n → VarPos (n + m)\nweakV {m = zero} x = x\nweakV {m = suc m} x = prev (weakV x)\n\ninfix 30 _[_]\n\n-- _[_] : {p : SyntaxSort} (A : Expr p (n + k)) (δ : Mor n m k) → Expr p (n + m)\n_[_] : {p : SyntaxSort} (A : Expr p k) (δ : Mor m k) → Expr p m\n\nuu [ δ ] = uu\nel v [ δ ] = el (v [ δ ])\npi A B [ δ ] = pi (A [ δ ]) (B [ weakenMor+ δ ])\n\nvar last [ δ , u ] = u\nvar (prev x) [ δ , u ] = var x [ δ ]\nlam A B u [ δ ] = lam (A [ δ ]) (B [ weakenMor+ δ ]) (u [ weakenMor+ δ ])\napp A B f a [ δ ] = app (A [ δ ]) (B [ weakenMor+ δ ]) (f [ δ ]) (a [ δ ])\n\nidMor : Mor n n\nidMor {zero} = ◇\nidMor {suc n} = (weakenMor idMor , var last)\n\nsubst : {n : ℕ} {k : SyntaxSort} → Expr k (suc n) → TmExpr n → Expr k n\nsubst e a = e [ idMor , a ]\n\nget : {n : ℕ} → VarPos n → Ctx n → TyExpr n\nget last (Γ , A) = weaken last A\nget (prev k) (Γ , A) = weaken last (get k Γ)\n\n{- Derivability of judgments, the typing rules of the type theory -}\n\ndata Derivable : Judgment → Prop where\n\n -- Variable rules\n Var : {n : ℕ} {Γ : Ctx n} (k : VarPos n)\n → Derivable (Γ ⊢ get k Γ)\n → Derivable (Γ ⊢ var k :> get k Γ)\n\n -- Symmetry and transitivity for types\n TyRefl : {n : ℕ} {Γ : Ctx n} {A : TyExpr n}\n → Derivable (Γ ⊢ A) → Derivable (Γ ⊢ A == A)\n TySymm : {n : ℕ} {Γ : Ctx n} {A B : TyExpr n}\n → Derivable (Γ ⊢ A == B) → Derivable (Γ ⊢ B == A)\n TyTran : {n : ℕ} {Γ : Ctx n} {A B C : TyExpr n}\n → Derivable (Γ ⊢ A == B)→ Derivable (Γ ⊢ B == C) → Derivable (Γ ⊢ A == C)\n\n -- Symmetry and transitivity for terms\n TmRefl : {n : ℕ} {Γ : Ctx n} {A : TyExpr n} {u : TmExpr n}\n → Derivable (Γ ⊢ u :> A) → Derivable (Γ ⊢ u == u :> A)\n TmSymm : {n : ℕ} {Γ : Ctx n} {u v : TmExpr n} {A : TyExpr n}\n → Derivable (Γ ⊢ u == v :> A) → Derivable (Γ ⊢ v == u :> A)\n TmTran : {n : ℕ} {Γ : Ctx n} {u v w : TmExpr n} {A : TyExpr n}\n → Derivable (Γ ⊢ u == v :> A)→ Derivable (Γ ⊢ v == w :> A) → Derivable (Γ ⊢ u == w :> A)\n\n -- Conversion rules\n Conv : {n : ℕ} {Γ : Ctx n} {u : TmExpr n} {A B : TyExpr n}\n → Derivable (Γ ⊢ u :> A) → Derivable (Γ ⊢ A == B) → Derivable (Γ ⊢ u :> B)\n ConvEq : {n : ℕ} {Γ : Ctx n} {u u' : TmExpr n} {A B : TyExpr n}\n → Derivable (Γ ⊢ u == u' :> A) → Derivable (Γ ⊢ A == B) → Derivable (Γ ⊢ u == u' :> B)\n\n\n -- Rules for UU\n UU : {n : ℕ} {Γ : Ctx n}\n → Derivable (Γ ⊢ uu)\n UUCong : {n : ℕ} {Γ : Ctx n}\n → Derivable (Γ ⊢ uu == uu)\n\n -- Rules for El\n El : {n : ℕ} {Γ : Ctx n} {v : TmExpr n}\n → Derivable (Γ ⊢ v :> uu) → Derivable (Γ ⊢ el v)\n ElCong : {n : ℕ} {Γ : Ctx n} {v v' : TmExpr n}\n → {- Derivable (Γ ⊢ v :> uu) → Derivable (Γ ⊢ v' :> uu) → -} Derivable (Γ ⊢ v == v' :> uu) → Derivable (Γ ⊢ el v == el v')\n\n -- Rules for Pi\n Pi : {n : ℕ} {Γ : Ctx n} {A : TyExpr n} {B : TyExpr (suc n)}\n → Derivable (Γ ⊢ A) → Derivable ((Γ , A) ⊢ B) → Derivable (Γ ⊢ pi A B)\n PiCong : {n : ℕ} {Γ : Ctx n} {A A' : TyExpr n} {B B' : TyExpr (suc n)}\n → {- Derivable (Γ ⊢ A) → Derivable (Γ ⊢ A') → -} Derivable (Γ ⊢ A == A') → {- Derivable ((Γ , A) ⊢ B) → Derivable ((Γ , A') ⊢ B') → -} Derivable ((Γ , A) ⊢ B == B') → Derivable (Γ ⊢ pi A B == pi A' B')\n\n -- Rules for lambda\n Lam : {n : ℕ} {Γ : Ctx n} {A : TyExpr n} {B : TyExpr (suc n)} {u : TmExpr (suc n)}\n → Derivable (Γ ⊢ A) → Derivable ((Γ , A) ⊢ B) → Derivable ((Γ , A) ⊢ u :> B)\n → Derivable (Γ ⊢ lam A B u :> pi A B)\n LamCong : {n : ℕ} {Γ : Ctx n} {A A' : TyExpr n} {B B' : TyExpr (suc n)} {u u' : TmExpr (suc n)}\n → {- Derivable (Γ ⊢ A) → Derivable (Γ ⊢ A') → -} Derivable (Γ ⊢ A == A')\n → {- Derivable ((Γ , A) ⊢ B) → Derivable ((Γ , A') ⊢ B') → -} Derivable ((Γ , A) ⊢ B == B')\n → {- Derivable ((Γ , A) ⊢ u :> B) → Derivable ((Γ , A') ⊢ u' :> B') → -} Derivable ((Γ , A) ⊢ u == u' :> B)\n → Derivable (Γ ⊢ lam A B u == lam A' B' u' :> pi A B)\n\n -- Rules for app\n App : {n : ℕ} {Γ : Ctx n} {A : TyExpr n} {B : TyExpr (suc n)} {f a : TmExpr n}\n → Derivable (Γ ⊢ A) → Derivable ((Γ , A) ⊢ B) → Derivable (Γ ⊢ f :> pi A B) → Derivable (Γ ⊢ a :> A)\n → Derivable (Γ ⊢ app A B f a :> subst B a)\n AppCong : {n : ℕ} {Γ : Ctx n} {A A' : TyExpr n} {B B' : TyExpr (suc n)} {f f' a a' : TmExpr n}\n → {- Derivable (Γ ⊢ A) → Derivable (Γ ⊢ A') → -} Derivable (Γ ⊢ A == A')\n → {- Derivable ((Γ , A) ⊢ B) → Derivable ((Γ , A') ⊢ B') → -} Derivable ((Γ , A) ⊢ B == B')\n → {- Derivable (Γ ⊢ f :> pi A B) → Derivable (Γ ⊢ f' :> pi A' B') → -} Derivable (Γ ⊢ f == f' :> pi A B)\n → {- Derivable (Γ ⊢ a :> A) → Derivable (Γ ⊢ a' :> A') → -} Derivable (Γ ⊢ a == a' :> A)\n → Derivable (Γ ⊢ app A B f a == app A' B' f' a' :> subst B a)\n\n -- Equality rules\n BetaPi : {n : ℕ} {Γ : Ctx n} {A : TyExpr n} {B : TyExpr (suc n)} {u : TmExpr (suc n)} {a : TmExpr n}\n → Derivable (Γ ⊢ A) → Derivable ((Γ , A) ⊢ B) → Derivable ((Γ , A) ⊢ u :> B) → Derivable (Γ ⊢ a :> A)\n → Derivable (Γ ⊢ app A B (lam A B u) a == subst u a :> subst B a)\n EtaPi : {n : ℕ} {Γ : Ctx n} {A : TyExpr n} {B : TyExpr (suc n)} {f : TmExpr n}\n → Derivable (Γ ⊢ A) → Derivable ((Γ , A) ⊢ B) → Derivable (Γ ⊢ f :> pi A B)\n → Derivable (Γ ⊢ f == lam A B (app (weaken last A) (weaken (prev last) B) (weaken last f) (var last)) :> pi A B)\n\ndata DepCtx (n : ℕ) : ℕ → Set where\n ◇ : DepCtx n 0\n _,_ : {m : ℕ} → DepCtx n m → TyExpr (n + m) → DepCtx n (suc m)\n\n_++_ : {n m : ℕ} → Ctx n → DepCtx n m → Ctx (n + m)\nΓ ++ ◇ = Γ\nΓ ++ (Δ , A) = (Γ ++ Δ) , A\n\ninfixl 30 _++_\n\n_-WeakPos_ : (n : ℕ) → WeakPos n → ℕ\nn -WeakPos last = n\nsuc n -WeakPos prev k = n -WeakPos k\n\nweakenCtx : (k : WeakPos n) (Γ : Ctx n) (T : TyExpr (n -WeakPos k)) → Ctx (suc n)\nweakenCtx last Γ T = Γ , T\nweakenCtx (prev k) (Γ , A) T = weakenCtx k Γ T , weaken k A \n\n-- data _⊢_===_ (Γ : Ctx n) : DepCtx n m → DepCtx n m → Prop where\n-- tt : Γ ⊢ ◇ === ◇\n-- _,_ : {Δ Δ' : DepCtx n m} {A A' : TyExpr (n + m)} → (Γ ⊢ Δ === Δ') → Derivable ((Γ ++ Δ) ⊢ A == A') → Γ ⊢ (Δ , A) === (Δ' , A')\n\n\n-- data _⊢_∷>_⇒_ (Γ : Ctx n) : Mor n m k → DepCtx n m → DepCtx n k → Prop where\n-- tt : {Δ : DepCtx n m} → Γ ⊢ ◇ ∷> Δ ⇒ ◇\n-- _,_ : {Δ : DepCtx n m} {Δ' : DepCtx n k} {δ : Mor n m k} {u : TmExpr (n + m)} {A : TyExpr (n + k)}\n-- → Γ ⊢ δ ∷> Δ ⇒ Δ'\n-- → Derivable (Γ ++ Δ ⊢ u :> (A [ δ ]))\n-- → Γ ⊢ (δ , u) ∷> Δ ⇒ (Δ' , A)\n\n-- WeakTy : {k : WeakPos n} {Γ : Ctx n} {T : TyExpr (n -WeakPos k)} {A : TyExpr n}\n-- → Derivable (Γ ⊢ A) → Derivable (weakenCtx k Γ T ⊢ weaken k A)\n-- WeakTy= : {k : WeakPos n} {Γ : Ctx n} {T : TyExpr (n -WeakPos k)} {A B : TyExpr n}\n-- → Derivable (Γ ⊢ A == B) → Derivable (weakenCtx k Γ T ⊢ weaken k A == weaken k B)\n-- WeakTm : {k : WeakPos n} {Γ : Ctx n} {T : TyExpr (n -WeakPos k)} {u : TmExpr n} {A : TyExpr n}\n-- → Derivable (Γ ⊢ u :> A) → Derivable (weakenCtx k Γ T ⊢ weaken k u :> weaken k A)\n-- WeakTm= : {k : WeakPos n} {Γ : Ctx n} {T : TyExpr (n -WeakPos k)} {u v : TmExpr n} {A : TyExpr n}\n-- → Derivable (Γ ⊢ u == v :> A) → Derivable (weakenCtx k Γ T ⊢ weaken k u == weaken k v :> weaken k A)\n\n-- WeakTy UU = UU\n-- WeakTy (El dv) = El (WeakTm dv)\n-- WeakTy (Pi dA dB) = Pi (WeakTy dA) (WeakTy dB)\n\n-- WeakTy= (TyRefl dA) = TyRefl (WeakTy dA)\n-- WeakTy= (TySymm dA=) = TySymm (WeakTy= dA=)\n-- WeakTy= (TyTran dA= dB=) = TyTran (WeakTy= dA=) (WeakTy= dB=)\n-- WeakTy= UUCong = UUCong\n-- WeakTy= (ElCong dv dv' dv=) = ElCong (WeakTm dv) (WeakTm dv') (WeakTm= dv=)\n-- WeakTy= (PiCong dA dA' dA= dB dB' dB=) = PiCong (WeakTy dA) (WeakTy dA') (WeakTy= dA=) (WeakTy dB) (WeakTy dB') (WeakTy= dB=)\n\n-- WeakTm (Var k dA) = Conv (Var (weakenV _ k) {!!}) {!!}\n-- WeakTm (Conv du dA=) = Conv (WeakTm du) (WeakTy= dA=)\n-- WeakTm (Lam dA dB du) = Lam (WeakTy dA) (WeakTy dB) (WeakTm du)\n-- WeakTm (App dA dB df da) = Conv (App (WeakTy dA) (WeakTy dB) (WeakTm df) (WeakTm da)) {!!}\n\n-- WeakTm= (TmRefl du) = TmRefl (WeakTm du)\n-- WeakTm= (TmSymm du=) = TmSymm (WeakTm= du=)\n-- WeakTm= (TmTran du= dv=) = TmTran (WeakTm= du=) (WeakTm= dv=)\n-- WeakTm= (ConvEq du= dA=) = ConvEq (WeakTm= du=) (WeakTy= dA=)\n-- WeakTm= (LamCong dA dA' dA= dB dB' dB= du du' du=) = LamCong (WeakTy dA) (WeakTy dA') (WeakTy= dA=) (WeakTy dB) (WeakTy dB') (WeakTy= dB=) (WeakTm du) (WeakTm du') (WeakTm= du=)\n-- WeakTm= (AppCong dA dA' dA= dB dB' dB= df df' df= da da' da=) = ConvEq (AppCong (WeakTy dA) (WeakTy dA') (WeakTy= dA=) (WeakTy dB) (WeakTy dB') (WeakTy= dB=) (WeakTm df) (WeakTm df') (WeakTm= df=) (WeakTm da) (WeakTm da') (WeakTm= da=)) {!!}\n-- WeakTm= (BetaPi dA dB du da) = ConvEq (TmTran (BetaPi (WeakTy dA) (WeakTy dB) (WeakTm du) (WeakTm da)) {!!}) {!!}\n\n-- WeakMor : {Γ : Ctx n} {Δ : DepCtx n m} {Δ' : DepCtx n k} {T : TyExpr (n + m)} {δ : Mor n m k} → Γ ⊢ δ ∷> Δ ⇒ Δ' → Γ ⊢ weakenMor δ ∷> (Δ , T) ⇒ Δ'\n-- WeakMor tt = tt\n-- WeakMor (dδ , du) = WeakMor dδ , Conv (WeakTm du) {!!}\n\n-- SubstTy : {Γ : Ctx n} {Δ : DepCtx n m} {Δ' : DepCtx n k} {A : TyExpr (n + k)} {δ : Mor n m k}\n-- → Derivable (Γ ++ Δ' ⊢ A) → Γ ⊢ δ ∷> Δ ⇒ Δ' → Derivable (Γ ++ Δ ⊢ A [ δ ])\n-- SubstTy= : {Γ : Ctx n} {Δ : DepCtx n m} {Δ' : DepCtx n k} {A A' : TyExpr (n + k)} {δ : Mor n m k}\n-- → Derivable (Γ ++ Δ' ⊢ A) → Derivable (Γ ++ Δ' ⊢ A == A') → Γ ⊢ δ ∷> Δ ⇒ Δ' → Derivable (Γ ++ Δ ⊢ A [ δ ] == A' [ δ ])\n-- SubstTm : {Γ : Ctx n} {Δ : DepCtx n m} {Δ' : DepCtx n k} {u : TmExpr (n + k)} {A : TyExpr (n + k)} {δ : Mor n m k}\n-- → Derivable (Γ ++ Δ' ⊢ u :> A) → Γ ⊢ δ ∷> Δ ⇒ Δ' → Derivable (Γ ++ Δ ⊢ u [ δ ] :> A [ δ ])\n-- SubstTm= : {Γ : Ctx n} {Δ : DepCtx n m} {Δ' : DepCtx n k} {u u' : TmExpr (n + k)} {A : TyExpr (n + k)} {δ : Mor n m k}\n-- → Derivable (Γ ++ Δ' ⊢ u == u' :> A) → Γ ⊢ δ ∷> Δ ⇒ Δ' → Derivable (Γ ++ Δ ⊢ u [ δ ] == u' [ δ ] :> A [ δ ])\n\n-- WeakMor+ : {Γ : Ctx n} {Δ : DepCtx n m} {Δ' : DepCtx n k} {A : TyExpr (n + k)} {δ : Mor n m k} → Derivable (Γ ++ Δ' ⊢ A) → Γ ⊢ δ ∷> Δ ⇒ Δ' → Γ ⊢ weakenMor+ δ ∷> (Δ , A [ δ ]) ⇒ (Δ' , A)\n-- WeakMor+ dA dδ = WeakMor dδ , Conv (Var last (WeakTy (SubstTy dA dδ))) {!syntx!}\n\n-- TyEqTy1 : {Γ : Ctx n} {A B : TyExpr n} → Derivable (Γ ⊢ A == B) → Derivable (Γ ⊢ A)\n-- TyEqTy2 : {Γ : Ctx n} {A B : TyExpr n} → Derivable (Γ ⊢ A == B) → Derivable (Γ ⊢ B)\n-- TmEqTm1 : {Γ : Ctx n} {u u' : TmExpr n} {A : TyExpr n} → Derivable (Γ ⊢ u == u' :> A) → Derivable (Γ ⊢ u :> A)\n-- TmEqTm2 : {Γ : Ctx n} {u u' : TmExpr n} {A : TyExpr n} → Derivable (Γ ⊢ u == u' :> A) → Derivable (Γ ⊢ u' :> A)\n\n-- SubstTy UU dδ = UU\n-- SubstTy (El dv) dδ = El (SubstTm dv dδ)\n-- SubstTy (Pi dA dB) dδ = Pi (SubstTy dA dδ) (SubstTy dB (WeakMor+ dA dδ))\n\n-- -- SubstTy= _ (TyRefl dA) dδ = TyRefl (SubstTy dA dδ)\n-- -- SubstTy= dA (TySymm dA=) dδ = TySymm (SubstTy= {!!} dA= dδ)\n-- -- SubstTy= dA (TyTran dA= dB=) dδ = TyTran (SubstTy= dA dA= dδ) (SubstTy= {!!} dB= dδ)\n-- -- SubstTy= dA UUCong dδ = UUCong\n-- -- SubstTy= dA (ElCong dv=) dδ = ElCong (SubstTm= dv= dδ)\n-- -- SubstTy= {Γ = Γ} (Pi dA dB) (PiCong dA= dB=) dδ = PiCong (SubstTy= dA dA= dδ) (SubstTy= dB dB= (WeakMor+ dA dδ))\n\n-- -- SubstTm (Var k du) dδ = {!!}\n-- -- SubstTm (Conv du dA=) dδ = Conv (SubstTm du dδ) (SubstTy= dA= dδ)\n-- -- SubstTm (Lam dA dB du) dδ = Lam (SubstTy dA dδ) (SubstTy dB (WeakMor+ dA dδ)) (SubstTm du (WeakMor+ dA dδ))\n-- -- SubstTm (App dA dB df da) dδ = Conv (App (SubstTy dA dδ) (SubstTy dB (WeakMor+ dA dδ)) (SubstTm df dδ) (SubstTm da dδ)) {!!}\n\n-- -- SubstTm= (TmRefl du) dδ = TmRefl (SubstTm du dδ)\n-- -- SubstTm= (TmSymm du=) dδ = TmSymm (SubstTm= du= dδ)\n-- -- SubstTm= (TmTran du= dv=) dδ = TmTran (SubstTm= du= dδ) (SubstTm= dv= dδ)\n-- -- SubstTm= (ConvEq du= dA=) dδ = ConvEq (SubstTm= du= dδ) (SubstTy= dA= dδ)\n-- -- SubstTm= (LamCong dA= dB= du=) dδ = LamCong (SubstTy= dA= dδ) (SubstTy= dB= (WeakMor+ {!TyEqTy1 dA=!} dδ)) (SubstTm= du= (WeakMor+ {!TyEqTy1 dA=!} dδ))\n-- -- SubstTm= (AppCong dA= dB= df= da=) dδ = ConvEq (AppCong (SubstTy= dA= dδ) (SubstTy= dB= (WeakMor+ {!TyEqTy1 dA=!} dδ)) (SubstTm= df= dδ) (SubstTm= da= dδ)) {!stx!}\n-- -- SubstTm= (BetaPi dA dB du da) dδ = ConvEq (TmTran (BetaPi (SubstTy dA dδ) (SubstTy dB (WeakMor+ dA dδ)) (SubstTm du (WeakMor+ dA dδ)) (SubstTm da dδ)) {!!}) {!!}\n\n-- -- ConvTy : {n m : ℕ} {Γ : Ctx n} {Δ Δ' : DepCtx n m} {A : TyExpr (n + m)} → Derivable ((Γ ++ Δ) ⊢ A) → (Γ ⊢ Δ === Δ') → Derivable ((Γ ++ Δ') ⊢ A)\n-- -- ConvTy= : {n m : ℕ} {Γ : Ctx n} {Δ Δ' : DepCtx n m} {A A' : TyExpr (n + m)} → Derivable ((Γ ++ Δ) ⊢ A == A') → (Γ ⊢ Δ === Δ') → Derivable ((Γ ++ Δ') ⊢ A == A')\n-- -- ConvTm : {n m : ℕ} {Γ : Ctx n} {Δ Δ' : DepCtx n m} {A : TyExpr (n + m)} {u : TmExpr (n + m)} → Derivable ((Γ ++ Δ) ⊢ u :> A) → (Γ ⊢ Δ === Δ') → Derivable ((Γ ++ Δ') ⊢ u :> A)\n-- -- ConvTm= : {n m : ℕ} {Γ : Ctx n} {Δ Δ' : DepCtx n m} {A : TyExpr (n + m)} {u u' : TmExpr (n + m)} → Derivable ((Γ ++ Δ) ⊢ u == u' :> A) → (Γ ⊢ Δ === Δ') → Derivable ((Γ ++ Δ') ⊢ u == u' :> A)\n\n\n-- -- ConvTy UU dΔ= = UU\n-- -- ConvTy (El dv) dΔ= = El (ConvTm dv dΔ=)\n-- -- ConvTy (Pi dA dB) dΔ= = Pi (ConvTy dA dΔ=) (ConvTy dB (dΔ= , TyRefl dA))\n\n-- -- ConvTy= (TyRefl dA) dΔ= = TyRefl (ConvTy dA dΔ=)\n-- -- ConvTy= (TySymm dA=) dΔ= = TySymm (ConvTy= dA= dΔ=)\n-- -- ConvTy= (TyTran dA= dB=) dΔ= = TyTran (ConvTy= dA= dΔ=) (ConvTy= dB= dΔ=)\n-- -- ConvTy= UUCong dΔ= = UUCong\n-- -- ConvTy= (ElCong dv=) dΔ= = ElCong (ConvTm= dv= dΔ=)\n-- -- ConvTy= (PiCong dA= dB=) dΔ= = PiCong (ConvTy= dA= dΔ=) (ConvTy= dB= (dΔ= , {!ok!}))\n\n-- -- ConvTm (Var k du) dΔ= = Conv (Var k (ConvTy {!TODO!} dΔ=)) {!TODO!}\n-- -- ConvTm (Conv du dA=) dΔ= = Conv (ConvTm du dΔ=) (ConvTy= dA= dΔ=)\n-- -- ConvTm (Lam dA dB du) dΔ= = Lam (ConvTy dA dΔ=) (ConvTy dB (dΔ= , TyRefl dA)) (ConvTm du (dΔ= , TyRefl dA))\n-- -- ConvTm (App dA dB df da) dΔ= = App (ConvTy dA dΔ=) (ConvTy dB (dΔ= , TyRefl dA)) (ConvTm df dΔ=) (ConvTm da dΔ=)\n\n-- -- ConvTm= (TmRefl du) dΔ= = TmRefl (ConvTm du dΔ=)\n-- -- ConvTm= (TmSymm du=) dΔ= = TmSymm (ConvTm= du= dΔ=)\n-- -- ConvTm= (TmTran du= dv=) dΔ= = TmTran (ConvTm= du= dΔ=) (ConvTm= dv= dΔ=)\n-- -- ConvTm= (ConvEq du= dA=) dΔ= = ConvEq (ConvTm= du= dΔ=) (ConvTy= dA= dΔ=)\n-- -- ConvTm= (LamCong dA= dB= du=) dΔ= = LamCong (ConvTy= dA= dΔ=) (ConvTy= dB= (dΔ= , {!ok!})) (ConvTm= du= (dΔ= , {!ok!}))\n-- -- ConvTm= (AppCong dA= dB= df= da=) dΔ= = AppCong (ConvTy= dA= dΔ=) (ConvTy= dB= (dΔ= , {!ok!})) (ConvTm= df= dΔ=) (ConvTm= da= dΔ=)\n-- -- ConvTm= (BetaPi dA dB du da) dΔ= = BetaPi (ConvTy dA dΔ=) (ConvTy dB (dΔ= , TyRefl dA)) (ConvTm du (dΔ= , TyRefl dA)) (ConvTm da dΔ=)\n\n-- -- TyEqTy1 (TyRefl dA) = dA\n-- -- TyEqTy1 (TySymm dA=) = TyEqTy2 dA=\n-- -- TyEqTy1 (TyTran dA= dB=) = TyEqTy1 dA=\n-- -- TyEqTy1 UUCong = UU\n-- -- TyEqTy1 (ElCong du=) = El (TmEqTm1 du=)\n-- -- TyEqTy1 (PiCong dA= dB=) = Pi (TyEqTy1 dA=) (TyEqTy1 dB=)\n\n-- -- TyEqTy2 (TyRefl dA) = dA\n-- -- TyEqTy2 (TySymm dA=) = TyEqTy1 dA=\n-- -- TyEqTy2 (TyTran dA= dB=) = TyEqTy2 dB=\n-- -- TyEqTy2 UUCong = UU\n-- -- TyEqTy2 (ElCong du=) = El (TmEqTm2 du=)\n-- -- TyEqTy2 (PiCong dA= dB=) = Pi (TyEqTy2 dA=) (ConvTy (TyEqTy2 dB=) (tt , dA=))\n\n-- -- TmEqTm1 (TmRefl du) = du\n-- -- TmEqTm1 (TmSymm du=) = TmEqTm2 du=\n-- -- TmEqTm1 (TmTran du= dv=) = TmEqTm1 du=\n-- -- TmEqTm1 (ConvEq du= dA=) = Conv (TmEqTm1 du=) dA=\n-- -- TmEqTm1 (LamCong dA= dB= du=) = Lam (TyEqTy1 dA=) (TyEqTy1 dB=) (TmEqTm1 du=)\n-- -- TmEqTm1 (AppCong dA= dB= df= da=) = App (TyEqTy1 dA=) (TyEqTy1 dB=) (TmEqTm1 df=) (TmEqTm1 da=)\n-- -- TmEqTm1 (BetaPi dA dB du da) = App dA dB (Lam dA dB du) da\n\n-- -- TmEqTm2 (TmRefl du) = du\n-- -- TmEqTm2 (TmSymm du=) = TmEqTm1 du=\n-- -- TmEqTm2 (TmTran du= dv=) = TmEqTm2 dv=\n-- -- TmEqTm2 (ConvEq du= dA=) = Conv (TmEqTm2 du=) dA=\n-- -- TmEqTm2 (LamCong dA= dB= du=) = Conv (Lam (TyEqTy2 dA=) (ConvTy (TyEqTy2 dB=) (tt , dA=)) (ConvTm (Conv (TmEqTm2 du=) dB=) (tt , dA=))) (PiCong (TySymm dA=) (ConvTy= (TySymm dB=) (tt , dA=)))\n-- -- TmEqTm2 (AppCong dA= dB= df= da=) = Conv (App (TyEqTy2 dA=) (ConvTy (TyEqTy2 dB=) (tt , dA=)) (Conv (TmEqTm2 df=) (PiCong dA= dB=)) (Conv (TmEqTm2 da=) dA=)) {!TySymm (SubstTy= dB= (tt , {!da=!}))!}\n-- -- TmEqTm2 (BetaPi dA dB du da) = {!SubstTm du (tt , {!da!})!}\n", "meta": {"hexsha": "c6c09eddb61be1d168c07159c1598d6a7aedd269", "size": 18058, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "traditional.agda", "max_stars_repo_name": "guillaumebrunerie/general-type-theories", "max_stars_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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": "traditional.agda", "max_issues_repo_name": "guillaumebrunerie/general-type-theories", "max_issues_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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": "traditional.agda", "max_forks_repo_name": "guillaumebrunerie/general-type-theories", "max_forks_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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": 52.1907514451, "max_line_length": 244, "alphanum_fraction": 0.5132905084, "num_tokens": 8816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737214979745, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.3837269063483285}} {"text": "{-# OPTIONS --without-K --allow-unsolved-metas --exact-split #-}\n\nmodule 16-pushouts where\n\nimport 15-pullbacks\nopen 15-pullbacks public\n\n-- Section 14.1\n\n{- We define the type of cocones with vertex X on a span. Since we will use it\n later on, we will also characterize the identity type of the type of cocones\n with a given vertex X. -}\n\ncocone :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) → UU l4 → UU _\ncocone {A = A} {B = B} f g X =\n Σ (A → X) (λ i → Σ (B → X) (λ j → (i ∘ f) ~ (j ∘ g)))\n\n{- We characterize the identity type of the type of cocones with vertex C. -}\n\ncoherence-htpy-cocone :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) →\n (K : (pr1 c) ~ (pr1 c')) (L : (pr1 (pr2 c)) ~ (pr1 (pr2 c'))) → UU (l1 ⊔ l4)\ncoherence-htpy-cocone f g c c' K L =\n ((pr2 (pr2 c)) ∙h (L ·r g)) ~ ((K ·r f) ∙h (pr2 (pr2 c')))\n\nhtpy-cocone :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} →\n cocone f g X → cocone f g X → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ l4)))\nhtpy-cocone f g c c' =\n Σ ((pr1 c) ~ (pr1 c'))\n ( λ K → Σ ((pr1 (pr2 c)) ~ (pr1 (pr2 c')))\n ( coherence-htpy-cocone f g c c' K))\n\nreflexive-htpy-cocone :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →\n htpy-cocone f g c c\nreflexive-htpy-cocone f g (pair i (pair j H)) =\n pair htpy-refl (pair htpy-refl htpy-right-unit)\n\nhtpy-cocone-eq :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) →\n Id c c' → htpy-cocone f g c c'\nhtpy-cocone-eq f g c .c refl = reflexive-htpy-cocone f g c\n\nis-contr-total-htpy-cocone :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →\n is-contr (Σ (cocone f g X) (htpy-cocone f g c))\nis-contr-total-htpy-cocone f g c =\n is-contr-total-Eq-structure\n ( λ i' jH' K → Σ ((pr1 (pr2 c)) ~ (pr1 jH'))\n ( coherence-htpy-cocone f g c (pair i' jH') K))\n ( is-contr-total-htpy (pr1 c))\n ( pair (pr1 c) htpy-refl)\n ( is-contr-total-Eq-structure\n ( λ j' H' → coherence-htpy-cocone f g c\n ( pair (pr1 c) (pair j' H'))\n ( htpy-refl))\n ( is-contr-total-htpy (pr1 (pr2 c)))\n ( pair (pr1 (pr2 c)) htpy-refl)\n ( is-contr-is-equiv'\n ( Σ (((pr1 c) ∘ f) ~ ((pr1 (pr2 c)) ∘ g)) (λ H' → (pr2 (pr2 c)) ~ H'))\n ( tot (λ H' M → htpy-right-unit ∙h M))\n ( is-equiv-tot-is-fiberwise-equiv (λ H' → is-equiv-htpy-concat _ _))\n ( is-contr-total-htpy (pr2 (pr2 c)))))\n\nis-equiv-htpy-cocone-eq :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) →\n is-equiv (htpy-cocone-eq f g c c')\nis-equiv-htpy-cocone-eq f g c =\n fundamental-theorem-id c\n ( reflexive-htpy-cocone f g c)\n ( is-contr-total-htpy-cocone f g c)\n ( htpy-cocone-eq f g c)\n\neq-htpy-cocone :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) →\n htpy-cocone f g c c' → Id c c'\neq-htpy-cocone f g c c' = inv-is-equiv (is-equiv-htpy-cocone-eq f g c c')\n\n{- Given a cocone c on a span S with vertex X, and a type Y, the function \n cocone-map sends a function X → Y to a new cocone with vertex Y. -}\n\ncocone-map :\n {l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} {Y : UU l5} →\n cocone f g X → (X → Y) → cocone f g Y\ncocone-map f g (pair i (pair j H)) h =\n pair (h ∘ i) (pair (h ∘ j) (h ·l H))\n\ncocone-map-id :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →\n Id (cocone-map f g c id) c\ncocone-map-id f g (pair i (pair j H)) =\n eq-pair refl (eq-pair refl (eq-htpy (λ s → ap-id (H s))))\n\ncocone-map-comp :\n {l1 l2 l3 l4 l5 l6 : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X)\n {Y : UU l5} (h : X → Y) {Z : UU l6} (k : Y → Z) →\n Id (cocone-map f g c (k ∘ h)) ((cocone-map f g (cocone-map f g c h) k))\ncocone-map-comp f g (pair i (pair j H)) h k =\n eq-pair refl (eq-pair refl (eq-htpy (λ s → ap-comp k h (H s))))\n\n{- A cocone c on a span S is said to satisfy the universal property of the\n pushout of S if the function cocone-map is an equivalence for every type Y.\n -}\n\nuniversal-property-pushout :\n {l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} →\n cocone f g X → UU _\nuniversal-property-pushout l f g c =\n (Y : UU l) → is-equiv (cocone-map f g {Y = Y} c)\n\n-- Section 14.2 Suspensions\n\nsuspension-structure :\n {l1 l2 : Level} (X : UU l1) (Y : UU l2) → UU (l1 ⊔ l2)\nsuspension-structure X Y = Σ Y (λ N → Σ Y (λ S → (x : X) → Id N S))\n\nsuspension-cocone' :\n {l1 l2 : Level} (X : UU l1) (Y : UU l2) → UU (l1 ⊔ l2)\nsuspension-cocone' X Y = cocone (const X unit star) (const X unit star) Y\n\ncocone-suspension-structure :\n {l1 l2 : Level} (X : UU l1) (Y : UU l2) →\n suspension-structure X Y → suspension-cocone' X Y\ncocone-suspension-structure X Y (pair N (pair S merid)) =\n pair\n ( const unit Y N)\n ( pair\n ( const unit Y S)\n ( merid))\n\nuniversal-property-suspension' :\n (l : Level) {l1 l2 : Level} (X : UU l1) (Y : UU l2)\n (susp-str : suspension-structure X Y) → UU (lsuc l ⊔ l1 ⊔ l2)\nuniversal-property-suspension' l X Y susp-str-Y =\n universal-property-pushout l\n ( const X unit star)\n ( const X unit star)\n ( cocone-suspension-structure X Y susp-str-Y)\n\nis-suspension :\n (l : Level) {l1 l2 : Level} (X : UU l1) (Y : UU l2) → UU (lsuc l ⊔ l1 ⊔ l2)\nis-suspension l X Y =\n Σ (suspension-structure X Y) (universal-property-suspension' l X Y)\n\n{- We define the type of suspensions at universe level l, for any type X. Since\n we would like to define type families over a suspension by the universal\n property of the suspension, we assume that the universal property of a \n suspension holds for at least level (lsuc l ⊔ l1). This is the level that\n contains both X and the suspension itself. -}\n\nUU-Suspensions :\n (l : Level) {l1 : Level} (X : UU l1) → UU (lsuc (lsuc l) ⊔ lsuc l1)\nUU-Suspensions l {l1} X = Σ (UU l) (is-suspension (lsuc l ⊔ l1) X)\n\n{- We now work towards Lemma 17.2.2. -}\n\nsuspension-cocone :\n {l1 l2 : Level} (X : UU l1) (Z : UU l2) → UU _\nsuspension-cocone X Z = Σ Z (λ z1 → Σ Z (λ z2 → (x : X) → Id z1 z2))\n\nev-suspension :\n {l1 l2 l3 : Level} {X : UU l1} {Y : UU l2} →\n (susp-str-Y : suspension-structure X Y) →\n (Z : UU l3) → (Y → Z) → suspension-cocone X Z\nev-suspension (pair N (pair S merid)) Z h =\n pair (h N) (pair (h S) (h ·l merid))\n\nuniversal-property-suspension :\n (l : Level) {l1 l2 : Level} (X : UU l1) (Y : UU l2) →\n suspension-structure X Y → UU (lsuc l ⊔ l1 ⊔ l2)\nuniversal-property-suspension l X Y susp-str-Y =\n (Z : UU l) → is-equiv (ev-suspension susp-str-Y Z)\n\ncomparison-suspension-cocone :\n {l1 l2 : Level} (X : UU l1) (Z : UU l2) →\n suspension-cocone' X Z ≃ suspension-cocone X Z\ncomparison-suspension-cocone X Z =\n equiv-toto\n ( λ z1 → Σ Z (λ z2 → (x : X) → Id z1 z2))\n ( equiv-ev-star' Z)\n ( λ z1 →\n equiv-toto\n ( λ z2 → (x : X) → Id (z1 star) z2)\n ( equiv-ev-star' Z)\n ( λ z2 → equiv-id ((x : X) → Id (z1 star) (z2 star))))\n\nmap-comparison-suspension-cocone :\n {l1 l2 : Level} (X : UU l1) (Z : UU l2) →\n suspension-cocone' X Z → suspension-cocone X Z\nmap-comparison-suspension-cocone X Z =\n map-equiv (comparison-suspension-cocone X Z)\n\nis-equiv-map-comparison-suspension-cocone :\n {l1 l2 : Level} (X : UU l1) (Z : UU l2) →\n is-equiv (map-comparison-suspension-cocone X Z)\nis-equiv-map-comparison-suspension-cocone X Z =\n is-equiv-map-equiv (comparison-suspension-cocone X Z)\n\ntriangle-ev-suspension :\n {l1 l2 l3 : Level} {X : UU l1} {Y : UU l2} →\n (susp-str-Y : suspension-structure X Y) →\n (Z : UU l3) →\n ( ( map-comparison-suspension-cocone X Z) ∘\n ( cocone-map\n ( const X unit star)\n ( const X unit star)\n ( cocone-suspension-structure X Y susp-str-Y))) ~\n ( ev-suspension susp-str-Y Z)\ntriangle-ev-suspension (pair N (pair S merid)) Z h = refl\n\nis-equiv-ev-suspension :\n { l1 l2 l3 : Level} {X : UU l1} {Y : UU l2} →\n ( susp-str-Y : suspension-structure X Y) →\n ( up-Y : universal-property-suspension' l3 X Y susp-str-Y) → \n ( Z : UU l3) → is-equiv (ev-suspension susp-str-Y Z)\nis-equiv-ev-suspension {X = X} susp-str-Y up-Y Z =\n is-equiv-comp\n ( ev-suspension susp-str-Y Z)\n ( map-comparison-suspension-cocone X Z)\n ( cocone-map\n ( const X unit star)\n ( const X unit star)\n ( cocone-suspension-structure X _ susp-str-Y))\n ( htpy-inv (triangle-ev-suspension susp-str-Y Z))\n ( up-Y Z)\n ( is-equiv-map-comparison-suspension-cocone X Z)\n\n{- Pointed maps and pointed homotopies. -}\n\npointed-fam :\n {l1 : Level} (l : Level) (X : UU-pt l1) → UU (lsuc l ⊔ l1)\npointed-fam l (pair X x) = Σ (X → UU l) (λ P → P x)\n\npointed-Π :\n {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) → UU (l1 ⊔ l2)\npointed-Π (pair X x) (pair P p) = Σ ((x' : X) → P x') (λ f → Id (f x) p)\n\npointed-htpy :\n {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) →\n (f g : pointed-Π X P) → UU (l1 ⊔ l2)\npointed-htpy (pair X x) (pair P p) (pair f α) g =\n pointed-Π (pair X x) (pair (λ x' → Id (f x') (pr1 g x')) (α ∙ (inv (pr2 g))))\n\npointed-htpy-refl :\n {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) →\n (f : pointed-Π X P) → pointed-htpy X P f f\npointed-htpy-refl (pair X x) (pair P p) (pair f α) =\n pair htpy-refl (inv (right-inv α))\n\npointed-htpy-eq :\n {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) →\n (f g : pointed-Π X P) → Id f g → pointed-htpy X P f g\npointed-htpy-eq X P f .f refl = pointed-htpy-refl X P f\n\nis-contr-total-pointed-htpy :\n {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) (f : pointed-Π X P) →\n is-contr (Σ (pointed-Π X P) (pointed-htpy X P f))\nis-contr-total-pointed-htpy (pair X x) (pair P p) (pair f α) =\n is-contr-total-Eq-structure\n ( λ g β (H : f ~ g) → Id (H x) (α ∙ (inv β)))\n ( is-contr-total-htpy f)\n ( pair f htpy-refl)\n ( is-contr-equiv'\n ( Σ (Id (f x) p) (λ β → Id β α))\n ( equiv-tot (λ β → equiv-con-inv refl β α))\n ( is-contr-total-path' α))\n\nis-equiv-pointed-htpy-eq :\n {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) →\n (f g : pointed-Π X P) → is-equiv (pointed-htpy-eq X P f g)\nis-equiv-pointed-htpy-eq X P f =\n fundamental-theorem-id f\n ( pointed-htpy-refl X P f)\n ( is-contr-total-pointed-htpy X P f)\n ( pointed-htpy-eq X P f)\n\neq-pointed-htpy :\n {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) →\n (f g : pointed-Π X P) → (pointed-htpy X P f g) → Id f g\neq-pointed-htpy X P f g = inv-is-equiv (is-equiv-pointed-htpy-eq X P f g)\n\n-- Section 14.3 Duality of pushouts and pullbacks\n \n{- The universal property of the pushout of a span S can also be stated as a\n pullback-property: a cocone c = (pair i (pair j H)) with vertex X\n satisfies the universal property of the pushout of S if and only if the\n square\n\n Y^X -----> Y^B\n | |\n | |\n V V\n Y^A -----> Y^S\n\n is a pullback square for every type Y. Below, we first define the cone of\n this commuting square, and then we introduce the type \n pullback-property-pushout, which states that the above square is a pullback.\n -}\n\nhtpy-precomp :\n {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}\n {f g : A → B} (H : f ~ g) (C : UU l3) →\n (precomp f C) ~ (precomp g C)\nhtpy-precomp H C h = eq-htpy (h ·l H)\n\ncompute-htpy-precomp :\n {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : UU l3) →\n (htpy-precomp (htpy-refl' f) C) ~ htpy-refl\ncompute-htpy-precomp f C h = eq-htpy-htpy-refl (h ∘ f)\n\ncone-pullback-property-pushout :\n {l1 l2 l3 l4 l : Level} {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) (Y : UU l) →\n cone (λ (h : A → Y) → h ∘ f) (λ (h : B → Y) → h ∘ g) (X → Y)\ncone-pullback-property-pushout f g {X} c Y =\n pair\n ( precomp (pr1 c) Y)\n ( pair\n ( precomp (pr1 (pr2 c)) Y)\n ( htpy-precomp (pr2 (pr2 c)) Y))\n\npullback-property-pushout :\n {l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2} {B : UU l3}\n (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →\n UU (l1 ⊔ (l2 ⊔ (l3 ⊔ (l4 ⊔ lsuc l))))\npullback-property-pushout l {S} {A} {B} f g {X} c =\n (Y : UU l) → is-pullback\n ( precomp f Y)\n ( precomp g Y)\n ( cone-pullback-property-pushout f g c Y)\n\n{- In order to show that the universal property of pushouts is equivalent to \n the pullback property, we show that the maps cocone-map and the gap map fit \n in a commuting triangle, where the third map is an equivalence. The claim \n then follows from the 3-for-2 property of equivalences. -}\n \ntriangle-pullback-property-pushout-universal-property-pushout :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2}\n {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →\n {l : Level} (Y : UU l) →\n ( cocone-map f g c) ~\n ( ( tot (λ i' → tot (λ j' p → htpy-eq p))) ∘\n ( gap (λ h → h ∘ f) (λ h → h ∘ g) (cone-pullback-property-pushout f g c Y)))\ntriangle-pullback-property-pushout-universal-property-pushout\n {S = S} {A = A} {B = B} f g (pair i (pair j H)) Y h =\n eq-pair refl (eq-pair refl (inv (issec-eq-htpy (h ·l H))))\n\npullback-property-pushout-universal-property-pushout :\n {l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2}\n {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →\n universal-property-pushout l f g c → pullback-property-pushout l f g c\npullback-property-pushout-universal-property-pushout\n l f g (pair i (pair j H)) up-c Y =\n let c = (pair i (pair j H)) in\n is-equiv-right-factor\n ( cocone-map f g c)\n ( tot (λ i' → tot (λ j' p → htpy-eq p)))\n ( gap (λ h → h ∘ f) (λ h → h ∘ g) (cone-pullback-property-pushout f g c Y))\n ( triangle-pullback-property-pushout-universal-property-pushout f g c Y)\n ( is-equiv-tot-is-fiberwise-equiv\n ( λ i' → is-equiv-tot-is-fiberwise-equiv\n ( λ j' → funext (i' ∘ f) (j' ∘ g))))\n ( up-c Y)\n\nuniversal-property-pushout-pullback-property-pushout :\n {l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2}\n {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →\n pullback-property-pushout l f g c → universal-property-pushout l f g c\nuniversal-property-pushout-pullback-property-pushout\n l f g (pair i (pair j H)) pb-c Y =\n let c = (pair i (pair j H)) in\n is-equiv-comp\n ( cocone-map f g c)\n ( tot (λ i' → tot (λ j' p → htpy-eq p)))\n ( gap (λ h → h ∘ f) (λ h → h ∘ g) (cone-pullback-property-pushout f g c Y))\n ( triangle-pullback-property-pushout-universal-property-pushout f g c Y)\n ( pb-c Y)\n ( is-equiv-tot-is-fiberwise-equiv\n ( λ i' → is-equiv-tot-is-fiberwise-equiv\n ( λ j' → funext (i' ∘ f) (j' ∘ g))))\n\ncocone-compose-horizontal :\n { l1 l2 l3 l4 l5 l6 : Level}\n { A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6}\n ( f : A → X) (i : A → B) (k : B → C) →\n ( c : cocone f i Y) (d : cocone (pr1 (pr2 c)) k Z) →\n cocone f (k ∘ i) Z\ncocone-compose-horizontal f i k (pair j (pair g H)) (pair l (pair h K)) =\n pair\n ( l ∘ j)\n ( pair\n ( h)\n ( (l ·l H) ∙h (K ·r i)))\n\n{-\nis-pushout-rectangle-is-pushout-right-square :\n ( l : Level) { l1 l2 l3 l4 l5 l6 : Level}\n { A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6}\n ( f : A → X) (i : A → B) (k : B → C) →\n ( c : cocone f i Y) (d : cocone (pr1 (pr2 c)) k Z) →\n universal-property-pushout l f i c →\n universal-property-pushout l (pr1 (pr2 c)) k d →\n universal-property-pushout l f (k ∘ i) (cocone-compose-horizontal f i k c d)\nis-pushout-rectangle-is-pushout-right-square l f i k c d up-Y up-Z =\n universal-property-pushout-pullback-property-pushout l f (k ∘ i)\n ( cocone-compose-horizontal f i k c d)\n ( λ T → is-pullback-htpy {!!} {!!} {!!} {!!} {!!} {!!} {!!})\n-}\n\n-- Exercises\n\n-- Exercise 13.1\n\n-- Exercise 13.2\n\nis-equiv-universal-property-pushout :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}\n (f : S → A) (g : S → B) (c : cocone f g C) →\n is-equiv f →\n ((l : Level) → universal-property-pushout l f g c) → is-equiv (pr1 (pr2 c))\nis-equiv-universal-property-pushout\n {A = A} {B} f g (pair i (pair j H)) is-equiv-f up-c =\n is-equiv-is-equiv-precomp j\n ( λ l T →\n is-equiv-is-pullback'\n ( λ (h : A → T) → h ∘ f)\n ( λ (h : B → T) → h ∘ g)\n ( cone-pullback-property-pushout f g (pair i (pair j H)) T)\n ( is-equiv-precomp-is-equiv f is-equiv-f T)\n ( pullback-property-pushout-universal-property-pushout\n l f g (pair i (pair j H)) (up-c l) T))\n\nuniversal-property-pushout-is-equiv :\n {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}\n (f : S → A) (g : S → B) (c : cocone f g C) →\n is-equiv f → is-equiv (pr1 (pr2 c)) →\n ((l : Level) → universal-property-pushout l f g c)\nuniversal-property-pushout-is-equiv f g (pair i (pair j H)) is-equiv-f is-equiv-j l =\n let c = (pair i (pair j H)) in\n universal-property-pushout-pullback-property-pushout l f g c\n ( λ T → is-pullback-is-equiv'\n ( λ h → h ∘ f)\n ( λ h → h ∘ g)\n ( cone-pullback-property-pushout f g c T)\n ( is-equiv-precomp-is-equiv f is-equiv-f T)\n ( is-equiv-precomp-is-equiv j is-equiv-j T))\n \n", "meta": {"hexsha": "553e1704f980e02d2c5200529c99216d790f3e3f", "size": 17524, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Agda/16-pushouts.agda", "max_stars_repo_name": "tadejpetric/HoTT-Intro", "max_stars_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_stars_repo_licenses": ["CC-BY-4.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": "Agda/16-pushouts.agda", "max_issues_repo_name": "tadejpetric/HoTT-Intro", "max_issues_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_issues_repo_licenses": ["CC-BY-4.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": "Agda/16-pushouts.agda", "max_forks_repo_name": "tadejpetric/HoTT-Intro", "max_forks_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9307359307, "max_line_length": 85, "alphanum_fraction": 0.571102488, "num_tokens": 7209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6688802735722128, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.38372217011930604}} {"text": "{-# OPTIONS --rewriting --confluence-check #-}\n\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Equality.Rewrite\n\npostulate\n A : Set\n a b c : A\n f g : A → A\n\n rew₁ : f a ≡ b\n rew₂ : ∀ {x} → f (g x) ≡ c\n rew₃ : g a ≡ a\n\n{-# REWRITE rew₁ #-}\n{-# REWRITE rew₂ #-}\n{-# REWRITE rew₃ #-}\n\nworks : (x : A) → f (g x) ≡ c\nworks x = refl\n\nworks' : f (g a) ≡ c\nworks' = works a\n\nfails : f (g a) ≡ c\nfails = refl\n", "meta": {"hexsha": "8629cb6abe20dff1036089f8f07915e8aa849a44", "size": 418, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/ConfluenceNestedOverlap.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/ConfluenceNestedOverlap.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/ConfluenceNestedOverlap.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": 15.4814814815, "max_line_length": 46, "alphanum_fraction": 0.5550239234, "num_tokens": 167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6688802603710086, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.3837221625460602}} {"text": "module FStream.FVec where\n\n------------------------------------------------------------------------\n-- Dissecting effectful streams\n------------------------------------------------------------------------\n\nopen import Library\nopen import FStream.Core\nopen import Data.Fin\n\ninfixr 5 _▻_\ninfix 6 ⟨_▻⋯\ninfix 7 _⟩\n\ndata FVec {ℓ₁ ℓ₂} (C : Container ℓ₁) (A : Set ℓ₂) : (n : ℕ) → Set (ℓ₁ ⊔ ℓ₂) where\n FNil : FVec C A 0\n FCons : ∀ {n} → ⟦ C ⟧ (A × FVec C A n) → FVec C A (suc n)\n\n-- TODO Syntactic sugar for these as well\ndata FVec' {ℓ₁ ℓ₂} (C : Container ℓ₁) (A : Set ℓ₂) : (n : ℕ) → Set (ℓ₁ ⊔ ℓ₂) where\n FNil' : FVec' C A 0\n FCons' : ∀ {n} → A → ⟦ C ⟧ (FVec' C A n) → FVec' C A (suc n)\n\n_▻'_ : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n} →\n A → ⟦ C ⟧ (FVec' C A n) → FVec' C A (suc n)\n_▻'_ = FCons'\n\nfVec'ToFVec : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n} →\n FVec' C A n → FVec C A n\nfVec'ToFVec FNil' = FNil\nfVec'ToFVec (FCons' a v) = FCons (fmap (λ x → a , fVec'ToFVec x) v)\n\nnest : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n} →\n Vec (⟦ C ⟧ A) n → FVec C A n\nnest [] = FNil\nnest (a ∷ as) = FCons (fmap (_, nest as) a)\n\n_▻_ : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n} →\n ⟦ C ⟧ A → (FVec C A n) → FVec C A (suc n)\na ▻ v = FCons (fmap (λ x → x , v) a)\n\n_⟩ : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} → ⟦ C ⟧ A → FVec C A 1\na ⟩ = a ▻ FNil\n\nmutual\n vmap : ∀ {ℓ₁ ℓ₂ ℓ₃} {C : Container ℓ₁} {A : Set ℓ₂} {B : Set ℓ₃} {n} →\n (f : A → B) → FVec C A n → FVec C B n\n vmap _ FNil = FNil\n vmap f (FCons x) = FCons (fmap (vmap' f) x)\n\n vmap' : ∀ {ℓ₁ ℓ₂ ℓ₃} {C : Container ℓ₁} {A : Set ℓ₂} {B : Set ℓ₃} {n} →\n (f : A → B) → A × FVec C A n → B × FVec C B n\n vmap' f (a , v) = f a , vmap f v\n\nmutual\n take : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} →\n (n : ℕ) → FStream C A → FVec C A n\n take ℕ.zero as = FNil\n take (ℕ.suc n) as = FCons (fmap (take' n) (inF as))\n\n take' : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} →\n (n : ℕ) → FStream' C A → A × FVec C A n\n proj₁ (take' n as) = head as\n proj₂ (take' n as) = take n (tail as)\n\ntake'' : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} →\n (n : ℕ) → FStream' C A → FVec' C A n\ntake'' zero as = FNil'\ntake'' (suc n) as = FCons' (head as) (fmap (take'' n) (inF (tail as)))\n\n_pre⟨_▻⋯' : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {m n}\n → FVec' C A m → FVec' C A (suc n) → FStream' {i} C A\nhead (FNil' pre⟨ FCons' a _ ▻⋯') = a\ninF (tail (FNil' pre⟨ FCons' a v ▻⋯')) = fmap (_pre⟨ (FCons' a v) ▻⋯') v\nhead (FCons' x _ pre⟨ v' ▻⋯') = x\ninF (tail (FCons' _ v pre⟨ v' ▻⋯')) = fmap (_pre⟨ v' ▻⋯') v\n\n⟨_▻⋯' : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n : ℕ}\n → FVec' C A (suc n) → FStream' {i} C A\n⟨ v ▻⋯' = FNil' pre⟨ v ▻⋯'\n\nmutual\n _pre⟨_▻⋯ : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {m n}\n → FVec C A m → FVec C A (suc n) → FStream {i} C A\n inF (FCons x pre⟨ keep ▻⋯) = fmap (_aux keep) x\n inF (FNil pre⟨ FCons x ▻⋯) = fmap (_aux (FCons x)) x\n _aux_ : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n m : ℕ}\n → A × FVec C A m → FVec C A (suc n) → FStream' {i} C A\n head ((a , _ ) aux v) = a\n tail ((_ , v') aux v) = v' pre⟨ v ▻⋯\n\n⟨_▻⋯ : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁} {A : Set ℓ₂} {n : ℕ}\n → FVec C A (suc n) → FStream {i} C A\n⟨ as ▻⋯ = FNil pre⟨ as ▻⋯\n\ndata _[_]=_ {a} {A : Set a} {ℓ} {C : Container ℓ} : {n : ℕ} → FVec C A n → Fin n → ⟦ C ⟧ A → Set (a ⊔ ℓ) where\n here : ∀ {n} {x : ⟦ C ⟧ A} {xs : FVec C A n} → (x ▻ xs) [ zero ]= x\n there : ∀ {n} {k} {x y} {xs : FVec C A n} → xs [ k ]= x → (y ▻ xs) [ suc k ]= x\n", "meta": {"hexsha": "dcae8076b53e4a0e661b2b045820e1a4c09c0624", "size": 3509, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "FStream/FVec.agda", "max_stars_repo_name": "Aerate/condatis", "max_stars_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-13T16:52:28.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-13T16:52:28.000Z", "max_issues_repo_path": "FStream/FVec.agda", "max_issues_repo_name": "zimbatm/condatis", "max_issues_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-06-03T20:02:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-01T16:52:07.000Z", "max_forks_repo_path": "FStream/FVec.agda", "max_forks_repo_name": "zimbatm/condatis", "max_forks_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-13T15:56:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-13T15:56:38.000Z", "avg_line_length": 35.4444444444, "max_line_length": 110, "alphanum_fraction": 0.4762040467, "num_tokens": 1819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548782017745, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.3835758080456301}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nmodule Definition.Typed.Consequences.Inversion where\n\nopen import Definition.Untyped\nopen import Definition.Typed\nopen import Definition.Typed.Properties\n\nopen import Definition.Typed.Consequences.Syntactic\nopen import Definition.Typed.Consequences.Substitution\nopen import Definition.Typed.Consequences.Inequality\n\nopen import Tools.Product\nopen import Tools.Empty using (⊥; ⊥-elim)\n\n\n-- Inversion of U (it has no type).\ninversion-U : ∀ {Γ C} → Γ ⊢ U ∷ C → ⊥\ninversion-U (conv x x₁) = inversion-U x\n\n-- Inversion of natural number type.\ninversion-ℕ : ∀ {Γ C} → Γ ⊢ ℕ ∷ C → Γ ⊢ C ≡ U\ninversion-ℕ (ℕⱼ x) = refl (Uⱼ x)\ninversion-ℕ (conv x x₁) = trans (sym x₁) (inversion-ℕ x)\n\n-- Inversion of Empty.\ninversion-Empty : ∀ {Γ C} → Γ ⊢ Empty ∷ C → Γ ⊢ C ≡ U\ninversion-Empty (Emptyⱼ x) = refl (Uⱼ x)\ninversion-Empty (conv x x₁) = trans (sym x₁) (inversion-Empty x)\n\n-- Inversion of Unit.\ninversion-Unit : ∀ {Γ C} → Γ ⊢ Unit ∷ C → Γ ⊢ C ≡ U\ninversion-Unit (Unitⱼ x) = refl (Uⱼ x)\ninversion-Unit (conv x x₁) = trans (sym x₁) (inversion-Unit x)\n\n-- Inversion of Π-types.\ninversion-Π : ∀ {F G Γ C}\n → Γ ⊢ Π F ▹ G ∷ C → Γ ⊢ F ∷ U × Γ ∙ F ⊢ G ∷ U × Γ ⊢ C ≡ U\ninversion-Π (Πⱼ x ▹ x₁) = x , x₁ , refl (Uⱼ (wfTerm x))\ninversion-Π (conv x x₁) = let a , b , c = inversion-Π x\n in a , b , trans (sym x₁) c\n\ninversion-Σ : ∀ {F G Γ C}\n → Γ ⊢ Σ F ▹ G ∷ C → Γ ⊢ F ∷ U × Γ ∙ F ⊢ G ∷ U × Γ ⊢ C ≡ U\ninversion-Σ (Σⱼ x ▹ x₁) = x , x₁ , refl (Uⱼ (wfTerm x))\ninversion-Σ (conv x x₁) = let a , b , c = inversion-Σ x\n in a , b , trans (sym x₁) c\n\n-- Inversion of zero.\ninversion-zero : ∀ {Γ C} → Γ ⊢ zero ∷ C → Γ ⊢ C ≡ ℕ\ninversion-zero (zeroⱼ x) = refl (ℕⱼ x)\ninversion-zero (conv x x₁) = trans (sym x₁) (inversion-zero x)\n\n-- Inversion of successor.\ninversion-suc : ∀ {Γ t C} → Γ ⊢ suc t ∷ C → Γ ⊢ t ∷ ℕ × Γ ⊢ C ≡ ℕ\ninversion-suc (sucⱼ x) = x , refl (ℕⱼ (wfTerm x))\ninversion-suc (conv x x₁) =\n let a , b = inversion-suc x\n in a , trans (sym x₁) b\n\n-- Inversion of natural recursion.\ninversion-natrec : ∀ {Γ c g n A C} → Γ ⊢ natrec C c g n ∷ A\n → (Γ ∙ ℕ ⊢ C)\n × Γ ⊢ c ∷ C [ zero ]\n × Γ ⊢ g ∷ Π ℕ ▹ (C ▹▹ C [ suc (var 0) ]↑)\n × Γ ⊢ n ∷ ℕ\n × Γ ⊢ A ≡ C [ n ]\ninversion-natrec (natrecⱼ x d d₁ n) = x , d , d₁ , n , refl (substType x n)\ninversion-natrec (conv d x) = let a , b , c , d , e = inversion-natrec d\n in a , b , c , d , trans (sym x) e\n\n-- Inversion of application.\ninversion-app : ∀ {Γ f a A} → Γ ⊢ (f ∘ a) ∷ A →\n ∃₂ λ F G → Γ ⊢ f ∷ Π F ▹ G × Γ ⊢ a ∷ F × Γ ⊢ A ≡ G [ a ]\ninversion-app (d ∘ⱼ d₁) = _ , _ , d , d₁ , refl (substTypeΠ (syntacticTerm d) d₁)\ninversion-app (conv d x) = let a , b , c , d , e = inversion-app d\n in a , b , c , d , trans (sym x) e\n\n-- Inversion of lambda.\ninversion-lam : ∀ {t A Γ} → Γ ⊢ lam t ∷ A →\n ∃₂ λ F G → Γ ⊢ F × (Γ ∙ F ⊢ t ∷ G × Γ ⊢ A ≡ Π F ▹ G)\ninversion-lam (lamⱼ x x₁) = _ , _ , x , x₁ , refl (Πⱼ x ▹ (syntacticTerm x₁))\ninversion-lam (conv x x₁) = let a , b , c , d , e = inversion-lam x\n in a , b , c , d , trans (sym x₁) e\n\n-- Inversion of products.\ninversion-prod : ∀ {t u A Γ} → Γ ⊢ prod t u ∷ A →\n ∃₂ λ F G → Γ ⊢ F × (Γ ∙ F ⊢ G × (Γ ⊢ t ∷ F × Γ ⊢ u ∷ G [ t ] × Γ ⊢ A ≡ Σ F ▹ G))\ninversion-prod (prodⱼ ⊢F ⊢G ⊢t ⊢u) =\n -- NOTE fundamental theorem not required since prodⱼ has inversion built-in.\n _ , _ , ⊢F , ⊢G , ⊢t , ⊢u , refl (Σⱼ ⊢F ▹ ⊢G )\ninversion-prod (conv x x₁) =\n let F , G , a , b , c , d , e = inversion-prod x\n in F , G , a , b , c , d , trans (sym x₁) e\n\n-- Inversion of star.\ninversion-star : ∀ {Γ C} → Γ ⊢ star ∷ C → Γ ⊢ C ≡ Unit\ninversion-star (starⱼ x) = refl (Unitⱼ x)\ninversion-star (conv x x₁) = trans (sym x₁) (inversion-star x)\n\n-- Inversion of products in WHNF.\nwhnfProduct : ∀ {Γ p F G} → Γ ⊢ p ∷ Σ F ▹ G → Whnf p → Product p\nwhnfProduct x prodₙ = prodₙ\nwhnfProduct x (ne pNe) = ne pNe\n\nwhnfProduct x Uₙ = ⊥-elim (inversion-U x)\nwhnfProduct x Πₙ =\n let _ , _ , Σ≡U = inversion-Π x\n in ⊥-elim (U≢Σ (sym Σ≡U))\nwhnfProduct x Σₙ =\n let _ , _ , Σ≡U = inversion-Σ x\n in ⊥-elim (U≢Σ (sym Σ≡U))\nwhnfProduct x ℕₙ = ⊥-elim (U≢Σ (sym (inversion-ℕ x)))\nwhnfProduct x Unitₙ = ⊥-elim (U≢Σ (sym (inversion-Unit x)))\nwhnfProduct x Emptyₙ = ⊥-elim (U≢Σ (sym (inversion-Empty x)))\nwhnfProduct x lamₙ =\n let _ , _ , _ , _ , Σ≡Π = inversion-lam x\n in ⊥-elim (Π≢Σ (sym Σ≡Π))\nwhnfProduct x zeroₙ = ⊥-elim (ℕ≢Σ (sym (inversion-zero x)))\nwhnfProduct x sucₙ =\n let _ , A≡ℕ = inversion-suc x\n in ⊥-elim (ℕ≢Σ (sym A≡ℕ))\nwhnfProduct x starₙ = ⊥-elim (Unit≢Σⱼ (sym (inversion-star x)))\n", "meta": {"hexsha": "b89bb48ec96ee96911485d84a130c4a8d5905763", "size": 4620, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Typed/Consequences/Inversion.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/Typed/Consequences/Inversion.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/Typed/Consequences/Inversion.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": 37.2580645161, "max_line_length": 82, "alphanum_fraction": 0.5612554113, "num_tokens": 2030, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5888891307678319, "lm_q2_score": 0.6513548646660543, "lm_q1q2_score": 0.3835758000745915}} {"text": "open import Relation.Binary.Core using (Decidable ; _≡_)\n\nmodule Precond (Carrier : Set) (deq : Decidable {A = Carrier} _≡_) where\n\nopen import Data.Nat using (ℕ)\nopen import Data.Fin using (Fin ; zero ; suc)\nopen import Data.Fin.Properties using (_≟_)\nopen import Data.List using (List ; [] ; _∷_)\nopen import Level using () renaming (zero to ℓ₀)\nimport Category.Monad\nimport Category.Functor\nopen import Data.Maybe using (Maybe ; nothing ; just ; maybe′)\nopen Category.Monad.RawMonad {Level.zero} Data.Maybe.monad using (_>>=_)\nopen Category.Functor.RawFunctor {Level.zero} Data.Maybe.functor using (_<$>_)\nopen import Data.Vec using (Vec ; [] ; _∷_ ; map ; lookup ; toList)\nopen import Data.Vec.Properties using (map-cong ; map-∘ ; tabulate-∘)\nimport Data.List.All\nopen import Data.List.Any using (here ; there)\nopen Data.List.Any.Membership-≡ using (_∉_)\nopen import Data.Maybe using (just)\nopen import Data.Product using (∃ ; _,_ ; proj₁ ; proj₂)\nopen import Function using (flip ; _∘_ ; id)\nopen import Relation.Binary using (Setoid)\nopen import Relation.Binary.PropositionalEquality using (refl ; cong ; inspect ; [_] ; sym ; decSetoid)\nopen Relation.Binary.PropositionalEquality.≡-Reasoning using (begin_ ; _≡⟨_⟩_ ; _∎)\nopen import Relation.Nullary using (yes ; no)\n\nopen import Structures using (IsFunctor ; module Shaped ; Shaped)\nopen import FinMap using (FinMapMaybe ; lookupM ; union ; fromFunc ; empty ; insert ; lemma-lookupM-empty ; delete-many ; lemma-tabulate-∘ ; delete ; lemma-lookupM-delete ; lemma-lookupM-fromFunc ; reshape ; lemma-reshape-id)\nimport CheckInsert\nopen CheckInsert (decSetoid deq) using (checkInsert ; lemma-checkInsert-new ; lemma-lookupM-checkInsert-other)\nimport BFF\nimport Bidir\nopen Bidir (decSetoid deq) using (_in-domain-of_ ; lemma-assoc-domain)\nimport GetTypes\nopen GetTypes.PartialShapeShape using (Get ; module Get)\nopen BFF.PartialShapeBFF (decSetoid deq) using (assoc ; enumerate ; denumerate ; bff)\n\nlemma-maybe-just : {A : Set} → (a : A) → (ma : Maybe A) → maybe′ Maybe.just (just a) ma ≡ Maybe.just (maybe′ id a ma)\nlemma-maybe-just a (just x) = refl\nlemma-maybe-just a nothing = refl\n\nlemma-union-delete-fromFunc : {m n : ℕ} {A : Set} {is : Vec (Fin n) m} {h : FinMapMaybe n A} {g : Fin n → A} → is in-domain-of h → ∃ λ v → union h (delete-many is (fromFunc g)) ≡ fromFunc v\nlemma-union-delete-fromFunc {is = []} {h = h} {g = g} p = _ , (lemma-tabulate-∘ (λ f → begin\n maybe′ just (lookupM f (fromFunc g)) (lookupM f h)\n ≡⟨ cong (flip (maybe′ just) (lookupM f h)) (lemma-lookupM-fromFunc g f) ⟩\n maybe′ just (just (g f)) (lookupM f h)\n ≡⟨ lemma-maybe-just (g f) (lookupM f h) ⟩\n just (maybe′ id (g f) (lookupM f h)) ∎))\nlemma-union-delete-fromFunc {n = n} {is = i ∷ is} {h = h} {g = g} (Data.List.All._∷_ (x , px) ps) = _ , (begin\n union h (delete i (delete-many is (fromFunc g)))\n ≡⟨ lemma-tabulate-∘ inner ⟩\n union h (delete-many is (fromFunc g))\n ≡⟨ proj₂ (lemma-union-delete-fromFunc ps) ⟩\n _ ∎)\n where inner : (f : Fin n) → maybe′ just (lookupM f (delete i (delete-many is (fromFunc g)))) (lookup f h) ≡ maybe′ just (lookupM f (delete-many is (fromFunc g))) (lookup f h)\n inner f with f ≟ i\n inner .i | yes refl = begin\n maybe′ just (lookupM i (delete i (delete-many is (fromFunc g)))) (lookup i h)\n ≡⟨ cong (maybe′ just _) px ⟩\n just x\n ≡⟨ cong (maybe′ just _) (sym px) ⟩\n maybe′ just (lookupM i (delete-many is (fromFunc g))) (lookup i h) ∎\n inner f | no f≢i = cong (flip (maybe′ just) (lookup f h)) (lemma-lookupM-delete (delete-many is (fromFunc g)) f≢i)\n\nmodule _ (G : Get) where\n open Get G\n open Shaped ViewShapeT using () renaming (content to contentV)\n\n assoc-enough : {i : I} → (j : I) → (s : SourceContainer Carrier (gl₁ i)) → (v : ViewContainer Carrier (gl₂ j)) → ∃ (λ h → assoc (contentV (get (enumerate SourceShapeT (gl₁ j)))) (contentV v) ≡ just h) → ∃ λ u → bff G j s v ≡ just u\n assoc-enough {i} j s v (h , p) = _ , cong (_<$>_ ((λ f → fmapS f t) ∘ flip lookupM) ∘ _<$>_ (flip union (reshape g′ (Shaped.arity SourceShapeT (gl₁ j))))) p\n where g′ = delete-many (contentV (get (enumerate SourceShapeT (gl₁ i)))) (fromFunc (denumerate SourceShapeT s))\n t = enumerate SourceShapeT (gl₁ j)\n\nmodule _ (G : Get) where\n open Get G\n open Shaped ViewShapeT using () renaming (content to contentV)\n\n assoc-enough′ : {i : I} → (s : SourceContainer Carrier (gl₁ i)) → (v : ViewContainer Carrier (gl₂ i)) → ∃ (λ h → assoc (contentV (get (enumerate SourceShapeT (gl₁ i)))) (contentV v) ≡ just h) → ∃ λ u → bff G i s v ≡ just (fmapS just u)\n assoc-enough′ {i} s v (h , p) = _ , (begin\n bff G i s v\n ≡⟨ proj₂ (assoc-enough G i s v (h , p)) ⟩\n just (fmapS (flip lookupM (union h (reshape g′ (Shaped.arity SourceShapeT (gl₁ i))))) t)\n ≡⟨ cong just (begin _\n ≡⟨ cong ((λ f → fmapS f t) ∘ flip lookupM ∘ union h) (lemma-reshape-id g′) ⟩\n fmapS (flip lookupM (union h g′)) t\n ≡⟨ cong ((λ f → fmapS f t) ∘ flip lookupM) (proj₂ wp) ⟩\n fmapS (flip lookupM (fromFunc (proj₁ wp))) t\n ≡⟨ IsFunctor.cong (Shaped.isFunctor SourceShapeT (gl₁ i)) (lemma-lookupM-fromFunc (proj₁ wp)) t ⟩\n fmapS (Maybe.just ∘ proj₁ wp) t\n ≡⟨ IsFunctor.composition (Shaped.isFunctor SourceShapeT (gl₁ i)) just (proj₁ wp) t ⟩\n fmapS Maybe.just (fmapS (proj₁ wp) t) ∎) ⟩ _ ∎)\n where s′ = enumerate SourceShapeT (gl₁ i)\n g = fromFunc (denumerate SourceShapeT s)\n g′ = delete-many (contentV (get s′)) g\n t = enumerate SourceShapeT (gl₁ i)\n wp = lemma-union-delete-fromFunc (lemma-assoc-domain (contentV (get t)) (contentV v) p)\n\ndata All-different {A : Set} : List A → Set where\n different-[] : All-different []\n different-∷ : {x : A} {xs : List A} → x ∉ xs → All-different xs → All-different (x ∷ xs)\n\nlemma-∉-lookupM-assoc : {m n : ℕ} → (i : Fin n) → (is : Vec (Fin n) m) → (xs : Vec Carrier m) → {h : FinMapMaybe n Carrier} → assoc is xs ≡ just h → (i ∉ toList is) → lookupM i h ≡ nothing\nlemma-∉-lookupM-assoc i [] [] refl i∉is = lemma-lookupM-empty i\nlemma-∉-lookupM-assoc i (i' ∷ is') (x' ∷ xs') ph i∉is with assoc is' xs' | inspect (assoc is') xs'\nlemma-∉-lookupM-assoc i (i' ∷ is') (x' ∷ xs') () i∉is | nothing | [ ph' ]\nlemma-∉-lookupM-assoc i (i' ∷ is') (x' ∷ xs') {h} ph i∉is | just h' | [ ph' ] = begin\n lookupM i h\n ≡⟨ lemma-lookupM-checkInsert-other i i' (i∉is ∘ here) x' h' ph ⟩\n lookupM i h'\n ≡⟨ lemma-∉-lookupM-assoc i is' xs' ph' (i∉is ∘ there) ⟩\n nothing ∎\n\ndifferent-assoc : {m n : ℕ} → (u : Vec (Fin n) m) → (v : Vec Carrier m) → All-different (toList u) → ∃ λ h → assoc u v ≡ just h\ndifferent-assoc [] [] p = empty , refl\ndifferent-assoc (u ∷ us) (v ∷ vs) (different-∷ u∉us diff-us) with different-assoc us vs diff-us\ndifferent-assoc (u ∷ us) (v ∷ vs) (different-∷ u∉us diff-us) | h , p' = insert u v h , (begin\n assoc (u ∷ us) (v ∷ vs)\n ≡⟨ refl ⟩\n (assoc us vs >>= checkInsert u v)\n ≡⟨ cong (flip _>>=_ (checkInsert u v)) p' ⟩\n checkInsert u v h\n ≡⟨ lemma-checkInsert-new u v h (lemma-∉-lookupM-assoc u us vs p' u∉us) ⟩\n just (insert u v h) ∎)\n", "meta": {"hexsha": "70f294d3b9058f901ff217cfc4757e9bcaedfd82", "size": 7193, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Precond.agda", "max_stars_repo_name": "jvoigtlaender/bidiragda", "max_stars_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0", "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": "Precond.agda", "max_issues_repo_name": "jvoigtlaender/bidiragda", "max_issues_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0", "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": "Precond.agda", "max_forks_repo_name": "jvoigtlaender/bidiragda", "max_forks_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0", "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": 57.544, "max_line_length": 237, "alphanum_fraction": 0.627832615, "num_tokens": 2519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7431680199891789, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.3831922318348608}} {"text": "import Relation.Binary.Reasoning.Setoid as SetoidR\nopen import MultiSorted.AlgebraicTheory\n\nimport MultiSorted.Interpretation as Interpretation\nimport MultiSorted.Model as Model\nimport MultiSorted.UniversalInterpretation as UniversalInterpretation\nimport MultiSorted.Substitution as Substitution\nimport MultiSorted.SyntacticCategory as SyntacticCategory\n\nmodule MultiSorted.UniversalModel\n {ℓt}\n {𝓈 ℴ}\n {Σ : Signature {𝓈} {ℴ}}\n (T : Theory ℓt Σ) where\n\n open Theory T\n open Substitution T\n open UniversalInterpretation T\n open Interpretation.Interpretation ℐ\n open SyntacticCategory T\n\n 𝒰 : Model.Is-Model T ℐ\n 𝒰 =\n record\n { model-eq = λ ε var-var →\n let open SetoidR (eq-setoid (ax-ctx ε) (sort-of (ctx-slot (ax-sort ε)) var-var)) in\n begin\n interp-term (ax-lhs ε) var-var ≈⟨ interp-term-self (ax-lhs ε) var-var ⟩\n ax-lhs ε ≈⟨ id-action ⟩\n ax-lhs ε [ id-s ]s ≈⟨ eq-axiom ε id-s ⟩\n ax-rhs ε [ id-s ]s ≈˘⟨ id-action ⟩\n ax-rhs ε ≈˘⟨ interp-term-self (ax-rhs ε) var-var ⟩\n interp-term (ax-rhs ε) var-var ∎\n }\n\n\n -- The universal model is universal\n universality : ∀ (ε : Equation Σ) → ⊨ ε → ⊢ ε\n universality ε p =\n let open Equation in\n let open SetoidR (eq-setoid (eq-ctx ε) (eq-sort ε)) in\n (begin\n eq-lhs ε ≈˘⟨ interp-term-self (eq-lhs ε) var-var ⟩\n interp-term (eq-lhs ε) var-var ≈⟨ p var-var ⟩\n interp-term (eq-rhs ε) var-var ≈⟨ interp-term-self (eq-rhs ε) var-var ⟩\n eq-rhs ε ∎)\n", "meta": {"hexsha": "dc43761bd416e78413502225df9f20bd79763eb0", "size": 1645, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/MultiSorted/UniversalModel.agda", "max_stars_repo_name": "cilinder/formaltt", "max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z", "max_issues_repo_path": "src/MultiSorted/UniversalModel.agda", "max_issues_repo_name": "andrejbauer/formaltt", "max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z", "max_forks_repo_path": "src/MultiSorted/UniversalModel.agda", "max_forks_repo_name": "andrejbauer/formaltt", "max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z", "avg_line_length": 35.0, "max_line_length": 106, "alphanum_fraction": 0.5975683891, "num_tokens": 510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7431679972357831, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.3831922201027567}} {"text": "open import Relation.Binary.Core\n\nmodule PLRTree.DropLast.Permutation {A : Set} \n (_≤_ : A → A → Set)\n (tot≤ : Total _≤_) where\n\nopen import Data.List \nopen import Data.Sum\nopen import List.Permutation.Base A \nopen import List.Permutation.Base.Concatenation A \nopen import List.Permutation.Base.Equivalence A \nopen import PLRTree {A} \nopen import PLRTree.Complete {A} \nopen import PLRTree.Compound {A} \nopen import PLRTree.Drop _≤_ tot≤\nopen import PLRTree.DropLast.Complete _≤_ tot≤\nopen import PLRTree.Equality {A} \n\nlemma-last-dropLast : {t : Tag}{x : A}{l r : PLRTree} → Complete (node t x l r) → (last (node t x l r) compound ∷ flatten (dropLast (node t x l r))) ∼ flatten (node t x l r) \nlemma-last-dropLast (perfect {l} {r} x cl cr l≃r) \n with l | r | l≃r\n... | leaf | leaf | ≃lf = ∼x /head /head ∼[]\n... | node perfect x' l' r' | node perfect x'' l'' r'' | ≃nd .x' .x'' l'≃r' l''≃r'' l'≃l'' = \n let _l = node perfect x' l' r' ;\n _r = node perfect x'' l'' r'' ;\n zxflfrd∼xflzfrd = ∼x /head (lemma++/ {last _r compound} {x ∷ flatten _l}) refl∼ ;\n xflzfrd∼xflfr = lemma++∼l {x ∷ flatten _l} (lemma-last-dropLast cr)\n in trans∼ zxflfrd∼xflzfrd xflzfrd∼xflfr\nlemma-last-dropLast (left {l} {r} x cl cr l⋘r)\n with l | r | l⋘r | lemma-dropLast-⋘ l⋘r\n... | leaf | _ | () | _ \n... | node perfect x' l' r' | _ | () | _ \n... | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₁ ld⋘r \n with dropLast (node left x' l' r') | ld⋘r | lemma-last-dropLast cl\n... | leaf | () | _\n... | node perfect _ _ _ | () | _\n... | node left x''' l''' r''' | ld⋘r' | zfldfr∼flfr = ∼x (/tail /head) /head (lemma++∼r zfldfr∼flfr)\n... | node right x''' l''' r''' | ld⋘r' | zfldfr∼flfr = ∼x (/tail /head) /head (lemma++∼r zfldfr∼flfr)\nlemma-last-dropLast (left x cl cr l⋘r) | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₂ ld≃r \n with dropLast (node left x' l' r') | ld≃r | lemma-last-dropLast cl\n... | leaf | () | _\n... | node perfect x''' l''' r''' | ld≃r' | zfldfr∼flfr = ∼x (/tail /head) /head (lemma++∼r zfldfr∼flfr)\n... | node left _ _ _ | () | _\n... | node right _ _ _ | () | _\nlemma-last-dropLast (left x cl cr l⋘r) | node right x' l' r' | leaf | () | _ \nlemma-last-dropLast (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₁ () \nlemma-last-dropLast (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₂ x'≃x''' = \n ∼x (/tail /head) /head (lemma++∼r (lemma-last-dropLast cl))\nlemma-last-dropLast (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₁ ld⋘r \n with dropLast (node right x' l' r') | ld⋘r | lemma-last-dropLast cl\n... | leaf | () | _\n... | node perfect _ _ _ | () | _\n... | node left x''' l''' r''' | ld⋘r' | zfldfr∼flfr = ∼x (/tail /head) /head (lemma++∼r zfldfr∼flfr)\n... | node right x''' l''' r''' | ld⋘r' | zfldfr∼flfr = ∼x (/tail /head) /head (lemma++∼r zfldfr∼flfr)\nlemma-last-dropLast (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₂ ld≃r \n with dropLast (node right x' l' r') | ld≃r | lemma-last-dropLast cl\n... | leaf | () | _\n... | node perfect x''' l''' r''' | ld≃r' | zfldfr∼flfr = ∼x (/tail /head) /head (lemma++∼r zfldfr∼flfr)\n... | node left _ _ _ | () | _\n... | node right _ _ _ | () | _ \nlemma-last-dropLast (left x cl cr l⋘r) | node right x' l' r' | node left x'' l'' r'' | () | _ \nlemma-last-dropLast (left x cl cr l⋘r) | node right x' l' r' | node right x'' l'' r'' | () | _\nlemma-last-dropLast (right {l} {r} x cl cr l⋙r) \n with l | r | l⋙r\n... | leaf | _ | ⋙p ()\n... | node perfect x' leaf leaf | leaf | ⋙p (⋗lf .x') = ∼x (/tail /head) /head (∼x /head /head ∼[])\n... | node perfect x' leaf leaf | node left _ _ _ | ⋙p ()\n... | node perfect x' leaf leaf | node right _ _ _ | ⋙p ()\n... | node perfect x' l' r' | node perfect x'' l'' r'' | ⋙p (⋗nd .x' .x'' l'≃r' l''≃r'' l'⋗l'') = \n ∼x (/tail /head) /head (lemma++∼r (lemma-last-dropLast cl))\n... | node perfect x' l' r' | node left x'' l'' r'' | ⋙l .x' .x'' l'≃r' l''⋘r'' l'⋗r'' \n with lemma-dropLast-⋙ (⋙l x' x'' l'≃r' l''⋘r'' l'⋗r'')\n... | inj₁ l⋙rd = \n let _l = node perfect x' l' r' ;\n _r = node left x'' l'' r'' ;\n zxflfrd∼xflzfrd = ∼x /head (lemma++/ {last _r compound} {x ∷ flatten _l}) refl∼ ;\n xflzfrd∼xflfr = lemma++∼l {x ∷ flatten _l} (lemma-last-dropLast cr)\n in trans∼ zxflfrd∼xflzfrd xflzfrd∼xflfr\n... | inj₂ ()\nlemma-last-dropLast (right x cl cr l⋙r) | node perfect x' l' r' | node right x'' l'' r'' | ⋙r .x' .x'' l'≃r' l''⋙r'' l'≃l'' \n with lemma-dropLast-⋙ (⋙r x' x'' l'≃r' l''⋙r'' l'≃l'')\n... | inj₁ l⋙rd = \n let _l = node perfect x' l' r' ;\n _r = node right x'' l'' r'' ;\n zxflfrd∼xflzfrd = ∼x /head (lemma++/ {last _r compound} {x ∷ flatten _l}) refl∼ ;\n xflzfrd∼xflfr = lemma++∼l {x ∷ flatten _l} (lemma-last-dropLast cr)\n in trans∼ zxflfrd∼xflzfrd xflzfrd∼xflfr\n... | inj₂ ()\nlemma-last-dropLast (right x cl cr l⋙r) | node left _ _ _ | _ | ⋙p ()\nlemma-last-dropLast (right x cl cr l⋙r) | node right _ _ _ | _ | ⋙p ()\n\nlemma-dropLast-∼ : {t : Tag}{x : A}{l r : PLRTree} → Complete (node t x l r) → flatten (setRoot (last (node t x l r) compound) (dropLast (node t x l r))) ∼ (flatten l ++ flatten r)\nlemma-dropLast-∼ (perfect {l} {r} x cl cr l≃r) \n with l | r | l≃r\n... | leaf | leaf | ≃lf = ∼[]\n... | node perfect x' l' r' | node perfect x'' l'' r'' | ≃nd .x' .x'' l'≃r' l''≃r'' l'≃l'' = \n let _l = node perfect x' l' r' ;\n _r = node perfect x'' l'' r'' ;\n zflfrd∼flzfrd = ∼x /head (lemma++/ {last _r compound} {flatten _l}) refl∼ ;\n flzfrd∼flfr = lemma++∼l {flatten _l} (lemma-last-dropLast cr)\n in trans∼ zflfrd∼flzfrd flzfrd∼flfr\nlemma-dropLast-∼ (left {l} {r} x cl cr l⋘r)\n with l | r | l⋘r | lemma-dropLast-⋘ l⋘r\n... | leaf | _ | () | _ \n... | node perfect x' l' r' | _ | () | _ \n... | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₁ ld⋘r \n with dropLast (node left x' l' r') | ld⋘r | lemma-last-dropLast cl\n... | leaf | () | _\n... | node perfect _ _ _ | () | _\n... | node left x''' l''' r''' | ld⋘r' | zfld∼fl = lemma++∼r zfld∼fl\n... | node right x''' l''' r''' | ld⋘r' | zfld∼fl = lemma++∼r zfld∼fl\nlemma-dropLast-∼ (left x cl cr l⋘r) | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₂ ld≃r \n with dropLast (node left x' l' r') | ld≃r | lemma-last-dropLast cl\n... | leaf | () | _\n... | node perfect x''' l''' r''' | ld≃r' | zfld∼fl = lemma++∼r zfld∼fl \n... | node left _ _ _ | () | _\n... | node right _ _ _ | () | _\nlemma-dropLast-∼ (left x cl cr l⋘r) | node right x' l' r' | leaf | () | _ \nlemma-dropLast-∼ (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₁ () \nlemma-dropLast-∼ (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₂ x'≃x''' = \n lemma++∼r (lemma-last-dropLast cl)\nlemma-dropLast-∼ (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₁ ld⋘r \n with dropLast (node right x' l' r') | ld⋘r | lemma-last-dropLast cl\n... | leaf | () | _\n... | node perfect _ _ _ | () | _\n... | node left x''' l''' r''' | ld⋘r' | zfld∼fl = lemma++∼r zfld∼fl\n... | node right x''' l''' r''' | ld⋘r' | zfld∼fl = lemma++∼r zfld∼fl\nlemma-dropLast-∼ (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₂ ld≃r \n with dropLast (node right x' l' r') | ld≃r | lemma-last-dropLast cl\n... | leaf | () | _\n... | node perfect x''' l''' r''' | ld≃r' | zfld∼fl = lemma++∼r zfld∼fl \n... | node left _ _ _ | () | _\n... | node right _ _ _ | () | _ \nlemma-dropLast-∼ (left x cl cr l⋘r) | node right x' l' r' | node left x'' l'' r'' | () | _ \nlemma-dropLast-∼ (left x cl cr l⋘r) | node right x' l' r' | node right x'' l'' r'' | () | _\nlemma-dropLast-∼ (right {l} {r} x cl cr l⋙r) \n with l | r | l⋙r\n... | leaf | _ | ⋙p ()\n... | node perfect x' leaf leaf | leaf | ⋙p (⋗lf .x') = ∼x /head /head ∼[]\n... | node perfect x' leaf leaf | node left _ _ _ | ⋙p ()\n... | node perfect x' leaf leaf | node right _ _ _ | ⋙p ()\n... | node perfect x' l' r' | node perfect x'' l'' r'' | ⋙p (⋗nd .x' .x'' l'≃r' l''≃r'' l'⋗l'') = lemma++∼r (lemma-last-dropLast cl)\n... | node perfect x' l' r' | node left x'' l'' r'' | ⋙l .x' .x'' l'≃r' l''⋘r'' l'⋗r'' \n with lemma-dropLast-⋙ (⋙l x' x'' l'≃r' l''⋘r'' l'⋗r'')\n... | inj₁ l⋙rd = \n let _l = node perfect x' l' r' ;\n _r = node left x'' l'' r'' ;\n zflfrd∼flzfrd = ∼x /head (lemma++/ {last _r compound} {flatten _l}) refl∼ ;\n flzfrd∼flfr = lemma++∼l {flatten _l} (lemma-last-dropLast cr)\n in trans∼ zflfrd∼flzfrd flzfrd∼flfr\n... | inj₂ ()\nlemma-dropLast-∼ (right x cl cr l⋙r) | node perfect x' l' r' | node right x'' l'' r'' | ⋙r .x' .x'' l'≃r' l''⋙r'' l'≃l'' \n with lemma-dropLast-⋙ (⋙r x' x'' l'≃r' l''⋙r'' l'≃l'')\n... | inj₁ l⋙rd =\n let _l = node perfect x' l' r' ;\n _r = node right x'' l'' r'' ;\n zflfrd∼flzfrd = ∼x /head (lemma++/ {last _r compound} {flatten _l}) refl∼ ;\n flzfrd∼flfr = lemma++∼l {flatten _l} (lemma-last-dropLast cr)\n in trans∼ zflfrd∼flzfrd flzfrd∼flfr\n... | inj₂ ()\nlemma-dropLast-∼ (right x cl cr l⋙r) | node left _ _ _ | _ | ⋙p ()\nlemma-dropLast-∼ (right x cl cr l⋙r) | node right _ _ _ | _ | ⋙p ()\n\n", "meta": {"hexsha": "a339219419480ee7bd0f7918e725d2d82f373a52", "size": 10107, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda/PLRTree/DropLast/Permutation.agda", "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_issues_repo_path": "agda/PLRTree/DropLast/Permutation.agda", "max_issues_repo_name": "bgbianchi/sorting", "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "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/PLRTree/DropLast/Permutation.agda", "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "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": 61.6280487805, "max_line_length": 180, "alphanum_fraction": 0.5078658356, "num_tokens": 4264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431679972357831, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.3831922201027567}} {"text": "------------------------------------------------------------------------\n-- Partiality algebras\n------------------------------------------------------------------------\n\n{-# OPTIONS --erased-cubical --safe #-}\n\nmodule Partiality-algebra where\n\nopen import Equality.Propositional.Cubical\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude hiding (id; T) renaming (_∘_ to _⊚_)\n\nopen import Bijection equality-with-J as Bijection using (_↔_)\nopen import Equivalence equality-with-J as Eq using (_≃_)\nopen import Function-universe equality-with-J as F hiding (id; _∘_)\nopen import H-level equality-with-J as H-level\nopen import H-level.Closure equality-with-J\nopen import Univalence-axiom equality-with-J\n\n------------------------------------------------------------------------\n-- Partiality algebras\n\n-- Partiality algebras for certain universe levels and types, with a\n-- certain underlying type (T).\n\nrecord Partiality-algebra-with\n {a p} (T : Type p) q (A : Type a) : Type (a ⊔ p ⊔ lsuc q) where\n\n -- A binary relation on the type.\n\n infix 4 _⊑_ _⊒_\n\n field\n _⊑_ : T → T → Type q\n\n _⊒_ : T → T → Type q\n _⊒_ x y = y ⊑ x\n\n -- Increasing sequences.\n\n Increasing-sequence : Type (p ⊔ q)\n Increasing-sequence = ∃ λ (f : ℕ → T) → ∀ n → f n ⊑ f (suc n)\n\n -- Projection functions for Increasing-sequence.\n\n infix 30 _[_]\n\n _[_] : Increasing-sequence → ℕ → T\n _[_] s n = proj₁ s n\n\n increasing : (s : Increasing-sequence) →\n ∀ n → (s [ n ]) ⊑ (s [ suc n ])\n increasing = proj₂\n\n -- Upper bounds.\n\n Is-upper-bound : Increasing-sequence → T → Type q\n Is-upper-bound s x = ∀ n → (s [ n ]) ⊑ x\n\n field\n -- T \"constructors\".\n\n never : T\n now : A → T\n ⨆ : Increasing-sequence → T\n antisymmetry : ∀ {x y} → x ⊑ y → y ⊑ x → x ≡ y\n\n -- We have chosen to explicitly make the type set-truncated.\n -- However, this \"constructor\" is not used anywhere in the\n -- development (except when partiality algebras are modified, see\n -- for instance equality-characterisation-Partiality-algebra-with₁\n -- or Partiality-algebra.Pi.Π-with).\n T-is-set-unused : Is-set T\n\n -- _⊑_ \"constructors\".\n\n ⊑-refl : ∀ x → x ⊑ x\n ⊑-trans : ∀ {x y z} → x ⊑ y → y ⊑ z → x ⊑ z\n never⊑ : ∀ x → never ⊑ x\n upper-bound : ∀ s → Is-upper-bound s (⨆ s)\n least-upper-bound : ∀ s ub → Is-upper-bound s ub → ⨆ s ⊑ ub\n ⊑-propositional : ∀ {x y} → Is-proposition (x ⊑ y)\n\n ----------------------------------------------------------------------\n -- Some simple consequences\n\n private\n\n -- A lemma.\n\n T-is-set-and-equality-characterisation : Is-set T × _\n T-is-set-and-equality-characterisation =\n Eq.propositional-identity≃≡\n (λ x y → x ⊑ y × y ⊑ x)\n (λ _ _ → ×-closure 1 ⊑-propositional ⊑-propositional)\n (λ x → ⊑-refl x , ⊑-refl x)\n (λ x y → uncurry {B = λ _ → y ⊑ x} antisymmetry)\n\n -- T is a set. (This lemma is analogous to Theorem 11.3.9 in\n -- \"Homotopy Type Theory: Univalent Foundations of Mathematics\"\n -- (first edition).)\n\n T-is-set : Is-set T\n T-is-set = proj₁ T-is-set-and-equality-characterisation\n\n -- Equality characterisation lemma for T.\n\n equality-characterisation-T :\n ∀ {x y} → (x ⊑ y × y ⊑ x) ≃ (x ≡ y)\n equality-characterisation-T =\n proj₂ T-is-set-and-equality-characterisation ext\n\n -- Equality characterisation lemma for increasing sequences.\n\n equality-characterisation-increasing :\n ∀ {s₁ s₂} → (∀ n → s₁ [ n ] ≡ s₂ [ n ]) ↔ s₁ ≡ s₂\n equality-characterisation-increasing {s₁} {s₂} =\n (∀ n → s₁ [ n ] ≡ s₂ [ n ]) ↔⟨ Eq.extensionality-isomorphism bad-ext ⟩\n proj₁ s₁ ≡ proj₁ s₂ ↝⟨ ignore-propositional-component\n (Π-closure ext 1 λ _ →\n ⊑-propositional) ⟩□\n s₁ ≡ s₂ □\n\n-- Partiality algebras for certain universe levels and types.\n\nrecord Partiality-algebra {a} p q (A : Type a) :\n Type (a ⊔ lsuc (p ⊔ q)) where\n constructor ⟨_⟩\n field\n -- A type.\n\n {T} : Type p\n\n -- A partiality-algebra with that type as the underlying type.\n\n partiality-algebra-with : Partiality-algebra-with T q A\n\n open Partiality-algebra-with partiality-algebra-with public\n\n------------------------------------------------------------------------\n-- Partiality algebra morphisms\n\n-- Morphisms from one partiality algebra to another.\n\nrecord Morphism {a p₁ p₂ q₁ q₂} {A : Type a}\n (P₁ : Partiality-algebra p₁ q₁ A)\n (P₂ : Partiality-algebra p₂ q₂ A) :\n Type (a ⊔ p₁ ⊔ p₂ ⊔ q₁ ⊔ q₂) where\n\n private\n module P₁ = Partiality-algebra P₁\n module P₂ = Partiality-algebra P₂\n\n field\n function : P₁.T → P₂.T\n monotone : ∀ {x y} → x P₁.⊑ y → function x P₂.⊑ function y\n\n sequence-function : P₁.Increasing-sequence → P₂.Increasing-sequence\n sequence-function = Σ-map (function ⊚_) (monotone ⊚_)\n\n field\n strict : function P₁.never ≡ P₂.never\n now-to-now : ∀ x → function (P₁.now x) ≡ P₂.now x\n ω-continuous : ∀ s → function (P₁.⨆ s) ≡ P₂.⨆ (sequence-function s)\n\n-- An identity morphism.\n\nid :\n ∀ {a p q} {A : Type a} {P : Partiality-algebra p q A} →\n Morphism P P\nid = record\n { function = Prelude.id\n ; monotone = Prelude.id\n ; strict = refl\n ; now-to-now = λ _ → refl\n ; ω-continuous = λ _ → refl\n }\n\n-- Composition of morphisms.\n\n_∘_ : ∀ {a p₁ p₂ p₃ q₁ q₂ q₃} {A : Type a}\n {P₁ : Partiality-algebra p₁ q₁ A}\n {P₂ : Partiality-algebra p₂ q₂ A}\n {P₃ : Partiality-algebra p₃ q₃ A} →\n Morphism P₂ P₃ → Morphism P₁ P₂ → Morphism P₁ P₃\n_∘_ {P₁ = P₁} {P₂} {P₃} m₁ m₂ = record\n { function = function m₁ ⊚ function m₂\n ; monotone = monotone m₁ ⊚ monotone m₂\n ; strict = function m₁ (function m₂ (never P₁)) ≡⟨ cong (function m₁) (strict m₂) ⟩\n function m₁ (never P₂) ≡⟨ strict m₁ ⟩∎\n never P₃ ∎\n ; now-to-now = λ x →\n function m₁ (function m₂ (now P₁ x)) ≡⟨ cong (function m₁) (now-to-now m₂ x) ⟩\n function m₁ (now P₂ x) ≡⟨ now-to-now m₁ x ⟩∎\n now P₃ x ∎\n ; ω-continuous = λ s →\n function m₁ (function m₂ (⨆ P₁ s)) ≡⟨ cong (function m₁) (ω-continuous m₂ s) ⟩\n function m₁ (⨆ P₂ (sequence-function m₂ s)) ≡⟨ ω-continuous m₁ (sequence-function m₂ s) ⟩∎\n ⨆ P₃ (sequence-function m₁ (sequence-function m₂ s)) ∎\n }\n where\n open Morphism\n open Partiality-algebra\n\n-- Is-morphism-with P Q f holds if f is a morphism from P to Q.\n\nIs-morphism-with :\n ∀ {a p₁ p₂ q₁ q₂} {T₁ : Type p₁} {T₂ : Type p₂} {A : Type a}\n (P₁ : Partiality-algebra-with T₁ q₁ A)\n (P₂ : Partiality-algebra-with T₂ q₂ A) →\n (T₁ → T₂) → Type _\nIs-morphism-with P₁ P₂ f =\n ∃ λ (m : ∀ {x y} → x P₁.⊑ y → f x P₂.⊑ f y) →\n f P₁.never ≡ P₂.never\n ×\n (∀ x → f (P₁.now x) ≡ P₂.now x)\n ×\n (∀ s → f (P₁.⨆ s) ≡ P₂.⨆ (Σ-map (f ⊚_) (m ⊚_) s))\n where\n module P₁ = Partiality-algebra-with P₁\n module P₂ = Partiality-algebra-with P₂\n\n-- Is-morphism P Q f holds if f is a morphism from P to Q.\n\nIs-morphism :\n let open Partiality-algebra in\n ∀ {a p₁ p₂ q₁ q₂} {A : Type a}\n (P₁ : Partiality-algebra p₁ q₁ A) (P₂ : Partiality-algebra p₂ q₂ A) →\n (T P₁ → T P₂) → Type _\nIs-morphism P₁ P₂ =\n Is-morphism-with P₁.partiality-algebra-with\n P₂.partiality-algebra-with\n where\n module P₁ = Partiality-algebra P₁\n module P₂ = Partiality-algebra P₂\n\n-- An alternative definition of morphisms.\n\nMorphism-as-Σ :\n ∀ {a p₁ p₂ q₁ q₂} {A : Type a} →\n Partiality-algebra p₁ q₁ A → Partiality-algebra p₂ q₂ A → Type _\nMorphism-as-Σ P₁ P₂ =\n ∃ λ (f : P₁.T → P₂.T) → Is-morphism P₁ P₂ f\n where\n module P₁ = Partiality-algebra P₁\n module P₂ = Partiality-algebra P₂\n\n-- The two definitions are isomorphic.\n\nMorphism↔Morphism-as-Σ :\n ∀ {a p₁ p₂ q₁ q₂} {A : Type a}\n {P₁ : Partiality-algebra p₁ q₁ A}\n {P₂ : Partiality-algebra p₂ q₂ A} →\n Morphism P₁ P₂ ↔ Morphism-as-Σ P₁ P₂\nMorphism↔Morphism-as-Σ = record\n { surjection = record\n { logical-equivalence = record\n { to = λ m → function m\n , monotone m\n , strict m\n , now-to-now m\n , ω-continuous m\n ; from = λ { (f , m , s , n , ω) → record\n { function = f\n ; monotone = m\n ; strict = s\n ; now-to-now = n\n ; ω-continuous = ω\n }\n }\n }\n ; right-inverse-of = λ _ → refl\n }\n ; left-inverse-of = λ _ → refl\n }\n where\n open Morphism\n\nabstract\n\n -- Is-morphism-with is pointwise propositional.\n\n Is-morphism-with-propositional :\n let open Partiality-algebra in\n ∀ {a p₁ p₂ q₁ q₂} {T₁ : Type p₁} {T₂ : Type p₂} {A : Type a}\n (P₁ : Partiality-algebra-with T₁ q₁ A)\n (P₂ : Partiality-algebra-with T₂ q₂ A)\n {f : T₁ → T₂} →\n Is-proposition (Is-morphism-with P₁ P₂ f)\n Is-morphism-with-propositional _ P₂ =\n Σ-closure 1 (implicit-Π-closure ext 1 λ _ →\n implicit-Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n P₂.⊑-propositional) λ _ →\n ×-closure 1 P₂.T-is-set $\n ×-closure 1 (Π-closure ext 1 λ _ →\n P₂.T-is-set) $\n Π-closure ext 1 λ _ →\n P₂.T-is-set\n where\n module P₂ = Partiality-algebra-with P₂\n\n -- Is-morphism is pointwise propositional.\n\n Is-morphism-propositional :\n let open Partiality-algebra in\n ∀ {a p₁ p₂ q₁ q₂} {A : Type a}\n (P₁ : Partiality-algebra p₁ q₁ A)\n (P₂ : Partiality-algebra p₂ q₂ A)\n {f : T P₁ → T P₂} →\n Is-proposition (Is-morphism P₁ P₂ f)\n Is-morphism-propositional P₁ P₂ =\n Is-morphism-with-propositional\n P₁.partiality-algebra-with\n P₂.partiality-algebra-with\n where\n module P₁ = Partiality-algebra P₁\n module P₂ = Partiality-algebra P₂\n\n -- An equality characterisation lemma for morphisms.\n\n equality-characterisation-Morphism :\n ∀ {a p₁ p₂ q₁ q₂} {A : Type a}\n {P₁ : Partiality-algebra p₁ q₁ A}\n {P₂ : Partiality-algebra p₂ q₂ A} →\n {m₁ m₂ : Morphism P₁ P₂} →\n\n Morphism.function m₁ ≡ Morphism.function m₂\n ↔\n m₁ ≡ m₂\n equality-characterisation-Morphism {P₁ = P₁} {P₂} {m₁} {m₂} =\n function m₁ ≡ function m₂ ↝⟨ ignore-propositional-component (Is-morphism-propositional P₁ P₂) ⟩\n _↔_.to Morphism↔Morphism-as-Σ m₁ ≡ _↔_.to Morphism↔Morphism-as-Σ m₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ Morphism↔Morphism-as-Σ) ⟩□\n m₁ ≡ m₂ □\n where\n open Morphism\n\n -- The type of morphisms is a set.\n\n Morphism-set :\n ∀ {a p₁ p₂ q₁ q₂} {A : Type a}\n {P₁ : Partiality-algebra p₁ q₁ A}\n {P₂ : Partiality-algebra p₂ q₂ A} →\n Is-set (Morphism P₁ P₂)\n Morphism-set {P₂ = P₂} =\n H-level.respects-surjection\n (_↔_.surjection equality-characterisation-Morphism)\n 1\n (Π-closure ext 2 λ _ → T-is-set P₂)\n where\n open Partiality-algebra\n", "meta": {"hexsha": "354d18f10f2f45c5e02d90efde17b9395ee02018", "size": 11240, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Partiality-algebra.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/Partiality-algebra.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/Partiality-algebra.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": 31.9318181818, "max_line_length": 142, "alphanum_fraction": 0.5545373665, "num_tokens": 3727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6548947425132315, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.38317966972611966}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Results concerning the excluded middle axiom.\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Axiom.ExcludedMiddle where\n\nopen import Level\nopen import Relation.Nullary\n\n------------------------------------------------------------------------\n-- Definition\n\n-- The classical statement of excluded middle says that every\n-- statement/set is decidable (i.e. it either holds or it doesn't hold).\n\nExcludedMiddle : (ℓ : Level) → Set (suc ℓ)\nExcludedMiddle ℓ = {P : Set ℓ} → Dec P\n", "meta": {"hexsha": "8ac27d22b405fcc0f84db1e29b8a3bc9651833b2", "size": 653, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Axiom/ExcludedMiddle.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Axiom/ExcludedMiddle.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Axiom/ExcludedMiddle.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 29.6818181818, "max_line_length": 72, "alphanum_fraction": 0.4793261868, "num_tokens": 117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6548947290421276, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.38317966184416125}} {"text": "open import Nat\nopen import Prelude\nopen import List\nopen import core\nopen import judgemental-erase\nopen import sensibility\nopen import moveerase\n\nmodule checks where\n -- these three judmgements lift the action semantics judgements to relate\n -- an expression and a list of pair-wise composable actions to the\n -- expression that's produced by tracing through the action semantics for\n -- each element in that list.\n --\n -- we do this just by appealing to the original judgement with\n -- constraints on the terms to enforce composability.\n --\n -- in all three cases, we assert that the empty list of actions\n -- constitutes a reflexivity step, so when you run out of actions to\n -- preform you have to be where you wanted to be.\n --\n -- note that the only difference between the types for each judgement and\n -- the original action semantics is that the action is now a list of\n -- actions.\n data runtype : (t : τ̂) (Lα : List action) (t' : τ̂) → Set where\n DoRefl : {t : τ̂} → runtype t [] t\n DoType : {t : τ̂} {α : action} {t' t'' : τ̂}\n {L : List action} →\n t + α +> t' →\n runtype t' L t'' →\n runtype t (α :: L) t''\n\n data runsynth :\n (Γ : ·ctx) (e : ê) (t1 : τ̇) (Lα : List action) (e' : ê) (t2 : τ̇) → Set where\n DoRefl : {Γ : ·ctx} {e : ê} {t : τ̇} → runsynth Γ e t [] e t\n DoSynth : {Γ : ·ctx} {e : ê} {t : τ̇} {α : action} {e' e'' : ê} {t' t'' : τ̇}\n {L : List action} →\n Γ ⊢ e => t ~ α ~> e' => t' →\n runsynth Γ e' t' L e'' t'' →\n runsynth Γ e t (α :: L) e'' t''\n\n data runana : (Γ : ·ctx) (e : ê) (Lα : List action) (e' : ê) (t : τ̇) → Set where\n DoRefl : {Γ : ·ctx} {e : ê} {t : τ̇} → runana Γ e [] e t\n DoAna : {Γ : ·ctx} {e : ê} {α : action} {e' e'' : ê} {t : τ̇}\n {L : List action} →\n Γ ⊢ e ~ α ~> e' ⇐ t →\n runana Γ e' L e'' t →\n runana Γ e (α :: L) e'' t\n\n -- all three run judgements lift to the list monoid as expected. these\n -- theorems are simple because the structure of lists is simple, but they\n -- amount a reasoning principle about the composition of action sequences\n -- by letting you split lists in (nearly) arbitrary places and argue\n -- about the consequences of the splits before composing them together.\n runtype++ : ∀{t t' t'' L1 L2 }\n → runtype t L1 t'\n → runtype t' L2 t''\n → runtype t (L1 ++ L2) t''\n runtype++ DoRefl d2 = d2\n runtype++ (DoType x d1) d2 = DoType x (runtype++ d1 d2)\n\n runsynth++ : ∀{Γ e t L1 e' t' L2 e'' t''}\n → runsynth Γ e t L1 e' t'\n → runsynth Γ e' t' L2 e'' t''\n → runsynth Γ e t (L1 ++ L2) e'' t''\n runsynth++ DoRefl d2 = d2\n runsynth++ (DoSynth x d1) d2 = DoSynth x (runsynth++ d1 d2)\n\n runana++ : ∀{Γ e t L1 e' L2 e''}\n → runana Γ e L1 e' t\n → runana Γ e' L2 e'' t\n → runana Γ e (L1 ++ L2) e'' t\n runana++ DoRefl d2 = d2\n runana++ (DoAna x d1) d2 = DoAna x (runana++ d1 d2)\n\n -- the following collection of lemmas asserts that the various runs\n -- interoperate nicely. in many cases, these amount to observing\n -- something like congruence: if a subterm is related to something by one\n -- of the judgements, it can be replaced by the thing to which it is\n -- related in a larger context without disrupting that larger\n -- context.\n --\n -- taken together, this is a little messier than a proper congruence,\n -- because the action semantics demand well-typedness at each step, and\n -- therefore there are enough premises to each lemma to supply to the\n -- action semantics rules.\n --\n -- therefore, these amount to a checksum on the zipper actions under the\n -- lifing of the action semantics to the list monoid.\n --\n -- they only check the zipper actions they happen to be include, however,\n -- which is driven by the particular lists we use in the proofs of\n -- contructability and reachability, which may or may not be all of\n -- them. additionally, the lemmas given here are what is needed for these\n -- proofs, not anything that's more general.\n\n -- type zippers\n ziplem-tmarr1 : ∀ {t1 t1' t2 L } →\n runtype t1' L t1 →\n runtype (t1' ==>₁ t2) L (t1 ==>₁ t2)\n ziplem-tmarr1 DoRefl = DoRefl\n ziplem-tmarr1 (DoType x L') = DoType (TMArrZip1 x) (ziplem-tmarr1 L')\n\n ziplem-tmarr2 : ∀ {t1 t2 t2' L } →\n runtype t2' L t2 →\n runtype (t1 ==>₂ t2') L (t1 ==>₂ t2)\n ziplem-tmarr2 DoRefl = DoRefl\n ziplem-tmarr2 (DoType x L') = DoType (TMArrZip2 x) (ziplem-tmarr2 L')\n\n\n -- expression zippers\n ziplem-asc1 : ∀{Γ t L e e'} →\n runana Γ e L e' t →\n runsynth Γ (e ·:₁ t) t L (e' ·:₁ t) t\n ziplem-asc1 DoRefl = DoRefl\n ziplem-asc1 (DoAna a r) = DoSynth (SAZipAsc1 a) (ziplem-asc1 r)\n\n ziplem-asc2 : ∀{Γ t L t' t◆ t'◆} →\n erase-t t t◆ →\n erase-t t' t'◆ →\n runtype t L t' →\n runsynth Γ (⦇-⦈ ·:₂ t) t◆ L (⦇-⦈ ·:₂ t') t'◆\n ziplem-asc2 {Γ} er er' rt with erase-t◆ er | erase-t◆ er'\n ... | refl | refl = ziplem-asc2' {Γ = Γ} rt\n where\n ziplem-asc2' : ∀{t L t' Γ } →\n runtype t L t' →\n runsynth Γ (⦇-⦈ ·:₂ t) (t ◆t) L (⦇-⦈ ·:₂ t') (t' ◆t)\n ziplem-asc2' DoRefl = DoRefl\n ziplem-asc2' (DoType x rt) = DoSynth\n (SAZipAsc2 x (◆erase-t _ _ refl) (◆erase-t _ _ refl)\n (ASubsume SEHole TCHole1)) (ziplem-asc2' rt)\n\n ziplem-lam : ∀ {Γ x e t t1 t2 L e'} →\n x # Γ →\n t ▸arr (t1 ==> t2) →\n runana (Γ ,, (x , t1)) e L e' t2 →\n runana Γ (·λ x e) L (·λ x e') t\n ziplem-lam a m DoRefl = DoRefl\n ziplem-lam a m (DoAna x₁ d) = DoAna (AAZipLam a m x₁) (ziplem-lam a m d)\n\n ziplem-plus1 : ∀{ Γ e L e' f} →\n runana Γ e L e' num →\n runsynth Γ (e ·+₁ f) num L (e' ·+₁ f) num\n ziplem-plus1 DoRefl = DoRefl\n ziplem-plus1 (DoAna x d) = DoSynth (SAZipPlus1 x) (ziplem-plus1 d)\n\n ziplem-plus2 : ∀{ Γ e L e' f} →\n runana Γ e L e' num →\n runsynth Γ (f ·+₂ e) num L (f ·+₂ e') num\n ziplem-plus2 DoRefl = DoRefl\n ziplem-plus2 (DoAna x d) = DoSynth (SAZipPlus2 x) (ziplem-plus2 d)\n\n ziplem-ap2 : ∀{ Γ e L e' t t' f tf} →\n Γ ⊢ f => t' →\n t' ▸arr (t ==> tf) →\n runana Γ e L e' t →\n runsynth Γ (f ∘₂ e) tf L (f ∘₂ e') tf\n ziplem-ap2 wt m DoRefl = DoRefl\n ziplem-ap2 wt m (DoAna x d) = DoSynth (SAZipApAna m wt x) (ziplem-ap2 wt m d)\n\n ziplem-nehole-a : ∀{Γ e e' L t t'} →\n (Γ ⊢ e ◆e => t) →\n runsynth Γ e t L e' t' →\n runsynth Γ ⦇⌜ e ⌟⦈ ⦇-⦈ L ⦇⌜ e' ⌟⦈ ⦇-⦈\n ziplem-nehole-a wt DoRefl = DoRefl\n ziplem-nehole-a wt (DoSynth {e = e} x d) =\n DoSynth (SAZipHole (rel◆ e) wt x) (ziplem-nehole-a (actsense-synth (rel◆ e) (rel◆ _) x wt) d)\n\n ziplem-nehole-b : ∀{Γ e e' L t t' t''} →\n (Γ ⊢ e ◆e => t) →\n (t'' ~ t') →\n runsynth Γ e t L e' t' →\n runana Γ ⦇⌜ e ⌟⦈ L ⦇⌜ e' ⌟⦈ t''\n ziplem-nehole-b wt c DoRefl = DoRefl\n ziplem-nehole-b wt c (DoSynth x rs) =\n DoAna (AASubsume (erase-in-hole (rel◆ _)) (SNEHole wt) (SAZipHole (rel◆ _) wt x) TCHole1)\n (ziplem-nehole-b (actsense-synth (rel◆ _) (rel◆ _) x wt) c rs)\n\n\n -- because the point of the reachability theorems is to show that we\n -- didn't forget to define any of the action semantic cases, it's\n -- important that theorems include the fact that the witness only uses\n -- move -- otherwise, you could cheat by just prepending [ del ] to the\n -- list produced by constructability. constructability does also use\n -- some, but not all, of the possible movements, so this would no longer\n -- demonstrate the property we really want. to that end, we define a\n -- predicate on lists that they contain only (move _) and that the\n -- various things above that produce the lists we use have this property.\n\n -- predicate\n data movements : List action → Set where\n AM:: : {L : List action} {δ : direction}\n → movements L\n → movements ((move δ) :: L)\n AM[] : movements []\n\n -- movements breaks over the list monoid, as expected\n movements++ : {l1 l2 : List action} →\n movements l1 → movements l2 → movements (l1 ++ l2)\n movements++ (AM:: m1) m2 = AM:: (movements++ m1 m2)\n movements++ AM[] m2 = m2\n\n\n -- these are zipper lemmas that are specific to list of movement\n -- actions. they are not true for general actions, but because\n -- reachability is restricted to movements, we get some milage out of\n -- them anyway.\n endpoints : ∀{ Γ e t L e' t'} →\n Γ ⊢ (e ◆e) => t →\n runsynth Γ e t L e' t' →\n movements L →\n t == t'\n endpoints _ DoRefl AM[] = refl\n endpoints wt (DoSynth x rs) (AM:: mv)\n with endpoints (actsense-synth (rel◆ _) (rel◆ _) x wt) rs mv\n ... | refl = π2 (moveerase-synth (rel◆ _) wt x)\n\n ziplem-moves-asc2 : ∀{ Γ l t t' e t◆ } →\n movements l →\n erase-t t t◆ →\n Γ ⊢ e <= t◆ →\n runtype t l t' →\n runsynth Γ (e ·:₂ t) t◆ l (e ·:₂ t') t◆\n ziplem-moves-asc2 _ _ _ DoRefl = DoRefl\n ziplem-moves-asc2 (AM:: m) er wt (DoType x rt) with moveeraset' er x\n ... | er' = DoSynth (SAZipAsc2 x er' er wt) (ziplem-moves-asc2 m er' wt rt)\n\n synthana-moves : ∀{t t' l e e' Γ} →\n Γ ⊢ e ◆e => t' →\n movements l →\n t ~ t' →\n runsynth Γ e t' l e' t' →\n runana Γ e l e' t\n synthana-moves _ _ _ DoRefl = DoRefl\n synthana-moves wt (AM:: m) c (DoSynth x rs) with π2 (moveerase-synth (rel◆ _) wt x)\n ... | refl = DoAna (AASubsume (rel◆ _) wt x c)\n (synthana-moves (actsense-synth (rel◆ _) (rel◆ _) x wt) m c rs)\n\n ziplem-moves-ap1 : ∀{Γ l e1 e1' e2 t t' tx} →\n Γ ⊢ e1 ◆e => t →\n t ▸arr (tx ==> t') →\n Γ ⊢ e2 <= tx →\n movements l →\n runsynth Γ e1 t l e1' t →\n runsynth Γ (e1 ∘₁ e2) t' l (e1' ∘₁ e2) t'\n ziplem-moves-ap1 _ _ _ _ DoRefl = DoRefl\n ziplem-moves-ap1 wt1 mch wt2 (AM:: m) (DoSynth x rs) with π2 (moveerase-synth (rel◆ _) wt1 x)\n ... | refl = DoSynth (SAZipApArr mch (rel◆ _) wt1 x wt2)\n (ziplem-moves-ap1 (actsense-synth (rel◆ _) (rel◆ _) x wt1)\n mch wt2 m rs)\n", "meta": {"hexsha": "9f671da7c1ce7fc505c903116ebd33f6de23960d", "size": 10785, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "checks.agda", "max_stars_repo_name": "hazelgrove/agda-popl17", "max_stars_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-07-01T22:44:11.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-11T12:30:50.000Z", "max_issues_repo_path": "checks.agda", "max_issues_repo_name": "hazelgrove/agda-popl17", "max_issues_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2016-07-07T16:23:11.000Z", "max_issues_repo_issues_event_max_datetime": "2016-11-09T18:13:55.000Z", "max_forks_repo_path": "checks.agda", "max_forks_repo_name": "hazelgrove/agda-popl17", "max_forks_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-03T03:45:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-03T03:45:07.000Z", "avg_line_length": 42.7976190476, "max_line_length": 110, "alphanum_fraction": 0.5325915624, "num_tokens": 3770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723317123102955, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.38313000888984217}} {"text": "\n-- IIRDg is expressible in IIRDr + Identity\nmodule Proof where\n\nopen import LF\nopen import IIRD\nopen import IIRDr\nopen import DefinitionalEquality\nopen import Identity\nopen import Proof.Setup\nimport Logic.ChainReasoning as Chain\n\n-- We can then define general IIRDs using the ε function from Proof.Setup.\nUg : {I : Set}{D : I -> Set1} -> OPg I D -> I -> Set\nUg γ = Ur (ε γ)\n\nTg : {I : Set}{D : I -> Set1}(γ : OPg I D)(i : I) -> Ug γ i -> D i\nTg γ = Tr (ε γ)\n\nintrog : {I : Set}{D : I -> Set1}(γ : OPg I D)(a : Gu γ (Ug γ) (Tg γ)) ->\n Ug γ (Gi γ (Ug γ) (Tg γ) a)\nintrog γ a = intror (G→H γ (Ug γ) (Tg γ) a)\n\n-- To prove the reduction behviour of Tg we first have to prove that the\n-- top-level reduction of the encoding behaves as it should. At bit simplified\n-- that Ht (ε γ) (Gi a) ≡ Gt γ a\nTg-eq : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i)\n (a : Gu γ U T) ->\n Ht (ε γ) U T (Gi γ U T a) (G→H γ U T a) ≡₁ Gt γ U T a\nTg-eq {I}{D} (ι < i | e >') U T ★ = refl-≡₁\nTg-eq (σ A γ) U T < a | b > = Tg-eq (γ a) U T b\nTg-eq (δ A i γ) U T < g | b > = Tg-eq (γ (T « i × g »)) U T b\n\n-- The statement we're interested in is a special case of the more general\n-- lemma above.\nTg-equality : {I : Set}{D : I -> Set1}(γ : OPg I D)(a : Gu γ (Ug γ) (Tg γ)) ->\n Tg γ (Gi γ (Ug γ) (Tg γ) a) (introg γ a) ≡₁ Gt γ (Ug γ) (Tg γ) a\nTg-equality γ a = Tg-eq γ (Ug γ) (Tg γ) a\n\n-- The elimination rule for generalised IIRDs.\n-- It's basically the elimination of the encoding followed by the elimination\n-- of the proof the the index is the right one.\nRg : {I : Set}{D : I -> Set1}(γ : OPg I D)(F : (i : I) -> Ug γ i -> Set1)\n (h : (a : Gu γ (Ug γ) (Tg γ)) -> KIH γ (Ug γ) (Tg γ) F a -> F (Gi γ (Ug γ) (Tg γ) a) (introg γ a))\n (i : I)(u : Ug γ i) -> F i u\nRg {I}{D} γ F h = Rr (ε γ) F \\i a ih ->\n G→H∘H→G-subst γ U T\n (\\i a -> F i (intror a))\n i a (lem1 i a ih)\n where\n U = Ug γ\n T = Tg γ\n lem1 : (i : I)(a : Hu (ε γ) U T i) ->\n KIH (ε γ i) U T F a ->\n F (Gi γ U T (H→G γ U T i a))\n (intror (G→H γ U T (H→G γ U T i a)))\n lem1 i a ih = h (H→G γ U T i a) (\\v -> εIArg-subst γ U T F i a v (ih (εIArg γ U T i a v)))\n\nopen module Chain-≡ = Chain.Poly.Heterogenous1 _≡₁_ (\\x -> refl-≡₁) trans-≡₁\nopen module Chain-≡₀ = Chain.Poly.Heterogenous _≡_ (\\x -> refl-≡) trans-≡\n\t renaming (chain>_ to chain>₀_; _===_ to _===₀_; _by_ to _by₀_)\n\n-- Again we have to generalise\nRg-eq : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i)\n (F : (i : I) -> U i -> Set1)(intro : (a : Gu γ U T) -> U (Gi γ U T a))\n (g : (i : I)(u : U i) -> F i u)\n (h : (a : Gu γ U T) -> KIH γ U T F a -> F (Gi γ U T a) (intro a))\n (a : Gu γ U T) ->\n let i = Gi γ U T a\n a' = G→H γ U T a\n in h (H→G γ U T i a')\n\t (\\v -> εIArg-subst γ U T F i a' v\n\t\t (Kmap (ε γ i) U T F g a' (εIArg γ U T i a' v)))\n ≡₁ h a (Kmap γ U T F g a)\nRg-eq {I}{D} γ U T F intro g h a = app-≡₁\n (cong-≡₁⁰ h (H→G∘G→H-identity γ U T a))\n (η-≡₁⁰ \\x y p ->\n chain> εIArg-subst γ U T F i a' x (Kmap (ε γ i) U T F g a' (εIArg γ U T i a' x))\n === Kmap (ε γ i) U T F g a' (εIArg γ U T i a' x)\n by εIArg-identity γ U T F a x (Kmap (ε γ i) U T F g a' (εIArg γ U T i a' x))\n === Kmap γ U T F g a y\n by app-≡₁⁰\n (cong-≡₁⁰ g\n (chain>₀ KIArg→I (ε γ i) U T a' (εIArg γ U T i a' x)\n ===₀ KIArg→I γ U T (H→G γ U T i a') x by₀ εIArg→I-identity γ U T i a' x\n ===₀ KIArg→I γ U T a y by₀\n app-≡₀ (cong-≡' (KIArg→I γ U T)\n (H→G∘G→H-identity γ U T a)\n ) p\n )\n )\n (chain>₀ KIArg→U (ε γ i) U T a' (εIArg γ U T i a' x)\n ===₀ KIArg→U γ U T (H→G γ U T i a') x by₀ εIArg→U-identity γ U T i a' x\n ===₀ KIArg→U γ U T a y by₀\n app-≡₀ (cong-≡' (KIArg→U γ U T)\n (H→G∘G→H-identity γ U T a)\n ) p\n )\n )\n where\n i = Gi γ U T a\n a' = G→H γ U T a\n\nRg-equality : {I : Set}{D : I -> Set1}(γ : OPg I D)(F : (i : I) -> Ug γ i -> Set1)\n (h : (a : Gu γ (Ug γ) (Tg γ)) -> KIH γ (Ug γ) (Tg γ) F a -> F (Gi γ (Ug γ) (Tg γ) a) (introg γ a))\n (a : Gu γ (Ug γ) (Tg γ)) ->\n Rg γ F h (Gi γ (Ug γ) (Tg γ) a) (introg γ a)\n ≡₁ h a (Kmap γ (Ug γ) (Tg γ) F (Rg γ F h) a)\nRg-equality {I}{D} γ F h a =\n chain> Rg γ F h (Gi γ U T a) (introg γ a)\n === h'' i a' ih by refl-≡₁\n === G→H∘H→G-subst γ U T F' i a' (h' i a' ih)\n by refl-≡₁\n === h' i a' ih by G→H∘H→G-identity γ U T F' a (h' i a' ih)\n === h (H→G γ U T i a') (\\v -> εIArg-subst γ U T F i a' v (ih (εIArg γ U T i a' v)))\n by refl-≡₁\n === h a (Kmap γ U T F (Rg γ F h) a) by Rg-eq γ U T F (introg γ) (Rg γ F h) h a\n where\n U = Ug γ\n T = Tg γ\n F' = \\i a -> F i (intror a)\n i = Gi γ U T a\n a' = G→H γ U T a\n h' : (i : I)(a : Hu (ε γ) U T i) -> KIH (ε γ i) U T F a -> F _ _\n h' = \\i a ih -> h (H→G γ U T i a) \\v ->\n εIArg-subst γ U T F i a v\n (ih (εIArg γ U T i a v))\n h'' = \\i a ih -> G→H∘H→G-subst γ U T F' i a (h' i a ih)\n ih = Kmap (ε γ i) U T F (Rg γ F h) a'\n\n", "meta": {"hexsha": "f625fdc7fa99d32f132a3efdf702423f511d277c", "size": 5734, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "examples/outdated-and-incorrect/iird/Proof.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": "examples/outdated-and-incorrect/iird/Proof.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": "examples/outdated-and-incorrect/iird/Proof.agda", "max_forks_repo_name": "masondesu/agda", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "avg_line_length": 43.7709923664, "max_line_length": 112, "alphanum_fraction": 0.4258807115, "num_tokens": 2377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723316991792861, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3831300014071017}} {"text": "\nopen import Everything\n\nmodule Test.Symmetrical where\n\n test-𝓢ymmetrical𝓢ymmetry : ∀\n {𝔬} {𝔒 : Ø 𝔬}\n {ℓ} {_∼_ : 𝔒 → 𝔒 → Ø ℓ}\n ⦃ _ : Symmetry.class _∼_ ⦄\n → Symmetry.type _∼_\n -- test-𝓢ymmetrical𝓢ymmetry = symmetrical _ _ -- FIXME no longer works after 𝓢ymmetrical𝓢ymmetry was \"rationalised\"\n test-𝓢ymmetrical𝓢ymmetry {𝔒 = 𝔒} = symmetrical {𝔄 = 𝔒} _ _\n\n test-𝓢ymmetrical𝓢ymmetry-alternate : ∀\n {𝔬} {𝔒 : Ø 𝔬}\n {ℓ} {_∼_ : 𝔒 → 𝔒 → Ø ℓ}\n ⦃ _ : Symmetry.class _∼_ ⦄\n → Symmetry.type _∼_\n test-𝓢ymmetrical𝓢ymmetry-alternate {x = x} = symmetrical x _\n\n lhs-test1 : ∀ {𝔬} {𝔒 : Ø 𝔬}\n {ℓ} {_∼_ : 𝔒 → 𝔒 → Ø ℓ}\n ⦃ _ : Symmetry.class _∼_ ⦄\n {_∼'_ : 𝔒 → 𝔒 → Ø ℓ}\n ⦃ _ : Symmetry.class _∼'_ ⦄\n → ∀ x y → _\n lhs-test1 {_∼_ = _∼_} = symmetrical⟦ _∼_ / (λ x y → x → y) ⟧\n\n module OverlappingInstances\n {𝔞} {𝔄 : Ø 𝔞}\n {𝔟} {𝔅 : Ø 𝔟}\n {ℓ} {_↦_ : 𝔅 → 𝔅 → Ø ℓ}\n {_↦'_ : 𝔅 → 𝔅 → Ø ℓ}\n {_∼1_ : 𝔄 → 𝔄 → 𝔅}\n {_∼2_ : 𝔄 → 𝔄 → 𝔅}\n ⦃ _ : Symmetrical _∼1_ _↦_ ⦄\n ⦃ _ : Symmetrical _∼1_ _↦'_ ⦄\n ⦃ _ : Symmetrical _∼2_ _↦_ ⦄\n ⦃ _ : Symmetrical _∼2_ _↦'_ ⦄\n (x y : 𝔄)\n where\n\n test1 = symmetrical {_∼_ = _∼1_} {_↦_ = _↦_} x y\n\n test2 : (x ∼1 y) ↦ (y ∼1 x)\n test2 = symmetrical⟦ _ / _↦_ ⟧ x y\n\n test2a : (x ∼1 y) ↦ (y ∼1 x)\n test2a = symmetrical x y\n\n test3 = symmetrical⟦ _∼1_ / _↦_ ⟧ x y\n\n lhs-test2a : ∀\n {𝔞} {𝔄 : Ø 𝔞}\n {𝔟} {𝔅 : Ø 𝔟}\n (_∼_ : 𝔄 → 𝔄 → 𝔅)\n {ℓ} (_↦_ : 𝔅 → 𝔅 → Ø ℓ)\n ⦃ _ : Symmetrical _∼_ _↦_ ⦄\n → ∀ (x y : 𝔄) → _ ↦ _\n lhs-test2a _∼_ _↦_ x y =\n symmetrical x y -- works\n -- symmetrical⟦ _∼_ / _↦_ ⟧ x y -- works\n -- symmetrical⟦ _ / _↦_ ⟧ x y -- works\n -- symmetrical⟦ _∼_ / _ ⟧ x y -- works\n\n open import Oscar.Data.Proposequality\n lhs-test2a' : ∀\n {𝔞} {𝔄 : Ø 𝔞}\n {𝔟} {𝔅 : Ø 𝔟}\n (_∼_ : 𝔄 → 𝔄 → 𝔅) {_∼'_ : 𝔄 → 𝔄 → 𝔅}\n {ℓ} (_↦_ : 𝔅 → 𝔅 → Ø ℓ) {_↦'_ : 𝔅 → 𝔅 → Ø ℓ}\n ⦃ _ : Symmetrical _∼_ _↦_ ⦄\n ⦃ _ : Symmetrical _∼'_ _↦_ ⦄\n ⦃ _ : Symmetrical _∼_ _↦'_ ⦄\n ⦃ _ : Symmetrical _∼'_ _↦'_ ⦄\n → ∀ (x y : 𝔄) → -- _\n _ ↦ _\n -- (x ∼ y) ↦ (y ∼ x)\n lhs-test2a' _∼_ _↦_ x y =\n symmetrical⟦ _∼_ / _ ⟧ x y\n -- symmetrical x y -- fails, as expected\n -- symmetrical⟦ _ / _ ⟧ x y -- fails, as expected\n -- symmetrical⟦ _ / _↦_ ⟧ x y -- fails, as expected\n\n lhs-test2a'' : ∀\n {𝔞} {𝔄 : Ø 𝔞}\n {𝔟} {𝔅 : Ø 𝔟}\n (_∼_ : 𝔄 → 𝔄 → 𝔅) {_∼'_ : 𝔄 → 𝔄 → 𝔅}\n {ℓ} (_↦_ : 𝔅 → 𝔅 → Ø ℓ) {_↦'_ : 𝔅 → 𝔅 → Ø ℓ}\n ⦃ _ : Symmetrical _∼_ _↦_ ⦄\n ⦃ _ : Symmetrical _∼'_ _↦_ ⦄\n ⦃ _ : Symmetrical _∼_ _↦'_ ⦄\n ⦃ _ : Symmetrical _∼'_ _↦'_ ⦄\n → ∀ (x y : 𝔄) → -- _\n -- _ ↦ _\n (x ∼ y) ↦ (y ∼ x)\n lhs-test2a'' _∼_ _↦_ x y =\n symmetrical {_∼_ = _∼_} x y\n -- symmetrical'' {_↦_ = _↦_} x y\n -- symmetrical'' {_∼_ = _∼_} {_↦_ = _↦_} x y\n -- symmetrical'' x y\n", "meta": {"hexsha": "9f5621fb2409415adcebcdf89e7d43ef3cdb9e76", "size": 2873, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "archive/agda-3/src/Test/Symmetrical.agda", "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "archive/agda-3/src/Test/Symmetrical.agda", "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_forks_repo_path": "archive/agda-3/src/Test/Symmetrical.agda", "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1666666667, "max_line_length": 117, "alphanum_fraction": 0.4566655064, "num_tokens": 1570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723316991792861, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3831300014071017}} {"text": "{-# OPTIONS --allow-unsolved-metas #-}\n-- {-# OPTIONS -v tc.meta:45 #-}\n\n-- Andreas, 2014-12-07 found a bug in pruning\n\nopen import Common.Prelude\nopen import Common.Product\nopen import Common.Equality\n\npostulate\n f : Bool → Bool\n\ntest : let\n X : Bool → Bool → Bool\n X = _\n Y : Bool\n Y = _\n in ∀ b → Y ≡ f (X b (f (if true then true else b))) ×\n (∀ a → X a (f b) ≡ f b)\ntest b = refl , λ a → refl\n\n-- ERROR WAS:\n\n-- Cannot instantiate the metavariable _22 to solution f b since it\n-- contains the variable b which is not in scope of the metavariable\n-- or irrelevant in the metavariable but relevant in the solution\n-- when checking that the expression refl has type (_22 ≡ f b)\n\n-- Here, Agda complains although there is a solution\n\n-- X a b = b\n-- Y = f (f true)\n\n-- Looking at the first constraint\n\n-- Y = f (X b (f (if true then true else b)))\n\n-- agda prunes *both* arguments of X since they have rigid occurrences\n-- of b. However, the second occurrences goes away by normalization:\n\n-- Y = f (X b (f true))\n\n-- For efficiency reasons, see issue 415 , Agda first does not\n-- normalize during occurs check. Thus, the free variable check for\n-- the arg (if true then true else b) returns b as rigid, which means\n-- we have a neutral term (f (...b...)) with a rigid occurrence of bad\n-- variable b, and we prune this argument of meta X. This is unsound,\n-- since the free variable check only returns a superset of the actual\n-- (semantic) variable dependencies.\n\n-- NOW: metas should be unsolved.\n", "meta": {"hexsha": "c064ae1cc117bedb46492aba4ab4cfe4fceda770", "size": 1536, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1386.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue1386.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue1386.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 29.5384615385, "max_line_length": 70, "alphanum_fraction": 0.6692708333, "num_tokens": 421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.685949467848392, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.38298410464974225}} {"text": "\npostulate\n C : Set\n anything : C\n\nrecord I : Set where\n constructor c\n field\n f : C\n\ndata Wrap : (j : I) → Set where\n wrap : ∀ {j} → Wrap j\n\n-- The following should not pass.\n-- It did before the fix of #142.\nissue142 : ∀ {j} → Wrap j → C\nissue142 {c _} (wrap {c _}) with anything\nissue142 {c _} (wrap .{c anything}) | z = z\n", "meta": {"hexsha": "0b440622a834ebc918e67e41b54c081d6039c72d", "size": 334, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue1606.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/Issue1606.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/Issue1606.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": 17.5789473684, "max_line_length": 43, "alphanum_fraction": 0.5958083832, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6859494550081925, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.38298409748071227}} {"text": "import MJ.Classtable.Core as Core\n\n\nmodule MJ.Classtable.Membership {c}(Ct : Core.Classtable c) where\n\nopen Core c\nopen Classtable Ct\n\nopen import Prelude\nopen import Data.Star\nopen import Data.Product hiding (Σ)\nopen import Data.List\nopen import Data.List.Relation.Unary.Any\nopen import Data.List.Relation.Unary.Any.Properties\nopen import Data.List.First.Membership\nopen import Data.Product.Relation.Binary.Pointwise.NonDependent\nopen import Relation.Nullary.Decidable\nopen import Data.Maybe\nopen import Data.String as Str\nopen import Function.Equality using (Π)\nopen import Function.Inverse using (Inverse)\n\nopen import MJ.Types as Types\n\n{-\nWe can observe that a class declares a member in a particular namespace using a\npredicate Declares.\n-}\nDeclares : Cid c → (ns : NS) → String → typing ns → Set\nDeclares cid ns m ty = let cl = Σ cid in (m , ty) ∈ (Class.decls cl ns)\n\n{-\nWe define a notion of *declarative membership* of C as the product\nof a witness that C inherits from P and a declaration in P.\n-}\nIsMember : Cid c → (ns : NS) → String → typing ns → Set\nIsMember cid ns m ty = let C = Σ cid in ∃ λ P → Σ ⊢ cid <: P × Declares P ns m ty\n\n{-\nWe can prove that Object has no members.\n-}\n∉Object : ∀ {ns m a} → ¬ IsMember Object ns m a\n∉Object (.Object , ε , mem) rewrite Σ-Object = ¬x∈[] mem\n∉Object (._ , () ◅ _ , _)\n\n{-\nAnd we can show that Declares and IsMember are decidable relations\n-}\nfind-declaration : ∀ cid ns n ty → Dec (Declares cid ns n ty)\nfind-declaration cid ns m ty = find (Str._≟_ ×-≟ _typing-≟_) (m , ty) (Class.decls (Σ cid) ns)\n\nfind-member : ∀ cid ns n ty → Dec (IsMember cid ns n ty)\nfind-member cid ns n ty = helper cid ns n ty (rooted cid)\n where\n helper : ∀ cid ns n ty → Σ ⊢ cid <: Object → Dec (IsMember cid ns n ty)\n helper cid ns n ty ε = no (⊥-elim ∘ ∉Object)\n helper cid ns n ty (super ◅ p) with find-declaration cid ns n ty\n ... | yes q = yes (cid , ε , q)\n ... | no ¬q with helper _ ns n ty p\n ... | yes (pid , s , d) = yes (pid , super ◅ s , d)\n ... | no ¬r = no impossible\n where\n impossible : ¬ (IsMember cid ns n ty)\n impossible (_ , ε , d) = ¬q d\n impossible (pid , Core.super ◅ s , d) = ¬r (pid , s , d)\n\n{-\nUsing said decision procedures we can formalize a notion of accessible members.\n-}\nAccMember : Cid c → (ns : NS) → String → typing ns → Set\nAccMember cid ns n ty = True (find-member cid ns n ty)\n\n{-\nAll accessible members are also declarative members, but not vice versa,\nbecause overrides make their super inaccessible.\n-}\nsound : ∀ {cid ns n ty} → AccMember cid ns n ty → IsMember cid ns n ty\nsound p = toWitness p\n\n{-\nDeclarative members are inherited:\n-}\ninherit' : ∀ {C P ns m a} → Σ ⊢ C <: P → IsMember P ns m a → IsMember C ns m a\ninherit' S (_ , S' , def) = -, S ◅◅ S' , def\n\n{-\nAccessible members are inherited (but may point to different definitions thanks to overrides):\n-}\ninherit : ∀ {m ns ty pid} cid → Σ ⊢ cid <: pid → AccMember pid ns m ty → AccMember cid ns m ty\ninherit {m}{ns}{ty} cid s mb with find-member cid ns m ty\n... | yes mb' = tt\n... | no ¬mb = ⊥-elim (¬mb (inherit' s (sound mb)))\n", "meta": {"hexsha": "f0ad55dc0c4499ca7ae82f2ff06bfc8854b1b304", "size": 3113, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/MJ/Classtable/Membership.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/Membership.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/Membership.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.4731182796, "max_line_length": 94, "alphanum_fraction": 0.6646321876, "num_tokens": 953, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.737158174177441, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.3829693891364554}} {"text": "{-# OPTIONS --safe #-}\nmodule Cubical.Algebra.CommRing.Instances.Unit where\n\nopen import Cubical.Foundations.Prelude\n\nopen import Cubical.Data.Unit\n\nopen import Cubical.Algebra.Ring\nopen import Cubical.Algebra.CommRing\n\nprivate\n variable\n ℓ : Level\n\nopen CommRingStr\n\nUnitCommRing : ∀ {ℓ} → CommRing ℓ\nfst UnitCommRing = Unit*\n0r (snd UnitCommRing) = tt*\n1r (snd UnitCommRing) = tt*\n_+_ (snd UnitCommRing) = λ _ _ → tt*\n_·_ (snd UnitCommRing) = λ _ _ → tt*\n- snd UnitCommRing = λ _ → tt*\nisCommRing (snd UnitCommRing) =\n makeIsCommRing isSetUnit* (λ _ _ _ → refl) (λ { tt* → refl }) (λ _ → refl)\n (λ _ _ → refl) (λ _ _ _ → refl) (λ { tt* → refl })\n (λ _ _ _ → refl) (λ _ _ → refl)\n", "meta": {"hexsha": "3a9e6a3685850f03af509c116f8290679aa860d9", "size": 718, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/CommRing/Instances/Unit.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_issues_repo_path": "Cubical/Algebra/CommRing/Instances/Unit.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/CommRing/Instances/Unit.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": 25.6428571429, "max_line_length": 76, "alphanum_fraction": 0.6420612813, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.837619947119304, "lm_q2_score": 0.45713671682749474, "lm_q1q2_score": 0.38290683257533836}} {"text": "module RawSemantics where\n\nopen import Data.Maybe\nopen import Data.Nat hiding (_⊔_; _⊓_)\nopen import Data.Product\nopen import Data.Sum\nopen import Data.String using (String)\nopen import Data.Unit hiding (_≟_)\nopen import Data.Empty\n\nopen import Function using (_∘_)\n\nopen import Relation.Nullary\nimport Relation.Binary.PropositionalEquality as Eq\nopen Eq using (_≡_;_≢_; refl)\nopen Eq.≡-Reasoning\nopen import Level hiding (_⊔_) renaming (zero to lzero; suc to lsuc)\n\n{- TODO:\n* might be useful to distinguish positive and negative (refinement) types from the start\n* subtyping of refinement types\n* union types: want a rule to convert from a (union) type to a sum type using a decidable predicate\n* intersection types\n-}\n\nId = String\n\nvariable\n x y : Id\n ℓ ℓ′ : Level\n n : ℕ\n\ndata Expr : Set where\n Nat : ℕ → Expr\n Var : Id → Expr\n Lam : Id → Expr → Expr\n App : Expr → Expr → Expr\n Pair : Expr → Expr → Expr\n LetPair : Id → Id → Expr → Expr → Expr\n Fst Snd : Expr → Expr\n Inl Inr : Expr → Expr\n Case : Expr → Id → Expr → Id → Expr → Expr\n\n-- raw types are the types which support standard execution\n-- currently just simple types\n\ndata RawType : Set where\n Nat : RawType\n _⇒_ _⋆_ _⊹_ : RawType → RawType → RawType\n\n\nss⇒tt : ∀ {S S₁ T T₁ : RawType} → (S ⇒ S₁) ≡ (T ⇒ T₁) → (S ≡ T × S₁ ≡ T₁)\nss⇒tt refl = refl , refl\n\nss⋆tt : ∀ {S S₁ T T₁ : RawType} → (S ⋆ S₁) ≡ (T ⋆ T₁) → (S ≡ T × S₁ ≡ T₁)\nss⋆tt refl = refl , refl\n\nss⊹tt : ∀ {S S₁ T T₁ : RawType} → (S ⊹ S₁) ≡ (T ⊹ T₁) → (S ≡ T × S₁ ≡ T₁)\nss⊹tt refl = refl , refl\n\n-- semantics of raw types\nR⟦_⟧ : RawType → Set\nR⟦ Nat ⟧ = ℕ\nR⟦ S ⇒ T ⟧ = R⟦ S ⟧ → R⟦ T ⟧\nR⟦ S ⋆ T ⟧ = R⟦ S ⟧ × R⟦ T ⟧\nR⟦ S ⊹ T ⟧ = R⟦ S ⟧ ⊎ R⟦ T ⟧\n\n\ndata Env (A : Set ℓ) : Set ℓ where\n · : Env A\n _,_⦂_ : Env A → (x : Id) → (a : A) → Env A\n\ndata AllEnv (A : Set ℓ) (P : A → Set) : Env A → Set ℓ where\n · : AllEnv A P ·\n _,_ : ∀ {γ}{x : Id}{a : A} → AllEnv A P γ → P a → AllEnv A P (γ , x ⦂ a)\n\nvariable\n L M N : Expr\n\n RS RT RU RV RW : RawType\n Δ Δ₁ Δ₂ : Env RawType\n\n-- mapping a function over an environment\n\n_⁺ : ∀ {A : Set ℓ′}{B : Set ℓ} → (A → B) → (Env A → Env B)\n(f ⁺) · = ·\n(f ⁺) (Φ , x ⦂ a) = (f ⁺) Φ , x ⦂ f a\n\nRE⟦_⟧ : Env RawType → Env Set\nRE⟦_⟧ = R⟦_⟧ ⁺\n\ndata _⦂_∈_ {A : Set ℓ} : Id → A → Env A → Set ℓ where\n\n found : ∀ {a : A}{E : Env A} →\n x ⦂ a ∈ (E , x ⦂ a)\n\n there : ∀ {a a' : A}{E : Env A} →\n x ⦂ a ∈ E →\n -- x ≢ y →\n x ⦂ a ∈ (E , y ⦂ a')\n\n\ndata iEnv : Env Set → Set where\n · : iEnv ·\n _,_⦂_ : ∀ {E}{A} → iEnv E → (x : Id) → (a : A) → iEnv (E , x ⦂ A)\n\ndata jEnv {A : Set ℓ} (⟦_⟧ : A → Set) : Env A → Set where\n · : jEnv ⟦_⟧ ·\n _,_⦂_ : ∀ {E}{A} → jEnv ⟦_⟧ E → (x : Id) → (a : ⟦ A ⟧) → jEnv ⟦_⟧ (E , x ⦂ A)\n\n-- F here is a natural transformation\njEnvMap : {A : Set ℓ} {⟦_⟧ ⟦_⟧′ : A → Set}{E : Env A} →\n (F : {a : A} → ⟦ a ⟧ → ⟦ a ⟧′) →\n jEnv ⟦_⟧ E → jEnv ⟦_⟧′ E\njEnvMap F · = ·\njEnvMap F (env , x ⦂ ⟦a⟧) = (jEnvMap F env) , x ⦂ F ⟦a⟧\n\n-- should be in terms of RawType for evaluation\n\ndata _⊢_⦂_ : Env RawType → Expr → RawType → Set₁ where\n\n nat :\n Δ ⊢ Nat n ⦂ Nat\n\n var :\n (x∈ : x ⦂ RT ∈ Δ) →\n --------------------\n Δ ⊢ Var x ⦂ RT\n\n lam :\n (Δ , x ⦂ RS) ⊢ M ⦂ RT →\n --------------------\n Δ ⊢ Lam x M ⦂ (RS ⇒ RT)\n\n app :\n Δ ⊢ M ⦂ (RS ⇒ RT) →\n Δ ⊢ N ⦂ RS →\n --------------------\n Δ ⊢ App M N ⦂ RT\n\n pair :\n Δ ⊢ M ⦂ RS →\n Δ ⊢ N ⦂ RT →\n --------------------\n Δ ⊢ Pair M N ⦂ (RS ⋆ RT)\n\n pair-E :\n Δ ⊢ M ⦂ (RS ⋆ RT) →\n ((Δ , x ⦂ RS) , y ⦂ RT) ⊢ N ⦂ RU →\n ------------------------------\n Δ ⊢ LetPair x y M N ⦂ RU\n\n pair-E1 :\n Δ ⊢ M ⦂ (RS ⋆ RT) →\n --------------------\n Δ ⊢ Fst M ⦂ RS\n\n pair-E2 :\n Δ ⊢ M ⦂ (RS ⋆ RT) →\n --------------------\n Δ ⊢ Snd M ⦂ RT\n\n sum-I1 :\n Δ ⊢ M ⦂ RS →\n --------------------\n Δ ⊢ Inl M ⦂ (RS ⊹ RT)\n\n sum-I2 :\n Δ ⊢ N ⦂ RT →\n --------------------\n Δ ⊢ Inr N ⦂ (RS ⊹ RT)\n \n sum-E :\n Δ ⊢ L ⦂ (RS ⊹ RT) →\n (Δ , x ⦂ RS) ⊢ M ⦂ RU →\n (Δ , y ⦂ RT) ⊢ N ⦂ RV →\n RW ≡ RU × RW ≡ RV →\n --------------------\n Δ ⊢ Case L x M y N ⦂ RW\n\nglookup : ∀ {A : Set ℓ} {⟦_⟧ : A → Set}{Φ : Env A}{a : A} →\n (x ⦂ a ∈ Φ) → jEnv ⟦_⟧ Φ → ⟦ a ⟧\nglookup found (γ , _ ⦂ a) = a\nglookup (there x∈) (γ , _ ⦂ a) = glookup x∈ γ\n{-\nlookup : (x ⦂ RT ∈ Δ) → jEnv R⟦_⟧ Δ → R⟦ RT ⟧\nlookup found (γ , _ ⦂ a) = a\nlookup (there x∈) (γ , _ ⦂ a) = lookup x∈ γ\n-}\neval : Δ ⊢ M ⦂ RT → jEnv R⟦_⟧ Δ → R⟦ RT ⟧\neval (nat{n = n}) γ = n\neval (var x∈) γ = glookup x∈ γ\neval (lam ⊢M) γ = λ s → eval ⊢M (γ , _ ⦂ s)\neval (app ⊢M ⊢N) γ = eval ⊢M γ (eval ⊢N γ)\neval (pair ⊢M ⊢N) γ = (eval ⊢M γ) , (eval ⊢N γ)\neval (pair-E ⊢M ⊢N) γ with eval ⊢M γ\n... | vx , vy = eval ⊢N ((γ , _ ⦂ vx) , _ ⦂ vy)\neval (pair-E1 ⊢M) γ = proj₁ (eval ⊢M γ)\neval (pair-E2 ⊢M) γ = proj₂ (eval ⊢M γ)\neval (sum-I1 ⊢M) γ = inj₁ (eval ⊢M γ)\neval (sum-I2 ⊢N) γ = inj₂ (eval ⊢N γ)\neval (sum-E ⊢L ⊢M ⊢N (refl , refl)) γ =\n [ (λ s → eval ⊢M (γ , _ ⦂ s)) , (λ t → eval ⊢N (γ , _ ⦂ t)) ] (eval ⊢L γ)\n\n----------------------------------------------------------------------\n-- refinement types that drive the incorrectness typing\n\ndata Type : Set₁ where\n Base : (P : ℕ → Set) (p : ∀ n → Dec (P n)) → Type -- refinement\n Nat : Type\n _⇒_ _⋆_ : (S : Type) (T : Type) → Type\n _⊹_ _⊹ˡ_ _⊹ʳ_ : (S : Type) (T : Type) → Type\n\nT-Nat : Type\nT-Nat = Base (λ n → ⊤) (λ n → yes tt) -- all natural numbers\n\n-- characterize non-empty types\n\ndata ne : Type → Set where\n ne-base : ∀ {P p} → (∃P : Σ ℕ P) → ne (Base P p)\n ne-nat : ne Nat\n ne-⇒ : ∀ {S T} → ne S → ne T → ne (S ⇒ T)\n ne-⋆ : ∀ {S T} → ne S → ne T → ne (S ⋆ T)\n ne-⊹L : ∀ {S T} → ne S → ne (S ⊹ T)\n ne-⊹R : ∀ {S T} → ne T → ne (S ⊹ T)\n\n∥_∥ : Type → RawType\n∥ Base P p ∥ = Nat\n∥ Nat ∥ = Nat\n∥ S ⇒ S₁ ∥ = ∥ S ∥ ⇒ ∥ S₁ ∥\n∥ S ⋆ S₁ ∥ = ∥ S ∥ ⋆ ∥ S₁ ∥\n∥ S ⊹ S₁ ∥ = ∥ S ∥ ⊹ ∥ S₁ ∥\n∥ S ⊹ˡ S₁ ∥ = ∥ S ∥ ⊹ ∥ S₁ ∥\n∥ S ⊹ʳ S₁ ∥ = ∥ S ∥ ⊹ ∥ S₁ ∥\n\nT⟦_⟧ : Type → Set\nT⟦ Base P p ⟧ = Σ ℕ P\nT⟦ Nat ⟧ = ℕ\nT⟦ S ⇒ T ⟧ = T⟦ S ⟧ → T⟦ T ⟧\nT⟦ S ⋆ T ⟧ = T⟦ S ⟧ × T⟦ T ⟧\nT⟦ S ⊹ T ⟧ = T⟦ S ⟧ ⊎ T⟦ T ⟧\nT⟦ S ⊹ˡ T ⟧ = T⟦ S ⟧\nT⟦ S ⊹ʳ T ⟧ = T⟦ T ⟧\n\nM⟦_⟧ V⟦_⟧ : Type → (Set → Set) → Set\n\nV⟦ Base P p ⟧ m = Σ ℕ P\nV⟦ Nat ⟧ m = ℕ\nV⟦ T ⇒ T₁ ⟧ m = V⟦ T ⟧ m → M⟦ T₁ ⟧ m\nV⟦ T ⋆ T₁ ⟧ m = V⟦ T ⟧ m × V⟦ T₁ ⟧ m\nV⟦ T ⊹ T₁ ⟧ m = V⟦ T ⟧ m ⊎ V⟦ T₁ ⟧ m\nV⟦ T ⊹ˡ T₁ ⟧ m = V⟦ T ⟧ m\nV⟦ T ⊹ʳ T₁ ⟧ m = V⟦ T₁ ⟧ m\n\nM⟦ T ⟧ m = m (V⟦ T ⟧ m)\n\nE⟦_⟧ : Env Type → Env Set\nE⟦_⟧ = T⟦_⟧ ⁺\n\n∥_∥⁺ : Env Type → Env RawType\n∥_∥⁺ = ∥_∥ ⁺\n\n-- a value is a member of refinement type T\n\n_∋_ : (T : Type) → R⟦ ∥ T ∥ ⟧ → Set\nBase P p ∋ x = P x\nNat ∋ x = ⊤\n(T ⇒ T₁) ∋ f = ∀ x → T ∋ x → T₁ ∋ f x\n(T ⋆ T₁) ∋ (fst , snd) = T ∋ fst × T₁ ∋ snd\n(T ⊹ T₁) ∋ inj₁ x = T ∋ x\n(T ⊹ T₁) ∋ inj₂ y = T₁ ∋ y\n(S ⊹ˡ T) ∋ inj₁ x = S ∋ x\n(S ⊹ˡ T) ∋ inj₂ y = ⊥\n(S ⊹ʳ T) ∋ inj₁ x = ⊥\n(S ⊹ʳ T) ∋ inj₂ y = T ∋ y\n\n-- operations on predicates \n_∨_ : (P Q : ℕ → Set) → ℕ → Set\nP ∨ Q = λ n → P n ⊎ Q n\n\n_∧_ : (P Q : ℕ → Set) → ℕ → Set\nP ∧ Q = λ n → P n × Q n\n\nimplies : ∀ {P Q : ℕ → Set} → (n : ℕ) → P n → (P n ⊎ Q n)\nimplies n Pn = inj₁ Pn\n\np*q->p : ∀ {P Q : ℕ → Set} → (n : ℕ) → (P n × Q n) → P n\np*q->p n (Pn , Qn) = Pn\n\ndec-P∨Q : ∀ {P Q : ℕ → Set} → (p : ∀ n → Dec (P n)) (q : ∀ n → Dec (Q n)) → (∀ n → Dec ((P ∨ Q) n))\ndec-P∨Q p q n with p n | q n\n... | no ¬p | no ¬q = no [ ¬p , ¬q ]\n... | no ¬p | yes !q = yes (inj₂ !q)\n... | yes !p | no ¬q = yes (inj₁ !p)\n... | yes !p | yes !q = yes (inj₁ !p)\n\ndec-P∧Q : ∀ {P Q : ℕ → Set} → (p : ∀ n → Dec (P n)) (q : ∀ n → Dec (Q n)) → (∀ n → Dec ((P ∧ Q) n))\ndec-P∧Q p q n with p n | q n\n... | no ¬p | no ¬q = no (¬p ∘ proj₁)\n... | no ¬p | yes !q = no (¬p ∘ proj₁)\n... | yes !p | no ¬q = no (¬q ∘ proj₂)\n... | yes !p | yes !q = yes (!p , !q)\n\n_⊔_ _⊓_ : (S T : Type) {r : ∥ S ∥ ≡ ∥ T ∥} → Type\n\n(Base P p ⊔ Base P₁ p₁) {refl} = Base (P ∨ P₁) (dec-P∨Q p p₁)\n(Base P p ⊔ Nat) = Nat\n(Nat ⊔ Base P p) = Nat\n(Nat ⊔ Nat) = Nat\n((S ⇒ S₁) ⊔ (T ⇒ T₁)) {r} with ss⇒tt r\n... | sss , ttt = (S ⊓ T){sss} ⇒ (S₁ ⊔ T₁){ttt}\n((S ⋆ S₁) ⊔ (T ⋆ T₁)) {r} with ss⋆tt r\n... | sss , ttt = (S ⊔ T){sss} ⋆ (S₁ ⊔ T₁){ttt}\n((S ⊹ S₁) ⊔ (T ⊹ T₁)) {r} with ss⊹tt r\n... | sss , ttt = (S ⊔ T){sss} ⊹ (S₁ ⊔ T₁){ttt}\n((S ⊹ S₁) ⊔ (T ⊹ˡ T₁)) {r} with ss⊹tt r\n... | sss , ttt = (S ⊔ T){sss} ⊹ S₁\n((S ⊹ S₁) ⊔ (T ⊹ʳ T₁)) {r} with ss⊹tt r\n... | sss , ttt = S ⊹ (S₁ ⊔ T₁){ttt}\n((S ⊹ˡ S₁) ⊔ (T ⊹ T₁)) {r} with ss⊹tt r\n... | sss , ttt = ((S ⊔ T){sss}) ⊹ (S₁ ⊔ T₁){ttt}\n((S ⊹ˡ S₁) ⊔ (T ⊹ˡ T₁)) {r} with ss⊹tt r\n... | sss , ttt = ((S ⊔ T){sss}) ⊹ˡ ((S₁ ⊔ T₁){ttt})\n((S ⊹ˡ S₁) ⊔ (T ⊹ʳ T₁)) {r} = S ⊹ T₁\n((S ⊹ʳ S₁) ⊔ (T ⊹ T₁)) {r} with ss⊹tt r\n... | sss , ttt = T ⊹ ((S₁ ⊔ T₁) {ttt})\n((S ⊹ʳ S₁) ⊔ (T ⊹ˡ T₁)) {r} = T ⊹ S₁\n((S ⊹ʳ S₁) ⊔ (T ⊹ʳ T₁)) {r} with ss⊹tt r\n... | sss , ttt = (S ⊔ T) {sss} ⊹ (S₁ ⊔ T₁) {ttt}\n\nBase P p ⊓ Base P₁ p₁ = Base (P ∧ P₁) (dec-P∧Q p p₁)\nBase P p ⊓ Nat = Base P p\nNat ⊓ Base P p = Base P p\nNat ⊓ Nat = Nat\n((S ⇒ S₁) ⊓ (T ⇒ T₁)){r} with ss⇒tt r\n... | sss , ttt = (S ⊔ T){sss} ⇒ (S₁ ⊓ T₁){ttt}\n((S ⋆ S₁) ⊓ (T ⋆ T₁)){r} with ss⋆tt r\n... | sss , ttt = (S ⊓ T){sss} ⋆ (S₁ ⊓ T₁){ttt}\n((S ⊹ S₁) ⊓ (T ⊹ T₁)){r} with ss⊹tt r\n... | sss , ttt = (S ⊓ T){sss} ⊹ (S₁ ⊓ T₁){ttt}\n((S ⊹ˡ S₁) ⊓ (T ⊹ T₁)) {r} = {!!}\n((S ⊹ʳ S₁) ⊓ (T ⊹ T₁)) {r} = {!!}\n((S ⊹ S₁) ⊓ (T ⊹ˡ T₁)) {r} = {!!}\n((S ⊹ˡ S₁) ⊓ (T ⊹ˡ T₁)) {r} = {!!}\n((S ⊹ʳ S₁) ⊓ (T ⊹ˡ T₁)) {r} = {!!}\n((S ⊹ S₁) ⊓ (T ⊹ʳ T₁)) {r} = {!!}\n((S ⊹ˡ S₁) ⊓ (T ⊹ʳ T₁)) {r} = {!!}\n((S ⊹ʳ S₁) ⊓ (T ⊹ʳ T₁)) {r} = {!!}\n\nvariable\n S T U S′ T′ U′ U″ : Type\n Γ Γ₁ Γ₂ : Env Type\n P : ℕ → Set\n p : ∀ n → Dec (P n)\n A : Set ℓ\n a : A\n Φ Φ₁ Φ₂ : Env A\n\n⊔-preserves : ∀ S T {st : ∥ S ∥ ≡ ∥ T ∥} →\n ∥ (S ⊔ T){st} ∥ ≡ ∥ S ∥ × ∥ (S ⊔ T){st} ∥ ≡ ∥ T ∥\n⊓-preserves : ∀ S T {st : ∥ S ∥ ≡ ∥ T ∥} →\n ∥ (S ⊓ T){st} ∥ ≡ ∥ S ∥ × ∥ (S ⊓ T){st} ∥ ≡ ∥ T ∥\n\n⊔-preserves (Base P p) (Base P₁ p₁) {refl} = refl , refl\n⊔-preserves (Base P p) Nat {st} = refl , refl\n⊔-preserves Nat (Base P p) {st} = refl , refl\n⊔-preserves Nat Nat {st} = refl , refl\n⊔-preserves (S ⇒ S₁) (T ⇒ T₁) {st} with ss⇒tt st\n... | sss , ttt with ⊓-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st\n⊔-preserves (S ⋆ S₁) (T ⋆ T₁) {st} with ss⋆tt st\n... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st\n⊔-preserves (S ⊹ S₁) (T ⊹ T₁) {st} with ss⊹tt st\n... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st\n⊔-preserves (S ⊹ S₁) (T ⊹ˡ T₁) {st} with ss⊹tt st\n... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s = refl , st\n⊔-preserves (S ⊹ S₁) (T ⊹ʳ T₁) {st} with ss⊹tt st\n... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st\n⊔-preserves (S ⊹ˡ S₁) (T ⊹ T₁) {st} with ss⊹tt st\n... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st\n⊔-preserves (S ⊹ˡ S₁) (T ⊹ˡ T₁) {st} with ss⊹tt st\n... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st\n⊔-preserves (S ⊹ˡ S₁) (T ⊹ʳ T₁) {st} with ss⊹tt st\n... | sss , ttt rewrite sss | ttt = refl , refl\n⊔-preserves (S ⊹ʳ S₁) (T ⊹ T₁) {st} with ss⊹tt st\n... | sss , ttt rewrite sss with ⊔-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t rewrite sut=t = (Eq.sym st) , refl\n⊔-preserves (S ⊹ʳ S₁) (T ⊹ˡ T₁) {st} with ss⊹tt st\n... | sss , ttt rewrite sss = refl , st\n⊔-preserves (S ⊹ʳ S₁) (T ⊹ʳ T₁) {st} with ss⊹tt st\n... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st\n\n⊓-preserves (Base P p) (Base P₁ p₂) {st} = refl , refl\n⊓-preserves (Base P p) Nat {st} = refl , refl\n⊓-preserves Nat (Base P p) {st} = refl , refl\n⊓-preserves Nat Nat {st} = refl , refl\n⊓-preserves (S ⇒ S₁) (T ⇒ T₁) {st} with ss⇒tt st\n... | sss , ttt with ⊔-preserves S T {sss} | ⊓-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s1 , sut=t1 rewrite sut=s | sut=s1 = refl , st\n⊓-preserves (S ⋆ S₁) (T ⋆ T₁) {st} with ss⋆tt st\n... | sss , ttt with ⊓-preserves S T {sss} | ⊓-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s1 , sut=t1 rewrite sut=s | sut=s1 = refl , st\n⊓-preserves (S ⊹ S₁) (T ⊹ T₁) {st} with ss⊹tt st\n... | sss , ttt with ⊓-preserves S T {sss} | ⊓-preserves S₁ T₁ {ttt}\n... | sut=s , sut=t | sut=s1 , sut=t1 rewrite sut=s | sut=s1 = refl , st\n⊓-preserves (S ⊹ˡ S₁) (T ⊹ T₁) {st} = {!!}\n⊓-preserves (S ⊹ʳ S₁) (T ⊹ T₁) {st} = {!!}\n⊓-preserves S (T ⊹ˡ T₁) {st} = {!!}\n⊓-preserves S (T ⊹ʳ T₁) {st} = {!!}\n\n\ndata Split {A : Set ℓ} : Env A → Env A → Env A → Set ℓ where\n nil : Split · · ·\n lft : ∀ {a : A}{Γ Γ₁ Γ₂ : Env A} → Split Γ Γ₁ Γ₂ → Split (Γ , x ⦂ a) (Γ₁ , x ⦂ a) Γ₂\n rgt : ∀ {a : A}{Γ Γ₁ Γ₂ : Env A} → Split Γ Γ₁ Γ₂ → Split (Γ , x ⦂ a) Γ₁ (Γ₂ , x ⦂ a)\n\n-- subtyping\n\ndata _<:_ : Type → Type → Set where\n\n <:-refl :\n T <: T\n\n <:-base : \n (P Q : ℕ → Set) →\n {p : ∀ n → Dec (P n)} \n {q : ∀ n → Dec (Q n)}\n (p→q : ∀ n → P n → Q n) →\n Base P p <: Base Q q\n\n <:-base-nat : ∀ {p : ∀ n → Dec (P n)} →\n Base P p <: Nat\n \n <:-⇒ :\n S′ <: S →\n T <: T′ →\n (S ⇒ T) <: (S′ ⇒ T′)\n \n <:-⋆ :\n S <: S′ →\n T <: T′ →\n (S ⋆ T) <: (S′ ⋆ T′)\n\n <:-⊹ :\n S <: S′ →\n T <: T′ →\n (S ⊹ T) <: (S′ ⊹ T′)\n\n <:-⊹ˡ-⊹ :\n S <: S′ →\n (S ⊹ˡ T) <: (S′ ⊹ T)\n\n <:-⊹ʳ-⊹ :\n T <: T′ →\n (S ⊹ʳ T) <: (S ⊹ T′)\n\n-- subtyping is compatible with raw types\n\n<:-raw : S <: T → ∥ S ∥ ≡ ∥ T ∥\n<:-raw <:-refl = refl\n<:-raw (<:-base P Q p→q) = refl\n<:-raw <:-base-nat = refl\n<:-raw (<:-⇒ s<:t s<:t₁) = Eq.cong₂ _⇒_ (Eq.sym (<:-raw s<:t)) (<:-raw s<:t₁)\n<:-raw (<:-⋆ s<:t s<:t₁) = Eq.cong₂ _⋆_ (<:-raw s<:t) (<:-raw s<:t₁)\n<:-raw (<:-⊹ s<:t s<:t₁) = Eq.cong₂ _⊹_ (<:-raw s<:t) (<:-raw s<:t₁)\n<:-raw (<:-⊹ˡ-⊹ s<:t) = Eq.cong₂ _⊹_ (<:-raw s<:t) refl\n<:-raw (<:-⊹ʳ-⊹ s<:t) = Eq.cong₂ _⊹_ refl (<:-raw s<:t)\n\n<:-⊔ : ∀ S T → {c : ∥ S ∥ ≡ ∥ T ∥} → S <: (S ⊔ T){c}\n<:-⊓ : ∀ S T → {c : ∥ S ∥ ≡ ∥ T ∥} → (S ⊓ T){c} <: S\n\n<:-⊔ (Base P p) (Base P₁ p₁) {refl} = <:-base P (P ∨ P₁) implies\n<:-⊔ (Base P p) Nat = <:-base-nat\n<:-⊔ Nat (Base P p) = <:-refl\n<:-⊔ Nat Nat = <:-refl\n<:-⊔ (S ⇒ S₁) (T ⇒ T₁) {c} with ss⇒tt c\n... | c1 , c2 = <:-⇒ (<:-⊓ S T) (<:-⊔ S₁ T₁)\n<:-⊔ (S ⋆ S₁) (T ⋆ T₁) {c} with ss⋆tt c\n... | c1 , c2 = <:-⋆ (<:-⊔ S T) (<:-⊔ S₁ T₁)\n<:-⊔ (S ⊹ S₁) (T ⊹ T₁) {c} with ss⊹tt c\n... | c1 , c2 = <:-⊹ (<:-⊔ S T) (<:-⊔ S₁ T₁)\n<:-⊔ (S ⊹ S₁) (T ⊹ˡ T₁) {c} with ss⊹tt c\n... | c1 , c2 = <:-⊹ (<:-⊔ S T) <:-refl\n<:-⊔ (S ⊹ S₁) (T ⊹ʳ T₁) {c} with ss⊹tt c\n... | c1 , c2 = <:-⊹ <:-refl (<:-⊔ S₁ T₁)\n<:-⊔ (S ⊹ˡ S₁) (T ⊹ T₁) {c} with ss⊹tt c\n... | c12 = {!<:-⊹!}\n<:-⊔ (S ⊹ˡ S₁) (T ⊹ˡ T₁) = {!!}\n<:-⊔ (S ⊹ˡ S₁) (T ⊹ʳ T₁) = {!!}\n<:-⊔ (S ⊹ʳ S₁) T = {!!}\n\n\n<:-⊓ (Base P p) (Base P₁ p₁) {refl} = <:-base (P ∧ P₁) P p*q->p\n<:-⊓ (Base P p) Nat = <:-refl\n<:-⊓ Nat (Base P p) = <:-base-nat\n<:-⊓ Nat Nat = <:-refl\n<:-⊓ (S ⇒ S₁) (T ⇒ T₁) {c} with ss⇒tt c\n... | c1 , c2 = <:-⇒ (<:-⊔ S T) (<:-⊓ S₁ T₁)\n<:-⊓ (S ⋆ S₁) (T ⋆ T₁) {c} with ss⋆tt c\n... | c1 , c2 = <:-⋆ (<:-⊓ S T) (<:-⊓ S₁ T₁)\n<:-⊓ (S ⊹ S₁) (T ⊹ T₁) {c} with ss⊹tt c\n... | c1 , c2 = <:-⊹ (<:-⊓ S T) (<:-⊓ S₁ T₁)\n<:-⊓ (S ⊹ S₁) (T ⊹ˡ T₁) = {!!}\n<:-⊓ (S ⊹ S₁) (T ⊹ʳ T₁) = {!!}\n<:-⊓ (S ⊹ˡ S₁) T = {!!}\n<:-⊓ (S ⊹ʳ S₁) T = {!!}\n\n-- subtyping generates an embedding and a projection\nembed : (S <: T) → T⟦ S ⟧ → T⟦ T ⟧\nembed <:-refl s = s\nembed (<:-base P Q p→q) (s , p) = s , p→q s p\nembed <:-base-nat (s , p) = s\nembed (<:-⇒ s<:t s<:t₁) s = λ x → embed s<:t₁ (s (embed s<:t x))\nembed (<:-⋆ s<:t s<:t₁) (s , t) = (embed s<:t s) , (embed s<:t₁ t)\nembed (<:-⊹ s<:t s<:t₁) (inj₁ x) = inj₁ (embed s<:t x)\nembed (<:-⊹ s<:t s<:t₁) (inj₂ y) = inj₂ (embed s<:t₁ y)\nembed (<:-⊹ˡ-⊹ s<:t) s = inj₁ (embed s<:t s)\nembed (<:-⊹ʳ-⊹ s<:t) s = inj₂ (embed s<:t s)\n\n{- no definable\ninject : T⟦ S ⟧ → V⟦ S ⟧ Maybe\neject : V⟦ S ⟧ Maybe → Maybe T⟦ S ⟧\n\ninject {Base P p} s = s\ninject {Nat} s = s\ninject {S ⇒ S₁} s = λ x → eject{S} x >>= λ x₁ → let s₁ = s x₁ in just (inject {S₁} s₁)\ninject {S ⋆ S₁} (s , s₁) = (inject{S} s) , (inject{S₁} s₁)\ninject {S ⊹ S₁} (inj₁ x) = inj₁ (inject{S} x)\ninject {S ⊹ S₁} (inj₂ y) = inj₂ (inject{S₁} y)\ninject {S ⊹ˡ S₁} s = inject{S} s\ninject {S ⊹ʳ S₁} s = inject{S₁} s\n\neject {Base P p} s = {!!}\neject {Nat} s = {!!}\neject {S ⇒ S₁} s = just (λ x → {!!})\neject {S ⋆ S₁} s = {!!}\neject {S ⊹ S₁} s = {!!}\neject {S ⊹ˡ S₁} s = {!!}\neject {S ⊹ʳ S₁} s = {!!}\n-}\n\nproject : (S <: T) → V⟦ T ⟧ Maybe → M⟦ S ⟧ Maybe\nproject <:-refl t = just t\nproject (<:-base P Q {p = p} p→q) (t , qt)\n with p t\n... | no ¬p = nothing\n... | yes p₁ = just (t , p₁)\nproject (<:-base-nat{p = p}) t\n with p t\n... | no ¬p = nothing\n... | yes p₁ = just (t , p₁)\nproject (<:-⇒ s<:t s<:t₁) t = just λ s → project s<:t s >>= t >>= project s<:t₁\nproject (<:-⋆ s<:t s<:t₁) (s , t) = project s<:t s >>= λ x → project s<:t₁ t >>= λ x₁ → just (x , x₁)\nproject (<:-⊹ s<:t s<:t₁) (inj₁ x) = Data.Maybe.map inj₁ (project s<:t x)\nproject (<:-⊹ s<:t s<:t₁) (inj₂ y) = Data.Maybe.map inj₂ (project s<:t₁ y)\nproject (<:-⊹ˡ-⊹ s<:t) (inj₁ x) = project s<:t x\nproject (<:-⊹ˡ-⊹ s<:t) (inj₂ y) = nothing\nproject (<:-⊹ʳ-⊹ s<:t) (inj₁ x) = nothing\nproject (<:-⊹ʳ-⊹ s<:t) (inj₂ y) = project s<:t y\n\nsplit-sym : Split Φ Φ₁ Φ₂ → Split Φ Φ₂ Φ₁\nsplit-sym nil = nil\nsplit-sym (lft sp) = rgt (split-sym sp)\nsplit-sym (rgt sp) = lft (split-sym sp)\n\nsplit-map : ∀ {A : Set ℓ}{B : Set ℓ′}{Φ Φ₁ Φ₂ : Env A} →\n {f : A → B} → Split Φ Φ₁ Φ₂ → Split ((f ⁺) Φ) ((f ⁺) Φ₁) ((f ⁺) Φ₂)\nsplit-map nil = nil\nsplit-map (lft sp) = lft (split-map sp)\nsplit-map (rgt sp) = rgt (split-map sp)\n\nweaken-∈ : Split Φ Φ₁ Φ₂ → x ⦂ a ∈ Φ₁ → x ⦂ a ∈ Φ\nweaken-∈ (lft sp) found = found\nweaken-∈ (rgt sp) found = there (weaken-∈ sp found)\nweaken-∈ (lft sp) (there x∈) = there (weaken-∈ sp x∈)\nweaken-∈ (rgt sp) (there x∈) = there (weaken-∈ sp (there x∈))\n\nweaken : Split Δ Δ₁ Δ₂ → Δ₁ ⊢ M ⦂ RT → Δ ⊢ M ⦂ RT\nweaken sp (nat) = nat\nweaken sp (var x∈) = var (weaken-∈ sp x∈)\nweaken sp (lam ⊢M) = lam (weaken (lft sp) ⊢M)\nweaken sp (app ⊢M ⊢N) = app (weaken sp ⊢M) (weaken sp ⊢N)\nweaken sp (pair ⊢M ⊢N) = pair (weaken sp ⊢M) (weaken sp ⊢N)\nweaken sp (pair-E ⊢M ⊢N) = pair-E (weaken sp ⊢M) (weaken (lft (lft sp)) ⊢N)\nweaken sp (pair-E1 ⊢M) = pair-E1 (weaken sp ⊢M)\nweaken sp (pair-E2 ⊢M) = pair-E2 (weaken sp ⊢M)\nweaken sp (sum-I1 ⊢M) = sum-I1 (weaken sp ⊢M)\nweaken sp (sum-I2 ⊢N) = sum-I2 (weaken sp ⊢N)\nweaken sp (sum-E ⊢L ⊢M ⊢N (RT=RU , RT=RV)) =\n sum-E (weaken sp ⊢L) (weaken (lft sp) ⊢M) (weaken (lft sp) ⊢N) (RT=RU , RT=RV)\n\n-- incorrectness typing\n\n-- a positive type contains refinements only in positive positions\n\nmutual\n data Pos : Type → Set where\n Pos-Base : Pos (Base P p)\n Pos-Nat : Pos Nat\n Pos-⇒ : Neg S → Pos T → Pos (S ⇒ T)\n Pos-⋆ : Pos S → Pos T → Pos (S ⋆ T)\n Pos-⊹ : Pos S → Pos T → Pos (S ⊹ T)\n Pos-⊹ˡ : Pos S → Pos (S ⊹ˡ T)\n Pos-⊹ʳ : Pos T → Pos (S ⊹ʳ T)\n\n data Neg : Type → Set where\n Neg-Nat : Neg Nat\n Neg-⇒ : Pos S → Neg T → Neg (S ⇒ T)\n Neg-⋆ : Neg S → Neg T → Neg (S ⋆ T)\n Neg-⊹ : Neg S → Neg T → Neg (S ⊹ T)\n\npos-unique : ∀ T → (pos pos' : Pos T) → pos ≡ pos'\nneg-unique : ∀ T → (neg neg' : Neg T) → neg ≡ neg'\n\npos-unique (Base P p) Pos-Base Pos-Base = refl\npos-unique Nat Pos-Nat Pos-Nat = refl\npos-unique (T ⇒ T₁) (Pos-⇒ x pos) (Pos-⇒ x₁ pos') rewrite neg-unique T x x₁ | pos-unique T₁ pos pos' = refl\npos-unique (T ⋆ T₁) (Pos-⋆ pos pos₁) (Pos-⋆ pos' pos'') rewrite pos-unique T pos pos' | pos-unique T₁ pos₁ pos'' = refl\npos-unique (T ⊹ T₁) (Pos-⊹ pos pos₁) (Pos-⊹ pos' pos'') rewrite pos-unique T pos pos' | pos-unique T₁ pos₁ pos'' = refl\npos-unique (T ⊹ˡ T₁) (Pos-⊹ˡ pos) (Pos-⊹ˡ pos') rewrite pos-unique T pos pos' = refl\npos-unique (T ⊹ʳ T₁) (Pos-⊹ʳ pos) (Pos-⊹ʳ pos') rewrite pos-unique T₁ pos pos' = refl\n--etc\nneg-unique T neg neg' = {!!}\n\nmodule positive-restricted where\n toRaw : ∀ T → Pos T → T⟦ T ⟧ → R⟦ ∥ T ∥ ⟧\n fromRaw : ∀ T → Neg T → R⟦ ∥ T ∥ ⟧ → T⟦ T ⟧\n\n toRaw (Base P p) Pos-Base (n , pn) = n\n toRaw Nat Pos-Nat t = t\n toRaw (T ⇒ T₁) (Pos-⇒ neg pos₁) t = toRaw T₁ pos₁ ∘ t ∘ fromRaw T neg\n toRaw (T ⋆ T₁) (Pos-⋆ pos pos₁) (t , t₁) = toRaw T pos t , (toRaw T₁ pos₁ t₁)\n toRaw (T ⊹ T₁) (Pos-⊹ pos pos₁) (inj₁ x) = inj₁ (toRaw T pos x)\n toRaw (T ⊹ T₁) (Pos-⊹ pos pos₁) (inj₂ y) = inj₂ (toRaw T₁ pos₁ y)\n toRaw (S ⊹ˡ T) (Pos-⊹ˡ pos) x = inj₁ (toRaw S pos x)\n toRaw (S ⊹ʳ T) (Pos-⊹ʳ pos) y = inj₂ (toRaw T pos y)\n\n fromRaw (Base P p) () r\n fromRaw Nat Neg-Nat r = r\n fromRaw (T ⇒ T₁) (Neg-⇒ pos neg) r = fromRaw T₁ neg ∘ r ∘ toRaw T pos\n fromRaw (T ⋆ T₁) (Neg-⋆ neg neg₁) (r , r₁) = fromRaw T neg r , fromRaw T₁ neg₁ r₁\n fromRaw (T ⊹ T₁) (Neg-⊹ neg neg₁) (inj₁ x) = inj₁ (fromRaw T neg x)\n fromRaw (T ⊹ T₁) (Neg-⊹ neg neg₁) (inj₂ y) = inj₂ (fromRaw T₁ neg₁ y)\n \n toRawEnv : AllEnv Type Pos Γ → jEnv T⟦_⟧ Γ → jEnv R⟦_⟧ ∥ Γ ∥⁺\n toRawEnv{·} posΓ · = ·\n toRawEnv{Γ , _ ⦂ T} (posΓ , x₁) (γ , x ⦂ a) = toRawEnv{Γ} posΓ γ , x ⦂ toRaw T x₁ a\n\n{-\n-- attempt to map type (interpretation) to corresponding raw type (interpretation)\n-- * must be monadic because of refinement\n-- * fails at function types\nmodule monadic where\n toRaw : ∀ T → T⟦ T ⟧ → Maybe R⟦ ∥ T ∥ ⟧\n fromRaw : ∀ T → R⟦ ∥ T ∥ ⟧ → Maybe T⟦ T ⟧\n\n toRaw (Base P p) (n , Pn) = just n\n toRaw Nat n = just n\n toRaw (T ⇒ T₁) t = {!!}\n toRaw (T ⋆ T₁) (t , t₁) = toRaw T t >>= (λ r → toRaw T₁ t₁ >>= (λ r₁ → just (r , r₁)))\n toRaw (T ⊹ T₁) (inj₁ x) = Data.Maybe.map inj₁ (toRaw T x)\n toRaw (T ⊹ T₁) (inj₂ y) = Data.Maybe.map inj₂ (toRaw T₁ y)\n\n fromRaw (Base P p) r with p r\n ... | no ¬p = nothing\n ... | yes pr = just (r , pr)\n fromRaw Nat r = just r\n fromRaw (T ⇒ T₁) r = {!!}\n fromRaw (T ⋆ T₁) (r , r₁) = fromRaw T r >>= (λ t → fromRaw T₁ r₁ >>= (λ t₁ → just (t , t₁)))\n fromRaw (T ⊹ T₁) (inj₁ x) = Data.Maybe.map inj₁ (fromRaw T x)\n fromRaw (T ⊹ T₁) (inj₂ y) = Data.Maybe.map inj₂ (fromRaw T₁ y)\n-}\n\ncorr-sp : Split Γ Γ₁ Γ₂ → Split ∥ Γ ∥⁺ ∥ Γ₁ ∥⁺ ∥ Γ₂ ∥⁺\ncorr-sp nil = nil\ncorr-sp (lft sp) = lft (corr-sp sp)\ncorr-sp (rgt sp) = rgt (corr-sp sp)\n\npostulate\n ext : ∀ {A B : Set}{f g : A → B} → (∀ x → f x ≡ g x) → f ≡ g\n\nunsplit-env : ∀ {A : Set ℓ} {⟦_⟧ : A → Set}{Φ Φ₁ Φ₂ : Env A}→\n Split Φ Φ₁ Φ₂ → jEnv ⟦_⟧ Φ₁ → jEnv ⟦_⟧ Φ₂ → jEnv ⟦_⟧ Φ\nunsplit-env nil γ₁ γ₂ = ·\nunsplit-env (lft sp) (γ₁ , _ ⦂ a) γ₂ = (unsplit-env sp γ₁ γ₂) , _ ⦂ a\nunsplit-env (rgt sp) γ₁ (γ₂ , _ ⦂ a) = (unsplit-env sp γ₁ γ₂) , _ ⦂ a\n\nunsplit-split : ∀ {A : Set ℓ} {⟦_⟧ : A → Set}{Φ Φ₁ Φ₂ : Env A} →\n (sp : Split Φ Φ₁ Φ₂) (γ₁ : jEnv ⟦_⟧ Φ₁) (γ₂ : jEnv ⟦_⟧ Φ₂) →\n unsplit-env sp γ₁ γ₂ ≡ unsplit-env (split-sym sp) γ₂ γ₁\nunsplit-split nil γ₁ γ₂ = refl\nunsplit-split (lft sp) (γ₁ , _ ⦂ a) γ₂ rewrite unsplit-split sp γ₁ γ₂ = refl\nunsplit-split (rgt sp) γ₁ (γ₂ , _ ⦂ a) rewrite unsplit-split sp γ₁ γ₂ = refl\n\nlookup-unsplit : ∀ {A : Set ℓ} {⟦_⟧ : A → Set}{Φ Φ₁ Φ₂ : Env A}{a : A} →\n (sp : Split Φ Φ₁ Φ₂) (γ₁ : jEnv ⟦_⟧ Φ₁) (γ₂ : jEnv ⟦_⟧ Φ₂) →\n (x∈ : x ⦂ a ∈ Φ₁) →\n glookup (weaken-∈ sp x∈) (unsplit-env sp γ₁ γ₂) ≡ glookup x∈ γ₁\nlookup-unsplit (lft sp) (γ₁ , _ ⦂ a) γ₂ found = refl\nlookup-unsplit (rgt sp) γ₁ (γ₂ , _ ⦂ a) found = lookup-unsplit sp γ₁ γ₂ found\nlookup-unsplit (lft sp) (γ₁ , _ ⦂ a) γ₂ (there x∈) = lookup-unsplit sp γ₁ γ₂ x∈\nlookup-unsplit (rgt sp) γ₁ (γ₂ , _ ⦂ a) (there x∈) = lookup-unsplit sp γ₁ γ₂ (there x∈)\n\nopen positive-restricted\neval-unsplit' : (sp : Split Γ Γ₁ Γ₂) (γ₁ : jEnv T⟦_⟧ Γ₁) (γ₂ : jEnv T⟦_⟧ Γ₂) →\n (posΓ₁ : AllEnv Type Pos Γ₁) (posΓ₂ : AllEnv Type Pos Γ₂) →\n (⊢M : ∥ Γ₁ ∥⁺ ⊢ M ⦂ RT) →\n eval (weaken (corr-sp sp) ⊢M) (unsplit-env (corr-sp sp) (toRawEnv posΓ₁ γ₁) (toRawEnv posΓ₂ γ₂)) ≡ eval ⊢M (toRawEnv posΓ₁ γ₁)\neval-unsplit' sp γ₁ γ₂ posΓ₁ posΓ₂ ⊢M = {!!}\n{-\n (eval (weaken (corr-sp sp) (corr ÷M))\n (toRawEnv posΓ (unsplit-env sp γ₁ γ₂)))\n-}\n\neval-unsplit : (sp : Split Δ Δ₁ Δ₂) (γ₁ : jEnv R⟦_⟧ Δ₁) (γ₂ : jEnv R⟦_⟧ Δ₂) →\n (⊢M : Δ₁ ⊢ M ⦂ RT) →\n eval (weaken sp ⊢M) (unsplit-env sp γ₁ γ₂) ≡ eval ⊢M γ₁\neval-unsplit sp γ₁ γ₂ (nat)= refl\neval-unsplit sp γ₁ γ₂ (var x∈) = lookup-unsplit sp γ₁ γ₂ x∈\neval-unsplit sp γ₁ γ₂ (lam ⊢M) = ext (λ s → eval-unsplit (lft sp) (γ₁ , _ ⦂ s) γ₂ ⊢M)\neval-unsplit sp γ₁ γ₂ (app ⊢M ⊢M₁) \n rewrite eval-unsplit sp γ₁ γ₂ ⊢M | eval-unsplit sp γ₁ γ₂ ⊢M₁ = refl\neval-unsplit sp γ₁ γ₂ (pair ⊢M ⊢M₁)\n rewrite eval-unsplit sp γ₁ γ₂ ⊢M | eval-unsplit sp γ₁ γ₂ ⊢M₁ = refl\neval-unsplit sp γ₁ γ₂ (pair-E ⊢M ⊢N)\n rewrite eval-unsplit sp γ₁ γ₂ ⊢M = eval-unsplit (lft (lft sp)) ((γ₁ , _ ⦂ _) , _ ⦂ _) γ₂ ⊢N\neval-unsplit sp γ₁ γ₂ (pair-E1 ⊢M)\n rewrite eval-unsplit sp γ₁ γ₂ ⊢M = refl\neval-unsplit sp γ₁ γ₂ (pair-E2 ⊢M)\n rewrite eval-unsplit sp γ₁ γ₂ ⊢M = refl\neval-unsplit sp γ₁ γ₂ (sum-I1 ⊢M) \n rewrite eval-unsplit sp γ₁ γ₂ ⊢M = refl\neval-unsplit sp γ₁ γ₂ (sum-I2 ⊢N)\n rewrite eval-unsplit sp γ₁ γ₂ ⊢N = refl\neval-unsplit sp γ₁ γ₂ (sum-E ⊢L ⊢M ⊢N (refl , refl)) \n rewrite eval-unsplit sp γ₁ γ₂ ⊢L\n | ext (λ s → eval-unsplit (lft sp) (γ₁ , _ ⦂ s) γ₂ ⊢M)\n | ext (λ t → eval-unsplit (lft sp) (γ₁ , _ ⦂ t) γ₂ ⊢N)\n = refl\n\nmodule rule-by-rule where\n\n open positive-restricted\n open Eq.≡-Reasoning\n\n data _⊢_÷_ : Env Type → Expr → Type → Set₁ where\n\n nat' :\n --------------------\n · ⊢ Nat n ÷ Base (_≡_ n) (_≟_ n)\n\n var' :\n ( · , x ⦂ T) ⊢ Var x ÷ T\n\n pair-I :\n Split Γ Γ₁ Γ₂ →\n Γ₁ ⊢ M ÷ S →\n Γ₂ ⊢ N ÷ T →\n --------------------\n Γ ⊢ Pair M N ÷ (S ⋆ T)\n\n sum-I1 :\n Γ ⊢ M ÷ S →\n --------------------\n Γ ⊢ Inl M ÷ (S ⊹ˡ T)\n\n sum-I2 :\n Γ ⊢ M ÷ T →\n --------------------\n Γ ⊢ Inr M ÷ (S ⊹ʳ T)\n\n {- perhaps this rule should involve splitting between L and M,N -}\n sum-Case :\n Split Γ Γ₁ Γ₂ →\n Γ₁ ⊢ L ÷ (S ⊹ T) →\n (Γ₂ , x ⦂ S) ⊢ M ÷ (U ⊹ˡ U′) →\n (Γ₂ , y ⦂ T) ⊢ N ÷ (U ⊹ʳ U′) →\n ------------------------------\n Γ ⊢ Case L x M y N ÷ (U ⊹ U′)\n\n corr : Γ ⊢ M ÷ T → ∥ Γ ∥⁺ ⊢ M ⦂ ∥ T ∥\n corr nat' =\n nat\n corr var' =\n var found\n corr (pair-I sp ÷M ÷N) =\n pair (weaken (corr-sp sp) (corr ÷M)) (weaken (split-sym (corr-sp sp)) (corr ÷N))\n corr (sum-I1 ÷M) = \n sum-I1 (corr ÷M)\n corr (sum-I2 ÷M) =\n sum-I2 (corr ÷M)\n corr (sum-Case sp ÷L ÷M ÷N) =\n sum-E (weaken (corr-sp sp) (corr ÷L))\n (weaken (split-sym (corr-sp (rgt sp))) (corr ÷M))\n (weaken (split-sym (corr-sp (rgt sp))) (corr ÷N)) \n (refl , refl) \n\n applySplit : {A : Set ℓ}{P : A → Set}{Θ Θ₁ Θ₂ : Env A} →\n Split Θ Θ₁ Θ₂ → AllEnv A P Θ → AllEnv A P Θ₁ × AllEnv A P Θ₂\n applySplit nil · = · , ·\n applySplit (lft sp) (ae , x)\n with applySplit sp ae\n ... | ae1 , ae2 = (ae1 , x) , ae2\n applySplit (rgt sp) (ae , x)\n with applySplit sp ae\n ... | ae1 , ae2 = ae1 , (ae2 , x)\n\n lave' :\n (÷M : Γ ⊢ M ÷ T) →\n (posT : Pos T) →\n (posΓ : AllEnv Type Pos Γ) →\n ∀ (t : T⟦ T ⟧) →\n ∃ λ (γ : jEnv T⟦_⟧ Γ) →\n eval (corr ÷M) (toRawEnv posΓ γ) ≡ toRaw T posT t\n lave' nat' Pos-Base posΓ (n , refl) = · , refl\n lave' var' posT (· , posT') t rewrite pos-unique _ posT posT' = (· , _ ⦂ t) , refl\n lave' (pair-I x ÷M ÷M₁) posT posΓ t = {!!}\n lave' (sum-I1 ÷M) (Pos-⊹ˡ posT) posΓ t\n with lave' ÷M posT posΓ t\n ... | γ , ih = γ , Eq.cong inj₁ ih\n lave' (sum-I2 ÷M) (Pos-⊹ʳ posT) posΓ t\n with lave' ÷M posT posΓ t\n ... | γ , ih = γ , Eq.cong inj₂ ih\n lave' (sum-Case sp ÷M ÷M₁ ÷M₂) (Pos-⊹ posT posT₁) posΓ (inj₁ x)\n with applySplit sp posΓ\n ... | posΓ₁ , posΓ₂\n with lave' ÷M₁ (Pos-⊹ˡ posT) (posΓ₂ , {!!}) x\n ... | (γ₂ , _ ⦂ s) , ih₂\n with lave' ÷M (Pos-⊹ {!!} {!!}) posΓ₁ (inj₁ s)\n ... | γ₁ , ih₁ =\n let ih₂′ = {!eval-unsplit' sp γ₁ γ₂ posΓ₁ posΓ₂ (corr ÷M) !} in \n (unsplit-env sp γ₁ γ₂) , {!!}\n lave' (sum-Case sp ÷M ÷M₁ ÷M₂) (Pos-⊹ posT posT₁) posΓ (inj₂ y) = {!!}\n\n lave :\n (÷M : Γ ⊢ M ÷ T) →\n (pos : Pos T) → \n ∀ (t : T⟦ T ⟧) →\n ∃ λ (γ : jEnv R⟦_⟧ ∥ Γ ∥⁺) →\n eval (corr ÷M) γ ≡ toRaw T pos t\n lave nat' Pos-Base (n , pn) = · , pn\n lave var' pos t = (· , _ ⦂ toRaw _ pos t) , refl\n lave (pair-I sp ÷M ÷N) (Pos-⋆ pos₁ pos₂) (t₁ , t₂) \n with lave ÷M pos₁ t₁ | lave ÷N pos₂ t₂\n ... | γ₁ , ih₁ | γ₂ , ih₂ =\n (unsplit-env (corr-sp sp) γ₁ γ₂) , \n Eq.cong₂ _,_ \n (begin (eval (weaken (corr-sp sp) (corr ÷M)) (unsplit-env (corr-sp sp) γ₁ γ₂) \n ≡⟨ eval-unsplit (corr-sp sp) γ₁ γ₂ (corr ÷M) ⟩\n ih₁))\n (begin (eval (weaken (split-sym (corr-sp sp)) (corr ÷N)) (unsplit-env (corr-sp sp) γ₁ γ₂)\n ≡⟨ Eq.cong (eval (weaken (split-sym (corr-sp sp)) (corr ÷N))) (unsplit-split (corr-sp sp) γ₁ γ₂) ⟩\n eval (weaken (split-sym (corr-sp sp)) (corr ÷N)) (unsplit-env (split-sym (corr-sp sp)) γ₂ γ₁)\n ≡⟨ eval-unsplit (split-sym (corr-sp sp)) γ₂ γ₁ (corr ÷N) ⟩\n ih₂))\n lave (sum-I1 ÷M) (Pos-⊹ˡ pos) t\n with lave ÷M pos t\n ... | γ , ih = γ , Eq.cong inj₁ ih\n lave (sum-I2 ÷M) (Pos-⊹ʳ pos) t\n with lave ÷M pos t\n ... | γ , ih = γ , Eq.cong inj₂ ih\n lave (sum-Case sp ÷L ÷M ÷N) (Pos-⊹ p p₁) (inj₁ x)\n with lave ÷M (Pos-⊹ˡ p) x\n ... | (γ₂ , _ ⦂ a) , ih₂\n with lave ÷L {!!} (inj₁ {!!})\n ... | γ₁ , ih₁ = {!!}\n lave (sum-Case sp ÷L ÷M ÷N) (Pos-⊹ p p₁) (inj₂ y) = {!!}\n\ndata _⊢_÷_ : Env Type → Expr → Type → Set₁ where\n\n nat' :\n --------------------\n · ⊢ Nat n ÷ Base (_≡_ n) λ n₁ → n ≟ n₁\n\n var1 :\n ( · , x ⦂ T) ⊢ Var x ÷ T\n\n{-\n var :\n x ⦂ T ∈ Γ →\n --------------------\n Γ ⊢ Var x ÷ T\n-}\n\n lam :\n (· , x ⦂ S) ⊢ M ÷ T →\n --------------------\n · ⊢ Lam x M ÷ (S ⇒ T)\n\n pair :\n Split Γ Γ₁ Γ₂ →\n Γ₁ ⊢ M ÷ S →\n Γ₂ ⊢ N ÷ T →\n --------------------\n Γ ⊢ Pair M N ÷ (S ⋆ T)\n\n pair-E1 :\n Γ ⊢ M ÷ (S ⋆ T) →\n --------------------\n Γ ⊢ Fst M ÷ S\n\n pair-E2 :\n Γ ⊢ M ÷ (S ⋆ T) →\n --------------------\n Γ ⊢ Snd M ÷ T\n\n sum-E :\n Split Γ Γ₁ Γ₂ →\n Γ₁ ⊢ L ÷ (S ⊹ T) →\n (Γ₂ , x ⦂ S) ⊢ M ÷ U →\n (Γ₂ , y ⦂ T) ⊢ N ÷ U →\n --------------------\n Γ ⊢ Case L x M y N ÷ U\n\n sum-E′ : ∀ {ru′=ru″} →\n Split Γ Γ₁ Γ₂ →\n Γ₁ ⊢ L ÷ (S ⊹ T) →\n (Γ₂ , x ⦂ S) ⊢ M ÷ U′ →\n (Γ₂ , y ⦂ T) ⊢ N ÷ U″ →\n U ≡ (U′ ⊔ U″){ru′=ru″} →\n --------------------\n Γ ⊢ Case L x M y N ÷ U\n\n{-\n `sub` :\n Γ ⊢ M ÷ S →\n T <: S → \n --------------------\n Γ ⊢ M ÷ T\n-}\n\n\n\n\ncorr : Γ ⊢ M ÷ T → ∥ Γ ∥⁺ ⊢ M ⦂ ∥ T ∥\ncorr (nat') = nat\ncorr var1 = var found\n-- corr (var x) = var x\ncorr (lam ⊢M) = lam (corr ⊢M)\ncorr (pair-E1 ÷M) = pair-E1 (corr ÷M)\ncorr (pair-E2 ÷M) = pair-E2 (corr ÷M)\ncorr (pair sp ÷M ÷N) =\n pair (weaken (corr-sp sp) (corr ÷M)) (weaken (split-sym (corr-sp sp)) (corr ÷N))\ncorr (sum-E sp ÷L ÷M ÷N) =\n sum-E (weaken (corr-sp sp) (corr ÷L))\n (weaken (lft (split-sym (corr-sp sp))) (corr ÷M))\n (weaken (lft (split-sym (corr-sp sp))) (corr ÷N))\n (refl , refl)\ncorr (sum-E′ {S = S}{T = T}{U′ = U′}{U″ = U″}{U = U}{ru′=ru″ = ru′=ru″} sp ÷L ÷M ÷N refl) =\n sum-E (weaken (corr-sp sp) (corr ÷L))\n (weaken (lft (split-sym (corr-sp sp))) (corr ÷M))\n (weaken (lft (split-sym (corr-sp sp))) (corr ÷N))\n (⊔-preserves U′ U″)\n\n-- pick one element of a type to demonstrate non-emptiness\none : ∀ (T : Type) {ne-T : ne T} → T⟦ T ⟧\none (Base P p) {ne-base ∃P} = ∃P\none Nat = zero\none (T ⇒ T₁) {ne-⇒ ne-T ne-T₁} = λ x → one T₁ {ne-T₁}\none (T ⋆ T₁) {ne-⋆ ne-T ne-T₁} = (one T {ne-T}) , (one T₁ {ne-T₁})\none (T ⊹ T₁) {ne-⊹L ne-T} = inj₁ (one T {ne-T})\none (T ⊹ T₁) {ne-⊹R ne-T₁} = inj₂ (one T₁ {ne-T₁})\n\n{- not needed\nmany : iEnv E⟦ Γ ⟧\nmany {·} = ·\nmany {Γ , x ⦂ T} = many , x ⦂ one T\n\ngen : (x∈ : x ⦂ T ∈ Γ) (t : T⟦ T ⟧) → iEnv E⟦ Γ ⟧\ngen found t = many , _ ⦂ t\ngen (there x∈) t = (gen x∈ t) , _ ⦂ one {!!}\n\nlookup-gen : (x∈ : x ⦂ T ∈ Γ) (t : T⟦ T ⟧) → lookup x∈ (gen x∈ t) ≡ t\nlookup-gen found t = refl\nlookup-gen (there x∈) t = lookup-gen x∈ t\n-}\n\n\n{-\n-- soundness of the incorrectness rules\nlave :\n (÷M : Γ ⊢ M ÷ T) →\n ∀ (t : T⟦ T ⟧) →\n ∃ λ (γ : iEnv E⟦ Γ ⟧) →\n eval (corr ÷M) γ ≡ t\n\nlave nat' (n , refl) = · , refl\n\nlave var1 t = (· , _ ⦂ t) , refl\n-- lave (var x∈) t = (gen x∈ t) , lookup-gen x∈ t\nlave (lam{x = x}{S = S} ÷M) t = · , ext aux\n where\n aux : (s : T⟦ S ⟧) → eval (corr ÷M) (· , x ⦂ s) ≡ t s\n aux s with lave ÷M (t s)\n ... | (· , .x ⦂ a) , snd = {!!} -- impossible to complete!\n\nlave (pair-E1 ÷M) t with lave ÷M (t , one {!!})\n... | γ , ih = γ , Eq.cong proj₁ ih\nlave (pair-E2 ÷M) t with lave ÷M (one {!!} , t)\n... | γ , ih = γ , Eq.cong proj₂ ih\n\nlave (pair sp ÷M ÷N) (s , t) with lave ÷M s | lave ÷N t\n... | γ₁ , ih-M | γ₂ , ih-N =\n unsplit-env sp γ₁ γ₂ ,\n Eq.cong₂ _,_ (Eq.trans (eval-unsplit sp γ₁ γ₂ (corr ÷M)) ih-M)\n (begin eval (weaken (split-sym sp) (corr ÷N)) (unsplit-env sp γ₁ γ₂) \n ≡⟨ Eq.cong (eval (weaken (split-sym sp) (corr ÷N))) (unsplit-split sp γ₁ γ₂) ⟩\n eval (weaken (split-sym sp) (corr ÷N)) (unsplit-env (split-sym sp) γ₂ γ₁)\n ≡⟨ eval-unsplit (split-sym sp) γ₂ γ₁ (corr ÷N) ⟩\n ih-N)\n\n-- works, but unsatisfactory!\n-- this proof uses only one branch of the case\n-- this choice is possible because both branches ÷M and ÷N have the same type\n-- in general, U could be the union of the types of ÷M and ÷N\nlave (sum-E{S = S}{T = T}{U = U} sp ÷L ÷M ÷N) u\n with lave ÷M u | lave ÷N u\n... | (γ₁ , x ⦂ s) , ih-M | (γ₂ , y ⦂ t) , ih-N\n with lave ÷L (inj₁ s)\n... | γ₀ , ih-L\n =\n unsplit-env sp γ₀ γ₁ ,\n (begin [\n (λ s₁ →\n eval (weaken (lft (split-sym sp)) (corr ÷M))\n (unsplit-env sp γ₀ γ₁ , x ⦂ s₁))\n ,\n (λ t₁ →\n eval (weaken (lft (split-sym sp)) (corr ÷N))\n (unsplit-env sp γ₀ γ₁ , y ⦂ t₁))\n ]\n (eval (weaken sp (corr ÷L)) (unsplit-env sp γ₀ γ₁))\n ≡⟨ Eq.cong [\n (λ s₁ →\n eval (weaken (lft (split-sym sp)) (corr ÷M))\n (unsplit-env sp γ₀ γ₁ , x ⦂ s₁))\n ,\n (λ t₁ →\n eval (weaken (lft (split-sym sp)) (corr ÷N))\n (unsplit-env sp γ₀ γ₁ , y ⦂ t₁))\n ] (eval-unsplit sp γ₀ γ₁ (corr ÷L)) ⟩ \n [\n (λ s₁ →\n eval (weaken (lft (split-sym sp)) (corr ÷M))\n (unsplit-env sp γ₀ γ₁ , x ⦂ s₁))\n ,\n (λ t₁ →\n eval (weaken (lft (split-sym sp)) (corr ÷N))\n (unsplit-env sp γ₀ γ₁ , y ⦂ t₁))\n ]\n (eval (corr ÷L) γ₀) \n ≡⟨ Eq.cong\n [\n (λ s₁ →\n eval (weaken (lft (split-sym sp)) (corr ÷M))\n (unsplit-env sp γ₀ γ₁ , x ⦂ s₁))\n ,\n (λ t₁ →\n eval (weaken (lft (split-sym sp)) (corr ÷N))\n (unsplit-env sp γ₀ γ₁ , y ⦂ t₁))\n ]\n ih-L ⟩\n eval (weaken (lft (split-sym sp)) (corr ÷M)) (unsplit-env sp γ₀ γ₁ , x ⦂ s) \n ≡⟨ Eq.cong (λ γ → eval (weaken (lft (split-sym sp)) (corr ÷M)) (γ , x ⦂ s)) (unsplit-split sp γ₀ γ₁) ⟩\n eval (weaken (lft (split-sym sp)) (corr ÷M)) (unsplit-env (split-sym sp) γ₁ γ₀ , x ⦂ s)\n ≡⟨⟩\n eval (weaken (lft (split-sym sp)) (corr ÷M)) (unsplit-env (lft (split-sym sp)) (γ₁ , x ⦂ s) γ₀)\n ≡⟨ eval-unsplit (lft (split-sym sp)) (γ₁ , x ⦂ s) γ₀ (corr ÷M) ⟩\n ih-M)\n\nlave (sum-E′{S = S}{T = T}{U = U} sp ÷L ÷M ÷N uuu) u = {!!}\n-}\n\n-- unused stuff\n\n{- unused - needed?\nrecord _←_ (A B : Set) : Set where\n field\n func : A → B\n back : ∀ (b : B) → ∃ λ (a : A) → func a ≡ b\n\nopen _←_\n-}\n", "meta": {"hexsha": "fa99160e962b7be48717e73c349e8a47275ee48f", "size": 34925, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/RawSemantics.agda", "max_stars_repo_name": "proglang/incorrectness", "max_stars_repo_head_hexsha": "91a5ff5267089e6ed0d2f6d3998633ba1842b397", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-17T19:13:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-17T19:13:13.000Z", "max_issues_repo_path": "src/RawSemantics.agda", "max_issues_repo_name": "proglang/incorrectness", "max_issues_repo_head_hexsha": "91a5ff5267089e6ed0d2f6d3998633ba1842b397", "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": "src/RawSemantics.agda", "max_forks_repo_name": "proglang/incorrectness", "max_forks_repo_head_hexsha": "91a5ff5267089e6ed0d2f6d3998633ba1842b397", "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": 32.0119156737, "max_line_length": 128, "alphanum_fraction": 0.4770508232, "num_tokens": 17453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.6187804337438501, "lm_q1q2_score": 0.3828892251842272}} {"text": "{-# OPTIONS --safe #-}\n{-\nConstructions of \"sets\" in the cumulative hierarchy. Including:\n- the empty set\n- unions\n- ω\n- replacement\n- separation\n-}\n\nmodule Cubical.HITs.CumulativeHierarchy.Constructions where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Structure\nopen import Cubical.Functions.Embedding\nopen import Cubical.Functions.Logic as L\nopen import Cubical.Data.Sum hiding (elim)\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Nat hiding (elim)\nopen import Cubical.Data.Sum as ⊎ using (_⊎_)\nopen import Cubical.Data.Bool\nopen import Cubical.Data.Unit\nopen import Cubical.Data.Empty as E hiding (elim)\nopen import Cubical.HITs.PropositionalTruncation as P hiding (elim; elim2)\n\nopen import Cubical.HITs.CumulativeHierarchy.Base\nopen import Cubical.HITs.CumulativeHierarchy.Properties\nimport Cubical.HITs.PropositionalTruncation.Monad as PropMonad\n\nprivate\n variable\n ℓ ℓ' : Level\n\n------------\n-- Structures for building specific sets by giving encodings and decodings for their membership\n-----------\n\nrecord SetStructure ℓ : Type (ℓ-suc ℓ) where\n field\n X : Type ℓ\n ix : X → V ℓ\n resSet : V ℓ\n resSet = sett X ix\n\nrecord SetPackage ℓ ℓ' : Type (ℓ-max (ℓ-suc ℓ) (ℓ-suc ℓ')) where\n field\n structure : SetStructure ℓ\n open SetStructure structure hiding (resSet)\n open SetStructure structure using (resSet) public\n field\n ∈-rep : V ℓ → hProp ℓ'\n unpack : (x : X) → ⟨ ∈-rep (ix x) ⟩\n repack : {y : V ℓ} → ⟨ ∈-rep y ⟩ → ∥ fiber ix y ∥₁\n\n open PropMonad\n classification : ⟨ ∀[ y ] (y ∈ₛ resSet ⇔ ∈-rep y) ⟩\n classification y = intoClassifier , fromClassifier where\n intoClassifier : ⟨ y ∈ₛ resSet ⟩ → ⟨ ∈-rep y ⟩\n intoClassifier (yi , yr) = proof (∈-rep y) by do\n (x , ix) ← ∈∈ₛ {b = resSet} .snd (yi , yr)\n return (subst (fst ∘ ∈-rep) ix (unpack x))\n fromClassifier : ⟨ ∈-rep y ⟩ → ⟨ y ∈ₛ resSet ⟩\n fromClassifier yr = ∈∈ₛ {b = resSet} .fst (repack {y = y} yr)\n\n------------\n-- Specific constructions\n-----------\nopen SetPackage using (structure; ∈-rep; unpack; repack)\n\nmodule EmptySet where\n EmptyStructure : SetStructure ℓ\n SetStructure.X EmptyStructure = Lift E.⊥\n SetStructure.ix EmptyStructure ()\n\n EmptyPackage : SetPackage ℓ ℓ-zero\n structure EmptyPackage = EmptyStructure\n ∈-rep EmptyPackage _ = L.⊥\n unpack EmptyPackage ()\n repack EmptyPackage ()\n\n ∅ : V ℓ\n ∅ = SetStructure.resSet EmptyStructure\n\n ∅-empty : ⟨ ∀[ b ∶ V ℓ ] ¬ (b ∈ₛ ∅) ⟩\n ∅-empty b = SetPackage.classification EmptyPackage b .fst\nopen EmptySet using (∅; ∅-empty) public\n\nmodule UnionSet (S : V ℓ) where\n UnionStructure : SetStructure ℓ\n SetStructure.X UnionStructure = Σ[ r ∈ ⟪ S ⟫ ] ⟪ ⟪ S ⟫↪ r ⟫\n SetStructure.ix UnionStructure (r , i) = ⟪ ⟪ S ⟫↪ r ⟫↪ i\n\n UNION : V ℓ\n UNION = SetStructure.resSet UnionStructure\n\n UnionPackage : SetPackage _ (ℓ-suc ℓ)\n structure UnionPackage = UnionStructure\n ∈-rep UnionPackage y = ∃[ v ] (v ∈ₛ S) ⊓ (y ∈ₛ v)\n unpack UnionPackage (vi , yi) = ∣ ⟪ S ⟫↪ vi , ∈ₛ⟪ S ⟫↪ vi , ∈ₛ⟪ ⟪ S ⟫↪ vi ⟫↪ yi ∣₁\n repack UnionPackage {y = y} = P.rec squash₁ go where\n go : Σ[ v ∈ V _ ] ⟨ v ∈ₛ S ⟩ ⊓′ ⟨ y ∈ₛ v ⟩ → ∥ fiber _ y ∥₁\n go (v , (vi , vS) , xv) = ∣ repFiber≃fiber _ _ .fst ((vi , key .fst) , key .snd) ∣₁ where\n path : v ≡ ⟪ S ⟫↪ vi\n path = sym (equivFun identityPrinciple vS)\n key : Σ[ i ∈ ⟪ ⟪ S ⟫↪ vi ⟫ ] ⟪ ⟪ S ⟫↪ vi ⟫↪ i ≊ y\n key = subst (λ v → Σ[ ix ∈ ⟪ v ⟫ ] ⟪ v ⟫↪ ix ≊ y) path xv\n\n union-ax : ⟨ ∀[ u ] (u ∈ₛ UNION ⇔ (∃[ v ] (v ∈ₛ S) ⊓ (u ∈ₛ v))) ⟩\n union-ax = classification where\n open SetPackage UnionPackage using (classification)\nopen UnionSet renaming (UNION to infixr 9 ⋃_) using (union-ax) public\n\nmodule PairingSet (a b : V ℓ) where\n PairingStructure : SetStructure ℓ\n SetStructure.X PairingStructure = Lift Bool\n SetStructure.ix PairingStructure (lift false) = a\n SetStructure.ix PairingStructure (lift true) = b\n\n open PropMonad\n PairingPackage : SetPackage _ (ℓ-suc ℓ)\n structure PairingPackage = PairingStructure\n ∈-rep PairingPackage d = (d ≡ₕ a) ⊔ (d ≡ₕ b)\n unpack PairingPackage (lift false) = L.inl refl\n unpack PairingPackage (lift true) = L.inr refl\n repack PairingPackage {y = y} = _>>= λ where\n (_⊎_.inl ya) → ∣ lift false , sym ya ∣₁\n (_⊎_.inr yb) → ∣ lift true , sym yb ∣₁\n\n PAIR : V ℓ\n PAIR = SetStructure.resSet PairingStructure\n\n pairing-ax : ⟨ ∀[ d ] (d ∈ₛ PAIR ⇔ (d ≡ₕ a) ⊔ (d ≡ₕ b)) ⟩\n pairing-ax = classification where\n open SetPackage PairingPackage using (classification)\n-- pairing TODO: notation?\nopen PairingSet renaming (PAIR to infix 12 ⁅_,_⁆) using (pairing-ax) public\n\nmodule SingletonSet (a : V ℓ) where\n SingletonStructure : SetStructure ℓ\n SetStructure.X SingletonStructure = Lift Unit\n SetStructure.ix SingletonStructure (lift tt) = a\n\n SingletonPackage : SetPackage _ (ℓ-suc ℓ)\n structure SingletonPackage = SingletonStructure\n ∈-rep SingletonPackage d = d ≡ₕ a\n unpack SingletonPackage _ = refl\n repack SingletonPackage ya = ∣ lift tt , sym ya ∣₁\n\n SINGL : V ℓ\n SINGL = SetStructure.resSet SingletonStructure\nopen SingletonSet renaming (SINGL to infix 10 ⁅_⁆s) public\n\n-- small unions\n_∪_ : (a b : V ℓ) → V ℓ\na ∪ b = ⋃ ⁅ a , b ⁆\n\nmodule InfinitySet {ℓ} where\n sucV : V ℓ → V ℓ\n sucV N = N ∪ ⁅ N ⁆s\n\n #_ : ℕ → V ℓ\n # zero = ∅\n # suc n = sucV (# n)\n\n ωStructure : SetStructure ℓ\n SetStructure.X ωStructure = Lift ℕ\n SetStructure.ix ωStructure = #_ ∘ lower\n\n ω : V ℓ\n ω = SetStructure.resSet ωStructure\n\n open PropMonad\n ωPackage : SetPackage _ (ℓ-suc ℓ)\n structure ωPackage = ωStructure\n ∈-rep ωPackage d = (d ≡ₕ ∅) ⊔ (∃[ v ] (d ≡ₕ sucV v) ⊓ (v ∈ₛ ω))\n unpack ωPackage (lift zero) = L.inl refl\n unpack ωPackage (lift (suc n)) = L.inr ∣ # n , refl , ∈∈ₛ {b = ω} .fst ∣ lift n , refl ∣₁ ∣₁\n repack ωPackage {y = y} = ⊔-elim (y ≡ₕ ∅) ∥ _ ∥ₚ (λ _ → ∥ fiber _ y ∥ₚ)\n (λ e → ∣ lift zero , sym e ∣₁)\n (λ m → do (v , yv , vr) ← m\n (lift n , eq) ← ∈∈ₛ {b = ω} .snd vr\n ∣ lift (suc n) , sym (subst (λ v → y ≡ (v ∪ ⁅ v ⁆s)) (sym eq) yv) ∣₁\n )\n\n infinity-ax : ⟨ ∀[ y ] (y ∈ₛ ω ⇔ (y ≡ₕ ∅) ⊔ (∃[ v ] (y ≡ₕ sucV v) ⊓ (v ∈ₛ ω))) ⟩\n infinity-ax = classification where\n open SetPackage ωPackage using (classification)\n\n ω-empty : ⟨ ∅ ∈ₛ ω ⟩\n ω-empty = infinity-ax ∅ .snd (L.inl refl)\n\n ω-next : ⟨ ∀[ x ∶ V ℓ ] x ∈ₛ ω ⇒ sucV x ∈ₛ ω ⟩\n ω-next x x∈ω = infinity-ax (sucV x) .snd (L.inr ∣ x , refl , x∈ω ∣₁)\n\n #-in-ω : ∀ n → ⟨ # n ∈ₛ ω ⟩\n #-in-ω zero = ω-empty\n #-in-ω (suc n) = ω-next (# n) (#-in-ω n)\n\nopen InfinitySet using (ω; ω-empty; ω-next; infinity-ax) public\n\nmodule ReplacementSet (r : V ℓ → V ℓ) (a : V ℓ) where\n ReplacementStructure : SetStructure ℓ\n SetStructure.X ReplacementStructure = ⟪ a ⟫\n SetStructure.ix ReplacementStructure = r ∘ ⟪ a ⟫↪\n\n REPLACED : V ℓ\n REPLACED = SetStructure.resSet ReplacementStructure\n\n open PropMonad\n ReplacementPackage : SetPackage _ (ℓ-suc ℓ)\n structure ReplacementPackage = ReplacementStructure\n ∈-rep ReplacementPackage y = ∃[ z ] (z ∈ₛ a) ⊓ (y ≡ₕ r z)\n unpack ReplacementPackage ⟪a⟫ = ∣ ⟪ a ⟫↪ ⟪a⟫ , (∈ₛ⟪ a ⟫↪ ⟪a⟫) , refl ∣₁\n repack ReplacementPackage {y = y} m = do\n (z , (a , za) , yr) ← m\n ∣ a , cong r (equivFun identityPrinciple za) ∙ sym yr ∣₁\n\n replacement-ax : ⟨ ∀[ y ] (y ∈ₛ REPLACED ⇔ (∃[ z ] (z ∈ₛ a) ⊓ (y ≡ₕ r z))) ⟩\n replacement-ax y = classification y where\n open SetPackage ReplacementPackage using (classification)\nopen ReplacementSet renaming (REPLACED to infix 12 ⁅_∣_⁆) using (replacement-ax) public\n\nmodule SeparationSet (a : V ℓ) (ϕ : V ℓ → hProp ℓ) where\n SeparationStructure : SetStructure ℓ\n SetStructure.X SeparationStructure = Σ[ x ∈ ⟪ a ⟫ ] ⟨ ϕ (⟪ a ⟫↪ x) ⟩\n SetStructure.ix SeparationStructure = ⟪ a ⟫↪ ∘ fst\n\n SeparationPackage : SetPackage _ ℓ\n structure SeparationPackage = SeparationStructure\n ∈-rep SeparationPackage y = (y ∈ₛ a) ⊓ ϕ y\n unpack SeparationPackage (⟪a⟫ , phi) = (∈ₛ⟪ a ⟫↪ ⟪a⟫) , phi\n repack SeparationPackage ((⟪a⟫ , ya) , phi) =\n ∣ (⟪a⟫ , subst (fst ∘ ϕ) (sym (equivFun identityPrinciple ya)) phi)\n , equivFun identityPrinciple ya ∣₁\n\n SEPAREE : V ℓ\n SEPAREE = SetStructure.resSet SeparationStructure\n\n separation-ax : ⟨ ∀[ y ] (y ∈ₛ SEPAREE ⇔ (y ∈ₛ a) ⊓ ϕ y) ⟩\n separation-ax y = classification y .fst , classification y .snd where\n open SetPackage SeparationPackage using (classification)\nopen SeparationSet renaming (SEPAREE to infix 12 ⁅_∶_⁆) using (separation-ax) public\n\nmodule Examples where\n open InfinitySet\n\n the1 : V ℓ-zero\n the1 = # 1\n\n 1-ok? : ∥ Bool ∥₁\n 1-ok? = do\n prf ← infinity-ax the1 .fst (#-in-ω 1)\n case prf of λ { (⊎.inl _) → ∣ false ∣₁ ; (⊎.inr _) → ∣ true ∣₁ }\n where\n open PropMonad\n test : 1-ok? ≡ ∣ true ∣₁\n test = refl\n", "meta": {"hexsha": "03336f5c7ae2a4497838751f1e92acea892a6d8a", "size": 8800, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/HITs/CumulativeHierarchy/Constructions.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_issues_repo_path": "Cubical/HITs/CumulativeHierarchy/Constructions.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/HITs/CumulativeHierarchy/Constructions.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": 33.7164750958, "max_line_length": 95, "alphanum_fraction": 0.63875, "num_tokens": 3316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6224593312018545, "lm_q2_score": 0.6150878555160665, "lm_q1q2_score": 0.38286717517491364}} {"text": "open import Relation.Binary.Core\n\nmodule PLRTree.Insert.Permutation {A : Set} \n (_≤_ : A → A → Set)\n (tot≤ : Total _≤_) where\n\nopen import Data.List\nopen import Data.Product renaming (_×_ to _∧_)\nopen import Data.Sum\nopen import List.Permutation.Base A \nopen import List.Permutation.Base.Concatenation A \nopen import List.Permutation.Base.Equivalence A \nopen import PLRTree {A} \nopen import PLRTree.Complete {A} \nopen import PLRTree.Compound {A} \nopen import PLRTree.Insert _≤_ tot≤\nopen import PLRTree.Insert.Properties _≤_ tot≤\n\nmutual\n lemma-insert-/ : {t : PLRTree}(x : A) → Complete t → ∃ (λ xs → flatten (insert x t) / x ⟶ xs ∧ xs ∼ flatten t)\n lemma-insert-/ x leaf = [] , /head , ∼[]\n lemma-insert-/ x (perfect {l} {r} y cl _ l≃r) \n with tot≤ x y | l | r | l≃r\n ... | inj₁ x≤y | leaf | leaf | _ = y ∷ [] , /head , refl∼\n ... | inj₁ x≤y | leaf | node _ _ _ _ | () \n ... | inj₁ x≤y | node perfect _ _ _ | leaf | ()\n ... | inj₁ x≤y | node perfect y' l' r' | node perfect y'' l'' r'' | _ = \n let _l = node perfect y' l' r' ;\n _r = node perfect y'' l'' r'' ;\n flᵢfr∼yflfr = lemma++∼r (lemma-insert-∼ y cl)\n in flatten (insert y _l) ++ flatten _r , /head , flᵢfr∼yflfr \n ... | inj₁ x≤y | node perfect _ _ _ | node left _ _ _ | ()\n ... | inj₁ x≤y | node perfect _ _ _ | node right _ _ _ | ()\n ... | inj₁ x≤y | node left _ _ _ | _ | () \n ... | inj₁ x≤y | node right _ _ _ | _ | () \n ... | inj₂ y≤x | leaf | leaf | _ = y ∷ [] , /tail /head , refl∼\n ... | inj₂ y≤x | leaf | node _ _ _ _ | ()\n ... | inj₂ y≤x | node perfect _ _ _ | leaf | ()\n ... | inj₂ y≤x | node perfect y' l' r' | node perfect y'' l'' r'' | _ \n with lemma-insert-/ x cl\n ... | xs , flᵢ/x⟶xs , xs∼fl = \n let _l = node perfect y' l' r' ;\n _r = node perfect y'' l'' r'' ;\n yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;\n yflᵢfr∼yxsfr = ∼x /head /head (lemma++∼r xs∼fl)\n in y ∷ xs ++ flatten _r , yflᵢfr/x⟶yxsfr , yflᵢfr∼yxsfr \n lemma-insert-/ x (perfect y cl _ l≃r) | inj₂ y≤x | node perfect _ _ _ | node left _ _ _ | ()\n lemma-insert-/ x (perfect y cl _ l≃r) | inj₂ y≤x | node perfect _ _ _ | node right _ _ _ | ()\n lemma-insert-/ x (perfect y cl _ l≃r) | inj₂ y≤x | node left _ _ _ | _ | () \n lemma-insert-/ x (perfect y cl _ l≃r) | inj₂ y≤x | node right _ _ _ | _ | () \n lemma-insert-/ x (left {l} {r} y cl _ _) \n with tot≤ x y\n ... | inj₁ x≤y \n with insert y l | lemma-insert-∼ y cl | lemma-insert-compound y l\n ... | node perfect y' l' r' | flᵢ∼yfl | compound = \n let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl\n in flatten (node perfect y' l' r') ++ flatten r , /head , flᵢfr∼yflfr \n ... | node left y' l' r' | flᵢ∼yfl | compound = \n let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl\n in flatten (node left y' l' r') ++ flatten r , /head , flᵢfr∼yflfr \n ... | node right y' l' r' | flᵢ∼yfl | compound = \n let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl\n in flatten (node right y' l' r') ++ flatten r , /head , flᵢfr∼yflfr \n lemma-insert-/ x (left {l} {r} y cl _ _) | inj₂ y≤x \n with insert x l | lemma-insert-/ x cl | lemma-insert-compound x l\n ... | node perfect _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound = \n let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;\n yflᵢfr∼yxsfr = ∼x /head /head (lemma++∼r xs∼fl)\n in y ∷ xs ++ flatten r , yflᵢfr/x⟶yxsfr , yflᵢfr∼yxsfr \n ... | node left _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound = \n let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;\n yflᵢfr∼yxsfr = ∼x /head /head (lemma++∼r xs∼fl)\n in y ∷ xs ++ flatten r , yflᵢfr/x⟶yxsfr , yflᵢfr∼yxsfr \n ... | node right _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound = \n let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;\n yflᵢfr∼yxsfr = ∼x /head /head (lemma++∼r xs∼fl)\n in y ∷ xs ++ flatten r , yflᵢfr/x⟶yxsfr , yflᵢfr∼yxsfr \n lemma-insert-/ x (right {l} {r} y _ cr _) \n with tot≤ x y \n ... | inj₁ x≤y \n with insert y r | lemma-insert-∼ y cr | lemma-insert-compound y r\n ... | node perfect y' l' r' | frᵢ∼yfr | compound =\n let flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;\n flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ; \n flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr \n in flatten l ++ flatten (node perfect y' l' r') , /head , flfrᵢ∼yflfr \n ... | node left y' l' r' | frᵢ∼yfr | compound = \n let flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;\n flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ; \n flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr \n in flatten l ++ flatten (node left y' l' r') , /head , flfrᵢ∼yflfr \n ... | node right y' l' r' | frᵢ∼yfr | compound = \n let flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;\n flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ; \n flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr \n in flatten l ++ flatten (node right y' l' r') , /head , flfrᵢ∼yflfr \n lemma-insert-/ x (right {l} {r} y _ cr _) | inj₂ y≤x \n with insert x r | lemma-insert-/ x cr | lemma-insert-compound x r\n ... | node perfect y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound = \n let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;\n yflfrᵢ∼yflxs = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)\n in y ∷ flatten l ++ xs , yflfrᵢ/x⟶yflxs , yflfrᵢ∼yflxs \n ... | node left y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound = \n let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;\n yflfrᵢ∼yflxs = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)\n in y ∷ flatten l ++ xs , yflfrᵢ/x⟶yflxs , yflfrᵢ∼yflxs \n ... | node right y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound = \n let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;\n yflfrᵢ∼yflxs = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)\n in y ∷ flatten l ++ xs , yflfrᵢ/x⟶yflxs , yflfrᵢ∼yflxs \n\n lemma-insert-∼ : {t : PLRTree}(x : A) → Complete t → flatten (insert x t) ∼ (x ∷ flatten t)\n lemma-insert-∼ x leaf = ∼x /head /head ∼[]\n lemma-insert-∼ x (perfect {l} {r} y cl _ l≃r) \n with tot≤ x y | l | r | l≃r\n ... | inj₁ x≤y | leaf | leaf | _ = ∼x /head /head (∼x /head /head ∼[])\n ... | inj₁ x≤y | leaf | node _ _ _ _ | () \n ... | inj₁ x≤y | node perfect _ _ _ | leaf | ()\n ... | inj₁ x≤y | node perfect _ _ _ | node perfect _ _ _ | _ = \n let flᵢfr∼yflfr = lemma++∼r (lemma-insert-∼ y cl)\n in ∼x /head /head flᵢfr∼yflfr\n ... | inj₁ x≤y | node perfect _ _ _ | node left _ _ _ | ()\n ... | inj₁ x≤y | node perfect _ _ _ | node right _ _ _ | ()\n ... | inj₁ x≤y | node left _ _ _ | _ | () \n ... | inj₁ x≤y | node right _ _ _ | _ | () \n ... | inj₂ y≤x | leaf | leaf | _ = ∼x /head (/tail /head) (∼x /head /head ∼[])\n ... | inj₂ y≤x | leaf | node _ _ _ _ | ()\n ... | inj₂ y≤x | node perfect _ _ _ | leaf | ()\n ... | inj₂ y≤x | node perfect _ _ _ | node perfect _ _ _ | _ \n with lemma-insert-/ x cl \n ... | xs , flᵢ/x⟶xs , xs∼fl =\n let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;\n yxsfr∼yflfr = ∼x /head /head (lemma++∼r xs∼fl)\n in ∼x yflᵢfr/x⟶yxsfr /head yxsfr∼yflfr\n lemma-insert-∼ x (perfect y cl _ l≃r) | inj₂ y≤x | node perfect _ _ _ | node left _ _ _ | ()\n lemma-insert-∼ x (perfect y cl _ l≃r) | inj₂ y≤x | node perfect _ _ _ | node right _ _ _ | ()\n lemma-insert-∼ x (perfect y cl _ l≃r) | inj₂ y≤x | node left _ _ _ | _ | () \n lemma-insert-∼ x (perfect y cl _ l≃r) | inj₂ y≤x | node right _ _ _ | _ | () \n lemma-insert-∼ x (left {l} {r} y cl _ _) \n with tot≤ x y\n ... | inj₁ x≤y \n with insert y l | lemma-insert-∼ y cl | lemma-insert-compound y l\n ... | node perfect _ _ _ | flᵢ∼yfl | compound = \n let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl\n in ∼x /head /head flᵢfr∼yflfr \n ... | node left _ _ _ | flᵢ∼yfl | compound = \n let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl\n in ∼x /head /head flᵢfr∼yflfr \n ... | node right _ _ _ | flᵢ∼yfl | compound = \n let flᵢfr∼yflfr = lemma++∼r flᵢ∼yfl\n in ∼x /head /head flᵢfr∼yflfr \n lemma-insert-∼ x (left {l} {r} y cl _ _) | inj₂ y≤x \n with insert x l | lemma-insert-/ x cl | lemma-insert-compound x l\n ... | node perfect _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound = \n let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;\n yxsfr∼yflfr = ∼x /head /head (lemma++∼r xs∼fl)\n in ∼x yflᵢfr/x⟶yxsfr /head yxsfr∼yflfr\n ... | node left _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound = \n let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;\n yxsfr∼yflfr = ∼x /head /head (lemma++∼r xs∼fl)\n in ∼x yflᵢfr/x⟶yxsfr /head yxsfr∼yflfr\n ... | node right _ _ _ | xs , flᵢ/x⟶xs , xs∼fl | compound = \n let yflᵢfr/x⟶yxsfr = /tail (lemma++/r flᵢ/x⟶xs) ;\n yxsfr∼yflfr = ∼x /head /head (lemma++∼r xs∼fl)\n in ∼x yflᵢfr/x⟶yxsfr /head yxsfr∼yflfr\n lemma-insert-∼ x (right {l} {r} y _ cr _) \n with tot≤ x y \n ... | inj₁ x≤y \n with insert y r | lemma-insert-∼ y cr | lemma-insert-compound y r\n ... | node perfect _ _ _ | frᵢ∼yfr | compound = \n let flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ;\n flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;\n flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr\n in ∼x /head /head flfrᵢ∼yflfr\n ... | node left _ _ _ | frᵢ∼yfr | compound = \n let flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ;\n flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;\n flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr\n in ∼x /head /head flfrᵢ∼yflfr\n ... | node right _ _ _ | frᵢ∼yfr | compound = \n let flyfr∼yflfr = ∼x (lemma++/ {y} {flatten l}) /head refl∼ ;\n flfrᵢ∼flyfr = lemma++∼l {flatten l} frᵢ∼yfr ;\n flfrᵢ∼yflfr = trans∼ flfrᵢ∼flyfr flyfr∼yflfr\n in ∼x /head /head flfrᵢ∼yflfr\n lemma-insert-∼ x (right {l} {r} y _ cr _) | inj₂ y≤x \n with insert x r | lemma-insert-/ x cr | lemma-insert-compound x r\n ... | node perfect y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound = \n let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;\n yflxs∼yflfr = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)\n in ∼x yflfrᵢ/x⟶yflxs /head yflxs∼yflfr\n ... | node left y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound = \n let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;\n yflxs∼yflfr = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)\n in ∼x yflfrᵢ/x⟶yflxs /head yflxs∼yflfr\n ... | node right y' l' r' | xs , frᵢ/x⟶xs , xs∼fr | compound = \n let yflfrᵢ/x⟶yflxs = /tail (lemma++/l {x} {flatten l} frᵢ/x⟶xs) ;\n yflxs∼yflfr = ∼x /head /head (lemma++∼l {flatten l} xs∼fr)\n in ∼x yflfrᵢ/x⟶yflxs /head yflxs∼yflfr\n\n", "meta": {"hexsha": "1abd86ae5996eb556e0475a845fb4967a92b7605", "size": 11715, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda/PLRTree/Insert/Permutation.agda", "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_issues_repo_path": "agda/PLRTree/Insert/Permutation.agda", "max_issues_repo_name": "bgbianchi/sorting", "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "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/PLRTree/Insert/Permutation.agda", "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "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.575, "max_line_length": 112, "alphanum_fraction": 0.4977379428, "num_tokens": 4841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.4493926344647597, "lm_q1q2_score": 0.3828613208731392}} {"text": "module Scratch.Subset where\nopen import Level renaming (zero to lzero; suc to lsuc)\n\nopen import Relation.Unary using (Pred; Satisfiable) renaming (Decidable to Dec₁)\nopen import Relation.Binary renaming (Decidable to Dec₂)\nopen import Relation.Binary.PropositionalEquality as Eq using (_≡_ ; _≢_; refl; cong; sym; trans; subst₂)\nopen Eq.≡-Reasoning\nopen import Data.Empty using (⊥-elim)\nopen import Data.Nat.Base as ℕ using (ℕ;_+_;_∸_;suc;zero; _<_)\nopen import Data.Bool using (not; Bool)\nopen import Data.Bool.Properties hiding (_≟_)\nopen import Data.Product\nopen import Data.Sum renaming ([_,_] to _⊞_)\nopen import Data.Vec hiding (allFin)\nopen import Data.Vec.Properties\nopen import Data.Fin.Properties using (∃-toSum)\nopen import Data.Fin hiding (fold; _+_; _<_)\n renaming (zero to fzero ; suc to fsuc)\n hiding (_≟_)\n\nopen import Relation.Nullary.Negation using (contradiction)\n\nopen import Data.Fin.Properties using (suc-injective)\nopen import Data.Fin.Subset\nopen import Data.Fin.Subset.Properties\nopen import Data.Maybe\nopen import Data.List.Base renaming (tabulate to tab ;\n foldr to fold;\n [] to <>;\n [_] to <_>;\n map to lmap;\n lookup to llookup)\n hiding (tail; any)\nopen import Data.List.Properties\nopen import Data.List.Membership.Propositional\n renaming (_∈_ to _∈ℓ_)\nopen import Data.List.Membership.Propositional.Properties\nopen import Data.List.Relation.Unary.Any as Any hiding (tail)\nopen import Data.List.Relation.Unary.Any.Properties\nopen import Data.List.Relation.Unary.All as All\nopen import Data.List.Relation.Unary.AllPairs as AllPairs\nopen import Data.List.Relation.Unary.AllPairs.Properties\n\n\nopen import Function.Base\n\nopen import Relation.Nullary\n\nopen import Data.Nat.Properties\n using (_≟_; m+n∸m≡n; +-∸-assoc; +-∸-comm; +-comm; +-identityʳ; 0∸n≡0; n≤0⇒n≡0; n≢0⇒n>0; +-0-commutativeMonoid)\n\nopen import Algebra.Core\nimport Algebra.Properties.BooleanAlgebra\n\n_\\\\_ : ∀ {n} → Op₂ (Subset n)\nS \\\\ T = S ∩ (∁ T)\n\ns\\\\⊥≡s : ∀ {n : ℕ} → (S : Subset n) → (S \\\\ ⊥) ≡ S\ns\\\\⊥≡s {n} S = begin\n S ∩ (∁ ⊥) ≡⟨ cong (S ∩_) ⊥≉⊤ ⟩\n S ∩ ⊤ ≡⟨ ∩-identityʳ _ ⟩\n S ∎ where open Algebra.Properties.BooleanAlgebra (∪-∩-booleanAlgebra n)\n\nDisj : ∀ {n} → Subset n → Subset n → Set\nDisj S T = S ∩ T ≡ ⊥\n\nDisj-sym : ∀ {n} → Symmetric (Disj {n = n})\nDisj-sym {n} {S} {T} S∩T≡⊥ = begin T ∩ S ≡⟨ ∩-comm T S ⟩ S ∩ T ≡⟨ S∩T≡⊥ ⟩ ⊥ ∎\n\n∩-⊆-stable : ∀ {n} → ∀ {p q} → (r : Subset n) → p ⊆ q → (p ∩ r) ⊆ (q ∩ r)\n∩-⊆-stable {_} {p} {q} r p⊆q x∈p∩r = let\n x∈p = proj₁ (x∈p∩q⁻ p r x∈p∩r)\n x∈r = proj₂ (x∈p∩q⁻ p r x∈p∩r)\n in x∈p∩q⁺ ( p⊆q x∈p , x∈r )\n\nidʳ⇒⊆ : ∀ {n} → (S T : Subset n) → (S ∪ T) ≡ T → S ⊆ T\nidʳ⇒⊆ {n} S T sut≡t = subst₂ _⊆_ refl sut≡t (p⊆p∪q T)\n\np∩∁p≡⊥ : ∀ {n} → (p : Subset n) → p ∩ ∁ p ≡ ⊥\np∩∁p≡⊥ [] = refl\np∩∁p≡⊥ (outside ∷ p) = cong (outside ∷_) (p∩∁p≡⊥ p)\np∩∁p≡⊥ (inside ∷ p) = cong (outside ∷_) (p∩∁p≡⊥ p)\n\np⊆q⇒p∩∁q≡⊥ : ∀ {n} → {S T : Subset n} → S ⊆ T → S ∩ (∁ T) ≡ ⊥\np⊆q⇒p∩∁q≡⊥ {_} {S} {T} s⊆t = let\n a = p∩∁p≡⊥ _\n b : S ∩ (∁ T) ⊆ T ∩ (∁ T)\n b = ∩-⊆-stable (∁ T) s⊆t\n c = subst₂ _⊆_ refl a b\n in ⊆-antisym c (⊆-min _)\n\np⊆q⇒p∩q≡p : ∀ {n} → (S T : Subset n) → S ⊆ T → S ∩ T ≡ S\np⊆q⇒p∩q≡p S T s⊆t = sym (begin\n S ≡˘⟨ ∩-identityʳ _ ⟩\n S ∩ ⊤ ≡˘⟨ cong (_ ∩_) (p∪∁p≡⊤ _) ⟩\n S ∩ (T ∪ (∁ T)) ≡⟨ ∩-distribˡ-∪ _ _ _ ⟩\n (S ∩ T) ∪ (S ∩ (∁ T)) ≡⟨ cong ((S ∩ T) ∪_) (p⊆q⇒p∩∁q≡⊥ s⊆t) ⟩\n (S ∩ T) ∪ ⊥ ≡⟨ ∪-identityʳ _ ⟩\n S ∩ T ∎)\n\n\ndisj⇒⊆∁ : ∀ {n} → {S T : Subset n} → Disj S T → S ⊆ (∁ T)\ndisj⇒⊆∁ {n} {S} {T} dst = let ct≡suct = begin\n ∁ T ≡˘⟨ ∪-identityˡ _ ⟩\n ⊥ ∪ (∁ T) ≡˘⟨ cong (_∪ (∁ T)) dst ⟩\n (S ∩ T) ∪ (∁ T) ≡⟨ ∪-distribʳ-∩ _ _ _ ⟩\n (S ∪ (∁ T)) ∩ (T ∪ (∁ T)) ≡⟨ cong ((S ∪ (∁ T)) ∩_) (p∪∁p≡⊤ T) ⟩\n (S ∪ (∁ T)) ∩ ⊤ ≡⟨ ∩-identityʳ _ ⟩\n S ∪ (∁ T) ∎\n in idʳ⇒⊆ S (∁ T) (sym ct≡suct)\n\n⊆∁⇒disj : ∀ {n} → {S T : Subset n} → S ⊆ (∁ T) → Disj S T\n⊆∁⇒disj {n} {S} {T} s⊆∁t = begin\n S ∩ T ≡˘⟨ cong (S ∩_) (¬-involutive T ) ⟩\n S ∩ (∁ (∁ T)) ≡⟨ p⊆q⇒p∩∁q≡⊥ s⊆∁t ⟩\n ⊥ ∎ where open Algebra.Properties.BooleanAlgebra (∪-∩-booleanAlgebra n)\n\np⊆r×q⊆r⇒p∪q⊆r : ∀ {n} → { p q r : Subset n} → (p ⊆ r) × (q ⊆ r) → (p ∪ q) ⊆ r\np⊆r×q⊆r⇒p∪q⊆r {n} {p} {q} {r} (p⊆r , q⊆r) x∈p∪q = let\n y = x∈p∪q⁻ {n} p q x∈p∪q\n in (p⊆r ⊞ q⊆r) y\n\npᵢ⊆q⇒⋃pᵢ⊆q : ∀ {n m} → (S : Subset n) → (ϕ : Fin m → Subset n) →\n (∀ i → (ϕ i) ⊆ S) → (⋃ (tab ϕ) ⊆ S)\n\npᵢ⊆q⇒⋃pᵢ⊆q {_} {zero} S _ _ = ⊆-min S\npᵢ⊆q⇒⋃pᵢ⊆q {n} {suc m} S ϕ Δ = let\n y : ((ϕ fzero) ∪ (⋃(tab (ϕ ∘ fsuc)))) ⊆ S\n y = p⊆r×q⊆r⇒p∪q⊆r ( Δ fzero , pᵢ⊆q⇒⋃pᵢ⊆q S (λ z → ϕ (fsuc z)) (λ i → Δ (fsuc i)) )\n in subst₂ _⊆_ refl refl y\n\npᵢ⊆q⇒⋃pᵢ⊆q-list : ∀ {n} → ∀ S → ∀ (L : List (Subset n)) →\n All (_⊆ S) L → (⋃ L) ⊆ S\npᵢ⊆q⇒⋃pᵢ⊆q-list S <> _ = ⊆-min S\npᵢ⊆q⇒⋃pᵢ⊆q-list S (x ∷ xs) (h ∷ t) = subst₂ _⊆_ refl refl (p⊆r×q⊆r⇒p∪q⊆r ( h , pᵢ⊆q⇒⋃pᵢ⊆q-list S xs t ))\n\n-- obvious but exposes S for computation later\ndrop-outside : ∀ {n} → (S : Subset n) → ∣ outside ∷ S ∣ ≡ ∣ S ∣\ndrop-outside S = refl\n\ndrop-disj : ∀ {n} → {x y : Side} → {p q : Subset n} → Disj (x ∷ p) (y ∷ q) → Disj p q\ndrop-disj {zero} {_} {_} {[]} {[]} _ = refl\ndrop-disj d = cong Data.Vec.tail d\n\n∣p⊍q∣≡∣p∣+∣q∣ : ∀ {n} → ∀ (p q : Subset n) → Disj p q → ∣ p ∪ q ∣ ≡ ∣ p ∣ + ∣ q ∣\n∣p⊍q∣≡∣p∣+∣q∣ {zero} [] [] d = refl\n∣p⊍q∣≡∣p∣+∣q∣ {suc n} (outside ∷ p) (outside ∷ q) d = begin\n -- ∣ (outside ∷ p) ∪ (outside ∷ q) ∣ ≡⟨⟩\n ∣ p ∪ q ∣ ≡⟨ ∣p⊍q∣≡∣p∣+∣q∣ {_} p q (drop-disj {n} {outside} {outside} d) ⟩\n -- ∣ p ∣ + ∣ q ∣ ≡⟨⟩\n ∣ (outside ∷ p) ∣ + ∣ (outside ∷ q) ∣ ∎\n\n∣p⊍q∣≡∣p∣+∣q∣ {suc n} (inside ∷ p) (outside ∷ q) d = begin -- {! !} -- begin\n ∣ (inside ∷ p) ∪ (outside ∷ q) ∣ ≡⟨ refl ⟩ -- cong suc refl ⟩\n -- suc ∣ (inside ∷ p) ∪ (outside ∷ q) ∣ ≡⟨ cong suc {! !} ⟩ -- cong suc refl ⟩\n suc ∣ p ∪ q ∣ ≡⟨ cong suc (∣p⊍q∣≡∣p∣+∣q∣ {_} p q (drop-disj {n} {inside} {outside} d)) ⟩\n suc (∣ p ∣ + ∣ q ∣) ≡⟨⟩\n (suc ∣ p ∣) + ∣ q ∣ ≡⟨⟩\n ∣ (inside ∷ p) ∣ + ∣ (outside ∷ q) ∣ ∎\n∣p⊍q∣≡∣p∣+∣q∣ {suc n} (outside ∷ p) (inside ∷ q) d = begin\n ∣ (outside ∷ p) ∪ (inside ∷ q) ∣ ≡⟨ refl ⟩\n suc ∣ p ∪ q ∣ ≡⟨ cong suc (∣p⊍q∣≡∣p∣+∣q∣ {_} p q (drop-disj {n} {outside} {inside} d)) ⟩\n suc (∣ p ∣ + ∣ q ∣) ≡⟨ cong suc (+-comm ∣ p ∣ ∣ q ∣) ⟩\n suc (∣ q ∣ + ∣ p ∣) ≡⟨ refl ⟩\n (suc ∣ q ∣) + ∣ p ∣ ≡⟨⟩\n ∣ (inside ∷ q) ∣ + ∣ (outside ∷ p) ∣ ≡⟨ +-comm ∣ (inside ∷ q) ∣ ∣ (outside ∷ p) ∣ ⟩\n ∣ (outside ∷ p) ∣ + ∣ (inside ∷ q) ∣ ∎\n\n-- why can't we use fold fusion here?\n∣⋃ᵢpᵢ∣≡Σᵢ∣pᵢ∣ : ∀ {n m} → (ϕ : Fin m → Subset n) →\n (∀ i j → (i ≢ j) → Disj (ϕ i) (ϕ j)) →\n ∣ ⋃ (tab ϕ) ∣ ≡ fold _+_ 0 (tab (∣_∣ ∘ ϕ))\n∣⋃ᵢpᵢ∣≡Σᵢ∣pᵢ∣ {n} {zero} ϕ _ = begin\n ∣ ⋃ {n} <> ∣ ≡⟨⟩\n -- ∣ fold (_∪_ {n}) ⊥ <> ∣ ≡⟨⟩\n ∣ ⊥ {n} ∣ ≡⟨ ∣⊥∣≡0 n ⟩\n 0 ≡⟨⟩\n fold _+_ 0 <> ∎\n∣⋃ᵢpᵢ∣≡Σᵢ∣pᵢ∣ {n} {suc m} ϕ Δ = begin\n ∣ ⋃ (tab ϕ) ∣ ≡⟨⟩\n ∣ (ϕ fzero) ∪ (⋃ (tab (ϕ ∘ fsuc))) ∣ ≡⟨ ∣p⊍q∣≡∣p∣+∣q∣ (ϕ fzero) (⋃ (tab (ϕ ∘ fsuc))) d ⟩\n ∣ (ϕ fzero) ∣ + ∣ ⋃ (tab (ϕ ∘ fsuc)) ∣ ≡⟨ cong (∣ (ϕ fzero) ∣ +_) (∣⋃ᵢpᵢ∣≡Σᵢ∣pᵢ∣ {_} {m} (ϕ ∘ fsuc) λ i j i≢j → Δ (fsuc i) (fsuc j) (i≢j ∘ suc-injective) ) ⟩\n ∣ (ϕ fzero) ∣ + (fold _+_ 0 (tab (∣_∣ ∘ (ϕ ∘ fsuc)))) ≡⟨⟩\n fold _+_ 0 (tab (∣_∣ ∘ ϕ)) ∎\n where\n a : ∀ (i : Fin m) → Disj (ϕ (fsuc i)) (ϕ fzero)\n a = λ i → Δ (fsuc i) fzero (λ ())\n b : ∀ (i : Fin m) → (ϕ (fsuc i) ⊆ ∁ (ϕ fzero))\n b = disj⇒⊆∁ ∘ a\n c : ⋃ (tab (ϕ ∘ fsuc)) ⊆ ∁ (ϕ fzero)\n c = pᵢ⊆q⇒⋃pᵢ⊆q (∁ (ϕ fzero)) (ϕ ∘ fsuc) b\n\n e : Disj (⋃ (tab (ϕ ∘ fsuc))) (ϕ fzero)\n e = ⊆∁⇒disj c\n\n d : Disj (ϕ fzero) (⋃ (tab (ϕ ∘ fsuc)))\n d = begin\n (ϕ fzero) ∩ (⋃ (tab (ϕ ∘ fsuc))) ≡⟨ ∩-comm _ _ ⟩\n (⋃ (tab (ϕ ∘ fsuc))) ∩ (ϕ fzero) ≡⟨ e ⟩\n ⊥ ∎\n\n∣⋃ᵢpᵢ∣≡Σᵢ∣pᵢ∣-list : ∀ {n} (C : List (Subset n)) →\n AllPairs Disj C →\n ∣ ⋃ C ∣ ≡ fold _+_ 0 (lmap ∣_∣ C)\n∣⋃ᵢpᵢ∣≡Σᵢ∣pᵢ∣-list {n} <> Δℓ = begin\n ∣ ⋃ {n} <> ∣ ≡⟨⟩\n -- ∣ fold (_∪_ {n}) ⊥ <> ∣ ≡⟨⟩\n ∣ ⊥ {n} ∣ ≡⟨ ∣⊥∣≡0 n ⟩\n 0 ≡⟨⟩\n fold _+_ 0 <> ∎\n∣⋃ᵢpᵢ∣≡Σᵢ∣pᵢ∣-list {n} (s ∷ C) (h ∷ t) = begin\n ∣ ⋃ (s ∷ C) ∣ ≡⟨⟩\n ∣ s ∪ (⋃ C) ∣ ≡⟨ ∣p⊍q∣≡∣p∣+∣q∣ s (⋃ C) DisjsUC ⟩\n ∣ s ∣ + ∣ ⋃ C ∣ ≡⟨ cong (∣ s ∣ +_) (∣⋃ᵢpᵢ∣≡Σᵢ∣pᵢ∣-list {n} C t ) ⟩\n ∣ s ∣ + (fold _+_ 0 (lmap ∣_∣ C)) ≡⟨⟩\n fold _+_ 0 (lmap ∣_∣ (s ∷ C)) ∎\n where\n a : All (λ x → x ⊆ ∁ s) C\n a = All.map (disj⇒⊆∁ ∘ Disj-sym) h\n c : ⋃ C ⊆ ∁ s\n c = pᵢ⊆q⇒⋃pᵢ⊆q-list (∁ s) C a\n e : Disj (⋃ C) s\n e = ⊆∁⇒disj c\n DisjsUC : Disj s (⋃ C)\n DisjsUC = Disj-sym e\n\n⋃-remove : ∀ {n} {L : List (Subset n)} →\n ∀ s → (s∈L : s ∈ℓ L) →\n (⋃ L) ≡ s ∪ ⋃ (L Any.─ s∈L)\n⋃-remove {n} {<>} _ = λ ()\n⋃-remove {n} {x ∷ xs} s (here px) = begin\n ⋃ (x ∷ xs) ≡⟨ refl ⟩\n x ∪ (⋃ xs) ≡˘⟨ cong (_∪ _) px ⟩\n s ∪ (⋃ xs) ≡⟨ cong (_ ∪_) refl ⟩\n s ∪ ⋃ ((x ∷ xs) Data.List.Base.─ fzero ) ≡⟨ cong (_ ∪_) refl ⟩\n s ∪ ⋃ ((x ∷ xs) Any.─ (here {P = P} px)) ∎\n where\n P : Pred (Subset n) lzero\n P = s ≡_\n\n⋃-remove {n} {x ∷ xs} s (there s∈L) = begin\n x ∪ (⋃ xs) ≡⟨ cong (x ∪_) (⋃-remove {L = xs} s s∈L) ⟩\n x ∪ (s ∪ ⋃ (xs Any.─ s∈L)) ≡˘⟨ ∪-assoc _ _ _ ⟩ -- TODO: -- use solver\n (x ∪ s) ∪ ⋃ (xs Any.─ s∈L) ≡⟨ cong (_∪ _) (∪-comm x s) ⟩\n (s ∪ x) ∪ ⋃ (xs Any.─ s∈L) ≡⟨ ∪-assoc _ _ _ ⟩\n s ∪ (x ∪ ⋃ (xs Any.─ s∈L)) ≡⟨ refl ⟩\n s ∪ ⋃ ((x ∷ xs) Any.─ (there s∈L)) ∎\n\ncover-⊤ : ∀ {n} → (L : List (Subset n)) →\n (∀ (x : Fin n) → Any (x ∈_) L ) →\n ⊤ {n} ≡ ⋃ L\n\ncover-⊤ {n} L ∃lx∈l = ⊆-antisym ⊤⊆⋃L (⊆-max (⋃ L)) where\n ⊤⊆⋃L : ⊤ ⊆ (⋃ L)\n ⊤⊆⋃L {x} _ = let\n (l , l∈ℓL , x∈l) = find {P = x ∈_} (∃lx∈l x)\n l⊆l∪* = p⊆p∪q {p = l} (⋃ (L Any.─ l∈ℓL))\n x∈l∪* = l⊆l∪* {x} x∈l\n in subst₂ _∈_ refl (sym (⋃-remove l l∈ℓL)) x∈l∪*\n\n-- 👇 not essential\n\n|s\\\\t| : ∀ {n : ℕ} → ∀ {S T : Subset n} → T ⊆ S → ∣ S \\\\ T ∣ ≡ ∣ S ∣ ∸ ∣ T ∣\n|s\\\\t| {.0} {[]} {T} t⊆s = begin\n ∣ [] \\\\ T ∣ ≡⟨ n≤0⇒n≡0 (∣p∩q∣≤∣p∣ [] (∁ T)) ⟩\n 0 ≡˘⟨ 0∸n≡0 ∣ T ∣ ⟩\n ∣ [] ∣ ∸ ∣ T ∣\n ∎\n|s\\\\t| {.(suc _)} {inside ∷ S} {inside ∷ T} t⊆s = |s\\\\t| {_} {S} {T} (drop-∷-⊆ t⊆s)\n|s\\\\t| {.(suc _)} {outside ∷ S} {outside ∷ T} t⊆s = |s\\\\t| {_} {S} {T} (drop-∷-⊆ t⊆s)\n|s\\\\t| {.(suc _)} {outside ∷ S} {inside ∷ T} t⊆s = let z = (t⊆s here)\n y = []=⇒lookup z\n w = not-¬ y\n in ⊥-elim (w refl)\n|s\\\\t| {(suc n)} {inside ∷ S} {outside ∷ T} t⊆s = sym (begin\n ∣ inside ∷ S ∣ ∸ ∣ outside ∷ T ∣ ≡⟨ refl ⟩\n (suc ∣ S ∣) ∸ ∣ outside ∷ T ∣ ≡⟨ cong ((suc ∣ S ∣) ∸_) (drop-outside T) ⟩\n (1 + ∣ S ∣) ∸ ∣ T ∣ ≡⟨ cong (_∸ ∣ T ∣) (Data.Nat.Properties.+-comm _ ∣ S ∣)⟩\n (∣ S ∣ + 1) ∸ ∣ T ∣ ≡⟨ +-∸-comm 1 (p⊆q⇒∣p∣≤∣q∣ (drop-∷-⊆ {n} {_} {_} {T} {S} t⊆s)) ⟩\n (∣ S ∣ ∸ ∣ T ∣) + 1 ≡⟨ Data.Nat.Properties.+-comm (∣ S ∣ ∸ ∣ T ∣) _ ⟩\n (suc (∣ S ∣ ∸ ∣ T ∣)) ≡˘⟨ cong suc (|s\\\\t| {n} {S} {T} (drop-∷-⊆ {n} t⊆s))⟩\n (suc ∣ S \\\\ T ∣) ≡⟨ refl ⟩\n ∣ (inside ∷ S) \\\\ (outside ∷ T) ∣ ∎)\n\nfst : ∀ {n} → (s : Subset n) → Nonempty s → Fin n\nfst {suc n} (x ∷ rest) ne with (∃-toSum ne)\n... | inj₁ _ = fzero\n... | inj₂ b = let w = drop-there (proj₂ b)\n z = (proj₁ b , w)\n in fsuc (fst rest z)\n\n\nrecord Partition (n : ℕ) : Set where\n field\n Carrier : Subset n\n size : ℕ\n -- try parts as Data.Vec.Functional\n -- or try parts as List (Subset n) for ease of updates\n parts : Fin size → Subset n\n -- nne : 0 ℕ.< m\n nnd : ∀ i → Nonempty (parts i)\n all-⊆ : ∀ i → (parts i) ⊆ Carrier\n disj : ∀ i j → i ≢ j → Disj (parts i) (parts j)\n cover : Carrier ≡ ⋃ (tab parts)\n\n traversal : Vec (Fin n) size\n traversal = Data.Vec.tabulate λ i → fst (parts i) (nnd i)\n\n _P∈ : (j : Fin n) → Dec ( j ∈ Carrier )\n j P∈ = (j ∈? Carrier)\n\n -- open import Data.Vec.Relation.Unary.Any {0ℓ} {Fin n}\n -- anyRel : {_≈_ : Rel (Fin n) 0ℓ } → Dec₂ _≈_ → (j : Fin n) → Dec (Any (j ≈_) traversal)\n -- anyRel _≈?_ j = any (j ≈?_) traversal\n\n -- do I need this for counting arguments?\n respects : Rel (Fin n) 0ℓ → Set _\n respects _≈_ = ∀ x y → x ≈ y → ∃ λ i → (x ∈ parts i) × (y ∈ parts i)\n\n -- proj i = index (proof anyRel ≈ j)\n -- ∀ i → tabulate (i ≈?_) ≡ proj i\n\n⊥P : ∀ {n} → Partition n\n⊥P {n} = record { Carrier = ⊥ {n} ;\n size = 0 ;\n parts = λ () ;\n all-⊆ = λ () ;\n nnd = λ () ;\n disj = λ i () ;\n cover = refl }\n\n------ has holes\n-- add : ∀ {n} {≈ : Rel (Fin n) 0ℓ } → Partition n → (Dec₂ ≈) → Fin n → Partition n\n-- add P ≈ j with (j P∈) where open Partition P\n-- ... | yes _ = P\n-- ... | no j∉P with (anyRel ≈ j) where open Partition P\n-- ... | yes p = {! !}\n-- ... | no ¬p = record { Carrier = Carrier ∪ ⁅ j ⁆ ;\n-- size = suc size ;\n-- parts = λ { fzero → ⁅ j ⁆ ;\n-- (fsuc k) → parts k } ;\n-- nnd = {! !} ;\n-- all-⊆ = {! !} ;\n-- disj = {! !} ;\n-- cover = {! !}\n-- } where open Partition P\n\n\n----junk👇--------------------------------------------------------\n-- ↓ : ∀ {n m : ℕ} → ∀ {S : Subset n} → ( 0 < m ) →\n-- (P : Partition S (suc m)) → Partition (S \\\\ Partition.p P fzero) m\n-- ↓ {_} {m} {S} 0\n-- tab0 {zero} m≡0 = refl\n--\n-- would follow trivially from a kind of guarded (dependent)\n-- fold fusion with h = ∣_∣ f = _∪_ and g = _+c_\n-- cc : ∀ {n m : ℕ} → {S : Subset n} →\n-- ∀ (P : Partition S m) → (card P) ≡ ∣ S ∣\n-- cc {n} {m = suc m'} {S} P with m' ≟ 0\n-- ... | yes m'≡0 = begin\n-- (card P) ≡⟨ refl ⟩\n-- fold _+c_ 0 (tab p) ≡⟨ cong (fold _+c_ 0) (tab0 {m'} {Subset n} {p} m'≡0) ⟩\n-- fold _+c_ 0 < p fzero > ≡⟨ refl ⟩\n-- (p fzero) +c 0 ≡⟨ refl ⟩\n-- -- (p fzero) +c (fold _+c_ 0 <>) ≡⟨ refl ⟩\n-- -- fold _+c_ 0 ((p fzero) ∷ <>) ≡⟨ refl ⟩\n-- ∣ (p fzero) ∣ + 0 ≡⟨ +-identityʳ _ ⟩\n-- ∣ (p fzero) ∣ ≡˘⟨ cong ∣_∣ (∪-identityʳ (p fzero)) ⟩\n-- ∣ (p fzero) ∪ ⊥ ∣ ≡˘⟨ refl ⟩\n-- ∣ ⋃ < (p fzero) > ∣ ≡˘⟨ cong ∣_∣ (cong ⋃ (tab0 {m'} {Subset n} {p} m'≡0)) ⟩\n-- ∣ ⋃ (tab p) ∣ ≡˘⟨ cong ∣_∣ cover ⟩\n-- ∣ S ∣ ∎ where\n-- open Partition P\n--\n-- ... | no ¬m'≡0 = begin\n-- (card P) ≡⟨⟩\n-- fold _+c_ 0 ((p fzero) ∷ tab (p ∘ fsuc)) ≡⟨⟩\n-- (p fzero) +c (fold _+c_ 0 (tab (p ∘ fsuc))) ≡⟨⟩\n-- ∣ (p fzero) ∣ + (fold _+c_ 0 (tab (p ∘ fsuc))) ≡˘⟨ cong (∣ (p fzero) ∣ +_) refl ⟩\n-- ∣ (p fzero) ∣ + card (↓ r P) ≡⟨ cong (_ +_) (cc (↓ r P)) ⟩\n-- ∣ (p fzero) ∣ + ∣ S \\\\ (p fzero) ∣ ≡⟨ cong (_ +_) (|s\\\\t| (all-⊆ fzero)) ⟩\n-- ∣ (p fzero) ∣ + ( ∣ S ∣ ∸ ∣ (p fzero) ∣ ) ≡˘⟨ +-∸-assoc ∣ (p fzero) ∣ (p⊆q⇒∣p∣≤∣q∣ (all-⊆ fzero)) ⟩\n-- (∣ (p fzero) ∣ + ∣ S ∣) ∸ ∣ (p fzero) ∣ ≡⟨ m+n∸m≡n ∣ (p fzero) ∣ ∣ S ∣ ⟩\n-- ∣ S ∣ ∎ where\n-- open Partition P\n-- r = (n≢0⇒n>0 ¬m'≡0)\n", "meta": {"hexsha": "a804d9a866b0628521dd94d1eb4d8fc3fb033864", "size": 22212, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/scratch/Subset.agda", "max_stars_repo_name": "zampino/ggt", "max_stars_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-17T11:10:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-28T05:48:39.000Z", "max_issues_repo_path": "src/scratch/Subset.agda", "max_issues_repo_name": "zampino/ggt", "max_issues_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af", "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/scratch/Subset.agda", "max_forks_repo_name": "zampino/ggt", "max_forks_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af", "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": 50.9449541284, "max_line_length": 191, "alphanum_fraction": 0.3130289933, "num_tokens": 9023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300048, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.3826509363194102}} {"text": "{-# OPTIONS --without-K #-}\n\n{- Our goal in this file is to observe some structure possessed by the\n universes of types, reflexive graphs, type families, and so on. Somewhat\n more precisely, we develop an imperfect structure of internal model of type\n theory, with enough ingredients to get some type theoretic developments off\n the ground.\n\n We begin with the basic structure of type dependency, with operations for\n context extension, weakening, substitution, and identity morphisms (the\n `variable rule'). Once this structure is implemented, we introduce the\n structure of usual type constructors Σ, Π, Id, the unit type, and ℕ. \n\n The reason this is an `imperfect' notion of model structure is that\n in our internal model structure, we have identifications in the role of\n judgmental equalities. This leads to the usual coherence problem, which we\n do not attempt to solve. As we said before, our goal is merely to postulate\n enough equalities so that we can introduce and work with the type\n constructors. We then proceed to develop some examples.\n-}\n\nmodule models where\n\nimport Lecture15\nopen Lecture15 public\n\nContexts :\n ( l : Level) → UU (lsuc l)\nContexts l = UU l\n\nFamilies :\n { l1 : Level} (l2 : Level) (ctx : Contexts l1) → UU (l1 ⊔ (lsuc l2))\nFamilies l2 ctx = ctx → UU l2\n\nTerms :\n { l1 l2 : Level} (l3 : Level)\n ( ctx : Contexts l1) (fam : Families l2 ctx) → UU (l1 ⊔ (l2 ⊔ (lsuc l3)))\nTerms l3 ctx fam = (Γ : ctx) → (fam Γ) → UU l3\n\nContext-Extensions :\n { l1 l2 : Level}\n ( ctx : Contexts l1) (fam : Families l2 ctx) → UU (l1 ⊔ l2)\nContext-Extensions ctx fam = (Γ : ctx) → (fam Γ) → ctx\n\nFamily-Extensions :\n { l1 l2 : Level}\n ( ctx : Contexts l1) (fam : Families l2 ctx)\n ( ctx-ext : Context-Extensions ctx fam) → UU (l1 ⊔ l2)\nFamily-Extensions ctx fam ctx-ext =\n ( Γ : ctx) → (A : fam Γ) → (fam (ctx-ext Γ A)) → fam Γ\n \nModel-Base :\n ( l1 l2 l3 : Level) → UU (lsuc l1 ⊔ (lsuc l2 ⊔ lsuc l3))\nModel-Base l1 l2 l3 =\n Σ ( Contexts l1)\n ( λ ctx → Σ (Families l2 ctx)\n ( λ fam → Σ (Terms l3 ctx fam)\n ( λ tm → Σ (Context-Extensions ctx fam) (Family-Extensions ctx fam))))\n\nHom-Model-Base :\n { l1 l2 l3 l1' l2' l3' : Level} →\n Model-Base l1 l2 l3 → Model-Base l1' l2' l3' → UU _\nHom-Model-Base\n ( pair ctx (pair fam (pair tm (pair ctx-ext fam-ext))))\n ( pair ctx' (pair fam' (pair tm' (pair ctx-ext' fam-ext')))) =\n Σ ( ctx → ctx')\n ( λ h-ctx → Σ ((Γ : ctx) → (fam Γ) → (fam' (h-ctx Γ)))\n ( λ h-fam →\n Σ ((Γ : ctx) (A : fam Γ) → (tm Γ A) → tm' (h-ctx Γ) (h-fam Γ A))\n ( λ h-tm →\n Σ ( (Γ : ctx) (A : fam Γ) →\n Id\n ( h-ctx (ctx-ext Γ A))\n ( ctx-ext' (h-ctx Γ) (h-fam Γ A)))\n ( λ h-ctx-ext → (Γ : ctx) (A : fam Γ) (B : fam (ctx-ext Γ A)) →\n Id\n ( h-fam Γ (fam-ext Γ A B))\n ( fam-ext'\n ( h-ctx Γ)\n ( h-fam Γ A)\n ( tr fam' (h-ctx-ext Γ A) (h-fam (ctx-ext Γ A) B)))))))\n\nAssoc-Ctx-ext :\n { l1 l2 l3 : Level} (M : Model-Base l1 l2 l3) → UU (l1 ⊔ l2)\nAssoc-Ctx-ext (pair ctx (pair fam (pair tm (pair ctx-ext fam-ext)))) =\n ( Γ : ctx) (A : fam Γ) (B : fam (ctx-ext Γ A)) →\n Id (ctx-ext (ctx-ext Γ A) B) (ctx-ext Γ (fam-ext Γ A B))\n\nSlice-Model-Base :\n { l1 l2 l3 : Level} (M : Model-Base l1 l2 l3)\n ( assoc : Assoc-Ctx-ext M) →\n ( Γ : pr1 M) → Model-Base l2 l2 l3\nSlice-Model-Base\n ( pair ctx (pair fam (pair tm (pair ctx-ext fam-ext)))) assoc Γ =\n pair (fam Γ)\n ( pair (λ A → fam (ctx-ext Γ A))\n ( pair (λ A B → tm (ctx-ext Γ A) B)\n ( pair (fam-ext Γ)\n ( λ A B C →\n fam-ext (ctx-ext Γ A) B (tr fam (inv (assoc Γ A B)) C)))))\n\nEmpty-context :\n { l1 l2 l3 : Level} (M : Model-Base l1 l2 l3) → UU l1\nEmpty-context M = pr1 M\n\nAxiom-Empty-Context :\n { l1 l2 l3 : Level}\n (M : Model-Base l1 l2 l3) (empty-ctx : Empty-context M) → UU (l1 ⊔ l2)\nAxiom-Empty-Context\n ( pair ctx (pair fam (pair tm (pair ctx-ext fam-ext)))) empty-ctx =\n is-equiv (ctx-ext empty-ctx)\n", "meta": {"hexsha": "223fbfdcba334d12f3a82c758436fd12c121b6f2", "size": 4067, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Agda/models.agda", "max_stars_repo_name": "tadejpetric/HoTT-Intro", "max_stars_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 333, "max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z", "max_issues_repo_path": "Agda/models.agda", "max_issues_repo_name": "tadejpetric/HoTT-Intro", "max_issues_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z", "max_forks_repo_path": "Agda/models.agda", "max_forks_repo_name": "tadejpetric/HoTT-Intro", "max_forks_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z", "avg_line_length": 36.3125, "max_line_length": 78, "alphanum_fraction": 0.5832308827, "num_tokens": 1410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6334102636778403, "lm_q2_score": 0.6039318337259584, "lm_q1q2_score": 0.3825366220438009}} {"text": "-- Andreas, 2017-07-26\n-- Better error message when constructor not fully applied.\n\nopen import Agda.Builtin.Nat\n\ntest : (Nat → Nat) → Nat\ntest suc = suc zero\n\n-- WAS: Type mismatch\n-- NOW: Cannot pattern match on functions\n-- when checking that the pattern suc has type Nat → Nat\n", "meta": {"hexsha": "2a0e06efbb6ea8fb3fd89a493d1eab774bf4a144", "size": 281, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/MatchOnFunctions.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/MatchOnFunctions.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/MatchOnFunctions.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": 23.4166666667, "max_line_length": 59, "alphanum_fraction": 0.7224199288, "num_tokens": 74, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6001883592602051, "lm_q2_score": 0.6370307944803831, "lm_q1q2_score": 0.38233846733740606}} {"text": "open import Agda.Builtin.Nat\nopen import Agda.Builtin.Unit\nopen import Agda.Builtin.Reflection renaming (bindTC to _>>=_)\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Sigma\nopen import Agda.Builtin.Equality\n\ninfixr -1 _$_\n_$_ : ∀ {a b}{A : Set a}{B : Set b} → (A → B) → A → B\nf $ x = f x\n\nmap : ∀ {a b}{A : Set a}{B : Set b} → (A → B) → List A → List B\nmap f [] = []\nmap f (x ∷ xs) = f x ∷ map f xs\n\nreverse : ∀ {a}{A : Set a} → List A → List A\nreverse {A = A} xs = reverseAcc xs []\n where\n reverseAcc : List A → List A → List A\n reverseAcc [] a = a\n reverseAcc (x ∷ xs) a = reverseAcc xs (x ∷ a)\n\ndata Fin : Nat → Set where\n zero : ∀ {n} → Fin (suc n)\n suc : ∀ {n} → Fin n → Fin (suc n)\n\ninfixr 5 _∷_\ndata Vec {a} (A : Set a) : Nat → Set a where\n [] : Vec A zero\n _∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n)\n\ndata Ix : (d : Nat) → (s : Vec Nat d) → Set where\n [] : Ix 0 []\n _∷_ : ∀ {d s x} → Fin x → (ix : Ix d s) → Ix (suc d) (x ∷ s)\n\nrecord Ar {a} (X : Set a) (d : Nat) (s : Vec Nat d) : Set a where\n constructor imap\n field sel : Ix d s → X\nopen Ar public\n\n\nfoo : Nat → Nat\nfoo x = 1 + x\n\ntest-ar : ∀ {n} → (a : Ar Nat 1 (n ∷ [])) → Ar Nat 1 (n ∷ [])\ntest-ar (imap f) = imap λ iv → foo $ foo $ f iv\n\n-- Make sure that the telescope is also reconstructed when\n-- calling getDefinition with withReconstructed.\nmacro\n z : Name → Term → TC ⊤\n z n hole = do\n (function (clause tel ps t ∷ [])) ←\n withReconstructed $ getDefinition n\n where _ → quoteTC \"ERROR\" >>= unify hole\n t ← withReconstructed\n $ inContext (reverse tel)\n $ normalise t\n quoteTC t >>= unify hole\n\n\ntest₁ : z test-ar\n ≡ con (quote imap) (_ ∷ _ ∷ _ ∷ _ ∷\n arg _ (lam _ (abs \"iv\"\n (con (quote Nat.suc) _)))\n ∷ [])\ntest₁ = refl\n\n\n-- Make sure that getType behaves correctly under withReconstructed.\nmacro\n q : Name → Term → TC ⊤\n q n hole = do\n t ← withReconstructed $\n getType n\n t ← withReconstructed $\n normalise t\n quoteTC t >>= unify hole\n\ntest₂ : Term\ntest₂ = q test-ar\n", "meta": {"hexsha": "8f6ef819f9f21e126545495de01f62e01c8ec271", "size": 2134, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/recons-tele.agda", "max_stars_repo_name": "KDr2/agda", "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-05T00:25:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:25:14.000Z", "max_issues_repo_path": "test/Succeed/recons-tele.agda", "max_issues_repo_name": "Seanpm2001-Agda-lang/agda", "max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_forks_repo_path": "test/Succeed/recons-tele.agda", "max_forks_repo_name": "Seanpm2001-Agda-lang/agda", "max_forks_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0243902439, "max_line_length": 68, "alphanum_fraction": 0.5440487348, "num_tokens": 751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.66192288918838, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.38225740061669117}} {"text": "------------------------------------------------------------------------\n-- A large class of algebraic structures satisfies the property that\n-- isomorphic instances of a structure are equal (assuming univalence)\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\n-- This code has been superseded by more recent developments. See\n-- README.agda.\n\n-- This module has been developed in collaboration with Thierry\n-- Coquand.\n\nopen import Equality\n\nmodule Univalence-axiom.Isomorphism-implies-equality\n {reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where\n\nopen import Bijection eq\nopen Derived-definitions-and-properties eq\nopen import Equivalence eq as Eq\nopen import H-level eq\nopen import H-level.Closure eq\nopen import Logical-equivalence\nopen import Prelude\nopen import Univalence-axiom eq\n\n------------------------------------------------------------------------\n-- N-ary functions\n\n-- N-ary functions.\n\n_^_⟶_ : Type → ℕ → Type → Type\nA ^ zero ⟶ B = B\nA ^ suc n ⟶ B = A → A ^ n ⟶ B\n\n-- N-ary function morphisms.\n\nIs-_-ary-morphism :\n (n : ℕ) {A B : Type} → A ^ n ⟶ A → B ^ n ⟶ B → (A → B) → Type\nIs- zero -ary-morphism f₁ f₂ m = m f₁ ≡ f₂\nIs- suc n -ary-morphism f₁ f₂ m =\n ∀ x → Is- n -ary-morphism (f₁ x) (f₂ (m x)) m\n\nabstract\n\n -- If _↔_.to m is a morphism, then _↔_.from m is also a morphism.\n\n from-also-_-ary-morphism :\n (n : ℕ) {A B : Type} (f₁ : A ^ n ⟶ A) (f₂ : B ^ n ⟶ B) (m : A ↔ B) →\n Is- n -ary-morphism f₁ f₂ (_↔_.to m) →\n Is- n -ary-morphism f₂ f₁ (_↔_.from m)\n from-also- zero -ary-morphism f₁ f₂ m is = _↔_.to-from m is\n from-also- suc n -ary-morphism f₁ f₂ m is = λ x →\n from-also- n -ary-morphism (f₁ (from x)) (f₂ x) m\n (subst (λ y → Is- n -ary-morphism (f₁ (from x)) (f₂ y) to)\n (right-inverse-of x)\n (is (from x)))\n where open _↔_ m\n\n-- Changes the type of an n-ary function.\n\ncast : {A₁ A₂ : Type} → A₁ ≃ A₂ → ∀ n → A₁ ^ n ⟶ A₁ → A₂ ^ n ⟶ A₂\ncast A₁≃A₂ zero = _≃_.to A₁≃A₂\ncast A₁≃A₂ (suc n) = λ f x → cast A₁≃A₂ n (f (_≃_.from A₁≃A₂ x))\n\nabstract\n\n -- Cast simplification lemma.\n\n cast-id : {A : Type} →\n (∀ n → Extensionality′ A (λ _ → A ^ n ⟶ A)) →\n ∀ n (f : A ^ n ⟶ A) → cast Eq.id n f ≡ f\n cast-id ext zero f = refl f\n cast-id ext (suc n) f = ext n $ λ x → cast-id ext n (f x)\n\n -- We can express cast as an instance of subst (assuming\n -- extensionality and univalence).\n\n cast-is-subst :\n (∀ {A : Type} n → Extensionality′ A (λ _ → A ^ n ⟶ A)) →\n {A₁ A₂ : Type}\n (univ : Univalence′ A₁ A₂)\n (A₁≃A₂ : A₁ ≃ A₂) (n : ℕ) (f : A₁ ^ n ⟶ A₁) →\n cast A₁≃A₂ n f ≡ subst (λ C → C ^ n ⟶ C) (≃⇒≡ univ A₁≃A₂) f\n cast-is-subst ext univ A₁≃A₂ n =\n transport-theorem\n (λ A → A ^ n ⟶ A)\n (λ A≃B f → cast A≃B n f)\n (cast-id ext n)\n univ\n A₁≃A₂\n\n -- If there is an isomorphism from f₁ to f₂, then the corresponding\n -- instance of cast maps f₁ to f₂ (assuming extensionality).\n\n cast-isomorphism :\n {A₁ A₂ : Type} →\n (∀ n → Extensionality′ A₂ (λ _ → A₂ ^ n ⟶ A₂)) →\n (A₁≃A₂ : A₁ ≃ A₂)\n (n : ℕ) (f₁ : A₁ ^ n ⟶ A₁) (f₂ : A₂ ^ n ⟶ A₂) →\n Is- n -ary-morphism f₁ f₂ (_≃_.to A₁≃A₂) →\n cast A₁≃A₂ n f₁ ≡ f₂\n cast-isomorphism ext A₁≃A₂ zero f₁ f₂ is = is\n cast-isomorphism ext A₁≃A₂ (suc n) f₁ f₂ is = ext n $ λ x →\n cast A₁≃A₂ n (f₁ (from x)) ≡⟨ cast-isomorphism ext A₁≃A₂ n _ _ (is (from x)) ⟩\n f₂ (to (from x)) ≡⟨ cong f₂ (right-inverse-of x) ⟩∎\n f₂ x ∎\n where open _≃_ A₁≃A₂\n\n -- Combining the results above we get the following: if there is an\n -- isomorphism from f₁ to f₂, then the corresponding instance of\n -- subst maps f₁ to f₂ (assuming extensionality and univalence).\n\n subst-isomorphism :\n (∀ {A : Type} n → Extensionality′ A (λ _ → A ^ n ⟶ A)) →\n {A₁ A₂ : Type}\n (univ : Univalence′ A₁ A₂)\n (A₁≃A₂ : A₁ ≃ A₂)\n (n : ℕ) (f₁ : A₁ ^ n ⟶ A₁) (f₂ : A₂ ^ n ⟶ A₂) →\n Is- n -ary-morphism f₁ f₂ (_≃_.to A₁≃A₂) →\n subst (λ A → A ^ n ⟶ A) (≃⇒≡ univ A₁≃A₂) f₁ ≡ f₂\n subst-isomorphism ext univ A₁≃A₂ n f₁ f₂ is =\n subst (λ A → A ^ n ⟶ A) (≃⇒≡ univ A₁≃A₂) f₁ ≡⟨ sym $ cast-is-subst ext univ A₁≃A₂ n f₁ ⟩\n cast A₁≃A₂ n f₁ ≡⟨ cast-isomorphism ext A₁≃A₂ n f₁ f₂ is ⟩∎\n f₂ ∎\n\n------------------------------------------------------------------------\n-- A class of algebraic structures\n\n-- An algebraic structure universe.\n\nmutual\n\n -- Codes for structures.\n\n infixl 5 _+operator_ _+axiom_\n\n data Structure : Type₁ where\n empty : Structure\n\n -- N-ary functions.\n _+operator_ : Structure → (n : ℕ) → Structure\n\n -- Arbitrary /propositional/ axioms.\n _+axiom_ : (s : Structure)\n (P : ∃ λ (P : (A : Type) → ⟦ s ⟧ A → Type) →\n ∀ A s → Is-proposition (P A s)) →\n Structure\n\n -- Interpretation of the codes.\n\n ⟦_⟧ : Structure → Type → Type₁\n ⟦ empty ⟧ A = ↑ _ ⊤\n ⟦ s +operator n ⟧ A = ⟦ s ⟧ A × (A ^ n ⟶ A)\n ⟦ s +axiom (P , P-prop) ⟧ A = Σ (⟦ s ⟧ A) (P A)\n\n-- Top-level interpretation.\n\n⟪_⟫ : Structure → Type₁\n⟪ s ⟫ = ∃ ⟦ s ⟧\n\n-- Morphisms.\n\nIs-structure-morphism :\n (s : Structure) →\n {A B : Type} → ⟦ s ⟧ A → ⟦ s ⟧ B →\n (A → B) → Type\nIs-structure-morphism empty _ _ m = ⊤\nIs-structure-morphism (s +axiom _) (s₁ , _) (s₂ , _) m =\n Is-structure-morphism s s₁ s₂ m\nIs-structure-morphism (s +operator n) (s₁ , op₁) (s₂ , op₂) m =\n Is-structure-morphism s s₁ s₂ m × Is- n -ary-morphism op₁ op₂ m\n\n-- Isomorphisms.\n\nIsomorphism : (s : Structure) → ⟪ s ⟫ → ⟪ s ⟫ → Type\nIsomorphism s (A₁ , s₁) (A₂ , s₂) =\n ∃ λ (m : A₁ ↔ A₂) → Is-structure-morphism s s₁ s₂ (_↔_.to m)\n\nabstract\n\n -- If _↔_.to m is a morphism, then _↔_.from m is also a morphism.\n\n from-also-structure-morphism :\n (s : Structure) →\n {A B : Type} {s₁ : ⟦ s ⟧ A} {s₂ : ⟦ s ⟧ B} →\n (m : A ↔ B) →\n Is-structure-morphism s s₁ s₂ (_↔_.to m) →\n Is-structure-morphism s s₂ s₁ (_↔_.from m)\n from-also-structure-morphism empty m = _\n from-also-structure-morphism (s +axiom _) m =\n from-also-structure-morphism s m\n from-also-structure-morphism (s +operator n) m =\n Σ-map (from-also-structure-morphism s m)\n (from-also- n -ary-morphism _ _ m)\n\n -- Isomorphic structures are equal (assuming univalence).\n\n isomorphic-equal :\n Univalence′ (Type ²/≡) Type →\n Univalence lzero →\n (s : Structure) (s₁ s₂ : ⟪ s ⟫) →\n Isomorphism s s₁ s₂ → s₁ ≡ s₂\n isomorphic-equal univ₁ univ₂\n s (A₁ , s₁) (A₂ , s₂) (m , is) =\n\n (A₁ , s₁) ≡⟨ Σ-≡,≡→≡ A₁≡A₂ (lemma s s₁ s₂ is) ⟩∎\n (A₂ , s₂) ∎\n\n where\n open _↔_ m\n\n -- Extensionality follows from univalence.\n\n ext : {A : Type} {B : A → Type} → Extensionality′ A B\n ext = dependent-extensionality′ univ₁ (λ _ → univ₂)\n\n -- The presence of the bijection implies that the structure's\n -- underlying types are equal (due to univalence).\n\n A₁≡A₂ : A₁ ≡ A₂\n A₁≡A₂ = _≃_.from (≡≃≃ univ₂) $ ↔⇒≃ m\n\n -- We can lift subst-isomorphism to structures by recursion on\n -- structure codes.\n\n lemma : (s : Structure)\n (s₁ : ⟦ s ⟧ A₁) (s₂ : ⟦ s ⟧ A₂) →\n Is-structure-morphism s s₁ s₂ to →\n subst ⟦ s ⟧ A₁≡A₂ s₁ ≡ s₂\n lemma empty _ _ _ = refl _\n\n lemma (s +axiom (P , P-prop)) (s₁ , ax₁) (s₂ , ax₂) is =\n subst (λ A → Σ (⟦ s ⟧ A) (P A)) A₁≡A₂ (s₁ , ax₁) ≡⟨ push-subst-pair′ ⟦ s ⟧ (uncurry P) (lemma s s₁ s₂ is) ⟩\n (s₂ , _) ≡⟨ cong (_,_ s₂) $ P-prop _ _ _ _ ⟩∎\n (s₂ , ax₂) ∎\n\n lemma (s +operator n) (s₁ , op₁) (s₂ , op₂) (is-s , is-o) =\n subst (λ A → ⟦ s ⟧ A × (A ^ n ⟶ A)) A₁≡A₂ (s₁ , op₁) ≡⟨ push-subst-pair′ ⟦ s ⟧ (λ { (A , _) → A ^ n ⟶ A }) (lemma s s₁ s₂ is-s) ⟩\n\n (s₂ , subst₂ (λ { (A , _) → A ^ n ⟶ A }) A₁≡A₂\n (lemma s s₁ s₂ is-s) op₁) ≡⟨ cong (_,_ s₂) $ subst₂-proj₁ (λ A → A ^ n ⟶ A) ⟩\n\n (s₂ , subst (λ A → A ^ n ⟶ A) A₁≡A₂ op₁) ≡⟨ cong (_,_ s₂) $ subst-isomorphism (λ _ → ext) univ₂ (↔⇒≃ m) n op₁ op₂ is-o ⟩∎\n (s₂ , op₂) ∎\n\n------------------------------------------------------------------------\n-- Some example structures\n\n-- Example: magmas.\n\nmagma : Structure\nmagma = empty +operator 2\n\nMagma : Type₁\nMagma = ⟪ magma ⟫\n\nprivate\n\n -- An unfolding of Magma.\n\n Magma-unfolded : Magma ≡ ∃ λ (A : Type) → ↑ _ ⊤ × (A → A → A)\n Magma-unfolded = refl _\n\n-- Example: semigroups. The definition uses extensionality to prove\n-- that the axioms are propositional. Note that one axiom states that\n-- the underlying type is a set. This assumption is used to prove that\n-- the other axiom is propositional.\n\nsemigroup : Extensionality lzero lzero → Structure\nsemigroup ext =\n empty\n\n +axiom\n ( (λ A _ → Is-set A)\n , is-set-prop\n )\n\n +operator 2\n\n +axiom\n ( (λ { _ (_ , _∙_) →\n ∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) })\n , assoc-prop\n )\n\n where\n is-set-prop = λ _ _ → H-level-propositional ext 2\n\n assoc-prop = λ { _ ((_ , A-set) , _) →\n Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n A-set\n }\n\nSemigroup : Extensionality lzero lzero → Type₁\nSemigroup ext = ⟪ semigroup ext ⟫\n\nprivate\n\n -- An unfolding of Semigroup.\n\n Semigroup-unfolded :\n (ext : Extensionality lzero lzero) →\n Semigroup ext ≡ Σ\n Type λ A → Σ (Σ (Σ (↑ _ ⊤) λ _ →\n Is-set A ) λ _ →\n A → A → A ) λ { (_ , _∙_) →\n ∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) }\n Semigroup-unfolded _ = refl _\n\n-- Example: abelian groups.\n\nabelian-group : Extensionality lzero lzero → Structure\nabelian-group ext =\n empty\n\n -- The underlying type is a set.\n +axiom\n ( (λ A _ → Is-set A)\n , is-set-prop\n )\n\n -- The binary group operation.\n +operator 2\n\n -- Commutativity.\n +axiom\n ( (λ { _ (_ , _∙_) →\n ∀ x y → (x ∙ y) ≡ (y ∙ x) })\n , comm-prop\n )\n\n -- Associativity.\n +axiom\n ( (λ { _ ((_ , _∙_) , _) →\n ∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) })\n , assoc-prop\n )\n\n -- Identity.\n +operator 0\n\n -- Left identity.\n +axiom\n ( (λ { _ ((((_ , _∙_) , _) , _) , e) →\n ∀ x → (e ∙ x) ≡ x })\n , left-identity-prop\n )\n\n -- Right identity.\n +axiom\n ( (λ { _ (((((_ , _∙_) , _) , _) , e) , _) →\n ∀ x → (x ∙ e) ≡ x })\n , right-identity-prop\n )\n\n -- Inverse.\n +operator 1\n\n -- Left inverse.\n +axiom\n ( (λ { _ (((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) →\n ∀ x → ((x ⁻¹) ∙ x) ≡ e })\n , left-inverse-prop\n )\n\n -- Right inverse.\n +axiom\n ( (λ { _ ((((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) , _) →\n ∀ x → (x ∙ (x ⁻¹)) ≡ e })\n , right-inverse-prop\n )\n\n where\n is-set-prop = λ _ _ → H-level-propositional ext 2\n\n comm-prop =\n λ { _ ((_ , A-set) , _) →\n Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n A-set\n }\n\n assoc-prop =\n λ { _ (((_ , A-set) , _) , _) →\n Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n A-set\n }\n\n left-identity-prop =\n λ { _ (((((_ , A-set) , _) , _) , _) , _) →\n Π-closure ext 1 λ _ →\n A-set\n }\n\n right-identity-prop =\n λ { _ ((((((_ , A-set) , _) , _) , _) , _) , _) →\n Π-closure ext 1 λ _ →\n A-set\n }\n\n left-inverse-prop =\n λ { _ ((((((((_ , A-set) , _) , _) , _) , _) , _) , _) , _) →\n Π-closure ext 1 λ _ →\n A-set\n }\n\n right-inverse-prop =\n λ { _ (((((((((_ , A-set) , _) , _) , _) , _) , _) , _) , _) , _) →\n Π-closure ext 1 λ _ →\n A-set\n }\n\nAbelian-group : Extensionality lzero lzero → Type₁\nAbelian-group ext = ⟪ abelian-group ext ⟫\n\nprivate\n\n -- An unfolding of Abelian-group. Note that the inner structure is\n -- left-nested.\n\n Abelian-group-unfolded :\n (ext : Extensionality lzero lzero) →\n Abelian-group ext ≡ Σ\n Type λ A → Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (↑ _ ⊤) λ _ →\n Is-set A ) λ _ →\n A → A → A ) λ { (_ , _∙_) →\n ∀ x y → (x ∙ y) ≡ (y ∙ x) }) λ { ((_ , _∙_) , _) →\n ∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) }) λ _ →\n A ) λ { ((((_ , _∙_) , _) , _) , e) →\n ∀ x → (e ∙ x) ≡ x }) λ { (((((_ , _∙_) , _) , _) , e) , _) →\n ∀ x → (x ∙ e) ≡ x }) λ _ →\n A → A ) λ { (((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) →\n ∀ x → ((x ⁻¹) ∙ x) ≡ e }) λ { ((((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) , _) →\n ∀ x → (x ∙ (x ⁻¹)) ≡ e }\n\n Abelian-group-unfolded _ = refl _\n\n------------------------------------------------------------------------\n-- Right-nested structures\n\n-- Right-nested structures are arguably easier to define (see the\n-- example below). However, the following class of right-nested\n-- structures is in some sense different from the class above. Take\n-- \"operator 0 f : Structureʳ Bool\", for instance. The /shape/ of f op\n-- can vary depending on whether the operator op is true or false.\n--\n-- One could perhaps avoid this issue by only considering values of\n-- type ∀ A → Structureʳ A. However, it is not obvious how to convert\n-- elements of this type to elements of type Structure in a\n-- meaning-preserving way. Furthermore it seems to be awkward to\n-- define things like Is-structure-isomorphism when using values of\n-- type ∀ A → Structureʳ A (see the definition of\n-- Is-structure-isomorphismʳ below).\n\n-- Codes. (Note that these structures are defined for a single\n-- underlying type.)\n\ndata Structureʳ (A : Type) : Type₁ where\n empty : Structureʳ A\n\n -- N-ary functions.\n operator : (n : ℕ)\n (s : A ^ n ⟶ A → Structureʳ A) →\n Structureʳ A\n\n -- Arbitrary /propositional/ axioms.\n axiom : (P : Type)\n (P-prop : Is-proposition P)\n (s : P → Structureʳ A) →\n Structureʳ A\n\n-- Interpretation of the codes.\n\n⟦_⟧ʳ : {A : Type} → Structureʳ A → Type₁\n⟦ empty ⟧ʳ = ↑ _ ⊤\n⟦ operator n s ⟧ʳ = ∃ λ op → ⟦ s op ⟧ʳ\n⟦ axiom P P-prop s ⟧ʳ = ∃ λ p → ⟦ s p ⟧ʳ\n\n-- Top-level interpretation.\n\n⟪_⟫ʳ : (∀ A → Structureʳ A) → Type₁\n⟪ s ⟫ʳ = ∃ λ A → ⟦ s A ⟧ʳ\n\n-- The property of being an isomorphism.\n\nIs-structure-isomorphismʳ :\n (s : ∀ A → Structureʳ A) →\n {A B : Type} → ⟦ s A ⟧ʳ → ⟦ s B ⟧ʳ →\n A ↔ B → Type\nIs-structure-isomorphismʳ s {A} {B} S₁ S₂ m =\n helper (s A) (s B) S₁ S₂\n where\n helper : (s₁ : Structureʳ A) (s₂ : Structureʳ B) →\n ⟦ s₁ ⟧ʳ → ⟦ s₂ ⟧ʳ → Type\n helper empty empty _ _ = ⊤\n helper (operator n₁ s₁) (operator n₂ s₂) (op₁ , S₁) (op₂ , S₂) =\n (∃ λ (eq : n₁ ≡ n₂) →\n Is- n₁ -ary-morphism\n op₁ (subst (λ n → B ^ n ⟶ B) (sym eq) op₂) (_↔_.to m)) ×\n helper (s₁ op₁) (s₂ op₂) S₁ S₂\n helper (axiom P₁ _ s₁) (axiom P₂ _ s₂) (p₁ , S₁) (p₂ , S₂) =\n helper (s₁ p₁) (s₂ p₂) S₁ S₂\n\n helper empty (operator n s₂) _ _ = ⊥\n helper empty (axiom P P-prop s₂) _ _ = ⊥\n helper (operator n s₁) empty _ _ = ⊥\n helper (operator n s₁) (axiom P P-prop s₂) _ _ = ⊥\n helper (axiom P P-prop s₁) empty _ _ = ⊥\n helper (axiom P P-prop s₁) (operator n s₂) _ _ = ⊥\n\n-- Example: semigroups.\n\nsemigroupʳ :\n Extensionality lzero lzero →\n ∀ A → Structureʳ A\nsemigroupʳ ext A =\n axiom (Is-set A)\n\n (H-level-propositional ext 2)\n\n λ A-set →\n\n operator 2 λ _∙_ →\n\n axiom (∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z))\n\n (Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n A-set)\n\n λ _ →\n\n empty\n\nSemigroupʳ : Extensionality lzero lzero → Type₁\nSemigroupʳ ext = ⟪ semigroupʳ ext ⟫ʳ\n\nprivate\n\n -- An unfolding of Semigroupʳ.\n\n Semigroupʳ-unfolded :\n (ext : Extensionality lzero lzero) →\n Semigroupʳ ext ≡\n ∃ λ (A : Type) →\n ∃ λ (_ : Is-set A) →\n ∃ λ (_∙_ : A → A → A) →\n ∃ λ (_ : ∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z)) →\n ↑ _ ⊤\n Semigroupʳ-unfolded _ = refl _\n", "meta": {"hexsha": "16a8cf61bbbbaa833a47db8440e47190f544c176", "size": 16412, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Univalence-axiom/Isomorphism-implies-equality.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/Univalence-axiom/Isomorphism-implies-equality.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/Univalence-axiom/Isomorphism-implies-equality.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": 29.4121863799, "max_line_length": 140, "alphanum_fraction": 0.4942115525, "num_tokens": 6132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.38225739291383515}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT hiding (left; right)\nimport homotopy.WedgeExtension as WedgeExt\n\nmodule homotopy.blakersmassey.CoherenceData {i j k}\n {A : Type i} {B : Type j} (Q : A → B → Type k)\n m (f-conn : ∀ a → is-connected (S m) (Σ B (λ b → Q a b)))\n n (g-conn : ∀ b → is-connected (S n) (Σ A (λ a → Q a b)))\n where\n\nopen import homotopy.blakersmassey.Pushout Q\n\n{- goal :\n Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r)\n ≃ Trunc (m +2+ n) (hfiber bmglue r)\n-}\n\nprivate\n swap-level :\n (m +2+ n) -Type (lmax i (lmax j k))\n → (n +2+ m) -Type (lmax i (lmax j k))\n swap-level (X , level) = X , new-level where\n abstract new-level = transport (λ o → has-level o X) (+2+-comm m n) level\n\nα₁=α₁α₂⁻¹α₂ : ∀ {p₁ p₂ p₃ : BMPushout} (α₁ : p₁ == p₂) (α₂ : p₃ == p₂)\n → α₁ == α₁ ∙' ! α₂ ∙' α₂\nα₁=α₁α₂⁻¹α₂ _ idp = idp\n\nα₁=α₂α₂⁻¹α₁ : ∀ {p₁ p₂ p₃ : BMPushout} (α₁ : p₁ == p₂) (α₂ : p₁ == p₃)\n → α₁ == α₂ ∙' ! α₂ ∙' α₁\nα₁=α₂α₂⁻¹α₁ idp α₂ = ! (!-inv'-r α₂)\n\nprivate\n path-lemma₁ : ∀ {a₀ a₁ b} (q₀ : Q a₀ b) (q₁ : Q a₁ b)\n → bmglue q₀ == bmglue q₀ ∙' ! (bmglue q₁) ∙' bmglue q₁\n path-lemma₁ q₀ q₁ = α₁=α₁α₂⁻¹α₂ (bmglue q₀) (bmglue q₁)\n\n path-lemma₂ : ∀ {a b₀ b₁} (q₀ : Q a b₀) (q₁ : Q a b₁)\n → bmglue q₀ == bmglue q₁ ∙' ! (bmglue q₁) ∙' bmglue q₀\n path-lemma₂ q₀ q₁ = α₁=α₂α₂⁻¹α₁ (bmglue q₀) (bmglue q₁)\n\n abstract\n path-coherence : ∀ {a b} (q : Q a b)\n → path-lemma₁ q q == path-lemma₂ q q\n path-coherence q = lemma (bmglue q) where\n lemma : ∀ {p₀ p₁ : BMPushout} (path : p₀ == p₁)\n → α₁=α₁α₂⁻¹α₂ path path == α₁=α₂α₂⁻¹α₁ path path\n lemma idp = idp\n\nmodule To {a₁ b₀} (q₁₀ : Q a₁ b₀) where\n U = Σ A λ a → Q a b₀\n u₀ : U\n u₀ = (a₁ , q₁₀)\n\n V = Σ B λ b → Q a₁ b\n v₀ : V\n v₀ = (b₀ , q₁₀)\n\n P : U → V → Type (lmax i (lmax j k))\n P u v = (r : bmleft (fst u) == bmright (fst v))\n → bmglue (snd u) ∙' ! (bmglue q₁₀) ∙' bmglue (snd v) == r\n → Trunc (m +2+ n) (hfiber bmglue r)\n\n template : ∀ (u : U) (v : V)\n → (r : bmleft (fst u) == bmright (fst v))\n → (shift : bmglue (snd u) ∙' ! (bmglue q₁₀) ∙' bmglue (snd v) == r)\n → ∀ q₀₁ → bmglue q₀₁ == bmglue (snd u) ∙' ! (bmglue q₁₀) ∙' bmglue (snd v)\n → Trunc (m +2+ n) (hfiber bmglue r)\n template u v r shift q₀₁ path = [ q₀₁ , path ∙' shift ]\n\n f = λ u r shift → template u v₀ r shift (snd u) (path-lemma₁ (snd u) q₁₀)\n g = λ v r shift → template u₀ v r shift (snd v) (path-lemma₂ (snd v) q₁₀)\n p' = λ r shift → ap (template u₀ v₀ r shift q₁₀) (path-coherence q₁₀)\n p = λ= λ r → λ= λ shift → p' r shift\n\n args : WedgeExt.args {A = U} {a₀ = u₀} {B = V} {b₀ = v₀}\n args = record {\n n = n; m = m;\n cA = g-conn b₀;\n cB = f-conn a₁;\n P = λ u v → swap-level $ P u v , Π-level λ _ → Π-level λ _ → Trunc-level;\n f = f; g = g; p = p}\n\n ext : ∀ u v → P u v\n ext = WedgeExt.ext args\n\n β-l : ∀ u r shift → ext u v₀ r shift == f u r shift\n β-l u r shift = app= (app= (WedgeExt.β-l u) r) shift\n\n β-r : ∀ v r shift → ext u₀ v r shift == g v r shift\n β-r v r shift = app= (app= (WedgeExt.β-r v) r) shift\n\n abstract\n coh : ∀ r shift → ! (β-l u₀ r shift) ∙ β-r v₀ r shift == p' r shift\n coh r shift =\n ! (β-l u₀ r shift) ∙ β-r v₀ r shift\n =⟨ ap (_∙ β-r v₀ r shift) (!-ap (_$ shift) (app= (WedgeExt.β-l u₀) r))\n ∙ ∙-ap (_$ shift)\n (! (app= (WedgeExt.β-l {r = args} u₀) r))\n (app= (WedgeExt.β-r {r = args} v₀) r)\n ∙ ap (λ p → app= p shift)\n ( ap (_∙ app= (WedgeExt.β-r {r = args} v₀) r)\n (!-ap (_$ r) (WedgeExt.β-l {r = args} u₀))\n ∙ ∙-ap (_$ r)\n (! (WedgeExt.β-l {r = args} u₀))\n (WedgeExt.β-r {r = args} v₀)) ⟩\n app= (app= (! (WedgeExt.β-l {r = args} u₀) ∙ WedgeExt.β-r {r = args} v₀) r) shift\n =⟨ ap (λ p → app= (app= p r) shift) (WedgeExt.coh {r = args}) ⟩\n app= (app= (λ= λ r → λ= λ shift → p' r shift) r) shift\n =⟨ ap (λ p → app= p shift) (app=-β (λ r → λ= λ shift → p' r shift) r)\n ∙ app=-β (λ shift → p' r shift) shift ⟩\n p' r shift\n =∎\n\nto' : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁)\n → (r : bmleft a₀ == bmright b₁)\n → hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r\n → Trunc (m +2+ n) (hfiber bmglue r)\nto' q₀₀ q₁₁ r (q₁₀ , shift) = To.ext q₁₀ (_ , q₀₀) (_ , q₁₁) r shift\n\nto : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁)\n → (r : bmleft a₀ == bmright b₁)\n → Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r)\n → Trunc (m +2+ n) (hfiber bmglue r)\nto q₀₀ q₁₁ r = Trunc-rec (to' q₀₀ q₁₁ r)\n\nmodule From {a₀ b₁} (q₀₁ : Q a₀ b₁) where\n U = Σ A λ a → Q a b₁\n u₀ : U\n u₀ = (a₀ , q₀₁)\n\n V = Σ B λ b → Q a₀ b\n v₀ : V\n v₀ = (b₁ , q₀₁)\n\n P : U → V → Type (lmax i (lmax j k))\n P u v = (r : bmleft a₀ == bmright b₁)\n → bmglue q₀₁ == r\n → Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue (snd v) ∙' ! (bmglue q₁₀) ∙' bmglue (snd u)) r)\n\n template : ∀ (u : U) (v : V)\n → (r : bmleft a₀ == bmright b₁)\n → (shift : bmglue q₀₁ == r)\n → ∀ q₁₀ → bmglue q₀₁ == bmglue (snd v) ∙' ! (bmglue q₁₀) ∙' bmglue (snd u)\n → Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue (snd v) ∙' ! (bmglue q₁₀) ∙' bmglue (snd u)) r)\n template u v r shift q₁₀ path = [ q₁₀ , ! path ∙' shift ]\n\n f = λ u r shift → template u v₀ r shift (snd u) (path-lemma₁ q₀₁ (snd u))\n g = λ v r shift → template u₀ v r shift (snd v) (path-lemma₂ q₀₁ (snd v))\n p' = λ r shift → ap (template u₀ v₀ r shift q₀₁) (path-coherence q₀₁)\n p = λ= λ r → λ= λ shift → p' r shift\n\n args : WedgeExt.args {A = U} {a₀ = u₀} {B = V} {b₀ = v₀}\n args = record {\n n = n; m = m;\n cA = g-conn b₁;\n cB = f-conn a₀;\n P = λ u v → swap-level $ P u v , Π-level λ _ → Π-level λ _ → Trunc-level;\n f = f; g = g; p = p}\n\n ext : ∀ u v → P u v\n ext = WedgeExt.ext args\n\n β-l : ∀ u r shift → ext u v₀ r shift == f u r shift\n β-l u r shift = app= (app= (WedgeExt.β-l u) r) shift\n\n β-r : ∀ v r shift → ext u₀ v r shift == g v r shift\n β-r v r shift = app= (app= (WedgeExt.β-r v) r) shift\n\n abstract\n coh : ∀ r shift → ! (β-l u₀ r shift) ∙ β-r v₀ r shift == p' r shift\n coh r shift =\n ! (β-l u₀ r shift) ∙ β-r v₀ r shift\n =⟨ ap (_∙ β-r v₀ r shift) (!-ap (_$ shift) (app= β-l' r))\n ∙ ∙-ap (_$ shift) (! (app= β-l' r)) (app= β-r' r)\n ∙ ap (λ p → app= p shift)\n ( ap (_∙ app= β-r' r) (!-ap (_$ r) β-l')\n ∙ ∙-ap (_$ r) (! β-l') β-r') ⟩\n app= (app= (! β-l' ∙ β-r') r) shift\n =⟨ ap (λ p → app= (app= p r) shift) (WedgeExt.coh {r = args}) ⟩\n app= (app= (λ= λ r → λ= λ shift → p' r shift) r) shift\n =⟨ ap (λ p → app= p shift) (app=-β (λ r → λ= λ shift → p' r shift) r)\n ∙ app=-β (λ shift → p' r shift) shift ⟩\n p' r shift\n =∎\n where β-l' = WedgeExt.β-l {r = args} u₀\n β-r' = WedgeExt.β-r {r = args} v₀\n\nfrom' : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁)\n → (r : bmleft a₀ == bmright b₁)\n → hfiber bmglue r\n → Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r)\nfrom' q₀₀ q₁₁ r (q₀₁ , shift) = From.ext q₀₁ (_ , q₁₁) (_ , q₀₀) r shift\n\nfrom : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁)\n → (r : bmleft a₀ == bmright b₁)\n → Trunc (m +2+ n) (hfiber bmglue r)\n → Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r)\nfrom q₀₀ q₁₁ r = Trunc-rec (from' q₀₀ q₁₁ r)\n\n-- Equivalence\n\n{-\n First step: Pack relevant rules into records.\n-}\n\nrecord βPair {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀)\n (q₁₁ : Q a₁ b₁) (q₀₁ : Q a₀ b₁) (q₁₀ : Q a₁ b₀)\n (r : bmleft a₀ == bmright b₁) : Type (lmax i (lmax j k)) where\n constructor βpair\n field\n path : bmglue q₀₁ == bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁\n to-β : ∀ shift → To.ext q₁₀ (_ , q₀₀) (_ , q₁₁) r shift\n == To.template q₁₀ (_ , q₀₀) (_ , q₁₁) r shift q₀₁ path\n from-β : ∀ shift → From.ext q₀₁ (_ , q₁₁) (_ , q₀₀) r shift\n == From.template q₀₁ (_ , q₁₁) (_ , q₀₀) r shift q₁₀ path\n\nβpair-bmleft : ∀ {a₀ a₁ b} (q₀ : Q a₀ b) (q₁ : Q a₁ b) r\n → βPair q₀ q₁ q₀ q₁ r\nβpair-bmleft q₀ q₁ r = record\n { path = path-lemma₁ q₀ q₁\n ; to-β = To.β-l q₁ (_ , q₀) r\n ; from-β = From.β-l q₀ (_ , q₁) r\n }\n\nβpair-bmright : ∀ {a b₀ b₁} (q₀ : Q a b₀) (q₁ : Q a b₁) r\n → βPair q₀ q₁ q₁ q₀ r\nβpair-bmright q₀ q₁ r = record\n { path = path-lemma₂ q₁ q₀\n ; to-β = To.β-r q₀ (_ , q₁) r\n ; from-β = From.β-r q₁ (_ , q₀) r\n }\n\nabstract\n βpair= : ∀ {a₀ a₁} {b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁)\n (q₀₁ : Q a₀ b₁) (q₁₀ : Q a₁ b₀) (r : bmleft a₀ == bmright b₁)\n {p₁ p₂ : bmglue q₀₁ == bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁} (p= : p₁ == p₂)\n {toβ₁} {toβ₂}\n (toβ= : ∀ shift → toβ₁ shift ∙ ap (To.template q₁₀ (_ , q₀₀) (_ , q₁₁) r shift q₀₁) p=\n == toβ₂ shift)\n {fromβ₁} {fromβ₂}\n (fromβ= : ∀ shift → fromβ₁ shift ∙ ap (From.template q₀₁ (_ , q₁₁) (_ , q₀₀) r shift q₁₀) p=\n == fromβ₂ shift)\n → βpair p₁ toβ₁ fromβ₁ == βpair p₂ toβ₂ fromβ₂\n βpair= q₀₀ q₁₁ q₀₁ q₁₀ r {p} idp toβ= fromβ= = lemma\n (λ= λ shift → ! (∙-unit-r _) ∙ toβ= shift)\n (λ= λ shift → ! (∙-unit-r _) ∙ fromβ= shift)\n where\n lemma : ∀ {toβ₁} {toβ₂} (toβ= : toβ₁ == toβ₂) {fromβ₁} {fromβ₂} (fromβ= : fromβ₁ == fromβ₂)\n → βpair p toβ₁ fromβ₁ == βpair p toβ₂ fromβ₂\n lemma idp idp = idp\n\nabstract\n βpair-glue : ∀ {a} {b} (q : Q a b) r\n → βpair-bmleft q q r == βpair-bmright q q r\n βpair-glue q r = βpair= q q q q r\n (path-coherence q)\n (λ shift →\n To.β-l q (_ , q) r shift ∙ To.p' q r shift\n =⟨ ! $ ap (To.β-l q (_ , q) r shift ∙_) (To.coh q r shift) ⟩\n To.β-l q (_ , q) r shift ∙ ! (To.β-l q (_ , q) r shift) ∙ To.β-r q (_ , q) r shift\n =⟨ ! (∙-assoc (To.β-l q (_ , q) r shift) (! (To.β-l q (_ , q) r shift)) (To.β-r q (_ , q) r shift))\n ∙ ap (_∙ To.β-r q (_ , q) r shift) (!-inv-r (To.β-l q (_ , q) r shift)) ⟩\n To.β-r q (_ , q) r shift\n ∎)\n (λ shift →\n From.β-l q (_ , q) r shift ∙ From.p' q r shift\n =⟨ ! $ ap (From.β-l q (_ , q) r shift ∙_) (From.coh q r shift) ⟩\n From.β-l q (_ , q) r shift ∙ ! (From.β-l q (_ , q) r shift) ∙ From.β-r q (_ , q) r shift\n =⟨ ! (∙-assoc (From.β-l q (_ , q) r shift) (! (From.β-l q (_ , q) r shift)) (From.β-r q (_ , q) r shift))\n ∙ ap (_∙ From.β-r q (_ , q) r shift) (!-inv-r (From.β-l q (_ , q) r shift)) ⟩\n From.β-r q (_ , q) r shift\n ∎)\n\n-- Lemmas\n\nprivate\n abstract\n to-from-template : ∀ {a₀ a₁ b₀ b₁} {q₀₀ : Q a₀ b₀}\n {q₁₁ : Q a₁ b₁} {q₀₁ : Q a₀ b₁} {q₁₀ : Q a₁ b₀} {r}\n (params : βPair q₀₀ q₁₁ q₀₁ q₁₀ r) shift\n → to q₀₀ q₁₁ r (from q₀₀ q₁₁ r [ q₀₁ , shift ]) == [ q₀₁ , shift ]\n to-from-template {q₀₀ = q₀₀} {q₁₁} {q₀₁} {q₁₀} {r} params shift =\n to q₀₀ q₁₁ r (from q₀₀ q₁₁ r [ q₀₁ , shift ])\n =⟨ ap (to q₀₀ q₁₁ r) $ from-β shift ⟩\n to q₀₀ q₁₁ r [ q₁₀ , ! path ∙' shift ]\n =⟨ to-β (! path ∙' shift) ⟩\n [ q₀₁ , path ∙' ! path ∙' shift ]\n =⟨ ap (λ p → [ q₀₁ , p ]) $ ! (∙'-assoc path (! path) shift) ∙ ap (_∙' shift) (!-inv'-r path) ∙ ∙'-unit-l shift ⟩\n [ q₀₁ , shift ]\n =∎\n where open βPair params\n\nmodule FromTo {a₁ b₀} (q₁₀ : Q a₁ b₀) where\n -- upper\n U = To.U q₁₀\n u₀ = To.u₀ q₁₀\n -- lower\n V = To.V q₁₀\n v₀ = To.v₀ q₁₀\n\n P : U → V → Type (lmax i (lmax j k))\n P u v = (r : bmleft (fst u) == bmright (fst v))\n → (shift : bmglue (snd u) ∙' ! (bmglue q₁₀) ∙' bmglue (snd v) == r)\n → from (snd u) (snd v) r (to (snd u) (snd v) r [ q₁₀ , shift ]) == [ q₁₀ , shift ]\n\n abstract\n template : ∀ (u : U) (v : V) r shift q₀₁\n → βPair (snd u) (snd v) q₀₁ q₁₀ r\n → from (snd u) (snd v) r (to (snd u) (snd v) r [ q₁₀ , shift ]) == [ q₁₀ , shift ]\n template (_ , q₀₀) (_ , q₁₁) r shift q₀₁ params =\n from q₀₀ q₁₁ r (to q₀₀ q₁₁ r [ q₁₀ , shift ])\n =⟨ ap (from q₀₀ q₁₁ r) $ to-β shift ⟩\n from q₀₀ q₁₁ r [ q₀₁ , path ∙' shift ]\n =⟨ from-β (path ∙' shift) ⟩\n [ q₁₀ , ! path ∙' path ∙' shift ]\n =⟨ ap (λ p → [ q₁₀ , p ]) $ ! (∙'-assoc (! path) path shift) ∙ ap (_∙' shift) (!-inv'-l path) ∙ ∙'-unit-l shift ⟩\n [ q₁₀ , shift ]\n =∎\n where open βPair params\n\n f = λ u r shift → template u v₀ r shift (snd u) (βpair-bmleft (snd u) q₁₀ r)\n g = λ v r shift → template u₀ v r shift (snd v) (βpair-bmright q₁₀ (snd v) r)\n\n abstract\n p : f u₀ == g v₀\n p = λ= λ r → λ= λ shift → ap (template u₀ v₀ r shift q₁₀) (βpair-glue q₁₀ r)\n\n args : WedgeExt.args {A = U} {a₀ = u₀} {B = V} {b₀ = v₀}\n args = record {\n n = n; m = m;\n cA = g-conn b₀;\n cB = f-conn a₁;\n P = λ u v → swap-level $ P u v , Π-level λ _ → Π-level λ _ → =-preserves-level Trunc-level;\n f = f; g = g; p = p}\n\n abstract\n ext : ∀ u v → P u v\n ext = WedgeExt.ext args\n\nabstract\n from-to' : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁) r fiber\n → from q₀₀ q₁₁ r (to q₀₀ q₁₁ r [ fiber ]) == [ fiber ]\n from-to' q₀₀ q₁₁ r (q₁₀ , shift) = FromTo.ext q₁₀ (_ , q₀₀) (_ , q₁₁) r shift\n\n from-to : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁) r fiber\n → from q₀₀ q₁₁ r (to q₀₀ q₁₁ r fiber) == fiber\n from-to q₀₀ q₁₁ r = Trunc-elim (from-to' q₀₀ q₁₁ r)\n\nmodule ToFrom {a₀ b₁} (q₀₁ : Q a₀ b₁) where\n -- upper\n U = From.U q₀₁\n u₀ = From.u₀ q₀₁\n -- lower\n V = From.V q₀₁\n v₀ = From.v₀ q₀₁\n\n P : U → V → Type (lmax i (lmax j k))\n P u v = (r : bmleft a₀ == bmright b₁)\n → (shift : bmglue q₀₁ == r)\n → to (snd v) (snd u) r (from (snd v) (snd u) r [ q₀₁ , shift ]) == [ q₀₁ , shift ]\n\n abstract\n template : ∀ (u : U) (v : V) r shift q₁₀\n → βPair (snd v) (snd u) q₀₁ q₁₀ r\n → to (snd v) (snd u) r (from (snd v) (snd u) r [ q₀₁ , shift ]) == [ q₀₁ , shift ]\n template (_ , q₁₁) (_ , q₀₀) r shift q₁₀ params =\n to q₀₀ q₁₁ r (from q₀₀ q₁₁ r [ q₀₁ , shift ])\n =⟨ ap (to q₀₀ q₁₁ r) $ from-β shift ⟩\n to q₀₀ q₁₁ r [ q₁₀ , ! path ∙' shift ]\n =⟨ to-β (! path ∙' shift) ⟩\n [ q₀₁ , path ∙' ! path ∙' shift ]\n =⟨ ap (λ p → [ q₀₁ , p ]) $ ! (∙'-assoc path (! path) shift) ∙ ap (_∙' shift) (!-inv'-r path) ∙ ∙'-unit-l shift ⟩\n [ q₀₁ , shift ]\n =∎\n where open βPair params\n\n f = λ u r shift → template u v₀ r shift (snd u) (βpair-bmleft q₀₁ (snd u) r)\n g = λ v r shift → template u₀ v r shift (snd v) (βpair-bmright (snd v) q₀₁ r)\n\n abstract\n p : f u₀ == g v₀\n p = λ= λ r → λ= λ shift → ap (template u₀ v₀ r shift q₀₁) (βpair-glue q₀₁ r)\n\n args : WedgeExt.args {A = U} {a₀ = u₀} {B = V} {b₀ = v₀}\n args = record {\n n = n; m = m;\n cA = g-conn b₁;\n cB = f-conn a₀;\n P = λ u v → swap-level $ P u v , Π-level λ _ → Π-level λ _ → =-preserves-level Trunc-level;\n f = f; g = g; p = p}\n\n abstract\n ext : ∀ u v → P u v\n ext = WedgeExt.ext args\n\nabstract\n to-from' : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁) r fiber\n → to q₀₀ q₁₁ r (from q₀₀ q₁₁ r [ fiber ]) == [ fiber ]\n to-from' q₀₀ q₁₁ r (q₀₁ , shift) = ToFrom.ext q₀₁ (_ , q₁₁) (_ , q₀₀) r shift\n\n to-from : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁) r fiber\n → to q₀₀ q₁₁ r (from q₀₀ q₁₁ r fiber) == fiber\n to-from q₀₀ q₁₁ r = Trunc-elim (to-from' q₀₀ q₁₁ r)\n\neqv : ∀ {a₀ a₁ b₀ b₁} (q₀₀ : Q a₀ b₀) (q₁₁ : Q a₁ b₁) r\n → Trunc (m +2+ n) (hfiber (λ q₁₀ → bmglue q₀₀ ∙' ! (bmglue q₁₀) ∙' bmglue q₁₁) r)\n ≃ Trunc (m +2+ n) (hfiber bmglue r)\neqv q₀₀ q₁₁ r = equiv (to q₀₀ q₁₁ r) (from q₀₀ q₁₁ r) (to-from q₀₀ q₁₁ r) (from-to q₀₀ q₁₁ r)\n", "meta": {"hexsha": "6ec33cdced245afc9768b59818a77699ebeb3030", "size": 15451, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/blakersmassey/CoherenceData.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/homotopy/blakersmassey/CoherenceData.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/homotopy/blakersmassey/CoherenceData.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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.5936739659, "max_line_length": 121, "alphanum_fraction": 0.5070869199, "num_tokens": 7188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.38223607393474995}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule Examples.New where\n\nopen import Data.Empty using (⊥)\nopen import Data.Unit using (⊤; tt)\nopen import Data.Sum using (_⊎_; inj₁; inj₂; [_,_]′)\nopen import Data.Product using (_×_; _,_; proj₁; proj₂)\nopen import Relation.Binary.PropositionalEquality\n using (_≡_; refl; sym; trans; cong; subst)\n\nopen import Singleton\nopen import PiPointedFrac\n\n------------------------------------------------------------------------------\n-- Conventional PI examples\n\n𝔹 : 𝕌\n𝔹 = 𝟙 +ᵤ 𝟙\n\n𝔹² : 𝕌\n𝔹² = 𝔹 ×ᵤ 𝔹\n\n𝔽 𝕋 : ⟦ 𝔹 ⟧\n𝔽 = inj₁ tt\n𝕋 = inj₂ tt\n\nNOT : 𝔹 ⟷ 𝔹\nNOT = swap₊\n\nNEG1 NEG2 NEG3 NEG4 NEG5 : 𝔹 ⟷ 𝔹\nNEG1 = swap₊\nNEG2 = id⟷ ⊚ NOT\nNEG3 = NOT ⊚ NOT ⊚ NOT\nNEG4 = NOT ⊚ id⟷\nNEG5 = uniti⋆l ⊚ swap⋆ ⊚ (NOT ⊗ id⟷) ⊚ swap⋆ ⊚ unite⋆l\nNEG6 = uniti⋆r ⊚ (NOT ⊗ id⟷) ⊚ unite⋆r\n\nCONTROL : {A : 𝕌} → (A ⟷ A) → (𝔹 ×ᵤ A ⟷ 𝔹 ×ᵤ A)\nCONTROL f = dist ⊚ (id⟷ ⊕ (id⟷ ⊗ f)) ⊚ factor\n\nCNOT : 𝔹² ⟷ 𝔹²\nCNOT = CONTROL NOT\n\nTOFFOLI : 𝔹 ×ᵤ 𝔹² ⟷ 𝔹 ×ᵤ 𝔹²\nTOFFOLI = CONTROL (CONTROL NOT)\n\nPERES : (𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹 ⟷ (𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹\nPERES = (id⟷ ⊗ NOT) ⊚ assocr⋆ ⊚ (id⟷ ⊗ swap⋆) ⊚\n TOFFOLI ⊚\n (id⟷ ⊗ (NOT ⊗ id⟷)) ⊚\n TOFFOLI ⊚\n (id⟷ ⊗ swap⋆) ⊚ (id⟷ ⊗ (NOT ⊗ id⟷)) ⊚\n TOFFOLI ⊚\n (id⟷ ⊗ (NOT ⊗ id⟷)) ⊚ assocl⋆\n\nSWAP12 SWAP23 SWAP13 ROTL ROTR : 𝟙 +ᵤ 𝟙 +ᵤ 𝟙 ⟷ 𝟙 +ᵤ 𝟙 +ᵤ 𝟙\nSWAP12 = assocl₊ ⊚ (swap₊ ⊕ id⟷) ⊚ assocr₊\nSWAP23 = id⟷ ⊕ swap₊\nSWAP13 = SWAP23 ⊚ SWAP12 ⊚ SWAP23\nROTR = SWAP12 ⊚ SWAP23\nROTL = SWAP13 ⊚ SWAP23\n\n------------------------------------------------------------------------------\n-- Pointed versions\n\n∙TOFFOLI-1 : ∀ {b₁ b₂} →\n (𝔹 ×ᵤ 𝔹²) # (𝔽 , (b₁ , b₂)) ∙⟶ (𝔹 ×ᵤ 𝔹²) # (𝔽 , (b₁ , b₂))\n∙TOFFOLI-1 = ∙c TOFFOLI\n\n∙TOFFOLI-2 : ∀ {b} →\n (𝔹 ×ᵤ 𝔹²) # (𝕋 , (𝔽 , b)) ∙⟶ (𝔹 ×ᵤ 𝔹²) # (𝕋 , (𝔽 , b))\n∙TOFFOLI-2 = ∙c TOFFOLI\n\n∙TOFFOLI-3 : ∀ {b} →\n (𝔹 ×ᵤ 𝔹²) # (𝕋 , (𝕋 , b)) ∙⟶ (𝔹 ×ᵤ 𝔹²) # (𝕋 , (𝕋 , eval swap₊ b))\n∙TOFFOLI-3 = ∙c TOFFOLI\n\n-- Ancilla examples from literature\n\n-- Fig. 2 in Ricercar\n\nfig2a : 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ⟷\n 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹\nfig2a = CONTROL (CONTROL (CONTROL NOT))\n\n-- first write the circuit with the additional ancilla\n\nfig2b' : ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹) ⟷ ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹)\nfig2b' =\n (swap⋆ ⊗ id⟷) ⊚\n assocr⋆ ⊚\n (swap⋆ ⊗ id⟷) ⊚\n assocr⋆ ⊚\n (id⟷ ⊗ CONTROL (CONTROL NOT)) -- first ccnot\n ⊚\n assocl⋆ ⊚\n (swap⋆ ⊗ id⟷) ⊚\n assocl⋆ ⊚\n (swap⋆ ⊗ id⟷) -- move it back\n ⊚\n (assocl⋆ ⊗ id⟷) ⊚\n assocr⋆ ⊚\n (id⟷ ⊗ swap⋆) ⊚\n (id⟷ ⊗ CONTROL (CONTROL NOT)) -- second ccnot\n ⊚\n (id⟷ ⊗ swap⋆) ⊚\n assocl⋆ ⊚\n (assocr⋆ ⊗ id⟷) -- move it back\n ⊚\n (swap⋆ ⊗ id⟷) ⊚\n assocr⋆ ⊚\n (swap⋆ ⊗ id⟷) ⊚\n assocr⋆ ⊚\n (id⟷ ⊗ CONTROL (CONTROL NOT)) -- third ccnot\n ⊚\n assocl⋆ ⊚\n (swap⋆ ⊗ id⟷) ⊚\n assocl⋆ ⊚\n (swap⋆ ⊗ id⟷) -- move it back\n\n-- then prove a theorem that specifies its semantics\n\nfig2b'≡ : (a b c d : ⟦ 𝔹 ⟧) →\n proj₂ (eval fig2b' ((a , b , c , d) , 𝔽)) ≡ 𝔽\nfig2b'≡ a (inj₁ tt) c d = refl\nfig2b'≡ (inj₁ tt) (inj₂ tt) c d = refl\nfig2b'≡ (inj₂ tt) (inj₂ tt) c d = refl\n\n-- generalize above? Method:\n-- for 'dist' to evaluate, need to split on b first\n-- in first case, split on e (same reason)\n-- in second case, split on a (same reason)\n-- split on e\n-- split on e\nfoo : (a b c d e : ⟦ 𝔹 ⟧) →\n proj₂ (eval fig2b' ((a , b , c , d) , e)) ≡ e\nfoo a (inj₁ x) c d (inj₁ x₁) = refl\nfoo a (inj₁ x) c d (inj₂ y) = refl\nfoo (inj₁ x) (inj₂ y) c d (inj₁ x₁) = refl\nfoo (inj₁ x) (inj₂ y) c d (inj₂ y₁) = refl\nfoo (inj₂ y₁) (inj₂ y) c d (inj₁ x) = refl\nfoo (inj₂ y₁) (inj₂ y) c d (inj₂ y₂) = refl\n\n{--\npostulate\n -- boring...\n tensor4 : ∀ {a b c d e} →\n (● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ]) ×ᵤ ● 𝔹 [ e ] ⟷\n ● ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹) [ (a , b , c , d) , e ]\n itensor4 : ∀ {a b c d e} →\n ● ((𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹 ×ᵤ 𝔹) ×ᵤ 𝔹) [ (a , b , c , d) , e ] ⟷\n (● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ]) ×ᵤ ● 𝔹 [ e ]\n--}\n-- now lift it\n{--\nfig2b : ∀ {a b c d e} →\n let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e)\n in\n ● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ] ⟷\n ● 𝔹 [ x ] ×ᵤ ● 𝔹 [ y ] ×ᵤ ● 𝔹 [ z ] ×ᵤ ● 𝔹 [ w ]\nfig2b {a} {b} {c} {d} {e} =\n let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e)\n in uniti⋆r ⊚\n -- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝟙[e]\n (id⟷ ⊗ η e) ⊚\n -- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × (●𝔹[e] x ●1/𝔹[e])\n assocl⋆ ⊚\n -- ((●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝔹[e) x ●1/𝔹[e]\n (tensor4 ⊗ id⟷) ⊚\n -- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (a,b,c,d),e ] x ●1/𝔹[e]\n (lift fig2b' ⊗ id⟷) ⊚\n -- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (x,y,z,w),e ] x ●1/𝔹[e]\n (((== id⟷ (cong (λ H → ((x , y , z , w)) , H) (foo a b c d e))) ⊗ id⟷)) ⊚\n -- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (x,y,z,w),e ] x ●1/𝔹[e]\n (itensor4 ⊗ id⟷) ⊚\n -- ((●𝔹[x] × ●𝔹[y] × ●𝔹[z] × ●𝔹[w]) × ●𝔹[e]) x ●1/𝔹[e]\n assocr⋆ ⊚\n (id⟷ ⊗ ε e) ⊚\n unite⋆r\n--}\n{--\n-- This is mostly to show that == is really 'subst' in hiding.\nfig2b₂ : ∀ {a b c d e} →\n let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e)\n in\n ● 𝔹 [ a ] ×ᵤ ● 𝔹 [ b ] ×ᵤ ● 𝔹 [ c ] ×ᵤ ● 𝔹 [ d ] ⟷\n ● 𝔹 [ x ] ×ᵤ ● 𝔹 [ y ] ×ᵤ ● 𝔹 [ z ] ×ᵤ ● 𝔹 [ w ]\nfig2b₂ {a} {b} {c} {d} {e} =\n let ((x , y , z , w) , u) = eval fig2b' ((a , b , c , d) , e)\n in uniti⋆r ⊚\n -- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝟙[e]\n (id⟷ ⊗ η e) ⊚\n -- (●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × (●𝔹[e] x ●1/𝔹[e])\n assocl⋆ ⊚\n -- ((●𝔹[a] × ●𝔹[b] × ●𝔹[c] × ●𝔹[d]) × ●𝔹[e) x ●1/𝔹[e]\n (tensor4 ⊗ id⟷) ⊚\n -- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (a,b,c,d),e ] x ●1/𝔹[e]\n (lift fig2b' ⊗ id⟷) ⊚\n -- ● ((𝔹 × 𝔹 × 𝔹 × 𝔹) × 𝔹) [ (x,y,z,w),e ] x ●1/𝔹[e]\n (itensor4 ⊗ id⟷) ⊚\n -- ((●𝔹[x] × ●𝔹[y] × ●𝔹[z] × ●𝔹[w]) × ●𝔹[e]) x ●1/𝔹[e]\n assocr⋆ ⊚\n (id⟷ ⊗ (subst (λ ee → ● 𝔹 [ ee ] ×ᵤ 𝟙/● 𝔹 [ e ] ⟷ 𝟙) (sym (foo a b c d e)) (ε e))) ⊚\n unite⋆r\n--}\n-- Examples\n\ninfixr 2 _→⟨_⟩_\ninfix 3 _□\n\n_→⟨_⟩_ : (T₁ : ∙𝕌) → {T₂ T₃ : ∙𝕌} →\n (T₁ ∙⟶ T₂) → (T₂ ∙⟶ T₃) → (T₁ ∙⟶ T₃)\n_ →⟨ α ⟩ β = α ∙⊚ β\n\n_□ : (T : ∙𝕌) → {T : ∙𝕌} → (T ∙⟶ T)\n_□ T = ∙id⟷\n\nzigzag : ∀ b → 𝔹 # b ∙⟶ 𝔹 # b\nzigzag b =\n (𝔹 # b)\n →⟨ (∙c uniti⋆l) ⟩\n (𝟙 ×ᵤ 𝔹) # (tt , b)\n →⟨ ∙times# ⟩\n (𝟙 # tt) ∙×ᵤ (𝔹 # b)\n →⟨ ∙id⟷ ∙⊗ return (𝔹 # b) ⟩\n (𝟙 # tt) ∙×ᵤ (Singᵤ (𝔹 # b))\n →⟨ η (𝔹 # b) ∙⊗ ∙id⟷ ⟩\n ((Singᵤ (𝔹 # b)) ∙×ᵤ (Recipᵤ (𝔹 # b))) ∙×ᵤ (Singᵤ (𝔹 # b))\n →⟨ ∙assocr⋆ ⟩ \n Singᵤ (𝔹 # b) ∙×ᵤ (Recipᵤ (𝔹 # b) ∙×ᵤ (Singᵤ (𝔹 # b)))\n →⟨ ∙id⟷ ∙⊗ ∙swap⋆ ⟩\n Singᵤ (𝔹 # b) ∙×ᵤ ((Singᵤ (𝔹 # b)) ∙×ᵤ (Recipᵤ (𝔹 # b)))\n →⟨ ∙id⟷ ∙⊗ ε (𝔹 # b) ⟩\n Singᵤ (𝔹 # b) ∙×ᵤ (𝟙 # tt)\n →⟨ extract (𝔹 # b) ∙⊗ ∙id⟷ ⟩\n (𝔹 # b) ∙×ᵤ (𝟙 # tt)\n →⟨ ∙#times ⟩\n (𝔹 ×ᵤ 𝟙) # (b , tt)\n →⟨ ∙c unite⋆r ⟩\n (𝔹 # b) □\n\ntest1 : proj₁ (∙eval (zigzag 𝔽)) 𝔽 ≡ 𝔽\ntest1 = proj₂ (∙eval (zigzag 𝔽))\n\ntest2 : proj₁ (∙eval (zigzag 𝕋)) 𝕋 ≡ 𝕋\ntest2 = proj₂ (∙eval (zigzag 𝕋))\n\n\n------------------------------------------------------------------------------\n", "meta": {"hexsha": "96b2706510fd44e19a74590ac66951ea6ad32504", "size": 7139, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "fracGC/Examples/New.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "fracGC/Examples/New.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "fracGC/Examples/New.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 28.4422310757, "max_line_length": 92, "alphanum_fraction": 0.3937526264, "num_tokens": 4231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702642896702, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.38223606766645685}} {"text": "{-\n\nIn this file we apply the cubical machinery to Martin Hötzel-Escardó's\nstructure identity principle:\n\nhttps://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#sns\n\n-}\n{-# OPTIONS --cubical --safe #-}\nmodule Cubical.Foundations.SIP where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Univalence renaming (ua-pathToEquiv to ua-pathToEquiv')\nopen import Cubical.Foundations.Transport\nopen import Cubical.Foundations.Path\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.FunExtEquiv\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HAEquiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Prod.Base hiding (_×_) renaming (_×Σ_ to _×_)\n\nprivate\n variable\n ℓ ℓ' ℓ'' ℓ''' ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓ₅ : Level\n\n-- For technical reasons we reprove ua-pathToEquiv using the\n-- particular proof constructed by iso→HAEquiv. The reason is that we\n-- want to later be able to extract\n--\n-- eq : ua-au (ua e) ≡ cong ua (au-ua e)\n--\nuaHAEquiv : (A B : Type ℓ) → HAEquiv (A ≃ B) (A ≡ B)\nuaHAEquiv A B = iso→HAEquiv (iso ua pathToEquiv ua-pathToEquiv' pathToEquiv-ua)\nopen isHAEquiv\n\n-- We now extract the particular proof constructed from iso→HAEquiv\n-- for reasons explained above.\nua-pathToEquiv : {A B : Type ℓ} (e : A ≡ B) → ua (pathToEquiv e) ≡ e\nua-pathToEquiv e = uaHAEquiv _ _ .snd .ret e\n\n\n-- A structure is a type-family S : Type ℓ → Type ℓ', i.e. for X : Type ℓ and s : S X, the pair (X , s)\n-- means that X is equipped with a S-structure, which is witnessed by s.\n-- An S-structure should have a notion of S-homomorphism, or rather S-isomorphism.\n-- This will be implemented by a function ι\n-- that gives us for any two types with S-structure (X , s) and (Y , t) a family:\n-- ι (X , s) (Y , t) : (X ≃ Y) → Type ℓ''\n-- Note that for any equivalence (f , e) : X ≃ Y the type ι (X , s) (Y , t) (f , e) need not to be\n-- a proposition. Indeed this type should correspond to the ways s and t can be identified\n-- as S-structures. This we call a standard notion of structure or SNS.\n-- We will use a different definition, but the two definitions are interchangeable.\nSNS : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → Type (ℓ-max (ℓ-max(ℓ-suc ℓ) ℓ') ℓ'')\nSNS {ℓ = ℓ} S ι = ∀ {X : (Type ℓ)} (s t : S X) → ((s ≡ t) ≃ ι (X , s) (X , t) (idEquiv X))\n\n\n-- We introduce the notation for structure preserving equivalences a bit differently,\n-- but this definition doesn't actually change from Escardó's notes.\n_≃[_]_ : {S : Type ℓ → Type ℓ'}\n → (A : Σ[ X ∈ (Type ℓ) ] (S X))\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → (B : Σ[ X ∈ (Type ℓ) ] (S X))\n → Type (ℓ-max ℓ ℓ'')\nA ≃[ ι ] B = Σ[ f ∈ ((A .fst) ≃ (B. fst)) ] (ι A B f)\n\n-- Before we can formulate our version of an SNS we introduce a bit of\n-- notation and prove a few basic results. First, we define the\n-- \"cong-≃\":\n_⋆_ : (S : Type ℓ → Type ℓ') → {X Y : Type ℓ} → (X ≃ Y) → S X ≃ S Y\nS ⋆ f = pathToEquiv (cong S (ua f))\n\n\n-- Next, we prove a couple of helpful results about this ⋆ operation:\n⋆-idEquiv : (S : Type ℓ → Type ℓ') (X : Type ℓ) → S ⋆ (idEquiv X) ≡ idEquiv (S X)\n⋆-idEquiv S X = S ⋆ (idEquiv X) ≡⟨ cong (λ p → pathToEquiv (cong S p)) uaIdEquiv ⟩\n pathToEquiv refl ≡⟨ pathToEquivRefl ⟩\n idEquiv (S X) ∎\n\n⋆-char : (S : Type ℓ → Type ℓ') {X Y : Type ℓ} (f : X ≃ Y) → ua (S ⋆ f) ≡ cong S (ua f)\n⋆-char S f = ua-pathToEquiv (cong S (ua f))\n\nPathP-⋆-lemma : (S : Type ℓ → Type ℓ') (A B : Σ[ X ∈ (Type ℓ) ] (S X)) (f : A .fst ≃ B .fst)\n → (PathP (λ i → ua (S ⋆ f) i) (A .snd) (B .snd)) ≡ (PathP (λ i → S ((ua f) i)) (A .snd) (B .snd))\nPathP-⋆-lemma S A B f i = PathP (λ j → (⋆-char S f) i j) (A .snd) (B .snd)\n\n\n\n-- Our new definition of standard notion of structure SNS' using the ⋆ notation.\n-- This is easier to work with than SNS wrt Glue-types\nSNS' : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → Type (ℓ-max (ℓ-max(ℓ-suc ℓ) ℓ') ℓ'')\nSNS' S ι = (A B : Σ[ X ∈ (Type _) ] (S X)) → (f : A .fst ≃ B .fst)\n → (equivFun (S ⋆ f) (A .snd) ≡ (B .snd)) ≃ (ι A B f)\n\n-- We can unfold SNS' as follows:\nSNS'' : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → Type (ℓ-max (ℓ-max(ℓ-suc ℓ) ℓ') ℓ'')\nSNS'' S ι = (A B : Σ[ X ∈ (Type _) ] (S X)) → (f : A .fst ≃ B .fst)\n → (transport (λ i → S (ua f i)) (A .snd) ≡ (B .snd)) ≃ (ι A B f)\n\nSNS'≡SNS'' : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → SNS' S ι ≡ SNS'' S ι\nSNS'≡SNS'' S ι = refl\n\n\n\n-- A quick sanity-check that our definition is interchangeable with\n-- Escardó's. The direction SNS→SNS' corresponds more or less to an\n-- EquivJ formulation of Escardó's homomorphism-lemma.\nSNS'→SNS : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → SNS' S ι → SNS S ι\nSNS'→SNS S ι θ {X = X} s t = subst (λ x → (equivFun x s ≡ t) ≃ ι (X , s) (X , t) (idEquiv X)) (⋆-idEquiv S X) θ-id\n where\n θ-id = θ (X , s) (X , t) (idEquiv X)\n\nSNS→SNS' : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → SNS S ι → SNS' S ι\nSNS→SNS' S ι θ A B f = EquivJ P C (B .fst) (A .fst) f (B .snd) (A .snd)\n where\n P : (X Y : Type _) → Y ≃ X → Type _\n P X Y g = (s : S X) (t : S Y) → (equivFun (S ⋆ g) t ≡ s) ≃ ι (Y , t) (X , s) g\n\n C : (X : Type _) → (s t : S X) → (equivFun (S ⋆ (idEquiv X)) t ≡ s) ≃ ι (X , t) (X , s) (idEquiv X)\n C X s t = subst (λ u → (u ≡ s) ≃ (ι (X , t) (X , s) (idEquiv X)))\n (sym ( cong (λ f → (equivFun f) t) (⋆-idEquiv S X))) (θ t s)\n\n\n\n-- The following transport-free version of SNS'' is a bit easier to\n-- work with for the proof of the SIP\nSNS''' : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → Type (ℓ-max (ℓ-max(ℓ-suc ℓ) ℓ') ℓ'')\nSNS''' S ι = (A B : Σ[ X ∈ (Type _) ] (S X)) → (e : A .fst ≃ B .fst)\n → (PathP (λ i → S (ua e i)) (A .snd) (B .snd)) ≃ ι A B e\n\n-- We can easily go between SNS'' (which is def. equal to SNS') and SNS'''\n-- We should be able to find are more direct version of PathP≃Path for the family (λ i → S (ua f i))\n-- using glue and unglue terms.\nSNS''→SNS''' : {S : Type ℓ → Type ℓ'}\n → {ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ''}\n → SNS'' S ι → SNS''' S ι\nSNS''→SNS''' {S = S} h A B f = PathP (λ i → S (ua f i)) (A .snd) (B .snd)\n ≃⟨ PathP≃Path (λ i → S (ua f i)) (A .snd) (B .snd) ⟩\n h A B f\n\nSNS'''→SNS'' : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → SNS''' S ι → SNS'' S ι\nSNS'''→SNS'' S ι h A B f = transport (λ i → S (ua f i)) (A .snd) ≡ (B .snd)\n ≃⟨ invEquiv (PathP≃Path (λ i → S (ua f i)) (A .snd) (B .snd)) ⟩\n h A B f\n\n\n-- We can now directly define a function\n-- sip : A ≃[ ι ] B → A ≡ B\n-- together with is inverse.\n-- Here, these functions use SNS''' and are expressed using a Σ-type instead as it is a bit\n-- easier to work with\nsip : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → (θ : SNS''' S ι)\n → (A B : Σ[ X ∈ (Type ℓ) ] (S X))\n → A ≃[ ι ] B\n → Σ (A .fst ≡ B .fst) (λ p → PathP (λ i → S (p i)) (A .snd) (B .snd))\nsip S ι θ A B (e , p) = ua e , invEq (θ A B e) p\n\n-- The inverse to sip using the following little lemma\nlem : (S : Type ℓ → Type ℓ')\n (A B : Σ[ X ∈ (Type ℓ) ] (S X))\n (e : A .fst ≡ B .fst)\n → PathP (λ i → S (ua (pathToEquiv e) i)) (A .snd) (B .snd) ≡\n PathP (λ i → S (e i)) (A .snd) (B .snd)\nlem S A B e i = PathP (λ j → S (ua-pathToEquiv e i j)) (A .snd) (B .snd)\n\nsip⁻ : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → (θ : SNS''' S ι)\n → (A B : Σ[ X ∈ (Type ℓ) ] (S X))\n → Σ (A .fst ≡ B .fst) (λ p → PathP (λ i → S (p i)) (A .snd) (B .snd))\n → A ≃[ ι ] B\nsip⁻ S ι θ A B (e , r) = pathToEquiv e , θ A B (pathToEquiv e) .fst q\n where\n q : PathP (λ i → S (ua (pathToEquiv e) i)) (A .snd) (B .snd)\n q = transport (λ i → lem S A B e (~ i)) r\n\n\n-- we can rather directly show that sip and sip⁻ are mutually inverse:\nsip-sip⁻ : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → (θ : SNS''' S ι)\n → (A B : Σ[ X ∈ (Type ℓ) ] (S X))\n → (r : Σ (A .fst ≡ B .fst) (λ p → PathP (λ i → S (p i)) (A .snd) (B .snd)))\n → sip S ι θ A B (sip⁻ S ι θ A B r) ≡ r\nsip-sip⁻ S ι θ A B (p , q) =\n sip S ι θ A B (sip⁻ S ι θ A B (p , q))\n ≡⟨ refl ⟩\n ua (pathToEquiv p) , invEq (θ A B (pathToEquiv p)) (θ A B (pathToEquiv p) .fst (transport (λ i → lem S A B p (~ i)) q))\n ≡⟨ (λ i → ua (pathToEquiv p) , secEq (θ A B (pathToEquiv p)) (transport (λ i → lem S A B p (~ i)) q) i) ⟩\n ua (pathToEquiv p) , transport (λ i → lem S A B p (~ i)) q\n ≡⟨ (λ i → ua-pathToEquiv p i ,\n transp (λ k → PathP (λ j → S (ua-pathToEquiv p (i ∧ k) j)) (A .snd) (B .snd))\n (~ i)\n (transport (λ i → lem S A B p (~ i)) q)) ⟩\n p , transport (λ i → lem S A B p i) (transport (λ i → lem S A B p (~ i)) q)\n ≡⟨ (λ i → p , transportTransport⁻ (lem S A B p) q i) ⟩\n p , q ∎\n\n\n-- The trickier direction:\nsip⁻-sip : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → (θ : SNS''' S ι)\n → (A B : Σ[ X ∈ (Type ℓ) ] (S X))\n → (r : A ≃[ ι ] B)\n → sip⁻ S ι θ A B (sip S ι θ A B r) ≡ r\nsip⁻-sip S ι θ A B (e , p) =\n sip⁻ S ι θ A B (sip S ι θ A B (e , p))\n ≡⟨ refl ⟩\n pathToEquiv (ua e) , θ A B (pathToEquiv (ua e)) .fst (f⁺ p')\n ≡⟨ (λ i → pathToEquiv-ua e i , θ A B (pathToEquiv-ua e i) .fst (pth' i)) ⟩\n e , θ A B e .fst (f⁻ (f⁺ p'))\n ≡⟨ (λ i → e , θ A B e .fst (transportTransport⁻ (lem S A B (ua e)) p' i)) ⟩\n e , θ A B e .fst (invEq (θ A B e) p)\n ≡⟨ (λ i → e , (retEq (θ A B e) p i)) ⟩\n e , p ∎\n where\n p' : PathP (λ i → S (ua e i)) (A .snd) (B .snd)\n p' = invEq (θ A B e) p\n\n f⁺ : PathP (λ i → S (ua e i)) (A .snd) (B .snd)\n → PathP (λ i → S (ua (pathToEquiv (ua e)) i)) (A .snd) (B .snd)\n f⁺ = transport (λ i → PathP (λ j → S (ua-pathToEquiv (ua e) (~ i) j)) (A .snd) (B .snd))\n\n f⁻ : PathP (λ i → S (ua (pathToEquiv (ua e)) i)) (A .snd) (B .snd)\n → PathP (λ i → S (ua e i)) (A .snd) (B .snd)\n f⁻ = transport (λ i → PathP (λ j → S (ua-pathToEquiv (ua e) i j)) (A .snd) (B .snd))\n\n -- We can prove the following as in sip∘pis-id, but the type is not\n -- what we want as it should be \"cong ua (pathToEquiv-ua e)\"\n pth : PathP (λ j → PathP (λ k → S (ua-pathToEquiv (ua e) j k)) (A .snd) (B .snd))\n (f⁺ p') (f⁻ (f⁺ p'))\n pth i = transp (λ k → PathP (λ j → S (ua-pathToEquiv (ua e) (i ∧ k) j)) (A .snd) (B .snd))\n (~ i)\n (f⁺ p')\n\n -- So we build an equality that we want to cast the types with\n casteq : PathP (λ j → PathP (λ k → S (ua-pathToEquiv (ua e) j k)) (A .snd) (B .snd))\n (f⁺ p') (f⁻ (f⁺ p'))\n ≡ PathP (λ j → PathP (λ k → S (cong ua (pathToEquiv-ua e) j k)) (A .snd) (B .snd))\n (f⁺ p') (f⁻ (f⁺ p'))\n casteq i = PathP (λ j → PathP (λ k → S (eq i j k)) (A .snd) (B .snd)) (f⁺ p') (f⁻ (f⁺ p'))\n where\n -- This is where we need the half-adjoint equivalence property\n eq : ua-pathToEquiv (ua e) ≡ cong ua (pathToEquiv-ua e)\n eq = sym (uaHAEquiv (A .fst) (B .fst) .snd .com e)\n\n -- We then get a term of the type we need\n pth' : PathP (λ j → PathP (λ k → S (cong ua (pathToEquiv-ua e) j k)) (A .snd) (B .snd))\n (f⁺ p') (f⁻ (f⁺ p'))\n pth' = transport (λ i → casteq i) pth\n\n\n-- Finally package everything up to get the cubical SIP\nSIP : (S : Type ℓ → Type ℓ')\n → (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n → (θ : SNS''' S ι)\n → (A B : Σ[ X ∈ (Type ℓ) ] (S X))\n → A ≃[ ι ] B ≃ (A ≡ B)\nSIP S ι θ A B = (A ≃[ ι ] B ) ≃⟨ eq ⟩ Σ≡\n where\n eq : A ≃[ ι ] B ≃ Σ (A .fst ≡ B .fst) (λ p → PathP (λ i → S (p i)) (A .snd) (B .snd))\n eq = isoToEquiv (iso (sip S ι θ A B) (sip⁻ S ι θ A B)\n (sip-sip⁻ S ι θ A B) (sip⁻-sip S ι θ A B))\n\n\n-- Now, we want to add axioms (i.e. propositions) to our Structure S that don't affect the ι.\n-- For this and the remainder of this file we will work with SNS'\n-- We use a lemma due to Zesen Qian, which can now be found in Foundations.Prelude:\n-- https://github.com/riaqn/cubical/blob/hgroup/Cubical/Data/Group/Properties.agda#L83\nadd-to-structure : (S : Type ℓ → Type ℓ')\n (axioms : (X : Type ℓ) → (S X) → Type ℓ''')\n → Type ℓ → Type (ℓ-max ℓ' ℓ''')\nadd-to-structure S axioms X = Σ[ s ∈ S X ] (axioms X s)\n\nadd-to-iso : (S : Type ℓ → Type ℓ')\n (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n (axioms : (X : Type ℓ) → (S X) → Type ℓ''')\n → (A B : Σ[ X ∈ (Type ℓ) ] (add-to-structure S axioms X)) → A .fst ≃ B .fst\n → Type ℓ''\nadd-to-iso S ι axioms (X , (s , a)) (Y , (t , b)) f = ι (X , s) (Y , t) f\n\nadd-⋆-lemma : (S : Type ℓ → Type ℓ')\n (axioms : (X : Type ℓ) → (S X) → Type ℓ''')\n (axioms-are-Props : (X : Type ℓ) (s : S X) → isProp (axioms X s))\n {X Y : Type ℓ} {s : S X} {t : S Y} {a : axioms X s} {b : axioms Y t}\n (f : X ≃ Y)\n → (equivFun (add-to-structure S axioms ⋆ f) (s , a) ≡ (t , b)) ≃ (equivFun (S ⋆ f) s ≡ t)\nadd-⋆-lemma S axioms axioms-are-Props {Y = Y} {s = s} {t = t} {a = a} {b = b} f = isoToEquiv (iso φ ψ η ε)\n where\n φ : equivFun ((add-to-structure S axioms) ⋆ f) (s , a) ≡ (t , b)\n → equivFun (S ⋆ f) s ≡ t\n φ r i = r i .fst\n\n ψ : equivFun (S ⋆ f) s ≡ t\n → equivFun ((add-to-structure S axioms) ⋆ f) (s , a) ≡ (t , b)\n ψ p i = p i , isProp→PathP (λ j → axioms-are-Props Y (p j)) (equivFun (add-to-structure S axioms ⋆ f) (s , a) .snd) b i\n\n η : section φ ψ\n η p = refl\n\n ε : retract φ ψ\n ε r i j = r j .fst\n , isProp→isSet-PathP (λ k → axioms-are-Props Y (r k .fst)) _ _\n (isProp→PathP (λ j → axioms-are-Props Y (r j .fst))\n (equivFun (add-to-structure S axioms ⋆ f) (s , a) .snd) b)\n (λ k → r k .snd) i j\n\n\nadd-axioms-SNS' : (S : Type ℓ → Type ℓ')\n (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')\n (axioms : (X : Type ℓ) → (S X) → Type ℓ''')\n (axioms-are-Props : (X : Type ℓ) (s : S X) → isProp (axioms X s))\n (θ : SNS' S ι)\n → SNS' (add-to-structure S axioms) (add-to-iso S ι axioms)\nadd-axioms-SNS' S ι axioms axioms-are-Props θ (X , (s , a)) (Y , (t , b)) f =\n equivFun (add-to-structure S axioms ⋆ f) (s , a) ≡ (t , b) ≃⟨ add-⋆-lemma S axioms axioms-are-Props f ⟩\n equivFun (S ⋆ f) s ≡ t ≃⟨ θ (X , s) (Y , t) f ⟩\n add-to-iso S ι axioms (X , (s , a)) (Y , (t , b)) f ■\n\n\n-- Now, we want to join two structures. Together with the adding of\n-- axioms this will allow us to prove that a lot of mathematical\n-- structures are a standard notion of structure\ntechnical-×-lemma : {A : Type ℓ₁} {B : Type ℓ₂} {C : Type ℓ₃} {D : Type ℓ₄}\n → A ≃ C → B ≃ D → A × B ≃ C × D\ntechnical-×-lemma {A = A} {B = B} {C = C} {D = D} f g = isoToEquiv (iso φ ψ η ε)\n where\n φ : (A × B) → (C × D)\n φ (a , b) = equivFun f a , equivFun g b\n\n ψ : (C × D) → (A × B)\n ψ (c , d) = equivFun (invEquiv f) c , equivFun (invEquiv g) d\n\n η : section φ ψ\n η (c , d) i = retEq f c i , retEq g d i\n\n ε : retract φ ψ\n ε (a , b) i = secEq f a i , secEq g b i\n\n\njoin-structure : (S₁ : Type ℓ₁ → Type ℓ₂) (S₂ : Type ℓ₁ → Type ℓ₄)\n → Type ℓ₁ → Type (ℓ-max ℓ₂ ℓ₄)\njoin-structure S₁ S₂ X = S₁ X × S₂ X\n\njoin-iso : {S₁ : Type ℓ₁ → Type ℓ₂}\n (ι₁ : (A B : Σ[ X ∈ (Type ℓ₁) ] (S₁ X)) → A .fst ≃ B .fst → Type ℓ₃)\n {S₂ : Type ℓ₁ → Type ℓ₄}\n (ι₂ : (A B : Σ[ X ∈ (Type ℓ₁) ] (S₂ X)) → A .fst ≃ B .fst → Type ℓ₅)\n (A B : Σ[ X ∈ (Type ℓ₁) ] (join-structure S₁ S₂ X))\n → A .fst ≃ B .fst\n → Type (ℓ-max ℓ₃ ℓ₅)\njoin-iso ι₁ ι₂ (X , s₁ , s₂) (Y , t₁ , t₂) f = (ι₁ (X , s₁) (Y , t₁) f) × (ι₂ (X , s₂) (Y , t₂) f)\n\njoin-⋆-lemma : (S₁ : Type ℓ₁ → Type ℓ₂) (S₂ : Type ℓ₁ → Type ℓ₄)\n {X Y : Type ℓ₁} {s₁ : S₁ X} {s₂ : S₂ X} {t₁ : S₁ Y} {t₂ : S₂ Y} (f : X ≃ Y)\n → (equivFun (join-structure S₁ S₂ ⋆ f) (s₁ , s₂) ≡ (t₁ , t₂)) ≃\n (equivFun (S₁ ⋆ f) s₁ ≡ t₁) × (equivFun (S₂ ⋆ f) s₂ ≡ t₂)\njoin-⋆-lemma S₁ S₂ {Y = Y} {s₁ = s₁} {s₂ = s₂} {t₁ = t₁} {t₂ = t₂} f = isoToEquiv (iso φ ψ η ε)\n where\n φ : equivFun (join-structure S₁ S₂ ⋆ f) (s₁ , s₂) ≡ (t₁ , t₂)\n → (equivFun (S₁ ⋆ f) s₁ ≡ t₁) × (equivFun (S₂ ⋆ f) s₂ ≡ t₂)\n φ p = (λ i → p i .fst) , (λ i → p i .snd)\n\n ψ : (equivFun (S₁ ⋆ f) s₁ ≡ t₁) × (equivFun (S₂ ⋆ f) s₂ ≡ t₂)\n → equivFun (join-structure S₁ S₂ ⋆ f) (s₁ , s₂) ≡ (t₁ , t₂)\n ψ (p , q) i = (p i) , (q i)\n\n η : section φ ψ\n η (p , q) = refl\n\n ε : retract φ ψ\n ε p = refl\n\njoin-SNS' : (S₁ : Type ℓ₁ → Type ℓ₂)\n (ι₁ : (A B : Σ[ X ∈ (Type ℓ₁) ] (S₁ X)) → A .fst ≃ B .fst → Type ℓ₃)\n (θ₁ : SNS' S₁ ι₁)\n (S₂ : Type ℓ₁ → Type ℓ₄)\n (ι₂ : (A B : Σ[ X ∈ (Type ℓ₁) ] (S₂ X)) → A .fst ≃ B .fst → Type ℓ₅)\n (θ₂ : SNS' S₂ ι₂)\n → SNS' (join-structure S₁ S₂) (join-iso ι₁ ι₂)\njoin-SNS' S₁ ι₁ θ₁ S₂ ι₂ θ₂ (X , s₁ , s₂) (Y , t₁ , t₂) f =\n equivFun (join-structure S₁ S₂ ⋆ f) (s₁ , s₂) ≡ (t₁ , t₂)\n ≃⟨ join-⋆-lemma S₁ S₂ f ⟩\n (equivFun (S₁ ⋆ f) s₁ ≡ t₁) × (equivFun (S₂ ⋆ f) s₂ ≡ t₂)\n ≃⟨ technical-×-lemma (θ₁ (X , s₁) (Y , t₁) f) (θ₂ (X , s₂) (Y , t₂) f) ⟩\n join-iso ι₁ ι₂ (X , s₁ , s₂) (Y , t₁ , t₂) f ■\n\n\n-- Now, we want to do Monoids as an example. We begin by showing SNS' for simple structures, i.e. pointed types and ∞-magmas.\n-- Pointed types with SNS'\npointed-structure : Type ℓ → Type ℓ\npointed-structure X = X\n\nPointed-Type : Type (ℓ-suc ℓ)\nPointed-Type {ℓ = ℓ} = Σ (Type ℓ) pointed-structure\n\npointed-iso : (A B : Pointed-Type) → A .fst ≃ B .fst → Type ℓ\npointed-iso A B f = equivFun f (A .snd) ≡ B .snd\n\npointed-is-SNS' : SNS' {ℓ = ℓ} pointed-structure pointed-iso\npointed-is-SNS' A B f = transportEquiv (λ i → transportRefl (equivFun f (A .snd)) i ≡ B .snd)\n\n\n-- ∞-Magmas with SNS'\n-- We need function extensionality for binary functions.\n-- TODO: upstream\nfunExtBin : {A : Type ℓ} {B : A → Type ℓ'} {C : (x : A) → B x → Type ℓ''} {f g : (x : A) → (y : B x) → C x y}\n → ((x : A) (y : B x) → f x y ≡ g x y) → f ≡ g\nfunExtBin p i x y = p x y i\nmodule _ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : A → Type ℓ'} {C : (x : A) → B x → Type ℓ''} {f g : (x : A) → (y : B x) → C x y} where\n private\n appl : f ≡ g → ∀ x y → f x y ≡ g x y\n appl eq x y i = eq i x y\n\n fib : (p : f ≡ g) → fiber funExtBin p\n fib p = (appl p , refl)\n\n funExtBin-fiber-isContr\n : (p : f ≡ g)\n → (fi : fiber funExtBin p)\n → fib p ≡ fi\n funExtBin-fiber-isContr p (h , eq) i = (appl (eq (~ i)) , λ j → eq (~ i ∨ j))\n\n funExtBin-isEquiv : isEquiv funExtBin\n equiv-proof funExtBin-isEquiv p = (fib p , funExtBin-fiber-isContr p)\n\n funExtBinEquiv : (∀ x y → f x y ≡ g x y) ≃ (f ≡ g)\n funExtBinEquiv = (funExtBin , funExtBin-isEquiv)\n\n-- ∞-Magmas\n∞-magma-structure : Type ℓ → Type ℓ\n∞-magma-structure X = X → X → X\n\n∞-Magma : Type (ℓ-suc ℓ)\n∞-Magma {ℓ = ℓ} = Σ (Type ℓ) ∞-magma-structure\n\n∞-magma-iso : (A B : ∞-Magma) → A .fst ≃ B .fst → Type ℓ\n∞-magma-iso (X , _·_) (Y , _∗_) f = (x x' : X) → equivFun f (x · x') ≡ (equivFun f x) ∗ (equivFun f x')\n\n∞-magma-is-SNS' : SNS' {ℓ = ℓ} ∞-magma-structure ∞-magma-iso\n∞-magma-is-SNS' (X , _·_) (Y , _∗_) f = SNS→SNS' ∞-magma-structure ∞-magma-iso C (X , _·_) (Y , _∗_) f\n where\n C : {X : Type ℓ} (_·_ _∗_ : X → X → X) → (_·_ ≡ _∗_) ≃ ((x x' : X) → (x · x') ≡ (x ∗ x'))\n C _·_ _∗_ = invEquiv funExtBinEquiv\n\n\n\n-- Now we're getting serious: Monoids\nraw-monoid-structure : Type ℓ → Type ℓ\nraw-monoid-structure X = X × (X → X → X)\n\n\nraw-monoid-iso : (M N : Σ (Type ℓ) raw-monoid-structure) → (M .fst) ≃ (N .fst) → Type ℓ\nraw-monoid-iso (M , e , _·_) (N , d , _∗_) f = (equivFun f e ≡ d)\n × ((x y : M) → equivFun f (x · y) ≡ (equivFun f x) ∗ (equivFun f y))\n\n-- If we ignore the axioms we get something like a \"raw\" monoid, which essentially is the join of a pointed type and an ∞-magma\nraw-monoid-is-SNS' : SNS' {ℓ = ℓ} raw-monoid-structure raw-monoid-iso\nraw-monoid-is-SNS' = join-SNS' pointed-structure pointed-iso pointed-is-SNS'\n ∞-magma-structure ∞-magma-iso ∞-magma-is-SNS'\n\n-- Now define monoids\nmonoid-axioms : (X : Type ℓ) → raw-monoid-structure X → Type ℓ\nmonoid-axioms X (e , _·_ ) = isSet X\n × ((x y z : X) → (x · (y · z)) ≡ ((x · y) · z))\n × ((x : X) → (x · e) ≡ x)\n × ((x : X) → (e · x) ≡ x)\n\nmonoid-structure : Type ℓ → Type ℓ\nmonoid-structure = add-to-structure (raw-monoid-structure) monoid-axioms\n\n-- TODO: it might be nicer to formulate the SIP lemmas so that they're\n-- easier to use for things that are not \"completely packaged\"\nMonoids : Type (ℓ-suc ℓ)\nMonoids = Σ (Type _) monoid-structure\n\nmonoid-iso : (M N : Monoids) → M .fst ≃ N .fst → Type ℓ\nmonoid-iso = add-to-iso raw-monoid-structure raw-monoid-iso monoid-axioms\n\n-- We have to show that the monoid axioms are indeed Propositions\nmonoid-axioms-are-Props : (X : Type ℓ) (s : raw-monoid-structure X) → isProp (monoid-axioms X s)\nmonoid-axioms-are-Props X (e , _·_) s = β s\n where\n α = s .fst\n β = isOfHLevelΣ 1 isPropIsSet\n λ _ → isOfHLevelΣ 1 (hLevelPi 1 (λ x → hLevelPi 1 λ y → hLevelPi 1 λ z → α (x · (y · z)) ((x · y) · z)))\n λ _ → isOfHLevelΣ 1 (hLevelPi 1 λ x → α (x · e) x)\n λ _ → hLevelPi 1 λ x → α (e · x) x\n\nmonoid-is-SNS' : SNS' {ℓ = ℓ} monoid-structure monoid-iso\nmonoid-is-SNS' = add-axioms-SNS' raw-monoid-structure raw-monoid-iso\n monoid-axioms monoid-axioms-are-Props raw-monoid-is-SNS'\n\nMonoidPath : (M N : Monoids {ℓ}) → (M ≃[ monoid-iso ] N) ≃ (M ≡ N)\nMonoidPath M N = SIP monoid-structure monoid-iso (SNS''→SNS''' monoid-is-SNS') M N\n", "meta": {"hexsha": "f73bd50aa946cb0426f27d27408ad154d3123298", "size": 22779, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Foundations/SIP.agda", "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": "Cubical/Foundations/SIP.agda", "max_issues_repo_name": "limemloh/cubical", "max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": "Cubical/Foundations/SIP.agda", "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": 44.2310679612, "max_line_length": 127, "alphanum_fraction": 0.5066508626, "num_tokens": 9834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056040203135, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3821995987609714}} {"text": "-- Andreas, 2012-06-07\n-- {-# OPTIONS --show-implicit -v tc.rec:100 -v tc.meta.assign:15 #-}\nmodule Issue387 where\n\nimport Common.Level\n\nmutual\n\n record R' (A : Set) : Set where\n field f : _\n\n c' : {A : Set} -> A -> R' A\n c' a = record { f = a }\n\n-- previous to fix of 387, this had an unresolved meta\n-- because two metas were created for _\n", "meta": {"hexsha": "858431542ea31ed004896523b9b5ef27dd713c94", "size": 348, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue387.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/Succeed/Issue387.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/Succeed/Issue387.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": 20.4705882353, "max_line_length": 69, "alphanum_fraction": 0.617816092, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.5964331462646254, "lm_q1q2_score": 0.38209645851208823}} {"text": "{- OPTIONS --without-K -}\n\nmodule Base where\n\nopen import Agda.Primitive public using (lzero)\n renaming (Level to ULevel; lsuc to lsucc; _⊔_ to lmax)\n\nType : (i : ULevel) → Set (lsucc i)\nType i = Set i\n\nType₀ = Type lzero\nType0 = Type lzero\n\nType₁ = Type (lsucc lzero)\nType1 = Type (lsucc lzero)\n\n{- Naturals -}\n\ndata ℕ : Type₀ where\n O : ℕ\n S : (n : ℕ) → ℕ\n\n{-# BUILTIN NATURAL ℕ #-}\n\nNat = ℕ\n\ninfix 3 _==_\n\ndata _==_ {i} {A : Type i} (a : A) : A → Type i where\n idp : a == a\n\nPath = _==_\n\n{-# BUILTIN EQUALITY _==_ #-}\n{-# BUILTIN REFL idp #-}\n\n{- Free path induction, or as close as I could get, written in Section 1.12.1 as\n\nind=A : ∏ ∏(x:A)C(x,x,reflx) → ∏ ∏ C(x,y,p) (C:∏(x,y:A)(x=Ay)→U) (x,y:A) (p:x=Ay)\nind=A (C, c, x, x, reflx) :≡ c(x)\n-}\nind== : ∀ {i j} {A : Type i} (D : (x y : A) → x == y → Type j) (d : (x : A) → D x x idp)\n {x y : A} (p : x == y) → D x y p\nind== D d {x} idp = d x -- slight concern: what rules govern the implicit {x} and {y}\n -- converging on the single {x} parameter here? I don't know Agda\n -- well enough to answer this yet. Depending upon what\n -- they are, this rule may be a duplicate of one of the based\n -- path induction rules below.\n \n{- Based path induction, or the J rule in HoTT-Agda lib -}\nind=' : ∀ {i j} {A : Type i} {a : A} (D : (x : A) (p : a == x) → Type j) (d : D a idp)\n {x : A} (p : a == x) → D x p\nind=' D d idp = d\n\n{- Right-based path induction, or J' in the HoTT-Agda lib -}\nind'= : ∀ {i j} {A : Type i} {a : A} (D : (x : A) (p : x == a) → Type j) (d : D a idp)\n {x : A} (p : x == a) → D x p\nind'= D d idp = d\n \nind==2 : ∀ {i j} {A : Type i} (D : {x y : A} → x == y → Type j) (d : {x : A} → D {x} {x} idp)\n {x y : A} (p : x == y) → D p\nind==2 D d idp = d -- slight concern: what rules govern the implicit {x} and {y}\n\n-- {- Alternative based path induction as a specialized free path induction -}\n-- ind='2 : ∀ {i j} {A : Type i} {a : A} (D : {x : A} (p : a == x) → Type j) (d : D idp)\n-- {x : A} (p : a == x) → D p\n-- ind='2 D d = ind==2 {!!} {!!}\n\n-- Christine Paulin-Mohring’s version of the J rule is based path induction ind='\nJ : ∀ {i j} {A : Type i} {a : A} (D : {x : A} → a == x → Type j) → D idp →\n {x : A} (p : a == x) → D p\nJ D d idp = d\n\n\n{- Unit type\n\nThe unit type is defined as record so that we also get the η-rule definitionally.\n-}\n\nrecord Unit : Type₀ where\n constructor unit\n\n{- Dependent paths\n\nThe notion of dependent path is a very important notion.\nIf you have a dependent type [B] over [A], a path [p : x == y] in [A] and two\npoints [u : B x] and [v : B y], there is a type [u == v [ B ↓ p ]] of paths from\n[u] to [v] lying over the path [p].\nBy definition, if [p] is a constant path, then [u == v [ B ↓ p ]] is just an\nordinary path in the fiber.\n-}\n\nPathOver : ∀ {i j} {A : Type i} (B : A → Type j)\n {x y : A} (p : x == y) (u : B x) (v : B y) → Type j\nPathOver B idp u v = (u == v)\n\nsyntax PathOver B p u v =\n u == v [ B ↓ p ]\n\n{- Ap, coe and transport\n\nGiven two fibrations over a type [A], a fiberwise map between the two fibrations\ncan be applied to any dependent path in the first fibration ([ap↓]).\nAs a special case, when [A] is [Unit], we find the familiar [ap] ([ap] is\ndefined in terms of [ap↓] because it shouldn’t change anything for the user\nand this is helpful in some rare cases)\n-}\n\nap : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y : A}\n → (x == y → f x == f y)\nap f idp = idp\n\nap↓ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}\n (g : {a : A} → B a → C a) {x y : A} {p : x == y}\n {u : B x} {v : B y}\n → (u == v [ B ↓ p ] → g u == g v [ C ↓ p ])\nap↓ g {p = idp} p = ap g p\n\n{-\n[apd↓] is defined in lib.PathOver. Unlike [ap↓] and [ap], [apd] is not\ndefinitionally a special case of [apd↓]\n-}\n\napd : ∀ {i j} {A : Type i} {B : A → Type j} (f : (a : A) → B a) {x y : A}\n → (p : x == y) → f x == f y [ B ↓ p ]\napd f idp = idp\n\n{-\nAn equality between types gives two maps back and forth\n-}\n\ncoe : ∀ {i} {A B : Type i} (p : A == B) → A → B\ncoe idp x = x\n\ncoe! : ∀ {i} {A B : Type i} (p : A == B) → B → A\ncoe! idp x = x\n\n{-\nThe operations of transport forward and backward are defined in terms of [ap]\nand [coe], because this is more convenient in practice.\n-}\n\ntransport : ∀ {i j} {A : Type i} (B : A → Type j) {x y : A} (p : x == y)\n → (B x → B y)\ntransport B p = coe (ap B p)\n\ntransport! : ∀ {i j} {A : Type i} (B : A → Type j) {x y : A} (p : x == y)\n → (B y → B x)\ntransport! B p = coe! (ap B p)\n\n{- Equational reasoning\n\nEquational reasoning is a way to write readable chains of equalities.\nThe idea is that you can write the following:\n\n t : a == e\n t = a =⟨ p ⟩\n b =⟨ q ⟩\n c =⟨ r ⟩\n d =⟨ s ⟩\n e ∎\n\nwhere [p] is a path from [a] to [b], [q] is a path from [b] to [c], and so on.\n\nYou often have to apply some equality in some context, for instance [p] could be\n[ap ctx thm] where [thm] is the interesting theorem used to prove that [a] is\nequal to [b], and [ctx] is the context.\nIn such cases, you can use instead [thm |in-ctx ctx]. The advantage is that\n[ctx] is usually boring whereas the first word of [thm] is the most interesting\npart.\n\n_=⟨_⟩ is not definitionally the same thing as concatenation of paths _∙_ because\nwe haven’t defined concatenation of paths yet, and also you probably shouldn’t\nreason on paths constructed with equational reasoning.\nIf you do want to reason on paths constructed with equational reasoning, check\nout lib.types.PathSeq instead.\n-}\n\ninfix 2 _∎\ninfixr 2 _=⟨_⟩_\n\n_=⟨_⟩_ : ∀ {i} {A : Type i} (x : A) {y z : A} → x == y → y == z → x == z\n_ =⟨ idp ⟩ idp = idp\n\n_∎ : ∀ {i} {A : Type i} (x : A) → x == x\n_ ∎ = idp\n\nsyntax ap f p = p |in-ctx f\n\n{- Truncation levels\n\nThe type of truncation levels is isomorphic to the type of natural numbers but\n\"starts at -2\".\n-}\n\ndata TLevel : Type₀ where\n ⟨-2⟩ : TLevel\n succT : (n : TLevel) → TLevel\n\nℕ₋₂ = TLevel\n\n⟨-1⟩ : TLevel\n⟨-1⟩ = succT ⟨-2⟩\n\n⟨0⟩ : TLevel\n⟨0⟩ = succT ⟨-1⟩\n\n{- Coproducts and case analysis -}\n\ndata Coprod {i j} (A : Type i) (B : Type j) : Type (lmax i j) where\n inl : A → Coprod A B\n inr : B → Coprod A B\n\n{- Σ-types\n\nΣ-types are defined as a record so that we have definitional η.\n-}\n\ninfix 1 _,_\n\nrecord Σ {i j} (A : Type i) (B : A → Type j) : Type (lmax i j) where\n constructor _,_\n field\n fst : A\n snd : B fst\nopen Σ public\n\npair= : ∀ {i j} {A : Type i} {B : A → Type j}\n {a a' : A} (p : a == a') {b : B a} {b' : B a'}\n (q : b == b' [ B ↓ p ])\n → (a , b) == (a' , b')\npair= idp q = ap (_,_ _) q\n\npair×= : ∀ {i j} {A : Type i} {B : Type j}\n {a a' : A} (p : a == a') {b b' : B} (q : b == b')\n → (a , b) == (a' , b')\npair×= idp q = pair= idp q\n\n\n{- Empty type\n\nWe define the eliminator of the empty type using an absurd pattern. Given that\nabsurd patterns are not consistent with HIT, we will not use empty patterns\nanymore after that.\n-}\n\ndata Empty : Type₀ where\n\nEmpty-elim : ∀ {i} {A : Empty → Type i} → ((x : Empty) → A x)\nEmpty-elim ()\n\n\n{- Negation and disequality -}\n\n¬ : ∀ {i} (A : Type i) → Type i\n¬ A = A → Empty\n\n_≠_ : ∀ {i} {A : Type i} → (A → A → Type i)\nx ≠ y = ¬ (x == y)\n\n-- Cartesian product\n_×_ : ∀ {i j} (A : Type i) (B : Type j) → Type _\nA × B = Σ A (λ _ → B)\n\n⊥ = Empty\n\n{- Π-types\n\nShorter notation for Π-types.\n-}\n\nΠ : ∀ {i j} (A : Type i) (P : A → Type j) → Type _\nΠ A P = (x : A) → P x\n\n{- Bool type -}\n\ndata Bool : Type₀ where\n true : Bool\n false : Bool\n\n\n{- Equivalences -}\n\nmodule _ {i} {j} {A : Type i} {B : Type j} where\n\n record is-equiv (f : A → B) : Type (lmax i j)\n where\n field\n g : B → A\n f-g : (b : B) → f (g b) == b\n g-f : (a : A) → g (f a) == a\n adj : (a : A) → ap f (g-f a) == f-g (f a)\n\n{- Definition of contractible types and truncation levels -}\n\nmodule _ {i} where\n is-contr : Type i → Type i\n is-contr A = Σ A (λ a → ((x : A) → a == x))\n\n has-level : ℕ₋₂ → (Type i → Type i)\n has-level ⟨-2⟩ A = is-contr A\n has-level (succT n) A = (x y : A) → has-level n (x == y)\n\n is-prop = has-level ⟨-1⟩\n is-set = has-level ⟨0⟩\n", "meta": {"hexsha": "7b66bae95454cba30bb630c8bc0474e45cdffb91", "size": 8122, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Base.agda", "max_stars_repo_name": "aerskine/hott-ex", "max_stars_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7", "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": "Base.agda", "max_issues_repo_name": "aerskine/hott-ex", "max_issues_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7", "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": "Base.agda", "max_forks_repo_name": "aerskine/hott-ex", "max_forks_repo_head_hexsha": "f8b6b11fb7ee0c54ce91a19338c5069a69a51dc7", "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": 26.5424836601, "max_line_length": 93, "alphanum_fraction": 0.5412459985, "num_tokens": 3100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.640635854839898, "lm_q1q2_score": 0.38209645851208823}} {"text": "module Thesis.BigStepSILR2 where\n\nopen import Data.Empty\nopen import Data.Unit.Base hiding (_≤_)\nopen import Data.Product\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Binary hiding (_⇒_)\nopen import Data.Nat -- using (ℕ; zero; suc; decTotalOrder; _<_; _≤_)\nopen import Data.Nat.Properties\nopen import Thesis.FunBigStepSILR2\n\n-- Standard relational big-step semantics, with step-indexes matching a small-step semantics.\n-- Protip: doing this on ANF terms would be much easier.\ndata _⊢_↓[_]_ {Γ} (ρ : ⟦ Γ ⟧Context) : ∀ {τ} → Term Γ τ → ℕ → Val τ → Set where\n abs : ∀ {τ₁ τ₂} {t : Term (τ₁ • Γ) τ₂} →\n ρ ⊢ abs t ↓[ 0 ] closure t ρ\n app : ∀ n1 n2 n3 {Γ′ τ₁ τ₂ ρ′ v₂ v′} {t₁ : Term Γ (τ₁ ⇒ τ₂)} {t₂ : Term Γ τ₁} {t′ : Term (τ₁ • Γ′) τ₂} →\n ρ ⊢ t₁ ↓[ n1 ] closure t′ ρ′ →\n ρ ⊢ t₂ ↓[ n2 ] v₂ →\n (v₂ • ρ′) ⊢ t′ ↓[ n3 ] v′ →\n ρ ⊢ app t₁ t₂ ↓[ suc n1 + n2 + n3 ] v′\n var : ∀ {τ} (x : Var Γ τ) →\n ρ ⊢ var x ↓[ 0 ] (⟦ x ⟧Var ρ)\n lit : ∀ n →\n ρ ⊢ const (lit n) ↓[ 0 ] intV n\n\n-- Silly lemmas for eval-dec-sound\nmodule _ where\n Done-inj : ∀ {τ} m n {v1 v2 : Val τ} → Done v1 m ≡ Done v2 n → m ≡ n\n Done-inj _ _ refl = refl\n\n lem1 : ∀ n d → d ≢ suc (n + d)\n lem1 n d eq rewrite +-comm n d = m≢1+m+n d eq\n\n subd : ∀ n d → n + d ≡ d → n ≡ 0\n subd zero d eq = refl\n subd (suc n) d eq = ⊥-elim (lem1 n d (sym eq))\n\n comp∸ : ∀ a b → b ≤ a → suc a ∸ b ≡ suc (a ∸ b)\n comp∸ a zero le = refl\n comp∸ zero (suc b) ()\n comp∸ (suc a) (suc b) (s≤s le) = comp∸ a b le\n\n rearr∸ : ∀ a b c → c ≤ b → a + (b ∸ c) ≡ (a + b) ∸ c\n rearr∸ a b zero c≤b = refl\n rearr∸ a zero (suc c) ()\n rearr∸ a (suc b) (suc c) (s≤s c≤b) rewrite +-suc a b = rearr∸ a b c c≤b\n\n cancel∸ : ∀ a b → b ≤ a → a ∸ b + b ≡ a\n cancel∸ a zero b≤a = +-identityʳ a\n cancel∸ zero (suc b) ()\n cancel∸ (suc a) (suc b) (s≤s b≤a) rewrite +-suc (a ∸ b) b = cong suc (cancel∸ a b b≤a)\n\n lemR : ∀ {τ} n m {v1 v2 : Val τ} → Done v1 m ≡ Done v2 n → m ≡ n\n lemR n .n refl = refl\n\n lem2 : ∀ n n3 r → n3 ≤ n → n + n3 ≡ suc r → ∃ λ s → (n ≡ suc s)\n lem2 zero .0 r z≤n ()\n lem2 (suc n) n3 .(n + n3) le refl = n , refl\n\n{-# TERMINATING #-}\neval-dec-sound : ∀ {Γ τ} → (t : Term Γ τ) → ∀ ρ v m n → eval t ρ m ≡ Done v n → ρ ⊢ t ↓[ m ∸ n ] v\neval-dec-sound (const (lit x)) ρ (intV v) m n eq with lemR n m eq\neval-dec-sound (const (lit x)) ρ (intV .x) m .m refl | refl rewrite n∸n≡0 m = lit x\neval-dec-sound (var x) ρ v m n eq with lemR n m eq\neval-dec-sound (var x) ρ .(⟦ x ⟧Var ρ) m .m refl | refl rewrite n∸n≡0 m = var x\neval-dec-sound (abs t) ρ v m n eq with lemR n m eq\neval-dec-sound (abs t) ρ .(closure t ρ) m .m refl | refl rewrite n∸n≡0 m = abs\neval-dec-sound (app s t) ρ v zero n ()\neval-dec-sound (app s t) ρ v (suc r) n eq with eval s ρ r | inspect (eval s ρ) r\neval-dec-sound (app s t) ρ v (suc r) n eq | (Done sv n1) | [ seq ] with eval t ρ n1 | inspect (eval t ρ) n1\neval-dec-sound (app s t) ρ v (suc r) n eq | (Done (closure st sρ) n1) | [ seq ] | (Done tv n2) | [ teq ] with eval st (tv • sρ) n2 | inspect (eval st (tv • sρ)) n2\neval-dec-sound (app s t) ρ .v (suc r) .n3 refl | (Done sv@(closure st sρ) n1) | [ seq ] | (Done tv n2) | [ teq ] | (Done v n3) | [ veq ] = body\n where\n n1≤r : n1 ≤ r\n n1≤r = eval-dec s ρ sv r n1 seq\n n2≤n1 : n2 ≤ n1\n n2≤n1 = eval-dec t ρ tv n1 n2 teq\n n3≤n2 : n3 ≤ n2\n n3≤n2 = eval-dec st (tv • sρ) v n2 n3 veq\n eval1 = eval-dec-sound s ρ sv r n1 seq\n eval2 = eval-dec-sound t ρ tv n1 n2 teq\n eval3 = eval-dec-sound st (tv • sρ) v n2 n3 veq\n l1 : suc r ∸ n3 ≡ suc (r ∸ n3)\n l1 = comp∸ r n3 (≤-trans n3≤n2 (≤-trans n2≤n1 n1≤r))\n l2 : suc r ∸ n3 ≡ suc (((r ∸ n1) + (n1 ∸ n2)) + (n2 ∸ n3))\n l2\n rewrite rearr∸ (r ∸ n1) n1 n2 n2≤n1 | cancel∸ r n1 n1≤r\n | rearr∸ (r ∸ n2) n2 n3 n3≤n2 | cancel∸ r n2 (≤-trans n2≤n1 n1≤r) = l1\n foo : ρ ⊢ app s t ↓[ suc (r ∸ n1 + (n1 ∸ n2) + (n2 ∸ n3)) ] v\n foo = app (r ∸ n1) (n1 ∸ n2) (n2 ∸ n3) {t₁ = s} {t₂ = t} {t′ = st} eval1 eval2 eval3\n body : ρ ⊢ app s t ↓[ suc r ∸ n3 ] v\n body rewrite l2 = foo\neval-dec-sound (app s t) ρ v (suc r) n () | (Done (closure st sρ) n1) | [ seq ] | (Done tv n2) | [ teq ] | Error | [ veq ]\neval-dec-sound (app s t) ρ v (suc r) n () | (Done (closure st sρ) n1) | [ seq ] | (Done tv n2) | [ teq ] | TimeOut | [ veq ]\neval-dec-sound (app s t) ρ v (suc r) n () | (Done sv n1) | [ seq ] | Error | [ teq ]\neval-dec-sound (app s t) ρ v (suc r) n () | (Done sv n1) | [ seq ] | TimeOut | [ teq ]\neval-dec-sound (app s t) ρ v (suc r) n () | Error | [ seq ]\neval-dec-sound (app s t) ρ v (suc r) n () | TimeOut | [ seq ]\n-- ↦-sound : ∀ {Γ τ} ρ (x : Var Γ τ) →\n-- ((Den.⟦ x ⟧Var) (⟦ ρ ⟧Context)) ≡ (⟦ (⟦ x ⟧Var) ρ ⟧Val)\n-- ↦-sound (px • ρ) this = refl\n-- ↦-sound (px • ρ) (that x) = ↦-sound ρ x\n\n-- ↓-sound : ∀ {Γ τ ρ v} {t : Term Γ τ} →\n-- ρ ⊢ t ↓ v →\n-- ⟦ t ⟧Term ⟦ ρ ⟧Env ≡ ⟦ v ⟧Val\n-- ↓-sound abs = refl\n-- ↓-sound (app ↓₁ ↓₂ ↓′) rewrite ↓-sound ↓₁ | ↓-sound ↓₂ | ↓-sound ↓′ = refl\n-- ↓-sound (var x) = ↦-sound _ x\n-- ↓-sound (lit n) = refl\n\nimport Data.Integer as I\nopen I using (ℤ)\n\n-- The extra \"r\" stands for \"relational\", because unlike relT and relV, rrelV\n-- and rrelT are based on a *relational* big-step semantics.\nmutual\n rrelT : ∀ {τ Γ} (t1 : Term Γ τ) (t2 : Term Γ τ) (ρ1 : ⟦ Γ ⟧Context) (ρ2 : ⟦ Γ ⟧Context) → ℕ → Set\n rrelT {τ} t1 t2 ρ1 ρ2 k =\n (v1 : Val τ) →\n ∀ j (jn : (n : ℕ) → isConnected (1 + n) X\n → (m k : ℕ) → isConnectedFun ((1 + m) · n) (incl {X∙ = X∙} {n = k + m})\n isConnectedIncl>n n conn m k = isConnectedFunSubtr _ (k · n) _\n (subst (λ d → isConnectedFun d (incl {X∙ = X∙} {n = k + m}))\n (nat-path n m k) (isConnectedIncl n conn (k + m)))\n\n private\n inl∞ : (n : ℕ) → 𝕁ames n → 𝕁ames∞\n inl∞ _ = inl\n\n isConnectedInl : (n : ℕ) → isConnected (1 + n) X\n → (m : ℕ) → isConnectedFun ((1 + m) · n) (inl∞ m)\n isConnectedInl n conn m = isConnectedInl∞ _ _ _ (isConnectedIncl>n _ conn _)\n", "meta": {"hexsha": "b535067891baa160d41d5acb217ede7c0a68b5a6", "size": 9259, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/HITs/James/Inductive/PushoutFormula.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_issues_repo_path": "Cubical/HITs/James/Inductive/PushoutFormula.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/HITs/James/Inductive/PushoutFormula.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": 34.0404411765, "max_line_length": 102, "alphanum_fraction": 0.5663678583, "num_tokens": 4277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6791787121629466, "lm_q2_score": 0.5621765008857982, "lm_q1q2_score": 0.381818311879888}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Basics\nopen import lib.types.FunctionSeq\nopen import lib.types.TLevel\nopen import lib.types.Pi\nopen import lib.types.Pointed\nopen import lib.types.Sigma\nopen import lib.NType2\n\nmodule lib.types.Truncation where\n\nmodule _ {i} where\n\n postulate -- HIT\n Trunc : (n : ℕ₋₂) (A : Type i) → Type i\n [_] : {n : ℕ₋₂} {A : Type i} → A → Trunc n A\n instance Trunc-level : {n : ℕ₋₂} {A : Type i} → has-level n (Trunc n A)\n\n module TruncElim {n : ℕ₋₂} {A : Type i} {j} {P : Trunc n A → Type j}\n {{p : (x : Trunc n A) → has-level n (P x)}} (d : (a : A) → P [ a ]) where\n\n postulate -- HIT\n f : Π (Trunc n A) P\n [_]-β : ∀ a → f [ a ] ↦ d a\n {-# REWRITE [_]-β #-}\n\nopen TruncElim public renaming (f to Trunc-elim)\n\nmodule TruncRec {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} {{p : has-level n B}}\n (d : A → B) where\n\n private\n module M = TruncElim {{λ x → p}} d\n\n f : Trunc n A → B\n f = M.f\n\nopen TruncRec public renaming (f to Trunc-rec)\n\nmodule TruncRecType {i j} {n : ℕ₋₂} {A : Type i} (d : A → n -Type j) where\n\n open TruncRec {{n -Type-level j}} d public\n\n flattening-Trunc : Σ (Trunc (S n) A) (fst ∘ f) ≃ Trunc (S n) (Σ A (fst ∘ d))\n flattening-Trunc = equiv to from to-from from-to where\n\n to-aux : (x : Trunc (S n) A) → (fst (f x) → Trunc (S n) (Σ A (fst ∘ d)))\n to-aux = Trunc-elim (λ a b → [ (a , b) ])\n\n to : Σ (Trunc (S n) A) (fst ∘ f) → Trunc (S n) (Σ A (fst ∘ d))\n to (x , y) = to-aux x y\n\n from-aux : Σ A (fst ∘ d) → Σ (Trunc (S n) A) (fst ∘ f)\n from-aux (a , b) = ([ a ] , b)\n\n from : Trunc (S n) (Σ A (fst ∘ d)) → Σ (Trunc (S n) A) (fst ∘ f)\n from = Trunc-rec {{Σ-level ⟨⟩ (λ x → raise-level _ (snd (f x)))}}\n from-aux where\n\n to-from : (x : Trunc (S n) (Σ A (fst ∘ d))) → to (from x) == x\n to-from = Trunc-elim (λ _ → idp)\n\n from-to-aux : (a : Trunc (S n) A) (b : fst (f a)) → from (to-aux a b) == (a , b)\n from-to-aux = Trunc-elim {{λ _ → Π-level (λ _ → =-preserves-level (Σ-level ⟨⟩ (λ x → raise-level _ (snd (f x)))))}}\n (λ a b → idp)\n\n from-to : (x : Σ (Trunc (S n) A) (fst ∘ f)) → from (to x) == x\n from-to (a , b) = from-to-aux a b\n\n\n⊙Trunc : ∀ {i} → ℕ₋₂ → Ptd i → Ptd i\n⊙Trunc n ⊙[ A , a ] = ⊙[ Trunc n A , [ a ] ]\n\n⊙Trunc-rec : ∀ {i j} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j} {{Y-level : has-level n (de⊙ Y)}}\n → X ⊙→ Y\n → ⊙Trunc n X ⊙→ Y\n⊙Trunc-rec {{Y-level}} f = Trunc-rec {{Y-level}} (fst f) , snd f\n\n⊙Trunc-rec-post-⊙∘ : ∀ {i j k} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n {{Y-level : has-level n (de⊙ Y)}} {{Z-level : has-level n (de⊙ Z)}}\n (g : Y ⊙→ Z) (f : X ⊙→ Y)\n → ⊙Trunc-rec {n = n} {{Z-level}} (g ⊙∘ f) == g ⊙∘ ⊙Trunc-rec {{Y-level}} f\n⊙Trunc-rec-post-⊙∘ {{Y-level}} {{Z-level}} g f =\n ⊙λ=' (Trunc-elim {{λ x → =-preserves-level Z-level}} (λ x → idp)) idp\n\nmodule _ {i} {A : Type i} where\n\n [_]₀ : A → Trunc 0 A\n [_]₀ = [_] {n = 0}\n\n [_]₁ : A → Trunc 1 A\n [_]₁ = [_] {n = 1}\n\n [_]₂ : A → Trunc 2 A\n [_]₂ = [_] {n = 2}\n\nmodule _ {i} {n : ℕ₋₂} {A : Type i} where\n\n private\n Trunc= : (a b : Trunc (S n) A) → n -Type i\n Trunc= = Trunc-elim (λ a → Trunc-elim ((λ b → (Trunc n (a == b) , Trunc-level))))\n\n {- t is for truncated -}\n _=ₜ_ : (a b : Trunc (S n) A) → Type i\n _=ₜ_ a b = fst (Trunc= a b)\n\n =ₜ-level : (a b : Trunc (S n) A) → has-level n (a =ₜ b)\n =ₜ-level a b = snd (Trunc= a b)\n\n =ₜ-refl : (a : Trunc (S n) A) → a =ₜ a\n =ₜ-refl = Trunc-elim {{λ x → raise-level _ (=ₜ-level x x)}}\n (λ a → [ idp ])\n\n =ₜ-equiv : (a b : Trunc (S n) A) → (a == b) ≃ (a =ₜ b)\n =ₜ-equiv a b = to a b , to-is-equiv a b where\n\n to : (a b : Trunc (S n) A) → (a == b → a =ₜ b)\n to a b p = transport (λ c → a =ₜ c) p (=ₜ-refl a)\n\n from-aux : (a b : A) → a == b → [ a ] == [ b ] :> Trunc (S n) A\n from-aux _ _ = ap [_]\n\n from : (a b : Trunc (S n) A) → a =ₜ b → a == b\n from = Trunc-elim (λ a → Trunc-elim (λ b → Trunc-rec (from-aux a b)))\n\n to-from-aux : (a b : A) → (p : a == b) → to _ _ (from-aux a b p) == [ p ]\n to-from-aux a .a idp = idp\n\n to-from : (a b : Trunc (S n) A) (x : a =ₜ b) → to a b (from a b x) == x\n to-from = Trunc-elim {{λ x → Π-level (λ y → Π-level (λ _ → =-preserves-level (raise-level _ (=ₜ-level x y))))}}\n (λ a → Trunc-elim {{λ x → Π-level (λ _ → =-preserves-level (raise-level _ (=ₜ-level [ a ] x)))}}\n (λ b → Trunc-elim\n (to-from-aux a b)))\n\n from-to-aux : (a : Trunc (S n) A) → from a a (=ₜ-refl a) == idp\n from-to-aux = Trunc-elim (λ _ → idp)\n\n from-to : (a b : Trunc (S n) A) (p : a == b) → from a b (to a b p) == p\n from-to a .a idp = from-to-aux a\n\n adj : (ta tb : Trunc (S n) A) (p : ta == tb)\n → ap (to ta tb) (from-to ta tb p) == to-from ta tb (to ta tb p)\n adj ta .ta idp =\n Trunc-elim {P = λ ta → ap (to ta ta) (from-to ta ta idp) == to-from ta ta (to ta ta idp)}\n {{λ x → =-preserves-level $ =-preserves-level $ raise-level _ $ =ₜ-level x x}}\n (λ _ → idp)\n ta\n\n to-is-equiv : ∀ a b → is-equiv (to a b)\n to-is-equiv a b =\n record\n { g = from a b\n ; f-g = to-from a b\n ; g-f = from-to a b\n ; adj = adj a b\n }\n\n =ₜ-path : (a b : Trunc (S n) A) → (a == b) == (a =ₜ b)\n =ₜ-path a b = ua (=ₜ-equiv a b)\n\n{- Universal property -}\n\nabstract\n Trunc-rec-is-equiv : ∀ {i j} (n : ℕ₋₂) (A : Type i) (B : Type j)\n {{p : has-level n B}} → is-equiv (Trunc-rec {{p}} :> ((A → B) → (Trunc n A → B)))\n Trunc-rec-is-equiv n A B {{p}} = is-eq _ (λ f → f ∘ [_])\n (λ f → λ= (Trunc-elim (λ a → idp))) (λ f → idp)\n\n\nTrunc-preserves-level : ∀ {i} {A : Type i} {n : ℕ₋₂} (m : ℕ₋₂)\n → has-level n A → has-level n (Trunc m A)\nTrunc-preserves-level {n = ⟨-2⟩} _ p = has-level-in\n ([ contr-center p ] , Trunc-elim (λ a → ap [_] (contr-path p a)))\nTrunc-preserves-level ⟨-2⟩ _ = contr-has-level Trunc-level\nTrunc-preserves-level {n = (S n)} (S m) c = has-level-in (λ t₁ t₂ →\n Trunc-elim\n {{λ s₁ → prop-has-level-S {A = has-level n (s₁ == t₂)} has-level-is-prop}}\n (λ a₁ → Trunc-elim\n {{λ s₂ → prop-has-level-S {A = has-level n ([ a₁ ] == s₂)} has-level-is-prop}}\n (λ a₂ → equiv-preserves-level\n ((=ₜ-equiv [ a₁ ] [ a₂ ])⁻¹)\n {{Trunc-preserves-level {n = n} m (has-level-apply c a₁ a₂)}})\n t₂)\n t₁)\n\n{- an n-type is equivalent to its n-truncation -}\nunTrunc-equiv : ∀ {i} {n : ℕ₋₂} (A : Type i)\n {{_ : has-level n A}} → Trunc n A ≃ A\nunTrunc-equiv A = equiv f [_] (λ _ → idp) g-f where\n f = Trunc-rec (idf _)\n g-f = Trunc-elim (λ _ → idp)\n\n⊙unTrunc-equiv : ∀ {i} {n : ℕ₋₂} (X : Ptd i)\n {{_ : has-level n (de⊙ X)}} → ⊙Trunc n X ⊙≃ X\n⊙unTrunc-equiv {n = n} X = ≃-to-⊙≃ (unTrunc-equiv (de⊙ X)) idp\n\n-- Equivalence associated to the universal property\nTrunc-extend-equiv : ∀ {i j} (n : ℕ₋₂) (A : Type i) (B : Type j)\n {{p : has-level n B}} → (A → B) ≃ (Trunc n A → B)\nTrunc-extend-equiv n A B = (Trunc-rec , Trunc-rec-is-equiv n A B)\n\nTrunc-fmap : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} → ((A → B) → (Trunc n A → Trunc n B))\nTrunc-fmap f = Trunc-rec ([_] ∘ f)\n\n⊙Trunc-fmap : ∀ {i j} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j} → ((X ⊙→ Y) → (⊙Trunc n X ⊙→ ⊙Trunc n Y))\n⊙Trunc-fmap F = Trunc-fmap (fst F) , ap [_] (snd F)\n\n–>-unTrunc-equiv-natural : ∀ {i} {j} {n : ℕ₋₂}\n {A : Type i} {B : Type j} (f : A → B)\n {{_ : has-level n A}} {{_ : has-level n B}}\n → –> (unTrunc-equiv {n = n} B) ∘ Trunc-fmap f ∼\n f ∘ –> (unTrunc-equiv {n = n} A)\n–>-unTrunc-equiv-natural f = Trunc-elim (λ a → idp)\n\n⊙–>-⊙unTrunc-equiv-natural : ∀ {i} {j} {n : ℕ₋₂}\n {X : Ptd i} {Y : Ptd j} (f : X ⊙→ Y)\n {{_ : has-level n (de⊙ X)}} {{_ : has-level n (de⊙ Y)}}\n → ⊙–> (⊙unTrunc-equiv {n = n} Y) ⊙∘ ⊙Trunc-fmap f ==\n f ⊙∘ ⊙–> (⊙unTrunc-equiv {n = n} X)\n⊙–>-⊙unTrunc-equiv-natural (f' , idp) =\n ⊙λ=' (–>-unTrunc-equiv-natural f') idp\n\n⊙–>-⊙unTrunc-equiv-natural-=⊙∘ : ∀ {i} {n : ℕ₋₂}\n {X Y : Ptd i} (f : X ⊙→ Y)\n {{_ : has-level n (de⊙ X)}} {{_ : has-level n (de⊙ Y)}}\n → ⊙–> (⊙unTrunc-equiv {n = n} Y) ◃⊙∘\n ⊙Trunc-fmap f ◃⊙idf\n =⊙∘\n f ◃⊙∘\n ⊙–> (⊙unTrunc-equiv {n = n} X) ◃⊙idf\n⊙–>-⊙unTrunc-equiv-natural-=⊙∘ f =\n =⊙∘-in (⊙–>-⊙unTrunc-equiv-natural f)\n\nTrunc-fmap2 : ∀ {i j k} {n : ℕ₋₂} {A : Type i} {B : Type j} {C : Type k}\n → ((A → B → C) → (Trunc n A → Trunc n B → Trunc n C))\nTrunc-fmap2 f = Trunc-rec (λ a → Trunc-fmap (f a))\n\n⊙Trunc-rec-⊙Trunc-fmap : ∀ {i j k} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n {{Z-level : has-level n (de⊙ Z)}}\n (g : Y ⊙→ Z) (f : X ⊙→ Y)\n → ⊙Trunc-rec {n = n} {{Z-level}} g ⊙∘ ⊙Trunc-fmap f ==\n ⊙Trunc-rec {n = n} {{Z-level}} (g ⊙∘ f)\n⊙Trunc-rec-⊙Trunc-fmap {{Z-level}} g f =\n ⊙λ=' (Trunc-elim {{λ tx → =-preserves-level Z-level}} (λ x → idp)) $\n ap (_∙ snd g) (∘-ap (Trunc-elim (fst g)) [_] (snd f))\n\n-- XXX What is the naming convention?\nTrunc-fpmap : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} {f g : A → B}\n → f ∼ g → Trunc-fmap {n = n} f ∼ Trunc-fmap g\nTrunc-fpmap h = Trunc-elim (ap [_] ∘ h)\n\nTrunc-fmap-idf : ∀ {i} {n : ℕ₋₂} {A : Type i}\n → ∀ x → Trunc-fmap {n = n} (idf A) x == x\nTrunc-fmap-idf = Trunc-elim (λ _ → idp)\n\n⊙Trunc-fmap-⊙idf : ∀ {i} {n : ℕ₋₂} {X : Ptd i}\n → ⊙Trunc-fmap (⊙idf X) ⊙∼ ⊙idf (⊙Trunc n X)\n⊙Trunc-fmap-⊙idf = Trunc-fmap-idf , idp\n\ntransport-Trunc : ∀ {i} {n : ℕ₋₂} {A B : Type i}\n (p : A == B)\n → transport (Trunc n) p == Trunc-fmap (coe p)\ntransport-Trunc p@idp = ! (λ= Trunc-fmap-idf)\n\n⊙transport-⊙Trunc : ∀ {i} {n : ℕ₋₂} {X Y : Ptd i}\n (p : X == Y)\n → ⊙transport (⊙Trunc n) p == ⊙Trunc-fmap (⊙coe p)\n⊙transport-⊙Trunc p@idp = ! (⊙λ= ⊙Trunc-fmap-⊙idf)\n\nTrunc-fmap-cst : ∀ {i} {j} {n : ℕ₋₂} {A : Type i} {B : Type j}\n → ∀ (b : B) → Trunc-fmap {n = n} {A = A} (cst b) ∼ cst [ b ]\nTrunc-fmap-cst b = Trunc-elim (λ a → idp)\n\n⊙Trunc-fmap-cst : ∀ {i} {j} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j}\n → ⊙Trunc-fmap {n = n} (⊙cst {X = X} {Y = Y}) ⊙∼ ⊙cst\n⊙Trunc-fmap-cst {Y = Y} = Trunc-fmap-cst (pt Y) , idp\n\nTrunc-fmap-∘ : ∀ {i j k} {n : ℕ₋₂} {A : Type i} {B : Type j} {C : Type k}\n (g : B → C) (f : A → B)\n → ∀ x → Trunc-fmap {n = n} g (Trunc-fmap f x) == Trunc-fmap (g ∘ f) x\nTrunc-fmap-∘ g f = Trunc-elim (λ _ → idp)\n\n⊙Trunc-fmap-⊙∘ : ∀ {i j k} {n : ℕ₋₂} {A : Ptd i} {B : Ptd j} {C : Ptd k}\n (g : B ⊙→ C) (f : A ⊙→ B)\n → ⊙Trunc-fmap {n = n} g ⊙∘ ⊙Trunc-fmap f ⊙∼ ⊙Trunc-fmap (g ⊙∘ f)\n⊙Trunc-fmap-⊙∘ {n = n} g f =\n Trunc-fmap-∘ (fst g) (fst f) , pres-pt-path\n where\n pres-pt-path : snd (⊙Trunc-fmap {n = n} g ⊙∘ ⊙Trunc-fmap f) == snd (⊙Trunc-fmap (g ⊙∘ f))\n pres-pt-path =\n ap (Trunc-fmap (fst g)) (ap [_] (snd f)) ∙ ap [_] (snd g)\n =⟨ ap (_∙ ap [_] (snd g))\n (∘-ap (Trunc-fmap (fst g)) [_] (snd f) ∙\n ap-∘ [_] (fst g) (snd f)) ⟩\n ap [_] (ap (fst g) (snd f)) ∙ ap [_] (snd g)\n =⟨ ∙-ap [_] (ap (fst g) (snd f)) (snd g) ⟩\n ap [_] (ap (fst g) (snd f) ∙ snd g) =∎\n\n⊙Trunc-fmap-seq : ∀ {i} {n : ℕ₋₂} {X Y : Ptd i}\n → X ⊙–→ Y\n → ⊙Trunc n X ⊙–→ ⊙Trunc n Y\n⊙Trunc-fmap-seq ⊙idf-seq = ⊙idf-seq\n⊙Trunc-fmap-seq (f ◃⊙∘ fs) = ⊙Trunc-fmap f ◃⊙∘ ⊙Trunc-fmap-seq fs\n\n⊙Trunc-fmap-seq-⊙∘ : ∀ {i} {n : ℕ₋₂} {X Y : Ptd i} (fs : X ⊙–→ Y)\n → ⊙Trunc-fmap {n = n} (⊙compose fs) ◃⊙idf =⊙∘ ⊙Trunc-fmap-seq fs\n⊙Trunc-fmap-seq-⊙∘ ⊙idf-seq = =⊙∘-in (⊙λ= (⊙Trunc-fmap-⊙idf))\n⊙Trunc-fmap-seq-⊙∘ (f ◃⊙∘ fs) = =⊙∘-in $\n ⊙Trunc-fmap (f ⊙∘ ⊙compose fs)\n =⟨ ! $ ⊙λ= $ ⊙Trunc-fmap-⊙∘ f (⊙compose fs) ⟩\n ⊙Trunc-fmap f ⊙∘ ⊙Trunc-fmap (⊙compose fs)\n =⟨ ap (⊙Trunc-fmap f ⊙∘_) (=⊙∘-out (⊙Trunc-fmap-seq-⊙∘ fs)) ⟩\n ⊙Trunc-fmap f ⊙∘ ⊙compose (⊙Trunc-fmap-seq fs) =∎\n\n⊙Trunc-fmap-seq-=⊙∘ : ∀ {i} {n : ℕ₋₂} {X Y : Ptd i} {fs gs : X ⊙–→ Y}\n → fs =⊙∘ gs\n → ⊙Trunc-fmap-seq {n = n} fs =⊙∘ ⊙Trunc-fmap-seq {n = n} gs\n⊙Trunc-fmap-seq-=⊙∘ {fs = fs} {gs = gs} p =\n ⊙Trunc-fmap-seq fs\n =⊙∘⟨ !⊙∘ (⊙Trunc-fmap-seq-⊙∘ fs) ⟩\n ⊙Trunc-fmap (⊙compose fs) ◃⊙idf\n =⊙∘₁⟨ ap ⊙Trunc-fmap (=⊙∘-out p) ⟩\n ⊙Trunc-fmap (⊙compose gs) ◃⊙idf\n =⊙∘⟨ ⊙Trunc-fmap-seq-⊙∘ gs ⟩\n ⊙Trunc-fmap-seq gs ∎⊙∘\n\nTrunc-csmap : ∀ {i₀ i₁ j₀ j₁} {n : ℕ₋₂}\n {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}\n {f : A₀ → B₀} {g : A₁ → B₁} {hA : A₀ → A₁} {hB : B₀ → B₁}\n → CommSquare f g hA hB\n → CommSquare (Trunc-fmap {n = n} f) (Trunc-fmap g) (Trunc-fmap hA) (Trunc-fmap hB)\nTrunc-csmap (comm-sqr cs) = comm-sqr $ Trunc-elim (ap [_] ∘ cs)\n\n{- Pushing concatenatation through _=ₜ_ -}\nmodule _ {i} {n : ℕ₋₂} {A : Type i} where\n\n {- concatenation in _=ₜ_ -}\n _∙ₜ_ : {ta tb tc : Trunc (S n) A}\n → ta =ₜ tb → tb =ₜ tc → ta =ₜ tc\n _∙ₜ_ {ta = ta} {tb = tb} {tc = tc} =\n Trunc-elim {P = λ ta → C ta tb tc}\n {{λ ta → level ta tb tc}}\n (λ a → Trunc-elim {P = λ tb → C [ a ] tb tc}\n {{λ tb → level [ a ] tb tc}}\n (λ b → Trunc-elim {P = λ tc → C [ a ] [ b ] tc}\n {{λ tc → level [ a ] [ b ] tc}}\n (λ c → Trunc-fmap2 _∙_)\n tc)\n tb)\n ta\n where\n C : (ta tb tc : Trunc (S n) A) → Type i\n C ta tb tc = ta =ₜ tb → tb =ₜ tc → ta =ₜ tc\n level : (ta tb tc : Trunc (S n) A) → has-level (S n) (C ta tb tc)\n level ta tb tc =\n raise-level _ $\n Π-level $ λ _ →\n Π-level $ λ _ →\n =ₜ-level ta tc\n\n {- inversion in _=ₜ_ -}\n !ₜ : {ta tb : Trunc (S n) A}\n → ta =ₜ tb\n → tb =ₜ ta\n !ₜ {ta = ta} {tb = tb} =\n Trunc-elim {P = λ ta → C ta tb}\n {{λ ta → level ta tb}}\n (λ a → Trunc-elim {P = λ tb → C [ a ] tb}\n {{λ tb → level [ a ] tb}}\n (λ b → Trunc-fmap !)\n tb)\n ta\n where\n C : (ta tb : Trunc (S n) A) → Type i\n C ta tb = ta =ₜ tb → tb =ₜ ta\n level : (ta tb : Trunc (S n) A) → has-level (S n) (C ta tb)\n level ta tb = raise-level _ $ Π-level $ λ _ → =ₜ-level tb ta\n\n ∙ₜ-assoc : {ta tb tc td : Trunc (S n) A}\n (tp : ta =ₜ tb) (tq : tb =ₜ tc) (tr : tc =ₜ td)\n → _∙ₜ_ {ta} (_∙ₜ_ {ta} tp tq) tr\n == _∙ₜ_ {ta} tp (_∙ₜ_ {tb} tq tr)\n ∙ₜ-assoc {ta = ta} {tb = tb} {tc = tc} {td = td} =\n Trunc-elim {P = λ ta → C ta tb tc td}\n {{λ ta → C-level ta tb tc td}}\n (λ a → Trunc-elim {P = λ tb → C [ a ] tb tc td}\n {{λ tb → C-level [ a ] tb tc td}}\n (λ b → Trunc-elim {P = λ tc → C [ a ] [ b ] tc td}\n {{λ tc → C-level [ a ] [ b ] tc td}}\n (λ c → Trunc-elim {P = λ td → C [ a ] [ b ] [ c ] td}\n {{λ td → C-level [ a ] [ b ] [ c ] td}}\n (λ d tp tq tr → Trunc-elim\n {P = λ tp → D [ a ] [ b ] [ c ] [ d ] tp tq tr}\n {{λ tp → D-level [ a ] [ b ] [ c ] [ d ] tp tq tr}}\n (λ p → Trunc-elim\n {P = λ tq → D [ a ] [ b ] [ c ] [ d ] [ p ] tq tr}\n {{λ tq → D-level [ a ] [ b ] [ c ] [ d ] [ p ] tq tr}}\n (λ q → Trunc-elim\n {P = λ tr → D [ a ] [ b ] [ c ] [ d ] [ p ] [ q ] tr}\n {{λ tr → D-level [ a ] [ b ] [ c ] [ d ] [ p ] [ q ] tr}}\n (λ r → ap [_] (∙-assoc p q r))\n tr)\n tq)\n tp)\n td)\n tc)\n tb)\n ta\n where\n D : (ta tb tc td : Trunc (S n) A)\n → ta =ₜ tb → tb =ₜ tc → tc =ₜ td\n → Type i\n D ta tb tc td tp tq tr =\n _∙ₜ_ {ta} (_∙ₜ_ {ta} tp tq) tr\n == _∙ₜ_ {ta} tp (_∙ₜ_ {tb} tq tr)\n C : (ta tb tc td : Trunc (S n) A) → Type i\n C ta tb tc td = ∀ tp tq tr → D ta tb tc td tp tq tr\n D-level : (ta tb tc td : Trunc (S n) A)\n (tp : ta =ₜ tb) (tq : tb =ₜ tc) (tr : tc =ₜ td)\n → has-level n (D ta tb tc td tp tq tr)\n D-level ta tb tc td tp tq tr = =-preserves-level (=ₜ-level ta td)\n C-level : (ta tb tc td : Trunc (S n) A) → has-level (S n) (C ta tb tc td)\n C-level ta tb tc td =\n raise-level _ $\n Π-level $ λ tp →\n Π-level $ λ tq →\n Π-level $ λ tr →\n D-level ta tb tc td tp tq tr\n\n abstract\n ∙ₜ-assoc-pentagon : {ta tb tc td te : Trunc (S n) A}\n (tp : ta =ₜ tb) (tq : tb =ₜ tc) (tr : tc =ₜ td) (ts : td =ₜ te)\n → ∙ₜ-assoc {ta} (_∙ₜ_ {ta} tp tq) tr ts ◃∙\n ∙ₜ-assoc {ta} tp tq (_∙ₜ_ {tc} tr ts) ◃∎\n =ₛ\n ap (λ u → _∙ₜ_ {ta} u ts) (∙ₜ-assoc {ta} tp tq tr) ◃∙\n ∙ₜ-assoc {ta} tp (_∙ₜ_ {tb} tq tr) ts ◃∙\n ap (_∙ₜ_ {ta} tp) (∙ₜ-assoc {tb} tq tr ts) ◃∎\n ∙ₜ-assoc-pentagon {ta} {tb} {tc} {td} {te} = core ta tb tc td te\n where\n P : (ta tb tc td te : Trunc (S n) A)\n (tp : ta =ₜ tb) (tq : tb =ₜ tc) (tr : tc =ₜ td) (ts : td =ₜ te)\n → Type i\n P ta tb tc td te tp tq tr ts =\n ∙ₜ-assoc {ta} (_∙ₜ_ {ta} tp tq) tr ts ◃∙\n ∙ₜ-assoc {ta} tp tq (_∙ₜ_ {tc} tr ts) ◃∎\n =ₛ\n ap (λ u → _∙ₜ_ {ta} u ts) (∙ₜ-assoc {ta} tp tq tr) ◃∙\n ∙ₜ-assoc {ta} tp (_∙ₜ_ {tb} tq tr) ts ◃∙\n ap (_∙ₜ_ {ta} tp) (∙ₜ-assoc {tb} tq tr ts) ◃∎\n P-level : ∀ ta tb tc td te →\n (tp : ta =ₜ tb) (tq : tb =ₜ tc) (tr : tc =ₜ td) (ts : td =ₜ te)\n → has-level n (P ta tb tc td te tp tq tr ts)\n P-level ta tb tc td te tp tq tr ts =\n =ₛ-level $ raise-level _ $ raise-level _ $ =ₜ-level ta te\n Q : (ta tb tc td te : Trunc (S n) A) → Type i\n Q ta tb tc td te = ∀ tp tq tr ts → P ta tb tc td te tp tq tr ts\n Q-level : ∀ ta tb tc td te → has-level (S n) (Q ta tb tc td te)\n Q-level ta tb tc td te =\n raise-level n $\n Π-level $ λ tp →\n Π-level $ λ tq →\n Π-level $ λ tr →\n Π-level $ λ ts →\n P-level ta tb tc td te tp tq tr ts\n core' : ∀ {a} {b} {c} {d} {e} p q r s → P [ a ] [ b ] [ c ] [ d ] [ e ] [ p ] [ q ] [ r ] [ s ]\n core' idp idp r s = =ₛ-in idp\n core : ∀ ta tb tc td te → Q ta tb tc td te\n core ta tb tc td te =\n Trunc-elim {P = λ ta → Q ta tb tc td te} {{λ ta → Q-level ta tb tc td te}} (λ a →\n Trunc-elim {P = λ tb → Q [ a ] tb tc td te} {{λ tb → Q-level [ a ] tb tc td te}} (λ b →\n Trunc-elim {P = λ tc → Q [ a ] [ b ] tc td te} {{λ tc → Q-level [ a ] [ b ] tc td te}} (λ c →\n Trunc-elim {P = λ td → Q [ a ] [ b ] [ c ] td te} {{λ td → Q-level [ a ] [ b ] [ c ] td te}} (λ d →\n Trunc-elim {P = λ te → Q [ a ] [ b ] [ c ] [ d ] te} {{λ te → Q-level [ a ] [ b ] [ c ] [ d ] te}} (λ e →\n let R = P [ a ] [ b ] [ c ] [ d ] [ e ]\n R-level = P-level [ a ] [ b ] [ c ] [ d ] [ e ]\n in λ tp tq tr ts →\n Trunc-elim {P = λ tp → R tp tq tr ts} {{λ tp → R-level tp tq tr ts }} (λ p →\n Trunc-elim {P = λ tq → R [ p ] tq tr ts} {{λ tq → R-level [ p ] tq tr ts}} (λ q →\n Trunc-elim {P = λ tr → R [ p ] [ q ] tr ts} {{λ tr → R-level [ p ] [ q ] tr ts}} (λ r →\n Trunc-elim {P = λ ts → R [ p ] [ q ] [ r ] ts} {{λ ts → R-level [ p ] [ q ] [ r ] ts}} (λ s →\n core' p q r s\n ) ts\n ) tr\n ) tq\n ) tp\n ) te\n ) td\n ) tc\n ) tb\n ) ta\n\n –>-=ₜ-equiv-pres-∙ : {ta tb tc : Trunc (S n) A}\n (p : ta == tb) (q : tb == tc)\n → –> (=ₜ-equiv ta tc) (p ∙ q)\n ==\n _∙ₜ_ {ta = ta} (–> (=ₜ-equiv ta tb) p) (–> (=ₜ-equiv tb tc) q)\n –>-=ₜ-equiv-pres-∙ {ta = ta} idp idp =\n Trunc-elim\n {P = λ ta → –> (=ₜ-equiv ta ta) idp\n == _∙ₜ_ {ta = ta} (–> (=ₜ-equiv ta ta) idp)\n (–> (=ₜ-equiv ta ta) idp)}\n {{λ ta → raise-level _ $ =-preserves-level $ =ₜ-level ta ta}}\n (λ a → idp)\n ta\n\n !ₜ-=ₜ-refl : ∀ (ta : Trunc (S n) A)\n → !ₜ {ta = ta} (=ₜ-refl ta) == =ₜ-refl ta\n !ₜ-=ₜ-refl =\n Trunc-elim\n {P = λ ta → !ₜ {ta = ta} (=ₜ-refl ta) == =ₜ-refl ta}\n {{λ ta → raise-level _ $ =-preserves-level $ =ₜ-level ta ta}}\n (λ a → idp)\n\n –>-=ₜ-equiv-pres-! : {ta tb : Trunc (S n) A}\n (p : ta == tb)\n → –> (=ₜ-equiv tb ta) (! p) == !ₜ {ta = ta} (–> (=ₜ-equiv ta tb) p)\n –>-=ₜ-equiv-pres-! {ta = ta} p@idp = ! (!ₜ-=ₜ-refl ta)\n\n abstract\n –>-=ₜ-equiv-pres-∙-coh : {ta tb tc td : Trunc (S n) A}\n (p : ta == tb) (q : tb == tc) (r : tc == td)\n → –>-=ₜ-equiv-pres-∙ (p ∙ q) r ◃∙\n ap (λ u → _∙ₜ_ {ta = ta} u (–> (=ₜ-equiv tc td) r)) (–>-=ₜ-equiv-pres-∙ p q) ◃∙\n ∙ₜ-assoc {ta = ta} (–> (=ₜ-equiv ta tb) p) (–> (=ₜ-equiv tb tc) q) (–> (=ₜ-equiv tc td) r) ◃∎\n =ₛ\n ap (–> (=ₜ-equiv ta td)) (∙-assoc p q r) ◃∙\n –>-=ₜ-equiv-pres-∙ p (q ∙ r) ◃∙\n ap (_∙ₜ_ {ta = ta} (–> (=ₜ-equiv ta tb) p)) (–>-=ₜ-equiv-pres-∙ q r) ◃∎\n –>-=ₜ-equiv-pres-∙-coh {ta = ta} idp idp idp =\n Trunc-elim\n {P = λ ta → P ta ta ta ta idp idp idp}\n {{λ ta → =ₛ-level $ raise-level (S (S n)) $ raise-level (S n) $ raise-level n $ =ₜ-level ta ta}}\n (λ a → =ₛ-in idp)\n ta\n where\n P : (ta tb tc td : Trunc (S n) A) (p : ta == tb) (q : tb == tc) (r : tc == td) → Type i\n P ta tb tc td p q r =\n –>-=ₜ-equiv-pres-∙ (p ∙ q) r ◃∙\n ap (λ u → _∙ₜ_ {ta = ta} u (–> (=ₜ-equiv tc td) r)) (–>-=ₜ-equiv-pres-∙ p q) ◃∙\n ∙ₜ-assoc {ta = ta} (–> (=ₜ-equiv ta tb) p) (–> (=ₜ-equiv tb tc) q) (–> (=ₜ-equiv tc td) r) ◃∎\n =ₛ\n ap (–> (=ₜ-equiv ta td)) (∙-assoc p q r) ◃∙\n –>-=ₜ-equiv-pres-∙ p (q ∙ r) ◃∙\n ap (_∙ₜ_ {ta = ta} (–> (=ₜ-equiv ta tb) p)) (–>-=ₜ-equiv-pres-∙ q r) ◃∎\n\n{- naturality of =ₜ-equiv -}\n\nmodule _ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} (f : A → B) where\n =ₜ-fmap : ∀ (a₀ a₁ : Trunc (S n) A)\n → a₀ =ₜ a₁ → Trunc-fmap f a₀ =ₜ Trunc-fmap f a₁\n =ₜ-fmap = Trunc-elim\n {P = λ a₀ → ∀ a₁ → a₀ =ₜ a₁ → Trunc-fmap f a₀ =ₜ Trunc-fmap f a₁}\n {{λ a₀ → Π-level λ a₁ → Π-level λ _ → raise-level _ $ =ₜ-level (Trunc-fmap f a₀) (Trunc-fmap f a₁)}}\n (λ a₀ → Trunc-elim\n {P = λ a₁ → [ a₀ ] =ₜ a₁ → [ f a₀ ] =ₜ Trunc-fmap f a₁}\n {{λ a₁ → Π-level λ _ → raise-level _ $ =ₜ-level [ f a₀ ] (Trunc-fmap f a₁)}}\n (λ a₁ → Trunc-fmap (ap f)))\n\nmodule _ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} (f : A → B) where\n =ₜ-equiv-nat : ∀ (a₀ a₁ : Trunc (S n) A) (p : a₀ == a₁)\n → –> (=ₜ-equiv (Trunc-fmap f a₀) (Trunc-fmap f a₁)) (ap (Trunc-fmap f) p)\n == =ₜ-fmap f a₀ a₁ (–> (=ₜ-equiv a₀ a₁) p)\n =ₜ-equiv-nat a₀ .a₀ idp =\n Trunc-elim\n {P = λ a\n → –> (=ₜ-equiv (Trunc-fmap f a) (Trunc-fmap f a)) idp\n == =ₜ-fmap f a a (–> (=ₜ-equiv a a) idp)}\n {{λ a → raise-level _ $ =-preserves-level $ =ₜ-level (Trunc-fmap f a) (Trunc-fmap f a)}}\n (λ _ → idp)\n a₀\n\n{- Truncation preserves equivalences - more convenient than univalence+ap\n - when we need to know the forward or backward function explicitly -}\nmodule _ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} where\n\n Trunc-isemap : {f : A → B} → is-equiv f → is-equiv (Trunc-fmap {n = n} f)\n Trunc-isemap {f-orig} ie = is-eq f g f-g g-f where\n f = Trunc-fmap f-orig\n g = Trunc-fmap (is-equiv.g ie)\n\n f-g : ∀ tb → f (g tb) == tb\n f-g = Trunc-elim (ap [_] ∘ is-equiv.f-g ie)\n\n g-f : ∀ ta → g (f ta) == ta\n g-f = Trunc-elim (ap [_] ∘ is-equiv.g-f ie)\n\n Trunc-emap : A ≃ B → Trunc n A ≃ Trunc n B\n Trunc-emap (f , f-ie) = Trunc-fmap f , Trunc-isemap f-ie\n\nTrunc-csemap : ∀ {i₀ i₁ j₀ j₁} {n : ℕ₋₂}\n {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}\n {f : A₀ → B₀} {g : A₁ → B₁} {hA : A₀ → A₁} {hB : B₀ → B₁}\n → CommSquareEquiv f g hA hB\n → CommSquareEquiv (Trunc-fmap {n = n} f) (Trunc-fmap g) (Trunc-fmap hA) (Trunc-fmap hB)\nTrunc-csemap (cs , hA-ise , hB-ise) = Trunc-csmap cs , Trunc-isemap hA-ise , Trunc-isemap hB-ise\n\ntransport-Trunc' : ∀ {i j} {A : Type i} {n : ℕ₋₂} (P : A → Type j)\n {x y : A} (p : x == y) (b : P x)\n → transport (Trunc n ∘ P) p [ b ] == [ transport P p b ]\ntransport-Trunc' _ idp _ = idp\n\nTrunc-fuse : ∀ {i} (A : Type i) (m n : ℕ₋₂)\n → Trunc m (Trunc n A) ≃ Trunc (minT m n) A\nTrunc-fuse A m n = equiv\n (Trunc-rec {{raise-level-≤T (minT≤l m n) Trunc-level}}\n (Trunc-rec {{raise-level-≤T (minT≤r m n) Trunc-level}}\n [_]))\n (Trunc-rec ([_] ∘ [_]))\n (Trunc-elim (λ _ → idp))\n (Trunc-elim (Trunc-elim\n {{λ _ → =-preserves-level (Trunc-preserves-level _ Trunc-level)}}\n (λ _ → idp)))\n where\n instance\n l : has-level (minT m n) (Trunc m (Trunc n A))\n l with (minT-out m n)\n l | inl p = transport (λ k → has-level k (Trunc m (Trunc n A)))\n (! p) Trunc-level\n l | inr q = Trunc-preserves-level _\n (transport (λ k → has-level k (Trunc n A))\n (! q) Trunc-level)\n\nTrunc-fuse-≤ : ∀ {i} (A : Type i) {m n : ℕ₋₂} (m≤n : m ≤T n)\n → Trunc m (Trunc n A) ≃ Trunc m A\nTrunc-fuse-≤ A m≤n = equiv\n (Trunc-rec (Trunc-rec {{raise-level-≤T m≤n Trunc-level}}\n [_]))\n (Trunc-rec ([_] ∘ [_]))\n (Trunc-elim (λ _ → idp))\n (Trunc-elim (Trunc-elim\n {{λ _ → =-preserves-level (Trunc-preserves-level _ Trunc-level)}}\n (λ _ → idp)))\n\n{- Truncating a binary product is equivalent to truncating its components -}\nTrunc-×-econv : ∀ {i} {j} (n : ℕ₋₂) (A : Type i) (B : Type j)\n → Trunc n (A × B) ≃ Trunc n A × Trunc n B\nTrunc-×-econv n A B = equiv f g f-g g-f\n where\n f : Trunc n (A × B) → Trunc n A × Trunc n B\n f = Trunc-rec (λ {(a , b) → [ a ] , [ b ]})\n\n g : Trunc n A × Trunc n B → Trunc n (A × B)\n g (ta , tb) = Trunc-rec (λ a → Trunc-rec (λ b → [ a , b ]) tb) ta\n\n f-g : ∀ p → f (g p) == p\n f-g (ta , tb) = Trunc-elim\n {P = λ ta → f (g (ta , tb)) == (ta , tb)}\n (λ a → Trunc-elim\n {P = λ tb → f (g ([ a ] , tb)) == ([ a ] , tb)}\n (λ b → idp)\n tb)\n ta\n\n g-f : ∀ tab → g (f tab) == tab\n g-f = Trunc-elim\n {P = λ tab → g (f tab) == tab}\n (λ ab → idp)\n\nTrunc-×-conv : ∀ {i} {j} (n : ℕ₋₂) (A : Type i) (B : Type j)\n → Trunc n (A × B) == Trunc n A × Trunc n B\nTrunc-×-conv n A B = ua (Trunc-×-econv n A B)\n", "meta": {"hexsha": "1e7c1be664eaf0b53cc3021bfdb52d6a0d9fca69", "size": 25667, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/types/Truncation.agda", "max_stars_repo_name": "AntoineAllioux/HoTT-Agda", "max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "core/lib/types/Truncation.agda", "max_issues_repo_name": "AntoineAllioux/HoTT-Agda", "max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "core/lib/types/Truncation.agda", "max_forks_repo_name": "AntoineAllioux/HoTT-Agda", "max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 38.6551204819, "max_line_length": 121, "alphanum_fraction": 0.460669342, "num_tokens": 11666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.5621765008857982, "lm_q1q2_score": 0.38181830457859056}} {"text": "\nmodule Tactic.Nat.Subtract.Auto where\n\nopen import Prelude\nopen import Builtin.Reflection\nopen import Tactic.Reflection.Quote\nopen import Tactic.Reflection.Meta\n\nopen import Tactic.Nat.Reflect\nopen import Tactic.Nat.NF\nopen import Tactic.Nat.Auto\nopen import Tactic.Nat.Simpl.Lemmas\nopen import Tactic.Nat.Subtract.Exp\nopen import Tactic.Nat.Subtract.Reflect\nopen import Tactic.Nat.Subtract.Lemmas\nopen import Tactic.Nat.Less.Lemmas\n\nautosub-proof : ∀ eqn ρ → Maybe (⟦ eqn ⟧eqn ρ)\nautosub-proof (e₁ :≡ e₂) ρ with normSub e₁ == normSub e₂\nautosub-proof (e₁ :≡ e₂) ρ | no _ = nothing\nautosub-proof (e₁ :≡ e₂) ρ | yes eq = just (liftNFSubEq e₁ e₂ ρ (cong (λ n → ⟦ n ⟧sn ρ) eq))\nautosub-proof (e₁ :< e₂) ρ with cancel (normSub e₁) (normSub e₂) | simplifySubLess e₁ e₂ ρ\nautosub-proof (e₁ :< e₂) ρ | [] , (suc n , []) ∷ nf | simp =\n let sk : SubNF\n sk = (suc n , []) ∷ nf\n k = ( n , []) ∷ nf in\n just $ simp $ LessNat.diff (⟦ k ⟧sns ρ) $\n ns-sound sk (atomEnvS ρ) ⟨≡⟩\n auto ⟨≡⟩ʳ (λ z → suc (z + 0)) $≡ lem-eval-sns-nS k ρ\nautosub-proof (e₁ :< e₂) ρ | _ , _ | simp = nothing\n\nautosub-tactic : Type → TC Term\nautosub-tactic t = do\n ensureNoMetas t\n just (eqn , Γ) ← termToSubEqn t\n where nothing → typeError $ strErr \"Invalid goal:\" ∷ termErr t ∷ []\n pure $\n getProof (quote cantProve) t $\n def (quote autosub-proof)\n ( vArg (` eqn)\n ∷ vArg (quotedEnv Γ)\n ∷ [] )\n", "meta": {"hexsha": "c245aa48024a4a5cedc379b377d1592a6507edbb", "size": 1423, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Tactic/Nat/Subtract/Auto.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/Nat/Subtract/Auto.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/Nat/Subtract/Auto.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": 33.0930232558, "max_line_length": 92, "alphanum_fraction": 0.6416022488, "num_tokens": 535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6791786861878392, "lm_q2_score": 0.5621765008857982, "lm_q1q2_score": 0.381818297277293}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule PiEquiv where\n\nopen import Data.Empty\nopen import Data.Unit\nopen import Data.Sum using (_⊎_; inj₁; inj₂)\nopen import Data.Product using (_×_; Σ; _,_; proj₁; proj₂)\nopen import Relation.Binary.PropositionalEquality\n using (_≡_; refl; sym; trans; cong; cong₂)\nopen import Function using (_∘_; id)\n\nopen import Equiv\nopen import EquivEquiv\nopen _≋_\nopen import TypeEquiv as TE\nopen import TypeEquivEquiv\n-- open import TypeEquivCat\nopen import PiU\nopen import PiLevel0\nopen import PiLevel1\n\nopen import Data.Sum.Properties2\nopen import Data.SumProd.Properties\n\n------------------------------------------------------------------------------\n-- A combinator t₁ ⟷ t₂ denotes an equivalence to types\n-- note how we don't have to look at the types at all.\n\n⟦_⟧ : U → Set\n⟦ ZERO ⟧ = ⊥\n⟦ ONE ⟧ = ⊤\n⟦ PLUS t₁ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧\n⟦ TIMES t₁ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧\n\neval : {t₁ t₂ : U} → (t₁ ⟷ t₂) → ⟦ t₁ ⟧ → ⟦ t₂ ⟧\neval unite₊l (inj₁ ())\neval unite₊l (inj₂ v) = v\neval uniti₊l v = inj₂ v\neval unite₊r (inj₁ x) = x\neval unite₊r (inj₂ ())\neval uniti₊r v = inj₁ v\neval swap₊ (inj₁ v) = inj₂ v\neval swap₊ (inj₂ v) = inj₁ v\neval assocl₊ (inj₁ v) = inj₁ (inj₁ v)\neval assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v)\neval assocl₊ (inj₂ (inj₂ v)) = inj₂ v\neval assocr₊ (inj₁ (inj₁ v)) = inj₁ v\neval assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v)\neval assocr₊ (inj₂ v) = inj₂ (inj₂ v)\neval unite⋆l (tt , v) = v\neval uniti⋆l v = (tt , v)\neval unite⋆r (v , tt) = v\neval uniti⋆r v = v , tt\neval swap⋆ (v₁ , v₂) = (v₂ , v₁)\neval assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃)\neval assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃))\neval absorbr (x , _) = x\neval absorbl (_ , y) = y\neval factorzl ()\neval factorzr ()\neval dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃)\neval dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃)\neval factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃)\neval factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃)\neval distl (v , inj₁ x) = inj₁ (v , x)\neval distl (v , inj₂ y) = inj₂ (v , y)\neval factorl (inj₁ (x , y)) = x , inj₁ y\neval factorl (inj₂ (x , y)) = x , inj₂ y\neval id⟷ v = v\neval (c₁ ◎ c₂) v = eval c₂ (eval c₁ v)\neval (c₁ ⊕ c₂) (inj₁ v) = inj₁ (eval c₁ v)\neval (c₁ ⊕ c₂) (inj₂ v) = inj₂ (eval c₂ v)\neval (c₁ ⊗ c₂) (v₁ , v₂) = (eval c₁ v₁ , eval c₂ v₂)\n\n-- useful to have the backwards eval too\n\nevalB : {t₁ t₂ : U} → (t₁ ⟷ t₂) → ⟦ t₂ ⟧ → ⟦ t₁ ⟧\nevalB unite₊l x = inj₂ x\nevalB uniti₊l (inj₁ ())\nevalB uniti₊l (inj₂ y) = y\nevalB unite₊r v = inj₁ v\nevalB uniti₊r (inj₁ x) = x\nevalB uniti₊r (inj₂ ())\nevalB swap₊ (inj₁ x) = inj₂ x\nevalB swap₊ (inj₂ y) = inj₁ y\nevalB assocl₊ (inj₁ (inj₁ x)) = inj₁ x\nevalB assocl₊ (inj₁ (inj₂ y)) = inj₂ (inj₁ y)\nevalB assocl₊ (inj₂ y) = inj₂ (inj₂ y)\nevalB assocr₊ (inj₁ x) = inj₁ (inj₁ x)\nevalB assocr₊ (inj₂ (inj₁ x)) = inj₁ (inj₂ x)\nevalB assocr₊ (inj₂ (inj₂ y)) = inj₂ y\nevalB unite⋆l x = tt , x\nevalB uniti⋆l (tt , x) = x\nevalB unite⋆r v = v , tt\nevalB uniti⋆r (v , tt) = v\nevalB swap⋆ (x , y) = y , x\nevalB assocl⋆ ((x , y) , z) = x , y , z\nevalB assocr⋆ (x , y , z) = (x , y) , z\nevalB absorbr ()\nevalB absorbl ()\nevalB factorzr (_ , x) = x\nevalB factorzl (x , _) = x\nevalB dist (inj₁ (x , y)) = inj₁ x , y\nevalB dist (inj₂ (x , y)) = inj₂ x , y\nevalB factor (inj₁ x , z) = inj₁ (x , z)\nevalB factor (inj₂ y , z) = inj₂ (y , z)\nevalB distl (inj₁ (x , y)) = x , inj₁ y\nevalB distl (inj₂ (x , y)) = x , inj₂ y\nevalB factorl (v , inj₁ x) = inj₁ (v , x)\nevalB factorl (v , inj₂ y) = inj₂ (v , y)\nevalB id⟷ x = x\nevalB (c₀ ◎ c₁) x = evalB c₀ (evalB c₁ x)\nevalB (c₀ ⊕ c₁) (inj₁ x) = inj₁ (evalB c₀ x)\nevalB (c₀ ⊕ c₁) (inj₂ y) = inj₂ (evalB c₁ y)\nevalB (c₀ ⊗ c₁) (x , y) = evalB c₀ x , evalB c₁ y\n\n-- should probably prove that these are inverses!\n-- to a certain extent, no need, because here's\n-- the right way to do it:\n\nc2equiv : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → ⟦ t₁ ⟧ ≃ ⟦ t₂ ⟧\nc2equiv unite₊l = TE.unite₊equiv\nc2equiv uniti₊l = TE.uniti₊equiv\nc2equiv unite₊r = TE.unite₊′equiv\nc2equiv uniti₊r = TE.uniti₊′equiv\nc2equiv swap₊ = TE.swap₊equiv\nc2equiv assocl₊ = TE.assocl₊equiv\nc2equiv assocr₊ = TE.assocr₊equiv\nc2equiv unite⋆l = TE.unite⋆equiv\nc2equiv uniti⋆l = TE.uniti⋆equiv\nc2equiv unite⋆r = TE.unite⋆′equiv\nc2equiv uniti⋆r = TE.uniti⋆′equiv\nc2equiv swap⋆ = TE.swap⋆equiv\nc2equiv assocl⋆ = TE.assocl⋆equiv\nc2equiv assocr⋆ = TE.assocr⋆equiv\nc2equiv absorbr = TE.distzequiv\nc2equiv absorbl = TE.distzrequiv\nc2equiv factorzr = TE.factorzrequiv\nc2equiv factorzl = TE.factorzequiv\nc2equiv dist = TE.distequiv\nc2equiv factor = TE.factorequiv\nc2equiv distl = TE.distlequiv\nc2equiv factorl = TE.factorlequiv\nc2equiv id⟷ = id≃\nc2equiv (c ◎ c₁) = c2equiv c₁ ● c2equiv c\nc2equiv (c ⊕ c₁) = (c2equiv c) ⊎≃ (c2equiv c₁)\nc2equiv (c ⊗ c₁) = (c2equiv c) ×≃ (c2equiv c₁)\n\n-- and these are 'coherent'\n-- first with evaluation:\n\nlemma0 : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → (v : ⟦ t₁ ⟧) →\n eval c v ≡ proj₁ (c2equiv c) v\nlemma0 unite₊l (inj₁ ())\nlemma0 unite₊l (inj₂ y) = refl\nlemma0 uniti₊l v = refl\nlemma0 unite₊r (inj₁ x) = refl\nlemma0 unite₊r (inj₂ ())\nlemma0 uniti₊r v = refl\nlemma0 PiLevel0.swap₊ (inj₁ x) = refl\nlemma0 PiLevel0.swap₊ (inj₂ y) = refl\nlemma0 PiLevel0.assocl₊ (inj₁ x) = refl\nlemma0 PiLevel0.assocl₊ (inj₂ (inj₁ x)) = refl\nlemma0 PiLevel0.assocl₊ (inj₂ (inj₂ y)) = refl\nlemma0 PiLevel0.assocr₊ (inj₁ (inj₁ x)) = refl\nlemma0 PiLevel0.assocr₊ (inj₁ (inj₂ y)) = refl\nlemma0 PiLevel0.assocr₊ (inj₂ y) = refl\nlemma0 unite⋆l v = refl -- yay for η !\nlemma0 uniti⋆l v = refl\nlemma0 unite⋆r v = refl\nlemma0 uniti⋆r v = refl\nlemma0 PiLevel0.swap⋆ v = refl\nlemma0 PiLevel0.assocl⋆ v = refl\nlemma0 PiLevel0.assocr⋆ v = refl\nlemma0 absorbr v = refl\nlemma0 absorbl v = refl\nlemma0 factorzr ()\nlemma0 factorzl ()\nlemma0 PiLevel0.dist (inj₁ x , proj₂) = refl\nlemma0 PiLevel0.dist (inj₂ y , proj₂) = refl\nlemma0 PiLevel0.factor (inj₁ x) = refl\nlemma0 PiLevel0.factor (inj₂ y) = refl\nlemma0 PiLevel0.distl (proj₁ , inj₁ x) = refl\nlemma0 PiLevel0.distl (proj₁ , inj₂ y) = refl\nlemma0 PiLevel0.factorl (inj₁ x) = refl\nlemma0 PiLevel0.factorl (inj₂ y) = refl\nlemma0 id⟷ v = refl\nlemma0 (c ◎ c₁) v =\n trans (cong (eval c₁) (lemma0 c v)) (\n trans (lemma0 c₁ (proj₁ (c2equiv c) v))\n (sym (β₁ v)))\nlemma0 (c ⊕ c₁) (inj₁ x) =\n trans (cong inj₁ (lemma0 c x)) (sym (β⊎₁ (inj₁ x)))\nlemma0 (c ⊕ c₁) (inj₂ y) =\n trans (cong inj₂ (lemma0 c₁ y)) (sym (β⊎₁ (inj₂ y)))\nlemma0 (c ⊗ c₁) (x , y) =\n trans (cong₂ _,_ (lemma0 c x) (lemma0 c₁ y)) (sym (β×₁ (x , y)))\n\nlemma1 : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → (v : ⟦ t₂ ⟧) →\n evalB c v ≡ proj₁ (sym≃ (c2equiv c)) v\nlemma1 PiLevel0.unite₊l v = refl\nlemma1 PiLevel0.uniti₊l (inj₁ ())\nlemma1 PiLevel0.uniti₊l (inj₂ y) = refl\nlemma1 PiLevel0.unite₊r v = refl\nlemma1 uniti₊r (inj₁ x) = refl\nlemma1 uniti₊r (inj₂ ())\nlemma1 PiLevel0.swap₊ (inj₁ x) = refl\nlemma1 PiLevel0.swap₊ (inj₂ y) = refl\nlemma1 PiLevel0.assocl₊ (inj₁ (inj₁ x)) = refl\nlemma1 PiLevel0.assocl₊ (inj₁ (inj₂ y)) = refl\nlemma1 PiLevel0.assocl₊ (inj₂ y) = refl\nlemma1 PiLevel0.assocr₊ (inj₁ x) = refl\nlemma1 PiLevel0.assocr₊ (inj₂ (inj₁ x)) = refl\nlemma1 PiLevel0.assocr₊ (inj₂ (inj₂ y)) = refl\nlemma1 PiLevel0.unite⋆l v = refl\nlemma1 PiLevel0.uniti⋆l (tt , x) = refl\nlemma1 PiLevel0.unite⋆r v = refl\nlemma1 uniti⋆r (x , tt) = refl\nlemma1 PiLevel0.swap⋆ (x , y) = refl\nlemma1 PiLevel0.assocl⋆ ((x , y) , z) = refl\nlemma1 PiLevel0.assocr⋆ (x , y , z) = refl\nlemma1 absorbr ()\nlemma1 absorbl ()\nlemma1 PiLevel0.factorzr (_ , ())\nlemma1 factorzl (() , v)\nlemma1 PiLevel0.dist (inj₁ (proj₁ , proj₂)) = refl\nlemma1 PiLevel0.dist (inj₂ (proj₁ , proj₂)) = refl\nlemma1 PiLevel0.factor (inj₁ x , proj₂) = refl\nlemma1 PiLevel0.factor (inj₂ y , proj₂) = refl\nlemma1 PiLevel0.distl (inj₁ (proj₁ , proj₂)) = refl\nlemma1 PiLevel0.distl (inj₂ (proj₁ , proj₂)) = refl\nlemma1 PiLevel0.factorl (v , inj₁ x) = refl\nlemma1 PiLevel0.factorl (v , inj₂ y) = refl\nlemma1 id⟷ v = refl\nlemma1 (c₀ ◎ c₁) v = trans (\n trans (cong (evalB c₀) (lemma1 c₁ v)) (lemma1 c₀ (gg (c2equiv c₁) v)) )\n (sym (β₂ v))\nlemma1 (c₀ ⊕ c₁) (inj₁ x) = trans (cong inj₁ (lemma1 c₀ x)) (sym (β⊎₂ (inj₁ x))) -- cong inj₁ (lemma1 c₀ x)\nlemma1 (c₀ ⊕ c₁) (inj₂ y) = trans (cong inj₂ (lemma1 c₁ y)) (sym (β⊎₂ (inj₂ y)))\nlemma1 (c₀ ⊗ c₁) (x , y) = trans (cong₂ _,_ (lemma1 c₀ x) (lemma1 c₁ y)) (sym (β×₂ (x , y)))\n\n-- and with reverse\n!≡sym≃ : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) →\n c2equiv (! c) ≋ sym≃ (c2equiv c)\n!≡sym≃ unite₊l = id≋\n!≡sym≃ uniti₊l = id≋\n!≡sym≃ unite₊r = id≋\n!≡sym≃ uniti₊r = id≋\n!≡sym≃ PiLevel0.swap₊ = id≋\n!≡sym≃ PiLevel0.assocl₊ = id≋\n!≡sym≃ PiLevel0.assocr₊ = id≋\n!≡sym≃ unite⋆l = id≋\n!≡sym≃ uniti⋆l = id≋\n!≡sym≃ unite⋆r = id≋\n!≡sym≃ uniti⋆r = id≋\n!≡sym≃ PiLevel0.swap⋆ = id≋\n!≡sym≃ PiLevel0.assocl⋆ = id≋\n!≡sym≃ PiLevel0.assocr⋆ = id≋\n!≡sym≃ absorbr = id≋\n!≡sym≃ absorbl = id≋\n!≡sym≃ PiLevel0.factorzr = id≋\n!≡sym≃ factorzl = id≋\n!≡sym≃ PiLevel0.dist = id≋\n!≡sym≃ PiLevel0.factor = id≋\n!≡sym≃ PiLevel0.distl = id≋\n!≡sym≃ PiLevel0.factorl = id≋\n!≡sym≃ id⟷ = id≋\n!≡sym≃ (c ◎ c₁) = trans≋ (EquivEquiv._◎_ (!≡sym≃ c) (!≡sym≃ c₁)) (sym≋ sym≃●)\n!≡sym≃ (c ⊕ c₁) = trans≋ ((!≡sym≃ c) ⊎≋ (!≡sym≃ c₁)) (sym≋ sym≃-distrib⊎)\n!≡sym≃ (c ⊗ c₁) = trans≋ ((!≡sym≃ c) ×≋ (!≡sym≃ c₁)) (sym≋ sym≃-distrib×)\n\nleft-inv : {t₁ t₂ : U} (c : t₁ ⟷ t₂) →\n (c2equiv (! c) ● c2equiv c) ≋ id≃\nleft-inv c =\n let p = c2equiv c in\n trans≋ (!≡sym≃ c EquivEquiv.◎ id≋) (linv≋ p)\n\nright-inv : {t₁ t₂ : U} (c : t₁ ⟷ t₂) →\n (c2equiv c ● c2equiv (! c)) ≋ id≃\nright-inv c =\n let p = c2equiv c in\n trans≋ (id≋ EquivEquiv.◎ (!≡sym≃ c)) (rinv≋ p)\n\n----------------------------------------------------------\n\ncc2equiv : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} (ce : c₁ ⇔ c₂) →\n c2equiv c₁ ≋ c2equiv c₂\ncc2equiv assoc◎l = ●-assoc\ncc2equiv assoc◎r = ●-assocl\ncc2equiv assocl⊕l = assocl₊-nat\ncc2equiv assocl⊕r = sym≋ assocl₊-nat\ncc2equiv assocl⊗l = assocl⋆-nat\ncc2equiv assocl⊗r = sym≋ assocl⋆-nat\ncc2equiv assocr⊕r = assocr₊-nat\ncc2equiv assocr⊗l = sym≋ assocr⋆-nat\ncc2equiv assocr⊗r = assocr⋆-nat\ncc2equiv assocr⊕l = sym≋ assocr₊-nat\ncc2equiv dist⇔l = dist-nat\ncc2equiv dist⇔r = sym≋ dist-nat\ncc2equiv distl⇔l = distl-nat\ncc2equiv distl⇔r = sym≋ distl-nat\ncc2equiv factor⇔l = factor-nat\ncc2equiv factor⇔r = sym≋ factor-nat\ncc2equiv factorl⇔l = factorl-nat\ncc2equiv factorl⇔r = sym≋ factorl-nat\ncc2equiv idl◎l = rid≋\ncc2equiv idl◎r = sym≋ rid≋\ncc2equiv idr◎l = lid≋\ncc2equiv idr◎r = sym≋ lid≋\ncc2equiv (linv◎l {c = c}) = left-inv c\ncc2equiv (linv◎r {c = c}) = sym≋ (left-inv c)\ncc2equiv (rinv◎l {c = c}) = right-inv c\ncc2equiv (rinv◎r {c = c}) = sym≋ (right-inv c)\ncc2equiv (unite₊l⇔l {c₁ = c₁} {c₂}) = sym≋ (unite₊-nat {f = c2equiv c₂})\ncc2equiv unite₊l⇔r = unite₊-nat\ncc2equiv uniti₊l⇔l = sym≋ uniti₊-nat\ncc2equiv uniti₊l⇔r = uniti₊-nat\ncc2equiv unite₊r⇔l = sym≋ unite₊′-nat\ncc2equiv unite₊r⇔r = unite₊′-nat\ncc2equiv uniti₊r⇔l = sym≋ uniti₊′-nat\ncc2equiv uniti₊r⇔r = uniti₊′-nat\ncc2equiv swapl₊⇔ = sym≋ swap₊-nat\ncc2equiv swapr₊⇔ = swap₊-nat\ncc2equiv unitel⋆⇔l = sym≋ unite⋆-nat\ncc2equiv uniter⋆⇔l = unite⋆-nat\ncc2equiv unitil⋆⇔l = sym≋ uniti⋆-nat\ncc2equiv unitir⋆⇔l = uniti⋆-nat\ncc2equiv unitel⋆⇔r = sym≋ unite⋆′-nat\ncc2equiv uniter⋆⇔r = unite⋆′-nat\ncc2equiv unitil⋆⇔r = sym≋ uniti⋆′-nat\ncc2equiv unitir⋆⇔r = uniti⋆′-nat\ncc2equiv swapl⋆⇔ = sym≋ swap⋆-nat\ncc2equiv swapr⋆⇔ = swap⋆-nat\ncc2equiv id⇔ = id≋\ncc2equiv (trans⇔ ce ce₁) = trans≋ (cc2equiv ce) (cc2equiv ce₁)\ncc2equiv (ce ⊡ ce₁) = (cc2equiv ce₁) EquivEquiv.◎ (cc2equiv ce)\ncc2equiv (resp⊕⇔ ce ce₁) = cc2equiv ce ⊎≋ cc2equiv ce₁\ncc2equiv (resp⊗⇔ ce ce₁) = cc2equiv ce ×≋ cc2equiv ce₁\ncc2equiv id⟷⊕id⟷⇔ = [id,id]≋id\ncc2equiv split⊕-id⟷ = sym≋ [id,id]≋id\ncc2equiv hom⊕◎⇔ = ⊎●≋●⊎\ncc2equiv hom◎⊕⇔ = sym≋ ⊎●≋●⊎\ncc2equiv id⟷⊗id⟷⇔ = id×id≋id\ncc2equiv split⊗-id⟷ = sym≋ id×id≋id\ncc2equiv hom⊗◎⇔ = ×●≋●×\ncc2equiv hom◎⊗⇔ = sym≋ ×●≋●×\ncc2equiv triangle⊕l = unite-assocr₊-coh\ncc2equiv triangle⊕r = sym≋ unite-assocr₊-coh\ncc2equiv triangle⊗l = unite-assocr⋆-coh\ncc2equiv triangle⊗r = sym≋ unite-assocr⋆-coh\ncc2equiv unite₊l-coh-l = unite₊l-coh\ncc2equiv unite₊l-coh-r = sym≋ unite₊l-coh\ncc2equiv unite⋆l-coh-l = unite⋆l-coh\ncc2equiv unite⋆l-coh-r = sym≋ unite⋆l-coh\ncc2equiv pentagon⊕l = assocr₊-coh\ncc2equiv pentagon⊕r = sym≋ assocr₊-coh\ncc2equiv pentagon⊗l = assocr⋆-coh\ncc2equiv pentagon⊗r = sym≋ assocr⋆-coh\ncc2equiv hexagonr⊕l = assocr₊-swap₊-coh\ncc2equiv hexagonr⊕r = sym≋ assocr₊-swap₊-coh\ncc2equiv hexagonl⊕l = assocl₊-swap₊-coh\ncc2equiv hexagonl⊕r = sym≋ assocl₊-swap₊-coh\ncc2equiv hexagonr⊗l = assocr⋆-swap⋆-coh\ncc2equiv hexagonr⊗r = sym≋ assocr⋆-swap⋆-coh\ncc2equiv hexagonl⊗l = assocl⋆-swap⋆-coh\ncc2equiv hexagonl⊗r = sym≋ assocl⋆-swap⋆-coh\ncc2equiv absorbl⇔l = distzr-nat\ncc2equiv absorbl⇔r = sym≋ distzr-nat\ncc2equiv absorbr⇔l = distz-nat\ncc2equiv absorbr⇔r = sym≋ distz-nat\ncc2equiv factorzl⇔l = factorz-nat\ncc2equiv factorzl⇔r = sym≋ factorz-nat\ncc2equiv factorzr⇔l = factorzr-nat\ncc2equiv factorzr⇔r = sym≋ factorzr-nat\ncc2equiv swap₊distl⇔l = A×[B⊎C]≃[A×C]⊎[A×B]\ncc2equiv swap₊distl⇔r = sym≋ A×[B⊎C]≃[A×C]⊎[A×B]\ncc2equiv dist-swap⋆⇔l = [A⊎B]×C≃[C×A]⊎[C×B]\ncc2equiv dist-swap⋆⇔r = sym≋ [A⊎B]×C≃[C×A]⊎[C×B]\ncc2equiv assocl₊-dist-dist⇔l = [A⊎B⊎C]×D≃[A×D⊎B×D]⊎C×D\ncc2equiv assocl₊-dist-dist⇔r = sym≋ [A⊎B⊎C]×D≃[A×D⊎B×D]⊎C×D\ncc2equiv assocl⋆-distl⇔l = A×B×[C⊎D]≃[A×B]×C⊎[A×B]×D\ncc2equiv assocl⋆-distl⇔r = sym≋ A×B×[C⊎D]≃[A×B]×C⊎[A×B]×D\ncc2equiv absorbr0-absorbl0⇔ = 0×0≃0\ncc2equiv absorbl0-absorbr0⇔ = sym≋ 0×0≃0\ncc2equiv absorbr⇔distl-absorb-unite = 0×[A⊎B]≃0\ncc2equiv distl-absorb-unite⇔absorbr = sym≋ 0×[A⊎B]≃0\ncc2equiv unite⋆r0-absorbr1⇔ = 0×1≃0\ncc2equiv absorbr1-unite⋆r-⇔ = sym≋ 0×1≃0\ncc2equiv absorbl≡swap⋆◎absorbr = A×0≃0\ncc2equiv swap⋆◎absorbr≡absorbl = sym≋ A×0≃0\ncc2equiv absorbr⇔[assocl⋆◎[absorbr⊗id⟷]]◎absorbr = 0×A×B≃0\ncc2equiv [assocl⋆◎[absorbr⊗id⟷]]◎absorbr⇔absorbr = sym≋ 0×A×B≃0\ncc2equiv [id⟷⊗absorbr]◎absorbl⇔assocl⋆◎[absorbl⊗id⟷]◎absorbr = A×0×B≃0\ncc2equiv assocl⋆◎[absorbl⊗id⟷]◎absorbr⇔[id⟷⊗absorbr]◎absorbl = sym≋ A×0×B≃0\ncc2equiv elim⊥-A[0⊕B]⇔l = A×[0+B]≃A×B\ncc2equiv elim⊥-A[0⊕B]⇔r = sym≋ A×[0+B]≃A×B\ncc2equiv elim⊥-1[A⊕B]⇔l = 1×[A⊎B]≃A⊎B\ncc2equiv elim⊥-1[A⊕B]⇔r = sym≋ 1×[A⊎B]≃A⊎B\ncc2equiv fully-distribute⇔l = [A⊎B]×[C⊎D]≃[[A×C⊎B×C]⊎A×D]⊎B×D\ncc2equiv fully-distribute⇔r = sym≋ [A⊎B]×[C⊎D]≃[[A×C⊎B×C]⊎A×D]⊎B×D\n\n--\n-- These programs really are equivalent. Here's two ways to see that:\n\n-- 1. they give the same results as programs:\n\n≋⇒≡ : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} (ce : c₁ ⇔ c₂) →\n eval c₁ ∼ eval c₂\n≋⇒≡ {c₁ = c₁} {c₂} ce =\n trans∼ (lemma0 c₁) (\n trans∼ (_≋_.f≡ (cc2equiv ce))\n (sym∼ (lemma0 c₂)))\n\n-- 2. in fact, you can run one forward, then the other\n-- backward, and that's the identity\n\nping-pong : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} (ce : c₁ ⇔ c₂) →\n evalB c₂ ∘ eval c₁ ∼ id\nping-pong {c₁ = c₁} {c₂} ce =\n trans∼ (cong₂∘ (lemma1 c₂) (lemma0 c₁)) (\n trans∼ (cong∘r (proj₁ (c2equiv c₁)) (_≋_.f≡ (flip≋ (cc2equiv (2! ce))) )) (\n trans∼(sym∼ β₁)\n (_≋_.f≡ (linv≋ (c2equiv c₁)))))\n", "meta": {"hexsha": "3225b1e52016e3c315ea5b29935a4450e70e9687", "size": 14710, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Univalence/PiEquiv.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "Univalence/PiEquiv.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "Univalence/PiEquiv.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 34.6117647059, "max_line_length": 107, "alphanum_fraction": 0.6348742352, "num_tokens": 7690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.38181070346632523}} {"text": "open import Nat\nopen import Prelude\nopen import Hazelnut-core\n\nmodule Hazelnut-sensible where\n -- theorem 1: action sensibility\n synthmovelem : {Γ : ·ctx} {e e' : ê} {t : τ̇} {δ : direction} →\n (e + move δ +>e e') →\n (Γ ⊢ e ◆e => t) →\n (Γ ⊢ e' ◆e => t)\n synthmovelem EMAscFirstChild d2 = d2\n synthmovelem EMAscParent1 d2 = d2\n synthmovelem EMAscParent2 d2 = d2\n synthmovelem EMAscNextSib d2 = d2\n synthmovelem EMAscPrevSib d2 = d2\n synthmovelem EMLamFirstChild d2 = d2\n synthmovelem EMLamParent d2 = d2\n synthmovelem EMPlusFirstChild d2 = d2\n synthmovelem EMPlusParent1 d2 = d2\n synthmovelem EMPlusParent2 d2 = d2\n synthmovelem EMPlusNextSib d2 = d2\n synthmovelem EMPlusPrevSib d2 = d2\n synthmovelem EMApFirstChild d2 = d2\n synthmovelem EMApParent1 d2 = d2\n synthmovelem EMApParent2 d2 = d2\n synthmovelem EMApNextSib d2 = d2\n synthmovelem EMApPrevSib d2 = d2\n synthmovelem EMFHoleFirstChild d2 = d2\n synthmovelem EMFHoleParent d2 = d2\n\n -- movements preserve analytic types up to erasure. this lemma seems\n -- silly because all it seems to do in each case is return the second\n -- derivation D. the pattern matching here, though, constrains what that\n -- derivation may be in each case, and is therefore actually\n -- non-trivial. it's just that most of the work is happening in the\n -- implicit arguments.\n anamovelem : {Γ : ·ctx} {δ : direction} {e e' : ê} {t : τ̇}\n (p : e + move δ +>e e') →\n (Γ ⊢ e ◆e <= t) →\n (Γ ⊢ e' ◆e <= t)\n anamovelem EMAscFirstChild d2 = d2\n anamovelem EMAscParent1 d2 = d2\n anamovelem EMAscParent2 d2 = d2\n anamovelem EMAscNextSib d2 = d2\n anamovelem EMAscPrevSib d2 = d2\n anamovelem EMLamFirstChild d2 = d2\n anamovelem EMLamParent d2 = d2\n anamovelem EMPlusFirstChild d2 = d2\n anamovelem EMPlusParent1 d2 = d2\n anamovelem EMPlusParent2 d2 = d2\n anamovelem EMPlusNextSib d2 = d2\n anamovelem EMPlusPrevSib d2 = d2\n anamovelem EMApFirstChild d2 = d2\n anamovelem EMApParent1 d2 = d2\n anamovelem EMApParent2 d2 = d2\n anamovelem EMApNextSib d2 = d2\n anamovelem EMApPrevSib d2 = d2\n anamovelem EMFHoleFirstChild d2 = d2\n anamovelem EMFHoleParent d2 = d2\n\n mutual\n -- if an action transforms an zexp in a synthetic posistion to another\n -- zexp, they have the same type up erasure of focus.\n actsense1 : {Γ : ·ctx} {e e' : ê} {t t' : τ̇} {α : action} →\n (Γ ⊢ e => t ~ α ~> e' => t') →\n (Γ ⊢ (e ◆e) => t) →\n Γ ⊢ (e' ◆e) => t'\n actsense1 (SAMove x) D2 = synthmovelem x D2\n actsense1 SADel D2 = SEHole\n actsense1 SAConAsc D2 = SAsc (ASubsume D2 TCRefl)\n actsense1 (SAConVar p) D2 = SVar p\n actsense1 (SAConLam p) D2 = SAsc (ALam p (ASubsume SEHole TCRefl))\n actsense1 SAConAp1 D2 = SAp D2 (ASubsume SEHole TCHole1)\n actsense1 SAConAp2 D2 = SApHole D2 (ASubsume SEHole TCRefl)\n actsense1 (SAConAp3 x) D2 = SApHole (SFHole D2) (ASubsume SEHole TCRefl)\n actsense1 SAConArg D2 = SApHole SEHole (ASubsume D2 TCHole2)\n actsense1 SAConNumlit D2 = SNum\n actsense1 (SAConPlus1 TCRefl) D2 = SPlus (ASubsume D2 TCRefl) (ASubsume SEHole TCHole1)\n actsense1 (SAConPlus1 TCHole2) D2 = SPlus (ASubsume D2 TCHole1) (ASubsume SEHole TCHole1)\n actsense1 (SAConPlus2 x) D2 = SPlus (ASubsume (SFHole D2) TCHole1) (ASubsume SEHole TCHole1)\n actsense1 (SAFinish x) D2 = x\n actsense1 (SAZipAsc1 x) (SAsc D2) = SAsc (actsense2 x D2)\n actsense1 (SAZipAsc2 x x₁) _ = SAsc x₁\n actsense1 (SAZipAp1 x D1 x₁) D2 = SAp (actsense1 D1 x) x₁\n actsense1 (SAZipAp2 x D1 x₁) D2 = SApHole (actsense1 D1 x) x₁\n actsense1 (SAZipAp3 x x₁) (SAp D2 x₃) with synthunicity x D2\n ... | refl = SAp x (actsense2 x₁ x₃)\n actsense1 (SAZipAp3 x x₁) (SApHole D2 x₂) with synthunicity x D2\n ... | ()\n actsense1 (SAZipAp4 x x₁) (SAp D2 x₂) with synthunicity x D2\n ... | ()\n actsense1 (SAZipAp4 x x₁) (SApHole D2 x₂) = SApHole x (actsense2 x₁ x₂)\n actsense1 (SAZipPlus1 x) (SPlus x₁ x₂) = SPlus (actsense2 x x₁) x₂\n actsense1 (SAZipPlus2 x) (SPlus x₁ x₂) = SPlus x₁ (actsense2 x x₂)\n actsense1 (SAZipHole1 x D1 x₁) D2 = SFHole (actsense1 D1 x)\n actsense1 (SAZipHole2 x D1) D2 = SEHole\n\n -- if an action transforms an zexp in an analytic posistion to another\n -- zexp, they have the same type up erasure of focus.\n actsense2 : {Γ : ·ctx} {e e' : ê} {t : τ̇} {α : action} →\n (Γ ⊢ e ~ α ~> e' ⇐ t) →\n (Γ ⊢ (e ◆e) <= t) →\n (Γ ⊢ (e' ◆e) <= t)\n actsense2 (AASubsume x act p) D2 = ASubsume (actsense1 act x) p\n actsense2 (AAMove x) D2 = anamovelem x D2\n actsense2 AADel _ = ASubsume SEHole TCHole1\n actsense2 AAConAsc D2 = ASubsume (SAsc D2) TCRefl\n actsense2 (AAConVar x₁ p) D2 = ASubsume (SFHole (SVar p)) TCHole1\n actsense2 (AAConLam1 p) (ASubsume SEHole TCHole1) = ALam p (ASubsume SEHole TCHole1)\n actsense2 (AAConLam2 p n~) (ASubsume SEHole TCRefl) = abort (n~ TCHole2)\n actsense2 (AAConLam2 p x₁) (ASubsume SEHole TCHole1) = ASubsume (SFHole (SAsc (ALam p (ASubsume SEHole TCRefl)))) TCHole1\n actsense2 (AAConLam2 p n~) (ASubsume SEHole TCHole2) = abort (n~ TCHole2)\n actsense2 (AAConNumlit _) _ = ASubsume (SFHole SNum) TCHole1\n actsense2 (AAFinish x) _ = x\n actsense2 (AAZipLam _ _ ) (ASubsume () _)\n\n actsense2 (AAZipLam x₁ (AASubsume {p = p} x₂ x₃ x₄)) (ALam x₅ D2) = ALam x₅ (actsense2 (AASubsume {p = p} x₂ x₃ x₄) D2)\n actsense2 (AAZipLam x₁ (AAMove x₂)) (ALam x₃ D2) = ALam x₃ (anamovelem x₂ D2)\n actsense2 (AAZipLam x₁ AADel) (ALam x₂ D2) = ALam x₂ (ASubsume SEHole TCHole1)\n actsense2 (AAZipLam x₁ AAConAsc) (ALam x₂ (ASubsume x₃ x₄)) = ALam x₂ (ASubsume (SAsc (ASubsume x₃ x₄)) TCRefl)\n actsense2 (AAZipLam x₁ AAConAsc) (ALam x₂ (ALam x₃ D2)) = ALam x₂ (ASubsume (SAsc (ALam x₃ D2)) TCRefl)\n actsense2 (AAZipLam x₁ (AAConVar x₃ p)) (ALam x₄ D2) = ALam x₄ (ASubsume (SFHole (SVar p)) TCHole1)\n actsense2 (AAZipLam x₁ (AAConLam1 x₃)) (ALam x₄ D2) = ALam x₄ (ALam x₃ (ASubsume SEHole TCHole1))\n actsense2 (AAZipLam x₁ (AAConLam2 x₃ x₄)) (ALam x₅ D2) = ALam x₅ (ASubsume (SFHole (SAsc (ALam x₃ (ASubsume SEHole TCRefl))))\n TCHole1)\n actsense2 (AAZipLam x₁ (AAConNumlit x₂)) (ALam x₃ D2) = ALam x₃ (ASubsume (SFHole SNum) TCHole1)\n actsense2 (AAZipLam x₁ (AAFinish x₂)) (ALam x₃ D2) = ALam x₃ x₂\n actsense2 (AAZipLam x₁ (AAZipLam x₃ D1)) (ALam x₄ (ASubsume () x₆))\n actsense2 (AAZipLam x₁ (AAZipLam x₃ D1)) (ALam x₄ (ALam x₅ D2)) = ALam x₄ (ALam x₃ (actsense2 D1 D2))\n", "meta": {"hexsha": "7233eedea87e7f29a8f97b1b9417fa79f3daee45", "size": 6624, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Hazelnut-sensible.agda", "max_stars_repo_name": "ivoysey/agda-tfp16", "max_stars_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-09T13:35:22.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-14T02:19:58.000Z", "max_issues_repo_path": "Hazelnut-sensible.agda", "max_issues_repo_name": "ivoysey/agda-tfp16", "max_issues_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb", "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": "Hazelnut-sensible.agda", "max_forks_repo_name": "ivoysey/agda-tfp16", "max_forks_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb", "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": 50.9538461538, "max_line_length": 129, "alphanum_fraction": 0.6568538647, "num_tokens": 2824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.665410572017153, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.38173167725686385}} {"text": "module Monads.ExceptT where\n\nopen import Class.Monad\nopen import Class.Monad.Except\nopen import Class.Monad.State\nopen import Class.MonadTrans\nopen import Data.Sum\nopen import Function\nopen import Level\n\nprivate\n variable\n a : Level\n\nExceptT : (M : Set a -> Set a) -> Set a -> Set a -> Set a\nExceptT M E A = M (E ⊎ A)\n\nExceptT-MonadTrans : {E : Set a} -> MonadTrans (λ (M : Set a -> Set a) -> ExceptT M E)\nExceptT-MonadTrans = record { embed = λ x -> x >>= (return ∘ inj₂) }\n\nmodule _ {M : Set a -> Set a} {{_ : Monad M}} {E : Set a} where\n\n ExceptT-Monad : Monad (ExceptT M E)\n ExceptT-Monad = record { _>>=_ = helper ; return = λ x → (return $ inj₂ x) }\n where\n helper : ∀ {A B} -> ExceptT M E A -> (A -> ExceptT M E B) -> ExceptT M E B\n helper x f = x >>= λ { (inj₁ y) -> return $ inj₁ y ; (inj₂ y) -> f y }\n\n private\n throwError' : ∀ {A : Set a} -> E -> ExceptT M E A\n throwError' = return ∘ inj₁\n\n catchError' : ∀ {A} -> ExceptT M E A -> (E -> ExceptT M E A) -> ExceptT M E A\n catchError' x f = x >>= λ { (inj₁ x) → f x ; (inj₂ y) → return {{ExceptT-Monad}} y }\n\n ExceptT-MonadExcept : MonadExcept (ExceptT M E) {{ExceptT-Monad}} E\n ExceptT-MonadExcept = record { throwError = throwError' ; catchError = catchError' }\n\n ExceptT-MonadState : ∀ {S} {{_ : MonadState M S}} -> MonadState (ExceptT M E) {{ExceptT-Monad}} S\n ExceptT-MonadState = record\n { get = embed {{ExceptT-MonadTrans}} get\n ; put = embed {{ExceptT-MonadTrans}} ∘ put }\n", "meta": {"hexsha": "a02e8ec3d1f5954329d9c4a60c4ea9a214a38fe7", "size": 1482, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "stdlib-exts/Monads/ExceptT.agda", "max_stars_repo_name": "WhatisRT/meta-cedille", "max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 35, "max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z", "max_issues_repo_path": "stdlib-exts/Monads/ExceptT.agda", "max_issues_repo_name": "WhatisRT/meta-cedille", "max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z", "max_forks_repo_path": "stdlib-exts/Monads/ExceptT.agda", "max_forks_repo_name": "WhatisRT/meta-cedille", "max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z", "avg_line_length": 34.4651162791, "max_line_length": 99, "alphanum_fraction": 0.6086369771, "num_tokens": 506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.3817240769874595}} {"text": "open import Nat\nopen import Prelude\nopen import contexts\nopen import dynamics-core\n\nopen import canonical-value-forms\n\nmodule canonical-boxed-forms where\n canonical-boxed-forms-num : ∀{Δ d} →\n Δ , ∅ ⊢ d :: num →\n d boxedval →\n Σ[ n ∈ Nat ] (d == N n)\n canonical-boxed-forms-num (TAVar _) (BVVal ())\n canonical-boxed-forms-num wt (BVVal v) = canonical-value-forms-num wt v\n\n -- this type gives somewhat nicer syntax for the output of the canonical\n -- forms lemma for boxed values at arrow type\n data cbf-arr : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where\n CBFALam : ∀{Δ d τ1 τ2} →\n Σ[ x ∈ Nat ] Σ[ d' ∈ ihexp ]\n ((d == (·λ x ·[ τ1 ] d')) ×\n (Δ , ■ (x , τ1) ⊢ d' :: τ2)\n )\n → cbf-arr Δ d τ1 τ2\n CBFACastArr : ∀{Δ d τ1 τ2} →\n Σ[ d' ∈ ihexp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]\n ((d == (d' ⟨ τ1' ==> τ2' ⇒ τ1 ==> τ2 ⟩)) ×\n (τ1' ==> τ2' ≠ τ1 ==> τ2) ×\n (Δ , ∅ ⊢ d' :: τ1' ==> τ2') ×\n (d' boxedval)\n )\n → cbf-arr Δ d τ1 τ2\n\n canonical-boxed-forms-arr : ∀{Δ d τ1 τ2 } →\n Δ , ∅ ⊢ d :: (τ1 ==> τ2) →\n d boxedval →\n cbf-arr Δ d τ1 τ2\n canonical-boxed-forms-arr (TAVar x₁) (BVVal ())\n canonical-boxed-forms-arr (TALam f wt) (BVVal v) = CBFALam (canonical-value-forms-arr (TALam f wt) v)\n canonical-boxed-forms-arr (TAAp wt wt₁) (BVVal ())\n canonical-boxed-forms-arr (TAEHole x x₁) (BVVal ())\n canonical-boxed-forms-arr (TANEHole x wt x₁) (BVVal ())\n canonical-boxed-forms-arr (TACast wt x) (BVVal ())\n canonical-boxed-forms-arr (TACast wt x) (BVArrCast x₁ bv) = CBFACastArr (_ , _ , _ , refl , x₁ , wt , bv)\n canonical-boxed-forms-arr (TAFailedCast x x₁ x₂ x₃) (BVVal ())\n\n -- this type gives somewhat nicer syntax for the output of the canonical\n -- forms lemma for boxed values at sum type\n data cbf-sum : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where\n CBFSInl : ∀{Δ d τ1 τ2} →\n Σ[ d' ∈ ihexp ]\n ((d == (inl τ2 d')) ×\n (Δ , ∅ ⊢ d' :: τ1) ×\n (d boxedval)\n )\n → cbf-sum Δ d τ1 τ2\n CBFSInr : ∀{Δ d τ1 τ2} →\n Σ[ d' ∈ ihexp ]\n ((d == (inr τ1 d')) ×\n (Δ , ∅ ⊢ d' :: τ2) ×\n (d boxedval)\n )\n → cbf-sum Δ d τ1 τ2\n CBFSCastSum : ∀{Δ d τ1 τ2} →\n Σ[ d' ∈ ihexp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]\n ((d == (d' ⟨ τ1' ⊕ τ2' ⇒ τ1 ⊕ τ2 ⟩)) ×\n (τ1' ⊕ τ2' ≠ τ1 ⊕ τ2) ×\n (Δ , ∅ ⊢ d' :: τ1' ⊕ τ2') ×\n (d' boxedval)\n )\n → cbf-sum Δ d τ1 τ2\n \n canonical-boxed-forms-sum : ∀{Δ d τ1 τ2 } →\n Δ , ∅ ⊢ d :: (τ1 ⊕ τ2) →\n d boxedval →\n cbf-sum Δ d τ1 τ2\n canonical-boxed-forms-sum (TAInl wt) x = CBFSInl (_ , refl , wt , x)\n canonical-boxed-forms-sum (TAInr wt) x = CBFSInr (_ , refl , wt , x)\n canonical-boxed-forms-sum (TACast wt x₁) (BVSumCast x bv) = CBFSCastSum (_ , _ , _ , refl , x , wt , bv)\n canonical-boxed-forms-sum (TAVar x₁) (BVVal ())\n canonical-boxed-forms-sum (TAAp wt wt₁) (BVVal ())\n canonical-boxed-forms-sum (TACase wt _ wt₁ _ wt₂) (BVVal ())\n canonical-boxed-forms-sum (TAFst wt) (BVVal ())\n canonical-boxed-forms-sum (TASnd wt) (BVVal ())\n canonical-boxed-forms-sum (TAEHole x₁ x₂) (BVVal ()) \n canonical-boxed-forms-sum (TANEHole x₁ wt x₂) (BVVal ())\n canonical-boxed-forms-sum (TACast wt x₁) (BVVal ())\n canonical-boxed-forms-sum (TAFailedCast wt x₁ x₂ x₃) (BVVal ())\n\n -- this type gives somewhat nicer syntax for the output of the canonical\n -- forms lemma for boxed values at product type\n data cbf-prod : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where\n CBFPPair : ∀{Δ d τ1 τ2} →\n Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ]\n ((d == ⟨ d1 , d2 ⟩) ×\n (Δ , ∅ ⊢ d1 :: τ1) ×\n (Δ , ∅ ⊢ d2 :: τ2) ×\n (d1 boxedval) ×\n (d2 boxedval)\n )\n → cbf-prod Δ d τ1 τ2\n CBFPCastProd : ∀{Δ d τ1 τ2} →\n Σ[ d' ∈ ihexp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]\n ((d == (d' ⟨ τ1' ⊠ τ2' ⇒ τ1 ⊠ τ2 ⟩)) ×\n (τ1' ⊠ τ2' ≠ τ1 ⊠ τ2) ×\n (Δ , ∅ ⊢ d' :: τ1' ⊠ τ2') ×\n (d' boxedval)\n )\n → cbf-prod Δ d τ1 τ2\n canonical-boxed-forms-prod : ∀{Δ d τ1 τ2 } →\n Δ , ∅ ⊢ d :: (τ1 ⊠ τ2) →\n d boxedval →\n cbf-prod Δ d τ1 τ2\n canonical-boxed-forms-prod (TAPair wt wt₁) (BVVal (VPair x x₁)) = CBFPPair (_ , _ , refl , wt , wt₁ , BVVal x , BVVal x₁)\n canonical-boxed-forms-prod (TAPair wt wt₁) (BVPair bv bv₁) = CBFPPair (_ , _ , refl , wt , wt₁ , bv , bv₁)\n canonical-boxed-forms-prod (TACast wt x) (BVProdCast x₁ bv) = CBFPCastProd (_ , _ , _ , refl , x₁ , wt , bv)\n \n canonical-boxed-forms-hole : ∀{Δ d} →\n Δ , ∅ ⊢ d :: ⦇-⦈ →\n d boxedval →\n Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]\n ((d == d' ⟨ τ' ⇒ ⦇-⦈ ⟩) ×\n (τ' ground) ×\n (Δ , ∅ ⊢ d' :: τ'))\n canonical-boxed-forms-hole (TAVar x₁) (BVVal ())\n canonical-boxed-forms-hole (TAAp wt wt₁) (BVVal ())\n canonical-boxed-forms-hole (TAEHole x x₁) (BVVal ())\n canonical-boxed-forms-hole (TANEHole x wt x₁) (BVVal ())\n canonical-boxed-forms-hole (TACast wt x) (BVVal ())\n canonical-boxed-forms-hole (TACast wt x) (BVHoleCast x₁ bv) = _ , _ , refl , x₁ , wt\n canonical-boxed-forms-hole (TAFailedCast x x₁ x₂ x₃) (BVVal ())\n\n canonical-boxed-forms-coverage : ∀{Δ d τ} →\n Δ , ∅ ⊢ d :: τ →\n d boxedval →\n τ ≠ num →\n ((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ==> τ2)) →\n ((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ⊕ τ2)) →\n ((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ⊠ τ2)) →\n τ ≠ ⦇-⦈ →\n ⊥\n canonical-boxed-forms-coverage TANum bv nn na ns np nh = nn refl\n canonical-boxed-forms-coverage (TAPlus wt wt₁) bv nn na ns np nh = nn refl\n canonical-boxed-forms-coverage (TALam x wt) bv nn na ns np nh = na _ _ refl\n canonical-boxed-forms-coverage (TAAp wt wt₁) (BVVal ()) nn na ns np nh\n canonical-boxed-forms-coverage (TAInl wt) bv nn na ns np nh = ns _ _ refl\n canonical-boxed-forms-coverage (TAInr wt) bv nn na ns np nh = ns _ _ refl\n canonical-boxed-forms-coverage (TACase wt _ wt₁ _ wt₂) (BVVal ()) nn na ns np nh\n canonical-boxed-forms-coverage (TAEHole x x₁) (BVVal ()) nn na ns np nh\n canonical-boxed-forms-coverage (TANEHole x wt x₁) (BVVal ()) nn na ns np nh\n canonical-boxed-forms-coverage (TACast wt x) (BVArrCast x₁ bv) nn na ns np nh = na _ _ refl\n canonical-boxed-forms-coverage (TACast wt x) (BVSumCast x₁ bv) nn na ns np nh = ns _ _ refl\n canonical-boxed-forms-coverage (TACast wt x) (BVProdCast x₁ bv) nn na ns np nh = np _ _ refl\n canonical-boxed-forms-coverage (TACast wt x) (BVHoleCast x₁ bv) nn na ns np nh = nh refl\n canonical-boxed-forms-coverage (TAFailedCast wt x x₁ x₂) (BVVal ()) nn na ns np nh\n canonical-boxed-forms-coverage (TAPair wt wt₁) bv nn na ns np nh = np _ _ refl\n canonical-boxed-forms-coverage (TAFst wt) (BVVal ()) nn na ns np nh\n canonical-boxed-forms-coverage (TASnd wt) (BVVal ()) nn na ns np nh\n \n", "meta": {"hexsha": "522453afc150c4a6d116a0244f27ceea53ab38f8", "size": 7496, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "canonical-boxed-forms.agda", "max_stars_repo_name": "hazelgrove/hazelnut-agda", "max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": "canonical-boxed-forms.agda", "max_issues_repo_name": "hazelgrove/hazelnut-agda", "max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": "canonical-boxed-forms.agda", "max_forks_repo_name": "hazelgrove/hazelnut-agda", "max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": 46.85, "max_line_length": 123, "alphanum_fraction": 0.5090715048, "num_tokens": 2751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.4843800842769844, "lm_q1q2_score": 0.3816581789499704}} {"text": "{-\nThis second-order term syntax was created from the following second-order syntax description:\n\nsyntax PDiff | PD\n\ntype\n * : 0-ary\n\nterm\n zero : * | 𝟘\n add : * * -> * | _⊕_ l20\n one : * | 𝟙\n mult : * * -> * | _⊗_ l20\n neg : * -> * | ⊖_ r50\n pd : *.* * -> * | ∂_∣_\n\ntheory\n (𝟘U⊕ᴸ) a |> add (zero, a) = a\n (𝟘U⊕ᴿ) a |> add (a, zero) = a\n (⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c))\n (⊕C) a b |> add(a, b) = add(b, a)\n (𝟙U⊗ᴸ) a |> mult (one, a) = a\n (𝟙U⊗ᴿ) a |> mult (a, one) = a\n (⊗A) a b c |> mult (mult(a, b), c) = mult (a, mult(b, c))\n (⊗D⊕ᴸ) a b c |> mult (a, add (b, c)) = add (mult(a, b), mult(a, c))\n (⊗D⊕ᴿ) a b c |> mult (add (a, b), c) = add (mult(a, c), mult(b, c))\n (𝟘X⊗ᴸ) a |> mult (zero, a) = zero\n (𝟘X⊗ᴿ) a |> mult (a, zero) = zero\n (⊖N⊕ᴸ) a |> add (neg (a), a) = zero\n (⊖N⊕ᴿ) a |> add (a, neg (a)) = zero\n (⊗C) a b |> mult(a, b) = mult(b, a)\n (∂⊕) a : * |> x : * |- d0 (add (x, a)) = one\n (∂⊗) a : * |> x : * |- d0 (mult(a, x)) = a\n (∂C) f : (*,*).* |> x : * y : * |- d1 (d0 (f[x,y])) = d0 (d1 (f[x,y]))\n (∂Ch₂) f : (*,*).* g h : *.* |> x : * |- d0 (f[g[x], h[x]]) = add (mult(pd(z. f[z, h[x]], g[x]), d0(g[x])), mult(pd(z. f[g[x], z], h[x]), d0(h[x])))\n (∂Ch₁) f g : *.* |> x : * |- d0 (f[g[x]]) = mult (pd (z. f[z], g[x]), d0(g[x]))\n-}\n\n\nmodule PDiff.Syntax where\n\nopen import SOAS.Common\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.Families.Core\nopen import SOAS.Construction.Structure\nopen import SOAS.ContextMaps.Inductive\n\nopen import SOAS.Metatheory.Syntax\n\nopen import PDiff.Signature\n\nprivate\n variable\n Γ Δ Π : Ctx\n α : *T\n 𝔛 : Familyₛ\n\n-- Inductive term declaration\nmodule PD:Terms (𝔛 : Familyₛ) where\n\n data PD : Familyₛ where\n var : ℐ ⇾̣ PD\n mvar : 𝔛 α Π → Sub PD Π Γ → PD α Γ\n\n 𝟘 : PD * Γ\n _⊕_ : PD * Γ → PD * Γ → PD * Γ\n 𝟙 : PD * Γ\n _⊗_ : PD * Γ → PD * Γ → PD * Γ\n ⊖_ : PD * Γ → PD * Γ\n ∂_∣_ : PD * (* ∙ Γ) → PD * Γ → PD * Γ\n\n infixl 20 _⊕_\n infixl 30 _⊗_\n infixr 50 ⊖_\n\n open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛\n\n PDᵃ : MetaAlg PD\n PDᵃ = record\n { 𝑎𝑙𝑔 = λ where\n (zeroₒ ⋮ _) → 𝟘\n (addₒ ⋮ a , b) → _⊕_ a b\n (oneₒ ⋮ _) → 𝟙\n (multₒ ⋮ a , b) → _⊗_ a b\n (negₒ ⋮ a) → ⊖_ a\n (pdₒ ⋮ a , b) → ∂_∣_ a b\n ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }\n\n module PDᵃ = MetaAlg PDᵃ\n\n module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where\n\n open MetaAlg 𝒜ᵃ\n\n 𝕤𝕖𝕞 : PD ⇾̣ 𝒜\n 𝕊 : Sub PD Π Γ → Π ~[ 𝒜 ]↝ Γ\n 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t\n 𝕊 (t ◂ σ) (old v) = 𝕊 σ v\n 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)\n 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v\n\n 𝕤𝕖𝕞 𝟘 = 𝑎𝑙𝑔 (zeroₒ ⋮ tt)\n 𝕤𝕖𝕞 (_⊕_ a b) = 𝑎𝑙𝑔 (addₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 𝟙 = 𝑎𝑙𝑔 (oneₒ ⋮ tt)\n 𝕤𝕖𝕞 (_⊗_ a b) = 𝑎𝑙𝑔 (multₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 (⊖_ a) = 𝑎𝑙𝑔 (negₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (∂_∣_ a b) = 𝑎𝑙𝑔 (pdₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n\n 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ PDᵃ 𝒜ᵃ 𝕤𝕖𝕞\n 𝕤𝕖𝕞ᵃ⇒ = record\n { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }\n ; ⟨𝑣𝑎𝑟⟩ = refl\n ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }\n where\n open ≡-Reasoning\n ⟨𝑎𝑙𝑔⟩ : (t : ⅀ PD α Γ) → 𝕤𝕖𝕞 (PDᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)\n ⟨𝑎𝑙𝑔⟩ (zeroₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (addₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (oneₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (multₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (negₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (pdₒ ⋮ _) = refl\n\n 𝕊-tab : (mε : Π ~[ PD ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)\n 𝕊-tab mε new = refl\n 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v\n\n module _ (g : PD ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ PDᵃ 𝒜ᵃ g) where\n\n open MetaAlg⇒ gᵃ⇒\n\n 𝕤𝕖𝕞! : (t : PD α Γ) → 𝕤𝕖𝕞 t ≡ g t\n 𝕊-ix : (mε : Sub PD Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)\n 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x\n 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v\n 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))\n = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))\n 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩\n\n 𝕤𝕖𝕞! 𝟘 = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (_⊕_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! 𝟙 = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (_⊗_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (⊖_ a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (∂_∣_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n\n\n-- Syntax instance for the signature\nPD:Syn : Syntax\nPD:Syn = record\n { ⅀F = ⅀F\n ; ⅀:CS = ⅀:CompatStr\n ; mvarᵢ = PD:Terms.mvar\n ; 𝕋:Init = λ 𝔛 → let open PD:Terms 𝔛 in record\n { ⊥ = PD ⋉ PDᵃ\n ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }\n ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }\n\n-- Instantiation of the syntax and metatheory\nopen Syntax PD:Syn public\nopen PD:Terms public\nopen import SOAS.Families.Build public\nopen import SOAS.Syntax.Shorthands PDᵃ public\nopen import SOAS.Metatheory PD:Syn public\n\n-- Derived operations\n∂₀_ : {𝔛 : Familyₛ} → PD 𝔛 * (* ∙ Γ) → PD 𝔛 * (* ∙ Γ)\n∂₀_ {𝔛 = 𝔛} e = ∂ Theory.𝕨𝕜 𝔛 e ∣ x₀\n∂₁_ : {𝔛 : Familyₛ} → PD 𝔛 * (* ∙ * ∙ Γ) → PD 𝔛 * (* ∙ * ∙ Γ)\n∂₁_ {𝔛 = 𝔛} e = ∂ Theory.𝕨𝕜 𝔛 e ∣ x₁\ninfix 10 ∂₀_ ∂₁_\n", "meta": {"hexsha": "55172e0dea10c5b0ce79e05b26637c0486a31c92", "size": 5001, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "out/PDiff/Syntax.agda", "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_issues_repo_path": "out/PDiff/Syntax.agda", "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_forks_repo_path": "out/PDiff/Syntax.agda", "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "avg_line_length": 28.9075144509, "max_line_length": 151, "alphanum_fraction": 0.4719056189, "num_tokens": 3267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743735019595, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.38164864808541626}} {"text": "{-# OPTIONS --safe --without-K #-}\nmodule Generics.All where\n\nopen import Generics.Prelude\nopen import Generics.Telescope\nopen import Generics.Desc\nopen import Generics.Mu\n\nprivate\n variable\n P : Telescope ⊤\n p : ⟦ P ⟧tel tt\n V I : ExTele P\n ℓ c : Level\n n : ℕ\n\n\nlevelAllIndArg : ConDesc P V I → Level → Level\nlevelAllIndArg (var _) c = c\nlevelAllIndArg (π {ℓ} _ _ C) c = ℓ ⊔ levelAllIndArg C c\nlevelAllIndArg (A ⊗ B) c = levelAllIndArg A c ⊔ levelAllIndArg B c\n\nAllIndArg\n : {X : ⟦ P , I ⟧xtel → Set ℓ}\n (Pr : ∀ {i} → X (p , i) → Set c)\n (C : ConDesc P V I)\n → ∀ {v} → ⟦ C ⟧IndArg X (p , v) → Set (levelAllIndArg C c)\nAllIndArg Pr (var _) x = Pr x\nAllIndArg Pr (π (n , ai) S C) x = (s : < relevance ai > S _) → AllIndArg Pr C (app< n , ai > x s)\nAllIndArg Pr (A ⊗ B) (xa , xb) = AllIndArg Pr A xa × AllIndArg Pr B xb\n\nAllIndArgω\n : {X : ⟦ P , I ⟧xtel → Set ℓ}\n (Pr : ∀ {i} → X (p , i) → Setω)\n (C : ConDesc P V I)\n → ∀ {v} → ⟦ C ⟧IndArg X (p , v) → Setω\nAllIndArgω Pr (var _) x = Pr x\nAllIndArgω Pr (π (n , ai) S C) x = (s : < relevance ai > S _) → AllIndArgω Pr C (app< n , ai > x s)\nAllIndArgω Pr (A ⊗ B) (xa , xb) = AllIndArgω Pr A xa ×ω AllIndArgω Pr B xb\n\n\nlevelAllCon : ConDesc P V I → Level → Level\nlevelAllCon (var _) c = lzero\nlevelAllCon (π {ℓ} _ _ C) c = levelAllCon C c\nlevelAllCon (A ⊗ B) c = levelAllIndArg A c ⊔ levelAllCon B c\n\nAllCon\n : {X : ⟦ P , I ⟧xtel → Set ℓ}\n (Pr : ∀ {i} → X (p , i) → Set c)\n (C : ConDesc P V I)\n → ∀ {v i} → ⟦ C ⟧Con X (p , v , i) → Set (levelAllCon C c)\nAllCon Pr (var _) x = ⊤\nAllCon Pr (π _ _ C) (_ , x) = AllCon Pr C x\nAllCon Pr (A ⊗ B) (xa , xb) = AllIndArg Pr A xa × AllCon Pr B xb\n\nAllConω\n : {X : ⟦ P , I ⟧xtel → Set ℓ}\n (Pr : ∀ {i} → X (p , i) → Setω)\n (C : ConDesc P V I)\n → ∀ {v i} → ⟦ C ⟧Con X (p , v , i) → Setω\nAllConω Pr (var f) x = ⊤ω\nAllConω Pr (π ia S C) (_ , x) = AllConω Pr C x\nAllConω Pr (A ⊗ B) (xa , xb) = AllIndArgω Pr A xa ×ω AllConω Pr B xb\n\n\nAllData : {X : ⟦ P , I ⟧xtel → Set ℓ}\n (Pr : ∀ {i} → X (p , i) → Set c)\n (D : DataDesc P I n)\n → ∀ {i} ((k , x) : ⟦ D ⟧Data X (p , i))\n → Set (levelAllCon (lookupCon D k) c)\nAllData Pr D (k , x) = AllCon Pr (lookupCon D k) x\n\nAllDataω : {X : ⟦ P , I ⟧xtel → Set ℓ}\n (Pr : ∀ {i} → X (p , i) → Setω)\n (D : DataDesc P I n)\n → ∀ {i} (x : ⟦ D ⟧Data X (p , i))\n → Setω\nAllDataω Pr D (k , x) = AllConω Pr (lookupCon D k) x\n", "meta": {"hexsha": "a5cd792019c3ba959a2d0a315180317cede5134a", "size": 2452, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Generics/All.agda", "max_stars_repo_name": "flupe/generics", "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_issues_repo_path": "src/Generics/All.agda", "max_issues_repo_name": "flupe/generics", "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_forks_repo_path": "src/Generics/All.agda", "max_forks_repo_name": "flupe/generics", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "avg_line_length": 31.0379746835, "max_line_length": 99, "alphanum_fraction": 0.527324633, "num_tokens": 1067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743735019595, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.3816486480854162}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import groups.SuspAdjointLoop\nopen import groups.ToOmega\nopen import cohomology.Theory\n\n{- A spectrum (family (Eₙ | n : ℤ) such that ΩEₙ₊₁ = Eₙ)\n - gives rise to a cohomology theory C with Cⁿ(S⁰) = π₁(Eₙ₊₁). -}\n\nmodule cohomology.SpectrumModel\n {i} (E : ℤ → Ptd i) (spectrum : (n : ℤ) → ⊙Ω (E (succ n)) ⊙≃ E n) where\n\nmodule SpectrumModel where\n\n {- Definition of cohomology group C -}\n module _ (n : ℤ) (X : Ptd i) where\n C : Group i\n C = Trunc-⊙→Ω-group X (E (succ n))\n\n {- convenient abbreviations -}\n CEl = Group.El C\n ⊙CEl = Group.⊙El C\n Cid = Group.ident C\n\n {- before truncation -}\n uCEl = X ⊙→ ⊙Ω (E (succ n))\n\n {- Cⁿ(X) is an abelian group -}\n C-is-abelian : (n : ℤ) (X : Ptd i) → is-abelian (C n X)\n C-is-abelian n X =\n iso-preserves-abelian (Trunc-⊙→Ω-group-emap-codom X (spectrum (succ n))) $\n Trunc-group-abelian (⊙→Ω-group-structure _ _) $ λ {(f , fpt) (g , gpt) →\n ⊙λ=' (λ x → Ω^2-∙-comm (f x) (g x)) (pt-lemma fpt gpt)}\n where\n pt-lemma : ∀ {i} {A : Type i} {x : A} {p q : idp {a = x} == idp {a = x}}\n (α : p == idp) (β : q == idp)\n → ⊙∘-pt (fst ⊙Ω-∙) (⊙fanout-pt α β) idp\n == ⊙∘-pt (fst ⊙Ω-∙) (⊙fanout-pt β α) idp\n [ _== idp ↓ Ω^2-∙-comm p q ]\n pt-lemma idp idp = idp\n\n {- C-fmap, the functorial action of C:\n - contravariant functor from pointed spaces to abelian groups -}\n module _ (n : ℤ) {X Y : Ptd i} where\n\n C-fmap : X ⊙→ Y → (C n Y →ᴳ C n X)\n C-fmap f = Trunc-⊙→Ω-group-fmap-dom f (E (succ n))\n\n CEl-fmap : X ⊙→ Y → CEl n Y → CEl n X\n CEl-fmap F = GroupHom.f (C-fmap F)\n\n ⊙CEl-fmap : X ⊙→ Y → ⊙CEl n Y ⊙→ ⊙CEl n X\n ⊙CEl-fmap F = GroupHom.⊙f (C-fmap F)\n\n {- C-fmap is a functor from pointed spaces to abelian groups -}\n module _ (n : ℤ) {X : Ptd i} where\n\n C-fmap-idf : ∀ x → CEl-fmap n {X} {X} (⊙idf X) x == x\n C-fmap-idf x = ap (λ h → GroupHom.f h x) (Trunc-⊙→Ω-group-fmap-dom-idf (E (succ n)))\n\n C-fmap-∘ : {Y Z : Ptd i} (g : Y ⊙→ Z) (f : X ⊙→ Y)\n → ∀ x → CEl-fmap n (g ⊙∘ f) x == CEl-fmap n f (CEl-fmap n g x)\n C-fmap-∘ g f x = ap (λ h → GroupHom.f h x) (Trunc-⊙→Ω-group-fmap-dom-∘ g f (E (succ n)))\n\n -- Eilenberg-Steenrod Axioms\n\n {- Susp Axiom -}\n private\n C-Susp' : {E₁ E₀ : Ptd i} (iso : ⊙Ω E₁ ⊙≃ E₀) (X : Ptd i)\n → Trunc-⊙→Ω-group (⊙Susp X) E₁ ≃ᴳ Trunc-⊙→Ω-group X E₀\n C-Susp' {E₁ = E₁} iso X = Trunc-⊙→Ω-group-emap-codom X iso\n ∘eᴳ Trunc-⊙→Ω-iso-Trunc-⊙→Ω X E₁\n\n -- This can be further simplified\n C-Susp-fmap' : {E₁ E₀ : Ptd i} (iso : ⊙Ω E₁ ⊙≃ E₀) {X Y : Ptd i} (f : X ⊙→ Y)\n → CommSquareᴳ\n (Trunc-⊙→Ω-group-fmap-dom (⊙Susp-fmap f) E₁)\n (Trunc-⊙→Ω-group-fmap-dom f E₀)\n (fst (C-Susp' iso Y)) (fst (C-Susp' iso X))\n C-Susp-fmap' {E₁} {E₀} iso {X} {Y} f = comm-sqrᴳ λ x →\n GroupHom.f (Trunc-⊙→Ω-group-fmap-codom X (fst iso))\n (GroupIso.f (Trunc-⊙→Ω-iso-Trunc-⊙→Ω X E₁)\n (GroupHom.f (Trunc-⊙→Ω-group-fmap-dom (⊙Susp-fmap f) E₁) x))\n =⟨ Trunc-⊙→Ω-iso-Trunc-⊙→Ω-nat-dom f E₁\n |in-ctx (λ h → GroupHom.f h x)\n |in-ctx GroupHom.f (Trunc-⊙→Ω-group-fmap-codom X (fst iso)) ⟩\n GroupHom.f (Trunc-⊙→Ω-group-fmap-codom X (fst iso))\n (GroupHom.f (Trunc-⊙→Ω-group-fmap-dom f (⊙Ω E₁))\n (GroupIso.f (Trunc-⊙→Ω-iso-Trunc-⊙→Ω Y E₁) x))\n =⟨ ! $ Trunc-⊙→Ω-group-fmap-nat f (fst iso)\n |in-ctx GroupHom.f\n |in-ctx (λ h → h (GroupIso.f (Trunc-⊙→Ω-iso-Trunc-⊙→Ω Y E₁) x)) ⟩\n GroupHom.f (Trunc-⊙→Ω-group-fmap-dom f E₀)\n (GroupHom.f (Trunc-⊙→Ω-group-fmap-codom Y (fst iso))\n (GroupIso.f (Trunc-⊙→Ω-iso-Trunc-⊙→Ω Y E₁) x))\n =∎\n\n C-Susp : (n : ℤ) (X : Ptd i) → C (succ n) (⊙Susp X) ≃ᴳ C n X\n C-Susp n X = C-Susp' (spectrum (succ n)) X\n\n C-Susp-fmap : (n : ℤ) {X Y : Ptd i} (f : X ⊙→ Y)\n → CommSquareᴳ\n (C-fmap (succ n) (⊙Susp-fmap f)) (C-fmap n f)\n (fst (C-Susp n Y)) (fst (C-Susp n X))\n C-Susp-fmap n f = C-Susp-fmap' (spectrum (succ n)) f\n\n {- Non-truncated Exactness Axiom -}\n module _ (n : ℤ) {X Y : Ptd i} where\n\n {- precomposing [⊙cfcod' f] and then [f] gives [0] -}\n im-sub-ker-lemma : (f : X ⊙→ Y) (g : uCEl n (⊙Cofiber f))\n → (g ⊙∘ ⊙cfcod' f) ⊙∘ f == ⊙cst\n im-sub-ker-lemma (f , fpt) (g , gpt) = ⊙λ='\n (λ x → ap g (! (cfglue' f x)) ∙ gpt)\n (↓-idf=cst-in\n (ap (g ∘ cfcod) fpt\n ∙ ap g (ap cfcod (! fpt) ∙ ! (cfglue (pt X))) ∙ gpt\n =⟨ lemma cfcod g fpt (! (cfglue (pt X))) gpt ⟩\n ap g (! (cfglue (pt X))) ∙ gpt\n =⟨ ! (∙-unit-r _) ⟩\n (ap g (! (cfglue (pt X))) ∙ gpt) ∙ idp ∎))\n where\n lemma : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}\n {a₁ a₂ : A} {b : B} {c : C} (f : A → B) (g : B → C)\n (p : a₁ == a₂) (q : f a₁ == b) (r : g b == c)\n → ap (g ∘ f) p ∙ ap g (ap f (! p) ∙ q) ∙ r == ap g q ∙ r\n lemma f g idp idp idp = idp\n\n {- if g ⊙∘ f is constant then g factors as h ⊙∘ ⊙cfcod' f -}\n ker-sub-im-lemma : (f : X ⊙→ Y) (g : uCEl n Y)\n → g ⊙∘ f == ⊙cst\n → Σ (uCEl n (⊙Cofiber f)) (λ h → h ⊙∘ ⊙cfcod' f == g)\n ker-sub-im-lemma (f , fpt) (h , hpt) p =\n ((g , ! q ∙ hpt) ,\n pair= idp (! (∙-assoc q (! q) hpt) ∙ ap (_∙ hpt) (!-inv-r q)))\n where\n g : Cofiber f → Ω (E (succ n))\n g = CofiberRec.f idp h (! ∘ app= (ap fst p))\n\n q : h (pt Y) == g (cfbase' f)\n q = ap g (snd (⊙cfcod' (f , fpt)))\n\n {- Truncated Exactness Axiom -}\n module _ (n : ℤ) {X Y : Ptd i} where\n\n abstract\n C-im-sub-ker : (f : X ⊙→ Y)\n → im-propᴳ (C-fmap n (⊙cfcod' f)) ⊆ᴳ ker-propᴳ (C-fmap n f)\n C-im-sub-ker f =\n im-sub-ker-in (C-fmap n (⊙cfcod' f)) (C-fmap n f) $\n Trunc-elim\n (ap [_] ∘ im-sub-ker-lemma n f)\n\n abstract\n C-ker-sub-im : (f : X ⊙→ Y)\n → ker-propᴳ (C-fmap n f) ⊆ᴳ im-propᴳ (C-fmap n (⊙cfcod' f))\n C-ker-sub-im f =\n Trunc-elim\n {{λ _ → Π-level (λ _ → raise-level _ Trunc-level)}}\n (λ h tp → Trunc-rec (lemma h) (–> (Trunc=-equiv _ _) tp))\n where\n lemma : (h : uCEl n Y) → h ⊙∘ f == ⊙cst\n → Trunc -1 (Σ (CEl n (⊙Cofiber f))\n (λ tk → fst (⊙CEl-fmap n (⊙cfcod' f)) tk == [ h ]))\n lemma h p = [ [ fst wit ] , ap [_] (snd wit) ]\n where\n wit : Σ (uCEl n (⊙Cofiber f)) (λ k → k ⊙∘ ⊙cfcod' f == h)\n wit = ker-sub-im-lemma n f h p\n\n C-exact : (f : X ⊙→ Y) → is-exact (C-fmap n (⊙cfcod' f)) (C-fmap n f)\n C-exact f = record {im-sub-ker = C-im-sub-ker f; ker-sub-im = C-ker-sub-im f}\n\n {- Additivity Axiom -}\n module _ (n : ℤ) {A : Type i} (X : A → Ptd i)\n (ac : has-choice 0 A i)\n where\n\n into : CEl n (⊙BigWedge X) → Trunc 0 (Π A (uCEl n ∘ X))\n into = Trunc-rec (λ H → [ (λ a → H ⊙∘ ⊙bwin a) ])\n\n module Out' (K : Π A (uCEl n ∘ X)) = BigWedgeRec\n idp\n (fst ∘ K)\n (! ∘ snd ∘ K)\n\n out : Trunc 0 (Π A (uCEl n ∘ X)) → CEl n (⊙BigWedge X)\n out = Trunc-rec (λ K → [ Out'.f K , idp ])\n\n into-out : ∀ y → into (out y) == y\n into-out = Trunc-elim\n (λ K → ap [_] (λ= (λ a → pair= idp $\n ap (Out'.f K) (! (bwglue a)) ∙ idp\n =⟨ ∙-unit-r _ ⟩\n ap (Out'.f K) (! (bwglue a))\n =⟨ ap-! (Out'.f K) (bwglue a) ⟩\n ! (ap (Out'.f K) (bwglue a))\n =⟨ ap ! (Out'.glue-β K a) ⟩\n ! (! (snd (K a)))\n =⟨ !-! (snd (K a)) ⟩\n snd (K a) ∎)))\n\n out-into : ∀ x → out (into x) == x\n out-into = Trunc-elim\n {P = λ tH → out (into tH) == tH}\n (λ {(h , hpt) → ap [_] $ ⊙λ=' (out-into-fst (h , hpt)) (↓-idf=cst-in (! (!-inv-l hpt)))})\n where\n lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)\n {a₁ a₂ : A} {b : B} (p : a₁ == a₂) (q : f a₁ == b)\n → ! q ∙ ap f p == ! (ap f (! p) ∙ q)\n lemma f idp idp = idp\n\n out-into-fst : (H : ⊙BigWedge X ⊙→ ⊙Ω (E (succ n)))\n → ∀ w → Out'.f (λ a → H ⊙∘ ⊙bwin a) w == fst H w\n out-into-fst (h , hpt) = BigWedge-elim\n (! hpt)\n (λ _ _ → idp)\n (λ a → ↓-='-in' $\n ! hpt ∙ ap h (bwglue a)\n =⟨ lemma h (bwglue a) hpt ⟩\n ! (ap h (! (bwglue a)) ∙ hpt)\n =⟨ ! (Out'.glue-β (λ a → (h , hpt) ⊙∘ ⊙bwin a) a) ⟩\n ap (Out'.f (λ a → (h , hpt) ⊙∘ ⊙bwin a)) (bwglue a) ∎)\n\n abstract\n C-additive-is-equiv : is-equiv (GroupHom.f (Πᴳ-fanout (C-fmap n ∘ ⊙bwin {X = X})))\n C-additive-is-equiv = transport is-equiv\n (λ= $ Trunc-elim\n (λ _ → idp))\n ((ac (uCEl n ∘ X)) ∘ise (is-eq into out into-out out-into))\n\n\nopen SpectrumModel\n\nspectrum-cohomology : CohomologyTheory i\nspectrum-cohomology = record {\n C = C;\n C-fmap = C-fmap;\n C-fmap-idf = C-fmap-idf;\n C-fmap-∘ = C-fmap-∘;\n C-is-abelian = C-is-abelian;\n C-Susp = C-Susp;\n C-Susp-fmap = C-Susp-fmap;\n C-exact = C-exact;\n C-additive-is-equiv = C-additive-is-equiv}\n\nspectrum-C-S⁰ : (n : ℤ) → C n (⊙Lift ⊙S⁰) ≃ᴳ πS 0 (E (succ n))\nspectrum-C-S⁰ n = Trunc-⊙Bool→Ω-iso-π₁ (E (succ n)) ∘eᴳ Trunc-⊙→Ω-group-emap-dom ⊙lift-equiv (E (succ n))\n", "meta": {"hexsha": "78f5db8d65c788ee8281d51979d361eab7a03de2", "size": 9129, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/cohomology/SpectrumModel.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/cohomology/SpectrumModel.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/cohomology/SpectrumModel.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": 36.6626506024, "max_line_length": 105, "alphanum_fraction": 0.4769416146, "num_tokens": 4185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.38153595997882017}} {"text": "postulate\n C : Set\n anything : C\n\nrecord I : Set where\n constructor c\n field\n {f} : C\n\ndata Wrap : (i : I) → Set where\n wrap : ∀ {i} → Wrap i\n\nworks : ∀ {j} → Wrap j → C\nworks {c {._}} (wrap {c {x}}) = anything\n\nfails : ∀ {j} → Wrap j → C\nfails {c {._}} (wrap {c}) = anything\n\n-- Failed to infer the value of dotted pattern\n-- when checking that the pattern ._ has type C\n\nfails' : ∀ {j} → Wrap j → C\nfails' .{c {_}} (wrap {c}) = anything\n\nworks2 : ∀ {j} → Wrap j → C\nworks2 {c} (wrap {c {._}}) = anything\n\nfails2 : ∀ {j} → Wrap j → C\nfails2 {c {._}} (wrap {c}) = anything\n", "meta": {"hexsha": "0f85727e24a16327909130c532364d5846c4978b", "size": 581, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1608.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/Succeed/Issue1608.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/Succeed/Issue1608.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": 19.3666666667, "max_line_length": 47, "alphanum_fraction": 0.5507745267, "num_tokens": 217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.38148132948276886}} {"text": "{-# OPTIONS --safe --experimental-lossy-unification #-}\nmodule Cubical.ZCohomology.Groups.KleinBottle where\n\nopen import Cubical.ZCohomology.Base\nopen import Cubical.ZCohomology.GroupStructure\nopen import Cubical.ZCohomology.Properties\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Pointed\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.GroupoidLaws\nopen import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to pRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap)\nopen import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∣_∣ to ∣_∣₁)\nopen import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2)\nopen import Cubical.Data.Nat hiding (+-assoc)\nopen import Cubical.Algebra.Group renaming (Int to IntGroup ; Bool to BoolGroup ; Unit to UnitGroup)\n\nopen import Cubical.Foundations.Equiv.HalfAdjoint\nopen import Cubical.Foundations.Transport\n\nopen import Cubical.ZCohomology.Groups.Unit\nopen import Cubical.ZCohomology.Groups.Sn\n\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.HITs.S1\nopen import Cubical.HITs.Sn\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Homotopy.Connected\n\nopen import Cubical.Data.Empty renaming (rec to ⊥-rec)\nopen import Cubical.Data.Bool\nopen import Cubical.Data.Int renaming (+-comm to +-commℤ ; _+_ to _+ℤ_)\n\nopen import Cubical.HITs.KleinBottle\nopen import Cubical.Data.Empty\nopen import Cubical.Foundations.Path\n\nopen import Cubical.Homotopy.Loopspace\n\nopen IsGroupHom\nopen Iso\n\ncharacFunSpace𝕂² : ∀ {ℓ} (A : Type ℓ) →\n Iso (KleinBottle → A)\n (Σ[ x ∈ A ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q)\nfun (characFunSpace𝕂² A) f =\n (f point) ,\n ((cong f line1) ,\n (cong f line2 ,\n fst (Square≃doubleComp\n (cong f line2) (cong f line2)\n (sym (cong f line1)) (cong f line1))\n (λ i j → f (square i j))))\ninv (characFunSpace𝕂² A) (x , p , q , sq) point = x\ninv (characFunSpace𝕂² A) (x , p , q , sq) (line1 i) = p i\ninv (characFunSpace𝕂² A) (x , p , q , sq) (line2 i) = q i\ninv (characFunSpace𝕂² A) (x , p , q , sq) (square i j) =\n invEq (Square≃doubleComp q q (sym p) p) sq i j\nrightInv (characFunSpace𝕂² A) (x , (p , (q , sq))) =\n ΣPathP (refl , (ΣPathP (refl , (ΣPathP (refl , secEq (Square≃doubleComp q q (sym p) p) sq)))))\nleftInv (characFunSpace𝕂² A) f _ point = f point\nleftInv (characFunSpace𝕂² A) f _ (line1 i) = f (line1 i)\nleftInv (characFunSpace𝕂² A) f _ (line2 i) = f (line2 i)\nleftInv (characFunSpace𝕂² A) f z (square i j) =\n retEq (Square≃doubleComp\n (cong f line2) (cong f line2)\n (sym (cong f line1)) (cong f line1))\n (λ i j → f (square i j)) z i j\nprivate\n movePathLem : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → isComm∙ (A , x)\n → (p ∙∙ q ∙∙ p ≡ q) ≡ ((p ∙ p) ∙ q ≡ q)\n movePathLem p q comm =\n cong (_≡ q) (doubleCompPath-elim' p q p ∙∙ cong (p ∙_) (comm q p) ∙∙ assoc _ _ _)\n\n movePathLem2 : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x)\n → (((p ∙ p) ∙ q) ∙ sym q ≡ q ∙ sym q) ≡ (p ∙ p ≡ refl)\n movePathLem2 p q =\n cong₂ _≡_ (sym (assoc (p ∙ p) q (sym q)) ∙∙ cong ((p ∙ p) ∙_) (rCancel q) ∙∙ sym (rUnit (p ∙ p)))\n (rCancel q)\n\n movePathIso : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → isComm∙ (A , x)\n → Iso (p ∙∙ q ∙∙ p ≡ q) (p ∙ p ≡ refl)\n movePathIso {x = x} p q comm =\n compIso (pathToIso (movePathLem p q comm))\n (compIso (helper (p ∙ p))\n (pathToIso (movePathLem2 p q)))\n where\n helper : (p : x ≡ x) → Iso (p ∙ q ≡ q) ((p ∙ q) ∙ sym q ≡ q ∙ sym q)\n helper p = congIso (equivToIso (_ , compPathr-isEquiv (sym q)))\n\n------ H¹(𝕂²) ≅ 0 --------------\nH⁰-𝕂² : GroupIso (coHomGr 0 KleinBottle) IntGroup\nfun (fst H⁰-𝕂²) = sRec isSetInt λ f → f point\ninv (fst H⁰-𝕂²) x = ∣ (λ _ → x) ∣₂\nrightInv (fst H⁰-𝕂²) _ = refl\nleftInv (fst H⁰-𝕂²) =\n sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)\n λ f → cong ∣_∣₂ (funExt (λ {point → refl\n ; (line1 i) j → isSetInt (f point) (f point) refl (cong f line1) j i\n ; (line2 i) j → isSetInt (f point) (f point) refl (cong f line2) j i\n ; (square i j) z → helper f i j z}))\n where\n helper : (f : KleinBottle → Int)\n → Cube (λ j z → isSetInt (f point) (f point) refl (cong f line2) z j)\n (λ j z → isSetInt (f point) (f point) refl (cong f line2) z j)\n (λ i z → isSetInt (f point) (f point) refl (cong f line1) z (~ i))\n (λ i z → isSetInt (f point) (f point) refl (cong f line1) z i)\n refl\n λ i j → f (square i j)\n helper f = isGroupoid→isGroupoid' (isOfHLevelSuc 2 isSetInt) _ _ _ _ _ _\nsnd H⁰-𝕂² =\n makeIsGroupHom (sElim2 (λ _ _ → isOfHLevelPath 2 isSetInt _ _) λ _ _ → refl)\n\n------ H¹(𝕂¹) ≅ ℤ ------------\n{-\nStep one :\nH¹(𝕂²) := ∥ 𝕂² → K₁ ∥₂\n ≡ ∥ Σ[ x ∈ K₁ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] (p ∙∙ q ∙∙ p ≡ q) ∥₂ (characFunSpace𝕂²)\n ≡ ∥ Σ[ x ∈ K₁ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (movePathIso, using commutativity of ΩK₂)\n ≡ ∥ Σ[ x ∈ K₁ ] (x ≡ x) ∥₂ (p ∙ p ≡ refl forces p ≡ refl. Also, p ∙ p ≡ refl is an hProp)\n-}\n\nnilpotent→≡0 : (x : Int) → x +ℤ x ≡ 0 → x ≡ 0\nnilpotent→≡0 (pos zero) p = refl\nnilpotent→≡0 (pos (suc n)) p =\n ⊥-rec (negsucNotpos _ _\n (sym (cong (_- 1) (cong sucInt (sym (helper2 n)) ∙ p))))\n where\n helper2 : (n : ℕ) → pos (suc n) +pos n ≡ pos (suc (n + n))\n helper2 zero = refl\n helper2 (suc n) = cong sucInt (sym (sucInt+pos n (pos (suc n))))\n ∙∙ cong (sucInt ∘ sucInt) (helper2 n)\n ∙∙ cong (pos ∘ suc ∘ suc) (sym (+-suc n n))\nnilpotent→≡0 (negsuc n) p = ⊥-rec (negsucNotpos _ _ (helper2 n p))\n where\n helper2 : (n : ℕ) → (negsuc n +negsuc n) ≡ pos 0 → negsuc n ≡ pos (suc n)\n helper2 n p = cong (negsuc n +ℤ_) (sym (helper3 n))\n ∙ +-assoc (negsuc n) (negsuc n) (pos (suc n))\n ∙∙ cong (_+ℤ (pos (suc n))) p\n ∙∙ cong sucInt (+-commℤ (pos 0) (pos n))\n where\n helper3 : (n : ℕ) → negsuc n +pos (suc n) ≡ 0\n helper3 zero = refl\n helper3 (suc n) = cong sucInt (sucInt+pos n (negsuc (suc n))) ∙ helper3 n\n\nnilpotent→≡refl : (x : coHomK 1) (p : x ≡ x) → p ∙ p ≡ refl → p ≡ refl\nnilpotent→≡refl =\n trElim (λ _ → isGroupoidΠ2 λ _ _ → isOfHLevelPlus {n = 1} 2 (isOfHLevelTrunc 3 _ _ _ _))\n (toPropElim (λ _ → isPropΠ2 λ _ _ → isOfHLevelTrunc 3 _ _ _ _)\n λ p pId → sym (rightInv (Iso-Kn-ΩKn+1 0) p)\n ∙∙ cong (Kn→ΩKn+1 0) (nilpotent→≡0 (ΩKn+1→Kn 0 p)\n (sym (ΩKn+1→Kn-hom 0 p p)\n ∙ cong (ΩKn+1→Kn 0) pId))\n ∙∙ Kn→ΩKn+10ₖ 0)\n\nIso-H¹-𝕂²₁ : Iso (Σ[ x ∈ coHomK 1 ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl)\n (Σ[ x ∈ coHomK 1 ] x ≡ x)\nfun Iso-H¹-𝕂²₁ (x , (_ , (q , _))) = x , q\ninv Iso-H¹-𝕂²₁ (x , q) = x , (refl , (q , (sym (rUnit refl))))\nrightInv Iso-H¹-𝕂²₁ _ = refl\nleftInv Iso-H¹-𝕂²₁ (x , (p , (q , P))) =\n ΣPathP (refl ,\n (ΣPathP (sym (nilpotent→≡refl x p P)\n , toPathP (Σ≡Prop (λ _ → isOfHLevelTrunc 3 _ _ _ _)\n (transportRefl q)))))\n\n{- But this is precisely the type (minus set-truncation) of H¹(S¹) -}\nIso-H¹-𝕂²₂ : Iso (Σ[ x ∈ coHomK 1 ] x ≡ x) (S¹ → coHomK 1)\nIso-H¹-𝕂²₂ = invIso IsoFunSpaceS¹\n\nH¹-𝕂²≅ℤ : GroupIso (coHomGr 1 KleinBottle) IntGroup\nH¹-𝕂²≅ℤ = compGroupIso theGroupIso (Hⁿ-Sⁿ≅ℤ 0)\n where\n theIso : Iso (coHom 1 KleinBottle) (coHom 1 S¹)\n theIso =\n setTruncIso (\n compIso (characFunSpace𝕂² (coHomK 1))\n (compIso\n (Σ-cong-iso-snd (λ x → Σ-cong-iso-snd\n λ p → Σ-cong-iso-snd\n λ q → movePathIso p q (isCommΩK-based 1 x)))\n (compIso Iso-H¹-𝕂²₁\n Iso-H¹-𝕂²₂)))\n\n is-hom : IsGroupHom (coHomGr 1 KleinBottle .snd) (fun theIso) (coHomGr 1 S¹ .snd)\n is-hom =\n makeIsGroupHom\n (sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _)\n λ f g → cong ∣_∣₂ (funExt λ {base → refl ; (loop i) → refl}))\n\n theGroupIso : GroupIso (coHomGr 1 KleinBottle) (coHomGr 1 S¹)\n theGroupIso = (theIso , is-hom)\n\n------ H²(𝕂²) ≅ ℤ/2ℤ (represented here by BoolGroup) -------\n-- It suffices to show that H²(Klein) is equivalent to Bool as types\n\n{-\nStep one :\nH²(𝕂²) := ∥ 𝕂² → K₂ ∥₂\n ≡ ∥ Σ[ x ∈ K₂ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] (p ∙∙ q ∙∙ p ≡ q) ∥₂ (characFunSpace𝕂²)\n ≡ ∥ Σ[ x ∈ K₂ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (movePathIso, using commutativity of ΩK₂)\n ≡ ∥ Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (connectedness of K₂)\n-}\n\n\nIso-H²-𝕂²₁ : Iso ∥ Σ[ x ∈ coHomK 2 ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂\n ∥ Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ∙ p ≡ refl ∥₂\nfun Iso-H²-𝕂²₁ =\n sRec setTruncIsSet\n (uncurry (trElim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 2} 2 setTruncIsSet)\n (sphereElim _ (λ _ → isSetΠ λ _ → setTruncIsSet)\n λ y → ∣ fst y , snd (snd y) ∣₂)))\ninv Iso-H²-𝕂²₁ =\n sMap λ p → (0ₖ 2) , ((fst p) , (refl , (snd p)))\nrightInv Iso-H²-𝕂²₁ =\n sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)\n λ p → refl\nleftInv Iso-H²-𝕂²₁ =\n sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)\n (uncurry (trElim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 1} 3 (setTruncIsSet _ _))\n (sphereToPropElim _\n (λ _ → isPropΠ λ _ → setTruncIsSet _ _)\n λ {(p , (q , sq))\n → trRec (setTruncIsSet _ _)\n (λ qid → cong ∣_∣₂ (ΣPathP (refl , (ΣPathP (refl , (ΣPathP (sym qid , refl)))))))\n (fun (PathIdTruncIso _)\n (isContr→isProp (isConnectedPathKn 1 (0ₖ 2) (0ₖ 2)) ∣ q ∣ ∣ refl ∣))})))\n\n{- Step two : ∥ Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ ≡ ∥ Σ[ x ∈ K₁ ] x + x ≡ 0 ∥₂ -}\nIso-H²-𝕂²₂ : Iso ∥ (Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ∙ p ≡ refl) ∥₂ ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂\nIso-H²-𝕂²₂ = setTruncIso (Σ-cong-iso {B' = λ x → x +ₖ x ≡ 0ₖ 1} (invIso (Iso-Kn-ΩKn+1 1))\n λ p → compIso (congIso (invIso (Iso-Kn-ΩKn+1 1)))\n (pathToIso λ i → ΩKn+1→Kn-hom 1 p p i ≡ 0ₖ 1))\n\n{- Step three :\n∥ Σ[ x ∈ K₁ ] x + x ≡ 0 ∥₂ ≡ Bool\nWe begin by defining the a map Σ[ x ∈ K₁ ] x + x ≡ 0 → Bool. For a point\n(0 , p) we map it to true if winding(p) is even and false if winding(p) is odd.\nWe also have to show that this map respects the loop\n-}\n\nΣKₙNilpot→Bool : Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 → Bool\nΣKₙNilpot→Bool = uncurry (trElim (λ _ → isGroupoidΠ λ _ → isOfHLevelSuc 2 isSetBool)\n λ {base p → isEven (ΩKn+1→Kn 0 p)\n ; (loop i) p → hcomp (λ k → λ { (i = i0) → respectsLoop p k\n ; (i = i1) → isEven (ΩKn+1→Kn 0 p)})\n (isEven (ΩKn+1→Kn 0 (transp (λ j → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) i\n p)))})\n where\n isEven-2 : (x : Int) → isEven (-2 +ℤ x) ≡ isEven x\n isEven-2 (pos zero) = refl\n isEven-2 (pos (suc zero)) = refl\n isEven-2 (pos (suc (suc n))) =\n cong isEven (cong sucInt (sucInt+pos _ _)\n ∙∙ sucInt+pos _ _\n ∙∙ +-commℤ 0 (pos n))\n ∙ lossy n\n where\n lossy : (n : ℕ) → isEven (pos n) ≡ isEven (pos n)\n lossy n = refl\n isEven-2 (negsuc zero) = refl\n isEven-2 (negsuc (suc n)) =\n cong isEven (predInt+negsuc n _\n ∙ +-commℤ -3 (negsuc n))\n ∙ lossy2 n\n where\n lossy2 : (n : ℕ) → isEven (negsuc (suc (suc (suc n)))) ≡ isEven (pos n)\n lossy2 n = refl\n respectsLoop : (p : 0ₖ 1 ≡ 0ₖ 1)\n → isEven (ΩKn+1→Kn 0 (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1) p))\n ≡ isEven (ΩKn+1→Kn 0 p)\n respectsLoop p =\n cong isEven (cong (ΩKn+1→Kn 0) (cong (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1))\n (lUnit p)))\n ∙∙ cong isEven (cong (ΩKn+1→Kn 0)\n λ j → transp (λ i → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) j\n ((λ i → ∣ (loop ∙ loop) (~ i ∧ j) ∣) ∙ p))\n ∙∙ cong isEven (ΩKn+1→Kn-hom 0 (sym (cong ∣_∣ (loop ∙ loop))) p)\n ∙ isEven-2 (ΩKn+1→Kn 0 p)\n\n{-\nWe show that for any x : Int we have ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ≡ ∣ (0ₖ 1 , refl) ∣₂ when x is even\nand ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ≡ ∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂ when x is odd\n\nThis is done by induction on x. For the inductive step we define a multiplication _*_ on ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂\nwhich is just ∣ (0 , p) ∣₂ * ∣ (0 , q) ∣₂ ≡ ∣ (0 , p ∙ q) ∣₂ when x is 0\n-}\n\nprivate\n _*_ : ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂\n _*_ = sRec (isSetΠ (λ _ → setTruncIsSet)) λ a → sRec setTruncIsSet λ b → *' (fst a) (fst b) (snd a) (snd b)\n where\n *' : (x y : coHomK 1) (p : x +ₖ x ≡ 0ₖ 1) (q : y +ₖ y ≡ 0ₖ 1) → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂\n *' =\n trElim2 (λ _ _ → isGroupoidΠ2 λ _ _ → isOfHLevelSuc 2 setTruncIsSet)\n (wedgeconFun _ _\n (λ _ _ → isSetΠ2 λ _ _ → setTruncIsSet)\n (λ x p q → ∣ ∣ x ∣ , cong₂ _+ₖ_ p q ∣₂)\n (λ y p q → ∣ ∣ y ∣ , sym (rUnitₖ 1 (∣ y ∣ +ₖ ∣ y ∣)) ∙ cong₂ _+ₖ_ p q ∣₂)\n (funExt λ p → funExt λ q → cong ∣_∣₂ (ΣPathP (refl , (sym (lUnit _))))))\n\n *=∙ : (p q : 0ₖ 1 ≡ 0ₖ 1) → ∣ 0ₖ 1 , p ∣₂ * ∣ 0ₖ 1 , q ∣₂ ≡ ∣ 0ₖ 1 , p ∙ q ∣₂\n *=∙ p q = cong ∣_∣₂ (ΣPathP (refl , sym (∙≡+₁ p q)))\n\nisEvenNegsuc : (n : ℕ) → isEven (pos (suc n)) ≡ true → isEven (negsuc n) ≡ true\nisEvenNegsuc zero p = ⊥-rec (true≢false (sym p))\nisEvenNegsuc (suc n) p = p\n\n¬isEvenNegSuc : (n : ℕ) → isEven (pos (suc n)) ≡ false → isEven (negsuc n) ≡ false\n¬isEvenNegSuc zero p = refl\n¬isEvenNegSuc (suc n) p = p\n\nevenCharac : (x : Int) → isEven x ≡ true\n → Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂\n ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂\n ∣ (0ₖ 1 , refl) ∣₂\nevenCharac (pos zero) isisEven i = ∣ (0ₖ 1) , (rUnit refl (~ i)) ∣₂\nevenCharac (pos (suc zero)) isisEven = ⊥-rec (true≢false (sym isisEven))\nevenCharac (pos (suc (suc zero))) isisEven =\n cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (cong ∣_∣ ((lUnit loop (~ i)) ∙ loop)) (~ i))\n ∙ (ΣPathP (cong ∣_∣ loop , λ i j → ∣ (loop ∙ loop) (i ∨ j) ∣)))\nevenCharac (pos (suc (suc (suc n)))) isisEven =\n (λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos (suc n)) 2 i ∣₂)\n ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos (suc n))) (Kn→ΩKn+1 0 (pos 2)))\n ∙∙ (cong₂ _*_ (evenCharac (pos (suc n)) isisEven) (evenCharac 2 refl))\n\nevenCharac (negsuc zero) isisEven = ⊥-rec (true≢false (sym isisEven))\nevenCharac (negsuc (suc zero)) isisEven =\n cong ∣_∣₂ ((λ i → 0ₖ 1\n , λ i₁ → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) i₁)\n (inS ∣ compPath≡compPath' (sym loop) (sym loop) i i₁ ∣) (~ i))\n ∙ ΣPathP ((cong ∣_∣ (sym loop)) , λ i j → ∣ (sym loop ∙' sym loop) (i ∨ j) ∣))\nevenCharac (negsuc (suc (suc n))) isisEven =\n cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i)\n ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2))\n ∙∙ cong₂ _*_ (evenCharac (negsuc n) (isEvenNegsuc n isisEven)) (evenCharac -2 refl)\n\noddCharac : (x : Int) → isEven x ≡ false\n → Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂\n ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂\n ∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂\noddCharac (pos zero) isOdd = ⊥-rec (true≢false isOdd)\noddCharac (pos (suc zero)) isOdd i =\n ∣ (0ₖ 1 , λ j → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) j)\n (inS ∣ lUnit loop (~ i) j ∣) (~ i)) ∣₂\noddCharac (pos (suc (suc n))) isOdd =\n (λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos n) 2 i ∣₂)\n ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos n)) (Kn→ΩKn+1 0 2))\n ∙∙ cong₂ _*_ (oddCharac (pos n) isOdd) (evenCharac 2 refl)\noddCharac (negsuc zero) isOdd =\n cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (sym (cong ∣_∣ loop)) (~ i))\n ∙ ΣPathP (cong ∣_∣ (sym loop) , λ i j → ∣ hcomp (λ k → λ { (i = i0) → loop (~ j ∧ k)\n ; (i = i1) → loop j\n ; (j = i1) → base})\n (loop (j ∨ ~ i)) ∣))\noddCharac (negsuc (suc zero)) isOdd = ⊥-rec (true≢false isOdd)\noddCharac (negsuc (suc (suc n))) isOdd =\n cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i)\n ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2))\n ∙∙ cong₂ _*_ (oddCharac (negsuc n) (¬isEvenNegSuc n isOdd)) (evenCharac (negsuc 1) refl)\n\n{- We now have all we need to establish the Iso -}\nBool→ΣKₙNilpot : Bool → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂\nBool→ΣKₙNilpot false = ∣ 0ₖ 1 , cong ∣_∣ loop ∣₂\nBool→ΣKₙNilpot true = ∣ 0ₖ 1 , refl ∣₂\n\ntestIso : Iso ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Bool\nfun testIso = sRec isSetBool ΣKₙNilpot→Bool\ninv testIso = Bool→ΣKₙNilpot\nrightInv testIso false = refl\nrightInv testIso true = refl\nleftInv testIso =\n sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)\n (uncurry (trElim\n (λ _ → isGroupoidΠ λ _ → isOfHLevelPlus {n = 1} 2 (setTruncIsSet _ _))\n (toPropElim (λ _ → isPropΠ (λ _ → setTruncIsSet _ _))\n (λ p → path p (isEven (ΩKn+1→Kn 0 p)) refl))))\n where\n path : (p : 0ₖ 1 ≡ 0ₖ 1) (b : Bool) → (isEven (ΩKn+1→Kn 0 p) ≡ b)\n → Bool→ΣKₙNilpot (ΣKₙNilpot→Bool (∣ base ∣ , p)) ≡ ∣ ∣ base ∣ , p ∣₂\n path p false q =\n (cong Bool→ΣKₙNilpot q)\n ∙∙ sym (oddCharac (ΩKn+1→Kn 0 p) q)\n ∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , rightInv (Iso-Kn-ΩKn+1 0) p i\n path p true q =\n cong Bool→ΣKₙNilpot q\n ∙∙ sym (evenCharac (ΩKn+1→Kn 0 p) q)\n ∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , rightInv (Iso-Kn-ΩKn+1 0) p i\n\n\nH²-𝕂²≅Bool : GroupIso (coHomGr 2 KleinBottle) BoolGroup\nH²-𝕂²≅Bool = invGroupIso (≅Bool theIso)\n where\n theIso : Iso _ _\n theIso =\n compIso (setTruncIso\n (compIso (characFunSpace𝕂² (coHomK 2))\n (Σ-cong-iso-snd\n λ x → Σ-cong-iso-snd\n λ p → Σ-cong-iso-snd\n λ q → (movePathIso p q (isCommΩK-based 2 x)))))\n (compIso Iso-H²-𝕂²₁\n (compIso\n Iso-H²-𝕂²₂\n testIso))\n\n------ Hⁿ(𝕂²) ≅ 0 , n ≥ 3 ------\nisContrHⁿ-𝕂² : (n : ℕ) → isContr (coHom (3 + n) KleinBottle)\nisContrHⁿ-𝕂² n =\n isOfHLevelRetractFromIso 0\n (setTruncIso (characFunSpace𝕂² (coHomK _)))\n isContrΣ-help\n where\n helper : (x : coHomK (3 + n))(p : x ≡ x) → (refl ≡ p) → (q : x ≡ x) → (refl ≡ q)\n → (P : p ∙∙ q ∙∙ p ≡ q)\n → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂\n ∣ x , p , q , P ∣₂\n ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂\n helper =\n trElim (λ _ → isProp→isOfHLevelSuc (4 + n) (isPropΠ4 λ _ _ _ _ → isPropΠ λ _ → setTruncIsSet _ _))\n (sphereToPropElim _ (λ _ → isPropΠ4 λ _ _ _ _ → isPropΠ λ _ → setTruncIsSet _ _)\n λ p → J (λ p _ → (q : 0ₖ _ ≡ 0ₖ _) → (refl ≡ q)\n → (P : p ∙∙ q ∙∙ p ≡ q)\n → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂\n ∣ 0ₖ _ , p , q , P ∣₂\n ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂)\n λ q → J (λ q _ → (P : refl ∙∙ q ∙∙ refl ≡ q)\n → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂\n ∣ 0ₖ _ , refl , q , P ∣₂\n ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂)\n λ P → trRec (isProp→isOfHLevelSuc n (setTruncIsSet _ _))\n (λ P≡rUnitrefl i → ∣ 0ₖ (3 + n) , refl , refl , P≡rUnitrefl i ∣₂)\n (fun (PathIdTruncIso _)\n (isContr→isProp (isConnectedPath _ (isConnectedPathKn (2 + n) _ _)\n (refl ∙∙ refl ∙∙ refl) refl)\n ∣ P ∣ ∣ sym (rUnit refl) ∣)))\n\n isContrΣ-help : isContr ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂\n fst isContrΣ-help = ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂\n snd isContrΣ-help =\n sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)\n λ {(x , p , q , P)\n → trRec (isProp→isOfHLevelSuc (suc n) (setTruncIsSet _ _))\n (λ pId → trRec (isProp→isOfHLevelSuc (suc n) (setTruncIsSet _ _))\n (λ qId → sym (helper x p pId q qId P))\n (fun (PathIdTruncIso (2 + n))\n (isContr→isProp (isConnectedPathKn (2 + n) _ _) ∣ refl ∣ ∣ q ∣)))\n (fun (PathIdTruncIso (2 + n))\n (isContr→isProp (isConnectedPathKn (2 + n) _ _) ∣ refl ∣ ∣ p ∣))}\n\nHⁿ⁺³-𝕂²≅0 : (n : ℕ) → GroupIso (coHomGr (3 + n) KleinBottle) UnitGroup\nHⁿ⁺³-𝕂²≅0 n = contrGroupIsoUnit (isContrHⁿ-𝕂² n)\n", "meta": {"hexsha": "8b9da05a701dd7e75f911e0d16fa84453396b849", "size": 21362, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/ZCohomology/Groups/KleinBottle.agda", "max_stars_repo_name": "LuuBluum/cubical", "max_stars_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621", "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": "Cubical/ZCohomology/Groups/KleinBottle.agda", "max_issues_repo_name": "LuuBluum/cubical", "max_issues_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621", "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": "Cubical/ZCohomology/Groups/KleinBottle.agda", "max_forks_repo_name": "LuuBluum/cubical", "max_forks_repo_head_hexsha": "ce8fe04f9c5d2c9faf8690885c1b702434626621", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-12T20:08:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-12T20:08:45.000Z", "avg_line_length": 46.9494505495, "max_line_length": 141, "alphanum_fraction": 0.5052897669, "num_tokens": 9306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195385342972, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.3813907531301986}} {"text": "module posts.agda.typed-protocols where\n\nopen import Relation.Binary.PropositionalEquality as Eq\nopen Eq using (_≡_; refl)\nopen import Relation.Nullary using (¬_)\nopen import Data.Empty using (⊥; ⊥-elim)\nopen import Data.List\nopen import Data.Nat\nopen import Data.Unit using (⊤; tt)\nopen import Function.Base using (_$_; _|>_)\n\n\n-- Client / server roles\n-- \ndata PeerRole : Set where\n ClientRole : PeerRole\n ServerRole : PeerRole\n\ndual-role : PeerRole → PeerRole\ndual-role ClientRole = ServerRole\ndual-role ServerRole = ClientRole\n\n-- Objective agency: who is responsible for sending next message.\n--\ndata Agency : Set where\n ClientAgency : Agency\n ServerAgency : Agency\n NobodyAgency : Agency\n\n\n-- Relative agency to the current 'PeerRole'. It answer the question: are we\n-- responsible for sending next message?\n--\ndata RelativeAgency : Set where\n WeHaveAgency : RelativeAgency\n TheyHaveAgency : RelativeAgency\n NobodyHasAgency : RelativeAgency\n\n\nrelative : PeerRole → Agency → RelativeAgency\n\nrelative ClientRole ClientAgency = WeHaveAgency\nrelative ClientRole ServerAgency = TheyHaveAgency\nrelative ClientRole NobodyAgency = NobodyHasAgency\n\nrelative ServerRole ClientAgency = TheyHaveAgency\nrelative ServerRole ServerAgency = WeHaveAgency\nrelative ServerRole NobodyAgency = NobodyHasAgency\n\n\n-- 'relative' function obeys the following three exclusion lemmas:\n--\n-- * it is an absurd if client and server have agency\n-- * it is an absurd if 'WeHaveAgency' and the dual role terminated\n-- ('NobodyHasAgency')\n-- * it is an absurd if 'TheyHaveAgency' and the dual role terminated\n-- ('NobodyHasAgency')\n--\n-- Note that these lemmas are provided regardless of the protocol, unlike the\n-- Haskell implementation which requires to prove them for each protocol.\n\nexclusion-lemma-client-and-server-have-agency₁\n : ∀ {agency : Agency}\n {pr : PeerRole}\n → WeHaveAgency ≡ relative pr agency\n → WeHaveAgency ≡ relative (dual-role pr) agency\n → ⊥\nexclusion-lemma-client-and-server-have-agency₁\n {ClientAgency}\n {ClientRole}\n refl ()\nexclusion-lemma-client-and-server-have-agency₁\n {ServerAgency}\n {ServerRole}\n refl ()\n\n\nexclusion-lemma-client-and-server-have-agency₂\n : ∀ {agency : Agency}\n {pr : PeerRole}\n → TheyHaveAgency ≡ relative pr agency\n → TheyHaveAgency ≡ relative (dual-role pr) agency\n → ⊥\nexclusion-lemma-client-and-server-have-agency₂\n {ServerAgency}\n {ClientRole}\n refl ()\nexclusion-lemma-client-and-server-have-agency₂\n {ClientAgency}\n {ServerRole}\n refl ()\n\n\nexclusion-lemma-we-have-agency-and-nobody-has-agency\n : ∀ {agency : Agency}\n {pr : PeerRole}\n {pr' : PeerRole}\n → WeHaveAgency ≡ relative pr agency\n → NobodyHasAgency ≡ relative pr' agency\n → ⊥\nexclusion-lemma-we-have-agency-and-nobody-has-agency\n {ClientAgency}\n {ClientRole}\n {ServerRole}\n refl ()\nexclusion-lemma-we-have-agency-and-nobody-has-agency\n {ServerAgency}\n {ServerRole}\n {ClientRole}\n refl ()\n\n\nexclusion-lemma-they-have-agency-and-nobody-has-agency\n : ∀ {agency : Agency}\n {pr : PeerRole}\n {pr' : PeerRole}\n → TheyHaveAgency ≡ relative pr agency\n → NobodyHasAgency ≡ relative pr' agency\n → ⊥\nexclusion-lemma-they-have-agency-and-nobody-has-agency\n {ServerAgency}\n {ClientRole}\n {ServerRole}\n refl ()\nexclusion-lemma-they-have-agency-and-nobody-has-agency\n {ClientAgency}\n {ServerRole}\n {ClientRole}\n refl ()\n\n\n-----------\n-- Peer API\n--\n\n\n-- We index each primitive with 'IsPipelined'\n--\ndata IsPipelined : Set where\n Pipelined : IsPipelined\n NonPipelined : IsPipelined\n\n\n-- Promised protocol transition\n--\ndata Trans (ps : Set) : Set where\n Tr : ps → ps → Trans ps\n\n\n-- 'Peer' explicitly indexed by:\n-- * message type\n-- * objective protocol agency\n-- * peer role\n-- * return type\n-- * 'IsPipelined'\n-- * queue of unrealised transitions, due to pipelining\n-- * current state\n--\ndata Peer {ps : Set}\n (msg : ps → ps → Set)\n (agency : ps → Agency)\n (pr : PeerRole)\n (a : Set)\n : IsPipelined\n → List (Trans ps)\n → ps\n → Set where\n\n --\n -- non-pipelined primitives\n --\n\n -- non-pipelined send a message\n Yield : ∀ {st st' : ps}\n {pl : IsPipelined}\n → WeHaveAgency ≡ relative pr (agency st)\n → msg st st'\n → Peer msg agency pr a pl [] st'\n → Peer msg agency pr a pl [] st\n\n -- non-pipelined receive a message\n Await : ∀ {st : ps}\n {pl : IsPipelined}\n → TheyHaveAgency ≡ relative pr (agency st)\n → (∀ {st' : ps}\n → msg st st'\n → Peer msg agency pr a pl [] st'\n )\n → Peer msg agency pr a pl [] st\n\n -- protocol termination\n Done : ∀ {st : ps}\n {pl : IsPipelined}\n → NobodyHasAgency ≡ relative pr (agency st)\n → a\n → Peer msg agency pr a pl [] st\n\n --\n -- pipelining primitives\n --\n\n -- pipeline a single message\n YieldPipelined\n : ∀ {st st' st'' : ps}\n {q : List (Trans ps)}\n → WeHaveAgency ≡ relative pr (agency st)\n → msg st st'\n → Peer msg agency pr a Pipelined (q ∷ʳ Tr st' st'') st''\n → Peer msg agency pr a Pipelined q st\n\n -- partially collect a promissed transition\n Collect\n : ∀ {st st' st'' : ps}\n {q : List (Trans ps)}\n → TheyHaveAgency ≡ relative pr (agency st')\n → (∀ {stNext : ps}\n → msg st' stNext\n → Peer msg agency pr a Pipelined (Tr stNext st'' ∷ q) st\n )\n → Peer msg agency pr a Pipelined (Tr st' st'' ∷ q) st\n\n -- collect the identity transition\n CollectDone\n : ∀ {st : ps}\n {q : List (Trans ps)}\n → Peer msg agency pr a Pipelined q st\n → Peer msg agency pr a Pipelined (Tr st st ∷ q) st\n \n--------------\n-- PingPong v1\n--\n\n-- Protocol states\n--\ndata PingPong : Set where\n StIdle : PingPong\n StBusy : PingPong\n StDone : PingPong\n\n\n-- Agency of PingPong states\n--\npingPongAgency : PingPong → Agency\npingPongAgency StIdle = ClientAgency\npingPongAgency StBusy = ServerAgency\npingPongAgency StDone = NobodyAgency\n\n\n-- Protocol messages\n--\ndata PingPongMsg : ∀ (st st' : PingPong) → Set where\n MsgPing : PingPongMsg StIdle StBusy\n MsgPong : PingPongMsg StBusy StIdle\n MsgDone : PingPongMsg StIdle StDone\n\n--\n-- PingPong v1, examples\n--\n\n\n-- ping client which computes unit (tt : ⊤)\n--\nping : Peer PingPongMsg pingPongAgency ClientRole ⊤ NonPipelined [] StIdle\nping =\n Yield refl MsgPing\n $ await\n $ Yield refl MsgPing\n $ await\n $ Yield refl MsgDone\n $ Done refl tt\n where\n await : Peer PingPongMsg pingPongAgency ClientRole ⊤ NonPipelined [] StIdle\n → Peer PingPongMsg pingPongAgency ClientRole ⊤ NonPipelined [] StBusy\n await k = Await refl λ {MsgPong → k}\n\n\n-- pipelined client which computes unit (tt : ⊤)\n--\npipelinedPing\n : Peer PingPongMsg pingPongAgency ClientRole ⊤ Pipelined [] StIdle\npipelinedPing =\n YieldPipelined refl MsgPing\n $ YieldPipelined refl MsgPing\n $ YieldPipelined refl MsgPing\n $ collect\n $ collect\n $ collect\n $ Yield refl MsgDone\n $ Done refl tt\n where\n collect : ∀ {q : List (Trans PingPong)}\n → Peer PingPongMsg pingPongAgency ClientRole ⊤ Pipelined q StIdle\n → Peer PingPongMsg pingPongAgency ClientRole ⊤ Pipelined\n (Tr StBusy StIdle ∷ q) StIdle\n collect k = \n Collect refl λ {MsgPong → CollectDone k}\n\n\n--------------\n-- PingPong v2\n--\n-- The same states and agency as PingPong v1, but with additional 'MsgBusy'\n-- transition.\n\n\ndata PingPongMsg2 : ∀ (st st' : PingPong) → Set where\n MsgPingPong : ∀ {st st' : PingPong}\n → PingPongMsg st st' → PingPongMsg2 st st'\n MsgBusy : PingPongMsg2 StBusy StBusy\n\n-- we use unbounded recursion in 'pipelinedPing2'\n{-# NON_TERMINATING #-}\n\n-- pipelined ping client which computes the number of busy messages\n--\npipelinedPing2\n : Peer PingPongMsg2 pingPongAgency ClientRole ℕ Pipelined [] StIdle\npipelinedPing2 =\n YieldPipelined refl (MsgPingPong MsgPing)\n $ YieldPipelined refl (MsgPingPong MsgPing)\n $ YieldPipelined refl (MsgPingPong MsgPing)\n $ collect 0\n $ λ { n1 → collect n1\n λ { n2 → collect n2\n λ { n3 → Yield refl (MsgPingPong MsgDone)\n $ Done refl n3 }}}\n where\n collect : ∀ {q : List (Trans PingPong)}\n → ℕ\n → (ℕ → Peer PingPongMsg2 pingPongAgency ClientRole ℕ Pipelined q StIdle)\n → Peer PingPongMsg2 pingPongAgency ClientRole ℕ Pipelined\n (Tr StBusy StIdle ∷ q) StIdle\n collect n k =\n Collect refl \n λ { MsgBusy → collect (n + 1) k\n ; (MsgPingPong MsgPong) → CollectDone (k n)\n } \n\n------------------------\n-- Non-pipelined Duality\n--\n\n-- Termination witness\ndata Termination (ps : Set)\n (agency : ps → Agency)\n (a : Set)\n (b : Set)\n : Set where\n Terminated : ∀ {st : ps} {pr : PeerRole}\n → a\n → b\n → NobodyHasAgency ≡ relative pr (agency st)\n → NobodyHasAgency ≡ relative (dual-role pr) (agency st)\n → Termination ps agency a b\n\n\ntheorem-non-pipelined-duality\n : ∀ {ps : Set}\n {msg : ps → ps → Set}\n {agency : ps → Agency}\n {pr : PeerRole}\n {a : Set}\n {b : Set}\n {st : ps}\n → Peer msg agency pr a NonPipelined [] st\n → Peer msg agency (dual-role pr) b NonPipelined [] st\n → Termination ps agency a b\n\ntheorem-non-pipelined-duality (Yield _ msg k) (Await _ k') =\n theorem-non-pipelined-duality k (k' msg)\n\ntheorem-non-pipelined-duality (Await _ k) (Yield _ msg k') =\n theorem-non-pipelined-duality (k msg) k'\n\ntheorem-non-pipelined-duality (Done termA a) (Done termB b) =\n Terminated a b termA termB\n\n-- excluded cases\n\ntheorem-non-pipelined-duality (Yield weHaveAgency _ _)\n (Yield theyHaveAgency _ _) =\n ⊥-elim (exclusion-lemma-client-and-server-have-agency₁ weHaveAgency theyHaveAgency)\n\ntheorem-non-pipelined-duality (Await theyHaveAgency _)\n (Await weHaveAgency _) =\n ⊥-elim (exclusion-lemma-client-and-server-have-agency₂ theyHaveAgency weHaveAgency)\n\ntheorem-non-pipelined-duality (Yield weHaveAgency _ _)\n (Done nobodyHasAgency _) =\n ⊥-elim (exclusion-lemma-we-have-agency-and-nobody-has-agency\n weHaveAgency\n nobodyHasAgency)\n\ntheorem-non-pipelined-duality (Done nobodyHasAgency _)\n (Yield weHaveAgency _ _) =\n ⊥-elim (exclusion-lemma-we-have-agency-and-nobody-has-agency\n weHaveAgency\n nobodyHasAgency)\n\ntheorem-non-pipelined-duality (Await theyHaveAgency _)\n (Done nobodyHasAgency _) =\n ⊥-elim (exclusion-lemma-they-have-agency-and-nobody-has-agency\n theyHaveAgency\n nobodyHasAgency)\n\ntheorem-non-pipelined-duality (Done nobodyHasAgency _)\n (Await theyHaveAgency _) =\n ⊥-elim (exclusion-lemma-they-have-agency-and-nobody-has-agency\n theyHaveAgency\n nobodyHasAgency)\n\n\n--------------\n-- Un-pipeline\n--\n\n-- Transition queue which allows to transform pipelined 'Peer' into\n-- non-pipelined one. Pipelined messages are pushed to the end together with\n-- promised transitions to be collected.\n--\ndata PrQueue {ps : Set}\n (msg : ps → ps → Set)\n (agency : ps -> Agency)\n (pr : PeerRole)\n : ps\n → List (Trans ps)\n → ps\n → Set where\n\n ConsMsgQ : ∀ {st st' st'' : ps}\n {q : List (Trans ps)}\n → WeHaveAgency ≡ relative pr (agency st)\n → msg st st'\n → PrQueue msg agency pr st' q st''\n → PrQueue msg agency pr st q st''\n\n ConsTrQ : ∀ {st st' st'' : ps}\n {q : List (Trans ps)}\n → PrQueue msg agency pr st' q st''\n → PrQueue msg agency pr st (Tr st st' ∷ q) st''\n\n EmptyQ : ∀ {st : ps}\n → PrQueue msg agency pr st [] st\n\n\nsnockMsgQ : ∀ {ps : Set}\n {msg : ps → ps → Set}\n {agency : ps → Agency}\n {pr : PeerRole}\n {st st' st'' : ps}\n {q : List (Trans ps)}\n → WeHaveAgency ≡ relative pr (agency st')\n → msg st' st''\n → PrQueue msg agency pr st q st'\n → PrQueue msg agency pr st q st''\nsnockMsgQ tok msg (ConsMsgQ tok' msg' q) = ConsMsgQ tok' msg' (snockMsgQ tok msg q)\nsnockMsgQ tok msg (ConsTrQ q) = ConsTrQ (snockMsgQ tok msg q)\nsnockMsgQ tok msg EmptyQ = ConsMsgQ tok msg EmptyQ\n\n\nsnockTrQ : ∀ {ps : Set}\n {msg : ps → ps → Set}\n {agency : ps → Agency}\n {pr : PeerRole}\n {st st' st'' : ps}\n {q : List (Trans ps)}\n → PrQueue msg agency pr st q st'\n → PrQueue msg agency pr st (q ∷ʳ Tr st' st'') st''\nsnockTrQ (ConsMsgQ tok msg q) = ConsMsgQ tok msg (snockTrQ q)\nsnockTrQ (ConsTrQ q) = ConsTrQ (snockTrQ q)\nsnockTrQ EmptyQ = ConsTrQ EmptyQ\n\n\n-- Every pipelined peer can be transformed into non-pipelined one, by\n-- preserving the order of all transition.\n--\ntheorem-unpipeline\n : ∀ {ps : Set}\n {msg : ps → ps → Set}\n {agency : ps → Agency}\n {pr : PeerRole}\n {pl : IsPipelined}\n {a : Set}\n {stInit : ps}\n → Peer msg agency pr a pl [] stInit\n → Peer msg agency pr a NonPipelined [] stInit\ntheorem-unpipeline = go EmptyQ\n where\n go : ∀ {ps : Set}\n {msg : ps → ps → Set}\n {agency : ps → Agency}\n {pr : PeerRole}\n {pl : IsPipelined}\n {a : Set}\n {q : List (Trans ps)}\n {st st' : ps}\n → PrQueue msg agency pr st q st'\n → Peer msg agency pr a pl q st'\n → Peer msg agency pr a NonPipelined [] st\n\n -- non-piplined primitives\n go EmptyQ (Done tok a) = Done tok a\n go EmptyQ (Yield tok msg k) = Yield tok msg (go EmptyQ k)\n go EmptyQ (Await tok k) = Await tok λ {msg → go EmptyQ (k msg)}\n\n -- push msg and promised transition to back of the 'PrQueue'\n go q (YieldPipelined tok msg k) =\n go ( q\n |> snockMsgQ tok msg\n |> snockTrQ\n )\n k\n\n go (ConsMsgQ tok msg q) k =\n Yield tok msg (go q k)\n\n go (ConsTrQ q) (Collect tok k) =\n Await tok λ {msg → go (ConsTrQ q) (k msg)}\n\n go (ConsTrQ q) (CollectDone k) =\n go q k\n\n\n----------\n-- Duality\n--\n\n\ntheorem-pipelined-duality\n : ∀ {ps : Set}\n {msg : ps → ps → Set}\n {agency : ps → Agency}\n {pr : PeerRole}\n {pl : IsPipelined}\n {a : Set}\n {b : Set}\n {st : ps}\n → Peer msg agency pr a pl [] st\n → Peer msg agency (dual-role pr) b pl [] st\n → Termination ps agency a b\ntheorem-pipelined-duality a b =\n theorem-non-pipelined-duality (theorem-unpipeline a)\n (theorem-unpipeline b)\n", "meta": {"hexsha": "d025b34cc1a24f1b0e7b868a8422d0d8fcba44e2", "size": 15522, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "posts/agda/typed-protocols.agda", "max_stars_repo_name": "coot/homepage", "max_stars_repo_head_hexsha": "6773b88e8bbd1cfab98ed615855d9ae9c8859e0c", "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": "posts/agda/typed-protocols.agda", "max_issues_repo_name": "coot/homepage", "max_issues_repo_head_hexsha": "6773b88e8bbd1cfab98ed615855d9ae9c8859e0c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-02-18T21:05:46.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-18T21:05:51.000Z", "max_forks_repo_path": "posts/agda/typed-protocols.agda", "max_forks_repo_name": "coot/homepage", "max_forks_repo_head_hexsha": "6773b88e8bbd1cfab98ed615855d9ae9c8859e0c", "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": 28.5330882353, "max_line_length": 85, "alphanum_fraction": 0.5842030666, "num_tokens": 4369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195385342971, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.3813907531301985}} {"text": "------------------------------------------------------------------------\n-- Is-equivalence, defined in terms of contractible fibres\n------------------------------------------------------------------------\n\n-- Partly based on Voevodsky's work on univalent foundations.\n\n{-# OPTIONS --without-K --safe #-}\n\nopen import Equality\n\nmodule Equivalence.Contractible-preimages\n {e⁺} (eq : ∀ {a p} → Equality-with-J a p e⁺) where\n\nopen Derived-definitions-and-properties eq\n\nopen import Prelude as P hiding (id)\n\nopen import Bijection eq using (_↔_)\nopen import Equality.Decision-procedures eq\nopen import H-level eq as H-level\nopen import H-level.Closure eq\nopen import Preimage eq as Preimage using (_⁻¹_)\nopen import Surjection eq using (_↠_)\n\nprivate\n variable\n a b ℓ p q : Level\n A B : Type a\n f g : A → B\n\n------------------------------------------------------------------------\n-- Is-equivalence\n\n-- A function f is an equivalence if all preimages under f are\n-- contractible.\n\nIs-equivalence :\n {A : Type a} {B : Type b} →\n (A → B) → Type (a ⊔ b)\nIs-equivalence f = ∀ y → Contractible (f ⁻¹ y)\n\nabstract\n\n -- Is-equivalence f is a proposition, assuming extensional equality.\n\n propositional :\n Extensionality (a ⊔ b) (a ⊔ b) →\n {A : Type a} {B : Type b} (f : A → B) →\n Is-proposition (Is-equivalence f)\n propositional {a = a} ext f =\n Π-closure (lower-extensionality a lzero ext) 1 λ _ →\n Contractible-propositional ext\n\n -- If the domain is contractible and the codomain is propositional,\n -- then Is-equivalence f is contractible.\n\n sometimes-contractible :\n Extensionality (a ⊔ b) (a ⊔ b) →\n {A : Type a} {B : Type b} {f : A → B} →\n Contractible A → Is-proposition B →\n Contractible (Is-equivalence f)\n sometimes-contractible {a = a} ext A-contr B-prop =\n Π-closure (lower-extensionality a lzero ext) 0 λ _ →\n cojoin ext (Σ-closure 0 A-contr (λ _ → +⇒≡ B-prop))\n\n -- Is-equivalence f is not always contractible.\n\n not-always-contractible₁ :\n ∃ λ (A : Type a) → ∃ λ (B : Type b) → ∃ λ (f : A → B) →\n Is-proposition A × Contractible B ×\n ¬ Contractible (Is-equivalence f)\n not-always-contractible₁ =\n ⊥ ,\n ↑ _ ⊤ ,\n const (lift tt) ,\n ⊥-propositional ,\n ↑-closure 0 ⊤-contractible ,\n λ c → ⊥-elim (proj₁ (proj₁ (proj₁ c (lift tt))))\n\n not-always-contractible₂ :\n ∃ λ (A : Type a) → ∃ λ (B : Type b) → ∃ λ (f : A → B) →\n Contractible A × Is-set B ×\n ¬ Contractible (Is-equivalence f)\n not-always-contractible₂ =\n ↑ _ ⊤ ,\n ↑ _ Bool ,\n const (lift true) ,\n ↑-closure 0 ⊤-contractible ,\n ↑-closure 2 Bool-set ,\n λ c → Bool.true≢false (cong lower\n (proj₂ (proj₁ (proj₁ c (lift false)))))\n\n-- Is-equivalence respects extensional equality.\n\nrespects-extensional-equality :\n (∀ x → f x ≡ g x) →\n Is-equivalence f → Is-equivalence g\nrespects-extensional-equality f≡g f-eq = λ b →\n H-level.respects-surjection\n (_↔_.surjection (Preimage.respects-extensional-equality f≡g))\n 0\n (f-eq b)\n\n-- If f is an equivalence, then it has an inverse.\n\ninverse :\n {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} →\n Is-equivalence f → B → A\ninverse eq y = proj₁ (proj₁ (eq y))\n\nright-inverse-of :\n {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} →\n (eq : Is-equivalence f) → ∀ x → f (inverse eq x) ≡ x\nright-inverse-of eq x = proj₂ (proj₁ (eq x))\n\nabstract\n\n left-inverse-of :\n (eq : Is-equivalence f) → ∀ x → inverse eq (f x) ≡ x\n left-inverse-of {f = f} eq x =\n cong (proj₁ {B = λ x′ → f x′ ≡ f x}) (\n proj₁ (eq (f x)) ≡⟨ proj₂ (eq (f x)) (x , refl (f x)) ⟩∎\n (x , refl (f x)) ∎)\n\n-- All fibres of an equivalence over a given point are equal to a\n-- given fibre.\n\nirrelevance :\n {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} →\n (eq : Is-equivalence f) →\n ∀ y (p : f ⁻¹ y) → (inverse eq y , right-inverse-of eq y) ≡ p\nirrelevance eq y = proj₂ (eq y)\n\nabstract\n\n -- The two proofs left-inverse-of and right-inverse-of are\n -- related.\n\n left-right-lemma :\n (eq : Is-equivalence f) →\n ∀ x → cong f (left-inverse-of eq x) ≡ right-inverse-of eq (f x)\n left-right-lemma {f = f} eq x =\n lemma₁ f _ _ (lemma₂ (irrelevance eq (f x) (x , refl (f x))))\n where\n lemma₁ : {x y : A} (f : A → B) (p : x ≡ y) (q : f x ≡ f y) →\n refl (f y) ≡ trans (cong f (sym p)) q →\n cong f p ≡ q\n lemma₁ f = elim\n (λ {x y} p → ∀ q → refl (f y) ≡ trans (cong f (sym p)) q →\n cong f p ≡ q)\n (λ x q hyp →\n cong f (refl x) ≡⟨ cong-refl f ⟩\n refl (f x) ≡⟨ hyp ⟩\n trans (cong f (sym (refl x))) q ≡⟨ cong (λ p → trans (cong f p) q) sym-refl ⟩\n trans (cong f (refl x)) q ≡⟨ cong (λ p → trans p q) (cong-refl f) ⟩\n trans (refl (f x)) q ≡⟨ trans-reflˡ _ ⟩∎\n q ∎)\n\n lemma₂ : ∀ {f : A → B} {y} {f⁻¹y₁ f⁻¹y₂ : f ⁻¹ y}\n (p : f⁻¹y₁ ≡ f⁻¹y₂) →\n proj₂ f⁻¹y₂ ≡\n trans (cong f (sym (cong (proj₁ {B = λ x → f x ≡ y}) p)))\n (proj₂ f⁻¹y₁)\n lemma₂ {f = f} {y = y} =\n let pr = proj₁ {B = λ x → f x ≡ y} in\n elim {A = f ⁻¹ y}\n (λ {f⁻¹y₁ f⁻¹y₂} p →\n proj₂ f⁻¹y₂ ≡\n trans (cong f (sym (cong pr p))) (proj₂ f⁻¹y₁))\n (λ f⁻¹y →\n proj₂ f⁻¹y ≡⟨ sym $ trans-reflˡ _ ⟩\n trans (refl (f (proj₁ f⁻¹y))) (proj₂ f⁻¹y) ≡⟨ cong (λ p → trans p (proj₂ f⁻¹y)) (sym (cong-refl f)) ⟩\n trans (cong f (refl (proj₁ f⁻¹y))) (proj₂ f⁻¹y) ≡⟨ cong (λ p → trans (cong f p) (proj₂ f⁻¹y)) (sym sym-refl) ⟩\n trans (cong f (sym (refl (proj₁ f⁻¹y)))) (proj₂ f⁻¹y) ≡⟨ cong (λ p → trans (cong f (sym p)) (proj₂ f⁻¹y))\n (sym (cong-refl pr)) ⟩∎\n trans (cong f (sym (cong pr (refl f⁻¹y)))) (proj₂ f⁻¹y) ∎)\n\n right-left-lemma :\n (eq : Is-equivalence f) →\n ∀ x →\n cong (inverse eq) (right-inverse-of eq x) ≡\n left-inverse-of eq (inverse eq x)\n right-left-lemma {f = f} eq x =\n let f⁻¹ = inverse eq in\n subst\n (λ x → cong f⁻¹ (right-inverse-of eq x) ≡\n left-inverse-of eq (f⁻¹ x))\n (right-inverse-of eq x)\n (cong f⁻¹ (right-inverse-of eq (f (f⁻¹ x))) ≡⟨ cong (cong f⁻¹) $ sym $ left-right-lemma eq _ ⟩\n\n cong f⁻¹ (cong f (left-inverse-of eq (f⁻¹ x))) ≡⟨ cong-∘ f⁻¹ f _ ⟩\n\n cong (f⁻¹ ∘ f) (left-inverse-of eq (f⁻¹ x)) ≡⟨ cong-roughly-id (f⁻¹ ∘ f) (λ _ → true) (left-inverse-of eq _) _ _\n (λ z _ → left-inverse-of eq z) ⟩\n trans (left-inverse-of eq (f⁻¹ (f (f⁻¹ x))))\n (trans (left-inverse-of eq (f⁻¹ x))\n (sym (left-inverse-of eq (f⁻¹ x)))) ≡⟨ cong (trans _) $ trans-symʳ _ ⟩\n\n trans (left-inverse-of eq (f⁻¹ (f (f⁻¹ x)))) (refl _) ≡⟨ trans-reflʳ _ ⟩∎\n\n left-inverse-of eq (f⁻¹ (f (f⁻¹ x))) ∎)\n\nabstract\n\n -- If Σ-map P.id f is an equivalence, then f is also an equivalence.\n\n drop-Σ-map-id :\n {A : Type a} {P : A → Type p} {Q : A → Type q}\n (f : ∀ {x} → P x → Q x) →\n Is-equivalence {A = Σ A P} {B = Σ A Q} (Σ-map P.id f) →\n ∀ x → Is-equivalence (f {x = x})\n drop-Σ-map-id {p = ℓp} {q = ℓq} {A = A} {P = P} {Q = Q} f eq x z =\n H-level.respects-surjection surj 0 (eq (x , z))\n where\n map-f : Σ A P → Σ A Q\n map-f = Σ-map P.id f\n\n to-P : ∀ {x y} {p : ∃ Q} → (x , f y) ≡ p → Type (ℓp ⊔ ℓq)\n to-P {y = y} {p} _ = ∃ λ y′ → f y′ ≡ proj₂ p\n\n to : map-f ⁻¹ (x , z) → f ⁻¹ z\n to ((x′ , y) , eq) = elim¹ to-P (y , refl (f y)) eq\n\n from : f ⁻¹ z → map-f ⁻¹ (x , z)\n from (y , eq) = (x , y) , cong (_,_ x) eq\n\n to∘from : ∀ p → to (from p) ≡ p\n to∘from (y , eq) = elim¹\n (λ {z′} (eq : f y ≡ z′) →\n _≡_ {A = ∃ λ (y : P x) → f y ≡ z′}\n (elim¹ to-P (y , refl (f y)) (cong (_,_ x) eq))\n (y , eq))\n (elim¹ to-P (y , refl (f y)) (cong (_,_ x) (refl (f y))) ≡⟨ cong (elim¹ to-P (y , refl (f y))) $\n cong-refl (_,_ x) ⟩\n elim¹ to-P (y , refl (f y)) (refl (x , f y)) ≡⟨ elim¹-refl to-P _ ⟩∎\n (y , refl (f y)) ∎)\n eq\n\n surj : map-f ⁻¹ (x , z) ↠ f ⁻¹ z\n surj = record\n { logical-equivalence = record { to = to; from = from }\n ; right-inverse-of = to∘from\n }\n\n -- A \"computation\" rule for drop-Σ-map-id.\n\n inverse-drop-Σ-map-id :\n {A : Type a} {P : A → Type p} {Q : A → Type q}\n {f : ∀ {x} → P x → Q x} {x : A} {y : Q x}\n {eq : Is-equivalence {A = Σ A P} {B = Σ A Q} (Σ-map P.id f)} →\n inverse (drop-Σ-map-id f eq x) y ≡\n subst P (cong proj₁ (right-inverse-of eq (x , y)))\n (proj₂ (inverse eq (x , y)))\n inverse-drop-Σ-map-id\n {P = P} {Q = Q} {f = f} {x = x} {y = y} {eq = eq} =\n\n let lemma = elim¹\n (λ {q′} eq →\n cong proj₁\n (proj₂ (other-singleton-contractible (Σ-map P.id f p′))\n (q′ , eq)) ≡\n eq)\n (cong proj₁\n (proj₂ (other-singleton-contractible (Σ-map P.id f p′))\n (Σ-map P.id f p′ , refl _)) ≡⟨ cong (cong proj₁) $\n other-singleton-contractible-refl _ ⟩\n\n cong proj₁ (refl _) ≡⟨ cong-refl _ ⟩∎\n\n refl _ ∎)\n _\n in\n proj₁\n (subst\n (λ ((_ , y) , _) → f ⁻¹ y)\n (proj₂\n (other-singleton-contractible (Σ-map P.id f p′))\n (q′ , right-inverse-of eq q′))\n (proj₂ p′ , refl _)) ≡⟨ cong proj₁ $ push-subst-pair _ _ ⟩\n\n subst\n (λ ((x , _) , _) → P x)\n (proj₂\n (other-singleton-contractible (Σ-map P.id f p′))\n (q′ , right-inverse-of eq q′))\n (proj₂ p′) ≡⟨ trans (subst-∘ _ _ _) (subst-∘ _ _ _) ⟩\n\n subst P\n (cong proj₁ $ cong proj₁ $\n proj₂\n (other-singleton-contractible (Σ-map P.id f p′))\n (q′ , right-inverse-of eq q′))\n (proj₂ p′) ≡⟨ cong (λ eq → subst P (cong proj₁ eq) (proj₂ p′))\n lemma ⟩∎\n subst P\n (cong proj₁ (right-inverse-of eq q′))\n (proj₂ p′) ∎\n where\n q′ : ∃ Q\n q′ = x , y\n\n p′ : ∃ P\n p′ = inverse eq q′\n\n------------------------------------------------------------------------\n-- _≃_\n\n-- A notion of equivalence.\n\ninfix 4 _≃_\n\n_≃_ : Type a → Type b → Type (a ⊔ b)\nA ≃ B = ∃ λ (f : A → B) → Is-equivalence f\n\n-- An identity equivalence.\n\nid : A ≃ A\nid = P.id , singleton-contractible\n\n-- Equalities can be converted to equivalences.\n\n≡⇒≃ : A ≡ B → A ≃ B\n≡⇒≃ = elim (λ {A B} _ → A ≃ B) (λ _ → id)\n\n-- If ≡⇒≃ is applied to reflexivity, then the result is equal to id.\n\n≡⇒≃-refl : ≡⇒≃ (refl A) ≡ id\n≡⇒≃-refl = elim-refl (λ {A B} _ → A ≃ B) (λ _ → id)\n\n-- Univalence for fixed types.\n\nUnivalence′ : (A B : Type ℓ) → Type (lsuc ℓ)\nUnivalence′ A B = Is-equivalence (≡⇒≃ {A = A} {B = B})\n\n-- Univalence.\n\nUnivalence : ∀ ℓ → Type (lsuc ℓ)\nUnivalence ℓ = {A B : Type ℓ} → Univalence′ A B\n", "meta": {"hexsha": "9c5b9bd23709eb8706683ad4fa20972b1f13b004", "size": 11567, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Equivalence/Contractible-preimages.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/Equivalence/Contractible-preimages.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/Equivalence/Contractible-preimages.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": 34.1209439528, "max_line_length": 130, "alphanum_fraction": 0.4666724302, "num_tokens": 4117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300449389326, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.38137776672287654}} {"text": "-- This file needs to be rewritten so that Rng's are defined as a\n-- record (as is the case for other algebraic structures like\n-- rings). As this file isn't used for anything at the moment this\n-- rewrite has been postponed.\n\n{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.Experiments.Rng where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.SIP\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Structures.Axioms\nopen import Cubical.Structures.Auto\nopen import Cubical.Structures.Macro\nopen import Cubical.Algebra.Semigroup hiding (⟨_⟩)\nopen import Cubical.Algebra.AbGroup\n\nprivate\n variable\n ℓ ℓ' : Level\n\nmodule _ {ℓ} where\n rawRngDesc : Desc ℓ\n rawRngDesc = autoDesc (λ (X : Type ℓ) → (X → X → X) × (X → X → X))\n\n open Macro ℓ rawRngDesc public renaming\n ( structure to RawRngStructure\n ; equiv to RawRngEquivStr\n ; univalent to rawRngUnivalentStr\n )\n\nRngAxioms : (X : Type ℓ) (s : RawRngStructure X) → Type ℓ\nRngAxioms X (_·_ , _+_) =\n AbGroupΣTheory.AbGroupAxioms X _·_ ×\n SemigroupΣTheory.SemigroupAxioms X _+_ ×\n ((x y z : X) → x · (y + z) ≡ (x · y) + (x · z)) × ((x y z : X) → (x + y) · z ≡ (x · z) + (y · z))\n\nRngStructure : Type ℓ → Type ℓ\nRngStructure = AxiomsStructure RawRngStructure RngAxioms\n\nRng : Type (ℓ-suc ℓ)\nRng {ℓ} = TypeWithStr ℓ RngStructure\n\nRngEquivStr : StrEquiv RngStructure ℓ\nRngEquivStr = AxiomsEquivStr RawRngEquivStr RngAxioms\n\nisPropRngAxioms : (X : Type ℓ) (s : RawRngStructure X) → isProp (RngAxioms X s)\nisPropRngAxioms X (_·_ , _+_) = isPropΣ (AbGroupΣTheory.isPropAbGroupAxioms X _·_)\n λ _ → isPropΣ (SemigroupΣTheory.isPropSemigroupAxioms X _+_)\n λ { (isSetX , _) → isPropΣ (isPropΠ3 (λ _ _ _ → isSetX _ _))\n λ _ → isPropΠ3 (λ _ _ _ → isSetX _ _)}\n\nrngUnivalentStr : UnivalentStr {ℓ} RngStructure RngEquivStr\nrngUnivalentStr = axiomsUnivalentStr _ isPropRngAxioms rawRngUnivalentStr\n\nRngPath : (M N : Rng {ℓ}) → (M ≃[ RngEquivStr ] N) ≃ (M ≡ N)\nRngPath = SIP rngUnivalentStr\n", "meta": {"hexsha": "62d261172facde73bc8391faf7be9fb053d49a5e", "size": 2162, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Experiments/Rng.agda", "max_stars_repo_name": "knrafto/cubical", "max_stars_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "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": "Cubical/Experiments/Rng.agda", "max_issues_repo_name": "knrafto/cubical", "max_issues_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "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": "Cubical/Experiments/Rng.agda", "max_forks_repo_name": "knrafto/cubical", "max_forks_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "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.4426229508, "max_line_length": 99, "alphanum_fraction": 0.6822386679, "num_tokens": 760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.38137377759292146}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import lib.Basics\nopen import lib.NType2\nopen import lib.PathFunctor\nopen import lib.PathGroupoid\n\nopen import lib.types.Bool\nopen import lib.types.IteratedSuspension\nopen import lib.types.LoopSpace\nopen import lib.types.Nat\nopen import lib.types.Paths\nopen import lib.types.Pi\nopen import lib.types.Pointed\nopen import lib.types.Sigma\nopen import lib.types.Suspension\nopen import lib.types.TLevel\nopen import lib.types.Unit\n\nopen import nicolai.pseudotruncations.Preliminary-definitions\nopen import nicolai.pseudotruncations.Liblemmas\nopen import nicolai.pseudotruncations.SeqColim\nopen import nicolai.pseudotruncations.wconstSequence\n\n\nmodule nicolai.pseudotruncations.PseudoTruncs where\n\n\n{- Definition of the Pseudo-truncation -}\nmodule _ {i} where\n\n private\n data #Pseudotrunc-aux (n : ℕ) (A : Type i) : Type i where\n #point : A → #Pseudotrunc-aux n A\n #hub : (r : Sphere' n → A) → #Pseudotrunc-aux n A\n\n data #Pseudotrunc (n : ℕ) (A : Type i) : Type i where\n #trick-aux : #Pseudotrunc-aux n A → (Unit → Unit) → #Pseudotrunc n A\n\n Pseudo_-1-trunc : (n : ℕ) (A : Type i) → Type i\n Pseudo_-1-trunc = #Pseudotrunc\n\n point_-1 : {A : Type i} → (n : ℕ) → A → Pseudo n -1-trunc A\n point_-1 {A} n a = #trick-aux (#point a) _\n\n hub_-1 : {A : Type i} (n : ℕ) (r : Sphere' n → A) → Pseudo n -1-trunc A\n hub_-1 {A} n r = #trick-aux (#hub r) _\n\n\n postulate\n spoke_-1 : {A : Type i} (n : ℕ) (r : Sphere' n → A) (x : Sphere' n)\n → point n -1 (r x) == hub n -1 r\n\n {- The induction principle -}\n module PseudotruncInduction\n {A : Type i} (n : ℕ) {j}\n {P : Pseudo n -1-trunc A → Type j}\n (Point-1 : (a : A) → P (point n -1 a))\n (Hub-1 : (r : Sphere' n → A) → P (hub n -1 r))\n (Spoke-1 : (r : Sphere' n → A) → (x : Sphere' n)\n → Point-1 (r x) == Hub-1 r [ P ↓ spoke n -1 r x ])\n where\n\n f : Π (Pseudo n -1-trunc A) P\n f = f-aux phantom where\n f-aux : Phantom Spoke-1 → Π (Pseudo n -1-trunc A) P\n f-aux phantom (#trick-aux (#point x) _) = Point-1 x\n f-aux phantom (#trick-aux (#hub r) _) = Hub-1 r\n\n postulate\n pathβ : (r : Sphere' {i} n → A)\n → (x : Sphere' {i} n)\n → apd f (spoke n -1 r x) == Spoke-1 r x\n\n\nopen PseudotruncInduction public renaming\n (f to Pseudotrunc-ind ; pathβ to Pseudotrunc-ind-pathβ)\n\n\n{- We derive the recursion principle from the induction principle -}\nmodule PseudotruncRecursion\n {i j} {A : Type i} \n {P : Type j} (n : ℕ)\n (Point-1 : A → P)\n (Hub-1 : (r : Sphere' {i} n → A) → P)\n (Spoke-1 : (r : Sphere' n → A) (x : Sphere' n) → Point-1 (r x) == Hub-1 r)\n where\n\n rec : Pseudo n -1-trunc A → P\n rec = Pseudotrunc-ind n {P = λ _ → P} Point-1 Hub-1\n (λ r x → from-transp\n (λ _ → P)\n (spoke n -1 r x)\n ((transport (λ _ → P) (spoke n -1 r x) (Point-1 (r x)))\n =⟨ transport-const-fam (spoke n -1 r x) (Point-1 (r x)) ⟩\n Point-1 (r x)\n =⟨ Spoke-1 r x ⟩\n Hub-1 r\n ∎))\n\nopen PseudotruncRecursion public renaming (rec to Pseudotrunc-rec)\n\n\n\n{- A lemma that will be important later: any map from\n the sphere, composed with the points constructor,\n is null. -}\n \nopen import nicolai.pseudotruncations.pointed-O-Sphere\nopen import nicolai.pseudotruncations.LoopsAndSpheres\nopen null\n\nmodule _ {i} {A : Type i} (n : ℕ) where\n\n from-sphere-null : (g : Sphere' {i} n → A)\n → isNull (point n -1 (g (nor' n))) ((point n -1) ∘ g)\n from-sphere-null g x = point n -1 (g x)\n =⟨ spoke n -1 g x ⟩\n hub n -1 g\n =⟨ ! (spoke n -1 g (nor' n)) ⟩\n point n -1 (g (nor' n))\n ∎\n\nmodule cmp-nll {i} { : Ptd i} (n : ℕ) (g : ⊙Sphere' {i} n →̇ Â) where\n\n {- Pointed version of first constructor -}\n -- points∙ :  →̇ (Pseudo n -1-trunc (fst Â) , point n -1 (snd Â))\n -- points∙ = point n -1 , idp\n\n from-sphere-null∙ : isNulld ((point n -1 , idp) ⊙∘ g)\n from-sphere-null∙ = λ x → \n point n -1 ((fst g) x)\n =⟨ spoke n -1 (fst g) x ⟩\n hub n -1 (fst g)\n =⟨ ! (spoke n -1 (fst g) (nor' n)) ⟩\n point n -1 ((fst g) (nor' n))\n =⟨ ap (point n -1) (snd g) ⟩\n point n -1 (snd Â)\n ∎\n\n {- Unfortunately, we will need this lemma not for maps\n g : Sphere' (S n) → A,\n but we will need it for maps\n g : Susp (Sphere' n) → A,\n and Sphere' (S n) is NOT judgmentally equal to Susp (Sphere' n).\n We have to give a second proof. -}\n\nmodule cmp-nll' {i} { : Ptd i} (n : ℕ) (g : ⊙Susp (⊙Sphere' {i} n) →̇ Â) where\n\n {- \"translate\" equivalence -}\n tr≃⊙ : ⊙Sphere' {i} (S n) ⊙≃ ⊙Susp (⊙Sphere' {i} n) \n tr≃⊙ = coe-equiv∙ (susp'-switch n)\n\n tr≃ : Sphere' {i} (S n) ≃ fst (⊙Susp (⊙Sphere' {i} n)) \n tr≃ = fst (fst tr≃⊙) , snd tr≃⊙\n\n tr–̇> : (⊙Sphere' {i} (S n)) →̇ ⊙Susp (⊙Sphere' {i} n) \n tr–̇> = fst tr≃⊙ -- –> (fst (fst tr-eq) , snd tr-eq) , {!!}\n\n from-sphere-null'∙ : isNulld ((point S n -1 , idp) ⊙∘ g)\n from-sphere-null'∙ = λ x → \n\n fst ((point S n -1 , idp) ⊙∘ g) x\n =⟨ ap (fst ((point S n -1 , idp) ⊙∘ g)) (! (<–-inv-r tr≃ x)) ⟩\n fst ((point S n -1 , idp) ⊙∘ g) (–> tr≃ (<– tr≃ x))\n =⟨ cmp-nll.from-sphere-null∙ {i} {Â} (S n) (g ⊙∘ tr–̇>) (<– tr≃ x) ⟩ \n point S n -1 (snd Â)\n ∎ \n\n", "meta": {"hexsha": "1a7a8510aedc9237aa5a4907dcac17c749ab89f8", "size": 5627, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "nicolai/pseudotruncations/PseudoTruncs.agda", "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolai/pseudotruncations/PseudoTruncs.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": "nicolai/pseudotruncations/PseudoTruncs.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": 33.1, "max_line_length": 81, "alphanum_fraction": 0.5198151768, "num_tokens": 2085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.38137377759292146}} {"text": "{-# OPTIONS --without-K --exact-split --allow-unsolved-metas #-}\n\nmodule 21-image where\n\nimport 20-sequences\nopen 20-sequences public\n\n{- We give the formal specification of propositional truncation. -}\n\nprecomp-Prop :\n { l1 l2 l3 : Level} {A : UU l1} (P : hProp l2) →\n (A → type-Prop P) → (Q : hProp l3) →\n (type-Prop P → type-Prop Q) → A → type-Prop Q\nprecomp-Prop P f Q g = g ∘ f\n\nuniversal-property-propositional-truncation :\n ( l : Level) {l1 l2 : Level} {A : UU l1} (P : hProp l2) →\n ( A → type-Prop P) → UU (lsuc l ⊔ l1 ⊔ l2)\nuniversal-property-propositional-truncation l P f =\n (Q : hProp l) → is-equiv (precomp-Prop P f Q)\n\nuniversal-property-propositional-truncation' :\n ( l : Level) {l1 l2 : Level} {A : UU l1} (P : hProp l2) →\n ( A → type-Prop P) → UU (lsuc l ⊔ l1 ⊔ l2)\nuniversal-property-propositional-truncation' l {A = A} P f =\n (Q : hProp l) → (A → type-Prop Q) → (type-Prop P → type-Prop Q)\n\nuniversal-property-propositional-truncation-simplify :\n { l1 l2 : Level} {A : UU l1} (P : hProp l2)\n ( f : A → type-Prop P) →\n ( (l : Level) → universal-property-propositional-truncation' l P f) →\n ( (l : Level) → universal-property-propositional-truncation l P f)\nuniversal-property-propositional-truncation-simplify P f up-P l Q =\n is-equiv-is-prop\n ( is-prop-Π (λ x → is-prop-type-Prop Q))\n ( is-prop-Π (λ x → is-prop-type-Prop Q))\n ( up-P l Q)\n \nprecomp-Π-Prop :\n { l1 l2 l3 : Level} {A : UU l1} (P : hProp l2) →\n ( f : A → type-Prop P) (Q : type-Prop P → hProp l3) →\n ( g : (p : type-Prop P) → type-Prop (Q p)) → (x : A) → type-Prop (Q (f x))\nprecomp-Π-Prop P f Q g x = g (f x)\n\ndependent-universal-property-propositional-truncation :\n ( l : Level) {l1 l2 : Level} {A : UU l1} (P : hProp l2) →\n ( A → type-Prop P) → UU (lsuc l ⊔ l1 ⊔ l2)\ndependent-universal-property-propositional-truncation l P f =\n (Q : type-Prop P → hProp l) → is-equiv (precomp-Π-Prop P f Q)\n\n{- We introduce the image inclusion of a map. -}\n\nprecomp-emb :\n { l1 l2 l3 l4 : Level} {X : UU l1} {A : UU l2} (f : A → X)\n {B : UU l3} ( i : B ↪ X) (q : hom-slice f (map-emb i)) →\n {C : UU l4} ( j : C ↪ X) (r : hom-slice (map-emb i) (map-emb j)) →\n hom-slice f (map-emb j)\nprecomp-emb f i q j r =\n pair\n ( ( map-hom-slice (map-emb i) (map-emb j) r) ∘\n ( map-hom-slice f (map-emb i) q))\n ( ( triangle-hom-slice f (map-emb i) q) ∙h\n ( ( triangle-hom-slice (map-emb i) (map-emb j) r) ·r\n ( map-hom-slice f (map-emb i) q)))\n\nis-prop-hom-slice :\n { l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →\n { B : UU l3} (i : B ↪ X) → is-prop (hom-slice f (map-emb i))\nis-prop-hom-slice {X = X} f i =\n is-prop-is-equiv\n ( (x : X) → fib f x → fib (map-emb i) x)\n ( fiberwise-hom-hom-slice f (map-emb i))\n ( is-equiv-fiberwise-hom-hom-slice f (map-emb i))\n ( is-prop-Π\n ( λ x → is-prop-Π\n ( λ p → is-prop-map-is-emb (map-emb i) (is-emb-map-emb i) x)))\n\nuniversal-property-image :\n ( l : Level) {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →\n { B : UU l3} (i : B ↪ X) (q : hom-slice f (map-emb i)) →\n UU (lsuc l ⊔ l1 ⊔ l2 ⊔ l3)\nuniversal-property-image l {X = X} f i q =\n ( C : UU l) (j : C ↪ X) → is-equiv (precomp-emb f i q j)\n\nuniversal-property-image' :\n ( l : Level) {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →\n { B : UU l3} (i : B ↪ X) (q : hom-slice f (map-emb i)) →\n UU (lsuc l ⊔ l1 ⊔ l2 ⊔ l3)\nuniversal-property-image' l {X = X} f i q =\n ( C : UU l) (j : C ↪ X) →\n hom-slice f (map-emb j) → hom-slice (map-emb i) (map-emb j)\n\nuniversal-property-image-universal-property-image' :\n ( l : Level) {l1 l2 l3 : Level} {X : UU l1} {A : UU l2} (f : A → X) →\n { B : UU l3} (i : B ↪ X) (q : hom-slice f (map-emb i)) →\n universal-property-image' l f i q → universal-property-image l f i q\nuniversal-property-image-universal-property-image' l f i q up' C j =\n is-equiv-is-prop\n ( is-prop-hom-slice (map-emb i) j)\n ( is-prop-hom-slice f j)\n ( up' C j)\n \n\n", "meta": {"hexsha": "c5e80facfd6612ae63401016388fd6c7d91fa432", "size": 3955, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Agda/21-image.agda", "max_stars_repo_name": "tadejpetric/HoTT-Intro", "max_stars_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_stars_repo_licenses": ["CC-BY-4.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": "Agda/21-image.agda", "max_issues_repo_name": "tadejpetric/HoTT-Intro", "max_issues_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_issues_repo_licenses": ["CC-BY-4.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": "Agda/21-image.agda", "max_forks_repo_name": "tadejpetric/HoTT-Intro", "max_forks_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.0288461538, "max_line_length": 76, "alphanum_fraction": 0.5737041719, "num_tokens": 1637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737344123242, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.3810993415467051}} {"text": "-- Laws for weakenings and substitutions.\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Definition.Untyped.Properties where\n\nopen import Definition.Untyped\n\nopen import Tools.Nat\nopen import Tools.List\nopen import Tools.PropositionalEquality hiding (subst)\n\n\n-- Weakening properties\n\n-- Two weakenings ρ and ρ′ are extensionally equal if they agree on\n-- all arguments when interpreted as functions mapping variables to\n-- variables. Formally, they are considered equal iff\n--\n-- (∀ x → wkVar ρ x ≡ wkVar ρ′ x)\n--\n-- Intensional (propositional) equality would be too fine. For\n-- instance,\n--\n-- lift id : Γ∙A ≤ Γ∙A\n--\n-- is extensionally equal to\n--\n-- id : Γ∙A ≤ Γ∙A\n--\n-- but syntactically different.\n\n-- \"lift\" preserves equality of weakenings. Or:\n-- If two weakenings are equal under wkVar, then they are equal when lifted.\n\nwkVar-lift : ∀ {ρ ρ′}\n → (∀ x → wkVar ρ x ≡ wkVar ρ′ x)\n → (∀ x → wkVar (lift ρ) x ≡ wkVar (lift ρ′) x)\n\nwkVar-lift eq 0 = refl\nwkVar-lift eq (1+ x) = cong 1+ (eq x)\n\nwkVar-lifts : ∀ {ρ ρ′}\n → (∀ x → wkVar ρ x ≡ wkVar ρ′ x)\n → (∀ n x → wkVar (repeat lift ρ n) x ≡ wkVar (repeat lift ρ′ n) x)\nwkVar-lifts eq 0 x = eq x\nwkVar-lifts eq (1+ n) x = wkVar-lift (wkVar-lifts eq n) x\n\n-- Extensionally equal weakenings, if applied to a term,\n-- yield the same weakened term. Or:\n-- If two weakenings are equal under wkVar, then they are equal under wk.\n\nmutual\n wkVar-to-wk : ∀ {ρ ρ′}\n → (∀ x → wkVar ρ x ≡ wkVar ρ′ x)\n → ∀ t → wk ρ t ≡ wk ρ′ t\n wkVar-to-wk eq (var x) = cong var (eq x)\n wkVar-to-wk eq (gen x c) = cong (gen x) (wkVar-to-wkGen eq c)\n\n wkVar-to-wkGen : ∀ {ρ ρ′}\n → (∀ x → wkVar ρ x ≡ wkVar ρ′ x)\n → ∀ t → wkGen ρ t ≡ wkGen ρ′ t\n wkVar-to-wkGen eq [] = refl\n wkVar-to-wkGen eq (⟦ l , t ⟧ ∷ g) =\n cong₂ _∷_ (cong (⟦_,_⟧ l) (wkVar-to-wk (wkVar-lifts eq l) t))\n (wkVar-to-wkGen eq g)\n\n-- lift id is extensionally equal to id.\n\nwkVar-lift-id : (x : Nat) → wkVar (lift id) x ≡ wkVar id x\nwkVar-lift-id 0 = refl\nwkVar-lift-id (1+ x) = refl\n\nwkVar-lifts-id : (n x : Nat) → wkVar (repeat lift id n) x ≡ wkVar id x\nwkVar-lifts-id 0 x = refl\nwkVar-lifts-id (1+ n) 0 = refl\nwkVar-lifts-id (1+ n) (1+ x) = cong 1+ (wkVar-lifts-id n x)\n\n-- id is the identity renaming.\n\nwkVar-id : (x : Nat) → wkVar id x ≡ x\nwkVar-id x = refl\n\nmutual\n wk-id : (t : Term) → wk id t ≡ t\n wk-id (var x) = refl\n wk-id (gen x c) = cong (gen x) (wkGen-id c)\n\n wkGen-id : ∀ x → wkGen id x ≡ x\n wkGen-id [] = refl\n wkGen-id (⟦ l , t ⟧ ∷ g) =\n cong₂ _∷_ (cong (⟦_,_⟧ l)\n (trans (wkVar-to-wk (wkVar-lifts-id l) t) (wk-id t))) (wkGen-id g)\n\n-- lift id is also the identity renaming.\n\nwk-lift-id : (t : Term) → wk (lift id) t ≡ t\nwk-lift-id t = trans (wkVar-to-wk wkVar-lift-id t) (wk-id t)\n\n-- The composition of weakenings is correct...\n--\n-- ...as action on variables.\n\nwkVar-comp : ∀ ρ ρ′ x → wkVar ρ (wkVar ρ′ x) ≡ wkVar (ρ • ρ′) x\nwkVar-comp id ρ′ x = refl\nwkVar-comp (step ρ) ρ′ x = cong 1+ (wkVar-comp ρ ρ′ x)\nwkVar-comp (lift ρ) id x = refl\nwkVar-comp (lift ρ) (step ρ′) x = cong 1+ (wkVar-comp ρ ρ′ x)\nwkVar-comp (lift ρ) (lift ρ′) 0 = refl\nwkVar-comp (lift ρ) (lift ρ′) (1+ x) = cong 1+ (wkVar-comp ρ ρ′ x)\n\nwkVar-comps : ∀ n ρ ρ′ x\n → wkVar (repeat lift ρ n • repeat lift ρ′ n) x\n ≡ wkVar (repeat lift (ρ • ρ′) n) x\nwkVar-comps 0 ρ ρ′ x = refl\nwkVar-comps (1+ n) ρ ρ′ 0 = refl\nwkVar-comps (1+ n) ρ ρ′ (1+ x) = cong 1+ (wkVar-comps n ρ ρ′ x)\n\n-- ... as action on terms.\n\nmutual\n wk-comp : ∀ ρ ρ′ t → wk ρ (wk ρ′ t) ≡ wk (ρ • ρ′) t\n wk-comp ρ ρ′ (var x) = cong var (wkVar-comp ρ ρ′ x)\n wk-comp ρ ρ′ (gen x c) = cong (gen x) (wkGen-comp ρ ρ′ c)\n\n wkGen-comp : ∀ ρ ρ′ g → wkGen ρ (wkGen ρ′ g) ≡ wkGen (ρ • ρ′) g\n wkGen-comp ρ ρ′ [] = refl\n wkGen-comp ρ ρ′ (⟦ l , t ⟧ ∷ g) =\n cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (wk-comp (repeat lift ρ l) (repeat lift ρ′ l) t)\n (wkVar-to-wk (wkVar-comps l ρ ρ′) t)))\n (wkGen-comp ρ ρ′ g)\n\n-- The following lemmata are variations on the equality\n--\n-- wk1 ∘ ρ = lift ρ ∘ wk1.\n--\n-- Typing: Γ∙A ≤ Γ ≤ Δ <==> Γ∙A ≤ Δ∙A ≤ Δ.\n\nlift-step-comp : (ρ : Wk) → step id • ρ ≡ lift ρ • step id\nlift-step-comp id = refl\nlift-step-comp (step ρ) = cong step (lift-step-comp ρ)\nlift-step-comp (lift ρ) = refl\n\nwk1-wk : ∀ ρ t → wk1 (wk ρ t) ≡ wk (step ρ) t\nwk1-wk ρ t = wk-comp (step id) ρ t\n\nlift-wk1 : ∀ ρ t → wk (lift ρ) (wk1 t) ≡ wk (step ρ) t\nlift-wk1 pr A = trans (wk-comp (lift pr) (step id) A)\n (sym (cong (λ x → wk x A) (lift-step-comp pr)))\n\nwk1-wk≡lift-wk1 : ∀ ρ t → wk1 (wk ρ t) ≡ wk (lift ρ) (wk1 t)\nwk1-wk≡lift-wk1 ρ t = trans (wk1-wk ρ t) (sym (lift-wk1 ρ t))\n\n-- Substitution properties.\n\n-- Two substitutions σ and σ′ are equal if they are pointwise equal,\n-- i.e., agree on all variables.\n--\n-- ∀ x → σ x ≡ σ′ x\n\n-- If σ = σ′ then lift σ = lift σ′.\n\nsubstVar-lift : ∀ {σ σ′}\n → (∀ x → σ x ≡ σ′ x)\n → ∀ x → liftSubst σ x ≡ liftSubst σ′ x\n\nsubstVar-lift eq 0 = refl\nsubstVar-lift eq (1+ x) = cong wk1 (eq x)\n\nsubstVar-lifts : ∀ {σ σ′}\n → (∀ x → σ x ≡ σ′ x)\n → ∀ n x → repeat liftSubst σ n x ≡ repeat liftSubst σ′ n x\n\nsubstVar-lifts eq 0 x = eq x\nsubstVar-lifts eq (1+ n) 0 = refl\nsubstVar-lifts eq (1+ n) (1+ x) = cong wk1 (substVar-lifts eq n x)\n\n-- If σ = σ′ then subst σ t = subst σ′ t.\n\nmutual\n substVar-to-subst : ∀ {σ σ′}\n → ((x : Nat) → σ x ≡ σ′ x)\n → (t : Term) → subst σ t ≡ subst σ′ t\n substVar-to-subst eq (var x) = eq x\n substVar-to-subst eq (gen x c) = cong (gen x) (substVar-to-substGen eq c)\n\n substVar-to-substGen : ∀ {σ σ′}\n → ((x : Nat) → σ x ≡ σ′ x)\n → ∀ g → substGen σ g ≡ substGen σ′ g\n substVar-to-substGen eq [] = refl\n substVar-to-substGen eq (⟦ l , t ⟧ ∷ g) =\n cong₂ _∷_ (cong (⟦_,_⟧ l) (substVar-to-subst (substVar-lifts eq l) t))\n (substVar-to-substGen eq g)\n\n-- lift id = id (as substitutions)\n\nsubst-lift-id : (x : Nat) → (liftSubst idSubst) x ≡ idSubst x\nsubst-lift-id 0 = refl\nsubst-lift-id (1+ x) = refl\n\nsubst-lifts-id : (n x : Nat) → (repeat liftSubst idSubst n) x ≡ idSubst x\nsubst-lifts-id 0 x = refl\nsubst-lifts-id (1+ n) 0 = refl\nsubst-lifts-id (1+ n) (1+ x) = cong wk1 (subst-lifts-id n x)\n\n-- Identity substitution.\n\nmutual\n subst-id : (t : Term) → subst idSubst t ≡ t\n subst-id (var x) = refl\n subst-id (gen x c) = cong (gen x) (substGen-id c)\n\n substGen-id : ∀ g → substGen idSubst g ≡ g\n substGen-id [] = refl\n substGen-id (⟦ l , t ⟧ ∷ g) =\n cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (substVar-to-subst (subst-lifts-id l) t)\n (subst-id t)))\n (substGen-id g)\n\n\n-- Correctness of composition of weakening and substitution.\n\n-- Composition of liftings is lifting of the composition.\n-- lift ρ •ₛ lift σ = lift (ρ •ₛ σ)\n\nsubst-lift-•ₛ : ∀ {ρ σ} t\n → subst (lift ρ •ₛ liftSubst σ) t\n ≡ subst (liftSubst (ρ •ₛ σ)) t\nsubst-lift-•ₛ =\n substVar-to-subst (λ { 0 → refl ; (1+ x) → sym (wk1-wk≡lift-wk1 _ _)})\n\nhelper1 : ∀ {ρ σ} (n x : Nat) →\n (lift (repeat lift ρ n) •ₛ liftSubst (repeat liftSubst σ n)) x ≡\n liftSubst (repeat liftSubst (ρ •ₛ σ) n) x\nhelper1 0 0 = refl\nhelper1 0 (1+ x) = sym (wk1-wk≡lift-wk1 _ _)\nhelper1 (1+ n) 0 = refl\nhelper1 (1+ n) (1+ x) = trans (sym (wk1-wk≡lift-wk1 _ _)) (cong wk1 (helper1 n x))\n\nsubst-lifts-•ₛ : ∀ {ρ σ} n t\n → subst (repeat lift ρ n •ₛ repeat liftSubst σ n) t\n ≡ subst (repeat liftSubst (ρ •ₛ σ) n) t\nsubst-lifts-•ₛ 0 t = refl\nsubst-lifts-•ₛ (1+ n) t = substVar-to-subst (helper1 n) t\n\n-- lift σ ₛ• lift ρ = lift (σ ₛ• ρ)\n\nsubst-lift-ₛ• : ∀ {ρ σ} t\n → subst (liftSubst σ ₛ• lift ρ) t\n ≡ subst (liftSubst (σ ₛ• ρ)) t\nsubst-lift-ₛ• = substVar-to-subst (λ { 0 → refl ; (1+ x) → refl})\n\nhelper2 : ∀ {ρ σ} (n x : Nat) →\n liftSubst (repeat liftSubst σ n) (wkVar (lift (repeat lift ρ n)) x) ≡\n liftSubst (repeat liftSubst (λ x₁ → σ (wkVar ρ x₁)) n) x\nhelper2 0 0 = refl\nhelper2 0 (1+ x) = refl\nhelper2 (1+ n) 0 = refl\nhelper2 (1+ n) (1+ x) = cong wk1 (helper2 n x)\n\nsubst-lifts-ₛ• : ∀ {ρ σ} n t\n → subst (repeat liftSubst σ n ₛ• repeat lift ρ n) t\n ≡ subst (repeat liftSubst (σ ₛ• ρ) n) t\nsubst-lifts-ₛ• 0 t = refl\nsubst-lifts-ₛ• (1+ n) t = substVar-to-subst (helper2 n) t\n\n-- wk ρ ∘ subst σ = subst (ρ •ₛ σ)\n\nmutual\n wk-subst : ∀ {ρ σ} t → wk ρ (subst σ t) ≡ subst (ρ •ₛ σ) t\n wk-subst (var x) = refl\n wk-subst (gen x c) = cong (gen x) (wkGen-substGen c)\n\n wkGen-substGen : ∀ {ρ σ} t → wkGen ρ (substGen σ t) ≡ substGen (ρ •ₛ σ) t\n wkGen-substGen [] = refl\n wkGen-substGen (⟦ l , t ⟧ ∷ c) =\n cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (wk-subst t) (subst-lifts-•ₛ l t)))\n (wkGen-substGen c)\n\n-- subst σ ∘ wk ρ = subst (σ •ₛ ρ)\n\nmutual\n subst-wk : ∀ {ρ σ} t → subst σ (wk ρ t) ≡ subst (σ ₛ• ρ) t\n subst-wk (var x) = refl\n subst-wk (gen x c) = cong (gen x) (substGen-wkGen c)\n\n substGen-wkGen : ∀ {ρ σ} t → substGen σ (wkGen ρ t) ≡ substGen (σ ₛ• ρ) t\n substGen-wkGen [] = refl\n substGen-wkGen (⟦ l , t ⟧ ∷ c) =\n cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (subst-wk t) (subst-lifts-ₛ• l t)))\n (substGen-wkGen c)\n\n-- Composition of liftings is lifting of the composition.\n\nwk-subst-lift : ∀ {ρ σ} G\n → wk (lift ρ) (subst (liftSubst σ) G)\n ≡ subst (liftSubst (ρ •ₛ σ)) G\nwk-subst-lift G = trans (wk-subst G) (subst-lift-•ₛ G)\n\n-- Renaming with ρ is the same as substituting with ρ turned into a substitution.\n\nwk≡subst : ∀ ρ t → wk ρ t ≡ subst (toSubst ρ) t\nwk≡subst ρ t = trans (cong (wk ρ) (sym (subst-id t))) (wk-subst t)\n\n\n-- Composition of substitutions.\n\n-- Composition of liftings is lifting of the composition.\n\nsubstCompLift : ∀ {σ σ′} x\n → (liftSubst σ ₛ•ₛ liftSubst σ′) x\n ≡ (liftSubst (σ ₛ•ₛ σ′)) x\nsubstCompLift 0 = refl\nsubstCompLift {σ} {σ′} (1+ x) = trans (subst-wk (σ′ x)) (sym (wk-subst (σ′ x)))\n\nsubstCompLifts : ∀ {σ σ′} n x\n → (repeat liftSubst σ n ₛ•ₛ repeat liftSubst σ′ n) x\n ≡ (repeat liftSubst (σ ₛ•ₛ σ′) n) x\nsubstCompLifts 0 x = refl\nsubstCompLifts (1+ n) 0 = refl\nsubstCompLifts {σ} {σ′} (1+ n) (1+ x) =\n trans (substCompLift {repeat liftSubst σ n} {repeat liftSubst σ′ n} (1+ x))\n (cong wk1 (substCompLifts n x))\n\n-- Soundness of the composition of substitutions.\n\nmutual\n substCompEq : ∀ {σ σ′} (t : Term)\n → subst σ (subst σ′ t) ≡ subst (σ ₛ•ₛ σ′) t\n substCompEq (var x) = refl\n substCompEq (gen x c) = cong (gen x) (substGenCompEq c)\n\n substGenCompEq : ∀ {σ σ′} t\n → substGen σ (substGen σ′ t) ≡ substGen (σ ₛ•ₛ σ′) t\n substGenCompEq [] = refl\n substGenCompEq (⟦ l , t ⟧ ∷ c) =\n cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (substCompEq t)\n (substVar-to-subst (substCompLifts l) t)))\n (substGenCompEq c)\n\n-- Weakening single substitutions.\n\n-- Pulling apart a weakening composition in specific context _[a].\n\nwk-comp-subst : ∀ {a} ρ ρ′ G\n → wk (lift (ρ • ρ′)) G [ a ] ≡ wk (lift ρ) (wk (lift ρ′) G) [ a ]\n\nwk-comp-subst {a} ρ ρ′ G =\n cong (λ x → x [ a ]) (sym (wk-comp (lift ρ) (lift ρ′) G))\n\n-- Pushing a weakening into a single substitution.\n-- ρ (t[a]) = ((lift ρ) t)[ρ a]\n\nwk-β : ∀ {ρ a} t → wk ρ (t [ a ]) ≡ wk (lift ρ) t [ wk ρ a ]\nwk-β t = trans (wk-subst t) (sym (trans (subst-wk t)\n (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) t)))\n\n-- Pushing a weakening into a single shifting substitution.\n-- If ρ′ = lift ρ then ρ′(t[a]↑) = ρ′(t) [ρ′(a)]↑\n\nwk-β↑ : ∀ {ρ a} t → wk (lift ρ) (t [ a ]↑) ≡ wk (lift ρ) t [ wk (lift ρ) a ]↑\nwk-β↑ t = trans (wk-subst t) (sym (trans (subst-wk t)\n (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) t)))\n\n-- A specific equation on weakenings used for the reduction of natrec.\n\nwk-β-natrec : ∀ ρ G\n → Π ℕ ▹ (Π wk (lift ρ) G ▹ wk (lift (lift ρ)) (wk1 (G [ suc (var 0) ]↑)))\n ≡ Π ℕ ▹ (wk (lift ρ) G ▹▹ wk (lift ρ) G [ suc (var 0) ]↑)\nwk-β-natrec ρ G =\n cong₂ Π_▹_ refl (cong₂ Π_▹_ refl\n (trans (wk-comp (lift (lift ρ)) (step id)\n (subst (consSubst (wk1Subst var) (suc (var 0))) G))\n (trans (wk-subst G) (sym (trans (wk-subst (wk (lift ρ) G))\n (trans (subst-wk G)\n (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G)))))))\n\n-- Composing a singleton substitution and a lifted substitution.\n-- sg u ∘ lift σ = cons id u ∘ lift σ = cons σ u\n\nsubstVarSingletonComp : ∀ {u σ} (x : Nat)\n → (sgSubst u ₛ•ₛ liftSubst σ) x ≡ (consSubst σ u) x\nsubstVarSingletonComp 0 = refl\nsubstVarSingletonComp {σ = σ} (1+ x) = trans (subst-wk (σ x)) (subst-id (σ x))\n\n-- The same again, as action on a term t.\n\nsubstSingletonComp : ∀ {a σ} t\n → subst (sgSubst a ₛ•ₛ liftSubst σ) t ≡ subst (consSubst σ a) t\nsubstSingletonComp = substVar-to-subst substVarSingletonComp\n\n-- A single substitution after a lifted substitution.\n-- ((lift σ) G)[t] = (cons σ t)(G)\n\nsingleSubstComp : ∀ t σ G\n → (subst (liftSubst σ) G) [ t ]\n ≡ subst (consSubst σ t) G\nsingleSubstComp t σ G = trans (substCompEq G) (substSingletonComp G)\n\n-- A single substitution after a lifted substitution (with weakening).\n-- ((lift (ρ ∘ σ)) G)[t] = (cons (ρ ∘ σ) t)(G)\n\nsingleSubstWkComp : ∀ {ρ} t σ G\n → wk (lift ρ) (subst (liftSubst σ) G) [ t ]\n ≡ subst (consSubst (ρ •ₛ σ) t) G\nsingleSubstWkComp t σ G =\n trans (cong (subst (consSubst var t))\n (trans (wk-subst G) (subst-lift-•ₛ G)))\n (trans (substCompEq G) (substSingletonComp G))\n\n-- Pushing a substitution into a single substitution.\n\nsingleSubstLift : ∀ {σ} G t\n → subst σ (G [ t ])\n ≡ subst (liftSubst σ) G [ subst σ t ]\nsingleSubstLift G t =\n trans (substCompEq G)\n (trans (trans (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G)\n (sym (substSingletonComp G)))\n (sym (substCompEq G)))\n\n-- More specific laws.\n\nidWkLiftSubstLemma : ∀ σ G\n → wk (lift (step id)) (subst (liftSubst σ) G) [ var 0 ]\n ≡ subst (liftSubst σ) G\nidWkLiftSubstLemma σ G =\n trans (singleSubstWkComp (var 0) σ G)\n (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G)\n\nsubstVarComp↑ : ∀ {t} σ x\n → (consSubst (wk1Subst idSubst) (subst (liftSubst σ) t) ₛ•ₛ liftSubst σ) x\n ≡ (liftSubst σ ₛ•ₛ consSubst (wk1Subst idSubst) t) x\nsubstVarComp↑ σ 0 = refl\nsubstVarComp↑ σ (1+ x) = trans (subst-wk (σ x)) (sym (wk≡subst (step id) (σ x)))\n\nsingleSubstLift↑ : ∀ σ G t\n → subst (liftSubst σ) (G [ t ]↑)\n ≡ subst (liftSubst σ) G [ subst (liftSubst σ) t ]↑\nsingleSubstLift↑ σ G t =\n trans (substCompEq G)\n (sym (trans (substCompEq G) (substVar-to-subst (substVarComp↑ σ) G)))\n\nsubstConsComp : ∀ {σ t G}\n → subst (consSubst (λ x → σ (1+ x)) (subst (tail σ) t)) G\n ≡ subst σ (subst (consSubst (λ x → var (1+ x)) (wk1 t)) G)\nsubstConsComp {t = t} {G = G} =\n trans (substVar-to-subst (λ { 0 → sym (subst-wk t) ; (1+ x) → refl }) G)\n (sym (substCompEq G))\n\nwkSingleSubstId : ∀ F → (wk (lift (step id)) F) [ var 0 ] ≡ F\nwkSingleSubstId F =\n trans (subst-wk F)\n (trans (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) F)\n (subst-id F))\n\ncons-wk-subst : ∀ ρ σ a t\n → subst (sgSubst a ₛ• lift ρ ₛ•ₛ liftSubst σ) t\n ≡ subst (consSubst (ρ •ₛ σ) a) t\ncons-wk-subst ρ σ a = substVar-to-subst\n (λ { 0 → refl\n ; (1+ x) → trans (subst-wk (σ x)) (sym (wk≡subst ρ (σ x))) })\n\nnatrecSucCaseLemma : ∀ {σ} (x : Nat)\n → (step id •ₛ consSubst (wk1Subst idSubst) (suc (var 0)) ₛ•ₛ liftSubst σ) x\n ≡ (liftSubst (liftSubst σ) ₛ• step id ₛ•ₛ consSubst (wk1Subst idSubst) (suc (var 0))) x\nnatrecSucCaseLemma 0 = refl\nnatrecSucCaseLemma {σ} (1+ x) =\n trans (subst-wk (σ x))\n (sym (trans (wk1-wk (step id) _)\n (wk≡subst (step (step id)) (σ x))))\n\nnatrecSucCase : ∀ σ F\n → Π ℕ ▹ (Π subst (liftSubst σ) F\n ▹ subst (liftSubst (liftSubst σ)) (wk1 (F [ suc (var 0) ]↑)))\n ≡ Π ℕ ▹ (subst (liftSubst σ) F ▹▹ subst (liftSubst σ) F [ suc (var 0) ]↑)\nnatrecSucCase σ F =\n cong₂ Π_▹_ refl\n (cong₂ Π_▹_ refl\n (trans (trans (subst-wk (F [ suc (var 0) ]↑))\n (substCompEq F))\n (sym (trans (wk-subst (subst (liftSubst σ) F))\n (trans (substCompEq F)\n (substVar-to-subst natrecSucCaseLemma F))))))\n\nnatrecIrrelevantSubstLemma : ∀ F z s m σ (x : Nat)\n → (sgSubst (natrec (subst (liftSubst σ) F) (subst σ z) (subst σ s) m)\n ₛ•ₛ liftSubst (sgSubst m)\n ₛ•ₛ liftSubst (liftSubst σ)\n ₛ• step id\n ₛ•ₛ consSubst (tail idSubst) (suc (var 0))) x\n ≡ (consSubst σ (suc m)) x\nnatrecIrrelevantSubstLemma F z s m σ 0 =\n cong suc (trans (subst-wk m) (subst-id m))\nnatrecIrrelevantSubstLemma F z s m σ (1+ x) =\n trans (subst-wk (wk (step id) (σ x)))\n (trans (subst-wk (σ x))\n (subst-id (σ x)))\n\nnatrecIrrelevantSubst : ∀ F z s m σ\n → subst (consSubst σ (suc m)) F\n ≡ subst (liftSubst (sgSubst m))\n (subst (liftSubst (liftSubst σ))\n (wk1 (F [ suc (var 0) ]↑)))\n [ natrec (subst (liftSubst σ) F) (subst σ z) (subst σ s) m ]\nnatrecIrrelevantSubst F z s m σ =\n sym (trans (substCompEq (subst (liftSubst (liftSubst σ))\n (wk (step id)\n (subst (consSubst (tail idSubst) (suc (var 0))) F))))\n (trans (substCompEq (wk (step id)\n (subst (consSubst (tail idSubst) (suc (var 0))) F)))\n (trans\n (subst-wk (subst (consSubst (tail idSubst) (suc (var 0))) F))\n (trans (substCompEq F)\n (substVar-to-subst (natrecIrrelevantSubstLemma F z s m σ) F)))))\n\nnatrecIrrelevantSubstLemma′ : ∀ F z s n (x : Nat)\n → (sgSubst (natrec F z s n)\n ₛ•ₛ liftSubst (sgSubst n)\n ₛ• step id\n ₛ•ₛ consSubst (tail idSubst) (suc (var 0))) x\n ≡ (consSubst var (suc n)) x\nnatrecIrrelevantSubstLemma′ F z s n 0 =\n cong suc (trans (subst-wk n) (subst-id n))\nnatrecIrrelevantSubstLemma′ F z s n (1+ x) = refl\n\nnatrecIrrelevantSubst′ : ∀ F z s n\n → subst (liftSubst (sgSubst n))\n (wk1 (F [ suc (var 0) ]↑))\n [ natrec F z s n ]\n ≡ F [ suc n ]\nnatrecIrrelevantSubst′ F z s n =\n trans (substCompEq (wk (step id)\n (subst (consSubst (tail idSubst) (suc (var 0))) F)))\n (trans (subst-wk (subst (consSubst (tail idSubst) (suc (var 0))) F))\n (trans (substCompEq F)\n (substVar-to-subst (natrecIrrelevantSubstLemma′ F z s n) F)))\n\ncons0wkLift1-id : ∀ σ G\n → subst (sgSubst (var 0))\n (wk (lift (step id)) (subst (liftSubst σ) G))\n ≡ subst (liftSubst σ) G\ncons0wkLift1-id σ G =\n trans (subst-wk (subst (liftSubst σ) G))\n (trans (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl })\n (subst (liftSubst σ) G))\n (subst-id (subst (liftSubst σ) G)))\n\nsubstConsId : ∀ {σ t} G\n → subst (consSubst σ (subst σ t)) G\n ≡ subst σ (subst (sgSubst t) G)\nsubstConsId G =\n sym (trans (substCompEq G)\n (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G))\n\nsubstConsTailId : ∀ {G t σ}\n → subst (consSubst (tail σ) (subst σ t)) G\n ≡ subst σ (subst (consSubst (tail idSubst) t) G)\nsubstConsTailId {G} {t} {σ} =\n trans (substVar-to-subst (λ { 0 → refl\n ; (1+ x) → refl }) G)\n (sym (substCompEq G))\n\nsubstConcatSingleton′ : ∀ {a σ} t\n → subst (σ ₛ•ₛ sgSubst a) t\n ≡ subst (consSubst σ (subst σ a)) t\nsubstConcatSingleton′ t = substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) t\n\nwk1-tailId : ∀ t → wk1 t ≡ subst (tail idSubst) t\nwk1-tailId t = trans (sym (subst-id (wk1 t))) (subst-wk t)\n", "meta": {"hexsha": "c7268b46e91fa4db313656f69ddbb7e1352f6d15", "size": 19867, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Untyped/Properties.agda", "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/Untyped/Properties.agda", "max_issues_repo_name": "loic-p/logrel-mltt", "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/Untyped/Properties.agda", "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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": 34.7933450088, "max_line_length": 90, "alphanum_fraction": 0.5594704787, "num_tokens": 7861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737344123242, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.3810993415467051}} {"text": "------------------------------------------------------------------------\n-- Truncation, defined using a kind of Church encoding\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\n-- Partly following the HoTT book.\n\nopen import Equality\n\nmodule H-level.Truncation.Church\n {reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where\n\nopen import Prelude\nopen import Logical-equivalence using (_⇔_)\n\nopen import Bijection eq as Bijection using (_↔_)\nopen Derived-definitions-and-properties eq\nopen import Embedding eq hiding (_∘_)\nopen import Equality.Decidable-UIP eq\nimport Equality.Groupoid eq as EG\nopen import Equivalence eq as Eq using (_≃_; Is-equivalence)\nimport Equivalence.Half-adjoint eq as HA\nopen import Function-universe eq as F hiding (_∘_)\nopen import Groupoid eq\nopen import H-level eq as H-level\nopen import H-level.Closure eq\nopen import Nat eq\nopen import Preimage eq as Preimage using (_⁻¹_)\nopen import Surjection eq using (_↠_; Split-surjective)\n\n-- Truncation.\n\n∥_∥ : ∀ {a} → Type a → ℕ → (ℓ : Level) → Type (a ⊔ lsuc ℓ)\n∥ A ∥ n ℓ = (P : Type ℓ) → H-level n P → (A → P) → P\n\n-- If A is inhabited, then ∥ A ∥ n ℓ is also inhabited.\n\n∣_∣ : ∀ {n ℓ a} {A : Type a} → A → ∥ A ∥ n ℓ\n∣ x ∣ = λ _ _ f → f x\n\n-- A special case of ∣_∣.\n\n∣_∣₁ : ∀ {ℓ a} {A : Type a} → A → ∥ A ∥ 1 ℓ\n∣ x ∣₁ = ∣_∣ {n = 1} x\n\n-- The truncation produces types of the right h-level (assuming\n-- extensionality).\n\ntruncation-has-correct-h-level :\n ∀ n {ℓ a} {A : Type a} →\n Extensionality (a ⊔ lsuc ℓ) (a ⊔ ℓ) →\n H-level n (∥ A ∥ n ℓ)\ntruncation-has-correct-h-level n {ℓ} {a} ext =\n Π-closure (lower-extensionality a lzero ext) n λ _ →\n Π-closure (lower-extensionality (a ⊔ lsuc ℓ) lzero ext) n λ h →\n Π-closure (lower-extensionality (lsuc ℓ) a ext) n λ _ →\n h\n\n-- Primitive \"recursion\" for truncated types.\n\nrec :\n ∀ n {a b} {A : Type a} {B : Type b} →\n H-level n B →\n (A → B) → ∥ A ∥ n b → B\nrec _ h f x = x _ h f\n\nprivate\n\n -- The function rec computes in the right way.\n\n rec-∣∣ :\n ∀ {n a b} {A : Type a} {B : Type b}\n (h : H-level n B) (f : A → B) (x : A) →\n rec _ h f ∣ x ∣ ≡ f x\n rec-∣∣ _ _ _ = refl _\n\n-- Map function.\n\n∥∥-map : ∀ n {a b ℓ} {A : Type a} {B : Type b} →\n (A → B) →\n ∥ A ∥ n ℓ → ∥ B ∥ n ℓ\n∥∥-map _ f x = λ P h g → x P h (g ∘ f)\n\n-- The truncation operator preserves logical equivalences.\n\n∥∥-cong-⇔ : ∀ {n a b ℓ} {A : Type a} {B : Type b} →\n A ⇔ B → ∥ A ∥ n ℓ ⇔ ∥ B ∥ n ℓ\n∥∥-cong-⇔ A⇔B = record\n { to = ∥∥-map _ (_⇔_.to A⇔B)\n ; from = ∥∥-map _ (_⇔_.from A⇔B)\n }\n\n-- The truncation operator preserves bijections (assuming\n-- extensionality).\n\n∥∥-cong : ∀ {k n a b ℓ} {A : Type a} {B : Type b} →\n Extensionality (a ⊔ b ⊔ lsuc ℓ) (a ⊔ b ⊔ ℓ) →\n A ↔[ k ] B → ∥ A ∥ n ℓ ↔[ k ] ∥ B ∥ n ℓ\n∥∥-cong {k} {n} {a} {b} {ℓ} ext A↝B = from-bijection (record\n { surjection = record\n { logical-equivalence = record\n { to = ∥∥-map _ (_↔_.to A↔B)\n ; from = ∥∥-map _ (_↔_.from A↔B)\n }\n ; right-inverse-of = lemma (lower-extensionality a a ext) A↔B\n }\n ; left-inverse-of = lemma (lower-extensionality b b ext) (inverse A↔B)\n })\n where\n A↔B = from-isomorphism A↝B\n\n lemma :\n ∀ {c d} {C : Type c} {D : Type d} →\n Extensionality (d ⊔ lsuc ℓ) (d ⊔ ℓ) →\n (C↔D : C ↔ D) (∥d∥ : ∥ D ∥ n ℓ) →\n ∥∥-map _ (_↔_.to C↔D) (∥∥-map _ (_↔_.from C↔D) ∥d∥) ≡ ∥d∥\n lemma {d = d} ext C↔D ∥d∥ =\n apply-ext (lower-extensionality d lzero ext) λ P →\n apply-ext (lower-extensionality _ lzero ext) λ h →\n apply-ext (lower-extensionality (lsuc ℓ) d ext) λ g →\n\n ∥d∥ P h (g ∘ _↔_.to C↔D ∘ _↔_.from C↔D) ≡⟨ cong (λ f → ∥d∥ P h (g ∘ f)) $\n apply-ext (lower-extensionality (lsuc ℓ) ℓ ext)\n (_↔_.right-inverse-of C↔D) ⟩∎\n ∥d∥ P h g ∎\n\n-- The universe level can be decreased (unless it is zero).\n\nwith-lower-level :\n ∀ ℓ₁ {ℓ₂ a} n {A : Type a} →\n ∥ A ∥ n (ℓ₁ ⊔ ℓ₂) → ∥ A ∥ n ℓ₂\nwith-lower-level ℓ₁ _ x =\n λ P h f → lower (x (↑ ℓ₁ P) (↑-closure _ h) (lift ∘ f))\n\nprivate\n\n -- The function with-lower-level computes in the right way.\n\n with-lower-level-∣∣ :\n ∀ {ℓ₁ ℓ₂ a n} {A : Type a} (x : A) →\n with-lower-level ℓ₁ {ℓ₂ = ℓ₂} n ∣ x ∣ ≡ ∣ x ∣\n with-lower-level-∣∣ _ = refl _\n\n-- ∥_∥ is downwards closed in the h-level.\n\ndownwards-closed :\n ∀ {m n a ℓ} {A : Type a} →\n n ≤ m →\n ∥ A ∥ m ℓ → ∥ A ∥ n ℓ\ndownwards-closed n≤m x = λ P h f → x P (H-level.mono n≤m h) f\n\nprivate\n\n -- The function downwards-closed computes in the right way.\n\n downwards-closed-∣∣ :\n ∀ {m n a ℓ} {A : Type a} (n≤m : n ≤ m) (x : A) →\n downwards-closed {ℓ = ℓ} n≤m ∣ x ∣ ≡ ∣ x ∣\n downwards-closed-∣∣ _ _ = refl _\n\n-- The function rec can be used to define a kind of dependently typed\n-- eliminator for the propositional truncation (assuming\n-- extensionality).\n\nprop-elim :\n ∀ {ℓ a p} {A : Type a} →\n Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a ⊔ p) →\n (P : ∥ A ∥ 1 ℓ → Type p) →\n (∀ x → Is-proposition (P x)) →\n ((x : A) → P ∣ x ∣₁) →\n ∥ A ∥ 1 (lsuc ℓ ⊔ a ⊔ p) → (x : ∥ A ∥ 1 ℓ) → P x\nprop-elim {ℓ} {a} {p} ext P P-prop f =\n rec 1\n (Π-closure (lower-extensionality lzero (ℓ ⊔ a) ext) 1 P-prop)\n (λ x _ → subst P\n (truncation-has-correct-h-level 1\n (lower-extensionality lzero p ext) _ _)\n (f x))\n\nabstract\n\n -- The eliminator gives the right result, up to propositional\n -- equality, when applied to ∣ x ∣ and ∣ x ∣.\n\n prop-elim-∣∣ :\n ∀ {ℓ a p} {A : Type a}\n (ext : Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a ⊔ p))\n (P : ∥ A ∥ 1 ℓ → Type p)\n (P-prop : ∀ x → Is-proposition (P x))\n (f : (x : A) → P ∣ x ∣₁) (x : A) →\n prop-elim ext P P-prop f ∣ x ∣₁ ∣ x ∣₁ ≡ f x\n prop-elim-∣∣ _ _ P-prop _ _ = P-prop _ _ _\n\n-- Nested truncations can sometimes be flattened.\n\nflatten↠ :\n ∀ {m n a ℓ} {A : Type a} →\n Extensionality (a ⊔ lsuc ℓ) (a ⊔ ℓ) →\n m ≤ n →\n ∥ ∥ A ∥ m ℓ ∥ n (a ⊔ lsuc ℓ) ↠ ∥ A ∥ m ℓ\nflatten↠ ext m≤n = record\n { logical-equivalence = record\n { to = rec _\n (H-level.mono m≤n\n (truncation-has-correct-h-level _ ext))\n F.id\n ; from = ∣_∣\n }\n ; right-inverse-of = refl\n }\n\nflatten↔ :\n ∀ {a ℓ} {A : Type a} →\n Extensionality (lsuc (a ⊔ lsuc ℓ)) (lsuc (a ⊔ lsuc ℓ)) →\n (∥ ∥ A ∥ 1 ℓ ∥ 1 (a ⊔ lsuc ℓ) →\n ∥ ∥ A ∥ 1 ℓ ∥ 1 (lsuc (a ⊔ lsuc ℓ))) →\n ∥ ∥ A ∥ 1 ℓ ∥ 1 (a ⊔ lsuc ℓ) ↔ ∥ A ∥ 1 ℓ\nflatten↔ ext resize = record\n { surjection = flatten↠ {m = 1} ext′ ≤-refl\n ; left-inverse-of = λ x →\n prop-elim\n ext\n (λ x → ∣ rec 1\n (H-level.mono (≤-refl {n = 1})\n (truncation-has-correct-h-level 1 ext′))\n F.id x ∣₁ ≡ x)\n (λ _ → ⇒≡ 1 $ truncation-has-correct-h-level\n 1 (lower-extensionality lzero _ ext))\n (λ _ → refl _)\n (resize x)\n x\n }\n where\n ext′ = lower-extensionality _ _ ext\n\n-- Surjectivity.\n--\n-- I'm not quite sure what the universe level of the truncation should\n-- be, so I've included it as a parameter.\n\nSurjective : ∀ {a b} ℓ {A : Type a} {B : Type b} →\n (A → B) → Type (a ⊔ b ⊔ lsuc ℓ)\nSurjective ℓ f = ∀ b → ∥ f ⁻¹ b ∥ 1 ℓ\n\n-- The property Surjective ℓ f is a proposition (assuming\n-- extensionality).\n\nSurjective-propositional :\n ∀ {ℓ a b} {A : Type a} {B : Type b} {f : A → B} →\n Extensionality (a ⊔ b ⊔ lsuc ℓ) (a ⊔ b ⊔ lsuc ℓ) →\n Is-proposition (Surjective ℓ f)\nSurjective-propositional {ℓ} {a} ext =\n Π-closure (lower-extensionality (a ⊔ lsuc ℓ) lzero ext) 1 λ _ →\n truncation-has-correct-h-level 1\n (lower-extensionality lzero (lsuc ℓ) ext)\n\n-- Split surjective functions are surjective.\n\nSplit-surjective→Surjective :\n ∀ {a b ℓ} {A : Type a} {B : Type b} {f : A → B} →\n Split-surjective f → Surjective ℓ f\nSplit-surjective→Surjective s = λ b → ∣ s b ∣₁\n\n-- Being both surjective and an embedding is equivalent to being an\n-- equivalence.\n--\n-- This is Corollary 4.6.4 from the first edition of the HoTT book\n-- (the proof is perhaps not quite identical).\n\nsurjective×embedding≃equivalence :\n ∀ {a b} ℓ {A : Type a} {B : Type b} {f : A → B} →\n Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (lsuc (a ⊔ b ⊔ ℓ)) →\n (Surjective (a ⊔ b ⊔ ℓ) f × Is-embedding f) ≃ Is-equivalence f\nsurjective×embedding≃equivalence {a} {b} ℓ {f = f} ext =\n Eq.⇔→≃\n (×-closure 1 (Surjective-propositional ext)\n (Is-embedding-propositional\n (lower-extensionality _ _ ext)))\n (Eq.propositional (lower-extensionality _ _ ext) _)\n (λ (is-surj , is-emb) →\n _⇔_.from HA.Is-equivalence⇔Is-equivalence-CP $ λ y →\n $⟨ is-surj y ⟩\n ∥ f ⁻¹ y ∥ 1 (a ⊔ b ⊔ ℓ) ↝⟨ with-lower-level ℓ 1 ⟩\n ∥ f ⁻¹ y ∥ 1 (a ⊔ b) ↝⟨ rec 1\n (Contractible-propositional\n (lower-extensionality _ _ ext))\n (f ⁻¹ y ↝⟨ propositional⇒inhabited⇒contractible\n (embedding→⁻¹-propositional is-emb y) ⟩□\n Contractible (f ⁻¹ y) □) ⟩□\n\n Contractible (f ⁻¹ y) □)\n (λ is-eq →\n (λ y → $⟨ HA.inverse is-eq y\n , HA.right-inverse-of is-eq y\n ⟩\n f ⁻¹ y ↝⟨ ∣_∣₁ ⟩□\n ∥ f ⁻¹ y ∥ 1 (a ⊔ b ⊔ ℓ) □)\n\n , ($⟨ is-eq ⟩\n Is-equivalence f ↝⟨ Embedding.is-embedding ∘ from-equivalence ∘ Eq.⟨ _ ,_⟩ ⟩□\n Is-embedding f □))\n\n-- If the underlying type has a certain h-level, then there is a split\n-- surjection from corresponding truncations (if they are \"big\"\n-- enough) to the type itself.\n\n∥∥↠ : ∀ ℓ {a} {A : Type a} n →\n H-level n A → ∥ A ∥ n (a ⊔ ℓ) ↠ A\n∥∥↠ ℓ _ h = record\n { logical-equivalence = record\n { to = rec _ h F.id ∘ with-lower-level ℓ _\n ; from = ∣_∣\n }\n ; right-inverse-of = refl\n }\n\n-- If the underlying type is a proposition, then propositional\n-- truncations of the type are isomorphic to the type itself (if they\n-- are \"big\" enough, and assuming extensionality).\n\n∥∥↔ : ∀ ℓ {a} {A : Type a} →\n Extensionality (lsuc (a ⊔ ℓ)) (a ⊔ ℓ) →\n Is-proposition A → ∥ A ∥ 1 (a ⊔ ℓ) ↔ A\n∥∥↔ ℓ ext A-prop = record\n { surjection = ∥∥↠ ℓ 1 A-prop\n ; left-inverse-of = λ _ →\n truncation-has-correct-h-level 1 ext _ _\n }\n\n-- A simple isomorphism involving propositional truncation.\n\n∥∥×↔ :\n ∀ {ℓ a} {A : Type a} →\n Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a) →\n ∥ A ∥ 1 ℓ × A ↔ A\n∥∥×↔ {ℓ} {A = A} ext =\n ∥ A ∥ 1 ℓ × A ↝⟨ ×-comm ⟩\n A × ∥ A ∥ 1 ℓ ↝⟨ (drop-⊤-right λ a →\n _⇔_.to contractible⇔↔⊤ $\n propositional⇒inhabited⇒contractible\n (truncation-has-correct-h-level 1 ext)\n ∣ a ∣₁) ⟩□\n A □\n\n-- A variant of ∥∥×↔, introduced to ensure that the right-inverse-of\n-- proof is, by definition, simple (see right-inverse-of-∥∥×≃ below).\n\n∥∥×≃ :\n ∀ {ℓ a} {A : Type a} →\n Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a) →\n (∥ A ∥ 1 ℓ × A) ≃ A\n∥∥×≃ ext = Eq.↔→≃\n proj₂\n (λ x → ∣ x ∣₁ , x)\n refl\n (λ _ → cong (_, _) (truncation-has-correct-h-level 1 ext _ _))\n\nprivate\n\n right-inverse-of-∥∥×≃ :\n ∀ {ℓ a} {A : Type a}\n (ext : Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a)) (x : A) →\n _≃_.right-inverse-of (∥∥×≃ {ℓ = ℓ} ext) x ≡ refl x\n right-inverse-of-∥∥×≃ _ x = refl (refl x)\n\n-- ∥_∥ commutes with _×_ (assuming extensionality and a resizing\n-- function for the propositional truncation).\n\n∥∥×∥∥↔∥×∥ :\n ∀ {a b} ℓ {A : Type a} {B : Type b} →\n Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ) →\n (∀ {x} {X : Type x} →\n ∥ X ∥ 1 (a ⊔ b ⊔ ℓ) →\n ∥ X ∥ 1 (lsuc (a ⊔ b ⊔ ℓ))) →\n let ℓ′ = a ⊔ b ⊔ ℓ in\n (∥ A ∥ 1 ℓ′ × ∥ B ∥ 1 ℓ′) ↔ ∥ A × B ∥ 1 ℓ′\n∥∥×∥∥↔∥×∥ _ ext resize = record\n { surjection = record\n { logical-equivalence = record\n { from = λ p → ∥∥-map 1 proj₁ p , ∥∥-map 1 proj₂ p\n ; to = λ { (x , y) →\n rec 1\n (truncation-has-correct-h-level 1 ext)\n (λ x → rec 1\n (truncation-has-correct-h-level 1 ext)\n (λ y → ∣ x , y ∣₁)\n (resize y))\n (resize x) }\n }\n ; right-inverse-of = λ _ → truncation-has-correct-h-level 1 ext _ _\n }\n ; left-inverse-of = λ _ →\n ×-closure 1\n (truncation-has-correct-h-level 1 ext)\n (truncation-has-correct-h-level 1 ext)\n _ _\n }\n\n-- If A is merely inhabited (at a certain level), then the\n-- propositional truncation of A (at the same level) is isomorphic to\n-- the unit type (assuming extensionality).\n\ninhabited⇒∥∥↔⊤ :\n ∀ {ℓ a} {A : Type a} →\n Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a) →\n ∥ A ∥ 1 ℓ → ∥ A ∥ 1 ℓ ↔ ⊤\ninhabited⇒∥∥↔⊤ ext ∥a∥ =\n _⇔_.to contractible⇔↔⊤ $\n propositional⇒inhabited⇒contractible\n (truncation-has-correct-h-level 1 ext)\n ∥a∥\n\n-- If A is not inhabited, then the propositional truncation of A is\n-- isomorphic to the empty type.\n\nnot-inhabited⇒∥∥↔⊥ :\n ∀ {ℓ₁ ℓ₂ a} {A : Type a} →\n ¬ A → ∥ A ∥ 1 ℓ₁ ↔ ⊥ {ℓ = ℓ₂}\nnot-inhabited⇒∥∥↔⊥ {A = A} =\n ¬ A ↝⟨ (λ ¬a ∥a∥ → rec 1 ⊥-propositional ¬a (with-lower-level _ 1 ∥a∥)) ⟩\n ¬ ∥ A ∥ 1 _ ↝⟨ inverse ∘ Bijection.⊥↔uninhabited ⟩□\n ∥ A ∥ 1 _ ↔ ⊥ □\n\n-- The following two results come from \"Generalizations of Hedberg's\n-- Theorem\" by Kraus, Escardó, Coquand and Altenkirch.\n\n-- Types with constant endofunctions are \"h-stable\" (meaning that\n-- \"mere inhabitance\" implies inhabitance).\n\nconstant-endofunction⇒h-stable :\n ∀ {a} {A : Type a} {f : A → A} →\n Constant f → ∥ A ∥ 1 a → A\nconstant-endofunction⇒h-stable {a} {A} {f} c =\n ∥ A ∥ 1 a ↝⟨ rec 1 (fixpoint-lemma f c) (λ x → f x , c (f x) x) ⟩\n (∃ λ (x : A) → f x ≡ x) ↝⟨ proj₁ ⟩□\n A □\n\n-- Having a constant endofunction is logically equivalent to being\n-- h-stable (assuming extensionality).\n\nconstant-endofunction⇔h-stable :\n ∀ {a} {A : Type a} →\n Extensionality (lsuc a) a →\n (∃ λ (f : A → A) → Constant f) ⇔ (∥ A ∥ 1 a → A)\nconstant-endofunction⇔h-stable ext = record\n { to = λ { (_ , c) → constant-endofunction⇒h-stable c }\n ; from = λ f → f ∘ ∣_∣₁ , λ x y →\n\n f ∣ x ∣₁ ≡⟨ cong f $ truncation-has-correct-h-level 1 ext _ _ ⟩∎\n f ∣ y ∣₁ ∎\n }\n\n-- The following three lemmas were communicated to me by Nicolai\n-- Kraus. (In slightly different form.) They are closely related to\n-- Lemma 2.1 in his paper \"The General Universal Property of the\n-- Propositional Truncation\".\n\n-- A variant of ∥∥×≃.\n\ndrop-∥∥ :\n ∀ ℓ {a b} {A : Type a} {B : A → Type b} →\n Extensionality (lsuc (a ⊔ ℓ)) (a ⊔ b ⊔ ℓ) →\n\n (∥ A ∥ 1 (a ⊔ ℓ) → ∀ x → B x)\n ↔\n (∀ x → B x)\ndrop-∥∥ ℓ {a} {b} {A} {B} ext =\n\n (∥ A ∥ 1 _ → ∀ x → B x) ↝⟨ inverse currying ⟩\n\n ((p : ∥ A ∥ 1 _ × A) → B (proj₂ p)) ↝⟨ Π-cong (lower-extensionality lzero (a ⊔ ℓ) ext)\n (∥∥×≃ (lower-extensionality lzero b ext))\n (λ _ → F.id) ⟩□\n (∀ x → B x) □\n\n-- Another variant of ∥∥×≃.\n\npush-∥∥ :\n ∀ ℓ {a b c} {A : Type a} {B : A → Type b} {C : (∀ x → B x) → Type c} →\n Extensionality (lsuc (a ⊔ ℓ)) (a ⊔ b ⊔ c ⊔ ℓ) →\n\n (∥ A ∥ 1 (a ⊔ ℓ) → ∃ λ (f : ∀ x → B x) → C f)\n ↔\n (∃ λ (f : ∀ x → B x) → ∥ A ∥ 1 (a ⊔ ℓ) → C f)\n\npush-∥∥ ℓ {a} {b} {c} {A} {B} {C} ext =\n\n (∥ A ∥ 1 _ → ∃ λ (f : ∀ x → B x) → C f) ↝⟨ ΠΣ-comm ⟩\n\n (∃ λ (f : ∥ A ∥ 1 _ → ∀ x → B x) → ∀ ∥x∥ → C (f ∥x∥)) ↝⟨ Σ-cong (drop-∥∥ ℓ (lower-extensionality lzero c ext)) (λ f →\n ∀-cong (lower-extensionality lzero (a ⊔ b ⊔ ℓ) ext) λ ∥x∥ →\n ≡⇒↝ _ $ cong C $ apply-ext (lower-extensionality _ (a ⊔ c ⊔ ℓ) ext) λ x →\n f ∥x∥ x ≡⟨ cong (λ ∥x∥ → f ∥x∥ x) $\n truncation-has-correct-h-level 1\n (lower-extensionality lzero (b ⊔ c) ext)\n _ _ ⟩\n f ∣ x ∣₁ x ≡⟨ sym $ subst-refl _ _ ⟩∎\n\n subst B (refl x) (f ∣ x ∣₁ x) ∎) ⟩□\n\n (∃ λ (f : ∀ x → B x) → ∥ A ∥ 1 _ → C (λ x → f x)) □\n\n-- This is an instance of a variant of Lemma 2.1 from \"The General\n-- Universal Property of the Propositional Truncation\" by Kraus.\n\ndrop-∥∥₃ :\n ∀ ℓ {a b c d}\n {A : Type a} {B : A → Type b} {C : A → (∀ x → B x) → Type c}\n {D : A → (f : ∀ x → B x) → (∀ x → C x f) → Type d} →\n Extensionality (lsuc (a ⊔ ℓ)) (a ⊔ b ⊔ c ⊔ d ⊔ ℓ) →\n\n (∥ A ∥ 1 (a ⊔ ℓ) →\n ∃ λ (f : ∀ x → B x) → ∃ λ (g : ∀ x → C x f) → ∀ x → D x f g)\n ↔\n (∃ λ (f : ∀ x → B x) → ∃ λ (g : ∀ x → C x f) → ∀ x → D x f g)\n\ndrop-∥∥₃ ℓ {b = b} {c} {A = A} {B} {C} {D} ext =\n (∥ A ∥ 1 _ →\n ∃ λ (f : ∀ x → B x) → ∃ λ (g : ∀ x → C x f) → ∀ x → D x f g) ↝⟨ push-∥∥ ℓ ext ⟩\n\n (∃ λ (f : ∀ x → B x) →\n ∥ A ∥ 1 _ → ∃ λ (g : ∀ x → C x f) → ∀ x → D x f g) ↝⟨ (∃-cong λ _ →\n push-∥∥ ℓ (lower-extensionality lzero b ext)) ⟩\n (∃ λ (f : ∀ x → B x) → ∃ λ (g : ∀ x → C x f) →\n ∥ A ∥ 1 _ → ∀ x → D x f g) ↝⟨ (∃-cong λ _ → ∃-cong λ _ →\n drop-∥∥ ℓ (lower-extensionality lzero (b ⊔ c) ext)) ⟩□\n (∃ λ (f : ∀ x → B x) → ∃ λ (g : ∀ x → C x f) → ∀ x → D x f g) □\n\n-- Having a coherently constant function into a groupoid is equivalent\n-- to having a function from a propositionally truncated type into the\n-- groupoid (assuming extensionality). This result is Proposition 2.3\n-- in \"The General Universal Property of the Propositional Truncation\"\n-- by Kraus.\n\nCoherently-constant :\n ∀ {a b} {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b)\nCoherently-constant f =\n ∃ λ (c : Constant f) →\n ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃\n\ncoherently-constant-function≃∥inhabited∥⇒inhabited :\n ∀ {a b} ℓ {A : Type a} {B : Type b} →\n Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ) →\n H-level 3 B →\n (∃ λ (f : A → B) → Coherently-constant f) ≃ (∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B)\ncoherently-constant-function≃∥inhabited∥⇒inhabited {a} {b} ℓ {A} {B}\n ext B-groupoid =\n (∃ λ (f : A → B) → Coherently-constant f) ↔⟨ inverse $ drop-∥∥₃ (b ⊔ ℓ) ext ⟩\n (∥ A ∥ 1 ℓ′ → ∃ λ (f : A → B) → Coherently-constant f) ↝⟨ ∀-cong (lower-extensionality lzero ℓ ext) (inverse ∘ equivalence₂) ⟩□\n (∥ A ∥ 1 ℓ′ → B) □\n where\n ℓ′ = a ⊔ b ⊔ ℓ\n\n rearrangement-lemma = λ a₀ →\n (∃ λ (f₁ : B) →\n ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (c : Constant f) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ ∃-comm ⟩\n\n (∃ λ (f : A → B) →\n ∃ λ (f₁ : B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (c : Constant f) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩\n\n (∃ λ (f : A → B) →\n ∃ λ (f₁ : B) →\n ∃ λ (c : Constant f) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-comm) ⟩\n\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (f₁ : B) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n ∃-cong λ _ → ∃-comm) ⟩\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (f₁ : B) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n ∃-comm) ⟩\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (f₁ : B) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩\n\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (f₁ : B) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩\n\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (f₁ : B) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩\n\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n ∃-comm) ⟩\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩\n\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n ∃-cong λ _ → ∃-cong λ _ → ×-comm) ⟩\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (d₂ : (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) →\n trans (c a₀ a₀) (c₁ a₀) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n ∃-cong λ _ → ∃-comm) ⟩□\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₂ : (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n trans (c a₀ a₀) (c₁ a₀) ≡ c₂) □\n\n equivalence₁ : A → (B ≃ ∃ λ (f : A → B) → Coherently-constant f)\n equivalence₁ a₀ = Eq.↔⇒≃ (\n B ↝⟨ (inverse $ drop-⊤-right λ _ →\n _⇔_.to contractible⇔↔⊤ $\n Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 0 λ _ →\n singleton-contractible _) ⟩\n (∃ λ (f₁ : B) →\n (a : A) → ∃ λ (b : B) → b ≡ f₁) ↝⟨ (∃-cong λ _ → ΠΣ-comm) ⟩\n\n (∃ λ (f₁ : B) →\n ∃ λ (f : A → B) → (a : A) → f a ≡ f₁) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → inverse $ drop-⊤-right λ _ →\n _⇔_.to contractible⇔↔⊤ $\n Π-closure (lower-extensionality _ ℓ ext) 0 λ _ →\n Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 0 λ _ →\n singleton-contractible _) ⟩\n (∃ λ (f₁ : B) →\n ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∀ a₁ a₂ → ∃ λ (c : f a₁ ≡ f a₂) → c ≡ trans (c₁ a₁) (sym (c₁ a₂))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n ∀-cong (lower-extensionality _ ℓ ext) λ _ →\n ∀-cong (lower-extensionality _ (a ⊔ ℓ) ext) λ _ →\n ∃-cong λ _ → ≡⇒↝ _ $ sym $ [trans≡]≡[≡trans-symʳ] _ _ _) ⟩\n (∃ λ (f₁ : B) →\n ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∀ a₁ a₂ → ∃ λ (c : f a₁ ≡ f a₂) → trans c (c₁ a₂) ≡ c₁ a₁) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n ∀-cong (lower-extensionality _ ℓ ext) λ _ →\n ΠΣ-comm) ⟩\n (∃ λ (f₁ : B) →\n ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∀ a₁ → ∃ λ (c : ∀ a₂ → f a₁ ≡ f a₂) →\n ∀ a₂ → trans (c a₂) (c₁ a₂) ≡ c₁ a₁) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ΠΣ-comm) ⟩\n\n (∃ λ (f₁ : B) →\n ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (c : Constant f) → ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n inverse $ drop-⊤-right λ _ →\n _⇔_.to contractible⇔↔⊤ $\n other-singleton-contractible _) ⟩\n (∃ λ (f₁ : B) →\n ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (c : Constant f) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) → trans (c a₀ a₀) (c₁ a₀) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ c₁ → ∃-cong λ c → ∃-cong λ d₁ →\n ∃-cong λ _ → inverse $ drop-⊤-right λ _ →\n _⇔_.to contractible⇔↔⊤ $\n propositional⇒inhabited⇒contractible\n (Π-closure (lower-extensionality _ ℓ ext) 1 λ _ →\n Π-closure (lower-extensionality _ ℓ ext) 1 λ _ →\n Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 1 λ _ →\n B-groupoid)\n (λ a₁ a₂ a₃ →\n trans (c a₁ a₂) (c a₂ a₃) ≡⟨ cong₂ trans (≡⇒↝ implication\n ([trans≡]≡[≡trans-symʳ] _ _ _) (d₁ _ _))\n (≡⇒↝ implication\n ([trans≡]≡[≡trans-symʳ] _ _ _) (d₁ _ _)) ⟩\n trans (trans (c₁ a₁) (sym (c₁ a₂)))\n (trans (c₁ a₂) (sym (c₁ a₃))) ≡⟨ sym $ trans-assoc _ _ _ ⟩\n\n trans (trans (trans (c₁ a₁) (sym (c₁ a₂))) (c₁ a₂))\n (sym (c₁ a₃)) ≡⟨ cong (flip trans _) $ trans-[trans-sym]- _ _ ⟩\n\n trans (c₁ a₁) (sym (c₁ a₃)) ≡⟨ sym $ ≡⇒↝ implication\n ([trans≡]≡[≡trans-symʳ] _ _ _) (d₁ _ _) ⟩∎\n c a₁ a₃ ∎)) ⟩\n\n (∃ λ (f₁ : B) →\n ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (c : Constant f) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ c₁ → ∃-cong λ c → ∃-cong λ d₁ →\n ∃-cong λ c₂ → ∃-cong λ d₃ → inverse $ drop-⊤-right λ d →\n _⇔_.to contractible⇔↔⊤ $\n propositional⇒inhabited⇒contractible\n (Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 1 λ _ →\n B-groupoid)\n (λ a →\n trans (c a₀ a) (c₁ a) ≡⟨ cong (λ x → trans x _) $ sym $ d _ _ _ ⟩\n trans (trans (c a₀ a₀) (c a₀ a)) (c₁ a) ≡⟨ trans-assoc _ _ _ ⟩\n trans (c a₀ a₀) (trans (c a₀ a) (c₁ a)) ≡⟨ cong (trans _) $ d₁ _ _ ⟩\n trans (c a₀ a₀) (c₁ a₀) ≡⟨ d₃ ⟩∎\n c₂ ∎)) ⟩\n\n (∃ λ (f₁ : B) →\n ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (c : Constant f) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ rearrangement-lemma a₀ ⟩\n\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₂ : (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) →\n ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) →\n trans (c a₀ a₀) (c₁ a₀) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n ∃-cong λ _ → ∃-cong λ d₂ → drop-⊤-right λ _ →\n _⇔_.to contractible⇔↔⊤ $\n propositional⇒inhabited⇒contractible\n (B-groupoid)\n (d₂ _)) ⟩\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n ∃ λ (d₂ : (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) →\n ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) ↝⟨ (∃-cong λ _ → ∃-cong λ c → ∃-cong λ d → ∃-cong λ _ → ∃-cong λ c₂ →\n ∃-cong λ c₁ → drop-⊤-right λ d₂ →\n _⇔_.to contractible⇔↔⊤ $\n propositional⇒inhabited⇒contractible\n (Π-closure (lower-extensionality _ ℓ ext) 1 λ _ →\n Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 1 λ _ →\n B-groupoid)\n (λ a₁ a₂ →\n trans (c a₁ a₂) (c₁ a₂) ≡⟨ cong₂ trans (sym $ d _ _ _)\n (≡⇒↝ implication\n ([trans≡]≡[≡trans-symˡ] _ _ _) (d₂ _)) ⟩\n trans (trans (c a₁ a₀) (c a₀ a₂)) (trans (sym (c a₀ a₂)) c₂) ≡⟨ sym $ trans-assoc _ _ _ ⟩\n trans (trans (trans (c a₁ a₀) (c a₀ a₂)) (sym (c a₀ a₂))) c₂ ≡⟨ cong (flip trans _) $ trans-[trans]-sym _ _ ⟩\n trans (c a₁ a₀) c₂ ≡⟨ cong (trans _) $ sym $ d₂ _ ⟩\n trans (c a₁ a₀) (trans (c a₀ a₁) (c₁ a₁)) ≡⟨ sym $ trans-assoc _ _ _ ⟩\n trans (trans (c a₁ a₀) (c a₀ a₁)) (c₁ a₁) ≡⟨ cong (flip trans _) $ d _ _ _ ⟩\n trans (c a₁ a₁) (c₁ a₁) ≡⟨ cong (flip trans _) $\n Groupoid.idempotent⇒≡id (EG.groupoid _) (d _ _ _) ⟩\n trans (refl _) (c₁ a₁) ≡⟨ trans-reflˡ _ ⟩∎\n c₁ a₁ ∎)) ⟩\n\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) →\n ∃ λ (c₁ : (a : A) → f a ≡ f₁) →\n (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n inverse ΠΣ-comm) ⟩\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) →\n (a : A) → ∃ λ (c₁ : f a ≡ f₁) → trans (c a₀ a) c₁ ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n ∀-cong (lower-extensionality _ (a ⊔ ℓ) ext) λ _ → ∃-cong λ _ →\n ≡⇒↝ _ $ [trans≡]≡[≡trans-symˡ] _ _ _) ⟩\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) →\n (a : A) → ∃ λ (c₁ : f a ≡ f₁) → c₁ ≡ trans (sym (c a₀ a)) c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →\n drop-⊤-right λ _ →\n _⇔_.to contractible⇔↔⊤ $\n Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 0 λ _ →\n singleton-contractible _) ⟩\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) →\n ∃ λ (f₁ : B) → f a₀ ≡ f₁) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → drop-⊤-right λ _ →\n _⇔_.to contractible⇔↔⊤ $\n other-singleton-contractible _) ⟩□\n (∃ λ (f : A → B) → ∃ λ (c : Constant f) →\n ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) □)\n\n -- An alternative implementation of the forward component of the\n -- equivalence above (with shorter proofs).\n\n to : B → ∃ λ (f : A → B) → Coherently-constant f\n to b =\n (λ _ → b)\n , (λ _ _ → refl b)\n , (λ _ _ _ → trans-refl-refl)\n\n to-is-an-equivalence : A → Is-equivalence to\n to-is-an-equivalence a₀ =\n Eq.respects-extensional-equality\n (λ b →\n Σ-≡,≡→≡ (refl _) $\n Σ-≡,≡→≡\n (proj₁ (subst Coherently-constant\n (refl _)\n (proj₂ (_≃_.to (equivalence₁ a₀) b))) ≡⟨ cong proj₁ $ subst-refl Coherently-constant _ ⟩\n\n (λ _ _ → trans (refl b) (sym (refl b))) ≡⟨ (apply-ext (lower-extensionality _ ℓ ext) λ _ →\n apply-ext (lower-extensionality _ (a ⊔ ℓ) ext) λ _ →\n trans-symʳ _) ⟩∎\n (λ _ _ → refl b) ∎)\n ((Π-closure (lower-extensionality _ ℓ ext) 1 λ _ →\n Π-closure (lower-extensionality _ ℓ ext) 1 λ _ →\n Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 1 λ _ →\n B-groupoid) _ _))\n (_≃_.is-equivalence (equivalence₁ a₀))\n\n -- The forward component of the equivalence above does not depend on\n -- the value a₀ of type A, so it suffices to assume that A is merely\n -- inhabited.\n\n equivalence₂ :\n ∥ A ∥ 1 ℓ′ → (B ≃ ∃ λ (f : A → B) → Coherently-constant f)\n equivalence₂ ∥a∥ =\n Eq.⟨ to\n , rec 1\n (Eq.propositional (lower-extensionality _ ℓ ext) _)\n to-is-an-equivalence\n (with-lower-level ℓ 1 ∥a∥)\n ⟩\n\n-- Having a constant function into a set is equivalent to having a\n-- function from a propositionally truncated type into the set\n-- (assuming extensionality). The statement of this result is that of\n-- Proposition 2.2 in \"The General Universal Property of the\n-- Propositional Truncation\" by Kraus, but it uses a different proof:\n-- as observed by Kraus this result follows from Proposition 2.3.\n\nconstant-function≃∥inhabited∥⇒inhabited :\n ∀ {a b} ℓ {A : Type a} {B : Type b} →\n Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ) →\n Is-set B →\n (∃ λ (f : A → B) → Constant f) ≃ (∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B)\nconstant-function≃∥inhabited∥⇒inhabited {a} {b} ℓ {A} {B} ext B-set =\n (∃ λ (f : A → B) → Constant f) ↔⟨ (∃-cong λ f → inverse $ drop-⊤-right λ c →\n _⇔_.to contractible⇔↔⊤ $\n Π-closure (lower-extensionality _ ℓ ext) 0 λ _ →\n Π-closure (lower-extensionality _ ℓ ext) 0 λ _ →\n Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 0 λ _ →\n +⇒≡ B-set) ⟩\n (∃ λ (f : A → B) → Coherently-constant f) ↝⟨ coherently-constant-function≃∥inhabited∥⇒inhabited ℓ ext (mono₁ 2 B-set) ⟩□\n (∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B) □\n\nprivate\n\n -- One direction of the proposition above computes in the right way.\n\n to-constant-function≃∥inhabited∥⇒inhabited :\n ∀ {a b} ℓ {A : Type a} {B : Type b}\n (ext : Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ))\n (B-set : Is-set B)\n (f : ∃ λ (f : A → B) → Constant f) (x : A) →\n _≃_.to (constant-function≃∥inhabited∥⇒inhabited ℓ ext B-set)\n f ∣ x ∣₁ ≡ proj₁ f x\n to-constant-function≃∥inhabited∥⇒inhabited _ _ _ _ _ = refl _\n\n-- The propositional truncation's universal property (defined using\n-- extensionality).\n--\n-- As observed by Kraus this result follows from Proposition 2.2 in\n-- his \"The General Universal Property of the Propositional\n-- Truncation\".\n\nuniversal-property :\n ∀ {a b} ℓ {A : Type a} {B : Type b} →\n Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ) →\n Is-proposition B →\n (∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B) ≃ (A → B)\nuniversal-property {a = a} {b} ℓ {A} {B} ext B-prop =\n Eq.with-other-function\n ((∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B) ↝⟨ inverse $ constant-function≃∥inhabited∥⇒inhabited ℓ ext (mono₁ 1 B-prop) ⟩\n (∃ λ (f : A → B) → Constant f) ↔⟨ (drop-⊤-right λ _ →\n _⇔_.to contractible⇔↔⊤ $\n Π-closure (lower-extensionality _ ℓ ext) 0 λ _ →\n Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 0 λ _ →\n +⇒≡ B-prop) ⟩□\n (A → B) □)\n\n (_∘ ∣_∣₁)\n\n (λ f → apply-ext (lower-extensionality _ (a ⊔ ℓ) ext) λ x →\n subst (const B) (refl x) (f ∣ x ∣₁) ≡⟨ subst-refl _ _ ⟩∎\n f ∣ x ∣₁ ∎)\n\nprivate\n\n -- The universal property computes in the right way.\n\n to-universal-property :\n ∀ {a b} ℓ {A : Type a} {B : Type b}\n (ext : Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ))\n (B-prop : Is-proposition B)\n (f : ∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B) →\n _≃_.to (universal-property ℓ ext B-prop) f ≡ f ∘ ∣_∣₁\n to-universal-property _ _ _ _ = refl _\n\n from-universal-property :\n ∀ {a b} ℓ {A : Type a} {B : Type b}\n (ext : Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ))\n (B-prop : Is-proposition B)\n (f : A → B) (x : A) →\n _≃_.from (universal-property ℓ ext B-prop) f ∣ x ∣₁ ≡ f x\n from-universal-property _ _ _ _ _ = refl _\n\n-- Some properties of an imagined \"real\" /propositional/ truncation.\n\nmodule Real-propositional-truncation\n (∥_∥ʳ : ∀ {a} → Type a → Type a)\n (∣_∣ʳ : ∀ {a} {A : Type a} → A → ∥ A ∥ʳ)\n (truncation-is-proposition :\n ∀ {a} {A : Type a} → Is-proposition ∥ A ∥ʳ)\n (recʳ :\n ∀ {a b} {A : Type a} {B : Type b} →\n Is-proposition B →\n (A → B) → ∥ A ∥ʳ → B)\n where\n\n -- The function recʳ can be used to define a dependently typed\n -- eliminator (assuming extensionality).\n\n elimʳ :\n ∀ {a p} {A : Type a} →\n Extensionality a p →\n (P : ∥ A ∥ʳ → Type p) →\n (∀ x → Is-proposition (P x)) →\n ((x : A) → P ∣ x ∣ʳ) →\n (x : ∥ A ∥ʳ) → P x\n elimʳ {A = A} ext P P-prop f x =\n recʳ {A = A}\n {B = ∀ x → P x}\n (Π-closure ext 1 P-prop)\n (λ x _ → subst P\n (truncation-is-proposition _ _)\n (f x))\n x\n x\n\n -- The eliminator gives the right result, up to propositional\n -- equality, when applied to ∣ x ∣ʳ.\n\n elimʳ-∣∣ʳ :\n ∀ {a p} {A : Type a}\n (ext : Extensionality a p)\n (P : ∥ A ∥ʳ → Type p)\n (P-prop : ∀ x → Is-proposition (P x))\n (f : (x : A) → P ∣ x ∣ʳ)\n (x : A) →\n elimʳ ext P P-prop f ∣ x ∣ʳ ≡ f x\n elimʳ-∣∣ʳ ext P P-prop f x =\n P-prop _ _ _\n\n -- The \"real\" propositional truncation is isomorphic to the one\n -- defined above (assuming extensionality).\n\n isomorphic :\n ∀ {ℓ a} {A : Type a} →\n Extensionality (lsuc (a ⊔ ℓ)) (a ⊔ ℓ) →\n ∥ A ∥ʳ ↔ ∥ A ∥ 1 (a ⊔ ℓ)\n isomorphic {ℓ} ext = record\n { surjection = record\n { logical-equivalence = record\n { to = recʳ (truncation-has-correct-h-level 1 ext) ∣_∣₁\n ; from = lower {ℓ = ℓ} ∘\n rec 1\n (↑-closure 1 truncation-is-proposition)\n (lift ∘ ∣_∣ʳ)\n }\n ; right-inverse-of = λ _ →\n truncation-has-correct-h-level 1 ext _ _\n }\n ; left-inverse-of = λ _ → truncation-is-proposition _ _\n }\n\n-- The axiom of choice, in one of the alternative forms given in the\n-- HoTT book (§3.8).\n--\n-- The HoTT book uses a \"real\" propositional truncation, rather than\n-- the defined one used here. Note that I don't know if the universe\n-- levels used below (b ⊔ ℓ and a ⊔ b ⊔ ℓ) make sense. However, in the\n-- presence of a \"real\" propositional truncation (and extensionality)\n-- they can be dropped (see Real-propositional-truncation.isomorphic).\n\nAxiom-of-choice : (a b ℓ : Level) → Type (lsuc (a ⊔ b ⊔ ℓ))\nAxiom-of-choice a b ℓ =\n {A : Type a} {B : A → Type b} →\n Is-set A → (∀ x → ∥ B x ∥ 1 (b ⊔ ℓ)) → ∥ (∀ x → B x) ∥ 1 (a ⊔ b ⊔ ℓ)\n", "meta": {"hexsha": "38c92d9b004f4b8a015845ffc681fe7da92d73e7", "size": 46510, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/H-level/Truncation/Church.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/H-level/Truncation/Church.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/H-level/Truncation/Church.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": 45.111542192, "max_line_length": 146, "alphanum_fraction": 0.4026660933, "num_tokens": 17934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.682573734412324, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.38109934154670505}} {"text": "{-# OPTIONS --safe #-}\nmodule Cubical.Experiments.Brunerie where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Pointed\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Univalence\n\nopen import Cubical.Data.Bool\nopen import Cubical.Data.Nat\nopen import Cubical.Data.Int\n\nopen import Cubical.HITs.S1 hiding (encode)\nopen import Cubical.HITs.S2\nopen import Cubical.HITs.S3\nopen import Cubical.HITs.Join\nopen import Cubical.HITs.SetTruncation as SetTrunc\nopen import Cubical.HITs.GroupoidTruncation as GroupoidTrunc\nopen import Cubical.HITs.2GroupoidTruncation as 2GroupoidTrunc\nopen import Cubical.HITs.Truncation as Trunc\nopen import Cubical.HITs.Susp renaming (toSusp to σ)\n\nopen import Cubical.Homotopy.Loopspace\nopen import Cubical.Homotopy.Hopf\nopen S¹Hopf\n\n-- This code is adapted from examples/brunerie3.ctt on the pi4s3_nobug branch of cubicaltt\n\nBool∙ S¹∙ S³∙ : Pointed₀\nBool∙ = (Bool , true)\nS¹∙ = (S¹ , base)\nS³∙ = (S³ , base)\n\n∥_∥₃∙ ∥_∥₄∙ : Pointed₀ → Pointed₀\n∥ A , a ∥₃∙ = ∥ A ∥₃ , ∣ a ∣₃\n∥ A , a ∥₄∙ = ∥ A ∥₄ , ∣ a ∣₄\n\njoin∙ : Pointed₀ → Type₀ → Pointed₀\njoin∙ (A , a) B = join A B , inl a\n\nΩ² Ω³ : Pointed₀ → Pointed₀\nΩ² = Ω^ 2\nΩ³ = Ω^ 3\n\nmapΩrefl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω A .fst → Ω (B , f (pt A)) .fst\nmapΩrefl f p i = f (p i)\n\nmapΩ²refl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω² A .fst → Ω² (B , f (pt A)) .fst\nmapΩ²refl f p i j = f (p i j)\n\nmapΩ³refl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω³ A .fst → Ω³ (B , f (pt A)) .fst\nmapΩ³refl f p i j k = f (p i j k)\n\nmeridS² : S¹ → Path S² base base\nmeridS² base _ = base\nmeridS² (loop i) j = surf i j\n\nalpha : join S¹ S¹ → S²\nalpha (inl x) = base\nalpha (inr y) = base\nalpha (push x y i) = (meridS² y ∙ meridS² x) i\n\nconnectionBoth : {A : Type₀} {a : A} (p : Path A a a) → PathP (λ i → Path A (p i) (p i)) p p\nconnectionBoth {a = a} p i j =\n hcomp\n (λ k → λ\n { (i = i0) → p (j ∨ ~ k)\n ; (i = i1) → p (j ∧ k)\n ; (j = i0) → p (i ∨ ~ k)\n ; (j = i1) → p (i ∧ k)\n })\n a\n\ndata PostTotalHopf : Type₀ where\n base : S¹ → PostTotalHopf\n loop : (x : S¹) → PathP (λ i → Path PostTotalHopf (base x) (base (rotLoop x (~ i)))) refl refl\n\ntee12 : (x : S²) → HopfS² x → PostTotalHopf\ntee12 base y = base y\ntee12 (surf i j) y =\n hcomp\n (λ k → λ\n { (i = i0) → base y\n ; (i = i1) → base y\n ; (j = i0) → base y\n ; (j = i1) → base (rotLoopInv y (~ i) k)\n })\n (loop (unglue (i ∨ ~ i ∨ j ∨ ~ j) y) i j)\n\ntee34 : PostTotalHopf → join S¹ S¹\ntee34 (base x) = inl x\ntee34 (loop x i j) =\n hcomp\n (λ k → λ\n { (i = i0) → push x x (j ∧ ~ k)\n ; (i = i1) → push x x (j ∧ ~ k)\n ; (j = i0) → inl x\n ; (j = i1) → push (rotLoop x (~ i)) x (~ k)\n })\n (push x x j)\n\ntee : (x : S²) → HopfS² x → join S¹ S¹\ntee x y = tee34 (tee12 x y)\n\nfibΩ : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω B .fst → Type₀\nfibΩ P f p = PathP (λ i → P (p i)) f f\n\nfibΩ² : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω² B .fst → Type₀\nfibΩ² P f = fibΩ (fibΩ P f) refl\n\nfibΩ³ : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω³ B .fst → Type₀\nfibΩ³ P f = fibΩ² (fibΩ P f) refl\n\nΩ³Hopf : Ω³ S²∙ .fst → Type₀\nΩ³Hopf = fibΩ³ HopfS² base\n\nfibContrΩ³Hopf : ∀ p → Ω³Hopf p\nfibContrΩ³Hopf p i j k =\n hcomp\n (λ m → λ\n { (i = i0) → base\n ; (i = i1) → base\n ; (j = i0) → base\n ; (j = i1) → base\n ; (k = i0) → base\n ; (k = i1) →\n isSetΩS¹ refl refl\n (λ i j → transp (λ n → HopfS² (p i j n)) (i ∨ ~ i ∨ j ∨ ~ j) base)\n (λ _ _ → base)\n m i j\n })\n (transp (λ n → HopfS² (p i j (k ∧ n))) (i ∨ ~ i ∨ j ∨ ~ j ∨ ~ k) base)\n\nh : Ω³ S²∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst\nh p i j k = tee (p i j k) (fibContrΩ³Hopf p i j k)\n\nmultTwoAux : (x : S²) → Path (Path ∥ S² ∥₄ ∣ x ∣₄ ∣ x ∣₄) refl refl\nmultTwoAux base i j = ∣ surf i j ∣₄\nmultTwoAux (surf k l) i j =\n hcomp\n (λ m → λ\n { (i = i0) → ∣ surf k l ∣₄\n ; (i = i1) → ∣ surf k l ∣₄\n ; (j = i0) → ∣ surf k l ∣₄\n ; (j = i1) → ∣ surf k l ∣₄\n ; (k = i0) → ∣ surf i j ∣₄\n ; (k = i1) → ∣ surf i j ∣₄\n ; (l = i0) → ∣ surf i j ∣₄\n ; (l = i1) → squash₄ _ _ _ _ _ _ (λ k i j → step₁ k i j) refl m k i j\n })\n (step₁ k i j)\n\n where\n step₁ : I → I → I → ∥ S² ∥₄\n step₁ k i j =\n hcomp {A = ∥ S² ∥₄}\n (λ m → λ\n { (i = i0) → ∣ surf k (l ∧ m) ∣₄\n ; (i = i1) → ∣ surf k (l ∧ m) ∣₄\n ; (j = i0) → ∣ surf k (l ∧ m) ∣₄\n ; (j = i1) → ∣ surf k (l ∧ m) ∣₄\n ; (k = i0) → ∣ surf i j ∣₄\n ; (k = i1) → ∣ surf i j ∣₄\n ; (l = i0) → ∣ surf i j ∣₄\n })\n ∣ surf i j ∣₄\n\nmultTwoTildeAux : (t : ∥ S² ∥₄) → Path (Path ∥ S² ∥₄ t t) refl refl\nmultTwoTildeAux ∣ x ∣₄ = multTwoAux x\nmultTwoTildeAux (squash₄ _ _ _ _ _ _ t u k l m n) i j =\n squash₄ _ _ _ _ _ _\n (λ k l m → multTwoTildeAux (t k l m) i j)\n (λ k l m → multTwoTildeAux (u k l m) i j)\n k l m n\n\nmultTwoEquivAux : Path (Path (∥ S² ∥₄ ≃ ∥ S² ∥₄) (idEquiv _) (idEquiv _)) refl refl\nmultTwoEquivAux i j =\n ( f i j\n , hcomp\n (λ l → λ\n { (i = i0) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l\n ; (i = i1) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l\n ; (j = i0) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l\n ; (j = i1) →\n isPropIsEquiv _\n (transp (λ k → isEquiv (f i k)) (i ∨ ~ i) (idIsEquiv _))\n (idIsEquiv _)\n l\n })\n (transp (λ k → isEquiv (f i (j ∧ k))) (i ∨ ~ i ∨ ~ j) (idIsEquiv _))\n )\n where\n f : I → I → ∥ S² ∥₄ → ∥ S² ∥₄\n f i j t = multTwoTildeAux t i j\n\ntHopf³ : S³ → Type₀\ntHopf³ base = ∥ S² ∥₄\ntHopf³ (surf i j k) =\n Glue ∥ S² ∥₄\n (λ { (i = i0) → (∥ S² ∥₄ , idEquiv _)\n ; (i = i1) → (∥ S² ∥₄ , idEquiv _)\n ; (j = i0) → (∥ S² ∥₄ , idEquiv _)\n ; (j = i1) → (∥ S² ∥₄ , idEquiv _)\n ; (k = i0) → (∥ S² ∥₄ , multTwoEquivAux i j)\n ; (k = i1) → (∥ S² ∥₄ , idEquiv _)\n })\n\nπ₃S³ : Ω³ S³∙ .fst → Ω² ∥ S²∙ ∥₄∙ .fst\nπ₃S³ p i j = transp (λ k → tHopf³ (p j k i)) i0 ∣ base ∣₄\n\ncodeS² : S² → hGroupoid _\ncodeS² s = ∥ HopfS² s ∥₃ , squash₃\n\ncodeTruncS² : ∥ S² ∥₄ → hGroupoid _\ncodeTruncS² = 2GroupoidTrunc.rec (isOfHLevelTypeOfHLevel 3) codeS²\n\nencodeTruncS² : Ω ∥ S²∙ ∥₄∙ .fst → ∥ S¹ ∥₃\nencodeTruncS² p = transp (λ i → codeTruncS² (p i) .fst) i0 ∣ base ∣₃\n\ncodeS¹ : S¹ → hSet _\ncodeS¹ s = ∥ helix s ∥₂ , squash₂\n\ncodeTruncS¹ : ∥ S¹ ∥₃ → hSet _\ncodeTruncS¹ = GroupoidTrunc.rec (isOfHLevelTypeOfHLevel 2) codeS¹\n\nencodeTruncS¹ : Ω ∥ S¹∙ ∥₃∙ .fst → ∥ ℤ ∥₂\nencodeTruncS¹ p = transp (λ i → codeTruncS¹ (p i) .fst) i0 ∣ pos zero ∣₂\n\n\n-- THE BIG GAME\n\nf3 : Ω³ S³∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst\nf3 = mapΩ³refl S³→joinS¹S¹\n\nf4 : Ω³ (join∙ S¹∙ S¹) .fst → Ω³ S²∙ .fst\nf4 = mapΩ³refl alpha\n\nf5 : Ω³ S²∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst\nf5 = h\n\nf6 : Ω³ (join∙ S¹∙ S¹) .fst → Ω³ S³∙ .fst\nf6 = mapΩ³refl joinS¹S¹→S³\n\nf7 : Ω³ S³∙ .fst → Ω² ∥ S²∙ ∥₄∙ .fst\nf7 = π₃S³\n\ng8 : Ω² ∥ S²∙ ∥₄∙ .fst → Ω ∥ S¹∙ ∥₃∙ .fst\ng8 = mapΩrefl encodeTruncS²\n\ng9 : Ω ∥ S¹∙ ∥₃∙ .fst → ∥ ℤ ∥₂\ng9 = encodeTruncS¹\n\ng10 : ∥ ℤ ∥₂ → ℤ\ng10 = SetTrunc.rec isSetℤ (idfun ℤ)\n\n-- don't run me\nbrunerie : ℤ\nbrunerie = g10 (g9 (g8 (f7 (f6 (f5 (f4 (f3 (λ i j k → surf i j k))))))))\n\n-- simpler tests\n\ntest63 : ℕ → ℤ\ntest63 n = g10 (g9 (g8 (f7 (63n n))))\n where\n 63n : ℕ → Ω³ S³∙ .fst\n 63n zero i j k = surf i j k\n 63n (suc n) = f6 (f3 (63n n))\n\nfoo : Ω³ S²∙ .fst\nfoo i j k =\n hcomp\n (λ l → λ\n { (i = i0) → surf l l\n ; (i = i1) → surf l l\n ; (j = i0) → surf l l\n ; (j = i1) → surf l l\n ; (k = i0) → surf l l\n ; (k = i1) → surf l l\n })\n base\n\nsorghum : Ω³ S²∙ .fst\nsorghum i j k =\n hcomp\n (λ l → λ\n { (i = i0) → surf j l\n ; (i = i1) → surf k (~ l)\n ; (j = i0) → surf k (i ∧ ~ l)\n ; (j = i1) → surf k (i ∧ ~ l)\n ; (k = i0) → surf j (i ∨ l)\n ; (k = i1) → surf j (i ∨ l)\n })\n (hcomp\n (λ l → λ\n { (i = i0) → base\n ; (i = i1) → surf j l\n ; (j = i0) → surf k i\n ; (j = i1) → surf k i\n ; (k = i0) → surf j (i ∧ l)\n ; (k = i1) → surf j (i ∧ l)\n })\n (surf k i))\n\ngoo : Ω³ S²∙ .fst → ℤ\ngoo x = g10 (g9 (g8 (f7 (f6 (f5 x)))))\n\n\n{- Computation of an alternative definition of the Brunerie number\nbased on https://github.com/agda/cubical/pull/741. One should note\nthat this computation by no means is comparable to the one of the term\n\"brunerie\" defined above. This computation starts in π₃S³ rather than\nπ₃S². -}\n\n-- The brunerie element can be shown to correspond to the following map\nη₃ : (join S¹ S¹ , inl base) →∙ (Susp S² , north)\nfst η₃ (inl x) = north\nfst η₃ (inr x) = north\nfst η₃ (push a b i) =\n (σ (S² , base) (S¹×S¹→S² a b) ∙ σ (S² , base) (S¹×S¹→S² a b)) i\n where\n S¹×S¹→S² : S¹ → S¹ → S²\n S¹×S¹→S² base y = base\n S¹×S¹→S² (loop i) base = base\n S¹×S¹→S² (loop i) (loop j) = surf i j\nsnd η₃ = refl\n\nK₂ = ∥ S² ∥₄\n-- We will need a map Ω (Susp S²) → K₂. It turns out that the\n-- following map is fast. It need a bit of work, however. It's\n-- esentially the same map as you find in ZCohomology from ΩKₙ₊₁ to\n-- Kₙ. This gives another definition of f7 which appears to work better.\n\nmodule f7stuff where\n _+₂_ : K₂ → K₂ → K₂\n _+₂_ = 2GroupoidTrunc.elim (λ _ → isOfHLevelΠ 4 λ _ → squash₄)\n λ { base x → x\n ; (surf i j) x → surfc x i j}\n where\n surfc : (x : K₂) → typ ((Ω^ 2) (K₂ , x))\n surfc =\n 2GroupoidTrunc.elim\n (λ _ → isOfHLevelPath 4 (isOfHLevelPath 4 squash₄ _ _) _ _)\n (S²ToSetElim (λ _ → squash₄ _ _ _ _) λ i j → ∣ surf i j ∣₄)\n\n K₂≃K₂ : (x : S²) → K₂ ≃ K₂\n fst (K₂≃K₂ x) y = ∣ x ∣₄ +₂ y\n snd (K₂≃K₂ x) = help x\n where\n help : (x : _) → isEquiv (λ y → ∣ x ∣₄ +₂ y)\n help = S²ToSetElim (λ _ → isProp→isSet (isPropIsEquiv _))\n (idEquiv _ .snd)\n\n Code : Susp S² → Type ℓ-zero\n Code north = K₂\n Code south = K₂\n Code (merid a i) = ua (K₂≃K₂ a) i\n\n encode : (x : Susp S²) → north ≡ x → Code x\n encode x = J (λ x p → Code x) ∣ base ∣₄\n\n-- We now get an alternative definition of f7\nf7' : typ (Ω (Susp∙ S²)) → K₂\nf7' = f7stuff.encode north\n\n-- We can define the Brunerie number by\nbrunerie' : ℤ\nbrunerie' = g10 (g9 (g8 λ i j → f7' λ k → η₃ .fst (push (loop i) (loop j) k)))\n\n-- Computing it takes ~1s\nbrunerie'≡-2 : brunerie' ≡ -2\nbrunerie'≡-2 = refl\n", "meta": {"hexsha": "18f32581411200f6cec8e488ce637b4a0ec2dda2", "size": 10388, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Experiments/Brunerie.agda", "max_stars_repo_name": "xekoukou/cubical", "max_stars_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc", "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": "Cubical/Experiments/Brunerie.agda", "max_issues_repo_name": "xekoukou/cubical", "max_issues_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc", "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": "Cubical/Experiments/Brunerie.agda", "max_forks_repo_name": "xekoukou/cubical", "max_forks_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc", "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": 27.7754010695, "max_line_length": 96, "alphanum_fraction": 0.5338852522, "num_tokens": 4940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432182679956, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3805871246298595}} {"text": "open import Level\nopen import Ordinals\nmodule filter {n : Level } (O : Ordinals {n}) where\n\nopen import zf\nopen import logic\nimport OD \n\nopen import Relation.Nullary \nopen import Data.Empty \nopen import Relation.Binary.Core\nopen import Relation.Binary.PropositionalEquality\nimport BAlgbra \n\nopen BAlgbra O\n\nopen inOrdinal O\nopen OD O\nopen OD.OD\nopen ODAxiom odAxiom\n\nimport OrdUtil\nimport ODUtil\nopen Ordinals.Ordinals O\nopen Ordinals.IsOrdinals isOrdinal\nopen Ordinals.IsNext isNext\nopen OrdUtil O\nopen ODUtil O\n\n\nimport ODC\nopen ODC O\n\nopen _∧_\nopen _∨_\nopen Bool\n\n-- Kunen p.76 and p.53, we use ⊆\nrecord Filter ( L : HOD ) : Set (suc n) where\n field\n filter : HOD \n f⊆PL : filter ⊆ Power L \n filter1 : { p q : HOD } → q ⊆ L → filter ∋ p → p ⊆ q → filter ∋ q\n filter2 : { p q : HOD } → filter ∋ p → filter ∋ q → filter ∋ (p ∩ q)\n\nopen Filter\n\nrecord prime-filter { L : HOD } (P : Filter L) : Set (suc (suc n)) where\n field\n proper : ¬ (filter P ∋ od∅)\n prime : {p q : HOD } → filter P ∋ (p ∪ q) → ( filter P ∋ p ) ∨ ( filter P ∋ q )\n\nrecord ultra-filter { L : HOD } (P : Filter L) : Set (suc (suc n)) where\n field\n proper : ¬ (filter P ∋ od∅)\n ultra : {p : HOD } → p ⊆ L → ( filter P ∋ p ) ∨ ( filter P ∋ ( L \ p) )\n\nopen _⊆_\n\n∈-filter : {L p : HOD} → (P : Filter L ) → filter P ∋ p → p ⊆ L\n∈-filter {L} {p} P lt = power→⊆ L p ( incl (f⊆PL P) lt )\n\n∪-lemma1 : {L p q : HOD } → (p ∪ q) ⊆ L → p ⊆ L\n∪-lemma1 {L} {p} {q} lt = record { incl = λ {x} p∋x → incl lt (case1 p∋x) }\n\n∪-lemma2 : {L p q : HOD } → (p ∪ q) ⊆ L → q ⊆ L\n∪-lemma2 {L} {p} {q} lt = record { incl = λ {x} p∋x → incl lt (case2 p∋x) }\n\nq∩q⊆q : {p q : HOD } → (q ∩ p) ⊆ q \nq∩q⊆q = record { incl = λ lt → proj1 lt } \n\nopen HOD\n\n-----\n--\n-- ultra filter is prime\n--\n\nfilter-lemma1 : {L : HOD} → (P : Filter L) → ∀ {p q : HOD } → ultra-filter P → prime-filter P \nfilter-lemma1 {L} P u = record {\n proper = ultra-filter.proper u\n ; prime = lemma3\n } where\n lemma3 : {p q : HOD} → filter P ∋ (p ∪ q) → ( filter P ∋ p ) ∨ ( filter P ∋ q )\n lemma3 {p} {q} lt with ultra-filter.ultra u (∪-lemma1 (∈-filter P lt) )\n ... | case1 p∈P = case1 p∈P\n ... | case2 ¬p∈P = case2 (filter1 P {q ∩ (L \ p)} (∪-lemma2 (∈-filter P lt)) lemma7 lemma8) where\n lemma5 : ((p ∪ q ) ∩ (L \ p)) =h= (q ∩ (L \ p))\n lemma5 = record { eq→ = λ {x} lt → ⟪ lemma4 x lt , proj2 lt ⟫\n ; eq← = λ {x} lt → ⟪ case2 (proj1 lt) , proj2 lt ⟫\n } where\n lemma4 : (x : Ordinal ) → odef ((p ∪ q) ∩ (L \ p)) x → odef q x\n lemma4 x lt with proj1 lt\n lemma4 x lt | case1 px = ⊥-elim ( proj2 (proj2 lt) px )\n lemma4 x lt | case2 qx = qx\n lemma6 : filter P ∋ ((p ∪ q ) ∩ (L \ p))\n lemma6 = filter2 P lt ¬p∈P\n lemma7 : filter P ∋ (q ∩ (L \ p))\n lemma7 = subst (λ k → filter P ∋ k ) (==→o≡ lemma5 ) lemma6\n lemma8 : (q ∩ (L \ p)) ⊆ q\n lemma8 = q∩q⊆q\n\n-----\n--\n-- if Filter contains L, prime filter is ultra\n--\n\nfilter-lemma2 : {L : HOD} → (P : Filter L) → filter P ∋ L → prime-filter P → ultra-filter P\nfilter-lemma2 {L} P f∋L prime = record {\n proper = prime-filter.proper prime\n ; ultra = λ {p} p⊆L → prime-filter.prime prime (lemma p p⊆L)\n } where\n open _==_\n p+1-p=1 : {p : HOD} → p ⊆ L → L =h= (p ∪ (L \ p)) \n eq→ (p+1-p=1 {p} p⊆L) {x} lt with ODC.decp O (odef p x)\n eq→ (p+1-p=1 {p} p⊆L) {x} lt | yes p∋x = case1 p∋x\n eq→ (p+1-p=1 {p} p⊆L) {x} lt | no ¬p = case2 ⟪ lt , ¬p ⟫\n eq← (p+1-p=1 {p} p⊆L) {x} ( case1 p∋x ) = subst (λ k → odef L k ) &iso (incl p⊆L ( subst (λ k → odef p k) (sym &iso) p∋x )) \n eq← (p+1-p=1 {p} p⊆L) {x} ( case2 ¬p ) = proj1 ¬p\n lemma : (p : HOD) → p ⊆ L → filter P ∋ (p ∪ (L \ p))\n lemma p p⊆L = subst (λ k → filter P ∋ k ) (==→o≡ (p+1-p=1 p⊆L)) f∋L\n\nrecord Dense (P : HOD ) : Set (suc n) where\n field\n dense : HOD\n d⊆P : dense ⊆ Power P \n dense-f : HOD → HOD\n dense-d : { p : HOD} → p ⊆ P → dense ∋ dense-f p \n dense-p : { p : HOD} → p ⊆ P → p ⊆ (dense-f p) \n\nrecord Ideal ( L : HOD ) : Set (suc n) where\n field\n ideal : HOD \n i⊆PL : ideal ⊆ Power L \n ideal1 : { p q : HOD } → q ⊆ L → ideal ∋ p → q ⊆ p → ideal ∋ q\n ideal2 : { p q : HOD } → ideal ∋ p → ideal ∋ q → ideal ∋ (p ∪ q)\n\nopen Ideal\n\nproper-ideal : {L : HOD} → (P : Ideal L ) → {p : HOD} → Set n\nproper-ideal {L} P {p} = ideal P ∋ od∅\n\nprime-ideal : {L : HOD} → Ideal L → ∀ {p q : HOD } → Set n\nprime-ideal {L} P {p} {q} = ideal P ∋ ( p ∩ q) → ( ideal P ∋ p ) ∨ ( ideal P ∋ q )\n\n----\n--\n-- Filter/Ideal without ZF \n-- L have to be a Latice\n--\n\nrecord F-Filter {n : Level} (L : Set n) (PL : (L → Set n) → Set n) ( _⊆_ : L → L → Set n) (_∩_ : L → L → L ) : Set (suc n) where\n field\n filter : L → Set n\n f⊆P : PL filter \n filter1 : { p q : L } → PL (λ x → q ⊆ x ) → filter p → p ⊆ q → filter q\n filter2 : { p q : L } → filter p → filter q → filter (p ∩ q)\n\nFilter-is-F : {L : HOD} → (f : Filter L ) → F-Filter HOD (λ p → (x : HOD) → p x → x ⊆ L ) _⊆_ _∩_\nFilter-is-F {L} f = record {\n filter = λ x → Lift (suc n) ((filter f) ∋ x)\n ; f⊆P = λ x f∋x → power→⊆ _ _ (incl ( f⊆PL f ) (lower f∋x ))\n ; filter1 = λ {p} {q} q⊆L f∋p p⊆q → lift ( filter1 f (q⊆L q refl-⊆) (lower f∋p) p⊆q)\n ; filter2 = λ {p} {q} f∋p f∋q → lift ( filter2 f (lower f∋p) (lower f∋q)) \n }\n\nrecord F-Dense {n : Level} (L : Set n) (PL : (L → Set n) → Set n) ( _⊆_ : L → L → Set n) (_∩_ : L → L → L ) : Set (suc n) where\n field\n dense : L → Set n\n d⊆P : PL dense \n dense-f : L → L \n dense-d : { p : L} → PL (λ x → p ⊆ x ) → dense ( dense-f p )\n dense-p : { p : L} → PL (λ x → p ⊆ x ) → p ⊆ (dense-f p) \n\nDense-is-F : {L : HOD} → (f : Dense L ) → F-Dense HOD (λ p → (x : HOD) → p x → x ⊆ L ) _⊆_ _∩_\nDense-is-F {L} f = record {\n dense = λ x → Lift (suc n) ((dense f) ∋ x)\n ; d⊆P = λ x f∋x → power→⊆ _ _ (incl ( d⊆P f ) (lower f∋x ))\n ; dense-f = λ x → dense-f f x\n ; dense-d = λ {p} d → lift ( dense-d f (d p refl-⊆ ) )\n ; dense-p = λ {p} d → dense-p f (d p refl-⊆) \n } where open Dense\n\n \nrecord GenericFilter (P : HOD) : Set (suc n) where\n field\n genf : Filter P\n generic : (D : Dense P ) → ¬ ( (Dense.dense D ∩ Filter.filter genf ) ≡ od∅ )\n\nrecord F-GenericFilter {n : Level} (L : Set n) (PL : (L → Set n) → Set n) ( _⊆_ : L → L → Set n) (_∩_ : L → L → L ) : Set (suc n) where\n field\n GFilter : F-Filter L PL _⊆_ _∩_\n Intersection : (D : F-Dense L PL _⊆_ _∩_ ) → { x : L } → F-Dense.dense D x → L\n Generic : (D : F-Dense L PL _⊆_ _∩_ ) → { x : L } → ( y : F-Dense.dense D x) → F-Filter.filter GFilter (Intersection D y )\n\n", "meta": {"hexsha": "8aabd8a20db7f4452e11ef0b84bc210e6501b248", "size": 6801, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/filter.agda", "max_stars_repo_name": "shinji-kono/zf-in-agda", "max_stars_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-10-02T13:46:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-10T13:27:48.000Z", "max_issues_repo_path": "src/filter.agda", "max_issues_repo_name": "shinji-kono/zf-in-agda", "max_issues_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "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/filter.agda", "max_forks_repo_name": "shinji-kono/zf-in-agda", "max_forks_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "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": 34.6989795918, "max_line_length": 137, "alphanum_fraction": 0.492280547, "num_tokens": 2979, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.38058711831767106}} {"text": "{-# OPTIONS --allow-unsolved-metas #-}\n\nopen import Prelude hiding (⊤)\n\nmodule Control.Monad.Free.State {ℓ} (S : Type ℓ) (isSetS : isSet S) where\n\nopen import Control.Monad.Free.Quotiented\nopen import Data.Unit.UniversePolymorphic\nopen import Algebra\nopen import Data.List\nopen import Data.List.Syntax\n\ndata StateF (A : Type ℓ) : Type ℓ where\n getF : (k : S → A) → StateF A\n putF : (s : S) (k : A) → StateF A\n\nmodule Laws where\n open RawMonadSyntax\n put : S → Syntax StateF ⊤\n put x = lift (putF x _)\n\n get : Syntax StateF S\n get = lift (getF id)\n\n law₁ law₂ law₃ law₄ : Law StateF\n\n law₁ .Γ = S × S\n\n law₁ .ν = ⊤\n law₁ .eqn (u , u′) .lhs = do put u\n put u′\n law₁ .eqn (u , u′) .rhs = put u′\n\n law₂ .Γ = S\n law₂ .ν = S\n law₂ .eqn u .lhs = do put u\n u′ ← get\n return u′\n law₂ .eqn u .rhs = do put u\n return u\n\n law₃ .Γ = ⊤\n law₃ .ν = S × S\n law₃ .eqn _ .lhs = do s ← get\n s′ ← get\n return (s , s′)\n law₃ .eqn _ .rhs = do s ← get\n return (s , s)\n\n law₄ .Γ = ⊤\n law₄ .ν = ⊤\n law₄ .eqn _ .lhs = do s ← get\n put s\n law₄ .eqn _ .rhs = return tt\n\n StateLaws : Theory StateF\n StateLaws = [ law₁ , law₂ , law₃ , law₄ ]\n\nopen Laws using (StateLaws)\n\nState : Type ℓ → Type _\nState = Free StateF StateLaws\n\nget : State S\nget = lift (getF id)\n\nput : S → State ⊤\nput x = lift (putF x _)\n\nstate-alg : Φ[ StateF ⋆ A / StateLaws ] ⇒ (S → A × S)\nstate-alg .fst (liftF (getF k)) s = k s , s\nstate-alg .fst (liftF (putF s₂ k)) s₁ = k , s₂\nstate-alg .fst (returnF x) s = x , s\nstate-alg .fst (bindF _ P⟨xs⟩ _ P⟨∘k⟩) s = uncurry P⟨∘k⟩ (P⟨xs⟩ s)\nstate-alg .snd .c->>=idˡ f Pf x = refl\nstate-alg .snd .c->>=idʳ x Px = refl\nstate-alg .snd .c->>=assoc xs Pxs f Pf g Pg = refl\nstate-alg .snd .c-quot (0 , p) γ = refl\nstate-alg .snd .c-quot (1 , p) γ = refl\nstate-alg .snd .c-quot (2 , p) γ = refl\nstate-alg .snd .c-quot (3 , p) γ = refl\n\nrunState : State A → S → A × S\nrunState = ⟦ state-alg ⟧\n\nopen FreeMonadSyntax\n\nfromState : (S → A × S) → State A\nfromState k = do\n s₁ ← get\n let x , s₂ = k s₁\n put s₂\n return x\n\nopen import HITs.PropositionalTruncation\nopen import Relation.Binary.Equivalence.PropHIT\nopen import Path.Reasoning\n\nstate-state : isSet A → State A ⇔ (S → A × S)\nstate-state _ .fun = runState\nstate-state _ .inv = fromState\nstate-state _ .rightInv _ = refl\nstate-state isSetA .leftInv xs = ⟦ lemma ⟧ xs\n where\n dup : S → S × S\n dup x = x , x\n\n lemma : Ψ[ xs ⦂ StateF ⋆ * / StateLaws ] ⇒ (fromState (runState xs) ≡ xs)\n lemma .snd = prop-coh λ _ → uip _ _\n\n lemma .fst (liftF (getF k)) =\n fromState (runState (lift (getF k))) ≡⟨ {!!} ⟩\n lift (getF k) ∎\n\n lemma .fst (liftF (putF s k)) =\n fromState (runState (lift (putF s k))) ≡⟨ {!!} ⟩\n lift (putF s k) ∎\n\n lemma .fst (returnF x) =\n fromState (runState (return x)) ≡⟨⟩\n fromState (λ s → x , s) ≡⟨⟩\n (get >>= λ s → put s >> return x) ≡˘⟨ >>=-assoc get put (const (return x)) ⟩\n ((get >>= put) >> return x) ≡⟨ cong (_>> return x) (quot (3 , _) tt) ⟩\n (return tt >> return x) ≡⟨ >>=-idˡ (const (return x)) tt ⟩\n return x ∎\n\n lemma .fst (bindF xs P⟨xs⟩ k P⟨∘k⟩) =\n fromState (runState (xs >>= k)) ≡⟨⟩\n fromState (λ s → uncurry (runState ∘ k) (runState xs s)) ≡⟨⟩\n (get >>= λ s₁ → let x , s₂ = uncurry (runState ∘ k) (runState xs s₁) in put s₂ >> return x) ≡⟨⟩\n (get >>= λ s₁ → let x , s₂ = runState xs s₁ ; y , s₃ = runState (k x) s₂ in put s₃ >> return y) ≡⟨ {!!} ⟩\n (fromState (runState xs) >>= (fromState ∘ runState ∘ k)) ≡⟨ cong₂ Free._>>=_ P⟨xs⟩ (funExt P⟨∘k⟩) ⟩\n (xs >>= k) ∎\n\nfunctorState : Functor ℓ ℓ\nfunctorState .Functor.𝐹 = StateF\nfunctorState .Functor.map f (getF k) = getF (f ∘ k)\nfunctorState .Functor.map f (putF s k) = putF s (f k)\nfunctorState .Functor.map-id i (getF k) = getF k\nfunctorState .Functor.map-id i (putF s k) = putF s k\nfunctorState .Functor.map-comp f g i (getF k) = getF (f ∘ g ∘ k)\nfunctorState .Functor.map-comp f g i (putF s k) = putF s (f (g k))\n\n-- runState′ : isSet A → State A → S → A × S\n-- runState′ isSetA = cata functorState (isSetState isSetA) _,_ ϕ ℒ\n-- where\n-- ϕ : StateF (S → A × S) → S → A × S\n-- ϕ (getF k) s = k s s\n-- ϕ (putF s₂ k) s₁ = k s₂\n\n-- ℒ : InTheory functorState {𝒯 = StateLaws} (isSetState isSetA) ϕ\n-- ℒ (0 , p) f iss e = refl\n-- ℒ (1 , p) f iss e = refl\n-- ℒ (2 , p) f iss e = refl\n-- ℒ (3 , p) f iss e = refl\n\n-- -- open import Data.Nat using (_∸_)\n\n-- -- example : State ℕ ℕ\n-- -- example = do\n-- -- x ← get\n-- -- put (suc x)\n-- -- put x\n-- -- return (x ∸ 1)\n\n-- -- res : ℕ × ℕ\n-- -- res = runState example 5\n", "meta": {"hexsha": "7085f9895f8a0ff55d13f26a65d1e9c6d8bbd995", "size": 4716, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Control/Monad/Free/State.agda", "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_issues_repo_path": "Control/Monad/Free/State.agda", "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "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": "Control/Monad/Free/State.agda", "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "avg_line_length": 28.0714285714, "max_line_length": 109, "alphanum_fraction": 0.5536471586, "num_tokens": 1915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.3805522035353654}} {"text": "{-# OPTIONS --cubical --safe #-}\n\nmodule Cubical.Data.Fin.Properties where\n\nopen import Cubical.Core.Everything\n\nopen import Cubical.Foundations.Embedding\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Univalence\n\nopen import Cubical.Data.Fin.Base\nopen import Cubical.Data.Nat\nopen import Cubical.Data.Nat.Order\nopen import Cubical.Data.Empty\nopen import Cubical.Data.Sum\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Induction.WellFounded\n\nprivate\n -- Σ is more convenient than the inductive ×, but I don't\n -- want to have to write λ_→ all over.\n _×_ : Type₀ → Type₀ → Type₀\n A × B = Σ A λ _ → B\n\n-- Fin 0 is empty, and thus a proposition.\nFin0-isProp : isProp (Fin 0)\nFin0-isProp = ⊥-elim ∘ ¬Fin0\n\n-- Fin 1 has only one value.\nFin1-isContr : isContr (Fin 1)\nFin1-isContr\n = fzero , λ\n { (zero , _) → toℕ-injective refl\n ; (suc k , sk<1) → ⊥-elim (¬-<-zero (pred-≤-pred sk<1))\n }\n\n-- Regardless of k, Fin k is a set.\nisSetFin : ∀{k} → isSet (Fin k)\nisSetFin {k} = isOfHLevelΣ 2 isSetℕ (λ _ → isProp→isSet m≤n-isProp)\n\n-- Helper function for the reduction procedure below.\n--\n-- If n = expand o k m, then n is congruent to m modulo k.\nexpand : ℕ → ℕ → ℕ → ℕ\nexpand 0 k m = m\nexpand (suc o) k m = k + expand o k m\n\nexpand≡ : ∀ k m o → expand o k m ≡ o * k + m\nexpand≡ k m zero = refl\nexpand≡ k m (suc o)\n = cong (k +_) (expand≡ k m o) ∙ +-assoc k (o * k) m\n\n-- Expand a pair. This is useful because the whole function is\n-- injective.\nexpand× : ∀{k} → (Fin k × ℕ) → ℕ\nexpand× {k} (f , o) = expand o k (toℕ f)\n\nprivate\n lemma₀ : ∀{k m n r} → r ≡ n → k + m ≡ n → k ≤ r\n lemma₀ {k = k} {m} p q = m , +-comm m k ∙ q ∙ sym p\n\n expand×Inj : ∀ k → {t1 t2 : Fin (suc k) × ℕ} → expand× t1 ≡ expand× t2 → t1 ≡ t2\n expand×Inj k {f1 , zero} {f2 , zero} p i\n = toℕ-injective {fj = f1} {f2} p i , zero\n expand×Inj k {f1 , suc o1} {(r , r b) = Inr (λ ())\n ground-decidable (b ==> ⦇·⦈) = Inr (λ ())\n ground-decidable (b ==> τ' ==> τ'') = Inr (λ ())\n ground-decidable (b ==> τ₁ ⊗ τ₂) = Inr (λ ())\n ground-decidable (⦇·⦈ ==> b) = Inr (λ ())\n ground-decidable (⦇·⦈ ==> ⦇·⦈) = Inl GHole\n ground-decidable (⦇·⦈ ==> τ' ==> τ'') = Inr (λ ())\n ground-decidable ((τ ==> τ₁) ==> b) = Inr (λ ())\n ground-decidable ((τ ==> τ₁) ==> ⦇·⦈) = Inr (λ ())\n ground-decidable ((τ ==> τ₁) ==> τ' ==> τ'') = Inr (λ ())\n ground-decidable ((τ ⊗ τ₂) ==> τ₁) = Inr (λ ())\n ground-decidable (τ ⊗ b) = Inr (λ ())\n ground-decidable (b ⊗ ⦇·⦈) = Inr (λ ())\n ground-decidable (⦇·⦈ ⊗ ⦇·⦈) = Inl GProd\n ground-decidable (⦇·⦈ ==> τ₁ ⊗ τ₂) = Inr (λ ())\n ground-decidable ((τ ⊗ τ₁) ⊗ ⦇·⦈) = Inr (λ ())\n ground-decidable ((τ ==> τ₁) ⊗ ⦇·⦈) = Inr (λ ())\n ground-decidable ((τ ==> τ₂) ==> τ₁ ⊗ τ₃) = Inr (λ ())\n ground-decidable (τ ⊗ τ₁ ==> τ₂) = Inr (λ ())\n ground-decidable (τ ⊗ τ₁ ⊗ τ₂) = Inr (λ ())\n", "meta": {"hexsha": "ce87fd6d0a944d22d071d865b3c4ee77672e6cf5", "size": 1207, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "ground-decidable.agda", "max_stars_repo_name": "hazelgrove/hazel-palette-agda", "max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z", "max_issues_repo_path": "ground-decidable.agda", "max_issues_repo_name": "hazelgrove/hazel-palette-agda", "max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z", "max_forks_repo_path": "ground-decidable.agda", "max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda", "max_forks_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a", "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": 41.6206896552, "max_line_length": 62, "alphanum_fraction": 0.5053852527, "num_tokens": 547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583124210896, "lm_q2_score": 0.546738151984614, "lm_q1q2_score": 0.38050696159143715}} {"text": "module PiFrac.Eval where\nopen import Data.Empty\nopen import Data.Unit hiding (_≟_)\nopen import Data.Sum\nopen import Data.Product\nopen import Data.List as L hiding (_∷_)\nopen import Data.Maybe\nopen import Relation.Binary.Core\nopen import Relation.Binary\nopen import Relation.Nullary\nopen import Relation.Binary.PropositionalEquality\nopen import Function using (_∘_)\nopen import PiFrac.Syntax\nopen import PiFrac.Opsem\nopen import PiFrac.NoRepeat\n\n-- Stuck states must be either of the form [ c ∣ v ∣ ☐ ] or ⊠\nStuck : ∀ {st} → is-stuck st\n → (Σ[ A ∈ 𝕌 ] Σ[ B ∈ 𝕌 ] Σ[ c ∈ A ↔ B ] Σ[ v ∈ ⟦ B ⟧ ] st ≡ [ c ∣ v ∣ ☐ ]) ⊎ st ≡ ⊠\nStuck {⟨ uniti₊l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ unite₊l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ swap₊ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ assocl₊ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ assocr₊ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ unite⋆l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ uniti⋆l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ swap⋆ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ assocl⋆ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ assocr⋆ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ dist ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ factor ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))\nStuck {⟨ id↔ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₂))\nStuck {⟨ ηₓ v ∣ tt ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦η))\nStuck {⟨ εₓ v ∣ v' , ↻ ∣ κ ⟩} stuck with v ≟ v'\n... | yes eq = ⊥-elim (stuck (_ , ↦ε₁ {eq = eq}))\n... | no neq = ⊥-elim (stuck (_ , ↦ε₂ {neq = neq}))\nStuck {⟨ c₁ ⨾ c₂ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₃))\nStuck {⟨ c₁ ⊕ c₂ ∣ inj₁ x ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₄))\nStuck {⟨ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₅))\nStuck {⟨ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₆))\nStuck {[ c ∣ v ∣ ☐ ]} stuck = inj₁ (_ , _ , _ , _ , refl)\nStuck {[ c ∣ v ∣ ☐⨾ c₂ • κ ]} stuck = ⊥-elim (stuck (_ , ↦₇))\nStuck {[ c ∣ v ∣ c₁ ⨾☐• κ ]} stuck = ⊥-elim (stuck (_ , ↦₁₀))\nStuck {[ c ∣ v ∣ ☐⊕ c₂ • κ ]} stuck = ⊥-elim (stuck (_ , ↦₁₁))\nStuck {[ c ∣ v ∣ c₁ ⊕☐• κ ]} stuck = ⊥-elim (stuck (_ , ↦₁₂))\nStuck {[ c ∣ v ∣ ☐⊗[ c₂ , y ]• κ ]} stuck = ⊥-elim (stuck (_ , ↦₈))\nStuck {[ c ∣ v ∣ [ c₁ , x ]⊗☐• κ ]} stuck = ⊥-elim (stuck (_ , ↦₉))\nStuck {⊠} stuck = inj₂ refl\n\n-- Auxiliary function for forward evaluator\nev : ∀ {A B κ} → (c : A ↔ B) (v : ⟦ A ⟧)\n → Σ[ v' ∈ ⟦ B ⟧ ] ⟨ c ∣ v ∣ κ ⟩ ↦* [ c ∣ v' ∣ κ ]\n ⊎ ⟨ c ∣ v ∣ κ ⟩ ↦* ⊠\nev uniti₊l v = inj₁ ((inj₂ v) , ↦₁ ∷ ◾)\nev unite₊l (inj₂ y) = inj₁ (y , ↦₁ ∷ ◾)\nev swap₊ (inj₁ v) = inj₁ (inj₂ v , (↦₁ ∷ ◾))\nev swap₊ (inj₂ v) = inj₁ (inj₁ v , (↦₁ ∷ ◾))\nev assocl₊ (inj₁ v) = inj₁ (inj₁ (inj₁ v) , (↦₁ ∷ ◾))\nev assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₁ (inj₂ v) , (↦₁ ∷ ◾))\nev assocl₊ (inj₂ (inj₂ v)) = inj₁ (inj₂ v , (↦₁ ∷ ◾))\nev assocr₊ (inj₁ (inj₁ v)) = inj₁ (inj₁ v , (↦₁ ∷ ◾))\nev assocr₊ (inj₁ (inj₂ v)) = inj₁ (inj₂ (inj₁ v) , (↦₁ ∷ ◾))\nev assocr₊ (inj₂ v) = inj₁ (inj₂ (inj₂ v) , (↦₁ ∷ ◾))\nev unite⋆l (tt , v) = inj₁ (v , (↦₁ ∷ ◾))\nev uniti⋆l v = inj₁ ((tt , v) , (↦₁ ∷ ◾))\nev swap⋆ (x , y) = inj₁ ((y , x) , (↦₁ ∷ ◾))\nev assocl⋆ (x , (y , z)) = inj₁ (((x , y) , z) , (↦₁ ∷ ◾))\nev assocr⋆ ((x , y) , z) = inj₁ ((x , (y , z)) , (↦₁ ∷ ◾))\nev dist (inj₁ x , z) = inj₁ (inj₁ (x , z) , (↦₁ ∷ ◾))\nev dist (inj₂ y , z) = inj₁ (inj₂ (y , z) , (↦₁ ∷ ◾))\nev factor (inj₁ (x , z)) = inj₁ ((inj₁ x , z) , (↦₁ ∷ ◾))\nev factor (inj₂ (y , z)) = inj₁ ((inj₂ y , z) , (↦₁ ∷ ◾))\nev id↔ v = inj₁ (v , (↦₂ ∷ ◾))\nev {κ = κ} (c₁ ⨾ c₂) v₁ with ev {κ = ☐⨾ c₂ • κ} c₁ v₁\n... | inj₁ (v₂ , c₁↦*) with ev {κ = c₁ ⨾☐• κ} c₂ v₂\n... | inj₁ (v₃ , c₂↦*) = inj₁ (v₃ , ((↦₃ ∷ c₁↦* ++↦ (↦₇ ∷ ◾)) ++↦ (c₂↦* ++↦ (↦₁₀ ∷ ◾))))\n... | inj₂ c₂↦* = inj₂ ((↦₃ ∷ c₁↦* ++↦ (↦₇ ∷ ◾)) ++↦ c₂↦*)\nev {κ = κ} (c₁ ⨾ c₂) v₁ | inj₂ c₁↦* = inj₂ (↦₃ ∷ c₁↦*)\nev {κ = κ} (c₁ ⊕ c₂) (inj₁ x) with ev {κ = ☐⊕ c₂ • κ} c₁ x\n... | inj₁ (x' , c₁↦*) = inj₁ (inj₁ x' , ↦₄ ∷ c₁↦* ++↦ (↦₁₁ ∷ ◾))\n... | inj₂ c₁↦* = inj₂ (↦₄ ∷ c₁↦*) \nev {κ = κ} (c₁ ⊕ c₂) (inj₂ y) with ev {κ = c₁ ⊕☐• κ} c₂ y\n... | inj₁ (y' , c₂↦*) = inj₁ (inj₂ y' , ↦₅ ∷ c₂↦* ++↦ (↦₁₂ ∷ ◾))\n... | inj₂ c₂↦* = inj₂ (↦₅ ∷ c₂↦*)\nev {κ = κ} (c₁ ⊗ c₂) (x , y) with ev {κ = ☐⊗[ c₂ , y ]• κ} c₁ x\n... | inj₁ (x' , c₁↦*) with ev {κ = [ c₁ , x' ]⊗☐• κ} c₂ y\n... | inj₁ (y' , c₂↦*) = inj₁ ((x' , y') , ((↦₆ ∷ c₁↦*) ++↦ ((↦₈ ∷ c₂↦*) ++↦ (↦₉ ∷ ◾))))\n... | inj₂ c₂↦* = inj₂ ((↦₆ ∷ c₁↦*) ++↦ (↦₈ ∷ c₂↦*))\nev {κ = κ} (c₁ ⊗ c₂) (x , y) | inj₂ c₁↦* = inj₂ (↦₆ ∷ c₁↦*)\nev (ηₓ v) tt = inj₁ ((v , ↻) , (↦η ∷ ◾))\nev (εₓ v) (v' , ↻) with v ≟ v'\n... | yes eq = inj₁ (tt , (↦ε₁ {eq = eq} ∷ ◾))\n... | no neq = inj₂ (↦ε₂ {neq = neq} ∷ ◾)\n\n-- Forward evaluator for PiFrac\neval : ∀ {A B} → (c : A ↔ B) → ⟦ A ⟧ → Maybe ⟦ B ⟧\neval c v = [ just ∘ proj₁ , (λ _ → nothing) ]′ (ev {κ = ☐} c v)\n\n-- Forward evaluator which returns execution trace\nevalₜᵣ : ∀ {A B} → (c : A ↔ B) → ⟦ A ⟧ → List State\nevalₜᵣ c v = [ convert ∘ proj₂ , convert ]′ (ev {κ = ☐} c v)\n where\n convert : ∀ {st st'} → st ↦* st' → List State\n convert (◾ {st}) = st L.∷ []\n convert (_∷_ {st} r rs) = st L.∷ convert rs\n\n-- Auxiliary function for backward evaluator\nevᵣₑᵥ : ∀ {A B κ} → (c : A ↔ B) (v : ⟦ B ⟧)\n → Σ[ v' ∈ ⟦ A ⟧ ] [ c ∣ v ∣ κ ] ↦ᵣₑᵥ* ⟨ c ∣ v' ∣ κ ⟩\n ⊎ ∃[ A ] (∃[ v' ] (∃[ v'' ] (∃[ κ' ] (v' ≢ v'' × [ c ∣ v ∣ κ ] ↦ᵣₑᵥ* [ ηₓ {A} v' ∣ (v'' , ↻) ∣ κ' ]))))\nevᵣₑᵥ uniti₊l (inj₂ v) = inj₁ (v , (↦₁ ᵣₑᵥ ∷ ◾))\nevᵣₑᵥ unite₊l v = inj₁ ((inj₂ v) , (↦₁ ᵣₑᵥ ∷ ◾))\nevᵣₑᵥ swap₊ (inj₁ x) = inj₁ (inj₂ x , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ swap₊ (inj₂ y) = inj₁ (inj₁ y , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ assocl₊ (inj₁ (inj₁ x)) = inj₁ (inj₁ x , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ assocl₊ (inj₁ (inj₂ y)) = inj₁ (inj₂ (inj₁ y) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ assocl₊ (inj₂ z) = inj₁ (inj₂ (inj₂ z) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ assocr₊ (inj₁ x) = inj₁ (inj₁ (inj₁ x) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ assocr₊ (inj₂ (inj₁ y)) = inj₁ (inj₁ (inj₂ y) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ assocr₊ (inj₂ (inj₂ z)) = inj₁ (inj₂ z , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ unite⋆l v = inj₁ ((tt , v) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ uniti⋆l (tt , v) = inj₁ (v , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ swap⋆ (x , y) = inj₁ ((y , x) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ assocl⋆ ((x , y) , z) = inj₁ ((x , (y , z)) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ assocr⋆ (x , (y , z)) = inj₁ (((x , y) , z) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ dist (inj₁ (x , z)) = inj₁ ((inj₁ x , z) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ dist (inj₂ (y , z)) = inj₁ ((inj₂ y , z) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ factor (inj₁ x , z) = inj₁ (inj₁ (x , z) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ factor (inj₂ y , z) = inj₁ (inj₂ (y , z) , (↦₁ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ id↔ v = inj₁ (v , (↦₂ ᵣₑᵥ) ∷ ◾)\nevᵣₑᵥ {κ = κ} (c₁ ⨾ c₂) v₃ with evᵣₑᵥ {κ = c₁ ⨾☐• κ} c₂ v₃\n... | inj₁ (v₂ , rs) with evᵣₑᵥ {κ = ☐⨾ c₂ • κ} c₁ v₂\n... | inj₁ (v₁ , rs') = inj₁ (v₁ , ((↦₁₀ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₇ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ (rs' ++↦ᵣₑᵥ ((↦₃ ᵣₑᵥ) ∷ ◾)))\n... | inj₂ (_ , _ , _ , _ , neq , rs') = inj₂ (_ , _ , _ , _ , neq , (((↦₁₀ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₇ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ rs'))\nevᵣₑᵥ (c₁ ⨾ c₂) v₃ | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , (((↦₁₀ ᵣₑᵥ) ∷ ◾) ++↦ᵣₑᵥ rs))\nevᵣₑᵥ {κ = κ} (c₁ ⊕ c₂) (inj₁ x) with evᵣₑᵥ {κ = ☐⊕ c₂ • κ} c₁ x\n... | inj₁ (x' , rs) = inj₁ (inj₁ x' , (↦₁₁ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₄ ᵣₑᵥ) ∷ ◾)))\n... | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , (↦₁₁ ᵣₑᵥ) ∷ rs)\nevᵣₑᵥ {κ = κ} (c₁ ⊕ c₂) (inj₂ y) with evᵣₑᵥ {κ = c₁ ⊕☐• κ} c₂ y\n... | inj₁ (y' , rs) = inj₁ (inj₂ y' , (↦₁₂ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₅ ᵣₑᵥ) ∷ ◾)))\n... | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , (↦₁₂ ᵣₑᵥ) ∷ rs)\nevᵣₑᵥ {κ = κ} (c₁ ⊗ c₂) (x , y) with evᵣₑᵥ {κ = [ c₁ , x ]⊗☐• κ} c₂ y\n... | inj₁ (y' , rs) with evᵣₑᵥ {κ = ☐⊗[ c₂ , y' ]• κ} c₁ x\n... | inj₁ (x' , rs') = inj₁ ((x' , y') , (((↦₉ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₈ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ (rs' ++↦ᵣₑᵥ ((↦₆ ᵣₑᵥ) ∷ ◾))))\n... | inj₂ (_ , _ , _ , _ , neq , rs') = inj₂ (_ , _ , _ , _ , neq , (((↦₉ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₈ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ rs'))\nevᵣₑᵥ (c₁ ⊗ c₂) (x , y) | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , ((↦₉ ᵣₑᵥ) ∷ rs))\nevᵣₑᵥ (ηₓ v) (v' , ↻) with v ≟ v'\n... | yes refl = inj₁ (tt , ((↦η ᵣₑᵥ) ∷ ◾))\n... | no neq = inj₂ (_ , _ , _ , _ , neq , ◾)\nevᵣₑᵥ (εₓ v) tt = inj₁ ((v , ↻) , ((↦ε₁ {eq = refl} ᵣₑᵥ) ∷ ◾))\n\n-- Backward evaluator for Pi\nevalᵣₑᵥ : ∀ {A B} → (c : A ↔ B) → ⟦ B ⟧ → Maybe ⟦ A ⟧\nevalᵣₑᵥ c v = [ just ∘ proj₁ , (λ _ → nothing) ]′ (evᵣₑᵥ {κ = ☐} c v)\n", "meta": {"hexsha": "04bafb94ba90c4debc8181e0de4d78b3e392577b", "size": 8392, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "PiFrac/Eval.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "PiFrac/Eval.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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": "PiFrac/Eval.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 54.1419354839, "max_line_length": 123, "alphanum_fraction": 0.4382745472, "num_tokens": 5331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149978955811, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.38040632566453114}} {"text": "{-# OPTIONS --safe #-}\nmodule Extraction where\nopen import Data.Empty\nopen import Data.Unit\nopen import Data.Product\nopen import Data.Sum\nopen import Data.Maybe\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Binary.HeterogeneousEquality\nopen import Relation.Nullary\nopen import PiPointedFrac as Pi/ hiding (𝕌; ⟦_⟧; eval)\nopen import PiFracDyn\n\nInj𝕌 : Pi/.𝕌 → 𝕌\nInj𝕌 𝟘 = 𝟘\nInj𝕌 𝟙 = 𝟙\nInj𝕌 (t₁ +ᵤ t₂) = Inj𝕌 t₁ +ᵤ Inj𝕌 t₂\nInj𝕌 (t₁ ×ᵤ t₂) = Inj𝕌 t₁ ×ᵤ Inj𝕌 t₂\n\nInj𝕌≡ : (t : Pi/.𝕌) → Pi/.⟦ t ⟧ ≡ ⟦ Inj𝕌 t ⟧\nInj𝕌≡ 𝟘 = refl\nInj𝕌≡ 𝟙 = refl\nInj𝕌≡ (t₁ +ᵤ t₂) rewrite (Inj𝕌≡ t₁) | (Inj𝕌≡ t₂) = refl\nInj𝕌≡ (t₁ ×ᵤ t₂) rewrite (Inj𝕌≡ t₁) | (Inj𝕌≡ t₂) = refl\n\nInj⟦𝕌⟧ : {t : Pi/.𝕌} → Pi/.⟦ t ⟧ → ⟦ Inj𝕌 t ⟧\nInj⟦𝕌⟧ {𝟙} tt = tt\nInj⟦𝕌⟧ {t₁ +ᵤ t₂} (inj₁ x) = inj₁ (Inj⟦𝕌⟧ x)\nInj⟦𝕌⟧ {t₁ +ᵤ t₂} (inj₂ y) = inj₂ (Inj⟦𝕌⟧ y)\nInj⟦𝕌⟧ {t₁ ×ᵤ t₂} (x , y) = Inj⟦𝕌⟧ x , Inj⟦𝕌⟧ y\n\nInj⟦𝕌⟧≅ : {t : Pi/.𝕌} (x : Pi/.⟦ t ⟧) → x ≅ Inj⟦𝕌⟧ x\nInj⟦𝕌⟧≅ {𝟙} tt = refl\nInj⟦𝕌⟧≅ {t₁ +ᵤ t₂} (inj₁ x) = inj1 (Inj𝕌≡ t₂) (Inj⟦𝕌⟧≅ x)\n where\n inj1 : {A B A' B' : Set} {x : A} {x' : A'}\n → B ≡ B' → x ≅ x'\n → inj₁ {B = B} x ≅ inj₁ {B = B'} x'\n inj1 refl refl = refl\nInj⟦𝕌⟧≅ {t₁ +ᵤ t₂} (inj₂ y) = inj2 (Inj𝕌≡ t₁) (Inj⟦𝕌⟧≅ y)\n where\n inj2 : {A B A' B' : Set} {y : B} {y' : B'}\n → A ≡ A' → y ≅ y'\n → inj₂ {A = A} y ≅ inj₂ {A = A'} y'\n inj2 refl refl = refl\nInj⟦𝕌⟧≅ {t₁ ×ᵤ t₂} (x , y) = ⦅ Inj⟦𝕌⟧≅ x , Inj⟦𝕌⟧≅ y ⦆\n where\n ⦅_,_⦆ : {A B A' B' : Set} {x : A} {y : B} {x' : A'} {y' : B'}\n → x ≅ x' → y ≅ y'\n → (x , y) ≅ (x' , y')\n ⦅ refl , refl ⦆ = refl\n\nInj⟷ : ∀ {t₁ t₂} → t₁ ⟷ t₂ → Inj𝕌 t₁ ↔ Inj𝕌 t₂\nInj⟷ unite₊l = unite₊l\nInj⟷ uniti₊l = uniti₊l\nInj⟷ unite₊r = unite₊r\nInj⟷ uniti₊r = uniti₊r\nInj⟷ swap₊ = swap₊\nInj⟷ assocl₊ = assocl₊\nInj⟷ assocr₊ = assocr₊\nInj⟷ unite⋆l = unite⋆l\nInj⟷ uniti⋆l = uniti⋆l\nInj⟷ unite⋆r = unite⋆r\nInj⟷ uniti⋆r = uniti⋆r\nInj⟷ swap⋆ = swap⋆\nInj⟷ assocl⋆ = assocl⋆\nInj⟷ assocr⋆ = assocr⋆\nInj⟷ absorbr = absorbr\nInj⟷ absorbl = absorbl\nInj⟷ factorzr = factorzr\nInj⟷ factorzl = factorzl\nInj⟷ dist = dist\nInj⟷ factor = factor\nInj⟷ distl = distl\nInj⟷ factorl = factorl\nInj⟷ id⟷ = id↔\nInj⟷ (c₁ ⊚ c₂) = Inj⟷ c₁ ⊚ Inj⟷ c₂\nInj⟷ (c₁ ⊕ c₂) = Inj⟷ c₁ ⊕ Inj⟷ c₂\nInj⟷ (c₁ ⊗ c₂) = Inj⟷ c₁ ⊗ Inj⟷ c₂\n\nExt𝕌 : ∙𝕌 → Σ[ t ∈ 𝕌 ] ⟦ t ⟧\nExt𝕌 (t # v) = (Inj𝕌 t , Inj⟦𝕌⟧ v)\nExt𝕌 (t₁ ∙×ᵤ t₂) with Ext𝕌 t₁ | Ext𝕌 t₂\n... | (t₁' , v₁') | (t₂' , v₂') = t₁' ×ᵤ t₂' , v₁' , v₂'\nExt𝕌 (t₁ ∙+ᵤl t₂) with Ext𝕌 t₁ | Ext𝕌 t₂\n... | (t₁' , v₁') | (t₂' , v₂') = t₁' +ᵤ t₂' , inj₁ v₁'\nExt𝕌 (t₁ ∙+ᵤr t₂) with Ext𝕌 t₁ | Ext𝕌 t₂\n... | (t₁' , v₁') | (t₂' , v₂') = t₁' +ᵤ t₂' , inj₂ v₂'\nExt𝕌 (Singᵤ T) with Ext𝕌 T\n... | (t , v) = t , v\nExt𝕌 (Recipᵤ T) with Ext𝕌 T\n... | (t , v) = 𝟙/ v , ○\n\nExt∙⟶ : ∀ {t₁ t₂} → t₁ ∙⟶ t₂ → proj₁ (Ext𝕌 t₁) ↔ proj₁ (Ext𝕌 t₂)\nExt∙⟶ (∙c c) = Inj⟷ c\nExt∙⟶ ∙times# = id↔\nExt∙⟶ ∙#times = id↔\nExt∙⟶ ∙id⟷ = id↔\nExt∙⟶ (c₁ ∙⊚ c₂) = Ext∙⟶ c₁ ⊚ Ext∙⟶ c₂\nExt∙⟶ ∙unite⋆l = unite⋆l\nExt∙⟶ ∙uniti⋆l = uniti⋆l\nExt∙⟶ ∙unite⋆r = unite⋆r\nExt∙⟶ ∙uniti⋆r = uniti⋆r\nExt∙⟶ ∙swap⋆ = swap⋆\nExt∙⟶ ∙assocl⋆ = assocl⋆\nExt∙⟶ ∙assocr⋆ = assocr⋆\nExt∙⟶ (c₁ ∙⊗ c₂) = Ext∙⟶ c₁ ⊗ Ext∙⟶ c₂\nExt∙⟶ (c₁ ∙⊕ₗ c₂) = Ext∙⟶ c₁ ⊕ Ext∙⟶ c₂\nExt∙⟶ (c₁ ∙⊕ᵣ c₂) = Ext∙⟶ c₁ ⊕ Ext∙⟶ c₂\nExt∙⟶ (return T) = id↔\nExt∙⟶ (extract T) = id↔\nExt∙⟶ (η T) = η (proj₂ (Ext𝕌 T))\nExt∙⟶ (ε T) = ε (proj₂ (Ext𝕌 T))\n\nEval≡ : ∀ {t₁ t₂} {v} (c : t₁ ⟷ t₂) → interp (Inj⟷ c) (Inj⟦𝕌⟧ v) ≡ just (Inj⟦𝕌⟧ (Pi/.eval c v))\nEval≡ {_} {_} {inj₂ y} unite₊l = refl\nEval≡ {_} {_} {x} uniti₊l = refl\nEval≡ {_} {_} {inj₁ x} unite₊r = refl\nEval≡ {_} {_} {x} uniti₊r = refl\nEval≡ {_} {_} {inj₁ x} swap₊ = refl\nEval≡ {_} {_} {inj₂ y} swap₊ = refl\nEval≡ {_} {_} {inj₁ x} assocl₊ = refl\nEval≡ {_} {_} {inj₂ (inj₁ y)} assocl₊ = refl\nEval≡ {_} {_} {inj₂ (inj₂ z)} assocl₊ = refl\nEval≡ {_} {_} {inj₁ (inj₁ x)} assocr₊ = refl\nEval≡ {_} {_} {inj₁ (inj₂ y)} assocr₊ = refl\nEval≡ {_} {_} {inj₂ z} assocr₊ = refl\nEval≡ {_} {_} {x} unite⋆l = refl\nEval≡ {_} {_} {x} uniti⋆l = refl\nEval≡ {_} {_} {x} unite⋆r = refl\nEval≡ {_} {_} {x} uniti⋆r = refl\nEval≡ {_} {_} {x , y} swap⋆ = refl\nEval≡ {_} {_} {x , y , z} assocl⋆ = refl\nEval≡ {_} {_} {(x , y) , z} assocr⋆ = refl\nEval≡ {_} {_} {inj₁ x , z} dist = refl\nEval≡ {_} {_} {inj₂ y , z} dist = refl\nEval≡ {_} {_} {inj₁ (x , z)} factor = refl\nEval≡ {_} {_} {inj₂ (y , z)} factor = refl\nEval≡ {_} {_} {x , inj₁ y} distl = refl\nEval≡ {_} {_} {x , inj₂ z} distl = refl\nEval≡ {_} {_} {inj₁ (x , y)} factorl = refl\nEval≡ {_} {_} {inj₂ (x , z)} factorl = refl\nEval≡ {_} {_} {x} id⟷ = refl\nEval≡ {_} {_} {x} (c₁ ⊚ c₂) rewrite Eval≡ {v = x} c₁ = Eval≡ c₂\nEval≡ {_} {_} {inj₁ x} (c₁ ⊕ c₂) rewrite Eval≡ {v = x} c₁ = refl\nEval≡ {_} {_} {inj₂ y} (c₁ ⊕ c₂) rewrite Eval≡ {v = y} c₂ = refl\nEval≡ {_} {_} {x , y} (c₁ ⊗ c₂) rewrite Eval≡ {v = x} c₁ | Eval≡ {v = y} c₂ = refl\n\nExt≡ : ∀ {t₁ t₂} → (c : t₁ ∙⟶ t₂)\n → let c' = Ext∙⟶ c\n (t₁' , v₁') = Ext𝕌 t₁\n (t₂' , v₂') = Ext𝕌 t₂\n in interp c' v₁' ≡ just v₂'\nExt≡ (∙c c) = Eval≡ c\nExt≡ (∙times# {t₁} {t₂}) = refl\nExt≡ (∙#times {t₁} {t₂}) = refl\nExt≡ ∙id⟷ = refl\nExt≡ (c₁ ∙⊚ c₂) rewrite Ext≡ c₁ | Ext≡ c₂ = refl\nExt≡ (c₁ ∙⊕ₗ c₂) rewrite Ext≡ c₁ = refl\nExt≡ (c₁ ∙⊕ᵣ c₂) rewrite Ext≡ c₂ = refl\nExt≡ ∙unite⋆l = refl\nExt≡ ∙uniti⋆l = refl\nExt≡ ∙unite⋆r = refl\nExt≡ ∙uniti⋆r = refl\nExt≡ ∙swap⋆ = refl\nExt≡ ∙assocl⋆ = refl\nExt≡ ∙assocr⋆ = refl\nExt≡ (c₁ ∙⊗ c₂) rewrite Ext≡ c₁ | Ext≡ c₂ = refl\nExt≡ (return T) = refl\nExt≡ (extract T) = refl\nExt≡ (η T) = refl\nExt≡ (ε T) with 𝕌dec _ (proj₂ (Ext𝕌 T)) (proj₂ (Ext𝕌 T))\nExt≡ (ε T) | yes p = refl\nExt≡ (ε T) | no ¬p = ⊥-elim (¬p refl)\n\n𝔹 : Pi/.𝕌\n𝔹 = 𝟙 +ᵤ 𝟙\n\ninfixr 2 _→⟨_⟩_\ninfix 3 _□\n\n_→⟨_⟩_ : (T₁ : ∙𝕌) → {T₂ T₃ : ∙𝕌} →\n (T₁ ∙⟶ T₂) → (T₂ ∙⟶ T₃) → (T₁ ∙⟶ T₃)\n_ →⟨ α ⟩ β = α ∙⊚ β\n\n_□ : (T : ∙𝕌) → {T : ∙𝕌} → (T ∙⟶ T)\n_□ T = ∙id⟷\n\nzigzag : ∀ b → 𝔹 # b ∙⟶ 𝔹 # b\nzigzag b = ∙c uniti⋆l ∙⊚\n ∙times# ∙⊚\n (∙id⟷ ∙⊗ return ((𝟙 +ᵤ 𝟙) # b)) ∙⊚\n (η ((𝟙 +ᵤ 𝟙) # b) ∙⊗ ∙id⟷) ∙⊚\n ∙assocr⋆ ∙⊚\n (∙id⟷ ∙⊗ ∙swap⋆) ∙⊚\n (∙id⟷ ∙⊗ ε ((𝟙 +ᵤ 𝟙) # b)) ∙⊚\n (extract ((𝟙 +ᵤ 𝟙) # b) ∙⊗ ∙id⟷) ∙⊚ ∙#times ∙⊚ ∙c unite⋆r ∙⊚ ∙id⟷\n\nzigzag-ext : ∀ b → Σ[ c ∈ 𝟙 +ᵤ 𝟙 ↔ 𝟙 +ᵤ 𝟙 ] interp c (Inj⟦𝕌⟧ b) ≡ just (Inj⟦𝕌⟧ b)\nzigzag-ext b = Ext∙⟶ (zigzag b) , Ext≡ (zigzag b)\n", "meta": {"hexsha": "5be8188fd52c4e363f5b1f52ede696860feececa", "size": 6202, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "fracGC/Extraction.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "fracGC/Extraction.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "fracGC/Extraction.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 30.855721393, "max_line_length": 95, "alphanum_fraction": 0.5, "num_tokens": 3875, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7549149868676284, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.3804063201074777}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nmodule Definition.Typed.Consequences.Canonicity where\n\nopen import Definition.Untyped\n\nopen import Definition.Typed\nopen import Definition.Typed.Weakening\nopen import Definition.Typed.Properties\nopen import Definition.Typed.EqRelInstance\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.Irrelevance\nopen import Definition.LogicalRelation.ShapeView\nopen import Definition.LogicalRelation.Fundamental.Reducibility\n\nopen import Tools.Embedding\nopen import Tools.Empty\nopen import Tools.Nat\nopen import Tools.Product\n\n\n-- Turns a natural number into its term representation\nsucᵏ : Nat → Term\nsucᵏ 0 = zero\nsucᵏ (1+ n) = suc (sucᵏ n)\n\n-- Helper function for canonicity for reducible natural properties\ncanonicity″ : ∀ {t}\n → Natural-prop ε t\n → ∃ λ k → ε ⊢ t ≡ sucᵏ k ∷ ℕ\ncanonicity″ (sucᵣ (ℕₜ n₁ d n≡n prop)) =\n let a , b = canonicity″ prop\n in 1+ a , suc-cong (trans (subset*Term (redₜ d)) b)\ncanonicity″ zeroᵣ = 0 , refl (zeroⱼ ε)\ncanonicity″ (ne (neNfₜ neK ⊢k k≡k)) = ⊥-elim (noNe ⊢k neK)\n\n-- Helper function for canonicity for specific reducible natural numbers\ncanonicity′ : ∀ {t l}\n → ([ℕ] : ε ⊩⟨ l ⟩ℕ ℕ)\n → ε ⊩⟨ l ⟩ t ∷ ℕ / ℕ-intr [ℕ]\n → ∃ λ k → ε ⊢ t ≡ sucᵏ k ∷ ℕ\ncanonicity′ (noemb [ℕ]) (ιx (ℕₜ n d n≡n prop)) =\n let a , b = canonicity″ prop\n in a , trans (subset*Term (redₜ d)) b\ncanonicity′ (emb 0<1 [ℕ]) (ιx [t]) = canonicity′ [ℕ] [t]\n\n-- Canonicity of natural numbers\ncanonicity : ∀ {t} → ε ⊢ t ∷ ℕ → ∃ λ k → ε ⊢ t ≡ sucᵏ k ∷ ℕ\ncanonicity ⊢t with reducibleTerm ⊢t\ncanonicity ⊢t | [ℕ] , [t] =\n canonicity′ (ℕ-elim [ℕ]) (irrelevanceTerm [ℕ] (ℕ-intr (ℕ-elim [ℕ])) [t])\n", "meta": {"hexsha": "00135b0c9bd90ecf8ac47fa4bf52923045aeeb49", "size": 1709, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Typed/Consequences/Canonicity.agda", "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/Typed/Consequences/Canonicity.agda", "max_issues_repo_name": "loic-p/logrel-mltt", "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/Typed/Consequences/Canonicity.agda", "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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": 32.8653846154, "max_line_length": 74, "alphanum_fraction": 0.6635459333, "num_tokens": 628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3804062874167391}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nmodule Math.NumberTheory.Summation.Generic.Properties where\n\n-- agda-stdlib\nopen import Algebra\nimport Algebra.Operations.CommutativeMonoid as CommutativeMonoidOperations\nopen import Data.Nat as ℕ hiding (_+_; _*_)\nimport Data.Fin as Fin\nimport Data.Nat.Properties as ℕₚ\nopen import Relation.Nullary\nopen import Relation.Binary.PropositionalEquality as ≡ using (_≡_)\nimport Relation.Binary.Reasoning.Setoid as SetoidReasoning\nopen import Function.Base\n\n-- agda-misc\nopen import Math.NumberTheory.Summation.Generic\nimport Math.NumberTheory.Summation.Generic.Properties.Lemma as Lemma\n\nmodule MonoidSummationProperties {c e} (M : Monoid c e) where\n open MonoidSummation M\n open Monoid M\n open SetoidReasoning setoid\n\n -- Congruence\n Σ<-cong : ∀ {m n f g} → m ≡ n → (∀ x → f x ≈ g x) → Σ< m f ≈ Σ< n g\n Σ<-cong {0} {.0} {f} {g} ≡.refl f≈g = refl\n Σ<-cong {suc m} {.(suc m)} {f} {g} ≡.refl f≈g = begin\n Σ< m f ∙ f m ≈⟨ ∙-cong (Σ<-cong {m = m} {n = m} ≡.refl f≈g) (f≈g m) ⟩\n Σ< m g ∙ g m ∎\n\n Σ<-congˡ : ∀ n {f g} → (∀ x → f x ≈ g x) → Σ< n f ≈ Σ< n g\n Σ<-congˡ n f≈g = Σ<-cong {m = n} ≡.refl f≈g\n\n Σ<-congʳ : ∀ {m n} f → m ≡ n → Σ< m f ≈ Σ< n f\n Σ<-congʳ f m≡n = Σ<-cong {f = f} m≡n (λ _ → refl)\n\n Σ≤-cong : ∀ {m n f g} → m ≡ n → (∀ x → f x ≈ g x) → Σ≤ m f ≈ Σ≤ n g\n Σ≤-cong m≡n f≈g = Σ<-cong (≡.cong suc m≡n) f≈g\n\n Σ≤-congˡ : ∀ n {f g} → (∀ x → f x ≈ g x) → Σ≤ n f ≈ Σ≤ n g\n Σ≤-congˡ n = Σ<-congˡ (suc n)\n\n Σ≤-congʳ : ∀ {m n} f → m ≡ n → Σ≤ m f ≈ Σ≤ n f\n Σ≤-congʳ f m≡n = Σ<-congʳ f (≡.cong suc m≡n)\n\n Σ m≰n\n\n Σ≤range-cong₃-with-≤ : ∀ m n {f g} →\n (∀ i → m ≤ i → i ≤ n → f i ≈ g i) → Σ≤range m n f ≈ Σ≤range m n g\n Σ≤range-cong₃-with-≤ m n {f} {g} f≈g = Σ>=_; _∈_; _[_]=_)\nopen import Data.Vec.All.Properties.Extra as Vec∀++\nopen import Data.Sum\nopen import Data.String\nopen import Data.List.Most as List\nopen import Data.Maybe as Maybe using (Maybe; just; nothing)\nopen import Relation.Nullary.Decidable\nopen import Data.Star hiding (return; _>>=_)\n\nimport Data.Vec.All as Vec∀\n\nopen Syntax Ct\nopen Core c\nopen Classtable Ct\nopen import MJ.Classtable.Membership Ct\n\nopen import MJ.Types\n\n{-}\n-- fragment of a typed smallstep semantics;\n-- this is tedious, because there are so many indices to repeat and keep track of\n\nreadvar : ∀ {W Γ a} → Var Γ a → Env Γ W → Store W → Val W a\nreadvar v E μ = {!!}\n\ndata Cont (Γ : Ctx) : Ty c → Ty c → Set where\n k-iopₗ : ∀ {a} → NativeBinOp → Cont int a → Expr Γ\n\ndata State : Ty c → Set where\n exp : ∀ {Γ W a b} → Store W → Env Γ W → Expr Γ a → Cont a b → State b\n skip : ∀ {Γ W a b} → Store W → Env Γ W → Val W a → Cont a b → State b\n\ndata _⟶_ {b} : State b → State b → Set where\n\n exp-var : ∀ {W Γ a}{μ : Store W}{E : Env Γ W}{x k} →\n exp μ E (var {a = a} x) k ⟶ skip μ E (readvar x E μ) k\n\n iopₗ : ∀ {W Γ a}{μ : Store W}{E : Env Γ W}{x k l r f} →\n exp μ E (iop f l r) k ⟶ k-iopₗ \n-}\n\nLoc = ℕ\n\ndata Val : Set where\n num : ℕ → Val\n unit : Val\n null : Val\n ref : Cid c → Loc → Val\n\ndefault : Ty c → Val\ndefault a = {!!}\n\ndata StoreVal : Set where\n val : Val → StoreVal\n\nEnv : ℕ → Set\nEnv = Vec Val\n\nStore = List StoreVal\n\ndata Focus (n : ℕ) : ℕ → Set where\n stmt : ∀ {o} → Stmt n o → Focus n o\n continue : Focus n n\n exp : Expr n → Focus n n\n val : Val → Focus n n\n vals : List Val → Focus n n\n\ndata Cont (n : ℕ) : Set where\n k-done : Cont n\n k-iopₗ : NativeBinOp → Cont n → Expr n → Cont n\n k-iopᵣ : NativeBinOp → Val → Cont n → Cont n\n k-new : Cid c → Cont n → Cont n\n k-args : List Val → List (Expr n) → Cont n → Cont n\n k-get : String → Cont n → Cont n\n k-call : String → Cont n → Cont n\n\n k-asgn : Fin n → Cont n → Cont n\n k-seq : ∀ {o} → Stmts n o → Cont o → Cont n\n k-set₁ : String → Expr n → Cont n → Cont n\n k-set₂ : Val → String → Cont n → Cont n\n\ndata Config : Set where\n ⟨_,_,_,_⟩ : ∀ {n o} → Store → Env n → Focus n o → Cont o → Config\n\ndata _⟶_ : Config → Config → Set where\n ----\n -- expressions\n ----\n\n num : ∀ {n}{E : Env n}{μ i k} →\n ⟨ μ , E , exp (num i) , k ⟩ ⟶ ⟨ μ , E , val (num i) , k ⟩\n unit : ∀ {n}{E : Env n}{μ k} →\n ⟨ μ , E , exp unit , k ⟩ ⟶ ⟨ μ , E , val unit , k ⟩\n null : ∀ {n}{E : Env n}{μ k} →\n ⟨ μ , E , exp null , k ⟩ ⟶ ⟨ μ , E , val null , k ⟩\n\n var : ∀ {n}{E : Env n}{μ x k ℓ v} →\n μ [ ℓ ]= (val v) →\n ⟨ μ , E , exp (var x) , k ⟩ ⟶ ⟨ μ , E , val v , k ⟩\n\n iopₗ : ∀ {n}{E : Env n}{μ k f l r} →\n ⟨ μ , E , exp (iop f l r) , k ⟩ ⟶ ⟨ μ , E , exp l , k-iopₗ f k r ⟩\n iopᵣ : ∀ {n}{E : Env n}{μ k f v r} →\n ⟨ μ , E , val v , (k-iopₗ f k r) ⟩ ⟶ ⟨ μ , E , exp r , k-iopᵣ f v k ⟩\n iop-red : ∀ {n}{E : Env n}{μ k f vᵣ vₗ} →\n ⟨ μ , E , val (num vᵣ) , (k-iopᵣ f (num vₗ) k) ⟩ ⟶ ⟨ μ , E , val (num (f vₗ vᵣ)) , k ⟩\n\n new : ∀ {n}{E : Env n}{μ k cid e es} →\n ⟨ μ , E , exp (new cid (e ∷ es)), k ⟩ ⟶ ⟨ μ , E , exp e , k-args [] es (k-new cid k) ⟩\n new-nil : ∀ {n}{E : Env n}{μ k cid} →\n ⟨ μ , E , exp (new cid []), k ⟩ ⟶ ⟨ μ List.∷ʳ {!!} , E , {!!} , k ⟩\n new-red : ∀ {n}{E : Env n}{μ k cid vs} →\n ⟨ μ , E , vals vs , k-new cid k ⟩ ⟶ ⟨ μ List.∷ʳ {!!} , E , {!!} , k ⟩\n\n args : ∀ {n}{E : Env n}{μ k e es v vs} →\n ⟨ μ , E , val v , k-args vs (e ∷ es) k ⟩ ⟶ ⟨ μ , E , exp e , k-args (vs List.∷ʳ v) es k ⟩\n args-red : ∀ {n}{E : Env n}{μ k v vs} →\n ⟨ μ , E , val v , k-args vs [] k ⟩ ⟶ ⟨ μ , E , vals (vs List.∷ʳ v) , k ⟩\n\n get : ∀ {n}{E : Env n}{μ k e m} →\n ⟨ μ , E , exp (get e m) , k ⟩ ⟶ ⟨ μ , E , exp e , k-get m k ⟩\n get-red : ∀ {n}{E : Env n}{μ k c o m} →\n ⟨ μ , E , val (ref c o) , k-get m k ⟩ ⟶ ⟨ μ , E , {!!} , k ⟩\n\n call : ∀ {n}{E : Env n}{μ k e m args} →\n ⟨ μ , E , exp (call e m args), k ⟩ ⟶ ⟨ μ , E , exp e , k-args [] args (k-call m k) ⟩\n call-red : ∀ {n}{E : Env n}{μ k m v vs} →\n ⟨ μ , E , vals (v ∷ vs) , k-call m k ⟩ ⟶ ⟨ μ , E , {!!} , k ⟩\n\n ----\n -- statements\n ----\n\n next : ∀ {n}{E : Env n}{μ j o}{s : Stmt n j}{st : Stmts j o}{k} →\n ⟨ μ , E , continue , k-seq (s ◅ st) k ⟩ ⟶ ⟨ μ , E , stmt s , k-seq st k ⟩\n\n loc : ∀ {n}{E : Env n}{μ k a} →\n ⟨ μ , E , stmt (loc a) , k ⟩ ⟶ ⟨ μ , default a ∷ E , continue , k ⟩\n\n asgn : ∀ {n}{E : Env n}{μ k e x} →\n ⟨ μ , E , stmt (asgn x e) , k ⟩ ⟶ ⟨ μ , E , exp e , k-asgn x k ⟩\n asgn-red : ∀ {n}{E : Env n}{μ k v x} →\n ⟨ μ , E , val v , k-asgn x k ⟩ ⟶ ⟨ μ , (E V.[ x ]≔ v) , continue , k ⟩\n\n set₁ : ∀ {n}{E : Env n}{μ m k e e'} →\n ⟨ μ , E , stmt (set e m e') , k ⟩ ⟶ ⟨ μ , E , exp e , k-set₁ m e' k ⟩\n set₂ : ∀ {n}{E : Env n}{μ m k v e'} →\n ⟨ μ , E , val v , k-set₁ m e' k ⟩ ⟶ ⟨ μ , E , exp e' , k-set₂ v m k ⟩\n set-red : ∀ {n}{E : Env n}{μ μ' m C k v o O} →\n maybe-lookup o μ ≡ just O →\n maybe-write o {!!} μ ≡ just μ' →\n ⟨ μ , E , val v , k-set₂ (ref C o) m k ⟩ ⟶ ⟨ μ' , E , continue , k ⟩\n\n-- A few useful predicates on configurations\n\nStuck : Config → Set\nStuck φ = ¬ ∃ λ φ' → φ ⟶ φ'\n\ndata Done : Config → Set where\n done : ∀ {n}{E : Env n}{μ v} → Done ⟨ μ , E , val v , k-done ⟩\n\n-- reflexive, transitive-closure of step\n_⟶ₖ_ : Config → Config → Set\n_⟶ₖ_ = Star _⟶_\n", "meta": {"hexsha": "8ac67f4cd9cff1a72da9a4dfabcc0b4aa7e4cc96", "size": 5543, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/MJ/Semantics/Smallstep.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/Semantics/Smallstep.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/Semantics/Smallstep.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": 31.8563218391, "max_line_length": 93, "alphanum_fraction": 0.4935955259, "num_tokens": 2383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6584175005616829, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.38023305493159854}} {"text": "{-\nThis second-order term syntax was created from the following second-order syntax description:\n\nsyntax Naturals | Nat\n\ntype\n N : 0-ary\n\nterm\n ze : N\n su : N -> N\n nrec : N α (α,N).α -> α\n\ntheory\n (zeβ) z : α s : (α,N).α |> nrec (ze, z, r m. s[r,m]) = z\n (suβ) z : α s : (α,N).α n : N |> nrec (su (n), z, r m. s[r,m]) = s[nrec (n, z, r m. s[r,m]), n]\n-}\n\n\nmodule Naturals.Syntax where\n\nopen import SOAS.Common\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.Families.Core\nopen import SOAS.Construction.Structure\nopen import SOAS.ContextMaps.Inductive\n\nopen import SOAS.Metatheory.Syntax\n\nopen import Naturals.Signature\n\nprivate\n variable\n Γ Δ Π : Ctx\n α : NatT\n 𝔛 : Familyₛ\n\n-- Inductive term declaration\nmodule Nat:Terms (𝔛 : Familyₛ) where\n\n data Nat : Familyₛ where\n var : ℐ ⇾̣ Nat\n mvar : 𝔛 α Π → Sub Nat Π Γ → Nat α Γ\n\n ze : Nat N Γ\n su : Nat N Γ → Nat N Γ\n nrec : Nat N Γ → Nat α Γ → Nat α (α ∙ N ∙ Γ) → Nat α Γ\n\n\n\n open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛\n\n Natᵃ : MetaAlg Nat\n Natᵃ = record\n { 𝑎𝑙𝑔 = λ where\n (zeₒ ⋮ _) → ze\n (suₒ ⋮ a) → su a\n (nrecₒ ⋮ a , b , c) → nrec a b c\n ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }\n\n module Natᵃ = MetaAlg Natᵃ\n\n module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where\n\n open MetaAlg 𝒜ᵃ\n\n 𝕤𝕖𝕞 : Nat ⇾̣ 𝒜\n 𝕊 : Sub Nat Π Γ → Π ~[ 𝒜 ]↝ Γ\n 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t\n 𝕊 (t ◂ σ) (old v) = 𝕊 σ v\n 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)\n 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v\n\n 𝕤𝕖𝕞 ze = 𝑎𝑙𝑔 (zeₒ ⋮ tt)\n 𝕤𝕖𝕞 (su a) = 𝑎𝑙𝑔 (suₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (nrec a b c) = 𝑎𝑙𝑔 (nrecₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b , 𝕤𝕖𝕞 c)\n\n 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Natᵃ 𝒜ᵃ 𝕤𝕖𝕞\n 𝕤𝕖𝕞ᵃ⇒ = record\n { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }\n ; ⟨𝑣𝑎𝑟⟩ = refl\n ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }\n where\n open ≡-Reasoning\n ⟨𝑎𝑙𝑔⟩ : (t : ⅀ Nat α Γ) → 𝕤𝕖𝕞 (Natᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)\n ⟨𝑎𝑙𝑔⟩ (zeₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (suₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (nrecₒ ⋮ _) = refl\n\n 𝕊-tab : (mε : Π ~[ Nat ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)\n 𝕊-tab mε new = refl\n 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v\n\n module _ (g : Nat ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Natᵃ 𝒜ᵃ g) where\n\n open MetaAlg⇒ gᵃ⇒\n\n 𝕤𝕖𝕞! : (t : Nat α Γ) → 𝕤𝕖𝕞 t ≡ g t\n 𝕊-ix : (mε : Sub Nat Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)\n 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x\n 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v\n 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))\n = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))\n 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩\n\n 𝕤𝕖𝕞! ze = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (su a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (nrec a b c) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b | 𝕤𝕖𝕞! c = sym ⟨𝑎𝑙𝑔⟩\n\n\n-- Syntax instance for the signature\nNat:Syn : Syntax\nNat:Syn = record\n { ⅀F = ⅀F\n ; ⅀:CS = ⅀:CompatStr\n ; mvarᵢ = Nat:Terms.mvar\n ; 𝕋:Init = λ 𝔛 → let open Nat:Terms 𝔛 in record\n { ⊥ = Nat ⋉ Natᵃ\n ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }\n ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }\n\n-- Instantiation of the syntax and metatheory\nopen Syntax Nat:Syn public\nopen Nat:Terms public\nopen import SOAS.Families.Build public\nopen import SOAS.Syntax.Shorthands Natᵃ public\nopen import SOAS.Metatheory Nat:Syn public\n", "meta": {"hexsha": "2703b3ce71b02e8a02baa0f9e2d8199d21e8c6db", "size": 3354, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "out/Naturals/Syntax.agda", "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_issues_repo_path": "out/Naturals/Syntax.agda", "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_forks_repo_path": "out/Naturals/Syntax.agda", "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "avg_line_length": 26.0, "max_line_length": 100, "alphanum_fraction": 0.5295169946, "num_tokens": 2046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.6001883592602049, "lm_q1q2_score": 0.3801654668953766}} {"text": "open import Level\nopen import Ordinals\nmodule generic-filter {n : Level } (O : Ordinals {n}) where\n\nimport filter \nopen import zf\nopen import logic\n-- open import partfunc {n} O\nimport OD \n\nopen import Relation.Nullary \nopen import Relation.Binary \nopen import Data.Empty \nopen import Relation.Binary\nopen import Relation.Binary.Core\nopen import Relation.Binary.PropositionalEquality\nopen import Data.Nat renaming ( zero to Zero ; suc to Suc ; ℕ to Nat ; _⊔_ to _n⊔_ ) \nimport BAlgbra \n\nopen BAlgbra O\n\nopen inOrdinal O\nopen OD O\nopen OD.OD\nopen ODAxiom odAxiom\nimport OrdUtil\nimport ODUtil\nopen Ordinals.Ordinals O\nopen Ordinals.IsOrdinals isOrdinal\nopen Ordinals.IsNext isNext\nopen OrdUtil O\nopen ODUtil O\n\n\nimport ODC\n\nopen filter O\n\nopen _∧_\nopen _∨_\nopen Bool\n\n\nopen HOD\n\n-------\n-- the set of finite partial functions from ω to 2\n--\n--\n\nopen import Data.List hiding (filter)\nopen import Data.Maybe \n\nimport OPair\nopen OPair O\n\nODSuc : (y : HOD) → infinite ∋ y → HOD\nODSuc y lt = Union (y , (y , y)) \n\ndata Hω2 : (i : Nat) ( x : Ordinal ) → Set n where\n hφ : Hω2 0 o∅\n h0 : {i : Nat} {x : Ordinal } → Hω2 i x →\n Hω2 (Suc i) (& (Union ((< nat→ω i , nat→ω 0 >) , * x )))\n h1 : {i : Nat} {x : Ordinal } → Hω2 i x →\n Hω2 (Suc i) (& (Union ((< nat→ω i , nat→ω 1 >) , * x )))\n he : {i : Nat} {x : Ordinal } → Hω2 i x →\n Hω2 (Suc i) x\n\nrecord Hω2r (x : Ordinal) : Set n where\n field\n count : Nat\n hω2 : Hω2 count x\n\nopen Hω2r\n\nHODω2 : HOD\nHODω2 = record { od = record { def = λ x → Hω2r x } ; odmax = next o∅ ; , ( list→hod t (Suc i) )) \n list→hod (just i1 ∷ t) i = Union (< nat→ω i , nat→ω 1 > , ( list→hod t (Suc i) )) \n list→hod (nothing ∷ t) i = list→hod t (Suc i ) \n\nHω2→3 : (x : HOD) → HODω2 ∋ x → List (Maybe Two) \nHω2→3 x = lemma where\n lemma : { y : Ordinal } → Hω2r y → List (Maybe Two)\n lemma record { count = 0 ; hω2 = hφ } = []\n lemma record { count = (Suc i) ; hω2 = (h0 hω3) } = just i0 ∷ lemma record { count = i ; hω2 = hω3 }\n lemma record { count = (Suc i) ; hω2 = (h1 hω3) } = just i1 ∷ lemma record { count = i ; hω2 = hω3 }\n lemma record { count = (Suc i) ; hω2 = (he hω3) } = nothing ∷ lemma record { count = i ; hω2 = hω3 }\n\nω→2 : HOD\nω→2 = Power infinite\n\nω→2f : (x : HOD) → ω→2 ∋ x → Nat → Two\nω→2f x lt n with ODC.∋-p O x (nat→ω n)\nω→2f x lt n | yes p = i1\nω→2f x lt n | no ¬p = i0\n\nfω→2-sel : ( f : Nat → Two ) (x : HOD) → Set n\nfω→2-sel f x = (infinite ∋ x) ∧ ( (lt : odef infinite (& x) ) → f (ω→nat x lt) ≡ i1 )\n\nfω→2 : (Nat → Two) → HOD\nfω→2 f = Select infinite (fω→2-sel f)\n\nopen _==_\n\nimport Axiom.Extensionality.Propositional\npostulate f-extensionality : { n m : Level} → Axiom.Extensionality.Propositional.Extensionality n m\n\nω2∋f : (f : Nat → Two) → ω→2 ∋ fω→2 f\nω2∋f f = power← infinite (fω→2 f) (λ {x} lt → proj1 ((proj2 (selection {fω→2-sel f} {infinite} )) lt))\n\nω→2f≡i1 : (X i : HOD) → (iω : infinite ∋ i) → (lt : ω→2 ∋ X ) → ω→2f X lt (ω→nat i iω) ≡ i1 → X ∋ i\nω→2f≡i1 X i iω lt eq with ODC.∋-p O X (nat→ω (ω→nat i iω))\nω→2f≡i1 X i iω lt eq | yes p = subst (λ k → X ∋ k ) (nat→ω-iso iω) p\n\nopen _⊆_\n\n-- someday ...\n-- postulate \n-- ω→2f-iso : (X : HOD) → ( lt : ω→2 ∋ X ) → fω→2 ( ω→2f X lt ) =h= X\n-- fω→2-iso : (f : Nat → Two) → ω→2f ( fω→2 f ) (ω2∋f f) ≡ f\n\nrecord CountableOrdinal : Set (suc (suc n)) where\n field\n ctl→ : Nat → Ordinal\n ctl← : Ordinal → Nat\n ctl-iso→ : { x : Ordinal } → ctl→ (ctl← x ) ≡ x \n ctl-iso← : { x : Nat } → ctl← (ctl→ x ) ≡ x\n\nrecord CountableHOD : Set (suc (suc n)) where\n field\n mhod : HOD\n mtl→ : Nat → Ordinal\n mtl→∈P : (i : Nat) → odef mhod (mtl→ i)\n mtl← : (x : Ordinal) → odef mhod x → Nat\n mtl-iso→ : { x : Ordinal } → (lt : odef mhod x ) → mtl→ (mtl← x lt ) ≡ x \n mtl-iso← : { x : Nat } → mtl← (mtl→ x ) (mtl→∈P x) ≡ x\n \n \nopen CountableOrdinal \nopen CountableHOD\n\n----\n-- a(n) ∈ M\n-- ∃ q ∈ Power P → q ∈ a(n) ∧ p(n) ⊆ q \n--\nPGHOD : (i : Nat) → (C : CountableOrdinal) → (P : HOD) → (p : Ordinal) → HOD\nPGHOD i C P p = record { od = record { def = λ x →\n odef (Power P) x ∧ odef (* (ctl→ C i)) x ∧ ( (y : Ordinal ) → odef (* p) y → odef (* x) y ) }\n ; odmax = odmax (Power P) ; }\n--\n-- W (ω , H ( ω , 2 )) = { p ∈ ( Nat → H (ω , 2) ) | { i ∈ Nat → p i ≠ i1 } is finite }\n--\n\n\n\n", "meta": {"hexsha": "dfbeb944bc5d024a81e45893eeb7087b03e2acdf", "size": 8750, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/generic-filter.agda", "max_stars_repo_name": "shinji-kono/zf-in-agda", "max_stars_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-10-02T13:46:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-10T13:27:48.000Z", "max_issues_repo_path": "src/generic-filter.agda", "max_issues_repo_name": "shinji-kono/zf-in-agda", "max_issues_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "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/generic-filter.agda", "max_forks_repo_name": "shinji-kono/zf-in-agda", "max_forks_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "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": 33.1439393939, "max_line_length": 143, "alphanum_fraction": 0.5218285714, "num_tokens": 3777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.3801535478977357}} {"text": "module Issue373 where\n\ndata ⊤ : Set where\n tt : ⊤\n\n{-# COMPILED_DATA ⊤ () () #-}\n\ndata ℕ : Set where\n zero : ℕ\n suc : (n : ℕ) → ℕ\n\n{-# BUILTIN NATURAL ℕ #-}\n{-# IMPORT Imports.Nat #-}\n\ndata List (A : Set) : Set where\n [] : List A\n _∷_ : A → List A → List A\n\n{-# BUILTIN LIST List #-}\n{-# BUILTIN NIL [] #-}\n{-# BUILTIN CONS _∷_ #-}\n{-# COMPILED_DATA List [] [] (:) #-}\n\npostulate\n String : Set\n\n{-# BUILTIN STRING String #-}\n\npostulate\n IO : Set → Set\n\n{-# BUILTIN IO IO #-}\n{-# COMPILED_TYPE IO IO #-}\n\ninfixl 1 _>>=_\n\npostulate\n _>>=_ : ∀ {A B} → IO A → (A → IO B) → IO B\n\n{-# COMPILED _>>=_ (\\_ _ -> (>>=) :: IO a -> (a -> IO b) -> IO b) #-}\n\n{-# IMPORT Data.Text.IO #-}\n\npostulate\n putStrLn : String → IO ⊤\n\n{-# COMPILED putStrLn Data.Text.IO.putStrLn #-}\n\nf : ℕ → String\nf zero = \"bad\"\nf _ = \"ok\"\n\n-- Works:\n\n-- main = putStrLn (f (suc zero))\n\n-- Compiles, but when the program is run we (used to) get the output\n-- \"bad\":\n\nmain = putStrLn (f 1)\n", "meta": {"hexsha": "2e50115f9c2fcefdbda5cf4334a33f06333d4557", "size": 975, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/interaction/Issue373.agda", "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "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/interaction/Issue373.agda", "max_issues_repo_name": "redfish64/autonomic-agda", "max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "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/interaction/Issue373.agda", "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "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": 15.9836065574, "max_line_length": 69, "alphanum_fraction": 0.5302564103, "num_tokens": 329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8175744939732855, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.38009166696298335}} {"text": "module ModuleReexport where\n\nopen import Common.Unit\nopen import Common.Nat\nopen import Common.IO\n\nmodule A (B : Set) (b : B) where\n data X : Set where\n Con1 : B -> X\n Con2 : X\n f : X -> B\n f (Con1 x) = x\n f Con2 = b\n\n\nmodule X = A Nat 10\n\n\nmain = printNat (A.f Nat 10 (X.Con1 20)) ,,\n putStrLn \"\" ,,\n printNat (A.f Nat 10 X.Con2) ,,\n putStrLn \"\" ,,\n return unit\n", "meta": {"hexsha": "bda52e46721993989b7a9331f8f5e7eadcbc792e", "size": 377, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Compiler/simple/ModuleReexport.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Compiler/simple/ModuleReexport.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Compiler/simple/ModuleReexport.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 15.7083333333, "max_line_length": 43, "alphanum_fraction": 0.5968169761, "num_tokens": 137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.3798989788233756}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import HoTT\nopen import cohomology.CofiberSequence\nopen import cohomology.Exactness\nopen import cohomology.FunctionOver\nopen import cohomology.Theory\nopen import cohomology.ProductRepr\nopen import cohomology.WedgeCofiber\n\n{- Finite additivity is provable (and in a stronger form) without using\n - the additivity axiom. For any m ≥ 0,\n\n Cⁿ(Σᵐ(X ∨ Y)) == Cⁿ(ΣᵐX) × Cⁿ(ΣᵐY)\n\n - and over this path\n\\ - ∙ Cⁿ(Σᵐwinl) corresponds to fst : Cⁿ(ΣᵐX) × Cⁿ(ΣᵐY) → Cⁿ(ΣᵐX),\n - ∙ Cⁿ(Σᵐwinr) corresponds to snd : Cⁿ(ΣᵐX) × Cⁿ(ΣᵐY) → Cⁿ(ΣᵐY),\n - ∙ Cⁿ(Σᵐ(Wedge-rec winl* winr* wglue*)) : Cⁿ(ΣᵐZ) → Cⁿ(Σᵐ(X ∨ Y))\n corresponds to Cⁿ(Σᵐwinl*) × Cⁿ(Σᵐwinr*).\n -}\n\nmodule cohomology.Wedge {i} (CT : CohomologyTheory i) where\n\nmodule CSusp^Wedge (n : ℤ) (X Y : Ptd i) (m : ℕ) where\n\n open WedgeCofiber X Y\n\n open CohomologyTheory CT\n open import cohomology.ConstantFunction CT\n\n private\n βl : CF-hom n (⊙susp^-fmap m ⊙winl) ∘ᴳ\n CF-hom n (⊙susp^-fmap m ⊙projl)\n == idhom _\n βl = ! (CF-comp n (⊙susp^-fmap m ⊙projl)\n (⊙susp^-fmap m ⊙winl))\n ∙ ap (CF-hom n)\n (! (⊙susp^-fmap-∘ m ⊙projl ⊙winl)\n ∙ ⊙susp^-fmap-idf m _)\n ∙ CF-ident n\n\n βr : CF-hom n (⊙susp^-fmap m ⊙winr) ∘ᴳ\n CF-hom n (⊙susp^-fmap m ⊙projr)\n == idhom _\n βr = ! (CF-comp n (⊙susp^-fmap m ⊙projr)\n (⊙susp^-fmap m ⊙winr))\n ∙ ap (CF-hom n)\n (! (⊙susp^-fmap-∘ m ⊙projr ⊙winr)\n ∙ ap (⊙susp^-fmap m) ⊙projr-winr\n ∙ ⊙susp^-fmap-idf m _)\n ∙ CF-ident n\n where\n ⊙projr-winr : ⊙projr ⊙∘ ⊙winr == ⊙idf _\n ⊙projr-winr = ⊙λ= (λ _ → idp) $\n ∙-unit-r _ ∙ ap-! projr wglue ∙ ap ! Projr.glue-β\n\n open ProductRepr\n (CF-hom n (⊙susp^-fmap m ⊙projl))\n (CF-hom n (⊙susp^-fmap m ⊙projr))\n (CF-hom n (⊙susp^-fmap m ⊙winl))\n (CF-hom n (⊙susp^-fmap m ⊙winr))\n (app= (ap GroupHom.f βl))\n (app= (ap GroupHom.f βr))\n (transport\n (λ {(_ , f , g) → is-exact (CF n g) (CF n f)})\n (suspend^-cof= m ⊙winr ⊙projl\n (pair= CofWinr.⊙path CofWinr.cfcod-over))\n (C-exact n (⊙susp^-fmap m ⊙winr)))\n (transport\n (λ {(_ , f , g) → is-exact (CF n g) (CF n f)})\n (suspend^-cof= m ⊙winl ⊙projr\n (pair= CofWinl.⊙path CofWinl.cfcod-over))\n (C-exact n (⊙susp^-fmap m ⊙winl)))\n public\n\n wedge-rec-over : {Z : Ptd i}\n (winl* : fst X → fst Z) (winr* : fst Y → fst Z)\n (wglue* : winl* (snd X) == winr* (snd Y)) (pt : winl* (snd X) == snd Z)\n → CF-hom n (⊙susp^-fmap m (WedgeRec.f winl* winr* wglue* , pt))\n == ×ᴳ-hom-in (CF-hom n (⊙susp^-fmap m (winl* , pt)))\n (CF-hom n (⊙susp^-fmap m (winr* , ! wglue* ∙ pt)))\n [ (λ K → C n (⊙Susp^ m Z) →ᴳ K) ↓ iso ]\n wedge-rec-over winl* winr* wglue* pt = codomain-over-iso _ _ _ _ $\n codomain-over-equiv\n (fst (CF n (⊙susp^-fmap m (WedgeRec.f winl* winr* wglue* , pt)))) _\n ▹ ap2 (λ f g z → (f z , g z))\n (ap GroupHom.f $ ! $\n ap (CF-hom n) (⊙susp^-fmap-∘ m (rec , pt) ⊙winl)\n ∙ CF-comp n (⊙susp^-fmap m (rec , pt)) (⊙susp^-fmap m ⊙winl))\n (ap GroupHom.f $ ! $\n ap (CF-hom n) (ap (⊙susp^-fmap m) (pair= idp (! pt-lemma))\n ∙ ⊙susp^-fmap-∘ m (rec , pt) ⊙winr)\n ∙ CF-comp n (⊙susp^-fmap m (rec , pt)) (⊙susp^-fmap m ⊙winr))\n where\n rec = WedgeRec.f winl* winr* wglue*\n\n pt-lemma : ap rec (! wglue) ∙ pt == ! wglue* ∙ pt\n pt-lemma = ap (λ w → w ∙ pt) $\n ap-! rec wglue ∙ ap ! (WedgeRec.glue-β winl* winr* wglue*)\n\n wedge-in-over : {Z : Ptd i}\n (f : fst (⊙Susp^ m Z ⊙→ ⊙Susp^ m (⊙Wedge X Y)))\n → CF-hom n f\n == ×ᴳ-sum-hom (C-abelian n _)\n (CF-hom n (⊙susp^-fmap m ⊙projl ⊙∘ f))\n (CF-hom n (⊙susp^-fmap m ⊙projr ⊙∘ f))\n [ (λ G → G →ᴳ C n (⊙Susp^ m Z)) ↓ iso ]\n wedge-in-over f =\n lemma (C-abelian n _) (C-abelian n _) inl-over inr-over\n ▹ ap2 (×ᴳ-sum-hom (C-abelian n _))\n (! (CF-comp n (⊙susp^-fmap m ⊙projl) f))\n (! (CF-comp n (⊙susp^-fmap m ⊙projr) f))\n where\n lemma : {G H K L : Group i}\n (aG : is-abelian G) (aL : is-abelian L) {p : G == H ×ᴳ K}\n {φ : H →ᴳ G} {ψ : K →ᴳ G} {χ : G →ᴳ L}\n → φ == ×ᴳ-inl [ (λ J → H →ᴳ J) ↓ p ]\n → ψ == ×ᴳ-inr {G = H} [ (λ J → K →ᴳ J) ↓ p ]\n → χ == ×ᴳ-sum-hom aL (χ ∘ᴳ φ) (χ ∘ᴳ ψ) [ (λ J → J →ᴳ L) ↓ p ]\n lemma {H = H} {K = K} aG aL {p = idp} {χ = χ} idp idp =\n ap (λ α → χ ∘ᴳ α) (×ᴳ-sum-hom-η H K aG)\n ∙ ! (∘-×ᴳ-sum-hom aG aL χ (×ᴳ-inl {G = H}) (×ᴳ-inr {G = H}))\n", "meta": {"hexsha": "b93d73892b9d147ecad5f3a2107c8b5386031985", "size": 4607, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "cohomology/Wedge.agda", "max_stars_repo_name": "danbornside/HoTT-Agda", "max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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": "cohomology/Wedge.agda", "max_issues_repo_name": "danbornside/HoTT-Agda", "max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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": "cohomology/Wedge.agda", "max_forks_repo_name": "danbornside/HoTT-Agda", "max_forks_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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.1532258065, "max_line_length": 75, "alphanum_fraction": 0.4983720425, "num_tokens": 2183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757645879592641, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.37989897148147217}} {"text": "open import Data.List hiding ([_]) renaming (_∷_ to _∷ₗ_)\nopen import Data.Maybe\nopen import Data.Product\n\nopen import AEff\nopen import EffectAnnotations\nopen import Renamings\nopen import Substitutions renaming (⟨_,_⟩ to ⟨_,,_⟩)\nopen import Types\n\nopen import Relation.Binary.PropositionalEquality hiding ([_])\nopen import Relation.Nullary\n\nmodule Preservation where\n\n\n-- BINDING CONTEXTS\n\nBCtx = List VType\n\n\n-- WELL-TYPED EVALUATION CONTEXTS\n\ndata _⊢E[_]⦂_ (Γ : Ctx) : (Δ : BCtx) → CType → Set where\n\n [-] : {C : CType} → \n -------------\n Γ ⊢E[ [] ]⦂ C\n\n let=_`in_ : {Δ : BCtx}\n {X Y : VType}\n {o : O}\n {i : I} →\n Γ ⊢E[ Δ ]⦂ X ! (o , i) →\n Γ ∷ X ⊢C⦂ Y ! (o , i) →\n ------------------------\n Γ ⊢E[ Δ ]⦂ Y ! (o , i)\n\n ↑ : {Δ : BCtx}\n {X : VType}\n {o : O}\n {i : I} →\n (op : Σₛ) →\n op ∈ₒ o →\n Γ ⊢V⦂ proj₁ (payload op) →\n Γ ⊢E[ Δ ]⦂ X ! (o , i) →\n --------------------------\n Γ ⊢E[ Δ ]⦂ X ! (o , i)\n\n ↓ : {Δ : BCtx}\n {X : VType}\n {o : O}\n {i : I}\n (op : Σₛ) →\n Γ ⊢V⦂ proj₁ (payload op) →\n Γ ⊢E[ Δ ]⦂ X ! (o , i) →\n ---------------------------\n Γ ⊢E[ Δ ]⦂ X ! op ↓ₑ (o , i)\n\n promise_∣_↦_`in_ : {Δ : BCtx}\n {X Y : VType}\n {o o' : O}\n {i i' : I} → \n (op : Σₛ) →\n (o' , i') ⊑ lkpᵢ op i →\n Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i') →\n Γ ∷ ⟨ X ⟩ ⊢E[ Δ ]⦂ Y ! (o , i) →\n ----------------------------------------------\n Γ ⊢E[ X ∷ₗ Δ ]⦂ Y ! (o , i)\n\n spawn : {Δ : BCtx}\n {C D : CType} →\n Γ ■ ⊢C⦂ C →\n Γ ⊢E[ Δ ]⦂ D →\n ---------------\n Γ ⊢E[ Δ ]⦂ D\n\n coerce : {Δ : BCtx}\n {X : VType}\n {o o' : O}\n {i i' : I} →\n o ⊑ₒ o' →\n i ⊑ᵢ i' → \n Γ ⊢E[ Δ ]⦂ X ! (o , i) →\n ------------------------\n Γ ⊢E[ Δ ]⦂ X ! (o' , i')\n\n\n-- MERGING AN ORDINARY CONTEXT AND A BINDING CONTEXT\n\ninfix 30 _⋈_\n\n_⋈_ : Ctx → BCtx → Ctx\nΓ ⋈ [] = Γ\nΓ ⋈ (X ∷ₗ Δ) = (Γ ∷ ⟨ X ⟩) ⋈ Δ\n\n\n-- FINDING THE TYPE OF THE HOLE OF A WELL-TYPED EVALUATION CONTEXT\n\nhole-ty-e : {Γ : Ctx} {Δ : BCtx} {C : CType} → Γ ⊢E[ Δ ]⦂ C → CType\nhole-ty-e {_} {_} {C} [-] =\n C\nhole-ty-e (let= E `in M) =\n hole-ty-e E\nhole-ty-e (↑ op p V E) =\n hole-ty-e E\nhole-ty-e (↓ op V E) =\n hole-ty-e E\nhole-ty-e (promise op ∣ p ↦ M `in E) =\n hole-ty-e E\nhole-ty-e (spawn M E) =\n hole-ty-e E\nhole-ty-e (coerce p q E) =\n hole-ty-e E\n\n\n-- FILLING A WELL-TYPED EVALUATION CONTEXT\n\ninfix 30 _[_]\n\n_[_] : {Γ : Ctx} {Δ : BCtx} {C : CType} → (E : Γ ⊢E[ Δ ]⦂ C) → Γ ⋈ Δ ⊢C⦂ (hole-ty-e E) → Γ ⊢C⦂ C\n[-] [ M ] =\n M\n(let= E `in N) [ M ] =\n let= (E [ M ]) `in N\n(↑ op p V E) [ M ] =\n ↑ op p V (E [ M ])\n(↓ op V E) [ M ] =\n ↓ op V (E [ M ])\n(promise op ∣ p ↦ N `in E) [ M ] =\n promise op ∣ p ↦ N `in (E [ M ])\n(spawn N E) [ M ] =\n spawn N (E [ M ])\n(coerce p q E) [ M ] =\n coerce p q (E [ M ])\n\n\n-- STRENGTHENING OF GROUND VALUES WRT BOUND PROMISES\n\nstrengthen-var : {Γ : Ctx} → (Δ : BCtx) → {X : VType} →\n mobile X →\n X ∈ Γ ⋈ Δ →\n --------------------------------------\n X ∈ Γ\n \nstrengthen-var [] p x = x\nstrengthen-var (y ∷ₗ Δ) p x with strengthen-var Δ p x\n... | Tl-v z = z\n\n\nstrengthen-■-var : {Γ : Ctx} → (Γ' : Ctx) →\n (Δ : BCtx) → {X : VType} →\n X ∈ (Γ ⋈ Δ) ■ ++ₖ Γ' →\n --------------------------\n X ∈ Γ ■ ++ₖ Γ'\n\nstrengthen-■-var Γ' [] x = x\nstrengthen-■-var [] (y ∷ₗ Δ) x with strengthen-■-var [] Δ x\n... | Tl-■ p (Tl-v z) = Tl-■ p z\nstrengthen-■-var (Γ' ∷ Z) (y ∷ₗ Δ) Hd = Hd\nstrengthen-■-var (Γ' ∷ Z) (y ∷ₗ Δ) (Tl-v x) with strengthen-■-var Γ' (y ∷ₗ Δ) x\n... | q = Tl-v q\nstrengthen-■-var (Γ' ■) (y ∷ₗ Δ) (Tl-■ p x) with strengthen-■-var Γ' (y ∷ₗ Δ) x\n... | q = Tl-■ p q\n\n\nmutual \n strengthen-■-v : {Γ Γ' : Ctx} {Δ : BCtx} {X : VType} →\n (Γ ⋈ Δ) ■ ++ₖ Γ' ⊢V⦂ X →\n -------------------------------------\n Γ ■ ++ₖ Γ' ⊢V⦂ X\n \n strengthen-■-v {_} {Γ'} {Δ} (` x) =\n ` strengthen-■-var Γ' Δ x\n strengthen-■-v (´ c) =\n ´ c\n strengthen-■-v ⋆ =\n ⋆\n strengthen-■-v {Γ} {Γ'} {Δ} (ƛ M) =\n ƛ (strengthen-■-c {Γ} {Γ' ∷ _} {Δ} M)\n strengthen-■-v {Γ} {Γ'} {Δ} ⟨ V ⟩ =\n ⟨ strengthen-■-v {Γ} {Γ'} {Δ} V ⟩\n strengthen-■-v {Γ} {Γ'} {Δ} (□ V) =\n □ (strengthen-■-v {Γ' = _ ■} {Δ = Δ} V)\n\n\n strengthen-■-c : {Γ Γ' : Ctx} {Δ : BCtx} {C : CType} →\n (Γ ⋈ Δ) ■ ++ₖ Γ' ⊢C⦂ C →\n -------------------------------------\n Γ ■ ++ₖ Γ' ⊢C⦂ C\n\n strengthen-■-c {Γ} {Γ'} {Δ} (return V) =\n return (strengthen-■-v {Γ} {Γ'} {Δ} V)\n strengthen-■-c {Γ} {Γ'} {Δ} (let= M `in N) =\n let= (strengthen-■-c {Γ} {Γ'} {Δ} M) `in (strengthen-■-c {Γ} {Γ' ∷ _} {Δ} N)\n strengthen-■-c {Γ} {Γ'} {Δ} (V · W) =\n (strengthen-■-v {Γ} {Γ'} {Δ} V) · (strengthen-■-v {Γ} {Γ'} {Δ} W)\n strengthen-■-c {Γ} {Γ'} {Δ} (↑ op p V M) =\n ↑ op p (strengthen-■-v {Γ} {Γ'} {Δ} V) (strengthen-■-c {Γ} {Γ'} {Δ} M)\n strengthen-■-c {Γ} {Γ'} {Δ} (↓ op V M) =\n ↓ op (strengthen-■-v {Γ} {Γ'} {Δ} V) (strengthen-■-c {Γ} {Γ'} {Δ} M)\n strengthen-■-c {Γ} {Γ'} {Δ} (promise op ∣ p ↦ M `in N) =\n promise op ∣ p ↦ (strengthen-■-c {Γ} {Γ' ∷ proj₁ (payload op) ∷ _} {Δ} M) `in (strengthen-■-c {Γ} {Γ' ∷ ⟨ _ ⟩} {Δ} N)\n strengthen-■-c {Γ} {Γ'} {Δ} (await V until N) =\n await (strengthen-■-v {Γ} {Γ'} {Δ} V) until (strengthen-■-c {Γ} {Γ' ∷ _} {Δ} N)\n strengthen-■-c {Γ} {Γ'} {Δ} (unbox V `in N) =\n unbox (strengthen-■-v {Γ} {Γ'} {Δ} V) `in (strengthen-■-c {Γ} {Γ' ∷ _} {Δ} N)\n strengthen-■-c {Γ} {Γ'} {Δ} (spawn M N) =\n spawn (strengthen-■-c {Γ' = _ ■} {Δ = Δ} M) (strengthen-■-c {Δ = Δ} N)\n strengthen-■-c {Γ} {Γ'} {Δ} (coerce p q M) =\n coerce p q (strengthen-■-c {Γ} {Γ'} {Δ} M)\n\n\nstrengthen-val : {Γ : Ctx} {Δ : BCtx} {X : VType} →\n mobile X →\n Γ ⋈ Δ ⊢V⦂ X →\n ----------------------------------\n Γ ⊢V⦂ X\n \nstrengthen-val {_} {Δ} p (` x) =\n ` strengthen-var Δ p x\nstrengthen-val p (´ c) =\n ´ c\nstrengthen-val p ⋆ =\n ⋆\nstrengthen-val {Γ} {Δ} p (□ V) =\n □ (strengthen-■-v {Γ} {[]} {Δ} V)\n\n\n-- SMALL-STEP OPERATIONAL SEMANTICS FOR WELL-TYPED COMPUTATIONS\n-- (ADDITIONALLY SERVES AS THE PRESERVATION THEOREM)\n\ninfix 10 _↝_\n\ndata _↝_ {Γ : Ctx} : {C : CType} → Γ ⊢C⦂ C → Γ ⊢C⦂ C → Set where\n\n -- COMPUTATIONAL RULES\n\n apply : {X : VType}\n {C : CType} →\n (M : Γ ∷ X ⊢C⦂ C) →\n (V : Γ ⊢V⦂ X) →\n ----------------------\n (ƛ M) · V\n ↝\n M [ sub-id [ V ]s ]c\n\n let-return : {X Y : VType}\n {o : O}\n {i : I} → \n (V : Γ ⊢V⦂ X) →\n (N : Γ ∷ X ⊢C⦂ Y ! (o , i)) →\n -----------------------------\n let= (return V) `in N\n ↝\n N [ sub-id [ V ]s ]c\n\n let-↑ : {X Y : VType}\n {o : O}\n {i : I}\n {op : Σₛ} →\n (p : op ∈ₒ o) →\n (V : Γ ⊢V⦂ proj₁ (payload op)) →\n (M : Γ ⊢C⦂ X ! (o , i)) →\n (N : Γ ∷ X ⊢C⦂ Y ! (o , i)) →\n -----------------------------\n let= (↑ op p V M) `in N\n ↝\n ↑ op p V (let= M `in N)\n\n let-promise : {X Y Z : VType}\n {o o' : O}\n {i i' : I}\n {op : Σₛ} →\n (p : (o' , i') ⊑ lkpᵢ op i) →\n (M₁ : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')) →\n (M₂ : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →\n (N : Γ ∷ Y ⊢C⦂ Z ! (o , i)) →\n ----------------------------------------------------------------------------------------------------------\n let= (promise op ∣ p ↦ M₁ `in M₂) `in N\n ↝\n (promise op ∣ p ↦ M₁ `in (let= M₂ `in (C-rename (ren-cong ren-wk) N)))\n\n let-await : {X Y Z : VType}\n {o : O}\n {i : I} →\n (V : Γ ⊢V⦂ ⟨ X ⟩) →\n (M : Γ ∷ X ⊢C⦂ Y ! (o , i)) →\n (N : Γ ∷ Y ⊢C⦂ Z ! (o , i)) → \n -------------------------------------------------------\n let= (await V until M) `in N\n ↝\n await V until (let= M `in C-rename (ren-cong ren-wk) N)\n\n let-spawn : {X Y : VType}\n {C : CType}\n {o : O}\n {i : I} → \n (M : Γ ■ ⊢C⦂ C) → \n (N : Γ ⊢C⦂ X ! (o , i)) →\n (K : Γ ∷ X ⊢C⦂ Y ! (o , i)) →\n ---------------------------------------\n let= (spawn M N) `in K\n ↝\n spawn M (let= N `in K)\n\n promise-↑ : {X Y : VType}\n {o o' : O}\n {i i' : I}\n {op op' : Σₛ} →\n (p : (o' , i') ⊑ lkpᵢ op i) →\n (q : op' ∈ₒ o) →\n (V : Γ ∷ ⟨ X ⟩ ⊢V⦂ proj₁ (payload op')) → \n (M : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')) →\n (N : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →\n -----------------------------------------------------------------------------------------\n (promise op ∣ p ↦ M `in (↑ op' q V N))\n ↝\n ↑ op' q (strengthen-val {Δ = X ∷ₗ []} (proj₂ (payload op')) V) (promise op ∣ p ↦ M `in N)\n\n promise-spawn : {X Y : VType}\n {C : CType}\n {o o' : O}\n {i i' : I}\n {op : Σₛ} →\n (p : (o' , i') ⊑ lkpᵢ op i) →\n (M : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')) →\n (N : Γ ∷ ⟨ X ⟩ ■ ⊢C⦂ C) → \n (K : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →\n ---------------------------------------------------------------------------\n (promise op ∣ p ↦ M `in (spawn N K))\n ↝\n spawn (strengthen-■-c {Γ' = []} {Δ = X ∷ₗ []} N) (promise op ∣ p ↦ M `in K)\n\n\n ↓-return : {X : VType}\n {o : O}\n {i : I}\n {op : Σₛ} →\n (V : Γ ⊢V⦂ proj₁ (payload op)) →\n (W : Γ ⊢V⦂ X) →\n ----------------------------------------------------------------\n ↓ {o = o} {i = i} op V (return W)\n ↝\n return {o = proj₁ (op ↓ₑ (o , i))} {i = proj₂ (op ↓ₑ (o , i))} W\n\n ↓-↑ : {X : VType}\n {o : O}\n {i : I}\n {op : Σₛ}\n {op' : Σₛ} →\n (p : op' ∈ₒ o) →\n (V : Γ ⊢V⦂ proj₁ (payload op)) →\n (W : Γ ⊢V⦂ proj₁ (payload op')) →\n (M : Γ ⊢C⦂ X ! (o , i)) →\n --------------------------------\n ↓ op V (↑ op' p W M)\n ↝\n ↑ op' (↓ₑ-⊑ₒ op' p) W (↓ op V M)\n\n ↓-promise-op : {X Y : VType}\n {o o' : O}\n {i i' : I}\n {op : Σₛ} →\n (p : (o' , i') ⊑ lkpᵢ op i) →\n (V : Γ ⊢V⦂ proj₁ (payload op)) → \n (M : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')) →\n (N : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →\n --------------------------------------------------------------------------------------------------------------------------------------------------------\n ↓ op V (promise op ∣ p ↦ M `in N )\n ↝\n (let= (coerce (⊑ₒ-trans (proj₁ (⊑-proj p (proj₂ (proj₂ (⊑-just p))))) (↓ₑ-⊑ₒ-o' {o = o} (proj₂ (proj₂ (⊑-just p)))))\n (⊑ᵢ-trans (proj₂ (⊑-proj p (proj₂ (proj₂ (⊑-just p))))) (↓ₑ-⊑ₒ-i' {o = o} (proj₂ (proj₂ (⊑-just p)))))\n (M [ (sub-id [ V ]s)\n [ ƛ (promise op ∣ subst (λ oi → (o' , i') ⊑ oi) (sym ite-≡) ⊑-refl ↦ C-rename (ren-cong (ren-cong ren-wk)) M `in return (` Hd)) ]s ]c))\n `in (↓ op (V-rename ren-wk V) N))\n\n ↓-promise-op' : {X Y : VType}\n {o o' : O}\n {i i' : I}\n {op op' : Σₛ} →\n (p : ¬ op ≡ op') →\n (q : (o' , i') ⊑ lkpᵢ op' i) →\n (V : Γ ⊢V⦂ proj₁ (payload op)) → \n (M : Γ ∷ proj₁ (payload op') ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op' ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i')) →\n (N : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →\n ----------------------------------------------------------------------------------------------------------\n ↓ op V (promise op' ∣ q ↦ M `in N )\n ↝\n promise op' ∣ (lkpᵢ-↓ₑ-neq-⊑ {o = o} {i = i} p q) ↦ M `in ↓ op (V-rename ren-wk V) N \n\n ↓-await : {X Y : VType}\n {o : O}\n {i : I}\n {op : Σₛ} →\n (V : Γ ⊢V⦂ proj₁ (payload op)) →\n (W : Γ ⊢V⦂ ⟨ X ⟩) →\n (M : Γ ∷ X ⊢C⦂ Y ! (o , i)) →\n ------------------------------------------\n ↓ op V (await W until M)\n ↝\n await W until (↓ op (V-rename ren-wk V) M)\n\n ↓-spawn : {X : VType}\n {C : CType}\n {o : O}\n {i : I}\n {op : Σₛ} →\n (V : Γ ⊢V⦂ proj₁ (payload op)) →\n (M : Γ ■ ⊢C⦂ C) →\n (N : Γ ⊢C⦂ X ! (o , i)) →\n --------------------------------\n ↓ op V (spawn M N)\n ↝\n spawn M (↓ op V N)\n\n await-promise : {X : VType}\n {C : CType} → \n (V : Γ ⊢V⦂ X) → \n (M : Γ ∷ X ⊢C⦂ C) →\n --------------------\n await ⟨ V ⟩ until M\n ↝\n M [ sub-id [ V ]s ]c\n\n box-unbox : {X : VType}\n {C : CType} →\n (V : Γ ■ ⊢V⦂ X) →\n (M : Γ ∷ X ⊢C⦂ C) →\n -------------------\n unbox (□ V) `in M\n ↝\n M [ ⟨ sub-id ,, ■-str-v {Γ' = []} V ⟩ ]c\n\n -- EVALUATION CONTEXT RULE\n\n context : {Δ : BCtx}\n {C : CType} → \n (E : Γ ⊢E[ Δ ]⦂ C) →\n {M N : Γ ⋈ Δ ⊢C⦂ (hole-ty-e E)} →\n M ↝ N →\n -------------------------------\n E [ M ] ↝ E [ N ]\n\n -- COERCION RULES\n -- (THE RESULT OF WORKING WITH WELL-TYPED SYNTAX AND MAKING SUBSUMPTION INTO AN EXPLICIT COERCION)\n\n coerce-return : {X : VType}\n {o o' : O}\n {i i' : I}\n {p : o ⊑ₒ o'}\n {q : i ⊑ᵢ i'} → \n (V : Γ ⊢V⦂ X) →\n --------------------------------\n coerce p q (return V) ↝ return V\n\n coerce-↑ : {X : VType}\n {o o' : O}\n {i i' : I}\n {p : o ⊑ₒ o'}\n {q : i ⊑ᵢ i'}\n {op : Σₛ} → \n (r : op ∈ₒ o) →\n (V : Γ ⊢V⦂ proj₁ (payload op)) →\n (M : Γ ⊢C⦂ X ! (o , i)) →\n --------------------------------\n coerce p q (↑ op r V M)\n ↝\n ↑ op (p op r) V (coerce p q M)\n\n coerce-promise : {X Y : VType}\n {o o' o'' : O}\n {i i' i'' : I}\n {p : o ⊑ₒ o'}\n {q : i ⊑ᵢ i'}\n {op : Σₛ} →\n (r : (o'' , i'') ⊑ lkpᵢ op i)\n (M : Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o'' , i'') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o'' , i'')) →\n (N : Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i)) →\n -------------------------------------------------------------------------------------------------------------\n coerce p q (promise op ∣ r ↦ M `in N)\n ↝\n promise_∣_↦_`in_ op (subst (λ oi → (o'' , i'') ⊑ oi) (sym (lkpᵢ-next-eq q (proj₂ (proj₂ (⊑-just r)))))\n (⊑-trans r (proj₂ (proj₂ (⊑-just r))) (\n (lkpᵢ-next-⊑ₒ q (proj₂ (proj₂ (⊑-just r)))) ,\n (lkpᵢ-next-⊑ᵢ q (proj₂ (proj₂ (⊑-just r)))))))\n M\n (coerce p q N)\n\n coerce-await : {X Y : VType}\n {o o' : O}\n {i i' : I}\n {p : o ⊑ₒ o'}\n {q : i ⊑ᵢ i'} →\n (V : Γ ⊢V⦂ ⟨ X ⟩) →\n (M : Γ ∷ X ⊢C⦂ Y ! (o , i)) →\n -----------------------------\n coerce p q (await V until M)\n ↝\n await V until (coerce p q M)\n\n coerce-spawn : {X : VType}\n {C : CType}\n {o o' : O}\n {i i' : I}\n {p : o ⊑ₒ o'}\n {q : i ⊑ᵢ i'} →\n (M : Γ ■ ⊢C⦂ C) →\n (N : Γ ⊢C⦂ X ! (o , i)) → \n -------------------------\n coerce p q (spawn M N)\n ↝\n spawn M (coerce p q N)\n\n\n", "meta": {"hexsha": "e8d34b584b1a6b54e120ac8705b22e900034c4ab", "size": 19123, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Preservation.agda", "max_stars_repo_name": "danelahman/higher-order-aeff-agda", "max_stars_repo_head_hexsha": "b41df71f4456666aab4bd14e13d285c31af80ff6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-17T15:00:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T18:50:26.000Z", "max_issues_repo_path": "Preservation.agda", "max_issues_repo_name": "danelahman/modal-aeff-agda", "max_issues_repo_head_hexsha": "b41df71f4456666aab4bd14e13d285c31af80ff6", "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": "Preservation.agda", "max_forks_repo_name": "danelahman/modal-aeff-agda", "max_forks_repo_head_hexsha": "b41df71f4456666aab4bd14e13d285c31af80ff6", "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.0600775194, "max_line_length": 172, "alphanum_fraction": 0.2629817497, "num_tokens": 6678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.37989221226963205}} {"text": "{-# OPTIONS --safe #-}\n\nmodule Definition.Typed.Consequences.Substitution where\n\nopen import Definition.Untyped\nopen import Definition.Untyped.Properties\nopen import Definition.Typed\nopen import Definition.Typed.Properties\nopen import Definition.Typed.EqRelInstance\nopen import Definition.Typed.Weakening\nopen import Definition.Typed.Consequences.Syntactic\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.Properties\nopen import Definition.LogicalRelation.Substitution\nopen import Definition.LogicalRelation.Substitution.Irrelevance\nopen import Definition.LogicalRelation.Fundamental\n\nopen import Tools.Product\nimport Tools.PropositionalEquality as PE\n\n\n-- Well-formed substitution of types.\nsubstitution : ∀ {A rA Γ Δ σ} → Γ ⊢ A ^ rA → Δ ⊢ˢ σ ∷ Γ → ⊢ Δ → Δ ⊢ subst σ A ^ rA\nsubstitution A σ ⊢Δ =\n let X = fundamental A\n [Γ] = proj₁ X\n [A] = proj₂ X\n Y = fundamentalSubst (wf A) ⊢Δ σ\n [Γ]′ = proj₁ Y\n [σ] = proj₂ Y\n in escape (proj₁ ([A] ⊢Δ (irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ])))\n\n-- Well-formed substitution of type equality.\nsubstitutionEq : ∀ {A B rA Γ Δ σ σ′}\n → Γ ⊢ A ≡ B ^ rA → Δ ⊢ˢ σ ≡ σ′ ∷ Γ → ⊢ Δ → Δ ⊢ subst σ A ≡ subst σ′ B ^ rA\nsubstitutionEq A≡B σ ⊢Δ =\n let X = fundamentalEq A≡B\n [Γ] = proj₁ X\n [A] = proj₁ (proj₂ X)\n [B] = proj₁ (proj₂ (proj₂ X))\n [A≡B] = proj₂ (proj₂ (proj₂ X))\n Y = fundamentalSubstEq (wfEq A≡B) ⊢Δ σ\n [Γ]′ = proj₁ Y\n [σ] = proj₁ (proj₂ Y)\n [σ′] = proj₁ (proj₂ (proj₂ Y))\n [σ≡σ′] = proj₂ (proj₂ (proj₂ Y))\n [σ]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]\n [σ′]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ′]\n [σ≡σ′]′ = irrelevanceSubstEq [Γ]′ [Γ] ⊢Δ ⊢Δ [σ] [σ]′ [σ≡σ′]\n in escapeEq (proj₁ ([A] ⊢Δ [σ]′))\n (transEq (proj₁ ([A] ⊢Δ [σ]′)) (proj₁ ([B] ⊢Δ [σ]′))\n (proj₁ ([B] ⊢Δ [σ′]′)) ([A≡B] ⊢Δ [σ]′)\n (proj₂ ([B] ⊢Δ [σ]′) [σ′]′ [σ≡σ′]′))\n\n-- Well-formed substitution of terms.\nsubstitutionTerm : ∀ {t A rA Γ Δ σ}\n → Γ ⊢ t ∷ A ^ rA → Δ ⊢ˢ σ ∷ Γ → ⊢ Δ → Δ ⊢ subst σ t ∷ subst σ A ^ rA\nsubstitutionTerm t σ ⊢Δ =\n let X = fundamentalTerm t\n [Γ] = proj₁ X\n [A] = proj₁ (proj₂ X)\n [t] = proj₂ (proj₂ X)\n Y = fundamentalSubst (wfTerm t) ⊢Δ σ\n [Γ]′ = proj₁ Y\n [σ] = proj₂ Y\n [σ]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]\n in escapeTerm (proj₁ ([A] ⊢Δ [σ]′)) (proj₁ ([t] ⊢Δ [σ]′))\n\n-- Well-formed substitution of term equality.\nsubstitutionEqTerm : ∀ {t u A rA Γ Δ σ σ′}\n → Γ ⊢ t ≡ u ∷ A ^ rA → Δ ⊢ˢ σ ≡ σ′ ∷ Γ → ⊢ Δ\n → Δ ⊢ subst σ t ≡ subst σ′ u ∷ subst σ A ^ rA\nsubstitutionEqTerm t≡u σ≡σ′ ⊢Δ with fundamentalTermEq t≡u\nsubstitutionEqTerm t≡u σ≡σ′ ⊢Δ | [Γ] , modelsTermEq [A] [t] [u] [t≡u] =\n let Y = fundamentalSubstEq (wfEqTerm t≡u) ⊢Δ σ≡σ′\n [Γ]′ = proj₁ Y\n [σ] = proj₁ (proj₂ Y)\n [σ′] = proj₁ (proj₂ (proj₂ Y))\n [σ≡σ′] = proj₂ (proj₂ (proj₂ Y)) \n [σ]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]\n [σ′]′ = irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ′]\n [σ≡σ′]′ = irrelevanceSubstEq [Γ]′ [Γ] ⊢Δ ⊢Δ [σ] [σ]′ [σ≡σ′]\n in escapeTermEq (proj₁ ([A] ⊢Δ [σ]′))\n (transEqTerm (proj₁ ([A] ⊢Δ [σ]′)) ([t≡u] ⊢Δ [σ]′)\n (proj₂ ([u] ⊢Δ [σ]′) [σ′]′ [σ≡σ′]′))\n\n-- Reflexivity of well-formed substitution.\nsubstRefl : ∀ {σ Γ Δ}\n → Δ ⊢ˢ σ ∷ Γ\n → Δ ⊢ˢ σ ≡ σ ∷ Γ\nsubstRefl id = id\nsubstRefl (σ , x) = substRefl σ , genRefl x\n\n-- Weakening of well-formed substitution.\nwkSubst′ : ∀ {ρ σ Γ Δ Δ′} (⊢Γ : ⊢ Γ) (⊢Δ : ⊢ Δ) (⊢Δ′ : ⊢ Δ′)\n ([ρ] : ρ ∷ Δ′ ⊆ Δ)\n ([σ] : Δ ⊢ˢ σ ∷ Γ)\n → Δ′ ⊢ˢ ρ •ₛ σ ∷ Γ\nwkSubst′ ε ⊢Δ ⊢Δ′ ρ id = id\nwkSubst′ (_∙_ {Γ} {A} ⊢Γ ⊢A) ⊢Δ ⊢Δ′ ρ (tailσ , headσ) =\n wkSubst′ ⊢Γ ⊢Δ ⊢Δ′ ρ tailσ\n , PE.subst (λ x → _ ⊢ _ ∷ x ^ _) (wk-subst A) (wkTerm ρ ⊢Δ′ headσ)\n\n-- Weakening of well-formed substitution by one.\nwk1Subst′ : ∀ {F rF σ Γ Δ} (⊢Γ : ⊢ Γ) (⊢Δ : ⊢ Δ)\n (⊢F : Δ ⊢ F ^ rF)\n ([σ] : Δ ⊢ˢ σ ∷ Γ)\n → (Δ ∙ F ^ rF) ⊢ˢ wk1Subst σ ∷ Γ\nwk1Subst′ {F} {σ} {Γ} {Δ} ⊢Γ ⊢Δ ⊢F [σ] =\n wkSubst′ ⊢Γ ⊢Δ (⊢Δ ∙ ⊢F) (step id) [σ]\n\n-- Lifting of well-formed substitution.\nliftSubst′ : ∀ {F rF σ Γ Δ} (⊢Γ : ⊢ Γ) (⊢Δ : ⊢ Δ)\n (⊢F : Γ ⊢ F ^ rF)\n ([σ] : Δ ⊢ˢ σ ∷ Γ)\n → (Δ ∙ subst σ F ^ rF) ⊢ˢ liftSubst σ ∷ Γ ∙ F ^ rF\nliftSubst′ {F} {rF} {σ} {Γ} {Δ} ⊢Γ ⊢Δ ⊢F [σ] =\n let ⊢Δ∙F = ⊢Δ ∙ substitution ⊢F [σ] ⊢Δ\n in wkSubst′ ⊢Γ ⊢Δ ⊢Δ∙F (step id) [σ]\n , var ⊢Δ∙F (PE.subst (λ x → 0 ∷ x ^ rF ∈ (Δ ∙ subst σ F ^ rF))\n (wk-subst F) here)\n\n-- Well-formed identity substitution.\nidSubst′ : ∀ {Γ} (⊢Γ : ⊢ Γ)\n → Γ ⊢ˢ idSubst ∷ Γ\nidSubst′ ε = id\nidSubst′ (_∙_ {Γ} {A} {rA} ⊢Γ ⊢A) =\n wk1Subst′ ⊢Γ ⊢Γ ⊢A (idSubst′ ⊢Γ)\n , PE.subst (λ x → Γ ∙ A ^ rA ⊢ _ ∷ x ^ rA) (wk1-tailId A) (var (⊢Γ ∙ ⊢A) here)\n\n-- Well-formed substitution composition.\nsubstComp′ : ∀ {σ σ′ Γ Δ Δ′} (⊢Γ : ⊢ Γ) (⊢Δ : ⊢ Δ) (⊢Δ′ : ⊢ Δ′)\n ([σ] : Δ′ ⊢ˢ σ ∷ Δ)\n ([σ′] : Δ ⊢ˢ σ′ ∷ Γ)\n → Δ′ ⊢ˢ σ ₛ•ₛ σ′ ∷ Γ\nsubstComp′ ε ⊢Δ ⊢Δ′ [σ] id = id\nsubstComp′ (_∙_ {Γ} {A} {rA} ⊢Γ ⊢A) ⊢Δ ⊢Δ′ [σ] ([tailσ′] , [headσ′]) =\n substComp′ ⊢Γ ⊢Δ ⊢Δ′ [σ] [tailσ′]\n , PE.subst (λ x → _ ⊢ _ ∷ x ^ rA) (substCompEq A)\n (substitutionTerm [headσ′] [σ] ⊢Δ′)\n\n-- Well-formed singleton substitution of terms.\nsingleSubst : ∀ {A t rA Γ} → Γ ⊢ t ∷ A ^ rA → Γ ⊢ˢ sgSubst t ∷ Γ ∙ A ^ rA\nsingleSubst {A} {rA = rA} t =\n let ⊢Γ = wfTerm t\n in idSubst′ ⊢Γ , PE.subst (λ x → _ ⊢ _ ∷ x ^ rA) (PE.sym (subst-id A)) t\n\n-- Well-formed singleton substitution of term equality.\nsingleSubstEq : ∀ {A t u rA Γ} → Γ ⊢ t ≡ u ∷ A ^ rA\n → Γ ⊢ˢ sgSubst t ≡ sgSubst u ∷ Γ ∙ A ^ rA\nsingleSubstEq {A} {rA = rA} t =\n let ⊢Γ = wfEqTerm t\n in substRefl (idSubst′ ⊢Γ) , PE.subst (λ x → _ ⊢ _ ≡ _ ∷ x ^ rA) (PE.sym (subst-id A)) t\n\n-- Well-formed singleton substitution of terms with lifting.\nsingleSubst↑ : ∀ {A t rA Γ} → Γ ∙ A ^ rA ⊢ t ∷ wk1 A ^ rA\n → Γ ∙ A ^ rA ⊢ˢ consSubst (wk1Subst idSubst) t ∷ Γ ∙ A ^ rA\nsingleSubst↑ {A} {rA = rA} t with wfTerm t\n... | ⊢Γ ∙ ⊢A = wk1Subst′ ⊢Γ ⊢Γ ⊢A (idSubst′ ⊢Γ)\n , PE.subst (λ x → _ ∙ A ^ rA ⊢ _ ∷ x ^ _) (wk1-tailId A) t\n\n-- Well-formed singleton substitution of term equality with lifting.\nsingleSubst↑Eq : ∀ {A rA t u Γ} → Γ ∙ A ^ rA ⊢ t ≡ u ∷ wk1 A ^ rA\n → Γ ∙ A ^ rA ⊢ˢ consSubst (wk1Subst idSubst) t ≡ consSubst (wk1Subst idSubst) u ∷ Γ ∙ A ^ rA\nsingleSubst↑Eq {A} {rA} t with wfEqTerm t\n... | ⊢Γ ∙ ⊢A = substRefl (wk1Subst′ ⊢Γ ⊢Γ ⊢A (idSubst′ ⊢Γ))\n , PE.subst (λ x → _ ∙ A ^ rA ⊢ _ ≡ _ ∷ x ^ rA) (wk1-tailId A) t\n\n-- Helper lemmas for single substitution\n\nsubstType : ∀ {t F rF G rG Γ} → Γ ∙ F ^ rF ⊢ G ^ rG → Γ ⊢ t ∷ F ^ rF → Γ ⊢ G [ t ] ^ rG\nsubstType {t} {F} {G} ⊢G ⊢t =\n let ⊢Γ = wfTerm ⊢t\n in substitution ⊢G (singleSubst ⊢t) ⊢Γ\n\nsubstTypeEq : ∀ {t u F rF G E rG Γ} → Γ ∙ F ^ rF ⊢ G ≡ E ^ rG\n → Γ ⊢ t ≡ u ∷ F ^ rF\n → Γ ⊢ G [ t ] ≡ E [ u ] ^ rG\nsubstTypeEq {F = F} ⊢G ⊢t =\n let ⊢Γ = wfEqTerm ⊢t\n in substitutionEq ⊢G (singleSubstEq ⊢t) ⊢Γ\n\nsubstTerm : ∀ {F rF G rG t f Γ} → Γ ∙ F ^ rF ⊢ f ∷ G ^ rG\n → Γ ⊢ t ∷ F ^ rF\n → Γ ⊢ f [ t ] ∷ G [ t ] ^ rG\nsubstTerm {F} {G} {t} {f} ⊢f ⊢t =\n let ⊢Γ = wfTerm ⊢t\n in substitutionTerm ⊢f (singleSubst ⊢t) ⊢Γ\n\nsubstTypeΠ : ∀ {t F rF lF lG G rΠ lΠ Γ} → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ rΠ , ι lΠ ] → Γ ⊢ t ∷ F ^ [ rF , ι lF ]\n → Γ ⊢ G [ t ] ^ [ rΠ , ι lG ] \nsubstTypeΠ ΠFG t with syntacticΠ ΠFG\nsubstTypeΠ ΠFG t | F , G = substType G t\n\nsubst↑Type : ∀ {t F rF G rG Γ}\n → Γ ∙ F ^ rF ⊢ G ^ rG\n → Γ ∙ F ^ rF ⊢ t ∷ wk1 F ^ rF\n → Γ ∙ F ^ rF ⊢ G [ t ]↑ ^ rG\nsubst↑Type ⊢G ⊢t = substitution ⊢G (singleSubst↑ ⊢t) (wfTerm ⊢t)\n\nsubst↑TypeEq : ∀ {t u F rF G E rG Γ}\n → Γ ∙ F ^ rF ⊢ G ≡ E ^ rG\n → Γ ∙ F ^ rF ⊢ t ≡ u ∷ wk1 F ^ rF\n → Γ ∙ F ^ rF ⊢ G [ t ]↑ ≡ E [ u ]↑ ^ rG\nsubst↑TypeEq ⊢G ⊢t = substitutionEq ⊢G (singleSubst↑Eq ⊢t) (wfEqTerm ⊢t)\n", "meta": {"hexsha": "cd58d3e580f253f4f52069473f1ac22e4f96cc16", "size": 8100, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Typed/Consequences/Substitution.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/Typed/Consequences/Substitution.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/Typed/Consequences/Substitution.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": 39.3203883495, "max_line_length": 117, "alphanum_fraction": 0.4979012346, "num_tokens": 3847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.37973086127400996}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule PathLemmas where\n\nopen import Relation.Binary.PropositionalEquality using\n (_≡_; sym; refl)\n \n------------------------------------------------------------------------------\n-- These also follow from irrelevance, but this is nicer\n\nsym-sym : {A : Set} {x y : A} {p : x ≡ y} → sym (sym p) ≡ p\nsym-sym {_} {x} {.x} {refl} = refl\n\n------------------------------------------------------------------------------\n", "meta": {"hexsha": "66ba03ee0820971dafcda1cce674b904de54ced2", "size": 444, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Univalence/PathLemmas.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "Univalence/PathLemmas.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "Univalence/PathLemmas.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 29.6, "max_line_length": 78, "alphanum_fraction": 0.4054054054, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6406358411176238, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.3796834657638978}} {"text": "------------------------------------------------------------------------\n-- Incorrect coinductive axiomatisation of subtyping\n------------------------------------------------------------------------\n\n-- This module shows that if we remove transitivity from\n-- RecursiveTypes.Subtyping.Axiomatic.Coinductive._≤_, and take the\n-- transitive closure of the resulting relation, then we get a weaker\n-- (less defined) relation than the one we started with.\n\nmodule RecursiveTypes.Subtyping.Axiomatic.Incorrect where\n\nopen import Codata.Musical.Notation\nopen import Data.Fin using (Fin; zero; suc)\nopen import Function using (id; _$_)\nopen import Data.Nat\n using (ℕ; zero; suc; z≤n; s≤s; ≤′-refl) renaming (_≤_ to _≤ℕ_)\nopen import Data.Nat.Induction\nopen import Data.Nat.Properties using (≤-step; ≤⇒≤′)\nopen import Data.Product as Prod\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Nullary\n\nopen import RecursiveTypes.Syntax hiding (_≲_)\nopen import RecursiveTypes.Substitution using (_[0≔_]; unfold[μ_⟶_])\nopen import RecursiveTypes.Subtyping.Semantic.Coinductive as Sem\n using (_≤Coind_; ⊥; ⊤; _⟶_)\n\n------------------------------------------------------------------------\n-- The alternative \"subtyping\" relation\n\ninfixr 10 _⟶_\ninfix 4 _≤_ _≤′_\ninfixr 2 _≤⟨_⟩_\ninfix 2 _∎\n\n-- A definition which does not include a transitivity constructor.\n\ndata _≤′_ {n} : Ty n → Ty n → Set where\n ⊥ : ∀ {τ} → ⊥ ≤′ τ\n ⊤ : ∀ {σ} → σ ≤′ ⊤\n _⟶_ : ∀ {σ₁ σ₂ τ₁ τ₂}\n (τ₁≤′σ₁ : ∞ (τ₁ ≤′ σ₁)) (σ₂≤′τ₂ : ∞ (σ₂ ≤′ τ₂)) →\n σ₁ ⟶ σ₂ ≤′ τ₁ ⟶ τ₂\n\n unfold : ∀ {τ₁ τ₂} → μ τ₁ ⟶ τ₂ ≤′ unfold[μ τ₁ ⟶ τ₂ ]\n fold : ∀ {τ₁ τ₂} → unfold[μ τ₁ ⟶ τ₂ ] ≤′ μ τ₁ ⟶ τ₂\n\n _∎ : ∀ τ → τ ≤′ τ\n\n-- The transitive closure of this relation.\n\ndata _≤_ {n} : Ty n → Ty n → Set where\n include : ∀ {σ τ} (σ≤τ : σ ≤′ τ) → σ ≤ τ\n _≤⟨_⟩_ : ∀ τ₁ {τ₂ τ₃} (τ₁≤τ₂ : τ₁ ≤ τ₂) (τ₂≤τ₃ : τ₂ ≤ τ₃) → τ₁ ≤ τ₃\n\n------------------------------------------------------------------------\n-- Some types used in counterexamples below\n\nσ : Ty zero\nσ = μ ⊤ ⟶ var zero\n\nτ : Ty zero\nτ = μ ⊥ ⟶ var zero\n\nσ≤τ : σ ≤Coind τ\nσ≤τ = ♯ ⊥ ⟶ ♯ σ≤τ\n\n------------------------------------------------------------------------\n-- Soundness and incompleteness of _≤′_\n\nsound′ : ∀ {n} {σ τ : Ty n} → σ ≤′ τ → σ ≤Coind τ\nsound′ ⊥ = ⊥\nsound′ ⊤ = ⊤\nsound′ (τ₁≤σ₁ ⟶ σ₂≤τ₂) = ♯ sound′ (♭ τ₁≤σ₁) ⟶ ♯ sound′ (♭ σ₂≤τ₂)\nsound′ unfold = Sem.unfold\nsound′ fold = Sem.fold\nsound′ (τ ∎) = Sem.refl∞ _\n\nincomplete′ : ¬ (∀ {n} {σ τ : Ty n} → σ ≤Coind τ → σ ≤′ τ)\nincomplete′ hyp with hyp {σ = σ} {τ = τ} σ≤τ\n... | ()\n\n------------------------------------------------------------------------\n-- Soundness of _≤_\n\nsound : ∀ {n} {σ τ : Ty n} → σ ≤ τ → σ ≤Coind τ\nsound (τ₁ ≤⟨ τ₁≤τ₂ ⟩ τ₂≤τ₃) = Sem.trans (sound τ₁≤τ₂) (sound τ₂≤τ₃)\nsound (include σ≤τ) = sound′ σ≤τ\n\n------------------------------------------------------------------------\n-- An alternative definition of the transitive closure of _≤′_\n\ninfixr 5 _∷_\ninfix 4 _≲_\n\ndata _≲_ {n} : Ty n → Ty n → Set where\n [_] : ∀ {σ τ} (σ≤τ : σ ≤′ τ) → σ ≲ τ\n _∷_ : ∀ {τ₁ τ₂ τ₃} (τ₁≤τ₂ : τ₁ ≤′ τ₂) (τ₂≲τ₃ : τ₂ ≲ τ₃) → τ₁ ≲ τ₃\n\n-- This definition is transitive.\n\n_++_ : ∀ {n} {τ₁ τ₂ τ₃ : Ty n} → τ₁ ≲ τ₂ → τ₂ ≲ τ₃ → τ₁ ≲ τ₃\n[ τ₁≤τ₂ ] ++ τ₂≤τ₃ = τ₁≤τ₂ ∷ τ₂≤τ₃\n(τ₁≤τ₂ ∷ τ₂≤τ₃) ++ τ₃≤τ₄ = τ₁≤τ₂ ∷ (τ₂≤τ₃ ++ τ₃≤τ₄)\n\n-- Hence it is complete with respect to the one above.\n\n≲-complete : ∀ {n} {σ τ : Ty n} → σ ≤ τ → σ ≲ τ\n≲-complete (include σ≤τ) = [ σ≤τ ]\n≲-complete (τ₁ ≤⟨ τ₁≤τ₂ ⟩ τ₂≤τ₃) = ≲-complete τ₁≤τ₂ ++ ≲-complete τ₂≤τ₃\n\n-- It is also sound.\n\n≲-sound : ∀ {n} {σ τ : Ty n} → σ ≲ τ → σ ≤ τ\n≲-sound [ σ≤τ ] = include σ≤τ\n≲-sound (τ₁≤τ₂ ∷ τ₂≲τ₃) = _ ≤⟨ include τ₁≤τ₂ ⟩ ≲-sound τ₂≲τ₃\n\n-- The number of uses of transitivity in the proof.\n\nlength : ∀ {n} {σ τ : Ty n} → σ ≲ τ → ℕ\nlength [ σ≤τ ] = 0\nlength (τ₁≤τ₂ ∷ τ₂≲τ₃) = suc (length τ₂≲τ₃)\n\n------------------------------------------------------------------------\n-- Given proofs of certain statements one can extract shorter or\n-- equally long proofs for related statements\n\nmutual\n\n codomain-⟶μ : ∀ {n} {σ₁ σ₂ : Ty n} {τ₁ τ₂} →\n (σ₁⟶σ₂≲μτ₁⟶τ₂ : σ₁ ⟶ σ₂ ≲ μ τ₁ ⟶ τ₂) →\n ∃ λ (σ₂≲τ₂′ : σ₂ ≲ τ₂ [0≔ μ τ₁ ⟶ τ₂ ]) →\n length σ₂≲τ₂′ ≤ℕ length σ₁⟶σ₂≲μτ₁⟶τ₂\n codomain-⟶μ [ fold ] = ([ _ ∎ ] , z≤n)\n codomain-⟶μ (τ₁≤′σ₁ ⟶ σ₂≤′τ₂ ∷ τ₂≲τ₃) = Prod.map (_∷_ (♭ σ₂≤′τ₂)) s≤s (codomain-⟶μ τ₂≲τ₃)\n codomain-⟶μ (fold ∷ τ₂≲τ₃) = Prod.map id ≤-step (codomain-μμ τ₂≲τ₃)\n codomain-⟶μ ((._ ∎) ∷ τ₂≲τ₃) = Prod.map id ≤-step (codomain-⟶μ τ₂≲τ₃)\n codomain-⟶μ (⊤ ∷ τ₂≲τ₃) with sound (≲-sound τ₂≲τ₃)\n ... | ()\n\n codomain-μμ : ∀ {n} {σ₁ σ₂ τ₁ τ₂ : Ty (suc n)} →\n (μσ₁⟶σ₂≲μτ₁⟶τ₂ : μ σ₁ ⟶ σ₂ ≲ μ τ₁ ⟶ τ₂) →\n ∃ λ (σ₂′≲τ₂′ : σ₂ [0≔ μ σ₁ ⟶ σ₂ ] ≲ τ₂ [0≔ μ τ₁ ⟶ τ₂ ]) →\n length σ₂′≲τ₂′ ≤ℕ length μσ₁⟶σ₂≲μτ₁⟶τ₂\n codomain-μμ [ ._ ∎ ] = ([ _ ∎ ] , z≤n)\n codomain-μμ (unfold ∷ τ₂≲τ₃) = Prod.map id ≤-step (codomain-⟶μ τ₂≲τ₃)\n codomain-μμ ((._ ∎) ∷ τ₂≲τ₃) = Prod.map id ≤-step (codomain-μμ τ₂≲τ₃)\n codomain-μμ (⊤ ∷ τ₂≲τ₃) with sound (≲-sound τ₂≲τ₃)\n ... | ()\n\n------------------------------------------------------------------------\n-- Incompleteness of _≤_\n\nincomplete : ¬ (∀ {n} {σ τ : Ty n} → σ ≤Coind τ → σ ≤ τ)\nincomplete hyp = σ≴τ $ ≲-complete $ hyp σ≤τ\n where\n σ≴τ : ¬ σ ≲ τ\n σ≴τ σ≲τ = <′-rec Pred ≴ _ σ≲τ refl\n where\n Pred : ℕ → Set\n Pred n = (σ≲τ : σ ≲ τ) → length σ≲τ ≢ n\n\n ≴ : ∀ n → <′-Rec Pred n → Pred n\n ≴ n rec [ () ] _\n ≴ ._ rec ((._ ∎) ∷ τ₂≲τ₃) refl = rec _ ≤′-refl τ₂≲τ₃ refl\n ≴ ._ rec (unfold ∷ τ₂≲τ₃) refl with codomain-⟶μ τ₂≲τ₃\n ... | (τ₂≲τ₃′ , not-longer) = rec _ (≤⇒≤′ $ s≤s not-longer) τ₂≲τ₃′ refl\n ≴ n rec (⊤ ∷ τ₂≲τ₃) _ with sound (≲-sound τ₂≲τ₃)\n ... | ()\n", "meta": {"hexsha": "f85e36591ab63550149d9a4ab0f0478ede894e18", "size": 5905, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "RecursiveTypes/Subtyping/Axiomatic/Incorrect.agda", "max_stars_repo_name": "nad/codata", "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_issues_repo_path": "RecursiveTypes/Subtyping/Axiomatic/Incorrect.agda", "max_issues_repo_name": "nad/codata", "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": "RecursiveTypes/Subtyping/Axiomatic/Incorrect.agda", "max_forks_repo_name": "nad/codata", "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": 34.7352941176, "max_line_length": 91, "alphanum_fraction": 0.4772226926, "num_tokens": 2559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544085240401, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3795995439842086}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import HoTT\nopen import cohomology.Exactness\nopen import cohomology.FunctionOver\n\n{- Splitting Lemma - Right Split\n Assume an exact sequence:\n\n φ ψ\n 0 → G → H → K\n\n where H is abelian. If ψ has a right inverse χ, then H == G × K. Over\n this path φ becomes the natural injection and ψ the natural projection.\n\n The only non-private terms are [iso], [φ-over-iso], and [ψ-over-iso].\n-}\n\nmodule cohomology.SplitExactRight {i} {L G H K : Group i}\n (H-abelian : is-abelian H) (φ : G →ᴳ H) (ψ : H →ᴳ K) where\n\nprivate\n module G = Group G\n module H = Group H\n module K = Group K\n module φ = GroupHom φ\n module ψ = GroupHom ψ\n\nmodule SplitExactRight\n (ex : is-exact-seq (L ⟨ cst-hom ⟩→ G ⟨ φ ⟩→ H ⟨ ψ ⟩→ K ⊣|))\n (χ : K →ᴳ H) (χ-rinv : (k : K.El) → ψ.f (GroupHom.f χ k) == k)\n where\n\n private\n module χ = GroupHom χ\n\n {- H == Ker ψ × Im χ -}\n\n ker-part : H →ᴳ Ker ψ\n ker-part = ker-hom ψ\n (comp-hom H-abelian (idhom H) (inv-hom H H-abelian ∘ᴳ (χ ∘ᴳ ψ)))\n (λ h →\n ψ.f (H.comp h (H.inv (χ.f (ψ.f h))))\n =⟨ ψ.pres-comp h (H.inv (χ.f (ψ.f h))) ⟩\n K.comp (ψ.f h) (ψ.f (H.inv (χ.f (ψ.f h))))\n =⟨ ! (χ.pres-inv (ψ.f h))\n |in-ctx (λ w → K.comp (ψ.f h) (ψ.f w)) ⟩\n K.comp (ψ.f h) (ψ.f (χ.f (K.inv (ψ.f h))))\n =⟨ χ-rinv (K.inv (ψ.f h)) |in-ctx (λ w → K.comp (ψ.f h) w) ⟩\n K.comp (ψ.f h) (K.inv (ψ.f h))\n =⟨ K.invr (ψ.f h) ⟩\n K.ident ∎)\n\n ker-part-kerψ : (h : H.El) (p : ψ.f h == K.ident)\n → GroupHom.f ker-part h == (h , p)\n ker-part-kerψ h p = pair=\n (H.comp h (H.inv (χ.f (ψ.f h)))\n =⟨ p |in-ctx (λ w → H.comp h (H.inv (χ.f w))) ⟩\n H.comp h (H.inv (χ.f K.ident))\n =⟨ χ.pres-ident |in-ctx (λ w → H.comp h (H.inv w)) ⟩\n H.comp h (H.inv H.ident)\n =⟨ group-inv-ident H |in-ctx H.comp h ⟩\n H.comp h H.ident\n =⟨ H.unitr h ⟩\n h ∎)\n (prop-has-all-paths-↓ (K.El-level _ _))\n\n ker-part-imχ : (h : H.El) → Trunc -1 (Σ K.El (λ k → χ.f k == h))\n → GroupHom.f ker-part h == Group.ident (Ker ψ)\n ker-part-imχ h = Trunc-rec (Group.El-level (Ker ψ) _ _) $\n (λ {(k , p) → pair=\n (H.comp h (H.inv (χ.f (ψ.f h)))\n =⟨ ! p |in-ctx (λ w → H.comp w (H.inv (χ.f (ψ.f w)))) ⟩\n H.comp (χ.f k) (H.inv (χ.f (ψ.f (χ.f k))))\n =⟨ χ-rinv k |in-ctx (λ w → H.comp (χ.f k) (H.inv (χ.f w))) ⟩\n H.comp (χ.f k) (H.inv (χ.f k))\n =⟨ H.invr (χ.f k) ⟩\n H.ident ∎)\n (prop-has-all-paths-↓ (K.El-level _ _))})\n\n\n im-part : H →ᴳ Im χ\n im-part = im-in-hom χ ∘ᴳ ψ\n\n im-part-kerψ : (h : H.El) → ψ.f h == K.ident\n → GroupHom.f im-part h == Group.ident (Im χ)\n im-part-kerψ h p = pair=\n (ap χ.f p ∙ χ.pres-ident)\n (prop-has-all-paths-↓ Trunc-level)\n\n im-part-imχ : (h : H.El) (s : Trunc -1 (Σ K.El (λ k → χ.f k == h)))\n → GroupHom.f im-part h == (h , s)\n im-part-imχ h s = pair=\n (Trunc-rec (Group.El-level H _ _)\n (λ {(k , p) →\n χ.f (ψ.f h) =⟨ ! p |in-ctx (χ.f ∘ ψ.f) ⟩\n χ.f (ψ.f (χ.f k)) =⟨ χ-rinv k |in-ctx χ.f ⟩\n χ.f k =⟨ p ⟩\n h ∎})\n s)\n (prop-has-all-paths-↓ Trunc-level)\n\n decomp : H →ᴳ Ker ψ ×ᴳ Im χ\n decomp = ×ᴳ-hom-in ker-part im-part\n\n decomp-is-equiv : is-equiv (GroupHom.f decomp)\n decomp-is-equiv = is-eq _ dinv decomp-dinv dinv-decomp\n where\n dinv : Group.El (Ker ψ ×ᴳ Im χ) → H.El\n dinv ((h₁ , _) , (h₂ , _)) = H.comp h₁ h₂\n\n decomp-dinv : ∀ s → GroupHom.f decomp (dinv s) == s\n decomp-dinv ((h₁ , kr) , (h₂ , im)) = pair×=\n (GroupHom.f ker-part (H.comp h₁ h₂)\n =⟨ GroupHom.pres-comp ker-part h₁ h₂ ⟩\n Group.comp (Ker ψ) (GroupHom.f ker-part h₁) (GroupHom.f ker-part h₂)\n =⟨ ker-part-kerψ h₁ kr\n |in-ctx (λ w → Group.comp (Ker ψ) w (GroupHom.f ker-part h₂)) ⟩\n Group.comp (Ker ψ) (h₁ , kr) (GroupHom.f ker-part h₂)\n =⟨ ker-part-imχ h₂ im\n |in-ctx (λ w → Group.comp (Ker ψ) (h₁ , kr) w) ⟩\n Group.comp (Ker ψ) (h₁ , kr) (Group.ident (Ker ψ))\n =⟨ Group.unitr (Ker ψ) (h₁ , kr) ⟩\n (h₁ , kr) ∎)\n (GroupHom.f im-part (H.comp h₁ h₂)\n =⟨ GroupHom.pres-comp im-part h₁ h₂ ⟩\n Group.comp (Im χ) (GroupHom.f im-part h₁) (GroupHom.f im-part h₂)\n =⟨ im-part-kerψ h₁ kr\n |in-ctx (λ w → Group.comp (Im χ) w (GroupHom.f im-part h₂)) ⟩\n Group.comp (Im χ) (Group.ident (Im χ)) (GroupHom.f im-part h₂)\n =⟨ im-part-imχ h₂ im\n |in-ctx (λ w → Group.comp (Im χ) (Group.ident (Im χ)) w) ⟩\n Group.comp (Im χ) (Group.ident (Im χ)) (h₂ , im)\n =⟨ Group.unitl (Im χ) (h₂ , im) ⟩\n (h₂ , im) ∎)\n\n dinv-decomp : ∀ h → dinv (GroupHom.f decomp h) == h\n dinv-decomp h =\n H.comp (H.comp h (H.inv (χ.f (ψ.f h)))) (χ.f (ψ.f h))\n =⟨ H.assoc h (H.inv (χ.f (ψ.f h))) (χ.f (ψ.f h)) ⟩\n H.comp h (H.comp (H.inv (χ.f (ψ.f h))) (χ.f (ψ.f h)))\n =⟨ H.invl (χ.f (ψ.f h)) |in-ctx H.comp h ⟩\n H.comp h H.ident\n =⟨ H.unitr h ⟩\n h ∎\n\n decomp-equiv : H.El ≃ Group.El (Ker ψ ×ᴳ Im χ)\n decomp-equiv = (_ , decomp-is-equiv)\n\n decomp-iso : H == Ker ψ ×ᴳ Im χ\n decomp-iso = group-ua (decomp , decomp-is-equiv)\n\n {- G == Ker ψ -}\n\n ker-in-φ : G →ᴳ Ker ψ\n ker-in-φ = ker-hom ψ φ (λ g → itok (exact-get ex 1) (φ.f g) [ g , idp ])\n\n ker-in-φ-is-equiv : is-equiv (GroupHom.f ker-in-φ)\n ker-in-φ-is-equiv = surj-inj-is-equiv ker-in-φ inj surj\n where\n inj = zero-kernel-injective ker-in-φ\n (λ g p → Trunc-rec (G.El-level _ _)\n (λ {(_ , q) → ! q}) (ktoi (exact-get ex 0) g (ap fst p)))\n\n surj = λ {(h , p) → Trunc-fmap\n (λ {(g , q) → (g , pair= q (prop-has-all-paths-↓ (K.El-level _ _)))})\n (ktoi (exact-get ex 1) h p)}\n\n G-iso-Kerψ : G == Ker ψ\n G-iso-Kerψ = group-ua (ker-in-φ , ker-in-φ-is-equiv)\n\n {- K == Im χ -}\n\n im-in-χ-is-equiv : is-equiv (GroupHom.f (im-in-hom χ))\n im-in-χ-is-equiv = surj-inj-is-equiv (im-in-hom χ) inj (im-in-surj χ)\n where\n inj = zero-kernel-injective (im-in-hom χ)\n (λ k p → ! (χ-rinv k) ∙ ap ψ.f (ap fst p) ∙ ψ.pres-ident)\n\n K-iso-Imχ : K == Im χ\n K-iso-Imχ = group-ua (im-in-hom χ , im-in-χ-is-equiv)\n\n {- H == G ×ᴳ K -}\n\n iso : H == G ×ᴳ K\n iso = decomp-iso ∙ ap2 _×ᴳ_ (! G-iso-Kerψ) (! K-iso-Imχ)\n\n private\n\n decomp-φ = ×ᴳ-hom-in ker-in-φ (cst-hom {G = G} {H = Im χ})\n ψ-dinv = ψ ∘ᴳ ×ᴳ-sum-hom H-abelian (ker-inj ψ) (im-inj χ)\n\n φ-over-decomp : φ == decomp-φ [ (λ J → G →ᴳ J) ↓ decomp-iso ]\n φ-over-decomp = codomain-over-iso $ codomain-over-equiv φ.f _ ▹ lemma\n where\n lemma : GroupHom.f decomp ∘ φ.f == GroupHom.f decomp-φ\n lemma = λ= (λ g → pair×=\n (ker-part-kerψ (φ.f g) (itok (exact-get ex 1) (φ.f g) [ g , idp ]))\n (im-part-kerψ (φ.f g) (itok (exact-get ex 1) (φ.f g) [ g , idp ])))\n\n ψ-over-decomp : ψ == ψ-dinv [ (λ J → J →ᴳ K) ↓ decomp-iso ]\n ψ-over-decomp = domain-over-iso $ domain!-over-equiv ψ.f _\n\n id-over-G-iso : idhom _ == ker-in-φ [ (λ J → G →ᴳ J) ↓ G-iso-Kerψ ]\n id-over-G-iso = codomain-over-iso $ codomain-over-equiv (idf _) _\n\n φ-over-G-iso : φ == ker-inj ψ [ (λ J → J →ᴳ H) ↓ G-iso-Kerψ ]\n φ-over-G-iso =\n domain-over-iso $ domain-over-equiv (GroupHom.f (ker-inj ψ)) _\n\n ψ|imχ-over-K-iso : idhom K == ψ ∘ᴳ im-inj χ\n [ (λ J → J →ᴳ K) ↓ K-iso-Imχ ]\n ψ|imχ-over-K-iso = domain-over-iso $ domain!-over-equiv (idf _) _ ▹ lemma\n where\n lemma : <– (_ , im-in-χ-is-equiv) == ψ.f ∘ GroupHom.f (im-inj χ)\n lemma = λ= (λ {(h , s) →\n Trunc-elim {P = λ s' → <– (_ , im-in-χ-is-equiv) (h , s') == ψ.f h}\n (λ _ → K.El-level _ _) (λ {(k , p) → ! (χ-rinv k) ∙ ap ψ.f p}) s})\n\n φ-over-G-K-isos : decomp-φ == ×ᴳ-inl\n [ (λ J → G →ᴳ J) ↓ ap2 _×ᴳ_ (! G-iso-Kerψ) (! K-iso-Imχ) ]\n φ-over-G-K-isos = ↓-ap2-in _ _×ᴳ_ $ transport\n (λ q → decomp-φ == ×ᴳ-inl [ (λ {(J₁ , J₂) → G →ᴳ J₁ ×ᴳ J₂}) ↓ q ])\n (! (pair×=-split-l (! G-iso-Kerψ) (! K-iso-Imχ)))\n (l ∙ᵈ r)\n where\n l : decomp-φ == ×ᴳ-hom-in (idhom G) (cst-hom {G = G} {H = Im χ})\n [ (λ {(J₁ , J₂) → G →ᴳ J₁ ×ᴳ J₂})\n ↓ ap (λ J → J , Im χ) (! G-iso-Kerψ) ]\n l = ↓-ap-in _ (λ J → J , Im χ)\n (ap↓ (λ θ → ×ᴳ-hom-in θ (cst-hom {G = G} {H = Im χ}))\n (!ᵈ id-over-G-iso))\n\n r : ×ᴳ-hom-in (idhom G) (cst-hom {H = Im χ}) == ×ᴳ-inl\n [ (λ {(J₁ , J₂) → G →ᴳ J₁ ×ᴳ J₂})\n ↓ ap (λ J → G , J) (! K-iso-Imχ) ]\n r = ↓-ap-in _ (λ J → G , J)\n (apd (λ J → ×ᴳ-hom-in (idhom G)\n (cst-hom {G = G} {H = J})) (! K-iso-Imχ))\n\n ψ-over-G-K-isos : ψ-dinv == ×ᴳ-snd {G = G}\n [ (λ J → J →ᴳ K) ↓ ap2 _×ᴳ_ (! G-iso-Kerψ) (! K-iso-Imχ) ]\n ψ-over-G-K-isos = ↓-ap2-in _ _×ᴳ_ $ transport\n (λ q → ψ-dinv == (×ᴳ-snd {G = G})\n [ (λ {(J₁ , J₂) → J₁ ×ᴳ J₂ →ᴳ K}) ↓ q ])\n (! (pair×=-split-l (! G-iso-Kerψ) (! K-iso-Imχ)))\n (l ∙ᵈ (m ◃ r))\n where\n l : ψ-dinv == ψ ∘ᴳ ×ᴳ-sum-hom H-abelian φ (im-inj χ)\n [ (λ {(J₁ , J₂) → J₁ ×ᴳ J₂ →ᴳ K})\n ↓ ap (λ J → J , Im χ) (! G-iso-Kerψ) ]\n l = ↓-ap-in _ (λ J → J , Im χ)\n (ap↓ (λ θ → ψ ∘ᴳ ×ᴳ-sum-hom H-abelian θ (im-inj χ))\n (!ᵈ φ-over-G-iso))\n\n m : ψ ∘ᴳ ×ᴳ-sum-hom H-abelian φ (im-inj χ)\n == (ψ ∘ᴳ im-inj χ) ∘ᴳ ×ᴳ-snd {G = G}\n m = hom= _ _ $ λ= $ (λ {(g , (h , _)) →\n ψ.f (H.comp (φ.f g) h)\n =⟨ ψ.pres-comp (φ.f g) h ⟩\n K.comp (ψ.f (φ.f g)) (ψ.f h)\n =⟨ itok (exact-get ex 1) (φ.f g) [ g , idp ]\n |in-ctx (λ w → K.comp w (ψ.f h)) ⟩\n K.comp K.ident (ψ.f h)\n =⟨ K.unitl (ψ.f h) ⟩\n ψ.f h ∎})\n\n r : (ψ ∘ᴳ im-inj χ) ∘ᴳ ×ᴳ-snd {G = G} == ×ᴳ-snd {G = G}\n [ (λ {(J₁ , J₂) → J₁ ×ᴳ J₂ →ᴳ K})\n ↓ (ap (λ J → G , J) (! K-iso-Imχ)) ]\n r = ↓-ap-in _ (λ J → G , J)\n (ap↓ (λ θ → θ ∘ᴳ ×ᴳ-snd {G = G}) (!ᵈ ψ|imχ-over-K-iso))\n\n φ-over-iso : φ == ×ᴳ-inl [ (λ J → G →ᴳ J) ↓ iso ]\n φ-over-iso = φ-over-decomp ∙ᵈ φ-over-G-K-isos\n\n ψ-over-iso : ψ == (×ᴳ-snd {G = G}) [ (λ J → J →ᴳ K) ↓ iso ]\n ψ-over-iso = ψ-over-decomp ∙ᵈ ψ-over-G-K-isos\n", "meta": {"hexsha": "5cab59c7b4901639e3efbdb60269cd1cf22a8af3", "size": 10300, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/cohomology/SplitExactRight.agda", "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "theorems/cohomology/SplitExactRight.agda", "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "theorems/cohomology/SplitExactRight.agda", "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": 36.917562724, "max_line_length": 77, "alphanum_fraction": 0.4653398058, "num_tokens": 4530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.689305616785446, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.3795367497068784}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe --guardedness #-}\nmodule Cubical.Codata.Stream.Base where\n\nopen import Cubical.Core.Everything\n\nrecord Stream (A : Type₀) : Type₀ where\n coinductive\n constructor _,_\n field\n head : A\n tail : Stream A\n", "meta": {"hexsha": "ade3ad434d519e000814290ccd08b29df607e7b4", "size": 256, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Codata/Stream/Base.agda", "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": "Cubical/Codata/Stream/Base.agda", "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_forks_repo_path": "Cubical/Codata/Stream/Base.agda", "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "avg_line_length": 21.3333333333, "max_line_length": 64, "alphanum_fraction": 0.703125, "num_tokens": 71, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7090191460821871, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.37939503093476024}} {"text": "------------------------------------------------------------------------\n-- Some auxiliary operations and lemmas\n------------------------------------------------------------------------\n\nmodule BreadthFirst.Lemmas where\n\nopen import Codata.Musical.Notation\nopen import Codata.Musical.Colist as Colist\n using (Colist; []; _∷_; concat; _++_)\nopen import Function\nopen import Data.List using ([]; _∷_)\nopen import Data.List.NonEmpty as List⁺ using (List⁺; [_]; _∷_; _⁺++⁺_)\nimport Data.Vec as Vec\nopen import Data.Product using (_,_)\nopen import Relation.Binary.PropositionalEquality as PropEq\n using (_≡_) renaming (refl to ≡-refl)\n\nopen import BreadthFirst.Universe\nopen import BreadthFirst.Programs\nopen import Tree using (leaf; node; map)\nopen import Stream using (Stream; _≺_) renaming (_++_ to _++∞_)\n\n------------------------------------------------------------------------\n-- Some operations\n\nzipWith : {A B : Set} (f : A → B → B) → Colist A → Stream B → Stream B\nzipWith f [] ys = ys\nzipWith f (x ∷ xs) (y ≺ ys) = f x y ≺ ♯ zipWith f (♭ xs) (♭ ys)\n\ninfixr 5 _⁺++_ _⁺++∞_\n\n_⁺++∞_ : {A : Set} → List⁺ A → Stream A → Stream A\nxs ⁺++∞ ys = Colist.fromList (Vec.toList $ List⁺.toVec xs) ++∞ ys\n\n_⁺++_ : {A : Set} → List⁺ A → Colist A → Colist A\nxs ⁺++ ys = Colist.fromList (Vec.toList $ List⁺.toVec xs) ++ ys\n\n------------------------------------------------------------------------\n-- Eq is an equivalence relation\n\nrefl : ∀ {a} x → Eq a x x\nrefl {a = tree a} leaf = leaf\nrefl {a = tree a} (node l x r) = node (♯ refl (♭ l)) (refl x) (♯ refl (♭ r))\nrefl {a = stream a} (x ≺ xs) = refl x ≺ ♯ refl (♭ xs)\nrefl {a = colist a} [] = []\nrefl {a = colist a} (x ∷ xs) = refl x ∷ ♯ refl (♭ xs)\nrefl {a = a ⊗ b} (x , y) = (refl x , refl y)\nrefl {a = ⌈ A ⌉} x = ⌈ PropEq.refl ⌉\n\nsym : ∀ {a x y} → Eq a x y → Eq a y x\nsym {a = tree a} leaf = leaf\nsym {a = tree a} (node l≈l′ x≈x′ r≈r′) = node (♯ sym (♭ l≈l′)) (sym x≈x′) (♯ sym (♭ r≈r′))\nsym {a = stream a} (x≈x′ ≺ xs≈xs′) = sym x≈x′ ≺ ♯ sym (♭ xs≈xs′)\nsym {a = colist a} [] = []\nsym {a = colist a} (x≈x′ ∷ xs≈xs′) = sym x≈x′ ∷ ♯ sym (♭ xs≈xs′)\nsym {a = a ⊗ b} (x≈x′ , y≈y′) = (sym x≈x′ , sym y≈y′)\nsym {a = ⌈ A ⌉} ⌈ x≡x′ ⌉ = ⌈ PropEq.sym x≡x′ ⌉\n\ntrans : ∀ {a x y z} → Eq a x y → Eq a y z → Eq a x z\ntrans {a = tree a} leaf leaf = leaf\ntrans {a = tree a} (node l≈l′ x≈x′ r≈r′)\n (node l′≈l″ x′≈x″ r′≈r″) = node (♯ trans (♭ l≈l′) (♭ l′≈l″))\n (trans x≈x′ x′≈x″)\n (♯ trans (♭ r≈r′) (♭ r′≈r″))\ntrans {a = stream a} (x≈x′ ≺ xs≈xs′)\n (x′≈x″ ≺ xs′≈xs″) = trans x≈x′ x′≈x″ ≺ ♯ trans (♭ xs≈xs′) (♭ xs′≈xs″)\ntrans {a = colist a} [] [] = []\ntrans {a = colist a} (x≈x′ ∷ xs≈xs′)\n (x′≈x″ ∷ xs′≈xs″) = trans x≈x′ x′≈x″ ∷ ♯ trans (♭ xs≈xs′) (♭ xs′≈xs″)\ntrans {a = a ⊗ b} (x≈x′ , y≈y′)\n (x′≈x″ , y′≈y″) = (trans x≈x′ x′≈x″ , trans y≈y′ y′≈y″)\ntrans {a = ⌈ A ⌉} ⌈ x≡x′ ⌉ ⌈ x′≡x″ ⌉ = ⌈ PropEq.trans x≡x′ x′≡x″ ⌉\n\n------------------------------------------------------------------------\n-- Productivity checker workaround for Eq\n\ninfixr 5 _≺_ _∷_\ninfixr 4 _,_\ninfix 3 _∎\ninfixr 2 _≈⟨_⟩_ _≊⟨_⟩_\n\ndata EqP : ∀ a → El a → El a → Set₁ where\n leaf : ∀ {a} → EqP (tree a) leaf leaf\n node : ∀ {a x x′ l l′ r r′}\n (l≈l′ : ∞ (EqP (tree a) (♭ l) (♭ l′)))\n (x≈x′ : Eq a x x′ )\n (r≈r′ : ∞ (EqP (tree a) (♭ r) (♭ r′))) →\n EqP (tree a) (node l x r) (node l′ x′ r′)\n _≺_ : ∀ {a x x′ xs xs′}\n (x≈x′ : Eq a x x′ )\n (xs≈xs′ : ∞ (EqP (stream a) (♭ xs) (♭ xs′))) →\n EqP (stream a) (x ≺ xs) (x′ ≺ xs′)\n [] : ∀ {a} → EqP (colist a) [] []\n _∷_ : ∀ {a x x′ xs xs′}\n (x≈x′ : Eq a x x′ )\n (xs≈xs′ : ∞ (EqP (colist a) (♭ xs) (♭ xs′))) →\n EqP (colist a) (x ∷ xs) (x′ ∷ xs′)\n _,_ : ∀ {a b x x′ y y′}\n (x≈x′ : Eq a x x′) (y≈y′ : Eq b y y′) →\n EqP (a ⊗ b) (x , y) (x′ , y′)\n ⌈_⌉ : ∀ {A x x′} (x≡x′ : x ≡ x′) → EqP ⌈ A ⌉ x x′\n\n _≊⟨_⟩_ : ∀ {a} x {y z}\n (x≈y : EqP a x y) (y≈z : EqP a y z) → EqP a x z\n\n zipWith-cong :\n ∀ {a b} {f : El a → El b → El b}\n (cong : ∀ {x x′ y y′} →\n Eq a x x′ → Eq b y y′ → Eq b (f x y) (f x′ y′))\n {xs xs′ ys ys′}\n (xs≈xs′ : EqP (colist a) xs xs′)\n (ys≈ys′ : EqP (stream b) ys ys′) →\n EqP (stream b) (zipWith f xs ys) (zipWith f xs′ ys′)\n\ndata EqW : ∀ a → El a → El a → Set₁ where\n leaf : ∀ {a} → EqW (tree a) leaf leaf\n node : ∀ {a x x′ l l′ r r′}\n (l≈l′ : EqP (tree a) (♭ l) (♭ l′))\n (x≈x′ : Eq a x x′ )\n (r≈r′ : EqP (tree a) (♭ r) (♭ r′)) →\n EqW (tree a) (node l x r) (node l′ x′ r′)\n _≺_ : ∀ {a x x′ xs xs′}\n (x≈x′ : Eq a x x′ )\n (xs≈xs′ : EqP (stream a) (♭ xs) (♭ xs′)) →\n EqW (stream a) (x ≺ xs) (x′ ≺ xs′)\n [] : ∀ {a} → EqW (colist a) [] []\n _∷_ : ∀ {a x x′ xs xs′}\n (x≈x′ : Eq a x x′ )\n (xs≈xs′ : EqP (colist a) (♭ xs) (♭ xs′)) →\n EqW (colist a) (x ∷ xs) (x′ ∷ xs′)\n _,_ : ∀ {a b x x′ y y′}\n (x≈x′ : Eq a x x′) (y≈y′ : Eq b y y′) →\n EqW (a ⊗ b) (x , y) (x′ , y′)\n ⌈_⌉ : ∀ {A x x′} (x≡x′ : x ≡ x′) → EqW ⌈ A ⌉ x x′\n\n⟦_⟧≈⁻¹ : ∀ {a} {x y : El a} → Eq a x y → EqP a x y\n⟦ leaf ⟧≈⁻¹ = leaf\n⟦ node l≈l′ x≈x′ r≈r′ ⟧≈⁻¹ = node (♯ ⟦ ♭ l≈l′ ⟧≈⁻¹) x≈x′ (♯ ⟦ ♭ r≈r′ ⟧≈⁻¹)\n⟦ x≈x′ ≺ xs≈xs′ ⟧≈⁻¹ = x≈x′ ≺ ♯ ⟦ ♭ xs≈xs′ ⟧≈⁻¹\n⟦ [] ⟧≈⁻¹ = []\n⟦ x≈x′ ∷ xs≈xs′ ⟧≈⁻¹ = x≈x′ ∷ ♯ ⟦ ♭ xs≈xs′ ⟧≈⁻¹\n⟦ (x≈x′ , y≈y′) ⟧≈⁻¹ = (x≈x′ , y≈y′)\n⟦ ⌈ x≡x′ ⌉ ⟧≈⁻¹ = ⌈ x≡x′ ⌉\n\nwhnf≈ : ∀ {a xs ys} → EqP a xs ys → EqW a xs ys\nwhnf≈ leaf = leaf\nwhnf≈ (node l≈l′ x≈x′ r≈r′) = node (♭ l≈l′) x≈x′ (♭ r≈r′)\nwhnf≈ (x≈x′ ≺ xs≈xs′) = x≈x′ ≺ ♭ xs≈xs′\nwhnf≈ [] = []\nwhnf≈ (x≈x′ ∷ xs≈xs′) = x≈x′ ∷ ♭ xs≈xs′\nwhnf≈ (x≈x′ , y≈y′) = (x≈x′ , y≈y′)\nwhnf≈ ⌈ x≡x′ ⌉ = ⌈ x≡x′ ⌉\n\nwhnf≈ ( _ ≊⟨ x≈y ⟩ y≈z) with whnf≈ x≈y | whnf≈ y≈z\nwhnf≈ (._ ≊⟨ x≈y ⟩ y≈z) | leaf | leaf = leaf\nwhnf≈ (._ ≊⟨ x≈y ⟩ y≈z) | node l≈l′ x≈x′ r≈r′\n | node l′≈l″ x′≈x″ r′≈r″ = node (_ ≊⟨ l≈l′ ⟩ l′≈l″) (trans x≈x′ x′≈x″) (_ ≊⟨ r≈r′ ⟩ r′≈r″)\nwhnf≈ (._ ≊⟨ x≈y ⟩ y≈z) | [] | [] = []\nwhnf≈ (._ ≊⟨ x≈y ⟩ y≈z) | x≈y′ ∷ xs≈ys′ | y≈z′ ∷ ys≈zs′ = trans x≈y′ y≈z′ ∷ (_ ≊⟨ xs≈ys′ ⟩ ys≈zs′)\nwhnf≈ (._ ≊⟨ x≈y ⟩ y≈z) | x≈y′ ≺ xs≈ys′ | y≈z′ ≺ ys≈zs′ = trans x≈y′ y≈z′ ≺ (_ ≊⟨ xs≈ys′ ⟩ ys≈zs′)\nwhnf≈ (._ ≊⟨ x≈y ⟩ y≈z) | (x≈x′ , y≈y′) | (x′≈x″ , y′≈y″) = (trans x≈x′ x′≈x″ , trans y≈y′ y′≈y″)\nwhnf≈ ( _ ≊⟨ x≈y ⟩ y≈z) | ⌈ x≡x′ ⌉ | ⌈ x′≡x″ ⌉ = ⌈ PropEq.trans x≡x′ x′≡x″ ⌉\n\nwhnf≈ (zipWith-cong cong xs≈xs′ ys≈ys′) with whnf≈ xs≈xs′ | whnf≈ ys≈ys′\n... | [] | ys≈ys″ = ys≈ys″\n... | x≈x′ ∷ xs≈xs″ | y≈y′ ≺ ys≈ys″ =\n cong x≈x′ y≈y′ ≺ zipWith-cong cong xs≈xs″ ys≈ys″\n\nmutual\n\n value≈ : ∀ {a xs ys} → EqW a xs ys → Eq a xs ys\n value≈ leaf = leaf\n value≈ (node l≈l′ x≈x′ r≈r′) = node (♯ ⟦ l≈l′ ⟧≈) x≈x′ (♯ ⟦ r≈r′ ⟧≈)\n value≈ (x≈x′ ≺ xs≈xs′) = x≈x′ ≺ ♯ ⟦ xs≈xs′ ⟧≈\n value≈ [] = []\n value≈ (x≈x′ ∷ xs≈xs′) = x≈x′ ∷ ♯ ⟦ xs≈xs′ ⟧≈\n value≈ (x≈x′ , y≈y′) = (x≈x′ , y≈y′)\n value≈ ⌈ x≡x′ ⌉ = ⌈ x≡x′ ⌉\n\n ⟦_⟧≈ : ∀ {a xs ys} → EqP a xs ys → Eq a xs ys\n ⟦ xs≈ys ⟧≈ = value≈ (whnf≈ xs≈ys)\n\n_≈⟨_⟩_ : ∀ {a} x {y z}\n (x≈y : Eq a x y) (y≈z : EqP a y z) → EqP a x z\nx ≈⟨ x≈y ⟩ y≈z = x ≊⟨ ⟦ x≈y ⟧≈⁻¹ ⟩ y≈z\n\n_∎ : ∀ {a} x → EqP a x x\nx ∎ = ⟦ refl x ⟧≈⁻¹\n\n------------------------------------------------------------------------\n-- Productivity checker workaround for PrefixOf\n\ninfixr 2 _≋⟨_⟩_ _⊑⟨_⟩_\n\ndata PrefixOfP (a : U) :\n Colist (El a) → Stream (El a) → Set₁ where\n [] : ∀ {ys} → PrefixOfP a [] ys\n ⁺++-mono : ∀ xs {ys ys′} (ys⊑ys′ : ∞ (PrefixOfP a ys ys′)) →\n PrefixOfP a (xs ⁺++ ys) (xs ⁺++∞ ys′)\n _≋⟨_⟩_ : ∀ xs {ys zs} (xs≈ys : Eq (colist a) xs ys)\n (ys⊑zs : PrefixOfP a ys zs) → PrefixOfP a xs zs\n _⊑⟨_⟩_ : ∀ xs {ys zs} (xs⊑ys : PrefixOfP a xs ys)\n (ys≈zs : EqP (stream a) ys zs) → PrefixOfP a xs zs\n\ndata PrefixOfW (a : U) :\n Colist (El a) → Stream (El a) → Set₁ where\n [] : ∀ {ys} → PrefixOfW a [] ys\n _∷_ : ∀ {x y xs ys}\n (x≈y : Eq a x y) (p : PrefixOfP a (♭ xs) (♭ ys)) →\n PrefixOfW a (x ∷ xs) (y ≺ ys)\n\nwhnf⊑ : ∀ {a xs ys} →\n PrefixOfP a xs ys → PrefixOfW a xs ys\nwhnf⊑ [] = []\n\nwhnf⊑ (⁺++-mono (x ∷ []) ys⊑ys′) = refl x ∷ ♭ ys⊑ys′\nwhnf⊑ (⁺++-mono (x ∷ (x′ ∷ xs)) ys⊑ys′) =\n refl x ∷ ⁺++-mono (x′ ∷ xs) ys⊑ys′\n\nwhnf⊑ (._ ≋⟨ [] ⟩ _ ) = []\nwhnf⊑ (._ ≋⟨ x≈y ∷ xs≈ys ⟩ ys⊑zs) with whnf⊑ ys⊑zs\n... | y≈z ∷ ys⊑zs′ = trans x≈y y≈z ∷ (_ ≋⟨ ♭ xs≈ys ⟩ ys⊑zs′)\n\nwhnf⊑ (._ ⊑⟨ xs⊑ys ⟩ ys≈zs) with whnf⊑ xs⊑ys | whnf≈ ys≈zs\n... | [] | _ = []\n... | x≈y ∷ xs⊑ys′ | y≈z ≺ ys≈zs′ = trans x≈y y≈z ∷ (_ ⊑⟨ xs⊑ys′ ⟩ ys≈zs′)\n\nmutual\n\n value⊑ : ∀ {a xs ys} → PrefixOfW a xs ys → PrefixOf a xs ys\n value⊑ [] = []\n value⊑ (x≈y ∷ xs⊑ys) = x≈y ∷ ♯ ⟦ xs⊑ys ⟧⊑\n\n ⟦_⟧⊑ : ∀ {a xs ys} → PrefixOfP a xs ys → PrefixOf a xs ys\n ⟦ xs⊑ys ⟧⊑ = value⊑ (whnf⊑ xs⊑ys)\n\n------------------------------------------------------------------------\n-- More lemmas\n\n⁺++∞-cong : ∀ {a xs xs′ ys ys′} →\n Eq ⌈ List⁺ (El a) ⌉ xs xs′ →\n Eq (stream a) ys ys′ →\n Eq (stream a) (xs ⁺++∞ ys) (xs′ ⁺++∞ ys′)\n⁺++∞-cong {xs = x ∷ []} ⌈ ≡-refl ⌉ ys≈ys′ = refl x ≺ ♯ ys≈ys′\n⁺++∞-cong {xs = x ∷ (x′ ∷ xs)} ⌈ ≡-refl ⌉ ys≈ys′ =\n refl x ≺ ♯ ⁺++∞-cong {xs = x′ ∷ xs} ⌈ ≡-refl ⌉ ys≈ys′\n\n++-assoc : ∀ {a} xs ys zs →\n Eq (stream a) (xs ⁺++∞ (ys ⁺++∞ zs)) ((xs ⁺++⁺ ys) ⁺++∞ zs)\n++-assoc (x ∷ []) ys zs = refl x ≺ ♯ refl (ys ⁺++∞ zs)\n++-assoc (x ∷ (x′ ∷ xs)) ys zs = refl x ≺ ♯ ++-assoc (x′ ∷ xs) ys zs\n\nzip-++-assoc : ∀ {a} xss yss (zss : Stream (Stream (El a))) →\n Eq (stream (stream a))\n (zipWith _⁺++∞_ ⟦ xss ⟧ (zipWith _⁺++∞_ ⟦ yss ⟧ zss))\n (zipWith _⁺++∞_ ⟦ longZipWith _⁺++⁺_ xss yss ⟧ zss)\nzip-++-assoc xss yss (zs ≺ zss) with whnf xss | whnf yss\n... | [] | [] = refl _\n... | [] | ys ∷ yss′ = refl _\n... | xs ∷ xss′ | [] = refl _\n... | ⌈ xs ⌉ ∷ xss′ | ⌈ ys ⌉ ∷ yss′ =\n ++-assoc xs ys zs ≺ ♯ zip-++-assoc (♭ xss′) (♭ yss′) (♭ zss)\n\nconcat-lemma : ∀ {a} xs xss →\n Eq (colist a) (concat (xs ∷ xss))\n (xs ⁺++ concat (♭ xss))\nconcat-lemma (x ∷ []) xss = refl x ∷ ♯ refl (concat (♭ xss))\nconcat-lemma (x ∷ (x′ ∷ xs)) xss = refl x ∷ ♯ concat-lemma (x′ ∷ xs) xss\n", "meta": {"hexsha": "05069d7b14a6490b11d7cb6dc73c7af1cc113bf5", "size": 10958, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BreadthFirst/Lemmas.agda", "max_stars_repo_name": "nad/codata", "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_issues_repo_path": "BreadthFirst/Lemmas.agda", "max_issues_repo_name": "nad/codata", "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": "BreadthFirst/Lemmas.agda", "max_forks_repo_name": "nad/codata", "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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.7360594796, "max_line_length": 114, "alphanum_fraction": 0.3796313196, "num_tokens": 5549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.37937716297757224}} {"text": "{-# OPTIONS --cubical --safe #-}\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Path\nopen import Cubical.Foundations.Isomorphism renaming (Iso to _≅_)\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Functions.FunExtEquiv\nopen import Cubical.Data.Unit\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Nat\n\nmodule Cubical.Data.W.Indexed where\n\nopen _≅_\n\nprivate\n variable\n ℓX ℓS ℓP : Level\n\nmodule Types {X : Type ℓX} (S : X → Type ℓS) (P : ∀ x → S x → Type ℓP) (inX : ∀ x (s : S x) → P x s → X) where\n data IW (x : X) : Type (ℓ-max ℓX (ℓ-max ℓS ℓP)) where\n node : (s : S x) → (subtree : (p : P x s) → IW (inX x s p)) → IW x\n\n Subtree : ∀ {x} → (s : S x) → Type (ℓ-max (ℓ-max ℓX ℓS) ℓP)\n Subtree {x} s = (p : P x s) → IW (inX x s p)\n\n RepIW : (x : X) → Type (ℓ-max (ℓ-max ℓX ℓS) ℓP)\n RepIW x = Σ[ s ∈ S x ] Subtree s\n\nopen Types public\n\nmodule _ {X : Type ℓX} {S : X → Type ℓS} {P : ∀ x → S x → Type ℓP} {inX : ∀ x (s : S x) → P x s → X} where\n\n getShape : ∀ {x} → IW S P inX x → S x\n getShape (node s subtree) = s\n\n getSubtree : ∀ {x} → (w : IW S P inX x) → (p : P x (getShape w)) → IW S P inX (inX x (getShape w) p)\n getSubtree (node s subtree) = subtree\n\n wExt : ∀ {x} (w w' : IW S P inX x)\n → (ps : getShape w ≡ getShape w')\n → (pw : PathP (λ i → Subtree S P inX (ps i)) (getSubtree w) (getSubtree w'))\n → w ≡ w'\n wExt (node s subtree) (node s' subtree') ps psubtree = cong₂ node ps psubtree\n\n isoRepIW : (x : X) → IW S P inX x ≅ RepIW S P inX x\n fun (isoRepIW x) (node s subtree) = s , subtree\n inv (isoRepIW x) (s , subtree) = node s subtree\n rightInv (isoRepIW x) (s , subtree) = refl\n leftInv (isoRepIW x) (node s subtree) = refl\n\n equivRepIW : (x : X) → IW S P inX x ≃ RepIW S P inX x\n equivRepIW x = isoToEquiv (isoRepIW x)\n\n pathRepIW : (x : X) → IW S P inX x ≡ RepIW S P inX x\n pathRepIW x = ua (equivRepIW x)\n\n isPropIW : (∀ x → isProp (S x)) → ∀ x → isProp (IW S P inX x)\n isPropIW isPropS x (node s subtree) (node s' subtree') =\n cong₂ node (isPropS x s s') (toPathP (funExt λ p → isPropIW isPropS _ _ (subtree' p)))\n\nmodule IWPathTypes {X : Type ℓX} (S : X → Type ℓS) (P : ∀ x → S x → Type ℓP) (inX : ∀ x (s : S x) → P x s → X) where\n\n --somewhat inspired by https://github.com/jashug/IWTypes , but different.\n\n IndexCover : Type (ℓ-max (ℓ-max ℓX ℓS) ℓP)\n IndexCover = Σ[ x ∈ X ] IW S P inX x × IW S P inX x\n\n ShapeCover : IndexCover → Type ℓS\n ShapeCover (x , w , w') = getShape w ≡ getShape w'\n\n ArityCover : ∀ xww' → ShapeCover xww' → Type ℓP\n ArityCover (x , w , w') ps = P x (getShape w')\n\n inXCover : ∀ xww' → (ps : ShapeCover xww') → ArityCover xww' ps → IndexCover\n inXCover (x , w , w') ps p = (inX x (getShape w') p) , (subst (Subtree S P inX) ps (getSubtree w) p , getSubtree w' p)\n\n Cover : ∀ {x : X} → (w w' : IW S P inX x) → Type (ℓ-max (ℓ-max ℓX ℓS) ℓP)\n Cover {x} w w' = IW ShapeCover ArityCover inXCover (x , w , w')\n\nmodule IWPath {X : Type ℓX} {S : X → Type ℓS} {P : ∀ x → S x → Type ℓP} {inX : ∀ x (s : S x) → P x s → X} where\n open IWPathTypes S P inX\n\n isoEncode : ∀ {x} (w w' : IW S P inX x) → (w ≡ w') ≅ Cover w w'\n isoEncodeSubtree : ∀ {x} (w w' : IW S P inX x) (ps : ShapeCover (x , w , w'))\n → (PathP (λ i → Subtree S P inX (ps i)) (getSubtree w) (getSubtree w'))\n ≅\n (∀ (p : P x (getShape w')) → IW ShapeCover ArityCover inXCover (inXCover (x , w , w') ps p))\n\n isoEncodeSubtree w w'@(node s' subtree') ps =\n PathPIsoPath (λ i → Subtree S P inX (ps i)) (getSubtree w) (getSubtree w') ⟫\n invIso (funExtIso) ⟫\n codomainIsoDep (λ p → isoEncode _ (subtree' p))\n where _⟫_ = compIso\n infixr 10 _⟫_\n fun (isoEncode w@(node s subtree) w'@(node s' subtree')) pw =\n node (cong getShape pw) (fun (isoEncodeSubtree w w' (cong getShape pw)) (cong getSubtree pw))\n inv (isoEncode w@(node s subtree) w'@(node s' subtree')) cw@(node ps csubtree) =\n cong₂ node ps (inv (isoEncodeSubtree w w' ps) csubtree)\n rightInv (isoEncode w@(node s subtree) w'@(node s' subtree')) cw@(node ps csubtree) =\n cong (node ps) (\n fun (isoEncodeSubtree w w' ps) (inv (isoEncodeSubtree w w' ps) csubtree)\n ≡⟨ rightInv (isoEncodeSubtree w w' ps) csubtree ⟩\n csubtree ∎\n )\n leftInv (isoEncode w@(node s subtree) w'@(node s' subtree')) pw =\n cong₂ node (cong getShape pw)\n (inv (isoEncodeSubtree w w' (cong getShape pw))\n (fun (isoEncodeSubtree w w' (cong getShape pw))\n (cong getSubtree pw)\n )\n )\n ≡⟨ cong (cong₂ node (cong getShape pw)) (leftInv (isoEncodeSubtree w w' (cong getShape pw)) (cong getSubtree pw)) ⟩\n cong₂ node (cong getShape pw) (cong getSubtree pw)\n ≡⟨ flipSquare (λ i → wExt (node (getShape (pw i)) (getSubtree (pw i))) (pw i) refl refl) ⟩\n pw ∎\n\n encode : ∀ {x} (w w' : IW S P inX x) → w ≡ w' → Cover w w'\n encode w w' = fun (isoEncode w w')\n\n decode : ∀ {x} (w w' : IW S P inX x) → Cover w w' → w ≡ w'\n decode w w' = inv (isoEncode w w')\n\n decodeEncode : ∀ {x} (w w' : IW S P inX x) → (pw : w ≡ w') → decode w w' (encode w w' pw) ≡ pw\n decodeEncode w w' = leftInv (isoEncode w w')\n\n encodeDecode : ∀ {x} (w w' : IW S P inX x) → (cw : Cover w w') → encode w w' (decode w w' cw) ≡ cw\n encodeDecode w w' = rightInv (isoEncode w w')\n\n equivEncode : ∀ {x} (w w' : IW S P inX x) → (w ≡ w') ≃ Cover w w'\n equivEncode w w' = isoToEquiv (isoEncode w w')\n\n pathEncode : ∀ {x} (w w' : IW S P inX x) → (w ≡ w') ≡ Cover w w'\n pathEncode w w' = ua (equivEncode w w')\n\nopen IWPathTypes\nopen IWPath\n\nisOfHLevelSuc-IW : {X : Type ℓX} {S : X → Type ℓS} {P : ∀ x → S x → Type ℓP} {inX : ∀ x (s : S x) → P x s → X} →\n (n : HLevel) → (∀ x → isOfHLevel (suc n) (S x)) → ∀ x → isOfHLevel (suc n) (IW S P inX x)\nisOfHLevelSuc-IW zero isHS x = isPropIW isHS x\nisOfHLevelSuc-IW (suc n) isHS x w w' =\n subst (isOfHLevel (suc n)) (λ i → pathEncode w w' (~ i))\n (isOfHLevelSuc-IW n\n (λ (y , v , v') → isHS y (getShape v) (getShape v'))\n (x , w , w')\n )\n", "meta": {"hexsha": "71a56811ff78d2e7d2e98034906a3b345e157f65", "size": 6122, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Data/W/Indexed.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_issues_repo_path": "Cubical/Data/W/Indexed.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Data/W/Indexed.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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.5430463576, "max_line_length": 121, "alphanum_fraction": 0.5913100294, "num_tokens": 2463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442251064863695, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.3793771629775722}} {"text": "{-# OPTIONS --without-K --safe #-}\n\n-- Properties of F<:⁻\n--\n-- This file shows several structural properties of F<:⁻, including weakening,\n-- narrowing and transitivity. They are not used anywhere, but just serve as a\n-- reference to compare the complexity with the corresponding proofs of D<:.\nmodule FsubMinus2 where\n\nopen import Data.List as List\nopen import Data.Nat\nopen import Data.Maybe as Maybe\nopen import Data.Product\nopen import Data.Sum\nopen import Function\nopen import Data.Empty renaming (⊥ to False)\n\nopen import Relation.Nullary\nopen import Relation.Binary.PropositionalEquality as ≡\n\nopen import Data.Nat.Properties as ℕₚ\nopen import Data.Maybe.Properties as Maybeₚ\nopen import Utils\nopen import FsubMinus\nopen import Data.List.Properties as Listₚ\n\nopen import Induction.Nat\n\nopen FsubMinus.FsubMinus\n\ninfixl 7 _⇑\n\nΓ-⇑ : Env → Ftyp → Ftyp\nΓ-⇑ Γ = _↑ length Γ\n\n_⇑ : Env → Env\n[] ⇑ = []\n(T ∷ Γ) ⇑ = Γ-⇑ Γ T ∷ Γ ⇑\n\n↑-↑-comm : ∀ T m n → m ≤ n → T ↑ m ↑ suc n ≡ T ↑ n ↑ m\n↑-↑-comm ⊤ m n m≤n = refl\n↑-↑-comm (var x) m n m≤n with n ≤? x\n... | yes n≤x\n rewrite ≤?-yes $ ≤-step $ ≤-trans m≤n n≤x\n | ≤?-yes $ ≤-trans m≤n n≤x\n | ≤?-yes n≤x = refl\n... | no x : ∀ {x T Γ} →\n x <: T ∈ Γ →\n ∀ Γ₁ Γ₂ T′ →\n Γ ≡ Γ₁ ‣ Γ₂ →\n length Γ₂ > x →\n x <: Γ-⇑ Γ₂ T ∈ Γ₁ ‣ T′ ! ‣ Γ₂ ⇑\n<:∈-weakening-> hd Γ₁ [] T′ eq ()\n<:∈-weakening-> hd Γ₁ (T ∷ Γ₂) T′ refl l>x\n rewrite ↑-↑-comm T 0 (length Γ₂) z≤n = hd\n<:∈-weakening-> (tl <:∈) Γ₁ [] T′ eq ()\n<:∈-weakening-> (tl {T = T} <:∈) Γ₁ (_ ∷ Γ₂) T′ refl (s≤s l>x)\n rewrite ↑-↑-comm T 0 (length Γ₂) z≤n = tl $ <:∈-weakening-> <:∈ Γ₁ Γ₂ T′ refl l>x\n\n<:∈-weakening : ∀ {x T Γ} →\n x <: T ∈ Γ →\n ∀ Γ₁ Γ₂ T′ →\n Γ ≡ Γ₁ ‣ Γ₂ →\n ↑-idx x (length Γ₂) <: Γ-⇑ Γ₂ T ∈ Γ₁ ‣ T′ ! ‣ Γ₂ ⇑\n<:∈-weakening {x} <:∈ Γ₁ Γ₂ T′ eq with length Γ₂ ≤? x\n... | yes p = <:∈-weakening-≤ <:∈ Γ₁ Γ₂ T′ eq p\n... | no ¬p = <:∈-weakening-> <:∈ Γ₁ Γ₂ T′ eq (≰⇒> ¬p)\n\n<:-weakening-gen : ∀ {Γ S U} →\n Γ ⊢F S <: U →\n ∀ Γ₁ Γ₂ T →\n Γ ≡ Γ₁ ‣ Γ₂ →\n Γ₁ ‣ T ! ‣ Γ₂ ⇑ ⊢F Γ-⇑ Γ₂ S <: Γ-⇑ Γ₂ U\n<:-weakening-gen ftop Γ₁ Γ₂ T eq = ftop\n<:-weakening-gen (fvrefl {_} {x}) Γ₁ Γ₂ T eq\n rewrite ↑-var x (length Γ₂) = fvrefl\n<:-weakening-gen (fbinds {_} {x} T∈Γ D) Γ₁ Γ₂ T eq\n rewrite ↑-var x (length Γ₂) = fbinds (<:∈-weakening T∈Γ Γ₁ Γ₂ T eq)\n (<:-weakening-gen D Γ₁ Γ₂ T eq)\n<:-weakening-gen (fall {S₂ = S₂} Dp Db) Γ₁ Γ₂ T eq\n = fall (<:-weakening-gen Dp Γ₁ Γ₂ T eq)\n (<:-weakening-gen Db Γ₁ (Γ₂ ‣ S₂ !) T (cong (S₂ ∷_) eq))\n\n<:-weakening : ∀ {S U} Γ₁ Γ₂ T →\n Γ₁ ‣ Γ₂ ⊢F S <: U →\n Γ₁ ‣ T ! ‣ Γ₂ ⇑ ⊢F Γ-⇑ Γ₂ S <: Γ-⇑ Γ₂ U\n<:-weakening _ _ T D = <:-weakening-gen D _ _ T refl\n\n<:-weakening-hd : ∀ {Γ S U} T →\n Γ ⊢F S <: U →\n Γ ‣ T ! ⊢F S ↑ 0 <: U ↑ 0\n<:-weakening-hd T D = <:-weakening _ [] T D\n\n<:-weakening′ : ∀ {Γ S U} Γ′ →\n Γ ⊢F S <: U →\n Γ ‣ Γ′ ⊢F repeat (length Γ′) (_↑ 0) S <: repeat (length Γ′) (_↑ 0) U\n<:-weakening′ [] D = D\n<:-weakening′ (T ∷ Γ′) D = <:-weakening-hd T $ <:-weakening′ Γ′ D\n\n<:-refl : ∀ Γ T → Γ ⊢F T <: T\n<:-refl Γ ⊤ = ftop\n<:-refl Γ (var x) = fvrefl\n<:-refl Γ (Π<: S ∙ U) = fall (<:-refl Γ S) (<:-refl (S ∷ Γ) U)\n\nmodule TransProof where\n open ≤-Reasoning\n\n <:∈-find : ∀ {x T Γ} →\n x <: T ∈ Γ →\n ∀ T₁ T₂ Γ₁ Γ₂ →\n Γ ≡ Γ₁ ‣ T₁ ! ‣ Γ₂ →\n x ≢ length Γ₂ × x <: T ∈ Γ₁ ‣ T₂ ! ‣ Γ₂ ⊎\n x ≡ length Γ₂ × T ≡ repeat (suc (length Γ₂)) (_↑ 0) T₁ ×\n x <: repeat (suc (length Γ₂)) (_↑ 0) T₂ ∈ Γ₁ ‣ T₂ ! ‣ Γ₂\n <:∈-find hd T₁ T₂ Γ₁ [] refl = inj₂ (refl , refl , hd)\n <:∈-find hd T₁ T₂ Γ₁ (_ ∷ Γ₂) refl = inj₁ ((λ ()) , hd)\n <:∈-find (tl <:∈) T₁ T₂ Γ₁ [] refl = inj₁ ((λ ()) , tl <:∈)\n <:∈-find (tl <:∈) T₁ T₂ Γ₁ (_ ∷ Γ₂) refl with <:∈-find <:∈ T₁ T₂ Γ₁ Γ₂ refl\n ... | inj₁ (n≢l , r) = inj₁ ((λ n≡l → n≢l (suc-injective n≡l)) , tl r)\n ... | inj₂ (n≡l , e , r) = inj₂ (cong suc n≡l , cong (_↑ 0) e , tl r)\n\n infix 4 _≺:[_]_\n data _≺:[_]_ : Env → ℕ → Env → Set where\n ≺[_,_] : ∀ {Γ U} S → Γ ⊢F S <: U → Γ ‣ S ! ≺:[ 0 ] Γ ‣ U !\n _∷_ : ∀ {Γ₁ n Γ₂} T → Γ₁ ≺:[ n ] Γ₂ → Γ₁ ‣ T ! ≺:[ suc n ] Γ₂ ‣ T !\n\n <:∈-find′ : ∀ {x T Γ Γ′ n} →\n x <: T ∈ Γ →\n Γ′ ≺:[ n ] Γ →\n x ≡ n × (∃ λ T′ → n <: T′ ∈ Γ′ × Γ′ ⊢F T′ <: T) ⊎ x ≢ n × x <: T ∈ Γ′\n <:∈-find′ hd ≺[ T′ , T′<:T ] = inj₁ (refl , T′ ↑ 0 , hd , <:-weakening-hd T′ T′<:T)\n <:∈-find′ hd (T ∷ Γ′≺:Γ) = inj₂ ((λ ()) , hd)\n <:∈-find′ (tl T∈Γ) ≺[ T′ , T′<:T ] = inj₂ ((λ ()) , tl T∈Γ)\n <:∈-find′ (tl T∈Γ) (S ∷ Γ′≺:Γ) with <:∈-find′ T∈Γ Γ′≺:Γ\n ... | inj₁ (x≡n , T′ , T′∈Γ′ , T′<:T) = inj₁ (cong suc x≡n , T′ ↑ 0 , tl T′∈Γ′ , <:-weakening-hd S T′<:T)\n ... | inj₂ (x≢n , T∈Γ′) = inj₂ (x≢n ∘ suc-injective , tl T∈Γ′)\n\n trans-on : Ftyp → Set\n trans-on T = ∀ {Γ S U} → Γ ⊢F S <: T → Γ ⊢F T <: U → Γ ⊢F S <: U\n\n narrow-on : Ftyp → Set\n narrow-on T = ∀ {Γ Γ′ n S U} →\n Γ ⊢F S <: U →\n Γ′ ≺:[ n ] Γ →\n n <: T ∈ Γ →\n Γ′ ⊢F S <: U\n\n <:-trans-rec : ∀ T → (∀ T′ → Ftyp-measure T′ < Ftyp-measure T → trans-on T′ × narrow-on T′) → trans-on T\n <:-trans-rec ⊤ rec S<:T ftop = S<:T\n <:-trans-rec (var x) rec S<:T ftop = ftop\n <:-trans-rec (var x) rec S<:T fvrefl = S<:T\n <:-trans-rec (var x) rec fvrefl (fbinds T∈Γ T<:U) = fbinds T∈Γ T<:U\n <:-trans-rec (var x) rec (fbinds S∈Γ S<:T) (fbinds T∈Γ T<:U) = fbinds S∈Γ (<:-trans-rec (var x) rec S<:T (fbinds T∈Γ T<:U))\n <:-trans-rec (Π<: S ∙ U) rec S<:T ftop = ftop\n <:-trans-rec (Π<: S ∙ U) rec (fbinds S∈Γ S<:T) (fall Db Dp) = fbinds S∈Γ (<:-trans-rec (Π<: S ∙ U) rec S<:T (fall Db Dp))\n <:-trans-rec (Π<: S ∙ U) rec (fall Dp₁ Db₁) (fall Dp₂ Db₂) = fall (<:-trans-rec S (λ T′ T′<:S → rec T′ (≤-stepsʳ _ T′<:S)) Dp₂ Dp₁)\n (<:-trans-rec U\n (λ T′ T′ 10) $ showString tag ∘ showString \" \" ∘ showsPrec 11 x\n\ninstance\n iShowMaybe : ⦃ Show a ⦄ → Show (Maybe a)\n iShowMaybe = makeShowsPrec λ where p Nothing → showString \"Nothing\"\n p (Just x) → showApp₁ p \"Just\" x\n\n iShowEither : ⦃ Show a ⦄ → ⦃ Show b ⦄ → Show (Either a b)\n iShowEither = makeShowsPrec λ where p (Left x) → showApp₁ p \"Left\" x\n p (Right y) → showApp₁ p \"Right\" y\n\nprivate\n -- Minus the parens\n showTuple : ∀ {as} → ⦃ All Show as ⦄ → Tuple as → ShowS\n showTuple [] = showString \"\"\n showTuple ⦃ allCons ⦄ (x ∷ []) = shows x\n showTuple ⦃ allCons ⦄ (x ∷ xs) = shows x ∘ showString \",\" ∘ showTuple xs\n\ninstance\n iShowTuple : ∀ {as} → ⦃ All Show as ⦄ → Show (Tuple as)\n iShowTuple = makeShowsPrec λ _ → showParen true ∘ showTuple\n", "meta": {"hexsha": "b16820b1a19048ad04578ae849916742d4306ecf", "size": 3315, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lib/Haskell/Prim/Show.agda", "max_stars_repo_name": "flupe/agda2hs", "max_stars_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6", "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": "lib/Haskell/Prim/Show.agda", "max_issues_repo_name": "flupe/agda2hs", "max_issues_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6", "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": "lib/Haskell/Prim/Show.agda", "max_forks_repo_name": "flupe/agda2hs", "max_forks_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6", "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": 28.5775862069, "max_line_length": 124, "alphanum_fraction": 0.6660633484, "num_tokens": 1051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6688802735722129, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.3785986326689116}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Algebra\n\nmodule Data.FingerTree.View\n {r m}\n (ℳ : Monoid r m)\n where\n\nopen import Level using (_⊔_)\nopen import Data.Product\nopen import Function\n\nopen import Data.List as List using (List; _∷_; [])\n\nopen import Data.FingerTree.Structures ℳ\nopen import Data.FingerTree.Reasoning ℳ\nopen import Data.FingerTree.Measures ℳ\nopen import Data.FingerTree.Cons ℳ\nopen σ ⦃ ... ⦄\n{-# DISPLAY σ.μ _ = μ #-}\n{-# DISPLAY μ-tree _ x = μ x #-}\n{-# DISPLAY μ-deep _ x = μ x #-}\n\nopen Monoid ℳ renaming (Carrier to 𝓡)\n\ninfixr 5 _◃_\ndata Viewₗ {a b} (A : Set a) (Σ : Set b) : Set (a ⊔ b) where\n nilₗ : Viewₗ A Σ\n _◃_ : A → Σ → Viewₗ A Σ\n\ninstance\n σ-Viewₗ : ∀ {a b} {A : Set a} {Σ : Set b} ⦃ _ : σ A ⦄ ⦃ _ : σ Σ ⦄ → σ (Viewₗ A Σ)\n μ ⦃ σ-Viewₗ ⦄ nilₗ = ε\n μ ⦃ σ-Viewₗ ⦄ (x ◃ xs) = μ x ∙ μ xs\n\nviewₗ : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → (xs : Tree Σ) → μ⟨ Viewₗ Σ (Tree Σ) ⟩≈ (μ xs)\nviewₗ empty = nilₗ ⇑\nviewₗ (single x) = (x ◃ empty) ⇑[ ℳ ↯ ]\nviewₗ (deep (𝓂 ↤ (D₂ a b & m & rs) ⇑[ 𝓂≈ ])) = a ◃ deep ⟪ D₁ b & m & rs ⇓⟫ ⇑[ ℳ ↯ ] ≈[ 𝓂≈ ]′\nviewₗ (deep (𝓂 ↤ (D₃ a b c & m & rs) ⇑[ 𝓂≈ ])) = a ◃ deep ⟪ D₂ b c & m & rs ⇓⟫ ⇑[ ℳ ↯ ] ≈[ 𝓂≈ ]′\nviewₗ (deep (𝓂 ↤ (D₄ a b c d & m & rs) ⇑[ 𝓂≈ ])) = a ◃ deep ⟪ D₃ b c d & m & rs ⇓⟫ ⇑[ ℳ ↯ ] ≈[ 𝓂≈ ]′\nviewₗ (deep (𝓂 ↤ (D₁ a & m & rs) ⇑[ 𝓂≈ ])) with viewₗ m\n... | (μ⟨y⟩ ↤ N₂ y₁ y₂ ⇑[ yp ]) ◃ ys ⇑[ p ] = a ◃ deep (μ m ∙ μ rs ↤ D₂ y₁ y₂ & ys & rs ⇑[ ℳ ↯ ] ≈[ ≪∙ (≪∙ yp ⍮ p) ]′) ⇑[ 𝓂≈ ]\n... | (μ⟨y⟩ ↤ N₃ y₁ y₂ y₃ ⇑[ yp ]) ◃ ys ⇑[ p ] = a ◃ deep (μ m ∙ μ rs ↤ D₃ y₁ y₂ y₃ & ys & rs ⇑[ ℳ ↯ ] ≈[ ≪∙ (≪∙ yp ⍮ p) ]′) ⇑[ 𝓂≈ ]\n... | nilₗ ⇑[ p ] = (digitToTree rs [ _ ∙> r ⟿ r ] >>= (λ rs′ → (a ◃ rs′) ⇑)) ≈[ ∙≫ sym (identityˡ _) ⍮ (∙≫ ≪∙ p) ⍮ 𝓂≈ ]\n\ninfixl 5 _▹_\ndata Viewᵣ {a b} (A : Set a) (Σ : Set b) : Set (a ⊔ b) where\n nilᵣ : Viewᵣ A Σ\n _▹_ : Σ → A → Viewᵣ A Σ\n\ninstance\n σ-Viewᵣ : ∀ {a b} {A : Set a} {Σ : Set b} ⦃ _ : σ A ⦄ ⦃ _ : σ Σ ⦄ → σ (Viewᵣ A Σ)\n μ ⦃ σ-Viewᵣ ⦄ nilᵣ = ε\n μ ⦃ σ-Viewᵣ ⦄ (xs ▹ x) = μ xs ∙ μ x\n\nviewᵣ : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → (xs : Tree Σ) → μ⟨ Viewᵣ Σ (Tree Σ) ⟩≈ (μ xs)\nviewᵣ empty = nilᵣ ⇑\nviewᵣ (single x) = empty ▹ x ⇑[ ℳ ↯ ]\nviewᵣ (deep (𝓂 ↤ (ls & m & D₂ a b ) ⇑[ 𝓂≈ ])) = (deep ⟪ ls & m & D₁ a ⇓⟫ ▹ b) ⇑[ ℳ ↯ ] ≈[ 𝓂≈ ]′\nviewᵣ (deep (𝓂 ↤ (ls & m & D₃ a b c ) ⇑[ 𝓂≈ ])) = (deep ⟪ ls & m & D₂ a b ⇓⟫ ▹ c) ⇑[ ℳ ↯ ] ≈[ 𝓂≈ ]′\nviewᵣ (deep (𝓂 ↤ (ls & m & D₄ a b c d) ⇑[ 𝓂≈ ])) = (deep ⟪ ls & m & D₃ a b c ⇓⟫ ▹ d) ⇑[ ℳ ↯ ] ≈[ 𝓂≈ ]′\nviewᵣ (deep (𝓂 ↤ (ls & m & D₁ a) ⇑[ 𝓂≈ ])) with viewᵣ m\n... | ys ▹ (μ⟨y⟩ ↤ N₂ y₁ y₂ ⇑[ yp ]) ⇑[ p ] = deep (μ ls ∙ μ m ↤ ls & ys & D₂ y₁ y₂ ⇑[ ℳ ↯ ] ≈[ ∙≫ (∙≫ yp ⍮ p) ]′) ▹ a ⇑[ ℳ ↯ ] ≈[ 𝓂≈ ]′\n... | ys ▹ (μ⟨y⟩ ↤ N₃ y₁ y₂ y₃ ⇑[ yp ]) ⇑[ p ] = deep (μ ls ∙ μ m ↤ ls & ys & D₃ y₁ y₂ y₃ ⇑[ ℳ ↯ ] ≈[ ∙≫ (∙≫ yp ⍮ p) ]′) ▹ a ⇑[ ℳ ↯ ] ≈[ 𝓂≈ ]′\n... | nilᵣ ⇑[ p ] = (digitToTree ls [ l <∙ _ ⟿ l ] >>= (λ ls′ → (ls′ ▹ a) ⇑)) ≈[ ℳ ↯ ↣ μ ls ∙ (ε ∙ μ a) ] ≈[ ∙≫ ≪∙ p ⍮ 𝓂≈ ]′\n\ndeepₗ : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → (l : List Σ) → (m : Tree ⟪ Node Σ ⟫) → (r : Digit Σ) → μ⟨ Tree Σ ⟩≈ (μ l ∙ (μ m ∙ μ r))\ndeepₗ [] m r with viewₗ m\ndeepₗ [] m r | nilₗ ⇑[ n≈ ] = digitToTree r ≈[ ℳ ↯ ↣ ε ∙ (ε ∙ μ r) ] ≈[ ∙≫ ≪∙ n≈ ]′\ndeepₗ [] m r | ((μ⟨y⟩ ↤ N₂ y₁ y₂ ⇑[ yp ]) ◃ ys) ⇑[ ys≈ ] = deep (μ m ∙ μ r ↤ D₂ y₁ y₂ & ys & r ⇑[ ≪∙ yp ⍮ sym (assoc _ _ _) ⍮ ≪∙ ys≈ ]) ⇑[ ℳ ↯ ]\ndeepₗ [] m r | ((μ⟨y⟩ ↤ N₃ y₁ y₂ y₃ ⇑[ yp ]) ◃ ys) ⇑[ ys≈ ] = deep (μ m ∙ μ r ↤ D₃ y₁ y₂ y₃ & ys & r ⇑[ ≪∙ yp ⍮ sym (assoc _ _ _) ⍮ ≪∙ ys≈ ]) ⇑[ ℳ ↯ ]\ndeepₗ (l ∷ ls) m r = go l ls m r\n where\n go : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → (l : Σ) → (ls : List Σ) → (m : Tree ⟪ Node Σ ⟫) → (r : Digit Σ) → μ⟨ Tree Σ ⟩≈ (μ l ∙ μ ls ∙ (μ m ∙ μ r))\n go l [] m r = deep ⟪ D₁ l & m & r ⇓⟫ ⇑[ ℳ ↯ ]\n go l₁ (l₂ ∷ ls) m r = (go l₂ ls m r [ _ ∙> ls′ ⟿ ls′ ] >>= (l₁ ◂_)) ≈[ ℳ ↯ ]\n\ndeepᵣ : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → (l : Digit Σ) → (m : Tree ⟪ Node Σ ⟫) → (r : List Σ) → μ⟨ Tree Σ ⟩≈ (μ l ∙ (μ m ∙ μ r))\ndeepᵣ l m [] with viewᵣ m\ndeepᵣ l m [] | nilᵣ ⇑[ p ] = digitToTree l ≈[ sym (identityʳ _) ⍮ ∙≫ (p ⍮ sym (identityʳ _)) ]\ndeepᵣ l m [] | (ys ▹ (μ⟨y⟩ ↤ N₂ y₁ y₂ ⇑[ μ⟨y⟩≈ ])) ⇑[ p ] = deep (μ l ∙ μ m ↤ l & ys & D₂ y₁ y₂ ⇑[ ∙≫ (∙≫ μ⟨y⟩≈ ⍮ p) ]) ⇑[ ℳ ↯ ]\ndeepᵣ l m [] | (ys ▹ (μ⟨y⟩ ↤ N₃ y₁ y₂ y₃ ⇑[ μ⟨y⟩≈ ])) ⇑[ p ] = deep (μ l ∙ μ m ↤ l & ys & D₃ y₁ y₂ y₃ ⇑[ ∙≫ (∙≫ μ⟨y⟩≈ ⍮ p) ]) ⇑[ ℳ ↯ ]\ndeepᵣ l m (r ∷ rs) = go (deep ⟪ l & m & D₁ r ⇓⟫ ⇑) rs ≈[ ℳ ↯ ]\n where\n go : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → ∀ {xs} → μ⟨ Tree Σ ⟩≈ xs → (rs : List Σ) → μ⟨ Tree Σ ⟩≈ (xs ∙ μ rs)\n go xs [] = xs ≈[ sym (identityʳ _) ]\n go xs (r ∷ rs) = go (xs [ sz <∙ _ ⟿ sz ] >>= (_▸ r)) rs ≈[ ℳ ↯ ]\n", "meta": {"hexsha": "268576458d0b5e0e55137bd7bb8322ac23b1470c", "size": 4581, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Data/FingerTree/View.agda", "max_stars_repo_name": "oisdk/agda-indexed-fingertree", "max_stars_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-02-26T07:04:54.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-26T07:04:54.000Z", "max_issues_repo_path": "src/Data/FingerTree/View.agda", "max_issues_repo_name": "oisdk/agda-indexed-fingertree", "max_issues_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f", "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/Data/FingerTree/View.agda", "max_forks_repo_name": "oisdk/agda-indexed-fingertree", "max_forks_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f", "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": 50.9, "max_line_length": 150, "alphanum_fraction": 0.4154114822, "num_tokens": 2838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.37853216810354917}} {"text": "\ndata _≡_ {A : Set}(x : A) : A → Set where\n refl : x ≡ x\n\ndata * : Set where ! : *\n\npostulate\n prop : ∀ x → x ≡ !\n\nrecord StrictTotalOrder : Set where\n field compare : *\n\nopen StrictTotalOrder\n\nmodule M (Key : StrictTotalOrder) where\n\n postulate\n intersection′-₁ : ∀ x → x ≡ compare Key\n\n -- Doesn't termination check, but shouldn't get __IMPOSSIBLE__\n -- when termination checking!\n to-∈-intersection′ : * → * → Set\n to-∈-intersection′ x h with intersection′-₁ x\n to-∈-intersection′ ._ h | refl with prop h\n to-∈-intersection′ ._ ._ | refl | refl = to-∈-intersection′ ! !\n", "meta": {"hexsha": "c5f861f73809644bc58f98442646c60d8aca8939", "size": 609, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue1035.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Issue1035.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Issue1035.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 23.4230769231, "max_line_length": 71, "alphanum_fraction": 0.6108374384, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.37853216810354917}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Substitution.Reduction {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.LogicalRelation.Properties\nopen import Definition.LogicalRelation.Substitution\nopen import Definition.Untyped using (Con ; Term)\n\nopen import Tools.Nat\nopen import Tools.Product\n\nprivate\n variable\n n : Nat\n Γ : Con Term n\n\n-- Weak head expansion of valid terms.\nredSubstTermᵛ : ∀ {A t u l}\n → ([Γ] : ⊩ᵛ Γ)\n → Γ ⊩ᵛ t ⇒ u ∷ A / [Γ]\n → ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])\n → Γ ⊩ᵛ⟨ l ⟩ u ∷ A / [Γ] / [A]\n → Γ ⊩ᵛ⟨ l ⟩ t ∷ A / [Γ] / [A]\n × Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A / [Γ] / [A]\nredSubstTermᵛ [Γ] t⇒u [A] [u] =\n (λ ⊢Δ [σ] →\n let [σA] = proj₁ ([A] ⊢Δ [σ])\n [σt] , [σt≡σu] = redSubstTerm (t⇒u ⊢Δ [σ])\n (proj₁ ([A] ⊢Δ [σ]))\n (proj₁ ([u] ⊢Δ [σ]))\n in [σt]\n , (λ [σ′] [σ≡σ′] →\n let [σ′A] = proj₁ ([A] ⊢Δ [σ′])\n [σA≡σ′A] = proj₂ ([A] ⊢Δ [σ]) [σ′] [σ≡σ′]\n [σ′t] , [σ′t≡σ′u] = redSubstTerm (t⇒u ⊢Δ [σ′])\n (proj₁ ([A] ⊢Δ [σ′]))\n (proj₁ ([u] ⊢Δ [σ′]))\n in transEqTerm [σA] [σt≡σu]\n (transEqTerm [σA] ((proj₂ ([u] ⊢Δ [σ])) [σ′] [σ≡σ′])\n (convEqTerm₂ [σA] [σ′A] [σA≡σ′A]\n (symEqTerm [σ′A] [σ′t≡σ′u])))))\n , (λ ⊢Δ [σ] → proj₂ (redSubstTerm (t⇒u ⊢Δ [σ])\n (proj₁ ([A] ⊢Δ [σ]))\n (proj₁ ([u] ⊢Δ [σ]))))\n", "meta": {"hexsha": "37a13111faf1d338e7616a0c89196be4f8597ccc", "size": 1801, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Reduction.agda", "max_stars_repo_name": "fhlkfy/logrel-mltt", "max_stars_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2017-05-20T03:05:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:01:07.000Z", "max_issues_repo_path": "Definition/LogicalRelation/Substitution/Reduction.agda", "max_issues_repo_name": "fhlkfy/logrel-mltt", "max_issues_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-06-22T12:49:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-22T10:37:24.000Z", "max_forks_repo_path": "Definition/LogicalRelation/Substitution/Reduction.agda", "max_forks_repo_name": "fhlkfy/logrel-mltt", "max_forks_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2017-10-18T14:18:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-27T15:58:33.000Z", "avg_line_length": 37.5208333333, "max_line_length": 85, "alphanum_fraction": 0.3814547474, "num_tokens": 676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.37834441228619275}} {"text": "module BasicT.Metatheory.GentzenNormalForm-Unknown where\n\nopen import BasicT.Syntax.GentzenNormalForm public\n\n\n-- Forcing. (In a particular model?)\n\ninfix 3 _⊩_\n_⊩_ : Cx Ty → Ty → Set\nΓ ⊩ α P = Γ ⊢ⁿᶠ α P\nΓ ⊩ A ▻ B = Γ ⊢ⁿᵉ A ▻ B ⊎ ∀ {Γ′} → Γ ⊆ Γ′ → Γ′ ⊩ A → Γ′ ⊩ B\nΓ ⊩ A ∧ B = Γ ⊢ⁿᵉ A ∧ B ⊎ Γ ⊩ A × Γ ⊩ B\nΓ ⊩ ⊤ = Γ ⊢ⁿᶠ ⊤\nΓ ⊩ BOOL = Γ ⊢ⁿᶠ BOOL\nΓ ⊩ NAT = Γ ⊢ⁿᶠ NAT\n\ninfix 3 _⊩⋆_\n_⊩⋆_ : Cx Ty → Cx Ty → Set\nΓ ⊩⋆ ∅ = 𝟙\nΓ ⊩⋆ Ξ , A = Γ ⊩⋆ Ξ × Γ ⊩ A\n\n\n-- Monotonicity with respect to context inclusion.\n\nmono⊩ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩ A → Γ′ ⊩ A\nmono⊩ {α P} η t = mono⊢ⁿᶠ η t\nmono⊩ {A ▻ B} η (ι₁ t) = ι₁ (mono⊢ⁿᵉ η t)\nmono⊩ {A ▻ B} η (ι₂ s) = ι₂ (λ η′ a → s (trans⊆ η η′) a)\nmono⊩ {A ∧ B} η (ι₁ t) = ι₁ (mono⊢ⁿᵉ η t)\nmono⊩ {A ∧ B} η (ι₂ s) = ι₂ (mono⊩ {A} η (π₁ s) , mono⊩ {B} η (π₂ s))\nmono⊩ {⊤} η t = mono⊢ⁿᶠ η t\nmono⊩ {BOOL} η t = mono⊢ⁿᶠ η t\nmono⊩ {NAT} η t = mono⊢ⁿᶠ η t\n\nmono⊩⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩⋆ Ξ → Γ′ ⊩⋆ Ξ\nmono⊩⋆ {∅} η ∙ = ∙\nmono⊩⋆ {Ξ , A} η (γ , a) = mono⊩⋆ {Ξ} η γ , mono⊩ {A} η a\n\n\n-- Soundness and completeness. (With respect to a particular model?)\n\nreflect : ∀ {A Γ} → Γ ⊢ⁿᵉ A → Γ ⊩ A\nreflect {α P} t = neⁿᶠ t\nreflect {A ▻ B} t = ι₁ t\nreflect {A ∧ B} t = ι₁ t\nreflect {⊤} t = neⁿᶠ t\nreflect {BOOL} t = neⁿᶠ t\nreflect {NAT} t = neⁿᶠ t\n\nreify : ∀ {A Γ} → Γ ⊩ A → Γ ⊢ⁿᶠ A\nreify {α P} t = t\nreify {A ▻ B} (ι₁ t) = neⁿᶠ t\nreify {A ▻ B} (ι₂ s) = lamⁿᶠ (reify (s weak⊆ (reflect {A} (varⁿᵉ top))))\nreify {A ∧ B} (ι₁ t) = neⁿᶠ t\nreify {A ∧ B} (ι₂ s) = pairⁿᶠ (reify (π₁ s)) (reify (π₂ s))\nreify {⊤} t = t\nreify {BOOL} t = t\nreify {NAT} t = t\n\nreflect⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ⁿᵉ Ξ → Γ ⊩⋆ Ξ\nreflect⋆ {∅} ∙ = ∙\nreflect⋆ {Ξ , A} (ts , t) = reflect⋆ ts , reflect t\n\nreify⋆ : ∀ {Ξ Γ} → Γ ⊩⋆ Ξ → Γ ⊢⋆ⁿᶠ Ξ\nreify⋆ {∅} ∙ = ∙\nreify⋆ {Ξ , A} (ts , t) = reify⋆ ts , reify t\n\n\n-- Additional useful equipment.\n\n_⟪$⟫_ : ∀ {A B w} → w ⊩ A ▻ B → w ⊩ A → w ⊩ B\nι₁ t ⟪$⟫ a = reflect (appⁿᵉ t (reify a))\nι₂ s ⟪$⟫ a = s refl⊆ a\n\n⟪π₁⟫ : ∀ {A B w} → w ⊩ A ∧ B → w ⊩ A\n⟪π₁⟫ (ι₁ t) = reflect (fstⁿᵉ t)\n⟪π₁⟫ (ι₂ s) = π₁ s\n\n⟪π₂⟫ : ∀ {A B w} → w ⊩ A ∧ B → w ⊩ B\n⟪π₂⟫ (ι₁ t) = reflect (sndⁿᵉ t)\n⟪π₂⟫ (ι₂ s) = π₂ s\n\n⟪if⟫ : ∀ {C w} → w ⊩ BOOL → w ⊩ C → w ⊩ C → w ⊩ C\n⟪if⟫ {C} (neⁿᶠ t) s₂ s₃ = reflect {C} (ifⁿᵉ t (reify s₂) (reify s₃))\n⟪if⟫ {C} trueⁿᶠ s₂ s₃ = s₂\n⟪if⟫ {C} falseⁿᶠ s₂ s₃ = s₃\n\n⟪it⟫ : ∀ {C w} → w ⊩ NAT → w ⊩ C ▻ C → w ⊩ C → w ⊩ C\n⟪it⟫ {C} (neⁿᶠ t) s₂ s₃ = reflect {C} (itⁿᵉ t (reify s₂) (reify s₃))\n⟪it⟫ {C} zeroⁿᶠ s₂ s₃ = s₃\n⟪it⟫ {C} (sucⁿᶠ t) s₂ s₃ = s₂ ⟪$⟫ ⟪it⟫ t s₂ s₃\n\n⟪rec⟫ : ∀ {C w} → w ⊩ NAT → w ⊩ NAT ▻ C ▻ C → w ⊩ C → w ⊩ C\n⟪rec⟫ {C} (neⁿᶠ t) s₂ s₃ = reflect {C} (recⁿᵉ t (reify s₂) (reify s₃))\n⟪rec⟫ {C} zeroⁿᶠ s₂ s₃ = s₃\n⟪rec⟫ {C} (sucⁿᶠ t) s₂ s₃ = (s₂ ⟪$⟫ t) ⟪$⟫ ⟪rec⟫ t s₂ s₃\n\n\n-- Forcing for sequents. (In a particular world of a particular model?)\n\ninfix 3 _⊩_⇒_\n_⊩_⇒_ : Cx Ty → Cx Ty → Ty → Set\nw ⊩ Γ ⇒ A = w ⊩⋆ Γ → w ⊩ A\n\ninfix 3 _⊩_⇒⋆_\n_⊩_⇒⋆_ : Cx Ty → Cx Ty → Cx Ty → Set\nw ⊩ Γ ⇒⋆ Ξ = w ⊩⋆ Γ → w ⊩⋆ Ξ\n\n\n-- Entailment. (Forcing in all worlds of all models, for sequents?)\n\ninfix 3 _⊨_\n_⊨_ : Cx Ty → Ty → Set\nΓ ⊨ A = ∀ {w : Cx Ty} → w ⊩ Γ ⇒ A\n\ninfix 3 _⊨⋆_\n_⊨⋆_ : Cx Ty → Cx Ty → Set\nΓ ⊨⋆ Ξ = ∀ {w : Cx Ty} → w ⊩ Γ ⇒⋆ Ξ\n\n\n-- Additional useful equipment, for sequents.\n\nlookup : ∀ {A Γ w} → A ∈ Γ → w ⊩ Γ ⇒ A\nlookup top (γ , a) = a\nlookup (pop i) (γ , b) = lookup i γ\n\n\n-- Evaluation. (Soundness with respect to all models?)\n\neval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A\neval (var i) γ = lookup i γ\neval (lam t) γ = ι₂ (λ η a → eval t (mono⊩⋆ η γ , a))\neval (app t u) γ = eval t γ ⟪$⟫ eval u γ\neval (pair t u) γ = ι₂ (eval t γ , eval u γ)\neval (fst t) γ = ⟪π₁⟫ (eval t γ)\neval (snd t) γ = ⟪π₂⟫ (eval t γ)\neval unit γ = unitⁿᶠ\neval true γ = trueⁿᶠ\neval false γ = trueⁿᶠ\neval (if {C} t u v) γ = ⟪if⟫ {C} (eval t γ) (eval u γ) (eval v γ)\neval zero γ = zeroⁿᶠ\neval (suc t) γ = sucⁿᶠ (eval t γ)\neval (it {C} t u v) γ = ⟪it⟫ {C} (eval t γ) (eval u γ) (eval v γ)\neval (rec {C} t u v) γ = ⟪rec⟫ {C} (eval t γ) (eval u γ) (eval v γ)\n\neval⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊨⋆ Ξ\neval⋆ {∅} ∙ γ = ∙\neval⋆ {Ξ , A} (ts , t) γ = eval⋆ ts γ , eval t γ\n\n\n-- Reflexivity and transitivity.\n\nrefl⊩⋆ : ∀ {Γ} → Γ ⊩⋆ Γ\nrefl⊩⋆ = reflect⋆ refl⊢⋆ⁿᵉ\n\ntrans⊩⋆ : ∀ {Γ Γ′ Γ″} → Γ ⊩⋆ Γ′ → Γ′ ⊩⋆ Γ″ → Γ ⊩⋆ Γ″\ntrans⊩⋆ ts us = eval⋆ (trans⊢⋆ (nf→tm⋆ (reify⋆ ts)) (nf→tm⋆ (reify⋆ us))) refl⊩⋆\n\n\n-- Quotation. (Completeness with respect to all models?)\n\nquot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A\nquot s = nf→tm (reify (s refl⊩⋆))\n\n\n-- Normalisation by evaluation.\n\nnorm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A\nnorm = quot ∘ eval\n\n\n-- TODO: Correctness of normalisation with respect to conversion.\n", "meta": {"hexsha": "4dd08a6a469b53f09b204d9e2045cefa41681e20", "size": 4752, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BasicT/Metatheory/GentzenNormalForm-Unknown.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": "BasicT/Metatheory/GentzenNormalForm-Unknown.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": "BasicT/Metatheory/GentzenNormalForm-Unknown.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": 27.4682080925, "max_line_length": 80, "alphanum_fraction": 0.4814814815, "num_tokens": 2824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.37834441228619275}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Substitution.Introductions.Natrec {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped\nopen import Definition.Untyped.Properties\nopen import Definition.Typed\nopen import Definition.Typed.Properties\nopen import Definition.Typed.RedSteps\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.Irrelevance\nopen import Definition.LogicalRelation.Properties\nopen import Definition.LogicalRelation.Application\nopen import Definition.LogicalRelation.Substitution\nopen import Definition.LogicalRelation.Substitution.Properties\nimport Definition.LogicalRelation.Substitution.Irrelevance as S\nopen import Definition.LogicalRelation.Substitution.Reflexivity\nopen import Definition.LogicalRelation.Substitution.Weakening\nopen import Definition.LogicalRelation.Substitution.Introductions.Nat\nopen import Definition.LogicalRelation.Substitution.Introductions.Pi\nopen import Definition.LogicalRelation.Substitution.Introductions.SingleSubst\n\nopen import Tools.Embedding\nopen import Tools.Product\nopen import Tools.Empty\nimport Tools.PropositionalEquality as PE\n\n\n-- Natural recursion closure reduction (requires reducible terms and equality).\nnatrec-subst* : ∀ {Γ C c g n n′ l} → Γ ∙ ℕ ⊢ C → Γ ⊢ c ∷ C [ zero ]\n → Γ ⊢ g ∷ Π ℕ ▹ (C ▹▹ C [ suc (var 0) ]↑)\n → Γ ⊢ n ⇒* n′ ∷ ℕ\n → ([ℕ] : Γ ⊩⟨ l ⟩ ℕ)\n → Γ ⊩⟨ l ⟩ n′ ∷ ℕ / [ℕ]\n → (∀ {t t′} → Γ ⊩⟨ l ⟩ t ∷ ℕ / [ℕ]\n → Γ ⊩⟨ l ⟩ t′ ∷ ℕ / [ℕ]\n → Γ ⊩⟨ l ⟩ t ≡ t′ ∷ ℕ / [ℕ]\n → Γ ⊢ C [ t ] ≡ C [ t′ ])\n → Γ ⊢ natrec C c g n ⇒* natrec C c g n′ ∷ C [ n ]\nnatrec-subst* C c g (id x) [ℕ] [n′] prop = id (natrecⱼ C c g x)\nnatrec-subst* C c g (x ⇨ n⇒n′) [ℕ] [n′] prop =\n let q , w = redSubst*Term n⇒n′ [ℕ] [n′]\n a , s = redSubstTerm x [ℕ] q\n in natrec-subst C c g x ⇨ conv* (natrec-subst* C c g n⇒n′ [ℕ] [n′] prop)\n (prop q a (symEqTerm [ℕ] s))\n\n-- Helper functions for construction of valid type for the successor case of natrec.\n\nsucCase₃ : ∀ {Γ l} ([Γ] : ⊩ᵛ Γ)\n ([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])\n → Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ suc (var 0) ∷ ℕ / [Γ] ∙″ [ℕ]\n / (λ {Δ} {σ} → wk1ᵛ {ℕ} {ℕ} [Γ] [ℕ] [ℕ] {Δ} {σ})\nsucCase₃ {Γ} {l} [Γ] [ℕ] {Δ} {σ} =\n sucᵛ {n = var 0} {l = l} (_∙″_ {A = ℕ} [Γ] [ℕ])\n (λ {Δ} {σ} → wk1ᵛ {ℕ} {ℕ} [Γ] [ℕ] [ℕ] {Δ} {σ})\n (λ ⊢Δ [σ] → proj₂ [σ] , (λ [σ′] [σ≡σ′] → proj₂ [σ≡σ′])) {Δ} {σ}\n\nsucCase₂ : ∀ {F Γ l} ([Γ] : ⊩ᵛ Γ)\n ([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])\n ([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙″ [ℕ]))\n → Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F [ suc (var 0) ]↑ / ([Γ] ∙″ [ℕ])\nsucCase₂ {F} {Γ} {l} [Γ] [ℕ] [F] =\n subst↑S {ℕ} {F} {suc (var 0)} [Γ] [ℕ] [F]\n (λ {Δ} {σ} → sucCase₃ [Γ] [ℕ] {Δ} {σ})\n\nsucCase₁ : ∀ {F Γ l} ([Γ] : ⊩ᵛ Γ)\n ([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])\n ([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙″ [ℕ]))\n → Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F ▹▹ F [ suc (var 0) ]↑ / ([Γ] ∙″ [ℕ])\nsucCase₁ {F} {Γ} {l} [Γ] [ℕ] [F] =\n ▹▹ᵛ {F} {F [ suc (var 0) ]↑} (_∙″_ {A = ℕ} [Γ] [ℕ]) [F]\n (sucCase₂ {F} [Γ] [ℕ] [F])\n\n-- Construct a valid type for the successor case of natrec.\nsucCase : ∀ {F Γ l} ([Γ] : ⊩ᵛ Γ)\n ([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])\n ([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙″ [ℕ]))\n → Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ]\nsucCase {F} {Γ} {l} [Γ] [ℕ] [F] =\n Πᵛ {ℕ} {F ▹▹ F [ suc (var 0) ]↑} [Γ] [ℕ]\n (sucCase₁ {F} [Γ] [ℕ] [F])\n\n-- Construct a valid type equality for the successor case of natrec.\nsucCaseCong : ∀ {F F′ Γ l} ([Γ] : ⊩ᵛ Γ)\n ([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])\n ([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙″ [ℕ]))\n ([F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F′ / ([Γ] ∙″ [ℕ]))\n ([F≡F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F ≡ F′ / [Γ] ∙″ [ℕ] / [F])\n → Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)\n ≡ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑)\n / [Γ] / sucCase {F} [Γ] [ℕ] [F]\nsucCaseCong {F} {F′} {Γ} {l} [Γ] [ℕ] [F] [F′] [F≡F′] =\n Π-congᵛ {ℕ} {F ▹▹ F [ suc (var 0) ]↑} {ℕ} {F′ ▹▹ F′ [ suc (var 0) ]↑}\n [Γ] [ℕ] (sucCase₁ {F} [Γ] [ℕ] [F]) [ℕ] (sucCase₁ {F′} [Γ] [ℕ] [F′])\n (reflᵛ {ℕ} [Γ] [ℕ])\n (▹▹-congᵛ {F} {F′} {F [ suc (var 0) ]↑} {F′ [ suc (var 0) ]↑}\n (_∙″_ {A = ℕ} [Γ] [ℕ]) [F] [F′] [F≡F′]\n (sucCase₂ {F} [Γ] [ℕ] [F]) (sucCase₂ {F′} [Γ] [ℕ] [F′])\n (subst↑SEq {ℕ} {F} {F′} {suc (var 0)} {suc (var 0)}\n [Γ] [ℕ] [F] [F′] [F≡F′]\n (λ {Δ} {σ} → sucCase₃ [Γ] [ℕ] {Δ} {σ})\n (λ {Δ} {σ} → sucCase₃ [Γ] [ℕ] {Δ} {σ})\n (λ {Δ} {σ} →\n reflᵗᵛ {ℕ} {suc (var 0)} (_∙″_ {A = ℕ} [Γ] [ℕ])\n (λ {Δ} {σ} → wk1ᵛ {ℕ} {ℕ} [Γ] [ℕ] [ℕ] {Δ} {σ})\n (λ {Δ} {σ} → sucCase₃ [Γ] [ℕ] {Δ} {σ})\n {Δ} {σ})))\n\n-- Reducibility of natural recursion under a valid substitution.\nnatrecTerm : ∀ {F z s n Γ Δ σ l}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / _∙″_ {l = l} [Γ] (ℕᵛ [Γ]))\n ([F₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] / [Γ])\n ([F₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ])\n ([z] : Γ ⊩ᵛ⟨ l ⟩ z ∷ F [ zero ] / [Γ] / [F₀])\n ([s] : Γ ⊩ᵛ⟨ l ⟩ s ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)\n / [Γ] / [F₊])\n (⊢Δ : ⊢ Δ)\n ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)\n ([σn] : Δ ⊩⟨ l ⟩ n ∷ ℕ / ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))\n → Δ ⊩⟨ l ⟩ natrec (subst (liftSubst σ) F) (subst σ z) (subst σ s) n\n ∷ subst (liftSubst σ) F [ n ]\n / irrelevance′ (PE.sym (singleSubstComp n σ F))\n (proj₁ ([F] ⊢Δ ([σ] , [σn])))\nnatrecTerm {F} {z} {s} {n} {Γ} {Δ} {σ} {l} [Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ]\n (ιx (ℕₜ .(suc m) d n≡n (sucᵣ {m} [m]))) =\n let [ℕ] = ℕᵛ {l = l} [Γ]\n [σℕ] = proj₁ ([ℕ] ⊢Δ [σ])\n ⊢ℕ = escape (proj₁ ([ℕ] ⊢Δ [σ]))\n ⊢F = escape (proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ])))\n ⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)\n (escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))\n ⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)\n (escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))\n ⊢m = escapeTerm {l = l} [σℕ] (ιx [m])\n [σsm] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) [σℕ]\n (ιx (ℕₜ (suc m) (idRedTerm:*: (sucⱼ ⊢m)) n≡n (sucᵣ [m])))\n [σn] = ℕₜ (suc m) d n≡n (sucᵣ [m])\n [σn]′ , [σn≡σsm] = redSubst*Term (redₜ d) [σℕ] [σsm]\n [σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , ιx [σn]))\n [σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′\n [σFₛₘ] = irrelevance′ (PE.sym (singleSubstComp (suc m) σ F))\n (proj₁ ([F] ⊢Δ ([σ] , [σsm])))\n [Fₙ≡Fₛₘ] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.sym (singleSubstComp (suc m) σ F))\n [σFₙ]′ [σFₙ]\n (proj₂ ([F] ⊢Δ ([σ] , ιx [σn])) ([σ] , [σsm])\n (reflSubst [Γ] ⊢Δ [σ] , [σn≡σsm]))\n [σFₘ] = irrelevance′ (PE.sym (PE.trans (substCompEq F)\n (substSingletonComp F)))\n (proj₁ ([F] ⊢Δ ([σ] , ιx [m])))\n [σFₛₘ]′ = irrelevance′ (natrecIrrelevantSubst F z s m σ)\n (proj₁ ([F] ⊢Δ ([σ] , [σsm])))\n [σF₊ₘ] = substSΠ₁ (proj₁ ([F₊] ⊢Δ [σ])) [σℕ] (ιx [m])\n natrecM = appTerm [σFₘ] [σFₛₘ]′ [σF₊ₘ]\n (appTerm [σℕ] [σF₊ₘ]\n (proj₁ ([F₊] ⊢Δ [σ]))\n (proj₁ ([s] ⊢Δ [σ])) (ιx [m]))\n (natrecTerm {F} {z} {s} {m} {σ = σ}\n [Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ] (ιx [m]))\n natrecM′ = irrelevanceTerm′ (PE.trans\n (PE.sym (natrecIrrelevantSubst F z s m σ))\n (PE.sym (singleSubstComp (suc m) σ F)))\n [σFₛₘ]′ [σFₛₘ] natrecM\n reduction = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) [σℕ] [σsm]\n (λ {t} {t′} [t] [t′] [t≡t′] →\n PE.subst₂ (λ x y → _ ⊢ x ≡ y)\n (PE.sym (singleSubstComp t σ F))\n (PE.sym (singleSubstComp t′ σ F))\n (≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))\n (proj₂ ([F] ⊢Δ ([σ] , [t]))\n ([σ] , [t′])\n (reflSubst [Γ] ⊢Δ [σ] ,\n [t≡t′])))))\n ⇨∷* (conv* (natrec-suc ⊢m ⊢F ⊢z ⊢s\n ⇨ id (escapeTerm [σFₛₘ] natrecM′))\n (sym (≅-eq (escapeEq [σFₙ] [Fₙ≡Fₛₘ]))))\n in proj₁ (redSubst*Term reduction [σFₙ]\n (convTerm₂ [σFₙ] [σFₛₘ] [Fₙ≡Fₛₘ] natrecM′))\nnatrecTerm {F} {z} {s} {n} {Γ} {Δ} {σ} {l} [Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ]\n (ιx (ℕₜ .zero d n≡n zeroᵣ)) =\n let [ℕ] = ℕᵛ {l = l} [Γ]\n [σℕ] = proj₁ ([ℕ] ⊢Δ [σ])\n ⊢ℕ = escape (proj₁ ([ℕ] ⊢Δ [σ]))\n [σF] = proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ]))\n ⊢F = escape [σF]\n ⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)\n (escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))\n ⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)\n (escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))\n [σ0] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) [σℕ]\n (ιx (ℕₜ zero (idRedTerm:*: (zeroⱼ ⊢Δ)) n≡n zeroᵣ))\n [σn]′ , [σn≡σ0] = redSubst*Term (redₜ d) (proj₁ ([ℕ] ⊢Δ [σ])) [σ0]\n [σn] = ιx (ℕₜ zero d n≡n zeroᵣ)\n [σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , [σn]))\n [σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′\n [Fₙ≡F₀]′ = proj₂ ([F] ⊢Δ ([σ] , [σn])) ([σ] , [σ0])\n (reflSubst [Γ] ⊢Δ [σ] , [σn≡σ0])\n [Fₙ≡F₀] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.sym (substCompEq F))\n [σFₙ]′ [σFₙ] [Fₙ≡F₀]′\n [Fₙ≡F₀]″ = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.trans (substConcatSingleton′ F)\n (PE.sym (singleSubstComp zero σ F)))\n [σFₙ]′ [σFₙ] [Fₙ≡F₀]′\n [σz] = proj₁ ([z] ⊢Δ [σ])\n reduction = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) (proj₁ ([ℕ] ⊢Δ [σ])) [σ0]\n (λ {t} {t′} [t] [t′] [t≡t′] →\n PE.subst₂ (λ x y → _ ⊢ x ≡ y)\n (PE.sym (singleSubstComp t σ F))\n (PE.sym (singleSubstComp t′ σ F))\n (≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))\n (proj₂ ([F] ⊢Δ ([σ] , [t]))\n ([σ] , [t′])\n (reflSubst [Γ] ⊢Δ [σ] ,\n [t≡t′])))))\n ⇨∷* (conv* (natrec-zero ⊢F ⊢z ⊢s ⇨ id ⊢z)\n (sym (≅-eq (escapeEq [σFₙ] [Fₙ≡F₀]″))))\n in proj₁ (redSubst*Term reduction [σFₙ]\n (convTerm₂ [σFₙ] (proj₁ ([F₀] ⊢Δ [σ])) [Fₙ≡F₀] [σz]))\nnatrecTerm {F} {z} {s} {n} {Γ} {Δ} {σ} {l} [Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ]\n (ιx (ℕₜ m d n≡n (ne (neNfₜ neM ⊢m m≡m)))) =\n let [ℕ] = ℕᵛ {l = l} [Γ]\n [σℕ] = proj₁ ([ℕ] ⊢Δ [σ])\n ⊢ℕ = escape (proj₁ ([ℕ] ⊢Δ [σ]))\n [σn] = ιx (ℕₜ m d n≡n (ne (neNfₜ neM ⊢m m≡m)))\n [σF] = proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ]))\n ⊢F = escape [σF]\n ⊢F≡F = escapeEq [σF] (reflEq [σF])\n ⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)\n (escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))\n ⊢z≡z = PE.subst (λ x → _ ⊢ _ ≅ _ ∷ x) (singleSubstLift F zero)\n (escapeTermEq (proj₁ ([F₀] ⊢Δ [σ]))\n (reflEqTerm (proj₁ ([F₀] ⊢Δ [σ]))\n (proj₁ ([z] ⊢Δ [σ]))))\n ⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)\n (escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))\n ⊢s≡s = PE.subst (λ x → Δ ⊢ subst σ s ≅ subst σ s ∷ x) (natrecSucCase σ F)\n (escapeTermEq (proj₁ ([F₊] ⊢Δ [σ]))\n (reflEqTerm (proj₁ ([F₊] ⊢Δ [σ]))\n (proj₁ ([s] ⊢Δ [σ]))))\n [σm] = neuTerm [σℕ] neM ⊢m m≡m\n [σn]′ , [σn≡σm] = redSubst*Term (redₜ d) [σℕ] [σm]\n [σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , [σn]))\n [σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′\n [σFₘ] = irrelevance′ (PE.sym (singleSubstComp m σ F))\n (proj₁ ([F] ⊢Δ ([σ] , [σm])))\n [Fₙ≡Fₘ] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.sym (singleSubstComp m σ F)) [σFₙ]′ [σFₙ]\n ((proj₂ ([F] ⊢Δ ([σ] , [σn]))) ([σ] , [σm])\n (reflSubst [Γ] ⊢Δ [σ] , [σn≡σm]))\n natrecM = neuTerm [σFₘ] (natrecₙ neM) (natrecⱼ ⊢F ⊢z ⊢s ⊢m)\n (~-natrec ⊢F≡F ⊢z≡z ⊢s≡s m≡m)\n reduction = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) [σℕ] [σm]\n (λ {t} {t′} [t] [t′] [t≡t′] →\n PE.subst₂ (λ x y → _ ⊢ x ≡ y)\n (PE.sym (singleSubstComp t σ F))\n (PE.sym (singleSubstComp t′ σ F))\n (≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))\n (proj₂ ([F] ⊢Δ ([σ] , [t]))\n ([σ] , [t′])\n (reflSubst [Γ] ⊢Δ [σ] ,\n [t≡t′])))))\n in proj₁ (redSubst*Term reduction [σFₙ]\n (convTerm₂ [σFₙ] [σFₘ] [Fₙ≡Fₘ] natrecM))\n\n\n-- Reducibility of natural recursion congurence under a valid substitution equality.\nnatrec-congTerm : ∀ {F F′ z z′ s s′ n m Γ Δ σ σ′ l}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / _∙″_ {l = l} [Γ] (ℕᵛ [Γ]))\n ([F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F′ / _∙″_ {l = l} [Γ] (ℕᵛ [Γ]))\n ([F≡F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F ≡ F′ / _∙″_ {l = l} [Γ] (ℕᵛ [Γ])\n / [F])\n ([F₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] / [Γ])\n ([F′₀] : Γ ⊩ᵛ⟨ l ⟩ F′ [ zero ] / [Γ])\n ([F₀≡F′₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] ≡ F′ [ zero ] / [Γ] / [F₀])\n ([F₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)\n / [Γ])\n ([F′₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑)\n / [Γ])\n ([F₊≡F₊′] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)\n ≡ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑)\n / [Γ] / [F₊])\n ([z] : Γ ⊩ᵛ⟨ l ⟩ z ∷ F [ zero ] / [Γ] / [F₀])\n ([z′] : Γ ⊩ᵛ⟨ l ⟩ z′ ∷ F′ [ zero ] / [Γ] / [F′₀])\n ([z≡z′] : Γ ⊩ᵛ⟨ l ⟩ z ≡ z′ ∷ F [ zero ] / [Γ] / [F₀])\n ([s] : Γ ⊩ᵛ⟨ l ⟩ s ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)\n / [Γ] / [F₊])\n ([s′] : Γ ⊩ᵛ⟨ l ⟩ s′\n ∷ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑)\n / [Γ] / [F′₊])\n ([s≡s′] : Γ ⊩ᵛ⟨ l ⟩ s ≡ s′\n ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)\n / [Γ] / [F₊])\n (⊢Δ : ⊢ Δ)\n ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)\n ([σ′] : Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ)\n ([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ])\n ([σn] : Δ ⊩⟨ l ⟩ n ∷ ℕ / ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))\n ([σm] : Δ ⊩⟨ l ⟩ m ∷ ℕ / ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))\n ([σn≡σm] : Δ ⊩⟨ l ⟩ n ≡ m ∷ ℕ / ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))\n → Δ ⊩⟨ l ⟩ natrec (subst (liftSubst σ) F)\n (subst σ z) (subst σ s) n\n ≡ natrec (subst (liftSubst σ′) F′)\n (subst σ′ z′) (subst σ′ s′) m\n ∷ subst (liftSubst σ) F [ n ]\n / irrelevance′ (PE.sym (singleSubstComp n σ F))\n (proj₁ ([F] ⊢Δ ([σ] , [σn])))\nnatrec-congTerm {F} {F′} {z} {z′} {s} {s′} {n} {m} {Γ} {Δ} {σ} {σ′} {l}\n [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n (ιx (ℕₜ .(suc n′) d n≡n (sucᵣ {n′} [n′])))\n (ιx (ℕₜ .(suc m′) d′ m≡m (sucᵣ {m′} [m′])))\n (ιx (ℕₜ₌ .(suc n″) .(suc m″) d₁ d₁′\n t≡u (sucᵣ {n″} {m″} [n″≡m″]))) =\n let n″≡n′ = suc-PE-injectivity (whrDet*Term (redₜ d₁ , sucₙ) (redₜ d , sucₙ))\n m″≡m′ = suc-PE-injectivity (whrDet*Term (redₜ d₁′ , sucₙ) (redₜ d′ , sucₙ))\n [ℕ] = ℕᵛ {l = l} [Γ]\n [σℕ] = proj₁ ([ℕ] ⊢Δ [σ])\n [σ′ℕ] = proj₁ ([ℕ] ⊢Δ [σ′])\n [n′≡m′] = irrelevanceEqTerm″ n″≡n′ m″≡m′ PE.refl [σℕ] [σℕ] (ιx [n″≡m″])\n [σn] = ℕₜ (suc n′) d n≡n (sucᵣ [n′])\n [σ′m] = ℕₜ (suc m′) d′ m≡m (sucᵣ [m′])\n [σn≡σ′m] = ℕₜ₌ (suc n″) (suc m″) d₁ d₁′ t≡u (sucᵣ [n″≡m″])\n ⊢ℕ = escape [σℕ]\n ⊢F = escape (proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ])))\n ⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)\n (escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))\n ⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)\n (escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))\n ⊢n′ = escapeTerm {l = l} [σℕ] (ιx [n′])\n ⊢ℕ′ = escape [σ′ℕ]\n ⊢F′ = escape (proj₁ ([F′] (⊢Δ ∙ ⊢ℕ′)\n (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′])))\n ⊢z′ = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F′ zero)\n (escapeTerm (proj₁ ([F′₀] ⊢Δ [σ′]))\n (proj₁ ([z′] ⊢Δ [σ′])))\n ⊢s′ = PE.subst (λ x → Δ ⊢ subst σ′ s′ ∷ x) (natrecSucCase σ′ F′)\n (escapeTerm (proj₁ ([F′₊] ⊢Δ [σ′]))\n (proj₁ ([s′] ⊢Δ [σ′])))\n ⊢m′ = escapeTerm {l = l} [σ′ℕ] (ιx [m′])\n [σsn′] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) [σℕ]\n (ιx (ℕₜ (suc n′) (idRedTerm:*: (sucⱼ ⊢n′)) n≡n (sucᵣ [n′])))\n [σn]′ , [σn≡σsn′] = redSubst*Term (redₜ d) [σℕ] [σsn′]\n [σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , ιx [σn]))\n [σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′\n [σFₛₙ′] = irrelevance′ (PE.sym (singleSubstComp (suc n′) σ F))\n (proj₁ ([F] ⊢Δ ([σ] , [σsn′])))\n [Fₙ≡Fₛₙ′] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.sym (singleSubstComp (suc n′) σ F))\n [σFₙ]′ [σFₙ]\n (proj₂ ([F] ⊢Δ ([σ] , ιx [σn])) ([σ] , [σsn′])\n (reflSubst [Γ] ⊢Δ [σ] , [σn≡σsn′]))\n [Fₙ≡Fₛₙ′]′ = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (natrecIrrelevantSubst F z s n′ σ)\n [σFₙ]′ [σFₙ]\n (proj₂ ([F] ⊢Δ ([σ] , ιx [σn])) ([σ] , [σsn′])\n (reflSubst [Γ] ⊢Δ [σ] , [σn≡σsn′]))\n [σFₙ′] = irrelevance′ (PE.sym (PE.trans (substCompEq F)\n (substSingletonComp F)))\n (proj₁ ([F] ⊢Δ ([σ] , ιx [n′])))\n [σFₛₙ′]′ = irrelevance′ (natrecIrrelevantSubst F z s n′ σ)\n (proj₁ ([F] ⊢Δ ([σ] , [σsn′])))\n [σF₊ₙ′] = substSΠ₁ (proj₁ ([F₊] ⊢Δ [σ])) [σℕ] (ιx [n′])\n [σ′sm′] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) [σ′ℕ]\n (ιx (ℕₜ (suc m′) (idRedTerm:*: (sucⱼ ⊢m′)) m≡m (sucᵣ [m′])))\n [σ′m]′ , [σ′m≡σ′sm′] = redSubst*Term (redₜ d′) [σ′ℕ] [σ′sm′]\n [σ′F′ₘ]′ = proj₁ ([F′] ⊢Δ ([σ′] , ιx [σ′m]))\n [σ′F′ₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F′)) [σ′F′ₘ]′\n [σ′Fₘ]′ = proj₁ ([F] ⊢Δ ([σ′] , ιx [σ′m]))\n [σ′Fₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F)) [σ′Fₘ]′\n [σ′F′ₛₘ′] = irrelevance′ (PE.sym (singleSubstComp (suc m′) σ′ F′))\n (proj₁ ([F′] ⊢Δ ([σ′] , [σ′sm′])))\n [F′ₘ≡F′ₛₘ′] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F′))\n (PE.sym (singleSubstComp (suc m′) σ′ F′))\n [σ′F′ₘ]′ [σ′F′ₘ]\n (proj₂ ([F′] ⊢Δ ([σ′] , ιx [σ′m]))\n ([σ′] , [σ′sm′])\n (reflSubst [Γ] ⊢Δ [σ′] , [σ′m≡σ′sm′]))\n [σ′Fₘ′] = irrelevance′ (PE.sym (PE.trans (substCompEq F)\n (substSingletonComp F)))\n (proj₁ ([F] ⊢Δ ([σ′] , ιx [m′])))\n [σ′F′ₘ′] = irrelevance′ (PE.sym (PE.trans (substCompEq F′)\n (substSingletonComp F′)))\n (proj₁ ([F′] ⊢Δ ([σ′] , ιx [m′])))\n [σ′F′ₛₘ′]′ = irrelevance′ (natrecIrrelevantSubst F′ z′ s′ m′ σ′)\n (proj₁ ([F′] ⊢Δ ([σ′] , [σ′sm′])))\n [σ′F′₊ₘ′] = substSΠ₁ (proj₁ ([F′₊] ⊢Δ [σ′])) [σ′ℕ] (ιx [m′])\n [σFₙ′≡σ′Fₘ′] = irrelevanceEq″ (PE.sym (singleSubstComp n′ σ F))\n (PE.sym (singleSubstComp m′ σ′ F))\n (proj₁ ([F] ⊢Δ ([σ] , ιx [n′]))) [σFₙ′]\n (proj₂ ([F] ⊢Δ ([σ] , ιx [n′]))\n ([σ′] , ιx [m′]) ([σ≡σ′] , [n′≡m′]))\n [σ′Fₘ′≡σ′F′ₘ′] = irrelevanceEq″ (PE.sym (singleSubstComp m′ σ′ F))\n (PE.sym (singleSubstComp m′ σ′ F′))\n (proj₁ ([F] ⊢Δ ([σ′] , ιx [m′])))\n [σ′Fₘ′] ([F≡F′] ⊢Δ ([σ′] , ιx [m′]))\n [σFₙ′≡σ′F′ₘ′] = transEq [σFₙ′] [σ′Fₘ′] [σ′F′ₘ′] [σFₙ′≡σ′Fₘ′] [σ′Fₘ′≡σ′F′ₘ′]\n [σFₙ≡σ′Fₘ] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.sym (singleSubstComp m σ′ F))\n (proj₁ ([F] ⊢Δ ([σ] , ιx [σn]))) [σFₙ]\n (proj₂ ([F] ⊢Δ ([σ] , ιx [σn]))\n ([σ′] , ιx [σ′m]) ([σ≡σ′] , ιx [σn≡σ′m]))\n [σ′Fₘ≡σ′F′ₘ] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F))\n (PE.sym (singleSubstComp m σ′ F′))\n [σ′Fₘ]′ [σ′Fₘ] ([F≡F′] ⊢Δ ([σ′] , ιx [σ′m]))\n [σFₙ≡σ′F′ₘ] = transEq [σFₙ] [σ′Fₘ] [σ′F′ₘ] [σFₙ≡σ′Fₘ] [σ′Fₘ≡σ′F′ₘ]\n natrecN = appTerm [σFₙ′] [σFₛₙ′]′ [σF₊ₙ′]\n (appTerm [σℕ] [σF₊ₙ′] (proj₁ ([F₊] ⊢Δ [σ]))\n (proj₁ ([s] ⊢Δ [σ])) (ιx [n′]))\n (natrecTerm {F} {z} {s} {n′} {σ = σ}\n [Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ] (ιx [n′]))\n natrecN′ = irrelevanceTerm′ (PE.trans (PE.sym (natrecIrrelevantSubst F z s n′ σ))\n (PE.sym (singleSubstComp (suc n′) σ F)))\n [σFₛₙ′]′ [σFₛₙ′] natrecN\n natrecM = appTerm [σ′F′ₘ′] [σ′F′ₛₘ′]′ [σ′F′₊ₘ′]\n (appTerm [σ′ℕ] [σ′F′₊ₘ′] (proj₁ ([F′₊] ⊢Δ [σ′]))\n (proj₁ ([s′] ⊢Δ [σ′])) (ιx [m′]))\n (natrecTerm {F′} {z′} {s′} {m′} {σ = σ′}\n [Γ] [F′] [F′₀] [F′₊] [z′] [s′] ⊢Δ [σ′] (ιx [m′]))\n natrecM′ = irrelevanceTerm′ (PE.trans (PE.sym (natrecIrrelevantSubst F′ z′ s′ m′ σ′))\n (PE.sym (singleSubstComp (suc m′) σ′ F′)))\n [σ′F′ₛₘ′]′ [σ′F′ₛₘ′] natrecM\n [σs≡σ′s] = proj₂ ([s] ⊢Δ [σ]) [σ′] [σ≡σ′]\n [σ′s≡σ′s′] = convEqTerm₂ (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([F₊] ⊢Δ [σ′]))\n (proj₂ ([F₊] ⊢Δ [σ]) [σ′] [σ≡σ′]) ([s≡s′] ⊢Δ [σ′])\n [σs≡σ′s′] = transEqTerm (proj₁ ([F₊] ⊢Δ [σ])) [σs≡σ′s] [σ′s≡σ′s′]\n appEq = convEqTerm₂ [σFₙ] [σFₛₙ′]′ [Fₙ≡Fₛₙ′]′\n (app-congTerm [σFₙ′] [σFₛₙ′]′ [σF₊ₙ′]\n (app-congTerm [σℕ] [σF₊ₙ′] (proj₁ ([F₊] ⊢Δ [σ])) [σs≡σ′s′]\n (ιx [n′]) (ιx [m′]) [n′≡m′])\n (natrecTerm {F} {z} {s} {n′} {σ = σ}\n [Γ] [F] [F₀] [F₊] [z] [s] ⊢Δ [σ] (ιx [n′]))\n (convTerm₂ [σFₙ′] [σ′F′ₘ′] [σFₙ′≡σ′F′ₘ′]\n (natrecTerm {F′} {z′} {s′} {m′} {σ = σ′}\n [Γ] [F′] [F′₀] [F′₊] [z′] [s′]\n ⊢Δ [σ′] (ιx [m′])))\n (natrec-congTerm {F} {F′} {z} {z′} {s} {s′} {n′} {m′} {σ = σ}\n [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀]\n [F₊] [F′₊] [F₊≡F′₊] [z] [z′] [z≡z′]\n [s] [s′] [s≡s′]\n ⊢Δ [σ] [σ′] [σ≡σ′] (ιx [n′]) (ιx [m′]) [n′≡m′]))\n reduction₁ = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) [σℕ] [σsn′]\n (λ {t} {t′} [t] [t′] [t≡t′] →\n PE.subst₂ (λ x y → _ ⊢ x ≡ y)\n (PE.sym (singleSubstComp t σ F))\n (PE.sym (singleSubstComp t′ σ F))\n (≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))\n (proj₂ ([F] ⊢Δ ([σ] , [t]))\n ([σ] , [t′])\n (reflSubst [Γ] ⊢Δ [σ] , [t≡t′])))))\n ⇨∷* (conv* (natrec-suc ⊢n′ ⊢F ⊢z ⊢s\n ⇨ id (escapeTerm [σFₛₙ′] natrecN′))\n (sym (≅-eq (escapeEq [σFₙ] [Fₙ≡Fₛₙ′]))))\n reduction₂ = natrec-subst* ⊢F′ ⊢z′ ⊢s′ (redₜ d′) [σ′ℕ] [σ′sm′]\n (λ {t} {t′} [t] [t′] [t≡t′] →\n PE.subst₂ (λ x y → _ ⊢ x ≡ y)\n (PE.sym (singleSubstComp t σ′ F′))\n (PE.sym (singleSubstComp t′ σ′ F′))\n (≅-eq (escapeEq (proj₁ ([F′] ⊢Δ ([σ′] , [t])))\n (proj₂ ([F′] ⊢Δ ([σ′] , [t]))\n ([σ′] , [t′])\n (reflSubst [Γ] ⊢Δ [σ′] , [t≡t′])))))\n ⇨∷* (conv* (natrec-suc ⊢m′ ⊢F′ ⊢z′ ⊢s′\n ⇨ id (escapeTerm [σ′F′ₛₘ′] natrecM′))\n (sym (≅-eq (escapeEq [σ′F′ₘ] [F′ₘ≡F′ₛₘ′]))))\n eq₁ = proj₂ (redSubst*Term reduction₁ [σFₙ]\n (convTerm₂ [σFₙ] [σFₛₙ′]\n [Fₙ≡Fₛₙ′] natrecN′))\n eq₂ = proj₂ (redSubst*Term reduction₂ [σ′F′ₘ]\n (convTerm₂ [σ′F′ₘ] [σ′F′ₛₘ′]\n [F′ₘ≡F′ₛₘ′] natrecM′))\n in transEqTerm [σFₙ] eq₁\n (transEqTerm [σFₙ] appEq\n (convEqTerm₂ [σFₙ] [σ′F′ₘ] [σFₙ≡σ′F′ₘ]\n (symEqTerm [σ′F′ₘ] eq₂)))\nnatrec-congTerm {F} {F′} {z} {z′} {s} {s′} {n} {m} {Γ} {Δ} {σ} {σ′} {l}\n [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n (ιx (ℕₜ .zero d n≡n zeroᵣ)) (ιx (ℕₜ .zero d₁ m≡m zeroᵣ))\n (ιx (ℕₜ₌ .zero .zero d₂ d′ t≡u zeroᵣ)) =\n let [ℕ] = ℕᵛ {l = l} [Γ]\n [σℕ] = proj₁ ([ℕ] ⊢Δ [σ])\n ⊢ℕ = escape (proj₁ ([ℕ] ⊢Δ [σ]))\n ⊢F = escape (proj₁ ([F] {σ = liftSubst σ} (⊢Δ ∙ ⊢ℕ)\n (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ])))\n ⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)\n (escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))\n ⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)\n (escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))\n ⊢F′ = escape (proj₁ ([F′] {σ = liftSubst σ′} (⊢Δ ∙ ⊢ℕ)\n (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′])))\n ⊢z′ = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F′ zero)\n (escapeTerm (proj₁ ([F′₀] ⊢Δ [σ′])) (proj₁ ([z′] ⊢Δ [σ′])))\n ⊢s′ = PE.subst (λ x → Δ ⊢ subst σ′ s′ ∷ x) (natrecSucCase σ′ F′)\n (escapeTerm (proj₁ ([F′₊] ⊢Δ [σ′])) (proj₁ ([s′] ⊢Δ [σ′])))\n [σ0] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) (proj₁ ([ℕ] ⊢Δ [σ]))\n (ιx (ℕₜ zero (idRedTerm:*: (zeroⱼ ⊢Δ)) n≡n zeroᵣ))\n [σ′0] = irrelevanceTerm {l = l} (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) (proj₁ ([ℕ] ⊢Δ [σ′]))\n (ιx (ℕₜ zero (idRedTerm:*: (zeroⱼ ⊢Δ)) m≡m zeroᵣ))\n [σn]′ , [σn≡σ0] = redSubst*Term (redₜ d) (proj₁ ([ℕ] ⊢Δ [σ])) [σ0]\n [σ′m]′ , [σ′m≡σ′0] = redSubst*Term (redₜ d′) (proj₁ ([ℕ] ⊢Δ [σ′])) [σ′0]\n [σn] = ιx (ℕₜ zero d n≡n zeroᵣ)\n [σ′m] = ιx (ℕₜ zero d′ m≡m zeroᵣ)\n [σn≡σ′m] = ιx (ℕₜ₌ zero zero d₂ d′ t≡u zeroᵣ)\n [σn≡σ′0] = transEqTerm [σℕ] [σn≡σ′m] [σ′m≡σ′0]\n [σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , [σn]))\n [σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′\n [σ′Fₘ]′ = proj₁ ([F] ⊢Δ ([σ′] , [σ′m]))\n [σ′Fₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F)) [σ′Fₘ]′\n [σ′F′ₘ]′ = proj₁ ([F′] ⊢Δ ([σ′] , [σ′m]))\n [σ′F′ₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F′)) [σ′F′ₘ]′\n [σFₙ≡σ′Fₘ] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.sym (singleSubstComp m σ′ F))\n [σFₙ]′ [σFₙ]\n (proj₂ ([F] ⊢Δ ([σ] , [σn])) ([σ′] , [σ′m])\n ([σ≡σ′] , [σn≡σ′m]))\n [σ′Fₘ≡σ′F′ₘ] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F))\n (PE.sym (singleSubstComp m σ′ F′))\n [σ′Fₘ]′ [σ′Fₘ] ([F≡F′] ⊢Δ ([σ′] , [σ′m]))\n [σFₙ≡σ′F′ₘ] = transEq [σFₙ] [σ′Fₘ] [σ′F′ₘ] [σFₙ≡σ′Fₘ] [σ′Fₘ≡σ′F′ₘ]\n [Fₙ≡F₀]′ = proj₂ ([F] ⊢Δ ([σ] , [σn])) ([σ] , [σ0]) (reflSubst [Γ] ⊢Δ [σ] , [σn≡σ0])\n [Fₙ≡F₀] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.sym (substCompEq F))\n [σFₙ]′ [σFₙ] [Fₙ≡F₀]′\n [σFₙ≡σ′F₀]′ = proj₂ ([F] ⊢Δ ([σ] , [σn])) ([σ′] , [σ′0]) ([σ≡σ′] , [σn≡σ′0])\n [σFₙ≡σ′F₀] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.sym (substCompEq F))\n [σFₙ]′ [σFₙ] [σFₙ≡σ′F₀]′\n [F′ₘ≡F′₀]′ = proj₂ ([F′] ⊢Δ ([σ′] , [σ′m])) ([σ′] , [σ′0])\n (reflSubst [Γ] ⊢Δ [σ′] , [σ′m≡σ′0])\n [F′ₘ≡F′₀] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F′))\n (PE.sym (substCompEq F′))\n [σ′F′ₘ]′ [σ′F′ₘ] [F′ₘ≡F′₀]′\n [Fₙ≡F₀]″ = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.trans (substConcatSingleton′ F)\n (PE.sym (singleSubstComp zero σ F)))\n [σFₙ]′ [σFₙ] [Fₙ≡F₀]′\n [F′ₘ≡F′₀]″ = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F′))\n (PE.trans (substConcatSingleton′ F′)\n (PE.sym (singleSubstComp zero σ′ F′)))\n [σ′F′ₘ]′ [σ′F′ₘ] [F′ₘ≡F′₀]′\n [σz] = proj₁ ([z] ⊢Δ [σ])\n [σ′z′] = proj₁ ([z′] ⊢Δ [σ′])\n [σz≡σ′z] = convEqTerm₂ [σFₙ] (proj₁ ([F₀] ⊢Δ [σ])) [Fₙ≡F₀]\n (proj₂ ([z] ⊢Δ [σ]) [σ′] [σ≡σ′])\n [σ′z≡σ′z′] = convEqTerm₂ [σFₙ] (proj₁ ([F₀] ⊢Δ [σ′])) [σFₙ≡σ′F₀]\n ([z≡z′] ⊢Δ [σ′])\n [σz≡σ′z′] = transEqTerm [σFₙ] [σz≡σ′z] [σ′z≡σ′z′]\n reduction₁ = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) (proj₁ ([ℕ] ⊢Δ [σ])) [σ0]\n (λ {t} {t′} [t] [t′] [t≡t′] →\n PE.subst₂ (λ x y → _ ⊢ x ≡ y)\n (PE.sym (singleSubstComp t σ F))\n (PE.sym (singleSubstComp t′ σ F))\n (≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))\n (proj₂ ([F] ⊢Δ ([σ] , [t]))\n ([σ] , [t′])\n (reflSubst [Γ] ⊢Δ [σ] , [t≡t′])))))\n ⇨∷* (conv* (natrec-zero ⊢F ⊢z ⊢s ⇨ id ⊢z)\n (sym (≅-eq (escapeEq [σFₙ] [Fₙ≡F₀]″))))\n reduction₂ = natrec-subst* ⊢F′ ⊢z′ ⊢s′ (redₜ d′) (proj₁ ([ℕ] ⊢Δ [σ′])) [σ′0]\n (λ {t} {t′} [t] [t′] [t≡t′] →\n PE.subst₂ (λ x y → _ ⊢ x ≡ y)\n (PE.sym (singleSubstComp t σ′ F′))\n (PE.sym (singleSubstComp t′ σ′ F′))\n (≅-eq (escapeEq (proj₁ ([F′] ⊢Δ ([σ′] , [t])))\n (proj₂ ([F′] ⊢Δ ([σ′] , [t]))\n ([σ′] , [t′])\n (reflSubst [Γ] ⊢Δ [σ′] , [t≡t′])))))\n ⇨∷* (conv* (natrec-zero ⊢F′ ⊢z′ ⊢s′ ⇨ id ⊢z′)\n (sym (≅-eq (escapeEq [σ′F′ₘ] [F′ₘ≡F′₀]″))))\n eq₁ = proj₂ (redSubst*Term reduction₁ [σFₙ]\n (convTerm₂ [σFₙ] (proj₁ ([F₀] ⊢Δ [σ]))\n [Fₙ≡F₀] [σz]))\n eq₂ = proj₂ (redSubst*Term reduction₂ [σ′F′ₘ]\n (convTerm₂ [σ′F′ₘ] (proj₁ ([F′₀] ⊢Δ [σ′]))\n [F′ₘ≡F′₀] [σ′z′]))\n in transEqTerm [σFₙ] eq₁\n (transEqTerm [σFₙ] [σz≡σ′z′]\n (convEqTerm₂ [σFₙ] [σ′F′ₘ] [σFₙ≡σ′F′ₘ]\n (symEqTerm [σ′F′ₘ] eq₂)))\nnatrec-congTerm {F} {F′} {z} {z′} {s} {s′} {n} {m} {Γ} {Δ} {σ} {σ′} {l}\n [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n (ιx (ℕₜ n′ d n≡n (ne (neNfₜ neN′ ⊢n′ n≡n₁))))\n (ιx (ℕₜ m′ d′ m≡m (ne (neNfₜ neM′ ⊢m′ m≡m₁))))\n (ιx (ℕₜ₌ n″ m″ d₁ d₁′ t≡u (ne (neNfₜ₌ x₂ x₃ prop₂)))) =\n let n″≡n′ = whrDet*Term (redₜ d₁ , ne x₂) (redₜ d , ne neN′)\n m″≡m′ = whrDet*Term (redₜ d₁′ , ne x₃) (redₜ d′ , ne neM′)\n [ℕ] = ℕᵛ {l = l} [Γ]\n [σℕ] = proj₁ ([ℕ] ⊢Δ [σ])\n [σ′ℕ] = proj₁ ([ℕ] ⊢Δ [σ′])\n [σn] = ℕₜ n′ d n≡n (ne (neNfₜ neN′ ⊢n′ n≡n₁))\n [σ′m] = ℕₜ m′ d′ m≡m (ne (neNfₜ neM′ ⊢m′ m≡m₁))\n [σn≡σ′m] = ℕₜ₌ n″ m″ d₁ d₁′ t≡u (ne (neNfₜ₌ x₂ x₃ prop₂))\n ⊢ℕ = escape (proj₁ ([ℕ] ⊢Δ [σ]))\n [σF] = proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ]))\n [σ′F] = proj₁ ([F] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′]))\n [σ′F′] = proj₁ ([F′] (⊢Δ ∙ ⊢ℕ) (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′]))\n ⊢F = escape [σF]\n ⊢F≡F = escapeEq [σF] (reflEq [σF])\n ⊢z = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F zero)\n (escapeTerm (proj₁ ([F₀] ⊢Δ [σ])) (proj₁ ([z] ⊢Δ [σ])))\n ⊢z≡z = PE.subst (λ x → _ ⊢ _ ≅ _ ∷ x) (singleSubstLift F zero)\n (escapeTermEq (proj₁ ([F₀] ⊢Δ [σ]))\n (reflEqTerm (proj₁ ([F₀] ⊢Δ [σ]))\n (proj₁ ([z] ⊢Δ [σ]))))\n ⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x) (natrecSucCase σ F)\n (escapeTerm (proj₁ ([F₊] ⊢Δ [σ])) (proj₁ ([s] ⊢Δ [σ])))\n ⊢s≡s = PE.subst (λ x → Δ ⊢ subst σ s ≅ subst σ s ∷ x) (natrecSucCase σ F)\n (escapeTermEq (proj₁ ([F₊] ⊢Δ [σ]))\n (reflEqTerm (proj₁ ([F₊] ⊢Δ [σ]))\n (proj₁ ([s] ⊢Δ [σ]))))\n ⊢F′ = escape [σ′F′]\n ⊢F′≡F′ = escapeEq [σ′F′] (reflEq [σ′F′])\n ⊢z′ = PE.subst (λ x → _ ⊢ _ ∷ x) (singleSubstLift F′ zero)\n (escapeTerm (proj₁ ([F′₀] ⊢Δ [σ′])) (proj₁ ([z′] ⊢Δ [σ′])))\n ⊢z′≡z′ = PE.subst (λ x → _ ⊢ _ ≅ _ ∷ x) (singleSubstLift F′ zero)\n (escapeTermEq (proj₁ ([F′₀] ⊢Δ [σ′]))\n (reflEqTerm (proj₁ ([F′₀] ⊢Δ [σ′]))\n (proj₁ ([z′] ⊢Δ [σ′]))))\n ⊢s′ = PE.subst (λ x → Δ ⊢ subst σ′ s′ ∷ x) (natrecSucCase σ′ F′)\n (escapeTerm (proj₁ ([F′₊] ⊢Δ [σ′])) (proj₁ ([s′] ⊢Δ [σ′])))\n ⊢s′≡s′ = PE.subst (λ x → Δ ⊢ subst σ′ s′ ≅ subst σ′ s′ ∷ x) (natrecSucCase σ′ F′)\n (escapeTermEq (proj₁ ([F′₊] ⊢Δ [σ′]))\n (reflEqTerm (proj₁ ([F′₊] ⊢Δ [σ′]))\n (proj₁ ([s′] ⊢Δ [σ′]))))\n ⊢σF≡σ′F = escapeEq [σF] (proj₂ ([F] {σ = liftSubst σ} (⊢Δ ∙ ⊢ℕ)\n (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ]))\n {σ′ = liftSubst σ′}\n (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′])\n (liftSubstSEq {F = ℕ} [Γ] ⊢Δ [ℕ] [σ] [σ≡σ′]))\n ⊢σz≡σ′z = PE.subst (λ x → _ ⊢ _ ≅ _ ∷ x) (singleSubstLift F zero)\n (escapeTermEq (proj₁ ([F₀] ⊢Δ [σ]))\n (proj₂ ([z] ⊢Δ [σ]) [σ′] [σ≡σ′]))\n ⊢σs≡σ′s = PE.subst (λ x → Δ ⊢ subst σ s ≅ subst σ′ s ∷ x)\n (natrecSucCase σ F)\n (escapeTermEq (proj₁ ([F₊] ⊢Δ [σ]))\n (proj₂ ([s] ⊢Δ [σ]) [σ′] [σ≡σ′]))\n ⊢σ′F≡⊢σ′F′ = escapeEq [σ′F] ([F≡F′] (⊢Δ ∙ ⊢ℕ)\n (liftSubstS {F = ℕ} [Γ] ⊢Δ [ℕ] [σ′]))\n ⊢σ′z≡⊢σ′z′ = PE.subst (λ x → _ ⊢ _ ≅ _ ∷ x)\n (singleSubstLift F zero)\n (≅-conv (escapeTermEq (proj₁ ([F₀] ⊢Δ [σ′]))\n ([z≡z′] ⊢Δ [σ′]))\n (sym (≅-eq (escapeEq (proj₁ ([F₀] ⊢Δ [σ]))\n (proj₂ ([F₀] ⊢Δ [σ]) [σ′] [σ≡σ′])))))\n ⊢σ′s≡⊢σ′s′ = PE.subst (λ x → Δ ⊢ subst σ′ s ≅ subst σ′ s′ ∷ x)\n (natrecSucCase σ F)\n (≅-conv (escapeTermEq (proj₁ ([F₊] ⊢Δ [σ′]))\n ([s≡s′] ⊢Δ [σ′]))\n (sym (≅-eq (escapeEq (proj₁ ([F₊] ⊢Δ [σ]))\n (proj₂ ([F₊] ⊢Δ [σ]) [σ′] [σ≡σ′])))))\n ⊢F≡F′ = ≅-trans ⊢σF≡σ′F ⊢σ′F≡⊢σ′F′\n ⊢z≡z′ = ≅ₜ-trans ⊢σz≡σ′z ⊢σ′z≡⊢σ′z′\n ⊢s≡s′ = ≅ₜ-trans ⊢σs≡σ′s ⊢σ′s≡⊢σ′s′\n [σn′] = neuTerm [σℕ] neN′ ⊢n′ n≡n₁\n [σn]′ , [σn≡σn′] = redSubst*Term (redₜ d) [σℕ] [σn′]\n [σFₙ]′ = proj₁ ([F] ⊢Δ ([σ] , ιx [σn]))\n [σFₙ] = irrelevance′ (PE.sym (singleSubstComp n σ F)) [σFₙ]′\n [σFₙ′] = irrelevance′ (PE.sym (singleSubstComp n′ σ F))\n (proj₁ ([F] ⊢Δ ([σ] , [σn′])))\n [Fₙ≡Fₙ′] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.sym (singleSubstComp n′ σ F)) [σFₙ]′ [σFₙ]\n ((proj₂ ([F] ⊢Δ ([σ] , ιx [σn])))\n ([σ] , [σn′])\n (reflSubst [Γ] ⊢Δ [σ] , [σn≡σn′]))\n [σ′m′] = neuTerm [σ′ℕ] neM′ ⊢m′ m≡m₁\n [σ′m]′ , [σ′m≡σ′m′] = redSubst*Term (redₜ d′) [σ′ℕ] [σ′m′]\n [σ′F′ₘ]′ = proj₁ ([F′] ⊢Δ ([σ′] , ιx [σ′m]))\n [σ′F′ₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F′)) [σ′F′ₘ]′\n [σ′Fₘ]′ = proj₁ ([F] ⊢Δ ([σ′] , ιx [σ′m]))\n [σ′Fₘ] = irrelevance′ (PE.sym (singleSubstComp m σ′ F)) [σ′Fₘ]′\n [σ′F′ₘ′] = irrelevance′ (PE.sym (singleSubstComp m′ σ′ F′))\n (proj₁ ([F′] ⊢Δ ([σ′] , [σ′m′])))\n [F′ₘ≡F′ₘ′] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F′))\n (PE.sym (singleSubstComp m′ σ′ F′))\n [σ′F′ₘ]′ [σ′F′ₘ]\n ((proj₂ ([F′] ⊢Δ ([σ′] , ιx [σ′m])))\n ([σ′] , [σ′m′])\n (reflSubst [Γ] ⊢Δ [σ′] , [σ′m≡σ′m′]))\n [σFₙ≡σ′Fₘ] = irrelevanceEq″ (PE.sym (singleSubstComp n σ F))\n (PE.sym (singleSubstComp m σ′ F))\n [σFₙ]′ [σFₙ]\n (proj₂ ([F] ⊢Δ ([σ] , ιx [σn])) ([σ′] , ιx [σ′m])\n ([σ≡σ′] , ιx [σn≡σ′m]))\n [σ′Fₘ≡σ′F′ₘ] = irrelevanceEq″ (PE.sym (singleSubstComp m σ′ F))\n (PE.sym (singleSubstComp m σ′ F′))\n (proj₁ ([F] ⊢Δ ([σ′] , ιx [σ′m])))\n [σ′Fₘ] ([F≡F′] ⊢Δ ([σ′] , ιx [σ′m]))\n [σFₙ≡σ′F′ₘ] = transEq [σFₙ] [σ′Fₘ] [σ′F′ₘ] [σFₙ≡σ′Fₘ] [σ′Fₘ≡σ′F′ₘ]\n [σFₙ′≡σ′Fₘ′] = transEq [σFₙ′] [σFₙ] [σ′F′ₘ′] (symEq [σFₙ] [σFₙ′] [Fₙ≡Fₙ′])\n (transEq [σFₙ] [σ′F′ₘ] [σ′F′ₘ′] [σFₙ≡σ′F′ₘ] [F′ₘ≡F′ₘ′])\n natrecN = neuTerm [σFₙ′] (natrecₙ neN′) (natrecⱼ ⊢F ⊢z ⊢s ⊢n′)\n (~-natrec ⊢F≡F ⊢z≡z ⊢s≡s n≡n₁)\n natrecM = neuTerm [σ′F′ₘ′] (natrecₙ neM′) (natrecⱼ ⊢F′ ⊢z′ ⊢s′ ⊢m′)\n (~-natrec ⊢F′≡F′ ⊢z′≡z′ ⊢s′≡s′ m≡m₁)\n natrecN≡M =\n convEqTerm₂ [σFₙ] [σFₙ′] [Fₙ≡Fₙ′]\n (neuEqTerm [σFₙ′] (natrecₙ neN′) (natrecₙ neM′)\n (natrecⱼ ⊢F ⊢z ⊢s ⊢n′)\n (conv (natrecⱼ ⊢F′ ⊢z′ ⊢s′ ⊢m′)\n (sym (≅-eq (escapeEq [σFₙ′] [σFₙ′≡σ′Fₘ′]))))\n (~-natrec ⊢F≡F′ ⊢z≡z′ ⊢s≡s′\n (PE.subst₂ (λ x y → _ ⊢ x ~ y ∷ _)\n n″≡n′ m″≡m′ prop₂)))\n reduction₁ = natrec-subst* ⊢F ⊢z ⊢s (redₜ d) [σℕ] [σn′]\n (λ {t} {t′} [t] [t′] [t≡t′] →\n PE.subst₂ (λ x y → _ ⊢ x ≡ y)\n (PE.sym (singleSubstComp t σ F))\n (PE.sym (singleSubstComp t′ σ F))\n (≅-eq (escapeEq (proj₁ ([F] ⊢Δ ([σ] , [t])))\n (proj₂ ([F] ⊢Δ ([σ] , [t]))\n ([σ] , [t′])\n (reflSubst [Γ] ⊢Δ [σ] , [t≡t′])))))\n reduction₂ = natrec-subst* ⊢F′ ⊢z′ ⊢s′ (redₜ d′) [σ′ℕ] [σ′m′]\n (λ {t} {t′} [t] [t′] [t≡t′] →\n PE.subst₂ (λ x y → _ ⊢ x ≡ y)\n (PE.sym (singleSubstComp t σ′ F′))\n (PE.sym (singleSubstComp t′ σ′ F′))\n (≅-eq (escapeEq (proj₁ ([F′] ⊢Δ ([σ′] , [t])))\n (proj₂ ([F′] ⊢Δ ([σ′] , [t]))\n ([σ′] , [t′])\n (reflSubst [Γ] ⊢Δ [σ′] , [t≡t′])))))\n eq₁ = proj₂ (redSubst*Term reduction₁ [σFₙ]\n (convTerm₂ [σFₙ] [σFₙ′] [Fₙ≡Fₙ′] natrecN))\n eq₂ = proj₂ (redSubst*Term reduction₂ [σ′F′ₘ]\n (convTerm₂ [σ′F′ₘ] [σ′F′ₘ′] [F′ₘ≡F′ₘ′] natrecM))\n in transEqTerm [σFₙ] eq₁\n (transEqTerm [σFₙ] natrecN≡M\n (convEqTerm₂ [σFₙ] [σ′F′ₘ] [σFₙ≡σ′F′ₘ]\n (symEqTerm [σ′F′ₘ] eq₂)))\n-- Refuting cases\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n [σn] (ιx (ℕₜ _ d₁ _ zeroᵣ))\n (ιx (ℕₜ₌ _ _ d₂ d′ t≡u (sucᵣ prop₂))) =\n ⊥-elim (zero≢suc (whrDet*Term (redₜ d₁ , zeroₙ) (redₜ d′ , sucₙ)))\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n [σn] (ιx (ℕₜ n d₁ _ (ne (neNfₜ neK ⊢k k≡k))))\n (ιx (ℕₜ₌ _ _ d₂ d′ t≡u (sucᵣ prop₂))) =\n ⊥-elim (suc≢ne neK (whrDet*Term (redₜ d′ , sucₙ) (redₜ d₁ , ne neK)))\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n (ιx (ℕₜ _ d _ zeroᵣ)) [σm]\n (ιx (ℕₜ₌ _ _ d₁ d′ t≡u (sucᵣ prop₂))) =\n ⊥-elim (zero≢suc (whrDet*Term (redₜ d , zeroₙ) (redₜ d₁ , sucₙ)))\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n (ιx (ℕₜ n d _ (ne (neNfₜ neK ⊢k k≡k)))) [σm]\n (ιx (ℕₜ₌ _ _ d₁ d′ t≡u (sucᵣ prop₂))) =\n ⊥-elim (suc≢ne neK (whrDet*Term (redₜ d₁ , sucₙ) (redₜ d , ne neK)))\n\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n (ιx (ℕₜ _ d _ (sucᵣ prop))) [σm]\n (ιx (ℕₜ₌ _ _ d₂ d′ t≡u zeroᵣ)) =\n ⊥-elim (zero≢suc (whrDet*Term (redₜ d₂ , zeroₙ) (redₜ d , sucₙ)))\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n [σn] (ιx (ℕₜ _ d₁ _ (sucᵣ prop₁)))\n (ιx (ℕₜ₌ _ _ d₂ d′ t≡u zeroᵣ)) =\n ⊥-elim (zero≢suc (whrDet*Term (redₜ d′ , zeroₙ) (redₜ d₁ , sucₙ)))\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n [σn] (ιx (ℕₜ n d₁ _ (ne (neNfₜ neK ⊢k k≡k))))\n (ιx (ℕₜ₌ _ _ d₂ d′ t≡u zeroᵣ)) =\n ⊥-elim (zero≢ne neK (whrDet*Term (redₜ d′ , zeroₙ) (redₜ d₁ , ne neK)))\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n (ιx (ℕₜ n d _ (ne (neNfₜ neK ⊢k k≡k)))) [σm]\n (ιx (ℕₜ₌ _ _ d₂ d′ t≡u zeroᵣ)) =\n ⊥-elim (zero≢ne neK (whrDet*Term (redₜ d₂ , zeroₙ) (redₜ d , ne neK)))\n\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n (ιx (ℕₜ _ d _ (sucᵣ prop))) [σm]\n (ιx (ℕₜ₌ n₁ n′ d₂ d′ t≡u (ne (neNfₜ₌ x x₁ prop₂)))) =\n ⊥-elim (suc≢ne x (whrDet*Term (redₜ d , sucₙ) (redₜ d₂ , ne x)))\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n (ιx (ℕₜ _ d _ zeroᵣ)) [σm]\n (ιx (ℕₜ₌ n₁ n′ d₂ d′ t≡u (ne (neNfₜ₌ x x₁ prop₂)))) =\n ⊥-elim (zero≢ne x (whrDet*Term (redₜ d , zeroₙ) (redₜ d₂ , ne x)))\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n [σn] (ιx (ℕₜ _ d₁ _ (sucᵣ prop₁)))\n (ιx (ℕₜ₌ n₁ n′ d₂ d′ t≡u (ne (neNfₜ₌ x₁ x₂ prop₂)))) =\n ⊥-elim (suc≢ne x₂ (whrDet*Term (redₜ d₁ , sucₙ) (redₜ d′ , ne x₂)))\nnatrec-congTerm [Γ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′] [s] [s′] [s≡s′] ⊢Δ [σ] [σ′] [σ≡σ′]\n [σn] (ιx (ℕₜ _ d₁ _ zeroᵣ))\n (ιx (ℕₜ₌ n₁ n′ d₂ d′ t≡u (ne (neNfₜ₌ x₁ x₂ prop₂)))) =\n ⊥-elim (zero≢ne x₂ (whrDet*Term (redₜ d₁ , zeroₙ) (redₜ d′ , ne x₂)))\n\n\n-- Validity of natural recursion.\nnatrecᵛ : ∀ {F z s n Γ l} ([Γ] : ⊩ᵛ Γ)\n ([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])\n ([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙′ [ℕ]))\n ([F₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] / [Γ])\n ([F₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ])\n ([Fₙ] : Γ ⊩ᵛ⟨ l ⟩ F [ n ] / [Γ])\n → Γ ⊩ᵛ⟨ l ⟩ z ∷ F [ zero ] / [Γ] / [F₀]\n → Γ ⊩ᵛ⟨ l ⟩ s ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ] / [F₊]\n → ([n] : Γ ⊩ᵛ⟨ l ⟩ n ∷ ℕ / [Γ] / [ℕ])\n → Γ ⊩ᵛ⟨ l ⟩ natrec F z s n ∷ F [ n ] / [Γ] / [Fₙ]\nnatrecᵛ {F} {z} {s} {n} {l = l} [Γ] [ℕ] [F] [F₀] [F₊] [Fₙ] [z] [s] [n]\n {Δ = Δ} {σ = σ} ⊢Δ [σ] =\n let [F]′ = S.irrelevance {A = F} (_∙″_ {A = ℕ} [Γ] [ℕ])\n (_∙″_ {l = l} [Γ] (ℕᵛ [Γ])) [F]\n [σn]′ = irrelevanceTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ]))\n (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) (proj₁ ([n] ⊢Δ [σ]))\n n′ = subst σ n\n eqPrf = PE.trans (singleSubstComp n′ σ F)\n (PE.sym (PE.trans (substCompEq F)\n (substConcatSingleton′ F)))\n in irrelevanceTerm′ eqPrf (irrelevance′ (PE.sym (singleSubstComp n′ σ F))\n (proj₁ ([F]′ ⊢Δ ([σ] , [σn]′))))\n (proj₁ ([Fₙ] ⊢Δ [σ]))\n (natrecTerm {F} {z} {s} {n′} {σ = σ} [Γ]\n [F]′\n [F₀] [F₊] [z] [s] ⊢Δ [σ]\n [σn]′)\n , (λ {σ′} [σ′] [σ≡σ′] →\n let [σ′n]′ = irrelevanceTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ′]))\n (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))\n (proj₁ ([n] ⊢Δ [σ′]))\n [σn≡σ′n] = irrelevanceEqTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ]))\n (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ)))\n (proj₂ ([n] ⊢Δ [σ]) [σ′] [σ≡σ′])\n in irrelevanceEqTerm′ eqPrf\n (irrelevance′ (PE.sym (singleSubstComp n′ σ F))\n (proj₁ ([F]′ ⊢Δ ([σ] , [σn]′))))\n (proj₁ ([Fₙ] ⊢Δ [σ]))\n (natrec-congTerm {F} {F} {z} {z} {s} {s} {n′} {subst σ′ n} {σ = σ}\n [Γ] [F]′ [F]′ (reflᵛ {F} (_∙″_ {A = ℕ} {l = l}\n [Γ] (ℕᵛ [Γ])) [F]′) [F₀] [F₀]\n (reflᵛ {F [ zero ]} [Γ] [F₀]) [F₊] [F₊]\n (reflᵛ {Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)}\n [Γ] [F₊])\n [z] [z] (reflᵗᵛ {F [ zero ]} {z} [Γ] [F₀] [z])\n [s] [s]\n (reflᵗᵛ {Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)} {s}\n [Γ] [F₊] [s])\n ⊢Δ [σ] [σ′] [σ≡σ′] [σn]′ [σ′n]′ [σn≡σ′n]))\n\n-- Validity of natural recursion congurence.\nnatrec-congᵛ : ∀ {F F′ z z′ s s′ n n′ Γ l} ([Γ] : ⊩ᵛ Γ)\n ([ℕ] : Γ ⊩ᵛ⟨ l ⟩ ℕ / [Γ])\n ([F] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F / ([Γ] ∙″ [ℕ]))\n ([F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F′ / ([Γ] ∙″ [ℕ]))\n ([F≡F′] : Γ ∙ ℕ ⊩ᵛ⟨ l ⟩ F ≡ F′ / [Γ] ∙″ [ℕ] / [F])\n ([F₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] / [Γ])\n ([F′₀] : Γ ⊩ᵛ⟨ l ⟩ F′ [ zero ] / [Γ])\n ([F₀≡F′₀] : Γ ⊩ᵛ⟨ l ⟩ F [ zero ] ≡ F′ [ zero ] / [Γ] / [F₀])\n ([F₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ])\n ([F′₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑) / [Γ])\n ([F₊≡F′₊] : Γ ⊩ᵛ⟨ l ⟩ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)\n ≡ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑) / [Γ]\n / [F₊])\n ([Fₙ] : Γ ⊩ᵛ⟨ l ⟩ F [ n ] / [Γ])\n ([z] : Γ ⊩ᵛ⟨ l ⟩ z ∷ F [ zero ] / [Γ] / [F₀])\n ([z′] : Γ ⊩ᵛ⟨ l ⟩ z′ ∷ F′ [ zero ] / [Γ] / [F′₀])\n ([z≡z′] : Γ ⊩ᵛ⟨ l ⟩ z ≡ z′ ∷ F [ zero ] / [Γ] / [F₀])\n ([s] : Γ ⊩ᵛ⟨ l ⟩ s ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑) / [Γ] / [F₊])\n ([s′] : Γ ⊩ᵛ⟨ l ⟩ s′ ∷ Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑) / [Γ]\n / [F′₊])\n ([s≡s′] : Γ ⊩ᵛ⟨ l ⟩ s ≡ s′ ∷ Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)\n / [Γ] / [F₊])\n ([n] : Γ ⊩ᵛ⟨ l ⟩ n ∷ ℕ / [Γ] / [ℕ])\n ([n′] : Γ ⊩ᵛ⟨ l ⟩ n′ ∷ ℕ / [Γ] / [ℕ])\n ([n≡n′] : Γ ⊩ᵛ⟨ l ⟩ n ≡ n′ ∷ ℕ / [Γ] / [ℕ])\n → Γ ⊩ᵛ⟨ l ⟩ natrec F z s n ≡ natrec F′ z′ s′ n′ ∷ F [ n ] / [Γ] / [Fₙ]\nnatrec-congᵛ {F} {F′} {z} {z′} {s} {s′} {n} {n′} {l = l}\n [Γ] [ℕ] [F] [F′] [F≡F′] [F₀] [F′₀] [F₀≡F′₀] [F₊] [F′₊] [F₊≡F′₊]\n [Fₙ] [z] [z′] [z≡z′] [s] [s′] [s≡s′] [n] [n′]\n [n≡n′] {Δ = Δ} {σ = σ} ⊢Δ [σ] =\n let [F]′ = S.irrelevance {A = F} (_∙″_ {A = ℕ} [Γ] [ℕ])\n (_∙″_ {l = l} [Γ] (ℕᵛ [Γ])) [F]\n [F′]′ = S.irrelevance {A = F′} (_∙″_ {A = ℕ} [Γ] [ℕ])\n (_∙″_ {l = l} [Γ] (ℕᵛ [Γ])) [F′]\n [F≡F′]′ = S.irrelevanceEq {A = F} {B = F′} (_∙″_ {A = ℕ} [Γ] [ℕ])\n (_∙″_ {l = l} [Γ] (ℕᵛ [Γ])) [F] [F]′ [F≡F′]\n [σn]′ = irrelevanceTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ]))\n (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) (proj₁ ([n] ⊢Δ [σ]))\n [σn′]′ = irrelevanceTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ]))\n (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) (proj₁ ([n′] ⊢Δ [σ]))\n [σn≡σn′]′ = irrelevanceEqTerm {l′ = l} (proj₁ ([ℕ] ⊢Δ [σ]))\n (ℕᵣ (idRed:*: (ℕⱼ ⊢Δ))) ([n≡n′] ⊢Δ [σ])\n [Fₙ]′ = irrelevance′ (PE.sym (singleSubstComp (subst σ n) σ F))\n (proj₁ ([F]′ ⊢Δ ([σ] , [σn]′)))\n in irrelevanceEqTerm′ (PE.sym (singleSubstLift F n))\n [Fₙ]′ (proj₁ ([Fₙ] ⊢Δ [σ]))\n (natrec-congTerm {F} {F′} {z} {z′} {s} {s′}\n {subst σ n} {subst σ n′}\n [Γ] [F]′ [F′]′ [F≡F′]′\n [F₀] [F′₀] [F₀≡F′₀]\n [F₊] [F′₊] [F₊≡F′₊]\n [z] [z′] [z≡z′]\n [s] [s′] [s≡s′] ⊢Δ\n [σ] [σ] (reflSubst [Γ] ⊢Δ [σ])\n [σn]′ [σn′]′ [σn≡σn′]′)\n", "meta": {"hexsha": "f785938ee0b7228bde9e4c397c96a04d012660f8", "size": 54755, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Natrec.agda", "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Substitution/Introductions/Natrec.agda", "max_issues_repo_name": "loic-p/logrel-mltt", "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Substitution/Introductions/Natrec.agda", "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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": 60.2365236524, "max_line_length": 94, "alphanum_fraction": 0.3313304721, "num_tokens": 25125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.6150878555160665, "lm_q1q2_score": 0.3783330700033535}} {"text": "------------------------------------------------------------------------\n-- Some negative results related to weak bisimilarity and expansion\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nopen import Prelude\n\nmodule Delay-monad.Bisimilarity.Negative {a} {A : Type a} where\n\nopen import Equality.Propositional\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude.Size\n\nopen import Function-universe equality-with-J hiding (id; _∘_)\n\nopen import Delay-monad\nopen import Delay-monad.Bisimilarity\nopen import Delay-monad.Termination\n\n------------------------------------------------------------------------\n-- Lemmas stating that functions of certain types can be defined iff A\n-- is uninhabited\n\n-- The computation now x is an expansion of\n-- later (record { force = now x }) for every x : A iff A is\n-- uninhabited.\n\nNow≳later-now = (x : A) → now x ≳ later (record { force = now x })\n\nnow≳later-now⇔uninhabited : Now≳later-now ⇔ ¬ A\nnow≳later-now⇔uninhabited = record\n { to = Now≳later-now ↝⟨ (λ hyp x → case hyp x of λ ()) ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≳ y) ↝⟨ (λ hyp _ → hyp _ _) ⟩□\n Now≳later-now □\n }\n\n-- A variant of laterˡ⁻¹ for (fully defined) expansion can be defined\n-- iff A is uninhabited.\n\nLaterˡ⁻¹-≳ = ∀ {x} {y : Delay A ∞} → later x ≳ y → force x ≳ y\n\nlaterˡ⁻¹-≳⇔uninhabited : Laterˡ⁻¹-≳ ⇔ ¬ A\nlaterˡ⁻¹-≳⇔uninhabited = record\n { to = Laterˡ⁻¹-≳ ↝⟨ (λ hyp _ → hyp (reflexive _)) ⟩\n Now≳later-now ↝⟨ _⇔_.to now≳later-now⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≳ y) ↝⟨ (λ hyp {_ _} _ → hyp _ _) ⟩□\n Laterˡ⁻¹-≳ □\n }\n\n-- The following variants of transitivity can be proved iff A is\n-- uninhabited.\n\nTransitivity-≈≳≳ = {x y z : Delay A ∞} → x ≈ y → y ≳ z → x ≳ z\nTransitivity-≳≈≳ = {x y z : Delay A ∞} → x ≳ y → y ≈ z → x ≳ z\n\ntransitive-≈≳≳⇔uninhabited : Transitivity-≈≳≳ ⇔ ¬ A\ntransitive-≈≳≳⇔uninhabited = record\n { to = Transitivity-≈≳≳ ↝⟨ (λ trans → trans (laterʳ (reflexive _))) ⟩\n Laterˡ⁻¹-≳ ↝⟨ _⇔_.to laterˡ⁻¹-≳⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≳ y) ↝⟨ (λ hyp {_ _ _} _ _ → hyp _ _) ⟩□\n Transitivity-≈≳≳ □\n }\n\ntransitive-≳≈≳⇔uninhabited : Transitivity-≳≈≳ ⇔ ¬ A\ntransitive-≳≈≳⇔uninhabited = record\n { to = Transitivity-≳≈≳ ↝⟨ (λ trans {_ y} lx≳y → later⁻¹ {y = record { force = y }}\n (trans lx≳y (laterʳ (reflexive _)))) ⟩\n Laterˡ⁻¹-≳ ↝⟨ _⇔_.to laterˡ⁻¹-≳⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≳ y) ↝⟨ (λ hyp {_ _ _} _ _ → hyp _ _) ⟩□\n Transitivity-≳≈≳ □\n }\n\n------------------------------------------------------------------------\n-- Lemmas stating that certain size-preserving functions can be\n-- defined iff A is uninhabited\n\n-- A variant of laterˡ⁻¹ in which one occurrence of weak bisimilarity\n-- is replaced by strong bisimilarity, and both arguments are\n-- specialised, can be made size-preserving iff A is uninhabited.\n--\n-- This lemma is used to prove all other similar results below\n-- (directly or indirectly), with the exception that an alternative,\n-- more direct proof is also given for one of the results.\n\nLaterˡ⁻¹-∼≈ = ∀ {i} {x : A} →\n [ i ] later (λ { .force → now x }) ∼ never →\n [ i ] now x ≈ never\n\nsize-preserving-laterˡ⁻¹-∼≈⇔uninhabited : Laterˡ⁻¹-∼≈ ⇔ ¬ A\nsize-preserving-laterˡ⁻¹-∼≈⇔uninhabited = record\n { to = Laterˡ⁻¹-∼≈ ↝⟨ (λ laterˡ⁻¹-∼≈ x → contradiction (laterˡ⁻¹-∼≈ {_}) x ∞) ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _} _ → trivial _ _) ⟩□\n Laterˡ⁻¹-∼≈ □\n }\n where\n\n module _ (laterˡ⁻¹-∼≈ : Laterˡ⁻¹-∼≈) (x : A) where\n\n mutual\n\n now≈never : ∀ {i} → [ i ] now x ≈ never\n now≈never = laterˡ⁻¹-∼≈ (later now∼never)\n\n now∼never : ∀ {i} → [ i ] now x ∼′ never\n force now∼never {j = j} = ⊥-elim (contradiction j)\n\n contradiction : Size → ⊥\n contradiction i = now≉never (now≈never {i = i})\n\n-- A variant of Laterˡ⁻¹-∼≈ which it is sometimes easier to work with.\n\nLaterˡ⁻¹-∼≈′ = ∀ {i} {x : A} →\n [ i ] later (record { force = now x }) ∼ never →\n [ i ] now x ≈ never\n\nsize-preserving-laterˡ⁻¹-∼≈′⇔uninhabited : Laterˡ⁻¹-∼≈′ ⇔ ¬ A\nsize-preserving-laterˡ⁻¹-∼≈′⇔uninhabited =\n Laterˡ⁻¹-∼≈′ ↝⟨ record { to = _∘ transitive-∼ʳ (later λ { .force → now })\n ; from = _∘ transitive-∼ʳ (later λ { .force → now })\n } ⟩\n Laterˡ⁻¹-∼≈ ↝⟨ size-preserving-laterˡ⁻¹-∼≈⇔uninhabited ⟩□\n ¬ A □\n\n-- A variant of laterʳ⁻¹ for weak bisimilarity in which one occurrence\n-- of weak bisimilarity is replaced by strong bisimilarity, and both\n-- arguments are specialised, can be made size-preserving iff A is\n-- uninhabited.\n\nLaterʳ⁻¹-∼≈ = ∀ {i} {x : A} →\n [ i ] never ∼ later (record { force = now x }) →\n [ i ] never ≈ now x\n\nsize-preserving-laterʳ⁻¹-∼≈⇔uninhabited : Laterʳ⁻¹-∼≈ ⇔ ¬ A\nsize-preserving-laterʳ⁻¹-∼≈⇔uninhabited =\n Laterʳ⁻¹-∼≈ ↝⟨ record { to = λ laterʳ⁻¹ → symmetric ∘ laterʳ⁻¹ ∘ symmetric\n ; from = λ laterˡ⁻¹ → symmetric ∘ laterˡ⁻¹ ∘ symmetric\n } ⟩\n Laterˡ⁻¹-∼≈′ ↝⟨ size-preserving-laterˡ⁻¹-∼≈′⇔uninhabited ⟩□\n ¬ A □\n\n-- A variant of laterʳ⁻¹ for expansion in which one occurrence of the\n-- expansion relation is replaced by strong bisimilarity, and both\n-- arguments are specialised, can be made size-preserving iff A is\n-- uninhabited.\n\nLaterʳ⁻¹-∼≳ = ∀ {i} {x : A} →\n [ i ] never ∼ later (record { force = now x }) →\n [ i ] never ≳ now x\n\nsize-preserving-laterʳ⁻¹-∼≳⇔uninhabited : Laterʳ⁻¹-∼≳ ⇔ ¬ A\nsize-preserving-laterʳ⁻¹-∼≳⇔uninhabited = record\n { to = Laterʳ⁻¹-∼≳ ↝⟨ ≳→ ∘_ ⟩\n Laterʳ⁻¹-∼≈ ↝⟨ _⇔_.to size-preserving-laterʳ⁻¹-∼≈⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _} _ → trivial _ _) ⟩□\n Laterʳ⁻¹-∼≳ □\n }\n\n-- The function laterˡ⁻¹ can be made size-preserving iff A is\n-- uninhabited.\n\nLaterˡ⁻¹-≈ = ∀ {i x} {y : Delay A ∞} →\n [ i ] later x ≈ y → [ i ] force x ≈ y\n\nsize-preserving-laterˡ⁻¹-≈⇔uninhabited : Laterˡ⁻¹-≈ ⇔ ¬ A\nsize-preserving-laterˡ⁻¹-≈⇔uninhabited = record\n { to = Laterˡ⁻¹-≈ ↝⟨ _∘ ∼→ ⟩\n Laterˡ⁻¹-∼≈ ↝⟨ _⇔_.to size-preserving-laterˡ⁻¹-∼≈⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _} _ → trivial _ _) ⟩□\n Laterˡ⁻¹-≈ □\n }\n\n-- The function laterʳ⁻¹ can be made size-preserving for weak\n-- bisimilarity iff A is uninhabited.\n\nLaterʳ⁻¹-≈ = ∀ {i} {x : Delay A ∞} {y} →\n [ i ] x ≈ later y → [ i ] x ≈ force y\n\nsize-preserving-laterʳ⁻¹-≈⇔uninhabited : Laterʳ⁻¹-≈ ⇔ ¬ A\nsize-preserving-laterʳ⁻¹-≈⇔uninhabited =\n Laterʳ⁻¹-≈ ↝⟨ record { to = λ laterʳ⁻¹ → symmetric ∘ laterʳ⁻¹ ∘ symmetric\n ; from = λ laterˡ⁻¹ → symmetric ∘ laterˡ⁻¹ ∘ symmetric\n } ⟩\n Laterˡ⁻¹-≈ ↝⟨ size-preserving-laterˡ⁻¹-≈⇔uninhabited ⟩□\n\n ¬ A □\n\n-- The function laterʳ⁻¹ can be made size-preserving for expansion iff\n-- A is uninhabited.\n\nLaterʳ⁻¹-≳ = ∀ {i} {x : Delay A ∞} {y} →\n [ i ] x ≳ later y → [ i ] x ≳ force y\n\nsize-preserving-laterʳ⁻¹-≳⇔uninhabited : Laterʳ⁻¹-≳ ⇔ ¬ A\nsize-preserving-laterʳ⁻¹-≳⇔uninhabited = record\n { to = Laterʳ⁻¹-≳ ↝⟨ _∘ ∼→ ⟩\n Laterʳ⁻¹-∼≳ ↝⟨ _⇔_.to size-preserving-laterʳ⁻¹-∼≳⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _} _ → trivial _ _) ⟩□\n Laterʳ⁻¹-≳ □\n }\n\n-- A variant of ⇓-respects-≈ in which _≈_ is replaced by _∼_ can be\n-- made size-preserving in the second argument iff A is uninhabited.\n\n⇓-Respects-∼ʳ = ∀ {i x y} {z : A} →\n x ⇓ z → [ i ] x ∼ y → Terminates i y z\n\nsize-preserving-⇓-respects-∼ʳ⇔uninhabited : ⇓-Respects-∼ʳ ⇔ ¬ A\nsize-preserving-⇓-respects-∼ʳ⇔uninhabited = record\n { to = ⇓-Respects-∼ʳ ↝⟨ (λ resp → resp (laterʳ now)) ⟩\n Laterˡ⁻¹-∼≈ ↝⟨ _⇔_.to size-preserving-laterˡ⁻¹-∼≈⇔uninhabited ⟩\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n ⇓-Respects-∼ʳ □\n }\n\n-- The lemma ⇓-respects-≈ can be made size-preserving in the second\n-- argument iff A is uninhabited.\n\n⇓-Respects-≈ʳ = ∀ {i x y} {z : A} →\n x ⇓ z → [ i ] x ≈ y → Terminates i y z\n\nsize-preserving-⇓-respects-≈ʳ⇔uninhabited : ⇓-Respects-≈ʳ ⇔ ¬ A\nsize-preserving-⇓-respects-≈ʳ⇔uninhabited = record\n { to = ⇓-Respects-≈ʳ ↝⟨ (λ resp x⇓z → resp x⇓z ∘ ∼→) ⟩\n ⇓-Respects-∼ʳ ↝⟨ _⇔_.to size-preserving-⇓-respects-∼ʳ⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n ⇓-Respects-≈ʳ □\n }\n\n-- There is a transitivity-like proof, taking weak bisimilarity and\n-- strong bisimilarity to weak bisimilarity, that preserves the size\n-- of the second argument iff A is uninhabited.\n\nTransitivity-≈∼ʳ = ∀ {i} {x y z : Delay A ∞} →\n x ≈ y → [ i ] y ∼ z → [ i ] x ≈ z\n\nsize-preserving-transitivity-≈∼ʳ⇔uninhabited : Transitivity-≈∼ʳ ⇔ ¬ A\nsize-preserving-transitivity-≈∼ʳ⇔uninhabited = record\n { to = Transitivity-≈∼ʳ ↝⟨ (λ trans → trans) ⟩\n ⇓-Respects-∼ʳ ↝⟨ _⇔_.to size-preserving-⇓-respects-∼ʳ⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n Transitivity-≈∼ʳ □\n }\n\n-- There is a transitivity-like proof, taking strong bisimilarity and\n-- weak bisimilarity to weak bisimilarity, that preserves the size of\n-- the first argument iff A is uninhabited.\n\nTransitivity-∼≈ˡ = ∀ {i} {x y z : Delay A ∞} →\n [ i ] x ∼ y → y ≈ z → [ i ] x ≈ z\n\nsize-preserving-transitivity-∼≈ˡ⇔uninhabited : Transitivity-∼≈ˡ ⇔ ¬ A\nsize-preserving-transitivity-∼≈ˡ⇔uninhabited =\n Transitivity-∼≈ˡ ↝⟨ record { to = λ trans {_ _ _ _} p q →\n symmetric (trans (symmetric q) (symmetric p))\n ; from = λ trans {_ _ _ _} p q →\n symmetric (trans (symmetric q) (symmetric p))\n } ⟩\n Transitivity-≈∼ʳ ↝⟨ size-preserving-transitivity-≈∼ʳ⇔uninhabited ⟩□\n\n ¬ A □\n\n-- There is a transitivity-like proof, taking strong bisimilarity and\n-- expansion to expansion, that preserves the size of the first\n-- argument iff A is uninhabited.\n\nTransitivity-∼≳ˡ = ∀ {i} {x y z : Delay A ∞} →\n [ i ] x ∼ y → y ≳ z → [ i ] x ≳ z\n\nsize-preserving-transitivity-∼≳ˡ⇔uninhabited : Transitivity-∼≳ˡ ⇔ ¬ A\nsize-preserving-transitivity-∼≳ˡ⇔uninhabited = record\n { to = Transitivity-∼≳ˡ ↝⟨ (λ trans never∼lnx → trans never∼lnx (laterˡ now)) ⟩\n Laterʳ⁻¹-∼≳ ↝⟨ _⇔_.to size-preserving-laterʳ⁻¹-∼≳⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n Transitivity-∼≳ˡ □\n }\n\n-- There is a transitivity proof for weak bisimilarity that preserves\n-- the size of the second argument iff A is uninhabited.\n\nTransitivity-≈ʳ = ∀ {i} {x y z : Delay A ∞} →\n x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z\n\nsize-preserving-transitivity-≈ʳ⇔uninhabited : Transitivity-≈ʳ ⇔ ¬ A\nsize-preserving-transitivity-≈ʳ⇔uninhabited = record\n { to = Transitivity-≈ʳ ↝⟨ (λ trans → trans) ⟩\n ⇓-Respects-≈ʳ ↝⟨ _⇔_.to size-preserving-⇓-respects-≈ʳ⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n Transitivity-≈ʳ □\n }\n\n-- There is a transitivity proof for weak bisimilarity that preserves\n-- the size of the first argument iff A is uninhabited.\n\nTransitivity-≈ˡ = ∀ {i} {x y z : Delay A ∞} →\n [ i ] x ≈ y → y ≈ z → [ i ] x ≈ z\n\nsize-preserving-transitivity-≈ˡ⇔uninhabited : Transitivity-≈ˡ ⇔ ¬ A\nsize-preserving-transitivity-≈ˡ⇔uninhabited =\n Transitivity-≈ˡ ↝⟨ record { to = λ trans {_ _ _ _} p q →\n symmetric (trans (symmetric q) (symmetric p))\n ; from = λ trans {_ _ _ _} p q →\n symmetric (trans (symmetric q) (symmetric p))\n } ⟩\n Transitivity-≈ʳ ↝⟨ size-preserving-transitivity-≈ʳ⇔uninhabited ⟩□\n\n ¬ A □\n\n-- There is a transitivity proof for expansion that preserves the size\n-- of the first argument iff A is uninhabited.\n\nTransitivity-≳ˡ = ∀ {i} {x y z : Delay A ∞} →\n [ i ] x ≳ y → y ≳ z → [ i ] x ≳ z\n\nsize-preserving-transitivity-≳ˡ⇔uninhabited : Transitivity-≳ˡ ⇔ ¬ A\nsize-preserving-transitivity-≳ˡ⇔uninhabited = record\n { to = Transitivity-≳ˡ ↝⟨ _∘ ∼→ ⟩\n Transitivity-∼≳ˡ ↝⟨ _⇔_.to size-preserving-transitivity-∼≳ˡ⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n Transitivity-≳ˡ □\n }\n\n-- There is a fully size-preserving transitivity proof for weak\n-- bisimilarity iff A is uninhabited.\n\nTransitivity-≈ = ∀ {i} {x y z : Delay A ∞} →\n [ i ] x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z\n\nsize-preserving-transitivity-≈⇔uninhabited : Transitivity-≈ ⇔ ¬ A\nsize-preserving-transitivity-≈⇔uninhabited = record\n { to = Transitivity-≈ ↝⟨ (λ trans → trans) ⟩\n Transitivity-≈ˡ ↝⟨ _⇔_.to size-preserving-transitivity-≈ˡ⇔uninhabited ⟩\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n Transitivity-≈ □\n }\n\n-- The following two lemmas provide an alternative proof of one\n-- direction of the previous lemma (with a small change to one of the\n-- types).\n\n-- If there is a transitivity proof for weak bisimilarity that is\n-- size-preserving in both arguments, then weak bisimilarity is\n-- trivial.\n\nsize-preserving-transitivity-≈→trivial :\n (∀ {i} x {y z : Delay A ∞} →\n [ i ] x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z) →\n ∀ {i} (x y : Delay A ∞) → [ i ] x ≈ y\nsize-preserving-transitivity-≈→trivial _≈⟨_⟩ʷ_ x y =\n (x ≈⟨ laterʳ (x ∎ʷ) ⟩ʷ\n (later (λ { .force → x }) ≈⟨ later (λ { .force → size-preserving-transitivity-≈→trivial _≈⟨_⟩ʷ_ x y }) ⟩ʷ\n (later (λ { .force → y }) ≈⟨ laterˡ (y ∎ʷ) ⟩ʷ\n (y ∎ʷ))))\n where\n _∎ʷ = reflexive\n\n-- If there is a transitivity proof for weak bisimilarity that is\n-- size-preserving in both arguments, then the carrier type A is not\n-- inhabited.\n\nsize-preserving-transitivity-≈→uninhabited :\n (∀ {i} x {y z : Delay A ∞} →\n [ i ] x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z) →\n ¬ A\nsize-preserving-transitivity-≈→uninhabited trans x =\n now≉never (size-preserving-transitivity-≈→trivial trans (now x) never)\n\n-- There is a fully size-preserving transitivity proof for expansion\n-- iff A is uninhabited.\n\nTransitivity-≳ = ∀ {i} {x y z : Delay A ∞} →\n [ i ] x ≳ y → [ i ] y ≳ z → [ i ] x ≳ z\n\nsize-preserving-transitivity-≳⇔uninhabited : Transitivity-≳ ⇔ ¬ A\nsize-preserving-transitivity-≳⇔uninhabited = record\n { to = Transitivity-≳ ↝⟨ id ⟩\n Transitivity-≳ˡ ↝⟨ _⇔_.to size-preserving-transitivity-≳ˡ⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n Transitivity-≳ □\n }\n\n-- There is a transitivity-like proof, taking expansion and weak\n-- bisimilarity to weak bisimilarity, that preserves the size of the\n-- first argument iff A is uninhabited.\n\nTransitivity-≳≈ˡ = ∀ {i} {x y z : Delay A ∞} →\n [ i ] x ≳ y → y ≈ z → [ i ] x ≈ z\n\nsize-preserving-transitivity-≳≈ˡ⇔uninhabited : Transitivity-≳≈ˡ ⇔ ¬ A\nsize-preserving-transitivity-≳≈ˡ⇔uninhabited = record\n { to = Transitivity-≳≈ˡ ↝⟨ _∘ ∼→ ⟩\n Transitivity-∼≈ˡ ↝⟨ _⇔_.to size-preserving-transitivity-∼≈ˡ⇔uninhabited ⟩\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n Transitivity-≳≈ˡ □\n }\n\n-- There is a transitivity-like proof, taking expansion and weak\n-- bisimilarity to weak bisimilarity, that preserves the size of both\n-- arguments iff A is uninhabited.\n\nTransitivity-≳≈ = ∀ {i} {x y z : Delay A ∞} →\n [ i ] x ≳ y → [ i ] y ≈ z → [ i ] x ≈ z\n\nsize-preserving-transitivity-≳≈⇔uninhabited : Transitivity-≳≈ ⇔ ¬ A\nsize-preserving-transitivity-≳≈⇔uninhabited = record\n { to = Transitivity-≳≈ ↝⟨ id ⟩\n Transitivity-≳≈ˡ ↝⟨ _⇔_.to size-preserving-transitivity-≳≈ˡ⇔uninhabited ⟩\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n Transitivity-≳≈ □\n }\n\n-- There is a transitivity-like proof, taking weak bisimilarity and\n-- the converse of expansion to weak bisimilarity, that preserves the\n-- size of the second argument iff A is uninhabited.\n\nTransitivity-≈≲ʳ = ∀ {i} {x y z : Delay A ∞} →\n x ≈ y → [ i ] y ≲ z → [ i ] x ≈ z\n\nsize-preserving-transitivity-≈≲ʳ⇔uninhabited : Transitivity-≈≲ʳ ⇔ ¬ A\nsize-preserving-transitivity-≈≲ʳ⇔uninhabited =\n Transitivity-≈≲ʳ ↝⟨ record { to = λ trans x≳y y≈z → symmetric (trans (symmetric y≈z) x≳y)\n ; from = λ trans x≈y y≲z → symmetric (trans y≲z (symmetric x≈y))\n } ⟩\n Transitivity-≳≈ˡ ↝⟨ size-preserving-transitivity-≳≈ˡ⇔uninhabited ⟩□\n ¬ A □\n\n-- There is a transitivity-like proof, taking weak bisimilarity and\n-- the converse of expansion to weak bisimilarity, that preserves the\n-- size of both arguments iff A is uninhabited.\n\nTransitivity-≈≲ = ∀ {i} {x y z : Delay A ∞} →\n [ i ] x ≈ y → [ i ] y ≲ z → [ i ] x ≈ z\n\nsize-preserving-transitivity-≈≲⇔uninhabited : Transitivity-≈≲ ⇔ ¬ A\nsize-preserving-transitivity-≈≲⇔uninhabited =\n Transitivity-≈≲ ↝⟨ record { to = λ trans x≳y y≈z → symmetric (trans (symmetric y≈z) x≳y)\n ; from = λ trans x≈y y≲z → symmetric (trans y≲z (symmetric x≈y))\n } ⟩\n Transitivity-≳≈ ↝⟨ size-preserving-transitivity-≳≈⇔uninhabited ⟩□\n ¬ A □\n\n-- There is a transitivity-like proof, taking weak bisimilarity and\n-- expansion to weak bisimilarity, that preserves the size of the\n-- first argument iff A is uninhabited.\n\nTransitivity-≈≳ˡ = ∀ {i} {x y z : Delay A ∞} →\n [ i ] x ≈ y → y ≳ z → [ i ] x ≈ z\n\nsize-preserving-transitivity-≈≳ˡ⇔uninhabited : Transitivity-≈≳ˡ ⇔ ¬ A\nsize-preserving-transitivity-≈≳ˡ⇔uninhabited = record\n { to = Transitivity-≈≳ˡ ↝⟨ (λ trans x≈ly → trans x≈ly (laterˡ (reflexive _))) ⟩\n Laterʳ⁻¹-≈ ↝⟨ _⇔_.to size-preserving-laterʳ⁻¹-≈⇔uninhabited ⟩\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□\n Transitivity-≈≳ˡ □\n }\n", "meta": {"hexsha": "1bb585490c7d4bd038a8e9bfe384fb82617ef4d2", "size": 20039, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Delay-monad/Bisimilarity/Negative.agda", "max_stars_repo_name": "nad/delay-monad", "max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Bisimilarity/Negative.agda", "max_issues_repo_name": "nad/delay-monad", "max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Bisimilarity/Negative.agda", "max_forks_repo_name": "nad/delay-monad", "max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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.5647773279, "max_line_length": 108, "alphanum_fraction": 0.5322620889, "num_tokens": 8001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.6224593241981982, "lm_q1q2_score": 0.3782456060343166}} {"text": "-- {-# OPTIONS -v term:20 #-}\nmodule Issue787 where\n\ndata ⊥ : Set where\n\ndata List (A : Set) : Set where\n [] : List A\n _∷_ : A → List A → List A\n\ndata Rat' {X : Set} : List (List X) → List X → Set where\n cons : ∀{ss x xs} → Rat' ((x ∷ xs) ∷ ss) xs → Rat' ss (x ∷ xs)\n\nbad : {X : Set} (xs : List X) (acc : List (List X)) (p : Rat' acc xs) → ⊥\nbad .(x ∷ xs) acc (cons {ss = .acc} {x = x} {xs = xs} p) =\n bad (x ∷ xs) acc (cons {ss = acc} {x = x} {xs = xs} p)\n\n-- Andreas, 2013-02-18\n-- This should give a termination error.\n-- It did pass up to today because of the idempotency check\n-- excluded bad calls with embedded sub-matrices.\n-- Disabling matrix-shaped orders, which do not have a formal semantics\n-- anyway, bring the termination problem to Agda's attention.\n", "meta": {"hexsha": "ed8548ce7a980c4b70043522515e08d490e7afe3", "size": 770, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue787.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Issue787.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Issue787.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 33.4782608696, "max_line_length": 73, "alphanum_fraction": 0.6025974026, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.37819876756430165}} {"text": "------------------------------------------------------------------------\n-- INCREMENTAL λ-CALCULUS\n--\n-- Delta-observational equivalence\n------------------------------------------------------------------------\nmodule Base.Change.Equivalence where\n\nopen import Relation.Binary.PropositionalEquality\nopen import Base.Change.Algebra\nopen import Level\nopen import Data.Unit\nopen import Data.Product\nopen import Function\n\nopen import Base.Change.Equivalence.Base public\nopen import Base.Change.Equivalence.EqReasoning public\n\nmodule _\n {a} {A : Set a} {{CA : ChangeAlgebra A}}\n {x : A}\n where\n -- By update-nil, if dx = nil x, then x ⊞ dx ≡ x.\n -- As a consequence, if dx ≙ nil x, then x ⊞ dx ≡ x\n nil-is-⊞-unit : ∀ (dx : Δ x) → dx ≙ nil x → x ⊞ dx ≡ x\n nil-is-⊞-unit dx dx≙nil-x =\n begin\n x ⊞ dx\n ≡⟨ proof dx≙nil-x ⟩\n x ⊞ (nil x)\n ≡⟨ update-nil x ⟩\n x\n ∎\n where\n open ≡-Reasoning\n\n -- Here we prove the inverse:\n ⊞-unit-is-nil : ∀ (dx : Δ x) → x ⊞ dx ≡ x → dx ≙ (nil x)\n ⊞-unit-is-nil dx x⊞dx≡x = doe $\n begin\n x ⊞ dx\n ≡⟨ x⊞dx≡x ⟩\n x\n ≡⟨ sym (update-nil x) ⟩\n x ⊞ nil x\n ∎\n where\n open ≡-Reasoning\n\n -- Let's show that nil x is d.o.e. to x ⊟ x\n nil-x-is-x⊟x : nil x ≙ x ⊟ x\n nil-x-is-x⊟x = ≙-sym (⊞-unit-is-nil (x ⊟ x) (update-diff x x))\n\n -- TODO: we want to show that all functions of interest respect\n -- delta-observational equivalence, so that two d.o.e. changes can be\n -- substituted for each other freely.\n --\n -- * That should be be true for\n -- functions using changes parametrically.\n --\n -- * Moreover, d.o.e. should be respected by contexts [ ] x dx and df x [ ];\n -- this is proved below on both contexts at once by\n -- equiv-fun-changes-respect, and its corollaries fun-change-respects and\n -- equiv-fun-changes-funs.\n --\n -- * Finally, change algebra operations should respect d.o.e. But ⊞ respects\n -- it by definition, and ⊟ doesn't take change arguments - we will only\n -- need a proof for compose, when we define it.\n --\n -- Stating the general result, though, seems hard, we should\n -- rather have lemmas proving that certain classes of functions respect this\n -- equivalence.\n\n -- This results pairs with update-diff.\n diff-update : ∀ {dx : Δ x} → (x ⊞ dx) ⊟ x ≙ dx\n diff-update {dx} = doe lemma\n where\n lemma : x ⊞ (x ⊞ dx ⊟ x) ≡ x ⊞ dx\n lemma = update-diff (x ⊞ dx) x\n\n -- \\begin{lemma}[Equivalence cancellation]\n -- |v2 `ominus` v1 `doe` dv| holds if and only if |v2 = v1 `oplus`\n -- dv|, for any |v1, v2 `elem` V| and |dv `elem` Dt ^ v1|.\n -- \\end{lemma}\n\n equiv-cancel-1 : ∀ x' dx → (x' ⊟ x) ≙ dx → x' ≡ x ⊞ dx\n equiv-cancel-1 x' dx (doe x'⊟x≙dx) = trans (sym (update-diff x' x)) x'⊟x≙dx\n equiv-cancel-2 : ∀ x' dx → x' ≡ x ⊞ dx → x' ⊟ x ≙ dx\n equiv-cancel-2 _ dx refl = diff-update\n\nmodule _\n {a} {A : Set a} {{CA : ChangeAlgebra A}}\n {b} {B : Set b} {{CB : ChangeAlgebra B}}\n where\n\n ≙-cong₂ : ∀ {c} {C : Set c} {x y}\n (f : A → B → C) {dx1 dx2 dy1 dy2} → dx1 ≙ dx2 → dy1 ≙ dy2 → f (x ⊞ dx1) (y ⊞ dy1) ≡ f (x ⊞ dx2) (y ⊞ dy2)\n ≙-cong₂ f dx1≙dx2 dy1≙dy2 = cong₂ f (proof dx1≙dx2) (proof dy1≙dy2)\n\n ≙-incrementalization : ∀ (f : A → B) (df : Δ f) x dx → (f ⊞ df) (x ⊞ dx) ⊟ f x ≙ apply df x dx\n ≙-incrementalization f df x dx = equiv-cancel-2 _ _ (incrementalization f df x dx)\n\n equiv-fun-changes-respect : ∀ {x : A} {dx₁ dx₂ : Δ x} {f : A → B} {df₁ df₂ : Δ f} →\n df₁ ≙₍ f ₎ df₂ → dx₁ ≙ dx₂ → apply df₁ x dx₁ ≙ apply df₂ x dx₂\n equiv-fun-changes-respect {x} {dx₁} {dx₂} {f} {df₁} {df₂} df₁≙df₂ dx₁≙dx₂ = doe lemma\n where\n open ≡-Reasoning\n -- This type signature just expands the goal manually a bit.\n lemma : f x ⊞ apply df₁ x dx₁ ≡ f x ⊞ apply df₂ x dx₂\n -- Informally: use incrementalization on both sides and then apply\n -- congruence.\n lemma =\n begin\n f x ⊞ apply df₁ x dx₁\n ≡⟨ sym (incrementalization f df₁ x dx₁) ⟩\n (f ⊞ df₁) (x ⊞ dx₁)\n ≡⟨ ≙-cong (f ⊞ df₁) dx₁≙dx₂ ⟩\n (f ⊞ df₁) (x ⊞ dx₂)\n ≡⟨ ≙-cong (λ f → f (x ⊞ dx₂)) df₁≙df₂ ⟩\n (f ⊞ df₂) (x ⊞ dx₂)\n ≡⟨ incrementalization f df₂ x dx₂ ⟩\n f x ⊞ apply df₂ x dx₂\n ∎\n\n fun-change-respects : ∀ {x : A} {dx₁ dx₂} {f : A → B} (df : Δ f) →\n dx₁ ≙ dx₂ → apply df x dx₁ ≙ apply df x dx₂\n fun-change-respects df dx₁≙dx₂ = equiv-fun-changes-respect (≙-refl {dx = df}) dx₁≙dx₂\n\n -- D.o.e. function changes behave like the same function (up to d.o.e.).\n equiv-fun-changes-funs : ∀ {x : A} {dx} {f : A → B} {df₁ df₂} →\n df₁ ≙₍ f ₎ df₂ → apply df₁ x dx ≙ apply df₂ x dx\n equiv-fun-changes-funs {dx = dx} df₁≙df₂ = equiv-fun-changes-respect df₁≙df₂ (≙-refl {dx = dx})\n\n derivative-doe-characterization : ∀ {a : A} {da : Δ a}\n {f : A → B} {df : RawChange f} (is-derivative : IsDerivative f df) →\n df a da ≙ f (a ⊞ da) ⊟ f a\n derivative-doe-characterization {a} {da} {f} {df} is-derivative = doe lemma\n where\n open ≡-Reasoning\n lemma : f a ⊞ df a da ≡ f a ⊞ (f (a ⊞ da) ⊟ f a)\n lemma =\n begin\n (f a ⊞ df a da)\n ≡⟨ is-derivative a da ⟩\n (f (a ⊞ da))\n ≡⟨ sym (update-diff (f (a ⊞ da)) (f a)) ⟩\n (f a ⊞ (f (a ⊞ da) ⊟ f a))\n ∎\n\n derivative-respects-doe : ∀ {x : A} {dx₁ dx₂ : Δ x}\n {f : A → B} {df : RawChange f} (is-derivative : IsDerivative f df) →\n dx₁ ≙ dx₂ → df x dx₁ ≙ df x dx₂\n derivative-respects-doe {x} {dx₁} {dx₂} {f} {df} is-derivative dx₁≙dx₂ =\n begin\n df x dx₁\n ≙⟨ derivative-doe-characterization is-derivative ⟩\n f (x ⊞ dx₁) ⊟ f x\n ≡⟨ cong (λ v → f v ⊟ f x) (proof dx₁≙dx₂) ⟩\n f (x ⊞ dx₂) ⊟ f x\n ≙⟨ ≙-sym (derivative-doe-characterization is-derivative) ⟩\n df x dx₂\n ∎\n where\n open ≙-Reasoning\n\n -- This is also a corollary of fun-changes-respect\n derivative-respects-doe-alt : ∀ {x : A} {dx₁ dx₂ : Δ x}\n {f : A → B} {df : RawChange f} (is-derivative : IsDerivative f df) →\n dx₁ ≙ dx₂ → df x dx₁ ≙ df x dx₂\n derivative-respects-doe-alt {x} {dx₁} {dx₂} {f} {df} is-derivative dx₁≙dx₂ =\n fun-change-respects (DerivativeAsChange is-derivative) dx₁≙dx₂\n\n open import Postulate.Extensionality\n\n -- An extensionality principle for delta-observational equivalence: if\n -- applying two function changes to the same base value and input change gives\n -- a d.o.e. result, then the two function changes are d.o.e. themselves.\n\n delta-ext : ∀ {f : A → B} → ∀ {df dg : Δ f} → (∀ x dx → apply df x dx ≙ apply dg x dx) → df ≙ dg\n delta-ext {f} {df} {dg} df-x-dx≙dg-x-dx = doe lemma₂\n where\n open ≡-Reasoning\n -- This type signature just expands the goal manually a bit.\n lemma₁ : ∀ x dx → f x ⊞ apply df x dx ≡ f x ⊞ apply dg x dx\n lemma₁ x dx = proof $ df-x-dx≙dg-x-dx x dx\n lemma₂ : f ⊞ df ≡ f ⊞ dg\n lemma₂ = ext (λ x → lemma₁ x (nil x))\n\n -- You could think that the function should relate equivalent changes, but\n -- that's a stronger hypothesis, which doesn't give you extra guarantees. But\n -- here's the statement and proof, for completeness:\n\n delta-ext₂ : ∀ {f : A → B} → ∀ {df dg : Δ f} → (∀ x (dx₁ dx₂ : Δ x) → dx₁ ≙₍ x ₎ dx₂ → apply df x dx₁ ≙ apply dg x dx₂) → df ≙ dg\n delta-ext₂ {f} {df} {dg} df-x-dx≙dg-x-dx = delta-ext (λ x dx → df-x-dx≙dg-x-dx x dx dx ≙-refl)\n\n -- We know that IsDerivative f (apply (nil f)) (by nil-is-derivative).\n -- That is, df = nil f -> IsDerivative f (apply df).\n -- Now, we try to prove that if IsDerivative f (apply df) -> df = nil f.\n -- But first, we prove that f ⊞ df = f.\n derivative-is-⊞-unit : ∀ {f : A → B} df →\n IsDerivative f (apply df) → f ⊞ df ≡ f\n derivative-is-⊞-unit {f} df fdf =\n begin\n f ⊞ df\n ≡⟨⟩\n (λ x → f x ⊞ apply df x (nil x))\n ≡⟨ ext (λ x → fdf x (nil x)) ⟩\n (λ x → f (x ⊞ nil x))\n ≡⟨ ext (λ x → cong f (update-nil x)) ⟩\n (λ x → f x)\n ≡⟨⟩\n f\n ∎\n where\n open ≡-Reasoning\n\n -- We can restate the above as \"df is a nil change\".\n\n derivative-is-nil : ∀ {f : A → B} df →\n IsDerivative f (apply df) → df ≙ nil f\n derivative-is-nil df fdf = ⊞-unit-is-nil df (derivative-is-⊞-unit df fdf)\n\n derivative-is-nil-alternative : ∀ {f : A → B} df →\n (IsDerivative-f-df : IsDerivative f df) → DerivativeAsChange IsDerivative-f-df ≙ nil f\n derivative-is-nil-alternative df IsDerivative-f-df = derivative-is-nil (DerivativeAsChange IsDerivative-f-df) IsDerivative-f-df\n\n -- Theorem 2.10, appears in Base.Change.Algebra.\n -- nil-is-derivative : ∀ (f : A → B) → IsDerivative f (apply (nil f))\n\n -- If we have two derivatives, they're both nil, hence they're equivalent.\n derivative-unique : ∀ {f : A → B} {df dg : Δ f} → IsDerivative f (apply df) → IsDerivative f (apply dg) → df ≙ dg\n derivative-unique {f} {df} {dg} fdf fdg =\n begin\n df\n ≙⟨ derivative-is-nil df fdf ⟩\n nil f\n ≙⟨ ≙-sym (derivative-is-nil dg fdg) ⟩\n dg\n ∎\n where\n open ≙-Reasoning\n\n equiv-derivative-is-derivative : ∀ {f : A → B} df₁ df₂ → IsDerivative f (apply df₁) → df₁ ≙₍ f ₎ df₂ → IsDerivative f (apply df₂)\n equiv-derivative-is-derivative {f} df₁ df₂ IsDerivative-f-df₁ df₁≙df₂ a da =\n begin\n f a ⊞ apply df₂ a da\n ≡⟨ sym (incrementalization f df₂ a da) ⟩\n (f ⊞ df₂) (a ⊞ da)\n ≡⟨ cong (λ □ → □ (a ⊞ da)) lemma ⟩\n f (a ⊞ da)\n ∎\n where\n open ≡-Reasoning\n lemma : f ⊞ df₂ ≡ f\n lemma =\n begin\n f ⊞ df₂\n ≡⟨ proof (≙-sym df₁≙df₂) ⟩\n f ⊞ df₁\n ≡⟨ derivative-is-⊞-unit df₁ IsDerivative-f-df₁ ⟩\n f\n ∎\n equiv-nil-is-derivative : ∀ {f : A → B} df → nil f ≙₍ f ₎ df → IsDerivative f (apply df)\n equiv-nil-is-derivative {f} df = equiv-derivative-is-derivative (nil f) df (nil-is-derivative f)\n\n -- This is Lemma 2.5 in the paper. Note that the statement in the paper uses\n -- (incorrectly) normal equality instead of delta-observational equivalence.\n deriv-zero :\n ∀ (f : A → B) df → IsDerivative f df →\n ∀ v → df v (nil v) ≙ nil (f v)\n deriv-zero f df proof v = doe lemma\n where\n open ≡-Reasoning\n lemma : f v ⊞ df v (nil v) ≡ f v ⊞ nil (f v)\n lemma =\n begin\n f v ⊞ df v (nil v)\n ≡⟨ proof v (nil v) ⟩\n f (v ⊞ (nil v))\n ≡⟨ cong f (update-nil v) ⟩\n f v\n ≡⟨ sym (update-nil (f v)) ⟩\n f v ⊞ nil (f v)\n ∎\n\nmodule _\n {a} {A : Set a} {{CA : ChangeAlgebra A}}\n {b} {B : Set b} {{CB : ChangeAlgebra B}}\n {c} {C : Set c} {{CC : ChangeAlgebra C}}\n where\n ≙-cong₃ : ∀ {d} {D : Set d} {x y z}\n (f : A → B → C → D) {dx1 dx2 dy1 dy2 dz1 dz2} →\n dx1 ≙ dx2 → dy1 ≙ dy2 → dz1 ≙ dz2 →\n f (x ⊞ dx1) (y ⊞ dy1) (z ⊞ dz1) ≡ f (x ⊞ dx2) (y ⊞ dy2) (z ⊞ dz2)\n ≙-cong₃ f dx1≙dx2 dy1≙dy2 dz1≙dz2 = cong₂ (λ x y → x y) (cong₂ f (proof dx1≙dx2) (proof dy1≙dy2)) (proof dz1≙dz2)\n", "meta": {"hexsha": "640b8c97e719987169a8dec25dcb25b30dbaf02e", "size": 10827, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Base/Change/Equivalence.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": "Base/Change/Equivalence.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": "Base/Change/Equivalence.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": 36.7016949153, "max_line_length": 131, "alphanum_fraction": 0.5591576614, "num_tokens": 4198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.3781986707064467}} {"text": "module STLCSF.Examples where\n\nopen import Data.Fin hiding (_+_)\nopen import Data.Product\nopen import Data.List\nopen import Data.List.Membership.Propositional\nopen import Data.List.Relation.Unary.Any\nopen import Data.List.Relation.Unary.All\nopen import Data.Maybe\nopen import Data.Integer hiding (suc)\n\n-- This file contains a few example programs for the definitional\n-- interpreter for STLC using scopes and frames in Section 4.\n\nopen import Agda.Builtin.Nat hiding (_+_)\nopen import Relation.Binary.PropositionalEquality hiding ([_])\n\n-- The identity function: λ x . x\nmodule Id where\n\n open import STLCSF.Semantics 2\n open import ScopesFrames.ScopesFrames 2 Ty\n\n -- Whereas Agda can infer the structure of ordinary type contexts,\n -- the scope graph library represents scope graphs as \"lookup\n -- tables\". Agda cannot straightforwardly infer the structure of a\n -- lookup table. We spell it out.\n\n g : Graph\n g zero = [] , [] -- root scope\n g (suc n) = [ unit ] , [ zero ] -- lexical scope for lambda\n\n -- Had we used the structural representation discussed in Section\n -- 4.2 (\"A Note on Scope Representation\"), Agda could infer the\n -- structure of scope graphs for STLC for us. As summarized in that\n -- discussion, such a representation has other shortcomings, e.g.,\n -- when it comes to dealing with scope graphs that has actual graph\n -- structure (i.e. cyclic paths).\n --\n -- We assume that programs have been analyzed using the scope graph\n -- resolution calculus to construct scope graphs and replace named\n -- references with paths in programs. In future work, we will\n -- explore how to automate this. For now, we construct scope graphs\n -- manually.\n\n -- We load the syntax definition, specialized to our scope graph:\n open Syntax g\n open UsesGraph g\n\n idexpr : Expr zero (unit ⇒ unit)\n idexpr = ƛ {s' = suc zero} (var (path ([]) (here refl)))\n\n open UsesVal Val val-weaken\n \n -- Initial heap with an empty frame that is typed by the root scope:\n init-h : Heap [ zero ]\n init-h = ([] , []) ∷ []\n\n -- id () = ()\n test-idexpr : eval 2 (idexpr · unit) (here refl) init-h ≡ just (_ , _ , unit , _)\n test-idexpr = refl\n \n \nmodule Curry where\n\n open import STLCSF.Semantics 3\n open import ScopesFrames.ScopesFrames 3 Ty\n\n -- Whereas Agda can infer the structure of ordinary type contexts,\n -- the scope graph library represents scope graphs as \"lookup\n -- tables\". Agda cannot straightforwardly infer the structure of a\n -- lookup table. We spell it out.\n\n g : Graph\n g zero = [] , [] -- root scope\n g (suc (suc n)) = [ int ] , [ suc zero ] -- lexical scope for inner lambda\n g (suc n) = [ int ] , [ zero ] -- lexical scope for outer\n\n -- Had we used the structural representation discussed in Section\n -- 4.2 (\"A Note on Scope Representation\"), Agda could infer the\n -- structure of scope graphs for STLC for us. As summarized in that\n -- discussion, such a representation has other shortcomings, e.g.,\n -- when it comes to dealing with scope graphs that has actual graph\n -- structure (i.e. cyclic paths).\n --\n -- We assume that programs have been analyzed using the scope graph\n -- resolution calculus to construct scope graphs and replace named\n -- references with paths in programs. In future work, we will\n -- explore how to automate this. For now, we construct scope graphs\n -- manually.\n\n -- We load the syntax definition, specialized to our scope graph:\n open Syntax g\n open UsesGraph g\n\n -- curried addition: λ x . λ y . y + x\n curry+ : Expr zero (int ⇒ (int ⇒ int))\n curry+ = ƛ {s' = suc zero}\n (ƛ {s' = suc (suc zero)}\n (iop _+_\n (var (path [] (here refl)))\n (var (path ((here refl) ∷ []) (here refl)))))\n\n open UsesVal Val val-weaken\n \n -- Initial heap with an empty frame that is typed by the root scope:\n init-h : Heap [ zero ]\n init-h = ([] , []) ∷ []\n\n -- 1 + 1 = 2\n test-curry+ : eval 3 ((curry+ · (num (+ 1))) · (num (+ 1))) (here refl) init-h\n ≡ just (_ , _ , num (+ 2) , _)\n test-curry+ = refl\n", "meta": {"hexsha": "8494d83f0f4a4a9740226fe9aa9723a59f3f100e", "size": 4106, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/STLCSF/Examples.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/STLCSF/Examples.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/STLCSF/Examples.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": 36.0175438596, "max_line_length": 83, "alphanum_fraction": 0.6660983926, "num_tokens": 1084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.6039318337259583, "lm_q1q2_score": 0.37813632249364615}} {"text": "\nopen import Proc\n\nmodule Mission (param : Param) where\n\nimport Interp\nimport Hear\nopen import Basics\n\nprivate\n open module P = Process param\n open module I = Interp param\n open module H = Hear param\n renaming ( sound to hear-sound\n ; uniq to hear-uniq\n ; complete to hear-complete\n )\n\n\nopen Tran\n\ndata IsRefuse {a : U}{p : Proc a} : Result p -> Set where\n isRefuse : {s : Silent p} -> IsRefuse (refuse s)\n\ncompleteS : {a : U}{p : Proc a}(g : Guard p) ->\n Silent p -> (oracle : Oracle) -> IsRefuse (step g oracle)\ncompleteS og silent-o oracle = isRefuse\ncompleteS (>g f) silent-> oracle = isRefuse\ncompleteS (_ !g _) () oracle\ncompleteS (_ ! _ +g _) () oracle\ncompleteS (g1 ||g g2) (silent-|| s1 s2) oracle\n with step g1 (nextOracle oracle)\n | completeS g1 s1 (nextOracle oracle)\n | step g2 (nextOracle oracle)\n | completeS g2 s2 (nextOracle oracle)\n | prophecy oracle\n... | refuse _ | _ | refuse _ | _ | _ = isRefuse\n... | speak _ | () | speak _ | _ | _\n... | refuse _ | _ | speak _ | () | _\n... | speak _ | () | speak _ | _ | left\n... | speak _ | _ | speak _ | () | right\n... | speak _ | _ | refuse _ | () | _\ncompleteS (φ /|g g) (silent-/| s) oracle with step g oracle\n | completeS g s oracle\n... | speak _ | ()\n... | refuse _ | _ = isRefuse\ncompleteS (defg x g) (silent-def s) oracle with step g oracle\n | completeS g s oracle\n... | speak _ | ()\n... | refuse _ | _ = isRefuse\n\ntheOracle : {a : U}{p : Proc a}{w : LT a}{q : Proc a} ->\n p -! w !-> q -> Oracle\ntheOracle tx-! = anyOracle\ntheOracle tx-+ = anyOracle\ntheOracle (tx-!| s r) = ocons left (theOracle s)\ntheOracle (tx-|! r s) = ocons right (theOracle s)\ntheOracle (tx-/| s) = theOracle s\ntheOracle (tx-def s) = theOracle s\n\ndata IsSpeak {a : U}{p : Proc a}(w : LT a)(q : Proc a) : Result p -> Set where\n isSpeak : {r : p -! w !-> q} -> IsSpeak w q (speak r)\n\ncompleteT : {a : U}{p : Proc a}(g : Guard p){w : LT a}{q : Proc a} ->\n (r : p -! w !-> q) -> IsSpeak w q (step g (\\x -> theOracle r x))\ncompleteT og ()\ncompleteT (>g _) ()\ncompleteT (w !g p) tx-! = isSpeak\ncompleteT (w ! p +g f) tx-+ = isSpeak\ncompleteT (g1 ||g g2) (tx-!| s r) with step g1 (\\x -> theOracle s x)\n | step g2 (\\x -> theOracle s x)\n | completeT g1 s\n | hear-complete g2 r\n... | .(speak _) | refuse _ | isSpeak | refl = isSpeak\n... | .(speak _) | speak _ | isSpeak | refl = isSpeak\ncompleteT (g1 ||g g2) (tx-|! r s) with step g1 (\\x -> theOracle s x)\n | step g2 (\\x -> theOracle s x)\n | hear-complete g1 r\n | completeT g2 s\n... | refuse _ | .(speak _) | refl | isSpeak = isSpeak\n... | speak _ | .(speak _) | refl | isSpeak = isSpeak\ncompleteT (φ /|g g) (tx-/| s) with step g (\\x -> theOracle s x)\n | completeT g s\n... | ._ | isSpeak = isSpeak\ncompleteT (defg x g) (tx-def s) with step g (\\x -> theOracle s x)\n | completeT g s\n... | ._ | isSpeak = isSpeak\n\n\n", "meta": {"hexsha": "e2442095a62f192ed12a883cddd414ed7c22040f", "size": 3434, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "examples/outdated-and-incorrect/cbs/Mission.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": "examples/outdated-and-incorrect/cbs/Mission.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": "examples/outdated-and-incorrect/cbs/Mission.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": 38.1555555556, "max_line_length": 78, "alphanum_fraction": 0.4877693652, "num_tokens": 1045, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.3779781574718489}} {"text": "open import Prelude\n\nmodule Implicits.Substitutions.Lemmas.Type where\n\nopen import Implicits.Syntax.Type\nopen import Implicits.Substitutions\n\nopen import Data.Fin.Substitution\nopen import Data.Fin.Substitution.Lemmas\nopen import Data.Vec.Properties\nopen import Extensions.Substitution\nopen import Data.Star using (Star; ε; _◅_)\nopen import Data.Product hiding (map)\n\ntypeLemmas : TermLemmas Type\ntypeLemmas = record { termSubst = TypeSubst.typeSubst; app-var = refl ; /✶-↑✶ = Lemma./✶-↑✶ }\n where\n open TypeSubst\n module Lemma {T₁ T₂} {lift₁ : Lift T₁ Type} {lift₂ : Lift T₂ Type} where\n\n open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_)\n open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_)\n\n /✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → (simpl (tvar x)) /✶₁ σs₁ ↑✶₁ k ≡ (simpl (tvar x)) /✶₂ σs₂ ↑✶₂ k) →\n ∀ k t → t /✶₁ σs₁ ↑✶₁ k ≡ t /✶₂ σs₂ ↑✶₂ k\n /✶-↑✶ ρs₁ ρs₂ hyp k (simpl (tvar x)) = hyp k x\n /✶-↑✶ ρs₁ ρs₂ hyp k (simpl (tc c)) = begin\n (simpl $ tc c) /✶₁ ρs₁ ↑✶₁ k\n ≡⟨ TypeApp.tc-/✶-↑✶ _ k ρs₁ ⟩\n (simpl $ tc c)\n ≡⟨ sym $ TypeApp.tc-/✶-↑✶ _ k ρs₂ ⟩\n (simpl $ tc c) /✶₂ ρs₂ ↑✶₂ k ∎\n /✶-↑✶ ρs₁ ρs₂ hyp k (simpl (a →' b)) = begin\n (simpl $ a →' b) /✶₁ ρs₁ ↑✶₁ k\n ≡⟨ TypeApp.→'-/✶-↑✶ _ k ρs₁ ⟩\n simpl ((a /✶₁ ρs₁ ↑✶₁ k) →' (b /✶₁ ρs₁ ↑✶₁ k))\n ≡⟨ cong₂ (λ a b → simpl (a →' b)) (/✶-↑✶ ρs₁ ρs₂ hyp k a) (/✶-↑✶ ρs₁ ρs₂ hyp k b) ⟩\n simpl ((a /✶₂ ρs₂ ↑✶₂ k) →' (b /✶₂ ρs₂ ↑✶₂ k))\n ≡⟨ sym (TypeApp.→'-/✶-↑✶ _ k ρs₂) ⟩\n (simpl $ a →' b) /✶₂ ρs₂ ↑✶₂ k\n ∎\n /✶-↑✶ ρs₁ ρs₂ hyp k (a ⇒ b) = begin\n (a ⇒ b) /✶₁ ρs₁ ↑✶₁ k\n ≡⟨ TypeApp.⇒-/✶-↑✶ _ k ρs₁ ⟩ --\n (a /✶₁ ρs₁ ↑✶₁ k) ⇒ (b /✶₁ ρs₁ ↑✶₁ k)\n ≡⟨ cong₂ _⇒_ (/✶-↑✶ ρs₁ ρs₂ hyp k a) (/✶-↑✶ ρs₁ ρs₂ hyp k b) ⟩\n (a /✶₂ ρs₂ ↑✶₂ k) ⇒ (b /✶₂ ρs₂ ↑✶₂ k)\n ≡⟨ sym (TypeApp.⇒-/✶-↑✶ _ k ρs₂) ⟩\n (a ⇒ b) /✶₂ ρs₂ ↑✶₂ k\n ∎\n /✶-↑✶ ρs₁ ρs₂ hyp k (∀' a) = begin\n (∀' a) /✶₁ ρs₁ ↑✶₁ k\n ≡⟨ TypeApp.∀'-/✶-↑✶ _ k ρs₁ ⟩\n ∀' (a /✶₁ ρs₁ ↑✶₁ (suc k))\n ≡⟨ cong ∀' (/✶-↑✶ ρs₁ ρs₂ hyp (suc k) a) ⟩\n ∀' (a /✶₂ ρs₂ ↑✶₂ (suc k))\n ≡⟨ sym (TypeApp.∀'-/✶-↑✶ _ k ρs₂) ⟩\n (∀' a) /✶₂ ρs₂ ↑✶₂ k\n ∎\n\nopen TermLemmas typeLemmas public hiding (var; id)\nopen AdditionalLemmas typeLemmas public\nopen TypeSubst using (module Lifted)\n\n-- The above lemma /✶-↑✶ specialized to single substitutions\n/-↑⋆ : ∀ {T₁ T₂} {lift₁ : Lift T₁ Type} {lift₂ : Lift T₂ Type} →\n let open Lifted lift₁ using () renaming (_↑⋆_ to _↑⋆₁_; _/_ to _/₁_)\n open Lifted lift₂ using () renaming (_↑⋆_ to _↑⋆₂_; _/_ to _/₂_)\n in\n ∀ {n k} (ρ₁ : Sub T₁ n k) (ρ₂ : Sub T₂ n k) →\n (∀ i x → (simpl (tvar x)) /₁ ρ₁ ↑⋆₁ i ≡ (simpl (tvar x)) /₂ ρ₂ ↑⋆₂ i) →\n ∀ i a → a /₁ ρ₁ ↑⋆₁ i ≡ a /₂ ρ₂ ↑⋆₂ i\n/-↑⋆ ρ₁ ρ₂ hyp i a = /✶-↑✶ (ρ₁ ◅ ε) (ρ₂ ◅ ε) hyp i a\n\n-- weakening a simple type gives a simple type\nsimpl-wk : ∀ {ν} k (τ : SimpleType (k + ν)) → ∃ λ τ' → (simpl τ) / wk ↑⋆ k ≡ simpl τ'\nsimpl-wk k (tc x) = , refl\nsimpl-wk k (tvar n) = , var-/-wk-↑⋆ k n\nsimpl-wk k (x →' x₁) = , refl\n", "meta": {"hexsha": "acafd68497036b1ce53c1185d5854984f6eb8160", "size": 3275, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Implicits/Substitutions/Lemmas/Type.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/Substitutions/Lemmas/Type.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/Substitutions/Lemmas/Type.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": 40.4320987654, "max_line_length": 101, "alphanum_fraction": 0.4809160305, "num_tokens": 1659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723316860482762, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.37796907469726887}} {"text": "{- Formal verification of authenticated append-only skiplists in Agda, version 1.0.\n\n Copyright (c) 2021 Victor C Miraldo.\n Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl\n-}\nopen import Data.Unit.NonEta\nopen import Data.Empty\nopen import Data.Sum\nopen import Data.Product\nopen import Data.Product.Properties\nopen import Data.Fin hiding (_<_; _≤_)\nopen import Data.Fin.Properties using () renaming (_≟_ to _≟Fin_)\nopen import Data.Nat renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_)\nopen import Data.Nat.Properties\nopen import Data.List renaming (map to List-map)\nopen import Data.List.Properties using (∷-injective; length-map)\nopen import Data.List.Relation.Unary.Any renaming (map to Any-map)\nopen import Data.List.Relation.Unary.All renaming (lookup to All-lookup; map to All-map)\nopen import Data.List.Relation.Unary.All.Properties hiding (All-map)\nopen import Data.List.Relation.Unary.Any.Properties renaming (map⁺ to Any-map⁺)\nopen import Data.List.Relation.Binary.Pointwise using (decidable-≡)\nopen import Data.Bool hiding (_<_; _≤_)\nopen import Data.Maybe renaming (map to Maybe-map)\nopen import Function\n\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Binary.Core\nopen import Relation.Nullary\n\n-- This module defines the DepRel type, which represents the class of AAOSLs we\n-- consider, and proves properties about any DepRel.\n\nmodule AAOSL.Abstract.DepRel where\n\n open import AAOSL.Lemmas\n open import AAOSL.Abstract.Hash\n\n -- TODO-1: make names same as paper (lvlof -> maxlvl, etc.)\n -- The important bit is that we must have a dependency relation\n -- between these indexes.\n record DepRel : Set₁ where\n field\n lvlof : ℕ → ℕ\n lvlof-z : lvlof 0 ≡ 0\n lvlof-s : ∀ m → 0 < lvlof (suc m)\n\n HopFrom : ℕ → Set\n HopFrom = Fin ∘ lvlof\n\n field\n hop-tgt : {m : ℕ} → HopFrom m → ℕ\n\n hop-tgt-inj : {m : ℕ}{h h' : HopFrom m}\n → hop-tgt h ≡ hop-tgt h'\n → h ≡ h'\n\n hop-< : {m : ℕ}(h : HopFrom m)\n → hop-tgt h < m\n\n -- This property requires that any pair of hops is either nested or\n -- non-overlapping. When nonoverlapping, one end may coincide and\n -- when nested, both ends may coincide. As a diagram,\n --\n -- h₂\n -- ⌜⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⌝\n -- ∣ ∣\n -- ∣ h₁ ∣\n -- ∣ ⌜⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⌝ |\n -- | | | |\n -- tgt h₂ >= f\n fix′-is-fixpoint-combinator f =\n fix′ f ≡⟨⟩\n fix (monotone-function (f ∗)) ≡⟨ fix-is-fixpoint-combinator (f ∗) ⟩∎\n fix (monotone-function (f ∗)) >>= f ∎\n\n fix′-is-least :\n (f : A → A ⊥) →\n (x : A ⊥) → x >>= f ⊑ x → fix′ f ⊑ x\n fix′-is-least f = fix-is-least (monotone-function (f ∗))\n\n -- Taking steps that are \"twice as large\" does not affect the end\n -- result.\n\n fix′-∘ : (f : A → A ⊥) → fix′ (λ x → f x >>= f) ≡ fix′ f\n fix′-∘ f =\n fix′ (λ x → f x >>= f) ≡⟨⟩\n\n fix (monotone-function ((λ x → f x >>= f) ∗)) ≡⟨ cong fix (_↔_.to equality-characterisation-monotone λ (x : A ⊥) →\n\n (x >>= λ y → f y >>= f) ≡⟨ associativity x f f ⟩∎\n x >>= f >>= f ∎) ⟩\n\n fix (monotone-function (f ∗) ∘⊑ monotone-function (f ∗)) ≡⟨ fix-∘ (monotone-function (f ∗)) ⟩∎\n\n fix′ f ∎\n\n -- Unary Scott induction for fix′.\n\n fix′-induction₁ :\n ∀ {p}\n (P : A ⊥ → Type p)\n (P⊥ : P never)\n (P⨆ : ∀ s → (∀ n → P (s [ n ])) → P (⨆ s))\n (f : A → A ⊥) →\n (∀ x → P x → P (x >>= f)) →\n P (fix′ f)\n fix′-induction₁ P P⊥ P⨆ f =\n fix-induction₁ P P⊥ P⨆ ([_⊥→_⊥].monotone-function (f ∗))\n\n-- N-ary Scott induction.\n\nmodule _ {a p} n\n (As : Fin n → Type a)\n (P : (∀ i → As i ⊥) → Type p)\n (P⊥ : P (λ _ → never))\n (P⨆ : ∀ ss → (∀ n → P (λ i → ss i [ n ])) → P (⨆ ∘ ss))\n where\n\n open PAF.N-ary n As (λ i → partiality-algebra (As i)) P P⊥ P⨆ public\n\n fix′-induction :\n (fs : ∀ i → As i → As i ⊥) →\n (∀ xs → P xs → P (λ i → xs i >>= fs i)) →\n P (fix′ ∘ fs)\n fix′-induction fs =\n fix-induction (λ i → [_⊥→_⊥].monotone-function (fs i ∗))\n\n------------------------------------------------------------------------\n-- The fixpoint combinator machinery instantiated with dependent\n-- functions to the partiality monad\n\nmodule _ {a b} (A : Type a) (B : A → Type b) where\n\n -- Partial function transformers.\n\n Trans : Type (a ⊔ b)\n Trans = ((x : A) → B x ⊥) → ((x : A) → B x ⊥)\n\n -- A partiality algebra.\n\n Pi : Partiality-algebra (a ⊔ b) (a ⊔ b) ((x : A) → B x)\n Pi = Π A (partiality-algebra ∘ B)\n\n -- Monotone partial function transformers.\n\n Trans-⊑ : Type (a ⊔ b)\n Trans-⊑ = [ Pi ⟶ Pi ]⊑\n\n private\n\n sanity-check : Trans-⊑ → Trans\n sanity-check = [_⟶_]⊑.function\n\n -- Partial function transformers that are ω-continuous.\n\n Trans-ω : Type (a ⊔ b)\n Trans-ω = [ Pi ⟶ Pi ]\n\nmodule _ {a b} {A : Type a} {B : A → Type b} where\n\n module Trans-⊑ = [_⟶_]⊑ {P₁ = Pi A B} {P₂ = Pi A B}\n module Trans-ω = [_⟶_] {P₁ = Pi A B} {P₂ = Pi A B}\n\n private\n module F = PAF.Fix {P = Pi A B}\n\n -- Applies an increasing sequence of functions to a value.\n\n at :\n (∃ λ (f : ℕ → (x : A) → B x ⊥) → ∀ n x → f n x ⊑ f (suc n) x) →\n (x : A) → ∃ λ (f : ℕ → B x ⊥) → ∀ n → f n ⊑ f (suc n)\n at = Pi.at (partiality-algebra ∘ B)\n\n -- Repeated application of a monotone partial function transformer\n -- to the least element.\n\n app→ : Trans-⊑ A B → ℕ → ((x : A) → B x ⊥)\n app→ = F.app\n\n -- The increasing sequence fix→-sequence f consists of the elements\n -- const never, Trans-⊑.function f (const never), and so on. This\n -- sequence is used in the implementation of fix→.\n\n fix→-sequence : Trans-⊑ A B →\n Partiality-algebra.Increasing-sequence (Pi A B)\n fix→-sequence = F.fix-sequence\n\n -- A fixpoint combinator.\n\n fix→ : Trans-⊑ A B → ((x : A) → B x ⊥)\n fix→ = F.fix\n\n -- The fixpoint combinator produces fixpoints for ω-continuous\n -- arguments.\n\n fix→-is-fixpoint-combinator :\n (f : Trans-ω A B) →\n fix→ (Trans-ω.monotone-function f) ≡\n Trans-ω.function f (fix→ (Trans-ω.monotone-function f))\n fix→-is-fixpoint-combinator = F.fix-is-fixpoint-combinator\n\n -- The result of the fixpoint combinator is pointwise smaller than\n -- or equal to every \"pointwise post-fixpoint\".\n\n fix→-is-least :\n (f : Trans-⊑ A B) →\n ∀ g → (∀ x → Trans-⊑.function f g x ⊑ g x) →\n ∀ x → fix→ f x ⊑ g x\n fix→-is-least = F.fix-is-least\n\n -- Taking steps that are \"twice as large\" does not affect the end\n -- result.\n\n fix→-∘ : (f : Trans-⊑ A B) → fix→ (f ∘⊑ f) ≡ fix→ f\n fix→-∘ = F.fix-∘\n\n-- N-ary Scott induction.\n\nmodule _\n {a b p} n\n (As : Fin n → Type a)\n (Bs : (i : Fin n) → As i → Type b)\n (P : (∀ i → (x : As i) → Bs i x ⊥) → Type p)\n (P⊥ : P (λ _ _ → never))\n (P⨆ : (ss : ∀ i (x : As i) → Increasing-sequence (Bs i x)) →\n (∀ n → P (λ i xs → ss i xs [ n ])) →\n P (λ i xs → ⨆ (ss i xs)))\n (fs : ∀ i → Trans-⊑ (As i) (Bs i)) where\n\n private\n module N = PAF.N-ary n\n (λ i → (x : As i) → Bs i x)\n (λ i → Π (As i) (partiality-algebra ∘ Bs i))\n P\n P⊥\n (λ _ → P⨆ _)\n fs\n\n -- Generalised.\n\n fix→-induction′ :\n (∀ n → P (λ i → app→ (fs i) n) →\n P (λ i → app→ (fs i) (suc n))) →\n P (λ i → fix→ (fs i))\n fix→-induction′ = N.fix-induction′\n\n -- Basic.\n\n fix→-induction :\n ((gs : ∀ i (x : As i) → Bs i x ⊥) →\n P gs → P (λ i → Trans-⊑.function (fs i) (gs i))) →\n P (λ i → fix→ (fs i))\n fix→-induction = N.fix-induction\n\n-- Unary Scott induction.\n\nfix→-induction₁ :\n ∀ {a b p} {A : Type a} {B : A → Type b}\n (P : ((x : A) → B x ⊥) → Type p) →\n P (λ _ → never) →\n ((s : (x : A) → Increasing-sequence (B x)) →\n (∀ n → P (λ x → s x [ n ])) →\n P (λ x → ⨆ (s x))) →\n (f : Trans-⊑ A B) →\n (∀ g → P g → P (Trans-⊑.function f g)) →\n P (fix→ f)\nfix→-induction₁ P P⊥ P⨆ = PAF.fix-induction₁ P P⊥ (λ _ → P⨆ _)\n\n------------------------------------------------------------------------\n-- Some combinators that can be used to construct ω-continuous partial\n-- function transformers, for use with fix→\n\n-- A type used by these combinators.\n\nrecord Partial\n {a b c}\n (A : Type a) (B : A → Type b) (C : Type c) :\n Type (a ⊔ b ⊔ lsuc c) where\n field\n -- A function that is allowed to make \"recursive calls\" of type\n -- (x : A) → B x ⊥.\n\n function : ((x : A) → B x ⊥) → C ⊥\n\n -- The function must be monotone.\n\n monotone : ∀ {rec₁ rec₂} →\n (∀ x → rec₁ x ⊑ rec₂ x) →\n function rec₁ ⊑ function rec₂\n\n -- The function can be turned into an increasing sequence.\n\n sequence : ((x : A) → Increasing-sequence (B x)) →\n Increasing-sequence C\n sequence recs =\n (λ n → function (λ x → recs x [ n ]))\n , (λ n → monotone (λ x → increasing (recs x) n))\n\n field\n -- The function must be ω-continuous in the following sense.\n\n ω-continuous : (recs : (x : A) → Increasing-sequence (B x)) →\n function (⨆ ∘ recs) ≡ ⨆ (sequence recs)\n\n-- The first two arguments of Partial specify the domain and codomain\n-- of \"recursive calls\".\n\nrec : ∀ {a b} {A : Type a} {B : A → Type b} →\n (x : A) → Partial A B (B x)\nrec x = record\n { function = _$ x\n ; monotone = _$ x\n ; ω-continuous = λ _ → refl\n }\n\n-- Turns certain Partial-valued functions into monotone partial\n-- function transformers.\n\ntransformer : ∀ {a b} {A : Type a} {B : A → Type b} →\n ((x : A) → Partial A B (B x)) → Trans-⊑ A B\ntransformer f = record\n { function = λ g x → function (f x) g\n ; monotone = λ g₁⊑g₂ x → monotone (f x) g₁⊑g₂\n }\n where\n open Partial\n\n-- Turns certain Partial-valued functions into ω-continuous partial\n-- function transformers.\n\ntransformer-ω : ∀ {a b} {A : Type a} {B : A → Type b} →\n ((x : A) → Partial A B (B x)) → Trans-ω A B\ntransformer-ω f = record\n { monotone-function = transformer f\n ; ω-continuous = λ _ → ⟨ext⟩ λ x → ω-continuous (f x) _\n }\n where\n open Partial\n\n-- A fixpoint combinator.\n\nfixP : ∀ {a b} {A : Type a} {B : A → Type b} →\n ((x : A) → Partial A B (B x)) → ((x : A) → B x ⊥)\nfixP {A = A} {B} =\n ((x : A) → Partial A B (B x)) ↝⟨ transformer ⟩\n Trans-⊑ A B ↝⟨ fix→ ⟩□\n ((x : A) → B x ⊥) □\n\n-- The fixpoint combinator produces fixpoints.\n\nfixP-is-fixpoint-combinator :\n ∀ {a b} {A : Type a} {B : A → Type b} →\n (f : (x : A) → Partial A B (B x)) →\n fixP f ≡ flip (Partial.function ∘ f) (fixP f)\nfixP-is-fixpoint-combinator =\n fix→-is-fixpoint-combinator ∘ transformer-ω\n\n-- The result of the fixpoint combinator is pointwise smaller than\n-- or equal to every \"pointwise post-fixpoint\".\n\nfixP-is-least :\n ∀ {a b} {A : Type a} {B : A → Type b}\n (f : (x : A) → Partial A B (B x)) →\n ∀ g → (∀ x → Partial.function (f x) g ⊑ g x) →\n ∀ x → fixP f x ⊑ g x\nfixP-is-least = fix→-is-least ∘ transformer\n\n-- Composition of certain Partial-valued functions.\n\ninfixr 40 _∘P_\n\n_∘P_ :\n ∀ {a b} {A : Type a} {B : A → Type b} →\n ((x : A) → Partial A B (B x)) →\n ((x : A) → Partial A B (B x)) →\n ((x : A) → Partial A B (B x))\nPartial.function ((f ∘P g) x) = λ h →\n Partial.function (f x) λ y →\n Partial.function (g y) h\nPartial.monotone ((f ∘P g) x) = λ hyp →\n Partial.monotone (f x) λ y →\n Partial.monotone (g y) hyp\nPartial.ω-continuous ((f ∘P g) x) = λ recs →\n function (f x) (λ y → function (g y) (⨆ ∘ recs)) ≡⟨ cong (function (f x)) (⟨ext⟩ λ y → ω-continuous (g y) recs) ⟩\n function (f x) (λ y → ⨆ (sequence (g y) recs)) ≡⟨ ω-continuous (f x) (λ y → sequence (g y) recs) ⟩∎\n ⨆ (sequence (f x) λ y → sequence (g y) recs) ∎\n where\n open Partial\n\n-- Taking steps that are \"twice as large\" does not affect the end\n-- result.\n\nfixP-∘ : ∀ {a b} {A : Type a} {B : A → Type b}\n (f : (x : A) → Partial A B (B x)) →\n fixP (f ∘P f) ≡ fixP f\nfixP-∘ f =\n fix→ (transformer (f ∘P f)) ≡⟨⟩\n fix→ (transformer f ∘⊑ transformer f) ≡⟨ fix→-∘ (transformer f) ⟩∎\n fix→ (transformer f) ∎\n\n-- N-ary Scott induction.\n\nmodule _\n {a b p} n\n (As : Fin n → Type a)\n (Bs : (i : Fin n) → As i → Type b)\n (P : (∀ i (x : As i) → Bs i x ⊥) → Type p)\n (P⊥ : P (λ _ _ → never))\n (P⨆ : (ss : ∀ i (x : As i) → Increasing-sequence (Bs i x)) →\n (∀ n → P (λ i xs → ss i xs [ n ])) →\n P (λ i xs → ⨆ (ss i xs)))\n (fs : ∀ i (x : As i) → Partial (As i) (Bs i) (Bs i x)) where\n\n -- Generalised.\n\n fixP-induction′ :\n (∀ n → P (λ i → app→ (transformer (fs i)) n) →\n P (λ i → app→ (transformer (fs i)) (suc n))) →\n P (λ i → fixP (fs i))\n fixP-induction′ =\n fix→-induction′ n As Bs P P⊥ P⨆ (transformer ∘ fs)\n\n -- Basic.\n\n fixP-induction :\n ((gs : ∀ i (x : As i) → Bs i x ⊥) →\n P gs → P (λ i xs → Partial.function (fs i xs) (gs i))) →\n P (λ i → fixP (fs i))\n fixP-induction =\n fix→-induction n As Bs P P⊥ P⨆ (transformer ∘ fs)\n\n-- Unary Scott induction.\n\nfixP-induction₁ :\n ∀ {a b p} {A : Type a} {B : A → Type b}\n (P : ((x : A) → B x ⊥) → Type p) →\n P (λ _ → never) →\n ((s : (x : A) → Increasing-sequence (B x)) →\n (∀ n → P (λ x → s x [ n ])) →\n P (λ x → ⨆ (s x))) →\n (f : (x : A) → Partial A B (B x)) →\n (∀ g → P g → P (λ x → Partial.function (f x) g)) →\n P (fixP f)\nfixP-induction₁ P P⊥ P⨆ f =\n fix→-induction₁ P P⊥ P⨆ (transformer f)\n\n-- Equality characterisation lemma for Partial.\n\nequality-characterisation-Partial :\n ∀ {a b c} {A : Type a} {B : A → Type b} {C : Type c}\n {f g : Partial A B C} →\n (∀ rec → Partial.function f rec ≡ Partial.function g rec) ↔\n f ≡ g\nequality-characterisation-Partial {f = f} {g} =\n (∀ rec → function f rec ≡ function g rec) ↔⟨ Eq.extensionality-isomorphism bad-ext ⟩\n function f ≡ function g ↝⟨ ignore-propositional-component\n (Σ-closure 1\n (implicit-Π-closure ext 1 λ _ →\n implicit-Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n ⊑-propositional) λ _ →\n Π-closure ext 1 λ _ →\n ⊥-is-set) ⟩\n (function f , _) ≡ (function g , _) ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ lemma) ⟩□\n f ≡ g □\n where\n open Partial\n\n lemma :\n Partial _ _ _\n ↔\n ∃ λ f →\n ∃ λ (_ : ∀ {rec₁ rec₂} → (∀ x → rec₁ x ⊑ _) → f rec₁ ⊑ _) → _\n lemma = record\n { surjection = record\n { logical-equivalence = record\n { to = λ x → function x , monotone x , ω-continuous x\n ; from = λ { (f , m , ω) → record\n { function = f\n ; monotone = λ {rec₁ rec₂} → m {rec₁ = rec₁} {rec₂ = rec₂}\n ; ω-continuous = ω\n } }\n }\n ; right-inverse-of = λ _ → refl\n }\n ; left-inverse-of = λ _ → refl\n }\n\n-- \"Non-recursive\" computations can be converted into possibly\n-- recursive ones.\n\nnon-recursive :\n ∀ {a b c} {A : Type a} {B : A → Type b} {C : Type c} →\n C ⊥ → Partial A B C\nnon-recursive x = record\n { function = const x\n ; monotone = const (x ■)\n ; ω-continuous = λ _ →\n x ≡⟨ sym ⨆-const ⟩∎\n ⨆ (constˢ x) ∎\n }\n\ninstance\n\n -- Partial A B is a monad.\n\n partial-raw-monad : ∀ {a b c} {A : Type a} {B : A → Type b} →\n Raw-monad (Partial {c = c} A B)\n Raw-monad.return partial-raw-monad x = non-recursive (return x)\n Raw-monad._>>=_ partial-raw-monad x f = record\n { function = λ rec →\n function x rec >>=′ λ y →\n function (f y) rec\n ; monotone = λ rec⊑rec →\n monotone x rec⊑rec >>=-mono λ y →\n monotone (f y) rec⊑rec\n ; ω-continuous = λ recs →\n (function x (⨆ ∘ recs) >>=′ λ y → function (f y) (⨆ ∘ recs)) ≡⟨ cong₂ _>>=′_ (ω-continuous x recs)\n (⟨ext⟩ λ y → ω-continuous (f y) recs) ⟩\n (⨆ (sequence x recs) >>=′ λ y → ⨆ (sequence (f y) recs)) ≡⟨ ⨆->>= ⟩\n\n ⨆ ( (λ n →\n function x (λ z → recs z [ n ]) >>=′ λ y →\n ⨆ (sequence (f y) recs))\n , _\n ) ≡⟨ ⨆>>=⨆≡⨆>>= (sequence x recs)\n (λ y → sequence (f y) recs) ⟩∎\n ⨆ ( (λ n → function x (λ z → recs z [ n ]) >>=′ λ y →\n function (f y) (λ z → recs z [ n ]))\n , _\n ) ∎\n }\n where\n open Partial\n\n partial-monad : ∀ {a b c} {A : Type a} {B : A → Type b} →\n Monad (Partial {c = c} A B)\n Monad.raw-monad partial-monad = partial-raw-monad\n\n Monad.left-identity partial-monad _ f =\n _↔_.to equality-characterisation-Partial\n (λ h → left-identity _ (λ y → Partial.function (f y) h))\n\n Monad.right-identity partial-monad _ =\n _↔_.to equality-characterisation-Partial\n (λ _ → right-identity _)\n\n Monad.associativity partial-monad x _ _ =\n _↔_.to equality-characterisation-Partial\n (λ h → associativity (Partial.function x h) _ _)\n", "meta": {"hexsha": "a47665782f9224ca0cb16c17e9d80b69a11380c4", "size": 16990, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Partiality-monad/Inductive/Fixpoints.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/Partiality-monad/Inductive/Fixpoints.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/Partiality-monad/Inductive/Fixpoints.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": 32.0566037736, "max_line_length": 130, "alphanum_fraction": 0.4875220718, "num_tokens": 5946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.5964331462646254, "lm_q1q2_score": 0.3777868764416802}} {"text": "-- This is mostly based on the ``Dependently-typed Functional Programming''\n-- lecture from Pierre-Evariste Dagand (17--18, MPRI).\n-- ref: https://gitlab.inria.fr/fpottier/mpri-2.4-public/\n\nmodule lambda.stlc where\n\nopen import Relation.Binary.PropositionalEquality\nopen import Function hiding (id)\nopen import Data.Product\nopen import Agda.Builtin.Unit\n\nopen import lambda.stack\n\n\ninfixr 50 _⇒_\n\ndata type : Set where\n unit : type\n _⇒_ : type → type → type\n\n\ncontext : Set\ncontext = stack type\n\n\ndata _⊢_ (Γ : context) : type → Set where\n lam : ∀ {A B} → Γ ▸ A ⊢ B → Γ ⊢ A ⇒ B\n var : ∀ {A} → A ∈ Γ → Γ ⊢ A\n app : ∀ {A B} → Γ ⊢ A ⇒ B → Γ ⊢ A → Γ ⊢ B\n tt : Γ ⊢ unit\n\n\nmodule norm where\n\n infix 30 _⊢ⁿ_\n infix 30 _⊢ᵉ_\n infix 40 _⟶_\n infix 45 _⟦⇒⟧_\n infix 50 _⟦×⟧_\n\n data _⊢ᵉ_ (Γ : context) : type → Set\n data _⊢ⁿ_ (Γ : context) : type → Set\n\n data _⊢ⁿ_ (Γ : context) where\n lam : ∀ {A B} → Γ ▸ A ⊢ⁿ B → Γ ⊢ⁿ A ⇒ B\n tt : Γ ⊢ⁿ unit\n ground : Γ ⊢ᵉ unit → Γ ⊢ⁿ unit\n\n data _⊢ᵉ_ (Γ : context) where\n var : ∀ {A} → A ∈ Γ → Γ ⊢ᵉ A\n app : ∀ {A B} → Γ ⊢ᵉ A ⇒ B → Γ ⊢ⁿ A → Γ ⊢ᵉ B\n\n ⌊_⌋ⁿ : ∀ {Γ A} → Γ ⊢ⁿ A → Γ ⊢ A\n ⌊_⌋ᵉ : ∀ {Γ A} → Γ ⊢ᵉ A → Γ ⊢ A\n\n ⌊ lam x ⌋ⁿ = lam ⌊ x ⌋ⁿ\n ⌊ tt ⌋ⁿ = tt\n ⌊ ground x ⌋ⁿ = ⌊ x ⌋ᵉ\n\n ⌊ var x ⌋ᵉ = var x\n ⌊ app x y ⌋ᵉ = app ⌊ x ⌋ᵉ ⌊ y ⌋ⁿ\n\n\n record sem : Set₁ where\n field\n _⊢ : context → Set\n ren : ∀ {Γ Δ} → Γ ⊇ Δ → Δ ⊢ → Γ ⊢\n\n _⟶_ : (A B : sem) → Set\n A ⟶ B = ∀ {Γ} → Γ ⊢A → Γ ⊢B\n where open sem A renaming (_⊢ to _⊢A)\n open sem B renaming (_⊢ to _⊢B)\n\n renameⁿ : ∀ {Γ Δ T} → Γ ⊇ Δ → Δ ⊢ⁿ T → Γ ⊢ⁿ T\n renameᵉ : ∀ {Γ Δ T} → Γ ⊇ Δ → Δ ⊢ᵉ T → Γ ⊢ᵉ T\n\n renameⁿ wk (lam b) = lam (renameⁿ (keep wk) b)\n renameⁿ wk (ground grnd) = ground (renameᵉ wk grnd)\n renameⁿ wk tt = tt\n\n renameᵉ wk (var v) = var (shift wk v)\n renameᵉ wk (app f s) = app (renameᵉ wk f) (renameⁿ wk s)\n\n renameⁿ-id : ∀ {Γ T} → (x : Γ ⊢ⁿ T) → renameⁿ id x ≡ x\n renameᵉ-id : ∀ {Γ T} → (x : Γ ⊢ᵉ T) → renameᵉ id x ≡ x\n\n renameⁿ-id (lam x) = cong lam (renameⁿ-id x)\n renameⁿ-id tt = refl\n renameⁿ-id (ground x) = cong ground (renameᵉ-id x)\n\n renameᵉ-id (var x) = cong var (shift-id x)\n renameᵉ-id (app x y) = cong₂ app (renameᵉ-id x) (renameⁿ-id y)\n\n semⁿ : type → sem\n semⁿ T = record {\n _⊢ = λ Γ → Γ ⊢ⁿ T ;\n ren = renameⁿ }\n\n semᵉ : type → sem\n semᵉ T = record {\n _⊢ = λ Γ → Γ ⊢ᵉ T ;\n ren = renameᵉ }\n\n ⟦unit⟧ : sem\n ⟦unit⟧ = semⁿ unit\n\n ⟦tt⟧ : ∀ {P} → P ⟶ ⟦unit⟧\n ⟦tt⟧ ρ = tt\n\n _⟦⇒⟧_ : sem → sem → sem\n P ⟦⇒⟧ Q = record {\n _⊢ = λ Γ → ∀ {Δ} → Δ ⊇ Γ → Δ ⊢P → Δ ⊢Q ;\n ren = λ wk₁ k wk₂ → k (wk₂ ∘⊇ wk₁) }\n where open sem P renaming (_⊢ to _⊢P)\n open sem Q renaming (_⊢ to _⊢Q)\n\n\n _⟦×⟧_ : sem → sem → sem\n P ⟦×⟧ Q = record { _⊢ = λ Γ → (Γ ⊢P) × (Γ ⊢Q)\n ; ren = λ { wk (x , y) → ( ren-P wk x , ren-Q wk y ) } }\n where open sem P renaming (_⊢ to _⊢P ; ren to ren-P)\n open sem Q renaming (_⊢ to _⊢Q ; ren to ren-Q)\n\n ⟦lam⟧ : ∀ {P Q R} → P ⟦×⟧ Q ⟶ R → P ⟶ Q ⟦⇒⟧ R\n ⟦lam⟧ {P} η p = λ wk q → η (ren-P wk p , q)\n where open sem P renaming (ren to ren-P)\n\n ⟦app⟧ : ∀ {P Q R} → P ⟶ Q ⟦⇒⟧ R → P ⟶ Q → P ⟶ R\n ⟦app⟧ η μ = λ px → η px id (μ px)\n\n ⟦_⟧ : type → sem\n ⟦ unit ⟧ = ⟦unit⟧\n ⟦ S ⇒ T ⟧ = ⟦ S ⟧ ⟦⇒⟧ ⟦ T ⟧\n\n ⊤̂ : sem\n ⊤̂ = record { _⊢ = λ _ → ⊤\n ; ren = λ _ _ → tt }\n\n ⟦_⟧c : (Γ : context) → sem\n ⟦ ε ⟧c = ⊤̂\n ⟦ Γ ▸ T ⟧c = ⟦ Γ ⟧c ⟦×⟧ ⟦ T ⟧\n\n _⟦⊢⟧_ : context → type → Set\n Γ ⟦⊢⟧ T = ⟦ Γ ⟧c ⟶ ⟦ T ⟧\n\n lookup : ∀ {Γ T} → T ∈ Γ → Γ ⟦⊢⟧ T\n lookup here (_ , v) = v\n lookup (there x) (γ , _) = lookup x γ\n\n eval : ∀ {Γ T} → Γ ⊢ T → Γ ⟦⊢⟧ T\n eval {Γ} {A ⇒ B} (lam x) = ⟦lam⟧ {⟦ Γ ⟧c} {⟦ A ⟧} {⟦ B ⟧} (eval x)\n eval (var x) = lookup x\n eval {Γ} {B} (app {A} x y) = ⟦app⟧ {⟦ Γ ⟧c} {⟦ A ⟧} {⟦ B ⟧} (eval x) (eval y)\n eval {Γ} tt = ⟦tt⟧ {⟦ Γ ⟧c}\n\n\n [_]⊢_ : context → type → Set\n [ Γ ]⊢ T = Γ ⊢⟦T⟧\n where open sem ⟦ T ⟧ renaming (_⊢ to _⊢⟦T⟧)\n\n [_]⊢c_ : context → context → Set\n [ Γ ]⊢c Δ = Γ ⊢⟦Δ⟧c\n where open sem ⟦ Δ ⟧c renaming (_⊢ to _⊢⟦Δ⟧c)\n\n reify : ∀ {T Γ} → [ Γ ]⊢ T → Γ ⊢ⁿ T\n reflect : ∀ {Γ} → (T : type) → Γ ⊢ᵉ T → [ Γ ]⊢ T\n\n reify {unit} v = v\n reify {A ⇒ B} x = lam (reify (x (skip id) (reflect A (var here))))\n\n reflect unit x = ground x\n reflect (A ⇒ B) x = λ w s → reflect B (app (ren w x) (reify s))\n where open sem (semᵉ (A ⇒ B))\n\n reify-id : ∀ {Γ T} → Γ ⟦⊢⟧ T → Γ ⊢ⁿ T\n reify-id {Γ} x = reify (x (id-c Γ))\n where\n open sem\n id-c : ∀ Γ → [ Γ ]⊢c Γ\n id-c ε = tt\n id-c (Γ ▸ T) = ren ⟦ Γ ⟧c (skip id) (id-c Γ) , reflect T (var here)\n\n norm : ∀ {Γ T} → Γ ⊢ T → Γ ⊢ⁿ T\n norm = reify-id ∘ eval\n", "meta": {"hexsha": "b04210264d5275597a4b2ab07e4001c304e3d7d1", "size": 4635, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lambda/stlc.agda", "max_stars_repo_name": "Lapin0t/lambda", "max_stars_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2", "max_stars_repo_licenses": ["Apache-2.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": "lambda/stlc.agda", "max_issues_repo_name": "Lapin0t/lambda", "max_issues_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2", "max_issues_repo_licenses": ["Apache-2.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": "lambda/stlc.agda", "max_forks_repo_name": "Lapin0t/lambda", "max_forks_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0540540541, "max_line_length": 79, "alphanum_fraction": 0.4724919094, "num_tokens": 2404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.37777508088271}} {"text": "\nmodule proofs where\n\nopen import univ\nopen import cwf\nopen import Base\nopen import Nat\nopen import help\n\n{-\nlem-id∘ : {Γ Δ : Con}(σ : Γ ─→ Δ) -> id ∘ σ == σ\nlem-id∘ (el < σ , pσ >) = eq \\x -> ref\n\nlem-∘id : {Γ Δ : Con}(σ : Γ ─→ Δ) -> σ ∘ id == σ\nlem-∘id (el < σ , pσ >) = eq \\x -> ref\n\nlem-∘assoc : {Γ Δ Θ Ξ : Con}(σ : Θ ─→ Ξ)(δ : Δ ─→ Θ)(θ : Γ ─→ Δ) ->\n (σ ∘ δ) ∘ θ == σ ∘ (δ ∘ θ)\nlem-∘assoc (el < σ , pσ >) (el < δ , pδ >) (el < θ , pθ >) = eq \\x -> ref\n-}\n\nlem-/∘ : {Γ Δ Θ : Con}(A : Type Γ)(σ : Δ ─→ Γ)(δ : Θ ─→ Δ) ->\n A / σ ∘ δ =Ty A / σ / δ\nlem-/∘ A (el < _ , _ >) (el < _ , _ >) = eqTy \\x -> refS\n\n{-\nlem-//id : {Γ : Con}{A : Type Γ}{u : Elem Γ A} -> u // id =El castElem lem-/id u\nlem-//id {Γ}{A}{elem (el < u , pu >)} = eqEl (eq prf)\n where\n prf : (x : El Γ) -> _\n prf x =\n chain> u x\n === _ << u (refS << x) by pu (sym (ref<< x))\n === _ << u (refS << x) by pfi _ _ _\n where open module C11 = Chain _==_ (ref {_}) (trans {_})\n\nlem-//∘ : {Γ Δ Θ : Con}{A : Type Γ}(u : Elem Γ A)(σ : Δ ─→ Γ)(δ : Θ ─→ Δ) ->\n u // σ ∘ δ =El castElem (lem-/∘ A σ δ) (u // σ // δ)\nlem-//∘ {Γ}{Δ}{Θ} (elem (el < u , pu >)) σ'@(el < σ , _ >) δ'@(el < δ , _ >) = eqEl (eq prf)\n where\n prf : (x : El Θ) -> _\n prf x =\n chain> u (σ (δ x))\n === _ << u (σ (δ (refS << x))) by pu (p─→ σ' (p─→ δ' (sym (ref<< x))))\n === _ << u (σ (δ (refS << x))) by pfi _ _ _\n where open module C12 = Chain _==_ (ref {_}) (trans {_})\n\nlem-wk∘σ,,u : {Γ Δ : Con}{A : Type Γ}(σ : Δ ─→ Γ)(u : Elem Δ (A / σ)) ->\n wk ∘ (σ ,, u) == σ\nlem-wk∘σ,,u (el < σ , pσ >) (elem (el < u , pu >)) = eq \\x -> ref\n\nlem-/wk∘σ,,u : {Γ Δ : Con}(A : Type Γ)(σ : Δ ─→ Γ)(u : Elem Δ (A / σ)) ->\n A / wk / (σ ,, u) =Ty A / σ\nlem-/wk∘σ,,u A (el < σ , pσ >) (elem (el < u , pu >)) = eqTy \\x -> refS\n\nlem-vz/σ,,u : {Γ Δ : Con}{A : Type Γ}(σ : Δ ─→ Γ)(u : Elem Δ (A / σ)) ->\n vz // (σ ,, u) =El castElem (lem-/wk∘σ,,u A σ u) u\nlem-vz/σ,,u (el < σ , pσ >) (elem (el < u , pu >)) = eqEl (eq \\x -> prf x)\n where\n prf : (x : El _) -> u x == _ << u (refS << x)\n prf x =\n chain> u x\n === _ << u (refS << x) by pu (sym (ref<< x))\n === _ << u (refS << x) by pfi _ _ _\n where open module C15 = Chain _==_ (ref {_}) (trans {_})\n\nlem-σ,,u∘ : {Γ Δ Θ : Con}{A : Type Γ}\n (σ : Δ ─→ Γ)(u : Elem Δ (A / σ))(δ : Θ ─→ Δ) ->\n (σ ,, u) ∘ δ == (σ ∘ δ ,, castElem (lem-/∘ A σ δ) (u // δ))\nlem-σ,,u∘ (el < σ , _ >) (elem (el < u , pu >)) δ'@(el < δ , _ >) =\n eq \\x -> eq < ref , prf x >\n where\n prf : (x : El _) -> u (δ x) == _ << _ << u (δ (refS << x))\n prf x =\n chain> u (δ x)\n === _ << u (δ (refS << x)) by pu (p─→ δ' (sym (ref<< x)))\n === _ << _ << u (δ (refS << x)) by sym (casttrans _ _ _ _)\n where open module C15 = Chain _==_ (ref {_}) (trans {_})\n\nlem-wk,,vz : {Γ : Con}{A : Type Γ} -> (wk ,, vz) == id {Γ , A}\nlem-wk,,vz {Γ}{A} = eq prf\n where\n prf : (x : El (Γ , A)) -> _\n prf (el < x , y >) = ref\n-}\n\nlem-Π/ : {Γ Δ : Con}{A : Type Γ}(B : Type (Γ , A))(σ : Δ ─→ Γ) ->\n Π A B / σ =Ty Π (A / σ) (B / (σ ∘ wk ,, castElem (lem-/∘ A σ wk) vz))\nlem-Π/ B (el < σ , pσ >) =\n eqTy \\x -> eqS < refS , (\\y -> pFam B (eq < ref , prf x y >)) >\n where\n postulate prf : (x : El _)(y : El _) -> y == _ << _ << _ << _ << y\n-- prf x y =\n-- chain> y\n-- === _ << _ << y by sym (castref2 _ _ y)\n-- === _ << _ << _ << y by trans<< _ _ _\n-- === _ << _ << _ << _ << y by trans<< _ _ _\n-- where open module C16 = Chain _==_ (ref {_}) (trans {_})\n\n{-\nlem-β : {Γ : Con}{A : Type Γ}{B : Type (Γ , A)}\n\t(v : Elem (Γ , A) B)(u : Elem Γ A) ->\n\t(ƛ v) ∙ u =El v // [ u ]\nlem-β {Γ}{A}{B} (elem (el < v , pv >)) (elem (el < u , pu >)) = eqEl (eq \\x -> prf x _ _)\n where\n prf : (x : El Γ)(q : _ =S _)(p : _ =S _) ->\n\t p << v (el < x , u x >) == v (el < x , q << u (refS << x) >)\n prf x q p =\n chain> p << v (el < x , u x >)\n\t === p << q0 << v (el < x , q1 << u (refS << x) >)\n\t by p<< p (pv (eqSnd (pu (sym (ref<< x)))))\n\t === q2 << v (el < x , q1 << u (refS << x) >)\n\t by sym (trans<< p q0 _)\n\t === q2 << q3 << v (el < x , q << u (refS << x) >)\n\t by p<< q2 (pv (eqSnd (pfi q1 q _)))\n\t === v (el < x , q << u (refS << x) >)\n\t by castref2 q2 q3 _\n where\n\topen module C17 = Chain _==_ (ref {_}) (trans {_})\n\tq0 = _\n\tq1 = _\n\tq2 = _\n\tq3 = _\n\n-}\n", "meta": {"hexsha": "7be982896f1d739d708d4cc0a68084b44d127133", "size": 4447, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "examples/outdated-and-incorrect/univ/proofs.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": "examples/outdated-and-incorrect/univ/proofs.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": "examples/outdated-and-incorrect/univ/proofs.agda", "max_forks_repo_name": "masondesu/agda", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "avg_line_length": 35.2936507937, "max_line_length": 92, "alphanum_fraction": 0.3854283787, "num_tokens": 2017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217431943271999, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.3777750746171601}} {"text": "{-# OPTIONS --cubical --no-import-sorts #-}\n\nmodule Hit where\n\n-- open import Cubical.Core.Everything\nopen import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ)\n-- open import Cubical.Foundations.Equiv.HalfAdjoint\n-- open import Cubical.Data.Sigma.Properties\n\n-- https://en.wikipedia.org/wiki/Inductive_type#Higher_inductive_types\n\n-- private\n-- ℓ : Level\n\n_ : (A B : Type₀) → Type₁\n_ = λ a b → a ≡ b\n\n-- https://www.youtube.com/watch?v=AZ8wMIar-_c\n\n-- List becomes a normal form of this\ndata FreeMonoid' (A : Type₀) : Type₀ where\n [_]' : A → FreeMonoid' A\n ε' : FreeMonoid' A\n _*'_ : FreeMonoid' A → FreeMonoid' A → FreeMonoid' A\n assoc' : ∀ x y z → x *' (y *' z) ≡ (x *' y) *' z\n\n\ndata List (A : Type) : Type where\n [] : List A\n _∷_ : A → List A → List A\n\n-- debug fonts\n-- see which fonts are \"in effect\" with\n-- fc-match --verbose\n-- https://wiki.archlinux.org/index.php/X_Logical_Font_Description\n-- Two different font systems are used by X11:\n-- - the older or core X Logical Font Description, XLFD,\n-- - and the newer X FreeType, Xft, systems (see An Xft Tutorial for font names format).\n-- https://keithp.com/~keithp/render/Xft.tutorial\n\n-- λ-calculus\n-- Cockx 2019 - Hack your type theory with rewrite rules\n-- https://jesper.sikanda.be/posts/hack-your-type-theory.html\n-- email thread from Georgi Lyubenov (24.03.20, 23:28 ff) about sized lambdas \"How can I implement naive sized lambdas?\"\n-- email thread from Joey Eremondi (22.04.20, 06:07 ff) about variable binding \"What do you use for variable binding in 2020?\"\n\n-- literate agda markdown -> latex\n-- https://lists.chalmers.se/pipermail/agda/2019/011286.html\n-- https://stackoverflow.com/questions/58339725/literate-agda-in-markdown-format-to-latex-via-pandoc\n-- https://jesper.sikanda.be/posts/literate-agda.html\n-- Jesper Cockx' mail from 09.07.19, 18:35\n\n-- an example file/paper that shows how to use cubical:\n-- /home/christianl/agda/cubical/Cubical/Papers/Synthetic.agda\n-- Cubical synthetic homotopy theory\n-- Mörtberg and Pujet, „Cubical synthetic homotopy theory“.\n-- https://dl.acm.org/doi/abs/10.1145/3372885.3373825\n\n-- the github repository recommends\n-- Vezzosi 2019 - Cubical Agda: A Dependently Typed ProgrammingLanguage with Univalence and Higher Inductive Types\n-- https://dl.acm.org/doi/pdf/10.1145/3341691\n\n-- there is also the very comprehensive\n-- https://arxiv.org/pdf/1911.00580.pdf\n-- Martín Hötzel Escardó 2020 - Introduction to Univalent Foundations of Mathematics with Agda\n-- clickable html version: https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html\n-- https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#sns\n-- A structure identity principle for a standard notion of structure\n\n\n-- some useful, recent stuff from the mailing list:\n-- https://ncatlab.org/nlab/show/archimedean+field\n-- An archimedean field is an ordered field in which every element is bounded above by a natural number.\n-- Q: why refl {x} and refl {_} {_} {x} behave differently according to context\n-- A: (U. Norell 01.05.20, 23:08)\n-- pattern reflpv x = refl {x = x}\n-- you are not allowed to pattern match on datatype parameters, since they are not stored in the constructor. In a right-hand side you can give the parameters to guide the type checker, but they are thrown out during elaboration.\n-- Andreas Nuyts 26.04.20, 22:34\n-- a case in a pattern matching definition gets a light grey background when it doesn't hold as a definitional equation, typically because it is a fallthrough case and further matching of the arguments is necessary to establish that none of the prior cases apply\n-- Q: what do I assume/not assume when using --cubical?\n-- A: (Andreas Abel 24.04.20, 15:04) That is a long story. One thing is that in --cubical, the identity type is a primitive (not a data), and you cannot match on refl.\n-- https://agda.readthedocs.io/en/v2.6.1/tools/command-line-options.html?highlight=infective#consistency-checking-of-options-used\n-- An infective option is an option that if used in one module, must be used in all modules that depend on this module.\n-- A coinfective option is an option that if used in one module, must be used in all modules that this module depends on.\n-- (Orestis Melkonian 22.12.19, 21:11) inspect MAlonzo haskell code's variable names with https://github.com/agda/agda-ghc-names\n-- (James Wood 22.12.19, 21:28)\n-- Note that record field names can also overlap if they are applied directly to a record value.\n-- The theory behind this is in bidirectional type checking, and how a term having its type checked (rather than inferred) may be ambiguous without the information from the type.\n-- The same mechanism allows λ to be reused for dimension abstraction in cubical Agda (because it is a constructor).\n-- In short, overloading is fine in the following cases:\n-- - Everything being overloaded is a constructor, and there is an obvious type to check the resulting construction against.\n-- - Everything being overloaded is a field, and there is an obvious record type that the field is destructing.\n-- Outside of these cases, overloading fails.\n-- You might notice also that the agda2-infer-type command will usually fail to infer the type of a construction of which the head is an overloaded constructor.\n-- This is because Agda really wants to check the construction, rather than inferring a type for it.\n-- It just happens that when the constructor is not overloaded, it's easier to make progress, because that gives just enough to check the construction against.\n-- Q: Copattern match in emacs\n-- A: (James Wood 05.11.19, 22:41) If I understand the question correctly, it's the usual C-c C-c for case-splitting, but on an empty hole and followed immediately by RET, rather than entering a variable name. The intermediate prompt is “pattern variables to case (empty for split on result)”. It's splitting on the result that you want.\n-- Constructor names can overlap; the right one will be chosen on usage depending on the expected type.\n-- Note that other kind of names cannot overlap (e.g. definition names, etc..).\n\n-- the cubical std-lib is described in a blog post from Andreas Mörtberg\n-- https://homotopytypetheory.org/2018/12/06/cubical-agda/\n-- isomorphisms are equivalences (i.e. have contractible fibers)\n-- Hedberg’s theorem (types with decidable equality are sets)\n-- The main things that the CCHM cubical type theory extends dependent type theory with are:\n-- 1. An interval pretype\n-- 2. Kan operations\n-- 3. Glue types\n-- 4. Cubical identity types\n\nopen import Cubical.Structures.CommRing\nopen import Cubical.Relation.Nullary.Base -- ¬_\nopen import Cubical.Relation.Binary.Base\n-- open import Cubical.Data.Prod.Base renaming (_×_ to _×'_)\n-- NOTE: Cubical.Core.Sigma uses Agda.Builtin.Sigma\n-- open import Agda.Builtin.Sigma renaming (_×_ to _×ᵇ_)\nopen import Cubical.Data.Sum.Base\nopen import Cubical.Data.Sigma.Base -- Σ-types are defined in Core/Primitives as they are needed for Glue types.\n\n-- PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ\n--\n-- We have a variable name in `(λ i → A)` as a hint for case splitting.\n--\n-- Path : ∀ {ℓ} (A : Set ℓ) → A → A → Set ℓ\n-- Path A a b = PathP (λ _ → A) a b\n--\n-- _≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ\n-- _≡_ {A = A} = PathP (λ i → A)\n\n-- Cubical.Foundations.Id \n--\n-- transport : ∀ (B : A → Type ℓ') {x y : A} → x ≡ y → B x → B y\n-- transport B {x} p b = J (λ y p → B y) b p\n-- \n-- _⁻¹ : {x y : A} → x ≡ y → y ≡ x\n-- _⁻¹ {x = x} p = J (λ z _ → z ≡ x) refl p\n-- \n-- ap : ∀ {B : Type ℓ'} (f : A → B) → ∀ {x y : A} → x ≡ y → f x ≡ f y\n-- ap f {x} = J (λ z _ → f x ≡ f z) refl\n-- \n-- _∙_ : ∀ {x y z : A} → x ≡ y → y ≡ z → x ≡ z\n-- _∙_ {x = x} p = J (λ y _ → x ≡ y) p\n\nrefl1 : ∀ {ℓ} {A : Type ℓ} {x : A} → Path A x x\nrefl1 {x = x} = λ i → x\n\nrefl2 : ∀ {ℓ} {A : Type ℓ} {x : A} → PathP (λ _ → A) x x\nrefl2 {x = x} = λ i → x\n\nrefl3 : ∀{ℓ} {A : Type ℓ} {x : A} → PathP (λ _ → A) x x\nrefl3 {x = x} = λ _ → x\n\nsym1 : ∀ {ℓ} {A : Type ℓ} {x y : A} → x ≡ y → y ≡ x\nsym1 p = λ i → p (~ i)\n\ncong1 : ∀ {ℓ} {A : Type ℓ} {x y : A} {B : A → Type ℓ}\n (f : (a : A) → B a)\n (p : x ≡ y)\n --------------------------------------------\n → PathP (λ i → B (p i)) (f x) (f y)\ncong1 f p i = f (p i)\n\ncong2 : ∀ {ℓ} {A : Type ℓ} {x y : A} {B : A → Type ℓ}\n (f : (a : A) → B a)\n (p : PathP (λ i → A ) x y )\n ----------------------------------------------\n → ( PathP (λ i → B (p i)) (f x) (f y))\ncong2 f p i = f (p i)\n\n-- see \"Propositional truncation\" https://homotopytypetheory.org/2018/12/06/cubical-agda for\n-- data ∥_∥ {ℓ} (A : Set ℓ) : Set ℓ where\n-- ∣_∣ : A → ∥ A ∥\n-- squash : ∀ (x y : ∥ A ∥) → x ≡ y\n-- see https://planetmath.org/37propositionaltruncation\n\nopen import Cubical.HITs.PropositionalTruncation -- for `|_|` and `squash`\n\ntest1 : {Carrier : Type} -> ∃[ x ∈ Carrier ] x ≡ x → Carrier\ntest1 ∣ x , x≡x ∣ = x\n-- Goal: Carrier\n-- ———— Boundary ——————————————————————————————————————————————\n-- i = i0 ⊢ test1 x\n-- i = i1 ⊢ test1 y\n-- ———— Constraints ———————————————————————————————————————————\n-- test1 x = ?0 (i = i0) : Carrier\n-- test1 y = ?0 (i = i1) : Carrier\ntest1 (squash x y i) = {! test1 x!}\n\ntest2 : {A : Type} → (x y : A) → x ≡ y → A\n-- test2 x y x≡y = {! x≡y!}\ntest2 x y p = p i0\n\n-- test4 : I → Type\n-- test4 i = {!!}\n\ntest5a : {A : Type} {P : A → Type} → (x y : A) → x ≡ y → P x → P y\ntest5a {A} {P} x y p px = transport (λ i → P (p i)) px \n\ntest5b : {A : Type}\n → {P : A → Type}\n → (x y : A)\n → PathP (λ _ → A) x y -- x ≡ y\n → P x\n --------------------------\n → P y\ntest5b {A} {P} x y x≡y Px = transport {A = P x} Px≡Py Px where\n -- transport gives us `P x → P y`, but we need to feed it `P x ≡ P y`\n Px≡Py : P x ≡ P y\n Px≡Py = cong P x≡y\n -- this is almost what `isProp P` would give us\n -- isProp : ∀ {ℓ} → Type ℓ → Type ℓ\n -- isProp A = (x y : A) → x ≡ y\n -- but we need something like `∀(x y : A) → P x ≡ P y`\n -- well, no. `cong P x≡y` gives us `P x ≡ P y`\n -- it is different from non-cubical agda, where `x ≡ y` was sufficient, no matter what P is\n -- there, we could just pattern match on refl and \"change\" the goal to `P x` instead of `P y`\n -- well, in some sense we are already changing the goal as this approach could be \"at the end\" of a sequence of equational reasoning\n -- ... just without pattern matching\n\ntest5c : {A : Type}\n → {P : A → Type}\n → (x y : A)\n → PathP (λ _ → A) x y -- x ≡ y\n → P x\n --------------------------\n → P y\ntest5c {A} {P} x y x≡y Px = transport {A = P x} Px≡Py Px where\n -- once again, without `cong`\n Px≡Py : P x ≡ P y\n -- we need to build a path that is `P x` at i0 and `P y` at i1\n -- with `x≡y` we have given a path that is `x` at i0 and `y` at i1\n -- therefore `x≡y(i)` behaves in the correct way and we just plug this into `P`\n Px≡Py i = P (x≡y i)\n\n-- the short version, collapsing all intermediates\ntest5f : ∀{ℓ ℓ'} {A : Type ℓ} {P : A → Type ℓ'} {x y : A} → (x ≡ y) → (P x) → P y\ntest5f {P = P} p px = transport (λ i → P (p i)) px\n\n--primitive\n-- transp : ∀ {ℓ} (A : (i : I) → Set (ℓ i)) (φ : I) (a : A i0) → A i1\n\ntransport1 : ∀{ℓ} {A B : Type ℓ} → A ≡ B → A → B\ntransport1 p a = transp (λ i → p i) i0 a\n\ntest5d : {A : Type} {P : A → Type} → (x y : A) → x ≡ y → P x → P y\ntest5d {A} {P} x y x≡y Px = transport (cong P x≡y) Px\n\nmodule Utils where\n private\n variable\n ℓ ℓ' : Level\n A : Type ℓ\n B : A → Type ℓ\n C : (a : A) → B a → Type ℓ\n D : (a : A) → (b : B a) → C a b → Type ℓ\n\n cong₁ : ∀ (f : (a : A) → B a)\n → {x : A} {y : A} (p : PathP (λ i → A) x y) -- (p : x ≡ y)\n ----------------------------------\n → PathP (λ i → B (p i)) (f x) (f y)\n cong₁ f p i = f (p i)\n {-# INLINE cong₁ #-}\n\n cong₂' : ∀ {F : (a : A) → (b : B a) → Type ℓ}\n → (f : (a : A) → (b : B a) → F a b)\n → {x : A } {y : A } (p : PathP (λ i → A ) x y) -- (p : x ≡ y)\n → {u : B x } {v : B y } (q : PathP (λ i → B (p i) ) u v) -- ? u ≡ v given x ≡ y ?\n ---------------------------------------------\n → PathP (λ i → F (p i) (q i)) (f x u) (f y v)\n cong₂' f p q i = f (p i) (q i)\n {-# INLINE cong₂' #-}\n\n cong₃ : ∀{F : (a : A) → (b : B a) → (c : C a b) → Type ℓ}\n → (f : (a : A) → (b : B a) → (c : C a b) → F a b c)\n → {x : A } {y : A } (p : PathP (λ i → A ) x y) -- (p : x ≡ y)\n → {u : B x } {v : B y } (q : PathP (λ i → B (p i) ) u v) -- ? u ≡ v given x ≡ y ?\n → {m : C x u} {n : C y v} (r : PathP (λ i → C (p i) (q i)) m n) -- ? m ≡ n given x ≡ y and u ≡ v ?\n --------------------------------------------\n → PathP (λ i → F (p i) (q i) (r i)) (f x u m) (f y v n)\n cong₃ f p q r i = f (p i) (q i) (r i)\n {-# INLINE cong₃ #-}\n\n cong₄ : ∀{F : (a : A) → (b : B a) → (c : C a b) → (d : D a b c) → Type ℓ}\n → (f : (a : A) → (b : B a) → (c : C a b) → (d : D a b c) → F a b c d)\n → {x : A } {y : A } (p : PathP (λ i → A ) x y) -- (p : x ≡ y)\n → {u : B x } {v : B y } (q : PathP (λ i → B (p i) ) u v) -- ? u ≡ v given x ≡ y ?\n → {m : C x u } {n : C y v } (r : PathP (λ i → C (p i) (q i) ) m n) -- ? m ≡ n given x ≡ y and u ≡ v ?\n → {k : D x u m} {l : D y v n} (s : PathP (λ i → D (p i) (q i) (r i)) k l) -- ? k ≡ l given x ≡ y and u ≡ v and m ≡ n?\n --------------------------------------------\n → PathP (λ i → F (p i) (q i) (r i) (s i)) (f x u m k) (f y v n l)\n cong₄ f p q r s i = f (p i) (q i) (r i) (s i)\n {-# INLINE cong₄ #-}\n\nopen Utils using (cong₃; cong₄)\n\n-- slide 18 of http://www.cse.chalmers.se/~abela/esslli2016/talkESSLLI3.pdf\nfullelim : (A : Type)\n → (C : (x y : A) → (p : x ≡ y) → Type)\n → (M N : A)\n → (P : M ≡ N)\n → (O : (z : A) → C z z refl)\n ------------------------\n → C M N P\nfullelim A C M N P O = transport along (O M) where\n along : C M M refl ≡ C M N P\n -- the \"obvious\" idea would be to show equality on every argument\n -- and then use a brute force `cong₃` to apply these equalities\n along = cong₃ C (refl {x = M}) P refl≡P where\n -- the first two arguments are easy, and the hole of the third argument rewards us with a signature to implement:\n refl≡P : PathP (λ i → M ≡ (P i)) refl P\n -- here, we need to build a path that is refl on i0 and P on i1 just with the things we have given\n -- refl : ∀{ℓ} {A : Type ℓ} {x : A} x ≡ x\n -- refl {x = x} = λ _ → x\n -- _≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ\n -- _≡_ {A = A} = PathP (λ i → A)\n -- therefore, we have\n -- refl : ∀{ℓ} {A : Type ℓ} {x : A} → PathP (λ i → A) M M\n -- refl {x = x} = λ _ → x\n -- P : PathP (λ i → A) M N\n -- Goal: M ≡ P i\n -- Goal: PathP (λ j → A) M (P i)\n refl≡P i = λ j → P (i ∧ j)\n -- I could not come up with the solution myself, but I was able to pick it off ...\n -- ... of `J` under \"Kan operations\" at https://homotopytypetheory.org/2018/12/06/cubical-agda/\n -- so, how does this work? These are the cases:\n -- i | j | i∧j | P(i∧j) | λ j → P(i∧j) | λ i → λ j → P(i∧j)\n -- i0 | i0 | i0 | M : A | M≡M : M ≡ M | p : (M≡M) ≡ (M≡N)\n -- i0 | i1 | i0 | M : A | | which is \"like\"\n -- i1 | i0 | i0 | M : A | M≡N : M ≡ N | p : refl ≡ P\n -- i1 | i1 | i1 | N : A | |\n -- and indeed, they work out\n -- we could not write `refl ≡ P` but instead have `PathP _ refl P`\n\nfullelim2 : (A : Type)\n → (C : (x y : A) → (p : x ≡ y) → Type)\n → (M N : A)\n → (P : M ≡ N)\n → (O : (z : A) → C z z refl)\n ------------------------\n → C M N P\n-- we can unfold `transport` as in the blog post\n-- transport : {A B : Type ℓ} → A ≡ B → A → B\n-- transport p a = transp (λ i → p i) i0 a\nfullelim2 A C M N P O = transp (λ i → along i) i0 (O M) where\n -- and we can directly \"set up\" the path without using `cong₃`\n along : C M M refl ≡ C M N P\n along i = C (refl {x = M} i) (P i) (λ j → P (i ∧ j) )\n\n--\n\n-- see favonia: [Agda] Equational Reasoning\n-- https://favonia.org/courses/hdtt2020/agda/agda-0305-eqreasoning.agda\n\n-- Kraus 2013 - Generalizations of Hedberg’s Theorem\n-- https://www.cs.bham.ac.uk/~mhe/papers/hedberg.pdf\n-- Although the identity types in Martin-Löf type theory (MLTT) are defined byone constructor refl and by one eliminator J that matches the constructor, the statement that every identity type has at most one inhabitant is not provable [9].\n-- Thus,uniqueness of identity proofs(UIP), or, equivalently, Streicher’s axiom K are principles that have to be assumed, and have often been assumed, as additional rules of MLTT.\n-- ...\n-- we do not assume the principle of unique identity proofs.\n-- However, certain types do satisfy it naturally, and such types are often called h-sets.\n-- A sufficient condition for a type to be an h-set, given by Hedberg [8], isthat it has decidable propositional equality.\n-- In Section 3, we analyze Hedberg’s original argument, which consists of two steps:\n-- 1. A type X is an h-set iff for all x, y : X there is a constant map x = y → x = y.\n-- 2. If X has decidable equality then such constant endomaps exist\n-- Decidable equality means that, for all x and y, we have (x = y) + (x ≠ y).\n-- Thus, a natural weakening is ¬¬-separated equality, ¬¬(x = y) → x = y, which occurs often in constructive mathematics.\n-- In this case we say that the type X is separated.\n-- For example, going beyond MLTT, the reals and the Cantorspace in Bishop mathematics and topos theory are separated.\n-- In MLTT, the Cantortype of functions from natural numbers to booleans is separated under the assumption of functional extensionality,\n-- ∀ f g : X → Y, (∀ x : X, f x = g x) → f = g.\n-- We observe that under functional extensionality, a separated type X is an h-set, because there is always a constant map x = y → x = y.\n-- In order to obtain a further characterization of the notion of h-set, we consider truncations\n-- (also known as bracket or squash types), written ‖X‖in accordance with recent HoTT notation.\n-- The idea is to collapse all inhabitants of X so that ‖X‖ has at most one inhabitant.\n-- We refer the reader to the technical development for a precise definition.\n-- cites\n-- Altenkirch 2012 - On h-Propositional Reflection and Hedberg’s Theorem\n-- https://homotopytypetheory.org/2012/11/27/on-h-propositional-reflection-and-hedbergs-theorem/\n-- Bracket-Type https://ncatlab.org/nlab/show/bracket+type\n-- By contrast, in the paradigm that may be called propositions as some types, every proposition is a type, but not every type is a proposition.\n-- The types which are propositions are generally those which “have at most one inhabitant” — in homotopy type theory this is called being of h-level 1 or being a (-1)-type.\n-- ...\n-- For A a type, the support of A denoted supp(A) or isInhab(A) or τ₋₁ A or ‖A‖₋₁ or ‖A‖ or, lastly, [A],\n-- is the higher inductive type defined by the two constructors\n-- a : A ⊢ isinhab(a) : supp(A)\n-- x : supp(A), y : supp(A) ⊢ inpath(x,y) : (x = y),\n-- where in the last sequent on the right we have the identity type.\n\n-- https://github.com/agda/cubical/issues/286\n-- It could also be a good idea to axiomatize the notion of a Caucy-complete Archimedean ordered field, as in Auke Booij's thesis, and show that Dedekind reals are an instance. The HoTT reals are then another instance. (Can cubical Agda handle the HoTT reals as a HIIT yet?)\n\n-- https://www.cs.bham.ac.uk/~abb538/thesis-first_submission.pdf\n-- Booij 2020 - Analysis in Univalent Type Theory\n\n-- 4.1 Algebraic structure of numbers\n-- \n-- Fields have the property that nonzero numbers have a multiplicative inverse, or more precisely, that\n-- (∀ x : F) x ≠ 0 ⇒ (∃ y : F) x · y = 1.\n-- \n-- Remark 4.1.1.\n-- If we require the collection of numbers to form a set in the sense of Definition 2.5.4, and satisfy the ring axioms, then multiplicative inverses are unique, so that the above is equivalent to the proposition\n-- (Π x : F) x ≠ 0 ⇒ (Σ y : F) x · y = 1.\n-- \n-- Definition 4.1.2.\n-- A classical field is a set F with points 0, 1 : F, operations +, · : F → F → F, which is a commutative ring with unit, such that\n-- (∀ x : F) x ≠ 0 ⇒ (∃ y : F) x · y = 1.\n\nprivate\n variable\n ℓ ℓ' ℓ'' : Level\n\nmodule ClassicalFieldModule where -- NOTE: one might want to put this into another file to omit the name-clashing\n record IsClassicalField {F : Type ℓ}\n (0f : F) (1f : F) (_+_ : F → F → F) (_·_ : F → F → F) (-_ : F → F) (_⁻¹ᶠ : (x : F) → {{¬(x ≡ 0f)}} → F) : Type ℓ where\n constructor isclassicalfield\n\n field\n isCommRing : IsCommRing 0f 1f _+_ _·_ -_\n ·-rinv : (x : F) → (p : ¬(x ≡ 0f)) → x · (_⁻¹ᶠ x {{p}}) ≡ 1f\n ·-linv : (x : F) → (p : ¬(x ≡ 0f)) → (_⁻¹ᶠ x {{p}}) · x ≡ 1f\n\n open IsCommRing {0r = 0f} {1r = 1f} isCommRing public\n\n record ClassicalField : Type (ℓ-suc ℓ) where\n field\n Carrier : Type ℓ\n 0f : Carrier\n 1f : Carrier\n _+_ : Carrier → Carrier → Carrier\n _·_ : Carrier → Carrier → Carrier\n -_ : Carrier → Carrier\n _⁻¹ᶠ : (x : Carrier) → {{¬(x ≡ 0f)}} → Carrier\n isClassicalField : IsClassicalField 0f 1f _+_ _·_ -_ _⁻¹ᶠ\n\n infix 9 _⁻¹ᶠ\n infix 8 -_\n infixl 7 _·_\n infixl 6 _+_\n\n open IsClassicalField isClassicalField public\n\n-- Remark 4.1.3.\n-- As in the classical case, by proving that additive and multiplicative inverses are unique, we also obtain the negation and division operations.\n-- \n-- For the reals, the assumption x ≠ 0 does not give us any information allowing us to bound x away from 0, which we would like in order to compute multiplicative inverses.\n-- Hence, we give a variation on the denition of fields in which the underlying set comes equipped with an apartness relation #, which satises x # y ⇒ x ≠ y, although the converse implication may not hold.\n-- This apartness relation allows us to make appropriate error bounds and compute multiplicative inverses based on the assumption x # 0.\n-- \n-- Definition 4.1.4.\n-- - An apartness relation, denoted by #, is an irreflexive symmetric cotransitive relation.\n-- - A strict partial order, denoted by <, is an irreflexive transitive cotransitive relation.\n\nIsIrrefl : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ')\nIsIrrefl {A = A} R = (a b : A) → R a b → ¬(R b a)\n\nIsCotrans : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ')\nIsCotrans {A = A} R = (a b : A) → R a b → (∀(x : A) → (R a x) ⊎ (R x b))\n\n-- NOTE: these `IsX` definitions are in the style of the standard library and do not make `a` and `b` to be implicit arguments\n-- when using them, we can just use `_` as in `isIrrefl _ _ a#b`\n\n-- NOTE: module parameters \"add\" to the contained function's arguments\n-- see https://agda.readthedocs.io/en/v2.6.0.1/language/module-system.html#parameterised-modules\n\n-- IsApartnessRel : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ')\n-- IsApartnessRel R = IsIrrefl R × BinaryRelation.isSym R × IsCotrans R\n\nrecord IsApartnessRel {ℓ ℓ' : Level} {A : Type ℓ} (R : Rel A A ℓ') : Type (ℓ-max ℓ ℓ') where\n field\n isIrrefl : IsIrrefl R\n isSym : BinaryRelation.isSym R\n isCotrans : IsCotrans R\n\n-- IsStrictPartialOrder : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ')\n-- IsStrictPartialOrder R = IsIrrefl R × BinaryRelation.isTrans R × IsCotrans R\n\nrecord IsStrictPartialOrder {ℓ ℓ' : Level} {A : Type ℓ} (R : Rel A A ℓ') : Type (ℓ-max ℓ ℓ') where\n field\n isIrrefl : IsIrrefl R\n isTrans : BinaryRelation.isTrans R\n isCotrans : IsCotrans R\n\n-- Definition 4.1.5.\n-- A constructive field is a set F with points 0, 1 : F, binary operations +, · : F → F → F, and a binary relation # such that\n-- 1. (F, 0, 1, +, ·) is a commutative ring with unit;\n-- 2. x : F has a multiplicative inverse iff x # 0;\n-- 3. + is #-extensional, that is, for all w, x, y, z : F\n-- w + x # y + z ⇒ w # y ∨ x # z.\n\n{- NOTE: about naming in the standard library\nwith `isCommRing : IsCommRing 0f 1f _+_ _·_ -_` we import\n is-set : (x y : Carrier) (x₁ y₁ : x ≡ y) → x₁ ≡ y₁ -- NOTE: this is imported from +-isAbGroup and explicitly hidden from ·-isMonoid\n isCommRing : IsCommRing 0f 1f _+_ _·_ -_\n isRing : IsRing 0f 1f _+_ _·_ -_\n +-isAbGroup : IsAbGroup 0f _+_ -_\n +-assoc : (x y z : Carrier) → x + (y + z) ≡ x + y + z\n +-identity : (x : Carrier) → (x + 0f ≡ x) × (0f + x ≡ x)\n +-rid : (x : Carrier) → x + 0f ≡ x\n +-lid : (x : Carrier) → 0f + x ≡ x\n +-inv : (x : Carrier) → (x + - x ≡ 0f) × (- x + x ≡ 0f)\n +-linv : (x : Carrier) → - x + x ≡ 0f\n +-rinv : (x : Carrier) → x + - x ≡ 0f\n +-comm : (x y : Carrier) → x + y ≡ y + x\n +-isSemigroup : IsSemigroup _+_\n +-isMonoid : IsMonoid 0f _+_\n +-isGroup : IsGroup 0f _+_ -_\n ·-isSemigroup : IsSemigroup _·_\n ·-isMonoid : IsMonoid 1f _·_\n ·-comm : (x y : Carrier) → x · y ≡ y · x\n ·-assoc : (x y z : Carrier) → x + (y + z) ≡ x + y + z\n ·-identity : (x : Carrier) → (x · 1f ≡ x) × (1f · x ≡ x)\n ·-lid : (x : Carrier) → 1f · x ≡ x\n ·-rid : (x : Carrier) → x · 1f ≡ x\n dist : (x y z : Carrier) → (x · (y + z) ≡ x · y + x · z) × ((x + y) · z ≡ x · z + y · z)\n ·-rdist-+ : (x y z : Carrier) → x · (y + z) ≡ x · y + x · z\n ·-ldist-+ : (x y z : Carrier) → (x + y) · z ≡ x · z + y · z\nthere is\n module GroupLemmas (G : Group {ℓ}) where\n record MonoidEquiv (M N : Monoid {ℓ}) : Type ℓ where\n module SemigroupΣTheory {ℓ} where\n module CommRingΣTheory {ℓ} where\n module MonoidΣTheory {ℓ} where\n module MonoidTheory {ℓ} (M' : Monoid {ℓ}) where\n module GroupΣTheory {ℓ} where\n module AbGroupΣTheory {ℓ} where\n module RingΣTheory {ℓ} where\n module Theory (R' : Ring {ℓ}) where\n module PosetReasoning (P : Poset ℓ₀ ℓ₁) where\nthere is a syntax for https://agda.readthedocs.io/en/latest/language/module-system.html?highlight=module#parameterised-modules\n module SortNat = Sort Nat leqNat\nthe non-cubical standard library has a lot of machinery that is missing in the cubical-stdlib\n module Function.Base where\n -- Binary application\n _⟨_⟩_ : A → (A → B → C) → B → C\n x ⟨ f ⟩ y = f x y\n -- Composition of a binary function with a unary function\n _on_ : (B → B → C) → (A → B) → (A → A → C)\n _*_ on f = λ x y → f x * f y\n -- Flipped application (aka pipe-forward)\n _|>_ : ∀ {A : Set a} {B : A → Set b} → (a : A) → (∀ a → B a) → B a\n -- Construct an element of the given type by instance search.\n it : {A : Set a} → {{A}} → A\n it {{x}} = x\n module Relation.Binary.Core where\n infix 4 _⇒_ _⇔_ _=[_]⇒_\n -- Implication/containment - could also be written _⊆_.\n -- and corresponding notion of equivalence\n _⇒_ : REL A B ℓ₁ → REL A B ℓ₂ → Set _\n P ⇒ Q = ∀ {x y} → P x y → Q x y\n _⇔_ : REL A B ℓ₁ → REL A B ℓ₂ → Set _\n P ⇔ Q = P ⇒ Q × Q ⇒ P\n -- Generalised implication - if P ≡ Q it can be read as \"f preserves P\".\n _=[_]⇒_ : Rel A ℓ₁ → (A → B) → Rel B ℓ₂ → Set _\n P =[ f ]⇒ Q = P ⇒ (Q on f)\n -- A synonym for _=[_]⇒_.\n _Preserves_⟶_ : (A → B) → Rel A ℓ₁ → Rel B ℓ₂ → Set _\n f Preserves P ⟶ Q = P =[ f ]⇒ Q\n -- A binary variant of _Preserves_⟶_.\n _Preserves₂_⟶_⟶_ : (A → B → C) → Rel A ℓ₁ → Rel B ℓ₂ → Rel C ℓ₃ → Set _\n _∙_ Preserves₂ P ⟶ Q ⟶ R = ∀ {x y u v} → P x y → Q u v → R (x ∙ u) (y ∙ v)\n module Algebra.Definitions\n Congruent₁ : Op₁ A → Set _\n Congruent₁ f = f Preserves _≈_ ⟶ _≈_\n Congruent₂ : Op₂ A → Set _\n Congruent₂ ∙ = ∙ Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_\n LeftCongruent : Op₂ A → Set _\n LeftCongruent _∙_ = ∀ {x} → (x ∙_) Preserves _≈_ ⟶ _≈_\n RightCongruent : Op₂ A → Set _\n RightCongruent _∙_ = ∀ {x} → (_∙ x) Preserves _≈_ ⟶ _≈_\nthe non-cubical standard library makes more use of unicode, e.g. in invˡ and invʳ\nfor the inverse, we have in the non-cubical standard library\n inverseˡ : LeftInverse ε _⁻¹ _∙_\n inverseˡ = proj₁ inverse\n inverseʳ : RightInverse ε _⁻¹ _∙_\n inverseʳ = proj₂ inverse\n uniqueˡ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → x ≈ (y ⁻¹)\n uniqueˡ-⁻¹ = Consequences.assoc+id+invʳ⇒invˡ-unique\n setoid ∙-cong assoc identity inverseʳ\n uniqueʳ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → y ≈ (x ⁻¹)\n uniqueʳ-⁻¹ = Consequences.assoc+id+invˡ⇒invʳ-unique\n setoid ∙-cong assoc identity inverseˡ\ninterestingly, this follows from just one field `inverse : Inverse ε _⁻¹ _∙_`\n there is `module Algebra.Consequences.Setoid` for such results (\"consequences\")\nthere are open pull requests which might have some more information about the \"intended\" style\n https://github.com/agda/cubical/pull/331\n Algebras and modules #331 \n https://github.com/agda/cubical/pull/365\n Mayer-Vietoris and some cohomology groups #365 \n https://github.com/agda/cubical/pull/325\n Denial field #325\n A denial field is a commutative ring where every non-zero element has an inverse. See #301 for a discussion of other notions of 'field' in constructive algebra.\n https://github.com/felixwellen/cubical/tree/denial-field\n https://github.com/agda/cubical/issues/301\n Add Field to Cubical.Structures #301 \n In the style of Ring, etc. from #284. I think it would be good to have this so we could show ℚ is a field.\n https://github.com/agda/cubical/pull/284\n Newstructures #284\n Adding some new structures (semigroups, groups, abelian groups and rngs) and a new folder of Algebra, in order to produce results about these new Algebraic structures.\n https://github.com/agda/cubical/commit/8cf91aeb49ebf26d4cf4e6795e8b56041e28c7a1\n Rewrite Group, AbGroup, Ring and CommRing to be records instead of nested Sigma types\n https://github.com/agda/cubical/pull/324\n Ideals and quotient rings #324 \n - define (left-, right- and two-sided) ideals\n - define quotient by a two-sided ideal\n - construct the ring structure on the quotient\n-}\n\nrecord IsConstructiveField {F : Type ℓ}\n (0f : F) (1f : F) (_+_ : F → F → F) (_·_ : F → F → F) (-_ : F → F) (_#_ : Rel F F ℓ') (_⁻¹ᶠ : (x : F) → {{x # 0f}} → F) : Type (ℓ-max ℓ ℓ') where\n constructor isconstructivefield\n\n field\n isCommRing : IsCommRing 0f 1f _+_ _·_ -_\n ·-rinv : (x : F) → (p : x # 0f) → x · (_⁻¹ᶠ x {{p}}) ≡ 1f\n ·-linv : (x : F) → (p : x # 0f) → (_⁻¹ᶠ x {{p}}) · x ≡ 1f\n -- ·-inv : (x : F) → (p : x # 0f) → x · (let instance p = p in (x ⁻¹ᶠ)) ≡ 1f -- this does also work\n -- ·-inv : (x : F) → ({{p}} : x # 0f) → x · (x ⁻¹ᶠ) ≡ 1f -- this does not do the right thing\n -- ·-inv-back : (x : F) → ∃[ y ∈ F ] (x · y ≡ 1f) → x # 0f\n ·-inv-back : (x y : F) → (x · y ≡ 1f) → x # 0f × y # 0f\n +-#-extensional : (w x y z : F) → (w + x) # (y + z) → (w # y) ⊎ (x # z)\n isApartnessRel : IsApartnessRel _#_\n\n open IsCommRing {0r = 0f} {1r = 1f} isCommRing public\n open IsApartnessRel isApartnessRel public\n renaming\n ( isIrrefl to #-irrefl\n ; isSym to #-sym\n ; isCotrans to #-cotrans )\n\n_ = {!!}\n\nrecord ConstructiveField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where\n field\n Carrier : Type ℓ\n 0f : Carrier\n 1f : Carrier\n _+_ : Carrier → Carrier → Carrier\n _·_ : Carrier → Carrier → Carrier\n -_ : Carrier → Carrier\n _#_ : Rel Carrier Carrier ℓ'\n _⁻¹ᶠ : (x : Carrier) → {{x # 0f}} → Carrier\n isConstructiveField : IsConstructiveField 0f 1f _+_ _·_ -_ _#_ _⁻¹ᶠ\n \n infix 9 _⁻¹ᶠ\n infixl 7 _·_\n infix 6 -_\n infixl 5 _+_\n infixl 4 _#_\n\n open IsConstructiveField isConstructiveField public\n\nopen import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim`\n\n-- Lemma 4.1.6.\n-- For a constructive field (F, 0, 1, +, ·, #), the following hold.\n-- 1. 1 # 0.\n-- 2. Addition + is #-compatible in the sense that for all x, y, z : F\n-- x # y ⇔ x + z # y + z.\n-- 3. Multiplication · is #-extensional in the sense that for all w, x, y, z : F\n-- w · x # y · z ⇒ w # y ∨ x # z.\nmodule Lemmas-4-6-1 {{F : ConstructiveField {ℓ} {ℓ'}}} where\n --open ConstructiveField {{...}} public -- creates additional `ConstructiveField.foo F` in the \"Goal/Have-previews\"\n open ConstructiveField F -- works\n \n open import Cubical.Structures.Ring\n -- NOTE: this also creates additional `Ring.Carrier (makeRing ...)` in the \"Goal/Have-previews\", except when using C-u C-u C-... then these get normalized fine\n -- can we do something with pragmas here? https://agda.readthedocs.io/en/latest/language/pragmas.html?highlight=INLINE#the-inline-and-noinline-pragmas\n -- or maybe with macros? https://github.com/alhassy/gentle-intro-to-reflection\n -- using this `R` makes it a little better\n R = (makeRing 0f 1f _+_ _·_ -_ is-set +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+)\n open Cubical.Structures.Ring.Theory R\n -- 0-rightNullifies\n\n -- open Ring {{...}} public\n\n {-\n module ReflectionTest where\n open import Data.Nat as Nat hiding (_⊓_)\n open import Data.List as List\n open import Data.Char as Char\n open import Data.String as String\n\n open import Reflection hiding (name; Type)\n open import Reflection.Term as Term public hiding (Type)\n test06 = (quoteTC 0-rightNullifies)\n\n test07 : _\n unquoteDef test07 = defineFun test07\n [ clause\n ( [] ) -- hidden arguments `{x}`\n ( [] ) -- visible arguments `{y}`\n (quoteTerm 0f) -- the \"Term\" at the right hand side of the `=`\n ]\n -- {-# INLINE test07 #-}\n -- {-# NOINLINE test07 #-}\n\n proof07 : test07 ≡ 0f\n proof07 = {!!}\n -}\n\n {-\n -- NOTE: it might be possible with --overlapping-instances to resolve this \"Goal/Have-preview\" issue\n -- but it is mentioned that this \"might lead to an exponential slowdown in instance resolution and possibly (apparent) looping behaviour\"\n -- also the OPTION pragma to apply --overlapping-instances can only be set per file (and not per module)\n -- so it might be a good idea to have a separate \"Theory.agda\" or \"Properties.agda\" (as it is called in the standard library)\n -- well, in a test with --overlapping instances, I got the issue that -_ is defined multiple times\n -- to be fair, the result we have implemented might fit better in a more general Ring context\n -- so one might think about this and until then, I guess, the best solution is to just omit multiple instances\n\n module InstanceTest where\n -- taken from https://agda.readthedocs.io/en/latest/language/instance-arguments.html#defining-type-classes\n -- open import Algebra\n open import Agda.Builtin.Nat\n open import Data.List renaming (List to BList)\n\n record Monoid {a} (A : Type a) : Type a where\n field\n mempty : A\n _<>_ : A → A → A\n open Monoid {{...}} public\n\n instance\n ListMonoid : ∀ {a} {A : Type a} → Monoid (BList A)\n -- normal: provide \"implementation\" in a single term\n -- ListMonoid = record { mempty = []; _<>_ = _++_ }\n -- with copatterns: provide \"implementation\" with patterns\n mempty {{ListMonoid}} = []\n _<>_ {{ListMonoid}} xs ys = xs ++ ys\n\n mconcat : ∀ {a} {A : Type a} → {{Monoid A}} → BList A → A\n mconcat [] = mempty\n mconcat (x ∷ xs) = x <> mconcat xs\n\n sum1 : BList Nat → Nat\n sum1 xs =\n let instance -- NOTE: IMPORTANT: the instance-block needs to be more indented (!) than the `instance` keyword\n NatMonoid : Monoid Nat\n NatMonoid = record { mempty = 0; _<>_ = Agda.Builtin.Nat._+_ }\n in mconcat xs\n\n itest2 =\n let\n instance\n rr = R\n in {! 0-rightNullifies!}\n\n -- To restrict an instance to the current module, you can mark it as private. For instance,\n -- https://agda.readthedocs.io/en/latest/language/instance-arguments.html#restricting-instance-search\n -}\n\n {-\n https://agda.readthedocs.io/en/latest/language/abstract-definitions.html\n Abstract definitions\n Definitions can be marked as abstract, for the purpose of hiding implementation details, or to speed up type-checking of other parts. In essence, abstract definitions behave like postulates, thus, do not reduce/compute. For instance, proofs whose content does not matter could be marked abstract, to prevent Agda from unfolding them (which might slow down type-checking).\n -}\n\n -- anonymous modules `module _ params where` automatically open themselves\n -- they are not well documented but there is this usage example\n -- Anonymous modules or sections #735 \n -- https://github.com/agda/agda/issues/735\n -- I often want to use something like sections in Coq. I usually use parametrized modules but this has at least two issues that Coq does not have:\n -- 1) I need to give a name to the module, and there is often no meaningful name to be given\n -- 2) It exports the module, so I cannot define a module in another file with the same name\n -- the following code\n -- module _ params where\n -- declarations\n -- would be translated to:\n -- private\n -- module Fresh params where\n -- declarations\n -- open Fresh public\n -- where Fresh is a new name.\n -- NOTE: this gives a hint on the use of \"sections\" in mathematical writing\n -- it suggests, that these introduce variable-but-fixed parameter dependencies to all definitions (in the way the `variable` keyword does)\n -- the difference between an anonymous module and a variable seems to be that the module adds all parameters, where `variable` only adds parameters when used\n -- also, in the module we have more flexibility with opening other modules and hiding names with the `private` keyword, etc.\n -- and there is\n -- https://github.com/agda/agda/issues/1145\n -- Allow multiple layout keywords on the same line #1145 \n\n -- NOTE: IMPORTANT: when in a hole, with C-c C-o one can list \"module contents\"\n -- if given `F` here, we can see the contents of F\n -- I guess, since every inherited member is included with `open ... public`,\n -- we can continue with just `isConstructiveField`\n -- and even `isCommRing`\n -- and even `isRing`\n -- this greatly helps to investigate available\n\n {-\n test3 : ∃[ x ∈ Carrier ] x · x ≡ x → Carrier\n test3 ∥_∥.∣ Σx-x·x≡x ∣ = {!!}\n --test ∥_∥.∣ x , x·x≡x ∣ = x\n test3 (∥_∥.squash Σx-x·x≡x₁ Σx-x·x≡x₂ i) = {!!}\n\n test3b : {A : Type} → ∃[ x ∈ A ] ∃[ y ∈ A ] x ≡ y → A\n test3b ∥_∥.∣ fst₁ , ∥_∥.∣ fst₂ , snd₁ ∣ ∣ = {!!}\n test3b ∥_∥.∣ fst₁ , ∥_∥.squash snd₁ ∥_∥.∣ x ∣ i ∣ = {!!}\n test3b ∥_∥.∣ fst₁ , ∥_∥.squash snd₁ (∥_∥.squash snd₂ ∥_∥.∣ x ∣ i₁) i ∣ = {!!}\n test3b ∥_∥.∣ fst₁ , ∥_∥.squash snd₁ (∥_∥.squash snd₂ (∥_∥.squash snd₃ snd₄ i₂) i₁) i ∣ = {!!}\n test3b (∥_∥.squash ∥_∥.∣ x ∣ ∥_∥.∣ x₁ ∣ i) = {!!}\n test3b (∥_∥.squash ∥_∥.∣ x ∣ (∥_∥.squash x₁ x₂ i₁) i) = {!!}\n test3b (∥_∥.squash (∥_∥.squash x x₂ i₁) x₁ i) = {!!}\n -}\n\n -- ∃ : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')\n -- ∃ A B = ∥ Σ A B ∥\n -- infix 2 ∃-syntax\n -- ∃-syntax : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')\n -- ∃-syntax = ∃\n -- syntax ∃-syntax A (λ x → B) = ∃[ x ∈ A ] B\n\n -- Lemma 4.1.6.1\n 1f#0f : 1f # 0f\n 1f#0f with ·-identity 1f\n -- 1f#0f | 1·1≡1 , _ = ·-inv-back 1f ∣ (1f , 1·1≡1) ∣ -- need additional ∣_∣ resp. \\|_\\| around the tuple\n 1f#0f | 1·1≡1 , _ = fst (·-inv-back _ _ 1·1≡1)\n\n _ = Cubical.Data.Sigma.Base._×_ -- fst and snd\n\n a+b-b≡a : ∀ a b → a ≡ (a + b) - b\n -- NOTE: about workflow\n -- one can investigate some single term in the hole (C-c C-.), but not a second one\n -- therefore, we can move a term temporarily into a let-clause and work on another term in the hole\n -- ... is there equational reasoning in --cubical ?\n -- NOTE: Yes! it is in Cubical.Foundations.Id\n a+b-b≡a a b = let P = sym (fst (+-inv b))\n Q = sym (fst (+-identity a))\n R = transport (λ i → a ≡ a + P i) Q\n S = transport (λ i → a ≡ (+-assoc a b (- b)) i ) R\n in S\n\n +-preserves-≡ : ∀{a b} → ∀ c → a ≡ b → a + c ≡ b + c\n +-preserves-≡ c a≡b i = a≡b i + c\n\n +-preserves-≡-l : ∀{a b} → ∀ c → a ≡ b → c + a ≡ c + b\n +-preserves-≡-l c a≡b i = c + a≡b i\n\n a+b≡0→a≡-b : ∀{a b} → a + b ≡ 0f → a ≡ - b\n a+b≡0→a≡-b {a} {b} a+b≡0 = transport\n (λ i →\n let RHS = snd (+-identity (- b))\n LHS₁ : a + (b + - b) ≡ a + 0f\n LHS₁ = +-preserves-≡-l a (fst (+-inv b))\n LHS₂ : (a + b) - b ≡ a\n LHS₂ = transport (λ j → (+-assoc a b (- b)) j ≡ fst (+-identity a) j) LHS₁\n in LHS₂ i ≡ RHS i \n ) (+-preserves-≡ (- b) a+b≡0)\n\n a·-b≡-a·b : ∀ a b → a · (- b) ≡ - a · b\n a·-b≡-a·b a b =\n let P : a · 0f ≡ 0f\n P = 0-rightNullifies a\n Q : a · (- b + b) ≡ 0f\n Q = transport (λ i → a · snd (+-inv b) (~ i) ≡ 0f) P\n R : a · (- b) + a · b ≡ 0f\n R = transport (λ i → ·-rdist-+ a (- b) b i ≡ 0f) Q\n in a+b≡0→a≡-b R\n\n a·b-a·c≡a·[b-c] : ∀ a b c → a · b - a · c ≡ a · (b - c)\n a·b-a·c≡a·[b-c] a b c =\n let P : a · b + a · (- c) ≡ a · (b + - c)\n P = sym (·-rdist-+ a b (- c))\n Q : a · b - a · c ≡ a · (b + - c)\n Q = transport (λ i → a · b + a·-b≡-a·b a c i ≡ a · (b + - c) ) P\n in Q \n\n -- Lemma 4.1.6.2\n -- For #-compatibility of +, suppose x # y, that is, (x +z) −z # (y +z) −z.\n -- Then #-extensionality gives (x + z # y + z) ∨ (−z # −z), where the latter case is excluded by irreflexivity of #.\n +-#-compatible : ∀(x y z : Carrier) → x # y → x + z # y + z\n +-#-compatible x y z x#y with\n let P = transport (λ i → a+b-b≡a x z i # a+b-b≡a y z i ) x#y \n in +-#-extensional _ _ _ _ P\n ... | inl x+z#y+z = x+z#y+z\n ... | inr -z#-z = ⊥-elim (#-irrefl _ _ -z#-z -z#-z) \n\n -- The other direction is similar.\n +-#-compatible-inv : ∀(x y z : Carrier) → x + z # y + z → x # y\n +-#-compatible-inv _ _ _ x+z#y+z with +-#-extensional _ _ _ _ x+z#y+z\n ... | inl x#y = x#y\n ... | inr z#z = ⊥-elim (#-irrefl _ _ z#z z#z)\n\n -- _ = {!!} ≃⟨ {!!} ⟩ {!!} ■\n -- open import \n -- _ = {!!} ≡[ i ]⟨ {!!} ⟩ {!!} ∎\n\n --_≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → x ≡ z\n --_ ≡⟨ x≡y ⟩ y≡z = x≡y ∙ y≡z\n\n -- for a list of unicode symbols in agda, see https://people.inf.elte.hu/divip/AgdaTutorial/Symbols.html\n infix 3 _◼\n infixr 2 _⇒⟨_⟩_\n\n _⇒⟨_⟩_ : ∀{ℓ ℓ' ℓ''} {Q : Type ℓ'} {R : Type ℓ''} → (P : Type ℓ) → (P → Q) → (Q → R) → (P → R)\n _ ⇒⟨ pq ⟩ qr = qr ∘ pq\n\n _◼ : ∀{ℓ} (A : Type ℓ) → A → A\n _ ◼ = λ x → x\n\n f : Carrier → Carrier\n f x with +-inv x\n ... | fst₁ , snd₁ = {!!}\n\n -- see https://agda.readthedocs.io/en/latest/language/instance-arguments.html\n it : ∀ {a} {A : Type a} → {{A}} → A\n it {{x}} = x -- instance search\n\n -- Lemma 4.1.6.3\n -- TODO: there is equational resoning in Cubical.Foundations.Id, use this\n -- P = _ ≡⟨ _ ⟩ _ ∎\n -- P = _ ≡[ i ] _ ∎\n -- syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y\n -- in general this module offers a lot of useful equational machinery\n -- it already makes use of path concatenation with ∙ and ∙∙\n -- there is also Cubical.Foundations.Equiv\n -- P = _ ≃⟨ _ ⟩ _ ■\n ·-#-extensional-case1 : ∀(w x y z : Carrier) → w · x # y · z → w · x # w · z → x # z\n ·-#-extensional-case1 w x y z w·x#y·z w·x#w·z =\n let P : w · x + - w · x # w · z + - w · x\n P = +-#-compatible _ _ (- (w · x)) w·x#w·z\n Q : 0f # w · (z + - x)\n Q = transport (λ i → (fst (+-inv (w · x)) i) # a·b-a·c≡a·[b-c] w z x i) P\n instance -- NOTE: this allows to use ⁻¹ᶠ without an instance argument\n q = #-sym _ _ Q\n -- see https://agda.readthedocs.io/en/latest/language/instance-arguments.html\n it : ∀ {a} {A : Type a} → {{A}} → A\n it {{x}} = x -- instance search\n R : w · (z - x) · (w · (z - x)) ⁻¹ᶠ ≡ 1f\n R = ·-rinv (w · (z - x)) it -- (#-sym _ _ Q)\n S : (z + - x) · w · (w · (z + - x)) ⁻¹ᶠ ≡ 1f\n S = transport (λ i → ·-comm w (z - x) i · (w · (z - x)) ⁻¹ᶠ ≡ 1f) R\n T : (z + - x) · (w · (w · (z + - x)) ⁻¹ᶠ) ≡ 1f\n T = transport (λ i → ·-assoc (z + - x) w ((w · (z + - x)) ⁻¹ᶠ) (~ i) ≡ 1f) S\n U : z - x # 0f\n U = fst (·-inv-back _ _ T)\n V : z - x + x # 0f + x\n V = (+-#-compatible _ _ x) (fst (·-inv-back _ _ T)) -- (+-#-compatible _ _ x U)\n -- workflow:\n -- start with `transport (λ i → z - x + x # 0f + x) V` in the hole (i.e. a constant transport)\n -- and then fiddle with the path and look what comes out\n W : z + (- x + x) # x\n W = transport (λ i → +-assoc z (- x) x (~ i) # snd (+-identity x) i) V\n X : z + 0f # x\n X = transport (λ i → z + snd (+-inv x) i # x) W\n in (#-sym _ _ (transport (λ i → fst (+-identity z) i # x) X))\n ·-#-extensional : ∀(w x y z : Carrier) → w · x # y · z → (w # y) ⊎ (x # z)\n ·-#-extensional w x y z w·x#y·z with #-cotrans _ _ w·x#y·z (w · z)\n ... | inl w·x#w·z = inr (·-#-extensional-case1 w x y z w·x#y·z w·x#w·z) -- first case\n ... | inr w·z#y·z = let z·w≡z·y = (transport (λ i → ·-comm w z i # ·-comm y z i) w·z#y·z)\n in inl (·-#-extensional-case1 _ _ _ _ z·w≡z·y z·w≡z·y) -- second case reduced to first case\n\n -- for an example to use equational reasoning in this topic, see https://github.com/felixwellen/cubical/blob/field/Cubical/Structures/Field.agda\n -- we do not do equational reasoning here but \"implicational\" reasoning instead\n -- the special syntax should make it more readable and omit giving names to every intermediate step\n -- but giving names to intermediates in a `let` or `where` clause might just be the way it's done\n -- c.f. with more elaborate proofs e.g. in https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#combining-structures\n -- also see the elaborate proof in https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#381519\n -- which uses equational reasoning, but still names the single steps i, ii, iii, iv, v, vi, ... and resolves them in a `where` clause\n -- also see https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#391417\n -- \"We consider rings without unit, called rngs, and with unit, called rings.\"\n -- this work of Martín Escardó was prepared for the\n -- Midlands Graduate School in the Foundations of Computing Science (University of Birmingham, UK, 14 - 18 April, 2019)\n -- http://events.cs.bham.ac.uk/mgs2019/\n -- Introductory Courses:\n -- - Lambda Calculus (course notes) by Venanzio Capretta (University of Nottingham)\n -- - Category Theory (course notes) by Thorsten Altenkirch (University of Nottingham)\n -- - Univalent Type Theory in Agda (course notes) by Martín Escardó (University of Birmingham)\n\n ·-#-extensional-case1' : ∀(w x y z : Carrier) → w · x # y · z → w · x # w · z → x # z\n ·-#-extensional-case1' w x y z w·x#y·z w·x#w·z =\n let\n instance -- this allows to use ⁻¹ᶠ without an instance argument\n w·[z-x]#0f =\n ( w · x # w · z ⇒⟨ +-#-compatible _ _ (- (w · x)) ⟩\n w · x - w · x # w · z - w · x ⇒⟨ transport (λ i → (fst (+-inv (w · x)) i) # a·b-a·c≡a·[b-c] w z x i) ⟩\n 0f # w · (z - x) ⇒⟨ #-sym _ _ ⟩\n w · (z - x) # 0f ◼) w·x#w·z\n in ( w · (z - x) # 0f ⇒⟨ (λ _ → ·-rinv (w · (z - x)) it ) ⟩ -- NOTE: \"plugging in\" the instance did not work, ∴ `it`\n w · (z - x) · (w · (z - x)) ⁻¹ᶠ ≡ 1f ⇒⟨ transport (λ i → ·-comm w (z - x) i · (w · (z - x)) ⁻¹ᶠ ≡ 1f) ⟩\n (z - x) · w · (w · (z - x)) ⁻¹ᶠ ≡ 1f ⇒⟨ transport (λ i → ·-assoc (z - x) w ((w · (z - x)) ⁻¹ᶠ) (~ i) ≡ 1f) ⟩\n (z - x) · (w · (w · (z - x)) ⁻¹ᶠ) ≡ 1f ⇒⟨ fst ∘ (·-inv-back _ _) ⟩\n z - x # 0f ⇒⟨ +-#-compatible _ _ x ⟩\n (z - x) + x # 0f + x ⇒⟨ transport (λ i → +-assoc z (- x) x (~ i) # snd (+-identity x) i) ⟩\n z + (- x + x) # x ⇒⟨ transport (λ i → z + snd (+-inv x) i # x) ⟩\n z + 0f # x ⇒⟨ transport (λ i → fst (+-identity z) i # x) ⟩\n z # x ⇒⟨ #-sym _ _ ⟩\n x # z ◼) it -- conceptually we would plug `w·[z-x]#0f` in, but this breaks the very first step\n\n-- \n-- Lemma 4.1.7.\n-- Given a strict partial order < on a set X:\n-- 1. we have an apartness relation defined by\n-- x # y := (x < y) ∨ (y < x), and\n-- 2. we have a preorder defined by\n-- x ≤ y := ¬(y < x).\n-- \n-- Definition 4.1.8.\n-- Let (A, ≤) be a partial order, and let min, max : A → A → A be binary operators on A. We say that (A, ≤, min, max) is a lattice if min computes greatest lower bounds in the sense that for every x, y, z : A, we have\n-- z ≤ min(x,y) ⇔ z ≤ x ∧ z ≤ y,\n-- and max computes least upper bounds in the sense that for every x, y, z : A, we have\n-- max(x,y) ≤ z ⇔ x ≤ z ∧ y ≤ z.\n-- \n-- Remark 4.1.9.\n-- 1. From the fact that (A, ≤, min, max) is a lattice, it does not follow that for every x and y, min(x,y) = x ∨ min(x,y) = y. However, we can characterize min as\n-- z < min(x,y) ⇔ z < x ∨ z < y\n-- and similarly for max, see Lemma 6.7.1.\n-- 2. In a partial order, for two fixed elements a and b, all joins and meets of a, b are equal, so that Lemma 2.6.20 the type of joins and the type of meets are propositions. Hence, providing the maps min and max as in the above definition is equivalent to the showing the existenceof all binary joins and meets.\n-- \n-- The following definition is modified from on The Univalent Foundations Program [89, Definition 11.2.7].\n-- \n-- Definition 4.1.10.\n-- An ordered field is a set F together with constants 0, 1, operations +, ·, min, max, and a binary relation < such that:\n-- 1. (F, 0, 1, +, ·) is a commutative ring with unit;\n-- 2. < is a strict order;\n-- 3. x : F has a multiplicative inverse iff x # 0, recalling that # is defined as in Lemma 4.1.7;\n-- 4. ≤, as in Lemma 4.1.7, is antisymmetric, so that (F, ≤) is a partial order;\n-- 5. (F, ≤, min, max) is a lattice.\n-- 6. for all x, y, z, w : F:\n-- x + y < z + w ⇒ x < z ∨ y < w, (†)\n-- 0 < z ∧ x < y ⇒ x z < y z. (∗)\n-- Our notion of ordered fields coincides with The Univalent Foundations Program [89, Definition 11.2.7].\n-- \n-- Lemma 4.1.11.\n-- In the presence of the first five axioms of Definition 4.1.10, conditions (†) and (∗) are together equivalent to the condition that for all x, y, z : F,\n-- 1. x ≤ y ⇔ ¬(y < x),\n-- 2. x # y ⇔ (x < y) ∨ (y < x)\n-- 3. x ≤ y ⇔ x + z ≤ y + z,\n-- 4. x < y ⇔ x + z < y + z,\n-- 5. 0 < x + y ⇒ 0 < x ∨ 0 < y,\n-- 6. x < y ≤ z ⇒ x < z,\n-- 7. x ≤ y < z ⇒ x < z,\n-- 8. x ≤ y ∧ 0 ≤ z ⇒ x z ≤ y z,\n-- 9. 0 < z ⇒ (x < y ⇔ x z < y z),\n-- 10. 0 < 1.\n\n\n-- we have in cubical\n-- import Cubical.HITs.Rationals.HITQ\n-- ℚ as a higher inductive type\n-- import Cubical.HITs.Rationals.QuoQ\n-- ℚ as a set quotient of ℤ × ℕ₊₁ (as in the HoTT book)\n-- import Cubical.HITs.Rationals.SigmaQ\n-- ℚ as the set of coprime pairs in ℤ × ℕ₊₁\n", "meta": {"hexsha": "2293081f33f40677c4540163cac255dfc828037e", "size": 51464, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Hit.agda", "max_stars_repo_name": "mchristianl/synthetic-reals", "max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z", "max_issues_repo_path": "test/Hit.agda", "max_issues_repo_name": "mchristianl/synthetic-reals", "max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "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/Hit.agda", "max_forks_repo_name": "mchristianl/synthetic-reals", "max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "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": 49.24784689, "max_line_length": 375, "alphanum_fraction": 0.5742266439, "num_tokens": 18705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.6584175139669997, "lm_q1q2_score": 0.37771991085142886}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule Pif2 where\n\n{-- 2 paths --} \n\nopen import Level using (Level; _⊔_) renaming (zero to lzero; suc to lsuc)\n\nopen import Relation.Binary.PropositionalEquality \n using (_≡_; refl; sym; trans; subst; subst₂; cong; cong₂; setoid;\n inspect; [_]; proof-irrelevance; module ≡-Reasoning)\nopen import Relation.Binary.PropositionalEquality.TrustMe\n using (trustMe)\nopen import Relation.Nullary using (Dec; yes; no; ¬_)\nopen import Data.Nat.Properties\n using (m≢1+m+n; i+j≡0⇒i≡0; i+j≡0⇒j≡0; n≤m+n)\nopen import Data.Nat.Properties.Simple \n using (+-right-identity; +-suc; +-assoc; +-comm; \n *-assoc; *-comm; *-right-zero; distribʳ-*-+)\nopen import Data.Nat.DivMod using (_mod_)\nopen import Relation.Binary using (Rel; Decidable; Setoid)\nopen import Relation.Binary.Core using (Transitive)\n\nopen import Data.String using (String)\n renaming (_++_ to _++S_)\nopen import Data.Nat.Show using (show)\nopen import Data.Bool using (Bool; false; true; T; _∧_; _∨_)\nopen import Data.Nat using (ℕ; suc; _+_; _∸_; _*_; _<_; _≮_; _≤_; _≰_; \n z≤n; s≤s; _≟_; _≤?_; module ≤-Reasoning)\nopen import Data.Fin \n using (Fin; zero; suc; toℕ; fromℕ; _ℕ-_; _≺_;\n raise; inject+; inject₁; inject≤; _≻toℕ_) \n renaming (_+_ to _F+_)\nopen import Data.Fin.Properties using (bounded; inject+-lemma)\nopen import Data.Vec.Properties \n using (lookup∘tabulate; tabulate∘lookup; lookup-allFin; tabulate-∘; \n tabulate-allFin; map-id; allFin-map)\n\nopen import Data.List \n using (List; []; _∷_; _∷ʳ_; foldl; replicate; reverse; downFrom; \n concatMap; gfilter; initLast; InitLast; _∷ʳ'_) \n renaming (_++_ to _++L_; map to mapL; concat to concatL; zip to zipL)\nopen import Data.List.NonEmpty \n using (List⁺; module List⁺; [_]; _∷⁺_; head; last; _⁺++_)\n renaming (toList to nonEmptyListtoList; _∷ʳ_ to _n∷ʳ_; tail to ntail)\nopen List⁺ public \nopen import Data.List.Any using (Any; here; there; any; module Membership)\nopen import Data.Maybe using (Maybe; nothing; just; maybe′)\nopen import Data.Vec \n using (Vec; tabulate; []; _∷_; tail; lookup; zip; zipWith; splitAt;\n _[_]≔_; allFin; toList)\n renaming (_++_ to _++V_; map to mapV; concat to concatV)\nopen import Function using (id; _∘_; _$_)\n\nopen import Data.Empty using (⊥; ⊥-elim)\nopen import Data.Unit using (⊤; tt)\nopen import Data.Sum using (_⊎_; inj₁; inj₂)\nopen import Data.Product using (Σ; _×_; _,_; proj₁; proj₂)\n\nopen import Cauchy\nopen import Perm\nopen import Proofs\nopen import CauchyProofs\nopen import CauchyProofsT\nopen import CauchyProofsS\nopen import Groupoid\nopen import PiLevel0\nopen import Swaps\nopen import Pif\n\n------------------------------------------------------------------------------\n-- Picture so far:\n--\n-- path p\n-- =====================\n-- || || ||\n-- || ||2path ||\n-- || || ||\n-- || || path q ||\n-- t₁ =================t₂\n-- || ... ||\n-- =====================\n--\n-- The types t₁, t₂, etc are discrete groupoids. The paths between\n-- them correspond to permutations. Each syntactically different\n-- permutation corresponds to a path but equivalent permutations are\n-- connected by 2paths. But now we want an alternative definition of\n-- 2paths that is structural, i.e., that looks at the actual\n-- construction of the path t₁ ⟷ t₂ in terms of combinators... The\n-- theorem we want is that α ∼ β iff we can rewrite α to β using\n-- various syntactic structural rules. We start with a collection of\n-- simplication rules and then try to show they are complete.\n\n-- Simplification rules\n\ninfix 30 _⇔_\n\ndata _⇔_ : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₁ ⟷ t₂) → Set where\n assoc◎l : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₃ ⟷ t₄} → \n (c₁ ◎ (c₂ ◎ c₃)) ⇔ ((c₁ ◎ c₂) ◎ c₃)\n assoc◎r : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₃ ⟷ t₄} → \n ((c₁ ◎ c₂) ◎ c₃) ⇔ (c₁ ◎ (c₂ ◎ c₃))\n assoc⊕l : {t₁ t₂ t₃ t₄ t₅ t₆ : U} \n {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → \n (c₁ ⊕ (c₂ ⊕ c₃)) ⇔ (assocl₊ ◎ ((c₁ ⊕ c₂) ⊕ c₃) ◎ assocr₊)\n assoc⊕r : {t₁ t₂ t₃ t₄ t₅ t₆ : U} \n {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → \n (assocl₊ ◎ ((c₁ ⊕ c₂) ⊕ c₃) ◎ assocr₊) ⇔ (c₁ ⊕ (c₂ ⊕ c₃))\n assoc⊗l : {t₁ t₂ t₃ t₄ t₅ t₆ : U} \n {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → \n (c₁ ⊗ (c₂ ⊗ c₃)) ⇔ (assocl⋆ ◎ ((c₁ ⊗ c₂) ⊗ c₃) ◎ assocr⋆)\n assoc⊗r : {t₁ t₂ t₃ t₄ t₅ t₆ : U} \n {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → \n (assocl⋆ ◎ ((c₁ ⊗ c₂) ⊗ c₃) ◎ assocr⋆) ⇔ (c₁ ⊗ (c₂ ⊗ c₃))\n dist⇔ : {t₁ t₂ t₃ t₄ t₅ t₆ : U} \n {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → \n ((c₁ ⊕ c₂) ⊗ c₃) ⇔ (dist ◎ ((c₁ ⊗ c₃) ⊕ (c₂ ⊗ c₃)) ◎ factor)\n factor⇔ : {t₁ t₂ t₃ t₄ t₅ t₆ : U} \n {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} → \n (dist ◎ ((c₁ ⊗ c₃) ⊕ (c₂ ⊗ c₃)) ◎ factor) ⇔ ((c₁ ⊕ c₂) ⊗ c₃)\n idl◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (id⟷ ◎ c) ⇔ c\n idl◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ id⟷ ◎ c\n idr◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (c ◎ id⟷) ⇔ c\n idr◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ (c ◎ id⟷) \n linv◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (c ◎ ! c) ⇔ id⟷\n linv◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → id⟷ ⇔ (c ◎ ! c) \n rinv◎l : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (! c ◎ c) ⇔ id⟷\n rinv◎r : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → id⟷ ⇔ (! c ◎ c) \n unitel₊⇔ : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → \n (unite₊ ◎ c₂) ⇔ ((c₁ ⊕ c₂) ◎ unite₊)\n uniter₊⇔ : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → \n ((c₁ ⊕ c₂) ◎ unite₊) ⇔ (unite₊ ◎ c₂)\n unitil₊⇔ : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → \n (uniti₊ ◎ (c₁ ⊕ c₂)) ⇔ (c₂ ◎ uniti₊)\n unitir₊⇔ : {t₁ t₂ : U} {c₁ : ZERO ⟷ ZERO} {c₂ : t₁ ⟷ t₂} → \n (c₂ ◎ uniti₊) ⇔ (uniti₊ ◎ (c₁ ⊕ c₂))\n unitial₊⇔ : {t₁ t₂ : U} → (uniti₊ {PLUS t₁ t₂} ◎ assocl₊) ⇔ (uniti₊ ⊕ id⟷)\n unitiar₊⇔ : {t₁ t₂ : U} → (uniti₊ {t₁} ⊕ id⟷ {t₂}) ⇔ (uniti₊ ◎ assocl₊)\n swapl₊⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} → \n (swap₊ ◎ (c₁ ⊕ c₂)) ⇔ ((c₂ ⊕ c₁) ◎ swap₊)\n swapr₊⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} → \n ((c₂ ⊕ c₁) ◎ swap₊) ⇔ (swap₊ ◎ (c₁ ⊕ c₂))\n unitel⋆⇔ : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → \n (unite⋆ ◎ c₂) ⇔ ((c₁ ⊗ c₂) ◎ unite⋆)\n uniter⋆⇔ : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → \n ((c₁ ⊗ c₂) ◎ unite⋆) ⇔ (unite⋆ ◎ c₂)\n unitil⋆⇔ : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → \n (uniti⋆ ◎ (c₁ ⊗ c₂)) ⇔ (c₂ ◎ uniti⋆)\n unitir⋆⇔ : {t₁ t₂ : U} {c₁ : ONE ⟷ ONE} {c₂ : t₁ ⟷ t₂} → \n (c₂ ◎ uniti⋆) ⇔ (uniti⋆ ◎ (c₁ ⊗ c₂))\n unitial⋆⇔ : {t₁ t₂ : U} → (uniti⋆ {TIMES t₁ t₂} ◎ assocl⋆) ⇔ (uniti⋆ ⊗ id⟷)\n unitiar⋆⇔ : {t₁ t₂ : U} → (uniti⋆ {t₁} ⊗ id⟷ {t₂}) ⇔ (uniti⋆ ◎ assocl⋆)\n swapl⋆⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} → \n (swap⋆ ◎ (c₁ ⊗ c₂)) ⇔ ((c₂ ⊗ c₁) ◎ swap⋆)\n swapr⋆⇔ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} → \n ((c₂ ⊗ c₁) ◎ swap⋆) ⇔ (swap⋆ ◎ (c₁ ⊗ c₂))\n swapfl⋆⇔ : {t₁ t₂ t₃ : U} → \n (swap₊ {TIMES t₂ t₃} {TIMES t₁ t₃} ◎ factor) ⇔ \n (factor ◎ (swap₊ {t₂} {t₁} ⊗ id⟷))\n swapfr⋆⇔ : {t₁ t₂ t₃ : U} → \n (factor ◎ (swap₊ {t₂} {t₁} ⊗ id⟷)) ⇔ \n (swap₊ {TIMES t₂ t₃} {TIMES t₁ t₃} ◎ factor)\n id⇔ : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ⇔ c\n trans⇔ : {t₁ t₂ : U} {c₁ c₂ c₃ : t₁ ⟷ t₂} → \n (c₁ ⇔ c₂) → (c₂ ⇔ c₃) → (c₁ ⇔ c₃)\n resp◎⇔ : {t₁ t₂ t₃ : U} \n {c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₁ ⟷ t₂} {c₄ : t₂ ⟷ t₃} → \n (c₁ ⇔ c₃) → (c₂ ⇔ c₄) → (c₁ ◎ c₂) ⇔ (c₃ ◎ c₄)\n resp⊕⇔ : {t₁ t₂ t₃ t₄ : U} \n {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₁ ⟷ t₂} {c₄ : t₃ ⟷ t₄} → \n (c₁ ⇔ c₃) → (c₂ ⇔ c₄) → (c₁ ⊕ c₂) ⇔ (c₃ ⊕ c₄)\n resp⊗⇔ : {t₁ t₂ t₃ t₄ : U} \n {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₁ ⟷ t₂} {c₄ : t₃ ⟷ t₄} → \n (c₁ ⇔ c₃) → (c₂ ⇔ c₄) → (c₁ ⊗ c₂) ⇔ (c₃ ⊗ c₄)\n\n-- better syntax for writing 2paths\n\ninfix 2 _▤\ninfixr 2 _⇔⟨_⟩_ \n\n_⇔⟨_⟩_ : {t₁ t₂ : U} (c₁ : t₁ ⟷ t₂) {c₂ : t₁ ⟷ t₂} {c₃ : t₁ ⟷ t₂} → \n (c₁ ⇔ c₂) → (c₂ ⇔ c₃) → (c₁ ⇔ c₃)\n_ ⇔⟨ α ⟩ β = trans⇔ α β \n\n_▤ : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → (c ⇔ c)\n_▤ c = id⇔ \n\n-- Inverses for 2paths\n\n2! : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ⇔ c₂) → (c₂ ⇔ c₁)\n2! assoc◎l = assoc◎r\n2! assoc◎r = assoc◎l\n2! assoc⊕l = assoc⊕r\n2! assoc⊕r = assoc⊕l\n2! assoc⊗l = assoc⊗r\n2! assoc⊗r = assoc⊗l\n2! dist⇔ = factor⇔ \n2! factor⇔ = dist⇔\n2! idl◎l = idl◎r\n2! idl◎r = idl◎l\n2! idr◎l = idr◎r\n2! idr◎r = idr◎l\n2! linv◎l = linv◎r\n2! linv◎r = linv◎l\n2! rinv◎l = rinv◎r\n2! rinv◎r = rinv◎l\n2! unitel₊⇔ = uniter₊⇔\n2! uniter₊⇔ = unitel₊⇔\n2! unitil₊⇔ = unitir₊⇔\n2! unitir₊⇔ = unitil₊⇔\n2! swapl₊⇔ = swapr₊⇔\n2! swapr₊⇔ = swapl₊⇔\n2! unitial₊⇔ = unitiar₊⇔ \n2! unitiar₊⇔ = unitial₊⇔ \n2! unitel⋆⇔ = uniter⋆⇔\n2! uniter⋆⇔ = unitel⋆⇔\n2! unitil⋆⇔ = unitir⋆⇔\n2! unitir⋆⇔ = unitil⋆⇔\n2! unitial⋆⇔ = unitiar⋆⇔ \n2! unitiar⋆⇔ = unitial⋆⇔ \n2! swapl⋆⇔ = swapr⋆⇔\n2! swapr⋆⇔ = swapl⋆⇔\n2! swapfl⋆⇔ = swapfr⋆⇔\n2! swapfr⋆⇔ = swapfl⋆⇔\n2! id⇔ = id⇔\n2! (trans⇔ α β) = trans⇔ (2! β) (2! α)\n2! (resp◎⇔ α β) = resp◎⇔ (2! α) (2! β)\n2! (resp⊕⇔ α β) = resp⊕⇔ (2! α) (2! β)\n2! (resp⊗⇔ α β) = resp⊗⇔ (2! α) (2! β) \n\n-- a nice example of 2 paths\n\nnegEx : uniti⋆ ◎ (swap⋆ ◎ ((swap₊ {ONE} {ONE} ⊗ id⟷) ◎ (swap⋆ ◎ unite⋆))) \n ⇔ swap₊\nnegEx = uniti⋆ ◎ (swap⋆ ◎ ((swap₊ ⊗ id⟷) ◎ (swap⋆ ◎ unite⋆)))\n ⇔⟨ resp◎⇔ id⇔ assoc◎l ⟩\n uniti⋆ ◎ ((swap⋆ ◎ (swap₊ ⊗ id⟷)) ◎ (swap⋆ ◎ unite⋆))\n ⇔⟨ resp◎⇔ id⇔ (resp◎⇔ swapl⋆⇔ id⇔) ⟩\n uniti⋆ ◎ (((id⟷ ⊗ swap₊) ◎ swap⋆) ◎ (swap⋆ ◎ unite⋆))\n ⇔⟨ resp◎⇔ id⇔ assoc◎r ⟩\n uniti⋆ ◎ ((id⟷ ⊗ swap₊) ◎ (swap⋆ ◎ (swap⋆ ◎ unite⋆)))\n ⇔⟨ resp◎⇔ id⇔ (resp◎⇔ id⇔ assoc◎l) ⟩\n uniti⋆ ◎ ((id⟷ ⊗ swap₊) ◎ ((swap⋆ ◎ swap⋆) ◎ unite⋆))\n ⇔⟨ resp◎⇔ id⇔ (resp◎⇔ id⇔ (resp◎⇔ linv◎l id⇔)) ⟩\n uniti⋆ ◎ ((id⟷ ⊗ swap₊) ◎ (id⟷ ◎ unite⋆))\n ⇔⟨ resp◎⇔ id⇔ (resp◎⇔ id⇔ idl◎l) ⟩\n uniti⋆ ◎ ((id⟷ ⊗ swap₊) ◎ unite⋆)\n ⇔⟨ assoc◎l ⟩\n (uniti⋆ ◎ (id⟷ ⊗ swap₊)) ◎ unite⋆\n ⇔⟨ resp◎⇔ unitil⋆⇔ id⇔ ⟩\n (swap₊ ◎ uniti⋆) ◎ unite⋆\n ⇔⟨ assoc◎r ⟩\n swap₊ ◎ (uniti⋆ ◎ unite⋆)\n ⇔⟨ resp◎⇔ id⇔ linv◎l ⟩\n swap₊ ◎ id⟷\n ⇔⟨ idr◎l ⟩\n swap₊ ▤\n\n-- The equivalence ⇔ of paths is rich enough to make U a 1groupoid:\n-- the points are types (t : U); the 1paths are ⟷; and the 2paths\n-- between them are based on the simplification rules ⇔ \n\nG' : 1Groupoid\nG' = record\n { set = U\n ; _↝_ = _⟷_\n ; _≈_ = _⇔_\n ; id = id⟷\n ; _∘_ = λ p q → q ◎ p\n ; _⁻¹ = !\n ; lneutr = λ _ → idr◎l\n ; rneutr = λ _ → idl◎l\n ; assoc = λ _ _ _ → assoc◎l\n ; equiv = record { \n refl = id⇔\n ; sym = 2!\n ; trans = trans⇔\n }\n ; linv = λ {t₁} {t₂} α → linv◎l\n ; rinv = λ {t₁} {t₂} α → rinv◎l\n ; ∘-resp-≈ = λ p∼q r∼s → resp◎⇔ r∼s p∼q \n }\n\n\n------------------------------------------------------------------------------\n-- Soundness and completeness\n\n-- The idea is to invert evaluation and use that to extract from each\n-- extensional representation of a combinator, a canonical syntactic\n-- representative\n\ncanonical : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₁ ⟷ t₂)\ncanonical c = perm2c (size≡ c , c2perm c)\n\n-- Check canonical NOT = canonical NEG1 = canonical NEG2 = canonical NEG3\n-- = canonical NEG4 = canonical NEG5\n\ncanonicalEx : Bool\ncanonicalEx =\n let x = canonical NOT in \n comb= x (canonical NEG1) ∧\n comb= x (canonical NEG2) ∧\n comb= x (canonical NEG3) ∧\n comb= x (canonical NEG4) ∧\n comb= x (canonical NEG5)\n\n-- Proof of soundness and completeness: now we want to verify that ⇔\n-- is sound and complete with respect to ∼. The statement to prove is\n-- that for all c₁ and c₂, we have c₁ ∼ c₂ iff c₁ ⇔ c₂\n\nassoc⊕∼ : {t₁ t₂ t₃ t₄ t₅ t₆ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} →\n subst Cauchy (+-assoc (size t₁) (size t₃) (size t₅)) (c2cauchy ((c₁ ⊕ c₂) ⊕ c₃))\n ≡ c2cauchy (c₁ ⊕ (c₂ ⊕ c₃)) \nassoc⊕∼ {t₁} {t₂} {t₃} {t₄} {t₅} {t₆} {c₁} {c₂} {c₃} =\n begin (subst Cauchy (+-assoc (size t₁) (size t₃) (size t₅))\n (mapV\n (inject+ (size t₅))\n (mapV (inject+ (size t₃)) (c2cauchy c₁) ++V\n mapV (raise (size t₁)) (c2cauchy c₂))\n ++V mapV (raise (size t₁ + size t₃)) (c2cauchy c₃))\n ≡⟨ cong\n (λ x →\n subst Cauchy (+-assoc (size t₁) (size t₃) (size t₅))\n (x ++V mapV (raise (size t₁ + size t₃)) (c2cauchy c₃)))\n (map-++-commute\n (inject+ (size t₅))\n (mapV (inject+ (size t₃)) (c2cauchy c₁))) ⟩\n subst Cauchy (+-assoc (size t₁) (size t₃) (size t₅))\n ((mapV (inject+ (size t₅)) (mapV (inject+ (size t₃)) (c2cauchy c₁)) ++V\n mapV (inject+ (size t₅)) (mapV (raise (size t₁)) (c2cauchy c₂)))\n ++V mapV (raise (size t₁ + size t₃)) (c2cauchy c₃))\n ≡⟨ cong\n (λ x →\n subst Cauchy (+-assoc (size t₁) (size t₃) (size t₅))\n (x ++V mapV (raise (size t₁ + size t₃)) (c2cauchy c₃)))\n (cong₂ _++V_\n (sym (map-∘ (inject+ (size t₅)) (inject+ (size t₃)) (c2cauchy c₁)))\n (sym (map-∘ (inject+ (size t₅)) (raise (size t₁)) (c2cauchy c₂)))) ⟩ \n subst Cauchy (+-assoc (size t₁) (size t₃) (size t₅))\n ((mapV (inject+ (size t₅) ∘ inject+ (size t₃)) (c2cauchy c₁) ++V\n mapV (inject+ (size t₅) ∘ raise (size t₁)) (c2cauchy c₂))\n ++V mapV (raise (size t₁ + size t₃)) (c2cauchy c₃))\n ≡⟨ {!!} ⟩\n (subst\n (λ x → Vec (Fin x) (size t₁))\n (+-assoc (size t₁) (size t₃) (size t₅))\n (mapV (inject+ (size t₅) ∘ inject+ (size t₃)) (c2cauchy c₁))) ++V\n ((subst\n (λ x → Vec (Fin x) (size t₃))\n (+-assoc (size t₁) (size t₃) (size t₅))\n (mapV (inject+ (size t₅) ∘ raise (size t₁)) (c2cauchy c₂))) ++V\n (subst\n (λ x → Vec (Fin x) (size t₅))\n (+-assoc (size t₁) (size t₃) (size t₅))\n (mapV (raise (size t₁ + size t₃)) (c2cauchy c₃))))\n ≡⟨ {!!} ⟩ \n mapV (inject+ (size t₃ + size t₅)) (c2cauchy c₁) ++V\n (mapV (raise (size t₁) ∘ inject+ (size t₅)) (c2cauchy c₂) ++V\n mapV (raise (size t₁) ∘ raise (size t₃)) (c2cauchy c₃))\n ≡⟨ cong\n (λ x → mapV (inject+ (size t₃ + size t₅)) (c2cauchy c₁) ++V x)\n (cong₂ _++V_ \n (map-∘ (raise (size t₁)) (inject+ (size t₅)) (c2cauchy c₂))\n (map-∘ (raise (size t₁)) (raise (size t₃)) (c2cauchy c₃))) ⟩\n mapV (inject+ (size t₃ + size t₅)) (c2cauchy c₁) ++V\n (mapV (raise (size t₁)) (mapV (inject+ (size t₅)) (c2cauchy c₂)) ++V\n mapV (raise (size t₁)) (mapV (raise (size t₃)) (c2cauchy c₃)))\n ≡⟨ cong\n (λ x → mapV (inject+ (size t₃ + size t₅)) (c2cauchy c₁) ++V x)\n (sym (map-++-commute\n (raise (size t₁))\n (mapV (inject+ (size t₅)) (c2cauchy c₂)))) ⟩ \n mapV (inject+ (size t₃ + size t₅)) (c2cauchy c₁) ++V\n (mapV (raise (size t₁))\n (mapV (inject+ (size t₅)) (c2cauchy c₂) ++V\n mapV (raise (size t₃)) (c2cauchy c₃)))\n ≡⟨ refl ⟩\n pcompcauchy (c2cauchy c₁) (pcompcauchy (c2cauchy c₂) (c2cauchy c₃)) ∎)\n where open ≡-Reasoning\n\nsoundness : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ⇔ c₂) → (c₁ ∼ c₂)\nsoundness (assoc◎l {t₁} {t₂} {t₃} {t₄} {c₁} {c₂} {c₃}) =\n assoc∼ {t₁} {t₂} {t₃} {t₄} {c₁} {c₂} {c₃}\nsoundness (assoc◎r {t₁} {t₂} {t₃} {t₄} {c₁} {c₂} {c₃}) =\n sym (assoc∼ {t₁} {t₂} {t₃} {t₄} {c₁} {c₂} {c₃})\nsoundness (assoc⊕l {t₁} {t₂} {t₃} {t₄} {t₅} {t₆} {c₁} {c₂} {c₃}) =\n begin (c2cauchy (c₁ ⊕ (c₂ ⊕ c₃))\n ≡⟨ sym (assoc⊕∼ {t₁} {t₂} {t₃} {t₄} {t₅} {t₆} {c₁} {c₂} {c₃}) ⟩ \n subst Cauchy (+-assoc (size t₁) (size t₃) (size t₅)) \n (c2cauchy {PLUS (PLUS t₁ t₃) t₅} {PLUS (PLUS t₂ t₄) t₆} ((c₁ ⊕ c₂) ⊕ c₃))\n ≡⟨ sym (scomprid _) ⟩\n scompcauchy\n (subst Cauchy (size≡! (assocl₊ {t₁} {t₃} {t₅}))\n (c2cauchy {PLUS (PLUS t₁ t₃) t₅} {PLUS (PLUS t₂ t₄) t₆} ((c₁ ⊕ c₂) ⊕ c₃)))\n (idcauchy (size t₁ + (size t₃ + size t₅)))\n ≡⟨ cong\n (scompcauchy\n (subst Cauchy (size≡! (assocl₊ {t₁} {t₃} {t₅}))\n (c2cauchy\n {PLUS (PLUS t₁ t₃) t₅}\n {PLUS (PLUS t₂ t₄) t₆}\n ((c₁ ⊕ c₂) ⊕ c₃))))\n (sym (congD! idcauchy (size≡! (assocl₊ {t₁} {t₃} {t₅})))) ⟩\n scompcauchy\n (subst Cauchy (size≡! (assocl₊ {t₁} {t₃} {t₅}))\n (c2cauchy {PLUS (PLUS t₁ t₃) t₅} {PLUS (PLUS t₂ t₄) t₆} ((c₁ ⊕ c₂) ⊕ c₃)))\n (subst Cauchy (size≡! (assocl₊ {t₁} {t₃} {t₅}))\n (idcauchy ((size t₁ + size t₃) + size t₅)))\n ≡⟨ cong\n (λ x →\n scompcauchy\n (subst Cauchy (size≡! (assocl₊ {t₁} {t₃} {t₅}))\n (c2cauchy\n {PLUS (PLUS t₁ t₃) t₅}\n {PLUS (PLUS t₂ t₄) t₆}\n ((c₁ ⊕ c₂) ⊕ c₃)))\n (subst Cauchy (size≡! (assocl₊ {t₁} {t₃} {t₅})) x))\n (sym (congD! idcauchy (size≡! ((c₁ ⊕ c₂) ⊕ c₃)))) ⟩\n scompcauchy\n (subst Cauchy (size≡! (assocl₊ {t₁} {t₃} {t₅}))\n (c2cauchy {PLUS (PLUS t₁ t₃) t₅} {PLUS (PLUS t₂ t₄) t₆} ((c₁ ⊕ c₂) ⊕ c₃)))\n (subst Cauchy (size≡! (assocl₊ {t₁} {t₃} {t₅}))\n (subst Cauchy (size≡! ((c₁ ⊕ c₂) ⊕ c₃))\n (idcauchy ((size t₂ + size t₄) + size t₆))))\n ≡⟨ sym (subst-dist scompcauchy (size≡! (assocl₊ {t₁} {t₃} {t₅})) _ _) ⟩\n subst Cauchy (size≡! (assocl₊ {t₁} {t₃} {t₅}))\n (scompcauchy\n (c2cauchy {PLUS (PLUS t₁ t₃) t₅} {PLUS (PLUS t₂ t₄) t₆} ((c₁ ⊕ c₂) ⊕ c₃))\n (subst Cauchy (size≡! ((c₁ ⊕ c₂) ⊕ c₃))\n (idcauchy ((size t₂ + size t₄) + size t₆))))\n ≡⟨ sym (scomplid _) ⟩\n scompcauchy\n (idcauchy (size t₁ + (size t₃ + size t₅)))\n (subst Cauchy (size≡! (assocl₊ {t₁} {t₃} {t₅}))\n (scompcauchy\n (c2cauchy\n {PLUS (PLUS t₁ t₃) t₅} {PLUS (PLUS t₂ t₄) t₆} ((c₁ ⊕ c₂) ⊕ c₃))\n (subst Cauchy (size≡! ((c₁ ⊕ c₂) ⊕ c₃))\n (idcauchy ((size t₂ + size t₄) + size t₆)))))\n ≡⟨ refl ⟩\n c2cauchy (assocl₊ ◎ (((c₁ ⊕ c₂) ⊕ c₃) ◎ assocr₊)) ∎)\n where open ≡-Reasoning\nsoundness (assoc⊕r {t₁} {t₂} {t₃} {t₄} {t₅} {t₆} {c₁} {c₂} {c₃}) = {!!}\nsoundness (assoc⊗l {t₁} {t₂} {t₃} {t₄} {t₅} {t₆} {c₁} {c₂} {c₃}) = {!!}\nsoundness (assoc⊗r {t₁} {t₂} {t₃} {t₄} {t₅} {t₆} {c₁} {c₂} {c₃}) = {!!}\nsoundness (dist⇔ {t₁} {t₂} {t₃} {t₄} {t₅} {t₆} {c₁} {c₂} {c₃}) = {!!}\nsoundness (factor⇔ {t₁} {t₂} {t₃} {t₄} {t₅} {t₆} {c₁} {c₂} {c₃}) = {!!}\nsoundness (idl◎l {t₁} {t₂} {c}) = id◎c∼c {t₁} {t₂} {c}\nsoundness (idl◎r {t₁} {t₂} {c}) = sym (id◎c∼c {t₁} {t₂} {c})\nsoundness (idr◎l {t₁} {t₂} {c}) = c◎id∼c {t₁} {t₂} {c}\nsoundness (idr◎r {t₁} {t₂} {c}) = sym (c◎id∼c {t₁} {t₂} {c})\nsoundness (linv◎l {t₁} {t₂} {c}) = linv∼ {t₁} {t₂} {c}\nsoundness (linv◎r {t₁} {t₂} {c}) = sym (linv∼ {t₁} {t₂} {c})\nsoundness (rinv◎l {t₁} {t₂} {c}) = rinv∼ {t₁} {t₂} {c}\nsoundness (rinv◎r {t₁} {t₂} {c}) = sym (rinv∼ {t₁} {t₂} {c})\nsoundness (unitel₊⇔ {t₁} {t₂} {c₁} {c₂}) = {!!}\nsoundness (uniter₊⇔ {t₁} {t₂} {c₁} {c₂}) = {!!}\nsoundness (unitil₊⇔ {t₁} {t₂} {c₁} {c₂}) = {!!}\nsoundness (unitir₊⇔ {t₁} {t₂} {c₁} {c₂}) = {!!}\nsoundness (unitial₊⇔ {t₁} {t₂}) = {!!}\nsoundness (unitiar₊⇔ {t₁} {t₂}) = {!!}\nsoundness (swapl₊⇔ {t₁} {t₂} {t₃} {t₄} {c₁} {c₂}) = {!!}\nsoundness (swapr₊⇔ {t₁} {t₂} {t₃} {t₄} {c₁} {c₂}) = {!!}\nsoundness (unitel⋆⇔ {t₁} {t₂} {c₁} {c₂}) = {!!}\nsoundness (uniter⋆⇔ {t₁} {t₂} {c₁} {c₂}) = {!!}\nsoundness (unitil⋆⇔ {t₁} {t₂} {c₁} {c₂}) = {!!}\nsoundness (unitir⋆⇔ {t₁} {t₂} {c₁} {c₂}) = {!!}\nsoundness (unitial⋆⇔ {t₁} {t₂}) = {!!}\nsoundness (unitiar⋆⇔ {t₁} {t₂}) = {!!}\nsoundness (swapl⋆⇔ {t₁} {t₂} {t₃} {t₄} {c₁} {c₂}) = {!!}\nsoundness (swapr⋆⇔ {t₁} {t₂} {t₃} {t₄} {c₁} {c₂}) = {!!}\nsoundness (swapfl⋆⇔ {t₁} {t₂} {t₃}) = {!!}\nsoundness (swapfr⋆⇔ {t₁} {t₂} {t₃}) = {!!}\nsoundness (id⇔ {t₁} {t₂} {c}) = refl∼ {t₁} {t₂} {c}\nsoundness (trans⇔ {t₁} {t₂} {c₁} {c₂} {c₃} α β) =\n trans∼ {t₁} {t₂} {c₁} {c₂} {c₃} (soundness α) (soundness β)\nsoundness (resp◎⇔ {t₁} {t₂} {t₃} {c₁} {c₃} {c₂} {c₄} α β) =\n resp∼ {t₁} {t₂} {t₃} {c₁} {c₂} {c₃} {c₄} (soundness α) (soundness β)\nsoundness (resp⊕⇔ {t₁} {t₂} {t₃} {t₄} {c₁} {c₂} {c₃} {c₄} α β) = {!!}\nsoundness (resp⊗⇔ {t₁} {t₂} {t₃} {t₄} {c₁} {c₂} {c₃} {c₄} α β) = {!!}\n\n-- If we can prove that every combinator is equal to its normal form\n-- then we can prove completeness.\n\ninversion : {t₁ t₂ : U} (c : t₁ ⟷ t₂) → canonical c ⇔ c\ninversion (c₁ ◎ c₂) = {!!} \ninversion {PLUS ZERO t} {.t} unite₊ = {!!} \ninversion {t} {PLUS ZERO .t} uniti₊ = {!!} \ninversion {PLUS t₁ t₂} {PLUS .t₂ .t₁} swap₊ = {!!} \ninversion {PLUS t₁ (PLUS t₂ t₃)} {PLUS (PLUS .t₁ .t₂) .t₃} assocl₊ = {!!} \ninversion {PLUS (PLUS t₁ t₂) t₃} {PLUS .t₁ (PLUS .t₂ .t₃)} assocr₊ = {!!}\ninversion {TIMES ONE t} {.t} unite⋆ = {!!}\ninversion {t} {TIMES ONE .t} uniti⋆ = {!!} \ninversion {TIMES t₁ t₂} {TIMES .t₂ .t₁} swap⋆ = {!!} \ninversion {TIMES t₁ (TIMES t₂ t₃)} {TIMES (TIMES .t₁ .t₂) .t₃} assocl⋆ = {!!}\ninversion {TIMES (TIMES t₁ t₂) t₃} {TIMES .t₁ (TIMES .t₂ .t₃)} assocr⋆ = {!!}\ninversion {TIMES .ZERO t} {ZERO} distz = {!!} \ninversion {ZERO} {TIMES ZERO t} factorz = {!!} \ninversion {TIMES (PLUS t₁ t₂) t₃} {PLUS (TIMES .t₁ .t₃) (TIMES .t₂ .t₃)} dist = {!!}\ninversion {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} {TIMES (PLUS .t₁ .t₂) .t₃} factor = {!!}\ninversion {t} {.t} id⟷ =\n canonical id⟷\n ⇔⟨ id⇔ ⟩\n normalizeC t ◎\n transposition*2c (size t) (size t) refl (cauchy→transposition* (idcauchy (size t))) ◎\n ! (normalizeC t)\n ⇔⟨ {!!} ⟩\n normalizeC t ◎ id⟷ ◎ ! (normalizeC t)\n ⇔⟨ resp◎⇔ id⇔ idl◎l ⟩\n normalizeC t ◎ ! (normalizeC t)\n ⇔⟨ linv◎l ⟩\n id⟷ ▤\ninversion {PLUS t₁ t₂} {PLUS t₃ t₄} (c₁ ⊕ c₂) = {!!} \ninversion {TIMES t₁ t₂} {TIMES t₃ t₄} (c₁ ⊗ c₂) = {!!} \ninversion {PLUS ONE ONE} {BOOL} foldBool = {!!}\n{--\ncanonical foldBool =\n ((uniti₊ ◎ swap₊ ⊕ uniti₊ ◎ swap₊) ◎ assocr₊ ◎ (id⟷ ⊕ unite₊)) ◎\n (id⟷ ◎ (id⟷ ⊕ id⟷) ◎ id⟷) ◎\n (((id⟷ ⊕ uniti₊) ◎ assocl₊) ◎ (swap₊ ◎ unite₊ ⊕ swap₊ ◎ unite₊)) ◎\n foldBool\n--}\ninversion {BOOL} {PLUS ONE ONE} unfoldBool = {!!} \n\nresp≡⇔ : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ≡ c₂) → (c₁ ⇔ c₂)\nresp≡⇔ {t₁} {t₂} {c₁} {c₂} p rewrite p = id⇔ \n\ncompleteness : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ∼ c₂) → (c₁ ⇔ c₂)\ncompleteness {t₁} {t₂} {c₁} {c₂} c₁∼c₂ = \n c₁\n ⇔⟨ 2! (inversion c₁) ⟩\n canonical c₁\n ⇔⟨ resp≡⇔ {!!} ⟩ \n canonical c₂\n ⇔⟨ inversion c₂ ⟩ \n c₂ ▤\n\n------------------------------------------------------------------------------\n", "meta": {"hexsha": "c6b7f93713971ed1753678b9bcbadb1ab36ffce9", "size": 22654, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Univalence/Obsolete/Pif2.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "Univalence/Obsolete/Pif2.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "Univalence/Obsolete/Pif2.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 42.0296846011, "max_line_length": 87, "alphanum_fraction": 0.4867131632, "num_tokens": 11681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6859494421679929, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.3776888152424863}} {"text": "{-\n\nTechnical results about row transformation applied to matrices\n\n-}\n{-# OPTIONS --safe #-}\nmodule Cubical.Algebra.Matrix.RowTransformation where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\n\nopen import Cubical.Data.Nat hiding (_+_ ; _·_)\nopen import Cubical.Data.Nat.Order\nopen import Cubical.Data.Empty as Empty\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Bool\nopen import Cubical.Data.FinData renaming (znots to znotsFin ; snotz to snotzFin)\n\nopen import Cubical.Relation.Nullary\n\nopen import Cubical.Algebra.Matrix\nopen import Cubical.Algebra.RingSolver.Reflection\n\nopen import Cubical.Algebra.Ring\nopen import Cubical.Algebra.Ring.BigOps\nopen import Cubical.Algebra.CommRing\nopen import Cubical.Algebra.RingSolver.Reflection\nopen import Cubical.Algebra.Matrix.CommRingCoefficient\n\nprivate\n variable\n ℓ : Level\n A : Type ℓ\n m n k l : ℕ\n\ntakeRows : FinMatrix A (suc (suc m)) n → FinMatrix A 2 n\ntakeRows M zero = M zero\ntakeRows M one = M one\n\ntakeRowsᶜ : FinMatrix A (suc (suc m)) n → FinMatrix A (suc m) n\ntakeRowsᶜ M zero = M zero\ntakeRowsᶜ M (suc i) = M (suc (suc i))\n\ncombRows : FinMatrix A (suc (suc m)) n → FinMatrix A 2 n → FinMatrix A (suc m) n\ncombRows M M₀ zero = M₀ zero\ncombRows M M₀ (suc i) = M (suc (suc i))\n\nshufRows : FinMatrix A 2 n → FinMatrix A (suc m) n → FinMatrix A (suc (suc m)) n\nshufRows M₀ M₁ zero = M₁ zero\nshufRows M₀ M₁ one = M₀ one\nshufRows M₀ M₁ (suc (suc i)) = M₁ (suc i)\n\nmodule _\n (T₀ : FinMatrix A 2 n → FinMatrix A 2 n)\n (M : FinMatrix A (suc (suc m)) n) where\n\n private\n M₀ = T₀ (takeRows M)\n\n takeTrans : FinMatrix A (suc (suc m)) n\n takeTrans zero = M₀ zero\n takeTrans one = M₀ one\n takeTrans (suc (suc i)) = M (suc (suc i))\n\nmodule _\n (T₁ : FinMatrix A (suc m) n → FinMatrix A (suc m) n)\n (M : FinMatrix A (suc (suc m)) n) where\n\n private\n M₁ = T₁ (takeRowsᶜ M)\n\n combTrans : FinMatrix A (suc (suc m)) n\n combTrans zero = M₁ zero\n combTrans one = M one\n combTrans (suc (suc i)) = M₁ (suc i)\n\nmodule _\n (T₀ : FinMatrix A 2 n → FinMatrix A 2 n)\n (T₁ : FinMatrix A (suc m) n → FinMatrix A (suc m) n)\n (M : FinMatrix A (suc (suc m)) n) where\n\n private\n M₀ = T₀ (takeRows M)\n M₁ = T₁ (combRows M M₀)\n\n helper : takeRowsᶜ (takeTrans T₀ M) ≡ combRows M M₀\n helper t zero = M₀ zero\n helper t (suc i) = M (suc (suc i))\n\n takeCombShufRows : FinMatrix A (suc (suc m)) n\n takeCombShufRows = shufRows M₀ M₁\n\n takeCombShufEquiv : combTrans T₁ (takeTrans T₀ M) ≡ takeCombShufRows\n takeCombShufEquiv t zero = T₁ (helper t) zero\n takeCombShufEquiv t one = M₀ one\n takeCombShufEquiv t (suc (suc i)) = T₁ (helper t) (suc i)\n\n-- The iterated row transformation\n\nmodule _\n (T : FinMatrix A 2 n → FinMatrix A 2 n) where\n\n transRows : FinMatrix A (suc m) n → FinMatrix A (suc m) n\n transRows {m = 0} M = M\n transRows {m = suc m} = takeCombShufRows T transRows\n\n -- Several induction principle to prove properties after transformation\n\n module _\n (invRow : (M : FinMatrix A 2 n) → M zero ≡ T M zero) where\n\n invRow₀ : (M : FinMatrix A (suc m) n) → M zero ≡ transRows M zero\n invRow₀ {m = 0} _ = refl\n invRow₀ {m = suc m} M = invRow _ ∙ invRow₀ (combRows M _)\n\n module _\n (P : FinVec A n → Type ℓ)\n (indP : (M : FinMatrix A 2 n) → P (M zero) → P (T M zero)) where\n\n transRowsIndP : (M : FinMatrix A (suc m) n) → P (M zero) → P (transRows M zero)\n transRowsIndP {m = 0} _ h = h\n transRowsIndP {m = suc m} M h = transRowsIndP (combRows M _) (indP _ h)\n\n module _\n (P : FinVec A n → Type ℓ)\n (indP : (M : FinMatrix A 2 n) → P (T M one)) where\n\n transRowsIndP' : (M : FinMatrix A (suc m) n) → (i : Fin m) → P (transRows M (suc i))\n transRowsIndP' {m = suc m} M zero = indP _\n transRowsIndP' {m = suc m} M (suc i) = transRowsIndP' _ i\n\n module _\n (Q : FinVec A n → Type ℓ)\n (P : FinVec A n → Type ℓ)\n (indQ : (M : FinMatrix A 2 n) → Q (M zero) → Q (T M zero))\n (indP : (M : FinMatrix A 2 n) → Q (M zero) → P (T M one )) where\n\n transRowsIndPQ : (M : FinMatrix A (suc m) n) → Q (M zero) → (i : Fin m) → P (transRows M (suc i))\n transRowsIndPQ {m = suc m} M p zero = indP _ p\n transRowsIndPQ {m = suc m} M p (suc i) = transRowsIndPQ _ (indQ _ p) i\n\n module _\n (Q : FinVec A n → Type ℓ)\n (P : FinVec A n → Type ℓ)\n (indQ : (M : FinMatrix A 2 n) → Q (M zero) → Q (T M zero))\n (indP : (M : FinMatrix A 2 n) → P (M one ) → Q (T M zero)) where\n\n transRowsIndPQ' : (M : FinMatrix A (suc m) n) → (i : Fin m) → P (M (suc i)) → Q (transRows M zero)\n transRowsIndPQ' {m = suc m} M zero p = transRowsIndP Q indQ (combRows M _) (indP _ p)\n transRowsIndPQ' {m = suc m} M (suc i) p = transRowsIndPQ' (combRows M _) _ p\n\n module _\n (Rel : FinVec A n → FinVec A n → Type ℓ)\n (indRel : (M : FinMatrix A 2 n) → Rel (M one) (T M one)) where\n\n transRowsIndRel : (M : FinMatrix A (suc m) n) → (i : Fin m) → Rel (M (suc i)) (transRows M (suc i))\n transRowsIndRel {m = suc m} M zero = indRel _\n transRowsIndRel {m = suc m} M (suc i) = transRowsIndRel _ i\n\n module _\n (Rel3 : FinVec A n → FinVec A n → FinVec A n → Type ℓ)\n (invRow : (M : FinMatrix A 2 n) → M zero ≡ T M zero)\n (indRel3 : (M : FinMatrix A 2 n) → Rel3 (M zero) (M one) (T M one)) where\n\n transRowsIndRel3 : (M : FinMatrix A (suc m) n) → (i : Fin m) → Rel3 (M zero) (M (suc i)) (transRows M (suc i))\n transRowsIndRel3 {m = suc m} M zero = indRel3 _\n transRowsIndRel3 {m = suc m} M (suc i) =\n subst (λ V → Rel3 V (M (suc (suc i)))\n (transRows M (suc (suc i)))) (sym (invRow _)) (transRowsIndRel3 _ i)\n\n module _\n (Rel : FinVec A n → FinVec A n → Type ℓ)\n (indRel : (M : FinMatrix A 2 n) → Rel (M zero) (M one) → M zero ≡ T M zero) where\n\n transRowsIndRelInv :\n (M : FinMatrix A (suc m) n)\n → ((i : Fin m) → Rel (M zero) (M (suc i)))\n → M zero ≡ transRows M zero\n transRowsIndRelInv {m = 0} _ _ = refl\n transRowsIndRelInv {m = suc m} M rel =\n let invRow = indRel _ (rel zero)\n rel₁ = (λ i → subst (λ V → Rel V (M (suc (suc i)))) invRow (rel (suc i)))\n in invRow ∙ transRowsIndRelInv _ rel₁\n\n module _\n (P : FinVec A n → Type ℓ)\n (Rel : FinVec A n → FinVec A n → Type ℓ)\n (indPRel : (M : FinMatrix A 2 n) → P (M zero) → Rel (M zero) (M one) → M zero ≡ T M zero) where\n\n transRowsIndPRelInv :\n (M : FinMatrix A (suc m) n)\n → P (M zero)\n → ((i : Fin m) → Rel (M zero) (M (suc i)))\n → M zero ≡ transRows M zero\n transRowsIndPRelInv {m = 0} _ _ _ = refl\n transRowsIndPRelInv {m = suc m} M p rel =\n let invRow = indPRel _ p (rel zero)\n p₁ = subst P invRow p\n rel₁ = (λ i → subst (λ V → Rel V (M (suc (suc i)))) invRow (rel (suc i)))\n in invRow ∙ transRowsIndPRelInv _ p₁ rel₁\n\n module _\n (P : FinVec A n → Type ℓ)\n (indP₀ : (M : FinMatrix A 2 n) → P (M zero) → P (M one) → P (T M zero))\n (indP₁ : (M : FinMatrix A 2 n) → P (M zero) → P (M one) → P (T M one )) where\n\n transRowsIndP₀ :\n (M : FinMatrix A (suc m) n)\n → P (M zero)\n → ((i : Fin m) → P (M (suc i)))\n → P (transRows M zero)\n transRowsIndP₀ {m = 0} _ p _ = p\n transRowsIndP₀ {m = suc m} _ p q = transRowsIndP₀ _ (indP₀ _ p (q zero)) (q ∘ suc)\n\n transRowsIndP₁ :\n (M : FinMatrix A (suc m) n)\n → P (M zero)\n → ((i : Fin m) → P (M (suc i)))\n → (i : Fin m) → P (transRows M (suc i))\n transRowsIndP₁ {m = 0} _ _ q = q\n transRowsIndP₁ {m = suc m} _ p q zero = indP₁ _ p (q zero)\n transRowsIndP₁ {m = suc m} M p q (suc i) = transRowsIndP₁ _ (indP₀ _ p (q zero)) (q ∘ suc) i\n\n\n-- Row transformation of linear coefficient matrices\n\nmodule LinearTransformation (𝓡 : CommRing ℓ) where\n\n private\n R = 𝓡 .fst\n 𝑹 = CommRing→Ring 𝓡\n AbR = Ring→AbGroup 𝑹\n\n open CommRingStr (𝓡 .snd) renaming ( is-set to isSetR )\n open CommRingTheory 𝓡\n open RingTheory 𝑹\n open KroneckerDelta 𝑹\n open Sum 𝑹\n\n open Coefficient 𝓡\n\n -- Definition of linear transformation\n\n record isLinear2×2 (T : Mat 2 n → Mat 2 n) : Type ℓ where\n field\n transMat : (M : Mat 2 n) → Mat 2 2\n transEq : (M : Mat 2 n) → T M ≡ transMat M ⋆ M\n\n record isLinear (T : Mat m n → Mat k n) : Type ℓ where\n field\n transMat : (M : Mat m n) → Mat k m\n transEq : (M : Mat m n) → T M ≡ transMat M ⋆ M\n\n open isLinear2×2\n open isLinear\n\n isLinearId : isLinear {m = m} {n = n} (idfun _)\n isLinearId .transMat _ = 𝟙\n isLinearId .transEq _ = sym (⋆lUnit _)\n\n isInvId : (M : Mat (suc m) (suc n)) → isInv (isLinearId .transMat M)\n isInvId _ = isInv𝟙\n\n module _\n {T₁ : Mat (suc m) (suc n) → Mat (suc k) (suc n)}\n {T₂ : Mat (suc k) (suc n) → Mat (suc l) (suc n)}\n (isLinearT₁ : isLinear T₁)\n (isLinearT₂ : isLinear T₂) where\n\n isLinearComp : isLinear (T₂ ∘ T₁)\n isLinearComp .transMat M =\n let T₁M = isLinearT₁ .transMat M in\n isLinearT₂ .transMat (T₁ M) ⋆ T₁M\n isLinearComp .transEq M =\n isLinearT₂ .transEq _\n ∙ (λ t → isLinearT₂ .transMat (T₁ M) ⋆ (isLinearT₁ .transEq M t))\n ∙ ⋆Assoc (isLinearT₂ .transMat _) (isLinearT₁ .transMat M) M\n\n module _\n {T₁ : Mat (suc m) (suc n) → Mat (suc m) (suc n)}\n {T₂ : Mat (suc m) (suc n) → Mat (suc m) (suc n)}\n (isLinearT₁ : isLinear T₁)\n (isLinearT₂ : isLinear T₂) where\n\n module _\n (isInvT₁ : (M : Mat (suc m) (suc n)) → isInv (isLinearT₁ .transMat M))\n (isInvT₂ : (M : Mat (suc m) (suc n)) → isInv (isLinearT₂ .transMat M)) where\n\n isInvComp : (M : Mat (suc m) (suc n)) → isInv (isLinearComp isLinearT₁ isLinearT₂ .transMat M)\n isInvComp M =\n let T₁M = isLinearT₁ .transMat M in\n isInv⋆ {M = isLinearT₂ .transMat (T₁ M)} {M' = T₁M} (isInvT₂ (T₁ M)) (isInvT₁ M)\n\n module _\n (P : FinVec R (suc n) → Type ℓ)\n (indP : (M : Mat (suc m) (suc n)) → P (M zero) → P (T₁ M zero))\n (isInvT₁ : (M : Mat (suc m) (suc n)) → P (M zero) → isInv (isLinearT₁ .transMat M))\n (isInvT₂ : (M : Mat (suc m) (suc n)) → P (M zero) → isInv (isLinearT₂ .transMat M)) where\n\n isInvCompInd : (M : Mat (suc m) (suc n)) → P (M zero) → isInv (isLinearComp isLinearT₁ isLinearT₂ .transMat M)\n isInvCompInd M p =\n let T₁M = isLinearT₁ .transMat M in\n isInv⋆ {M = isLinearT₂ .transMat (T₁ M)} {M' = T₁M} (isInvT₂ (T₁ M) (indP _ p)) (isInvT₁ M p)\n\n -- Linearity of row transformation\n\n takeTransMat : Mat 2 2 → Mat (suc (suc m)) (suc (suc m))\n takeTransMat P zero zero = P zero zero\n takeTransMat P one zero = P one zero\n takeTransMat P zero one = P zero one\n takeTransMat P one one = P one one\n takeTransMat _ zero (suc (suc j)) = 0r\n takeTransMat _ one (suc (suc j)) = 0r\n takeTransMat _ (suc (suc i)) zero = 0r\n takeTransMat _ (suc (suc i)) one = 0r\n takeTransMat _ (suc (suc i)) (suc (suc j)) = 𝟙 i j\n\n takeTransMat𝟙 : takeTransMat {m = m} 𝟙 ≡ 𝟙\n takeTransMat𝟙 t zero zero = 1r\n takeTransMat𝟙 t one zero = 0r\n takeTransMat𝟙 t zero one = 0r\n takeTransMat𝟙 t one one = 1r\n takeTransMat𝟙 t zero (suc (suc j)) = 0r\n takeTransMat𝟙 t one (suc (suc j)) = 0r\n takeTransMat𝟙 t (suc (suc i)) zero = 0r\n takeTransMat𝟙 t (suc (suc i)) one = 0r\n takeTransMat𝟙 t (suc (suc i)) (suc (suc j)) = δ i j\n\n module _\n (M N : Mat 2 2) where\n\n ⋆TakeTransMat : takeTransMat M ⋆ takeTransMat N ≡ takeTransMat {m = m} (M ⋆ N)\n ⋆TakeTransMat {m = m} t zero zero =\n M zero zero · N zero zero + (M zero one · N one zero + ∑Mul0r {n = m} (λ i → 0r) t)\n ⋆TakeTransMat {m = m} t one zero =\n M one zero · N zero zero + (M one one · N one zero + ∑Mul0r {n = m} (λ i → 0r) t)\n ⋆TakeTransMat {m = m} t zero one =\n M zero zero · N zero one + (M zero one · N one one + ∑Mul0r {n = m} (λ i → 0r) t)\n ⋆TakeTransMat {m = m} t one one =\n M one zero · N zero one + (M one one · N one one + ∑Mul0r {n = m} (λ i → 0r) t)\n ⋆TakeTransMat t zero (suc (suc j)) =\n (helper (M zero zero) (M zero one ) _ ∙ ∑Mul0r (λ i → 𝟙 i j)) t\n where helper : (a b c : R) → a · 0r + (b · 0r + c) ≡ c\n helper = solve 𝓡\n ⋆TakeTransMat t one (suc (suc j)) =\n (helper (M one zero) (M one one ) _ ∙ ∑Mul0r (λ i → 𝟙 i j)) t\n where helper : (a b c : R) → a · 0r + (b · 0r + c) ≡ c\n helper = solve 𝓡\n ⋆TakeTransMat t (suc (suc i)) zero =\n (helper (N zero zero) (N one zero) _ ∙ ∑Mulr0 (λ j → 𝟙 i j)) t\n where helper : (a b c : R) → 0r · a + (0r · b + c) ≡ c\n helper = solve 𝓡\n ⋆TakeTransMat t (suc (suc i)) one =\n (helper (N zero one ) (N one one ) _ ∙ ∑Mulr0 (λ j → 𝟙 i j)) t\n where helper : (a b c : R) → 0r · a + (0r · b + c) ≡ c\n helper = solve 𝓡\n ⋆TakeTransMat t (suc (suc i)) (suc (suc j)) =\n (helper _\n ∙ (λ t → ⋆lUnit 𝟙 t i j)) t\n where helper : (c : R) → 0r · 0r + (0r · 0r + c) ≡ c\n helper = solve 𝓡\n\n module _\n (T₀ : Mat 2 (suc n) → Mat 2 (suc n))\n (isLinear2×2T₀ : isLinear2×2 T₀) where\n\n module _\n (M : Mat (suc (suc m)) (suc n)) where\n\n private\n P = isLinear2×2T₀ .transMat (takeRows M)\n\n takeTransEquiv : takeTrans T₀ M ≡ takeTransMat P ⋆ M\n takeTransEquiv t zero j =\n ((λ t → isLinear2×2T₀ .transEq (takeRows M) t zero j)\n ∙ mul2 P (takeRows M) _ _\n ∙ helper _ _\n ∙ (λ t → P zero zero · M zero j + (P zero one · M one j\n + ∑Mul0r (λ i → M (suc (suc i)) j) (~ t)))) t\n where helper : (a b : R) → a + b ≡ a + (b + 0r)\n helper = solve 𝓡\n takeTransEquiv t one j =\n ((λ t → isLinear2×2T₀ .transEq (takeRows M) t one j)\n ∙ mul2 P (takeRows M) _ _\n ∙ helper _ _\n ∙ (λ t → P one zero · M zero j + (P one one · M one j\n + ∑Mul0r (λ i → M (suc (suc i)) j) (~ t)))) t\n where helper : (a b : R) → a + b ≡ a + (b + 0r)\n helper = solve 𝓡\n takeTransEquiv t (suc (suc i)) j =\n ((λ t → ⋆lUnit (λ i j → M (suc (suc i)) j) (~ t) i j)\n ∙ helper (M zero j) (M one j) _) t\n where helper : (a b c : R) → c ≡ 0r · a + (0r · b + c)\n helper = solve 𝓡\n\n isLinearTakeRowsTrans : isLinear (takeTrans {m = m} T₀)\n isLinearTakeRowsTrans .transMat M = takeTransMat _\n isLinearTakeRowsTrans .transEq = takeTransEquiv\n\n isInvTakeTransMat : (M : Mat 2 2)(isInvM : isInv M) → isInv (takeTransMat {m = m} M)\n isInvTakeTransMat M isInvM .fst = takeTransMat (isInvM .fst)\n isInvTakeTransMat M isInvM .snd .fst =\n ⋆TakeTransMat _ _ ∙ (λ t → takeTransMat (isInvM .snd .fst t)) ∙ takeTransMat𝟙\n isInvTakeTransMat M isInvM .snd .snd =\n ⋆TakeTransMat _ _ ∙ (λ t → takeTransMat (isInvM .snd .snd t)) ∙ takeTransMat𝟙\n\n combTransMat : Mat (suc m) (suc m) → Mat (suc (suc m)) (suc (suc m))\n combTransMat P zero zero = P zero zero\n combTransMat _ zero one = 0r\n combTransMat _ one zero = 0r\n combTransMat _ one one = 1r\n combTransMat P zero (suc (suc j)) = P zero (suc j)\n combTransMat _ one (suc (suc j)) = 0r\n combTransMat P (suc (suc i)) zero = P (suc i) zero\n combTransMat _ (suc (suc i)) one = 0r\n combTransMat P (suc (suc i)) (suc (suc j)) = P (suc i) (suc j)\n\n combTransMat𝟙 : combTransMat {m = m} 𝟙 ≡ 𝟙\n combTransMat𝟙 t zero zero = 1r\n combTransMat𝟙 t zero one = 0r\n combTransMat𝟙 t one zero = 0r\n combTransMat𝟙 t one one = 1r\n combTransMat𝟙 t zero (suc (suc j)) = 0r\n combTransMat𝟙 t one (suc (suc j)) = 0r\n combTransMat𝟙 t (suc (suc i)) zero = 0r\n combTransMat𝟙 t (suc (suc i)) one = 0r\n combTransMat𝟙 t (suc (suc i)) (suc (suc j)) = δ i j\n\n module _\n (M N : Mat (suc m) (suc m)) where\n\n ⋆CombTransMat : combTransMat M ⋆ combTransMat N ≡ combTransMat (M ⋆ N)\n ⋆CombTransMat t zero zero =\n helper (M zero zero · N zero zero) (∑ (λ l → M zero (suc l) · N (suc l) zero)) t\n where helper : (a c : R) → a + (0r · 0r + c) ≡ a + c\n helper = solve 𝓡\n ⋆CombTransMat t zero one =\n (helper (M zero zero) _ ∙ ∑Mulr0 (λ j → M zero (suc j))) t\n where helper : (a c : R) → a · 0r + (0r · 1r + c) ≡ c\n helper = solve 𝓡\n ⋆CombTransMat t one zero =\n (helper (N zero zero) _ ∙ ∑Mul0r (λ i → N (suc i) zero)) t\n where helper : (a c : R) → 0r · a + (1r · 0r + c) ≡ c\n helper = solve 𝓡\n ⋆CombTransMat t one one =\n ((λ t → 0r · 0r + (1r · 1r + ∑Mul0r {n = m} (λ i → 0r) t))\n ∙ helper) t\n where helper : 0r · 0r + (1r · 1r + 0r) ≡ 1r\n helper = solve 𝓡\n ⋆CombTransMat t zero (suc (suc j)) =\n helper (M zero zero · N zero (suc j)) (∑ (λ l → M zero (suc l) · N (suc l) (suc j))) t\n where helper : (a c : R) → a + (0r · 0r + c) ≡ a + c\n helper = solve 𝓡\n ⋆CombTransMat t one (suc (suc j)) =\n (helper (N zero (suc j)) _ ∙ ∑Mul0r (λ i → N (suc i) (suc j))) t\n where helper : (a c : R) → 0r · a + (1r · 0r + c) ≡ c\n helper = solve 𝓡\n ⋆CombTransMat t (suc (suc i)) zero =\n helper (M (suc i) zero · N zero zero) (∑ (λ l → M (suc i) (suc l) · N (suc l) zero)) t\n where helper : (a c : R) → a + (0r · 0r + c) ≡ a + c\n helper = solve 𝓡\n ⋆CombTransMat t (suc (suc i)) one =\n (helper (M (suc i) zero) _ ∙ ∑Mulr0 (λ j → M (suc i) (suc j))) t\n where helper : (a c : R) → a · 0r + (0r · 1r + c) ≡ c\n helper = solve 𝓡\n ⋆CombTransMat t (suc (suc i)) (suc (suc j)) =\n helper (M (suc i) zero · N zero (suc j)) (∑ (λ l → M (suc i) (suc l) · N (suc l) (suc j))) t\n where helper : (a c : R) → a + (0r · 0r + c) ≡ a + c\n helper = solve 𝓡\n\n module _\n (T₁ : Mat (suc m) (suc n) → Mat (suc m) (suc n))\n (isLinearT₁ : isLinear T₁) where\n\n module _\n (M : Mat (suc (suc m)) (suc n)) where\n\n private\n P = isLinearT₁ .transMat (takeRowsᶜ M)\n\n combTransEquiv : combTrans T₁ M ≡ combTransMat P ⋆ M\n combTransEquiv t zero j =\n ((λ t → isLinearT₁ .transEq (takeRowsᶜ M) t zero j)\n ∙ helper _ (M one j) _) t\n where helper : (a b c : R) → a + c ≡ a + (0r · b + c)\n helper = solve 𝓡\n combTransEquiv t one j =\n (helper _ _\n ∙ (λ t → 0r · M zero j + (1r · M one j\n + ∑Mul0r (λ i → M (suc (suc i)) j) (~ t)))) t\n where helper : (a b : R) → b ≡ 0r · a + (1r · b + 0r)\n helper = solve 𝓡\n combTransEquiv t (suc (suc i)) j =\n ((λ t → isLinearT₁ .transEq (takeRowsᶜ M) t (suc i) j)\n ∙ helper _ (M one j) _) t\n where helper : (a b c : R) → a + c ≡ a + (0r · b + c)\n helper = solve 𝓡\n\n isLinearCombRowsTrans : isLinear (combTrans T₁)\n isLinearCombRowsTrans .transMat M = combTransMat _\n isLinearCombRowsTrans .transEq = combTransEquiv\n\n isInvCombTransMat : (M : Mat (suc m) (suc m))(isInvM : isInv M) → isInv (combTransMat M)\n isInvCombTransMat M isInvM .fst = combTransMat (isInvM .fst)\n isInvCombTransMat M isInvM .snd .fst =\n ⋆CombTransMat _ _ ∙ (λ t → combTransMat (isInvM .snd .fst t)) ∙ combTransMat𝟙\n isInvCombTransMat M isInvM .snd .snd =\n ⋆CombTransMat _ _ ∙ (λ t → combTransMat (isInvM .snd .snd t)) ∙ combTransMat𝟙\n\n module _\n {T₁ : Mat 2 (suc n) → Mat 2 (suc n)}\n {T₂ : Mat (suc m) (suc n) → Mat (suc m) (suc n)}\n (isLinearT₁ : isLinear2×2 T₁)\n (isLinearT₂ : isLinear T₂) where\n\n private\n compL = isLinearComp (isLinearTakeRowsTrans _ isLinearT₁) (isLinearCombRowsTrans _ isLinearT₂)\n\n isLinearTakeCombShufRows : isLinear (takeCombShufRows {m = m} T₁ T₂)\n isLinearTakeCombShufRows .transMat = compL .transMat\n isLinearTakeCombShufRows .transEq M = sym (takeCombShufEquiv _ _ _) ∙ compL .transEq _\n\n module _\n (T : Mat 2 (suc n) → Mat 2 (suc n))\n (isLinear2×2T : isLinear2×2 T) where\n\n isLinearTransRows : (m : ℕ) → isLinear (transRows T {m = m})\n isLinearTransRows 0 = isLinearId\n isLinearTransRows (suc m) = isLinearTakeCombShufRows isLinear2×2T (isLinearTransRows m)\n\n module _\n (isInvT : (M : Mat 2 (suc n)) → isInv (isLinear2×2T .transMat M)) where\n\n isInvTransRows : (M : Mat (suc m) (suc n)) → isInv (isLinearTransRows _ .transMat M)\n isInvTransRows {m = 0} _ = isInv𝟙\n isInvTransRows {m = suc m} M =\n isInv⋆ {M = combTransMat _} {M' = takeTransMat _}\n (isInvCombTransMat _ (isInvTransRows _))\n (isInvTakeTransMat _ (isInvT _))\n\n module _\n (P : FinVec R (suc n) → Type ℓ)\n (indP : (M : Mat 2 (suc n)) → P (M zero) → P (T M zero))\n (isInvT : (M : Mat 2 (suc n)) → P (M zero) → isInv (isLinear2×2T .transMat M)) where\n\n isInvTransRowsInd :\n (M : Mat (suc m) (suc n)) → P (M zero) → isInv (isLinearTransRows _ .transMat M)\n isInvTransRowsInd {m = 0} M _ = isInvId M\n isInvTransRowsInd {m = suc m} M p =\n isInv⋆ {M = combTransMat _} {M' = takeTransMat _}\n (isInvCombTransMat _ (isInvTransRowsInd _ (indP _ p)))\n (isInvTakeTransMat _ (isInvT _ p))\n\n -- Some useful properties of 2-rows transformation\n\n symδ : (i j : Fin m) → δ i j ≡ δ j i\n symδ zero zero = refl\n symδ zero (suc _) = refl\n symδ (suc _) zero = refl\n symδ (suc i) (suc j) = symδ i j\n\n diagδ : (i j : Fin m)(p : i ≡ j) → δ i j ≡ 1r\n diagδ zero zero _ = refl\n diagδ (suc _) zero p = Empty.rec (snotzFin p)\n diagδ zero (suc _) p = Empty.rec (znotsFin p)\n diagδ (suc i) (suc j) p = diagδ _ _ (injSucFin p)\n\n skewδ : (i j : Fin m)(p : ¬ i ≡ j) → δ i j ≡ 0r\n skewδ zero zero p = Empty.rec (p refl)\n skewδ (suc _) zero _ = refl\n skewδ zero (suc _) _ = refl\n skewδ (suc i) (suc j) p = skewδ _ _ (λ r → p (cong suc r))\n\n diagSet : (i₀ : Fin m)(a : R) → Mat m m\n diagSet {m = suc m} zero a zero zero = a\n diagSet {m = suc m} zero _ (suc i) zero = 0r\n diagSet {m = suc m} zero _ zero (suc j) = 0r\n diagSet {m = suc m} zero _ (suc i) (suc j) = δ i j\n diagSet {m = suc m} (suc i₀) _ zero zero = 1r\n diagSet {m = suc m} (suc i₀) _ (suc i) zero = 0r\n diagSet {m = suc m} (suc i₀) _ zero (suc j) = 0r\n diagSet {m = suc m} (suc i₀) a (suc i) (suc j) = diagSet i₀ a i j\n\n diagSet≡diagSetᵗ : (i₀ : Fin m)(a : R) → diagSet i₀ a ≡ (diagSet i₀ a)ᵗ\n diagSet≡diagSetᵗ {m = suc m} zero a t zero zero = a\n diagSet≡diagSetᵗ {m = suc m} zero _ t (suc i) zero = 0r\n diagSet≡diagSetᵗ {m = suc m} zero _ t zero (suc j) = 0r\n diagSet≡diagSetᵗ {m = suc m} zero _ t (suc i) (suc j) = symδ i j t\n diagSet≡diagSetᵗ {m = suc m} (suc i₀) _ t zero zero = 1r\n diagSet≡diagSetᵗ {m = suc m} (suc i₀) _ t (suc i) zero = 0r\n diagSet≡diagSetᵗ {m = suc m} (suc i₀) _ t zero (suc j) = 0r\n diagSet≡diagSetᵗ {m = suc m} (suc i₀) a t (suc i) (suc j) = diagSet≡diagSetᵗ i₀ a t i j\n\n diagSet1≡𝟙 : (i₀ : Fin m) → diagSet i₀ 1r ≡ 𝟙\n diagSet1≡𝟙 {m = suc m} zero t zero zero = 1r\n diagSet1≡𝟙 {m = suc m} zero t (suc i) zero = 0r\n diagSet1≡𝟙 {m = suc m} zero t zero (suc j) = 0r\n diagSet1≡𝟙 {m = suc m} zero t (suc i) (suc j) = δ i j\n diagSet1≡𝟙 {m = suc m} (suc i₀) t zero zero = 1r\n diagSet1≡𝟙 {m = suc m} (suc i₀) t (suc i) zero = 0r\n diagSet1≡𝟙 {m = suc m} (suc i₀) t zero (suc j) = 0r\n diagSet1≡𝟙 {m = suc m} (suc i₀) t (suc i) (suc j) = diagSet1≡𝟙 i₀ t i j\n\n module _\n (a b c : R) where\n\n ·DiagSetˡ : (i₀ : Fin m)(i : Fin m) → a · δ i₀ i + diagSet i₀ b i i₀ · c ≡ (a + (b · c + 0r)) · δ i₀ i\n ·DiagSetˡ {m = suc m} zero zero = helper _ _ _\n where helper : (a b c : R) → a · 1r + b · c ≡ (a + (b · c + 0r)) · 1r\n helper = solve 𝓡\n ·DiagSetˡ {m = suc m} (suc i₀) zero = helper _ _ _\n where helper : (a b c : R) → a · 0r + 0r · c ≡ (a + (b · c + 0r)) · 0r\n helper = solve 𝓡\n ·DiagSetˡ {m = suc m} zero (suc j) = helper _ _ _\n where helper : (a b c : R) → a · 0r + 0r · c ≡ (a + (b · c + 0r)) · 0r\n helper = solve 𝓡\n ·DiagSetˡ {m = suc m} (suc i₀) (suc j) = ·DiagSetˡ i₀ j\n\n ·DiagSetʳ : (i₀ : Fin m)(i : Fin m) → a · δ i₀ i + b · diagSet i₀ c i₀ i ≡ (a + (b · c + 0r)) · δ i₀ i\n ·DiagSetʳ {m = suc m} zero zero = helper _ _ _\n where helper : (a b c : R) → a · 1r + b · c ≡ (a + (b · c + 0r)) · 1r\n helper = solve 𝓡\n ·DiagSetʳ {m = suc m} (suc i₀) zero = helper _ _ _\n where helper : (a b c : R) → a · 0r + b · 0r ≡ (a + (b · c + 0r)) · 0r\n helper = solve 𝓡\n ·DiagSetʳ {m = suc m} zero (suc j) = helper _ _ _\n where helper : (a b c : R) → a · 0r + b · 0r ≡ (a + (b · c + 0r)) · 0r\n helper = solve 𝓡\n ·DiagSetʳ {m = suc m} (suc i₀) (suc j) = ·DiagSetʳ i₀ j\n\n module _\n (a b : R) where\n\n ⋆DiagSet : (i₀ : Fin m) → diagSet i₀ a ⋆ diagSet i₀ b ≡ diagSet i₀ (a · b)\n ⋆DiagSet {m = suc m} zero t zero zero =\n ((λ t → a · b + ∑Mul0r {n = m} (λ i → 0r) t) ∙ helper _) t\n where helper : (a : R) → a + 0r ≡ a\n helper = solve 𝓡\n ⋆DiagSet {m = suc m} zero t (suc i) zero =\n ((λ t → 0r · b + ∑Mulr0 (λ j → diagSet zero a (suc i) (suc j)) t) ∙ helper _) t\n where helper : (b : R) → 0r · b + 0r ≡ 0r\n helper = solve 𝓡\n ⋆DiagSet {m = suc m} zero t zero (suc j) =\n ((λ t → a · 0r + ∑Mul0r (λ i → diagSet zero b (suc i) (suc j)) t) ∙ helper _) t\n where helper : (a : R) → a · 0r + 0r ≡ 0r\n helper = solve 𝓡\n ⋆DiagSet {m = suc m} zero t (suc i) (suc j) =\n ((λ t → 0r · 0r + ∑Mulr1 _ (λ l → δ i l) j t) ∙ helper _) t\n where helper : (d : R) → 0r · 0r + d ≡ d\n helper = solve 𝓡\n ⋆DiagSet {m = suc m} (suc i₀) t zero zero =\n ((λ t → 1r · 1r + ∑Mul0r {n = m} (λ i → 0r) t) ∙ helper) t\n where helper : 1r · 1r + 0r ≡ 1r\n helper = solve 𝓡\n ⋆DiagSet {m = suc m} (suc i₀) t (suc i) zero =\n ((λ t → 0r · 1r + ∑Mulr0 (λ j → diagSet (suc i₀) a (suc i) (suc j)) t) ∙ helper) t\n where helper : 0r · 1r + 0r ≡ 0r\n helper = solve 𝓡\n ⋆DiagSet {m = suc m} (suc i₀) t zero (suc j) =\n ((λ t → 1r · 0r + ∑Mul0r (λ i → diagSet (suc i₀) b (suc i) (suc j)) t) ∙ helper) t\n where helper : 1r · 0r + 0r ≡ 0r\n helper = solve 𝓡\n ⋆DiagSet {m = suc m} (suc i₀) t (suc i) (suc j) =\n ((λ t → 0r · 0r + ⋆DiagSet i₀ t i j) ∙ helper _) t\n where helper : (a : R) → 0r · 0r + a ≡ a\n helper = solve 𝓡\n\n module _\n (a b c : R) where\n\n +DiagSet :\n (i₀ i j : Fin m)\n → (a · δ i₀ i) · (b · δ i₀ j) + diagSet i₀ c i j ≡ diagSet i₀ (a · b + (c + 0r)) i j\n +DiagSet {m = suc m} zero zero zero = helper _ _ _\n where helper : (a b c : R) → (a · 1r) · (b · 1r) + c ≡ a · b + (c + 0r)\n helper = solve 𝓡\n +DiagSet {m = suc m} zero (suc i) zero = helper _ _\n where helper : (a b : R) → (a · 0r) · (b · 1r) + 0r ≡ 0r\n helper = solve 𝓡\n +DiagSet {m = suc m} zero zero (suc j) = helper _ _\n where helper : (a b : R) → (a · 1r) · (b · 0r) + 0r ≡ 0r\n helper = solve 𝓡\n +DiagSet {m = suc m} zero (suc i) (suc j) = helper _ _ _\n where helper : (a b d : R) → (a · 0r) · (b · 0r) + d ≡ d\n helper = solve 𝓡\n +DiagSet {m = suc m} (suc i₀) zero zero = helper _ _\n where helper : (a b : R) → (a · 0r) · (b · 0r) + 1r ≡ 1r\n helper = solve 𝓡\n +DiagSet {m = suc m} (suc i₀) (suc i) zero = helper _ _\n where helper : (a b : R) → a · (b · 0r) + 0r ≡ 0r\n helper = solve 𝓡\n +DiagSet {m = suc m} (suc i₀) zero (suc j) = helper _ _\n where helper : (a b : R) → (a · 0r) · b + 0r ≡ 0r\n helper = solve 𝓡\n +DiagSet {m = suc m} (suc i₀) (suc i) (suc j) = +DiagSet i₀ i j\n\n module _\n (M : Mat 2 2)(i₀ : Fin m) where\n\n trans2RowsMat : Mat (suc m) (suc m)\n trans2RowsMat zero zero = M zero zero\n trans2RowsMat (suc i) zero = M one zero · δ i₀ i\n trans2RowsMat zero (suc j) = M zero one · δ i₀ j\n trans2RowsMat (suc i) (suc j) = diagSet i₀ (M one one) i j\n\n module _\n (i₀ : Fin m) where\n\n trans2RowsMat𝟙 : trans2RowsMat 𝟙 i₀ ≡ 𝟙\n trans2RowsMat𝟙 t zero zero = 1r\n trans2RowsMat𝟙 t (suc i) zero = 0LeftAnnihilates (δ i₀ i) t\n trans2RowsMat𝟙 t zero (suc j) = 0LeftAnnihilates (δ i₀ j) t\n trans2RowsMat𝟙 t (suc i) (suc j) = diagSet1≡𝟙 i₀ t i j\n\n module _\n (M N : Mat 2 2)(i₀ : Fin m) where\n\n private\n ∑helper00 : (x a b : R) → x + ∑(λ l → (a · δ i₀ l) · (b · δ i₀ l)) ≡ x + a · b\n ∑helper00 x a b =\n (λ t → x + ∑(λ l → helper a b (δ i₀ l) (δ i₀ l) t))\n ∙ (λ t → x + ∑Mul1r _ (λ l → (δ i₀ l · (a · b))) i₀ t)\n ∙ (λ t → x + diagδ i₀ i₀ refl t · (a · b))\n ∙ (λ t → x + ·Lid (a · b) t)\n where helper : (a b x y : R) → (a · x) · (b · y) ≡ x · (y · (a · b))\n helper = solve 𝓡\n\n ∑helper10 :\n (a b c : R)(K : Mat m m)(i : Fin m)\n → (a · δ i₀ i) · b + ∑ (λ l → K i l · (c · δ i₀ l)) ≡ (a · b) · δ i₀ i + K i i₀ · c\n ∑helper10 a b c K i =\n (λ t → helper1 a b (δ i₀ i) t + ∑ (λ l → helper2 (K i l) c (δ i₀ l) t))\n ∙ (λ t → (a · b) · δ i₀ i + ∑Mul1r _ (λ l → K i l · c) i₀ t)\n where helper1 : (a b c : R) → (a · c) · b ≡ (a · b) · c\n helper1 = solve 𝓡\n helper2 : (a b c : R) → a · (b · c) ≡ c · (a · b)\n helper2 = solve 𝓡\n\n ∑helper01 :\n (a b c : R)(K : Mat m m)(i : Fin m)\n → a · (b · δ i₀ i) + ∑ (λ l → (c · δ i₀ l) · K l i) ≡ (a · b) · δ i₀ i + c · K i₀ i\n ∑helper01 a b c K i =\n (λ t → helper1 a b (δ i₀ i) t + ∑ (λ l → helper2 c (K l i) (δ i₀ l) t))\n ∙ (λ t → (a · b) · δ i₀ i + ∑Mul1r _ (λ l → c · K l i) i₀ t)\n where helper1 : (a b c : R) → a · (b · c) ≡ (a · b) · c\n helper1 = solve 𝓡\n helper2 : (a b c : R) → (a · c) · b ≡ c · (a · b)\n helper2 = solve 𝓡\n\n ⋆Trans2RowsMat : trans2RowsMat M i₀ ⋆ trans2RowsMat N i₀ ≡ trans2RowsMat (M ⋆ N) i₀\n ⋆Trans2RowsMat t zero zero =\n (∑helper00 _ _ _ ∙ sym (mul2 M N zero zero)) t\n ⋆Trans2RowsMat t (suc i) zero =\n (∑helper10 (M one zero) (N zero zero)\n (N one zero) (diagSet i₀ (M one one)) i\n ∙ ·DiagSetˡ _ _ _ i₀ i) t\n ⋆Trans2RowsMat t zero (suc j) =\n (∑helper01 (M zero zero) (N zero one)\n (M zero one ) (diagSet i₀ (N one one)) j\n ∙ ·DiagSetʳ _ _ _ i₀ j) t\n ⋆Trans2RowsMat t (suc i) (suc j) =\n ((λ t → (M one zero · δ i₀ i) · (N zero one · δ i₀ j)\n + ⋆DiagSet (M one one) (N one one) i₀ t i j)\n ∙ +DiagSet _ _ _ i₀ i j) t\n\n isInvTrans2RowsMat : (M : Mat 2 2)(i₀ : Fin m)(isInvM : isInv M) → isInv (trans2RowsMat M i₀)\n isInvTrans2RowsMat M i₀ isInvM .fst = trans2RowsMat (isInvM .fst) i₀\n isInvTrans2RowsMat M i₀ isInvM .snd .fst =\n ⋆Trans2RowsMat _ _ _ ∙ (λ t → trans2RowsMat (isInvM .snd .fst t) i₀) ∙ trans2RowsMat𝟙 _\n isInvTrans2RowsMat M i₀ isInvM .snd .snd =\n ⋆Trans2RowsMat _ _ _ ∙ (λ t → trans2RowsMat (isInvM .snd .snd t) i₀) ∙ trans2RowsMat𝟙 _\n", "meta": {"hexsha": "669585295ceb26b8dbd2274d2b166249c19b5fd0", "size": 30981, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/Matrix/RowTransformation.agda", "max_stars_repo_name": "howsiyu/cubical", "max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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": "Cubical/Algebra/Matrix/RowTransformation.agda", "max_issues_repo_name": "howsiyu/cubical", "max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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": "Cubical/Algebra/Matrix/RowTransformation.agda", "max_forks_repo_name": "howsiyu/cubical", "max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "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.1308290155, "max_line_length": 116, "alphanum_fraction": 0.541751396, "num_tokens": 13228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6370307944803831, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.3775468750307285}} {"text": "open import Data.Empty\nopen import Data.List hiding ([_]) renaming (_∷_ to _∷ₗ_)\nopen import Data.Maybe\nopen import Data.Product\nopen import Data.Sum\nopen import Data.Unit\n\nopen import AEff\nopen import AwaitingComputations\nopen import EffectAnnotations\nopen import Preservation\nopen import Progress\nopen import Renamings\nopen import Substitutions\nopen import Types\n\nopen import Relation.Binary.PropositionalEquality hiding ([_])\nopen import Relation.Nullary\nopen import Relation.Nullary.Negation\n\nmodule Finality where\n\n\n-- SMALL-STEP OPERATIONAL SEMANTICS FOR WELL-TYPED COMPUTATIONS\n-- WITH INLINED EVALUATION CONTEXT RULES\n\nmutual\n\n infix 10 _↝↝_\n\n data _↝↝_ {Γ : Ctx} : {C : CType} → Γ ⊢M⦂ C → Γ ⊢M⦂ C → Set where\n\n -- COMPUTATIONAL RULES\n\n apply : {X : VType}\n {C : CType} →\n (M : Γ ∷ X ⊢M⦂ C) →\n (V : Γ ⊢V⦂ X) →\n ----------------------\n (ƛ M) · V\n ↝↝\n M [ id-subst [ V ]s ]m\n\n let-return : {X Y : VType}\n {o : O}\n {i : I} → \n (V : Γ ⊢V⦂ X) →\n (N : Γ ∷ X ⊢M⦂ Y ! (o , i)) →\n -----------------------------\n let= (return V) `in N\n ↝↝\n N [ id-subst [ V ]s ]m\n\n let-↑ : {X Y : VType}\n {o : O}\n {i : I}\n {op : Σₛ} →\n (p : op ∈ₒ o) →\n (V : Γ ⊢V⦂ ``(payload op)) →\n (M : Γ ⊢M⦂ X ! (o , i)) →\n (N : Γ ∷ X ⊢M⦂ Y ! (o , i)) →\n -----------------------------\n let= (↑ op p V M) `in N\n ↝↝\n ↑ op p V (let= M `in N)\n\n let-promise : {X Y Z : VType}\n {o o' : O}\n {i i' : I}\n {op : Σₛ} →\n (p : lkpᵢ op i ≡ just (o' , i')) →\n (M₁ : Γ ∷ ``(payload op) ⊢M⦂ ⟨ X ⟩ ! (o' , i')) →\n (M₂ : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)) →\n (N : Γ ∷ Y ⊢M⦂ Z ! (o , i)) →\n ---------------------------------------------------------------------------\n let= (promise op ∣ p ↦ M₁ `in M₂) `in N\n ↝↝\n (promise op ∣ p ↦ M₁ `in (let= M₂ `in (M-rename (comp-ren exchange wk₁) N)))\n\n letrec-unfold : {X : VType}\n {C D : CType}\n (M : Γ ∷ (X ⇒ C) ∷ X ⊢M⦂ C) →\n (N : Γ ∷ (X ⇒ C) ⊢M⦂ D) →\n ----------------------------------------\n (letrec M `in N)\n ↝↝\n N [ id-subst [ ƛ (letrec M-rename wk₃ M `in M-rename exchange M) ]s ]m\n\n promise-↑ : {X Y : VType}\n {o o' : O}\n {i i' : I}\n {op op' : Σₛ} →\n (p : lkpᵢ op i ≡ just (o' , i')) →\n (q : op' ∈ₒ o) →\n (V : Γ ∷ ⟨ X ⟩ ⊢V⦂ ``(payload op')) → \n (M : Γ ∷ ``(payload op) ⊢M⦂ ⟨ X ⟩ ! (o' , i')) →\n (N : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)) →\n --------------------------------------------\n (promise op ∣ p ↦ M `in (↑ op' q V N))\n ↝↝\n ↑ op' q (strengthen-val {Δ = X ∷ₗ []} V) (promise op ∣ p ↦ M `in N)\n\n ↓-return : {X : VType}\n {o : O}\n {i : I}\n {op : Σₛ} →\n (V : Γ ⊢V⦂ ``(payload op)) →\n (W : Γ ⊢V⦂ X) →\n ----------------------------------------------------------------\n ↓ {o = o} {i = i} op V (return W)\n ↝↝\n return {o = proj₁ (op ↓ₑ (o , i))} {i = proj₂ (op ↓ₑ (o , i))} W\n\n ↓-↑ : {X : VType}\n {o : O}\n {i : I}\n {op : Σₛ}\n {op' : Σₛ} →\n (p : op' ∈ₒ o) →\n (V : Γ ⊢V⦂ ``(payload op)) →\n (W : Γ ⊢V⦂ ``(payload op')) →\n (M : Γ ⊢M⦂ X ! (o , i)) →\n -------------------------------\n ↓ op V (↑ op' p W M)\n ↝↝\n ↑ op' (↓ₑ-⊑ₒ op' p) W (↓ op V M)\n\n\n ↓-promise-op : {X Y : VType}\n {o o' : O}\n {i i' : I}\n {op : Σₛ} →\n (p : lkpᵢ op i ≡ just (o' , i')) →\n (V : Γ ⊢V⦂ ``(payload op)) → \n (M : Γ ∷ ``(payload op) ⊢M⦂ ⟨ X ⟩ ! (o' , i')) →\n (N : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)) →\n ---------------------------------------------------------------------------------------\n ↓ op V (promise op ∣ p ↦ M `in N )\n ↝↝\n (let= (coerce (↓ₑ-⊑ₒ-o' {o} p) (↓ₑ-⊑ₒ-i' {o} p) (M [ id-subst [ V ]s ]m)) `in\n ↓ op (V-rename wk₁ V) ((M-rename (comp-ren exchange wk₁) N) [ id-subst [ ` Hd ]s ]m))\n\n ↓-promise-op' : {X Y : VType}\n {o o' : O}\n {i i' : I}\n {op op' : Σₛ} →\n (p : ¬ op ≡ op') →\n (q : lkpᵢ op' i ≡ just (o' , i')) →\n (V : Γ ⊢V⦂ ``(payload op)) → \n (M : Γ ∷ ``(payload op') ⊢M⦂ ⟨ X ⟩ ! (o' , i')) →\n (N : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)) →\n ------------------------------------------------------------------------------------------\n ↓ op V (promise op' ∣ q ↦ M `in N )\n ↝↝\n promise_∣_↦_`in_ {o' = proj₁ (lkpᵢ-↓ₑ-neq {o = o} {i = i} p q)}\n {i' = proj₁ (proj₂ (lkpᵢ-↓ₑ-neq {o = o} {i = i} p q))}\n op'\n (proj₁ (proj₂ (proj₂ (lkpᵢ-↓ₑ-neq {o = o} {i = i} p q))))\n (coerce (proj₁ (proj₂ (proj₂ (proj₂ (lkpᵢ-↓ₑ-neq {o = o} {i = i} p q)))))\n (proj₂ (proj₂ (proj₂ (proj₂ (lkpᵢ-↓ₑ-neq {o = o} {i = i} p q)))))\n M)\n (↓ op (V-rename wk₁ V) N)\n\n await-promise : {X : VType}\n {C : CType} → \n (V : Γ ⊢V⦂ X) → \n (M : Γ ∷ X ⊢M⦂ C) →\n --------------------\n await ⟨ V ⟩ until M\n ↝↝\n M [ id-subst [ V ]s ]m\n\n -- INLINED EVALUATION CONTEXT RULES\n\n context-let : {X Y : VType}\n {o : O}\n {i : I} → \n {M M' : Γ ⊢M⦂ X ! (o , i)} →\n {N : Γ ∷ X ⊢M⦂ Y ! (o , i)} →\n M ↝↝ M' → \n -----------------------------\n let= M `in N\n ↝↝\n let= M' `in N\n\n context-↑ : {X : VType}\n {o : O}\n {i : I}\n {op : Σₛ}\n {p : op ∈ₒ o}\n {V : Γ ⊢V⦂ ``(payload op)}\n {M N : Γ ⊢M⦂ X ! (o , i)} →\n M ↝↝ N →\n ---------------------------\n ↑ op p V M\n ↝↝\n ↑ op p V N\n\n context-↓ : {X : VType}\n {o : O}\n {i : I}\n {op : Σₛ}\n {V : Γ ⊢V⦂ ``(payload op)}\n {M N : Γ ⊢M⦂ X ! (o , i)} →\n M ↝↝ N →\n ---------------------------\n ↓ op V M\n ↝↝\n ↓ op V N\n\n context-promise : {X Y : VType}\n {o o' : O}\n {i i' : I}\n {op : Σₛ} →\n {r : lkpᵢ op i ≡ just (o' , i')}\n {M : Γ ∷ ``(payload op) ⊢M⦂ ⟨ X ⟩ ! (o' , i')} →\n {N N' : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)} →\n N ↝↝ N' →\n ------------------------------------------------\n promise op ∣ r ↦ M `in N\n ↝↝\n promise op ∣ r ↦ M `in N'\n\n context-coerce : {X : VType}\n {o o' : O}\n {i i' : I}\n {p : o ⊑ₒ o'}\n {q : i ⊑ᵢ i'} → \n {M N : Γ ⊢M⦂ X ! (o , i)} →\n M ↝↝ N →\n ---------------------------\n coerce p q M\n ↝↝\n coerce p q N\n\n -- COERCION RULES\n\n coerce-return : {X : VType}\n {o o' : O}\n {i i' : I}\n {p : o ⊑ₒ o'}\n {q : i ⊑ᵢ i'} → \n (V : Γ ⊢V⦂ X) →\n --------------------------------\n coerce p q (return V) ↝↝ return V\n\n coerce-↑ : {X : VType}\n {o o' : O}\n {i i' : I}\n {p : o ⊑ₒ o'}\n {q : i ⊑ᵢ i'}\n {op : Σₛ} → \n (r : op ∈ₒ o) →\n (V : Γ ⊢V⦂ ``(payload op)) →\n (M : Γ ⊢M⦂ X ! (o , i)) →\n -------------------------------\n coerce p q (↑ op r V M)\n ↝↝\n ↑ op (p op r) V (coerce p q M)\n\n coerce-promise : {X Y : VType}\n {o o' o'' : O}\n {i i' i'' : I}\n {p : o ⊑ₒ o'}\n {q : i ⊑ᵢ i'}\n {op : Σₛ} →\n (r : lkpᵢ op i ≡ just (o'' , i''))\n (M : Γ ∷ ``(payload op) ⊢M⦂ ⟨ X ⟩ ! (o'' , i'')) →\n (N : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)) →\n ------------------------------------------------------------------\n coerce p q (promise op ∣ r ↦ M `in N)\n ↝↝\n promise_∣_↦_`in_ {o' = lkpᵢ-nextₒ q r}\n {i' = lkpᵢ-nextᵢ q r}\n op\n (lkpᵢ-next-eq q r)\n (coerce (lkpᵢ-next-⊑ₒ q r) (lkpᵢ-next-⊑ᵢ q r) M)\n (coerce p q N)\n\n\n-- ONE-TO-ONE CORRESPONDENCE BETWEEN THE TWO SETS OF REDUCTION RULES\n\n↝↝-to-↝ : {Γ : Ctx}\n {C : CType}\n {M N : Γ ⊢M⦂ C} → \n M ↝↝ N →\n -----------------\n M ↝ N\n\n↝↝-to-↝ (apply M V) =\n apply M V\n↝↝-to-↝ (let-return V N) =\n let-return V N\n↝↝-to-↝ (let-↑ p V M N) =\n let-↑ p V M N\n↝↝-to-↝ (let-promise p M₁ M₂ N) =\n let-promise p M₁ M₂ N\n↝↝-to-↝ (letrec-unfold M N) =\n letrec-unfold M N\n↝↝-to-↝ (promise-↑ p q V M N) =\n promise-↑ p q V M N\n↝↝-to-↝ (↓-return V W) =\n ↓-return V W\n↝↝-to-↝ (↓-↑ p V W M) =\n ↓-↑ p V W M\n↝↝-to-↝ (↓-promise-op p V M N) =\n ↓-promise-op p V M N\n↝↝-to-↝ (↓-promise-op' p q V M N) =\n ↓-promise-op' p q V M N\n↝↝-to-↝ (await-promise V M) =\n await-promise V M\n↝↝-to-↝ (context-let r) =\n context _ (↝↝-to-↝ r)\n↝↝-to-↝ (context-↑ r) =\n context _ (↝↝-to-↝ r)\n↝↝-to-↝ (context-↓ r) =\n context _ (↝↝-to-↝ r)\n↝↝-to-↝ (context-promise r) =\n context _ (↝↝-to-↝ r)\n↝↝-to-↝ (context-coerce r) =\n context _ (↝↝-to-↝ r)\n↝↝-to-↝ (coerce-return V) =\n coerce-return V\n↝↝-to-↝ (coerce-↑ p V M) =\n coerce-↑ p V M\n↝↝-to-↝ (coerce-promise p M N) =\n coerce-promise p M N\n\n\nmutual\n ↝-context-to-↝↝ : {Γ : Ctx}\n {Δ : BCtx}\n {C : CType} → \n (E : Γ ⊢E[ Δ ]⦂ C) → \n {M N : (Γ ⋈ Δ) ⊢M⦂ hole-ty-e E} → \n M ↝ N →\n ---------------------------\n E [ M ] ↝↝ E [ N ]\n\n ↝-context-to-↝↝ [-] r =\n ↝-to-↝↝ r\n ↝-context-to-↝↝ (let= E `in x) r =\n context-let (↝-context-to-↝↝ E r)\n ↝-context-to-↝↝ (↑ op p V E) r =\n context-↑ (↝-context-to-↝↝ E r)\n ↝-context-to-↝↝ (↓ op V E) r =\n context-↓ (↝-context-to-↝↝ E r)\n ↝-context-to-↝↝ (promise op ∣ p ↦ M `in E) r =\n context-promise (↝-context-to-↝↝ E r)\n ↝-context-to-↝↝ (coerce p q E) r =\n context-coerce (↝-context-to-↝↝ E r)\n \n \n ↝-to-↝↝ : {Γ : Ctx}\n {C : CType}\n {M N : Γ ⊢M⦂ C} → \n M ↝ N →\n -----------------\n M ↝↝ N\n\n ↝-to-↝↝ (apply M V) =\n apply M V\n ↝-to-↝↝ (let-return V N) =\n let-return V N\n ↝-to-↝↝ (let-↑ p V M N) =\n let-↑ p V M N\n ↝-to-↝↝ (let-promise p M₁ M₂ N) =\n let-promise p M₁ M₂ N\n ↝-to-↝↝ (letrec-unfold M N) =\n letrec-unfold M N\n ↝-to-↝↝ (promise-↑ p q V M N) =\n promise-↑ p q V M N\n ↝-to-↝↝ (↓-return V W) =\n ↓-return V W\n ↝-to-↝↝ (↓-↑ p V W M) =\n ↓-↑ p V W M\n ↝-to-↝↝ (↓-promise-op p V M N) =\n ↓-promise-op p V M N\n ↝-to-↝↝ (↓-promise-op' p q V M N) =\n ↓-promise-op' p q V M N\n ↝-to-↝↝ (await-promise V M) =\n await-promise V M\n ↝-to-↝↝ (context E r) =\n ↝-context-to-↝↝ E r\n ↝-to-↝↝ (coerce-return V) =\n coerce-return V\n ↝-to-↝↝ (coerce-↑ p V M) =\n coerce-↑ p V M\n ↝-to-↝↝ (coerce-promise p M N) =\n coerce-promise p M N\n\n\n-- FINALITY OF RESULT FORMS\n\nrun-invert-let : {Γ : Ctx}\n {X Y : VType}\n {o : O}\n {i : I}\n {M : ⟨⟨ Γ ⟩⟩ ⊢M⦂ X ! (o , i)}\n {N : (⟨⟨ Γ ⟩⟩ ∷ X) ⊢M⦂ Y ! (o , i)} →\n RunResult⟨ Γ ∣ let= M `in N ⟩ →\n -------------------------------------\n RunResult⟨ Γ ∣ M ⟩\n\nrun-invert-let (awaiting (let-in R)) =\n awaiting R\n\n\nrun-invert-↓ : {Γ : Ctx}\n {X : VType}\n {o : O}\n {i : I}\n {op : Σₛ}\n {V : ⟨⟨ Γ ⟩⟩ ⊢V⦂ ``(payload op)}\n {M : ⟨⟨ Γ ⟩⟩ ⊢M⦂ X ! (o , i)} →\n RunResult⟨ Γ ∣ ↓ op V M ⟩ → \n -------------------------------\n RunResult⟨ Γ ∣ M ⟩\n\nrun-invert-↓ (awaiting (interrupt await)) =\n awaiting await\nrun-invert-↓ (awaiting (interrupt (let-in R))) =\n awaiting (let-in R)\nrun-invert-↓ (awaiting (interrupt (interrupt R))) =\n awaiting (interrupt R)\nrun-invert-↓ (awaiting (interrupt (coerce R))) =\n awaiting (coerce R)\n\n\nrun-invert-promise : {Γ : Ctx}\n {X Y : VType}\n {o o' : O}\n {i i' : I}\n {op : Σₛ}\n {p : lkpᵢ op i ≡ just (o' , i')}\n {M : (⟨⟨ Γ ⟩⟩ ∷ `` (payload op)) ⊢M⦂ (⟨ X ⟩ ! (o' , i'))}\n {N : (⟨⟨ Γ ⟩⟩ ∷ ⟨ X ⟩) ⊢M⦂ (Y ! (o , i))} → \n RunResult⟨ Γ ∣ (promise op ∣ p ↦ M `in N) ⟩ →\n --------------------------------------------------------\n RunResult⟨ Γ ∷ X ∣ N ⟩\n\nrun-invert-promise (promise R) =\n R\n\n\nrun-invert-coerce : {Γ : Ctx}\n {X : VType}\n {o o' : O}\n {i i' : I}\n {p : o ⊑ₒ o'}\n {q : i ⊑ᵢ i'}\n {M : ⟨⟨ Γ ⟩⟩ ⊢M⦂ X ! (o , i)} →\n RunResult⟨ Γ ∣ coerce p q M ⟩ →\n -------------------------------\n RunResult⟨ Γ ∣ M ⟩\n\nrun-invert-coerce (awaiting (coerce R)) =\n awaiting R\n\n\nrun-apply-⊥ : {Γ : Ctx}\n {X : VType}\n {C : CType}\n {M : (⟨⟨ Γ ⟩⟩ ∷ X) ⊢M⦂ C}\n {V : ⟨⟨ Γ ⟩⟩ ⊢V⦂ X} →\n RunResult⟨ Γ ∣ ƛ M · V ⟩ →\n --------------------------\n ⊥\n\nrun-apply-⊥ (awaiting ())\n\n\nrun-↑-⊥ : {Γ : Ctx}\n {X : VType}\n {o : O}\n {i : I}\n {op : Σₛ}\n {p : op ∈ₒ o}\n {V : ⟨⟨ Γ ⟩⟩ ⊢V⦂ ``(payload op)}\n {M : ⟨⟨ Γ ⟩⟩ ⊢M⦂ (X ! (o , i))} → \n RunResult⟨ Γ ∣ ↑ op p V M ⟩ →\n --------------------------------\n ⊥\n \nrun-↑-⊥ (awaiting ())\n\n\nrun-let-return-⊥ : {Γ : Ctx}\n {X Y : VType}\n {o : O}\n {i : I}\n {V : ⟨⟨ Γ ⟩⟩ ⊢V⦂ X}\n {N : (⟨⟨ Γ ⟩⟩ ∷ X) ⊢M⦂ (Y ! (o , i))} →\n RunResult⟨ Γ ∣ let= return V `in N ⟩ →\n --------------------------------------\n ⊥\n\nrun-let-return-⊥ (awaiting (let-in ()))\n\n\nrun-let-promise-⊥ : {Γ : Ctx}\n {X Y Z : VType}\n {o o' : O}\n {i i' : I}\n {op : Σₛ}\n {p : lkpᵢ op i ≡ just (o' , i')}\n {M₁ : (⟨⟨ Γ ⟩⟩ ∷ `` (payload op)) ⊢M⦂ (⟨ X ⟩ ! (o' , i'))}\n {M₂ : (⟨⟨ Γ ⟩⟩ ∷ ⟨ X ⟩) ⊢M⦂ (Y ! (o , i))}\n {N : (⟨⟨ Γ ⟩⟩ ∷ Y) ⊢M⦂ (Z ! (o , i))} →\n RunResult⟨ Γ ∣ let= promise op ∣ p ↦ M₁ `in M₂ `in N ⟩ →\n ----------------------------------------------------------\n ⊥\n\nrun-let-promise-⊥ (awaiting (let-in ()))\n\nrun-finality-↝↝ : {Γ : Ctx}\n {C : CType}\n {M N : ⟨⟨ Γ ⟩⟩ ⊢M⦂ C} → \n RunResult⟨ Γ ∣ M ⟩ →\n M ↝↝ N →\n -----------------------\n ⊥\n\nrun-finality-↝↝ (awaiting ()) (apply M V)\nrun-finality-↝↝ R (let-return V N) =\n run-let-return-⊥ R\nrun-finality-↝↝ R (let-↑ p V M N) =\n run-↑-⊥ (run-invert-let R)\nrun-finality-↝↝ R (let-promise p M₁ M₂ N) =\n run-let-promise-⊥ R\nrun-finality-↝↝ (awaiting ()) (letrec-unfold M N)\nrun-finality-↝↝ (promise (awaiting ())) (promise-↑ p q V M N)\nrun-finality-↝↝ (awaiting (interrupt ())) (↓-return V W)\nrun-finality-↝↝ (awaiting (interrupt ())) (↓-↑ p V W M)\nrun-finality-↝↝ (awaiting (interrupt ())) (↓-promise-op p V M N)\nrun-finality-↝↝ (awaiting (interrupt ())) (↓-promise-op' p q V M N)\nrun-finality-↝↝ (awaiting ()) (await-promise V M)\nrun-finality-↝↝ R (context-let r) =\n run-finality-↝↝ (run-invert-let R) r\nrun-finality-↝↝ R (context-↑ r) =\n run-↑-⊥ R\nrun-finality-↝↝ R (context-↓ r) =\n run-finality-↝↝ (run-invert-↓ R) r\nrun-finality-↝↝ R (context-promise r) =\n run-finality-↝↝ (run-invert-promise R) r\nrun-finality-↝↝ R (context-coerce r) =\n run-finality-↝↝ (run-invert-coerce R) r\nrun-finality-↝↝ (awaiting (coerce ())) (coerce-return V)\nrun-finality-↝↝ (awaiting (coerce ())) (coerce-↑ p V M)\nrun-finality-↝↝ (awaiting (coerce ())) (coerce-promise p M N)\n\n\ncomp-finality-↝↝ : {Γ : Ctx}\n {C : CType}\n {M N : ⟨⟨ Γ ⟩⟩ ⊢M⦂ C} → \n CompResult⟨ Γ ∣ M ⟩ →\n M ↝↝ N →\n -----------------------\n ⊥\n\ncomp-finality-↝↝ (comp R) r =\n run-finality-↝↝ R r\ncomp-finality-↝↝ (signal R) (context-↑ r) =\n comp-finality-↝↝ R r\n\n\n{- LEMMA 3.2 -}\n\ncomp-finality : {Γ : Ctx}\n {C : CType}\n {M N : ⟨⟨ Γ ⟩⟩ ⊢M⦂ C} → \n CompResult⟨ Γ ∣ M ⟩ →\n M ↝ N →\n -----------------------\n ⊥\n\ncomp-finality R r =\n comp-finality-↝↝ R (↝-to-↝↝ r)\n", "meta": {"hexsha": "950fce3548bb5463430415ae592a4de3c5f63657", "size": 19626, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Finality.agda", "max_stars_repo_name": "danelahman/aeff-agda", "max_stars_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-17T00:15:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-22T22:48:48.000Z", "max_issues_repo_path": "Finality.agda", "max_issues_repo_name": "danelahman/aeff-agda", "max_issues_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1", "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": "Finality.agda", "max_forks_repo_name": "danelahman/aeff-agda", "max_forks_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1", "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": 33.896373057, "max_line_length": 112, "alphanum_fraction": 0.2851319678, "num_tokens": 6676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3773895319261679}} {"text": "{-# OPTIONS --rewriting --prop #-}\n\nopen import common\nopen import syntx\nopen import derivability\n\n{- Here are the structural rules, as derivation rules -}\n\nmodule _ (Σ : Signature) where\n\n{-\n\nΓ ⊢ A (x : A) ∈ Γ\n--------------------\n Γ ⊢ x : A\n\n-}\n\n-- The version of the variable rule we use is that Γ ⊢ x : A if Γ ⊢ A holds, and if A is the type\n-- corresponding to x in Γ.\nVarRule : (k : ℕ) → DerivationRule Σ (([] , (0 , Ty)) , Tm)\nrule (VarRule k) ↑ Γ ([] , ◇ ⊢ A) =\n do\n (k' , A') ← get k Γ\n assume (A' ≡ A)\n return (◇ ⊢ var k' :> A)\n\nConvRule : DerivationRule Σ (([] , (0 , Tm) , (0 , Ty=)) , Tm)\nrule ConvRule ↑ Γ ([] , ◇ ⊢ u :> A , ◇ ⊢ A' == B) =\n do\n assume (A ≡ A')\n return (◇ ⊢ u :> B)\n\nConvEqRule : DerivationRule Σ (([] , (0 , Tm=) , (0 , Ty=)) , Tm=)\nrule ConvEqRule ↑ Γ ([] , ◇ ⊢ u == v :> A , ◇ ⊢ A' == B) =\n do\n assume (A ≡ A')\n return (◇ ⊢ u == v :> B)\n\nTyReflRule : DerivationRule Σ (([] , (0 , Ty)) , Ty=)\nrule TyReflRule ↑ Γ ([] , ◇ ⊢ A) = return (◇ ⊢ A == A)\n\nTySymmRule : DerivationRule Σ (([] , (0 , Ty=)) , Ty=)\nrule TySymmRule ↑ Γ ([] , ◇ ⊢ A == B) = return (◇ ⊢ B == A)\n\nTyTranRule : DerivationRule Σ (([] , (0 , Ty=) , (0 , Ty=)) , Ty=)\nrule TyTranRule ↑ Γ ([] , ◇ ⊢ A == B , ◇ ⊢ B' == D) = -- Can’t use C as a bound variable as it’s a tag.\n do\n assume (B ≡ B')\n return (◇ ⊢ A == D)\n\n\nTmReflRule : DerivationRule Σ (([] , (0 , Tm)) , Tm=)\nrule TmReflRule ↑ Γ ([] , ◇ ⊢ u :> A) = return (◇ ⊢ u == u :> A)\n\nTmSymmRule : DerivationRule Σ (([] , (0 , Tm=)) , Tm=)\nrule TmSymmRule ↑ Γ ([] , ◇ ⊢ u == v :> A) = return (◇ ⊢ v == u :> A)\n\nTmTranRule : DerivationRule Σ (([] , (0 , Tm=) , (0 , Tm=)) , Tm=)\nrule TmTranRule ↑ Γ ([] , ◇ ⊢ u == v :> A , ◇ ⊢ v' == w :> A') =\n do\n assume (v ≡ v')\n assume (A ≡ A')\n return (◇ ⊢ u == w :> A)\n\n{-\nSmall hack to make our life easier, the implicit argument [ar] of [StructuralRulesType] is\nautomatically inferred from the definition of [StructuralRules], but for that they need to be\nmutually recursive\n-}\n\nStructuralRules : DerivabilityStructure Σ\n\n-- See #4366\nprivate\n ar1 = _\n ar2 = _\n ar3 = _\n ar4 = _\n ar5 = _\n ar6 = _\n ar7 = _\n ar8 = _\n ar9 = _\n\ndata StructuralRulesType : {ar : JudgmentArity} → Set where\n var : ℕ → StructuralRulesType {ar1}\n conv : StructuralRulesType {ar2}\n convEq : StructuralRulesType {ar3}\n tyRefl : StructuralRulesType {ar4}\n tySymm : StructuralRulesType {ar5}\n tyTran : StructuralRulesType {ar6}\n tmRefl : StructuralRulesType {ar7}\n tmSymm : StructuralRulesType {ar8}\n tmTran : StructuralRulesType {ar9}\n\nRules StructuralRules S ar = StructuralRulesType {ar}\nRules StructuralRules T ar = Empty\nRules StructuralRules C ar = Empty\nRules StructuralRules Eq ar = Empty\nderivationRule StructuralRules {t = S} (var k) = VarRule k\nderivationRule StructuralRules {t = S} conv = ConvRule\nderivationRule StructuralRules {t = S} convEq = ConvEqRule\nderivationRule StructuralRules {t = S} tyRefl = TyReflRule\nderivationRule StructuralRules {t = S} tySymm = TySymmRule\nderivationRule StructuralRules {t = S} tyTran = TyTranRule\nderivationRule StructuralRules {t = S} tmRefl = TmReflRule\nderivationRule StructuralRules {t = S} tmSymm = TmSymmRule\nderivationRule StructuralRules {t = S} tmTran = TmTranRule\n", "meta": {"hexsha": "b534ddc65c21f95132d04af9ce50ad68e4a97a82", "size": 3248, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "structuralrules.agda", "max_stars_repo_name": "guillaumebrunerie/general-type-theories", "max_stars_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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": "structuralrules.agda", "max_issues_repo_name": "guillaumebrunerie/general-type-theories", "max_issues_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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": "structuralrules.agda", "max_forks_repo_name": "guillaumebrunerie/general-type-theories", "max_forks_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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": 29.5272727273, "max_line_length": 104, "alphanum_fraction": 0.5957512315, "num_tokens": 1207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6757645879592642, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.37729761127357875}} {"text": "{-# OPTIONS --prop --rewriting #-}\n\nopen import Calf.CostMonoid\nopen import Data.Nat using (ℕ)\nopen import Examples.Sorting.Comparable\n\nmodule Examples.Sorting.Core\n (costMonoid : CostMonoid) (fromℕ : ℕ → CostMonoid.ℂ costMonoid)\n (M : Comparable costMonoid fromℕ)\n where\n\nopen Comparable M\n\nopen import Calf costMonoid\nopen import Calf.Types.List\n\nopen import Relation.Nullary\nopen import Relation.Nullary.Negation\nopen import Relation.Binary\nopen import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; module ≡-Reasoning)\nopen import Data.Product using (_×_; _,_; ∃; proj₁; proj₂)\nopen import Data.Sum using (inj₁; inj₂)\nopen import Data.Nat as Nat using (ℕ; zero; suc; z≤n; s≤s; _+_; _*_; _^_; ⌊_/2⌋; ⌈_/2⌉)\nimport Data.Nat.Properties as N\n\nopen import Data.List.Properties using (++-assoc; length-++) public\n\nopen import Data.List.Relation.Binary.Permutation.Propositional public\nopen import Data.List.Relation.Binary.Permutation.Propositional.Properties\n using (↭-length; ¬x∷xs↭[]; All-resp-↭; Any-resp-↭; drop-∷; ++-identityʳ)\n renaming (++-comm to ++-comm-↭; ++⁺ˡ to ++⁺ˡ-↭; ++⁺ʳ to ++⁺ʳ-↭; ++⁺ to ++⁺-↭) public\n\nopen import Data.List.Relation.Unary.All using (All; []; _∷_; map; lookup) public\nopen import Data.List.Relation.Unary.All.Properties as AllP using () renaming (++⁺ to ++⁺-All) public\nopen import Data.List.Relation.Unary.Any using (Any; here; there)\n\n_≥_ : val A → val A → Set\nx ≥ y = y ≤ x\n\n_≰_ : val A → val A → Set\nx ≰ y = ¬ x ≤ y\n\n≰⇒≥ : _≰_ ⇒ _≥_\n≰⇒≥ {x} {y} h with ≤-total x y\n... | inj₁ h₁ = contradiction h₁ h\n... | inj₂ h₂ = h₂\n\n\n_≤*_ : val A → val (list A) → Set\n_≤*_ x = All (x ≤_)\n\n≤-≤* : ∀ {x₁ x₂ l} → x₁ ≤ x₂ → x₂ ≤* l → x₁ ≤* l\n≤-≤* x₁≤x₂ = map (≤-trans x₁≤x₂)\n\ndata Sorted : val (list A) → Set where\n [] : Sorted []\n _∷_ : ∀ {y ys} → y ≤* ys → Sorted ys → Sorted (y ∷ ys)\n\nshort-sorted : {l : val (list A)} → length l Nat.≤ 1 → Sorted l\nshort-sorted {[]} _ = []\nshort-sorted {_ ∷ []} _ = [] ∷ []\nshort-sorted {_ ∷ _ ∷ _} (s≤s ())\n\nunique-sorted : ∀ {l'₁ l'₂} → Sorted l'₁ → Sorted l'₂ → l'₁ ↭ l'₂ → l'₁ ≡ l'₂\nunique-sorted [] [] ↭ = refl\nunique-sorted [] (h₂ ∷ sorted₂) ↭ = contradiction (↭-sym ↭) ¬x∷xs↭[]\nunique-sorted (h₁ ∷ sorted₁) [] ↭ = contradiction (↭) ¬x∷xs↭[]\nunique-sorted (h₁ ∷ sorted₁) (h₂ ∷ sorted₂) ↭ with\n ≤-antisym\n (lookup (≤-refl ∷ h₁) (Any-resp-↭ (↭-sym ↭) (here refl)))\n (lookup (≤-refl ∷ h₂) (Any-resp-↭ (↭) (here refl)))\n... | refl = Eq.cong (_ ∷_) (unique-sorted sorted₁ sorted₂ (drop-∷ ↭))\n\njoin-sorted : ∀ {l₁ mid l₂} → Sorted l₁ → Sorted l₂ → All (_≤ mid) l₁ → All (mid ≤_) l₂ → Sorted (l₁ ++ [ mid ] ++ l₂)\njoin-sorted [] sorted₂ all₁ all₂ = all₂ ∷ sorted₂\njoin-sorted (h ∷ sorted₁) sorted₂ (h' ∷ all₁) all₂ =\n ++⁺-All h (h' ∷ ≤-≤* h' all₂) ∷ (join-sorted sorted₁ sorted₂ all₁ all₂)\n\n++⁻ˡ : ∀ xs {ys} → Sorted (xs ++ ys) → Sorted xs\n++⁻ˡ [] sorted = []\n++⁻ˡ (x ∷ xs) (h ∷ sorted) = AllP.++⁻ˡ xs h ∷ (++⁻ˡ xs sorted)\n\n++⁻ʳ : ∀ xs {ys} → Sorted (xs ++ ys) → Sorted ys\n++⁻ʳ [] sorted = sorted\n++⁻ʳ (x ∷ xs) (h ∷ sorted) = ++⁻ʳ xs sorted\n\nsplit-sorted₁ : ∀ xs {x} → Sorted (xs ∷ʳ x) → All (_≤ x) xs\nsplit-sorted₁ [] sorted = []\nsplit-sorted₁ (x ∷ xs) (h ∷ sorted) = proj₂ (AllP.∷ʳ⁻ h) ∷ split-sorted₁ xs sorted\n\nuncons₁ : ∀ {x xs} → Sorted (x ∷ xs) → x ≤* xs\nuncons₁ (h ∷ sorted) = h\n\nuncons₂ : ∀ {x xs} → Sorted (x ∷ xs) → Sorted xs\nuncons₂ (h ∷ sorted) = sorted\n\nSortedOf : val (list A) → val (list A) → Set\nSortedOf l l' = l ↭ l' × Sorted l'\n\nSortResult : cmp (Π (list A) λ _ → F (list A)) → val (list A) → Set\nSortResult sort l = ◯ (∃ λ l' → sort l ≡ ret l' × SortedOf l l')\n\nIsSort : cmp (Π (list A) λ _ → F (list A)) → Set\nIsSort sort = ∀ l → SortResult sort l\n\nIsSort⇒≡ : ∀ sort₁ → IsSort sort₁ → ∀ sort₂ → IsSort sort₂ → ◯ (sort₁ ≡ sort₂)\nIsSort⇒≡ sort₁ correct₁ sort₂ correct₂ u =\n funext λ l →\n let (l'₁ , ≡₁ , ↭₁ , sorted₁) = correct₁ l u in\n let (l'₂ , ≡₂ , ↭₂ , sorted₂) = correct₂ l u in\n begin\n sort₁ l\n ≡⟨ ≡₁ ⟩\n ret l'₁\n ≡⟨ Eq.cong ret (unique-sorted sorted₁ sorted₂ (trans (↭-sym ↭₁) ↭₂)) ⟩\n ret l'₂\n ≡˘⟨ ≡₂ ⟩\n sort₂ l\n ∎\n where open ≡-Reasoning\n", "meta": {"hexsha": "b073858fa7aefb0a897527af816969e93edd42ef", "size": 4200, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Examples/Sorting/Core.agda", "max_stars_repo_name": "jonsterling/agda-calf", "max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z", "max_issues_repo_path": "src/Examples/Sorting/Core.agda", "max_issues_repo_name": "jonsterling/agda-calf", "max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146", "max_issues_repo_licenses": ["Apache-2.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/Examples/Sorting/Core.agda", "max_forks_repo_name": "jonsterling/agda-calf", "max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z", "avg_line_length": 34.7107438017, "max_line_length": 118, "alphanum_fraction": 0.5797619048, "num_tokens": 1721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154240079185319, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.37725490059787614}} {"text": "record R (A B : Set) : Set where\n constructor c₁\n field\n x : A\n\nmutual\n\n T : Set\n T = R D T\n\n data D : Set where\n c₂ : T → D\n\nf : T → Set\nf (c₁ (c₂ x)) = f x\n", "meta": {"hexsha": "274b0913942ebac5f6f0f1583486cdd559a46828", "size": 169, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue2997.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/Issue2997.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/Issue2997.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": 10.5625, "max_line_length": 32, "alphanum_fraction": 0.4970414201, "num_tokens": 74, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.37721607211031083}} {"text": "--------------------------------------------------------------------------------\n-- This is part of Agda Inference Systems\n\n{-# OPTIONS --sized-types #-}\n\nopen import Relation.Nullary\nopen import Relation.Nullary.Decidable\nopen import Data.Nat\nopen import Data.Vec\nopen import Data.Fin\nopen import Data.Product\nopen import Data.Sum\nopen import Data.Bool\nopen import Data.Unit\nopen import Data.Empty\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Binary.Construct.Closure.ReflexiveTransitive\nopen import Size\nopen import Codata.Thunk\nopen import Axiom.ExcludedMiddle\nopen import Level renaming (zero to ∅ ; suc to ++)\n\nopen import is-lib.SInfSys as IS\nopen import Examples.Lambda.Lambda\nopen import Examples.Lambda.BigStep renaming (U to BigStepU)\nopen import Examples.Lambda.SmallStep\n\nmodule Examples.Lambda.Proofs where\n\n Spec : BigStepU → Set\n Spec (e , res x) = e ⇒* term x\n Spec (e , div) = ∀{i} → ⇒∞ e i\n\n {- Soundness -}\n Spec-val : BigStepU → Set\n Spec-val (e , v) = ∀{v'} → v ≡ res v' → Spec (e , v)\n\n Spec-closed : ISClosed (BigStepIS ∪ BigStepCOIS) Spec-val\n Spec-closed (inj₁ VAL) _ _ refl = ε\n Spec-closed (inj₁ APP) _ prem refl =\n let s-e1 = prem zero refl in\n let s-e2 = prem (suc zero) refl in\n let s-subst = prem (suc (suc zero)) refl in\n let subst = IS.fold (β , _ , refl , λ ()) in\n inj-l-app _ (prem zero refl) ◅◅ inj-r-app _ (prem (suc zero) refl) ◅◅ subst ◅ prem (suc (suc zero)) refl\n Spec-closed (inj₂ COA) s_ _ ()\n\n ⇓ᵢ-to-⇒* : ∀{e v} → e ⇓ᵢ v → Spec-val (e , v)\n ⇓ᵢ-to-⇒* = ind[ BigStepIS ∪ BigStepCOIS ] Spec-val Spec-closed\n\n bs-sound-v : ∀{e v} → (∀{i} → (e ⇓ (res v)) i) → e ⇒* (term v)\n bs-sound-v r = ⇓ᵢ-to-⇒* (sfcoind-to-ind r) refl\n\n subject-red-⇓ : ∀{e e' v} → (∀{i} → (e ⇓ v) i) → e ⇒ e' → (∀{i} → (e' ⇓ v) i)\n subject-red-⇓ bs (fold (β , (e , v) , eq , _)) with bs\n subject-red-⇓ bs (fold (β , (e , v) , () , _)) | sfold (VAL , (lambda x , _) , refl , prem)\n subject-red-⇓ bs (fold (β , (e , lambda x) , refl , _)) | sfold (APP , ((.(lambda e) , _ , .(lambda x) , v , _) , _) , refl , prem)\n with val-⇓-≡ (prem zero .force) | val-⇓-≡ (prem (suc zero) .force)\n subject-red-⇓ bs (fold (β , (e , lambda x) , refl , _)) | sfold (APP , ((.(lambda e) , .e , .(lambda x) , .(lambda x) , _) , _) , refl , prem) | refl | refl = prem (suc (suc zero)) .force\n subject-red-⇓ bs (fold (β , (e , v) , refl , _)) | sfold (L-DIV , _ , refl , prem) = ⊥-elim (val-not-reduce⇓ (prem zero .force))\n subject-red-⇓ bs (fold (β , (e , v) , refl , _)) | sfold (R-DIV , _ , refl , prem) = ⊥-elim (val-not-reduce⇓ (prem (suc zero) .force))\n subject-red-⇓ bs (fold (L-APP , c , eq , _)) with bs\n subject-red-⇓ bs (fold (L-APP , _ , () , _)) | sfold (VAL , (lambda _ , _) , refl , _)\n subject-red-⇓ bs (fold (L-APP , (e1 , e1' , e2) , refl , pr)) | sfold (APP , ((.e1 , e1'' , .e2 , lambda _ , _) , ind) , refl , prem) =\n let rec = subject-red-⇓ (prem zero .force) (pr zero) in\n let prems = λ{zero → rec ; (suc zero) → prem (suc zero) .force ; (suc (suc zero)) → prem (suc (suc zero)) .force} in\n apply-sfcoind APP _ prems\n subject-red-⇓ bs (fold (L-APP , (e1 , e1' , e2) , refl , pr)) | sfold (L-DIV , ((.e1 , .e2) , ind) , refl , prem) =\n let rec = subject-red-⇓ (prem zero .force) (pr zero) in\n apply-sfcoind L-DIV _ λ{zero → rec}\n subject-red-⇓ bs (fold (L-APP , (e1 , e1' , e2) , refl , pr)) | sfold (R-DIV , ((.e1 , .e2 , lambda v) , ind) , refl , prem) =\n let rec = subject-red-⇓ (prem zero .force) (pr zero) in\n let prems = λ{zero → rec ; (suc zero) → prem (suc zero) .force} in\n apply-sfcoind R-DIV _ prems\n subject-red-⇓ bs (fold (R-APP , (lambda _ , e2 , e2') , eq , pr)) with bs\n subject-red-⇓ bs (fold (R-APP , (lambda _ , _ , _) , refl , _)) | sfold (VAL , (lambda _ , _) , () , _)\n subject-red-⇓ bs (fold (R-APP , (lambda e1 , e2 , e2') , refl , pr)) | sfold (APP , ((.(lambda _) , e1' , .e2 , lambda _ , _) , ind) , refl , prem)\n with val-⇓-≡ (prem zero .force)\n subject-red-⇓ bs (fold (R-APP , (lambda e1 , e2 , e2') , refl , pr)) | sfold (APP , ((.(lambda e1) , .e1 , .e2 , lambda _ , _) , ind) , refl , prem) | refl =\n let rec = subject-red-⇓ (prem (suc zero) .force) (pr zero) in\n let prems = λ{zero → prem zero .force ; (suc zero) → rec ; (suc (suc zero)) → prem (suc (suc zero)) .force} in\n apply-sfcoind APP _ prems\n subject-red-⇓ bs (fold (R-APP , (lambda _ , e2 , e2') , refl , _)) | sfold (L-DIV , ((.(lambda _) , .e2) , _) , refl , prem) = ⊥-elim (val-not-reduce⇓ (prem zero .force))\n subject-red-⇓ bs (fold (R-APP , (lambda e , e2 , e2') , refl , pr)) | sfold (R-DIV , ((.(lambda e) , .e2 , v) , ind) , refl , prem) with val-⇓-≡ (prem zero .force)\n subject-red-⇓ bs (fold (R-APP , (lambda e , e2 , e2') , refl , pr)) | sfold (R-DIV , ((.(lambda e) , .e2 , .(lambda e)) , ind) , refl , prem) | refl =\n let rec = subject-red-⇓ (prem (suc zero) .force) (pr zero) in\n let prems = λ{zero → prem zero .force ; (suc zero) → rec} in\n apply-sfcoind R-DIV _ prems\n\n progress : ∀{e} →(∀{i} → (e ⇓ div) i) → Σ[ e' ∈ Term 0 ] (e ⇒ e')\n progress {e} bs with bs\n progress bs | sfold (APP , _ , refl , prem) with bs-sound-v (prem zero .force)\n progress bs | sfold (APP , ((_ , e1' , _ , _ , .div) , _) , refl , prem) | ε with bs-sound-v (prem (suc zero) .force)\n progress bs | sfold (APP , ((.(lambda e1') , e1' , _ , v , .div) , _) , refl , prem) | ε | ε =\n _ , apply-ind β _ λ ()\n progress bs | sfold (APP , ((.(lambda e1') , e1' , e2 , _ , .div) , _) , refl , prem) | ε | x ◅ _ =\n app (lambda e1') _ , apply-ind R-APP _ λ{zero → x}\n progress bs | sfold (APP , ((e1 , _ , e2 , _ , .div) , _) , refl , prem) | x ◅ _ =\n app _ e2 , apply-ind L-APP _ λ{zero → x}\n progress bs | sfold (L-DIV , ((e1 , e2) , _) , refl , prem) =\n let e1' , e1⇒e1' = progress (prem zero .force) in\n app e1' e2 , apply-ind L-APP _ λ{zero → e1⇒e1'}\n progress bs | sfold (R-DIV , ((e1 , e2 , v) , _) , refl , prem) with bs-sound-v (prem zero .force)\n progress bs | sfold (R-DIV , ((.(term _) , e2 , (lambda e)) , _) , refl , prem) | ε =\n let e2' , e2⇒e2' = progress (prem (suc zero) .force) in\n app (lambda e) e2' , apply-ind R-APP _ λ{zero → e2⇒e2'}\n progress bs | sfold (R-DIV , ((e1 , e2 , (lambda e)) , _) , refl , prem) | x ◅ _ =\n app _ e2 , apply-ind L-APP _ λ{zero → x}\n\n bs-sound-∞ : ∀{e} → (∀{i} → (e ⇓ div) i) → (∀{i} → ⇒∞ e i)\n bs-sound-∞ bs with progress bs\n ... | e' , ss = step ss λ where .force → bs-sound-∞ (subject-red-⇓ bs ss)\n\n bs-sound : ∀{e v} → (∀{i} → (e ⇓ v) i) → Spec (e , v)\n bs-sound {_} {res _} = bs-sound-v\n bs-sound {_} {div} = bs-sound-∞\n\n\n {- Completeness -}\n inv-app : ∀{e1 e2 v} → (app e1 e2) ⇓ᵢ (res v) →\n Σ[ e1' ∈ Term 1 ] Σ[ e2' ∈ Value ]\n (e1 ⇓ᵢ res (lambda e1')) ×\n (e2 ⇓ᵢ (res e2')) ×\n (subst-0 e1' (term e2') ⇓ᵢ res v)\n -- Using consistency of inductive interpretation\n inv-app bs with ind-postfix bs\n inv-app bs | inj₁ VAL , lambda _ , () , _\n inv-app bs | inj₁ APP , _ , refl , pr = _ , _ , pr zero , pr (suc zero) , pr (suc (suc zero))\n inv-app bs | inj₂ COA , _ , () , _\n\n subject-exp : ∀{e e' v} → e ⇒ e' → e' ⇓ᵢ v → e ⇓ᵢ v\n subject-exp {.(app (lambda e1) (term v))} {_} {v'} (fold (β , (e1 , v) , refl , _)) bs =\n let prem-e1 = IS.fold (inj₁ VAL , lambda e1 , refl , λ ()) in\n let prem-e2 = IS.fold (inj₁ VAL , v , refl , λ ()) in\n let prems = λ{zero → prem-e1 ; (suc zero) → prem-e2 ; (suc (suc zero)) → bs} in\n apply-ind (inj₁ APP) _ prems\n subject-exp {.(app e1 e2)} {.(app e1' e2)} {res x} (fold (L-APP , (e1 , e1' , e2) , refl , pr)) bs =\n let e1'' , e2' , bs-e1' , bs-e2 , bs-subst = inv-app bs in\n let prems = λ{zero → subject-exp (pr zero) bs-e1' ; (suc zero) → bs-e2 ; (suc (suc zero)) → bs-subst} in\n apply-ind (inj₁ APP) _ prems\n subject-exp {.(app e1 e2)} {.(app e1' e2)} {div} (fold (L-APP , (e1 , e1' , e2) , refl , pr)) bs =\n apply-ind (inj₂ COA) _ λ ()\n subject-exp {.(app (term v) e2)} {.(app (term v) e2')} {res x} (fold (R-APP , (v , e2 , e2') , refl , pr)) bs =\n let e1' , e2'' , bs-e1 , bs-e2' , bs-subst = inv-app bs in\n let prems = λ{zero → bs-e1 ; (suc zero) → subject-exp (pr zero) bs-e2' ; (suc (suc zero)) → bs-subst} in\n apply-ind (inj₁ APP) _ prems\n subject-exp {.(app (term v) e2)} {.(app (term v) e2')} {div} (fold (R-APP , (v , e2 , e2') , refl , _)) bs =\n apply-ind (inj₂ COA) _ λ ()\n\n bounded-v : ∀{e v} → e ⇒* term v → e ⇓ᵢ res v\n bounded-v ε = apply-ind (inj₁ VAL) _ λ ()\n bounded-v (x ◅ ss) = subject-exp x (bounded-v ss)\n\n bounded-∞ : ∀{e} → (∀{i} → ⇒∞ e i) → e ⇓ᵢ div\n bounded-∞ {e} ss = apply-ind (inj₂ COA) _ λ ()\n \n bounded : ∀{e v} → Spec (e , v) → e ⇓ᵢ v\n bounded {_} {res _} = bounded-v\n bounded {_} {div} = bounded-∞\n\n get-prem-cons : ∀{e1 e2 v} → app e1 e2 ⇒* (term v) →\n Σ[ e1' ∈ Term 1 ] Σ[ e2' ∈ Value ]\n (e1 ⇒* lambda e1') ×\n (e2 ⇒* term e2') ×\n (subst-0 e1' (term e2') ⇒* (term v))\n get-prem-cons {.(lambda e1)} {.(term v)} {lambda _} (fold (β , (e1 , v) , refl , _) ◅ ss) =\n e1 , v , ε , ε , ss\n get-prem-cons {.e1} {.e2} {lambda _} (fold (L-APP , (e1 , e1' , e2) , refl , pr) ◅ ss) =\n let e1'' , e2' , rec-e1' , rec-e2 , rec-subst = get-prem-cons ss in\n e1'' , e2' , pr zero ◅ rec-e1' , rec-e2 , rec-subst\n get-prem-cons {.(term v)} {.e2} {lambda _} (fold (R-APP , (v , e2 , e2') , refl , pr) ◅ ss) =\n let e1' , e2'' , rec-e1 , rec-e2' , rec-subst = get-prem-cons ss in\n e1' , e2'' , rec-e1 , pr zero ◅ rec-e2' , rec-subst\n\n consistent-v : ∀{e v} → e ⇒* term v → IS.ISF[ BigStepIS ] Spec (e , res v)\n consistent-v {.(lambda _)} {lambda _} ε = VAL , _ , refl , λ ()\n consistent-v {lambda _} {lambda _} (x ◅ ss) = ⊥-elim (val-not-reduce⇒ x)\n consistent-v {app e1 e2} {lambda _} (x ◅ ss) =\n let e1' , e2' , e1⇒* , e2⇒* , subst⇒* = get-prem-cons (x ◅ ss) in\n let prems = λ{zero → e1⇒* ; (suc zero) → e2⇒* ; (suc (suc zero)) → subst⇒*} in\n APP , (e1 , e1' , e2 , e2' , _) , refl , prems\n \n postulate\n excluded-middle : ExcludedMiddle ∅\n \n lemma-divergence : ∀{e1 e2} → (∀{i} → ⇒∞ (app e1 e2) i) →\n (∀{i} → ⇒∞ e1 i) ⊎\n e1 ConvergesSS × (∀{i} → ⇒∞ e2 i) ⊎\n Σ[ t1 ∈ Term 1 ] Σ[ v ∈ Value ] (e1 ⇒* lambda t1) × (e2 ⇒* term v) × (∀{i} → ⇒∞ (subst-0 t1 (term v)) i)\n lemma-divergence {e1} {e2} ss with excluded-middle {e1 ConvergesSS}\n lemma-divergence {e1} {e2} ss | no ¬e1-conv = inj₁ (div-app-l-not-conv ss ¬e1-conv)\n lemma-divergence {e1} {e2} ss | yes e1-conv with excluded-middle {e2 ConvergesSS}\n lemma-divergence {e1} {e2} ss | yes e1-conv | no ¬e2-conv =\n inj₂ (inj₁ (e1-conv , div-app-r-not-conv ss (proj₂ e1-conv) ¬e2-conv))\n lemma-divergence {e1} {e2} ss | yes (lambda _ , red-e1) | yes (_ , red-e2) =\n inj₂ (inj₂ (_ , _ , ( red-e1 , red-e2 , app-subst-⇒∞₁ red-e1 red-e2 ss)))\n\n consistent-∞ : ∀{e} → (∀{i} → ⇒∞ e i) → IS.ISF[ BigStepIS ] Spec (e , div)\n consistent-∞ {e} ss with ss\n consistent-∞ {lambda e} ss | step x _ = ⊥-elim (val-not-reduce⇒ x)\n consistent-∞ {app e₁ e₂} ss | step x x₁ with lemma-divergence (step x x₁)\n consistent-∞ {app e₁ e₂} ss | step x x₁ | inj₁ e1-div =\n L-DIV , _ , refl , λ{zero → e1-div}\n consistent-∞ {app e₁ e₂} ss | step x x₁ | inj₂ (inj₁ (e1-conv , e2-div)) =\n R-DIV , _ , refl , λ{zero → proj₂ e1-conv ; (suc zero) → e2-div}\n consistent-∞ {app e₁ e₂} ss | step x x₁ | inj₂ (inj₂ (_ , _ , red-e1 , red-e2 , subst-div)) =\n APP , _ , refl , λ{zero → red-e1 ; (suc zero) → red-e2 ; (suc (suc zero)) → subst-div}\n\n consistent : ∀{e v} → Spec (e , v) → IS.ISF[ BigStepIS ] Spec (e , v)\n consistent {_} {res _} = consistent-v\n consistent {_} {div} = consistent-∞\n\n complete : ∀{e v} → Spec (e , v) → (∀{i} → (e ⇓ v) i)\n complete = bounded-scoind[ BigStepIS , BigStepCOIS ] Spec bounded consistent", "meta": {"hexsha": "ccd82eab8df23d5e296cc6df41b362b5f618d3b7", "size": 11768, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Examples/Lambda/Proofs.agda", "max_stars_repo_name": "LcicC/inference-systems-agda", "max_stars_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-03-10T15:53:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T15:48:52.000Z", "max_issues_repo_path": "Examples/Lambda/Proofs.agda", "max_issues_repo_name": "LcicC/inference-systems-agda", "max_issues_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f", "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": "Examples/Lambda/Proofs.agda", "max_forks_repo_name": "LcicC/inference-systems-agda", "max_forks_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f", "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": 54.9906542056, "max_line_length": 189, "alphanum_fraction": 0.543167913, "num_tokens": 4947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.37721607211031083}} {"text": "open import Agda.Builtin.Unit\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Reflection renaming (bindTC to _>>=_)\nopen import Agda.Builtin.Equality\n\nmacro\n macro₁ : Term -> TC ⊤\n macro₁ goal = do\n u ← quoteTC ((1 + 2) - 3)\n u' ← onlyReduceDefs (quote _+_ ∷ []) (normalise u)\n qu' ← quoteTC u'\n unify qu' goal\n\ntest₁ : macro₁ ≡ def (quote _-_)\n (arg (arg-info visible relevant) (lit (nat 3)) ∷\n arg (arg-info visible relevant) (lit (nat 3)) ∷ [])\ntest₁ = refl\n\n\nmacro\n macro₂ : Term -> TC ⊤\n macro₂ goal = do\n u ← quoteTC ((1 - 2) + 3)\n u' ← dontReduceDefs (quote _+_ ∷ []) (normalise u)\n qu' ← quoteTC u'\n unify qu' goal\n\ntest₂ : macro₂ ≡ def (quote _+_)\n (arg (arg-info visible relevant) (lit (nat 0)) ∷\n arg (arg-info visible relevant) (lit (nat 3)) ∷ [])\ntest₂ = refl\n", "meta": {"hexsha": "6f8232595e4aac1fb9e4c880685712f10e124b2c", "size": 917, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/ReduceDefs.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/Succeed/ReduceDefs.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/Succeed/ReduceDefs.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": 27.7878787879, "max_line_length": 71, "alphanum_fraction": 0.5736095965, "num_tokens": 298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7310585669110202, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.37694835665924886}} {"text": "{-# OPTIONS --safe --experimental-lossy-unification #-}\nmodule Cubical.Categories.Limits.RightKan where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Structure\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Powerset\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Categories.Category\nopen import Cubical.Categories.Morphism renaming (isIso to isIsoC)\nopen import Cubical.Categories.Functor\nopen import Cubical.Categories.NaturalTransformation\nopen import Cubical.Categories.Limits.Limits\n\n\n\nmodule _ {ℓC ℓC' ℓM ℓM' ℓA ℓA' : Level}\n {C : Category ℓC ℓC'}\n {M : Category ℓM ℓM'}\n {A : Category ℓA ℓA'}\n (limitA : Limits {ℓ-max ℓC' ℓM} {ℓ-max ℓC' ℓM'} A)\n (K : Functor M C)\n (T : Functor M A)\n where\n\n open Category\n open Functor\n open Cone\n open LimCone\n\n\n _↓Diag : ob C → Category (ℓ-max ℓC' ℓM) (ℓ-max ℓC' ℓM')\n ob (x ↓Diag) = Σ[ u ∈ ob M ] C [ x , K .F-ob u ]\n Hom[_,_] (x ↓Diag) (u , f) (v , g) = Σ[ h ∈ M [ u , v ] ] f ⋆⟨ C ⟩ K .F-hom h ≡ g\n id (x ↓Diag) {x = (u , f)} = id M , cong (seq' C f) (F-id K) ∙ ⋆IdR C f\n _⋆_ (x ↓Diag) {x = (u , f)} (h , hComm) (k , kComm) = (h ⋆⟨ M ⟩ k)\n , cong (seq' C f) (F-seq K h k)\n ∙ sym (⋆Assoc C _ _ _)\n ∙ cong (λ l → seq' C l (F-hom K k)) hComm\n ∙ kComm\n ⋆IdL (x ↓Diag) _ = Σ≡Prop (λ _ → isSetHom C _ _) (⋆IdL M _)\n ⋆IdR (x ↓Diag) _ = Σ≡Prop (λ _ → isSetHom C _ _) (⋆IdR M _)\n ⋆Assoc (x ↓Diag) _ _ _ = Σ≡Prop (λ _ → isSetHom C _ _) (⋆Assoc M _ _ _)\n isSetHom (x ↓Diag) = isSetΣSndProp (isSetHom M) λ _ → isSetHom C _ _\n\n private\n i : (x : ob C) → Functor (x ↓Diag) M\n F-ob (i x) = fst\n F-hom (i x) = fst\n F-id (i x) = refl\n F-seq (i x) _ _ = refl\n\n j : {x y : ob C} (f : C [ x , y ]) → Functor (y ↓Diag) (x ↓Diag)\n F-ob (j f) (u , g) = u , f ⋆⟨ C ⟩ g\n F-hom (j f) (h , hComm) = h , ⋆Assoc C _ _ _ ∙ cong (seq' C f) hComm\n F-id (j f) = Σ≡Prop (λ _ → isSetHom C _ _) refl\n F-seq (j f) _ _ = Σ≡Prop (λ _ → isSetHom C _ _) refl\n\n\n T* : (x : ob C) → Functor (x ↓Diag) A\n T* x = funcComp T (i x)\n\n RanOb : ob C → ob A\n RanOb x = limitA (x ↓Diag) (T* x) .lim\n\n\n RanCone : {x y : ob C} → C [ x , y ] → Cone (T* y) (RanOb x)\n coneOut (RanCone {x = x} f) v = limOut (limitA (x ↓Diag) (T* x)) (j f .F-ob v)\n coneOutCommutes (RanCone {x = x} f) h = limOutCommutes (limitA (x ↓Diag) (T* x)) (j f .F-hom h)\n\n\n -- technical lemmas for proving functoriality\n RanConeRefl : ∀ {x} v →\n limOut (limitA (x ↓Diag) (T* x)) v\n ≡ limOut (limitA (x ↓Diag) (T* x)) (j (id C) .F-ob v)\n RanConeRefl {x = x} (v , f) =\n cong (λ p → limOut (limitA (x ↓Diag) (T* x)) (v , p)) (sym (⋆IdL C f))\n\n RanConeTrans : ∀ {x y z} (f : C [ x , y ]) (g : C [ y , z ]) v →\n limOut (limitA (x ↓Diag) (T* x)) (j f .F-ob (j g .F-ob v))\n ≡ limOut (limitA (x ↓Diag) (T* x)) (j (f ⋆⟨ C ⟩ g) .F-ob v)\n RanConeTrans {x = x} {y = y} {z = z} f g (v , h) =\n cong (λ p → limOut (limitA (x ↓Diag) (T* x)) (v , p)) (sym (⋆Assoc C f g h))\n\n\n -- the right Kan-extension\n Ran : Functor C A\n F-ob Ran = RanOb\n F-hom Ran {y = y} f = limArrow (limitA (y ↓Diag) (T* y)) _ (RanCone f)\n F-id Ran {x = x} =\n limArrowUnique (limitA (x ↓Diag) (T* x)) _ _ _ (λ v → (⋆IdL A _) ∙ RanConeRefl v)\n F-seq Ran {x = x} {y = y} {z = z} f g =\n limArrowUnique (limitA (z ↓Diag) (T* z)) _ _ _ path\n where\n path : ∀ v →\n (F-hom Ran f) ⋆⟨ A ⟩ (F-hom Ran g) ⋆⟨ A ⟩ (limOut (limitA (z ↓Diag) (T* z)) v)\n ≡ coneOut (RanCone (f ⋆⟨ C ⟩ g)) v\n path v = (F-hom Ran f) ⋆⟨ A ⟩ (F-hom Ran g) ⋆⟨ A ⟩ (limOut (limitA (z ↓Diag) (T* z)) v)\n ≡⟨ ⋆Assoc A _ _ _ ⟩\n (F-hom Ran f) ⋆⟨ A ⟩ ((F-hom Ran g) ⋆⟨ A ⟩ (limOut (limitA (z ↓Diag) (T* z)) v))\n ≡⟨ cong (seq' A (F-hom Ran f)) (limArrowCommutes _ _ _ _) ⟩\n (F-hom Ran f) ⋆⟨ A ⟩ limOut (limitA (y ↓Diag) (T* y)) (j g .F-ob v)\n ≡⟨ limArrowCommutes _ _ _ _ ⟩\n limOut (limitA (x ↓Diag) (T* x)) (j f .F-ob (j g .F-ob v))\n ≡⟨ RanConeTrans f g v ⟩\n coneOut (RanCone (f ⋆⟨ C ⟩ g)) v ∎\n\n\n open NatTrans\n RanNatTrans : NatTrans (funcComp Ran K) T\n N-ob RanNatTrans u = coneOut (RanCone (id C)) (u , id C)\n N-hom RanNatTrans {x = u} {y = v} f =\n Ran .F-hom (K .F-hom f) ⋆⟨ A ⟩ coneOut (RanCone (id C)) (v , id C)\n ≡⟨ cong (λ g → Ran .F-hom (K .F-hom f) ⋆⟨ A ⟩ g) (sym (RanConeRefl (v , id C))) ⟩\n Ran .F-hom (K .F-hom f) ⋆⟨ A ⟩ limOut (limitA ((K .F-ob v) ↓Diag) (T* (K .F-ob v))) (v , id C)\n ≡⟨ limArrowCommutes _ _ _ _ ⟩\n coneOut (RanCone (K .F-hom f)) (v , id C)\n ≡⟨ cong (λ g → limOut (limitA ((K .F-ob u) ↓Diag) (T* (K .F-ob u))) (v , g))\n (⋆IdR C (K .F-hom f) ∙ sym (⋆IdL C (K .F-hom f))) ⟩\n coneOut (RanCone (id C)) (v , K .F-hom f)\n ≡⟨ sym (coneOutCommutes (RanCone (id C)) (f , ⋆IdL C _)) ⟩\n coneOut (RanCone (id C)) (u , id C) ⋆⟨ A ⟩ T .F-hom f ∎\n\n -- TODO: show that this nat. trans. is a \"universal arrow\" and that is a nat. iso.\n -- if K is full and faithful...\n", "meta": {"hexsha": "7dd85972e3e866fe6252b5b46e3110ee7aac3248", "size": 5225, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Categories/Limits/RightKan.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_issues_repo_path": "Cubical/Categories/Limits/RightKan.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Categories/Limits/RightKan.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": 41.1417322835, "max_line_length": 99, "alphanum_fraction": 0.5020095694, "num_tokens": 2296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544210587585, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3768863999423516}} {"text": "module PiFrac.Category where\nopen import Categories.Category.Monoidal\nopen import Categories.Category.Monoidal.Braided\nopen import Categories.Category.Monoidal.Symmetric\nopen import Categories.Category.Monoidal.Rigid\nopen import Categories.Category.Monoidal.CompactClosed\nopen import Categories.Functor.Bifunctor\nopen import Categories.Category\nopen import Categories.Category.Product\nopen import Categories.Category.Groupoid\nopen import Data.Empty\nopen import Data.Unit hiding (_≟_)\nopen import Data.Sum\nopen import Data.Product\nopen import Data.Maybe\nopen import Relation.Binary.Core\nopen import Relation.Binary hiding (Symmetric)\nopen import Relation.Nullary\nopen import Relation.Binary.PropositionalEquality\nopen import Function using (_∘_)\nopen import PiFrac.Syntax\nopen import PiFrac.Opsem\nopen import PiFrac.Interp\nopen import PiFrac.Properties\n\nPi∙ : Category _ _ _ \nPi∙ = record\n { Obj = Σ[ t ∈ 𝕌 ] ⟦ t ⟧\n ; _⇒_ = λ (A , a) (B , b) → Σ[ c ∈ (A ↔ B) ] (interp c a ≡ just b)\n ; _≈_ = λ {(A , a)} {(B , b)} (c , eq) (c' , eq) → ⊤\n ; id = id↔ , refl\n ; _∘_ = λ (c₂ , eq₂) (c₁ , eq₁) → comp (c₁ , eq₁) (c₂ , eq₂)\n ; assoc = tt\n ; sym-assoc = tt\n ; identityˡ = tt\n ; identityʳ = tt\n ; identity² = tt\n ; equiv = record { refl = tt ; sym = λ _ → tt ; trans = λ _ _ → tt }\n ; ∘-resp-≈ = λ _ _ → tt\n }\n where\n comp : ∀ {A B C a b c} → Σ[ c₁ ∈ (A ↔ B) ] (interp c₁ a ≡ just b) → Σ[ c₂ ∈ (B ↔ C) ] (interp c₂ b ≡ just c)\n → Σ[ c' ∈ (A ↔ C) ] (interp c' a ≡ just c)\n comp {c = c} (c₁ , eq₁) (c₂ , eq₂) = (c₁ ⨾ c₂) , subst (λ x → (x >>= interp c₂) ≡ just c) (sym eq₁) eq₂\n\nPi∙Groupoid : Groupoid _ _ _\nPi∙Groupoid = record { category = Pi∙\n ; isGroupoid = record { _⁻¹ = λ (c , eq) → ! c , interp! c _ _ eq\n ; iso = record { isoˡ = tt\n ; isoʳ = tt } } }\n\nPi∙Monoidal : Monoidal Pi∙\nPi∙Monoidal = record\n { ⊗ = record\n { F₀ = λ ((A , a) , (B , b)) → (A ×ᵤ B) , (a , b)\n ; F₁ = λ {((A , a) , (B , b))} {((C , c) , (D , d))} ((c₁ , eq₁) , (c₂ , eq₂)) →\n (c₁ ⊗ c₂) , subst (λ x → (x >>= (λ v₁' → interp c₂ b >>= λ v₂' → just (v₁' , v₂'))) ≡ just (c , d))\n (sym eq₁) (subst (λ x → (x >>= λ v₂' → just (c , v₂')) ≡ just (c , d)) (sym eq₂) refl)\n ; identity = tt\n ; homomorphism = tt\n ; F-resp-≈ = λ _ → tt\n }\n ; unit = (𝟙 , tt)\n ; unitorˡ = record { from = unite⋆l , refl\n ; to = uniti⋆l , refl\n ; iso = record { isoˡ = tt ; isoʳ = tt } }\n ; unitorʳ = record { from = unite⋆r , refl\n ; to = uniti⋆r , refl\n ; iso = record { isoˡ = tt ; isoʳ = tt } }\n ; associator = record { from = assocr⋆ , refl\n ; to = assocl⋆ , refl\n ; iso = record { isoˡ = tt ; isoʳ = tt } }\n ; unitorˡ-commute-from = tt\n ; unitorˡ-commute-to = tt\n ; unitorʳ-commute-from = tt\n ; unitorʳ-commute-to = tt\n ; assoc-commute-from = tt\n ; assoc-commute-to = tt\n ; triangle = tt\n ; pentagon = tt\n }\n\nPi∙Braided : Braided Pi∙Monoidal\nPi∙Braided = record { braiding = record { F⇒G = record { η = λ _ → swap⋆ , refl\n ; commute = λ _ → tt\n ; sym-commute = λ _ → tt }\n ; F⇐G = record { η = λ _ → swap⋆ , refl\n ; commute = λ _ → tt\n ; sym-commute = λ _ → tt }\n ; iso = λ X → record { isoˡ = tt ; isoʳ = tt } }\n ; hexagon₁ = tt\n ; hexagon₂ = tt }\n\nPi∙Symmetric : Symmetric Pi∙Monoidal\nPi∙Symmetric = record { braided = Pi∙Braided\n ; commutative = tt}\n\nPi∙Rigid : LeftRigid Pi∙Monoidal\nPi∙Rigid = record { _⁻¹ = λ {(A , a) → 𝟙/ a , ↻}\n ; η = λ {(X , x)} → ηₓ x , refl\n ; ε = λ {(X , x)} → (swap⋆ ⨾ εₓ x) , εₓ≡\n ; snake₁ = tt\n ; snake₂ = tt}\n where\n εₓ≡ : ∀ {X} {x : ⟦ X ⟧} → interp (swap⋆ ⨾ εₓ x) (↻ , x) ≡ just tt\n εₓ≡ {X} {x} with x ≟ x\n ... | yes refl = refl\n ... | no neq = ⊥-elim (neq refl)\n\nPi∙CompactClosed : CompactClosed Pi∙Monoidal\nPi∙CompactClosed = record { symmetric = Pi∙Symmetric\n ; rigid = inj₁ Pi∙Rigid }\n", "meta": {"hexsha": "1812d3eff3ee73c3d37ba8dc96e38937fe856be2", "size": 4860, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "PiFrac/Category.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "PiFrac/Category.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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": "PiFrac/Category.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 43.0088495575, "max_line_length": 129, "alphanum_fraction": 0.4450617284, "num_tokens": 1548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7718434978390747, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.3768783637618766}} {"text": "data ⊥ : Set where\n\npostulate\n M : Set → Set\n A : Set\n _>>=_ : ∀ {A B} → M A → (A → M B) → M B\n ma : M A\n f : A → M ⊥\n pure : ∀ {A} → A → M A\n\nabsurd-do : ∀ {A} → M A\nabsurd-do = do\n x ← ma\n () ← f x\n\natabsurd-do : ∀ {A} → M A\natabsurd-do = do\n x ← ma\n (y@()) ← f x -- I don't know why you would do that but we can support it\n", "meta": {"hexsha": "5a4ea874412e952b344c06875eac67448b8ccb49", "size": 343, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/absurddo.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/Succeed/absurddo.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/Succeed/absurddo.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": 17.15, "max_line_length": 74, "alphanum_fraction": 0.4606413994, "num_tokens": 155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191214879991, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.37663760323565115}} {"text": "module Reright where\n open import Prelude\n open import Tactic.Reflection.Reright\n open import Agda.Builtin.Reflection -- for better pretty-printing of error messages\n\n -- 'reright' presents the user with changed context variabes, to mimic that done by 'rewrite'.\n simple-reright-test₁ : (A B : Set) (F : Set → Set) → F A → A ≡ B → B → A\n simple-reright-test₁ A B F FA A≡B b = reright A≡B $ λ (FB : F B) → b\n\n -- the target of the reright (in this case x≡y₁) is excluded from the changed context variables\n simple-reright-test₂ : {a : Level} {A : Set a} {x y : A} (x≡y₁ : x ≡ y) (x≡y₂ : x ≡ y) → y ≡ x\n simple-reright-test₂ {y = y} x≡y₁ x≡y₂ = reright x≡y₁ λ (x≡y₂' : y ≡ y) → refl\n\n -- the visibility of context variables remains the same in their changed state\n simple-reright-test₃ : {a : Level} {A : Set a} {x y : A} (x≡y₁ : x ≡ y) (x≡y₂ : x ≡ y) {x≡y₃ : x ≡ y} → y ≡ x\n simple-reright-test₃ {y = y} x≡y₁ x≡y₂ {x≡y₃} = reright x≡y₁ λ (x≡y₂' : y ≡ y) {x≡y₃' : y ≡ y} → refl\n\n -- for some reason, when the first changed variable is hidden, it's impossible to bring it into scope\n {- FAILS - results in unsolved metas\n problematic-visibility : {a : Level} {A : Set a} {x y : A} (x≡y₁ : x ≡ y) {x≡y₃ : x ≡ y} → y ≡ x\n problematic-visibility {y = y} x≡y₁ {x≡y₃} = reright x≡y₁ λ {x≡y₃' : y ≡ y} → refl\n -}\n\n module Test₁ where\n postulate\n Set≡Set : Set ≡ Set\n A₀ : Set\n A₁ : A₀ → Set\n A₂ : (a₀ : A₀) → A₁ a₀ → Set\n A₃ : (a₀ : A₀) → (a₁ : A₁ a₀) → A₂ a₀ a₁ → Set\n B₀ : Set\n B₁ : B₀ → Set\n B₂ : (b₀ : B₀) → B₁ b₀ → Set\n B₃ : (b₀ : B₀) → (b₁ : B₁ b₀) → B₂ b₀ b₁ → Set\n A₀≡B₀ : A₀ ≡ B₀\n F : Set → Set\n C : (α : Level) (β : Level) → Set α → Set β\n 𝑨₀¹ : A₀\n 𝑨₀² : A₀\n 𝑨₀¹≡𝑨₀² : 𝑨₀¹ ≡ 𝑨₀²\n 𝑨₂𝑨₀²⋆ : (a₁𝑨₀² : A₁ 𝑨₀²) → A₂ 𝑨₀² a₁𝑨₀²\n 𝑩₀ : B₀\n K₀ : A₀ → Set\n\n test₀ : (b₀¹ b₀² : B₀) (b₀¹≡b₀² : b₀¹ ≡ b₀²) → Set\n test₀ b₀¹ b₀² b₀¹≡b₀² with b₀¹≡b₀²\n test₀ b₀¹ b₀² b₀¹≡b₀² | b₀¹≡b₀²-with = let b₀¹≡b₀²-let = b₀¹≡b₀²-with in reright b₀¹≡b₀²-let {!!}\n\n test₁ : ∀ (a₀ : A₀) → a₀ ≡ a₀\n test₁ a₀ = id (reright A₀≡B₀ {!!})\n\n test₂ : A₀ → B₀\n test₂ a₀ = reright A₀≡B₀ (λ b₀ → 𝑩₀)\n \n test₃ : A₀ → B₀\n test₃ a₀ = reright Set≡Set (reright A₀≡B₀ (λ b₀ → 𝑩₀))\n \n test₄ : A₀ → B₀\n test₄ a₀ = reright Set≡Set (reright A₀≡B₀ (λ b₀ → reright A₀≡B₀ {!!}))\n \n test₅ : A₀ → B₀\n test₅ a₀ = reright Set≡Set 𝑩₀\n \n test₆ : A₀ → B₀\n test₆ a₀ = reright Set≡Set $ reright A₀≡B₀ $ {!!}\n \n test₇ : ∀ {α : Level}\n (a₀ : A₀)\n {β : Level}\n (X Y : Set (α ⊔ β))\n → X ≡ Y\n → Y ≡ X\n test₇ {α} a₀ {β} X Y X≡Y = id (reright X≡Y {!!})\n \n test₈ : (a₁𝑨₀¹ : A₁ 𝑨₀¹) → A₂ 𝑨₀¹ a₁𝑨₀¹\n test₈ a₁𝑨₀¹ = reright 𝑨₀¹≡𝑨₀² (λ a₁𝑨₀² → {!!})\n \n test₉ : (a₀¹ : A₀) (a₀² : A₀) (a₀¹≡a₀²-1 : a₀¹ ≡ a₀²) (a₁a₀¹ : A₁ a₀¹) (X : Set) (Y : Set) (a₀¹≡a₀²-2 : a₀¹ ≡ a₀²) → F (A₂ a₀¹ a₁a₀¹) → F (A₁ a₀¹) ≡ A₂ a₀¹ a₁a₀¹\n test₉ a₀¹ a₀² a₀¹≡a₀²-1 a₁a₀¹ X Y a₀¹≡a₀²-2 = reright a₀¹≡a₀²-1 {!!}\n \n module _ (A₂⋆ : (a₀ : A₀) (a₁a₀ : A₁ a₀) → A₂ a₀ a₁a₀) where\n test₁₀ : (a₀ : A₀) (a₁a₀¹ : A₁ a₀) (a₁a₀² : A₁ a₀) (a₁a₀¹≡a₁a₀² : a₁a₀¹ ≡ a₁a₀²) → A₂ a₀ a₁a₀¹\n test₁₀ a₀ a₁a₀¹ a₁a₀² a₁a₀¹≡a₁a₀² = reright a₁a₀¹≡a₁a₀² {!!}\n \n test₁₁ : (a₀¹ : A₀) (a₀² : A₀) (FA₁a₀¹≡FA₁a₀² : F (A₁ a₀¹) ≡ F (A₁ a₀²)) → F (A₁ a₀¹) → F (A₁ a₀¹) ≡ F (F (A₁ a₀¹))\n test₁₁ a₀¹ a₀² FA₁a₀¹≡FA₁a₀² = reright FA₁a₀¹≡FA₁a₀² {!!}\n \n test₁₂ : (a₀¹ : A₀) (a₀² : A₀) (FA₁a₀¹≡FA₁a₀² : F (A₁ a₀¹) ≡ F (A₁ a₀²)) → F (A₁ a₀¹) → F (A₁ a₀¹) ≡ F (F (A₁ a₀¹))\n test₁₂ a₀¹ a₀² FA₁a₀¹≡FA₁a₀² FA₁a₀¹ = reright FA₁a₀¹≡FA₁a₀² {!!}\n \n test₁₃ : (β : Level)\n (a₀¹ : A₀)\n (χ : Level)\n (a₀² : A₀)\n (CA₁a₀¹≡CA₁a₀² : C lzero (β ⊔ χ) (A₁ a₀¹) ≡ C lzero (β ⊔ χ) (A₁ a₀²)) →\n C lzero (β ⊔ χ) (A₁ a₀¹)\n → Nat → Σ _ λ γ → C lzero (β ⊔ χ) (A₁ a₀¹) ≡ C γ (β ⊔ χ) (C lzero γ (A₁ a₀¹)) \n test₁₃ β a₀¹ χ a₀² CA₁a₀¹≡CA₁a₀² CA₁a₀¹ = reright CA₁a₀¹≡CA₁a₀² {!!}\n \n test₁₄ : (a₀ : A₀) (FFA₁a₀≡FA₁a₀ : F (F (A₁ a₀)) ≡ F (A₁ a₀)) → F (F (F (F (A₁ a₀))))\n test₁₄ a₀ FFA₁a₀≡FA₁a₀ = reright FFA₁a₀≡FA₁a₀ (reright FFA₁a₀≡FA₁a₀ (reright FFA₁a₀≡FA₁a₀ {!!}))\n \n test₁₅ : (a₀ : A₀) (FA₁a₀≡FFA₁a₀ : F (A₁ a₀) ≡ F (F (A₁ a₀))) → F (F (A₁ a₀))\n test₁₅ a₀ FA₁a₀≡FFA₁a₀ = reright FA₁a₀≡FFA₁a₀ (reright FA₁a₀≡FFA₁a₀ {!!})\n \n test₁₆ : (l : A₀ → Level → Level)\n (β : Level)\n (a₀² : A₀)\n (a₀¹ : A₀)\n (CA₁a₀¹≡CA₁a₀² : C lzero (l a₀¹ β) (A₁ a₀¹) ≡ C lzero (l a₀¹ β) (A₁ a₀²))\n → C lzero (l a₀¹ β) (A₁ a₀¹)\n → Σ _ λ γ → C lzero (l a₀¹ β) (A₁ a₀¹) ≡ C γ (l a₀¹ β) (C lzero γ (A₁ a₀¹))\n test₁₆ l β a₀² a₀¹ CA₁a₀¹≡CA₁a₀² CA₁a₀¹ = reright CA₁a₀¹≡CA₁a₀² {!!}\n \n test₁₇ : (a₀¹ : A₀)\n (a₀² : A₀)\n (K₀a₀¹ : K₀ a₀¹)\n (a₀¹≡a₀² : a₀¹ ≡ a₀²)\n → Set\n test₁₇ a₀¹ a₀² K₀a₀¹ a₀¹≡a₀² = reright a₀¹≡a₀² {!!}\n \n test₁₈ : (a₀¹ : A₀)\n (a₀² : A₀)\n (k₀a₀¹ : K₀ a₀¹)\n (FK₀a₀¹ : F (K₀ a₀¹))\n (K₀a₀¹≡K₀a₀² : K₀ a₀¹ ≡ K₀ a₀²)\n → F (F (K₀ a₀¹)) ≡ F (K₀ a₀²)\n test₁₈ a₀¹ a₀² k₀a₀¹ FK₀a₀¹ K₀a₀¹≡K₀a₀² = reright K₀a₀¹≡K₀a₀² {!!}\n \n test₁₉ : ∀ {a₀¹ : A₀}\n {a₀² : A₀}\n {a₁a₀²-1 a₁a₀²-2 a₁a₀²-3 : A₁ a₀²}\n {a₁a₀²-2=a₁a₀²-3 : A₂ a₀² a₁a₀²-2 ≡ A₂ a₀² a₁a₀²-3}\n (R : ∀ (a₀²' : A₀) → A₂ a₀² a₁a₀²-1 ≡ A₂ a₀² a₁a₀²-2)\n (X : A₂ a₀² a₁a₀²-2 ≡ A₂ a₀² a₁a₀²-3)\n {ignore : Set}\n → A₂ a₀² a₁a₀²-1 ≡ A₂ a₀² a₁a₀²-3\n test₁₉ {a₀¹} {a₀²} {a₁a₀²-1} {a₁a₀²-2} {a₁a₀²-3} {a₁a₀²-2=a₁a₀²-3} R X = reright (R a₀¹) {!!}\n\n {- FAILS (correctly, though perhaps without the most comprehensible of error messages)\n test₂₀' : (f₁ : A₀) (f₂ : A₀) (A₀f₁≡A₀f₂ : A₁ f₁ ≡ A₁ f₂) (g₁ : A₁ f₁) → A₂ f₁ g₁\n test₂₀' f₁ f₂ A₀f₁≡A₀f₂ g₁ rewrite A₀f₁≡A₀f₂ = {!!}\n\n test₂₀ : (f₁ : A₀) (f₂ : A₀) (A₀f₁≡A₀f₂ : A₁ f₁ ≡ A₁ f₂) (g₁ : A₁ f₁) → A₂ f₁ g₁\n test₂₀ f₁ f₂ A₀f₁≡A₀f₂ g₁ = reright A₀f₁≡A₀f₂ {!!}\n -}\n \n test₂₀ : ∀ {a b : Level} {A : Set a} {x y : A} (x≡y : x ≡ y) → Set\n test₂₀ x≡y = reright x≡y {!!}\n\n test₂₁ : ∀ {a b : Level} {A : Set a} {x y : A} (B : Set b) (x≡y : x ≡ y) → Set\n test₂₁ B x≡y = reright x≡y {!!}\n\n test₂₂ : ∀ {a : Level} {A : Set a} {B : Set} {x : B} {y : B} (x≡y : x ≡ y) → Set\n test₂₂ x≡y = reright x≡y {!!}\n\n module _ (l : Level) where\n postulate P : Set\n \n test₂₃ : (p : P)\n (A : Set)\n (x y : A)\n (x≡y : x ≡ y)\n → Set\n test₂₃ _ _ _ _ x≡y = reright x≡y ?\n\n module Test₂ where\n record Map \n {K : Set}\n (V : K → Set)\n (Carrier : Nat → Set) {{isDecEquivalence/K : Eq K}} {{isDecEquivalence/V : (k : K) → Eq (V k)}} : Set₁ where\n field\n ∅ : Carrier 0\n _∉_ : ∀ {s} → K → Carrier s → Set\n ∅-is-empty : ∀ {𝑘} {∅ : Carrier 0} → 𝑘 ∉ ∅\n \n _∈_ : ∀ {s} → K → Carrier s → Set\n _∈_ k m = ¬ k ∉ m\n \n field\n get : ∀ {k : K} {s} {m : Carrier s} → k ∈ m → V k\n put : ∀ {k₀ : K} (v₀ : V k₀) {s₁} {m₁ : Carrier s₁} → k₀ ∉ m₁ → Σ _ λ (m₀ : Carrier (suc s₁)) → Σ _ λ (k₀∈m₀ : k₀ ∈ m₀) → get k₀∈m₀ ≡ v₀\n \n postulate\n A : Set\n \n V : A → Set\n V = λ _ → Nat\n \n postulate\n M : Nat → Set\n isDecEquivalence/A : Eq A\n isDecEquivalence/V : (a : A) → Eq (V a)\n \n postulate\n m : Map V M {{isDecEquivalence/A}} {{isDecEquivalence/V}}\n \n open Map m\n \n test₁ : (v : Nat) (k : A)\n → (k∈putkv∅ : k ∈ (fst $ put {k₀ = k} v {m₁ = ∅} ∅-is-empty))\n → Set\n test₁ v k k∈putkv∅ = let p = (put {k₀ = k} v {m₁ = ∅} ∅-is-empty) in let r = sym (snd $ snd p) in reright r {!!}\n\n{- expected.out\n?0 : b₀² ≡ b₀² → Set\n?1 : (b : B₀) → b ≡ b\n?2 : B₀ → B₀\n?3 : B₀ → B₀\n?4 : Y ≡ Y\n?5 : A₂ 𝑨₀² a₁𝑨₀²\n?6 : (a₁ : A₁ a₀²) → a₀² ≡ a₀² → F (A₂ a₀² a₁) → F (A₁ a₀²) ≡ A₂ a₀² a₁\n?7 : A₂ a₀ a₁a₀²\n?8 : F (A₁ a₀²) → F (A₁ a₀²) ≡ F (F (A₁ a₀²))\n?9 : F (A₁ a₀²) → F (A₁ a₀²) ≡ F (F (A₁ a₀²))\n?10 : C lzero (χ ⊔ β) (A₁ a₀²) →\nNat →\nΣ Level\n(λ γ → C lzero (χ ⊔ β) (A₁ a₀²) ≡ C γ (χ ⊔ β) (C lzero γ (A₁ a₀¹)))\n?11 : F (A₁ a₀)\n?12 : F (F (F (F (A₁ a₀))))\n?13 : C lzero (l a₀¹ β) (A₁ a₀²) →\nΣ Level\n(λ γ →\n C lzero (l a₀¹ β) (A₁ a₀²) ≡ C γ (l a₀¹ β) (C lzero γ (A₁ a₀¹)))\n?14 : K₀ a₀² → Set\n?15 : K₀ a₀² → F (K₀ a₀²) → F (F (K₀ a₀²)) ≡ F (K₀ a₀²)\n?16 : (A₀ → A₂ a₀² a₁a₀²-2 ≡ A₂ a₀² a₁a₀²-2) →\nA₂ a₀² a₁a₀²-2 ≡ A₂ a₀² a₁a₀²-3\n?17 : Set\n?18 : Set\n?19 : Set\n?20 : Set\n?21 : (k ∉ fst (put (get (fst (snd (put v ∅-is-empty)))) ∅-is-empty) →\n ⊥) →\nSet\n-}\n", "meta": {"hexsha": "16c38c4bf77ec07f0bde0a997b443e92f6f90933", "size": 8722, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Reright.agda", "max_stars_repo_name": "L-TChen/agda-prelude", "max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 111, "max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z", "max_issues_repo_path": "test/Reright.agda", "max_issues_repo_name": "L-TChen/agda-prelude", "max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 59, "max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z", "max_forks_repo_path": "test/Reright.agda", "max_forks_repo_name": "L-TChen/agda-prelude", "max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 24, "max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z", "avg_line_length": 36.6470588235, "max_line_length": 165, "alphanum_fraction": 0.4930061912, "num_tokens": 4622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191214879991, "lm_q2_score": 0.5312093733737562, "lm_q1q2_score": 0.3766376032356511}} {"text": "module list-simplifier where\n\nopen import level\nopen import bool\nopen import functions\nopen import eq\nopen import empty\nopen import level\nopen import list\nopen import list-thms\nopen import nat\nopen import neq\nopen import product\nopen import product-thms\n\ndata 𝕃ʳ : Set → Set lone where\n _ʳ : {A : Set} → 𝕃 A → 𝕃ʳ A\n _++ʳ_ : {A : Set} → 𝕃ʳ A → 𝕃ʳ A → 𝕃ʳ A\n mapʳ : {A B : Set} → (A → B) → 𝕃ʳ A → 𝕃ʳ B\n _::ʳ_ : {A : Set} → A → 𝕃ʳ A → 𝕃ʳ A\n []ʳ : {A : Set} → 𝕃ʳ A\n\n𝕃⟦_⟧ : {A : Set} → 𝕃ʳ A → 𝕃 A\n𝕃⟦ l ʳ ⟧ = l\n𝕃⟦ t1 ++ʳ t2 ⟧ = 𝕃⟦ t1 ⟧ ++ 𝕃⟦ t2 ⟧\n𝕃⟦ mapʳ f t ⟧ = map f 𝕃⟦ t ⟧ \n𝕃⟦ x ::ʳ t ⟧ = x :: 𝕃⟦ t ⟧ \n𝕃⟦ []ʳ ⟧ = []\n\nis-emptyʳ : {A : Set} → 𝕃ʳ A → 𝔹\nis-emptyʳ []ʳ = tt\nis-emptyʳ _ = ff\n\nis-emptyʳ-≡ : {A : Set}(t : 𝕃ʳ A) → is-emptyʳ t ≡ tt → t ≡ []ʳ \nis-emptyʳ-≡ []ʳ p = refl\nis-emptyʳ-≡ (_ ++ʳ _) ()\nis-emptyʳ-≡ (mapʳ _ _) ()\nis-emptyʳ-≡ (_ ::ʳ _) ()\nis-emptyʳ-≡ (_ ʳ) ()\n\n𝕃ʳ-simp-step : {A : Set}(t : 𝕃ʳ A) → 𝕃ʳ A\n𝕃ʳ-simp-step ((t1a ++ʳ t1b) ++ʳ t2) = t1a ++ʳ (t1b ++ʳ t2) \n𝕃ʳ-simp-step ((x ::ʳ t1) ++ʳ t2) = x ::ʳ (t1 ++ʳ t2) \n𝕃ʳ-simp-step ([]ʳ ++ʳ t2) = t2 \n𝕃ʳ-simp-step ((l ʳ) ++ʳ t2) = \n if is-emptyʳ t2 then l ʳ else ((l ʳ) ++ʳ t2)\n𝕃ʳ-simp-step ((mapʳ f t1) ++ʳ t2) = \n if is-emptyʳ t2 then mapʳ f t1 else ((mapʳ f t1) ++ʳ t2)\n𝕃ʳ-simp-step (mapʳ f (t1 ++ʳ t2)) = (mapʳ f t1) ++ʳ (mapʳ f t2) \n𝕃ʳ-simp-step (mapʳ f (l ʳ)) = (map f l) ʳ \n𝕃ʳ-simp-step (mapʳ f (mapʳ g t)) = mapʳ (f ∘ g) t \n𝕃ʳ-simp-step (mapʳ f (x ::ʳ t)) = (f x) ::ʳ (mapʳ f t)\n𝕃ʳ-simp-step (mapʳ f []ʳ) = []ʳ \n𝕃ʳ-simp-step (l ʳ) = l ʳ \n𝕃ʳ-simp-step (x ::ʳ t) = (x ::ʳ t)\n𝕃ʳ-simp-step []ʳ = []ʳ \n\n𝕃ʳ-simp-sdev : {A : Set}(t : 𝕃ʳ A) → 𝕃ʳ A\n𝕃ʳ-simp-sdev (l ʳ) = (l ʳ)\n𝕃ʳ-simp-sdev (t1 ++ʳ t2) = 𝕃ʳ-simp-step ((𝕃ʳ-simp-sdev t1) ++ʳ (𝕃ʳ-simp-sdev t2))\n𝕃ʳ-simp-sdev (mapʳ f t1) = 𝕃ʳ-simp-step (mapʳ f (𝕃ʳ-simp-sdev t1))\n𝕃ʳ-simp-sdev (x ::ʳ t1) = 𝕃ʳ-simp-step (x ::ʳ (𝕃ʳ-simp-sdev t1))\n𝕃ʳ-simp-sdev []ʳ = []ʳ \n\n𝕃ʳ-simp : {A : Set}(t : 𝕃ʳ A) → ℕ → 𝕃ʳ A\n𝕃ʳ-simp t 0 = t\n𝕃ʳ-simp t (suc n) = 𝕃ʳ-simp-sdev (𝕃ʳ-simp t n)\n\n𝕃ʳ-simp-step-sound : {A : Set}(t : 𝕃ʳ A) → 𝕃⟦ t ⟧ ≡ 𝕃⟦ 𝕃ʳ-simp-step t ⟧\n𝕃ʳ-simp-step-sound ((t1a ++ʳ t1b) ++ʳ t2) = ++-assoc 𝕃⟦ t1a ⟧ 𝕃⟦ t1b ⟧ 𝕃⟦ t2 ⟧\n𝕃ʳ-simp-step-sound ((x ::ʳ t1) ++ʳ t2) = refl\n𝕃ʳ-simp-step-sound ([]ʳ ++ʳ t2) = refl\n𝕃ʳ-simp-step-sound ((l ʳ) ++ʳ t2) with keep (is-emptyʳ t2)\n𝕃ʳ-simp-step-sound ((l ʳ) ++ʳ t2) | tt , p rewrite p | is-emptyʳ-≡ t2 p | ++[] l = refl\n𝕃ʳ-simp-step-sound ((l ʳ) ++ʳ t2) | ff , p rewrite p = refl\n𝕃ʳ-simp-step-sound ((mapʳ f t1) ++ʳ t2) with keep (is-emptyʳ t2)\n𝕃ʳ-simp-step-sound ((mapʳ f t1) ++ʳ t2) | tt , p rewrite p | is-emptyʳ-≡ t2 p | ++[] (map f 𝕃⟦ t1 ⟧) = refl\n𝕃ʳ-simp-step-sound ((mapʳ f t1) ++ʳ t2) | ff , p rewrite p = refl\n𝕃ʳ-simp-step-sound (l ʳ) = refl\n𝕃ʳ-simp-step-sound (mapʳ f (t1 ++ʳ t2)) = map-append f 𝕃⟦ t1 ⟧ 𝕃⟦ t2 ⟧\n𝕃ʳ-simp-step-sound (mapʳ f (l ʳ)) = refl\n𝕃ʳ-simp-step-sound (mapʳ f (mapʳ g t)) = map-compose f g 𝕃⟦ t ⟧\n𝕃ʳ-simp-step-sound (mapʳ f (x ::ʳ t)) = refl\n𝕃ʳ-simp-step-sound (mapʳ f []ʳ) = refl\n𝕃ʳ-simp-step-sound (x ::ʳ t) = refl\n𝕃ʳ-simp-step-sound []ʳ = refl\n\n𝕃ʳ-simp-sdev-sound : {A : Set}(t : 𝕃ʳ A) → 𝕃⟦ t ⟧ ≡ 𝕃⟦ 𝕃ʳ-simp-sdev t ⟧\n𝕃ʳ-simp-sdev-sound (l ʳ) = refl\n𝕃ʳ-simp-sdev-sound (t1 ++ʳ t2) \n rewrite sym (𝕃ʳ-simp-step-sound ((𝕃ʳ-simp-sdev t1) ++ʳ (𝕃ʳ-simp-sdev t2))) | 𝕃ʳ-simp-sdev-sound t1 | 𝕃ʳ-simp-sdev-sound t2 = refl\n𝕃ʳ-simp-sdev-sound (mapʳ f t1)\n rewrite sym (𝕃ʳ-simp-step-sound (mapʳ f (𝕃ʳ-simp-sdev t1))) | 𝕃ʳ-simp-sdev-sound t1 = refl\n𝕃ʳ-simp-sdev-sound (x ::ʳ t1) rewrite 𝕃ʳ-simp-sdev-sound t1 = refl\n𝕃ʳ-simp-sdev-sound []ʳ = refl\n\n𝕃ʳ-simp-sound : {A : Set}(t : 𝕃ʳ A)(n : ℕ) → 𝕃⟦ t ⟧ ≡ 𝕃⟦ 𝕃ʳ-simp t n ⟧\n𝕃ʳ-simp-sound t 0 = refl\n𝕃ʳ-simp-sound t (suc n) rewrite sym (𝕃ʳ-simp-sdev-sound (𝕃ʳ-simp t n)) = 𝕃ʳ-simp-sound t n\n\nmodule test1 {A B : Set}(f : A → B)(l1 l2 : 𝕃 A) where\n\n lhs = (mapʳ f (l1 ʳ)) ++ʳ (mapʳ f (l2 ʳ))\n\n rhs = mapʳ f ((l1 ʳ) ++ʳ (l2 ʳ))\n\n test-tp : Set\n test-tp = 𝕃⟦ lhs ⟧ ≡ 𝕃⟦ rhs ⟧\n\n test : test-tp\n test rewrite (𝕃ʳ-simp-sdev-sound rhs) = refl\n\nmodule test2 {A B : Set}(f : A → B)(l1 l2 l3 : 𝕃 A) where\n\n lhs = mapʳ f (((l1 ʳ) ++ʳ (l2 ʳ)) ++ʳ (l3 ʳ))\n\n rhs = 𝕃ʳ-simp lhs 3\n\n test-tp : Set\n test-tp = 𝕃⟦ lhs ⟧ ≡ 𝕃⟦ rhs ⟧\n\n test : test-tp\n test = 𝕃ʳ-simp-sound lhs 3\n\n one-step : 𝕃ʳ B\n one-step = 𝕃ʳ-simp-step lhs\n\n sdev : 𝕃ʳ B\n sdev = 𝕃ʳ-simp-sdev lhs\n\n\n", "meta": {"hexsha": "a93a5272a5108752fcde21adb43e7360e9b65663", "size": 4271, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "list-simplifier.agda", "max_stars_repo_name": "rfindler/ial", "max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z", "max_issues_repo_path": "list-simplifier.agda", "max_issues_repo_name": "rfindler/ial", "max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z", "max_forks_repo_path": "list-simplifier.agda", "max_forks_repo_name": "rfindler/ial", "max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z", "avg_line_length": 32.3560606061, "max_line_length": 131, "alphanum_fraction": 0.5645047998, "num_tokens": 2583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768248, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.37658556412316274}} {"text": "module New.LangChanges where\n\nopen import New.Lang public\nopen import New.Changes\n\nisChAlgτ : (τ : Type) → IsChAlg ⟦ τ ⟧Type ⟦ Δt τ ⟧Type\n\nChτ : (τ : Type) → Set\nChτ τ = ⟦ Δt τ ⟧Type\n\nchAlgt : (τ : Type) → ChAlg ⟦ τ ⟧Type\nchAlgt τ = record { Ch = Chτ τ ; isChAlg = isChAlgτ τ}\n\ninstance\n ichAlgt : ∀ {τ} → ChAlg ⟦ τ ⟧Type\n ichAlgt {τ} = chAlgt τ\n\nisChAlgτ (σ ⇒ τ) = isChAlg {{funCA {{chAlgt σ}} {{chAlgt τ}}}}\nisChAlgτ int = isChAlg {{intCA}}\nisChAlgτ (pair σ τ) = isChAlg {{pairCA {{chAlgt σ}} {{chAlgt τ}}}}\nisChAlgτ (sum σ τ) = isChAlg {{sumCA {{chAlgt σ}} {{chAlgt τ}}}}\n\nΔΓ : Context → Context\nΔΓ ∅ = ∅\nΔΓ (τ • Γ) = Δt τ • τ • ΔΓ Γ\n\nmodule _ where\n ChΓ : ∀ (Γ : Context) → Set\n ChΓ Γ = ⟦ ΔΓ Γ ⟧Context\n\n _e⊕_ : ∀ {Γ} → ⟦ Γ ⟧Context → ChΓ Γ → ⟦ Γ ⟧Context\n _e⊕_ ∅ ∅ = ∅\n _e⊕_ (v • ρ) (dv • _ • dρ) = v ⊕ dv • ρ e⊕ dρ\n _e⊝_ : ∀ {Γ} → ⟦ Γ ⟧Context → ⟦ Γ ⟧Context → ChΓ Γ\n _e⊝_ ∅ ∅ = ∅\n _e⊝_ (v₂ • ρ₂) (v₁ • ρ₁) = v₂ ⊝ v₁ • v₁ • ρ₂ e⊝ ρ₁\n\n validΓ : ∀ {Γ} → ⟦ Γ ⟧Context → ChΓ Γ → Set\n validΓ ∅ ∅ = ⊤\n validΓ (v • ρ) (dv • v′ • dρ) = valid v dv × v ≡ v′ × validΓ ρ dρ\n\n e⊝-valid : ∀ {Γ} → (ρ1 ρ2 : ⟦ Γ ⟧Context) → validΓ ρ1 (ρ2 e⊝ ρ1)\n e⊝-valid ∅ ∅ = tt\n e⊝-valid (v₁ • ρ₁) (v₂ • ρ₂) = ⊝-valid v₁ v₂ , refl , e⊝-valid ρ₁ ρ₂\n e⊕-⊝ : ∀ {Γ} → (ρ2 ρ1 : ⟦ Γ ⟧Context) → ρ1 e⊕ (ρ2 e⊝ ρ1) ≡ ρ2\n e⊕-⊝ ∅ ∅ = refl\n e⊕-⊝ (v₂ • ρ₂) (v₁ • ρ₁) = cong₂ _•_ (⊕-⊝ v₂ v₁) (e⊕-⊝ ρ₂ ρ₁)\n\n {-# TERMINATING #-}\n isEnvCA : ∀ Γ → IsChAlg ⟦ Γ ⟧Context (ChΓ Γ)\n\n e⊚-valid : ∀ {Γ} → (ρ : ⟦ Γ ⟧Context) (dρ1 : ChΓ Γ) →\n validΓ ρ dρ1 →\n (dρ2 : ChΓ Γ) →\n validΓ (ρ e⊕ dρ1) dρ2 →\n validΓ ρ (IsChAlg.default-⊚ (isEnvCA Γ) dρ1 ρ dρ2)\n e⊚-correct : ∀ {Γ} → (ρ : ⟦ Γ ⟧Context) (dρ1 : ChΓ Γ) →\n validΓ ρ dρ1 →\n (dρ2 : ChΓ Γ) →\n validΓ (ρ e⊕ dρ1) dρ2 →\n (ρ e⊕ IsChAlg.default-⊚ (isEnvCA Γ) dρ1 ρ dρ2) ≡\n ((ρ e⊕ dρ1) e⊕ dρ2)\n\n isEnvCA Γ = record\n { _⊕_ = _e⊕_\n ; _⊝_ = _e⊝_\n ; valid = validΓ\n ; ⊝-valid = e⊝-valid\n ; ⊕-⊝ = e⊕-⊝\n ; _⊚[_]_ = IsChAlg.default-⊚ (isEnvCA Γ)\n ; ⊚-valid = e⊚-valid\n ; ⊚-correct = e⊚-correct\n }\n e⊚-valid {Γ} = IsChAlg.default-⊚-valid (isEnvCA Γ)\n e⊚-correct {Γ} = IsChAlg.default-⊚-correct (isEnvCA Γ)\n\n envCA : ∀ Γ → ChAlg ⟦ Γ ⟧Context\n envCA Γ = record\n { Ch = ChΓ Γ\n ; isChAlg = isEnvCA Γ }\n\ninstance\n ienvCA : ∀ {Γ} → ChAlg ⟦ Γ ⟧Context\n ienvCA {Γ} = envCA Γ\n", "meta": {"hexsha": "e5abf85cf03d92611b3278a79324e4593fadcf97", "size": 2360, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "New/LangChanges.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": "New/LangChanges.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": "New/LangChanges.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": 27.7647058824, "max_line_length": 70, "alphanum_fraction": 0.5076271186, "num_tokens": 1346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.72487026428967, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.3765855579475324}} {"text": "-- An implementation of Olivier Danvy's Type-Directed Partial Evaluation (POPL 1996)\n-- for STLC with sum types using continuations in form of shift and reset.\n--\n-- The algorithm was originally for a two-level lambda-calculus.\n\n-- Our use of Kripke semantics makes the effect of fresh variable generation explicit and formal.\n\n\nopen import Library\n\nmodule DanvyShiftReset where\n\ndata Base : Set where\n α β : Base\n\n-- import Formulas ; open module Form = Formulas Base\n-- import Derivations; open module Der = Derivations Base\nopen import Formulas Base\nopen import Derivations Base\n\n-- -- Shift-reset continutation monad\n\n-- record M (A B C : Set) : Set where\n-- field run : (C → B) → A\n-- open M\n\n-- return : ∀{X A} → A → M X X A\n-- return x .run k = k x\n\n-- _>>=_ : ∀{X Y Z A B} (m : M X Y A) (f : A → M Y Z B) → M X Z B\n-- (m >>= f) .run k = m .run λ a → f a .run k\n\n-- _<$>_ : ∀{X Y A B} (f : A → B) (m : M X Y A) → M X Y B\n-- (f <$> m) .run k = m .run (k ∘ f)\n\n-- shift : ∀{X Y A} (f : (A → Y) → M X Y Y) → M X Y A\n-- shift f .run k = f k .run id\n\n-- shift' : ∀{X Y A} (f : (A → Y) → X) → M X Y A\n-- shift' f .run k = f k\n\n-- reset : ∀{X Y A} (m : M A Y Y) → M X X A\n-- reset m .run k = k (m .run id)\n\n-- Shift-reset continutation monad\n\nrecord M (A B C : Cxt → Set) (Γ : Cxt) : Set where\n field run : KFun (KFun C B) A Γ\nopen M\n\nreturn : ∀{X A} → □ A →̇ M X X A\nreturn x .run τ k = k id≤ (x τ)\n\nreturn' : ∀{X A} → □ A →̇ M X X (□ A)\nreturn' x .run τ k = k id≤ λ τ₁ → x (τ₁ • τ)\n\n_>>=_ : ∀{X Y Z A B Γ} (m : M X Y A Γ) (f : KFun A (M Y Z B) Γ) → M X Z B Γ\n(m >>= f) .run σ k = m .run σ λ τ a → f (τ • σ) a .run id≤ λ τ′ → k (τ′ • τ)\n\n_<$>_ : ∀{X Y A B} (f : A →̇ B) → M X Y A →̇ M X Y B\n(f <$> m) .run σ k = m .run σ λ τ → k τ ∘ f\n\n-- liftA2 : ∀{X Y A B C} (f : ∀{Γ} → A Γ → B Γ → C Γ) → ∀{Γ} → M X Y A Γ → M X Y B Γ → M X Y C Γ\n-- liftA2 f ma mb .run σ k = ma .run σ λ τ a → {!mb .run!}\n\nK$ : ∀{X Y A B} → KFun A B →̇ KFun (M X Y A) (M X Y B)\nK$ f τ m .run σ k = m .run σ λ τ′ a → k τ′ (f (τ′ • (σ • τ)) a)\n\nshift' : ∀{X Y A Γ} (f : KFun (KFun A Y) X Γ) → M X Y A Γ\nshift' f .run σ k = f σ k\n\nshift : ∀{X Y A Γ} (f : KFun (KFun A Y) (M X Y Y) Γ) → M X Y A Γ\nshift f .run σ k = f σ k .run id≤ λ τ → id\n\nreset' : ∀{Y A} → M A Y Y →̇ A\nreset' m = m .run id≤ λ τ → id\n\nreset : ∀{X Y A} → M A Y Y →̇ M X X A\nreset m .run σ k = k id≤ (m .run σ λ τ → id)\n\n-- We use a continuation monad with answer type Nf.\n\nM' : (X : Cxt → Set) (Γ : Cxt) → Set\nM' X Γ = ∀ {C} → M (Nf' C) (Nf' C) X Γ\n\nT⟦_⟧ : (A : Form) (Γ : Cxt) → Set\nT⟦ Atom P ⟧ = Nf' (Atom P)\nT⟦ True ⟧ Γ = ⊤\nT⟦ False ⟧ Γ = ⊥\nT⟦ A ∨ B ⟧ Γ = T⟦ A ⟧ Γ ⊎ T⟦ B ⟧ Γ\nT⟦ A ∧ B ⟧ Γ = T⟦ A ⟧ Γ × T⟦ B ⟧ Γ\nT⟦ A ⇒ B ⟧ Γ = ∀{Δ} (τ : Δ ≤ Γ) → T⟦ A ⟧ Δ → M' T⟦ B ⟧ Δ\n\n-- Monotonicity of the model is proven by induction on the proposition.\n\n-- monT : ∀ A {Γ Δ} (τ : Δ ≤ Γ) → T⟦ A ⟧ Γ → T⟦ A ⟧ Δ\n\nmonT : ∀ A → Mon T⟦ A ⟧\nmonT (Atom P) = monNf\nmonT True = _\nmonT False τ ()\nmonT (A ∨ B) τ = map-⊎ (monT A τ) (monT B τ)\nmonT (A ∧ B) τ (a , b) = monT A τ a , monT B τ b\nmonT (A ⇒ B) τ f σ = f (σ • τ)\n\n\n-- Reflection / reification, proven simultaneously by induction on the proposition.\n\n-- Reflection is η-expansion (and recursively reflection);\n\nmutual\n\n reflect : ∀{Γ} A (t : Ne Γ A) → M' T⟦ A ⟧ Γ\n reflect (Atom P) t = return λ τ → ne (monNe τ t)\n reflect True t = return _\n reflect False t = shift' λ τ k → falseE (monNe τ t)\n reflect (A ∨ B) t = shift' λ τ k → orE (monNe τ t)\n (reset' (K$ k (weak id≤) (inj₁ <$> reflect A (hyp top))))\n (reset' (K$ k (weak id≤) (inj₂ <$> reflect B (hyp top))))\n\n -- ((inj₂ <$> reflect B (hyp top)) .run λ τ → k (τ • weak id≤))\n -- Wrong:\n -- (reset' (k (weak id≤) <$> (inj₁ <$> reflect A (hyp top))))\n\n -- reflect (A ∧ B) t = do\n -- a ← reflect A (andE₁ t)\n -- b ← reflect B (andE₂ t)\n -- return (a , b)\n\n reflect (A ∧ B) t =\n reflect A (andE₁ t ) >>= λ τ a →\n reflect B (andE₂ (monNe τ t)) >>= λ τ′ b →\n return λ τ₁ → monT A (τ₁ • τ′) a , monT B τ₁ b\n\n reflect (A ⇒ B) t = return' λ τ a → reflect B (impE (monNe τ t) (reify A a))\n\n\n reify : ∀{Γ} A (⟦f⟧ : T⟦ A ⟧ Γ) → Nf Γ A\n\n reify (Atom P) t = t\n reify True _ = trueI\n reify False ()\n reify (A ∨ B) (inj₁ a) = orI₁ (reify A a)\n reify (A ∨ B) (inj₂ b) = orI₂ (reify B b)\n reify (A ∧ B) (a , b) = andI (reify A a) (reify B b)\n\n reify (A ⇒ B) f = impI $ reset' $\n reflect A (hyp top) >>= λ τ a →\n reify B <$> f (τ • weak id≤) a\n\n\n-- Fundamental theorem\n\n-- Extension of T⟦_⟧ to contexts\n\nG⟦_⟧ : ∀ (Γ Δ : Cxt) → Set\nG⟦ ε ⟧ Δ = ⊤\nG⟦ Γ ∙ A ⟧ Δ = G⟦ Γ ⟧ Δ × T⟦ A ⟧ Δ\n\n-- monG : ∀{Γ Δ Φ} (τ : Φ ≤ Δ) → G⟦ Γ ⟧ Δ → G⟦ Γ ⟧ Φ\n\nmonG : ∀{Γ} → Mon G⟦ Γ ⟧\nmonG {ε} τ _ = _\nmonG {Γ ∙ A} τ (γ , a) = monG τ γ , monT A τ a\n\n-- Variable case.\n\nfundH : ∀{Γ Δ A} (x : Hyp A Γ) (γ : G⟦ Γ ⟧ Δ) → T⟦ A ⟧ Δ\nfundH top = proj₂\nfundH (pop x) = fundH x ∘ proj₁\n\n-- The fundamental theorem:\n-- A call-by-value interpreter.\n\nfund : ∀{Γ A} (t : Γ ⊢ A) {Δ} (γ : G⟦ Γ ⟧ Δ) → M' T⟦ A ⟧ Δ\n\nfund (hyp {A} x) γ = return λ τ → monT A τ (fundH x γ)\nfund (impI t) γ = return' λ τ a → fund t (monG τ γ , a)\n\nfund (impE t u) γ =\n fund t γ >>= λ τ f →\n fund u (monG τ γ) >>= λ τ′ a →\n f τ′ a\n\nfund (andI {A} {B} t u) γ =\n fund t γ >>= λ τ a →\n fund u (monG τ γ) >>= λ τ′ b →\n return λ τ₁ → monT A (τ₁ • τ′) a , monT B τ₁ b\n\nfund (andE₁ t) γ = proj₁ <$> fund t γ\nfund (andE₂ t) γ = proj₂ <$> fund t γ\nfund (orI₁ t) γ = inj₁ <$> fund t γ\nfund (orI₂ t) γ = inj₂ <$> fund t γ\n\nfund (orE t u v) γ = fund t γ >>= λ τ →\n [ (λ a → fund u (monG τ γ , a))\n , (λ b → fund v (monG τ γ , b))\n ]\n\nfund (falseE t) γ = fund t γ >>= λ τ ()\nfund trueI γ = return _\n\n-- Identity environment\n\nide : ∀ Γ → □ (M' G⟦ Γ ⟧) Γ\nide ε τ = return _\nide (Γ ∙ A) τ =\n ide Γ (τ • weak id≤) >>= λ τ₁ γ →\n reflect A (monNe (τ₁ • τ) (hyp top)) >>= λ τ₂ a →\n return λ τ₃ → monG (τ₃ • τ₂) γ , monT A τ₃ a\n\n-- Normalization\n\nnorm : ∀{A Γ} (t : Γ ⊢ A) → Nf Γ A\nnorm {A} {Γ} t = reset' $\n ide Γ id≤ >>= λ _ γ →\n reify A <$> fund t γ\n\nidD : (A : Form) → ε ⊢ (A ⇒ A)\nidD A = impI (hyp top)\n\ntest : let A = Atom α; B = Atom β in Nf ε (A ∨ B ⇒ A ∨ B)\ntest = norm (idD (Atom α ∨ Atom β))\n\ntest2 = norm (idD (Atom α ∨ Atom β ∨ Atom α))\n\n-- Q.E.D. -}\n-- -}\n-- -}\n-- -}\n-- -}\n-- -}\n-- -}\n", "meta": {"hexsha": "ea73b62a4b527ca533319e2c578da780fc560e15", "size": 6324, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/DanvyShiftReset.agda", "max_stars_repo_name": "andreasabel/ipl", "max_stars_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2018-05-16T08:08:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T19:10:49.000Z", "max_issues_repo_path": "src/DanvyShiftReset.agda", "max_issues_repo_name": "andreasabel/ipl", "max_issues_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_issues_repo_licenses": ["Unlicense"], "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/DanvyShiftReset.agda", "max_forks_repo_name": "andreasabel/ipl", "max_forks_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-11-13T16:01:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-25T20:39:03.000Z", "avg_line_length": 27.0256410256, "max_line_length": 97, "alphanum_fraction": 0.4922517394, "num_tokens": 2835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6791787121629465, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3765845363242131}} {"text": "------------------------------------------------------------------------------\n-- Properties related with the forest type\n------------------------------------------------------------------------------\n\n{-# OPTIONS --exact-split #-}\n{-# OPTIONS --no-sized-types #-}\n{-# OPTIONS --no-universe-polymorphism #-}\n{-# OPTIONS --without-K #-}\n\nmodule FOTC.Program.Mirror.Forest.PropertiesI where\n\nopen import Common.FOL.Relation.Binary.EqReasoning\n\nopen import FOTC.Base\nopen import FOTC.Base.List\nopen import FOTC.Base.List.PropertiesI\nopen import FOTC.Data.List\nopen import FOTC.Data.List.PropertiesI\n using ( ++-leftCong\n ; ++-leftIdentity\n ; ++-rightCong\n ; mapCong₂\n ; revCong₁\n ; reverseCong\n ; reverse-[x]≡[x]\n )\nopen import FOTC.Program.Mirror.Forest.TotalityI\nopen import FOTC.Program.Mirror.Type\n\n------------------------------------------------------------------------------\n\n++-rightIdentity : ∀ {xs} → Forest xs → xs ++ [] ≡ xs\n++-rightIdentity fnil = ++-leftIdentity []\n++-rightIdentity (fcons {x} {xs} Tx Fxs) =\n (x ∷ xs) ++ []\n ≡⟨ ++-∷ x xs [] ⟩\n x ∷ (xs ++ [])\n ≡⟨ ∷-rightCong (++-rightIdentity Fxs) ⟩\n x ∷ xs ∎\n\n++-assoc : ∀ {xs} → Forest xs → ∀ ys zs → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs)\n++-assoc fnil ys zs =\n ([] ++ ys) ++ zs\n ≡⟨ ++-leftCong (++-leftIdentity ys) ⟩\n ys ++ zs\n ≡⟨ sym (++-leftIdentity (ys ++ zs)) ⟩\n [] ++ ys ++ zs ∎\n\n++-assoc (fcons {x} {xs} Tx Fxs) ys zs =\n ((x ∷ xs) ++ ys) ++ zs\n ≡⟨ ++-leftCong (++-∷ x xs ys) ⟩\n (x ∷ (xs ++ ys)) ++ zs\n ≡⟨ ++-∷ x (xs ++ ys) zs ⟩\n x ∷ ((xs ++ ys) ++ zs)\n ≡⟨ ∷-rightCong (++-assoc Fxs ys zs) ⟩\n x ∷ (xs ++ ys ++ zs)\n ≡⟨ sym (++-∷ x xs (ys ++ zs)) ⟩\n (x ∷ xs) ++ ys ++ zs ∎\n\nmap-++ : ∀ f {xs} → (∀ {x} → Tree x → Tree (f · x)) →\n Forest xs →\n ∀ ys → map f (xs ++ ys) ≡ map f xs ++ map f ys\nmap-++ f h fnil ys =\n map f ([] ++ ys)\n ≡⟨ mapCong₂ (++-leftIdentity ys) ⟩\n map f ys\n ≡⟨ sym (++-leftIdentity (map f ys)) ⟩\n [] ++ map f ys\n ≡⟨ ++-leftCong (sym (map-[] f)) ⟩\n map f [] ++ map f ys ∎\n\nmap-++ f h (fcons {x} {xs} Tx Fxs) ys =\n map f ((x ∷ xs) ++ ys)\n ≡⟨ mapCong₂ (++-∷ x xs ys) ⟩\n map f (x ∷ xs ++ ys)\n ≡⟨ map-∷ f x (xs ++ ys) ⟩\n f · x ∷ map f (xs ++ ys)\n ≡⟨ ∷-rightCong (map-++ f h Fxs ys) ⟩\n f · x ∷ (map f xs ++ map f ys)\n ≡⟨ sym (++-∷ (f · x) (map f xs) (map f ys)) ⟩\n (f · x ∷ map f xs) ++ map f ys\n ≡⟨ ++-leftCong (sym (map-∷ f x xs)) ⟩\n map f (x ∷ xs) ++ map f ys ∎\n\nrev-++ : ∀ {xs} → Forest xs → ∀ ys → rev xs ys ≡ rev xs [] ++ ys\nrev-++ fnil ys =\n rev [] ys ≡⟨ rev-[] ys ⟩\n ys ≡⟨ sym (++-leftIdentity ys) ⟩\n [] ++ ys ≡⟨ ++-leftCong (sym (rev-[] [])) ⟩\n rev [] [] ++ ys ∎\n\nrev-++ (fcons {x} {xs} Tx Fxs) ys =\n rev (x ∷ xs) ys\n ≡⟨ rev-∷ x xs ys ⟩\n rev xs (x ∷ ys)\n ≡⟨ rev-++ Fxs (x ∷ ys) ⟩\n rev xs [] ++ x ∷ ys\n ≡⟨ ++-rightCong prf ⟩\n rev xs [] ++ (x ∷ []) ++ ys\n ≡⟨ sym (++-assoc (rev-Forest Fxs fnil) (x ∷ []) ys) ⟩\n (rev xs [] ++ (x ∷ [])) ++ ys\n ≡⟨ ++-leftCong (sym (rev-++ Fxs (x ∷ []))) ⟩\n rev xs (x ∷ []) ++ ys\n ≡⟨ ++-leftCong (sym (rev-∷ x xs [])) ⟩\n rev (x ∷ xs) [] ++ ys ∎\n where prf : x ∷ ys ≡ (x ∷ []) ++ ys\n prf = x ∷ ys ≡⟨ ∷-rightCong (sym (++-leftIdentity ys)) ⟩\n x ∷ ([] ++ ys) ≡⟨ sym (++-∷ x [] ys) ⟩\n (x ∷ []) ++ ys ∎\n\nreverse-++ : ∀ {xs ys} → Forest xs → Forest ys →\n reverse (xs ++ ys) ≡ reverse ys ++ reverse xs\nreverse-++ {ys = ys} fnil Fys =\n reverse ([] ++ ys)\n ≡⟨ reverseCong (++-leftIdentity ys) ⟩\n reverse ys\n ≡⟨ sym (++-rightIdentity (reverse-Forest Fys)) ⟩\n reverse ys ++ []\n ≡⟨ ++-rightCong (sym (rev-[] [])) ⟩\n reverse ys ++ reverse [] ∎\n\nreverse-++ (fcons {x} {xs} Tx Fxs) fnil =\n reverse ((x ∷ xs) ++ [])\n ≡⟨ reverseCong (++-rightIdentity (fcons Tx Fxs)) ⟩\n reverse (x ∷ xs)\n ≡⟨ sym (++-leftIdentity (reverse (x ∷ xs))) ⟩\n [] ++ reverse (x ∷ xs)\n ≡⟨ ++-leftCong (sym (rev-[] [])) ⟩\n reverse [] ++ reverse (x ∷ xs) ∎\n\nreverse-++ (fcons {x} {xs} Tx Fxs) (fcons {y} {ys} Ty Fys) =\n rev ((x ∷ xs) ++ y ∷ ys) []\n ≡⟨ revCong₁ (++-∷ x xs (y ∷ ys)) ⟩\n rev (x ∷ (xs ++ y ∷ ys)) []\n ≡⟨ rev-∷ x (xs ++ y ∷ ys) [] ⟩\n rev (xs ++ y ∷ ys) (x ∷ [])\n ≡⟨ rev-++ (++-Forest Fxs (fcons Ty Fys)) (x ∷ []) ⟩\n rev (xs ++ y ∷ ys) [] ++ (x ∷ [])\n ≡⟨ ++-leftCong refl ⟩\n reverse (xs ++ y ∷ ys) ++ (x ∷ [])\n ≡⟨ ++-leftCong (reverse-++ Fxs (fcons Ty Fys)) ⟩\n (reverse (y ∷ ys) ++ reverse xs) ++ x ∷ []\n ≡⟨ ++-assoc (reverse-Forest (fcons Ty Fys))\n (reverse xs)\n (x ∷ [])\n ⟩\n reverse (y ∷ ys) ++ rev xs [] ++ x ∷ []\n ≡⟨ ++-rightCong (sym (rev-++ Fxs (x ∷ []))) ⟩\n reverse (y ∷ ys) ++ rev xs (x ∷ [])\n ≡⟨ ++-rightCong (sym (rev-∷ x xs [])) ⟩\n reverse (y ∷ ys) ++ reverse (x ∷ xs) ∎\n\nreverse-∷ : ∀ {x ys} → Tree x → Forest ys →\n reverse (x ∷ ys) ≡ reverse ys ++ (x ∷ [])\nreverse-∷ {x} Tx fnil =\n rev (x ∷ []) []\n ≡⟨ rev-∷ x [] [] ⟩\n rev [] (x ∷ [])\n ≡⟨ rev-[] (x ∷ []) ⟩\n x ∷ []\n ≡⟨ sym (++-leftIdentity (x ∷ [])) ⟩\n [] ++ x ∷ []\n ≡⟨ ++-leftCong (sym (rev-[] [])) ⟩\n rev [] [] ++ x ∷ [] ∎\n\nreverse-∷ {x} Tx (fcons {y} {ys} Ty Fys) = sym (\n reverse (y ∷ ys) ++ x ∷ []\n ≡⟨ ++-rightCong (sym (reverse-[x]≡[x] x)) ⟩\n (reverse (y ∷ ys) ++ reverse (x ∷ []))\n ≡⟨ sym (reverse-++ (fcons Tx fnil) (fcons Ty Fys)) ⟩\n reverse ((x ∷ []) ++ (y ∷ ys))\n ≡⟨ reverseCong (++-∷ x [] (y ∷ ys)) ⟩\n reverse (x ∷ ([] ++ (y ∷ ys)))\n ≡⟨ reverseCong (∷-rightCong (++-leftIdentity (y ∷ ys))) ⟩\n reverse (x ∷ y ∷ ys) ∎\n )\n", "meta": {"hexsha": "a9cb805becc2ee24b339486e870c7ec5cf016412", "size": 5631, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/fot/FOTC/Program/Mirror/Forest/PropertiesI.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": "src/fot/FOTC/Program/Mirror/Forest/PropertiesI.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": "src/fot/FOTC/Program/Mirror/Forest/PropertiesI.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": 31.813559322, "max_line_length": 78, "alphanum_fraction": 0.4203516249, "num_tokens": 2306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5544704502361149, "lm_q2_score": 0.6791787121629465, "lm_q1q2_score": 0.3765845263237736}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import lib.Basics\nopen import lib.types.Paths\nopen import lib.types.Pi\nopen import lib.types.Unit\nopen import lib.types.Nat\nopen import lib.types.TLevel\nopen import lib.types.Pointed\nopen import lib.types.Sigma\nopen import lib.NType2\n\nopen import lib.types.PathSeq\n\nopen import nicolai.pseudotruncations.Liblemmas\nopen import nicolai.pseudotruncations.SeqColim\n\n\nopen import nicolai.pseudotruncations.wconst-preparation\n\nmodule nicolai.pseudotruncations.heptagon\n {i} {C : Sequence {i}} (wc : wconst-chain C) (a₀ : fst C O) where\n\n {- î-def is defined in this module: -}\n open wconst-init {i} {C} wc a₀\n \n module _ (n : ℕ) (a : A n) where\n\n {- Let us formulate different simplification steps of the \n heptagon. -}\n\n full-hepta : seq-loop (ins (S n) (f n a)) \n full-hepta = (î-def (S n) (f n a)) ⋯ (‼ (î-def n a) ⋯ toSeq (glue n a))\n\n remove-g : seq-loop (ins (S n) (f n a)) \n remove-g = (î-def (S n) (f n a))\n ⋯ ‼ (ins (S n) (f n a)\n =⟪ ap (ins (S n)) (wc n _ _) ⟫\n ins (S n) (lift-point C a₀ (S n)) \n =⟪ ! (lift-point-= C a₀ (S n)) ⟫\n ins O a₀\n ∎∎)\n\n simplify-‼ : seq-loop (ins (S n) (f n a)) \n simplify-‼ = (î-def (S n) (f n a))\n ⋯ (ins O a₀\n =⟪ lift-point-= C a₀ (S n) ⟫\n ins (S n) (lift-point C a₀ (S n)) \n =⟪ ! (ap (ins (S n)) (wc n _ _)) ⟫\n ins (S n) (f n a)\n ∎∎)\n\n simplify-one-g : seq-loop (ins {C = C} (S n) (f n a))\n simplify-one-g =\n ins (S n) (f n a)\n =⟪ glue (S n) (f n a) ⟫\n ins (S (S n)) (f (S n) (f n a))\n =⟪ ap (ins (S (S n))) (wc (S n) (f n a) (lift-point C a₀ (S n))) ⟫\n ins (S (S n)) (lift-point C a₀ (S (S n)))\n =⟪ ! (glue (S n) (lift-point C a₀ (S n))) ⟫\n ins (S n) (lift-point C a₀ (S n))\n =⟪ ! (lift-point-= C a₀ (S n)) ⟫\n ins O a₀\n =⟪ lift-point-= C a₀ (S n) ⟫\n ins (S n) (lift-point C a₀ (S n))\n =⟪ ! (ap (ins (S n)) (wc n a (lift-point C a₀ n))) ⟫\n ins (S n) (f n a)\n ∎∎\n\n simplify-many-g : seq-loop (ins {C = C} (S n) (f n a))\n simplify-many-g =\n ins (S n) (f n a)\n =⟪ glue (S n) (f n a) ⟫\n ins (S (S n)) (f (S n) (f n a))\n =⟪ ap (ins (S (S n))) (wc (S n) (f n a) (lift-point C a₀ (S n))) ⟫\n ins (S (S n)) (lift-point C a₀ (S (S n)))\n =⟪ ! (glue (S n) (lift-point C a₀ (S n))) ⟫\n ins (S n) (lift-point C a₀ (S n))\n =⟪ ! (ap (ins (S n)) (wc n a (lift-point C a₀ n))) ⟫\n ins (S n) (f n a)\n ∎∎\n\n replace-ap-SSn : seq-loop (ins {C = C} (S n) (f n a))\n replace-ap-SSn =\n ins (S n) (f n a)\n =⟪ glue (S n) (f n a) ⟫\n ins (S (S n)) (f (S n) (f n a))\n =⟪ ap (ins (S (S n))) (ap (f (S n)) (wc n a (lift-point C a₀ n))) ⟫\n ins (S (S n)) (lift-point C a₀ (S (S n)))\n =⟪ ! (glue (S n) (lift-point C a₀ (S n))) ⟫\n ins (S n) (lift-point C a₀ (S n))\n =⟪ ! (ap (ins (S n)) (wc n a (lift-point C a₀ n))) ⟫\n ins (S n) (f n a)\n ∎∎\n\n {-\n Now, let us generalize:\n x for f n a \n y for lift-point C a₀ (S n) \n q for wc n a (lift C a₀ n)\n Then, we can show that the square commutes by induction on q.\n -}\n generalize-square : (x y : A (S n)) (q : x == y)\n → (↯ \n ins {C = C} (S n) x\n =⟪ glue (S n) x ⟫\n ins (S (S n)) (f (S n) x)\n =⟪ ap (ins (S (S n))) (ap (f (S n)) q) ⟫\n ins (S (S n)) (f (S n) y)\n =⟪ ! (glue (S n) y) ⟫\n ins (S n) y\n =⟪ ! (ap (ins (S n)) q) ⟫\n ins (S n) x\n ∎∎\n ) == idp\n generalize-square x .x idp = \n glue (S n) x ∙ ! (glue (S n) x) ∙ idp\n =⟨ ap (λ q → (glue (S n) x) ∙ q) (∙-unit-r _) ⟩\n glue (S n) x ∙ ! (glue (S n) x)\n =⟨ !-inv-r (glue (S n) x) ⟩\n idp\n ∎ \n\n {- Let us use some ad-hoc lemmas; these could all be done via\n very tedious concatenations of library lemmas.\n Of course, our ad-hoc way is somewhat ugly, but it saves a\n lot of work compared to using concatenations and nestings of\n library lemmas. The strategy is to formulate the equality \n that we need and solve it by trivial path induction.\n\n This ad-hoc approach is surely not the best way one can \n think of. \n The best way to do it would probably be a more principled \n approach with more powerful high-level lemmas that allow the\n manipulation of paths; however, such a technology is not\n implemented so far. -}\n adhoc-!-∙ : ∀ {i} {X : Type i} {x y z u v w o : X}\n (p : x == y) (q : y == z) (r : u == z)\n (s : v == u) (t : v == w) (l : w == o)\n → (↯ x =⟪ p ⟫ y =⟪ q ⟫ z =⟪ ! (s ∙ r) ⟫ v =⟪ t ⟫ w =⟪ l ⟫ o ∎∎ )\n ==\n (↯ x =⟪ p ⟫ y =⟪ q ⟫ z =⟪ ! r ⟫ u =⟪ ! s ⟫ v =⟪ t ⟫ w =⟪ l ⟫ o ∎∎)\n adhoc-!-∙ idp idp idp idp idp idp = idp\n\n\n adhoc-cancel-inv : ∀ {i} {X : Type i} {x y z u v w : X}\n (p : x == y) (q : y == z) (r : z == u)\n (s : v == u) (t : u == w)\n → (↯ x =⟪ p ⟫ y =⟪ q ⟫ z =⟪ r ⟫ u =⟪ ! s ⟫ v =⟪ s ⟫ u =⟪ t ⟫ w ∎∎ )\n ==\n (↯ x =⟪ p ⟫ y =⟪ q ⟫ z =⟪ r ⟫ u =⟪ t ⟫ w ∎∎)\n adhoc-cancel-inv idp idp idp idp idp = idp\n\n\n {- Now, we are ready to show that the heptagon is trivial! -}\n ĝ-def : (↯ full-hepta) == idp\n ĝ-def = \n\n (↯ full-hepta)\n\n =⟨ ap (λ q → (glue (S n) (f n a))\n ∙ ap (ins (S (S n))) (wc (S n) (f n a) (snd C n (lift-point C a₀ n)))\n ∙ ! ((lift-point-= C a₀ n ∙ glue n (lift-point C a₀ n))\n ∙ glue (S n) (snd C n (lift-point C a₀ n)))\n ∙ ! (! (lift-point-= C a₀ n ∙ glue n (lift-point C a₀ n)))\n ∙ ! (ap (ins (S n)) (wc n a (lift-point C a₀ n)))\n ∙ q )\n (!-inv-l (glue n a)) ⟩\n\n (↯ (remove-g ⋯ (toSeq idp)))\n\n =⟨ ap (λ q → (glue (S n) (f n a))\n ∙ ap (ins (S (S n))) (wc (S n) (f n a) (snd C n (lift-point C a₀ n)))\n ∙ ! ((lift-point-= C a₀ n ∙ glue n (lift-point C a₀ n))\n ∙ glue (S n) (snd C n (lift-point C a₀ n)))\n ∙ ! (! (lift-point-= C a₀ n ∙ glue n (lift-point C a₀ n)))\n ∙ q )\n (∙-unit-r (! (ap (ins (S n)) (wc n a (lift-point C a₀ n))))) ⟩\n (↯ remove-g)\n\n =⟨ ap (λ q → (glue (S n) (f n a))\n ∙ ap (ins (S (S n))) (wc (S n) (f n a) (snd C n (lift-point C a₀ n)))\n ∙ ! ((lift-point-= C a₀ n ∙ glue n (lift-point C a₀ n))\n ∙ glue (S n) (snd C n (lift-point C a₀ n)))\n ∙ q\n ∙ ! (ap (ins (S n)) (wc n a (lift-point C a₀ n)))\n )\n (!-! (lift-point-= C a₀ n ∙ glue n (lift-point C a₀ n))) ⟩\n\n (↯ simplify-‼) \n\n =⟨ adhoc-!-∙\n (glue (S n) (f n a))\n (ap (ins (S (S n))) (wc (S n) (f n a) (snd C n (lift-point C a₀ n))))\n (glue (S n) (snd C n (lift-point C a₀ n)))\n (lift-point-= C a₀ n ∙ glue n (lift-point C a₀ n))\n (lift-point-= C a₀ n ∙ glue n (lift-point C a₀ n))\n (! (ap (ins (S n)) (wc n a (lift-point C a₀ n)))) ⟩\n (↯ simplify-one-g) \n =⟨ adhoc-cancel-inv\n (glue (S n) (f n a))\n (ap (ins (S (S n))) (wc (S n) (f n a) (snd C n (lift-point C a₀ n))))\n (! (glue (S n) (snd C n (lift-point C a₀ n))))\n (lift-point-= C a₀ n ∙ glue n (lift-point C a₀ n))\n (! (ap (ins (S n)) (wc n a (lift-point C a₀ n)))) ⟩\n\n (↯ simplify-many-g) \n\n =⟨ ap (λ q → (glue (S n) (f n a))\n ∙ q\n ∙ ! (glue (S n) (snd C n (lift-point C a₀ n)))\n ∙ ! (ap (ins (S n)) (wc n a (lift-point C a₀ n)))\n )\n (ap-wconst (ins (S (S n)))\n (ins-wconst (S (S n)))\n (wc (S n) (f n a) (snd C n (lift-point C a₀ n)))\n (ap (f (S n)) (wc n a (lift-point C a₀ n)))\n ) ⟩\n\n (↯ replace-ap-SSn) \n\n =⟨ generalize-square (f n a) (lift-point C a₀ (S n)) (wc n a (lift-point C a₀ n)) ⟩\n\n idp\n ∎ \n\n", "meta": {"hexsha": "e8a293846ffeb402fd4ac2d60bd2bd99a42c82cd", "size": 9140, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "nicolai/pseudotruncations/heptagon.agda", "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolai/pseudotruncations/heptagon.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": "nicolai/pseudotruncations/heptagon.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": 40.2643171806, "max_line_length": 93, "alphanum_fraction": 0.3843544858, "num_tokens": 3203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6791786861878392, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3765845219217833}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nmodule Definition.Typed.EqRelInstance where\n\nopen import Definition.Untyped\nopen import Definition.Typed\nopen import Definition.Typed.Weakening\nopen import Definition.Typed.Reduction\nopen import Definition.Typed.EqualityRelation\n\nopen import Tools.Function\n\n\n-- Judgmental instance of the equality relation\n\ninstance eqRelInstance : EqRelSet\neqRelInstance = record {\n _⊢_≅_ = _⊢_≡_;\n _⊢_≅_∷_ = _⊢_≡_∷_;\n _⊢_~_∷_ = _⊢_≡_∷_;\n ~-to-≅ₜ = idᶠ;\n ≅-eq = idᶠ;\n ≅ₜ-eq = idᶠ;\n ≅-univ = univ;\n ≅-sym = sym;\n ≅ₜ-sym = sym;\n ~-sym = sym;\n ≅-trans = trans;\n ≅ₜ-trans = trans;\n ~-trans = trans;\n ≅-conv = conv;\n ~-conv = conv;\n ≅-wk = wkEq;\n ≅ₜ-wk = wkEqTerm;\n ~-wk = wkEqTerm;\n ≅-red = reduction;\n ≅ₜ-red = reductionₜ;\n ≅-Urefl = refl ∘ᶠ Uⱼ;\n ≅-ℕrefl = refl ∘ᶠ ℕⱼ;\n ≅ₜ-ℕrefl = refl ∘ᶠ ℕⱼ;\n ≅-Emptyrefl = refl ∘ᶠ Emptyⱼ;\n ≅ₜ-Emptyrefl = refl ∘ᶠ Emptyⱼ;\n ≅-Unitrefl = refl ∘ᶠ Unitⱼ;\n ≅ₜ-Unitrefl = refl ∘ᶠ Unitⱼ;\n ≅ₜ-η-unit = η-unit;\n ≅-Π-cong = Π-cong;\n ≅ₜ-Π-cong = Π-cong;\n ≅-Σ-cong = Σ-cong;\n ≅ₜ-Σ-cong = Σ-cong;\n ≅ₜ-zerorefl = refl ∘ᶠ zeroⱼ;\n ≅-suc-cong = suc-cong;\n ≅-η-eq = λ x x₁ x₂ x₃ x₄ x₅ → η-eq x x₁ x₂ x₅;\n ≅-Σ-η = λ ⊢F ⊢G ⊢p ⊢r pProd rProd fst≡ snd≡ → Σ-η ⊢F ⊢G ⊢p ⊢r fst≡ snd≡;\n ~-var = refl;\n ~-app = app-cong;\n ~-fst = fst-cong;\n ~-snd = snd-cong;\n ~-natrec = natrec-cong;\n ~-Emptyrec = Emptyrec-cong }\n", "meta": {"hexsha": "09448e16be1f102de9c5cf6448d87a7a6bd6aa70", "size": 1381, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Typed/EqRelInstance.agda", "max_stars_repo_name": "Vtec234/logrel-mltt", "max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2017-05-20T03:05:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:01:07.000Z", "max_issues_repo_path": "Definition/Typed/EqRelInstance.agda", "max_issues_repo_name": "Vtec234/logrel-mltt", "max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-06-22T12:49:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-22T10:37:24.000Z", "max_forks_repo_path": "Definition/Typed/EqRelInstance.agda", "max_forks_repo_name": "Vtec234/logrel-mltt", "max_forks_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2017-10-18T14:18:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-27T15:58:33.000Z", "avg_line_length": 23.0166666667, "max_line_length": 74, "alphanum_fraction": 0.6002896452, "num_tokens": 704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982315512489, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.37656711411466154}} {"text": "\nmodule _ where\n\nopen import Common.Prelude\nopen import Common.String\n\nrecord IsString {a} (A : Set a) : Set a where\n field\n fromString : String → A\n\nopen IsString {{...}} public\n{-# BUILTIN FROMSTRING fromString #-}\n\ninstance\n StringIsString : IsString String\n StringIsString = record { fromString = λ s → s }\n\n ListIsString : IsString (List Char)\n ListIsString = record { fromString = stringToList }\n\nfoo : List Char\nfoo = \"foo\"\n\nopen import Common.Equality\n\nthm : \"foo\" ≡ 'f' ∷ 'o' ∷ 'o' ∷ []\nthm = refl\n", "meta": {"hexsha": "20308bfeefe1e36e9f868aeb4ff805ab85930c1b", "size": 515, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/OverloadedString.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/Succeed/OverloadedString.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/Succeed/OverloadedString.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": 18.3928571429, "max_line_length": 53, "alphanum_fraction": 0.6737864078, "num_tokens": 155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6150878696277513, "lm_q2_score": 0.611381973294151, "lm_q1q2_score": 0.3760536354823101}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe --postfix-projections #-}\n\nmodule Cubical.Data.FinSet.Binary.Large where\n\nopen import Cubical.Functions.Embedding\nopen import Cubical.Functions.Involution\n\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Univalence\n\nopen import Cubical.Data.Bool\nopen import Cubical.Data.Sigma\n\nopen import Cubical.HITs.PropositionalTruncation\n\nprivate\n variable\n ℓ : Level\n\nisBinary : Type ℓ → Type ℓ\nisBinary B = ∥ Bool ≃ B ∥\n\nBinary : ∀ ℓ → Type _\nBinary ℓ = Σ (Type ℓ) isBinary\n\nisBinary→isSet : ∀{B : Type ℓ} → isBinary B → isSet B\nisBinary→isSet {B} = rec isPropIsSet λ eqv → isOfHLevelRespectEquiv 2 eqv isSetBool\n\nprivate\n Σ≡Prop²\n : ∀{ℓ ℓ'} {A : Type ℓ} {B : A → Type ℓ'}\n → {w x : Σ A B}\n → isOfHLevelDep 1 B\n → (p q : w ≡ x)\n → cong fst p ≡ cong fst q\n → p ≡ q\n Σ≡Prop² _ _ _ r i j .fst = r i j\n Σ≡Prop² {B = B} {w} {x} Bprp p q r i j .snd\n = isPropDep→isSetDep Bprp (w .snd) (x .snd) (cong snd p) (cong snd q) r i j\n\n\nBinaryEmbedding : isEmbedding (λ(B : Binary ℓ) → map-snd isBinary→isSet B)\nBinaryEmbedding w x = isoToIsEquiv theIso\n where\n open Iso\n f = map-snd isBinary→isSet\n\n theIso : Iso (w ≡ x) (f w ≡ f x)\n theIso .fun = cong f\n theIso .inv p i .fst = p i .fst\n theIso .inv p i .snd\n = ∥∥-isPropDep (Bool ≃_) (w .snd) (x .snd) (λ i → p i .fst) i\n theIso .rightInv p\n = Σ≡Prop² (isOfHLevel→isOfHLevelDep 1 (λ _ → isPropIsSet)) _ p refl\n theIso .leftInv p\n = Σ≡Prop² (∥∥-isPropDep (Bool ≃_)) _ p refl\n\nBase : Binary _\nBase .fst = Bool\nBase .snd = ∣ idEquiv Bool ∣\n\nLoop : Base ≡ Base\nLoop i .fst = notEq i\nLoop i .snd = ∥∥-isPropDep (Bool ≃_) (Base .snd) (Base .snd) notEq i\n\nprivate\n notEq² : Square notEq refl refl notEq\n notEq² = involPath² {f = not} notnot\n\nLoop² : Square Loop refl refl Loop\nLoop² i j .fst = notEq² i j\nLoop² i j .snd\n = isPropDep→isSetDep' (∥∥-isPropDep (Bool ≃_))\n notEq² (cong snd Loop) refl refl (cong snd Loop) i j\n\nisGroupoidBinary : isGroupoid (Binary ℓ)\nisGroupoidBinary\n = Embedding-into-hLevel→hLevel 2\n (map-snd isBinary→isSet , BinaryEmbedding)\n (isOfHLevelTypeOfHLevel 2)\n\nrecord BinStructure (B : Type ℓ) : Type ℓ where\n field\n base : B\n loop : base ≡ base\n loop² : Square loop refl refl loop\n trunc : isGroupoid B\n\nstructure₀ : BinStructure (Binary ℓ-zero)\nstructure₀ .BinStructure.base = Base\nstructure₀ .BinStructure.loop = Loop\nstructure₀ .BinStructure.loop² = Loop²\nstructure₀ .BinStructure.trunc = isGroupoidBinary\n\nmodule Parameterized (B : Type ℓ) where\n Baseᴾ : Bool ≃ B → Binary ℓ\n Baseᴾ P = B , ∣ P ∣\n\n Loopᴾ : (P Q : Bool ≃ B) → Baseᴾ P ≡ Baseᴾ Q\n Loopᴾ P Q i = λ where\n .fst → ua first i\n .snd → ∥∥-isPropDep (Bool ≃_) ∣ P ∣ ∣ Q ∣ (ua first) i\n where\n first : B ≃ B\n first = compEquiv (invEquiv P) Q\n\n Loopᴾ² : (P Q R : Bool ≃ B) → Square (Loopᴾ P Q) (Loopᴾ P R) refl (Loopᴾ Q R)\n Loopᴾ² P Q R i = Σ≡Prop (λ _ → squash) (S i)\n where\n PQ : B ≃ B\n PQ = compEquiv (invEquiv P) Q\n PR : B ≃ B\n PR = compEquiv (invEquiv P) R\n QR : B ≃ B\n QR = compEquiv (invEquiv Q) R\n Q-Q : Bool ≃ Bool\n Q-Q = compEquiv Q (invEquiv Q)\n\n PQRE : compEquiv PQ QR ≡ PR\n PQRE = compEquiv PQ QR\n ≡[ i ]⟨ compEquiv-assoc (invEquiv P) Q QR (~ i) ⟩\n compEquiv (invEquiv P) (compEquiv Q QR)\n ≡[ i ]⟨ compEquiv (invEquiv P) (compEquiv-assoc Q (invEquiv Q) R i) ⟩\n compEquiv (invEquiv P) (compEquiv Q-Q R)\n ≡[ i ]⟨ compEquiv (invEquiv P) (compEquiv (invEquiv-is-rinv Q i) R) ⟩\n compEquiv (invEquiv P) (compEquiv (idEquiv _) R)\n ≡[ i ]⟨ compEquiv (invEquiv P) (compEquivIdEquiv R i) ⟩\n PR ∎\n\n PQR : ua PQ ∙ ua QR ≡ ua PR\n PQR = ua PQ ∙ ua QR\n ≡[ i ]⟨ uaCompEquiv PQ QR (~ i) ⟩\n ua (compEquiv PQ QR)\n ≡⟨ cong ua PQRE ⟩\n ua PR ∎\n\n S : Square (ua PQ) (ua PR) refl (ua QR)\n S i j\n = hcomp (λ k → λ where\n (j = i0) → B\n (i = i0) → compPath-filler (ua PQ) (ua QR) (~ k) j\n (i = i1) → ua PR j\n (j = i1) → ua QR (i ∨ ~ k))\n (PQR i j)\n", "meta": {"hexsha": "9fc721f2efbcd6d561223af6606b6662a90e2bc1", "size": 4269, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Data/FinSet/Binary/Large.agda", "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": "Cubical/Data/FinSet/Binary/Large.agda", "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": "Cubical/Data/FinSet/Binary/Large.agda", "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": 28.8445945946, "max_line_length": 83, "alphanum_fraction": 0.607167955, "num_tokens": 1679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6688802735722128, "lm_q2_score": 0.5621765008857982, "lm_q1q2_score": 0.376028771708362}} {"text": "-- Andreas, 2017-01-13, regression introduced by the fix of #1899\n-- test case and report by Nisse\n\n-- {-# OPTIONS -v term:40 #-}\n\nopen import Agda.Builtin.Size\n\nmutual\n\n D : Size → Set\n D i = D′ i\n\n record D′ (i : Size) : Set where\n coinductive\n field\n force : {j : Size< i} → D j\n\ntest : D′ ω\nD′.force test = test\n\n-- Same without sizes (they are not used)\n\nmutual\n E = E'\n record E' : Set where\n coinductive\n field force : E\n\ntestE : E'\nE'.force testE = testE\n\n-- Both should succeed, no termination errors.\n", "meta": {"hexsha": "69905a7bc6672a45052a87438a148537e3c749c5", "size": 533, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1899-coind.agda", "max_stars_repo_name": "Blaisorblade/Agda", "max_stars_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_issues_repo_path": "test/Succeed/Issue1899-coind.agda", "max_issues_repo_name": "Blaisorblade/Agda", "max_issues_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "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/Succeed/Issue1899-coind.agda", "max_forks_repo_name": "Blaisorblade/Agda", "max_forks_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "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": 16.1515151515, "max_line_length": 65, "alphanum_fraction": 0.6228893058, "num_tokens": 176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6076631840431539, "lm_q2_score": 0.6187804267137442, "lm_q1q2_score": 0.37601008432045524}} {"text": "module BasicIS4.Metatheory.Hilbert-TarskiClosedOvergluedImplicit where\n\nopen import BasicIS4.Syntax.Hilbert public\nopen import BasicIS4.Semantics.TarskiClosedOvergluedImplicit public\n\nopen ImplicitSyntax (∅ ⊢_) public\n\n\n-- Completeness with respect to a particular model, for closed terms only.\n\nmodule _ {{_ : Model}} where\n reify : ∀ {A} → ⊩ A → ∅ ⊢ A\n reify {α P} s = syn s\n reify {A ▻ B} s = syn s\n reify {□ A} s = syn s\n reify {A ∧ B} s = pair (reify (π₁ s)) (reify (π₂ s))\n reify {⊤} s = unit\n\n\n-- Additional useful equipment.\n\nmodule _ {{_ : Model}} where\n ⟪K⟫ : ∀ {A B} → ⊩ A → ⊩ B ▻ A\n ⟪K⟫ a = app ck (reify a) ⅋ K a\n\n ⟪S⟫′ : ∀ {A B C} → ⊩ A ▻ B ▻ C → ⊩ (A ▻ B) ▻ A ▻ C\n ⟪S⟫′ s₁ = app cs (reify s₁) ⅋ λ s₂ →\n app (app cs (reify s₁)) (reify s₂) ⅋ ⟪S⟫ s₁ s₂\n\n _⟪D⟫_ : ∀ {A B} → ⊩ □ (A ▻ B) → ⊩ □ A → ⊩ □ B\n (t ⅋ s) ⟪D⟫ (u ⅋ a) = app (app cdist t) u ⅋ s ⟪$⟫ a\n\n _⟪D⟫′_ : ∀ {A B} → ⊩ □ (A ▻ B) → ⊩ □ A ▻ □ B\n _⟪D⟫′_ s = app cdist (reify s) ⅋ _⟪D⟫_ s\n\n ⟪↑⟫ : ∀ {A} → ⊩ □ A → ⊩ □ □ A\n ⟪↑⟫ s = box (syn s) ⅋ s\n\n _⟪,⟫′_ : ∀ {A B} → ⊩ A → ⊩ B ▻ A ∧ B\n _⟪,⟫′_ a = app cpair (reify a) ⅋ _,_ a\n\n\n-- Additional useful equipment, for sequents.\n\nmodule _ {{_ : Model}} where\n _⟦D⟧_ : ∀ {A B Γ} → ⊩ Γ ⇒ □ (A ▻ B) → ⊩ Γ ⇒ □ A → ⊩ Γ ⇒ □ B\n (s₁ ⟦D⟧ s₂) γ = (s₁ γ) ⟪D⟫ (s₂ γ)\n\n ⟦↑⟧ : ∀ {A Γ} → ⊩ Γ ⇒ □ A → ⊩ Γ ⇒ □ □ A\n ⟦↑⟧ s γ = ⟪↑⟫ (s γ)\n\n\n-- Soundness with respect to all models, or evaluation.\n\neval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A\neval (var i) γ = lookup i γ\neval (app t u) γ = eval t γ ⟪$⟫ eval u γ\neval ci γ = ci ⅋ I\neval ck γ = ck ⅋ ⟪K⟫\neval cs γ = cs ⅋ ⟪S⟫′\neval (box t) γ = box t ⅋ eval t ∙\neval cdist γ = cdist ⅋ _⟪D⟫′_\neval cup γ = cup ⅋ ⟪↑⟫\neval cdown γ = cdown ⅋ ⟪↓⟫\neval cpair γ = cpair ⅋ _⟪,⟫′_\neval cfst γ = cfst ⅋ π₁\neval csnd γ = csnd ⅋ π₂\neval unit γ = ∙\n\n\n-- Correctness of evaluation with respect to conversion.\n\neval✓ : ∀ {{_ : Model}} {A Γ} {t t′ : Γ ⊢ A} → t ⋙ t′ → eval t ≡ eval t′\neval✓ refl⋙ = refl\neval✓ (trans⋙ p q) = trans (eval✓ p) (eval✓ q)\neval✓ (sym⋙ p) = sym (eval✓ p)\neval✓ (congapp⋙ p q) = cong² _⟦$⟧_ (eval✓ p) (eval✓ q)\neval✓ (congi⋙ p) = cong I (eval✓ p)\neval✓ (congk⋙ p q) = cong² K (eval✓ p) (eval✓ q)\neval✓ (congs⋙ p q r) = cong³ ⟦S⟧ (eval✓ p) (eval✓ q) (eval✓ r)\neval✓ (congdist⋙ p q) = cong² _⟦D⟧_ (eval✓ p) (eval✓ q)\neval✓ (congup⋙ p) = cong ⟦↑⟧ (eval✓ p)\neval✓ (congdown⋙ p) = cong ⟦↓⟧ (eval✓ p)\neval✓ (congpair⋙ {A} {B} p q) = cong² (_⟦,⟧_ {A} {B}) (eval✓ p) (eval✓ q)\neval✓ (congfst⋙ {A} {B} p) = cong (⟦π₁⟧ {A} {B}) (eval✓ p)\neval✓ (congsnd⋙ {A} {B} p) = cong (⟦π₂⟧ {A} {B}) (eval✓ p)\neval✓ beta▻ₖ⋙ = refl\neval✓ beta▻ₛ⋙ = refl\neval✓ beta∧₁⋙ = refl\neval✓ beta∧₂⋙ = refl\neval✓ eta∧⋙ = refl\neval✓ eta⊤⋙ = refl\n\n\n-- The canonical model.\n\nprivate\n instance\n canon : Model\n canon = record\n { ⊩ᵅ_ = λ P → ∅ ⊢ α P\n }\n\n\n-- Completeness with respect to all models, or quotation, for closed terms only.\n\nquot₀ : ∀ {A} → ∅ ⊨ A → ∅ ⊢ A\nquot₀ t = reify (t ∙)\n\n\n-- Normalisation by evaluation, for closed terms only.\n\nnorm₀ : ∀ {A} → ∅ ⊢ A → ∅ ⊢ A\nnorm₀ = quot₀ ∘ eval\n\n\n-- TODO: Correctness of normalisation with respect to conversion.\n", "meta": {"hexsha": "650376ea430a46411581efb097c4c1a62faa366a", "size": 3393, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BasicIS4/Metatheory/Hilbert-TarskiClosedOvergluedImplicit.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/Metatheory/Hilbert-TarskiClosedOvergluedImplicit.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/Metatheory/Hilbert-TarskiClosedOvergluedImplicit.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": 28.7542372881, "max_line_length": 80, "alphanum_fraction": 0.4809902741, "num_tokens": 1629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419958239132, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.37600990791612615}} {"text": "open import Data.Empty\nopen import Data.Maybe\nopen import Data.Product\nopen import Data.Unit\n\nopen import Axiom.Extensionality.Propositional\nopen import Relation.Binary.PropositionalEquality hiding ([_])\nopen import Relation.Nullary\nopen import Relation.Nullary.Negation\n\nopen import EffectAnnotations\nopen import Types\n\nmodule AEff where\n\n-- ARITY ASSIGNMENT TO SIGNATURES OF SIGNALS, INTERRUPTS, AND BASE CONSTANTS\n\npostulate payload : Σₛ → Σ VType (λ X → mobile X) -- payload type assignment for signal and interrupt names\n\npostulate Σ-base : Set -- set of base constants\npostulate ar-base : Σ-base → BType -- arity assignment to base constants\n\n\n-- CONTEXTS\n\ndata Ctx : Set where\n [] : Ctx\n _∷_ : Ctx → VType → Ctx\n _■ : Ctx → Ctx\n\ninfixl 35 _∷_\ninfixl 35 _■\n\n_++ₖ_ : Ctx → Ctx → Ctx\nΓ ++ₖ [] = Γ\nΓ ++ₖ (Γ' ∷ X) = (Γ ++ₖ Γ') ∷ X\nΓ ++ₖ (Γ' ■) = (Γ ++ₖ Γ') ■\n\ninfixl 30 _++ₖ_\n\n-- VARIABLES IN CONTEXTS (I.E., DE BRUIJN INDICES)\n\ndata _∈_ (X : VType) : Ctx → Set where\n Hd : {Γ : Ctx} → X ∈ (Γ ∷ X)\n Tl-v : {Γ : Ctx} {Y : VType} → X ∈ Γ → X ∈ (Γ ∷ Y)\n Tl-■ : {Γ : Ctx} → mobile X → X ∈ Γ → X ∈ (Γ ■)\n\n\n-- DERIVATIONS OF WELL-TYPED TERMS\n\nmutual\n\n data _⊢V⦂_ (Γ : Ctx) : VType → Set where\n \n `_ : {X : VType} →\n X ∈ Γ →\n -------------\n Γ ⊢V⦂ X\n \n ´_ : (c : Σ-base) →\n --------------\n Γ ⊢V⦂ ``(ar-base c)\n\n ⋆ : Γ ⊢V⦂ 𝟙\n \n ƛ : {X : VType}\n {C : CType} →\n Γ ∷ X ⊢C⦂ C → \n -------------\n Γ ⊢V⦂ X ⇒ C\n\n ⟨_⟩ : {X : VType} →\n Γ ⊢V⦂ X →\n -------------\n Γ ⊢V⦂ ⟨ X ⟩\n\n □ : {X : VType} →\n Γ ■ ⊢V⦂ X →\n -------------\n Γ ⊢V⦂ □ X\n\n \n infix 40 _·_\n\n data _⊢C⦂_ (Γ : Ctx) : CType → Set where\n\n return : {X : VType}\n {o : O}\n {i : I} →\n Γ ⊢V⦂ X →\n -----------------\n Γ ⊢C⦂ X ! (o , i)\n\n let=_`in_ : {X Y : VType}\n {o : O}\n {i : I} → \n Γ ⊢C⦂ X ! (o , i) →\n Γ ∷ X ⊢C⦂ Y ! (o , i) →\n -----------------------\n Γ ⊢C⦂ Y ! (o , i)\n\n _·_ : {X : VType}\n {C : CType} → \n Γ ⊢V⦂ X ⇒ C →\n Γ ⊢V⦂ X →\n -------------\n Γ ⊢C⦂ C\n\n ↑ : {X : VType}\n {o : O}\n {i : I} →\n (op : Σₛ) →\n op ∈ₒ o →\n Γ ⊢V⦂ proj₁ (payload op) →\n Γ ⊢C⦂ X ! (o , i) →\n --------------------------\n Γ ⊢C⦂ X ! (o , i)\n\n ↓ : {X : VType}\n {o : O}\n {i : I}\n (op : Σₛ) →\n Γ ⊢V⦂ proj₁ (payload op) →\n Γ ⊢C⦂ X ! (o , i) →\n --------------------------\n Γ ⊢C⦂ X ! op ↓ₑ (o , i)\n\n promise_∣_↦_`in_ : {X Y : VType}\n {o o' : O}\n {i i' : I} → \n (op : Σₛ) →\n (o' , i') ⊑ lkpᵢ op i →\n Γ ∷ proj₁ (payload op) ∷ (𝟙 ⇒ (⟨ X ⟩ ! (∅ₒ , ∅ᵢ [ op ↦ just (o' , i') ]ᵢ))) ⊢C⦂ ⟨ X ⟩ ! (o' , i') →\n Γ ∷ ⟨ X ⟩ ⊢C⦂ Y ! (o , i) →\n ---------------------------------------------------------------------------------------------------\n Γ ⊢C⦂ Y ! (o , i)\n\n await_until_ : {X : VType}\n {C : CType} → \n Γ ⊢V⦂ ⟨ X ⟩ →\n Γ ∷ X ⊢C⦂ C →\n --------------\n Γ ⊢C⦂ C\n\n unbox_`in_ : {X : VType}\n {C : CType} →\n Γ ⊢V⦂ □ X →\n Γ ∷ X ⊢C⦂ C →\n -------------\n Γ ⊢C⦂ C\n\n spawn : {C D : CType} →\n Γ ■ ⊢C⦂ C →\n Γ ⊢C⦂ D →\n ---------------------\n Γ ⊢C⦂ D\n\n coerce : {X : VType}\n {o o' : O}\n {i i' : I} →\n o ⊑ₒ o' →\n i ⊑ᵢ i' → \n Γ ⊢C⦂ X ! (o , i) →\n -------------------\n Γ ⊢C⦂ X ! (o' , i')\n \n\n\n-- DERIVATIONS OF WELL-TYPED PROCESSES\n\ninfix 10 _⊢P⦂_\n\ndata _⊢P⦂_ (Γ : Ctx) : {o : O} → PType o → Set where\n\n run : {X : VType}\n {o : O}\n {i : I} →\n Γ ⊢C⦂ X ! (o , i) →\n -------------------\n Γ ⊢P⦂ X ‼ o , i\n\n _∥_ : {o o' : O}\n {PP : PType o} →\n {QQ : PType o'} → \n Γ ⊢P⦂ PP →\n Γ ⊢P⦂ QQ →\n -----------------\n Γ ⊢P⦂ (PP ∥ QQ)\n\n ↑ : {o : O} →\n {PP : PType o}\n (op : Σₛ) →\n op ∈ₒ o →\n Γ ⊢V⦂ (proj₁ (payload op)) →\n Γ ⊢P⦂ PP →\n ----------------------------\n Γ ⊢P⦂ PP\n\n ↓ : {o : O}\n {PP : PType o}\n (op : Σₛ) →\n Γ ⊢V⦂ (proj₁ (payload op)) →\n Γ ⊢P⦂ PP →\n ----------------------------\n Γ ⊢P⦂ op ↓ₚ PP\n\n\n-- ADMISSIBLE TYPING RULES\n\n■-dup-var : {Γ Γ' : Ctx} {X : VType} →\n X ∈ (Γ ■ ++ₖ Γ') →\n --------------------------\n X ∈ (Γ ■ ■ ++ₖ Γ')\n\n■-dup-var {Γ} {[]} (Tl-■ p x) =\n Tl-■ p (Tl-■ p x)\n■-dup-var {Γ} {Γ' ∷ Y} Hd =\n Hd\n■-dup-var {Γ} {Γ' ∷ Y} (Tl-v x) =\n Tl-v (■-dup-var x)\n■-dup-var {Γ} {Γ' ■} (Tl-■ p x) =\n Tl-■ p (■-dup-var x)\n \n\nmutual\n\n ■-dup-v : {Γ Γ' : Ctx} {X : VType} →\n (Γ ■ ++ₖ Γ') ⊢V⦂ X →\n --------------------------\n (Γ ■ ■ ++ₖ Γ') ⊢V⦂ X\n \n ■-dup-v (` x) =\n ` ■-dup-var x\n ■-dup-v (´ c) =\n ´ c\n ■-dup-v ⋆ =\n ⋆\n ■-dup-v (ƛ M) =\n ƛ (■-dup-c M)\n ■-dup-v ⟨ V ⟩ =\n ⟨ ■-dup-v V ⟩\n ■-dup-v (□ V) =\n □ (■-dup-v {Γ' = _ ■} V)\n\n\n ■-dup-c : {Γ Γ' : Ctx} {C : CType} →\n (Γ ■ ++ₖ Γ') ⊢C⦂ C →\n --------------------------\n (Γ ■ ■ ++ₖ Γ') ⊢C⦂ C\n\n ■-dup-c (return V) =\n return (■-dup-v V)\n ■-dup-c (let= M `in N) =\n let= (■-dup-c M) `in (■-dup-c N)\n ■-dup-c (V · W) =\n (■-dup-v V) · (■-dup-v W)\n ■-dup-c (↑ op p V M) =\n ↑ op p (■-dup-v V) (■-dup-c M)\n ■-dup-c (↓ op V M) =\n ↓ op (■-dup-v V) (■-dup-c M)\n ■-dup-c (promise op ∣ x ↦ M `in N) =\n promise op ∣ x ↦ (■-dup-c M) `in (■-dup-c N)\n ■-dup-c (await V until M) =\n await (■-dup-v V) until (■-dup-c M)\n ■-dup-c (unbox V `in M) =\n unbox (■-dup-v V) `in (■-dup-c M)\n ■-dup-c (spawn M N) =\n spawn (■-dup-c {Γ' = _ ■} M) (■-dup-c N)\n ■-dup-c (coerce p q M) =\n coerce p q (■-dup-c M)\n \n\n■-wk : {Γ : Ctx} {X : VType} →\n mobile X →\n Γ ⊢V⦂ X →\n -----------------------\n Γ ■ ⊢V⦂ X\n \n■-wk p (` x) =\n ` Tl-■ p x\n■-wk p (´ c) =\n ´ c\n■-wk p ⋆ =\n ⋆\n■-wk p (□ V) =\n □ (■-dup-v {_} {[]} V)\n\n\n■-str-var : {Γ Γ' : Ctx} {X : VType} →\n X ∈ Γ ■ ++ₖ Γ' →\n --------------------------\n X ∈ Γ ++ₖ Γ'\n\n■-str-var {Γ} {[]} (Tl-■ p x) =\n x\n■-str-var {Γ} {Γ' ∷ Y} Hd =\n Hd\n■-str-var {Γ} {Γ' ∷ Y} (Tl-v x) =\n Tl-v (■-str-var x)\n■-str-var {Γ} {Γ' ■} (Tl-■ p x) =\n Tl-■ p (■-str-var x)\n\n\nmutual\n\n ■-str-v : {Γ Γ' : Ctx} {X : VType} →\n Γ ■ ++ₖ Γ' ⊢V⦂ X →\n -----------------------\n Γ ++ₖ Γ' ⊢V⦂ X\n\n ■-str-v (` x) =\n ` ■-str-var x\n ■-str-v (´ c) =\n ´ c\n ■-str-v ⋆ =\n ⋆\n ■-str-v (ƛ M) =\n ƛ (■-str-c M)\n ■-str-v ⟨ V ⟩ =\n ⟨ ■-str-v V ⟩\n ■-str-v {Γ} {Γ'} (□ V) =\n □ (■-str-v {Γ' = _ ■} V)\n\n\n ■-str-c : {Γ Γ' : Ctx} {C : CType} →\n Γ ■ ++ₖ Γ' ⊢C⦂ C →\n -----------------------\n Γ ++ₖ Γ' ⊢C⦂ C\n\n ■-str-c (return V) =\n return (■-str-v V)\n ■-str-c (let= M `in N) =\n let= (■-str-c M) `in (■-str-c N)\n ■-str-c (V · W) =\n (■-str-v V) · (■-str-v W)\n ■-str-c (↑ op p V M) =\n ↑ op p (■-str-v V) (■-str-c M)\n ■-str-c (↓ op V M) =\n ↓ op (■-str-v V) (■-str-c M)\n ■-str-c (promise op ∣ r ↦ M `in N) =\n promise op ∣ r ↦ (■-str-c M) `in (■-str-c N)\n ■-str-c (await V until M) =\n await (■-str-v V) until (■-str-c M)\n ■-str-c (unbox V `in M) =\n unbox (■-str-v V) `in (■-str-c M)\n ■-str-c (spawn M N) =\n spawn (■-str-c {Γ' = _ ■} M) (■-str-c N)\n ■-str-c (coerce p q M) =\n coerce p q (■-str-c M)\n\n", "meta": {"hexsha": "fe94faf124d7ab5b4be3063f08310682e1ca8329", "size": 8708, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "AEff.agda", "max_stars_repo_name": "danelahman/higher-order-aeff-agda", "max_stars_repo_head_hexsha": "b41df71f4456666aab4bd14e13d285c31af80ff6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-17T15:00:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T18:50:26.000Z", "max_issues_repo_path": "AEff.agda", "max_issues_repo_name": "danelahman/modal-aeff-agda", "max_issues_repo_head_hexsha": "b41df71f4456666aab4bd14e13d285c31af80ff6", "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": "AEff.agda", "max_forks_repo_name": "danelahman/modal-aeff-agda", "max_forks_repo_head_hexsha": "b41df71f4456666aab4bd14e13d285c31af80ff6", "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": 24.8091168091, "max_line_length": 122, "alphanum_fraction": 0.286977492, "num_tokens": 3350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.3759840426605501}} {"text": "------------------------------------------------------------------------\n-- Subject reduction for typing in Fω with interval kinds\n------------------------------------------------------------------------\n\n{-# OPTIONS --safe --without-K #-}\n\n-- This module proves a variant of subject reduction (aka the\n-- \"preservation\" theorem) for term reduction in Fω with interval\n-- kinds. The subject reduction property proved here is weaker than\n-- the one typically found in the literature on other variants of Fω:\n-- subject reduction does not hold in arbitrary typing contexts in Fω\n-- with interval types because type variables of interval kind can be\n-- used to introduce arbitrary typing (in)equalities into the\n-- subtyping relation. In other words, subject reduction does not\n-- hold for full β-reduction as reductions under type abstractions are\n-- not safe in general. Note, however, that subject reduction does\n-- hold for arbitrary β-reductions in *types* (see `pres-Tp∈-→β*' in\n-- the Kinding.Declarative.Validity module for a proof).\n--\n-- NOTE. Here we use the CBV evaluation strategy, but this is\n-- unnecessarily restrictive. Other evaluation strategies work so\n-- long as they do not allow reductions under type abstractions.\n--\n-- Together with the \"progress\" theorem from Typing.Progress, subject\n-- reduction ensures type safety. For details, see e.g.\n--\n-- * B. C. Pierce, TAPL (2002), pp. 95.\n--\n-- * A. Wright and M. Felleisen, \"A Syntactic Approach to Type\n-- Soundness\" (1994).\n\nmodule FOmegaInt.Typing.Preservation where\n\nopen import Data.Product using (_,_)\nopen import Relation.Binary.Construct.Closure.ReflexiveTransitive using (ε; _◅_)\nopen import Relation.Binary.PropositionalEquality using (subst)\nopen import Relation.Nullary.Negation using (contradiction)\n\nopen import FOmegaInt.Syntax\nopen import FOmegaInt.Typing\nopen import FOmegaInt.Typing.Inversion\nopen import FOmegaInt.Reduction.Cbv\nopen import FOmegaInt.Reduction.Full\n\nopen Syntax\nopen TermCtx\nopen Substitution using (_[_]; weaken-sub)\nopen Typing\nopen TypedSubstitution using (Tm∈-[]; <:-[])\n\n-- Types of closed terms are preserved under single-step reduction.\npres : ∀ {a b c} → [] ⊢Tm a ∈ c → a →v b → [] ⊢Tm b ∈ c\npres (∈-var () _ _)\npres (∈-∀-i k-kd a∈b) ()\npres (∈-→-i a∈* b∈c c∈*) ()\npres (∈-∀-e Λja∈Πkc b∈k) (cont-⊡ j a b) with Tm∈-gen Λja∈Πkc\n... | ∈-∀-i j-kd a∈d Πjd<:Πkc =\n let k<∷j , d<:c = <:-∀-inv Πjd<:Πkc\n in ∈-⇑ (Tm∈-[] a∈d (∈-tp (∈-⇑ b∈k k<∷j))) (<:-[] d<:c (∈-tp b∈k))\npres (∈-∀-e a∈Πcd b∈c) (a→e ⊡ b) = ∈-∀-e (pres a∈Πcd a→e) b∈c\npres (∈-→-e ƛea∈c⇒d v∈c) (cont-· e a v) with Tm∈-gen ƛea∈c⇒d\n... | ∈-→-i e∈* a∈f e⇒f<:c⇒d =\n let c<:e , f<:d = <:-→-inv e⇒f<:c⇒d\n in ∈-⇑ (subst (_ ⊢Tm _ ∈_) (weaken-sub _) (Tm∈-[] a∈f (∈-tm (∈-⇑ v∈c c<:e))))\n f<:d\npres (∈-→-e a∈c⇒d b∈c) (a→e ·₁ b) = ∈-→-e (pres a∈c⇒d a→e) b∈c\npres (∈-→-e a∈c⇒d b∈c) (v ·₂ b→e) = ∈-→-e a∈c⇒d (pres b∈c b→e)\npres (∈-⇑ a∈c c<:d) a→b = ∈-⇑ (pres a∈c a→b) c<:d\n\n-- Weak preservation (aka subject reduction): types of closed terms\n-- are preserved under reduction.\npres* : ∀ {a b c} → [] ⊢Tm a ∈ c → a →v* b → [] ⊢Tm b ∈ c\npres* a∈c ε = a∈c\npres* a∈d (a→b ◅ b→*c) = pres* (pres a∈d a→b) b→*c\n", "meta": {"hexsha": "1ee3b8b2ba48ca67657aff6c9e0a0d1e01bf8bf9", "size": 3207, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/FOmegaInt/Typing/Preservation.agda", "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z", "max_issues_repo_path": "src/FOmegaInt/Typing/Preservation.agda", "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z", "max_forks_repo_path": "src/FOmegaInt/Typing/Preservation.agda", "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z", "avg_line_length": 42.76, "max_line_length": 80, "alphanum_fraction": 0.6186467103, "num_tokens": 1199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300698514777, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.3759227364404693}} {"text": "\nmodule _ where\n\nopen import Agda.Builtin.Nat using (mod-helper)\nopen import Common.Prelude\nopen import Common.Equality\n\n_mod_ : Nat → Nat → Nat\nn mod zero = 0\nn mod suc m = mod-helper 0 m n m\n\n{-# INLINE _mod_ #-}\n\nprimitive\n primForce : ∀ {a b} {A : Set a} {B : A → Set b} (x : A) → (∀ x → B x) → B x\n primForceLemma : ∀ {a b} {A : Set a} {B : A → Set b} (x : A) (f : ∀ x → B x) → primForce x f ≡ f x\n\nforce = primForce\nforceLemma = primForceLemma\n\ninfixr 0 _$!_\n_$!_ : ∀ {a b} {A : Set a} {B : A → Set b} → (∀ x → B x) → ∀ x → B x\nf $! x = force x f\n\n-- Memory leak without proper seq --\n\npow′ : Nat → Nat → Nat\npow′ zero acc = acc\npow′ (suc n) acc = pow′ n $! (acc + acc) mod 234576373\n\npow : Nat → Nat\npow n = pow′ n 1\n\nmain : IO Unit\nmain = printNat (pow 5000000)\n", "meta": {"hexsha": "9a2adba0157799ba6ec30a415c883358f83f5c5b", "size": 786, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Compiler/simple/PrimSeq.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Compiler/simple/PrimSeq.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Compiler/simple/PrimSeq.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 21.8333333333, "max_line_length": 100, "alphanum_fraction": 0.5674300254, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7401743620390163, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3758693226787037}} {"text": "------------------------------------------------------------------------\n-- Parallel substitutions (defined using an inductive family)\n------------------------------------------------------------------------\n\nopen import Data.Universe.Indexed\n\nmodule deBruijn.Substitution.Data.Basics\n {i u e} {Uni : IndexedUniverse i u e} where\n\nimport deBruijn.Context; open deBruijn.Context Uni\nopen import Function using (id; _∘_; _$_)\nopen import Level using (_⊔_)\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\n\nprivate\n module Dummy₁ {t} (T : Term-like t) where\n\n open Term-like T\n\n infixl 5 _▻_\n\n -- Substitutions, represented as sequences of terms.\n\n data Sub : ∀ {Γ Δ} → Γ ⇨̂ Δ → Set (i ⊔ u ⊔ e ⊔ t) where\n ε : ∀ {Δ} → Sub ε̂[ Δ ]\n _▻_ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ}\n (ρ : Sub ρ̂) (t : Δ ⊢ σ /̂ ρ̂) → Sub (ρ̂ ▻̂[ σ ] ⟦ t ⟧)\n\n -- A sequence of matching substitutions. (The reflexive transitive\n -- closure of Sub.)\n\n data Subs {Γ} : ∀ {Δ} → Γ ⇨̂ Δ → Set (i ⊔ u ⊔ e ⊔ t) where\n ε : Subs îd[ Γ ]\n _▻_ : ∀ {Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε}\n (ρs : Subs ρ̂₁) (ρ : Sub ρ̂₂) → Subs (ρ̂₁ ∘̂ ρ̂₂)\n\nopen Dummy₁ public\n\n-- Originally these substitutions were defined without the context\n-- morphism index, but this led to the need to prove lots of lemmas\n-- which hold by definition in the current setting. As an example the\n-- map function (in deBruijn.Substitution.Data.Map) is currently\n-- defined as follows:\n--\n-- -- Map.\n--\n-- map : ∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} →\n-- [ T₁ ⟶ T₂ ] ρ̂₂ → Sub T₁ ρ̂₁ → Sub T₂ (ρ̂₁ ∘̂ ρ̂₂)\n-- map f ε = ε\n-- map {ρ̂₂ = ρ̂₂} f (ρ₁ ▻ t) =\n-- P.subst (λ v → Sub T₂ (⟦ ρ₁ ⟧⇨ ∘̂ ρ̂₂ ▻̂ v))\n-- (≅-Value-⇒-≡ $ P.sym $ corresponds f t)\n-- (map f ρ₁ ▻ f · t)\n--\n-- Previously it was defined roughly as follows (the code below is\n-- untested and has been adapted to the current version of the\n-- library, as it was at the time of writing, with some imagined\n-- changes):\n--\n-- mutual\n--\n-- -- Map.\n--\n-- map : ∀ {Γ Δ Ε} {ρ̂₂ : Δ ⇨̂ Ε} →\n-- [ T₁ ⟶ T₂ ] ρ̂₂ → (ρ₁ : Γ ⇨₁ Δ) → Γ ⇨₂ Ε\n-- map f ε = ε\n-- map f (_▻_ {σ = σ} ρ t) =\n-- map f ρ ▻\n-- P.subst (λ ρ̂ → _ ⊢₂ σ /̂ ρ̂)\n-- (≅-⇨̂-⇒-≡ $ P.sym $ map-lemma f ρ)\n-- (f · t)\n--\n-- abstract\n--\n-- map-lemma :\n-- ∀ {Γ Δ Ε} {ρ̂₂ : Δ ⇨̂ Ε} →\n-- (f : [ T₁ ⟶ T₂ ] ρ̂₂) (ρ₁ : Γ ⇨₁ Δ) →\n-- ⟦ map f ρ₁ ⟧₂⇨ ≅-⇨̂ ⟦ ρ₁ ⟧₁⇨ ∘̂ ρ₂\n-- map-lemma f ε = P.refl\n-- map-lemma {ρ₂ = ρ₂} f (_▻_ {σ = σ} ρ t) =\n-- ▻̂-cong P.refl (map-lemma f ρ) (begin\n-- [ ⟦ P.subst (λ ρ̂ → _ ⊢₂ σ /̂ ρ̂)\n-- (≅-⇨̂-⇒-≡ $ P.sym (map-lemma f ρ))\n-- (f · t) ⟧₂ ] ≡⟨ Term-like.⟦⟧-cong T₂\n-- (Term-like.drop-subst-⊢ T₂\n-- (λ ρ̂ → σ /̂ ρ̂)\n-- (≅-⇨̂-⇒-≡ $ P.sym (map-lemma f ρ))) ⟩\n-- [ ⟦ f · t ⟧₂ ] ≡⟨ P.sym $ corresponds f t ⟩\n-- [ ⟦ t ⟧₁ /̂Val ρ₂ ] ∎)\n\nprivate\n module Dummy₂ {t} {T : Term-like t} where\n\n open Term-like T\n\n -- Some variants.\n\n ε⇨[_] : ∀ Δ → Sub T ε̂[ Δ ]\n ε⇨[ _ ] = ε\n\n infixl 5 _▻⇨[_]_\n\n _▻⇨[_]_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} →\n Sub T ρ̂ → ∀ σ (t : Δ ⊢ σ /̂ ρ̂) → Sub T (ρ̂ ▻̂[ σ ] ⟦ t ⟧)\n ρ ▻⇨[ _ ] t = ρ ▻ t\n\n ε⇨⋆[_] : ∀ Γ → Subs T îd[ Γ ]\n ε⇨⋆[ _ ] = ε\n\n -- Equality of substitutions.\n\n record [⇨] : Set (i ⊔ u ⊔ e ⊔ t) where\n constructor [_]\n field\n {Γ Δ} : Ctxt\n {ρ̂} : Γ ⇨̂ Δ\n ρ : Sub T ρ̂\n\n infix 4 _≅-⇨_\n\n _≅-⇨_ : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} (ρ₁ : Sub T ρ̂₁)\n {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} (ρ₂ : Sub T ρ̂₂) → Set _\n ρ₁ ≅-⇨ ρ₂ = _≡_ {A = [⇨]} [ ρ₁ ] [ ρ₂ ]\n\n ≅-⇨-⇒-≡ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} {ρ₁ ρ₂ : Sub T ρ̂} →\n ρ₁ ≅-⇨ ρ₂ → ρ₁ ≡ ρ₂\n ≅-⇨-⇒-≡ P.refl = P.refl\n\n -- Certain uses of substitutivity can be removed.\n\n drop-subst-Sub :\n ∀ {a} {A : Set a} {x₁ x₂ : A} {Γ Δ}\n (f : A → Γ ⇨̂ Δ) {ρ} (eq : x₁ ≡ x₂) →\n P.subst (λ x → Sub T (f x)) eq ρ ≅-⇨ ρ\n drop-subst-Sub f P.refl = P.refl\n\n -- Equality of sequences of substitutions.\n\n record [⇨⋆] : Set (i ⊔ u ⊔ e ⊔ t) where\n constructor [_]\n field\n {Γ Δ} : Ctxt\n {ρ̂} : Γ ⇨̂ Δ\n ρs : Subs T ρ̂\n\n infix 4 _≅-⇨⋆_\n\n _≅-⇨⋆_ : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} (ρs₁ : Subs T ρ̂₁)\n {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} (ρs₂ : Subs T ρ̂₂) → Set _\n ρs₁ ≅-⇨⋆ ρs₂ = _≡_ {A = [⇨⋆]} [ ρs₁ ] [ ρs₂ ]\n\n ≅-⇨⋆-⇒-≡ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} {ρs₁ ρs₂ : Subs T ρ̂} →\n ρs₁ ≅-⇨⋆ ρs₂ → ρs₁ ≡ ρs₂\n ≅-⇨⋆-⇒-≡ P.refl = P.refl\n\n -- Interpretation of substitutions: context morphisms.\n\n ⟦_⟧⇨ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → Γ ⇨̂ Δ\n ⟦_⟧⇨ {ρ̂ = ρ̂} _ = ρ̂\n\n ⟦_⟧⇨⋆ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Subs T ρ̂ → Γ ⇨̂ Δ\n ⟦_⟧⇨⋆ {ρ̂ = ρ̂} _ = ρ̂\n\n -- Application of substitutions to types.\n\n infixl 8 _/I_ _/_ _/⋆_\n\n _/I_ : ∀ {Γ Δ i} {ρ̂ : Γ ⇨̂ Δ} → IType Γ i → Sub T ρ̂ → IType Δ i\n σ /I ρ = σ /̂I ⟦ ρ ⟧⇨\n\n _/_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Type Γ → Sub T ρ̂ → Type Δ\n σ / ρ = σ /̂ ⟦ ρ ⟧⇨\n\n _/⋆_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Type Γ → Subs T ρ̂ → Type Δ\n σ /⋆ ρs = σ /̂ ⟦ ρs ⟧⇨⋆\n\n -- Application of substitutions to values.\n\n infixl 8 _/Val_\n\n _/Val_ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} →\n Value Γ σ → Sub T ρ̂ → Value Δ (σ /̂ ρ̂)\n v /Val ρ = v /̂Val ⟦ ρ ⟧⇨\n\n -- Application of substitutions to context extensions.\n\n infixl 8 _/⁺_ _/⁺⋆_ _/₊_ _/₊⋆_\n\n _/⁺_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Ctxt⁺ Γ → Sub T ρ̂ → Ctxt⁺ Δ\n Γ⁺ /⁺ ρ = Γ⁺ /̂⁺ ⟦ ρ ⟧⇨\n\n _/⁺⋆_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Ctxt⁺ Γ → Subs T ρ̂ → Ctxt⁺ Δ\n Γ⁺ /⁺⋆ ρs = Γ⁺ /̂⁺ ⟦ ρs ⟧⇨⋆\n\n _/₊_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Ctxt₊ Γ → Sub T ρ̂ → Ctxt₊ Δ\n Γ₊ /₊ ρ = Γ₊ /̂₊ ⟦ ρ ⟧⇨\n\n _/₊⋆_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Ctxt₊ Γ → Subs T ρ̂ → Ctxt₊ Δ\n Γ₊ /₊⋆ ρs = Γ₊ /̂₊ ⟦ ρs ⟧⇨⋆\n\n -- Application of substitutions to variables.\n\n infixl 8 _/∋_ _/∋-lemma_\n\n _/∋_ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} → Γ ∋ σ → (ρ : Sub T ρ̂) → Δ ⊢ σ / ρ\n zero /∋ (ρ ▻ y) = y\n suc x /∋ (ρ ▻ y) = x /∋ ρ\n\n abstract\n\n _/∋-lemma_ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (x : Γ ∋ σ) (ρ : Sub T ρ̂) →\n x /̂∋ ⟦ ρ ⟧⇨ ≅-Value ⟦ x /∋ ρ ⟧\n zero /∋-lemma (ρ ▻ y) = P.refl\n suc x /∋-lemma (ρ ▻ y) = x /∋-lemma ρ\n\n app∋ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → [ Var ⟶ T ] ρ̂\n app∋ ρ = record\n { function = λ _ x → x /∋ ρ\n ; corresponds = λ _ x → x /∋-lemma ρ\n }\n\n -- The tail of a nonempty substitution.\n\n tail : ∀ {Γ Δ σ} {ρ̂ : Γ ▻ σ ⇨̂ Δ} → Sub T ρ̂ → Sub T (t̂ail ρ̂)\n tail (ρ ▻ t) = ρ\n\n -- The head of a nonempty substitution.\n\n head : ∀ {Γ Δ σ} {ρ̂ : Γ ▻ σ ⇨̂ Δ} (ρ : Sub T ρ̂) → Δ ⊢ σ / tail ρ\n head (ρ ▻ t) = t\n\n head-lemma : ∀ {Γ Δ σ} {ρ̂ : Γ ▻ σ ⇨̂ Δ} (ρ : Sub T ρ̂) →\n ĥead ⟦ ρ ⟧⇨ ≅-Value ⟦ head ρ ⟧\n head-lemma (ρ ▻ t) = P.refl\n\n -- Fold for sequences of substitutions.\n\n fold : ∀ {f} (F : ∀ {Γ Δ} → Γ ⇨̂ Δ → Set f) {Γ} →\n F (îd {Γ = Γ}) →\n (∀ {Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} →\n F ρ̂₁ → Sub T ρ̂₂ → F (ρ̂₁ ∘̂ ρ̂₂)) →\n ∀ {Δ} {ρ̂ : Γ ⇨̂ Δ} → Subs T ρ̂ → F ρ̂\n fold F nil cons ε = nil\n fold F nil cons (ρs ▻ ρ) = cons (fold F nil cons ρs) ρ\n\n -- Some congruence lemmas.\n\n ε⇨-cong : ∀ {Δ₁ Δ₂} → Δ₁ ≅-Ctxt Δ₂ → ε⇨[ Δ₁ ] ≅-⇨ ε⇨[ Δ₂ ]\n ε⇨-cong P.refl = P.refl\n\n ▻⇨-cong :\n ∀ {Γ₁ Δ₁ σ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁} {t₁ : Δ₁ ⊢ σ₁ / ρ₁}\n {Γ₂ Δ₂ σ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} {t₂ : Δ₂ ⊢ σ₂ / ρ₂} →\n σ₁ ≅-Type σ₂ → ρ₁ ≅-⇨ ρ₂ → t₁ ≅-⊢ t₂ →\n ρ₁ ▻⇨[ σ₁ ] t₁ ≅-⇨ ρ₂ ▻⇨[ σ₂ ] t₂\n ▻⇨-cong P.refl P.refl P.refl = P.refl\n\n ε⇨⋆-cong : ∀ {Γ₁ Γ₂} → Γ₁ ≡ Γ₂ → ε⇨⋆[ Γ₁ ] ≅-⇨⋆ ε⇨⋆[ Γ₂ ]\n ε⇨⋆-cong P.refl = P.refl\n\n ▻⇨⋆-cong :\n ∀ {Γ₁ Δ₁ Ε₁} {ρ̂₁₁ : Γ₁ ⇨̂ Δ₁} {ρ̂₂₁ : Δ₁ ⇨̂ Ε₁}\n {ρs₁ : Subs T ρ̂₁₁} {ρ₁ : Sub T ρ̂₂₁}\n {Γ₂ Δ₂ Ε₂} {ρ̂₁₂ : Γ₂ ⇨̂ Δ₂} {ρ̂₂₂ : Δ₂ ⇨̂ Ε₂}\n {ρs₂ : Subs T ρ̂₁₂} {ρ₂ : Sub T ρ̂₂₂} →\n ρs₁ ≅-⇨⋆ ρs₂ → ρ₁ ≅-⇨ ρ₂ → ρs₁ ▻ ρ₁ ≅-⇨⋆ ρs₂ ▻ ρ₂\n ▻⇨⋆-cong P.refl P.refl = P.refl\n\n ⟦⟧⇨-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}\n {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →\n ρ₁ ≅-⇨ ρ₂ → ⟦ ρ₁ ⟧⇨ ≅-⇨̂ ⟦ ρ₂ ⟧⇨\n ⟦⟧⇨-cong P.refl = P.refl\n\n /I-cong :\n ∀ {i}\n {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {σ₁ : IType Γ₁ i} {ρ₁ : Sub T ρ̂₁}\n {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {σ₂ : IType Γ₂ i} {ρ₂ : Sub T ρ̂₂} →\n σ₁ ≅-IType σ₂ → ρ₁ ≅-⇨ ρ₂ → σ₁ /I ρ₁ ≅-IType σ₂ /I ρ₂\n /I-cong P.refl P.refl = P.refl\n\n /-cong : ∀ {Γ₁ Δ₁ σ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}\n {Γ₂ Δ₂ σ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →\n σ₁ ≅-Type σ₂ → ρ₁ ≅-⇨ ρ₂ → σ₁ / ρ₁ ≅-Type σ₂ / ρ₂\n /-cong P.refl P.refl = P.refl\n\n /⁺-cong : ∀ {Γ₁ Δ₁ Γ⁺₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}\n {Γ₂ Δ₂ Γ⁺₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →\n Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → ρ₁ ≅-⇨ ρ₂ → Γ⁺₁ /⁺ ρ₁ ≅-Ctxt⁺ Γ⁺₂ /⁺ ρ₂\n /⁺-cong P.refl P.refl = P.refl\n\n /⁺⋆-cong : ∀ {Γ₁ Δ₁ Γ⁺₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρs₁ : Subs T ρ̂₁}\n {Γ₂ Δ₂ Γ⁺₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρs₂ : Subs T ρ̂₂} →\n Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → ρs₁ ≅-⇨⋆ ρs₂ →\n Γ⁺₁ /⁺⋆ ρs₁ ≅-Ctxt⁺ Γ⁺₂ /⁺⋆ ρs₂\n /⁺⋆-cong P.refl P.refl = P.refl\n\n /₊-cong : ∀ {Γ₁ Δ₁ Γ₊₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}\n {Γ₂ Δ₂ Γ₊₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →\n Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ρ₁ ≅-⇨ ρ₂ → Γ₊₁ /₊ ρ₁ ≅-Ctxt₊ Γ₊₂ /₊ ρ₂\n /₊-cong P.refl P.refl = P.refl\n\n /₊⋆-cong : ∀ {Γ₁ Δ₁ Γ₊₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρs₁ : Subs T ρ̂₁}\n {Γ₂ Δ₂ Γ₊₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρs₂ : Subs T ρ̂₂} →\n Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ρs₁ ≅-⇨⋆ ρs₂ →\n Γ₊₁ /₊⋆ ρs₁ ≅-Ctxt₊ Γ₊₂ /₊⋆ ρs₂\n /₊⋆-cong P.refl P.refl = P.refl\n\n /∋-cong : ∀ {Γ₁ Δ₁ σ₁} {x₁ : Γ₁ ∋ σ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}\n {Γ₂ Δ₂ σ₂} {x₂ : Γ₂ ∋ σ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →\n x₁ ≅-∋ x₂ → ρ₁ ≅-⇨ ρ₂ → x₁ /∋ ρ₁ ≅-⊢ x₂ /∋ ρ₂\n /∋-cong P.refl P.refl = P.refl\n\n tail-cong : ∀ {Γ₁ Δ₁ σ₁} {ρ̂₁ : Γ₁ ▻ σ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}\n {Γ₂ Δ₂ σ₂} {ρ̂₂ : Γ₂ ▻ σ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →\n ρ₁ ≅-⇨ ρ₂ → tail ρ₁ ≅-⇨ tail ρ₂\n tail-cong P.refl = P.refl\n\n head-cong : ∀ {Γ₁ Δ₁ σ₁} {ρ̂₁ : Γ₁ ▻ σ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}\n {Γ₂ Δ₂ σ₂} {ρ̂₂ : Γ₂ ▻ σ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →\n ρ₁ ≅-⇨ ρ₂ → head ρ₁ ≅-⊢ head ρ₂\n head-cong P.refl = P.refl\n\n abstract\n\n -- Some eta-laws.\n\n ηε : ∀ {Δ} {ρ̂ : ε ⇨̂ Δ} (ρ : Sub T ρ̂) → ρ ≅-⇨ ε⇨[ Δ ]\n ηε ε = P.refl\n\n η▻ : ∀ {Γ Δ σ} {ρ̂ : Γ ▻ σ ⇨̂ Δ} (ρ : Sub T ρ̂) →\n ρ ≅-⇨ tail ρ ▻⇨[ σ ] head ρ\n η▻ (ρ ▻ t) = P.refl\n\n -- Two substitutions are equal if their indices are equal and\n -- their projections are pairwise equal.\n\n extensionality :\n ∀ {Γ Δ₁} {ρ̂₁ : Γ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}\n {Δ₂} {ρ̂₂ : Γ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →\n Δ₁ ≅-Ctxt Δ₂ → (∀ {σ} (x : Γ ∋ σ) → x /∋ ρ₁ ≅-⊢ x /∋ ρ₂) →\n ρ₁ ≅-⇨ ρ₂\n extensionality {ρ₁ = ε} {ρ₂ = ε} Δ₁≅Δ₂ hyp = ε⇨-cong Δ₁≅Δ₂\n extensionality {ρ₁ = ρ₁ ▻ t₁} {ρ₂ = ρ₂ ▻ t₂} Δ₁≅Δ₂ hyp =\n ▻⇨-cong P.refl\n (extensionality Δ₁≅Δ₂ (hyp ∘ suc))\n (hyp zero)\n\nopen Dummy₂ public\n", "meta": {"hexsha": "915f0c6ee080f29bf90306215cd27a3290327b53", "size": 11215, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "deBruijn/Substitution/Data/Basics.agda", "max_stars_repo_name": "nad/dependently-typed-syntax", "max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z", "max_issues_repo_path": "deBruijn/Substitution/Data/Basics.agda", "max_issues_repo_name": "nad/dependently-typed-syntax", "max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "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": "deBruijn/Substitution/Data/Basics.agda", "max_forks_repo_name": "nad/dependently-typed-syntax", "max_forks_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "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": 32.1346704871, "max_line_length": 107, "alphanum_fraction": 0.4056174766, "num_tokens": 6405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6261241632752915, "lm_q2_score": 0.600188359260205, "lm_q1q2_score": 0.3757924342493659}} {"text": "{-# OPTIONS --show-implicit #-}\n\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Unit\n\npostulate\n A B C D : Set\n F : (A → A) → (A → A → A) → A\n a : A\n\ndata Tree : Set where\n leaf : Tree\n node : (f : (x : A) → Tree) → Tree\n\ntree1 : Nat → Tree\ntree1 zero = leaf\ntree1 (suc n) = node (λ x → tree1 n)\n\ntree2 : Nat → Tree\ntree2 zero = leaf\ntree2 (suc n) = node (λ x → tree2 n)\n\n-- In Agda 2.6.0.1, this takes >50 sec and >5GB to typecheck.\ntest : tree1 5000 ≡ tree2 5000\ntest = refl\n", "meta": {"hexsha": "cdcf326fe906c0c081553b3e19067da4529b873c", "size": 523, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue4044.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue4044.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue4044.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 19.3703703704, "max_line_length": 61, "alphanum_fraction": 0.6195028681, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7341195385342971, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.3756611577057592}} {"text": "-- Andreas, 2018-06-10, issue #3124\n-- Wrong context for error IrrelevantDatatype in the coverage checker.\n\ndata Squash (A : Set) : Prop where\n squash : A → Squash A\n\ntest : ∀{A} → Squash (Squash A → A)\ntest = squash λ{ (squash y) → y }\n\n-- WAS: de Bruijn index in error message\n\n-- Expected error:\n-- Cannot split on argument of irrelevant datatype (Squash .A)\n-- when checking the definition of .extendedlambda0\n", "meta": {"hexsha": "1cb1faac6f3735b9c1f677b1fd7a0da507f1ec9f", "size": 415, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue3124.agda", "max_stars_repo_name": "alhassy/agda", "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-07T10:49:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-07T10:49:57.000Z", "max_issues_repo_path": "test/Fail/Issue3124.agda", "max_issues_repo_name": "alhassy/agda", "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "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/Issue3124.agda", "max_forks_repo_name": "alhassy/agda", "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "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": 27.6666666667, "max_line_length": 70, "alphanum_fraction": 0.6987951807, "num_tokens": 123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.37520095843255735}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Basics\nopen import lib.types.Bool\nopen import lib.types.Empty\nopen import lib.types.Lift\nopen import lib.types.Sigma\nopen import lib.types.Pi\n\nmodule lib.types.Coproduct where\n\nmodule _ {i j} {A : Type i} {B : Type j} where\n\n Coprod-elim : ∀ {k} {C : A ⊔ B → Type k}\n → ((a : A) → C (inl a)) → ((b : B) → C (inr b))\n → Π (A ⊔ B) C\n Coprod-elim f g (inl a) = f a\n Coprod-elim f g (inr b) = g b\n\n ⊔-elim = Coprod-elim\n\n Coprod-rec : ∀ {k} {C : Type k}\n → (A → C) → (B → C) → (A ⊔ B → C)\n Coprod-rec {C = C} = Coprod-elim {C = λ _ → C}\n\n ⊔-rec = Coprod-rec\n\n Coprod= : Coprod A B → Coprod A B → Type (lmax i j)\n Coprod= (inl a₁) (inl a₂) = Lift {j = (lmax i j)} $ a₁ == a₂\n Coprod= (inl a₁) (inr b₂) = Lift Empty\n Coprod= (inr b₁) (inl a₂) = Lift Empty\n Coprod= (inr b₁) (inr b₂) = Lift {j = (lmax i j)} $ b₁ == b₂\n\n Coprod=-in : {x y : Coprod A B} → (x == y) → Coprod= x y\n Coprod=-in {inl _} idp = lift idp\n Coprod=-in {inr _} idp = lift idp\n\n Coprod=-out : {x y : Coprod A B} → Coprod= x y → (x == y)\n Coprod=-out {inl _} {inl _} c = ap inl $ lower c\n Coprod=-out {inl _} {inr _} c = Empty-rec $ lower c\n Coprod=-out {inr _} {inl _} c = Empty-rec $ lower c\n Coprod=-out {inr _} {inr _} c = ap inr (lower c)\n\n Coprod=-in-equiv : (x y : Coprod A B) → (x == y) ≃ Coprod= x y\n Coprod=-in-equiv x y = equiv Coprod=-in Coprod=-out (f-g x y) (g-f x y)\n where f-g : ∀ x' y' → ∀ c → Coprod=-in (Coprod=-out {x'} {y'} c) == c\n f-g (inl a₁) (inl .a₁) (lift idp) = idp\n f-g (inl a₁) (inr b₂) b = Empty-rec $ lower b\n f-g (inr b₁) (inl a₂) b = Empty-rec $ lower b\n f-g (inr b₁) (inr .b₁) (lift idp) = idp\n\n g-f : ∀ x' y' → ∀ p → Coprod=-out (Coprod=-in {x'} {y'} p) == p\n g-f (inl _) .(inl _) idp = idp\n g-f (inr _) .(inr _) idp = idp\n\n inl=inl-equiv : (a₁ a₂ : A) → (inl a₁ == inl a₂) ≃ (a₁ == a₂)\n inl=inl-equiv a₁ a₂ = lower-equiv ∘e Coprod=-in-equiv (inl a₁) (inl a₂)\n\n inr=inr-equiv : (b₁ b₂ : B) → (inr b₁ == inr b₂) ≃ (b₁ == b₂)\n inr=inr-equiv b₁ b₂ = lower-equiv ∘e Coprod=-in-equiv (inr b₁) (inr b₂)\n\n inl≠inr : (a₁ : A) (b₂ : B) → (inl a₁ ≠ inr b₂)\n inl≠inr a₁ b₂ p = lower $ Coprod=-in p\n\n inr≠inl : (b₁ : B) (a₂ : A) → (inr b₁ ≠ inl a₂)\n inr≠inl a₁ b₂ p = lower $ Coprod=-in p\n\n instance\n ⊔-level : ∀ {n} → has-level (S (S n)) A → has-level (S (S n)) B\n → has-level (S (S n)) (Coprod A B)\n ⊔-level {n} pA pB = has-level-in (⊔-level-aux pA pB) where\n \n instance _ = pA; _ = pB\n\n ⊔-level-aux : has-level (S (S n)) A → has-level (S (S n)) B\n → has-level-aux (S (S n)) (Coprod A B)\n ⊔-level-aux _ _ (inl a₁) (inl a₂) = equiv-preserves-level (inl=inl-equiv a₁ a₂ ⁻¹)\n ⊔-level-aux _ _ (inl a₁) (inr b₂) = has-level-in (λ p → Empty-rec (inl≠inr a₁ b₂ p))\n ⊔-level-aux _ _ (inr b₁) (inl a₂) = has-level-in (λ p → Empty-rec (inr≠inl b₁ a₂ p))\n ⊔-level-aux _ _ (inr b₁) (inr b₂) = equiv-preserves-level ((inr=inr-equiv b₁ b₂)⁻¹)\n\n Coprod-level = ⊔-level\n\nmodule _ {i j} {A : Type i} {B : Type j} where\n\n Coprod-rec-post∘ : ∀ {k l} {C : Type k} {D : Type l}\n → (h : C → D) (f : A → C) (g : B → C)\n → h ∘ Coprod-rec f g ∼ Coprod-rec (h ∘ f) (h ∘ g)\n Coprod-rec-post∘ h f g (inl _) = idp\n Coprod-rec-post∘ h f g (inr _) = idp\n\n ⊔-rec-post∘ = Coprod-rec-post∘\n\nmodule _ {i i' j j'} {A : Type i} {A' : Type i'} {B : Type j} {B' : Type j'}\n (f : A → A') (g : B → B') where\n\n ⊔-fmap : A ⊔ B → A' ⊔ B'\n ⊔-fmap (inl a) = inl (f a)\n ⊔-fmap (inr b) = inr (g b)\n\ninfix 80 _⊙⊔_\n_⊙⊔_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j)\nX ⊙⊔ Y = ⊙[ Coprod (de⊙ X) (de⊙ Y) , inl (pt X) ]\n\n_⊔⊙_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j)\nX ⊔⊙ Y = ⊙[ Coprod (de⊙ X) (de⊙ Y) , inr (pt Y) ]\n\nmodule _ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n (f : X ⊙→ Z) (g : Y ⊙→ Z) where\n\n ⊙⊔-rec : X ⊙⊔ Y ⊙→ Z\n ⊙⊔-rec = Coprod-rec (fst f) (fst g) , snd f\n\n ⊔⊙-rec : X ⊔⊙ Y ⊙→ Z\n ⊔⊙-rec = Coprod-rec (fst f) (fst g) , snd g\n\nmodule _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}\n (f : X ⊙→ X') (g : Y ⊙→ Y') where\n\n ⊙⊔-fmap : X ⊙⊔ Y ⊙→ X' ⊙⊔ Y'\n ⊙⊔-fmap = ⊔-fmap (fst f) (fst g) , ap inl (snd f)\n\n ⊔⊙-fmap : X ⊔⊙ Y ⊙→ X' ⊔⊙ Y'\n ⊔⊙-fmap = ⊔-fmap (fst f) (fst g) , ap inr (snd g)\n\ncodiag : ∀ {i} {A : Type i} → A ⊔ A → A\ncodiag = Coprod-rec (idf _) (idf _)\n\n⊙codiag : ∀ {i} {X : Ptd i} → X ⊙⊔ X ⊙→ X\n⊙codiag = (codiag , idp)\n\n-- A binary sigma is a coproduct\nΣBool-equiv-⊔ : ∀ {i} (Pick : Bool → Type i)\n → Σ Bool Pick ≃ Pick true ⊔ Pick false\nΣBool-equiv-⊔ Pick = equiv into out into-out out-into\n where\n into : Σ _ Pick → Pick true ⊔ Pick false\n into (true , a) = inl a\n into (false , b) = inr b\n\n out : (Pick true ⊔ Pick false) → Σ _ Pick\n out (inl a) = (true , a)\n out (inr b) = (false , b)\n\n abstract\n into-out : ∀ c → into (out c) == c\n into-out (inl a) = idp\n into-out (inr b) = idp\n\n out-into : ∀ s → out (into s) == s\n out-into (true , a) = idp\n out-into (false , b) = idp\n\n⊔₁-Empty : ∀ {i} (A : Type i) → Empty ⊔ A ≃ A\n⊔₁-Empty A = equiv (λ{(inl ()); (inr a) → a}) inr (λ _ → idp) (λ{(inl ()); (inr _) → idp})\n\nmodule _ {i j k} {A : Type i} {B : Type j} (P : A ⊔ B → Type k) where\n Π₁-⊔-equiv-× : Π (A ⊔ B) P ≃ Π A (P ∘ inl) × Π B (P ∘ inr)\n Π₁-⊔-equiv-× = equiv to from to-from from-to\n where\n to : Π (A ⊔ B) P → Π A (P ∘ inl) × Π B (P ∘ inr)\n to f = (λ a → f (inl a)) , (λ b → f (inr b))\n\n from : Π A (P ∘ inl) × Π B (P ∘ inr) → Π (A ⊔ B) P\n from (f , g) (inl a) = f a\n from (f , g) (inr b) = g b\n\n abstract\n to-from : ∀ fg → to (from fg) == fg\n to-from _ = idp\n\n from-to : ∀ fg → from (to fg) == fg\n from-to fg = λ= λ where (inl _) → idp\n (inr _) → idp\n", "meta": {"hexsha": "78f9e16db0954ec35912ec51832db2bc0e153e2b", "size": 5787, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/types/Coproduct.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "core/lib/types/Coproduct.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "core/lib/types/Coproduct.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": 33.0685714286, "max_line_length": 90, "alphanum_fraction": 0.4950751685, "num_tokens": 2782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6370307944803831, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.37514051083389427}} {"text": "{-# OPTIONS --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Substitution.Introductions.Snd {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped as U hiding (wk)\nopen import Definition.Untyped.Properties\nopen import Definition.Typed\nopen import Definition.Typed.Properties\nopen import Definition.Typed.Weakening as T hiding (wk; wkTerm; wkEqTerm)\nopen import Definition.Typed.RedSteps\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.ShapeView\nopen import Definition.LogicalRelation.Irrelevance\nopen import Definition.LogicalRelation.Weakening\nopen import Definition.LogicalRelation.Properties\nopen import Definition.LogicalRelation.Application\nopen import Definition.LogicalRelation.Substitution\nopen import Definition.LogicalRelation.Substitution.Properties\nopen import Definition.LogicalRelation.Substitution.Reflexivity\nopen import Definition.LogicalRelation.Substitution.Introductions.Sigma\nopen import Definition.LogicalRelation.Substitution.Introductions.Fst\nopen import Definition.LogicalRelation.Substitution.Introductions.Pi\nopen import Definition.LogicalRelation.Substitution.Introductions.SingleSubst\nopen import Definition.LogicalRelation.Substitution.MaybeEmbed\nopen import Definition.LogicalRelation.Substitution.Introductions.Universe\n\nopen import Tools.Product\nimport Tools.PropositionalEquality as PE\n\n-- Valid snd term construction.\nsndᵛ : ∀ {F G l∃ tu Γ}\n ([Γ] : ⊩ᵛ Γ) →\n let l = ∞\n [UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])\n [U∃] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])\n in \n ([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ % , ι l∃ ] / [Γ])\n ([G] : Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ G ^ [ % , ι l∃ ] / [Γ] ∙ [F])\n ([UG] : Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [F])\n ([Fₜ] : Γ ⊩ᵛ⟨ l ⟩ F ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] / [UF])\n ([Gₜ] : Γ ∙ F ^ [ % , ι l∃ ] ⊩ᵛ⟨ l ⟩ G ∷ Univ % l∃ ^ [ ! , next l∃ ] / [Γ] ∙ [F] / (λ {Δ} {σ} → [UG] {Δ} {σ}))\n ([tu] : Γ ⊩ᵛ⟨ l ⟩ tu ∷ ∃ F ▹ G ^ [ % , ι l∃ ] / [Γ] / ∃ᵛ {F} {G} [Γ] [F] [G])\n → Γ ⊩ᵛ⟨ l ⟩ snd tu ∷ G [ fst tu ] ^ [ % , ι l∃ ] / [Γ] / substS {F} {G} {fst tu} [Γ] [F] [G] (fstᵛ {F} {G} {l∃} {tu} {Γ} [Γ] [F] [G] (λ {Δ} {σ} → [UG] {Δ} {σ}) [Fₜ] [Gₜ] [tu])\nsndᵛ {F} {G} {l∃} {tu} {Γ} [Γ] [F] [G] [UG] [Fₜ] [Gₜ] [tu] {Δ = Δ} {σ = σ} ⊢Δ [σ] =\n let [fst] = fstᵛ {F} {G} {l∃} {tu} {Γ} [Γ] [F] [G] (λ {Δ} {σ} → [UG] {Δ} {σ}) [Fₜ] [Gₜ] [tu]\n [G[fsttu]] = substS {F} {G} {fst tu} [Γ] [F] [G] [fst]\n [UF] = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])\n [σUF] = proj₁ ([UF] ⊢Δ [σ])\n [σF] = proj₁ ([F] ⊢Δ [σ])\n ⊢F = escape [σF]\n [σF]ₜ = proj₁ ([Fₜ] ⊢Δ [σ])\n ⊢Fₜ = escapeTerm [σUF] [σF]ₜ\n [σUG] = proj₁ ([UG] {σ = liftSubst σ} (⊢Δ ∙ ⊢F)\n (liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]))\n [σG]ₜ = proj₁ ([Gₜ] (⊢Δ ∙ ⊢F)\n (liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]))\n ⊢Gₜ = escapeTerm [σUG] [σG]ₜ\n [σtu] = proj₁ ([tu] (⊢Δ) [σ])\n [∃FG] = ∃ᵛ {F} {G} {Γ} [Γ] [F] [G]\n [σ∃FG] = proj₁ ([∃FG] ⊢Δ [σ])\n ⊢tu = escapeTerm [σ∃FG] [σtu]\n ⊢snd = sndⱼ {F = subst σ F} {G = subst (liftSubst σ) G} {t = subst σ tu}\n ⊢Fₜ ⊢Gₜ ⊢tu\n [σG[fsttu]] = proj₁ ([G[fsttu]] ⊢Δ [σ])\n ⊢sndSubst = PE.subst (λ x → _ ⊢ _ ∷ x ^ _) (PE.sym (singleSubstLift G (fst tu))) ⊢snd\n in logRelIrr [σG[fsttu]] ⊢sndSubst , \n (λ {σ′} [σ]′ [σ≡σ′] → logRelIrrEq [σG[fsttu]] ⊢sndSubst\n let [UF]′ = maybeEmbᵛ {A = Univ % _} [Γ] (Uᵛ (proj₂ (levelBounded l∃)) [Γ])\n [σUF]′ = proj₁ ([UF] ⊢Δ [σ]′)\n [σF]′ = proj₁ ([F] ⊢Δ [σ]′)\n ⊢F′ = escape [σF]′\n [σF]ₜ′ = proj₁ ([Fₜ] ⊢Δ [σ]′)\n ⊢Fₜ′ = escapeTerm [σUF]′ [σF]ₜ′\n [σUG]′ = proj₁ ([UG] {σ = liftSubst σ′} (⊢Δ ∙ ⊢F′)\n (liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]′))\n [σG]ₜ′ = proj₁ ([Gₜ] (⊢Δ ∙ ⊢F′)\n (liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]′))\n ⊢Gₜ′ = escapeTerm [σUG]′ [σG]ₜ′\n [σtu]′ = proj₁ ([tu] (⊢Δ) [σ]′)\n [σ∃FG]′ = proj₁ ([∃FG] ⊢Δ [σ]′)\n ⊢tu′ = escapeTerm [σ∃FG]′ [σtu]′\n ⊢snd′ = sndⱼ {F = subst σ′ F} {G = subst (liftSubst σ′) G} {t = subst σ′ tu}\n ⊢Fₜ′ ⊢Gₜ′ ⊢tu′\n [σG[fsttu]′] = proj₁ ([G[fsttu]] ⊢Δ [σ]′)\n ⊢sndSubst′ = PE.subst (λ x → _ ⊢ _ ∷ x ^ _) (PE.sym (singleSubstLift G (fst tu))) ⊢snd′\n [σG[fsttu]≡σG[fsttu]′] = proj₂ ([G[fsttu]] ⊢Δ [σ]) [σ]′ [σ≡σ′]\n ⊢σG[fsttu]≡σG[fsttu]′ = escapeEq [σG[fsttu]] [σG[fsttu]≡σG[fsttu]′]\n in conv ⊢sndSubst′ (≅-eq (≅-sym ⊢σG[fsttu]≡σG[fsttu]′)) ) \n", "meta": {"hexsha": "87e2a41b0d5c9ff62d38d0136fc17199920e8660", "size": 4741, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Snd.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/LogicalRelation/Substitution/Introductions/Snd.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/LogicalRelation/Substitution/Introductions/Snd.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": 51.5326086957, "max_line_length": 183, "alphanum_fraction": 0.5199325037, "num_tokens": 2162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6370307944803831, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.37514051083389427}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Basics\nopen import lib.types.Coproduct\nopen import lib.types.Paths\nopen import lib.types.Pointed\nopen import lib.types.Pushout\nopen import lib.types.PushoutFlattening\nopen import lib.types.PushoutFmap\nopen import lib.types.Sigma\nopen import lib.types.Span\nopen import lib.types.Unit\n\n-- Wedge of two pointed types is defined as a particular case of pushout\n\nmodule lib.types.Wedge where\n\nmodule _ {i j} (X : Ptd i) (Y : Ptd j) where\n\n ⊙∨-span : ⊙Span\n ⊙∨-span = ⊙span X Y ⊙Unit ⊙cst ⊙cst\n ⊙wedge-span = ⊙∨-span\n\n ∨-span : Span\n ∨-span = ⊙Span-to-Span ⊙∨-span\n wedge-span = ∨-span\n\n Wedge : Type (lmax i j)\n Wedge = Pushout wedge-span\n\n infix 80 _∨_\n _∨_ = Wedge\n\n ⊙Wedge : Ptd (lmax i j)\n ⊙Wedge = ⊙Pushout ⊙wedge-span\n\n infix 80 _⊙∨_\n _⊙∨_ = ⊙Wedge\n\nmodule _ {i j} {X : Ptd i} {Y : Ptd j} where\n\n winl : de⊙ X → X ∨ Y\n winl x = left x\n\n winr : de⊙ Y → X ∨ Y\n winr y = right y\n\n wglue : winl (pt X) == winr (pt Y)\n wglue = glue tt\n\n ⊙winl : X ⊙→ X ⊙∨ Y\n ⊙winl = (winl , idp)\n\n ⊙winr : Y ⊙→ X ⊙∨ Y\n ⊙winr = (winr , ! wglue)\n\n module WedgeElim {k} {P : X ∨ Y → Type k}\n (winl* : (x : de⊙ X) → P (winl x)) (winr* : (y : de⊙ Y) → P (winr y))\n (glue* : winl* (pt X) == winr* (pt Y) [ P ↓ wglue ]) where\n\n private\n module M = PushoutElim winl* winr* (λ _ → glue*)\n\n f = M.f\n glue-β = M.glue-β unit\n\n ∨-elim = WedgeElim.f\n Wedge-elim = WedgeElim.f\n\n module WedgeRec {k} {C : Type k} (winl* : de⊙ X → C) (winr* : de⊙ Y → C)\n (glue* : winl* (pt X) == winr* (pt Y)) where\n\n private\n module M = PushoutRec {d = wedge-span X Y} winl* winr* (λ _ → glue*)\n\n f = M.f\n glue-β = M.glue-β unit\n\n ∨-rec = WedgeRec.f\n Wedge-rec = WedgeRec.f\n\n module ⊙WedgeRec {k} {Z : Ptd k} (g : X ⊙→ Z) (h : Y ⊙→ Z) where\n\n open WedgeRec (fst g) (fst h) (snd g ∙ ! (snd h)) public\n\n ⊙f : X ⊙∨ Y ⊙→ Z\n ⊙f = (f , snd g)\n\n ⊙winl-β : ⊙f ⊙∘ ⊙winl == g\n ⊙winl-β = idp\n\n ⊙winr-β : ⊙f ⊙∘ ⊙winr == h\n ⊙winr-β = ⊙λ=' (λ _ → idp) lemma where\n abstract\n lemma : snd (⊙f ⊙∘ ⊙winr) == snd h\n lemma =\n ap (_∙ snd g)\n (ap-! f wglue ∙ ap ! glue-β ∙ !-∙ (snd g) (! (snd h)))\n ∙ ∙-assoc (! (! (snd h))) (! (snd g)) (snd g)\n ∙ ap (! (! (snd h)) ∙_) (!-inv-l (snd g))\n ∙ ∙-unit-r (! (! (snd h)))\n ∙ !-! (snd h)\n\n ⊙∨-rec = ⊙WedgeRec.⊙f\n ⊙Wedge-rec = ⊙WedgeRec.⊙f\n\n ⊙Wedge-rec-post∘ : ∀ {k l} {Z : Ptd k} {W : Ptd l}\n (k : Z ⊙→ W) (g : X ⊙→ Z) (h : Y ⊙→ Z)\n → k ⊙∘ ⊙Wedge-rec g h ⊙∼ ⊙Wedge-rec (k ⊙∘ g) (k ⊙∘ h)\n ⊙Wedge-rec-post∘ k g h =\n (Wedge-elim (λ _ → idp) (λ _ → idp)\n (↓-='-in' $ ⊙WedgeRec.glue-β (k ⊙∘ g) (k ⊙∘ h)\n ∙ lemma (fst k) (snd g) (snd h) (snd k)\n ∙ ! (ap (ap (fst k)) (⊙WedgeRec.glue-β g h))\n ∙ ∘-ap (fst k) (fst (⊙Wedge-rec g h)) wglue)) ,\n idp\n where\n lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y z : A} {w : B}\n (p : x == z) (q : y == z) (r : f z == w)\n → (ap f p ∙ r) ∙ ! (ap f q ∙ r) == ap f (p ∙ ! q)\n lemma f idp idp idp = idp\n ⊙∨-rec-post∘ = ⊙Wedge-rec-post∘\n\n ⊙Wedge-rec-η : ⊙Wedge-rec ⊙winl ⊙winr == ⊙idf (X ⊙∨ Y)\n ⊙Wedge-rec-η = ⊙λ='\n (Wedge-elim (λ _ → idp) (λ _ → idp)\n (↓-='-in' $ ap-idf wglue\n ∙ ! (!-! wglue)\n ∙ ! (⊙WedgeRec.glue-β ⊙winl ⊙winr)))\n idp\n ⊙∨-rec-η = ⊙Wedge-rec-η\n\n add-wglue : de⊙ (X ⊙⊔ Y) → X ∨ Y\n add-wglue (inl x) = winl x\n add-wglue (inr y) = winr y\n\n ⊙add-wglue : X ⊙⊔ Y ⊙→ X ⊙∨ Y\n ⊙add-wglue = add-wglue , idp\n\n module Projl = ⊙WedgeRec (⊙idf X) (⊙cst {X = Y})\n module Projr = ⊙WedgeRec (⊙cst {X = X}) (⊙idf Y)\n\n projl = Projl.f\n projr = Projr.f\n ⊙projl = Projl.⊙f\n ⊙projr = Projr.⊙f\n\n module WedgeToProduct = ⊙WedgeRec ((_, pt Y) , idp) ((pt X ,_), idp)\n\n ∨-⊙to-× : X ⊙∨ Y ⊙→ X ⊙× Y\n ∨-⊙to-× = WedgeToProduct.⊙f\n\n ∨-to-× : X ∨ Y → de⊙ (X ⊙× Y)\n ∨-to-× = WedgeToProduct.f\n\n ∨-to-×-glue-β : ap ∨-to-× wglue == idp\n ∨-to-×-glue-β = WedgeToProduct.glue-β\n \n abstract\n ↓-∨to×=cst-in : ∀ {x y} {p p' : (pt X , pt Y) == (x , y)}\n → p == p'\n → p == p' [ (λ w → ∨-to-× w == (x , y)) ↓ wglue ]\n ↓-∨to×=cst-in {p' = idp} q =\n ↓-app=cst-in' (q ∙ ! WedgeToProduct.glue-β)\n\n ↓-∨to×=cst-out : ∀ {x y} {p p' : (pt X , pt Y) == (x , y)}\n → p == p' [ (λ w → ∨-to-× w == (x , y)) ↓ wglue ]\n → p == p'\n ↓-∨to×=cst-out {p' = idp} q =\n ↓-app=cst-out' q ∙ WedgeToProduct.glue-β\n\n ↓-∨to×=cst-β : ∀ {x y} {p p' : (pt X , pt Y) == (x , y)}\n (q : p == p')\n → ↓-∨to×=cst-out (↓-∨to×=cst-in q) == q\n ↓-∨to×=cst-β {p' = idp} idp =\n ap (_∙ WedgeToProduct.glue-β) (↓-app=cst-β' {p = wglue} (! WedgeToProduct.glue-β))\n ∙ !-inv-l WedgeToProduct.glue-β\n\n ↓-∨to×=cst-η : ∀ {x y} {p p' : (pt X , pt Y) == (x , y)}\n (q : p == p' [ (λ w → ∨-to-× w == (x , y)) ↓ wglue ])\n → ↓-∨to×=cst-in (↓-∨to×=cst-out q) == q\n ↓-∨to×=cst-η {p = p} {p' = idp} q =\n ap ↓-app=cst-in'\n ( ∙-assoc (↓-app=cst-out' q) WedgeToProduct.glue-β (! WedgeToProduct.glue-β)\n ∙ ap (↓-app=cst-out' q ∙_) (!-inv-r WedgeToProduct.glue-β)\n ∙ ∙-unit-r (↓-app=cst-out' q))\n ∙ ↓-app=cst-η' q\n\nmodule Fold {i} {X : Ptd i} = ⊙WedgeRec (⊙idf X) (⊙idf X)\nfold = Fold.f\n⊙fold = Fold.⊙f\n\nmodule _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}\n (fX : X ⊙→ X') (fY : Y ⊙→ Y') where\n\n wedge-span-map : SpanMap (wedge-span X Y) (wedge-span X' Y')\n wedge-span-map = span-map (fst fX) (fst fY) (idf _)\n (comm-sqr λ _ → snd fX)\n (comm-sqr λ _ → snd fY)\n\n module WedgeFmap where\n private\n module M = PushoutFmap wedge-span-map\n f = M.f\n glue-β = M.glue-β unit\n\n ∨-fmap : X ∨ Y → X' ∨ Y'\n ∨-fmap = WedgeFmap.f\n\n ⊙∨-fmap : X ⊙∨ Y ⊙→ X' ⊙∨ Y'\n ⊙∨-fmap = ∨-fmap , ap winl (snd fX)\n\n Wedge-fmap = ∨-fmap\n ⊙Wedge-fmap = ⊙∨-fmap\n\nmodule _ {i₀ i₁ i₂ j₀ j₁ j₂} {X₀ : Ptd i₀} {X₁ : Ptd i₁} {X₂ : Ptd i₂}\n {Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {Y₂ : Ptd j₂}\n where\n\n ∨-fmap-∘ :\n (gX : X₁ ⊙→ X₂) (fX : X₀ ⊙→ X₁)\n (gY : Y₁ ⊙→ Y₂) (fY : Y₀ ⊙→ Y₁)\n → ∨-fmap (gX ⊙∘ fX) (gY ⊙∘ fY) ∼ ∨-fmap gX gY ∘ ∨-fmap fX fY\n ∨-fmap-∘ (gX , idp) (fX , idp) (gY , idp) (fY , idp) =\n Pushout-fmap-∘ (wedge-span-map (gX , idp) (gY , idp)) (wedge-span-map (fX , idp) (fY , idp))\n\n ⊙∨-fmap-∘ :\n (gX : X₁ ⊙→ X₂) (fX : X₀ ⊙→ X₁)\n (gY : Y₁ ⊙→ Y₂) (fY : Y₀ ⊙→ Y₁)\n → ⊙∨-fmap (gX ⊙∘ fX) (gY ⊙∘ fY) ⊙∼ ⊙∨-fmap gX gY ⊙∘ ⊙∨-fmap fX fY\n ⊙∨-fmap-∘ (gX , idp) (fX , idp) (gY , idp) (fY , idp) =\n ∨-fmap-∘ (gX , idp) (fX , idp) (gY , idp) (fY , idp) , idp\n\n Wedge-fmap-∘ = ∨-fmap-∘\n ⊙Wedge-fmap-∘ = ⊙∨-fmap-∘\n\nmodule _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}\n (eqX : X ⊙≃ X') (eqY : Y ⊙≃ Y') where\n\n wedge-span-emap : SpanEquiv (wedge-span X Y) (wedge-span X' Y')\n wedge-span-emap = wedge-span-map (⊙–> eqX) (⊙–> eqY)\n , snd eqX , snd eqY , idf-is-equiv _\n\n ∨-emap : X ∨ Y ≃ X' ∨ Y'\n ∨-emap = Pushout-emap wedge-span-emap\n\n ⊙∨-emap : X ⊙∨ Y ⊙≃ X' ⊙∨ Y'\n ⊙∨-emap = ≃-to-⊙≃ ∨-emap (ap winl (⊙–>-pt eqX))\n\n Wedge-emap = ∨-emap\n ⊙Wedge-emap = ⊙∨-emap\n\nmodule _ {i i' j j' k} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j}\n {Y' : Ptd j'} {Z : Ptd k} (winl* : X' ⊙→ Z) (winr* : Y' ⊙→ Z)\n (f : X ⊙→ X') (g : Y ⊙→ Y') where\n\n ⊙Wedge-rec-fmap :\n ⊙Wedge-rec winl* winr* ⊙∘ ⊙∨-fmap f g\n ⊙∼ ⊙Wedge-rec (winl* ⊙∘ f) (winr* ⊙∘ g)\n ⊙Wedge-rec-fmap =\n Wedge-elim (λ _ → idp) (λ _ → idp) (↓-='-in' $ ! $ lemma₀ winl* winr* f g) ,\n lemma₁ winl* winr* f\n where\n abstract\n lemma₀ : ∀ {X' Y' Z} (winl* : X' ⊙→ Z) (winr* : Y' ⊙→ Z)\n (f : X ⊙→ X') (g : Y ⊙→ Y')\n → ap (⊙WedgeRec.f winl* winr* ∘ ∨-fmap f g) wglue\n == ap (⊙WedgeRec.f (winl* ⊙∘ f) (winr* ⊙∘ g)) wglue\n lemma₀ (winl* , idp) (winr* , winr*-pt) (f , idp) (g , idp) =\n ap (Wedge-rec winl* winr* (! winr*-pt) ∘ ∨-fmap (f , idp) (g , idp)) wglue\n =⟨ ap-∘ (Wedge-rec winl* winr* (! winr*-pt)) (∨-fmap (f , idp) (g , idp)) wglue ⟩\n ap (Wedge-rec winl* winr* (! winr*-pt)) (ap (∨-fmap (f , idp) (g , idp)) wglue)\n =⟨ ap (ap (Wedge-rec winl* winr* (! winr*-pt))) $ WedgeFmap.glue-β (f , idp) (g , idp) ⟩\n ap (Wedge-rec winl* winr* (! winr*-pt)) wglue\n =⟨ WedgeRec.glue-β winl* winr* (! winr*-pt) ⟩\n ! winr*-pt\n =⟨ ! $ WedgeRec.glue-β (winl* ∘ f) (winr* ∘ g) (! winr*-pt) ⟩\n ap (Wedge-rec (winl* ∘ f) (winr* ∘ g) (! winr*-pt)) wglue\n =∎\n\n lemma₁ : ∀ {X' Z} (winl* : X' ⊙→ Z) (winr* : Y' ⊙→ Z) (f : X ⊙→ X')\n → snd (⊙Wedge-rec winl* winr* ⊙∘ ⊙∨-fmap f g)\n == snd (⊙Wedge-rec (winl* ⊙∘ f) (winr* ⊙∘ g))\n lemma₁ (f , idp) _ (winl* , idp) = idp\n ⊙∨-rec-fmap = ⊙Wedge-rec-fmap\n\nmodule _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j}\n {Y' : Ptd j'} (f : X ⊙→ X') (g : Y ⊙→ Y') where\n\n ⊙projl-fmap : ⊙projl ⊙∘ ⊙∨-fmap f g ⊙∼ ⊙Wedge-rec f ⊙cst\n ⊙projl-fmap =\n Wedge-elim (λ _ → idp) (λ _ → idp) (↓-='-in' $ ! $ lemma₀ f g) , lemma₁ f g\n where\n abstract\n lemma₀ : ∀ {X' Y'} (f : X ⊙→ X') (g : Y ⊙→ Y')\n → ap (projl ∘ ∨-fmap f g) wglue\n == ap (⊙WedgeRec.f f ⊙cst) wglue\n lemma₀ (f , idp) (g , idp) =\n ap (projl ∘ ∨-fmap (f , idp) (g , idp)) wglue\n =⟨ ap-∘ projl (∨-fmap (f , idp) (g , idp)) wglue ⟩\n ap projl (ap (∨-fmap (f , idp) (g , idp)) wglue)\n =⟨ ap (ap projl) (WedgeFmap.glue-β (f , idp) (g , idp)) ⟩\n ap projl wglue\n =⟨ Projl.glue-β ⟩\n idp\n =⟨ ! $ ⊙WedgeRec.glue-β (f , idp) ⊙cst ⟩\n ap (⊙WedgeRec.f (f , idp) ⊙cst) wglue\n =∎\n\n lemma₁ : ∀ {X' Y'} (f : X ⊙→ X') (g : Y ⊙→ Y')\n → snd (⊙projl ⊙∘ ⊙∨-fmap f g)\n == snd (⊙Wedge-rec {Y = Y} f ⊙cst)\n lemma₁ (f , idp) (g , idp) = idp\n\n ⊙projr-fmap : ⊙projr ⊙∘ ⊙∨-fmap f g ⊙∼ ⊙Wedge-rec ⊙cst g\n ⊙projr-fmap =\n Wedge-elim (λ _ → idp) (λ _ → idp) (↓-='-in' $ ! $ lemma₀ f g) , lemma₁ f g\n where\n abstract\n lemma₀ : ∀ {X' Y'} (f : X ⊙→ X') (g : Y ⊙→ Y')\n → ap (projr ∘ ∨-fmap f g) wglue\n == ap (⊙WedgeRec.f ⊙cst g) wglue\n lemma₀ (f , idp) (g , idp) =\n ap (projr ∘ ∨-fmap (f , idp) (g , idp)) wglue\n =⟨ ap-∘ projr (∨-fmap (f , idp) (g , idp)) wglue ⟩\n ap projr (ap (∨-fmap (f , idp) (g , idp)) wglue)\n =⟨ ap (ap projr) (WedgeFmap.glue-β (f , idp) (g , idp)) ⟩\n ap projr wglue\n =⟨ Projr.glue-β ⟩\n idp\n =⟨ ! $ ⊙WedgeRec.glue-β ⊙cst (g , idp) ⟩\n ap (⊙WedgeRec.f ⊙cst (g , idp)) wglue\n =∎\n\n lemma₁ : ∀ {X' Y'} (f : X ⊙→ X') (g : Y ⊙→ Y')\n → snd (⊙projr ⊙∘ ⊙∨-fmap f g)\n == snd (⊙Wedge-rec {X = X} ⊙cst g)\n lemma₁ (f , idp) (g , idp) = idp\n\nmodule _ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n (f : X ⊙→ Z) (g : Y ⊙→ Z) where\n\n {- favonia: This is a special case, but still proved separately to make sure\n it has good computational content. (Maybe this is overkilling.) -}\n ⊙fold-fmap : ⊙fold ⊙∘ ⊙∨-fmap f g ⊙∼ ⊙Wedge-rec f g\n ⊙fold-fmap =\n Wedge-elim (λ _ → idp) (λ _ → idp) (↓-='-in' $ ! $ lemma₀ f g) , lemma₁ f g\n where\n abstract\n lemma₀ : ∀ {Z} (f : X ⊙→ Z) (g : Y ⊙→ Z)\n → ap (⊙WedgeRec.f (⊙idf _) (⊙idf _) ∘ ∨-fmap f g) wglue\n == ap (⊙WedgeRec.f f g) wglue\n lemma₀ (f , idp) (g , g-pt) =\n ap (⊙WedgeRec.f (⊙idf _) (⊙idf _) ∘ ∨-fmap (f , idp) (g , g-pt)) wglue\n =⟨ ap-∘\n (⊙WedgeRec.f (⊙idf _) (⊙idf _))\n (∨-fmap (f , idp) (g , g-pt))\n wglue ⟩\n ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)) (ap (∨-fmap (f , idp) (g , g-pt)) wglue)\n =⟨ ap (ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)))\n (WedgeFmap.glue-β (f , idp) (g , g-pt)) ⟩\n ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)) (wglue ∙' ap winr (! g-pt))\n =⟨ ap-∙' (⊙WedgeRec.f (⊙idf _) (⊙idf _)) wglue (ap winr (! g-pt)) ⟩\n ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)) wglue\n ∙' ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)) (ap winr (! g-pt))\n =⟨ ap2 _∙'_\n (⊙WedgeRec.glue-β (⊙idf _) (⊙idf _))\n ( ∘-ap (⊙WedgeRec.f (⊙idf _) (⊙idf _)) winr (! g-pt)\n ∙ ap-idf (! g-pt)) ⟩\n idp ∙' ! g-pt\n =⟨ ∙'-unit-l (! g-pt) ⟩\n ! g-pt\n =⟨ ! $ ⊙WedgeRec.glue-β (f , idp) (g , g-pt) ⟩\n ap (⊙WedgeRec.f (f , idp) (g , g-pt) ) wglue\n =∎\n\n lemma₁ : ∀ {Z} (f : X ⊙→ Z) (g : Y ⊙→ Z)\n → snd (⊙Wedge-rec (⊙idf _) (⊙idf _) ⊙∘ ⊙∨-fmap f g)\n == snd (⊙Wedge-rec f g)\n lemma₁ (f , idp) (g , g-pt) = idp\n\nmodule _ {i j k} (X : Ptd i) (Y : Ptd j) (Z : Ptd k) where\n \n module WedgeAssocInl = WedgeRec {C = X ∨ (Y ⊙∨ Z)} winl (winr ∘ winl) wglue\n module WedgeAssoc = WedgeRec {X = X ⊙∨ Y} WedgeAssocInl.f (winr ∘ winr) (wglue ∙ ap winr wglue)\n\n ∨-assoc : (X ⊙∨ Y) ∨ Z ≃ X ∨ (Y ⊙∨ Z)\n ∨-assoc = equiv to from to-from from-to where\n\n to : (X ⊙∨ Y) ∨ Z → X ∨ (Y ⊙∨ Z)\n to = WedgeAssoc.f\n\n module FromInr = WedgeRec {C = (X ⊙∨ Y) ∨ Z} (winl ∘ winr) winr (! (ap winl wglue) ∙ wglue)\n module From = WedgeRec {Y = Y ⊙∨ Z} (winl ∘ winl) FromInr.f (ap winl wglue)\n\n from : X ∨ (Y ⊙∨ Z) → (X ⊙∨ Y) ∨ Z\n from = From.f\n\n abstract\n to-from : ∀ x → to (from x) == x\n to-from = Wedge-elim\n (λ x → idp)\n (Wedge-elim (λ y → idp) (λ z → idp) $ ↓-='-in' $ ! $\n ap (to ∘ FromInr.f) wglue\n =⟨ ap-∘ to FromInr.f wglue ⟩\n ap to (ap FromInr.f wglue)\n =⟨ ap (ap to) FromInr.glue-β ⟩\n ap to (! (ap winl wglue) ∙ wglue)\n =⟨ ap-∙ to (! (ap winl wglue)) wglue ⟩\n ap to (! (ap winl wglue)) ∙ ap to wglue\n =⟨ _∙2_ (ap-! to (ap winl wglue) ∙ ap ! (∘-ap to winl wglue ∙ WedgeAssocInl.glue-β)) WedgeAssoc.glue-β ⟩\n ! wglue ∙ wglue ∙ ap winr wglue\n =⟨ ! $ ∙-assoc (! wglue) wglue (ap winr wglue) ⟩\n (! wglue ∙ wglue) ∙ ap winr wglue\n =⟨ ap (_∙ ap winr wglue) (!-inv-l wglue) ⟩\n ap winr wglue\n =∎)\n (↓-∘=idf-in' to from (ap (ap to) From.glue-β ∙ ∘-ap to winl wglue ∙ WedgeAssocInl.glue-β))\n\n from-to : ∀ x → from (to x) == x\n from-to = Wedge-elim\n (Wedge-elim (λ x → idp) (λ y → idp) $ ↓-='-in' $ ! $\n ap-∘ from WedgeAssocInl.f wglue ∙ ap (ap from) WedgeAssocInl.glue-β ∙ From.glue-β)\n (λ z → idp)\n (↓-∘=idf-in' from to $\n ap from (ap to wglue)\n =⟨ ap (ap from) WedgeAssoc.glue-β ⟩\n ap from (wglue ∙ ap winr wglue)\n =⟨ ap-∙ from wglue (ap winr wglue) ⟩\n ap from wglue ∙ ap from (ap winr wglue)\n =⟨ From.glue-β ∙2 (∘-ap from winr wglue ∙ FromInr.glue-β) ⟩\n ap winl wglue ∙ ! (ap winl wglue) ∙ wglue\n =⟨ ! $ ∙-assoc (ap winl wglue) (! (ap winl wglue)) wglue ⟩\n (ap winl wglue ∙ ! (ap winl wglue)) ∙ wglue\n =⟨ ap (_∙ wglue) (!-inv-r (ap winl wglue)) ⟩\n wglue\n =∎)\n\n ⊙∨-assoc : (X ⊙∨ Y) ⊙∨ Z ⊙≃ X ⊙∨ (Y ⊙∨ Z)\n ⊙∨-assoc = ≃-to-⊙≃ ∨-assoc idp\n\n{-\nmodule _ {i₀ i₁ j₀ j₁ k₀ k₁}\n {X₀ : Ptd i₀} {Y₀ : Ptd j₀} {Z₀ : Ptd k₀}\n {X₁ : Ptd i₁} {Y₁ : Ptd j₁} {Z₁ : Ptd k₁}\n where\n\n ⊙∨-assoc-nat : ∀ (f : X₀ ⊙→ X₁) (g : Y₀ ⊙→ Y₁) (h : Z₀ ⊙→ Z₁)\n → ⊙–> (⊙∨-assoc X₁ Y₁ Z₁) ⊙∘ ⊙∨-fmap (⊙∨-fmap f g) h\n ⊙∼ ⊙∨-fmap f (⊙∨-fmap g h) ⊙∘ ⊙–> (⊙∨-assoc X₀ Y₀ Z₀)\n ⊙∨-assoc-nat (f , idp) (g , idp) (h , idp) =\n (Wedge-elim\n -- {P = –> (∨-assoc X₁ Y₁ Z₁) ∘ ∨-fmap (⊙∨-fmap f g) h ∼ ∨-fmap f (⊙∨-fmap g h) ∘ –> (∨-assoc X₀ Y₀ Z₀)}\n (Wedge-elim (λ _ → idp) (λ _ → idp)\n (↓-='-in' $\n ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp)) ∘ WedgeAssocInl.f X₀ Y₀ Z₀) wglue\n =⟨ ap-∘ (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (WedgeAssocInl.f X₀ Y₀ Z₀) wglue ⟩\n ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (ap (WedgeAssocInl.f X₀ Y₀ Z₀) wglue)\n =⟨ ap (ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp)))) (WedgeAssocInl.glue-β X₀ Y₀ Z₀) ⟩\n ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) wglue\n =⟨ WedgeFmap.glue-β (f , idp) (⊙∨-fmap (g , idp) (h , idp)) ⟩\n wglue\n =⟨ ! $ WedgeAssocInl.glue-β X₁ Y₁ Z₁ ⟩\n ap (WedgeAssocInl.f X₁ Y₁ Z₁) wglue\n =⟨ ! $ ap (ap (WedgeAssocInl.f X₁ Y₁ Z₁)) $ WedgeFmap.glue-β (f , idp) (g , idp) ⟩\n ap (WedgeAssocInl.f X₁ Y₁ Z₁) (ap (∨-fmap (f , idp) (g , idp)) wglue)\n =⟨ ∘-ap (WedgeAssocInl.f X₁ Y₁ Z₁) (∨-fmap (f , idp) (g , idp)) wglue ⟩\n ap (WedgeAssocInl.f X₁ Y₁ Z₁ ∘ ∨-fmap (f , idp) (g , idp)) wglue\n =∎))\n (λ _ → idp)\n (↓-='-in' $\n ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp)) ∘ WedgeAssoc.f X₀ Y₀ Z₀) wglue\n =⟨ ap-∘ (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (WedgeAssoc.f X₀ Y₀ Z₀) wglue ⟩\n ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (ap (WedgeAssoc.f X₀ Y₀ Z₀) wglue)\n =⟨ ap (ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp)))) (WedgeAssoc.glue-β X₀ Y₀ Z₀) ⟩\n ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (wglue ∙ ap winr wglue)\n =⟨ ap-∙ (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) wglue (ap winr wglue) ⟩\n ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) wglue\n ∙ ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) (ap winr wglue)\n =⟨ ap2 _∙_\n (WedgeFmap.glue-β (f , idp) (⊙∨-fmap (g , idp) (h , idp)))\n ( ∘-ap (∨-fmap (f , idp) (⊙∨-fmap (g , idp) (h , idp))) winr wglue\n ∙ ap-∘ winr (∨-fmap (g , idp) (h , idp)) wglue\n ∙ ap (ap winr) (WedgeFmap.glue-β (g , idp) (h , idp))) ⟩\n wglue ∙ ap winr wglue\n =⟨ ! $ WedgeAssoc.glue-β X₁ Y₁ Z₁ ⟩\n ap (WedgeAssoc.f X₁ Y₁ Z₁) wglue\n =⟨ ! $ ap (ap (WedgeAssoc.f X₁ Y₁ Z₁)) $ WedgeFmap.glue-β (⊙∨-fmap (f , idp) (g , idp)) (h , idp) ⟩\n ap (WedgeAssoc.f X₁ Y₁ Z₁) (ap (∨-fmap (⊙∨-fmap (f , idp) (g , idp)) (h , idp)) wglue)\n =⟨ ∘-ap (WedgeAssoc.f X₁ Y₁ Z₁) (∨-fmap (⊙∨-fmap (f , idp) (g , idp)) (h , idp)) wglue ⟩\n ap (WedgeAssoc.f X₁ Y₁ Z₁ ∘ ∨-fmap (⊙∨-fmap (f , idp) (g , idp)) (h , idp)) wglue\n =∎))\n ,\n idp\n-}\n\nmodule _ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}\n (f : X ⊙→ W) (g : Y ⊙→ W) (h : Z ⊙→ W) where\n\n ⊙Wedge-rec-assoc : ⊙Wedge-rec (⊙Wedge-rec f g) h\n ⊙∼ ⊙Wedge-rec f (⊙Wedge-rec g h) ⊙∘ ⊙–> (⊙∨-assoc X Y Z)\n ⊙Wedge-rec-assoc =\n (Wedge-elim\n (Wedge-elim (λ x → idp) (λ y → idp)\n (↓-='-in' $\n ap-∘ (⊙WedgeRec.f f (⊙Wedge-rec g h)) (WedgeAssocInl.f X Y Z) wglue\n ∙ ap (ap (⊙WedgeRec.f f (⊙Wedge-rec g h))) (WedgeAssocInl.glue-β X Y Z)\n ∙ ⊙WedgeRec.glue-β f (⊙Wedge-rec g h)\n ∙ ! (⊙WedgeRec.glue-β f g)))\n (λ z → idp)\n (↓-='-in' $\n ap-∘ (⊙WedgeRec.f f (⊙Wedge-rec g h)) (WedgeAssoc.f X Y Z) wglue\n ∙ ap (ap (⊙WedgeRec.f f (⊙Wedge-rec g h))) (WedgeAssoc.glue-β X Y Z)\n ∙ ap-∙ (⊙WedgeRec.f f (⊙Wedge-rec g h)) wglue (ap winr wglue)\n ∙ _∙2_ (⊙WedgeRec.glue-β f (⊙Wedge-rec g h))\n ( ∘-ap (⊙WedgeRec.f f (⊙Wedge-rec g h)) winr wglue\n ∙ ⊙WedgeRec.glue-β g h)\n ∙ ∙-assoc (snd f) (! (snd g)) (snd g ∙ ! (snd h))\n ∙ ap (snd f ∙_) (! $ ∙-assoc (! (snd g)) (snd g) (! (snd h)))\n ∙ ap (λ p → snd f ∙ p ∙ ! (snd h)) (!-inv-l (snd g))\n ∙ ! (⊙WedgeRec.glue-β (⊙Wedge-rec f g) h)))\n ,\n idp\n ⊙∨-rec-assoc = ⊙Wedge-rec-assoc\n", "meta": {"hexsha": "22c3ea751a6040242164aeac58b92775e89dd1fc", "size": 19658, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/types/Wedge.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "core/lib/types/Wedge.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "core/lib/types/Wedge.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 37.4438095238, "max_line_length": 116, "alphanum_fraction": 0.4484688168, "num_tokens": 9873, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6370307944803831, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.37514051083389427}} {"text": "open import Relation.Nullary\nopen import Relation.Binary.PropositionalEquality\nmodule DTGP\n {Domain Word : Set}\n (pre post : Word → Domain → Domain)\n (_≟_ : (x y : Domain) → Dec (x ≡ y))\nwhere\nopen import Function\nopen import Relation.Binary\nopen import Data.Bool hiding (_≟_)\nopen import Data.Nat hiding (_≥_; _≟_)\nopen import Data.Fin hiding (_+_; raise)\nopen import Data.Maybe\nopen import Data.Product hiding (map; swap)\nopen import Data.List hiding (length) renaming (_++_ to _l++_)\nopen import Data.Vec hiding (_++_; _>>=_; concat; map; init)\nopen import DTGP.Rand\n\ninfixr 5 _∷_ _++_ _++'_\n\ndata Term (inp : Domain) : Domain → Set where\n [] : Term inp inp\n\n _∷_ : ∀ {d} (w : Word) →\n Term inp (pre w d) → Term inp (post w d)\n\n_++_ : ∀ {inp mid out} →\n Term mid out →\n Term inp mid →\n Term inp out\n[] ++ ys = ys\n(x ∷ xs) ++ ys = x ∷ (xs ++ ys)\n\ndata Split {inp out} mid : Term inp out → Set where\n _++'_ :\n (xs : Term mid out)\n (ys : Term inp mid) →\n Split mid (xs ++ ys)\n\nswap₁ : ∀ {inp mid out} {xs ys : Term inp out} →\n Split mid xs → Split mid ys → Term inp out\nswap₁ (xs ++' ys) (as ++' bs) = xs ++ bs\n\nswap₂ : ∀ {inp mid out} {xs ys : Term inp out} →\n Split mid xs → Split mid ys → Term inp out\nswap₂ (xs ++' ys) (as ++' bs) = as ++ ys\n\nswaps : ∀ {inp mid out} {xs ys : Term inp out} →\n Split mid xs → Split mid ys →\n Term inp out × Term inp out\nswaps xs ys = swap₁ xs ys , swap₂ xs ys\n\nsplit : ∀ {inp out} (n : ℕ) (xs : Term inp out) → ∃ λ mid → Split mid xs\nsplit zero xs = _ , [] ++' xs\nsplit (suc n) [] = _ , [] ++' []\nsplit (suc n) (x ∷ xs) with split n xs\nsplit (suc n) (x ∷ ._) | _ , xs ++' ys = _ , (x ∷ xs) ++' ys\n\nsplits : ∀ {inp out} (n : ℕ) mid → (xs : Term inp out) → ∃ (Vec (Split mid xs))\nsplits zero mid xs with split zero xs\n... | mid' , ys with mid ≟ mid'\n... | yes p rewrite p = _ , ys ∷ []\n... | no p = _ , []\nsplits (suc n) mid xs with split (suc n) xs\n... | mid' , ys with mid ≟ mid' | splits n mid xs\n... | yes p | _ , yss rewrite p = _ , ys ∷ yss\n... | no p | _ , yss = _ , yss\n\nlength : ∀ {inp out} → Term inp out → ℕ\nlength [] = 0\nlength (x ∷ xs) = suc (length xs)\n\nsplit♀ : ∀ {inp out} → (xs : Term inp out) → Rand (∃ λ mid → Split mid xs)\nsplit♀ xs = \n rand >>= λ r →\n let i = r mod (suc (length xs))\n in return (split (toℕ i) xs)\n\nsplit♂ : ∀ {inp out} (xs : Term inp out) mid →\n Maybe (Rand (Split mid xs))\nsplit♂ xs B\n with splits (length xs) B xs\n... | zero , [] = nothing\n... | suc n , xss = just (\n rand >>= λ r →\n return (lookup (r mod suc n) xss)\n )\n\ncrossover : ∀ {inp out} (♀ ♂ : Term inp out) →\n Rand (Term inp out × Term inp out)\ncrossover ♀ ♂ =\n split♀ ♀ >>= λ b,xs →\n maybe′\n (_=<<_ (return ∘ (swaps (proj₂ b,xs))))\n (return (♀ , ♂))\n (split♂ ♂ (proj₁ b,xs))\n\nPopulation : ∀ inp out n → Set\nPopulation inp out n = Vec (Term inp out) (2 + n)\n\nmodule Initialization\n (match : ∀ w out → Dec (∃ λ d → out ≡ pre w d))\n where\n\n toMaybe : ∀ {w inp out} →\n Term inp out →\n Dec (∃ λ d → out ≡ pre w d) →\n Maybe (∃ λ d → Term inp d)\n toMaybe {w = w} ws (no _) = nothing\n toMaybe {w = w} ws (yes (_ , p))\n rewrite p = just (_ , w ∷ ws)\n\n enum-inp : ∀ (n : ℕ) inp → List Word → List (∃ λ out → Term inp out)\n enum-inp zero inp ws = gfilter (λ w → toMaybe [] (match w inp)) ws\n enum-inp (suc n) A ws\n with enum-inp n A ws\n ... | ih = concat (map (λ out,t → gfilter (λ w →\n toMaybe (proj₂ out,t) (match w (proj₁ out,t))\n ) ws) ih) l++ ih\n\n filter-out : ∀ {inp} out → List (∃ (Term inp)) → List (Term inp out)\n filter-out out [] = []\n filter-out out ((out' , x) ∷ xs)\n with out' ≟ out\n ... | no p = filter-out out xs\n ... | yes p rewrite p = x ∷ filter-out out xs\n\n init : ∀ (n : ℕ) inp out → List Word → List (Term inp out)\n init n inp out ws = filter-out out (enum-inp n inp ws)\n\nmodule Evolution {inp out} (score : Term inp out → ℕ) where\n\n _≥_ : ℕ → ℕ → Bool\n zero ≥ zero = true\n zero ≥ (suc n) = false\n (suc m) ≥ zero = true\n (suc m) ≥ (suc n) = m ≥ n\n\n select : ∀ {n} →\n Population inp out n → Rand (Term inp out)\n select {n = n} xss =\n rand >>= λ ii →\n rand >>= λ jj →\n let ♀ = lookup (ii mod (2 + n)) xss\n ♂ = lookup (jj mod (2 + n)) xss\n in return $\n if score ♀ ≥ score ♂\n then ♀ else ♂\n\n breed2 : ∀ {n} →\n Population inp out n →\n Rand (Term inp out × Term inp out)\n breed2 xss =\n select xss >>= λ ♀ →\n select xss >>= λ ♂ →\n crossover ♀ ♂\n\n breedN : ∀ {m} → (n : ℕ) →\n Population inp out m →\n Rand (Vec (Term inp out) n)\n breedN zero xss = return []\n breedN (suc n) xss =\n breed2 xss >>= λ offspring →\n breedN n xss >>= λ ih →\n return (proj₁ offspring ∷ ih)\n\n evolve1 : ∀ {n} →\n Population inp out n → Rand (Population inp out n)\n evolve1 xss = breedN _ xss\n\n evolveN : ∀ {n} → (gens : ℕ) →\n Population inp out n → Rand (Population inp out n)\n evolveN zero xss = return xss\n evolveN (suc gens) xss =\n evolveN gens xss >>= evolve1\n\n evolve : ∀ {n} → (seed gens : ℕ) →\n Population inp out n → Population inp out n\n evolve seed gens xss =\n runRand (evolveN gens xss) seed\n\n", "meta": {"hexsha": "502bd202274fd2aaf9c1721b8ff9498d6a485694", "size": 5098, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/DTGP.agda", "max_stars_repo_name": "larrytheliquid/dtgp", "max_stars_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2015-07-20T16:46:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T21:39:58.000Z", "max_issues_repo_path": "src/DTGP.agda", "max_issues_repo_name": "larrytheliquid/dtgp", "max_issues_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f", "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/DTGP.agda", "max_forks_repo_name": "larrytheliquid/dtgp", "max_forks_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-04-17T02:02:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:53:14.000Z", "avg_line_length": 28.010989011, "max_line_length": 79, "alphanum_fraction": 0.5578658297, "num_tokens": 1848, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583250334526, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.37510985949093634}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import lib.Basics\nopen import lib.NConnected\nopen import lib.types.TLevel\nopen import lib.NType2\nopen import lib.types.Pi\nopen import lib.types.Sigma\nopen import lib.types.Pointed\nopen import lib.types.LoopSpace\nopen import lib.types.Truncation\nopen import lib.types.PathSet\n\nmodule lib.types.Cover where\n\n{-\n The definition of covering spaces.\n-}\nrecord Cover {i} (A : Type i) j : Type (lmax i (lsucc j)) where\n constructor cover\n field\n Fiber : A → Type j\n Fiber-level : ∀ a → is-set (Fiber a)\n Fiber-is-set = Fiber-level\n TotalSpace = Σ A Fiber\n\n-- Basic lemmas\nmodule _ {i} {A : Type i} {j} where\n\n open Cover\n\n -- Equality between covers.\n private\n cover=′ : {c₁ c₂ : Cover A j} → Fiber c₁ == Fiber c₂ → c₁ == c₂\n cover=′ {cover f _} {cover .f _} idp = ap (cover f) $\n prop-has-all-paths (Π-is-prop λ _ → is-set-is-prop) _ _\n\n cover= : {c₁ c₂ : Cover A j} → (∀ a → Fiber c₁ a ≃ Fiber c₂ a)\n → c₁ == c₂\n cover= F≃ = cover=′ (λ= λ a → ua $ F≃ a)\n\n -- The definition of universality in terms of connectedness.\n is-universal : Cover A j → Type (lmax i j)\n is-universal cov = is-connected 1 $ TotalSpace cov\n\n -- In terms of connectedness\n UniversalCover : Type (lmax i (lsucc j))\n UniversalCover = Σ (Cover A j) is-universal\n\n-- Theorem: A covering space keeps higher homotopy groups.\nmodule _ {i} (A∙ : Ptd i)\n {j} (c : Cover (fst A∙) j)\n (a↑ : Cover.Fiber c (snd A∙)) where\n\n open Cover c\n private\n F = Cover.Fiber c\n F-level = Cover.Fiber-level c\n A = fst A∙\n a = snd A∙\n\n private\n -- The projection map with one end free (in order to apply J).\n to′ : ∀ {p⇑ : _==_ {A = Σ A F} (a , a↑) (a , a↑)}\n → idp == p⇑ → idp == fst= p⇑\n to′ idp=p⇑ = ap fst= idp=p⇑\n\n -- The projection map from Ω²(Σ A F) to Ω²(A).\n to : Ω^ 2 ⊙[ Σ A F , (a , a↑) ] → Ω^ 2 A∙\n to p²⇑ = to′ {p⇑ = idp} p²⇑\n\n -- Auxiliary synthesized path for injection.\n idp=p↑ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}\n → (idp=p : idp == p)\n → idp == p↑\n [ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ]\n idp=p↑ idp = prop-has-all-paths (F-level a _ _) _ _\n\n -- The injection map with some ends free (in order to apply J).\n from′ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}\n → (idp=p : idp == p)\n → idp == p↑ -- aux\n [ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ]\n → idp == pair= p p↑\n from′ idp=p idp=p↑ = pair== idp=p idp=p↑\n\n -- The injection map from Ω²(A) to Ω²(Σ A F).\n from : Ω^ 2 A∙ → Ω^ 2 ⊙[ Σ A F , (a , a↑) ]\n from p² = from′ {p = idp} {p↑ = idp} p² (idp=p↑ p²)\n\n -- Injection is left-inverse to projection (with some ends free).\n from′-to′ : ∀ {p⇑ : _==_ {A = Σ A F} (a , a↑) (a , a↑)}\n → (idp=p⇑ : idp == p⇑)\n → (idp=snd=p⇑ : idp == snd= p⇑ -- aux\n [ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ to′ idp=p⇑ ])\n → from′ (to′ idp=p⇑) idp=snd=p⇑ == idp=p⇑\n [ (λ p⇑ → idp == p⇑) ↓ ! (pair=-η p⇑) ]\n from′-to′ idp idp=snd=p⇑ = ap (from′ idp)\n $ contr-has-all-paths (F-level a _ _ _ _) _ _\n\n -- Injection is left-inverse to projection.\n from-to : ∀ p²⇑ → from (to p²⇑) == p²⇑\n from-to p²⇑ = from′-to′ {p⇑ = idp} p²⇑ (idp=p↑ (to′ p²⇑))\n\n -- Injection is right-inverse to projection (with some ends free).\n to′-from′ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}\n → (idp=p : idp == p)\n → (idp=p↑ : idp == p↑ -- aux\n [ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ])\n → to′ (from′ idp=p idp=p↑) == idp=p\n [ (λ p → idp == p) ↓ fst=-β p p↑ ]\n to′-from′ idp idp = idp\n\n -- Injection is right-inverse to projection.\n to-from : ∀ p² → to (from p²) == p²\n to-from p² = to′-from′ p² (idp=p↑ p²)\n\n -- The theorem.\n Ω²ΣAFiber≃Ω²A : Ω^ 2 (Σ A F , (a , a↑)) ≃ Ω^ 2 A∙\n Ω²ΣAFiber≃Ω²A = to , is-eq to from to-from from-to\n\n-- A natural way to construct a G-set from covering spaces.\nmodule _ {i} {A : Type i} where\n open Cover\n\n cover-trace : ∀ {j} (cov : Cover A j) {a₁ a₂}\n → Fiber cov a₁ → a₁ =₀ a₂\n → Fiber cov a₂\n cover-trace cov a↑ p =\n transport₀ (Fiber cov) (Fiber-is-set cov _) p a↑\n\n abstract\n cover-trace-idp₀ : ∀ {j} (cov : Cover A j) {a₁}\n → (a↑ : Fiber cov a₁)\n → cover-trace cov a↑ idp₀ == a↑\n cover-trace-idp₀ cov a↑ = idp\n\n cover-paste : ∀ {j} (cov : Cover A j) {a₁ a₂}\n → (a↑ : Fiber cov a₁)\n → (loop : a₁ =₀ a₁)\n → (p : a₁ =₀ a₂)\n → cover-trace cov (cover-trace cov a↑ loop) p\n == cover-trace cov a↑ (loop ∙₀ p)\n cover-paste cov a↑ loop p = ! $ trans₀-∙₀ (Fiber-is-set cov) loop p a↑\n\n-- Path sets form a covering space\nmodule _ {i} (A∙ : Ptd i) where\n path-set-cover : Cover (fst A∙) i\n path-set-cover = record\n { Fiber = λ a → snd A∙ =₀ a\n ; Fiber-level = λ a → Trunc-level\n }\n\n-- Cover morphisms\nCoverHom : ∀ {i} {A : Type i} {j₁ j₂}\n → (cov1 : Cover A j₁)\n → (cov2 : Cover A j₂)\n → Type (lmax i (lmax j₁ j₂))\nCoverHom (cover F₁ _) (cover F₂ _) = ∀ a → F₁ a → F₂ a\n", "meta": {"hexsha": "c6afb9bd86a907da73ba783a467bda37705697c3", "size": 5088, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/types/Cover.agda", "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "core/lib/types/Cover.agda", "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "core/lib/types/Cover.agda", "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": 31.8, "max_line_length": 74, "alphanum_fraction": 0.5157232704, "num_tokens": 1999, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.685949467848392, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.3750347444062591}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import HoTT\n\n{- The pseudo-adjoint functors F,G : Ptd → Ptd\n - It stops at composition and ignores\n - all the higher associahedrons.\n -}\n\nmodule homotopy.PtdAdjoint where\n\nrecord PtdFunctor i j : Type (lsucc (lmax i j)) where\n field\n obj : Ptd i → Ptd j\n arr : {X Y : Ptd i} → fst (X ⊙→ Y) → fst (obj X ⊙→ obj Y)\n id : (X : Ptd i) → arr (⊙idf X) == ⊙idf (obj X)\n comp : {X Y Z : Ptd i} (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y))\n → arr (g ⊙∘ f) == arr g ⊙∘ arr f\n\n{- counit-unit description of F ⊣ G -}\nrecord CounitUnitAdjoint {i j} (F : PtdFunctor i j) (G : PtdFunctor j i)\n : Type (lsucc (lmax i j)) where\n\n private\n module F = PtdFunctor F\n module G = PtdFunctor G\n\n field\n η : (X : Ptd i) → fst (X ⊙→ G.obj (F.obj X))\n ε : (U : Ptd j) → fst (F.obj (G.obj U) ⊙→ U)\n\n η-natural : {X Y : Ptd i} (h : fst (X ⊙→ Y))\n → η Y ⊙∘ h == G.arr (F.arr h) ⊙∘ η X\n ε-natural : {U V : Ptd j} (k : fst (U ⊙→ V))\n → ε V ⊙∘ F.arr (G.arr k) == k ⊙∘ ε U\n\n εF-Fη : (X : Ptd i) → ε (F.obj X) ⊙∘ F.arr (η X) == ⊙idf (F.obj X)\n Gε-ηG : (U : Ptd j) → G.arr (ε U) ⊙∘ η (G.obj U) == ⊙idf (G.obj U)\n\n{- hom-set isomorphism description of F ⊣ G -}\nrecord HomAdjoint {i j} (F : PtdFunctor i j) (G : PtdFunctor j i)\n : Type (lsucc (lmax i j)) where\n\n private\n module F = PtdFunctor F\n module G = PtdFunctor G\n\n field\n eq : (X : Ptd i) (U : Ptd j) → fst (F.obj X ⊙→ U) ≃ fst (X ⊙→ G.obj U)\n\n nat-dom : {X Y : Ptd i} (h : fst (X ⊙→ Y)) (U : Ptd j)\n (r : fst (F.obj Y ⊙→ U))\n → –> (eq Y U) r ⊙∘ h == –> (eq X U) (r ⊙∘ F.arr h)\n\n nat-cod : (X : Ptd i) {U V : Ptd j} (k : fst (U ⊙→ V))\n (r : fst (F.obj X ⊙→ U))\n → G.arr k ⊙∘ –> (eq X U) r == –> (eq X V) (k ⊙∘ r)\n\n nat!-dom : {X Y : Ptd i} (h : fst (X ⊙→ Y)) (U : Ptd j)\n (s : fst (Y ⊙→ G.obj U))\n → <– (eq Y U) s ⊙∘ F.arr h == <– (eq X U) (s ⊙∘ h)\n nat!-dom {X} {Y} h U s =\n ! (<–-inv-l (eq X U) (<– (eq Y U) s ⊙∘ F.arr h))\n ∙ ap (<– (eq X U)) (! (nat-dom h U (<– (eq Y U) s)))\n ∙ ap (λ w → <– (eq X U) (w ⊙∘ h)) (<–-inv-r (eq Y U) s)\n\n nat!-cod : (X : Ptd i) {U V : Ptd j} (k : fst (U ⊙→ V))\n (s : fst (X ⊙→ G.obj U))\n → k ⊙∘ <– (eq X U) s == <– (eq X V) (G.arr k ⊙∘ s)\n nat!-cod X {U} {V} k s =\n ! (<–-inv-l (eq X V) (k ⊙∘ <– (eq X U) s))\n ∙ ap (<– (eq X V)) (! (nat-cod X k (<– (eq X U) s)))\n ∙ ap (λ w → <– (eq X V) (G.arr k ⊙∘ w)) (<–-inv-r (eq X U) s)\n\ncounit-unit-to-hom : ∀ {i j} {F : PtdFunctor i j} {G : PtdFunctor j i}\n → CounitUnitAdjoint F G → HomAdjoint F G\ncounit-unit-to-hom {i} {j} {F} {G} adj = record {\n eq = eq;\n nat-dom = nat-dom;\n nat-cod = nat-cod}\n where\n module F = PtdFunctor F\n module G = PtdFunctor G\n open CounitUnitAdjoint adj\n\n module _ (X : Ptd i) (U : Ptd j) where\n\n into : fst (F.obj X ⊙→ U) → fst (X ⊙→ G.obj U)\n into r = G.arr r ⊙∘ η X\n\n out : fst (X ⊙→ G.obj U) → fst (F.obj X ⊙→ U)\n out s = ε U ⊙∘ F.arr s\n\n into-out : (s : fst (X ⊙→ G.obj U)) → into (out s) == s\n into-out s =\n G.arr (ε U ⊙∘ F.arr s) ⊙∘ η X\n =⟨ G.comp (ε U) (F.arr s) |in-ctx (λ w → w ⊙∘ η X) ⟩\n (G.arr (ε U) ⊙∘ G.arr (F.arr s)) ⊙∘ η X\n =⟨ ⊙∘-assoc (G.arr (ε U)) (G.arr (F.arr s)) (η X) ⟩\n G.arr (ε U) ⊙∘ G.arr (F.arr s) ⊙∘ η X\n =⟨ ! (η-natural s) |in-ctx (λ w → G.arr (ε U) ⊙∘ w) ⟩\n G.arr (ε U) ⊙∘ η (G.obj U) ⊙∘ s\n =⟨ ! (⊙∘-assoc (G.arr (ε U)) (η (G.obj U)) s) ⟩\n (G.arr (ε U) ⊙∘ η (G.obj U)) ⊙∘ s\n =⟨ Gε-ηG U |in-ctx (λ w → w ⊙∘ s) ⟩\n ⊙idf (G.obj U) ⊙∘ s\n =⟨ ⊙∘-unit-l s ⟩\n s ∎\n\n out-into : (r : fst (F.obj X ⊙→ U)) → out (into r) == r\n out-into r =\n ε U ⊙∘ F.arr (G.arr r ⊙∘ η X)\n =⟨ F.comp (G.arr r) (η X) |in-ctx (λ w → ε U ⊙∘ w) ⟩\n ε U ⊙∘ F.arr (G.arr r) ⊙∘ F.arr (η X)\n =⟨ ! (⊙∘-assoc (ε U) (F.arr (G.arr r)) (F.arr (η X))) ⟩\n (ε U ⊙∘ F.arr (G.arr r)) ⊙∘ F.arr (η X)\n =⟨ ε-natural r |in-ctx (λ w → w ⊙∘ F.arr (η X)) ⟩\n (r ⊙∘ ε (F.obj X)) ⊙∘ F.arr (η X)\n =⟨ ⊙∘-assoc r (ε (F.obj X)) (F.arr (η X)) ⟩\n r ⊙∘ ε (F.obj X) ⊙∘ F.arr (η X)\n =⟨ εF-Fη X |in-ctx (λ w → r ⊙∘ w) ⟩\n r ∎\n\n eq : fst (F.obj X ⊙→ U) ≃ fst (X ⊙→ G.obj U)\n eq = equiv into out into-out out-into\n\n nat-dom : {X Y : Ptd i} (h : fst (X ⊙→ Y)) (U : Ptd j)\n (r : fst (F.obj Y ⊙→ U))\n → –> (eq Y U) r ⊙∘ h == –> (eq X U) (r ⊙∘ F.arr h)\n nat-dom {X} {Y} h U r =\n (G.arr r ⊙∘ η Y) ⊙∘ h\n =⟨ ⊙∘-assoc (G.arr r) (η Y) h ⟩\n G.arr r ⊙∘ η Y ⊙∘ h\n =⟨ η-natural h |in-ctx (λ w → G.arr r ⊙∘ w) ⟩\n G.arr r ⊙∘ G.arr (F.arr h) ⊙∘ η X\n =⟨ ! (⊙∘-assoc (G.arr r) (G.arr (F.arr h)) (η X)) ⟩\n (G.arr r ⊙∘ G.arr (F.arr h)) ⊙∘ η X\n =⟨ ! (G.comp r (F.arr h)) |in-ctx (λ w → w ⊙∘ η X) ⟩\n G.arr (r ⊙∘ F.arr h) ⊙∘ η X ∎\n\n nat-cod : (X : Ptd i) {U V : Ptd j} (k : fst (U ⊙→ V))\n (r : fst (F.obj X ⊙→ U))\n → G.arr k ⊙∘ –> (eq X U) r == –> (eq X V) (k ⊙∘ r)\n nat-cod X k r =\n G.arr k ⊙∘ (G.arr r ⊙∘ η X)\n =⟨ ! (⊙∘-assoc (G.arr k) (G.arr r) (η X)) ⟩\n (G.arr k ⊙∘ G.arr r) ⊙∘ η X\n =⟨ ! (G.comp k r) |in-ctx (λ w → w ⊙∘ η X) ⟩\n G.arr (k ⊙∘ r) ⊙∘ η X ∎\n\n{- a right adjoint preserves products -}\nmodule RightAdjoint× {i j} {F : PtdFunctor i j} {G : PtdFunctor j i}\n (adj : HomAdjoint F G) (U V : Ptd j) where\n\n private\n module F = PtdFunctor F\n module G = PtdFunctor G\n module A = HomAdjoint adj\n\n ⊙into : fst (G.obj (U ⊙× V) ⊙→ G.obj U ⊙× G.obj V)\n ⊙into = ⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)\n\n ⊙out : fst (G.obj U ⊙× G.obj V ⊙→ G.obj (U ⊙× V))\n ⊙out = –> (A.eq _ _) (⊙×-in (<– (A.eq _ _) ⊙fst)\n (<– (A.eq _ _) ⊙snd))\n\n ⊙into-out : ⊙into ⊙∘ ⊙out == ⊙idf _\n ⊙into-out =\n ⊙×-in (G.arr ⊙fst) (G.arr ⊙snd) ⊙∘ ⊙out\n =⟨ ⊙×-in-pre∘ (G.arr ⊙fst) (G.arr ⊙snd) ⊙out ⟩\n ⊙×-in (G.arr ⊙fst ⊙∘ ⊙out) (G.arr ⊙snd ⊙∘ ⊙out)\n =⟨ ap2 ⊙×-in\n (A.nat-cod _ ⊙fst (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd))\n ∙ ap (–> (A.eq _ _))\n (⊙fst-⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd))\n ∙ <–-inv-r (A.eq _ _) ⊙fst)\n (A.nat-cod _ ⊙snd (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd))\n ∙ ap (–> (A.eq _ _))\n (⊙snd-⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd))\n ∙ <–-inv-r (A.eq _ _) ⊙snd) ⟩\n ⊙×-in ⊙fst ⊙snd ∎\n\n ⊙out-into : ⊙out ⊙∘ ⊙into == ⊙idf _\n ⊙out-into =\n –> (A.eq _ _) (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd))\n ⊙∘ ⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)\n =⟨ A.nat-dom (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) _\n (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)) ⟩\n –> (A.eq _ _) (⊙×-in (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)\n ⊙∘ F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)))\n =⟨ ⊙×-in-pre∘ (<– (A.eq _ _) ⊙fst) (<– (A.eq _ _) ⊙snd)\n (F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)))\n |in-ctx –> (A.eq _ _) ⟩\n –> (A.eq _ _) (⊙×-in\n (<– (A.eq _ _) ⊙fst ⊙∘ F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)))\n (<– (A.eq _ _) ⊙snd ⊙∘ F.arr (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd))))\n =⟨ ap2 (λ f g → –> (A.eq _ _) (⊙×-in f g))\n (A.nat!-dom (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) _ ⊙fst\n ∙ ap (<– (A.eq _ _)) (⊙fst-⊙×-in (G.arr ⊙fst) (G.arr ⊙snd))\n ∙ ! (A.nat!-cod _ ⊙fst (⊙idf _)))\n (A.nat!-dom (⊙×-in (G.arr ⊙fst) (G.arr ⊙snd)) _ ⊙snd\n ∙ ap (<– (A.eq _ _)) (⊙snd-⊙×-in (G.arr ⊙fst) (G.arr ⊙snd))\n ∙ ! (A.nat!-cod _ ⊙snd (⊙idf _))) ⟩\n –> (A.eq _ _) (⊙×-in (⊙fst ⊙∘ <– (A.eq _ _) (⊙idf _))\n (⊙snd ⊙∘ <– (A.eq _ _) (⊙idf _)))\n =⟨ ap (–> (A.eq _ _)) (! (⊙×-in-pre∘ ⊙fst ⊙snd (<– (A.eq _ _) (⊙idf _)))) ⟩\n –> (A.eq _ _) (⊙×-in ⊙fst ⊙snd ⊙∘ <– (A.eq _ _) (⊙idf _))\n =⟨ ⊙∘-unit-l _ |in-ctx –> (A.eq _ _) ⟩\n –> (A.eq _ _) (<– (A.eq _ _) (⊙idf _))\n =⟨ <–-inv-r (A.eq _ _) (⊙idf _) ⟩\n ⊙idf _ ∎\n\n ⊙eq : G.obj (U ⊙× V) ⊙≃ G.obj U ⊙× G.obj V\n ⊙eq = ⊙≃-in (equiv (fst ⊙into) (fst ⊙out)\n (app= (ap fst ⊙into-out)) (app= (ap fst ⊙out-into)))\n (snd ⊙into)\n\n ⊙path = ⊙ua ⊙eq\n\n{- Using the equivalence in RightAdjoint× we get a binary\n - \"G.arr2\" : (X × Y → Z) → (G X × G Y → G Z)\n - and there is some kind of naturality wrt the (FX→Y)≃(X→GY) equivalence\n - (use case: from ⊙ap we get ⊙ap2) -}\nmodule RightAdjointBinary {i j} {F : PtdFunctor i j} {G : PtdFunctor j i}\n (adj : HomAdjoint F G)\n where\n\n private\n module F = PtdFunctor F\n module G = PtdFunctor G\n module A = HomAdjoint adj\n module A× = RightAdjoint× adj\n\n arr2 : {X Y Z : Ptd j}\n → fst (X ⊙× Y ⊙→ Z) → fst (G.obj X ⊙× G.obj Y ⊙→ G.obj Z)\n arr2 {X} {Y} {Z} f = G.arr f ⊙∘ A×.⊙out X Y\n\n nat-cod : {X : Ptd i} {Y Z W : Ptd j}\n (r₁ : fst (F.obj X ⊙→ Y)) (r₂ : fst (F.obj X ⊙→ Z))\n (o : fst (Y ⊙× Z ⊙→ W))\n → –> (A.eq X W) (o ⊙∘ ⊙×-in r₁ r₂)\n == arr2 o ⊙∘ ⊙×-in (–> (A.eq X Y) r₁) (–> (A.eq X Z) r₂)\n nat-cod {X} {Y} {Z} {W} r₁ r₂ o =\n –> (A.eq X W) (o ⊙∘ ⊙×-in r₁ r₂)\n =⟨ ! (A.nat-cod X o (⊙×-in r₁ r₂)) ⟩\n G.arr o ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)\n =⟨ ! (A×.⊙out-into Y Z)\n |in-ctx (λ w → (G.arr o ⊙∘ w) ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)) ⟩\n (G.arr o ⊙∘ (A×.⊙out Y Z ⊙∘ A×.⊙into Y Z))\n ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)\n =⟨ ⊙∘-assoc-lemma (G.arr o) (A×.⊙out Y Z) (A×.⊙into Y Z)\n (–> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)) ⟩\n arr2 o ⊙∘ A×.⊙into Y Z ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂)\n =⟨ ⊙×-in-pre∘ (G.arr ⊙fst) (G.arr ⊙snd) (–> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂))\n |in-ctx (λ w → arr2 o ⊙∘ w) ⟩\n arr2 o ⊙∘ ⊙×-in (G.arr ⊙fst ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂))\n (G.arr ⊙snd ⊙∘ –> (A.eq X (Y ⊙× Z)) (⊙×-in r₁ r₂))\n =⟨ ap2 (λ w₁ w₂ → arr2 o ⊙∘ ⊙×-in w₁ w₂)\n (A.nat-cod X ⊙fst (⊙×-in r₁ r₂)\n ∙ ap (–> (A.eq X Y)) (⊙fst-⊙×-in r₁ r₂))\n (A.nat-cod X ⊙snd (⊙×-in r₁ r₂)\n ∙ ap (–> (A.eq X Z)) (⊙snd-⊙×-in r₁ r₂)) ⟩\n arr2 o ⊙∘ ⊙×-in (–> (A.eq X Y) r₁) (–> (A.eq X Z) r₂) ∎\n where\n ⊙∘-assoc-lemma : ∀ {i j k l m}\n {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {U : Ptd l} {V : Ptd m}\n (k : fst (U ⊙→ V)) (h : fst (Z ⊙→ U))\n (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y))\n → (k ⊙∘ (h ⊙∘ g)) ⊙∘ f == (k ⊙∘ h) ⊙∘ g ⊙∘ f\n ⊙∘-assoc-lemma (k , idp) (h , idp) (g , idp) (f , idp) = idp\n\n{- a left adjoint preserves wedges -}\nmodule LeftAdjoint∨ {i j} {F : PtdFunctor i j} {G : PtdFunctor j i}\n (adj : HomAdjoint F G) (U V : Ptd i) where\n\n private\n module F = PtdFunctor F\n module G = PtdFunctor G\n module A = HomAdjoint adj\n\n module Into = ⊙WedgeRec (F.arr ⊙winl) (F.arr ⊙winr)\n\n ⊙into : fst (F.obj U ⊙∨ F.obj V ⊙→ F.obj (U ⊙∨ V))\n ⊙into = Into.⊙f\n\n module OutHelp = ⊙WedgeRec (–> (A.eq _ _) ⊙winl) (–> (A.eq _ _) ⊙winr)\n\n ⊙out : fst (F.obj (U ⊙∨ V) ⊙→ F.obj U ⊙∨ F.obj V)\n ⊙out = <– (A.eq _ _) OutHelp.⊙f\n\n ⊙into-out : ⊙into ⊙∘ ⊙out == ⊙idf _\n ⊙into-out =\n ⊙into ⊙∘ ⊙out\n =⟨ A.nat!-cod _ ⊙into (⊙wedge-rec (–> (A.eq _ _) ⊙winl)\n (–> (A.eq _ _) ⊙winr)) ⟩\n <– (A.eq _ _) (G.arr ⊙into ⊙∘ ⊙wedge-rec (–> (A.eq _ _) ⊙winl)\n (–> (A.eq _ _) ⊙winr))\n =⟨ ap (<– (A.eq _ _)) (⊙wedge-rec-post∘ (G.arr ⊙into)\n (–> (A.eq _ _) ⊙winl) (–> (A.eq _ _) ⊙winr)) ⟩\n <– (A.eq _ _) (⊙wedge-rec (G.arr ⊙into ⊙∘ –> (A.eq _ _) ⊙winl)\n (G.arr ⊙into ⊙∘ –> (A.eq _ _) ⊙winr))\n =⟨ ap2 (λ w₁ w₂ → <– (A.eq _ _) (⊙wedge-rec w₁ w₂))\n (A.nat-cod _ ⊙into ⊙winl\n ∙ ap (–> (A.eq _ _)) (Into.⊙winl-β ∙ ! (⊙∘-unit-l _))\n ∙ ! (A.nat-dom ⊙winl _ (⊙idf _)))\n (A.nat-cod _ ⊙into ⊙winr\n ∙ ap (–> (A.eq _ _)) (Into.⊙winr-β ∙ ! (⊙∘-unit-l _))\n ∙ ! (A.nat-dom ⊙winr _ (⊙idf _))) ⟩\n <– (A.eq _ _) (⊙wedge-rec (–> (A.eq _ _) (⊙idf _) ⊙∘ ⊙winl)\n (–> (A.eq _ _) (⊙idf _) ⊙∘ ⊙winr))\n =⟨ ap (<– (A.eq _ _))\n (! (⊙wedge-rec-post∘ (–> (A.eq _ _) (⊙idf _)) ⊙winl ⊙winr)) ⟩\n <– (A.eq _ _) (–> (A.eq _ _) (⊙idf _) ⊙∘ ⊙wedge-rec ⊙winl ⊙winr)\n =⟨ ap (λ w → <– (A.eq _ _) (–> (A.eq _ _) (⊙idf _) ⊙∘ w))\n ⊙wedge-rec-η ⟩\n <– (A.eq _ _) (–> (A.eq _ _) (⊙idf _))\n =⟨ <–-inv-l (A.eq _ _) (⊙idf _) ⟩\n ⊙idf _ ∎\n\n ⊙out-into : ⊙out ⊙∘ ⊙into == ⊙idf _\n ⊙out-into =\n ⊙out ⊙∘ ⊙wedge-rec (F.arr ⊙winl) (F.arr ⊙winr)\n =⟨ ⊙wedge-rec-post∘ ⊙out (F.arr ⊙winl) (F.arr ⊙winr) ⟩\n ⊙wedge-rec (⊙out ⊙∘ F.arr ⊙winl) (⊙out ⊙∘ F.arr ⊙winr)\n =⟨ ap2 ⊙wedge-rec\n (A.nat!-dom ⊙winl _ (⊙wedge-rec _ _)\n ∙ ap (<– (A.eq _ _)) OutHelp.⊙winl-β\n ∙ <–-inv-l (A.eq _ _) ⊙winl)\n (A.nat!-dom ⊙winr _ (⊙wedge-rec _ _)\n ∙ ap (<– (A.eq _ _)) OutHelp.⊙winr-β\n ∙ <–-inv-l (A.eq _ _) ⊙winr) ⟩\n ⊙wedge-rec ⊙winl ⊙winr\n =⟨ ⊙wedge-rec-η ⟩\n ⊙idf _ ∎\n\n ⊙eq : F.obj U ⊙∨ F.obj V ⊙≃ F.obj (U ⊙∨ V)\n ⊙eq = ⊙≃-in (equiv (fst ⊙into) (fst ⊙out)\n (app= (ap fst ⊙into-out)) (app= (ap fst ⊙out-into)))\n (snd ⊙into)\n\n ⊙path = ⊙ua ⊙eq\n", "meta": {"hexsha": "41718b3fbf52c79534f4fcef2287040285ce0761", "size": 13097, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/PtdAdjoint.agda", "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "theorems/homotopy/PtdAdjoint.agda", "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "theorems/homotopy/PtdAdjoint.agda", "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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.2953216374, "max_line_length": 82, "alphanum_fraction": 0.4090249675, "num_tokens": 6699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494421679929, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.3750347303658052}} {"text": "{-# OPTIONS --without-K #-}\nmodule well-typed-syntax-interpreter where\nopen import common public\nopen import well-typed-syntax\nimport well-typed-syntax-pre-interpreter\nopen import well-typed-syntax-eq-dec\n\nmax-level : Level\nmax-level = well-typed-syntax-pre-interpreter.max-level\n\nContext⇓ : (Γ : Context) → Set (lsuc max-level)\nContext⇓ = well-typed-syntax-pre-interpreter.inner.Context⇓\n (λ ℓ P Γ' dummy val → context-pick-if {P = P} dummy val)\n (λ ℓ P dummy val → context-pick-if-refl {P = P} {dummy})\n\nTyp⇓ : {Γ : Context} → Typ Γ → Context⇓ Γ → Set max-level\nTyp⇓ = well-typed-syntax-pre-interpreter.inner.Typ⇓\n (λ ℓ P Γ' dummy val → context-pick-if {P = P} dummy val)\n (λ ℓ P dummy val → context-pick-if-refl {P = P} {dummy})\n\nTerm⇓ : ∀ {Γ : Context} {T : Typ Γ} → Term T → (Γ⇓ : Context⇓ Γ) → Typ⇓ T Γ⇓\nTerm⇓ = well-typed-syntax-pre-interpreter.inner.Term⇓\n (λ ℓ P Γ' dummy val → context-pick-if {P = P} dummy val)\n (λ ℓ P dummy val → context-pick-if-refl {P = P} {dummy})\n", "meta": {"hexsha": "c3a75f751cbe09b1b72411e3d71f323899f5467b", "size": 1026, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "internal/well-typed-syntax-interpreter.agda", "max_stars_repo_name": "JasonGross/lob", "max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z", "max_issues_repo_path": "internal/well-typed-syntax-interpreter.agda", "max_issues_repo_name": "JasonGross/lob", "max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z", "max_forks_repo_path": "internal/well-typed-syntax-interpreter.agda", "max_forks_repo_name": "JasonGross/lob", "max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z", "avg_line_length": 41.04, "max_line_length": 76, "alphanum_fraction": 0.6452241715, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7799929053683038, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.3747699600581088}} {"text": "-- 2014-08-25 reported by Wolfram Kahl, test case shrunk by Ulf, fixed by Andreas and Ulf\n-- {-# OPTIONS --show-implicit -v tc.cover.splittree:10 -v tc.with:40 -v tc.cc:12 #-}\npostulate K : Set\n\ndata SUList : K → Set where\n cons : ∀ {k} (es : SUList k) → SUList k\n\ndata Tri : Set where\n tri< tri> : Tri\n\npostulate\n k : K\n compareK : Tri\n dummy : Set\n es : SUList k\n\ndiff : SUList k → SUList k → Tri → Set\ndiff (cons _) _ tri< = K\ndiff es₁ (cons es₂) tri> = diff es₁ es₂ compareK\n\ntest = diff (cons es) (cons es) tri>\n-- normalizing test\n-- gives WRONG diff (cons k es) es compareK\n-- should be diff (cons {k} es) es compareK\n-- Problem was in the clause compiler\n\n-- Trigger the bug:\nfrom : (es : SUList k) (c : Tri) → diff (cons es) (cons es) c → Set\nfrom es tri< d = K\nfrom es tri> d with dummy\n... | _ = K\n\n-- WAS:\n-- Expected a hidden argument, but found a visible argument\n-- when checking that the type\n-- Set → (es₁ : SUList k) (d : diff (cons k es₁) es₁ compareK) → Set\n-- of the generated with function is well-formed\n", "meta": {"hexsha": "fdae369b33e33d5842936777f1421c1298d02c5b", "size": 1042, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1186.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue1186.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue1186.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 27.4210526316, "max_line_length": 89, "alphanum_fraction": 0.6439539347, "num_tokens": 352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.37469151253082894}} {"text": "{-# OPTIONS --cubical --safe --postfix-projections #-}\n\nopen import Cubical.Core.Everything\n\nopen import Cubical.Foundations.Embedding\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Univalence\n\n-- A helper module for deriving univalence for a higher inductive-recursive\n-- universe.\n--\n-- U is the type of codes\n-- El is the decoding\n-- uaf is a higher constructor that requires paths between codes to exist\n-- for equivalences of decodings\n-- comp is intended to be the computational behavior of El on uaf, although\n-- it seems that being a path is sufficient.\n-- ret is a higher constructor that fills out the equivalence structure\n-- for uaf and the computational behavior of El.\n--\n-- Given a universe defined as above, it's possible to show that the path\n-- space of the code type is equivalent to the path space of the actual\n-- decodings, which are themselves determined by equivalences.\n--\n-- The levels are left independent, but of course it will generally be\n-- impossible to define this sort of universe unless ℓ' < ℓ, because El will\n-- be too big to go in a constructor of U. The exception would be if U could\n-- be defined independently of El, though it might be tricky to get the right\n-- higher structure in such a case.\nmodule Cubical.Foundations.Univalence.Universe {ℓ ℓ'}\n (U : Type ℓ)\n (El : U → Type ℓ')\n (uaf : ∀{s t} → El s ≃ El t → s ≡ t)\n (comp : ∀{s t} (e : El s ≃ El t) → cong El (uaf e) ≡ ua e)\n (ret : ∀{s t : U} → (p : s ≡ t) → uaf (lineToEquiv (λ i → El (p i))) ≡ p)\n where\n\nminivalence : ∀{s t} → (s ≡ t) ≃ (El s ≡ El t)\nminivalence {s} {t} = isoToEquiv mini\n where\n open Iso\n mini : Iso (s ≡ t) (El s ≡ El t)\n mini .fun = cong El\n mini .inv = uaf ∘ pathToEquiv\n mini .rightInv p = comp (pathToEquiv p) ∙ uaη p\n mini .leftInv = ret\n\nisEmbeddingEl : isEmbedding El\nisEmbeddingEl s t = snd minivalence\n", "meta": {"hexsha": "9f261cd537535f7b5c522c78846bcfc44e82aa9e", "size": 2017, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Foundations/Univalence/Universe.agda", "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": "Cubical/Foundations/Univalence/Universe.agda", "max_issues_repo_name": "limemloh/cubical", "max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": "Cubical/Foundations/Univalence/Universe.agda", "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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.0566037736, "max_line_length": 77, "alphanum_fraction": 0.7030242935, "num_tokens": 596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.37469151253082894}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Categories.Adjoint\nopen import Categories.Category\nopen import Categories.Functor renaming (id to idF)\n\nmodule Categories.Adjoint.Monadic.Properties {o ℓ e o′ ℓ′ e′} {𝒞 : Category o ℓ e} {𝒟 : Category o′ ℓ′ e′}\n {L : Functor 𝒞 𝒟} {R : Functor 𝒟 𝒞} (adjoint : L ⊣ R) where\n\n\nopen import Level\nopen import Function using (_$_)\n\nopen import Categories.Adjoint.Properties\nopen import Categories.Adjoint.Monadic\nopen import Categories.NaturalTransformation.NaturalIsomorphism\nopen import Categories.NaturalTransformation\nopen import Categories.Monad\n\nopen import Categories.Diagram.Coequalizer\n\nopen import Categories.Category.Construction.EilenbergMoore\nopen import Categories.Category.Construction.Properties.EilenbergMoore\n\nopen import Categories.Morphism\nimport Categories.Morphism.Reasoning as MR\n\nprivate\n module L = Functor L\n module R = Functor R\n\n module 𝒞 = Category 𝒞\n module 𝒟 = Category 𝒟\n\n module adjoint = Adjoint adjoint\n\n T : Monad 𝒞\n T = adjoint⇒monad adjoint\n\n 𝒞ᵀ : Category _ _ _\n 𝒞ᵀ = EilenbergMoore T\n\n Comparison : Functor 𝒟 𝒞ᵀ\n Comparison = ComparisonF adjoint\n\n module Comparison = Functor Comparison\n\n\n-- If we have a coequalizer of the following diagram for every T-algabra, then the comparison functor has a left adjoint.\nmodule _ (has-coequalizer : (M : Module T) → Coequalizer 𝒟 (L.F₁ (Module.action M)) (adjoint.counit.η (L.₀ (Module.A M)))) where\n\n open Coequalizer\n\n Comparison⁻¹ : Functor 𝒞ᵀ 𝒟\n Comparison⁻¹ = record\n { F₀ = λ M → obj (has-coequalizer M)\n ; F₁ = λ {M} {N} α → coequalize (has-coequalizer M) $ begin\n 𝒟 [ 𝒟 [ arr (has-coequalizer N) ∘ L.F₁ (Module⇒.arr α) ] ∘ L.F₁ (Module.action M) ] ≈⟨ pullʳ (⟺ L.homomorphism) ⟩\n 𝒟 [ arr (has-coequalizer N) ∘ L.F₁ (𝒞 [ Module⇒.arr α ∘ Module.action M ]) ] ≈⟨ refl⟩∘⟨ L.F-resp-≈ (Module⇒.commute α) ⟩\n 𝒟 [ arr (has-coequalizer N) ∘ L.F₁ (𝒞 [ Module.action N ∘ R.F₁ (L.F₁ (Module⇒.arr α)) ]) ] ≈⟨ refl⟩∘⟨ L.homomorphism ⟩\n 𝒟 [ arr (has-coequalizer N) ∘ 𝒟 [ L.F₁ (Module.action N) ∘ L.F₁ (R.F₁ (L.F₁ (Module⇒.arr α))) ] ] ≈⟨ pullˡ (equality (has-coequalizer N)) ⟩\n 𝒟 [ 𝒟 [ arr (has-coequalizer N) ∘ adjoint.counit.η (L.F₀ (Module.A N)) ] ∘ L.F₁ (R.F₁ (L.F₁ (Module⇒.arr α))) ] ≈⟨ extendˡ (adjoint.counit.commute (L.F₁ (Module⇒.arr α))) ⟩\n 𝒟 [ 𝒟 [ arr (has-coequalizer N) ∘ L.F₁ (Module⇒.arr α) ] ∘ adjoint.counit.η (L.₀ (Module.A M)) ] ∎\n ; identity = λ {A} → ⟺ $ unique (has-coequalizer A) $ begin\n 𝒟 [ arr (has-coequalizer A) ∘ L.F₁ 𝒞.id ] ≈⟨ refl⟩∘⟨ L.identity ⟩\n 𝒟 [ arr (has-coequalizer A) ∘ 𝒟.id ] ≈⟨ id-comm ⟩\n 𝒟 [ 𝒟.id ∘ arr (has-coequalizer A) ] ∎\n ; homomorphism = λ {X} {Y} {Z} {f} {g} → ⟺ $ unique (has-coequalizer X) $ begin\n 𝒟 [ arr (has-coequalizer Z) ∘ L.F₁ (𝒞 [ Module⇒.arr g ∘ Module⇒.arr f ]) ] ≈⟨ 𝒟.∘-resp-≈ʳ L.homomorphism ○ 𝒟.sym-assoc ⟩\n 𝒟 [ 𝒟 [ arr (has-coequalizer Z) ∘ L.F₁ (Module⇒.arr g) ] ∘ L.F₁ (Module⇒.arr f) ] ≈⟨ universal (has-coequalizer Y) ⟩∘⟨refl ⟩\n 𝒟 [ 𝒟 [ coequalize (has-coequalizer Y) _ ∘ arr (has-coequalizer Y) ] ∘ L.F₁ (Module⇒.arr f) ] ≈⟨ extendˡ (universal (has-coequalizer X)) ⟩\n 𝒟 [ 𝒟 [ coequalize (has-coequalizer Y) _ ∘ coequalize (has-coequalizer X) _ ] ∘ arr (has-coequalizer X) ] ∎\n ; F-resp-≈ = λ {A} {B} {f} {g} eq → unique (has-coequalizer A) $ begin\n 𝒟 [ arr (has-coequalizer B) ∘ L.F₁ (Module⇒.arr g) ] ≈⟨ refl⟩∘⟨ L.F-resp-≈ (𝒞.Equiv.sym eq) ⟩\n 𝒟 [ arr (has-coequalizer B) ∘ L.F₁ (Module⇒.arr f) ] ≈⟨ universal (has-coequalizer A) ⟩\n 𝒟 [ coequalize (has-coequalizer A) _ ∘ arr (has-coequalizer A) ] ∎\n }\n where\n open 𝒟.HomReasoning\n open MR 𝒟\n\n private\n module Comparison⁻¹ = Functor Comparison⁻¹\n\n Comparison⁻¹⊣Comparison : Comparison⁻¹ ⊣ Comparison\n Adjoint.unit Comparison⁻¹⊣Comparison = ntHelper record\n { η = λ M → record\n { arr = 𝒞 [ R.F₁ (arr (has-coequalizer M)) ∘ adjoint.unit.η (Module.A M) ]\n ; commute = begin\n 𝒞 [ 𝒞 [ R.F₁ (arr (has-coequalizer M)) ∘ adjoint.unit.η (Module.A M) ] ∘ Module.action M ] ≈⟨ pullʳ (adjoint.unit.commute (Module.action M)) ⟩\n -- It would be nice to have a reasoning combinator doing this \"⟺ homomorphism ... homomorphism\" pattern\n 𝒞 [ R.F₁ (arr (has-coequalizer M)) ∘ 𝒞 [ R.F₁ (L.F₁ (Module.action M)) ∘ adjoint.unit.η (R.F₀ (L.F₀ (Module.A M))) ] ] ≈⟨ pullˡ (⟺ R.homomorphism) ⟩\n 𝒞 [ R.F₁ (𝒟 [ arr (has-coequalizer M) ∘ L.F₁ (Module.action M) ]) ∘ adjoint.unit.η (R.F₀ (L.F₀ (Module.A M))) ] ≈⟨ (R.F-resp-≈ (equality (has-coequalizer M)) ⟩∘⟨refl) ⟩\n 𝒞 [ R.F₁ (𝒟 [ arr (has-coequalizer M) ∘ adjoint.counit.η (L.F₀ (Module.A M)) ]) ∘ adjoint.unit.η (R.F₀ (L.F₀ (Module.A M))) ] ≈⟨ (R.homomorphism ⟩∘⟨refl) ⟩\n 𝒞 [ 𝒞 [ R.F₁ (arr (has-coequalizer M)) ∘ R.F₁ (adjoint.counit.η (L.F₀ (Module.A M))) ] ∘ adjoint.unit.η (R.F₀ (L.F₀ (Module.A M))) ] ≈⟨ cancelʳ adjoint.zag ⟩\n -- FIXME Use something like cancel here\n R.F₁ (arr (has-coequalizer M)) ≈˘⟨ R.F-resp-≈ (𝒟.identityʳ) ⟩\n R.F₁ (𝒟 [ arr (has-coequalizer M) ∘ 𝒟.id ]) ≈˘⟨ R.F-resp-≈ (𝒟.∘-resp-≈ʳ adjoint.zig) ⟩\n R.F₁ (𝒟 [ arr (has-coequalizer M) ∘ 𝒟 [ adjoint.counit.η (L.F₀ (Module.A M)) ∘ L.F₁ (adjoint.unit.η (Module.A M)) ] ]) ≈⟨ R.F-resp-≈ (MR.extendʳ 𝒟 (adjoint.counit.sym-commute (arr (has-coequalizer M)))) ⟩\n R.F₁ (𝒟 [ adjoint.counit.η (obj (has-coequalizer M)) ∘ 𝒟 [ L.F₁ (R.F₁ (arr (has-coequalizer M))) ∘ L.F₁ (adjoint.unit.η (Module.A M)) ] ]) ≈˘⟨ R.F-resp-≈ (𝒟.∘-resp-≈ʳ L.homomorphism) ⟩\n R.F₁ (𝒟 [ adjoint.counit.η (obj (has-coequalizer M)) ∘ L.F₁ (𝒞 [ R.F₁ (arr (has-coequalizer M)) ∘ adjoint.unit.η (Module.A M)])]) ≈⟨ R.homomorphism ⟩\n 𝒞 [ R.F₁ (adjoint.counit.η (obj (has-coequalizer M))) ∘ R.F₁ (L.F₁ (𝒞 [ R.F₁ (arr (has-coequalizer M)) ∘ adjoint.unit.η (Module.A M)])) ] ∎\n }\n ; commute = λ {M} {N} f → begin\n 𝒞 [ 𝒞 [ R.F₁ (arr (has-coequalizer N)) ∘ adjoint.unit.η (Module.A N) ] ∘ Module⇒.arr f ] ≈⟨ extendˡ (adjoint.unit.commute (Module⇒.arr f)) ⟩\n 𝒞 [ 𝒞 [ R.F₁ (arr (has-coequalizer N)) ∘ R.F₁ (L.F₁ (Module⇒.arr f)) ] ∘ adjoint.unit.η (Module.A M) ] ≈˘⟨ R.homomorphism ⟩∘⟨refl ⟩\n 𝒞 [ R.F₁ (𝒟 [ arr (has-coequalizer N) ∘ L.F₁ (Module⇒.arr f) ]) ∘ adjoint.unit.η (Module.A M) ] ≈⟨ R.F-resp-≈ (universal (has-coequalizer M)) ⟩∘⟨refl ⟩\n 𝒞 [ R.F₁ (𝒟 [ (coequalize (has-coequalizer M) _) ∘ (arr (has-coequalizer M)) ]) ∘ adjoint.unit.η (Module.A M) ] ≈⟨ pushˡ R.homomorphism ⟩\n 𝒞 [ R.F₁ (coequalize (has-coequalizer M) _) ∘ 𝒞 [ R.F₁ (arr (has-coequalizer M)) ∘ adjoint.unit.η (Module.A M) ] ] ∎\n }\n where\n open 𝒞.HomReasoning\n open MR 𝒞\n Adjoint.counit Comparison⁻¹⊣Comparison = ntHelper record\n { η = λ X → coequalize (has-coequalizer (Comparison.F₀ X)) (adjoint.counit.commute (adjoint.counit.η X))\n ; commute = λ {X} {Y} f → begin\n 𝒟 [ coequalize (has-coequalizer (Comparison.F₀ Y)) _ ∘ coequalize (has-coequalizer (Comparison.F₀ X)) _ ] ≈⟨ unique (has-coequalizer (Comparison.F₀ X)) (adjoint.counit.sym-commute f ○ pushˡ (universal (has-coequalizer (Comparison.F₀ Y))) ○ pushʳ (universal (has-coequalizer (Comparison.F₀ X)))) ⟩\n coequalize (has-coequalizer (Comparison.F₀ X)) (extendˡ (adjoint.counit.commute (adjoint.counit.η X))) ≈˘⟨ unique (has-coequalizer (Comparison.F₀ X)) (pushʳ (universal (has-coequalizer (Comparison.F₀ X)))) ⟩\n 𝒟 [ f ∘ coequalize (has-coequalizer (Comparison.F₀ X)) _ ] ∎\n }\n where\n open 𝒟.HomReasoning\n open MR 𝒟\n Adjoint.zig Comparison⁻¹⊣Comparison {X} = begin\n 𝒟 [ coequalize (has-coequalizer (Comparison.F₀ (Comparison⁻¹.F₀ X))) _ ∘ coequalize (has-coequalizer X) _ ] ≈⟨ unique (has-coequalizer X) (⟺ adjoint.RLadjunct≈id ○ pushˡ (universal (has-coequalizer (Comparison.F₀ (Comparison⁻¹.F₀ X)))) ○ pushʳ (universal (has-coequalizer X))) ⟩\n coequalize (has-coequalizer X) {h = arr (has-coequalizer X)} (equality (has-coequalizer X)) ≈˘⟨ unique (has-coequalizer X) (⟺ 𝒟.identityˡ) ⟩\n 𝒟.id ∎\n where\n open 𝒟.HomReasoning\n open MR 𝒟\n Adjoint.zag Comparison⁻¹⊣Comparison {A} = begin\n 𝒞 [ R.F₁ (coequalize (has-coequalizer (Comparison.F₀ A)) _) ∘ 𝒞 [ R.F₁ (arr (has-coequalizer (Comparison.F₀ A))) ∘ adjoint.unit.η (Module.A (Comparison.F₀ A)) ] ] ≈⟨ pullˡ (⟺ R.homomorphism) ⟩\n 𝒞 [ R.F₁ (𝒟 [ coequalize (has-coequalizer (Comparison.F₀ A)) _ ∘ arr (has-coequalizer (Comparison.F₀ A)) ]) ∘ adjoint.unit.η (Module.A (Comparison.F₀ A)) ] ≈˘⟨ R.F-resp-≈ (universal (has-coequalizer (Comparison.F₀ A))) ⟩∘⟨refl ⟩\n 𝒞 [ R.F₁ (adjoint.counit.η A) ∘ adjoint.unit.η (R.F₀ A) ] ≈⟨ adjoint.zag ⟩\n 𝒞.id ∎\n where\n open 𝒞.HomReasoning\n open MR 𝒞\n", "meta": {"hexsha": "f9ac0128dcce9bc48eea10cba3f6c5ca5a789883", "size": 9784, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Categories/Adjoint/Monadic/Properties.agda", "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 279, "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_issues_repo_path": "src/Categories/Adjoint/Monadic/Properties.agda", "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 236, "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_forks_repo_path": "src/Categories/Adjoint/Monadic/Properties.agda", "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 64, "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "avg_line_length": 70.3884892086, "max_line_length": 303, "alphanum_fraction": 0.5528413737, "num_tokens": 3642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7549149978955811, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.37450867223104994}} {"text": "{-# OPTIONS --allow-unsolved-metas #-}\n-- {-# OPTIONS -v tc.conv.elim:100 #-}\nmodule Issue814 where\n\nrecord IsMonoid (M : Set) : Set where\n field\n unit : M\n _*_ : M → M → M\n\nrecord Monoid : Set₁ where\n field\n carrier : Set\n is-mon : IsMonoid carrier\n\nrecord Structure (Struct : Set₁)\n (HasStruct : Set → Set)\n (carrier : Struct → Set) : Set₁ where\n field\n has-struct : (X : Struct) → HasStruct (carrier X)\n\nmon-mon-struct : Structure Monoid IsMonoid Monoid.carrier\nmon-mon-struct = record\n { has-struct = Monoid.is-mon }\n\nmon-mon-struct' : Structure Monoid IsMonoid Monoid.carrier\nmon-mon-struct' = record\n { has-struct = Monoid.is-mon }\n\nunit : {Struct : Set₁}{C : Struct → Set}\n → ⦃ X : Struct ⦄\n → ⦃ struct : Structure Struct IsMonoid C ⦄\n → C X\nunit {Struct}{C} ⦃ X ⦄ ⦃ struct ⦄ = IsMonoid.unit (Structure.has-struct struct X)\n\nf : (M : Monoid) → Monoid.carrier M\nf M = unit\n\n-- An internal error has occurred. Please report this as a bug.\n-- Location of the error: src/full/Agda/TypeChecking/Eliminators.hs:45\n\n-- This used to crash, but should only produce unsolved metas.\n", "meta": {"hexsha": "57ca5bb0a5b81ec370fcf63c260a83c6fb5a7048", "size": 1143, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/succeed/Issue814.agda", "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "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/succeed/Issue814.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/succeed/Issue814.agda", "max_forks_repo_name": "masondesu/agda", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "avg_line_length": 27.2142857143, "max_line_length": 81, "alphanum_fraction": 0.6430446194, "num_tokens": 356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7549149758396752, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.37450866128925114}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import lib.Basics\nopen import lib.NType2\nopen import lib.PathFunctor\nopen import lib.PathGroupoid\n\nopen import lib.types.Bool\nopen import lib.types.IteratedSuspension\nopen import lib.types.LoopSpace\nopen import lib.types.Nat\nopen import lib.types.Paths\nopen import lib.types.Pi\nopen import lib.types.Pointed\nopen import lib.types.Sigma\nopen import lib.types.Suspension\nopen import lib.types.TLevel\nopen import lib.types.Unit\n\nopen import nicolai.pseudotruncations.Preliminary-definitions\nopen import nicolai.pseudotruncations.Liblemmas\nopen import nicolai.pseudotruncations.SeqColim\nopen import nicolai.pseudotruncations.wconstSequence\n\n\nmodule nicolai.pseudotruncations.PseudoTruncs-wconst-seq where\n\n\nopen import nicolai.pseudotruncations.pointed-O-Sphere\nopen import nicolai.pseudotruncations.LoopsAndSpheres\nopen import nicolai.pseudotruncations.PseudoTruncs\n\n{- The special sequence that we consider -}\nmodule PtruncsSeq {i} (X : Type i) where\n\n A : ℕ → Type i\n A O = X\n A (S n) = Pseudo n -1-trunc (A n)\n\n f : (n : ℕ) → A n → A (S n)\n f n x = point n -1 x\n \n C : Sequence {i}\n C = (A , f)\n\n\n\n\n\n{- A main result: If we have an inhabitant of X, then the sequence is weakly constant. \n This is Lemma 6.2 ! -}\nmodule PtruncSeqWC {i} (X : Type i) (x₀ : X) where\n\n open PtruncsSeq {i} X\n\n fs : (n : ℕ) → A n\n fs O = x₀\n fs (S n) = f n (fs n)\n\n P : (n : ℕ) → (x : A n) → Type i\n P n x = f n x == fs (S n)\n\n {- This is the easy 'Case j ≡ -2' -}\n f₀-x₀ : (y : X) → P O y \n f₀-x₀ y = (spoke O -1 r (lift false)) ∙ ! (spoke O -1 r (lift true)) where\n\n r : Sphere {i} O → X\n r (lift true) = x₀\n r (lift false) = y\n \n {- Now, the general case is done by induction on n \n (note that this variable is called 'j' in the paper).\n Hence, what is 'j' in the paper is now 'S n'.\n\n Unfortunately, we have to do everything in one \"big\"\n step with many \"where\" clauses due to the mutual dependencies. -}\n \n fₙ-x₀ : (n : ℕ) → (y : A n) → P n y\n fₙ-x₀ O y = f₀-x₀ y\n fₙ-x₀ (S n) = Pseudotrunc-ind n Point Hub Spoke where\n\n -- just for convenience - saves brackets\n norₙ' : Sphere' {i} n\n norₙ' = nor' n\n\n fⁿx₀ = fs n\n\n Point : (w : A n) → P (S n) (point n -1 w)\n Point w = ap (point (S n) -1) (fₙ-x₀ n w)\n\n Hub : (r : Sphere' n → A n) → point S n -1 _ == _\n Hub r = ap (point (S n) -1) (! (spoke n -1 r norₙ') ∙ fₙ-x₀ n (r norₙ'))\n\n {- The definition of [Spoke] is the hard part. \n First, we do the easy things that we have to do... -}\n Spoke : (r : _) → (x : Sphere' n) → _\n Spoke r = λ x → from-transp (P (S n))\n (spoke n -1 r x)\n (\n transport (P (S n)) (spoke n -1 r x) (Point (r x))\n =⟨ trans-ap₁ (f (S n)) (fs (S (S n))) (spoke n -1 r x) (Point (r x)) ⟩\n ! (ap (point (S n) -1) (spoke n -1 r x)) ∙ Point (r x)\n =⟨ ! (ap (point (S n) -1) (spoke n -1 r x)) ∙ₗ ! (∙-unit-r (Point (r x))) ⟩\n ! (ap (point (S n) -1) (spoke n -1 r x)) ∙ Point (r x) ∙ idp\n {- Now comes the hard step which requires A LOT of work in the where clause\n below: we can compose with something which, for a complicated reason, is idp! -}\n =⟨ ! (ap (point (S n) -1) (spoke n -1 r x)) ∙ₗ (Point (r x) ∙ₗ ! (k-const x)) ⟩\n ! (ap (point (S n) -1) (spoke n -1 r x)) ∙ Point (r x) ∙ k x\n {- From here, it's easy; we just have to re-associate paths and cancel inverses. \n This could be done with standard library lemmas, but it's easier to just use\n an 'ad-hoc' lemma. -}\n =⟨ multi-cancelling (ap (point S n -1) (spoke n -1 r x)) (Point (r x)) (Hub r) ⟩\n Hub r\n ∎ \n )\n\n where\n\n {- Now, the actual work follows! -}\n \n {- First, we define the interesting loop. \n In the paper, it is called [kₓ]. \n Here, it is just [k x]. -}\n k : (x : Sphere' {i} n)\n → Ω (Pseudo S n -1-trunc (A (S n)) ,\n f (S n) (f n fⁿx₀))\n k x = ! (Point (r x)) ∙ ap (point (S n) -1) (spoke n -1 r x) ∙ (Hub r)\n\n {- We want to show that [k] factors as [ap pₙ ∘ h].\n First, we define h. -}\n h : Sphere' {i} n\n → Ω (Pseudo n -1-trunc (A n) ,\n f n fⁿx₀)\n h x = ! (fₙ-x₀ n (r x))\n ∙ (spoke n -1 r x)\n ∙ (! (spoke n -1 r norₙ') ∙ fₙ-x₀ n (r norₙ'))\n\n {- The statement that k == ap pₙ ∘ h: -}\n k-p-h : k == ap (point S n -1) ∘ h\n k-p-h = λ= (λ (x : Sphere' {i} n)\n → k x\n =⟨ idp ⟩\n ! (Point (r x))\n ∙ (ap (point (S n) -1) (spoke n -1 r x) ∙ (Hub r))\n =⟨ !-ap (point S n -1) (fₙ-x₀ n (r x))\n ∙ᵣ ( ap (point S n -1) (spoke n -1 r x)\n ∙ Hub r) ⟩\n ap (point (S n) -1) (! (fₙ-x₀ n (r x)))\n ∙ ap (point (S n) -1) (spoke n -1 r x)\n ∙ (Hub r)\n =⟨ ! (ap (point (S n) -1) (! (fₙ-x₀ n (r x)))\n ∙ₗ ap-∙ point S n -1\n (spoke n -1 r x)\n _ ) ⟩\n ap (point (S n) -1) (! (fₙ-x₀ n (r x)))\n ∙ ap (point (S n) -1)\n ( spoke n -1 r x\n ∙ (! (spoke n -1 r norₙ')\n ∙ fₙ-x₀ n (r norₙ')))\n =⟨ ! (ap-∙ point S n -1 (! (fₙ-x₀ n (r x))) _) ⟩ \n ap (point S n -1) (h x)\n ∎)\n\n {- [h] can be made into a a pointed map, written [ĥ] -}\n ĥ : (⊙Sphere' {i} n)\n →̇ ⊙Ω (A (S n) ,\n f n fⁿx₀)\n ĥ = h , \n (! (fₙ-x₀ n (r _)) \n ∙ (spoke n -1 r _)\n ∙ ! (spoke n -1 r norₙ')\n ∙ fₙ-x₀ n (r norₙ')\n\n =⟨ (! (fₙ-x₀ n (r _)))\n ∙ₗ (! (∙-assoc (spoke n -1 r _)\n (! (spoke n -1 r norₙ'))\n (fₙ-x₀ n (r norₙ')))) ⟩\n \n ! (fₙ-x₀ n (r _))\n ∙ ((spoke n -1 r _) ∙ (! (spoke n -1 r norₙ')))\n ∙ fₙ-x₀ n (r norₙ')\n \n =⟨ ! (fₙ-x₀ n (r _))\n ∙ₗ !-inv-r (spoke n -1 r _)\n ∙ᵣ fₙ-x₀ n (r norₙ') ⟩\n\n ! (fₙ-x₀ n (r _))\n ∙ idp\n ∙ fₙ-x₀ n (r norₙ')\n\n \n =⟨ !-inv-l (fₙ-x₀ n (r _)) ⟩\n \n idp\n \n ∎ )\n\n {- A pointed version of the first constructor. -}\n pointsₙ : (A (S n) , f n fⁿx₀) →̇ A (S (S n)) , f (S n) (f n fⁿx₀) \n pointsₙ = point S n -1 , idp \n\n open null\n open hom-adjoint\n \n points-Φ⁻¹-null : isNull∙ (pointsₙ ⊙∘ Φ⁻¹ _ _ ĥ) \n points-Φ⁻¹-null = <– (isNull-equiv (pointsₙ ⊙∘ Φ⁻¹ _ _ ĥ))\n -- translate from isNull∙'\n (null-lequiv (pointsₙ ⊙∘ Φ⁻¹ _ _ ĥ)\n -- translate from isNulld; this,\n -- we have done already!\n (cmp-nll'.from-sphere-null'∙ n (Φ⁻¹ _ _ ĥ)))\n\n ap-points-ĥ-null : isNull∙ (⊙ap (point S n -1 , idp) ⊙∘ ĥ)\n ap-points-ĥ-null = –> (combine-isnull-nat' ĥ (point S n -1 , idp)) points-Φ⁻¹-null\n\n {- ... consequently, h is always refl [in the library \"idp\"]: -}\n points-h-const : (x : Sphere' n) → ap (point S n -1) (h x) == idp\n points-h-const x = null-lequiv-easy _ ap-points-ĥ-null x \n\n {- ... and so is k: -}\n k-const : (x : Sphere' n) → k x == idp\n k-const x = app= k-p-h x ∙ points-h-const x \n\n\n\n\n\n {- Main result: each function in the sequence is propositional! -}\n wconst-f : wconst-chain C\n wconst-f n w₁ w₂ = fₙ-x₀ n w₁ ∙ ! (fₙ-x₀ n w₂)\n\n\n{- Another important result: \n if we want to show a proposition, we can assume A₀ instead of Aω\n But this should follow from the general induction principle, so... TODO\n-} \nmodule PtruncSeqResult' {i} (X : Type i) where\n\n open PtruncsSeq {i} X -- this defines the chain C of pseudo-truncations\n\n SC = SeqCo C\n\n reduction-lemma : (P : Type i) → (is-prop P) → (A O → P) → (SC → P)\n reduction-lemma P ip ff = SeqCo-rec {C = C} {B = P} Ins Glue where\n\n Ins : (n : ℕ) → A n → P\n Ins O = ff \n Ins (S n) = Pseudotrunc-rec {P = P} n Point-1 Hub-1 Spoke-1 where\n Point-1 : _ → P\n Point-1 x = Ins n x\n Hub-1 : (Sphere' n → A n) → P\n Hub-1 r = Ins n (r (nor' n))\n Spoke-1 : (r : Sphere' n → A n) (x : Sphere' n) → Point-1 (r x) == Hub-1 r\n Spoke-1 r x = prop-has-all-paths {A = P} ip _ _\n\n Glue : (n : ℕ) (a : A n) → Ins n a == Ins (S n) (f n a) \n Glue n a = prop-has-all-paths ip _ _\n\n\n{- Corollary of the main result: The colimit of the considered sequence is propositional! -}\nmodule PtruncSeqResult {i} (X : Type i) where\n\n open PtruncsSeq {i} X -- this defines the chain C of pseudo-truncations\n\n colim-is-prp : is-prop (SeqCo C)\n colim-is-prp =\n inhab-to-contr-is-prop\n (PtruncSeqResult'.reduction-lemma X (is-contr (SeqCo C)) has-level-is-prop\n (λ x₀ → ins O x₀ , prop-has-all-paths (wconst-prop C (PtruncSeqWC.wconst-f X x₀))\n (ins O x₀)))\n\n\n open PtruncSeqResult' X\n\n {- If we have the propositional truncation in the theory: -}\n open import lib.types.Truncation\n \n colim-is-trunc : (Trunc ⟨-1⟩ X) ≃ SeqCo C\n colim-is-trunc = equiv (Trunc-rec (colim-is-prp) (ins 0))\n (reduction-lemma (Trunc ⟨-1⟩ X) Trunc-level [_])\n (λ _ → prop-has-all-paths colim-is-prp _ _)\n (λ _ → prop-has-all-paths Trunc-level _ _)\n\n", "meta": {"hexsha": "36232f1e491af8039961a7842f379ba6ba73baf2", "size": 10100, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "nicolai/pseudotruncations/PseudoTruncs-wconst-seq.agda", "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolai/pseudotruncations/PseudoTruncs-wconst-seq.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": "nicolai/pseudotruncations/PseudoTruncs-wconst-seq.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": 35.5633802817, "max_line_length": 94, "alphanum_fraction": 0.4685148515, "num_tokens": 3478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.3744900454711885}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\n\nmodule stash.modalities.gbm.GbmUtil where\n\n BM-Relation : ∀ {ℓ} (M : Modality ℓ) {A : Type ℓ} {B : Type ℓ} (Q : A → B → Type ℓ) → Type ℓ\n BM-Relation M {A} {B} Q =\n {a₀ : A} {b₀ : B} (q₀ : Q a₀ b₀)\n {a₁ : A} (q₁ : Q a₁ b₀)\n {b₁ : B} (q₂ : Q a₀ b₁) → \n Modality.is-◯-connected M (((a₀ , q₀) == (a₁ , q₁)) * ((b₀ , q₀) == (b₁ , q₂)))\n\n\n prop-lemma : ∀ {ℓ} {A : Type ℓ} {a₀ a₁ : A} (P : A → hProp ℓ)\n (p : a₀ == a₁) (x₀ : (fst ∘ P) a₀) (x₁ : (fst ∘ P) a₁) →\n x₀ == x₁ [ (fst ∘ P) ↓ p ]\n prop-lemma P idp x₀ x₁ = prop-has-all-paths (snd (P _)) x₀ x₁ \n\n pths-ovr-is-prop : ∀ {ℓ} {A : Type ℓ} {a₀ a₁ : A} (P : A → hProp ℓ)\n (p : a₀ == a₁) (x₀ : (fst ∘ P) a₀) (x₁ : (fst ∘ P) a₁) →\n is-prop (x₀ == x₁ [ (fst ∘ P) ↓ p ])\n pths-ovr-is-prop P idp x₀ x₁ = =-preserves-level (snd (P _)) \n\n pths-ovr-contr : ∀ {ℓ} {A : Type ℓ} {a₀ a₁ : A} (P : A → hProp ℓ)\n (p : a₀ == a₁) (x₀ : (fst ∘ P) a₀) (x₁ : (fst ∘ P) a₁) →\n is-contr (x₀ == x₁ [ (fst ∘ P) ↓ p ])\n pths-ovr-contr P idp x₀ x₁ = =-preserves-level (inhab-prop-is-contr x₀ (snd (P _)))\n \n eqv-square : ∀ {i j} {A : Type i} {B : Type j} (e : A ≃ B)\n {b b' : B} (p : b == b')\n → ap (–> e ∘ <– e) p == (<–-inv-r e b) ∙ p ∙ (! (<–-inv-r e b'))\n eqv-square e idp = ! (!-inv-r (<–-inv-r e _))\n\n eqv-square' : ∀ {i j} {A : Type i} {B : Type j} (e : A ≃ B)\n {a a' : A} (p : a == a')\n → ap (<– e ∘ –> e) p == <–-inv-l e a ∙ p ∙ ! (<–-inv-l e a')\n eqv-square' e idp = ! (!-inv-r (<–-inv-l e _))\n \n ↓-==-in : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B}\n {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}\n → (u ∙ ap g p) == (ap f p ∙ v)\n → (u == v [ (λ x → f x == g x) ↓ p ])\n ↓-==-in {p = idp} q = ! (∙-unit-r _) ∙ q\n\n ↓-==-out : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B}\n {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}\n → (u == v [ (λ x → f x == g x) ↓ p ])\n → (u ∙ ap g p) == (ap f p ∙ v)\n ↓-==-out {p = idp} q = (∙-unit-r _) ∙ q \n\n module HFiberSrcEquiv {i₀ i₁ i₂} {A : Type i₀} {B : Type i₁} {C : Type i₂}\n (f : A → B) (h : B → C) (k : A → C)\n (w : (a : A) → h (f a) == k a)\n (ise-f : is-equiv f) \n where\n\n private\n g = is-equiv.g ise-f\n f-g = is-equiv.f-g ise-f\n g-f = is-equiv.g-f ise-f\n adj = is-equiv.adj ise-f\n adj' = is-equiv.adj' ise-f\n\n to : (c : C) → hfiber k c → hfiber h c\n to .(k a) (a , idp) = f a , w a\n\n to-lem₀ : (c : C) (x : hfiber k c) → fst (to c x) == f (fst x)\n to-lem₀ .(k a) (a , idp) = idp\n\n to-lem₁ : (c : C) (x : hfiber k c) → snd (to c x) == ap h (to-lem₀ c x) ∙ w (fst x) ∙ snd x \n to-lem₁ .(k a) (a , idp) = ! (∙-unit-r (w a))\n \n from : (c : C) → hfiber h c → hfiber k c\n from .(h b) (b , idp) = g b , ! (w (g b)) ∙ ap h (f-g b)\n\n from-lem₀ : (c : C) (x : hfiber h c) → fst (from c x) == g (fst x)\n from-lem₀ .(h b) (b , idp) = idp\n\n from-lem₁ : (c : C) (x : hfiber h c) → snd (from c x) == ap k (from-lem₀ c x) ∙ (! (w (g (fst x)))) ∙ ap h (f-g (fst x)) ∙ snd x\n from-lem₁ .(h b) (b , idp) = ap (λ p → ! (w (g b)) ∙ p) (! (∙-unit-r (ap h (f-g b))))\n\n to-from : (c : C) (x : hfiber h c) → to c (from c x) == x\n to-from .(h b) (b , idp) = pair= (q ∙ f-g b) (↓-app=cst-in (r ∙ eq))\n\n where c = h b\n p = ! (w (g b)) ∙ ap h (f-g b)\n q = to-lem₀ c (g b , p)\n r = to-lem₁ c (g b , p)\n\n eq = ap h q ∙ w (g b) ∙ ! (w (g b)) ∙ ap h (f-g b)\n =⟨ ! (∙-assoc (w (g b)) (! (w (g b))) (ap h (f-g b))) |in-ctx (λ x → ap h q ∙ x) ⟩\n ap h q ∙ (w (g b) ∙ (! (w (g b)))) ∙ ap h (f-g b)\n =⟨ !-inv-r (w (g b)) |in-ctx (λ x → ap h q ∙ x ∙ ap h (f-g b)) ⟩ \n ap h q ∙ ap h (f-g b)\n =⟨ ∙-ap h q (f-g b) ⟩\n ap h (q ∙ f-g b)\n =⟨ ! (∙-unit-r (ap h (q ∙ f-g b))) ⟩ \n ap h (q ∙ f-g b) ∙ idp ∎\n\n from-to : (c : C) (x : hfiber k c) → from c (to c x) == x\n from-to .(k a) (a , idp) = pair= (p ∙ g-f a) (↓-app=cst-in (q ∙ eq))\n\n where c = k a\n p = from-lem₀ c (f a , w a)\n q = from-lem₁ c (f a , w a)\n\n eq = ap k p ∙ ! (w (g (f a))) ∙ ap h (f-g (f a)) ∙ w a\n =⟨ ! (adj a) |in-ctx (λ x → ap k p ∙ ! (w (g (f a))) ∙ ap h x ∙ w a) ⟩\n ap k p ∙ ! (w (g (f a))) ∙ ap h (ap f (g-f a)) ∙ w a\n =⟨ ∘-ap h f (g-f a) |in-ctx (λ x → ap k p ∙ ! (w (g (f a))) ∙ x ∙ w a) ⟩ \n ap k p ∙ ! (w (g (f a))) ∙ ap (h ∘ f) (g-f a) ∙ w a\n =⟨ ! (↓-='-out (apd w (g-f a))) |in-ctx (λ x → ap k p ∙ ! (w (g (f a))) ∙ x) ⟩\n ap k p ∙ ! (w (g (f a))) ∙ w (g (f a)) ∙' ap k (g-f a)\n =⟨ ∙'=∙ (w (g (f a))) (ap k (g-f a)) |in-ctx (λ x → ap k p ∙ ! (w (g (f a))) ∙ x) ⟩ \n ap k p ∙ ! (w (g (f a))) ∙ w (g (f a)) ∙ ap k (g-f a)\n =⟨ ! (∙-assoc (! (w (g (f a)))) (w (g (f a))) (ap k (g-f a))) |in-ctx (λ x → ap k p ∙ x) ⟩ \n ap k p ∙ (! (w (g (f a))) ∙ w (g (f a))) ∙ ap k (g-f a)\n =⟨ !-inv-l (w (g (f a))) |in-ctx (λ x → ap k p ∙ x ∙ ap k (g-f a)) ⟩ \n ap k p ∙ ap k (g-f a)\n =⟨ ∙-ap k p (g-f a) ⟩ \n ap k (p ∙ g-f a)\n =⟨ ! (∙-unit-r (ap k (p ∙ g-f a))) ⟩ \n ap k (p ∙ g-f a) ∙ idp ∎\n\n eqv : (c : C) → hfiber k c ≃ hfiber h c\n eqv c = equiv (to c) (from c) (to-from c) (from-to c)\n\n\n module HFiberTgtEquiv {i₀ i₁ i₂} {A : Type i₀} {B : Type i₁} {C : Type i₂}\n (h : A → B) (k : A → C) (f : B → C)\n (w : (a : A) → k a == f (h a))\n (ise-f : is-equiv f) \n where\n\n private\n g = is-equiv.g ise-f\n f-g = is-equiv.f-g ise-f\n g-f = is-equiv.g-f ise-f\n adj = is-equiv.adj ise-f\n adj' = is-equiv.adj' ise-f\n\n to : (b : B) → hfiber h b → hfiber k (f b)\n to .(h a) (a , idp) = a , w a\n\n to-lem₀ : (b : B) (x : hfiber h b) → fst (to b x) == fst x\n to-lem₀ .(h a) (a , idp) = idp\n\n to-lem₁ : (b : B) (x : hfiber h b) → snd (to b x) == ap k (to-lem₀ b x) ∙ w (fst x) ∙ ap f (snd x)\n to-lem₁ .(h a) (a , idp) = ! (∙-unit-r (w a))\n \n from : (b : B) → hfiber k (f b) → hfiber h b\n from b (a , p) = a , (! (g-f (h a)) ∙ ap g (! (w a) ∙ p) ∙ g-f b)\n\n to-from : (b : B) (x : hfiber k (f b)) → to b (from b x) == x\n to-from b (a , p) = pair= r (↓-app=cst-in (s ∙ (ap (λ x → ap k r ∙ x) eq)))\n\n where q = ! (g-f (h a)) ∙ ap g (! (w a) ∙ p) ∙ g-f b\n r = to-lem₀ b (a , q)\n s = to-lem₁ b (a , q)\n\n eq = w a ∙ ap f q\n =⟨ ! (∙-ap f (! (g-f (h a))) (ap g (! (w a) ∙ p) ∙ g-f b)) |in-ctx (λ x → w a ∙ x) ⟩\n w a ∙ ap f (! (g-f (h a))) ∙ ap f (ap g (! (w a) ∙ p) ∙ g-f b)\n =⟨ ! (∙-ap f (ap g (! (w a) ∙ p)) (g-f b)) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ x) ⟩\n w a ∙ ap f (! (g-f (h a))) ∙ ap f (ap g (! (w a) ∙ p)) ∙ ap f (g-f b)\n =⟨ ∘-ap f g (! (w a) ∙ p) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ x ∙ ap f (g-f b)) ⟩\n w a ∙ ap f (! (g-f (h a))) ∙ ap (f ∘ g) (! (w a) ∙ p) ∙ ap f (g-f b)\n =⟨ ap (λ x → w a ∙ ap f (! (g-f (h a))) ∙ x ∙ ap f (g-f b)) (eqv-square (f , ise-f) (! (w a) ∙ p)) ⟩\n w a ∙ ap f (! (g-f (h a))) ∙ (f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ ! (f-g (f b))) ∙ ap f (g-f b)\n =⟨ adj b |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ (f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ ! (f-g (f b))) ∙ x) ⟩ \n w a ∙ ap f (! (g-f (h a))) ∙ (f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ ! (f-g (f b))) ∙ f-g (f b)\n =⟨ ∙-assoc (f-g (f (h a))) ((! (w a) ∙ p) ∙ ! (f-g (f b))) (f-g (f b)) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ x) ⟩\n w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ ((! (w a) ∙ p) ∙ ! (f-g (f b))) ∙ f-g (f b)\n =⟨ ∙-assoc (! (w a) ∙ p) (! (f-g (f b))) (f-g (f b)) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ x) ⟩ \n w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ ! (f-g (f b)) ∙ f-g (f b)\n =⟨ !-inv-l (f-g (f b)) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ x) ⟩ \n w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ idp\n =⟨ ∙-unit-r (! (w a) ∙ p) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ x) ⟩ \n w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ ! (w a) ∙ p\n =⟨ ap-! f (g-f (h a)) |in-ctx (λ x → w a ∙ x ∙ f-g (f (h a)) ∙ ! (w a) ∙ p) ⟩\n w a ∙ ! (ap f (g-f (h a))) ∙ f-g (f (h a)) ∙ ! (w a) ∙ p\n =⟨ ! (adj (h a)) |in-ctx (λ x → w a ∙ ! (ap f (g-f (h a))) ∙ x ∙ ! (w a) ∙ p) ⟩ \n w a ∙ ! (ap f (g-f (h a))) ∙ ap f (g-f (h a)) ∙ ! (w a) ∙ p\n =⟨ ! (∙-assoc (! (ap f (g-f (h a)))) (ap f (g-f (h a))) (! (w a) ∙ p)) |in-ctx (λ x → w a ∙ x)⟩\n w a ∙ (! (ap f (g-f (h a))) ∙ ap f (g-f (h a))) ∙ ! (w a) ∙ p\n =⟨ !-inv-l (ap f (g-f (h a))) |in-ctx (λ x → w a ∙ x ∙ ! (w a) ∙ p)⟩ \n w a ∙ ! (w a) ∙ p\n =⟨ ! (∙-assoc (w a) (! (w a)) p) ⟩\n (w a ∙ ! (w a)) ∙ p\n =⟨ !-inv-r (w a) |in-ctx (λ x → x ∙ p) ⟩ \n p ∎\n\n from-to : (b : B) (x : hfiber h b) → from b (to b x) == x\n from-to .(h a) (a , idp) = pair= idp eq\n\n where eq = ! (g-f (h a)) ∙ ap g (! (w a) ∙ w a) ∙ g-f (h a)\n =⟨ !-inv-l (w a)|in-ctx (λ x → ! (g-f (h a)) ∙ ap g x ∙ g-f (h a)) ⟩\n ! (g-f (h a)) ∙ g-f (h a)\n =⟨ !-inv-l (g-f (h a)) ⟩ \n idp ∎\n \n eqv : (b : B) → hfiber h b ≃ hfiber k (f b)\n eqv b = equiv (to b) (from b) (to-from b) (from-to b)\n\n module HFiberSqEquiv {i₀ i₁ j₀ j₁}\n {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}\n (f₀ : A₀ → B₀) (f₁ : A₁ → B₁) (hA : A₀ → A₁) (hB : B₀ → B₁)\n (sq : CommSquare f₀ f₁ hA hB) (ise-hA : is-equiv hA) (ise-hB : is-equiv hB) where\n\n open CommSquare\n\n private\n gB = is-equiv.g ise-hB\n\n \n module Src = HFiberSrcEquiv hA f₁ (hB ∘ f₀) (λ a₀ → ! (commutes sq a₀)) ise-hA\n module Tgt = HFiberTgtEquiv f₀ (f₁ ∘ hA) hB (λ a₀ → ! (commutes sq a₀)) ise-hB\n\n eqv : (b₀ : B₀) → hfiber f₀ b₀ ≃ hfiber f₁ (hB b₀)\n eqv b₀ = Src.eqv (hB b₀)\n ∘e coe-equiv (ap (λ s → hfiber s (hB b₀)) (λ= (λ a₀ → ! (commutes sq a₀))))\n ∘e Tgt.eqv b₀\n\n hfiber-sq-eqv : ∀ {i₀ i₁ j₀ j₁}\n {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}\n (f₀ : A₀ → B₀) (f₁ : A₁ → B₁) (hA : A₀ → A₁) (hB : B₀ → B₁)\n (sq : CommSquare f₀ f₁ hA hB) (ise-hA : is-equiv hA) (ise-hB : is-equiv hB) →\n (b₀ : B₀) → hfiber f₀ b₀ ≃ hfiber f₁ (hB b₀)\n hfiber-sq-eqv f₀ f₁ hA hB sq ise-hA ise-hB b₀ = M.eqv b₀\n\n where module M = HFiberSqEquiv f₀ f₁ hA hB sq ise-hA ise-hB\n", "meta": {"hexsha": "86003e6d9447230eefd56716683c4ed18b8a885c", "size": 11449, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/stash/modalities/gbm/GbmUtil.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/stash/modalities/gbm/GbmUtil.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/stash/modalities/gbm/GbmUtil.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 49.1373390558, "max_line_length": 141, "alphanum_fraction": 0.3431740763, "num_tokens": 5248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239957834733, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.3744674775104048}} {"text": "------------------------------------------------------------------------\n-- A definition of the propositional truncation operator that does not\n-- use recursive higher inductive types\n------------------------------------------------------------------------\n\n-- The definition does use natural numbers. The code is based on van\n-- Doorn's \"Constructing the Propositional Truncation using\n-- Non-recursive HITs\".\n\n{-# OPTIONS --erased-cubical --safe #-}\n\nimport Equality.Path as P\n\nmodule H-level.Truncation.Propositional.Non-recursive\n {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where\n\nprivate\n open module PD = P.Derived-definitions-and-properties eq\n hiding (elim)\n\nopen import Prelude\n\nopen import Colimit.Sequential eq as C using (Colimit)\nopen import Equality.Decidable-UIP equality-with-J\nopen import Equality.Path.Isomorphisms eq\nopen import Equivalence equality-with-J as Eq using (_≃_)\nopen import Function-universe equality-with-J as F\nopen import H-level equality-with-J\nopen import H-level.Closure equality-with-J\nimport H-level.Truncation.Propositional eq as T\nopen import H-level.Truncation.Propositional.Non-recursive.Erased eq\n as N using (∥_∥ᴱ)\nopen import H-level.Truncation.Propositional.One-step eq as O\n using (∥_∥¹; ∥_∥¹-out-^; ∣_∣-out-^)\n\nprivate\n variable\n a p : Level\n A B : Type a\n P : A → Type p\n e x : A\n\n-- The propositional truncation operator.\n\n∥_∥ : Type a → Type a\n∥ A ∥ = Colimit ∥ A ∥¹-out-^ O.∣_∣\n\n-- The point constructor.\n\n∣_∣ : A → ∥ A ∥\n∣_∣ = C.∣_∣\n\n-- The eliminator.\n\nrecord Elim {A : Type a} (P : ∥ A ∥ → Type p) : Type (a ⊔ p) where\n no-eta-equality\n field\n ∣∣ʳ : ∀ x → P ∣ x ∣\n is-propositionʳ : ∀ x → Is-proposition (P x)\n\nopen Elim public\n\nelim : Elim P → (x : ∥ A ∥) → P x\nelim {A = A} {P = P} e = C.elim λ where\n .C.Elim.∣∣ʳ {n = n} → helper n\n .C.Elim.∣∣≡∣∣ʳ _ → E.is-propositionʳ _ _ _\n where\n module E = Elim e\n\n helper : ∀ n (x : ∥ A ∥¹-out-^ n) → P C.∣ x ∣\n helper zero = E.∣∣ʳ\n helper (suc n) = O.elim λ where\n .O.Elim.∣∣ʳ x → subst P (sym (C.∣∣≡∣∣ x)) (helper n x)\n .O.Elim.∣∣-constantʳ _ _ → E.is-propositionʳ _ _ _\n\n_ : elim e ∣ x ∣ ≡ e .∣∣ʳ x\n_ = refl _\n\n-- The propositional truncation operator returns propositions.\n\n∥∥-proposition : Is-proposition ∥ A ∥\n∥∥-proposition {A = A} = elim λ where\n .is-propositionʳ → Π≡-proposition ext\n .∣∣ʳ x → C.elim λ where\n .C.Elim.∣∣ʳ → lemma₁ _ x\n .C.Elim.∣∣≡∣∣ʳ {n = n} y →\n subst (∣ x ∣ ≡_) (C.∣∣≡∣∣ y) (lemma₁ (suc n) x O.∣ y ∣) ≡⟨ sym trans-subst ⟩\n\n trans (lemma₁ (1 + n) x O.∣ y ∣) (C.∣∣≡∣∣ y) ≡⟨⟩\n\n trans (trans (sym (trans (C.∣∣≡∣∣ (∣ x ∣-out-^ (1 + n)))\n (lemma₀ (1 + n) x)))\n (trans (cong C.∣_∣\n (O.∣∣-constant\n (∣ x ∣-out-^ (1 + n)) O.∣ y ∣))\n (C.∣∣≡∣∣ O.∣ y ∣)))\n (C.∣∣≡∣∣ y) ≡⟨ trans (cong (λ eq → trans (trans eq\n (trans (cong C.∣_∣ (O.∣∣-constant _ _))\n (C.∣∣≡∣∣ _)))\n (C.∣∣≡∣∣ _)) $\n sym-trans _ _) $\n trans (trans-assoc _ _ _) $\n trans (trans-assoc _ _ _) $\n cong (trans (sym (lemma₀ (1 + n) _))) $\n sym $ trans-assoc _ _ _ ⟩\n trans (sym (lemma₀ (1 + n) x))\n (trans (trans (sym (C.∣∣≡∣∣ (∣ x ∣-out-^ (1 + n))))\n (trans (cong C.∣_∣\n (O.∣∣-constant\n (∣ x ∣-out-^ (1 + n)) O.∣ y ∣))\n (C.∣∣≡∣∣ O.∣ y ∣)))\n (C.∣∣≡∣∣ y)) ≡⟨ cong (λ eq → trans (sym (lemma₀ (1 + n) _))\n (trans (trans (sym (C.∣∣≡∣∣ _)) eq) (C.∣∣≡∣∣ _))) $ sym $\n lemma₂ _ _ _ _ _ ⟩\n trans (sym (lemma₀ (1 + n) x))\n (trans (trans (sym (C.∣∣≡∣∣ (∣ x ∣-out-^ (1 + n))))\n (trans (C.∣∣≡∣∣ (∣ x ∣-out-^ (1 + n)))\n (cong C.∣_∣ (O.∣∣-constant _ _))))\n (C.∣∣≡∣∣ y)) ≡⟨ cong (λ eq → trans (sym (lemma₀ (1 + n) _)) (trans eq (C.∣∣≡∣∣ _))) $\n trans-sym-[trans] _ _ ⟩\n trans (sym (lemma₀ (1 + n) x))\n (trans (cong C.∣_∣ (O.∣∣-constant _ _)) (C.∣∣≡∣∣ y)) ≡⟨⟩\n\n lemma₁ n x y ∎\n where\n lemma₀ : ∀ n (x : A) → C.∣ ∣ x ∣-out-^ n ∣ ≡ ∣ x ∣\n lemma₀ zero x = ∣ x ∣ ∎\n lemma₀ (suc n) x =\n C.∣ O.∣ ∣ x ∣-out-^ n ∣ ∣ ≡⟨ C.∣∣≡∣∣ (∣ x ∣-out-^ n) ⟩\n C.∣ ∣ x ∣-out-^ n ∣ ≡⟨ lemma₀ n x ⟩∎\n ∣ x ∣ ∎\n\n lemma₁ : ∀ n (x : A) (y : ∥ A ∥¹-out-^ n) → ∣ x ∣ ≡ C.∣ y ∣\n lemma₁ n x y =\n ∣ x ∣ ≡⟨ sym (lemma₀ (suc n) x) ⟩\n C.∣ ∣ x ∣-out-^ (suc n) ∣ ≡⟨⟩\n C.∣ O.∣ ∣ x ∣-out-^ n ∣ ∣ ≡⟨ cong C.∣_∣ (O.∣∣-constant _ _) ⟩\n C.∣ O.∣ y ∣ ∣ ≡⟨ C.∣∣≡∣∣ y ⟩∎\n C.∣ y ∣ ∎\n\n lemma₂ :\n ∀ n (x y : ∥ A ∥¹-out-^ n) (p : x ≡ y) (q : O.∣ x ∣ ≡ O.∣ y ∣) →\n trans (C.∣∣≡∣∣ {P = ∥ A ∥¹-out-^} x) (cong C.∣_∣ p) ≡\n trans (cong C.∣_∣ q) (C.∣∣≡∣∣ y)\n lemma₂ n x y p q =\n trans (C.∣∣≡∣∣ x) (cong C.∣_∣ p) ≡⟨ PD.elim\n (λ {x y} p → trans (C.∣∣≡∣∣ x) (cong C.∣_∣ p) ≡\n trans (cong C.∣_∣ (cong O.∣_∣ p)) (C.∣∣≡∣∣ y))\n (λ x →\n trans (C.∣∣≡∣∣ x) (cong C.∣_∣ (refl _)) ≡⟨ cong (trans _) $ cong-refl _ ⟩\n trans (C.∣∣≡∣∣ x) (refl _) ≡⟨ trans-reflʳ _ ⟩\n C.∣∣≡∣∣ x ≡⟨ sym $ trans-reflˡ _ ⟩\n trans (refl _) (C.∣∣≡∣∣ x) ≡⟨ cong (flip trans _) $ sym $\n trans (cong (cong C.∣_∣) $ cong-refl _) $\n cong-refl _ ⟩∎\n trans (cong C.∣_∣ (cong O.∣_∣ (refl _))) (C.∣∣≡∣∣ x) ∎)\n p ⟩\n\n trans (cong C.∣_∣ (cong O.∣_∣ p)) (C.∣∣≡∣∣ y) ≡⟨ cong (flip trans _) $\n cong-preserves-Constant\n (λ u v →\n C.∣ u ∣ ≡⟨ sym (C.∣∣≡∣∣ u) ⟩\n C.∣ O.∣ u ∣ ∣ ≡⟨ cong C.∣_∣ (O.∣∣-constant _ _) ⟩\n C.∣ O.∣ v ∣ ∣ ≡⟨ C.∣∣≡∣∣ v ⟩∎\n C.∣ v ∣ ∎)\n _ _ ⟩∎\n trans (cong C.∣_∣ q) (C.∣∣≡∣∣ y) ∎\n\n-- ∥_∥ is pointwise equivalent to T.∥_∥.\n\n∥∥≃∥∥ : ∥ A ∥ ≃ T.∥ A ∥\n∥∥≃∥∥ = Eq.⇔→≃\n ∥∥-proposition\n T.truncation-is-proposition\n (elim λ where\n .∣∣ʳ → T.∣_∣\n .is-propositionʳ _ → T.truncation-is-proposition)\n (T.rec ∥∥-proposition ∣_∣)\n\n-- Functions from T.∥ A ∥ can be expressed as families of functions\n-- from ∥ A ∥¹-out-^ that satisfy a certain property.\n\n∥∥→≃ :\n (T.∥ A ∥ → B)\n ≃\n (∃ λ (f : ∀ n → ∥ A ∥¹-out-^ n → B) →\n ∀ n x → f (suc n) O.∣ x ∣ ≡ f n x)\n∥∥→≃ {A = A} {B = B} =\n (T.∥ A ∥ → B) ↝⟨ →-cong ext (inverse ∥∥≃∥∥) F.id ⟩\n\n (∥ A ∥ → B) ↝⟨ C.universal-property ⟩□\n\n (∃ λ (f : ∀ n → ∥ A ∥¹-out-^ n → B) →\n ∀ n x → f (suc n) O.∣ x ∣ ≡ f n x) □\n\n------------------------------------------------------------------------\n-- Some conversion functions\n\n-- ∥ A ∥ᴱ implies ∥ A ∥.\n\n∥∥ᴱ→∥∥ : ∥ A ∥ᴱ → ∥ A ∥\n∥∥ᴱ→∥∥ = N.elim λ where\n .N.∣∣ʳ → ∣_∣\n .N.is-propositionʳ _ → ∥∥-proposition\n\n-- In erased contexts ∥ A ∥ᴱ and ∥ A ∥ are equivalent.\n\n@0 ∥∥ᴱ≃∥∥ : ∥ A ∥ᴱ ≃ ∥ A ∥\n∥∥ᴱ≃∥∥ = Eq.↔→≃\n ∥∥ᴱ→∥∥\n (elim λ @0 where\n .∣∣ʳ → N.∣_∣\n .is-propositionʳ _ → N.∥∥ᴱ-proposition)\n (elim λ @0 where\n .∣∣ʳ _ → refl _\n .is-propositionʳ _ → mono₁ 1 ∥∥-proposition)\n (N.elim λ where\n .N.∣∣ʳ _ → refl _\n .N.is-propositionʳ _ → mono₁ 1 N.∥∥ᴱ-proposition)\n", "meta": {"hexsha": "a2903018fcbe35e7f0a08b0314d99dd8c5019a61", "size": 9168, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/H-level/Truncation/Propositional/Non-recursive.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/H-level/Truncation/Propositional/Non-recursive.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/H-level/Truncation/Propositional/Non-recursive.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": 41.6727272727, "max_line_length": 141, "alphanum_fraction": 0.3447862129, "num_tokens": 3495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6893056040203135, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3741987033076742}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import Base\nopen import Homotopy.Connected\n\n{-\n Wedge is a pushout.\n-}\n\nmodule Homotopy.Wedge\n where\n\n import Homotopy.Pushout as P\n\n record wedge-diag i : Set (suc i) where\n constructor diag_,_,_,_\n field\n A : Set i\n B : Set i\n a : A\n b : B\n\n f : unit {i} → A\n f _ = a\n g : unit {i} → B\n g _ = b\n\n wedge-diag-to-pushout-diag : ∀ {i} → wedge-diag i → P.pushout-diag i\n wedge-diag-to-pushout-diag {i} (diag A , B , a , b) = P.diag A , B , unit {i} , (λ _ → a) , (λ _ → b)\n\n wedge : ∀ {i} → wedge-diag i → Set i\n wedge d = P.pushout (wedge-diag-to-pushout-diag d)\n\n left : ∀ {i} {d : wedge-diag i} → wedge-diag.A d → wedge d\n left = P.left\n\n right : ∀ {i} {d : wedge-diag i} → wedge-diag.B d → wedge d\n right = P.right\n\n glue : ∀ {i} {d : wedge-diag i} → left (wedge-diag.a d) ≡ right (wedge-diag.b d)\n glue = P.glue tt\n\n wedge-rec : ∀ {i} {d : wedge-diag i}\n → let open wedge-diag d in\n ∀ {j} (P : wedge d → Set j)\n (left* : ∀ a → P (left a))\n (right* : ∀ b → P (right b))\n (glue* : transport P glue (left* a) ≡ right* b)\n → (∀ x → P x)\n wedge-rec P left* right* glue* = P.pushout-rec P left* right* (λ _ → glue*)\n\n wedge-rec-nondep : ∀ {i} {d : wedge-diag i}\n → let open wedge-diag d in\n ∀ {j} (P : Set j)\n (left* : ∀ a → P)\n (right* : ∀ b → P)\n (glue* : left* a ≡ right* b)\n → (wedge d → P)\n wedge-rec-nondep P left* right* glue* = P.pushout-rec-nondep P left* right* (λ _ → glue*)\n\n{-\n module _ (f : X → Y) where\n nA (A-is-conn : is-connected n A)\n nB (B-is-conn : is-connected n B)\n (P : A → B → Set k)\n ⦃ P-is-trunc : ∀ a b → is-connected (n +2+ m) (P a b) ⦄\n extension : \n-}\n", "meta": {"hexsha": "3b078cfd9fc19be00bed48c6091768c6ddc7ca0c", "size": 1716, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "old/Homotopy/Wedge.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": "old/Homotopy/Wedge.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": "old/Homotopy/Wedge.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": 24.8695652174, "max_line_length": 103, "alphanum_fraction": 0.5285547786, "num_tokens": 668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544085240401, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.3741699352114445}} {"text": "\nopen import Oscar.Prelude\nopen import Oscar.Class.Smap\nopen import Oscar.Data.Proposequality\nopen import Oscar.Class.Surjection\n\nmodule Oscar.Data.Surjcollation where\n\n𝓼urjcollation : ∀ {𝔵₁ 𝔵₂ 𝔞 𝔟} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂}\n (surjection : Surjection.type 𝔛₁ 𝔛₂)\n 𝔟̇\n (𝔅 : 𝔛₂ → Ø 𝔟)\n (𝔄 : π̂² 𝔞 𝔛₁)\n → Ø 𝔵₁ ∙̂ 𝔞 ∙̂ 𝔟 ∙̂ ↑̂ 𝔟̇\n𝓼urjcollation surjection 𝔟̇ 𝔅 𝔄 = ∀ {m} → 𝔅 (surjection m) → 𝔅 (surjection m) → LeftṖroperty 𝔟̇ 𝔄 m\n\nmodule _ {𝔵₁ 𝔵₂ 𝔞 𝔟 𝔟̇} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂}\n (𝔅 : 𝔛₂ → Ø 𝔟)\n (𝔄 : π̂² 𝔞 𝔛₁)\n ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄\n ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄\n (𝔅̇ : ∀̇ π̂² 𝔟̇ 𝔅)\n (let infix 4 _⟨𝔅̇⟩_\n _⟨𝔅̇⟩_ : ∀ {x} → 𝔅 x → 𝔅 x → Ø 𝔟̇\n _⟨𝔅̇⟩_ p q = 𝔅̇ p q)\n where\n surjcollation[_]⟦_/_⟧ : 𝓼urjcollation surjection 𝔟̇ 𝔅 𝔄\n surjcollation[_]⟦_/_⟧ p q .π₀ x = x ◃ p ⟨𝔅̇⟩ x ◃ q\n\nmodule _ {𝔵₁ 𝔵₂ 𝔞 𝔟 𝔟̇} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} {𝔅 : 𝔛₂ → Ø 𝔟}\n (𝔄 : π̂² 𝔞 𝔛₁)\n ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄\n ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄\n (𝔅̇ : ∀̇ π̂² 𝔟̇ 𝔅)\n where\n surjcollation⟦_/_⟧ = surjcollation[ 𝔅 ]⟦ 𝔄 / 𝔅̇ ⟧\n\nmodule _ {𝔵₁ 𝔵₂ 𝔞} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂}\n (𝔄 : 𝔛₁ → 𝔛₁ → Ø 𝔞)\n {𝔟} {𝔅 : 𝔛₂ → Ø 𝔟}\n ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄\n ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄\n {𝔟̇} {𝔅̇ : ∀ {x} → 𝔅 x → 𝔅 x → Ø 𝔟̇}\n where\n surjcollation⟦_⟧ = surjcollation[ 𝔅 ]⟦ 𝔄 / 𝔅̇ ⟧\n\nmodule _ {𝔵₁ 𝔵₂ 𝔞 𝔟} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂}\n (𝔅 : 𝔛₂ → Ø 𝔟)\n (𝔄 : π̂² 𝔞 𝔛₁)\n ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄\n ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄\n where\n ≡-surjcollation[_]⟦_⟧ = surjcollation[ 𝔅 ]⟦ 𝔄 / _≡_ ⟧\n\nmodule _ {𝔵₁ 𝔞} {𝔛₁ : Ø 𝔵₁}\n (𝔄 : π̂² 𝔞 𝔛₁)\n {𝔵₂} {𝔛₂ : Ø 𝔵₂} ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄\n {𝔟} {𝔅 : 𝔛₂ → Ø 𝔟} ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄\n where\n ≡-surjcollation⟦_⟧ = ≡-surjcollation[ 𝔅 ]⟦ 𝔄 ⟧\n\nmodule _ {𝔵₁ 𝔞} {𝔛₁ : Ø 𝔵₁} {𝔄 : π̂² 𝔞 𝔛₁}\n where\n ≡-surjcollation = ≡-surjcollation⟦ 𝔄 ⟧\n\nmodule Surjcollation {𝔵₁ 𝔵₂ 𝔞 𝔟̇} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} ⦃ _ : Surjection.class 𝔛₁ 𝔛₂ ⦄\n (𝔄 : 𝔛₁ → 𝔛₁ → Ø 𝔞)\n (𝔅̇ : ∀ {𝔟} {𝔅 : 𝔛₂ → Ø 𝔟} → (∀ {x} → 𝔅 x → 𝔅 x → Ø 𝔟̇))\n {𝔟} {𝔅 : 𝔛₂ → Ø 𝔟}\n ⦃ _ : Smaphomarrow!.class 𝔄 𝔅 ⦄\n where\n method = surjcollation[ 𝔅 ]⟦ 𝔄 / 𝔅̇ {𝔅 = 𝔅} ⟧\n\n infix 18 _⟹_\n _⟹_ = method\n", "meta": {"hexsha": "482448c3c1ed912fc17c56aa4e4bd01885074912", "size": 2134, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "archive/agda-3/src/Oscar/Data/Surjcollation.agda", "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "archive/agda-3/src/Oscar/Data/Surjcollation.agda", "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_forks_repo_path": "archive/agda-3/src/Oscar/Data/Surjcollation.agda", "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0789473684, "max_line_length": 100, "alphanum_fraction": 0.5253045923, "num_tokens": 1518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.3741684618396269}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Pointwise lifting of relations to lists\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.List.Relation.Binary.Pointwise where\n\nopen import Function.Base\nopen import Function.Inverse using (Inverse)\nopen import Data.Bool.Base using (true; false)\nopen import Data.Product hiding (map)\nopen import Data.List.Base as List hiding (map; head; tail; uncons)\nopen import Data.List.Properties using (≡-dec; length-++)\nopen import Data.List.Relation.Unary.All as All using (All; []; _∷_)\nopen import Data.List.Relation.Unary.AllPairs using (AllPairs; []; _∷_)\nopen import Data.List.Relation.Unary.Any using (Any; here; there)\nopen import Data.Fin.Base using (Fin) renaming (zero to fzero; suc to fsuc)\nopen import Data.Nat.Base using (ℕ; zero; suc)\nopen import Data.Nat.Properties\nopen import Level\nopen import Relation.Nullary hiding (Irrelevant)\nopen import Relation.Nullary.Negation using (contradiction)\nimport Relation.Nullary.Decidable as Dec using (map′)\nopen import Relation.Nullary.Product using (_×-dec_)\nopen import Relation.Unary as U using (Pred)\nopen import Relation.Binary renaming (Rel to Rel₂)\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\n\nprivate\n variable\n a b c d p q r ℓ ℓ₁ ℓ₂ ℓ₃ : Level\n A : Set a\n B : Set b\n C : Set c\n D : Set d\n\n------------------------------------------------------------------------\n-- Definition\n\ninfixr 5 _∷_\n\ndata Pointwise {A : Set a} {B : Set b} (_∼_ : REL A B ℓ)\n : List A → List B → Set (a ⊔ b ⊔ ℓ) where\n [] : Pointwise _∼_ [] []\n _∷_ : ∀ {x xs y ys} (x∼y : x ∼ y) (xs∼ys : Pointwise _∼_ xs ys) →\n Pointwise _∼_ (x ∷ xs) (y ∷ ys)\n\n------------------------------------------------------------------------\n-- Operations\n\nmodule _ {_∼_ : REL A B ℓ} where\n\n head : ∀ {x y xs ys} → Pointwise _∼_ (x ∷ xs) (y ∷ ys) → x ∼ y\n head (x∼y ∷ xs∼ys) = x∼y\n\n tail : ∀ {x y xs ys} → Pointwise _∼_ (x ∷ xs) (y ∷ ys) →\n Pointwise _∼_ xs ys\n tail (x∼y ∷ xs∼ys) = xs∼ys\n\n uncons : ∀ {x y xs ys} → Pointwise _∼_ (x ∷ xs) (y ∷ ys) →\n x ∼ y × Pointwise _∼_ xs ys\n uncons = < head , tail >\n\n rec : ∀ (P : ∀ {xs ys} → Pointwise _∼_ xs ys → Set c) →\n (∀ {x y xs ys} {xs∼ys : Pointwise _∼_ xs ys} →\n (x∼y : x ∼ y) → P xs∼ys → P (x∼y ∷ xs∼ys)) →\n P [] →\n ∀ {xs ys} (xs∼ys : Pointwise _∼_ xs ys) → P xs∼ys\n rec P c n [] = n\n rec P c n (x∼y ∷ xs∼ys) = c x∼y (rec P c n xs∼ys)\n\n map : ∀ {_≈_ : REL A B ℓ₂} → _≈_ ⇒ _∼_ → Pointwise _≈_ ⇒ Pointwise _∼_\n map ≈⇒∼ [] = []\n map ≈⇒∼ (x≈y ∷ xs≈ys) = ≈⇒∼ x≈y ∷ map ≈⇒∼ xs≈ys\n\n------------------------------------------------------------------------\n-- Relational properties\n\nreflexive : ∀ {_≈_ : REL A B ℓ₁} {_∼_ : REL A B ℓ₂} →\n _≈_ ⇒ _∼_ → Pointwise _≈_ ⇒ Pointwise _∼_\nreflexive ≈⇒∼ [] = []\nreflexive ≈⇒∼ (x≈y ∷ xs≈ys) = ≈⇒∼ x≈y ∷ reflexive ≈⇒∼ xs≈ys\n\nrefl : ∀ {_∼_ : Rel₂ A ℓ} → Reflexive _∼_ → Reflexive (Pointwise _∼_)\nrefl rfl {[]} = []\nrefl rfl {x ∷ xs} = rfl ∷ refl rfl\n\nsymmetric : ∀ {_≈_ : REL A B ℓ₁} {_∼_ : REL B A ℓ₂} →\n Sym _≈_ _∼_ → Sym (Pointwise _≈_) (Pointwise _∼_)\nsymmetric sym [] = []\nsymmetric sym (x∼y ∷ xs∼ys) = sym x∼y ∷ symmetric sym xs∼ys\n\ntransitive : ∀ {_≋_ : REL A B ℓ₁} {_≈_ : REL B C ℓ₂} {_∼_ : REL A C ℓ₃} →\n Trans _≋_ _≈_ _∼_ →\n Trans (Pointwise _≋_) (Pointwise _≈_) (Pointwise _∼_)\ntransitive trans [] [] = []\ntransitive trans (x∼y ∷ xs∼ys) (y∼z ∷ ys∼zs) =\n trans x∼y y∼z ∷ transitive trans xs∼ys ys∼zs\n\nantisymmetric : ∀ {_≤_ : REL A B ℓ₁} {_≤′_ : REL B A ℓ₂} {_≈_ : REL A B ℓ₃} →\n Antisym _≤_ _≤′_ _≈_ →\n Antisym (Pointwise _≤_) (Pointwise _≤′_) (Pointwise _≈_)\nantisymmetric antisym [] [] = []\nantisymmetric antisym (x∼y ∷ xs∼ys) (y∼x ∷ ys∼xs) =\n antisym x∼y y∼x ∷ antisymmetric antisym xs∼ys ys∼xs\n\nrespects₂ : ∀ {_≈_ : Rel₂ A ℓ₁} {_∼_ : Rel₂ A ℓ₂} →\n _∼_ Respects₂ _≈_ → (Pointwise _∼_) Respects₂ (Pointwise _≈_)\nrespects₂ {_≈_ = _≈_} {_∼_} resp = respʳ , respˡ\n where\n respʳ : (Pointwise _∼_) Respectsʳ (Pointwise _≈_)\n respʳ [] [] = []\n respʳ (x≈y ∷ xs≈ys) (z∼x ∷ zs∼xs) =\n proj₁ resp x≈y z∼x ∷ respʳ xs≈ys zs∼xs\n\n respˡ : (Pointwise _∼_) Respectsˡ (Pointwise _≈_)\n respˡ [] [] = []\n respˡ (x≈y ∷ xs≈ys) (x∼z ∷ xs∼zs) =\n proj₂ resp x≈y x∼z ∷ respˡ xs≈ys xs∼zs\n\nmodule _ {_∼_ : REL A B ℓ} (dec : Decidable _∼_) where\n\n decidable : Decidable (Pointwise _∼_)\n decidable [] [] = yes []\n decidable [] (y ∷ ys) = no (λ ())\n decidable (x ∷ xs) [] = no (λ ())\n decidable (x ∷ xs) (y ∷ ys) =\n Dec.map′ (uncurry _∷_) uncons (dec x y ×-dec decidable xs ys)\n\nmodule _ {_≈_ : Rel₂ A ℓ} where\n\n isEquivalence : IsEquivalence _≈_ → IsEquivalence (Pointwise _≈_)\n isEquivalence eq = record\n { refl = refl Eq.refl\n ; sym = symmetric Eq.sym\n ; trans = transitive Eq.trans\n } where module Eq = IsEquivalence eq\n\n isDecEquivalence : IsDecEquivalence _≈_ → IsDecEquivalence (Pointwise _≈_)\n isDecEquivalence eq = record\n { isEquivalence = isEquivalence DE.isEquivalence\n ; _≟_ = decidable DE._≟_\n } where module DE = IsDecEquivalence eq\n\nmodule _ {_≈_ : Rel₂ A ℓ₁} {_∼_ : Rel₂ A ℓ₂} where\n\n isPreorder : IsPreorder _≈_ _∼_ → IsPreorder (Pointwise _≈_) (Pointwise _∼_)\n isPreorder pre = record\n { isEquivalence = isEquivalence Pre.isEquivalence\n ; reflexive = reflexive Pre.reflexive\n ; trans = transitive Pre.trans\n } where module Pre = IsPreorder pre\n\n isPartialOrder : IsPartialOrder _≈_ _∼_ →\n IsPartialOrder (Pointwise _≈_) (Pointwise _∼_)\n isPartialOrder po = record\n { isPreorder = isPreorder PO.isPreorder\n ; antisym = antisymmetric PO.antisym\n } where module PO = IsPartialOrder po\n\nsetoid : Setoid a ℓ → Setoid a (a ⊔ ℓ)\nsetoid s = record\n { isEquivalence = isEquivalence (Setoid.isEquivalence s)\n }\n\ndecSetoid : DecSetoid a ℓ → DecSetoid a (a ⊔ ℓ)\ndecSetoid d = record\n { isDecEquivalence = isDecEquivalence (DecSetoid.isDecEquivalence d)\n }\n\npreorder : Preorder a ℓ₁ ℓ₂ → Preorder _ _ _\npreorder p = record\n { isPreorder = isPreorder (Preorder.isPreorder p)\n }\n\nposet : Poset a ℓ₁ ℓ₂ → Poset _ _ _\nposet p = record\n { isPartialOrder = isPartialOrder (Poset.isPartialOrder p)\n }\n\n------------------------------------------------------------------------\n-- Relationships to other predicates\n\nmodule _ {_∼_ : Rel₂ A ℓ} {P : Pred A p} where\n\n All-resp-Pointwise : P Respects _∼_ → (All P) Respects (Pointwise _∼_)\n All-resp-Pointwise resp [] [] = []\n All-resp-Pointwise resp (x∼y ∷ xs) (px ∷ pxs) =\n resp x∼y px ∷ All-resp-Pointwise resp xs pxs\n\n Any-resp-Pointwise : P Respects _∼_ → (Any P) Respects (Pointwise _∼_)\n Any-resp-Pointwise resp (x∼y ∷ xs) (here px) = here (resp x∼y px)\n Any-resp-Pointwise resp (x∼y ∷ xs) (there pxs) = there (Any-resp-Pointwise resp xs pxs)\n\nmodule _ {_∼_ : Rel₂ A ℓ} {R : Rel₂ A r} where\n\n AllPairs-resp-Pointwise : R Respects₂ _∼_ → (AllPairs R) Respects (Pointwise _∼_)\n AllPairs-resp-Pointwise _ [] [] = []\n AllPairs-resp-Pointwise resp@(respₗ , respᵣ) (x∼y ∷ xs) (px ∷ pxs) =\n All-resp-Pointwise respₗ xs (All.map (respᵣ x∼y) px) ∷ (AllPairs-resp-Pointwise resp xs pxs)\n\n------------------------------------------------------------------------\n-- length\n\nmodule _ {_∼_ : REL A B ℓ} where\n\n Pointwise-length : ∀ {xs ys} → Pointwise _∼_ xs ys →\n length xs ≡ length ys\n Pointwise-length [] = P.refl\n Pointwise-length (x∼y ∷ xs∼ys) = P.cong ℕ.suc (Pointwise-length xs∼ys)\n\n------------------------------------------------------------------------\n-- tabulate\n\nmodule _ {_∼_ : REL A B ℓ} where\n\n tabulate⁺ : ∀ {n} {f : Fin n → A} {g : Fin n → B} →\n (∀ i → f i ∼ g i) → Pointwise _∼_ (tabulate f) (tabulate g)\n tabulate⁺ {zero} f∼g = []\n tabulate⁺ {suc n} f∼g = f∼g fzero ∷ tabulate⁺ (f∼g ∘ fsuc)\n\n tabulate⁻ : ∀ {n} {f : Fin n → A} {g : Fin n → B} →\n Pointwise _∼_ (tabulate f) (tabulate g) → (∀ i → f i ∼ g i)\n tabulate⁻ {suc n} (x∼y ∷ xs∼ys) fzero = x∼y\n tabulate⁻ {suc n} (x∼y ∷ xs∼ys) (fsuc i) = tabulate⁻ xs∼ys i\n\n------------------------------------------------------------------------\n-- _++_\n\nmodule _ {_∼_ : REL A B ℓ} where\n\n ++⁺ : ∀ {ws xs ys zs} → Pointwise _∼_ ws xs → Pointwise _∼_ ys zs →\n Pointwise _∼_ (ws ++ ys) (xs ++ zs)\n ++⁺ [] ys∼zs = ys∼zs\n ++⁺ (w∼x ∷ ws∼xs) ys∼zs = w∼x ∷ ++⁺ ws∼xs ys∼zs\n\nmodule _ {_∼_ : Rel₂ A ℓ} where\n\n ++-cancelˡ : ∀ xs {ys zs : List A} → Pointwise _∼_ (xs ++ ys) (xs ++ zs) → Pointwise _∼_ ys zs\n ++-cancelˡ [] ys∼zs = ys∼zs\n ++-cancelˡ (x ∷ xs) (_ ∷ xs++ys∼xs++zs) = ++-cancelˡ xs xs++ys∼xs++zs\n\n ++-cancelʳ : ∀ {xs : List A} ys zs → Pointwise _∼_ (ys ++ xs) (zs ++ xs) → Pointwise _∼_ ys zs\n ++-cancelʳ [] [] _ = []\n ++-cancelʳ (y ∷ ys) (z ∷ zs) (y∼z ∷ ys∼zs) = y∼z ∷ (++-cancelʳ ys zs ys∼zs)\n -- Impossible cases\n ++-cancelʳ {xs} [] (z ∷ zs) eq =\n contradiction (P.trans (Pointwise-length eq) (length-++ (z ∷ zs))) (m≢1+n+m (length xs))\n ++-cancelʳ {xs} (y ∷ ys) [] eq =\n contradiction (P.trans (P.sym (length-++ (y ∷ ys))) (Pointwise-length eq)) (m≢1+n+m (length xs) ∘ P.sym)\n\n------------------------------------------------------------------------\n-- concat\n\nmodule _ {_∼_ : REL A B ℓ} where\n\n concat⁺ : ∀ {xss yss} → Pointwise (Pointwise _∼_) xss yss →\n Pointwise _∼_ (concat xss) (concat yss)\n concat⁺ [] = []\n concat⁺ (xs∼ys ∷ xss∼yss) = ++⁺ xs∼ys (concat⁺ xss∼yss)\n\n------------------------------------------------------------------------\n-- reverse\n\nmodule _ {R : REL A B ℓ} where\n\n reverseAcc⁺ : ∀ {as bs as′ bs′} → Pointwise R as′ bs′ → Pointwise R as bs →\n Pointwise R (reverseAcc as′ as) (reverseAcc bs′ bs)\n reverseAcc⁺ rs′ [] = rs′\n reverseAcc⁺ rs′ (r ∷ rs) = reverseAcc⁺ (r ∷ rs′) rs\n\n ʳ++⁺ : ∀ {as bs as′ bs′} →\n Pointwise R as bs →\n Pointwise R as′ bs′ →\n Pointwise R (as ʳ++ as′) (bs ʳ++ bs′)\n ʳ++⁺ rs rs′ = reverseAcc⁺ rs′ rs\n\n reverse⁺ : ∀ {as bs} → Pointwise R as bs → Pointwise R (reverse as) (reverse bs)\n reverse⁺ = reverseAcc⁺ []\n\n------------------------------------------------------------------------\n-- map\n\nmodule _ {R : REL C D ℓ} where\n\n map⁺ : ∀ {as bs} (f : A → C) (g : B → D) →\n Pointwise (λ a b → R (f a) (g b)) as bs →\n Pointwise R (List.map f as) (List.map g bs)\n map⁺ f g [] = []\n map⁺ f g (r ∷ rs) = r ∷ map⁺ f g rs\n\n map⁻ : ∀ {as bs} (f : A → C) (g : B → D) →\n Pointwise R (List.map f as) (List.map g bs) →\n Pointwise (λ a b → R (f a) (g b)) as bs\n map⁻ {as = []} {[]} f g [] = []\n map⁻ {as = []} {b ∷ bs} f g rs = contradiction (Pointwise-length rs) λ()\n map⁻ {as = a ∷ as} {[]} f g rs = contradiction (Pointwise-length rs) λ()\n map⁻ {as = a ∷ as} {b ∷ bs} f g (r ∷ rs) = r ∷ map⁻ f g rs\n\n------------------------------------------------------------------------\n-- filter\n\nmodule _ {R : REL A B ℓ} {P : Pred A p} {Q : Pred B q}\n (P? : U.Decidable P) (Q? : U.Decidable Q)\n (P⇒Q : ∀ {a b} → R a b → P a → Q b)\n (Q⇒P : ∀ {a b} → R a b → Q b → P a)\n where\n\n filter⁺ : ∀ {as bs} → Pointwise R as bs → Pointwise R (filter P? as) (filter Q? bs)\n filter⁺ [] = []\n filter⁺ {a ∷ _} {b ∷ _} (r ∷ rs) with P? a | Q? b\n ... | true because _ | true because _ = r ∷ filter⁺ rs\n ... | false because _ | false because _ = filter⁺ rs\n ... | yes p | no ¬q = contradiction (P⇒Q r p) ¬q\n ... | no ¬p | yes q = contradiction (Q⇒P r q) ¬p\n\n------------------------------------------------------------------------\n-- replicate\n\nmodule _ {R : REL A B ℓ} where\n\n replicate⁺ : ∀ {a b} → R a b → ∀ n → Pointwise R (replicate n a) (replicate n b)\n replicate⁺ r 0 = []\n replicate⁺ r (suc n) = r ∷ replicate⁺ r n\n\n------------------------------------------------------------------------\n-- Irrelevance\n\nmodule _ {R : REL A B ℓ} where\n\n irrelevant : Irrelevant R → Irrelevant (Pointwise R)\n irrelevant R-irr [] [] = P.refl\n irrelevant R-irr (r ∷ rs) (r₁ ∷ rs₁) =\n P.cong₂ _∷_ (R-irr r r₁) (irrelevant R-irr rs rs₁)\n\n------------------------------------------------------------------------\n-- Properties of propositional pointwise\n\nPointwise-≡⇒≡ : Pointwise {A = A} _≡_ ⇒ _≡_\nPointwise-≡⇒≡ [] = P.refl\nPointwise-≡⇒≡ (P.refl ∷ xs∼ys) with Pointwise-≡⇒≡ xs∼ys\n... | P.refl = P.refl\n\n≡⇒Pointwise-≡ : _≡_ ⇒ Pointwise {A = A} _≡_\n≡⇒Pointwise-≡ P.refl = refl P.refl\n\nPointwise-≡↔≡ : Inverse (setoid (P.setoid A)) (P.setoid (List A))\nPointwise-≡↔≡ = record\n { to = record { _⟨$⟩_ = id; cong = Pointwise-≡⇒≡ }\n ; from = record { _⟨$⟩_ = id; cong = ≡⇒Pointwise-≡ }\n ; inverse-of = record\n { left-inverse-of = λ _ → refl P.refl\n ; right-inverse-of = λ _ → P.refl\n }\n }\n\n------------------------------------------------------------------------\n-- DEPRECATED NAMES\n------------------------------------------------------------------------\n-- Please use the new names as continuing support for the old names is\n-- not guaranteed.\n\n-- Version 0.15\n\nRel = Pointwise\n{-# WARNING_ON_USAGE Rel\n\"Warning: Rel was deprecated in v0.15.\nPlease use Pointwise instead.\"\n#-}\nRel≡⇒≡ = Pointwise-≡⇒≡\n{-# WARNING_ON_USAGE Rel≡⇒≡\n\"Warning: Rel≡⇒≡ was deprecated in v0.15.\nPlease use Pointwise-≡⇒≡ instead.\"\n#-}\n≡⇒Rel≡ = ≡⇒Pointwise-≡\n{-# WARNING_ON_USAGE ≡⇒Rel≡\n\"Warning: ≡⇒Rel≡ was deprecated in v0.15.\nPlease use ≡⇒Pointwise-≡ instead.\"\n#-}\nRel↔≡ = Pointwise-≡↔≡\n{-# WARNING_ON_USAGE Rel↔≡\n\"Warning: Rel↔≡ was deprecated in v0.15.\nPlease use Pointwise-≡↔≡ instead.\"\n#-}\n\n-- Version 1.0\n\ndecidable-≡ = ≡-dec\n{-# WARNING_ON_USAGE decidable-≡\n\"Warning: decidable-≡ was deprecated in v1.0.\nPlease use ≡-dec from `Data.List.Properties` instead.\"\n#-}\n", "meta": {"hexsha": "b3df9abd0e9740bf9ad206166b10e99214655fed", "size": 14187, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Pointwise.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Pointwise.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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-stdlib/src/Data/List/Relation/Binary/Pointwise.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 35.8257575758, "max_line_length": 108, "alphanum_fraction": 0.5120180447, "num_tokens": 5292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.6477982179521103, "lm_q1q2_score": 0.37410046844297207}} {"text": "\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Reflection\nopen import Agda.Builtin.Unit\nopen import Agda.Builtin.Nat\n\n-- setup\n\ninfixl 5 _>>=_\n_>>=_ = bindTC\n\ndefToTerm : Name → Definition → List (Arg Term) → Term\ndefToTerm _ (function cs) as = pat-lam cs as\ndefToTerm _ (data-cons d) as = con d as\ndefToTerm _ _ _ = unknown\n\nderefImmediate : Term → TC Term\nderefImmediate (def f args) = getDefinition f >>= λ f' → returnTC (defToTerm f f' args)\nderefImmediate x = returnTC x\n\nmacro\n reflect : ∀ {ℓ} {t : Set ℓ} → t → Term → TC ⊤\n reflect x a = quoteTC x >>= derefImmediate >>= quoteTC >>= unify a\n\n unfold : Name → Term → TC ⊤\n unfold x a = getDefinition x >>= λ d → unify a (defToTerm x d [])\n\n-- crash\n\ndata Vec (A : Set) : Nat → Set where\n [] : Vec A zero\n _∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)\n\nvid vid' : ∀ n → Vec Nat n → Vec Nat n\nvid n [] = []\nvid n (x ∷ xs) = x ∷ xs\n\nvid' = unfold vid\n\ncrash : Term\ncrash = reflect vid\n\nlen : ∀ {n} → Vec Nat n → Nat\nlen [] = 0\nlen (x ∷ xs) = suc (len xs)\n\n-- Forces different order in clause tel and patterns\nf f' : ∀ n → Vec Nat n → Vec Nat n → Nat\nf n xs [] = n\nf n xs (y ∷ ys) = n + y + len xs + len ys\n\nf' = unfold f\n", "meta": {"hexsha": "9cf0dae638c83c165bbf1685511e7fe28520dccc", "size": 1185, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue2165.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue2165.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue2165.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 22.358490566, "max_line_length": 87, "alphanum_fraction": 0.6135021097, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5774953506426082, "lm_q2_score": 0.6477982043529715, "lm_q1q2_score": 0.37410045116847124}} {"text": "module Ambient where\n\nopen import Relation.Nullary\n using (yes; no)\n\nopen import Data.String\n using (String; _≟_)\n\nopen import Data.Bool\n using (Bool; true; false)\n\nopen import Relation.Binary.PropositionalEquality\n using (_≢_; refl)\n renaming (_≡_ to _≡≡_)\n\nopen import Data.List\n using (List; []; _∷_; _++_; filter)\n\n-- Local modules ---------------------------------------------------------------\n\nopen import Common\n using (Id)\n\nopen import Capability\n using (Capability; `_; In; Out; Open; ε; _∙_)\n renaming (_[_/_] to _[_/_]-capa; freeVar to freeVar-capa)\n\n-- Process Definition ----------------------------------------------------------\n\ninfix 40 _[_/_]\ninfixr 30 Λ_∙_\ninfix 20 _[_]\ninfixr 10 _||_\n\ndata Process : Set where\n ν_∙_ : Id → Process → Process -- Restriction\n Zero : Process -- Inactivity\n _||_ : Process → Process → Process -- Composition\n !_ : Process → Process -- Replication\n _[_] : Capability → Process → Process -- Ambient\n _∙_ : Capability → Process → Process -- Action\n Λ_∙_ : Id → Process → Process -- Input Action\n <_> : Capability → Process -- Message\n\n-- Free variable ---------------------------------------------------------------\n\n_-_ : List Id → Id → List Id\n[] - _ = []\n(x ∷ xs) - y with x ≟ y\n... | yes _ = xs - y\n... | no _ = x ∷ (xs - y)\n\nfreeVar : Process → List Id\nfreeVar (ν x ∙ P) = freeVar P\nfreeVar Zero = []\nfreeVar (P || Q) = (freeVar P) ++ (freeVar Q)\nfreeVar (! P) = freeVar P\nfreeVar (M [ P ]) = (freeVar-capa M) ++ (freeVar P)\nfreeVar (M ∙ P) = (freeVar-capa M) ++ (freeVar P)\nfreeVar (Λ x ∙ P) = (freeVar P) - x\nfreeVar (< M >) = freeVar-capa M\n\n_∉_ : Id → List Id → Set\ny ∉ l = member y l ≡≡ false\n where member : Id → List Id → Bool -- Should propably use the List filter instead!\n member y [] = false\n member y (x ∷ xs) with x ≟ y\n ... | yes _ = true\n ... | no _ = member y xs\n\n-- Process substitution --------------------------------------------------------\n\n_[_/_] : Process → Id → Capability → Process\n\nZero [ _ / _ ] = Zero\n(P || Q) [ x / M ] = P [ x / M ] || Q [ x / M ]\n(! P) [ x / M ] = ! (P [ x / M ])\n(x [ P ]) [ y / M ] = (x [ y / M ]-capa) [ P [ y / M ] ]\n(ν x ∙ P) [ y / M ] with x ≟ y\n... | yes _ = ν x ∙ P\n... | no _ = ν x ∙ (P [ y / M ])\n< N > [ x / M ] = < N [ x / M ]-capa >\n(Λ x ∙ P) [ y / M ] with x ≟ y\n... | yes _ = Λ x ∙ P\n... | no _ = Λ x ∙ (P [ y / M ])\n( N ∙ P) [ x / M ] = (N [ x / M ]-capa) ∙ (P [ x / M ])\n\nmodule Test where\n a = \"a\"\n b = \"b\"\n\n ------------------------------------------------------------------------------\n\n _ : (` a [ < ` b > ]) [ b / Open a ] ≡≡ ` a [ < Open a > ]\n _ = refl\n\n _ : (< ` a > || < ` b >) [ b / Open a ] ≡≡ < ` a > || < Open a >\n _ = refl\n\n-- Congruence ------------------------------------------------------------------\n\ninfix 5 _≡_\n\ndata _≡_ : Process → Process → Set where\n Struct-Refl : ∀ {P}\n -----\n → P ≡ P\n\n Struct-Symm : ∀ {P Q}\n → P ≡ Q\n -----\n → Q ≡ P\n\n Struct-Trans : ∀ {P Q R}\n → P ≡ Q → Q ≡ R\n -------------\n → P ≡ R\n\n Struct-Res : ∀ {n P Q}\n → P ≡ Q\n -----------------\n → ν n ∙ P ≡ ν n ∙ Q\n\n Struct-Par : ∀ {P Q R}\n → P ≡ Q\n ---------------\n → P || R ≡ Q || R\n\n Struct-Repl : ∀ {P Q}\n → P ≡ Q\n ---------\n → ! P ≡ ! Q\n\n Struct-Amb : ∀ {M P Q}\n → P ≡ Q\n -----------------\n → M [ P ] ≡ M [ Q ]\n\n Struct-Action : ∀ {M P Q}\n → P ≡ Q\n -------------\n → M ∙ P ≡ M ∙ Q\n\n Struct-Input : ∀ {x P Q}\n → P ≡ Q\n ---------------------\n → Λ x ∙ P ≡ Λ x ∙ Q\n\n Struct-Comm : ∀ {P Q}\n → P ≡ Q\n -----\n → Q ≡ P\n\n Struct-Assoc : ∀ {P Q R}\n -----------------------------\n → (P || Q) || R ≡ P || (Q || R)\n\n Struct-ResRes : ∀ {n m P}\n → n ≢ m\n -----------------------------\n → ν n ∙ ν m ∙ P ≡ ν m ∙ ν n ∙ P\n\n Struct-ResPar : ∀ {n P Q}\n → n ∉ freeVar(P)\n -----------------------------\n → ν n ∙ (P || Q) ≡ P || ν n ∙ Q\n\n Struct-ResAmb : ∀ {n m P}\n → n ≢ m\n -----------------------------------\n → ν n ∙ (` m [ P ]) ≡ ` m [ ν n ∙ P ]\n\n Struct-ZeroPar : ∀ {P}\n -------------\n → P || Zero ≡ P\n\n Struct-ZeroRes : ∀ {n}\n -----------------\n → ν n ∙ Zero ≡ Zero\n\n Struct-ZeroRep : ! Zero ≡ Zero\n\n Struct-ε : ---------------\n ε ∙ Zero ≡ Zero\n\n Struct-∙ : ∀ {M M' P}\n ---------------------------\n → (M ∙ M') ∙ P ≡ M ∙ (M' ∙ P)\n\n-- Reduction rules -------------------------------------------------------------\n\ninfix 5 _~>_\n\ndata _~>_ : Process → Process → Set where\n Red-In : ∀ {m n P Q R}\n -----------------------------------------------------------------\n → ` m [ In n ∙ P || Q ] || ` n [ R ] ~> ` n [ ` m [ P || Q ] || R ]\n\n Red-Out : ∀ {m n P Q R}\n ------------------------------------------------------------------\n → ` m [ ` n [ Out m ∙ P || R ] || Q ] ~> ` m [ Q ] || ` n [ P || R ]\n\n Red-Open : ∀ {m P Q}\n ---------------------------------\n → ` m [ P ] || Open m ∙ Q ~> P || Q\n\n Red-I/O : ∀ {M x P}\n ---------------------------------\n → < M > || Λ x ∙ P ~> P [ x / M ]\n\n Red-Par : ∀ {P Q R}\n → P ~> Q\n ------------------\n → P || R ~> Q || R\n\n Red-Res : ∀ {n P Q}\n → P ~> Q\n --------------------\n → ν n ∙ P ~> ν n ∙ Q\n\n Red-Amb : ∀ {M P Q}\n → P ~> Q\n --------------------\n → M [ P ] ~> M [ Q ]\n\n Red-≡ : ∀ {P P' Q Q'}\n → P' ≡ P → P ~> Q → Q ≡ Q'\n -------------------------\n → P' ~> Q'\n\n--------------------------------------------------------------------------------\n", "meta": {"hexsha": "3401ef5d5334a83bd2f34862e3383abe1a2ebdbc", "size": 6605, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Ambient.agda", "max_stars_repo_name": "d-plaindoux/colca", "max_stars_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-12T18:31:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-04T09:35:36.000Z", "max_issues_repo_path": "src/Ambient.agda", "max_issues_repo_name": "d-plaindoux/colca", "max_issues_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81", "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/Ambient.agda", "max_forks_repo_name": "d-plaindoux/colca", "max_forks_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81", "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": 28.4698275862, "max_line_length": 87, "alphanum_fraction": 0.2844814534, "num_tokens": 1904, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.3740948136963992}} {"text": "-- Andreas, 2015-06-29 polarity handling is broken\n-- See also issue 1592\n\n-- {-# OPTIONS -v tc.polarity:20 -v tc.proj.like:100 #-}\n-- {-# OPTIONS -v tc.conv.elim:25 --show-implicit #-}\n\nopen import Common.Size\nopen import Common.Prelude\n\ndata D : Size → Set where\n c : ∀ i → D (↑ i)\n\nrecord Type (a : Bool) : Set1 where\n constructor mkType\n field type : Set\nopen Type\n\nOpp : Set → Set\nOpp X = X → ⊥\n\n-- projection-like contravariant function which does not unfold\nabstract\n Contra : ∀ a (T : Type a) → Set\n Contra a (mkType A) = Opp A\n\n-- Subtyping is broken for projection(-like) things.\n-- This is exploitable as Contra true (mkType X) does not reduce to Opp X here.\ncast : ∀{i} → Contra true (mkType (D i)) → Contra true (mkType (D (↑ i)))\ncast x = x\n\n-- Here it, does reduce.\nabstract\n loop : ∀{i} → D i → ⊥\n loop (c i) = cast loop (c i)\n\nabsurd : ⊥\nabsurd = loop (c ∞)\n", "meta": {"hexsha": "2642b9665f932a7686dd448e2a422ce29c17ca7c", "size": 884, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/PolarityProjectionLike.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_issues_repo_path": "test/Fail/PolarityProjectionLike.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_forks_repo_path": "test/Fail/PolarityProjectionLike.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z", "max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z", "avg_line_length": 23.2631578947, "max_line_length": 81, "alphanum_fraction": 0.6391402715, "num_tokens": 293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.3740948136963992}} {"text": "------------------------------------------------------------------------\n-- Laws related to return⋆\n------------------------------------------------------------------------\n\nmodule TotalParserCombinators.Laws.ReturnStar where\n\nopen import Algebra\nopen import Category.Monad\nopen import Codata.Musical.Notation\nopen import Data.List\nimport Data.List.Categorical\nopen import Data.List.Relation.Binary.BagAndSetEquality as Eq\n using (bag) renaming (_∼[_]_ to _List-∼[_]_)\nopen import Function\nopen import Level\n\nprivate\n module BagMonoid {A : Set} =\n CommutativeMonoid (Eq.commutativeMonoid bag A)\n open module ListMonad =\n RawMonad {f = zero} Data.List.Categorical.monad\n using () renaming (_⊛_ to _⊛′_; _>>=_ to _>>=′_)\n\nopen import TotalParserCombinators.Derivative using (D)\nopen import TotalParserCombinators.Congruence\n hiding (fail)\nimport TotalParserCombinators.Laws.AdditiveMonoid as AdditiveMonoid\nopen import TotalParserCombinators.Laws.Derivative\nopen import TotalParserCombinators.Lib\nopen import TotalParserCombinators.Parser\n\n-- return⋆ preserves equality.\n\ncong : ∀ {k Tok R} {xs₁ xs₂ : List R} →\n xs₁ List-∼[ k ] xs₂ → return⋆ {Tok = Tok} xs₁ ∼[ k ]P return⋆ xs₂\ncong {xs₁ = xs₁} {xs₂} xs₁≈xs₂ = xs₁≈xs₂ ∷ λ t → ♯ (\n D t (return⋆ xs₁) ≅⟨ D-return⋆ xs₁ ⟩\n fail ≅⟨ sym $ D-return⋆ xs₂ ⟩\n D t (return⋆ xs₂) ∎)\n\n-- return⋆ is homomorphic with respect to _++_/_∣_.\n\ndistrib-∣ :\n ∀ {Tok R} (xs₁ xs₂ : List R) →\n return⋆ {Tok = Tok} (xs₁ ++ xs₂) ≅P return⋆ xs₁ ∣ return⋆ xs₂\ndistrib-∣ xs₁ xs₂ =\n BagMonoid.refl ∷ λ t → ♯ (\n D t (return⋆ (xs₁ ++ xs₂)) ≅⟨ D-return⋆ (xs₁ ++ xs₂) ⟩\n fail ≅⟨ sym $ AdditiveMonoid.left-identity fail ⟩\n fail ∣ fail ≅⟨ sym $ D-return⋆ xs₁ ∣ D-return⋆ xs₂ ⟩\n D t (return⋆ xs₁) ∣ D t (return⋆ xs₂) ∎)\n\n-- return⋆ is homomorphic with respect to _⊛′_/_⊛_.\n\ndistrib-⊛ :\n ∀ {Tok R₁ R₂} (fs : List (R₁ → R₂)) xs →\n return⋆ {Tok = Tok} (fs ⊛′ xs) ≅P return⋆ fs ⊛ return⋆ xs\ndistrib-⊛ fs xs =\n BagMonoid.refl ∷ λ t → ♯ (\n D t (return⋆ (fs ⊛′ xs)) ≅⟨ D-return⋆ (fs ⊛′ xs) ⟩\n\n fail ≅⟨ sym $ AdditiveMonoid.left-identity fail ⟩\n\n fail ∣ fail ≅⟨ sym $ left-zero-⊛ (return⋆ xs) ∣\n right-zero-⊛ (return⋆ fs) ⟩\n fail ⊛ return⋆ xs ∣\n return⋆ fs ⊛ fail ≅⟨ sym $ [ ○ - ○ - ○ - ○ ] D-return⋆ fs ⊛ (return⋆ xs ∎) ∣\n [ ○ - ○ - ○ - ○ ] return⋆ fs ∎ ⊛ D-return⋆ xs ⟩\n D t (return⋆ fs) ⊛ return⋆ xs ∣\n return⋆ fs ⊛ D t (return⋆ xs) ≅⟨ sym $ D-⊛ (return⋆ fs) (return⋆ xs) ⟩\n\n D t (return⋆ fs ⊛ return⋆ xs) ∎)\n\n-- return⋆ is homomorphic with respect to _>>=′_/_>>=_.\n\ndistrib->>= :\n ∀ {Tok R₁ R₂} xs (f : R₁ → List R₂) →\n return⋆ {Tok = Tok} (xs >>=′ f) ≅P return⋆ xs >>= (return⋆ ∘ f)\ndistrib->>= xs f =\n BagMonoid.refl ∷ λ t → ♯ (\n D t (return⋆ (xs >>=′ f)) ≅⟨ D-return⋆ (xs >>=′ f) ⟩\n\n fail ≅⟨ sym $ AdditiveMonoid.left-identity fail ⟩\n\n fail ∣ fail ≅⟨ sym $ left-zero->>= (return⋆ ∘ f) ∣\n right-zero->>= (return⋆ xs) ⟩\n fail >>= (return⋆ ∘ f) ∣\n return⋆ xs >>= (λ _ → fail) ≅⟨ sym $ [ ○ - ○ - ○ - ○ ] D-return⋆ xs >>= (λ x → return⋆ (f x) ∎) ∣\n [ ○ - ○ - ○ - ○ ] return⋆ xs ∎ >>= (λ x → D-return⋆ (f x)) ⟩\n D t (return⋆ xs) >>= (return⋆ ∘ f) ∣\n return⋆ xs >>= (λ x → D t (return⋆ (f x))) ≅⟨ sym $ D->>= (return⋆ xs) (return⋆ ∘ f) ⟩\n\n D t (return⋆ xs >>= (return⋆ ∘ f)) ∎)\n", "meta": {"hexsha": "22b17a03b41880725c723b0795dfa7c90256bcd0", "size": 3760, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "TotalParserCombinators/Laws/ReturnStar.agda", "max_stars_repo_name": "nad/parser-combinators", "max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z", "max_issues_repo_path": "TotalParserCombinators/Laws/ReturnStar.agda", "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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": "TotalParserCombinators/Laws/ReturnStar.agda", "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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.0, "max_line_length": 117, "alphanum_fraction": 0.4880319149, "num_tokens": 1424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6791786861878392, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.37396078712957187}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import lib.Basics\nopen import lib.types.Paths\nopen import lib.types.Sigma\nopen import lib.types.Span\nopen import lib.types.Pointed\nopen import lib.types.Pushout\n\nmodule lib.types.Join where\n\nmodule _ {i j} (A : Type i) (B : Type j) where\n\n *-span : Span\n *-span = span A B (A × B) fst snd\n\n infix 80 _*_\n\n _*_ : Type _\n _*_ = Pushout *-span\n\nmodule JoinElim {i j} {A : Type i} {B : Type j} {k} {P : A * B → Type k}\n (left* : (a : A) → P (left a)) (right* : (b : B) → P (right b))\n (glue* : (ab : A × B) → left* (fst ab) == right* (snd ab) [ P ↓ glue ab ])\n = PushoutElim left* right* glue*\nopen JoinElim public using () renaming (f to Join-elim)\n\nmodule JoinRec {i j} {A : Type i} {B : Type j} {k} {D : Type k}\n (left* : (a : A) → D) (right* : (b : B) → D)\n (glue* : (ab : A × B) → left* (fst ab) == right* (snd ab))\n = PushoutRec left* right* glue*\nopen JoinRec public using () renaming (f to Join-rec)\n\nmodule _ {i j} (X : Ptd i) (Y : Ptd j) where\n\n *-⊙span : ⊙Span\n *-⊙span = ⊙span X Y (X ⊙× Y) ⊙fst ⊙snd\n\n infix 80 _⊙*_\n\n _⊙*_ : Ptd _\n _⊙*_ = ⊙Pushout *-⊙span\n\nmodule _ {i i' j j'} {A : Type i} {A' : Type i'} {B : Type j} {B' : Type j'} where\n\n equiv-* : A ≃ A' → B ≃ B' → A * B ≃ A' * B'\n equiv-* eqA eqB = equiv to from to-from from-to where\n module To = JoinRec {D = A' * B'} (left ∘ –> eqA) (right ∘ –> eqB) (λ{(a , b) → glue (–> eqA a , –> eqB b)})\n module From = JoinRec {D = A * B} (left ∘ <– eqA) (right ∘ <– eqB) (λ{(a , b) → glue (<– eqA a , <– eqB b)})\n\n to : A * B → A' * B'\n to = To.f\n\n from : A' * B' → A * B\n from = From.f\n\n to-from : ∀ y → to (from y) == y\n to-from = Join-elim (ap left ∘ <–-inv-r eqA) (ap right ∘ <–-inv-r eqB) to-from-glue where\n to-from-glue : ∀ (ab : A' × B')\n → ap left (<–-inv-r eqA (fst ab)) == ap right (<–-inv-r eqB (snd ab)) [ (λ y → to (from y) == y) ↓ glue ab ]\n to-from-glue (a , b) = ↓-app=idf-in $\n ap left (<–-inv-r eqA a) ∙' glue (a , b)\n =⟨ htpy-natural'-app=cst (λ a → glue (a , b)) (<–-inv-r eqA a) ⟩\n glue (–> eqA (<– eqA a) , b)\n =⟨ ! $ htpy-natural-cst=app (λ b → glue (–> eqA (<– eqA a) , b)) (<–-inv-r eqB b) ⟩\n glue (–> eqA (<– eqA a) , –> eqB (<– eqB b)) ∙ ap right (<–-inv-r eqB b)\n =⟨ ! $ To.glue-β (<– eqA a , <– eqB b) |in-ctx (_∙ ap right (<–-inv-r eqB b)) ⟩\n ap to (glue (<– eqA a , <– eqB b)) ∙ ap right (<–-inv-r eqB b)\n =⟨ ! $ From.glue-β (a , b) |in-ctx (λ p → ap to p ∙ ap right (<–-inv-r eqB b)) ⟩\n ap to (ap from (glue (a , b))) ∙ ap right (<–-inv-r eqB b)\n =⟨ ! $ ap-∘ to from (glue (a , b)) |in-ctx (_∙ ap right (<–-inv-r eqB b)) ⟩\n ap (to ∘ from) (glue (a , b)) ∙ ap right (<–-inv-r eqB b)\n ∎\n\n from-to : ∀ x → from (to x) == x\n from-to = Join-elim (ap left ∘ <–-inv-l eqA) (ap right ∘ <–-inv-l eqB) from-to-glue where\n from-to-glue : ∀ (ab : A × B)\n → ap left (<–-inv-l eqA (fst ab)) == ap right (<–-inv-l eqB (snd ab)) [ (λ x → from (to x) == x) ↓ glue ab ]\n from-to-glue (a , b) = ↓-app=idf-in $\n ap left (<–-inv-l eqA a) ∙' glue (a , b)\n =⟨ htpy-natural'-app=cst (λ a → glue (a , b)) (<–-inv-l eqA a) ⟩\n glue (<– eqA (–> eqA a) , b)\n =⟨ ! $ htpy-natural-cst=app (λ b → glue (<– eqA (–> eqA a) , b)) (<–-inv-l eqB b) ⟩\n glue (<– eqA (–> eqA a) , <– eqB (–> eqB b)) ∙ ap right (<–-inv-l eqB b)\n =⟨ ! $ From.glue-β (–> eqA a , –> eqB b) |in-ctx (_∙ ap right (<–-inv-l eqB b)) ⟩\n ap from (glue (–> eqA a , –> eqB b)) ∙ ap right (<–-inv-l eqB b)\n =⟨ ! $ To.glue-β (a , b) |in-ctx (λ p → ap from p ∙ ap right (<–-inv-l eqB b)) ⟩\n ap from (ap to (glue (a , b))) ∙ ap right (<–-inv-l eqB b)\n =⟨ ! $ ap-∘ from to (glue (a , b)) |in-ctx (_∙ ap right (<–-inv-l eqB b)) ⟩\n ap (from ∘ to) (glue (a , b)) ∙ ap right (<–-inv-l eqB b)\n ∎\n\nmodule _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'} where\n\n ⊙equiv-⊙* : X ⊙≃ X' → Y ⊙≃ Y' → X ⊙* Y ⊙≃ X' ⊙* Y'\n ⊙equiv-⊙* ⊙eqX ⊙eqY = ⊙≃-in (equiv-* (fst (⊙≃-out ⊙eqX)) (fst (⊙≃-out ⊙eqY))) (ap left (snd (⊙≃-out ⊙eqX)))\n", "meta": {"hexsha": "74a919f2946c24106e8fee217b2d1574ff604d05", "size": 4160, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/types/Join.agda", "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "core/lib/types/Join.agda", "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "core/lib/types/Join.agda", "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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.8865979381, "max_line_length": 116, "alphanum_fraction": 0.4682692308, "num_tokens": 1840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6113819591324418, "lm_q2_score": 0.6113819732941511, "lm_q1q2_score": 0.3737879086108363}} {"text": "{-# OPTIONS --allow-unsolved-metas #-}\nmodule _ where\n\nopen import Agda.Builtin.Equality\n\nmodule Case₀ where\n\n postulate\n I : Set\n P : I → Set\n\n variable\n p : P _\n\n postulate\n D : P _ → Set\n d : D p\n\nmodule Case₁ where\n\n postulate\n I : Set\n P : I → Set\n Q : ∀ n → P n → Set\n\n variable\n q : Q _ _\n\n postulate\n D : ∀ {p} → Q _ p → Set\n d : D q\n\nmodule Case₂ where\n\n postulate\n I : Set\n P : I → Set\n Q : ∀ n → P n → Set\n\n record R n (p : P n) : Set where\n constructor c\n field\n f : Q _ p\n\n variable\n q : Q _ _\n\n data D {p} : R _ p → Set where\n d : D (c q)\n\nmodule Case₃ where\n\n variable\n A : Set\n a : A\n\n record B : Set where\n id = λ x → x ≡ x\n field\n b : id a\n", "meta": {"hexsha": "192c5246872183b9704ff61b8df89584db7b730c", "size": 746, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue3390.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/Succeed/Issue3390.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/Succeed/Issue3390.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": 12.2295081967, "max_line_length": 38, "alphanum_fraction": 0.5040214477, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.6076631698328916, "lm_q1q2_score": 0.3737662360086086}} {"text": "{-# OPTIONS --without-K --safe #-}\n\n-- This is a utility module.\nmodule Utils where\n\nopen import Induction.WellFounded as Wf\nopen import Data.List as List\nopen import Data.List.All\nopen import Data.Nat\nopen import Data.Maybe\nopen import Data.Product as ,\nopen import Data.Empty\nopen import Function\n\nopen import Relation.Nullary\nopen import Relation.Binary\nopen import Relation.Binary.PropositionalEquality\n\ninfix 6 _!\n_! : ∀ {a} {A : Set a} → A → List A\na ! = a ∷ []\n\ninfixl 5 _‣_\n_‣_ : ∀ {a} {A : Set a} → List A → List A → List A\nl₁ ‣ l₂ = l₂ ++ l₁\n\nlookupOpt : ∀ {a} {A : Set a} → List A → ℕ → Maybe A\nlookupOpt [] n = nothing\nlookupOpt (x ∷ l) zero = just x\nlookupOpt (x ∷ l) (suc n) = lookupOpt l n\n\nmodule _ {a} {A : Set a} where\n lookupOpt-map-inv : ∀ {b} {B : Set b} {f : A → B} l {n e} →\n lookupOpt (List.map f l) n ≡ just e →\n ∃[ e' ] (e ≡ f e' × lookupOpt l n ≡ just e')\n lookupOpt-map-inv [] {n} ()\n lookupOpt-map-inv (x ∷ l) {zero} refl = x , refl , refl\n lookupOpt-map-inv (x ∷ l) {suc n} eq = lookupOpt-map-inv l eq\n \n lookupOpt-map : ∀ {b} {B : Set b} l (f : A → B) {n e} →\n lookupOpt l n ≡ just e → \n lookupOpt (List.map f l) n ≡ just (f e)\n lookupOpt-map [] f ()\n lookupOpt-map (x ∷ l) f {zero} refl = refl\n lookupOpt-map (x ∷ l) f {suc n} eq = lookupOpt-map l f eq\n \n lookupOpt-All : ∀ {b} {P : A → Set b} {l n e} →\n lookupOpt l n ≡ just e →\n All P l →\n P e\n lookupOpt-All {n = n} () []\n lookupOpt-All {n = zero} refl (px ∷ all) = px\n lookupOpt-All {n = suc n} eq (px ∷ all) = lookupOpt-All eq all\n\n lookupOpt-app₁ : ∀ (l₁ l₂ : List A) {n} →\n n < length l₁ →\n lookupOpt (l₁ ++ l₂) n ≡ lookupOpt l₁ n\n lookupOpt-app₁ [] l₂ {n} ()\n lookupOpt-app₁ (x ∷ l₁) l₂ {zero} (s≤s nn : ¬ m ≤ n) → ∃ λ ¬p → (m ≤? n) ≡ no ¬p\n≤?-no {m} {n} m>n with m ≤? n\n... | yes p = ⊥-elim $ m>n p\n... | no _ = -, refl\n\nmodule Measure {a b ℓ} {A : Set a} {B : Set b} {_≺_ : Rel A ℓ}\n (≺-wf : WellFounded _≺_)\n (m : B → A) where\n\n open import Level using () renaming (zero to lzero)\n import Relation.Binary.Reasoning.Base.Triple as Triple\n open Wf.Inverse-image {_<_ = _≺_} m using (wellFounded)\n \n open Wf.All (wellFounded ≺-wf) lzero using (wfRec) public\n\nmodule LexicographicMeasure {a b c d ℓ₁ ℓ₂}\n {A : Set a} {B : A → Set b}\n {C : Set c} {D : C → Set d}\n {_≺A_ : Rel A ℓ₁}\n {[_]_≺B_ : ∀ x → Rel (B x) ℓ₂}\n (≺A-wf : WellFounded _≺A_)\n (≺B-wf : ∀ {x} → WellFounded ([ x ]_≺B_))\n (mC : C → A)\n (mD : ∀ {c} → D c → B (mC c)) where\n open import Level using () renaming (zero to lzero)\n module Lex = Wf.Lexicographic _≺A_ [_]_≺B_\n open Lex renaming (wellFounded to lex-wf ; _<_ to _≺′_)\n open Lex using (left ; right) public\n open Wf.Inverse-image renaming (wellFounded to m-wf)\n\n measure : Σ C D → Σ A B\n measure (c , d) = mC c , mD d\n\n ΣAB-wf : WellFounded _≺′_\n ΣAB-wf = lex-wf ≺A-wf ≺B-wf\n\n infix 3 _≺_\n _≺_ = _≺′_ on ,.map mC mD\n\n measure-wf : WellFounded _≺_\n measure-wf = m-wf measure ΣAB-wf\n \n open Wf.All measure-wf lzero using (wfRec) public\n", "meta": {"hexsha": "426b148fd77c89730e95791091c8dd3f05509a81", "size": 3975, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda/Utils.agda", "max_stars_repo_name": "HuStmpHrrr/popl20-artifact", "max_stars_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-23T08:40:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-23T08:40:28.000Z", "max_issues_repo_path": "agda/Utils.agda", "max_issues_repo_name": "HuStmpHrrr/popl20-artifact", "max_issues_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b", "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/Utils.agda", "max_forks_repo_name": "HuStmpHrrr/popl20-artifact", "max_forks_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b", "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": 33.4033613445, "max_line_length": 74, "alphanum_fraction": 0.5116981132, "num_tokens": 1488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.6150878555160665, "lm_q1q2_score": 0.3737662360086086}} {"text": "{-\n\n Functions building UARels and DUARels on Σ-types\n\n-}\n{-# OPTIONS --safe #-}\nmodule Cubical.Displayed.Sigma where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\n\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Displayed.Base\nopen import Cubical.Displayed.Subst\nopen import Cubical.Displayed.Morphism\nopen import Cubical.Displayed.Constant\n\nprivate\n variable\n ℓ ℓA ℓA' ℓP ℓ≅A ℓ≅A' ℓB ℓB' ℓ≅B ℓ≅B' ℓC ℓ≅C : Level\n\n-- UARel on a Σ-type\n\n∫ˢ : {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB} (𝒮ˢ-B : SubstRel 𝒮-A B)\n → UARel (Σ A B) (ℓ-max ℓ≅A ℓB)\n∫ˢ 𝒮ˢ-B = ∫ (Subst→DUA 𝒮ˢ-B)\n\n_×𝒮_ : {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) {B : Type ℓB} (𝒮-B : UARel B ℓ≅B)\n → UARel (A × B) (ℓ-max ℓ≅A ℓ≅B)\n𝒮-A ×𝒮 𝒮-B = ∫ (𝒮ᴰ-const 𝒮-A 𝒮-B)\n\n-- Projection UARel morphisms\n\n𝒮-fst : {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB} {𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B}\n → UARelHom (∫ 𝒮ᴰ-B) 𝒮-A\n𝒮-fst .UARelHom.fun = fst\n𝒮-fst .UARelHom.rel = fst\n𝒮-fst .UARelHom.ua p = refl\n\n𝒮-snd : {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : Type ℓB} {𝒮-B : UARel B ℓ≅B}\n → UARelHom (𝒮-A ×𝒮 𝒮-B) 𝒮-B\n𝒮-snd .UARelHom.fun = snd\n𝒮-snd .UARelHom.rel = snd\n𝒮-snd .UARelHom.ua p = refl\n\n-- Lift a DUARel to live over a Σ-type\n\n𝒮ᴰ-Lift : {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) {B : A → Type ℓB} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B)\n {C : A → Type ℓC} (𝒮ᴰ-C : DUARel 𝒮-A C ℓ≅C)\n → DUARel (∫ 𝒮ᴰ-C) (λ (a , _) → B a) ℓ≅B\n𝒮ᴰ-Lift _ 𝒮ᴰ-B _ = 𝒮ᴰ-reindex 𝒮-fst 𝒮ᴰ-B\n\n-- DUARel on a Σ-type\n\nmodule _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}\n {B : A → Type ℓB} {ℓ≅B : Level} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B)\n {C : Σ A B → Type ℓC} {ℓ≅C : Level} (𝒮ᴰ-C : DUARel (∫ 𝒮ᴰ-B) C ℓ≅C)\n where\n\n open UARel 𝒮-A\n private\n module B = DUARel 𝒮ᴰ-B\n module C = DUARel 𝒮ᴰ-C\n\n 𝒮ᴰ-Σ : DUARel 𝒮-A (λ a → Σ[ b ∈ B a ] C (a , b)) (ℓ-max ℓ≅B ℓ≅C)\n DUARel._≅ᴰ⟨_⟩_ 𝒮ᴰ-Σ (b , c) p (b' , c') =\n Σ[ q ∈ b B.≅ᴰ⟨ p ⟩ b' ] (c C.≅ᴰ⟨ p , q ⟩ c')\n DUARel.uaᴰ 𝒮ᴰ-Σ (b , c) p (b' , c') =\n compEquiv\n (Σ-cong-equiv (B.uaᴰ b p b') (λ q → C.uaᴰ c (p , q) c'))\n ΣPath≃PathΣ\n\n-- DUARel on a non-dependent Σ-type\n\nmodule _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}\n {B : A → Type ℓB} {ℓ≅B : Level} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B)\n {C : A → Type ℓC} {ℓ≅C : Level} (𝒮ᴰ-C : DUARel 𝒮-A C ℓ≅C)\n where\n\n _×𝒮ᴰ_ : DUARel 𝒮-A (λ a → B a × C a) (ℓ-max ℓ≅B ℓ≅C)\n _×𝒮ᴰ_ = 𝒮ᴰ-Σ 𝒮ᴰ-B (𝒮ᴰ-Lift 𝒮-A 𝒮ᴰ-C 𝒮ᴰ-B)\n\n-- SubstRel on a Σ-type\n\nmodule _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}\n {B : A → Type ℓB} (𝒮ˢ-B : SubstRel 𝒮-A B)\n {C : Σ A B → Type ℓC} (𝒮ˢ-C : SubstRel (∫ˢ 𝒮ˢ-B) C)\n where\n\n open UARel 𝒮-A\n open SubstRel\n private\n module B = SubstRel 𝒮ˢ-B\n module C = SubstRel 𝒮ˢ-C\n\n 𝒮ˢ-Σ : SubstRel 𝒮-A (λ a → Σ[ b ∈ B a ] C (a , b))\n 𝒮ˢ-Σ .act p = Σ-cong-equiv (B.act p) (λ b → C.act (p , refl))\n 𝒮ˢ-Σ .uaˢ p _ =\n fromPathP\n (DUARel.uaᴰ (𝒮ᴰ-Σ (Subst→DUA 𝒮ˢ-B) (Subst→DUA 𝒮ˢ-C)) _ p _ .fst (refl , refl))\n\n-- SubstRel on a non-dependent product\n\nmodule _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A}\n {B : A → Type ℓB} (𝒮ˢ-B : SubstRel 𝒮-A B)\n {C : A → Type ℓC} (𝒮ˢ-C : SubstRel 𝒮-A C)\n where\n\n open UARel 𝒮-A\n open SubstRel\n private\n module B = SubstRel 𝒮ˢ-B\n module C = SubstRel 𝒮ˢ-C\n\n _×𝒮ˢ_ : SubstRel 𝒮-A (λ a → B a × C a)\n _×𝒮ˢ_ .act p = ≃-× (B.act p) (C.act p)\n _×𝒮ˢ_ .uaˢ p (b , c) = ΣPathP (B.uaˢ p b , C.uaˢ p c)\n", "meta": {"hexsha": "d62834baa122ed177a056a816d3684a3ec92e1ba", "size": 3263, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Displayed/Sigma.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Displayed/Sigma.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Displayed/Sigma.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": 27.4201680672, "max_line_length": 87, "alphanum_fraction": 0.5623659209, "num_tokens": 1969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.6150878555160665, "lm_q1q2_score": 0.3737662360086086}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Some properties imply others\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Relation.Unary.Consequences where\n\nopen import Relation.Unary\nopen import Relation.Nullary using (recompute)\n\ndec⟶recomputable : {a ℓ : _} {A : Set a} {P : Pred A ℓ} → Decidable P → Recomputable P\ndec⟶recomputable P-dec = recompute (P-dec _)\n", "meta": {"hexsha": "23bf21b22da4fe31e4c13a7107fd068f89cd8b69", "size": 496, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib/src/Relation/Unary/Consequences.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "agda-stdlib/src/Relation/Unary/Consequences.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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-stdlib/src/Relation/Unary/Consequences.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 31.0, "max_line_length": 86, "alphanum_fraction": 0.5040322581, "num_tokens": 107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.6039318337259584, "lm_q1q2_score": 0.3737012020246673}} {"text": "------------------------------------------------------------------------------\n-- Properties stated in the Burstall's paper\n------------------------------------------------------------------------------\n\n{-# OPTIONS --exact-split #-}\n{-# OPTIONS --no-sized-types #-}\n{-# OPTIONS --no-universe-polymorphism #-}\n{-# OPTIONS --without-K #-}\n\nmodule FOTC.Program.SortList.PropertiesI where\n\nopen import Common.FOL.Relation.Binary.EqReasoning\n\nopen import FOTC.Base\nopen import FOTC.Base.List\nopen import FOTC.Data.Bool\nopen import FOTC.Data.Bool.PropertiesI\nopen import FOTC.Data.Nat.Inequalities\nopen import FOTC.Data.Nat.Inequalities.PropertiesI\nopen import FOTC.Data.Nat.List.Type\nopen import FOTC.Data.Nat.Type\nopen import FOTC.Data.List\nopen import FOTC.Data.List.PropertiesI\nopen import FOTC.Program.SortList.Properties.Totality.BoolI\nopen import FOTC.Program.SortList.Properties.Totality.ListN-I\nopen import FOTC.Program.SortList.Properties.Totality.OrdList.FlattenI\nopen import FOTC.Program.SortList.Properties.Totality.OrdListI\nopen import FOTC.Program.SortList.Properties.Totality.OrdTreeI\nopen import FOTC.Program.SortList.Properties.Totality.TreeI\nopen import FOTC.Program.SortList.SortList\n\n------------------------------------------------------------------------------\n-- Induction on lit.\nind-lit : (A : D → Set) (f : D) → ∀ y₀ {xs} → ListN xs →\n A y₀ →\n (∀ {x} → N x → ∀ y → A y → A (f · x · y)) →\n A (lit f xs y₀)\nind-lit A f y₀ lnnil Ay₀ ih = subst A (sym (lit-[] f y₀)) Ay₀\nind-lit A f y₀ (lncons {i} {is} Ni LNis) Ay₀ ih =\n subst A\n (sym (lit-∷ f i is y₀))\n (ih Ni (lit f is y₀) (ind-lit A f y₀ LNis Ay₀ ih))\n\n------------------------------------------------------------------------------\n-- Burstall's lemma: If t is ordered then totree(i, t) is ordered.\ntoTree-OrdTree : ∀ {item t} → N item → Tree t → OrdTree t →\n OrdTree (toTree · item · t)\ntoTree-OrdTree {item} Nitem tnil _ =\n ordTree (toTree · item · nil)\n ≡⟨ subst (λ x → ordTree (toTree · item · nil) ≡\n ordTree x)\n (toTree-nil item)\n refl\n ⟩\n ordTree (tip item)\n ≡⟨ ordTree-tip item ⟩\n true ∎\n\ntoTree-OrdTree {item} Nitem (ttip {i} Ni) _ =\n case prf₁ prf₂ (x>y∨x≤y Ni Nitem)\n where\n prf₁ : i > item → OrdTree (toTree · item · tip i)\n prf₁ i>item =\n ordTree (toTree · item · tip i)\n ≡⟨ subst (λ t → ordTree (toTree · item · tip i) ≡ ordTree t)\n (toTree-tip item i)\n refl\n ⟩\n ordTree (if (le i item)\n then (node (tip i) item (tip item))\n else (node (tip item) i (tip i)))\n ≡⟨ subst (λ t → ordTree (if (le i item)\n then (node (tip i) item (tip item))\n else (node (tip item) i (tip i))) ≡\n ordTree (if t\n then (node (tip i) item (tip item))\n else (node (tip item) i (tip i))))\n (x>y→x≰y Ni Nitem i>item)\n refl\n ⟩\n ordTree (if false\n then (node (tip i) item (tip item))\n else (node (tip item) i (tip i)))\n ≡⟨ subst (λ t → ordTree (if false\n then (node (tip i) item (tip item))\n else (node (tip item) i (tip i))) ≡\n ordTree t)\n (if-false (node (tip item) i (tip i)))\n refl\n ⟩\n ordTree (node (tip item) i (tip i))\n ≡⟨ ordTree-node (tip item) i (tip i) ⟩\n ordTree (tip item)\n && ordTree (tip i)\n && le-TreeItem (tip item) i\n && le-ItemTree i (tip i)\n ≡⟨ subst (λ t → ordTree (tip item)\n && ordTree (tip i)\n && le-TreeItem (tip item) i\n && le-ItemTree i (tip i) ≡\n t\n && ordTree (tip i)\n && le-TreeItem (tip item) i\n && le-ItemTree i (tip i))\n (ordTree-tip item)\n refl\n ⟩\n true && ordTree (tip i) && le-TreeItem (tip item) i &&\n le-ItemTree i (tip i)\n ≡⟨ subst (λ t → true\n && ordTree (tip i)\n && le-TreeItem (tip item) i\n && le-ItemTree i (tip i) ≡\n true\n && t\n && le-TreeItem (tip item) i\n && le-ItemTree i (tip i))\n (ordTree-tip i)\n refl\n ⟩\n true && true && le-TreeItem (tip item) i && le-ItemTree i (tip i)\n ≡⟨ subst (λ t → true && true && le-TreeItem (tip item) i &&\n le-ItemTree i (tip i) ≡\n true && true && t && le-ItemTree i (tip i))\n (le-TreeItem-tip item i)\n refl\n ⟩\n true && true && le item i && le-ItemTree i (tip i)\n ≡⟨ subst (λ t → true && true && le item i && le-ItemTree i (tip i) ≡\n true && true && t && le-ItemTree i (tip i))\n (xitem)\n refl\n ⟩\n true && true && true && le-ItemTree i (tip i)\n ≡⟨ subst (λ t → true && true && true && le-ItemTree i (tip i) ≡\n true && true && true && t)\n (le-ItemTree-tip i i)\n refl\n ⟩\n true && true && true && le i i\n ≡⟨ subst (λ t → true && true && true && le i i ≡\n true && true && true && t)\n (x≤x Ni)\n refl\n ⟩\n true && true && true && true\n ≡⟨ subst (λ t → true && true && true && true ≡ true && true && t)\n (t&&x≡x true)\n refl\n ⟩\n true && true && true\n ≡⟨ subst (λ t → true && true && true ≡ true && t)\n (t&&x≡x true)\n refl\n ⟩\n true && true\n ≡⟨ t&&x≡x true ⟩\n true ∎\n\n prf₂ : i ≤ item → OrdTree (toTree · item · tip i)\n prf₂ i≤item =\n ordTree (toTree · item · tip i)\n ≡⟨ subst (λ t → ordTree (toTree · item · tip i) ≡ ordTree t)\n (toTree-tip item i)\n refl\n ⟩\n ordTree (if (le i item)\n then (node (tip i) item (tip item))\n else (node (tip item) i (tip i)))\n ≡⟨ subst (λ t → ordTree (if (le i item)\n then (node (tip i) item (tip item))\n else (node (tip item) i (tip i))) ≡\n ordTree (if t\n then (node (tip i) item (tip item))\n else (node (tip item) i (tip i))))\n i≤item\n refl\n ⟩\n ordTree (if true\n then (node (tip i) item (tip item))\n else (node (tip item) i (tip i)))\n ≡⟨ subst (λ t → ordTree (if true\n then (node (tip i) item (tip item))\n else (node (tip item) i (tip i))) ≡\n ordTree t)\n (if-true (node (tip i) item (tip item)))\n refl\n ⟩\n ordTree (node (tip i) item (tip item))\n ≡⟨ ordTree-node (tip i) item (tip item) ⟩\n ordTree (tip i) && ordTree (tip item) && le-TreeItem (tip i) item &&\n le-ItemTree item (tip item)\n ≡⟨ subst (λ t → ordTree (tip i) &&\n ordTree (tip item) &&\n le-TreeItem (tip i) item &&\n le-ItemTree item (tip item) ≡\n t &&\n ordTree (tip item) &&\n le-TreeItem (tip i) item &&\n le-ItemTree item (tip item))\n (ordTree-tip i)\n refl\n ⟩\n true && ordTree (tip item) && le-TreeItem (tip i) item &&\n le-ItemTree item (tip item)\n ≡⟨ subst (λ t → true &&\n ordTree (tip item) &&\n le-TreeItem (tip i) item &&\n le-ItemTree item (tip item) ≡\n true &&\n t &&\n le-TreeItem (tip i) item &&\n le-ItemTree item (tip item))\n (ordTree-tip item)\n refl\n ⟩\n true && true && le-TreeItem (tip i) item && le-ItemTree item (tip item)\n ≡⟨ subst (λ t → true && true && le-TreeItem (tip i) item &&\n le-ItemTree item (tip item) ≡\n true && true && t && le-ItemTree item (tip item))\n (le-TreeItem-tip i item)\n refl\n ⟩\n true && true && le i item && le-ItemTree item (tip item)\n ≡⟨ subst (λ t → true && true && le i item && le-ItemTree item (tip item) ≡\n true && true && t && le-ItemTree item (tip item))\n i≤item\n refl\n ⟩\n true && true && true && le-ItemTree item (tip item)\n ≡⟨ subst (λ t → true && true && true && le-ItemTree item (tip item) ≡\n true && true && true && t)\n (le-ItemTree-tip item item)\n refl\n ⟩\n true && true && true && le item item\n ≡⟨ subst (λ t → true && true && true && le item item ≡\n true && true && true && t)\n (x≤x Nitem)\n refl\n ⟩\n true && true && true && true\n ≡⟨ subst (λ t → true && true && true && true ≡ true && true && t)\n (t&&x≡x true)\n refl\n ⟩\n true && true && true\n ≡⟨ subst (λ t → true && true && true ≡ true && t) (t&&x≡x true) refl ⟩\n true && true\n ≡⟨ t&&x≡x true ⟩\n true ∎\n\ntoTree-OrdTree {item} Nitem (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) OTtnode =\n case prf₁ prf₂ (x>y∨x≤y Ni Nitem)\n where\n prf₁ : i > item → OrdTree (toTree · item · node t₁ i t₂)\n prf₁ i>item =\n ordTree (toTree · item · node t₁ i t₂)\n ≡⟨ subst (λ t → ordTree (toTree · item · node t₁ i t₂) ≡ ordTree t)\n (toTree-node item t₁ i t₂)\n refl\n ⟩\n ordTree (if (le i item)\n then (node t₁ i (toTree · item · t₂))\n else (node (toTree · item · t₁) i t₂))\n ≡⟨ subst (λ t → ordTree (if (le i item)\n then (node t₁ i (toTree · item · t₂))\n else (node (toTree · item · t₁) i t₂)) ≡\n ordTree (if t\n then (node t₁ i (toTree · item · t₂))\n else (node (toTree · item · t₁) i t₂)))\n (x>y→x≰y Ni Nitem i>item)\n refl\n ⟩\n ordTree (if false\n then (node t₁ i (toTree · item · t₂))\n else (node (toTree · item · t₁) i t₂))\n ≡⟨ subst (λ t → ordTree (if false\n then (node t₁ i (toTree · item · t₂))\n else (node (toTree · item · t₁) i t₂)) ≡\n ordTree t)\n (if-false (node (toTree · item · t₁) i t₂))\n refl\n ⟩\n ordTree (node (toTree · item · t₁) i t₂)\n ≡⟨ ordTree-node (toTree · item · t₁) i t₂ ⟩\n ordTree (toTree · item · t₁) &&\n ordTree t₂ &&\n le-TreeItem (toTree · item · t₁) i &&\n le-ItemTree i t₂\n ≡⟨ subst (λ t → ordTree (toTree · item · t₁) &&\n ordTree t₂ &&\n le-TreeItem (toTree · item · t₁) i &&\n le-ItemTree i t₂ ≡\n t &&\n ordTree t₂ &&\n le-TreeItem (toTree · item · t₁) i &&\n le-ItemTree i t₂)\n (toTree-OrdTree Nitem Tt₁\n (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))\n refl\n ⟩\n true && ordTree t₂ && le-TreeItem (toTree · item · t₁) i &&\n le-ItemTree i t₂\n ≡⟨ subst (λ t → true &&\n ordTree t₂ &&\n le-TreeItem (toTree · item · t₁) i &&\n le-ItemTree i t₂ ≡\n true &&\n t &&\n le-TreeItem (toTree · item · t₁) i &&\n le-ItemTree i t₂)\n (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode)\n refl\n ⟩\n true && true && le-TreeItem (toTree · item · t₁) i && le-ItemTree i t₂\n ≡⟨ subst (λ t → true &&\n true &&\n le-TreeItem (toTree · item · t₁) i &&\n le-ItemTree i t₂ ≡\n true && true && t && le-ItemTree i t₂)\n (toTree-OrdTree-helper₁ Ni Nitem i>item Tt₁\n ((&&-list₄-t₃\n (ordTree-Bool Tt₁)\n (ordTree-Bool Tt₂)\n (le-TreeItem-Bool Tt₁ Ni)\n (le-ItemTree-Bool Ni Tt₂)\n (trans (sym (ordTree-node t₁ i t₂)) OTtnode))))\n refl\n ⟩\n true && true && true && le-ItemTree i t₂\n ≡⟨ subst (λ t → true && true && true && le-ItemTree i t₂ ≡\n true && true && true && t)\n (&&-list₄-t₄\n (ordTree-Bool Tt₁)\n (ordTree-Bool Tt₂)\n (le-TreeItem-Bool Tt₁ Ni)\n (le-ItemTree-Bool Ni Tt₂)\n (trans (sym (ordTree-node t₁ i t₂)) OTtnode))\n refl\n ⟩\n true && true && true && true\n ≡⟨ subst (λ t → true && true && true && true ≡ true && true && t)\n (t&&x≡x true)\n refl\n ⟩\n true && true && true\n ≡⟨ subst (λ t → true && true && true ≡ true && t) (t&&x≡x true) refl ⟩\n true && true\n ≡⟨ t&&x≡x true ⟩\n true ∎\n\n prf₂ : i ≤ item → OrdTree (toTree · item · node t₁ i t₂)\n prf₂ i≤item =\n ordTree (toTree · item · node t₁ i t₂)\n ≡⟨ subst (λ t → ordTree (toTree · item · node t₁ i t₂) ≡ ordTree t)\n (toTree-node item t₁ i t₂)\n refl\n ⟩\n ordTree (if (le i item)\n then (node t₁ i (toTree · item · t₂))\n else (node (toTree · item · t₁) i t₂))\n ≡⟨ subst (λ t → ordTree (if (le i item)\n then (node t₁ i (toTree · item · t₂))\n else (node (toTree · item · t₁) i t₂)) ≡\n ordTree (if t\n then (node t₁ i (toTree · item · t₂))\n else (node (toTree · item · t₁) i t₂)))\n i≤item\n refl\n ⟩\n ordTree (if true\n then (node t₁ i (toTree · item · t₂))\n else (node (toTree · item · t₁) i t₂))\n ≡⟨ subst (λ t → ordTree (if true\n then (node t₁ i (toTree · item · t₂))\n else (node (toTree · item · t₁) i t₂)) ≡\n ordTree t)\n (if-true (node t₁ i (toTree · item · t₂)))\n refl\n ⟩\n ordTree (node t₁ i (toTree · item · t₂))\n ≡⟨ ordTree-node t₁ i (toTree · item · t₂) ⟩\n ordTree t₁ &&\n ordTree (toTree · item · t₂) &&\n le-TreeItem t₁ i &&\n le-ItemTree i (toTree · item · t₂)\n ≡⟨ subst (λ t → ordTree t₁ &&\n ordTree (toTree · item · t₂) &&\n le-TreeItem t₁ i &&\n le-ItemTree i (toTree · item · t₂) ≡\n t &&\n ordTree (toTree · item · t₂) &&\n le-TreeItem t₁ i &&\n le-ItemTree i (toTree · item · t₂))\n (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode)\n refl\n ⟩\n true && ordTree (toTree · item · t₂) && le-TreeItem t₁ i &&\n le-ItemTree i (toTree · item · t₂)\n ≡⟨ subst (λ t → true &&\n ordTree (toTree · item · t₂) &&\n le-TreeItem t₁ i &&\n le-ItemTree i (toTree · item · t₂) ≡\n true &&\n t &&\n le-TreeItem t₁ i &&\n le-ItemTree i (toTree · item · t₂))\n (toTree-OrdTree Nitem Tt₂\n (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))\n refl\n ⟩\n true && true && le-TreeItem t₁ i && le-ItemTree i (toTree · item · t₂)\n ≡⟨ subst (λ t → true &&\n true &&\n le-TreeItem t₁ i &&\n le-ItemTree i (toTree · item · t₂) ≡\n true &&\n true &&\n t &&\n le-ItemTree i (toTree · item · t₂))\n (&&-list₄-t₃\n (ordTree-Bool Tt₁)\n (ordTree-Bool Tt₂)\n (le-TreeItem-Bool Tt₁ Ni)\n (le-ItemTree-Bool Ni Tt₂)\n (trans (sym (ordTree-node t₁ i t₂)) OTtnode))\n refl\n ⟩\n true && true && true && le-ItemTree i (toTree · item · t₂)\n ≡⟨ subst (λ t → true &&\n true &&\n true &&\n le-ItemTree i (toTree · item · t₂) ≡\n true && true && true && t)\n (toTree-OrdTree-helper₂ Ni Nitem i≤item Tt₂\n ((&&-list₄-t₄\n (ordTree-Bool Tt₁)\n (ordTree-Bool Tt₂)\n (le-TreeItem-Bool Tt₁ Ni)\n (le-ItemTree-Bool Ni Tt₂)\n (trans (sym (ordTree-node t₁ i t₂)) OTtnode))))\n refl\n ⟩\n true && true && true && true\n ≡⟨ subst (λ t → true && true && true && true ≡ true && true && t)\n (t&&x≡x true)\n refl\n ⟩\n true && true && true\n ≡⟨ subst (λ t → true && true && true ≡ true && t) (t&&x≡x true) refl ⟩\n true && true\n ≡⟨ t&&x≡x true ⟩\n true ∎\n\n------------------------------------------------------------------------------\n-- Burstall's lemma: ord(maketree(is)).\n\n-- makeTree-TreeOrd : ∀ {is} → ListN is → OrdTree (makeTree is)\n-- makeTree-TreeOrd LNis =\n-- ind-lit OrdTree toTree nil LNis ordTree-nil\n-- (λ Nx y TOy → toTree-OrdTree Nx {!!} TOy)\n\nmakeTree-OrdTree : ∀ {is} → ListN is → OrdTree (makeTree is)\nmakeTree-OrdTree lnnil =\n ordTree (lit toTree [] nil)\n ≡⟨ subst (λ t → ordTree (lit toTree [] nil) ≡ ordTree t)\n (lit-[] toTree nil)\n refl\n ⟩\n ordTree nil\n ≡⟨ ordTree-nil ⟩\n true ∎\n\nmakeTree-OrdTree (lncons {i} {is} Ni Lis) =\n ordTree (lit toTree (i ∷ is) nil)\n ≡⟨ subst (λ t → ordTree (lit toTree (i ∷ is) nil) ≡ ordTree t)\n (lit-∷ toTree i is nil)\n refl\n ⟩\n ordTree (toTree · i · (lit toTree is nil))\n ≡⟨ toTree-OrdTree Ni (makeTree-Tree Lis) (makeTree-OrdTree Lis) ⟩\n true ∎\n\n------------------------------------------------------------------------------\n-- Burstall's lemma: If ord(is1) and ord(is2) and is1 ≤ is2 then\n-- ord(concat(is1, is2)).\n++-OrdList : ∀ {is js} → ListN is → ListN js → OrdList is → OrdList js →\n ≤-Lists is js → OrdList (is ++ js)\n\n++-OrdList {js = js} lnnil LNjs LOis LOjs is≤js =\n subst OrdList (sym (++-leftIdentity js)) LOjs\n\n++-OrdList {js = js} (lncons {i} {is} Ni LNis) LNjs LOi∷is LOjs i∷is≤js =\n subst OrdList (sym (++-∷ i is js)) lemma\n where\n lemma : OrdList (i ∷ is ++ js)\n lemma =\n ordList (i ∷ is ++ js)\n ≡⟨ ordList-∷ i (is ++ js) ⟩\n le-ItemList i (is ++ js) && ordList (is ++ js)\n ≡⟨ subst (λ t → le-ItemList i (is ++ js) && ordList (is ++ js) ≡\n t && ordList (is ++ js))\n (++-OrdList-helper Ni LNis LNjs\n (&&-list₂-t₁ (le-ItemList-Bool Ni LNis)\n (ordList-Bool LNis)\n (trans (sym (ordList-∷ i is)) LOi∷is))\n (&&-list₂-t₁ (le-ItemList-Bool Ni LNjs)\n (le-Lists-Bool LNis LNjs)\n (trans (sym (le-Lists-∷ i is js)) i∷is≤js))\n (&&-list₂-t₂ (le-ItemList-Bool Ni LNjs)\n (le-Lists-Bool LNis LNjs)\n (trans (sym (le-Lists-∷ i is js)) i∷is≤js))\n )\n refl\n ⟩\n true && ordList (is ++ js)\n ≡⟨ subst (λ t → true && ordList (is ++ js) ≡ true && t)\n (++-OrdList LNis LNjs (subList-OrdList Ni LNis LOi∷is) LOjs\n (&&-list₂-t₂\n (le-ItemList-Bool Ni LNjs)\n (le-Lists-Bool LNis LNjs)\n (trans (sym (le-Lists-∷ i is js)) i∷is≤js)))\n refl\n ⟩\n true && true\n ≡⟨ t&&x≡x true ⟩\n true ∎\n\n------------------------------------------------------------------------------\n-- Burstall's lemma: If t is ordered then (flatten t) is ordered.\nflatten-OrdList : ∀ {t} → Tree t → OrdTree t → OrdList (flatten t)\nflatten-OrdList tnil OTt =\n subst OrdList (sym flatten-nil) ordList-[]\n\nflatten-OrdList (ttip {i} Ni) OTt =\n ordList (flatten (tip i))\n ≡⟨ subst (λ t → ordList (flatten (tip i)) ≡ ordList t)\n (flatten-tip i)\n refl\n ⟩\n ordList (i ∷ [])\n ≡⟨ ordList-∷ i [] ⟩\n le-ItemList i [] && ordList []\n ≡⟨ subst₂ (λ t₁ t₂ → le-ItemList i [] && ordList [] ≡ t₁ && t₂)\n (le-ItemList-[] i)\n ordList-[]\n refl\n ⟩\n true && true\n ≡⟨ t&&x≡x true ⟩\n true ∎\n\nflatten-OrdList (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) OTt =\n ordList (flatten (node t₁ i t₂))\n ≡⟨ subst (λ t → ordList (flatten (node t₁ i t₂)) ≡ ordList t)\n (flatten-node t₁ i t₂)\n refl\n ⟩\n ordList (flatten t₁ ++ flatten t₂)\n ≡⟨ ++-OrdList (flatten-ListN Tt₁)\n (flatten-ListN Tt₂)\n (flatten-OrdList Tt₁ (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTt))\n (flatten-OrdList Tt₂ (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTt))\n (flatten-OrdList-helper Tt₁ Ni Tt₂ OTt)\n ⟩\n true ∎\n", "meta": {"hexsha": "01e87c7bb81a461eb4f9a69be4eb112ae4ad5d6c", "size": 22814, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/fot/FOTC/Program/SortList/PropertiesI.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": "src/fot/FOTC/Program/SortList/PropertiesI.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": "src/fot/FOTC/Program/SortList/PropertiesI.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": 40.1654929577, "max_line_length": 80, "alphanum_fraction": 0.4080389235, "num_tokens": 6539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.6039318337259583, "lm_q1q2_score": 0.37370120202466717}} {"text": "-- Andreas, 2012-09-13\n-- (The signature on the previous line does not apply to all of the\n-- text in this file.)\nmodule RelevanceSubtyping where\n\n-- this naturally type-checks:\none : {A B : Set} → (.A → B) → A → B\none f x = f x\n\n-- Subtyping is no longer supported for irrelevance, so the following\n-- code is no longer accepted.\n\n-- -- this type-checks because of subtyping\n-- one' : {A B : Set} → (.A → B) → A → B\n-- one' f = f\n", "meta": {"hexsha": "ca39b34ff95708dd6ac0710b9641355456fb2a86", "size": 431, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/RelevanceSubtyping.agda", "max_stars_repo_name": "cagix/agda", "max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_stars_repo_licenses": ["BSD-2-Clause"], "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/Succeed/RelevanceSubtyping.agda", "max_issues_repo_name": "cagix/agda", "max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_issues_repo_licenses": ["BSD-2-Clause"], "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/Succeed/RelevanceSubtyping.agda", "max_forks_repo_name": "cagix/agda", "max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_forks_repo_licenses": ["BSD-2-Clause"], "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.9375, "max_line_length": 69, "alphanum_fraction": 0.6450116009, "num_tokens": 134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6513548646660542, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.3736682214480669}} {"text": "\nmodule Oscar.Data.Equality.properties where\n\n-- open import Relation.Binary.PropositionalEquality public using (cong; cong₂; cong-app; subst; subst₂; sym; trans)\n\n-- open import Oscar.Data.Equality\n-- open import Oscar.Function\n-- open import Oscar.Level\n-- open import Oscar.Relation\n\n-- -- ≡̇-refl : ∀ {a} {A : Set a} {b} {B : A → Set b} (f : (x : A) → B x) → f ≡̇ f\n-- -- ≡̇-refl _ _ = refl\n\n-- -- ≡̇-sym : ∀ {a} {A : Set a} {b} {B : A → Set b} {f g : (x : A) → B x} → f ≡̇ g → g ≡̇ f\n-- -- ≡̇-sym f≡̇g = sym ∘ f≡̇g\n\n-- -- ≡̇-trans : ∀ {a} {A : Set a} {b} {B : A → Set b} {f g : (x : A) → B x} → f ≡̇ g → {h : (x : A) → B x} → g ⟨ _≡̇ h ⟩→ f\n-- -- ≡̇-trans f≡̇g g≡̇h x = trans (f≡̇g x) (g≡̇h x)\n\n-- -- -- open import Oscar.Category.Setoid\n\n-- -- -- instance\n\n-- -- -- IsEquivalencePropositionalEquality : ∀ {a} {A : Set a} → IsEquivalence (_≡_ {A = A})\n-- -- -- IsEquivalence.reflexivity IsEquivalencePropositionalEquality _ = refl\n-- -- -- IsEquivalence.symmetry IsEquivalencePropositionalEquality = sym\n-- -- -- IsEquivalence.transitivity IsEquivalencePropositionalEquality = λ ‵ → trans ‵\n\n-- -- -- IsEquivalenceIndexedPropositionalEquality : ∀ {a} {A : Set a} {b} {B : A → Set b} → IsEquivalence (_≡̇_ {B = B})\n-- -- -- IsEquivalence.reflexivity IsEquivalenceIndexedPropositionalEquality = ≡̇-refl\n-- -- -- IsEquivalence.symmetry IsEquivalenceIndexedPropositionalEquality = ≡̇-sym\n-- -- -- IsEquivalence.transitivity IsEquivalenceIndexedPropositionalEquality = ≡̇-trans\n\n-- -- -- instance\n\n-- -- -- IsSetoidPropositionalEquality : ∀ {a} {A : Set a} → IsSetoid A a\n-- -- -- IsSetoid._≋_ IsSetoidPropositionalEquality = _≡_\n\n-- -- -- IsSetoidIndexedPropositionalEquality : ∀ {a} {A : Set a} {b} {B : A → Set b} → IsSetoid ((x : A) → B x) (a ⊔ b)\n-- -- -- IsSetoid._≋_ IsSetoidIndexedPropositionalEquality = _≡̇_\n\n-- -- -- setoidPropositionalEquality : ∀ {a} (A : Set a) → Setoid a a\n-- -- -- Setoid.⋆ (setoidPropositionalEquality A) = A\n\n-- -- -- setoidIndexedPropositionalEquality : ∀ {a} {A : Set a} {b} (B : A → Set b) → Setoid (a ⊔ b) (a ⊔ b)\n-- -- -- Setoid.⋆ (setoidIndexedPropositionalEquality {A = A} B) = (x : A) → B x\n-- -- -- Setoid.isSetoid (setoidIndexedPropositionalEquality B) = IsSetoidIndexedPropositionalEquality {B = B}\n\n-- -- -- open import Oscar.Category.Action\n\n-- -- -- actionΣ : ∀ {a} {A : Set a} {b} (B : A → Set b) → Action A b b\n-- -- -- Action.𝔄 (actionΣ B) x = setoidPropositionalEquality (B x)\n\n-- -- -- _⇒_ : ∀ {a} (A : Set a) {b} (B : Set b) → Setoid _ _\n-- -- -- _⇒_ A B = setoidIndexedPropositionalEquality {A = A} λ _ → B\n\n-- -- -- open import Oscar.Category.Semigroupoid\n-- -- -- open import Oscar.Category.Morphism\n\n-- -- -- ⇧ : ∀ {a} {A : Set a} {b} (B : A → A → Set b) → Morphism A b b\n-- -- -- Morphism._⇒_ (⇧ B) x y = setoidPropositionalEquality (B x y)\n\n-- -- -- _⇨_ : ∀ {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) → Morphism A (b ⊔ c) (b ⊔ c)\n-- -- -- Morphism._⇒_ (B ⇨ C) = λ m n → B m ⇒ C n\n\n-- -- -- IsSemigroupoid⋆ : ∀ {a} {A : Set a} {b} {B : A → Set b} {c} {C : A → Set c}\n-- -- -- (let _↦_ = λ m n → B m → C n)\n-- -- -- (_∙_ : ∀ {y z} → y ↦ z → ∀ {x} → x ↦ y → x ↦ z) → Set (lsuc (a ⊔ b ⊔ c))\n-- -- -- IsSemigroupoid⋆ _∙_ = IsSemigroupoid (_ ⇨ _) _∙_\n\n-- -- -- Semigroupoid⋆ :\n-- -- -- ∀ {a} {A : Set a} {b} {B : A → Set b} {c} {C : A → Set c}\n-- -- -- (let _↦_ = λ m n → B m → C n)\n-- -- -- (_∙_ : ∀ {y z} → y ↦ z → ∀ {x} → x ↦ y → x ↦ z)\n-- -- -- ⦃ _ : IsSemigroupoid⋆ _∙_ ⦄\n-- -- -- → Semigroupoid _ _ _\n-- -- -- Semigroupoid⋆ _∙_ = _ ⇨ _ , _∙_\n\n-- -- -- open import Oscar.Category.Semigroupoid\n\n-- -- -- instance\n\n-- -- -- isSemigroupoidFunctions≡̇ : ∀ {a} {A : Set a} {b} {B : A → Set b} → IsSemigroupoid (B ⇨ B) (λ g f → g ∘ f)\n-- -- -- IsSemigroupoid.extensionality isSemigroupoidFunctions≡̇ {f₂ = f₂} f₁≡̇f₂ g₁≡̇g₂ x rewrite f₁≡̇f₂ x = g₁≡̇g₂ (f₂ x)\n-- -- -- IsSemigroupoid.associativity isSemigroupoidFunctions≡̇ _ _ _ _ = refl\n\n-- -- -- semigroupoidFunction : ∀ {a} {A : Set a} {b} (B : A → Set b) → Semigroupoid _ _ _\n-- -- -- semigroupoidFunction B = B ⇨ B , (λ ‵ → _∘_ ‵)\n\n-- -- -- open import Oscar.Category.Category\n\n-- -- -- instance\n\n-- -- -- isCategoryFunctions≡̇ : ∀ {a} {A : Set a} {b} {B : A → Set b} → IsCategory (semigroupoidFunction B) id\n-- -- -- IsCategory.left-identity isCategoryFunctions≡̇ _ _ = refl\n-- -- -- IsCategory.right-identity isCategoryFunctions≡̇ _ _ = refl\n\n-- -- -- categoryFunction : ∀ {a} {A : Set a} {b} (B : A → Set b) → Category _ _ _\n-- -- -- categoryFunction B = semigroupoidFunction B , id\n\n\n\n-- -- -- -- -- open import Oscar.Property.Reflexivity\n\n-- -- -- -- -- instance Reflexivity≡ : ∀ {a} {A : Set a} → Reflexivity (_≡_ {A = A})\n-- -- -- -- -- Reflexivity.reflexivity Reflexivity≡ _ = refl\n\n-- -- -- -- -- instance Reflexivity≡̇ : ∀ {a} {A : Set a} {b} {B : A → Set b} → Reflexivity (_≡̇_ {B = B})\n-- -- -- -- -- Reflexivity.reflexivity Reflexivity≡̇ _ _ = refl\n\n-- -- -- -- -- open import Oscar.Property.Symmetry\n\n-- -- -- -- -- instance Symmetry≡ : ∀ {a} {A : Set a} → Symmetry (_≡_ {A = A})\n-- -- -- -- -- Symmetry.symmetry Symmetry≡ = sym\n\n-- -- -- -- -- instance Symmetry≡̇ : ∀ {a} {A : Set a} {b} {B : A → Set b} → Symmetry (_≡̇_ {B = B})\n-- -- -- -- -- Symmetry.symmetry Symmetry≡̇ = ≡̇-sym\n\n-- -- -- -- -- open import Oscar.Property.Transitivity\n\n-- -- -- -- -- instance Transitivity≡ : ∀ {a} {A : Set a} → Transitivity (_≡_ {A = A})\n-- -- -- -- -- Transitivity.transitivity Transitivity≡ x≡y = trans x≡y\n\n-- -- -- -- -- instance Transitivity≡̇ : ∀ {a} {A : Set a} {b} {B : A → Set b} → Transitivity (_≡̇_ {B = B})\n-- -- -- -- -- Transitivity.transitivity Transitivity≡̇ = ≡̇-trans\n\n-- -- -- -- -- -- {-\n-- -- -- -- -- -- _∘₂_ : ∀ {a b c}\n-- -- -- -- -- -- {A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} →\n-- -- -- -- -- -- (∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →\n-- -- -- -- -- -- ((x : A) → C (g x))\n-- -- -- -- -- -- f ∘₂ g = λ x → f (g x)\n-- -- -- -- -- -- -}\n\n\n-- -- -- -- -- -- open import Oscar.Class.Equivalence\n\n-- -- -- -- -- -- instance ReflexivityPropositional : ∀ {a} {A : Set a} → Reflexivity (_≡_ {A = A})\n-- -- -- -- -- -- Reflexivity.reflexivity ReflexivityPropositional = refl\n\n-- -- -- -- -- -- instance SymmetryPropositional : ∀ {a} {A : Set a} → Symmetry (_≡_ {A = A})\n-- -- -- -- -- -- Symmetry.symmetry SymmetryPropositional = sym\n\n-- -- -- -- -- -- instance TransitivityPropositional : ∀ {a} {A : Set a} → Transitivity (_≡_ {A = A})\n-- -- -- -- -- -- Transitivity.transitivity TransitivityPropositional = trans\n\n-- -- -- -- -- -- open import Prelude using (it)\n\n-- -- -- -- -- -- instance Equivalence⋆ : ∀ {a} {A : Set a} {ℓ} {_≋_ : A → A → Set ℓ} ⦃ _ : Reflexivity _≋_ ⦄ ⦃ _ : Symmetry _≋_ ⦄ ⦃ _ : Transitivity _≋_ ⦄ → Equivalence _≋_\n-- -- -- -- -- -- Equivalence.reflexivityI Equivalence⋆ = it\n-- -- -- -- -- -- Equivalence.symmetryI Equivalence⋆ = it\n-- -- -- -- -- -- Equivalence.transitivityI Equivalence⋆ = it\n\n-- -- -- -- -- -- -- -- {-\n-- -- -- -- -- -- -- -- instance EquivalencePropositional : ∀ {a} {A : Set a} → Equivalence (_≡_ {A = A})\n-- -- -- -- -- -- -- -- Equivalence.reflexivity EquivalencePropositional = refl\n-- -- -- -- -- -- -- -- Equivalence.symmetry EquivalencePropositional = sym\n-- -- -- -- -- -- -- -- Equivalence.transitivity EquivalencePropositional = trans\n\n-- -- -- -- -- -- -- -- instance EquivalencePointwise : ∀ {a} {A : Set a} {b} {B : A → Set b} → Equivalence (_≡̇_ {B = B})\n-- -- -- -- -- -- -- -- Equivalence.reflexivity EquivalencePointwise x = refl\n-- -- -- -- -- -- -- -- Equivalence.symmetry EquivalencePointwise = ≡̇-sym\n-- -- -- -- -- -- -- -- Equivalence.transitivity EquivalencePointwise = ≡̇-trans\n-- -- -- -- -- -- -- -- -}\n\n-- -- -- -- -- -- instance CongruousEquivalencesPropositional : ∀ {a} {A : Set a} {b} {B : Set b} → CongruousEquivalences (_≡_ {A = A}) (_≡_ {A = B})\n-- -- -- -- -- -- CongruousEquivalences.equivalence₁ CongruousEquivalencesPropositional = it\n-- -- -- -- -- -- CongruousEquivalences.equivalence₂ CongruousEquivalencesPropositional = it\n-- -- -- -- -- -- CongruousEquivalences.congruity CongruousEquivalencesPropositional = cong\n\n-- -- -- -- -- -- postulate\n-- -- -- -- -- -- FunctionName : Set\n\n-- -- -- -- -- -- open import Oscar.Data.Nat\n-- -- -- -- -- -- open import Oscar.Data.Fin\n-- -- -- -- -- -- open import Oscar.Data.Term FunctionName\n-- -- -- -- -- -- open import Oscar.Data.Term.Injectivity FunctionName\n\n-- -- -- -- -- -- instance InjectiveEquivalencesTermI : ∀ {m : Nat} → InjectiveEquivalences (_≡_ {A = Fin m}) (_≡_ {A = Term m}) Term.i Term.i\n-- -- -- -- -- -- InjectiveEquivalences.equivalence₁ InjectiveEquivalencesTermI = it\n-- -- -- -- -- -- InjectiveEquivalences.equivalence₂ InjectiveEquivalencesTermI = it\n-- -- -- -- -- -- InjectiveEquivalences.injectivity InjectiveEquivalencesTermI refl = reflexivity\n\n-- -- -- -- -- -- instance InjectiveEquivalencesTermLeft : ∀ {m : Nat} {r₁ r₂ : Term m} → InjectiveEquivalences _≡_ _≡_ (_fork r₁) (_fork r₂)\n-- -- -- -- -- -- InjectiveEquivalences.equivalence₁ InjectiveEquivalencesTermLeft = it\n-- -- -- -- -- -- InjectiveEquivalences.equivalence₂ InjectiveEquivalencesTermLeft = it\n-- -- -- -- -- -- InjectiveEquivalences.injectivity InjectiveEquivalencesTermLeft refl = reflexivity\n\n-- -- -- -- -- -- instance InjectiveEquivalencesTermRight : ∀ {m : Nat} {l₁ l₂ : Term m} → InjectiveEquivalences _≡_ _≡_ (l₁ fork_) (l₂ fork_)\n-- -- -- -- -- -- InjectiveEquivalences.equivalence₁ InjectiveEquivalencesTermRight = it\n-- -- -- -- -- -- InjectiveEquivalences.equivalence₂ InjectiveEquivalencesTermRight = it\n-- -- -- -- -- -- InjectiveEquivalences.injectivity InjectiveEquivalencesTermRight refl = reflexivity\n\n-- -- -- -- -- -- injectivity' :\n-- -- -- -- -- -- ∀ {a} {A : Set a} {ℓ₁} {_≋₁_ : A → A → Set ℓ₁}\n-- -- -- -- -- -- {b} {B : Set b}\n-- -- -- -- -- -- {f : A → B}\n-- -- -- -- -- -- {g : A → B}\n-- -- -- -- -- -- ⦃ _ : InjectiveEquivalences _≋₁_ _≡_ f g ⦄ →\n-- -- -- -- -- -- ∀ {x y} → f x ≡ g y → x ≋₁ y\n-- -- -- -- -- -- injectivity' x = injectivity {_≋₂_ = _≡_} x\n\n-- -- -- -- -- -- Term-forkLeft-inj' : ∀ {n} {l₁ r₁ l₂ r₂ : Term n} → l₁ fork r₁ ≡ l₂ fork r₂ → l₁ ≡ l₂\n-- -- -- -- -- -- Term-forkLeft-inj' {n} {l₁} {r₁} {l₂} {r₂} x = injectivity' x\n-- -- -- -- -- -- --Term-forkLeft-inj' {n} {l₁} {r₁} {l₂} {r₂} x = injectivity {_≋₂_ = _≡_} x\n-- -- -- -- -- -- -- injectivity {_≋₁_ = {!_≡_!}} {_≋₂_ = {!_≡_!}} ⦃ InjectiveEquivalencesTermLeft ⦄ x\n\n-- -- -- -- -- -- Term-forkRight-inj' : ∀ {n} {l₁ r₁ l₂ r₂ : Term n} → l₁ fork r₁ ≡ l₂ fork r₂ → r₁ ≡ r₂\n-- -- -- -- -- -- Term-forkRight-inj' {n} {l₁} {r₁} {l₂} {r₂} x = injectivity' x\n-- -- -- -- -- -- --Term-forkLeft-inj' {n} {l₁} {r₁} {l₂} {r₂} x = injectivity {_≋₂_ = _≡_} x\n-- -- -- -- -- -- -- injectivity {_≋₁_ = {!_≡_!}} {_≋₂_ = {!_≡_!}} ⦃ InjectiveEquivalencesTermLeft ⦄ x\n", "meta": {"hexsha": "4e5ae00a0481150a83a58bb8c28f505c482ed5aa", "size": 10920, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "archive/agda-2/Oscar/Data/Equality/properties.agda", "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "archive/agda-2/Oscar/Data/Equality/properties.agda", "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_forks_repo_path": "archive/agda-2/Oscar/Data/Equality/properties.agda", "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.5094339623, "max_line_length": 173, "alphanum_fraction": 0.5373626374, "num_tokens": 4123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548511303338, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.37366821368291636}} {"text": "\nmodule _ where\n\nopen import Agda.Builtin.Reflection renaming (bindTC to _>>=_)\nopen import Agda.Builtin.Unit\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Bool\n\n_>>_ : {A B : Set} → TC A → TC B → TC B\nm >> m₁ = m >>= λ _ → m₁\n\ndata Fin : Nat → Set where\n zero : ∀ {n} → Fin (suc n)\n suc : ∀ {n} → Fin n → Fin (suc n)\n\nmacro\n reflectAndCheck : ∀ {a} {A : Set a} → A → Term → TC ⊤\n reflectAndCheck {A = A} x hole = withNormalisation true do\n `x ← quoteTC x\n `A ← quoteTC A\n ``x ← checkType `x `A >>= quoteTC\n unify hole ``x\n\n quoteUnquote : ∀ {a} {A : Set a} → A → Term → TC ⊤\n quoteUnquote x hole = withNormalisation true do\n `x ← quoteTC x\n unify hole `x\n\nmodule _ (n : Nat) (A : Set) (m : Nat) (j : Fin m) where\n\n plam₁ : Fin n → Fin m\n plam₁ = λ where zero → j; (suc i) → j\n\n `plam₁ : Term\n `plam₁ = reflectAndCheck plam₁\n\n plam₁′ : Fin n → Fin m\n plam₁′ = quoteUnquote plam₁\n\n refined₁ : n ≡ suc m → Nat\n refined₁ refl = 0\n where\n plam : Fin n → Fin m\n plam = λ where zero → j; (suc i) → i\n\n `plam : Term\n `plam = reflectAndCheck plam\n\n plam′ : Fin n → Fin m\n plam′ = quoteUnquote plam\n\n refined₂ : m ≡ suc n → Nat\n refined₂ refl = 0\n where\n plam : Fin n → Fin m\n plam = λ where zero → j; (suc i) → suc (suc i)\n\n `plam : Term\n `plam = reflectAndCheck plam\n\n plam′ : Fin n → Fin m\n plam′ = quoteUnquote plam\n", "meta": {"hexsha": "14f6201c2104d4d0750bc04aebd601794065c0f0", "size": 1486, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/QuotePatternLambda.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/Succeed/QuotePatternLambda.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/Succeed/QuotePatternLambda.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": 22.8615384615, "max_line_length": 62, "alphanum_fraction": 0.5807537012, "num_tokens": 556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6224593312018546, "lm_q2_score": 0.600188359260205, "lm_q1q2_score": 0.3735928447002456}} {"text": "--{-# OPTIONS -v tc.pos:100 #-}\n\nopen import Agda.Builtin.Equality\n\ndata ⊥ : Set where\n\npostulate\n A : Set\n R : A → Set\n\nmagic : ⊥ → A\nmagic ()\n\ntest : (a : ⊥) → magic a ≡ magic _\ntest a = refl\n", "meta": {"hexsha": "bbf2eef60d33ce52a5ed19f190ef53f603983ccb", "size": 196, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/AbsurdMatchIsNeutral.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/AbsurdMatchIsNeutral.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/AbsurdMatchIsNeutral.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 12.25, "max_line_length": 34, "alphanum_fraction": 0.5714285714, "num_tokens": 70, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6926419958239132, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3733224136927182}} {"text": "------------------------------------------------------------------------\n-- The two semantical definitions of subtyping are equivalent\n------------------------------------------------------------------------\n\nmodule RecursiveTypes.Subtyping.Semantic.Equivalence where\n\nopen import Data.Nat\nopen import Codata.Musical.Notation\nopen import Function.Base\n\nopen import RecursiveTypes.Syntax\nopen import RecursiveTypes.Subtyping.Semantic.Inductive\nopen import RecursiveTypes.Subtyping.Semantic.Coinductive\n\nmutual\n\n ≤∞⇒≤↓ : ∀ {n} {σ τ : Tree n} → σ ≤∞ τ → σ ≤↓ τ\n ≤∞⇒≤↓ le zero = ⊥\n ≤∞⇒≤↓ ⊥ (suc k) = ⊥\n ≤∞⇒≤↓ ⊤ (suc k) = ⊤\n ≤∞⇒≤↓ var (suc k) = refl\n ≤∞⇒≤↓ (τ₁≤σ₁ ⟶ σ₂≤τ₂) (suc k) = ≤∞⇒≤↑ (♭ τ₁≤σ₁) k ⟶ ≤∞⇒≤↓ (♭ σ₂≤τ₂) k\n\n ≤∞⇒≤↑ : ∀ {n} {σ τ : Tree n} → σ ≤∞ τ → σ ≤↑ τ\n ≤∞⇒≤↑ le zero = ⊤\n ≤∞⇒≤↑ ⊥ (suc k) = ⊥\n ≤∞⇒≤↑ ⊤ (suc k) = ⊤\n ≤∞⇒≤↑ var (suc k) = refl\n ≤∞⇒≤↑ (τ₁≤σ₁ ⟶ σ₂≤τ₂) (suc k) = ≤∞⇒≤↓ (♭ τ₁≤σ₁) k ⟶ ≤∞⇒≤↑ (♭ σ₂≤τ₂) k\n\ndomain : ∀ {n} {σ₁ σ₂ τ₁ τ₂ : FinTree n} →\n σ₁ ⟶ σ₂ ≤Fin τ₁ ⟶ τ₂ → σ₂ ≤Fin τ₂\ndomain refl = refl\ndomain (τ₁≤σ₁ ⟶ σ₂≤τ₂) = σ₂≤τ₂\n\ncodomain : ∀ {n} {σ₁ σ₂ τ₁ τ₂ : FinTree n} →\n σ₁ ⟶ σ₂ ≤Fin τ₁ ⟶ τ₂ → τ₁ ≤Fin σ₁\ncodomain refl = refl\ncodomain (τ₁≤σ₁ ⟶ σ₂≤τ₂) = τ₁≤σ₁\n\nmutual\n\n ≤↑⇒≤∞ : ∀ {n} (σ τ : Tree n) → σ ≤↑ τ → σ ≤∞ τ\n ≤↑⇒≤∞ ⊥ _ le = ⊥\n ≤↑⇒≤∞ _ ⊤ le = ⊤\n ≤↑⇒≤∞ ⊤ ⊥ le with le 1\n ... | ()\n ≤↑⇒≤∞ ⊤ (var x) le with le 1\n ... | ()\n ≤↑⇒≤∞ ⊤ (σ ⟶ τ) le with le 1\n ... | ()\n ≤↑⇒≤∞ (var x) ⊥ le with le 1\n ... | ()\n ≤↑⇒≤∞ (var x) (var x′) le with le 1\n ≤↑⇒≤∞ (var x) (var .x) le | refl = var\n ≤↑⇒≤∞ (var x) (σ ⟶ τ) le with le 1\n ... | ()\n ≤↑⇒≤∞ (σ₁ ⟶ τ₁) ⊥ le with le 1\n ... | ()\n ≤↑⇒≤∞ (σ₁ ⟶ τ₁) (var x) le with le 1\n ... | ()\n ≤↑⇒≤∞ (σ₁ ⟶ τ₁) (σ₂ ⟶ τ₂) le =\n ♯ ≤↓⇒≤∞ (♭ σ₂) (♭ σ₁) (codomain ∘ le ∘ suc) ⟶\n ♯ ≤↑⇒≤∞ (♭ τ₁) (♭ τ₂) (domain ∘ le ∘ suc)\n\n ≤↓⇒≤∞ : ∀ {n} (σ τ : Tree n) → σ ≤↓ τ → σ ≤∞ τ\n ≤↓⇒≤∞ ⊥ _ le = ⊥\n ≤↓⇒≤∞ _ ⊤ le = ⊤\n ≤↓⇒≤∞ ⊤ ⊥ le with le 1\n ... | ()\n ≤↓⇒≤∞ ⊤ (var x) le with le 1\n ... | ()\n ≤↓⇒≤∞ ⊤ (σ ⟶ τ) le with le 1\n ... | ()\n ≤↓⇒≤∞ (var x) ⊥ le with le 1\n ... | ()\n ≤↓⇒≤∞ (var x) (var x′) le with le 1\n ≤↓⇒≤∞ (var x) (var .x) le | refl = var\n ≤↓⇒≤∞ (var x) (σ ⟶ τ) le with le 1\n ... | ()\n ≤↓⇒≤∞ (σ₁ ⟶ τ₁) ⊥ le with le 1\n ... | ()\n ≤↓⇒≤∞ (σ₁ ⟶ τ₁) (var x) le with le 1\n ... | ()\n ≤↓⇒≤∞ (σ₁ ⟶ τ₁) (σ₂ ⟶ τ₂) le =\n ♯ ≤↑⇒≤∞ (♭ σ₂) (♭ σ₁) (codomain ∘ le ∘ suc) ⟶\n ♯ ≤↓⇒≤∞ (♭ τ₁) (♭ τ₂) (domain ∘ le ∘ suc)\n\nInd⇒Coind : ∀ {n} {σ τ : Ty n} → σ ≤Ind τ → σ ≤Coind τ\nInd⇒Coind = ≤↓⇒≤∞ _ _\n\nCoind⇒Ind : ∀ {n} {σ τ : Ty n} → σ ≤Coind τ → σ ≤Ind τ\nCoind⇒Ind = ≤∞⇒≤↓\n", "meta": {"hexsha": "a13e0384d1bdb73931e1214f63f79f45adb1d24f", "size": 2715, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "RecursiveTypes/Subtyping/Semantic/Equivalence.agda", "max_stars_repo_name": "nad/codata", "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_issues_repo_path": "RecursiveTypes/Subtyping/Semantic/Equivalence.agda", "max_issues_repo_name": "nad/codata", "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": "RecursiveTypes/Subtyping/Semantic/Equivalence.agda", "max_forks_repo_name": "nad/codata", "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": 28.8829787234, "max_line_length": 72, "alphanum_fraction": 0.3786372007, "num_tokens": 1551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419831347362, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.37332240685346474}} {"text": "module cfg1 where\n\nopen import Level renaming ( suc to succ ; zero to Zero )\nopen import Data.Nat hiding ( _≟_ )\n-- open import Data.Fin\n-- open import Data.Product\nopen import Data.List\nopen import Data.Maybe\n-- open import Data.Bool using ( Bool ; true ; false ; _∧_ ; _∨_ )\nopen import Relation.Binary.PropositionalEquality hiding ( [_] )\nopen import Relation.Nullary using (¬_; Dec; yes; no)\nopen import logic\n\n--\n-- Java → Java Byte Code\n--\n-- CFG Stack Machine (PDA)\n--\n\n\ndata Node (Symbol : Set) : Set where\n T : Symbol → Node Symbol \n N : Symbol → Node Symbol \n\ndata Seq (Symbol : Set) : Set where\n _,_ : Symbol → Seq Symbol → Seq Symbol \n _. : Symbol → Seq Symbol \n Error : Seq Symbol \n\ndata Body (Symbol : Set) : Set where\n _|_ : Seq Symbol → Body Symbol → Body Symbol \n _; : Seq Symbol → Body Symbol \n\nrecord CFGGrammer (Symbol : Set) : Set where\n field\n cfg : Symbol → Body Symbol \n top : Symbol\n eq? : Symbol → Symbol → Bool\n typeof : Symbol → Node Symbol\n\ninfixr 80 _|_\ninfixr 90 _;\ninfixr 100 _,_\ninfixr 110 _.\n\nopen CFGGrammer \n\n-----------------\n--\n-- CGF language\n--\n-----------------\n\nsplit : {Σ : Set} → (List Σ → Bool)\n → ( List Σ → Bool) → List Σ → Bool\nsplit x y [] = x [] /\\ y []\nsplit x y (h ∷ t) = (x [] /\\ y (h ∷ t)) \\/\n split (λ t1 → x ( h ∷ t1 )) (λ t2 → y t2 ) t\n\n\ncfg-language0 : {Symbol : Set} → CFGGrammer Symbol → Body Symbol → List Symbol → Bool\n\n{-# TERMINATING #-}\ncfg-language1 : {Symbol : Set} → CFGGrammer Symbol → Seq Symbol → List Symbol → Bool\ncfg-language1 cg Error x = false\ncfg-language1 cg (S , seq) x with typeof cg S\ncfg-language1 cg (_ , seq) (x' ∷ t) | T x = eq? cg x x' /\\ cfg-language1 cg seq t\ncfg-language1 cg (_ , seq) [] | T x = false\ncfg-language1 cg (_ , seq) x | N nonTerminal = split (cfg-language0 cg (cfg cg nonTerminal) )(cfg-language1 cg seq ) x\ncfg-language1 cg (S .) x with typeof cg S\ncfg-language1 cg (_ .) (x' ∷ []) | T x = eq? cg x x'\ncfg-language1 cg (_ .) _ | T x = false\ncfg-language1 cg (_ .) x | N nonTerminal = cfg-language0 cg (cfg cg nonTerminal) x\n\ncfg-language0 cg _ [] = false\ncfg-language0 cg (rule | b) x =\n cfg-language1 cg rule x \\/ cfg-language0 cg b x \ncfg-language0 cg (rule ;) x = cfg-language1 cg rule x \n\ncfg-language : {Symbol : Set} → CFGGrammer Symbol → List Symbol → Bool\ncfg-language cg = cfg-language0 cg (cfg cg (top cg )) \n\n\ndata IFToken : Set where\n EA : IFToken\n EB : IFToken\n EC : IFToken\n IF : IFToken\n THEN : IFToken\n ELSE : IFToken\n SA : IFToken\n SB : IFToken\n SC : IFToken\n expr : IFToken\n statement : IFToken\n\ntoken-eq? : IFToken → IFToken → Bool\ntoken-eq? EA EA = true\ntoken-eq? EB EB = true\ntoken-eq? EC EC = true\ntoken-eq? IF IF = true\ntoken-eq? THEN THEN = true\ntoken-eq? ELSE ELSE = true\ntoken-eq? SA SA = true\ntoken-eq? SB SB = true\ntoken-eq? SC SC = true\ntoken-eq? expr expr = true\ntoken-eq? statement statement = true\ntoken-eq? _ _ = false\n\ntypeof-IFG : IFToken → Node IFToken \ntypeof-IFG expr = N expr\ntypeof-IFG statement = N statement\ntypeof-IFG x = T x\n\nIFGrammer : CFGGrammer IFToken \nIFGrammer = record {\n cfg = cfg'\n ; top = statement\n ; eq? = token-eq?\n ; typeof = typeof-IFG \n } where\n cfg' : IFToken → Body IFToken \n cfg' expr = EA . | EB . | EC . ; \n cfg' statement = \n SA . | SB . | SC .\n | IF , expr , THEN , statement .\n | IF , expr , THEN , statement , ELSE , statement .\n ; \n cfg' x = Error ; \n\ncfgtest1 = cfg-language IFGrammer ( SA ∷ [] ) \n\ncfgtest2 = cfg-language1 IFGrammer ( SA .) ( SA ∷ [] ) \n\ncfgtest3 = cfg-language1 IFGrammer ( SA . ) ( SA ∷ [] ) \n\ncfgtest4 = cfg-language IFGrammer (IF ∷ EA ∷ THEN ∷ SA ∷ [] ) \n\ncfgtest5 = cfg-language1 IFGrammer ( IF , expr , THEN , statement . ) (IF ∷ EA ∷ THEN ∷ SA ∷ [] ) \ncfgtest6 = cfg-language1 IFGrammer ( statement .)(IF ∷ EA ∷ SA ∷ [] ) \ncfgtest7 = cfg-language1 IFGrammer ( IF , expr , THEN , statement , ELSE , statement . )\n (IF ∷ EA ∷ THEN ∷ SA ∷ ELSE ∷ SB ∷ [] ) \ncfgtest8 = cfg-language IFGrammer (IF ∷ EA ∷ THEN ∷ IF ∷ EB ∷ THEN ∷ SA ∷ ELSE ∷ SB ∷ [] ) \ncfgtest9 = cfg-language IFGrammer (IF ∷ EB ∷ THEN ∷ SA ∷ ELSE ∷ SB ∷ [] ) \n\ndata E1Token : Set where\n e1 : E1Token\n e[ : E1Token\n e] : E1Token\n expr : E1Token\n term : E1Token\n\nE1-token-eq? : E1Token → E1Token → Bool\nE1-token-eq? e1 e1 = true\nE1-token-eq? e[ e] = true\nE1-token-eq? e] e] = true\nE1-token-eq? expr expr = true\nE1-token-eq? term term = true\nE1-token-eq? _ _ = false\n\ntypeof-E1 : E1Token → Node E1Token\ntypeof-E1 expr = N expr\ntypeof-E1 term = N term\ntypeof-E1 x = T x\n\nE1Grammer : CFGGrammer E1Token\nE1Grammer = record {\n cfg = cfgE\n ; top = expr\n ; eq? = E1-token-eq?\n ; typeof = typeof-E1\n } where\n cfgE : E1Token → Body E1Token\n cfgE expr = term .\n ;\n cfgE term = e1 .\n | e[ , expr , e] .\n ;\n cfgE x = Error ;\n\necfgtest1 = cfg-language E1Grammer ( e1 ∷ [] )\necfgtest2 = cfg-language E1Grammer ( e[ ∷ e1 ∷ e] ∷ [] )\necfgtest3 = cfg-language E1Grammer ( e[ ∷ e[ ∷ e1 ∷ e] ∷ e] ∷ [] )\necfgtest4 = cfg-language E1Grammer ( e[ ∷ e1 ∷ [] )\n\nopen import Function\n\nleft : {t : Set } → List E1Token → ( fail next : List E1Token → t ) → t\nleft ( e[ ∷ t ) fail next = next t\nleft t fail next = fail t \n\nright : {t : Set } → List E1Token → ( fail next : List E1Token → t ) → t\nright ( e] ∷ t ) fail next = next t\nright t fail next = fail t \n\n\n{-# TERMINATING #-}\nexpr1 : {t : Set } → List E1Token → ( fail next : List E1Token → t ) → t\nexpr1 ( e1 ∷ t ) fail next = next t\nexpr1 ( expr ∷ t ) fail next = next t\nexpr1 ( term ∷ t ) fail next = next t\nexpr1 x fail next = left x fail $ λ x → expr1 x fail $ λ x → right x fail $ next\n-- expr1 x fail next = left x fail ( λ x → expr1 x fail ( λ x → right x fail ( next )))\n\ncfgtest01 = expr1 ( e[ ∷ e[ ∷ e1 ∷ e] ∷ e] ∷ [] ) (λ x → ⟪ false , x ⟫ ) (λ x → ⟪ true , x ⟫ ) \ncfgtest02 = expr1 ( e[ ∷ e[ ∷ e1 ∷ e] ∷ [] ) (λ x → ⟪ false , x ⟫ ) (λ x → ⟪ true , x ⟫ )\ncfgtest03 = expr1 ( e[ ∷ e[ ∷ e1 ∷ e] ∷ e] ∷ e] ∷ [] ) (λ x → ⟪ false , x ⟫ ) (λ x → ⟪ true , x ⟫ )\n\nopen import pushdown\n\ndata CG1 : Set where\n ce : CG1\n c1 : CG1\n\npd : CG1 → E1Token → CG1 → CG1 ∧ PushDown CG1\npd c1 e[ s = ⟪ c1 , push c1 ⟫\npd c1 e] c1 = ⟪ c1 , pop ⟫\npd c1 e1 c1 = ⟪ c1 , none ⟫\npd s expr s1 = ⟪ c1 , none ⟫\npd s term s1 = ⟪ c1 , none ⟫\npd s _ s1 = ⟪ ce , none ⟫\n\npok : CG1 → Bool\npok c1 = true\npok s = false\n\npnc : PushDownAutomaton CG1 E1Token CG1\npnc = record {\n pδ = pd\n ; pempty = ce\n ; pok = pok\n } \n\npda-ce-test1 = PushDownAutomaton.paccept pnc c1 ( e[ ∷ e[ ∷ e1 ∷ e] ∷ e] ∷ [] ) []\npda-ce-test2 = PushDownAutomaton.paccept pnc c1 ( e[ ∷ e[ ∷ e1 ∷ e] ∷ [] ) []\npda-ce-test3 = PushDownAutomaton.paccept pnc c1 ( e[ ∷ e1 ∷ e] ∷ e1 ∷ [] ) []\n\nrecord PNC (accept : Bool ) : Set where\n field\n orig-x : List E1Token\n pnc-q : CG1\n pnc-st : List CG1\n pnc-p : CG1 → List CG1 → Bool \n success : accept ≡ true → pnc-p pnc-q pnc-st ≡ true → PushDownAutomaton.paccept pnc c1 orig-x [] ≡ true\n failure : accept ≡ false → pnc-p pnc-q pnc-st ≡ false → PushDownAutomaton.paccept pnc c1 orig-x [] ≡ false\n\nopen import Data.Unit\n\n{-# TERMINATING #-}\nexpr1P : {n : Level } {t : Set n } → (x : List E1Token ) → PNC true \n → ( fail : List E1Token → PNC false → t ) → ( next : List E1Token → PNC true → t ) → t\nexpr1P x _ _ _ = {!!}\n\nexpr1P-test : (x : List E1Token ) → ⊤\nexpr1P-test x = expr1P x record { orig-x = x ; pnc-q = c1 ; pnc-st = []\n ; pnc-p = λ q st → PushDownAutomaton.paccept pnc q x st ; success = λ _ p → p ; failure = λ _ p → p }\n (λ x p → {!!} ) (λ x p → {!!} )\n\n----\n--\n-- CFG to PDA\n--\n\ncfg→pda-state : {Symbol : Set} → CFGGrammer Symbol → Set \ncfg→pda-state cfg = {!!}\n\ncfg→pda-start : {Symbol : Set} → (cfg : CFGGrammer Symbol) → cfg→pda-state cfg\ncfg→pda-start cfg = {!!}\n\ncfg→pda : {Symbol : Set} → (cfg : CFGGrammer Symbol) → PDA (cfg→pda-state cfg) Symbol (cfg→pda-state cfg)\ncfg→pda cfg = {!!}\n\ncfg->pda : {Symbol : Set} → (input : List Symbol)\n → (cfg : CFGGrammer Symbol)\n → PDA.paccept (cfg→pda cfg ) (cfg→pda-start cfg) input [] ≡ cfg-language cfg input\ncfg->pda = {!!}\n\n----\n--\n-- PDA to CFG \n--\nopen import pushdown\n\npda→cfg : {Symbol : Set} { Q : Set} → (pda : PDA Q Symbol Q) → CFGGrammer Symbol\npda→cfg pda = record {\n cfg = {!!}\n ; top = {!!}\n ; eq? = {!!}\n ; typeof = {!!}\n } \n\npda->cfg : {Symbol : Set} { Q : Set} → (start : Q) → (input : List Symbol)\n → (pda : PDA Q Symbol Q)\n → PDA.paccept pda start input [] ≡ cfg-language (pda→cfg pda) input\npda->cfg = {!!}\n\nrecord CDGGrammer (Symbol : Set) : Set where\n field\n cdg : Seq Symbol → Body Symbol \n top : Symbol\n eq? : Symbol → Symbol → Bool\n typeof : Symbol → Node Symbol\n\n", "meta": {"hexsha": "5ac732363ae45c4f9aeb13649a216d54de451115", "size": 8934, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/cfg1.agda", "max_stars_repo_name": "shinji-kono/automaton-in-agda", "max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "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/cfg1.agda", "max_issues_repo_name": "shinji-kono/automaton-in-agda", "max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "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/cfg1.agda", "max_forks_repo_name": "shinji-kono/automaton-in-agda", "max_forks_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "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": 29.2918032787, "max_line_length": 118, "alphanum_fraction": 0.5688381464, "num_tokens": 3356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3733224068534647}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Basics\nopen import lib.NConnected\nopen import lib.types.Empty\nopen import lib.types.Nat\nopen import lib.types.Paths\nopen import lib.types.Pi\nopen import lib.types.Pointed\nopen import lib.types.Sigma\nopen import lib.types.TLevel\nopen import lib.types.Truncation\n\nmodule lib.types.LoopSpace where\n\n{- loop space -}\n\nmodule _ {i} where\n\n ⊙Ω : Ptd i → Ptd i\n ⊙Ω ⊙[ A , a ] = ⊙[ (a == a) , idp ]\n\n Ω : Ptd i → Type i\n Ω = de⊙ ∘ ⊙Ω\n\nmodule _ {i} {X : Ptd i} where\n\n Ω-! : Ω X → Ω X\n Ω-! = !\n\n Ω-∙ : Ω X → Ω X → Ω X\n Ω-∙ = _∙_\n\n{- pointed versions of functions on paths -}\n\n⊙Ω-∙ : ∀ {i} {X : Ptd i} → ⊙Ω X ⊙× ⊙Ω X ⊙→ ⊙Ω X\n⊙Ω-∙ = (uncurry Ω-∙ , idp)\n\n⊙Ω-fmap : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → X ⊙→ Y → ⊙Ω X ⊙→ ⊙Ω Y\n⊙Ω-fmap (f , idp) = ap f , idp\n\nΩ-fmap : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → X ⊙→ Y → (Ω X → Ω Y)\nΩ-fmap F = fst (⊙Ω-fmap F)\n\nΩ-fmap-β : ∀ {i j} {X : Ptd i} {Y : Ptd j} (F : X ⊙→ Y) (p : Ω X)\n → Ω-fmap F p == ! (snd F) ∙ ap (fst F) p ∙' snd F\nΩ-fmap-β (_ , idp) _ = idp\n\nΩ-isemap : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n (F : X ⊙→ Y) → is-equiv (fst F) → is-equiv (Ω-fmap F)\nΩ-isemap (f , idp) e = ap-is-equiv e _ _\n\nΩ-emap : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → (X ⊙≃ Y) → (Ω X ≃ Ω Y)\nΩ-emap (F , F-is-equiv) = Ω-fmap F , Ω-isemap F F-is-equiv\n\n⊙Ω-emap : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → (X ⊙≃ Y) → (⊙Ω X ⊙≃ ⊙Ω Y)\n⊙Ω-emap (F , F-is-equiv) = ⊙Ω-fmap F , Ω-isemap F F-is-equiv\n\n⊙Ω-fmap2 : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n → X ⊙× Y ⊙→ Z → ⊙Ω X ⊙× ⊙Ω Y ⊙→ ⊙Ω Z\n⊙Ω-fmap2 (f , idp) = (λ{(p , q) → ap2 (curry f) p q}) , idp\n\n⊙Ω-fmap-∘ : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n (g : Y ⊙→ Z) (f : X ⊙→ Y)\n → ⊙Ω-fmap (g ⊙∘ f) == ⊙Ω-fmap g ⊙∘ ⊙Ω-fmap f\n⊙Ω-fmap-∘ (g , idp) (f , idp) = ⊙λ=' (λ p → ap-∘ g f p) idp\n\n⊙Ω-csmap : ∀ {i₀ i₁ j₀ j₁} {X₀ : Ptd i₀} {X₁ : Ptd i₁}\n {Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}\n {hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}\n → ⊙CommSquare f g hX hY\n → ⊙CommSquare (⊙Ω-fmap f) (⊙Ω-fmap g) (⊙Ω-fmap hX) (⊙Ω-fmap hY)\n⊙Ω-csmap {f = f} {g} {hX} {hY} (⊙comm-sqr cs) = ⊙comm-sqr $ ⊙app= $\n ⊙Ω-fmap hY ⊙∘ ⊙Ω-fmap f\n =⟨ ! $ ⊙Ω-fmap-∘ hY f ⟩\n ⊙Ω-fmap (hY ⊙∘ f)\n =⟨ ap ⊙Ω-fmap $ ⊙λ= cs ⟩\n ⊙Ω-fmap (g ⊙∘ hX)\n =⟨ ⊙Ω-fmap-∘ g hX ⟩\n ⊙Ω-fmap g ⊙∘ ⊙Ω-fmap hX\n =∎\n\n⊙Ω-csemap : ∀ {i₀ i₁ j₀ j₁} {X₀ : Ptd i₀} {X₁ : Ptd i₁}\n {Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}\n {hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}\n → ⊙CommSquareEquiv f g hX hY\n → ⊙CommSquareEquiv (⊙Ω-fmap f) (⊙Ω-fmap g) (⊙Ω-fmap hX) (⊙Ω-fmap hY)\n⊙Ω-csemap {f = f} {g} {hX} {hY} (⊙comm-sqr cs , hX-ise , hY-ise) =\n (⊙comm-sqr $ ⊙app= $\n ⊙Ω-fmap hY ⊙∘ ⊙Ω-fmap f\n =⟨ ! $ ⊙Ω-fmap-∘ hY f ⟩\n ⊙Ω-fmap (hY ⊙∘ f)\n =⟨ ap ⊙Ω-fmap $ ⊙λ= cs ⟩\n ⊙Ω-fmap (g ⊙∘ hX)\n =⟨ ⊙Ω-fmap-∘ g hX ⟩\n ⊙Ω-fmap g ⊙∘ ⊙Ω-fmap hX\n =∎) ,\n Ω-isemap hX hX-ise , Ω-isemap hY hY-ise\n\n⊙Ω-fmap-idf : ∀ {i} {X : Ptd i} → ⊙Ω-fmap (⊙idf X) == ⊙idf _\n⊙Ω-fmap-idf = ⊙λ=' ap-idf idp\n\n⊙Ω-fmap2-fst : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → ⊙Ω-fmap2 {X = X} {Y = Y} ⊙fst == ⊙fst\n⊙Ω-fmap2-fst = ⊙λ=' (uncurry ap2-fst) idp\n\n⊙Ω-fmap2-snd : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → ⊙Ω-fmap2 {X = X} {Y = Y} ⊙snd == ⊙snd\n⊙Ω-fmap2-snd = ⊙λ=' (uncurry ap2-snd) idp\n\n⊙Ω-fmap-fmap2 : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}\n (G : Z ⊙→ W) (F : X ⊙× Y ⊙→ Z)\n → ⊙Ω-fmap G ⊙∘ ⊙Ω-fmap2 F == ⊙Ω-fmap2 (G ⊙∘ F)\n⊙Ω-fmap-fmap2 (g , idp) (f , idp) =\n ⊙λ=' (uncurry (ap-ap2 g (curry f))) idp\n\n⊙Ω-fmap2-fmap : ∀ {i j k l m}\n {X : Ptd i} {Y : Ptd j} {U : Ptd k} {V : Ptd l} {Z : Ptd m}\n (G : (U ⊙× V) ⊙→ Z) (F₁ : X ⊙→ U) (F₂ : Y ⊙→ V)\n → ⊙Ω-fmap2 G ⊙∘ ⊙×-fmap (⊙Ω-fmap F₁) (⊙Ω-fmap F₂) == ⊙Ω-fmap2 (G ⊙∘ ⊙×-fmap F₁ F₂)\n⊙Ω-fmap2-fmap (g , idp) (f₁ , idp) (f₂ , idp) =\n ⊙λ=' (λ {(p , q) → ap2-ap-l (curry g) f₁ p (ap f₂ q)\n ∙ ap2-ap-r (λ x v → g (f₁ x , v)) f₂ p q})\n idp\n\n⊙Ω-fmap2-diag : ∀ {i j} {X : Ptd i} {Y : Ptd j} (F : X ⊙× X ⊙→ Y)\n → ⊙Ω-fmap2 F ⊙∘ ⊙diag == ⊙Ω-fmap (F ⊙∘ ⊙diag)\n⊙Ω-fmap2-diag (f , idp) = ⊙λ=' (ap2-diag (curry f)) idp\n\n{- iterated loop spaces. [Ω^] and [Ω^'] iterates [Ω] from different sides:\n [Ω^ (S n) X = Ω (Ω^ n X)] and [Ω^' (S n) X = Ω^' n (Ω X)]. -}\n\nmodule _ {i} where\n\n ⊙Ω^ : (n : ℕ) → Ptd i → Ptd i\n ⊙Ω^ O X = X\n ⊙Ω^ (S n) X = ⊙Ω (⊙Ω^ n X)\n\n Ω^ : (n : ℕ) → Ptd i → Type i\n Ω^ n X = de⊙ (⊙Ω^ n X)\n\n ⊙Ω^' : (n : ℕ) → Ptd i → Ptd i\n ⊙Ω^' O X = X\n ⊙Ω^' (S n) X = (⊙Ω^' n (⊙Ω X))\n\n Ω^' : (n : ℕ) → Ptd i → Type i\n Ω^' n X = de⊙ (⊙Ω^' n X)\n\n{- [⊙Ω^-fmap] and [⊙Ω^-fmap2] for higher loop spaces -}\n\n⊙Ω^-fmap : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → X ⊙→ Y → ⊙Ω^ n X ⊙→ ⊙Ω^ n Y\n⊙Ω^-fmap O F = F\n⊙Ω^-fmap (S n) F = ⊙Ω-fmap (⊙Ω^-fmap n F)\n\nΩ^-fmap : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → X ⊙→ Y → (de⊙ (⊙Ω^ n X) → de⊙ (⊙Ω^ n Y))\nΩ^-fmap n F = fst (⊙Ω^-fmap n F)\n\n⊙Ω^-csmap : ∀ {i₀ i₁ j₀ j₁} (n : ℕ) {X₀ : Ptd i₀} {X₁ : Ptd i₁}\n {Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}\n {hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}\n → ⊙CommSquare f g hX hY\n → ⊙CommSquare (⊙Ω^-fmap n f) (⊙Ω^-fmap n g) (⊙Ω^-fmap n hX) (⊙Ω^-fmap n hY)\n⊙Ω^-csmap O cs = cs\n⊙Ω^-csmap (S n) cs = ⊙Ω-csmap (⊙Ω^-csmap n cs)\n\n⊙Ω^'-fmap : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → X ⊙→ Y → ⊙Ω^' n X ⊙→ ⊙Ω^' n Y\n⊙Ω^'-fmap O F = F\n⊙Ω^'-fmap (S n) F = ⊙Ω^'-fmap n (⊙Ω-fmap F)\n\n⊙Ω^'-csmap : ∀ {i₀ i₁ j₀ j₁} (n : ℕ) {X₀ : Ptd i₀} {X₁ : Ptd i₁}\n {Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}\n {hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}\n → ⊙CommSquare f g hX hY\n → ⊙CommSquare (⊙Ω^'-fmap n f) (⊙Ω^'-fmap n g) (⊙Ω^'-fmap n hX) (⊙Ω^'-fmap n hY)\n⊙Ω^'-csmap O cs = cs\n⊙Ω^'-csmap (S n) cs = ⊙Ω^'-csmap n (⊙Ω-csmap cs)\n\nΩ^'-fmap : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → X ⊙→ Y → (de⊙ (⊙Ω^' n X) → de⊙ (⊙Ω^' n Y))\nΩ^'-fmap n F = fst (⊙Ω^'-fmap n F)\n\n⊙Ω^-fmap2 : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n → ((X ⊙× Y) ⊙→ Z)\n → ((⊙Ω^ n X ⊙× ⊙Ω^ n Y) ⊙→ ⊙Ω^ n Z)\n⊙Ω^-fmap2 O F = F\n⊙Ω^-fmap2 (S n) F = ⊙Ω-fmap2 (⊙Ω^-fmap2 n F)\n\nΩ^-fmap2 : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n → ((X ⊙× Y) ⊙→ Z)\n → ((Ω^ n X) × (Ω^ n Y) → Ω^ n Z)\nΩ^-fmap2 n F = fst (⊙Ω^-fmap2 n F)\n\n⊙Ω^'-fmap2 : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n → ((X ⊙× Y) ⊙→ Z)\n → ((⊙Ω^' n X ⊙× ⊙Ω^' n Y) ⊙→ ⊙Ω^' n Z)\n⊙Ω^'-fmap2 O F = F\n⊙Ω^'-fmap2 (S n) F = ⊙Ω^'-fmap2 n (⊙Ω-fmap2 F)\n\nΩ^'-fmap2 : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n → ((X ⊙× Y) ⊙→ Z)\n → ((Ω^' n X) × (Ω^' n Y) → Ω^' n Z)\nΩ^'-fmap2 n F = fst (⊙Ω^'-fmap2 n F)\n\n⊙Ω^-fmap-∘ : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n (g : Y ⊙→ Z) (f : X ⊙→ Y)\n → ⊙Ω^-fmap n (g ⊙∘ f) == ⊙Ω^-fmap n g ⊙∘ ⊙Ω^-fmap n f\n⊙Ω^-fmap-∘ O _ _ = idp\n⊙Ω^-fmap-∘ (S n) g f = ap ⊙Ω-fmap (⊙Ω^-fmap-∘ n g f)\n ∙ ⊙Ω-fmap-∘ (⊙Ω^-fmap n g) (⊙Ω^-fmap n f)\n\n⊙Ω^-fmap-idf : ∀ {i} (n : ℕ) {X : Ptd i} → ⊙Ω^-fmap n (⊙idf X) == ⊙idf _\n⊙Ω^-fmap-idf O = idp\n⊙Ω^-fmap-idf (S n) = ap ⊙Ω-fmap (⊙Ω^-fmap-idf n) ∙ ⊙Ω-fmap-idf\n\nΩ^-fmap-idf : ∀ {i} (n : ℕ) {X : Ptd i} → Ω^-fmap n (⊙idf X) == idf _\nΩ^-fmap-idf n = fst= $ ⊙Ω^-fmap-idf n\n\n⊙Ω^'-fmap-idf : ∀ {i} (n : ℕ) {X : Ptd i} → ⊙Ω^'-fmap n (⊙idf X) == ⊙idf _\n⊙Ω^'-fmap-idf O = idp\n⊙Ω^'-fmap-idf (S n) = ap (⊙Ω^'-fmap n) ⊙Ω-fmap-idf ∙ ⊙Ω^'-fmap-idf n\n\nΩ^'-fmap-idf : ∀ {i} (n : ℕ) {X : Ptd i} → Ω^'-fmap n (⊙idf X) == idf _\nΩ^'-fmap-idf n = fst= $ ⊙Ω^'-fmap-idf n\n\n⊙Ω^-fmap-fmap2 : ∀ {i j k l} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}\n (G : Z ⊙→ W) (F : (X ⊙× Y) ⊙→ Z)\n → ⊙Ω^-fmap n G ⊙∘ ⊙Ω^-fmap2 n F == ⊙Ω^-fmap2 n (G ⊙∘ F)\n⊙Ω^-fmap-fmap2 O G F = idp\n⊙Ω^-fmap-fmap2 (S n) G F = ⊙Ω-fmap-fmap2 (⊙Ω^-fmap n G) (⊙Ω^-fmap2 n F) ∙ ap ⊙Ω-fmap2 (⊙Ω^-fmap-fmap2 n G F)\n\nΩ^-fmap-fmap2 : ∀ {i j k l} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}\n (G : Z ⊙→ W) (F : (X ⊙× Y) ⊙→ Z)\n → Ω^-fmap n G ∘ Ω^-fmap2 n F == Ω^-fmap2 n (G ⊙∘ F)\nΩ^-fmap-fmap2 n G F = fst= $ ⊙Ω^-fmap-fmap2 n G F\n\n⊙Ω^-fmap2-fst : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → ⊙Ω^-fmap2 n {X} {Y} ⊙fst == ⊙fst\n⊙Ω^-fmap2-fst O = idp\n⊙Ω^-fmap2-fst (S n) = ap ⊙Ω-fmap2 (⊙Ω^-fmap2-fst n) ∙ ⊙Ω-fmap2-fst\n\nΩ^-fmap2-fst : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → Ω^-fmap2 n {X} {Y} ⊙fst == fst\nΩ^-fmap2-fst n = fst= $ ⊙Ω^-fmap2-fst n\n\n⊙Ω^-fmap2-snd : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → ⊙Ω^-fmap2 n {X} {Y} ⊙snd == ⊙snd\n⊙Ω^-fmap2-snd O = idp\n⊙Ω^-fmap2-snd (S n) = ap ⊙Ω-fmap2 (⊙Ω^-fmap2-snd n) ∙ ⊙Ω-fmap2-snd\n\nΩ^-fmap2-snd : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → Ω^-fmap2 n {X} {Y} ⊙snd == snd\nΩ^-fmap2-snd n = fst= $ ⊙Ω^-fmap2-snd n\n\n⊙Ω^-fmap2-fmap : ∀ {i j k l m} (n : ℕ)\n {X : Ptd i} {Y : Ptd j} {U : Ptd k} {V : Ptd l} {Z : Ptd m}\n (G : (U ⊙× V) ⊙→ Z) (F₁ : X ⊙→ U) (F₂ : Y ⊙→ V)\n → ⊙Ω^-fmap2 n G ⊙∘ ⊙×-fmap (⊙Ω^-fmap n F₁) (⊙Ω^-fmap n F₂) == ⊙Ω^-fmap2 n (G ⊙∘ ⊙×-fmap F₁ F₂)\n⊙Ω^-fmap2-fmap O G F₁ F₂ = idp\n⊙Ω^-fmap2-fmap (S n) G F₁ F₂ =\n ⊙Ω-fmap2-fmap (⊙Ω^-fmap2 n G) (⊙Ω^-fmap n F₁) (⊙Ω^-fmap n F₂) ∙ ap ⊙Ω-fmap2 (⊙Ω^-fmap2-fmap n G F₁ F₂)\n\nΩ^-fmap2-fmap : ∀ {i j k l m} (n : ℕ)\n {X : Ptd i} {Y : Ptd j} {U : Ptd k} {V : Ptd l} {Z : Ptd m}\n (G : (U ⊙× V) ⊙→ Z) (F₁ : X ⊙→ U) (F₂ : Y ⊙→ V)\n → Ω^-fmap2 n G ∘ ×-fmap (Ω^-fmap n F₁) (Ω^-fmap n F₂) == Ω^-fmap2 n (G ⊙∘ ⊙×-fmap F₁ F₂)\nΩ^-fmap2-fmap n G F₁ F₂ = fst= $ ⊙Ω^-fmap2-fmap n G F₁ F₂\n\n⊙Ω^-fmap2-diag : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} (F : X ⊙× X ⊙→ Y)\n → ⊙Ω^-fmap2 n F ⊙∘ ⊙diag == ⊙Ω^-fmap n (F ⊙∘ ⊙diag)\n⊙Ω^-fmap2-diag O F = idp\n⊙Ω^-fmap2-diag (S n) F = ⊙Ω-fmap2-diag (⊙Ω^-fmap2 n F) ∙ ap ⊙Ω-fmap (⊙Ω^-fmap2-diag n F)\n\nΩ^-fmap2-diag : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} (F : X ⊙× X ⊙→ Y)\n → Ω^-fmap2 n F ∘ diag == Ω^-fmap n (F ⊙∘ ⊙diag)\nΩ^-fmap2-diag n F = fst= $ ⊙Ω^-fmap2-diag n F\n\n{- for n ≥ 1, we have a group structure on the loop space -}\nmodule _ {i} (n : ℕ) {X : Ptd i} where\n\n Ω^S-! : Ω^ (S n) X → Ω^ (S n) X\n Ω^S-! = Ω-!\n\n Ω^S-∙ : Ω^ (S n) X → Ω^ (S n) X → Ω^ (S n) X\n Ω^S-∙ = Ω-∙\n\nmodule _ {i} where\n\n Ω^'S-! : (n : ℕ) {X : Ptd i} → Ω^' (S n) X → Ω^' (S n) X\n Ω^'S-! O = Ω-!\n Ω^'S-! (S n) {X} = Ω^'S-! n {⊙Ω X}\n\n Ω^'S-∙ : (n : ℕ) {X : Ptd i} → Ω^' (S n) X → Ω^' (S n) X → Ω^' (S n) X\n Ω^'S-∙ O = Ω-∙\n Ω^'S-∙ (S n) {X} = Ω^'S-∙ n {⊙Ω X}\n\nidp^ : ∀ {i} (n : ℕ) {X : Ptd i} → Ω^ n X\nidp^ n {X} = pt (⊙Ω^ n X)\n\nidp^' : ∀ {i} (n : ℕ) {X : Ptd i} → Ω^' n X\nidp^' n {X} = pt (⊙Ω^' n X)\n\nmodule _ {i} (n : ℕ) {X : Ptd i} where\n\n {- Prove these as lemmas now\n - so we don't have to deal with the n = O case later -}\n\n Ω^S-∙-unit-l : (q : Ω^ (S n) X)\n → (Ω^S-∙ n (idp^ (S n)) q) == q\n Ω^S-∙-unit-l _ = idp\n\n Ω^S-∙-unit-r : (q : Ω^ (S n) X)\n → (Ω^S-∙ n q (idp^ (S n))) == q\n Ω^S-∙-unit-r = ∙-unit-r\n\n Ω^S-∙-assoc : (p q r : Ω^ (S n) X)\n → Ω^S-∙ n (Ω^S-∙ n p q) r == Ω^S-∙ n p (Ω^S-∙ n q r)\n Ω^S-∙-assoc = ∙-assoc\n\n Ω^S-!-inv-l : (p : Ω^ (S n) X)\n → Ω^S-∙ n (Ω^S-! n p) p == idp^ (S n)\n Ω^S-!-inv-l = !-inv-l\n\n Ω^S-!-inv-r : (p : Ω^ (S n) X)\n → Ω^S-∙ n p (Ω^S-! n p) == idp^ (S n)\n Ω^S-!-inv-r = !-inv-r\n\nmodule _ {i} where\n\n Ω^'S-∙-unit-l : (n : ℕ) {X : Ptd i} (q : Ω^' (S n) X)\n → (Ω^'S-∙ n (idp^' (S n)) q) == q\n Ω^'S-∙-unit-l O _ = idp\n Ω^'S-∙-unit-l (S n) = Ω^'S-∙-unit-l n\n\n Ω^'S-∙-unit-r : (n : ℕ) {X : Ptd i} (q : Ω^' (S n) X)\n → (Ω^'S-∙ n q (idp^' (S n))) == q\n Ω^'S-∙-unit-r O = ∙-unit-r\n Ω^'S-∙-unit-r (S n) = Ω^'S-∙-unit-r n\n\n Ω^'S-∙-assoc : (n : ℕ) {X : Ptd i} (p q r : Ω^' (S n) X)\n → Ω^'S-∙ n (Ω^'S-∙ n p q) r == Ω^'S-∙ n p (Ω^'S-∙ n q r)\n Ω^'S-∙-assoc O = ∙-assoc\n Ω^'S-∙-assoc (S n) = Ω^'S-∙-assoc n\n\n Ω^'S-!-inv-l : (n : ℕ) {X : Ptd i} (p : Ω^' (S n) X)\n → Ω^'S-∙ n (Ω^'S-! n p) p == idp^' (S n)\n Ω^'S-!-inv-l O = !-inv-l\n Ω^'S-!-inv-l (S n) = Ω^'S-!-inv-l n\n\n Ω^'S-!-inv-r : (n : ℕ) {X : Ptd i} (p : Ω^' (S n) X)\n → Ω^'S-∙ n p (Ω^'S-! n p) == idp^' (S n)\n Ω^'S-!-inv-r O = !-inv-r\n Ω^'S-!-inv-r (S n) = Ω^'S-!-inv-r n\n\nmodule _ where\n Ω-fmap-∙ : ∀ {i j} {X : Ptd i} {Y : Ptd j} (F : X ⊙→ Y) (p q : Ω X)\n → Ω-fmap F (p ∙ q) == Ω-fmap F p ∙ Ω-fmap F q\n Ω-fmap-∙ (f , idp) p q = ap-∙ f p q\n\n Ω^S-fmap-∙ : ∀ {i j} (n : ℕ)\n {X : Ptd i} {Y : Ptd j} (F : X ⊙→ Y) (p q : Ω^ (S n) X)\n → Ω^-fmap (S n) F (Ω^S-∙ n p q)\n == Ω^S-∙ n (Ω^-fmap (S n) F p) (Ω^-fmap (S n) F q)\n Ω^S-fmap-∙ n F = Ω-fmap-∙ (⊙Ω^-fmap n F)\n\n Ω^'S-fmap-∙ : ∀ {i j} (n : ℕ)\n {X : Ptd i} {Y : Ptd j} (F : X ⊙→ Y) (p q : Ω^' (S n) X)\n → Ω^'-fmap (S n) F (Ω^'S-∙ n p q)\n == Ω^'S-∙ n (Ω^'-fmap (S n) F p) (Ω^'-fmap (S n) F q)\n Ω^'S-fmap-∙ O = Ω-fmap-∙\n Ω^'S-fmap-∙ (S n) F = Ω^'S-fmap-∙ n (⊙Ω-fmap F)\n\n{- [Ω^] preserves (pointed) equivalences -}\nmodule _ {i j} {X : Ptd i} {Y : Ptd j} where\n\n Ω^-isemap : (n : ℕ) (F : X ⊙→ Y) (e : is-equiv (fst F))\n → is-equiv (Ω^-fmap n F)\n Ω^-isemap O F e = e\n Ω^-isemap (S n) F e = Ω-isemap (⊙Ω^-fmap n F) (Ω^-isemap n F e)\n\n ⊙Ω^-isemap = Ω^-isemap\n\n Ω^-emap : (n : ℕ) → X ⊙≃ Y → Ω^ n X ≃ Ω^ n Y\n Ω^-emap n (F , e) = Ω^-fmap n F , Ω^-isemap n F e\n\n ⊙Ω^-emap : (n : ℕ) → X ⊙≃ Y → ⊙Ω^ n X ⊙≃ ⊙Ω^ n Y\n ⊙Ω^-emap n (F , e) = ⊙Ω^-fmap n F , ⊙Ω^-isemap n F e\n\n⊙Ω^-csemap : ∀ {i₀ i₁ j₀ j₁} (n : ℕ) {X₀ : Ptd i₀} {X₁ : Ptd i₁}\n {Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}\n {hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}\n → ⊙CommSquareEquiv f g hX hY\n → ⊙CommSquareEquiv (⊙Ω^-fmap n f) (⊙Ω^-fmap n g) (⊙Ω^-fmap n hX) (⊙Ω^-fmap n hY)\n⊙Ω^-csemap n {hX = hX} {hY} (cs , hX-ise , hY-ise) = ⊙Ω^-csmap n cs , Ω^-isemap n hX hX-ise , Ω^-isemap n hY hY-ise\n\n{- [Ω^'] preserves (pointed) equivalences too -}\nmodule _ {i j} where\n\n Ω^'-isemap : {X : Ptd i} {Y : Ptd j} (n : ℕ) (F : X ⊙→ Y) (e : is-equiv (fst F))\n → is-equiv (Ω^'-fmap n F)\n Ω^'-isemap O F e = e\n Ω^'-isemap (S n) F e = Ω^'-isemap n (⊙Ω-fmap F) (Ω-isemap F e)\n\n ⊙Ω^'-isemap = Ω^'-isemap\n\n Ω^'-emap : {X : Ptd i} {Y : Ptd j} (n : ℕ) → X ⊙≃ Y → Ω^' n X ≃ Ω^' n Y\n Ω^'-emap n (F , e) = Ω^'-fmap n F , Ω^'-isemap n F e\n\n ⊙Ω^'-emap : {X : Ptd i} {Y : Ptd j} (n : ℕ) → X ⊙≃ Y → ⊙Ω^' n X ⊙≃ ⊙Ω^' n Y\n ⊙Ω^'-emap n (F , e) = ⊙Ω^'-fmap n F , ⊙Ω^'-isemap n F e\n\n⊙Ω^'-csemap : ∀ {i₀ i₁ j₀ j₁} (n : ℕ) {X₀ : Ptd i₀} {X₁ : Ptd i₁}\n {Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}\n {hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}\n → ⊙CommSquareEquiv f g hX hY\n → ⊙CommSquareEquiv (⊙Ω^'-fmap n f) (⊙Ω^'-fmap n g) (⊙Ω^'-fmap n hX) (⊙Ω^'-fmap n hY)\n⊙Ω^'-csemap n {hX = hX} {hY} (cs , hX-ise , hY-ise) = ⊙Ω^'-csmap n cs , Ω^'-isemap n hX hX-ise , Ω^'-isemap n hY hY-ise\n\nΩ^-level : ∀ {i} (m : ℕ₋₂) (n : ℕ) (X : Ptd i)\n → (has-level (⟨ n ⟩₋₂ +2+ m) (de⊙ X) → has-level m (Ω^ n X))\nΩ^-level m O X pX = pX\nΩ^-level m (S n) X pX =\n has-level-apply (Ω^-level (S m) n X\n (transport (λ k → has-level k (de⊙ X)) (! (+2+-βr ⟨ n ⟩₋₂ m)) pX))\n (idp^ n) (idp^ n)\n\n{- As for the levels of [Ω^'], these special cases can avoid\n trailing constants, and it seems we only need the following\n two special cases. -}\n\nΩ^'-is-set : ∀ {i} (n : ℕ) (X : Ptd i)\n → (has-level ⟨ n ⟩ (de⊙ X) → is-set (Ω^' n X))\nΩ^'-is-set O X pX = pX\nΩ^'-is-set (S n) X pX = Ω^'-is-set n (⊙Ω X) (has-level-apply pX (pt X) (pt X))\n\nΩ^'-is-prop : ∀ {i} (n : ℕ) (X : Ptd i)\n → (has-level ⟨ n ⟩₋₁ (de⊙ X) → is-prop (Ω^' n X))\nΩ^'-is-prop O X pX = pX\nΩ^'-is-prop (S n) X pX = Ω^'-is-prop n (⊙Ω X) (has-level-apply pX (pt X) (pt X))\n\nΩ^-conn : ∀ {i} (m : ℕ₋₂) (n : ℕ) (X : Ptd i)\n → (is-connected (⟨ n ⟩₋₂ +2+ m) (de⊙ X)) → is-connected m (Ω^ n X)\nΩ^-conn m O X pX = pX\nΩ^-conn m (S n) X pX =\n path-conn $ Ω^-conn (S m) n X $\n transport (λ k → is-connected k (de⊙ X)) (! (+2+-βr ⟨ n ⟩₋₂ m)) pX\n\n{- Eckmann-Hilton argument -}\nmodule _ {i} {X : Ptd i} where\n\n Ω-fmap2-∙ : (α β : Ω^ 2 X) → ap2 _∙_ α β == Ω^S-∙ 1 α β\n Ω-fmap2-∙ α β = ap2-out _∙_ α β ∙ ap2 _∙_ (lemma α) (ap-idf β)\n where\n lemma : ∀ {i} {A : Type i} {x y : A} {p q : x == y} (α : p == q)\n → ap (λ r → r ∙ idp) α == ∙-unit-r p ∙ α ∙' ! (∙-unit-r q)\n lemma {p = idp} idp = idp\n\n ⊙Ω-fmap2-∙ : ⊙Ω-fmap2 (⊙Ω-∙ {X = X}) == ⊙Ω-∙\n ⊙Ω-fmap2-∙ = ⊙λ=' (uncurry Ω-fmap2-∙) idp\n\n Ω^2-∙-comm : (α β : Ω^ 2 X) → Ω^S-∙ 1 α β == Ω^S-∙ 1 β α\n Ω^2-∙-comm α β = ! (⋆2=Ω^S-∙ α β) ∙ ⋆2=⋆'2 α β ∙ ⋆'2=Ω^S-∙ α β\n where\n ⋆2=Ω^S-∙ : (α β : Ω^ 2 X) → α ⋆2 β == Ω^S-∙ 1 α β\n ⋆2=Ω^S-∙ α β = ap (λ π → π ∙ β) (∙-unit-r α)\n\n ⋆'2=Ω^S-∙ : (α β : Ω^ 2 X) → α ⋆'2 β == Ω^S-∙ 1 β α\n ⋆'2=Ω^S-∙ α β = ap (λ π → β ∙ π) (∙-unit-r α)\n\n{- NOT USED and DUPLICATE of [Ω^S-Trunc-preiso] in lib.groups.HomotopyGroup.\n XXX Should be an equivalence.\n\n{- Pushing truncation through loop space -}\nmodule _ {i} where\n\n Trunc-Ω^-conv : (m : ℕ₋₂) (n : ℕ) (X : Ptd i)\n → ⊙Trunc m (⊙Ω^ n X) == ⊙Ω^ n (⊙Trunc (⟨ n ⟩₋₂ +2+ m) X)\n Trunc-Ω^-conv m O X = idp\n Trunc-Ω^-conv m (S n) X =\n ⊙Trunc m (⊙Ω^ (S n) X)\n =⟨ ! (pair= (Trunc=-path [ _ ] [ _ ]) (↓-idf-ua-in _ idp)) ⟩\n ⊙Ω (⊙Trunc (S m) (⊙Ω^ n X))\n =⟨ ap ⊙Ω (Trunc-Ω^-conv (S m) n X) ⟩\n ⊙Ω^ (S n) (⊙Trunc (⟨ n ⟩₋₂ +2+ S m) X)\n =⟨ +2+-βr ⟨ n ⟩₋₂ m |in-ctx (λ k → ⊙Ω^ (S n) (⊙Trunc k X)) ⟩\n ⊙Ω^ (S n) (⊙Trunc (S ⟨ n ⟩₋₂ +2+ m) X) =∎\n\n Ω-Trunc-econv : (m : ℕ₋₂) (X : Ptd i)\n → Ω (⊙Trunc (S m) X) ≃ Trunc m (Ω X)\n Ω-Trunc-econv m X = Trunc=-equiv [ pt X ] [ pt X ]\n-}\n\n{- Our definition of [Ω^] builds up loops from the outside,\n - but this is equivalent to building up from the inside -}\nmodule _ {i} where\n ⊙Ω^-Ω-split : (n : ℕ) (X : Ptd i)\n → (⊙Ω^ (S n) X ⊙→ ⊙Ω^ n (⊙Ω X))\n ⊙Ω^-Ω-split O _ = (idf _ , idp)\n ⊙Ω^-Ω-split (S n) X = ⊙Ω-fmap (⊙Ω^-Ω-split n X)\n\n Ω^-Ω-split : (n : ℕ) (X : Ptd i)\n → (Ω^ (S n) X → Ω^ n (⊙Ω X))\n Ω^-Ω-split n X = fst (⊙Ω^-Ω-split n X)\n\n Ω^S-Ω-split-∙ : (n : ℕ)\n (X : Ptd i) (p q : Ω^ (S (S n)) X)\n → Ω^-Ω-split (S n) X (Ω^S-∙ (S n) p q)\n == Ω^S-∙ n (Ω^-Ω-split (S n) X p) (Ω^-Ω-split (S n) X q)\n Ω^S-Ω-split-∙ n X p q =\n Ω^S-fmap-∙ 0 (⊙Ω^-Ω-split n X) p q\n\n Ω^-Ω-split-is-equiv : (n : ℕ) (X : Ptd i)\n → is-equiv (Ω^-Ω-split n X)\n Ω^-Ω-split-is-equiv O X = is-eq (idf _) (idf _) (λ _ → idp) (λ _ → idp)\n Ω^-Ω-split-is-equiv (S n) X =\n ⊙Ω^-isemap 1 (⊙Ω^-Ω-split n X) (Ω^-Ω-split-is-equiv n X)\n\n Ω^-Ω-split-equiv : (n : ℕ) (X : Ptd i) → Ω^ (S n) X ≃ Ω^ n (⊙Ω X)\n Ω^-Ω-split-equiv n X = _ , Ω^-Ω-split-is-equiv n X\n\nmodule _ {i j} (X : Ptd i) (Y : Ptd j) where\n\n Ω-× : Ω (X ⊙× Y) ≃ Ω X × Ω Y\n Ω-× = equiv\n (λ p → fst×= p , snd×= p)\n (λ p → pair×= (fst p) (snd p))\n (λ p → pair×= (fst×=-β (fst p) (snd p)) (snd×=-β (fst p) (snd p)))\n (! ∘ pair×=-η)\n\n ⊙Ω-× : ⊙Ω (X ⊙× Y) ⊙≃ ⊙Ω X ⊙× ⊙Ω Y\n ⊙Ω-× = ≃-to-⊙≃ Ω-× idp\n\n Ω-×-∙ : ∀ (p q : Ω (X ⊙× Y))\n → –> Ω-× (p ∙ q) == (fst (–> Ω-× p) ∙ fst (–> Ω-× q) , snd (–> Ω-× p) ∙ snd (–> Ω-× q))\n Ω-×-∙ p q = pair×= (Ω-fmap-∙ ⊙fst p q) (Ω-fmap-∙ ⊙snd p q)\n\nmodule _ {i j} where\n\n ⊙Ω^-× : ∀ (n : ℕ) (X : Ptd i) (Y : Ptd j)\n → ⊙Ω^ n (X ⊙× Y) ⊙≃ ⊙Ω^ n X ⊙× ⊙Ω^ n Y\n ⊙Ω^-× O _ _ = ⊙ide _\n ⊙Ω^-× (S n) X Y = ⊙Ω-× (⊙Ω^ n X) (⊙Ω^ n Y) ⊙∘e ⊙Ω-emap (⊙Ω^-× n X Y)\n\n ⊙Ω^'-× : ∀ (n : ℕ) (X : Ptd i) (Y : Ptd j)\n → ⊙Ω^' n (X ⊙× Y) ⊙≃ ⊙Ω^' n X ⊙× ⊙Ω^' n Y\n ⊙Ω^'-× O _ _ = ⊙ide _\n ⊙Ω^'-× (S n) X Y = ⊙Ω^'-× n (⊙Ω X) (⊙Ω Y) ⊙∘e ⊙Ω^'-emap n (⊙Ω-× X Y)\n", "meta": {"hexsha": "e00a140c46c58d29d367c2faceb7db48143cacef", "size": 18844, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/types/LoopSpace.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "core/lib/types/LoopSpace.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "core/lib/types/LoopSpace.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": 34.0144404332, "max_line_length": 119, "alphanum_fraction": 0.4348333687, "num_tokens": 11870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947155710233, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3731934900652679}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nmodule Definition.Conversion.Reduction where\n\nopen import Definition.Untyped\nopen import Definition.Typed\nopen import Definition.Typed.Properties\nopen import Definition.Typed.RedSteps\nopen import Definition.Conversion\n\n\n-- Weak head expansion of algorithmic equality of types.\nreductionConv↑ : ∀ {A A′ B B′ Γ}\n → Γ ⊢ A ⇒* A′\n → Γ ⊢ B ⇒* B′\n → Γ ⊢ A′ [conv↑] B′\n → Γ ⊢ A [conv↑] B\nreductionConv↑ A⇒* B⇒* ([↑] A″ B″ D D′ whnfA″ whnfB″ A″<>B″) =\n [↑] A″ B″ (A⇒* ⇨* D) (B⇒* ⇨* D′) whnfA″ whnfB″ A″<>B″\n\n-- Weak head expansion of algorithmic equality of terms.\nreductionConv↑Term : ∀ {t t′ u u′ A B Γ}\n → Γ ⊢ A ⇒* B\n → Γ ⊢ t ⇒* t′ ∷ B\n → Γ ⊢ u ⇒* u′ ∷ B\n → Γ ⊢ t′ [conv↑] u′ ∷ B\n → Γ ⊢ t [conv↑] u ∷ A\nreductionConv↑Term A⇒* t⇒* u⇒* ([↑]ₜ B′ t″ u″ D d d′ whnfB′ whnft″ whnfu″ t″<>u″) =\n [↑]ₜ B′ t″ u″\n (A⇒* ⇨* D)\n ((conv* t⇒* (subset* D)) ⇨∷* d)\n ((conv* u⇒* (subset* D)) ⇨∷* d′)\n whnfB′ whnft″ whnfu″ t″<>u″\n", "meta": {"hexsha": "51c3d0bf86d322c1e3e28d750c73251810e3b8d2", "size": 1115, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Conversion/Reduction.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/Reduction.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/Reduction.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": 32.7941176471, "max_line_length": 83, "alphanum_fraction": 0.4753363229, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6825737344123242, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.37318910214583073}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import groups.ExactSequence\nopen import homotopy.FunctionOver\nopen import homotopy.PtdAdjoint\nopen import homotopy.SuspAdjointLoop\nopen import cohomology.MayerVietoris\nopen import cohomology.Theory\n\n{- Standard Mayer-Vietoris exact sequence (algebraic) derived from\n - the result in cohomology.MayerVietoris (topological).\n - This is a whole bunch of algebra which is not very interesting.\n -}\n\nmodule cohomology.MayerVietorisExact {i} (CT : CohomologyTheory i)\n (n : ℤ) (ps : ⊙Span {i} {i} {i}) where\n\nopen MayerVietorisFunctions ps\nmodule MV = MayerVietoris ps\nopen ⊙Span ps\n\nopen CohomologyTheory CT\nopen import cohomology.BaseIndependence CT\nopen import cohomology.Functor CT\nopen import cohomology.InverseInSusp CT\nopen import cohomology.LongExactSequence CT n ⊙reglue\nopen import cohomology.Wedge CT\n\nmayer-vietoris-seq : HomSequence _ _\nmayer-vietoris-seq =\n C n (⊙Pushout ps)\n ⟨ ×ᴳ-fanout (CF-hom n (⊙left ps)) (CF-hom n (⊙right ps)) ⟩→\n C n X ×ᴳ C n Y\n ⟨ ×ᴳ-fanin (C-is-abelian _ _) (CF-hom n f)\n (inv-hom _ (C-is-abelian _ _) ∘ᴳ (CF-hom n g)) ⟩→\n C n Z\n ⟨ CF-hom (succ n) ⊙extract-glue ∘ᴳ fst ((C-Susp n Z)⁻¹ᴳ) ⟩→\n C (succ n) (⊙Pushout ps)\n ⟨ ×ᴳ-fanout (CF-hom _ (⊙left ps)) (CF-hom _ (⊙right ps)) ⟩→\n C (succ n) X ×ᴳ C (succ n) Y ⊣|\n\nmayer-vietoris-exact : is-exact-seq mayer-vietoris-seq\nmayer-vietoris-exact =\n transport (λ {(r , s) → is-exact-seq s})\n (pair= _ $ sequence= _ _ $\n idp\n ∥⟨ ↓-over-×-in _→ᴳ_ idp (CWedge.⊙Wedge-rec-over n X Y _ _) ⟩∥\n CWedge.path n X Y\n ∥⟨ ↓-over-×-in' _→ᴳ_\n (ap↓ (λ φ → φ ∘ᴳ fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ))\n (CF-↓cod= (succ n) MV.ext-over)\n ∙ᵈ codomain-over-iso {χ = diff'} (codomain-over-equiv _ _))\n (CWedge.Wedge-hom-η n X Y _\n ▹ ap2 (×ᴳ-fanin (C-is-abelian n Z)) inl-lemma inr-lemma) ⟩∥\n ap (C (succ n)) MV.⊙path ∙ uaᴳ (C-Susp n Z)\n ∥⟨ ↓-over-×-in _→ᴳ_\n (CF-↓dom= (succ n) MV.cfcod-over\n ∙ᵈ domain-over-iso\n (! (ap (λ h → CF _ ⊙extract-glue ∘ h)\n (λ= (is-equiv.g-f (snd (C-Susp n Z)))))\n ◃ domain-over-equiv _ _))\n idp ⟩∥\n idp\n ∥⟨ ↓-over-×-in _→ᴳ_ idp (CWedge.⊙Wedge-rec-over (succ n) X Y _ _) ⟩∥\n CWedge.path (succ n) X Y ∥⊣|)\n long-cofiber-exact\n where\n {- shorthand -}\n diff' = fst (C-Susp n Z) ∘ᴳ CF-hom (succ n) MV.⊙mv-diff\n ∘ᴳ fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ)\n\n {- Variations on suspension axiom naturality -}\n natural-lemma₁ : {X Y : Ptd i} (n : ℤ) (f : X ⊙→ Y)\n → (fst (C-Susp n X) ∘ᴳ CF-hom _ (⊙Susp-fmap f)) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)\n == CF-hom n f\n natural-lemma₁ {X} {Y} n f =\n ap (λ φ → φ ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)) (C-SuspF n f)\n ∙ group-hom= (λ= (ap (CF n f) ∘ is-equiv.f-g (snd (C-Susp n Y))))\n\n natural-lemma₂ : {X Y : Ptd i} (n : ℤ) (f : X ⊙→ Y)\n → CF-hom _ (⊙Susp-fmap f) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ)\n == fst (C-Susp n X ⁻¹ᴳ) ∘ᴳ CF-hom n f\n natural-lemma₂ {X} {Y} n f =\n group-hom= (λ= (! ∘ is-equiv.g-f (snd (C-Susp n X))\n ∘ CF _ (⊙Susp-fmap f)\n ∘ GroupHom.f (fst (C-Susp n Y ⁻¹ᴳ))))\n ∙ ap (λ φ → fst (C-Susp n X ⁻¹ᴳ) ∘ᴳ φ) (natural-lemma₁ n f)\n\n {- Associativity lemmas -}\n assoc-lemma : ∀ {i} {G H K L J : Group i}\n (φ : L →ᴳ J) (ψ : K →ᴳ L) (χ : H →ᴳ K) (ξ : G →ᴳ H)\n → (φ ∘ᴳ ψ) ∘ᴳ χ ∘ᴳ ξ == φ ∘ᴳ ((ψ ∘ᴳ χ) ∘ᴳ ξ)\n assoc-lemma _ _ _ _ = group-hom= idp\n\n assoc-lemma₂ : ∀ {i} {G H K L J : Group i}\n (φ : L →ᴳ J) (ψ : K →ᴳ L) (χ : H →ᴳ K) (ξ : G →ᴳ H)\n → (φ ∘ᴳ ψ ∘ᴳ χ) ∘ᴳ ξ == φ ∘ᴳ ψ ∘ᴳ χ ∘ᴳ ξ\n assoc-lemma₂ _ _ _ _ = group-hom= idp\n\n inl-lemma : diff' ∘ᴳ CF-hom n (⊙projl X Y) == CF-hom n f\n inl-lemma =\n assoc-lemma₂\n (fst (C-Susp n Z)) (CF-hom (succ n) MV.⊙mv-diff)\n (fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ)) (CF-hom n (⊙projl X Y))\n ∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ CF-hom (succ n) MV.⊙mv-diff ∘ᴳ φ)\n (! (natural-lemma₂ n (⊙projl X Y)))\n ∙ ! (assoc-lemma₂\n (fst (C-Susp n Z)) (CF-hom _ MV.⊙mv-diff)\n (CF-hom _ (⊙Susp-fmap (⊙projl X Y)))\n (fst (C-Susp n X ⁻¹ᴳ)))\n ∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ) ∘ᴳ fst (C-Susp n X ⁻¹ᴳ))\n (! (CF-comp _ (⊙Susp-fmap (⊙projl X Y)) MV.⊙mv-diff))\n ∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ) ∘ᴳ fst (C-Susp n X ⁻¹ᴳ))\n (CF-λ= (succ n) projl-mv-diff)\n ∙ natural-lemma₁ n f\n where\n {- Compute the left projection of mv-diff -}\n projl-mv-diff : (σz : fst (⊙Susp Z))\n → Susp-fmap (projl X Y) (MV.mv-diff σz)\n == Susp-fmap (fst f) σz\n projl-mv-diff = Susp-elim idp (merid (pt X)) $\n ↓-='-from-square ∘ λ z →\n (ap-∘ (Susp-fmap (projl X Y)) MV.mv-diff (merid z)\n ∙ ap (ap (Susp-fmap (projl X Y))) (MV.MVDiff.merid-β z)\n ∙ ap-∙ (Susp-fmap (projl X Y))\n (merid (winl (fst f z))) (! (merid (winr (fst g z))))\n ∙ (SuspFmap.merid-β (projl X Y) (winl (fst f z))\n ∙2 (ap-! (Susp-fmap _) (merid (winr (fst g z)))\n ∙ ap ! (SuspFmap.merid-β (projl X Y) (winr (fst g z))))))\n ∙v⊡ (vid-square {p = merid (fst f z)}\n ⊡h rt-square (merid (pt X)))\n ⊡v∙ (∙-unit-r _ ∙ ! (SuspFmap.merid-β (fst f) z))\n\n inr-lemma : diff' ∘ᴳ CF-hom n (⊙projr X Y)\n == inv-hom _ (C-is-abelian n Z) ∘ᴳ CF-hom n g\n inr-lemma =\n assoc-lemma₂\n (fst (C-Susp n Z)) (CF-hom (succ n) MV.⊙mv-diff)\n (fst (C-Susp n (X ⊙∨ Y) ⁻¹ᴳ)) (CF-hom n (⊙projr X Y))\n ∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ CF-hom (succ n) MV.⊙mv-diff ∘ᴳ φ)\n (! (natural-lemma₂ n (⊙projr X Y)))\n ∙ ! (assoc-lemma₂\n (fst (C-Susp n Z)) (CF-hom _ MV.⊙mv-diff)\n (CF-hom _ (⊙Susp-fmap (⊙projr X Y)))\n (fst (C-Susp n Y ⁻¹ᴳ)))\n ∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ))\n (! (CF-comp _ (⊙Susp-fmap (⊙projr X Y)) MV.⊙mv-diff))\n ∙ ∘ᴳ-assoc (fst (C-Susp n Z))\n (CF-hom _ (⊙Susp-fmap (⊙projr X Y) ⊙∘ MV.⊙mv-diff))\n (fst (C-Susp n Y ⁻¹ᴳ))\n ∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ φ ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ))\n (CF-λ= (succ n) projr-mv-diff)\n ∙ ap (λ φ → fst (C-Susp n Z) ∘ᴳ φ ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ))\n (CF-comp _ (⊙Susp-fmap g) (⊙Susp-flip Z))\n ∙ ! (assoc-lemma (fst (C-Susp n Z)) (CF-hom _ (⊙Susp-flip Z))\n (CF-hom _ (⊙Susp-fmap g)) (fst (C-Susp n Y ⁻¹ᴳ)))\n ∙ ap (λ φ → (fst (C-Susp n Z) ∘ᴳ φ)\n ∘ᴳ CF-hom _ (⊙Susp-fmap g) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ))\n (C-Susp-flip-is-inv (succ n))\n ∙ ap (λ φ → φ ∘ᴳ CF-hom _ (⊙Susp-fmap g) ∘ᴳ fst (C-Susp n Y ⁻¹ᴳ))\n (inv-hom-natural (C-is-abelian _ _) (C-is-abelian _ _)\n (fst (C-Susp n Z)))\n ∙ assoc-lemma (inv-hom _ (C-is-abelian n Z)) (fst (C-Susp n Z))\n (CF-hom _ (⊙Susp-fmap g)) (fst (C-Susp n Y ⁻¹ᴳ))\n ∙ ap (λ φ → inv-hom _ (C-is-abelian n Z) ∘ᴳ φ) (natural-lemma₁ n g)\n where\n {- Compute the right projection of mv-diff -}\n projr-mv-diff : (σz : fst (⊙Susp Z))\n → Susp-fmap (projr X Y) (MV.mv-diff σz)\n == Susp-fmap (fst g) (Susp-flip σz)\n projr-mv-diff = Susp-elim (merid (pt Y)) idp $\n ↓-='-from-square ∘ λ z →\n (ap-∘ (Susp-fmap (projr X Y)) MV.mv-diff (merid z)\n ∙ ap (ap (Susp-fmap (projr X Y))) (MV.MVDiff.merid-β z)\n ∙ ap-∙ (Susp-fmap (projr X Y))\n (merid (winl (fst f z))) (! (merid (winr (fst g z))))\n ∙ (SuspFmap.merid-β (projr X Y) (winl (fst f z))\n ∙2 (ap-! (Susp-fmap (projr X Y))\n (merid (winr (fst g z)))\n ∙ ap ! (SuspFmap.merid-β (projr X Y) (winr (fst g z))))))\n ∙v⊡ ((lt-square (merid (pt Y))\n ⊡h vid-square {p = ! (merid (fst g z))}))\n ⊡v∙ ! (ap-∘ (Susp-fmap (fst g)) Susp-flip (merid z)\n ∙ ap (ap (Susp-fmap (fst g))) (FlipSusp.merid-β z)\n ∙ ap-! (Susp-fmap (fst g)) (merid z)\n ∙ ap ! (SuspFmap.merid-β (fst g) z))\n", "meta": {"hexsha": "addcb729e997b5c8ce690a2f1e9378ba337dd512", "size": 8033, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/stash/cohomology/MayerVietorisExact.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/stash/cohomology/MayerVietorisExact.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/stash/cohomology/MayerVietorisExact.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 42.7287234043, "max_line_length": 76, "alphanum_fraction": 0.5060375949, "num_tokens": 3626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.746138993030751, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3730694965153755}} {"text": "data Bool : Set where\n true false : Bool\n\npostulate\n and : Bool → Bool → Bool\n\n-- WAS: splitting on y removes the x@ as-pattern\ntest : Bool → Bool → Bool\ntest x@true y = {!y!}\ntest x@false y = and x {!y!} -- x will go out of scope if we split on y\n\n-- Multiple as-patterns on the same pattern should be preserved in the\n-- right order.\ntest₂ : Bool → Bool → Bool\ntest₂ x@y@true z = {!z!}\ntest₂ x@y z = {!!}\n\nopen import Agda.Builtin.String\n\n-- As bindings on literals should also be preserved\ntest₃ : String → Bool → Bool\ntest₃ x@\"foo\" z = {!z!}\ntest₃ _ _ = {!!}\n", "meta": {"hexsha": "9ca75d4e4e56bde1c9dc0d8db25411c55f34199e", "size": 567, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/interaction/Issue2414.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/interaction/Issue2414.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/interaction/Issue2414.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 23.625, "max_line_length": 72, "alphanum_fraction": 0.6507936508, "num_tokens": 181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.6334102567576901, "lm_q1q2_score": 0.3730084155214654}} {"text": "module Abstract where\n\nabstract\n\n f\n : {A : Set}\n → A\n → A\n f x\n = x\n\n g\n : {A : Set}\n → A\n → A\n g x\n = x\n\n h\n : {A : Set}\n → A\n → A\n h x\n = f x\n\n _\n : {A : Set}\n → A\n → A\n _\n = λ x → x\n\n", "meta": {"hexsha": "946d7f368f51fe73a943fe5d0a60d85428451da2", "size": 243, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "data/declaration/Abstract.agda", "max_stars_repo_name": "msuperdock/agda-unused", "max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z", "max_issues_repo_path": "data/declaration/Abstract.agda", "max_issues_repo_name": "msuperdock/agda-unused", "max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "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": "data/declaration/Abstract.agda", "max_forks_repo_name": "msuperdock/agda-unused", "max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z", "avg_line_length": 7.3636363636, "max_line_length": 21, "alphanum_fraction": 0.2839506173, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6334102498375401, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.3730084114462643}} {"text": "open import Nat\nopen import Prelude\nopen import core\nopen import contexts\n\nopen import lemmas-consistency\nopen import type-assignment-unicity\nopen import binders-disjoint-checks\n\nopen import lemmas-subst-ta\n\nmodule preservation where\n -- if d and d' both result from filling the hole in ε with terms of the\n -- same type, they too have the same type.\n wt-different-fill : ∀{ Δ Γ d ε d1 d2 d' τ τ1 } →\n d == ε ⟦ d1 ⟧ →\n Δ , Γ ⊢ d :: τ →\n Δ , Γ ⊢ d1 :: τ1 →\n Δ , Γ ⊢ d2 :: τ1 →\n d' == ε ⟦ d2 ⟧ →\n Δ , Γ ⊢ d' :: τ\n wt-different-fill FHOuter D1 D2 D3 FHOuter\n with type-assignment-unicity D1 D2\n ... | refl = D3\n wt-different-fill (FHAp1 eps) (TAAp D1 D2) D3 D4 (FHAp1 D5) = TAAp (wt-different-fill eps D1 D3 D4 D5) D2\n wt-different-fill (FHAp2 eps) (TAAp D1 D2) D3 D4 (FHAp2 D5) = TAAp D1 (wt-different-fill eps D2 D3 D4 D5)\n wt-different-fill (FHNEHole eps) (TANEHole x D1 x₁) D2 D3 (FHNEHole D4) = TANEHole x (wt-different-fill eps D1 D2 D3 D4) x₁\n wt-different-fill (FHCast eps) (TACast D1 x) D2 D3 (FHCast D4) = TACast (wt-different-fill eps D1 D2 D3 D4) x\n wt-different-fill (FHFailedCast x) (TAFailedCast y x₁ x₂ x₃) D3 D4 (FHFailedCast eps) = TAFailedCast (wt-different-fill x y D3 D4 eps) x₁ x₂ x₃\n\n -- if a well typed term results from filling the hole in ε, then the term\n -- that filled the hole is also well typed\n wt-filling : ∀{ ε Δ Γ d τ d' } →\n Δ , Γ ⊢ d :: τ →\n d == ε ⟦ d' ⟧ →\n Σ[ τ' ∈ htyp ] (Δ , Γ ⊢ d' :: τ')\n wt-filling TAConst FHOuter = _ , TAConst\n wt-filling (TAVar x₁) FHOuter = _ , TAVar x₁\n wt-filling (TALam f ta) FHOuter = _ , TALam f ta\n\n wt-filling (TAAp ta ta₁) FHOuter = _ , TAAp ta ta₁\n wt-filling (TAAp ta ta₁) (FHAp1 eps) = wt-filling ta eps\n wt-filling (TAAp ta ta₁) (FHAp2 eps) = wt-filling ta₁ eps\n\n wt-filling (TAEHole x x₁) FHOuter = _ , TAEHole x x₁\n wt-filling (TANEHole x ta x₁) FHOuter = _ , TANEHole x ta x₁\n wt-filling (TANEHole x ta x₁) (FHNEHole eps) = wt-filling ta eps\n wt-filling (TACast ta x) FHOuter = _ , TACast ta x\n wt-filling (TACast ta x) (FHCast eps) = wt-filling ta eps\n wt-filling (TAFailedCast x y z w) FHOuter = _ , TAFailedCast x y z w\n wt-filling (TAFailedCast x x₁ x₂ x₃) (FHFailedCast y) = wt-filling x y\n\n -- instruction transitions preserve type\n preserve-trans : ∀{ Δ Γ d τ d' } →\n binders-unique d →\n Δ , Γ ⊢ d :: τ →\n d →> d' →\n Δ , Γ ⊢ d' :: τ\n preserve-trans bd TAConst ()\n preserve-trans bd (TAVar x₁) ()\n preserve-trans bd (TALam _ ta) ()\n preserve-trans (BUAp (BULam bd x₁) bd₁ (BDLam x₂ x₃)) (TAAp (TALam apt ta) ta₁) ITLam = lem-subst apt x₂ bd₁ ta ta₁\n preserve-trans bd (TAAp (TACast ta TCRefl) ta₁) ITApCast = TACast (TAAp ta (TACast ta₁ TCRefl)) TCRefl\n preserve-trans bd (TAAp (TACast ta (TCArr x x₁)) ta₁) ITApCast = TACast (TAAp ta (TACast ta₁ (~sym x))) x₁\n preserve-trans bd (TAEHole x x₁) ()\n preserve-trans bd (TANEHole x ta x₁) ()\n preserve-trans bd (TACast ta x) (ITCastID) = ta\n preserve-trans bd (TACast (TACast ta x) x₁) (ITCastSucceed x₂) = ta\n preserve-trans bd (TACast ta x) (ITGround (MGArr x₁)) = TACast (TACast ta (TCArr TCHole1 TCHole1)) TCHole1\n preserve-trans bd (TACast ta TCHole2) (ITExpand (MGArr x₁)) = TACast (TACast ta TCHole2) (TCArr TCHole2 TCHole2)\n preserve-trans bd (TACast (TACast ta x) x₁) (ITCastFail w y z) = TAFailedCast ta w y z\n preserve-trans bd (TAFailedCast x y z q) ()\n\n lem-bd-ε1 : ∀{ d ε d0} → d == ε ⟦ d0 ⟧ → binders-unique d → binders-unique d0\n lem-bd-ε1 FHOuter bd = bd\n lem-bd-ε1 (FHAp1 eps) (BUAp bd bd₁ x) = lem-bd-ε1 eps bd\n lem-bd-ε1 (FHAp2 eps) (BUAp bd bd₁ x) = lem-bd-ε1 eps bd₁\n lem-bd-ε1 (FHNEHole eps) (BUNEHole bd x) = lem-bd-ε1 eps bd\n lem-bd-ε1 (FHCast eps) (BUCast bd) = lem-bd-ε1 eps bd\n lem-bd-ε1 (FHFailedCast eps) (BUFailedCast bd) = lem-bd-ε1 eps bd\n\n -- this is the main preservation theorem, gluing together the above\n preservation : {Δ : hctx} {d d' : ihexp} {τ : htyp} {Γ : tctx} →\n binders-unique d →\n Δ , Γ ⊢ d :: τ →\n d ↦ d' →\n Δ , Γ ⊢ d' :: τ\n preservation bd D (Step x x₁ x₂)\n with wt-filling D x\n ... | (_ , wt) = wt-different-fill x D wt (preserve-trans (lem-bd-ε1 x bd) wt x₁) x₂\n\n -- note that the exact statement of preservation in the paper, where Γ is\n -- empty indicating that the terms are closed, is an immediate corrolary\n -- of the slightly more general statement above.\n preservation' : {Δ : hctx} {d d' : ihexp} {τ : htyp} →\n binders-unique d →\n Δ , ∅ ⊢ d :: τ →\n d ↦ d' →\n Δ , ∅ ⊢ d' :: τ\n preservation' = preservation\n", "meta": {"hexsha": "e6d38a11175909f65f0453e2881642dfa31e11bd", "size": 4700, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "preservation.agda", "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_issues_repo_path": "preservation.agda", "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_forks_repo_path": "preservation.agda", "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "avg_line_length": 46.5346534653, "max_line_length": 145, "alphanum_fraction": 0.6214893617, "num_tokens": 1831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.37279681839802986}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule function.fibration where\n\nopen import level\nopen import sum\nopen import equality.core\nopen import function.core\nopen import function.isomorphism.core\nopen import function.isomorphism.coherent\nopen import function.isomorphism.lift\nopen import function.isomorphism.univalence\nopen import function.isomorphism.utils\nopen import function.extensionality.core\nopen import function.extensionality.proof\nopen import function.overloading\nopen import hott.level.core\nopen import hott.equivalence.core\nopen import hott.equivalence.alternative\nopen import hott.univalence\nopen import sets.unit\n\nFibration : ∀ {i} j → Set i → Set _\nFibration j X = Σ (Set j) λ Y → Y → X\n\nfib : ∀ {i j}{X : Set i}(Y : X → Set j)\n → Σ X Y → X\nfib Y = proj₁\n\nfib-iso : ∀ {i j}{X : Set i}{Y : X → Set j}\n → (x : X)\n → fib Y ⁻¹ x ≅ Y x\nfib-iso {X = X}{Y = Y} x = begin\n fib Y ⁻¹ x\n ≅⟨ refl≅ ⟩\n ( Σ (Σ X Y) λ { (x' , y)\n → x' ≡ x } )\n ≅⟨ Σ-assoc-iso ⟩\n ( Σ X λ x' → Y x' × x' ≡ x )\n ≅⟨ (Σ-ap-iso refl≅ λ x' → ×-comm) ⟩\n ( Σ X λ x' → x' ≡ x × Y x' )\n ≅⟨ sym≅ Σ-assoc-iso ⟩\n ( Σ (singleton' x) λ { (x' , _) → Y x' } )\n ≅⟨ Σ-ap-iso' (contr-⊤-iso (singl-contr' x)) (λ _ → refl≅) ⟩\n ( ⊤ × Y x )\n ≅⟨ ×-left-unit ⟩\n Y x\n ∎\n where open ≅-Reasoning\n\ntotal-iso : ∀ {i j}{X : Set i}{Y : Set j}(p : Y → X)\n → (Σ X (_⁻¹_ p)) ≅ Y\ntotal-iso {X = X}{Y = Y} p = begin\n ( Σ X λ x → (Σ Y λ y → p y ≡ x) )\n ≅⟨ Σ-comm-iso ⟩\n ( Σ Y λ y → (Σ X λ x → p y ≡ x) )\n ≅⟨ ( Σ-ap-iso refl≅ λ y → contr-⊤-iso (singl-contr (p y)) ) ⟩\n (Y × ⊤)\n ≅⟨ ×-right-unit ⟩\n Y\n ∎\n where open ≅-Reasoning\n\nfib-eq-iso : ∀ {i j}{X : Set i}{Y₁ Y₂ : Set j}\n → (p₁ : Y₁ → X) (p₂ : Y₂ → X)\n → _≡_ {A = Fibration _ X} (Y₁ , p₁) (Y₂ , p₂)\n ≅ ( Σ (Y₁ ≅' Y₂) λ q → p₁ ≡ p₂ ∘ apply q )\nfib-eq-iso {i}{j}{X}{Y₁}{Y₂} p₁ p₂ = begin\n _≡_ {A = Fibration _ X} (Y₁ , p₁) (Y₂ , p₂)\n ≅⟨ sym≅ Σ-split-iso ⟩\n ( Σ (Y₁ ≡ Y₂) λ q → subst (λ Y → Y → X) q p₁ ≡ p₂ )\n ≅⟨ ( Σ-ap-iso refl≅ λ q → lem q p₁ p₂ ) ⟩\n ( Σ (Y₁ ≡ Y₂) λ q → p₁ ≡ p₂ ∘ coerce q )\n ≅⟨ step ⟩\n ( Σ (Y₁ ≅' Y₂) λ q → p₁ ≡ p₂ ∘ apply q )\n ∎\n where\n open ≅-Reasoning\n abstract\n step : ( Σ (Y₁ ≡ Y₂) λ q → p₁ ≡ p₂ ∘ coerce q )\n ≅ ( Σ (Y₁ ≅' Y₂) λ q → p₁ ≡ p₂ ∘ apply q )\n step = Σ-ap-iso (uni-iso ·≅ ≈⇔≅') λ q → refl≅\n\n abstract\n lem : {Y₁ Y₂ : Set j}(q : Y₁ ≡ Y₂)(p₁ : Y₁ → X)(p₂ : Y₂ → X)\n → (subst (λ Y → Y → X) q p₁ ≡ p₂)\n ≅ (p₁ ≡ p₂ ∘ coerce q)\n lem refl p₁ p₂ = refl≅\n\nfibration-iso : ∀ {i} j {X : Set i}\n → (Σ (Set (i ⊔ j)) λ Y → Y → X)\n ≅ (X → Set (i ⊔ j))\nfibration-iso {i} j {X} = record\n { to = λ { (Y , p) x → p ⁻¹ x }\n ; from = λ P → (Σ X P , fib P)\n ; iso₁ = λ { (Y , p) → α Y p }\n ; iso₂ = λ P → funext λ x → ≅⇒≡ (fib-iso x) }\n where\n α : (Y : Set (i ⊔ j))(p : Y → X)\n → _≡_ {A = Σ (Set (i ⊔ j)) λ Y → Y → X}\n (Σ X (_⁻¹_ p) , proj₁)\n (Y , p)\n α Y p = invert (fib-eq-iso proj₁ p)\n ( ≅⇒≅' (total-iso p)\n , funext λ { (y , x , eq) → sym eq } )\n\nfamily-eq-iso : ∀ {i j₁ j₂}{X : Set i}{Y₁ : X → Set j₁}{Y₂ : X → Set j₂}\n → (isom : Σ X Y₁ ≅ Σ X Y₂)\n → (∀ x y → proj₁ (apply≅ isom (x , y)) ≡ x)\n → (x : X) → Y₁ x ≅ Y₂ x\nfamily-eq-iso {i}{j₁}{j₂}{X}{Y₁}{Y₂} isom comm x\n = lift-iso _ (Y₁ x)\n ·≅ ≡⇒≅ (funext-inv eq' x)\n ·≅ sym≅ (lift-iso _ (Y₂ x))\n where\n open _≅_ isom\n\n to-we : weak-equiv to\n to-we = proj₂ (≅⇒≈ isom)\n\n P₁ : X → Set (i ⊔ j₁ ⊔ j₂)\n P₁ x = ↑ (i ⊔ j₂) (Y₁ x)\n\n p₁ : Σ X P₁ → X\n p₁ = proj₁\n\n P₂ : X → Set (i ⊔ j₁ ⊔ j₂)\n P₂ x = ↑ (i ⊔ j₁) (Y₂ x)\n\n p₂ : Σ X P₂ → X\n p₂ = proj₁\n\n total : Σ X P₁ ≅ Σ X P₂\n total = (Σ-ap-iso refl≅ λ x → sym≅ (lift-iso _ _))\n ·≅ isom\n ·≅ (Σ-ap-iso refl≅ λ x → lift-iso _ _)\n\n comm' : (a : Σ X P₁) → p₁ a ≡ p₂ (apply total a)\n comm' (x , lift u) = sym (comm x u)\n\n eq' : P₁ ≡ P₂\n eq' = iso⇒inj (sym≅ (fibration-iso (i ⊔ j₁ ⊔ j₂)))\n (invert (fib-eq-iso p₁ p₂) (≅⇒≅' total , funext comm'))\n\n\nfib-compose : ∀ {i j k}{X : Set i}{Y : Set j}{Z : Set k}\n → (f : X → Y)(g : Y → Z)(z : Z)\n → (g ∘' f) ⁻¹ z\n ≅ ( Σ (g ⁻¹ z) λ { (y , _) → f ⁻¹ y } )\nfib-compose {X = X}{Y}{Z} f g z = begin\n (g ∘' f) ⁻¹ z\n ≅⟨ refl≅ ⟩\n ( Σ X λ x → g (f x) ≡ z )\n ≅⟨ Σ-ap-iso refl≅ (λ _ → sym≅ ×-left-unit) ⟩\n ( Σ X λ x → ⊤ × g (f x) ≡ z)\n ≅⟨ ( Σ-ap-iso refl≅ λ x\n → Σ-ap-iso (sym≅ (contr-⊤-iso (singl-contr (f x))) ) λ _\n → refl≅ ) ⟩\n ( Σ X λ x → singleton (f x) × g (f x) ≡ z )\n ≅⟨ ( Σ-ap-iso refl≅ λ x → Σ-assoc-iso ) ⟩\n ( Σ X λ x → Σ Y λ y → (f x ≡ y) × (g (f x) ≡ z) )\n ≅⟨ ( Σ-ap-iso refl≅ λ x\n → Σ-ap-iso refl≅ λ y\n → Σ-ap-iso refl≅ λ p\n → ≡⇒≅ (ap (λ u → g u ≡ z) p) ) ⟩\n ( Σ X λ x → Σ Y λ y → (f x ≡ y) × (g y ≡ z) )\n ≅⟨ Σ-comm-iso ⟩\n ( Σ Y λ y → Σ X λ x → (f x ≡ y) × (g y ≡ z) )\n ≅⟨ ( Σ-ap-iso refl≅ λ y → sym≅ Σ-assoc-iso ) ⟩\n ( Σ Y λ y → (f ⁻¹ y) × (g y ≡ z) )\n ≅⟨ ( Σ-ap-iso refl≅ λ y → ×-comm ) ⟩\n ( Σ Y λ y → (g y ≡ z) × (f ⁻¹ y) )\n ≅⟨ sym≅ Σ-assoc-iso ⟩\n ( Σ (g ⁻¹ z) λ { (y , _) → f ⁻¹ y } )\n ∎\n where open ≅-Reasoning\n", "meta": {"hexsha": "08cb22ca80e1b40111618ff7ecb70c571c58125f", "size": 5224, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "function/fibration.agda", "max_stars_repo_name": "HoTT/M-types", "max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z", "max_issues_repo_path": "function/fibration.agda", "max_issues_repo_name": "HoTT/M-types", "max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z", "max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z", "max_forks_repo_path": "function/fibration.agda", "max_forks_repo_name": "HoTT/M-types", "max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z", "avg_line_length": 29.5141242938, "max_line_length": 72, "alphanum_fraction": 0.4452526799, "num_tokens": 2548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.37279460555894955}} {"text": "{-# OPTIONS --safe #-}\nmodule Cubical.Algebra.Algebra.Properties where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.GroupoidLaws\nopen import Cubical.Foundations.Path\nopen import Cubical.Foundations.Transport\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Foundations.SIP\n\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Structures.Axioms\nopen import Cubical.Structures.Auto\nopen import Cubical.Structures.Macro\n\nopen import Cubical.Algebra.Monoid\nopen import Cubical.Algebra.Group\nopen import Cubical.Algebra.AbGroup\nopen import Cubical.Algebra.Ring\nopen import Cubical.Algebra.Module\n\nopen import Cubical.Algebra.Algebra.Base\n\nopen Iso\n\nprivate\n variable\n ℓ ℓ' ℓ'' ℓ''' : Level\n\nmodule AlgebraTheory (R : Ring ℓ) (A : Algebra R ℓ') where\n open RingStr (snd R) renaming (_+_ to _+r_ ; _·_ to _·r_)\n open AlgebraStr (A .snd)\n\n 0-actsNullifying : (x : ⟨ A ⟩) → 0r ⋆ x ≡ 0a\n 0-actsNullifying x =\n let idempotent-+ = 0r ⋆ x ≡⟨ cong (λ u → u ⋆ x) (sym (RingTheory.0Idempotent R)) ⟩\n (0r +r 0r) ⋆ x ≡⟨ ⋆DistL+ 0r 0r x ⟩\n (0r ⋆ x) + (0r ⋆ x) ∎\n in RingTheory.+Idempotency→0 (Algebra→Ring A) (0r ⋆ x) idempotent-+\n\n ⋆Dist· : (x y : ⟨ R ⟩) (a b : ⟨ A ⟩) → (x ·r y) ⋆ (a · b) ≡ (x ⋆ a) · (y ⋆ b)\n ⋆Dist· x y a b = (x ·r y) ⋆ (a · b) ≡⟨ ⋆AssocR _ _ _ ⟩\n a · ((x ·r y) ⋆ b) ≡⟨ cong (a ·_) (⋆Assoc _ _ _) ⟩\n a · (x ⋆ (y ⋆ b)) ≡⟨ sym (⋆AssocR _ _ _) ⟩\n x ⋆ (a · (y ⋆ b)) ≡⟨ sym (⋆AssocL _ _ _) ⟩\n (x ⋆ a) · (y ⋆ b) ∎\n\n\nmodule AlgebraHoms {R : Ring ℓ} where\n open IsAlgebraHom\n\n idAlgebraHom : (A : Algebra R ℓ') → AlgebraHom A A\n fst (idAlgebraHom A) x = x\n pres0 (snd (idAlgebraHom A)) = refl\n pres1 (snd (idAlgebraHom A)) = refl\n pres+ (snd (idAlgebraHom A)) x y = refl\n pres· (snd (idAlgebraHom A)) x y = refl\n pres- (snd (idAlgebraHom A)) x = refl\n pres⋆ (snd (idAlgebraHom A)) r x = refl\n\n compIsAlgebraHom : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}\n {g : ⟨ B ⟩ → ⟨ C ⟩} {f : ⟨ A ⟩ → ⟨ B ⟩}\n → IsAlgebraHom (B .snd) g (C .snd)\n → IsAlgebraHom (A .snd) f (B .snd)\n → IsAlgebraHom (A .snd) (g ∘ f) (C .snd)\n compIsAlgebraHom {g = g} {f} gh fh .pres0 = cong g (fh .pres0) ∙ gh .pres0\n compIsAlgebraHom {g = g} {f} gh fh .pres1 = cong g (fh .pres1) ∙ gh .pres1\n compIsAlgebraHom {g = g} {f} gh fh .pres+ x y = cong g (fh .pres+ x y) ∙ gh .pres+ (f x) (f y)\n compIsAlgebraHom {g = g} {f} gh fh .pres· x y = cong g (fh .pres· x y) ∙ gh .pres· (f x) (f y)\n compIsAlgebraHom {g = g} {f} gh fh .pres- x = cong g (fh .pres- x) ∙ gh .pres- (f x)\n compIsAlgebraHom {g = g} {f} gh fh .pres⋆ r x = cong g (fh .pres⋆ r x) ∙ gh .pres⋆ r (f x)\n\n _∘≃a_ : {A B C : Algebra R ℓ'}\n → AlgebraEquiv B C → AlgebraEquiv A B → AlgebraEquiv A C\n _∘≃a_ g f .fst = compEquiv (fst f) (fst g)\n _∘≃a_ g f .snd = compIsAlgebraHom (g .snd) (f .snd)\n\n compAlgebraHom : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}\n → AlgebraHom A B → AlgebraHom B C → AlgebraHom A C\n compAlgebraHom f g .fst = g .fst ∘ f .fst\n compAlgebraHom f g .snd = compIsAlgebraHom (g .snd) (f .snd)\n\n syntax compAlgebraHom f g = g ∘a f\n\n compIdAlgebraHom : {A B : Algebra R ℓ'} (φ : AlgebraHom A B) → compAlgebraHom (idAlgebraHom A) φ ≡ φ\n compIdAlgebraHom φ = AlgebraHom≡ refl\n\n idCompAlgebraHom : {A B : Algebra R ℓ'} (φ : AlgebraHom A B) → compAlgebraHom φ (idAlgebraHom B) ≡ φ\n idCompAlgebraHom φ = AlgebraHom≡ refl\n\n compAssocAlgebraHom : {A B C D : Algebra R ℓ'}\n (φ : AlgebraHom A B) (ψ : AlgebraHom B C) (χ : AlgebraHom C D)\n → compAlgebraHom (compAlgebraHom φ ψ) χ ≡ compAlgebraHom φ (compAlgebraHom ψ χ)\n compAssocAlgebraHom _ _ _ = AlgebraHom≡ refl\n\n\nmodule AlgebraEquivs {R : Ring ℓ} where\n open IsAlgebraHom\n open AlgebraHoms\n\n compIsAlgebraEquiv : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}\n {g : ⟨ B ⟩ ≃ ⟨ C ⟩} {f : ⟨ A ⟩ ≃ ⟨ B ⟩}\n → IsAlgebraEquiv (B .snd) g (C .snd)\n → IsAlgebraEquiv (A .snd) f (B .snd)\n → IsAlgebraEquiv (A .snd) (compEquiv f g) (C .snd)\n compIsAlgebraEquiv {g = g} {f} gh fh = compIsAlgebraHom {g = g .fst} {f .fst} gh fh\n\n compAlgebraEquiv : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}\n → AlgebraEquiv A B → AlgebraEquiv B C → AlgebraEquiv A C\n fst (compAlgebraEquiv f g) = compEquiv (f .fst) (g .fst)\n snd (compAlgebraEquiv f g) = compIsAlgebraEquiv {g = g .fst} {f = f .fst} (g .snd) (f .snd)\n\n\n\n-- the Algebra version of uaCompEquiv\nmodule AlgebraUAFunctoriality {R : Ring ℓ} where\n open AlgebraStr\n open AlgebraEquivs\n\n Algebra≡ : (A B : Algebra R ℓ') → (\n Σ[ p ∈ ⟨ A ⟩ ≡ ⟨ B ⟩ ]\n Σ[ q0 ∈ PathP (λ i → p i) (0a (snd A)) (0a (snd B)) ]\n Σ[ q1 ∈ PathP (λ i → p i) (1a (snd A)) (1a (snd B)) ]\n Σ[ r+ ∈ PathP (λ i → p i → p i → p i) (_+_ (snd A)) (_+_ (snd B)) ]\n Σ[ r· ∈ PathP (λ i → p i → p i → p i) (_·_ (snd A)) (_·_ (snd B)) ]\n Σ[ s- ∈ PathP (λ i → p i → p i) (-_ (snd A)) (-_ (snd B)) ]\n Σ[ s⋆ ∈ PathP (λ i → ⟨ R ⟩ → p i → p i) (_⋆_ (snd A)) (_⋆_ (snd B)) ]\n PathP (λ i → IsAlgebra R (q0 i) (q1 i) (r+ i) (r· i) (s- i) (s⋆ i)) (isAlgebra (snd A))\n (isAlgebra (snd B)))\n ≃ (A ≡ B)\n Algebra≡ A B = isoToEquiv theIso\n where\n open Iso\n theIso : Iso _ _\n fun theIso (p , q0 , q1 , r+ , r· , s- , s⋆ , t) i = p i\n , algebrastr (q0 i) (q1 i) (r+ i) (r· i) (s- i) (s⋆ i) (t i)\n inv theIso x = cong ⟨_⟩ x , cong (0a ∘ snd) x , cong (1a ∘ snd) x\n , cong (_+_ ∘ snd) x , cong (_·_ ∘ snd) x , cong (-_ ∘ snd) x , cong (_⋆_ ∘ snd) x\n , cong (isAlgebra ∘ snd) x\n rightInv theIso _ = refl\n leftInv theIso _ = refl\n\n caracAlgebra≡ : {A B : Algebra R ℓ'} (p q : A ≡ B) → cong ⟨_⟩ p ≡ cong ⟨_⟩ q → p ≡ q\n caracAlgebra≡ {A = A} {B = B} p q P =\n sym (transportTransport⁻ (ua (Algebra≡ A B)) p)\n ∙∙ cong (transport (ua (Algebra≡ A B))) helper\n ∙∙ transportTransport⁻ (ua (Algebra≡ A B)) q\n where\n helper : transport (sym (ua (Algebra≡ A B))) p ≡ transport (sym (ua (Algebra≡ A B))) q\n helper = Σ≡Prop\n (λ _ → isPropΣ\n (isOfHLevelPathP' 1 (is-set (snd B)) _ _)\n λ _ → isPropΣ (isOfHLevelPathP' 1 (is-set (snd B)) _ _)\n λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)\n λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)\n λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ λ _ → is-set (snd B)) _ _)\n λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)\n λ _ → isOfHLevelPathP 1 (isPropIsAlgebra _ _ _ _ _ _ _) _ _)\n (transportRefl (cong ⟨_⟩ p) ∙ P ∙ sym (transportRefl (cong ⟨_⟩ q)))\n\n uaCompAlgebraEquiv : {A B C : Algebra R ℓ'} (f : AlgebraEquiv A B) (g : AlgebraEquiv B C)\n → uaAlgebra (compAlgebraEquiv f g) ≡ uaAlgebra f ∙ uaAlgebra g\n uaCompAlgebraEquiv f g = caracAlgebra≡ _ _ (\n cong ⟨_⟩ (uaAlgebra (compAlgebraEquiv f g))\n ≡⟨ uaCompEquiv _ _ ⟩\n cong ⟨_⟩ (uaAlgebra f) ∙ cong ⟨_⟩ (uaAlgebra g)\n ≡⟨ sym (cong-∙ ⟨_⟩ (uaAlgebra f) (uaAlgebra g)) ⟩\n cong ⟨_⟩ (uaAlgebra f ∙ uaAlgebra g) ∎)\n", "meta": {"hexsha": "d03089c2677278dff2a710b2d90124ad2f5ba972", "size": 7633, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/Algebra/Properties.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/Algebra/Properties.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/Algebra/Properties.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": 43.867816092, "max_line_length": 102, "alphanum_fraction": 0.5544346915, "num_tokens": 3072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723316991792861, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3727880698515729}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import library.Basics hiding (Type ; Σ)\nopen import library.types.Sigma\n\nmodule Sec2preliminaries where\n\n-- is-prop, is-contr, is-set, has-dec-eq exist in library.Basicss\n\n-- Let us redefine Type and Σ so that they only refer to the lowest universe.\nType = Type₀\nΣ = library.Basics.Σ {lzero} {lzero} \n\n_+_ : Type → Type → Type\nX + Y = Coprod X Y\n\nconst : {X Y : Type} → (f : X → Y) → Type\nconst {X} f = (x₁ x₂ : X) → (f x₁) == (f x₂)\n\nhasConst : Type → Type\nhasConst X = Σ (X → X) const\n\npathHasConst : Type → Type\npathHasConst X = (x₁ x₂ : X) → hasConst (x₁ == x₂)\n\nLEM : Type₁\nLEM = (P : Type) → is-prop P → P + (¬ P)\n\nLEM∞ : Type₁\nLEM∞ = (X : Type) → X + (¬ X)\n\nFunext : {X Y : Type} → Type\nFunext {X} {Y} = (f g : X → Y) → ((x : X) → (f x) == (g x)) → f == g\n\n\n-- In the rest of this file, we define several auxiliary notations or lemmata that are not mentioned \n-- explicitly in the article but are somewhat self-explaining.\n\n-- for convenience, we also define ↔ to mean logical equivalence (maps in both directions)\n_↔_ : Type → Type → Type\nX ↔ Y = (X → Y) × (Y → X)\n\n-- we define it for types in the higher universe separately \n-- (because most of the time, we only need the lowest universe and do not want to carry around indices)\n_↔₀₁_ : Type → Type₁ → Type₁\nA ↔₀₁ B = (A → B) × (B → A)\n\n_↔₁₁_ : Type₁ → Type₁ → Type₁\nX ↔₁₁ Y = (X → Y) × (Y → X)\n\n-- composition of ↔\n_◎_ : {X Y Z : Type} → (X ↔ Y) → (Y ↔ Z) → (X ↔ Z) \ne₁ ◎ e₂ = fst e₂ ∘ fst e₁ , snd e₁ ∘ snd e₂\n\n-- A trivial, but useful lemma. The only thing we do is hiding the arguments.\nprop-eq-triv : {P : Type} → {p₁ p₂ : P} → is-prop P → p₁ == p₂\nprop-eq-triv h = prop-has-all-paths h _ _\n\n-- A second such useful lemma\nsecond-comp-triv : {X : Type} → {P : X → Type} → ((x : X) → is-prop (P x)) → (a b : Σ X P) → (fst a == fst b) → a == b\nsecond-comp-triv {X} {P} h a b q = pair= q (from-transp P q (prop-eq-triv (h (fst b))))\n\nopen import library.types.Pi\n\n-- Note that this lemma needs function extensionality (we use Π-level).\nneutral-codomain : {X : Type} → {Y : X → Type} → ((x : X) → is-contr (Y x)) → Π X Y ≃ Unit\nneutral-codomain = contr-equiv-Unit ∘ Π-level\n\n-- the following is the function which the univalence axiom postulates to be an equivalence\n-- (we define it ourselves as we do not want to implicitly import the whole univalence library)\npath-to-equiv : {X Y : Type} → X == Y → X ≃ Y\npath-to-equiv {X} idp = ide X\n\n-- some rather silly lemmata\n\ndelete-idp : {X : Type} → {x₁ x₂ : X} → (p q : x₁ == x₂) → (p ∙ idp == q) ≃ (p == q)\ndelete-idp idp q = ide _\n\nadd-path : {X : Type} → {x₁ x₂ x₃ : X} → (p q : x₁ == x₂) → (r : x₂ == x₃) → (p == q) == (p ∙ r == q ∙ r)\nadd-path idp q idp = transport (λ q₁ → (idp == q₁) == (idp == q ∙ idp)) {x = q ∙ idp} {y = q} (∙-unit-r _) idp\n\nopen import library.types.Paths\n\nreverse-paths : {X : Type} → {x₁ x₂ : X} → (p : x₂ == x₁) → (q : x₁ == x₂) → (! p == q) ≃ (p == ! q)\nreverse-paths p idp = \n ! p == idp ≃⟨ path-to-equiv (add-path _ _ _) ⟩\n ! p ∙ p == p ≃⟨ path-to-equiv (transport (λ p₁ → (! p ∙ p == p) == (p₁ == p)) (!-inv-l p) idp) ⟩\n idp == p ≃⟨ !-equiv ⟩\n p == idp ≃∎\n\nswitch-args : {X Y : Type} → {Z : X → Y → Type} → ((x : X) → (y : Y) → Z x y) ≃ ((y : Y) → (x : X) → Z x y)\nswitch-args = equiv f g h₁ h₂ where\n f = λ k y x → k x y\n g = λ i x y → i y x\n h₁ = λ _ → idp\n h₂ = λ _ → idp\n\n\n-- another useful (but simple) lemma: if we have a proof of (x , y₁) == (x , y₂) and the type of x is a set, we get a proof of y₁ == y₂.\nset-lemma : {X : Type} → (is-set X) → {Y : X → Type} → (x₀ : X) → (y₁ y₂ : Y x₀) → _==_ {A = Σ X Y} (x₀ , y₁) (x₀ , y₂) → y₁ == y₂\nset-lemma {X} h {Y} x₀ y₁ y₂ p = \n y₁ =⟨ idp ⟩\n transport Y idp y₁ =⟨ transport {A = x₀ == x₀} (λ q → y₁ == transport Y q y₁) \n {x = idp} {y = ap fst p} \n (prop-has-all-paths (h x₀ x₀) _ _) \n idp ⟩\n transport Y (ap fst p) y₁ =⟨ snd-of-p ⟩\n y₂ ∎ where\n pairs : =Σ {B = Y} (x₀ , y₁) (x₀ , y₂)\n pairs = <– (=Σ-eqv _ _) p\n\n paov : y₁ == y₂ [ Y ↓ fst (pairs) ]\n paov = snd pairs\n\n snd-of-p : transport Y (ap fst p) y₁ == y₂\n snd-of-p = to-transp paov\n\n", "meta": {"hexsha": "e4e02fbf7bff5ab38c4ed56ab5b712c784d19ebc", "size": 4211, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "nicolai/anonymousExistence/Sec2preliminaries.agda", "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolai/anonymousExistence/Sec2preliminaries.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": "nicolai/anonymousExistence/Sec2preliminaries.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": 35.686440678, "max_line_length": 136, "alphanum_fraction": 0.5445262408, "num_tokens": 1656, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6370307944803832, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.3727274531134736}} {"text": " \nmodule Extended.FunRetRec where\n\nopen import Function\nopen import Data.Nat\nopen import Data.Nat.Properties.Simple\nopen import Relation.Binary.PropositionalEquality hiding ([_])\nopen import Data.String\nopen import Data.Product\nopen import Data.Bool renaming (not to bnot) hiding (if_then_else_)\nopen import Relation.Nullary.Decidable\nopen import Relation.Nullary\nopen import Data.List hiding (and; or)\nopen import Data.List.Properties using (∷-injective)\nopen import Data.Empty\nopen import Data.Unit\nimport Level as L\n\nopen import Utils.Decidable\nopen import Utils.Monoid\nopen import Utils.NatOrdLemmas\n\n{-\nThis module contains an extension of the While language and assorted semantics.\nIt incorporates some of the suggested extra features in the book.\n\nThe extra features in short:\n\n - Function calls and recursive local function declarations\n - Local variable declarations\n - String-based bindings with name shadowing\n - Return statements with the usual jump in control flow\n-}\n\n\n-- Data definitions\n--------------------------------------------------\n\ndata Ty : Set where\n bool nat : Ty\n\n⟦_⟧ᵗ : Ty → Set\n⟦ nat ⟧ᵗ = ℕ\n⟦ bool ⟧ᵗ = Bool\n\ndata Exp : Ty → Set where\n lit : ℕ → Exp nat\n add mul sub : Exp nat → Exp nat → Exp nat\n var : String → Exp nat\n\n {-\n Function calls. Note that we have calls as a proper *expression* that\n evaluate to a value, if they terminate. This also implies that the evaluation\n of expressions has a partial semantics just like statements.\n\n We apply a function to a list of arguments. The number of args must be correct.\n -}\n _$:_ : String → List (Exp nat) → Exp nat\n \n tt ff : Exp bool\n eq lt lte : Exp nat → Exp nat → Exp bool\n and : Exp bool → Exp bool → Exp bool\n not : Exp bool → Exp bool\n or : Exp bool → Exp bool → Exp bool\n\ninfixr 4 _,_\ninfixr 5 _:=_\ndata St : Set where\n\n {- Function declarations. We specify the arguments as a list of bindings.\n They are recursive. -}\n fun : String → List String → St → St → St\n\n {- variable declarations -} \n decl : String → Exp nat → St → St\n \n _:=_ : String → Exp nat → St\n skip : St\n _,_ : St → St → St\n if_then_else_ : Exp bool → St → St → St\n while_do_ : Exp bool → St → St\n ret : Exp nat → St\n\n\n{- The environment contains numbers and functions -}\ndata Entry : Set where\n nat : ℕ → Entry\n fun : List String → St → Entry\n\n{- The environment is now keyed by strings (rather than de Bruijn indices) -}\nEnv : Set\nEnv = List (String × Entry)\n\n_,ₙ_ : String → ℕ → (String × Entry)\nv ,ₙ n = v , nat n\ninfixr 5 _,ₙ_\n\n{-\nA note on the return statement:\n\nThe book recommends two way for dealing with exceptions and jumps.\n\nOne way is to use small-step semantics. The other way is to introduce new program\nstates in big-step semantics. With more complicated derivation rules and many\ntypes of non-local effects (and of course non-determinism), small-step semantics\nseems to be more manageable.\n\nBut here we have just the return statement, so big-step semantics seems fine.\n-}\n\ndata State : Set where\n ok : Env → State\n ret : ℕ → State\n\nret-inj : ∀ {a b} → (State ∋ ret a) ≡ ret b → a ≡ b\nret-inj refl = refl\n\nok-inj : ∀ {s s'} → ok s ≡ ok s' → s ≡ s'\nok-inj refl = refl\n\n\n-- Well-scopedness\n--------------------------------------------------\n\n\n{-\nScoping rules are nontrivial, but we don't want to clutter our derivations\nwith explicit proofs for them.\n\nA standard Agda solution for this is to use so-called irrelevant proofs. Such\ntypes have at most a single value up to definitional equality, therefore they\ncannot influence actual computation. Agda is willing to automatically fill in\nthe value for some of these types once it becomes apparent that the value exists.\n\nThe simplest example of a irrelevant type is the unit type.\n\n record ⊤ : Set where constructor tt. \n\nAgda has eta-extensionality for records, so Agda thinks that any value of\ntype ⊤ is definitionally equal to \"tt\".\n\nThe well-scopedness predicates below all compute to ⊤ or ⊥ (the unprovable type),\nand both are irrelevant, so we get all the scoping proofs nicely inferred\nand hidden.\n\nWe also augment our inference system with judicious use of instance arguments.\nAgda tries to search for suitable values for these arguments from the current scope.\n-}\n\n------------------------------------------------------------\n\n{-\nA note on static semantics:\n\nArguably, well-scopedness should belong to static semantics. After all,\nit can be checked without running the program, and in real compilers\nscope checking also tends to be done statically.\n\nHere, we don't *have* static semantics at all. The static semantic rules are baked into\nthe dynamic semantic rules. Adding proper static semantics would be one of the many potential\nextensions and improvements to this library.\n\nIdeally, we would have a completely raw AST, and an AST for code that is correct\nwith respect to static semantics (so it's annotated with proofs of static correctness).\n\nWe would also have a type checker function that would decide if a raw AST can be converted\nto the correct AST. It would also nice to have a type erasure function that goes in the opposite\ndirection (erases proofs and returns a raw AST), and we could establish correctness of type\nchecking with respect to erasure, for example by proving that checking is the left inverse\nof erasure.\n\nIt may be also the case, although I haven't tested it, that type checking would be faster\nwith a separate checked AST.\n-}\n\n\n-- variable is in scope\nInScopeVar : String → Env → Set\nInScopeVar v [] = ⊥\nInScopeVar v ((_ , fun _ _) ∷ s) = InScopeVar v s\nInScopeVar v ((v' , nat n) ∷ s) with v ≡⁇ v'\n... | yes _ = ⊤\n... | no _ = InScopeVar v s\n\n-- function is in scope\nInScopeFun : String → Env → Set\nInScopeFun v [] = ⊥\nInScopeFun v ((_ , nat _) ∷ s) = InScopeFun v s\nInScopeFun v ((v' , fun _ _) ∷ s) with v ≡⁇ v'\n... | yes _ = ⊤\n... | no _ = InScopeFun v s\n\nlookupVar : ∀ v s ⦃ _ : InScopeVar v s ⦄ → ℕ\nlookupVar v [] ⦃ ⦄\nlookupVar v ((_ , fun _ _) ∷ s) = lookupVar v s \nlookupVar v ((v' , nat n) ∷ s) with v ≡⁇ v'\n... | yes _ = n\n... | no _ = lookupVar v s\n\nlookupFun : ∀ f s ⦃ _ : InScopeFun f s ⦄ → List String × St\nlookupFun v [] ⦃ ⦄\nlookupFun v ((_ , nat _) ∷ s) = lookupFun v s\nlookupFun v ((v' , fun args body) ∷ s) with v ≡⁇ v'\n... | yes _ = args , body\n... | no _ = lookupFun v s\n\n-- perform a substitution on the environment at a name that is in scope\n_[_]≔_ : ∀ s v ⦃ _ : InScopeVar v s ⦄ → ℕ → Env\n_[_]≔_ [] _ ⦃ ⦄ _\n_[_]≔_ ((v' , fun args body) ∷ s) v n = (v' , fun args body) ∷ (s [ v ]≔ n)\n((v' , nat n) ∷ Γ) [ v ]≔ n' with v ≡⁇ v'\n... | yes p = (v' , nat n') ∷ Γ\n... | no ¬p = (v' , nat n ) ∷ Γ [ v ]≔ n'\n\n-- Match the length of two lists\nArgLenMatch : List String → List ℕ → Set\nArgLenMatch [] [] = ⊤\nArgLenMatch [] (_ ∷ _) = ⊥\nArgLenMatch (_ ∷ names) [] = ⊥\nArgLenMatch (_ ∷ names) (_ ∷ vals) = ArgLenMatch names vals\n\n-- Create a new environment with the function arguments pushed to the front\ncallWith : ∀ args vals ⦃ _ : ArgLenMatch args vals ⦄ → Env\ncallWith [] [] = []\ncallWith [] (_ ∷ _) ⦃ ⦄\ncallWith (_ ∷ _) [] ⦃ ⦄\ncallWith (n ∷ names) (v ∷ vals) = (n , nat v) ∷ callWith names vals\n\n\n-- Semantics\n--------------------------------------------------\n\nmutual\n -- Evaluation of argument lists\n infixr 5 _∷_\n data _⟨_⟩ᵃ⟱_ (s : Env) : List (Exp nat) → List ℕ → Set where\n\n [] : \n ----------------\n s ⟨ [] ⟩ᵃ⟱ []\n\n _∷_ : \n ∀ {a args v vals} → \n s ⟨ a ⟩ᵉ⟱ v → s ⟨ args ⟩ᵃ⟱ vals \n → ---------------------------------\n s ⟨ a ∷ args ⟩ᵃ⟱ (v ∷ vals)\n\n \n -- Shorthand for the evaluation of binary expressions\n BinExp : ∀ {s t r} → (Exp t → Exp t → Exp r) → (⟦ t ⟧ᵗ → ⟦ t ⟧ᵗ → ⟦ r ⟧ᵗ) → Set\n BinExp {s} cons op = \n ∀ {a b va vb} → \n s ⟨ a ⟩ᵉ⟱ va → s ⟨ b ⟩ᵉ⟱ vb \n -----------------------------\n → s ⟨ cons a b ⟩ᵉ⟱ (op va vb)\n\n\n -- Evaluation of expressions\n data _⟨_⟩ᵉ⟱_ (s : Env) : ∀ {t} → Exp t → ⟦ t ⟧ᵗ → Set where\n\n add : BinExp add _+_\n eq : BinExp eq (λ a b → ⌊ a ≡⁇ b ⌋)\n lt : BinExp lt (λ a b → ⌊ suc a ≤⁇ b ⌋)\n lte : BinExp lte (λ a b → ⌊ a ≤⁇ b ⌋)\n and : BinExp and _∧_\n or : BinExp or _∨_ \n mul : BinExp mul _*_\n sub : BinExp sub _∸_\n tt : s ⟨ tt ⟩ᵉ⟱ true\n ff : s ⟨ ff ⟩ᵉ⟱ false\n lit : ∀ {n} → s ⟨ lit n ⟩ᵉ⟱ n\n not : ∀ {e b} → s ⟨ e ⟩ᵉ⟱ b → s ⟨ not e ⟩ᵉ⟱ bnot b \n\n var : \n ∀ {v in-scope}\n → ----------------------------\n s ⟨ var v ⟩ᵉ⟱ lookupVar v s\n\n {- Evaluation of function calls -}\n _$:_ : \n {retVal : ℕ} \n {argVals : List ℕ}\n {f : String} -- if we have a function\n {args : List (Exp nat)} -- and a list of arguments\n ⦃ in-scope-f : InScopeFun f s ⦄ -- and the function is in scope\n\n → let func = lookupFun f s \n argNames = proj₁ func \n body = proj₂ func in \n\n s ⟨ args ⟩ᵃ⟱ argVals -- we can evaluate the arguments\n → ⦃ arg-len-match : ArgLenMatch argNames argVals ⦄ -- and the number of arguments is correct\n\n -- note the recursive occurence in the call environement ⇓ \n → let callEnv = callWith argNames argVals <> [ (f , fun argNames body) ] in\n\n ⟨ body , ok callEnv ⟩⟱ ret retVal\n → ----------------------------------- -- then a function call evaluates to the return value\n s ⟨ f $: args ⟩ᵉ⟱ retVal -- of the function body evaluated in the call environment\n \n -- Evaluation of statements\n data ⟨_,_⟩⟱_ : St → State → State → Set where\n\n fun : \n ∀ {x s s' S args body} → \n ⟨ S , ok ((x , fun args body) ∷ s) ⟩⟱ ok ((x , fun args body) ∷ s')\n → -------------------------------------------------------------------\n ⟨ fun x args body S , ok s ⟩⟱ ok s'\n\n {-- This rule propagates (\"rethrows\") the return statement's effect if it happens inside the\n scope of the function declaration --}\n fun-ret : \n ∀ {x s r S args body} → \n ⟨ S , ok ((x , fun args body) ∷ s) ⟩⟱ ret r\n → --------------------------------------------\n ⟨ fun x args body S , ok s ⟩⟱ ret r\n\n {- variable declarations -}\n decl :\n ∀ {s s' S x e eVal e'} → \n s ⟨ e ⟩ᵉ⟱ eVal → \n ⟨ S , ok ((x , nat eVal) ∷ s) ⟩⟱ (ok ((x , e') ∷ s'))\n → ----------------------------------------------------\n ⟨ decl x e S , ok s ⟩⟱ ok s'\n\n {- variable declarations propagating the return statement -}\n decl-ret :\n ∀ {r s S x e eVal} → \n s ⟨ e ⟩ᵉ⟱ eVal → \n ⟨ S , ok ((x , nat eVal) ∷ s) ⟩⟱ ret r\n → ---------------------------------------\n ⟨ decl x e S , ok s ⟩⟱ ret r\n \n ret :\n ∀ {e eVal s}\n → s ⟨ e ⟩ᵉ⟱ eVal\n → ---------------------------\n ⟨ ret e , ok s ⟩⟱ ret eVal\n \n ass : \n ∀ {s e eVal x in-scope} → \n s ⟨ e ⟩ᵉ⟱ eVal \n → --------------------------------------\n ⟨ x := e , ok s ⟩⟱ ok (s [ x ]≔ eVal)\n \n skip : \n ∀ {s} \n → -----------------\n ⟨ skip , s ⟩⟱ s \n \n _,_ :\n ∀ {s₁ s₂ s₃ S₁ S₂} → \n ⟨ S₁ , s₁ ⟩⟱ ok s₂ → ⟨ S₂ , ok s₂ ⟩⟱ s₃ \n → --------------------------------------\n ⟨ (S₁ , S₂ ) , s₁ ⟩⟱ s₃\n\n {-- If we return in the left statement of a composite statement,\n then we ignore the right statement and just return -} \n _ret,_ :\n ∀ {x s₁ s₂ S₁ S₂} → \n ⟨ S₁ , s₁ ⟩⟱ ret x → ⟨ S₂ , ret x ⟩⟱ s₂\n → ---------------------------------------\n ⟨ (S₁ , S₂ ) , s₁ ⟩⟱ ret x\n \n if-true :\n ∀ {s s' S₁ S₂ b} →\n s ⟨ b ⟩ᵉ⟱ true → ⟨ S₁ , ok s ⟩⟱ s'\n → ------------------------------------\n ⟨ if b then S₁ else S₂ , ok s ⟩⟱ s' \n\n if-false :\n ∀ {s s' S₁ S₂ b} → \n s ⟨ b ⟩ᵉ⟱ false → ⟨ S₂ , ok s ⟩⟱ s'\n → -------------------------------------\n ⟨ if b then S₁ else S₂ , ok s ⟩⟱ s' \n \n while-true :\n ∀ {s s' s'' S b} → \n s ⟨ b ⟩ᵉ⟱ true → ⟨ S , ok s ⟩⟱ s' → ⟨ while b do S , s' ⟩⟱ s''\n → ------------------------------------------------------------------\n ⟨ while b do S , ok s ⟩⟱ s''\n \n while-false :\n ∀ {s S b} → \n s ⟨ b ⟩ᵉ⟱ false \n → ------------------------------\n ⟨ while b do S , ok s ⟩⟱ ok s\n\n\n \nsubstExp : ∀ {t s}{e : Exp t}{v v'} → v ≡ v' → s ⟨ e ⟩ᵉ⟱ v → s ⟨ e ⟩ᵉ⟱ v'\nsubstExp refl p2 = p2\n\n\n\n-- State transition is deterministic\n--------------------------------------------------\n\ndeterministic : ∀ {S s s' s''} → ⟨ S , s ⟩⟱ s' → ⟨ S , s ⟩⟱ s'' → s' ≡ s''\ndeterministic = st where \n mutual\n args : ∀ {s as vs vs'} → s ⟨ as ⟩ᵃ⟱ vs → s ⟨ as ⟩ᵃ⟱ vs' → vs ≡ vs'\n args [] [] = refl\n args (x ∷ p1) (x₁ ∷ p2) rewrite exp x x₁ | args p1 p2 = refl\n\n exp : ∀ {t s}{e : Exp t}{v v'} → s ⟨ e ⟩ᵉ⟱ v → s ⟨ e ⟩ᵉ⟱ v' → v ≡ v'\n exp (add p1 p2) (add p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl\n exp (sub p1 p2) (sub p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl \n exp (eq p1 p2) (eq p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl\n exp (lt p1 p2) (lt p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl\n exp (lte p1 p2) (lte p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl\n exp (and p1 p2) (and p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl\n exp (or p1 p2) (or p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl\n exp (mul p1 p2) (mul p3 p4) rewrite exp p1 p3 | exp p2 p4 = refl\n exp tt tt = refl\n exp ff ff = refl\n exp lit lit = refl\n exp (not p1) (not p2) rewrite exp p1 p2 = refl\n exp var var = refl\n exp (_$:_ ae be) (_$:_ ae' be') rewrite args ae ae' = ret-inj (st be be')\n \n st : ∀ {S s s' s''} → ⟨ S , s ⟩⟱ s' → ⟨ S , s ⟩⟱ s'' → s' ≡ s''\n st (fun p1) (fun p2) = cong ok $ proj₂ $ ∷-injective $ ok-inj $ st p1 p2\n st (fun p1) (fun-ret p2) with st p1 p2\n ... | ()\n st (fun-ret p1) (fun p2) with st p1 p2\n ... | ()\n st (fun-ret p1) (fun-ret p2) = st p1 p2\n st (decl x₁ p1) (decl x₂ p2) rewrite \n exp x₁ x₂ = cong ok $ proj₂ $ ∷-injective $ ok-inj $ st p1 p2\n st (decl x₁ p1) (decl-ret x₂ p2) rewrite exp x₁ x₂ with st p1 p2\n ... | ()\n st (decl-ret x₁ p1) (decl x₂ p2) rewrite exp x₁ x₂ with st p1 p2\n ... | () \n st (decl-ret x₁ p1) (decl-ret x₂ p2) rewrite exp x₁ x₂ = st p1 p2\n st (ret x) (ret x₁) rewrite exp x x₁ = refl\n st (ass x₁) (ass x₂) rewrite exp x₁ x₂ = refl\n st skip skip = refl\n st (p1 , p2) (p3 , p4) rewrite st p1 p3 = st p2 p4\n st (p1 , p2) (p3 ret, p4) with st p1 p3\n ... | () \n st (p1 ret, p2) (p3 , p4) with st p1 p3\n ... | ()\n st (p1 ret, p2) (p3 ret, p4) = st p1 p3\n st (if-true x p1) (if-true x₁ p2) rewrite st p1 p2 = refl\n st (if-true x p1) (if-false x₁ p2) with exp x₁ x\n ... | ()\n st (if-false x p1) (if-true x₁ p2) with exp x x₁\n ... | ()\n st (if-false x p1) (if-false x₁ p2) rewrite st p1 p2 = refl\n st (while-true x p1 p2) (while-true x₁ p3 p4) rewrite st p1 p3 | st p2 p4 = refl\n st (while-true x p1 p2) (while-false x₁) with exp x x₁\n ... | ()\n st (while-false x) (while-true x₁ p2 p3) with exp x x₁\n ... | ()\n st (while-false x) (while-false x₁) = refl\n\n\n-- Divergence \n--------------------------------------------------\n\n_divergesOn_ : St → State → Set\nprog divergesOn s = ∀ {s'} → ¬ ⟨ prog , s ⟩⟱ s'\n\nDivergent : St → Set\nDivergent prog = ∀ {s} → prog divergesOn s\n\nprivate\n inf-loop : Divergent (while tt do skip)\n inf-loop (while-true tt p p₁) = inf-loop p₁\n inf-loop (while-false ()) \n\n\n-- Semantic equivalence\n--------------------------------------------------\n\n_⇔_ : ∀ {a b} → Set a → Set b → Set (a L.⊔ b)\nA ⇔ B = (A → B) × (B → A)\n\nSemanticEq : St → St → Set\nSemanticEq pa pb = ∀ {s s'} → ⟨ pa , s ⟩⟱ s' ⇔ ⟨ pb , s ⟩⟱ s'\n\nSemantic⇒ : St → St → Set\nSemantic⇒ pa pb = ∀ {s s'} → ⟨ pa , s ⟩⟱ s' → ⟨ pb , s ⟩⟱ s'\n\n\n\n-- -- Correctness of factorial programs\n-- --------------------------------------------------\n\nprivate\n\n --- Semantics in meta-langauge\n ⟦fac⟧ : ℕ → ℕ\n ⟦fac⟧ zero = 1\n ⟦fac⟧ (suc n) = suc n * ⟦fac⟧ n\n\n\n -- 1. Correctness of recursive definition\n fac-rec-body : St\n fac-rec-body = \n if lte (var \"n\") (lit 0) then\n (ret (lit 1))\n else\n (ret (mul (var \"n\") (\"fac\" $: [ sub (var \"n\") (lit 1) ] )))\n\n fac-rec : St\n fac-rec =\n fun \"fac\" [ \"n\" ] fac-rec-body\n (ret (\"fac\" $: [ var \"n\" ]))\n\n fac-rec-body-ok :\n ∀ n\n → ⟨ fac-rec-body , \n ok ((\"n\" ,ₙ n) ∷ (\"fac\" , fun [ \"n\" ] fac-rec-body) ∷ []) ⟩⟱ \n ret (⟦fac⟧ n) \n fac-rec-body-ok zero = if-true (lte var lit) (ret lit)\n fac-rec-body-ok (suc n) = \n if-false (lte var lit) \n (ret (mul var ((sub var lit ∷ []) $: (fac-rec-body-ok n))))\n\n fac-rec-ok :\n ∀ n → ⟨ fac-rec , ok [ (\"n\" ,ₙ n) ] ⟩⟱ ret (⟦fac⟧ n)\n fac-rec-ok n = fun-ret (ret ((var ∷ []) $: (fac-rec-body-ok n)))\n\n\n -- 2. Correctness of procedural definition\n fac-loop : St\n fac-loop =\n while lt (var \"i\") (var \"n\") do ( \n \"i\" := add (lit 1) (var \"i\") ,\n \"acc\" := mul (var \"i\") (var \"acc\")\n )\n\n fac-proc : St\n fac-proc =\n fun \"fac\" ( \"n\" ∷ []) (\n decl \"i\" (lit 0) (\n decl \"acc\" (lit 1) (\n fac-loop ,\n ret (var \"acc\") )))\n (ret (\"fac\" $: [ var \"n\" ]))\n\n fac-loop-ok :\n ∀ {s} d i \n → ⟨ fac-loop ,\n ok ((\"acc\",ₙ ⟦fac⟧ i) ∷ (\"i\",ₙ i ) ∷ (\"n\",ₙ d + i) ∷ s) ⟩⟱ \n ok ((\"acc\",ₙ ⟦fac⟧ (d + i)) ∷ (\"i\",ₙ d + i) ∷ (\"n\",ₙ d + i) ∷ s)\n\n fac-loop-ok zero i = while-false (substExp (¬A→≡false (a≮a i)) (lt var var))\n fac-loop-ok (suc d) i with fac-loop-ok d (suc i)\n ... | next rewrite +-suc d i = \n while-true (substExp (A→≡true (a>= λ{(x ∷ xs) → put (♭ xs) >> return x}\n\n go : {Γ : Environment} (bound : {w : Type} → w ∈ Γ → String) → ⊢ Γ → State (Stream String) String\n go bound ax\n = return (boundˣ ++ \"<->\" ++ boundʸ)\n where\n boundˣ = bound (here P.refl)\n boundʸ = bound (there (here P.refl))\n go bound (cut {Γ} {Δ} {A} x y) = fresh >>= withFresh\n where\n withFresh : String → State (Stream String) String\n withFresh boundˣ\n = go bound₁ x >>= λ x'\n → go bound₂ y >>= λ y'\n → return (\"new \" ++ boundˣ ++ \".(\" ++ x' ++ \"|\" ++ y' ++ \")\")\n where\n bound₁ : {w : Type} → w ∈ A ∷ Γ → String\n bound₁ (here px) = boundˣ\n bound₁ (there i) = bound (++ˡ i)\n bound₂ : {w : Type} → w ∈ A ^ ∷ Δ → String\n bound₂ (here px) = boundˣ\n bound₂ (there i) = bound (++ʳ Γ i)\n go bound (send {Γ} {Δ} {A} {B} x y) = fresh >>= withFresh\n where\n withFresh : String → State (Stream String) String\n withFresh boundʸ\n = go bound₁ x >>= λ x'\n → go bound₂ y >>= λ y'\n → return (boundˣ ++ \"[\" ++ boundʸ ++ \"].(\" ++ x' ++ \"|\" ++ y' ++ \")\")\n where\n boundˣ = bound (here P.refl)\n bound₁ : {w : Type} → w ∈ A ∷ Γ → String\n bound₁ (here px) = boundʸ\n bound₁ (there i) = bound (there (++ˡ i))\n bound₂ : {w : Type} → w ∈ B ∷ Δ → String\n bound₂ (here px) = bound (here P.refl)\n bound₂ (there i) = bound (there (++ʳ Γ i))\n go bound (recv {Γ} {A} {B} x) = fresh >>= withFresh\n where\n withFresh : String → State (Stream String) String\n withFresh boundʸ\n = go bound₁ x >>= λ x'\n → return (boundˣ ++ \"(\" ++ boundʸ ++ \").\" ++ x')\n where\n boundˣ = bound (here P.refl)\n bound₁ : {w : Type} → w ∈ A ∷ B ∷ Γ → String\n bound₁ (here px) = boundʸ\n bound₁ (there (here px)) = boundˣ\n bound₁ (there (there i)) = bound (there i)\n go bound (sel₁ {Γ} {A} {B} x)\n = go bound₁ x >>= λ x'\n → return (boundˣ ++ \"[inl].\" ++ x')\n where\n boundˣ = bound (here P.refl)\n bound₁ : {w : Type} → w ∈ A ∷ Γ → String\n bound₁ (here px) = boundˣ\n bound₁ (there i) = bound (there i)\n go bound (sel₂ {Γ} {A} {B} x)\n = go bound₁ x >>= λ x'\n → return (boundˣ ++ \"[inr].\" ++ x')\n where\n boundˣ = bound (here P.refl)\n bound₁ : {w : Type} → w ∈ B ∷ Γ → String\n bound₁ (here px) = boundˣ\n bound₁ (there i) = bound (there i)\n go bound (case {Γ} {A} {B} x y)\n = go bound₁ x >>= λ x'\n → go bound₂ y >>= λ y'\n → return (\"case \" ++ boundˣ ++ \" {\" ++ x' ++ \";\" ++ y' ++ \"}\")\n where\n boundˣ = bound (here P.refl)\n bound₁ : {w : Type} → w ∈ A ∷ Γ → String\n bound₁ (here px) = boundˣ\n bound₁ (there i) = bound (there i)\n bound₂ : {w : Type} → w ∈ B ∷ Γ → String\n bound₂ (here px) = boundˣ\n bound₂ (there i) = bound (there i)\n go bound halt\n = return (boundˣ ++ \"[].0\")\n where\n boundˣ = bound (here P.refl)\n go bound (wait x)\n = go (bound ∘ there) x >>= λ x'\n → return (boundˣ ++ \"().\" ++ x')\n where\n boundˣ = bound (here P.refl)\n go bound loop\n = return (\"case \" ++ boundˣ ++ \" {;}\")\n where\n boundˣ = bound (here P.refl)\n go bound (mk?₁ {Γ} {A} x) = fresh >>= withFresh\n where\n withFresh : String → State (Stream String) String\n withFresh boundʸ\n = go bound₁ x >>= λ x'\n → return (\"?\" ++ boundˣ ++ \"[\" ++ boundʸ ++ \"].\" ++ x')\n where\n boundˣ = bound (here P.refl)\n bound₁ : {w : Type} → w ∈ A ∷ Γ → String\n bound₁ (here px) = boundʸ\n bound₁ (there i) = bound (there i)\n go bound (mk!₁ {Γ} {A} x) = fresh >>= withFresh\n where\n withFresh : String → State (Stream String) String\n withFresh boundʸ\n = go bound₁ x >>= λ x'\n → return (\"!\" ++ boundˣ ++ \"(\" ++ boundʸ ++ \").\" ++ x')\n where\n boundˣ = bound (here P.refl)\n bound₁ : {w : Type} → w ∈ A ∷ Γ → String\n bound₁ (here px) = boundʸ\n bound₁ (there i) = bound (there i)\n go bound (cont {Γ} {A} {m} {n} x)\n = go bound₁ x\n where\n boundˣ = bound (here P.refl)\n bound₁ : {w : Type} → w ∈ ?[ m ] A ∷ ?[ n ] A ∷ Γ → String\n bound₁ (here px) = boundˣ\n bound₁ (there (here px)) = boundˣ\n bound₁ (there (there i)) = bound (there i)\n go bound (pool {Γ} {Δ} {A} {m} {n} x y)\n = go bound₁ x >>= λ x'\n → go bound₂ y >>= λ y'\n → return (\"(\" ++ x' ++ \"|\" ++ y' ++ \")\")\n where\n boundˣ = bound (here P.refl)\n bound₁ : {w : Type} → w ∈ ![ m ] A ∷ Γ → String\n bound₁ (here px) = boundˣ\n bound₁ (there i) = bound (there (++ˡ i))\n bound₂ : {w : Type} → w ∈ ![ n ] A ∷ Δ → String\n bound₂ (here px) = boundˣ\n bound₂ (there i) = bound (there (++ʳ Γ i))\n go bound (exch b x) = go (bound ∘ (to b ⟨$⟩_)) x\n\n bound : {w : Type} → w ∈ Γ → String\n bound i = V.lookup (toFin i) (X.take (length Γ) names)\n where\n toFin : {Γ : Environment} {w : Type} → w ∈ Γ → Fin (length Γ)\n toFin (here px) = zero\n toFin (there i) = suc (toFin i)\n\n state : Stream String\n state = X.drop (length Γ) names\n", "meta": {"hexsha": "899b812e302c13f7f807a950fa38730c70e0de18", "size": 6804, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/cpnd1/nodcap/Show.agda", "max_stars_repo_name": "wenkokke/nodcap", "max_stars_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-09-05T08:58:11.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-24T20:16:35.000Z", "max_issues_repo_path": "src/cpnd1/nodcap/Show.agda", "max_issues_repo_name": "pepijnkokke/nodcap", "max_issues_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2", "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/cpnd1/nodcap/Show.agda", "max_forks_repo_name": "pepijnkokke/nodcap", "max_forks_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-09-05T08:58:13.000Z", "max_forks_repo_forks_event_max_datetime": "2018-09-05T08:58:13.000Z", "avg_line_length": 37.3846153846, "max_line_length": 101, "alphanum_fraction": 0.5052910053, "num_tokens": 2213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.37251712502215745}} {"text": "\nmodule Haskell.Prim.Ord where\n\nopen import Agda.Builtin.Nat as Nat hiding (_==_; _<_)\nopen import Agda.Builtin.Char\n\nopen import Haskell.Prim\nopen import Haskell.Prim.Eq\nopen import Haskell.Prim.Bool\nopen import Haskell.Prim.Int\nopen import Haskell.Prim.Word\nopen import Haskell.Prim.Integer\nopen import Haskell.Prim.Double\nopen import Haskell.Prim.Tuple\nopen import Haskell.Prim.Monoid\nopen import Haskell.Prim.List\nopen import Haskell.Prim.Maybe\nopen import Haskell.Prim.Either\n\n--------------------------------------------------\n-- Ordering\n\ndata Ordering : Set where\n LT EQ GT : Ordering\n\ninstance\n iEqOrdering : Eq Ordering\n iEqOrdering ._==_ LT LT = true\n iEqOrdering ._==_ EQ EQ = true\n iEqOrdering ._==_ GT GT = true\n iEqOrdering ._==_ _ _ = false\n\n iSemigroupOrdering : Semigroup Ordering\n iSemigroupOrdering ._<>_ LT _ = LT\n iSemigroupOrdering ._<>_ EQ o = o\n iSemigroupOrdering ._<>_ GT _ = GT\n\n iMonoidOrdering : Monoid Ordering\n iMonoidOrdering .mempty = EQ\n\n--------------------------------------------------\n-- Ord\n\nrecord Ord (a : Set) : Set where\n field\n compare : a → a → Ordering\n _<_ : a → a → Bool\n _>_ : a → a → Bool\n _>=_ : a → a → Bool\n _<=_ : a → a → Bool\n max : a → a → a\n min : a → a → a\n overlap ⦃ super ⦄ : Eq a\n\n infix 4 _<_ _>_ _<=_ _>=_\n\nopen Ord ⦃ ... ⦄ public\n\n{-# COMPILE AGDA2HS Ord existing-class #-}\n\nordFromCompare : ⦃ Eq a ⦄ → (a → a → Ordering) → Ord a\nordFromCompare cmp .compare = cmp\nordFromCompare cmp ._<_ x y = cmp x y == LT\nordFromCompare cmp ._>_ x y = cmp x y == GT\nordFromCompare cmp ._<=_ x y = cmp x y /= GT\nordFromCompare cmp ._>=_ x y = cmp x y /= LT\nordFromCompare cmp .max x y = if cmp x y == LT then y else x\nordFromCompare cmp .min x y = if cmp x y == GT then y else x\n\nordFromLessThan : ⦃ Eq a ⦄ → (a → a → Bool) → Ord a\nordFromLessThan _<_ .compare x y = if x < y then LT else if x == y then EQ else GT\nordFromLessThan _<_ ._<_ x y = x < y\nordFromLessThan _<_ ._>_ x y = y < x\nordFromLessThan _<_ ._<=_ x y = x < y || x == y\nordFromLessThan _<_ ._>=_ x y = y < x || x == y\nordFromLessThan _<_ .max x y = if x < y then y else x\nordFromLessThan _<_ .min x y = if y < x then y else x\n\nordFromLessEq : ⦃ Eq a ⦄ → (a → a → Bool) → Ord a\nordFromLessEq _<=_ .compare x y = if x == y then EQ else if x <= y then LT else GT\nordFromLessEq _<=_ ._<_ x y = x <= y && not (x == y)\nordFromLessEq _<=_ ._>_ x y = y <= x && not (x == y)\nordFromLessEq _<=_ ._<=_ x y = x <= y\nordFromLessEq _<=_ ._>=_ x y = y <= x\nordFromLessEq _<=_ .max x y = if y <= x then x else y\nordFromLessEq _<=_ .min x y = if x <= y then x else y\n\nprivate\n compareFromLt : ⦃ Eq a ⦄ → (a → a → Bool) → a → a → Ordering\n compareFromLt _<_ x y = if x < y then LT else if x == y then EQ else GT\n\ninstance\n iOrdNat : Ord Nat\n iOrdNat = ordFromLessThan Nat._<_\n\n iOrdInteger : Ord Integer\n iOrdInteger = ordFromLessThan ltInteger\n\n iOrdInt : Ord Int\n iOrdInt = ordFromLessThan ltInt\n\n iOrdWord : Ord Word\n iOrdWord = ordFromLessThan ltWord\n\n iOrdDouble : Ord Double\n iOrdDouble = ordFromLessThan primFloatNumericalLess\n\n iOrdChar : Ord Char\n iOrdChar = ordFromLessThan λ x y → primCharToNat x < primCharToNat y\n\n iOrdBool : Ord Bool\n iOrdBool = ordFromCompare λ where\n false true → LT\n true false → GT\n _ _ → EQ\n\n iOrdTuple₀ : Ord (Tuple [])\n iOrdTuple₀ = ordFromCompare λ _ _ → EQ\n\n iOrdTuple : ∀ {as} → ⦃ Ord a ⦄ → ⦃ Ord (Tuple as) ⦄ → Ord (Tuple (a ∷ as))\n iOrdTuple = ordFromCompare λ where (x ∷ xs) (y ∷ ys) → compare x y <> compare xs ys\n\ncompareList : ⦃ Ord a ⦄ → List a → List a → Ordering\ncompareList [] [] = EQ\ncompareList [] (_ ∷ _) = LT\ncompareList (_ ∷ _) [] = GT\ncompareList (x ∷ xs) (y ∷ ys) = compare x y <> compareList xs ys\n\ninstance\n iOrdList : ⦃ Ord a ⦄ → Ord (List a)\n iOrdList = ordFromCompare compareList\n\n iOrdMaybe : ⦃ Ord a ⦄ → Ord (Maybe a)\n iOrdMaybe = ordFromCompare λ where\n Nothing Nothing → EQ\n Nothing (Just _) → LT\n (Just _) Nothing → GT\n (Just x) (Just y) → compare x y\n\n iOrdEither : ⦃ Ord a ⦄ → ⦃ Ord b ⦄ → Ord (Either a b)\n iOrdEither = ordFromCompare λ where\n (Left x) (Left y) → compare x y\n (Left _) (Right _) → LT\n (Right _) (Left _) → GT\n (Right x) (Right y) → compare x y\n\n iOrdOrdering : Ord Ordering\n iOrdOrdering = ordFromCompare λ where\n LT LT → EQ\n LT _ → LT\n _ LT → GT\n EQ EQ → EQ\n EQ GT → LT\n GT EQ → GT\n GT GT → EQ\n", "meta": {"hexsha": "cb67ab2d5ca8f23a3591394ad2f79b2037ddceac", "size": 4465, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lib/Haskell/Prim/Ord.agda", "max_stars_repo_name": "dxts/agda2hs", "max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6", "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": "lib/Haskell/Prim/Ord.agda", "max_issues_repo_name": "dxts/agda2hs", "max_issues_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6", "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": "lib/Haskell/Prim/Ord.agda", "max_forks_repo_name": "dxts/agda2hs", "max_forks_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6", "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": 28.6217948718, "max_line_length": 85, "alphanum_fraction": 0.6145576708, "num_tokens": 1570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.640635868562172, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.3724036103727947}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- A universe of proposition functors, along with some properties\n------------------------------------------------------------------------\n\nmodule Relation.Nullary.Universe where\n\nopen import Relation.Nullary\nopen import Relation.Nullary.Negation\nopen import Relation.Binary hiding (_⇒_)\nopen import Relation.Binary.Simple\nopen import Relation.Binary.PropositionalEquality as PropEq\n using (_≡_; refl)\nopen import Relation.Binary.Sum\nopen import Relation.Binary.Product.Pointwise\nopen import Data.Sum as Sum hiding (map)\nopen import Data.Product as Prod hiding (map)\nopen import Function\nimport Function.Equality as FunS\nopen import Data.Empty\nopen import Category.Applicative\nopen import Category.Monad\nopen import Level\n\ninfix 5 ¬¬_\ninfixr 4 _⇒_\ninfixr 3 _∧_\ninfixr 2 _∨_\ninfix 1 ⟨_⟩_≈_\n\n-- The universe.\n\ndata PropF p : Set (suc p) where\n Id : PropF p\n K : (P : Set p) → PropF p\n _∨_ : (F₁ F₂ : PropF p) → PropF p\n _∧_ : (F₁ F₂ : PropF p) → PropF p\n _⇒_ : (P₁ : Set p) (F₂ : PropF p) → PropF p\n ¬¬_ : (F : PropF p) → PropF p\n\n-- Equalities for universe inhabitants.\n\nmutual\n\n setoid : ∀ {p} → PropF p → Set p → Setoid p p\n setoid Id P = PropEq.setoid P\n setoid (K P) _ = PropEq.setoid P\n setoid (F₁ ∨ F₂) P = (setoid F₁ P) ⊎-setoid (setoid F₂ P)\n setoid (F₁ ∧ F₂) P = (setoid F₁ P) ×-setoid (setoid F₂ P)\n setoid (P₁ ⇒ F₂) P = FunS.≡-setoid P₁\n (Setoid.indexedSetoid (setoid F₂ P))\n setoid (¬¬ F) P = Always-setoid (¬ ¬ ⟦ F ⟧ P)\n\n ⟦_⟧ : ∀ {p} → PropF p → (Set p → Set p)\n ⟦ F ⟧ P = Setoid.Carrier (setoid F P)\n\n⟨_⟩_≈_ : ∀ {p} (F : PropF p) {P : Set p} → Rel (⟦ F ⟧ P) p\n⟨_⟩_≈_ F = Setoid._≈_ (setoid F _)\n\n-- ⟦ F ⟧ is functorial.\n\nmap : ∀ {p} (F : PropF p) {P Q} → (P → Q) → ⟦ F ⟧ P → ⟦ F ⟧ Q\nmap Id f p = f p\nmap (K P) f p = p\nmap (F₁ ∨ F₂) f FP = Sum.map (map F₁ f) (map F₂ f) FP\nmap (F₁ ∧ F₂) f FP = Prod.map (map F₁ f) (map F₂ f) FP\nmap (P₁ ⇒ F₂) f FP = map F₂ f ∘ FP\nmap (¬¬ F) f FP = ¬¬-map (map F f) FP\n\nmap-id : ∀ {p} (F : PropF p) {P} → ⟨ ⟦ F ⟧ P ⇒ F ⟩ map F id ≈ id\nmap-id Id x = refl\nmap-id (K P) x = refl\nmap-id (F₁ ∨ F₂) (inj₁ x) = ₁∼₁ (map-id F₁ x)\nmap-id (F₁ ∨ F₂) (inj₂ y) = ₂∼₂ (map-id F₂ y)\nmap-id (F₁ ∧ F₂) (x , y) = (map-id F₁ x , map-id F₂ y)\nmap-id (P₁ ⇒ F₂) f = λ x → map-id F₂ (f x)\nmap-id (¬¬ F) ¬¬x = _\n\nmap-∘ : ∀ {p} (F : PropF p) {P Q R} (f : Q → R) (g : P → Q) →\n ⟨ ⟦ F ⟧ P ⇒ F ⟩ map F f ∘ map F g ≈ map F (f ∘ g)\nmap-∘ Id f g x = refl\nmap-∘ (K P) f g x = refl\nmap-∘ (F₁ ∨ F₂) f g (inj₁ x) = ₁∼₁ (map-∘ F₁ f g x)\nmap-∘ (F₁ ∨ F₂) f g (inj₂ y) = ₂∼₂ (map-∘ F₂ f g y)\nmap-∘ (F₁ ∧ F₂) f g x = (map-∘ F₁ f g (proj₁ x) ,\n map-∘ F₂ f g (proj₂ x))\nmap-∘ (P₁ ⇒ F₂) f g h = λ x → map-∘ F₂ f g (h x)\nmap-∘ (¬¬ F) f g x = _\n\n-- A variant of sequence can be implemented for ⟦ F ⟧.\n\nsequence : ∀ {p AF} → RawApplicative AF →\n (AF (Lift ⊥) → ⊥) →\n ({A B : Set p} → (A → AF B) → AF (A → B)) →\n ∀ F {P} → ⟦ F ⟧ (AF P) → AF (⟦ F ⟧ P)\nsequence {AF = AF} A extract-⊥ sequence-⇒ = helper\n where\n open RawApplicative A\n\n helper : ∀ F {P} → ⟦ F ⟧ (AF P) → AF (⟦ F ⟧ P)\n helper Id x = x\n helper (K P) x = pure x\n helper (F₁ ∨ F₂) (inj₁ x) = inj₁ <$> helper F₁ x\n helper (F₁ ∨ F₂) (inj₂ y) = inj₂ <$> helper F₂ y\n helper (F₁ ∧ F₂) (x , y) = _,_ <$> helper F₁ x ⊛ helper F₂ y\n helper (P₁ ⇒ F₂) f = sequence-⇒ (helper F₂ ∘ f)\n helper (¬¬ F) x =\n pure (λ ¬FP → x (λ fp → extract-⊥ (lift ∘ ¬FP <$> helper F fp)))\n\n-- Some lemmas about double negation.\n\nprivate\n open module M {p} = RawMonad (¬¬-Monad {p = p})\n\n¬¬-pull : ∀ {p} (F : PropF p) {P} →\n ⟦ F ⟧ (¬ ¬ P) → ¬ ¬ ⟦ F ⟧ P\n¬¬-pull = sequence rawIApplicative\n (λ f → f lower)\n (λ f g → g (λ x → ⊥-elim (f x (λ y → g (λ _ → y)))))\n\n¬¬-remove : ∀ {p} (F : PropF p) {P} →\n ¬ ¬ ⟦ F ⟧ (¬ ¬ P) → ¬ ¬ ⟦ F ⟧ P\n¬¬-remove F = negated-stable ∘ ¬¬-pull (¬¬ F)\n", "meta": {"hexsha": "c85f85821bc8b712dd1ed498ecd6355eb03e29ce", "size": 4167, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Nullary/Universe.agda", "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Nullary/Universe.agda", "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_licenses": ["Apache-2.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": "agda-stdlib-0.9/src/Relation/Nullary/Universe.agda", "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.336, "max_line_length": 72, "alphanum_fraction": 0.4941204704, "num_tokens": 1730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.3724036023959944}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\n\nopen import Cubical.Categories.Category\nopen import Cubical.Categories.Morphism renaming (isIso to isIsoC)\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Equiv\nopen Iso\nopen import Cubical.Foundations.HLevels\nopen Precategory\nopen import Cubical.Core.Glue\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Foundations.Transport using (transpFill)\n\nmodule Cubical.Categories.Constructions.Slice {ℓ ℓ' : Level} (C : Precategory ℓ ℓ') (c : C .ob) {{isC : isCategory C}} where\n\nopen import Cubical.Data.Sigma\n\n\n-- just a helper to prevent redundency\nTypeC : Type (ℓ-suc (ℓ-max ℓ ℓ'))\nTypeC = Type (ℓ-max ℓ ℓ')\n\n-- Components of a slice category\n\nrecord SliceOb : TypeC where\n constructor sliceob\n field\n {S-ob} : C .ob\n S-arr : C [ S-ob , c ]\n\nopen SliceOb public\n\nrecord SliceHom (a b : SliceOb) : Type ℓ' where\n constructor slicehom\n field\n S-hom : C [ S-ob a , S-ob b ]\n -- commutative diagram\n S-comm : S-hom ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a\n\nopen SliceHom public\n\n-- Helpers for working with equality\n-- can probably replace these by showing that SliceOb is isomorphic to Sigma and\n-- that paths are isomorphic to Sigma? But sounds like that would need a lot of transp\n\nSliceOb-≡-intro : ∀ {a b} {f g}\n → (p : a ≡ b)\n → PathP (λ i → C [ p i , c ]) f g\n → sliceob {a} f ≡ sliceob {b} g\nSliceOb-≡-intro p q = λ i → sliceob {p i} (q i)\n\nmodule _ {xf yg : SliceOb} where\n private\n x = xf .S-ob\n f = xf .S-arr\n y = yg .S-ob\n g = yg .S-arr\n\n -- a path between slice objects is the \"same\" as a pair of paths between C obs and C arrows\n SOPathIsoPathΣ : Iso (xf ≡ yg) (Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g)\n SOPathIsoPathΣ .fun p = (λ i → (p i) .S-ob) , (λ i → (p i) .S-arr)\n SOPathIsoPathΣ .inv (p , q) i = sliceob {p i} (q i)\n SOPathIsoPathΣ .rightInv _ = refl\n SOPathIsoPathΣ .leftInv _ = refl\n\n SOPath≃PathΣ = isoToEquiv SOPathIsoPathΣ\n\n SOPath≡PathΣ = ua (isoToEquiv SOPathIsoPathΣ)\n\n-- intro and elim for working with SliceHom equalities (is there a better way to do this?)\nSliceHom-≡-intro : ∀ {a b} {f g} {c₁} {c₂}\n → (p : f ≡ g)\n → PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂\n → slicehom f c₁ ≡ slicehom g c₂\nSliceHom-≡-intro p q = λ i → slicehom (p i) (q i)\n\nSliceHom-≡-elim : ∀ {a b} {f g} {c₁} {c₂}\n → slicehom f c₁ ≡ slicehom g c₂\n → Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂\nSliceHom-≡-elim r = (λ i → S-hom (r i)) , λ i → S-comm (r i)\n\n\nSliceHom-≡-intro' : ∀ {a b} {f g : C [ a .S-ob , b .S-ob ]} {c₁} {c₂}\n → (p : f ≡ g)\n → slicehom f c₁ ≡ slicehom g c₂\nSliceHom-≡-intro' {a} {b} {f} {g} {c₁} {c₂} p i = slicehom (p i) (c₁≡c₂ i)\n where\n c₁≡c₂ : PathP (λ i → (p i) ⋆⟨ C ⟩ (b .S-arr) ≡ a .S-arr) c₁ c₂\n c₁≡c₂ = isOfHLevel→isOfHLevelDep 1 (λ _ → isC .isSetHom _ _) c₁ c₂ p\n\n-- SliceHom is isomorphic to the Sigma type with the same components\nSliceHom-Σ-Iso : ∀ {a b}\n → Iso (SliceHom a b) (Σ[ h ∈ C [ S-ob a , S-ob b ] ] h ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a)\nSliceHom-Σ-Iso .fun (slicehom h c) = h , c\nSliceHom-Σ-Iso .inv (h , c) = slicehom h c\nSliceHom-Σ-Iso .rightInv = λ x → refl\nSliceHom-Σ-Iso .leftInv = λ x → refl\n\n\n-- Precategory definition\n\nSliceCat : Precategory _ _\nSliceCat .ob = SliceOb\nSliceCat .Hom[_,_] = SliceHom\nSliceCat .id (sliceob {x} f) = slicehom (C .id x) (C .⋆IdL _)\nSliceCat ._⋆_ {sliceob j} {sliceob k} {sliceob l} (slicehom f p) (slicehom g p') =\n slicehom\n (f ⋆⟨ C ⟩ g)\n ( f ⋆⟨ C ⟩ g ⋆⟨ C ⟩ l\n ≡⟨ C .⋆Assoc _ _ _ ⟩\n f ⋆⟨ C ⟩ (g ⋆⟨ C ⟩ l)\n ≡⟨ cong (λ v → f ⋆⟨ C ⟩ v) p' ⟩\n f ⋆⟨ C ⟩ k\n ≡⟨ p ⟩\n j\n ∎)\nSliceCat .⋆IdL (slicehom S-hom S-comm) =\n SliceHom-≡-intro (⋆IdL C _) (toPathP (isC .isSetHom _ _ _ _))\nSliceCat .⋆IdR (slicehom S-hom S-comm) =\n SliceHom-≡-intro (⋆IdR C _) (toPathP (isC .isSetHom _ _ _ _))\nSliceCat .⋆Assoc f g h =\n SliceHom-≡-intro (⋆Assoc C _ _ _) (toPathP (isC .isSetHom _ _ _ _))\n\n\n-- SliceCat is a Category\n\ninstance\n isCatSlice : isCategory SliceCat\n isCatSlice .isSetHom {a} {b} (slicehom f c₁) (slicehom g c₂) p q = cong isoP p'≡q'\n where\n -- paths between SliceHoms are equivalent to the projection paths\n p' : Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂\n p' = SliceHom-≡-elim p\n q' : Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂\n q' = SliceHom-≡-elim q\n\n -- we want all paths between (dependent) paths of this type to be equal\n B = λ v → v ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a\n\n -- need the groupoidness for dependent paths\n homIsGroupoidDep : isOfHLevelDep 2 B\n homIsGroupoidDep = isOfHLevel→isOfHLevelDep 2 (λ v x y → isSet→isGroupoid (isC .isSetHom) _ _ x y)\n\n -- we first prove that the projected paths are equal\n p'≡q' : p' ≡ q'\n p'≡q' = ΣPathP ((isC .isSetHom _ _ _ _) , toPathP (homIsGroupoidDep _ _ _ _ _))\n\n -- and then we can use equivalence to lift these paths up\n -- to actual SliceHom paths\n isoP = λ g → cong (inv SliceHom-Σ-Iso) (fun (ΣPathIsoPathΣ) g)\n\n-- SliceCat is univalent if C is univalent\n\nmodule _ ⦃ isU : isUnivalent C ⦄ where\n open CatIso\n open Iso\n\n module _ { xf yg : SliceOb } where\n private\n x = xf .S-ob\n y = yg .S-ob\n\n -- names for the equivalences/isos\n\n pathIsoEquiv : (x ≡ y) ≃ (CatIso x y)\n pathIsoEquiv = univEquiv isU x y\n\n isoPathEquiv : (CatIso x y) ≃ (x ≡ y)\n isoPathEquiv = invEquiv pathIsoEquiv\n\n pToIIso' : Iso (x ≡ y) (CatIso x y)\n pToIIso' = equivToIso pathIsoEquiv\n\n -- the iso in SliceCat we're given induces an iso in C between x and y\n module _ ( cIso@(catiso kc lc s r) : CatIso {C = SliceCat} xf yg ) where\n extractIso' : CatIso {C = C} x y\n extractIso' .mor = kc .S-hom\n extractIso' .inv = lc .S-hom\n extractIso' .sec i = (s i) .S-hom\n extractIso' .ret i = (r i) .S-hom\n\n instance\n preservesUnivalenceSlice : isUnivalent SliceCat\n -- we prove the equivalence by going through Iso\n preservesUnivalenceSlice .univ xf@(sliceob {x} f) yg@(sliceob {y} g) = isoToIsEquiv sIso\n where\n -- this is just here because the type checker can't seem to infer xf and yg\n pToIIso : Iso (x ≡ y) (CatIso x y)\n pToIIso = pToIIso' {xf = xf} {yg}\n\n -- the meat of the proof\n sIso : Iso (xf ≡ yg) (CatIso xf yg)\n sIso .fun p = pathToIso xf yg p -- we use the normal pathToIso via path induction to get an isomorphism\n sIso .inv is@(catiso kc lc s r) = SliceOb-≡-intro x≡y (symP (sym (lc .S-comm) ◁ lf≡f))\n where\n -- we get a path between xf and yg by combining paths between\n -- x and y, and f and g\n -- 1. x≡y follows from univalence of C\n -- 2. f≡g is more tricky; by commutativity, we know that g ≡ l ⋆ f\n -- so we want l to be id; we get this by showing: id ≡ pathToIso x y x≡y ≡ l\n -- where the first step follows from path induction, and the second from univalence of C\n\n -- morphisms in C from kc and lc\n k = kc .S-hom\n l = lc .S-hom\n\n -- extract out the iso between x and y\n extractIso : CatIso {C = C} x y\n extractIso = extractIso' is\n\n -- and we can use univalence of C to get x ≡ y\n x≡y : x ≡ y\n x≡y = pToIIso .inv extractIso\n\n -- to show that f ≡ g, we show that l ≡ id\n -- by using C's isomorphism\n pToI≡id : PathP (λ i → C [ x≡y (~ i) , x ]) (pathToIso {C = C} x y x≡y .inv) (C .id x)\n pToI≡id = J (λ y p → PathP (λ i → C [ p (~ i) , x ]) (pathToIso {C = C} x y p .inv) (C .id x))\n (λ j → JRefl pToIFam pToIBase j .inv)\n x≡y\n where\n idx = C .id x\n pToIFam = (λ z _ → CatIso {C = C} x z)\n pToIBase = catiso (C .id x) idx (C .⋆IdL idx) (C .⋆IdL idx)\n\n l≡pToI : l ≡ pathToIso {C = C} x y x≡y .inv\n l≡pToI i = pToIIso .rightInv extractIso (~ i) .inv\n\n l≡id : PathP (λ i → C [ x≡y (~ i) , x ]) l (C .id x)\n l≡id = l≡pToI ◁ pToI≡id\n\n lf≡f : PathP (λ i → C [ x≡y (~ i) , c ]) (l ⋆⟨ C ⟩ f) f\n lf≡f = (λ i → (l≡id i) ⋆⟨ C ⟩ f) ▷ C .⋆IdL _\n\n sIso .rightInv is@(catiso kc lc s r) i = catiso (kc'≡kc i) (lc'≡lc i) (s'≡s i) (r'≡r i)\n -- we prove rightInv using a combination of univalence and the fact that homs are an h-set\n where\n kc' = (sIso .fun) (sIso .inv is) .mor\n lc' = (sIso .fun) (sIso .inv is) .inv\n k' = kc' .S-hom\n l' = lc' .S-hom\n k = kc .S-hom\n l = lc .S-hom\n\n extractIso : CatIso {C = C} x y\n extractIso = extractIso' is\n\n -- we do the equality component wise\n\n -- mor\n\n k'≡k : k' ≡ k\n k'≡k i = (pToIIso .rightInv extractIso) i .mor\n\n kcom'≡kcom : PathP (λ j → (k'≡k j) ⋆⟨ C ⟩ g ≡ f) (kc' .S-comm) (kc .S-comm)\n kcom'≡kcom = isSetHomP1 _ _ λ i → (k'≡k i) ⋆⟨ C ⟩ g\n\n kc'≡kc : kc' ≡ kc\n kc'≡kc i = slicehom (k'≡k i) (kcom'≡kcom i)\n\n -- inv\n\n l'≡l : l' ≡ l\n l'≡l i = (pToIIso .rightInv extractIso) i .inv\n\n lcom'≡lcom : PathP (λ j → (l'≡l j) ⋆⟨ C ⟩ f ≡ g) (lc' .S-comm) (lc .S-comm)\n lcom'≡lcom = isSetHomP1 _ _ λ i → (l'≡l i) ⋆⟨ C ⟩ f\n\n lc'≡lc : lc' ≡ lc\n lc'≡lc i = slicehom (l'≡l i) (lcom'≡lcom i)\n\n -- sec\n\n s' = (sIso .fun) (sIso .inv is) .sec\n s'≡s : PathP (λ i → lc'≡lc i ⋆⟨ SliceCat ⟩ kc'≡kc i ≡ SliceCat .id _) s' s\n s'≡s = isSetHomP1 _ _ λ i → lc'≡lc i ⋆⟨ SliceCat ⟩ kc'≡kc i\n\n -- ret\n\n r' = (sIso .fun) (sIso .inv is) .ret\n r'≡r : PathP (λ i → kc'≡kc i ⋆⟨ SliceCat ⟩ lc'≡lc i ≡ SliceCat .id _) r' r\n r'≡r = isSetHomP1 _ _ λ i → kc'≡kc i ⋆⟨ SliceCat ⟩ lc'≡lc i\n\n sIso .leftInv p = p'≡p\n -- to show that the round trip is equivalent to the identity\n -- we show that this is true for each component (S-ob, S-arr)\n -- and then combine\n -- specifically, we show that p'Ob≡pOb and p'Mor≡pMor\n -- and it follows that p'≡p\n where\n p' = (sIso .inv) (sIso .fun p)\n\n pOb : x ≡ y\n pOb i = (p i) .S-ob\n\n p'Ob : x ≡ y\n p'Ob i = (p' i) .S-ob\n\n\n pMor : PathP (λ i → C [ pOb i , c ]) f g\n pMor i = (p i) .S-arr\n\n p'Mor : PathP (λ i → C [ p'Ob i , c ]) f g\n p'Mor i = (p' i) .S-arr\n\n -- we first show that it's equivalent to use sIso first then extract, or to extract first than use pToIIso\n extractCom : extractIso' (sIso .fun p) ≡ pToIIso .fun pOb\n extractCom = J (λ yg' p̃ → extractIso' (pathToIso xf yg' p̃) ≡ pToIIso' {xf = xf} {yg'} .fun (λ i → (p̃ i) .S-ob))\n (cong extractIso' (JRefl pToIFam' pToIBase') ∙ sym (JRefl pToIFam pToIBase))\n p\n where\n idx = C .id x\n pToIFam = (λ z _ → CatIso {C = C} x z)\n pToIBase = catiso (C .id x) idx (C .⋆IdL idx) (C .⋆IdL idx)\n\n idxf = SliceCat .id xf\n pToIFam' = (λ z _ → CatIso {C = SliceCat} xf z)\n pToIBase' = catiso (SliceCat .id xf) idxf (SliceCat .⋆IdL idxf) (SliceCat .⋆IdL idxf)\n\n -- why does this not follow definitionally?\n -- from extractCom, we get that performing the roundtrip on pOb gives us back p'Ob\n ppp : p'Ob ≡ (pToIIso .inv) (pToIIso .fun pOb)\n ppp = cong (pToIIso .inv) extractCom\n\n -- apply univalence of C\n -- this gives us the first component that we want\n p'Ob≡pOb : p'Ob ≡ pOb\n p'Ob≡pOb = ppp ∙ pToIIso .leftInv pOb\n\n -- isSetHom gives us the second component, path between morphisms\n p'Mor≡pMor : PathP (λ j → PathP (λ i → C [ (p'Ob≡pOb j) i , c ]) f g) p'Mor pMor\n p'Mor≡pMor = isSetHomP2l _ _ p'Mor pMor p'Ob≡pOb\n\n -- we can use the above paths to show that p' ≡ p\n p'≡p : p' ≡ p\n p'≡p i = comp (λ i' → SOPath≡PathΣ {xf = xf} {yg} (~ i'))\n (λ j → λ { (i = i0) → left (~ j) ; (i = i1) → right (~ j) })\n (p'Σ≡pΣ i)\n where\n -- we break up p' and p into their constituent paths\n -- first via transport and then via our component definitions from before\n -- we show that p'ΣT ≡ p'Σ (and same for p) via univalence\n -- and p'Σ≡pΣ follows from our work from above\n p'ΣT : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g\n p'ΣT = transport SOPath≡PathΣ p'\n p'Σ : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g\n p'Σ = (p'Ob , p'Mor)\n\n pΣT : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g\n pΣT = transport SOPath≡PathΣ p\n pΣ : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g\n pΣ = (pOb , pMor)-- transport SOPathP≡PathPSO p\n\n -- using the computation rule to ua\n p'ΣT≡p'Σ : p'ΣT ≡ p'Σ\n p'ΣT≡p'Σ = uaβ SOPath≃PathΣ p'\n\n pΣT≡pΣ : pΣT ≡ pΣ\n pΣT≡pΣ = uaβ SOPath≃PathΣ p\n\n p'Σ≡pΣ : p'Σ ≡ pΣ\n p'Σ≡pΣ = ΣPathP (p'Ob≡pOb , p'Mor≡pMor)\n\n -- two sides of the square we're connecting\n left : PathP (λ i → SOPath≡PathΣ {xf = xf} {yg} i) p' p'Σ\n left = transport-filler SOPath≡PathΣ p' ▷ p'ΣT≡p'Σ\n\n right : PathP (λ i → SOPath≡PathΣ {xf = xf} {yg} i) p pΣ\n right = transport-filler SOPath≡PathΣ p ▷ pΣT≡pΣ\n\n-- properties\n-- TODO: move to own file\n\nopen isIsoC renaming (inv to invC)\n\n-- make a slice isomorphism from just the hom\nsliceIso : ∀ {a b} (f : C [ a .S-ob , b .S-ob ]) (c : (f ⋆⟨ C ⟩ b .S-arr) ≡ a .S-arr)\n → isIsoC {C = C} f\n → isIsoC {C = SliceCat} (slicehom f c)\nsliceIso f c isof .invC = slicehom (isof .invC) (sym (invMoveL (isIso→areInv isof) c))\nsliceIso f c isof .sec = SliceHom-≡-intro' (isof .sec)\nsliceIso f c isof .ret = SliceHom-≡-intro' (isof .ret)\n", "meta": {"hexsha": "fb2cfd3138a180c8a60c4725a80f78a67e3a4cd0", "size": 14600, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Categories/Constructions/Slice.agda", "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": "Cubical/Categories/Constructions/Slice.agda", "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": "Cubical/Categories/Constructions/Slice.agda", "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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.0208333333, "max_line_length": 126, "alphanum_fraction": 0.522739726, "num_tokens": 5668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494678483918, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3723767802066108}} {"text": "open import Agda.Primitive using (lzero; lsuc; _⊔_)\nopen import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; setoid; cong; trans)\nimport Function.Equality\nopen import Relation.Binary using (Setoid)\n\nimport Categories.Category\nimport Categories.Functor\nimport Categories.Category.Instance.Setoids\nimport Categories.Monad.Relative\nimport Categories.Category.Equivalence\nimport Categories.Category.Cocartesian\n\nimport SecondOrder.Arity\nimport SecondOrder.Signature\nimport SecondOrder.Metavariable\nimport SecondOrder.VRenaming\nimport SecondOrder.Term\nimport SecondOrder.IndexedCategory\nimport SecondOrder.RelativeKleisli\n\nmodule SecondOrder.Substitution\n {ℓ}\n {𝔸 : SecondOrder.Arity.Arity}\n (Σ : SecondOrder.Signature.Signature ℓ 𝔸)\n where\n\n open SecondOrder.Signature.Signature Σ\n open SecondOrder.Metavariable Σ\n open SecondOrder.Term Σ\n open SecondOrder.VRenaming Σ\n\n -- substitution\n\n infix 4 _⊕_⇒ˢ_\n\n _⊕_⇒ˢ_ : ∀ (Θ : MContext) (Γ Δ : VContext) → Set ℓ\n Θ ⊕ Γ ⇒ˢ Δ = ∀ {A} (x : A ∈ Γ) → Term Θ Δ A\n\n -- syntactic equality of substitutions\n\n infix 5 _≈ˢ_\n\n _≈ˢ_ : ∀ {Θ} {Γ Δ} (σ τ : Θ ⊕ Γ ⇒ˢ Δ) → Set ℓ\n _≈ˢ_ {Θ} {Γ} σ τ = ∀ {A} (x : A ∈ Γ) → σ x ≈ τ x\n\n -- equality of substitutions form a setoid\n ≈ˢ-refl : ∀ {Θ Γ Δ} {σ : Θ ⊕ Γ ⇒ˢ Δ}\n → σ ≈ˢ σ\n ≈ˢ-refl x = ≈-refl\n\n ≈ˢ-sym : ∀ {Θ Γ Δ} {σ τ : Θ ⊕ Γ ⇒ˢ Δ}\n → σ ≈ˢ τ\n → τ ≈ˢ σ\n ≈ˢ-sym eq x = ≈-sym (eq x)\n\n ≈ˢ-trans : ∀ {Θ Γ Δ} {σ τ μ : Θ ⊕ Γ ⇒ˢ Δ}\n → σ ≈ˢ τ → τ ≈ˢ μ\n → σ ≈ˢ μ\n ≈ˢ-trans eq1 eq2 x = ≈-trans (eq1 x) (eq2 x)\n\n substitution-setoid : ∀ (Γ Δ : VContext) (Θ : MContext) → Setoid ℓ ℓ\n substitution-setoid Γ Δ Θ =\n record\n { Carrier = Θ ⊕ Γ ⇒ˢ Δ\n ; _≈_ = λ σ τ → σ ≈ˢ τ\n ; isEquivalence =\n record\n { refl = λ {σ} x → ≈ˢ-refl {σ = σ} x\n ; sym = ≈ˢ-sym\n ; trans = ≈ˢ-trans\n }\n }\n\n congˢ : ∀ {Θ} {Γ Δ} {A} {σ τ : Θ ⊕ Γ ⇒ˢ Δ} {x : A ∈ Γ} → σ ≈ˢ τ → σ x ≈ τ x\n congˢ {x = x} eq = eq x\n\n congˢ-var : ∀ {Θ} {Γ Δ} {A} {σ : Θ ⊕ Γ ⇒ˢ Δ} {x y : A ∈ Γ} → x ≡ y → σ x ≈ σ y\n congˢ-var refl = ≈-refl\n\n -- extension of a substitution\n\n ⇑ˢ : ∀ {Θ Γ Δ Ξ} → Θ ⊕ Γ ⇒ˢ Δ → Θ ⊕ (Γ ,, Ξ) ⇒ˢ (Δ ,, Ξ)\n ⇑ˢ σ (var-inl x) = [ var-inl ]ᵛ σ x\n ⇑ˢ σ (var-inr y) = tm-var (var-inr y)\n\n -- extension respects equality of substitutions\n\n ⇑ˢ-resp-≈ˢ : ∀ {Θ Γ Δ Ξ} {σ τ : Θ ⊕ Γ ⇒ˢ Δ} → σ ≈ˢ τ → ⇑ˢ {Ξ = Ξ} σ ≈ˢ ⇑ˢ {Ξ = Ξ} τ\n ⇑ˢ-resp-≈ˢ ξ (var-inl x) = []ᵛ-resp-≈ (ξ x)\n ⇑ˢ-resp-≈ˢ ξ (var-inr y) = ≈-refl\n\n -- the action of a renaming on a substitution\n\n infixr 6 _ᵛ∘ˢ_\n\n _ᵛ∘ˢ_ : ∀ {Θ} {Γ Δ Ξ} (ρ : Δ ⇒ᵛ Ξ) (σ : Θ ⊕ Γ ⇒ˢ Δ) → Θ ⊕ Γ ⇒ˢ Ξ\n (ρ ᵛ∘ˢ σ) x = [ ρ ]ᵛ (σ x)\n\n infixl 6 _ˢ∘ᵛ_\n\n _ˢ∘ᵛ_ : ∀ {Θ} {Γ Δ Ξ} (σ : Θ ⊕ Δ ⇒ˢ Ξ) (ρ : Γ ⇒ᵛ Δ) → Θ ⊕ Γ ⇒ˢ Ξ\n (σ ˢ∘ᵛ ρ) x = σ (ρ x)\n\n -- extension commutes with renaming action\n\n ⇑ˢ-resp-ˢ∘ᵛ : ∀ {Θ} {Γ Δ Ξ Ψ} {ρ : Γ ⇒ᵛ Δ} {σ : Θ ⊕ Δ ⇒ˢ Ξ} → ⇑ˢ {Ξ = Ψ} (σ ˢ∘ᵛ ρ) ≈ˢ ⇑ˢ σ ˢ∘ᵛ ⇑ᵛ ρ\n ⇑ˢ-resp-ˢ∘ᵛ (var-inl x) = ≈-refl\n ⇑ˢ-resp-ˢ∘ᵛ (var-inr x) = ≈-refl\n\n -- the action of a substitution on a term\n\n infix 6 [_]ˢ_\n\n [_]ˢ_ : ∀ {Θ Γ Δ A} → Θ ⊕ Γ ⇒ˢ Δ → Term Θ Γ A → Term Θ Δ A\n [ σ ]ˢ (tm-var x) = σ x\n [ σ ]ˢ (tm-meta M ts) = tm-meta M (λ i → [ σ ]ˢ ts i)\n [ σ ]ˢ (tm-oper f es) = tm-oper f (λ i → [ ⇑ˢ σ ]ˢ es i)\n\n -- composition of substitutions\n\n infixl 7 _∘ˢ_\n _∘ˢ_ : ∀ {Θ} {Γ Δ Ξ} → Θ ⊕ Δ ⇒ˢ Ξ → Θ ⊕ Γ ⇒ˢ Δ → Θ ⊕ Γ ⇒ˢ Ξ\n (σ ∘ˢ τ) x = [ σ ]ˢ τ x\n\n -- substitution action respects equality of terms\n\n []ˢ-resp-≈ : ∀ {Θ} {Γ Δ} {A} (σ : Θ ⊕ Γ ⇒ˢ Δ) {t u : Term Θ Γ A} → t ≈ u → [ σ ]ˢ t ≈ [ σ ]ˢ u\n []ˢ-resp-≈ σ (≈-≡ refl) = ≈-refl\n []ˢ-resp-≈ σ (≈-meta ξ) = ≈-meta (λ i → []ˢ-resp-≈ σ (ξ i))\n []ˢ-resp-≈ σ (≈-oper ξ) = ≈-oper (λ i → []ˢ-resp-≈ (⇑ˢ σ) (ξ i))\n\n -- substitution action respects equality of substitutions\n\n []ˢ-resp-≈ˢ : ∀ {Θ} {Γ Δ} {A} {σ τ : Θ ⊕ Γ ⇒ˢ Δ} (t : Term Θ Γ A) → σ ≈ˢ τ → [ σ ]ˢ t ≈ [ τ ]ˢ t\n []ˢ-resp-≈ˢ (tm-var x) ξ = ξ x\n []ˢ-resp-≈ˢ (tm-meta M ts) ξ = ≈-meta (λ i → []ˢ-resp-≈ˢ (ts i) ξ)\n []ˢ-resp-≈ˢ (tm-oper f es) ξ = ≈-oper (λ i → []ˢ-resp-≈ˢ (es i) (⇑ˢ-resp-≈ˢ ξ))\n\n -- substitution actions respects both equalities\n\n []ˢ-resp-≈ˢ-≈ : ∀ {Θ} {Γ Δ} {A} {σ τ : Θ ⊕ Γ ⇒ˢ Δ} {t u : Term Θ Γ A} → σ ≈ˢ τ → t ≈ u → [ σ ]ˢ t ≈ [ τ ]ˢ u\n []ˢ-resp-≈ˢ-≈ {τ = τ} {t = t} ζ ξ = ≈-trans ([]ˢ-resp-≈ˢ t ζ) ([]ˢ-resp-≈ τ ξ)\n\n -- identity substitution\n\n idˢ : ∀ {Θ Γ} → Θ ⊕ Γ ⇒ˢ Γ\n idˢ = tm-var\n\n -- extension preserves identity\n\n ⇑ˢ-resp-idˢ : ∀ {Θ} {Γ Δ} → ⇑ˢ idˢ ≈ˢ idˢ {Θ = Θ} {Γ = Γ ,, Δ}\n ⇑ˢ-resp-idˢ (var-inl x) = ≈-refl\n ⇑ˢ-resp-idˢ (var-inr y) = ≈-refl\n\n -- the identity substution acts trivially\n\n [idˢ] : ∀ {Θ} {Γ} {A} {t : Term Θ Γ A} → [ idˢ ]ˢ t ≈ t\n [idˢ] {t = tm-var x} = ≈-refl\n [idˢ] {t = tm-meta M ts} = ≈-meta (λ i → [idˢ])\n [idˢ] {t = tm-oper f es} = ≈-oper (λ i → ≈-trans ([]ˢ-resp-≈ˢ (es i) ⇑ˢ-resp-idˢ) [idˢ])\n\n -- the identity substitution preserves equality of terms\n [idˢ]-resp-≈ : ∀ {Θ} {Γ} {A} {t s : Term Θ Γ A} → t ≈ s → [ idˢ ]ˢ t ≈ s\n [idˢ]-resp-≈ t≈s = ≈-trans ([]ˢ-resp-≈ idˢ t≈s) [idˢ]\n\n\n -- if a substiution is equal to the identity then it acts trivially\n ≈ˢ-idˢ-[]ˢ : ∀ {Θ} {Γ} {A} {σ : Θ ⊕ Γ ⇒ˢ Γ} {t : Term Θ Γ A} → σ ≈ˢ idˢ → [ σ ]ˢ t ≈ t\n ≈ˢ-idˢ-[]ˢ {t = t} ξ = ≈-trans ([]ˢ-resp-≈ˢ t ξ) [idˢ]\n\n -- interaction of extension and right renaming action\n\n [⇑ˢ∘ᵛ] : ∀ {Θ} {A} {Γ Δ Ξ Ψ} {σ : Θ ⊕ Δ ⇒ˢ Ξ} {ρ : Γ ⇒ᵛ Δ} (t : Term Θ (Γ ,, Ψ) A) →\n [ ⇑ˢ (σ ˢ∘ᵛ ρ) ]ˢ t ≈ [ ⇑ˢ σ ]ˢ [ ⇑ᵛ ρ ]ᵛ t\n [⇑ˢ∘ᵛ] (tm-var (var-inl x)) = ≈-refl\n [⇑ˢ∘ᵛ] (tm-var (var-inr x)) = ≈-refl\n [⇑ˢ∘ᵛ] (tm-meta M ts) = ≈-meta (λ i → [⇑ˢ∘ᵛ] (ts i))\n [⇑ˢ∘ᵛ] (tm-oper f es) = ≈-oper (λ i → ≈-trans ([]ˢ-resp-≈ˢ (es i) (⇑ˢ-resp-≈ˢ ⇑ˢ-resp-ˢ∘ᵛ)) ([⇑ˢ∘ᵛ] (es i)))\n\n -- interaction of extension and left renaming action\n\n ⇑ˢ-resp-ᵛ∘ˢ : ∀ {Θ} {Γ Δ Ξ Ψ} {σ : Θ ⊕ Γ ⇒ˢ Δ} {ρ : Δ ⇒ᵛ Ξ} →\n ⇑ˢ {Ξ = Ψ} (ρ ᵛ∘ˢ σ) ≈ˢ ⇑ᵛ ρ ᵛ∘ˢ ⇑ˢ σ\n ⇑ˢ-resp-ᵛ∘ˢ (var-inl x) = ≈-trans (≈-sym [∘ᵛ]) (≈-trans ([]ᵛ-resp-≡ᵛ (λ _ → refl)) [∘ᵛ])\n ⇑ˢ-resp-ᵛ∘ˢ (var-inr y) = ≈-refl\n\n [⇑ᵛ∘ˢ] : ∀ {Θ} {A} {Γ Δ Ξ Ψ} {σ : Θ ⊕ Γ ⇒ˢ Δ} {ρ : Δ ⇒ᵛ Ξ} (t : Term Θ (Γ ,, Ψ) A) →\n [ ⇑ˢ (ρ ᵛ∘ˢ σ) ]ˢ t ≈ [ ⇑ᵛ ρ ]ᵛ ([ ⇑ˢ σ ]ˢ t)\n [⇑ᵛ∘ˢ] (tm-var x) = ⇑ˢ-resp-ᵛ∘ˢ x\n [⇑ᵛ∘ˢ] (tm-meta M ts) = ≈-meta (λ i → [⇑ᵛ∘ˢ] (ts i))\n [⇑ᵛ∘ˢ] (tm-oper f es) = ≈-oper (λ i → ≈-trans ([]ˢ-resp-≈ˢ (es i) (⇑ˢ-resp-≈ˢ ⇑ˢ-resp-ᵛ∘ˢ)) ([⇑ᵛ∘ˢ] (es i)))\n\n -- functoriality of left renaming action\n\n [ᵛ∘ˢ] : ∀ {Θ} {A} {Γ Δ Ξ} {ρ : Δ ⇒ᵛ Ξ} {σ : Θ ⊕ Γ ⇒ˢ Δ} (t : Term Θ Γ A) →\n [ ρ ᵛ∘ˢ σ ]ˢ t ≈ [ ρ ]ᵛ [ σ ]ˢ t\n [ᵛ∘ˢ] (tm-var x) = ≈-refl\n [ᵛ∘ˢ] (tm-meta M ts) = ≈-meta (λ i → [ᵛ∘ˢ] (ts i))\n [ᵛ∘ˢ] (tm-oper f es) = ≈-oper (λ i → [⇑ᵛ∘ˢ] (es i))\n\n -- functoriality of right renaming action\n\n [ˢ∘ᵛ] : ∀ {Θ} {A} {Γ Δ Ξ} {σ : Θ ⊕ Δ ⇒ˢ Ξ} {ρ : Γ ⇒ᵛ Δ} (t : Term Θ Γ A) →\n [ σ ˢ∘ᵛ ρ ]ˢ t ≈ [ σ ]ˢ [ ρ ]ᵛ t\n [ˢ∘ᵛ] (tm-var x) = ≈-refl\n [ˢ∘ᵛ] (tm-meta M ts) = ≈-meta (λ i → [ˢ∘ᵛ] (ts i))\n [ˢ∘ᵛ] (tm-oper f es) = ≈-oper (λ i → [⇑ˢ∘ᵛ] (es i))\n\n -- composition commutes with extension\n\n ⇑ˢ-resp-∘ˢ : ∀ {Θ} {Γ Δ Ξ Ψ} {σ : Θ ⊕ Γ ⇒ˢ Δ} {τ : Θ ⊕ Δ ⇒ˢ Ξ} →\n ⇑ˢ {Ξ = Ψ} (τ ∘ˢ σ) ≈ˢ ⇑ˢ τ ∘ˢ ⇑ˢ σ\n ⇑ˢ-resp-∘ˢ {σ = σ} {τ = τ} (var-inl x) = ≈-trans (≈-sym ([ᵛ∘ˢ] (σ x))) ([ˢ∘ᵛ] (σ x))\n ⇑ˢ-resp-∘ˢ (var-inr y) = ≈-refl\n\n -- substitition action is functorial\n\n [∘ˢ] : ∀ {Θ} {Γ Δ Ξ} {A} {σ : Θ ⊕ Γ ⇒ˢ Δ} {τ : Θ ⊕ Δ ⇒ˢ Ξ} (t : Term Θ Γ A) →\n [ τ ∘ˢ σ ]ˢ t ≈ [ τ ]ˢ ([ σ ]ˢ t)\n [∘ˢ] (tm-var x) = ≈-refl\n [∘ˢ] (tm-meta M ts) = ≈-meta (λ i → [∘ˢ] (ts i))\n [∘ˢ] (tm-oper f es) = ≈-oper (λ i → ≈-trans ([]ˢ-resp-≈ˢ (es i) ⇑ˢ-resp-∘ˢ) ([∘ˢ] (es i)))\n\n -- Terms form a relative monad\n\n module _ where\n open Categories.Category\n open Categories.Functor using (Functor)\n open Categories.Category.Instance.Setoids\n open Categories.Monad.Relative\n open Function.Equality using () renaming (setoid to Π-setoid)\n open Categories.Category.Equivalence using (StrongEquivalence)\n open import SecondOrder.IndexedCategory\n open import SecondOrder.RelativeKleisli\n\n -- The embedding of contexts into setoids indexed by sorts\n\n slots : Functor VContexts (IndexedCategory sort (Setoids ℓ ℓ))\n slots = record\n { F₀ = λ Γ A → setoid (A ∈ Γ)\n ; F₁ = λ ρ A → record { _⟨$⟩_ = ρ ; cong = cong ρ }\n ; identity = λ A ξ → ξ\n ; homomorphism = λ {_} {_} {_} {ρ} {σ} A {_} {_} ξ → cong σ (cong ρ ξ)\n ; F-resp-≈ = λ ξ A ζ → trans (ξ _) (cong _ ζ)\n }\n\n\n module _ {Θ : MContext} where\n open Categories.Category\n open Categories.Functor using (Functor)\n open Categories.Category.Instance.Setoids\n open Categories.Monad.Relative\n open Function.Equality using () renaming (setoid to Π-setoid)\n open Categories.Category.Equivalence using (StrongEquivalence)\n open import SecondOrder.IndexedCategory\n open import SecondOrder.RelativeKleisli\n\n\n -- The relative monad of terms over contexts\n\n Term-Monad : Monad slots\n Term-Monad =\n let open Function.Equality using (_⟨$⟩_) renaming (cong to func-cong) in\n record\n { F₀ = Term-setoid Θ\n ; unit = λ A → record { _⟨$⟩_ = idˢ ; cong = λ ξ → ≈-≡ (cong idˢ ξ) }\n ; extend = λ σ A → record { _⟨$⟩_ = [ (σ _ ⟨$⟩_) ]ˢ_ ; cong = []ˢ-resp-≈ (σ _ ⟨$⟩_)}\n ; identityʳ = λ {_} {_} {σ} A {_} {_} ξ → func-cong (σ A) ξ\n ; identityˡ = λ A → ≈-trans [idˢ]\n ; assoc = λ {_} {_} {_} {σ} {ρ} A {_} {t} ξ → ≈-trans ([]ˢ-resp-≈ _ ξ) ([∘ˢ] t)\n ; extend-≈ = λ {Γ} {Δ} {σ} {ρ} ζ B {s} {t} ξ → []ˢ-resp-≈ˢ-≈ (λ x → ζ _ refl) ξ\n }\n\n\n -- the category of contexts and substitutions\n\n -- we show below that the category of contexts and substitiions is equivalent\n -- to the Kleisli category for the Term relative monad. However, we define\n -- the category of contexts and substitutions directly, as that it is easier\n -- to work with it\n\n Terms : Category ℓ ℓ ℓ\n Terms =\n record\n { Obj = VContext\n ; _⇒_ = Θ ⊕_⇒ˢ_\n ; _≈_ = _≈ˢ_\n ; id = idˢ\n ; _∘_ = _∘ˢ_\n ; assoc = λ {Γ} {Δ} {Ξ} {Ψ} {σ} {τ} {ψ} {A} x → [∘ˢ] (σ x)\n ; sym-assoc = λ {Γ} {Δ} {Ξ} {Ψ} {σ} {τ} {ψ} {A} x → ≈-sym ([∘ˢ] (σ x))\n ; identityˡ = λ x → [idˢ]\n ; identityʳ = λ x → ≈-refl\n ; identity² = λ x → ≈-refl\n ; equiv = record { refl = λ {σ} {A} → ≈ˢ-refl {σ = σ} ; sym = ≈ˢ-sym ; trans = ≈ˢ-trans }\n ; ∘-resp-≈ = λ f≈ˢg g≈ˢi x → []ˢ-resp-≈ˢ-≈ f≈ˢg (g≈ˢi x)\n }\n\n Terms-is-Kleisli : StrongEquivalence Terms (Kleisli Term-Monad)\n Terms-is-Kleisli =\n record\n { F = record\n { F₀ = λ Γ → Γ\n ; F₁ = λ σ A → record { _⟨$⟩_ = λ x → σ x ; cong = λ i≡j → ≈-≡ (cong σ i≡j) }\n ; identity = λ A eq → ≈-≡ (cong idˢ eq)\n ; homomorphism = λ {Γ} {Δ} {Ξ} {σ} {τ} A eq → ≈-≡ (cong (λ x → [ τ ]ˢ σ x) eq)\n ; F-resp-≈ = λ {Γ} {Δ} {σ} {τ} hom_eq A eq\n → ≈-trans (congˢ hom_eq) (≈-≡ (cong τ eq))\n }\n ; G =\n let open Function.Equality using (_⟨$⟩_) renaming (cong to func-cong) in\n record\n { F₀ = λ Γ → Γ\n ; F₁ = λ {Γ} {Δ} σ {A} → λ x → σ A ⟨$⟩ x\n ; identity = λ x → ≈-refl\n ; homomorphism = λ x → ≈-refl\n ; F-resp-≈ = λ {Γ} {Δ} {σ} {τ} σ≈τ {A} x → σ≈τ A refl\n }\n ; weak-inverse =\n let open Function.Equality using (_⟨$⟩_) renaming (cong to func-cong) in\n record\n { F∘G≈id =\n record\n { F⇒G =\n record\n { η = λ Γ A → record { _⟨$⟩_ = idˢ\n ; cong = λ i≡j → ≈-≡ (cong idˢ i≡j)\n }\n ; commute = λ σ A x≡y → [idˢ]-resp-≈ (≈-≡ (cong (λ x → σ A ⟨$⟩ x) x≡y))\n ; sym-commute = λ σ A x≡y\n → ≈-sym ([idˢ]-resp-≈ (≈-≡ (cong (λ x → σ A ⟨$⟩ x ) (sym x≡y))))\n }\n ; F⇐G =\n record\n { η = λ Γ A → record { _⟨$⟩_ = idˢ\n ; cong = λ i≡j → ≈-≡ (cong idˢ i≡j)\n }\n ; commute = λ σ A x≡y → [idˢ]-resp-≈ (≈-≡ (cong (λ x → σ A ⟨$⟩ x) x≡y))\n ; sym-commute = λ σ A x≡y\n → ≈-sym ([idˢ]-resp-≈ (≈-≡ (cong (λ x → σ A ⟨$⟩ x ) (sym x≡y))))\n }\n ; iso = λ Γ → record { isoˡ = λ A x≡y → ≈-≡ (cong tm-var x≡y)\n ; isoʳ = λ A x≡y → ≈-≡ (cong tm-var x≡y)\n }\n }\n ; G∘F≈id =\n record\n { F⇒G =\n record\n { η = λ Γ x → tm-var x\n ; commute = λ σ x → [idˢ]\n ; sym-commute = λ σ x → ≈-sym [idˢ]\n }\n ; F⇐G =\n record\n { η = λ Γ x → tm-var x\n ; commute = λ σ x → [idˢ]\n ; sym-commute = λ σ x → ≈-sym [idˢ]\n }\n ; iso = λ Γ → record { isoˡ = λ x → ≈-refl\n ; isoʳ = λ x → ≈-refl\n }\n }\n }\n }\n\n -- the binary coproduct structure on Terms\n\n infixl 7 [_,_]ˢ\n\n [_,_]ˢ : ∀ {Γ Δ Ξ} (σ : Θ ⊕ Γ ⇒ˢ Ξ) (τ : Θ ⊕ Δ ⇒ˢ Ξ) → Θ ⊕ (Γ ,, Δ) ⇒ˢ Ξ\n [ σ , τ ]ˢ (var-inl x) = σ x\n [ σ , τ ]ˢ (var-inr y) = τ y\n\n inlˢ : ∀ {Γ Δ} → Θ ⊕ Γ ⇒ˢ Γ ,, Δ\n inlˢ x = tm-var (var-inl x)\n\n inrˢ : ∀ {Γ Δ} → Θ ⊕ Δ ⇒ˢ Γ ,, Δ\n inrˢ y = tm-var (var-inr y)\n\n [,]ˢ-resp-≈ˢ : ∀ {Γ Δ Ξ} {σ₁ σ₂ : Θ ⊕ Γ ⇒ˢ Ξ} {τ₁ τ₂ : Θ ⊕ Δ ⇒ˢ Ξ} →\n σ₁ ≈ˢ σ₂ → τ₁ ≈ˢ τ₂ → [ σ₁ , τ₁ ]ˢ ≈ˢ [ σ₂ , τ₂ ]ˢ\n [,]ˢ-resp-≈ˢ ζ ξ (var-inl x) = ζ x\n [,]ˢ-resp-≈ˢ ζ ξ (var-inr y) = ξ y\n\n uniqueˢ : ∀ {Γ Δ Ξ} {τ : Θ ⊕ Γ ,, Δ ⇒ˢ Ξ} {ρ : Θ ⊕ Γ ⇒ˢ Ξ} {σ : Θ ⊕ Δ ⇒ˢ Ξ}\n → τ ∘ˢ inlˢ ≈ˢ ρ\n → τ ∘ˢ inrˢ ≈ˢ σ\n → [ ρ , σ ]ˢ ≈ˢ τ\n uniqueˢ ξ ζ (var-inl x) = ≈-sym (ξ x)\n uniqueˢ ξ ζ (var-inr y) = ≈-sym (ζ y)\n\n Terms-Coproduct : Categories.Category.Cocartesian.BinaryCoproducts Terms\n Terms-Coproduct =\n let open Function.Equality using (_⟨$⟩_) renaming (cong to func-cong) in\n record {\n coproduct =\n λ {Γ Δ} →\n record\n { A+B = Γ ,, Δ\n ; i₁ = inlˢ\n ; i₂ = inrˢ\n ; [_,_] = [_,_]ˢ\n ; inject₁ = λ x → ≈-≡ refl\n ; inject₂ = λ x → ≈-≡ refl\n ; unique = λ {Ξ} {h} p₁ p₂ → uniqueˢ {τ = h} p₁ p₂\n }\n }\n\n open Categories.Category.Cocartesian.BinaryCoproducts Terms-Coproduct\n\n -- the sum of subsitutions\n\n infixl 6 _+ˢ_\n\n _+ˢ_ : ∀ {Γ₁ Γ₂ Δ₁ Δ₂} (σ : Θ ⊕ Γ₁ ⇒ˢ Δ₁) (τ : Θ ⊕ Γ₂ ⇒ˢ Δ₂) → Θ ⊕ Γ₁ ,, Γ₂ ⇒ˢ Δ₁ ,, Δ₂\n σ +ˢ τ = σ +₁ τ\n\n -- reassociations of context sums\n\n assoc-l : ∀ {Γ Δ Ξ} → Θ ⊕ (Γ ,, Δ) ,, Ξ ⇒ˢ Γ ,, (Δ ,, Ξ)\n assoc-l (var-inl (var-inl x)) = tm-var (var-inl x)\n assoc-l (var-inl (var-inr y)) = tm-var (var-inr (var-inl y))\n assoc-l (var-inr z) = tm-var (var-inr (var-inr z))\n\n assoc-r : ∀ {Γ Δ Ξ} → Θ ⊕ Γ ,, (Δ ,, Ξ) ⇒ˢ (Γ ,, Δ) ,, Ξ\n assoc-r (var-inl x) = tm-var (var-inl (var-inl x))\n assoc-r (var-inr (var-inl y)) = tm-var (var-inl (var-inr y))\n assoc-r (var-inr (var-inr z)) = tm-var (var-inr z)\n\n assoc-lr : ∀ {Γ Δ Ξ} → assoc-l {Γ = Γ} {Δ = Δ} {Ξ = Ξ} ∘ˢ assoc-r {Γ = Γ} {Δ = Δ} {Ξ = Ξ} ≈ˢ idˢ\n assoc-lr (var-inl x) = ≈-refl\n assoc-lr (var-inr (var-inl y)) = ≈-refl\n assoc-lr (var-inr (var-inr y)) = ≈-refl\n\n assoc-rl : ∀ {Γ Δ Ξ} → assoc-r {Γ = Γ} {Δ = Δ} {Ξ = Ξ} ∘ˢ assoc-l {Γ = Γ} {Δ = Δ} {Ξ = Ξ} ≈ˢ idˢ\n assoc-rl (var-inl (var-inl x)) = ≈-refl\n assoc-rl (var-inl (var-inr x)) = ≈-refl\n assoc-rl (var-inr z) = ≈-refl\n\n -- summing with the empty context is the unit\n\n sum-ctx-empty-r : ∀ {Γ} → Θ ⊕ Γ ,, ctx-empty ⇒ˢ Γ\n sum-ctx-empty-r (var-inl x) = tm-var x\n\n sum-ctx-empty-l : ∀ {Γ} → Θ ⊕ ctx-empty ,, Γ ⇒ˢ Γ\n sum-ctx-empty-l (var-inr x) = tm-var x\n", "meta": {"hexsha": "d583e88e276c1196b68fe54f62a1ddef94bd95ad", "size": 16390, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/SecondOrder/Substitution.agda", "max_stars_repo_name": "andrejbauer/formal", "max_stars_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-18T18:21:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-18T18:21:00.000Z", "max_issues_repo_path": "src/SecondOrder/Substitution.agda", "max_issues_repo_name": "andrejbauer/formaltt", "max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "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/SecondOrder/Substitution.agda", "max_forks_repo_name": "andrejbauer/formaltt", "max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "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": 36.5848214286, "max_line_length": 110, "alphanum_fraction": 0.4507016473, "num_tokens": 7813, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494421679929, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3723767662656651}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import HoTT\nopen import cohomology.SuspAdjointLoopIso\nopen import cohomology.WithCoefficients\nopen import cohomology.Theory\nopen import cohomology.Exactness\nopen import cohomology.Choice\n\nmodule cohomology.SpectrumModel\n {i} (E : ℤ → Ptd i) (spectrum : (n : ℤ) → ⊙Ω (E (succ n)) == E n) where\n\nmodule SpectrumModel where\n\n {- Definition of cohomology group C -}\n module _ (n : ℤ) (X : Ptd i) where\n C : Group i\n C = →Ω-Group X (E (succ n))\n\n {- convenient abbreviations -}\n CEl = Group.El C\n ⊙CEl = Group.⊙El C\n Cid = Group.ident C\n\n {- before truncation -}\n ⊙uCEl : Ptd i\n ⊙uCEl = X ⊙→ ⊙Ω (E (succ n))\n\n uCEl = fst ⊙uCEl\n uCid = snd ⊙uCEl\n\n {- Cⁿ(X) is an abelian group -}\n C-abelian : (n : ℤ) (X : Ptd i) → is-abelian (C n X)\n C-abelian n X =\n transport (is-abelian ∘ →Ω-Group X) (spectrum (succ n)) C-abelian-lemma\n where\n pt-lemma : ∀ {i} {X : Ptd i} {α β : Ω^ 2 X}\n (γ : α == idp^ 2) (δ : β == idp^ 2)\n → ap2 _∙_ γ δ == conc^2-comm α β ∙ ap2 _∙_ δ γ\n pt-lemma idp idp = idp\n\n C-abelian-lemma = Trunc-elim\n (λ _ → Π-level (λ _ → =-preserves-level _ Trunc-level))\n (λ {(f , fpt) → Trunc-elim\n (λ _ → =-preserves-level _ Trunc-level)\n (λ {(g , gpt) → ap [_] $ ⊙λ=\n (λ x → conc^2-comm (f x) (g x))\n (pt-lemma fpt gpt)})})\n\n {- CF, the functorial action of C:\n - contravariant functor from pointed spaces to abelian groups -}\n module _ (n : ℤ) {X Y : Ptd i} where\n\n {- before truncation - from pointed spaces to pointed spaces -}\n uCF : fst (X ⊙→ Y) → fst (⊙uCEl n Y ⊙→ ⊙uCEl n X)\n uCF f =\n ((λ g → g ⊙∘ f) ,\n pair= idp (∙-unit-r _ ∙ ap-cst idp (snd f)))\n\n CF-hom : fst (X ⊙→ Y) → (C n Y →ᴳ C n X)\n CF-hom f = record {\n f = Trunc-fmap {n = ⟨0⟩} (fst (uCF f));\n pres-comp = Trunc-elim\n (λ _ → Π-level (λ _ → =-preserves-level _ Trunc-level))\n (λ g → Trunc-elim\n (λ _ → =-preserves-level _ Trunc-level)\n (λ h → ap [_] $ pair= idp (comp-snd _∙_ f g h)))}\n where\n comp-snd : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {C : Type k}\n {c₁ c₂ : C} (_⊕_ : C → C → C) (f : fst (X ⊙→ Y))\n (g : fst (Y ⊙→ ⊙[ C , c₁ ])) (h : fst (Y ⊙→ ⊙[ C , c₂ ]))\n → ap (λ x → fst g x ⊕ fst h x) (snd f) ∙ ap2 _⊕_ (snd g) (snd h)\n == ap2 _⊕_ (ap (fst g) (snd f) ∙ snd g) (ap (fst h) (snd f) ∙ snd h)\n comp-snd _⊕_ (_ , idp) (_ , idp) (_ , idp) = idp\n\n CF : fst (X ⊙→ Y) → fst (⊙CEl n Y ⊙→ ⊙CEl n X)\n CF F = GroupHom.⊙f (CF-hom F)\n\n {- CF-hom is a functor from pointed spaces to abelian groups -}\n module _ (n : ℤ) {X : Ptd i} where\n\n CF-ident : CF-hom n {X} {X} (⊙idf X) == idhom (C n X)\n CF-ident = hom= _ _ $ λ= $ Trunc-elim\n (λ _ → =-preserves-level _ Trunc-level)\n (λ _ → idp)\n\n CF-comp : {Y Z : Ptd i} (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y))\n → CF-hom n (g ⊙∘ f) == CF-hom n f ∘ᴳ CF-hom n g\n CF-comp g f = hom= _ _ $ λ= $ Trunc-elim\n (λ _ → =-preserves-level _ Trunc-level)\n (λ h → ap [_] (! (⊙∘-assoc h g f)))\n\n {- Eilenberg-Steenrod Axioms -}\n\n {- Suspension Axiom -}\n C-Susp : (n : ℤ) (X : Ptd i) → C (succ n) (⊙Susp X) == C n X\n C-Susp n X =\n group-ua (SuspAdjointLoopIso.iso X (E (succ (succ n))))\n ∙ ap (→Ω-Group X) (spectrum (succ n))\n\n {- Non-truncated Exactness Axiom -}\n module _ (n : ℤ) {X Y : Ptd i} where\n\n {- [uCF n (⊙cfcod f) ∘ uCF n f] is constant -}\n uC-exact-itok-lemma : (f : fst (X ⊙→ Y)) (g : uCEl n (⊙Cof f))\n → fst (uCF n f) (fst (uCF n (⊙cfcod f)) g) == uCid n X\n uC-exact-itok-lemma (f , fpt) (g , gpt) = ⊙λ=\n (λ x → ap g (! (cfglue f x)) ∙ gpt)\n (ap (g ∘ cfcod f) fpt\n ∙ ap g (ap (cfcod f) (! fpt) ∙ ! (cfglue f (snd X))) ∙ gpt\n =⟨ lemma (cfcod f) g fpt (! (cfglue f (snd X))) gpt ⟩\n ap g (! (cfglue f (snd X))) ∙ gpt\n =⟨ ! (∙-unit-r _) ⟩\n (ap g (! (cfglue f (snd X))) ∙ gpt) ∙ idp ∎)\n where\n lemma : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}\n {a₁ a₂ : A} {b : B} {c : C} (f : A → B) (g : B → C)\n (p : a₁ == a₂) (q : f a₁ == b) (r : g b == c)\n → ap (g ∘ f) p ∙ ap g (ap f (! p) ∙ q) ∙ r == ap g q ∙ r\n lemma f g idp idp idp = idp\n\n {- in kernel of [uCF n f] ⇒ in image of [uCF n (⊙cfcod f)] -}\n uC-exact-ktoi-lemma : (f : fst (X ⊙→ Y)) (g : uCEl n Y)\n → fst (uCF n f) g == uCid n X\n → Σ (uCEl n (⊙Cof f)) (λ h → fst (uCF n (⊙cfcod f)) h == g)\n uC-exact-ktoi-lemma (f , fpt) (h , hpt) p =\n ((g , ! q ∙ hpt) ,\n pair= idp (! (∙-assoc q (! q) hpt) ∙ ap (λ w → w ∙ hpt) (!-inv-r q)))\n where\n g : Cofiber f → Ω (E (succ n))\n g = CofiberRec.f f idp h (! ∘ app= (ap fst p))\n\n q : h (snd Y) == g (cfbase f)\n q = ap g (snd (⊙cfcod (f , fpt)))\n\n {- Truncated Exactness Axiom -}\n module _ (n : ℤ) {X Y : Ptd i} where\n\n {- in image of (CF n (⊙cfcod f)) ⇒ in kernel of (CF n f) -}\n abstract\n C-exact-itok : (f : fst (X ⊙→ Y))\n → is-exact-itok (CF n (⊙cfcod f)) (CF n f)\n C-exact-itok f =\n itok-alt-in (CF n (⊙cfcod f)) (CF n f) (Trunc-level {n = ⟨0⟩}) $\n Trunc-elim (λ _ → =-preserves-level _ (Trunc-level {n = ⟨0⟩}))\n (ap [_] ∘ uC-exact-itok-lemma n f)\n\n {- in kernel of (CF n f) ⇒ in image of (CF n (⊙cfcod f)) -}\n abstract\n C-exact-ktoi : (f : fst (X ⊙→ Y))\n → is-exact-ktoi (CF n (⊙cfcod f)) (CF n f)\n C-exact-ktoi f =\n Trunc-elim\n (λ _ → Π-level (λ _ → raise-level _ Trunc-level))\n (λ h tp → Trunc-rec Trunc-level (lemma h) (–> (Trunc=-equiv _ _) tp))\n where\n lemma : (h : uCEl n Y)\n → fst (uCF n f) h == uCid n X\n → Trunc ⟨-1⟩ (Σ (CEl n (⊙Cof f))\n (λ tk → fst (CF n (⊙cfcod f)) tk == [ h ]))\n lemma h p = [ [ fst wit ] , ap [_] (snd wit) ]\n where\n wit : Σ (uCEl n (⊙Cof f)) (λ k → fst (uCF n (⊙cfcod f)) k == h)\n wit = uC-exact-ktoi-lemma n f h p\n\n C-exact : (f : fst (X ⊙→ Y)) → is-exact (CF n (⊙cfcod f)) (CF n f)\n C-exact f = record {itok = C-exact-itok f; ktoi = C-exact-ktoi f}\n\n {- Additivity Axiom -}\n module _ (n : ℤ) {A : Type i} (X : A → Ptd i)\n (ac : (W : A → Type i) → has-choice ⟨0⟩ A W)\n where\n\n uie : has-choice ⟨0⟩ A (uCEl n ∘ X)\n uie = ac (uCEl n ∘ X)\n\n R' : CEl n (⊙BigWedge X) → Trunc ⟨0⟩ (Π A (uCEl n ∘ X))\n R' = Trunc-rec Trunc-level (λ H → [ (λ a → H ⊙∘ ⊙bwin a) ])\n\n L' : Trunc ⟨0⟩ (Π A (uCEl n ∘ X)) → CEl n (⊙BigWedge X)\n L' = Trunc-rec Trunc-level\n (λ k → [ BigWedgeRec.f idp (fst ∘ k) (! ∘ snd ∘ k) , idp ])\n\n R = unchoose ∘ R'\n L = L' ∘ (is-equiv.g uie)\n\n R'-L' : ∀ y → R' (L' y) == y\n R'-L' = Trunc-elim\n (λ _ → =-preserves-level _ Trunc-level)\n (λ K → ap [_] (λ= (λ a → pair= idp $\n ap (BigWedgeRec.f idp (fst ∘ K) (! ∘ snd ∘ K)) (! (bwglue a)) ∙ idp\n =⟨ ∙-unit-r _ ⟩\n ap (BigWedgeRec.f idp (fst ∘ K) (! ∘ snd ∘ K)) (! (bwglue a))\n =⟨ ap-! (BigWedgeRec.f idp (fst ∘ K) (! ∘ snd ∘ K)) (bwglue a) ⟩\n ! (ap (BigWedgeRec.f idp (fst ∘ K) (! ∘ snd ∘ K)) (bwglue a))\n =⟨ ap ! (BigWedgeRec.glue-β idp (fst ∘ K) (! ∘ snd ∘ K) a) ⟩\n ! (! (snd (K a)))\n =⟨ !-! (snd (K a)) ⟩\n snd (K a) ∎)))\n\n L'-R' : ∀ x → L' (R' x) == x\n L'-R' = Trunc-elim\n {P = λ tH → L' (R' tH) == tH}\n (λ _ → =-preserves-level _ Trunc-level)\n (λ {(h , hpt) → ap [_] (pair=\n (λ= (L-R-fst (h , hpt)))\n (↓-app=cst-in $ ! $\n ap (λ w → w ∙ hpt) (app=-β (L-R-fst (h , hpt)) bwbase)\n ∙ !-inv-l hpt))})\n where\n lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)\n {a₁ a₂ : A} {b : B} (p : a₁ == a₂) (q : f a₁ == b)\n → ! q ∙ ap f p == ! (ap f (! p) ∙ q)\n lemma f idp idp = idp\n\n l∘r : fst (⊙BigWedge X ⊙→ ⊙Ω (E (succ n)))\n → (BigWedge X → Ω (E (succ n)))\n l∘r (h , hpt) =\n BigWedgeRec.f idp (λ a → h ∘ bwin a)\n (λ a → ! (ap h (! (bwglue a)) ∙ hpt))\n\n L-R-fst : (h : fst (⊙BigWedge X ⊙→ ⊙Ω (E (succ n))))\n → ∀ w → (l∘r h) w == fst h w\n L-R-fst (h , hpt) = BigWedge-elim\n (! hpt)\n (λ _ _ → idp)\n (λ a → ↓-='-in $\n ! hpt ∙ ap h (bwglue a)\n =⟨ lemma h (bwglue a) hpt ⟩\n ! (ap h (! (bwglue a)) ∙ hpt)\n =⟨ ! (BigWedgeRec.glue-β idp (λ a → h ∘ bwin a)\n (λ a → ! (ap h (! (bwglue a)) ∙ hpt)) a) ⟩\n ap (l∘r (h , hpt)) (bwglue a) ∎)\n\n R-is-equiv : is-equiv R\n R-is-equiv = uie ∘ise (is-eq R' L' R'-L' L'-R')\n\n pres-comp : (tf tg : CEl n (⊙BigWedge X))\n → R (Group.comp (C n (⊙BigWedge X)) tf tg)\n == Group.comp (Πᴳ A (C n ∘ X)) (R tf) (R tg)\n pres-comp = Trunc-elim\n (λ _ → Π-level (λ _ → =-preserves-level _ (Π-level (λ _ → Trunc-level))))\n (λ {(f , fpt) → Trunc-elim\n (λ _ → =-preserves-level _ (Π-level (λ _ → Trunc-level)))\n (λ {(g , gpt) → λ= $ λ a → ap [_] $\n pair= idp (comp-snd f g (! (bwglue a)) fpt gpt)})})\n where\n comp-snd : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} {b₀ : B}\n {p q : b₀ == b₀} (f : A → b₀ == b₀) (g : A → b₀ == b₀)\n (r : a₁ == a₂) (α : f a₂ == p) (β : g a₂ == q)\n → ap (λ x → f x ∙ g x) r ∙ ap2 _∙_ α β\n == ap2 _∙_ (ap f r ∙ α) (ap g r ∙ β)\n comp-snd f g idp idp idp = idp\n\n abstract\n C-additive : C n (⊙BigWedge X) == Πᴳ A (C n ∘ X)\n C-additive = group-ua (group-hom R pres-comp , R-is-equiv)\n\nopen SpectrumModel\n\nspectrum-cohomology : CohomologyTheory i\nspectrum-cohomology = record {\n C = C;\n CF-hom = CF-hom;\n CF-ident = CF-ident;\n CF-comp = CF-comp;\n C-abelian = C-abelian;\n C-Susp = C-Susp;\n C-exact = C-exact;\n C-additive = C-additive}\n\nspectrum-C-S⁰ : (n : ℤ) → C n (⊙Sphere O) == π 1 (ℕ-S≠O _) (E (succ n))\nspectrum-C-S⁰ n = Bool⊙→Ω-is-π₁ (E (succ n))\n", "meta": {"hexsha": "d38c65238cdb0426a261853473eaabd030b491b1", "size": 9898, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "cohomology/SpectrumModel.agda", "max_stars_repo_name": "danbornside/HoTT-Agda", "max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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": "cohomology/SpectrumModel.agda", "max_issues_repo_name": "danbornside/HoTT-Agda", "max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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": "cohomology/SpectrumModel.agda", "max_forks_repo_name": "danbornside/HoTT-Agda", "max_forks_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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": 36.1240875912, "max_line_length": 79, "alphanum_fraction": 0.4615073752, "num_tokens": 4348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.37217210713236376}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Basics\nopen import lib.cubical.Square\nopen import lib.types.Group\nopen import lib.types.EilenbergMacLane1.Core\n\nmodule lib.types.EilenbergMacLane1.PathElim where\n\nmodule _ {i} (G : Group i) where\n\n private\n module G = Group G\n\n module EM₁Level₂PathElim {k} {C : Type k}\n {{C-level : has-level 2 C}}\n (f₁ f₂ : EM₁ G → C)\n (embase* : f₁ embase == f₂ embase)\n (emloop* : ∀ g →\n Square embase* (ap f₁ (emloop g))\n (ap f₂ (emloop g)) embase*)\n (emloop-comp* : ∀ g₁ g₂ →\n emloop* (G.comp g₁ g₂) ⊡v∙\n ap (ap f₂) (emloop-comp' G g₁ g₂)\n ==\n ap (ap f₁) (emloop-comp' G g₁ g₂) ∙v⊡\n ↓-='-square-comp (emloop* g₁) (emloop* g₂))\n where\n\n private\n module M =\n EM₁Level₁Elim {i} {G}\n {P = λ x → f₁ x == f₂ x}\n {{λ x → has-level-apply C-level _ _}}\n embase*\n (λ g → ↓-='-from-square (emloop* g))\n (λ g₁ g₂ →\n ↓-='-from-square-comp-path (emloop-comp g₁ g₂)\n (emloop* g₁)\n (emloop* g₂)\n (emloop* (G.comp g₁ g₂))\n (emloop-comp* g₁ g₂))\n\n open M public\n\n module EM₁Level₂PathConstElim {k} {C : Type k}\n {{C-level : has-level 2 C}}\n (f : EM₁ G → C) (c : C)\n (embase* : f embase == c)\n (emloop* : ∀ g →\n Square embase* (ap f (emloop g))\n idp embase*)\n (emloop-comp* : ∀ g₁ g₂ →\n emloop* (G.comp g₁ g₂)\n ==\n (ap (ap f) (emloop-comp' G g₁ g₂) ∙\n ap-∙ f (emloop g₁) (emloop g₂)) ∙v⊡\n (emloop* g₁ ⊡h emloop* g₂))\n where\n\n emloop** : ∀ g → Square embase* (ap f (emloop g))\n (ap (cst c) (emloop' G g)) embase*\n emloop** g = emloop* g ⊡v∙ ! (ap-cst c (emloop g))\n\n private\n\n emloop-comp** : ∀ g₁ g₂ →\n emloop** (G.comp g₁ g₂) ⊡v∙ ap (ap (cst c)) (emloop-comp' G g₁ g₂)\n ==\n ap (ap f) (emloop-comp g₁ g₂) ∙v⊡\n ↓-='-square-comp (emloop** g₁) (emloop** g₂)\n emloop-comp** g₁ g₂ =\n (emloop* (G.comp g₁ g₂) ⊡v∙ ! (ap-cst c (emloop (G.comp g₁ g₂)))) ⊡v∙ ap (ap (cst c)) (emloop-comp g₁ g₂)\n =⟨ ⊡v∙-assoc (emloop* (G.comp g₁ g₂))\n (! (ap-cst c (emloop (G.comp g₁ g₂))))\n (ap (ap (cst c)) (emloop-comp g₁ g₂)) ⟩\n emloop* (G.comp g₁ g₂) ⊡v∙\n (! (ap-cst c (emloop (G.comp g₁ g₂))) ∙\n ap (ap (cst c)) (emloop-comp g₁ g₂))\n =⟨ ap (emloop* (G.comp g₁ g₂) ⊡v∙_) $ =ₛ-out $\n ! (ap-cst c (emloop (G.comp g₁ g₂))) ◃∙\n ap (ap (cst c)) (emloop-comp g₁ g₂) ◃∎\n =ₛ⟨ pre-rotate'-in $\n post-rotate-in {p = _ ◃∎} $\n homotopy-naturality-to-cst (ap (cst c)) idp (ap-cst c) (emloop-comp g₁ g₂) ⟩\n ! (ap-cst c (emloop g₁ ∙ emloop g₂)) ◃∎\n =ₛ⟨ !-=ₛ (ap-cst-coh c (emloop g₁) (emloop g₂)) ⟩\n ! (ap2 _∙_ (ap-cst c (emloop g₁)) (ap-cst c (emloop g₂))) ◃∙\n ! (ap-∙ (cst c) (emloop g₁) (emloop g₂)) ◃∎\n =ₛ₁⟨ 0 & 1 & !-ap2 _∙_ (ap-cst c (emloop g₁)) (ap-cst c (emloop g₂)) ⟩\n ap2 _∙_ (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂))) ◃∙\n ! (ap-∙ (cst c) (emloop g₁) (emloop g₂)) ◃∎\n =ₛ₁⟨ 1 & 1 & !ap-∙=∙-ap (cst c) (emloop g₁) (emloop g₂) ⟩\n ap2 _∙_ (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂))) ◃∙\n ∙-ap (cst c) (emloop g₁) (emloop g₂) ◃∎ ∎ₛ\n ⟩\n emloop* (G.comp g₁ g₂) ⊡v∙\n (ap2 _∙_ (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂))) ∙\n ∙-ap (cst c) (emloop g₁) (emloop g₂))\n =⟨ ! $ ⊡v∙-assoc (emloop* (G.comp g₁ g₂))\n (ap2 _∙_ (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂))))\n (∙-ap (cst c) (emloop g₁) (emloop g₂)) ⟩\n (emloop* (G.comp g₁ g₂) ⊡v∙\n ap2 _∙_ (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂)))) ⊡v∙\n ∙-ap (cst c) (emloop g₁) (emloop g₂)\n =⟨ ap (λ s → (s ⊡v∙\n ap2 _∙_ (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂)))) ⊡v∙\n ∙-ap (cst c) (emloop g₁) (emloop g₂))\n (emloop-comp* g₁ g₂) ⟩\n (((ap (ap f) (emloop-comp' G g₁ g₂) ∙\n ap-∙ f (emloop g₁) (emloop g₂)) ∙v⊡\n emloop* g₁ ⊡h emloop* g₂) ⊡v∙\n ap2 _∙_ (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂)))) ⊡v∙\n ∙-ap (cst c) (emloop g₁) (emloop g₂)\n =⟨ ap (_⊡v∙ ∙-ap (cst c) (emloop g₁) (emloop g₂)) $\n ((ap (ap f) (emloop-comp' G g₁ g₂) ∙\n ap-∙ f (emloop g₁) (emloop g₂)) ∙v⊡\n emloop* g₁ ⊡h emloop* g₂) ⊡v∙\n ap2 _∙_ (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂)))\n =⟨ ∙v⊡-⊡v∙-comm\n (ap (ap f) (emloop-comp' G g₁ g₂) ∙ ap-∙ f (emloop g₁) (emloop g₂))\n (emloop* g₁ ⊡h emloop* g₂)\n (ap2 _∙_ (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂)))) ⟩\n (ap (ap f) (emloop-comp' G g₁ g₂) ∙\n ap-∙ f (emloop g₁) (emloop g₂)) ∙v⊡\n ((emloop* g₁ ⊡h emloop* g₂) ⊡v∙\n ap2 _∙_ (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂))))\n =⟨ ap ((ap (ap f) (emloop-comp' G g₁ g₂) ∙\n ap-∙ f (emloop g₁) (emloop g₂)) ∙v⊡_) $\n ⊡h-⊡v∙-comm (emloop* g₁) (emloop* g₂)\n (! (ap-cst c (emloop g₁))) (! (ap-cst c (emloop g₂))) ⟩\n (ap (ap f) (emloop-comp' G g₁ g₂) ∙\n ap-∙ f (emloop g₁) (emloop g₂)) ∙v⊡\n (emloop** g₁ ⊡h emloop** g₂)\n =⟨ ∙v⊡-assoc (ap (ap f) (emloop-comp' G g₁ g₂))\n (ap-∙ f (emloop g₁) (emloop g₂))\n (emloop** g₁ ⊡h emloop** g₂) ⟩\n ap (ap f) (emloop-comp' G g₁ g₂) ∙v⊡\n (ap-∙ f (emloop g₁) (emloop g₂) ∙v⊡\n (emloop** g₁ ⊡h emloop** g₂)) =∎\n ⟩\n (ap (ap f) (emloop-comp' G g₁ g₂) ∙v⊡\n (ap-∙ f (emloop g₁) (emloop g₂) ∙v⊡\n (emloop** g₁ ⊡h emloop** g₂))) ⊡v∙\n ∙-ap (cst c) (emloop g₁) (emloop g₂)\n =⟨ ∙v⊡-⊡v∙-comm (ap (ap f) (emloop-comp' G g₁ g₂))\n (ap-∙ f (emloop g₁) (emloop g₂) ∙v⊡ (emloop** g₁ ⊡h emloop** g₂))\n (∙-ap (cst c) (emloop g₁) (emloop g₂)) ⟩\n ap (ap f) (emloop-comp' G g₁ g₂) ∙v⊡\n (ap-∙ f (emloop g₁) (emloop g₂) ∙v⊡ emloop** g₁ ⊡h emloop** g₂) ⊡v∙ ∙-ap (cst c) (emloop g₁) (emloop g₂)\n =⟨ ap (ap (ap f) (emloop-comp' G g₁ g₂) ∙v⊡_) $\n ∙v⊡-⊡v∙-comm (ap-∙ f (emloop g₁) (emloop g₂))\n (emloop** g₁ ⊡h emloop** g₂)\n (∙-ap (cst c) (emloop g₁) (emloop g₂)) ⟩\n ap (ap f) (emloop-comp' G g₁ g₂) ∙v⊡\n ↓-='-square-comp' (emloop** g₁) (emloop** g₂)\n =⟨ ap (ap (ap f) (emloop-comp' G g₁ g₂) ∙v⊡_) $\n ↓-='-square-comp'=↓-='-square-comp {f = f} {g = cst c}\n (emloop** g₁) (emloop** g₂) ⟩\n ap (ap f) (emloop-comp g₁ g₂) ∙v⊡\n ↓-='-square-comp (emloop** g₁) (emloop** g₂) =∎\n\n module M =\n EM₁Level₂PathElim {k} {C}\n {{C-level}}\n f (cst c)\n embase*\n emloop**\n emloop-comp**\n\n open M public\n", "meta": {"hexsha": "f8eb7a52dcbb65016b20f45e5053bf9d60b27613", "size": 7439, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/types/EilenbergMacLane1/PathElim.agda", "max_stars_repo_name": "AntoineAllioux/HoTT-Agda", "max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "core/lib/types/EilenbergMacLane1/PathElim.agda", "max_issues_repo_name": "AntoineAllioux/HoTT-Agda", "max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "core/lib/types/EilenbergMacLane1/PathElim.agda", "max_forks_repo_name": "AntoineAllioux/HoTT-Agda", "max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 43.25, "max_line_length": 113, "alphanum_fraction": 0.426804678, "num_tokens": 3119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850154599562, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.37217210060573813}} {"text": "-- Andreas, 2014-04-23 test case by Andrea Vezzosi\n{-# OPTIONS --sized-types --copatterns #-}\n-- {-# OPTIONS --show-implicit -v term:60 #-}\nmodule _ where\n\nopen import Common.Size\n\n-- Invalid coinductive record, since not recursive.\nrecord ▸ (A : Size → Set) (i : Size) : Set where\n coinductive -- This should be an error, since non-recursive.\n constructor delay_\n field\n force : ∀ {j : Size< i} → A j\n\nopen ▸\n\n-- This fixed-point combinator should not pass the termination checker.\n∞fix : ∀ {A : Size → Set} → (∀ {i} → ▸ A i → A i) → ∀ {i} → ▸ A i\nforce (∞fix {A} f {i}) {j} = f {j} (∞fix {A} f {j})\n\n-- The following fixed-point combinator is not strongly normalizing!\nfix : ∀ {A : Size → Set} → (∀ {i} → (∀ {j : Size< i} → A j) → A i) → ∀ {i} {j : Size< i} → A j\nfix f = force (∞fix (λ {i} x → f {i} (force x)))\n\n-- test = fix {!!}\n-- C-c C-n test gives me a stack overflow\n", "meta": {"hexsha": "2589fee08031b16c8d90138779e17d0a34a4a4cd", "size": 891, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Bugs/NonRecursiveCoinductiveRecord.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/Bugs/NonRecursiveCoinductiveRecord.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/Bugs/NonRecursiveCoinductiveRecord.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": 33.0, "max_line_length": 94, "alphanum_fraction": 0.5836139169, "num_tokens": 309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7745833841649232, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.37217080046143647}} {"text": "------------------------------------------------------------------------\n-- The values that are used by the NBE algorithm\n------------------------------------------------------------------------\n\nimport Level\nopen import Data.Universe\n\nmodule README.DependentlyTyped.NBE.Value\n (Uni₀ : Universe Level.zero Level.zero)\n where\n\nimport Axiom.Extensionality.Propositional as E\nopen import Data.Product renaming (curry to c; uncurry to uc)\nopen import deBruijn.Substitution.Data\nopen import Function using (id; _ˢ_; _$_) renaming (const to k)\nimport README.DependentlyTyped.NormalForm as NF; open NF Uni₀\nimport README.DependentlyTyped.NormalForm.Substitution as NFS\nopen NFS Uni₀\nimport README.DependentlyTyped.Term as Term; open Term Uni₀\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\nimport Relation.Binary.PropositionalEquality.WithK as P\n\nopen P.≡-Reasoning\n\n-- A wrapper which is used to make V̌alue \"constructor-headed\", which\n-- in turn makes Agda infer more types for us.\n\ninfix 3 _⊢_⟨ne⟩\n\nrecord _⊢_⟨ne⟩ (Γ : Ctxt) (σ : Type Γ) : Set where\n constructor [_]el\n field t : Γ ⊢ σ ⟨ ne ⟩\n\nmutual\n\n -- The values.\n\n V̌alue′ : ∀ Γ sp (σ : IType Γ sp) → Set\n V̌alue′ Γ ⋆ σ = Γ ⊢ ⋆ , σ ⟨ ne ⟩\n V̌alue′ Γ el σ = Γ ⊢ el , σ ⟨ne⟩\n V̌alue′ Γ (π sp₁ sp₂) σ =\n Σ (V̌alue-π Γ sp₁ sp₂ σ) (W̌ell-behaved sp₁ sp₂ σ)\n\n V̌alue : (Γ : Ctxt) (σ : Type Γ) → Set\n V̌alue Γ (sp , σ) = V̌alue′ Γ sp σ\n\n V̌alue-π : ∀ Γ sp₁ sp₂ → IType Γ (π sp₁ sp₂) → Set\n V̌alue-π Γ sp₁ sp₂ σ =\n (Γ₊ : Ctxt₊ Γ)\n (v : V̌alue′ (Γ ++₊ Γ₊) sp₁ (ifst σ /̂I ŵk₊ Γ₊)) →\n V̌alue′ (Γ ++₊ Γ₊) sp₂ (isnd σ /̂I ŵk₊ Γ₊ ↑̂ ∘̂ ŝub ⟦̌ v ⟧)\n\n -- The use of Ctxt₊ rather than Ctxt⁺ in V̌alue-π is important: it\n -- seems to make it much easier to define weakening for V̌alue.\n\n W̌ell-behaved :\n ∀ {Γ} sp₁ sp₂ σ → V̌alue-π Γ sp₁ sp₂ σ → Set\n W̌ell-behaved {Γ} sp₁ sp₂ σ f =\n ∀ Γ₊ v → (⟦̌ σ ∣ f ⟧-π /̂Val ŵk₊ Γ₊) ˢ ⟦̌ v ⟧ ≅-Value ⟦̌ f Γ₊ v ⟧\n\n -- The semantics of a value.\n\n ⟦̌_⟧ : ∀ {Γ sp σ} → V̌alue′ Γ sp σ → Value Γ (sp , σ)\n ⟦̌ v ⟧ = ⟦ řeify _ v ⟧n\n\n ⟦̌_∣_⟧-π : ∀ {Γ sp₁ sp₂} σ →\n V̌alue-π Γ sp₁ sp₂ σ → Value Γ (π sp₁ sp₂ , σ)\n ⟦̌ _ ∣ f ⟧-π = ⟦ řeify-π _ _ _ f ⟧n\n\n -- Neutral terms can be turned into normal terms using reflection\n -- followed by reification.\n\n ňeutral-to-normal :\n ∀ {Γ} sp {σ} → Γ ⊢ sp , σ ⟨ ne ⟩ → Γ ⊢ sp , σ ⟨ no ⟩\n ňeutral-to-normal sp t = řeify sp (řeflect sp t)\n\n -- A normal term corresponding to variable zero.\n\n žero : ∀ {Γ} sp σ → Γ ▻ (sp , σ) ⊢ sp , σ /̂I ŵk ⟨ no ⟩\n žero sp σ = ňeutral-to-normal sp (var zero[ -, σ ])\n\n -- Reification.\n\n řeify : ∀ {Γ} sp {σ} → V̌alue′ Γ sp σ → Γ ⊢ sp , σ ⟨ no ⟩\n řeify ⋆ t = ne ⋆ t\n řeify el [ t ]el = ne el t\n řeify (π sp₁ sp₂) f = řeify-π sp₁ sp₂ _ (proj₁ f)\n\n řeify-π : ∀ {Γ} sp₁ sp₂ σ →\n V̌alue-π Γ sp₁ sp₂ σ → Γ ⊢ π sp₁ sp₂ , σ ⟨ no ⟩\n řeify-π {Γ} sp₁ sp₂ σ f = čast sp₁ σ $\n ƛ (řeify sp₂ (f (fst σ ◅ ε) (řeflect sp₁ (var zero))))\n\n čast : ∀ {Γ} sp₁ {sp₂} (σ : IType Γ (π sp₁ sp₂)) →\n let ρ̂ = ŵk ↑̂ ∘̂ ŝub ⟦ žero sp₁ (ifst σ) ⟧n in\n Γ ⊢ Type-π (fst σ) (snd σ /̂ ρ̂) ⟨ no ⟩ →\n Γ ⊢ -, σ ⟨ no ⟩\n čast {Γ} sp₁ σ =\n P.subst (λ σ → Γ ⊢ σ ⟨ no ⟩)\n (≅-Type-⇒-≡ $ π-fst-snd-ŵk-ŝub-žero sp₁ σ)\n\n -- Reflection.\n\n řeflect : ∀ {Γ} sp {σ} → Γ ⊢ sp , σ ⟨ ne ⟩ → V̌alue Γ (sp , σ)\n řeflect ⋆ t = t\n řeflect el t = [ t ]el\n řeflect (π sp₁ sp₂) t =\n (λ Γ₊ v → řeflect sp₂ ((t /⊢n Renaming.wk₊ Γ₊) · řeify sp₁ v)) ,\n řeflect-π-well-behaved sp₁ sp₂ t\n\n abstract\n\n řeflect-π-well-behaved :\n ∀ {Γ} sp₁ sp₂ {σ} (t : Γ ⊢ π sp₁ sp₂ , σ ⟨ ne ⟩) Γ₊ v →\n let t′ = ňeutral-to-normal sp₂\n ((t /⊢n Renaming.wk) · žero sp₁ (ifst σ)) in\n (⟦ čast sp₁ σ (ƛ t′) ⟧n /̂Val ŵk₊ Γ₊) ˢ ⟦̌ v ⟧\n ≅-Value\n ⟦ ňeutral-to-normal sp₂ ((t /⊢n Renaming.wk₊ Γ₊) · řeify sp₁ v) ⟧n\n řeflect-π-well-behaved sp₁ sp₂ {σ} t Γ₊ v =\n let t′ = ňeutral-to-normal sp₂\n ((t /⊢n Renaming.wk) · žero sp₁ (ifst σ))\n v′ = řeify sp₁ v\n\n lemma′ = begin\n [ ⟦ čast sp₁ σ (ƛ t′) ⟧n /̂Val ŵk₊ Γ₊ ] ≡⟨ /̂Val-cong (ňeutral-to-normal-identity-π sp₁ sp₂ t) P.refl ⟩\n [ ⟦ t ⟧n /̂Val ŵk₊ Γ₊ ] ≡⟨ t /⊢n-lemma Renaming.wk₊ Γ₊ ⟩\n [ ⟦ t /⊢n Renaming.wk₊ Γ₊ ⟧n ] ∎\n\n in begin\n [ (⟦ čast sp₁ σ (ƛ t′) ⟧n /̂Val ŵk₊ Γ₊) ˢ ⟦ v′ ⟧n ] ≡⟨ ˢ-cong lemma′ P.refl ⟩\n [ ⟦ t /⊢n Renaming.wk₊ Γ₊ ⟧n ˢ ⟦ v′ ⟧n ] ≡⟨ P.refl ⟩\n [ ⟦ (t /⊢n Renaming.wk₊ Γ₊) · v′ ⟧n ] ≡⟨ P.sym $ ňeutral-to-normal-identity sp₂ _ ⟩\n [ ⟦ ňeutral-to-normal sp₂ ((t /⊢n Renaming.wk₊ Γ₊) · v′) ⟧n ] ∎\n\n -- A given context morphism is equal to the identity.\n\n ŵk-ŝub-žero :\n ∀ {Γ} sp₁ {sp₂} (σ : IType Γ (π sp₁ sp₂)) →\n ŵk ↑̂ fst σ ∘̂ ŝub ⟦ žero sp₁ (ifst σ) ⟧n ≅-⇨̂ îd[ Γ ▻ fst σ ]\n ŵk-ŝub-žero sp₁ σ = begin\n [ ŵk ↑̂ ∘̂ ŝub ⟦ žero sp₁ (ifst σ) ⟧n ] ≡⟨ ∘̂-cong (P.refl {x = [ ŵk ↑̂ ]})\n (ŝub-cong (ňeutral-to-normal-identity sp₁ (var zero))) ⟩\n [ ŵk ↑̂ ∘̂ ŝub ⟦ var zero ⟧n ] ≡⟨ P.refl ⟩\n [ îd ] ∎\n\n -- A corollary of the lemma above.\n\n π-fst-snd-ŵk-ŝub-žero :\n ∀ {Γ} sp₁ {sp₂} (σ : IType Γ (π sp₁ sp₂)) →\n Type-π (fst σ) (snd σ /̂ ŵk ↑̂ ∘̂ ŝub ⟦ žero sp₁ (ifst σ) ⟧n) ≅-Type\n (-, σ)\n π-fst-snd-ŵk-ŝub-žero sp₁ σ = begin\n [ Type-π (fst σ) (snd σ /̂ ŵk ↑̂ ∘̂ ŝub ⟦ žero sp₁ (ifst σ) ⟧n) ] ≡⟨ Type-π-cong $ /̂-cong (P.refl {x = [ snd σ ]})\n (ŵk-ŝub-žero sp₁ σ) ⟩\n [ Type-π (fst σ) (snd σ) ] ≡⟨ P.refl ⟩\n [ -, σ ] ∎\n\n -- In the semantics řeify is a left inverse of řeflect.\n\n ňeutral-to-normal-identity :\n ∀ {Γ} sp {σ} (t : Γ ⊢ sp , σ ⟨ ne ⟩) →\n ⟦ ňeutral-to-normal sp t ⟧n ≅-Value ⟦ t ⟧n\n ňeutral-to-normal-identity ⋆ t = P.refl\n ňeutral-to-normal-identity el t = P.refl\n ňeutral-to-normal-identity (π sp₁ sp₂) t =\n ňeutral-to-normal-identity-π sp₁ sp₂ t\n\n ňeutral-to-normal-identity-π :\n ∀ {Γ} sp₁ sp₂ {σ} (t : Γ ⊢ π sp₁ sp₂ , σ ⟨ ne ⟩) →\n let t′ = ňeutral-to-normal sp₂\n ((t /⊢n Renaming.wk) · žero sp₁ (ifst σ)) in\n ⟦ čast sp₁ σ (ƛ t′) ⟧n ≅-Value ⟦ t ⟧n\n ňeutral-to-normal-identity-π sp₁ sp₂ {σ} t =\n let t′ = (t /⊢n Renaming.wk) · žero sp₁ (ifst σ)\n\n lemma = begin\n [ ⟦ ňeutral-to-normal sp₂ t′ ⟧n ] ≡⟨ ňeutral-to-normal-identity sp₂ t′ ⟩\n [ ⟦ t′ ⟧n ] ≡⟨ P.refl ⟩\n [ ⟦ t /⊢n Renaming.wk ⟧n ˢ ⟦ žero sp₁ (ifst σ) ⟧n ] ≡⟨ ˢ-cong (P.sym $ t /⊢n-lemma Renaming.wk)\n (ňeutral-to-normal-identity sp₁ (var zero)) ⟩\n [ (⟦ t ⟧n /̂Val ŵk) ˢ lookup zero ] ≡⟨ P.refl ⟩\n [ uc ⟦ t ⟧n ] ∎\n\n in begin\n [ ⟦ čast sp₁ σ (ƛ (ňeutral-to-normal sp₂ t′)) ⟧n ] ≡⟨ ⟦⟧n-cong $ drop-subst-⊢n id (≅-Type-⇒-≡ $ π-fst-snd-ŵk-ŝub-žero sp₁ σ) ⟩\n [ c ⟦ ňeutral-to-normal sp₂ t′ ⟧n ] ≡⟨ curry-cong lemma ⟩\n [ c {C = k El ˢ isnd σ} (uc ⟦ t ⟧n) ] ≡⟨ P.refl ⟩\n [ ⟦ t ⟧n ] ∎\n\n-- An immediate consequence of the somewhat roundabout definition\n-- above.\n\nw̌ell-behaved :\n ∀ {Γ sp₁ sp₂ σ} (f : V̌alue Γ (π sp₁ sp₂ , σ)) →\n ∀ Γ₊ v → (⟦̌_⟧ {σ = σ} f /̂Val ŵk₊ Γ₊) ˢ ⟦̌ v ⟧ ≅-Value ⟦̌ proj₁ f Γ₊ v ⟧\nw̌ell-behaved = proj₂\n\n-- Values are term-like.\n\nV̌al : Term-like _\nV̌al = record\n { _⊢_ = V̌alue\n ; ⟦_⟧ = ⟦̌_⟧\n }\n\nopen Term-like V̌al public\n using ([_])\n renaming ( _≅-⊢_ to _≅-V̌alue_\n ; drop-subst-⊢ to drop-subst-V̌alue; ⟦⟧-cong to ⟦̌⟧-cong\n )\n\nabstract\n\n -- Unfolding lemma for ⟦̌_∣_⟧-π.\n\n unfold-⟦̌∣⟧-π :\n ∀ {Γ sp₁ sp₂} σ (f : V̌alue-π Γ sp₁ sp₂ σ) →\n ⟦̌ σ ∣ f ⟧-π ≅-Value c ⟦̌ f (fst σ ◅ ε) (řeflect sp₁ (var zero)) ⟧\n unfold-⟦̌∣⟧-π σ _ = ⟦⟧n-cong $\n drop-subst-⊢n id (≅-Type-⇒-≡ $ π-fst-snd-ŵk-ŝub-žero _ σ)\n\n-- Some congruence/conversion lemmas.\n\n≅-⊢n-⇒-≅-Value-⋆ : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ ⋆ , σ₁ ⟨ ne ⟩}\n {Γ₂ σ₂} {t₂ : Γ₂ ⊢ ⋆ , σ₂ ⟨ ne ⟩} →\n t₁ ≅-⊢n t₂ → t₁ ≅-V̌alue t₂\n≅-⊢n-⇒-≅-Value-⋆ P.refl = P.refl\n\n≅-Value-⋆-⇒-≅-⊢n : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ ⋆ , σ₁ ⟨ ne ⟩}\n {Γ₂ σ₂} {t₂ : Γ₂ ⊢ ⋆ , σ₂ ⟨ ne ⟩} →\n t₁ ≅-V̌alue t₂ → t₁ ≅-⊢n t₂\n≅-Value-⋆-⇒-≅-⊢n P.refl = P.refl\n\n≅-⊢n-⇒-≅-Value-el : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ el , σ₁ ⟨ ne ⟩}\n {Γ₂ σ₂} {t₂ : Γ₂ ⊢ el , σ₂ ⟨ ne ⟩} →\n t₁ ≅-⊢n t₂ → [ t₁ ]el ≅-V̌alue [ t₂ ]el\n≅-⊢n-⇒-≅-Value-el P.refl = P.refl\n\n≅-Value-el-⇒-≅-⊢n : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ el , σ₁ ⟨ ne ⟩}\n {Γ₂ σ₂} {t₂ : Γ₂ ⊢ el , σ₂ ⟨ ne ⟩} →\n [ t₁ ]el ≅-V̌alue [ t₂ ]el → t₁ ≅-⊢n t₂\n≅-Value-el-⇒-≅-⊢n P.refl = P.refl\n\nabstract\n\n ,-cong : E.Extensionality Level.zero Level.zero →\n ∀ {Γ sp₁ sp₂ σ} {f₁ f₂ : V̌alue Γ (π sp₁ sp₂ , σ)} →\n (∀ Γ₊ v → proj₁ f₁ Γ₊ v ≅-V̌alue proj₁ f₂ Γ₊ v) →\n _≅-V̌alue_ {σ₁ = (π sp₁ sp₂ , σ)} f₁\n {σ₂ = (π sp₁ sp₂ , σ)} f₂\n ,-cong ext hyp = P.cong (Term-like.[_] {_} {V̌al}) $\n ,-cong′ (ext λ Γ₊ → ext λ v → Term-like.≅-⊢-⇒-≡ V̌al $ hyp Γ₊ v)\n (ext λ _ → ext λ _ → P.≡-irrelevant _ _)\n where\n ,-cong′ : {A : Set} {B : A → Set}\n {x₁ x₂ : A} {y₁ : B x₁} {y₂ : B x₂} →\n (eq : x₁ ≡ x₂) → P.subst B eq y₁ ≡ y₂ →\n _≡_ {A = Σ A B} (x₁ , y₁) (x₂ , y₂)\n ,-cong′ P.refl P.refl = P.refl\n\nňeutral-to-normal-cong :\n ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ σ₁ ⟨ ne ⟩}\n {Γ₂ σ₂} {t₂ : Γ₂ ⊢ σ₂ ⟨ ne ⟩} →\n t₁ ≅-⊢n t₂ → ňeutral-to-normal _ t₁ ≅-⊢n ňeutral-to-normal _ t₂\nňeutral-to-normal-cong P.refl = P.refl\n\nžero-cong : ∀ {Γ₁} {σ₁ : Type Γ₁}\n {Γ₂} {σ₂ : Type Γ₂} →\n σ₁ ≅-Type σ₂ → žero _ (proj₂ σ₁) ≅-⊢n žero _ (proj₂ σ₂)\nžero-cong P.refl = P.refl\n\nřeify-cong : ∀ {Γ₁ σ₁} {v₁ : V̌alue Γ₁ σ₁}\n {Γ₂ σ₂} {v₂ : V̌alue Γ₂ σ₂} →\n v₁ ≅-V̌alue v₂ → řeify _ v₁ ≅-⊢n řeify _ v₂\nřeify-cong P.refl = P.refl\n\nřeflect-cong : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ σ₁ ⟨ ne ⟩}\n {Γ₂ σ₂} {t₂ : Γ₂ ⊢ σ₂ ⟨ ne ⟩} →\n t₁ ≅-⊢n t₂ → řeflect _ t₁ ≅-V̌alue řeflect _ t₂\nřeflect-cong P.refl = P.refl\n", "meta": {"hexsha": "9348711e4ce4de8e8ebf8cbc51a61d71bd4b07a3", "size": 10783, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "README/DependentlyTyped/NBE/Value.agda", "max_stars_repo_name": "nad/dependently-typed-syntax", "max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z", "max_issues_repo_path": "README/DependentlyTyped/NBE/Value.agda", "max_issues_repo_name": "nad/dependently-typed-syntax", "max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "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": "README/DependentlyTyped/NBE/Value.agda", "max_forks_repo_name": "nad/dependently-typed-syntax", "max_forks_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "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.2375886525, "max_line_length": 138, "alphanum_fraction": 0.4542335157, "num_tokens": 5185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.3721451712048265}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.Homotopy.Connected where\n\nopen import Cubical.Core.Everything\nopen import Cubical.Foundations.Everything\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.GroupoidLaws\nopen import Cubical.Foundations.Path\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Functions.Fibration\nopen import Cubical.Data.Nat\nopen import Cubical.Data.Prod hiding (map)\nopen import Cubical.Data.Sigma hiding (_×_)\nopen import Cubical.HITs.Nullification\nopen import Cubical.HITs.Susp\nopen import Cubical.HITs.SmashProduct\nopen import Cubical.HITs.Truncation as Trunc renaming (rec to trRec)\nopen import Cubical.Homotopy.Loopspace\nopen import Cubical.HITs.Pushout\nopen import Cubical.HITs.Sn.Base\nopen import Cubical.HITs.S1\nopen import Cubical.Data.Bool\nopen import Cubical.Data.Unit\n\n-- Note that relative to most sources, this notation is off by +2\nisConnected : ∀ {ℓ} (n : HLevel) (A : Type ℓ) → Type ℓ\nisConnected n A = isContr (hLevelTrunc n A)\n\nisConnectedFun : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')\nisConnectedFun n f = ∀ b → isConnected n (fiber f b)\n\nisTruncatedFun : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')\nisTruncatedFun n f = ∀ b → isOfHLevel n (fiber f b)\n\nisConnectedSubtr : ∀ {ℓ} {A : Type ℓ} (n m : HLevel)\n → isConnected (m + n) A\n → isConnected n A\nisConnectedSubtr {A = A} n m iscon =\n isOfHLevelRetractFromIso 0 (truncOfTruncIso n m) (helper n iscon)\n where\n helper : (n : ℕ) → isConnected (m + n) A → isContr (hLevelTrunc n (hLevelTrunc (m + n) A))\n helper zero iscon = isContrUnit*\n helper (suc n) iscon = ∣ iscon .fst ∣ , (Trunc.elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ a → cong ∣_∣ (iscon .snd a))\n\n\nisConnectedFunSubtr : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (n m : HLevel) (f : A → B)\n → isConnectedFun (m + n) f\n → isConnectedFun n f\nisConnectedFunSubtr n m f iscon b = isConnectedSubtr n m (iscon b)\n\nprivate\n typeToFiberIso : ∀ {ℓ} (A : Type ℓ) → Iso A (fiber (λ (x : A) → tt) tt)\n Iso.fun (typeToFiberIso A) x = x , refl\n Iso.inv (typeToFiberIso A) = fst\n Iso.rightInv (typeToFiberIso A) b i = fst b , (isOfHLevelSuc 1 (isPropUnit) tt tt (snd b) refl) i\n Iso.leftInv (typeToFiberIso A) a = refl\n\n typeToFiber : ∀ {ℓ} (A : Type ℓ) → A ≡ fiber (λ (x : A) → tt) tt\n typeToFiber A = isoToPath (typeToFiberIso A)\n\n\n\nmodule elim {ℓ ℓ' : Level} {A : Type ℓ} {B : Type ℓ'} (f : A → B) where\n private\n inv : ∀ {ℓ'''} (n : HLevel) (P : B → TypeOfHLevel ℓ''' (suc n))\n → ((a : A) → P (f a) .fst)\n → (b : B)\n → hLevelTrunc (suc n) (fiber f b) → P b .fst\n inv n P t b =\n Trunc.rec\n (P b .snd)\n (λ {(a , p) → subst (fst ∘ P) p (t a)})\n\n isIsoPrecompose : ∀ {ℓ'''} (n : ℕ) (P : B → TypeOfHLevel ℓ''' n)\n → isConnectedFun n f\n → Iso ((b : B) → P b .fst) ((a : A) → P (f a) .fst)\n isIsoPrecompose zero P fConn = isContr→Iso (isOfHLevelΠ _ (λ b → P b .snd)) (isOfHLevelΠ _ λ a → P (f a) .snd)\n Iso.fun (isIsoPrecompose (suc n) P fConn) = _∘ f\n Iso.inv (isIsoPrecompose (suc n) P fConn) t b = inv n P t b (fConn b .fst)\n Iso.rightInv (isIsoPrecompose (suc n) P fConn) t =\n funExt λ a → cong (inv n P t (f a)) (fConn (f a) .snd ∣ a , refl ∣)\n ∙ substRefl {B = fst ∘ P} (t a)\n Iso.leftInv (isIsoPrecompose (suc n) P fConn) s =\n funExt λ b →\n Trunc.elim\n {B = λ d → inv n P (s ∘ f) b d ≡ s b}\n (λ _ → isOfHLevelPath (suc n) (P b .snd) _ _)\n (λ {(a , p) i → transp (λ j → P (p (j ∨ i)) .fst) i (s (p i))})\n (fConn b .fst)\n\n isEquivPrecompose : ∀ {ℓ'''} (n : ℕ) (P : B → TypeOfHLevel ℓ''' n)\n → isConnectedFun n f\n → isEquiv (λ(s : (b : B) → P b .fst) → s ∘ f)\n isEquivPrecompose zero P fConn = isoToIsEquiv theIso\n where\n theIso : Iso ((b : B) → P b .fst) ((a : A) → P (f a) .fst)\n Iso.fun theIso = λ(s : (b : B) → P b .fst) → s ∘ f\n Iso.inv theIso = λ _ b → P b .snd .fst\n Iso.rightInv theIso g = funExt λ x → P (f x) .snd .snd (g x)\n Iso.leftInv theIso g = funExt λ x → P x .snd .snd (g x)\n isEquivPrecompose (suc n) P fConn = isoToIsEquiv (isIsoPrecompose (suc n) P fConn)\n\n isConnectedPrecompose : (n : ℕ) → ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') n)\n → hasSection (λ(s : (b : B) → P b .fst) → s ∘ f))\n → isConnectedFun n f\n isConnectedPrecompose zero P→sect b = isContrUnit*\n isConnectedPrecompose (suc n) P→sect b = c n P→sect b , λ y → sym (fun n P→sect b y)\n where\n P : (n : HLevel) → ((P : B → TypeOfHLevel ℓ (suc n))\n → hasSection (λ(s : (b : B) → P b .fst) → s ∘ f))\n → B → Type _\n P n s b = hLevelTrunc (suc n) (fiber f b)\n\n c : (n : HLevel) → ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') (suc n))\n → hasSection (λ(s : (b : B) → P b .fst) → s ∘ f)) → (b : B)\n → hLevelTrunc (suc n) (fiber f b)\n c n s = (s λ b → (hLevelTrunc (suc n) (fiber f b) , isOfHLevelTrunc _)) .fst\n λ a → ∣ a , refl ∣\n\n fun : (n : HLevel) (P→sect : ((P : B → TypeOfHLevel (ℓ-max ℓ ℓ') (suc n))\n → hasSection λ(s : (b : B) → P b .fst) → s ∘ f))\n → (b : B) (w : (hLevelTrunc (suc n) (fiber f b)))\n → w ≡ c n P→sect b\n fun n P→sect b = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)\n λ a → J (λ b p → ∣ (fst a) , p ∣ ≡ c n P→sect b)\n (c* (fst a))\n (snd a)\n where\n c* : ((a : A) → ∣ (a , refl {x = f a}) ∣ ≡ c n P→sect (f a))\n c* a = sym (cong (λ x → x a) (P→sect (λ b → hLevelTrunc (suc n) (fiber f b) , isOfHLevelTrunc _) .snd λ a → ∣ a , refl ∣))\n\nisOfHLevelPrecomposeConnected : ∀ {ℓ ℓ' ℓ''} (k : HLevel) (n : HLevel)\n {A : Type ℓ} {B : Type ℓ'} (P : B → TypeOfHLevel ℓ'' (k + n)) (f : A → B)\n → isConnectedFun n f\n → isOfHLevelFun k (λ(s : (b : B) → P b .fst) → s ∘ f)\nisOfHLevelPrecomposeConnected zero n P f fConn =\n elim.isEquivPrecompose f n P fConn .equiv-proof\nisOfHLevelPrecomposeConnected (suc k) n P f fConn t =\n isOfHLevelPath'⁻ k\n λ {(s₀ , p₀) (s₁ , p₁) →\n isOfHLevelRetractFromIso k (invIso ΣPathIsoPathΣ)\n (subst (isOfHLevel k)\n (sym (fiberPath (s₀ , p₀) (s₁ , p₁)))\n (isOfHLevelRetract k\n (λ {(q , α) → (funExt⁻ q) , (cong funExt⁻ α)})\n (λ {(h , β) → (funExt h) , (cong funExt β)})\n (λ _ → refl)\n (isOfHLevelPrecomposeConnected k n\n (λ b → (s₀ b ≡ s₁ b) , isOfHLevelPath' (k + n) (P b .snd) _ _)\n f fConn\n (funExt⁻ (p₀ ∙∙ refl ∙∙ sym p₁)))))}\n\nindMapEquiv→conType : ∀ {ℓ} {A : Type ℓ} (n : HLevel)\n → ((B : TypeOfHLevel ℓ n)\n → isEquiv (λ (b : (fst B)) → λ (a : A) → b))\n → isConnected n A\nindMapEquiv→conType {A = A} zero BEq = isContrUnit*\nindMapEquiv→conType {A = A} (suc n) BEq =\n isOfHLevelRetractFromIso 0 (mapCompIso {n = (suc n)} (typeToFiberIso A))\n (elim.isConnectedPrecompose (λ _ → tt) (suc n)\n (λ P → ((λ a _ → a) ∘ invIsEq (BEq (P tt)))\n , λ a → equiv-proof (BEq (P tt)) a .fst .snd)\n tt)\n\nisConnectedPath : ∀ {ℓ} (n : HLevel) {A : Type ℓ}\n → isConnected (suc n) A\n → (a₀ a₁ : A) → isConnected n (a₀ ≡ a₁)\nisConnectedPath zero connA a₀ a₁ = isContrUnit*\nisConnectedPath (suc n) connA a₀ a₁ =\n isOfHLevelRetractFromIso 0\n (invIso (PathIdTruncIso (suc n)))\n (isContr→isContrPath connA _ _)\n\nisConnectedPathP : ∀ {ℓ} (n : HLevel) {A : I → Type ℓ}\n → isConnected (suc n) (A i1)\n → (a₀ : A i0) (a₁ : A i1) → isConnected n (PathP A a₀ a₁)\nisConnectedPathP n con a₀ a₁ =\n subst (isConnected n) (sym (PathP≡Path _ _ _))\n (isConnectedPath n con _ _)\n\nisConnectedRetract : ∀ {ℓ ℓ'} (n : HLevel)\n {A : Type ℓ} {B : Type ℓ'}\n (f : A → B) (g : B → A)\n (h : (x : A) → g (f x) ≡ x)\n → isConnected n B → isConnected n A\nisConnectedRetract zero _ _ _ _ = isContrUnit*\nisConnectedRetract (suc n) f g h =\n isContrRetract\n (Trunc.map f)\n (Trunc.map g)\n (Trunc.elim\n (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)\n (λ a → cong ∣_∣ (h a)))\n\nisConnectedRetractFromIso : ∀ {ℓ ℓ'} (n : HLevel)\n {A : Type ℓ} {B : Type ℓ'}\n → Iso A B\n → isConnected n B → isConnected n A\nisConnectedRetractFromIso n e =\n isConnectedRetract n\n (Iso.fun e)\n (Iso.inv e)\n (Iso.leftInv e)\n\nisConnectedPoint : ∀ {ℓ} (n : HLevel) {A : Type ℓ}\n → isConnected (suc n) A\n → (a : A) → isConnectedFun n (λ(_ : Unit) → a)\nisConnectedPoint n connA a₀ a =\n isConnectedRetract n\n snd (_ ,_) (λ _ → refl)\n (isConnectedPath n connA a₀ a)\n\nisConnectedPoint2 : ∀ {ℓ} (n : HLevel) {A : Type ℓ} (a : A)\n → isConnectedFun n (λ(_ : Unit) → a)\n → isConnected (suc n) A\nisConnectedPoint2 n {A = A} a connMap = indMapEquiv→conType _ λ B → isoToIsEquiv (theIso B)\n where\n module _ {ℓ' : Level} (B : TypeOfHLevel ℓ' (suc n))\n where\n helper : (f : A → fst B) → (a2 : A) → f a2 ≡ f a\n helper f = equiv-proof (elim.isEquivPrecompose (λ _ → a) n (λ a2 → (f a2 ≡ f a) ,\n isOfHLevelPath' n (snd B) (f a2) (f a)) connMap) (λ _ → refl) .fst .fst\n\n theIso : Iso (fst B) (A → fst B)\n Iso.fun theIso b a = b\n Iso.inv theIso f = f a\n Iso.rightInv theIso f = funExt λ y → sym (helper f y)\n Iso.leftInv theIso _ = refl\n\nconnectedTruncIso : ∀ {ℓ} {A B : Type ℓ} (n : HLevel) (f : A → B)\n → isConnectedFun n f\n → Iso (hLevelTrunc n A) (hLevelTrunc n B)\nconnectedTruncIso {A = A} {B = B} zero f con = isContr→Iso isContrUnit* isContrUnit*\nconnectedTruncIso {A = A} {B = B} (suc n) f con = g\n where\n back : B → hLevelTrunc (suc n) A\n back y = map fst ((con y) .fst)\n\n backSection : (b : B) → Path (hLevelTrunc (suc n) B)\n (Trunc.rec (isOfHLevelTrunc (suc n))\n (λ a → ∣ f a ∣)\n (Trunc.rec {n = n}\n {B = hLevelTrunc (suc n) A} (isOfHLevelTrunc (suc n))\n back ∣ b ∣))\n ∣ b ∣\n backSection b = helper (λ p → map f p ≡ ∣ b ∣)\n (λ x → (isOfHLevelSuc (suc n) (isOfHLevelTrunc (suc n)))\n (map f (map fst x)) ∣ b ∣)\n (λ a p → cong ∣_∣ p)\n (fst (con b))\n where\n helper : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : A → Type ℓ'} (P : hLevelTrunc (suc n) A → Type ℓ'')\n → ((x : hLevelTrunc (suc n) (Σ A B)) → isOfHLevel (suc n) (P (map fst x)))\n → ((a : A) (b : B a) → P ∣ a ∣)\n → (p : hLevelTrunc (suc n) (Σ A B))\n → P (map fst p)\n helper P hlev pf = Trunc.elim hlev λ pair → pf (fst pair) (snd pair)\n\n g : Iso (hLevelTrunc (suc n) A) (hLevelTrunc (suc n) B)\n Iso.fun g = map f\n Iso.inv g = Trunc.rec (isOfHLevelTrunc _) back\n Iso.leftInv g = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)\n λ a → cong (map fst) (con (f a) .snd ∣ a , refl ∣)\n Iso.rightInv g = Trunc.elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc _) _ _)\n backSection\n\nconnectedTruncIso2 : ∀ {ℓ} {A B : Type ℓ} (n m : HLevel) (f : A → B)\n → Σ[ x ∈ ℕ ] x + n ≡ m\n → isConnectedFun m f\n → Iso (hLevelTrunc n A) (hLevelTrunc n B)\nconnectedTruncIso2 {A = A} {B = B} n m f (x , pf) con =\n connectedTruncIso n f (isConnectedFunSubtr n x f (transport (λ i → isConnectedFun (pf (~ i)) f) con))\n\nconnectedTruncEquiv : ∀ {ℓ} {A B : Type ℓ} (n : HLevel) (f : A → B)\n → isConnectedFun n f\n → hLevelTrunc n A ≃ hLevelTrunc n B\nconnectedTruncEquiv {A = A} {B = B} n f con = isoToEquiv (connectedTruncIso n f con)\n\n\n-- TODO : Reorganise the following proofs.\n\ninrConnected : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} (n : HLevel)\n → (f : C → A) (g : C → B)\n → isConnectedFun n f\n → isConnectedFun n {A = B} {B = Pushout f g} inr\ninrConnected {A = A} {B = B} {C = C} n f g iscon =\n elim.isConnectedPrecompose inr n λ P → (k P) , λ b → refl\n where\n module _ {ℓ : Level} (P : (Pushout f g) → TypeOfHLevel ℓ n)\n (h : (b : B) → typ (P (inr b)))\n where\n Q : A → TypeOfHLevel _ n\n Q a = (P (inl a))\n\n fun : (c : C) → typ (Q (f c))\n fun c = transport (λ i → typ (P (push c (~ i)))) (h (g c))\n\n k : (d : Pushout f g) → typ (P d)\n k (inl x) = equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .fst x\n k (inr x) = h x\n k (push a i) =\n hcomp (λ k → λ { (i = i0) → equiv-proof (elim.isEquivPrecompose f n Q iscon) fun .fst .snd i0 a\n ; (i = i1) → transportTransport⁻ (λ j → typ (P (push a j))) (h (g a)) k })\n (transp (λ j → typ (P (push a (i ∧ j))))\n (~ i)\n (equiv-proof (elim.isEquivPrecompose f n Q iscon)\n fun .fst .snd i a))\n", "meta": {"hexsha": "2693bc83e07fbed6695c7f56764baeb0c058b972", "size": 13529, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Homotopy/Connected.agda", "max_stars_repo_name": "ayberkt/cubical", "max_stars_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f", "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": "Cubical/Homotopy/Connected.agda", "max_issues_repo_name": "ayberkt/cubical", "max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f", "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": "Cubical/Homotopy/Connected.agda", "max_forks_repo_name": "ayberkt/cubical", "max_forks_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f", "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": 43.501607717, "max_line_length": 145, "alphanum_fraction": 0.5298248208, "num_tokens": 5037, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6619228891883799, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.3721174937001413}} {"text": "------------------------------------------------------------------------\n-- A virtual machine\n------------------------------------------------------------------------\n\nopen import Prelude\n\nimport Lambda.Virtual-machine.Instructions\n\nmodule Lambda.Virtual-machine\n {Name : Type}\n (open Lambda.Virtual-machine.Instructions Name)\n (def : Name → Code 1)\n where\n\nopen import Equality.Propositional\n\nopen import Colist equality-with-J as Colist using (Colist)\nopen import List equality-with-J using (_++_; length)\nopen import Monad equality-with-J\nopen import Vec.Data equality-with-J\n\nopen import Lambda.Delay-crash using (Delay-crash)\nopen import Lambda.Delay-crash-trace\nopen import Lambda.Syntax Name\n\nopen Closure Code\n\n-- A single step of the computation.\n\nstep : State → Result\nstep ⟨ var x ∷ c , s , ρ ⟩ = continue ⟨ c , val (index ρ x) ∷ s , ρ ⟩\nstep ⟨ clo c′ ∷ c , s , ρ ⟩ = continue ⟨ c , val (lam c′ ρ) ∷ s , ρ ⟩\nstep ⟨ app ∷ c , val v ∷ val (lam c′ ρ′) ∷ s , ρ ⟩ = continue ⟨ c′ , ret c ρ ∷ s , v ∷ ρ′ ⟩\nstep ⟨ ret ∷ c , val v ∷ ret c′ ρ′ ∷ s , ρ ⟩ = continue ⟨ c′ , val v ∷ s , ρ′ ⟩\nstep ⟨ cal f ∷ c , val v ∷ s , ρ ⟩ = continue ⟨ def f , ret c ρ ∷ s , v ∷ [] ⟩\nstep ⟨ tcl f ∷ c , val v ∷ s , ρ ⟩ = continue ⟨ def f , s , v ∷ [] ⟩\nstep ⟨ con b ∷ c , s , ρ ⟩ = continue ⟨ c , val (con b) ∷ s , ρ ⟩\nstep ⟨ bra c₁ c₂ ∷ c , val (con true) ∷ s , ρ ⟩ = continue ⟨ c₁ ++ c , s , ρ ⟩\nstep ⟨ bra c₁ c₂ ∷ c , val (con false) ∷ s , ρ ⟩ = continue ⟨ c₂ ++ c , s , ρ ⟩\nstep ⟨ [] , val v ∷ [] , [] ⟩ = done v\nstep _ = crash\n\n-- A functional semantics for the VM. The result includes a trace of\n-- all the encountered states.\n\nmutual\n\n exec⁺ : ∀ {i} → State → Delay-crash-trace State Value i\n exec⁺ s = later s λ { .force → exec⁺′ (step s) }\n\n exec⁺′ : ∀ {i} → Result → Delay-crash-trace State Value i\n exec⁺′ (continue s) = exec⁺ s\n exec⁺′ (done v) = now v\n exec⁺′ crash = crash\n\n-- The semantics without the trace of states.\n\nexec : ∀ {i} → State → Delay-crash Value i\nexec = delay-crash ∘ exec⁺\n\n-- The stack sizes of all the encountered states.\n\nstack-sizes : ∀ {i} → State → Colist ℕ i\nstack-sizes =\n Colist.map (λ { ⟨ _ , s , _ ⟩ → length s }) ∘ trace ∘ exec⁺\n", "meta": {"hexsha": "68fd48d7161c3a23d5967959c486599590a31a2f", "size": 2594, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Lambda/Virtual-machine.agda", "max_stars_repo_name": "nad/definitional-interpreters", "max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96", "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/Lambda/Virtual-machine.agda", "max_issues_repo_name": "nad/definitional-interpreters", "max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96", "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/Virtual-machine.agda", "max_forks_repo_name": "nad/definitional-interpreters", "max_forks_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96", "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.303030303, "max_line_length": 112, "alphanum_fraction": 0.4718581342, "num_tokens": 804, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.3721174862016143}} {"text": "-- Andreas, 2018-06-12, issue #2170\n-- Reported by tomjack\n\n{-# OPTIONS --irrelevant-projections --subtyping #-}\n\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Bool\n\ninfixr 42 _,_\nrecord Σ (A : Set) (B : A → Set) : Set where\n constructor _,_\n field\n fst : A\n snd : B fst\nopen Σ\n\nrecord Irr (A : Set) : Set where\n constructor irr\n field\n .unirr : A\nopen Irr\n\n-- Usually, unirr (irr a) = .(a) which is DontCare a in internal syntax.\n-- The DontCare protection of an irrelevant field could be circumvented\n-- using subtyping irr : (.Bool → Irr Bool) ≤ (Bool → Irr Bool):\n-- The argument a in (i a) would not have ArgInfo Irrelevant, even\n-- after substitution irr/i. Since the DontCare came from the ArgInfo of a,\n-- there was none. Now, the record constructor name also carries ArgInfo for\n-- each of its fields, which is used to produce a DontCare.\n\nbizarre : Irr (Σ (Bool → Irr Bool) (λ i → Σ (Irr Bool → Bool) (λ u → (a : Bool) → u (i a) ≡ a)))\nbizarre = irr (irr , unirr , λ a → refl) -- Should not pass\n\n-- Expected error:\n-- .(a) != a of type Bool\n-- when checking that the expression refl has type .(a) ≡ a\n\n-- The rest is proving False.\n\ndata ⊥ : Set where\n\n¬_ : Set → Set\n¬ A = (A → ⊥)\n\ntrue≠false : ¬ (true ≡ false)\ntrue≠false ()\n\ninfixr 30 _∙_\n_∙_ : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z\nrefl ∙ q = q\n\ninfix 42 !_\n!_ : {A : Set} {x y : A} → x ≡ y → y ≡ x\n! refl = refl\n\nmap-irr : {A B : Set} → (A → B) → Irr A → Irr B\nmap-irr f (irr x) = irr (f x)\n\nfactivity : ¬ (Irr ⊥)\nfactivity (irr ())\n\nbad : Irr (true ≡ false)\nbad = map-irr (λ { (i , u , s) → ! (s true) ∙ s false }) bizarre\n\nboom : ⊥\nboom = factivity (map-irr true≠false bad)\n\n\n-- the hole here is is .(a) ≡ a\n-- bizarre' : Irr (Σ (Irr Bool → Bool) (λ u → (a : Bool) → u (irr a) ≡ a))\n-- bizarre' = irr (unirr , (λ a → {!!}))\n\n-- also fails, unirr (irr a) = .(a)\n-- bizarre' : Irr (Σ (Bool → Irr Bool) (λ i → Σ (Irr Bool → Bool) (λ u → (a : Bool) → u (i a) ≡ a)))\n-- bizarre' = irr (irr , unirr , (λ a → refl {x = unirr (irr a)})\n", "meta": {"hexsha": "1b388f3455c9b2fa23f8795c858cae1c58c0f8fa", "size": 2042, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue2170-subtyping.agda", "max_stars_repo_name": "cruhland/agda", "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-20T13:58:52.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-20T13:58:52.000Z", "max_issues_repo_path": "test/Fail/Issue2170-subtyping.agda", "max_issues_repo_name": "cruhland/agda", "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-15T15:49:15.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-15T15:49:15.000Z", "max_forks_repo_path": "test/Fail/Issue2170-subtyping.agda", "max_forks_repo_name": "cruhland/agda", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-18T13:34:07.000Z", "avg_line_length": 26.8684210526, "max_line_length": 100, "alphanum_fraction": 0.5886385896, "num_tokens": 770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.5774953651858117, "lm_q1q2_score": 0.3720370131322145}} {"text": "module Cats.Util.Simp where\n\nopen import Data.List using (List ; [] ; _∷_)\nopen import Data.Nat using (ℕ ; zero ; suc)\nopen import Data.Product using (_×_ ; _,_ ; ∃-syntax)\nopen import Data.Unit using (⊤)\nopen import Function using () renaming (_∘_ to _⊚_)\nopen import Level using (_⊔_) renaming (zero to lzero)\nopen import Relation.Binary.PropositionalEquality as ≡ using\n (_≡_ ; inspect ; [_])\n\nopen import Cats.Category.Base\nopen import Cats.Util.Reflection\n\n_>>=_ = bindTC\nreturn = returnTC\n\n_>>_ : ∀ {a} {A : Set a} {b} {B : Set b} → TC A → TC B → TC B\nma >> mb = ma >>= λ _ → mb\n\n\nmodule _ {lo la l≈} (C : Category lo la l≈) where\n\n infixr 9 _∘_\n\n private\n module C = Category C\n module ≈ = C.≈\n open C.≈-Reasoning\n\n\n data Tm : C.Obj → C.Obj → Set (lo ⊔ la) where\n var : ∀ {A B} → A C.⇒ B → Tm A B\n id : ∀ {A} → Tm A A\n _∘_ : ∀ {A B C} → Tm B C → Tm A B → Tm A C\n\n\n ⟦_⟧ : ∀ {A B} → Tm A B → A C.⇒ B\n ⟦ var f ⟧ = f\n ⟦ id ⟧ = C.id\n ⟦ f ∘ g ⟧ = ⟦ f ⟧ C.∘ ⟦ g ⟧\n\n\n Method : Set (lo ⊔ la)\n Method = ∀ {A B} → Tm A B → Tm A B\n\n\n Correct : Method → Set (lo ⊔ la ⊔ l≈)\n Correct f = ∀ {A B} (t : Tm A B) → ⟦ t ⟧ C.≈ ⟦ f t ⟧\n\n\n Correct→Injective : (f : Method) → Correct f → ∀ {A B} (t u : Tm A B)\n → ⟦ f t ⟧ C.≈ ⟦ f u ⟧\n → ⟦ t ⟧ C.≈ ⟦ u ⟧\n Correct→Injective f fcor t u eq\n = ≈.trans (fcor t) (≈.trans eq (≈.sym (fcor u)))\n\n\n ⊚-correct : (f g : Method) → Correct f → Correct g → Correct (f ⊚ g)\n ⊚-correct _ _ fcor gcor t = ≈.trans (gcor _) (fcor _)\n\n\n {-# TERMINATING #-}\n reassoc : Method\n reassoc (var f) = var f\n reassoc id = id\n reassoc (var f ∘ g) = var f ∘ reassoc g\n reassoc (id ∘ g) = id ∘ reassoc g\n reassoc ((f ∘ g) ∘ h) = reassoc (f ∘ g ∘ h)\n\n\n {-# TERMINATING #-}\n reassoc-correct : Correct reassoc\n reassoc-correct (var f) = C.≈.refl\n reassoc-correct id = C.≈.refl\n reassoc-correct (var f ∘ g) = C.∘-resp-r (reassoc-correct g)\n reassoc-correct (id ∘ f) = C.∘-resp-r (reassoc-correct f)\n reassoc-correct ((f ∘ g) ∘ h) = ≈.trans C.assoc (reassoc-correct (f ∘ g ∘ h))\n\n\n simpId : Method\n simpId (var x) = var x\n simpId id = id\n simpId (f ∘ g) with simpId f | simpId g\n ... | var f′ | var g′ = var f′ ∘ var g′\n ... | var f′ | id = var f′\n ... | var f′ | g′ ∘ g″ = var f′ ∘ g′ ∘ g″\n ... | id | g′ = g′\n ... | f′ ∘ f″ | var g′ = f′ ∘ f″ ∘ var g′\n ... | f′ ∘ f″ | id = f′ ∘ f″\n ... | f′ ∘ f″ | g′ ∘ g″ = f′ ∘ f″ ∘ g′ ∘ g″\n\n\n simpId-correct : Correct simpId\n\n simpId-≡ : ∀ {A B} t {u : Tm A B} → simpId t ≡ u → ⟦ t ⟧ C.≈ ⟦ u ⟧\n\n\n simpId-correct (var x) = C.≈.refl\n simpId-correct id = C.≈.refl\n simpId-correct (f ∘ g)\n with simpId f | inspect simpId f | simpId g | inspect simpId g\n ... | var f′ | [ eq-f ] | var g′ | [ eq-g ]\n = C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)\n ... | var f′ | [ eq-f ] | id | [ eq-g ]\n = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.id-r\n ... | var f′ | [ eq-f ] | g′ ∘ g″ | [ eq-g ]\n = C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)\n ... | id | [ eq-f ] | g' | [ eq-g ]\n = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.id-l\n ... | f′ ∘ f″ | [ eq-f ] | var x | [ eq-g ]\n = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.assoc\n ... | f′ ∘ f″ | [ eq-f ] | id | [ eq-g ]\n = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.id-r\n ... | f′ ∘ f″ | [ eq-f ] | g′ ∘ g″ | [ eq-g ]\n = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.assoc\n\n\n simpId-≡ t eq\n = ≈.trans (simpId-correct t) (≈.reflexive (≡.cong ⟦_⟧ eq))\n\n\n simp : Method\n simp = reassoc ⊚ simpId\n\n\n simp-correct : Correct simp\n simp-correct\n = ⊚-correct reassoc simpId reassoc-correct simpId-correct\n\n\n simp-injective : ∀ {A B} (t u : Tm A B)\n → ⟦ simp t ⟧ C.≈ ⟦ simp u ⟧\n → ⟦ t ⟧ C.≈ ⟦ u ⟧\n simp-injective = Correct→Injective simp simp-correct\n\n\n simp-injective′ : ∀ {A B} (t u : Tm A B)\n → simp t ≡ simp u\n → ⟦ t ⟧ C.≈ ⟦ u ⟧\n simp-injective′ t u eq = simp-injective t u (≈.reflexive (≡.cong ⟦_⟧ eq))\n\n\nreify : Term → Term\nreify (def (quote Category.id)\n (argH _ ∷ argH _ ∷ argH _ ∷ argD C ∷ argH _ ∷ []))\n = con (quote id) []\nreify (def (quote Category._∘_)\n (argH _ ∷ argH _ ∷ argH _ ∷ argD C ∷ argH _ ∷ argH _ ∷ argH _ ∷ argD f ∷ argD g ∷ []))\n = con (quote _∘_) (argD (reify f) ∷ argD (reify g) ∷ [])\nreify t = con (quote Tm.var) (argD t ∷ [])\n\n\nmatchGoal : Term → TC (Term × Term)\nmatchGoal (def (quote Category._≈_)\n (argH _ ∷ argH _ ∷ argH _ ∷ argD C ∷ argH A ∷ argH B ∷ argD f ∷ argD g ∷ []))\n = return (reify f , reify g)\nmatchGoal _ = typeError (strErr \"matchGoal: not an equality\" ∷ [])\n\n\nmacro\n simp! : ∀ {lo la l≈} → Category lo la l≈ → Term → TC ⊤\n simp! C hole = do\n goal ← inferType hole\n blockOnAnyMeta goal\n (lhs , rhs) ← matchGoal goal\n C′ ← quoteTC C\n let solution\n = def (quote simp-injective′)\n ( argD C′\n ∷ argD lhs\n ∷ argD rhs\n ∷ argD (con (quote ≡.refl) [])\n ∷ [])\n unify hole solution\n\n\nmodule Test {lo la l≈} {C : Category lo la l≈} (let module C = Category C) {A B C′ D} {f : C′ C.⇒ D} {g : B C.⇒ C′} {h : A C.⇒ B} where\n\n test : ((C.id C.∘ f) C.∘ g) C.∘ h C.≈ C.id C.∘ f C.∘ g C.∘ h\n test = simp! C\n", "meta": {"hexsha": "576cbf200fd286b02ec4cf966ec966baf0bb36eb", "size": 5263, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cats/Util/Simp.agda", "max_stars_repo_name": "alessio-b-zak/cats", "max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "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": "Cats/Util/Simp.agda", "max_issues_repo_name": "alessio-b-zak/cats", "max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "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": "Cats/Util/Simp.agda", "max_forks_repo_name": "alessio-b-zak/cats", "max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86", "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": 28.9175824176, "max_line_length": 135, "alphanum_fraction": 0.5052251568, "num_tokens": 2323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442250928250376, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.3720370052428586}} {"text": "module Languages.FILL.AgdaInterface where\n\nopen import nat\n\nopen import Utils.HaskellTypes\nopen import Utils.Exception\nopen import Languages.FILL.Intermediate\nopen import Languages.FILL.Syntax\n\ntranslate : ITerm → Either Exception Term\ntranslate = translate' 0 0\n where\n -- n : the next fresh bound variable name\n -- m : the next fresh bound pattern variable name\n translate' : Name → Name → ITerm → Either Exception Term\n translate' n m Triv = right Triv\n translate' n m Void = right Void\n translate' n m (Var x) = right (FVar x)\n translate' n m (TTensor t₁ t₂) =\n (translate' n m t₁)\n >>=E (λ e₁ → (translate' n m t₂)\n >>=E (λ e₂ → right (Tensor e₁ e₂)))\n translate' n m (TPar t₁ t₂) =\n (translate' n m t₁)\n >>=E (λ e₁ → (translate' n m t₂)\n >>=E (λ e₂ → right (Par e₁ e₂)))\n translate' n m (Lam x a t) =\n (translate' (suc n) m t)\n >>=E (λ e → right (Lam x a (close-t n x BV x e)))\n translate' n m (Let t₁ a PTriv t₂) =\n (translate' n m t₁)\n >>=E (λ e₁ → (translate' n m t₂)\n >>=E (λ e₂ → right (Let e₁ a PTriv e₂)))\n translate' n m (Let t₁ a (PTensor (PVar x) (PVar y)) t₂) =\n (translate' n (suc m) t₁)\n >>=E (λ e₁ → (translate' n (suc m) t₂)\n >>=E (λ e₂ → right (Let e₁ a (PTensor x y) (close-t m x LPV x (close-t m y RPV y e₂)))))\n translate' n m (Let t₁ a (PPar (PVar x) (PVar y)) t₂) =\n (translate' n (suc m) t₁)\n >>=E (λ e₁ → (translate' n (suc m) t₂)\n >>=E (λ e₂ → right (Let e₁ a (PPar x y) (close-t m x LPV x (close-t m y RPV y e₂)))))\n translate' n m (Let _ _ _ _) = error IllformedLetPattern \n translate' n m (App t₁ t₂) =\n (translate' n m t₁)\n >>=E (λ e₁ → (translate' n m t₂)\n >>=E (λ e₂ → right (App e₁ e₂)))\n\nuntranslate : Term → ITerm\nuntranslate Triv = Triv\nuntranslate Void = Void\nuntranslate (FVar x) = Var x\nuntranslate (BVar _ x _) = Var x\nuntranslate (Let t₁ a PTriv t₂) = Let (untranslate t₁) a PTriv (untranslate t₂)\nuntranslate (Let t₁ a (PTensor xs ys) t₂) = Let (untranslate t₁) a (PTensor (PVar xs) (PVar ys)) (untranslate t₂)\nuntranslate (Let t₁ a (PPar xs ys) t₂) = Let (untranslate t₁) a (PPar (PVar xs) (PVar ys)) (untranslate t₂)\nuntranslate (Lam x a t) = Lam x a (untranslate t)\nuntranslate (App t₁ t₂) = App (untranslate t₁) (untranslate t₂)\nuntranslate (Tensor t₁ t₂) = TTensor (untranslate t₁) (untranslate t₂)\nuntranslate (Par t₁ t₂) = TPar (untranslate t₁) (untranslate t₂)\n\ntransUntransId : ITerm → Either Exception ITerm\ntransUntransId t = (translate t) >>=E (λ e → right (untranslate e))\n\n{-# COMPILED_EXPORT transUntransId transUntransId #-}\n", "meta": {"hexsha": "b8fb8448df4e08547473b0796add4455398f21a7", "size": 2633, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Source/ALL/Languages/FILL/AgdaInterface.agda", "max_stars_repo_name": "heades/Agda-LLS", "max_stars_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-04-09T20:53:53.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-02T23:41:23.000Z", "max_issues_repo_path": "Source/ALL/Languages/FILL/AgdaInterface.agda", "max_issues_repo_name": "heades/Agda-LLS", "max_issues_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-03-27T14:52:46.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-05T17:30:16.000Z", "max_forks_repo_path": "Source/ALL/Languages/FILL/AgdaInterface.agda", "max_forks_repo_name": "heades/Agda-LLS", "max_forks_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1", "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": 40.5076923077, "max_line_length": 113, "alphanum_fraction": 0.6221040638, "num_tokens": 924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154240079185319, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.37167802635010033}} {"text": "\nopen import Oscar.Prelude\nopen import Oscar.Class.IsPrecategory\nopen import Oscar.Class.IsCategory\nopen import Oscar.Class.Category\nopen import Oscar.Class.IsFunctor\nopen import Oscar.Class.Functor\n\nopen import Oscar.Class.Reflexivity\nopen import Oscar.Class.Transitivity\nopen import Oscar.Class.Surjection\nopen import Oscar.Class.Smap\nopen import Oscar.Class.Transextensionality\nopen import Oscar.Class.Transassociativity\nopen import Oscar.Class.Transleftidentity\nopen import Oscar.Class.Transrightidentity\nopen import Oscar.Class.Surjidentity\nopen import Oscar.Class\n\nmodule Oscar.Class.Kitten where\n\nproductCat : ∀ {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} → Category 𝔬₁ 𝔯₁ ℓ₁ → Category 𝔬₂ 𝔯₂ ℓ₂ → Category (𝔬₁ ∙̂ 𝔬₂) (𝔯₁ ∙̂ 𝔯₂) (ℓ₁ ∙̂ ℓ₂)\nCategory.𝔒 (productCat c₁ c₂) = Category.𝔒 c₁ × Category.𝔒 c₂\nCategory._∼_ (productCat c₁ c₂) (x₁ , x₂) (y₁ , y₂) = Category._∼_ c₁ x₁ y₁ × Category._∼_ c₂ x₂ y₂\nCategory._∼̇_ (productCat c₁ c₂) {x₁ , x₂} {y₁ , y₂} (f₁ , g₁) (f₂ , g₂) = Category._∼̇_ c₁ f₁ f₂ × Category._∼̇_ c₂ g₁ g₂\nCategory.category-ε (productCat c₁ c₂) = (Category.category-ε c₁) , (Category.category-ε c₂)\nCategory._↦_ (productCat c₁ c₂) (f₁ , f₂) (g₁ , g₂) = (Category._↦_ c₁ f₁ g₁) , (Category._↦_ c₂ f₂ g₂)\nCategory.`IsCategory (productCat c₁ c₂) .IsCategory.`IsPrecategory .IsPrecategory.`𝓣ransextensionality .⋆ (x₁ , y₁) (x₂ , y₂) = transextensionality x₁ x₂ , transextensionality y₁ y₂\nCategory.`IsCategory (productCat c₁ c₂) .IsCategory.`IsPrecategory .IsPrecategory.`𝓣ransassociativity .⋆ f g h = transassociativity (f .π₀) (g .π₀) (h .π₀) , transassociativity (f .π₁) (g .π₁) (h .π₁)\nCategory.`IsCategory (productCat c₁ c₂) .IsCategory.`𝓣ransleftidentity .⋆ = transleftidentity , transleftidentity\nCategory.`IsCategory (productCat c₁ c₂) .IsCategory.`𝓣ransrightidentity = ∁ (transrightidentity , transrightidentity)\n\nrecord AFunctor {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂} (source : Category 𝔬₁ 𝔯₁ ℓ₁) (target : Category 𝔬₂ 𝔯₂ ℓ₂) : Ø 𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂ where\n constructor ∁\n private module S = Category source\n private module T = Category target\n field\n F₀ : S.𝔒 → T.𝔒\n F₁ : Smap.type S._∼_ T._∼_ F₀ F₀\n isFunctor : IsFunctor S._∼_ S._∼̇_ S.category-ε S._↦_ T._∼_ T._∼̇_ T.category-ε T._↦_ F₁\n\nrecord MonoidalCategory 𝔬 𝔯 ℓ : Ø ↑̂ (𝔬 ∙̂ 𝔯 ∙̂ ℓ) where\n constructor ∁\n field\n thecat : Category 𝔬 𝔯 ℓ\n thefunc : AFunctor (productCat thecat thecat) thecat\n O : Ø 𝔬\n O = Category.𝔒 thecat\n field\n 𝟏 : O\n _⟶_ : O → O → Ø 𝔯\n _⟶_ = Category._∼_ thecat\n _⊗_ : O → O → O\n _⊗_ = λ x y → AFunctor.F₀ thefunc (x , y)\n _⨂_ : ∀ {w x y z} → w ⟶ x → y ⟶ z → (w ⊗ y) ⟶ (x ⊗ z)\n _⨂_ f g = AFunctor.F₁ thefunc (f , g)\n _↦_ : ∀ {x y z} (f : x ⟶ y) (g : y ⟶ z) → x ⟶ z\n _↦_ = Category._↦_ thecat\n i : ∀ {x} → x ⟶ x\n i = Category.category-ε thecat\n _≈̇_ = Category._∼̇_ thecat\n -- infixr 9 _⊗_\n field\n associator : ∀ (x y z : O)\n → Σ (((x ⊗ y) ⊗ z) ⟶ (x ⊗ (y ⊗ z))) λ f\n → Σ ((x ⊗ (y ⊗ z)) ⟶ ((x ⊗ y) ⊗ z)) λ f⁻¹\n → ((f ↦ f⁻¹) ≈̇ i) × ((f⁻¹ ↦ f) ≈̇ i)\n left-unitor : ∀ (x : O)\n → Σ ((𝟏 ⊗ x) ⟶ x) λ f\n → Σ (x ⟶ (𝟏 ⊗ x)) λ f⁻¹\n → ((f ↦ f⁻¹) ≈̇ i) × ((f⁻¹ ↦ f) ≈̇ i)\n right-unitor : ∀ (x : O)\n → Σ ((x ⊗ 𝟏) ⟶ x) λ f\n → Σ (x ⟶ (x ⊗ 𝟏)) λ f⁻¹\n → ((f ↦ f⁻¹) ≈̇ i) × ((f⁻¹ ↦ f) ≈̇ i)\n assoc : ∀ (x y z : O) → ((x ⊗ y) ⊗ z) ⟶ (x ⊗ (y ⊗ z))\n assoc x y z = π₀ (associator x y z)\n ru : ∀ x → (x ⊗ 𝟏) ⟶ x\n ru x = π₀ (right-unitor x)\n lu : ∀ x → (𝟏 ⊗ x) ⟶ x\n lu x = π₀ (left-unitor x)\n field\n triangle-identity : ∀ (x y : O)\n → (ru x ⨂ i) ≈̇ (assoc x 𝟏 y ↦ (i ⨂ lu y))\n pentagon-identity : ∀ (w x y z : O)\n → (((assoc w x y ⨂ i) ↦ assoc w (x ⊗ y) z) ↦ (i ⨂ assoc x y z))\n ≈̇ (assoc (w ⊗ x) y z ↦ assoc w x (y ⊗ z))\n\nmodule _\n {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂}\n (source : MonoidalCategory 𝔬₁ 𝔯₁ ℓ₁)\n (target : MonoidalCategory 𝔬₂ 𝔯₂ ℓ₂)\n where\n record LaxMonoidalFunctor : Ø 𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂ where\n module C = MonoidalCategory source\n module D = MonoidalCategory target\n field\n 𝓕 : AFunctor C.thecat D.thecat\n open AFunctor 𝓕 public\n field\n e : D.𝟏 D.⟶ F₀ C.𝟏\n μ : ∀ x y → (F₀ x D.⊗ F₀ y) D.⟶ F₀ (x C.⊗ y) -- F A → F B → F (A × B)\n associativity : ∀ x y z\n → ((μ x y D.⨂ D.i) D.↦ (μ (x C.⊗ y) z D.↦ F₁ (C.assoc x y z)))\n D.≈̇\n (D.assoc (F₀ x) (F₀ y) (F₀ z) D.↦ ((D.i D.⨂ μ y z) D.↦ μ x (y C.⊗ z)))\n left-unitality : ∀ x → (D.lu (F₀ x)) D.≈̇ ((e D.⨂ D.i) D.↦ (μ C.𝟏 x D.↦ F₁ (C.lu x)))\n right-unitality : ∀ x → (D.ru (F₀ x)) D.≈̇ ((D.i D.⨂ e) D.↦ (μ x C.𝟏 D.↦ F₁ (C.ru x)))\n\nmodule _\n {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂}\n (source : MonoidalCategory 𝔬₁ 𝔯₁ ℓ₁)\n (target : MonoidalCategory 𝔬₂ 𝔯₂ ℓ₂)\n (let module C = MonoidalCategory source)\n (let module D = MonoidalCategory target)\n (𝓕 : AFunctor C.thecat D.thecat)\n (open AFunctor 𝓕)\n (e : D.𝟏 D.⟶ F₀ C.𝟏)\n (μ : ∀ x y → (F₀ x D.⊗ F₀ y) D.⟶ F₀ (x C.⊗ y))\n where\n record IsLaxMonoidalFunctor : Ø 𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂ where\n field\n associativity : ∀ x y z\n → ((μ x y D.⨂ D.i) D.↦ (μ (x C.⊗ y) z D.↦ F₁ (C.assoc x y z)))\n D.≈̇\n (D.assoc (F₀ x) (F₀ y) (F₀ z) D.↦ ((D.i D.⨂ μ y z) D.↦ μ x (y C.⊗ z)))\n left-unitality : ∀ x → (D.lu (F₀ x)) D.≈̇ ((e D.⨂ D.i) D.↦ (μ C.𝟏 x D.↦ F₁ (C.lu x)))\n right-unitality : ∀ x → (D.ru (F₀ x)) D.≈̇ ((D.i D.⨂ e) D.↦ (μ x C.𝟏 D.↦ F₁ (C.ru x)))\n\nrecord GenericApplicativeRaw\n {lc ld} {Oc : Ø lc} {Od : Ø ld}\n (F : Oc → Od)\n (1c : Oc) (1d : Od)\n (_⊗c_ : Oc → Oc → Oc) (_⊗d_ : Od → Od → Od)\n {ℓc} (_⟶c_ : Oc → Oc → Ø ℓc)\n {ℓd} (_⟶d_ : Od → Od → Ø ℓd)\n : Ø ℓd ∙̂ lc ∙̂ ℓc\n where\n field\n m : ∀ {x y} → x ⟶c y → F x ⟶d F y -- fmap\n e : 1d ⟶d F 1c -- pure\n μ : ∀ {x y} → (F x ⊗d F y) ⟶d F (x ⊗c y) -- apply\n\n -- _<*>_ : ∀ {x y : Oc} → ? → ? → {!!} -- F (x ⟶c y) → F x ⟶d F y\n -- _<*>_ f x = m ? (μ )\n\n{-\n _<*>_ : ∀ {A B} → F (A → B) → F A → F B\n _<*>_ f x = sfmap (λ {(f , x) → f x}) (f x)\n-}\n\n{-\nrecord ContainedGenericApplicativeRaw\n {lc ld} {Oc : Ø lc} {Od : Ø ld}\n (F : Oc → Od)\n (1c : Oc) (1d : Od)\n (_⊗c_ : Oc → Oc → Oc) (_⊗d_ : Od → Od → Od)\n {ℓd} (_⟶d_ : Od → Od → Ø ℓd)\n : Ø ℓd ∙̂ lc\n where\n field\n e : 1d ⟶d F 1c\n μ : ∀ {x y} → (F x ⊗d F y) ⟶d F (x ⊗c y)\n-}\nopen import Oscar.Data.𝟙\nopen import Oscar.Data.Proposequality\n\nrecord Action {a b} {A : Set a} {B : Set b} {f g h} (F : A → B → Set f) (G : A → Set g) (H : B → Set h) : Ø a ∙̂ b ∙̂ f ∙̂ g ∙̂ h where\n field\n act : ∀ {x y} → F x y → G x → H y\n\nrecord SetApplyM {a b} (F : Set a → Set b)\n -- (𝟏ᴬ : Set a) (𝟏ᴮ : Set b) (_⊕_ : Set p → Set p → Set p) (_⟶_ : A → A → Set ℓ)\n : Ø ↑̂ a ∙̂ b where\n field\n sfmap : ∀ {A B} → (A → B) → F A → F B\n sunit : Lift {_} {a} 𝟙 → F (Lift 𝟙)\n __ : ∀ {A B} → F A → F B → F (A × B)\n _<*>_ : ∀ {A B} → F (A → B) → F A → F B\n _<*>_ f x = sfmap (λ {(f , x) → f x}) (f x)\n _⨂_ : ∀ {A B C D : Ø a} → (A → B) → (C → D) → A × C → B × D\n _⨂_ f g ac = let (a , c) = ac in f a , g c\n assoc : ∀ {A B C : Ø a} → A × (B × C) → (A × B) × C\n assoc abc = let (a , (b , c)) = abc in (a , b) , c\n field\n law-nat : ∀ {A B C D} (f : A → B) (g : C → D) u v → sfmap (f ⨂ g) (u v) ≡ (sfmap f u sfmap g v)\n leftid : ∀ {B} (v : F B) → sfmap π₁ (sunit _ v) ≡ v\n righttid : ∀ {A} (u : F A) → sfmap π₀ (u sunit _) ≡ u\n associativity : ∀ {A B C} u v w → sfmap (assoc {A} {B} {C}) (u (v w)) ≡ ((u v) w)\n\n source-cat : MonoidalCategory _ _ _\n source-cat .MonoidalCategory.thecat .Category.𝔒 = Ø a\n source-cat .MonoidalCategory.thecat .Category._∼_ = Function\n source-cat .MonoidalCategory.thecat .Category._∼̇_ = _≡̇_\n source-cat .MonoidalCategory.thecat .Category.category-ε = ¡\n source-cat .MonoidalCategory.thecat .Category._↦_ = flip _∘′_\n source-cat .MonoidalCategory.thecat .Category.`IsCategory = {!!}\n source-cat .MonoidalCategory.thefunc .AFunctor.F₀ (A , B) = A × B\n source-cat .MonoidalCategory.thefunc .AFunctor.F₁ = {!!}\n source-cat .MonoidalCategory.thefunc .AFunctor.isFunctor = {!!}\n source-cat .MonoidalCategory.𝟏 = Lift 𝟙\n source-cat .MonoidalCategory.associator = {!!}\n source-cat .MonoidalCategory.left-unitor = {!!}\n source-cat .MonoidalCategory.right-unitor = {!!}\n source-cat .MonoidalCategory.triangle-identity = {!!}\n source-cat .MonoidalCategory.pentagon-identity = {!!}\n\n target-cat : MonoidalCategory _ _ _\n target-cat .MonoidalCategory.thecat .Category.𝔒 = Ø b\n target-cat .MonoidalCategory.thecat .Category._∼_ = Function\n target-cat .MonoidalCategory.thecat .Category._∼̇_ = _≡̇_\n target-cat .MonoidalCategory.thecat .Category.category-ε = ¡\n target-cat .MonoidalCategory.thecat .Category._↦_ = flip _∘′_\n target-cat .MonoidalCategory.thecat .Category.`IsCategory = {!!}\n target-cat .MonoidalCategory.thefunc .AFunctor.F₀ (A , B) = A × B\n target-cat .MonoidalCategory.thefunc .AFunctor.F₁ = {!!}\n target-cat .MonoidalCategory.thefunc .AFunctor.isFunctor = {!!}\n target-cat .MonoidalCategory.𝟏 = Lift 𝟙\n target-cat .MonoidalCategory.associator = {!!}\n target-cat .MonoidalCategory.left-unitor = {!!}\n target-cat .MonoidalCategory.right-unitor = {!!}\n target-cat .MonoidalCategory.triangle-identity = {!!}\n target-cat .MonoidalCategory.pentagon-identity = {!!}\n\n module C = MonoidalCategory source-cat\n module D = MonoidalCategory target-cat\n\n the-functor : AFunctor C.thecat D.thecat\n the-functor .AFunctor.F₀ = F\n the-functor .AFunctor.F₁ = sfmap\n the-functor .AFunctor.isFunctor = {!!}\n\n open AFunctor the-functor\n\n the-e : D.𝟏 D.⟶ F₀ C.𝟏 -- F (Lift 𝟙)\n the-e = {!!}\n\n the-μ : ∀ x y → (F₀ x D.⊗ F₀ y) D.⟶ F₀ (x C.⊗ y) -- F A → F B → F (A × B)\n the-μ A B (FA , FB) = FA FB\n\ntoSetApply : ∀ {a b} (F : Set a → Set b) (gar : GenericApplicativeRaw F (Lift 𝟙) (Lift 𝟙) (λ A B → A × B) (λ A B → A × B) Function Function) → SetApplyM F\ntoSetApply F gar .SetApplyM.sfmap = GenericApplicativeRaw.m gar\ntoSetApply F gar .SetApplyM.sunit _ = GenericApplicativeRaw.e gar !\ntoSetApply F gar .SetApplyM.__ FA FB = GenericApplicativeRaw.μ gar (FA , FB)\ntoSetApply F gar .SetApplyM.law-nat = {!!}\ntoSetApply F gar .SetApplyM.leftid = {!!}\ntoSetApply F gar .SetApplyM.righttid = {!!}\ntoSetApply F gar .SetApplyM.associativity = {!!}\n\nmodule _\n {𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂}\n (C : MonoidalCategory 𝔬₁ 𝔯₁ ℓ₁)\n (D : MonoidalCategory 𝔬₂ 𝔯₂ ℓ₂)\n where\n record LaxMonoidalFunctorWithStrength : Ø 𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂ where\n field\n laxMonoidalFunctor : LaxMonoidalFunctor C D\n open LaxMonoidalFunctor laxMonoidalFunctor\n {-\n field\n β : ∀ v w → (v D.⊗ F₀ w) D.⟶ F₀ (v C.⊗ w)\n commute-5 : ∀ u v w → (C.assoc u v (F₀ w) C.↦ ((C.i C.⨂ β v w) C.↦ β u (v C.⊗ w))) C.≈̇ (β (u C.⊗ v) w C.↦ F₁ (C.assoc u v w))\n commute-3 : ∀ v → C.lu (F₀ v) C.≈̇ (β C.𝟏 v C.↦ F₁ (C.lu v))\n -- strength : TensorialStrength C (LaxMonoidalFunctor.𝓕 laxMonoidalEndofunctor)\n -}\n\nmodule _ {𝔬 𝔯 ℓ} (V : MonoidalCategory 𝔬 𝔯 ℓ) (let C = MonoidalCategory.thecat V) (F : AFunctor C C) where\n open MonoidalCategory V\n open AFunctor F\n record TensorialStrength : Ø 𝔬 ∙̂ 𝔯 ∙̂ ℓ where\n field\n β : ∀ v w → (v ⊗ F₀ w) ⟶ F₀ (v ⊗ w)\n commute-5 : ∀ u v w → (assoc u v (F₀ w) ↦ ((i ⨂ β v w) ↦ β u (v ⊗ w))) ≈̇ (β (u ⊗ v) w ↦ F₁ (assoc u v w))\n commute-3 : ∀ v → lu (F₀ v) ≈̇ (β 𝟏 v ↦ F₁ (lu v))\n\nmodule _\n {𝔬 𝔯 ℓ}\n (C : MonoidalCategory 𝔬 𝔯 ℓ)\n where\n record LaxMonoidalEndofunctorWithStrength : Ø 𝔬 ∙̂ 𝔯 ∙̂ ℓ where\n field\n laxMonoidalEndofunctor : LaxMonoidalFunctor C C\n strength : TensorialStrength C (LaxMonoidalFunctor.𝓕 laxMonoidalEndofunctor)\n\n{- want parameters :\n X : Set a\n Y : Set b\n X₀ : X\n F : X → Y\n _⨁_ : X → X → Set a\n\n LaxMonoidalFunctor.e = unit : F X₀\n LaxMonoidalFunctor.μ = apply : ∀ {A B : X} → F A → F B → F (A ⨁ B)\n LaxMonoidalFunctor.𝓕.F₀ = F : X → Y\n\n-}\n\nrecord GenericApplyM {a ℓ} {A : Set a} (F : A → A) (𝟏 : A) (_⊕_ : A → A → A) (_⟶_ : A → A → Set ℓ) : Ø a ∙̂ ℓ where\n field\n gunit : 𝟏 ⟶ F 𝟏\n gproduct : ∀ {x y : A} → (F x ⊕ F y) ⟶ F (x ⊕ y)\n\nopen import Oscar.Data.𝟙\n-- open import Oscar.Class.Kitten\nopen import Oscar.Class.Category\nopen import Oscar.Class.IsPrefunctor\nopen import Oscar.Class.IsCategory\nopen import Oscar.Class.IsPrecategory\nopen import Oscar.Property.Category.Function\nopen import Oscar.Class\nopen import Oscar.Class.Fmap\nimport Oscar.Class.Reflexivity.Function\n\nmodule _\n {𝔬₁ 𝔬₂} (𝓕 : Ø 𝔬₁ → Ø 𝔬₂)\n (fmapper : Fmap 𝓕)\n (fpure : ∀ {𝔄} → 𝔄 → 𝓕 𝔄)\n (fapply : ∀ {𝔄 𝔅} → 𝓕 (𝔄 → 𝔅) → 𝓕 𝔄 → 𝓕 𝔅)\n where\n -- instance _ = fmapper\n fmap' = λ {A B} (f : A → B) → fapply (fpure f)\n mkProductMonoidalCategory : MonoidalCategory _ _ _\n mkProductMonoidalCategory .MonoidalCategory.thecat .Category.𝔒 = Ø 𝔬₁\n mkProductMonoidalCategory .MonoidalCategory.thecat .Category._∼_ = MFunction 𝓕\n mkProductMonoidalCategory .MonoidalCategory.thecat .Category._∼̇_ = Proposextensequality\n mkProductMonoidalCategory .MonoidalCategory.thecat .Category.category-ε = ε\n mkProductMonoidalCategory .MonoidalCategory.thecat .Category._↦_ = (flip _∘′_)\n mkProductMonoidalCategory .MonoidalCategory.thecat .Category.`IsCategory = ?\n mkProductMonoidalCategory .MonoidalCategory.thefunc .AFunctor.F₀ (A , B) = A × B\n mkProductMonoidalCategory .MonoidalCategory.thefunc .AFunctor.F₁ (f , g) xy = fapply (fmap' _,_ (f (fmap' π₀ xy))) (g (fmap' π₁ xy))\n mkProductMonoidalCategory .MonoidalCategory.thefunc .AFunctor.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`𝓢urjtranscommutativity = {!!}\n mkProductMonoidalCategory .MonoidalCategory.thefunc .AFunctor.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`𝓢urjextensionality = {!!}\n mkProductMonoidalCategory .MonoidalCategory.thefunc .AFunctor.isFunctor .IsFunctor.`𝒮urjidentity = {!!}\n mkProductMonoidalCategory .MonoidalCategory.𝟏 = {!!}\n mkProductMonoidalCategory .MonoidalCategory.associator = {!!}\n mkProductMonoidalCategory .MonoidalCategory.left-unitor = {!!}\n mkProductMonoidalCategory .MonoidalCategory.right-unitor = {!!}\n mkProductMonoidalCategory .MonoidalCategory.triangle-identity = {!!}\n mkProductMonoidalCategory .MonoidalCategory.pentagon-identity = {!!}\n\nrecord HApplicativeFunctor {𝔬₁ 𝔬₂} (𝓕 : Ø 𝔬₁ → Ø 𝔬₂) : Ø (↑̂ (↑̂ 𝔬₁ ∙̂ 𝔬₂)) where\n constructor ∁\n field\n fmapper : Fmap 𝓕\n fpure : ∀ {𝔄} → 𝔄 → 𝓕 𝔄\n fapply : ∀ {𝔄 𝔅} → 𝓕 (𝔄 → 𝔅) → 𝓕 𝔄 → 𝓕 𝔅\n\n\n field\n isStrongLaxMonoidalEndofunctor : LaxMonoidalEndofunctorWithStrength (mkProductMonoidalCategory 𝓕 fmapper fpure fapply)\n\n module LMF = LaxMonoidalFunctor (LaxMonoidalEndofunctorWithStrength.laxMonoidalEndofunctor isStrongLaxMonoidalEndofunctor)\n derive-fpure : ∀ {𝔄} → 𝔄 → 𝓕 𝔄\n derive-fpure = {!LMF!} where\n\n {-\n ⦃ isFunctor ⦄ : IsFunctor\n {𝔒₁ = Ø 𝔬₁} (λ A B → A × 𝓕 B)\n {!(λ { {A} {B} (x₁ , f₁) (x₂ , f₂) → {!(x₁ ≡ x₂) × !}})!} (λ {A} → {!!} , {!!}) {!!}\n {𝔒₂ = Ø 𝔬₁} {!!}\n {!!} {!!} {!!}\n {!!}\n -}\n\nrecord MonoidalFunctor {𝔬₁ 𝔬₂} (𝓕 : Ø 𝔬₁ → Ø 𝔬₂) : Ø (↑̂ (↑̂ 𝔬₁ ∙̂ 𝔬₂)) where\n constructor ∁\n field\n ⦃ isFmap ⦄ : Fmap 𝓕\n unit : 𝓕 (Lift 𝟙)\n mappend : ∀ {𝔄 𝔅} → 𝓕 𝔄 → 𝓕 𝔅 → 𝓕 (𝔄 × 𝔅)\n {-\n ⦃ isFunctor ⦄ : IsFunctor\n Function⟦ 𝔬₁ ⟧\n Proposextensequality ε (flip _∘′_)\n (MFunction 𝓕)\n Proposextensequality ε (flip _∘′_)\n {!!}\n -}\n pure : ∀ {𝔄} → 𝔄 → 𝓕 𝔄\n pure x = fmap (x ∞) unit\n\n infixl 4 _<*>_\n _<*>_ : ∀ {𝔄 𝔅} → 𝓕 (𝔄 → 𝔅) → 𝓕 𝔄 → 𝓕 𝔅\n f <*> x = fmap (λ {(f , x) → f x}) (mappend f x)\n\n app-identity : ∀ {𝔄} (v : 𝓕 𝔄) → (pure ¡[ 𝔄 ] <*> v) ≡ v\n app-identity v = {!!}\n\nopen MonoidalFunctor ⦃ … ⦄ public using (unit; mappend)\n\n\n-- record ApplicativeFunctor where\nmodule Purity\n {𝔵₁ 𝔵₂ 𝔯} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (F : 𝔛₁ → 𝔛₂) (x₁ : 𝔛₁) (x₂ : 𝔛₂) (_⟶_ : 𝔛₂ → 𝔛₂ → Ø 𝔯)\n = ℭLASS (F , x₁ , x₂ , _⟶_) (x₂ ⟶ F x₁)\n\nmodule Applicativity\n {𝔵₁ 𝔵₂ 𝔯} {𝔛₁ : Ø 𝔵₁} {𝔛₂ : Ø 𝔵₂} (F : 𝔛₁ → 𝔛₂) (_⊗₁_ : 𝔛₁ → 𝔛₁ → 𝔛₁) (_⊗₂_ : 𝔛₂ → 𝔛₂ → 𝔛₂) (_⟶_ : 𝔛₂ → 𝔛₂ → Ø 𝔯)\n = ℭLASS (F , _⊗₁_ , _⊗₂_ , _⟶_) (∀ x y → (F x ⊗₂ F y) ⟶ F (x ⊗₁ y))\n\n-- FunctionalMonoidalCategory\n\nAFunctorFunction²Function : ∀ {𝔬₁} → AFunctor (productCat (CategoryFunction {𝔬₁}) (CategoryFunction {𝔬₁})) (CategoryFunction {𝔬₁})\nAFunctorFunction²Function .AFunctor.F₀ = uncurry _×_\nAFunctorFunction²Function .AFunctor.F₁ (f₁ , f₂) (x₁ , x₂) = f₁ x₁ , f₂ x₂\nAFunctorFunction²Function .AFunctor.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`𝓢urjtranscommutativity = {!!}\nAFunctorFunction²Function .AFunctor.isFunctor .IsFunctor.`IsPrefunctor .IsPrefunctor.`𝓢urjextensionality = {!!}\nAFunctorFunction²Function .AFunctor.isFunctor .IsFunctor.`𝒮urjidentity = {!!}\n\nrecord LMF {𝔬₁ 𝔬₂} (𝓕 : Ø 𝔬₁ → Ø 𝔬₂) ⦃ _ : Fmap 𝓕 ⦄ : Ø ↑̂ (↑̂ 𝔬₁ ∙̂ 𝔬₂) where\n constructor ∁\n field\n lmf-pure : Purity.type 𝓕 (Lift 𝟙) (Lift 𝟙) Function\n lmf-apply : Applicativity.type 𝓕 _×_ _×_ Function\n\n lmf-happly : ∀ {𝔄 𝔅} → 𝓕 (𝔄 → 𝔅) → 𝓕 𝔄 → 𝓕 𝔅\n lmf-happly f x = fmap (λ {(f , x) → f x}) (lmf-apply _ _ (f , x))\n\n field\n ⦃ islmf ⦄ : IsLaxMonoidalFunctor (∁ CategoryFunction (∁ (uncurry _×_) {!!} {!!}) (Lift 𝟙) {!!} {!!} {!!} {!!} {!!}) (∁ CategoryFunction (∁ (uncurry _×_) {!!} {!!}) ((Lift 𝟙)) {!!} {!!} {!!} {!!} {!!}) (record { F₀ = 𝓕 ; F₁ = fmap ; isFunctor = ∁ ⦃ {!!} ⦄ ⦃ ! ⦄ ⦃ ! ⦄ ⦃ {!!} ⦄ }) lmf-pure lmf-apply\n", "meta": {"hexsha": "a8857bebe8f598ad2742efb02f58f62891121bff", "size": 17402, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Kitten.agda", "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Kitten.agda", "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Kitten.agda", "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.3349168646, "max_line_length": 302, "alphanum_fraction": 0.5812550282, "num_tokens": 7918, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.3716175497195352}} {"text": "{-# OPTIONS --copatterns --sized-types --without-K #-}\nmodule PolyFinalCoalg where\n\nopen import Data.Product\nopen import Data.Nat\nopen import Data.Fin\nopen import Data.Unit as Unit\nopen import Data.Empty\nopen import Data.Vec hiding (_∈_; [_])\nopen import Relation.Binary.PropositionalEquality\nopen import Function\nopen import Data.Sum as Sum\nopen import Size\n\nopen import Poly\n\n-- | Indexed product\n_×ᵢ_ : {I : Set} → Fam I → Fam I → Fam I\n(A ×ᵢ B) i = A i × B i\n\n-- | Product of indexed functors\n_×ᵢ'_ : {I J K : Set} →\n (Fam K → Fam I) → (Fam J → Fam I) → (Fam K × Fam J → Fam I)\n(F ×ᵢ' G) (X , Y) = F X ×ᵢ G Y\n\nrecord Isomorphic (A B : Set) : Set where\n-- constructor isIso\n field\n f : A → B\n f⃖ : B → A\n is-invˡ : (a : A) → f⃖ (f a) ≡ a\n is-invʳ : (b : B) → f (f⃖ b) ≡ b\n\n_≃_ = Isomorphic\n\n_≃'_ : {I : Set} → Fam I → Fam I → Set\n_≃'_ {I} A B = (i : I) → A i ≃ B i\n\n-- | Avoid setoids for now\npostulate\n Π'-ext : {I J : Set} {u : I → J} {P : Fam I} →\n (j : J) (f g : Π' u P j) →\n ((i : I) → (p : u i ≡ j) → f (i , p) ≡ g (i , p)) → f ≡ g\n Π'-ext' : {I J : Set} {u : I → J} {P : Fam I} →\n (f g : (i : I) → Π' u P (u i)) →\n ((i : I) → app i (f i) ≡ app i (g i)) → (i : I) → f i ≡ g i\n\n-- | Dependent polynomials\nrecord ParamPoly {I J : Set} : Set₁ where\n constructor ppoly\n field\n -- J ←t- B -p→ A -s→ I\n A : Set -- ^ Labels\n s : A → I\n B : Set\n p₁ p₂ : B → A\n t₁ : B → J\n t₂ : B → I\n\nfirst : {I J : Set} → ParamPoly {I} {J} → DPoly {I} {J}\nfirst (ppoly A s B p₁ p₂ t₁ t₂) = dpoly A s B p₁ t₁\n\nsecond : {I J : Set} → ParamPoly {I} {J} → DPoly {I} {I}\nsecond (ppoly A s B p₁ p₂ t₁ t₂) = dpoly A s B p₂ t₂\n\n\nR : {I J : Set} → ParamPoly {I} {J} →\n (X : Fam J) → (Y : Fam I) → Fam I\nR (ppoly A s B p₁ p₂ t₁ t₂) X Y =\n Σ' s (Π' p₁ ((t₁ *) X) ×ᵢ Π' p₂ ((t₂ *) Y))\n\ndata ⊤' (I : Set) : I → Set where\n tt : (i : I) → ⊤' I i\n\n⊤'-unique : {I : Set} {i : I} → (x y : ⊤' I i) → x ≡ y\n⊤'-unique (tt i) (tt .i) = refl\n\ntriv-param : {I J : Set} → (P : ParamPoly {I} {J}) →\n (Y : Fam I) → R P (⊤' J) Y ≃' T (second P) Y\ntriv-param {I} {J} (ppoly A s B p₁ p₂ t₁ t₂) Y i =\n record\n { f = f i\n ; f⃖ = g i\n ; is-invˡ = is-invˡ i\n ; is-invʳ = is-invʳ i\n }\n where\n P = ppoly A s B p₁ p₂ t₁ t₂\n\n f : (i : I) → R P (⊤' J) Y i → T (second P) Y i\n f ._ (ins a (v₁ , v₂)) = ins a v₂\n\n triv : (a : A) → Π' p₁ ((t₁ *) (⊤' J)) a\n triv a = abs (λ b → tt (t₁ b)) a\n\n g : (i : I) → T (second P) Y i → R P (⊤' J) Y i\n g ._ (ins a v) = ins a (triv a , v)\n\n is-invˡ : (i : I) → (x : R P (⊤' J) Y i) → g i (f i x) ≡ x\n is-invˡ ._ (ins a (v₁ , v₂)) =\n Σ'-eq a a (triv a , v₂) (v₁ , v₂)\n refl\n (×-eq (triv a) v₁ v₂ v₂\n (Π'-ext a (triv a) v₁ (lem a v₁))\n refl)\n where\n lem : (a : A) (v₁ : Π' p₁ ((t₁ *) (⊤' J)) a)\n (i₁ : B) (p : p₁ i₁ ≡ a) →\n triv a (i₁ , p) ≡ v₁ (i₁ , p)\n lem ._ v₁ i₁ refl = ⊤'-unique (tt (t₁ i₁)) (app i₁ v₁)\n\n is-invʳ : (i : I) → (x : T (second P) Y i) → f i (g i x) ≡ x\n is-invʳ ._ (ins a x) = refl\n\ntriv : {I J : Set} (P : DPoly {I} {J}) → T P (⊤' J) ≃' toFam (DPoly.s P)\ntriv {I} {J} (dpoly A s E p t) i =\n record\n { f = f i\n ; f⃖ = g i\n ; is-invˡ = p₁ i\n ; is-invʳ = p₂ i\n }\n where\n P = dpoly A s E p t\n\n f : (i : I) → T P (⊤' J) i → toFam s i\n f ._ (ins a v) = (a , refl)\n\n g : (i : I) → toFam s i → T P (⊤' J) i\n g ._ (a , refl) = ins a (abs'' a v)\n where\n v : (b : E) → p b ≡ a → ⊤' J (t b)\n v b _ = tt (t b)\n\n p₁ : (i : I) → (x : T (dpoly A s E p t) (⊤' J) i) → g i (f i x) ≡ x\n p₁ ._ (ins a v) =\n Σ'-eq a a (abs'' a (λ b _ → tt (t b))) v\n refl\n (Π'-ext a (abs'' a (λ b _ → tt (t b))) v\n (λ b p₂ → ⊤'-unique (tt (t b)) (v (b , p₂))))\n\n p₂ : (i : I) (b : toFam s i) → f i (g i b) ≡ b\n p₂ ._ (a , refl) = refl\n\nfoo : {A C P : Set} (B : Fam A) (D : Fam C) (Q : Fam P) (X : Set) →\n Σ (A × C) (λ {(a , c) → (B a → X) × (D c → Σ P (λ p → Q p → X)) })\n ≃\n Σ (A × Σ C (λ c → D c → P))\n (λ {(a , c , t) → ((B a → X) × ((Σ (D c) ((t *) Q)) → X))})\nfoo {A} {C} {P} B D Q X =\n record\n { f = f\n ; f⃖ = g\n ; is-invˡ = {!!}\n ; is-invʳ = {!!}\n }\n where\n f : Σ (A × C) (λ {(a , c) → (B a → X) × (D c → Σ P (λ p → Q p → X)) }) →\n Σ (A × Σ C (λ c → D c → P))\n (λ {(a , c , t) → ((B a → X) × ((Σ (D c) ((t *) Q)) → X))})\n f ((a , c) , t) =\n ((a , c , (λ d → proj₁ (proj₂ t d) ))\n , ((proj₁ t) , (λ { (d , q) → proj₂ (proj₂ t d) q})))\n\n g : Σ (A × Σ C (λ c → D c → P))\n (λ {(a , c , t) → ((B a → X) × ((Σ (D c) ((t *) Q)) → X))}) →\n Σ (A × C) (λ {(a , c) → (B a → X) × (D c → Σ P (λ p → Q p → X)) })\n g ((a , c , t₁) , t₂) =\n ((a , c)\n , (proj₁ t₂)\n , (λ d → (t₁ d , (λ q → proj₂ t₂ (d , q)))))\n\nδ : {I : Set} → I → I × I\nδ i = (i , i)\n\nbar : {I K L : Set} (t : K → I) (v : L → I) (A : Fam K) (B : Fam L) →\n (Σ' t A ×ᵢ Σ' v B) ≃' (δ *) (Σ' (t ⊗ v) ((proj₁ *) A ×ᵢ (proj₂ *) B))\nbar {I} {K} {L} t v A B i =\n record\n { f = f i\n ; f⃖ = g i\n ; is-invˡ = {!!}\n ; is-invʳ = {!!}\n }\n where\n f : (i : I) →\n (Σ' t A ×ᵢ Σ' v B) i → (Σ' (t ⊗ v) ((proj₁ *) A ×ᵢ (proj₂ *) B)) (i , i)\n f .(t k) (ins k x , y) = h k x (t k) refl y\n where\n h : (k : K) (x : A k) (i : I) (p : t k ≡ i) →\n (Σ' v B) i → (Σ' (t ⊗ v) ((proj₁ *) A ×ᵢ (proj₂ *) B)) (i , i)\n h k x ._ p (ins l y) =\n ins' (k , l)\n ((v l) , (v l))\n (⊗-eq {f = t} {v} k l p)\n (x , y)\n\n g : (i : I) →\n (Σ' (t ⊗ v) ((proj₁ *) A ×ᵢ (proj₂ *) B)) (i , i) → (Σ' t A ×ᵢ Σ' v B) i\n g i x =\n let\n k = proj₁ (p₁' x)\n l = proj₂ (p₁' x)\n\n q₁ : t k ≡ i\n q₁ = ×-eqˡ (p₌' x)\n\n q₂ : v l ≡ i\n q₂ = ×-eqʳ (p₌' x)\n\n u : A k × B l\n u = p₂' x\n in (ins' k i q₁ (proj₁ u) , ins' l i q₂ (proj₂ u))\n\n_∣_ : {I J : Set} → Fam I → Fam J → Fam (I ⊎ J)\nX ∣ Y = [ X , Y ]′\n\nPB : {A₁ A₂ I : Set} → (A₁ → I) → (A₂ → I) → Set\nPB {A₁} {A₂} f g = Σ[ x ∈ A₁ × A₂ ] (f (proj₁ x) ≡ g (proj₂ x))\n\nPB-idx : {A₁ A₂ I : Set} → (f : A₁ → I) → (g : A₂ → I) → (PB f g → I)\nPB-idx f _ ((x₁ , x₂) , _) = f x₁\n\n_⊎'_ : {I J K : Set} → DPoly {I} {J} → DPoly {I} {K} → DPoly {I} {J ⊎ K}\n(dpoly A₁ s₁ B₁ p₁ t₁) ⊎' (dpoly A₂ s₂ B₂ p₂ t₂)\n = dpoly A (PB-idx s₁ s₂) (U₁ ⊎ U₂) [ q₁ , q₂ ]′ (Sum.map (t₁ ∘ r₁) (t₂ ∘ r₂))\n where\n A = PB s₁ s₂\n U₁ = PB {A} (proj₁ ∘ proj₁) p₁\n U₂ = PB {A} (proj₂ ∘ proj₁) p₂\n q₁ : U₁ → A\n q₁ = proj₁ ∘ proj₁\n q₂ : U₂ → A\n q₂ = proj₁ ∘ proj₁\n r₁ : U₁ → B₁\n r₁ = proj₂ ∘ proj₁\n r₂ : U₂ → B₂\n r₂ = proj₂ ∘ proj₁\n\nparametric-poly-by-sum : {I J K : Set} →\n (P : DPoly {I} {J}) → (Q : DPoly {I} {K}) →\n ∀ X Y → (T P ×ᵢ' T Q)(X , Y) ≃' T (P ⊎' Q) (X ∣ Y)\nparametric-poly-by-sum {I} {J} P Q X Y i =\n record\n { f = f i\n ; f⃖ = g i\n ; is-invˡ = {!!}\n ; is-invʳ = {!!}\n }\n\n where\n\n f : (i : I) → (T P ×ᵢ' T Q) (X , Y) i → T (P ⊎' Q) (X ∣ Y) i\n f ._ (ins a v , y) = h a v (DPoly.s P a) refl y\n where\n h : (a : DPoly.A P)\n (v : Π' (DPoly.p P) (λ e → X (DPoly.t P e)) a)\n (i : I)\n (p : DPoly.s P a ≡ i) →\n T Q Y i → T (P ⊎' Q) (X ∣ Y) i\n h a₁ v₁ ._ p (ins a₂ v₂) = ins' a₃ (DPoly.s Q a₂) p₃ v₃\n where\n a₃ : DPoly.A (P ⊎' Q)\n a₃ = (a₁ , a₂) , p\n\n p₃ : DPoly.s (P ⊎' Q) a₃ ≡ DPoly.s Q a₂\n p₃ = trans refl p\n\n v₃ : Π' (DPoly.p (P ⊎' Q)) (λ e → (X ∣ Y) (DPoly.t (P ⊎' Q) e)) a₃\n v₃ = abs'' a₃ (v' a₃ refl)\n where\n v' : (u : DPoly.A (P ⊎' Q)) →\n (a₁ , a₂) ≡ proj₁ u →\n (i₁ : DPoly.E (P ⊎' Q)) →\n DPoly.p (P ⊎' Q) i₁ ≡ u →\n ((X ∣ Y) (DPoly.t (P ⊎' Q) i₁))\n v' u r (inj₁ ((.u , b) , q)) refl = v₁ (b , sym (trans (×-eqˡ r) q))\n v' u r (inj₂ ((.u , b) , q)) refl = v₂ (b , sym (trans (×-eqʳ r) q))\n\n g : (i : I) → T (P ⊎' Q) (X ∣ Y) i → (T P ×ᵢ' T Q) (X , Y) i\n g ._ (ins x v) =\n (ins (proj₁ (proj₁ x)) v₁\n , ins' a₂ (DPoly.s P a₁) (sym (proj₂ x)) v₂)\n where\n a₁ = proj₁ (proj₁ x)\n a₂ = proj₂ (proj₁ x)\n\n v₁ : Π' (DPoly.p P) (((DPoly.t P) *) X) a₁\n v₁ = abs'' a₁ (v₁' a₁ refl)\n where\n v₁' : (a : DPoly.A P) (p : a₁ ≡ a) (b : DPoly.E P) →\n DPoly.p P b ≡ a → X (DPoly.t P b)\n v₁' ._ p b refl = v ((inj₁ ((x , b) , p)) , refl)\n\n v₂ : Π' (DPoly.p Q) (((DPoly.t Q) *) Y) a₂\n v₂ = abs'' a₂ (v₂' a₂ refl)\n where\n v₂' : (a : DPoly.A Q) (p : a₂ ≡ a) (b : DPoly.E Q) →\n DPoly.p Q b ≡ a → Y (DPoly.t Q b)\n v₂' ._ p b refl = v ((inj₂ ((x , b) , p)) , refl)\n\n\n{-\n : {I J : Set} → (P : DPoly {I} {J}) → (Q : DPoly {I} {J}) →\n let H = λ X Y → ⟦ P ⟧ X ×ᵢ ⟦ Q ⟧\n in \n-}\n", "meta": {"hexsha": "aa298aad9f1aa907f2afeee9a232940635229b23", "size": 8915, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "TypeTheory/Container/PolyFinalCoalg.agda", "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "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": "TypeTheory/Container/PolyFinalCoalg.agda", "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "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": "TypeTheory/Container/PolyFinalCoalg.agda", "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "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": 28.9448051948, "max_line_length": 80, "alphanum_fraction": 0.3837352776, "num_tokens": 4375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.5, "lm_q1q2_score": 0.37158400430624056}} {"text": "------------------------------------------------------------------------\n-- A variant of the development in \"Internalizing Representation\n-- Independence with Univalence\" (by Angiuli, Cavallo, Mörtberg and\n-- Zeuner) with support for erasure\n------------------------------------------------------------------------\n\n-- This development follows parts of \"Internalizing Representation\n-- Independence with Univalence\" (and sometimes the code supporting\n-- that paper) fairly closely, but with explicit support for erasure,\n-- and there are some other differences. Note that some things\n-- discussed in the paper are not included, for instance tactics and\n-- most examples.\n\n-- This formalisation was started because an anonymous reviewer asked\n-- whether something like this could be done, and when I had made some\n-- initial experiments Andrea Vezzosi encouraged me to include more in\n-- the formalisation.\n\n{-# OPTIONS --erased-cubical --safe #-}\n\nimport Equality.Path as P\n\nmodule Structure-identity-principle.Erased\n {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where\n\nopen P.Derived-definitions-and-properties eq\n\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude\n\nopen import Bijection equality-with-J as B using (_↔_)\nopen import Equality.Decidable-UIP equality-with-J\nopen import Equality.Path.Isomorphisms eq\nimport Equality.Path.Isomorphisms.Univalence eq as U\nopen import Equivalence equality-with-J as Eq\n using (_≃_; Is-equivalence)\nopen import Equivalence.Erased.Cubical eq as EEq\n using (_≃ᴱ_; Is-equivalenceᴱ)\nopen import Equivalence.Erased.Contractible-preimages.Cubical eq as ECP\n using (Contractibleᴱ)\nopen import Equivalence-relation equality-with-J\nopen import Erased.Cubical eq as Er hiding (map; map-id)\nopen import Function-universe equality-with-J as F hiding (id; _∘_)\nopen import H-level equality-with-J as H-level\nopen import H-level.Closure equality-with-J\nopen import H-level.Truncation.Propositional.Erased eq as T\n using (∥_∥ᴱ; ∣_∣)\nimport List equality-with-J as L\nimport Maybe equality-with-J as Maybe\nimport Monad equality-with-J as Monad\nimport Nat equality-with-J as Nat\nopen import Quotient.Erased eq as Q using (_/ᴱ_; [_])\nopen import Univalence-axiom equality-with-J\n\nopen import\n Nat.Binary equality-with-J instance-of-[]-cong-axiomatisation\n as Bin using (Bin)\n\nprivate\n variable\n a b c d e r : Level\n C : Type c\n A A₁ A₂ B B₁ B₂ Ax F f G g M m N P R R₁ R₂ S\n x x′ x₁ x₂ y y′ ys z z₁ z₂ : C\n\n------------------------------------------------------------------------\n-- The structure identity principle\n\n-- Structures.\n\nStructure : (a b : Level) → Type (lsuc (a ⊔ b))\nStructure a b = Type a → Type b\n\n-- Types with a given structure.\n\nType-with : Structure a b → Type (lsuc a ⊔ b)\nType-with {a = a} F = ∃ λ (A : Type a) → F A\n\n-- Axioms.\n--\n-- Originally I made the argument of type Type-with F erased. After\n-- feedback from Andrea Vezzosi I instead added a use of Erased in\n-- _With-the-axioms_ below.\n\nAxioms : Structure a b → (c : Level) → Type (lsuc a ⊔ b ⊔ lsuc c)\nAxioms F c = Type-with F → Type c\n\n-- One can add axioms to structures.\n\n_With-the-axioms_ :\n (F : Structure a b) → Axioms F c → Structure a (b ⊔ c)\n(F With-the-axioms Ax) A = ∃ λ (x : F A) → Erased (Ax (A , x))\n\n-- A type of predicates defining when a given equivalence (with erased\n-- proofs) is structure-preserving.\n\nStructure-preserving-equivalence-predicate :\n Structure a b → (c : Level) → Type (lsuc a ⊔ b ⊔ lsuc c)\nStructure-preserving-equivalence-predicate F c =\n (A B : Type-with F) → proj₁ A ≃ᴱ proj₁ B → Type c\n\n-- One can lift a \"structure-preserving equivalence predicate\" from F\n-- to F With-the-axioms Ax.\n\nLift-With-the-axioms :\n Structure-preserving-equivalence-predicate F c →\n Structure-preserving-equivalence-predicate (F With-the-axioms Ax) c\nLift-With-the-axioms P (A , x , _) (B , y , _) = P (A , x) (B , y)\n\n-- Structure-preserving equivalences (with erased proofs).\n\ninfix 4 _≃[_]ᴱ_\n\n_≃[_]ᴱ_ :\n {F : Structure a b} →\n Type-with F → @0 Structure-preserving-equivalence-predicate F c →\n Type-with F →\n Type (a ⊔ c)\nA ≃[ P ]ᴱ B = ∃ λ (eq : proj₁ A ≃ᴱ proj₁ B) → Erased (P A B eq)\n\n-- Univalent pairs of structures and predicates.\n\nrecord Univalent\n (@0 F : Structure a b)\n (@0 P : Structure-preserving-equivalence-predicate F c) :\n Type (lsuc a ⊔ b ⊔ c) where\n field\n -- This field is erased because it uses univalence and EEq.≃ᴱ→≃.\n\n @0 univalent :\n {A B : Type-with F}\n (eq : proj₁ A ≃ᴱ proj₁ B) →\n P A B eq ≃\n (subst F (≃⇒≡ U.abstract-univ (EEq.≃ᴱ→≃ eq)) (proj₂ A) ≡ proj₂ B)\n\n-- If Ax is pointwise propositional, then the functions\n-- _With-the-axioms Ax and Lift-With-the-axioms preserve\n-- Univalent univ.\n--\n-- This is a variant of Lemma 3.3 from \"Internalizing Representation\n-- Independence with Univalence\".\n\nUnivalent-With-the-axioms :\n {@0 P : Structure-preserving-equivalence-predicate F c} →\n @0 (∀ A → Is-proposition (Ax A)) →\n Univalent F P →\n Univalent (F With-the-axioms Ax) (Lift-With-the-axioms P)\nUnivalent-With-the-axioms\n {F = F} {Ax = Ax} {P = P} prop u .Univalent.univalent\n {A = A₁ , x₁ , ax₁} {B = A₂ , x₂ , ax₂} eq =\n\n P (A₁ , x₁) (A₂ , x₂) eq ↝⟨ u .Univalent.univalent eq ⟩\n\n subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁ ≡ x₂ ↔⟨ ignore-propositional-component (H-level-Erased 1 (prop _)) ⟩\n\n (subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁ , _) ≡ (x₂ , ax₂) ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-pair _ _ ⟩□\n\n subst (F With-the-axioms Ax) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (x₁ , ax₁) ≡\n (x₂ , ax₂) □\n where\n univ = U.abstract-univ\n\n-- The structure identity principle.\n--\n-- This is a variant of Theorem 3.1 from \"Internalizing Representation\n-- Independence with Univalence\". Note that the principle is erased.\n\n@0 sip :\n Univalent F P →\n (A ≃[ P ]ᴱ B) ≃ (A ≡ B)\nsip {F = F} {P = P} {A = A} {B = B} u =\n (A ≃[ P ]ᴱ B) ↔⟨⟩\n (∃ λ (eq : proj₁ A ≃ᴱ proj₁ B) → Erased (P A B eq)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩\n (∃ λ (eq : proj₁ A ≃ᴱ proj₁ B) → P A B eq) ↝⟨ Σ-cong\n (inverse $ EEq.≃≃≃ᴱ F.∘ ≡≃≃ U.abstract-univ)\n (u .Univalent.univalent) ⟩\n (∃ λ (eq : proj₁ A ≡ proj₁ B) → subst F eq (proj₂ A) ≡ proj₂ B) ↔⟨ B.Σ-≡,≡↔≡ ⟩□\n (A ≡ B) □\n\n-- If there is a structure-preserving equivalence (for a univalent\n-- pair of a structure and a predicate) between two types with\n-- structures, where one side satisfies some axioms, then the other\n-- side also satisfies the axioms (in erased contexts), and the\n-- resulting triple is equivalent (with erased proofs) to the other\n-- one.\n--\n-- This is a variant of Corollary 3.4 from \"Internalizing\n-- Representation Independence with Univalence\".\n\ninduced-structures :\n {@0 P : Structure-preserving-equivalence-predicate F c} →\n @0 Univalent F P →\n (X@(A , x , _) : Type-with (F With-the-axioms Ax)) →\n ((B , y) : Type-with F) →\n (A , x) ≃[ P ]ᴱ (B , y) →\n ∃ λ (ax : Erased (Ax (B , y))) →\n X ≃[ Lift-With-the-axioms P ]ᴱ (B , y , ax)\ninduced-structures {Ax = Ax} u (A , x , ax) (B , y) eq =\n Er.map (subst Ax (_≃_.to (sip u) eq)) ax\n , eq\n\n------------------------------------------------------------------------\n-- Some binary relation combinators, along with some properties\n\n-- The converse of a binary relation.\n\ninfix 10 _⁻¹\n\n_⁻¹ : (A → B → Type c) → (B → A → Type c)\n(R ⁻¹) x y = R y x\n\n-- Propositionally truncated composition of two binary relations (the\n-- definition uses ∥_∥ᴱ).\n\ninfixr 9 _;ᴱ_\n\n_;ᴱ_ :\n {B : Type b} →\n (A → B → Type d) → (B → C → Type e) → A → C → Type (b ⊔ d ⊔ e)\n(R ;ᴱ S) x z = ∥ (∃ λ y → R x y × S y z) ∥ᴱ\n\n-- Two ways to compose a relation and its converse.\n\ninfix 10 _⟵ _⟶\n\n_⟵ : {B : Type b} → (A → B → Type c) → A → A → Type (b ⊔ c)\nR ⟵ = R ;ᴱ R ⁻¹\n\n_⟶ : {A : Type a} → (A → B → Type c) → B → B → Type (a ⊔ c)\nR ⟶ = R ⁻¹ ;ᴱ R\n\n-- If R is a propositional equivalence relation targetting a certain\n-- universe, then R ⟵ is pointwise logically equivalent (with erased\n-- proofs) to R.\n\n⟵≃ᴱ :\n {A : Type a}\n {R : A → A → Type a} →\n @0 (∀ x y → Is-proposition (R x y)) →\n Is-equivalence-relation R →\n ∀ {x y} → (R ⟵) x y ≃ᴱ R x y\n⟵≃ᴱ prop equiv =\n EEq.⇔→≃ᴱ\n T.truncation-is-proposition\n (prop _ _)\n (T.rec λ where\n .T.truncation-is-propositionʳ → prop _ _\n .T.∣∣ʳ (_ , Rxy , Rzy) →\n E.transitive Rxy (E.symmetric Rzy))\n (λ Rxz → ∣ _ , Rxz , E.reflexive ∣)\n where\n module E = Is-equivalence-relation equiv\n\n-- If R is a propositional equivalence relation targetting a certain\n-- universe, then R ⟶ is pointwise logically equivalent (with erased\n-- proofs) to R.\n\n⟶≃ᴱ :\n {A : Type a}\n {R : A → A → Type a} →\n @0 (∀ x y → Is-proposition (R x y)) →\n Is-equivalence-relation R →\n ∀ {x y} → (R ⟶) x y ≃ᴱ R x y\n⟶≃ᴱ prop equiv =\n EEq.⇔→≃ᴱ\n T.truncation-is-proposition\n (prop _ _)\n (T.rec λ where\n .T.truncation-is-propositionʳ → prop _ _\n .T.∣∣ʳ (_ , Ryx , Ryz) →\n E.transitive (E.symmetric Ryx) Ryz)\n (λ Rzx →\n ∣ _ , E.symmetric Rzx , E.reflexive ∣)\n where\n module E = Is-equivalence-relation equiv\n\n-- If R is a propositional equivalence relation targetting a certain\n-- universe, then R ⟵ is equal to R (in erased contexts).\n\n@0 ⟵≡ :\n {A : Type a}\n {R : A → A → Type a} →\n (∀ x y → Is-proposition (R x y)) →\n Is-equivalence-relation R →\n R ⟵ ≡ R\n⟵≡ prop equiv =\n ⟨ext⟩ λ _ → ⟨ext⟩ λ _ →\n ≃⇒≡ U.univ $\n EEq.≃ᴱ→≃ $\n ⟵≃ᴱ prop equiv\n\n-- If R is a propositional equivalence relation targetting a certain\n-- universe, then R ⟶ is equal to R (in erased contexts).\n\n@0 ⟶≡ :\n {A : Type a}\n {R : A → A → Type a} →\n (∀ x y → Is-proposition (R x y)) →\n Is-equivalence-relation R →\n R ⟶ ≡ R\n⟶≡ prop equiv =\n ⟨ext⟩ λ _ → ⟨ext⟩ λ _ →\n ≃⇒≡ U.univ $\n EEq.≃ᴱ→≃ $\n ⟶≃ᴱ prop equiv\n\n-- The graph of a function.\n\nGraph : {A : Type a} {B : Type b} → (A → B) → A → B → Type b\nGraph f x y = f x ≡ y\n\n-- If R is a propositional equivalence relation targetting a certain\n-- universe, then Graph (Q.[_] {R = R}) ⟵ is equal to R (in erased\n-- contexts).\n\n@0 Graph-[]-⟵≡ :\n {A : Type a}\n {R : A → A → Type a} →\n (∀ x y → Is-proposition (R x y)) →\n Is-equivalence-relation R →\n Graph (Q.[_] {R = R}) ⟵ ≡ R\nGraph-[]-⟵≡ {R = R} prop equiv =\n ⟨ext⟩ λ x → ⟨ext⟩ λ y →\n let\n lemma =\n Eq.⇔→≃\n T.truncation-is-proposition\n Q./ᴱ-is-set\n (T.rec λ @0 where\n .T.truncation-is-propositionʳ → Q./ᴱ-is-set\n .T.∣∣ʳ (_ , [x]≡z , [y]≡z) → trans [x]≡z (sym [y]≡z))\n (λ [x]≡[y] → ∣ _ , [x]≡[y] , refl _ ∣)\n in\n ≃⇒≡ U.univ\n ((Graph [_] ⟵) x y ↝⟨ lemma ⟩\n [ x ] ≡ [ y ] ↔⟨ inverse $ Q.related≃[equal] equiv (prop _ _) ⟩□\n R x y □)\n\n-- If R is a propositional equivalence relation, then\n-- R ;ᴱ Graph ([_] {R = R}) is equal to Graph ([_] {R = R}) (in erased\n-- contexts).\n\n@0 ;ᴱ-Graph-[]≡Graph-[] :\n {A : Type a}\n {R : A → A → Type r} →\n (∀ x y → Is-proposition (R x y)) →\n Is-equivalence-relation R →\n R ;ᴱ Graph ([_] {R = R}) ≡ Graph ([_] {R = R})\n;ᴱ-Graph-[]≡Graph-[] {R = R} prop equiv =\n ⟨ext⟩ λ x → ⟨ext⟩ λ y →\n ≃⇒≡ U.univ $\n flip\n (Q.elim-prop\n {P = λ y → (R ;ᴱ Graph ([_] {R = R})) x y ≃\n Graph ([_] {R = R}) x y})\n y\n λ @0 where\n .Q.is-propositionʳ _ →\n Eq.left-closure ext 0 $\n T.truncation-is-proposition\n .Q.[]ʳ y →\n Eq.⇔→≃\n T.truncation-is-proposition\n Q./ᴱ-is-set\n (T.rec λ @0 where\n .T.Rec.truncation-is-propositionʳ →\n Q./ᴱ-is-set\n .T.Rec.∣∣ʳ (z , Rxz , [z]≡[y]) →\n [ x ] ≡⟨ Q.[]-respects-relation Rxz ⟩\n [ z ] ≡⟨ [z]≡[y] ⟩∎\n [ y ] ∎)\n ([ x ] ≡ [ y ] ↔⟨ inverse $ Q.related≃[equal] equiv (prop _ _) ⟩\n R x y ↝⟨ (λ Rxy → ∣ _ , Rxy , refl _ ∣) ⟩\n (R ;ᴱ Graph [_]) x [ y ] □)\n\n------------------------------------------------------------------------\n-- Quasi-equivalence relations\n\n-- Quasi-PERs, or zigzag-complete relations (following Krishnaswami\n-- and Dreyer, see \"Internalizing Relational Parametricity in the\n-- Extensional Calculus of Constructions\").\n--\n-- Angiuli et al. only define what it means to be a quasi-PER for\n-- propositional relations. The following definition applies to\n-- arbitrary relations.\n\nIs-QPER :\n {A : Type a} {B : Type b} →\n (A → B → Type c) → Type (a ⊔ b ⊔ c)\nIs-QPER R =\n ∀ {x x′ y y′} →\n R x y → R x′ y → R x′ y′ → R x y′\n\n-- Quasi-equivalence relations (QERs), defined using ∥_∥ᴱ instead of\n-- ∥_∥.\n\nIs-QER :\n {A : Type a} {B : Type b} →\n (A → B → Type c) → Type (a ⊔ b ⊔ c)\nIs-QER R =\n Is-QPER R ×\n (∀ x → ∥ ∃ (λ y → R x y) ∥ᴱ) ×\n (∀ y → ∥ ∃ (λ x → R x y) ∥ᴱ)\n\n-- Quasi-equivalence relations (QERs), defined using ∥_∥ᴱ instead of\n-- ∥_∥, and with some parts erased.\n\nIs-QERᴱ :\n {A : Type a} {B : Type b} →\n @0 (A → B → Type c) → Type (a ⊔ b ⊔ c)\nIs-QERᴱ R =\n Erased (Is-QPER R) ×\n (∀ x → ∥ ∃ (λ y → Erased (R x y)) ∥ᴱ) ×\n (∀ y → ∥ ∃ (λ x → Erased (R x y)) ∥ᴱ)\n\n-- Is-QERᴱ can be expressed using Is-QER and Erased.\n\nIs-QERᴱ≃Is-QER-Erased :\n {@0 R : A → B → Type r} →\n Is-QERᴱ R ≃ Is-QER (λ x y → Erased (R x y))\nIs-QERᴱ≃Is-QER-Erased {A = A} {B = B} {R = R} = ×-cong₁ λ _ →\n\n Erased (∀ {x x′ y y′} → R x y → R x′ y → R x′ y′ → R x y′) ↝⟨ Erased-cong lemma ⟩\n\n Erased (∀ x x′ y y′ → R x y → R x′ y → R x′ y′ → R x y′) ↔⟨ (∀-cong ext λ _ →\n (∀-cong ext λ _ →\n (∀-cong ext λ _ →\n Erased-Π↔Π) F.∘\n Erased-Π↔Π) F.∘\n Erased-Π↔Π) F.∘\n Erased-Π↔Π ⟩\n\n (∀ x x′ y y′ → Erased (R x y → R x′ y → R x′ y′ → R x y′)) ↔⟨ (∀-cong ext λ _ →\n ∀-cong ext λ _ →\n ∀-cong ext λ _ →\n ∀-cong ext λ _ →\n (∀-cong ext λ _ →\n (∀-cong ext λ _ →\n Erased-Π↔Π-Erased) F.∘\n Erased-Π↔Π-Erased) F.∘\n Erased-Π↔Π-Erased) ⟩\n (∀ x x′ y y′ →\n Erased (R x y) → Erased (R x′ y) →\n Erased (R x′ y′) → Erased (R x y′)) ↝⟨ inverse lemma ⟩□\n\n (∀ {x x′ y y′} →\n Erased (R x y) → Erased (R x′ y) →\n Erased (R x′ y′) → Erased (R x y′)) □\n where\n lemma :\n {P : A → A → B → B → Type r} →\n (∀ {x x′ y y′} → P x x′ y y′) ≃\n (∀ x x′ y y′ → P x x′ y y′)\n lemma = Eq.↔⇒≃ $\n (∀-cong ext λ _ →\n (∀-cong ext λ _ →\n (∀-cong ext λ _ →\n B.implicit-Π↔Π) F.∘\n B.implicit-Π↔Π) F.∘\n B.implicit-Π↔Π) F.∘\n B.implicit-Π↔Π\n\n-- Is-QER R implies Is-QERᴱ R.\n\nIs-QER→Is-QERᴱ : Is-QER R → Is-QERᴱ R\nIs-QER→Is-QERᴱ =\n [_]→\n ×-cong\n (∀-cong _ λ x →\n T.∥∥ᴱ-map $ ∃-cong λ _ → [_]→)\n ×-cong\n (∀-cong _ λ x →\n T.∥∥ᴱ-map $ ∃-cong λ _ → [_]→)\n\n-- In erased contexts Is-QER R is equivalent to Is-QERᴱ R.\n\n@0 Is-QER≃Is-QERᴱ : Is-QER R ≃ Is-QERᴱ R\nIs-QER≃Is-QERᴱ = Eq.↔⇒≃ $ inverse $\n Erased↔ .erased\n ×-cong\n (∀-cong ext λ x →\n T.∥∥ᴱ-cong $ ∃-cong λ _ → Erased↔ .erased)\n ×-cong\n (∀-cong ext λ x →\n T.∥∥ᴱ-cong $ ∃-cong λ _ → Erased↔ .erased)\n\n-- The forward direction of Is-QER≃Is-QERᴱ {R = R} is definitionally\n-- equal to Is-QER→Is-QERᴱ.\n\n_ : _≃_.to (Is-QER≃Is-QERᴱ {R = R}) ≡ Is-QER→Is-QERᴱ\n_ = refl _\n\n-- If Is-QER R holds, then R ⟵ is an equivalence relation.\n\nIs-QER→Is-equivalence-relation-⟵ :\n Is-QER R →\n Is-equivalence-relation (R ⟵)\nIs-QER→Is-equivalence-relation-⟵ (qper , lr , rl) = λ where\n .Is-equivalence-relation.reflexive {x = x} →\n T.∥∥ᴱ-map (λ (y , Rxy) → y , Rxy , Rxy) (lr x)\n .Is-equivalence-relation.symmetric →\n T.∥∥ᴱ-map (Σ-map id swap)\n .Is-equivalence-relation.transitive →\n T.rec λ where\n .T.truncation-is-propositionʳ →\n Π-closure ext 1 λ _ →\n T.truncation-is-proposition\n .T.∣∣ʳ (_ , Rx₁y₁ , Rx₂y₁) → T.∥∥ᴱ-map\n λ (_ , Rx₂y₂ , Rx₃y₂) →\n _ , qper Rx₁y₁ Rx₂y₁ Rx₂y₂ , Rx₃y₂\n\n-- If Is-QERᴱ R holds, then R ⟵ is an equivalence relation (in erased\n-- contexts).\n\n@0 Is-QERᴱ→Is-equivalence-relation-⟵ :\n Is-QERᴱ R →\n Is-equivalence-relation (R ⟵)\nIs-QERᴱ→Is-equivalence-relation-⟵ {R = R} =\n Is-QERᴱ R ↔⟨ inverse Is-QER≃Is-QERᴱ ⟩\n Is-QER R ↝⟨ Is-QER→Is-equivalence-relation-⟵ ⟩□\n Is-equivalence-relation (R ⟵) □\n\n-- If Is-QER R holds, then R ⟶ is an equivalence relation.\n\nIs-QER→Is-equivalence-relation-⟶ :\n Is-QER R →\n Is-equivalence-relation (R ⟶)\nIs-QER→Is-equivalence-relation-⟶ (qper , lr , rl) = λ where\n .Is-equivalence-relation.reflexive {x = y} →\n T.∥∥ᴱ-map (λ (x , Rxy) → x , Rxy , Rxy) (rl y)\n .Is-equivalence-relation.symmetric →\n T.∥∥ᴱ-map (Σ-map id swap)\n .Is-equivalence-relation.transitive →\n T.rec λ where\n .T.truncation-is-propositionʳ →\n Π-closure ext 1 λ _ →\n T.truncation-is-proposition\n .T.∣∣ʳ (_ , Rx₁y₁ , Rx₁y₂) → T.∥∥ᴱ-map\n λ (_ , Rx₂y₂ , Rx₂y₃) →\n _ , qper Rx₂y₂ Rx₁y₂ Rx₁y₁ , Rx₂y₃\n\n-- If Is-QERᴱ R holds, then R ⟶ is an equivalence relation (in erased\n-- contexts).\n\n@0 Is-QERᴱ→Is-equivalence-relation-⟶ :\n Is-QERᴱ R →\n Is-equivalence-relation (R ⟶)\nIs-QERᴱ→Is-equivalence-relation-⟶ {R = R} =\n Is-QERᴱ R ↔⟨ inverse Is-QER≃Is-QERᴱ ⟩\n Is-QER R ↝⟨ Is-QER→Is-equivalence-relation-⟶ ⟩□\n Is-equivalence-relation (R ⟶) □\n\n-- A propositional QER R can be turned into an equivalence (with\n-- erased proofs) satisfying a certain (partly erased) condition.\n--\n-- This is a variant of Lemma 5.4 from \"Internalizing Representation\n-- Independence with Univalence\".\n\n/ᴱ⟵≃ᴱ/ᴱ⟶ :\n Is-QER R →\n @0 (∀ x y → Is-proposition (R x y)) →\n ∃ λ (eq : A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶) →\n ∀ x y →\n ∃ λ (f : _≃ᴱ_.to eq [ x ] ≡ [ y ] → R x y) →\n Erased (Is-equivalence f)\n/ᴱ⟵≃ᴱ/ᴱ⟶ {A = A} {B = B} {R = R} qer@(qper , lr , rl) prop =\n EEq.↔→≃ᴱ to from to-from from-to\n , (λ _ _ →\n to″\n , [ _≃_.is-equivalence $\n Eq.⇔→≃ Q./ᴱ-is-set (prop _ _) to″ from″\n ])\n where\n to′ : ∥ ∃ (R x) ∥ᴱ → B /ᴱ R ⟶\n to′ =\n _≃_.to (Q.Σ→Erased-Constant≃∥∥ᴱ→ Q./ᴱ-is-set)\n ( [_] ∘ proj₁\n , [ (λ (_ , r₁) (_ , r₂) →\n Q.[]-respects-relation ∣ _ , r₁ , r₂ ∣)\n ]\n )\n\n @0 to′-lemma :\n R x y → R x′ y →\n (p : ∥ ∃ (R x) ∥ᴱ)\n (p′ : ∥ ∃ (R x′) ∥ᴱ) →\n to′ p ≡ to′ p′\n to′-lemma Rxy Rx′y = T.elim λ @0 where\n .T.truncation-is-propositionʳ _ →\n Π-closure ext 1 λ _ →\n Q./ᴱ-is-set\n .T.∣∣ʳ (y₁ , Rxy₁) → T.elim λ @0 where\n .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set\n .T.∣∣ʳ (y₂ , Rx′y₂) →\n [ y₁ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rxy₁ , qper Rxy Rx′y Rx′y₂ ∣ ⟩∎\n [ y₂ ] ∎\n\n to : A /ᴱ R ⟵ → B /ᴱ R ⟶\n to = Q.rec λ where\n .Q.is-setʳ → Q./ᴱ-is-set\n\n .Q.[]ʳ → to′ ∘ lr\n\n .Q.[]-respects-relationʳ {x = x} {y = x′} → T.elim λ @0 where\n .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set\n .T.∣∣ʳ (_ , Rxy , Rx′y) →\n to′ (lr x) ≡⟨ to′-lemma Rxy Rx′y (lr x) (lr x′) ⟩∎\n to′ (lr x′) ∎\n\n from′ : ∥ ∃ ((R ⁻¹) y) ∥ᴱ → A /ᴱ R ⟵\n from′ =\n _≃_.to (Q.Σ→Erased-Constant≃∥∥ᴱ→ Q./ᴱ-is-set)\n ( [_] ∘ proj₁\n , [ (λ (_ , r₁) (_ , r₂) →\n Q.[]-respects-relation ∣ _ , r₁ , r₂ ∣)\n ]\n )\n\n @0 from′-lemma :\n R x y → R x y′ →\n (p : ∥ ∃ ((R ⁻¹) y) ∥ᴱ)\n (p′ : ∥ ∃ ((R ⁻¹) y′) ∥ᴱ) →\n from′ p ≡ from′ p′\n from′-lemma Rxy Rxy′ = T.elim λ @0 where\n .T.truncation-is-propositionʳ _ →\n Π-closure ext 1 λ _ →\n Q./ᴱ-is-set\n .T.∣∣ʳ (x₁ , Rx₁y) → T.elim λ @0 where\n .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set\n .T.∣∣ʳ (x₂ , Rx₂y′) →\n [ x₁ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rx₁y , qper Rx₂y′ Rxy′ Rxy ∣ ⟩∎\n [ x₂ ] ∎\n\n from : B /ᴱ R ⟶ → A /ᴱ R ⟵\n from = Q.rec λ where\n .Q.is-setʳ → Q./ᴱ-is-set\n\n .Q.[]ʳ → from′ ∘ rl\n\n .Q.[]-respects-relationʳ {x = y} {y = y′} → T.elim λ @0 where\n .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set\n .T.∣∣ʳ (_ , Rxy , Rxy′) →\n from′ (rl y) ≡⟨ from′-lemma Rxy Rxy′ (rl y) (rl y′) ⟩∎\n from′ (rl y′) ∎\n\n @0 to′≡[] :\n R x y → (p : ∥ ∃ (R x) ∥ᴱ) →\n to′ p ≡ [ y ]\n to′≡[] {x = x} {y = y} Rxy = T.elim λ @0 where\n .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set\n .T.∣∣ʳ (y′ , Rxy′) →\n [ y′ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rxy′ , Rxy ∣ ⟩∎\n [ y ] ∎\n\n @0 to-from′ :\n ∀ y (p : ∥ ∃ ((R ⁻¹) y) ∥ᴱ) →\n to (from′ p) ≡ [ y ]\n to-from′ y = T.elim λ @0 where\n .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set\n .T.∣∣ʳ (x , Rxy) →\n to′ (lr x) ≡⟨ to′≡[] Rxy (lr x) ⟩∎\n [ y ] ∎\n\n @0 to-from : ∀ y → to (from y) ≡ y\n to-from = Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ → Q./ᴱ-is-set\n .Q.[]ʳ y →\n to (from′ (rl y)) ≡⟨ to-from′ y (rl y) ⟩∎\n [ y ] ∎\n\n @0 from′≡[] :\n R x y → (p : ∥ ∃ ((R ⁻¹) y) ∥ᴱ) →\n from′ p ≡ [ x ]\n from′≡[] {x = x} {y = y} Rxy = T.elim λ @0 where\n .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set\n .T.∣∣ʳ (x′ , Rx′y) →\n [ x′ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rx′y , Rxy ∣ ⟩∎\n [ x ] ∎\n\n @0 from-to′ :\n ∀ x (p : ∥ ∃ (R x) ∥ᴱ) →\n from (to′ p) ≡ [ x ]\n from-to′ x = T.elim λ @0 where\n .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set\n .T.∣∣ʳ (y , Rxy) →\n from′ (rl y) ≡⟨ from′≡[] Rxy (rl y) ⟩∎\n [ x ] ∎\n\n @0 from-to : ∀ x → from (to x) ≡ x\n from-to = Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ → Q./ᴱ-is-set\n .Q.[]ʳ x →\n from (to′ (lr x)) ≡⟨ from-to′ x (lr x) ⟩∎\n [ x ] ∎\n\n to″ : to [ x ] ≡ [ y ] → R x y\n to″ {x = x} {y = y} =\n to′ (lr x) ≡ [ y ] ↝⟨ flip (T.elim {P = λ p → to′ p ≡ [ y ] → R x y}) (lr x) (λ where\n .T.truncation-is-propositionʳ _ →\n Π-closure ext 1 λ _ →\n prop _ _\n .T.∣∣ʳ (y′ , Rxy′) →\n [ y′ ] ≡ [ y ] ↝⟨ Q.effective\n (Is-QER→Is-equivalence-relation-⟶ qer)\n T.truncation-is-proposition\n ∣ _ , Rxy′ , Rxy′ ∣ ⟩\n (R ⟶) y′ y ↝⟨ T.rec (λ where\n .T.truncation-is-propositionʳ → prop _ _\n .T.∣∣ʳ (_ , Rx′y′ , Rx′y) →\n qper Rxy′ Rx′y′ Rx′y) ⟩□\n R x y □) ⟩□\n R x y □\n\n @0 from″ : R x y → to [ x ] ≡ [ y ]\n from″ {x = x} {y = y} Rxy =\n to′ (lr x) ≡⟨ to′≡[] Rxy (lr x) ⟩∎\n [ y ] ∎\n\n-- A propositional QER R (with erased proofs) can be turned into an\n-- equivalence (with erased proofs) satisfying a certain (erased)\n-- condition.\n--\n-- This is another variant of Lemma 5.4 from \"Internalizing\n-- Representation Independence with Univalence\".\n\n/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ :\n {@0 R : A → B → Type c} →\n Is-QERᴱ R →\n @0 (∀ x y → Is-proposition (R x y)) →\n ∃ λ (eq : A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶) →\n Erased (∀ x y → (_≃ᴱ_.to eq [ x ] ≡ [ y ]) ≃ R x y)\n/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ {A = A} {B = B} {R = R} qer prop = $⟨ [ prop ] ⟩\n\n Erased (∀ x y → Is-proposition (R x y)) ↝⟨ (λ ([ hyp ]) x y → H-level-Erased 1 (hyp x y)) ⦂ (_ → _) ⟩\n\n (∀ x y → Is-proposition (Rᴱ x y)) ↝⟨ (λ prop → /ᴱ⟵≃ᴱ/ᴱ⟶ (_≃_.to Is-QERᴱ≃Is-QER-Erased qer) prop) ⟩\n\n (∃ λ (eq : A /ᴱ Rᴱ ⟵ ≃ᴱ B /ᴱ Rᴱ ⟶) →\n ∀ x y →\n ∃ λ (f : _≃ᴱ_.to eq [ x ] ≡ [ y ] → Rᴱ x y) →\n Erased (Is-equivalence f)) ↝⟨ (λ (eq , ok) → drop-ᴱ eq , [ drop-ᴱ-ok eq ok ]) ⟩□\n\n (∃ λ (eq : A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶) →\n Erased (∀ x y → (_≃ᴱ_.to eq [ x ] ≡ [ y ]) ≃ R x y)) □\n where\n Rᴱ = λ x y → Erased (R x y)\n\n @0 lemma :\n ∀ x y →\n ((λ x y → Erased (R₁ x y)) ;ᴱ (λ x y → Erased (R₂ x y))) x y ⇔\n (R₁ ;ᴱ R₂) x y\n lemma {R₁ = R₁} {R₂ = R₂} x z =\n ∥ (∃ λ y → Erased (R₁ x y) × Erased (R₂ y z)) ∥ᴱ ↔⟨ (T.∥∥ᴱ-cong $ ∃-cong λ _ →\n Erased↔ .erased\n ×-cong\n Erased↔ .erased) ⟩□\n ∥ (∃ λ y → R₁ x y × R₂ y z) ∥ᴱ □\n\n drop-ᴱ :\n A /ᴱ Rᴱ ⟵ ≃ᴱ B /ᴱ Rᴱ ⟶ →\n A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶\n drop-ᴱ eq =\n A /ᴱ R ⟵ ↔⟨ Eq.id Q./ᴱ-cong (λ x y → inverse (lemma {R₁ = R} {R₂ = R ⁻¹} x y)) ⟩\n A /ᴱ Rᴱ ⟵ ↝⟨ eq ⟩\n B /ᴱ Rᴱ ⟶ ↔⟨ Eq.id Q./ᴱ-cong lemma ⟩□\n B /ᴱ R ⟶ □\n\n @0 drop-ᴱ-ok :\n (eq : A /ᴱ Rᴱ ⟵ ≃ᴱ B /ᴱ Rᴱ ⟶) →\n (∀ x y →\n ∃ λ (f : _≃ᴱ_.to eq [ x ] ≡ [ y ] → Rᴱ x y) →\n Erased (Is-equivalence f)) →\n ∀ x y → (_≃ᴱ_.to (drop-ᴱ eq) [ x ] ≡ [ y ]) ≃ R x y\n drop-ᴱ-ok eq ok x y =\n _≃ᴱ_.to (drop-ᴱ eq) [ x ] ≡ [ y ] ↔⟨⟩\n _≃_.to (Eq.id Q./ᴱ-cong lemma) (_≃ᴱ_.to eq [ x ]) ≡ [ y ] ↝⟨ Eq.≃-≡ (Eq.id Q./ᴱ-cong lemma) ⟩\n _≃ᴱ_.to eq [ x ] ≡ [ y ] ↝⟨ (let f , [ eq ] = ok x y in Eq.⟨ f , eq ⟩) ⟩\n Rᴱ x y ↔⟨ Erased↔ .erased ⟩□\n R x y □\n\n------------------------------------------------------------------------\n-- Relation transformers\n\n-- Relation transformers for a given structure.\n\nRelation-transformer-for :\n Structure a b → Type (lsuc (a ⊔ b))\nRelation-transformer-for {a = a} {b = b} F =\n ∀ {A B} → (A → B → Type a) → F A → F B → Type b\n\n-- A notion of \"suitable\" relation transformers.\n\nrecord Suitable\n {F : Structure a b}\n (@0 G : Relation-transformer-for F) :\n Type (lsuc a ⊔ b) where\n field\n -- F preserves Is-set.\n\n @0 preserves-is-set :\n Is-set A → Is-set (F A)\n\n -- G preserves a variant of Is-proposition.\n\n @0 preserves-is-proposition :\n (∀ x y → Is-proposition (R x y)) →\n ∀ x y → Is-proposition (G R x y)\n\n -- G is \"symmetric\" for propositional relations.\n\n @0 symmetric :\n (∀ x y → Is-proposition (R x y)) →\n G R x y → G (R ⁻¹) y x\n\n -- G is \"transitive\" for propositional relations.\n\n @0 transitive :\n (∀ x y → Is-proposition (R x y)) →\n (∀ x y → Is-proposition (S x y)) →\n G R x y → G S y z → G (R ;ᴱ S) x z\n\n -- Descent to quotients. Note that this is the only non-erased\n -- field of this record type.\n\n descent :\n {@0 R : A → A → Type a} →\n @0 (∀ x y → Is-proposition (R x y)) →\n @0 Is-equivalence-relation R →\n @0 G R x x →\n Contractibleᴱ (∃ λ (y : F (A /ᴱ R)) → Erased (G (Graph [_]) x y))\n\n -- A variant of transitive.\n\n @0 transitive-;ᴱ :\n (∀ x y → Is-proposition (R x y)) →\n (∀ x y → Is-proposition (S x y)) →\n ∀ x z → (G R ;ᴱ G S) x z → G (R ;ᴱ S) x z\n transitive-;ᴱ R-prop S-prop _ _ = T.rec λ @0 where\n .T.truncation-is-propositionʳ →\n preserves-is-proposition\n (λ _ _ → T.truncation-is-proposition) _ _\n .T.∣∣ʳ (_ , GRxy , GSyz) →\n transitive R-prop S-prop GRxy GSyz\n\n-- A variant of Univalent for relation transformers.\n\nUnivalentᴿ :\n {F : Structure a b} →\n @0 Relation-transformer-for F → Type (lsuc a ⊔ b)\nUnivalentᴿ {F = F} G =\n Suitable G ×\n Univalent F (λ (A , x) (B , y) eq → G (Graph (_≃ᴱ_.to eq)) x y)\n\n-- A notion of \"acting on functions\" for relation transformers.\n\nrecord Acts-on-functions\n {F : Structure a b}\n (@0 G : Relation-transformer-for F) :\n Type (lsuc a ⊔ b) where\n field\n -- A map function.\n\n map : (A → B) → F A → F B\n\n -- Mapping the identity function is the same thing as applying the\n -- identity function.\n\n @0 map-id : map {A = A} id ≡ id\n\n -- G respects map in a certain way.\n\n @0 map-map :\n {R₁ : A₁ → B₁ → Type a} {R₂ : A₂ → B₂ → Type a} →\n (∀ {x y} → R₁ x y → R₂ (f x) (g y)) →\n G R₁ x y → G R₂ (map f x) (map g y)\n\n-- Suitable respects equivalences.\n\nSuitable-map :\n {@0 G H : Relation-transformer-for F} →\n @0 (∀ {A B} {R : A → B → _} {x y} → G R x y ≃ H R x y) →\n Suitable G → Suitable H\nSuitable-map {G = G} {H = H} G≃H s-G = λ where\n .Suitable.preserves-is-set → S.preserves-is-set\n\n .Suitable.preserves-is-proposition {R = R} →\n (∀ x y → Is-proposition (R x y)) ↝⟨ S.preserves-is-proposition ⟩\n (∀ x y → Is-proposition (G R x y)) ↝⟨ (∀-cong _ λ _ → ∀-cong _ λ _ → H-level-cong _ 1 G≃H) ⟩□\n (∀ x y → Is-proposition (H R x y)) □\n\n .Suitable.symmetric {R = R} {x = x} {y = y} →\n (∀ x y → Is-proposition (R x y)) ↝⟨ S.symmetric ⟩\n (G R x y → G (R ⁻¹) y x) ↝⟨ →-cong-→ (_≃_.from G≃H) (_≃_.to G≃H) ⟩□\n (H R x y → H (R ⁻¹) y x) □\n\n .Suitable.transitive {R = R} {S = S} {x = x} {y = y} {z = z} → curry\n ((∀ x y → Is-proposition (R x y)) ×\n (∀ x y → Is-proposition (S x y)) ↝⟨ uncurry S.transitive ⟩\n\n (G R x y → G S y z → G (R ;ᴱ S) x z) ↝⟨ →-cong-→ (_≃_.from G≃H) (→-cong-→ (_≃_.from G≃H) (_≃_.to G≃H)) ⟩□\n\n (H R x y → H S y z → H (R ;ᴱ S) x z) □)\n\n .Suitable.descent {x = x} {R = R} prop equiv HRxx → $⟨ [ HRxx ] ⟩\n Erased (H R x x) ↔⟨ Erased-cong (inverse G≃H) ⟩\n Erased (G R x x) ↝⟨ (λ ([ hyp ]) → S.descent prop equiv hyp) ⦂ (_ → _) ⟩\n Contractibleᴱ (∃ λ y → Erased (G (Graph [_]) x y)) ↝⟨ ECP.Contractibleᴱ-cong _ (∃-cong λ _ → Erased-cong G≃H) ⟩□\n Contractibleᴱ (∃ λ y → Erased (H (Graph [_]) x y)) □\n where\n module S = Suitable s-G\n\n-- If R is a propositional QER (with erased proofs) between A and B, G\n-- is a suitable relation transformer for F, and G R x y holds, then\n-- there are structures in F (A /ᴱ R ⟵) and F (B /ᴱ R ⟶) that are\n-- related in a certain way to x and y, respectively, and the two\n-- structures are also related to each other by /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ in a certain\n-- way.\n--\n-- This is a variant of Theorem 5.7 from \"Internalizing Representation\n-- Independence with Univalence\". Note that quite a few inputs are\n-- erased, and also parts of the result.\n\nSuitable→/ᴱ⟵×/ᴱ⟶ :\n {F : Structure a b}\n ((A , x) (B , y) : Type-with F) →\n {@0 R : A → B → Type a}\n {@0 G : Relation-transformer-for F} →\n Suitable G →\n (qer : Is-QERᴱ R)\n (@0 prop : ∀ x y → Is-proposition (R x y)) →\n @0 G R x y →\n ∃ λ (x′ : F (A /ᴱ R ⟵)) → ∃ λ (y′ : F (B /ᴱ R ⟶)) →\n Erased\n (G (Graph [_]) x x′ × G (Graph [_]) y y′ ×\n G (Graph (_≃ᴱ_.to (/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₁))) x′ y′)\nSuitable→/ᴱ⟵×/ᴱ⟶ {F = F} (A , x) (B , y) {R = R} {G = G}\n s qer@([ qper ] , _) prop g =\n x″ , y″ , [ (Gxx″ , Gyy″ , g″) ]\n where\n module S = Suitable s\n\n @0 x∼x : G (R ⟵) x x\n x∼x = S.transitive prop (flip prop) g (S.symmetric prop g)\n\n @0 y∼y : G (R ⟶) y y\n y∼y = S.transitive (flip prop) prop (S.symmetric prop g) g\n\n x-lemma :\n Contractibleᴱ\n (∃ λ (x′ : F (A /ᴱ R ⟵)) → Erased (G (Graph [_]) x x′))\n x-lemma =\n S.descent\n (λ _ _ → T.truncation-is-proposition)\n (Is-QERᴱ→Is-equivalence-relation-⟵ qer)\n x∼x\n\n y-lemma :\n Contractibleᴱ\n (∃ λ (y′ : F (B /ᴱ R ⟶)) → Erased (G (Graph [_]) y y′))\n y-lemma =\n S.descent\n (λ _ _ → T.truncation-is-proposition)\n (Is-QERᴱ→Is-equivalence-relation-⟶ qer)\n y∼y\n\n x″ = x-lemma .proj₁ .proj₁\n y″ = y-lemma .proj₁ .proj₁\n\n @0 Gxx″ : G (Graph [_]) x x″\n Gxx″ = x-lemma .proj₁ .proj₂ .erased\n\n @0 Gyy″ : G (Graph [_]) y y″\n Gyy″ = y-lemma .proj₁ .proj₂ .erased\n\n @0 g′ : G (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) x″ y″\n g′ =\n S.transitive\n (λ _ _ → Q./ᴱ-is-set)\n (λ _ _ → T.truncation-is-proposition)\n (S.symmetric (λ _ _ → Q./ᴱ-is-set) Gxx″)\n (S.transitive prop (λ _ _ → Q./ᴱ-is-set) g Gyy″)\n\n equiv = /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₁\n\n @0 to :\n ∀ {x y} →\n (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) [ x ] [ y ] → R x y\n to {x = x} {y = y} =\n T.rec λ @0 where\n .T.truncation-is-propositionʳ →\n prop _ _\n .T.∣∣ʳ → uncurry λ x′ → uncurry λ [x′]≡[x] →\n T.rec λ @0 where\n .T.truncation-is-propositionʳ →\n prop _ _\n .T.∣∣ʳ (y′ , Rx′y′ , [y′]≡[y]) →\n let R⟵x′x : (R ⟵) x′ x\n R⟵x′x =\n _≃_.from\n (Q.related≃[equal]\n (Is-QERᴱ→Is-equivalence-relation-⟵ qer)\n T.truncation-is-proposition)\n [x′]≡[x]\n\n R⟶y′y : (R ⟶) y′ y\n R⟶y′y =\n _≃_.from\n (Q.related≃[equal]\n (Is-QERᴱ→Is-equivalence-relation-⟶ qer)\n T.truncation-is-proposition)\n [y′]≡[y]\n in\n flip T.rec R⟵x′x λ @0 where\n .T.truncation-is-propositionʳ →\n prop _ _\n .T.∣∣ʳ (_ , Rx′x″ , Rxx″) →\n flip T.rec R⟶y′y λ @0 where\n .T.truncation-is-propositionʳ →\n prop _ _\n .T.∣∣ʳ (_ , Ry″y′ , Ry″y) →\n qper Rxx″ Rx′x″ (qper Rx′y′ Ry″y′ Ry″y)\n\n @0 from :\n ∀ {x y} →\n R x y → (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) [ x ] [ y ]\n from Rxy = ∣ _ , refl _ , ∣ _ , Rxy , refl _ ∣ ∣\n\n @0 lemma :\n ∀ x y →\n (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) x y ≃\n Graph (_≃ᴱ_.to equiv) x y\n lemma = Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ →\n Π-closure ext 1 λ _ →\n Eq.left-closure ext 0 T.truncation-is-proposition\n .Q.[]ʳ x → Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ →\n Eq.left-closure ext 0 T.truncation-is-proposition\n .Q.[]ʳ y →\n (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) [ x ] [ y ] ↝⟨ Eq.⇔→≃ T.truncation-is-proposition (prop _ _) to from ⟩\n R x y ↝⟨ inverse (/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₂ .erased _ _) ⟩□\n Graph (_≃ᴱ_.to equiv) [ x ] [ y ] □\n\n @0 g″ : G (Graph (_≃ᴱ_.to equiv)) x″ y″\n g″ =\n subst (λ R → G R x″ y″)\n (⟨ext⟩ λ x → ⟨ext⟩ λ y →\n ≃⇒≡ U.univ (lemma x y))\n g′\n\n-- If R is a propositional QER (with erased proofs) between A and B, G\n-- is a univalent relation transformer for F, and G R x y holds, then\n-- there are structures x′ : F (A /ᴱ R ⟵) and y′ : F (B /ᴱ R ⟶) that\n-- are related in a certain way to x and y, respectively, and\n-- furthermore the two values A /ᴱ R ⟵ , x′ and B /ᴱ R ⟶ , y′ of type\n-- Type-with F are equal (in erased contexts).\n--\n-- This is a corollary of Suitable→/ᴱ⟵×/ᴱ⟶, /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ and sip.\n\nUnivalentᴿ→/ᴱ⟵×/ᴱ⟶ :\n {F : Structure a b}\n ((A , x) (B , y) : Type-with F) →\n {@0 R : A → B → Type a}\n {@0 G : Relation-transformer-for F} →\n Univalentᴿ G →\n (qer : Is-QERᴱ R)\n (@0 prop : ∀ x y → Is-proposition (R x y)) →\n @0 G R x y →\n ∃ λ (x′ : F (A /ᴱ R ⟵)) → ∃ λ (y′ : F (B /ᴱ R ⟶)) →\n Erased (G (Graph [_]) x x′ × G (Graph [_]) y y′ ×\n _≡_ {A = Type-with F}\n (A /ᴱ R ⟵ , x′) (B /ᴱ R ⟶ , y′))\nUnivalentᴿ→/ᴱ⟵×/ᴱ⟶ (A , x) (B , y) {R = R} {G = G} (s , u) qer prop g =\n let (x′ , y′ , [ x∼x′ , y∼y′ , x′∼y′ ]) =\n Suitable→/ᴱ⟵×/ᴱ⟶ (A , x) (B , y) s qer prop g\n in\n x′\n , y′\n , [ ( x∼x′\n , y∼y′\n , ( $⟨ /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₁ , [ x′∼y′ ] ⟩\n (A /ᴱ R ⟵ , x′)\n ≃[ (λ (A , x) (B , y) eq → G (Graph (_≃ᴱ_.to eq)) x y) ]ᴱ\n (B /ᴱ R ⟶ , y′) ↝⟨ sip u ⟩□\n\n (A /ᴱ R ⟵ , x′) ≡ (B /ᴱ R ⟶ , y′) □)\n )\n ]\n\n-- If G is a suitable relation transformer (for F) that acts on\n-- functions, and R is a propositional equivalence relation on A, then\n-- there is a function from F A /ᴱ G R to F (A /ᴱ R).\n--\n-- This is a variant of Lemma 5.10 from \"Internalizing Representation\n-- Independence with Univalence\". Note that quite a few inputs are\n-- erased.\n\n/ᴱ→/ᴱ :\n {A : Type a}\n {@0 R : A → A → Type a}\n (@0 G : Relation-transformer-for F) →\n Suitable G →\n Acts-on-functions G →\n @0 (∀ x y → Is-proposition (R x y)) →\n @0 Is-equivalence-relation R →\n F A /ᴱ G R → F (A /ᴱ R)\n/ᴱ→/ᴱ {F = F} {R = R} G s acts prop equiv =\n Q.rec λ where\n .Q.[]ʳ → map [_]\n\n .Q.is-setʳ → S.preserves-is-set Q./ᴱ-is-set\n\n .Q.[]-respects-relationʳ {x = x} {y = y} GRxy →\n let GRxx = $⟨ GRxy ⟩\n G R x y ↝⟨ (λ GRxy → S.transitive prop (flip prop) GRxy (S.symmetric prop GRxy)) ⟩\n G (R ⟵) x x ↝⟨ subst (λ R → G R _ _) (⟵≡ prop equiv) ⟩□\n G R x x □\n\n ((z , _) , [ unique ]) = $⟨ GRxx ⟩\n G R x x ↝⟨ (λ GRxx → S.descent prop equiv GRxx) ⦂ (_ → _) ⟩□\n Contractibleᴱ (∃ λ z → Erased (G (Graph [_]) x z)) □\n\n lemma₁ = $⟨ map-map Q.[]-respects-relation GRxx ⟩\n G (Graph [_]) (map id x) (map [_] x) ↝⟨ subst (λ x′ → G (Graph [_]) x′ (map [_] x)) (cong (_$ x) map-id) ⟩□\n G (Graph [_]) x (map [_] x) □\n\n lemma₂ = $⟨ map-map Q.[]-respects-relation GRxy ⟩\n G (Graph [_]) (map id x) (map [_] y) ↝⟨ subst (λ x → G (Graph [_]) x (map [_] y)) (cong (_$ x) map-id) ⟩□\n G (Graph [_]) x (map [_] y) □\n in\n map [_] x ≡⟨ sym $ cong proj₁ (unique (_ , [ lemma₁ ])) ⟩\n z ≡⟨ cong proj₁ (unique (_ , [ lemma₂ ])) ⟩∎\n map [_] y ∎\n where\n module S = Suitable s\n open Acts-on-functions acts\n\n-- Positive relation transformers.\n--\n-- Angiuli et al. define this notion for suitable relation\n-- transformers that act on functions. This definition works for\n-- arbitrary relation transformers G, and instead inludes fields of\n-- type Suitable G and Acts-on-functions G. (In their source code\n-- Angiuli et al. take a third approach, with the property\n-- corresponding to Suitable G as a parameter, and the property\n-- corresponding to Acts-on-functions G as a field.)\n\nrecord Positive\n {F : Structure a b}\n (@0 G : Relation-transformer-for F) :\n Type (lsuc a ⊔ b) where\n field\n -- G is suitable.\n\n suitable : Suitable G\n\n -- G acts on functions.\n\n acts-on-functions : Acts-on-functions G\n\n -- G is reflexive for a certain relation.\n\n @0 reflexive-∥≡∥ᴱ : G (λ x y → ∥ x ≡ y ∥ᴱ) x x\n\n -- The function Suitable.transitive-;ᴱ suitable is an equivalence\n -- (pointwise).\n\n @0 transitive-;ᴱ⁻¹ :\n {R : A → B → Type a} {S : B → C → Type a}\n (R-prop : ∀ x y → Is-proposition (R x y))\n (S-prop : ∀ x y → Is-proposition (S x y))\n (x : F A) (z : F C) →\n Is-equivalence\n (Suitable.transitive-;ᴱ suitable R-prop S-prop x z)\n\n -- The function /ᴱ→/ᴱ G suitable acts-on-functions is an\n -- equivalence with erased proofs (pointwise).\n\n commutes-with-/ᴱ :\n {@0 R : A → A → Type a}\n (@0 prop : ∀ x y → Is-proposition (R x y))\n (@0 equiv : Is-equivalence-relation R) →\n Is-equivalenceᴱ (/ᴱ→/ᴱ G suitable acts-on-functions prop equiv)\n\n -- G R is reflexive for propositional equivalence relations R (in\n -- erased contexts).\n\n @0 reflexive :\n (∀ x y → Is-proposition (R x y)) →\n Is-equivalence-relation R →\n ∀ x → G R x x\n reflexive {R = R} prop equiv x = $⟨ reflexive-∥≡∥ᴱ ⟩\n G (λ x y → ∥ x ≡ y ∥ᴱ) x x ↝⟨ A.map-map\n (T.rec λ @0 where\n .T.truncation-is-propositionʳ →\n prop _ _\n .T.∣∣ʳ x≡y →\n subst (R _) x≡y E.reflexive) ⟩\n G R (A.map id x) (A.map id x) ↝⟨ subst (uncurry (G R)) (cong (λ f → f x , f x) A.map-id) ⟩□\n G R x x □\n where\n module A = Acts-on-functions acts-on-functions\n module E = Is-equivalence-relation equiv\n\n------------------------------------------------------------------------\n-- The Const and Constᴿ combinators, along with some properties\n\n-- Constant structures.\n\nConst : Type b → Structure a b\nConst B = λ _ → B\n\n-- Relation transformers for Const.\n\nConstᴿ : (B : Type b) → Relation-transformer-for (Const {a = a} B)\nConstᴿ _ _ = _≡_\n\n-- When is an equivalence structure-preserving for Const?\n\nIs-Const-equivalence :\n {B : Type b} →\n Structure-preserving-equivalence-predicate (Const {a = a} B) b\nIs-Const-equivalence (_ , x) (_ , y) _ = x ≡ y\n\n-- Const and Is-Const-equivalence are univalent.\n\nConst-univalent : Univalent (Const {a = a} B) Is-Const-equivalence\nConst-univalent {B = B}\n .Univalent.univalent {A = _ , x} {B = _ , y} eq =\n\n x ≡ y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ subst-const _ ⟩□\n subst (Const B) (≃⇒≡ U.abstract-univ (EEq.≃ᴱ→≃ eq)) x ≡ y □\n\n-- Constᴿ is suitable for sets.\n\nConstᴿ-suitable : @0 Is-set B → Suitable (Constᴿ {a = a} B)\nConstᴿ-suitable set = λ where\n .Suitable.preserves-is-set _ → set\n .Suitable.preserves-is-proposition _ _ _ → set\n .Suitable.symmetric _ → sym\n .Suitable.transitive _ _ → trans\n .Suitable.descent _ _ _ → Contractibleᴱ-Erased-other-singleton\n\n-- Constᴿ is univalent for sets.\n\nConstᴿ-univalent : @0 Is-set B → Univalentᴿ (Constᴿ {a = a} B)\nConstᴿ-univalent set = Constᴿ-suitable set , Const-univalent\n\n-- Constᴿ acts on functions.\n\nConstᴿ-acts-on-functions : Acts-on-functions (Constᴿ {a = a} B)\nConstᴿ-acts-on-functions = λ where\n .Acts-on-functions.map _ → id\n .Acts-on-functions.map-id → refl _\n .Acts-on-functions.map-map _ → id\n\n-- Constᴿ is positive for sets.\n\nConstᴿ-positive : @0 Is-set B → Positive (Constᴿ {a = a} B)\nConstᴿ-positive {B = B} set = λ where\n .Positive.suitable → Constᴿ-suitable set\n\n .Positive.acts-on-functions → Constᴿ-acts-on-functions\n\n .Positive.reflexive-∥≡∥ᴱ → refl _\n\n .Positive.transitive-;ᴱ⁻¹ {R = R} {S = S} _ _ x z →\n _≃_.is-equivalence\n ((Constᴿ B R ;ᴱ Constᴿ B S) x z ↔⟨⟩\n ∥ (∃ λ y → x ≡ y × y ≡ z) ∥ᴱ ↝⟨ Eq.⇔→≃ T.truncation-is-proposition set _\n (λ x≡z → ∣ _ , x≡z , refl _ ∣) ⟩\n x ≡ z ↔⟨⟩\n Constᴿ B (R ;ᴱ S) x z □)\n\n .Positive.commutes-with-/ᴱ {A = C} {R = R} prop equiv →\n _≃ᴱ_.is-equivalence $\n EEq.with-other-function\n (Const B C /ᴱ Constᴿ B R ↔⟨⟩\n B /ᴱ _≡_ ↔⟨ Q./ᴱ≡↔ set ⟩\n B ↔⟨⟩\n Const B (C /ᴱ R) □)\n (/ᴱ→/ᴱ (Constᴿ B) (Constᴿ-suitable set) Constᴿ-acts-on-functions\n prop equiv)\n (Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ → set\n .Q.[]ʳ _ → refl _)\n\n------------------------------------------------------------------------\n-- The Id and Idᴿ combinators, along with some properties\n\n-- Identity structures.\n\nId : Structure a a\nId A = A\n\n-- Relation transformers for Id.\n\nIdᴿ : Relation-transformer-for (Id {a = a})\nIdᴿ R = R\n\n-- When is an equivalence structure-preserving for Id?\n\nIs-Id-equivalence : Structure-preserving-equivalence-predicate Id a\nIs-Id-equivalence (_ , x) (_ , y) eq = _≃ᴱ_.to eq x ≡ y\n\n-- Id and Is-Id-equivalence are univalent.\n\nId-univalent : Univalent (Id {a = a}) Is-Id-equivalence\nId-univalent .Univalent.univalent {A = _ , x} {B = _ , y} eq =\n _≃ᴱ_.to eq x ≡ y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ cong (λ eq → _≃_.to eq x) $ sym $\n _≃_.right-inverse-of (≡≃≃ univ) _ ⟩\n ≡⇒→ (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $\n subst-id-in-terms-of-≡⇒↝ equivalence ⟩□\n subst Id (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y □\n where\n univ = U.abstract-univ\n\n-- Idᴿ is suitable.\n\nIdᴿ-suitable : Suitable (Idᴿ {a = a})\nIdᴿ-suitable = λ where\n .Suitable.preserves-is-set → id\n .Suitable.preserves-is-proposition → id\n .Suitable.symmetric _ → id\n .Suitable.transitive _ _ Rxy Syz → ∣ _ , Rxy , Syz ∣\n .Suitable.descent _ _ _ →\n Contractibleᴱ-Erased-other-singleton\n\n-- Idᴿ is univalent.\n\nIdᴿ-univalent : Univalentᴿ (Idᴿ {a = a})\nIdᴿ-univalent = Idᴿ-suitable , Id-univalent\n\n-- Idᴿ acts on functions.\n\nIdᴿ-acts-on-functions : Acts-on-functions (Idᴿ {a = a})\nIdᴿ-acts-on-functions = λ where\n .Acts-on-functions.map → id\n .Acts-on-functions.map-id → refl _\n .Acts-on-functions.map-map f → f\n\n-- Idᴿ is positive.\n\nIdᴿ-positive : Positive (Idᴿ {a = a})\nIdᴿ-positive = λ where\n .Positive.suitable → Idᴿ-suitable\n\n .Positive.acts-on-functions → Idᴿ-acts-on-functions\n\n .Positive.reflexive-∥≡∥ᴱ → ∣ refl _ ∣\n\n .Positive.transitive-;ᴱ⁻¹ {R = R} {S = S} R-prop S-prop x z →\n _≃_.is-equivalence $\n Eq.with-other-function\n ((Idᴿ R ;ᴱ Idᴿ S) x z ↔⟨⟩\n (R ;ᴱ S) x z ↔⟨⟩\n Idᴿ (R ;ᴱ S) x z □)\n (Suitable.transitive-;ᴱ Idᴿ-suitable R-prop S-prop x z)\n (T.elim λ @0 where\n .T.truncation-is-propositionʳ _ →\n H-level.⇒≡ 1 T.truncation-is-proposition\n .T.∣∣ʳ _ →\n refl _)\n\n .Positive.commutes-with-/ᴱ {A = A} {R = R} prop equiv →\n _≃ᴱ_.is-equivalence $\n EEq.with-other-function\n (Id A /ᴱ Idᴿ R ↔⟨⟩\n A /ᴱ R ↔⟨⟩\n Id (A /ᴱ R) □)\n (/ᴱ→/ᴱ Idᴿ Idᴿ-suitable Idᴿ-acts-on-functions prop equiv)\n (Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ → Q./ᴱ-is-set\n .Q.[]ʳ _ → refl _)\n\n------------------------------------------------------------------------\n-- Combinators related to Cartesian products\n\n-- Product structures.\n\nProduct : Structure a b → Structure a c → Structure a (b ⊔ c)\nProduct F G A = F A × G A\n\n-- A combinator that, given relation transformers for F and G,\n-- produces a relation transformer for Product F G.\n\nProductᴿ :\n Relation-transformer-for F →\n Relation-transformer-for G →\n Relation-transformer-for (Product F G)\nProductᴿ S T R = S R ×ᴾ T R\n\n-- When is an equivalence structure-preserving for Product F G?\n\nIs-Product-equivalence :\n Structure-preserving-equivalence-predicate F a →\n Structure-preserving-equivalence-predicate G b →\n Structure-preserving-equivalence-predicate (Product F G) (a ⊔ b)\nIs-Product-equivalence Is-F-eq Is-G-eq (A , x₁ , x₂) (B , y₁ , y₂) eq =\n Is-F-eq (A , x₁) (B , y₁) eq ×\n Is-G-eq (A , x₂) (B , y₂) eq\n\n-- If F and G are univalent, then Product F G is univalent.\n\nProduct-univalent :\n {@0 F : Structure a b}\n {@0 G : Structure a c}\n {@0 Is-F-eq : Structure-preserving-equivalence-predicate F d}\n {@0 Is-G-eq : Structure-preserving-equivalence-predicate G e} →\n @0 Univalent F Is-F-eq →\n @0 Univalent G Is-G-eq →\n Univalent (Product F G) (Is-Product-equivalence Is-F-eq Is-G-eq)\nProduct-univalent\n {F = F} {G = G} {Is-F-eq = Is-F-eq} {Is-G-eq = Is-G-eq}\n u-F u-G .Univalent.univalent {A = A , x₁ , x₂} {B = B , y₁ , y₂} eq =\n\n Is-F-eq (A , x₁) (B , y₁) eq × Is-G-eq (A , x₂) (B , y₂) eq ↝⟨ u-F .Univalent.univalent eq\n ×-cong\n u-G .Univalent.univalent eq ⟩\n subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁ ≡ y₁ ×\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₂ ≡ y₂ ↔⟨ ≡×≡↔≡ ⟩\n\n ( subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁\n , subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₂\n ) ≡ (y₁ , y₂) ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $\n push-subst-, _ _ ⟩□\n subst (Product F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (x₁ , x₂) ≡ (y₁ , y₂) □\n where\n univ = U.abstract-univ\n\n-- If S and T are suitable, then Productᴿ S T is suitable.\n\nProductᴿ-suitable :\n {@0 S : Relation-transformer-for F}\n {@0 T : Relation-transformer-for G} →\n Suitable S →\n Suitable T →\n Suitable (Productᴿ S T)\nProductᴿ-suitable {S = S} {T = T} s-S s-T = λ where\n .Suitable.preserves-is-set set →\n ×-closure 2\n (s-S .Suitable.preserves-is-set set)\n (s-T .Suitable.preserves-is-set set)\n\n .Suitable.preserves-is-proposition prop _ _ →\n ×-closure 1\n (s-S .Suitable.preserves-is-proposition prop _ _)\n (s-T .Suitable.preserves-is-proposition prop _ _)\n\n .Suitable.symmetric prop →\n Σ-map\n (s-S .Suitable.symmetric prop)\n (s-T .Suitable.symmetric prop)\n\n .Suitable.transitive prop₁ prop₂ →\n Σ-zip\n (s-S .Suitable.transitive prop₁ prop₂)\n (s-T .Suitable.transitive prop₁ prop₂)\n\n .Suitable.descent {x = x , y} {R = R} prop equiv (SRxx , Tryy) → $⟨ [ SRxx ] , [ Tryy ] ⟩\n\n Erased (S R x x) × Erased (T R y y) ↝⟨ Σ-map (λ ([ SRxx ]) → s-S .Suitable.descent prop equiv SRxx)\n (λ ([ TRyy ]) → s-T .Suitable.descent prop equiv TRyy) ⟩\n Contractibleᴱ (∃ λ x′ → Erased (S (Graph [_]) x x′)) ×\n Contractibleᴱ (∃ λ y′ → Erased (T (Graph [_]) y y′)) ↝⟨ uncurry ECP.Contractibleᴱ-× ⟩\n\n Contractibleᴱ\n ((∃ λ x′ → Erased (S (Graph [_]) x x′)) ×\n (∃ λ y′ → Erased (T (Graph [_]) y y′))) ↝⟨ ECP.Contractibleᴱ-cong _ $\n Σ-assoc F.∘\n (∃-cong λ _ → ∃-cong λ _ → inverse Erased-Σ↔Σ) F.∘\n (∃-cong λ _ → ∃-comm) F.∘\n inverse Σ-assoc ⟩□\n Contractibleᴱ (∃ λ p → Erased (Productᴿ S T (Graph [_]) (x , y) p)) □\n\n-- If S and T are univalent, then Productᴿ S T is univalent.\n\nProductᴿ-univalent :\n {@0 S : Relation-transformer-for F}\n {@0 T : Relation-transformer-for G} →\n Univalentᴿ S →\n Univalentᴿ T →\n Univalentᴿ (Productᴿ S T)\nProductᴿ-univalent (s-S , u-S) (s-T , u-T) =\n Productᴿ-suitable s-S s-T\n , Product-univalent u-S u-T\n\n-- If S and T act on functions, then Productᴿ S T acts on functions.\n\nProductᴿ-acts-on-functions :\n {@0 S : Relation-transformer-for F}\n {@0 T : Relation-transformer-for G} →\n Acts-on-functions S →\n Acts-on-functions T →\n Acts-on-functions (Productᴿ S T)\nProductᴿ-acts-on-functions {S = S} {T = T} a-S a-T = λ where\n .Acts-on-functions.map f →\n Σ-map (a-S .Acts-on-functions.map f)\n (a-T .Acts-on-functions.map f)\n .Acts-on-functions.map-id →\n Σ-map (a-S .Acts-on-functions.map id)\n (a-T .Acts-on-functions.map id) ≡⟨ cong₂ (λ f g → Σ-map f g)\n (a-S .Acts-on-functions.map-id)\n (a-T .Acts-on-functions.map-id) ⟩\n Σ-map id id ≡⟨⟩\n\n id ∎\n .Acts-on-functions.map-map {f = f} {g = g} {x = x₁ , x₂} {y = y₁ , y₂} {R₁ = R₁} {R₂ = R₂} R₁→R₂ →\n S R₁ x₁ y₁ × T R₁ x₂ y₂ ↝⟨ a-S .Acts-on-functions.map-map R₁→R₂\n ×-cong\n a-T .Acts-on-functions.map-map R₁→R₂ ⟩□\n S R₂ (a-S .Acts-on-functions.map f x₁)\n (a-S .Acts-on-functions.map g y₁) ×\n T R₂ (a-T .Acts-on-functions.map f x₂)\n (a-T .Acts-on-functions.map g y₂) □\n\n-- If S and T are positive, then Productᴿ S T is positive.\n\nProductᴿ-positive :\n {@0 S : Relation-transformer-for F}\n {@0 T : Relation-transformer-for G} →\n Positive S →\n Positive T →\n Positive (Productᴿ S T)\nProductᴿ-positive {F = F} {G = G} {S = S} {T = T} p-S p-T = λ where\n .Positive.suitable → suitable\n\n .Positive.acts-on-functions → acts-on-functions\n\n .Positive.reflexive-∥≡∥ᴱ → SP.reflexive-∥≡∥ᴱ , TP.reflexive-∥≡∥ᴱ\n\n .Positive.transitive-;ᴱ⁻¹\n {R = R₁} {S = R₂} R₁-prop R₂-prop x@(x₁ , x₂) z@(z₁ , z₂) →\n\n _≃_.is-equivalence $\n Eq.with-other-function\n ((Productᴿ S T R₁ ;ᴱ Productᴿ S T R₂) x z ↝⟨ lemma ⟩\n (S R₁ ;ᴱ S R₂) x₁ z₁ × (T R₁ ;ᴱ T R₂) x₂ z₂ ↝⟨ Eq.⟨ _ , SP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩\n ×-cong\n Eq.⟨ _ , TP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩ ⟩\n S (R₁ ;ᴱ R₂) x₁ z₁ × T (R₁ ;ᴱ R₂) x₂ z₂ ↔⟨⟩\n\n Productᴿ S T (R₁ ;ᴱ R₂) x z □)\n _\n (T.elim λ @0 where\n .T.truncation-is-propositionʳ _ →\n H-level.mono₁ 1 $\n ×-closure 1\n (SS.preserves-is-proposition\n (λ _ _ → T.truncation-is-proposition) _ _)\n (TS.preserves-is-proposition\n (λ _ _ → T.truncation-is-proposition) _ _)\n .T.∣∣ʳ _ →\n refl _)\n\n .Positive.commutes-with-/ᴱ {A = A} {R = R} prop equiv →\n _≃ᴱ_.is-equivalence $\n EEq.with-other-function\n (Product F G A /ᴱ Productᴿ S T R ↔⟨⟩\n (F A × G A) /ᴱ Productᴿ S T R ↔⟨ Q.×/ᴱ (SP.reflexive prop equiv _) (TP.reflexive prop equiv _) ⟩\n F A /ᴱ S R × G A /ᴱ T R ↝⟨ EEq.⟨ _ , SP.commutes-with-/ᴱ prop equiv ⟩\n ×-cong\n EEq.⟨ _ , TP.commutes-with-/ᴱ prop equiv ⟩ ⟩\n F (A /ᴱ R) × G (A /ᴱ R) ↔⟨⟩\n Product F G (A /ᴱ R) □)\n _\n (Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ →\n ×-closure 2\n (SS.preserves-is-set Q./ᴱ-is-set)\n (TS.preserves-is-set Q./ᴱ-is-set)\n .Q.[]ʳ _ → refl _)\n where\n module SP = Positive p-S\n module SS = Suitable SP.suitable\n module TP = Positive p-T\n module TS = Suitable TP.suitable\n\n suitable =\n Productᴿ-suitable\n SP.suitable\n TP.suitable\n\n acts-on-functions =\n Productᴿ-acts-on-functions\n SP.acts-on-functions\n TP.acts-on-functions\n\n @0 lemma :\n (Productᴿ S T R₁ ;ᴱ Productᴿ S T R₂) (x₁ , x₂) (z₁ , z₂) ≃\n ((S R₁ ;ᴱ S R₂) x₁ z₁ × (T R₁ ;ᴱ T R₂) x₂ z₂)\n lemma = Eq.⇔→≃\n T.truncation-is-proposition\n (×-closure 1\n T.truncation-is-proposition\n T.truncation-is-proposition)\n (T.rec λ @0 where\n .T.truncation-is-propositionʳ →\n ×-closure 1\n T.truncation-is-proposition\n T.truncation-is-proposition\n .T.∣∣ʳ (_ , (SR₁x₁y₁ , TR₁x₂y₂) , (SR₂y₁z₁ , TR₂y₂z₂)) →\n ∣ _ , SR₁x₁y₁ , SR₂y₁z₁ ∣\n , ∣ _ , TR₁x₂y₂ , TR₂y₂z₂ ∣)\n (uncurry $ T.rec λ @0 where\n .T.truncation-is-propositionʳ →\n Π-closure ext 1 λ _ →\n T.truncation-is-proposition\n .T.∣∣ʳ (_ , SR₁x₁y₁ , SR₂y₁z₁) →\n T.∥∥ᴱ-map\n λ (_ , TR₁x₂y₂ , TR₂y₂z₂) →\n _ , (SR₁x₁y₁ , TR₁x₂y₂) , (SR₂y₁z₁ , TR₂y₂z₂))\n\n------------------------------------------------------------------------\n-- Combinators related to Maybe\n\n-- A combinator that, given a relation transformer for F, produces a\n-- relation transformer for Maybe ∘ F.\n\nMaybeᴿ :\n Relation-transformer-for F →\n Relation-transformer-for (Maybe ∘ F)\nMaybeᴿ = Maybeᴾ ∘_\n\n-- When is an equivalence structure-preserving for Maybe ∘ F?\n\nIs-Maybe-equivalence :\n Structure-preserving-equivalence-predicate F a →\n Structure-preserving-equivalence-predicate (Maybe ∘ F) a\nIs-Maybe-equivalence Is-F-eq = λ where\n (A , nothing) (B , nothing) eq → ↑ _ ⊤\n (A , just x) (B , just y) eq → Is-F-eq (A , x) (B , y) eq\n (A , _) (B , _) eq → ⊥\n\n-- If F is univalent, then Maybe ∘ F is univalent.\n\nMaybe-univalent :\n {@0 F : Structure a b}\n {@0 Is-F-eq : Structure-preserving-equivalence-predicate F c} →\n @0 Univalent F Is-F-eq →\n Univalent (Maybe ∘ F) (Is-Maybe-equivalence Is-F-eq)\nMaybe-univalent\n {F = F} {Is-F-eq = Is-F-eq} u-F .Univalent.univalent\n {A = A , x} {B = B , y} =\n lemma x y\n where\n univ = U.abstract-univ\n\n lemma :\n (x : Maybe (F A)) (y : Maybe (F B)) →\n (eq : A ≃ᴱ B) →\n Is-Maybe-equivalence Is-F-eq (A , x) (B , y) eq ≃\n (subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y)\n lemma nothing nothing eq =\n ↑ _ ⊤ ↔⟨ B.↑↔ ⟩\n\n ⊤ ↔⟨ inverse tt≡tt↔⊤ ⟩\n\n tt ≡ tt ↔⟨ B.≡↔inj₁≡inj₁ ⟩\n\n nothing ≡ nothing ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₁ _ _ ⟩□\n\n subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) nothing ≡ nothing □\n\n lemma nothing (just y) eq =\n ⊥ ↔⟨ ⊥↔⊥ ⟩\n ⊥ ↔⟨ inverse B.≡↔⊎ ⟩\n nothing ≡ just y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₁ _ _ ⟩□\n subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) nothing ≡ just y □\n\n lemma (just x) nothing eq =\n ⊥ ↔⟨ ⊥↔⊥ ⟩\n ⊥ ↔⟨ inverse B.≡↔⊎ ⟩\n just _ ≡ nothing ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₂ _ _ ⟩□\n subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (just x) ≡ nothing □\n\n lemma (just x) (just y) eq =\n Is-F-eq (A , x) (B , y) eq ↝⟨ u-F .Univalent.univalent eq ⟩\n subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y ↔⟨ B.≡↔inj₂≡inj₂ ⟩\n just (subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x) ≡ just y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₂ _ _ ⟩□\n subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (just x) ≡ just y □\n\n-- If G is suitable, then Maybeᴿ G is suitable.\n\nMaybeᴿ-suitable :\n {@0 G : Relation-transformer-for F} →\n Suitable G →\n Suitable (Maybeᴿ G)\nMaybeᴿ-suitable {G = G} s-G = λ where\n .Suitable.preserves-is-set set →\n Maybe-closure 0 (S.preserves-is-set set)\n\n .Suitable.preserves-is-proposition prop → λ @0 where\n nothing nothing →\n H-level.mono₁ 0 $\n ↑-closure 0 ⊤-contractible\n\n nothing (just _) →\n ⊥-propositional\n\n (just _) nothing →\n ⊥-propositional\n\n (just x) (just y) →\n S.preserves-is-proposition prop x y\n\n .Suitable.symmetric {x = nothing} {y = nothing} → _\n .Suitable.symmetric {x = just x} {y = just y} → S.symmetric\n\n .Suitable.transitive {x = nothing} {y = nothing} {z = nothing} → _\n .Suitable.transitive {x = just _} {y = just _} {z = just _} →\n S.transitive\n\n .Suitable.descent {x = nothing} {R = R} prop equiv _ →\n (nothing , [ _ ])\n , [ (λ @0 where\n (nothing , _) → refl _)\n ]\n .Suitable.descent {x = just x} {R = R} prop equiv SRxx →\n $⟨ [ SRxx ] ⟩\n Erased (G R x x) ↝⟨ (λ ([ SRxx ]) → S.descent prop equiv SRxx) ⟩\n Contractibleᴱ (∃ λ y → Erased (G (Graph [_]) x y)) ↝⟨ ECP.Contractibleᴱ-cong _\n (Eq.↔→≃\n (Σ-map just id)\n (λ where\n (nothing , ())\n (just y , s) → y , s)\n (λ where\n (nothing , ())\n (just _ , _) → refl _)\n refl)\n ⦂ (_ → _) ⟩□\n Contractibleᴱ (∃ λ y → Erased (Maybeᴿ G (Graph [_]) (just x) y)) □\n where\n module S = Suitable s-G\n\n-- If G is univalent, then Maybeᴿ G is univalent.\n\nMaybeᴿ-univalent :\n {@0 G : Relation-transformer-for F} →\n Univalentᴿ G →\n Univalentᴿ (Maybeᴿ G)\nMaybeᴿ-univalent {F = F} {G = G} (s-G , u-G) =\n Maybeᴿ-suitable s-G\n , ( $⟨ Maybe-univalent u-G ⟩\n Univalent (Maybe ∘ F)\n (Is-Maybe-equivalence λ (A , x) (B , y) eq →\n G (Graph (_≃ᴱ_.to eq)) x y) ↝⟨ substᴱ (Univalent _)\n (⟨ext⟩ λ p → ⟨ext⟩ λ q → lemma (p .proj₂) (q .proj₂)) ⟩□\n Univalent (Maybe ∘ F)\n (λ (A , x) (B , y) eq → Maybeᴿ G (Graph (_≃ᴱ_.to eq)) x y) □)\n where\n @0 lemma :\n ∀ x y →\n Is-Maybe-equivalence\n (λ (A , x) (B , y) eq → G (Graph (_≃ᴱ_.to eq)) x y)\n (A , x) (B , y) ≡\n (λ eq → Maybeᴿ G (Graph (_≃ᴱ_.to eq)) x y)\n lemma nothing nothing = refl _\n lemma nothing (just _) = refl _\n lemma (just _) nothing = refl _\n lemma (just _) (just _) = refl _\n\n-- If G acts on functions, then Maybeᴿ G acts on functions.\n\nMaybeᴿ-acts-on-functions :\n {@0 G : Relation-transformer-for F} →\n Acts-on-functions G →\n Acts-on-functions (Maybeᴿ G)\nMaybeᴿ-acts-on-functions {G = G} a-G = λ where\n .Acts-on-functions.map f →\n Monad.map (A.map f)\n .Acts-on-functions.map-id →\n Monad.map (A.map id) ≡⟨ cong Monad.map A.map-id ⟩\n Monad.map id ≡⟨ ⟨ext⟩ Monad.map-id ⟩∎\n id ∎\n .Acts-on-functions.map-map {x = nothing} {y = nothing} → _\n .Acts-on-functions.map-map {x = nothing} {y = just _} _ ()\n .Acts-on-functions.map-map {x = just _} {y = nothing} _ ()\n .Acts-on-functions.map-map {x = just _} {y = just _} →\n A.map-map\n where\n module A = Acts-on-functions a-G\n\n-- If G is positive, then Maybeᴿ G is positive.\n\nMaybeᴿ-positive :\n {@0 G : Relation-transformer-for F} →\n Positive G →\n Positive (Maybeᴿ G)\nMaybeᴿ-positive {F = F} {G = G} p-G = λ where\n .Positive.suitable → suitable\n\n .Positive.acts-on-functions → acts-on-functions\n\n .Positive.reflexive-∥≡∥ᴱ {x = nothing} → _\n .Positive.reflexive-∥≡∥ᴱ {x = just _} → SP.reflexive-∥≡∥ᴱ\n\n .Positive.transitive-;ᴱ⁻¹ R₁-prop R₂-prop x z →\n _≃_.is-equivalence $\n Eq.with-other-function\n (lemma R₁-prop R₂-prop x z .proj₁)\n _\n (lemma R₁-prop R₂-prop x z .proj₂)\n\n .Positive.commutes-with-/ᴱ {A = A} {R = R} prop equiv →\n _≃ᴱ_.is-equivalence $\n EEq.with-other-function\n (Maybe (F A) /ᴱ Maybeᴿ G R ↔⟨ Q.Maybe/ᴱ ⟩\n Maybe (F A /ᴱ G R) ↝⟨ F.id ⊎-cong EEq.⟨ _ , SP.commutes-with-/ᴱ prop equiv ⟩ ⟩□\n Maybe (F (A /ᴱ R)) □)\n (/ᴱ→/ᴱ (Maybeᴿ G) suitable acts-on-functions prop equiv)\n (Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ →\n Maybe-closure 0 (SS.preserves-is-set Q./ᴱ-is-set)\n .Q.[]ʳ nothing → refl _\n .Q.[]ʳ (just _) → refl _)\n where\n module SP = Positive p-G\n module SS = Suitable SP.suitable\n\n suitable = Maybeᴿ-suitable SP.suitable\n acts-on-functions = Maybeᴿ-acts-on-functions SP.acts-on-functions\n\n @0 lemma :\n (R₁-prop : ∀ x y → Is-proposition (R₁ x y)) →\n (R₂-prop : ∀ x y → Is-proposition (R₂ x y)) →\n ∀ x z →\n ∃ λ (eq : (Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) x z ≃\n Maybeᴿ G (R₁ ;ᴱ R₂) x z) →\n ∀ p →\n _≃_.to eq p ≡\n Suitable.transitive-;ᴱ suitable R₁-prop R₂-prop x z p\n lemma {R₁ = R₁} {R₂ = R₂} R₁-prop R₂-prop = λ @0 where\n nothing nothing →\n ((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) nothing nothing ↝⟨ Eq.⇔→≃\n T.truncation-is-proposition\n (H-level.mono₁ 0 $ ↑-closure 0 ⊤-contractible)\n _\n (λ _ → ∣ nothing , _ ∣) ⟩□\n ↑ _ ⊤ □)\n , (λ _ → refl _)\n\n nothing (just z) →\n ((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) nothing (just z) ↝⟨ Eq.⇔→≃\n T.truncation-is-proposition\n ⊥-propositional\n (T.rec λ @0 where\n .T.truncation-is-propositionʳ →\n ⊥-propositional\n .T.∣∣ʳ (nothing , _ , ())\n .T.∣∣ʳ (just _ , () , _))\n ⊥-elim ⟩□\n ⊥ □)\n , (T.elim λ @0 where\n .T.truncation-is-propositionʳ _ →\n H-level.⇒≡ 1 $\n ⊥-propositional\n .T.∣∣ʳ (nothing , _ , ())\n .T.∣∣ʳ (just _ , () , _))\n\n (just x) nothing →\n ((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) (just x) nothing ↝⟨ Eq.⇔→≃\n T.truncation-is-proposition\n ⊥-propositional\n (T.rec λ @0 where\n .T.truncation-is-propositionʳ →\n ⊥-propositional\n .T.∣∣ʳ (nothing , () , _)\n .T.∣∣ʳ (just _ , _ , ()))\n ⊥-elim ⟩□\n ⊥ □)\n , (T.elim λ @0 where\n .T.truncation-is-propositionʳ _ →\n H-level.⇒≡ 1 $\n ⊥-propositional\n .T.∣∣ʳ (nothing , () , _)\n .T.∣∣ʳ (just _ , _ , ()))\n\n (just x) (just z) →\n ((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) (just x) (just z) ↝⟨ Eq.⇔→≃\n T.truncation-is-proposition\n T.truncation-is-proposition\n (T.∥∥ᴱ-map λ where\n (nothing , () , ())\n (just _ , p) → _ , p)\n (T.∥∥ᴱ-map (Σ-map just id)) ⟩\n (G R₁ ;ᴱ G R₂) x z ↝⟨ Eq.⟨ _ , SP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩ ⟩□\n G (R₁ ;ᴱ R₂) x z □)\n , (T.elim λ @0 where\n .T.truncation-is-propositionʳ _ →\n H-level.⇒≡ 1 $\n SS.preserves-is-proposition\n (λ _ _ → T.truncation-is-proposition) _ _\n .T.∣∣ʳ (nothing , () , ())\n .T.∣∣ʳ (just _ , _) → refl _)\n\n------------------------------------------------------------------------\n-- The Function and Functionᴿ combinators, along with some properties\n\n-- Function structures.\n\nFunction : Structure a b → Structure a c → Structure a (b ⊔ c)\nFunction F G A = F A → G A\n\n-- A combinator that, given relation transformers for F and G,\n-- produces a relation transformer for Function F G.\n\nFunctionᴿ :\n {F : Structure a b}\n {G : Structure a c} →\n Relation-transformer-for F →\n Relation-transformer-for G →\n Relation-transformer-for (Function F G)\nFunctionᴿ S T R f g = ∀ {x y} → S R x y → T R (f x) (g y)\n\n-- A variant of Functionᴿ ∘ Constᴿ.\n\nFunction-Constᴿ :\n {F : Structure b c}\n (A : Type a) →\n Relation-transformer-for F →\n Relation-transformer-for (Function (Const A) F)\nFunction-Constᴿ A G R f g = (x : A) → G R (f x) (g x)\n\n-- Function-Constᴿ is pointwise equivalent to Functionᴿ ∘ Constᴿ.\n\nFunction-Constᴿ≃Functionᴿ∘Constᴿ :\n {f : A → F B} {g : A → F C}\n (G : Relation-transformer-for F) →\n Function-Constᴿ A G R f g ≃\n (Functionᴿ ∘ Constᴿ) A G R f g\nFunction-Constᴿ≃Functionᴿ∘Constᴿ {R = R} {f = f} {g = g} G =\n (∀ x → G R (f x) (g x)) ↝⟨ (∀-cong ext λ _ → ∀-intro _ ext) ⟩\n (∀ x y → x ≡ y → G R (f x) (g y)) ↔⟨ inverse (∀-cong ext (λ _ → B.implicit-Π↔Π) F.∘ B.implicit-Π↔Π) ⟩□\n (∀ {x y} → x ≡ y → G R (f x) (g y)) □\n\n-- When is an equivalence structure-preserving for Function F G?\n\nIs-Function-equivalence :\n {F : Structure a b} →\n Structure-preserving-equivalence-predicate F c →\n Structure-preserving-equivalence-predicate G d →\n Structure-preserving-equivalence-predicate (Function F G) (b ⊔ c ⊔ d)\nIs-Function-equivalence Is-F-eq Is-G-eq (A , f) (B , g) eq =\n ∀ {x y} → Is-F-eq (A , x) (B , y) eq → Is-G-eq (A , f x) (B , g y) eq\n\n-- A variant of Is-Function-equivalence.\n\nIs-Function-equivalence′ :\n {F : Structure a b} →\n (∀ {A B} → A ≃ᴱ B → F A ≃ᴱ F B) →\n Structure-preserving-equivalence-predicate G c →\n Structure-preserving-equivalence-predicate (Function F G) (b ⊔ c)\nIs-Function-equivalence′ F-cong Is-G-eq (A , f) (B , g) eq =\n ∀ x → Is-G-eq (A , f x) (B , g (_≃ᴱ_.to (F-cong eq) x)) eq\n\n-- If F and G are univalent, then Function F G is univalent.\n\nFunction-univalent :\n {@0 F : Structure a b}\n {@0 G : Structure a c}\n {@0 Is-F-eq : Structure-preserving-equivalence-predicate F d}\n {@0 Is-G-eq : Structure-preserving-equivalence-predicate G e} →\n @0 Univalent F Is-F-eq →\n @0 Univalent G Is-G-eq →\n Univalent (Function F G) (Is-Function-equivalence Is-F-eq Is-G-eq)\nFunction-univalent\n {F = F} {G = G} {Is-F-eq = Is-F-eq} {Is-G-eq = Is-G-eq}\n u-F u-G .Univalent.univalent\n {A = A , f} {B = B , g} eq =\n\n (∀ {x y} → Is-F-eq (A , x) (B , y) eq →\n Is-G-eq (A , f x) (B , g y) eq) ↔⟨ B.implicit-Π↔Π F.∘\n implicit-∀-cong ext B.implicit-Π↔Π ⟩\n (∀ x y → Is-F-eq (A , x) (B , y) eq →\n Is-G-eq (A , f x) (B , g y) eq) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ →\n →-cong ext (u-F .Univalent.univalent eq) (u-G .Univalent.univalent eq)) ⟩\n (∀ x y → subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y →\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g y) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → →-cong₁ ext $\n ≡⇒≃ (cong (_ ≡_) $ _≃_.left-inverse-of (Eq.subst-as-equivalence _ _) _) F.∘\n inverse (Eq.≃-≡ $ inverse $ Eq.subst-as-equivalence _ _) F.∘\n from-bijection ≡-comm) ⟩\n (∀ x y → subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y ≡ x →\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g y) ↔⟨ Π-comm ⟩\n\n (∀ y x → subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y ≡ x →\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g y) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ eq →\n ≡⇒≃ $ cong (_≡ _) $ cong (subst G _) $ cong f $ sym eq) ⟩\n (∀ y x → subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y ≡ x →\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))\n (f (subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y)) ≡\n g y) ↝⟨ (∀-cong ext λ _ → inverse $\n ∀-intro _ ext) ⟩\n (∀ y →\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))\n (f (subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y)) ≡\n g y) ↝⟨ (∀-cong ext λ _ → ≡⇒≃ $ cong (_≡ _) $ sym $\n subst-→) ⟩\n\n (∀ y → subst (Function F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) f y ≡ g y) ↝⟨ Eq.extensionality-isomorphism ext ⟩□\n\n subst (Function F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) f ≡ g □\n where\n univ = U.abstract-univ\n\n-- A variant of Function-univalent that is stated using\n-- Is-Function-equivalence′ instead of Is-Function-equivalence.\n\nFunction-univalent′ :\n {@0 G : Structure a c}\n {@0 Is-G-eq : Structure-preserving-equivalence-predicate G e}\n (@0 F-cong : ∀ {A B} → A ≃ᴱ B → F A ≃ᴱ F B) →\n @0 (∀ {A} (x : F A) → _≃ᴱ_.to (F-cong F.id) x ≡ x) →\n @0 Univalent G Is-G-eq →\n Univalent (Function F G) (Is-Function-equivalence′ F-cong Is-G-eq)\nFunction-univalent′\n {F = F} {G = G} {Is-G-eq = Is-G-eq}\n F-cong F-cong-id u-G .Univalent.univalent\n {A = A , f} {B = B , g} eq =\n\n (∀ x → Is-G-eq (A , f x) (B , g (_≃ᴱ_.to (F-cong eq) x)) eq) ↝⟨ (∀-cong ext λ _ → u-G .Univalent.univalent eq) ⟩\n\n (∀ x →\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g (_≃ᴱ_.to (F-cong eq) x)) ↝⟨ Eq.extensionality-isomorphism ext ⟩\n\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡ g ∘ _≃ᴱ_.to (F-cong eq) ↝⟨ ≡⇒≃ $ cong (subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡_) $\n cong (g ∘_) $ cong _≃ᴱ_.to $ cong F-cong $ sym $\n _≃_.right-inverse-of EEq.≃≃≃ᴱ _ ⟩\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡\n g ∘ _≃ᴱ_.to (F-cong $ EEq.≃→≃ᴱ $ EEq.≃ᴱ→≃ eq) ↝⟨ ≡⇒≃ $ cong (subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡_) $\n cong (g ∘_) $ ⟨ext⟩ $\n transport-theorem\n F (_≃ᴱ_.to ∘ F-cong ∘ EEq.≃→≃ᴱ) F-cong-id univ (EEq.≃ᴱ→≃ eq) ⟩\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡\n g ∘ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ↝⟨ inverse $ Eq.≃-≡ $ →-cong₁ ext $ Eq.subst-as-equivalence _ _ ⟩\n\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ∘\n subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ≡\n g ∘ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘\n subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ↝⟨ ≡⇒≃ $ cong (subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ∘\n subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ≡_) $\n cong (g ∘_) $ ⟨ext⟩ $\n _≃_.right-inverse-of (Eq.subst-as-equivalence _ _) ⟩\n subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ∘\n subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ≡\n g ↝⟨ (≡⇒≃ $ cong (_≡ _) $ sym $ ⟨ext⟩ λ _ →\n subst-→) ⟩□\n subst (Function F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) f ≡ g □\n where\n univ = U.abstract-univ\n\n-- If S is positive and T is suitable, then Functionᴿ S T is suitable.\n--\n-- This is a variant of Theorem 5.12 from \"Internalizing\n-- Representation Independence with Univalence\".\n\nFunctionᴿ-suitable :\n {@0 S : Relation-transformer-for F} →\n {@0 T : Relation-transformer-for G} →\n Positive S →\n Suitable T →\n Suitable (Functionᴿ S T)\nFunctionᴿ-suitable {F = F} {G = G} {S = S} {T = T} p-S s-T = λ where\n .Suitable.preserves-is-set set →\n Π-closure ext 2 λ _ →\n TS.preserves-is-set set\n\n .Suitable.preserves-is-proposition prop _ _ →\n implicit-Π-closure ext 1 λ _ →\n implicit-Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n TS.preserves-is-proposition prop _ _\n\n .Suitable.symmetric\n {R = R} {x = f} {y = g} prop S→T {x = x} {y = y} →\n\n S (R ⁻¹) x y ↝⟨ SS.symmetric (flip prop) ⟩\n S R y x ↝⟨ S→T ⟩\n T R (f y) (g x) ↝⟨ TS.symmetric prop ⟩□\n T (R ⁻¹) (g x) (f y) □\n\n .Suitable.transitive\n {R = R₁} {S = R₂} {x = f} {y = g} {z = h}\n R₁-prop R₂-prop S→T₁ S→T₂ {x = x} {y = y} →\n\n S (R₁ ;ᴱ R₂) x y ↔⟨ inverse Eq.⟨ _ , SP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩ ⟩\n (S R₁ ;ᴱ S R₂) x y ↝⟨ T.∥∥ᴱ-map (Σ-map _ (Σ-map S→T₁ S→T₂)) ⟩\n (T R₁ ;ᴱ T R₂) (f x) (h y) ↝⟨ TS.transitive-;ᴱ R₁-prop R₂-prop _ _ ⟩□\n T (R₁ ;ᴱ R₂) (f x) (h y) □\n\n .Suitable.descent {A = A} {x = f} {R = R} prop equiv S→T →\n let\n d :\n (x : F A) →\n Contractibleᴱ (∃ λ y → Erased (T (Graph [_]) (f x) y))\n d x = TS.descent prop equiv (S→T (SP.reflexive prop equiv x))\n\n g-[] : F A → G (A /ᴱ R)\n g-[] x = d x .proj₁ .proj₁\n\n S→T′ : Erased (S R x y → T (Graph [_]) (f x) (g-[] y))\n S→T′ = λ {x = x} {y = y} →\n [ S R x y ↝⟨ S→T ⟩\n T R (f x) (f y) ↝⟨ flip (TS.transitive prop (λ _ _ → Q./ᴱ-is-set)) (d y .proj₁ .proj₂ .erased) ⟩\n T (R ;ᴱ Graph [_]) (f x) (g-[] y) ↝⟨ subst (λ R → T R (f x) (g-[] y)) (;ᴱ-Graph-[]≡Graph-[] prop equiv) ⟩□\n T (Graph [_]) (f x) (g-[] y) □\n ]\n\n S-[]-map-[] : ∀ {x} → Erased (S (Graph [_]) x (SA.map [_] x))\n S-[]-map-[] = λ {x = x} →\n [ $⟨ SA.map-map Q.[]-respects-relation (SP.reflexive prop equiv x) ⟩\n S (Graph [_]) (SA.map id x) (SA.map [_] x) ↝⟨ subst (λ f → S (Graph (Q.[_] {R = R})) (f x) (SA.map Q.[_] x)) SA.map-id ⟩□\n S (Graph [_]) x (SA.map [_] x) □\n ]\n\n g : F A /ᴱ S R → G (A /ᴱ R)\n g = Q.rec λ where\n .Q.is-setʳ → TS.preserves-is-set Q./ᴱ-is-set\n\n .Q.[]ʳ → g-[]\n\n .Q.[]-respects-relationʳ {x = x} {y = y} SRxy →\n g-[] x ≡⟨ cong proj₁ $\n d x .proj₂ .erased\n (g-[] y , Er.map (_$ SRxy) S→T′) ⟩∎\n g-[] y ∎\n\n h : F A /ᴱ S R ≃ᴱ F (A /ᴱ R)\n h = EEq.⟨ _ , SP.commutes-with-/ᴱ prop equiv ⟩\n in\n ( (F (A /ᴱ R) ↝⟨ _≃ᴱ_.from h ⟩\n F A /ᴱ S R ↝⟨ g ⟩□\n G (A /ᴱ R) □)\n , [ (λ {x = x} {y = y} →\n let\n lemma :\n ∀ y →\n S (Graph [_]) x (_≃ᴱ_.to h y) →\n T (Graph [_]) (f x) (g y)\n lemma = Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ →\n Π-closure ext 1 λ _ →\n TS.preserves-is-proposition\n (λ _ _ → Q./ᴱ-is-set) _ _\n .Q.[]ʳ y →\n let\n s = $⟨ S-[]-map-[] .erased ⟩\n S (Graph [_]) y (SA.map [_] y) ↝⟨ SS.symmetric (λ _ _ → Q./ᴱ-is-set) ⟩□\n S (Graph [_] ⁻¹) (SA.map [_] y) y □\n in\n S (Graph [_]) x (SA.map [_] y) ↝⟨ flip (SS.transitive (λ _ _ → Q./ᴱ-is-set) λ _ _ → Q./ᴱ-is-set) s ⟩\n S (Graph [_] ⟵) x y ↝⟨ subst (λ R → S R x y) (Graph-[]-⟵≡ prop equiv) ⟩\n S R x y ↝⟨ S→T′ .erased ⟩□\n T (Graph [_]) (f x) (g-[] y) □\n in\n S (Graph [_]) x y ↝⟨ subst (S (Graph [_]) x) (sym $ _≃ᴱ_.right-inverse-of h _) ⟩\n S (Graph [_]) x (_≃ᴱ_.to h (_≃ᴱ_.from h y)) ↝⟨ lemma (_≃ᴱ_.from h y) ⟩□\n T (Graph [_]) (f x) (g (_≃ᴱ_.from h y)) □)\n ]\n )\n , [ (λ (g′ , [ g′-hyp ]) →\n let\n lemma : ∀ y → g y ≡ g′ (_≃ᴱ_.to h y)\n lemma = Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ →\n TS.preserves-is-set Q./ᴱ-is-set\n .Q.[]ʳ y →\n g-[] y ≡⟨ cong proj₁ $\n d y .proj₂ .erased\n ( g′ (SA.map [_] y)\n , [\n $⟨ S-[]-map-[] .erased ⟩\n S (Graph [_]) y (SA.map [_] y) ↝⟨ g′-hyp ⟩□\n T (Graph [_]) (f y) (g′ (SA.map [_] y)) □\n ]\n ) ⟩∎\n g′ (SA.map [_] y) ∎\n in\n Σ-≡,≡→≡\n (⟨ext⟩ λ x →\n g (_≃ᴱ_.from h x) ≡⟨ lemma (_≃ᴱ_.from h x) ⟩\n g′ (_≃ᴱ_.to h (_≃ᴱ_.from h x)) ≡⟨ cong g′ $ _≃ᴱ_.right-inverse-of h _ ⟩∎\n g′ x ∎)\n (H-level-Erased 1\n (implicit-Π-closure ext 1 λ _ →\n implicit-Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n TS.preserves-is-proposition (λ _ _ → Q./ᴱ-is-set) _ _)\n _ _))\n ]\n where\n module SP = Positive p-S\n module SA = Acts-on-functions SP.acts-on-functions\n module SS = Suitable SP.suitable\n module TS = Suitable s-T\n\n-- If A is a set and G is suitable, then Function-Constᴿ A G is\n-- suitable.\n\nFunction-Constᴿ-suitable :\n {@0 G : Relation-transformer-for F} →\n @0 Is-set A →\n Suitable G →\n Suitable (Function-Constᴿ A G)\nFunction-Constᴿ-suitable {F = F} {A = A} {G = G} set =\n Suitable G ↝⟨ Functionᴿ-suitable (Constᴿ-positive set) ⟩\n Suitable (Functionᴿ (Constᴿ A) G) ↝⟨ Suitable-map (inverse $ Function-Constᴿ≃Functionᴿ∘Constᴿ G) ⟩□\n Suitable (Function-Constᴿ A G) □\n\n-- If S is positive and univalent, and T is univalent, then\n-- Functionᴿ S T is univalent.\n\nFunctionᴿ-univalent :\n {@0 S : Relation-transformer-for F}\n {@0 T : Relation-transformer-for G} →\n Positive S →\n Univalentᴿ S →\n Univalentᴿ T →\n Univalentᴿ (Functionᴿ S T)\nFunctionᴿ-univalent p-S (_ , u-S) (s-T , u-T) =\n Functionᴿ-suitable p-S s-T\n , Function-univalent u-S u-T\n\n-- If A is a set and G is univalent, then Function-Constᴿ A G is\n-- univalent.\n\nFunction-Constᴿ-univalent :\n {@0 G : Relation-transformer-for F} →\n @0 Is-set A →\n Univalentᴿ G →\n Univalentᴿ (Function-Constᴿ A G)\nFunction-Constᴿ-univalent set (s-G , u-G) =\n Function-Constᴿ-suitable set s-G\n , Function-univalent′ (λ _ → F.id) refl u-G\n\n------------------------------------------------------------------------\n-- Combinators related to Erased\n\n-- A combinator that, given a relation transformer for F, produces a\n-- relation transformer for λ A → Erased (F A).\n--\n-- Note that I have not proved that Erasedᴿ G is positive if G is\n-- positive.\n\nErasedᴿ :\n {@0 F : Structure a b} →\n @0 Relation-transformer-for F →\n Relation-transformer-for (λ A → Erased (F A))\nErasedᴿ G R = Erasedᴾ (G R)\n\n-- When is an equivalence structure-preserving for λ A → Erased (F A)?\n\nIs-Erased-equivalence :\n @0 Structure-preserving-equivalence-predicate F a →\n Structure-preserving-equivalence-predicate (λ A → Erased (F A)) a\nIs-Erased-equivalence Is-F-eq (_ , [ x ]) (_ , [ y ]) eq =\n Erased (Is-F-eq (_ , x) (_ , y) eq)\n\n-- If F is univalent, then λ A → Erased (F A) is univalent.\n\nErased-univalent :\n {@0 F : Structure a b}\n {@0 Is-F-eq : Structure-preserving-equivalence-predicate F c} →\n @0 Univalent F Is-F-eq →\n Univalent (λ A → Erased (F A)) (Is-Erased-equivalence Is-F-eq)\nErased-univalent\n {F = F} {Is-F-eq = Is-F-eq} u-F .Univalent.univalent\n {A = A , [ x ]} {B = B , [ y ]} eq =\n\n Erased (Is-F-eq (A , x) (B , y) eq) ↝⟨ Erased-cong (u-F .Univalent.univalent eq) ⟩\n\n Erased (subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y) ↔⟨ Erased-≡↔[]≡[] ⟩\n\n [ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ] ≡ [ y ] ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym push-subst-[] ⟩□\n\n subst (λ A → Erased (F A)) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) [ x ] ≡ [ y ] □\n where\n univ = U.abstract-univ\n\n-- If G is suitable, then Erasedᴿ G is suitable.\n\nErasedᴿ-suitable :\n {@0 G : Relation-transformer-for F} →\n @0 Suitable G →\n Suitable (Erasedᴿ G)\nErasedᴿ-suitable {G = G} s-G = λ where\n .Suitable.preserves-is-set set →\n H-level-Erased 2 (s-G .Suitable.preserves-is-set set)\n\n .Suitable.preserves-is-proposition prop _ _ →\n H-level-Erased 1 (s-G .Suitable.preserves-is-proposition prop _ _)\n\n .Suitable.symmetric prop →\n Er.map (s-G .Suitable.symmetric prop)\n\n .Suitable.transitive R-prop S-prop [ GRxy ] [ GSyz ] →\n [ s-G .Suitable.transitive R-prop S-prop GRxy GSyz ]\n\n .Suitable.descent {x = [ x ]} {R = R} prop equiv [GRxx] → $⟨ [ [GRxx] .erased ] ⟩\n Erased (G R x x) ↝⟨ Er.map (λ GRxx → s-G .Suitable.descent prop equiv GRxx) ⟩\n Erased (Contractibleᴱ (∃ λ y → Erased (G (Graph [_]) x y))) ↝⟨ ECP.Erased-Contractibleᴱ↔Contractibleᴱ-Erased _ ⟩\n Contractibleᴱ (Erased (∃ λ y → Erased (G (Graph [_]) x y))) ↝⟨ ECP.Contractibleᴱ-cong _ Erased-Σ↔Σ ⟩\n Contractibleᴱ (∃ λ ([ y ]) → Erased (Erased (G (Graph [_]) x y))) ↔⟨⟩\n Contractibleᴱ (∃ λ y → Erased (Erasedᴿ G (Graph [_]) [ x ] y)) □\n\n-- If G is univalent, then Erasedᴿ G is univalent.\n\nErasedᴿ-univalent :\n {@0 G : Relation-transformer-for F} →\n @0 Univalentᴿ G →\n Univalentᴿ (Erasedᴿ G)\nErasedᴿ-univalent (s-G , u-G) =\n Erasedᴿ-suitable s-G\n , Erased-univalent u-G\n\n-- If G acts on functions, then Erasedᴿ G acts on functions.\n\nErasedᴿ-acts-on-functions :\n {@0 G : Relation-transformer-for F} →\n @0 Acts-on-functions G →\n Acts-on-functions (Erasedᴿ G)\nErasedᴿ-acts-on-functions {G = G} a-G = λ where\n .Acts-on-functions.map f →\n Er.map (a-G .Acts-on-functions.map f)\n .Acts-on-functions.map-id →\n Er.map (a-G .Acts-on-functions.map id) ≡⟨ cong (λ f → Er.map f) (a-G .Acts-on-functions.map-id) ⟩\n Er.map id ≡⟨⟩\n id ∎\n .Acts-on-functions.map-map\n {f = f} {g = g} {x = [ x ]} {y = [ y ]} {R₁ = R₁} {R₂ = R₂} R₁→R₂ →\n\n Erased (G R₁ x y) ↝⟨ Er.map (a-G .Acts-on-functions.map-map R₁→R₂) ⟩□\n\n Erased (G R₂ (a-G .Acts-on-functions.map f x)\n (a-G .Acts-on-functions.map g y)) □\n\n------------------------------------------------------------------------\n-- An example: monoids\n\n-- This is a variant of Examples 3.5 and 3.6 from \"Internalizing\n-- Representation Independence with Univalence\".\n\nmodule Example₁ where\n\n -- Raw monoid structures.\n\n Raw-monoid-structure : Structure a a\n Raw-monoid-structure A = A × (A → A → A)\n\n -- Raw-monoid-structure can be expressed using some combinators.\n\n _ :\n Raw-monoid-structure {a = a} ≡\n Product Id (Function Id (Function Id Id))\n _ = refl _\n\n -- Raw monoids, i.e., monoids without the monoid laws.\n\n Raw-monoid : (a : Level) → Type (lsuc a)\n Raw-monoid _ = Type-with Raw-monoid-structure\n\n -- Raw monoid equivalence predicates.\n\n Is-raw-monoid-equivalence :\n Structure-preserving-equivalence-predicate Raw-monoid-structure a\n Is-raw-monoid-equivalence (_ , id₁ , _∘₁_) (_ , id₂ , _∘₂_) eq =\n _≃ᴱ_.to eq id₁ ≡ id₂ ×\n (∀ x y → _≃ᴱ_.to eq (x ∘₁ y) ≡ _≃ᴱ_.to eq x ∘₂ _≃ᴱ_.to eq y)\n\n -- Is-raw-monoid-equivalence can be expressed using some\n -- combinators.\n\n _ :\n Is-raw-monoid-equivalence {a = a} ≡\n Is-Product-equivalence\n Is-Id-equivalence\n (Is-Function-equivalence′ id\n (Is-Function-equivalence′ id\n Is-Id-equivalence))\n _ = refl _\n\n -- Raw monoid equivalences (with erased proofs).\n\n infix 4 _≃ᴿᴹᴱ_\n\n _≃ᴿᴹᴱ_ : Raw-monoid a → Raw-monoid a → Type a\n _≃ᴿᴹᴱ_ = _≃[ Is-raw-monoid-equivalence ]ᴱ_\n\n -- The combination of Raw-monoid-structure and\n -- Is-raw-monoid-equivalence is univalent (in erased settings).\n\n Is-raw-monoid-equivalence-univalent :\n Univalent (Raw-monoid-structure {a = a}) Is-raw-monoid-equivalence\n Is-raw-monoid-equivalence-univalent =\n Product-univalent\n Id-univalent\n (Function-univalent′ id refl\n (Function-univalent′ id refl\n Id-univalent))\n\n -- The monoid laws.\n\n Monoid-laws : Axioms Raw-monoid-structure a\n Monoid-laws (A , id , _∘_) =\n Is-set A ×\n (∀ x → id ∘ x ≡ x) ×\n (∀ x → x ∘ id ≡ x) ×\n (∀ x y z → x ∘ (y ∘ z) ≡ (x ∘ y) ∘ z)\n\n -- The monoid laws are propositional.\n\n Monoid-laws-propositional :\n (M : Raw-monoid a) → Is-proposition (Monoid-laws M)\n Monoid-laws-propositional (A , id , _∘_) =\n Σ-closure 1 (H-level-propositional ext 2) λ A-set →\n ×-closure 1 (Π-closure ext 1 λ _ → A-set) $\n ×-closure 1 (Π-closure ext 1 λ _ → A-set) $\n Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ →\n A-set\n\n -- Monoid structures.\n\n Monoid-structure : Structure a a\n Monoid-structure =\n Raw-monoid-structure With-the-axioms Monoid-laws\n\n -- Monoids.\n\n Monoid : (a : Level) → Type (lsuc a)\n Monoid _ = Type-with Monoid-structure\n\n -- Monoid equivalence predicates.\n\n Is-monoid-equivalence :\n Structure-preserving-equivalence-predicate Monoid-structure a\n Is-monoid-equivalence = Lift-With-the-axioms Is-raw-monoid-equivalence\n\n -- Monoid equivalences (with erased proofs).\n\n infix 4 _≃ᴹᴱ_\n\n _≃ᴹᴱ_ : Monoid a → Monoid a → Type a\n _≃ᴹᴱ_ = _≃[ Is-monoid-equivalence ]ᴱ_\n\n -- The combination of Monoid-structure and Is-monoid-equivalence is\n -- univalent (in erased settings).\n\n Is-monoid-equivalence-univalent :\n Univalent (Monoid-structure {a = a}) Is-monoid-equivalence\n Is-monoid-equivalence-univalent =\n Univalent-With-the-axioms\n Monoid-laws-propositional\n Is-raw-monoid-equivalence-univalent\n\n -- The structure identity principle for monoids.\n\n @0 sip-for-monoids : (M ≃ᴹᴱ N) ≃ (M ≡ N)\n sip-for-monoids = sip Is-monoid-equivalence-univalent\n\n -- If a raw monoid M₂ is equivalent (with erased proofs) to the\n -- underlying raw monoid of a monoid M₁, then the monoid laws hold\n -- for M₂ (in erased contexts), and M₁ is equivalent (with erased\n -- proofs) to the monoid constructed from M₂ and the laws.\n\n induced-monoid :\n (M₁@(A₁ , ops₁ , _) : Monoid a)\n (M₂@(A₂ , ops₂) : Raw-monoid a) →\n (A₁ , ops₁) ≃ᴿᴹᴱ M₂ →\n ∃ λ (l₂ : Erased (Monoid-laws M₂)) → M₁ ≃ᴹᴱ (A₂ , ops₂ , l₂)\n induced-monoid =\n induced-structures Is-raw-monoid-equivalence-univalent\n\n -- The unary natural numbers form a monoid.\n\n ℕ-monoid : Monoid lzero\n ℕ-monoid =\n ℕ\n , (0 , _+_)\n , [ ( ℕ-set\n , refl\n , (λ _ → Nat.+-right-identity)\n , (λ m _ _ → Nat.+-assoc m)\n )\n ]\n\n -- One variant of binary natural numbers forms a raw monoid.\n\n Bin-raw-monoid : Raw-monoid lzero\n Bin-raw-monoid =\n Bin\n , Bin.Operations-for-Bin.zero\n , Bin.Operations-for-Bin._+_\n\n -- The raw monoid underlying ℕ-monoid is equivalent (with erased\n -- proofs) to Bin-raw-monoid.\n\n ℕ≃ᴿᴹᴱBin : (ℕ , (0 , _+_)) ≃ᴿᴹᴱ Bin-raw-monoid\n ℕ≃ᴿᴹᴱBin =\n (ℕ ↔⟨ inverse Bin.Bin↔ℕ ⟩□\n Bin □)\n , [ ( (_↔_.from Bin.Bin↔ℕ 0 ≡⟨ _↔_.to Bin.≡-for-indices↔≡ [ refl _ ] ⟩∎\n Bin.Operations-for-Bin.zero ∎)\n , (λ m n →\n _↔_.from Bin.Bin↔ℕ (m + n) ≡⟨ _↔_.to Bin.≡-for-indices↔≡ [ refl _ ] ⟩∎\n\n _↔_.from Bin.Bin↔ℕ m Bin.Operations-for-Bin.+\n _↔_.from Bin.Bin↔ℕ n ∎)\n )\n ]\n\n -- The monoid laws hold for Bin-raw-monoid (in erased contexts).\n\n @0 Bin-monoid-laws : Monoid-laws Bin-raw-monoid\n Bin-monoid-laws =\n induced-monoid ℕ-monoid Bin-raw-monoid ℕ≃ᴿᴹᴱBin .proj₁ .erased\n\n -- One variant of binary natural numbers forms a monoid.\n\n Bin-monoid : Monoid lzero\n Bin-monoid =\n Bin-raw-monoid .proj₁ , Bin-raw-monoid .proj₂ , [ Bin-monoid-laws ]\n\n -- This monoid is equivalent, with erased proofs, to ℕ-monoid.\n\n ℕ≃ᴹᴱBin : ℕ-monoid ≃ᴹᴱ Bin-monoid\n ℕ≃ᴹᴱBin =\n induced-monoid ℕ-monoid Bin-raw-monoid ℕ≃ᴿᴹᴱBin .proj₂\n\n -- In erased contexts the monoid is equal to ℕ-monoid.\n\n @0 ℕ≡Bin : ℕ-monoid ≡ Bin-monoid\n ℕ≡Bin = _≃_.to sip-for-monoids ℕ≃ᴹᴱBin\n\n------------------------------------------------------------------------\n-- Another example: bags\n\n-- This is a variant of Examples 5.5 and 5.13 from \"Internalizing\n-- Representation Independence with Univalence\".\n\n-- The type A is assumed to come with decidable equality.\n\nmodule Example₂ {A : Type a} (_≟_ : Decidable-equality A) where\n\n private\n\n -- The type A is a set.\n\n set : Is-set A\n set = decidable⇒set _≟_\n\n -- Raw bag structures.\n\n Raw-bag-structure : Structure a a\n Raw-bag-structure Bag =\n -- An empty bag.\n Bag ×\n -- Insertion.\n (A → Bag → Bag) ×\n -- Union.\n (Bag → Bag → Bag) ×\n -- The number of occurrences of the given element in the given\n -- bag.\n (A → Bag → ℕ)\n\n -- Raw-bag-structure can be expressed using some combinators.\n\n _ :\n Raw-bag-structure ≡\n Product Id\n (Product (Function (Const A) (Function Id Id))\n (Product (Function Id (Function Id Id))\n (Function (Const A) (Function Id (Const ℕ)))))\n _ = refl _\n\n -- Raw bag types.\n\n Raw-bag-type : Type (lsuc a)\n Raw-bag-type = Type-with Raw-bag-structure\n\n -- Raw bag equivalence predicates.\n\n Is-raw-bag-equivalence :\n Structure-preserving-equivalence-predicate Raw-bag-structure a\n Is-raw-bag-equivalence\n (_ , empty₁ , insert₁ , union₁ , count₁)\n (_ , empty₂ , insert₂ , union₂ , count₂)\n eq =\n _≃ᴱ_.to eq empty₁ ≡ empty₂ ×\n (∀ x xs → _≃ᴱ_.to eq (insert₁ x xs) ≡ insert₂ x (_≃ᴱ_.to eq xs)) ×\n (∀ xs ys →\n _≃ᴱ_.to eq (union₁ xs ys) ≡\n union₂ (_≃ᴱ_.to eq xs) (_≃ᴱ_.to eq ys)) ×\n (∀ x xs → count₁ x xs ≡ count₂ x (_≃ᴱ_.to eq xs))\n\n -- Is-raw-bag-equivalence can be expressed using some combinators.\n\n _ :\n Is-raw-bag-equivalence ≡\n Is-Product-equivalence\n Is-Id-equivalence\n (Is-Product-equivalence\n (Is-Function-equivalence′ (λ _ → EEq.id)\n (Is-Function-equivalence′ id\n Is-Id-equivalence))\n (Is-Product-equivalence\n (Is-Function-equivalence′ id\n (Is-Function-equivalence′ id\n Is-Id-equivalence))\n (Is-Function-equivalence′ (λ _ → EEq.id)\n (Is-Function-equivalence′ id\n Is-Const-equivalence))))\n _ = refl _\n\n -- Raw bag equivalences (with erased proofs).\n\n infix 4 _≃ᴮᴱ_\n\n _≃ᴮᴱ_ : Raw-bag-type → Raw-bag-type → Type a\n _≃ᴮᴱ_ = _≃[ Is-raw-bag-equivalence ]ᴱ_\n\n -- Relation transformers for raw bag types.\n\n Raw-bag-typeᴿ : Relation-transformer-for Raw-bag-structure\n Raw-bag-typeᴿ =\n Productᴿ Idᴿ\n (Productᴿ (Function-Constᴿ A (Functionᴿ Idᴿ Idᴿ))\n (Productᴿ (Functionᴿ Idᴿ (Functionᴿ Idᴿ Idᴿ))\n (Function-Constᴿ A (Functionᴿ Idᴿ (Constᴿ ℕ)))))\n\n -- Raw-bag-typeᴿ is univalent.\n\n Raw-bag-typeᴿ-univalent : Univalentᴿ Raw-bag-typeᴿ\n Raw-bag-typeᴿ-univalent =\n Productᴿ-univalent Idᴿ-univalent\n (Productᴿ-univalent\n (Function-Constᴿ-univalent set\n (Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent\n Idᴿ-univalent))\n (Productᴿ-univalent\n (Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent\n (Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent\n Idᴿ-univalent))\n (Function-Constᴿ-univalent set\n (Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent\n (Constᴿ-univalent ℕ-set)))))\n\n -- One implementation of bags.\n\n List-bag : Type a\n List-bag = List A\n\n count₁′ : A → A → ℕ\n count₁′ x y = if x ≟ y then 1 else 0\n\n count₁ : A → List-bag → ℕ\n count₁ x = L.foldr (λ y → count₁′ x y +_) 0\n\n Raw-bag-structure-List-bag : Raw-bag-structure List-bag\n Raw-bag-structure-List-bag =\n []\n , _∷_\n , L._++_\n , count₁\n\n Raw-bag-type-List-bag : Raw-bag-type\n Raw-bag-type-List-bag = List-bag , Raw-bag-structure-List-bag\n\n -- Another implementation of bags.\n\n Assoc-list-bag : Type a\n Assoc-list-bag = List (ℕ × A)\n\n insert : ℕ → A → Assoc-list-bag → Assoc-list-bag\n insert m x [] = (m , x) ∷ []\n insert m x ((n , y) ∷ ys) =\n if x ≟ y\n then (m + n , y) ∷ ys\n else (n , y) ∷ insert m x ys\n\n union : Assoc-list-bag → Assoc-list-bag → Assoc-list-bag\n union = flip (L.foldr (uncurry insert))\n\n count₂′ : A → ℕ × A → ℕ\n count₂′ x (n , y) = if x ≟ y then n else 0\n\n count₂ : A → Assoc-list-bag → ℕ\n count₂ x = L.foldr (λ y → count₂′ x y +_) 0\n\n Raw-bag-structure-Assoc-list-bag : Raw-bag-structure Assoc-list-bag\n Raw-bag-structure-Assoc-list-bag =\n []\n , insert 1\n , union\n , count₂\n\n Raw-bag-type-Assoc-list-bag : Raw-bag-type\n Raw-bag-type-Assoc-list-bag =\n Assoc-list-bag , Raw-bag-structure-Assoc-list-bag\n\n -- Some properties of count₁.\n\n count₁-++ :\n ∀ xs → count₁ z (xs L.++ ys) ≡ count₁ z xs + count₁ z ys\n count₁-++ [] = refl _\n count₁-++ {z = z} {ys = ys} (x ∷ xs) =\n count₁′ z x + (count₁ z (xs L.++ ys)) ≡⟨ cong (count₁′ z x +_) $ count₁-++ xs ⟩\n count₁′ z x + (count₁ z xs + count₁ z ys) ≡⟨ Nat.+-assoc (count₁′ z x) ⟩∎\n (count₁′ z x + count₁ z xs) + count₁ z ys ∎\n\n count₁-replicate :\n ∀ n → count₁ z (L.replicate n y) ≡ count₂′ z (n , y)\n count₁-replicate {z = z} {y = y} zero with z ≟ y\n … | yes _ = refl _\n … | no _ = refl _\n count₁-replicate {z = z} {y = y} (suc n) =\n count₁′ z y + count₁ z (L.replicate n y) ≡⟨ cong (count₁′ z y +_) $ count₁-replicate n ⟩\n count₁′ z y + count₂′ z (n , y) ≡⟨ lemma ⟩∎\n count₂′ z (suc n , y) ∎\n where\n lemma : count₁′ z y + count₂′ z (n , y) ≡ count₂′ z (suc n , y)\n lemma with z ≟ y\n … | yes _ = refl _\n … | no _ = refl _\n\n -- Some properties of count₂.\n\n count₂-insert-≡ :\n z ≡ x → ∀ ys → count₂ z (insert m x ys) ≡ m + count₂ z ys\n count₂-insert-≡ {z = z} {x = x} {m = m} z≡x = helper\n where\n helper : ∀ ys → count₂ z (insert m x ys) ≡ m + count₂ z ys\n helper [] with z ≟ x\n … | yes _ = m + 0 ∎\n … | no z≢x = ⊥-elim $ z≢x z≡x\n helper ((n , y) ∷ ys) with x ≟ y\n helper ((n , y) ∷ ys) | no x≢y =\n count₂′ z (n , y) + count₂ z (insert m x ys) ≡⟨ cong (count₂′ z (n , y) +_) $ helper ys ⟩\n count₂′ z (n , y) + (m + count₂ z ys) ≡⟨ Nat.+-assoc (count₂′ z (n , y)) ⟩\n (count₂′ z (n , y) + m) + count₂ z ys ≡⟨ cong (_+ count₂ z ys) $ sym $ Nat.+-comm m ⟩\n (m + count₂′ z (n , y)) + count₂ z ys ≡⟨ sym $ Nat.+-assoc m ⟩∎\n m + (count₂′ z (n , y) + count₂ z ys) ∎\n helper ((n , y) ∷ ys) | yes x≡y =\n count₂′ z (m + n , y) + count₂ z ys ≡⟨ cong (_+ _) lemma ⟩\n (m + count₂′ z (n , y)) + count₂ z ys ≡⟨ sym $ Nat.+-assoc m ⟩∎\n m + (count₂′ z (n , y) + count₂ z ys) ∎\n where\n lemma : count₂′ z (m + n , y) ≡ m + count₂′ z (n , y)\n lemma with z ≟ y\n … | yes _ = m + n ∎\n … | no z≢y = ⊥-elim $ z≢y (trans z≡x x≡y)\n\n count₂-insert-≢ :\n z ≢ x → ∀ ys → count₂ z (insert m x ys) ≡ count₂ z ys\n count₂-insert-≢ {z = z} {x = x} {m = m} z≢x = helper\n where\n helper : ∀ ys → count₂ z (insert m x ys) ≡ count₂ z ys\n helper [] with z ≟ x\n … | no _ = 0 ∎\n … | yes z≡x = ⊥-elim $ z≢x z≡x\n helper ((n , y) ∷ ys) with x ≟ y\n … | no _ =\n count₂′ z (n , y) + count₂ z (insert m x ys) ≡⟨ cong (count₂′ z (n , y) +_) $ helper ys ⟩∎\n count₂′ z (n , y) + count₂ z ys ∎\n … | yes x≡y =\n count₂′ z (m + n , y) + count₂ z ys ≡⟨ cong (_+ _) lemma ⟩∎\n count₂′ z ( n , y) + count₂ z ys ∎\n where\n lemma : count₂′ z (m + n , y) ≡ count₂′ z (n , y)\n lemma with z ≟ y\n … | no _ = 0 ∎\n … | yes z≡y = ⊥-elim $ z≢x (trans z≡y (sym x≡y))\n\n count₂-insert :\n ∀ ys → count₂ z (insert m x ys) ≡ count₂′ z (m , x) + count₂ z ys\n count₂-insert {z = z} {m = m} {x = x} ys with z ≟ x\n … | yes z≡x =\n count₂ z (insert m x ys) ≡⟨ count₂-insert-≡ z≡x ys ⟩∎\n m + count₂ z ys ∎\n … | no z≢x =\n count₂ z (insert m x ys) ≡⟨ count₂-insert-≢ z≢x ys ⟩∎\n count₂ z ys ∎\n\n count₂-union :\n ∀ xs → count₂ z (union xs ys) ≡ count₂ z xs + count₂ z ys\n count₂-union {z = z} {ys = ys} [] =\n count₂ z ys ∎\n count₂-union {z = z} {ys = ys} ((m , x) ∷ xs) =\n count₂ z (insert m x (union xs ys)) ≡⟨ count₂-insert (union xs ys) ⟩\n count₂′ z (m , x) + count₂ z (union xs ys) ≡⟨ cong (count₂′ z (m , x) +_) $ count₂-union xs ⟩\n count₂′ z (m , x) + (count₂ z xs + count₂ z ys) ≡⟨ Nat.+-assoc (count₂′ z (m , x)) ⟩∎\n (count₂′ z (m , x) + count₂ z xs) + count₂ z ys ∎\n\n -- A relation relating values of the two bag types.\n\n infix 4 _∼_\n\n _∼_ : List-bag → Assoc-list-bag → Type a\n xs ∼ ys = ∀ z → count₁ z xs ≡ count₂ z ys\n\n -- The relation _∼_ is propositional.\n\n ∼-propositional : ∀ xs ys → Is-proposition (xs ∼ ys)\n ∼-propositional _ _ =\n Π-closure ext 1 λ _ →\n ℕ-set\n\n -- The relation _∼_ is a QER.\n\n ∼-QER : Is-QER _∼_\n ∼-QER =\n (λ {xs₁ xs₂ ys₁ ys₂} xs₁∼ys₁ xs₂∼ys₁ xs₂∼ys₂ z →\n count₁ z xs₁ ≡⟨ xs₁∼ys₁ z ⟩\n count₂ z ys₁ ≡⟨ sym $ xs₂∼ys₁ z ⟩\n count₁ z xs₂ ≡⟨ xs₂∼ys₂ z ⟩∎\n count₂ z ys₂ ∎)\n , (λ xs → ∣ to xs , ∼to xs ∣)\n , (λ ys → ∣ from ys , from∼ ys ∣)\n where\n to : List-bag → Assoc-list-bag\n to = L.foldr (insert 1) []\n\n from : Assoc-list-bag → List-bag\n from = L.foldr (λ (n , x) → L.replicate n x L.++_) []\n\n ∼to : ∀ xs → xs ∼ to xs\n ∼to [] _ = refl _\n ∼to (x ∷ xs) z =\n count₁′ z x + count₁ z xs ≡⟨ cong (count₁′ z x +_) $ ∼to xs z ⟩\n count₁′ z x + count₂ z (to xs) ≡⟨⟩\n count₂′ z (1 , x) + count₂ z (to xs) ≡⟨ sym $ count₂-insert (to xs) ⟩∎\n count₂ z (insert 1 x (to xs)) ∎\n\n from∼ : ∀ ys → from ys ∼ ys\n from∼ [] _ = refl _\n from∼ ((n , y) ∷ ys) z =\n count₁ z (L.replicate n y L.++ from ys) ≡⟨ count₁-++ (L.replicate n y) ⟩\n count₁ z (L.replicate n y) + count₁ z (from ys) ≡⟨ cong (count₁ z (L.replicate n y) +_) $ from∼ ys z ⟩\n count₁ z (L.replicate n y) + count₂ z ys ≡⟨ cong (_+ count₂ z ys) $ count₁-replicate n ⟩\n count₂′ z (n , y) + count₂ z ys ≡⟨⟩\n count₂ z ((n , y) ∷ ys) ∎\n\n -- Raw-bag-structure-List-bag and Raw-bag-structure-Assoc-list-bag\n -- are related by Raw-bag-typeᴿ _∼_.\n\n List-bag∼Assoc-list-bag :\n Raw-bag-typeᴿ _∼_\n Raw-bag-structure-List-bag Raw-bag-structure-Assoc-list-bag\n List-bag∼Assoc-list-bag =\n (λ z →\n count₁ z [] ≡⟨⟩\n count₂ z [] ∎)\n , (λ x {x = xs} {y = ys} xs∼ys z →\n count₁ z (x ∷ xs) ≡⟨⟩\n count₁′ z x + count₁ z xs ≡⟨ cong (count₁′ z x +_) (xs∼ys z) ⟩\n count₁′ z x + count₂ z ys ≡⟨⟩\n count₂′ z (1 , x) + count₂ z ys ≡⟨ sym $ count₂-insert ys ⟩∎\n count₂ z (insert 1 x ys) ∎)\n , (λ {x = xs₁} {y = ys₁} xs₁∼ys₁ {x = xs₂} {y = ys₂} xs₂∼ys₂ z →\n count₁ z (xs₁ L.++ xs₂) ≡⟨ count₁-++ xs₁ ⟩\n count₁ z xs₁ + count₁ z xs₂ ≡⟨ cong₂ _+_ (xs₁∼ys₁ z) (xs₂∼ys₂ z) ⟩\n count₂ z ys₁ + count₂ z ys₂ ≡⟨ sym $ count₂-union ys₁ ⟩∎\n count₂ z (union ys₁ ys₂) ∎)\n , (λ x {x = xs} {y = ys} xs∼ys →\n count₁ x xs ≡⟨ xs∼ys x ⟩∎\n count₂ x ys ∎)\n\n -- There is an equivalence (with erased proofs) between List-bag\n -- quotiented by _∼_ ⟵ and Assoc-list-bag quotiented by _∼_ ⟶\n -- (where _/ᴱ_ is used for the quotients).\n\n List-bag≃ᴱAssoc-list-bag :\n List-bag /ᴱ _∼_ ⟵ ≃ᴱ Assoc-list-bag /ᴱ _∼_ ⟶\n List-bag≃ᴱAssoc-list-bag =\n /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ (Is-QER→Is-QERᴱ ∼-QER) ∼-propositional .proj₁\n\n -- Lists that are related by List-bag≃ᴱAssoc-list-bag (in a\n -- certain way) are also related by _∼_.\n --\n -- Note that this definition is not erased: it uses /ᴱ⟵≃ᴱ/ᴱ⟶\n -- instead of /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ, and ∼-QER instead of\n -- Is-QER→Is-QERᴱ ∼-QER.\n\n →∼ :\n ∀ xs ys →\n _≃ᴱ_.to List-bag≃ᴱAssoc-list-bag [ xs ] ≡ [ ys ] →\n xs ∼ ys\n →∼ xs ys = /ᴱ⟵≃ᴱ/ᴱ⟶ ∼-QER ∼-propositional .proj₂ xs ys .proj₁\n\n -- The function →∼ is an equivalence (in erased contexts).\n\n @0 →∼-equivalence : ∀ xs ys → Is-equivalence (→∼ xs ys)\n →∼-equivalence xs ys =\n /ᴱ⟵≃ᴱ/ᴱ⟶ ∼-QER ∼-propositional .proj₂ xs ys .proj₂ .erased\n\n -- The relation _∼_ can be expressed using\n -- List-bag≃ᴱAssoc-list-bag (in erased contexts).\n\n @0 ≃∼ :\n ∀ xs ys →\n (_≃ᴱ_.to List-bag≃ᴱAssoc-list-bag [ xs ] ≡ [ ys ]) ≃ (xs ∼ ys)\n ≃∼ = /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ (Is-QER→Is-QERᴱ ∼-QER) ∼-propositional .proj₂ .erased\n\n private\n\n instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ =\n Suitable→/ᴱ⟵×/ᴱ⟶\n Raw-bag-type-List-bag\n Raw-bag-type-Assoc-list-bag\n (Raw-bag-typeᴿ-univalent .proj₁)\n (Is-QER→Is-QERᴱ ∼-QER)\n ∼-propositional\n List-bag∼Assoc-list-bag\n\n -- There is a raw bag structure on List-bag /ᴱ _∼_ ⟵.\n\n Raw-bag-structure-List-bag-/ᴱ :\n Raw-bag-structure (List-bag /ᴱ _∼_ ⟵)\n Raw-bag-structure-List-bag-/ᴱ = instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₁\n\n Raw-bag-type-List-bag-/ᴱ : Raw-bag-type\n Raw-bag-type-List-bag-/ᴱ =\n List-bag /ᴱ _∼_ ⟵ , Raw-bag-structure-List-bag-/ᴱ\n\n -- There is a raw bag structure on Assoc-list-bag /ᴱ _∼_ ⟶.\n\n Raw-bag-structure-Assoc-list-bag-/ᴱ :\n Raw-bag-structure (Assoc-list-bag /ᴱ _∼_ ⟶)\n Raw-bag-structure-Assoc-list-bag-/ᴱ =\n instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₁\n\n Raw-bag-type-Assoc-list-bag-/ᴱ : Raw-bag-type\n Raw-bag-type-Assoc-list-bag-/ᴱ =\n Assoc-list-bag /ᴱ _∼_ ⟶ , Raw-bag-structure-Assoc-list-bag-/ᴱ\n\n -- The two raw bag structures are related to the underlying raw\n -- bag structures (in erased contexts).\n\n @0 List∼List-/ᴱ :\n Raw-bag-typeᴿ (Graph [_])\n Raw-bag-structure-List-bag Raw-bag-structure-List-bag-/ᴱ\n List∼List-/ᴱ = instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₂ .erased .proj₁\n\n @0 Assoc-list∼Assoc-list-/ᴱ :\n Raw-bag-typeᴿ (Graph [_])\n Raw-bag-structure-Assoc-list-bag\n Raw-bag-structure-Assoc-list-bag-/ᴱ\n Assoc-list∼Assoc-list-/ᴱ =\n instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₂ .erased .proj₂ .proj₁\n\n -- They are also related to each other (in erased contexts).\n\n @0 List-/ᴱ∼Assoc-list-/ᴱ :\n Raw-bag-typeᴿ (Graph (_≃ᴱ_.to List-bag≃ᴱAssoc-list-bag))\n Raw-bag-structure-List-bag-/ᴱ\n Raw-bag-structure-Assoc-list-bag-/ᴱ\n List-/ᴱ∼Assoc-list-/ᴱ =\n instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₂ .erased .proj₂ .proj₂\n\n -- Raw-bag-type-List-bag-/ᴱ is equal to\n -- Raw-bag-type-Assoc-list-bag-/ᴱ (in erased contexts).\n\n @0 List-/ᴱ≡Assoc-list-/ᴱ :\n Raw-bag-type-List-bag-/ᴱ ≡ Raw-bag-type-Assoc-list-bag-/ᴱ\n List-/ᴱ≡Assoc-list-/ᴱ =\n Univalentᴿ→/ᴱ⟵×/ᴱ⟶\n Raw-bag-type-List-bag\n Raw-bag-type-Assoc-list-bag\n Raw-bag-typeᴿ-univalent\n (Is-QER→Is-QERᴱ ∼-QER)\n ∼-propositional\n List-bag∼Assoc-list-bag\n .proj₂ .proj₂ .erased .proj₂ .proj₂\n\n -- For List-bag /ᴱ _∼_ ⟵ equality of two lists can be expressed in\n -- terms of the induced count function (in erased contexts).\n\n @0 List-≡≃ :\n let count = Raw-bag-structure-List-bag-/ᴱ .proj₂ .proj₂ .proj₂ in\n (xs ys : List-bag /ᴱ _∼_ ⟵) →\n (xs ≡ ys) ≃ (∀ z → count z xs ≡ count z ys)\n List-≡≃ = Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ →\n Π-closure ext 1 λ _ →\n Eq.left-closure ext 0 $\n Q./ᴱ-is-set\n .Q.[]ʳ xs → Q.elim-prop λ @0 where\n .Q.is-propositionʳ _ →\n Eq.left-closure ext 0 $\n Q./ᴱ-is-set\n .Q.[]ʳ ys →\n ([ xs ] ≡ [ ys ]) ↝⟨ inverse $\n Q.related≃[equal]\n (Is-QER→Is-equivalence-relation-⟵ ∼-QER)\n T.truncation-is-proposition ⟩\n (_∼_ ⟵) xs ys ↝⟨ Eq.⇔→≃\n T.truncation-is-proposition\n (Π-closure ext 1 λ _ → ℕ-set)\n (T.rec λ @0 where\n .T.truncation-is-propositionʳ →\n Π-closure ext 1 λ _ → ℕ-set\n .T.∣∣ʳ (zs , xs∼zs , ys∼zs) z →\n count₁ z xs ≡⟨ xs∼zs z ⟩\n count₂ z zs ≡⟨ sym $ ys∼zs z ⟩∎\n count₁ z ys ∎)\n (λ xs∼ys →\n T.∥∥ᴱ-map\n (λ (zs , xs∼zs) →\n zs\n , xs∼zs\n , λ z →\n count₁ z ys ≡⟨ sym $ xs∼ys z ⟩\n count₁ z xs ≡⟨ xs∼zs z ⟩∎\n count₂ z zs ∎)\n (∼-QER .proj₂ .proj₁ xs)) ⟩□\n (∀ z → count₁ z xs ≡ count₁ z ys) □\n\n -- This property can easily be transported to\n -- Assoc-list-bag /ᴱ _∼_ ⟶.\n\n @0 Assoc-list-≡≃ :\n let count = Raw-bag-structure-Assoc-list-bag-/ᴱ\n .proj₂ .proj₂ .proj₂ in\n (xs ys : Assoc-list-bag /ᴱ _∼_ ⟶) →\n (xs ≡ ys) ≃ (∀ z → count z xs ≡ count z ys)\n Assoc-list-≡≃ =\n subst\n (λ B → let count = B .proj₂ .proj₂ .proj₂ .proj₂ in\n (xs ys : B .proj₁) →\n (xs ≡ ys) ≃ (∀ z → count z xs ≡ count z ys))\n List-/ᴱ≡Assoc-list-/ᴱ\n List-≡≃\n", "meta": {"hexsha": "57ef13a9b6c667e681b5d8a6e4fd17c8c8258ace", "size": 111198, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Structure-identity-principle/Erased.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/Structure-identity-principle/Erased.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/Structure-identity-principle/Erased.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": 36.6627101879, "max_line_length": 146, "alphanum_fraction": 0.4792981888, "num_tokens": 41706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6893056167854461, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3715241613731303}} {"text": "{-\n\nDefinition of the integers as a HIT inspired by slide 10 of (original\nidea due to Paolo Capriotti):\n\nhttp://www.cs.nott.ac.uk/~psztxa/talks/bonn18.pdf\n\nDisclaimer: this definition is very hard to work with and I have not\nbeen able to prove that it is equivalent to nat + nat or that it is a\nset.\n\nFor a variation that relies on a different notion of equivalence\n(without any 2-cell) and which seems easier to work with see:\n\nhttps://github.com/RedPRL/redtt/blob/master/library/cool/biinv-int.red\n\nIt might be interesting to port that example one day.\n\n-}\n{-# OPTIONS --cubical --no-import-sorts #-}\nmodule Cubical.Experiments.HInt where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Data.Int\nopen import Cubical.Data.Nat\n\ndata ℤ : Type₀ where\n zero : ℤ\n suc : ℤ → ℤ\n pred : ℤ → ℤ\n sucpred : (n : ℤ) → suc (pred n) ≡ n\n predsuc : (n : ℤ) → pred (suc n) ≡ n\n -- Coherence: could also be written \"sucpred (suc n) ≡ cong (suc (predsuc n))\"\n coh : (n : ℤ) → Path (suc (pred (suc n)) ≡ suc n)\n (sucpred (suc n))\n (λ i → suc (predsuc n i))\n\n-- This is equivalent to Int:\ncoherence : (n : Int) → Path (Path Int (sucInt (predInt (sucInt n))) (sucInt n))\n (sucPred (sucInt n))\n (cong sucInt (predSuc n))\ncoherence (pos zero) = refl\ncoherence (pos (suc n)) = refl\ncoherence (negsuc zero) = refl\ncoherence (negsuc (suc zero)) = refl\ncoherence (negsuc (suc (suc n))) = refl\n\nℤ→Int : ℤ → Int\nℤ→Int zero = pos 0\nℤ→Int (suc n) = sucInt (ℤ→Int n)\nℤ→Int (pred n) = predInt (ℤ→Int n)\nℤ→Int (sucpred n i) = sucPred (ℤ→Int n) i\nℤ→Int (predsuc n i) = predSuc (ℤ→Int n) i\nℤ→Int (coh n i j) = coherence (ℤ→Int n) i j\n\nℕ→ℤ : ℕ → ℤ\nℕ→ℤ zero = zero\nℕ→ℤ (suc n) = suc (ℕ→ℤ n)\n\nnegsucℕ→ℤ : ℕ → ℤ\nnegsucℕ→ℤ zero = pred zero\nnegsucℕ→ℤ (suc n) = pred (negsucℕ→ℤ n)\n\nInt→ℤ : Int → ℤ\nInt→ℤ (pos n) = ℕ→ℤ n\nInt→ℤ (negsuc n) = negsucℕ→ℤ n\n\nlem1 : ∀ n → Int→ℤ (sucInt n) ≡ suc (Int→ℤ n)\nlem1 (pos n) = refl\nlem1 (negsuc zero) = sym (sucpred zero)\nlem1 (negsuc (suc n)) = sym (sucpred (negsucℕ→ℤ n))\n\nlem2 : ∀ n → Int→ℤ (predInt n) ≡ pred (Int→ℤ n)\nlem2 (pos zero) = refl\nlem2 (pos (suc n)) = sym (predsuc (ℕ→ℤ n))\nlem2 (negsuc n) = refl\n\n-- I don't see how to fill these holes, especially the last one\nℤ→Int→ℤ : ∀ (n : ℤ) → Int→ℤ (ℤ→Int n) ≡ n\nℤ→Int→ℤ zero = refl\nℤ→Int→ℤ (suc n) = (lem1 (ℤ→Int n)) ∙ (cong suc (ℤ→Int→ℤ n))\nℤ→Int→ℤ (pred n) = (lem2 (ℤ→Int n)) ∙ (cong pred (ℤ→Int→ℤ n))\nℤ→Int→ℤ (sucpred n i) = {!!}\nℤ→Int→ℤ (predsuc n i) = {!!}\nℤ→Int→ℤ (coh n i j) = {!!}\n\nInt→ℤ→Int : ∀ n → ℤ→Int (Int→ℤ n) ≡ n\nInt→ℤ→Int (pos zero) = refl\nInt→ℤ→Int (pos (suc n)) = cong sucInt (Int→ℤ→Int (pos n))\nInt→ℤ→Int (negsuc zero) = refl\nInt→ℤ→Int (negsuc (suc n)) = cong predInt (Int→ℤ→Int (negsuc n))\n\nInt≡ℤ : Int ≡ ℤ\nInt≡ℤ = isoToPath (iso Int→ℤ ℤ→Int ℤ→Int→ℤ Int→ℤ→Int)\n\nisSetℤ : isSet ℤ\nisSetℤ = subst isSet Int≡ℤ isSetInt\n", "meta": {"hexsha": "6d0135a851ad898f4f1c871b7b0cd5f0fe567939", "size": 3001, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Experiments/HInt.agda", "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": "Cubical/Experiments/HInt.agda", "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_forks_repo_path": "Cubical/Experiments/HInt.agda", "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "avg_line_length": 30.01, "max_line_length": 80, "alphanum_fraction": 0.620793069, "num_tokens": 1270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.3715181872431773}} {"text": "{-# OPTIONS --show-implicit #-}\n\nmodule BottomUp where\n\nopen import Foundation.Primitive\nopen import Foundation.Bottom\nopen import Foundation.Equivalence\n\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Unit\n\nmodule NegEquiv {ℓ'} (⊥ : Set ℓ') ⦃ _ : ∀ {b} → IsBottom ⊥ b ⦄ where\n\n _≉_ : ∀ {a} {A : Set a} {ℓ} ⦃ _ : Equivalence A ℓ ⦄ → A → A → Set (ℓ ⊔ ℓ')\n x ≉ y = x ≈ y → ⊥\n\nmodule Data-⊥ where\n\n data Data⊥ : Set where\n\n instance bottom-rule : ∀ {b} → IsBottom Data⊥ b\n IsBottom.⊥-elim (bottom-rule {b}) () {B}\n\nmodule IsDecisive-Module {ℓ'} (⊥ : Set ℓ') ⦃ _ : ∀ {b} → IsBottom ⊥ b ⦄ where\n\n open NegEquiv ⊥\n\n record IsDecisive a\n (Decision : (A : Set a) → Set a)\n (yes-c : {A : Set a} → A → Decision A)\n (no-c : {A : Set a} → (A → ⊥) → Decision A)\n ℓ\n ⦃ equiv-decision : {A : Set a} → Equivalence (Decision A) ℓ ⦄\n : Set (ℓ ⊔ ⟰ a ⊔ ℓ') where\n field\n yes-correct : {A : Set a} → (dec : Decision A) → (x : A) → yes-c x ≈ dec\n no-correct : {A : Set a} → (dec : Decision A) → (x : A → ⊥) → no-c x ≈ dec\n yes-no-incompat : {A : Set a} (x : A) (nx : A → ⊥) → yes-c x ≉ no-c nx\n\n open IsDecisive ⦃ … ⦄ public\n\nrecord ⊤′ {a} : Set a where\n instance constructor tt\n\nmodule Data-Decision {ℓ} (⊥ : Set ℓ) ⦃ _ : ∀ {b} → IsBottom ⊥ b ⦄ where\n\n data Decision {a} (A : Set a) : Set (a ⊔ ℓ) where\n yes : A → Decision A\n no : (A → ⊥) → Decision A\n\n open IsDecisive-Module ⊥\n\n instance dec-equiv : ∀ {a} {A : Set a} → Equivalence (Decision {a} A) a\n (dec-equiv {a} {A} Equivalence.≈ yes x₁) (yes x₂) = ⊤′\n (dec-equiv {a} {A} Equivalence.≈ yes x₁) (no x₂) = ⊥-elim (x₂ x₁)\n (dec-equiv {a} {A} Equivalence.≈ no x₁) (yes x₂) = ⊥-elim (x₁ x₂)\n (dec-equiv {a} {A} Equivalence.≈ no x₁) (no x₂) = ⊤′\n IsEquivalence.reflexivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) = tt\n IsEquivalence.reflexivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) = tt\n IsEquivalence.symmetry (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (yes x₂) x₃ = x₃\n IsEquivalence.symmetry (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (no x₂) x₃ = x₃\n IsEquivalence.symmetry (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (yes x₂) x₃ = x₃\n IsEquivalence.symmetry (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (no x₂) x₃ = x₃\n IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (yes x₂) (yes x₃) x₄ x₅ = tt\n IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (yes x₂) (no x₃) x₄ x₅ = ⊥-elim (x₃ x₂)\n IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (no x₂) (yes x₃) x₄ x₅ = tt\n IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (no x₂) (no x₃) x₄ x₅ = ⊥-elim (x₂ x₁)\n IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (yes x₂) (yes x₃) x₄ x₅ = ⊥-elim (x₁ x₂)\n IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (yes x₂) (no x₃) x₄ x₅ = tt\n IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (no x₂) (yes x₃) x₄ x₅ = ⊥-elim (x₂ x₃)\n IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (no x₂) (no x₃) x₄ x₅ = tt\n\n instance dec-instance : ∀ {a} → IsDecisive (a ⊔ ℓ) (Decision {a ⊔ ℓ}) yes no (a ⊔ ℓ)\n IsDecisive-Module.IsDecisive.yes-correct (dec-instance {a}) {A} (yes x₁) x₂ = tt\n IsDecisive-Module.IsDecisive.yes-correct (dec-instance {a}) {A} (no x₁) x₂ = ⊥-elim (x₁ x₂)\n IsDecisive-Module.IsDecisive.no-correct (dec-instance {a}) {A} (yes x₁) x₂ = ⊥-elim (x₂ x₁)\n IsDecisive-Module.IsDecisive.no-correct (dec-instance {a}) {A} (no x₁) x₂ = tt\n IsDecisive-Module.IsDecisive.yes-no-incompat (dec-instance {a}) x₁ nx x₂ = nx x₁\n\n\nopen Data-⊥\n\n\n-- module DecisionModule (⊥ : Set) ⦃ _ : ∀ {a} {b} → IsBottom ⊥ a b ⦄ where\n\n-- record IsDecidableEquivalence {a} {A : Set a} {ℓ} (_≈_ : A → A → Set ℓ) : Set (a ⊔ ℓ) where\n-- infix 4 _≈?_\n-- field\n-- isEquivalence : IsEquivalence _≈_\n-- _≈?_ : (x y : A) → Decision (x ≈ y)\n\n-- record DecidableEquivalence {a} (A : Set a) ℓ : Set (lsuc (a ⊔ ℓ)) where\n-- field\n-- ⦃ equivalence ⦄ : Equivalence A ℓ\n-- --open Equivalence equivalence\n-- infix 4 _≈?_\n-- field\n-- _≈?_ : (x y : A) → Decision (x ≈ y)\n\n-- open DecidableEquivalence ⦃ … ⦄ public\n\n-- record DecidableEquivalence' {a} (A : Set a) : Set (lsuc a) where\n-- field\n-- ⦃ equivalence ⦄ : Equivalence A a\n-- infix 4 _≈?_\n-- field\n-- _≈?_ : (x y : A) → Decision (x ≈ y)\n\n-- data ⊥-fake : Set where\n-- faker : ⊥-fake\n\n-- ⊥fake-rule : ∀ {a} {A : Set a} → (A → ⊥-fake) → A → ∀ {b} {B : Set b} → B\n-- ⊥fake-rule x x₁ with x x₁\n-- ⊥fake-rule x x₁ | faker = {!!}\n\n-- open DecisionModule ⊥\n\n-- data Tree (A : Set) : Set where\n-- value : A → Tree A\n-- leaf : Tree A\n-- branch : Tree A → Tree A → Tree A\n\n-- substitute₁List : ∀ {a} {A : Set a} ⦃ _ : DecidableEquivalence A a ⦄ → A → A → List A → List A\n-- substitute₁List x₁ y [] = []\n-- substitute₁List x₁ y (x₂ ∷ xs) with x₁ ≈? x₂\n-- substitute₁List x₁ y (x₂ ∷ xs) | yes x₃ = y ∷ substitute₁List x₁ y xs\n-- substitute₁List x₁ y (x₂ ∷ xs) | no x₃ = x₂ ∷ substitute₁List x₁ y xs\n\n-- open import Agda.Builtin.Nat\n-- open import Agda.Builtin.Bool\n\n-- instance EquivalenceNat : Equivalence Nat lzero\n-- (EquivalenceNat Equivalence.≈ x) x₁ = (x == x₁) ≡ true\n-- IsEquivalence.reflexivity (Equivalence.isEquivalence EquivalenceNat) = isrefl where\n-- isrefl : ∀ x → (x == x) ≡ true\n-- isrefl zero = refl\n-- isrefl (suc x) = isrefl x\n-- IsEquivalence.symmetry (Equivalence.isEquivalence EquivalenceNat) = issym where\n-- issym : (x y : Nat) →\n-- EquivalenceNat .Equivalence._≈_ x y →\n-- EquivalenceNat .Equivalence._≈_ y x\n-- issym zero zero x₁ = refl\n-- issym zero (suc y) x₁ = x₁\n-- issym (suc x) zero x₁ = x₁\n-- issym (suc x) (suc y) x₁ = issym x y x₁\n-- IsEquivalence.transitivity (Equivalence.isEquivalence EquivalenceNat) = {!!}\n\n-- instance DecidableEquivalenceNat : DecidableEquivalence Nat lzero\n-- DecisionModule.DecidableEquivalence.equivalence DecidableEquivalenceNat = EquivalenceNat\n-- (DecidableEquivalenceNat DecisionModule.DecidableEquivalence.≈? zero) zero = yes refl\n-- (DecidableEquivalenceNat DecisionModule.DecidableEquivalence.≈? zero) (suc y) = no (λ x → {!!})\n-- (DecidableEquivalenceNat DecisionModule.DecidableEquivalence.≈? suc x) zero = {!!}\n-- (DecidableEquivalenceNat DecisionModule.DecidableEquivalence.≈? suc x) (suc y) = {!!}\n\n\n-- {-\n-- $&[{}(=*)+]!#\n-- ~%7531902468`\n-- ;,.\n-- :<>\n-- -}\n", "meta": {"hexsha": "925148347826ef1c14277e0d7e461605bc878f77", "size": 6768, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "archive/agda-1/BottomUp.agda", "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "archive/agda-1/BottomUp.agda", "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_forks_repo_path": "archive/agda-1/BottomUp.agda", "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.5214723926, "max_line_length": 125, "alphanum_fraction": 0.6093380615, "num_tokens": 2636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.665410572017153, "lm_q2_score": 0.5583269943353744, "lm_q1q2_score": 0.3715166846733192}} {"text": "{-# OPTIONS --safe --experimental-lossy-unification #-}\n{-\nThis file contains a proof that the generator of Π₃S² has\nhopf invariant ±1.\n-}\nmodule Cubical.Homotopy.HopfInvariant.HopfMap where\n\nopen import Cubical.Homotopy.HopfInvariant.Base\nopen import Cubical.Homotopy.Hopf\nopen S¹Hopf\nopen import Cubical.Homotopy.Connected\nopen import Cubical.Homotopy.HSpace\n\nopen import Cubical.ZCohomology.Base\nopen import Cubical.ZCohomology.GroupStructure\nopen import Cubical.ZCohomology.Properties\nopen import Cubical.ZCohomology.Groups.Sn\nopen import Cubical.ZCohomology.RingStructure.CupProduct\nopen import Cubical.ZCohomology.RingStructure.RingLaws\nopen import Cubical.ZCohomology.Gysin\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Path\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Pointed\nopen import Cubical.Foundations.Pointed.Homogeneous\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.GroupoidLaws\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Univalence\n\nopen import Cubical.Data.Sum\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Int hiding (_+'_)\nopen import Cubical.Data.Nat renaming (_+_ to _+ℕ_ ; _·_ to _·ℕ_)\nopen import Cubical.Data.Unit\n\nopen import Cubical.Algebra.Group\nopen import Cubical.Algebra.Group.ZAction\nopen import Cubical.Algebra.Group.Exact\nopen import Cubical.Algebra.Group.Morphisms\nopen import Cubical.Algebra.Group.MorphismProperties\nopen import Cubical.Algebra.Group.Instances.Int\nopen import Cubical.Algebra.Group.GroupPath\n\nopen import Cubical.HITs.Pushout\nopen import Cubical.HITs.Join\nopen import Cubical.HITs.S1 renaming (_·_ to _*_)\nopen import Cubical.HITs.Sn\nopen import Cubical.HITs.Susp\nopen import Cubical.HITs.Truncation\n renaming (rec to trRec ; elim to trElim)\nopen import Cubical.HITs.SetTruncation\n renaming (rec to sRec ; rec2 to sRec2\n ; elim to sElim ; elim2 to sElim2 ; map to sMap)\nopen import Cubical.HITs.PropositionalTruncation\n renaming (rec to pRec)\n\nHopfMap : S₊∙ 3 →∙ S₊∙ 2\nfst HopfMap x = JoinS¹S¹→TotalHopf (Iso.inv (IsoSphereJoin 1 1) x) .fst\nsnd HopfMap = refl\n\n-- We use the Hopf fibration in order to connect it to the Gysin Sequence\nmodule hopfS¹ =\n Hopf S1-AssocHSpace (sphereElim2 _ (λ _ _ → squash₁) ∣ refl ∣₁)\n\nS¹Hopf = hopfS¹.Hopf\nE* = hopfS¹.TotalSpacePush²'\nIsoE*join = hopfS¹.joinIso₂\nIsoTotalHopf' = hopfS¹.joinIso₁\nCP² = hopfS¹.TotalSpaceHopfPush²\nfibr = hopfS¹.P\n\nTotalHopf' : Type _\nTotalHopf' = Σ (S₊ 2) S¹Hopf\n\nIsoJoins : (join S¹ (join S¹ S¹)) ≡ join S¹ (S₊ 3)\nIsoJoins = cong (join S¹) (isoToPath (IsoSphereJoin 1 1))\n\n-- CP² is 1-connected\nconCP² : (x y : CP²) → ∥ x ≡ y ∥₂\nconCP² x y = sRec2 squash₂ (λ p q → ∣ p ∙ sym q ∣₂) (conCP²' x) (conCP²' y)\n where\n conCP²' : (x : CP²) → ∥ x ≡ inl tt ∥₂\n conCP²' (inl x) = ∣ refl ∣₂\n conCP²' (inr x) = sphereElim 1 {A = λ x → ∥ inr x ≡ inl tt ∥₂}\n (λ _ → squash₂) ∣ sym (push (inl base)) ∣₂ x\n conCP²' (push a i) = main a i\n where\n indLem : ∀ {ℓ} {A : hopfS¹.TotalSpaceHopfPush → Type ℓ}\n → ((a : _) → isProp (A a))\n → A (inl base)\n → ((a : hopfS¹.TotalSpaceHopfPush) → A a)\n indLem {A = A} p b =\n PushoutToProp p\n (sphereElim 0 (λ _ → p _) b)\n (sphereElim 0 (λ _ → p _) (subst A (push (base , base)) b))\n\n main : (a : hopfS¹.TotalSpaceHopfPush)\n → PathP (λ i → ∥ Path CP² (push a i) (inl tt) ∥₂)\n (conCP²' (inl tt)) (conCP²' (inr (hopfS¹.induced a)))\n main = indLem (λ _ → isOfHLevelPathP' 1 squash₂ _ _)\n λ j → ∣ (λ i → push (inl base) (~ i ∧ j)) ∣₂\n\nmodule GysinS² = Gysin (CP² , inl tt) fibr conCP² 2 idIso refl\n\nE'S⁴Iso : Iso GysinS².E' (S₊ 5)\nE'S⁴Iso =\n compIso IsoE*join\n (compIso (Iso→joinIso idIso (IsoSphereJoin 1 1))\n (IsoSphereJoin 1 3))\n\nisContrH³E : isContr (coHom 3 (GysinS².E'))\nisContrH³E =\n subst isContr (sym (isoToPath\n (fst (Hⁿ-Sᵐ≅0 2 4\n λ p → snotz (sym (cong (predℕ ∘ predℕ) p)))))\n ∙ cong (coHom 3) (sym (isoToPath E'S⁴Iso)))\n isContrUnit\n\nisContrH⁴E : isContr (coHom 4 (GysinS².E'))\nisContrH⁴E =\n subst isContr (sym (isoToPath\n (fst (Hⁿ-Sᵐ≅0 3 4\n λ p → snotz (sym (cong (predℕ ∘ predℕ ∘ predℕ) p)))))\n ∙ cong (coHom 4) (sym (isoToPath E'S⁴Iso)))\n isContrUnit\n\n-- We will need a bunch of elimination principles\njoinS¹S¹→Groupoid : ∀ {ℓ} (P : join S¹ S¹ → Type ℓ)\n → ((x : _) → isGroupoid (P x))\n → P (inl base)\n → (x : _) → P x\njoinS¹S¹→Groupoid P grp b =\n transport (λ i → (x : (isoToPath (invIso (IsoSphereJoin 1 1))) i)\n → P (transp (λ j → isoToPath (invIso (IsoSphereJoin 1 1)) (i ∨ j)) i x))\n (sphereElim _ (λ _ → grp _) b)\n\nTotalHopf→Gpd : ∀ {ℓ} (P : hopfS¹.TotalSpaceHopfPush → Type ℓ)\n → ((x : _) → isGroupoid (P x))\n → P (inl base)\n → (x : _) → P x\nTotalHopf→Gpd P grp b =\n transport (λ i → (x : sym (isoToPath IsoTotalHopf') i)\n → P (transp (λ j → isoToPath IsoTotalHopf' (~ i ∧ ~ j)) i x))\n (joinS¹S¹→Groupoid _ (λ _ → grp _) b)\n\nTotalHopf→Gpd' : ∀ {ℓ} (P : Σ (S₊ 2) hopfS¹.Hopf → Type ℓ)\n → ((x : _) → isGroupoid (P x))\n → P (north , base)\n → (x : _) → P x\nTotalHopf→Gpd' P grp b =\n transport (λ i → (x : ua (_ , hopfS¹.isEquivTotalSpaceHopfPush→TotalSpace) i)\n → P (transp (λ j → ua (_ , hopfS¹.isEquivTotalSpaceHopfPush→TotalSpace)\n (i ∨ j)) i x))\n (TotalHopf→Gpd _ (λ _ → grp _) b)\n\nCP²→Groupoid : ∀ {ℓ} {P : CP² → Type ℓ}\n → ((x : _) → is2Groupoid (P x))\n → (b : P (inl tt))\n → (s2 : ((x : _) → P (inr x)))\n → PathP (λ i → P (push (inl base) i)) b (s2 north)\n → (x : _) → P x\nCP²→Groupoid {P = P} grp b s2 pp (inl x) = b\nCP²→Groupoid {P = P} grp b s2 pp (inr x) = s2 x\nCP²→Groupoid {P = P} grp b s2 pp (push a i₁) = lem a i₁\n where\n lem : (a : hopfS¹.TotalSpaceHopfPush) → PathP (λ i → P (push a i)) b (s2 _)\n lem = TotalHopf→Gpd _ (λ _ → isOfHLevelPathP' 3 (grp _) _ _) pp\n\n-- The function inducing the iso H²(S²) ≅ H²(CP²)\nH²S²→H²CP²-raw : (S₊ 2 → coHomK 2) → (CP² → coHomK 2)\nH²S²→H²CP²-raw f (inl x) = 0ₖ _\nH²S²→H²CP²-raw f (inr x) = f x -ₖ f north\nH²S²→H²CP²-raw f (push a i) =\n TotalHopf→Gpd (λ x → 0ₖ 2\n ≡ f (hopfS¹.TotalSpaceHopfPush→TotalSpace x .fst) -ₖ f north)\n (λ _ → isOfHLevelTrunc 4 _ _)\n (sym (rCancelₖ 2 (f north)))\n a i\n\nH²S²→H²CP² : coHomGr 2 (S₊ 2) .fst → coHomGr 2 CP² .fst\nH²S²→H²CP² = sMap H²S²→H²CP²-raw\n\ncancel-H²S²→H²CP² : (f : CP² → coHomK 2)\n → ∥ H²S²→H²CP²-raw (f ∘ inr) ≡ f ∥₁\ncancel-H²S²→H²CP² f =\n pRec squash₁\n (λ p → pRec squash₁\n (λ f → ∣ funExt f ∣₁)\n (cancelLem p))\n (connLem (f (inl tt)))\n where\n connLem : (x : coHomK 2) → ∥ x ≡ 0ₖ 2 ∥₁\n connLem = coHomK-elim _ (λ _ → isOfHLevelSuc 1 squash₁) ∣ refl ∣₁\n\n cancelLem : (p : f (inl tt) ≡ 0ₖ 2)\n → ∥ ((x : CP²) → H²S²→H²CP²-raw (f ∘ inr) x ≡ f x) ∥₁\n cancelLem p = trRec squash₁ (λ pp →\n ∣ CP²→Groupoid (λ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _)\n (sym p)\n (λ x → (λ i → f (inr x) -ₖ f (push (inl base) (~ i)))\n ∙∙ (λ i → f (inr x) -ₖ p i)\n ∙∙ rUnitₖ 2 (f (inr x))) pp ∣₁)\n help\n where\n help :\n hLevelTrunc 1\n (PathP (λ i₁ → H²S²→H²CP²-raw (f ∘ inr) (push (inl base) i₁)\n ≡ f (push (inl base) i₁))\n (sym p)\n (((λ i₁ → f (inr north) -ₖ f (push (inl base) (~ i₁))) ∙∙\n (λ i₁ → f (inr north) -ₖ p i₁) ∙∙ rUnitₖ 2 (f (inr north)))))\n help = isConnectedPathP 1 (isConnectedPath 2 (isConnectedKn 1) _ _) _ _ .fst\n\nH²CP²≅H²S² : GroupIso (coHomGr 2 CP²) (coHomGr 2 (S₊ 2))\nIso.fun (fst H²CP²≅H²S²) = sMap (_∘ inr)\nIso.inv (fst H²CP²≅H²S²) = H²S²→H²CP²\nIso.rightInv (fst H²CP²≅H²S²) =\n sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)\n λ f → trRec {B = Iso.fun (fst H²CP²≅H²S²) (Iso.inv (fst H²CP²≅H²S²) ∣ f ∣₂)\n ≡ ∣ f ∣₂}\n (isOfHLevelPath 2 squash₂ _ _)\n (λ p → cong ∣_∣₂ (funExt λ x → cong (λ y → (f x) -ₖ y) p ∙ rUnitₖ 2 (f x)))\n (Iso.fun (PathIdTruncIso _)\n (isContr→isProp (isConnectedKn 1) ∣ f north ∣ ∣ 0ₖ 2 ∣))\nIso.leftInv (fst H²CP²≅H²S²) =\n sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)\n λ f → pRec (squash₂ _ _) (cong ∣_∣₂) (cancel-H²S²→H²CP² f)\nsnd H²CP²≅H²S² =\n makeIsGroupHom\n (sElim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _) λ f g → refl)\n\nH²CP²≅ℤ : GroupIso (coHomGr 2 CP²) ℤGroup\nH²CP²≅ℤ = compGroupIso H²CP²≅H²S² (Hⁿ-Sⁿ≅ℤ 1)\n\n-- ⌣ gives a groupEquiv H²(CP²) ≃ H⁴(CP²)\n⌣Equiv : GroupEquiv (coHomGr 2 CP²) (coHomGr 4 CP²)\nfst (fst ⌣Equiv) = GysinS².⌣-hom 2 .fst\nsnd (fst ⌣Equiv) = isEq⌣\n where\n isEq⌣ : isEquiv (GysinS².⌣-hom 2 .fst)\n isEq⌣ =\n SES→isEquiv\n (GroupPath _ _ .fst (invGroupEquiv\n (isContr→≃Unit isContrH³E\n , makeIsGroupHom λ _ _ → refl)))\n (GroupPath _ _ .fst (invGroupEquiv\n (isContr→≃Unit isContrH⁴E\n , makeIsGroupHom λ _ _ → refl)))\n (GysinS².susp∘ϕ 1)\n (GysinS².⌣-hom 2)\n (GysinS².p-hom 4)\n (GysinS².Ker-⌣e⊂Im-Susp∘ϕ _)\n (GysinS².Ker-p⊂Im-⌣e _)\nsnd ⌣Equiv = GysinS².⌣-hom 2 .snd\n\n-- The generator of H²(CP²)\ngenCP² : coHom 2 CP²\ngenCP² = ∣ CP²→Groupoid (λ _ → isOfHLevelTrunc 4)\n (0ₖ _)\n ∣_∣\n refl ∣₂\n\ninrInjective : (f g : CP² → coHomK 2) → ∥ f ∘ inr ≡ g ∘ inr ∥₁\n → Path (coHom 2 CP²) ∣ f ∣₂ ∣ g ∣₂\ninrInjective f g = pRec (squash₂ _ _)\n (λ p → pRec (squash₂ _ _) (λ id → trRec (squash₂ _ _)\n (λ pp → cong ∣_∣₂\n (funExt (CP²→Groupoid\n (λ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _)\n id\n (funExt⁻ p)\n (compPathR→PathP pp))))\n (conn2 (f (inl tt)) (g (inl tt)) id\n (cong f (push (inl base))\n ∙ (funExt⁻ p north) ∙ cong g (sym (push (inl base))))))\n (conn (f (inl tt)) (g (inl tt))))\n\n where\n conn : (x y : coHomK 2) → ∥ x ≡ y ∥₁\n conn = coHomK-elim _ (λ _ → isSetΠ λ _ → isOfHLevelSuc 1 squash₁)\n (coHomK-elim _ (λ _ → isOfHLevelSuc 1 squash₁) ∣ refl ∣₁)\n\n conn2 : (x y : coHomK 2) (p q : x ≡ y) → hLevelTrunc 1 (p ≡ q)\n conn2 x y p q =\n Iso.fun (PathIdTruncIso _)\n (isContr→isProp (isConnectedPath _ (isConnectedKn 1) x y) ∣ p ∣ ∣ q ∣)\n\n-- A couple of basic lemma concerning the hSpace structure on S¹\nprivate\n invLooperLem₁ : (a x : S¹)\n → (invEq (hopfS¹.μ-eq a) x) * a ≡ (invLooper a * x) * a\n invLooperLem₁ a x =\n secEq (hopfS¹.μ-eq a) x\n ∙∙ cong (_* x) (rCancelS¹ a)\n ∙∙ AssocHSpace.μ-assoc S1-AssocHSpace a (invLooper a) x\n ∙ commS¹ _ _\n\n invLooperLem₂ : (a x : S¹) → invEq (hopfS¹.μ-eq a) x ≡ invLooper a * x\n invLooperLem₂ a x = sym (retEq (hopfS¹.μ-eq a) (invEq (hopfS¹.μ-eq a) x))\n ∙∙ cong (invEq (hopfS¹.μ-eq a)) (invLooperLem₁ a x)\n ∙∙ retEq (hopfS¹.μ-eq a) (invLooper a * x)\n\n rotLoop² : (a : S¹) → Path (a ≡ a) (λ i → rotLoop (rotLoop a i) (~ i)) refl\n rotLoop² =\n sphereElim 0 (λ _ → isGroupoidS¹ _ _ _ _)\n λ i j → hcomp (λ {k → λ { (i = i1) → base\n ; (j = i0) → base\n ; (j = i1) → base}})\n base\n\n\n-- We prove that the generator of CP² given by Gysin is the same one\n-- as genCP², which is much easier to work with\nGysin-e≡genCP² : GysinS².e ≡ genCP²\nGysin-e≡genCP² =\n inrInjective _ _ ∣ funExt (λ x → funExt⁻ (cong fst (main x)) south) ∣₁\n where\n mainId : (x : Σ (S₊ 2) hopfS¹.Hopf)\n → Path (hLevelTrunc 4 _) ∣ fst x ∣ ∣ north ∣\n mainId = uncurry λ { north → λ y → cong ∣_∣ₕ (merid base ∙ sym (merid y))\n ; south → λ y → cong ∣_∣ₕ (sym (merid y))\n ; (merid a i) → main a i}\n where\n main : (a : S¹) → PathP (λ i → (y : hopfS¹.Hopf (merid a i))\n → Path (HubAndSpoke (Susp S¹) 3) ∣ merid a i ∣ ∣ north ∣)\n (λ y → cong ∣_∣ₕ (merid base ∙ sym (merid y)))\n λ y → cong ∣_∣ₕ (sym (merid y))\n main a =\n toPathP\n (funExt λ x →\n cong (transport (λ i₁\n → Path (HubAndSpoke (Susp S¹) 3) ∣ merid a i₁ ∣ ∣ north ∣))\n ((λ i → (λ z → cong ∣_∣ₕ\n (merid base\n ∙ sym (merid (transport\n (λ j → uaInvEquiv (hopfS¹.μ-eq a) (~ i) j) x))) z))\n ∙ λ i → cong ∣_∣ₕ (merid base\n ∙ sym (merid (transportRefl (invEq (hopfS¹.μ-eq a) x) i))))\n ∙∙ (λ i → transp (λ i₁ → Path (HubAndSpoke (Susp S¹) 3)\n ∣ merid a (i₁ ∨ i) ∣ ∣ north ∣) i\n (compPath-filler' (cong ∣_∣ₕ (sym (merid a)))\n (cong ∣_∣ₕ (merid base\n ∙ sym (merid (invLooperLem₂ a x i)))) i))\n ∙∙ cong ((cong ∣_∣ₕ) (sym (merid a)) ∙_)\n (cong (cong ∣_∣ₕ) (cong sym (symDistr (merid base)\n (sym (merid (invLooper a * x)))))\n ∙ cong sym (SuspS¹-hom (invLooper a) x)\n ∙ symDistr ((cong ∣_∣ₕ) (merid (invLooper a) ∙ sym (merid base)))\n ((cong ∣_∣ₕ) (merid x ∙ sym (merid base)))\n ∙ isCommΩK 2 (sym (λ i₁ → ∣ (merid x\n ∙ (λ i₂ → merid base (~ i₂))) i₁ ∣))\n (sym (λ i₁ → ∣ (merid (invLooper a)\n ∙ (λ i₂ → merid base (~ i₂))) i₁ ∣))\n ∙ cong₂ _∙_ (cong sym (SuspS¹-inv a)\n ∙ cong-∙ ∣_∣ₕ (merid a) (sym (merid base)))\n (cong (cong ∣_∣ₕ) (symDistr (merid x) (sym (merid base)))\n ∙ cong-∙ ∣_∣ₕ (merid base) (sym (merid x))))\n ∙∙ (λ j → (λ i₁ → ∣ merid a (~ i₁ ∨ j) ∣) ∙ ((λ i₁ → ∣ merid a (i₁ ∨ j) ∣)\n ∙ (λ i₁ → ∣ merid base (~ i₁ ∨ j) ∣))\n ∙ (λ i₁ → ∣ merid base (i₁ ∨ j) ∣)\n ∙ (λ i₁ → ∣ merid x (~ i₁) ∣ₕ))\n ∙∙ sym (lUnit _)\n ∙∙ sym (assoc _ _ _)\n ∙∙ (sym (lUnit _) ∙ sym (lUnit _) ∙ sym (lUnit _)))\n\n gen' : (x : S₊ 2) → preThom.Q (CP² , inl tt) fibr (inr x) →∙ coHomK-ptd 2\n fst (gen' x) north = ∣ north ∣\n fst (gen' x) south = ∣ x ∣\n fst (gen' x) (merid a i₁) = mainId (x , a) (~ i₁)\n snd (gen' x) = refl\n\n gen'Id : GysinS².c (inr north) .fst ≡ gen' north .fst\n gen'Id = cong fst (GysinS².cEq (inr north) ∣ push (inl base) ∣₂)\n ∙ (funExt lem)\n where\n lem : (qb : _) →\n ∣ (subst (fst ∘ preThom.Q (CP² , inl tt) fibr)\n (sym (push (inl base))) qb) ∣\n ≡ gen' north .fst qb\n lem north = refl\n lem south = cong ∣_∣ₕ (sym (merid base))\n lem (merid a i) j =\n hcomp (λ k →\n λ { (i = i0) → ∣ merid a (~ k ∧ j) ∣\n ; (i = i1) → ∣ merid base (~ j) ∣\n ; (j = i0) → ∣ transportRefl (merid a i) (~ k) ∣\n ; (j = i1) → ∣ compPath-filler\n (merid base) (sym (merid a)) k (~ i) ∣ₕ})\n (hcomp (λ k →\n λ { (i = i0) → ∣ merid a (j ∨ ~ k) ∣\n ; (i = i1) → ∣ merid base (~ j ∨ ~ k) ∣\n ; (j = i0) → ∣ merid a (~ k ∨ i) ∣\n ; (j = i1) → ∣ merid base (~ i ∨ ~ k) ∣ₕ})\n ∣ south ∣)\n\n setHelp : (x : S₊ 2)\n → isSet (preThom.Q (CP² , inl tt) fibr (inr x) →∙ coHomK-ptd 2)\n setHelp = sphereElim _ (λ _ → isProp→isOfHLevelSuc 1 (isPropIsOfHLevel 2))\n (isOfHLevel↑∙' 0 1)\n\n main : (x : S₊ 2) → (GysinS².c (inr x) ≡ gen' x)\n main = sphereElim _ (λ x → isOfHLevelPath 2 (setHelp x) _ _)\n (→∙Homogeneous≡ (isHomogeneousKn _) gen'Id)\n\nisGenerator≃ℤ : ∀ {ℓ} (G : Group ℓ) (g : fst G) → Type ℓ\nisGenerator≃ℤ G g =\n Σ[ e ∈ GroupIso G ℤGroup ] abs (Iso.fun (fst e) g) ≡ 1\n\nisGenerator≃ℤ-e : isGenerator≃ℤ (coHomGr 2 CP²) GysinS².e\nisGenerator≃ℤ-e =\n subst (isGenerator≃ℤ (coHomGr 2 CP²)) (sym Gysin-e≡genCP²)\n (H²CP²≅ℤ , refl)\n\n-- Alternative definition of the hopfMap\nHopfMap' : S₊ 3 → S₊ 2\nHopfMap' x =\n hopfS¹.TotalSpaceHopfPush→TotalSpace\n (Iso.inv IsoTotalHopf'\n (Iso.inv (IsoSphereJoin 1 1) x)) .fst\n\nhopfMap≡HopfMap' : HopfMap ≡ (HopfMap' , refl)\nhopfMap≡HopfMap' =\n ΣPathP ((funExt (λ x →\n cong (λ x → JoinS¹S¹→TotalHopf x .fst)\n (sym (Iso.rightInv IsoTotalHopf'\n (Iso.inv (IsoSphereJoin 1 1) x)))\n ∙ sym (lem (Iso.inv IsoTotalHopf'\n (Iso.inv (IsoSphereJoin 1 1) x)))))\n , flipSquare (sym (rUnit refl) ◁ λ _ _ → north))\n where\n lem : (x : _) → hopfS¹.TotalSpaceHopfPush→TotalSpace x .fst\n ≡ JoinS¹S¹→TotalHopf (Iso.fun IsoTotalHopf' x) .fst\n lem (inl x) = refl\n lem (inr x) = refl\n lem (push (base , snd₁) i) = refl\n lem (push (loop i₁ , a) i) k = merid (rotLoop² a (~ k) i₁) i\n\nCP²' : Type _\nCP²' = Pushout {A = S₊ 3} (λ _ → tt) HopfMap'\n\nPushoutReplaceBase : ∀ {ℓ ℓ' ℓ''} {A B : Type ℓ} {C : Type ℓ'} {D : Type ℓ''}\n {f : A → C} {g : A → D} (e : B ≃ A)\n → Pushout (f ∘ fst e) (g ∘ fst e) ≡ Pushout f g\nPushoutReplaceBase {f = f} {g = g} =\n EquivJ (λ _ e → Pushout (f ∘ fst e) (g ∘ fst e) ≡ Pushout f g) refl\n\nCP2≡CP²' : CP²' ≡ CP²\nCP2≡CP²' =\n PushoutReplaceBase\n (isoToEquiv (compIso (invIso (IsoSphereJoin 1 1)) (invIso IsoTotalHopf')))\n\n-- packaging everything up:\n⌣equiv→pres1 : ∀ {ℓ} {G H : Type ℓ} → (G ≡ H)\n → (g₁ : coHom 2 G) (h₁ : coHom 2 H)\n → (fstEq : (Σ[ ϕ ∈ GroupEquiv (coHomGr 2 G) ℤGroup ]\n abs (fst (fst ϕ) g₁) ≡ 1))\n → (sndEq : ((Σ[ ϕ ∈ GroupEquiv (coHomGr 2 H) ℤGroup ]\n abs (fst (fst ϕ) h₁) ≡ 1)))\n → isEquiv {A = coHom 2 G} {B = coHom 4 G} (_⌣ g₁)\n → (3rdEq : GroupEquiv (coHomGr 4 H) ℤGroup)\n → abs (fst (fst 3rdEq) (h₁ ⌣ h₁)) ≡ 1\n⌣equiv→pres1 {G = G} = J (λ H _ → (g₁ : coHom 2 G) (h₁ : coHom 2 H)\n → (fstEq : (Σ[ ϕ ∈ GroupEquiv (coHomGr 2 G) ℤGroup ]\n abs (fst (fst ϕ) g₁) ≡ 1))\n → (sndEq : ((Σ[ ϕ ∈ GroupEquiv (coHomGr 2 H) ℤGroup ]\n abs (fst (fst ϕ) h₁) ≡ 1)))\n → isEquiv {A = coHom 2 G} {B = coHom 4 G} (_⌣ g₁)\n → (3rdEq : GroupEquiv (coHomGr 4 H) ℤGroup)\n → abs (fst (fst 3rdEq) (h₁ ⌣ h₁)) ≡ 1)\n help\n where\n help : (g₁ h₁ : coHom 2 G)\n → (fstEq : (Σ[ ϕ ∈ GroupEquiv (coHomGr 2 G) ℤGroup ]\n abs (fst (fst ϕ) g₁) ≡ 1))\n → (sndEq : ((Σ[ ϕ ∈ GroupEquiv (coHomGr 2 G) ℤGroup ]\n abs (fst (fst ϕ) h₁) ≡ 1)))\n → isEquiv {A = coHom 2 G} {B = coHom 4 G} (_⌣ g₁)\n → (3rdEq : GroupEquiv (coHomGr 4 G) ℤGroup)\n → abs (fst (fst 3rdEq) (h₁ ⌣ h₁)) ≡ 1\n help g h (ϕ , idg) (ψ , idh) ⌣eq ξ =\n ⊎→abs _ _\n (groupEquivPresGen _\n (compGroupEquiv main (compGroupEquiv (invGroupEquiv main) ψ))\n h (abs→⊎ _ _ (cong abs (cong (fst (fst ψ)) (retEq (fst main) h))\n ∙ idh)) (compGroupEquiv main ξ))\n where\n lem₁ : ((fst (fst ψ) h) ≡ 1) ⊎ (fst (fst ψ) h ≡ -1)\n → abs (fst (fst ϕ) h) ≡ 1\n lem₁ p = ⊎→abs _ _ (groupEquivPresGen _ ψ h p ϕ)\n\n lem₂ : ((fst (fst ϕ) h) ≡ 1) ⊎ (fst (fst ϕ) h ≡ -1)\n → ((fst (fst ϕ) g) ≡ 1) ⊎ (fst (fst ϕ) g ≡ -1)\n → (h ≡ g) ⊎ (h ≡ (-ₕ g))\n lem₂ (inl x) (inl x₁) =\n inl (sym (retEq (fst ϕ) h)\n ∙∙ cong (invEq (fst ϕ)) (x ∙ sym x₁)\n ∙∙ retEq (fst ϕ) g)\n lem₂ (inl x) (inr x₁) =\n inr (sym (retEq (fst ϕ) h)\n ∙∙ cong (invEq (fst ϕ)) x\n ∙ IsGroupHom.presinv (snd (invGroupEquiv ϕ)) (negsuc zero)\n ∙∙ cong (-ₕ_) (cong (invEq (fst ϕ)) (sym x₁) ∙ (retEq (fst ϕ) g)))\n lem₂ (inr x) (inl x₁) =\n inr (sym (retEq (fst ϕ) h)\n ∙∙ cong (invEq (fst ϕ)) x\n ∙∙ (IsGroupHom.presinv (snd (invGroupEquiv ϕ)) 1\n ∙ cong (-ₕ_) (cong (invEq (fst ϕ)) (sym x₁) ∙ (retEq (fst ϕ) g))))\n lem₂ (inr x) (inr x₁) =\n inl (sym (retEq (fst ϕ) h)\n ∙∙ cong (invEq (fst ϕ)) (x ∙ sym x₁)\n ∙∙ retEq (fst ϕ) g)\n\n -ₕeq : ∀ {ℓ} {A : Type ℓ} (n : ℕ) → Iso (coHom n A) (coHom n A)\n Iso.fun (-ₕeq n) = -ₕ_\n Iso.inv (-ₕeq n) = -ₕ_\n Iso.rightInv (-ₕeq n) =\n sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)\n λ f → cong ∣_∣₂ (funExt λ x → -ₖ^2 (f x))\n Iso.leftInv (-ₕeq n) =\n sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)\n λ f → cong ∣_∣₂ (funExt λ x → -ₖ^2 (f x))\n\n theEq : coHom 2 G ≃ coHom 4 G\n theEq = compEquiv (_ , ⌣eq) (isoToEquiv (-ₕeq 4))\n\n lem₃ : (h ≡ g) ⊎ (h ≡ (-ₕ g)) → isEquiv {A = coHom 2 G} (_⌣ h)\n lem₃ (inl x) = subst isEquiv (λ i → _⌣ (x (~ i))) ⌣eq\n lem₃ (inr x) =\n subst isEquiv (funExt (λ x → -ₕDistᵣ 2 2 x g) ∙ (λ i → _⌣ (x (~ i))))\n (theEq .snd)\n\n main : GroupEquiv (coHomGr 2 G) (coHomGr 4 G)\n fst main = _ ,\n (lem₃ (lem₂ (abs→⊎ _ _ (lem₁ (abs→⊎ _ _ idh))) (abs→⊎ _ _ idg)))\n snd main =\n makeIsGroupHom λ g1 g2 → rightDistr-⌣ _ _ g1 g2 h\n\n-- The hopf invariant is ±1 for both definitions of the hopf map\nHopfInvariant-HopfMap' :\n abs (HopfInvariant zero (HopfMap' , λ _ → HopfMap' (snd (S₊∙ 3)))) ≡ 1\nHopfInvariant-HopfMap' =\n cong abs (cong (Iso.fun (fst (Hopfβ-Iso zero (HopfMap' , refl))))\n (transportRefl (⌣-α 0 (HopfMap' , refl))))\n ∙ ⌣equiv→pres1 (sym CP2≡CP²')\n GysinS².e (Hopfα zero (HopfMap' , refl))\n (l isGenerator≃ℤ-e)\n (GroupIso→GroupEquiv (Hopfα-Iso 0 (HopfMap' , refl)) , refl)\n (snd (fst ⌣Equiv))\n (GroupIso→GroupEquiv (Hopfβ-Iso zero (HopfMap' , refl)))\n where\n l : Σ[ ϕ ∈ GroupIso (coHomGr 2 CP²) ℤGroup ]\n (abs (Iso.fun (fst ϕ) GysinS².e) ≡ 1)\n → Σ[ ϕ ∈ GroupEquiv (coHomGr 2 CP²) ℤGroup ]\n (abs (fst (fst ϕ) GysinS².e) ≡ 1)\n l p = (GroupIso→GroupEquiv (fst p)) , (snd p)\n\nHopfInvariant-HopfMap : abs (HopfInvariant zero HopfMap) ≡ 1\nHopfInvariant-HopfMap = cong abs (cong (HopfInvariant zero) hopfMap≡HopfMap')\n ∙ HopfInvariant-HopfMap'\n", "meta": {"hexsha": "278c0641319440784bf0d931bc59f5ea656793f6", "size": 22285, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Homotopy/HopfInvariant/HopfMap.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_issues_repo_path": "Cubical/Homotopy/HopfInvariant/HopfMap.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Homotopy/HopfInvariant/HopfMap.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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.5825932504, "max_line_length": 81, "alphanum_fraction": 0.5304913619, "num_tokens": 9320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.371458546804473}} {"text": "{-\n\nMaybe structure: X ↦ Maybe (S X)\n\n-}\n{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}\nmodule Cubical.Structures.Relational.Maybe where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Structure\nopen import Cubical.Foundations.RelationalStructure\nopen import Cubical.Data.Unit\nopen import Cubical.Data.Empty\nopen import Cubical.Data.Maybe\nopen import Cubical.Data.Sigma\nopen import Cubical.HITs.PropositionalTruncation as Trunc\nopen import Cubical.HITs.SetQuotients\n\nopen import Cubical.Structures.Maybe\n\nprivate\n variable\n ℓ ℓ₁ ℓ₁' ℓ₁'' : Level\n\n-- Structured relations\n\nMaybeRelStr : {S : Type ℓ → Type ℓ₁} {ℓ₁' : Level}\n → StrRel S ℓ₁' → StrRel (λ X → Maybe (S X)) ℓ₁'\nMaybeRelStr ρ R = MaybeRel (ρ R)\n\nmaybeSuitableRel : {S : Type ℓ → Type ℓ₁} {ρ : StrRel S ℓ₁'}\n → SuitableStrRel S ρ\n → SuitableStrRel (MaybeStructure S) (MaybeRelStr ρ)\nmaybeSuitableRel θ .quo (X , nothing) R _ .fst = nothing , _\nmaybeSuitableRel θ .quo (X , nothing) R _ .snd (nothing , _) = refl\nmaybeSuitableRel θ .quo (X , just s) R c .fst =\n just (θ .quo (X , s) R c .fst .fst) , θ .quo (X , s) R c .fst .snd\nmaybeSuitableRel θ .quo (X , just s) R c .snd (just s' , r) =\n cong (λ {(t , r') → just t , r'}) (θ .quo (X , s) R c .snd (s' , r))\nmaybeSuitableRel θ .symmetric R {nothing} {nothing} r = _\nmaybeSuitableRel θ .symmetric R {just s} {just t} r = θ .symmetric R r\nmaybeSuitableRel θ .transitive R R' {nothing} {nothing} {nothing} r r' = _\nmaybeSuitableRel θ .transitive R R' {just s} {just t} {just u} r r' = θ .transitive R R' r r'\nmaybeSuitableRel θ .set setX = isOfHLevelMaybe 0 (θ .set setX)\nmaybeSuitableRel θ .prop propR nothing nothing = isOfHLevelLift 1 isPropUnit\nmaybeSuitableRel θ .prop propR nothing (just y) = isOfHLevelLift 1 isProp⊥\nmaybeSuitableRel θ .prop propR (just x) nothing = isOfHLevelLift 1 isProp⊥\nmaybeSuitableRel θ .prop propR (just x) (just y) = θ .prop propR x y\n\nmaybeRelMatchesEquiv : {S : Type ℓ → Type ℓ₁} (ρ : StrRel S ℓ₁') {ι : StrEquiv S ℓ₁''}\n → StrRelMatchesEquiv ρ ι\n → StrRelMatchesEquiv (MaybeRelStr ρ) (MaybeEquivStr ι)\nmaybeRelMatchesEquiv ρ μ (X , nothing) (Y , nothing) _ = Lift≃Lift (idEquiv _)\nmaybeRelMatchesEquiv ρ μ (X , nothing) (Y , just y) _ = Lift≃Lift (idEquiv _)\nmaybeRelMatchesEquiv ρ μ (X , just x) (Y , nothing) _ = Lift≃Lift (idEquiv _)\nmaybeRelMatchesEquiv ρ μ (X , just x) (Y , just y) = μ (X , x) (Y , y)\n\nmaybeRelAction :\n {S : Type ℓ → Type ℓ₁} {ρ : StrRel S ℓ₁'}\n → StrRelAction ρ\n → StrRelAction (MaybeRelStr ρ)\nmaybeRelAction α .actStr f = map-Maybe (α .actStr f)\nmaybeRelAction α .actStrId s =\n funExt⁻ (cong map-Maybe (funExt (α .actStrId))) s ∙ map-Maybe-id s\nmaybeRelAction α .actRel h nothing nothing = _\nmaybeRelAction α .actRel h (just s) (just t) r = α .actRel h s t r\n\nmaybePositiveRel :\n {S : Type ℓ → Type ℓ₁} {ρ : StrRel S ℓ₁'} {θ : SuitableStrRel S ρ}\n → PositiveStrRel θ\n → PositiveStrRel (maybeSuitableRel θ)\nmaybePositiveRel σ .act = maybeRelAction (σ .act)\nmaybePositiveRel σ .reflexive nothing = _\nmaybePositiveRel σ .reflexive (just s) = σ .reflexive s\nmaybePositiveRel σ .detransitive R R' {nothing} {nothing} r = ∣ nothing , _ , _ ∣\nmaybePositiveRel σ .detransitive R R' {just s} {just u} rr' =\n Trunc.map (λ {(t , r , r') → just t , r , r'}) (σ .detransitive R R' rr')\nmaybePositiveRel {S = S} {ρ = ρ} {θ = θ} σ .quo {X} R =\n subst isEquiv\n (funExt\n (elimProp (λ _ → maybeSuitableRel θ .set squash/ _ _)\n (λ {nothing → refl; (just _) → refl})))\n (compEquiv (isoToEquiv isom) (congMaybeEquiv (_ , σ .quo R)) .snd)\n where\n fwd : Maybe (S X) / MaybeRel (ρ (R .fst .fst)) → Maybe (S X / ρ (R .fst .fst))\n fwd [ nothing ] = nothing\n fwd [ just s ] = just [ s ]\n fwd (eq/ nothing nothing r i) = nothing\n fwd (eq/ (just s) (just t) r i) = just (eq/ s t r i)\n fwd (squash/ _ _ p q i j) =\n isOfHLevelMaybe 0 squash/ _ _ (cong fwd p) (cong fwd q) i j\n\n bwd : Maybe (S X / ρ (R .fst .fst)) → Maybe (S X) / MaybeRel (ρ (R .fst .fst))\n bwd nothing = [ nothing ]\n bwd (just [ s ]) = [ just s ]\n bwd (just (eq/ s t r i)) = eq/ (just s) (just t) r i\n bwd (just (squash/ _ _ p q i j)) =\n squash/ _ _ (cong (bwd ∘ just) p) (cong (bwd ∘ just) q) i j\n\n open Iso\n isom : Iso (Maybe (S X) / MaybeRel (ρ (R .fst .fst))) (Maybe (S X / ρ (R .fst .fst)))\n isom .fun = fwd\n isom .inv = bwd\n isom .rightInv nothing = refl\n isom .rightInv (just x) =\n elimProp {B = λ x → fwd (bwd (just x)) ≡ just x}\n (λ _ → isOfHLevelMaybe 0 squash/ _ _)\n (λ _ → refl)\n x\n isom .leftInv = elimProp (λ _ → squash/ _ _) (λ {nothing → refl; (just _) → refl})\n\nmaybeRelMatchesTransp : {S : Type ℓ → Type ℓ₁}\n (ρ : StrRel S ℓ₁') (α : EquivAction S)\n → StrRelMatchesEquiv ρ (EquivAction→StrEquiv α)\n → StrRelMatchesEquiv (MaybeRelStr ρ) (EquivAction→StrEquiv (maybeEquivAction α))\nmaybeRelMatchesTransp _ _ μ (X , nothing) (Y , nothing) _ =\n isContr→Equiv (isOfHLevelLift 0 isContrUnit) isContr-nothing≡nothing\nmaybeRelMatchesTransp _ _ μ (X , nothing) (Y , just y) _ =\n uninhabEquiv lower ¬nothing≡just\nmaybeRelMatchesTransp _ _ μ (X , just x) (Y , nothing) _ =\n uninhabEquiv lower ¬just≡nothing\nmaybeRelMatchesTransp _ _ μ (X , just x) (Y , just y) e =\n compEquiv (μ (X , x) (Y , y) e) (_ , isEmbedding-just _ _)\n", "meta": {"hexsha": "5e521278e5316e83e43e0d0db20e20db2f71bf77", "size": 5435, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Structures/Relational/Maybe.agda", "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": "Cubical/Structures/Relational/Maybe.agda", "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_forks_repo_path": "Cubical/Structures/Relational/Maybe.agda", "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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.4609375, "max_line_length": 93, "alphanum_fraction": 0.6645814167, "num_tokens": 2049, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544210587586, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.37145050283945186}} {"text": "\nmodule Issue206 where\n\npostulate\n I : Set\n P : I → Set\n i : I\n Q : P i → Set\n\nFoo : (p : P i) → Q p → Set₁\nFoo p q with i\nFoo p q | i′ = Set\n\n-- Now better error message:\n-- Issue206.agda:11,1-19\n-- w != i of type I\n-- when checking that the type of the generated with function\n-- (w : I) (p : P w) (q : Q p) → Set₁ is well-formed\n", "meta": {"hexsha": "828bc7b2e53f4ace854c0d97fbad118b61d3e44e", "size": 336, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue206.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/Issue206.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/Issue206.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": 17.6842105263, "max_line_length": 61, "alphanum_fraction": 0.5833333333, "num_tokens": 127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6992544210587585, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.3714505028394518}} {"text": "{-# OPTIONS --safe #-}\n\nopen import Generics.Prelude hiding (lookup; pi; curry)\nopen import Generics.Telescope\nopen import Generics.Desc\nopen import Generics.All\nopen import Generics.HasDesc\nimport Generics.Helpers as Helpers\n\n\nmodule Generics.Constructions.Fold\n {P I ℓ} {A : Indexed P I ℓ} (H : HasDesc {P} {I} {ℓ} A)\n {p c} {X : Pred′ I λ i → Set c}\n where\n\nopen HasDesc H\n\nprivate\n variable\n V : ExTele P\n i : ⟦ I ⟧tel p\n v : ⟦ V ⟧tel p\n\nX′ : ⟦ I ⟧tel p → Set c\nX′ i = unpred′ I _ X i\n\n\n------------------------\n-- Types of the algebra\n\nlevelAlg : ConDesc P V I → Level\nlevelAlg (var _) = c\nlevelAlg (π {ℓ} _ _ C) = ℓ ⊔ levelAlg C\nlevelAlg (A ⊗ B) = levelAlg A ⊔ levelAlg B\n\nAlgIndArg : (C : ConDesc P V I) → ⟦ V ⟧tel p → Set (levelAlg C)\nAlgIndArg (var f) v = X′ (f (p , v))\nAlgIndArg (π ia S C) v = Π< ia > (S (p , v)) λ s → AlgIndArg C (v , s)\nAlgIndArg (A ⊗ B) v = AlgIndArg A v × AlgIndArg B v\n\nAlgCon : (C : ConDesc P V I) → ⟦ V ⟧tel p → Set (levelAlg C)\nAlgCon (var f) v = X′ (f (p , v))\nAlgCon (π ia S C) v = Π< ia > (S (p , v)) λ s → AlgCon C (v , s)\nAlgCon (A ⊗ B) v = AlgIndArg A v → AlgCon B v\n\nAlgebra : ∀ k → Set (levelAlg (lookupCon D k))\nAlgebra k = AlgCon (lookupCon D k) tt\n\n----------------\n-- Generic fold\n\nmodule _ (algs : Els Algebra) where\n\n fold-wf : (x : A′ (p , i)) → Acc x → X′ i\n\n foldData-wf : (x : ⟦ D ⟧Data A′ (p , i)) → AllDataω Acc D x → X′ i\n foldData-wf {i} (k , x) = foldCon (lookupCon D k) (algs k) x\n where\n foldIndArg : (C : ConDesc P V I)\n (x : ⟦ C ⟧IndArg A′ (p , v))\n → AllIndArgω Acc C x\n → AlgIndArg C v\n foldIndArg (var f) x a = fold-wf x a\n foldIndArg (π ia S C) x a = fun< ia > λ s → foldIndArg C (app< ia > x s) (a s)\n foldIndArg (A ⊗ B) (xa , xb) (aa , ab)\n = foldIndArg A xa aa\n , foldIndArg B xb ab\n\n foldCon : (C : ConDesc P V I)\n (alg : AlgCon C v)\n (x : ⟦ C ⟧Con A′ (p , v , i))\n → AllConω Acc C x\n → X′ i\n foldCon (var _) alg refl _ = alg\n foldCon (π ia S C) alg (s , x) a = foldCon C (app< ia > alg s) x a\n foldCon (A ⊗ B) alg (xa , xb) (aa , ab)\n = foldCon B (alg (foldIndArg A xa aa)) xb ab\n\n fold-wf x (acc a) = foldData-wf (split x) a\n\n fold : A′ (p , i) → X′ i\n fold x = fold-wf x (wf x)\n\nderiveFold : Arrows Algebra (Pred′ I λ i → A′ (p , i) → X′ i)\nderiveFold = curryₙ λ m → pred′ I _ λ i → fold m\n", "meta": {"hexsha": "9d1fadf841221b959c6e4747d3e4bab3efd016a8", "size": 2458, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Generics/Constructions/Fold.agda", "max_stars_repo_name": "flupe/generics", "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_issues_repo_path": "src/Generics/Constructions/Fold.agda", "max_issues_repo_name": "flupe/generics", "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_forks_repo_path": "src/Generics/Constructions/Fold.agda", "max_forks_repo_name": "flupe/generics", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "avg_line_length": 28.5813953488, "max_line_length": 84, "alphanum_fraction": 0.5288852726, "num_tokens": 954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7606506526772884, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.37141308332325906}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import lib.Basics\nopen import lib.types.Coproduct\nopen import lib.types.Paths\nopen import lib.types.Pointed\nopen import lib.types.Pushout\nopen import lib.types.PushoutFlattening\nopen import lib.types.Span\nopen import lib.types.Unit\n\n-- Wedge of two pointed types is defined as a particular case of pushout\n\nmodule lib.types.Wedge where\n\nmodule _ {i j} (X : Ptd i) (Y : Ptd j) where\n\n wedge-span : Span\n wedge-span = span (fst X) (fst Y) Unit (λ _ → snd X) (λ _ → snd Y)\n\n Wedge : Type (lmax i j)\n Wedge = Pushout wedge-span\n\n infix 80 _∨_\n _∨_ = Wedge\n\nmodule _ {i j} {X : Ptd i} {Y : Ptd j} where\n\n winl : fst X → X ∨ Y\n winl x = left x\n\n winr : fst Y → X ∨ Y\n winr y = right y\n\n wglue : winl (snd X) == winr (snd Y)\n wglue = glue tt\n\nmodule _ {i j} (X : Ptd i) (Y : Ptd j) where\n\n ⊙Wedge : Ptd (lmax i j)\n ⊙Wedge = ⊙[ Wedge X Y , winl (snd X) ]\n\n infix 80 _⊙∨_\n _⊙∨_ = ⊙Wedge\n\nmodule _ {i j} {X : Ptd i} {Y : Ptd j} where\n\n ⊙winl : fst (X ⊙→ X ⊙∨ Y)\n ⊙winl = (winl , idp)\n\n ⊙winr : fst (Y ⊙→ X ⊙∨ Y)\n ⊙winr = (winr , ! wglue)\n\nmodule _ {i j} {X : Ptd i} {Y : Ptd j} where\n\n module WedgeElim {k} {P : X ∨ Y → Type k}\n (winl* : (x : fst X) → P (winl x)) (winr* : (y : fst Y) → P (winr y))\n (wglue* : winl* (snd X) == winr* (snd Y) [ P ↓ wglue ]) where\n\n private\n module M = PushoutElim winl* winr* (λ _ → wglue*)\n\n f = M.f\n glue-β = M.glue-β unit\n\n open WedgeElim public using () renaming (f to Wedge-elim)\n\n\n module WedgeRec {k} {C : Type k} (winl* : fst X → C) (winr* : fst Y → C)\n (wglue* : winl* (snd X) == winr* (snd Y)) where\n\n private\n module M = PushoutRec {d = wedge-span X Y} winl* winr* (λ _ → wglue*)\n\n f = M.f\n glue-β = M.glue-β unit\n\n\nadd-wglue : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → fst (X ⊙⊔ Y) → X ∨ Y\nadd-wglue (inl x) = winl x\nadd-wglue (inr y) = winr y\n\n⊙add-wglue : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → fst (X ⊙⊔ Y ⊙→ X ⊙∨ Y)\n⊙add-wglue = (add-wglue , idp)\n\nmodule ⊙WedgeRec {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n (g : fst (X ⊙→ Z)) (h : fst (Y ⊙→ Z)) where\n\n open WedgeRec (fst g) (fst h) (snd g ∙ ! (snd h)) public\n\n ⊙f : fst (X ⊙∨ Y ⊙→ Z)\n ⊙f = (f , snd g)\n\n ⊙winl-β : ⊙f ⊙∘ ⊙winl == g\n ⊙winl-β = idp\n\n ⊙winr-β : ⊙f ⊙∘ ⊙winr == h\n ⊙winr-β = ⊙λ= (λ _ → idp) $\n ap (λ w → w ∙ snd g)\n (ap-! f wglue ∙ ap ! glue-β ∙ !-∙ (snd g) (! (snd h)))\n ∙ ∙-assoc (! (! (snd h))) (! (snd g)) (snd g)\n ∙ ap (λ w → ! (! (snd h)) ∙ w) (!-inv-l (snd g))\n ∙ ∙-unit-r (! (! (snd h)))\n ∙ !-! (snd h)\n\n⊙wedge-rec = ⊙WedgeRec.⊙f\n\n⊙wedge-rec-post∘ : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}\n (k : fst (Z ⊙→ W)) (g : fst (X ⊙→ Z)) (h : fst (Y ⊙→ Z))\n → k ⊙∘ ⊙wedge-rec g h == ⊙wedge-rec (k ⊙∘ g) (k ⊙∘ h)\n⊙wedge-rec-post∘ k g h = ⊙λ=\n (Wedge-elim (λ _ → idp) (λ _ → idp)\n (↓-='-in $ ⊙WedgeRec.glue-β (k ⊙∘ g) (k ⊙∘ h)\n ∙ lemma (fst k) (snd g) (snd h) (snd k)\n ∙ ! (ap (ap (fst k)) (⊙WedgeRec.glue-β g h))\n ∙ ∘-ap (fst k) (fst (⊙wedge-rec g h)) wglue))\n idp\n where\n lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y z : A} {w : B}\n (p : x == z) (q : y == z) (r : f z == w)\n → (ap f p ∙ r) ∙ ! (ap f q ∙ r) == ap f (p ∙ ! q)\n lemma f idp idp idp = idp\n\n⊙wedge-rec-η : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → ⊙wedge-rec ⊙winl ⊙winr == ⊙idf (X ⊙∨ Y)\n⊙wedge-rec-η = ⊙λ=\n (Wedge-elim (λ _ → idp) (λ _ → idp)\n (↓-='-in $ ap-idf wglue\n ∙ ! (!-! wglue)\n ∙ ! (⊙WedgeRec.glue-β ⊙winl ⊙winr)))\n idp\n\nmodule Fold {i} {X : Ptd i} = ⊙WedgeRec (⊙idf X) (⊙idf X)\nfold = Fold.f\n⊙fold = Fold.⊙f\n\nmodule _ {i j} (X : Ptd i) (Y : Ptd j) where\n\n module Projl = ⊙WedgeRec (⊙idf X) (⊙cst {X = Y})\n module Projr = ⊙WedgeRec (⊙cst {X = X}) (⊙idf Y)\n\n projl = Projl.f\n projr = Projr.f\n ⊙projl = Projl.⊙f\n ⊙projr = Projr.⊙f\n", "meta": {"hexsha": "a1ccb9059f0c41de457aadd344d110c378062d53", "size": 3841, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lib/types/Wedge.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": "lib/types/Wedge.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": "lib/types/Wedge.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": 25.9527027027, "max_line_length": 78, "alphanum_fraction": 0.497005988, "num_tokens": 1849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5964331319177487, "lm_q2_score": 0.6224593312018546, "lm_q1q2_score": 0.3712553684001494}} {"text": "-- Andreas, 2013-10-26, reported by Jesper Cockx\n\n{-# OPTIONS --cubical-compatible #-}\n\nmodule Issue920a where\n\nimport Common.Level\nopen import Common.Equality\n\nrecord ⊥ : Set where\n\ndata Bool : Set where\n true false : Bool\n\n-- Standard eliminator for ≡\nJ : ∀ {a b} {A : Set a} {x : A} {Φ : (y : A) → x ≡ y → Set b} →\n Φ x refl → {y : A} → (e : x ≡ y) → Φ y e\nJ φ refl = φ\n\n-- A kind of heterogeneous equality\n_≃_ : {A : Set} (x : A) {A' : Set} → A' → Set _\n_≃_ {A} x {A'} x' = (E : A ≡ A') → J x E ≡ x'\n\n-- It shouldn't be possible to define this without K\n≃refl : {A : Set} {x : A} → x ≃ x\n≃refl {x = x} = λ E → J {Φ = λ A' E' → J x E' ≡ _} refl E\n\n-- These can be given using univalence\npostulate Swap : Bool ≡ Bool\npostulate swap : true ≡ J {Φ = λ A _ → A} false Swap\n\n-- Univalence and ≃refl don't play nice together\nright : (true ≡ false) → ⊥\nright ()\n\nwrong : true ≡ false\nwrong = trans swap (≃refl Swap)\n\nmadness : ⊥\nmadness = right wrong\n", "meta": {"hexsha": "d48eefc1753b40a3ea504f55a6bb336dcbccd12f", "size": 959, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue920a.agda", "max_stars_repo_name": "KDr2/agda", "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": ["BSD-2-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/Issue920a.agda", "max_issues_repo_name": "KDr2/agda", "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_forks_repo_path": "test/Fail/Issue920a.agda", "max_forks_repo_name": "KDr2/agda", "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3902439024, "max_line_length": 63, "alphanum_fraction": 0.5797705944, "num_tokens": 368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7662936324115011, "lm_q2_score": 0.4843800842769844, "lm_q1q2_score": 0.3711773742483994}} {"text": "\nmodule Printf where\nimport AlonzoPrelude\nimport PreludeList\nimport PreludeShow\nimport PreludeString\nimport PreludeNat\n\nopen AlonzoPrelude\nopen PreludeList hiding (_++_)\nopen PreludeShow\nopen PreludeString\nopen PreludeNat\n\ndata Unit : Set where\n unit : Unit\n\ndata Format : Set where\n stringArg : Format\n natArg : Format\n intArg : Format\n floatArg : Format\n charArg : Format\n litChar : Char -> Format\n badFormat : Char -> Format\n\ndata BadFormat (c : Char) : Set where\n\nformat : String -> List Format\nformat s = format' (toList s)\n where\n format' : List Char -> List Format\n format' ('%' :: 's' :: fmt) = stringArg :: format' fmt\n format' ('%' :: 'n' :: fmt) = natArg :: format' fmt\n format' ('%' :: 'd' :: fmt) = intArg :: format' fmt\n format' ('%' :: 'f' :: fmt) = floatArg :: format' fmt\n format' ('%' :: 'c' :: fmt) = charArg :: format' fmt\n format' ('%' :: '%' :: fmt) = litChar '%' :: format' fmt\n format' ('%' :: c :: fmt) = badFormat c :: format' fmt\n format' (c\t\t:: fmt) = litChar c :: format' fmt\n format' []\t\t= []\n\nPrintf' : List Format -> Set\nPrintf' (stringArg :: fmt) = String × Printf' fmt\nPrintf' (natArg :: fmt) = Nat × Printf' fmt\nPrintf' (intArg :: fmt) = Int × Printf' fmt\nPrintf' (floatArg :: fmt) = Float × Printf' fmt\nPrintf' (charArg :: fmt) = Char × Printf' fmt\nPrintf' (badFormat c :: fmt) = BadFormat c\nPrintf' (litChar _ :: fmt) = Printf' fmt\nPrintf' []\t\t = Unit\n\nPrintf : String -> Set\nPrintf fmt = Printf' (format fmt)\n\n{-\nprintf' : (fmt : List Format) -> Printf' fmt -> String\nprintf' (stringArg :: fmt) < s , args > = s\t\t\t ++ printf' fmt args\nprintf' (natArg :: fmt) < n , args > = showNat n\t\t ++ printf' fmt args\nprintf' (intArg :: fmt) < n , args > = showInt n\t\t ++ printf' fmt args\nprintf' (floatArg :: fmt) < x , args > = showFloat x\t ++ printf' fmt args\nprintf' (charArg :: fmt) < c , args > = showChar c\t ++ printf' fmt args\nprintf' (litChar c :: fmt) args = fromList (c :: []) ++ printf' fmt args\nprintf' (badFormat _ :: fmt) ()\nprintf' []\t\t unit = \"\"\n-}\nprintf : (fmt : String) -> Printf fmt -> String\nprintf fmt = printf' (format fmt)\n where\n printf' : (fmt : List Format) -> Printf' fmt -> String\n printf' (stringArg :: fmt) < s , args > = s\t\t\t ++ printf' fmt args\n printf' (natArg :: fmt) < n , args > = showNat n\t\t ++ printf' fmt args\n printf' (intArg :: fmt) < n , args > = showInt n\t\t ++ printf' fmt args\n printf' (floatArg :: fmt) < x , args > = showFloat x\t ++ printf' fmt args\n printf' (charArg :: fmt) < c , args > = showChar c\t ++ printf' fmt args\n printf' (litChar c :: fmt) args\t = fromList (c :: []) ++ printf' fmt args\n printf' (badFormat _ :: fmt) ()\n printf' []\t\t unit \t = \"\"\n\nmainS : String\n-- mainS = printf \"pi = %f\" < 3.14 , unit >\nmainS = printf \"Answer is %n, pi = %f %% %s\"\n\t< 42 , < 3.14159 , < \"Alonzo\" , unit > > >\n", "meta": {"hexsha": "ac35a3ab91585bfeed4f178ec50fba81ac17bcb7", "size": 2974, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "examples/outdated-and-incorrect/Alonzo/Printf.agda", "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "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": "examples/outdated-and-incorrect/Alonzo/Printf.agda", "max_issues_repo_name": "larrytheliquid/agda", "max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "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": "examples/outdated-and-incorrect/Alonzo/Printf.agda", "max_forks_repo_name": "larrytheliquid/agda", "max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "avg_line_length": 35.4047619048, "max_line_length": 82, "alphanum_fraction": 0.5645595158, "num_tokens": 951, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191460821871, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.3711150488448729}} {"text": "------------------------------------------------------------------------\n-- Trees\n------------------------------------------------------------------------\n\n-- This example is based on one in Wadler's \"A prettier printer\".\n\n{-# OPTIONS --guardedness #-}\n\nmodule Examples.Tree where\n\nopen import Codata.Musical.Notation\nopen import Data.List\nopen import Data.List.NonEmpty as List⁺\nopen import Relation.Binary.PropositionalEquality using (_≡_; refl)\n\nopen import Examples.Identifier\nimport Grammar.Infinite\nimport Pretty\nopen import Renderer\nopen import Utilities\n\ndata Tree : Set where\n node : Identifier → List Tree → Tree\n\nmodule _ where\n\n open Grammar.Infinite\n\n mutual\n\n tree : Grammar Tree\n tree = node <$> identifier-w ⊛ brackets\n\n brackets : Grammar (List Tree)\n brackets = return []\n ∣ List⁺.toList <$> (symbol′ \"[\" ⊛> ♯ trees <⊛ symbol′ \"]\")\n\n trees : Grammar (List⁺ Tree)\n trees = _∷_ <$> tree ⊛ commas-and-trees\n\n commas-and-trees : Grammar (List Tree)\n commas-and-trees = (symbol′ \",\" ⊛> tree) ⋆\n\nopen Pretty\n\n-- Wadler presents two pretty-printers for trees in his final code\n-- listing (§11.7). I've included corresponding, but not quite\n-- identical, implementations here.\n--\n-- (One of Wadler's implementations is buggy: recursive calls to\n-- showTree/showTrees should most likely have referred to\n-- showTree'/showTrees'. The code below is intended to match a\n-- corrected version of Wadler's.)\n\nmodule Printer₁ where\n\n mutual\n\n tree-printer : Pretty-printer tree\n tree-printer (node s ts) =\n group (<$> identifier-w-printer s ⊛\n nest (List⁺.length s) (brackets-printer ts))\n\n brackets-printer : Pretty-printer brackets\n brackets-printer [] = left nil\n brackets-printer (t ∷ ts) =\n right (<$> (symbol ⊛> nest 1 (trees-printer (t ∷ ts)) <⊛ symbol))\n\n trees-printer : Pretty-printer trees\n trees-printer (t ∷ ts) =\n <$> tree-printer t ⊛ commas-and-trees-printer ts\n\n commas-and-trees-printer : Pretty-printer commas-and-trees\n commas-and-trees-printer [] = nil-⋆\n commas-and-trees-printer (t ∷ ts) =\n cons-⋆ (symbol-line ⊛> tree-printer t)\n (commas-and-trees-printer ts)\n\nmodule Printer₂ where\n\n mutual\n\n tree-printer : Pretty-printer tree\n tree-printer (node s ts) =\n <$> identifier-w-printer s ⊛ brackets-printer ts\n\n brackets-printer : Pretty-printer brackets\n brackets-printer [] = left nil\n brackets-printer (t ∷ ts) =\n right (<$> bracket 7 (trees-printer (t ∷ ts)))\n\n trees-printer : Pretty-printer trees\n trees-printer (t ∷ ts) =\n <$> tree-printer t ⊛ commas-and-trees-printer ts\n\n commas-and-trees-printer : Pretty-printer commas-and-trees\n commas-and-trees-printer [] = nil-⋆\n commas-and-trees-printer (t ∷ ts) =\n cons-⋆ (symbol-line ⊛> tree-printer t)\n (commas-and-trees-printer ts)\n\nt : Tree\nt = node (str⁺ \"aaa\")\n (node (str⁺ \"bbbbb\")\n (node (str⁺ \"ccc\") [] ∷\n node (str⁺ \"dd\") [] ∷\n []) ∷\n node (str⁺ \"eee\") [] ∷\n node (str⁺ \"ffff\")\n (node (str⁺ \"gg\") [] ∷\n node (str⁺ \"hhh\") [] ∷\n node (str⁺ \"ii\") [] ∷\n []) ∷\n [])\n\ntest₁ : render 0 (Printer₁.tree-printer t) ≡\n \"aaa[bbbbb[ccc,\\n dd],\\n eee,\\n ffff[gg,\\n hhh,\\n ii]]\"\ntest₁ = refl\n\ntest₂ : render 30 (Printer₁.tree-printer t) ≡\n \"aaa[bbbbb[ccc, dd],\\n eee,\\n ffff[gg, hhh, ii]]\"\ntest₂ = refl\n\ntest₃ : render 0 (Printer₂.tree-printer t) ≡\n \"aaa[\\n bbbbb[\\n ccc,\\n dd\\n ],\\n eee,\\n ffff[\\n gg,\\n hhh,\\n ii\\n ]\\n]\"\ntest₃ = refl\n\ntest₄ : render 80 (Printer₂.tree-printer t) ≡\n \"aaa[ bbbbb[ ccc, dd ], eee, ffff[ gg, hhh, ii ] ]\"\ntest₄ = refl\n", "meta": {"hexsha": "c38a6a8cb11bc8ed5f566dcb7f2cf7a6d99105a4", "size": 3786, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Examples/Tree.agda", "max_stars_repo_name": "nad/pretty", "max_stars_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492", "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": "Examples/Tree.agda", "max_issues_repo_name": "nad/pretty", "max_issues_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492", "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": "Examples/Tree.agda", "max_forks_repo_name": "nad/pretty", "max_forks_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492", "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": 28.9007633588, "max_line_length": 100, "alphanum_fraction": 0.5826730058, "num_tokens": 1127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5926666143434, "lm_q2_score": 0.6261241772283034, "lm_q1q2_score": 0.3710828962764455}} {"text": "\nmodule Issue292-19 where\n\npostulate\n I : Set\n i₁ i₂ : I\n J : Set\n j : I → J\n\ndata D : I → Set where\n d₁ : D i₁\n d₂ : D i₂\n\ndata P : ∀ i → D i → Set where\n p₁ : P i₁ d₁\n p₂ : P i₂ d₂\n\ndata P′ : ∀ i → D i → Set where\n p₁ : P′ i₁ d₁\n\ndata E : J → Set where\n e₁ : E (j i₁)\n e₂ : E (j i₂)\n\ndata Q : ∀ i → E i → Set where\n q₁ : Q (j i₁) e₁\n q₂ : Q (j i₂) e₂\n\nOk : Q (j i₁) e₁ → Set₁\nOk q₁ = Set\n\nAlsoOk : P i₁ d₁ → Set₁\nAlsoOk p₁ = Set\n\nFoo : ∀ {i} (d : D i) → P′ i d → Set₁\nFoo d₁ _ = Set\nFoo d₂ ()\n", "meta": {"hexsha": "29eeb695ef9aaabc671715b96b5e98e6aed743db", "size": 521, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue292-19.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/Succeed/Issue292-19.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/Succeed/Issue292-19.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": 13.7105263158, "max_line_length": 37, "alphanum_fraction": 0.4875239923, "num_tokens": 257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.37092815657617545}} {"text": "-- Andreas, 2019-12-03, issue #4200 reported and testcase by nad\n\nopen import Agda.Builtin.Bool\n\ndata D : Set where\n c₁ : D\n @0 c₂ : D\n\nf : D → Bool\nf c₁ = true\nf c₂ = false\n\n@0 _ : D\n_ = c₂ -- OK.\n\n_ : D\n_ = c₂ -- Not allowed.\n\n-- Expected error:\n\n-- Identifier c₂ is declared erased, so it cannot be used here\n-- when checking that the expression c₂ has type D\n", "meta": {"hexsha": "e3354b32677cbf95f5f9c1c1a57dd4cf673caa0f", "size": 367, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue4200.agda", "max_stars_repo_name": "cagix/agda", "max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_stars_repo_licenses": ["BSD-2-Clause"], "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/Issue4200.agda", "max_issues_repo_name": "cagix/agda", "max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_issues_repo_licenses": ["BSD-2-Clause"], "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/Issue4200.agda", "max_forks_repo_name": "cagix/agda", "max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_forks_repo_licenses": ["BSD-2-Clause"], "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": 15.9565217391, "max_line_length": 64, "alphanum_fraction": 0.6457765668, "num_tokens": 125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.668880247169804, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.37087434165108674}} {"text": "open import Nat\nopen import Prelude\nopen import List\nopen import judgemental-erase\nopen import lemmas-matching\nopen import statics-core\nopen import synth-unicity\n\nmodule moveerase where\n -- type actions don't change the term other than moving the cursor\n -- around\n moveeraset : {t t' : ztyp} {δ : direction} →\n (t + move δ +> t') →\n (t ◆t) == (t' ◆t)\n moveeraset TMArrChild1 = refl\n moveeraset TMArrChild2 = refl\n moveeraset TMArrParent1 = refl\n moveeraset TMArrParent2 = refl\n moveeraset (TMArrZip1 {t2 = t2} m) = ap1 (λ x → x ==> t2) (moveeraset m)\n moveeraset (TMArrZip2 {t1 = t1} m) = ap1 (λ x → t1 ==> x) (moveeraset m)\n moveeraset TMPlusChild1 = refl\n moveeraset TMPlusChild2 = refl\n moveeraset TMPlusParent1 = refl\n moveeraset TMPlusParent2 = refl\n moveeraset (TMPlusZip1 {t2 = t2} m) = ap1 (λ x → x ⊕ t2) (moveeraset m)\n moveeraset (TMPlusZip2 {t1 = t1} m) = ap1 (λ x → t1 ⊕ x) (moveeraset m)\n moveeraset TMProdChild1 = refl\n moveeraset TMProdChild2 = refl\n moveeraset TMProdParent1 = refl\n moveeraset TMProdParent2 = refl\n moveeraset (TMProdZip1 {t2 = t2} m) = ap1 (λ x → x ⊠ t2) (moveeraset m)\n moveeraset (TMProdZip2 {t1 = t1} m) = ap1 (λ x → t1 ⊠ x) (moveeraset m)\n \n -- the actual movements don't change the erasure\n moveerase : {e e' : zexp} {δ : direction} →\n (e + move δ +>e e') →\n (e ◆e) == (e' ◆e)\n moveerase EMAscChild1 = refl\n moveerase EMAscChild2 = refl\n moveerase EMAscParent1 = refl\n moveerase EMAscParent2 = refl\n moveerase EMLamChild1 = refl\n moveerase EMLamParent = refl\n moveerase EMHalfLamChild1 = refl\n moveerase EMHalfLamChild2 = refl\n moveerase EMHalfLamParent1 = refl\n moveerase EMHalfLamParent2 = refl\n moveerase EMPlusChild1 = refl\n moveerase EMPlusChild2 = refl\n moveerase EMPlusParent1 = refl\n moveerase EMPlusParent2 = refl\n moveerase EMApChild1 = refl\n moveerase EMApChild2 = refl\n moveerase EMApParent1 = refl\n moveerase EMApParent2 = refl\n moveerase EMNEHoleChild1 = refl\n moveerase EMNEHoleParent = refl\n moveerase EMInlChild1 = refl\n moveerase EMInlParent = refl\n moveerase EMInrChild1 = refl\n moveerase EMInrParent = refl\n moveerase EMCaseParent1 = refl\n moveerase EMCaseParent2 = refl\n moveerase EMCaseParent3 = refl\n moveerase EMCaseChild1 = refl\n moveerase EMCaseChild2 = refl\n moveerase EMCaseChild3 = refl\n moveerase EMPairChild1 = refl\n moveerase EMPairChild2 = refl\n moveerase EMPairParent1 = refl\n moveerase EMPairParent2 = refl\n moveerase EMFstChild1 = refl\n moveerase EMFstParent = refl\n moveerase EMSndChild1 = refl\n moveerase EMSndParent = refl\n \n -- this form is essentially the same as above, but for judgemental\n -- erasure, which is sometimes more convenient.\n moveerasee' : {e e' : zexp} {e◆ : hexp} {δ : direction} →\n erase-e e e◆ →\n e + move δ +>e e' →\n erase-e e' e◆\n moveerasee' er1 m with erase-e◆ er1\n ... | refl = ◆erase-e _ _ (! (moveerase m))\n\n moveeraset' : ∀{t t◆ t'' δ} →\n erase-t t t◆ →\n t + move δ +> t'' →\n erase-t t'' t◆\n moveeraset' er m with erase-t◆ er\n moveeraset' er m | refl = ◆erase-t _ _ (! (moveeraset m))\n\n -- movements don't change either the type or expression under expression\n -- actions\n mutual\n moveerase-synth : ∀{Γ e e' e◆ t t' δ } →\n erase-e e e◆ →\n Γ ⊢ e◆ => t →\n Γ ⊢ e => t ~ move δ ~> e' => t' →\n (e ◆e) == (e' ◆e) × t == t'\n moveerase-synth er wt (SAMove x) = moveerase x , refl\n moveerase-synth (EEPlusL er) (SPlus x x₁) (SAZipPlus1 x₂) =\n ap1 (λ q → q ·+ _) (moveerase-ana er x x₂) , refl\n moveerase-synth (EEPlusR er) (SPlus x x₁) (SAZipPlus2 x₂) =\n ap1 (λ q → _ ·+ q) (moveerase-ana er x₁ x₂) , refl\n moveerase-synth (EEAscL er) (SAsc x) (SAZipAsc1 x₁) =\n ap1 (λ q → q ·: _) (moveerase-ana er x x₁) , refl\n moveerase-synth er wt (SAZipAsc2 x x₁ x₂ x₃)\n with moveeraset x\n ... | qq = ap1 (λ q → _ ·: q) qq , eq-ert-trans qq x₂ x₁\n moveerase-synth (EEHalfLamL x) (SLam x₁ wt) (SAZipLam1 x₂ x₃ x₄ x₅ x₆ x₇)\n with erase-t◆ x₃\n ... | refl with erase-t◆ x₄\n ... | refl with moveeraset x₅\n ... | qq rewrite qq with synthunicity x₇ x₆\n ... | refl = refl , refl\n moveerase-synth (EEHalfLamR er) (SLam x wt) (SAZipLam2 x₁ x₂ x₃ x₄)\n with moveerase-synth x₂ x₃ x₄\n ... | qq , refl rewrite qq = refl , refl\n moveerase-synth (EEApL er) (SAp wt x x₁) (SAZipApArr x₂ x₃ x₄ d x₅)\n with erasee-det x₃ er\n ... | refl with synthunicity wt x₄\n ... | refl with moveerase-synth er x₄ d\n ... | pp , refl with ▸arr-unicity x x₂\n ... | refl = (ap1 (λ q → q ∘ _) pp ) , refl\n moveerase-synth (EEApR er) (SAp wt x x₁) (SAZipApAna x₂ x₃ x₄)\n with synthunicity x₃ wt\n ... | refl with ▸arr-unicity x x₂\n ... | refl = ap1 (λ q → _ ∘ q) (moveerase-ana er x₁ x₄ ) , refl\n moveerase-synth er wt (SAZipNEHole x x₁ d) =\n ap1 ⦇⌜_⌟⦈[ _ ] (π1 (moveerase-synth x x₁ d)) , refl\n moveerase-synth er wt (SAZipPair1 x x₁ x₂ x₃) with moveerase-synth x x₁ x₂\n ... | π1 , refl = (ap1 (λ q → ⟨ q , _ ⟩) π1) , refl\n moveerase-synth er wt (SAZipPair2 x x₁ x₂ x₃) with moveerase-synth x₁ x₂ x₃\n ... | π1 , refl = (ap1 (λ q → ⟨ _ , q ⟩) π1) , refl\n moveerase-synth er wt (SAZipFst x x₁ x₂ x₃ x₄)\n with moveerase-synth x₂ x₃ x₄\n ... | π1 , refl with ▸prod-unicity x₁ x\n ... | refl = (ap1 fst π1) , refl\n moveerase-synth er wt (SAZipSnd x x₁ x₂ x₃ x₄)\n with moveerase-synth x₂ x₃ x₄\n ... | π1 , refl with ▸prod-unicity x₁ x\n ... | refl = (ap1 snd π1) , refl\n \n moveerase-ana : ∀{Γ e e' e◆ t δ } →\n erase-e e e◆ →\n Γ ⊢ e◆ <= t →\n Γ ⊢ e ~ move δ ~> e' ⇐ t →\n (e ◆e) == (e' ◆e)\n moveerase-ana er wt (AASubsume x x₁ x₂ x₃) = π1 (moveerase-synth x x₁ x₂)\n moveerase-ana er wt (AAMove x) = moveerase x\n moveerase-ana (EELam er) (ASubsume () x₂) _\n moveerase-ana (EELam er) (ALam x₁ x₂ wt) (AAZipLam x₃ x₄ d) with ▸arr-unicity x₂ x₄\n ... | refl = ap1 (λ q → ·λ _ q) (moveerase-ana er wt d)\n moveerase-ana (EEInl er) (ASubsume () x₁) (AAZipInl x₂ d)\n moveerase-ana (EEInl er) (AInl x wt) (AAZipInl x₁ d) with ▸sum-unicity x x₁\n ... | refl = ap1 inl (moveerase-ana er wt d)\n moveerase-ana (EEInr er) (ASubsume () x₁) (AAZipInr x₂ d)\n moveerase-ana (EEInr er) (AInr x wt) (AAZipInr x₁ d) with ▸sum-unicity x x₁\n ... | refl = ap1 inr (moveerase-ana er wt d)\n moveerase-ana er wt (AAZipCase1 x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈) =\n ap1 (λ q → case q _ _ _ _) (π1(moveerase-synth x₃ x₄ x₅))\n moveerase-ana (EECase2 er) (ASubsume () x₂) (AAZipCase2 x₃ x₄ x₅ x₆ d)\n moveerase-ana (EECase2 er) (ACase x₁ x₂ x₃ x₄ wt wt₁) (AAZipCase2 x₅ x₆ x₇ x₈ d)\n with synthunicity x₄ x₇\n ... | refl with ▸sum-unicity x₃ x₈\n ... | refl = ap1 (λ q → case _ _ q _ _) (moveerase-ana er wt d)\n moveerase-ana (EECase3 er) (ASubsume () x₂) (AAZipCase3 x₃ x₄ x₅ x₆ d)\n moveerase-ana (EECase3 er) (ACase x₁ x₂ x₃ x₄ wt wt₁) (AAZipCase3 x₅ x₆ x₇ x₈ d)\n with synthunicity x₄ x₇\n ... | refl with ▸sum-unicity x₃ x₈\n ... | refl = ap1 (λ q → case _ _ _ _ q) (moveerase-ana er wt₁ d)\n \n", "meta": {"hexsha": "b30d6e5517b9b68cac74f3ba3b717262e6e09a7d", "size": 7298, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "moveerase.agda", "max_stars_repo_name": "hazelgrove/hazelnut-agda", "max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": "moveerase.agda", "max_issues_repo_name": "hazelgrove/hazelnut-agda", "max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": "moveerase.agda", "max_forks_repo_name": "hazelgrove/hazelnut-agda", "max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": 41.9425287356, "max_line_length": 87, "alphanum_fraction": 0.6118114552, "num_tokens": 2889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419958239132, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.37063164356617595}} {"text": "------------------------------------------------------------------------\n-- Encoders and decoders\n------------------------------------------------------------------------\n\nopen import Atom\n\nmodule Coding (atoms : χ-atoms) where\n\nopen import Equality.Propositional\nopen import Prelude hiding (const)\nopen import Tactic.By.Propositional\n\nopen import Bijection equality-with-J as Bijection using (_↔_)\nopen import Equality.Decision-procedures equality-with-J\nopen import Function-universe equality-with-J hiding (id; _∘_)\nopen import Injection equality-with-J using (Injective)\nopen import List equality-with-J using (foldr)\nopen import Maybe equality-with-J\nopen import Monad equality-with-J\n\nopen import Chi atoms\nopen import Constants atoms\nopen import Free-variables atoms\nopen import Values atoms\n\nopen χ-atoms atoms\n\n------------------------------------------------------------------------\n-- General definitions\n\n-- Representation functions.\n\nrecord Rep {a b} (A : Type a) (B : Type b) : Type (a ⊔ b) where\n field\n -- Representation function.\n ⌜_⌝ : A → B\n\n -- ⌜_⌝ is injective.\n rep-injective : Injective ⌜_⌝\n\nopen Rep ⦃ … ⦄ public\n\n-- An identity encoder.\n\nid-rep : ∀ {a} {A : Type a} → Rep A A\nid-rep = record\n { ⌜_⌝ = id\n ; rep-injective = id\n }\n\n-- Composition of representation functions.\n\ninfixr 9 _∘-rep_\n\n_∘-rep_ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →\n Rep B C → Rep A B → Rep A C\nr₁ ∘-rep r₂ = record\n { ⌜_⌝ = R₁.⌜_⌝ ∘ R₂.⌜_⌝\n ; rep-injective = λ {x y} →\n R₁.⌜ R₂.⌜ x ⌝ ⌝ ≡ R₁.⌜ R₂.⌜ y ⌝ ⌝ ↝⟨ R₁.rep-injective ⟩\n R₂.⌜ x ⌝ ≡ R₂.⌜ y ⌝ ↝⟨ R₂.rep-injective ⟩□\n x ≡ y □\n }\n where\n module R₁ = Rep r₁\n module R₂ = Rep r₂\n\n-- Encoder/decoder pairs.\n\nrecord Code {a b} (A : Type a) (B : Type b) : Type (a ⊔ b) where\n field\n -- Encoder.\n code : A → B\n\n -- Partial decoder.\n decode : B → Maybe A\n\n -- The decoder must decode encoded values successfully.\n decode∘code : ∀ x → decode (code x) ≡ just x\n\n -- The encoder is injective.\n\n code-injective : Injective code\n code-injective {x} {y} eq = ⊎.cancel-inj₂ (\n just x ≡⟨ by decode∘code ⟩\n decode (code x) ≡⟨ by eq ⟩\n decode (code y) ≡⟨ by decode∘code ⟩∎\n just y ∎)\n\n -- Encoder/decoder pairs can be turned into representation\n -- functions.\n\n rep : Rep A B\n rep = record\n { ⌜_⌝ = code\n ; rep-injective = code-injective\n }\n\nopen Code ⦃ … ⦄ public\n\n-- Converts bijections to encoders.\n\n↔→Code : ∀ {a b} {A : Type a} {B : Type b} → A ↔ B → Code A B\n↔→Code A↔B = record\n { code = to\n ; decode = λ b → just (from b)\n ; decode∘code = λ a →\n just (from (to a)) ≡⟨ cong just (left-inverse-of a) ⟩\n just a ∎\n }\n where\n open _↔_ A↔B\n\n-- An identity encoder.\n\nid-code : ∀ {a} {A : Type a} → Code A A\nid-code = ↔→Code Bijection.id\n\n-- Composition of encoders.\n\ninfixr 9 _∘-code_\n\n_∘-code_ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →\n Code B C → Code A B → Code A C\nc₁ ∘-code c₂ = record\n { code = C₁.code ∘ C₂.code\n ; decode = λ c → C₁.decode c >>=′ C₂.decode\n ; decode∘code = λ a →\n C₁.decode (C₁.code (C₂.code a)) >>=′ C₂.decode ≡⟨ cong (_>>=′ _) (C₁.decode∘code (C₂.code a)) ⟩\n return (C₂.code a) >>=′ C₂.decode ≡⟨⟩\n C₂.decode (C₂.code a) ≡⟨ by C₂.decode∘code ⟩∎\n return a ∎\n }\n where\n module C₁ = Code c₁\n module C₂ = Code c₂\n\n------------------------------------------------------------------------\n-- Some general definitions related to χ\n\n-- Constructor applications can be encoded as expressions (that are\n-- also constructor applications).\n\ncode-Consts : ∃ λ (cd : Code Consts Exp) →\n ∀ c → Constructor-application (Code.code cd c)\ncode-Consts = record\n { code = cd\n ; decode = dc\n ; decode∘code = dc∘cd\n } , cd-cs\n where\n mutual\n\n cd : Consts → Exp\n cd (const c cs) = const c (cd⋆ cs)\n\n cd⋆ : List Consts → List Exp\n cd⋆ [] = []\n cd⋆ (c ∷ cs) = cd c ∷ cd⋆ cs\n\n mutual\n\n cd-cs : ∀ c → Constructor-application (cd c)\n cd-cs (const c cs) = const c (cd⋆-cs cs)\n\n cd⋆-cs : ∀ cs → Constructor-applications (cd⋆ cs)\n cd⋆-cs [] = []\n cd⋆-cs (c ∷ cs) = cd-cs c ∷ cd⋆-cs cs\n\n mutual\n\n dc : Exp → Maybe Consts\n dc (const c es) = const c ⟨$⟩ dc⋆ es\n dc _ = nothing\n\n dc⋆ : List Exp → Maybe (List Consts)\n dc⋆ [] = return []\n dc⋆ (e ∷ es) = _∷_ ⟨$⟩ dc e ⊛ dc⋆ es\n\n mutual\n\n dc∘cd : ∀ c → dc (cd c) ≡ just c\n dc∘cd (const c cs) =\n const c ⟨$⟩ ⟨ dc⋆ (cd⋆ cs) ⟩ ≡⟨ ⟨by⟩ (dc∘cd⋆ cs) ⟩\n const c ⟨$⟩ return cs ≡⟨ refl ⟩∎\n return (const c cs) ∎\n\n dc∘cd⋆ : ∀ cs → dc⋆ (cd⋆ cs) ≡ just cs\n dc∘cd⋆ [] = refl\n dc∘cd⋆ (c ∷ cs) =\n _∷_ ⟨$⟩ ⟨ dc (cd c) ⟩ ⊛ dc⋆ (cd⋆ cs) ≡⟨ ⟨by⟩ (dc∘cd c) ⟩\n _∷_ ⟨$⟩ return c ⊛ ⟨ dc⋆ (cd⋆ cs) ⟩ ≡⟨ ⟨by⟩ (dc∘cd⋆ cs) ⟩\n _∷_ ⟨$⟩ return c ⊛ return cs ≡⟨⟩\n return (c ∷ cs) ∎\n\n-- Converts instances of the form Rep A Consts to Rep A Exp.\n\nrep-Consts-Exp : ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ →\n Rep A Exp\nrep-Consts-Exp ⦃ r ⦄ = rep ⦃ proj₁ code-Consts ⦄ ∘-rep r\n\n-- Represents something as an expression.\n\nrep-as-Exp : ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ → A → Exp\nrep-as-Exp = ⌜_⌝ ⦃ rep-Consts-Exp ⦄\n\n-- rep-as-Exp returns constructor applications.\n\nrep-const :\n ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄\n (x : A) → Constructor-application (rep-as-Exp x)\nrep-const = proj₂ code-Consts ∘ ⌜_⌝\n\n-- rep-as-Exp returns closed expressions.\n\nrep-closed :\n ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄\n (x : A) → Closed (rep-as-Exp x)\nrep-closed = const→closed ∘ rep-const\n\n-- Constructor applications can be encoded as closed expressions.\n\ncode-Consts-Closed : Code Consts Closed-exp\nCode.code code-Consts-Closed c =\n code ⦃ r = proj₁ code-Consts ⦄ c , const→closed (proj₂ code-Consts c)\n\nCode.decode code-Consts-Closed (e , _) =\n decode ⦃ r = proj₁ code-Consts ⦄ e\n\nCode.decode∘code code-Consts-Closed c =\n decode ⦃ r = proj₁ code-Consts ⦄ (code ⦃ r = proj₁ code-Consts ⦄ c) ≡⟨ decode∘code ⦃ r = proj₁ code-Consts ⦄ c ⟩∎\n just c ∎\n\n-- Converts instances of the form Rep A Consts to Rep A Closed-exp.\n\nrep-Consts-Closed-exp :\n ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ → Rep A Closed-exp\nrep-Consts-Closed-exp ⦃ r ⦄ = rep ⦃ r = code-Consts-Closed ⦄ ∘-rep r\n\n-- rep-as-Exp returns values.\n\nrep-value :\n ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄\n (x : A) → Value (rep-as-Exp x)\nrep-value = const→value ∘ rep-const\n\n-- Some derived lemmas.\n\nsubst-rep :\n ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ (x : A) {y e} →\n rep-as-Exp x [ y ← e ] ≡ rep-as-Exp x\nsubst-rep x = subst-closed _ _ (rep-closed x)\n\nsubsts-rep :\n ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ (x : A) ps →\n foldr (λ ye → _[ proj₁ ye ← proj₂ ye ]) (rep-as-Exp x) ps ≡\n rep-as-Exp x\nsubsts-rep x = substs-closed (rep-as-Exp x) (rep-closed x)\n\nrep⇓rep :\n ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄\n (x : A) → rep-as-Exp x ⇓ rep-as-Exp x\nrep⇓rep x = values-compute-to-themselves (rep-value x)\n\nrep⇓≡rep :\n ∀ {a} {A : Type a} ⦃ r : Rep A Consts ⦄ {v}\n (x : A) → rep-as-Exp x ⇓ v → rep-as-Exp x ≡ v\nrep⇓≡rep x = values-only-compute-to-themselves (rep-value x)\n\n------------------------------------------------------------------------\n-- Specifications of how a number of types are encoded as χ\n-- constructor applications\n\n-- Encoder for booleans.\n\ncode-Bool : Code Bool Consts\ncode-Bool = record\n { code = cd\n ; decode = dc\n ; decode∘code = dc∘cd\n }\n where\n cd : Bool → Consts\n cd true = const c-true []\n cd false = const c-false []\n\n dc : Consts → Maybe Bool\n dc (const c args) with c-true C.≟ c | c-false C.≟ c\n dc (const c []) | yes _ | _ = return true\n dc (const c []) | _ | yes _ = return false\n dc (const c _) | _ | _ = nothing\n\n dc∘cd : ∀ b → dc (cd b) ≡ just b\n dc∘cd true with c-true C.≟ c-true\n ... | yes _ = refl\n ... | no t≢t = ⊥-elim (t≢t refl)\n dc∘cd false with c-true C.≟ c-false | c-false C.≟ c-false\n ... | no _ | no f≢f = ⊥-elim (f≢f refl)\n ... | yes t≡f | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) t≡f)\n ... | no _ | yes _ = refl\n\n-- Encoder for natural numbers.\n\ncode-ℕ : Code ℕ Consts\ncode-ℕ = record\n { code = cd\n ; decode = dc\n ; decode∘code = dc∘cd\n }\n where\n cd : ℕ → Consts\n cd zero = const c-zero []\n cd (suc n) = const c-suc (cd n ∷ [])\n\n dc : Consts → Maybe ℕ\n dc (const c args) with c-zero C.≟ c | c-suc C.≟ c\n dc (const c []) | yes eq | _ = return zero\n dc (const c (n ∷ [])) | _ | yes eq = map suc (dc n)\n dc (const c _) | _ | _ = nothing\n\n dc∘cd : ∀ n → dc (cd n) ≡ just n\n dc∘cd zero with c-zero C.≟ c-zero\n ... | yes _ = refl\n ... | no z≢z = ⊥-elim (z≢z refl)\n dc∘cd (suc n) with c-zero C.≟ c-suc | c-suc C.≟ c-suc\n ... | no _ | no s≢s = ⊥-elim (s≢s refl)\n ... | yes z≡s | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) z≡s)\n ... | no _ | yes _ =\n map suc ⟨ dc (cd n) ⟩ ≡⟨ ⟨by⟩ (dc∘cd n) ⟩\n map suc (return n) ≡⟨ refl ⟩∎\n return (suc n) ∎\n\n-- Encoder for variables.\n\ncode-Var : Code Var Consts\ncode-Var = code-ℕ ∘-code ↔→Code V.countably-infinite\n\n-- Encoder for constants.\n\ncode-Const : Code Const Consts\ncode-Const = code-ℕ ∘-code ↔→Code C.countably-infinite\n\n-- Encoders for products.\n\nmodule _ {a b} {A : Type a} {B : Type b} where\n\n private\n\n encode : (A → Consts) → (B → Consts) → A × B → Consts\n encode encA encB (x , y) = const c-pair (encA x ∷ encB y ∷ [])\n\n rep-× : ⦃ r : Rep A Consts ⦄ ⦃ s : Rep B Consts ⦄ →\n Rep (A × B) Consts\n rep-× ⦃ r ⦄ ⦃ s ⦄ = record\n { ⌜_⌝ = encode ⌜_⌝ ⌜_⌝\n ; rep-injective = λ { {x₁ , x₂} {y₁ , y₂} →\n const c-pair (⌜ x₁ ⌝ ∷ ⌜ x₂ ⌝ ∷ []) ≡\n const c-pair (⌜ y₁ ⌝ ∷ ⌜ y₂ ⌝ ∷ []) ↝⟨ lemma ⟩\n\n ⌜ x₁ ⌝ ≡ ⌜ y₁ ⌝ × ⌜ x₂ ⌝ ≡ ⌜ y₂ ⌝ ↝⟨ Σ-map rep-injective rep-injective ⟩\n\n x₁ ≡ y₁ × x₂ ≡ y₂ ↝⟨ uncurry (cong₂ _,_) ⟩□\n\n (x₁ , x₂) ≡ (y₁ , y₂) □ }\n }\n where\n lemma :\n ∀ {c₁ c₂ x₁ x₂ y₁ y₂} →\n Consts.const c₁ (x₁ ∷ x₂ ∷ []) ≡ const c₂ (y₁ ∷ y₂ ∷ []) →\n x₁ ≡ y₁ × x₂ ≡ y₂\n lemma refl = refl , refl\n\n code-× : ⦃ c : Code A Consts ⦄ ⦃ d : Code B Consts ⦄ →\n Code (A × B) Consts\n code-× = record\n { code = cd\n ; decode = dc\n ; decode∘code = dc∘cd\n }\n where\n cd : A × B → Consts\n cd = encode code code\n\n dc : Consts → Maybe (A × B)\n dc (const c args) with c-pair C.≟ c\n dc (const c (x ∷ y ∷ [])) | yes _ = decode x >>=′ λ x →\n decode y >>=′ λ y →\n just (x , y)\n dc (const c args) | _ = nothing\n\n dc∘cd : ∀ x → dc (cd x) ≡ just x\n dc∘cd (x , y) with c-pair C.≟ c-pair\n ... | no p≢p = ⊥-elim (p≢p refl)\n ... | yes _ =\n (⟨ decode (code x) ⟩ >>=′ λ x →\n decode (code y) >>=′ λ y →\n just (x , y)) ≡⟨ ⟨by⟩ decode∘code ⟩\n\n (return x >>=′ λ x →\n decode (code y) >>=′ λ y →\n just (x , y)) ≡⟨⟩\n\n (⟨ decode (code y) ⟩ >>=′ λ y →\n just (x , y)) ≡⟨ ⟨by⟩ decode∘code ⟩\n\n (return y >>=′ λ y → just (x , y)) ≡⟨ refl ⟩∎\n\n return (x , y) ∎\n\n-- Encoders for lists.\n\nmodule _ {a} {A : Type a} where\n\n private\n\n encode : (A → Consts) → List A → Consts\n encode enc [] = const c-nil []\n encode enc (x ∷ xs) = const c-cons (enc x ∷ encode enc xs ∷ [])\n\n rep-List : ⦃ r : Rep A Consts ⦄ → Rep (List A) Consts\n rep-List = record\n { ⌜_⌝ = encode ⌜_⌝\n ; rep-injective = injective\n }\n where\n injective : ∀ {xs ys} → encode ⌜_⌝ xs ≡ encode ⌜_⌝ ys → xs ≡ ys\n injective {[]} {[]} = λ _ → refl\n injective {[]} {_ ∷ _} = λ ()\n injective {_ ∷ _} {[]} = λ ()\n injective {x ∷ xs} {y ∷ ys} =\n const c-cons (⌜ x ⌝ ∷ encode ⌜_⌝ xs ∷ []) ≡\n const c-cons (⌜ y ⌝ ∷ encode ⌜_⌝ ys ∷ []) ↝⟨ lemma ⟩\n\n ⌜ x ⌝ ≡ ⌜ y ⌝ × encode ⌜_⌝ xs ≡ encode ⌜_⌝ ys ↝⟨ Σ-map rep-injective injective ⟩\n\n x ≡ y × xs ≡ ys ↝⟨ uncurry (cong₂ _∷_) ⟩□\n\n x ∷ xs ≡ y ∷ ys □\n where\n lemma :\n ∀ {c₁ x₁ y₁ c₂ x₂ y₂} →\n Consts.const c₁ (x₁ ∷ y₁ ∷ []) ≡ const c₂ (x₂ ∷ y₂ ∷ []) →\n x₁ ≡ x₂ × y₁ ≡ y₂\n lemma refl = refl , refl\n\n code-List : ⦃ c : Code A Consts ⦄ → Code (List A) Consts\n code-List = record\n { code = cd\n ; decode = dc\n ; decode∘code = dc∘cd\n }\n where\n cd : List A → Consts\n cd = encode code\n\n dc : Consts → Maybe (List A)\n dc (const c args) with c-nil C.≟ c | c-cons C.≟ c\n dc (const c []) | yes eq | _ = return []\n dc (const c′ (x ∷ xs ∷ [])) | _ | yes eq =\n _∷_ ⟨$⟩ decode x ⊛ dc xs\n dc (const c args) | _ | _ = nothing\n\n dc∘cd : ∀ x → dc (cd x) ≡ just x\n dc∘cd [] with c-nil C.≟ c-nil\n ... | yes _ = refl\n ... | no n≢n = ⊥-elim (n≢n refl)\n dc∘cd (x ∷ xs) with c-nil C.≟ c-cons | c-cons C.≟ c-cons\n ... | no _ | no c≢c = ⊥-elim (c≢c refl)\n ... | yes n≡c | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) n≡c)\n ... | no _ | yes _ =\n _∷_ ⟨$⟩ ⟨ decode (code x) ⟩ ⊛ dc (cd xs) ≡⟨ ⟨by⟩ decode∘code ⟩\n _∷_ ⟨$⟩ return x ⊛ ⟨ dc (cd xs) ⟩ ≡⟨ ⟨by⟩ (dc∘cd xs) ⟩\n _∷_ ⟨$⟩ return x ⊛ return xs ≡⟨⟩\n return (x ∷ xs) ∎\n\n-- Encoder for lists of variables.\n\ncode-Var⋆ : Code (List Var) Consts\ncode-Var⋆ = code-List ⦃ code-Var ⦄\n\nprivate\n\n module Var = Code code-Var\n module Var⋆ = Code code-Var⋆\n module Const = Code code-Const\n\n -- Encoder for the abstract syntax.\n\n mutual\n\n code-E : Exp → Consts\n code-E (apply e₁ e₂) = const c-apply (code-E e₁ ∷ code-E e₂ ∷ [])\n code-E (lambda x e) = const c-lambda (code ⦃ code-Var ⦄ x ∷ code-E e ∷ [])\n code-E (case e bs) = const c-case (code-E e ∷ code-B⋆ bs ∷ [])\n code-E (rec x e) = const c-rec (code ⦃ code-Var ⦄ x ∷ code-E e ∷ [])\n code-E (var x) = const c-var (code ⦃ code-Var ⦄ x ∷ [])\n code-E (const c es) = const c-const (code ⦃ code-Const ⦄ c ∷ code-⋆ es ∷ [])\n\n code-B : Br → Consts\n code-B (branch c xs e) =\n const c-branch\n (code ⦃ code-Const ⦄ c ∷ code ⦃ code-Var⋆ ⦄ xs ∷ code-E e ∷ [])\n\n -- TODO: One could presumably use sized types to avoid repetitive\n -- code. However, I did not want to use sized types in the\n -- specification of χ.\n\n code-⋆ : List Exp → Consts\n code-⋆ [] = const c-nil []\n code-⋆ (e ∷ es) = const c-cons (code-E e ∷ code-⋆ es ∷ [])\n\n code-B⋆ : List Br → Consts\n code-B⋆ [] = const c-nil []\n code-B⋆ (b ∷ bs) = const c-cons (code-B b ∷ code-B⋆ bs ∷ [])\n\n mutual\n\n decode-E : Consts → Maybe Exp\n decode-E (const c args) with c-apply C.≟ c\n | c-lambda C.≟ c\n | c-case C.≟ c\n | c-rec C.≟ c\n | c-var C.≟ c\n | c-const C.≟ c\n\n decode-E (const c (e₁ ∷ e₂ ∷ [])) | yes eq | _ | _ | _ | _ | _ =\n apply ⟨$⟩ decode-E e₁ ⊛ decode-E e₂\n\n decode-E (const c (x ∷ e ∷ [])) | _ | yes eq | _ | _ | _ | _ =\n lambda ⟨$⟩ decode ⦃ code-Var ⦄ x ⊛ decode-E e\n\n decode-E (const c (e ∷ bs ∷ [])) | _ | _ | yes eq | _ | _ | _ =\n case ⟨$⟩ decode-E e ⊛ decode-B⋆ bs\n\n decode-E (const c (x ∷ e ∷ [])) | _ | _ | _ | yes eq | _ | _ =\n rec ⟨$⟩ decode ⦃ code-Var ⦄ x ⊛ decode-E e\n\n decode-E (const c (x ∷ [])) | _ | _ | _ | _ | yes eq | _ =\n var ⟨$⟩ decode ⦃ code-Var ⦄ x\n\n decode-E (const c (c′ ∷ es ∷ [])) | _ | _ | _ | _ | _ | yes eq =\n const ⟨$⟩ decode ⦃ code-Const ⦄ c′ ⊛ decode-⋆ es\n\n decode-E (const c args) | _ | _ | _ | _ | _ | _ = nothing\n\n decode-B : Consts → Maybe Br\n decode-B (const c args) with c-branch C.≟ c\n decode-B (const c (c′ ∷ xs ∷ e ∷ [])) | yes eq =\n branch ⟨$⟩ decode ⦃ code-Const ⦄ c′\n ⊛ decode ⦃ code-Var⋆ ⦄ xs\n ⊛ decode-E e\n decode-B (const c args) | _ = nothing\n\n decode-⋆ : Consts → Maybe (List Exp)\n decode-⋆ (const c args) with c-nil C.≟ c | c-cons C.≟ c\n decode-⋆ (const c []) | yes eq | _ = return []\n decode-⋆ (const c′ (e ∷ es ∷ [])) | _ | yes eq =\n _∷_ ⟨$⟩ decode-E e ⊛ decode-⋆ es\n decode-⋆ (const c args) | _ | _ = nothing\n\n decode-B⋆ : Consts → Maybe (List Br)\n decode-B⋆ (const c args) with c-nil C.≟ c | c-cons C.≟ c\n decode-B⋆ (const c []) | yes eq | _ = return []\n decode-B⋆ (const c′ (b ∷ bs ∷ [])) | _ | yes eq =\n _∷_ ⟨$⟩ decode-B b ⊛ decode-B⋆ bs\n decode-B⋆ (const c args) | _ | _ = nothing\n\n mutual\n\n decode∘code-E : ∀ e → decode-E (code-E e) ≡ just e\n\n decode∘code-E (apply e₁ e₂) with c-apply C.≟ c-apply\n ... | no c≢c = ⊥-elim (c≢c refl)\n ... | yes _ =\n apply ⟨$⟩ ⟨ decode-E (code-E e₁) ⟩ ⊛ decode-E (code-E e₂) ≡⟨ ⟨by⟩ (decode∘code-E e₁) ⟩\n apply ⟨$⟩ return e₁ ⊛ ⟨ decode-E (code-E e₂) ⟩ ≡⟨ ⟨by⟩ (decode∘code-E e₂) ⟩\n apply ⟨$⟩ return e₁ ⊛ return e₂ ≡⟨⟩\n return (apply e₁ e₂) ∎\n\n decode∘code-E (lambda x e) with c-apply C.≟ c-lambda\n | c-lambda C.≟ c-lambda\n ... | _ | no l≢l = ⊥-elim (l≢l refl)\n ... | yes a≡l | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) a≡l)\n ... | no _ | yes _ =\n lambda ⟨$⟩ ⟨ Var.decode (code ⦃ code-Var ⦄ x) ⟩ ⊛ decode-E (code-E e) ≡⟨ ⟨by⟩ Var.decode∘code ⟩\n lambda ⟨$⟩ return x ⊛ ⟨ decode-E (code-E e) ⟩ ≡⟨ ⟨by⟩ (decode∘code-E e) ⟩\n lambda ⟨$⟩ return x ⊛ return e ≡⟨⟩\n return (lambda x e) ∎\n\n decode∘code-E (case e bs) with c-apply C.≟ c-case\n | c-lambda C.≟ c-case\n | c-case C.≟ c-case\n ... | _ | _ | no c≢c = ⊥-elim (c≢c refl)\n ... | _ | yes l≡c | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) l≡c)\n ... | yes a≡c | _ | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) a≡c)\n ... | no _ | no _ | yes _ =\n case ⟨$⟩ ⟨ decode-E (code-E e) ⟩ ⊛ decode-B⋆ (code-B⋆ bs) ≡⟨ ⟨by⟩ (decode∘code-E e) ⟩\n case ⟨$⟩ return e ⊛ ⟨ decode-B⋆ (code-B⋆ bs) ⟩ ≡⟨ ⟨by⟩ (decode∘code-B⋆ bs) ⟩\n case ⟨$⟩ return e ⊛ return bs ≡⟨⟩\n return (case e bs) ∎\n\n decode∘code-E (rec x e) with c-apply C.≟ c-rec\n | c-lambda C.≟ c-rec\n | c-case C.≟ c-rec\n | c-rec C.≟ c-rec\n ... | _ | _ | _ | no r≢r = ⊥-elim (r≢r refl)\n ... | _ | _ | yes c≡r | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) c≡r)\n ... | _ | yes l≡r | _ | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) l≡r)\n ... | yes a≡r | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) a≡r)\n ... | no _ | no _ | no _ | yes _ =\n rec ⟨$⟩ ⟨ Var.decode (code ⦃ code-Var ⦄ x) ⟩ ⊛ decode-E (code-E e) ≡⟨ ⟨by⟩ Var.decode∘code ⟩\n rec ⟨$⟩ return x ⊛ ⟨ decode-E (code-E e) ⟩ ≡⟨ ⟨by⟩ (decode∘code-E e) ⟩\n rec ⟨$⟩ return x ⊛ return e ≡⟨⟩\n return (rec x e) ∎\n\n decode∘code-E (var x) with c-apply C.≟ c-var\n | c-lambda C.≟ c-var\n | c-case C.≟ c-var\n | c-rec C.≟ c-var\n | c-var C.≟ c-var\n ... | _ | _ | _ | _ | no v≢v = ⊥-elim (v≢v refl)\n ... | _ | _ | _ | yes r≡v | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) r≡v)\n ... | _ | _ | yes c≡v | _ | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) c≡v)\n ... | _ | yes l≡v | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) l≡v)\n ... | yes a≡v | _ | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) a≡v)\n ... | no _ | no _ | no _ | no _ | yes _ =\n var ⟨$⟩ ⟨ Var.decode (code ⦃ code-Var ⦄ x) ⟩ ≡⟨ ⟨by⟩ Var.decode∘code ⟩\n var ⟨$⟩ return x ≡⟨ refl ⟩∎\n return (var x) ∎\n\n decode∘code-E (const c es) with c-apply C.≟ c-const\n | c-lambda C.≟ c-const\n | c-case C.≟ c-const\n | c-rec C.≟ c-const\n | c-var C.≟ c-const\n | c-const C.≟ c-const\n ... | _ | _ | _ | _ | _ | no c≢c = ⊥-elim (c≢c refl)\n ... | _ | _ | _ | _ | yes v≡c | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) v≡c)\n ... | _ | _ | _ | yes r≡c | _ | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) r≡c)\n ... | _ | _ | yes c≡c | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) c≡c)\n ... | _ | yes l≡c | _ | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) l≡c)\n ... | yes a≡c | _ | _ | _ | _ | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) a≡c)\n ... | no _ | no _ | no _ | no _ | no _ | yes _ =\n const ⟨$⟩ ⟨ Const.decode (code ⦃ code-Const ⦄ c) ⟩ ⊛\n decode-⋆ (code-⋆ es) ≡⟨ ⟨by⟩ Const.decode∘code ⟩\n\n const ⟨$⟩ return c ⊛ ⟨ decode-⋆ (code-⋆ es) ⟩ ≡⟨ ⟨by⟩ (decode∘code-⋆ es) ⟩\n\n const ⟨$⟩ return c ⊛ return es ≡⟨⟩\n\n return (const c es) ∎\n\n decode∘code-B : ∀ b → decode-B (code-B b) ≡ just b\n decode∘code-B (branch c xs e) with c-branch C.≟ c-branch\n ... | no b≢b = ⊥-elim (b≢b refl)\n ... | yes _ =\n branch ⟨$⟩ ⟨ Const.decode (code ⦃ code-Const ⦄ c) ⟩ ⊛\n Var⋆.decode (code ⦃ code-Var⋆ ⦄ xs) ⊛\n decode-E (code-E e) ≡⟨ ⟨by⟩ Const.decode∘code ⟩\n\n branch ⟨$⟩ return c ⊛\n ⟨ Var⋆.decode (code ⦃ code-Var⋆ ⦄ xs) ⟩ ⊛\n decode-E (code-E e) ≡⟨ ⟨by⟩ Var⋆.decode∘code ⟩\n\n branch ⟨$⟩ return c ⊛ return xs ⊛ ⟨ decode-E (code-E e) ⟩ ≡⟨ ⟨by⟩ (decode∘code-E e) ⟩\n\n branch ⟨$⟩ return c ⊛ return xs ⊛ return e ≡⟨⟩\n\n return (branch c xs e) ∎\n\n decode∘code-⋆ : ∀ es → decode-⋆ (code-⋆ es) ≡ just es\n decode∘code-⋆ [] with c-nil C.≟ c-nil\n ... | no n≢n = ⊥-elim (n≢n refl)\n ... | yes _ = refl\n decode∘code-⋆ (e ∷ es) with c-nil C.≟ c-cons | c-cons C.≟ c-cons\n ... | no _ | no c≢c = ⊥-elim (c≢c refl)\n ... | yes n≡c | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) n≡c)\n ... | no _ | yes _ =\n _∷_ ⟨$⟩ ⟨ decode-E (code-E e) ⟩ ⊛ decode-⋆ (code-⋆ es) ≡⟨ ⟨by⟩ (decode∘code-E e) ⟩\n _∷_ ⟨$⟩ return e ⊛ ⟨ decode-⋆ (code-⋆ es) ⟩ ≡⟨ ⟨by⟩ (decode∘code-⋆ es) ⟩\n _∷_ ⟨$⟩ return e ⊛ return es ≡⟨⟩\n return (e ∷ es) ∎\n\n decode∘code-B⋆ : ∀ bs → decode-B⋆ (code-B⋆ bs) ≡ just bs\n decode∘code-B⋆ [] with c-nil C.≟ c-nil\n ... | no n≢n = ⊥-elim (n≢n refl)\n ... | yes _ = refl\n decode∘code-B⋆ (b ∷ bs) with c-nil C.≟ c-cons | c-cons C.≟ c-cons\n ... | no _ | no c≢c = ⊥-elim (c≢c refl)\n ... | yes n≡c | _ = ⊥-elim (C.distinct-codes→distinct-names\n (λ ()) n≡c)\n ... | no _ | yes _ =\n _∷_ ⟨$⟩ ⟨ decode-B (code-B b) ⟩ ⊛ decode-B⋆ (code-B⋆ bs) ≡⟨ ⟨by⟩ (decode∘code-B b) ⟩\n _∷_ ⟨$⟩ return b ⊛ ⟨ decode-B⋆ (code-B⋆ bs) ⟩ ≡⟨ ⟨by⟩ (decode∘code-B⋆ bs) ⟩\n _∷_ ⟨$⟩ return b ⊛ return bs ≡⟨⟩\n return (b ∷ bs) ∎\n\ncode-Exp : Code Exp Consts\nCode.code code-Exp = code-E\nCode.decode code-Exp = decode-E\nCode.decode∘code code-Exp = decode∘code-E\n\ncode-Br : Code Br Consts\nCode.code code-Br = code-B\nCode.decode code-Br = decode-B\nCode.decode∘code code-Br = decode∘code-B\n\ncode-Exps : Code (List Exp) Consts\nCode.code code-Exps = code-⋆\nCode.decode code-Exps = decode-⋆\nCode.decode∘code code-Exps = decode∘code-⋆\n\ncode-Brs : Code (List Br) Consts\nCode.code code-Brs = code-B⋆\nCode.decode code-Brs = decode-B⋆\nCode.decode∘code code-Brs = decode∘code-B⋆\n\n-- Encoder for closed expressions.\n\ncode-Closed : Code Closed-exp Consts\nCode.code code-Closed = code ⦃ code-Exp ⦄ ∘ proj₁\nCode.decode code-Closed c with decode ⦃ code-Exp ⦄ c\n... | nothing = nothing\n... | just e with closed? e\n... | yes cl = just (e , cl)\n... | no _ = nothing\nCode.decode∘code code-Closed (c , cl)\n with decode ⦃ r = code-Exp ⦄ (code ⦃ code-Exp ⦄ c)\n | decode∘code ⦃ r = code-Exp ⦄ c\n... | .(just c) | refl with closed? c\n... | no ¬cl = ⊥-elim (¬cl cl)\n... | yes cl′ =\n cong just (closed-equal-if-expressions-equal refl)\n", "meta": {"hexsha": "ee18ca6e4f56d3cb4ab7bb0a94d3fd089931d27d", "size": 27108, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Coding.agda", "max_stars_repo_name": "nad/chi", "max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z", "max_issues_repo_path": "src/Coding.agda", "max_issues_repo_name": "nad/chi", "max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z", "max_forks_repo_path": "src/Coding.agda", "max_forks_repo_name": "nad/chi", "max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "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": 36.0, "max_line_length": 116, "alphanum_fraction": 0.4356647484, "num_tokens": 9983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6825737473266735, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.370544225481118}} {"text": "open import Auto.Core\nopen import Data.List using (_∷_; []; length)\nopen import Data.Nat using (ℕ; zero; suc)\nopen import Data.Product using (_,_)\nopen import Data.Sum using (inj₁; inj₂)\nopen import Reflection using (Term; Name; lam; visible; abs; TC; returnTC; bindTC)\n\nmodule Auto.Extensible (instHintDB : IsHintDB) where\n\n\nopen IsHintDB instHintDB public\nopen PsExtensible instHintDB public\nopen Auto.Core public using (dfs; bfs; Exception; throw; searchSpaceExhausted; unsupportedSyntax)\n\n\nauto : Strategy → ℕ → HintDB → Term → TC Term\nauto search depth db type\n with agda2goal×premises type\n... | inj₁ msg = returnTC (quoteError msg)\n... | inj₂ ((n , g) , args)\n with search (suc depth) (solve g (fromRules args ∙ db))\n... | [] = returnTC (quoteError searchSpaceExhausted)\n... | (p ∷ _) = bindTC (reify p) (λ rp → returnTC (intros rp))\n where\n intros : Term → Term\n intros = introsAcc (length args)\n where\n introsAcc : ℕ → Term → Term\n introsAcc zero t = t\n introsAcc (suc k) t = lam visible (abs \"TODO\" (introsAcc k t))\n\n\n\ninfixl 5 _<<_\n\n_<<_ : HintDB → Name → TC HintDB\ndb << n = bindTC (name2rule n) (λ\n {(inj₁ msg) → returnTC db\n ; (inj₂ (k , r)) → returnTC (db ∙ return r)})\n-- db << n with (name2rule n)\n-- db << n | inj₁ msg = db\n-- db << n | inj₂ (k , r) = db ∙ return r\n", "meta": {"hexsha": "d66a2e6a3f28831a601bb66d66a1f6510c2a534d", "size": 1364, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Auto/Extensible.agda", "max_stars_repo_name": "wenkokke/AutoInAgda", "max_stars_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2017-07-18T18:14:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-20T15:04:47.000Z", "max_issues_repo_path": "src/Auto/Extensible.agda", "max_issues_repo_name": "wenkokke/AutoInAgda", "max_issues_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-11-03T09:46:19.000Z", "max_issues_repo_issues_event_max_datetime": "2017-11-06T16:49:27.000Z", "max_forks_repo_path": "src/Auto/Extensible.agda", "max_forks_repo_name": "wenkokke/AutoInAgda", "max_forks_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-07-10T10:47:30.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-07T07:37:07.000Z", "avg_line_length": 31.7209302326, "max_line_length": 111, "alphanum_fraction": 0.6341642229, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737214979745, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3705442114596656}} {"text": "module Impure.LFRef.Properties.Decidable where\n\nopen import Prelude\nopen import Relation.Unary\nopen import Relation.Nullary.Decidable as DecM\nopen import Data.Fin.Properties as FinP using ()\nopen import Data.List\nopen import Data.Vec\nopen import Data.Vec.Properties\nopen import Function.Inverse hiding (_∘_; sym)\nopen import Extensions.List as List↑ using ()\nopen import Extensions.Vec as Vec↑ using ()\nopen import Relation.Binary.List.Pointwise using (decidable-≡)\nopen import Relation.Binary.HeterogeneousEquality as Het using ()\n\nopen import Impure.LFRef.Syntax hiding (subst)\nopen import Impure.LFRef.Welltyped\n\nmodule DecidableEquality where\n -- termination checker has trouble with mapping\n -- recursively over the arguments of constructors; inlining would prove this terminating\n {-# TERMINATING #-}\n _tm≟_ : ∀ {n} (a b : Term n) → Dec (a ≡ b)\n var x tm≟ var x' with (x FinP.≟ x')\n ... | yes refl = yes refl\n ... | no neq = no (λ{ refl → neq refl })\n var x tm≟ loc x₁ = no (λ ())\n var x tm≟ unit = no (λ ())\n var x tm≟ con fn ts = no (λ ())\n loc x tm≟ var x₁ = no (λ ())\n loc x tm≟ loc x' with x ≟ x'\n ... | yes refl = yes refl\n ... | no neq = no (λ{ refl → neq refl })\n loc x tm≟ unit = no (λ ())\n loc x tm≟ con fn ts = no (λ ())\n unit tm≟ var x = no (λ ())\n unit tm≟ loc x = no (λ ())\n unit tm≟ unit = yes refl\n unit tm≟ con fn ts = no (λ ())\n con fn ts tm≟ var x = no (λ ())\n con fn ts tm≟ loc x = no (λ ())\n con fn ts tm≟ unit = no (λ ())\n con fn ts tm≟ con fn' ts' with fn ≟ fn'\n ... | no neq = no (λ{ refl → neq refl })\n ... | yes refl with decidable-≡ _tm≟_ ts ts'\n ... | no neq = no (λ{ refl → neq refl })\n ... | yes refl = yes refl\n\n -- decidable type equality\n _ty≟_ : ∀ {n} (a b : Type n) → Dec (a ≡ b)\n (x [ ts ]) ty≟ (x' [ ts' ]) with x ≟ x'\n ... | no neq = no (λ{ refl → neq refl })\n ... | yes refl with decidable-≡ _tm≟_ ts ts'\n ... | yes refl = yes refl\n ... | no neq = no (λ{ refl → neq refl })\n (x [ ts ]) ty≟ Ref b = no (λ ())\n (x [ ts ]) ty≟ Unit = no (λ ())\n Ref a ty≟ (x [ ts ]) = no (λ ())\n Ref a ty≟ Ref b with a ty≟ b\n ... | yes refl = yes refl\n ... | no neq = no (λ{ refl → neq refl })\n Ref a ty≟ Unit = no (λ ())\n Unit ty≟ (x [ ts ]) = no (λ ())\n Unit ty≟ Ref b = no (λ ())\n Unit ty≟ Unit = yes refl\n\nmodule UniqueTypings where\n unique-tm-type : ∀ {n a b 𝕊 Σ Γ} {t : Term n} → 𝕊 , Σ , Γ ⊢ t ∶ a → 𝕊 , Σ , Γ ⊢ t ∶ b → a ≡ b\n unique-tm-type unit unit = refl\n unique-tm-type (var x) (var x') with Vec↑.[]=-functional _ _ x x'\n ... | refl = refl\n unique-tm-type (loc x) (loc x') with List↑.[]=-functional _ _ x x'\n ... | refl = refl\n unique-tm-type (con c ts refl) (con c' ts' refl)\n with List↑.[]=-functional _ _ c c'\n ... | refl = refl\n\n unique-type : ∀ {n a b 𝕊 Σ Γ} {e : Exp n} → 𝕊 , Σ , Γ ⊢ₑ e ∶ a → 𝕊 , Σ , Γ ⊢ₑ e ∶ b → a ≡ b\n unique-type (tm x) (tm y) = unique-tm-type x y\n unique-type (fn ·★[ refl ] ts) (fn' ·★[ refl ] ts') with List↑.[]=-functional _ _ fn fn'\n ... | refl = refl\n unique-type (ref p) (ref q) = cong Ref (unique-type p q)\n unique-type (! p) (! q) with unique-type p q\n ... | refl = refl\n unique-type (p ≔ q) (p' ≔ q') = refl\n\n elim-mistype : ∀ {n a b 𝕊 Σ Γ} {e : Exp n} →\n 𝕊 , Σ , Γ ⊢ₑ e ∶ a → 𝕊 , Σ , Γ ⊢ₑ e ∶ b → ¬ (a ≢ b)\n elim-mistype p q with unique-type p q\n ... | refl = λ neq → neq refl\n\nmodule DecidableTypability where\n open UniqueTypings\n open DecidableEquality\n\n mutual\n type-tm : ∀ {n} 𝕊 Σ Γ (t : Term n) → Dec (∃ λ a → 𝕊 , Σ , Γ ⊢ t ∶ a)\n type-tm 𝕊 Σ Γ (var x) =\n yes (, var (proj₂ (Vec↑.strong-lookup _ _)))\n type-tm 𝕊 Σ Γ (loc x) =\n DecM.map′\n (λ{ (_ , p) → Ref _ , loc p})\n (λ{ (_ , loc p) → _ , p })\n (List↑.dec-lookup x Σ)\n type-tm 𝕊 Σ Γ unit = yes (Unit , unit)\n type-tm 𝕊 Σ Γ (con c ts) with (List↑.dec-lookup c (Sig.constructors 𝕊))\n ... | no ¬p = no (λ{ (._ , con p _ _) → ¬p (, p)})\n ... | yes (p , z) with typecheck-tele 𝕊 Σ Γ ts (weaken+-tele _ (ConType.args p))\n ... | no ¬q = no lem\n where\n lem : ¬ ∃ λ ty → 𝕊 , Σ , Γ ⊢ (con c ts) ∶ ty\n lem (._ , con x q p) with List↑.[]=-functional _ _ z x\n ... | refl = ¬q q\n ... | yes q = yes (, con z q (tele-fit-length q))\n\n -- deciding whether a term matches a given type follows from\n -- typability with unique type assignments\n typecheck-tm : ∀ {n} 𝕊 Σ Γ (t : Term n) a → Dec (𝕊 , Σ , Γ ⊢ t ∶ a)\n typecheck-tm 𝕊 Σ Γ t a with type-tm 𝕊 Σ Γ t\n ... | no nwt = no (λ wta → nwt (, wta))\n ... | yes (a' , wta') with a ty≟ a'\n ... | yes refl = yes wta'\n ... | no neq = no (λ wta → neq (unique-tm-type wta wta'))\n\n typecheck-tele : ∀ {n m } 𝕊 Σ Γ (ts : List (Term n)) → (T : Tele n m) → Dec (𝕊 , Σ , Γ ⊢ ts ∶ⁿ T)\n typecheck-tele 𝕊 Σ Γ [] ε = yes ε\n typecheck-tele 𝕊 Σ Γ [] (x ⟶ T) = no (λ ())\n typecheck-tele 𝕊 Σ Γ (x ∷ ts) ε = no (λ ())\n typecheck-tele 𝕊 Σ Γ (x ∷ ts) (ty ⟶ T)\n with typecheck-tm 𝕊 Σ Γ x ty\n ... | no ¬x∶ty = no (λ{ (x∶ty ⟶ _) → ¬x∶ty x∶ty })\n ... | yes x∶ty with typecheck-tele 𝕊 Σ Γ ts (T tele/ (sub x))\n ... | yes ts∶T = yes (x∶ty ⟶ ts∶T)\n ... | no ¬ts∶T = no (λ{ (_ ⟶ ts∶T) → ¬ts∶T ts∶T })\n\n type : ∀ {n} 𝕊 Σ Γ (e : Exp n) → Dec (∃ λ a → 𝕊 , Σ , Γ ⊢ₑ e ∶ a)\n type 𝕊 Σ Γ (tm t) = DecM.map′\n (λ{ (_ , x ) → , (tm x)})\n (λ{ (_ , tm x) → , x})\n (type-tm 𝕊 Σ Γ t)\n type {n} 𝕊 Σ Γ (fn ·★ ts) with List↑.dec-lookup fn (Sig.funs 𝕊)\n ... | no ¬fn! = no (λ { (_ , (fn! ·★[ q ] _)) → ¬fn! (, fn!) })\n ... | yes (φ , fn!) with typecheck-tele 𝕊 Σ Γ ts (weaken+-tele _ (Fun.args φ))\n ... | no ¬ts∶T = no lem\n where\n lem : ¬ ∃ λ a → 𝕊 , Σ , Γ ⊢ₑ (fn ·★ ts) ∶ a\n lem (_ , (fn!' ·★[ q ] ts∶T)) with List↑.[]=-functional _ _ fn! fn!'\n ... | refl = ¬ts∶T ts∶T\n ... | yes ts∶T = yes (, fn! ·★[ tele-fit-length ts∶T ] ts∶T)\n type 𝕊 Σ Γ (ref e) with (type 𝕊 Σ Γ e)\n ... | no ¬wte = no (λ{ (.(Ref _) , ref wte) → ¬wte (, wte)})\n ... | yes (a , wte) = yes (, ref wte)\n type 𝕊 Σ Γ (! e) with (type 𝕊 Σ Γ e)\n ... | no ¬wte = no ((λ{ (x , (! wte)) → ¬wte (, wte) }))\n type 𝕊 Σ Γ (! e) | yes (x [ ts ] , wte) =\n no λ{ (_ , ! wte') → elim-mistype wte wte' (λ ()) }\n type 𝕊 Σ Γ (! e) | yes (Unit , wte) =\n no λ{ (_ , ! wte' ) → elim-mistype wte wte' (λ ()) }\n type 𝕊 Σ Γ (! e) | yes (Ref a , wte) = yes (_ , (! wte))\n type 𝕊 Σ Γ (l ≔ r) with type 𝕊 Σ Γ l | type 𝕊 Σ Γ r\n ... | no ¬wtl | _ = no (λ{ (_ , wtl ≔ _ ) → ¬wtl (, wtl) })\n ... | _ | no ¬wtr = no (λ{ (_ , _ ≔ wtr ) → ¬wtr (, wtr) })\n ... | yes (x [ ts ] , wtl) | (yes (b , wtr)) =\n no (λ{ (_ , wtl' ≔ wtr) → elim-mistype wtl wtl' (λ ())})\n ... | yes (Unit , wtl) | (yes (b , wtr)) =\n no (λ{ (_ , wtl' ≔ wtr) → elim-mistype wtl wtl' (λ ())})\n ... | yes (Ref a , wtl) | yes (b , wtr) with a ty≟ b\n ... | yes refl = yes (, wtl ≔ wtr)\n ... | no neq = no lem\n where\n lem : ¬ ∃ λ a → 𝕊 , Σ , Γ ⊢ₑ (l ≔ r) ∶ a\n lem (.Unit , (wtl' ≔ wtr')) with unique-type wtl wtl'\n ... | refl = elim-mistype wtr wtr' (neq ∘ sym)\n\n typecheck : ∀ {n} 𝕊 Σ Γ (e : Exp n) a → Dec (𝕊 , Σ , Γ ⊢ₑ e ∶ a)\n typecheck 𝕊 Σ Γ e a with type 𝕊 Σ Γ e\n ... | no ¬wte = no (λ wte → ¬wte (, wte))\n ... | yes (a' , wte) with a' ty≟ a\n ... | yes refl = yes wte\n ... | no neq = no (λ{ wte' → elim-mistype wte wte' neq })\n\n typecheck-seq : ∀ {n} 𝕊 Σ Γ (e : SeqExp n) a → Dec (𝕊 , Σ , Γ ⊢ₛ e ∶ a)\n typecheck-seq 𝕊 Σ Γ (lett e c) a with type 𝕊 Σ Γ e\n ... | no ¬wte = no (λ{ (lett wte _ ) → ¬wte (, wte)})\n ... | yes (b , wte) with typecheck-seq 𝕊 Σ (b :+: Γ) c (weaken₁-tp a)\n ... | yes wtc = yes (lett wte wtc)\n ... | no ¬wtc = no lem\n where\n lem : ¬ 𝕊 , Σ , Γ ⊢ₛ lett e c ∶ a\n lem (lett wte' wtc) with unique-type wte wte'\n ... | refl = ¬wtc wtc\n typecheck-seq 𝕊 Σ Γ (ret e) a = DecM.map′ ret (λ{ (ret wte) → wte }) (typecheck 𝕊 Σ Γ e a)\n", "meta": {"hexsha": "b1c2899c77eca514f82feaf45ab3a41bbf531b9f", "size": 7800, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Impure/LFRef/Properties/Decidable.agda", "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "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/Impure/LFRef/Properties/Decidable.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/Impure/LFRef/Properties/Decidable.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": 40.414507772, "max_line_length": 101, "alphanum_fraction": 0.5047435897, "num_tokens": 3312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943805178139, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.3705215739216279}} {"text": "{-# OPTIONS --without-K --exact-split #-}\n\nmodule rational-numbers where\n\nimport integers\nopen integers public\n\n--------------------------------------------------------------------------------\n\n{- We introduce the type of non-zero integers. -}\n\nℤ\\0 : UU lzero\nℤ\\0 = Σ ℤ (λ k → ¬ (Id zero-ℤ k))\n\nint-ℤ\\0 : ℤ\\0 → ℤ\nint-ℤ\\0 = pr1\n\n{- We first show that multiplication by a non-zero integer is an injective\n function. -}\n\nmul-ℤ-ℤ\\0 : ℤ → ℤ\\0 → ℤ\nmul-ℤ-ℤ\\0 x y = mul-ℤ x (int-ℤ\\0 y)\n\nmul-ℤ\\0 : ℤ\\0 → ℤ\\0 → ℤ\\0\nmul-ℤ\\0 (pair x Hx) (pair y Hy) = pair (mul-ℤ x y) (neq-zero-mul-ℤ x y Hx Hy)\n\npostulate is-emb-mul-ℤ-ℤ\\0 : (y : ℤ\\0) → is-emb (λ x → mul-ℤ-ℤ\\0 x y)\n\nis-injective-mul-ℤ-ℤ\\0 :\n (y : ℤ\\0) (x1 x2 : ℤ) → Id (mul-ℤ-ℤ\\0 x1 y) (mul-ℤ-ℤ\\0 x2 y) → Id x1 x2\nis-injective-mul-ℤ-ℤ\\0 y x1 x2 = inv-is-equiv (is-emb-mul-ℤ-ℤ\\0 y x1 x2)\n\n--------------------------------------------------------------------------------\n\n{- We introduce the prerational numbers. -}\n\nℚ' : UU lzero\nℚ' = ℤ × ℤ\\0\n\n--------------------------------------------------------------------------------\n\n{- We introduce the equivalence relation on the prerational numbers that will\n define the rational numbers. -}\n\nequiv-ℚ' : ℚ' → ℚ' → UU lzero\nequiv-ℚ' (pair x1 x2) (pair y1 y2) =\n Id (mul-ℤ-ℤ\\0 x1 y2) (mul-ℤ-ℤ\\0 y1 x2)\n\nrefl-equiv-ℚ' :\n (x : ℚ') → equiv-ℚ' x x\nrefl-equiv-ℚ' (pair x1 x2) = refl\n\nsymmetric-equiv-ℚ' :\n (x y : ℚ') → equiv-ℚ' x y → equiv-ℚ' y x\nsymmetric-equiv-ℚ' (pair x1 x2) (pair y1 y2) = inv\n\ntransitive-equiv-ℚ' :\n (x y z : ℚ') →\n equiv-ℚ' x y → equiv-ℚ' y z → equiv-ℚ' x z\ntransitive-equiv-ℚ' (pair x1 x2) (pair y1 y2) (pair z1 z2) p q =\n is-injective-mul-ℤ-ℤ\\0 y2\n ( mul-ℤ-ℤ\\0 x1 z2)\n ( mul-ℤ-ℤ\\0 z1 x2)\n ( ( associative-mul-ℤ x1 (int-ℤ\\0 z2) (int-ℤ\\0 y2)) ∙\n ( ( ap ( mul-ℤ x1)\n ( commutative-mul-ℤ (int-ℤ\\0 z2) (int-ℤ\\0 y2))) ∙\n ( ( inv (associative-mul-ℤ x1 (int-ℤ\\0 y2) (int-ℤ\\0 z2))) ∙\n ( ( ap ( λ t → mul-ℤ t (int-ℤ\\0 z2))\n ( p ∙ (commutative-mul-ℤ y1 (int-ℤ\\0 x2)))) ∙\n ( ( associative-mul-ℤ (int-ℤ\\0 x2) y1 (int-ℤ\\0 z2)) ∙\n ( ( ap (mul-ℤ (int-ℤ\\0 x2)) q) ∙\n ( ( inv (associative-mul-ℤ (int-ℤ\\0 x2) z1 (int-ℤ\\0 y2))) ∙\n ( ap ( λ t → mul-ℤ-ℤ\\0 t y2)\n ( commutative-mul-ℤ (int-ℤ\\0 x2) z1)))))))))\n\n--------------------------------------------------------------------------------\n\n{- We define addition on the prerational numbers. -}\n\nadd-ℚ' : ℚ' → ℚ' → ℚ'\nadd-ℚ' (pair x1 x2) (pair y1 y2) =\n pair (add-ℤ (mul-ℤ-ℤ\\0 x1 y2) (mul-ℤ-ℤ\\0 y1 x2)) (mul-ℤ\\0 x2 y2)\n\nequiv-add-ℚ' :\n (x y x' y' : ℚ') → equiv-ℚ' x x' → equiv-ℚ' y y' →\n equiv-ℚ' (add-ℚ' x y) (add-ℚ' x' y')\nequiv-add-ℚ'\n ( pair x1 (pair x2 Hx))\n ( pair y1 (pair y2 Hy))\n ( pair x1' (pair x2' Hx'))\n ( pair y1' (pair y2' Hy')) e f =\n ( right-distributive-mul-add-ℤ\n ( mul-ℤ x1 y2)\n ( mul-ℤ y1 x2)\n ( mul-ℤ x2' y2')) ∙\n ( ( ap-add-ℤ\n ( ( interchange-2-3-mul-ℤ {x1}) ∙\n ( ( ap (λ t → mul-ℤ t (mul-ℤ y2 y2')) e) ∙\n ( move-four-mul-ℤ {x1'})))\n ( ( move-five-mul-ℤ {y1}) ∙\n ( ( ap (mul-ℤ (mul-ℤ x2 x2')) f) ∙\n ( interchange-1-3-mul-ℤ {x2} {x2'} {y1'})))) ∙\n ( inv\n ( right-distributive-mul-add-ℤ\n ( mul-ℤ x1' y2')\n ( mul-ℤ y1' x2')\n ( mul-ℤ x2 y2))))\n\n--------------------------------------------------------------------------------\n\n{- We define multiplication on the prerational numbers. -}\n\nmul-ℚ' : ℚ' → ℚ' → ℚ'\nmul-ℚ' (pair x1 x2) (pair y1 y2) = pair (mul-ℤ x1 y1) (mul-ℤ\\0 x2 y2)\n\nap-mul-ℤ :\n {a b a' b' : ℤ} →\n Id a a' → Id b b' → Id (mul-ℤ a b) (mul-ℤ a' b')\nap-mul-ℤ refl refl = refl\n\nequiv-mul-ℚ' :\n (x y x' y' : ℚ') → equiv-ℚ' x x' → equiv-ℚ' y y' →\n equiv-ℚ' (mul-ℚ' x y) (mul-ℚ' x' y')\nequiv-mul-ℚ'\n ( pair x1 (pair x2 Hx))\n ( pair y1 (pair y2 Hy))\n ( pair x1' (pair x2' Hx'))\n ( pair y1' (pair y2' Hy')) e f =\n ( interchange-2-3-mul-ℤ {x1} {y1} {x2'}) ∙\n ( ( ap-mul-ℤ e f) ∙\n ( interchange-2-3-mul-ℤ {x1'}))\n", "meta": {"hexsha": "f093bcada185b0b0763c10dbaff2d2f28569c3d4", "size": 4011, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Agda/rational-numbers.agda", "max_stars_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_stars_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 333, "max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z", "max_issues_repo_path": "Agda/rational-numbers.agda", "max_issues_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_issues_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z", "max_forks_repo_path": "Agda/rational-numbers.agda", "max_forks_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_forks_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z", "avg_line_length": 30.3863636364, "max_line_length": 80, "alphanum_fraction": 0.4654699576, "num_tokens": 1822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300698514777, "lm_q2_score": 0.5273165233795672, "lm_q1q2_score": 0.37045571400368577}} {"text": "open import Agda.Builtin.Bool\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Reflection renaming (bindTC to _>>=_)\nopen import Agda.Builtin.Unit\n\npostulate\n @0 A : Set\n\n@0 _ : @0 Set → (Set → Set) → Set\n_ = λ @0 where\n A G → G A\n\n@0 _ : @0 Set → (Set → Set) → Set\n_ = λ @0 { A G → G A }\n\ndata ⊥ : Set where\n\n@0 _ : @0 ⊥ → Set\n_ = λ @0 { () }\n\n@0 _ : @0 ⊥ → Set\n_ = λ @0 where\n ()\n\n@0 _ : @0 ⊥ → Set\n_ =\n λ @0\n @ω\n @erased\n @plenty\n @(tactic (λ _ → Set))\n @irr\n @irrelevant\n @shirr\n @shape-irrelevant\n @relevant\n @♭\n @flat\n @notlock\n @lock\n @tick where\n ()\n\nF : ⊤ → ⊤\nF = λ { tt → tt }\n\nmacro\n\n `F : Term → TC ⊤\n `F goal = do\n F ← withNormalisation true (quoteTC F)\n F ← quoteTC F\n unify goal F\n\n_ :\n `F ≡\n pat-lam\n (clause []\n (arg (arg-info visible relevant) (con (quote tt) []) ∷ [])\n (con (quote tt) []) ∷\n [])\n []\n_ = refl\n", "meta": {"hexsha": "dc86594aeac1fdac1efa42787635d8e42ed693ea", "size": 951, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue4525.agda", "max_stars_repo_name": "googleson78/agda", "max_stars_repo_head_hexsha": "aea2c53340f509c2c67157caeac360400ea6afbc", "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/Succeed/Issue4525.agda", "max_issues_repo_name": "googleson78/agda", "max_issues_repo_head_hexsha": "aea2c53340f509c2c67157caeac360400ea6afbc", "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/Succeed/Issue4525.agda", "max_forks_repo_name": "googleson78/agda", "max_forks_repo_head_hexsha": "aea2c53340f509c2c67157caeac360400ea6afbc", "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": 14.6307692308, "max_line_length": 64, "alphanum_fraction": 0.5131440589, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300573952054, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.37045570743528744}} {"text": "\nmodule _ where\n\nopen import Agda.Builtin.Reflection\nopen import Agda.Builtin.Bool\nopen import Agda.Builtin.Unit\nopen import Agda.Builtin.String\nopen import Common.Prelude\n\n_<_ = primQNameLess\n\nTrue : Bool → Set\nTrue true = ⊤\nTrue false = ⊥\n\nzzz aaa : ⊤\nzzz = _\naaa = _\n\n⊥-elim : {A : Set} → ⊥ → A\n⊥-elim ()\n\ncheck : (x y : Name) → True (x < y) → String\ncheck x y prf with x < y\ncheck x y prf | true = \"A-ok\"\ncheck x y prf | false = ⊥-elim prf\n\nmain : IO Unit\nmain = putStrLn (check (quote zzz) (quote aaa) _)\n", "meta": {"hexsha": "30e2e1725fb4bd4d1e22d6351e484dfc2193293e", "size": 511, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Compiler/simple/QNameOrder.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/Compiler/simple/QNameOrder.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/Compiler/simple/QNameOrder.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": 17.0333333333, "max_line_length": 49, "alphanum_fraction": 0.6555772994, "num_tokens": 183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7025300449389326, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.370455700866889}} {"text": "import Level as L\nopen import Relation.Binary\nopen import Relation.Binary.PropositionalEquality\nopen import Data.Product\nopen import Data.Empty\nopen import Data.Nat\nopen import Data.Nat.Properties\nopen import RevMachine\n\nmodule RevNoRepeat {ℓ} (M : RevMachine {ℓ}) where\n infix 99 _ᵣₑᵥ\n infixr 10 _∷_\n infixr 10 _++↦_\n open RevMachine.RevMachine M\n\n is-stuck : State → Set _\n is-stuck st = ∄[ st' ] (st ↦ st')\n\n is-initial : State → Set _\n is-initial st = ∄[ st' ] (st' ↦ st)\n\n data _↦ᵣₑᵥ_ : State → State → Set (L.suc ℓ) where\n _ᵣₑᵥ : ∀ {st₁ st₂} → st₁ ↦ st₂ → st₂ ↦ᵣₑᵥ st₁\n\n data _↦*_ : State → State → Set (L.suc ℓ) where\n ◾ : {st : State} → st ↦* st\n _∷_ : {st₁ st₂ st₃ : State} → st₁ ↦ st₂ → st₂ ↦* st₃ → st₁ ↦* st₃\n\n _++↦_ : {st₁ st₂ st₃ : State} → st₁ ↦* st₂ → st₂ ↦* st₃ → st₁ ↦* st₃\n ◾ ++↦ st₁↦*st₂ = st₁↦*st₂\n (st₁↦st₁' ∷ st₁'↦*st₂) ++↦ st₂'↦*st₃ = st₁↦st₁' ∷ (st₁'↦*st₂ ++↦ st₂'↦*st₃)\n\n len↦ : ∀ {st st'} → st ↦* st' → ℕ\n len↦ ◾ = 0\n len↦ (_ ∷ r) = 1 + len↦ r\n\n data _↦ᵣₑᵥ*_ : State → State → Set (L.suc ℓ) where\n ◾ : ∀ {st} → st ↦ᵣₑᵥ* st\n _∷_ : ∀ {st₁ st₂ st₃} → st₁ ↦ᵣₑᵥ st₂ → st₂ ↦ᵣₑᵥ* st₃ → st₁ ↦ᵣₑᵥ* st₃\n\n _++↦ᵣₑᵥ_ : ∀ {st₁ st₂ st₃} → st₁ ↦ᵣₑᵥ* st₂ → st₂ ↦ᵣₑᵥ* st₃ → st₁ ↦ᵣₑᵥ* st₃\n ◾ ++↦ᵣₑᵥ st₁↦ᵣₑᵥ*st₂ = st₁↦ᵣₑᵥ*st₂\n (st₁↦ᵣₑᵥst₁' ∷ st₁'↦ᵣₑᵥ*st₂) ++↦ᵣₑᵥ st₂'↦ᵣₑᵥ*st₃ = st₁↦ᵣₑᵥst₁' ∷ (st₁'↦ᵣₑᵥ*st₂ ++↦ᵣₑᵥ st₂'↦ᵣₑᵥ*st₃)\n\n Rev↦ : ∀ {st₁ st₂} → st₁ ↦* st₂ → st₂ ↦ᵣₑᵥ* st₁\n Rev↦ ◾ = ◾\n Rev↦ (r ∷ rs) = Rev↦ rs ++↦ᵣₑᵥ ((r ᵣₑᵥ) ∷ ◾)\n\n Rev↦ᵣₑᵥ : ∀ {st₁ st₂} → st₁ ↦ᵣₑᵥ* st₂ → st₂ ↦* st₁\n Rev↦ᵣₑᵥ ◾ = ◾\n Rev↦ᵣₑᵥ ((r ᵣₑᵥ) ∷ rs) = Rev↦ᵣₑᵥ rs ++↦ (r ∷ ◾)\n\n deterministic* : ∀ {st st₁ st₂} → st ↦* st₁ → st ↦* st₂\n → is-stuck st₁ → is-stuck st₂\n → st₁ ≡ st₂\n deterministic* ◾ ◾ stuck₁ stuck₂ = refl\n deterministic* ◾ (r ∷ ↦*₂) stuck₁ stuck₂ = ⊥-elim (stuck₁ (_ , r))\n deterministic* (r ∷ ↦*₁) ◾ stuck₁ stuck₂ = ⊥-elim (stuck₂ (_ , r))\n deterministic* (r₁ ∷ ↦*₁) (r₂ ∷ ↦*₂) stuck₁ stuck₂ with deterministic r₁ r₂\n ... | refl = deterministic* ↦*₁ ↦*₂ stuck₁ stuck₂\n\n deterministic*' : ∀ {st st₁ st'} → (rs₁ : st ↦* st₁) → (rs : st ↦* st')\n → is-stuck st'\n → Σ[ rs' ∈ st₁ ↦* st' ] (len↦ rs ≡ len↦ rs₁ + len↦ rs')\n deterministic*' ◾ rs stuck = rs , refl\n deterministic*' (r ∷ rs₁) ◾ stuck = ⊥-elim (stuck (_ , r))\n deterministic*' (r ∷ rs₁) (r' ∷ rs) stuck with deterministic r r'\n ... | refl with deterministic*' rs₁ rs stuck\n ... | (rs' , eq) = rs' , cong suc eq\n\n deterministicᵣₑᵥ* : ∀ {st st₁ st₂} → st ↦ᵣₑᵥ* st₁ → st ↦ᵣₑᵥ* st₂\n → is-initial st₁ → is-initial st₂\n → st₁ ≡ st₂\n deterministicᵣₑᵥ* ◾ ◾ initial₁ initial₂ = refl\n deterministicᵣₑᵥ* ◾ (r ᵣₑᵥ ∷ ↦ᵣₑᵥ*₂) initial₁ initial₂ = ⊥-elim (initial₁ (_ , r))\n deterministicᵣₑᵥ* (r ᵣₑᵥ ∷ ↦ᵣₑᵥ*₁) ◾ initial₁ initial₂ = ⊥-elim (initial₂ (_ , r))\n deterministicᵣₑᵥ* (r₁ ᵣₑᵥ ∷ ↦ᵣₑᵥ*₁) (r₂ ᵣₑᵥ ∷ ↦ᵣₑᵥ*₂) initial₁ initial₂ with deterministicᵣₑᵥ r₁ r₂\n ... | refl = deterministicᵣₑᵥ* ↦ᵣₑᵥ*₁ ↦ᵣₑᵥ*₂ initial₁ initial₂\n\n data _↦[_]_ : State → ℕ → State → Set (L.suc ℓ) where\n ◾ : ∀ {st} → st ↦[ 0 ] st\n _∷_ : ∀ {st₁ st₂ st₃ n} → st₁ ↦ st₂ → st₂ ↦[ n ] st₃ → st₁ ↦[ suc n ] st₃\n\n _++↦ⁿ_ : ∀ {st₁ st₂ st₃ n m} → st₁ ↦[ n ] st₂ → st₂ ↦[ m ] st₃ → st₁ ↦[ n + m ] st₃\n ◾ ++↦ⁿ st₁↦*st₂ = st₁↦*st₂\n (st₁↦st₁' ∷ st₁'↦*st₂) ++↦ⁿ st₂'↦*st₃ = st₁↦st₁' ∷ (st₁'↦*st₂ ++↦ⁿ st₂'↦*st₃)\n\n data _↦ᵣₑᵥ[_]_ : State → ℕ → State → Set (L.suc ℓ) where\n ◾ : ∀ {st} → st ↦ᵣₑᵥ[ 0 ] st\n _∷_ : ∀ {st₁ st₂ st₃ n} → st₁ ↦ᵣₑᵥ st₂ → st₂ ↦ᵣₑᵥ[ n ] st₃ → st₁ ↦ᵣₑᵥ[ suc n ] st₃\n\n _++↦ᵣₑᵥⁿ_ : ∀ {st₁ st₂ st₃ n m} → st₁ ↦ᵣₑᵥ[ n ] st₂ → st₂ ↦ᵣₑᵥ[ m ] st₃ → st₁ ↦ᵣₑᵥ[ n + m ] st₃\n ◾ ++↦ᵣₑᵥⁿ st₁↦*st₂ = st₁↦*st₂\n (st₁↦st₁' ∷ st₁'↦*st₂) ++↦ᵣₑᵥⁿ st₂'↦*st₃ = st₁↦st₁' ∷ (st₁'↦*st₂ ++↦ᵣₑᵥⁿ st₂'↦*st₃)\n\n deterministicⁿ : ∀ {st st₁ st₂ n} → st ↦[ n ] st₁ → st ↦[ n ] st₂\n → st₁ ≡ st₂\n deterministicⁿ ◾ ◾ = refl\n deterministicⁿ (r₁ ∷ rs₁) (r₂ ∷ rs₂) with deterministic r₁ r₂\n ... | refl = deterministicⁿ rs₁ rs₂\n\n deterministicᵣₑᵥⁿ : ∀ {st st₁ st₂ n} → st ↦ᵣₑᵥ[ n ] st₁ → st ↦ᵣₑᵥ[ n ] st₂\n → st₁ ≡ st₂\n deterministicᵣₑᵥⁿ ◾ ◾ = refl\n deterministicᵣₑᵥⁿ (r₁ ᵣₑᵥ ∷ rs₁) (r₂ ᵣₑᵥ ∷ rs₂) with deterministicᵣₑᵥ r₁ r₂\n ... | refl = deterministicᵣₑᵥⁿ rs₁ rs₂\n\n\n private\n split↦ⁿ : ∀ {st st'' n m} → st ↦ᵣₑᵥ[ n + m ] st''\n → ∃[ st' ] (st ↦ᵣₑᵥ[ n ] st' × st' ↦ᵣₑᵥ[ m ] st'')\n split↦ⁿ {n = 0} {m} rs = _ , ◾ , rs\n split↦ⁿ {n = suc n} {m} (r ∷ rs) with split↦ⁿ {n = n} {m} rs\n ... | st' , st↦ⁿst' , st'↦ᵐst'' = st' , (r ∷ st↦ⁿst') , st'↦ᵐst''\n\n diff : ∀ {n m} → n < m → ∃[ k ] (0 < k × n + k ≡ m)\n diff {0} {(suc m)} (s≤s z≤n) = suc m , s≤s z≤n , refl\n diff {(suc n)} {(suc (suc m))} (s≤s (s≤s n≤m)) with diff {n} {suc m} (s≤s n≤m)\n ... | k , 0>= (λ t → ♯ unambiguous (D t p))\n ∣ return⋆ (take 1 xs)\n\n -- The following two parsers are (parser) equal.\n\n p₁ : Parser Bool Bool (true ∷ (false ∷ []))\n p₁ = return true ∣ return false\n\n p₂ : Parser Bool Bool (false ∷ (true ∷ []))\n p₂ = return false ∣ return true\n\n equal : p₁ ≅P p₂\n equal = AdditiveMonoid.commutative (return true) (return false)\n\n -- However, unambiguous does not respect this equality.\n\n unambiguous-is-not-a-congruence :\n ¬ (unambiguous p₁ ≅ unambiguous p₂)\n unambiguous-is-not-a-congruence eq =\n case Inverse.to eq ⟨$⟩ S.∣-right [] (S.∣-left S.return) of λ\n { (S.∣-right .[] (S.∣-left ()))\n ; (S.∣-right .[] (S.∣-right .([ false ]) ()))\n ; (S.∣-left []∈) → helper refl []∈\n }\n where\n helper : ∀ {s} {f : Bool → List Bool}\n {p : ∀ b → ∞ (Parser Bool Bool (f b))} →\n s ≡ [] →\n ¬ (true ∈ token >>= p · s)\n helper () (S._>>=_ S.token _)\n\nmodule Example₂ where\n\n -- A combinator which returns true (without consuming input) if its\n -- argument is \"fail\", and false otherwise.\n\n is-fail-bag : ∀ {Tok R xs} → Parser Tok R xs → List Bool\n is-fail-bag fail = [ true ]\n is-fail-bag _ = [ false ]\n\n is-fail : ∀ {Tok R xs}\n (p : Parser Tok R xs) → Parser Tok Bool (is-fail-bag p)\n is-fail fail = return true\n is-fail (return x) = return false\n is-fail token = return false\n is-fail (p₁ ∣ p₂) = return false\n is-fail (f <$> p) = return false\n is-fail (p₁ ⊛ p₂) = return false\n is-fail (p₁ >>= p₂) = return false\n is-fail (nonempty p) = return false\n is-fail (cast xs₁≈xs₂ p) = return false\n\n -- The following parsers are equal, but is-fail treats them\n -- differently.\n\n p₁ : Parser Bool Bool []\n p₁ = fail\n\n p₂ : Parser Bool Bool []\n p₂ = fail ∣ fail\n\n equal : p₁ ≅P p₂\n equal = Inv.id ∷ λ _ → ♯ equal\n\n is-fail-is-not-a-congruence : ¬ (is-fail p₁ ≅ is-fail p₂)\n is-fail-is-not-a-congruence eq with Inverse.to eq ⟨$⟩ S.return\n ... | ()\n", "meta": {"hexsha": "69d4793795bdacf345ae2be205c8ab4a17bf2c20", "size": 3313, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "TotalParserCombinators/NotACongruence.agda", "max_stars_repo_name": "nad/parser-combinators", "max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z", "max_issues_repo_path": "TotalParserCombinators/NotACongruence.agda", "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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": "TotalParserCombinators/NotACongruence.agda", "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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": 32.4803921569, "max_line_length": 72, "alphanum_fraction": 0.6067008753, "num_tokens": 982, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6584175139669997, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.3701468541238939}} {"text": "open import Data.Nat as N using (ℕ; zero; suc; _<_; _≤_; _>_; z≤n; s≤s; _∸_)\nopen import Data.Nat.Properties as N\nopen import Data.Vec as V using (Vec; []; _∷_)\nopen import Data.Vec.Properties as V\nopen import Data.Fin as F using (Fin; zero; suc)\nimport Data.Fin.Properties as F\nopen import Data.List as L using (List; []; _∷_)\nopen import Data.Unit using (⊤; tt)\nopen import Data.Nat.Properties\nimport Data.Nat.DivMod as N\nopen import Data.Bool using (Bool; true; false)\nopen import Data.Product renaming (_×_ to _⊗_)\n\nopen import Relation.Binary.PropositionalEquality -- using (≡-Reasoning; _≡_; refl; cong; sym; subst; subst₂) -- (Extensionality)\nopen import Relation.Nullary\nopen import Relation.Nullary.Decidable\nopen import Relation.Nullary.Negation\n\nopen import Function\nopen import Reflection\nopen import Level using () renaming (zero to ℓ0; suc to lsuc)\n\nopen import Array.Base\nopen import Array.Properties\n\nopen import Agda.Builtin.Float\n\n\ndata dy-args : ∀ m n → Vec ℕ m → Vec ℕ n → Set where\n n-n : ∀ {n s} → dy-args n n s s\n n-0 : ∀ {n s} → dy-args n 0 s []\n 0-n : ∀ {n s} → dy-args 0 n [] s\n\ndy-args-dim : ∀ {m n sx sy} → dy-args m n sx sy → ℕ\ndy-args-dim {m} n-n = m\ndy-args-dim {m} n-0 = m\ndy-args-dim {m}{n} 0-n = n\n\ndy-args-shp : ∀ {m n sx sy} → (dy : dy-args m n sx sy) → Vec ℕ (dy-args-dim dy)\ndy-args-shp {m}{n}{sx} n-n = sx\ndy-args-shp {m}{n}{sx} n-0 = sx\ndy-args-shp {m}{n}{sx}{sy} 0-n = sy\n\ndy-args-ok? : Term → TC ⊤\ndy-args-ok? hole = do\n goal ← inferType hole\n def (quote dy-args) (vArg m ∷ vArg n ∷ vArg sx ∷ vArg sy ∷ []) ← reduce goal\n where _ → typeError (strErr \"expected dy-args expression in goal, found:\" ∷ termErr goal ∷ [])\n reduce m >>= λ where\n (lit (nat 0)) → unify hole (con (quote 0-n) [])\n (meta id _) → blockOnMeta id\n m → reduce n >>= λ where\n (lit (nat 0)) → unify hole (con (quote n-0) [])\n (meta id _) → blockOnMeta id\n n → do\n catchTC\n (unify m n)\n (typeError (strErr \"no valid dy-args found for goal: \" ∷ termErr goal ∷ []))\n -- XXX we could further check that sx and sy unify as well, however, this would\n -- fail later if they don't.\n unify hole (con (quote n-n) [])\n\ndy-type : ∀ a → Set a → Set a\ndy-type a X = ∀ {m n sx sy} {@(tactic dy-args-ok?) args : dy-args m n sx sy}\n → Ar X m sx → Ar X n sy → Ar X _ (dy-args-shp args)\n\nlift′ : ∀ {a}{X : Set a} → (_⊕_ : X → X → X) → dy-type a X\nlift′ _⊕_ {args = n-n} (imap a) (imap b) = imap λ iv → a iv ⊕ b iv\nlift′ _⊕_ {args = n-0} (imap a) (imap b) = imap λ iv → a iv ⊕ b []\nlift′ _⊕_ {args = 0-n} (imap a) (imap b) = imap λ iv → a [] ⊕ b iv\n\n\nScal : ∀ {a} → Set a → Set a\nScal X = Ar X 0 []\n\n--scal : ∀ {a}{X : Set a} → X → Scal X\n--scal = cst\n\n--unscal : ∀ {a}{X : Set a} → Scal X → X\n--unscal (imap f) = f []\n\n\n--module reduce-split where\n-- split-thm : ∀ m n → (m N.⊓ n) N.+ (n N.∸ m) ≡ n\n-- split-thm zero n = refl\n-- split-thm (suc m) zero = refl\n-- split-thm (suc m) (suc n) = cong suc (split-thm m n)\n--\n-- {-# REWRITE split-thm #-}\n--\n-- split : ∀ {X : Set}{n} → (m : ℕ) → (xy : Vec X n)\n-- → ∃₂ λ (x : Vec X (m N.⊓ n)) (y : Vec X (n N.∸ m)) → x V.++ y ≡ xy\n-- split zero xy = [] , xy , refl\n-- split {n = zero} (suc m) xy = [] , xy , refl\n-- split {X = X}{n = suc n} (suc m) (x ∷ xy) with split m xy\n-- ... | xs , ys , refl = x ∷ xs , ys , refl\n--\n-- split-axis : ∀ m → (k : Fin m) → ∃₂ λ l r → l N.+ 1 N.+ r ≡ m\n-- split-axis zero ()\n-- split-axis (suc m) zero = 0 , m , refl\n-- split-axis (suc m) (suc k) with split-axis m k\n-- ... | l' , r' , refl = suc l' , r' , refl\n--\n--\n-- split-vec : ∀ {l r}{X : Set} → (xyz : Vec X (l N.+ 1 N.+ r))\n-- → Σ[ x ∈ Vec X l ] Σ[ y ∈ Vec X 1 ] Σ[ z ∈ Vec X r ] ((x V.++ y) V.++ z ≡ xyz)\n-- split-vec {zero} {r} (h ∷ t) = [] , (h ∷ []) , t , refl\n-- split-vec {suc l} {r} (h ∷ t) with split-vec {l = l} t\n-- ... | l' , m' , r' , refl = h ∷ l' , m' , r' , refl\n\n\n\ndata SVup (X : Set) : Set → (d : ℕ) → (sh : Vec ℕ d) → Set where\n instance\n scal : SVup X X 0 []\n vect : ∀ {n} → SVup X (Vec X n) 1 (n ∷ [])\n arry : ∀ {d s} → SVup X (Ar X d s) d s\n -- XXX do we need the id case for arrays themselves?\n\ninfixr 30 ▴_\n▴_ : ∀ {X A d s}{{t : SVup X A d s}} → A → Ar X d s\n▴_ ⦃ t = scal ⦄ a = cst a --imap λ _ → a\n▴_ ⦃ t = vect ⦄ a = imap λ iv → V.lookup a $ ix-lookup iv zero --imap λ where (i ∷ []) → V.lookup a i\n▴_ ⦃ t = arry ⦄ a = a\n\n{-\ndata SVdown (X : Set) : (d : ℕ) → (sh : Vec ℕ d) → Set → Set where\n instance\n scal : SVdown X 0 [] X\n vect : ∀ {n} → SVdown X 1 (n ∷ []) (Vec X n)\n -- XXX do we need the id case for arrays themselves?\n-}\n\ninfixr 30 ▾_\n▾_ : ∀ {X A d s}{{t : SVup X A d s}} → Ar X d s → A\n▾_ ⦃ t = scal ⦄ (imap a) = a []\n▾_ ⦃ t = vect ⦄ (imap a) = V.tabulate λ i → a $ i ∷ []\n▾_ ⦃ t = arry ⦄ a = a\n\n-- FIXME These cases are missing\n-- Ar X 1 [n] + Vec X 0\n-- Ar X 1 [n] + Vec X 1\n-- Ar X 1 [n] + Vec X n\n\n-- FIXME we should allow for different types of lhs and rhs and result,\n-- e.g. replicate : ℕ → Char → String (not critical, but would be nice).\n-- FIXME we can add the cases when indices are added with scalars/arrays/vectors.\n--\n-- Simplify handling concatenation of `Prog`s and `String`s\ndata DyScalVec (X : Set) : Set → Set → (d : ℕ) → (sh : Vec ℕ d) → Set where\n instance\n s-s : DyScalVec X X X 0 []\n s-v : ∀ {n} → DyScalVec X X (Vec X n) 1 (n ∷ [])\n s-a : ∀ {d s} → DyScalVec X X (Ar X d s) d s\n v-s : ∀ {n} → DyScalVec X (Vec X n) X 1 (n ∷ [])\n v-v : ∀ {n} → DyScalVec X (Vec X n) (Vec X n) 1 (n ∷ [])\n -- v-a : X (Ar X 1 (n ∷ [])) (Vec X n) 1 (n ∷ [])\n a-s : ∀ {d s} → DyScalVec X (Ar X d s) X d s\n -- a-v : X (Vec X n) (Ar X 1 (n ∷ [])) 1 (n ∷ [])\n a-a : ∀ {m n sx sy}{@(tactic dy-args-ok?) args : dy-args m n sx sy} → DyScalVec X (Ar X m sx) (Ar X n sy) (dy-args-dim args) (dy-args-shp args)\n\n\n▴ₗ : ∀ {X A B d s} {{t : DyScalVec X A B d s}} → A → Ar X d s\n▴ₗ {{s-s}} a = cst a\n▴ₗ {{s-v}} a = cst a\n▴ₗ {{s-a}} a = cst a\n▴ₗ {{v-s}} a = ▴ a\n▴ₗ {{v-v}} a = ▴ a\n▴ₗ {{a-s}} a = a\n▴ₗ ⦃ t = a-a {args = n-n} ⦄ a = a\n▴ₗ ⦃ t = a-a {args = n-0} ⦄ a = a\n▴ₗ ⦃ t = a-a {args = 0-n} ⦄ a = cst (sel a [])\n\n\n▴ᵣ : ∀ {X A B d s} {{t : DyScalVec X A B d s}} → B → Ar X d s\n▴ᵣ {{s-s}} b = cst b\n▴ᵣ {{s-v}} b = ▴ b\n▴ᵣ {{s-a}} b = b\n▴ᵣ {{v-s}} b = cst b\n▴ᵣ {{v-v}} b = ▴ b\n▴ᵣ {{a-s}} b = cst b\n▴ᵣ ⦃ t = a-a {args = n-n} ⦄ b = b\n▴ᵣ ⦃ t = a-a {args = n-0} ⦄ b = cst (sel b [])\n▴ᵣ ⦃ t = a-a {args = 0-n} ⦄ b = b\n\n\n--infixr 20 _-′_\n--_-′_ = lift′ N._∸_\n\n\n_-safe-_ : (a : ℕ) → (b : ℕ) .{≥ : a N.≥ b} → ℕ\na -safe- b = a N.∸ b\n\n{-\ninfixr 20 _-ₙ_\n_-ₙ_ : ∀ {n}{s}\n → (a : Ar ℕ n s) → (b : Ar ℕ n s)\n → .{≥ : a ≥a b}\n → Ar ℕ n s\n(imap f -ₙ imap g) {≥} = imap λ iv → (f iv -safe- g iv) {≥ = ≥ iv}\n-}\n\n\n---- FIXME: I guess we can eliminate _-′_ and lift′ entirely by inlining definitions.\n--infixr 20 _-_\n--_-_ : ∀ {A B d s}{{t : DyScalVec ℕ A B d s}} → (a : A) → (b : B) → .{≥ : ▴ₗ a ≥a ▴ᵣ b} → Ar ℕ d s\n--_-_ ⦃ t = s-s ⦄ a b {a≥b} = imap λ iv → (a -safe- b) {a≥b iv}\n--_-_ ⦃ t = s-v ⦄ a b {a≥b} = imap λ iv → (a -safe- sel (▴ b) iv) {a≥b iv}\n--_-_ ⦃ t = s-a ⦄ a b {a≥b} = imap λ iv → (a -safe- sel b iv) {a≥b iv} --= ▴ a -′ b\n--_-_ ⦃ t = v-s ⦄ a b {a≥b} = imap λ iv → (sel (▴ a) iv -safe- b) {a≥b iv} -- = ▴ a -′ ▴ b\n--_-_ ⦃ t = v-v ⦄ a b {a≥b} = imap λ iv → (sel (▴ a) iv -safe- sel (▴ b) iv) {a≥b iv} --= ▴ a -′ ▴ b\n--_-_ ⦃ t = a-s ⦄ a b {a≥b} = imap λ iv → (sel a iv -safe- b) {a≥b iv} --= a -′ ▴ b\n--_-_ ⦃ t = a-a {args = n-n} ⦄ a b {a≥b} = imap λ iv → (sel a iv -safe- sel b iv) {a≥b iv}\n--_-_ ⦃ t = a-a {args = n-0} ⦄ a b {a≥b} = imap λ iv → (sel a iv -safe- sel b []) {a≥b iv}\n--_-_ ⦃ t = a-a {args = 0-n} ⦄ a b {a≥b} = imap λ iv → (sel a [] -safe- sel b iv) {a≥b iv}\n\n\ninfixr 20 _-_\n_-_ : ∀ {A B d s}{{t : DyScalVec ℕ A B d s}} → (a : A) → (b : B) → .{≥ : ▴ₗ a ≥a ▴ᵣ b} → Ar ℕ d s\n_-_ ⦃ t = s-s ⦄ a b = imap λ iv → (a N.∸ b) \n_-_ ⦃ t = s-v ⦄ a b = imap λ iv → (a N.∸ sel (▴ b) iv)\n_-_ ⦃ t = s-a ⦄ a b = imap λ iv → (a N.∸ sel b iv)\n_-_ ⦃ t = v-s ⦄ a b = imap λ iv → (sel (▴ a) iv N.∸ b)\n_-_ ⦃ t = v-v ⦄ a b = imap λ iv → (sel (▴ a) iv N.∸ sel (▴ b) iv)\n_-_ ⦃ t = a-s ⦄ a b = imap λ iv → (sel a iv N.∸ b)\n_-_ ⦃ t = a-a {args = n-n} ⦄ a b = imap λ iv → (sel a iv N.∸ sel b iv) \n_-_ ⦃ t = a-a {args = n-0} ⦄ a b = imap λ iv → (sel a iv N.∸ sel b []) \n_-_ ⦃ t = a-a {args = 0-n} ⦄ a b = imap λ iv → (sel a [] N.∸ sel b iv) \n-- _-′_ {args = args} a b\n\n\nlift : ∀ {X A B d s}{{t : DyScalVec X A B d s}} → A → B → (_⊕_ : X → X → X) → Ar X d s\nlift ⦃ t ⦄ a b _⊕_ = imap λ iv → sel (▴ₗ a) iv ⊕ sel (▴ᵣ b) iv\n\n-- ℕ operations\ninfixr 20 _+_ _×_\n_+_ _×_ : ∀ {A B d s}{{t : DyScalVec ℕ A B d s}} → A → B → Ar ℕ d s\na + b = lift a b N._+_\na × b = lift a b N._*_\n\n\n-- Float operations\ninfixr 20 _+ᵣ_ _-ᵣ_ _×ᵣ_ _÷ᵣ_\n_+ᵣ_ _-ᵣ_ _×ᵣ_ _÷ᵣ_ : ∀ {A B d s}{{t : DyScalVec Float A B d s}} → A → B → Ar Float d s\na +ᵣ b = lift a b primFloatPlus\na -ᵣ b = lift a b primFloatMinus\na ×ᵣ b = lift a b primFloatTimes\n-- XXX we can request the proof that the right argument is not zero.\n-- However, the current primFloatDiv has the type Float → Float → Float, so...\na ÷ᵣ b = lift a b primFloatDiv\n\n\nlift-unary : ∀ {X A d s}{{t : SVup X A d s}} → (X → X) → A → Ar X d s\nlift-unary ⦃ t = scal ⦄ f a = cst $ f a\nlift-unary ⦃ t = vect ⦄ f a = imap λ iv → f $ V.lookup a $ ix-lookup iv zero\nlift-unary ⦃ t = arry ⦄ f (imap a) = imap λ iv → f $ a iv\n\n\ninfixr 20 -ᵣ_ ÷ᵣ_ *ᵣ_\n-ᵣ_ ÷ᵣ_ *ᵣ_ : ∀ {A d s}{{t : SVup Float A d s}} → A → Ar Float d s\n\n*ᵣ_ = lift-unary primFloatExp\n-ᵣ_ = lift-unary primFloatNegate\n÷ᵣ_ = lift-unary (primFloatDiv 1.0)\n\n\n\nmodule reduce-custom where\n drop-last : ∀ {m}{X : Set} → Vec X m → Vec X (m N.∸ 1)\n drop-last {0} x = x\n drop-last {1} x = []\n drop-last {suc (suc m)} (x ∷ xs) = x ∷ drop-last xs\n\n gz : ℕ → ℕ\n gz 0 = 0\n gz _ = 1\n\n take-last : ∀ {m}{X : Set} → Vec X m → Vec X (gz m)\n take-last {0} x = x\n take-last {1} x = x\n take-last {suc (suc m)} (x ∷ xs) = take-last xs\n\n _tldl++_ : ∀ {d s} → Ix (d N.∸ 1) (drop-last s) → Ix (gz d) (take-last s) → Ix d s\n _tldl++_ {0} {s} iv jv = iv\n _tldl++_ {1} {s} iv jv = jv\n _tldl++_ {suc (suc d)} {s ∷ ss} (i ∷ iv) jv = i ∷ (iv tldl++ jv)\n\n reduce-1d : ∀ {X Y : Set}{s} → (X → Y → Y) → Y → Ar X 1 s → Y\n reduce-1d {s = 0 ∷ []} _⊕_ ε a = ε\n reduce-1d {s = suc x ∷ []} _⊕_ ε (imap a) = a (zero ∷ []) ⊕ reduce-1d {s = x ∷ []} _⊕_ ε (imap λ where (i ∷ []) → a (suc i ∷ []))\n\n infixr 20 _/′_\n _/′_ : ∀ {X Y : Set}{d s} → (X → Y → Y) → Ar X d s → {ε : Y} → Ar Y _ (drop-last s)\n _/′_ {d = 0} f (imap a) {ε} = imap λ iv → ε\n _/′_ {d = suc d} f (imap a) {ε} = imap λ iv → reduce-1d f ε (imap λ jv → a (iv tldl++ jv))\n\n data reduce-neut : {X Y : Set} → (X → Y → Y) → Y → Set where\n instance\n plus-nat : reduce-neut N._+_ 0\n mult-nat : reduce-neut N._*_ 1\n plus-flo : reduce-neut primFloatPlus 0.0\n gplus-float : reduce-neut (_+ᵣ_ {{t = a-a {sx = []}{sy = []}{args = n-n} }}) (cst 0.0)\n\n infixr 20 _/_\n _/_ : ∀ {X Y : Set}{n s ε}\n → (_⊕_ : X → Y → Y) → {{c : reduce-neut _⊕_ ε}}\n → Ar X n s → Ar Y _ (drop-last s)\n _/_ {ε = ε} f a = (f /′ a){ε}\n\n infixr 20 _//_\n _//_ : ∀ {X Y : Set}{n s ε}\n → (_⊕_ : Scal X → Scal Y → Scal Y) → {{c : reduce-neut _⊕_ ε}}\n → Ar X n s → Ar Y _ (drop-last s)\n _//_ {ε = ε} f a = imap λ jv → ▾ (sel ((f /′ (imap λ iv → ▴ (sel a iv))){ε}) jv)\n\n infixr 20 _/ᵣ_\n _/ᵣ_ : ∀ {X : Set}{d}{s}{m} → (n : ℕ) → Ar X (d N.+ 1) (s V.++ (m ∷ [])) → Ar X (d N.+ 1) (s V.++ (n N.* m ∷ []))\n _/ᵣ_ {d = d} {s = s} 0 a = imap λ iv → magic-fin (ix-lookup (take-ix-r s _ iv) zero)\n _/ᵣ_ {d = d} {s = s} (suc n) a = imap λ iv → let i = ix-lookup (take-ix-r s _ iv) zero\n l = take-ix-l s _ iv\n i/n = F.fromℕ< $ /-mono-f {b = suc n} (F.toℕ0\n a 0} → Fin (suc (m N.* n N.∸ m))\n _*lf_ {n} m (b) {m>0} = let\n m*sb≤m*n = *-monoʳ-≤ m $ F.toℕ 0} → let s = 1 + (m × s) -′ ▴ m in Ix n (▾ s)\n --(a il× ix) {m>0} = ix-tabulate λ i → subst Fin (sym (V.lookup∘tabulate _ i)) $ (a *lf ix-lookup ix i){m>0}\n\n{-\n avgpool' : ∀ {s}\n → Ar Float 2 $ ▾ (2 × s)\n → Ar Float 2 s\n avgpool' {s} (imap p) = imap body\n where\n m>0⇒k≤k*m : ∀ {m} → m N.> 0 → ∀ k → k N.≤ k N.* m\n m>0⇒k≤k*m m>0 zero = N.z≤n\n m>0⇒k≤k*m m>0 (suc k) = +-mono-≤ m>0 (m>0⇒k≤k*m m>0 k)\n\n --a≤a*b\n\n thm : ∀ {d s} → Ix d s → ∀ i → d N.+ (d N.* V.lookup s i N.∸ d) ≡ d N.* V.lookup s i\n thm {d}{s} ix i with V.lookup s i | ix-lookup ix i\n ... | zero | ()\n ... | suc m | _ = m+[n∸m]≡n (m>0⇒k≤k*m {m = suc m} (N.s≤s N.z≤n) d)\n\n thmx : ∀ {d s} → Ix d s → ∀ i → V.lookup (▾ (d + (d × s) -′ ▴ d)) i ≡ V.lookup (▾ (d × s)) i\n thmx {d}{s} ix i with V.lookup s i | inspect (V.lookup s) i | ix-lookup ix i\n ... | zero | _ | ()\n ... | suc m | [ pf ] | _ = begin\n V.lookup (V.tabulate (λ z → d N.+ (d N.* V.lookup s z N.∸ d))) i ≡⟨ lookup∘tabulate _ i ⟩\n d N.+ (d N.* V.lookup s i N.∸ d) ≡⟨ cong (d N.+_) (cong (N._∸ d) (cong (d N.*_) pf)) ⟩\n d N.+ (d N.* suc m N.∸ d) ≡⟨ m+[n∸m]≡n (m>0⇒k≤k*m {m = suc m} (N.s≤s N.z≤n) d) ⟩\n d N.* suc m ≡⟨ cong (d N.*_) (sym pf) ⟩\n d N.* V.lookup s i ≡⟨ sym (lookup∘tabulate _ i) ⟩\n V.lookup (V.tabulate (λ z → d N.* V.lookup s z)) i\n ∎\n where open ≡-Reasoning\n\n\n body : _ → _\n body iv = let\n ixs = iota (2 ∷ 2 ∷ [])\n ix = (2 il× iv) {N.s≤s N.z≤n}\n f iv = p $ subst-ix {!!} $ iv i+ ix\n xx = primFloatPlus / , f ̈ ixs\n in {!!}\n\n-}\n\n avgpool : ∀ {s}\n → Ar ℕ 2 $ ▾ (s × 2)\n → Ar ℕ 2 s\n avgpool {s} (imap p) = imap body\n where body : _ → _\n body iv = let\n sh = s × 2\n ix , ix (lemma r) (code-bmleft-template-diag r x)\n coe-coerce-path-code-bmglue-template idp lemma x =\n coe (app= (λ= (ua ∘ lemma)) idp) x\n =⟨ ap (λ p → coe p x) (app=-β (ua ∘ lemma) idp) ⟩\n coe (ua (lemma idp)) x\n =⟨ coe-β (lemma idp) x ⟩\n –> (lemma idp) x\n =⟨ ! (ap (–> (lemma idp)) (code-bmleft-template-diag-idp x)) ⟩\n –> (lemma idp) (code-bmleft-template-diag idp x)\n =∎\n\n -- Here is the actually lemma we want!\n -- A succinct breakdown of [coerce-path code (glue q)].\n abstract\n coe-coerce-path-code-bmglue : ∀ {b₁} (q₀₁ : Q a₀ b₁) x\n → coe (coerce-path (bmglue q₀₁)) x\n == Coh.to q₀₀ q₀₁ (bmglue q₀₁) (code-bmleft-template-diag (bmglue q₀₁) x)\n coe-coerce-path-code-bmglue q₀₁ x =\n coe (coerce-path-template (bmglue q₀₁) (apd code (bmglue q₀₁))) x\n =⟨ ap (λ p → coe (coerce-path-template (bmglue q₀₁) p) x) (Code.glue-β q₀₁) ⟩\n coe (coerce-path-template (bmglue q₀₁) (code-bmglue q₀₁)) x\n =⟨ coe-coerce-path-code-bmglue-template (bmglue q₀₁) (Coh.eqv q₀₀ q₀₁) x ⟩\n Coh.to q₀₀ q₀₁ (bmglue q₀₁) (code-bmleft-template-diag (bmglue q₀₁) x)\n =∎\n\n -- This is the only case you care for contractibiltiy.\n abstract\n code-coh-lemma : ∀ {b₁} (q₀₁ : Q a₀ b₁) → code-center (bmglue q₀₁) == [ q₀₁ , idp ]\n code-coh-lemma q₀₁ =\n coe (coerce-path (bmglue q₀₁)) code-center-idp\n =⟨ coe-coerce-path-code-bmglue q₀₁ code-center-idp ⟩\n Coh.to' q₀₀ q₀₁ (bmglue q₀₁) (q₀₀ , α₁α₁⁻¹α₂=α₂ (bmglue q₀₀) (bmglue q₀₁))\n =⟨ ap (Coh.To.ext q₀₀ (_ , q₀₀) (_ , q₀₁) (bmglue q₀₁)) (path-lemma (bmglue q₀₀) (bmglue q₀₁)) ⟩\n Coh.To.ext q₀₀ (_ , q₀₀) (_ , q₀₁) (bmglue q₀₁) (! path)\n =⟨ Coh.To.β-r q₀₀ (_ , q₀₁) (bmglue q₀₁) (! path) ⟩\n [ q₀₁ , path ∙' ! path ]\n =⟨ ap (λ p → [ q₀₁ , p ]) (!-inv'-r path) ⟩\n [ q₀₁ , idp ]\n =∎\n where\n path = Coh.βPair.path (Coh.βpair-bmright q₀₀ q₀₁ (bmglue q₀₁))\n\n -- this is defined to be the path generated by [code-bmleft-template-diag]\n α₁α₁⁻¹α₂=α₂ : ∀ {p₁ p₂ p₃ : BMPushout} (α₁ : p₁ == p₂) (α₂ : p₁ == p₃)\n → α₁ ∙' ! α₁ ∙' α₂ == α₂\n α₁α₁⁻¹α₂=α₂ α₁ α₂ = ! (∙'-assoc α₁ (! α₁) α₂) ∙ ap (_∙' α₂) (!-inv'-r α₁) ∙' ∙'-unit-l α₂\n\n -- the relation of this path and the one from CoherenceData\n path-lemma : ∀ {p₁ p₂ p₃ : BMPushout} (α₁ : p₁ == p₂) (α₂ : p₁ == p₃)\n → α₁α₁⁻¹α₂=α₂ α₁ α₂ == ! (Coh.α₁=α₂α₂⁻¹α₁ α₂ α₁)\n path-lemma idp idp = idp\n\n -- Make [r] free to apply identification elimination.\n code-coh : ∀ {b₁} (r : bmleft a₀ == bmright b₁) (s : hfiber bmglue r) → code-center r == [ s ]\n code-coh ._ (q₀₁ , idp) = code-coh-lemma q₀₁\n\n -- Finish the lemma.\n code-contr : ∀ {b₁} (r : bmleft a₀ == bmright b₁) → is-contr (Trunc (m +2+ n) (hfiber bmglue r))\n code-contr r = code-center r , Trunc-elim\n (λ _ → =-preserves-level Trunc-level) (code-coh r)\n\n-- The final theorem.\n-- It is sufficient to find some [q₀₀].\nblakers-massey : ∀ {a₀ b₀} → has-conn-fibers (m +2+ n) (bmglue {a₀} {b₀})\nblakers-massey {a₀} r = Trunc-rec\n (prop-has-level-S is-connected-is-prop)\n (λ{(_ , q₀₀) → code-contr q₀₀ r})\n (fst (f-conn a₀))\n", "meta": {"hexsha": "9e0d3cd63252ae3c01ac6245c13d3cab9e012b5d", "size": 7270, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/BlakersMassey.agda", "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/homotopy/BlakersMassey.agda", "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/homotopy/BlakersMassey.agda", "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "avg_line_length": 42.7647058824, "max_line_length": 104, "alphanum_fraction": 0.5949105915, "num_tokens": 2876, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321720225278, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.3700197995459541}} {"text": "-- Andreas, 2013-09-17 catches a bug in constraint solving\n-- with meta-variables applied to underapplied record constructors\n-- {-# OPTIONS --show-implicit -v tc.meta.assign:50 -v tc.conv.elim:30 #-}\nmodule Issue889 where\n\nrecord Monad (M : Set → Set) : Set₁ where\n field\n return : ∀ {A} → A → M A\n _>>=_ : ∀ {A} {B : M A → Set} (m : M A) →\n ((x : A) → M (B (return x))) → M (B m)\n\nrecord Σ (A : Set) (B : A → Set) : Set where\n constructor _,_\n field\n proj₁ : A\n proj₂ : B proj₁\n\n_×_ : (A B : Set) → Set\nA × B = Σ A λ _ → B\n\nState : Set → Set → Set\nState S X = S → X × S\n\n-- Here is the underapplied record constructor\n-- (made underapplied by eta-contraction, resp.).\nstate-return : ∀ {S X} → X → State S X\nstate-return x = _,_ x -- λ s → x , s\n\n-- When giving the @_>>=_@ function to the record goal we get:\n--\n-- An internal error has occurred. Please report this as a bug.\n-- Location of the error: src/full/Agda/TypeChecking/Conversion.hs:524\nstate-monad : ∀ {S} → Monad (State S)\nstate-monad {S} = record { return = state-return; _>>=_ = {!_>>=_!} }\n where\n postulate\n _>>=_ : ∀ {A} {B : State S A → Set} (m : State S A) →\n ((x : A) → State S (B (state-return x))) → State S (B m)\n-- Bug arises when checking\n-- _B (state-return x) = B (state-return x)\n-- _B (_,_ x) = B (_,_ x)\n-- then Agda does something special for record constructors\n-- [Miller unification in the presence of records]\n-- (now only done for FULLY APPLIED record constructors!)\n-- and produces some garbage solution for _B.\n\n------------------------------------------------------------------------\n\n-- Note that if we define the product type using data instead of\n-- record then it works:\n\ndata _×′_ (A B : Set) : Set where\n _,_ : A → B → A ×′ B\n\nState′ : Set → Set → Set\nState′ S X = S → X ×′ S\n\nstate-return′ : ∀ {S X} → X → State′ S X\nstate-return′ x = λ s → x , s\n\nstate-monad′ : ∀ {S} → Monad (State′ S)\nstate-monad′ {S} = record { return = state-return′; _>>=_ = _>>=_ }\n where\n postulate\n _>>=_ : ∀ {A} {B : State′ S A → Set} (m : State′ S A) →\n ((x : A) → State′ S (B (state-return′ x))) → State′ S (B m)\n", "meta": {"hexsha": "b4a0570aad1588caa992f606f222db637a129dc4", "size": 2160, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/interaction/Issue889.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/interaction/Issue889.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/interaction/Issue889.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 32.2388059701, "max_line_length": 74, "alphanum_fraction": 0.5662037037, "num_tokens": 704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6406358548398982, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.3699642369418917}} {"text": "------------------------------------------------------------------------\n-- Eliminators and initiality\n------------------------------------------------------------------------\n\n{-# OPTIONS --erased-cubical --safe #-}\n\nmodule Partiality-algebra.Eliminators where\n\nopen import Equality.Propositional.Cubical\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude hiding (T)\n\nopen import Bijection equality-with-J using (_↔_)\nimport Equivalence equality-with-J as Eq\nopen import Function-universe equality-with-J hiding (id; _∘_)\nopen import H-level equality-with-J\nopen import H-level.Closure equality-with-J\nopen import Surjection equality-with-J using (_↠_)\n\nopen import Partiality-algebra as PA hiding (id; _∘_)\n\n------------------------------------------------------------------------\n-- Eliminators\n\n-- I (NAD) have tried to follow the spirit of the rules for HITs\n-- specified in the HoTT-Agda library\n-- (https://github.com/HoTT/HoTT-Agda/blob/master/core/lib/types/HIT_README.txt).\n-- However, at the time of writing those rules don't apply to indexed\n-- types.\n\n-- A specification of a given partiality algebra's eliminator\n-- arguments (for given motive sizes).\n\nrecord Arguments {a p′ q′} {A : Type a} p q\n (PA : Partiality-algebra p′ q′ A) :\n Type (a ⊔ lsuc (p ⊔ q) ⊔ p′ ⊔ q′) where\n\n open Partiality-algebra PA\n\n -- Predicate transformer related to increasing sequences.\n\n Inc : (P : T → Type p)\n (Q : ∀ {x y} → P x → P y → x ⊑ y → Type q) →\n Increasing-sequence → Type (p ⊔ q)\n Inc P Q s =\n ∃ λ (p : ∀ n → P (s [ n ])) →\n ∀ n → Q (p n) (p (suc n)) (increasing s n)\n\n field\n P : T → Type p\n Q : ∀ {x y} → P x → P y → x ⊑ y → Type q\n pe : P never\n po : ∀ x → P (now x)\n pl : ∀ s (pq : Inc P Q s) → P (⨆ s)\n pa : ∀ {x y} (x⊑y : x ⊑ y) (x⊒y : x ⊒ y)\n (p-x : P x) (p-y : P y)\n (q-x⊑y : Q p-x p-y x⊑y) (q-x⊒y : Q p-y p-x x⊒y) →\n subst P (antisymmetry x⊑y x⊒y) p-x ≡ p-y\n pp : ∀ {x} → Is-set (P x)\n qr : ∀ x (p : P x) → Q p p (⊑-refl x)\n qt : ∀ {x y z} (x⊑y : x ⊑ y) (y⊑z : y ⊑ z) →\n (px : P x) (py : P y) (pz : P z) →\n Q px py x⊑y → Q py pz y⊑z → Q px pz (⊑-trans x⊑y y⊑z)\n qe : ∀ x (p : P x) → Q pe p (never⊑ x)\n qu : ∀ s (pq : Inc P Q s) n →\n Q (proj₁ pq n) (pl s pq) (upper-bound s n)\n ql : ∀ s ub is-ub (pq : Inc P Q s) (pu : P ub)\n (qu : ∀ n → Q (proj₁ pq n) pu (is-ub n)) →\n Q (pl s pq) pu (least-upper-bound s ub is-ub)\n qp : ∀ {x y} (p-x : P x) (p-y : P y) (x⊑y : x ⊑ y) →\n Is-proposition (Q p-x p-y x⊑y)\n\n-- A specification of a given partiality algebra's eliminators.\n\nrecord Eliminators {a p q p′ q′} {A : Type a}\n {PA : Partiality-algebra p′ q′ A}\n (args : Arguments p q PA) :\n Type (a ⊔ p ⊔ q ⊔ p′ ⊔ q′) where\n open Partiality-algebra PA\n open Arguments args\n\n field\n ⊥-rec : (x : T) → P x\n ⊑-rec : ∀ {x y} (x⊑y : x ⊑ y) → Q (⊥-rec x) (⊥-rec y) x⊑y\n\n inc-rec : (s : Increasing-sequence) → Inc P Q s\n inc-rec = λ { (s , inc) → ( (λ n → ⊥-rec (s n))\n , (λ n → ⊑-rec (inc n))\n ) }\n\n field\n\n -- Some \"computation\" rules.\n\n ⊥-rec-never : ⊥-rec never ≡ pe\n ⊥-rec-now : ∀ x → ⊥-rec (now x) ≡ po x\n ⊥-rec-⨆ : ∀ s → ⊥-rec (⨆ s) ≡ pl s (inc-rec s)\n\n-- A specification of the elimination principle for a given partiality\n-- algebra (for motives of certain sizes).\n\nElimination-principle :\n ∀ {a p′ q′} {A : Type a} →\n ∀ p q → Partiality-algebra p′ q′ A → Type (a ⊔ lsuc (p ⊔ q) ⊔ p′ ⊔ q′)\nElimination-principle p q P =\n (args : Arguments p q P) → Eliminators args\n\n------------------------------------------------------------------------\n-- Initiality\n\n-- The statement that a given partiality algebra is homotopy-initial.\n\nInitial : ∀ {a p q} p′ q′ {A : Type a} → Partiality-algebra p q A →\n Type (a ⊔ p ⊔ q ⊔ lsuc (p′ ⊔ q′))\nInitial p′ q′ {A} P =\n (P′ : Partiality-algebra p′ q′ A) → Contractible (Morphism P P′)\n\n-- If a partiality algebra is initial at certain sizes, then it is\n-- also initial at smaller sizes.\n\nlower-initiality :\n ∀ {a p q p₁ q₁} p₂ q₂ {A : Type a}\n (P : Partiality-algebra p q A)\n (initial : Initial (p₁ ⊔ p₂) (q₁ ⊔ q₂) P) →\n Initial p₁ q₁ P\nlower-initiality {p₁ = p₁} {q₁} p₂ q₂ {A} P initial P′ =\n Σ-map lower-morphism lemma (initial P″)\n where\n open Partiality-algebra P′\n\n P″ : Partiality-algebra (p₁ ⊔ p₂) (q₁ ⊔ q₂) A\n P″ = record\n { T = ↑ p₂ T\n ; partiality-algebra-with = record\n { _⊑_ = λ x y → ↑ q₂ (lower x ⊑ lower y)\n ; never = lift never\n ; now = lift ∘ now\n ; ⨆ = lift ∘ ⨆ ∘ Σ-map (lower ∘_) (lower ∘_)\n ; antisymmetry = λ x⊑y y⊑x →\n cong lift (antisymmetry (lower x⊑y)\n (lower y⊑x))\n ; T-is-set-unused = λ _ _ → ↑-closure 2 T-is-set _ _\n ; ⊑-refl = lift ∘ ⊑-refl ∘ lower\n ; ⊑-trans = λ x⊑y y⊑z →\n lift (⊑-trans (lower x⊑y)\n (lower y⊑z))\n ; never⊑ = lift ∘ never⊑ ∘ lower\n ; upper-bound = λ _ → lift ∘ upper-bound _\n ; least-upper-bound = λ _ _ →\n lift ∘\n least-upper-bound _ _ ∘\n (lower ∘_)\n ; ⊑-propositional = ↑-closure 1 ⊑-propositional\n }\n }\n\n lower-morphism : Morphism P P″ → Morphism P P′\n lower-morphism m = record\n { function = lower ∘ function\n ; monotone = lower ∘ monotone\n ; strict = cong lower strict\n ; now-to-now = cong lower ∘ now-to-now\n ; ω-continuous = cong lower ∘ ω-continuous\n }\n where\n open Morphism m\n\n lift-morphism : Morphism P P′ → Morphism P P″\n lift-morphism m = record\n { function = lift ∘ function\n ; monotone = lift ∘ monotone\n ; strict = cong lift strict\n ; now-to-now = cong lift ∘ now-to-now\n ; ω-continuous = cong lift ∘ ω-continuous\n }\n where\n open Morphism m\n\n lemma : {m : Morphism P P″} →\n (∀ m′ → m ≡ m′) →\n (∀ m′ → lower-morphism m ≡ m′)\n lemma {m} hyp m′ = _↔_.to equality-characterisation-Morphism\n (lower ∘ Morphism.function m ≡⟨ cong ((lower ∘_) ∘ Morphism.function) (hyp (lift-morphism m′)) ⟩∎\n Morphism.function m′ ∎)\n\n------------------------------------------------------------------------\n-- Specifying the partiality monad using eliminators is logically\n-- equivalent (at the meta-level) to specifying it using initiality\n\n-- Any partiality algebra with eliminators (at certain sizes) is\n-- initial (at the same sizes).\n\neliminators→initiality :\n ∀ {a p q p′ q′} {A : Type a} →\n (P : Partiality-algebra p′ q′ A) →\n Elimination-principle p q P →\n Initial p q P\neliminators→initiality {p = p} {q} P elims P′ = morphism , unique\n where\n module P = Partiality-algebra P\n module P′ = Partiality-algebra P′\n\n args : Arguments p q P\n args = record\n { P = λ _ → P′.T\n ; Q = λ x y _ → x P′.⊑ y\n ; pe = P′.never\n ; po = P′.now\n ; pl = λ _ → P′.⨆\n ; pa = λ x⊑y y⊑x u v u⊑v v⊑u →\n let eq = Partiality-algebra.antisymmetry P x⊑y y⊑x in\n\n subst (const P′.T) eq u ≡⟨ subst-const eq ⟩\n u ≡⟨ P′.antisymmetry u⊑v v⊑u ⟩∎\n v ∎\n ; pp = P′.T-is-set\n ; qr = λ _ → P′.⊑-refl\n ; qt = λ _ _ _ _ _ → P′.⊑-trans\n ; qe = λ _ → P′.never⊑\n ; qu = λ _ → P′.upper-bound\n ; ql = λ _ _ _ → P′.least-upper-bound\n ; qp = λ _ _ _ → P′.⊑-propositional\n }\n\n module E = Eliminators (elims args)\n\n morphism : Morphism P P′\n morphism = record\n { function = E.⊥-rec\n ; monotone = E.⊑-rec\n ; strict = E.⊥-rec-never\n ; now-to-now = E.⊥-rec-now\n ; ω-continuous = E.⊥-rec-⨆\n }\n\n open Morphism\n\n function-unique : (f : Morphism P P′) →\n E.⊥-rec ≡ function f\n function-unique f = sym $ ⟨ext⟩ $ Eliminators.⊥-rec (elims (record\n { Q = λ _ _ _ → ↑ _ ⊤\n ; pe = function f P.never ≡⟨ strict f ⟩\n P′.never ≡⟨ sym $ E.⊥-rec-never ⟩∎\n E.⊥-rec P.never ∎\n ; po = λ x →\n function f (P.now x) ≡⟨ now-to-now f x ⟩\n P′.now x ≡⟨ sym $ E.⊥-rec-now x ⟩∎\n E.⊥-rec (P.now x) ∎\n ; pl = λ s hyp →\n function f (P.⨆ s) ≡⟨ ω-continuous f s ⟩\n P′.⨆ (sequence-function f s) ≡⟨ cong P′.⨆ $ _↔_.to P′.equality-characterisation-increasing (proj₁ hyp) ⟩\n P′.⨆ (E.inc-rec s) ≡⟨ sym $ E.⊥-rec-⨆ s ⟩\n E.⊥-rec (P.⨆ s) ∎\n ; pa = λ _ _ _ _ _ _ → P′.T-is-set _ _\n ; pp = λ _ _ → mono₁ 1 P′.T-is-set _ _\n ; qp = λ _ _ _ _ _ → refl\n }))\n\n unique : ∀ f → morphism ≡ f\n unique f =\n _↔_.to equality-characterisation-Morphism (function-unique f)\n\n-- Any partiality algebra with initiality (at certain sufficiently\n-- large sizes) has eliminators (at certain sizes).\n\ninitiality→eliminators :\n ∀ {a p q p′ q′} {A : Type a} {P : Partiality-algebra p′ q′ A}\n (initial : Initial (p ⊔ p′) (q ⊔ q′) P) →\n Elimination-principle p q P\ninitiality→eliminators {p = p} {q} {p′} {q′} {A} {PA} initial args =\n record\n { ⊥-rec = ⊥-rec\n ; ⊑-rec = ⊑-rec\n ; ⊥-rec-never = ⊥-rec-never\n ; ⊥-rec-now = ⊥-rec-now\n ; ⊥-rec-⨆ = ⊥-rec-⨆\n }\n where\n open Partiality-algebra PA\n\n open Arguments args\n\n private\n\n -- A partiality algebra with ∃ P as the carrier type.\n\n ∃PA : Partiality-algebra (p ⊔ p′) (q ⊔ q′) A\n ∃PA = record\n { T = ∃ P\n ; partiality-algebra-with = record\n { _⊑_ = λ { (_ , p) (_ , q) → ∃ (Q p q) }\n ; never = never , pe\n ; now = λ x → now x , po x\n ; ⨆ = λ s → ⨆ (Σ-map (proj₁ ∘_) (proj₁ ∘_) s)\n , pl _ ( proj₂ ∘ proj₁ s\n , proj₂ ∘ proj₂ s\n )\n ; antisymmetry = λ { {x = (x , p)} {y = (y , q)}\n (x⊑y , Qx⊑y) (y⊑x , Qy⊑x) →\n Σ-≡,≡→≡\n (antisymmetry x⊑y y⊑x)\n (pa x⊑y y⊑x p q Qx⊑y Qy⊑x)\n }\n ; T-is-set-unused = Σ-closure 2 T-is-set (λ _ → pp)\n ; ⊑-refl = λ _ → _ , qr _ _\n ; ⊑-trans = Σ-zip ⊑-trans (qt _ _ _ _ _)\n ; never⊑ = λ _ → _ , qe _ _\n ; upper-bound = λ _ _ → upper-bound _ _ , qu _ _ _\n ; least-upper-bound = λ _ _ ⊑qs →\n least-upper-bound _ _ (proj₁ ∘ ⊑qs)\n , ql _ _ _ _ _ (proj₂ ∘ ⊑qs)\n ; ⊑-propositional = Σ-closure 1 ⊑-propositional λ _ → qp _ _ _\n }\n }\n\n -- Initiality gives us a morphism from PA to ∃PA.\n\n eliminator-morphism : Morphism PA ∃PA\n eliminator-morphism = proj₁ (initial ∃PA)\n\n open Morphism eliminator-morphism\n\n -- We can construct a morphism from ∃PA to PA directly.\n\n proj₁-morphism : Morphism ∃PA PA\n proj₁-morphism = record\n { function = proj₁\n ; monotone = proj₁\n ; strict = refl\n ; now-to-now = λ _ → refl\n ; ω-continuous = λ _ → refl\n }\n\n -- By composing the two morphisms we get an endomorphism on PA.\n\n id′ : Morphism PA PA\n id′ = proj₁-morphism PA.∘ eliminator-morphism\n\n -- Due to initiality this morphism must be equal to id.\n\n id′≡id : id′ ≡ PA.id\n id′≡id =\n let m , unique = lower-initiality p q PA initial PA in\n\n id′ ≡⟨ sym $ unique id′ ⟩\n m ≡⟨ unique PA.id ⟩∎\n PA.id ∎\n\n abstract\n\n -- This provides us with a key lemma used to define the\n -- eliminators.\n\n lemma : ∀ x → proj₁ (function x) ≡ x\n lemma x = cong (λ m → Morphism.function m x) id′≡id\n\n -- As an aside this means that there is a split surjection from\n -- ∃ P to T.\n\n ↠T : ∃ P ↠ T\n ↠T = record\n { logical-equivalence = record\n { to = Morphism.function proj₁-morphism\n ; from = function\n }\n ; right-inverse-of = lemma\n }\n\n -- The eliminators.\n\n ⊥-rec : ∀ x → P x\n ⊥-rec x = $⟨ proj₂ (function x) ⟩\n P (proj₁ (function x)) ↝⟨ subst P (lemma x) ⟩□\n P x □\n\n ⊑-rec : ∀ {x y} (x⊑y : x ⊑ y) → Q (⊥-rec x) (⊥-rec y) x⊑y\n ⊑-rec {x} {y} x⊑y = $⟨ proj₂ (monotone x⊑y) ⟩\n Q (proj₂ (function x)) (proj₂ (function y)) (proj₁ (monotone x⊑y)) ↝⟨ subst Q′ $\n Σ-≡,≡→≡ (cong₂ _,_ (lemma x) (lemma y)) (\n subst (λ xy → P (proj₁ xy) × P (proj₂ xy) ×\n proj₁ xy ⊑ proj₂ xy)\n (cong₂ _,_ (lemma x) (lemma y))\n ( proj₂ (function x)\n , proj₂ (function y)\n , proj₁ (monotone x⊑y)\n ) ≡⟨ push-subst-, {y≡z = cong₂ _,_ (lemma x) (lemma y)}\n (λ xy → P (proj₁ xy))\n (λ xy → P (proj₂ xy) × proj₁ xy ⊑ proj₂ xy)\n {p = ( proj₂ (function x)\n , proj₂ (function y)\n , proj₁ (monotone x⊑y)\n )} ⟩\n ( subst (λ xy → P (proj₁ xy))\n (cong₂ _,_ (lemma x) (lemma y))\n (proj₂ (function x))\n , subst (λ xy → P (proj₂ xy) × proj₁ xy ⊑ proj₂ xy)\n (cong₂ _,_ (lemma x) (lemma y))\n ( proj₂ (function y)\n , proj₁ (monotone x⊑y)\n )\n ) ≡⟨ cong₂ _,_\n (subst-∘ P proj₁ (cong₂ _,_ (lemma x) (lemma y))\n {p = proj₂ (function x)})\n (push-subst-, {y≡z = cong₂ _,_ (lemma x) (lemma y)}\n (λ xy → P (proj₂ xy))\n (λ xy → proj₁ xy ⊑ proj₂ xy)\n {p = ( proj₂ (function y)\n , proj₁ (monotone x⊑y)\n )}) ⟩\n ( subst P (cong proj₁ $ cong₂ _,_ (lemma x) (lemma y))\n (proj₂ (function x))\n , subst (λ xy → P (proj₂ xy))\n (cong₂ _,_ (lemma x) (lemma y))\n (proj₂ (function y))\n , subst (λ xy → proj₁ xy ⊑ proj₂ xy)\n (cong₂ _,_ (lemma x) (lemma y))\n (proj₁ (monotone x⊑y))\n ) ≡⟨ cong₂ _,_\n (cong (λ p → subst P p (proj₂ (function x))) $\n cong-proj₁-cong₂-, (lemma x) (lemma y))\n (cong₂ _,_\n (subst-∘ P proj₂ (cong₂ _,_ (lemma x) (lemma y))\n {p = proj₂ (function y)})\n (⊑-propositional _ _)) ⟩\n ( subst P (lemma x) (proj₂ (function x))\n , subst P (cong proj₂ $ cong₂ _,_ (lemma x) (lemma y))\n (proj₂ (function y))\n , x⊑y\n ) ≡⟨ cong (λ p → ⊥-rec x , subst P p (proj₂ (function y)) , x⊑y) $\n cong-proj₂-cong₂-, (lemma x) (lemma y) ⟩∎\n (⊥-rec x , ⊥-rec y , x⊑y) ∎) ⟩□\n\n Q (⊥-rec x) (⊥-rec y) x⊑y □\n where\n Q′ :\n (∃ λ xy → P (proj₁ xy) × P (proj₂ xy) × proj₁ xy ⊑ proj₂ xy) →\n Type q\n Q′ (_ , px , py , x⊑y) = Q px py x⊑y\n\n inc-rec : ∀ s → Inc P Q s\n inc-rec (s , inc) = ⊥-rec ∘ s , ⊑-rec ∘ inc\n\n -- \"Computation\" rules.\n\n private\n\n -- A lemma.\n\n ⊥-rec-lemma′ :\n ∀ {a b} {A : Type a} {B : A → Type b} {x y : Σ A B} →\n Is-set A →\n x ≡ y → (p : proj₁ x ≡ proj₁ y) →\n subst B p (proj₂ x) ≡ proj₂ y\n ⊥-rec-lemma′ {B = B} A-set =\n elim (λ {x y} _ → (p : proj₁ x ≡ proj₁ y) →\n subst B p (proj₂ x) ≡ proj₂ y)\n (λ { (_ , x₂) p →\n subst B p x₂ ≡⟨ cong (λ p → subst B p _) $ A-set p refl ⟩\n subst B refl x₂ ≡⟨⟩\n x₂ ∎\n })\n\n -- A specific instance of the lemma above.\n\n ⊥-rec-lemma : ∀ {x y} → function x ≡ (x , y) → ⊥-rec x ≡ y\n ⊥-rec-lemma {x} {y} eq =\n ⊥-rec x ≡⟨⟩\n subst P (lemma x) (proj₂ (function x)) ≡⟨ ⊥-rec-lemma′ T-is-set eq (lemma x) ⟩∎\n y ∎\n\n ⊥-rec-never : ⊥-rec never ≡ pe\n ⊥-rec-never = ⊥-rec-lemma strict\n\n ⊥-rec-now : ∀ x → ⊥-rec (now x) ≡ po x\n ⊥-rec-now x = ⊥-rec-lemma (now-to-now x)\n\n ⊥-rec-⨆ : ∀ s → ⊥-rec (⨆ s) ≡ pl s (inc-rec s)\n ⊥-rec-⨆ s = ⊥-rec-lemma\n (function (⨆ s) ≡⟨ ω-continuous s ⟩\n\n ⨆ (Σ-map (proj₁ ∘_) (proj₁ ∘_) (sequence-function s)) ,\n pl _ ( proj₂ ∘ proj₁ (sequence-function s)\n , proj₂ ∘ proj₂ (sequence-function s)\n ) ≡⟨⟩\n\n ⨆ ( proj₁ ∘ function ∘ proj₁ s\n , proj₁ ∘ monotone ∘ proj₂ s\n ) ,\n pl _ ( proj₂ ∘ function ∘ proj₁ s\n , proj₂ ∘ monotone ∘ proj₂ s\n ) ≡⟨ Σ-≡,≡→≡ (cong ⨆ lemma₁) lemma₂ ⟩\n\n ⨆ s , pl s ( ⊥-rec ∘ proj₁ s\n , ⊑-rec ∘ proj₂ s\n ) ≡⟨⟩\n\n ⨆ s , pl s (inc-rec s) ∎)\n where\n lemma₁ =\n ( proj₁ ∘ function ∘ proj₁ s\n , proj₁ ∘ monotone ∘ proj₂ s\n ) ≡⟨ _↔_.to equality-characterisation-increasing (λ n →\n lemma (s [ n ])) ⟩∎\n s ∎\n\n lemma₂ =\n subst P (cong ⨆ lemma₁)\n (pl _ ( proj₂ ∘ function ∘ proj₁ s\n , proj₂ ∘ monotone ∘ proj₂ s\n )) ≡⟨ sym $ subst-∘ P ⨆ lemma₁ ⟩\n\n subst (P ∘ ⨆) lemma₁\n (pl _ ( proj₂ ∘ function ∘ proj₁ s\n , proj₂ ∘ monotone ∘ proj₂ s\n )) ≡⟨ elim\n (λ {s′ s} eq → ∀ {i′ i} →\n subst (λ s → ∀ n → P (s [ n ])) eq (proj₁ i′) ≡ proj₁ i →\n subst (P ∘ ⨆) eq (pl s′ i′) ≡ pl s i)\n (λ s {i′ i} eq →\n pl s i′ ≡⟨ cong (pl s) (Σ-≡,≡→≡ eq (⟨ext⟩ λ _ → qp _ _ _ _ _)) ⟩∎\n pl s i ∎)\n lemma₁\n (⟨ext⟩ λ n →\n let lemma₃ =\n cong _[ n ] lemma₁ ≡⟨ sym $ cong-∘ (_$ n) proj₁ lemma₁ ⟩\n cong (_$ n) (cong proj₁ lemma₁) ≡⟨ cong (cong (_$ n)) $ proj₁-Σ-≡,≡→≡ (⟨ext⟩ (lemma ∘ proj₁ s)) _ ⟩\n cong (_$ n) (⟨ext⟩ (lemma ∘ proj₁ s)) ≡⟨ cong-ext (lemma ∘ proj₁ s) ⟩∎\n lemma (s [ n ]) ∎\n in\n subst (λ s → ∀ n → P (s [ n ])) lemma₁\n (proj₂ ∘ function ∘ proj₁ s) n ≡⟨ sym $ push-subst-application lemma₁ (λ s n → P (s [ n ])) ⟩\n\n subst (λ s → P (s [ n ])) lemma₁\n (proj₂ (function (s [ n ]))) ≡⟨ subst-∘ P _[ n ] lemma₁ ⟩\n\n subst P (cong _[ n ] lemma₁)\n (proj₂ (function (s [ n ]))) ≡⟨ cong (λ eq → subst P eq (proj₂ (function (s [ n ])))) lemma₃ ⟩∎\n\n subst P (lemma (s [ n ]))\n (proj₂ (function (s [ n ]))) ∎) ⟩\n\n pl s ( (λ n → subst P (lemma (s [ n ]))\n (proj₂ (function (s [ n ]))))\n , ⊑-rec ∘ proj₂ s\n ) ≡⟨⟩\n\n pl s ( ⊥-rec ∘ proj₁ s\n , ⊑-rec ∘ proj₂ s\n ) ∎\n\n-- For any partiality algebra (with certain levels) initiality (at\n-- possibly larger levels) is logically equivalent to having\n-- eliminators (at the same possibly larger levels).\n\ninitiality⇔eliminators :\n ∀ {a p q p′ q′} {A : Type a} →\n (P : Partiality-algebra p′ q′ A) →\n Initial (p ⊔ p′) (q ⊔ q′) P\n ⇔\n Elimination-principle (p ⊔ p′) (q ⊔ q′) P\ninitiality⇔eliminators P = record\n { to = initiality→eliminators\n ; from = eliminators→initiality P\n }\n\n-- For any partiality algebra initiality at all levels is logically\n-- equivalent (at the meta-level) to having eliminators at all levels.\n\n∀initiality→∀eliminators :\n ∀ {a p q} {A : Type a} →\n (P : Partiality-algebra p q A) →\n (∀ p q → Initial p q P) →\n (∀ p q → Elimination-principle p q P)\n∀initiality→∀eliminators {p = p′} {q = q′} P initial p q =\n initiality→eliminators (initial (p ⊔ p′) (q ⊔ q′))\n\n∀eliminators→∀initiality :\n ∀ {a p q} {A : Type a} →\n (P : Partiality-algebra p q A) →\n (∀ p q → Elimination-principle p q P) →\n (∀ p q → Initial p q P)\n∀eliminators→∀initiality P elim p q =\n eliminators→initiality P (elim p q)\n", "meta": {"hexsha": "08f4518753f062f00f390b8c59e80df3f0952087", "size": 23348, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Partiality-algebra/Eliminators.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/Partiality-algebra/Eliminators.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/Partiality-algebra/Eliminators.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": 39.9794520548, "max_line_length": 144, "alphanum_fraction": 0.39729313, "num_tokens": 7327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.3699642369418916}} {"text": "{-# OPTIONS -v tc.unquote:30 #-}\nopen import Common.Prelude\nopen import Common.Reflection\nopen import Agda.Builtin.Sigma\n\ndata Box : Bool → Set where\n box : (b : Bool) → Box b\n\nworks : (b : Bool) → Box b → Bool\nworks b (box .b) = unquote (give (var 0 []))\n\nworks₂ : (b : Bool) → Box b → Bool\nunquoteDef works₂ = defineFun works₂ (clause\n ( (\"b\" , arg (argInfo visible relevant) unknown) ∷ [])\n ( arg (argInfo visible relevant) (var 0)\n ∷ arg (argInfo visible relevant) (con (quote box)\n (arg (argInfo visible relevant) (dot unknown) ∷ []))\n ∷ [])\n (var 0 []) ∷ [])\n\nworks₃ : (b : Bool) → Box b → (x y : Bool) → Bool\nunquoteDef works₃ = defineFun works₃ (clause\n ( (\"y\" , arg (argInfo visible relevant) unknown)\n ∷ (\"x\" , arg (argInfo visible relevant) unknown)\n ∷ (\"b\" , arg (argInfo visible relevant) unknown)\n ∷ [])\n ( arg (argInfo visible relevant) (var 2)\n ∷ arg (argInfo visible relevant) (con (quote box)\n (arg (argInfo visible relevant) (dot unknown) ∷ []))\n ∷ arg (argInfo visible relevant) (var 1)\n ∷ arg (argInfo visible relevant) (var 0)\n ∷ [])\n (var 2 []) ∷ [])\n", "meta": {"hexsha": "4edf2deeace410c7209de474d29bc0e248b886bc", "size": 1104, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1344.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/Succeed/Issue1344.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/Succeed/Issue1344.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": 32.4705882353, "max_line_length": 60, "alphanum_fraction": 0.6195652174, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6406358411176238, "lm_q2_score": 0.5774953651858117, "lm_q1q2_score": 0.36996422901734183}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import Base\nopen import Homotopy.Pushout\nopen import Homotopy.VanKampen.Guide\n\n{-\n This module provides the function code⇒path\n for the homotopy equivalence for\n van Kampen theorem.\n-}\n\nmodule Homotopy.VanKampen.CodeToPath {i} (d : pushout-diag i)\n (l : legend i (pushout-diag.C d)) where\n\n open pushout-diag d\n open legend l\n\n open import Homotopy.Truncation\n open import Homotopy.PathTruncation\n open import Homotopy.VanKampen.Code d l\n\n private\n pgl : ∀ n → _≡₀_ {A = P} (left (f $ loc n)) (right (g $ loc n))\n pgl n = proj (glue $ loc n)\n\n p!gl : ∀ n → _≡₀_ {A = P} (right (g $ loc n)) (left (f $ loc n))\n p!gl n = proj (! (glue $ loc n))\n\n ap₀l : ∀ {a₁ a₂} → a₁ ≡₀ a₂ → _≡₀_ {A = P} (left a₁) (left a₂)\n ap₀l p = ap₀ left p\n\n ap₀r : ∀ {b₁ b₂} → b₁ ≡₀ b₂ → _≡₀_ {A = P} (right b₁) (right b₂)\n ap₀r p = ap₀ right p\n\n module _ {a₁ : A} where\n private\n ap⇒path-split : (∀ {a₂} → a-code-a a₁ a₂ → _≡₀_ {A = P} (left a₁) (left a₂))\n × (∀ {b₂} → a-code-b a₁ b₂ → _≡₀_ {A = P} (left a₁) (right b₂))\n ap⇒path-split = a-code-rec-nondep a₁\n (λ a₂ → left a₁ ≡₀ left a₂)\n ⦃ λ a₂ → π₀-is-set _ ⦄\n (λ b₂ → left a₁ ≡₀ right b₂)\n ⦃ λ b₂ → π₀-is-set _ ⦄\n (λ p → ap₀l p)\n (λ n pco p → (pco ∘₀ p!gl n) ∘₀ ap₀l p)\n (λ n pco p → (pco ∘₀ pgl n) ∘₀ ap₀r p)\n (λ n {co} pco →\n (((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n) ∘₀ refl₀\n ≡⟨ refl₀-right-unit _ ⟩\n ((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n\n ≡⟨ ap (λ x → x ∘₀ p!gl n)\n $ refl₀-right-unit $ pco ∘₀ pgl n ⟩\n (pco ∘₀ pgl n) ∘₀ p!gl n\n ≡⟨ concat₀-assoc pco (pgl n) (p!gl n) ⟩\n pco ∘₀ (pgl n ∘₀ p!gl n)\n ≡⟨ ap (λ x → pco ∘₀ proj x)\n $ opposite-right-inverse $ glue $ loc n ⟩\n pco ∘₀ refl₀\n ≡⟨ refl₀-right-unit pco ⟩∎\n pco\n ∎)\n (λ n {co} pco →\n (((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n) ∘₀ refl₀\n ≡⟨ refl₀-right-unit _ ⟩\n ((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n\n ≡⟨ ap (λ x → x ∘₀ pgl n)\n $ refl₀-right-unit $ pco ∘₀ p!gl n ⟩\n (pco ∘₀ p!gl n) ∘₀ pgl n\n ≡⟨ concat₀-assoc pco (p!gl n) (pgl n) ⟩\n pco ∘₀ (p!gl n ∘₀ pgl n)\n ≡⟨ ap (λ x → pco ∘₀ proj x)\n $ opposite-left-inverse $ glue $ loc n ⟩\n pco ∘₀ refl₀\n ≡⟨ refl₀-right-unit pco ⟩∎\n pco\n ∎)\n (λ n₁ {co} pco n₂ r →\n (((pco ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)) ∘₀ p!gl n₂) ∘₀ refl₀\n ≡⟨ refl₀-right-unit _ ⟩\n ((pco ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)) ∘₀ p!gl n₂\n ≡⟨ concat₀-assoc (pco ∘₀ pgl n₁) (ap₀r (ap₀ g r)) (p!gl n₂) ⟩\n (pco ∘₀ pgl n₁) ∘₀ (ap₀r (ap₀ g r) ∘₀ p!gl n₂)\n ≡⟨ ap (λ x → (pco ∘₀ pgl n₁) ∘₀ (x ∘₀ p!gl n₂)) $ ! $ ap₀-compose right g r ⟩\n (pco ∘₀ pgl n₁) ∘₀ (ap₀ (right ◯ g) r ∘₀ p!gl n₂)\n ≡⟨ ap (λ x → (pco ∘₀ pgl n₁) ∘₀ x)\n $ homotopy₀-naturality (right ◯ g) (left ◯ f) (proj ◯ (! ◯ glue)) r ⟩\n (pco ∘₀ pgl n₁) ∘₀ (p!gl n₁ ∘₀ ap₀ (left ◯ f) r)\n ≡⟨ ! $ concat₀-assoc (pco ∘₀ pgl n₁) (p!gl n₁) (ap₀ (left ◯ f) r) ⟩\n ((pco ∘₀ pgl n₁) ∘₀ p!gl n₁) ∘₀ ap₀ (left ◯ f) r\n ≡⟨ ap (λ x → ((pco ∘₀ pgl n₁) ∘₀ p!gl n₁) ∘₀ x) $ ap₀-compose left f r ⟩\n ((pco ∘₀ pgl n₁) ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)\n ≡⟨ ap (λ x → (x ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r))\n $ ! $ refl₀-right-unit $ pco ∘₀ pgl n₁ ⟩∎\n (((pco ∘₀ pgl n₁) ∘₀ refl₀) ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)\n ∎)\n\n aa⇒path : ∀ {a₂} → a-code-a a₁ a₂ → _≡₀_ {A = P} (left a₁) (left a₂)\n aa⇒path = π₁ ap⇒path-split\n ab⇒path : ∀ {b₂} → a-code-b a₁ b₂ → _≡₀_ {A = P} (left a₁) (right b₂)\n ab⇒path = π₂ ap⇒path-split\n\n ap⇒path : ∀ {p₂ : P} → a-code a₁ p₂ → left a₁ ≡₀ p₂\n ap⇒path {p₂} = pushout-rec\n (λ p → a-code a₁ p → left a₁ ≡₀ p)\n (λ a → aa⇒path {a})\n (λ b → ab⇒path {b})\n (loc-fiber-rec l\n (λ c → transport (λ p → a-code a₁ p → left a₁ ≡₀ p) (glue c) aa⇒path\n ≡ ab⇒path)\n ⦃ λ c → →-is-set (π₀-is-set (left a₁ ≡ right (g c))) _ _ ⦄\n (λ n → funext λ co →\n transport (λ p → a-code a₁ p → left a₁ ≡₀ p) (glue $ loc n) aa⇒path co\n ≡⟨ trans-→ (a-code a₁) (λ x → left a₁ ≡₀ x) (glue $ loc n) aa⇒path co ⟩\n transport (λ p → left a₁ ≡₀ p) (glue $ loc n) (aa⇒path $ transport (a-code a₁) (! (glue $ loc n)) co)\n ≡⟨ ap (transport (λ p → left a₁ ≡₀ p) (glue $ loc n) ◯ aa⇒path) $ trans-a-code-!glue-loc n co ⟩\n transport (λ p → left a₁ ≡₀ p) (glue $ loc n) (aa⇒path $ ab⇒aa n co)\n ≡⟨ trans-cst≡₀id (glue $ loc n) (aa⇒path $ ab⇒aa n co) ⟩\n (aa⇒path $ ab⇒aa n co) ∘₀ pgl n\n ≡⟨ refl ⟩\n ((ab⇒path co ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n\n ≡⟨ ap (λ x → x ∘₀ pgl n) $ refl₀-right-unit $ ab⇒path co ∘₀ p!gl n ⟩\n (ab⇒path co ∘₀ p!gl n) ∘₀ pgl n\n ≡⟨ concat₀-assoc (ab⇒path co) (p!gl n) (pgl n) ⟩\n ab⇒path co ∘₀ (p!gl n ∘₀ pgl n)\n ≡⟨ ap (λ x → ab⇒path co ∘₀ proj x) $ opposite-left-inverse $ glue $ loc n ⟩\n ab⇒path co ∘₀ refl₀\n ≡⟨ refl₀-right-unit $ ab⇒path co ⟩∎\n ab⇒path co\n ∎))\n p₂\n\n -- FIXME\n -- There is tension between reducing duplicate code and\n -- maintaining definitional equality. I could not make\n -- the neccessary type conversion definitional, so\n -- I just copied and pasted the previous module.\n module _ {b₁ : B} where\n private\n bp⇒path-split : (∀ {b₂} → b-code-b b₁ b₂ → _≡₀_ {A = P} (right b₁) (right b₂))\n × (∀ {a₂} → b-code-a b₁ a₂ → _≡₀_ {A = P} (right b₁) (left a₂))\n bp⇒path-split = b-code-rec-nondep b₁\n (λ b₂ → right b₁ ≡₀ right b₂)\n ⦃ λ b₂ → π₀-is-set _ ⦄\n (λ a₂ → right b₁ ≡₀ left a₂)\n ⦃ λ a₂ → π₀-is-set _ ⦄\n (λ p → ap₀r p)\n (λ n pco p → (pco ∘₀ pgl n) ∘₀ ap₀r p)\n (λ n pco p → (pco ∘₀ p!gl n) ∘₀ ap₀l p)\n (λ n {co} pco →\n (((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n) ∘₀ refl₀\n ≡⟨ refl₀-right-unit _ ⟩\n ((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n\n ≡⟨ ap (λ x → x ∘₀ pgl n)\n $ refl₀-right-unit $ pco ∘₀ p!gl n ⟩\n (pco ∘₀ p!gl n) ∘₀ pgl n\n ≡⟨ concat₀-assoc pco (p!gl n) (pgl n) ⟩\n pco ∘₀ (p!gl n ∘₀ pgl n)\n ≡⟨ ap (λ x → pco ∘₀ proj x)\n $ opposite-left-inverse $ glue $ loc n ⟩\n pco ∘₀ refl₀\n ≡⟨ refl₀-right-unit pco ⟩∎\n pco\n ∎)\n (λ n {co} pco →\n (((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n) ∘₀ refl₀\n ≡⟨ refl₀-right-unit _ ⟩\n ((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n\n ≡⟨ ap (λ x → x ∘₀ p!gl n)\n $ refl₀-right-unit $ pco ∘₀ pgl n ⟩\n (pco ∘₀ pgl n) ∘₀ p!gl n\n ≡⟨ concat₀-assoc pco (pgl n) (p!gl n) ⟩\n pco ∘₀ (pgl n ∘₀ p!gl n)\n ≡⟨ ap (λ x → pco ∘₀ proj x)\n $ opposite-right-inverse $ glue $ loc n ⟩\n pco ∘₀ refl₀\n ≡⟨ refl₀-right-unit pco ⟩∎\n pco\n ∎)\n (λ n₁ {co} pco n₂ r →\n (((pco ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)) ∘₀ pgl n₂) ∘₀ refl₀\n ≡⟨ refl₀-right-unit _ ⟩\n ((pco ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)) ∘₀ pgl n₂\n ≡⟨ concat₀-assoc (pco ∘₀ p!gl n₁) (ap₀l (ap₀ f r)) (pgl n₂) ⟩\n (pco ∘₀ p!gl n₁) ∘₀ (ap₀l (ap₀ f r) ∘₀ pgl n₂)\n ≡⟨ ap (λ x → (pco ∘₀ p!gl n₁) ∘₀ (x ∘₀ pgl n₂)) $ ! $ ap₀-compose left f r ⟩\n (pco ∘₀ p!gl n₁) ∘₀ (ap₀ (left ◯ f) r ∘₀ pgl n₂)\n ≡⟨ ap (λ x → (pco ∘₀ p!gl n₁) ∘₀ x)\n $ homotopy₀-naturality (left ◯ f) (right ◯ g) (proj ◯ glue) r ⟩\n (pco ∘₀ p!gl n₁) ∘₀ (pgl n₁ ∘₀ ap₀ (right ◯ g) r)\n ≡⟨ ! $ concat₀-assoc (pco ∘₀ p!gl n₁) (pgl n₁) (ap₀ (right ◯ g) r) ⟩\n ((pco ∘₀ p!gl n₁) ∘₀ pgl n₁) ∘₀ ap₀ (right ◯ g) r\n ≡⟨ ap (λ x → ((pco ∘₀ p!gl n₁) ∘₀ pgl n₁) ∘₀ x) $ ap₀-compose right g r ⟩\n ((pco ∘₀ p!gl n₁) ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)\n ≡⟨ ap (λ x → (x ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r))\n $ ! $ refl₀-right-unit $ pco ∘₀ p!gl n₁ ⟩∎\n (((pco ∘₀ p!gl n₁) ∘₀ refl₀) ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)\n ∎)\n\n bb⇒path : ∀ {b₂} → b-code-b b₁ b₂ → _≡₀_ {A = P} (right b₁) (right b₂)\n bb⇒path = π₁ bp⇒path-split\n ba⇒path : ∀ {a₂} → b-code-a b₁ a₂ → _≡₀_ {A = P} (right b₁) (left a₂)\n ba⇒path = π₂ bp⇒path-split\n\n bp⇒path : ∀ {p₂ : P} → b-code b₁ p₂ → right b₁ ≡₀ p₂\n bp⇒path {p₂} = pushout-rec\n (λ p → b-code b₁ p → right b₁ ≡₀ p)\n (λ a → ba⇒path {a})\n (λ b → bb⇒path {b})\n (λ c → loc-fiber-rec l\n (λ c → transport (λ p → b-code b₁ p → right b₁ ≡₀ p) (glue c) ba⇒path\n ≡ bb⇒path)\n ⦃ λ c → →-is-set (π₀-is-set (right b₁ ≡ right (g c))) _ _ ⦄\n (λ n → funext λ co →\n transport (λ p → b-code b₁ p → right b₁ ≡₀ p) (glue $ loc n) ba⇒path co\n ≡⟨ trans-→ (b-code b₁) (λ x → right b₁ ≡₀ x) (glue $ loc n) ba⇒path co ⟩\n transport (λ p → right b₁ ≡₀ p) (glue $ loc n) (ba⇒path $ transport (b-code b₁) (! (glue $ loc n)) co)\n ≡⟨ ap (transport (λ p → right b₁ ≡₀ p) (glue $ loc n) ◯ ba⇒path) $ trans-b-code-!glue-loc n co ⟩\n transport (λ p → right b₁ ≡₀ p) (glue $ loc n) (ba⇒path $ bb⇒ba n co)\n ≡⟨ trans-cst≡₀id (glue $ loc n) (ba⇒path $ bb⇒ba n co) ⟩\n (ba⇒path $ bb⇒ba n co) ∘₀ pgl n\n ≡⟨ refl ⟩\n ((bb⇒path co ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n\n ≡⟨ ap (λ x → x ∘₀ pgl n) $ refl₀-right-unit $ bb⇒path co ∘₀ p!gl n ⟩\n (bb⇒path co ∘₀ p!gl n) ∘₀ pgl n\n ≡⟨ concat₀-assoc (bb⇒path co) (p!gl n) (pgl n) ⟩\n bb⇒path co ∘₀ (p!gl n ∘₀ pgl n)\n ≡⟨ ap (λ x → bb⇒path co ∘₀ proj x) $ opposite-left-inverse $ glue $ loc n ⟩\n bb⇒path co ∘₀ refl₀\n ≡⟨ refl₀-right-unit $ bb⇒path co ⟩∎\n bb⇒path co\n ∎)\n c)\n p₂\n\n module _ where\n\n private\n Lbaaa : ∀ n {a₂} → b-code-a (g $ loc n) a₂ → Set i\n Lbaaa n co = aa⇒path {f $ loc n} (ba⇒aa n co) ≡ pgl n ∘₀ ba⇒path co\n Lbbab : ∀ n {b₂} → b-code-b (g $ loc n) b₂ → Set i\n Lbbab n co = ab⇒path {f $ loc n} (bb⇒ab n co) ≡ pgl n ∘₀ bb⇒path co\n\n private\n bp⇒ap⇒path-split : ∀ n\n → (∀ {a₂} co → Lbbab n {a₂} co)\n × (∀ {b₂} co → Lbaaa n {b₂} co)\n abstract\n bp⇒ap⇒path-split n = b-code-rec (g $ loc n)\n (λ co → ab⇒path {f $ loc n} (bb⇒ab n co) ≡ pgl n ∘₀ bb⇒path co)\n ⦃ λ _ → ≡-is-set $ π₀-is-set _ ⦄\n (λ co → aa⇒path {f $ loc n} (ba⇒aa n co) ≡ pgl n ∘₀ ba⇒path co)\n ⦃ λ _ → ≡-is-set $ π₀-is-set _ ⦄\n (λ p →\n ab⇒path (bb⇒ab n (⟧b p))\n ≡⟨ refl ⟩\n (refl₀ ∘₀ pgl n) ∘₀ ap₀r p\n ≡⟨ ap (λ x → x ∘₀ ap₀r p) $ refl₀-left-unit $ pgl n ⟩\n pgl n ∘₀ ap₀r p\n ≡⟨ refl ⟩∎\n pgl n ∘₀ bb⇒path (⟧b p)\n ∎)\n (λ n₁ {co} eq p₁ →\n (aa⇒path (ba⇒aa n co) ∘₀ pgl n₁) ∘₀ ap₀r p₁\n ≡⟨ ap (λ x → (x ∘₀ pgl n₁) ∘₀ ap₀r p₁) eq ⟩\n ((pgl n ∘₀ ba⇒path co) ∘₀ pgl n₁) ∘₀ ap₀r p₁\n ≡⟨ ap (λ x → x ∘₀ ap₀r p₁)\n $ concat₀-assoc (pgl n) (ba⇒path co) (pgl n₁) ⟩\n (pgl n ∘₀ (ba⇒path co ∘₀ pgl n₁)) ∘₀ ap₀r p₁\n ≡⟨ concat₀-assoc (pgl n) (ba⇒path co ∘₀ pgl n₁) (ap₀r p₁) ⟩∎\n pgl n ∘₀ ((ba⇒path co ∘₀ pgl n₁) ∘₀ ap₀r p₁)\n ∎)\n (λ n₁ {co} eq p₁ →\n (ab⇒path (bb⇒ab n co) ∘₀ p!gl n₁) ∘₀ ap₀l p₁\n ≡⟨ ap (λ x → (x ∘₀ p!gl n₁) ∘₀ ap₀l p₁) eq ⟩\n ((pgl n ∘₀ bb⇒path co) ∘₀ p!gl n₁) ∘₀ ap₀l p₁\n ≡⟨ ap (λ x → x ∘₀ ap₀l p₁)\n $ concat₀-assoc (pgl n) (bb⇒path co) (p!gl n₁) ⟩\n (pgl n ∘₀ (bb⇒path co ∘₀ p!gl n₁)) ∘₀ ap₀l p₁\n ≡⟨ concat₀-assoc (pgl n) (bb⇒path co ∘₀ p!gl n₁) (ap₀l p₁) ⟩∎\n pgl n ∘₀ ((bb⇒path co ∘₀ p!gl n₁) ∘₀ ap₀l p₁)\n ∎)\n (λ _ co → prop-has-all-paths (π₀-is-set _ _ _) _ co)\n (λ _ co → prop-has-all-paths (π₀-is-set _ _ _) _ co)\n (λ _ _ _ _ → prop-has-all-paths (π₀-is-set _ _ _) _ _)\n\n ba⇒aa⇒path : ∀ n {a₂} co → Lbaaa n {a₂} co\n ba⇒aa⇒path n = π₂ $ bp⇒ap⇒path-split n\n bb⇒ab⇒path : ∀ n {b₂} co → Lbbab n {b₂} co\n bb⇒ab⇒path n = π₁ $ bp⇒ap⇒path-split n\n\n private\n bp⇒ap⇒path : ∀ n {p₂} (co : b-code (g $ loc n) p₂)\n → ap⇒path {f $ loc n} {p₂} (bp⇒ap n {p₂} co)\n ≡ pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co\n abstract\n bp⇒ap⇒path n {p₂} = pushout-rec\n (λ x → ∀ (co : b-code (g $ loc n) x)\n → ap⇒path {f $ loc n} {x} (bp⇒ap n {x} co)\n ≡ pgl n ∘₀ bp⇒path {g $ loc n} {x} co)\n (λ a₂ → ba⇒aa⇒path n {a₂})\n (λ b₂ → bb⇒ab⇒path n {b₂})\n (λ _ → funext λ _ → prop-has-all-paths (π₀-is-set _ _ _) _ _)\n p₂\n\n code⇒path : ∀ {p₁ p₂} → code p₁ p₂ → p₁ ≡₀ p₂\n code⇒path {p₁} {p₂} = pushout-rec\n (λ p₁ → code p₁ p₂ → p₁ ≡₀ p₂)\n (λ a → ap⇒path {a} {p₂})\n (λ b → bp⇒path {b} {p₂})\n (loc-fiber-rec l\n (λ c → transport (λ x → code x p₂ → x ≡₀ p₂) (glue c) (ap⇒path {f c} {p₂})\n ≡ bp⇒path {g c} {p₂})\n ⦃ λ c → →-is-set (π₀-is-set (right (g c) ≡ p₂)) _ _ ⦄\n (λ n → funext λ (co : code (right $ g $ loc n) p₂) →\n transport (λ x → code x p₂ → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂}) co\n ≡⟨ trans-→ (λ x → code x p₂) (λ x → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂}) co ⟩\n transport (λ x → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂}\n $ transport (λ x → code x p₂) (! (glue $ loc n)) co)\n ≡⟨ ap (transport (λ x → x ≡₀ p₂) (glue $ loc n) ◯ ap⇒path {f $ loc n} {p₂})\n $ trans-!glue-code-loc n {p₂} co ⟩\n transport (λ x → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂} $ bp⇒ap n {p₂} co)\n ≡⟨ ap (transport (λ x → x ≡₀ p₂) (glue $ loc n)) $ bp⇒ap⇒path n {p₂} co ⟩\n transport (λ x → x ≡₀ p₂) (glue $ loc n) (pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co)\n ≡⟨ trans-id≡₀cst (glue $ loc n) (pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co) ⟩\n p!gl n ∘₀ (pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co)\n ≡⟨ ! $ concat₀-assoc (p!gl n) (pgl n) (bp⇒path {g $ loc n} {p₂} co) ⟩\n (p!gl n ∘₀ pgl n) ∘₀ bp⇒path {g $ loc n} {p₂} co\n ≡⟨ ap (λ x → proj x ∘₀ bp⇒path {g $ loc n} {p₂} co) $ opposite-left-inverse (glue $ loc n) ⟩\n refl₀ ∘₀ bp⇒path {g $ loc n} {p₂} co\n ≡⟨ refl₀-left-unit (bp⇒path {g $ loc n} {p₂} co) ⟩∎\n bp⇒path {g $ loc n} {p₂} co\n ∎))\n p₁\n", "meta": {"hexsha": "7edb9c4f2cfdc9bfbf4dde5d7937d2a11ea504be", "size": 14886, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "old/Homotopy/VanKampen/CodeToPath.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "old/Homotopy/VanKampen/CodeToPath.agda", "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "old/Homotopy/VanKampen/CodeToPath.agda", "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 44.4358208955, "max_line_length": 114, "alphanum_fraction": 0.4451162166, "num_tokens": 7007, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7826624789529376, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.36995162157184086}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import lib.Basics\nopen import lib.NConnected\nopen import lib.types.Nat\nopen import lib.types.TLevel\nopen import lib.types.Empty\nopen import lib.types.Group\nopen import lib.types.Pi\nopen import lib.types.Pointed\nopen import lib.types.Paths\nopen import lib.types.Sigma\nopen import lib.types.Truncation\nopen import lib.cubical.Square\n\nmodule lib.types.LoopSpace where\n\nmodule _ {i} where\n\n ⊙Ω : Ptd i → Ptd i\n ⊙Ω (A , a) = ⊙[ (a == a) , idp ]\n\n Ω : Ptd i → Type i\n Ω = fst ∘ ⊙Ω\n\n ⊙Ω^ : (n : ℕ) → Ptd i → Ptd i\n ⊙Ω^ O X = X\n ⊙Ω^ (S n) X = ⊙Ω (⊙Ω^ n X)\n\n Ω^ : (n : ℕ) → Ptd i → Type i\n Ω^ n X = fst (⊙Ω^ n X)\n\nidp^ : ∀ {i} (n : ℕ) {X : Ptd i} → Ω^ n X\nidp^ n {X} = snd (⊙Ω^ n X)\n\n{- for n ≥ 1, we have a group structure on the loop space -}\nmodule _ {i} (n : ℕ) {X : Ptd i} where\n !^S : Ω^ (S n) X → Ω^ (S n) X\n !^S = !\n\n conc^S : Ω^ (S n) X → Ω^ (S n) X → Ω^ (S n) X\n conc^S = _∙_\n\n{- pointed versions of functions on paths -}\n\nprivate\n pt-lemma : ∀ {i} {A : Type i} {x y : A} (p : x == y)\n → ! p ∙ (idp ∙' p) == idp\n pt-lemma idp = idp\n\n⊙conc : ∀ {i} {X : Ptd i} → fst (⊙Ω X ⊙× ⊙Ω X ⊙→ ⊙Ω X)\n⊙conc = (uncurry _∙_ , idp)\n\n⊙ap : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → fst (X ⊙→ Y) → fst (⊙Ω X ⊙→ ⊙Ω Y)\n⊙ap (f , fpt) = ((λ p → ! fpt ∙ ap f p ∙' fpt) , pt-lemma fpt)\n\n⊙ap2 : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n → fst (X ⊙× Y ⊙→ Z) → fst (⊙Ω X ⊙× ⊙Ω Y ⊙→ ⊙Ω Z)\n⊙ap2 (f , fpt) = ((λ {(p , q) → ! fpt ∙ ap2 (curry f) p q ∙' fpt}) ,\n pt-lemma fpt)\n\n⊙ap-∘ : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y))\n → ⊙ap (g ⊙∘ f) == ⊙ap g ⊙∘ ⊙ap f\n⊙ap-∘ (g , idp) (f , idp) = ⊙λ= (λ p → ap-∘ g f p) idp\n\n⊙ap-idf : ∀ {i} {X : Ptd i} → ⊙ap (⊙idf X) == ⊙idf _\n⊙ap-idf = ⊙λ= ap-idf idp\n\n⊙ap2-fst : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → ⊙ap2 {X = X} {Y = Y} ⊙fst == ⊙fst\n⊙ap2-fst = ⊙λ= (uncurry ap2-fst) idp\n\n⊙ap2-snd : ∀ {i j} {X : Ptd i} {Y : Ptd j}\n → ⊙ap2 {X = X} {Y = Y} ⊙snd == ⊙snd\n⊙ap2-snd = ⊙λ= (uncurry ap2-snd) idp\n\n⊙ap-ap2 : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}\n (G : fst (Z ⊙→ W)) (F : fst (X ⊙× Y ⊙→ Z))\n → ⊙ap G ⊙∘ ⊙ap2 F == ⊙ap2 (G ⊙∘ F)\n⊙ap-ap2 (g , idp) (f , idp) =\n ⊙λ= (uncurry (ap-ap2 g (curry f))) idp\n\n⊙ap2-ap : ∀ {i j k l m}\n {X : Ptd i} {Y : Ptd j} {U : Ptd k} {V : Ptd l} {Z : Ptd m}\n (G : fst ((U ⊙× V) ⊙→ Z)) (F₁ : fst (X ⊙→ U)) (F₂ : fst (Y ⊙→ V))\n → ⊙ap2 G ⊙∘ pair⊙→ (⊙ap F₁) (⊙ap F₂) == ⊙ap2 (G ⊙∘ pair⊙→ F₁ F₂)\n⊙ap2-ap (g , idp) (f₁ , idp) (f₂ , idp) =\n ⊙λ= (λ {(p , q) → ap2-ap-l (curry g) f₁ p (ap f₂ q)\n ∙ ap2-ap-r (λ x v → g (f₁ x , v)) f₂ p q})\n idp\n\n⊙ap2-diag : ∀ {i j} {X : Ptd i} {Y : Ptd j} (F : fst (X ⊙× X ⊙→ Y))\n → ⊙ap2 F ⊙∘ ⊙diag == ⊙ap (F ⊙∘ ⊙diag)\n⊙ap2-diag (f , idp) = ⊙λ= (ap2-diag (curry f)) idp\n\n{- ap and ap2 for higher loop spaces -}\n\nap^ : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → fst (X ⊙→ Y) → fst (⊙Ω^ n X ⊙→ ⊙Ω^ n Y)\nap^ O F = F\nap^ (S n) F = ⊙ap (ap^ n F)\n\nap2^ : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n → fst ((X ⊙× Y) ⊙→ Z)\n → fst ((⊙Ω^ n X ⊙× ⊙Ω^ n Y) ⊙→ ⊙Ω^ n Z)\nap2^ O F = F\nap2^ (S n) F = ⊙ap2 (ap2^ n F)\n\nap^-idf : ∀ {i} (n : ℕ) {X : Ptd i} → ap^ n (⊙idf X) == ⊙idf _\nap^-idf O = idp\nap^-idf (S n) = ap ⊙ap (ap^-idf n) ∙ ⊙ap-idf\n\nap^-ap2^ : ∀ {i j k l} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}\n (G : fst (Z ⊙→ W)) (F : fst ((X ⊙× Y) ⊙→ Z))\n → ap^ n G ⊙∘ ap2^ n F == ap2^ n (G ⊙∘ F)\nap^-ap2^ O G F = idp\nap^-ap2^ (S n) G F = ⊙ap-ap2 (ap^ n G) (ap2^ n F) ∙ ap ⊙ap2 (ap^-ap2^ n G F)\n\nap2^-fst : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → ap2^ n {X} {Y} ⊙fst == ⊙fst\nap2^-fst O = idp\nap2^-fst (S n) = ap ⊙ap2 (ap2^-fst n) ∙ ⊙ap2-fst\n\nap2^-snd : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}\n → ap2^ n {X} {Y} ⊙snd == ⊙snd\nap2^-snd O = idp\nap2^-snd (S n) = ap ⊙ap2 (ap2^-snd n) ∙ ⊙ap2-snd\n\nap2^-ap^ : ∀ {i j k l m} (n : ℕ)\n {X : Ptd i} {Y : Ptd j} {U : Ptd k} {V : Ptd l} {Z : Ptd m}\n (G : fst ((U ⊙× V) ⊙→ Z)) (F₁ : fst (X ⊙→ U)) (F₂ : fst (Y ⊙→ V))\n → ap2^ n G ⊙∘ pair⊙→ (ap^ n F₁) (ap^ n F₂) == ap2^ n (G ⊙∘ pair⊙→ F₁ F₂)\nap2^-ap^ O G F₁ F₂ = idp\nap2^-ap^ (S n) G F₁ F₂ =\n ⊙ap2-ap (ap2^ n G) (ap^ n F₁) (ap^ n F₂) ∙ ap ⊙ap2 (ap2^-ap^ n G F₁ F₂)\n\nap2^-diag : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} (F : fst (X ⊙× X ⊙→ Y))\n → ap2^ n F ⊙∘ ⊙diag == ap^ n (F ⊙∘ ⊙diag)\nap2^-diag O F = idp\nap2^-diag (S n) F = ⊙ap2-diag (ap2^ n F) ∙ ap ⊙ap (ap2^-diag n F)\n\n\nmodule _ {i} {X : Ptd i} (n : ℕ) where\n\n {- Prove these as lemmas now\n - so we don't have to deal with the n = O case later -}\n\n conc^S-unit-l : (q : Ω^ (S n) X)\n → (conc^S n (idp^ (S n)) q) == q\n conc^S-unit-l _ = idp\n\n conc^S-unit-r : (q : Ω^ (S n) X)\n → (conc^S n q (idp^ (S n))) == q\n conc^S-unit-r = ∙-unit-r\n\n conc^S-assoc : (p q r : Ω^ (S n) X)\n → conc^S n (conc^S n p q) r == conc^S n p (conc^S n q r)\n conc^S-assoc = ∙-assoc\n\n !^S-inv-l : (p : Ω^ (S n) X)\n → conc^S n (!^S n p) p == idp^ (S n)\n !^S-inv-l = !-inv-l\n\n !^S-inv-r : (p : Ω^ (S n) X)\n → conc^S n p (!^S n p) == idp^ (S n)\n !^S-inv-r = !-inv-r\n\nabstract\n ap^S-conc^S : ∀ {i j} (n : ℕ)\n {X : Ptd i} {Y : Ptd j} (F : fst (X ⊙→ Y)) (p q : Ω^ (S n) X)\n → fst (ap^ (S n) F) (conc^S n p q)\n == conc^S n (fst (ap^ (S n) F) p) (fst (ap^ (S n) F) q)\n ap^S-conc^S n {X = X} {Y = Y} F p q =\n ! gpt ∙ ap g (p ∙ q) ∙' gpt\n =⟨ ap-∙ g p q |in-ctx (λ w → ! gpt ∙ w ∙' gpt) ⟩\n ! gpt ∙ (ap g p ∙ ap g q) ∙' gpt\n =⟨ lemma (ap g p) (ap g q) gpt ⟩\n (! gpt ∙ ap g p ∙' gpt) ∙ (! gpt ∙ ap g q ∙' gpt) ∎\n where\n g : Ω^ n X → Ω^ n Y\n g = fst (ap^ n F)\n\n gpt : g (idp^ n) == idp^ n\n gpt = snd (ap^ n F)\n\n lemma : ∀ {i} {A : Type i} {x y : A}\n → (p q : x == x) (r : x == y)\n → ! r ∙ (p ∙ q) ∙' r == (! r ∙ p ∙' r) ∙ (! r ∙ q ∙' r)\n lemma p q idp = idp\n\n{- ap^ preserves (pointed) equivalences -}\nmodule _ {i j} {X : Ptd i} {Y : Ptd j} where\n\n is-equiv-ap^ : (n : ℕ) (F : fst (X ⊙→ Y)) (e : is-equiv (fst F))\n → is-equiv (fst (ap^ n F))\n is-equiv-ap^ O F e = e\n is-equiv-ap^ (S n) F e =\n pre∙-is-equiv (! (snd (ap^ n F)))\n ∘ise post∙'-is-equiv (snd (ap^ n F))\n ∘ise snd (equiv-ap (_ , is-equiv-ap^ n F e) _ _)\n\n equiv-ap^ : (n : ℕ) (F : fst (X ⊙→ Y)) (e : is-equiv (fst F))\n → Ω^ n X ≃ Ω^ n Y\n equiv-ap^ n F e = (fst (ap^ n F) , is-equiv-ap^ n F e)\n\nΩ^-level-in : ∀ {i} (m : ℕ₋₂) (n : ℕ) (X : Ptd i)\n → (has-level (⟨ n ⟩₋₂ +2+ m) (fst X) → has-level m (Ω^ n X))\nΩ^-level-in m O X pX = pX\nΩ^-level-in m (S n) X pX =\n Ω^-level-in (S m) n X\n (transport (λ k → has-level k (fst X)) (! (+2+-βr ⟨ n ⟩₋₂ m)) pX)\n (idp^ n) (idp^ n)\n\nΩ^-conn-in : ∀ {i} (m : ℕ₋₂) (n : ℕ) (X : Ptd i)\n → (is-connected (⟨ n ⟩₋₂ +2+ m) (fst X)) → is-connected m (Ω^ n X)\nΩ^-conn-in m O X pX = pX\nΩ^-conn-in m (S n) X pX =\n path-conn $ Ω^-conn-in (S m) n X $\n transport (λ k → is-connected k (fst X)) (! (+2+-βr ⟨ n ⟩₋₂ m)) pX\n\n{- Eckmann-Hilton argument -}\nmodule _ {i} {X : Ptd i} where\n\n ap2-conc-is-conc^S : (α β : Ω^ 2 X) → ap2 _∙_ α β == conc^S 1 α β\n ap2-conc-is-conc^S α β = ap2-out _∙_ α β ∙ ap2 _∙_ (lemma α) (ap-idf β)\n where\n lemma : ∀ {i} {A : Type i} {x y : A} {p q : x == y} (α : p == q)\n → ap (λ r → r ∙ idp) α == ∙-unit-r p ∙ α ∙' ! (∙-unit-r q)\n lemma {p = idp} idp = idp\n\n ⊙ap2-conc-is-conc : ⊙ap2 (⊙conc {X = X}) == ⊙conc\n ⊙ap2-conc-is-conc = ⊙λ= (uncurry ap2-conc-is-conc^S) idp\n\n conc^2-comm : (α β : Ω^ 2 X) → conc^S 1 α β == conc^S 1 β α\n conc^2-comm α β = ! (⋆2=conc^ α β) ∙ ⋆2=⋆'2 α β ∙ ⋆'2=conc^ α β\n where\n ⋆2=conc^ : (α β : Ω^ 2 X) → α ⋆2 β == conc^S 1 α β\n ⋆2=conc^ α β = ap (λ π → π ∙ β) (∙-unit-r α)\n\n ⋆'2=conc^ : (α β : Ω^ 2 X) → α ⋆'2 β == conc^S 1 β α\n ⋆'2=conc^ α β = ap (λ π → β ∙ π) (∙-unit-r α)\n\n{- Pushing truncation through loop space -}\nmodule _ {i} where\n\n Trunc-Ω^ : (m : ℕ₋₂) (n : ℕ) (X : Ptd i)\n → ⊙Trunc m (⊙Ω^ n X) == ⊙Ω^ n (⊙Trunc (⟨ n ⟩₋₂ +2+ m) X)\n Trunc-Ω^ m O X = idp\n Trunc-Ω^ m (S n) X =\n ⊙Trunc m (⊙Ω^ (S n) X)\n =⟨ ! (pair= (Trunc=-path [ _ ] [ _ ]) (↓-idf-ua-in _ idp)) ⟩\n ⊙Ω (⊙Trunc (S m) (⊙Ω^ n X))\n =⟨ ap ⊙Ω (Trunc-Ω^ (S m) n X) ⟩\n ⊙Ω^ (S n) (⊙Trunc (⟨ n ⟩₋₂ +2+ S m) X)\n =⟨ +2+-βr ⟨ n ⟩₋₂ m |in-ctx (λ k → ⊙Ω^ (S n) (⊙Trunc k X)) ⟩\n ⊙Ω^ (S n) (⊙Trunc (S ⟨ n ⟩₋₂ +2+ m) X) ∎\n\n Ω-Trunc-equiv : (m : ℕ₋₂) (X : Ptd i)\n → Ω (⊙Trunc (S m) X) ≃ Trunc m (Ω X)\n Ω-Trunc-equiv m X = Trunc=-equiv [ snd X ] [ snd X ]\n\n{- A loop space is a pregroup, and a group if it has the right level -}\nmodule _ {i} (n : ℕ) (X : Ptd i) where\n\n Ω^S-group-structure : GroupStructure (Ω^ (S n) X)\n Ω^S-group-structure = record {\n ident = idp^ (S n);\n inv = !^S n;\n comp = conc^S n;\n unitl = conc^S-unit-l n;\n unitr = conc^S-unit-r n;\n assoc = conc^S-assoc n;\n invr = !^S-inv-r n;\n invl = !^S-inv-l n\n }\n\n Ω^S-group : has-level ⟨ S n ⟩ (fst X) → Group i\n Ω^S-group pX = group\n (Ω^ (S n) X)\n (Ω^-level-in 0 (S n) X $\n transport (λ t → has-level t (fst X)) (+2+-comm 0 ⟨ S n ⟩₋₂) pX)\n Ω^S-group-structure\n\n{- Our definition of Ω^ builds up loops on the outside,\n - but this is equivalent to building up on the inside -}\nmodule _ {i} where\n ⊙Ω^-inner-path : (n : ℕ) (X : Ptd i)\n → ⊙Ω^ (S n) X == ⊙Ω^ n (⊙Ω X)\n ⊙Ω^-inner-path O X = idp\n ⊙Ω^-inner-path (S n) X = ap ⊙Ω (⊙Ω^-inner-path n X)\n\n ⊙Ω^-inner-out : (n : ℕ) (X : Ptd i)\n → fst (⊙Ω^ (S n) X ⊙→ ⊙Ω^ n (⊙Ω X))\n ⊙Ω^-inner-out O _ = (idf _ , idp)\n ⊙Ω^-inner-out (S n) X = ap^ 1 (⊙Ω^-inner-out n X)\n\n Ω^-inner-out : (n : ℕ) (X : Ptd i)\n → (Ω^ (S n) X → Ω^ n (⊙Ω X))\n Ω^-inner-out n X = fst (⊙Ω^-inner-out n X)\n\n Ω^S-inner-out-conc^S : (n : ℕ)\n (X : Ptd i) (p q : Ω^ (S (S n)) X)\n → Ω^-inner-out (S n) X (conc^S (S n) p q)\n == conc^S n (Ω^-inner-out (S n) X p) (Ω^-inner-out (S n) X q)\n Ω^S-inner-out-conc^S n X p q =\n ap^S-conc^S 0 (⊙Ω^-inner-out n X) p q\n\n Ω^-inner-is-equiv : (n : ℕ) (X : Ptd i)\n → is-equiv (fst (⊙Ω^-inner-out n X))\n Ω^-inner-is-equiv O X = is-eq (idf _) (idf _) (λ _ → idp) (λ _ → idp)\n Ω^-inner-is-equiv (S n) X =\n is-equiv-ap^ 1 (⊙Ω^-inner-out n X) (Ω^-inner-is-equiv n X)\n\n Ω^-inner-equiv : (n : ℕ) (X : Ptd i) → Ω^ (S n) X ≃ Ω^ n (⊙Ω X)\n Ω^-inner-equiv n X = _ , Ω^-inner-is-equiv n X\n", "meta": {"hexsha": "e469608d4ebc776e9081dd868702e5b4b1d26b78", "size": 10202, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/types/LoopSpace.agda", "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "core/lib/types/LoopSpace.agda", "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "core/lib/types/LoopSpace.agda", "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": 32.0817610063, "max_line_length": 78, "alphanum_fraction": 0.4527543619, "num_tokens": 5455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195385342971, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.3699273653733934}} {"text": "{-# OPTIONS --without-K #-}\n\n\nopen import M-types.Base.Core\nopen import M-types.Base.Sum\nopen import M-types.Base.Prod\nopen import M-types.Base.Eq\nopen import M-types.Base.Equi\nopen import M-types.Base.Axiom\n\n\nmodule M-types.Base.Rel where\n SpanRel : Ty ℓ → Ty (ℓ-suc ℓ)\n SpanRel {ℓ} X = ∑[ ty ∈ Ty ℓ ] (ty → X) × (ty → X)\n\n ρ₀ : {X : Ty ℓ₀} {Y Z : X → Ty ℓ₁} →\n ∏[ s ∈ ∑[ x ∈ X ] (Y x × Z x) ] Y (pr₀ s)\n ρ₀ = pr₀ ∘ pr₁\n\n ρ₁ : {X : Ty ℓ₀} {Y Z : X → Ty ℓ₁} →\n ∏[ s ∈ ∑[ x ∈ X ] (Y x × Z x) ] Z (pr₀ s)\n ρ₁ = pr₁ ∘ pr₁\n\n SpanRel-syntax : {X : Ty ℓ} →\n ∏[ ∼ ∈ SpanRel X ] ∏[ x₀ ∈ X ] ∏[ x₁ ∈ X ] Ty ℓ\n SpanRel-syntax ∼ x₀ x₁ = ∑[ s ∈ (ty ∼) ] ((ρ₀ ∼ s ≡ x₀) × (ρ₁ ∼ s ≡ x₁))\n syntax SpanRel-syntax ∼ x₀ x₁ = x₀ ⟨ ∼ ⟩ x₁\n\n ≡-spanRel : {X : Ty ℓ} →\n SpanRel X\n ≡-spanRel {_} {X} = (X , id , id)\n\n\n SpanRelMor : {X : Ty ℓ} →\n SpanRel X → SpanRel X → Ty ℓ\n SpanRelMor {_} {X} ∼ ≈ =\n ∑[ fun ∈ (ty ∼ → ty ≈) ]\n (ρ₀ ≈ ∘ fun ≡ ρ₀ ∼) × (ρ₁ ≈ ∘ fun ≡ ρ₁ ∼)\n\n com₀ : {X : Ty ℓ₀} {Y Z : X → Ty ℓ₁} →\n ∏[ s ∈ ∑[ x ∈ X ] (Y x × Z x) ] Y (pr₀ s)\n com₀ = pr₀ ∘ pr₁\n\n com₁ : {X : Ty ℓ₀} {Y Z : X → Ty ℓ₁} →\n ∏[ s ∈ ∑[ x ∈ X ] (Y x × Z x) ] Z (pr₀ s)\n com₁ = pr₁ ∘ pr₁\n\n id-spanRel : {X : Ty ℓ} {∼ : SpanRel X} →\n SpanRelMor ∼ ∼\n id-spanRel {_} {X} {∼} = (id , refl , refl)\n\n infixr 9 _∘-spanRel_\n _∘-spanRel_ : {X : Ty ℓ} {∼₀ ∼₁ ∼₂ : SpanRel X} →\n SpanRelMor ∼₁ ∼₂ → SpanRelMor ∼₀ ∼₁ → SpanRelMor ∼₀ ∼₂\n g ∘-spanRel f =\n (\n fun g ∘ fun f ,\n ap (λ k → k ∘ fun f) (com₀ g) · com₀ f ,\n ap (λ k → k ∘ fun f) (com₁ g) · com₁ f\n )\n\n\n DepRel : Ty ℓ → Ty (ℓ-suc ℓ)\n DepRel {ℓ} X = X → X → Ty ℓ\n\n DepRel-syntax : {X : Ty ℓ} →\n ∏[ ∼ ∈ DepRel X ] ∏[ x₀ ∈ X ] ∏[ x₁ ∈ X ] Ty ℓ\n DepRel-syntax ∼ x₀ x₁ = ∼ x₀ x₁\n syntax DepRel-syntax ∼ x₀ x₁ = x₀ [ ∼ ] x₁\n\n ≡-depRel : {X : Ty ℓ} →\n DepRel X\n ≡-depRel = λ x₀ → λ x₁ → x₀ ≡ x₁\n\n\n DepRelMor : {X : Ty ℓ} →\n DepRel X → DepRel X → Ty ℓ\n DepRelMor {_} {X} ∼ ≈ =\n ∏[ x₀ ∈ X ] ∏[ x₁ ∈ X ]\n (x₀ [ ∼ ] x₁ → x₀ [ ≈ ] x₁)\n\n id-depRel : {X : Ty ℓ} {∼ : DepRel X} →\n DepRelMor ∼ ∼\n id-depRel {_} {X} {∼} = λ x₀ → λ x₁ → id\n\n infixr 9 _∘-depRel_\n _∘-depRel_ : {X : Ty ℓ} {∼₀ ∼₁ ∼₂ : DepRel X} →\n DepRelMor ∼₁ ∼₂ → DepRelMor ∼₀ ∼₁ → DepRelMor ∼₀ ∼₂\n g ∘-depRel f = λ x₀ → λ x₁ → g x₀ x₁ ∘ f x₀ x₁\n\n\n SpanRel→DepRel : {X : Ty ℓ} →\n SpanRel X → DepRel X\n SpanRel→DepRel {_} {X} ∼ = λ x₀ → λ x₁ → x₀ ⟨ ∼ ⟩ x₁\n\n DepRel→SpanRel : {X : Ty ℓ} →\n DepRel X → SpanRel X\n DepRel→SpanRel {_} {X} ∼ =\n (\n (∑[ x₀ ∈ X ] ∑[ x₁ ∈ X ] x₀ [ ∼ ] x₁) ,\n pr₀ ,\n pr₀ ∘ pr₁\n )\n\n\n SpanRel→DepRel-pres : {X : Ty ℓ} →\n ∏[ ∼ ∈ SpanRel X ] ∏[ x₀ ∈ X ] ∏[ x₁ ∈ X ]\n (x₀ [ SpanRel→DepRel ∼ ] x₁) ≡ (x₀ ⟨ ∼ ⟩ x₁)\n SpanRel→DepRel-pres ∼ x₀ x₁ = refl\n\n DepRel→SpanRel-pres : {X : Ty ℓ} →\n ∏[ ∼ ∈ DepRel X ] ∏[ x₀ ∈ X ] ∏[ x₁ ∈ X ]\n (x₀ ⟨ DepRel→SpanRel ∼ ⟩ x₁) ≃ (x₀ [ ∼ ] x₁)\n DepRel→SpanRel-pres ∼ x₀ x₁ =\n (\n (λ ((y₀ , y₁ , s) , p₀ , p₁) →\n tra (λ x → x [ ∼ ] x₁) p₀ (tra (λ y → y₀ [ ∼ ] y) p₁ s)\n ) ,\n Qinv→IsEqui (\n (λ s → ((x₀ , x₁ , s) , refl , refl)) ,\n (λ {((x₀ , x₁ , s) , refl , refl) → refl}) ,\n (λ s → refl)\n )\n )\n\n\n SpanRel→SpanRel-mor : {X : Ty ℓ} →\n ∏[ ∼ ∈ SpanRel X ] SpanRelMor ∼ (DepRel→SpanRel (SpanRel→DepRel ∼))\n SpanRel→SpanRel-mor ∼ =\n (\n (λ s → (ρ₀ ∼ s , ρ₁ ∼ s , (s , refl , refl))) ,\n refl ,\n refl\n )\n\n DepRel→DepRel-mor : {X : Ty ℓ} →\n ∏[ ∼ ∈ DepRel X ] DepRelMor ∼ (SpanRel→DepRel (DepRel→SpanRel ∼))\n DepRel→DepRel-mor ∼ = λ x₀ → λ x₁ → λ s → ((x₀ , x₁ , s) , refl , refl)\n\n\n ≡-SpanRel→DepRel-mor : {X : Ty ℓ} →\n DepRelMor {ℓ} {X} (SpanRel→DepRel ≡-spanRel) ≡-depRel\n ≡-SpanRel→DepRel-mor = λ x₀ → λ x₁ → λ(s , p₀ , p₁) → p₀ ⁻¹ · p₁\n\n ≡-DepRel→SpanRel-mor : {X : Ty ℓ} →\n SpanRelMor {ℓ} {X} (DepRel→SpanRel ≡-depRel) ≡-spanRel\n ≡-DepRel→SpanRel-mor =\n (\n (λ (x₀ , x₁ , p) → x₀) ,\n refl ,\n funext (λ (x₀ , x₁ , p) → p)\n )\n\n\n SpanRelMor→DepRelMor : {X : Ty ℓ} {∼ ≈ : SpanRel X} →\n SpanRelMor ∼ ≈ → DepRelMor (SpanRel→DepRel ∼) (SpanRel→DepRel ≈)\n SpanRelMor→DepRelMor (fun , refl , refl) x₀ x₁ (s , refl , refl) =\n (\n fun s ,\n refl ,\n refl\n )\n\n DepRelMor→SpanRelMor : {X : Ty ℓ} {∼ ≈ : DepRel X} →\n DepRelMor ∼ ≈ → SpanRelMor (DepRel→SpanRel ∼) (DepRel→SpanRel ≈)\n DepRelMor→SpanRelMor f =\n (\n (λ (x₀ , x₁ , s) → (x₀ , x₁ , f x₀ x₁ s)) ,\n refl {_} {_} {pr₀} ,\n refl\n )\n", "meta": {"hexsha": "565ea93906bd3093a6151ffec669d74125dd37bd", "size": 4945, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Base/Rel.agda", "max_stars_repo_name": "DDOtten/M-types", "max_stars_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369", "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": "Base/Rel.agda", "max_issues_repo_name": "DDOtten/M-types", "max_issues_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369", "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": "Base/Rel.agda", "max_forks_repo_name": "DDOtten/M-types", "max_forks_repo_head_hexsha": "5b70f4b3dc3e50365ad7a3a80b0cd14efbfa4369", "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": 28.75, "max_line_length": 76, "alphanum_fraction": 0.4202224469, "num_tokens": 2225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.36992735951089156}} {"text": "-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇.\n-- Hilbert-style formalisation of syntax with context pairs.\n-- Nested terms.\n\nmodule BasicIS4.Syntax.DyadicHilbert where\n\nopen import BasicIS4.Syntax.Common public\n\n\n-- Derivations.\n\ninfix 3 _⊢_\ndata _⊢_ : Cx² Ty Ty → Ty → Set where\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\ninfix 3 _⊢⋆_\n_⊢⋆_ : Cx² Ty Ty → Cx Ty → Set\nΓ ⁏ Δ ⊢⋆ ∅ = 𝟙\nΓ ⁏ Δ ⊢⋆ Ξ , A = Γ ⁏ Δ ⊢⋆ Ξ × Γ ⁏ Δ ⊢ A\n\n\n-- Monotonicity with respect to context inclusion.\n\nmono⊢ : ∀ {A Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢ A → Γ′ ⁏ Δ ⊢ A\nmono⊢ η (var i) = var (mono∈ η i)\nmono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)\nmono⊢ η ci = ci\nmono⊢ η ck = ck\nmono⊢ η cs = cs\nmono⊢ η (mvar i) = mvar i\nmono⊢ η (box t) = box t\nmono⊢ η cdist = cdist\nmono⊢ η cup = cup\nmono⊢ η cdown = cdown\nmono⊢ η cpair = cpair\nmono⊢ η cfst = cfst\nmono⊢ η csnd = csnd\nmono⊢ η unit = unit\n\nmono⊢⋆ : ∀ {Ξ Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢⋆ Ξ → Γ′ ⁏ Δ ⊢⋆ Ξ\nmono⊢⋆ {∅} η ∙ = ∙\nmono⊢⋆ {Ξ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t\n\n\n-- Monotonicity with respect to modal context inclusion.\n\nmmono⊢ : ∀ {A Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ′ ⊢ A\nmmono⊢ θ (var i) = var i\nmmono⊢ θ (app t u) = app (mmono⊢ θ t) (mmono⊢ θ u)\nmmono⊢ θ ci = ci\nmmono⊢ θ ck = ck\nmmono⊢ θ cs = cs\nmmono⊢ θ (mvar i) = mvar (mono∈ θ i)\nmmono⊢ θ (box t) = box (mmono⊢ θ t)\nmmono⊢ θ cdist = cdist\nmmono⊢ θ cup = cup\nmmono⊢ θ cdown = cdown\nmmono⊢ θ cpair = cpair\nmmono⊢ θ cfst = cfst\nmmono⊢ θ csnd = csnd\nmmono⊢ θ unit = unit\n\nmmono⊢⋆ : ∀ {Ξ Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ′ ⊢⋆ Ξ\nmmono⊢⋆ {∅} θ ∙ = ∙\nmmono⊢⋆ {Ξ , A} θ (ts , t) = mmono⊢⋆ θ ts , mmono⊢ θ t\n\n\n-- Monotonicity using context pairs.\n\nmono²⊢ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊢ A → Π′ ⊢ A\nmono²⊢ (η , θ) = mono⊢ η ∘ mmono⊢ θ\n\n\n-- Shorthand for variables.\n\nv₀ : ∀ {A Γ Δ} → Γ , A ⁏ Δ ⊢ A\nv₀ = var i₀\n\nv₁ : ∀ {A B Γ Δ} → Γ , A , B ⁏ Δ ⊢ A\nv₁ = var i₁\n\nv₂ : ∀ {A B C Γ Δ} → Γ , A , B , C ⁏ Δ ⊢ A\nv₂ = var i₂\n\nmv₀ : ∀ {A Γ Δ} → Γ ⁏ Δ , A ⊢ A\nmv₀ = mvar i₀\n\nmv₁ : ∀ {A B Γ Δ} → Γ ⁏ Δ , A , B ⊢ A\nmv₁ = mvar i₁\n\nmv₂ : ∀ {A B C Γ Δ} → Γ ⁏ Δ , A , B , C ⊢ A\nmv₂ = mvar i₂\n\n\n-- Reflexivity.\n\nrefl⊢⋆ : ∀ {Γ Δ} → Γ ⁏ Δ ⊢⋆ Γ\nrefl⊢⋆ {∅} = ∙\nrefl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀\n\nmrefl⊢⋆ : ∀ {Δ Γ} → Γ ⁏ Δ ⊢⋆ □⋆ Δ\nmrefl⊢⋆ {∅} = ∙\nmrefl⊢⋆ {Δ , A} = mmono⊢⋆ weak⊆ mrefl⊢⋆ , box mv₀\n\n\n-- Deduction theorem.\n\nlam : ∀ {A B Γ Δ} → Γ , A ⁏ Δ ⊢ B → Γ ⁏ Δ ⊢ A ▻ B\nlam (var top) = ci\nlam (var (pop i)) = app ck (var i)\nlam (app t u) = app (app cs (lam t)) (lam u)\nlam ci = app ck ci\nlam ck = app ck ck\nlam cs = app ck cs\nlam (mvar i) = app ck (mvar i)\nlam (box t) = app ck (box t)\nlam cdist = app ck cdist\nlam cup = app ck cup\nlam cdown = app ck cdown\nlam cpair = app ck cpair\nlam cfst = app ck cfst\nlam csnd = app ck csnd\nlam unit = app ck unit\n\nlam⋆ : ∀ {Ξ A Γ Δ} → Γ ⧺ Ξ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ Ξ ▻⋯▻ A\nlam⋆ {∅} = I\nlam⋆ {Ξ , B} = lam⋆ {Ξ} ∘ lam\n\nlam⋆₀ : ∀ {Γ A Δ} → Γ ⁏ Δ ⊢ A → ∅ ⁏ Δ ⊢ Γ ▻⋯▻ A\nlam⋆₀ {∅} = I\nlam⋆₀ {Γ , B} = lam⋆₀ ∘ lam\n\n\n-- Combined axioms of distribution and transitivity.\n\ncdistup : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ □ (□ A ▻ B) ▻ □ A ▻ □ B\ncdistup = app (app cs (app (app cs (app ck cs))\n (app (app cs (app (app cs (app ck cs))\n (lam (lam cdist))))\n (app (app cs (app ck ck)) ci))))\n (app (app cs (app (app cs (app ck cs))\n (lam (lam cup))))\n (app ck ci))\n\n\n-- Modal deduction theorem.\n\nmlam : ∀ {A B Γ Δ} → Γ ⁏ Δ , A ⊢ B → Γ ⁏ Δ ⊢ □ A ▻ B\nmlam (var i) = app ck (var i)\nmlam (app t u) = app (app cs (mlam t)) (mlam u)\nmlam ci = app ck ci\nmlam ck = app ck ck\nmlam cs = app ck cs\nmlam (mvar top) = cdown\nmlam (mvar (pop i)) = app ck (mvar i)\nmlam (box t) = app cdistup (box (mlam t))\nmlam cdist = app ck cdist\nmlam cup = app ck cup\nmlam cdown = app ck cdown\nmlam cpair = app ck cpair\nmlam cfst = app ck cfst\nmlam csnd = app ck csnd\nmlam unit = app ck unit\n\nmlam⋆ : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ ⧺ Ξ ⊢ A → Γ ⁏ Δ ⊢ □⋆ Ξ ▻⋯▻ A\nmlam⋆ {∅} = I\nmlam⋆ {Ξ , B} = mlam⋆ {Ξ} ∘ mlam\n\nmlam⋆₀ : ∀ {Δ A Γ} → Γ ⁏ Δ ⊢ A → Γ ⁏ ∅ ⊢ □⋆ Δ ▻⋯▻ A\nmlam⋆₀ {∅} = I\nmlam⋆₀ {Δ , B} = mlam⋆₀ ∘ mlam\n\n\n-- Detachment theorems.\n\ndet : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ▻ B → Γ , A ⁏ Δ ⊢ B\ndet t = app (mono⊢ weak⊆ t) v₀\n\ndet⋆ : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ ⊢ Ξ ▻⋯▻ A → Γ ⧺ Ξ ⁏ Δ ⊢ A\ndet⋆ {∅} = I\ndet⋆ {Ξ , B} = det ∘ det⋆ {Ξ}\n\ndet⋆₀ : ∀ {Γ A Δ} → ∅ ⁏ Δ ⊢ Γ ▻⋯▻ A → Γ ⁏ Δ ⊢ A\ndet⋆₀ {∅} = I\ndet⋆₀ {Γ , B} = det ∘ det⋆₀\n\nmdet : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ □ A ▻ B → Γ ⁏ Δ , A ⊢ B\nmdet t = app (mmono⊢ weak⊆ t) (box mv₀)\n\nmdet⋆ : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ ⊢ □⋆ Ξ ▻⋯▻ A → Γ ⁏ Δ ⧺ Ξ ⊢ A\nmdet⋆ {∅} = I\nmdet⋆ {Ξ , B} = mdet ∘ mdet⋆ {Ξ}\n\nmdet⋆₀ : ∀ {Δ A Γ} → Γ ⁏ ∅ ⊢ □⋆ Δ ▻⋯▻ A → Γ ⁏ Δ ⊢ A\nmdet⋆₀ {∅} = I\nmdet⋆₀ {Δ , B} = mdet ∘ mdet⋆₀\n\n\n-- Context manipulation.\n\nmerge : ∀ {Δ A Γ} → Γ ⁏ Δ ⊢ A → Γ ⧺ (□⋆ Δ) ⁏ ∅ ⊢ A\nmerge {Δ} = det⋆ {□⋆ Δ} ∘ mlam⋆₀\n\nmmerge : ∀ {Γ A Δ} → □⋆ Γ ⁏ Δ ⊢ A → ∅ ⁏ Δ ⧺ Γ ⊢ A\nmmerge {Γ} = mdet⋆ {Γ} ∘ lam⋆₀\n\nsplit : ∀ {Δ A Γ} → Γ ⧺ (□⋆ Δ) ⁏ ∅ ⊢ A → Γ ⁏ Δ ⊢ A\nsplit {Δ} = mdet⋆₀ ∘ lam⋆ {□⋆ Δ}\n\nmsplit : ∀ {Γ A Δ} → ∅ ⁏ Δ ⧺ Γ ⊢ A → □⋆ Γ ⁏ Δ ⊢ A\nmsplit {Γ} = det⋆₀ ∘ mlam⋆ {Γ}\n\nmerge⋆ : ∀ {Ξ Δ Γ} → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⧺ (□⋆ Δ) ⁏ ∅ ⊢⋆ Ξ\nmerge⋆ {∅} ∙ = ∙\nmerge⋆ {Ξ , A} (ts , t) = merge⋆ ts , merge t\n\nsplit⋆ : ∀ {Ξ Δ Γ} → Γ ⧺ (□⋆ Δ) ⁏ ∅ ⊢⋆ Ξ → Γ ⁏ Δ ⊢⋆ Ξ\nsplit⋆ {∅} ∙ = ∙\nsplit⋆ {Ξ , A} (ts , t) = split⋆ ts , split t\n\n\n-- Cut and multicut.\n\ncut : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A → Γ , A ⁏ Δ ⊢ B → Γ ⁏ Δ ⊢ B\ncut t u = app (lam u) t\n\nmcut : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ □ A → Γ ⁏ Δ , A ⊢ B → Γ ⁏ Δ ⊢ B\nmcut t u = app (mlam u) t\n\nmulticut : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ ⊢⋆ Ξ → Ξ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ A\nmulticut {∅} ∙ u = mono⊢ bot⊆ u\nmulticut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t\n\nmmulticut : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ ⊢⋆ □⋆ Ξ → Γ ⁏ Ξ ⊢ A → Γ ⁏ Δ ⊢ A\nmmulticut {∅} ∙ u = mmono⊢ bot⊆ u\nmmulticut {Ξ , B} (ts , t) u = app (mmulticut ts (mlam u)) t\n\n\n-- Transitivity.\n\ntrans⊢⋆₀ : ∀ {Γ″ Γ′ Γ} → Γ ⁏ ∅ ⊢⋆ Γ′ → Γ′ ⁏ ∅ ⊢⋆ Γ″ → Γ ⁏ ∅ ⊢⋆ Γ″\ntrans⊢⋆₀ {∅} ts ∙ = ∙\ntrans⊢⋆₀ {Γ″ , A} ts (us , u) = trans⊢⋆₀ ts us , multicut ts u\n\ntrans⊢⋆ : ∀ {Ξ Γ Γ′ Δ Δ′} → Γ ⁏ Δ ⊢⋆ Γ′ ⧺ (□⋆ Δ′) → Γ′ ⁏ Δ′ ⊢⋆ Ξ → Γ ⁏ Δ ⊢⋆ Ξ\ntrans⊢⋆ ts us = split⋆ (trans⊢⋆₀ (merge⋆ ts) (merge⋆ us))\n\n\n-- Contraction.\n\nccont : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ (A ▻ A ▻ B) ▻ A ▻ B\nccont = lam (lam (app (app v₁ v₀) v₀))\n\ncont : ∀ {A B Γ Δ} → Γ , A , A ⁏ Δ ⊢ B → Γ , A ⁏ Δ ⊢ B\ncont t = det (app ccont (lam (lam t)))\n\nmcont : ∀ {A B Γ Δ} → Γ ⁏ Δ , A , A ⊢ B → Γ ⁏ Δ , A ⊢ B\nmcont t = mdet (app ccont (mlam (mlam t)))\n\n\n-- Exchange, or Schönfinkel’s C combinator.\n\ncexch : ∀ {A B C Γ Δ} → Γ ⁏ Δ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C\ncexch = lam (lam (lam (app (app v₂ v₀) v₁)))\n\nexch : ∀ {A B C Γ Δ} → Γ , A , B ⁏ Δ ⊢ C → Γ , B , A ⁏ Δ ⊢ C\nexch t = det (det (app cexch (lam (lam t))))\n\nmexch : ∀ {A B C Γ Δ} → Γ ⁏ Δ , A , B ⊢ C → Γ ⁏ Δ , B , A ⊢ C\nmexch t = mdet (mdet (app cexch (mlam (mlam t))))\n\n\n-- Composition, or Schönfinkel’s B combinator.\n\nccomp : ∀ {A B C Γ Δ} → Γ ⁏ Δ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C\nccomp = lam (lam (lam (app v₂ (app v₁ v₀))))\n\ncomp : ∀ {A B C Γ Δ} → Γ , B ⁏ Δ ⊢ C → Γ , A ⁏ Δ ⊢ B → Γ , A ⁏ Δ ⊢ C\ncomp t u = det (app (app ccomp (lam t)) (lam u))\n\nmcomp : ∀ {A B C Γ Δ} → Γ ⁏ Δ , B ⊢ □ C → Γ ⁏ Δ , A ⊢ □ B → Γ ⁏ Δ , A ⊢ □ C\nmcomp t u = mdet (app (app ccomp (mlam t)) (mlam u))\n\n\n-- Useful theorems in functional form.\n\ndist : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ □ (A ▻ B) → Γ ⁏ Δ ⊢ □ A → Γ ⁏ Δ ⊢ □ B\ndist t u = app (app cdist t) u\n\nup : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ □ A → Γ ⁏ Δ ⊢ □ □ A\nup t = app cup t\n\ndown : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ □ A → Γ ⁏ Δ ⊢ A\ndown t = app cdown t\n\ndistup : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ □ (□ A ▻ B) → Γ ⁏ Δ ⊢ □ A → Γ ⁏ Δ ⊢ □ B\ndistup t u = dist t (up u)\n\nunbox : ∀ {A C Γ Δ} → Γ ⁏ Δ ⊢ □ A → Γ ⁏ Δ , A ⊢ C → Γ ⁏ Δ ⊢ C\nunbox t u = app (mlam u) t\n\npair : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ B → Γ ⁏ Δ ⊢ A ∧ B\npair t u = app (app cpair t) u\n\nfst : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ∧ B → Γ ⁏ Δ ⊢ A\nfst t = app cfst t\n\nsnd : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ∧ B → Γ ⁏ Δ ⊢ B\nsnd t = app csnd t\n\n\n-- Internalisation, or lifting, and additional theorems.\n\nlift : ∀ {Γ A Δ} → Γ ⁏ Δ ⊢ A → □⋆ Γ ⁏ Δ ⊢ □ A\nlift {∅} t = box t\nlift {Γ , B} t = det (app cdist (lift (lam t)))\n\nhypup : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ▻ B → Γ ⁏ Δ ⊢ □ A ▻ B\nhypup t = lam (app (mono⊢ weak⊆ t) (down v₀))\n\nhypdown : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ □ □ A ▻ B → Γ ⁏ Δ ⊢ □ A ▻ B\nhypdown t = lam (app (mono⊢ weak⊆ t) (up v₀))\n\ncxup : ∀ {Γ A Δ} → Γ ⁏ Δ ⊢ A → □⋆ Γ ⁏ Δ ⊢ A\ncxup {∅} t = t\ncxup {Γ , B} t = det (hypup (cxup (lam t)))\n\ncxdown : ∀ {Γ A Δ} → □⋆ □⋆ Γ ⁏ Δ ⊢ A → □⋆ Γ ⁏ Δ ⊢ A\ncxdown {∅} t = t\ncxdown {Γ , B} t = det (hypdown (cxdown (lam t)))\n\nbox⋆ : ∀ {Ξ Γ Δ} → ∅ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ ⊢⋆ □⋆ Ξ\nbox⋆ {∅} ∙ = ∙\nbox⋆ {Ξ , A} (ts , t) = box⋆ ts , box t\n\nlift⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⋆ Ξ → □⋆ Γ ⁏ Δ ⊢⋆ □⋆ Ξ\nlift⋆ {∅} ∙ = ∙\nlift⋆ {Ξ , A} (ts , t) = lift⋆ ts , lift t\n\nup⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⋆ □⋆ Ξ → Γ ⁏ Δ ⊢⋆ □⋆ □⋆ Ξ\nup⋆ {∅} ∙ = ∙\nup⋆ {Ξ , A} (ts , t) = up⋆ ts , up t\n\ndown⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⋆ □⋆ Ξ → Γ ⁏ Δ ⊢⋆ Ξ\ndown⋆ {∅} ∙ = ∙\ndown⋆ {Ξ , A} (ts , t) = down⋆ ts , down t\n\nmultibox : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ ⊢⋆ □⋆ Ξ → □⋆ Ξ ⁏ ∅ ⊢ A → Γ ⁏ Δ ⊢ □ A\nmultibox ts u = multicut (up⋆ ts) (mmono⊢ bot⊆ (lift u))\n\ndist′ : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ □ (A ▻ B) → Γ ⁏ Δ ⊢ □ A ▻ □ B\ndist′ t = lam (dist (mono⊢ weak⊆ t) v₀)\n\nmpair : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ □ A → Γ ⁏ Δ ⊢ □ B → Γ ⁏ Δ ⊢ □ (A ∧ B)\nmpair t u = dist (dist (box cpair) t) u\n\nmfst : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ □ (A ∧ B) → Γ ⁏ Δ ⊢ □ A\nmfst t = dist (box cfst) t\n\nmsnd : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ □ (A ∧ B) → Γ ⁏ Δ ⊢ □ B\nmsnd t = dist (box csnd) t\n\n\n-- Closure under context concatenation.\n\nconcat : ∀ {A B Γ} Γ′ {Δ} → Γ , A ⁏ Δ ⊢ B → Γ′ ⁏ Δ ⊢ A → Γ ⧺ Γ′ ⁏ Δ ⊢ B\nconcat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)\n\nmconcat : ∀ {A B Γ Δ} Δ′ → Γ ⁏ Δ , A ⊢ B → Γ ⁏ Δ′ ⊢ □ A → Γ ⁏ Δ ⧺ Δ′ ⊢ B\nmconcat Δ′ t u = app (mmono⊢ (weak⊆⧺₁ Δ′) (mlam t)) (mmono⊢ weak⊆⧺₂ u)\n\n\n-- Convertibility.\n\ndata _⋙_ {Γ Δ : Cx Ty} : ∀ {A} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ A → Set where\n refl⋙ : ∀ {A} → {t : Γ ⁏ Δ ⊢ A}\n → t ⋙ t\n\n trans⋙ : ∀ {A} → {t t′ t″ : Γ ⁏ Δ ⊢ A}\n → t ⋙ t′ → t′ ⋙ t″\n → t ⋙ t″\n\n sym⋙ : ∀ {A} → {t t′ : Γ ⁏ Δ ⊢ A}\n → t ⋙ t′\n → t′ ⋙ t\n\n congapp⋙ : ∀ {A B} → {t t′ : Γ ⁏ Δ ⊢ A ▻ B} → {u u′ : Γ ⁏ Δ ⊢ A}\n → t ⋙ t′ → u ⋙ u′\n → app t u ⋙ app t′ u′\n\n congi⋙ : ∀ {A} → {t t′ : Γ ⁏ Δ ⊢ A}\n → t ⋙ t′\n → app ci t ⋙ app ci t′\n\n congk⋙ : ∀ {A B} → {t t′ : Γ ⁏ Δ ⊢ A} → {u u′ : Γ ⁏ Δ ⊢ B}\n → t ⋙ t′ → u ⋙ u′\n → app (app ck t) u ⋙ app (app ck t′) u′\n\n congs⋙ : ∀ {A B C} → {t t′ : Γ ⁏ Δ ⊢ A ▻ B ▻ C} → {u u′ : Γ ⁏ Δ ⊢ A ▻ B} → {v v′ : Γ ⁏ Δ ⊢ A}\n → t ⋙ t′ → u ⋙ u′ → v ⋙ v′\n\n -- NOTE: Rejected by Pfenning and Davies.\n -- congbox⋙ : ∀ {A} → {t t′ : ∅ ⁏ Δ ⊢ A}\n -- → t ⋙ t′\n -- → box {Γ} t ⋙ box {Γ} t′\n\n congdist⋙ : ∀ {A B} → {t t′ : Γ ⁏ Δ ⊢ □ (A ▻ B)} → {u u′ : Γ ⁏ Δ ⊢ □ A}\n → t ⋙ t′ → u ⋙ u′\n → app (app cdist t) u ⋙ app (app cdist t′) u′\n\n congup⋙ : ∀ {A} → {t t′ : Γ ⁏ Δ ⊢ □ A}\n → t ⋙ t′\n → app cup t ⋙ app cup t′\n\n congdown⋙ : ∀ {A} → {t t′ : Γ ⁏ Δ ⊢ □ A}\n → t ⋙ t′\n → app cdown t ⋙ app cdown t′\n\n congpair⋙ : ∀ {A B} → {t t′ : Γ ⁏ Δ ⊢ A} → {u u′ : Γ ⁏ Δ ⊢ B}\n → t ⋙ t′ → u ⋙ u′\n → app (app cpair t) u ⋙ app (app cpair t′) u′\n\n congfst⋙ : ∀ {A B} → {t t′ : Γ ⁏ Δ ⊢ A ∧ B}\n → t ⋙ t′\n → app cfst t ⋙ app cfst t′\n\n congsnd⋙ : ∀ {A B} → {t t′ : Γ ⁏ Δ ⊢ A ∧ B}\n → t ⋙ t′\n → app csnd t ⋙ app csnd t′\n\n -- TODO: Verify this.\n beta▻ₖ⋙ : ∀ {A B} → {t : Γ ⁏ Δ ⊢ A} → {u : Γ ⁏ Δ ⊢ B}\n → app (app ck t) u ⋙ t\n\n -- TODO: Verify this.\n beta▻ₛ⋙ : ∀ {A B C} → {t : Γ ⁏ Δ ⊢ A ▻ B ▻ C} → {u : Γ ⁏ Δ ⊢ A ▻ B} → {v : Γ ⁏ Δ ⊢ A}\n → app (app (app cs t) u) v ⋙ app (app t v) (app u v)\n\n -- TODO: What about eta for ▻? What about beta, eta, and commuting conversions for □?\n\n beta∧₁⋙ : ∀ {A B} → {t : Γ ⁏ Δ ⊢ A} → {u : Γ ⁏ Δ ⊢ B}\n → app cfst (app (app cpair t) u) ⋙ t\n\n beta∧₂⋙ : ∀ {A B} → {t : Γ ⁏ Δ ⊢ A} → {u : Γ ⁏ Δ ⊢ B}\n → app csnd (app (app cpair t) u) ⋙ u\n\n eta∧⋙ : ∀ {A B} → {t : Γ ⁏ Δ ⊢ A ∧ B}\n → t ⋙ app (app cpair (app cfst t)) (app csnd t)\n\n eta⊤⋙ : ∀ {t : Γ ⁏ Δ ⊢ ⊤} → t ⋙ unit\n", "meta": {"hexsha": "ea4ab7f3d38ff72b69c5f02047335c9b20858edc", "size": 13684, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BasicIS4/Syntax/DyadicHilbert.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/Syntax/DyadicHilbert.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/Syntax/DyadicHilbert.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": 29.4913793103, "max_line_length": 98, "alphanum_fraction": 0.3898713826, "num_tokens": 7428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7341195152660688, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.3699273536483896}} {"text": "module OldBasicILP.Syntax.Projection where\n\nopen import Common.UntypedContext public\n\nimport OldBasicILP.UntypedSyntax.ClosedHilbertSequential as CHS\nimport OldBasicILP.UntypedSyntax.ClosedHilbert as CH\n\n\n-- Projection of types and derivations to a form parametrised by a closed, untyped representation of syntax.\n\nmodule ClosedHilbertSequential where\n open import OldBasicILP.Syntax.ClosedHilbertSequential\n\n mutual\n ⌊_⌋ᵀ : Ty → CHS.Ty\n ⌊ α P ⌋ᵀ = CHS.α P\n ⌊ A ▻ B ⌋ᵀ = ⌊ A ⌋ᵀ CHS.▻ ⌊ B ⌋ᵀ\n ⌊ p ⦂ A ⌋ᵀ = ⌊ p ⌋ᴾ CHS.⦂ ⌊ A ⌋ᵀ\n ⌊ A ∧ B ⌋ᵀ = ⌊ A ⌋ᵀ CHS.∧ ⌊ B ⌋ᵀ\n ⌊ ⊤ ⌋ᵀ = CHS.⊤\n\n -- FIXME: WHat is going on here?\n postulate\n ⌊_⌋ᴾ : ∀ {Ξ A} → Proof Ξ A → CHS.Proof\n\n ⌊_⌋ᵀ⋆ : Cx Ty → Cx CHS.Ty\n ⌊ ∅ ⌋ᵀ⋆ = ∅\n ⌊ Γ , A ⌋ᵀ⋆ = ⌊ Γ ⌋ᵀ⋆ , ⌊ A ⌋ᵀ\n\n ⌊_⌋∈ : ∀ {Ξ A} → A ∈ Ξ → ⌊ A ⌋ᵀ ∈ ⌊ Ξ ⌋ᵀ⋆\n ⌊ top ⌋∈ = top\n ⌊ pop i ⌋∈ = pop ⌊ i ⌋∈\n\n ⌊_⌋ᴰ : ∀ {Ξ} → ⊢ᴰ Ξ → CHS.⊢ᴰ ⌊ Ξ ⌋ᵀ⋆\n ⌊ nil ⌋ᴰ = CHS.nil\n ⌊ mp i j d ⌋ᴰ = CHS.mp ⌊ i ⌋∈ ⌊ j ⌋∈ ⌊ d ⌋ᴰ\n ⌊ ci d ⌋ᴰ = CHS.ci ⌊ d ⌋ᴰ\n ⌊ ck d ⌋ᴰ = CHS.ck ⌊ d ⌋ᴰ\n ⌊ cs d ⌋ᴰ = CHS.cs ⌊ d ⌋ᴰ\n ⌊ nec `d d ⌋ᴰ = {!CHS.nec ⌊ `d ⌋ᴰ ⌊ d ⌋ᴰ!}\n ⌊ cdist d ⌋ᴰ = {!CHS.cdist ⌊ d ⌋ᴰ!}\n ⌊ cup d ⌋ᴰ = {!CHS.cup ⌊ d ⌋ᴰ!}\n ⌊ cdown d ⌋ᴰ = CHS.cdown ⌊ d ⌋ᴰ\n ⌊ cpair d ⌋ᴰ = CHS.cpair ⌊ d ⌋ᴰ\n ⌊ cfst d ⌋ᴰ = CHS.cfst ⌊ d ⌋ᴰ\n ⌊ csnd d ⌋ᴰ = CHS.csnd ⌊ d ⌋ᴰ\n ⌊ unit d ⌋ᴰ = CHS.unit ⌊ d ⌋ᴰ\n\n ⌊_⌋ : ∀ {A} → ⊢ A → CHS.⊢ ⌊ A ⌋ᵀ\n ⌊ Ξ , d ⌋ = ⌊ Ξ ⌋ᵀ⋆ , ⌊ d ⌋ᴰ\n\n\n-- Projection of types and derivations to a form parametrised by a closed, untyped representation of syntax.\n\nmodule ClosedHilbert where\n open import OldBasicILP.Syntax.ClosedHilbert\n\n mutual\n ⌊_⌋ᵀ : Ty → CH.Ty\n ⌊ α P ⌋ᵀ = CH.α P\n ⌊ A ▻ B ⌋ᵀ = ⌊ A ⌋ᵀ CH.▻ ⌊ B ⌋ᵀ\n ⌊ p ⦂ A ⌋ᵀ = ⌊ p ⌋ᴾ CH.⦂ ⌊ A ⌋ᵀ\n ⌊ A ∧ B ⌋ᵀ = ⌊ A ⌋ᵀ CH.∧ ⌊ B ⌋ᵀ\n ⌊ ⊤ ⌋ᵀ = CH.⊤\n\n ⌊_⌋ᴾ : ∀ {A} → Proof A → CH.Proof\n ⌊ [ d ] ⌋ᴾ = CH.[ CH.ᴿ⌊ ⌊ d ⌋ ⌋ ]\n\n ⌊_⌋ : ∀ {A} → ⊢ A → CH.⊢ ⌊ A ⌋ᵀ\n ⌊ app d₁ d₂ ⌋ = CH.app ⌊ d₁ ⌋ ⌊ d₂ ⌋\n ⌊ ci ⌋ = CH.ci\n ⌊ ck ⌋ = CH.ck\n ⌊ cs ⌋ = CH.cs\n ⌊ box d ⌋ = CH.box ⌊ d ⌋\n ⌊ cdist ⌋ = CH.cdist\n ⌊ cup ⌋ = CH.cup\n ⌊ cdown ⌋ = CH.cdown\n ⌊ cpair ⌋ = CH.cpair\n ⌊ cfst ⌋ = CH.cfst\n ⌊ csnd ⌋ = CH.csnd\n ⌊ unit ⌋ = CH.unit\n", "meta": {"hexsha": "ae9a7ae9501ded3f173265cd21cbb1aecc8a49a2", "size": 2314, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "OldBasicILP/Syntax/Projection.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": "OldBasicILP/Syntax/Projection.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": "OldBasicILP/Syntax/Projection.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": 28.2195121951, "max_line_length": 108, "alphanum_fraction": 0.4589455488, "num_tokens": 1537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.685949467848392, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.36971525340992933}} {"text": "-- Intuitionistic propositional calculus.\n-- Kripke-style semantics with exploding abstract worlds.\n\nmodule IPC.Semantics.KripkeExploding where\n\nopen import IPC.Syntax.Common public\n\n\n-- Intuitionistic Kripke-CPS models, with exploding worlds.\n\nrecord Model : Set₁ where\n infix 3 _⊪ᵅ_\n field\n World : Set\n\n -- Intuitionistic accessibility; preorder.\n _≤_ : World → World → Set\n refl≤ : ∀ {w} → w ≤ w\n trans≤ : ∀ {w w′ w″} → w ≤ w′ → w′ ≤ w″ → w ≤ w″\n\n -- Strong forcing for atomic propositions; monotonic.\n _⊪ᵅ_ : World → Atom → Set\n mono⊪ᵅ : ∀ {P w w′} → w ≤ w′ → w ⊪ᵅ P → w′ ⊪ᵅ P\n\n -- Exploding.\n _‼_ : World → Ty → Set\n\nopen Model {{…}} public\n\n\n-- Strong forcing and forcing, in a particular world of a particular model.\n\nmodule _ {{_ : Model}} where\n mutual\n infix 3 _⊪_\n _⊪_ : World → Ty → Set\n w ⊪ α P = w ⊪ᵅ P\n w ⊪ A ▻ B = ∀ {w′} → w ≤ w′ → w′ ⊩ A → w′ ⊩ B\n w ⊪ A ∧ B = w ⊩ A × w ⊩ B\n w ⊪ ⊤ = 𝟙\n w ⊪ ⊥ = 𝟘\n w ⊪ A ∨ B = w ⊩ A ⊎ w ⊩ B\n\n infix 3 _⊩_\n _⊩_ : World → Ty → Set\n w ⊩ A = ∀ {C w′} → w ≤ w′ → (∀ {w″} → w′ ≤ w″ → w″ ⊪ A → w″ ‼ C) → w′ ‼ C\n\n infix 3 _⊩⋆_\n _⊩⋆_ : World → Cx Ty → Set\n w ⊩⋆ ∅ = 𝟙\n w ⊩⋆ Ξ , A = w ⊩⋆ Ξ × w ⊩ A\n\n\n-- Monotonicity with respect to intuitionistic accessibility.\n\nmodule _ {{_ : Model}} where\n mutual\n mono⊪ : ∀ {A w w′} → w ≤ w′ → w ⊪ A → w′ ⊪ A\n mono⊪ {α P} ξ s = mono⊪ᵅ ξ s\n mono⊪ {A ▻ B} ξ f = λ ξ′ a → f (trans≤ ξ ξ′) a\n mono⊪ {A ∧ B} ξ (a , b) = mono⊩ {A} ξ a , mono⊩ {B} ξ b\n mono⊪ {⊤} ξ ∙ = ∙\n mono⊪ {⊥} ξ ()\n mono⊪ {A ∨ B} ξ (ι₁ a) = ι₁ (mono⊩ {A} ξ a)\n mono⊪ {A ∨ B} ξ (ι₂ b) = ι₂ (mono⊩ {B} ξ b)\n\n mono⊩ : ∀ {A w w′} → w ≤ w′ → w ⊩ A → w′ ⊩ A\n mono⊩ ξ a = λ ξ′ k′ → a (trans≤ ξ ξ′) k′\n\n mono⊩⋆ : ∀ {Ξ w w′} → w ≤ w′ → w ⊩⋆ Ξ → w′ ⊩⋆ Ξ\n mono⊩⋆ {∅} ξ ∙ = ∙\n mono⊩⋆ {Ξ , A} ξ (γ , a) = mono⊩⋆ {Ξ} ξ γ , mono⊩ {A} ξ a\n\n\n-- Additional useful equipment.\n\nmodule _ {{_ : Model}} where\n _⟪$⟫_ : ∀ {A B w} → w ⊪ A ▻ B → w ⊩ A → w ⊩ B\n s ⟪$⟫ a = s refl≤ a\n\n return : ∀ {A w} → w ⊪ A → w ⊩ A\n return {A} a = λ ξ k → k refl≤ (mono⊪ {A} ξ a)\n\n bind : ∀ {A B w} → w ⊩ A → (∀ {w′} → w ≤ w′ → w′ ⊪ A → w′ ⊩ B) → w ⊩ B\n bind a k = λ ξ k′ → a ξ (λ ξ′ a′ → k (trans≤ ξ ξ′) a′ refl≤ (λ ξ″ a″ → k′ (trans≤ ξ′ ξ″) a″))\n\n\n-- Forcing in a particular world of a particular model, for sequents.\n\nmodule _ {{_ : Model}} where\n infix 3 _⊩_⇒_\n _⊩_⇒_ : World → Cx Ty → Ty → Set\n w ⊩ Γ ⇒ A = w ⊩⋆ Γ → w ⊩ A\n\n infix 3 _⊩_⇒⋆_\n _⊩_⇒⋆_ : World → Cx Ty → Cx Ty → Set\n w ⊩ Γ ⇒⋆ Ξ = w ⊩⋆ Γ → w ⊩⋆ Ξ\n\n\n-- Entailment, or forcing in all worlds of all models, for sequents.\n\ninfix 3 _⊨_\n_⊨_ : Cx Ty → Ty → Set₁\nΓ ⊨ A = ∀ {{_ : Model}} {w : World} → w ⊩ Γ ⇒ A\n\ninfix 3 _⊨⋆_\n_⊨⋆_ : Cx Ty → Cx Ty → Set₁\nΓ ⊨⋆ Ξ = ∀ {{_ : Model}} {w : World} → w ⊩ Γ ⇒⋆ Ξ\n\n\n-- Additional useful equipment, for sequents.\n\nmodule _ {{_ : Model}} where\n lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩ Γ ⇒ A\n lookup top (γ , a) = a\n lookup (pop i) (γ , b) = lookup i γ\n", "meta": {"hexsha": "e7ae3fe3c73474b78405098d589b64b19c143e35", "size": 3017, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "IPC/Semantics/KripkeExploding.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": "IPC/Semantics/KripkeExploding.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": "IPC/Semantics/KripkeExploding.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": 25.7863247863, "max_line_length": 95, "alphanum_fraction": 0.4690089493, "num_tokens": 1541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583250334526, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.36969958573526934}} {"text": "open import Prelude\nopen import core\n\nmodule ground-decidable where\n ground-decidable : (τ : htyp) → (τ ground) + ((τ ground) → ⊥)\n ground-decidable b = Inl GBase\n ground-decidable ⦇-⦈ = Inr (λ ())\n ground-decidable (b ==> b) = Inr (λ ())\n ground-decidable (b ==> ⦇-⦈) = Inr (λ ())\n ground-decidable (b ==> τ' ==> τ'') = Inr (λ ())\n ground-decidable (⦇-⦈ ==> b) = Inr (λ ())\n ground-decidable (⦇-⦈ ==> ⦇-⦈) = Inl GHole\n ground-decidable (⦇-⦈ ==> τ' ==> τ'') = Inr (λ ())\n ground-decidable ((τ ==> τ₁) ==> b) = Inr (λ ())\n ground-decidable ((τ ==> τ₁) ==> ⦇-⦈) = Inr (λ ())\n ground-decidable ((τ ==> τ₁) ==> τ' ==> τ'') = Inr (λ ())\n\n ground-arr-lem : (τ : htyp) → ((τ ground) → ⊥) → (τ ≠ ⦇-⦈) → Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ] ((τ == (τ1 ==> τ2)) × ((τ1 ==> τ2) ≠ (⦇-⦈ ==> ⦇-⦈)))\n ground-arr-lem b ng nh = abort (ng GBase)\n ground-arr-lem ⦇-⦈ ng nh = abort (nh refl)\n ground-arr-lem (τ1 ==> τ2) ng nh = τ1 , τ2 , refl , (λ x → ng (lem' x))\n where\n lem' : ∀{τ1 τ2} → τ1 ==> τ2 == ⦇-⦈ ==> ⦇-⦈ → (τ1 ==> τ2) ground\n lem' refl = GHole\n", "meta": {"hexsha": "5c3d8a0bb6a3c0c3ae976bc71c913c83e53ae12e", "size": 1059, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "ground-decidable.agda", "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_issues_repo_path": "ground-decidable.agda", "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_forks_repo_path": "ground-decidable.agda", "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "avg_line_length": 42.36, "max_line_length": 146, "alphanum_fraction": 0.4796978281, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059774, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3696745698584351}} {"text": "-- {-# OPTIONS -v tc.meta:50 #-}\n-- Andreas 2012-03-27, record pattern unification\nmodule Issue376 where\n\nimport Common.Level\nopen import Common.Equality\nopen import Common.Irrelevance\n\nrecord Sigma (A : Set)(B : A -> Set) : Set where\n constructor _,_\n field\n fst : A\n snd : B fst\nopen Sigma public\n\nrecord Unit : Set where\n constructor unit\n\nbla1 : (A : Set) (a : A) ->\n let X : Unit -> A\n X = _\n in X unit ≡ a\nbla1 A a = refl\n\nbla2 : (A : Set)(B : A -> Set) ->\n let X : Sigma A B -> Sigma A B\n X = _\n in (x : A)(y : B x) -> X (x , y) ≡ (x , y)\nbla2 A B x y = refl\n-- _55 A B (x , y) := (x , y)\n\n-- irrelevant records\nbla3 : (A : Set)(B : A -> Set) ->\n let X : .(z : Sigma A B) -> (C : .(Sigma A B) -> Set) -> (.(z : Sigma A B) -> C z) -> C z\n X = _\n in (x : A)(y : B x)(C : .(Sigma A B) -> Set)(k : .(z : Sigma A B) -> C z) ->\n X (x , y) C k ≡ k (x , y)\nbla3 A B x y C k = refl\n\n-- nested irrelevance\nbla4 : (A : Set) ->\n let A' = Squash (Squash A) in\n let X : .(z : A') -> (C : .A' -> Set) -> (.(z : A') -> C z) -> C z\n X = _\n in (a : A)(C : .A' -> Set)(k : .(z : A') -> C z) ->\n X (squash (squash a)) C k ≡ k (squash (squash a))\nbla4 A a C k = refl\n\n-- projected bound var\nbla5 : (A : Set) (B : A -> Set) ->\n let X : (x : A) (y : B x) -> Sigma A B\n X = _\n in (z : Sigma A B) -> X (fst z) (snd z) ≡ z\nbla5 A B z = refl\n\n-- projected bound var\nbla6 : (A : Set) (B : A -> Set) ->\n let X : A -> A\n X = _\n in (z : Sigma A B) -> X (fst z) ≡ fst z\nbla6 A B z = refl\n", "meta": {"hexsha": "3e8ea42b45c8a88d52c4b887fdb916f99eb1df3d", "size": 1531, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue376.agda", "max_stars_repo_name": "hborum/agda", "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_issues_repo_path": "test/Succeed/Issue376.agda", "max_issues_repo_name": "hborum/agda", "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "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/Succeed/Issue376.agda", "max_forks_repo_name": "hborum/agda", "max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "avg_line_length": 24.6935483871, "max_line_length": 91, "alphanum_fraction": 0.480731548, "num_tokens": 623, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.6442251064863697, "lm_q1q2_score": 0.36957803313002396}} {"text": "------------------------------------------------------------------------\n-- M-types\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --sized-types #-}\n\nopen import Equality\n\nmodule M\n {reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where\n\nopen import Bijection eq as Bijection using (_↔_)\nopen Derived-definitions-and-properties eq\nimport Equivalence eq as Eq\nopen import Function-universe eq hiding (_∘_)\nopen import Function-universe.Size eq\nopen import H-level eq\nopen import H-level.Closure eq\nopen import Prelude\nopen import Prelude.Size\n\n------------------------------------------------------------------------\n-- M-types\n\nmutual\n\n data M {a b} (A : Type a) (B : A → Type b) (i : Size) :\n Type (a ⊔ b) where\n dns : (x : A) (f : B x → M′ A B i) → M A B i\n\n record M′ {a b} (A : Type a) (B : A → Type b) (i : Size) :\n Type (a ⊔ b) where\n coinductive\n field\n force : {j : Size< i} → M A B j\n\nopen M′ public\n\n-- Projections.\n\npɐǝɥ : ∀ {a b i} {A : Type a} {B : A → Type b} →\n M A B i → A\npɐǝɥ (dns x f) = x\n\nlıɐʇ : ∀ {a b i} {j : Size< i} {A : Type a} {B : A → Type b} →\n (x : M A B i) → B (pɐǝɥ x) → M A B j\nlıɐʇ (dns x f) y = force (f y)\n\n------------------------------------------------------------------------\n-- Equality\n\n-- M-types are isomorphic to Σ-types containing M-types (almost).\n\nM-unfolding : ∀ {a b} {i} {A : Type a} {B : A → Type b} →\n M A B i ↔ ∃ λ (x : A) → B x → M′ A B i\nM-unfolding = record\n { surjection = record\n { logical-equivalence = record\n { to = λ { (dns x f) → x , f }\n ; from = uncurry dns\n }\n ; right-inverse-of = refl\n }\n ; left-inverse-of = λ { (dns x f) → refl (dns x f) }\n }\n\nabstract\n\n -- Equality between elements of an M-type can be proved using a pair\n -- of equalities (assuming extensionality and a kind of η law).\n --\n -- Note that, because the equality type former is not sized, this\n -- lemma is perhaps not very useful.\n\n M-≡,≡↔≡ :\n ∀ {a b i} {A : Type a} {B : A → Type b} →\n Extensionality b (a ⊔ b) →\n (∀ {x} {f g : B x → M′ A B i} →\n _≡_ {A = B x → {j : Size< i} → M A B j}\n (force ∘ f) (force ∘ g) ↔\n f ≡ g) →\n ∀ {x y} {f : B x → M′ A B i} {g : B y → M′ A B i} →\n (∃ λ (p : x ≡ y) → ∀ b {j : Size< i} →\n force (f b) {j = j} ≡ force (g (subst B p b))) ↔\n _≡_ {A = M A B i} (dns x f) (dns y g)\n M-≡,≡↔≡ {a} {i = i} {A} {B} ext η {x} {y} {f} {g} =\n (∃ λ (p : x ≡ y) → ∀ b {j : Size< i} →\n force (f b) {j = j} ≡ force (g (subst B p b))) ↝⟨ ∃-cong lemma ⟩\n (∃ λ (p : x ≡ y) → subst (λ x → B x → M′ A B i) p f ≡ g) ↝⟨ Bijection.Σ-≡,≡↔≡ ⟩\n (_≡_ {A = ∃ λ (x : A) → B x → M′ A B i} (x , f) (y , g)) ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ M-unfolding) ⟩□\n (dns x f ≡ dns y g) □\n where\n lemma : (p : x ≡ y) →\n ((b : B x) {j : Size< i} →\n f b .force {j = j} ≡ g (subst B p b) .force) ↔\n (subst (λ x → B x → M′ A B i) p f ≡ g)\n lemma p = elim\n (λ {x y} p → (f : B x → M′ A B i) (g : B y → M′ A B i) →\n (∀ b {j : Size< i} → f b .force {j = j} ≡\n g (subst B p b) .force) ↔\n (subst (λ x → B x → M′ A B i) p f ≡ g))\n (λ x f g →\n (∀ b {j : Size< i} → f b .force {j = j} ≡\n g (subst B (refl x) b) .force) ↝⟨ subst (λ h → (∀ b {j : Size< i} → f b .force ≡ g (h b) .force) ↔\n (∀ b {j : Size< i} → f b .force ≡ g b .force))\n (sym (apply-ext (lower-extensionality lzero a ext)\n (subst-refl B)))\n Bijection.id ⟩\n\n (∀ b {j : Size< i} → f b .force {j = j} ≡ g b .force) ↔⟨ ∀-cong ext (λ _ → implicit-Π-size-≃-Π-size) ⟩\n\n (∀ b (j : Size< i) → f b .force {j = j} ≡ g b .force) ↔⟨ ∀-cong ext (λ _ → Π-size-≃) ⟩\n\n (∀ b (j : Size< i in-type) → f b .force {j = size j} ≡\n g b .force {j = size j}) ↔⟨ ∀-cong ext (λ _ → Eq.extensionality-isomorphism\n (lower-extensionality _ lzero ext)) ⟩\n ((b : B x) → _≡_ {A = (j : Size< i in-type) → M A B (size j)}\n (λ j → f b .force {j = size j})\n (λ j → g b .force {j = size j})) ↔⟨ ∀-cong ext (λ _ → Eq.≃-≡ $ Eq.↔⇒≃ Bijection.implicit-Π↔Π) ⟩\n\n ((b : B x) → _≡_ {A = {j : Size< i in-type} → M A B (size j)}\n (λ {j} → f b .force {j = size j})\n (λ {j} → g b .force {j = size j})) ↔⟨ ∀-cong ext (λ _ → Eq.≃-≡ implicit-Π-size-≃) ⟩\n\n ((b : B x) → _≡_ {A = {j : Size< i} → M A B j}\n (λ { {j} → f b .force {j = j} })\n (λ { {j} → g b .force {j = j} })) ↔⟨ Eq.extensionality-isomorphism ext ⟩\n\n (force ∘ f ≡ force ∘ g) ↝⟨ η ⟩\n\n (f ≡ g) ↝⟨ subst (λ h → (f ≡ g) ↔ (h ≡ g))\n (sym $ subst-refl (λ x' → B x' → M′ A B i) f)\n Bijection.id ⟩□\n (subst (λ x → B x → M′ A B i) (refl x) f ≡ g) □)\n p f g\n\n------------------------------------------------------------------------\n-- Bisimilarity and bisimilarity for bisimilarity\n\n-- Bisimilarity.\n\nmutual\n\n infix 4 [_]_≡M_ [_]_≡M′_\n\n data [_]_≡M_ {a b} {A : Type a} {B : A → Type b}\n (i : Size) (x y : M A B ∞) : Type (a ⊔ b) where\n dns : (p : pɐǝɥ x ≡ pɐǝɥ y) →\n (∀ b → [ i ] lıɐʇ x b ≡M′ lıɐʇ y (subst B p b)) →\n [ i ] x ≡M y\n\n record [_]_≡M′_ {a b} {A : Type a} {B : A → Type b}\n (i : Size) (x y : M A B ∞) : Type (a ⊔ b) where\n coinductive\n field\n force : {j : Size< i} → [ j ] x ≡M y\n\nopen [_]_≡M′_ public\n\n-- Projections.\n\npɐǝɥ≡ :\n ∀ {a b i} {A : Type a} {B : A → Type b} {x y : M A B ∞} →\n [ i ] x ≡M y → pɐǝɥ x ≡ pɐǝɥ y\npɐǝɥ≡ (dns p q) = p\n\nlıɐʇ≡ :\n ∀ {a b i} {A : Type a} {B : A → Type b} {x y : M A B ∞} →\n (p : [ i ] x ≡M y) →\n ∀ b {j : Size< i} → [ j ] lıɐʇ x b ≡M lıɐʇ y (subst B (pɐǝɥ≡ p) b)\nlıɐʇ≡ (dns p q) y = force (q y)\n\n-- Equality implies bisimilarity.\n\n≡⇒≡M : ∀ {a b i} {A : Type a} {B : A → Type b} {x y : M A B ∞} →\n x ≡ y → [ i ] x ≡M y\n≡⇒≡M {i = i} {B = B} {dns x f} {dns y g} p =\n dns (proj₁ q) helper\n where\n q = elim (λ {m m′} m≡m′ →\n ∃ λ (x≡y : pɐǝɥ m ≡ pɐǝɥ m′) →\n ∀ b → lıɐʇ m b ≡ lıɐʇ m′ (subst B x≡y b))\n (λ m → refl (pɐǝɥ m) , λ b →\n lıɐʇ m b ≡⟨ cong (lıɐʇ m) (sym $ subst-refl B _) ⟩∎\n lıɐʇ m (subst B (refl (pɐǝɥ m)) b) ∎)\n p\n\n helper :\n ∀ b →\n [ i ] lıɐʇ (dns x f) b ≡M′ lıɐʇ (dns y g) (subst B (proj₁ q) b)\n force (helper b) = ≡⇒≡M (proj₂ q b)\n\n-- Bisimilarity for the bisimilarity type.\n\nmutual\n\n data [_]_≡≡M_ {a b} {A : Type a} {B : A → Type b} {x y : M A B ∞}\n (i : Size) (p q : [ ∞ ] x ≡M y) : Type (a ⊔ b) where\n dns : (r : pɐǝɥ≡ p ≡ pɐǝɥ≡ q) →\n (∀ b → [ i ] lıɐʇ≡ p b ≡≡M′\n subst (λ p → [ ∞ ] lıɐʇ x b ≡M\n lıɐʇ y (subst B p b))\n (sym r)\n (lıɐʇ≡ q b)) →\n [ i ] p ≡≡M q\n\n record [_]_≡≡M′_ {a b} {A : Type a} {B : A → Type b} {x y : M A B ∞}\n (i : Size) (p q : [ ∞ ] x ≡M y) : Type (a ⊔ b) where\n coinductive\n field\n force : {j : Size< i} → [ j ] p ≡≡M q\n\nopen [_]_≡≡M′_ public\n\n------------------------------------------------------------------------\n-- Closure under various h-levels\n\nabstract\n\n -- If we assume a notion of extensionality (bisimilarity implies\n -- equality) then Contractible is closed under M.\n\n M-closure-contractible :\n ∀ {a b} {A : Type a} {B : A → Type b} →\n ({x y : M A B ∞} → [ ∞ ] x ≡M y → x ≡ y) →\n Contractible A → Contractible (M A B ∞)\n M-closure-contractible {A = A} {B} ext (z , irrA) = (x , ext ∘ irr)\n where\n x : ∀ {i} → M A B i\n x = dns z λ _ → λ { .force → x }\n\n irr : ∀ {i} y → [ i ] x ≡M y\n irr {i} (dns x′ f) = dns (irrA x′) helper\n where\n helper : ∀ y → [ i ] x ≡M′ force (f (subst B (irrA x′) y))\n force (helper _) = irr _\n\n -- The same applies to Is-proposition.\n\n M-closure-propositional :\n ∀ {a b} {A : Type a} {B : A → Type b} →\n ({x y : M A B ∞} → [ ∞ ] x ≡M y → x ≡ y) →\n Is-proposition A → Is-proposition (M A B ∞)\n M-closure-propositional {A = A} {B} ext p =\n λ x y → ext $ irrelevant x y\n where\n irrelevant : ∀ {i} (x y : M A B ∞) → [ i ] x ≡M y\n irrelevant {i} (dns x f) (dns y g) = dns (p x y) helper\n where\n helper :\n (y′ : B x) →\n [ i ] force (f y′) ≡M′ force (g (subst B (p x y) y′))\n force (helper _) = irrelevant _ _\n\n -- If we assume that we have another notion of extensionality, then\n -- Is-set is closed under M.\n\n M-closure-set :\n ∀ {a b} {A : Type a} {B : A → Type b} →\n ({x y : M A B ∞} {p q : x ≡ y} → [ ∞ ] ≡⇒≡M p ≡≡M ≡⇒≡M q → p ≡ q) →\n Is-set A → Is-set (M A B ∞)\n M-closure-set {A = A} {B} ext s =\n λ p q → ext $ uip (≡⇒≡M p) (≡⇒≡M q)\n where\n uip : ∀ {i} {x y : M A B ∞} (p q : [ ∞ ] x ≡M y) → [ i ] p ≡≡M q\n uip {i} {x} {y} (dns p f) (dns q g) = dns (s p q) helper\n where\n helper :\n (b : B (pɐǝɥ x)) →\n [ i ] force (f b) ≡≡M′\n subst (λ eq → [ ∞ ] lıɐʇ x b ≡M lıɐʇ y (subst B eq b))\n (sym (s p q))\n (force (g b))\n force (helper _) = uip _ _\n", "meta": {"hexsha": "189b4fb2aeabf0ad7fcda56f7107fe1841b0f6a6", "size": 10168, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/M.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/M.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/M.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": 36.9745454545, "max_line_length": 139, "alphanum_fraction": 0.3800157356, "num_tokens": 3936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6619228625116081, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.36956940230797347}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\n\n-- TODO Is it possible to have a more generic [→-group] construction?\n\nmodule groups.ToOmega where\n\n⊙→Ω-group-structure : ∀ {i j} (X : Ptd i) (Y : Ptd j)\n → GroupStructure (X ⊙→ ⊙Ω Y)\n⊙→Ω-group-structure X Y = record {M} where\n module M where\n ident : (X ⊙→ ⊙Ω Y)\n ident = ⊙cst\n\n comp : (X ⊙→ ⊙Ω Y) → (X ⊙→ ⊙Ω Y) → (X ⊙→ ⊙Ω Y)\n comp F G = ⊙Ω-∙ ⊙∘ ⊙fanout F G\n\n inv : (X ⊙→ ⊙Ω Y) → (X ⊙→ ⊙Ω Y)\n inv F = (! ∘ fst F) , ap ! (snd F)\n abstract\n unit-l-lemma : ∀ {i} {A : Type i} {x : A} {p : x == x} (α : p == idp)\n → ⊙∘-pt (fst ⊙Ω-∙) (⊙fanout-pt {a₀ = idp} idp α) idp == α\n unit-l-lemma idp = idp\n\n unit-l : ∀ G → comp ident G == G\n unit-l G = ⊙λ=' (λ _ → idp) (unit-l-lemma (snd G))\n\n assoc-lemma : ∀ {i} {A : Type i} {x : A} {p q r : x == x}\n (α : p == idp) (β : q == idp) (γ : r == idp)\n → ⊙∘-pt (fst ⊙Ω-∙) (⊙fanout-pt (⊙∘-pt (fst ⊙Ω-∙) (⊙fanout-pt α β) idp) γ) idp\n == ⊙∘-pt (fst ⊙Ω-∙) (⊙fanout-pt α (⊙∘-pt (fst ⊙Ω-∙) (⊙fanout-pt β γ) idp)) idp\n [ _== idp ↓ ∙-assoc p q r ]\n assoc-lemma idp idp idp = idp\n\n assoc : ∀ F G H → comp (comp F G) H == comp F (comp G H)\n assoc F G H = ⊙λ='\n (λ x → ∙-assoc (fst F x) (fst G x) (fst H x))\n (assoc-lemma (snd F) (snd G) (snd H))\n\n inv-l-lemma : ∀ {i} {A : Type i} {x : A} {p : x == x} (α : p == idp)\n → ⊙∘-pt (fst ⊙Ω-∙) (⊙fanout-pt (ap ! α) α) idp == idp [ _== idp ↓ !-inv-l p ]\n inv-l-lemma idp = idp\n\n inv-l : ∀ F → comp (inv F) F == ident\n inv-l F = ⊙λ=' (!-inv-l ∘ fst F) (inv-l-lemma (snd F))\n\nTrunc-⊙→Ω-group : ∀ {i j} (X : Ptd i) (Y : Ptd j) → Group (lmax i j)\nTrunc-⊙→Ω-group X Y = Trunc-group (⊙→Ω-group-structure X Y)\n\n{- [Trunc-→Ω-group] is functorial in the first argument -}\n\n⊙→Ω-group-structure-fmap-dom : ∀ {i j k} {X : Ptd i} {Y : Ptd j}\n (f : X ⊙→ Y) (Z : Ptd k)\n → (⊙→Ω-group-structure Y Z →ᴳˢ ⊙→Ω-group-structure X Z)\n⊙→Ω-group-structure-fmap-dom F Z = group-structure-hom (_⊙∘ F)\n (λ g₁ g₂ → ⊙λ= (⊙∘-assoc ⊙Ω-∙ (⊙fanout g₁ g₂) F)\n ∙ ap (⊙Ω-∙ ⊙∘_) (⊙fanout-pre∘ g₁ g₂ F))\n\nTrunc-⊙→Ω-group-fmap-dom : ∀ {i j k} {X : Ptd i} {Y : Ptd j}\n (f : X ⊙→ Y) (Z : Ptd k)\n → (Trunc-⊙→Ω-group Y Z →ᴳ Trunc-⊙→Ω-group X Z)\nTrunc-⊙→Ω-group-fmap-dom F Z =\n Trunc-group-fmap $ ⊙→Ω-group-structure-fmap-dom F Z\n\n⊙→Ω-group-structure-emap-dom : ∀ {i j k} {X : Ptd i} {Y : Ptd j}\n (e : X ⊙≃ Y) (Z : Ptd k)\n → (⊙→Ω-group-structure Y Z ≃ᴳˢ ⊙→Ω-group-structure X Z)\n⊙→Ω-group-structure-emap-dom (F , F-is-equiv) Z =\n ⊙→Ω-group-structure-fmap-dom F Z , pre⊙∘-is-equiv (F , F-is-equiv)\n\nTrunc-⊙→Ω-group-emap-dom : ∀ {i j k} {X : Ptd i} {Y : Ptd j}\n (e : X ⊙≃ Y) (Z : Ptd k)\n → (Trunc-⊙→Ω-group Y Z ≃ᴳ Trunc-⊙→Ω-group X Z)\nTrunc-⊙→Ω-group-emap-dom F Z =\n Trunc-group-emap $ ⊙→Ω-group-structure-emap-dom F Z\n\nTrunc-⊙→Ω-group-fmap-dom-idf : ∀ {i j} {X : Ptd i} (Y : Ptd j)\n → Trunc-⊙→Ω-group-fmap-dom (⊙idf X) Y == idhom (Trunc-⊙→Ω-group X Y)\nTrunc-⊙→Ω-group-fmap-dom-idf Y = group-hom= $ λ= $ Trunc-elim (λ _ → idp)\n\nTrunc-⊙→Ω-group-fmap-dom-∘ : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n (g : Y ⊙→ Z) (f : X ⊙→ Y) (W : Ptd l)\n → Trunc-⊙→Ω-group-fmap-dom (g ⊙∘ f) W\n == Trunc-⊙→Ω-group-fmap-dom f W ∘ᴳ Trunc-⊙→Ω-group-fmap-dom g W\nTrunc-⊙→Ω-group-fmap-dom-∘ g f W = group-hom= $ λ= $\n Trunc-elim (λ h → ap [_] (! (⊙λ= $ ⊙∘-assoc h g f)))\n\n⊙→Ω-group-structure-fmap-codom : ∀ {i j k} (X : Ptd i) {Y : Ptd j} {Z : Ptd k}\n → Y ⊙→ Z → (⊙→Ω-group-structure X Y →ᴳˢ ⊙→Ω-group-structure X Z)\n⊙→Ω-group-structure-fmap-codom X {Y} {Z} F = group-structure-hom\n (⊙Ω-fmap F ⊙∘_)\n (λ G H → ⊙λ=' (λ x → Ω-fmap-∙ F ((fst G) x) ((fst H) x))\n (lemma (snd F) (snd G) (snd H)))\n where\n abstract\n lemma : ∀ {ptZ : de⊙ Z} (α : (fst F) (pt Y) == ptZ)\n {gpt hpt : Ω Y} (β : gpt == idp) (γ : hpt == idp)\n → ⊙∘-pt (Ω-fmap (fst F , α)) (⊙∘-pt (fst ⊙Ω-∙) (⊙fanout-pt β γ) idp) (snd (⊙Ω-fmap (fst F , α)))\n == ⊙∘-pt (fst ⊙Ω-∙)\n (⊙fanout-pt\n (⊙∘-pt (Ω-fmap (fst F , α)) β (snd (⊙Ω-fmap (fst F , α))))\n (⊙∘-pt (Ω-fmap (fst F , α)) γ (snd (⊙Ω-fmap (fst F , α))))\n ) idp\n [ _== idp ↓ Ω-fmap-∙ (fst F , α) gpt hpt ]\n lemma idp idp idp = idp\n\nTrunc-⊙→Ω-group-fmap-codom : ∀ {i j k} (X : Ptd i) {Y : Ptd j} {Z : Ptd k}\n → Y ⊙→ Z → Trunc-⊙→Ω-group X Y →ᴳ Trunc-⊙→Ω-group X Z\nTrunc-⊙→Ω-group-fmap-codom X = Trunc-group-fmap ∘ ⊙→Ω-group-structure-fmap-codom X\n\n⊙→Ω-group-structure-emap-codom : ∀ {i j k} (X : Ptd i) {Y : Ptd j} {Z : Ptd k}\n → Y ⊙≃ Z → ⊙→Ω-group-structure X Y ≃ᴳˢ ⊙→Ω-group-structure X Z\n⊙→Ω-group-structure-emap-codom X (F , F-is-equiv) =\n ⊙→Ω-group-structure-fmap-codom X F , post⊙∘-is-equiv (⊙Ω-emap (F , F-is-equiv))\n\nTrunc-⊙→Ω-group-emap-codom : ∀ {i j k} (X : Ptd i) {Y : Ptd j} {Z : Ptd k}\n → Y ⊙≃ Z → Trunc-⊙→Ω-group X Y ≃ᴳ Trunc-⊙→Ω-group X Z\nTrunc-⊙→Ω-group-emap-codom X = Trunc-group-emap ∘ ⊙→Ω-group-structure-emap-codom X\n\n-- TODO Check naming convensions.\n-- TODO Use [CommSquareᴳ].\nTrunc-⊙→Ω-group-fmap-nat : ∀ {i₀ i₁ j₀ j₁}\n {X₀ : Ptd i₀} {X₁ : Ptd i₁} {Y₀ : Ptd j₀} {Y₁ : Ptd j₁}\n (F : X₀ ⊙→ X₁) (G : Y₀ ⊙→ Y₁)\n → Trunc-⊙→Ω-group-fmap-dom F Y₁ ∘ᴳ Trunc-⊙→Ω-group-fmap-codom X₁ G\n == Trunc-⊙→Ω-group-fmap-codom X₀ G ∘ᴳ Trunc-⊙→Ω-group-fmap-dom F Y₀\nTrunc-⊙→Ω-group-fmap-nat F G = group-hom= $ λ= $ Trunc-elim\n (λ k → ap [_] $ ⊙λ= $ ⊙∘-assoc (⊙Ω-fmap G) k F)\n\n{- Not used.\nTrunc-⊙→Ω-group-emap-nat : ∀ {i₀ i₁ j₀ j₁}\n {X₀ : Ptd i₀} {X₁ : Ptd i₁} {Y₀ : Ptd j₀} {Y₁ : Ptd j₁}\n (F : X₀ ⊙≃ X₁) (G : Y₀ ⊙≃ Y₁)\n → Trunc-⊙→Ω-group-emap-dom F Y₁ ∘ᴳ Trunc-⊙→Ω-group-emap-codom X₁ G\n == Trunc-⊙→Ω-group-emap-codom X₀ G ∘ᴳ Trunc-⊙→Ω-group-emap-dom F Y₀\nTrunc-⊙→Ω-group-emap-nat F G = group-hom=-to-iso= $ Trunc-⊙→Ω-group-fmap-nat F G\n-}\n\n{- Pointed maps out of bool -}\n\nTrunc-⊙Bool→Ω-iso-π₁ : ∀ {i} (X : Ptd i)\n → Trunc-⊙→Ω-group ⊙Bool X ≃ᴳ πS 0 X\nTrunc-⊙Bool→Ω-iso-π₁ {i} X = Trunc-group-emap (≃-to-≃ᴳˢ (⊙Bool→-equiv-idf (⊙Ω X)) (λ _ _ → idp))\n", "meta": {"hexsha": "e93d4af8f94d512bab79a1220e0664d48e63822f", "size": 6065, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/groups/ToOmega.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/groups/ToOmega.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/groups/ToOmega.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": 41.8275862069, "max_line_length": 107, "alphanum_fraction": 0.5079967024, "num_tokens": 3150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7690802370707281, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.3695266556205144}} {"text": "{-# OPTIONS --rewriting --without-K #-}\n\nopen import Agda.Primitive\nopen import Prelude\nopen import GSeTT.Syntax\n\n{- Typing Rules and basic syntactic properties for the type theory for globular sets -}\nmodule GSeTT.Rules where\n {- Well-formedness statements ≡ inference rules -}\n data _⊢C : Pre-Ctx → Set₁\n data _⊢T_ : Pre-Ctx → Pre-Ty → Set₁\n data _⊢t_#_ : Pre-Ctx → Pre-Tm → Pre-Ty → Set₁\n data _⊢S_>_ : Pre-Ctx → Pre-Sub → Pre-Ctx → Set₁\n\n data _⊢C where\n ec : nil ⊢C\n cc : ∀ {Γ x A} → Γ ⊢C → Γ ⊢T A → x == length Γ → (Γ :: (x , A)) ⊢C\n\n data _⊢T_ where\n ob : ∀ {Γ} → Γ ⊢C → Γ ⊢T ∗\n ar : ∀ {Γ A t u} → Γ ⊢t t # A → Γ ⊢t u # A → Γ ⊢T ⇒ A t u\n\n data _⊢t_#_ where\n var : ∀ {Γ x A} → Γ ⊢C → x # A ∈ Γ → Γ ⊢t (Var x) # A\n\n data _⊢S_>_ where\n es : ∀ {Δ} → Δ ⊢C → Δ ⊢S nil > nil\n sc : ∀ {Δ Γ γ x y A t} → Δ ⊢S γ > Γ → (Γ :: (x , A)) ⊢C → (Δ ⊢t t # (A [ γ ]Pre-Ty)) → x == y → Δ ⊢S (γ :: (y , t)) > (Γ :: (x , A))\n\n {- Weakening admissibility -}\n\n wkT : ∀ {Γ A y B} → Γ ⊢T A → (Γ :: (y , B)) ⊢C → (Γ :: (y , B)) ⊢T A\n wkt : ∀ {Γ A t y B} → Γ ⊢t t # A → (Γ :: (y , B)) ⊢C → (Γ :: (y , B)) ⊢t t # A\n\n wkT (ob _) Γ,y:B⊢ = ob Γ,y:B⊢\n wkT (ar Γ⊢t:A Γ⊢u:A) Γ,y:B⊢ = ar (wkt Γ⊢t:A Γ,y:B⊢) (wkt Γ⊢u:A Γ,y:B⊢)\n wkt (var Γ⊢C x∈Γ) Γ,y:B⊢ = var Γ,y:B⊢ (inl x∈Γ)\n\n wkS : ∀ {Δ Γ γ y B} → Δ ⊢S γ > Γ → (Δ :: (y , B)) ⊢C → (Δ :: (y , B)) ⊢S γ > Γ\n wkS (es _) Δ,y:B⊢ = es Δ,y:B⊢\n wkS (sc Δ⊢γ:Γ Γ,x:A⊢ Δ⊢t:A[γ] idp) Δ,y:B⊢ = sc (wkS Δ⊢γ:Γ Δ,y:B⊢) Γ,x:A⊢ (wkt Δ⊢t:A[γ] Δ,y:B⊢) idp\n\n\n {- Consistency : all objects appearing in derivable judgments are derivable -}\n Γ⊢A→Γ⊢ : ∀ {Γ A} → Γ ⊢T A → Γ ⊢C\n Γ⊢t:A→Γ⊢ : ∀ {Γ A t} → Γ ⊢t t # A → Γ ⊢C\n\n Γ⊢A→Γ⊢ (ob Γ⊢) = Γ⊢\n Γ⊢A→Γ⊢ (ar Γ⊢t:A Γ⊢u:A) = Γ⊢t:A→Γ⊢ Γ⊢t:A\n Γ⊢t:A→Γ⊢ (var Γ⊢ _) = Γ⊢\n\n Δ⊢γ:Γ→Γ⊢ : ∀ {Δ Γ γ} → Δ ⊢S γ > Γ → Γ ⊢C\n Δ⊢γ:Γ→Γ⊢ (es Δ⊢) = ec\n Δ⊢γ:Γ→Γ⊢ (sc Δ⊢γ:Γ Γ,x:A⊢ Δ⊢t:A[γ] idp) = Γ,x:A⊢\n\n Δ⊢γ:Γ→Δ⊢ : ∀ {Δ Γ γ} → Δ ⊢S γ > Γ → Δ ⊢C\n Δ⊢γ:Γ→Δ⊢ (es Δ⊢) = Δ⊢\n Δ⊢γ:Γ→Δ⊢ (sc Δ⊢γ:Γ Γ,x:A⊢ Δ⊢t:A[γ] idp) = Δ⊢γ:Γ→Δ⊢ Δ⊢γ:Γ\n\n Γ,x:A⊢→Γ,x:A⊢A : ∀ {Γ x A} → (Γ :: (x , A)) ⊢C → (Γ :: (x , A)) ⊢T A\n Γ,x:A⊢→Γ,x:A⊢A Γ,x:A⊢@(cc Γ⊢ Γ⊢A idp) = wkT Γ⊢A Γ,x:A⊢\n\n Γ,x:A⊢→Γ,x:A⊢x:A : ∀ {Γ x A} → (Γ :: (x , A)) ⊢C → (Γ :: (x , A)) ⊢t (Var x) # A\n Γ,x:A⊢→Γ,x:A⊢x:A Γ,x:A⊢ = var Γ,x:A⊢ (inr (idp , idp))\n\n Γ,x:A⊢→Γ⊢ : ∀ {Γ x A} → (Γ :: (x , A)) ⊢C → Γ ⊢C\n Γ,x:A⊢→Γ⊢ (cc Γ⊢ _ _) = Γ⊢\n\n\n Γ⊢t:A→Γ⊢A : ∀ {Γ A t} → Γ ⊢t t # A → Γ ⊢T A\n Γ⊢t:A→Γ⊢A (var Γ,x:A⊢@(cc Γ⊢ Γ⊢A idp) (inl y∈Γ)) = wkT (Γ⊢t:A→Γ⊢A (var Γ⊢ y∈Γ)) Γ,x:A⊢\n Γ⊢t:A→Γ⊢A (var Γ,x:A⊢@(cc _ _ idp) (inr (idp , idp))) = Γ,x:A⊢→Γ,x:A⊢A Γ,x:A⊢\n\n Γ⊢src : ∀ {Γ A t u} → Γ ⊢T ⇒ A t u → Γ ⊢t t # A\n Γ⊢src (ar Γ⊢t Γ⊢u) = Γ⊢t\n\n Γ⊢tgt : ∀ {Γ A t u} → Γ ⊢T ⇒ A t u → Γ ⊢t u # A\n Γ⊢tgt (ar Γ⊢t Γ⊢u) = Γ⊢u\n\n\n {- Cut-admissibility -}\n -- notational shortcut : if A = B a term of type A is also of type B\n trT : ∀ {Γ A B t} → A == B → Γ ⊢t t # A → Γ ⊢t t # B\n trT idp Γ⊢t:A = Γ⊢t:A\n\n n∉Γ : ∀ {Γ A n} → Γ ⊢C → (length Γ ≤ n) → ¬ (n # A ∈ Γ)\n n∉Γ (cc Γ⊢ _ _) l+1≤n (inl n∈Γ) = n∉Γ Γ⊢ (Sn≤m→n≤m l+1≤n) n∈Γ\n n∉Γ (cc Γ⊢ _ idp) Sn≤n (inr (idp , idp)) = Sn≰n _ Sn≤n\n\n lΓ∉Γ : ∀ {Γ A} → Γ ⊢C → ¬ ((length Γ) # A ∈ Γ)\n lΓ∉Γ Γ⊢ = n∉Γ Γ⊢ (n≤n _)\n\n Γ+⊢l : ∀ {Γ x A} → (Γ :: (x , A)) ⊢C → x == length Γ\n Γ+⊢l (cc _ _ idp) = idp\n\n {- action on weakened types and terms -}\n wk[]T : ∀ {Γ Δ γ x u A B} → Γ ⊢T A → Δ ⊢S (γ :: (x , u)) > (Γ :: (x , B)) → (A [ (γ :: (x , u)) ]Pre-Ty) == (A [ γ ]Pre-Ty)\n wk[]t : ∀ {Γ Δ γ x u A t B} → Γ ⊢t t # A → Δ ⊢S (γ :: (x , u)) > (Γ :: (x , B)) → (t [ (γ :: (x , u)) ]Pre-Tm) == (t [ γ ]Pre-Tm)\n\n wk[]T (ob Γ⊢) _ = idp\n wk[]T (ar Γ⊢t:A Γ⊢u:A) Δ⊢γ+:Γ+ = ⇒= (wk[]T (Γ⊢t:A→Γ⊢A Γ⊢t:A) Δ⊢γ+:Γ+) (wk[]t Γ⊢t:A Δ⊢γ+:Γ+) (wk[]t Γ⊢u:A Δ⊢γ+:Γ+)\n wk[]t {x = x} (var {x = y} Γ⊢ y∈Γ) Δ⊢γ+:Γ+ with (eqdecℕ y x)\n wk[]t {x = x} (var {x = y} Γ⊢ y∈Γ) Δ⊢γ+:Γ+ | inr _ = idp\n wk[]t (var {Γ = Γ} Γ⊢ x∈Γ) Δ⊢γ+:Γ+ | inl idp = ⊥-elim (lΓ∉Γ Γ⊢ (transport {B = λ n → n # _ ∈ Γ} (Γ+⊢l (Δ⊢γ:Γ→Γ⊢ Δ⊢γ+:Γ+)) x∈Γ))\n\n dim[] : ∀ (A : Pre-Ty) (γ : Pre-Sub) → dim (A [ γ ]Pre-Ty) == dim A\n dim[] ∗ γ = idp\n dim[] (⇒ A x x₁) γ = S= (dim[] A γ)\n", "meta": {"hexsha": "1dc933b43e2ab6d8fcd7f4f35c22045a194272d9", "size": 4060, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "GSeTT/Rules.agda", "max_stars_repo_name": "thibautbenjamin/catt-formalization", "max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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": "GSeTT/Rules.agda", "max_issues_repo_name": "thibautbenjamin/catt-formalization", "max_issues_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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": "GSeTT/Rules.agda", "max_forks_repo_name": "thibautbenjamin/catt-formalization", "max_forks_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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.247706422, "max_line_length": 136, "alphanum_fraction": 0.4229064039, "num_tokens": 2680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850402140659, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.36942225202288387}} {"text": "{- Cubical Agda with K\n\nThis file demonstrates the incompatibility of the --cubical\nand --with-K flags, relying on the well-known incosistency of K with\nunivalence.\n\nThe --safe flag can be used to prevent accidentally mixing such\nincompatible flags.\n\n-}\n\n{-# OPTIONS --cubical --no-import-sorts --with-K #-}\n\nmodule Cubical.WithK where\n\nopen import Cubical.Data.Equality\nopen import Cubical.Data.Bool\nopen import Cubical.Data.Empty\n\n\nprivate\n variable\n ℓ : Level\n A : Type ℓ\n x y : A\n\nuip : (prf : x ≡p x) → prf ≡c reflp\nuip reflp i = reflp\n\ntransport-uip : (prf : A ≡p A) → transport (ptoc prf) x ≡c x\ntransport-uip {x = x} prf =\n cong (λ m → transport (ptoc m) x) (uip prf) ∙ transportRefl x\n\ntransport-not : transport (ptoc (ctop notEq)) true ≡c false\ntransport-not = cong (λ a → transport a true) (ptoc-ctop notEq)\n\nfalse-true : false ≡c true\nfalse-true = sym transport-not ∙ transport-uip (ctop notEq)\n\nabsurd : (X : Type) → X\nabsurd X = transport (cong sel false-true) true\n where\n sel : Bool → Type\n sel false = Bool\n sel true = X\n\ninconsistency : ⊥\ninconsistency = absurd ⊥\n", "meta": {"hexsha": "180ca8484684ee5226c5f2d92646f50268782a40", "size": 1096, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/WithK.agda", "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "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": "Cubical/WithK.agda", "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_forks_repo_path": "Cubical/WithK.agda", "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "avg_line_length": 22.3673469388, "max_line_length": 68, "alphanum_fraction": 0.6916058394, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8080672227971211, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.36939719720538766}} {"text": "------------------------------------------------------------------------\n-- The two coinductive definitions of weak bisimilarity are pointwise\n-- logically equivalent\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nopen import Labelled-transition-system\n\nmodule Bisimilarity.Weak.Equivalent {ℓ} {lts : LTS ℓ} where\n\nopen import Equality.Propositional\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude\n\nimport Bisimilarity.Weak lts as Std\nimport Bisimilarity.Weak.Alternative lts as Alt\nimport Bisimilarity.Weak.Alternative.Equational-reasoning-instances\nimport Bisimilarity.Weak.Equational-reasoning-instances\nopen import Equational-reasoning\n\nopen LTS lts\n\nmutual\n\n -- The alternative definition of weak bisimilarity can be converted\n -- to the standard one, in a size-preserving way.\n\n alternative⇒ : ∀ {i p q} → Alt.[ i ] p ≈ q → Std.[ i ] p ≈ q\n alternative⇒ {i} p≈q =\n Std.⟨ lr p≈q\n , Σ-map id (Σ-map id symmetric) ∘ lr (symmetric p≈q)\n ⟩\n where\n lr : ∀ {p p′ q μ} →\n Alt.[ i ] p ≈ q → p [ μ ]⟶ p′ →\n ∃ λ q′ → q [ μ ]⇒̂ q′ × Std.[ i ] p′ ≈′ q′\n lr p≈q p⟶p′ =\n Σ-map id (Σ-map id alternative⇒′)\n (Alt.left-to-right p≈q (⟶→⇒̂ p⟶p′))\n\n alternative⇒′ : ∀ {i p q} → Alt.[ i ] p ≈′ q → Std.[ i ] p ≈′ q\n Std.force (alternative⇒′ p≈′q) = alternative⇒ (Alt.force p≈′q)\n\nmutual\n\n -- One can also convert in the other direction. Note that this\n -- conversion is not guaranteed to be size-preserving. For at least\n -- one LTS it cannot (in general) be size-preserving, see\n -- Bisimilarity.Weak.Delay-monad.size-preserving-⇒alternative⇔uninhabited.\n\n ⇒alternative : ∀ {i p q} → p Std.≈ q → Alt.[ i ] p ≈ q\n ⇒alternative {i} p≈q =\n Alt.⟨ lr p≈q\n , Σ-map id (Σ-map id symmetric) ∘ lr (symmetric p≈q)\n ⟩\n where\n lr : ∀ {p p′ q μ} →\n p Std.≈ q → p [ μ ]⇒̂ p′ →\n ∃ λ q′ → q [ μ ]⇒̂ q′ × Alt.[ i ] p′ ≈′ q′\n lr p≈q p⇒̂p′ =\n Σ-map id (Σ-map id ⇒alternative′) (Std.weak-is-weak⇒̂ p≈q p⇒̂p′)\n\n ⇒alternative′ : ∀ {i p q} → p Std.≈ q → Alt.[ i ] p ≈′ q\n Alt.force (⇒alternative′ p≈q) = ⇒alternative p≈q\n\n-- The two definitions of weak bisimilarity are logically equivalent.\n\nalternative⇔ : ∀ {p q} → p Alt.≈ q ⇔ p Std.≈ q\nalternative⇔ = record\n { to = alternative⇒\n ; from = ⇒alternative\n }\n\n-- TODO: I don't know if the two definitions of weak bisimilarity are\n-- isomorphic.\n", "meta": {"hexsha": "2c8bbaa8436146d758738b3788cf282e9eb658f0", "size": 2451, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Bisimilarity/Weak/Equivalent.agda", "max_stars_repo_name": "nad/up-to", "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Bisimilarity/Weak/Equivalent.agda", "max_issues_repo_name": "nad/up-to", "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Bisimilarity/Weak/Equivalent.agda", "max_forks_repo_name": "nad/up-to", "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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": 31.8311688312, "max_line_length": 76, "alphanum_fraction": 0.5777233782, "num_tokens": 865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.6113819732941511, "lm_q1q2_score": 0.3692330362385316}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Record types with manifest fields and \"with\", based on Randy\n-- Pollack's \"Dependently Typed Records in Type Theory\"\n------------------------------------------------------------------------\n\n-- For an example of how this module can be used, see README.Record.\n\n{-# OPTIONS --without-K --safe #-}\n\nopen import Data.Bool.Base using (if_then_else_)\nopen import Data.Empty\nopen import Data.List.Base\nopen import Data.Product hiding (proj₁; proj₂)\nopen import Data.Unit\nopen import Function\nopen import Level\nopen import Relation.Binary\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Nullary\nopen import Relation.Nullary.Decidable\n\n-- The module is parametrised by the type of labels, which should come\n-- with decidable equality.\n\nmodule Record {ℓ : Level} (Label : Set ℓ) (_≟_ : Decidable (_≡_ {A = Label})) where\n\n------------------------------------------------------------------------\n-- A Σ-type with a manifest field\n\n-- A variant of Σ where the value of the second field is \"manifest\"\n-- (given by the first).\n\ninfix 4 _,\n\nrecord Manifest-Σ {a b} (A : Set a) {B : A → Set b}\n (f : (x : A) → B x) : Set a where\n constructor _,\n field proj₁ : A\n\n proj₂ : B proj₁\n proj₂ = f proj₁\n\n------------------------------------------------------------------------\n-- Signatures and records\n\nmutual\n\n infixl 5 _,_∶_ _,_≔_\n\n data Signature s : Set (suc s ⊔ ℓ) where\n ∅ : Signature s\n _,_∶_ : (Sig : Signature s)\n (ℓ : Label)\n (A : Record Sig → Set s) →\n Signature s\n _,_≔_ : (Sig : Signature s)\n (ℓ : Label)\n {A : Record Sig → Set s}\n (a : (r : Record Sig) → A r) →\n Signature s\n\n -- Record is a record type to ensure that the signature can be\n -- inferred from a value of type Record Sig.\n\n record Record {s} (Sig : Signature s) : Set s where\n eta-equality\n inductive\n constructor rec\n field fun : Record-fun Sig\n\n Record-fun : ∀ {s} → Signature s → Set s\n Record-fun ∅ = Lift _ ⊤\n Record-fun (Sig , ℓ ∶ A) = Σ (Record Sig) A\n Record-fun (Sig , ℓ ≔ a) = Manifest-Σ (Record Sig) a\n\n------------------------------------------------------------------------\n-- Labels\n\n-- A signature's labels, starting with the last one.\n\nlabels : ∀ {s} → Signature s → List Label\nlabels ∅ = []\nlabels (Sig , ℓ ∶ A) = ℓ ∷ labels Sig\nlabels (Sig , ℓ ≔ a) = ℓ ∷ labels Sig\n\n-- Inhabited if the label is part of the signature.\n\ninfix 4 _∈_\n\n_∈_ : ∀ {s} → Label → Signature s → Set\nℓ ∈ Sig =\n foldr (λ ℓ′ → if ⌊ ℓ ≟ ℓ′ ⌋ then (λ _ → ⊤) else id) ⊥ (labels Sig)\n\n------------------------------------------------------------------------\n-- Projections\n\n-- Signature restriction and projection. (Restriction means removal of\n-- a given field and all subsequent fields.)\n\nRestrict : ∀ {s} (Sig : Signature s) (ℓ : Label) → ℓ ∈ Sig →\n Signature s\nRestrict ∅ ℓ ()\nRestrict (Sig , ℓ′ ∶ A) ℓ ℓ∈ with ℓ ≟ ℓ′\n... | yes _ = Sig\n... | no _ = Restrict Sig ℓ ℓ∈\nRestrict (Sig , ℓ′ ≔ a) ℓ ℓ∈ with ℓ ≟ ℓ′\n... | yes _ = Sig\n... | no _ = Restrict Sig ℓ ℓ∈\n\nRestricted : ∀ {s} (Sig : Signature s) (ℓ : Label) → ℓ ∈ Sig → Set s\nRestricted Sig ℓ ℓ∈ = Record (Restrict Sig ℓ ℓ∈)\n\nProj : ∀ {s} (Sig : Signature s) (ℓ : Label) {ℓ∈ : ℓ ∈ Sig} →\n Restricted Sig ℓ ℓ∈ → Set s\nProj ∅ ℓ {}\nProj (Sig , ℓ′ ∶ A) ℓ {ℓ∈} with ℓ ≟ ℓ′\n... | yes _ = A\n... | no _ = Proj Sig ℓ {ℓ∈}\nProj (_,_≔_ Sig ℓ′ {A = A} a) ℓ {ℓ∈} with ℓ ≟ ℓ′\n... | yes _ = A\n... | no _ = Proj Sig ℓ {ℓ∈}\n\n-- Record restriction and projection.\n\ninfixl 5 _∣_\n\n_∣_ : ∀ {s} {Sig : Signature s} → Record Sig →\n (ℓ : Label) {ℓ∈ : ℓ ∈ Sig} → Restricted Sig ℓ ℓ∈\n_∣_ {Sig = ∅} r ℓ {}\n_∣_ {Sig = Sig , ℓ′ ∶ A} (rec r) ℓ {ℓ∈} with ℓ ≟ ℓ′\n... | yes _ = Σ.proj₁ r\n... | no _ = _∣_ (Σ.proj₁ r) ℓ {ℓ∈}\n_∣_ {Sig = Sig , ℓ′ ≔ a} (rec r) ℓ {ℓ∈} with ℓ ≟ ℓ′\n... | yes _ = Manifest-Σ.proj₁ r\n... | no _ = _∣_ (Manifest-Σ.proj₁ r) ℓ {ℓ∈}\n\ninfixl 5 _·_\n\n_·_ : ∀ {s} {Sig : Signature s} (r : Record Sig)\n (ℓ : Label) {ℓ∈ : ℓ ∈ Sig} →\n Proj Sig ℓ {ℓ∈} (r ∣ ℓ)\n_·_ {Sig = ∅} r ℓ {}\n_·_ {Sig = Sig , ℓ′ ∶ A} (rec r) ℓ {ℓ∈} with ℓ ≟ ℓ′\n... | yes _ = Σ.proj₂ r\n... | no _ = _·_ (Σ.proj₁ r) ℓ {ℓ∈}\n_·_ {Sig = Sig , ℓ′ ≔ a} (rec r) ℓ {ℓ∈} with ℓ ≟ ℓ′\n... | yes _ = Manifest-Σ.proj₂ r\n... | no _ = _·_ (Manifest-Σ.proj₁ r) ℓ {ℓ∈}\n\n------------------------------------------------------------------------\n-- With\n\n-- Sig With ℓ ≔ a is the signature Sig, but with the ℓ field set to a.\n\nmutual\n\n infixl 5 _With_≔_\n\n _With_≔_ : ∀ {s} (Sig : Signature s) (ℓ : Label) {ℓ∈ : ℓ ∈ Sig} →\n ((r : Restricted Sig ℓ ℓ∈) → Proj Sig ℓ r) → Signature s\n _With_≔_ ∅ ℓ {} a\n _With_≔_ (Sig , ℓ′ ∶ A) ℓ {ℓ∈} a with ℓ ≟ ℓ′\n ... | yes _ = Sig , ℓ′ ≔ a\n ... | no _ = _With_≔_ Sig ℓ {ℓ∈} a , ℓ′ ∶ A ∘ drop-With\n _With_≔_ (Sig , ℓ′ ≔ a′) ℓ {ℓ∈} a with ℓ ≟ ℓ′\n ... | yes _ = Sig , ℓ′ ≔ a\n ... | no _ = _With_≔_ Sig ℓ {ℓ∈} a , ℓ′ ≔ a′ ∘ drop-With\n\n drop-With : ∀ {s} {Sig : Signature s} {ℓ : Label} {ℓ∈ : ℓ ∈ Sig}\n {a : (r : Restricted Sig ℓ ℓ∈) → Proj Sig ℓ r} →\n Record (_With_≔_ Sig ℓ {ℓ∈} a) → Record Sig\n drop-With {Sig = ∅} {ℓ∈ = ()} r\n drop-With {Sig = Sig , ℓ′ ∶ A} {ℓ} (rec r) with ℓ ≟ ℓ′\n ... | yes _ = rec (Manifest-Σ.proj₁ r , Manifest-Σ.proj₂ r)\n ... | no _ = rec (drop-With (Σ.proj₁ r) , Σ.proj₂ r)\n drop-With {Sig = Sig , ℓ′ ≔ a} {ℓ} (rec r) with ℓ ≟ ℓ′\n ... | yes _ = rec (Manifest-Σ.proj₁ r ,)\n ... | no _ = rec (drop-With (Manifest-Σ.proj₁ r) ,)\n", "meta": {"hexsha": "9252554798a3dcfda3e6b4022af842b7ab18bbaf", "size": 5708, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Record.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": "test/asset/agda-stdlib-1.0/Record.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Record.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": 31.5359116022, "max_line_length": 83, "alphanum_fraction": 0.4922915207, "num_tokens": 2116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804337438502, "lm_q2_score": 0.5964331462646254, "lm_q1q2_score": 0.36906116094483415}} {"text": "open import Prelude\n\nmodule Implicits.Resolution.Finite.Expressiveness where\n\nopen import Coinduction\nopen import Data.Fin.Substitution\nopen import Implicits.Syntax\nopen import Implicits.Substitutions\nopen import Implicits.Resolution.Deterministic.Resolution as D\nopen import Implicits.Resolution.Ambiguous.Resolution as A\nopen import Implicits.Resolution.Finite.Resolution as F\nopen import Implicits.Resolution.Infinite.Resolution as ∞\nopen import Implicits.Resolution.Termination\n\nmodule Finite⊆Infinite where\n\n p : ∀ {ν} {a} {Δ : ICtx ν} → Δ F.⊢ᵣ a → Δ ∞.⊢ᵣ a\n p (r-simp a a↓τ) = r-simp a (lem a↓τ)\n where\n lem : ∀ {ν} {a τ} {Δ : ICtx ν} → Δ F.⊢ a ↓ τ → Δ ∞.⊢ a ↓ τ\n lem (i-simp τ) = i-simp τ\n lem (i-iabs _ ⊢ᵣa b↓τ) = i-iabs (p ⊢ᵣa) (lem b↓τ)\n lem (i-tabs b a[/b]↓τ) = i-tabs b (lem a[/b]↓τ)\n p (r-iabs x) = r-iabs (p x)\n p (r-tabs x) = r-tabs (p x)\n\nmodule Finite⊆Ambiguous where\n\n p : ∀ {ν} {a} {Δ : ICtx ν} → Δ F.⊢ᵣ a → Δ A.⊢ᵣ a\n p (r-simp a a↓τ) = lem a↓τ (r-ivar a)\n where\n lem : ∀ {ν} {a τ} {Δ : ICtx ν} → Δ F.⊢ a ↓ τ → Δ A.⊢ᵣ a → Δ A.⊢ᵣ simpl τ\n lem (i-simp τ) K⊢ᵣτ = K⊢ᵣτ\n lem (i-iabs _ ⊢ᵣa b↓τ) K⊢ᵣa⇒b = lem b↓τ (r-iapp K⊢ᵣa⇒b (p ⊢ᵣa))\n lem (i-tabs b a[/b]↓τ) K⊢ᵣ∀a = lem a[/b]↓τ (r-tapp b K⊢ᵣ∀a)\n p (r-iabs x) = r-iabs (p x)\n p (r-tabs x) = r-tabs (p x)\n\nmodule Deterministic⊆Finite where\n\n open import Extensions.ListFirst\n\n -- Oliveira's termination condition is part of the well-formdness of types\n -- So we assume here that ⊢term x holds for all types x\n p : ∀ {ν} {a : Type ν} {Δ : ICtx ν} → (∀ {ν} (a : Type ν) → ⊢term a) → Δ D.⊢ᵣ a → Δ F.⊢ᵣ a\n p term (r-simp {ρ = r} x r↓a) =\n r-simp (proj₁ $ first⟶∈ x) (lem r↓a)\n where\n lem : ∀ {ν} {Δ : ICtx ν} {a r} → Δ D.⊢ r ↓ a → Δ F.⊢ r ↓ a\n lem (i-simp a) = i-simp a\n lem (i-iabs {ρ₁ = ρ₁} {ρ₂ = ρ₂} ⊢ᵣρ₁ ρ₂↓τ) with term (ρ₁ ⇒ ρ₂)\n lem (i-iabs ⊢ᵣρ₁ ρ₂↓τ) | term-iabs _ _ a-ρ<-b _ = i-iabs a-ρ<-b (p term ⊢ᵣρ₁) (lem ρ₂↓τ)\n lem (i-tabs b x₁) = i-tabs b (lem x₁)\n p term (r-iabs ρ₁ {ρ₂ = ρ₂} x) = r-iabs (p term x)\n p term (r-tabs x) = r-tabs (p term x)\n", "meta": {"hexsha": "59d9e95076388ea3e5bc8c654e9d9c395d0fbcf3", "size": 2105, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Implicits/Resolution/Finite/Expressiveness.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/Finite/Expressiveness.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/Finite/Expressiveness.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": 37.5892857143, "max_line_length": 94, "alphanum_fraction": 0.5814726841, "num_tokens": 1004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804337438502, "lm_q2_score": 0.5964331462646254, "lm_q1q2_score": 0.36906116094483415}} {"text": "------------------------------------------------------------------------\n-- A variant of set quotients with erased higher constructors\n------------------------------------------------------------------------\n\n-- This module contains some basic definitions with few dependencies\n-- (in particular, not Quotient). See Quotient.Erased for more\n-- definitions. The definitions below are reexported from\n-- Quotient.Erased.\n\n{-# OPTIONS --erased-cubical --safe #-}\n\n-- Partly following the HoTT book, but adapted for erasure.\n--\n-- Unlike the HoTT book, but following the cubical library (in which\n-- set quotients were implemented by Zesen Qian and Anders Mörtberg),\n-- the quotienting relations are not (always) required to be\n-- propositional.\n\n-- The module is parametrised by a notion of equality. The higher\n-- constructors of the HIT defining quotients use path equality, but\n-- the supplied notion of equality is used for many other things.\n\nimport Equality.Path as P\n\nmodule Quotient.Erased.Basics\n {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where\n\nopen P.Derived-definitions-and-properties eq hiding (elim)\n\nopen import Prelude\n\nopen import Bijection equality-with-J using (_↔_)\nopen import Equality.Path.Isomorphisms eq\nopen import Function-universe equality-with-J hiding (_∘_)\nopen import H-level equality-with-J\nimport H-level P.equality-with-J as PH\nopen import H-level.Closure equality-with-J\n\nprivate\n variable\n a b p r : Level\n A B : Type a\n R : A → A → Type r\n x y : A\n\n------------------------------------------------------------------------\n-- Quotients\n\n-- The quotient type constructor.\n\ninfix 5 _/ᴱ_\n\ndata _/ᴱ_ (A : Type a) (@0 R : A → A → Type r) : Type (a ⊔ r) where\n [_] : A → A /ᴱ R\n @0 []-respects-relationᴾ : {x y : A} → R x y → [ x ] P.≡ [ y ]\n @0 /ᴱ-is-setᴾ : P.Is-set (A /ᴱ R)\n\n-- [_] respects the quotient relation (in erased contexts).\n\n@0 []-respects-relation : R x y → _≡_ {A = A /ᴱ R} [ x ] [ y ]\n[]-respects-relation = _↔_.from ≡↔≡ ∘ []-respects-relationᴾ\n\n-- Quotients are sets (in erased contexts).\n\n@0 /ᴱ-is-set : Is-set (A /ᴱ R)\n/ᴱ-is-set = _↔_.from (H-level↔H-level 2) /ᴱ-is-setᴾ\n\n------------------------------------------------------------------------\n-- Eliminators\n\n-- An eliminator, expressed using paths.\n\nrecord Elimᴾ′ {A : Type a} {@0 R : A → A → Type r}\n (P : A /ᴱ R → Type p) :\n Type (a ⊔ r ⊔ p) where\n no-eta-equality\n field\n []ʳ : ∀ x → P [ x ]\n\n @0 []-respects-relationʳ :\n (r : R x y) →\n P.[ (λ i → P ([]-respects-relationᴾ r i)) ] []ʳ x ≡ []ʳ y\n\n @0 is-setʳ :\n {eq₁ eq₂ : x P.≡ y} {p : P x} {q : P y}\n (eq₃ : P.[ (λ i → P (eq₁ i)) ] p ≡ q)\n (eq₄ : P.[ (λ i → P (eq₂ i)) ] p ≡ q) →\n P.[ (λ i → P.[ (λ j → P (/ᴱ-is-setᴾ eq₁ eq₂ i j)) ] p ≡ q) ]\n eq₃ ≡ eq₄\n\nopen Elimᴾ′ public\n\nelimᴾ′ :\n {@0 R : A → A → Type r}\n {P : A /ᴱ R → Type p} →\n Elimᴾ′ P → (x : A /ᴱ R) → P x\nelimᴾ′ {A = A} {R = R} {P = P} e = helper\n where\n module E = Elimᴾ′ e\n\n helper : (x : A /ᴱ R) → P x\n helper [ x ] = E.[]ʳ x\n helper ([]-respects-relationᴾ r i) = E.[]-respects-relationʳ r i\n helper (/ᴱ-is-setᴾ p q i j) =\n E.is-setʳ (λ i → helper (p i)) (λ i → helper (q i)) i j\n\n-- A possibly more useful eliminator, expressed using paths.\n\nrecord Elimᴾ {A : Type a} {@0 R : A → A → Type r}\n (P : A /ᴱ R → Type p) :\n Type (a ⊔ r ⊔ p) where\n no-eta-equality\n field\n []ʳ : ∀ x → P [ x ]\n\n @0 []-respects-relationʳ :\n (r : R x y) →\n P.[ (λ i → P ([]-respects-relationᴾ r i)) ] []ʳ x ≡ []ʳ y\n\n @0 is-setʳ : ∀ x → P.Is-set (P x)\n\nopen Elimᴾ public\n\nelimᴾ :\n {@0 R : A → A → Type r}\n {P : A /ᴱ R → Type p} →\n Elimᴾ P → (x : A /ᴱ R) → P x\nelimᴾ e = elimᴾ′ λ where\n .[]ʳ → E.[]ʳ\n .[]-respects-relationʳ → E.[]-respects-relationʳ\n .is-setʳ → P.heterogeneous-UIP E.is-setʳ _\n where\n module E = Elimᴾ e\n\nprivate\n\n -- One can define elimᴾ′ using elimᴾ.\n\n elimᴾ′₂ :\n {@0 R : A → A → Type r}\n {P : A /ᴱ R → Type p} →\n Elimᴾ′ P → (x : A /ᴱ R) → P x\n elimᴾ′₂ {P = P} e = elimᴾ λ where\n .[]ʳ → E.[]ʳ\n .[]-respects-relationʳ → E.[]-respects-relationʳ\n .is-setʳ x {y} {z} p q → $⟨ E.is-setʳ p q ⟩\n P.[ (λ i →\n P.[ (λ j → P (/ᴱ-is-setᴾ P.refl P.refl i j)) ] y ≡ z) ]\n p ≡ q ↝⟨ P.subst (λ eq → P.[ (λ i → P.[ (λ j → P (eq i j)) ] y ≡ z) ] p ≡ q)\n (PH.mono₁ 2 /ᴱ-is-setᴾ _ _) ⟩\n P.[ (λ _ → P.[ (λ _ → P x) ] y ≡ z) ] p ≡ q ↔⟨⟩\n\n p P.≡ q □\n where\n module E = Elimᴾ′ e\n\n-- A non-dependent eliminator, expressed using paths.\n\nrecord Recᴾ {A : Type a} (@0 R : A → A → Type r) (B : Type b) :\n Type (a ⊔ r ⊔ b) where\n no-eta-equality\n field\n []ʳ : A → B\n @0 []-respects-relationʳ : (r : R x y) → []ʳ x P.≡ []ʳ y\n @0 is-setʳ : P.Is-set B\n\nopen Recᴾ public\n\nrecᴾ :\n {@0 R : A → A → Type r} →\n Recᴾ R B → A /ᴱ R → B\nrecᴾ r = elimᴾ λ where\n .[]ʳ → R.[]ʳ\n .[]-respects-relationʳ → R.[]-respects-relationʳ\n .is-setʳ _ → R.is-setʳ\n where\n module R = Recᴾ r\n\n-- An eliminator.\n\nrecord Elim {A : Type a} {@0 R : A → A → Type r}\n (P : A /ᴱ R → Type p) :\n Type (a ⊔ r ⊔ p) where\n no-eta-equality\n field\n []ʳ : ∀ x → P [ x ]\n\n @0 []-respects-relationʳ :\n (r : R x y) →\n subst P ([]-respects-relation r) ([]ʳ x) ≡ []ʳ y\n\n @0 is-setʳ : ∀ x → Is-set (P x)\n\nopen Elim public\n\nelim :\n {@0 R : A → A → Type r}\n {P : A /ᴱ R → Type p} →\n Elim P → (x : A /ᴱ R) → P x\nelim e = elimᴾ λ where\n .[]ʳ → E.[]ʳ\n .[]-respects-relationʳ → subst≡→[]≡ ∘ E.[]-respects-relationʳ\n .is-setʳ → _↔_.to (H-level↔H-level 2) ∘ E.is-setʳ\n where\n module E = Elim e\n\n-- A non-dependent eliminator.\n\nrecord Rec {A : Type a} (@0 R : A → A → Type r) (B : Type b) :\n Type (a ⊔ r ⊔ b) where\n no-eta-equality\n field\n []ʳ : A → B\n @0 []-respects-relationʳ : (r : R x y) → []ʳ x ≡ []ʳ y\n @0 is-setʳ : Is-set B\n\nopen Rec public\n\nrec :\n {@0 R : A → A → Type r} →\n Rec R B → A /ᴱ R → B\nrec r = recᴾ λ where\n .[]ʳ → R.[]ʳ\n .[]-respects-relationʳ → _↔_.to ≡↔≡ ∘ R.[]-respects-relationʳ\n .is-setʳ → _↔_.to (H-level↔H-level 2) R.is-setʳ\n where\n module R = Rec r\n\n-- A variant of elim that can be used if the motive composed with [_]\n-- is a family of propositions.\n--\n-- I took the idea for this eliminator from Nicolai Kraus.\n\nrecord Elim-prop\n {A : Type a} {@0 R : A → A → Type r}\n (P : A /ᴱ R → Type p) :\n Type (a ⊔ r ⊔ p) where\n no-eta-equality\n field\n []ʳ : ∀ x → P [ x ]\n @0 is-propositionʳ : ∀ x → Is-proposition (P [ x ])\n\nopen Elim-prop public\n\nelim-prop :\n {@0 R : A → A → Type r}\n {P : A /ᴱ R → Type p} →\n Elim-prop P → (x : A /ᴱ R) → P x\nelim-prop e = elim λ where\n .[]ʳ → E.[]ʳ\n .[]-respects-relationʳ _ → E.is-propositionʳ _ _ _\n .is-setʳ → elim λ @0 where\n .[]ʳ → mono₁ 1 ∘ E.is-propositionʳ\n .[]-respects-relationʳ _ → H-level-propositional ext 2 _ _\n .is-setʳ _ → mono₁ 1 (H-level-propositional ext 2)\n where\n module E = Elim-prop e\n\n-- A variant of rec that can be used if the motive is a proposition.\n\nrecord Rec-prop (A : Type a) (B : Type b) : Type (a ⊔ b) where\n no-eta-equality\n field\n []ʳ : A → B\n @0 is-propositionʳ : Is-proposition B\n\nopen Rec-prop public\n\nrec-prop :\n {@0 R : A → A → Type r} →\n Rec-prop A B → A /ᴱ R → B\nrec-prop r = elim-prop λ where\n .[]ʳ → R.[]ʳ\n .is-propositionʳ _ → R.is-propositionʳ\n where\n module R = Rec-prop r\n", "meta": {"hexsha": "01120f9653f1a417d8ffdadbb21a3f082c6abb8f", "size": 8106, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Quotient/Erased/Basics.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/Quotient/Erased/Basics.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/Quotient/Erased/Basics.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": 29.2635379061, "max_line_length": 142, "alphanum_fraction": 0.4830989391, "num_tokens": 2976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6654105454764747, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.36895049453991247}} {"text": "postulate\n A : Set\n P : A → Set\n p : (a : A) → P a\n\nrecord R : Set where\n field\n a : A\n b : P _\n b = p a\n\ntest : A\ntest = R.b\n", "meta": {"hexsha": "afdc14b918bc4db01678f9a2c7f5a6f5108c28a3", "size": 135, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue3566.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Issue3566.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Issue3566.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 9.6428571429, "max_line_length": 20, "alphanum_fraction": 0.4592592593, "num_tokens": 61, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7154240079185319, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.36888686666917553}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import HoTT\nopen import homotopy.HSpace renaming (HSpaceStructure to HSS)\nopen import homotopy.Freudenthal\nopen import homotopy.IterSuspensionStable\nopen import homotopy.Pi2HSusp\nopen import homotopy.EM1HSpace\n\nmodule homotopy.EilenbergMacLane where\n\n-- EM(G,n) when G is π₁(A,a₀)\nmodule EMImplicit {i} (A : Type i) (cA : is-connected ⟨0⟩ A)\n (gA : has-level ⟨ 1 ⟩ A) (A-H : HSS A)\n (μcoh : HSS.μe- A-H (HSS.e A-H) == HSS.μ-e A-H (HSS.e A-H)) where\n\n private\n a₀ = HSS.e A-H\n X = ⊙[ A , a₀ ]\n\n ⊙EM : (n : ℕ) → Ptd i\n ⊙EM O = ⊙Ω X\n ⊙EM (S n) = ⊙Trunc ⟨ S n ⟩ (⊙Susp^ n X)\n\n module _ (n : ℕ) where\n EM = fst (⊙EM n)\n embase = snd (⊙EM n)\n\n EM-level : (n : ℕ) → has-level ⟨ n ⟩ (fst (⊙EM n))\n EM-level O = gA a₀ a₀\n EM-level (S n) = Trunc-level\n\n EM-conn : (n : ℕ) → is-connected ⟨ n ⟩ (EM (S n))\n EM-conn n = Trunc-preserves-conn ⟨ S n ⟩\n (transport (λ t → is-connected t (fst (⊙Susp^ n X)))\n (nlemma n) (⊙Susp^-conn n cA))\n where nlemma : (n : ℕ) → (n -2) +2+ ⟨0⟩ == ⟨ n ⟩\n nlemma O = idp\n nlemma (S n) = ap S (nlemma n)\n\n {-\n π (S k) (EM (S n)) (embase (S n)) == π k (EM n) (embase n)\n where k > 0 and n = S (S n')\n -}\n module Stable (k n' : ℕ) (tk : k ≠ 0) (tsk : S k ≠ 0)\n (indexing : k ≤ S (S n'))\n where\n\n private\n n : ℕ\n n = S (S n')\n\n lte : ⟨ k ⟩ ≤T ⟨ n ⟩\n lte = ⟨⟩-monotone-≤ $ indexing\n\n kle : k ≤ (S n') *2\n kle = ≤-trans indexing (lemma n')\n where lemma : (n' : ℕ) → S (S n') ≤ (S n') *2\n lemma O = inl idp\n lemma (S n') = ≤-trans (≤-ap-S (lemma n')) (inr ltS)\n\n private\n module SS = Susp^Stable X cA (S n') k tk tsk kle\n\n abstract\n stable : π (S k) tsk (⊙EM (S n))\n == π k tk (⊙EM n)\n stable =\n π (S k) tsk (⊙EM (S n))\n =⟨ π-below-trunc _ tsk _ _ (≤T-ap-S lte) ⟩\n π (S k) tsk (⊙Susp^ n X)\n =⟨ SS.stable ⟩\n π k tk (⊙Susp^ (S n') X)\n =⟨ ! (π-below-trunc _ tk _ _ lte) ⟩\n π k tk (⊙EM n) ∎\n\n module BelowDiagonal where\n\n π₁ : (n : ℕ) (t1 : 1 ≠ 0 )\n → π 1 t1 (⊙EM (S (S n))) == LiftUnit-Group\n π₁ n t1 =\n contr-is-0ᴳ (π 1 t1 (⊙EM (S (S n))))\n (connected-at-level-is-contr\n (raise-level-≤T (≤T-ap-S (≤T-ap-S (-2≤T (n -2))))\n (Trunc-level {n = ⟨0⟩}))\n (Trunc-preserves-conn ⟨0⟩ (path-conn (EM-conn (S n)))))\n\n -- some clutter here arises from the definition of <;\n -- any simple way to avoid this?\n π-below : (k n : ℕ) (tk : k ≠ 0) → (k < n)\n → π k tk (⊙EM n) == LiftUnit-Group\n π-below 0 _ tk lt = ⊥-rec (tk idp)\n π-below 1 .2 tk ltS = π₁ 0 tk\n π-below 1 .3 tk (ltSR ltS) = π₁ 1 tk\n π-below 1 (S (S n)) tk (ltSR (ltSR _)) = π₁ n tk\n π-below (S (S k)) ._ tssk ltS =\n Stable.stable (S k) k (ℕ-S≠O k) tssk (inr ltS)\n ∙ π-below (S k) _ (ℕ-S≠O k) ltS\n π-below (S (S k)) ._ tssk (ltSR ltS) =\n Stable.stable (S k) (S k) (ℕ-S≠O k) tssk (inr (ltSR ltS))\n ∙ π-below (S k) _ (ℕ-S≠O k) (ltSR ltS)\n π-below (S (S k)) ._ tssk (ltSR (ltSR ltS)) =\n Stable.stable (S k) (S (S k)) (ℕ-S≠O k) tssk (inr (ltSR (ltSR ltS)))\n ∙ π-below (S k) _ (ℕ-S≠O k) (ltSR (ltSR ltS))\n π-below (S (S k)) (S (S (S n))) tssk (ltSR (ltSR (ltSR lt))) =\n Stable.stable (S k) n (ℕ-S≠O k) tssk\n (inr (<-cancel-S (ltSR (ltSR (ltSR lt)))))\n ∙ π-below (S k) _ (ℕ-S≠O k) (<-cancel-S (ltSR (ltSR (ltSR lt))))\n\n\n module OnDiagonal where\n\n π₁ : (tn : 1 ≠ O) (t1 : 1 ≠ O)\n → π 1 tn (⊙EM 1) == π 1 t1 X\n π₁ tn t1 =\n π-below-trunc 1 tn ⟨ 1 ⟩ X ≤T-refl\n ∙ ap (λ t → π 1 t X)\n (prop-has-all-paths (Π-level (λ _ → ⊥-is-prop)) tn t1)\n\n private\n module Π₂ = Pi2HSusp A gA cA A-H μcoh\n\n π₂ : (tn : 2 ≠ O) (t1 : 1 ≠ O)\n → π 2 tn (⊙EM 2) == π 1 t1 X\n π₂ tn t1 =\n π-below-trunc 2 tn ⟨ 2 ⟩ (⊙Susp X) ≤T-refl\n ∙ Π₂.π₂-Suspension t1 tn\n\n π-diag : (n : ℕ) (tn : n ≠ 0) (t1 : 1 ≠ O)\n → π n tn (⊙EM n) == π 1 t1 X\n π-diag 0 tn _ = ⊥-rec (tn idp)\n π-diag 1 tn t1 = π₁ tn t1\n π-diag 2 tn t1 = π₂ tn t1\n π-diag (S (S (S n))) tn t1 =\n Stable.stable (S (S n)) n (ℕ-S≠O _) tn ≤-refl\n ∙ π-diag (S (S n)) (ℕ-S≠O _) t1\n\n module AboveDiagonal where\n\n π-above : (k n : ℕ) (tk : k ≠ 0) → (n < k)\n → π k tk (⊙EM n) == LiftUnit-Group\n π-above k n tk lt =\n contr-is-0ᴳ (π k tk (⊙EM n))\n (inhab-prop-is-contr\n [ idp^ k ]\n (Trunc-preserves-level ⟨0⟩ (Ω^-level-in ⟨-1⟩ k _\n (raise-level-≤T (lemma lt) (EM-level n)))))\n where lemma : {k n : ℕ} → n < k → S (S (n -2)) ≤T ((k -2) +2+ ⟨-1⟩)\n lemma ltS = inl (! (+2+-comm _ ⟨-1⟩))\n lemma (ltSR lt) = ≤T-trans (lemma lt) (inr ltS)\n\n module Spectrum where\n\n private\n module Π₂ = Pi2HSusp A gA cA A-H μcoh\n\n spectrum0 : ⊙Ω (⊙EM 1) == ⊙EM 0\n spectrum0 =\n ⊙Ω (⊙EM 1)\n =⟨ ⊙ua (Trunc=-equiv _ _) idp ⟩\n ⊙Trunc ⟨ 0 ⟩ (⊙Ω X)\n =⟨ ⊙ua (unTrunc-equiv _ (gA a₀ a₀)) idp ⟩\n ⊙Ω X ∎\n\n spectrum1 : ⊙Ω (⊙EM 2) == ⊙EM 1\n spectrum1 =\n ⊙Ω (⊙EM 2)\n =⟨ ⊙ua (Trunc=-equiv _ _) idp ⟩\n ⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp X))\n =⟨ Π₂.⊙main-lemma ⟩\n X\n =⟨ ! (⊙ua (unTrunc-equiv _ gA) idp) ⟩\n ⊙EM 1 ∎\n\n private\n nlemma : (n : ℕ) → Path {A = ℕ₋₂} (S ((n -2) +2+ ⟨0⟩)) (S (S (n -1)))\n nlemma O = idp\n nlemma (S n) = ap S (nlemma n)\n\n sconn : (n : ℕ) → is-connected (S (S (n -1))) (fst (⊙Susp^ (S n) X))\n sconn n = transport (λ t → is-connected t (fst (⊙Susp^ (S n) X)))\n (nlemma n) (⊙Susp^-conn (S n) cA)\n\n kle : (n : ℕ) → ⟨ S (S n) ⟩ ≤T S ((n -1) +2+ S (n -1))\n kle O = inl idp\n kle (S n) = ≤T-trans (≤T-ap-S (kle n))\n (≤T-trans (inl (! (+2+-βr (S n -1) (S n -1))))\n (inr ltS))\n\n module FS (n : ℕ) =\n FreudenthalEquiv (n -1) (⟨ S (S n) ⟩) (kle n)\n (fst (⊙Susp^ (S n) X)) (snd (⊙Susp^ (S n) X)) (sconn n)\n\n spectrumSS : (n : ℕ)\n → ⊙Ω (⊙EM (S (S (S n)))) == ⊙EM (S (S n))\n spectrumSS n =\n ⊙Ω (⊙EM (S (S (S n))))\n =⟨ ⊙ua (Trunc=-equiv _ _) idp ⟩\n ⊙Trunc ⟨ S (S n) ⟩ (⊙Ω (⊙Susp^ (S (S n)) X))\n =⟨ ! (FS.⊙path n) ⟩\n ⊙EM (S (S n)) ∎\n\n abstract\n spectrum : (n : ℕ) → ⊙Ω (⊙EM (S n)) == ⊙EM n\n spectrum 0 = spectrum0\n spectrum 1 = spectrum1\n spectrum (S (S n)) = spectrumSS n\n\nmodule EMExplicit {i} (G : Group i) (G-abelian : is-abelian G) where\n module K₁ = EM₁ G\n module HSpace = EM₁HSpace G G-abelian\n open EMImplicit K₁.EM₁ K₁.EM₁-conn K₁.emlevel HSpace.H-EM₁ HSpace.μcoh public\n\n open BelowDiagonal public using (π-below)\n\n π-diag : (n : ℕ) (tn : n ≠ 0) → π n tn (⊙EM n) == G\n π-diag n tn =\n OnDiagonal.π-diag n tn (ℕ-S≠O 0) ∙ K₁.π₁.π₁-iso\n\n open AboveDiagonal public using (π-above)\n open Spectrum public using (spectrum)\n", "meta": {"hexsha": "995d606a761b198ed556a3715ddbdae1cbc6b8c0", "size": 6946, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "homotopy/EilenbergMacLane.agda", "max_stars_repo_name": "danbornside/HoTT-Agda", "max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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": "homotopy/EilenbergMacLane.agda", "max_issues_repo_name": "danbornside/HoTT-Agda", "max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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/EilenbergMacLane.agda", "max_forks_repo_name": "danbornside/HoTT-Agda", "max_forks_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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": 31.2882882883, "max_line_length": 79, "alphanum_fraction": 0.4696228045, "num_tokens": 3116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154239836484143, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.3688868541550195}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import Base\nopen import Homotopy.TruncatedHIT\n\n{-\nThe idea is that if [n : ℕ] and [A : Set i], then [τ n A] is defined by the\nfollowing n-truncated higher inductive type:\n\n module Homotopy.TruncationHIT {i} (n : ℕ) (A : Set i) where\n\n (n)data τ : Set i where\n proj : A → τ\n\nMore explanations on the way this is done can be found in TruncatedHIT.agda.\nThis file contains nothing but stuff that could (should) be autogenerated from\nthe three lines above.\n-}\n\nmodule Homotopy.TruncationHIT {i} (n : ℕ₋₂) (A : Set i) where\n\nprivate\n data #τ : Set i where\n #proj : A → #τ\n\n #top : (f : hSⁿ n → #τ) → #τ\n\nτ : Set i\nτ = #τ\n\nproj : A → τ\nproj = #proj\n\ntop : (f : hSⁿ n → τ) → τ\ntop = #top\n\npostulate -- HIT\n rays : (f : hSⁿ n → τ) (x : hSⁿ n) → top f ≡ f x\n hack-prop : (p : n ≡ ⟨-2⟩) (x y : τ) → (x ≡ y)\n\n#τ-rec : ∀ {j} (P : τ → Set j)\n (proj* : (x : A) → P (proj x))\n {top* : (f : hSⁿ n → τ) (p : (x : hSⁿ n) → P (f x)) → P (top f)}\n {rays* : (f : hSⁿ n → τ) (p : (x : hSⁿ n) → P (f x)) (x : hSⁿ n)\n → transport P (rays f x) (top* f p) ≡ p x}\n {hack-prop* : (p : n ≡ ⟨-2⟩) (x y : τ) (x* : P x) (y* : P y)\n → (transport P (hack-prop p x y) x* ≡ y* )}\n → ((x : τ) → P x)\n#τ-rec P proj* {top*} {rays*} {hack-prop*} (#proj u) = proj* u\n#τ-rec P proj* {top*} {rays*} {hack-prop*} (#top f) =\n top* f (λ x → #τ-rec P proj* {top*} {rays*} {hack-prop*} (f x))\n\n#τ-rec-nondep : ∀ {j} (C : Set j)\n (proj* : A → C)\n {top* : (f : hSⁿ n → τ) (p : hSⁿ n → C) → C}\n {rays* : (f : hSⁿ n → τ) (p : hSⁿ n → C) (x : hSⁿ n) → top* f p ≡ p x}\n {hack-prop* : (p : n ≡ ⟨-2⟩) (x y : τ) (x* y* : C) → x* ≡ y*}\n → (τ → C)\n#τ-rec-nondep C proj* {top*} {rays*} {hack-prop*} (#proj u) = proj* u\n#τ-rec-nondep C proj* {top*} {rays*} {hack-prop*} (#top f) =\n top* f (λ x → #τ-rec-nondep C proj* {top*} {rays*} {hack-prop*} (f x))\n\nprivate\n contr : (n ≡ ⟨-2⟩) → is-contr τ\nabstract\n contr p = inhab-prop-is-contr (top (λ x → abort-nondep (transport hSⁿ p x)))\n (all-paths-is-prop (hack-prop p))\n\n-- Computation rules for [rays] are not needed\n\nτ-rec : ∀ {j} (P : τ → Set j)\n (proj* : (x : A) → P (proj x))\n {hack-prop* : (p : n ≡ ⟨-2⟩) (x y : τ) (x* : P x) (y* : P y)\n → (transport P (hack-prop p x y) x* ≡ y* )}\n (trunc : (x : τ) → is-truncated n (P x))\n → ((x : τ) → P x)\nτ-rec P proj* {hack-prop*} trunc =\n #τ-rec P proj* {x₁} {x₂} {hack-prop*} where\n abstract\n u : (f : hSⁿ n → τ) (p : (x : hSⁿ n) → P (f x))\n → filling-dep n P f (top f , rays f) p\n u = truncated-has-filling-dep τ P n contr (λ f → (top f , rays f))\n\n x₁ : (f : hSⁿ n → τ) (p : (x : hSⁿ n) → P (f x)) → P (top f)\n x₁ = λ f p → π₁ (u f p)\n\n x₂ : (f : hSⁿ n → τ) (p : (x : hSⁿ n) → P (f x)) (x : hSⁿ n)\n → transport P (rays f x) (x₁ f p) ≡ p x\n x₂ = λ f p → π₂ (u f p)\n\nτ-rec-nondep : ∀ {j} (C : Set j)\n (proj* : A → C)\n {hack-prop* : (p : n ≡ ⟨-2⟩) (x y : τ) (x* y* : C) → x* ≡ y*}\n (trunc : is-truncated n C)\n → (τ → C)\nτ-rec-nondep C proj* {hack-prop*} trunc =\n #τ-rec-nondep C proj* {λ _ p → π₁ (u p)}\n {λ _ p → π₂ (u p)} {hack-prop*} where\n u : _\n u = truncated-has-spheres-filled n _ trunc\n\n-- The nth truncation is of h-level [n]\nabstract\n τ-is-truncated : is-truncated n τ\n τ-is-truncated =\n spheres-filled-is-truncated n τ contr (λ f → (top f , rays f))\n", "meta": {"hexsha": "dce14b2fa54b1c2fcd42ca0a6f2e02074b38b5e4", "size": 3372, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "old/Homotopy/TruncationHIT.agda", "max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda", "max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "old/Homotopy/TruncationHIT.agda", "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "old/Homotopy/TruncationHIT.agda", "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 31.5140186916, "max_line_length": 78, "alphanum_fraction": 0.4982206406, "num_tokens": 1473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6992544210587586, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3687284102704965}} {"text": "module Generate where\n\nopen import Data.List\nopen import Data.Fin hiding (_+_)\nopen import Data.Nat\nopen import Data.Product\nopen import Data.Bool\nopen import Function using (_∘_ ; _$_ ; _∋_ ; id ; case_return_of_ ; flip )\nopen import Function.Injection hiding (_∘_)\nopen import Function.Surjection hiding (_∘_)\nopen import Function.Bijection hiding (_∘_)\nopen import Function.LeftInverse hiding (_∘_)\nopen import Relation.Binary using (Setoid ; Decidable)\nopen import Relation.Binary.PropositionalEquality hiding ( [_] )\nopen import Relation.Nullary.Negation\nopen import Relation.Nullary\nopen import Function.Equality using (_⟶_ ; _⟨$⟩_ ; Π )\nopen import Reflection\nopen import Level\n\nopen import Serializer\nopen import Helper.Fin\nopen import Helper.CodeGeneration\n\nopen import Serializer.Bool\nopen import Serializer.Fin\nopen import With hiding (subst) -- ; _+_ ; A)\n\nopen Serializer.Serializer {{...}}\n--open Serializer.Serializer {{Fin 2}}\n\n-------------------------\n-- Generic from/to term's.\n\ndata Test : Set where\n A : Bool -> Test\n B : Bool -> Test\n C : Bool -> Test\n D : Bool -> Test\n\nconSize : (n : Name) -> Term\nconSize n with (definition n)\nconSize n | constructor′ with (type n)\nconSize n | constructor′ | el (lit n₁) (pi (arg i (el s t)) t₂) = def (quote size) [ a1 t ]\nconSize n | constructor′ | el _ _ = quoteTerm 0\nconSize n | _ = quoteTerm 0\n\nsumTerms : List Name -> Term\nsumTerms [] = quoteTerm 0\nsumTerms (x ∷ ls) = def (quote _+_) (a (conSize x) ∷ a (sumTerms ls) ∷ [])\n\ncons`` : (n : Name) -> List (_×_ Name (_×_ (List Name) (List Name)))\ncons`` n = zipWith _,_ (cons n) (zipWith _,_ (inits (cons n)) (drop 1 (tails (cons n))))\n\n\n{-\nfromTest : Test -> Fin 4\nfromTest (A z) = +₁ 2 (2 + 0) (fromBool z)\nfromTest (B z) = +₂ 2 2 (fromBool z)\n\ntoTest : Fin 4 -> Test\ntoTest x = (Helper.Fin.[ (λ z₁ → A (toBool z₁)) , (λ z₁ → B (toBool z₁)) ] (⨁ 2 2 x))\n-}\n\n{-\nfromTest : Test -> Fin 6\nfromTest (A x) = +₁ 4 2 (+₁ 2 2 (from x))\nfromTest (B x) = +₁ 4 2 (+₂ 2 2 (from x))\nfromTest (C x) = +₂ 4 2 (from x)\n\ntoTest : Fin 6 -> Test\ntoTest x = Helper.Fin.[ (\\y -> Helper.Fin.[ (\\z -> A $ to z) , (\\z -> B $ to z) ] (⨁ 2 2 y) ) , (\\y -> C $ to y) ] (⨁ 4 2 x)\n-}\n\ncons` : Name -> List (_×_ Name (_×_ (List Name) (List Name)))\ncons` n = zipWith _,_ (reverse (cons n)) (zipWith _,_ (inits (reverse (cons n))) (Data.List.map reverse (drop 1 (tails (reverse (cons n))))))\n\n{-# TERMINATING #-}\ngenFrom : (n : Name) -> FunctionDef\ngenFrom n = fun-def (t0 $ fun_type) clauses\n where\n fun_type = pi (a ∘ t0 $ def n []) (abs \"_\" (t0 (def (quote Fin) [ a (sumTerms (cons n)) ])))\n \n construct : (_×_ Name (_×_ (List Name) (List Name))) -> Term\n construct (c , [] , []) = (def (quote from) [ a (var 0 []) ])\n construct (c , x ∷ xs , []) = def (quote +₂) ((a (sumTerms (x ∷ xs))) ∷ (a (conSize c)) ∷ (a (construct (c , ([] , [])))) ∷ [])\n construct (c , xs , y ∷ ys) = def (quote +₁) ((a (sumTerms (c ∷ (xs ++ ys)))) ∷ (a (conSize y)) ∷ (a (construct (c , (xs , ys)))) ∷ [])\n \n clauses = Data.List.map (\\{ (c , xs) -> clause [ a $ con c [ a (var \"_\") ] ] (construct (c , xs))}) (cons` n)\n\nunquoteDecl fromTest = genFrom (quote Test)\n\ngenTo : (n : Name) -> FunctionDef\ngenTo n = fun-def (t0 $ fun_type) clauses\n where\n fun_type = pi (a (t0 (def (quote Fin) [ a (sumTerms (cons n)) ]))) (abs \"_\" (t0 $ def n []))\n\n match : List Name -> Term\n match [] = unknown\n match (x ∷ []) = con x [ a (def (quote to) [ a (var 0 []) ]) ]\n match (x ∷ x₁ ∷ cons) = def (quote [_,_])\n ( (a (lam visible (abs \"_\" (match (x₁ ∷ cons))))) -- (a (lam visible (abs \"_\" (con x [ a (def (quote to) [ a (var 0 []) ]) ]))))\n ∷ (a (lam visible (abs \"_\" (con x [ a (def (quote to) [ a (var 0 []) ]) ]))))\n ∷ (a (def (quote ⨁) ((a (sumTerms (x₁ ∷ cons))) ∷ (a (quoteTerm 2)) ∷ (a (var 0 [])) ∷ [])))\n ∷ [])\n\n clauses = [ clause [ a (var \"_\") ] (match (cons n)) ]\n\nunquoteDecl toTest = genTo (quote Test)\n\nmakePresEq : {T : Set} {n : ℕ} -> (T -> (Fin n)) -> setoid T ⟶ setoid (Fin n)\nmakePresEq f = record { _⟨$⟩_ = f ; cong = (\\{ {i} {.i} refl → refl }) }\n\ngenPresEq' : (n : Name) -> Term\ngenPresEq' n = def (quote makePresEq) [ a (def (quote fromTest) []) ] -- [(a (genFrom' n))]\n where\n setoidFrom = def (quote setoid) [(a (def n []))] \n setoidTo = def (quote setoid) [(a (def (quote Fin) [ a (sumTerms (cons n)) ]))]\n fun_type1 = t0 (def (quote _⟶_) ( (a setoidFrom) ∷ (a setoidTo) ∷ []))\n \ngenPresEq : (n : Name) -> FunctionDef\ngenPresEq n = fun-def fun_type1 [(clause [] (genPresEq' n) ) ]\n where\n setoidFrom = def (quote setoid) [(a (def n []))] \n setoidTo = def (quote setoid) [(a (def (quote Fin) [ a (sumTerms (cons n)) ]))] \n fun_type1 = t0 (def (quote _⟶_) ( (a setoidFrom) ∷ (a setoidTo) ∷ []))\n\nunquoteDecl genTest = genPresEq (quote Test)\n\nt2 : {x y : Bool} → fromBool x ≡ fromBool y → x ≡ y\nt2 = Bijective.injective (Bijection.bijective (bijection {Bool}))\n\nbijection' : Term\nbijection' = quoteTerm t2\n\nrefl' : Term\nrefl' = pat-lam [ clause ( (a1 (var \"d1\")) ∷ (a1 (dot)) ∷ ( a (con (quote refl) []) ) ∷ []) (con (quote refl) []) ] []\n\nx₁≡x₂' : Term\nx₁≡x₂' = def (quote _≡_) ((a $ var 1 []) ∷ (a $ var 0 []) ∷ [])\n\n+-eq₁' : Term -> Term\n+-eq₁' t = (def (quote +-eq₁) [ a t ])\n\n+-eq₂' : ℕ -> ℕ -> Term -> Term\n+-eq₂' n1 n2 t = (def (quote +-eq₂) ( a1 (lit (nat n1)) ∷ a1 (lit (nat n2)) ∷ a t ∷ [] ) )\n\n¬+-eq₁' : Term\n¬+-eq₁' = def (quote ¬+-eq₁) []\n\n¬+-eq₂' : Term\n¬+-eq₂' = def (quote ¬+-eq₂) []\n\n_$'_ : Term -> Term -> Term\nx $' y = def (quote _$_) ((a x) ∷ (a y) ∷ [])\n\ncontradiction' : Term -> Term -> Term\ncontradiction' t1 t2 = def (quote contradiction) ( (a t1) ∷ (a t2) ∷ [] )\n\ngenInjective : (n : Name) -> FunctionDef\ngenInjective n = fun-def fun_type1 [ (clause [] ( pat-lam (clauses 0 (var 0 []) (indexed_cons)) [] )) ]\n where\n fun_type1 = t0 (def (quote Injective) [ (a (def (quote genTest) [])) ] )\n\n ncons = (length (cons n))\n indexed_cons = zipWith (_,_) (cons n) ((downFrom (length (cons n))))\n\n clause'' : Name -> Name -> Term -> Clause\n clause'' l r t = clause ( (a1 $ con l [ a (var \"x\") ]) ∷ (a1 $ con r [ a (var \"y\") ]) ∷ (a (var \"p\")) ∷ [] ) t\n\n clause' : ℕ -> Term -> (_×_ Name ℕ) -> (_×_ Name ℕ) -> Clause\n clause' n t (n1 , i1) (n2 , i2) with (Data.Nat.compare i1 i2)\n clause' n t (n1 , i1) (n2 , ._) | less .i1 k = clause'' n1 n2 (contradiction' (t) ¬+-eq₁')\n clause' n t (n1 , ℕ.zero) (n2 , .0) | equal .0 = clause'' n1 n2 (with' x₁≡x₂' (bijection' $' (t)) refl')\n clause' n t (n1 , ℕ.suc i1) (n2 , .(ℕ.suc i1)) | equal .(ℕ.suc i1) = clause'' n1 n2 (with' x₁≡x₂' (bijection' $' (+-eq₂' ((ncons ∸ n ∸ 1) * 2) 2 (t))) refl')\n clause' n t (n1 , ._) (n2 , i2) | greater .i2 k = clause'' n1 n2 (contradiction' (t) ¬+-eq₂')\n \n clauses : ℕ -> Term -> List (_×_ Name ℕ) -> List Clause\n clauses n t [] = []\n clauses n t (x ∷ cs) = (Data.List.map (clause' n t x) (x ∷ cs)) ++ (Data.List.map ((flip (clause' n t)) x) cs) ++ (clauses (ℕ.suc n) (+-eq₁' t) cs) -- Data.List.map clause' c\n \nunquoteDecl testInjective = genInjective (quote Test)\n\nmakePresEqTo : {T : Set} {n : ℕ} -> ((Fin n) -> T) -> setoid (Fin n) ⟶ setoid T\nmakePresEqTo f = record { _⟨$⟩_ = f ; cong = (\\{ {i} {.i} refl → refl }) }\n\ngenPresEqTo' : (n : Name) -> Term\ngenPresEqTo' n = def (quote makePresEqTo) [ a (def (quote toTest) []) ]\n where\n setoidTo = def (quote setoid) [(a (def n []))] \n setoidFrom = def (quote setoid) [(a (def (quote Fin) [ a (sumTerms (cons n)) ]))]\n fun_type1 = t0 (def (quote _⟶_) ( (a setoidFrom) ∷ (a setoidTo) ∷ []))\n\ngenPresEqTo : (n : Name) -> FunctionDef\ngenPresEqTo n = fun-def infer_type [ (clause [] (genPresEqTo' n) ) ]\n \nunquoteDecl genTestTo = genPresEqTo (quote Test)\n\nFin+' : ℕ -> ℕ -> Term\nFin+' n1 n2 = def (quote Fin+) ((a (lit (nat n1))) ∷ (a (lit (nat n2))) ∷ (a $ var 0 []) ∷ [])\n\n⨁' : ℕ -> ℕ -> Term\n⨁' n1 n2 = def (quote ⨁) ((a (lit (nat n1))) ∷ (a (lit (nat n2))) ∷ (a $ var 0 []) ∷ [])\n\nx₂≡x₁' : Term\nx₂≡x₁' = def (quote _≡_) ( (a $ var 0 []) ∷ (a $ var 1 []) ∷ [])\n\nright-inverse-of' : Term\nright-inverse-of' = quoteTerm (Surjective.right-inverse-of (Bijective.surjective (Bijection.bijective (bijection {Bool}))))\n\nfromToBool' : Term\nfromToBool' = (def (quote fromBool) (arg (arg-info visible relevant) (def (quote toBool) (arg (arg-info visible relevant) (var 0 []) ∷ [])) ∷ []))\n\nmatchFin+ : Term -> Term -> Term\nmatchFin+ t1 t2 = pat-lam ((clause ( (a1 (dot)) ∷ (a (con (quote is+₁) [ a $ (var \"u\") ])) ∷ []) t1) ∷ (clause ( (a1 (dot)) ∷ (a (con (quote is+₂) [ a $ (var \"u\") ])) ∷ []) t2) ∷ []) []\n\nstep2 : Term\nstep2 = rewrite'' x₂≡x₁' (quoteTerm fromToBool') (quoteTerm (right-inverse-of' $' var 0 [])) refl'\n\n⨁'' : ℕ -> ℕ -> Term\n⨁'' m1 m2 = With.subst (quoteTerm (⨁' 1337 2)) (lit (nat 1337)) (lit (nat m1))\n\ngenRightInv' : (List Name) -> Term\ngenRightInv' [] = unknown\ngenRightInv' (x ∷ []) = step2\ngenRightInv' (x ∷ x₁ ∷ cons) = with'' (Fin+' l 2) (⨁'' l 2) (matchFin+ (genRightInv' (x₁ ∷ cons)) step2)\n where\n l = (length (x₁ ∷ cons) * 2)\n\nright-inverse-of : genTestTo RightInverseOf genTest\nright-inverse-of x = unquote (genRightInv' (cons (quote Test)))\n\n\n{-\nfrom-bijection : Bijection (setoid Test) (setoid (Fin 6))\nfrom-bijection = record {\n to = genTest\n ; bijective = record {\n injective = testInjective\n ; surjective = record {\n from = genTestTo\n ; right-inverse-of = right-inverse-of\n }\n }\n }\n\ninstance\n serializerTest : Serializer Test\n serializerTest = record {\n size = 6 ;\n from = fromTest ;\n to = toTest ;\n bijection = from-bijection\n }\n-}\n", "meta": {"hexsha": "b9828e112d7c6b75d3989e340951d858a99d0167", "size": 9607, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Generate.agda", "max_stars_repo_name": "mathijsb/generic-in-agda", "max_stars_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2015-06-09T09:59:27.000Z", "max_stars_repo_stars_event_max_datetime": "2016-08-04T16:05:24.000Z", "max_issues_repo_path": "Generate.agda", "max_issues_repo_name": "mathijsb/generic-in-agda", "max_issues_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759", "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": "Generate.agda", "max_forks_repo_name": "mathijsb/generic-in-agda", "max_forks_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759", "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.52734375, "max_line_length": 185, "alphanum_fraction": 0.5629228687, "num_tokens": 3606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6791787121629466, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.36870118554565107}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.Functions.Embedding where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Equiv.Properties\nopen import Cubical.Foundations.Equiv.HalfAdjoint\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Transport\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Path\nopen import Cubical.Foundations.Powerset\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Univalence using (ua; univalence)\nopen import Cubical.Functions.Fibration\n\nopen import Cubical.Data.Sigma\nopen import Cubical.Functions.Fibration\nopen import Cubical.Functions.FunExtEquiv\nopen import Cubical.Relation.Nullary using (Discrete; yes; no)\nopen import Cubical.Structures.Axioms\n\nopen import Cubical.Reflection.StrictEquiv\n\nopen import Cubical.Data.Nat using (ℕ; zero; suc)\nopen import Cubical.Data.Sigma\n\nprivate\n variable\n ℓ ℓ₁ ℓ₂ : Level\n A B : Type ℓ\n f h : A → B\n w x : A\n y z : B\n\n-- Embeddings are generalizations of injections. The usual\n-- definition of injection as:\n--\n-- f x ≡ f y → x ≡ y\n--\n-- is not well-behaved with higher h-levels, while embeddings\n-- are.\nisEmbedding : (A → B) → Type _\nisEmbedding f = ∀ w x → isEquiv {A = w ≡ x} (cong f)\n\nisEmbeddingIsProp : isProp (isEmbedding f)\nisEmbeddingIsProp {f = f} = isPropΠ2 λ _ _ → isPropIsEquiv (cong f)\n\n-- If A and B are h-sets, then injective functions between\n-- them are embeddings.\n--\n-- Note: It doesn't appear to be possible to omit either of\n-- the `isSet` hypotheses.\ninjEmbedding\n : {f : A → B}\n → isSet A → isSet B\n → (∀{w x} → f w ≡ f x → w ≡ x)\n → isEmbedding f\ninjEmbedding {f = f} iSA iSB inj w x\n = isoToIsEquiv (iso (cong f) inj sect retr)\n where\n sect : section (cong f) inj\n sect p = iSB (f w) (f x) _ p\n\n retr : retract (cong f) inj\n retr p = iSA w x _ p\n\n-- If `f` is an embedding, we'd expect the fibers of `f` to be\n-- propositions, like an injective function.\nhasPropFibers : (A → B) → Type _\nhasPropFibers f = ∀ y → isProp (fiber f y)\n\n-- This can be relaxed to having all prop fibers over the image, see [hasPropFibersOfImage→isEmbedding]\nhasPropFibersOfImage : (A → B) → Type _\nhasPropFibersOfImage f = ∀ x → isProp (fiber f (f x))\n\n-- some notation\n_↪_ : Type ℓ₁ → Type ℓ₂ → Type (ℓ-max ℓ₁ ℓ₂)\nA ↪ B = Σ[ f ∈ (A → B) ] isEmbedding f\n\nhasPropFibersIsProp : isProp (hasPropFibers f)\nhasPropFibersIsProp = isPropΠ (λ _ → isPropIsProp)\n\nprivate\n lemma₀ : (p : y ≡ z) → fiber f y ≡ fiber f z\n lemma₀ {f = f} p = λ i → fiber f (p i)\n\n lemma₁ : isEmbedding f → ∀ x → isContr (fiber f (f x))\n lemma₁ {f = f} iE x = value , path\n where\n value : fiber f (f x)\n value = (x , refl)\n\n path : ∀(fi : fiber f (f x)) → value ≡ fi\n path (w , p) i\n = case equiv-proof (iE w x) p of λ\n { ((q , sq) , _)\n → hfill (λ j → λ { (i = i0) → (x , refl)\n ; (i = i1) → (w , sq j)\n })\n (inS (q (~ i) , λ j → f (q (~ i ∨ j))))\n i1\n }\n\nisEmbedding→hasPropFibers : isEmbedding f → hasPropFibers f\nisEmbedding→hasPropFibers iE y (x , p)\n = subst (λ f → isProp f) (lemma₀ p) (isContr→isProp (lemma₁ iE x)) (x , p)\n\nprivate\n fibCong→PathP\n : {f : A → B}\n → (p : f w ≡ f x)\n → (fi : fiber (cong f) p)\n → PathP (λ i → fiber f (p i)) (w , refl) (x , refl)\n fibCong→PathP p (q , r) i = q i , λ j → r j i\n\n PathP→fibCong\n : {f : A → B}\n → (p : f w ≡ f x)\n → (pp : PathP (λ i → fiber f (p i)) (w , refl) (x , refl))\n → fiber (cong f) p\n PathP→fibCong p pp = (λ i → fst (pp i)) , (λ j i → snd (pp i) j)\n\nPathP≡fibCong\n : {f : A → B}\n → (p : f w ≡ f x)\n → PathP (λ i → fiber f (p i)) (w , refl) (x , refl) ≡ fiber (cong f) p\nPathP≡fibCong p\n = isoToPath (iso (PathP→fibCong p) (fibCong→PathP p) (λ _ → refl) (λ _ → refl))\n\nhasPropFibers→isEmbedding : hasPropFibers f → isEmbedding f\nhasPropFibers→isEmbedding {f = f} iP w x .equiv-proof p\n = subst isContr (PathP≡fibCong p) (isProp→isContrPathP (λ i → iP (p i)) fw fx)\n where\n fw : fiber f (f w)\n fw = (w , refl)\n\n fx : fiber f (f x)\n fx = (x , refl)\n\nhasPropFibersOfImage→hasPropFibers : hasPropFibersOfImage f → hasPropFibers f\nhasPropFibersOfImage→hasPropFibers {f = f} fibImg y a b =\n subst (λ y → isProp (fiber f y)) (snd a) (fibImg (fst a)) a b\n\nhasPropFibersOfImage→isEmbedding : hasPropFibersOfImage f → isEmbedding f\nhasPropFibersOfImage→isEmbedding = hasPropFibers→isEmbedding ∘ hasPropFibersOfImage→hasPropFibers\n\nisEmbedding≡hasPropFibers : isEmbedding f ≡ hasPropFibers f\nisEmbedding≡hasPropFibers\n = isoToPath\n (iso isEmbedding→hasPropFibers\n hasPropFibers→isEmbedding\n (λ _ → hasPropFibersIsProp _ _)\n (λ _ → isEmbeddingIsProp _ _))\n\nisEquiv→hasPropFibers : isEquiv f → hasPropFibers f\nisEquiv→hasPropFibers e b = isContr→isProp (equiv-proof e b)\n\nisEquiv→isEmbedding : isEquiv f → isEmbedding f\nisEquiv→isEmbedding e = λ _ _ → congEquiv (_ , e) .snd\n\nEquiv→Embedding : A ≃ B → A ↪ B\nEquiv→Embedding (f , isEquivF) = (f , isEquiv→isEmbedding isEquivF)\n\niso→isEmbedding : ∀ {ℓ} {A B : Type ℓ}\n → (isom : Iso A B)\n -------------------------------\n → isEmbedding (Iso.fun isom)\niso→isEmbedding {A = A} {B} isom = (isEquiv→isEmbedding (equivIsEquiv (isoToEquiv isom)))\n\nisEmbedding→Injection :\n ∀ {ℓ} {A B C : Type ℓ}\n → (a : A → B)\n → (e : isEmbedding a)\n ----------------------\n → ∀ {f g : C → A} →\n ∀ x → (a (f x) ≡ a (g x)) ≡ (f x ≡ g x)\nisEmbedding→Injection a e {f = f} {g} x = sym (ua (cong a , e (f x) (g x)))\n\n-- if `f` has a retract, then `cong f` has, as well. If `B` is a set, then `cong f`\n-- further has a section, making `f` an embedding.\nmodule _ {f : A → B} (retf : hasRetract f) where\n open Σ retf renaming (fst to g ; snd to ϕ)\n\n congRetract : f w ≡ f x → w ≡ x\n congRetract {w = w} {x = x} p = sym (ϕ w) ∙∙ cong g p ∙∙ ϕ x\n\n isRetractCongRetract : retract (cong {x = w} {y = x} f) congRetract\n isRetractCongRetract p = transport (PathP≡doubleCompPathˡ _ _ _ _) (λ i j → ϕ (p j) i)\n\n hasRetract→hasRetractCong : hasRetract (cong {x = w} {y = x} f)\n hasRetract→hasRetractCong = congRetract , isRetractCongRetract\n\n retractableIntoSet→isEmbedding : isSet B → isEmbedding f\n retractableIntoSet→isEmbedding setB w x =\n isoToIsEquiv (iso (cong f) congRetract (λ _ → setB _ _ _ _) (hasRetract→hasRetractCong .snd))\n\nEmbedding-into-Discrete→Discrete : A ↪ B → Discrete B → Discrete A\nEmbedding-into-Discrete→Discrete (f , isEmbeddingF) _≟_ x y with f x ≟ f y\n... | yes p = yes (invIsEq (isEmbeddingF x y) p)\n... | no ¬p = no (¬p ∘ cong f)\n\nEmbedding-into-isProp→isProp : A ↪ B → isProp B → isProp A\nEmbedding-into-isProp→isProp (f , isEmbeddingF) isProp-B x y\n = invIsEq (isEmbeddingF x y) (isProp-B (f x) (f y))\n\nEmbedding-into-isSet→isSet : A ↪ B → isSet B → isSet A\nEmbedding-into-isSet→isSet (f , isEmbeddingF) isSet-B x y p q =\n p ≡⟨ sym (retIsEq isEquiv-cong-f p) ⟩\n cong-f⁻¹ (cong f p) ≡⟨ cong cong-f⁻¹ cong-f-p≡cong-f-q ⟩\n cong-f⁻¹ (cong f q) ≡⟨ retIsEq isEquiv-cong-f q ⟩\n q ∎\n where\n cong-f-p≡cong-f-q = isSet-B (f x) (f y) (cong f p) (cong f q)\n isEquiv-cong-f = isEmbeddingF x y\n cong-f⁻¹ = invIsEq isEquiv-cong-f\n\nEmbedding-into-hLevel→hLevel\n : ∀ n → A ↪ B → isOfHLevel (suc n) B → isOfHLevel (suc n) A\nEmbedding-into-hLevel→hLevel zero = Embedding-into-isProp→isProp\nEmbedding-into-hLevel→hLevel (suc n) (f , isEmbeddingF) Blvl x y\n = isOfHLevelRespectEquiv (suc n) (invEquiv equiv) subLvl\n where\n equiv : (x ≡ y) ≃ (f x ≡ f y)\n equiv .fst = cong f\n equiv .snd = isEmbeddingF x y\n subLvl : isOfHLevel (suc n) (f x ≡ f y)\n subLvl = Blvl (f x) (f y)\n\n-- We now show that the powerset is the subtype classifier\n-- i.e. ℙ X ≃ Σ[A ∈ Type ℓ] (A ↪ X)\nEmbedding→Subset : {X : Type ℓ} → Σ[ A ∈ Type ℓ ] (A ↪ X) → ℙ X\nEmbedding→Subset (_ , f , isEmbeddingF) x = fiber f x , isEmbedding→hasPropFibers isEmbeddingF x\n\nSubset→Embedding : {X : Type ℓ} → ℙ X → Σ[ A ∈ Type ℓ ] (A ↪ X)\nSubset→Embedding {X = X} A = D , fst , Ψ\n where\n D = Σ[ x ∈ X ] x ∈ A\n\n Ψ : isEmbedding fst\n Ψ w x = isEmbeddingFstΣProp (∈-isProp A)\n\nSubset→Embedding→Subset : {X : Type ℓ} → section (Embedding→Subset {ℓ} {X}) (Subset→Embedding {ℓ} {X})\nSubset→Embedding→Subset _ = funExt λ x → Σ≡Prop (λ _ → isPropIsProp) (ua (FiberIso.fiberEquiv _ x))\n\nEmbedding→Subset→Embedding : {X : Type ℓ} → retract (Embedding→Subset {ℓ} {X}) (Subset→Embedding {ℓ} {X})\nEmbedding→Subset→Embedding {ℓ = ℓ} {X = X} (A , f , ψ) =\n cong (equivFun Σ-assoc-≃) (Σ≡Prop (λ _ → isEmbeddingIsProp) (secEq (fibrationEquiv X ℓ) (A , f)))\n\nSubset≃Embedding : {X : Type ℓ} → ℙ X ≃ (Σ[ A ∈ Type ℓ ] (A ↪ X))\nSubset≃Embedding = isoToEquiv (iso Subset→Embedding Embedding→Subset\n Embedding→Subset→Embedding Subset→Embedding→Subset)\n\nSubset≡Embedding : {X : Type ℓ} → ℙ X ≡ (Σ[ A ∈ Type ℓ ] (A ↪ X))\nSubset≡Embedding = ua Subset≃Embedding\n\nisEmbedding-∘ : isEmbedding f → isEmbedding h → isEmbedding (f ∘ h)\nisEmbedding-∘ {f = f} {h = h} Embf Embh w x\n = compEquiv (cong h , Embh w x) (cong f , Embf (h w) (h x)) .snd\n\nisEmbedding→embedsFibersIntoSingl\n : isEmbedding f\n → ∀ z → fiber f z ↪ singl z\nisEmbedding→embedsFibersIntoSingl {f = f} isE z = e , isEmbE where\n e : fiber f z → singl z\n e x = f (fst x) , sym (snd x)\n\n isEmbE : isEmbedding e\n isEmbE u v = goal where\n -- \"adjust\" ΣeqCf by trivial equivalences that hold judgementally, which should save compositions\n Dom′ : ∀ u v → Type _\n Dom′ u v = Σ[ p ∈ fst u ≡ fst v ] PathP (λ i → f (p i) ≡ z) (snd u) (snd v)\n Cod′ : ∀ u v → Type _\n Cod′ u v = Σ[ p ∈ f (fst u) ≡ f (fst v) ] PathP (λ i → p i ≡ z) (snd u) (snd v)\n ΣeqCf : Dom′ u v ≃ Cod′ u v\n ΣeqCf = Σ-cong-equiv-fst (_ , isE _ _)\n\n dom→ : u ≡ v → Dom′ u v\n dom→ p = cong fst p , cong snd p\n dom← : Dom′ u v → u ≡ v\n dom← p i = p .fst i , p .snd i\n\n cod→ : e u ≡ e v → Cod′ u v\n cod→ p = cong fst p , cong (sym ∘ snd) p\n cod← : Cod′ u v → e u ≡ e v\n cod← p i = p .fst i , sym (p .snd i)\n\n goal : isEquiv (cong e)\n goal .equiv-proof x .fst .fst =\n dom← (equivCtr ΣeqCf (cod→ x) .fst)\n goal .equiv-proof x .fst .snd j =\n cod← (equivCtr ΣeqCf (cod→ x) .snd j)\n goal .equiv-proof x .snd (g , p) i .fst =\n dom← (equivCtrPath ΣeqCf (cod→ x) (dom→ g , cong cod→ p) i .fst)\n goal .equiv-proof x .snd (g , p) i .snd j =\n cod← (equivCtrPath ΣeqCf (cod→ x) (dom→ g , cong cod→ p) i .snd j)\n\nisEmbedding→hasPropFibers′ : isEmbedding f → hasPropFibers f\nisEmbedding→hasPropFibers′ {f = f} iE z =\n Embedding-into-isProp→isProp (isEmbedding→embedsFibersIntoSingl iE z) isPropSingl\n\nuniverseEmbedding :\n ∀ {ℓ ℓ₁ : Level}\n → (F : Type ℓ → Type ℓ₁)\n → (∀ X → F X ≃ X)\n → isEmbedding F\nuniverseEmbedding F liftingEquiv = hasPropFibersOfImage→isEmbedding propFibersF where\n lemma : ∀ A B → (F A ≡ F B) ≃ (B ≡ A)\n lemma A B = (F A ≡ F B) ≃⟨ univalence ⟩\n (F A ≃ F B) ≃⟨ equivComp (liftingEquiv A) (liftingEquiv B) ⟩\n (A ≃ B) ≃⟨ invEquivEquiv ⟩\n (B ≃ A) ≃⟨ invEquiv univalence ⟩\n (B ≡ A) ■\n fiberSingl : ∀ X → fiber F (F X) ≃ singl X\n fiberSingl X = Σ-cong-equiv-snd (λ _ → lemma _ _)\n propFibersF : hasPropFibersOfImage F\n propFibersF X = Embedding-into-isProp→isProp (Equiv→Embedding (fiberSingl X)) isPropSingl\n\nliftEmbedding : (ℓ ℓ₁ : Level)\n → isEmbedding (Lift {i = ℓ} {j = ℓ₁})\nliftEmbedding ℓ ℓ₁ = universeEmbedding (Lift {j = ℓ₁}) (λ _ → invEquiv LiftEquiv)\n\nmodule FibrationIdentityPrinciple {B : Type ℓ} {ℓ₁} where\n -- note that fibrationEquiv (for good reason) uses ℓ₁ = ℓ-max ℓ ℓ₁, so we have to work\n -- some universe magic to achieve good universe polymorphism\n\n -- First, prove it for the case that's dealt with in fibrationEquiv\n Fibration′ = Fibration B (ℓ-max ℓ ℓ₁)\n\n module Lifted (f g : Fibration′) where\n f≃g′ : Type (ℓ-max ℓ ℓ₁)\n f≃g′ = ∀ b → fiber (f .snd) b ≃ fiber (g .snd) b\n\n Fibration′IP : f≃g′ ≃ (f ≡ g)\n Fibration′IP =\n f≃g′\n ≃⟨ equivΠCod (λ _ → invEquiv univalence) ⟩\n (∀ b → fiber (f .snd) b ≡ fiber (g .snd) b)\n ≃⟨ funExtEquiv ⟩\n fiber (f .snd) ≡ fiber (g .snd)\n ≃⟨ invEquiv (congEquiv (fibrationEquiv B ℓ₁)) ⟩\n f ≡ g\n ■\n\n -- Then embed into the above case by lifting the type\n L : Type _ → Type _ -- local synonym fixing the levels of Lift\n L = Lift {i = ℓ₁} {j = ℓ}\n\n liftFibration : Fibration B ℓ₁ → Fibration′\n liftFibration (A , f) = L A , f ∘ lower\n\n hasPropFibersLiftFibration : hasPropFibers liftFibration\n hasPropFibersLiftFibration (A , f) =\n Embedding-into-isProp→isProp (Equiv→Embedding fiberChar)\n (isPropΣ (isEmbedding→hasPropFibers (liftEmbedding _ _) A)\n λ _ → isEquiv→hasPropFibers (snd (invEquiv (preCompEquiv LiftEquiv))) _)\n where\n fiberChar : fiber liftFibration (A , f)\n ≃ (Σ[ (E , eq) ∈ fiber L A ] fiber (_∘ lower) (transport⁻ (λ i → eq i → B) f))\n fiberChar =\n fiber liftFibration (A , f)\n ≃⟨ Σ-cong-equiv-snd (λ _ → invEquiv ΣPath≃PathΣ) ⟩\n (Σ[ (E , g) ∈ Fibration B ℓ₁ ] Σ[ eq ∈ (L E ≡ A) ] PathP (λ i → eq i → B) (g ∘ lower) f)\n ≃⟨ boringSwap ⟩\n (Σ[ (E , eq) ∈ fiber L A ] Σ[ g ∈ (E → B) ] PathP (λ i → eq i → B) (g ∘ lower) f)\n ≃⟨ Σ-cong-equiv-snd (λ _ → Σ-cong-equiv-snd λ _ → transportEquiv (PathP≡Path⁻ _ _ _)) ⟩\n (Σ[ (E , eq) ∈ fiber L A ] fiber (_∘ lower) (transport⁻ (λ i → eq i → B) f))\n ■ where\n unquoteDecl boringSwap =\n declStrictEquiv boringSwap\n (λ ((E , g) , (eq , p)) → ((E , eq) , (g , p)))\n (λ ((E , g) , (eq , p)) → ((E , eq) , (g , p)))\n\n isEmbeddingLiftFibration : isEmbedding liftFibration\n isEmbeddingLiftFibration = hasPropFibers→isEmbedding hasPropFibersLiftFibration\n\n -- and finish off\n module _ (f g : Fibration B ℓ₁) where\n open Lifted (liftFibration f) (liftFibration g)\n f≃g : Type (ℓ-max ℓ ℓ₁)\n f≃g = ∀ b → fiber (f .snd) b ≃ fiber (g .snd) b\n\n FibrationIP : f≃g ≃ (f ≡ g)\n FibrationIP =\n f≃g ≃⟨ equivΠCod (λ b → equivComp (Σ-cong-equiv-fst LiftEquiv)\n (Σ-cong-equiv-fst LiftEquiv)) ⟩\n f≃g′ ≃⟨ Fibration′IP ⟩\n (liftFibration f ≡ liftFibration g) ≃⟨ invEquiv (_ , isEmbeddingLiftFibration _ _) ⟩\n (f ≡ g) ■\nopen FibrationIdentityPrinciple renaming (f≃g to _≃Fib_) using (FibrationIP) public\n\nEmbedding : (B : Type ℓ₁) → (ℓ : Level) → Type (ℓ-max ℓ₁ (ℓ-suc ℓ))\nEmbedding B ℓ = Σ[ A ∈ Type ℓ ] A ↪ B\n\nmodule EmbeddingIdentityPrinciple {B : Type ℓ} {ℓ₁} (f g : Embedding B ℓ₁) where\n module _ where\n open Σ f renaming (fst to F) public\n open Σ g renaming (fst to G) public\n open Σ (f .snd) renaming (fst to ffun; snd to isEmbF) public\n open Σ (g .snd) renaming (fst to gfun; snd to isEmbG) public\n f≃g : Type _\n f≃g = (∀ b → fiber ffun b → fiber gfun b) ×\n (∀ b → fiber gfun b → fiber ffun b)\n toFibr : Embedding B ℓ₁ → Fibration B ℓ₁\n toFibr (A , (f , _)) = (A , f)\n\n isEmbeddingToFibr : isEmbedding toFibr\n isEmbeddingToFibr w x = fullEquiv .snd where\n -- carefully managed such that (cong toFibr) is the equivalence\n fullEquiv : (w ≡ x) ≃ (toFibr w ≡ toFibr x)\n fullEquiv = compEquiv (congEquiv (invEquiv Σ-assoc-≃)) (invEquiv (Σ≡PropEquiv (λ _ → isEmbeddingIsProp)))\n\n EmbeddingIP : f≃g ≃ (f ≡ g)\n EmbeddingIP =\n f≃g\n ≃⟨ strictIsoToEquiv (invIso toProdIso) ⟩\n (∀ b → (fiber ffun b → fiber gfun b) × (fiber gfun b → fiber ffun b))\n ≃⟨ equivΠCod (λ _ → isEquivPropBiimpl→Equiv (isEmbedding→hasPropFibers isEmbF _)\n (isEmbedding→hasPropFibers isEmbG _)) ⟩\n (∀ b → (fiber (f .snd .fst) b) ≃ (fiber (g .snd .fst) b))\n ≃⟨ FibrationIP (toFibr f) (toFibr g) ⟩\n (toFibr f ≡ toFibr g)\n ≃⟨ invEquiv (_ , isEmbeddingToFibr _ _) ⟩\n f ≡ g\n ■\nopen EmbeddingIdentityPrinciple renaming (f≃g to _≃Emb_) using (EmbeddingIP) public\n", "meta": {"hexsha": "b68a7f89e8f502c0220fab270e65a8a1af7fc256", "size": 16036, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Functions/Embedding.agda", "max_stars_repo_name": "Edlyr/cubical", "max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e", "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": "Cubical/Functions/Embedding.agda", "max_issues_repo_name": "Edlyr/cubical", "max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e", "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": "Cubical/Functions/Embedding.agda", "max_forks_repo_name": "Edlyr/cubical", "max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e", "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.4672897196, "max_line_length": 109, "alphanum_fraction": 0.6150536293, "num_tokens": 6353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548782017745, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.3686789340526035}} {"text": "{-# OPTIONS --without-K --copatterns --sized-types #-}\nopen import lib.Basics\nopen import lib.PathGroupoid\nopen import lib.types.Paths\nopen import lib.Funext\nopen import Size\n\n{-\n-- | Coinductive delay type. This is the functor νπ̂ : Set → Set arising\n-- as the fixed point of π̂(H) = π ∘ ⟨Id, H⟩, where π : Set × Set → Set\n-- with π(X, Y) = X.\nrecord D (S : Set) : Set where\n coinductive\n field\n force : S\nopen D\n\n-- | Action of D on morphisms\nD₁ : ∀ {X Y} → (X → Y) → D X → D Y\nforce (D₁ f x) = f (force x)\n\n-- | D lifted to dependent functions\n↑D₁ : ∀ {A} → (B : A → Set) → ((x : A) → B x) → (y : D A) → D (B (force y))\nforce (↑D₁ B f y) = f (force y)\n\nD-intro : ∀ {H : Set → Set} → (∀ {X} → H X → X) → (∀ {X} → H X → D X)\nforce (D-intro f x) = f x\n\nD-intro2 : ∀ {X S : Set} → (X → S) → X → D S\nforce (D-intro2 f x) = f x\n\npostulate\n -- | We'll need coinduction to prove such equalities in the future, or prove\n -- it from univalence.\n D-coind : ∀ {S} {x y : D S} → force x == force y → x == y\n\nD-coind2 : ∀ {S} {x y : D S} → D (force x == force y) → x == y\nD-coind2 p = D-coind (force p\n-}\n\nmodule _ where\n private\n mutual\n data #D (A : Set) (P : Set) : Set where\n #p : #D-aux A P → (Unit → Unit) → #D A P\n\n data #D-aux (A : Set) (P : Set) : Set where\n #now : A → #D-aux A P\n #later : P → #D-aux A P\n\n D : Set → Set → Set\n D A X = #D A X\n\n now : ∀ {A X} → A → D A X\n now a = #p (#now a) _\n\n later : ∀ {A X} → X → D A X\n later x = #p (#later x) _\n\n D₁ : ∀ {A P₁ P₂} → (P₁ → P₂) → (D A P₁ → D A P₂)\n D₁ f (#p (#now a) _) = now a\n D₁ f (#p (#later x) _) = later (f x)\n\n record P {i : Size} (A : Set) : Set where\n coinductive\n field\n #force : ∀ {j : Size< i} → D A (P {j} A)\n open P\n\n force : ∀ {A} → P A → D A (P A)\n force x = #force x\n\n P-intro : ∀ {A X : Set} → (X → D A X) → (X → P A)\n P-intro {A} {X} f = P-intro'\n where\n P-intro' : ∀ {i} → X → P {i} A\n #force (P-intro' x) {j} = D₁ (P-intro' {j}) (f x)\n\n postulate -- HIT\n weak~ : ∀{A X : Set} → (force* : X → D A X) →\n (x : X) → (later x == force* x)\n\n -- | Extra module for recursion using sized types.\n -- This is convenient, as we can use the functor D in the definition, which\n -- in turn simplifies proofs.\n module DRec {A B : Set} {P' Y : Set}\n (now* : A → D B Y)\n (later* : P A → D B Y)\n (force* : Y → D B Y)\n (weak~* : (x : P A) → (later* x == force x))\n where\n f : D A P' → D B Y\n f = f-aux phantom where\n f-aux : Phantom weak~* → D A P' → D B Y\n f-aux phantom (#p (#now a) _) = now* a\n f-aux phantom (#p (#later x) _) = later* x\n\n postulate -- HIT\n weak~-β : (x : P') → ap f (weak~ force* x) == weak~* x\n\n{-\n module PElim {A X} {S : D A X → Set}\n (now* : (a : A) → S (now a))\n (later* : (x : X) → S (later x))\n (force*₁ : (x : X) → D A X)\n (force*₂ : (x : X) → S (force*₁ x))\n (weak~* : (x : X) → -- (x_rec : S\n (later* x == (force*₂ x) [ S ↓ (weak~ force*₁ x) ]))\n where\n f : (x : D A X) → S x\n f = f-aux phantom\n where\n f-aux : Phantom weak~* → (x : D A X) → S x\n f-aux phantom (#p (#now a) _) = now* a\n f-aux phantom (#p (#later x) _) = later* x\n-}\n-- postulate -- HIT\n-- weak~-β : (x : X) → apd f (weak~ force*₁ x) == weak~* x\n\n{-\n weak~-β₂ : (x : ∞P A) →\n apd f (weak~ x) == weak~* x (↑D₁ S f x)\n -- transport (weak~* x) g-is-D₁f (↑D₁ S f x)\n weak~-β₂ = ?\n-}\n\nopen DRec public renaming (f to D-rec)\n{-\nopen PElim public\n renaming (f to P-elim; g to ∞P-elim; f-homomorphism to P-elim-hom;\n weak~-β to elim-weak~-β)\n\n-}\n\nmodule Bla where\n\n⊥ : ∀ {A} → P A\n⊥ = P-intro later unit\n\n-- | Copairing of morphisms\n[_,_] : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}\n (l : A → C) (r : B → C) → (x : Coprod A B) → C\n[ f , g ] x = match x withl f withr g\n\nid-D : ∀ {A} → D A (P A) → D A (P A)\nid-D {A} = D-rec now later force (weak~ force)\n --(idf A) (idf (P A)) (λ x → force x) (weak~ (λ x → force x))\n\nD₁-force : ∀ {A P₁ P₂} → (force* : P₁ → D A P₁) → (f : P₁ → P₂) → (x : P₁)\n → later (f x) == D₁ f (force* x)\nD₁-force force* f x =\n later (f x)\n =⟨ idp ⟩\n D₁ f (later x)\n =⟨ weak~ force* x |in-ctx (D₁ f) ⟩\n D₁ f (force* x)\n ∎\n\n-- | Direct definition of bind\nbind : ∀ {A B} → (A → P B) → (P A → P B)\nbind {A} {B} f x = P-intro {X = P A ⊔ P B} [ u , v ] (inl x)\n where\n elim-A : A → D B (P A ⊔ P B)\n elim-A a =\n D-rec now\n (later ∘ inr)\n (D₁ inr ∘ force)\n (D₁-force force inr)\n (force (f a))\n\n u : P A → D B (P A ⊔ P B)\n u x = D-rec\n elim-A\n (later ∘ inl)\n (later ∘ inl) -- this should be force ...\n (λ _ → idp)\n (force x)\n\n v : P B → D B (P A ⊔ P B)\n v = D₁ inr ∘ force\n\n\n{-\n-- | Copairing of morphisms\n[_,_] : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}\n (l : A → C) (r : B → C) → (x : Coprod A B) → C\n[ f , g ] x = match x withl f withr g\n\n-- | Inverse of [now, later] à la Lambek,\n-- given by extending id + D ([now, later]) : A ⊔ D(A ⊔ ∞P A) → A ⊔ ∞P A.\nout : ∀ {A} → P A → A ⊔ ∞P A\nout {A} = P-rec inl force (λ _ → idp)\n -- (inr ∘ D₁ [ now , later ]) resp-weak~\n where\n resp-weak~ : (x : D (A ⊔ ∞P A)) →\n (inr ∘ D₁ [ now , later ]) x == force x\n resp-weak~ x =\n (inr ∘ D₁ [ now , later ]) x\n =⟨ {!!} ⟩\n inr (D₁ [ now , later ] x)\n =⟨ {!!} ⟩\n force x\n ∎\n\n\n⊥' : ∀ {A} → ∞P A\n\n⊥ : ∀ {A} → P A\n⊥ = later (D-intro (λ _ → {!!}) unit)\n\nforce ⊥' = {!!} -- ⊥\n\n-- | Action of P on morphisms\nP₁ : ∀ {A B} → (A → B) → (P A → P B)\nP₁ f = P-rec (now ∘ f) later weak~\n\n-- | Unit for the monad\nη : ∀ {A} → A → P A\nη = now\n\n-- | Monad multiplication\nμ : ∀ {A} → P (P A) → P A\nμ {A} = P-rec (idf (P A)) later weak~\n\n-- | Direct definition of bind\nbind : ∀ {A B} → (A → P B) → (P A → P B)\nbind {A} {B} f = P-rec f later weak~\n\nη-natural : ∀ {A B} → (f : A → B) →\n η ∘ f == P₁ f ∘ η\nη-natural f = λ=-nondep (λ x → idp)\n where\nn open FunextNonDep\n\nμ-natural : ∀ {A B} → (f : A → B) →\n μ ∘ P₁ (P₁ f) == P₁ f ∘ μ\nμ-natural {A} f = λ=-nondep q\n where\n open FunextNonDep\n\n T : P (P A) → Set\n T x = μ ( P₁ (P₁ f) x) == P₁ f (μ x)\n\n =-later : (x : ∞P (P A)) → D (T (force x)) → T (later x)\n =-later x p = transport T (! (weak~ x)) (force p)\n\n r : (x : ∞P (P A)) → (p : D (T (force x))) →\n (=-later x p) == (force p) [ T ↓ (weak~ x) ]\n r x p = trans-↓ T (weak~ x) (force p)\n\n q : (x : P (P A)) → μ ( P₁ (P₁ f) x) == P₁ f (μ x)\n q = P-elim {S = λ x → μ ( P₁ (P₁ f) x) == P₁ f (μ x)}\n (λ a → idp) =-later r\n\n-- | Termination predicate on P A\ndata _↓_ {A} (x : P A) : A → Set where\n now↓ : (a : A) → now a == x → x ↓ a\n later↓ : (a : A) → (u : ∞P A) → (later u == x) → (force u) ↓ a → x ↓ a\n\nmutual\n -- | Weak bisimilarity proofs\n data ~proof {A} (x y : P A) : Set where\n terminating : (a : A) → x ↓ a → y ↓ a → ~proof x y\n -- A bit awkward, but otherwise we cannot pattern matching on ~proof\n step : (u v : ∞P A) → (later u == x) → (later v == y) → force u ~ force v →\n ~proof x y\n\n -- | Weak bisimilarity for P A\n record _~_ {A} (x y : P A) : Set where\n coinductive\n field\n out~ : ~proof x y\nopen _~_\n\nterminate→=now : ∀{A} → (a : A) → (x : P A) → x ↓ a → now a == x\nterminate→=now a x (now↓ .a na=x) = na=x\nterminate→=now a x (later↓ .a u lu=x fu↓a) =\n now a\n =⟨ terminate→=now a (force u) fu↓a ⟩\n force u\n =⟨ ! (weak~ u) ⟩\n later u\n =⟨ lu=x ⟩\n x\n ∎\n\nlemma : ∀{A} → (a : A) → (x y : P A) → x ↓ a → y ↓ a → x == y\nlemma a x y x↓a y↓a =\n x\n =⟨ ! (terminate→=now a x x↓a) ⟩\n now a\n =⟨ terminate→=now a y y↓a ⟩\n y\n ∎\n\ninr-inj : ∀ {i} {A B : Set i} →\n (x y : B) → Path {i} {A ⊔ B} (inr x) (inr y) → x == y\ninr-inj x .x idp = idp\n\nlater-inj : ∀ {A} → (u v : ∞P A) → later u == later v → u == v\nlater-inj u v p = inr-inj u v lem\n where\n lem : inr u == inr v\n lem = transport (λ z → inr u == P-out z) {later u} {later v} p idp\n\n-- | Weak bisimilarity implies equality for P A\n~→= : ∀{A} → (x y : P A) → x ~ y → x == y\n~→= {A} x y = P-elim {S = λ x' → x' ~ y → x' == y} now-= later-= weak~-= x\n where\n now-= : (a : A) → now a ~ y → now a == y\n now-= a p = lem (out~ p)\n where\n lem : ~proof (now a) y → now a == y\n lem (terminating b (now↓ .b nb=na) y↓b) =\n now a\n =⟨ ! nb=na ⟩\n now b\n =⟨ terminate→=now b y y↓b ⟩\n y\n ∎\n lem (terminating b (later↓ .b u () now_a↓b) y↓b)\n lem (step u v () x₂ x₃)\n\n later-= : (u : ∞P A) →\n D (force u ~ y → force u == y) → later u ~ y → later u == y\n later-= u p later_u~y = lem (out~ later_u~y)\n where\n lem : ~proof (later u) y → later u == y\n lem (terminating a later_u↓a y↓a) = lemma a (later u) y later_u↓a y↓a\n lem (step u' v later_u'=later_u later_v=y force_u'~force_v) =\n later u\n =⟨ weak~ u ⟩\n force u\n =⟨ force p force_u~y ⟩\n y ∎\n where\n force_u'=force_u : force u' == force u\n force_u'=force_u =\n force u'\n =⟨ later-inj u' u later_u'=later_u |in-ctx force ⟩\n force u\n ∎\n\n y=force_v : y == force v\n y=force_v =\n y\n =⟨ ! later_v=y ⟩\n later v\n =⟨ weak~ v ⟩\n force v\n ∎\n\n force_u~y : force u ~ y\n force_u~y = transport\n (λ z → z ~ y)\n force_u'=force_u\n (transport! (λ z → force u' ~ z) y=force_v force_u'~force_v)\n\n weak~-= : (u : ∞P A) (p : D (force u ~ y → force u == y)) →\n (later-= u p)\n == (force p) [ (λ x' → x' ~ y → x' == y) ↓ (weak~ u) ]\n weak~-= u p = {!!}\n-}\n", "meta": {"hexsha": "2fff73fe5f79b867e2128c46d647d3673a55f7e1", "size": 10039, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "TypeTheory/HoTT/Partiality2.agda", "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "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": "TypeTheory/HoTT/Partiality2.agda", "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "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": "TypeTheory/HoTT/Partiality2.agda", "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "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": 27.5796703297, "max_line_length": 79, "alphanum_fraction": 0.4415778464, "num_tokens": 4087, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548511303338, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.36867891872966624}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import cohomology.Theory\n\nopen import cw.CW\n\nmodule cw.cohomology.ZerothCohomologyGroupOnDiag {i} (OT : OrdinaryTheory i)\n (⊙skel : ⊙Skeleton {i} 0) (ac : ⊙has-cells-with-choice 0 ⊙skel i) where\n\nopen OrdinaryTheory OT\nopen import cw.cohomology.TipAndAugment OT ⊙skel\n\nopen import groups.KernelSndImageInl (C2 0) {H = CX₀ 0}\n {K = Lift-group {j = i} Unit-group}\n cst-hom cst-hom (λ _ → idp)\n (C2×CX₀-is-abelian 0)\n\nopen import groups.KernelImage\n (cst-hom {G = C2×CX₀ 0} {H = Lift-group {j = i} Unit-group})\n cw-coε (C2×CX₀-is-abelian 0)\n\nC-cw-iso-ker/im : C 0 ⊙⟦ ⊙skel ⟧ ≃ᴳ Ker/Im\nC-cw-iso-ker/im =\n Ker-φ-snd-quot-Im-inl\n ∘eᴳ full-subgroup (ker-cst-hom-is-full (CX₀ 0) (Lift-group {j = i} Unit-group)) ⁻¹ᴳ\n", "meta": {"hexsha": "83a599c7937a957b71d5868453ae5e0b89eb464d", "size": 783, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/cw/cohomology/ZerothCohomologyGroupOnDiag.agda", "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/cw/cohomology/ZerothCohomologyGroupOnDiag.agda", "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/cw/cohomology/ZerothCohomologyGroupOnDiag.agda", "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "avg_line_length": 29.0, "max_line_length": 85, "alphanum_fraction": 0.6730523627, "num_tokens": 330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.4493926344647596, "lm_q1q2_score": 0.3684540301617093}} {"text": "open import AbstractInterfaces public\n\nmodule OrdersAndEqualities {{_ : IsProc}} {{_ : IsTime}} {{_ : IsMsg}} {{_ : IsEvent}} where\n\n\n-- _≡ₑ_ is a decidable equality on events within one process.\n\ndata _≡ₑ_ : ∀ {P T T′} → Event P T → Event P T′ → Set where\n refl≡ₑ : ∀ {P T} {a b : Event P T} →\n a ≡ₑ b\n\n\n_≢ₑ_ : ∀ {P T T′} → Event P T → Event P T′ → Set\na ≢ₑ b = ¬ (a ≡ₑ b)\n\n≡→≡ₑ : ∀ {P T T′} {a : Event P T} {b : Event P T′} →\n T ≡ T′ → a ≡ₑ b\n≡→≡ₑ refl = refl≡ₑ\n\n≢→≢ₑ : ∀ {P T T′} {a : Event P T} {b : Event P T′} →\n T ≢ T′ → a ≢ₑ b\n≢→≢ₑ T≢T′ refl≡ₑ = refl ↯ T≢T′\n\n_≡ₑ?_ : ∀ {T T′ P} → (a : Event P T) (b : Event P T′) → Dec (a ≡ₑ b)\n_≡ₑ?_ {T} {T′} a b with T ≡ₜ? T′\na ≡ₑ? b | yes T≡T′ = yes (≡→≡ₑ T≡T′)\na ≡ₑ? b | no T≢T′ = no (≢→≢ₑ T≢T′)\n\n\n-- _≅ₑ_ is a decidable equality on events across all processes.\n\ndata _≅ₑ_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → Event Pᵢ Tᵢ → Event Pⱼ Tⱼ → Set where\n refl≅ₑ : ∀ {P T} {a : Event P T} {b : Event P T} →\n a ≅ₑ b\n\n\n_≇ₑ_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → Event Pᵢ Tᵢ → Event Pⱼ Tⱼ → Set\na ≇ₑ b = ¬ (a ≅ₑ b)\n\n≡ₑ→≅ₑ : ∀ {P T T′} {a : Event P T} {b : Event P T′} →\n a ≡ₑ b → a ≅ₑ b\n≡ₑ→≅ₑ refl≡ₑ = refl≅ₑ\n\n≢ₑ→≇ₑ : ∀ {P T T′} {a : Event P T} {b : Event P T′} →\n a ≢ₑ b → a ≇ₑ b\n≢ₑ→≇ₑ a≢b refl≅ₑ = refl≡ₑ ↯ a≢b\n\n≢ₚ→≇ₑ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} →\n Pᵢ ≢ Pⱼ → a ≇ₑ b\n≢ₚ→≇ₑ P≢P′ refl≅ₑ = refl ↯ P≢P′\n\n≢ₜ→≇ₑ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} →\n Tᵢ ≢ Tⱼ → a ≇ₑ b\n≢ₜ→≇ₑ T≢T′ refl≅ₑ = refl ↯ T≢T′\n\n_≅ₑ?_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → (a : Event Pᵢ Tᵢ) (b : Event Pⱼ Tⱼ) → Dec (a ≅ₑ b)\n_≅ₑ?_ {Pᵢ} {Pⱼ} a b with Pᵢ ≡ₚ? Pⱼ\na ≅ₑ? b | yes refl with a ≡ₑ? b\na ≅ₑ? b | yes refl | yes a≡b = yes (≡ₑ→≅ₑ a≡b)\na ≅ₑ? b | yes refl | no a≢b = no (≢ₑ→≇ₑ a≢b)\na ≅ₑ? b | no Pᵢ≢Pⱼ = no (≢ₚ→≇ₑ Pᵢ≢Pⱼ)\n\n\n-- _<ₑ_ is a decidable strict total order on events within one process.\n\n_<ₑ_ : ∀ {T T′ P} → Event P T → Event P T′ → Set\n_<ₑ_ {T} {T′} a b = T <ₜ T′\n\n\n_≮ₑ_ : ∀ {P T T′} → Event P T → Event P T′ → Set\na ≮ₑ b = ¬ (a <ₑ b)\n\ntrans<ₑ : ∀ {P T T′ T″} {a : Event P T} {b : Event P T′} {c : Event P T″} →\n a <ₑ b → b <ₑ c → a <ₑ c\ntrans<ₑ = trans<ₜ\n\ntri<ₑ : ∀ {T T′ P} → (a : Event P T) (b : Event P T′) →\n Tri (a <ₑ b) (a ≡ₑ b) (b <ₑ a)\ntri<ₑ {T} {T′} a b with tri<ₜ T T′\ntri<ₑ a b | τ₍ T-is-trivial ⊙skel₋₂ ltS (⊙take-has-cells-with-choice Sn≤SSSn ⊙skel ac))\n\n module GLES-right = GLES (ℕ-to-ℤ (S n))\n (⊙cw-incl-tail n≤SSn ⊙skel₋₁) (⊙cw-incl-last ⊙skel)\n module GPM-right = GPM\n (⊙cw-incl-tail n≤SSn ⊙skel₋₁) (⊙cw-incl-last ⊙skel)\n\n C-apex-to-H : C-apex →ᴳ H\n C-apex-to-H = C-fmap (ℕ-to-ℤ (S (S n))) GPM-right.Y/X-to-Z/X\n\n abstract\n C-apex-to-H-is-inj : is-injᴳ C-apex-to-H\n C-apex-to-H-is-inj = Exact.G-trivial-implies-ψ-is-inj\n (exact-seq-index 2 GLES-right.C-grid-cofiber-exact-seq)\n (CXₙ/Xₙ₋₁-<-is-trivial ⊙skel ltS ac)\n\n C-WoC : Group i\n C-WoC = C (ℕ-to-ℤ (S (S n))) (⊙Cofiber (⊙cw-incl-last ⊙skel₋₁))\n\n G-to-C-WoC : G →ᴳ C-WoC\n G-to-C-WoC = C-fmap (ℕ-to-ℤ (S (S n)))\n (GPM.Y/X-to-Z/X (⊙cw-incl-last ⊙skel₋₁) (⊙cw-incl-last ⊙skel))\n\n C-WoC-to-H : C-WoC →ᴳ H\n C-WoC-to-H = C-fmap (ℕ-to-ℤ (S (S n)))\n (GPM.Z/X-to-Z/Y (⊙cw-incl-nth Sn≤SSSn ⊙skel) (⊙cw-incl-last ⊙skel₋₁))\n\nopen import groups.KernelImage cw-co∂-last LC.cw-co∂-last\n (CXₙ/Xₙ₋₁-is-abelian ⊙skel₋₁ (ℕ-to-ℤ (S (S n))))\n\nC-cw-iso-ker/im : C (ℕ-to-ℤ (S (S n))) ⊙⟦ ⊙skel ⟧ ≃ᴳ Ker/Im\nC-cw-iso-ker/im = lemma ∘eᴳ C-apex-iso-C-cw ⁻¹ᴳ where\n lemma : C-apex ≃ᴳ Ker/Im\n lemma = H-iso-Ker/Im\n cw-co∂-last LC.cw-co∂-last\n (CXₙ/Xₙ₋₁-is-abelian ⊙skel₋₁ (ℕ-to-ℤ (S (S n))))\n φ₁ φ₁-is-surj φ₂ φ₂-is-inj lemma-comm\n where\n φ₁ = G-to-C-apex ∘ᴳ GroupIso.g-hom G-iso-Ker\n abstract\n φ₁-is-surj : is-surjᴳ φ₁\n φ₁-is-surj = ∘-is-surj G-to-C-apex-is-surj (equiv-is-surj (GroupIso.g-is-equiv G-iso-Ker))\n\n φ₂ = GroupIso.g-hom Coker-iso-H ∘ᴳ C-apex-to-H\n abstract\n φ₂-is-inj : is-injᴳ φ₂\n φ₂-is-inj = ∘-is-inj (equiv-is-inj (GroupIso.g-is-equiv Coker-iso-H)) C-apex-to-H-is-inj\n\n abstract\n lemma-comm : ∀ g →\n GroupIso.g Coker-iso-H (GroupHom.f (C-apex-to-H ∘ᴳ G-to-C-apex) (GroupIso.g G-iso-Ker g))\n == q[ fst g ]\n lemma-comm g =\n GroupIso.g Coker-iso-H (GroupHom.f C-apex-to-H (GroupHom.f G-to-C-apex (GroupIso.g G-iso-Ker g)))\n =⟨ ap (GroupIso.g Coker-iso-H) (! (C-inner-grid-commutes □$ᴳ GroupIso.g G-iso-Ker g)) ⟩\n GroupIso.g Coker-iso-H (GroupHom.f C-WoC-to-H (GroupHom.f G-to-C-WoC (GroupIso.g G-iso-Ker g)))\n =⟨ ap (GroupIso.g Coker-iso-H ∘ GroupHom.f C-WoC-to-H ∘ fst) (GroupIso.f-g G-iso-Ker g) ⟩\n GroupIso.g Coker-iso-H (GroupHom.f C-WoC-to-H (fst g))\n =⟨ GroupIso.g-f Coker-iso-H q[ fst g ] ⟩\n q[ fst g ]\n =∎\n", "meta": {"hexsha": "2d1a09ae3aaa003d1457e1d510e48e2b9c5730d8", "size": 5336, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/cw/cohomology/HigherCohomologyGroups.agda", "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/cw/cohomology/HigherCohomologyGroups.agda", "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/cw/cohomology/HigherCohomologyGroups.agda", "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "avg_line_length": 33.9872611465, "max_line_length": 107, "alphanum_fraction": 0.5968890555, "num_tokens": 2440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757646140788307, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.36684779705063497}} {"text": "module Data.Num.Surjection where\n\nopen import Data.Num.Core\nopen import Data.Num.Continuous\n\nopen import Data.Nat\nopen import Data.Nat.Properties\nopen import Data.Nat.Properties.Simple\nopen import Data.Nat.Properties.Extra\n\nopen import Data.Fin as Fin\n using (Fin; fromℕ≤; inject≤)\n renaming (zero to z; suc to s)\nopen import Data.Fin.Properties using (toℕ-fromℕ≤; bounded)\nopen import Data.Product\nopen import Data.Empty using (⊥)\nopen import Data.Unit using (⊤; tt)\n\nopen import Function\nopen import Function.Surjection hiding (_∘_)\nopen Surjective\nopen import Function.Equality using (_⟶_; _⟨$⟩_)\nopen import Relation.Nullary.Decidable\nopen import Relation.Nullary\nopen import Relation.Nullary.Negation\nopen import Relation.Binary\nopen import Relation.Binary.PropositionalEquality\n\nopen ≡-Reasoning\nopen ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_)\nopen DecTotalOrder decTotalOrder using (reflexive) renaming (refl to ≤-refl)\n\n-- fromℕ that preserves equality\n\n-- ℕ⟶Num : ∀ {b d o}\n-- → (True (Continuous? b (suc d) o))\n-- → (val : ℕ)\n-- → (True (o ≤? val))\n-- → Num b (suc d) o\n\n-- ℕ⟶Num : ∀ b d o → True (Continuous? b (suc d) o) → setoid ℕ ⟶ setoid (Num b (suc d) o)\n-- ℕ⟶Num b d o cont = record\n-- { _⟨$⟩_ = fromℕ cont\n-- ; cong = cong (fromℕ cont)\n-- }\n--\n-- -- Surjective? : ∀ b d o → (True (Continuous? b (suc d) o)) → Dec (Surjective (ℕ⟶Num b d o))\n-- -- Surjective? b d o with Continuous? b (suc d) o\n-- -- Surjective? b d o | yes cont = {! !}\n-- -- Surjective? b d o | no ¬cont = {! !}\n--\n-- Num⟶ℕ-Surjective : ∀ b d o → (cont : True (Continuous? b (suc d) o)) → Surjective (Num⟶ℕ b (suc d) o)\n-- Num⟶ℕ-Surjective b d o cont = record\n-- { from = ℕ⟶Num b d o cont\n-- ; right-inverse-of = {! toℕ-fromℕ cont !}\n-- }\n\n-- Surjective? : ∀ b d o → Dec (Surjective (Num⟶ℕ b d o))\n-- Surjective? b d o with surjectionView b d o\n-- Surjective? b d o | Surj cond = yes (record\n-- { from = ℕ⟶Num b d o\n-- ; right-inverse-of = toℕ-fromℕ {b} {d} {o} {SurjCond⇒IsSurj cond}\n-- })\n-- Surjective? b d o | NonSurj reason = no (NonSurjCond⇏Surjective reason)\n--\n\n\n\n-- Conditions of surjectiveness\n-- data SurjCond : ℕ → ℕ → ℕ → Set where\n-- WithZerosUnary : ∀ { d} → (d≥2 : d ≥ 2) → SurjCond 1 d 0\n-- WithZeros : ∀ {b d} (b≥2 : b ≥ 2) → (d≥b : d ≥ b) → SurjCond b d 0\n-- Zeroless : ∀ {b d} (b≥1 : b ≥ 1) → (d≥b : d ≥ b) → SurjCond b d 1\n--\n-- -- Conditions of non-surjectiveness\n-- data NonSurjCond : ℕ → ℕ → ℕ → Set where\n-- Base≡0 : ∀ { d o} → NonSurjCond 0 d o\n-- NoDigits : ∀ {b o} → NonSurjCond b 0 o\n-- Offset≥2 : ∀ {b d o} → o ≥ 2 → NonSurjCond b d o\n-- UnaryWithOnlyZeros : NonSurjCond 1 1 0\n-- NotEnoughDigits : ∀ {b d o} → d ≥ 1 → d ≱ b → NonSurjCond b d o\n--\n-- data SurjectionView : ℕ → ℕ → ℕ → Set where\n-- Surj : ∀ {b d o} → SurjCond b d o → SurjectionView b d o\n-- NonSurj : ∀ {b d o} → NonSurjCond b d o → SurjectionView b d o\n--\n--\n-- surjectionView : (b d o : ℕ) → SurjectionView b d o\n-- surjectionView 0 d o = NonSurj Base≡0\n-- surjectionView (suc b) 0 o = NonSurj NoDigits\n-- surjectionView (suc b) (suc d) o with suc b ≤? suc d\n-- surjectionView 1 1 0 | yes p = NonSurj UnaryWithOnlyZeros\n-- surjectionView 1 (suc (suc d)) 0 | yes p = Surj (WithZerosUnary (s≤s (s≤s z≤n)))\n-- surjectionView (suc (suc b)) (suc d) 0 | yes p = Surj (WithZeros (s≤s (s≤s z≤n)) p)\n-- surjectionView (suc b) (suc d) 1 | yes p = Surj (Zeroless (s≤s z≤n) p)\n-- surjectionView (suc b) (suc d) (suc (suc o)) | yes p = NonSurj (Offset≥2 (s≤s (s≤s z≤n)))\n-- surjectionView (suc b) (suc d) o | no ¬p = NonSurj (NotEnoughDigits (s≤s z≤n) ¬p)\n--\n-- IsSurjective : ℕ → ℕ → ℕ → Set\n-- IsSurjective b d o with surjectionView b d o\n-- IsSurjective b d o | Surj _ = ⊤\n-- IsSurjective b d o | NonSurj _ = ⊥\n--\n-- SurjCond⇒b≥1 : ∀ {b d o} → SurjCond b d o → b ≥ 1\n-- SurjCond⇒b≥1 (WithZerosUnary d≥2) = s≤s z≤n\n-- SurjCond⇒b≥1 (WithZeros (s≤s b≥1) d≥b) = s≤s z≤n\n-- SurjCond⇒b≥1 (Zeroless b≥1 d≥b) = b≥1\n--\n-- SurjCond⇒d≥b : ∀ {b d o} → SurjCond b d o → d ≥ b\n-- SurjCond⇒d≥b (WithZerosUnary (s≤s d≥1)) = s≤s z≤n\n-- SurjCond⇒d≥b (WithZeros b≥2 d≥b) = d≥b\n-- SurjCond⇒d≥b (Zeroless b≥1 d≥b) = d≥b\n--\n-- SurjCond⇒IsSurj : ∀ {b d o} → SurjCond b d o → IsSurjective b d o\n-- SurjCond⇒IsSurj {b} {d} {o} cond with surjectionView b d o\n-- SurjCond⇒IsSurj cond | Surj x = tt\n-- SurjCond⇒IsSurj (WithZeros () d≥b) | NonSurj Base≡0\n-- SurjCond⇒IsSurj (Zeroless () d≥b) | NonSurj Base≡0\n-- SurjCond⇒IsSurj (WithZerosUnary ()) | NonSurj NoDigits\n-- SurjCond⇒IsSurj (WithZeros () z≤n) | NonSurj NoDigits\n-- SurjCond⇒IsSurj (Zeroless () z≤n) | NonSurj NoDigits\n-- SurjCond⇒IsSurj (WithZerosUnary _) | NonSurj (Offset≥2 ())\n-- SurjCond⇒IsSurj (WithZeros _ _) | NonSurj (Offset≥2 ())\n-- SurjCond⇒IsSurj (Zeroless _ _) | NonSurj (Offset≥2 (s≤s ()))\n-- SurjCond⇒IsSurj (WithZerosUnary (s≤s ())) | NonSurj UnaryWithOnlyZeros\n-- SurjCond⇒IsSurj (WithZeros (s≤s ()) _) | NonSurj UnaryWithOnlyZeros\n-- SurjCond⇒IsSurj (WithZerosUnary _) | NonSurj (NotEnoughDigits d≥1 d≱1) = contradiction d≥1 d≱1\n-- SurjCond⇒IsSurj (WithZeros _ d≥b) | NonSurj (NotEnoughDigits _ d≱b) = contradiction d≥b d≱b\n-- SurjCond⇒IsSurj (Zeroless _ d≥b) | NonSurj (NotEnoughDigits _ d≱b) = contradiction d≥b d≱b\n--\n-- ------------------------------------------------------------------------\n-- -- Operations on Num (which does not necessary needs to be Surj)\n-- ------------------------------------------------------------------------\n--\n-- starting-digit : ∀ {b d o} → SurjCond b d o → Digit d\n-- starting-digit (WithZerosUnary d≥2) = fromℕ≤ {1} d≥2\n-- starting-digit (WithZeros b≥2 d≥b) = fromℕ≤ {1} (≤-trans b≥2 d≥b)\n-- starting-digit (Zeroless b≥1 d≥b) = fromℕ≤ {0} (≤-trans b≥1 d≥b)\n\n-- 1+ : ∀ {b d o} → Num b d o → Num b d o\n-- 1+ {b} {d} {o} xs with surjectionView b d o\n-- 1+ ∙ | Surj cond = starting-digit cond ∷ ∙\n-- 1+ (x ∷ xs) | Surj cond with greatest x\n-- 1+ (x ∷ xs) | Surj cond | yes p = digit+1-b-legacy x (SurjCond⇒b≥1 cond) p ∷ 1+ xs -- carry\n-- 1+ (x ∷ xs) | Surj cond | no ¬p = digit+1 x ¬p ∷ xs\n-- 1+ ∙ | NonSurj reason = ∙\n-- 1+ (x ∷ xs) | NonSurj reason = xs\n--\n--\n-- n+ : ∀ {b d o} → ℕ → Num b d o → Num b d o\n-- n+ zero xs = xs\n-- n+ (suc n) xs = 1+ (n+ n xs)\n--\n-- fromℕ : ∀ {b d o} → ℕ → Num b d o\n-- fromℕ {b} {d} {o} n with surjectionView b d o\n-- fromℕ n | Surj x = n+ n ∙\n-- fromℕ n | NonSurj x = ∙\n--\n--\n-- -- fromℕ that preserves equality\n-- ℕ⟶Num : ∀ b d o → setoid ℕ ⟶ setoid (Num b d o)\n-- ℕ⟶Num b d o = record\n-- { _⟨$⟩_ = fromℕ\n-- ; cong = cong fromℕ\n-- }\n--\n-- toℕ-digit+1-b : ∀ {d b} (x : Digit d)\n-- → (b≥1 : b ≥ 1) → (p : suc (Fin.toℕ x) ≡ d) -- required props\n-- → Fin.toℕ (digit+1-b-legacy x b≥1 p) ≡ suc (Fin.toℕ x) ∸ b\n-- toℕ-digit+1-b {d} {b} x b≥1 p = toℕ-fromℕ≤ $ start\n-- suc (suc (Fin.toℕ x) ∸ b)\n-- ≤⟨ s≤s (∸-mono ≤-refl b≥1) ⟩\n-- suc (Fin.toℕ x)\n-- ≈⟨ p ⟩\n-- d\n-- □\n--\n-- ------------------------------------------------------------------------\n-- -- toℕ-1+ : toℕ (1+ xs) ≡ suc (toℕ xs)\n-- ------------------------------------------------------------------------\n--\n-- toℕ-1+-x∷xs-greatest-lemma : ∀ {b d o}\n-- → (x : Digit d) → (xs : Num b d o)\n-- → (cond : SurjCond b d o)\n-- → (p : suc (Fin.toℕ x) ≡ d)\n-- → (toℕ-1+-xs : toℕ (1+ xs) ≡ suc (toℕ xs))\n-- → toℕ (digit+1-b-legacy x (SurjCond⇒b≥1 cond) p ∷ 1+ xs) ≡ suc (toℕ (x ∷ xs))\n-- toℕ-1+-x∷xs-greatest-lemma {b} {d} {o} x xs cond p toℕ-1+-xs =\n-- begin\n-- toℕ (digit+1-b-legacy x (SurjCond⇒b≥1 cond) p ∷ 1+ xs)\n-- -- toℕ-fromℕ≤ : toℕ (fromℕ≤ mo+d)\n-- where\n-- ⟦xs⟧≡0 : toℕ xs ≡ 0\n-- ⟦xs⟧≡0 = ≤0⇒≡0 (toℕ xs) q\n-- ⟦x∷xs⟧>o+d : o + Fin.toℕ x + toℕ xs * b < o + d\n-- ⟦x∷xs⟧>o+d = start\n-- suc (o + Fin.toℕ x + toℕ xs * b)\n-- ≈⟨ begin\n-- suc (o + Fin.toℕ x + toℕ xs * b)\n-- ≡⟨ cong (λ w → suc (o + Fin.toℕ x + w * b)) ⟦xs⟧≡0 ⟩\n-- suc (o + Fin.toℕ x + zero)\n-- ≡⟨ +-right-identity (suc (o + Fin.toℕ x)) ⟩\n-- suc (o + Fin.toℕ x)\n-- ≡⟨ sym (+-suc o (Fin.toℕ x)) ⟩\n-- o + suc (Fin.toℕ x)\n-- ∎ ⟩\n-- o + suc (Fin.toℕ x)\n-- ≤⟨ n+-mono o (bounded x) ⟩\n-- o + d\n-- □\n--\n-- NonSurjCond-NotEnoughDigits {b} {d} {o} d≥1 b≰d (x ∷ xs) p | no ¬q =\n-- contradiction p (>⇒≢ ⟦x∷xs⟧>o+d)\n-- where\n-- ⟦x∷xs⟧>o+d : o + Fin.toℕ x + toℕ xs * b > o + d\n-- ⟦x∷xs⟧>o+d = start\n-- suc (o + d)\n-- ≈⟨ sym (+-suc o d) ⟩\n-- o + suc d\n-- ≤⟨ n+-mono o (\n-- start\n-- suc d\n-- ≤⟨ ≰⇒> b≰d ⟩\n-- b\n-- ≈⟨ sym (*-left-identity b) ⟩\n-- 1 * b\n-- ≤⟨ _*-mono_ {1} {toℕ xs} {b} {b} (≰⇒> ¬q) ≤-refl ⟩\n-- toℕ xs * b\n-- ≤⟨ n≤m+n (Fin.toℕ x) (toℕ xs * b) ⟩\n-- Fin.toℕ x + toℕ xs * b\n-- □\n-- ) ⟩\n-- o + (Fin.toℕ x + toℕ xs * b)\n-- ≈⟨ sym (+-assoc o (Fin.toℕ x) (toℕ xs * b)) ⟩\n-- o + Fin.toℕ x + toℕ xs * b\n-- □\n--\n-- NonSurjCond⇏Surjective : ∀ {b} {d} {o} → NonSurjCond b d o → ¬ (Surjective (Num⟶ℕ b d o))\n-- NonSurjCond⇏Surjective {_} {d} {o} Base≡0 claim =\n-- NonSurjCond-Base≡0\n-- (from claim ⟨$⟩ suc o + d)\n-- (right-inverse-of claim (suc (o + d)))\n-- NonSurjCond⇏Surjective NoDigits claim =\n-- NonSurjCond-NoDigits\n-- (from claim ⟨$⟩ 1)\n-- (right-inverse-of claim 1)\n-- NonSurjCond⇏Surjective (Offset≥2 p) claim =\n-- NonSurjCond-Offset≥2 p\n-- (from claim ⟨$⟩ 1)\n-- (right-inverse-of claim 1)\n-- NonSurjCond⇏Surjective UnaryWithOnlyZeros claim =\n-- NonSurjCond-UnaryWithOnlyZeros\n-- (from claim ⟨$⟩ 1)\n-- (right-inverse-of claim 1)\n-- NonSurjCond⇏Surjective {_} {d} {o} (NotEnoughDigits p q) claim =\n-- NonSurjCond-NotEnoughDigits p q\n-- (from claim ⟨$⟩ o + d)\n-- (right-inverse-of claim (o + d))\n--\n-- SurjCond⇒Surjective : ∀ {b} {d} {o} → SurjCond b d o → Surjective (Num⟶ℕ b d o)\n-- SurjCond⇒Surjective {b} {d} {o} cond = record\n-- { from = ℕ⟶Num b d o\n-- ; right-inverse-of = toℕ-fromℕ {b} {d} {o} {SurjCond⇒IsSurj cond}\n-- }\n--\n-- Surjective? : ∀ b d o → Dec (Surjective (Num⟶ℕ b d o))\n-- Surjective? b d o with surjectionView b d o\n-- Surjective? b d o | Surj cond = yes (record\n-- { from = ℕ⟶Num b d o\n-- ; right-inverse-of = toℕ-fromℕ {b} {d} {o} {SurjCond⇒IsSurj cond}\n-- })\n-- Surjective? b d o | NonSurj reason = no (NonSurjCond⇏Surjective reason)\n--\n-- ------------------------------------------------------------------------\n-- --\n-- ------------------------------------------------------------------------\n--\n-- -- Surjective⇒SurjCond {b} {d} {o} surj = {! !}\n-- Surjective⇒SurjCond : ∀ {b} {d} {o}\n-- → Surjective (Num⟶ℕ b d o)\n-- → SurjCond b d o\n-- Surjective⇒SurjCond {b} {d} {o} surj with surjectionView b d o\n-- Surjective⇒SurjCond surj | Surj condition = condition\n-- Surjective⇒SurjCond surj | NonSurj reason = contradiction surj (NonSurjCond⇏Surjective reason)\n--\n-- Surjective⇒IsSurj : ∀ {b} {d} {o} → Surjective (Num⟶ℕ b d o) → IsSurjective b d o\n-- Surjective⇒IsSurj = SurjCond⇒IsSurj ∘ Surjective⇒SurjCond\n--\n-- Surjective⇒b≥1 : ∀ {b} {d} {o} → Surjective (Num⟶ℕ b d o) → b ≥ 1\n-- Surjective⇒b≥1 = SurjCond⇒b≥1 ∘ Surjective⇒SurjCond\n--\n-- Surjective⇒d≥b : ∀ {b} {d} {o} → Surjective (Num⟶ℕ b d o) → b ≤ d\n-- Surjective⇒d≥b = SurjCond⇒d≥b ∘ Surjective⇒SurjCond\n", "meta": {"hexsha": "9af709a0e290294633aaaaf0495a181a59ba7008", "size": 20755, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Data/Num/Surjection.agda", "max_stars_repo_name": "banacorn/numeral", "max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z", "max_issues_repo_path": "Data/Num/Surjection.agda", "max_issues_repo_name": "banacorn/numeral", "max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "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": "Data/Num/Surjection.agda", "max_forks_repo_name": "banacorn/numeral", "max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z", "max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z", "avg_line_length": 41.8447580645, "max_line_length": 150, "alphanum_fraction": 0.4581064804, "num_tokens": 8865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.36683132069739943}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nmodule Math.Combinatorics.Function.Properties.Lemma where\n\nopen import Data.Unit using (tt)\nopen import Data.Product\nopen import Data.Sum\nopen import Data.Nat\nopen import Data.Nat.Properties\nopen import Data.Nat.DivMod\nopen import Data.Nat.Solver using (module +-*-Solver)\nopen import Relation.Binary\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Nullary\nopen import Relation.Nullary.Decidable\nopen import Function\nopen import Algebra.FunctionProperties\n\nopen ≤-Reasoning\n\n1≤n⇒n≢0 : ∀ {n} → 1 ≤ n → n ≢ 0\n1≤n⇒n≢0 .{suc _} (s≤s z≤n) ()\n\n-- TODO: use m Nat\n\n{-# BUILTIN NATURAL Nat #-}\n\n-- Now we can define\nfortyTwo : Nat\nfortyTwo = 42\n\n-- To anything interesting with values of the built-in types we need functions\n-- to manipulate them. To this end Agda provides a set of primitive functions.\n-- To gain access to a primitive function one simply declares it. For instance,\n-- the function for floating point addition is called primFloatPlus. See below\n-- for a complete list of primitive functions. At the moment the name that you\n-- bring into scope is always the name of the primitive function. In the future\n-- we might allow a primitive function to be introduced with any name.\n\nmodule FloatPlus where -- We put it in a module to prevent it from clashing with\n -- the plus function in the complete list of primitive\n -- functions below.\n primitive\n primFloatPlus : Float -> Float -> Float\n\n twoPi = primFloatPlus pi pi\n\n-- Some primitive functions returns elements of non-primitive types. For\n-- instance, the integer comparison functions return booleans. To be able to\n-- use these functions we have to explain which type to use for booleans.\n\ndata Bool : Set where\n false : Bool\n true : Bool\n\n{-# BUILTIN BOOL Bool #-}\n{-# BUILTIN TRUE true #-}\n{-# BUILTIN FALSE false #-}\n\nmodule FloatLess where\n\n primitive\n primFloatLess : Float -> Float -> Bool\n\n-- There are functions to convert a string to a list of characters, so we need\n-- to say which list type to use.\n\ndata List (A : Set) : Set where\n nil : List A\n _::_ : A -> List A -> List A\n\n{-# BUILTIN LIST List #-}\n{-# BUILTIN NIL nil #-}\n{-# BUILTIN CONS _::_ #-}\n\nmodule StringToList where\n\n primitive\n primStringToList : String -> List Char\n\n-- Below is a partial version of the complete list of primitive\n-- functions.\n\nprimitive\n\n -- Integer functions\n primIntegerPlus : Int -> Int -> Int\n primIntegerMinus : Int -> Int -> Int\n primIntegerTimes : Int -> Int -> Int\n primIntegerDiv : Int -> Int -> Int -- partial\n primIntegerMod : Int -> Int -> Int -- partial\n primIntegerEquality : Int -> Int -> Bool\n primIntegerLess : Int -> Int -> Bool\n primIntegerAbs : Int -> Nat\n primNatToInteger : Nat -> Int\n primShowInteger : Int -> String\n\n -- Floating point functions\n primIntegerToFloat : Int -> Float\n primFloatPlus : Float -> Float -> Float\n primFloatMinus : Float -> Float -> Float\n primFloatTimes : Float -> Float -> Float\n primFloatDiv : Float -> Float -> Float\n primFloatLess : Float -> Float -> Bool\n primRound : Float -> Int\n primFloor : Float -> Int\n primCeiling : Float -> Int\n primExp : Float -> Float\n primLog : Float -> Float -- partial\n primSin : Float -> Float\n primShowFloat : Float -> String\n\n -- Character functions\n primCharEquality : Char -> Char -> Bool\n primIsLower : Char -> Bool\n primIsDigit : Char -> Bool\n primIsAlpha : Char -> Bool\n primIsSpace : Char -> Bool\n primIsAscii : Char -> Bool\n primIsLatin1 : Char -> Bool\n primIsPrint : Char -> Bool\n primIsHexDigit : Char -> Bool\n primToUpper : Char -> Char\n primToLower : Char -> Char\n primCharToNat : Char -> Nat\n primNatToChar : Nat -> Char -- partial\n primShowChar : Char -> String\n\n -- String functions\n primStringToList : String -> List Char\n primStringFromList : List Char -> String\n primStringAppend : String -> String -> String\n primStringEquality : String -> String -> Bool\n primShowString : String -> String\n", "meta": {"hexsha": "c695faf6118b3e76eb2912fb65d885fa78efd05a", "size": 4775, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "examples/Introduction/Built-in.agda", "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z", "max_issues_repo_path": "examples/Introduction/Built-in.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": "examples/Introduction/Built-in.agda", "max_forks_repo_name": "masondesu/agda", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "avg_line_length": 29.6583850932, "max_line_length": 81, "alphanum_fraction": 0.6552879581, "num_tokens": 1194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.36673049578507216}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- The Colist type and some operations\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe --sized-types #-}\n\nmodule Codata.Colist where\n\nopen import Size\nopen import Data.Unit\nopen import Data.Nat.Base\nopen import Data.Product using (_×_ ; _,_)\nopen import Data.These using (These; this; that; these)\nopen import Data.Maybe using (Maybe; nothing; just)\nopen import Data.List.Base using (List; []; _∷_)\nopen import Data.List.NonEmpty using (List⁺; _∷_)\nopen import Data.Vec as Vec using (Vec; []; _∷_)\nopen import Data.BoundedVec as BVec using (BoundedVec)\nopen import Function\n\nopen import Codata.Thunk using (Thunk; force)\nopen import Codata.Conat as Conat using (Conat ; zero ; suc)\nopen import Codata.Cowriter as CW using (Cowriter; _∷_)\nopen import Codata.Delay as Delay using (Delay ; now ; later)\nopen import Codata.Stream using (Stream ; _∷_)\n\n\ndata Colist {a} (A : Set a) (i : Size) : Set a where\n [] : Colist A i\n _∷_ : A → Thunk (Colist A) i → Colist A i\n\nmodule _ {w a} {W : Set w} {A : Set a} where\n\n------------------------------------------------------------------------\n-- Relationship to Cowriter.\n\n fromCowriter : ∀ {i} → Cowriter W A i → Colist W i\n fromCowriter CW.[ _ ] = []\n fromCowriter (w ∷ ca) = w ∷ λ where .force → fromCowriter (ca .force)\n\nmodule _ {a} {A : Set a} where\n\n toCowriter : ∀ {i} → Colist A i → Cowriter A ⊤ i\n toCowriter [] = CW.[ _ ]\n toCowriter (a ∷ as) = a ∷ λ where .force → toCowriter (as .force)\n\n------------------------------------------------------------------------\n-- Basic functions.\n\n [_] : A → Colist A ∞\n [ a ] = a ∷ λ where .force → []\n\n length : ∀ {i} → Colist A i → Conat i\n length [] = zero\n length (x ∷ xs) = suc λ where .force → length (xs .force)\n\n replicate : ∀ {i} → Conat i → A → Colist A i\n replicate zero a = []\n replicate (suc n) a = a ∷ λ where .force → replicate (n .force) a\n\n infixr 5 _++_ _⁺++_\n _++_ : ∀ {i} → Colist A i → Colist A i → Colist A i\n [] ++ ys = ys\n (x ∷ xs) ++ ys = x ∷ λ where .force → xs .force ++ ys\n\n lookup : ℕ → Colist A ∞ → Maybe A\n lookup n [] = nothing\n lookup zero (a ∷ as) = just a\n lookup (suc n) (a ∷ as) = lookup n (as .force)\n\n colookup : ∀ {i} → Conat i → Colist A i → Delay (Maybe A) i\n colookup n [] = now nothing\n colookup zero (a ∷ as) = now (just a)\n colookup (suc n) (a ∷ as) =\n later λ where .force → colookup (n .force) (as .force)\n\n take : ∀ (n : ℕ) → Colist A ∞ → BoundedVec A n\n take zero xs = BVec.[]\n take n [] = BVec.[]\n take (suc n) (x ∷ xs) = x BVec.∷ take n (xs .force)\n\n cotake : ∀ {i} → Conat i → Stream A i → Colist A i\n cotake zero xs = []\n cotake (suc n) (x ∷ xs) = x ∷ λ where .force → cotake (n .force) (xs .force)\n\n fromList : List A → Colist A ∞\n fromList [] = []\n fromList (x ∷ xs) = x ∷ λ where .force → fromList xs\n\n _⁺++_ : ∀ {i} → List⁺ A → Thunk (Colist A) i → Colist A i\n (x ∷ xs) ⁺++ ys = x ∷ λ where .force → fromList xs ++ ys .force\n\n fromStream : ∀ {i} → Stream A i → Colist A i\n fromStream = cotake Conat.infinity\n\nmodule _ {ℓ} {A : Set ℓ} where\n\n chunksOf : (n : ℕ) → Colist A ∞ → Cowriter (Vec A n) (BoundedVec A n) ∞\n chunksOf n = chunksOfAcc n id id module ChunksOf where\n\n chunksOfAcc : ∀ {i} m →\n -- We have two continuations but we are only ever going to use one.\n -- If we had linear types, we would write the type using the & conjunction here.\n (k≤ : BoundedVec A m → BoundedVec A n) →\n (k≡ : Vec A m → Vec A n) →\n -- Finally we chop up the input stream.\n Colist A ∞ → Cowriter (Vec A n) (BoundedVec A n) i\n chunksOfAcc zero k≤ k≡ as = k≡ [] ∷ λ where .force → chunksOfAcc n id id as\n chunksOfAcc (suc k) k≤ k≡ [] = CW.[ k≤ BVec.[] ]\n chunksOfAcc (suc k) k≤ k≡ (a ∷ as) =\n chunksOfAcc k (k≤ ∘ (a BVec.∷_)) (k≡ ∘ (a ∷_)) (as .force)\n\nmodule _ {a b} {A : Set a} {B : Set b} where\n\n map : ∀ {i} (f : A → B) → Colist A i → Colist B i\n map f [] = []\n map f (a ∷ as) = f a ∷ λ where .force → map f (as .force)\n\n unfold : ∀ {i} → (A → Maybe (A × B)) → A → Colist B i\n unfold next seed with next seed\n ... | nothing = []\n ... | just (seed′ , b) = b ∷ λ where .force → unfold next seed′\n\n scanl : ∀ {i} → (B → A → B) → B → Colist A i → Colist B i\n scanl c n [] = n ∷ λ where .force → []\n scanl c n (a ∷ as) = n ∷ λ where .force → scanl c (c n a) (as .force)\n\nmodule _ {a b c} {A : Set a} {B : Set b} {C : Set c} where\n\n alignWith : ∀ {i} → (These A B → C) → Colist A i → Colist B i → Colist C i\n alignWith f [] bs = map (f ∘′ that) bs\n alignWith f as@(_ ∷ _) [] = map (f ∘′ this) as\n alignWith f (a ∷ as) (b ∷ bs) =\n f (these a b) ∷ λ where .force → alignWith f (as .force) (bs .force)\n\n zipWith : ∀ {i} → (A → B → C) → Colist A i → Colist B i → Colist C i\n zipWith f [] bs = []\n zipWith f as [] = []\n zipWith f (a ∷ as) (b ∷ bs) =\n f a b ∷ λ where .force → zipWith f (as .force) (bs .force)\n\nmodule _ {a b} {A : Set a} {B : Set b} where\n\n align : ∀ {i} → Colist A i → Colist B i → Colist (These A B) i\n align = alignWith id\n\n zip : ∀ {i} → Colist A i → Colist B i → Colist (A × B) i\n zip = zipWith _,_\n\n ap : ∀ {i} → Colist (A → B) i → Colist A i → Colist B i\n ap = zipWith _$′_\n", "meta": {"hexsha": "a2b4346c0cddb8cd4b1ef57ed37bf7f207641608", "size": 5466, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Codata/Colist.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": "test/asset/agda-stdlib-1.0/Codata/Colist.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Codata/Colist.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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.4935064935, "max_line_length": 88, "alphanum_fraction": 0.5279912184, "num_tokens": 1939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804196836382, "lm_q2_score": 0.5926665999540697, "lm_q1q2_score": 0.3667304874520541}} {"text": "------------------------------------------------------------------------\n-- Syntax of Fω with interval kinds\n------------------------------------------------------------------------\n\n{-# OPTIONS --safe --without-K #-}\n\nmodule FOmegaInt.Syntax where\n\nopen import Algebra using (Monoid)\nimport Data.Context as Context\nopen import Data.Context.Properties\nopen import Data.Fin using (Fin; suc; zero)\nopen import Data.Fin.Substitution\nopen import Data.Fin.Substitution.Lemmas\nopen import Data.Fin.Substitution.ExtraLemmas\nopen import Data.Nat using (ℕ; suc; zero)\nopen import Data.Product using (proj₂)\nopen import Data.Vec as Vec using ([]; _∷_)\nopen import Data.List as List using (List; []; _∷_; foldl; map; _++_; _∷ʳ_)\nopen import Data.List.Properties using (++-monoid)\nimport Data.Maybe as Maybe\nopen import Function using (_∘_)\nopen import Relation.Binary.Construct.Closure.ReflexiveTransitive using (ε; _◅_)\nopen import Relation.Binary.PropositionalEquality as P hiding ([_])\nopen P.≡-Reasoning\n\n\n----------------------------------------------------------------------\n-- Raw terms: untyped syntax of terms, types and kinds.\n\n-- NOTE 1. Following the style of Pure Type System (PTS), we define\n-- raw (i.e. untyped/unkinded) terms and types as a single syntactic\n-- category rather than distinguishing them syntactically.\n-- Concretely, we use the singe datatype Term to represent raw terms\n-- and types. This simplifies the definition of substitution in types\n-- and terms as we don't need to distinguish between type and term\n-- variables. The difference between terms and types becomes manifest\n-- only later in (sub-)typing and (sub-)kinding judgments. However,\n-- unlike PTS, we *do* treat kinds as a separate syntactic\n-- category/datatype because there are no kind variables. This\n-- simplifies some definitions and proofs that rely on the syntactic\n-- structure of kinds (e.g. kind simplification and related\n-- properties).\n--\n-- NOTE 2. We use well-scoped de Bruijn indexing to represent term\n-- and type variables in raw terms/types. The datatype `Term' is\n-- indexed by the number of free variables its inhabitants may\n-- contain, i.e. given a raw term\n--\n-- a : Term n\n--\n-- the set of \"names\" that may appear in `a' is\n--\n-- { 0, 1, ..., n-1 }.\n--\n-- Binders extend this set by increasing n by one for each fresh name\n-- they introduce. This ensures that raw terms are intrinsically\n-- well-scoped. This representation was adapted from previous Agda\n-- formalizations of typed lambda calculi by Danielsson and others [1,\n-- 2] and comes with some support in the Agda standard library. See\n-- Data.Fin.Substitution.Example for a simple example.\n--\n-- [1] N. A. Danielsson and T. Altenkirch, \"Subtyping, Declaratively\n-- An Exercise in Mixed Induction and Coinduction\", Proc. MPC\n-- 2010.\n--\n-- [2] N. A. Danielsson, \"Operational Semantics Using the Partiality\n-- Monad\", Proc. ICFP 2012.\n\nmodule Syntax where\n\n infixl 9 _·_ _⊡_ _⊡∙_\n infixr 7 _⇒_ _⇒∙_\n infix 6 _⋯_\n\n -- Raw, T-dependent kinds with up to n free variables.\n\n data Kind (T : ℕ → Set) (n : ℕ) : Set where\n _⋯_ : (a b : T n) → Kind T n -- interval\n Π : (j : Kind T n) (k : Kind T (suc n)) → Kind T n -- dependent arrow\n\n -- Raw terms and types with up to n free variables.\n --\n -- NOTE. The type instantiation operator _⊡_ should be considered\n -- specialized variant of the application operator _·_. The reason\n -- for including a dedicated _⊡_ constructor is to distinguish term\n -- applications from type applications/instantiations in CBV\n -- reductions (see FOmegaInt.Reduction.Cbv). Without the special\n -- treatment of type instantiation, CBV reduction would permit\n -- reduction of type arguments before contraction. Not only is this\n -- counter to the usual CBV semantics for Fω (see e.g. TAPL p. 450),\n -- but it would require a proof of subject reduction (aka\n -- preservation) for kinding in order to prove preservation of\n -- typing even under CBV reduction. By adopting the usual CBV\n -- semantics, this dependency can be avoided. See\n -- FOmegaInt.Typing.Preservation for a proof of subject reduction\n -- for typing using the usual CBV semantics.\n\n data Term (n : ℕ) : Set where\n var : (x : Fin n) → Term n -- variable\n ⊥ : Term n -- bottom (minimum)\n ⊤ : Term n -- top (maximum)\n Π : (k : Kind Term n) (a : Term (suc n)) → Term n -- universal quant.\n _⇒_ : (a b : Term n) → Term n -- arrow\n Λ : (k : Kind Term n) (a : Term (suc n)) → Term n -- type abstraction\n ƛ : (a : Term n) (b : Term (suc n)) → Term n -- term abstraction\n _⊡_ : (a b : Term n) → Term n -- type instantiation\n _·_ : (a b : Term n) → Term n -- term application\n\n -- A shorthand for the kind of proper types.\n\n * : ∀ {n} → Kind Term n\n * = ⊥ ⋯ ⊤\n\n infixl 9 _∙_\n\n -- Raw terms and types in spine form.\n --\n -- Spine form is an alternative representation of raw terms where\n -- the arguments of consecutive applications are grouped together\n -- into sequences of arguments called \"spines\". This representation\n -- is better suited for the definition of \"hereditary substitution\"\n -- (see Syntax.HereditarySubstitution) and canonical kinding (see\n -- Kinding.Canonical). The two representations are isomorphic, as\n -- witnessed by ⌜⌝∘⌞⌟-id and ⌞⌟∘⌜⌝-id below.\n --\n -- NOTE. Below, we consider type instantiations (a ⊡ b) as heads\n -- rather than eliminations, despite the fact that, semantically,\n -- they are elimination forms. However, for the purpose of\n -- hereditary substitution we will ignore their semantics and treat\n -- _⊡_ as an uninterpreted binary operation. This is justified by\n -- the fact that *well-kinded* hereditary substitution is only\n -- defined on (well-kinded) types, in which _⊡_ cannot appear.\n --\n -- One may wonder: why include constructors for term-level forms\n -- such as ƛ or _⊡_ in this presentation of the syntax if it is only\n -- used to define type-level hereditary substitution? The answer is\n -- that we often rely on the two presentations of the syntax being\n -- isomorphic to switch between them without loss of generality. If\n -- we only included type formers, we could not prove this\n -- isomorphism. Including the term formers thus adds a bit of\n -- overhead but simplifies things over all.\n\n mutual\n\n -- Eliminations are applications of (possibly empty) sequences of\n -- arguments to heads.\n\n data Elim (n : ℕ) : Set where\n _∙_ : (a : Head n) (as : Spine n) → Elim n -- application\n\n -- Heads are those terms that are not eliminations.\n\n data Head (n : ℕ) : Set where\n var : (x : Fin n) → Head n -- variable\n ⊥ : Head n -- bottom (minimum)\n ⊤ : Head n -- top (maximum)\n Π : (k : Kind Elim n) (a : Elim (suc n)) → Head n -- universal\n _⇒_ : (a b : Elim n) → Head n -- arrow\n Λ : (k : Kind Elim n) (a : Elim (suc n)) → Head n -- type abstraction\n ƛ : (a : Elim n) (b : Elim (suc n)) → Head n -- term abstraction\n _⊡_ : (a b : Elim n) → Head n -- type inst.\n\n -- Spines are (possibly empty) sequences of eliminations.\n\n Spine : ℕ → Set\n Spine n = List (Elim n)\n\n -- Projections.\n\n headOf : ∀ {n} → Elim n → Head n\n headOf (a ∙ as) = a\n\n spineOf : ∀ {n} → Elim n → Spine n\n spineOf (a ∙ as) = as\n\n infixl 9 _⌜·⌝_ _⌞∙⌟_ _∙∙_\n\n -- Post-application of spines and eliminations to eliminations.\n\n _∙∙_ : ∀ {n} → Elim n → Spine n → Elim n\n a ∙ as ∙∙ bs = a ∙ (as ++ bs)\n\n _⌜·⌝_ : ∀ {n} → Elim n → Elim n → Elim n\n a ⌜·⌝ b = a ∙∙ (b ∷ [])\n\n -- Application of term sequences to terms.\n\n _⌞∙⌟_ : ∀ {n} → Term n → List (Term n) → Term n\n a ⌞∙⌟ as = foldl _·_ a as\n\n -- Shorthands for \"unapplied\" term/type constructors.\n\n var∙ : ∀ {n} → Fin n → Elim n\n var∙ x = var x ∙ []\n\n ⊥∙ : ∀ {n} → Elim n\n ⊥∙ = ⊥ ∙ []\n\n ⊤∙ : ∀ {n} → Elim n\n ⊤∙ = ⊤ ∙ []\n\n ∀∙ : ∀ {n} → Kind Elim n → Elim (suc n) → Elim n\n ∀∙ k a = Π k a ∙ []\n\n _⇒∙_ : ∀ {n} → Elim n → Elim n → Elim n\n a ⇒∙ b = (a ⇒ b) ∙ []\n\n Λ∙ : ∀ {n} → Kind Elim n → Elim (suc n) → Elim n\n Λ∙ k a = Λ k a ∙ []\n\n ƛ∙ : ∀ {n} → Elim n → Elim (suc n) → Elim n\n ƛ∙ a b = ƛ a b ∙ []\n\n _⊡∙_ : ∀ {n} → Elim n → Elim n → Elim n\n a ⊡∙ b = (a ⊡ b) ∙ []\n\n ⌜*⌝ : ∀ {n} → Kind Elim n\n ⌜*⌝ = ⊥∙ ⋯ ⊤∙\n\n -- Conversions between the two representations.\n\n mutual\n\n -- Turn raw eliminations into raw terms.\n\n ⌞_⌟ : ∀ {n} → Elim n → Term n\n ⌞ a ∙ as ⌟ = ⌞ a ⌟Hd ⌞∙⌟ ⌞ as ⌟Sp\n\n ⌞_⌟Kd : ∀ {n} → Kind Elim n → Kind Term n\n ⌞ a ⋯ b ⌟Kd = ⌞ a ⌟ ⋯ ⌞ b ⌟\n ⌞ Π j k ⌟Kd = Π ⌞ j ⌟Kd ⌞ k ⌟Kd\n\n ⌞_⌟Sp : ∀ {n} → Spine n → List (Term n)\n ⌞ [] ⌟Sp = []\n ⌞ a ∷ as ⌟Sp = ⌞ a ⌟ ∷ ⌞ as ⌟Sp\n\n ⌞_⌟Hd : ∀ {n} → Head n → Term n\n ⌞ var x ⌟Hd = var x\n ⌞ ⊥ ⌟Hd = ⊥\n ⌞ ⊤ ⌟Hd = ⊤\n ⌞ Π k a ⌟Hd = Π ⌞ k ⌟Kd ⌞ a ⌟\n ⌞ a ⇒ b ⌟Hd = ⌞ a ⌟ ⇒ ⌞ b ⌟\n ⌞ Λ k a ⌟Hd = Λ ⌞ k ⌟Kd ⌞ a ⌟\n ⌞ ƛ a b ⌟Hd = ƛ ⌞ a ⌟ ⌞ b ⌟\n ⌞ a ⊡ b ⌟Hd = ⌞ a ⌟ ⊡ ⌞ b ⌟\n\n mutual\n\n -- Turn raw terms into raw eliminations.\n\n ⌜_⌝ : ∀ {n} → Term n → Elim n\n ⌜ var x ⌝ = var x ∙ []\n ⌜ ⊥ ⌝ = ⊥∙\n ⌜ ⊤ ⌝ = ⊤∙\n ⌜ Π k a ⌝ = ∀∙ ⌜ k ⌝Kd ⌜ a ⌝\n ⌜ a ⇒ b ⌝ = ⌜ a ⌝ ⇒∙ ⌜ b ⌝\n ⌜ Λ k a ⌝ = Λ∙ ⌜ k ⌝Kd ⌜ a ⌝\n ⌜ ƛ a b ⌝ = ƛ∙ ⌜ a ⌝ ⌜ b ⌝\n ⌜ a ⊡ b ⌝ = ⌜ a ⌝ ⊡∙ ⌜ b ⌝\n ⌜ a · b ⌝ = ⌜ a ⌝ ⌜·⌝ ⌜ b ⌝\n\n ⌜_⌝Kd : ∀ {n} → Kind Term n → Kind Elim n\n ⌜ a ⋯ b ⌝Kd = ⌜ a ⌝ ⋯ ⌜ b ⌝\n ⌜ Π j k ⌝Kd = Π ⌜ j ⌝Kd ⌜ k ⌝Kd\n\n -- Shapes (aka simple kinds).\n\n data SKind : Set where\n ★ : SKind\n _⇒_ : SKind → SKind → SKind\n\n -- Kind simplification (aka erasure from kinds to shapes).\n\n ⌊_⌋ : ∀ {T n} → Kind T n → SKind\n ⌊ a ⋯ b ⌋ = ★\n ⌊ Π j k ⌋ = ⌊ j ⌋ ⇒ ⌊ k ⌋\n\n -- A wrapper for raw kind or type ascriptions.\n\n data KdOrTp (T : ℕ → Set) (n : ℕ) : Set where\n kd : Kind T n → KdOrTp T n\n tp : T n → KdOrTp T n\n\n TermAsc = KdOrTp Term\n ElimAsc = KdOrTp Elim\n\n ⌞_⌟Asc : ∀ {n} → ElimAsc n → TermAsc n\n ⌞ kd k ⌟Asc = kd ⌞ k ⌟Kd\n ⌞ tp a ⌟Asc = tp ⌞ a ⌟\n\n ⌜_⌝Asc : ∀ {n} → TermAsc n → ElimAsc n\n ⌜ kd k ⌝Asc = kd ⌜ k ⌝Kd\n ⌜ tp a ⌝Asc = tp ⌜ a ⌝\n\nopen Syntax\n\n\n----------------------------------------------------------------------\n-- Some properties of raw terms and kinds\n\n-- The kd constructor is injective.\n\nkd-inj : ∀ {T n} {j k : Kind T n} → kd j ≡ kd k → j ≡ k\nkd-inj refl = refl\n\n-- Extensionality of eliminations.\n\n∙-ext : ∀ {n} (a : Elim n) → headOf a ∙ spineOf a ≡ a\n∙-ext (a ∙ as) = refl\n\n-- The empty spine is a right unit of _∙∙_\n\n∙∙-[] : ∀ {n} (a : Elim n) → a ∙∙ [] ≡ a\n∙∙-[] (a ∙ as) = cong (a ∙_) (proj₂ identity as)\n where open Monoid (++-monoid (Elim _)) hiding (_∙_)\n\n-- Spine application commutes with spine concatenation.\n\n∙∙-++ : ∀ {n} (a : Elim n) bs cs → a ∙∙ bs ∙∙ cs ≡ a ∙∙ (bs ++ cs)\n∙∙-++ (a ∙ as) bs cs = cong (a ∙_) (assoc as bs cs)\n where open Monoid (++-monoid (Elim _)) hiding (_∙_)\n\n-- Spine application can be expressed as a left fold.\n\n∙∙IsFold : ∀ {n} (a : Elim n) bs → a ∙∙ bs ≡ foldl _⌜·⌝_ a bs\n∙∙IsFold (a ∙ as) [] = ∙∙-[] (a ∙ as)\n∙∙IsFold (a ∙ as) (b ∷ bs) = begin\n a ∙ (as ++ b ∷ bs)\n ≡⟨ sym (∙∙-++ (a ∙ as) (b ∷ []) bs) ⟩\n a ∙ ((as ∷ʳ b) ++ bs)\n ≡⟨ ∙∙IsFold (a ∙ (as ∷ʳ b)) bs ⟩\n foldl _⌜·⌝_ (a ∙ (as ∷ʳ b)) bs\n ∎\n\n-- Conversion to raw terms commutes with (post-)application.\n\n⌞⌟-· : ∀ {n} (a : Elim n) b → ⌞ a ⌜·⌝ b ⌟ ≡ ⌞ a ⌟ · ⌞ b ⌟\n⌞⌟-· (a ∙ as) b = helper as b\n where\n helper : ∀ {n} {a : Term n} bs c →\n a ⌞∙⌟ ⌞ bs ∷ʳ c ⌟Sp ≡ a ⌞∙⌟ ⌞ bs ⌟Sp · ⌞ c ⌟\n helper [] c = refl\n helper (b ∷ bs) c = helper bs c\n\n⌞⌟-∙∙ : ∀ {n} (a : Elim n) bs → ⌞ a ∙∙ bs ⌟ ≡ ⌞ a ⌟ ⌞∙⌟ ⌞ bs ⌟Sp\n⌞⌟-∙∙ a [] = cong ⌞_⌟ (∙∙-[] a)\n⌞⌟-∙∙ a (b ∷ bs) = begin\n ⌞ a ∙∙ (b ∷ bs) ⌟ ≡⟨ sym (cong ⌞_⌟ (∙∙-++ a (b ∷ []) bs)) ⟩\n ⌞ a ∙∙ (b ∷ []) ∙∙ bs ⌟ ≡⟨ ⌞⌟-∙∙ (a ∙∙ (b ∷ [])) bs ⟩\n ⌞ a ∙∙ (b ∷ []) ⌟ ⌞∙⌟ ⌞ bs ⌟Sp ≡⟨ cong (_⌞∙⌟ ⌞ bs ⌟Sp) (⌞⌟-· a b) ⟩\n ⌞ a ⌟ · ⌞ b ⌟ ⌞∙⌟ ⌞ bs ⌟Sp ∎\n\n-- Conversion to eliminations commutes with spine application.\n\n⌜⌝-∙ : ∀ {n} (a : Term n) bs → ⌜ a ⌞∙⌟ bs ⌝ ≡ ⌜ a ⌝ ∙∙ map ⌜_⌝ bs\n⌜⌝-∙ a bs = begin\n ⌜ a ⌞∙⌟ bs ⌝ ≡⟨ helper a bs ⟩\n foldl _⌜·⌝_ ⌜ a ⌝ (map ⌜_⌝ bs) ≡⟨ sym (∙∙IsFold ⌜ a ⌝ (map ⌜_⌝ bs)) ⟩\n ⌜ a ⌝ ∙∙ map ⌜_⌝ bs ∎\n where\n helper : ∀ {n} (a : Term n) bs →\n ⌜ a ⌞∙⌟ bs ⌝ ≡ foldl _⌜·⌝_ ⌜ a ⌝ (map ⌜_⌝ bs)\n helper a [] = refl\n helper a (b ∷ bs) = helper (a · b) bs\n\n-- The two representations of raw terms are isomorphic.\n\nmutual\n\n ⌞⌟∘⌜⌝-id : ∀ {n} (a : Term n) → ⌞ ⌜ a ⌝ ⌟ ≡ a\n ⌞⌟∘⌜⌝-id (var x) = refl\n ⌞⌟∘⌜⌝-id ⊥ = refl\n ⌞⌟∘⌜⌝-id ⊤ = refl\n ⌞⌟∘⌜⌝-id (Π k a) = cong₂ Π (⌞⌟Kd∘⌜⌝Kd-id k) (⌞⌟∘⌜⌝-id a)\n ⌞⌟∘⌜⌝-id (a ⇒ b) = cong₂ _⇒_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)\n ⌞⌟∘⌜⌝-id (Λ k a) = cong₂ Λ (⌞⌟Kd∘⌜⌝Kd-id k) (⌞⌟∘⌜⌝-id a)\n ⌞⌟∘⌜⌝-id (ƛ a b) = cong₂ ƛ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)\n ⌞⌟∘⌜⌝-id (a ⊡ b) = cong₂ _⊡_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)\n ⌞⌟∘⌜⌝-id (a · b) = begin\n ⌞ ⌜ a ⌝ ⌜·⌝ ⌜ b ⌝ ⌟ ≡⟨ ⌞⌟-· ⌜ a ⌝ ⌜ b ⌝ ⟩\n ⌞ ⌜ a ⌝ ⌟ · ⌞ ⌜ b ⌝ ⌟ ≡⟨ cong₂ _·_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b) ⟩\n a · b ∎\n\n ⌞⌟Kd∘⌜⌝Kd-id : ∀ {n} (k : Kind Term n) → ⌞ ⌜ k ⌝Kd ⌟Kd ≡ k\n ⌞⌟Kd∘⌜⌝Kd-id (a ⋯ b) = cong₂ _⋯_ (⌞⌟∘⌜⌝-id a) (⌞⌟∘⌜⌝-id b)\n ⌞⌟Kd∘⌜⌝Kd-id (Π j k) = cong₂ Π (⌞⌟Kd∘⌜⌝Kd-id j) (⌞⌟Kd∘⌜⌝Kd-id k)\n\nmutual\n\n ⌜⌝∘⌞⌟-id : ∀ {n} (a : Elim n) → ⌜ ⌞ a ⌟ ⌝ ≡ a\n ⌜⌝∘⌞⌟-id (a ∙ bs) = begin\n ⌜ ⌞ a ⌟Hd ⌞∙⌟ ⌞ bs ⌟Sp ⌝\n ≡⟨ ⌜⌝-∙ ⌞ a ⌟Hd ⌞ bs ⌟Sp ⟩\n ⌜ ⌞ a ⌟Hd ⌝ ∙∙ map ⌜_⌝ ⌞ bs ⌟Sp\n ≡⟨ cong₂ _∙∙_ (⌜⌝∘⌞⌟Hd-∙-[] a) (map-⌜⌝∘⌞⌟Sp-id bs) ⟩\n a ∙ [] ∙∙ bs\n ∎\n\n map-⌜⌝∘⌞⌟Sp-id : ∀ {n} (as : Spine n) → map ⌜_⌝ ⌞ as ⌟Sp ≡ as\n map-⌜⌝∘⌞⌟Sp-id [] = refl\n map-⌜⌝∘⌞⌟Sp-id (a ∷ as) = cong₂ _∷_ (⌜⌝∘⌞⌟-id a) (map-⌜⌝∘⌞⌟Sp-id as)\n\n ⌜⌝∘⌞⌟Hd-∙-[] : ∀ {n} (a : Head n) → ⌜ ⌞ a ⌟Hd ⌝ ≡ a ∙ []\n ⌜⌝∘⌞⌟Hd-∙-[] (var x) = refl\n ⌜⌝∘⌞⌟Hd-∙-[] ⊥ = refl\n ⌜⌝∘⌞⌟Hd-∙-[] ⊤ = refl\n ⌜⌝∘⌞⌟Hd-∙-[] (Π k a) = cong₂ ∀∙ (⌜⌝Kd∘⌞⌟Kd-id k) (⌜⌝∘⌞⌟-id a)\n ⌜⌝∘⌞⌟Hd-∙-[] (a ⇒ b) = cong₂ _⇒∙_ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)\n ⌜⌝∘⌞⌟Hd-∙-[] (Λ k a) = cong₂ Λ∙ (⌜⌝Kd∘⌞⌟Kd-id k) (⌜⌝∘⌞⌟-id a)\n ⌜⌝∘⌞⌟Hd-∙-[] (ƛ a b) = cong₂ ƛ∙ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)\n ⌜⌝∘⌞⌟Hd-∙-[] (a ⊡ b) = cong₂ _⊡∙_ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)\n\n ⌜⌝Kd∘⌞⌟Kd-id : ∀ {n} (k : Kind Elim n) → ⌜ ⌞ k ⌟Kd ⌝Kd ≡ k\n ⌜⌝Kd∘⌞⌟Kd-id (a ⋯ b) = cong₂ _⋯_ (⌜⌝∘⌞⌟-id a) (⌜⌝∘⌞⌟-id b)\n ⌜⌝Kd∘⌞⌟Kd-id (Π j k) = cong₂ Π (⌜⌝Kd∘⌞⌟Kd-id j) (⌜⌝Kd∘⌞⌟Kd-id k)\n\n-- Simplified kinds are stable under conversions of term\n-- representation.\n\n⌊⌋-⌜⌝Kd : ∀ {n} (k : Kind Term n) → ⌊ ⌜ k ⌝Kd ⌋ ≡ ⌊ k ⌋\n⌊⌋-⌜⌝Kd (a ⋯ b) = refl\n⌊⌋-⌜⌝Kd (Π j k) = cong₂ _⇒_ (⌊⌋-⌜⌝Kd j) (⌊⌋-⌜⌝Kd k)\n\n⌊⌋-⌞⌟Kd : ∀ {n} (k : Kind Elim n) → ⌊ ⌞ k ⌟Kd ⌋ ≡ ⌊ k ⌋\n⌊⌋-⌞⌟Kd (a ⋯ b) = refl\n⌊⌋-⌞⌟Kd (Π j k) = cong₂ _⇒_ (⌊⌋-⌞⌟Kd j) (⌊⌋-⌞⌟Kd k)\n\n\n----------------------------------------------------------------------\n-- Substitutions in raw terms\n--\n-- We use an intrinsically well-scoped variant of simultaneous\n-- substitutions inspired by McBride's technique for defining\n-- type-preserving substitutions [3]. These come with some support in\n-- the Agda standard library. In particular, the standard library\n-- provides generic proofs for a plethora of standard untyped\n-- substitution lemmas (e.g. substitutions commute, identity\n-- substitutions vanish, etc.) which are easy but tedious to prove\n-- (see the Data.Fin.Substitution.Lemmas module). By using this\n-- substitution framework, we get those lemmas for \"free\" (we still\n-- need to provide some basic lemmas to bootstrap everything).\n--\n-- To use the standard framework, we must follow the following four\n-- steps.\n--\n-- 1. We define an application function `t / σ' of generic untyped\n-- substitutions `σ' to well-scoped untyped terms `t'. Generic\n-- substitutions are defined over an abstract type `T', which will\n-- later represent variables (to encode renamings) or terms (to\n-- encode actual substitutions). Hence the definition of\n-- application must be parametrized over some abstract operations\n-- on such substitutions (lifting, weakening, etc.) to be defined\n-- later. Concrete instances of these operations are collected in\n-- the record `Lift' (see e.g. `SubstApp' module below).\n--\n-- Along with application, we define a few lemmas to be used in\n-- step 4. (They express the fact that application of\n-- (multi-)substitutions is compositional w.r.t. the various\n-- syntactic forms.)\n--\n-- 2. Application is instantiated with `T = Fin' to obtain\n-- well-scoped renamings, i.e. substitutions of variables in\n-- terms. The standard library provides a predefined instance of\n-- `Lift Fin Term' to this end.\n--\n-- 3. Using well-scoped renamings, an instance of `Lift Term Term' is\n-- defined, and application is instantiated to concrete\n-- substitutions of terms in terms.\n--\n-- 4. Using the generic lemmas defined in step 1, many helpful\n-- derived substitution lemmas are instantiated.\n-- (E.g. \"substitutions commute\", \"identity substitutions vanish\",\n-- etc.)\n--\n-- Most of the work is done in step 1, while steps 2-3 consists mostly\n-- in calls to the substitution API of the Agda standard library.\n--\n-- [3] C. McBride, \"Type-Preserving Renaming and Substitution\"\n-- http://strictlypositive.org/ren-sub.pdf\n\n-- Application of generic substitutions lifted to type and kind\n-- ascriptions.\n\nmodule KdOrTpSubstApp {T T′ : ℕ → Set} (simple : Simple T)\n (kdApp : Application (Kind T′) T)\n (tpApp : Application T′ T) where\n open Simple simple\n open Application kdApp renaming (_/_ to _Kd/_; _/✶_ to _Kd/✶_)\n open Application tpApp renaming (_/_ to _Tp/_; _/✶_ to _Tp/✶_)\n\n infixl 8 _/_\n\n -- Apply a substitution to a kind or type ascription.\n\n _/_ : ∀ {m n} → KdOrTp T′ m → Sub T m n → KdOrTp T′ n\n (kd k) / σ = kd (k Kd/ σ)\n (tp a) / σ = tp (a Tp/ σ)\n\n open Application (record { _/_ = _/_ }) public hiding (_/_)\n\n -- Some helper lemmas about applying sequences of substitutions (to\n -- be used for instantiating TermSubstLemmas).\n\n -- Substitutions in kind ascriptions are compositional.\n\n kd-/✶-↑✶ : ∀ k {m n j} (σs : Subs T m n) →\n (kd j) /✶ σs ↑✶ k ≡ kd (j Kd/✶ σs ↑✶ k)\n kd-/✶-↑✶ k ε = refl\n kd-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (kd-/✶-↑✶ k σs) refl\n\n -- Substitutions in type ascriptions are compositional.\n\n tp-/✶-↑✶ : ∀ k {m n a} (σs : Subs T m n) →\n (tp a) /✶ σs ↑✶ k ≡ tp (a Tp/✶ σs ↑✶ k)\n tp-/✶-↑✶ k ε = refl\n tp-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (tp-/✶-↑✶ k σs) refl\n\n-- Application of generic substitutions to terms\n\nmodule SubstApp {T : ℕ → Set} (l : Lift T Term) where\n open Lift l hiding (var)\n\n infixl 8 _/_ _Kind/_ _Elim/_ _Head/_ _//_ _Kind′/_\n\n mutual\n\n -- Apply a substitution to a raw term/type.\n\n _/_ : ∀ {m n} → Term m → Sub T m n → Term n\n var x / σ = lift (Vec.lookup σ x)\n ⊥ / σ = ⊥\n ⊤ / σ = ⊤\n Π k a / σ = Π (k Kind/ σ) (a / σ ↑)\n (a ⇒ b) / σ = (a / σ) ⇒ (b / σ)\n Λ k a / σ = Λ (k Kind/ σ) (a / σ ↑)\n ƛ a b / σ = ƛ (a / σ) (b / σ ↑)\n a · b / σ = (a / σ) · (b / σ)\n a ⊡ b / σ = (a / σ) ⊡ (b / σ)\n\n -- Apply a substitution to a kind.\n\n _Kind/_ : ∀ {m n} → Kind Term m → Sub T m n → Kind Term n\n (a ⋯ b) Kind/ σ = (a / σ) ⋯ (b / σ)\n Π j k Kind/ σ = Π (j Kind/ σ) (k Kind/ σ ↑)\n\n mutual\n\n -- Apply a substitution to an elimination.\n\n _Elim/_ : ∀ {m n} → Elim m → Sub T m n → Elim n\n a ∙ as Elim/ σ = (a Head/ σ) ∙∙ (as // σ)\n\n -- Apply a substitution to a head.\n\n _Head/_ : ∀ {m n} → Head m → Sub T m n → Elim n\n var x Head/ σ = ⌜ lift (Vec.lookup σ x) ⌝\n ⊥ Head/ σ = ⊥∙\n ⊤ Head/ σ = ⊤∙\n Π k a Head/ σ = ∀∙ (k Kind′/ σ) (a Elim/ σ ↑)\n (a ⇒ b) Head/ σ = (a Elim/ σ) ⇒∙ (b Elim/ σ)\n Λ k a Head/ σ = Λ∙ (k Kind′/ σ) (a Elim/ σ ↑)\n ƛ a b Head/ σ = ƛ∙ (a Elim/ σ) (b Elim/ σ ↑)\n a ⊡ b Head/ σ = (a Elim/ σ) ⊡∙ (b Elim/ σ)\n\n -- Apply a substitution to a spine.\n\n _//_ : ∀ {m n} → Spine m → Sub T m n → Spine n\n [] // σ = []\n (a ∷ as) // σ = a Elim/ σ ∷ as // σ\n\n -- Apply a substitution to a (elimination-based) kind.\n _Kind′/_ : ∀ {m n} → Kind Elim m → Sub T m n → Kind Elim n\n (a ⋯ b) Kind′/ σ = (a Elim/ σ) ⋯ (b Elim/ σ)\n Π j k Kind′/ σ = Π (j Kind′/ σ) (k Kind′/ σ ↑)\n\n private\n appTerm = record { _/_ = _/_ }\n appKind = record { _/_ = _Kind/_ }\n appElim = record { _/_ = _Elim/_ }\n appKind′ = record { _/_ = _Kind′/_ }\n\n -- Some helper lemmas about applying sequences of substitutions (to\n -- be used for instantiating TermSubstLemmas).\n\n open Application appTerm hiding (_/_)\n open Application appKind using () renaming (_/✶_ to _Kind/✶_)\n\n -- The bottom and top types are invariant under substitution.\n\n ⊥-/✶-↑✶ : ∀ k {m n} (σs : Subs T m n) → ⊥ /✶ σs ↑✶ k ≡ ⊥\n ⊥-/✶-↑✶ k ε = refl\n ⊥-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⊥-/✶-↑✶ k σs) refl\n\n ⊤-/✶-↑✶ : ∀ k {m n} (σs : Subs T m n) → ⊤ /✶ σs ↑✶ k ≡ ⊤\n ⊤-/✶-↑✶ k ε = refl\n ⊤-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⊤-/✶-↑✶ k σs) refl\n\n -- Substitutions in the remaining term and type formers are\n -- compositional.\n \n Π-/✶-↑✶ : ∀ k {m n j a} (σs : Subs T m n) →\n (Π j a) /✶ σs ↑✶ k ≡ Π (j Kind/✶ σs ↑✶ k) (a /✶ σs ↑✶ suc k)\n Π-/✶-↑✶ k ε = refl\n Π-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (Π-/✶-↑✶ k σs) refl\n\n ⇒-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →\n (a ⇒ b) /✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) ⇒ (b /✶ σs ↑✶ k)\n ⇒-/✶-↑✶ k ε = refl\n ⇒-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⇒-/✶-↑✶ k σs) refl\n\n Λ-/✶-↑✶ : ∀ k {m n j a} (σs : Subs T m n) →\n (Λ j a) /✶ σs ↑✶ k ≡ Λ (j Kind/✶ σs ↑✶ k) (a /✶ σs ↑✶ suc k)\n Λ-/✶-↑✶ k ε = refl\n Λ-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (Λ-/✶-↑✶ k σs) refl\n\n ƛ-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →\n (ƛ a b) /✶ σs ↑✶ k ≡ ƛ (a /✶ σs ↑✶ k) (b /✶ σs ↑✶ suc k)\n ƛ-/✶-↑✶ k ε = refl\n ƛ-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (ƛ-/✶-↑✶ k σs) refl\n\n ·-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →\n (a · b) /✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) · (b /✶ σs ↑✶ k)\n ·-/✶-↑✶ k ε = refl\n ·-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (·-/✶-↑✶ k σs) refl\n\n ⊡-/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →\n (a ⊡ b) /✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) ⊡ (b /✶ σs ↑✶ k)\n ⊡-/✶-↑✶ k ε = refl\n ⊡-/✶-↑✶ k (σ ◅ σs) = cong₂ _/_ (⊡-/✶-↑✶ k σs) refl\n\n -- Substitutions in the kind formers are compositional.\n\n Π-Kind/✶-↑✶ : ∀ k {m n j l} (σs : Subs T m n) →\n (Π j l) Kind/✶ σs ↑✶ k ≡\n Π (j Kind/✶ σs ↑✶ k) (l Kind/✶ σs ↑✶ (suc k))\n Π-Kind/✶-↑✶ k ε = refl\n Π-Kind/✶-↑✶ k (σ ◅ σs) = cong₂ _Kind/_ (Π-Kind/✶-↑✶ k σs) refl\n\n ⋯-Kind/✶-↑✶ : ∀ k {m n a b} (σs : Subs T m n) →\n (a ⋯ b) Kind/✶ σs ↑✶ k ≡ (a /✶ σs ↑✶ k) ⋯ (b /✶ σs ↑✶ k)\n ⋯-Kind/✶-↑✶ k ε = refl\n ⋯-Kind/✶-↑✶ k (σ ◅ σs) = cong₂ _Kind/_ (⋯-Kind/✶-↑✶ k σs) refl\n\n -- Application of substitutions commutes with concatenation of spines.\n\n ++-// : ∀ {m n} (as bs : Spine m) {σ : Sub T m n} →\n (as ++ bs) // σ ≡ as // σ ++ bs // σ\n ++-// [] bs = refl\n ++-// (a ∷ as) bs = cong (a Elim/ _ ∷_) (++-// as bs)\n\n -- Application of substitutions commutes application of spines and\n -- eliminations.\n\n ∙∙-/ : ∀ {m n} a (as : Spine m) {σ : Sub T m n} →\n a ∙∙ as Elim/ σ ≡ (a Elim/ σ) ∙∙ (as // σ)\n ∙∙-/ (a ∙ as) bs = begin\n (a Head/ _) ∙∙ ((as ++ bs) // _)\n ≡⟨ cong (_ ∙∙_) (++-// as bs) ⟩\n (a Head/ _) ∙∙ (as // _ ++ bs // _)\n ≡⟨ sym (∙∙-++ _ (as // _) (bs // _)) ⟩\n (a Head/ _) ∙∙ (as // _) ∙∙ (bs // _)\n ∎\n\n ⌜·⌝-/ : ∀ {m n} (a b : Elim m) {σ : Sub T m n} →\n a ⌜·⌝ b Elim/ σ ≡ (a Elim/ σ) ⌜·⌝ (b Elim/ σ)\n ⌜·⌝-/ (a ∙ as) b {σ} = begin\n (a Head/ σ) ∙∙ ((as ∷ʳ b) // σ)\n ≡⟨ cong ((a Head/ σ) ∙∙_) (++-// as (b ∷ [])) ⟩\n (a Head/ σ) ∙∙ (as // σ ++ (b ∷ []) // σ)\n ≡⟨ sym (∙∙-++ (a Head/ σ) (as // σ) ((b ∷ []) // σ)) ⟩\n (a Head/ σ) ∙∙ (as // σ) ∙∙ ((b ∷ []) // σ)\n ≡⟨ ∙∙IsFold ((a Head/ σ) ∙∙ (as // σ)) ((b ∷ []) // σ) ⟩\n (a Head/ σ) ∙∙ (as // σ) ⌜·⌝ (b Elim/ σ)\n ∎\n\n -- Application of substitutions commutes with the conversions.\n\n mutual\n\n ⌜⌝-/ : ∀ {m n} a {σ : Sub T m n} → ⌜ a / σ ⌝ ≡ ⌜ a ⌝ Elim/ σ\n ⌜⌝-/ (var x) = sym (∙∙-[] _)\n ⌜⌝-/ ⊥ = refl\n ⌜⌝-/ ⊤ = refl\n ⌜⌝-/ (Π k a) = cong₂ ∀∙ (⌜⌝Kd-/ k) (⌜⌝-/ a)\n ⌜⌝-/ (a ⇒ b) = cong₂ _⇒∙_ (⌜⌝-/ a) (⌜⌝-/ b)\n ⌜⌝-/ (Λ k a) = cong₂ Λ∙ (⌜⌝Kd-/ k) (⌜⌝-/ a)\n ⌜⌝-/ (ƛ a b) = cong₂ ƛ∙ (⌜⌝-/ a) (⌜⌝-/ b)\n ⌜⌝-/ (a · b) {σ} = begin\n ⌜ a / σ ⌝ ⌜·⌝ ⌜ b / σ ⌝ ≡⟨ cong₂ _⌜·⌝_ (⌜⌝-/ a) (⌜⌝-/ b) ⟩\n (⌜ a ⌝ Elim/ σ) ⌜·⌝ (⌜ b ⌝ Elim/ σ) ≡⟨ sym (⌜·⌝-/ ⌜ a ⌝ ⌜ b ⌝) ⟩\n ⌜ a ⌝ ⌜·⌝ ⌜ b ⌝ Elim/ σ ∎\n ⌜⌝-/ (a ⊡ b) = cong₂ _⊡∙_ (⌜⌝-/ a) (⌜⌝-/ b)\n\n ⌜⌝Kd-/ : ∀ {m n} k {σ : Sub T m n} → ⌜ k Kind/ σ ⌝Kd ≡ ⌜ k ⌝Kd Kind′/ σ\n ⌜⌝Kd-/ (a ⋯ b) = cong₂ _⋯_ (⌜⌝-/ a) (⌜⌝-/ b)\n ⌜⌝Kd-/ (Π j k) = cong₂ Π (⌜⌝Kd-/ j) (⌜⌝Kd-/ k)\n\n ⌞⌟-/ : ∀ {m n} a {σ : Sub T m n} → ⌞ a Elim/ σ ⌟ ≡ ⌞ a ⌟ / σ\n ⌞⌟-/ a {σ} = begin\n ⌞ a Elim/ σ ⌟ ≡⟨ cong (⌞_⌟ ∘ (_Elim/ σ)) (sym (⌜⌝∘⌞⌟-id a)) ⟩\n ⌞ ⌜ ⌞ a ⌟ ⌝ Elim/ σ ⌟ ≡⟨ cong ⌞_⌟ (sym (⌜⌝-/ ⌞ a ⌟)) ⟩\n ⌞ ⌜ ⌞ a ⌟ / σ ⌝ ⌟ ≡⟨ ⌞⌟∘⌜⌝-id (⌞ a ⌟ / σ) ⟩\n ⌞ a ⌟ / σ ∎\n\n ⌞⌟Kd-/ : ∀ {m n} k {σ : Sub T m n} → ⌞ k Kind′/ σ ⌟Kd ≡ ⌞ k ⌟Kd Kind/ σ\n ⌞⌟Kd-/ (a ⋯ b) = cong₂ _⋯_ (⌞⌟-/ a) (⌞⌟-/ b)\n ⌞⌟Kd-/ (Π j k) = cong₂ Π (⌞⌟Kd-/ j) (⌞⌟Kd-/ k)\n\n open Application appElim using () renaming (_/✶_ to _Elim/✶_)\n open Application appKind′ using () renaming (_/✶_ to _Kind′/✶_)\n\n -- Application of multiple substitutions commutes with conversion to\n -- eliminations.\n\n ⌜⌝-/✶-↑✶ : ∀ k {m n a} (σs : Subs T m n) →\n ⌜ a /✶ σs ↑✶ k ⌝ ≡ ⌜ a ⌝ Elim/✶ σs ↑✶ k\n ⌜⌝-/✶-↑✶ k ε = refl\n ⌜⌝-/✶-↑✶ k (σ ◅ σs) = begin\n ⌜ _ /✶ (σ ◅ σs) ↑✶ k ⌝ ≡⟨ ⌜⌝-/ (_ /✶ σs ↑✶ k) ⟩\n ⌜ _ /✶ σs ↑✶ k ⌝ Elim/ σ ↑⋆ k ≡⟨ cong (_Elim/ _) (⌜⌝-/✶-↑✶ k σs) ⟩\n _ Elim/✶ (σ ◅ σs) ↑✶ k ∎\n\n ⌜⌝Kd-/✶-↑✶ : ∀ k {m n j} (σs : Subs T m n) →\n ⌜ j Kind/✶ σs ↑✶ k ⌝Kd ≡ ⌜ j ⌝Kd Kind′/✶ σs ↑✶ k\n ⌜⌝Kd-/✶-↑✶ k ε = refl\n ⌜⌝Kd-/✶-↑✶ k (σ ◅ σs) = begin\n ⌜ _ Kind/✶ (σ ◅ σs) ↑✶ k ⌝Kd\n ≡⟨ ⌜⌝Kd-/ (_ Kind/✶ σs ↑✶ k) ⟩\n ⌜ _ Kind/✶ σs ↑✶ k ⌝Kd Kind′/ σ ↑⋆ k\n ≡⟨ cong (_Kind′/ _) (⌜⌝Kd-/✶-↑✶ k σs) ⟩\n _ Kind′/✶ (σ ◅ σs) ↑✶ k\n ∎\n\n -- Simplified kinds are stable under application of substitutions.\n\n ⌊⌋-Kind/ : ∀ {m n} (k : Kind Term m) {σ : Sub T m n} → ⌊ k Kind/ σ ⌋ ≡ ⌊ k ⌋\n ⌊⌋-Kind/ (a ⋯ b) = refl\n ⌊⌋-Kind/ (Π j k) = cong₂ _⇒_ (⌊⌋-Kind/ j) (⌊⌋-Kind/ k)\n\n ⌊⌋-Kind′/ : ∀ {m n} (k : Kind Elim m) {σ : Sub T m n} →\n ⌊ k Kind′/ σ ⌋ ≡ ⌊ k ⌋\n ⌊⌋-Kind′/ (a ⋯ b) = refl\n ⌊⌋-Kind′/ (Π j k) = cong₂ _⇒_ (⌊⌋-Kind′/ j) (⌊⌋-Kind′/ k)\n\n -- Application of substitutions to type and kind ascriptions.\n\n open KdOrTpSubstApp simple appKind appTerm public using ()\n renaming (_/_ to _TermAsc/_)\n open KdOrTpSubstApp simple appKind′ appElim public using ()\n renaming (_/_ to _ElimAsc/_)\n\n-- Substitutions in terms and associated lemmas.\n\nmodule Substitution where\n\n -- Term substitutions.\n\n termSubst : TermSubst Term\n termSubst = record { var = var; app = SubstApp._/_ }\n\n -- Variable substitutions (renamings) in heads.\n --\n -- NOTE. The special treatment of heads here reflects the fact that\n -- the structure of heads is preserved by renamings but not by\n -- general term substitutions.\n\n module HeadRenamings where\n open Simple VarSubst.simple hiding (var)\n open SubstApp (TermSubst.varLift termSubst)\n\n infixl 8 _Head/Var_\n\n _Head/Var_ : ∀ {m n} → Head m → Sub Fin m n → Head n\n var x Head/Var σ = var (Vec.lookup σ x)\n ⊥ Head/Var σ = ⊥\n ⊤ Head/Var σ = ⊤\n Π k a Head/Var σ = Π (k Kind′/ σ) (a Elim/ σ ↑)\n (a ⇒ b) Head/Var σ = (a Elim/ σ) ⇒ (b Elim/ σ)\n Λ k a Head/Var σ = Λ (k Kind′/ σ) (a Elim/ σ ↑)\n ƛ a b Head/Var σ = ƛ (a Elim/ σ) (b Elim/ σ ↑)\n (a ⊡ b) Head/Var σ = (a Elim/ σ) ⊡ (b Elim/ σ)\n\n -- A lemma relating the above definition of application to the\n -- previous ones.\n\n Head/Var-∙ : ∀ {m n} {σ : Sub Fin m n} a → (a Head/Var σ) ∙ [] ≡ a Head/ σ\n Head/Var-∙ (var x) = refl\n Head/Var-∙ ⊥ = refl\n Head/Var-∙ ⊤ = refl\n Head/Var-∙ (Π k a) = refl\n Head/Var-∙ (a ⇒ b) = refl\n Head/Var-∙ (Λ k a) = refl\n Head/Var-∙ (ƛ a b) = refl\n Head/Var-∙ (a ⊡ b) = refl\n\n headOf-Head/Var : ∀ {m n} {σ : Sub Fin m n} a →\n a Head/Var σ ≡ headOf (a Head/ σ)\n headOf-Head/Var a = cong headOf (Head/Var-∙ a)\n\n Elim/Var-Head/Var : ∀ {m n} {σ : Sub Fin m n} a →\n a ∙ [] Elim/ σ ≡ (a Head/Var σ) ∙ []\n Elim/Var-Head/Var {σ = σ} a = begin\n a ∙ [] Elim/ σ ≡⟨ ∙∙-[] (a Head/ σ) ⟩\n a Head/ σ ≡⟨ sym (Head/Var-∙ a) ⟩\n (a Head/Var σ) ∙ [] ∎\n\n open HeadRenamings public\n\n -- Lemmas relating application of sequences of generic substitutions\n -- lifted to any number of additional variables.\n --\n -- Using these generic lemmas, we can instantiate the record\n -- Data.Fin.Substitution.Lemmas.TermLemmas below, which gives access\n -- to a number of useful (derived) lemmas about path substitutions.\n\n module Lemmas {T₁ T₂ : ℕ → Set}\n {lift₁ : Lift T₁ Term} {lift₂ : Lift T₂ Term} where\n open SubstApp\n open Lift lift₁ using () renaming (_↑✶_ to _↑✶₁_)\n open Lift lift₂ using () renaming (_↑✶_ to _↑✶₂_)\n open Application (record { _/_ = SubstApp._/_ lift₁ }) using ()\n renaming (_/✶_ to _/✶₁_)\n open Application (record { _/_ = SubstApp._/_ lift₂ }) using ()\n renaming (_/✶_ to _/✶₂_)\n open Application (record { _/_ = SubstApp._Kind/_ lift₁ }) using ()\n renaming (_/✶_ to _Kind/✶₁_)\n open Application (record { _/_ = SubstApp._Kind/_ lift₂ }) using ()\n renaming (_/✶_ to _Kind/✶₂_)\n\n -- Sequences of (lifted) T₁ and T₂-substitutions are equivalent\n -- when applied to raw terms/types/kinds if they are equivalent\n -- when applied to variables.\n\n mutual\n\n /✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →\n ∀ k a → a /✶₁ σs₁ ↑✶₁ k ≡ a /✶₂ σs₂ ↑✶₂ k\n /✶-↑✶ σs₁ σs₂ hyp k (var x) = hyp k x\n /✶-↑✶ σs₁ σs₂ hyp k ⊥ = begin\n ⊥ /✶₁ σs₁ ↑✶₁ k ≡⟨ ⊥-/✶-↑✶ _ k σs₁ ⟩\n ⊥ ≡⟨ sym (⊥-/✶-↑✶ _ k σs₂) ⟩\n ⊥ /✶₂ σs₂ ↑✶₂ k ∎\n /✶-↑✶ σs₁ σs₂ hyp k ⊤ = begin\n ⊤ /✶₁ σs₁ ↑✶₁ k ≡⟨ ⊤-/✶-↑✶ _ k σs₁ ⟩\n ⊤ ≡⟨ sym (⊤-/✶-↑✶ _ k σs₂) ⟩\n ⊤ /✶₂ σs₂ ↑✶₂ k ∎\n /✶-↑✶ σs₁ σs₂ hyp k (Π j a) = begin\n (Π j a) /✶₁ σs₁ ↑✶₁ k\n ≡⟨ Π-/✶-↑✶ _ k σs₁ ⟩\n Π (j Kind/✶₁ σs₁ ↑✶₁ k) (a /✶₁ σs₁ ↑✶₁ suc k)\n ≡⟨ cong₂ Π (Kind/✶-↑✶ σs₁ σs₂ hyp k j) (/✶-↑✶ σs₁ σs₂ hyp (suc k) a) ⟩\n Π (j Kind/✶₂ σs₂ ↑✶₂ k) (a /✶₂ σs₂ ↑✶₂ suc k)\n ≡⟨ sym (Π-/✶-↑✶ _ k σs₂) ⟩\n (Π j a) /✶₂ σs₂ ↑✶₂ k\n ∎\n /✶-↑✶ σs₁ σs₂ hyp k (a ⇒ b) = begin\n (a ⇒ b) /✶₁ σs₁ ↑✶₁ k\n ≡⟨ ⇒-/✶-↑✶ _ k σs₁ ⟩\n (a /✶₁ σs₁ ↑✶₁ k) ⇒ (b /✶₁ σs₁ ↑✶₁ k)\n ≡⟨ cong₂ _⇒_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩\n (a /✶₂ σs₂ ↑✶₂ k) ⇒ (b /✶₂ σs₂ ↑✶₂ k)\n ≡⟨ sym (⇒-/✶-↑✶ _ k σs₂) ⟩\n (a ⇒ b) /✶₂ σs₂ ↑✶₂ k\n ∎\n /✶-↑✶ σs₁ σs₂ hyp k (Λ j a) = begin\n (Λ j a) /✶₁ σs₁ ↑✶₁ k\n ≡⟨ Λ-/✶-↑✶ _ k σs₁ ⟩\n Λ (j Kind/✶₁ σs₁ ↑✶₁ k) (a /✶₁ σs₁ ↑✶₁ suc k)\n ≡⟨ cong₂ Λ (Kind/✶-↑✶ σs₁ σs₂ hyp k j) (/✶-↑✶ σs₁ σs₂ hyp (suc k) a) ⟩\n Λ (j Kind/✶₂ σs₂ ↑✶₂ k) (a /✶₂ σs₂ ↑✶₂ suc k)\n ≡⟨ sym (Λ-/✶-↑✶ _ k σs₂) ⟩\n (Λ j a) /✶₂ σs₂ ↑✶₂ k\n ∎\n /✶-↑✶ σs₁ σs₂ hyp k (ƛ a b) = begin\n (ƛ a b) /✶₁ σs₁ ↑✶₁ k\n ≡⟨ ƛ-/✶-↑✶ _ k σs₁ ⟩\n ƛ (a /✶₁ σs₁ ↑✶₁ k) (b /✶₁ σs₁ ↑✶₁ suc k)\n ≡⟨ cong₂ ƛ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp (suc k) b) ⟩\n ƛ (a /✶₂ σs₂ ↑✶₂ k) (b /✶₂ σs₂ ↑✶₂ suc k)\n ≡⟨ sym (ƛ-/✶-↑✶ _ k σs₂) ⟩\n (ƛ a b) /✶₂ σs₂ ↑✶₂ k\n ∎\n /✶-↑✶ σs₁ σs₂ hyp k (a · b) = begin\n (a · b) /✶₁ σs₁ ↑✶₁ k\n ≡⟨ ·-/✶-↑✶ _ k σs₁ ⟩\n (a /✶₁ σs₁ ↑✶₁ k) · (b /✶₁ σs₁ ↑✶₁ k)\n ≡⟨ cong₂ _·_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩\n (a /✶₂ σs₂ ↑✶₂ k) · (b /✶₂ σs₂ ↑✶₂ k)\n ≡⟨ sym (·-/✶-↑✶ _ k σs₂) ⟩\n (a · b) /✶₂ σs₂ ↑✶₂ k\n ∎\n /✶-↑✶ σs₁ σs₂ hyp k (a ⊡ b) = begin\n (a ⊡ b) /✶₁ σs₁ ↑✶₁ k\n ≡⟨ ⊡-/✶-↑✶ _ k σs₁ ⟩\n (a /✶₁ σs₁ ↑✶₁ k) ⊡ (b /✶₁ σs₁ ↑✶₁ k)\n ≡⟨ cong₂ _⊡_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩\n (a /✶₂ σs₂ ↑✶₂ k) ⊡ (b /✶₂ σs₂ ↑✶₂ k)\n ≡⟨ sym (⊡-/✶-↑✶ _ k σs₂) ⟩\n (a ⊡ b) /✶₂ σs₂ ↑✶₂ k\n ∎\n\n Kind/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →\n ∀ k j → j Kind/✶₁ σs₁ ↑✶₁ k ≡ j Kind/✶₂ σs₂ ↑✶₂ k\n Kind/✶-↑✶ σs₁ σs₂ hyp k (a ⋯ b) = begin\n (a ⋯ b) Kind/✶₁ σs₁ ↑✶₁ k\n ≡⟨ ⋯-Kind/✶-↑✶ _ k σs₁ ⟩\n (a /✶₁ σs₁ ↑✶₁ k) ⋯ (b /✶₁ σs₁ ↑✶₁ k)\n ≡⟨ cong₂ _⋯_ (/✶-↑✶ σs₁ σs₂ hyp k a) (/✶-↑✶ σs₁ σs₂ hyp k b) ⟩\n (a /✶₂ σs₂ ↑✶₂ k) ⋯ (b /✶₂ σs₂ ↑✶₂ k)\n ≡⟨ sym (⋯-Kind/✶-↑✶ _ k σs₂) ⟩\n (a ⋯ b) Kind/✶₂ σs₂ ↑✶₂ k\n ∎\n Kind/✶-↑✶ σs₁ σs₂ hyp k (Π j l) = begin\n (Π j l) Kind/✶₁ σs₁ ↑✶₁ k\n ≡⟨ Π-Kind/✶-↑✶ _ k σs₁ ⟩\n Π (j Kind/✶₁ σs₁ ↑✶₁ k) (l Kind/✶₁ σs₁ ↑✶₁ suc k)\n ≡⟨ cong₂ Π (Kind/✶-↑✶ σs₁ σs₂ hyp k j)\n (Kind/✶-↑✶ σs₁ σs₂ hyp (suc k) l) ⟩\n Π (j Kind/✶₂ σs₂ ↑✶₂ k) (l Kind/✶₂ σs₂ ↑✶₂ suc k)\n ≡⟨ sym (Π-Kind/✶-↑✶ _ k σs₂) ⟩\n (Π j l) Kind/✶₂ σs₂ ↑✶₂ k\n ∎\n\n open Application (record { _/_ = SubstApp._Elim/_ lift₁ }) using ()\n renaming (_/✶_ to _Elim/✶₁_)\n open Application (record { _/_ = SubstApp._Elim/_ lift₂ }) using ()\n renaming (_/✶_ to _Elim/✶₂_)\n\n Elim/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →\n ∀ k a → a Elim/✶₁ σs₁ ↑✶₁ k ≡ a Elim/✶₂ σs₂ ↑✶₂ k\n Elim/✶-↑✶ σs₁ σs₂ hyp k a = begin\n a Elim/✶₁ σs₁ ↑✶₁ k\n ≡⟨ sym (cong (_Elim/✶₁ σs₁ ↑✶₁ k) (⌜⌝∘⌞⌟-id a)) ⟩\n ⌜ ⌞ a ⌟ ⌝ Elim/✶₁ σs₁ ↑✶₁ k\n ≡⟨ sym (⌜⌝-/✶-↑✶ _ k σs₁) ⟩\n ⌜ ⌞ a ⌟ /✶₁ σs₁ ↑✶₁ k ⌝\n ≡⟨ cong ⌜_⌝ (/✶-↑✶ σs₁ σs₂ hyp k ⌞ a ⌟) ⟩\n ⌜ ⌞ a ⌟ /✶₂ σs₂ ↑✶₂ k ⌝\n ≡⟨ ⌜⌝-/✶-↑✶ _ k σs₂ ⟩\n ⌜ ⌞ a ⌟ ⌝ Elim/✶₂ σs₂ ↑✶₂ k\n ≡⟨ cong (_Elim/✶₂ σs₂ ↑✶₂ k) (⌜⌝∘⌞⌟-id a) ⟩\n a Elim/✶₂ σs₂ ↑✶₂ k\n ∎\n\n open Application (record { _/_ = SubstApp._Kind′/_ lift₁ }) using ()\n renaming (_/✶_ to _Kind′/✶₁_)\n open Application (record { _/_ = SubstApp._Kind′/_ lift₂ }) using ()\n renaming (_/✶_ to _Kind′/✶₂_)\n\n Kind′/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → var x /✶₁ σs₁ ↑✶₁ k ≡ var x /✶₂ σs₂ ↑✶₂ k) →\n ∀ k j → j Kind′/✶₁ σs₁ ↑✶₁ k ≡ j Kind′/✶₂ σs₂ ↑✶₂ k\n Kind′/✶-↑✶ σs₁ σs₂ hyp k j = begin\n j Kind′/✶₁ σs₁ ↑✶₁ k\n ≡⟨ sym (cong (_Kind′/✶₁ σs₁ ↑✶₁ k) (⌜⌝Kd∘⌞⌟Kd-id j)) ⟩\n ⌜ ⌞ j ⌟Kd ⌝Kd Kind′/✶₁ σs₁ ↑✶₁ k\n ≡⟨ sym (⌜⌝Kd-/✶-↑✶ _ k σs₁) ⟩\n ⌜ ⌞ j ⌟Kd Kind/✶₁ σs₁ ↑✶₁ k ⌝Kd\n ≡⟨ cong ⌜_⌝Kd (Kind/✶-↑✶ σs₁ σs₂ hyp k ⌞ j ⌟Kd) ⟩\n ⌜ ⌞ j ⌟Kd Kind/✶₂ σs₂ ↑✶₂ k ⌝Kd\n ≡⟨ ⌜⌝Kd-/✶-↑✶ _ k σs₂ ⟩\n ⌜ ⌞ j ⌟Kd ⌝Kd Kind′/✶₂ σs₂ ↑✶₂ k\n ≡⟨ cong (_Kind′/✶₂ σs₂ ↑✶₂ k) (⌜⌝Kd∘⌞⌟Kd-id j) ⟩\n j Kind′/✶₂ σs₂ ↑✶₂ k\n ∎\n\n -- Lemmas relating application of sequences of generic substitutions\n -- in generic kind or type ascriptions, provided substitutions on\n -- the underlying kinds or types are similarly related.\n\n record KdOrTpLemmas {T₁ T₂ T′ : ℕ → Set}\n (lift₁ : Lift T₁ Term)\n (lift₂ : Lift T₂ Term)\n : Set where\n field\n kdApp₁ : Application (Kind T′) T₁\n kdApp₂ : Application (Kind T′) T₂\n tpApp₁ : Application T′ T₁\n tpApp₂ : Application T′ T₂\n\n open Lift lift₁ using () renaming (_↑✶_ to _↑✶₁_)\n open Lift lift₂ using () renaming (_↑✶_ to _↑✶₂_)\n private\n module A₁ = Application (record { _/_ = SubstApp._/_ lift₁ })\n module A₂ = Application (record { _/_ = SubstApp._/_ lift₂ })\n module T₁ = Application tpApp₁\n module T₂ = Application tpApp₂\n module K₁ = Application kdApp₁\n module K₂ = Application kdApp₂\n module KT₁ = KdOrTpSubstApp (Lift.simple lift₁) kdApp₁ tpApp₁\n module KT₂ = KdOrTpSubstApp (Lift.simple lift₂) kdApp₂ tpApp₂\n\n -- Sequences of (lifted) T₁ and T₂-substitutions are equivalent\n -- when applied to kinds and raw types (represented as T′s) if\n -- they are equivalent when applied to variables (represented as\n -- raw terms).\n\n field\n Kd/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → var x A₁./✶ σs₁ ↑✶₁ k ≡ var x A₂./✶ σs₂ ↑✶₂ k) →\n ∀ k a → a K₁./✶ σs₁ ↑✶₁ k ≡ a K₂./✶ σs₂ ↑✶₂ k\n\n Tp/✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → var x A₁./✶ σs₁ ↑✶₁ k ≡ var x A₂./✶ σs₂ ↑✶₂ k) →\n ∀ k a → a T₁./✶ σs₁ ↑✶₁ k ≡ a T₂./✶ σs₂ ↑✶₂ k\n\n /✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) →\n (∀ k x → var x A₁./✶ σs₁ ↑✶₁ k ≡ var x A₂./✶ σs₂ ↑✶₂ k) →\n ∀ k a → a KT₁./✶ σs₁ ↑✶₁ k ≡ a KT₂./✶ σs₂ ↑✶₂ k\n /✶-↑✶ σs₁ σs₂ hyp k (kd j) = begin\n kd j KT₁./✶ σs₁ ↑✶₁ k ≡⟨ KT₁.kd-/✶-↑✶ k σs₁ ⟩\n kd (j K₁./✶ σs₁ ↑✶₁ k) ≡⟨ cong kd (Kd/✶-↑✶ σs₁ σs₂ hyp k j) ⟩\n kd (j K₂./✶ σs₂ ↑✶₂ k) ≡⟨ sym (KT₂.kd-/✶-↑✶ k σs₂) ⟩\n kd j KT₂./✶ σs₂ ↑✶₂ k ∎\n /✶-↑✶ σs₁ σs₂ hyp k (tp a) = begin\n tp a KT₁./✶ σs₁ ↑✶₁ k ≡⟨ KT₁.tp-/✶-↑✶ k σs₁ ⟩\n tp (a T₁./✶ σs₁ ↑✶₁ k) ≡⟨ cong tp (Tp/✶-↑✶ σs₁ σs₂ hyp k a) ⟩\n tp (a T₂./✶ σs₂ ↑✶₂ k) ≡⟨ sym (KT₂.tp-/✶-↑✶ k σs₂) ⟩\n tp a KT₂./✶ σs₂ ↑✶₂ k ∎\n\n termAscLemmas : ∀ {T₁ T₂} lift₁ lift₂ → KdOrTpLemmas {T₁} {T₂} lift₁ lift₂\n termAscLemmas lift₁ lift₂ = record\n { kdApp₁ = record { _/_ = SubstApp._Kind/_ lift₁ }\n ; kdApp₂ = record { _/_ = SubstApp._Kind/_ lift₂ }\n ; tpApp₁ = record { _/_ = SubstApp._/_ lift₁ }\n ; tpApp₂ = record { _/_ = SubstApp._/_ lift₂ }\n ; Kd/✶-↑✶ = Lemmas.Kind/✶-↑✶\n ; Tp/✶-↑✶ = Lemmas./✶-↑✶\n }\n\n elimAscLemmas : ∀ {T₁ T₂} lift₁ lift₂ → KdOrTpLemmas {T₁} {T₂} lift₁ lift₂\n elimAscLemmas lift₁ lift₂ = record\n { kdApp₁ = record { _/_ = SubstApp._Kind′/_ lift₁ }\n ; kdApp₂ = record { _/_ = SubstApp._Kind′/_ lift₂ }\n ; tpApp₁ = record { _/_ = SubstApp._Elim/_ lift₁ }\n ; tpApp₂ = record { _/_ = SubstApp._Elim/_ lift₂ }\n ; Kd/✶-↑✶ = Lemmas.Kind′/✶-↑✶\n ; Tp/✶-↑✶ = Lemmas.Elim/✶-↑✶\n }\n\n -- By instantiating TermLemmas, we get access to a number of useful\n -- (derived) lemmas about path substitutions.\n\n termLemmas : TermLemmas Term\n termLemmas = record\n { termSubst = termSubst\n ; app-var = refl\n ; /✶-↑✶ = Lemmas./✶-↑✶\n }\n\n open TermLemmas termLemmas public hiding (var; termSubst; weaken-sub)\n open SubstApp (TermSubst.termLift termSubst) public using\n ( _Head/_; _//_\n ; ++-//; ∙∙-/; ⌜·⌝-/; ⌜⌝-/; ⌜⌝Kd-/; ⌞⌟-/; ⌞⌟Kd-/; ⌊⌋-Kind/; ⌊⌋-Kind′/\n )\n open SubstApp (TermSubst.varLift termSubst) public using () renaming\n ( _Head/_ to _Head/Var′_\n ; _//_ to _//Var_\n ; ++-// to ++-//Var\n ; ∙∙-/ to ∙∙-/Var\n ; ⌜·⌝-/ to ⌜·⌝-/Var\n ; ⌜⌝-/ to ⌜⌝-/Var\n ; ⌜⌝Kd-/ to ⌜⌝Kd-/Var\n ; ⌞⌟-/ to ⌞⌟-/Var\n ; ⌞⌟Kd-/ to ⌞⌟Kd-/Var\n ; ⌊⌋-Kind/ to ⌊⌋-Kind/Var\n ; ⌊⌋-Kind′/ to ⌊⌋-Kind′/Var\n )\n\n -- By instantiating TermLikeLemmas, we get access to a number of\n -- useful (derived) lemmas about variable substitutions (renamings)\n -- and substitutions in kinds, eliminations and ascriptions.\n\n private\n termLikeLemmas : TermLikeLemmas Term Term\n termLikeLemmas = record\n { app = SubstApp._/_\n ; termLemmas = termLemmas\n ; /✶-↑✶₁ = Lemmas./✶-↑✶\n ; /✶-↑✶₂ = Lemmas./✶-↑✶\n }\n\n open TermLikeLemmas termLikeLemmas public using\n ( varLiftAppLemmas; varLiftSubLemmas; _/Var_\n ; weaken-sub; weaken-/; weaken⋆; /-wk⋆\n )\n\n termLikeLemmasKind : TermLikeLemmas (Kind Term) Term\n termLikeLemmasKind = record\n { app = SubstApp._Kind/_\n ; termLemmas = termLemmas\n ; /✶-↑✶₁ = Lemmas.Kind/✶-↑✶\n ; /✶-↑✶₂ = Lemmas.Kind/✶-↑✶\n }\n\n open TermLikeLemmas termLikeLemmasKind public using () renaming\n ( _/_ to _Kind/_\n ; _/Var_ to _Kind/Var_\n ; weaken to weakenKind\n ; weaken⋆ to weakenKind⋆\n )\n\n termLikeLemmasElim : TermLikeLemmas Elim Term\n termLikeLemmasElim = record\n { app = SubstApp._Elim/_\n ; termLemmas = termLemmas\n ; /✶-↑✶₁ = Lemmas.Elim/✶-↑✶\n ; /✶-↑✶₂ = Lemmas.Elim/✶-↑✶\n }\n\n open TermLikeLemmas termLikeLemmasElim public using () renaming\n ( _/_ to _Elim/_\n ; _/Var_ to _Elim/Var_\n ; weaken to weakenElim\n ; weaken⋆ to weakenElim⋆\n )\n\n termLikeLemmasKind′ : TermLikeLemmas (Kind Elim) Term\n termLikeLemmasKind′ = record\n { app = SubstApp._Kind′/_\n ; termLemmas = termLemmas\n ; /✶-↑✶₁ = Lemmas.Kind′/✶-↑✶\n ; /✶-↑✶₂ = Lemmas.Kind′/✶-↑✶\n }\n\n open TermLikeLemmas termLikeLemmasKind′ public using () renaming\n ( _/_ to _Kind′/_\n ; _/Var_ to _Kind′/Var_\n ; weaken to weakenKind′\n ; weaken⋆ to weakenKind′⋆\n )\n\n termLikeLemmasTermAsc : TermLikeLemmas TermAsc Term\n termLikeLemmasTermAsc = record\n { app = SubstApp._TermAsc/_\n ; termLemmas = termLemmas\n ; /✶-↑✶₁ = KdOrTpLemmas./✶-↑✶ (termAscLemmas _ _)\n ; /✶-↑✶₂ = KdOrTpLemmas./✶-↑✶ (termAscLemmas _ _)\n }\n\n open TermLikeLemmas termLikeLemmasTermAsc public using () renaming\n ( termLikeSubst to termAscTermSubst\n ; _/_ to _TermAsc/_\n ; _/Var_ to _TermAsc/Var_\n ; weaken to weakenTermAsc\n )\n\n termLikeLemmasElimAsc : TermLikeLemmas ElimAsc Term\n termLikeLemmasElimAsc = record\n { app = SubstApp._ElimAsc/_\n ; termLemmas = termLemmas\n ; /✶-↑✶₁ = KdOrTpLemmas./✶-↑✶ (elimAscLemmas _ _)\n ; /✶-↑✶₂ = KdOrTpLemmas./✶-↑✶ (elimAscLemmas _ _)\n }\n\n open TermLikeLemmas termLikeLemmasElimAsc public using () renaming\n ( termLikeSubst to elimAscTermSubst\n ; _/_ to _ElimAsc/_\n ; _/Var_ to _ElimAsc/Var_\n ; weaken to weakenElimAsc\n ; weaken⋆ to weakenElimAsc⋆\n )\n\n -- Weakening of heads and spines.\n\n weakenHead : ∀ {n} → Head n → Head (suc n)\n weakenHead a = a Head/Var VarSubst.wk\n\n weakenSpine : ∀ {n} → Spine n → Spine (suc n)\n weakenSpine a = a //Var VarSubst.wk\n\n -- Conversion of ascriptions commutes with weakening.\n\n ⌜⌝Asc-weaken : ∀ {n} (a : TermAsc n) →\n ⌜ weakenTermAsc a ⌝Asc ≡ weakenElimAsc ⌜ a ⌝Asc\n ⌜⌝Asc-weaken (kd k) = cong kd (⌜⌝Kd-/Var k)\n ⌜⌝Asc-weaken (tp a) = cong tp (⌜⌝-/Var a)\n\n ⌞⌟Asc-weaken : ∀ {n} (a : ElimAsc n) →\n ⌞ weakenElimAsc a ⌟Asc ≡ weakenTermAsc ⌞ a ⌟Asc\n ⌞⌟Asc-weaken (kd k) = cong kd (⌞⌟Kd-/Var k)\n ⌞⌟Asc-weaken (tp a) = cong tp (⌞⌟-/Var a)\n\n -- Simplified kinds are stable under weakening.\n\n ⌊⌋-weaken : ∀ {n} (k : Kind Term n) → ⌊ weakenKind k ⌋ ≡ ⌊ k ⌋\n ⌊⌋-weaken k = ⌊⌋-Kind/Var k\n\n ⌊⌋-weaken′ : ∀ {n} (k : Kind Elim n) → ⌊ weakenKind′ k ⌋ ≡ ⌊ k ⌋\n ⌊⌋-weaken′ k = ⌊⌋-Kind′/Var k\n\n ⌊⌋-weaken⋆′ : ∀ {m} n (k : Kind Elim m) → ⌊ weakenKind′⋆ n k ⌋ ≡ ⌊ k ⌋\n ⌊⌋-weaken⋆′ zero k = refl\n ⌊⌋-weaken⋆′ (suc n) k = begin\n ⌊ weakenKind′ (weakenKind′⋆ n k) ⌋ ≡⟨ ⌊⌋-weaken′ (weakenKind′⋆ n k) ⟩\n ⌊ weakenKind′⋆ n k ⌋ ≡⟨ ⌊⌋-weaken⋆′ n k ⟩\n ⌊ k ⌋ ∎\n\n infix 10 _[_] _Elim[_] _Kind[_] _Kind′[_] _TermAsc[_] _ElimAsc[_]\n\n -- Shorthands for single-variable term substitutions.\n\n _[_] : ∀ {n} → Term (suc n) → Term n → Term n\n a [ b ] = a / sub b\n\n _Elim[_] : ∀ {n} → Elim (suc n) → Term n → Elim n\n a Elim[ b ] = a Elim/ sub b\n\n _Kind[_] : ∀ {n} → Kind Term (suc n) → Term n → Kind Term n\n k Kind[ b ] = k Kind/ (sub b)\n\n _Kind′[_] : ∀ {n} → Kind Elim (suc n) → Term n → Kind Elim n\n k Kind′[ b ] = k Kind′/ (sub b)\n\n _TermAsc[_] : ∀ {n} → TermAsc (suc n) → Term n → TermAsc n\n a TermAsc[ b ] = a TermAsc/ sub b\n\n _ElimAsc[_] : ∀ {n} → ElimAsc (suc n) → Term n → ElimAsc n\n a ElimAsc[ b ] = a ElimAsc/ sub b\n\n private module V = VarSubst\n\n -- Kinds are stable under substitutions of a variable for a fresh\n -- variable (up to α-equivalence).\n\n Kind-wk↑-sub-zero-vanishes : ∀ {n} (k : Kind Term (suc n)) →\n (k Kind/Var V.wk V.↑) Kind[ var zero ] ≡ k\n Kind-wk↑-sub-zero-vanishes k = begin\n (k Kind/Var V.wk V.↑) Kind[ var zero ]\n ≡⟨ sym (KL./-sub (k Kind/Var _) zero) ⟩\n k Kind/Var V.wk V.↑ Kind/Var V.sub zero\n ≡⟨ sym (LiftAppLemmas./-⊙ KL.varLiftAppLemmas k) ⟩\n k Kind/Var V.wk V.↑ V.⊙ V.sub zero\n ≡⟨⟩\n k Kind/Var (zero ∷ (Vec.map suc V.wk V.⊙ V.sub zero))\n ≡⟨ cong (λ σ → k Kind/Var (zero ∷ σ)) VarLemmas.map-weaken-⊙-sub ⟩\n k Kind/Var (zero ∷ V.wk)\n ≡⟨⟩\n k Kind/Var V.id\n ≡⟨ LiftAppLemmas.id-vanishes KL.varLiftAppLemmas k ⟩\n k\n ∎\n where\n open ≡-Reasoning\n module KL = TermLikeLemmas termLikeLemmasKind\n\n\n----------------------------------------------------------------------\n-- Typing contexts containing kind and type ascriptions.\n\n-- Generic typing contexts over T-ascriptions and useful operations.\n\nrecord KdOrTpCtx (T : ℕ → Set) : Set₁ where\n open Context public hiding (Ctx; CtxExt)\n\n -- Contexts and context extensions.\n\n Ctx = Context.Ctx (KdOrTp T)\n CtxExt = Context.CtxExt (KdOrTp T)\n\n -- Operations such as context lookup and substitutions in context\n -- extensions require some extra substitution machinery for\n -- T-ascriptions, all of which is provided by the following instance\n -- of TermLikeLemmas.\n\n field termLikeLemmas : TermLikeLemmas (KdOrTp T) Term\n open TermLikeLemmas termLikeLemmas\n using (termApplication; weaken; termLemmas)\n open TermLemmas termLemmas using (simple)\n\n weakenOps : Extension (KdOrTp T)\n weakenOps = record { weaken = weaken }\n\n open WeakenOps weakenOps public hiding (weaken; weaken⋆)\n open WeakenOpsLemmas weakenOps public\n open ConversionLemmas weakenOps weakenOps public\n\n open SubstOps termApplication simple public using (_E/_)\n\nopen Substitution\n\n-- Concrete typing contexts over raw term and raw elimination\n-- ascriptions.\n\ntermCtx : KdOrTpCtx Term\ntermCtx = record { termLikeLemmas = termLikeLemmasTermAsc }\nmodule TermCtx = KdOrTpCtx termCtx\n\nelimCtx : KdOrTpCtx Elim\nelimCtx = record { termLikeLemmas = termLikeLemmasElimAsc }\nmodule ElimCtx = KdOrTpCtx elimCtx\n\n-- Concrete typing contexts over shape ascriptions and useful\n-- operations.\n\nmodule SimpleCtx where\n open Context public hiding (Ctx; CtxExt)\n open Maybe public using (Maybe) renaming (just to kd; nothing to tp)\n\n -- Shape ascriptions.\n --\n -- NOTE. We only use shape ascriptions (or \"simple\" kind\n -- ascriptions) in the simplified kinding system, which is defined\n -- exclusively on types (see the FOmegaInt.Kinding.Simple module).\n -- Because simple kinding judgments can never refer to term\n -- variables, we may as well forget the type of such variables. We\n -- just need to remember that there are such variables in the\n -- context so as to maintain the de Bruijn indexes of (type)\n -- variables, e.g. when we convert full kinding judgments to\n -- simplified ones. Accordingly, we implement shape ascriptions\n -- using `Maybe' from the standard library, but with the\n -- constructors `just' and `nothing' renamed to `kd' and `tp' to\n -- better reflect their meaning. (This renaming happens during the\n -- import of the `Maybe' module above.)\n\n SAsc : ℕ → Set\n SAsc _ = Maybe SKind\n\n -- Simplification/erasure of ascriptions.\n\n ⌊_⌋Asc : ∀ {T n} → KdOrTp T n → SAsc n\n ⌊ kd k ⌋Asc = kd ⌊ k ⌋\n ⌊ tp a ⌋Asc = tp\n\n -- Injectivity of the (simple) `kd' constructor.\n\n kd-inj′ : {j k : SKind} → _≡_ {A = Maybe SKind} (kd j) (kd k) → j ≡ k\n kd-inj′ refl = refl\n\n -- Contexts and context extensions over shape ascriptions.\n\n Ctx = Context.Ctx SAsc\n CtxExt = Context.CtxExt SAsc\n\n weakenOps : Extension SAsc\n weakenOps = record { weaken = Function.id }\n\n open WeakenOps weakenOps public hiding (weaken; weaken⋆)\n open WeakenOpsLemmas weakenOps public\n open ConversionLemmas weakenOps weakenOps public\n\n -- Change the indexing of a context extension.\n\n re-idx : ∀ {k m n} → CtxExt k n → CtxExt m n\n re-idx Γ = mapExt (λ _ k → k) Γ\n\n open Extension weakenOps public using () renaming (weaken⋆ to weakenSAsc⋆)\n\n weakenSAsc⋆-id : ∀ m {n a} → weakenSAsc⋆ m {n} a ≡ a\n weakenSAsc⋆-id zero = refl\n weakenSAsc⋆-id (suc m) = weakenSAsc⋆-id m\n\n ⌊⌋-TermAsc/ : ∀ {m n} a {σ : Sub Term m n} → ⌊ a TermAsc/ σ ⌋Asc ≡ ⌊ a ⌋Asc\n ⌊⌋-TermAsc/ (kd k) = cong kd (⌊⌋-Kind/ k)\n ⌊⌋-TermAsc/ (tp t) = refl\n\n ⌊⌋-ElimAsc/ : ∀ {m n} a {σ : Sub Term m n} → ⌊ a ElimAsc/ σ ⌋Asc ≡ ⌊ a ⌋Asc\n ⌊⌋-ElimAsc/ (kd k) = cong kd (⌊⌋-Kind′/ k)\n ⌊⌋-ElimAsc/ (tp t) = refl\n\n ⌊⌋-ElimAsc/Var : ∀ {m n} a {σ : Sub Fin m n} →\n ⌊ a ElimAsc/Var σ ⌋Asc ≡ ⌊ a ⌋Asc\n ⌊⌋-ElimAsc/Var (kd k) = cong kd (⌊⌋-Kind′/Var k)\n ⌊⌋-ElimAsc/Var (tp t) = refl\n\n-- Conversions between the different context representations.\n\nmodule ContextConversions where\n open Context\n open SimpleCtx using (kd; ⌊_⌋Asc; ⌊⌋-ElimAsc/Var)\n\n ⌞_⌟Ctx : ∀ {n} → ElimCtx.Ctx n → TermCtx.Ctx n\n ⌞ Γ ⌟Ctx = ElimCtx.map ⌞_⌟Asc Γ\n\n ⌜_⌝Ctx : ∀ {n} → TermCtx.Ctx n → ElimCtx.Ctx n\n ⌜ Γ ⌝Ctx = TermCtx.map ⌜_⌝Asc Γ\n\n ⌊_⌋Ctx : ∀ {T n} → Ctx (KdOrTp T) n → SimpleCtx.Ctx n\n ⌊ Γ ⌋Ctx = SimpleCtx.map ⌊_⌋Asc Γ\n\n ⌊_⌋CtxExt : ∀ {T m n} → CtxExt (KdOrTp T) m n → SimpleCtx.CtxExt m n\n ⌊ Γ ⌋CtxExt = SimpleCtx.mapExt (λ _ → ⌊_⌋Asc) Γ\n\n module ⌞⌟Ctx-Lemmas = ConversionLemmas ElimCtx.weakenOps TermCtx.weakenOps\n module ⌜⌝Ctx-Lemmas = ConversionLemmas TermCtx.weakenOps ElimCtx.weakenOps\n module ⌊⌋Ctx-Lemmas = ConversionLemmas ElimCtx.weakenOps SimpleCtx.weakenOps\n\n -- Context conversions commute with context lookup.\n\n ⌞⌟Asc-lookup : ∀ {n} (Γ : ElimCtx.Ctx n) x →\n TermCtx.lookup ⌞ Γ ⌟Ctx x ≡ ⌞ ElimCtx.lookup Γ x ⌟Asc\n ⌞⌟Asc-lookup Γ x =\n ⌞⌟Ctx-Lemmas.lookup-map ⌞_⌟Asc Γ x (λ a → sym (⌞⌟Asc-weaken a))\n\n ⌜⌝Asc-lookup : ∀ {n} (Γ : TermCtx.Ctx n) x →\n ElimCtx.lookup ⌜ Γ ⌝Ctx x ≡ ⌜ TermCtx.lookup Γ x ⌝Asc\n ⌜⌝Asc-lookup Γ x =\n ⌜⌝Ctx-Lemmas.lookup-map ⌜_⌝Asc Γ x (λ a → sym (⌜⌝Asc-weaken a))\n\n ⌊⌋Asc-lookup : ∀ {n} (Γ : ElimCtx.Ctx n) x →\n SimpleCtx.lookup ⌊ Γ ⌋Ctx x ≡ ⌊ ElimCtx.lookup Γ x ⌋Asc\n ⌊⌋Asc-lookup Γ x =\n ⌊⌋Ctx-Lemmas.lookup-map ⌊_⌋Asc Γ x (λ a → sym (⌊⌋-ElimAsc/Var a))\n\n ⌊⌋-lookup : ∀ {n} (Γ : ElimCtx.Ctx n) x {k} → ElimCtx.lookup Γ x ≡ kd k →\n SimpleCtx.lookup ⌊ Γ ⌋Ctx x ≡ kd ⌊ k ⌋\n ⌊⌋-lookup Γ x {k} Γ[x]≡kd-k = begin\n SimpleCtx.lookup ⌊ Γ ⌋Ctx x\n ≡⟨ ⌊⌋Asc-lookup Γ x ⟩\n ⌊ ElimCtx.lookup Γ x ⌋Asc\n ≡⟨ cong ⌊_⌋Asc Γ[x]≡kd-k ⟩\n kd ⌊ k ⌋\n ∎\n where open ≡-Reasoning\n", "meta": {"hexsha": "05ba78191488d0c19bd9143474b036c002b768d1", "size": 51471, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/FOmegaInt/Syntax.agda", "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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/FOmegaInt/Syntax.agda", "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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/FOmegaInt/Syntax.agda", "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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": 36.2727272727, "max_line_length": 80, "alphanum_fraction": 0.5107730567, "num_tokens": 24250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.36667037067587877}} {"text": "{-# OPTIONS --without-K --exact-split --safe #-}\n\nmodule Fragment.Extensions.CSemigroup.Base where\n\nopen import Fragment.Equational.Theory.Bundles\n\nopen import Fragment.Algebra.Signature\nopen import Fragment.Algebra.Free Σ-magma hiding (_~_)\nopen import Fragment.Algebra.Homomorphism Σ-magma\nopen import Fragment.Algebra.Algebra Σ-magma\n using (Algebra; IsAlgebra; Interpretation; Congruence)\n\nopen import Fragment.Equational.FreeExtension Θ-csemigroup\n using (FreeExtension; IsFreeExtension)\nopen import Fragment.Equational.Model Θ-csemigroup\nopen import Fragment.Extensions.CSemigroup.Monomial\n\nopen import Fragment.Setoid.Morphism using (_↝_)\n\nopen import Level using (Level; _⊔_)\n\nopen import Data.Nat using (ℕ)\nopen import Data.Fin using (#_)\n\nopen import Data.Vec using (Vec; []; _∷_; map)\nopen import Data.Vec.Relation.Binary.Pointwise.Inductive using ([]; _∷_)\n\nimport Relation.Binary.Reasoning.Setoid as Reasoning\nopen import Relation.Binary using (Setoid; IsEquivalence)\nopen import Relation.Binary.PropositionalEquality as PE using (_≡_)\n\nprivate\n variable\n a ℓ : Level\n\nmodule _ (A : Model {a} {ℓ}) (n : ℕ) where\n\n private\n\n open module A = Setoid ∥ A ∥/≈\n\n _·_ : ∥ A ∥ → ∥ A ∥ → ∥ A ∥\n x · y = A ⟦ • ⟧ (x ∷ y ∷ [])\n\n ·-cong : ∀ {x y z w} → x ≈ y → z ≈ w → x · z ≈ y · w\n ·-cong x≈y z≈w = (A ⟦ • ⟧-cong) (x≈y ∷ z≈w ∷ [])\n\n ·-comm : ∀ (x y : ∥ A ∥) → x · y ≈ y · x\n ·-comm x y = ∥ A ∥ₐ-models comm (env {A = ∥ A ∥ₐ} (x ∷ y ∷ []))\n\n ·-assoc : ∀ (x y z : ∥ A ∥) → (x · y) · z ≈ x · (y · z)\n ·-assoc x y z = ∥ A ∥ₐ-models assoc (env {A = ∥ A ∥ₐ} (x ∷ y ∷ z ∷ []))\n\n data Blob : Set a where\n sta : ∥ A ∥ → Blob\n dyn : ∥ J' n ∥ → Blob\n blob : ∥ J' n ∥ → ∥ A ∥ → Blob\n\n infix 6 _≋_\n\n data _≋_ : Blob → Blob → Set (a ⊔ ℓ) where\n sta : ∀ {x y} → x ≈ y → sta x ≋ sta y\n dyn : ∀ {xs ys} → xs ≡ ys → dyn xs ≋ dyn ys\n blob : ∀ {x y xs ys} → xs ≡ ys → x ≈ y\n → blob xs x ≋ blob ys y\n\n ≋-refl : ∀ {x} → x ≋ x\n ≋-refl {x = sta x} = sta A.refl\n ≋-refl {x = dyn xs} = dyn PE.refl\n ≋-refl {x = blob xs x} = blob PE.refl A.refl\n\n ≋-sym : ∀ {x y} → x ≋ y → y ≋ x\n ≋-sym (sta p) = sta (A.sym p)\n ≋-sym (dyn ps) = dyn (PE.sym ps)\n ≋-sym (blob ps p) = blob (PE.sym ps) (A.sym p)\n\n ≋-trans : ∀ {x y z} → x ≋ y → y ≋ z → x ≋ z\n ≋-trans (sta p) (sta q) = sta (A.trans p q)\n ≋-trans (dyn ps) (dyn qs) = dyn (PE.trans ps qs)\n ≋-trans (blob ps p) (blob qs q) = blob (PE.trans ps qs) (A.trans p q)\n\n ≋-isEquivalence : IsEquivalence _≋_\n ≋-isEquivalence = record { refl = ≋-refl\n ; sym = ≋-sym\n ; trans = ≋-trans\n }\n\n Blob/≋ : Setoid _ _\n Blob/≋ = record { Carrier = Blob\n ; _≈_ = _≋_\n ; isEquivalence = ≋-isEquivalence\n }\n\n _++_ : Blob → Blob → Blob\n sta x ++ sta y = sta (x · y)\n dyn xs ++ dyn ys = dyn (xs ⊗ ys)\n sta x ++ dyn ys = blob ys x\n sta x ++ blob ys y = blob ys (x · y)\n dyn xs ++ sta y = blob xs y\n dyn xs ++ blob ys y = blob (xs ⊗ ys) y\n blob xs x ++ sta y = blob xs (x · y)\n blob xs x ++ dyn ys = blob (xs ⊗ ys) x\n blob xs x ++ blob ys y = blob (xs ⊗ ys) (x · y)\n\n ++-cong : ∀ {x y z w} → x ≋ y → z ≋ w → x ++ z ≋ y ++ w\n ++-cong (sta p) (sta q) = sta (·-cong p q)\n ++-cong (dyn ps) (dyn qs) = dyn (⊗-cong ps qs)\n ++-cong (sta p) (dyn qs) = blob qs p\n ++-cong (sta p) (blob qs q) = blob qs (·-cong p q)\n ++-cong (dyn ps) (sta q) = blob ps q\n ++-cong (dyn ps) (blob qs q) = blob (⊗-cong ps qs) q\n ++-cong (blob ps p) (sta q) = blob ps (·-cong p q)\n ++-cong (blob ps p) (dyn qs) = blob (⊗-cong ps qs) p\n ++-cong (blob ps p) (blob qs q) = blob (⊗-cong ps qs) (·-cong p q)\n\n ++-comm : ∀ x y → x ++ y ≋ y ++ x\n ++-comm (sta x) (sta y) = sta (·-comm x y)\n ++-comm (dyn xs) (dyn ys) = dyn (⊗-comm xs ys)\n ++-comm (sta x) (dyn ys) = ≋-refl\n ++-comm (sta x) (blob ys y) = blob PE.refl (·-comm x y)\n ++-comm (dyn xs) (sta y) = ≋-refl\n ++-comm (dyn xs) (blob ys y) = blob (⊗-comm xs ys) A.refl\n ++-comm (blob xs x) (sta y) = blob PE.refl (·-comm x y)\n ++-comm (blob xs x) (dyn ys) = blob (⊗-comm xs ys) A.refl\n ++-comm (blob xs x) (blob ys y) = blob (⊗-comm xs ys) (·-comm x y)\n\n ++-assoc : ∀ x y z → (x ++ y) ++ z ≋ x ++ (y ++ z)\n ++-assoc (sta x) (sta y) (sta z) = sta (·-assoc x y z)\n ++-assoc (dyn xs) (dyn ys) (dyn zs) = dyn (⊗-assoc xs ys zs)\n ++-assoc (sta x) (sta y) (dyn zs) = ≋-refl\n ++-assoc (sta x) (sta y) (blob zs z) = blob PE.refl (·-assoc x y z)\n ++-assoc (sta x) (dyn ys) (sta z) = ≋-refl\n ++-assoc (sta x) (dyn ys) (dyn zs) = ≋-refl\n ++-assoc (sta x) (dyn ys) (blob zs z) = ≋-refl\n ++-assoc (sta x) (blob ys y) (sta z) = blob PE.refl (·-assoc x y z)\n ++-assoc (sta x) (blob ys y) (dyn zs) = ≋-refl\n ++-assoc (sta x) (blob ys y) (blob zs z) = blob PE.refl (·-assoc x y z)\n ++-assoc (dyn xs) (sta y) (sta z) = ≋-refl\n ++-assoc (dyn xs) (sta y) (dyn zs) = ≋-refl\n ++-assoc (dyn xs) (sta y) (blob zs z) = ≋-refl\n ++-assoc (dyn xs) (dyn ys) (sta z) = ≋-refl\n ++-assoc (dyn xs) (dyn ys) (blob zs z) = blob (⊗-assoc xs ys zs) A.refl\n ++-assoc (dyn xs) (blob ys y) (sta z) = ≋-refl\n ++-assoc (dyn xs) (blob ys y) (dyn zs) = blob (⊗-assoc xs ys zs) A.refl\n ++-assoc (dyn xs) (blob ys y) (blob zs z) = blob (⊗-assoc xs ys zs) A.refl\n ++-assoc (blob xs x) (sta y) (sta z) = blob PE.refl (·-assoc x y z)\n ++-assoc (blob xs x) (sta y) (dyn zs) = ≋-refl\n ++-assoc (blob xs x) (sta y) (blob zs z) = blob PE.refl (·-assoc x y z)\n ++-assoc (blob xs x) (dyn ys) (sta z) = ≋-refl\n ++-assoc (blob xs x) (dyn ys) (dyn zs) = blob (⊗-assoc xs ys zs) A.refl\n ++-assoc (blob xs x) (dyn ys) (blob zs z) = blob (⊗-assoc xs ys zs) A.refl\n ++-assoc (blob xs x) (blob ys y) (sta z) = blob PE.refl (·-assoc x y z)\n ++-assoc (blob xs x) (blob ys y) (dyn zs) = blob (⊗-assoc xs ys zs) A.refl\n ++-assoc (blob xs x) (blob ys y) (blob zs z) = blob (⊗-assoc xs ys zs) (·-assoc x y z)\n\n Blob⟦_⟧ : Interpretation Blob/≋\n Blob⟦ • ⟧ (x ∷ y ∷ []) = x ++ y\n\n Blob⟦_⟧-cong : Congruence Blob/≋ Blob⟦_⟧\n Blob⟦ • ⟧-cong (p ∷ q ∷ []) = ++-cong p q\n\n Blob/≋-isAlgebra : IsAlgebra Blob/≋\n Blob/≋-isAlgebra = record { ⟦_⟧ = Blob⟦_⟧\n ; ⟦⟧-cong = Blob⟦_⟧-cong\n }\n\n Blob/≋-algebra : Algebra\n Blob/≋-algebra =\n record { ∥_∥/≈ = Blob/≋\n ; ∥_∥/≈-isAlgebra = Blob/≋-isAlgebra\n }\n\n Blob/≋-models : Models Blob/≋-algebra\n Blob/≋-models comm θ = ++-comm (θ (# 0)) (θ (# 1))\n Blob/≋-models assoc θ = ++-assoc (θ (# 0)) (θ (# 1)) (θ (# 2))\n\n Blob/≋-isModel : IsModel Blob/≋\n Blob/≋-isModel =\n record { isAlgebra = Blob/≋-isAlgebra\n ; models = Blob/≋-models\n }\n\n Frex : Model\n Frex = record { ∥_∥/≈ = Blob/≋\n ; isModel = Blob/≋-isModel\n }\n\n ∣inl∣ : ∥ A ∥ → ∥ Frex ∥\n ∣inl∣ = sta\n\n ∣inl∣-cong : Congruent _≈_ _≋_ ∣inl∣\n ∣inl∣-cong = sta\n\n ∣inl∣⃗ : ∥ A ∥/≈ ↝ ∥ Frex ∥/≈\n ∣inl∣⃗ = record { ∣_∣ = ∣inl∣\n ; ∣_∣-cong = ∣inl∣-cong\n }\n\n ∣inl∣-hom : Homomorphic ∥ A ∥ₐ ∥ Frex ∥ₐ ∣inl∣\n ∣inl∣-hom • (x ∷ y ∷ []) = ≋-refl\n\n inl : ∥ A ∥ₐ ⟿ ∥ Frex ∥ₐ\n inl = record { ∣_∣⃗ = ∣inl∣⃗\n ; ∣_∣-hom = ∣inl∣-hom\n }\n\n ∣inr∣ : ∥ J n ∥ → ∥ Frex ∥\n ∣inr∣ x = dyn (∣ norm ∣ x)\n\n ∣inr∣-cong : Congruent ≈[ J n ] _≋_ ∣inr∣\n ∣inr∣-cong p = dyn (∣ norm ∣-cong p)\n\n ∣inr∣⃗ : ∥ J n ∥/≈ ↝ ∥ Frex ∥/≈\n ∣inr∣⃗ = record { ∣_∣ = ∣inr∣\n ; ∣_∣-cong = ∣inr∣-cong\n }\n\n ∣inr∣-hom : Homomorphic ∥ J n ∥ₐ ∥ Frex ∥ₐ ∣inr∣\n ∣inr∣-hom • (x ∷ y ∷ []) = dyn (∣ norm ∣-hom • (x ∷ y ∷ []))\n\n\n inr : ∥ J n ∥ₐ ⟿ ∥ Frex ∥ₐ\n inr = record { ∣_∣⃗ = ∣inr∣⃗\n ; ∣_∣-hom = ∣inr∣-hom\n }\n\n module _ {b ℓ} (X : Model {b} {ℓ}) where\n\n private\n\n open module X = Setoid ∥ X ∥/≈ renaming (_≈_ to _~_)\n\n _⊕_ : ∥ X ∥ → ∥ X ∥ → ∥ X ∥\n x ⊕ y = X ⟦ • ⟧ (x ∷ y ∷ [])\n\n ⊕-cong : ∀ {x y z w} → x ~ y → z ~ w → x ⊕ z ~ y ⊕ w\n ⊕-cong p q = (X ⟦ • ⟧-cong) (p ∷ q ∷ [])\n\n ⊕-comm : ∀ (x y : ∥ X ∥) → x ⊕ y ~ y ⊕ x\n ⊕-comm x y = ∥ X ∥ₐ-models comm (env {A = ∥ X ∥ₐ} (x ∷ y ∷ []))\n\n ⊕-assoc : ∀ (x y z : ∥ X ∥) → (x ⊕ y) ⊕ z ~ x ⊕ (y ⊕ z)\n ⊕-assoc x y z = ∥ X ∥ₐ-models assoc (env {A = ∥ X ∥ₐ} (x ∷ y ∷ z ∷ []))\n\n module _\n (f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ)\n (g : ∥ J n ∥ₐ ⟿ ∥ X ∥ₐ)\n where\n\n ∣resid∣ : ∥ Frex ∥ → ∥ X ∥\n ∣resid∣ (sta x) = ∣ f ∣ x\n ∣resid∣ (dyn xs) = ∣ g ∣ (∣ syn ∣ xs)\n ∣resid∣ (blob xs x) = ∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x\n\n ∣resid∣-cong : Congruent _≋_ _~_ ∣resid∣\n ∣resid∣-cong (sta p) = ∣ f ∣-cong p\n ∣resid∣-cong (dyn ps) = ∣ g ∣-cong (∣ syn ∣-cong ps)\n ∣resid∣-cong (blob ps p) =\n ⊕-cong (∣ g ∣-cong (∣ syn ∣-cong ps)) (∣ f ∣-cong p)\n\n open Reasoning ∥ X ∥/≈\n\n ∣resid∣-hom : Homomorphic ∥ Frex ∥ₐ ∥ X ∥ₐ ∣resid∣\n ∣resid∣-hom • (sta x ∷ sta y ∷ []) = ∣ f ∣-hom • (x ∷ y ∷ [])\n ∣resid∣-hom • (sta x ∷ dyn ys ∷ []) = ⊕-comm (∣ f ∣ x) _\n ∣resid∣-hom • (sta x ∷ blob ys y ∷ []) = begin\n ∣ f ∣ x ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y)\n ≈⟨ ⊕-cong X.refl (⊕-comm _ (∣ f ∣ y)) ⟩\n ∣ f ∣ x ⊕ (∣ f ∣ y ⊕ ∣ g ∣ (∣ syn ∣ ys))\n ≈⟨ X.sym (⊕-assoc (∣ f ∣ x) (∣ f ∣ y) _) ⟩\n (∣ f ∣ x ⊕ ∣ f ∣ y) ⊕ ∣ g ∣ (∣ syn ∣ ys)\n ≈⟨ ⊕-cong (∣ f ∣-hom • (x ∷ y ∷ [])) X.refl ⟩\n ∣ f ∣ (x · y) ⊕ ∣ g ∣ (∣ syn ∣ ys)\n ≈⟨ ⊕-comm _ _ ⟩\n ∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ (x · y)\n ∎\n ∣resid∣-hom • (dyn xs ∷ sta y ∷ []) = X.refl\n ∣resid∣-hom • (dyn xs ∷ dyn ys ∷ []) = ∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])\n ∣resid∣-hom • (dyn xs ∷ blob ys y ∷ []) = begin\n ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y)\n ≈⟨ X.sym (⊕-assoc _ _ (∣ f ∣ y)) ⟩\n (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ ∣ f ∣ y\n ≈⟨ ⊕-cong (∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])) X.refl ⟩\n ∣ g ∣ (∣ syn ∣ (xs ⊗ ys)) ⊕ ∣ f ∣ y\n ∎\n ∣resid∣-hom • (blob xs x ∷ sta y ∷ []) = begin\n (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x) ⊕ ∣ f ∣ y\n ≈⟨ ⊕-assoc _ (∣ f ∣ x) (∣ f ∣ y) ⟩\n ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ f ∣ x ⊕ ∣ f ∣ y)\n ≈⟨ ⊕-cong X.refl (∣ f ∣-hom • (x ∷ y ∷ [])) ⟩\n ∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ (x · y)\n ∎\n ∣resid∣-hom • (blob xs x ∷ dyn ys ∷ []) = begin\n (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x) ⊕ ∣ g ∣ (∣ syn ∣ ys)\n ≈⟨ ⊕-assoc _ (∣ f ∣ x) _ ⟩\n ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ f ∣ x ⊕ ∣ g ∣ (∣ syn ∣ ys))\n ≈⟨ ⊕-cong X.refl (⊕-comm (∣ f ∣ x) _) ⟩\n ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ x)\n ≈⟨ X.sym (⊕-assoc _ _ (∣ f ∣ x)) ⟩\n (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ ∣ f ∣ x\n ≈⟨ ⊕-cong (∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])) X.refl ⟩\n ∣ g ∣ (∣ syn ∣ (xs ⊗ ys)) ⊕ ∣ f ∣ x\n ∎\n ∣resid∣-hom • (blob xs x ∷ blob ys y ∷ []) = begin\n (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y)\n ≈⟨ ⊕-assoc _ (∣ f ∣ x) _ ⟩\n ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ f ∣ x ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y))\n ≈⟨ ⊕-cong X.refl (X.sym (⊕-assoc (∣ f ∣ x) _ _)) ⟩\n ∣ g ∣ (∣ syn ∣ xs) ⊕ ((∣ f ∣ x ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ ∣ f ∣ y)\n ≈⟨ ⊕-cong X.refl (⊕-cong (⊕-comm (∣ f ∣ x) _) X.refl) ⟩\n ∣ g ∣ (∣ syn ∣ xs) ⊕ ((∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ x) ⊕ ∣ f ∣ y)\n ≈⟨ ⊕-cong X.refl (⊕-assoc _ (∣ f ∣ x) _) ⟩\n ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ (∣ f ∣ x ⊕ ∣ f ∣ y))\n ≈⟨ X.sym (⊕-assoc _ _ _) ⟩\n (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ (∣ f ∣ x ⊕ ∣ f ∣ y)\n ≈⟨ ⊕-cong (∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])) (∣ f ∣-hom • (x ∷ y ∷ [])) ⟩\n ∣ g ∣ (∣ syn ∣ (xs ⊗ ys)) ⊕ ∣ f ∣ (x · y)\n ∎\n\n ∣resid∣⃗ : ∥ Frex ∥/≈ ↝ ∥ X ∥/≈\n ∣resid∣⃗ = record { ∣_∣ = ∣resid∣\n ; ∣_∣-cong = ∣resid∣-cong\n }\n\n _[_,_] : ∥ Frex ∥ₐ ⟿ ∥ X ∥ₐ\n _[_,_] = record { ∣_∣⃗ = ∣resid∣⃗\n ; ∣_∣-hom = ∣resid∣-hom\n }\n\n module _ {b ℓ} {X : Model {b} {ℓ}} where\n\n private\n\n open module X = Setoid ∥ X ∥/≈ renaming (_≈_ to _~_)\n\n _⊕_ : ∥ X ∥ → ∥ X ∥ → ∥ X ∥\n x ⊕ y = X ⟦ • ⟧ (x ∷ y ∷ [])\n\n ⊕-cong : ∀ {x y z w} → x ~ y → z ~ w → x ⊕ z ~ y ⊕ w\n ⊕-cong p q = (X ⟦ • ⟧-cong) (p ∷ q ∷ [])\n\n ⊕-comm : ∀ (x y : ∥ X ∥) → x ⊕ y ~ y ⊕ x\n ⊕-comm x y = ∥ X ∥ₐ-models comm (env {A = ∥ X ∥ₐ} (x ∷ y ∷ []))\n\n ⊕-assoc : ∀ (x y z : ∥ X ∥) → (x ⊕ y) ⊕ z ~ x ⊕ (y ⊕ z)\n ⊕-assoc x y z = ∥ X ∥ₐ-models assoc (env {A = ∥ X ∥ₐ} (x ∷ y ∷ z ∷ []))\n\n module _\n {f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ}\n {g : ∥ J n ∥ₐ ⟿ ∥ X ∥ₐ}\n where\n\n commute₁ : X [ f , g ] ⊙ inl ≗ f\n commute₁ = X.refl\n\n commute₂ : X [ f , g ] ⊙ inr ≗ g\n commute₂ {x} = ∣ g ∣-cong (syn⊙norm≗id {x = x})\n\n module _ {h : ∥ Frex ∥ₐ ⟿ ∥ X ∥ₐ}\n (c₁ : h ⊙ inl ≗ f)\n (c₂ : h ⊙ inr ≗ g)\n where\n\n open Reasoning ∥ X ∥/≈\n\n universal : X [ f , g ] ≗ h\n universal {sta x} = X.sym c₁\n universal {dyn xs} = begin\n ∣ g ∣ (∣ syn ∣ xs)\n ≈⟨ X.sym c₂ ⟩\n ∣ h ∣ (dyn (∣ norm ∣ (∣ syn ∣ xs)))\n ≈⟨ ∣ h ∣-cong (dyn norm⊙syn≗id) ⟩\n ∣ h ∣ (dyn xs)\n ∎\n universal {blob xs x} = begin\n ∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x\n ≈⟨ ⊕-cong universal universal ⟩\n ∣ h ∣ (dyn xs) ⊕ ∣ h ∣ (sta x)\n ≈⟨ ∣ h ∣-hom • (dyn xs ∷ sta x ∷ []) ⟩\n ∣ h ∣ (blob xs x)\n ∎\n\nCSemigroupFrex : FreeExtension\nCSemigroupFrex = record { _[_] = Frex\n ; _[_]-isFrex = isFrex\n }\n where isFrex : IsFreeExtension Frex\n isFrex A n =\n record { inl = inl A n\n ; inr = inr A n\n ; _[_,_] = _[_,_] A n\n ; commute₁ = λ {_ _ X f g} → commute₁ A n {X = X} {f} {g}\n ; commute₂ = λ {_ _ X f g} → commute₂ A n {X = X} {f} {g}\n ; universal = λ {_ _ X f g h} → universal A n {X = X} {f} {g} {h}\n }\n", "meta": {"hexsha": "6068c298befdbeb551e89782a061eb181585f3bd", "size": 14593, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Fragment/Extensions/CSemigroup/Base.agda", "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_issues_repo_path": "src/Fragment/Extensions/CSemigroup/Base.agda", "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_forks_repo_path": "src/Fragment/Extensions/CSemigroup/Base.agda", "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "avg_line_length": 36.851010101, "max_line_length": 88, "alphanum_fraction": 0.4032755431, "num_tokens": 6924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982315512489, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.3666658061252629}} {"text": "\nopen import Agda.Builtin.Reflection\nopen import Agda.Builtin.Unit\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Equality\n\ninfixl 4 _>>=_\n_>>=_ = bindTC\n\ndata Tm : Set where\n [_] : Term → Tm\n\nmacro\n qType : Term → Term → TC ⊤\n qType t hole = inferType t >>= quoteTC >>= unify hole\n\n qTerm : Term → Term → TC ⊤\n qTerm t hole = quoteTC t >>= unify hole\n\n unQ : Tm → Term → TC ⊤\n unQ [ t ] hole = unify hole t\n\npostulate\n X : Set\n x y z : X\n\nid : (A : Set) → A → A\nid _ x = x\n\nrecord R (A B : Set) : Set₁ where\n field\n F : X → X → X → Set\n\n bar : F x y z → Term\n bar fx = qType fx -- result: F z (x y are dropped)\n\n check-bar : F x y z → F x y z\n check-bar fx = id (unQ [ bar fx ]) fx\n\nbaz : ∀ {A B} (r : R A B) → R.F r x y z → Term\nbaz r fx = qType fx\n\ncheck-baz : ∀ {A B} (r : R A B) → R.F r x y z → R.F r x y z\ncheck-baz r fx = id (unQ [ baz r fx ]) fx\n\nmodule M (A B : Set) where\n\n data D : Set where\n d : D\n\n `d = qTerm d\n d′ = unquote (unify `d)\n\n`Md = qTerm (M.d {X} {X})\n\nMd : M.D X X\nMd = unquote (unify `Md)\n", "meta": {"hexsha": "ed1451e82a3f04e30757f0531ba9c9ddfbc1c44c", "size": 1050, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue2220.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue2220.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue2220.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 18.1034482759, "max_line_length": 59, "alphanum_fraction": 0.559047619, "num_tokens": 418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.6477982247516797, "lm_q1q2_score": 0.36666580227658063}} {"text": "------------------------------------------------------------------------\n-- Lexicographic products of binary relations\n------------------------------------------------------------------------\n\n-- The definition of lexicographic product used here is suitable if\n-- the left-hand relation is a strict partial order.\n\nmodule Relation.Binary.Product.StrictLex where\n\nopen import Data.Function\nopen import Data.Product\nopen import Data.Sum\nopen import Data.Empty\nopen import Relation.Nullary.Product\nopen import Relation.Nullary.Sum\nopen import Relation.Binary\nopen import Relation.Binary.Consequences\nopen import Relation.Binary.Product.Pointwise as Pointwise\n using (_×-Rel_)\n\nprivate\n module Dummy {a₁ a₂ : Set} where\n\n ×-Lex : (≈₁ <₁ : Rel a₁) → (≤₂ : Rel a₂) → Rel (a₁ × a₂)\n ×-Lex ≈₁ <₁ ≤₂ = (<₁ on₁ proj₁) -⊎- (≈₁ on₁ proj₁) -×- (≤₂ on₁ proj₂)\n\n -- Some properties which are preserved by ×-Lex (under certain\n -- assumptions).\n\n ×-reflexive : ∀ ≈₁ ∼₁ {≈₂} ≤₂ →\n ≈₂ ⇒ ≤₂ → (≈₁ ×-Rel ≈₂) ⇒ (×-Lex ≈₁ ∼₁ ≤₂)\n ×-reflexive _ _ _ refl₂ = λ x≈y →\n inj₂ (proj₁ x≈y , refl₂ (proj₂ x≈y))\n\n _×-irreflexive_ : ∀ {≈₁ <₁} → Irreflexive ≈₁ <₁ →\n ∀ {≈₂ <₂} → Irreflexive ≈₂ <₂ →\n Irreflexive (≈₁ ×-Rel ≈₂) (×-Lex ≈₁ <₁ <₂)\n (ir₁ ×-irreflexive ir₂) x≈y (inj₁ x₁y₁ = inj₂ (inj₁ x₁>y₁)\n\n ×-compare : ∀ {≈₁ <₁} → Symmetric ≈₁ → Trichotomous ≈₁ <₁ →\n ∀ {≈₂ <₂} → Trichotomous ≈₂ <₂ →\n Trichotomous (≈₁ ×-Rel ≈₂) (×-Lex ≈₁ <₁ <₂)\n ×-compare {≈₁} {<₁} sym₁ compare₁ {≈₂} {<₂} compare₂ = cmp\n where\n cmp : Trichotomous (≈₁ ×-Rel ≈₂) (×-Lex ≈₁ <₁ <₂)\n cmp (x₁ , x₂) (y₁ , y₂) with compare₁ x₁ y₁\n ... | tri< x₁ x₁≮y₁ x₁≉y₁ x₁>y₁ = tri> [ x₁≮y₁ , x₁≉y₁ ∘ proj₁ ]\n (x₁≉y₁ ∘ proj₁) (inj₁ x₁>y₁)\n ... | tri≈ x₁≮y₁ x₁≈y₁ x₁≯y₁ with compare₂ x₂ y₂\n ... | tri< x₂ x₂≮y₂ x₂≉y₂ x₂>y₂ = tri> [ x₁≮y₁ , x₂≮y₂ ∘ proj₂ ]\n (x₂≉y₂ ∘ proj₂)\n (inj₂ (sym₁ x₁≈y₁ , x₂>y₂))\n ... | tri≈ x₂≮y₂ x₂≈y₂ x₂≯y₂ = tri≈ [ x₁≮y₁ , x₂≮y₂ ∘ proj₂ ]\n (x₁≈y₁ , x₂≈y₂)\n [ x₁≯y₁ , x₂≯y₂ ∘ proj₂ ]\n\n -- Some collections of properties which are preserved by ×-Lex.\n\n _×-isPreorder_ : ∀ {≈₁ ∼₁} → IsPreorder ≈₁ ∼₁ →\n ∀ {≈₂ ∼₂} → IsPreorder ≈₂ ∼₂ →\n IsPreorder (≈₁ ×-Rel ≈₂) (×-Lex ≈₁ ∼₁ ∼₂)\n _×-isPreorder_ {≈₁ = ≈₁} {∼₁ = ∼₁} pre₁ {∼₂ = ∼₂} pre₂ = record\n { isEquivalence = Pointwise._×-isEquivalence_\n (isEquivalence pre₁) (isEquivalence pre₂)\n ; reflexive = λ {x y} →\n ×-reflexive ≈₁ ∼₁ ∼₂ (reflexive pre₂) {x} {y}\n ; trans = λ {x y z} →\n ×-transitive\n (isEquivalence pre₁) (∼-resp-≈ pre₁) (trans pre₁)\n {≤₂ = ∼₂} (trans pre₂) {x} {y} {z}\n ; ∼-resp-≈ = ×-≈-respects₂ (isEquivalence pre₁)\n (∼-resp-≈ pre₁)\n (∼-resp-≈ pre₂)\n }\n where open IsPreorder\n\n _×-isStrictPartialOrder_ :\n ∀ {≈₁ <₁} → IsStrictPartialOrder ≈₁ <₁ →\n ∀ {≈₂ <₂} → IsStrictPartialOrder ≈₂ <₂ →\n IsStrictPartialOrder (≈₁ ×-Rel ≈₂) (×-Lex ≈₁ <₁ <₂)\n _×-isStrictPartialOrder_ {<₁ = <₁} spo₁ {<₂ = <₂} spo₂ =\n record\n { isEquivalence = Pointwise._×-isEquivalence_\n (isEquivalence spo₁) (isEquivalence spo₂)\n ; irrefl = λ {x y} →\n _×-irreflexive_ {<₁ = <₁} (irrefl spo₁)\n {<₂ = <₂} (irrefl spo₂) {x} {y}\n ; trans = λ {x y z} →\n ×-transitive\n {<₁ = <₁} (isEquivalence spo₁) (<-resp-≈ spo₁)\n (trans spo₁)\n {≤₂ = <₂} (trans spo₂) {x} {y} {z}\n ; <-resp-≈ = ×-≈-respects₂ (isEquivalence spo₁)\n (<-resp-≈ spo₁)\n (<-resp-≈ spo₂)\n }\n where open IsStrictPartialOrder\n\n _×-isStrictTotalOrder_ :\n ∀ {≈₁ <₁} → IsStrictTotalOrder ≈₁ <₁ →\n ∀ {≈₂ <₂} → IsStrictTotalOrder ≈₂ <₂ →\n IsStrictTotalOrder (≈₁ ×-Rel ≈₂) (×-Lex ≈₁ <₁ <₂)\n _×-isStrictTotalOrder_ {<₁ = <₁} spo₁ {<₂ = <₂} spo₂ =\n record\n { isEquivalence = Pointwise._×-isEquivalence_\n (isEquivalence spo₁) (isEquivalence spo₂)\n ; trans = λ {x y z} →\n ×-transitive\n {<₁ = <₁} (isEquivalence spo₁) (<-resp-≈ spo₁)\n (trans spo₁)\n {≤₂ = <₂} (trans spo₂) {x} {y} {z}\n ; compare = ×-compare (Eq.sym spo₁) (compare spo₁)\n (compare spo₂)\n ; <-resp-≈ = ×-≈-respects₂ (isEquivalence spo₁)\n (<-resp-≈ spo₁)\n (<-resp-≈ spo₂)\n }\n where open IsStrictTotalOrder\n\nopen Dummy public\n\n-- \"Packages\" (e.g. preorders) can also be combined.\n\n_×-preorder_ : Preorder → Preorder → Preorder\np₁ ×-preorder p₂ = record\n { isPreorder = isPreorder p₁ ×-isPreorder isPreorder p₂\n } where open Preorder\n\n_×-strictPartialOrder_ :\n StrictPartialOrder → StrictPartialOrder → StrictPartialOrder\ns₁ ×-strictPartialOrder s₂ = record\n { isStrictPartialOrder = isStrictPartialOrder s₁\n ×-isStrictPartialOrder\n isStrictPartialOrder s₂\n } where open StrictPartialOrder\n\n_×-strictTotalOrder_ :\n StrictTotalOrder → StrictTotalOrder → StrictTotalOrder\ns₁ ×-strictTotalOrder s₂ = record\n { isStrictTotalOrder = isStrictTotalOrder s₁\n ×-isStrictTotalOrder\n isStrictTotalOrder s₂\n } where open StrictTotalOrder\n", "meta": {"hexsha": "5d7ead0cb7fe950ead26eeddc759fbf4bc48282c", "size": 10038, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "vendor/stdlib/src/Relation/Binary/Product/StrictLex.agda", "max_stars_repo_name": "isabella232/Lemmachine", "max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 56, "max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z", "max_issues_repo_path": "vendor/stdlib/src/Relation/Binary/Product/StrictLex.agda", "max_issues_repo_name": "larrytheliquid/Lemmachine", "max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z", "max_forks_repo_path": "vendor/stdlib/src/Relation/Binary/Product/StrictLex.agda", "max_forks_repo_name": "isabella232/Lemmachine", "max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z", "avg_line_length": 40.313253012, "max_line_length": 73, "alphanum_fraction": 0.4762900976, "num_tokens": 4114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982043529716, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.3666657907305338}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Empty type\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.Empty where\n\n------------------------------------------------------------------------\n-- Definition\n\n-- Note that by default the empty type is not universe polymorphic as it\n-- often results in unsolved metas. See `Data.Empty.Polymorphic` for a\n-- universe polymorphic variant.\n\ndata ⊥ : Set where\n\n------------------------------------------------------------------------\n-- Functions\n\n⊥-elim : ∀ {w} {Whatever : Set w} → ⊥ → Whatever\n⊥-elim ()\n", "meta": {"hexsha": "decbac8c3efa8c1d9e3914a67d50796783fbaf69", "size": 686, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib/src/Data/Empty.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "agda-stdlib/src/Data/Empty.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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-stdlib/src/Data/Empty.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 27.44, "max_line_length": 72, "alphanum_fraction": 0.389212828, "num_tokens": 117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.6224593241981982, "lm_q1q2_score": 0.36655953036540906}} {"text": "module Luau.Type.ToString where\n\nopen import FFI.Data.String using (String; _++_)\nopen import Luau.Type using (Type; nil; _⇒_; none; any; number; _∪_; _∩_; normalizeOptional)\n\n{-# TERMINATING #-}\ntypeToString : Type → String\ntypeToStringᵁ : Type → String\ntypeToStringᴵ : Type → String\n\ntypeToString nil = \"nil\"\ntypeToString (S ⇒ T) = \"(\" ++ (typeToString S) ++ \") -> \" ++ (typeToString T)\ntypeToString none = \"none\"\ntypeToString any = \"any\"\ntypeToString number = \"number\"\ntypeToString (S ∪ T) with normalizeOptional(S ∪ T)\ntypeToString (S ∪ T) | ((S′ ⇒ T′) ∪ nil) = \"(\" ++ typeToString (S′ ⇒ T′) ++ \")?\"\ntypeToString (S ∪ T) | (S′ ∪ nil) = typeToString S′ ++ \"?\"\ntypeToString (S ∪ T) | (S′ ∪ T′) = \"(\" ++ typeToStringᵁ (S ∪ T) ++ \")\"\ntypeToString (S ∪ T) | T′ = typeToString T′\ntypeToString (S ∩ T) = \"(\" ++ typeToStringᴵ (S ∩ T) ++ \")\"\n\ntypeToStringᵁ (S ∪ T) = (typeToStringᵁ S) ++ \" | \" ++ (typeToStringᵁ T)\ntypeToStringᵁ T = typeToString T\n\ntypeToStringᴵ (S ∩ T) = (typeToStringᴵ S) ++ \" & \" ++ (typeToStringᴵ T)\ntypeToStringᴵ T = typeToString T\n", "meta": {"hexsha": "e7a7c1c07b2ae4391b8d84f37a82989243c14b12", "size": 1049, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "prototyping/Luau/Type/ToString.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/Luau/Type/ToString.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/Luau/Type/ToString.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": 37.4642857143, "max_line_length": 92, "alphanum_fraction": 0.6263107722, "num_tokens": 376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7217432182679956, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3665097691995436}} {"text": "{-# OPTIONS --rewriting #-}\nmodule DualLMRefined where\n\nopen import Data.Bool\nopen import Data.Nat hiding (compare)\nopen import Data.Nat.Properties\nopen import Data.Fin hiding (_+_)\nopen import Data.Product\nopen import Function\nopen import Relation.Binary.PropositionalEquality hiding (Extensionality)\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Equality.Rewrite\nopen import Extensionality\nopen import Direction\n\n-- variables\n\nvariable\n n m : ℕ\n\n----------------------------------------------------------------------\n-- auxiliaries for automatic rewriting\n\nn+1=suc-n : n + 1 ≡ suc n\nn+1=suc-n {zero} = refl\nn+1=suc-n {suc n} = cong suc (n+1=suc-n {n})\n\n{-# REWRITE n+1=suc-n #-}\n\nn+0=n : n + 0 ≡ n\nn+0=n {zero} = refl\nn+0=n {suc n} = cong suc (n+0=n {n})\n\n{-# REWRITE n+0=n #-}\n\ninject+0-x=x : {x : Fin m} → inject+ 0 x ≡ x\ninject+0-x=x {x = zero} = refl\ninject+0-x=x {x = suc x} = cong suc inject+0-x=x\n\n{-# REWRITE inject+0-x=x #-}\n\nn+sucm : n + suc m ≡ suc (n + m)\nn+sucm {0} = refl\nn+sucm {suc n} = cong suc (n+sucm{n})\n\n{-# REWRITE n+sucm #-}\n\nn=fromℕtoℕn : (toℕ (fromℕ n)) ≡ n\nn=fromℕtoℕn {zero} = refl\nn=fromℕtoℕn {suc n} = cong suc (n=fromℕtoℕn {n})\n\n{-# REWRITE n=fromℕtoℕn #-}\n\nsucn∸suctoℕx≡n∸toℕx : {n : ℕ} {x : Fin n} → suc (n ∸ suc (toℕ x)) ≡ n ∸ (toℕ x)\nsucn∸suctoℕx≡n∸toℕx {suc n} {zero} = refl\nsucn∸suctoℕx≡n∸toℕx {suc n} {suc x} = sucn∸suctoℕx≡n∸toℕx{n}{x}\n\nsym-sucn∸suctoℕx≡n∸toℕx : {n : ℕ} {x : Fin n} → n ∸ (toℕ x) ≡ suc (n ∸ suc (toℕ x))\nsym-sucn∸suctoℕx≡n∸toℕx {n} {x} = sym (sucn∸suctoℕx≡n∸toℕx{n}{x})\n\n{-# REWRITE sym-sucn∸suctoℕx≡n∸toℕx #-}\n\nn∸n≡0F : n ∸ n ≡ 0\nn∸n≡0F {0} = refl\nn∸n≡0F {suc n} = n∸n≡0F{n}\n\n{-# REWRITE n∸n≡0F #-}\n\n{-# REWRITE m+n∸n≡m #-}\n\n----------------------------------------------------------------------\n-- some more required properties on natural numbers and fin\n\ntoℕx≤n : {n : ℕ} {x : Fin n} → Data.Nat._≤_ (toℕ x) n\ntoℕx≤n {suc n} {zero} = z≤n\ntoℕx≤n {suc n} {suc x} = s≤s toℕx≤n\n\ntoℕx≤n' : {n : ℕ} {x : Fin (suc n)} → Data.Nat._≤_ (toℕ x) n\ntoℕx≤n' {0} {zero} = z≤n\ntoℕx≤n' {suc n} {zero} = z≤n\ntoℕx≤n' {suc n} {suc x} = s≤s (toℕx≤n'{n}{x})\n\nn∸x+x≡n : {n x : ℕ} → Data.Nat._≤_ x n → n ∸ x + x ≡ n\nn∸x+x≡n {0} {zero} le = refl\nn∸x+x≡n {0} {suc x} ()\nn∸x+x≡n {suc n} {zero} le = refl\nn∸x+x≡n {suc n} {suc x} (s≤s le) = cong suc (n∸x+x≡n le)\n\ntoℕx : (i : Fin n) → StackS0 (n ∸ (toℕ (suc i))) → SType n → SType (toℕ (suc i))\nstack-sim-substG-i> : (i : Fin n) → StackS0 (n ∸ (toℕ (suc i))) → GType n → GType (toℕ (suc i))\nstack-sim-substT-i> : (i : Fin n) → StackS0 (n ∸ (toℕ (suc i))) → Type n → Type (toℕ (suc i))\n\nstack-sim-substS-i> i σ (gdd gst) = gdd (stack-sim-substG-i> i σ gst)\nstack-sim-substS-i> i σ (rec gst) = rec (stack-sim-substG-i> (suc i) σ gst)\nstack-sim-substS-i>{suc n} zero σ (var zero) = var zero\nstack-sim-substS-i> zero σ (var (suc x))\n with getS0 x σ \n... | σ' , s = weaken1S s\nstack-sim-substS-i> (suc i) σ (var zero) = var zero\nstack-sim-substS-i> (suc i) σ (var (suc x)) = weaken1S (stack-sim-substS-i> i σ (var x))\n\nstack-sim-substG-i> i σ (transmit d t s) = transmit d (stack-sim-substT-i> i σ t) (stack-sim-substS-i> i σ s)\nstack-sim-substG-i> i σ (choice d m alt) = choice d m (λ x → stack-sim-substS-i> i σ (alt x))\nstack-sim-substG-i> i σ end = end\n\nstack-sim-substT-i> i σ TUnit = TUnit\nstack-sim-substT-i> i σ TInt = TInt\nstack-sim-substT-i> i σ (TPair t t₁) = TPair (stack-sim-substT-i> i σ t) (stack-sim-substT-i> i σ t₁)\nstack-sim-substT-i> i σ (TChan x) = TChan (stack-sim-substS-i> i σ x)\n\n\n-- substitute stack\nstack-sim-substS : StackS0 n → SType n → SType 0\nstack-sim-substG : StackS0 n → GType n → GType 0\nstack-sim-substT : StackS0 n → Type n → Type 0\n\nstack-sim-substS σ (gdd gst) = gdd (stack-sim-substG σ gst)\nstack-sim-substS σ (rec gst) = rec (stack-sim-substG-i> zero σ gst) -- Apply stack substitution to variables 1, ..., suc n; keep 0F; can't extend StackS0 since only SType 0F allowed\nstack-sim-substS σ (var x)\n with getS0 x σ\n... | σ' , s = s\n\nstack-sim-substG σ (transmit d t s) = transmit d (stack-sim-substT σ t) (stack-sim-substS σ s)\nstack-sim-substG σ (choice d m alt) = choice d m (λ x → stack-sim-substS σ (alt x))\nstack-sim-substG σ end = end\n\nstack-sim-substT σ TUnit = TUnit\nstack-sim-substT σ TInt = TInt\nstack-sim-substT σ (TPair t t₁) = TPair (stack-sim-substT σ t) (stack-sim-substT σ t₁)\nstack-sim-substT σ (TChan x) = TChan (stack-sim-substS σ x)\n\n\nstack-sim-substS'-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → SType m → SType (n + toℕ i)\nstack-sim-substG'-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → GType m → GType (n + toℕ i)\nstack-sim-substT'-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → Type m → Type (n + toℕ i)\n\nstack-sim-substS'-i≥ i σ (gdd gst) = gdd (stack-sim-substG'-i≥ i σ gst)\nstack-sim-substS'-i≥ i σ (rec gst) = rec (stack-sim-substG'-i≥ (suc i) σ gst)\nstack-sim-substS'-i≥ zero σ (var x)\n with get'Sn x σ\n... | σ' , y = y\nstack-sim-substS'-i≥ (suc i) σ (var zero) = var zero\nstack-sim-substS'-i≥ (suc i) σ (var (suc x)) = weaken1S (stack-sim-substS'-i≥ i σ (var x))\n\nstack-sim-substG'-i≥ i σ (transmit d t s) = transmit d (stack-sim-substT'-i≥ i σ t) (stack-sim-substS'-i≥ i σ s)\nstack-sim-substG'-i≥ i σ (choice d m alt) = choice d m (λ x → stack-sim-substS'-i≥ i σ (alt x))\nstack-sim-substG'-i≥ i σ end = end\n\nstack-sim-substT'-i≥ i σ TUnit = TUnit\nstack-sim-substT'-i≥ i σ TInt = TInt\nstack-sim-substT'-i≥ i σ (TPair t t₁) = TPair (stack-sim-substT'-i≥ i σ t) (stack-sim-substT'-i≥ i σ t₁)\nstack-sim-substT'-i≥ i σ (TChan x) = TChan (stack-sim-substS'-i≥ i σ x)\n\n-- substitute stack'\nstack-sim-substS' : Stack'Sn n m → SType m → SType n\nstack-sim-substG' : Stack'Sn n m → GType m → GType n\nstack-sim-substT' : Stack'Sn n m → Type m → Type n\n\nstack-sim-substS' σ (gdd gst) = gdd (stack-sim-substG' σ gst)\nstack-sim-substS'{n}{m} σ (rec gst) = rec (stack-sim-substG'-i≥ (suc zero) σ gst)\nstack-sim-substS' σ (var x)\n with get'Sn x σ\n... | σ' , s = s\n\nstack-sim-substG' σ (transmit d t s) = transmit d (stack-sim-substT' σ t) (stack-sim-substS' σ s)\nstack-sim-substG' σ (choice d m alt) = choice d m (λ x → stack-sim-substS' σ (alt x))\nstack-sim-substG' σ end = end\n\nstack-sim-substT' σ TUnit = TUnit\nstack-sim-substT' σ TInt = TInt\nstack-sim-substT' σ (TPair t t₁) = TPair (stack-sim-substT' σ t) (stack-sim-substT' σ t₁)\nstack-sim-substT' σ (TChan x) = TChan (stack-sim-substS' σ x)\n\n{- required for alt. def. of rec case of stack-sim-substS'-top\n\nstack-sim-substS'-top-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → SType (n + m) → SType (n + toℕ i)\nstack-sim-substG'-top-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → GType (n + m) → GType (n + toℕ i)\nstack-sim-substT'-top-i≥ : (i : Fin (suc m)) → Stack'Sn n (m ∸ toℕ i) → Type (n + m) → Type (n + toℕ i)\n\nstack-sim-substS'-top-i≥ i σ (gdd gst) = {!!}\nstack-sim-substS'-top-i≥ i σ (rec gst) = rec (stack-sim-substG'-top-i≥ (suc i) σ gst)\nstack-sim-substS'-top-i≥ i σ (var x) = {!!}\n\nstack-sim-substS'-top-i≥' : (i : Fin (suc m)) → Stack'Sn (n + toℕ i) (toℕ i) → SType (n + m) → SType (n + m ∸ toℕ i)\nstack-sim-substG'-top-i≥' : (i : Fin (suc m)) → Stack'Sn (n + toℕ i) (toℕ i) → GType (n + m) → GType (n + m ∸ toℕ i)\n\nstack-sim-substS'-top-i≥'{m = m}{n = suc n} i σ (rec gst) = rec (stack-sim-substG'-top-i≥' {!!} {!!} gst)\n-}\n\n-- substitute top variables from stack'\nstack-sim-substS'-top : Stack'Sn n m → SType (n + m) → SType n\nstack-sim-substG'-top : Stack'Sn n m → GType (n + m) → GType n\nstack-sim-substT'-top : Stack'Sn n m → Type (n + m) → Type n\n\nstack-sim-substS'-top σ (gdd gst) = gdd (stack-sim-substG'-top σ gst)\nstack-sim-substS'-top{n}{m} σ (rec gst) = rec (stack-sim-substG'-top{m = m} (weaken1-Stack'Sn zero σ) gst) -- alternative: rec (stack-sim-substG'-top-i≥ 1 σ gst)\nstack-sim-substS'-top{n}{m} σ (var x) = {!!} -- <= n => var n, > n => substitute\n\n-- Transform Stack of STypes to Stack of closed STypes by substitution \n-- ⟪ ε , SType 0 , SType 1 , SType 2 , ⋯ ⟫\n-- ⟪ ε , SType 0 , SType 1 [0 ↦ SType 0], SType 2 [0 ↦ SType 0, 1 ↦ SType 1 [0 ↦ SType 0]], ⋯ ⟫\n-- ⟪ ε , SType 0 , SType 0 , SType 0 , ⋯ ⟫\nstack-transform : StackS n → StackS0 n\nstack-transform ε = ε\nstack-transform ⟪ σ , x ⟫\n with stack-transform σ\n... | σ' = ⟪ σ' , (stack-sim-substS σ' x) ⟫\n\nstack-transform' : Stack'S n m → Stack'Sn n m\nstack-transform' ε = ε\nstack-transform'{n} ⟪ σ , x ⟫\n with stack-transform' σ\n... | σ' = ⟪ σ' , stack-sim-substS'-top σ' x ⟫\n\nstack-cat : Stack n → Stack' n m → Stack (n + m)\nstack-cat σ ε = σ\nstack-cat σ ⟪ σ' , x ⟫ = ⟪ (stack-cat σ σ') , x ⟫\n\nstack-cat' : Stack' 0 n → Stack' n m → Stack' 0 (n + m)\nstack-cat' σ ε = σ\nstack-cat' σ ⟪ σ' , x ⟫ = ⟪ (stack-cat' σ σ') , x ⟫\n\nstack-sim-substS-refl : (s : SType 0) → stack-sim-substS ε s ≡ s\nstack-sim-substG-refl : (g : GType 0) → stack-sim-substG ε g ≡ g\nstack-sim-substT-refl : (t : Type 0) → stack-sim-substT ε t ≡ t\n\nstack-sim-substS-refl (gdd gst) = cong gdd (stack-sim-substG-refl gst)\nstack-sim-substS-refl (rec gst) = {!!} -- requires stack-sim-substG-i>-refl\n\nstack-sim-substG-refl (transmit d t s) = cong₂ (transmit d) (stack-sim-substT-refl t) (stack-sim-substS-refl s)\nstack-sim-substG-refl (choice d m alt) = cong (choice d m) (ext (λ x → stack-sim-substS-refl (alt x)))\nstack-sim-substG-refl end = refl\n\nstack-sim-substT-refl TUnit = refl\nstack-sim-substT-refl TInt = refl\nstack-sim-substT-refl (TPair t t₁) = cong₂ TPair (stack-sim-substT-refl t) (stack-sim-substT-refl t₁)\nstack-sim-substT-refl (TChan x) = cong TChan (stack-sim-substS-refl x)\n\n----------------------------------------------------------------------\n\n-- Message closure\nmclS : (σ : StackS n) → SType n → MClSType n\nmclG : (σ : StackS n) → GType n → MClGType n\nmclT : (σ : StackS n) → Type n → MClType n\n\nmclS σ (gdd gst) = tgdd (mclG σ gst)\nmclS σ (rec gst) = trec (mclG ⟪ σ , (rec gst) ⟫ gst)\nmclS σ (var x) = tvar x\n\nmclG σ (transmit d t s) = ttransmit d (mclT σ t) (mclS σ s)\nmclG σ (choice d m alt) = tchoice d m (λ x → mclS σ (alt x))\nmclG σ end = end\n\nmclT σ TUnit = MClTUnit\nmclT σ TInt = MClTInt\nmclT σ (TPair t t₁) = MClTPair (mclT σ t) (mclT σ t₁)\nmclT σ (TChan x) = MClTChan (stack-sim-substS (stack-transform σ) x)\n\n----------------------------------------------------------------------\n\n-- Any mcl type is a normal type with weakening\nmcl2indS : MClSType n → SType n\nmcl2indG : MClGType n → GType n\nmcl2indT : MClType n → Type n\n\nmcl2indS (tgdd tgst) = gdd (mcl2indG tgst)\nmcl2indS (trec tgst) = rec (mcl2indG tgst)\nmcl2indS (tvar x) = var x\n\nmcl2indG (ttransmit d t s) = transmit d (mcl2indT t) (mcl2indS s)\nmcl2indG (tchoice d m alt) = choice d m (λ x → mcl2indS (alt x))\nmcl2indG end = end\n\nmcl2indT MClTUnit = TUnit\nmcl2indT MClTInt = TInt\nmcl2indT (MClTPair t t₁) = TPair (mcl2indT t) (mcl2indT t₁)\nmcl2indT{n} (MClTChan x) = TChan (weakenS n x)\n\n----------------------------------------------------------------------\n\nstack2StackS : Stack n → StackS n\nstack2StackS ε = ε\nstack2StackS ⟪ σ , x ⟫ = ⟪ (stack2StackS σ) , (rec x) ⟫\n\nstackMCl2Stack : StackMCl n → Stack n\nstackMCl2Stack ε = ε\nstackMCl2Stack ⟪ σ , x ⟫ = ⟪ (stackMCl2Stack σ) , (mcl2indG x) ⟫\n\nstackMCl2StackS : StackMCl n → StackS n\nstackMCl2StackS ε = ε\nstackMCl2StackS ⟪ σ , x ⟫ = ⟪ (stackMCl2StackS σ) , (rec (mcl2indG x)) ⟫\n\nstack2StackMCl : Stack n → StackMCl n\nstack2StackMCl ε = ε\nstack2StackMCl ⟪ σ , x ⟫ = ⟪ (stack2StackMCl σ) , (mclG ⟪ stack2StackS σ , rec x ⟫ x) ⟫\n\nstack2Stack' : Stack n → Stack' 0 n\nstack2Stack' ε = ε\nstack2Stack' ⟪ σ , x ⟫ = ⟪ stack2Stack' σ , x ⟫\n\nstack'2Stack : Stack' 0 n → Stack n\nstack'2Stack ε = ε\nstack'2Stack ⟪ σ , x ⟫ = ⟪ stack'2Stack σ , x ⟫\n\nstack'2Stack'S : Stack' n m → Stack'S n m\nstack'2Stack'S ε = ε\nstack'2Stack'S ⟪ σ , x ⟫ = ⟪ (stack'2Stack'S σ) , (rec x) ⟫\n\nstack-stack'-refl : (σ : Stack n) → (stack'2Stack (stack2Stack' σ)) ≡ σ\nstack-stack'-refl ε = refl\nstack-stack'-refl ⟪ σ , x ⟫ rewrite (stack-stack'-refl σ) = refl \n\n{-# REWRITE stack-stack'-refl #-}\n\n----------------------------------------------------------------------\n\nnaive-dualS : SType n → SType n\nnaive-dualG : GType n → GType n\nnaive-dualT : Type n → Type n\n\nnaive-dualS (gdd gst) = gdd (naive-dualG gst)\nnaive-dualS (rec gst) = rec (naive-dualG gst)\nnaive-dualS (var x) = var x\n\nnaive-dualG (transmit d t s) = transmit (dual-dir d) (naive-dualT t) (naive-dualS s)\nnaive-dualG (choice d m alt) = choice (dual-dir d) m (λ x → naive-dualS (alt x))\nnaive-dualG end = end\n\nnaive-dualT TUnit = TUnit\nnaive-dualT TInt = TInt\nnaive-dualT (TPair t t₁) = TPair (naive-dualT t) (naive-dualT t₁)\nnaive-dualT (TChan x) = TChan (naive-dualS x)\n\nnaive-dualSt : MClSType n → MClSType n\nnaive-dualGt : MClGType n → MClGType n\nnaive-dualTt : MClType n → MClType n\n\nnaive-dualSt (tgdd tgst) = tgdd (naive-dualGt tgst)\nnaive-dualSt (trec tgst) = trec (naive-dualGt tgst)\nnaive-dualSt (tvar x) = tvar x\n\nnaive-dualGt (ttransmit d t s) = ttransmit (dual-dir d) (naive-dualTt t) (naive-dualSt s)\nnaive-dualGt (tchoice d m alt) = tchoice (dual-dir d) m (λ x → naive-dualSt (alt x))\nnaive-dualGt end = end\n\nnaive-dualTt MClTUnit = MClTUnit\nnaive-dualTt MClTInt = MClTInt\nnaive-dualTt (MClTPair t t₁) = MClTPair (naive-dualTt t) (naive-dualTt t₁)\nnaive-dualTt (MClTChan x) = MClTChan (naive-dualS x)\n\n----------------------------------------------------------------------\n\ndualS : (σ : StackS n) → SType n → MClSType n\ndualG : (σ : StackS n) → GType n → MClGType n\ndualT : (σ : StackS n) → Type n → MClType n\n\ndualS σ (gdd gst) = tgdd (dualG σ gst)\ndualS σ (rec gst) = trec (dualG ⟪ σ , (rec gst) ⟫ gst)\ndualS σ (var x) = (tvar x)\n\ndualG{n} σ (transmit d t s) = ttransmit (dual-dir d) (dualT σ t) (dualS σ s)\ndualG σ (choice d m alt) = tchoice (dual-dir d) m ((dualS σ) ∘ alt)\ndualG σ end = end\n\ndualT σ TUnit = MClTUnit\ndualT σ TInt = MClTInt\ndualT σ (TPair t t₁) = MClTPair (dualT σ t) (dualT σ t₁)\ndualT σ (TChan x) = MClTChan (stack-sim-substS (stack-transform σ) x)\n\nmodule sanity-check where\n -- μx.!x.x → μx.?(μx.!x.x).x\n S : SType 0\n S = rec (transmit SND (TChan (var zero)) (var zero))\n DS = rec (transmit RCV (weaken1T (TChan S)) (var zero))\n\n _ : mclS ε DS ≡ dualS ε S\n _ = refl\n\n -- μx.!x.!x.x → μx.?(μx.!x.!x.x).?(μx.!x.!x.x).x\n S' : SType 0\n S' = rec (transmit SND (TChan (var zero)) (gdd ((transmit SND (TChan (var zero)) (var zero)))))\n DS' = rec (transmit RCV (weaken1T (TChan S')) (gdd ((transmit RCV (weaken1T (TChan S')) (var zero)))))\n\n _ : mclS ε DS' ≡ dualS ε S'\n _ = refl\n\n -- μx.!x.(μy.!y.y) → μx.?(μx.!x.(μy.!y.y)).(μy.?(μy.!y.y).y)\n S'' : SType 0\n S'' = rec (transmit SND (TChan (var zero)) (rec (transmit SND (TChan (var zero)) (var zero))))\n DS'' = rec (transmit RCV (weaken1T (TChan S'')) (weaken1S DS))\n\n _ : mclS ε DS'' ≡ dualS ε S''\n _ = refl\n\n----------------------------------------------------------------------\n\n\nopen import DualCoinductive hiding (n ; m)\n\n_≈_ = COI._≈_\n_≈'_ = COI._≈'_\n_≈ᵗ_ = COI._≈ᵗ_\n\n-- IND to Coinductive using two stacks\n-- e.g. i = 0 => σ\n-- i = 1 => σ , g -- g = get σ' 0\n-- i = 2F => σ , g' , g -- g = get σ' 0; g' = get σ' 1\n-- i = n => σ'\nind2coiS' : (i : Fin (suc n)) → Stack (n ∸ toℕ i) → Stack' (n ∸ toℕ i) (toℕ i) → IND.SType n → COI.SType\nind2coiG' : (i : Fin (suc n)) → Stack (n ∸ toℕ i) → Stack' (n ∸ toℕ i) (toℕ i) → IND.GType n → COI.STypeF COI.SType\nind2coiT' : (i : Fin (suc n)) → Stack (n ∸ toℕ i) → Stack' (n ∸ toℕ i) (toℕ i) → IND.Type n → COI.Type\n\nCOI.SType.force (ind2coiS' i σ σ' (gdd gst)) = ind2coiG' i σ σ' gst\nCOI.SType.force (ind2coiS'{n} i σ σ' (rec gst)) = ind2coiG' (suc i) σ ⟪ σ' , gst ⟫ gst\nCOI.SType.force (ind2coiS' i σ σ' (var x)) = {!!}\n \n-- IND to Coinductive\nind2coiS : Stack n → IND.SType n → COI.SType\nind2coiG : Stack n → IND.GType n → COI.STypeF COI.SType\nind2coiT : Stack n → IND.Type n → COI.Type\n\nind2coiT σ TUnit = COI.TUnit\nind2coiT σ TInt = COI.TInt\nind2coiT σ (TPair t t₁) = COI.TPair (ind2coiT σ t) (ind2coiT σ t₁)\nind2coiT σ (TChan x) = COI.TChan (ind2coiS σ x)\n\nCOI.SType.force (ind2coiS σ (gdd gst)) = ind2coiG σ gst\nCOI.SType.force (ind2coiS σ (rec gst)) = ind2coiG ⟪ σ , gst ⟫ gst\nCOI.SType.force (ind2coiS{n} σ (var x))\n with get x σ\n... | σ' , gxs rewrite (n∸x≡suc[n∸sucx]{n}{toℕ x} toℕx mcl2coiG ⟪ σ' , g ⟫ g\n-------- getMCl x (stack2StackMCl σ) = (stack2StackMCl (get x σ).1 , mclG ⟪ stack2StackS (get x σ).1 , rec (get x σ).2 ⟫ (get x σ).2\n-- => mcl2coiG ⟪ (stack2StackMCl (get x σ).1 , mclG ⟪ stack2StackS (get x σ).1 , rec (get x σ).2 ⟫ (get x σ).2 ⟫ (mclG ⟪ stack2StackS (get x σ).1 , rec (get x σ).2 ⟫ (get x σ).2)\n------- which by definition of stack2StackMCl and stack2StackS is equivalent to\n-- = mcl2coiG (stack2StackMCl ⟪ (get x σ).1 , (get x σ).2 ⟫) (mclG (stack2StackS ⟪ (get x σ).1 , (get x σ).2 ⟫) g)\n------- which, by mcl-equiv-G\n-- ≈' ind2coiG ⟪ (get x σ).1 , (get x σ).2 ⟫ (get x σ).2\n-- = ind2coiG σ (var x)\n\ngetMCl-get : (x : Fin n) (σ : Stack n)\n → getMCl x (stack2StackMCl σ) ≡ (stack2StackMCl (proj₁ (get x σ)) , mclG ⟪ stack2StackS (proj₁ (get x σ)) , rec (proj₂ (get x σ)) ⟫ (proj₂ (get x σ)))\ngetMCl-get zero ⟪ σ , x ⟫ = refl\ngetMCl-get (suc x) ⟪ σ , x₁ ⟫ = getMCl-get x σ\n\n----------------------------------------------------------------------\n\nmcl-equiv-S : (σ : Stack n) (s : IND.SType n) →\n mcl2coiS (stack2StackMCl σ) (mclS (stack2StackS σ) s) ≈ ind2coiS σ s\nmcl-equiv-G : (σ : Stack n) (g : IND.GType n) →\n mcl2coiG (stack2StackMCl σ) (mclG (stack2StackS σ) g) ≈' ind2coiG σ g\nmcl-equiv-T : (σ : Stack n) (t : IND.Type n) →\n mcl2coiT (stack2StackMCl σ) (mclT (stack2StackS σ) t) ≈ᵗ ind2coiT σ t\n\nCOI.Equiv.force (mcl-equiv-S σ (gdd gst)) = mcl-equiv-G σ gst\nCOI.Equiv.force (mcl-equiv-S σ (rec gst)) = mcl-equiv-G ⟪ σ , gst ⟫ gst\nCOI.Equiv.force (mcl-equiv-S{n} σ (var x))\n rewrite (getMCl-get x σ)\n with (proj₁ (get x σ)) | (proj₂ (get x σ))\n... | σ' | g rewrite (n∸x≡suc[n∸sucx]{n}{toℕ x} toℕx (n + 0) ≡ n\nunitPlus 0 = refl 0\nunitPlus (suc m) = ap suc (unitPlus m)\n\nsPlus : (n m : ℕ) -> suc (n + m) ≡ (n + suc m)\nsPlus 0 m = refl (suc m) \nsPlus (suc n) m = ap suc (sPlus n m)\n\ncommPlus : (m n : ℕ) -> (m + n) ≡ (n + m)\ncommPlus 0 n = ! (unitPlus n)\ncommPlus (suc m) n = (ap suc (commPlus m n)) ∘ (sPlus n m)\n\nassocPlus : (m n o : ℕ) ->((m + n) + o) ≡ (m + (n + o))\nassocPlus 0 n o = refl (n + o)\nassocPlus (suc m) n o = ap suc (assocPlus m n o)\n\n--\n\nunitMult : (i : ℕ) → 1 * i ≡ i\nunitMult 0 = refl 0\nunitMult (suc i) = ap suc (unitMult i) \n\nmulSuc : (m n : ℕ) → m * suc n ≡ m + m * n\nmulSuc 0 n = refl 0\nmulSuc (suc m) n = ap (λ x → suc n + x) (mulSuc m n) ∘ \n ap suc (! (assocPlus n m (m * n))) ∘ \n ap (λ x → suc (x + m * n)) (commPlus n m) ∘ \n ap suc (assocPlus m n (m * n))\n \nannMult : (i : ℕ) → i * 0 ≡ 0\nannMult 0 = refl 0\nannMult (suc i) = annMult i\n\ncommMult : (i j : ℕ) → i * j ≡ j * i\ncommMult 0 j = ! (annMult j) \ncommMult (suc i) j = ap (λ x → j + x) (commMult i j) ∘ \n (! (mulSuc j i))\n\ndistrib : (i j k : ℕ) → (j + k) * i ≡ j * i + k * i\ndistrib i 0 k = refl (k * i)\ndistrib i (suc j) k = ap (_+_ i) (distrib i j k) ∘ \n (! (assocPlus i (j * i) (k * i))) \n\n\nassocMult : (i j k : ℕ) → (i * j) * k ≡ i * (j * k)\nassocMult 0 j k = refl 0\nassocMult (suc i) j k = distrib k j (i * j) ∘ \n ap (λ x → j * k + x) (assocMult i j k)\n--}\n\n--\n\ntoℚ : FT → ℚ\ntoℚ b = recPI (record {\n czero = + 0 ÷ 1 ;\n cone = + 1 ÷ 1 ;\n cplus = {!!} ; --_+_ ; \n ctimes = {!!} ; --_*_ ;\n cneg = {!!} ;\n crecip = {!!} ;\n cunite₊≡ = {!!} ; --λ {c} → refl c ;\n cuniti₊≡ = {!!} ; --λ {c} → refl c ;\n cswap₊≡ = {!!} ; --λ {a b} → commPlus a b ;\n cassocl₊≡ = {!!} ; --λ {a b c} → ! (assocPlus a b c) ;\n cassocr₊≡ = {!!} ; --λ {a b c} → assocPlus a b c ;\n cunite⋆≡ = {!!} ; --λ {a} → unitMult a ;\n cuniti⋆≡ = {!!} ; --λ {a} → ! (unitMult a) ;\n cswap⋆≡ = {!!} ; --λ {a b} → commMult a b ;\n cassocl⋆≡ = {!!} ; --λ {a b c} → ! (assocMult a b c) ;\n cassocr⋆≡ = {!!} ; --λ {a b c} → assocMult a b c ;\n cdistz≡ = {!!} ; --refl 0 ;\n cfactorz≡ = {!!} ; --refl 0 ;\n cdist≡ = {!!} ; --λ {a b c} → distrib c a b ;\n cfactor≡ = {!!} ; --λ {a b c} → ! (distrib c a b) ;\n cη₊ = {!!} ;\n cε₊ = {!!} ;\n crefe⋆ = {!!} ;\n crefi⋆ = {!!} ;\n crile⋆ = {!!} ;\n crili⋆ = {!!} \n }) b\n\n------------------------------------------------------------------------------\n\n", "meta": {"hexsha": "d0074e91f192fa2aa94f767c685f34c49a4b8b0d", "size": 30243, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "HP.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "HP.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "HP.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 31.5688935282, "max_line_length": 79, "alphanum_fraction": 0.4243626624, "num_tokens": 14386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.5813030906443134, "lm_q1q2_score": 0.3660899256934946}} {"text": "open import Mockingbird.Forest using (Forest)\n\n-- Russel’s Forest\nmodule Mockingbird.Problems.Chapter15 {b ℓ} (forest : Forest {b} {ℓ}) where\n\nopen import Data.Empty using (⊥; ⊥-elim)\nopen import Data.Product using (_×_; _,_; ∃-syntax; proj₁; proj₂)\nopen import Data.Sum using (_⊎_; inj₁; inj₂)\nopen import Function using (_$_; flip; case_of_; _⇔_; Equivalence; mk⇔)\nopen import Function.Equivalence.Reasoning renaming (begin_ to ⇔-begin_; _∎ to _⇔-∎)\nopen import Level using (_⊔_)\nopen import Relation.Binary using (_Respects_)\nopen import Relation.Nullary using (¬_)\nopen import Relation.Unary using (Pred)\n\nopen Forest forest\nopen import Mockingbird.Forest.Birds forest\n\n⇔-¬ : ∀ {a b} {A : Set a} {B : Set b} → A ⇔ B → (¬ A) ⇔ (¬ B)\n⇔-¬ A⇔B = record\n { f = λ ¬A b → ¬A (A⇔B.g b)\n ; g = λ ¬B a → ¬B (A⇔B.f a)\n ; cong₁ = λ p → ≡.cong _ p\n ; cong₂ = λ p → ≡.cong _ p\n } where\n module A⇔B = Equivalence A⇔B\n open import Relation.Binary.PropositionalEquality as ≡ using (cong)\n\n⇔-↯ : ∀ {a} {A : Set a} → ¬ (A ⇔ (¬ A))\n⇔-↯ {A = A} A⇔¬A = yes but no\n where\n _but_ = flip _$_\n\n no : ¬ A\n no A = Equivalence.f A⇔¬A A A\n\n yes : A\n yes = Equivalence.g A⇔¬A no\n\nmodule _ {s} (Sings : Pred Bird s)\n (respects : Sings Respects _≈_) where\n private\n -- TODO: move to Mockingbird.Forest.Axiom(.ExcludedMiddle)?\n ExcludedMiddle : Set (b ⊔ s)\n ExcludedMiddle = ∀ x → Sings x ⊎ ¬ Sings x\n\n doubleNegation : ExcludedMiddle → ∀ x → ¬ ¬ Sings x → Sings x\n doubleNegation LEM x ¬¬x-sings with LEM x\n ... | inj₁ x-sings = x-sings\n ... | inj₂ ¬x-sings = ⊥-elim $ ¬¬x-sings ¬x-sings\n\n doubleNegation-⇔ : ExcludedMiddle → ∀ x → (¬ ¬ Sings x) ⇔ Sings x\n doubleNegation-⇔ LEM x = mk⇔ (doubleNegation LEM x) λ x-sings ¬x-sings → ¬x-sings x-sings\n\n respects-⇔ : ∀ {x y} → x ≈ y → Sings x ⇔ Sings y\n respects-⇔ x≈y = mk⇔ (respects x≈y) (respects (sym x≈y))\n\n problem₁ :\n ExcludedMiddle\n → ∃[ a ] (∀ x → Sings (a ∙ x) ⇔ Sings (x ∙ x))\n → (∀ x → ∃[ x′ ] (∀ y → Sings (x′ ∙ y) ⇔ (¬ Sings (x ∙ y))))\n → ⊥\n problem₁ LEM (a , is-a) neg =\n let (a′ , is-a′) = neg a\n\n a′a′-sings⇔¬a′a′-sings : Sings (a′ ∙ a′) ⇔ (¬ Sings (a′ ∙ a′))\n a′a′-sings⇔¬a′a′-sings = ⇔-begin\n Sings (a′ ∙ a′) ⇔⟨ is-a′ a′ ⟩\n ¬ Sings (a ∙ a′) ⇔⟨ ⇔-¬ $ is-a a′ ⟩\n (¬ Sings (a′ ∙ a′)) ⇔-∎\n\n a′a′-sings⇒¬a′a′-sings = Equivalence.f a′a′-sings⇔¬a′a′-sings\n ¬a′a′-sings⇒a′a′-sings = Equivalence.g a′a′-sings⇔¬a′a′-sings\n\n ↯ : ⊥\n ↯ = case LEM (a′ ∙ a′) of λ\n { (inj₁ a′a′-sings) → a′a′-sings⇒¬a′a′-sings a′a′-sings a′a′-sings\n ; (inj₂ ¬a′a′-sings) → ¬a′a′-sings (¬a′a′-sings⇒a′a′-sings ¬a′a′-sings)\n }\n in ↯\n\n -- A constructive proof of Russel’s paradox, not using the LEM.\n problem₁′ :\n ∃[ a ] (∀ x → Sings (a ∙ x) ⇔ Sings (x ∙ x))\n → (∀ x → ∃[ x′ ] (∀ y → Sings (x′ ∙ y) ⇔ (¬ Sings (x ∙ y))))\n → ⊥\n problem₁′ (a , is-a) neg =\n let (a′ , is-a′) = neg a\n\n a′a′-sings⇔¬a′a′-sings : Sings (a′ ∙ a′) ⇔ (¬ Sings (a′ ∙ a′))\n a′a′-sings⇔¬a′a′-sings = ⇔-begin\n Sings (a′ ∙ a′) ⇔⟨ is-a′ a′ ⟩\n (¬ Sings (a ∙ a′)) ⇔⟨ ⇔-¬ $ is-a a′ ⟩\n (¬ Sings (a′ ∙ a′)) ⇔-∎\n\n in ⇔-↯ a′a′-sings⇔¬a′a′-sings\n\n problem₂ : ⦃ _ : HasSageBird ⦄\n → ExcludedMiddle\n → ∃[ N ] (∀ x → Sings x ⇔ (¬ Sings (N ∙ x)))\n → ⊥\n problem₂ LEM (N , is-N) = isNotFond isFond\n where\n isFond : N IsFondOf (Θ ∙ N)\n isFond = isSageBird N\n\n isNotFond : ¬ N IsFondOf (Θ ∙ N)\n isNotFond isFond with LEM (Θ ∙ N)\n ... | inj₁ ΘN-sings = Equivalence.f (is-N (Θ ∙ N)) ΘN-sings (respects (sym isFond) ΘN-sings)\n ... | inj₂ ¬ΘN-sings =\n let N[ΘN]-sings : Sings (N ∙ (Θ ∙ N))\n N[ΘN]-sings = doubleNegation LEM (N ∙ (Θ ∙ N)) $\n Equivalence.f (⇔-¬ (is-N (Θ ∙ N))) ¬ΘN-sings\n in Equivalence.f (is-N (Θ ∙ N)) (respects isFond N[ΘN]-sings) N[ΘN]-sings\n\n -- A constructive proof of problem 2, not using the LEM.\n problem₂′ : ⦃ _ : HasSageBird ⦄\n → ∃[ N ] (∀ x → Sings x ⇔ (¬ Sings (N ∙ x)))\n → ⊥\n problem₂′ (N , is-N) = ⇔-↯ ΘN-sings⇔¬ΘN-sings\n where\n isFond : N IsFondOf (Θ ∙ N)\n isFond = isSageBird N\n\n ΘN-sings⇔¬ΘN-sings : Sings (Θ ∙ N) ⇔ (¬ Sings (Θ ∙ N))\n ΘN-sings⇔¬ΘN-sings = ⇔-begin\n Sings (Θ ∙ N) ⇔⟨ is-N (Θ ∙ N) ⟩\n ¬ Sings (N ∙ (Θ ∙ N)) ⇔⟨ ⇔-¬ $ respects-⇔ isFond ⟩\n (¬ Sings (Θ ∙ N)) ⇔-∎\n\n problem₃ : ⦃ _ : HasSageBird ⦄\n → ∃[ A ] (∀ x y → Sings (A ∙ x ∙ y) ⇔ (¬ Sings x × ¬ Sings y))\n → ⊥\n problem₃ (A , is-A) = ↯\n where\n isFond : ∀ {x} → A ∙ x IsFondOf (Θ ∙ (A ∙ x))\n isFond {x} = isSageBird (A ∙ x)\n\n ¬Θ[Ax]-sings : ∀ x → ¬ Sings (Θ ∙ (A ∙ x))\n ¬Θ[Ax]-sings x Θ[Ax]-sings =\n let Ax[Θ[Ax]]-sings : Sings (A ∙ x ∙ (Θ ∙ (A ∙ x)))\n Ax[Θ[Ax]]-sings = respects (sym isFond) Θ[Ax]-sings\n\n ¬Θ[Ax]-sings : ¬ Sings (Θ ∙ (A ∙ x))\n ¬Θ[Ax]-sings = proj₂ $ Equivalence.f (is-A x (Θ ∙ (A ∙ x))) Ax[Θ[Ax]]-sings\n in ¬Θ[Ax]-sings Θ[Ax]-sings\n\n ¬¬x-sings : ∀ x → ¬ ¬ Sings x\n ¬¬x-sings x ¬x-sings =\n let Ax[Θ[Ax]]-sings = Equivalence.g (is-A x (Θ ∙ (A ∙ x))) (¬x-sings , ¬Θ[Ax]-sings x)\n Θ[Ax]-sings = respects isFond Ax[Θ[Ax]]-sings\n in ¬Θ[Ax]-sings x Θ[Ax]-sings\n\n ↯ : ⊥\n ↯ = ¬¬x-sings (Θ ∙ (A ∙ A)) $ ¬Θ[Ax]-sings A\n", "meta": {"hexsha": "d79cb0a04760ca3a772d5a83218f8044af1355ff", "size": 5404, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Mockingbird/Problems/Chapter15.agda", "max_stars_repo_name": "splintah/combinatory-logic", "max_stars_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-28T23:44:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:42.000Z", "max_issues_repo_path": "Mockingbird/Problems/Chapter15.agda", "max_issues_repo_name": "splintah/combinatory-logic", "max_issues_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0", "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": "Mockingbird/Problems/Chapter15.agda", "max_forks_repo_name": "splintah/combinatory-logic", "max_forks_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0", "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": 34.641025641, "max_line_length": 98, "alphanum_fraction": 0.4985196151, "num_tokens": 2555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.4921881357207955, "lm_q1q2_score": 0.36577847668631325}} {"text": "module CP where \n\nopen import Level \nopen import Data.Nat \nopen import Relation.Nullary \n-- open import Data.String using (String)\n\n\nTypeVar : Set \nTypeVar = ℕ \n\ninfixl 10 _⨂_\ninfixl 10 _⅋_\ndata Type : Set where \n -- ‵_ : TypeVar → Type\n -- _^ : Type → Type \n _⨂_ : Type → Type → Type \n _⅋_ : Type → Type → Type \n -- _⨁_ : Type → Type → Type \n -- _&_ : Type → Type → Type \n -- !_ : Type → Type \n -- ¿_ : Type → Type \n -- ∃[_] : Type → Type \n -- ∀[_] : Type → Type \n 𝟙 : Type \n ⊥ : Type \n 𝟘 : Type \n ⊤ : Type \n\n\ninfixl 11 _^\n_^ : Type → Type \n(A ⨂ B) ^ = A ^ ⅋ B ^\n(A ⅋ B) ^ = A ^ ⨂ B ^\n𝟙 ^ = ⊥\n⊥ ^ = 𝟙\n𝟘 ^ = ⊤\n⊤ ^ = 𝟘\n\n\n\n\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Nullary.Decidable\nopen import Relation.Nullary.Product\nopen import Data.Product\nopen import Agda.Builtin.Bool \n\n-- _≟t_ : (A B : Type) → Dec (A ≡ B)\n-- (A ⨂ B) ≟t (C ⨂ D) with A ≟t C | B ≟t D \n-- ... | yes refl | yes refl = yes refl\n-- ... | yes refl | no ¬q = no λ where refl → ¬q refl\n-- ... | no ¬p | yes q = no λ where refl → ¬p refl\n-- ... | no ¬p | no ¬q = no λ where refl → ¬p refl\n-- (A ⨂ B) ≟t (C ⅋ D) = no (λ ())\n-- (A ⨂ B) ≟t 𝟙 = no (λ ())\n-- (A ⨂ B) ≟t ⊥ = no (λ ())\n-- (A ⨂ B) ≟t 𝟘 = no (λ ())\n-- (A ⨂ B) ≟t ⊤ = no (λ ())\n-- (A ⅋ B) ≟t (C ⨂ D) = no (λ ())\n-- (A ⅋ B) ≟t (C ⅋ D) with A ≟t C | B ≟t D \n-- ... | yes refl | yes refl = yes refl\n-- ... | yes refl | no ¬q = no λ where refl → ¬q refl\n-- ... | no ¬p | yes q = no λ where refl → ¬p refl\n-- ... | no ¬p | no ¬q = no λ where refl → ¬p refl\n-- (A ⅋ B) ≟t 𝟙 = no (λ ())\n-- (A ⅋ B) ≟t ⊥ = no (λ ())\n-- (A ⅋ B) ≟t 𝟘 = no (λ ())\n-- (A ⅋ B) ≟t ⊤ = no (λ ())\n-- 𝟙 ≟t (B ⨂ C) = no (λ ())\n-- 𝟙 ≟t (B ⅋ C) = no (λ ())\n-- 𝟙 ≟t 𝟙 = yes refl\n-- 𝟙 ≟t ⊥ = no (λ ())\n-- 𝟙 ≟t 𝟘 = no (λ ())\n-- 𝟙 ≟t ⊤ = no (λ ())\n-- ⊥ ≟t (B ⨂ C) = no (λ ())\n-- ⊥ ≟t (B ⅋ C) = no (λ ())\n-- ⊥ ≟t 𝟙 = no (λ ())\n-- ⊥ ≟t ⊥ = yes refl\n-- ⊥ ≟t 𝟘 = no (λ ())\n-- ⊥ ≟t ⊤ = no (λ ())\n-- 𝟘 ≟t (B ⨂ C) = no (λ ())\n-- 𝟘 ≟t (B ⅋ C) = no (λ ())\n-- 𝟘 ≟t 𝟙 = no (λ ())\n-- 𝟘 ≟t ⊥ = no (λ ())\n-- 𝟘 ≟t 𝟘 = yes refl\n-- 𝟘 ≟t ⊤ = no (λ ())\n-- ⊤ ≟t (B ⨂ C) = no (λ ())\n-- ⊤ ≟t (B ⅋ C) = no (λ ())\n-- ⊤ ≟t 𝟙 = no (λ ())\n-- ⊤ ≟t ⊥ = no (λ ())\n-- ⊤ ≟t 𝟘 = no (λ ())\n-- ⊤ ≟t ⊤ = yes refl\n\n\n\nChan : Set \nChan = ℕ\n\ndata Proc⁺ : Set \ndata Proc⁻ : Set \n\ndata Proc⁺ where \n _↔_ : Chan → Chan → Proc⁺\n\n ν_∶_∙_∣_ : Chan → Type → Proc⁻ → Proc⁻ → Proc⁺\n-- infixl 7 _⟦⟧0\n\n-- inherited types\ndata Proc⁻ where \n \n -- x[y].(P|Q)\n _⟦_⟧_∣_ : Chan → Chan → Proc⁻ → Proc⁻ → Proc⁻\n\n -- x(y).(P|Q)\n _⦅_⦆_ : Chan → Chan → Proc⁻ → Proc⁻\n\n -- x[].0\n _⟦⟧0 : Chan → Proc⁻\n -- x().P\n _⦅⦆_ : Chan → Proc⁻ → Proc⁻\n -- x.case()\n _case : Chan → Proc⁻\n\n-- _[_/_] : Type → Type → TypeVar → Type \n-- (‵ P) [ T / X ] with P ≟ X \n-- ((‵ P) [ T / X ]) | yes p = T\n-- ((‵ P) [ T / X ]) | no ¬p = ‵ P\n-- (P ^) [ T / X ] = (P [ T / X ]) ^\n-- (P ⨂ Q) [ T / X ] = (P [ T / X ]) ⨂ (Q [ T / X ])\n-- (P ⅋ Q) [ T / X ] = (P [ T / X ]) ⅋ (Q [ T / X ])\n-- (P ⨁ Q) [ T / X ] = (P [ T / X ]) ⨁ (Q [ T / X ])\n-- (P & Q) [ T / X ] = (P [ T / X ]) & (Q [ T / X ])\n-- (! P) [ T / X ] = ! (P [ T / X ])\n-- (¿ P) [ T / X ] = ¿ (P [ T / X ])\n-- ∃[ P ] [ T / zero ] = {! !}\n-- ∃[ P ] [ T / suc X ] = {! !}\n-- ∀[ P ] [ T / X ] = {! !}\n-- 𝟙 [ T / X ] = {! !}\n-- ⊥ [ T / X ] = {! !}\n-- 𝟘 [ T / X ] = {! !}\n-- ⊤ [ T / X ] = {! !}\n\n\n-- infixl 5 _,_∶_ \n-- data Session : Set where \n-- _,_∶_ : Session → Chan → Type → Session\n-- _++_ : Session → Session → Session\n-- ∅ : Session\n\n-- infix 4 _⊢↓_\n-- infix 4 _⊢↑_\n-- data _⊢↑_ : Proc⁺ → Session → Set\n-- data _⊢↓_ : Proc⁻ → Session → Set\n\n-- data _⊢↑_ where \n-- ⊢↔ : ∀ {w x A} \n-- ---------------\n-- → w ↔ x ⊢↑ ∅ , w ∶ A ^ , x ∶ A\n\n-- ⊢Cut : ∀ {P Q Γ Δ x A} \n-- → P ⊢↓ Γ , x ∶ A\n-- → Q ⊢↓ Δ , x ∶ A ^ \n-- ---------------\n-- → ν x ∶ A ∙ P ∣ Q ⊢↑ Γ ++ Δ \n\n\n-- data _⊢↓_ where \n\n-- ⊢⨂ : ∀ {P Q Γ Δ y x A B}\n-- → P ⊢↓ Γ , y ∶ A \n-- → Q ⊢↓ Δ , x ∶ B\n-- ---------------\n-- → x ⟦ y ⟧ P ∣ Q ⊢↓ ∅ , x ∶ 𝟙\n\n-- ⊢⅋ : ∀ {R Θ y x A B}\n-- → R ⊢↓ Θ , y ∶ A , x ∶ B\n-- ---------------\n-- → x ⦅ y ⦆ R ⊢↓ Θ , x ∶ A ⅋ B\n\n\n-- ⊢𝟏 : ∀ {x}\n-- ---------------\n-- → x ⟦⟧0 ⊢↓ ∅ , x ∶ 𝟙\n \n-- ⊢⊥ : ∀ {x P Γ}\n-- → P ⊢↓ Γ \n-- ---------------\n-- → x ⦅⦆ P ⊢↓ Γ , x ∶ ⊥\n\n-- ⊢⊤ : ∀ {x Γ}\n-- ---------------\n-- → x case ⊢↓ Γ , x ∶ ⊤\n \n-- data Result (P : Proc⁺) : Set where \n-- known : (Γ : Session) → P ⊢↑ Γ → Result P\n-- cntx? : ((Γ : Session) → P ⊢↑ Γ) → Result P \n-- type? : ((Γ : Session) → (x : Chan) → (T : Type) → P ⊢↑ Γ , x ∶ T) → Result P \n-- wrong : Result P\n\n-- infer : ∀ (P : Proc⁺) → Result P\n-- infer (w ↔ x) = type? λ Γ x A → {! ⊢↔ {w} {x} {A} !}\n-- infer (ν x ∶ x₁ ∙ x₂ ∣ x₃) = {! !}\n\n-- open import Data.Bool hiding (_≟_)\n\n\nopen import Relation.Binary using (Decidable; DecSetoid)\n\nChanSetoid : DecSetoid _ _\nChanSetoid = ≡-decSetoid\n where \n open import Data.Nat.Properties using (≡-decSetoid)\n\n\nmodule Example where \n open import CP.Session3 ChanSetoid Type \n \n Γ : Session\n Γ = (0 ∶ 𝟙) ∷ (1 ∶ 𝟘) ∷ []\n\n Δ : Session \n Δ = (1 ∶ 𝟘) ∷ (0 ∶ 𝟙) ∷ []\n\n open import Data.List.Relation.Binary.Subset.DecSetoid typeOfDecSetoid\n\n-- _∋_ : Session → Chan → Bool \n-- (Γ , y ∶ A) ∋ x with x ≟ y \n-- ... | no ¬p = Γ ∋ x\n-- ... | yes p = true\n-- (Γ ++ Δ) ∋ x = (Γ ∋ x) ∨ (Δ ∋ x)\n-- ∅ ∋ x = false\n\n-- _≈_ : Session → Session → Set \n-- Γ ≈ Δ = ∀ x → Γ ∋ x ≡ Δ ∋ x\n\n-- empty : ∀ {Γ x A} → ¬ (∅ ≈ (Γ , x ∶ A))\n-- empty {Γ} {x} {A} P with x ≟ x\n-- ... | no ¬p = {! !}\n-- ... | yes p = {! !}\n\n-- lookup : (Γ : Session) (x : Chan) → Dec (∃[ Δ ] ∃[ A ] (Γ ≈ (Δ , x ∶ A)))\n-- lookup (Γ , y ∶ A) x = {! !}\n-- lookup (Γ ++ Δ) x with lookup Γ x \n-- ... | yes p = {! !}\n-- ... | no ¬p = {! !}\n-- lookup ∅ x = no (λ where (Γ , A , P) → {! P x !})\n\n\n\n-- infer : ∀ (P : Proc⁺) → Dec (∃[ Γ ] (P ⊢↑ Γ))\n-- infer' : ∀ (P : Proc⁻) → Dec (∃[ Γ ] (P ⊢↓ Γ))\n-- check : ∀ (P : Proc⁻) (Γ : Session) → Dec (P ⊢↓ Γ)\n\n-- infer' (x ⟦ y ⟧ P ∣ Q) = {! !}\n-- infer' (x ⦅ y ⦆ P) with infer' P \n-- ... | no ¬p = no λ where ((Γ , x ∶ A ⅋ B) , ⊢⅋ P⊢Γ) → ¬p ((Γ , y ∶ A , x ∶ B) , P⊢Γ)\n-- ... | yes (Γ , P⊢Γ) = yes ({! !} , (⊢⅋ {! !}))\n-- infer' (x ⟦⟧0) = yes (∅ , x ∶ 𝟙 , ⊢𝟏)\n-- infer' (x ⦅⦆ P) with infer' P \n-- ... | no ¬p = no λ where ((Γ , x ∶ ⊥) , ⊢⊥ P⊢Γ) → ¬p (Γ , P⊢Γ)\n-- ... | yes (Γ , P⊢Γ) = yes ((Γ , x ∶ ⊥) , (⊢⊥ P⊢Γ))\n-- infer' (x case) = yes (∅ , x ∶ ⊤ , ⊢⊤)\n\n-- infer (w ↔ x) = yes ((∅ , w ∶ {! !} , x ∶ {! !}) , ⊢↔)\n-- infer (ν x ∶ A ∙ P ∣ Q) with infer' P | infer' Q\n-- ... | no ¬p | no ¬q = {! !}\n-- ... | no ¬p | yes q = no (λ where (.(_ ++ _) , ⊢Cut x _) → ¬p {! x !})\n-- ... | yes p | no ¬q = {! !}\n-- ... | yes (Γ , P⊢Γ) | yes (Δ , Q⊢Δ) = yes ({! !} , ⊢Cut {! P⊢Γ !} {! !})\n-- -- = yes ({! !} , {! !})\n\n-- check P Γ = {! !}\n\n\n-- infixl 4 _∶_∈_\n-- data _∶_∈_ : Channel → Type → Session → Set where\n-- Z : ∀ {Γ x A} \n-- ------------------\n-- → x ∶ A ∈ Γ , x ∶ A\n\n-- S_ : ∀ {Γ x y A B} \n-- → x ∶ A ∈ Γ \n-- ------------------\n-- → x ∶ A ∈ Γ , x ∶ A , y ∶ B\n\n-- ¿[_] : Session → Session\n-- ¿[ Γ , x ∶ A ] = ¿[ Γ ] , x ∶ ¿ A\n-- ¿[ Γ ++ Δ ] = ¿[ Γ ] ++ ¿[ Δ ]\n-- ¿[ ∅ ] = ∅ \n\n-- infix 4 ⊢_\n-- data ⊢_ : Session → Set where \n\n-- Ax : ∀ {A w x} \n-- ---------------------------\n-- → ⊢ ∅ , w ∶ A ^ , x ∶ A\n\n-- Cut : ∀ {Γ Δ x A} \n-- → (P : ⊢ Γ , x ∶ A) \n-- → (Q : ⊢ Δ , x ∶ A ^) \n-- ---------------------------\n-- → ⊢ Γ ++ Δ\n\n-- Times : ∀ {Γ Δ x y A B} \n-- → (P : ⊢ Γ , y ∶ A) \n-- → (Q : ⊢ Δ , x ∶ B) \n-- ---------------------------\n-- → ⊢ Γ ++ Δ , x ∶ A ⨂ B\n\n-- Par : ∀ {Θ x y A B} \n-- → (R : ⊢ Θ , y ∶ A , x ∶ B) \n-- ---------------------------\n-- → ⊢ Θ , x ∶ A ⅋ B\n\n-- PlusL : ∀ {Γ x A B} \n-- → (P : ⊢ Γ , x ∶ A) \n-- ---------------------------\n-- → ⊢ Γ , x ∶ A ⨁ B\n\n-- PlusR : ∀ {Γ x A B} \n-- → (P : ⊢ Γ , x ∶ B) \n-- ---------------------------\n-- → ⊢ Γ , x ∶ A ⨁ B\n\n-- With : ∀ {Δ x A B} \n-- → (Q : ⊢ Δ , x ∶ A) \n-- → (R : ⊢ Δ , x ∶ B) \n-- ---------------------------\n-- → ⊢ Δ , x ∶ A & B\n\n-- OfCourse : ∀ {Γ x y A} \n-- → (P : ⊢ ¿[ Γ ] , y ∶ A) \n-- ---------------------------\n-- → ⊢ ¿[ Γ ] , x ∶ ! A\n\n-- WhyNot : ∀ {Δ x y A} \n-- → (Q : ⊢ Δ , y ∶ A) \n-- ---------------------------\n-- → ⊢ Δ , x ∶ ¿ A\n\n-- Weaken : ∀ {Δ x A} \n-- → (Q : ⊢ Δ) \n-- ---------------------------\n-- → ⊢ Δ , x ∶ ¿ A\n\n-- Contract : ∀ {Δ x x' A} \n-- → (Q : ⊢ Δ , x ∶ ¿ A , x' ∶ ¿ A) \n-- ---------------------------\n-- → ⊢ Δ , x ∶ ¿ A\n \n-- -- Exist : ∀ {Γ x x' A} \n-- -- → (Q : ⊢ Δ , x ∶ ¿ A , x' ∶ ¿ A) \n-- -- ---------------------------\n-- -- → ⊢ Δ , x ∶ ¿ A", "meta": {"hexsha": "00684b59fa1148528eb62bc101051f3f515a3f21", "size": 9089, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "CP.agda", "max_stars_repo_name": "banacorn/bidirectional", "max_stars_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-25T07:34:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-25T14:05:01.000Z", "max_issues_repo_path": "CP.agda", "max_issues_repo_name": "banacorn/bidirectional", "max_issues_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "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": "CP.agda", "max_forks_repo_name": "banacorn/bidirectional", "max_forks_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "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": 25.6028169014, "max_line_length": 87, "alphanum_fraction": 0.3098250633, "num_tokens": 4254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.743167997235783, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.36577847108683736}} {"text": "\nmodule UniDB.Morph.Sim where\n\nopen import UniDB.Spec\nopen import UniDB.Subst.Core\nopen import UniDB.Morph.Depth\nimport Level\nopen import Relation.Binary.PropositionalEquality\n\n--------------------------------------------------------------------------------\n\nrecord Sim (T : STX) (γ₁ γ₂ : Dom) : Set where\n constructor sim\n field\n lk-sim : (i : Ix γ₁) → T γ₂\nopen Sim public\n\nmodule _ {T : STX} where\n instance\n iLkSim : {{vrT : Vr T}} → Lk T (Sim T)\n lk {{iLkSim}} = lk-sim\n\n iWkSim : {{wkT : Wk T}} → {γ₁ : Dom} → Wk (Sim T γ₁)\n wk₁ {{iWkSim}} (sim f) = sim (wk₁ ∘ f)\n wk {{iWkSim}} δ (sim f) = sim (wk δ ∘ f)\n wk-zero {{iWkSim {{wkT}}}} (sim f) = cong sim (ext (wk-zero {T} ∘ f))\n where postulate ext : Extensionality Level.zero Level.zero\n wk-suc {{iWkSim}} δ (sim f) = cong sim (ext (wk-suc {T} δ ∘ f))\n where postulate ext : Extensionality Level.zero Level.zero\n\n iSnocSim : Snoc T (Sim T)\n snoc {{iSnocSim}} (sim f) t = sim λ\n { zero → t\n ; (suc i) → f i\n }\n\n iUpSim : {{vrT : Vr T}} {{wkT : Wk T}} → Up (Sim T)\n _↑₁ {{iUpSim}} ξ = snoc {T} {Sim T} (wk₁ ξ) (vr {T} zero)\n _↑_ {{iUpSim}} ξ 0 = ξ\n _↑_ {{iUpSim}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁\n ↑-zero {{iUpSim}} ξ = refl\n ↑-suc {{iUpSim}} ξ δ⁺ = refl\n\n iIdmSim : {{vrT : Vr T}} → Idm (Sim T)\n idm {{iIdmSim}} γ = sim (vr {T})\n\n iWkmSim : {{vrT : Vr T}} → Wkm (Sim T)\n wkm {{iWkmSim}} δ = sim (vr {T} ∘ wk δ)\n\n iBetaSim : {{vrT : Vr T}} → Beta T (Sim T)\n beta {{iBetaSim}} t = snoc {T} {Sim T} (idm {Sim T} _) t\n\n iCompSim : {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} → Comp (Sim T)\n lk-sim (_⊙_ {{iCompSim}} ξ ζ) i =\n ap {T} {T} {Sim T} ζ (lk {T} {Sim T} ξ i)\n\n iLkUpSim : {{vrT : Vr T}} {{wkT : Wk T}} → LkUp T (Sim T)\n lk-↑₁-zero {{iLkUpSim}} ξ = refl\n lk-↑₁-suc {{iLkUpSim}} ξ zero = refl\n lk-↑₁-suc {{iLkUpSim}} ξ (suc i) = refl\n\n iLkWkmSim : {{vrT : Vr T}} → LkWkm T (Sim T)\n lk-wkm {{iLkWkmSim}} δ i = refl\n\n iLkIdmSim : {{vrT : Vr T}} → LkIdm T (Sim T)\n lk-idm {{iLkIdmSim}} i = refl\n\n iLkCompSim : {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} → LkCompAp T (Sim T)\n lk-⊙-ap {{iLkCompSim}} ξ₁ ξ₂ i = refl\n\n--------------------------------------------------------------------------------\n\nmodule SimIxInstances (T : STX) where\n\n instance\n iLkSimIx : {{vrT : Vr T}} → Lk T (Sim Ix)\n lk {{iLkSimIx}} ξ i = vr {T} (lk {Ix} {Sim Ix} ξ i)\n\n iLkUpSimIx : {{vrT : Vr T}} {{wkT : Wk T}}\n {{wkVrT : WkVr T}} → LkUp T (Sim Ix)\n lk-↑₁-zero {{iLkUpSimIx}} ξ = refl\n lk-↑₁-suc {{iLkUpSimIx}} ξ i = sym (wk₁-vr {T} (lk {Ix} {Sim Ix} ξ i))\n\n iLkWkmSimIx : {{vrT : Vr T}} → LkWkm T (Sim Ix)\n lk-wkm {{iLkWkmSimIx}} δ i = refl\n\n iLkIdmSimIx : {{vrT : Vr T}} → LkIdm T (Sim Ix)\n lk-idm {{iLkIdmSimIx}} i = refl\n\n iLkCompSimIx : {{vrT : Vr T}} {{apTT : Ap T T}}\n {{apVrT : ApVr T}} → LkCompAp T (Sim Ix)\n lk-⊙-ap {{iLkCompSimIx}} ξ₁ ξ₂ i =\n sym (ap-vr {T} {Sim Ix} ξ₂ (lk {Ix} {Sim Ix} ξ₁ i))\n\n--------------------------------------------------------------------------------\n", "meta": {"hexsha": "58a1d8de1f9af52f4f3c904e751ee47927936a53", "size": 3150, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "UniDB/Morph/Sim.agda", "max_stars_repo_name": "skeuchel/unidb-agda", "max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "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": "UniDB/Morph/Sim.agda", "max_issues_repo_name": "skeuchel/unidb-agda", "max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "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": "UniDB/Morph/Sim.agda", "max_forks_repo_name": "skeuchel/unidb-agda", "max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "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": 32.8125, "max_line_length": 85, "alphanum_fraction": 0.4784126984, "num_tokens": 1340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6688802471698041, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.36570235023663045}} {"text": "open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; subst; cong)\n\nopen import Syntax\nimport Renaming\nimport Substitution\n\nmodule Instantiation where\n\n module _ {𝕊 : Signature} where\n\n open Expression 𝕊\n open Substitution\n open Renaming\n open Equality\n\n -- the set of instantiations\n\n infix 5 _→ⁱ_∥_\n\n _→ⁱ_∥_ : MShape → MShape → VShape → Set\n 𝕄 →ⁱ 𝕂 ∥ γ = ∀ {clᴹ γᴹ} (M : [ clᴹ , γᴹ ]∈ 𝕄) → Arg clᴹ 𝕂 γ γᴹ\n\n -- equality of instantiations\n\n infix 4 _≈ⁱ_\n\n _≈ⁱ_ : ∀ {𝕂 𝕄} {γ} (I J : 𝕂 →ⁱ 𝕄 ∥ γ) → Set\n I ≈ⁱ J = ∀ {clᴹ γᴹ} (M : [ clᴹ , γᴹ ]∈ _) → I M ≈ J M\n\n -- equality of instaniations is an equivalence relation\n\n ≈ⁱ-refl : ∀ {𝕂 𝕄} {γ} {I : 𝕂 →ⁱ 𝕄 ∥ γ} → I ≈ⁱ I\n ≈ⁱ-refl M = ≈-refl\n\n ≈ⁱ-sym : ∀ {𝕂 𝕄} {γ} {I J : 𝕂 →ⁱ 𝕄 ∥ γ} → I ≈ⁱ J → J ≈ⁱ I\n ≈ⁱ-sym ξ M = ≈-sym (ξ M)\n\n ≈ⁱ-trans : ∀ {𝕂 𝕄} {γ} {I J K : 𝕂 →ⁱ 𝕄 ∥ γ} → I ≈ⁱ J → J ≈ⁱ K → I ≈ⁱ K\n ≈ⁱ-trans ζ ξ M = ≈-trans (ζ M) (ξ M)\n\n -- identity instantiation\n\n 𝟙ⁱ : ∀ {𝕄 γ} → 𝕄 →ⁱ 𝕄 ∥ γ\n 𝟙ⁱ M = expr-meta-generic M\n\n -- instantiation extension\n\n ⇑ⁱ : ∀ {𝕂 𝕄 γ δ} → 𝕂 →ⁱ 𝕄 ∥ γ → 𝕂 →ⁱ 𝕄 ∥ γ ⊕ δ\n ⇑ⁱ I M = [ ⇑ʳ var-left ]ʳ (I M)\n\n -- extension respects equality\n\n ⇑ⁱ-resp-≈ⁱ : ∀ {𝕂 𝕄} {γ δ} → {I J : 𝕂 →ⁱ 𝕄 ∥ γ} → I ≈ⁱ J → ⇑ⁱ {δ = δ} I ≈ⁱ ⇑ⁱ J\n ⇑ⁱ-resp-≈ⁱ ξ M = []ʳ-resp-≈ (⇑ʳ var-left) (ξ M)\n\n -- the action of an instantiation on an expression\n\n infix 6 [_]ⁱ_\n\n [_]ⁱ_ : ∀ {cl 𝕂 𝕄} {γ} → (𝕂 →ⁱ 𝕄 ∥ γ) → Expr cl 𝕂 γ → Expr cl 𝕄 γ\n [ I ]ⁱ (expr-var x) = expr-var x\n [ I ]ⁱ (expr-symb S es) = expr-symb S (λ i → [ ⇑ⁱ I ]ⁱ es i)\n [ I ]ⁱ (expr-meta M ts) = [ [ 𝟙ˢ , (λ i → [ I ]ⁱ ts i) ]ˢ ]ˢ I M\n [ I ]ⁱ expr-eqty = expr-eqty\n [ I ]ⁱ expr-eqtm = expr-eqtm\n\n -- instantiations respects equality\n\n []ⁱ-resp-≈ : ∀ {cl} {𝕂 𝕄} {γ} (I : 𝕂 →ⁱ 𝕄 ∥ γ) {t u : Expr cl 𝕂 γ} → t ≈ u → [ I ]ⁱ t ≈ [ I ]ⁱ u\n []ⁱ-resp-≈ I (≈-≡ ξ) = ≈-≡ (cong [ I ]ⁱ_ ξ)\n []ⁱ-resp-≈ I (≈-symb ξ) = ≈-symb (λ i → []ⁱ-resp-≈ (⇑ⁱ I) (ξ i))\n []ⁱ-resp-≈ I (≈-meta ξ) = []ˢ-resp-≈ˢ ([,]ˢ-resp-≈ˢ ≈ˢ-refl (λ i → []ⁱ-resp-≈ I (ξ i))) (I _)\n\n []ⁱ-resp-≈ⁱ : ∀ {cl} {𝕂 𝕄} {γ} {I J : 𝕂 →ⁱ 𝕄 ∥ γ} (t : Expr cl 𝕂 γ) → I ≈ⁱ J → [ I ]ⁱ t ≈ [ J ]ⁱ t\n []ⁱ-resp-≈ⁱ (expr-var x) ξ = ≈-refl\n []ⁱ-resp-≈ⁱ (expr-symb S es) ξ = ≈-symb (λ i → []ⁱ-resp-≈ⁱ (es i) (⇑ⁱ-resp-≈ⁱ ξ))\n []ⁱ-resp-≈ⁱ (expr-meta M ts) ξ = []ˢ-resp-≈ˢ-≈ ([,]ˢ-resp-≈ˢ ≈ˢ-refl (λ i → []ⁱ-resp-≈ⁱ (ts i) ξ)) (ξ M)\n []ⁱ-resp-≈ⁱ expr-eqty ξ = ≈-eqty\n []ⁱ-resp-≈ⁱ expr-eqtm ξ = ≈-eqtm\n\n\n []ⁱ-resp-≈ⁱ-≈ : ∀ {cl} {𝕂 𝕄} {γ} {I J : 𝕂 →ⁱ 𝕄 ∥ γ} {t u : Expr cl 𝕂 γ} →\n I ≈ⁱ J → t ≈ u → [ I ]ⁱ t ≈ [ J ]ⁱ u\n []ⁱ-resp-≈ⁱ-≈ {J = J} {t = t} ζ ξ = ≈-trans ([]ⁱ-resp-≈ⁱ t ζ) ([]ⁱ-resp-≈ J ξ)\n\n -- composition of instantiations\n\n infixl 7 _∘ⁱ_\n\n _∘ⁱ_ : ∀ {𝕂 𝕃 𝕄} {γ} → 𝕃 →ⁱ 𝕄 ∥ γ → 𝕂 →ⁱ 𝕃 ∥ γ → 𝕂 →ⁱ 𝕄 ∥ γ\n (J ∘ⁱ I) M = [ ⇑ⁱ J ]ⁱ I M\n\n -- composition of a renaming and instantiation\n\n infixr 7 _ʳ∘ⁱ_\n\n _ʳ∘ⁱ_ : ∀ {𝕂 𝕄} {γ δ} → (ρ : γ →ʳ δ) → (I : 𝕂 →ⁱ 𝕄 ∥ γ) → 𝕂 →ⁱ 𝕄 ∥ δ\n (ρ ʳ∘ⁱ I) M = [ ⇑ʳ ρ ]ʳ I M\n\n ⇑ⁱ-resp-ʳ∘ⁱ : ∀ {𝕂 𝕄} {γ δ η} {ρ : γ →ʳ δ} → {I : 𝕂 →ⁱ 𝕄 ∥ γ} →\n ⇑ⁱ {δ = η} (ρ ʳ∘ⁱ I) ≈ⁱ ⇑ʳ ρ ʳ∘ⁱ ⇑ⁱ I\n ⇑ⁱ-resp-ʳ∘ⁱ {I = I} M =\n ≈-trans\n (≈-trans\n (≈-sym ([∘ʳ] (I M)))\n ([]ʳ-resp-≡ʳ (I M) (λ {(var-left x) → refl ; (var-right y) → refl})))\n ([∘ʳ] (I M))\n\n [ʳ∘ⁱ] : ∀ {cl 𝕂 𝕄} {γ δ} {ρ : γ →ʳ δ} {I : 𝕂 →ⁱ 𝕄 ∥ γ} (t : Expr cl 𝕂 γ) →\n [ ρ ]ʳ ([ I ]ⁱ t) ≈ [ ρ ʳ∘ⁱ I ]ⁱ [ ρ ]ʳ t\n [ʳ∘ⁱ] (expr-var x) = ≈-refl\n [ʳ∘ⁱ] {ρ = ρ} {I = I} (expr-symb S es) =\n ≈-symb (λ i → ≈-trans\n ([ʳ∘ⁱ] (es i))\n ([]ⁱ-resp-≈ⁱ\n ([ ⇑ʳ ρ ]ʳ es i)\n (≈ⁱ-sym (⇑ⁱ-resp-ʳ∘ⁱ {I = I}))))\n [ʳ∘ⁱ] {ρ = ρ} {I = I} (expr-meta M ts) =\n ≈-trans\n (≈-sym ([ʳ∘ˢ] (I M)))\n (≈-trans\n ([]ˢ-resp-≈ˢ (λ { (var-left x) → ≈-refl ; (var-right y) → [ʳ∘ⁱ] (ts y)}) (I M))\n ([ˢ∘ʳ] (I M)))\n [ʳ∘ⁱ] expr-eqty = ≈-eqty\n [ʳ∘ⁱ] expr-eqtm = ≈-eqtm\n\n -- composition of an instantiation and substitution\n\n infixr 7 _ⁱ∘ˢ_\n\n _ⁱ∘ˢ_ : ∀ {𝕂 𝕄} {γ δ} (I : 𝕂 →ⁱ 𝕄 ∥ δ) (σ : 𝕂 ∥ γ →ˢ δ) → (𝕄 ∥ γ →ˢ δ)\n (I ⁱ∘ˢ σ) x = [ I ]ⁱ σ x\n\n -- extension respects identity\n\n ⇑ⁱ-resp-𝟙ⁱ : ∀ {𝕄 γ δ} → ⇑ⁱ {δ = δ} 𝟙ⁱ ≈ⁱ 𝟙ⁱ {𝕄 = 𝕄} {γ = γ ⊕ δ}\n ⇑ⁱ-resp-𝟙ⁱ {clᴹ = obj _} M = ≈-refl\n ⇑ⁱ-resp-𝟙ⁱ {clᴹ = EqTy} M = ≈-eqty\n ⇑ⁱ-resp-𝟙ⁱ {clᴹ = EqTm} M = ≈-eqtm\n\n -- extension respects composition\n\n ⇑ⁱ-resp-∘ⁱ : ∀ {𝕂 𝕃 𝕄 γ δ} {I : 𝕂 →ⁱ 𝕃 ∥ γ} {J : 𝕃 →ⁱ 𝕄 ∥ γ} → ⇑ⁱ {δ = δ} (J ∘ⁱ I) ≈ⁱ ⇑ⁱ J ∘ⁱ ⇑ⁱ I\n ⇑ⁱ-resp-∘ⁱ {I = I} {J = J} M =\n ≈-trans\n ([ʳ∘ⁱ] (I M))\n ([]ⁱ-resp-≈ⁱ ([ ⇑ʳ var-left ]ʳ I M)\n λ N → ≈-trans (≈-sym ([∘ʳ] (J N)))\n (≈-trans ([]ʳ-resp-≡ʳ (J N) λ {(var-left x) → refl ; (var-right y) → refl}) ([∘ʳ] (J N))))\n\n ⇑ⁱ-resp-ⁱ∘ˢ : ∀ {𝕂 𝕄} {γ δ η} {I : 𝕂 →ⁱ 𝕄 ∥ δ} {σ : 𝕂 ∥ γ →ˢ δ} →\n ⇑ˢ {η = η} (I ⁱ∘ˢ σ ) ≈ˢ ⇑ⁱ I ⁱ∘ˢ ⇑ˢ σ\n ⇑ⁱ-resp-ⁱ∘ˢ {σ = σ}(var-left x) = ≈-trans ([ʳ∘ⁱ] (σ x)) ([]ⁱ-resp-≈ⁱ ([ var-left ]ʳ σ x) (λ _ → ≈-refl))\n ⇑ⁱ-resp-ⁱ∘ˢ (var-right y) = ≈-refl\n\n\n -- the action of an instantiation on a generic metavariable application\n\n []ⁱ-meta-generic : ∀ {𝕂 𝕄} {γ} {I : 𝕂 →ⁱ 𝕄 ∥ γ} {clᴹ γᴹ} {M : [ clᴹ , γᴹ ]∈ 𝕂} → [ ⇑ⁱ I ]ⁱ (expr-meta-generic {γ = γ} M) ≈ I M\n []ⁱ-meta-generic {I = I} {clᴹ = obj _} {M = M} =\n ≈-trans (≈-sym ([ˢ∘ʳ] (I M))) ([]ˢ-id (λ { (var-left _) → ≈-refl ; (var-right _) → ≈-refl}))\n []ⁱ-meta-generic {clᴹ = EqTy} = ≈-eqty\n []ⁱ-meta-generic {clᴹ = EqTm} = ≈-eqtm\n\n -- action of the identity\n\n [𝟙ⁱ] : ∀ {cl 𝕄 γ} (t : Expr cl 𝕄 γ) → [ 𝟙ⁱ ]ⁱ t ≈ t\n [𝟙ⁱ] (expr-var x) = ≈-refl\n [𝟙ⁱ] (expr-symb S es) = ≈-symb (λ i → ≈-trans ([]ⁱ-resp-≈ⁱ (es i) ⇑ⁱ-resp-𝟙ⁱ) ([𝟙ⁱ] (es i)))\n [𝟙ⁱ] (expr-meta M ts) = ≈-meta (λ i → [𝟙ⁱ] (ts i))\n [𝟙ⁱ] (expr-eqty) = ≈-eqty\n [𝟙ⁱ] (expr-eqtm) = ≈-eqtm\n\n -- interaction of instantiation, substitution and renaming\n\n []ⁱ-[]ˢ : ∀ {cl 𝕂 𝕄 γ δ} {I : 𝕂 →ⁱ 𝕄 ∥ δ} {σ : 𝕂 ∥ γ →ˢ δ} {ρ : δ →ʳ γ} (t : Expr cl 𝕂 γ) →\n σ ˢ∘ʳ ρ ≈ˢ 𝟙ˢ → ([ I ]ⁱ ([ σ ]ˢ t)) ≈ ([ I ⁱ∘ˢ σ ]ˢ [ ρ ʳ∘ⁱ I ]ⁱ t)\n []ⁱ-[]ˢ (expr-var x) ξ = ≈-refl\n []ⁱ-[]ˢ {I = I} {σ = σ} {ρ = ρ} (expr-symb S es) ξ =\n ≈-symb (λ i →\n ≈-trans\n ([]ⁱ-[]ˢ {ρ = ⇑ʳ ρ} (es i)\n λ where\n (var-left x) → []ʳ-resp-≈ var-left (ξ x)\n (var-right x) → ≈-refl)\n (≈-sym ([]ˢ-resp-≈ˢ-≈ (⇑ⁱ-resp-ⁱ∘ˢ) (([]ⁱ-resp-≈ⁱ (es i) (⇑ⁱ-resp-ʳ∘ⁱ {I = I}))))))\n []ⁱ-[]ˢ {I = I} {σ = σ} (expr-meta M ts) ξ =\n ≈-trans\n (≈-trans\n ([]ˢ-resp-≈ˢ (λ where\n (var-left x) → ≈-sym ([]ⁱ-resp-≈ I (ξ x))\n (var-right x) → []ⁱ-[]ˢ (ts x) ξ)\n (I M))\n ([∘ˢ] (I M)))\n (≈-sym ([]ˢ-resp-≈ (I ⁱ∘ˢ σ) (≈-sym ([ˢ∘ʳ] (I M))) ))\n []ⁱ-[]ˢ expr-eqty _ = ≈-eqty\n []ⁱ-[]ˢ expr-eqtm _ = ≈-eqtm\n\n _ˢ∘ⁱ_ : ∀ {𝕂 𝕄 γ δ} → 𝕊 % 𝕄 ∥ γ →ˢ δ → 𝕂 →ⁱ 𝕄 ∥ γ → 𝕂 →ⁱ 𝕄 ∥ δ\n (σ ˢ∘ⁱ I) M = [ ⇑ˢ σ ]ˢ I M\n\n ⇑ⁱ-resp-ˢ∘ⁱ : ∀ {𝕂 𝕄 γ δ η} {σ : 𝕊 % 𝕄 ∥ γ →ˢ δ} {I : 𝕂 →ⁱ 𝕄 ∥ γ} →\n ⇑ⁱ {δ = η} (σ ˢ∘ⁱ I) ≈ⁱ ⇑ˢ σ ˢ∘ⁱ ⇑ⁱ I\n ⇑ⁱ-resp-ˢ∘ⁱ {I = I} M =\n ≈-trans\n (≈-sym ([ʳ∘ˢ] (I M)))\n (≈-trans\n ([]ˢ-resp-≈ˢ (≈ˢ-sym ⇑ˢ-resp-ʳ∘ˢ) (I M))\n (≈-trans\n ([]ˢ-resp-≈ˢ\n (λ { (var-left x) → ≈-refl ; (var-right y) → ≈-refl})\n (I M))\n ([ˢ∘ʳ] (I M))))\n\n []ˢ-[]ⁱ : ∀ {cl 𝕂 𝕄 γ δ η} {I : 𝕂 →ⁱ 𝕄 ∥ γ} {σ : 𝕊 % 𝕄 ∥ γ →ˢ δ} {ρ : η →ʳ δ} {τ : η →ʳ γ} (t : Expr cl 𝕂 η) →\n (∀ x → σ (τ x) ≈ expr-var (ρ x)) → [ σ ]ˢ ([ I ]ⁱ ([ τ ]ʳ t)) ≈ [ σ ˢ∘ⁱ I ]ⁱ ([ ρ ]ʳ t)\n []ˢ-[]ⁱ (expr-var x) ξ = ξ x\n []ˢ-[]ⁱ {I = I} {σ = σ} {ρ = ρ} (expr-symb S es) ξ =\n ≈-symb\n (λ i →\n ≈-trans\n ([]ˢ-[]ⁱ {I = ⇑ⁱ I} {σ = ⇑ˢ σ} {ρ = ⇑ʳ ρ} (es i)\n (λ { (var-left x) → []ʳ-resp-≈ var-left (ξ x)\n ; (var-right x) → ≈-refl}))\n ([]ⁱ-resp-≈ⁱ ([ ⇑ʳ ρ ]ʳ es i) (≈ⁱ-sym (⇑ⁱ-resp-ˢ∘ⁱ {σ = σ} {I = I}))))\n []ˢ-[]ⁱ {I = I} {σ = σ} (expr-meta M ts) ξ =\n ≈-trans\n (≈-sym ([∘ˢ] (I M)))\n (≈-trans\n ([]ˢ-resp-≈ˢ\n (λ { (var-left x) → ≈-trans (≈-sym ([𝟙ˢ] (σ x))) ([ˢ∘ʳ] (σ x))\n ; (var-right j) → []ˢ-[]ⁱ (ts j) ξ}) (I M))\n ([∘ˢ] (I M)))\n []ˢ-[]ⁱ expr-eqty ξ = ≈-eqty\n []ˢ-[]ⁱ expr-eqtm ξ = ≈-eqtm\n\n -- action of composition\n\n [∘ⁱ] : ∀ {cl 𝕂 𝕃 𝕄 γ} {I : 𝕂 →ⁱ 𝕃 ∥ γ} {J : 𝕃 →ⁱ 𝕄 ∥ γ} (t : Expr cl 𝕂 γ) → [ J ∘ⁱ I ]ⁱ t ≈ [ J ]ⁱ [ I ]ⁱ t\n [∘ⁱ] (expr-var _) = ≈-refl\n [∘ⁱ] {I = I} {J = J} (expr-symb S es) =\n ≈-symb (λ i → ≈-trans ([]ⁱ-resp-≈ⁱ (es i) (⇑ⁱ-resp-∘ⁱ {I = I})) ([∘ⁱ] (es i)))\n [∘ⁱ] {I = I} {J = J} (expr-meta M ts) =\n ≈-sym (≈-trans\n ([]ⁱ-[]ˢ {I = J} {ρ = var-left} (I M) λ _ → ≈-refl)\n ([]ˢ-resp-≈ˢ\n (λ { (var-left x) → ≈-refl ; (var-right x) → ≈-sym ([∘ⁱ] (ts x))})\n ([ ⇑ⁱ J ]ⁱ (I M))))\n [∘ⁱ] expr-eqty = ≈-eqty\n [∘ⁱ] expr-eqtm = ≈-eqtm\n\n -- Notation for working with multiple signatures\n\n infix 5 _%_→ⁱ_∥_\n _%_→ⁱ_∥_ : ∀ (𝕊 : Signature) → MShape → MShape → VShape → Set\n _%_→ⁱ_∥_ 𝕊 = _→ⁱ_∥_ {𝕊 = 𝕊}\n", "meta": {"hexsha": "3b3ec17f5423c024b13824bbf52e6f85576acc54", "size": 9289, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Instantiation.agda", "max_stars_repo_name": "andrejbauer/dependent-type-theory-syntax", "max_stars_repo_head_hexsha": "9b634d284a0ec5108c68489575194cd573f38908", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-05-25T11:14:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-14T01:48:00.000Z", "max_issues_repo_path": "src/Instantiation.agda", "max_issues_repo_name": "andrejbauer/dependent-type-theory-syntax", "max_issues_repo_head_hexsha": "9b634d284a0ec5108c68489575194cd573f38908", "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/Instantiation.agda", "max_forks_repo_name": "andrejbauer/dependent-type-theory-syntax", "max_forks_repo_head_hexsha": "9b634d284a0ec5108c68489575194cd573f38908", "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": 36.1439688716, "max_line_length": 130, "alphanum_fraction": 0.3972440521, "num_tokens": 5453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.668880247169804, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.3657023502366304}} {"text": "{-# OPTIONS --allow-unsolved-metas #-} \nopen import Level\nopen import Ordinals\nmodule OD {n : Level } (O : Ordinals {n} ) where\n\nopen import zf\nopen import Data.Nat renaming ( zero to Zero ; suc to Suc ; ℕ to Nat ; _⊔_ to _n⊔_ ) \nopen import Relation.Binary.PropositionalEquality hiding ( [_] )\nopen import Data.Nat.Properties \nopen import Data.Empty\nopen import Relation.Nullary\nopen import Relation.Binary hiding (_⇔_)\nopen import Relation.Binary.Core hiding (_⇔_)\n\nopen import logic\nimport OrdUtil\nopen import nat\n\nopen Ordinals.Ordinals O\nopen Ordinals.IsOrdinals isOrdinal \nopen Ordinals.IsNext isNext \nopen OrdUtil O\n\n-- Ordinal Definable Set\n\nrecord OD : Set (suc n ) where\n field\n def : (x : Ordinal ) → Set n\n\nopen OD\n\nopen _∧_\nopen _∨_\nopen Bool\n\nrecord _==_ ( a b : OD ) : Set n where\n field\n eq→ : ∀ { x : Ordinal } → def a x → def b x \n eq← : ∀ { x : Ordinal } → def b x → def a x \n\n==-refl : { x : OD } → x == x\n==-refl {x} = record { eq→ = λ x → x ; eq← = λ x → x }\n\nopen _==_ \n\n==-trans : { x y z : OD } → x == y → y == z → x == z\n==-trans x=y y=z = record { eq→ = λ {m} t → eq→ y=z (eq→ x=y t) ; eq← = λ {m} t → eq← x=y (eq← y=z t) }\n\n==-sym : { x y : OD } → x == y → y == x \n==-sym x=y = record { eq→ = λ {m} t → eq← x=y t ; eq← = λ {m} t → eq→ x=y t }\n\n\n⇔→== : { x y : OD } → ( {z : Ordinal } → (def x z ⇔ def y z)) → x == y \neq→ ( ⇔→== {x} {y} eq ) {z} m = proj1 eq m \neq← ( ⇔→== {x} {y} eq ) {z} m = proj2 eq m \n\n-- next assumptions are our axiom\n--\n-- OD is an equation on Ordinals, so it contains Ordinals. If these Ordinals have one-to-one\n-- correspondence to the OD then the OD looks like a ZF Set.\n--\n-- If all ZF Set have supreme upper bound, the solutions of OD have to be bounded, i.e.\n-- bbounded ODs are ZF Set. Unbounded ODs are classes.\n--\n-- In classical Set Theory, HOD is used, as a subset of OD, \n-- HOD = { x | TC x ⊆ OD }\n-- where TC x is a transitive clusure of x, i.e. Union of all elemnts of all subset of x.\n-- This is not possible because we don't have V yet. So we assumes HODs are bounded OD.\n--\n-- We also assumes HODs are isomorphic to Ordinals, which is ususally proved by Goedel number tricks.\n-- There two contraints on the HOD order, one is ∋, the other one is ⊂.\n-- ODs have an ovbious maximum, but Ordinals are not, but HOD has no maximum because there is an aribtrary\n-- bound on each HOD.\n--\n-- In classical Set Theory, sup is defined by Uion, since we are working on constructive logic,\n-- we need explict assumption on sup.\n--\n-- ==→o≡ is necessary to prove axiom of extensionality.\n\n-- Ordinals in OD , the maximum\nOrds : OD\nOrds = record { def = λ x → One }\n\nrecord HOD : Set (suc n) where\n field\n od : OD\n odmax : Ordinal\n <-osuc (sup-o< next-ord (sup-o next-ord)) where\n next-ord : Ordinal → Ordinal\n next-ord x = osuc x\n\n-- Ordinal in OD ( and ZFSet ) Transitive Set\nOrd : ( a : Ordinal ) → HOD \nOrd a = record { od = record { def = λ y → y o< a } ; odmax = a ; ¬a ¬b c = no ¬b\n\n-- the pair\n_,_ : HOD → HOD → HOD \nx , y = record { od = record { def = λ t → (t ≡ & x ) ∨ ( t ≡ & y ) } ; odmax = omax (& x) (& y) ; ¬a ¬b c =\n ⊥-elim ( o<> (⊆→o≤ {x , x} {y} y⊆x,x ) lemma1 ) where\n lemma : {z : Ordinal} → (z ≡ & x) ∨ (z ≡ & x) → & x ≡ z\n lemma (case1 refl) = refl\n lemma (case2 refl) = refl\n y⊆x,x : {z : Ordinal} → def (od (x , x)) z → def (od y) z\n y⊆x,x {z} lt = subst (λ k → def (od y) k ) (lemma lt) y∋x \n lemma1 : osuc (& y) o< & (x , x)\n lemma1 = subst (λ k → osuc (& y) o< k ) (sym (peq {x})) (osucc c ) \n\nε-induction : { ψ : HOD → Set (suc n)}\n → ( {x : HOD } → ({ y : HOD } → x ∋ y → ψ y ) → ψ x )\n → (x : HOD ) → ψ x\nε-induction {ψ} ind x = subst (λ k → ψ k ) *iso (ε-induction-ord (osuc (& x)) <-osuc ) where\n induction : (ox : Ordinal) → ((oy : Ordinal) → oy o< ox → ψ (* oy)) → ψ (* ox)\n induction ox prev = ind ( λ {y} lt → subst (λ k → ψ k ) *iso (prev (& y) (o<-subst (c<→o< lt) refl &iso ))) \n ε-induction-ord : (ox : Ordinal) { oy : Ordinal } → oy o< ox → ψ (* oy)\n ε-induction-ord ox {oy} lt = TransFinite {λ oy → ψ (* oy)} induction oy\n\nSelect : (X : HOD ) → ((x : HOD ) → Set n ) → HOD \nSelect X ψ = record { od = record { def = λ x → ( odef X x ∧ ψ ( * x )) } ; odmax = odmax X ; u ¬a ¬b c = ⊥-elim (not c)\n_∈_ : ( A B : HOD ) → Set n\nA ∈ B = B ∋ A\n\nOPwr : (A : HOD ) → HOD \nOPwr A = Ord ( sup-o (Ord (osuc (& A))) ( λ x A∋x → & ( A ∩ (* x)) ) ) \n\nPower : HOD → HOD \nPower A = Replace (OPwr (Ord (& A))) ( λ x → A ∩ x )\n-- {_} : ZFSet → ZFSet\n-- { x } = ( x , x ) -- better to use (x , x) directly\n\nunion→ : (X z u : HOD) → (X ∋ u) ∧ (u ∋ z) → Union X ∋ z\nunion→ X z u xx not = ⊥-elim ( not (& u) ( ⟪ proj1 xx\n , subst ( λ k → odef k (& z)) (sym *iso) (proj2 xx) ⟫ ))\nunion← : (X z : HOD) (X∋z : Union X ∋ z) → ¬ ( (u : HOD ) → ¬ ((X ∋ u) ∧ (u ∋ z )))\nunion← X z UX∋z = FExists _ lemma UX∋z where\n lemma : {y : Ordinal} → odef X y ∧ odef (* y) (& z) → ¬ ((u : HOD) → ¬ (X ∋ u) ∧ (u ∋ z))\n lemma {y} xx not = not (* y) ⟪ d→∋ X (proj1 xx) , proj2 xx ⟫\n\ndata infinite-d : ( x : Ordinal ) → Set n where\n iφ : infinite-d o∅\n isuc : {x : Ordinal } → infinite-d x →\n infinite-d (& ( Union (* x , (* x , * x ) ) ))\n\n-- ω can be diverged in our case, since we have no restriction on the corresponding ordinal of a pair.\n-- We simply assumes infinite-d y has a maximum.\n-- \n-- This means that many of OD may not be HODs because of the & mapping divergence.\n-- We should have some axioms to prevent this such as & x o< next (odmax x).\n-- \n-- postulate\n-- ωmax : Ordinal\n-- <ωmax : {y : Ordinal} → infinite-d y → y o< ωmax\n-- \n-- infinite : HOD \n-- infinite = record { od = record { def = λ x → infinite-d x } ; odmax = ωmax ; ¬a ¬b c with (incl lt) (o<-subst c (sym &iso) refl )\n... | ttt = ⊥-elim ( o<¬≡ refl (o<-subst ttt &iso refl ))\n\nψiso : {ψ : HOD → Set n} {x y : HOD } → ψ x → x ≡ y → ψ y\nψiso {ψ} t refl = t\nselection : {ψ : HOD → Set n} {X y : HOD} → ((X ∋ y) ∧ ψ y) ⇔ (Select X ψ ∋ y)\nselection {ψ} {X} {y} = ⟪\n ( λ cond → ⟪ proj1 cond , ψiso {ψ} (proj2 cond) (sym *iso) ⟫ )\n , ( λ select → ⟪ proj1 select , ψiso {ψ} (proj2 select) *iso ⟫ )\n ⟫\n\nselection-in-domain : {ψ : HOD → Set n} {X y : HOD} → Select X ψ ∋ y → X ∋ y \nselection-in-domain {ψ} {X} {y} lt = proj1 ((proj2 (selection {ψ} {X} )) lt)\n\nsup-c< : (ψ : HOD → HOD) → {X x : HOD} → X ∋ x → & (ψ x) o< (sup-o X (λ y X∋y → & (ψ (* y))))\nsup-c< ψ {X} {x} lt = subst (λ k → & (ψ k) o< _ ) *iso (sup-o< X lt )\nreplacement← : {ψ : HOD → HOD} (X x : HOD) → X ∋ x → Replace X ψ ∋ ψ x\nreplacement← {ψ} X x lt = ⟪ sup-c< ψ {X} {x} lt , lemma ⟫ where \n lemma : def (in-codomain X ψ) (& (ψ x))\n lemma not = ⊥-elim ( not ( & x ) ⟪ lt , cong (λ k → & (ψ k)) (sym *iso)⟫ )\nreplacement→ : {ψ : HOD → HOD} (X x : HOD) → (lt : Replace X ψ ∋ x) → ¬ ( (y : HOD) → ¬ (x =h= ψ y))\nreplacement→ {ψ} X x lt = contra-position lemma (lemma2 (proj2 lt)) where\n lemma2 : ¬ ((y : Ordinal) → ¬ odef X y ∧ ((& x) ≡ & (ψ (* y))))\n → ¬ ((y : Ordinal) → ¬ odef X y ∧ (* (& x) =h= ψ (* y)))\n lemma2 not not2 = not ( λ y d → not2 y ⟪ proj1 d , lemma3 (proj2 d)⟫) where\n lemma3 : {y : Ordinal } → (& x ≡ & (ψ (* y))) → (* (& x) =h= ψ (* y)) \n lemma3 {y} eq = subst (λ k → * (& x) =h= k ) *iso (o≡→== eq )\n lemma : ( (y : HOD) → ¬ (x =h= ψ y)) → ( (y : Ordinal) → ¬ odef X y ∧ (* (& x) =h= ψ (* y)) )\n lemma not y not2 = not (* y) (subst (λ k → k =h= ψ (* y)) *iso ( proj2 not2 ))\n\n---\n--- Power Set\n---\n--- First consider ordinals in HOD\n---\n--- A ∩ x = record { def = λ y → odef A y ∧ odef x y } subset of A\n--\n--\n∩-≡ : { a b : HOD } → ({x : HOD } → (a ∋ x → b ∋ x)) → a =h= ( b ∩ a )\n∩-≡ {a} {b} inc = record {\n eq→ = λ {x} x Set)\n (C : (i : I) -> rArgs (ε γ) U i -> Set)\n (a' : Args γ U) ->\n let a = g→rArgs γ U a'\n i = index γ U a' in\n (h : C (index γ U (r→gArgs γ U i a))\n\t (g→rArgs γ U (r→gArgs γ U i a))\n ) -> r←→gArgs-subst γ U C i a h ≡ h\nr←→gArgs-subst-identity (ι i)\t U C _ h = refl-≡\nr←→gArgs-subst-identity (σ A γ)\t U C arg h = r←→gArgs-subst-identity (γ (π₀ arg)) U C' (π₁ arg) h\n where C' = \\i c -> C i (π₀ arg , c)\nr←→gArgs-subst-identity (δ H i γ) U C arg h = r←→gArgs-subst-identity γ U C' (π₁ arg) h\n where C' = \\i c -> C i (π₀ arg , c)\n\n", "meta": {"hexsha": "79bd755db2a5e4d0a40ba0e05e47ae6e3452eb6f", "size": 844, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "examples/outdated-and-incorrect/iird/Test.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": "examples/outdated-and-incorrect/iird/Test.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": "examples/outdated-and-incorrect/iird/Test.agda", "max_forks_repo_name": "masondesu/agda", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "avg_line_length": 33.76, "max_line_length": 98, "alphanum_fraction": 0.5817535545, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7310585669110202, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3655292834555101}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Substitution.Weakening {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped\nopen import Definition.Untyped.Properties\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.Irrelevance\nopen import Definition.LogicalRelation.Substitution\n\nopen import Tools.Product\nimport Tools.PropositionalEquality as PE\n\n\n-- Weakening of valid types by one.\nwk1ᵛ : ∀ {A F Γ l}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])\n → Γ ⊩ᵛ⟨ l ⟩ A / [Γ]\n → Γ ∙ F ⊩ᵛ⟨ l ⟩ wk1 A / (VPack _ _ (V∙ [Γ] [F]))\nwk1ᵛ {A} [Γ] [F] [A] ⊢Δ [σ] =\n let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ]))\n [σA]′ = irrelevance′ (PE.sym (subst-wk A)) [σA]\n in [σA]′\n , (λ [σ′] [σ≡σ′] →\n irrelevanceEq″ (PE.sym (subst-wk A))\n (PE.sym (subst-wk A))\n [σA] [σA]′\n (proj₂ ([A] ⊢Δ (proj₁ [σ])) (proj₁ [σ′]) (proj₁ [σ≡σ′])))\n\n-- Weakening of valid type equality by one.\nwk1Eqᵛ : ∀ {A B F Γ l}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])\n ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ])\n ([A≡B] : Γ ⊩ᵛ⟨ l ⟩ A ≡ B / [Γ] / [A])\n → Γ ∙ F ⊩ᵛ⟨ l ⟩ wk1 A ≡ wk1 B / (VPack _ _ (V∙ [Γ] [F])) / wk1ᵛ {A} {F} [Γ] [F] [A]\nwk1Eqᵛ {A} {B} [Γ] [F] [A] [A≡B] ⊢Δ [σ] =\n let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ]))\n [σA]′ = irrelevance′ (PE.sym (subst-wk A)) [σA]\n in irrelevanceEq″ (PE.sym (subst-wk A))\n (PE.sym (subst-wk B))\n [σA] [σA]′\n ([A≡B] ⊢Δ (proj₁ [σ]))\n", "meta": {"hexsha": "cdab625c87b79e61f47a7a3c7514a4bea954f486", "size": 1622, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Weakening.agda", "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Substitution/Weakening.agda", "max_issues_repo_name": "loic-p/logrel-mltt", "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Substitution/Weakening.agda", "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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": 33.7916666667, "max_line_length": 90, "alphanum_fraction": 0.4963008631, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6926419958239132, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.36524156918455053}} {"text": "\nopen import SOAS.Metatheory.Syntax\n\n-- Metasubstitution operation\nmodule SOAS.Metatheory.SecondOrder.Metasubstitution {T : Set}(Syn : Syntax {T}) where\n\nopen Syntax Syn\n\nopen import SOAS.Metatheory.FreeMonoid Syn\n\nopen import SOAS.Common\nopen import SOAS.Families.Core {T}\nopen import SOAS.Families.Build\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.Construction.Structure as Structure\nopen import SOAS.ContextMaps.Combinators\nopen import SOAS.ContextMaps.CategoryOfRenamings\n\nopen import SOAS.Abstract.Hom\nopen import SOAS.Abstract.ExpStrength\nimport SOAS.Abstract.Coalgebra as →□\nopen →□.Sorted\nimport SOAS.Abstract.Box as □ ; open □.Sorted\n\nopen import Categories.Monad\n\nopen import SOAS.Coalgebraic.Monoid\n\nopen import SOAS.Metatheory Syn\n\nprivate\n variable\n Γ Δ Π : Ctx\n α β τ : T\n 𝔛 𝔜 ℨ : Familyₛ\n 𝔐 𝔑 : MCtx\n\nopen Theory\n\n-- Ground metasubstitution from the monad structure\nmsub₀ : (𝔛 ⇾̣ 𝕋 𝔜) → 𝕋 𝔛 ⇾̣ 𝕋 𝔜\nmsub₀ {𝔛}{𝔜} κ t = μ.η 𝔜 (F.₁ κ t) where open Monad ΣMon:Monad\n\n-- Meta-algebra structure on the exponential [ 𝔛 ⊸ 𝒫 ] ⇨ ℳ\n[_⊸_]⇨_ᵃ : (𝔛 {𝒫}{ℳ} : Familyₛ) → Coalg 𝒫 → ΣMon ℳ → (𝒫 ⇾̣ ℳ)\n → MetaAlg 𝔛 ([ 𝔛 ⊸ 𝒫 ] ⇨ ℳ)\n[_⊸_]⇨_ᵃ 𝔛 {𝒫}{ℳ} 𝒫ᵇ Σℳᵐ ψ = record\n { 𝑎𝑙𝑔 = λ t ζ → ℳ.𝑎𝑙𝑔 (estr [ 𝔛 ⊸ 𝒫ᵇ ]ᵇ ℳ t ζ)\n ; 𝑣𝑎𝑟 = λ v ζ → ℳ.η v\n ; 𝑚𝑣𝑎𝑟 = λ 𝔪 ε ζ → ℳ.μ (ψ (ζ 𝔪)) (copair ℳ (λ x → ε x ζ) ℳ.η)\n } where module ℳ = ΣMon Σℳᵐ\n\n□[_⊸_]⇨_ᵃ : (𝔛 {𝒫}{ℳ} : Familyₛ) → Coalg 𝒫 → ΣMon ℳ → (𝒫 ⇾̣ ℳ)\n → MetaAlg 𝔛 ([ 𝔛 ⊸ 𝒫 ] ➡ ℳ)\n□[ 𝔛 ⊸ 𝒫ᵇ ]⇨ Σℳᵐ ᵃ ψ = □ᵃ 𝔛 ([ 𝔛 ⊸ 𝒫ᵇ ]⇨ Σℳᵐ ᵃ ψ)\n\n-- Derived meta-algebra instance for [ 𝔛 ⊸ 𝕋 𝔜 ] ⇨ 𝕋 𝔜\n⟅_⇨_⟆ᵃ : (𝔛 𝔜 : Familyₛ) → MetaAlg 𝔛 ⟅ 𝔛 ⇨ 𝕋 𝔜 ⟆\n⟅ 𝔛 ⇨ 𝔜 ⟆ᵃ = [ 𝔛 ⊸ 𝕋ᵇ 𝔜 ]⇨ Σ𝕋ᵐ 𝔜 ᵃ id\n\nmodule MS {𝔛 𝔜 : Familyₛ} = Semantics 𝔛 ⟅ 𝔛 ⇨ 𝔜 ⟆ᵃ\nmodule □MS {𝔛 𝔜 : Familyₛ} = □Traversal 𝔛 ⟅ 𝔛 ⇨ 𝔜 ⟆ᵃ\n\n-- Metasubstitution operations\n-- Base\nmsub : 𝕋 𝔛 ⇾̣ ⟅ 𝔛 ⇨ 𝕋 𝔜 ⟆\nmsub = MS.𝕤𝕖𝕞\n-- Parametrised\n□msub : 𝕋 𝔛 ⇾̣ ⟅ 𝔛 ➡ 𝕋 𝔜 ⟆\n□msub = □MS.𝕥𝕣𝕒𝕧\n-- Linear\n○msub : 𝕋 𝔛 ⇾̣ ⟅ 𝔛 ⊸ 𝕋 𝔜 ⟆\n○msub {𝔜 = 𝔜}{Γ = Γ} t ζ = □msub t (inl Γ) λ {_}{Π} 𝔪 → 𝕣𝕖𝕟 𝔜 (ζ 𝔪) (Π ∔∣ inr Γ)\n\n-- Unit parametrisation\n□msub-id : (t : 𝕋 𝔛 α Γ)(κ : [ 𝔛 ⊸ 𝕋 𝔜 ] Γ) → □msub t id κ ≡ msub t κ\n□msub-id {𝔛}{𝔜 = 𝔜} t κ = cong (λ - → - κ) (□𝕥𝕣𝕒𝕧-id≈𝕤𝕖𝕞 𝔛 ⟅ 𝔛 ⇨ 𝔜 ⟆ᵃ)\n\n-- Unit metasubstitution mapping\nms-unit : [ 𝔛 ⊸ 𝕋 𝔛 ] Γ\nms-unit {𝔛}{Δ = Δ} 𝔪 = 𝕞𝕧𝕒𝕣 𝔛 𝔪 (𝕧𝕒𝕣 𝔛 ∘ inl Δ)\n\n-- | Inductive metasubstitution\n\n-- List of terms in an extended (object variable) context mapped to every element of a metavariable context\ndata MSub (Γ : Ctx) : MCtx → MCtx → Set₁ where\n ◦ : MSub Γ ⁅⁆ 𝔑\n _◃_ : (𝔑 ▷ 𝕋) α (Π ∔ Γ) → MSub Γ 𝔐 𝔑 → MSub Γ (⁅ Π ⊩ₙ α ⁆ 𝔐) 𝔑\n\ninfixr 15 _◃_ _▹_\n\n-- Add term to the end of a metasubstitution map\n_▹_ : MSub Γ 𝔐 𝔑 → (𝔑 ▷ 𝕋) τ (Π ∔ Γ) → MSub Γ (𝔐 ⁅ Π ⊩ₙ τ ⁆) 𝔑\n◦ ▹ t = t ◃ ◦\n(s ◃ ζ) ▹ t = s ◃ (ζ ▹ t)\n\n-- Application of a metasubstitution to a metavariable\nix≀ : MSub Γ 𝔐 𝔑 → [ ∥ 𝔐 ∥ ⊸ 𝔑 ▷ 𝕋 ] Γ\nix≀ (t ◃ ζ) ↓ = t\nix≀ (t ◃ ζ) (↑ 𝔪) = ix≀ ζ 𝔪\n\n-- Term corresponding to the topmost distinguished metavariable of an extended mvar context\n_⊩◌ : (Π : Ctx) → (⁅ Π ⊩ₙ β ⁆ 𝔐 ▷ 𝕋) β (Π ∔ Γ)\n_⊩◌ {β}{𝔐} Π = ms-unit ↓\n\n◌ : (⁅ β ⁆ 𝔐 ▷ 𝕋) β Γ\n◌ = ∅ ⊩◌\n\n-- Weakening of metavariable context\nwk≀ : (𝔐 ▷ 𝕋) α Γ → (⁅ Π ⊩ₙ τ ⁆ 𝔐 ▷ 𝕋) α Γ\nwk≀ t = 𝕋₁ ↑_ t\n\n-- Extension of the codomain of a metasubstitution\next≀ : (Π : Ctx)(τ : T) → MSub Γ 𝔐 𝔑 → MSub Γ 𝔐 (⁅ Π ⊩ₙ τ ⁆ 𝔑)\next≀ Π τ ◦ = ◦\next≀ Π τ (t ◃ κ) = wk≀ t ◃ (ext≀ Π τ κ)\n\n-- Lifting of a metasubstitution\nlift≀ : (Π : Ctx)(τ : T) → MSub Γ 𝔐 𝔑 → MSub Γ (⁅ Π ⊩ₙ τ ⁆ 𝔐) (⁅ Π ⊩ₙ τ ⁆ 𝔑)\nlift≀ Π τ κ = (Π ⊩◌) ◃ (ext≀ Π τ κ)\n\n-- Identity metasubstitution\nid≀ : (Γ : Ctx) → MSub Γ 𝔐 𝔐\nid≀ {⁅⁆} Γ = ◦\nid≀ {⁅ Π ⊩ₙ τ ⁆ 𝔐} Γ = lift≀ Π τ (id≀ Γ)\n\n-- Left and right weakening of object context of a metasubstitution\ninl≀ : MSub Γ 𝔐 𝔑 → MSub (Γ ∔ Δ) 𝔐 𝔑\ninl≀ ◦ = ◦\ninl≀ {𝔑 = 𝔑} (_◃_ {Π = Π} t κ) = 𝕣𝕖𝕟 ∥ 𝔑 ∥ t (Π ∔∣ inl _) ◃ (inl≀ κ)\n\ninr≀ : (Γ : Ctx) → MSub Δ 𝔐 𝔑 → MSub (Γ ∔ Δ) 𝔐 𝔑\ninr≀ _ ◦ = ◦\ninr≀ {Δ}{𝔑 = 𝔑} Γ (_◃_ {Π = Π} t κ) = (𝕣𝕖𝕟 ∥ 𝔑 ∥ t (Π ∔∣ inr Γ)) ◃ (inr≀ Γ κ)\n\n-- Application of weakened metasubstitution corresponds to centre weakening\nix-inr≀ : (κ : MSub Δ 𝔐 𝔑)(𝔪 : Π ⊩ τ ∈ 𝔐)\n → ix≀ (inr≀ Γ κ) 𝔪 ≡ (𝕣𝕖𝕟 ∥ 𝔑 ∥ (ix≀ κ 𝔪) (Π ∔∣ inr Γ))\nix-inr≀ (x ◃ κ) ↓ = refl\nix-inr≀ (x ◃ κ) (↑ 𝔪) = ix-inr≀ κ 𝔪\n\n-- Correctness lemmas of weakening, lifting, identity\next≀≈𝕋₁pop : (κ : MSub Γ 𝔐 𝔑)(𝔪 : Π ⊩ τ ∈ 𝔐) → ix≀ (ext≀ Δ β κ) 𝔪 ≡ wk≀ (ix≀ κ 𝔪)\next≀≈𝕋₁pop (x ◃ κ) ↓ = refl\next≀≈𝕋₁pop (x ◃ κ) (↑ 𝔪) = ext≀≈𝕋₁pop κ 𝔪\n\nlift≀≈𝕋₁pop : (κ : MSub Γ 𝔐 𝔑)(𝔪 : Γ ⊩ α ∈ 𝔐) → ix≀ (lift≀ Γ α κ) (↑ 𝔪) ≡ wk≀ (ix≀ κ 𝔪)\nlift≀≈𝕋₁pop (x ◃ κ) ↓ = refl\nlift≀≈𝕋₁pop (x ◃ κ) (↑ 𝔪) = lift≀≈𝕋₁pop κ 𝔪\n\nid≀≈ms-unit : (Γ : Ctx)(𝔪 : Π ⊩ τ ∈ 𝔐) → ix≀ (id≀ Γ) 𝔪 ≡ ms-unit 𝔪\nid≀≈ms-unit {𝔐 = ⁅ Π ⊩ₙ τ ⁆ 𝔐} Γ ↓ = refl\nid≀≈ms-unit {𝔐 = ⁅ Π ⊩ₙ τ ⁆ 𝔐} Γ (↑_ {Δ}{β}{Γ = .Π}{.τ} 𝔪) = begin\n ix≀ (ext≀ Π τ (id≀ Γ)) 𝔪\n ≡⟨ ext≀≈𝕋₁pop (id≀ Γ) 𝔪 ⟩\n wk≀ (ix≀ (id≀ Γ) 𝔪)\n ≡⟨ cong (wk≀) (id≀≈ms-unit Γ 𝔪) ⟩\n wk≀ (ms-unit 𝔪)\n ≡⟨⟩\n wk≀ (𝕞𝕧𝕒𝕣 ∥ 𝔐 ∥ 𝔪 (𝕧𝕒𝕣 ∥ 𝔐 ∥ ∘ ∔.i₁))\n ≡⟨ 𝕋₁∘𝕞𝕧𝕒𝕣[𝕧𝕒𝕣] ↑_ 𝔪 (∔.i₁) ⟩\n 𝕞𝕧𝕒𝕣 ∥ ⁅ Π ⊩ₙ τ ⁆ 𝔐 ∥ (↑ 𝔪) (𝕧𝕒𝕣 ∥ ⁅ Π ⊩ₙ τ ⁆ 𝔐 ∥ ∘ ∔.i₁)\n ∎ where open ≡-Reasoning\n\n-- Inductive metasubstitution operations\n-- Base\nmsub≀ : (𝔐 ▷ 𝕋) α Γ → MSub Γ 𝔐 𝔑 → (𝔑 ▷ 𝕋) α Γ\nmsub≀ t ζ = msub t (ix≀ ζ)\n-- Parametrised\n□msub≀ : (𝔐 ▷ 𝕋) α Γ → (Γ ↝ Δ) → MSub Δ 𝔐 𝔑 → (𝔑 ▷ 𝕋) α Δ\n□msub≀ t ρ ζ = □msub t ρ (ix≀ ζ)\n-- Linear\n○msub≀ : (𝔐 ▷ 𝕋) α Γ → MSub Δ 𝔐 𝔑 → (𝔑 ▷ 𝕋) α (Γ ∔ Δ)\n○msub≀ {Γ = Γ} t ζ = □msub≀ t (inl Γ) (inr≀ Γ ζ)\n\n-- Syntactic sugar for metasubstitution application\n_》 : (𝔑 ▷ 𝕋) α (Π ∔ Γ) → MSub Γ (⁅ Π ⊩ₙ α ⁆̣) 𝔑\nt 》 = t ◃ ◦\n_《_ : (𝔐 ▷ 𝕋) α Γ → MSub Γ 𝔐 𝔑 → (𝔑 ▷ 𝕋) α Γ\n_《_ = msub≀\n\ninfixr 25 _》\ninfix 15 _《_\n\n-- Instantiation of a term extended at the start of the context\ninstₛ : (⁅ Π ⊩ₙ α ⁆ 𝔐 ▷ 𝕋) β Γ → (𝔐 ▷ 𝕋) α (Π ∔ Γ) → (𝔐 ▷ 𝕋) β Γ\ninstₛ {Γ = Γ} h s = msub≀ h (s ◃ id≀ Γ)\n\n-- Instantiation of a term extended at the end of the context\ninstₑ : (𝔐 ⁅ Π ⊩ₙ α ⁆ ▷ 𝕋) β Γ → (𝔐 ▷ 𝕋) α (Π ∔ Γ) → (𝔐 ▷ 𝕋) β Γ\ninstₑ {Γ = Γ} h s = msub≀ h ((id≀ Γ) ▹ s)\n\n-- Instantiation of a term extended twice at the end of the context\ninstₑ₂ : {Π₁ Π₂ : Ctx}{α₁ α₂ : T}\n → ((𝔐 ⁅ Π₁ ⊩ₙ α₁ ⁆) ⁅ Π₂ ⊩ₙ α₂ ⁆ ▷ 𝕋) β Γ\n → (𝔐 ▷ 𝕋) α₁ (Π₁ ∔ Γ) → (𝔐 ▷ 𝕋) α₂ (Π₂ ∔ Γ) → (𝔐 ▷ 𝕋) β Γ\ninstₑ₂ {Γ = Γ} h s t = msub≀ h ((id≀ Γ ▹ s) ▹ t)\n", "meta": {"hexsha": "15373a14fbc8a4538a57a8457a4e40d4eb80829d", "size": 6203, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "SOAS/Metatheory/SecondOrder/Metasubstitution.agda", "max_stars_repo_name": "k4rtik/agda-soas", "max_stars_repo_head_hexsha": "b224d31e20cfd010b7c924ce940f3c2f417777e3", "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": "SOAS/Metatheory/SecondOrder/Metasubstitution.agda", "max_issues_repo_name": "k4rtik/agda-soas", "max_issues_repo_head_hexsha": "b224d31e20cfd010b7c924ce940f3c2f417777e3", "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": "SOAS/Metatheory/SecondOrder/Metasubstitution.agda", "max_forks_repo_name": "k4rtik/agda-soas", "max_forks_repo_head_hexsha": "b224d31e20cfd010b7c924ce940f3c2f417777e3", "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": 31.1708542714, "max_line_length": 107, "alphanum_fraction": 0.5361921651, "num_tokens": 4013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.36509119793965245}} {"text": "-- Laws for weakenings and substitutions.\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Definition.Untyped.Properties where\n\nopen import Definition.Untyped\n\nopen import Tools.Fin\nopen import Tools.Nat\nopen import Tools.List\nopen import Tools.PropositionalEquality hiding (subst)\n\nprivate\n variable\n ℓ m n : Nat\n ρ ρ′ : Wk m n\n η : Wk n ℓ\n σ σ′ : Subst m n\n\n-- Weakening properties\n\n-- Two weakenings ρ and ρ′ are extensionally equal if they agree on\n-- all arguments when interpreted as functions mapping variables to\n-- variables. Formally, they are considered equal iff\n--\n-- (∀ x → wkVar ρ x ≡ wkVar ρ′ x)\n--\n-- Intensional (propositional) equality would be too fine. For\n-- instance,\n--\n-- lift id : Γ∙A ≤ Γ∙A\n--\n-- is extensionally equal to\n--\n-- id : Γ∙A ≤ Γ∙A\n--\n-- but syntactically different.\n\n-- \"lift\" preserves equality of weakenings. Or:\n-- If two weakenings are equal under wkVar, then they are equal when lifted.\n\nwkVar-lift : (∀ x → wkVar ρ x ≡ wkVar ρ′ x)\n → (∀ x → wkVar (lift ρ) x ≡ wkVar (lift ρ′) x)\n\nwkVar-lift eq x0 = refl\nwkVar-lift eq (x +1) = cong _+1 (eq x)\n\n\nwkVar-lifts : (∀ x → wkVar ρ x ≡ wkVar ρ′ x)\n → (∀ n x → wkVar (liftn ρ n) x ≡ wkVar (liftn ρ′ n) x)\nwkVar-lifts eq 0 x = eq x\nwkVar-lifts eq (1+ n) x = wkVar-lift (wkVar-lifts eq n) x\n\n-- Extensionally equal weakenings, if applied to a term,\n-- yield the same weakened term. Or:\n-- If two weakenings are equal under wkVar, then they are equal under wk.\n\nmutual\n wkVar-to-wk : (∀ x → wkVar ρ x ≡ wkVar ρ′ x)\n → ∀ t → wk ρ t ≡ wk ρ′ t\n wkVar-to-wk eq (var x) = cong var (eq x)\n wkVar-to-wk eq (gen k c) = cong (gen k) (wkVar-to-wkGen eq c)\n\n wkVar-to-wkGen : (∀ x → wkVar ρ x ≡ wkVar ρ′ x)\n → ∀ {bs} c → wkGen {bs = bs} ρ c ≡ wkGen {bs = bs} ρ′ c\n wkVar-to-wkGen eq [] = refl\n wkVar-to-wkGen eq (_∷_ {b = b} t ts) =\n cong₂ _∷_ (wkVar-to-wk (wkVar-lifts eq b) t) (wkVar-to-wkGen eq ts)\n\n\n-- lift id is extensionally equal to id.\n\nwkVar-lift-id : (x : Fin (1+ n)) → wkVar (lift id) x ≡ wkVar id x\nwkVar-lift-id x0 = refl\nwkVar-lift-id (x +1) = refl\n\nwkVar-lifts-id : (n : Nat) (x : Fin (n + m)) → wkVar (liftn id n) x ≡ wkVar id x\nwkVar-lifts-id 0 x = refl\nwkVar-lifts-id (1+ n) x0 = refl\nwkVar-lifts-id (1+ n) (x +1) = cong _+1 (wkVar-lifts-id n x)\n\n-- id is the identity renaming.\n\nwkVar-id : (x : Fin n) → wkVar id x ≡ x\nwkVar-id x = refl\n\nmutual\n wk-id : (t : Term n) → wk id t ≡ t\n wk-id (var x) = refl\n wk-id (gen k ts) = cong (gen k) (wkGen-id ts)\n\n wkGen-id : ∀ {bs} x → wkGen {n} {n} {bs} id x ≡ x\n wkGen-id [] = refl\n wkGen-id (_∷_ {b = b} t ts) =\n cong₂ _∷_ (trans (wkVar-to-wk (wkVar-lifts-id b) t) ( wk-id t)) (wkGen-id ts)\n\n-- lift id is also the identity renaming.\n\nwk-lift-id : (t : Term (1+ n)) → wk (lift id) t ≡ t\nwk-lift-id t = trans (wkVar-to-wk wkVar-lift-id t) (wk-id t)\n\n-- The composition of weakenings is correct...\n--\n-- ...as action on variables.\n\nwkVar-comp : (ρ : Wk m ℓ) (ρ′ : Wk ℓ n) (x : Fin n) → wkVar ρ (wkVar ρ′ x) ≡ wkVar (ρ • ρ′) x\nwkVar-comp id ρ′ x = refl\nwkVar-comp (step ρ) ρ′ x = cong _+1 (wkVar-comp ρ ρ′ x)\nwkVar-comp (lift ρ) id x = refl\nwkVar-comp (lift ρ) (step ρ′) x = cong _+1 (wkVar-comp ρ ρ′ x)\nwkVar-comp (lift ρ) (lift ρ′) x0 = refl\nwkVar-comp (lift ρ) (lift ρ′) (x +1) = cong _+1 (wkVar-comp ρ ρ′ x)\n\nwkVar-comps : ∀ k → (ρ : Wk m ℓ) (ρ′ : Wk ℓ n) (x : Fin (k + n))\n → wkVar (liftn ρ k • liftn ρ′ k) x\n ≡ wkVar (liftn (ρ • ρ′) k) x\nwkVar-comps 0 ρ ρ′ x = refl\nwkVar-comps (1+ n) ρ ρ′ x0 = refl\nwkVar-comps (1+ n) ρ ρ′ (x +1) = cong _+1 (wkVar-comps n ρ ρ′ x)\n\n-- ... as action on terms.\n\nmutual\n wk-comp : (ρ : Wk m ℓ) (ρ′ : Wk ℓ n) (t : Term n) → wk ρ (wk ρ′ t) ≡ wk (ρ • ρ′) t\n wk-comp ρ ρ′ (var x) = cong var (wkVar-comp ρ ρ′ x)\n wk-comp ρ ρ′ (gen k ts) = cong (gen k) (wkGen-comp ρ ρ′ ts)\n\n wkGen-comp : (ρ : Wk m ℓ) (ρ′ : Wk ℓ n) → ∀ {bs} g\n → wkGen ρ (wkGen ρ′ g) ≡ wkGen {bs = bs} (ρ • ρ′) g\n wkGen-comp ρ ρ′ [] = refl\n wkGen-comp ρ ρ′ (_∷_ {b = b} t ts) =\n cong₂ _∷_ (trans (wk-comp (liftn ρ b) (liftn ρ′ b) t)\n (wkVar-to-wk (wkVar-comps b ρ ρ′) t))\n (wkGen-comp ρ ρ′ ts)\n\n\n-- The following lemmata are variations on the equality\n--\n-- wk1 ∘ ρ = lift ρ ∘ wk1.\n--\n-- Typing: Γ∙A ≤ Γ ≤ Δ <==> Γ∙A ≤ Δ∙A ≤ Δ.\n\nlift-step-comp : (ρ : Wk m n) → step id • ρ ≡ lift ρ • step id\nlift-step-comp id = refl\nlift-step-comp (step ρ) = cong step (lift-step-comp ρ)\nlift-step-comp (lift ρ) = refl\n\nwk1-wk : (ρ : Wk m n) (t : Term n) → wk1 (wk ρ t) ≡ wk (step ρ) t\nwk1-wk ρ t = wk-comp (step id) ρ t\n\nlift-wk1 : (ρ : Wk m n) (t : Term n) → wk (lift ρ) (wk1 t) ≡ wk (step ρ) t\nlift-wk1 pr A = trans (wk-comp (lift pr) (step id) A)\n (sym (cong (λ x → wk x A) (lift-step-comp pr)))\n\nwk1-wk≡lift-wk1 : (ρ : Wk m n) (t : Term n) → wk1 (wk ρ t) ≡ wk (lift ρ) (wk1 t)\nwk1-wk≡lift-wk1 ρ t = trans (wk1-wk ρ t) (sym (lift-wk1 ρ t))\n\n-- Substitution properties.\n\n-- Two substitutions σ and σ′ are equal if they are pointwise equal,\n-- i.e., agree on all variables.\n--\n-- ∀ x → σ x ≡ σ′ x\n\n-- If σ = σ′ then lift σ = lift σ′.\n\nsubstVar-lift : (∀ x → σ x ≡ σ′ x) → ∀ x → liftSubst σ x ≡ liftSubst σ′ x\n\nsubstVar-lift eq x0 = refl\nsubstVar-lift eq (x +1) = cong wk1 (eq x)\n\nsubstVar-lifts : (∀ x → σ x ≡ σ′ x) → ∀ n x → liftSubstn σ n x ≡ liftSubstn σ′ n x\n\nsubstVar-lifts eq 0 x = eq x\nsubstVar-lifts eq (1+ n) x0 = refl\nsubstVar-lifts eq (1+ n) (x +1) = cong wk1 (substVar-lifts eq n x)\n\n-- If σ = σ′ then subst σ t = subst σ′ t.\n\nmutual\n substVar-to-subst : ((x : Fin n) → σ x ≡ σ′ x)\n → (t : Term n) → subst σ t ≡ subst σ′ t\n substVar-to-subst eq (var x) = eq x\n substVar-to-subst eq (gen k ts) = cong (gen k) (substVar-to-substGen eq ts)\n\n substVar-to-substGen : ∀ {bs} → ((x : Fin n) → σ x ≡ σ′ x)\n → ∀ g → substGen {bs = bs} σ g ≡ substGen {bs = bs} σ′ g\n substVar-to-substGen eq [] = refl\n substVar-to-substGen eq (_∷_ {b = b} t ts) =\n cong₂ _∷_ (substVar-to-subst (substVar-lifts eq b) t)\n (substVar-to-substGen eq ts)\n\n\n-- lift id = id (as substitutions)\n\nsubst-lift-id : (x : Fin (1+ n)) → (liftSubst idSubst) x ≡ idSubst x\nsubst-lift-id x0 = refl\nsubst-lift-id (x +1) = refl\n\nsubst-lifts-id : (n : Nat) → (x : Fin (n + m)) → (liftSubstn idSubst n) x ≡ idSubst x\nsubst-lifts-id 0 x = refl\nsubst-lifts-id (1+ n) x0 = refl\nsubst-lifts-id (1+ n) (x +1) = cong wk1 (subst-lifts-id n x)\n\n-- Identity substitution.\n\nmutual\n subst-id : (t : Term n) → subst idSubst t ≡ t\n subst-id (var x) = refl\n subst-id (gen k ts) = cong (gen k) (substGen-id ts)\n\n substGen-id : ∀ {bs} g → substGen {n} {n} {bs} idSubst g ≡ g\n substGen-id [] = refl\n substGen-id (_∷_ {b = b} t ts) =\n cong₂ _∷_ (trans (substVar-to-subst (subst-lifts-id b) t )\n (subst-id t))\n (substGen-id ts)\n\n\n-- Correctness of composition of weakening and substitution.\n\n-- Composition of liftings is lifting of the composition.\n-- lift ρ •ₛ lift σ = lift (ρ •ₛ σ)\n\nsubst-lift-•ₛ : ∀ t\n → subst (lift ρ •ₛ liftSubst σ) t\n ≡ subst (liftSubst (ρ •ₛ σ)) t\nsubst-lift-•ₛ =\n substVar-to-subst (λ { x0 → refl ; (x +1) → sym (wk1-wk≡lift-wk1 _ _)})\n\nhelper1 : (n : Nat) (x : Fin (1+ n + m)) →\n (lift (liftn ρ n) •ₛ liftSubst (liftSubstn σ n)) x ≡\n liftSubst (liftSubstn (ρ •ₛ σ) n) x\nhelper1 0 x0 = refl\nhelper1 0 (x +1) = sym (wk1-wk≡lift-wk1 _ _)\nhelper1 (1+ n) x0 = refl\nhelper1 (1+ n) (x +1) = trans (sym (wk1-wk≡lift-wk1 _ _)) (cong wk1 (helper1 n x))\n\nsubst-lifts-•ₛ : ∀ n t\n → subst (liftn ρ n •ₛ liftSubstn σ n) t\n ≡ subst (liftSubstn (ρ •ₛ σ) n) t\nsubst-lifts-•ₛ 0 t = refl\nsubst-lifts-•ₛ (1+ n) t = substVar-to-subst (helper1 n) t\n\n-- lift σ ₛ• lift ρ = lift (σ ₛ• ρ)\n\nsubst-lift-ₛ• : ∀ t\n → subst (liftSubst σ ₛ• lift ρ) t\n ≡ subst (liftSubst (σ ₛ• ρ)) t\nsubst-lift-ₛ• = substVar-to-subst (λ { x0 → refl ; (x +1) → refl})\n\nhelper2 : (n : Nat) → (x : Fin (1+ n + m))\n → liftSubst (liftSubstn σ n) (wkVar (lift (liftn ρ n)) x) ≡\n liftSubst (liftSubstn (λ x₁ → σ (wkVar ρ x₁)) n) x\nhelper2 0 x0 = refl\nhelper2 0 (x +1) = refl\nhelper2 (1+ n) x0 = refl\nhelper2 (1+ n) (x +1) = cong wk1 (helper2 n x)\n\nsubst-lifts-ₛ• : ∀ n t\n → subst (liftSubstn σ n ₛ• liftn ρ n) t\n ≡ subst (liftSubstn (σ ₛ• ρ) n) t\nsubst-lifts-ₛ• 0 t = refl\nsubst-lifts-ₛ• (1+ n) t = substVar-to-subst (helper2 n) t\n\n-- wk ρ ∘ subst σ = subst (ρ •ₛ σ)\n\nmutual\n wk-subst : ∀ t → wk ρ (subst σ t) ≡ subst (ρ •ₛ σ) t\n wk-subst (var x) = refl\n wk-subst (gen k ts) = cong (gen k) (wkGen-substGen ts)\n\n wkGen-substGen : ∀ {bs} t → wkGen ρ (substGen σ t) ≡ substGen {bs = bs} (ρ •ₛ σ) t\n wkGen-substGen [] = refl\n wkGen-substGen (_∷_ {b = b} t ts) =\n cong₂ _∷_ (trans (wk-subst t) ( subst-lifts-•ₛ b t)) (wkGen-substGen ts)\n\n\n-- subst σ ∘ wk ρ = subst (σ •ₛ ρ)\n\nmutual\n subst-wk : ∀ t → subst σ (wk ρ t) ≡ subst (σ ₛ• ρ) t\n subst-wk (var x) = refl\n subst-wk (gen k ts) = cong (gen k) (substGen-wkGen ts)\n\n substGen-wkGen : ∀ {bs} t → substGen σ (wkGen ρ t) ≡ substGen {bs = bs} (σ ₛ• ρ) t\n substGen-wkGen [] = refl\n substGen-wkGen (_∷_ {b = b} t ts) =\n cong₂ _∷_ (trans (subst-wk t) (subst-lifts-ₛ• b t)) (substGen-wkGen ts)\n\n\n-- Composition of liftings is lifting of the composition.\n\nwk-subst-lift : (G : Term (1+ n))\n → wk (lift ρ) (subst (liftSubst σ) G)\n ≡ subst (liftSubst (ρ •ₛ σ)) G\nwk-subst-lift G = trans (wk-subst G) (subst-lift-•ₛ G)\n\n-- Renaming with ρ is the same as substituting with ρ turned into a substitution.\n\nwk≡subst : (ρ : Wk m n) (t : Term n) → wk ρ t ≡ subst (toSubst ρ) t\nwk≡subst ρ t = trans (cong (wk ρ) (sym (subst-id t))) (wk-subst t)\n\n\n-- Composition of substitutions.\n\n-- Composition of liftings is lifting of the composition.\n\nsubstCompLift : ∀ x\n → (liftSubst σ ₛ•ₛ liftSubst σ′) x\n ≡ (liftSubst (σ ₛ•ₛ σ′)) x\nsubstCompLift x0 = refl\nsubstCompLift {σ = σ} {σ′ = σ′} (x +1) = trans (subst-wk (σ′ x)) (sym (wk-subst (σ′ x)))\n\nsubstCompLifts : ∀ n x\n → (liftSubstn σ n ₛ•ₛ liftSubstn σ′ n) x\n ≡ (liftSubstn (σ ₛ•ₛ σ′) n) x\nsubstCompLifts 0 x = refl\nsubstCompLifts (1+ n) x0 = refl\nsubstCompLifts {σ = σ} {σ′ = σ′} (1+ n) (x +1) =\n trans (substCompLift {σ = liftSubstn σ n} {σ′ = liftSubstn σ′ n} (x +1))\n (cong wk1 (substCompLifts n x))\n-- Soundness of the composition of substitutions.\n\nmutual\n substCompEq : ∀ (t : Term n)\n → subst σ (subst σ′ t) ≡ subst (σ ₛ•ₛ σ′) t\n substCompEq (var x) = refl\n substCompEq (gen k ts) = cong (gen k) (substGenCompEq ts)\n\n substGenCompEq : ∀ {bs} t\n → substGen σ (substGen σ′ t) ≡ substGen {bs = bs} (σ ₛ•ₛ σ′) t\n substGenCompEq [] = refl\n substGenCompEq (_∷_ {b = b} t ts) =\n cong₂ _∷_ (trans (substCompEq t) (substVar-to-subst (substCompLifts b) t))\n (substGenCompEq ts)\n\n-- Weakening single substitutions.\n\n-- Pulling apart a weakening composition in specific context _[a].\n\nwk-comp-subst : ∀ {a} (ρ : Wk m ℓ) (ρ′ : Wk ℓ n) G\n → wk (lift (ρ • ρ′)) G [ a ] ≡ wk (lift ρ) (wk (lift ρ′) G) [ a ]\n\nwk-comp-subst {a = a} ρ ρ′ G =\n cong (λ x → x [ a ]) (sym (wk-comp (lift ρ) (lift ρ′) G))\n\n-- Pushing a weakening into a single substitution.\n-- ρ (t[a]) = ((lift ρ) t)[ρ a]\n\nwk-β : ∀ {a} t → wk ρ (t [ a ]) ≡ wk (lift ρ) t [ wk ρ a ]\nwk-β t = trans (wk-subst t) (sym (trans (subst-wk t)\n (substVar-to-subst (λ { x0 → refl ; (x +1) → refl}) t)))\n\n-- Pushing a weakening into a single shifting substitution.\n-- If ρ′ = lift ρ then ρ′(t[a]↑) = ρ′(t) [ρ′(a)]↑\n\nwk-β↑ : ∀ {a} t → wk (lift ρ) (t [ a ]↑) ≡ wk (lift ρ) t [ wk (lift ρ) a ]↑\nwk-β↑ t = trans (wk-subst t) (sym (trans (subst-wk t)\n (substVar-to-subst (λ { x0 → refl ; (x +1) → refl}) t)))\n\n-- A specific equation on weakenings used for the reduction of natrec.\n\nwk-β-natrec : ∀ (ρ : Wk m n )G\n → Π ℕ ▹ (Π wk (lift ρ) G ▹ wk (lift (lift ρ)) (wk1 (G [ suc (var x0) ]↑)))\n ≡ Π ℕ ▹ (wk (lift ρ) G ▹▹ wk (lift ρ) G [ suc (var x0) ]↑)\nwk-β-natrec ρ G =\n cong₂ Π_▹_ refl (cong₂ Π_▹_ refl\n (trans (wk-comp (lift (lift ρ)) (step id)\n (subst (consSubst (wk1Subst var) (suc (var x0))) G))\n (trans (wk-subst G) (sym (trans (wk-subst (wk (lift ρ) G))\n (trans (subst-wk G)\n (substVar-to-subst (λ { x0 → refl ; (x +1) → refl}) G)))))))\n\n-- Composing a singleton substitution and a lifted substitution.\n-- sg u ∘ lift σ = cons id u ∘ lift σ = cons σ u\n\nsubstVarSingletonComp : ∀ {u} (x : Fin (1+ n))\n → (sgSubst u ₛ•ₛ liftSubst σ) x ≡ (consSubst σ u) x\nsubstVarSingletonComp x0 = refl\nsubstVarSingletonComp {σ = σ} (x +1) = trans (subst-wk (σ x)) (subst-id (σ x))\n\n-- The same again, as action on a term t.\n\nsubstSingletonComp : ∀ {a} t\n → subst (sgSubst a ₛ•ₛ liftSubst σ) t ≡ subst (consSubst σ a) t\nsubstSingletonComp = substVar-to-subst substVarSingletonComp\n\n-- A single substitution after a lifted substitution.\n-- ((lift σ) G)[t] = (cons σ t)(G)\n\nsingleSubstComp : ∀ t (σ : Subst m n) G\n → (subst (liftSubst σ) G) [ t ]\n ≡ subst (consSubst σ t) G\nsingleSubstComp t σ G = trans (substCompEq G) (substSingletonComp G)\n\n-- A single substitution after a lifted substitution (with weakening).\n-- ((lift (ρ ∘ σ)) G)[t] = (cons (ρ ∘ σ) t)(G)\n\nsingleSubstWkComp : ∀ t (σ : Subst m n) G\n → wk (lift ρ) (subst (liftSubst σ) G) [ t ]\n ≡ subst (consSubst (ρ •ₛ σ) t) G\nsingleSubstWkComp t σ G =\n trans (cong (subst (consSubst var t))\n (trans (wk-subst G) (subst-lift-•ₛ G)))\n (trans (substCompEq G) (substSingletonComp G))\n\n-- Pushing a substitution into a single substitution.\n\nsingleSubstLift : ∀ G t\n → subst σ (G [ t ])\n ≡ subst (liftSubst σ) G [ subst σ t ]\nsingleSubstLift G t =\n trans (substCompEq G)\n (trans (trans (substVar-to-subst (λ { x0 → refl ; (x +1) → refl}) G)\n (sym (substSingletonComp G)))\n (sym (substCompEq G)))\n\n-- More specific laws.\n\nidWkLiftSubstLemma : ∀ (σ : Subst m n) G\n → wk (lift (step id)) (subst (liftSubst σ) G) [ var x0 ]\n ≡ subst (liftSubst σ) G\nidWkLiftSubstLemma σ G =\n trans (singleSubstWkComp (var x0) σ G)\n (substVar-to-subst (λ { x0 → refl ; (x +1) → refl}) G)\n\nsubstVarComp↑ : ∀ {t} (σ : Subst m n) x\n → (consSubst (wk1Subst idSubst) (subst (liftSubst σ) t) ₛ•ₛ liftSubst σ) x\n ≡ (liftSubst σ ₛ•ₛ consSubst (wk1Subst idSubst) t) x\nsubstVarComp↑ σ x0 = refl\nsubstVarComp↑ σ (x +1) = trans (subst-wk (σ x)) (sym (wk≡subst (step id) (σ x)))\n\nsingleSubstLift↑ : ∀ (σ : Subst m n) G t\n → subst (liftSubst σ) (G [ t ]↑)\n ≡ subst (liftSubst σ) G [ subst (liftSubst σ) t ]↑\nsingleSubstLift↑ σ G t =\n trans (substCompEq G)\n (sym (trans (substCompEq G) (substVar-to-subst (substVarComp↑ σ) G)))\n\nsubstConsComp : ∀ {t G}\n → subst (consSubst (λ x → σ (x +1)) (subst (tail σ) t)) G\n ≡ subst σ (subst (consSubst (λ x → var (x +1)) (wk1 t)) G)\nsubstConsComp {t = t} {G = G} =\n trans (substVar-to-subst (λ { x0 → sym (subst-wk t) ; (x +1) → refl }) G)\n (sym (substCompEq G))\n\nwkSingleSubstId : (F : Term (1+ n)) → (wk (lift (step id)) F) [ var x0 ] ≡ F\nwkSingleSubstId F =\n trans (subst-wk F)\n (trans (substVar-to-subst (λ { x0 → refl ; (x +1) → refl}) F)\n (subst-id F))\n\ncons-wk-subst : ∀ (ρ : Wk m n) (σ : Subst n ℓ) a t\n → subst (sgSubst a ₛ• lift ρ ₛ•ₛ liftSubst σ) t\n ≡ subst (consSubst (ρ •ₛ σ) a) t\ncons-wk-subst ρ σ a = substVar-to-subst\n (λ { x0 → refl\n ; (x +1) → trans (subst-wk (σ x)) (sym (wk≡subst ρ (σ x))) })\n\nnatrecSucCaseLemma : (x : Fin (1+ n))\n → (step id •ₛ consSubst (wk1Subst idSubst) (suc (var x0)) ₛ•ₛ liftSubst σ) x\n ≡ (liftSubst (liftSubst σ) ₛ• step id ₛ•ₛ consSubst (wk1Subst idSubst) (suc (var x0))) x\nnatrecSucCaseLemma x0 = refl\nnatrecSucCaseLemma {σ = σ} (x +1) =\n trans (subst-wk (σ x))\n (sym (trans (wk1-wk (step id) _)\n (wk≡subst (step (step id)) (σ x))))\n\nnatrecSucCase : ∀ (σ : Subst m n) F\n → Π ℕ ▹ (Π subst (liftSubst σ) F\n ▹ subst (liftSubst (liftSubst σ)) (wk1 (F [ suc (var x0) ]↑)))\n ≡ Π ℕ ▹ (subst (liftSubst σ) F ▹▹ subst (liftSubst σ) F [ suc (var x0) ]↑)\nnatrecSucCase σ F =\n cong₂ Π_▹_ refl\n (cong₂ Π_▹_ refl\n (trans (trans (subst-wk (F [ suc (var x0) ]↑))\n (substCompEq F))\n (sym (trans (wk-subst (subst (liftSubst σ) F))\n (trans (substCompEq F)\n (substVar-to-subst natrecSucCaseLemma F))))))\n\nnatrecIrrelevantSubstLemma : ∀ F z s m (σ : Subst ℓ n) (x : Fin (1+ n))\n → (sgSubst (natrec (subst (liftSubst σ) F) (subst σ z) (subst σ s) m)\n ₛ•ₛ liftSubst (sgSubst m)\n ₛ•ₛ liftSubst (liftSubst σ)\n ₛ• step id\n ₛ•ₛ consSubst (tail idSubst) (suc (var x0))) x\n ≡ (consSubst σ (suc m)) x\nnatrecIrrelevantSubstLemma F z s m σ x0 =\n cong suc (trans (subst-wk m) (subst-id m))\nnatrecIrrelevantSubstLemma F z s m σ (x +1) =\n trans (subst-wk (wk (step id) (σ x)))\n (trans (subst-wk (σ x))\n (subst-id (σ x)))\n\nnatrecIrrelevantSubst : ∀ F z s m (σ : Subst ℓ n)\n → subst (consSubst σ (suc m)) F\n ≡ subst (liftSubst (sgSubst m))\n (subst (liftSubst (liftSubst σ))\n (wk1 (F [ suc (var x0) ]↑)))\n [ natrec (subst (liftSubst σ) F) (subst σ z) (subst σ s) m ]\nnatrecIrrelevantSubst F z s m σ =\n sym (trans (substCompEq (subst (liftSubst (liftSubst σ))\n (wk (step id)\n (subst (consSubst (tail idSubst) (suc (var x0))) F))))\n (trans (substCompEq (wk (step id)\n (subst (consSubst (tail idSubst) (suc (var x0))) F)))\n (trans\n (subst-wk (subst (consSubst (tail idSubst) (suc (var x0))) F))\n (trans (substCompEq F)\n (substVar-to-subst (natrecIrrelevantSubstLemma F z s m σ) F)))))\n\nnatrecIrrelevantSubstLemma′ : ∀ F z s n (x : Fin (1+ m))\n → (sgSubst (natrec F z s n)\n ₛ•ₛ liftSubst (sgSubst n)\n ₛ• step id\n ₛ•ₛ consSubst (tail idSubst) (suc (var x0))) x\n ≡ (consSubst var (suc n)) x\nnatrecIrrelevantSubstLemma′ F z s n x0 =\n cong suc (trans (subst-wk n) (subst-id n))\nnatrecIrrelevantSubstLemma′ F z s n (x +1) = refl\n\nnatrecIrrelevantSubst′ : ∀ (F : Term (1+ m)) z s n\n → subst (liftSubst (sgSubst n))\n (wk1 (F [ suc (var x0) ]↑))\n [ natrec F z s n ]\n ≡ F [ suc n ]\nnatrecIrrelevantSubst′ F z s n =\n trans (substCompEq (wk (step id)\n (subst (consSubst (tail idSubst) (suc (var x0))) F)))\n (trans (subst-wk (subst (consSubst (tail idSubst) (suc (var x0))) F))\n (trans (substCompEq F)\n (substVar-to-subst (natrecIrrelevantSubstLemma′ F z s n) F)))\n\ncons0wkLift1-id : ∀ (σ : Subst m n) G\n → subst (sgSubst (var x0))\n (wk (lift (step id)) (subst (liftSubst σ) G))\n ≡ subst (liftSubst σ) G\ncons0wkLift1-id σ G =\n trans (subst-wk (subst (liftSubst σ) G))\n (trans (substVar-to-subst (λ { x0 → refl ; (x +1) → refl })\n (subst (liftSubst σ) G))\n (subst-id (subst (liftSubst σ) G)))\n\nsubstConsId : ∀ {t} G\n → subst (consSubst σ (subst σ t)) G\n ≡ subst σ (subst (sgSubst t) G)\nsubstConsId G =\n sym (trans (substCompEq G)\n (substVar-to-subst (λ { x0 → refl ; (x +1) → refl}) G))\n\nsubstConsTailId : ∀ {G t}\n → subst (consSubst (tail σ) (subst σ t)) G\n ≡ subst σ (subst (consSubst (tail idSubst) t) G)\nsubstConsTailId {G = G} =\n trans (substVar-to-subst (λ { x0 → refl\n ; (x +1) → refl }) G)\n (sym (substCompEq G))\n\nsubstConcatSingleton′ : ∀ {a} t\n → subst (σ ₛ•ₛ sgSubst a) t\n ≡ subst (consSubst σ (subst σ a)) t\nsubstConcatSingleton′ t = substVar-to-subst (λ { x0 → refl ; (x +1) → refl}) t\n\nwk1-tailId : (t : Term n) → wk1 t ≡ subst (tail idSubst) t\nwk1-tailId t = trans (sym (subst-id (wk1 t))) (subst-wk t)\n\nwk1-sgSubst : ∀ (t : Term n) t' → (wk1 t) [ t' ] ≡ t\nwk1-sgSubst t t' rewrite wk1-tailId t =\n let substVar-sgSubst-tail : ∀ a n → (sgSubst a ₛ•ₛ tail idSubst) n ≡ idSubst n\n substVar-sgSubst-tail a n = refl\n in trans (trans\n (substCompEq t)\n (substVar-to-subst (substVar-sgSubst-tail t') t))\n (subst-id t)\n", "meta": {"hexsha": "82792a71eff4f3309f3300cd0547bd632ad20019", "size": 20755, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Untyped/Properties.agda", "max_stars_repo_name": "fhlkfy/logrel-mltt", "max_stars_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2017-05-20T03:05:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:01:07.000Z", "max_issues_repo_path": "Definition/Untyped/Properties.agda", "max_issues_repo_name": "fhlkfy/logrel-mltt", "max_issues_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-06-22T12:49:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-22T10:37:24.000Z", "max_forks_repo_path": "Definition/Untyped/Properties.agda", "max_forks_repo_name": "fhlkfy/logrel-mltt", "max_forks_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2017-10-18T14:18:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-27T15:58:33.000Z", "avg_line_length": 35.9083044983, "max_line_length": 93, "alphanum_fraction": 0.5557215129, "num_tokens": 8243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3650730576745188}} {"text": "------------------------------------------------------------------------\n-- Functional semantics for a non-deterministic untyped λ-calculus\n-- with constants\n------------------------------------------------------------------------\n\nmodule Lambda.Closure.Functional.Non-deterministic where\n\nopen import Category.Monad.Partiality as Pa using (_⊥; now; later)\nopen import Codata.Musical.Notation\nopen import Data.Fin using (Fin; zero; suc; #_)\nopen import Data.List hiding (lookup)\nopen import Data.Maybe hiding (_>>=_)\nopen import Data.Nat\nopen import Data.Vec using ([]; _∷_; lookup)\nopen import Function\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\nopen import Relation.Nullary\nopen import Relation.Nullary.Decidable\n\nopen import Lambda.Syntax using (Ty; Ctxt)\nopen Lambda.Syntax.Closure using (con; ƛ)\nopen Lambda.Syntax.Ty\nopen import Lambda.VirtualMachine\n hiding (comp; comp-val; comp-env; lookup-hom)\nopen Functional\nprivate\n module VM = Lambda.Syntax.Closure Code\n\n------------------------------------------------------------------------\n-- A monad with partiality, failure and non-determinism\n\nmodule D where\n\n -- This is basically the maybe monad transformer applied to the\n -- partiality monad transformer applied to the non-determinism monad\n -- N A = μX. A ⊎ X × X. Unfortunately it is somewhat awkward to\n -- implement the partiality monad transformer in Agda: the\n -- definition\n --\n -- data Partiality′ (M : Set → Set) (A : Set) : Set where\n -- now-or-later : M (A ⊎ Partiality′ M A) → Partiality′ M A\n --\n -- is rejected, because M might use its argument negatively.\n\n infixr 6 _∣_\n\n data D (A : Set) : Set where\n fail : D A\n return : (x : A) → D A\n _∣_ : (x y : D A) → D A\n later : (x : ∞ (D A)) → D A\n\n -- The function force n removes (up to) n layers of later\n -- constructors.\n\n force : {A : Set} → ℕ → D A → D A\n force (suc n) (later x) = force n (♭ x)\n force n (x₁ ∣ x₂) = force n x₁ ∣ force n x₂\n force _ x = x\n\n -- Bind.\n\n infixl 5 _>>=_\n\n _>>=_ : {A B : Set} → D A → (A → D B) → D B\n fail >>= f = fail\n return x >>= f = f x\n (x₁ ∣ x₂) >>= f = (x₁ >>= f) ∣ (x₂ >>= f)\n later x >>= f = later (♯ (♭ x >>= f))\n\n -- A deterministic non-terminating computation.\n\n never : {A : Set} → D A\n never = later (♯ never)\n\n -- Strong bisimilarity.\n\n infix 4 _≅_\n\n data _≅_ {A : Set} : D A → D A → Set where\n fail : fail ≅ fail\n return : ∀ {x} → return x ≅ return x\n _∣_ : ∀ {x₁ x₂ y₁ y₂}\n (x₁≅y₁ : x₁ ≅ y₁) (x₂≅y₂ : x₂ ≅ y₂) → x₁ ∣ x₂ ≅ y₁ ∣ y₂\n later : ∀ {x y} (x≅y : ∞ (♭ x ≅ ♭ y)) → later x ≅ later y\n\n -- Strong bisimilarity is reflexive.\n\n infixr 3 _∎\n\n _∎ : {A : Set} (x : D A) → x ≅ x\n fail ∎ = fail\n return x ∎ = return\n x₁ ∣ x₂ ∎ = (x₁ ∎) ∣ (x₂ ∎)\n later x ∎ = later (♯ (♭ x ∎))\n\n -- Strong bisimilarity is symmetric.\n\n sym : {A : Set} {x y : D A} → x ≅ y → y ≅ x\n sym fail = fail\n sym return = return\n sym (x₁≅y₁ ∣ x₂≅y₂) = sym x₁≅y₁ ∣ sym x₂≅y₂\n sym (later x≅y) = later (♯ sym (♭ x≅y))\n\n -- Strong bisimilarity is transitive.\n\n infixr 2 _≅⟨_⟩_\n\n _≅⟨_⟩_ : ∀ {A : Set} (x : D A) {y z} → x ≅ y → y ≅ z → x ≅ z\n ._ ≅⟨ fail ⟩ fail = fail\n ._ ≅⟨ return ⟩ return = return\n ._ ≅⟨ x₁≅y₁ ∣ x₂≅y₂ ⟩ y₁≅z₁ ∣ y₂≅z₂ = (_ ≅⟨ x₁≅y₁ ⟩ y₁≅z₁) ∣ (_ ≅⟨ x₂≅y₂ ⟩ y₂≅z₂)\n ._ ≅⟨ later x≅y ⟩ later y≅z = later (♯ (_ ≅⟨ ♭ x≅y ⟩ ♭ y≅z))\n\n -- The monad laws hold up to strong bisimilarity.\n\n left-identity : {A B : Set} {x : A} {f : A → D B} →\n return x >>= f ≅ f x\n left-identity {x = x} {f} = f x ∎\n\n right-identity : {A : Set} (x : D A) → x >>= return ≅ x\n right-identity fail = fail\n right-identity (return x) = return\n right-identity (x₁ ∣ x₂) = right-identity x₁ ∣ right-identity x₂\n right-identity (later x) = later (♯ right-identity (♭ x))\n\n associative : {A B C : Set} (x : D A) {f : A → D B} {g : B → D C} →\n x >>= f >>= g ≅ x >>= λ y → f y >>= g\n associative fail = fail\n associative (return x) {f} {g} = f x >>= g ∎\n associative (x₁ ∣ x₂) = associative x₁ ∣ associative x₂\n associative (later x) = later (♯ associative (♭ x))\n\n -- Bind respects strong bisimilarity.\n\n infixl 5 _>>=-cong_\n\n _>>=-cong_ : {A B : Set} {x₁ x₂ : D A} {f₁ f₂ : A → D B} →\n x₁ ≅ x₂ → (∀ y → f₁ y ≅ f₂ y) → x₁ >>= f₁ ≅ x₂ >>= f₂\n fail >>=-cong f₁≅f₂ = fail\n return >>=-cong f₁≅f₂ = f₁≅f₂ _\n later x≅y >>=-cong f₁≅f₂ = later (♯ (♭ x≅y >>=-cong f₁≅f₂))\n x₁≅x₂ ∣ y₁≅y₂ >>=-cong f₁≅f₂ =\n (x₁≅x₂ >>=-cong f₁≅f₂) ∣ (y₁≅y₂ >>=-cong f₁≅f₂)\n\n -- More laws.\n\n never-left-zero : {A B : Set} {f : A → D B} → never >>= f ≅ never\n never-left-zero = later (♯ never-left-zero)\n\n fail-left-zero : {A B : Set} {f : A → D B} → fail >>= f ≅ fail\n fail-left-zero = fail ∎\n\nopen D using (D; _≅_; _≅⟨_⟩_; _∎; _>>=-cong_) hiding (module D)\nopen D.D\nopen D._≅_\n\n------------------------------------------------------------------------\n-- Syntax\n\ninfixl 9 _·_\ninfixr 6 _∣_\n\ndata Tm (n : ℕ) : Set where\n con : (i : ℕ) → Tm n\n var : (x : Fin n) → Tm n\n ƛ : (t : Tm (suc n)) → Tm n\n _·_ : (t₁ t₂ : Tm n) → Tm n\n _∣_ : (t₁ t₂ : Tm n) → Tm n\n\n-- Convenient helper.\n\nvr : ∀ m {n} {m>=_\n\n data DP : Set → Set₁ where\n fail : ∀ {A} → DP A\n return : ∀ {A} (x : A) → DP A\n _∣_ : ∀ {A} (x y : DP A) → DP A\n later : ∀ {A} (x : ∞ (DP A)) → DP A\n _>>=_ : ∀ {A B} (x : DP A) (f : A → DP B) → DP B\n\n private\n\n data DW : Set → Set₁ where\n fail : ∀ {A} → DW A\n return : ∀ {A} (x : A) → DW A\n _∣_ : ∀ {A} (x y : DW A) → DW A\n later : ∀ {A} (x : DP A) → DW A\n\n mutual\n\n _>>=W_ : ∀ {A B} → DW A → (A → DP B) → DW B\n fail >>=W f = fail\n return x >>=W f = whnf (f x)\n (x ∣ y) >>=W f = (x >>=W f) ∣ (y >>=W f)\n later x >>=W f = later (x >>= f)\n\n whnf : ∀ {A} → DP A → DW A\n whnf fail = fail\n whnf (return x) = return x\n whnf (later x) = later (♭ x)\n whnf (x ∣ y) = whnf x ∣ whnf y\n whnf (x >>= f) = whnf x >>=W f\n\n mutual\n\n private\n\n ⟪_⟫W : ∀ {A} → DW A → D A\n ⟪ fail ⟫W = fail\n ⟪ return x ⟫W = return x\n ⟪ x ∣ y ⟫W = ⟪ x ⟫W ∣ ⟪ y ⟫W\n ⟪ later x ⟫W = later (♯ ⟪ x ⟫P)\n\n ⟪_⟫P : ∀ {A} → DP A → D A\n ⟪ p ⟫P = ⟪ whnf p ⟫W\n\n -- The definitions above make sense. ⟪_⟫P is homomorphic with respect\n -- to fail, return, _∣_, later and _>>=_.\n\n fail-hom : ∀ {A} → ⟪ fail {A = A} ⟫P ≅ fail\n fail-hom = fail ∎\n\n return-hom : ∀ {A} (x : A) → ⟪ return x ⟫P ≅ return x\n return-hom x = return x ∎\n\n ∣-hom : ∀ {A} (x y : DP A) → ⟪ x ∣ y ⟫P ≅ ⟪ x ⟫P ∣ ⟪ y ⟫P\n ∣-hom x y = ⟪ x ⟫P ∣ ⟪ y ⟫P ∎\n\n later-hom : ∀ {A} (x : ∞ (DP A)) → ⟪ later x ⟫P ≅ later (♯ ⟪ ♭ x ⟫P)\n later-hom x = later (♯ (⟪ ♭ x ⟫P ∎))\n\n mutual\n\n private\n\n >>=-homW : ∀ {A B} (x : DW A) (f : A → DP B) →\n ⟪ x >>=W f ⟫W ≅ D._>>=_ ⟪ x ⟫W (λ y → ⟪ f y ⟫P)\n >>=-homW fail f = fail ∎\n >>=-homW (return x) f = ⟪ f x ⟫P ∎\n >>=-homW (x ∣ y) f = >>=-homW x f ∣ >>=-homW y f\n >>=-homW (later x) f = later (♯ >>=-hom x f)\n\n >>=-hom : ∀ {A B} (x : DP A) (f : A → DP B) →\n ⟪ x >>= f ⟫P ≅ D._>>=_ ⟪ x ⟫P (λ y → ⟪ f y ⟫P)\n >>=-hom x f = >>=-homW (whnf x) f\n\nopen Workaround hiding (_>>=_)\n\n------------------------------------------------------------------------\n-- Semantics\n\ninfix 9 _∙_\n\nmutual\n\n ⟦_⟧′ : ∀ {n} → Tm n → Env n → DP Value\n ⟦ con i ⟧′ ρ = return (con i)\n ⟦ var x ⟧′ ρ = return (lookup ρ x)\n ⟦ ƛ t ⟧′ ρ = return (ƛ t ρ)\n ⟦ t₁ · t₂ ⟧′ ρ = ⟦ t₁ ⟧′ ρ >>= λ v₁ →\n ⟦ t₂ ⟧′ ρ >>= λ v₂ →\n v₁ ∙ v₂\n where open Workaround\n ⟦ t₁ ∣ t₂ ⟧′ ρ = ⟦ t₁ ⟧′ ρ ∣ ⟦ t₂ ⟧′ ρ\n\n _∙_ : Value → Value → DP Value\n con i ∙ v₂ = fail\n ƛ t₁ ρ ∙ v₂ = later (♯ (⟦ t₁ ⟧′ (v₂ ∷ ρ)))\n\n⟦_⟧ : ∀ {n} → Tm n → Env n → D Value\n⟦ t ⟧ ρ = ⟪ ⟦ t ⟧′ ρ ⟫P\n\n-- An abbreviation.\n\ninfix 9 _⟦·⟧_\n\n_⟦·⟧_ : D Value → D Value → D Value\nv₁ ⟦·⟧ v₂ = v₁ >>= λ v₁ → v₂ >>= λ v₂ → ⟪ v₁ ∙ v₂ ⟫P\n where open D\n\n-- The semantics of application is compositional (with respect to the\n-- syntactic equality which is used).\n\n·-comp : ∀ {n} (t₁ t₂ : Tm n) {ρ} →\n ⟦ t₁ · t₂ ⟧ ρ ≅ ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ\n·-comp t₁ t₂ {ρ} =\n ⟦ t₁ · t₂ ⟧ ρ ≅⟨ >>=-hom (⟦ t₁ ⟧′ ρ) _ ⟩\n\n D._>>=_ (⟦ t₁ ⟧ ρ) (λ v₁ →\n ⟪ Workaround._>>=_ (⟦ t₂ ⟧′ ρ) (λ v₂ →\n v₁ ∙ v₂) ⟫P) ≅⟨ ((⟦ t₁ ⟧ ρ ∎) >>=-cong λ _ →\n >>=-hom (⟦ t₂ ⟧′ ρ) _) ⟩\n ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ∎\n\nopen D\n\n------------------------------------------------------------------------\n-- Compiler\n\n-- The compiler takes a code continuation.\n--\n-- Non-determinism is resolved by always picking the left choice.\n\ncomp : ∀ {n} → Tm n → Code n → Code n\ncomp (con i) c = con i ∷ c\ncomp (var x) c = var x ∷ c\ncomp (ƛ t) c = clo (comp t [ ret ]) ∷ c\ncomp (t₁ · t₂) c = comp t₁ (comp t₂ (app ∷ c))\ncomp (t₁ ∣ t₂) c = comp t₁ c\n\n-- Environments and values can also be compiled.\n\nmutual\n\n comp-env : ∀ {n} → Env n → VM.Env n\n comp-env [] = []\n comp-env (v ∷ ρ) = comp-val v ∷ comp-env ρ\n\n comp-val : Value → VM.Value\n comp-val (con i) = con i\n comp-val (ƛ t ρ) = ƛ (comp t [ ret ]) (comp-env ρ)\n\n-- lookup x is homomorphic with respect to comp-env/comp-val.\n\nlookup-hom : ∀ {n} (x : Fin n) ρ →\n lookup (comp-env ρ) x ≡ comp-val (lookup ρ x)\nlookup-hom zero (v ∷ ρ) = P.refl\nlookup-hom (suc x) (v ∷ ρ) = lookup-hom x ρ\n\n------------------------------------------------------------------------\n-- Examples\n\n-- A non-terminating term.\n\nΩ : Tm 0\nΩ = ω · ω\n where ω = ƛ (vr 0 · vr 0)\n\nΩ-loops : ⟦ Ω ⟧ [] ≅ never\nΩ-loops = later (♯ Ω-loops)\n\n-- A call-by-value fix-point combinator.\n\nZ : {n : ℕ} → Tm n\nZ = ƛ (t · t)\n where t = ƛ (vr 1 · ƛ (vr 1 · vr 1 · vr 0))\n\n-- A non-deterministically non-terminating term.\n\n! : Tm 0\n! = Z · ƛ (ƛ (vr 1 · vr 0 ∣ vr 1 · vr 0)) · con 0\n\n-- Its semantics.\n\n!-sem : D Value\n!-sem = later (♯ later (♯ later (♯ later (♯ (!-sem ∣ !-sem)))))\n\n⟦!⟧≅!-sem : ⟦ ! ⟧ [] ≅ !-sem\n⟦!⟧≅!-sem = later (♯ lem)\n where\n lem : force 1 (⟦ ! ⟧ []) ≅ force 1 !-sem\n lem = later (♯ later (♯ later (♯ (later (♯ lem) ∣ later (♯ lem)))))\n\n-- How did I come up with this proof term? Through a manual\n-- calculation...\n--\n-- Let us first define some abbreviations:\n--\n-- t₀ = vr 1 · vr 1 · vr 0\n-- t₁ = ƛ t₀\n-- t₂ = vr 1 · t₁\n-- t₃ = ƛ t₂\n--\n-- u₀ = vr 1 · vr 0\n-- u₁ = u₀ ∣ u₀\n-- u₂ = ƛ u₁\n-- u₃ = ƛ u₂\n--\n-- c₀ = ƛ u₂ []\n-- c₁ = ƛ t₂ (c₀ ∷ [])\n-- c₂ = ƛ t₀ (c₁ ∷ c₀ ∷ [])\n--\n-- Now we can calculate as follows (ignoring ♯):\n--\n-- ⟦ Z · u₃ · con 0 ⟧ []\n-- = ⟦ Z · u₃ ⟧ [] ⟦·⟧ return (con 0)\n-- = ƛ (t₃ · t₃) [] ∙ c₀ ⟦·⟧ return (con 0)\n-- = later (⟦ t₃ · t₃ ⟧ (c₀ ∷ []) ⟦·⟧ return (con 0))\n-- = later (c₁ ∙ c₁ ⟦·⟧ return (con 0))\n--\n-- = c₁ ∙ c₁ ⟦·⟧ return (con 0)\n-- = later (⟦ t₂ ⟧ (c₁ ∷ c₀ ∷ []) ⟦·⟧ return (con 0))\n-- = later (c₀ ∙ c₂ ⟦·⟧ return (con 0))\n-- = later (later (⟦ u₂ ⟧ (c₂ ∷ []) ⟦·⟧ return (con 0)))\n-- = later (later (ƛ u₁ (c₂ ∷ []) ∙ con 0))\n-- = later (later (later (⟦ u₁ ⟧ (con 0 ∷ c₂ ∷ []))))\n-- = later (later (later (⟦ u₀ ⟧ (con 0 ∷ c₂ ∷ []) ∣\n-- ⟦ u₀ ⟧ (con 0 ∷ c₂ ∷ []))))\n-- = later (later (later (c₂ ∙ con 0 ∣ c₂ ∙ con 0)))\n-- = later (later (later (⟦ t₀ ⟧ (con 0 ∷ c₁ ∷ c₀ ∷ []) ∣\n-- ⟦ t₀ ⟧ (con 0 ∷ c₁ ∷ c₀ ∷ []))))\n-- = later (later (later (later (c₁ ∙ c₁ ⟦·⟧ return (con 0)) ∣\n-- later (c₁ ∙ c₁ ⟦·⟧ return (con 0)))))\n\n------------------------------------------------------------------------\n-- A relation relating deterministic and non-deterministic\n-- computations\n\n-- x ≈∈ y means that x implements /one/ possible semantics of y (up to\n-- weak bisimilarity).\n\ninfix 4 _≈∈_\n\ndata _≈∈_ {A : Set} : Maybe A ⊥ → D A → Set where\n fail : now nothing ≈∈ fail\n\n return : ∀ {x} → now (just x) ≈∈ return x\n\n ∣ˡ : ∀ {x y₁ y₂} (x≈∈y₁ : x ≈∈ y₁) → x ≈∈ y₁ ∣ y₂\n ∣ʳ : ∀ {x y₁ y₂} (x≈∈y₂ : x ≈∈ y₂) → x ≈∈ y₁ ∣ y₂\n\n later : ∀ {x y} (x≈∈y : ∞ (♭ x ≈∈ ♭ y)) → later x ≈∈ later y\n laterˡ : ∀ {x y} (x≈∈y : ♭ x ≈∈ y ) → later x ≈∈ y\n laterʳ : ∀ {x y} (x≈∈y : x ≈∈ ♭ y ) → x ≈∈ later y\n\n-- A transitivity-like result for _≡_ and _≈∈_.\n\ninfixr 2 _≡⟨_⟩_\n\n_≡⟨_⟩_ : ∀ {A : Set} (x : Maybe A ⊥) {y z} → x ≡ y → y ≈∈ z → x ≈∈ z\n_ ≡⟨ P.refl ⟩ y≈z = y≈z\n\n-- A transitivity-like result for _≈∈_ and _≅_.\n\ninfixr 2 _≈∈⟨_⟩_\n\n_≈∈⟨_⟩_ : ∀ {A : Set} (x : Maybe A ⊥) {y z} → x ≈∈ y → y ≅ z → x ≈∈ z\n._ ≈∈⟨ fail ⟩ fail = fail\n._ ≈∈⟨ return ⟩ return = return\n_ ≈∈⟨ ∣ˡ x₁≈∈y₁ ⟩ y₁≅z₁ ∣ y₂≅z₂ = ∣ˡ (_ ≈∈⟨ x₁≈∈y₁ ⟩ y₁≅z₁)\n_ ≈∈⟨ ∣ʳ x₂≈∈y₂ ⟩ y₁≅z₁ ∣ y₂≅z₂ = ∣ʳ (_ ≈∈⟨ x₂≈∈y₂ ⟩ y₂≅z₂)\n._ ≈∈⟨ later x≈∈y ⟩ later y≅z = later (♯ (_ ≈∈⟨ ♭ x≈∈y ⟩ ♭ y≅z))\n._ ≈∈⟨ laterˡ x≈∈y ⟩ y≅z = laterˡ (_ ≈∈⟨ x≈∈y ⟩ y≅z)\n_ ≈∈⟨ laterʳ x≈∈y ⟩ later y≅z = laterʳ (_ ≈∈⟨ x≈∈y ⟩ ♭ y≅z)\n\n-- An example.\n\nlemma : Pa.never ≈∈ !-sem\nlemma = later (♯ later (♯ later (♯ later (♯ ∣ˡ lemma))))\n\n------------------------------------------------------------------------\n-- Compiler correctness\n\nmodule Correctness where\n\n infix 4 _≈∈P_ _≈∈W_\n infixr 2 _≡⟨_⟩W_ _≈∈⟨_⟩P_ _≈∈⟨_⟩W_\n\n mutual\n\n data _≈∈P_ : Maybe VM.Value ⊥ → D VM.Value → Set where\n _≈∈⟨_⟩P_ : ∀ x {y z} (x≈y : x ≈∈P y) (y≅z : y ≅ z) → x ≈∈P z\n correct :\n ∀ {n} t {ρ : Env n} {c s} {k : Value → D VM.Value} →\n (hyp : ∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩\n ≈∈W k v) →\n exec ⟨ comp t c , s , comp-env ρ ⟩ ≈∈P (⟦ t ⟧ ρ >>= k)\n\n data _≈∈W_ : Maybe VM.Value ⊥ → D VM.Value → Set where\n ⌈_⌉ : ∀ {x y} (x≈y : x ≈∈ y) → x ≈∈W y\n ∣ˡ : ∀ {x y₁ y₂} (x≈y₁ : x ≈∈W y₁) → x ≈∈W y₁ ∣ y₂\n later : ∀ {x y} (x≈y : ♭ x ≈∈P ♭ y) → later x ≈∈W later y\n laterˡ : ∀ {x y} (x≈y : ♭ x ≈∈W y) → later x ≈∈W y\n\n _≡⟨_⟩W_ : ∀ x {y z} → x ≡ y → y ≈∈W z → x ≈∈W z\n _ ≡⟨ P.refl ⟩W y≈z = y≈z\n\n _≈∈⟨_⟩W_ : ∀ x {y z} → x ≈∈W y → y ≅ z → x ≈∈W z\n _ ≈∈⟨ ⌈ x≈y ⌉ ⟩W y≅z = ⌈ _ ≈∈⟨ x≈y ⟩ y≅z ⌉\n _ ≈∈⟨ ∣ˡ x≈y₁ ⟩W y₁≅z₁ ∣ y₂≅z₂ = ∣ˡ (_ ≈∈⟨ x≈y₁ ⟩W y₁≅z₁)\n ._ ≈∈⟨ later x≈y ⟩W later y≅z = later (_ ≈∈⟨ x≈y ⟩P ♭ y≅z)\n ._ ≈∈⟨ laterˡ x≈y ⟩W y≅z = laterˡ (_ ≈∈⟨ x≈y ⟩W y≅z)\n\n mutual\n\n correctW :\n ∀ {n} t {ρ : Env n} {c s} {k : Value → D VM.Value} →\n (∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≈∈W k v) →\n exec ⟨ comp t c , s , comp-env ρ ⟩ ≈∈W (⟦ t ⟧ ρ >>= k)\n correctW (con i) {ρ} {c} {s} {k} hyp = laterˡ (\n exec ⟨ c , val (con i) ∷ s , comp-env ρ ⟩ ≈∈⟨ hyp (con i) ⟩W\n k (con i) ∎)\n correctW (var x) {ρ} {c} {s} {k} hyp = laterˡ (\n exec ⟨ c , val (lookup (comp-env ρ) x) ∷ s , comp-env ρ ⟩ ≡⟨ P.cong (λ v → exec ⟨ c , val v ∷ s , comp-env ρ ⟩) (lookup-hom x ρ) ⟩W\n exec ⟨ c , val (comp-val (lookup ρ x)) ∷ s , comp-env ρ ⟩ ≈∈⟨ hyp (lookup ρ x) ⟩W\n k (lookup ρ x) ∎)\n correctW (ƛ t) {ρ} {c} {s} {k} hyp = laterˡ (\n exec ⟨ c , val (comp-val (ƛ t ρ)) ∷ s , comp-env ρ ⟩ ≈∈⟨ hyp (ƛ t ρ) ⟩W\n k (ƛ t ρ) ∎)\n correctW (t₁ · t₂) {ρ} {c} {s} {k} hyp =\n exec ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ≈∈⟨ correctW t₁ (λ v₁ → correctW t₂ (λ v₂ →\n ∙-correctW v₁ v₂ hyp)) ⟩W\n (⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → ⟪ v₁ ∙ v₂ ⟫P >>= k) ≅⟨ ((⟦ t₁ ⟧ ρ ∎) >>=-cong λ _ → sym $ associative (⟦ t₂ ⟧ ρ)) ⟩\n (⟦ t₁ ⟧ ρ >>= λ v₁ → (⟦ t₂ ⟧ ρ >>= λ v₂ → ⟪ v₁ ∙ v₂ ⟫P) >>= k) ≅⟨ sym $ associative (⟦ t₁ ⟧ ρ) ⟩\n (⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ >>= k) ≅⟨ sym (·-comp t₁ t₂ >>=-cong λ v → k v ∎) ⟩\n (⟦ t₁ · t₂ ⟧ ρ >>= k) ∎\n correctW (t₁ ∣ t₂) {ρ} {c} {s} {k} hyp =\n exec ⟨ comp t₁ c , s , comp-env ρ ⟩ ≈∈⟨ ∣ˡ (correctW t₁ hyp) ⟩W\n (⟦ t₁ ⟧ ρ >>= k) ∣ (⟦ t₂ ⟧ ρ >>= k) ∎\n\n ∙-correctW :\n ∀ {n} v₁ v₂ {ρ : Env n} {c s} {k : Value → D VM.Value} →\n (∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≈∈W k v) →\n exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s , comp-env ρ ⟩ ≈∈W\n ⟪ v₁ ∙ v₂ ⟫P >>= k\n ∙-correctW (con i) v₂ _ = ⌈ fail ⌉\n ∙-correctW (ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} hyp =\n exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val (ƛ t₁ ρ₁)) ∷ s , comp-env ρ ⟩ ≈∈⟨ later (\n\n exec ⟨ comp t₁ [ ret ] , ret c (comp-env ρ) ∷ s , comp-env (v₂ ∷ ρ₁) ⟩ ≈∈⟨ correct t₁ (λ v → laterˡ (hyp v)) ⟩P\n (⟦ t₁ ⟧ (v₂ ∷ ρ₁) >>= k) ∎) ⟩W\n\n (⟪ ƛ t₁ ρ₁ ∙ v₂ ⟫P >>= k) ∎\n\n whnf : ∀ {x y} → x ≈∈P y → x ≈∈W y\n whnf (x ≈∈⟨ x≈y ⟩P y≅z) = x ≈∈⟨ whnf x≈y ⟩W y≅z\n whnf (correct t hyp) = correctW t hyp\n\n mutual\n\n soundW : ∀ {x y} → x ≈∈W y → x ≈∈ y\n soundW ⌈ x≈y ⌉ = x≈y\n soundW (∣ˡ x≈y₁) = ∣ˡ (soundW x≈y₁)\n soundW (later x≈y) = later (♯ soundP x≈y)\n soundW (laterˡ x≈y) = laterˡ (soundW x≈y)\n\n soundP : ∀ {x y} → x ≈∈P y → x ≈∈ y\n soundP x≈y = soundW (whnf x≈y)\n\ncorrect : ∀ t →\n exec ⟨ comp t [] , [] , [] ⟩ ≈∈\n ⟦ t ⟧ [] >>= λ v → return (comp-val v)\ncorrect t =\n soundP $ Correctness.correct t (λ _ → ⌈ return ⌉)\n where open Correctness\n\n------------------------------------------------------------------------\n-- Type system (following Leroy and Grall)\n\ninfix 4 _⊢_∈_\n\ndata _⊢_∈_ {n} (Γ : Ctxt n) : Tm n → Ty → Set where\n con : ∀ {i} → Γ ⊢ con i ∈ nat\n var : ∀ {x} → Γ ⊢ var x ∈ lookup Γ x\n ƛ : ∀ {t σ τ} (t∈ : ♭ σ ∷ Γ ⊢ t ∈ ♭ τ) → Γ ⊢ ƛ t ∈ σ ⇾ τ\n _·_ : ∀ {t₁ t₂ σ τ} (t₁∈ : Γ ⊢ t₁ ∈ σ ⇾ τ) (t₂∈ : Γ ⊢ t₂ ∈ ♭ σ) →\n Γ ⊢ t₁ · t₂ ∈ ♭ τ\n _∣_ : ∀ {t₁ t₂ σ} (t₁∈ : Γ ⊢ t₁ ∈ σ) (t₂∈ : Γ ⊢ t₂ ∈ σ) →\n Γ ⊢ t₁ ∣ t₂ ∈ σ\n\n-- Ω is well-typed.\n\nΩ-well-typed : (τ : Ty) → [] ⊢ Ω ∈ τ\nΩ-well-typed τ =\n _·_ {σ = ♯ σ} {τ = ♯ τ} (ƛ (var · var)) (ƛ (var · var))\n where σ = ♯ σ ⇾ ♯ τ\n\n-- The call-by-value fix-point combinator is also well-typed.\n\nfix-well-typed :\n ∀ {σ τ} → [] ⊢ Z ∈ ♯ (♯ (σ ⇾ τ) ⇾ ♯ (σ ⇾ τ)) ⇾ ♯ (σ ⇾ τ)\nfix-well-typed =\n ƛ (_·_ {σ = υ} {τ = ♯ _}\n (ƛ (var · ƛ (var · var · var)))\n (ƛ (var · ƛ (var · var · var))))\n where\n υ : ∞ Ty\n υ = ♯ (υ ⇾ ♯ _)\n\n------------------------------------------------------------------------\n-- Type soundness\n\n-- WF-Value, WF-Env and WF-DV specify when a\n-- value/environment/computation is well-formed with respect to a\n-- given context (and type).\n\nmutual\n\n data WF-Value : Ty → Value → Set where\n con : ∀ {i} → WF-Value nat (con i)\n ƛ : ∀ {n Γ σ τ} {t : Tm (1 + n)} {ρ}\n (t∈ : ♭ σ ∷ Γ ⊢ t ∈ ♭ τ) (ρ-wf : WF-Env Γ ρ) →\n WF-Value (σ ⇾ τ) (ƛ t ρ)\n\n infixr 5 _∷_\n\n data WF-Env : ∀ {n} → Ctxt n → Env n → Set where\n [] : WF-Env [] []\n _∷_ : ∀ {n} {Γ : Ctxt n} {ρ σ v}\n (v-wf : WF-Value σ v) (ρ-wf : WF-Env Γ ρ) →\n WF-Env (σ ∷ Γ) (v ∷ ρ)\n\ndata WF-DV (σ : Ty) : D Value → Set where\n return : ∀ {v} (v-wf : WF-Value σ v) → WF-DV σ (return v)\n _∣_ : ∀ {x y}\n (x-wf : WF-DV σ x) (y-wf : WF-DV σ y) → WF-DV σ (x ∣ y)\n later : ∀ {x} (x-wf : ∞ (WF-DV σ (♭ x))) → WF-DV σ (later x)\n\n-- Variables pointing into a well-formed environment refer to\n-- well-formed values.\n\nlookup-wf : ∀ {n Γ ρ} (x : Fin n) → WF-Env Γ ρ →\n WF-Value (lookup Γ x) (lookup ρ x)\nlookup-wf zero (v-wf ∷ ρ-wf) = v-wf\nlookup-wf (suc x) (v-wf ∷ ρ-wf) = lookup-wf x ρ-wf\n\n-- If we can prove WF-DV σ x, then x does not \"go wrong\".\n\ndoes-not-go-wrong : ∀ {σ x} → WF-DV σ x → ¬ now nothing ≈∈ x\ndoes-not-go-wrong (return v-wf) ()\ndoes-not-go-wrong (x-wf ∣ y-wf) (∣ˡ x↯) = does-not-go-wrong x-wf x↯\ndoes-not-go-wrong (x-wf ∣ y-wf) (∣ʳ y↯) = does-not-go-wrong y-wf y↯\ndoes-not-go-wrong (later x-wf) (laterʳ x↯) =\n does-not-go-wrong (♭ x-wf) x↯\n\n-- A variant of WF-DV, used to please the productivity checker.\n\ninfix 3 _⟨_⟩P\ninfixr 2 _≅⟨_⟩P_\n\ndata WF-DVP (σ : Ty) : D Value → Set where\n return : ∀ {v} (v-wf : WF-Value σ v) → WF-DVP σ (return v)\n _∣_ : ∀ {x y} (x-wf : WF-DVP σ x) (y-wf : WF-DVP σ y) →\n WF-DVP σ (x ∣ y)\n later : ∀ {x} (x-wf : ∞ (WF-DVP σ (♭ x))) → WF-DVP σ (later x)\n _>>=-congP_ : ∀ {τ x f}\n (x-wf : WF-DVP τ x)\n (f-wf : ∀ {v} → WF-Value τ v → WF-DVP σ (f v)) →\n WF-DVP σ (x >>= f)\n _≅⟨_⟩P_ : ∀ x {y} (x≅y : x ≅ y) (y-wf : WF-DVP σ y) → WF-DVP σ x\n _⟨_⟩P : ∀ x (x-wf : WF-DVP σ x) → WF-DVP σ x\n\n-- WF-DVP is sound with respect to WF-DV.\n\nprivate\n\n -- WHNFs.\n\n data WF-DVW (σ : Ty) : D Value → Set where\n return : ∀ {v} (v-wf : WF-Value σ v) → WF-DVW σ (return v)\n _∣_ : ∀ {x y} (x-wf : WF-DVW σ x) (y-wf : WF-DVW σ y) →\n WF-DVW σ (x ∣ y)\n later : ∀ {x} (x-wf : WF-DVP σ (♭ x)) → WF-DVW σ (later x)\n\n -- Functions which turn programs into WHNFs.\n\n trans-≅ : ∀ {σ x y} → x ≅ y → WF-DVW σ y → WF-DVW σ x\n trans-≅ fail ()\n trans-≅ return (return v-wf) = return v-wf\n trans-≅ (x₁≅y₁ ∣ x₂≅y₂) (y₁-wf ∣ y₂-wf) = trans-≅ x₁≅y₁ y₁-wf\n ∣ trans-≅ x₂≅y₂ y₂-wf\n trans-≅ (later x≅y) (later y-wf) = later (_ ≅⟨ ♭ x≅y ⟩P y-wf)\n\n mutual\n\n _>>=-congW_ : ∀ {σ τ x f} →\n WF-DVW σ x →\n (∀ {v} → WF-Value σ v → WF-DVP τ (f v)) →\n WF-DVW τ (x >>= f)\n return v-wf >>=-congW f-wf = whnf (f-wf v-wf)\n (x-wf ∣ y-wf) >>=-congW f-wf = (x-wf >>=-congW f-wf)\n ∣ (y-wf >>=-congW f-wf)\n later x-wf >>=-congW f-wf = later (x-wf >>=-congP f-wf)\n\n whnf : ∀ {σ x} → WF-DVP σ x → WF-DVW σ x\n whnf (return v-wf) = return v-wf\n whnf (x-wf ∣ y-wf) = whnf x-wf ∣ whnf y-wf\n whnf (later x-wf) = later (♭ x-wf)\n whnf (x-wf >>=-congP f-wf) = whnf x-wf >>=-congW f-wf\n whnf (_ ≅⟨ x≅y ⟩P y-wf) = trans-≅ x≅y (whnf y-wf)\n whnf (_ ⟨ x-wf ⟩P) = whnf x-wf\n\nsound : ∀ {σ x} → WF-DVP σ x → WF-DV σ x\nsound = λ p → soundW (whnf p)\n where\n soundW : ∀ {σ x} → WF-DVW σ x → WF-DV σ x\n soundW (return v-wf) = return v-wf\n soundW (x-wf ∣ y-wf) = soundW x-wf ∣ soundW y-wf\n soundW (later x-wf) = later (♯ sound x-wf)\n\n-- Well-typed programs do not \"go wrong\".\n\nmutual\n\n ⟦⟧-wf : ∀ {n Γ} (t : Tm n) {σ} → Γ ⊢ t ∈ σ →\n ∀ {ρ} → WF-Env Γ ρ → WF-DVP σ (⟦ t ⟧ ρ)\n ⟦⟧-wf (con i) con ρ-wf = return con\n ⟦⟧-wf (var x) var ρ-wf = return (lookup-wf x ρ-wf)\n ⟦⟧-wf (ƛ t) (ƛ t∈) ρ-wf = return (ƛ t∈ ρ-wf)\n ⟦⟧-wf (t₁ ∣ t₂) (t₁∈ ∣ t₂∈) ρ-wf = ⟦⟧-wf t₁ t₁∈ ρ-wf\n ∣ ⟦⟧-wf t₂ t₂∈ ρ-wf\n ⟦⟧-wf (t₁ · t₂) (t₁∈ · t₂∈) {ρ} ρ-wf =\n ⟦ t₁ · t₂ ⟧ ρ ≅⟨ ·-comp t₁ t₂ ⟩P\n ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ⟨ (⟦⟧-wf t₁ t₁∈ ρ-wf >>=-congP λ f-wf →\n ⟦⟧-wf t₂ t₂∈ ρ-wf >>=-congP λ v-wf →\n ∙-wf f-wf v-wf) ⟩P\n\n ∙-wf : ∀ {σ τ f v} →\n WF-Value (σ ⇾ τ) f → WF-Value (♭ σ) v →\n WF-DVP (♭ τ) ⟪ f ∙ v ⟫P\n ∙-wf (ƛ t₁∈ ρ₁-wf) v₂-wf = later (♯ ⟦⟧-wf _ t₁∈ (v₂-wf ∷ ρ₁-wf))\n\ntype-soundness : ∀ {t : Tm 0} {σ} →\n [] ⊢ t ∈ σ → ¬ now nothing ≈∈ ⟦ t ⟧ []\ntype-soundness t∈ = does-not-go-wrong (sound (⟦⟧-wf _ t∈ []))\n", "meta": {"hexsha": "26cb0aef2d58ff3619bd804bc7bff8e5a7ac1240", "size": 23891, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Lambda/Closure/Functional/Non-deterministic.agda", "max_stars_repo_name": "nad/codata", "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_issues_repo_path": "Lambda/Closure/Functional/Non-deterministic.agda", "max_issues_repo_name": "nad/codata", "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": "Lambda/Closure/Functional/Non-deterministic.agda", "max_forks_repo_name": "nad/codata", "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": 32.8173076923, "max_line_length": 138, "alphanum_fraction": 0.4323803943, "num_tokens": 10909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.658417487156366, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3650730502416665}} {"text": "module WellScopedTermsModel where\n\nopen import Library\nopen import WellScopedTerms\nopen import RMonads\nopen import RMonads.REM\nopen import Categories.Sets\n\n_<<_ : ∀{n}{X : Set} → (Fin n → X) → X → Fin (suc n) → X\n(f << x) zero = x\n(f << x) (suc i) = f i\n\nrecord LambdaModel : Set₁ where\n field S : Set\n Env = λ n → Fin n → S\n field eval : ∀{n} → Env n → Tm n → S\n ap : S → S → S\n lawvar : ∀{n}{i : Fin n}{γ : Env n} →\n eval γ (var i) ≅ γ i\n lawapp : ∀{n}{t u : Tm n}{γ : Env n} → \n eval γ (app t u) ≅ ap (eval γ t) (eval γ u)\n lawlam : ∀{n}{t : Tm (suc n)}{γ : Env n}{s : S} →\n ap (eval γ (lam t)) s ≅ eval (γ << s) t\n lawext : ∀{f g : S} → ((a : S) → ap f a ≅ ap g a) → f ≅ g\n\nmodule Model (l : LambdaModel) where\n open LambdaModel l\n\n wk<< : ∀{m n}(α : Ren m n)(β : Env n)\n (v : S) → (y : Fin (suc m)) → \n ((β ∘ α) << v) y ≅ (β << v) (wk α y)\n wk<< α β v zero = refl\n wk<< α β v (suc i) = refl\n \n reneval : ∀{m n}(α : Ren m n)(β : Env n)\n (t : Tm m) → eval (β ∘ α) t ≅ (eval β ∘ ren α) t\n reneval α β (var i) = \n proof\n eval (β ∘ α) (var i) \n ≅⟨ lawvar ⟩\n β (α i)\n ≅⟨ sym lawvar ⟩\n eval β (var (α i)) ∎\n reneval α β (lam t) = lawext λ a → \n proof\n ap (eval (β ∘ α) (lam t)) a \n ≅⟨ lawlam ⟩\n eval ((β ∘ α) << a) t\n ≅⟨ cong (λ (f : Env _) → eval f t) (ext (wk<< α β a)) ⟩\n eval ((β << a) ∘ wk α) t\n ≅⟨ reneval (wk α) (β << a) t ⟩\n eval (β << a) (ren (wk α) t)\n ≅⟨ sym lawlam ⟩\n ap (eval β (lam (ren (wk α) t))) a \n ∎\n reneval α β (app t u) = \n proof\n eval (β ∘ α) (app t u) \n ≅⟨ lawapp ⟩\n ap (eval (β ∘ α) t) (eval (β ∘ α) u)\n ≅⟨ cong₂ ap (reneval α β t) (reneval α β u) ⟩\n ap (eval β (ren α t)) (eval β (ren α u))\n ≅⟨ sym lawapp ⟩\n eval β (app (ren α t) (ren α u))\n ∎\n \n lift<< : ∀{m n}(γ : Sub m n)(α : Env n)\n (a : S)(i : Fin (suc m)) → \n ((eval α ∘ γ ) << a) i ≅ (eval (α << a) ∘ lift γ) i\n lift<< γ α a zero = \n proof \n a \n ≅⟨ sym lawvar ⟩ \n eval (α << a) (var zero)\n ∎\n lift<< γ α a (suc i) = \n proof\n eval α (γ i)\n ≡⟨⟩\n eval ((α << a) ∘ suc) (γ i)\n ≅⟨ reneval suc (α << a) (γ i) ⟩\n eval (α << a) (ren suc (γ i))\n ∎\n \n subeval : ∀{m n}(t : Tm m)(γ : Sub m n)(α : Env n) → \n eval (eval α ∘ γ) t ≅ (eval α ∘ sub γ) t\n subeval (var i) γ α = \n proof\n eval (eval α ∘ γ) (var i) \n ≅⟨ lawvar ⟩\n eval α (γ i)\n ∎\n subeval (lam t) γ α = lawext λ a → \n proof\n ap (eval (eval α ∘ γ) (lam t)) a\n ≅⟨ lawlam ⟩\n eval ((eval α ∘ γ) << a) t\n ≅⟨ cong (λ (f : Env _) → eval f t) (ext (lift<< γ α a)) ⟩\n eval (eval (α << a) ∘ lift γ) t\n ≅⟨ subeval t (lift γ) (α << a) ⟩\n eval (α << a) (sub (lift γ) t) \n ≅⟨ sym lawlam ⟩\n ap (eval α (lam (sub (lift γ) t))) a \n ∎\n subeval (app t u) γ α = \n proof\n eval (eval α ∘ γ) (app t u) \n ≅⟨ lawapp ⟩\n ap (eval (eval α ∘ γ) t) (eval (eval α ∘ γ) u)\n ≅⟨ cong₂ ap (subeval t γ α) (subeval u γ α) ⟩\n ap (eval α (sub γ t)) (eval α (sub γ u))\n ≅⟨ sym lawapp ⟩\n eval α (app (sub γ t) (sub γ u)) \n ∎\n\n TmRAlg : RAlg TmRMonad\n TmRAlg = record{\n acar = S;\n astr = eval;\n alaw1 = ext λ _ → sym lawvar;\n alaw2 = ext λ t → subeval t _ _} \n \n\nmodule VEnv where\n open import Delay\n open import Size\n \n mutual\n Env : ℕ → Set\n Env n = Fin n → Val\n \n data Val : Set where\n clo : ∀{n} → Env n → Tm (suc n) → Val\n \n \n -- the RAlg is expecting a env containing 'values' here the values\n -- evaluator takes an env of undelayed values and makes a delayed\n -- values.\n mutual\n ev : ∀{i n} → Env n → Tm n → Delay Val i\n ev γ (var x) = now (γ x)\n ev γ (lam t) = now (clo γ t)\n ev γ (app t u) = ev γ t >>= λ f → ev γ u >>= λ v → f $$ v\n \n _∞$$_ : ∀{i} → Val → Val → ∞Delay Val i\n force (clo γ t ∞$$ v) = ev (γ << v) t \n \n _$$_ : ∀{i} → Val → Val → Delay Val i\n f $$ v = later (f ∞$$ v)\n\nmodule FusedVals where\n open import Size\n mutual\n data Env (i : Size) : (n : ℕ) → Set where\n ε : Env i zero\n _,_ : ∀ {n} (ρ : Env i n) (v : Val i) → Env i (suc n)\n\n data Val (i : Size) : Set where\n lam : forall {n} (t : Tm (suc n)) (ρ : Env i n) → Val i \n later : (v∞ : ∞Val i) → Val i\n \n record ∞Val (i : Size) : Set where\n coinductive\n constructor ∞val\n field\n vforce : {j : Size< i} → Val j\n\n open ∞Val\n\n lookup : ∀{i n} -> Env i n -> Fin n -> Val i\n lookup (ρ , v) zero = v\n lookup (ρ , v) (suc i) = lookup ρ i\n\n tabulate : ∀{i n} -> (Fin n -> Val i) -> Env i n\n tabulate {n = zero} f = ε\n tabulate {n = suc n} f = (tabulate {n = n} (f ∘ suc)) , f zero\n\n mutual\n ev : ∀{i n} -> Env i n -> Tm n -> Val i\n ev ρ (var x) = lookup ρ x\n ev ρ (lam t) = lam t ρ\n ev ρ (app t u) = ev ρ t $$ ev ρ u\n \n _$$_ : ∀{i} → Val i → Val i → Val i\n f $$ v = later (f ∞$$ v)\n \n _∞$$_ : ∀{i} → Val i → Val i → ∞Val i\n vforce (lam t ρ ∞$$ v) = ev (ρ , v) t \n vforce (later p ∞$$ v) = later (vforce p ∞$$ v) \n\n{-\n FRAlg : ∀ {i} -> RAlg TmRMonad\n FRAlg {i} = ralg\n (Val i)\n (ev ∘ tabulate)\n {!!}\n {!!}\n-}\n", "meta": {"hexsha": "51782875136185c20ba23533438822bef87ef0e7", "size": 5273, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "WellScopedTermsModel.agda", "max_stars_repo_name": "jmchapman/Relative-Monads", "max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z", "max_issues_repo_path": "WellScopedTermsModel.agda", "max_issues_repo_name": "jmchapman/Relative-Monads", "max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z", "max_forks_repo_path": "WellScopedTermsModel.agda", "max_forks_repo_name": "jmchapman/Relative-Monads", "max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z", "avg_line_length": 26.4974874372, "max_line_length": 68, "alphanum_fraction": 0.4452873127, "num_tokens": 2262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300573952054, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.3649793441290369}} {"text": "open import Relation.Binary using (Decidable; DecSetoid)\nopen import Level \n\n\nmodule CP.Session2 {a} (ChanSetoid : DecSetoid zero a) (Type : Set) where \n\nChan : Set\nChan = DecSetoid.Carrier ChanSetoid\n\n_≟Chan_ = DecSetoid._≟_ ChanSetoid\n_≈Chan_ = DecSetoid._≈_ ChanSetoid\n_≉Chan_ = DecSetoid._≉_ ChanSetoid\n\ninfixl 5 _,_∶_ \ndata Session : Set a where \n _,_∶_ : Session → Chan → Type → Session\n _++_ : Session → Session → Session\n ∅ : Session\n\n\n-- open import Data.Bool hiding (_≟_)\n\n-- open import Data.Empty \n-- open import Data.Unit \nopen import Relation.Nullary\nopen import Relation.Nullary.Decidable\n\n-- open import Relation.Binary.PropositionalEquality\n\n\ninfix 4 _∋_\ndata _∋_ : (Γ : Session) → (x : Chan) → Set a where\n here : ∀ {Γ x y A} → x ≈Chan y → Γ , y ∶ A ∋ x\n there : ∀ {Γ x y A} → Γ ∋ x → Γ , y ∶ A ∋ x\n left : ∀ {Γ Δ x} → Γ ∋ x → Γ ++ Δ ∋ x\n right : ∀ {Γ Δ x} → Δ ∋ x → Γ ++ Δ ∋ x\n\ninfix 4 _∋?_\n_∋?_ : (Γ : Session) → (x : Chan) → Dec (Γ ∋ x)\nΓ , y ∶ A ∋? x with x ≟Chan y\n... | yes x≈y = yes (here x≈y)\n... | no ¬x≈y with Γ ∋? x\n... | yes Γ∋x = yes (there Γ∋x)\n... | no ¬Γ∋x = no (λ where (here x≈y) → ¬x≈y x≈y\n (there Γ∋x) → ¬Γ∋x Γ∋x)\n(Γ ++ Δ) ∋? x with Γ ∋? x \n... | yes Γ∋x = yes (left Γ∋x)\n... | no ¬Γ∋x with Δ ∋? x \n... | yes Δ∋x = yes (right Δ∋x)\n... | no ¬Δ∋x = no (λ where (left Γ∋x) → ¬Γ∋x Γ∋x\n (right Δ∋x) → ¬Δ∋x Δ∋x)\n∅ ∋? x = no (λ ())\n\nopen import Data.Product\nopen import Data.Empty using (⊥-elim)\n\ninfix 4 _≈_\n_≈_ : Session → Session → Set a\nΓ ≈ Δ = (∀ x → Γ ∋ x → Δ ∋ x) × (∀ x → Δ ∋ x → Γ ∋ x)\n\n∅∌x : ∀ {x} → ¬ ∅ ∋ x\n∅∌x ()\n\nopen DecSetoid ChanSetoid hiding (_≈_)\n\n∅-empty : ∀ {Δ x A} → ¬ ∅ ≈ Δ , x ∶ A\n∅-empty {Δ} {x} (P , Q) = ∅∌x (Q x (here refl))\n\n<<<<<<< HEAD\nswap : ∀ {Γ x y A B} → Γ , x ∶ A , y ∶ B ≈ Γ , y ∶ B , x ∶ A\nswap {Γ} {x} {y} {A} {B} = to , from\n where \n to : ∀ v → Γ , x ∶ A , y ∶ B ∋ v → Γ , y ∶ B , x ∶ A ∋ v\n to v (here P) = there (here P)\n to v (there (here P)) = here P\n to v (there (there P)) = there (there P)\n\n from : ∀ v → Γ , y ∶ B , x ∶ A ∋ v → Γ , x ∶ A , y ∶ B ∋ v\n from v (here P) = there (here P)\n from v (there (here P)) = here P\n from v (there (there P)) = there (there P)\n\n-- contract : ∀ {Γ x y A B} → → Γ , x ∶ A ≈ Γ\n-- contract\n-- strengthen : ∀ {Γ x A v} → Γ , x ∶ A ∋ v → x ≉ v → Γ ∋ v\n-- strengthen (here x≈v) x≉v = ⊥-elim (x≉v (sym x≈v))\n-- strengthen (there P) x≉v = P\n=======\n>>>>>>> 40f82fd098a0c30c87ea0056baa48152aefae1f6\n\nlookup : (Γ : Session) (x : Chan) → Dec (∃[ Δ ] ∃[ A ] (Γ ≈ (Δ , x ∶ A)))\nlookup (Γ , y ∶ A) x with x ≟Chan y\n... | yes x≈y = yes (Γ , A , (λ where v (here v≈y) → here (trans v≈y (sym x≈y))\n v (there Γ∷y∋v) → there Γ∷y∋v) \n , λ where v (here v≈x) → here (trans v≈x x≈y)\n v (there Γ∷x∋v) → there Γ∷x∋v)\n... | no ¬x≈y with lookup Γ x \n... | yes (Δ , B , Γ≈Δ,x∶B) = yes (Δ , y ∶ A , B , (λ where v (here v≈y) → there (here v≈y)\n<<<<<<< HEAD\n v (there Γ∋v) → proj₁ swap v (there (proj₁ Γ≈Δ,x∶B v Γ∋v))) \n , λ where v (here v≈x) → there (proj₂ Γ≈Δ,x∶B v (here v≈x))\n v (there (here v≈y)) → here v≈y\n v (there (there Δ∋v)) → there (proj₂ Γ≈Δ,x∶B v (there Δ∋v)))\n... | no ¬P = no (λ (Δ , B , Q) → ¬P (Δ , B , {! !}))\n -- (λ where v P → proj₁ Q v (there P)) \n -- , (λ where v P → {! proj₂ Q v P !})))\n=======\n v (there Γ∋v) → {! !}) , {! !})\n... | no P = {! !}\n>>>>>>> 40f82fd098a0c30c87ea0056baa48152aefae1f6\nlookup (Γ ++ Δ) x = {! !}\nlookup ∅ x = no (λ where (Δ , A , P) → ∅-empty P)\n\n-- ... | yes x≈y = yes (Γ , A , λ v → (λ where (here v≈y) → here (trans v≈y (sym x≈y))\n-- (there Γ∋v) → there Γ∋v) -- (λ v≈x → v≉y (trans v≈x x≈y))\n-- , λ where (here v≈x) → here (trans v≈x x≈y)\n-- (there Γ∋v) → there Γ∋v) -- (λ v≈y → v≉x (trans v≈y (sym x≈y))) \n-- ... | no ¬x≈y with lookup Γ x \n-- ... | yes (Δ , B , Γ≈Δ,x∶B) = yes (Δ , y ∶ A , B , λ v → (λ where (here v≈y) → there (here v≈y) -- (λ v≈x → ¬x≈y (trans (sym v≈x) v≈y)) \n-- (there Γ∋v) → lemma-1 (proj₁ (Γ≈Δ,x∶B v) Γ∋v)) \n-- , λ where (here v≈x) → there (proj₂ (Γ≈Δ,x∶B v) (here v≈x)) -- (λ v≈y → ¬x≈y (trans (sym v≈x) v≈y))\n-- (there Δ,y∶A∋y) → ,-weakening y A (proj₂ (Γ≈Δ,x∶B v)) (lemma-1 Δ,y∶A∋y))\n-- where \n-- lemma-1 : ∀ {Γ x y z A B} → Γ , x ∶ A ∋ z → Γ , y ∶ B , x ∶ A ∋ z\n-- lemma-1 (here z≈x) = here z≈x\n-- lemma-1 (there Γ∋z) = there (there Γ∋z)\n\n-- ,-weakening : ∀ {Γ Δ v} x A → (Γ ∋ v → Δ ∋ v) → (Γ , x ∶ A ∋ v → Δ , x ∶ A ∋ v)\n-- ,-weakening x A f (here v≈x) = here v≈x\n-- ,-weakening x A f (there Γ∋v) = there (f Γ∋v)\n\n-- ... | no ¬P = no λ Q → {! !}\n\n-- -- GOAL : Γ , y ∶ A ≉ CTX , x ∶ TYPE\n-- -- ¬P Γ ≉ CTX , x : TYPE \n\n\n\n-- -- no (λ (Δ , B , Q) → ¬P (Δ , B , {! Q !}))\n-- -- λ v → (λ Γ∋v → proj₁ (Q v) (there Γ∋v)) \n-- -- , (λ Δ,x∶B∋v → {! proj₂ (Q v) Δ,x∶B∋v !})))\n-- -- → (λ Γ∋v → proj₁ (Q v) (there Γ∋v)) \n-- -- , λ Δ,x∶B∋v → {! (proj₂ (Q v) Δ,x∶B∋v) !}))\n-- -- where \n-- -- (here P) → strengthen (proj₂ (Q v) (here P)) (λ y≈v → ¬x≈y (sym (trans y≈v P)))\n-- -- (there P) → {! !}))\n \n-- where \n\n-- -- GOAL : Δ , x ∶ B → Γ\n\n-- -- Q v : Δ , x ∶ B <≈> Γ , y ∶ A \n\n-- -- -- ¬P Δ A = Γ <=> Δ , x ∶ A \n-- -- (x₁ : Carrier) →\n-- -- Σ (Γ ∋ x₁ → Δ₁ , x ∶ A₁ ∋ x₁) (λ x₂ → Δ₁ , x ∶ A₁ ∋ x₁ → Γ ∋ x₁)))\n\n-- strengthen : ∀ {Γ x A v} → Γ , x ∶ A ∋ v → x ≉ v → Γ ∋ v\n-- strengthen (here x≈v) x≉v = ⊥-elim (x≉v (sym x≈v))\n-- strengthen (there P) x≉v = P\n\n-- temp : ∀ Δ B v → (Δ ∋ v) → (f : Δ , x ∶ B ∋ v → Γ , y ∶ A ∋ v) → Γ ∋ v\n-- temp Δ B v Δ∋v f with v ≟Chan x\n-- ... | yes v≈x = strengthen (f (here v≈x)) (λ y≈v → ¬x≈y (sym (trans y≈v v≈x)))\n-- ... | no ¬v≈x with y ≟Chan v\n-- ... | yes y≈v = {! !}\n-- ... | no ¬y≈v = strengthen (f (there Δ∋v)) ¬y≈v\n-- -- strengthen (f (there Δ∈v)) λ y≈v → {! !}\n\n-- -- lemma : G \n\n-- lookup (Γ ++ Δ) x = {! !}\n-- lookup ∅ x = no (λ where (Δ , A , P) → ∅-empty P)\n\n-- -- _≈?_ : (Γ Δ : Session) → Dec (Γ ≈ Δ)\n-- -- Γ ≈? Δ = {! !}\n-- -- empty : ∀ {Γ x A} → ¬ (∅ ≈ (Γ , x ∶ A))\n-- -- empty {Γ} {x} {A} P with x ≟ x\n-- -- ... | no ¬p = {! !}\n-- -- ... | yes p = {! !}\n\n-- -- lookup : (Γ : Session) (x : Chan) → Dec (∃[ Δ ] ∃[ A ] (Γ ≈ (Δ , x ∶ A)))\n-- -- lookup (Γ , y ∶ A) x = {! !}\n-- -- lookup (Γ ++ Δ) x with lookup Γ x \n-- -- ... | yes p = {! !}\n-- -- ... | no ¬p = {! !}\n-- -- lookup ∅ x = no (λ where (Γ , A , P) → {! P x !})\n\n", "meta": {"hexsha": "c5262ec7cd33f3941acd848db7f1410d80aff130", "size": 7518, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "CP/Session2.agda", "max_stars_repo_name": "banacorn/bidirectional", "max_stars_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-25T07:34:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-25T14:05:01.000Z", "max_issues_repo_path": "CP/Session2.agda", "max_issues_repo_name": "banacorn/bidirectional", "max_issues_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "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": "CP/Session2.agda", "max_forks_repo_name": "banacorn/bidirectional", "max_forks_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "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.7777777778, "max_line_length": 158, "alphanum_fraction": 0.3733705773, "num_tokens": 3176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7025300573952054, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.3649793441290369}} {"text": "module Issue553a where\n\ndata D : Set where\n d₁ d₂ : D\n\ndata E : Set where\n\nmodule M (A : Set) where\n\n data B : Set where\n b : D → B\n\n T : B → Set\n T (b d₁) = E\n T (b d₂) = E\n\nopen M E\n\ng : (d : D) → T (b d) → D\ng d t with d₁\ng d t | d′ = d′ -- Unsolved meta-variable, no constraints.\n", "meta": {"hexsha": "5d1d1184631adafe86be937b42b929e1a8d83d6f", "size": 293, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue553a.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/Succeed/Issue553a.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/Succeed/Issue553a.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": 13.3181818182, "max_line_length": 59, "alphanum_fraction": 0.5392491468, "num_tokens": 122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7122321964553657, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.36446104133112983}} {"text": "{-# OPTIONS --cubical --safe --guardedness #-}\n\nmodule Data.PolyP.RecursionSchemes where\n\nopen import Function hiding (_⟨_⟩_)\nopen import Data.Sum\nopen import Data.Sigma\nopen import Level\nopen import Data.Unit\nopen import Data.Nat\nopen import Data.Vec.Iterated\nopen import Data.Empty\nopen import WellFounded\nopen import Literals.Number\nopen import Data.Fin.Indexed.Literals\nopen import Data.Fin.Indexed.Properties\nopen import Data.Fin.Indexed\nopen import Data.Nat.Literals\nopen import Data.Maybe\nopen import Path\n\nopen import Data.PolyP.Universe\n\n---------------------------------------------------------------------------------\n--\n-- Helpers for Termination\n--\n---------------------------------------------------------------------------------\n\n-- This is just the identity type. We need to use it because, if --without-K is\n-- turned on, Agda will only use an argument to a function to prove structural\n-- descent if that argument is a concrete data type.\n--\n-- wont-pass : (x : Bool) → (if x then ℕ else ℕ) → ℕ\n-- wont-pass false zero = zero\n-- wont-pass false (suc n) = wont-pass true n\n-- wont-pass true zero = zero\n-- wont-pass true (suc n) = wont-pass false n\n--\n-- Even though we're clearly structurally descending on the second argument\n-- there, Agda won't use it unless we make it concrete, like so:\n--\n-- will-pass : (x : Bool) → → ℕ\n-- will-pass false [! zero !] = zero\n-- will-pass false [! suc n !] = will-pass true [! n !]\n-- will-pass true [! zero !] = zero\n-- will-pass true [! suc n !] = will-pass false [! n !]\nrecord (A : Type) : Type where\n eta-equality\n constructor [!_!]\n field !! : A\nopen \n\n-- For the map and cata functions to be structurally\n-- terminating, we can't do things like:\n--\n-- cata f = f ∘ fmap (cata f) ∘ unwrap\n--\n-- So instead we need to carry a stack of all of the functors\n-- we're under at any given point, and pattern match on that to\n-- tell whether we should do f or fmap f.\n\ndata Layers (n : ℕ) : ℕ → Type₁ where\n [] : Layers n n\n _∷_ : Functor (1 + m) →\n Layers n m →\n Layers n (1 + m)\n\n_++∙_ : Layers n m → Params n → Params m\n[] ++∙ ys = ys\n(x ∷ xs) ++∙ ys = let zs = xs ++∙ ys in μ x zs ∷ zs\ninfixr 5 _∷_ _++∙_\n\n---------------------------------------------------------------------------------\n--\n-- Mapping\n--\n---------------------------------------------------------------------------------\n\nmodule Mapping {m} {As Bs : Params m} (f : (i : Fin m) → As [ i ] → Bs [ i ]) where\n mapRec : ∀ (F : Functor n) (Fs : Layers m n) →\n → ⟦ F ⟧ (Fs ++∙ Bs)\n mapRec (F ⊕ G) Fs [! inl x !] = inl (mapRec F Fs [! x !])\n mapRec (F ⊕ G) Fs [! inr x !] = inr (mapRec G Fs [! x !])\n mapRec (F ⊗ G) Fs [! x , y !] = mapRec F Fs [! x !] , mapRec G Fs [! y !]\n mapRec μ⟨ F ⟩ Fs [! ⟨ xs ⟩ !] = ⟨ mapRec F (F ∷ Fs) [! xs !] ⟩\n mapRec (! i ) [] [! xs !] = f i xs\n mapRec (! f0 ) (F ∷ Fs) [! ⟨ xs ⟩ !] = ⟨ mapRec F (F ∷ Fs) [! xs !] ⟩\n mapRec (! (fs i)) (F ∷ Fs) [! xs !] = mapRec (! i) Fs [! xs !]\n mapRec ① Fs _ = tt\n\nmapParamAt : (i : Fin n) → (As [ i ] → A) → (j : Fin n) → As [ j ] → As [ i ]≔ A [ j ]\nmapParamAt f0 f f0 x = f x\nmapParamAt f0 f (fs _) x = x\nmapParamAt (fs _) f f0 x = x\nmapParamAt (fs i) f (fs j) x = mapParamAt i f j x\n\nmap : ∀ F → (i : Fin n) → (As [ i ] → A) → ⟦ F ⟧ As → ⟦ F ⟧ (As [ i ]≔ A)\nmap F i f xs = Mapping.mapRec (mapParamAt i f) F [] [! xs !]\n\nmodule MapComp\n {m} {As Bs Cs : Params m}\n (f : (i : Fin m) → Bs [ i ] → Cs [ i ])\n (g : (i : Fin m) → As [ i ] → Bs [ i ])\n where\n open Mapping\n\n mapComp : ∀ (F : Functor n) (Fs : Layers m n) (xs : ) →\n mapRec f F Fs [! mapRec g F Fs xs !] ≡ mapRec (λ i → f i ∘ g i) F Fs xs\n mapComp (F ⊕ G) Fs [! inl x !] = cong inl (mapComp F Fs [! x !])\n mapComp (F ⊕ G) Fs [! inr x !] = cong inr (mapComp G Fs [! x !])\n mapComp (F ⊗ G) Fs [! x , y !] = cong₂ _,_ (mapComp F Fs [! x !]) (mapComp G Fs [! y !])\n mapComp μ⟨ F ⟩ Fs [! ⟨ x ⟩ !] = cong ⟨_⟩ (mapComp F (F ∷ Fs) [! x !])\n mapComp (! i) [] [! xs !] = refl\n mapComp (! f0) (F ∷ Fs) [! ⟨ x ⟩ !] = cong ⟨_⟩ (mapComp F (F ∷ Fs) [! x !])\n mapComp (! (fs i)) (F ∷ Fs) [! xs !] = mapComp (! i) Fs [! xs !]\n mapComp ① Fs xs = refl\n\nmap-comp : ∀ (F : Functor (suc n)) → (f : B → C) → (g : A → B) → (x : ⟦ F ⟧ (A ∷ As)) →\n map F f0 f (map F f0 g x) ≡ map F f0 (f ∘ g) x\nmap-comp F f g x =\n MapComp.mapComp (mapParamAt f0 f) (mapParamAt f0 g) F [] [! x !] ;\n cong (λ c → Mapping.mapRec c F [] [! x !])\n (funExt λ { f0 → refl ; (fs x) → refl } )\n\nmodule MapId {m} {As : Params m}\n where\n open Mapping {m = m} {As = As} {Bs = As}\n\n mapId : ∀ (F : Functor n) (Fs : Layers m n) (xs : ) →\n mapRec (λ _ x → x) F Fs xs ≡ xs .!!\n mapId (F ⊕ G) Fs [! inl x !] = cong inl (mapId F Fs [! x !])\n mapId (F ⊕ G) Fs [! inr x !] = cong inr (mapId G Fs [! x !])\n mapId (F ⊗ G) Fs [! x , y !] = cong₂ _,_ (mapId F Fs [! x !]) (mapId G Fs [! y !])\n mapId μ⟨ F ⟩ Fs [! ⟨ x ⟩ !] = cong ⟨_⟩ (mapId F (F ∷ Fs) [! x !])\n mapId (! i) [] [! xs !] = refl\n mapId (! f0) (F ∷ Fs) [! ⟨ x ⟩ !] = cong ⟨_⟩ (mapId F (F ∷ Fs) [! x !])\n mapId (! (fs i)) (F ∷ Fs) [! xs !] = mapId (! i) Fs [! xs !]\n mapId ① Fs xs = refl\n\nmap-id : (F : Functor (suc n)) → (x : ⟦ F ⟧ (A ∷ As)) → map F f0 id x ≡ x\nmap-id F x =\n cong\n (λ c → Mapping.mapRec c F [] [! x !])\n (funExt (λ { f0 → refl ; (fs i) → refl})) ;\n MapId.mapId F [] [! x !]\n\n---------------------------------------------------------------------------------\n--\n-- Categorical\n--\n---------------------------------------------------------------------------------\nmodule Categorical (F : Functor (suc n)) (As : Params n) where\n infix 4 _≗_\n _≗_ : (A → B) → (A → B) → Set _\n f ≗ g = ∀ x → f x ≡ g x\n {-# INLINE _≗_ #-}\n\n Alg : Type₁\n Alg = Σ[ A ⦂ Type ] × (⟦ F ⟧ (A ∷ As) → A)\n\n -- Hom\n _⟶_ : Alg → Alg → Type\n (A , a) ⟶ (B , b) = Σ[ h ⦂ (A → B) ] × (h ∘ a ≗ b ∘ map F f0 h)\n\n variable\n X Y Z : Alg\n\n _∙_ : (Y ⟶ Z) → (X ⟶ Y) → (X ⟶ Z)\n (f ∙ g) .fst = f .fst ∘ g .fst\n _∙_ {Y = Y} {Z = Z} {X = X} f g .snd x =\n cong (f .fst) (g .snd x) ;\n f .snd (map F f0 (g .fst) x) ;\n cong (Z .snd) (map-comp F (f .fst) (g .fst) x)\n\n\n id′ : X ⟶ X\n id′ .fst = id\n id′ {X = X} .snd x = cong (X .snd) (sym (map-id F x))\n\n---------------------------------------------------------------------------------\n--\n-- Catamorphisms\n--\n---------------------------------------------------------------------------------\n\n\nmodule Cata {k} {F : Functor (suc k)} {As : Params k} (alg : ⟦ F ⟧ (A ∷ As) → A) where\n cataRec : (G : Functor n) (Gs : Layers (suc m) n) →\n → ⟦ G ⟧ (Gs ++∙ A ∷ Bs)\n cataRec (G₁ ⊕ G₂) Gs [! inl x !] = inl (cataRec G₁ Gs [! x !])\n cataRec (G₁ ⊕ G₂) Gs [! inr x !] = inr (cataRec G₂ Gs [! x !])\n cataRec (G₁ ⊗ G₂) Gs [! x , y !] = cataRec G₁ Gs [! x !] , cataRec G₂ Gs [! y !]\n cataRec μ⟨ G ⟩ Gs [! ⟨ x ⟩ !] = ⟨ cataRec G (G ∷ Gs) [! x !] ⟩\n cataRec (! f0 ) [] [! ⟨ x ⟩ !] = alg (cataRec F [] [! x !])\n cataRec (! (fs i)) [] [! x !] = x\n cataRec (! (fs i)) (G ∷ Gs) [! x !] = cataRec (! i) Gs [! x !]\n cataRec (! f0 ) (G ∷ Gs) [! ⟨ x ⟩ !] = ⟨ cataRec G (G ∷ Gs) [! x !] ⟩\n cataRec ① Gs [! _ !] = tt\n\nmodule _ {F : Functor (suc n)} {As : Params n} where\n cata : (⟦ F ⟧ (A ∷ As) → A) → μ F As → A\n cata alg xs = Cata.cataRec alg {Bs = As} (! f0) [] [! xs !]\n\n\nmodule CataId {k} {F : Functor (suc k)} {As : Params k} where\n cataRecId : (G : Functor n) (Gs : Layers (suc m) n) →\n (x : ) → Cata.cataRec ⟨_⟩ G Gs x ≡ !! x\n cataRecId (G₁ ⊕ G₂) Gs [! inl x !] = cong inl (cataRecId G₁ Gs [! x !])\n cataRecId (G₁ ⊕ G₂) Gs [! inr x !] = cong inr (cataRecId G₂ Gs [! x !])\n cataRecId (G₁ ⊗ G₂) Gs [! x , y !] = cong₂ _,_ (cataRecId G₁ Gs [! x !]) (cataRecId G₂ Gs [! y !])\n cataRecId μ⟨ G ⟩ Gs [! ⟨ x ⟩ !] = cong ⟨_⟩ (cataRecId G (G ∷ Gs) [! x !])\n cataRecId (! f0 ) [] [! ⟨ x ⟩ !] = cong ⟨_⟩ (cataRecId F [] [! x !])\n cataRecId (! (fs i)) [] [! x !] = refl\n cataRecId (! (fs i)) (G ∷ Gs) [! x !] = cataRecId (! i) Gs [! x !]\n cataRecId (! f0 ) (G ∷ Gs) [! ⟨ x ⟩ !] = cong ⟨_⟩ ( cataRecId G (G ∷ Gs) [! x !] )\n cataRecId ① Gs [! _ !] = refl\n\nmodule _ {F : Functor (suc n)} {As : Params n} where\n cataId : (x : μ F As) → cata ⟨_⟩ x ≡ x\n cataId x = CataId.cataRecId (! f0) [] [! x !]\n---------------------------------------------------------------------------------\n--\n-- Eliminators\n--\n---------------------------------------------------------------------------------\n\nmodule Eliminator {As : Params k}\n {F : Functor (suc k)}\n (P : μ F As → Type)\n (f : (x : ⟦ F ⟧ ((∃ x × P x) ∷ As)) → P ⟨ map F f0 fst x ⟩)\n where\n open import Path\n open Mapping\n open Cata\n\n alg : ⟦ F ⟧ ((∃ x × P x) ∷ As) → ∃ x × P x\n alg x = ⟨ map F f0 fst x ⟩ , f x\n\n mutual\n elimRec : (G : Functor n) (Gs : Layers (suc m) n) →\n (x : ) →\n mapRec (mapParamAt f0 fst) G Gs [! cataRec alg G Gs x !] ≡ !! x\n elimRec (G₁ ⊕ G₂) Gs [! inl x !] = cong inl (elimRec G₁ Gs [! x !])\n elimRec (G₁ ⊕ G₂) Gs [! inr x !] = cong inr (elimRec G₂ Gs [! x !])\n elimRec (G₁ ⊗ G₂) Gs [! x , y !] = cong₂ _,_ (elimRec G₁ Gs [! x !]) (elimRec G₂ Gs [! y !])\n elimRec μ⟨ G ⟩ Gs [! ⟨ x ⟩ !] = cong ⟨_⟩ (elimRec G (G ∷ Gs) [! x !])\n elimRec (! f0 ) [] [! ⟨ x ⟩ !] = cong ⟨_⟩ (elimRec F [] [! x !])\n elimRec (! (fs i)) [] [! x !] = refl\n elimRec (! (fs i)) (G ∷ Gs) [! x !] = elimRec (! i) Gs [! x !]\n elimRec (! f0 ) (G ∷ Gs) [! ⟨ x ⟩ !] = cong ⟨_⟩ (elimRec G (G ∷ Gs) [! x !])\n elimRec ① Gs [! _ !] = refl\n\n elim : ∀ x → P x\n elim x = subst P (elimRec {Bs = As} (! f0) [] [! x !]) (snd (cata alg x))\n\nmodule _ {F : Functor (suc n)} where\n elim : (P : μ F As → Type) →\n ((x : ⟦ F ⟧ ((∃ x × P x) ∷ As)) → P ⟨ map F f0 fst x ⟩) →\n (x : μ F As) → P x\n elim = Eliminator.elim\n\nmodule AlgIsomorphism {F : Functor (suc n)} {As : Params n} where\n Alg : Type → Type\n Alg A = ⟦ F ⟧ (A ∷ As) → A\n\n AsAlg : Type₁\n AsAlg = ∀ A → Alg A → A\n\n open import Function.Isomorphism\n\n toAlg : μ F As → AsAlg\n toAlg xs A alg = cata alg xs\n {-# INLINE toAlg #-}\n\n fromAlg : AsAlg → μ F As\n fromAlg f = f _ ⟨_⟩\n {-# INLINE fromAlg #-}\n\n\n rinv : (x : μ F As) → fromAlg (toAlg x) ≡ x\n rinv = cataId\n\n -- think you need parametricity for this\n -- linv : (x : AsAlg) (A : Type) (alg : Alg A) → toAlg (fromAlg x) A alg ≡ x A alg\n -- linv x A alg = {!!}\n\n -- isom : AsAlg ⇔ μ F As\n -- isom .fun = fromAlg\n -- isom .inv = toAlg\n -- isom .rightInv = rinv\n -- isom .leftInv x = funExt λ A → funExt λ alg → linv x A alg\n\n---------------------------------------------------------------------------------\n--\n-- Anamorphisms\n--\n---------------------------------------------------------------------------------\n\n\n-- Coinductive fixpoint\nrecord ν (F : Functor (suc n)) (As : Params n) : Type where\n coinductive; constructor ⟪_⟫\n field unfold : ⟦ F ⟧ (ν F As ∷ As)\nopen ν public\n\n-- The \"proper\" anamorphism, which is coinductive.\nmodule AnaInf {k} {F : Functor (suc k)} {As : Params k} (coalg : A → ⟦ F ⟧ (A ∷ As)) where\n mutual\n anaRec : (G : Functor n) (Gs : Layers (suc m) n) →\n \n anaRec (G₁ ⊕ G₂) Gs [! inl x !] .!! = inl (anaRec G₁ Gs [! x !] .!!)\n anaRec (G₁ ⊕ G₂) Gs [! inr x !] .!! = inr (anaRec G₂ Gs [! x !] .!!)\n anaRec (G₁ ⊗ G₂) Gs [! x , y !] .!! .fst = anaRec G₁ Gs [! x !] .!!\n anaRec (G₁ ⊗ G₂) Gs [! x , y !] .!! .snd = anaRec G₂ Gs [! y !] .!!\n anaRec μ⟨ G ⟩ Gs [! ⟨ x ⟩ !] .!! = ⟨ anaRec G (G ∷ Gs) [! x !] .!! ⟩\n anaRec (! f0 ) [] [! x !] .!! = ana x\n anaRec (! (fs i)) [] [! x !] .!! = x\n anaRec (! (fs i)) (G ∷ Gs) [! x !] .!! = anaRec (! i) Gs [! x !] .!!\n anaRec (! f0 ) (G ∷ Gs) [! ⟨ x ⟩ !] .!! = ⟨ anaRec G (G ∷ Gs) [! x !] .!! ⟩\n anaRec ① Gs [! _ !] .!! = tt\n\n ana : A → ν F As\n ana x .unfold = anaRec F [] [! coalg x !] .!!\n\nmodule AnaInfDisplay {F : Functor (suc n)} {As : Params n} where\n ana : (A → ⟦ F ⟧ (A ∷ As)) → A → ν F As\n ana = AnaInf.ana\nopen AnaInfDisplay public\n\n-- The terminating anamorphism: uses well-founded recursion to ensure we're\n-- building a finite type.\nmodule AnaTerm {B : Type} {_<_ : B → B → Type} (<-wellFounded : WellFounded _<_)\n {k} {F : Functor (suc k)}\n {As : Params k}\n (coalg : (x : B) → ⟦ F ⟧ ((∃ y × (y < x)) ∷ As)) where\n\n pr-anaAcc : (x : B) → Acc _<_ x → μ F As\n pr-anaAcc x (acc wf) = ⟨ map F f0 (λ { (x , p) → pr-anaAcc x (wf x p) }) (coalg x) ⟩\n\n pr-ana : B → μ F As\n pr-ana x = pr-anaAcc x (<-wellFounded x)\n\nmodule AnaTermDisplay\n {A : Type}\n {_<_ : A → A → Type}\n {F : Functor (suc n)}\n {As : Params n}\n where\n pr-ana : WellFounded _<_ →\n ((x : A) → ⟦ F ⟧ ((∃ y × (y < x)) ∷ As)) → A → μ F As\n pr-ana wf = AnaTerm.pr-ana wf\n\nmodule Truncate {B : Type} {_<_ : B → B → Type} (<-wellFounded : WellFounded _<_)\n {k} {F : Functor (suc k)}\n {As : Params k} (step : (x : B) -> ⟦ F ⟧ (ν F As ∷ As) → ⟦ F ⟧ ((ν F As × ∃ y × (y < x)) ∷ As)) where\n\n truncAcc : (x : B) → Acc _<_ x → ν F As → μ F As\n truncAcc x (acc wf) xs = ⟨ map F f0 (λ { (ys , z , z ⟦ F ⟧ (ν F As ∷ As) → ⟦ F ⟧ ((ν F As × ∃ y × (y < x)) ∷ As)) →\n A → ν F As → μ F As\n trunc wf step = Truncate.trunc wf step\n", "meta": {"hexsha": "795a9ba3008dd26aa577746d04fa7c62850cf023", "size": 14235, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Data/PolyP/RecursionSchemes.agda", "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_issues_repo_path": "Data/PolyP/RecursionSchemes.agda", "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "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": "Data/PolyP/RecursionSchemes.agda", "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "avg_line_length": 38.163538874, "max_line_length": 117, "alphanum_fraction": 0.436459431, "num_tokens": 5668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.3644596108592753}} {"text": "------------------------------------------------------------------------\n-- Total parser combinators (very short version)\n-- Nils Anders Danielsson\n------------------------------------------------------------------------\n\nmodule Short where\n\nopen import Category.Monad\nopen import Coinduction\nopen import Data.Bool\nimport Data.BoundedVec.Inefficient as BoundedVec\nopen import Data.Char\nimport Data.Colist as Colist\nopen import Data.List as List\nopen import Data.Maybe\nopen import Data.Nat\nopen import Data.Nat.Show\nopen import Data.String using (Costring)\nopen import Function\nopen import IO hiding (return) renaming (_>>=_ to _>>=IO_)\nopen import Relation.Nullary.Decidable\n\nopen RawMonadPlus List.monadPlus using () renaming (_>>=_ to _>>=′_)\n\ninfix 7 _⋆ _+\ninfixl 6 _>>=_ _>>=app_\ninfixl 5 _∣_\n\n------------------------------------------------------------------------\n-- Helper functions\n\nflatten : {A : Set} → Maybe (List A) → List A\nflatten nothing = []\nflatten (just xs) = xs\n\napp : {A B : Set} → Maybe (A → List B) → A → List B\napp nothing x = []\napp (just f) x = f x\n\n_>>=app_ : {A B : Set} → List A → Maybe (A → List B) → List B\nxs >>=app nothing = []\nxs >>=app just f = xs >>=′ f\n\n------------------------------------------------------------------------\n-- Parsers\n\nmutual\n\n data Parser : (R : Set) → List R → Set₁ where\n return : ∀ {R} (x : R) → Parser R [ x ]\n fail : ∀ {R} → Parser R []\n token : Parser Char []\n _∣_ : ∀ {R xs₁ xs₂}\n (p₁ : Parser R xs₁ )\n (p₂ : Parser R xs₂) →\n Parser R (xs₁ ++ xs₂)\n _>>=_ : ∀ {R₁ R₂ xs} {f : Maybe (R₁ → List R₂)}\n (p₁ : ∞⟨ f ⟩Parser R₁ (flatten xs) )\n (p₂ : (x : R₁) → ∞⟨ xs ⟩Parser R₂ (app f x)) →\n Parser R₂ (flatten xs >>=app f)\n\n ∞⟨_⟩Parser : {R₂ : Set} → Maybe R₂ → (R₁ : Set) → List R₁ → Set₁\n ∞⟨ nothing ⟩Parser R₁ xs = ∞ (Parser R₁ xs)\n ∞⟨ just _ ⟩Parser R₁ xs = Parser R₁ xs\n\n------------------------------------------------------------------------\n-- Derived combinators\n\nsat : ∀ {R} → (Char → Maybe R) → Parser R []\nsat {R} p = token >>= (ok ∘ p)\n where\n ok-index : Maybe R → List R\n ok-index nothing = []\n ok-index (just x) = [ x ]\n\n ok : (x : Maybe R) → Parser R (ok-index x)\n ok nothing = fail\n ok (just x) = return x\n\ntok : Char → Parser Char []\ntok t = sat (λ t′ → if t == t′ then just t′ else nothing)\n\nreturn⋆ : ∀ {R} (xs : List R) → Parser R xs\nreturn⋆ [] = fail\nreturn⋆ (x ∷ xs) = return x ∣ return⋆ xs\n\nmutual\n\n _⋆ : ∀ {R} → Parser R [] → Parser (List R) _\n p ⋆ = return [] ∣ p +\n\n _+ : ∀ {R} → Parser R [] → Parser (List R) _\n p + = p >>= λ x → ♯ (\n p ⋆ >>= λ xs →\n return (x ∷ xs) )\n\ndigit = sat (λ t → if in-range t then just (to-number t) else nothing)\n where\n in-range : Char → Bool\n in-range t = ⌊ toNat '0' ≤? toNat t ⌋ ∧\n ⌊ toNat t ≤? toNat '9' ⌋\n\n to-number : Char → ℕ\n to-number t = toNat t ∸ toNat '0'\n\nnumber = digit + >>= return ∘ foldl (λ n d → 10 * n + d) 0\n\n------------------------------------------------------------------------\n-- Parser interpreter\n\ndelayed? : ∀ {R R′ xs} {m : Maybe R′} → ∞⟨ m ⟩Parser R xs → Maybe R′\ndelayed? {m = m} _ = m\n\ndelayed?′ : ∀ {R₁ R₂ R′ : Set} {m : Maybe R′} {f : R₁ → List R₂} →\n ((x : R₁) → ∞⟨ m ⟩Parser R₂ (f x)) → Maybe R′\ndelayed?′ {m = m} _ = m\n\n∂-initial : ∀ {R xs} → Parser R xs → Char → List R\n∂-initial (return x) t = []\n∂-initial fail t = []\n∂-initial token t = [ t ]\n∂-initial (p₁ ∣ p₂) t = ∂-initial p₁ t ++ ∂-initial p₂ t\n∂-initial (p₁ >>= p₂) t with delayed? p₁ | delayed?′ p₂\n... | just f | nothing = ∂-initial p₁ t >>=′ f\n... | just f | just xs = (∂-initial p₁ t >>=′ f) ++\n (xs >>=′ λ x → ∂-initial (p₂ x) t)\n... | nothing | nothing = []\n... | nothing | just xs = xs >>=′ λ x → ∂-initial (p₂ x) t\n\n∂ : ∀ {R xs} (p : Parser R xs) (t : Char) → Parser R (∂-initial p t)\n∂ (return x) t = fail\n∂ fail t = fail\n∂ token t = return t\n∂ (p₁ ∣ p₂) t = ∂ p₁ t ∣ ∂ p₂ t\n∂ (p₁ >>= p₂) t with delayed? p₁ | delayed?′ p₂\n... | just f | nothing = ∂ p₁ t >>= (λ x → ♭ (p₂ x))\n... | just f | just xs = ∂ p₁ t >>= (λ x → p₂ x)\n ∣ return⋆ xs >>= λ x → ∂ (p₂ x) t\n... | nothing | nothing = ♯ ∂ (♭ p₁) t >>= (λ x → ♭ (p₂ x))\n... | nothing | just xs = ♯ ∂ (♭ p₁) t >>= (λ x → p₂ x)\n ∣ return⋆ xs >>= λ x → ∂ (p₂ x) t\n\nparse : ∀ {R xs} → Parser R xs → List Char → List R\nparse {xs = xs} p [] = xs\nparse p (t ∷ s) = parse (∂ p t) s\n\n------------------------------------------------------------------------\n-- Example\n\ndata Expr : Set where\n num : (n : ℕ) → Expr\n plus : (e₁ e₂ : Expr) → Expr\n times : (e₁ e₂ : Expr) → Expr\n\n⟦_⟧ : Expr → ℕ\n⟦ num n ⟧ = n\n⟦ plus e₁ e₂ ⟧ = ⟦ e₁ ⟧ + ⟦ e₂ ⟧\n⟦ times e₁ e₂ ⟧ = ⟦ e₁ ⟧ * ⟦ e₂ ⟧\n\nmutual\n\n term = factor\n ∣ ♯ term >>= λ e₁ →\n tok '+' >>= λ _ →\n factor >>= λ e₂ →\n return (plus e₁ e₂)\n\n factor = atom\n ∣ ♯ factor >>= λ e₁ →\n tok '*' >>= λ _ →\n atom >>= λ e₂ →\n return (times e₁ e₂)\n\n atom = (number >>= return ∘ num)\n ∣ tok '(' >>= λ _ →\n ♯ term >>= λ e →\n tok ')' >>= λ _ →\n return e\n\n------------------------------------------------------------------------\n-- IO\n\ntoList : Costring → List Char\ntoList = BoundedVec.toList ∘ Colist.take 100000\n\nmain = run $\n ♯ getContents >>=IO λ s → ♯\n let s′ = takeWhile (not ∘ _==_ '\\n') $ toList s\n es = parse term s′ in\n mapM′ (putStrLn ∘ show ∘ ⟦_⟧) (Colist.fromList es)\n", "meta": {"hexsha": "adcdce970d1d8d5e4858534016943a28acbc0bcd", "size": 5864, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "misc/Short.agda", "max_stars_repo_name": "yurrriq/parser-combinators", "max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z", "max_issues_repo_path": "misc/Short.agda", "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z", "max_forks_repo_path": "misc/Short.agda", "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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": 30.7015706806, "max_line_length": 73, "alphanum_fraction": 0.4276944065, "num_tokens": 1973, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494678483918, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.3643827869818058}} {"text": "module STLC.Lib.MaybeElim where\n\nopen import Level\nopen import Function\nopen import Relation.Binary.PropositionalEquality\nopen import Data.Unit.Base\nopen import Data.Bool.Base\nopen import Data.Maybe.Base\n\ninfixl 1 _>>=ᵀ_ _>>=ᵗ_ _>>=⊤_\ninfixl 4 _<$>ᵗ_\ninfixr 1 _>=>ᵗ_\ninfixr 10 _<∘>ᵗ_\n\ndata _>>=ᵀ_ {α β} {A : Set α} : (mx : Maybe A) -> (∀ x -> mx ≡ just x -> Set β) -> Set β where\n nothingᵗ : ∀ {B} -> nothing >>=ᵀ B\n justᵗ : ∀ {x B} -> B x refl -> just x >>=ᵀ B\n\n-- We could write (Set (maybe (const β) zero mx)),\n-- but I don't want to introduce dependency at the type level.\nFromJustᵗ : ∀ {α β} {A : Set α} {mx : Maybe A} {B : ∀ x -> mx ≡ just x -> Set β}\n -> mx >>=ᵀ B -> Set β\nFromJustᵗ nothingᵗ = Lift ⊤\nFromJustᵗ (justᵗ {x} {B} y) = B x refl\n\nfromJustᵗ : ∀ {α β} {A : Set α} {mx : Maybe A} {B : ∀ x -> mx ≡ just x -> Set β}\n -> (yᵗ : mx >>=ᵀ B) -> FromJustᵗ yᵗ\nfromJustᵗ nothingᵗ = _\nfromJustᵗ (justᵗ y) = y\n\n_>>=ᵗ_ : ∀ {α β} {A : Set α} {B : A -> Set β}\n -> (mx : Maybe A) -> (∀ x -> B x) -> mx >>=ᵀ λ x _ -> B x\nnothing >>=ᵗ f = nothingᵗ\njust x >>=ᵗ f = justᵗ (f x)\n\n_>>=⊤_ : ∀ {α β} {A : Set α} {B : A -> Set β}\n -> (mx : Maybe A) -> (g : ∀ x -> B x) -> FromJustᵗ (mx >>=ᵗ g)\nmx >>=⊤ g = fromJustᵗ $ mx >>=ᵗ g\n\nrunᵗ : ∀ {α β} {A : Set α} {mx : Maybe A} {B : ∀ x -> mx ≡ just x -> Set β} {x}\n -> mx >>=ᵀ B -> (p : mx ≡ just x) -> B x p\nrunᵗ (justᵗ y) refl = y\n\n_<$>ᵗ_ : ∀ {α β γ} {A : Set α} {mx : Maybe A}\n {B : ∀ x -> mx ≡ just x -> Set β}\n {C : ∀ {x} {p : mx ≡ just x} -> B x p -> Set γ}\n -> (∀ {x} {p : mx ≡ just x} -> (y : B x p) -> C y)\n -> (yᵗ : mx >>=ᵀ B)\n -> mx >>=ᵀ λ _ -> C ∘ runᵗ yᵗ\ng <$>ᵗ nothingᵗ = nothingᵗ\ng <$>ᵗ justᵗ y = justᵗ (g y)\n\n_>=>ᵗ_ : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : ∀ {x} -> B x -> Set γ}\n -> (f : ∀ x -> Maybe (B x))\n -> (∀ {x} -> (y : B x) -> C y)\n -> ∀ x -> f x >>=ᵀ λ y _ -> C y\n(f >=>ᵗ g) x = f x >>=ᵗ g\n\n_<∘>ᵗ_ : ∀ {α β γ δ} {A : Set α} {B : A -> Set β} {f : ∀ x -> Maybe (B x)}\n {C : ∀ x y -> f x ≡ just y -> Set γ}\n {D : ∀ {x y} {p : f x ≡ just y} -> C x y p -> Set δ}\n -> (∀ {x y} {p : f x ≡ just y} -> (z : C x y p) -> D z)\n -> (g : ∀ x -> f x >>=ᵀ C x)\n -> ∀ x -> f x >>=ᵀ λ _ -> D ∘ runᵗ (g x)\n(h <∘>ᵗ g) x = h <$>ᵗ g x\n", "meta": {"hexsha": "fd05f0e802c6e2e936f46642d38d911abdabaaeb", "size": 2342, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "data/github.com/effectfully/STLC/3826d7555f37d032d07cf414c7f6770fc32918f1/src/STLC/Lib/MaybeElim.agda", "max_stars_repo_name": "ajnavarro/language-dataset", "max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-08-07T11:54:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T09:48:45.000Z", "max_issues_repo_path": "data/github.com/effectfully/STLC/3826d7555f37d032d07cf414c7f6770fc32918f1/src/STLC/Lib/MaybeElim.agda", "max_issues_repo_name": "ajnavarro/language-dataset", "max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 91, "max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z", "max_forks_repo_path": "data/github.com/effectfully/STLC/3826d7555f37d032d07cf414c7f6770fc32918f1/src/STLC/Lib/MaybeElim.agda", "max_forks_repo_name": "ajnavarro/language-dataset", "max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-11-13T12:44:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T19:34:26.000Z", "avg_line_length": 35.4848484848, "max_line_length": 94, "alphanum_fraction": 0.4342442357, "num_tokens": 1106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081925, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.3643827801609716}} {"text": "-- Algorithmic equality.\n\n{-# OPTIONS --safe #-}\n\nmodule Definition.Conversion where\n\nopen import Definition.Untyped\nopen import Definition.Typed\n\nopen import Tools.Nat\nimport Tools.PropositionalEquality as PE\n\n\ninfix 10 _⊢_~_↑_^_\ninfix 10 _⊢_[conv↑]_^_\ninfix 10 _⊢_[conv↓]_^_\ninfix 10 _⊢_[conv↑]_∷_^_\ninfix 10 _⊢_[conv↓]_∷_^_\ninfix 10 _⊢_[genconv↑]_∷_^_\n\nmutual\n -- Neutral equality.\n data _⊢_~_↑!_^_ (Γ : Con Term) : (k l A : Term) → TypeLevel → Set where\n var-refl : ∀ {x y A l}\n → Γ ⊢ var x ∷ A ^ [ ! , l ]\n → x PE.≡ y\n → Γ ⊢ var x ~ var y ↑! A ^ l\n app-cong : ∀ {k l t v F rF lF lG G lΠ}\n → Γ ⊢ k ~ l ↓! Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ ι lΠ\n → Γ ⊢ t [genconv↑] v ∷ F ^ [ rF , ι lF ]\n → Γ ⊢ k ∘ t ^ lΠ ~ l ∘ v ^ lΠ ↑! G [ t ] ^ ι lG\n natrec-cong : ∀ {k l h g a₀ b₀ F G lF}\n → Γ ∙ ℕ ^ [ ! , ι ⁰ ] ⊢ F [conv↑] G ^ [ ! , ι lF ]\n → Γ ⊢ a₀ [conv↑] b₀ ∷ F [ zero ] ^ ι lF\n → Γ ⊢ h [conv↑] g ∷ Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° lF ▹▹ F [ suc (var 0) ]↑ ° lF ° lF) ° lF ° lF ^ ι lF\n → Γ ⊢ k ~ l ↓! ℕ ^ ι ⁰\n → Γ ⊢ natrec lF F a₀ h k ~ natrec lF G b₀ g l ↑! F [ k ] ^ ι lF\n Emptyrec-cong : ∀ {k l F G ll lEmpty}\n → Γ ⊢ F [conv↑] G ^ [ ! , ι ll ]\n → Γ ⊢ k ~ l ↑% Empty lEmpty ^ ι lEmpty\n → Γ ⊢ Emptyrec ll lEmpty F k ~ Emptyrec ll lEmpty G l ↑! F ^ ι ll\n Id-cong : ∀ {l A A' t t' u u'}\n → Γ ⊢ A ~ A' ↓! U 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 Id-ℕ : ∀ {t t' u u'}\n → Γ ⊢ t ~ t' ↓! ℕ ^ ι ⁰\n → Γ ⊢ u [conv↑] u' ∷ ℕ ^ ι ⁰\n → Γ ⊢ Id ℕ t u ~ Id ℕ t' u' ↑! SProp ⁰ ^ next ⁰\n Id-ℕ0 : ∀ {t t'}\n → Γ ⊢ t ~ t' ↓! ℕ ^ ι ⁰\n → Γ ⊢ Id ℕ zero t ~ Id ℕ zero t' ↑! SProp ⁰ ^ next ⁰\n Id-ℕS : ∀ {t t' u u'}\n → Γ ⊢ t [conv↑] t' ∷ ℕ ^ ι ⁰\n → Γ ⊢ u ~ u' ↓! ℕ ^ ι ⁰\n → Γ ⊢ Id ℕ (suc t) u ~ Id ℕ (suc t') u' ↑! SProp ⁰ ^ next ⁰\n Id-U : ∀ {t t' u u'}\n → Γ ⊢ t ~ t' ↓! U ⁰ ^ ι ¹\n → Γ ⊢ u [conv↑] u' ∷ U ⁰ ^ ι ¹\n → Γ ⊢ Id (U ⁰) t u ~ Id (U ⁰) t' u' ↑! SProp ¹ ^ next ¹\n Id-Uℕ : ∀ {t t'}\n → Γ ⊢ t ~ t' ↓! U ⁰ ^ ι ¹\n → Γ ⊢ Id (U ⁰) ℕ t ~ Id (U ⁰) ℕ t' ↑! SProp ¹ ^ next ¹\n Id-UΠ : ∀ {A rA B A' B' t t'}\n → Γ ⊢ Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ [conv↑] Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰ ∷ U ⁰ ^ ι ¹\n → Γ ⊢ t ~ t' ↓! U ⁰ ^ ι ¹\n → Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ ) t ~ Id (U ⁰) (Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰ ) t' ↑! SProp ¹ ^ next ¹\n cast-cong : ∀ {A A' B B' t t' e e'}\n → Γ ⊢ A ~ A' ↓! U ⁰ ^ next ⁰\n → Γ ⊢ B [conv↑] B' ∷ U ⁰ ^ ι ¹\n → Γ ⊢ t [conv↑] 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 cast-ℕ : ∀ {A A' t t' e e'}\n → Γ ⊢ A ~ A' ↓! U ⁰ ^ next ⁰\n → Γ ⊢ t [conv↑] t' ∷ ℕ ^ ι ⁰\n → Γ ⊢ e ∷ (Id (U ⁰) ℕ A) ^ [ % , next ⁰ ]\n → Γ ⊢ e' ∷ (Id (U ⁰) ℕ A') ^ [ % , next ⁰ ]\n → Γ ⊢ cast ⁰ ℕ A e t ~ cast ⁰ ℕ A' e' t' ↑! A ^ ι ⁰\n cast-ℕℕ : ∀ {t t' e e'}\n → Γ ⊢ t ~ t' ↓! ℕ ^ ι ⁰\n → Γ ⊢ e ∷ (Id (U ⁰) ℕ ℕ) ^ [ % , next ⁰ ]\n → Γ ⊢ e' ∷ (Id (U ⁰) ℕ ℕ) ^ [ % , next ⁰ ]\n → Γ ⊢ cast ⁰ ℕ ℕ e t ~ cast ⁰ ℕ ℕ e' t' ↑! ℕ ^ ι ⁰\n cast-Π : ∀ {A rA P A' P' B B' t t' e e'}\n → Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [conv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ next ⁰\n → Γ ⊢ B ~ B' ↓! U ⁰ ^ next ⁰\n → Γ ⊢ t [conv↑] 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-Πℕ : ∀ {A rA P A' P' t t' e e'}\n → Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [conv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ ι ¹\n → Γ ⊢ t [conv↑] 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 ~ cast ⁰ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ) ℕ e' t' ↑! ℕ ^ ι ⁰\n cast-ℕΠ : ∀ {A rA P A' P' t t' e e'}\n → Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ [conv↑] Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ ι ¹\n → Γ ⊢ t [conv↑] 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' ↑! (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ) ^ ι ⁰\n cast-ΠΠ%! : ∀ {A P A' P' B Q B' Q' t t' e e'}\n → Γ ⊢ Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰ [conv↑] Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ ι ¹\n → Γ ⊢ Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰ [conv↑] Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰ ∷ U ⁰ ^ ι ¹\n → Γ ⊢ t [conv↑] 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 A' P' B Q B' Q' t t' e e'}\n → Γ ⊢ Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰ [conv↑] Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ ι ¹\n → Γ ⊢ Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰ [conv↑] Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰ ∷ U ⁰ ^ ι ¹\n → Γ ⊢ t [conv↑] 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\n\n record _⊢_~_↑%_^_ (Γ : Con Term) (k l A : Term) (ll : TypeLevel) : Set where\n inductive\n constructor %~↑\n field\n ⊢k : Γ ⊢ k ∷ A ^ [ % , ll ]\n ⊢l : Γ ⊢ l ∷ A ^ [ % , ll ]\n\n data _⊢_~_↑_^_ (Γ : Con Term) : (k l A : Term) → TypeInfo → Set where\n ~↑! : ∀ {k l A ll} → Γ ⊢ k ~ l ↑! A ^ ll → Γ ⊢ k ~ l ↑ A ^ [ ! , ll ]\n ~↑% : ∀ {k l A ll} → Γ ⊢ k ~ l ↑% A ^ ll → Γ ⊢ k ~ l ↑ A ^ [ % , ll ]\n\n -- Neutral equality with types in WHNF.\n record _⊢_~_↓!_^_ (Γ : Con Term) (k l B : Term) (ll : TypeLevel) : Set where\n inductive\n constructor [~]\n field\n A : Term\n D : Γ ⊢ A ⇒* B ^ [ ! , ll ]\n whnfB : Whnf B\n k~l : Γ ⊢ k ~ l ↑! A ^ ll\n\n -- Type equality.\n record _⊢_[conv↑]_^_ (Γ : Con Term) (A B : Term) (rA : TypeInfo) : Set where\n inductive\n constructor [↑]\n field\n A′ B′ : Term\n D : Γ ⊢ A ⇒* A′ ^ rA\n D′ : Γ ⊢ B ⇒* B′ ^ rA\n whnfA′ : Whnf A′\n whnfB′ : Whnf B′\n A′<>B′ : Γ ⊢ A′ [conv↓] B′ ^ rA\n\n -- Type equality with types in WHNF.\n data _⊢_[conv↓]_^_ (Γ : Con Term) : (A B : Term) → TypeInfo → Set where\n U-refl : ∀ {r r' }\n → r PE.≡ r' -- needed for K issues\n → ⊢ Γ → Γ ⊢ Univ r ¹ [conv↓] Univ r' ¹ ^ [ ! , next ¹ ]\n univ : ∀ {A B r l}\n → Γ ⊢ A [conv↓] B ∷ Univ r l ^ next l\n → Γ ⊢ A [conv↓] B ^ [ r , ι l ]\n\n -- Term equality.\n record _⊢_[conv↑]_∷_^_ (Γ : Con Term) (t u A : Term) (l : TypeLevel) : Set where\n inductive\n constructor [↑]ₜ\n field\n B t′ u′ : Term\n D : Γ ⊢ A ⇒* B ^ [ ! , l ]\n d : Γ ⊢ t ⇒* t′ ∷ B ^ l\n d′ : Γ ⊢ u ⇒* u′ ∷ B ^ l\n whnfB : Whnf B\n whnft′ : Whnf t′\n whnfu′ : Whnf u′\n t<>u : Γ ⊢ t′ [conv↓] u′ ∷ B ^ l\n\n -- Term equality with types and terms in WHNF.\n data _⊢_[conv↓]_∷_^_ (Γ : Con Term) : (t u A : Term) (l : TypeLevel) → Set where\n U-refl : ∀ {r r' }\n → r PE.≡ r' -- needed for K issues\n → ⊢ Γ → Γ ⊢ Univ r ⁰ [conv↓] Univ r' ⁰ ∷ U ¹ ^ next ¹\n ne : ∀ {r K L lU l}\n → Γ ⊢ K ~ L ↓! Univ r lU ^ l\n → Γ ⊢ K [conv↓] L ∷ Univ r lU ^ l\n ℕ-refl : ⊢ Γ → Γ ⊢ ℕ [conv↓] ℕ ∷ U ⁰ ^ next ⁰\n Empty-refl : ∀ {l ll} → ll PE.≡ next l → ⊢ Γ → Γ ⊢ Empty l [conv↓] Empty l ∷ SProp l ^ ll\n Π-cong : ∀ {F G H E rF rH rΠ lF lH lG lE lΠ ll}\n → ll PE.≡ next lΠ\n → rF PE.≡ rH -- needed for K issues\n → lF PE.≡ lH -- needed for K issues\n → lG PE.≡ lE -- needed for K issues\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 rΠ lG ^ next lG\n → Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° lΠ [conv↓] Π H ^ rH ° lH ▹ E ° lE ° lΠ ∷ Univ rΠ lΠ ^ ll\n ∃-cong : ∀ {F G H E l ll}\n → ll PE.≡ next l\n → Γ ⊢ F ^ [ % , ι l ]\n → Γ ⊢ F [conv↑] H ∷ SProp l ^ next l\n → Γ ∙ F ^ [ % , ι l ] ⊢ G [conv↑] E ∷ SProp l ^ next l\n → Γ ⊢ ∃ F ▹ G [conv↓] ∃ H ▹ E ∷ SProp l ^ ll\n ℕ-ins : ∀ {k l}\n → Γ ⊢ k ~ l ↓! ℕ ^ ι ⁰\n → Γ ⊢ k [conv↓] l ∷ ℕ ^ ι ⁰\n ne-ins : ∀ {k l M N ll}\n → Γ ⊢ k ∷ N ^ [ ! , ι ll ]\n → Γ ⊢ l ∷ N ^ [ ! , ι ll ]\n → Neutral N\n → Γ ⊢ k ~ l ↓! M ^ ι ll\n → Γ ⊢ k [conv↓] l ∷ N ^ ι ll\n zero-refl : ⊢ Γ → Γ ⊢ zero [conv↓] zero ∷ ℕ ^ ι ⁰\n suc-cong : ∀ {m n}\n → Γ ⊢ m [conv↑] n ∷ ℕ ^ ι ⁰\n → Γ ⊢ suc m [conv↓] suc n ∷ ℕ ^ ι ⁰\n η-eq : ∀ {f g F G rF lF lG l}\n → lF ≤ l\n → lG ≤ l\n → Γ ⊢ F ^ [ rF , ι lF ]\n → Γ ⊢ f ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , ι l ]\n → Γ ⊢ g ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , ι l ]\n → Function f\n → Function g\n → Γ ∙ F ^ [ rF , ι lF ] ⊢ wk1 f ∘ var 0 ^ l [conv↑] wk1 g ∘ var 0 ^ l ∷ G ^ ι lG\n → Γ ⊢ f [conv↓] g ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ ι l\n\n _⊢_[genconv↑]_∷_^_ : (Γ : Con Term) (t u A : Term) (r : TypeInfo) → Set\n _⊢_[genconv↑]_∷_^_ Γ k l A [ ! , ll ] = Γ ⊢ k [conv↑] l ∷ A ^ ll\n _⊢_[genconv↑]_∷_^_ Γ k l A [ % , ll ] = Γ ⊢ k ~ l ↑% A ^ ll\n\n\nvar-refl′ : ∀ {Γ x A rA ll}\n → Γ ⊢ var x ∷ A ^ [ rA , ll ]\n → Γ ⊢ var x ~ var x ↑ A ^ [ rA , ll ]\nvar-refl′ {rA = !} ⊢x = ~↑! (var-refl ⊢x PE.refl)\nvar-refl′ {rA = %} ⊢x = ~↑% (%~↑ ⊢x ⊢x)\n", "meta": {"hexsha": "21e9a449e68be768a1335d9b446fd28988cf3607", "size": 11197, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Conversion.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.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.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": 46.4605809129, "max_line_length": 144, "alphanum_fraction": 0.3270518889, "num_tokens": 5764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.4843800842769843, "lm_q1q2_score": 0.36425991385512246}} {"text": "{-# OPTIONS --cubical --safe --postfix-projections #-}\n\nopen import Prelude\n\nmodule Cardinality.Finite.Cardinal.Category {ℓ : Level} where\n\nopen import Cardinality.Finite.Cardinal\nopen import HITs.PropositionalTruncation\nopen import Data.Sigma.Properties\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Categories\nopen import Cubical.Foundations.Univalence\nopen import Categories.Product\nopen import Categories.Exponential\nopen import Data.Fin\nopen import Cardinality.Finite.ManifestBishop\n\n𝒞⇒isSet : 𝒞 A → isSet A\n𝒞⇒isSet = Discrete→isSet ∘ 𝒞⇒Discrete\n\nfinSetPreCategory : PreCategory (ℓsuc ℓ) ℓ\nfinSetPreCategory .PreCategory.Ob = Σ (Type ℓ) 𝒞\nfinSetPreCategory .PreCategory.Hom (X , _) (Y , _) = X → Y\nfinSetPreCategory .PreCategory.Id = id\nfinSetPreCategory .PreCategory.Comp f g = f ∘ g\nfinSetPreCategory .PreCategory.assoc-Comp _ _ _ = refl\nfinSetPreCategory .PreCategory.Comp-Id _ = refl\nfinSetPreCategory .PreCategory.Id-Comp _ = refl\nfinSetPreCategory .PreCategory.Hom-Set {X} {Y} = hLevelPi 2 λ _ → Discrete→isSet (𝒞⇒Discrete (Y .snd))\n\nopen PreCategory finSetPreCategory\n\niso-iso : (X ≅ Y) ⇔ (fst X ⇔ fst Y)\niso-iso .fun (f , g , f∘g , g∘f) = iso f g (λ x i → g∘f i x) (λ x i → f∘g i x)\niso-iso .inv (iso f g g∘f f∘g) = f , g , (λ i x → f∘g x i) , (λ i x → g∘f x i)\niso-iso .rightInv _ = refl\niso-iso .leftInv _ = refl\n\nfinSetCategory : Category (ℓsuc ℓ) ℓ\nfinSetCategory .Category.preCategory = finSetPreCategory\nfinSetCategory .Category.univalent {X} {Y} =\n ≃ΣProp≡ (λ _ → squash) ⟨ trans-≃ ⟩\n univalence ⟨ trans-≃ ⟩\n isoToEquiv (\n sym-⇔ (iso⇔equiv (Discrete→isSet (𝒞⇒Discrete (X .snd)))) ⟨ trans-⇔ ⟩\n sym-⇔ (iso-iso {X} {Y}))\n\nfinSetHasProducts : HasProducts finSetCategory\nfinSetHasProducts .HasProducts.product X Y .Product.obj = X .fst × Y .fst , X .snd ∥×∥ Y .snd\nfinSetHasProducts .HasProducts.product X Y .Product.proj₁ = fst\nfinSetHasProducts .HasProducts.product X Y .Product.proj₂ = snd\nfinSetHasProducts .HasProducts.product X Y .Product.ump f g .fst z = f z , g z\nfinSetHasProducts .HasProducts.product X Y .Product.ump f g .snd .fst .fst = refl\nfinSetHasProducts .HasProducts.product X Y .Product.ump f g .snd .fst .snd = refl\nfinSetHasProducts .HasProducts.product X Y .Product.ump f g .snd .snd (f≡ , g≡) i x = f≡ (~ i) x , g≡ (~ i) x\n\nfinSetHasExp : HasExponentials finSetCategory finSetHasProducts\nfinSetHasExp X Y .Exponential.obj = (X .fst → Y .fst) , (X .snd ∥→∥ Y .snd)\nfinSetHasExp X Y .Exponential.eval (f , x) = f x\nfinSetHasExp X Y .Exponential.uniq X₁ f .fst = curry f\nfinSetHasExp X Y .Exponential.uniq X₁ f .snd .fst = refl\nfinSetHasExp X Y .Exponential.uniq X₁ f .snd .snd x = cong curry (sym x)\n\nopen import Categories.Pullback\nopen import Cardinality.Finite.SplitEnumerable using (ℰ!⟨Lift⟩; ℰ!⟨⊤⟩; ℰ!⟨⊥⟩)\n\n\nfinSetHasPullbacks : HasPullbacks finSetCategory\nfinSetHasPullbacks {X = X} {Y = Y} {Z = Z} f g .Pullback.P = ∃[ ab ] (f (fst ab) ≡ g (snd ab)) , ((X .snd ∥×∥ Y .snd) ∥Σ∥ λ _ → 𝒞⟨≡⟩ _ _ (Z .snd))\nfinSetHasPullbacks f g .Pullback.p₁ ((x , _) , _) = x\nfinSetHasPullbacks f g .Pullback.p₂ ((_ , y) , _) = y\nfinSetHasPullbacks f g .Pullback.commute = funExt snd\nfinSetHasPullbacks f g .Pullback.ump {A = A} h₁ h₂ p .fst x = (h₁ x , h₂ x) , λ i → p i x\nfinSetHasPullbacks f g .Pullback.ump {A = A} h₁ h₂ p .snd .fst .fst = refl\nfinSetHasPullbacks f g .Pullback.ump {A = A} h₁ h₂ p .snd .fst .snd = refl\nfinSetHasPullbacks {Z = Z} f g .Pullback.ump {A = A} h₁ h₂ p .snd .snd {i} (p₁e , p₂e) = funExt (λ x → ΣProp≡ (λ _ → 𝒞⇒isSet (Z .snd) _ _) λ j → p₁e (~ j) x , p₂e (~ j) x)\n\nfinSetTerminal : Terminal\nfinSetTerminal .fst = Lift _ ⊤ , ∣ ℰ!⇒ℬ (ℰ!⟨Lift⟩ ℰ!⟨⊤⟩) ∣\nfinSetTerminal .snd .fst x .lower = tt\nfinSetTerminal .snd .snd y = funExt λ _ → refl\n\nfinSetInitial : Initial\nfinSetInitial .fst = Lift _ ⊥ , ∣ ℰ!⇒ℬ (ℰ!⟨Lift⟩ ℰ!⟨⊥⟩) ∣\nfinSetInitial .snd .fst ()\nfinSetInitial .snd .snd y i ()\n\nopen import HITs.PropositionalTruncation\nopen import Categories.Coequalizer\n\n∃!′ : (A : Type a) → (A → Type b) → Type (a ℓ⊔ b)\n∃!′ A P = ∥ Σ A P ∥ Prelude.× AtMostOne P\n\nlemma23 : ∀ {p} {P : A → hProp p} → ∃!′ A (fst ∘ P) → Σ A (fst ∘ P)\nlemma23 {P = P} (x , y) = rec (λ xs ys → ΣProp≡ (snd ∘ P) (y (xs .fst) (ys .fst) (xs .snd) (ys .snd))) id x\n\nmodule _ {A : Type a} {P : A → Type b} (R : ∀ x → P x → hProp c) where\n uniqueChoice : (Π[ x ⦂ A ] (∃!′ (P x) (λ u → R x u .fst))) →\n Σ[ f ⦂ Π[ x ⦂ A ] P x ] Π[ x ⦂ A ] (R x (f x) .fst)\n uniqueChoice H = fst ∘ mid , snd ∘ mid\n where\n mid : Π[ x ⦂ A ] Σ[ u ⦂ P x ] (R x u .fst)\n mid x = lemma23 {P = R x} (H x)\n\nopen import HITs.PropositionalTruncation.Sugar\nopen import Data.List using (_∷_; [])\nopen import Cardinality.Finite.SplitEnumerable.Search using (ℰ!⟨fib⟩)\n\nmodule CoeqProofs {X Y : Ob} (f : X ⟶ Y) where\n KernelPair : Pullback finSetCategory {X = X} {Z = Y} {Y = X} f f\n KernelPair = finSetHasPullbacks f f\n\n Im : Ob\n Im = ∃[ b ] ∥ fiber f b ∥ , (Y .snd ∥Σ∥ λ x → do cx ← X .snd ; cy ← Y .snd ; ∣ ℰ!⇒ℬ (ℰ!⟨fib⟩ f _ (ℬ⇒ℰ! cx) (ℬ⇒ℰ! cy)) ∣)\n\n im : X ⟶ Im\n im x = f x , ∣ x , refl ∣\n\n open Pullback KernelPair\n\n lem : ∀ {H : Ob} (h : X ⟶ H) → h ∘ p₁ ≡ h ∘ p₂ → Σ[ f ⦂ (Im ⟶ H) ] Π[ x ⦂ Im .fst ] (∀ y → im y ≡ x → h y ≡ f x)\n lem {H = H} h eq = uniqueChoice R prf\n where\n R : Im .fst → H .fst → hProp _\n R w x .fst = ∀ y → im y ≡ w → h y ≡ x\n R w x .snd = hLevelPi 1 λ _ → hLevelPi 1 λ _ → 𝒞⇒isSet (H .snd) _ _\n\n prf : Π[ x ⦂ Im .fst ] ∃!′ (H .fst) (λ u → ∀ y → im y ≡ x → h y ≡ u)\n prf (xy , p) .fst = (λ { (z , r) → h z , λ y imy≡xyp → cong (_$ ((y , z) , cong fst imy≡xyp ; sym r)) eq }) ∥$∥ p\n prf (xy , p) .snd x₁ x₂ Px₁ Px₂ = rec (𝒞⇒isSet (H .snd) x₁ x₂) (λ { (z , zs) → sym (Px₁ z (ΣProp≡ (λ _ → squash) zs)) ; Px₂ z (ΣProp≡ (λ _ → squash) zs) } ) p\n\n lem₂ : ∀ (H : Ob) (h : X ⟶ H) (i : Im ⟶ H) (x : Im .fst) (hi : h ≡ i ∘ im) (eq : h ∘ p₁ ≡ h ∘ p₂) → i x ≡ lem {H = H} h eq .fst x\n lem₂ H h i x hi eq = rec (𝒞⇒isSet (H .snd) _ _) (λ { (y , ys) → (cong i (ΣProp≡ (λ _ → squash) (sym ys)) ; sym (cong (_$ y) hi)) ; lem {H = H} h eq .snd x y (ΣProp≡ (λ _ → squash) ys) }) (x .snd)\n\n finSetCoeq : Coequalizer finSetCategory {X = P} {Y = X} p₁ p₂\n finSetCoeq .Coequalizer.obj = Im\n finSetCoeq .Coequalizer.arr = im\n finSetCoeq .Coequalizer.equality = funExt λ x → ΣProp≡ (λ _ → squash) λ i → commute i x\n finSetCoeq .Coequalizer.coequalize {H = H} {h = h} eq = lem {H = H} h eq .fst\n finSetCoeq .Coequalizer.universal {H = H} {h = h} {eq = eq} = funExt λ x → lem {H = H} h eq .snd (im x) x refl\n finSetCoeq .Coequalizer.unique {H = H} {h = h} {i = i} {eq = eq} prf = funExt λ x → lem₂ H h i x prf eq\nopen CoeqProofs public using (finSetCoeq)\n\nmodule PullbackSurjProofs {X Y : Ob} (f : X ⟶ Y) (fSurj : Surjective f) where\n KernelPair : Pullback finSetCategory {X = X} {Z = Y} {Y = X} f f\n KernelPair = finSetHasPullbacks f f\n\n open Pullback KernelPair\n\n p₁surj : Surjective p₁\n p₁surj y = ∣ ((y , y) , refl) , refl ∣\n\n p₂surj : Surjective p₂\n p₂surj y = ∣ ((y , y) , refl) , refl ∣\n", "meta": {"hexsha": "926ed20d26192f3464c211e20bf3ffe1c79c5505", "size": 6996, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda/Cardinality/Finite/Cardinal/Category.agda", "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "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": "agda/Cardinality/Finite/Cardinal/Category.agda", "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "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/Cardinality/Finite/Cardinal/Category.agda", "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "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": 44.8461538462, "max_line_length": 197, "alphanum_fraction": 0.6216409377, "num_tokens": 2995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6757646140788307, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3642257881229781}} {"text": "-- Copyright: (c) 2016 Ertugrul Söylemez\n-- License: BSD3\n-- Maintainer: Ertugrul Söylemez \n--\n-- This module contains definitions that are fundamental and/or used\n-- everywhere.\n\nmodule Core where\n\nopen import Agda.Builtin.Equality public\n renaming (refl to ≡-refl)\n using (_≡_)\nopen import Agda.Builtin.FromNat public\nopen import Agda.Builtin.FromNeg public\nopen import Agda.Builtin.FromString public\nopen import Agda.Builtin.Unit using (⊤; tt) public\nopen import Agda.Primitive using (Level; lsuc; lzero; _⊔_) public\n\n\n-- An empty type (or a false hypothesis).\n\ndata ⊥ : Set where\n\n\n-- Dependent sums (or existential quantification).\n\nrecord Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where\n constructor _,_\n field\n fst : A\n snd : B fst\n\nopen Σ public\n\ninfixr 4 _,_\ninfixr 0 _because_ _because:_\n\n∃ : ∀ {a b} {A : Set a} (B : A → Set b) → Set (a ⊔ b)\n∃ = Σ _\n\n_because_ : ∀ {a b} {A : Set a} {B : A → Set b} → (x : A) → B x → Σ A B\n_because_ = _,_\n\n_because:_ : ∀ {a b} {A : Set a} {B : A → Set b} → (x : A) → B x → Σ A B\n_because:_ = _,_\n\n_×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a ⊔ b)\nA × B = Σ A (λ _ → B)\n\ninfixr 7 _×_\n\n\n-- Tagged unions.\n\ndata Either {a} {b} (A : Set a) (B : Set b) : Set (a ⊔ b) where\n Left : A → Either A B\n Right : B → Either A B\n\n\n-- Equivalence relations.\n\nrecord Equiv {a r} (A : Set a) : Set (a ⊔ lsuc r) where\n field\n _≈_ : A → A → Set r\n refl : ∀ {x} → x ≈ x\n sym : ∀ {x y} → x ≈ y → y ≈ x\n trans : ∀ {x y z} → x ≈ y → y ≈ z → x ≈ z\n\n infix 4 _≈_\n\n -- Helper functions for equational reasoning.\n begin_ : ∀ {x y} → x ≈ y → x ≈ y\n begin_ p = p\n\n _≈[_]_ : ∀ x {y z} → x ≈ y → y ≈ z → x ≈ z\n _ ≈[ x≈y ] y≈z = trans x≈y y≈z\n\n _≈[]_ : ∀ x {y} → x ≈ y → x ≈ y\n _ ≈[] p = p\n\n _qed : ∀ (x : A) → x ≈ x\n _qed _ = refl\n\n infix 1 begin_\n infixr 2 _≈[_]_ _≈[]_\n infix 3 _qed\n\nPropEq : ∀ {a} → (A : Set a) → Equiv A\nPropEq A =\n record {\n _≈_ = _≡_;\n refl = ≡-refl;\n sym = sym';\n trans = trans'\n }\n\n where\n sym' : ∀ {x y} → x ≡ y → y ≡ x\n sym' ≡-refl = ≡-refl\n\n trans' : ∀ {x y z} → x ≡ y → y ≡ z → x ≡ z\n trans' ≡-refl q = q\n\nmodule PropEq {a} {A : Set a} = Equiv (PropEq A)\n\nFuncEq : ∀ {a b} (A : Set a) (B : Set b) → Equiv (A → B)\nFuncEq A B =\n record {\n _≈_ = λ f g → ∀ x → f x ≡ g x;\n refl = λ _ → ≡-refl;\n sym = λ p x → PropEq.sym (p x);\n trans = λ p q x → PropEq.trans (p x) (q x)\n }\n\nmodule FuncEq {a b} {A : Set a} {B : Set b} = Equiv (FuncEq A B)\n\ncong : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {x y} → x ≡ y → f x ≡ f y\ncong _ ≡-refl = ≡-refl\n\ncong2 :\n ∀ {a b c} {A : Set a} {B : Set b} {C : Set c}\n (f : A → B → C)\n → ∀ {x1 x2 : A} {y1 y2 : B}\n → x1 ≡ x2\n → y1 ≡ y2\n → f x1 y1 ≡ f x2 y2\ncong2 _ ≡-refl ≡-refl = ≡-refl\n\n\n-- Partial orders.\n\nrecord PartialOrder {a re rl} (A : Set a) : Set (a ⊔ lsuc (re ⊔ rl)) where\n field Eq : Equiv {r = re} A\n module ≈ = Equiv Eq\n open ≈ public using (_≈_)\n\n field\n _≤_ : (x : A) → (y : A) → Set rl\n antisym : ∀ {x y} → x ≤ y → y ≤ x → x ≈ y\n refl' : ∀ {x y} → x ≈ y → x ≤ y\n trans : ∀ {x y z} → x ≤ y → y ≤ z → x ≤ z\n\n infix 4 _≤_\n\n refl : ∀ {x} → x ≤ x\n refl = refl' ≈.refl\n\n -- Helper functions for transitivity reasoning.\n begin_ : ∀ {x y} → x ≤ y → x ≤ y\n begin_ p = p\n\n _≤[_]_ : ∀ x {y z} → x ≤ y → y ≤ z → x ≤ z\n _ ≤[ x≤y ] y≤z = trans x≤y y≤z\n\n _≤[]_ : ∀ x {y} → x ≤ y → x ≤ y\n _ ≤[] p = p\n\n _qed : ∀ (x : A) → x ≤ x\n _qed _ = refl\n\n infix 1 begin_\n infixr 2 _≤[_]_ _≤[]_\n infix 3 _qed\n\n\n-- Total orders.\n\nrecord TotalOrder {a re rl} (A : Set a) : Set (a ⊔ lsuc (re ⊔ rl)) where\n field partialOrder : PartialOrder {a} {re} {rl} A\n open PartialOrder partialOrder public\n\n field\n total : ∀ x y → Either (x ≤ y) (y ≤ x)\n\n\n-- Low-priority function application.\n\n_$_ : ∀ {a} {A : Set a} → A → A\n_$_ f = f\n\ninfixr 0 _$_\n\n\n-- Given two predicates, this is the predicate that requires both.\n\n_and_ : ∀ {a r1 r2} {A : Set a} → (A → Set r1) → (A → Set r2) → A → Set (r1 ⊔ r2)\n(P and Q) x = P x × Q x\n\ninfixr 6 _and_\n\n\n-- Use instance resolution to find a value of the target type.\n\nit : ∀ {a} {A : Set a} {{_ : A}} → A\nit {{x}} = x\n\n\n-- Not.\n\nnot : ∀ {a} → Set a → Set a\nnot A = A → ⊥\n\n\n-- Given two predicates, this is the predicate that requires at least\n-- one of them.\n\n_or_ : ∀ {a r1 r2} {A : Set a} → (A → Set r1) → (A → Set r2) → A → Set (r1 ⊔ r2)\n(P or Q) x = Either (P x) (Q x)\n\n\n-- Values with inline type signatures.\n\nthe : ∀ {a} (A : Set a) → A → A\nthe _ x = x\n\n\n-- Decidable properties.\n\ndata Decision {a} (P : Set a) : Set a where\n yes : (p : P) → Decision P\n no : (np : not P) → Decision P\n", "meta": {"hexsha": "7c102e8cfabc63a931abd4b95569682dcaa75022", "size": 4648, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Core.agda", "max_stars_repo_name": "esoeylemez/agda-simple", "max_stars_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-07T17:36:42.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-07T17:36:42.000Z", "max_issues_repo_path": "Core.agda", "max_issues_repo_name": "esoeylemez/agda-simple", "max_issues_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "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": "Core.agda", "max_forks_repo_name": "esoeylemez/agda-simple", "max_forks_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13", "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": 20.9369369369, "max_line_length": 81, "alphanum_fraction": 0.5163511188, "num_tokens": 2013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.6757646075489392, "lm_q1q2_score": 0.36422578460347615}} {"text": "{-# OPTIONS --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Properties.Universe {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped\nopen import Definition.Untyped.Properties\nopen import Definition.Typed\nopen import Definition.Typed.Weakening\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.Weakening as Lwk\nopen import Definition.LogicalRelation.ShapeView\nopen import Definition.LogicalRelation.Irrelevance as Irr\nopen import Definition.Typed.Properties\nopen import Definition.LogicalRelation.Properties.MaybeEmb\nopen import Definition.LogicalRelation.Properties.Escape\nopen import Definition.LogicalRelation.Properties.Reduction\nopen import Definition.LogicalRelation.Properties.Conversion\nopen import Tools.Product\nimport Tools.PropositionalEquality as PE\nopen import Tools.Empty using (⊥; ⊥-elim)\n\nimport Data.Fin as Fin\nimport Data.Nat as Nat\n\nUgen : ∀ {Γ rU l} → (⊢Γ : ⊢ Γ) → Γ ⊩⟨ next l ⟩ Univ rU l ^ [ ! , next l ] \nUgen {Γ} {rU} {⁰} ⊢Γ = Uᵣ′ (Univ rU ⁰) (ι ¹) rU ⁰ emb< PE.refl ((idRed:*: (Ugenⱼ ⊢Γ)))\nUgen {Γ} {rU} {¹} ⊢Γ = Uᵣ′ (Univ rU ¹) ∞ rU ¹ ∞< PE.refl (idRed:*: (Uⱼ ⊢Γ))\n\nU-Relevance-Level : ∀ {l ll Γ A} ([U] : Γ ⊩⟨ l ⟩U A ^ ll) → Relevance × Level\nU-Relevance-Level (noemb (Uᵣ r l′ l< eq d)) = r , l′\nU-Relevance-Level (emb x X) = U-Relevance-Level X\n\n\nunivRedTerm : ∀ {Γ r l u t ti}\n → Γ ⊢ Univ r l ⇒ u ∷ t ^ ti\n → ⊥\nunivRedTerm (conv d′ A≡t) = univRedTerm d′\n\nunivRed* : ∀ {Γ r l r′ l′ ti}\n → Γ ⊢ Univ r l ⇒* Univ r′ l′ ^ ti\n → (r PE.≡ r′) × (l PE.≡ l′)\nunivRed* (id x) = PE.refl , PE.refl\nunivRed* (univ x ⇨ D) = ⊥-elim (univRedTerm x)\n\n-- Reducible terms of type U are reducible types.\nunivEq : ∀ {l Γ A r l′ ll′}\n → ([U] : Γ ⊩⟨ l ⟩ Univ r l′ ^ [ ! , ll′ ] )\n → Γ ⊩⟨ l ⟩ A ∷ Univ r l′ ^ [ ! , ll′ ] / [U]\n → Γ ⊩⟨ ι l′ ⟩ A ^ [ r , ι l′ ]\nunivEq {ι ⁰} {Γ} {A} {r} {l′} (Uᵣ (Uᵣ r₁ l′₁ () eq [[ ⊢A , ⊢B , D ]])) (Uₜ K d₁ typeK K≡K [t])\nunivEq {ι ¹} {Γ} {A} {r} {l′} (Uᵣ (Uᵣ r₁ ⁰ emb< eq [[ ⊢A , ⊢B , D ]])) (Uₜ K d₁ typeK K≡K [t]) =\n let\n ⊢Γ = wf ⊢A\n r≡r₁ , l′≡l′₁ = univRed* D\n [t]′ : Γ ⊩⟨ ι ⁰ ⟩ A ^ [ r₁ , ι ⁰ ]\n [t]′ = PE.subst (λ X → Γ ⊩⟨ _ ⟩ X ^ [ _ , _ ])\n (Definition.Untyped.Properties.wk-id A) ([t] Definition.Typed.Weakening.id ⊢Γ)\n in\n PE.subst₂ (λ X Y → Γ ⊩⟨ ι Y ⟩ A ^ [ X , ι Y ]) (PE.sym r≡r₁) (PE.sym l′≡l′₁) [t]′\nunivEq {∞} {Γ} {A} {r} {l′} (Uᵣ (Uᵣ r₁ ¹ _ eq [[ ⊢A , ⊢B , D ]])) (Uₜ K d₁ typeK K≡K [t]) =\n let\n ⊢Γ = wf ⊢A\n r≡r₁ , l′≡l′₁ = univRed* D\n [t]′ : Γ ⊩⟨ ι ¹ ⟩ A ^ [ r₁ , ι ¹ ]\n [t]′ = PE.subst (λ X → Γ ⊩⟨ _ ⟩ X ^ [ _ , _ ])\n (Definition.Untyped.Properties.wk-id A) ([t] Definition.Typed.Weakening.id ⊢Γ)\n in\n PE.subst₂ (λ X Y → Γ ⊩⟨ ι Y ⟩ A ^ [ X , ι Y ]) (PE.sym r≡r₁) (PE.sym l′≡l′₁) [t]′\nunivEq (ℕᵣ [[ ⊢A , ⊢B , univ x ⇨ D ]]) [A] = ⊥-elim (univRedTerm x)\nunivEq (ne′ K [[ ⊢A , ⊢B , univ x ⇨ D ]] neK K≡K) [A] = ⊥-elim (univRedTerm x)\nunivEq (Πᵣ′ rF lF lG _ _ F G [[ ⊢A , ⊢B , univ x ⇨ D ]] ⊢F ⊢G A≡A [F] [G] G-ext) [A] =\n ⊥-elim (univRedTerm x)\nunivEq {ι ¹} (emb _ [U]′) [A] = univEq [U]′ [A]\nunivEq {∞} (emb _ [U]′) [A] = univEq [U]′ [A]\n\nunivEqGen : ∀ {Γ UA A l′}\n → ([U] : ((next l′) LogRel.⊩¹U logRelRec (next l′) ^ Γ) UA (next l′))\n → Γ ⊩⟨ next l′ ⟩ A ∷ UA ^ [ ! , next l′ ] / Uᵣ [U]\n → Γ ⊩⟨ ι l′ ⟩ A ^ [ LogRel._⊩¹U_^_.r [U] , ι l′ ]\nunivEqGen {Γ} {UA} {A} {l′} [UA] [A] =\n let (Uᵣ r l′₁ l< e [[ ⊢A , ⊢B , D ]]) = [UA]\n [U] = Ugen {l = l′} (wf ⊢A)\n [UA]' , [UAeq] = redSubst* (PE.subst (λ X → Γ ⊢ UA ⇒* Univ r X ^ [ ! , next X ]) (next-inj e) D) [U]\n in univEq [U] (convTerm₁ {t = A} [UA]' [U] [UAeq] (irrelevanceTerm (Uᵣ [UA]) [UA]' [A]))\n\nuniv⊩ : ∀ {A Γ rU lU lU' l} \n ([U] : Γ ⊩⟨ l ⟩ Univ rU lU ^ [ ! , lU' ])\n → Γ ⊩⟨ l ⟩ A ∷ Univ rU lU ^ [ ! , lU' ] / [U]\n → Γ ⊩⟨ ι lU ⟩ A ^ [ rU , ι lU ] \nuniv⊩ {lU = lU} {l = l} [U] [A] = irrelevance-≤ (≡is≤ PE.refl) (univEq [U] [A])\n \nunivEqTerm : ∀ {Γ A t r l′ ll′}\n → ([U] : Γ ⊩⟨ ∞ ⟩ Univ r l′ ^ [ ! , ll′ ] )\n → ([A] : Γ ⊩⟨ ∞ ⟩ A ∷ Univ r l′ ^ [ ! , ll′ ] / [U])\n → Γ ⊩⟨ ∞ ⟩ t ∷ A ^ [ r , ι l′ ] / maybeEmb (univ⊩ [U] [A])\n → Γ ⊩⟨ ι l′ ⟩ t ∷ A ^ [ r , ι l′ ] / univEq [U] [A]\nunivEqTerm {Γ} {A} {t} {r} {⁰} [U] [A] [t] = [t]\nunivEqTerm {Γ} {A} {t} {r} {¹} [U] [A] [t] = [t]\n\n-- Helper function for reducible term equality of type U for specific type derivations.\nunivEqEq′ : ∀ {l ll l′ Γ X A B} ([U] : Γ ⊩⟨ l ⟩U X ^ ll) →\n let r = toTypeInfo (U-Relevance-Level [U])\n in\n ([A] : Γ ⊩⟨ l′ ⟩ A ^ r)\n → Γ ⊩⟨ l ⟩ A ≡ B ∷ X ^ [ ! , ll ] / U-intr [U]\n → Γ ⊩⟨ l′ ⟩ A ≡ B ^ r / [A]\nunivEqEq′ {l} {ll} {l″} {Γ} {X} {A} {B} (noemb (Uᵣ r l′ l< eq [[ ⊢A , ⊢B , D ]])) [A]\n (Uₜ₌ (Uₜ K d typeK K≡K [t]) [u] A≡B [t≡u]) =\n let ⊢Γ = wf ⊢A in\n irrelevanceEq″ (Definition.Untyped.Properties.wk-id A) (Definition.Untyped.Properties.wk-id B) PE.refl PE.refl\n (emb l< ([t] Definition.Typed.Weakening.id ⊢Γ)) [A]\n ([t≡u] Definition.Typed.Weakening.id ⊢Γ)\nunivEqEq′ (emb emb< X) [A] [A≡B] = univEqEq′ X [A] [A≡B]\nunivEqEq′ (emb ∞< X) [A] [A≡B] = univEqEq′ X [A] [A≡B]\n\nUnivNotℕ : ∀ {Γ r ll} → Γ ⊩ℕ Univ r ll → ⊥\nUnivNotℕ {ll = ⁰} [[ ⊢A , ⊢B , D ]] = U≢ℕ (whrDet* (id (univ (univ 0<1 (wf ⊢A))) , Uₙ) (D , ℕₙ))\nUnivNotℕ {ll = ¹} [[ ⊢A , ⊢B , D ]] = U≢ℕ (whrDet* (id (Uⱼ (wf ⊢A)) , Uₙ) (D , ℕₙ))\n\nUnivNotΠ : ∀ {Γ r r' lΠ l ll} → (l LogRel.⊩¹Π logRelRec l ^[ Γ , Univ r ll ]) r' lΠ → ⊥ \nUnivNotΠ {ll = ⁰} (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) = U≢Π (whrDet* (id (univ (univ 0<1 (wf ⊢F))) , Uₙ) (red D , Πₙ))\nUnivNotΠ {ll = ¹} (Πᵣ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) = U≢Π (whrDet* (id (Uⱼ (wf ⊢F)) , Uₙ) (red D , Πₙ))\n\nU-Relevance-Level-eq : ∀ {l Γ r ll ll'} ([U] : Γ ⊩⟨ l ⟩ Univ r ll ^ [ ! , ll' ]) → U-Relevance-Level (U-elim [U]) PE.≡ (r , ll)\nU-Relevance-Level-eq {ll = ⁰} (Uᵣ (Uᵣ r ⁰ l< eq d)) = ×-eq (Univ-PE-injectivity (whrDet* (red d , Uₙ) (id (univ (univ 0<1 (wf (_⊢_:⇒*:_^_.⊢A d)))) , Uₙ)))\nU-Relevance-Level-eq {ll = ¹} (Uᵣ (Uᵣ r ⁰ l< eq d)) = let _ , X = (Univ-PE-injectivity (whrDet* (red d , Uₙ) (id (Uⱼ (wf (_⊢_:⇒*:_^_.⊢A d))) , Uₙ))) in ⊥-elim (⁰≢¹ X)\nU-Relevance-Level-eq {ll = ¹} (Uᵣ (Uᵣ r ¹ l< eq d)) = ×-eq (Univ-PE-injectivity (whrDet* (red d , Uₙ) (id (Uⱼ (wf (_⊢_:⇒*:_^_.⊢A d))) , Uₙ)))\nU-Relevance-Level-eq (ℕᵣ X) = ⊥-elim (UnivNotℕ X)\nU-Relevance-Level-eq (ne′ K D neK K≡K) = ⊥-elim (U≢ne neK (whnfRed* (red D) Uₙ))\nU-Relevance-Level-eq (Πᵣ X) = ⊥-elim (UnivNotΠ X)\nU-Relevance-Level-eq {ι ¹} (emb l< (ℕᵣ X)) = ⊥-elim (UnivNotℕ X)\nU-Relevance-Level-eq {ι ¹} (emb l< (ne′ K D neK K≡K)) = ⊥-elim (U≢ne neK (whnfRed* (red D) Uₙ))\nU-Relevance-Level-eq {ι ¹} (emb l< (Πᵣ X)) = ⊥-elim (UnivNotΠ X)\nU-Relevance-Level-eq {∞} {ll = ⁰} (emb ∞< (Uᵣ (Uᵣ r ⁰ l<₁ eq d))) = ×-eq (Univ-PE-injectivity (whrDet* (red d , Uₙ) (id (univ (univ 0<1 (wf (_⊢_:⇒*:_^_.⊢A d)))) , Uₙ)))\nU-Relevance-Level-eq {∞} {ll = ¹} (emb ∞< (Uᵣ (Uᵣ r ⁰ l<₁ eq d))) = let _ , X = (Univ-PE-injectivity (whrDet* (red d , Uₙ) (id (Uⱼ (wf (_⊢_:⇒*:_^_.⊢A d))) , Uₙ))) in ⊥-elim (⁰≢¹ X)\nU-Relevance-Level-eq {∞} {ll = ¹} (emb ∞< (Uᵣ (Uᵣ r ¹ l<₁ eq d))) = ×-eq (Univ-PE-injectivity (whrDet* (red d , Uₙ) (id (Uⱼ (wf (_⊢_:⇒*:_^_.⊢A d))) , Uₙ)))\nU-Relevance-Level-eq {∞} (emb {l′ = ι ¹} l< (ℕᵣ X)) = ⊥-elim (UnivNotℕ X)\nU-Relevance-Level-eq {∞} (emb {l′ = ι ¹} l< (ne′ K D neK K≡K)) = ⊥-elim (U≢ne neK (whnfRed* (red D) Uₙ))\nU-Relevance-Level-eq {∞} (emb {l′ = ι ¹} l< (Πᵣ x)) = ⊥-elim (UnivNotΠ x)\nU-Relevance-Level-eq {∞} (emb {l′ = ι ¹} l< (emb {l′ = ι ⁰} emb< (ℕᵣ x))) = ⊥-elim (UnivNotℕ x)\nU-Relevance-Level-eq {∞} (emb {l′ = ι ¹} l< (emb {l′ = ι ⁰} emb< (ne′ K D neK K≡K))) = ⊥-elim (U≢ne neK (whnfRed* (red D) Uₙ))\nU-Relevance-Level-eq {∞} (emb {l′ = ι ¹} l< (emb {l′ = ι ⁰} emb< (Πᵣ x))) = ⊥-elim (UnivNotΠ x)\n\nhelper-eq : ∀ {l Γ A B r r'} {[A] : Γ ⊩⟨ l ⟩ A ^ r} (e : r PE.≡ r' ) → Γ ⊩⟨ l ⟩ A ≡ B ^ r' / (PE.subst _ e [A]) → Γ ⊩⟨ l ⟩ A ≡ B ^ r / [A]\nhelper-eq PE.refl X = X\n\n-- Reducible term equality of type U is reducible type equality.\nunivEqEq : ∀ {l l′ Γ A B r ll} ([U] : Γ ⊩⟨ l ⟩ Univ r ll ^ [ ! , next ll ]) ([A] : Γ ⊩⟨ l′ ⟩ A ^ [ r , ι ll ])\n → Γ ⊩⟨ l ⟩ A ≡ B ∷ Univ r ll ^ [ ! , next ll ] / [U]\n → Γ ⊩⟨ l′ ⟩ A ≡ B ^ [ r , ι ll ] / [A]\nunivEqEq {l} {l′} {Γ} {A} {B} {r} {ll} [U] [A] [A≡B] =\n let [A≡B]′ = irrelevanceEqTerm [U] (U-intr (U-elim [U])) [A≡B]\n X = univEqEq′ (U-elim [U]) (PE.subst (λ r → Γ ⊩⟨ l′ ⟩ A ^ r) (PE.sym (PE.cong toTypeInfo (U-Relevance-Level-eq [U]))) [A]) [A≡B]′\n in helper-eq (PE.sym (PE.cong toTypeInfo (U-Relevance-Level-eq [U]))) X\n\nunivEqEqTerm : ∀ {Γ A t u r l′ ll}\n → ([U] : Γ ⊩⟨ ∞ ⟩ Univ r l′ ^ [ ! , ll ] )\n → ([A] : Γ ⊩⟨ ∞ ⟩ A ∷ Univ r l′ ^ [ ! , ll ] / [U])\n → Γ ⊩⟨ ∞ ⟩ t ∷ A ^ [ r , ι l′ ] / maybeEmb (univ⊩ [U] [A])\n → Γ ⊩⟨ ∞ ⟩ t ≡ u ∷ A ^ [ r , ι l′ ] / maybeEmb (univ⊩ [U] [A])\n → Γ ⊩⟨ ι l′ ⟩ t ≡ u ∷ A ^ [ r , ι l′ ] / univEq [U] [A]\nunivEqEqTerm {Γ} {A} {t} {u} {r} {⁰} [U] [A] [t] [t≡u] = [t≡u]\nunivEqEqTerm {Γ} {A} {t} {u} {r} {¹} [U] [A] [t] [t≡u] = [t≡u]\n\n\n\nun-univEq : ∀ {l Γ A r }\n → ([A] : Γ ⊩⟨ ι l ⟩ A ^ [ r , ι l ])\n → let [U] : Γ ⊩⟨ next l ⟩ Univ r l ^ [ ! , next l ]\n [U] = Ugen (wf (escape [A]))\n in Γ ⊩⟨ next l ⟩ A ∷ Univ r l ^ [ ! , next l ] / [U]\nun-univEq {⁰} {Γ} {A} {.!} (ℕᵣ [[ ⊢A , ⊢ℕ , D ]] ) = Uₜ ℕ (un-univ:⇒*: [[ ⊢A , ⊢ℕ , D ]]) ℕₙ (≅ₜ-ℕrefl (wf ⊢A)) (λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (ℕᵣ [[ ⊢A , ⊢ℕ , D ]] ))\nun-univEq {⁰} {Γ} {A} {.%} (Emptyᵣ [[ ⊢A , ⊢Empty , D ]]) = Uₜ (Empty ⁰) (un-univ:⇒*: [[ ⊢A , ⊢Empty , D ]]) Emptyₙ (≅ₜ-Emptyrefl (wf ⊢A))\n (λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (Emptyᵣ [[ ⊢A , ⊢Empty , D ]] ))\nun-univEq {⁰} {Γ} {A} {r} (ne′ K D neK K≡K) = Uₜ K (un-univ:⇒*: D) (ne neK) (~-to-≅ₜ K≡K) (λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (ne′ K D neK K≡K))\nun-univEq {⁰} {Γ} {A} {r} (Πᵣ′ rF .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F G D ⊢F ⊢G A≡A [F] [G] G-ext) =\n Uₜ (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) (un-univ:⇒*: D) Πₙ (≅-un-univ A≡A) λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (Πᵣ′ rF ⁰ ⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F G D ⊢F ⊢G A≡A [F] [G] G-ext)\nun-univEq {⁰} {Γ} {A} {.%} (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) =\n Uₜ (∃ F ▹ G) (un-univ:⇒*: D) ∃ₙ (≅-un-univ A≡A) λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext)\nun-univEq {¹} {Γ} {A} {.!} (Uᵣ (Uᵣ r .⁰ emb< eq [[ ⊢A , ⊢B , D ]])) = Uₜ (Univ r ⁰) (un-univ:⇒*: [[ ⊢A , ⊢B , D ]]) Uₙ (≅-U⁰refl (wf ⊢A))\n (λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (Uᵣ (Uᵣ r ⁰ emb< eq [[ ⊢A , ⊢B , D ]] )))\nun-univEq {¹} {Γ} {A} {.%} (Emptyᵣ [[ ⊢A , ⊢Empty , D ]]) = Uₜ (Empty ¹) (un-univ:⇒*: [[ ⊢A , ⊢Empty , D ]]) Emptyₙ (≅ₜ-Emptyrefl (wf ⊢A))\n (λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (Emptyᵣ [[ ⊢A , ⊢Empty , D ]] ))\nun-univEq {¹} {Γ} {A} {r} (ne′ K D neK K≡K) = Uₜ K (un-univ:⇒*: D) (ne neK) (~-to-≅ₜ K≡K) (λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (ne′ K D neK K≡K))\nun-univEq {¹} {Γ} {A} {r} (Πᵣ′ rF lF lG lF< lG< F G D ⊢F ⊢G A≡A [F] [G] G-ext) = \n Uₜ (Π F ^ rF ° lF ▹ G ° lG ° ¹ ) (un-univ:⇒*: D) Πₙ (≅-un-univ A≡A) λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (Πᵣ′ rF lF lG lF< lG< F G D ⊢F ⊢G A≡A [F] [G] G-ext)\nun-univEq {¹} {Γ} {A} {.%} (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) =\n Uₜ (∃ F ▹ G) (un-univ:⇒*: D) ∃ₙ (≅-un-univ A≡A) λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext)\nun-univEq {¹} {Γ} {A} {.%} (emb emb< (Emptyᵣ [[ ⊢A , ⊢Empty , D ]])) = Uₜ (Empty ¹) (un-univ:⇒*: [[ ⊢A , ⊢Empty , D ]]) Emptyₙ (≅ₜ-Emptyrefl (wf ⊢A))\n (λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (Emptyᵣ [[ ⊢A , ⊢Empty , D ]] ))\nun-univEq {¹} {Γ} {A} {r} (emb emb< (ne′ K D neK K≡K)) = Uₜ K (un-univ:⇒*: D) (ne neK) (~-to-≅ₜ K≡K) (λ [ρ] ⊢Δ → Lwk.wk [ρ] ⊢Δ (ne′ K D neK K≡K))\nun-univEq {¹} {Γ} {A} {r} (emb emb< (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) =\n Uₜ (Π F ^ rF ° lF ▹ G ° lG ° ¹) (un-univ:⇒*: D) Πₙ (≅-un-univ A≡A) λ [ρ] ⊢Δ → let X = Lwk.wk [ρ] ⊢Δ (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) in maybeEmb′ ( 2\n--\nSpanShape : FinCatShape\nSpanShape = record\n { size = 3\n ; ∣_⇒_∣ = morph\n ; hasShape = record\n { id = id\n ; _∘_ = _∘_\n ; assoc = assoc\n ; identityˡ = identityˡ\n ; identityʳ = identityʳ\n }\n }\n where morph : Fin 3 → Fin 3 → ℕ\n morph 0F 0F = 1\n morph 0F 1F = 1\n morph 0F 2F = 1\n morph 1F 1F = 1\n morph 2F 2F = 1\n morph _ _ = 0\n\n id : Fin (morph a a)\n id {0F} = 0F\n id {1F} = 0F\n id {2F} = 0F\n\n _∘_ : ∀ {a b c} → Fin (morph b c) → Fin (morph a b) → Fin (morph a c)\n _∘_ {0F} {0F} {0F} 0F 0F = 0F\n _∘_ {0F} {0F} {1F} 0F 0F = 0F\n _∘_ {0F} {0F} {2F} 0F 0F = 0F\n _∘_ {0F} {1F} {1F} 0F 0F = 0F\n _∘_ {0F} {2F} {2F} 0F 0F = 0F\n _∘_ {1F} {1F} {1F} 0F 0F = 0F\n _∘_ {2F} {2F} {2F} 0F 0F = 0F\n\n assoc : ∀ {f : Fin (morph a b)} {g : Fin (morph b c)} {h : Fin (morph c d)} →\n ((h ∘ g) ∘ f) ≡ (h ∘ (g ∘ f))\n assoc {0F} {0F} {0F} {0F} {0F} {0F} {0F} = refl\n assoc {0F} {0F} {0F} {1F} {0F} {0F} {0F} = refl\n assoc {0F} {0F} {0F} {2F} {0F} {0F} {0F} = refl\n assoc {0F} {0F} {1F} {1F} {0F} {0F} {0F} = refl\n assoc {0F} {0F} {2F} {2F} {0F} {0F} {0F} = refl\n assoc {0F} {1F} {1F} {1F} {0F} {0F} {0F} = refl\n assoc {0F} {2F} {2F} {2F} {0F} {0F} {0F} = refl\n assoc {1F} {1F} {1F} {1F} {0F} {0F} {0F} = refl\n assoc {2F} {2F} {2F} {2F} {0F} {0F} {0F} = refl\n\n identityˡ : ∀ {f : Fin (morph a b)} → (id ∘ f) ≡ f\n identityˡ {0F} {0F} {0F} = refl\n identityˡ {0F} {1F} {0F} = refl\n identityˡ {0F} {2F} {0F} = refl\n identityˡ {1F} {1F} {0F} = refl\n identityˡ {2F} {2F} {0F} = refl\n\n identityʳ : ∀ {f : Fin (morph a b)} → (f ∘ id) ≡ f\n identityʳ {0F} {0F} {0F} = refl\n identityʳ {0F} {1F} {0F} = refl\n identityʳ {0F} {2F} {0F} = refl\n identityʳ {1F} {1F} {0F} = refl\n identityʳ {2F} {2F} {0F} = refl\n\nSpan : Category _ _ _\nSpan = FinCategory SpanShape\n\nmodule Span = Category Span\n\nopen FinCatShape SpanShape\n\nSpanToF : Functor Span Sp.Span\nSpanToF = record\n { F₀ = F₀\n ; F₁ = F₁\n ; identity = identity\n ; homomorphism = homomorphism\n ; F-resp-≈ = F-resp-≈\n }\n where F₀ : Fin 3 → Sp.SpanObj\n F₀ 0F = Sp.center\n F₀ 1F = Sp.left\n F₀ 2F = Sp.right\n\n F₁ : Fin ∣ a ⇒ b ∣ → Sp.SpanArr (F₀ a) (F₀ b)\n F₁ {0F} {0F} 0F = Sp.span-id\n F₁ {0F} {1F} 0F = Sp.span-arrˡ\n F₁ {0F} {2F} 0F = Sp.span-arrʳ\n F₁ {1F} {1F} 0F = Sp.span-id\n F₁ {2F} {2F} 0F = Sp.span-id\n\n identity : F₁ (id {a}) ≡ Sp.span-id\n identity {0F} = refl\n identity {1F} = refl\n identity {2F} = refl\n\n homomorphism : ∀ {f : Fin ∣ a ⇒ b ∣} {g : Fin ∣ b ⇒ c ∣} →\n F₁ (g ∘ f) ≡ Sp.span-compose (F₁ g) (F₁ f)\n homomorphism {0F} {0F} {0F} {0F} {0F} = refl\n homomorphism {0F} {0F} {1F} {0F} {0F} = refl\n homomorphism {0F} {0F} {2F} {0F} {0F} = refl\n homomorphism {0F} {1F} {1F} {0F} {0F} = refl\n homomorphism {0F} {2F} {2F} {0F} {0F} = refl\n homomorphism {1F} {1F} {1F} {0F} {0F} = refl\n homomorphism {2F} {2F} {2F} {0F} {0F} = refl\n\n F-resp-≈ : ∀ {f g : Fin ∣ a ⇒ b ∣} → f ≡ g → F₁ f ≡ F₁ g\n F-resp-≈ {0F} {0F} {0F} {0F} _ = refl\n F-resp-≈ {0F} {1F} {0F} {0F} _ = refl\n F-resp-≈ {0F} {2F} {0F} {0F} _ = refl\n F-resp-≈ {1F} {1F} {0F} {0F} _ = refl\n F-resp-≈ {2F} {2F} {0F} {0F} _ = refl\n\nmodule SpanToF = Functor SpanToF\n\nSpanFromF : Functor Sp.Span Span\nSpanFromF = record\n { F₀ = F₀\n ; F₁ = F₁\n ; identity = identity\n ; homomorphism = homomorphism\n ; F-resp-≈ = F-resp-≈\n }\n where F₀ : Sp.SpanObj → Fin 3\n F₀ Sp.center = 0F\n F₀ Sp.left = 1F\n F₀ Sp.right = 2F\n\n F₁ : ∀ {A B} → Sp.Span [ A , B ] → Span [ F₀ A , F₀ B ]\n F₁ {Sp.center} Sp.span-id = 0F\n F₁ {Sp.left} Sp.span-id = 0F\n F₁ {Sp.right} Sp.span-id = 0F\n F₁ Sp.span-arrˡ = 0F\n F₁ Sp.span-arrʳ = 0F\n\n identity : ∀ {A} → F₁ (Category.id Sp.Span {A}) ≡ id\n identity {Sp.center} = refl\n identity {Sp.left} = refl\n identity {Sp.right} = refl\n\n homomorphism : ∀ {X Y Z} {f : Sp.Span [ X , Y ]} {g : Sp.Span [ Y , Z ]} →\n F₁ (Sp.Span [ g ∘ f ]) ≡ F₁ g ∘ F₁ f\n homomorphism {Sp.center} {_} {_} {Sp.span-id} {Sp.span-id} = refl\n homomorphism {Sp.left} {_} {_} {Sp.span-id} {Sp.span-id} = refl\n homomorphism {Sp.right} {_} {_} {Sp.span-id} {Sp.span-id} = refl\n homomorphism {_} {_} {_} {Sp.span-id} {Sp.span-arrˡ} = refl\n homomorphism {_} {_} {_} {Sp.span-id} {Sp.span-arrʳ} = refl\n homomorphism {_} {_} {_} {Sp.span-arrˡ} {Sp.span-id} = refl\n homomorphism {_} {_} {_} {Sp.span-arrʳ} {Sp.span-id} = refl\n\n F-resp-≈ : ∀ {A B} {f g : Sp.Span [ A , B ]} → f ≡ g → F₁ f ≡ F₁ g\n F-resp-≈ {Sp.center} {_} {Sp.span-id} {Sp.span-id} _ = refl\n F-resp-≈ {Sp.left} {_} {Sp.span-id} {Sp.span-id} _ = refl\n F-resp-≈ {Sp.right} {_} {Sp.span-id} {Sp.span-id} _ = refl\n F-resp-≈ {.Sp.center} {.Sp.left} {Sp.span-arrˡ} {Sp.span-arrˡ} _ = refl\n F-resp-≈ {.Sp.center} {.Sp.right} {Sp.span-arrʳ} {Sp.span-arrʳ} _ = refl\n\nmodule SpanFromF = Functor SpanFromF\n\nSpansEquivF : SpanToF ⊣⊢ SpanFromF\nSpansEquivF = withZig record\n { unit = unit\n ; counit = counit\n ; zig = zig\n }\n where unit⇒η : ∀ a → Fin ∣ a ⇒ SpanFromF.₀ (SpanToF.₀ a) ∣\n unit⇒η 0F = 0F\n unit⇒η 1F = 0F\n unit⇒η 2F = 0F\n unit⇐η : ∀ a → Fin ∣ SpanFromF.₀ (SpanToF.₀ a) ⇒ a ∣\n unit⇐η 0F = 0F\n unit⇐η 1F = 0F\n unit⇐η 2F = 0F\n\n unit : idF ≃ SpanFromF ∘F SpanToF\n unit = record\n { F⇒G = ntHelper record\n { η = unit⇒η\n ; commute = commute₁\n }\n ; F⇐G = ntHelper record\n { η = unit⇐η\n ; commute = commute₂\n }\n ; iso = iso\n }\n where open Mor Span\n commute₁ : ∀ (f : Fin ∣ a ⇒ b ∣) → unit⇒η b ∘ f ≡ SpanFromF.₁ (SpanToF.₁ f) ∘ unit⇒η a\n commute₁ {0F} {0F} 0F = refl\n commute₁ {0F} {1F} 0F = refl\n commute₁ {0F} {2F} 0F = refl\n commute₁ {1F} {1F} 0F = refl\n commute₁ {2F} {2F} 0F = refl\n commute₂ : ∀ (f : Fin ∣ a ⇒ b ∣) → unit⇐η b ∘ SpanFromF.₁ (SpanToF.₁ f) ≡ f ∘ unit⇐η a\n commute₂ {0F} {0F} 0F = refl\n commute₂ {0F} {1F} 0F = refl\n commute₂ {0F} {2F} 0F = refl\n commute₂ {1F} {1F} 0F = refl\n commute₂ {2F} {2F} 0F = refl\n\n iso : ∀ a → Iso (unit⇒η a) (unit⇐η a)\n iso 0F = record\n { isoˡ = refl\n ; isoʳ = refl\n }\n iso 1F = record\n { isoˡ = refl\n ; isoʳ = refl\n }\n iso 2F = record\n { isoˡ = refl\n ; isoʳ = refl\n }\n\n counit⇒η : ∀ X → Sp.Span [ Functor.F₀ (SpanToF ∘F SpanFromF) X , X ]\n counit⇒η Sp.center = Sp.span-id\n counit⇒η Sp.left = Sp.span-id\n counit⇒η Sp.right = Sp.span-id\n\n counit⇐η : ∀ X → Sp.Span [ X , Functor.F₀ (SpanToF ∘F SpanFromF) X ]\n counit⇐η Sp.center = Sp.span-id\n counit⇐η Sp.left = Sp.span-id\n counit⇐η Sp.right = Sp.span-id\n\n counit : SpanToF ∘F SpanFromF ≃ idF\n counit = record\n { F⇒G = ntHelper record\n { η = counit⇒η\n ; commute = commute₁\n }\n ; F⇐G = ntHelper record\n { η = counit⇐η\n ; commute = commute₂\n }\n ; iso = iso\n }\n where open Mor Sp.Span\n commute₁ : ∀ {X Y} (f : Sp.SpanArr X Y) →\n Sp.span-compose (counit⇒η Y) (SpanToF.₁ (SpanFromF.₁ f)) ≡ Sp.span-compose f (counit⇒η X)\n commute₁ {Sp.center} {.Sp.center} Sp.span-id = refl\n commute₁ {Sp.left} {.Sp.left} Sp.span-id = refl\n commute₁ {Sp.right} {.Sp.right} Sp.span-id = refl\n commute₁ {.Sp.center} {.Sp.left} Sp.span-arrˡ = refl\n commute₁ {.Sp.center} {.Sp.right} Sp.span-arrʳ = refl\n\n commute₂ : ∀ {X Y} (f : Sp.SpanArr X Y) →\n Sp.span-compose (counit⇐η Y) f ≡ Sp.span-compose (SpanToF.₁ (SpanFromF.₁ f)) (counit⇐η X)\n commute₂ {Sp.center} {.Sp.center} Sp.span-id = refl\n commute₂ {Sp.left} {.Sp.left} Sp.span-id = refl\n commute₂ {Sp.right} {.Sp.right} Sp.span-id = refl\n commute₂ {.Sp.center} {.Sp.left} Sp.span-arrˡ = refl\n commute₂ {.Sp.center} {.Sp.right} Sp.span-arrʳ = refl\n\n iso : ∀ X → Iso (counit⇒η X) (counit⇐η X)\n iso Sp.center = record\n { isoˡ = refl\n ; isoʳ = refl\n }\n iso Sp.left = record\n { isoˡ = refl\n ; isoʳ = refl\n }\n iso Sp.right = record\n { isoˡ = refl\n ; isoʳ = refl\n }\n\n zig : ∀ {a} → Sp.span-compose (counit⇒η (SpanToF.₀ a)) (SpanToF.₁ (unit⇒η a)) ≡ Sp.span-id\n zig {0F} = refl\n zig {1F} = refl\n zig {2F} = refl\n\nSpansEquiv : ⊣Equivalence Span Sp.Span\nSpansEquiv = record { L⊣⊢R = SpansEquivF }\n\nmodule SpansEquiv = ⊣Equivalence SpansEquiv\n", "meta": {"hexsha": "9b702ac69c479f67a16751d8d9b05fee7f2b3ce7", "size": 10676, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Categories/Category/Finite/Fin/Instance/Span.agda", "max_stars_repo_name": "MirceaS/agda-categories", "max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "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/Categories/Category/Finite/Fin/Instance/Span.agda", "max_issues_repo_name": "MirceaS/agda-categories", "max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "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/Categories/Category/Finite/Fin/Instance/Span.agda", "max_forks_repo_name": "MirceaS/agda-categories", "max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "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.7056856187, "max_line_length": 118, "alphanum_fraction": 0.4689958786, "num_tokens": 4158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056295505783, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3634822481205748}} {"text": "{-# OPTIONS --rewriting --prop #-}\n\nopen import common\n\nopen import syntx as N\nopen import derivability as N2\nopen import typingrules\nopen import structuralrules\nopen import typetheories\nopen import examples\n\nopen import traditional as T\n\nΣ : Signature\nΣ = TTSig ΠUEl-TT\n\n\n{- Maps between expressions -}\n\nT→N : {n : ℕ} {k : SyntaxSort} → T.Expr k n → N.Expr Σ n k\nT→N uu = sym 1 []\nT→N (el v) = sym 0 ([] , T→N v)\nT→N (pi A B) = sym 4 ([] , T→N A , T→N B)\nT→N (var x) = var x\nT→N (lam A B u) = sym 3 ([] , T→N A , T→N B , T→N u)\nT→N (app A B f a) = sym 2 ([] , T→N A , T→N B , T→N f , T→N a)\n\n\nN→T : {n : ℕ} {k : SyntaxSort} → N.Expr Σ n k → T.Expr k n\nN→T (var x) = var x\nN→T (sym (prev (prev (prev (prev new)))) ([] , A , B)) = pi (N→T A) (N→T B)\nN→T (sym (prev (prev (prev new))) ([] , A , B , u)) = lam (N→T A) (N→T B) (N→T u)\nN→T (sym (prev (prev new)) ([] , A , B , f , a)) = app (N→T A) (N→T B) (N→T f) (N→T a)\nN→T (sym (prev new) []) = uu\nN→T (sym new ([] , v)) = el (N→T v)\n\n\n{- Equalities -}\n\nTNT : {n : ℕ} {k : SyntaxSort} (e : N.Expr Σ n k) → T→N (N→T e) ≡ e\nTNT (var x) = refl\nTNT (sym (prev (prev (prev (prev new)))) ([] , A , B)) = ap2 (λ x y → sym 4 ([] , x , y)) (TNT A) (TNT B)\nTNT (sym (prev (prev (prev new))) ([] , A , B , u)) = ap3 (λ x y z → sym 3 ([] , x , y , z)) (TNT A) (TNT B) (TNT u)\nTNT (sym (prev (prev new)) ([] , A , B , f , a)) = ap4 (λ x y z t → sym 2 ([] , x , y , z , t)) (TNT A) (TNT B) (TNT f) (TNT a)\nTNT (sym (prev new) []) = refl\nTNT (sym new ([] , v)) = ap (λ v → sym 0 ([] , v)) (TNT v)\n\n\nNTN : {n : ℕ} {k : SyntaxSort} (e : T.Expr k n) → N→T (T→N e) ≡ e\nNTN uu = refl\nNTN (el v) = ap el (NTN v)\nNTN (pi A B) = ap2 pi (NTN A) (NTN B)\nNTN (var x) = refl\nNTN (lam A B u) = ap3 lam (NTN A) (NTN B) (NTN u)\nNTN (app A B f a) = ap4 app (NTN A) (NTN B) (NTN f) (NTN a)\n\n\n{- Derivability -}\n\ndata NJudgment : Set where\n njudgment : {n : ℕ} (Γ : N.Ctx Σ n) {k : JudgmentSort} → N2.Judgment Σ Γ 0 k → NJudgment\n\nNDerivable : NJudgment → Prop\nNDerivable (njudgment Γ j) = N2.Derivable (TTDer ΠUEl-TT) j\n\n-- record NJudgment : Set where\n-- constructor njudgment\n-- field\n-- {NJn} : ℕ\n-- NJΓ : N.Ctx (TTSig ΠUEl-TT4) NJn\n-- {NJk} : JudgmentSort\n-- NJj : N2.Judgment (TTSig ΠUEl-TT4) NJΓ 0 NJk\n\n-- open NJudgment\n\n-- record NDerivable (j : NJudgment) : Prop where\n-- constructor ´_\n\n-- field\n-- `_ : N2.Derivable (TTDer ΠUEl-TT4) (NJj j)\n\n-- open NDerivable\n\n-- -- `_ : NDerivable (njudgment Γ j) → N2.Derivable (TTDer ΠUEl-TT) j\n-- -- `_ d = d\n\n-- -- ´_ : {n : ℕ} {Γ : N.Ctx Σ n} {k : JudgmentSort} {j : N2.Judgment Σ Γ 0 k} → N2.Derivable (TTDer ΠUEl-TT) j → NDerivable (njudgment Γ j)\n-- -- ´_ d = d\n\nNDerivable= : {j j' : NJudgment} (j= : j ≡ j') → NDerivable j' → NDerivable j\nNDerivable= refl x = x\n\nNDerivable=! : {j j' : NJudgment} (j= : j ≡ j') → NDerivable j → NDerivable j'\nNDerivable=! refl x = x\n\nT→NCtx : {n : ℕ} → T.Ctx n → N.Ctx Σ n\nT→NCtx ◇ = ◇\nT→NCtx (Γ , A) = (T→NCtx Γ , T→N A)\n\nT→NJ : T.Judgment → NJudgment\nT→NJ (Γ ⊢ A) = njudgment (T→NCtx Γ) (◇ ⊢ T→N A)\nT→NJ (Γ ⊢ u :> A) = njudgment (T→NCtx Γ) (◇ ⊢ T→N u :> T→N A)\nT→NJ (Γ ⊢ A == B) = njudgment (T→NCtx Γ) (◇ ⊢ T→N A == T→N B)\nT→NJ (Γ ⊢ u == v :> A) = njudgment (T→NCtx Γ) (◇ ⊢ T→N u == T→N v :> T→N A)\n\n\nweaken-comm : {k : SyntaxSort} {n : ℕ} {A : T.Expr k n} (p : WeakPos n) → N.weaken p (T→N A) ≡ T→N (T.weaken p A)\nweaken-comm {A = uu} p = refl\nweaken-comm {A = el v} p = ap (λ z → sym new ([] , z)) (weaken-comm p)\nweaken-comm {A = pi A B} p = ap2 (λ z z' → sym (prev (prev (prev (prev new)))) ([] , z , z')) (weaken-comm p) (weaken-comm (prev p))\nweaken-comm {A = var x} p = refl --ap var (weakenV-comm p x)\nweaken-comm {A = lam A B u} p = ap3 (λ z z' z'' → sym (prev (prev (prev new))) ([] , z , z' , z'')) (weaken-comm p) (weaken-comm (prev p)) (weaken-comm (prev p))\nweaken-comm {A = app A B f a} p = ap4 (λ z z' z'' z''' → sym (prev (prev new)) ([] , z , z' , z'' , z''')) (weaken-comm p) (weaken-comm (prev p)) (weaken-comm p) (weaken-comm p)\n\n\nVarPos→ℕ : {n : ℕ} → VarPos n → ℕ\nVarPos→ℕ last = 0\nVarPos→ℕ (prev k) = suc (VarPos→ℕ k)\n\nfst-VarPos→ℕ : {Σ : Signature} {n : ℕ} (k : VarPos n) (Γ : N.Ctx Σ n) {def : _} → fst (N.get (VarPos→ℕ k) Γ $ def) ≡ k\nfst-VarPos→ℕ last (Γ , A) = refl\nfst-VarPos→ℕ (prev k) (Γ , A) = ap prev (fst-VarPos→ℕ k Γ)\n\nsnd-VarPos→ℕ : {n : ℕ} (k : VarPos n) (Γ : T.Ctx n) {def : _} → snd (N.get (VarPos→ℕ k) (T→NCtx Γ) $ def) ≡ T→N (T.get k Γ)\nsnd-VarPos→ℕ last (Γ , A) = weaken-comm last\nsnd-VarPos→ℕ (prev k) (Γ , A) = ap (N.weaken last) (snd-VarPos→ℕ k Γ) ∙ weaken-comm last\n\nget-def : {n : ℕ} (k : VarPos n) (Γ : T.Ctx n) → isDefined (N.get (VarPos→ℕ k) (T→NCtx Γ))\nget-def last (Γ , A) = tt\nget-def (prev k) (Γ , A) = (get-def k Γ , tt)\n\n\nMorInsert : {Σ : Signature} (x : WeakPos m) (δ : N.Mor Σ n m) (u : N.TmExpr Σ n) → N.Mor Σ n (suc m)\nMorInsert last δ u = (δ , u)\nMorInsert (prev x) (δ , v) u = (MorInsert x δ u , v)\n\n{-# REWRITE +O-rewrite #-}\n{-# REWRITE +S-rewrite #-}\n{-# REWRITE assoc #-}\n\nweaken-MorInsert : {Σ : Signature} {n k : ℕ} {x : WeakPos n} {δ : N.Mor Σ k n} {u : N.TmExpr Σ k}\n → N.weakenMor (MorInsert x δ u) ≡ MorInsert x (N.weakenMor δ) (N.weaken last u)\nweaken-MorInsert {x = last} = refl\nweaken-MorInsert {x = prev x} {δ , u} = ap2 _,_ weaken-MorInsert refl\n\nImpossible : {n k : ℕ} {A : Prop} → suc (n + k) ≤ n → A\nImpossible {suc n} {k = zero} (≤S p) = Impossible p\nImpossible {suc n} {k = suc k} p = Impossible (≤P p)\n\nweakenV-η : (x : WeakPos n) (y : VarPos n) {p : n ≤ n} → y ≡ weakenV {{p}} x y\nweakenV-η x y {≤r} = ! weakenV≤r\nweakenV-η x y {≤S p} = Impossible p\n\nweaken-η : {Σ : Signature} {k : _} {x : _} {p : n ≤ n} {u : N.Expr Σ n k} → u ≡ N.weaken {{p}} x u\nweakenA-η : {Σ : Signature} {k : _} {x : _} {p : n ≤ n} {u : N.Args Σ n k} → u ≡ N.weakenA {{p}} x u\n\nweaken-η {x = x} {u = var y} = ap var (weakenV-η x y)\nweaken-η {u = sym s us} = ap (sym s) weakenA-η\n\nweakenA-η {u = []} = refl\nweakenA-η {u = u , x} = ap2 _,_ weakenA-η weaken-η\n\nWeakPosIncl : {n m : ℕ} {{_ : n ≤ m}} → WeakPos n → WeakPos m\nWeakPosIncl last = last\nWeakPosIncl {m = suc m} {{p}} (prev x) = prev (WeakPosIncl {{≤P p}} x)\n\n≤P-≤SS : {n m : ℕ} (p : n ≤ m) → p ≡ ≤P (≤SS {{p}})\n≤P-≤SS ≤r = refl\n≤P-≤SS (≤S p) = ap ≤S (≤P-≤SS _)\n\nWeakPosIncl-comm : {n m k : ℕ} {{p : n ≤ m}} {x : WeakPos n} → weakenPos (≤-+ {m = k}) (WeakPosIncl {{p}} x) ≡ WeakPosIncl {{≤+ k {{p}}}} (weakenPos ≤-+ x)\nWeakPosIncl-comm {k = zero} {x = last} = refl\nWeakPosIncl-comm {k = suc k} {x = last} = ap prev (WeakPosIncl-comm {k = k} {x = last} ∙ ap (λ z → WeakPosIncl {{z}} (weakenPos ≤-+ last)) (≤P-≤SS _))\nWeakPosIncl-comm {m = suc m} {zero} {x = prev x} = refl\nWeakPosIncl-comm {m = suc m} {suc k} {x = prev x} = ap prev (WeakPosIncl-comm {m = suc m} {k = k} {x = prev x} ∙ ap (λ z → WeakPosIncl {{z}} (weakenPos ≤-+ (prev x))) (≤P-≤SS _))\n\n≤-ishProp : {n m : ℕ} (p q : n ≤ m) → p ≡ q\n≤-ishProp ≤r ≤r = refl\n≤-ishProp ≤r (≤S q) = Impossible q\n≤-ishProp (≤S p) ≤r = Impossible p\n≤-ishProp (≤S p) (≤S q) = ap ≤S (≤-ishProp p q)\n\nweakenV-μ : {n m k : ℕ} {{p : n ≤ m}} {{q : m ≤ k}} {{r : n ≤ k}} {x : VarPos n} {y : WeakPos n}\n → weakenV {{q}} (WeakPosIncl y) (weakenV {{p}} y x) ≡ weakenV {{r}} y x\nweakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤r ⦄ ⦃ ≤r ⦄ = weakenV≤r\nweakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤r ⦄ ⦃ ≤S r ⦄ = Impossible r\nweakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤S q ⦄ ⦃ ≤r ⦄ = Impossible q\nweakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤S q ⦄ ⦃ ≤S r ⦄ {x} {y = last} = ap2 (λ z z' → prev (weakenV ⦃ z ⦄ last z')) (≤-ishProp _ _) weakenV≤r\nweakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤S q ⦄ ⦃ ≤S r ⦄ {last} {y = prev y} = refl\nweakenV-μ ⦃ p = ≤r ⦄ ⦃ ≤S q ⦄ ⦃ ≤S r ⦄ {prev x} {y = prev y} = ap prev (ap (weakenV {{≤P (≤S q)}} (WeakPosIncl y)) (! weakenV≤r) ∙ weakenV-μ {{≤r}} {{≤P (≤S q)}} {{≤P (≤S r)}} {x = x} {y})\nweakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤r ⦄ ⦃ ≤r ⦄ = Impossible p\nweakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤r ⦄ ⦃ ≤S r ⦄ {x} {y} = weakenV≤r {p = WeakPosIncl {{≤S p}} y} {v = weakenV {{≤S p}} y x} ∙ ap (λ z → weakenV ⦃ z ⦄ y x) (≤-ishProp _ _) --\nweakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤S q ⦄ ⦃ ≤r ⦄ = Impossible (≤tr {{≤S p}} {{q}})\nweakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤S q ⦄ ⦃ ≤S ≤r ⦄ = Impossible (≤tr {{q}} {{p}})\nweakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤S q ⦄ ⦃ ≤S (≤S r) ⦄ {x} {y = last} = ap prev (weakenV-μ {{≤S p}} {{q}} {{≤S r}} {x} {last})\nweakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤S q ⦄ ⦃ ≤S (≤S r) ⦄ {last} {y = prev y} = refl\nweakenV-μ ⦃ p = ≤S p ⦄ ⦃ ≤S q ⦄ ⦃ ≤S (≤S r) ⦄ {prev x} {y = prev y} = ap prev (weakenV-μ {{≤P (≤S p)}} {{≤P (≤S q)}} {{≤P (≤S (≤S r))}} {x} {y})\n\nweaken-μ : {Σ : Signature} {k : _} {x : WeakPos n} {q : n ≤ m} {r : _} {u : N.Expr Σ n k} → N.weaken {{≤S ≤r}} (WeakPosIncl {{q}} x) (N.weaken {{q}} x u) ≡ N.weaken {{r}} x u\nweakenA-μ : {Σ : Signature} {k : _} {x : WeakPos n} {q : n ≤ m} {r : _} {u : N.Args Σ n k} → N.weakenA {{≤S ≤r}} (WeakPosIncl {{q}} x) (N.weakenA {{q}} x u) ≡ N.weakenA {{r}} x u\n\nweaken-μ {x = y} {q = p} {u = var x} = ap var ((weakenV-μ {{p}} {{≤S ≤r}} {{_}} {x = x} {y = y}))\nweaken-μ {u = sym s x} = ap (sym s) weakenA-μ\n\nweakenA-μ {u = []} = refl\nweakenA-μ {q = q} {u = u , x} = ap2 _,_ weakenA-μ (ap2 (λ z z' → N.weaken {{z}} z' (N.weaken {{≤+ _ {{q}}}} _ x))\n (≤-ishProp _ _)\n (WeakPosIncl-comm {{q}})\n ∙ weaken-μ {q = ≤+ _ {{q}}})\n\n\n\nweaken+-MorInsert : {Σ : Signature} (m : ℕ) {n k : ℕ} {x : WeakPos n} {δ : N.Mor Σ k n} {u : N.TmExpr Σ k}\n → N.weakenMor+ m (MorInsert x δ u) ≡ MorInsert (weakenPos ≤-+ x) (N.weakenMor+ m δ) (N.weaken last u)\nweaken+-MorInsert zero = ap (MorInsert _ _) weaken-η\nweaken+-MorInsert (suc m) = ap2 _,_ (ap N.weakenMor (weaken+-MorInsert m) ∙ weaken-MorInsert ∙ ap (MorInsert _ _) weaken-μ) refl\n\nSubstV-insert : {n m : ℕ} {y : VarPos n} {x : WeakPos n} {u : N.TmExpr Σ m} {δ : N.Mor Σ m n} {p : n ≤ suc n}\n → SubstMor (var (weakenV {{p}} x y)) (MorInsert x δ u) ≡ SubstMor (var y) δ\nSubstV-insert {x = last} {δ = δ} {p = ≤S ≤r} = ap (λ z → SubstMor (var z) δ) weakenV≤r\nSubstV-insert {y = last} {x = prev x} {δ = δ , v} {p = ≤S ≤r} = refl\nSubstV-insert {y = prev y} {x = prev x} {u} {δ = δ , v} {p = ≤S ≤r} = SubstV-insert {y = y} {x = x} {u = u} {δ = δ} {p = ≤S ≤r}\nSubstV-insert {p = ≤S (≤S p)} = Impossible p\n\nSubst-insert : {k : SyntaxSort} {n m : ℕ} {e : N.Expr Σ n k} {x : WeakPos n} {u : N.TmExpr Σ m} {δ : N.Mor Σ m n} {p : _}\n → SubstMor (N.weaken {{p}} x e) (MorInsert x δ u) ≡ SubstMor e δ\nSubstA-insert : {args : SyntaxArityArgs} {n m : ℕ} {es : N.Args Σ n args} {x : WeakPos n} {u : N.TmExpr Σ m} {δ : N.Mor Σ m n} {p : _}\n → SubstAMor (N.weakenA {{p}} x es) (MorInsert x δ u) ≡ SubstAMor es δ\n\nSubst-insert {e = var x} {x = x'} {u} {p = p} = SubstV-insert {x = x'} {u} {p = p}\nSubst-insert {e = sym s x} = ap (sym s) SubstA-insert\n\nSubstA-insert {es = []} = refl\nSubstA-insert {args} {n} {es = _,_ {m = m} es e} {x = x} {u = u} {p = p} =\n ap2 _,_ SubstA-insert (ap (SubstMor (N.weaken {{≤+ m {n} {suc n} {{p}}}} (weakenPos ≤-+ x) e)) (weaken+-MorInsert m) ∙ Subst-insert {e = e} {x = weakenPos ≤-+ x})\n\n\nweakenMor+-idMor : {n : ℕ} (m : ℕ) → N.weakenMor+ m (N.idMor {Σ = Σ} {n = n}) ≡ N.idMor\nweakenMor+-idMor zero = refl\nweakenMor+-idMor (suc m) = ap2 _,_ (ap N.weakenMor (weakenMor+-idMor m)) refl\n\nSubstMor-weakenMor : {x : VarPos n} {δ : N.Mor Σ m n} → SubstMor (var x) (N.weakenMor δ) ≡ N.weaken last (SubstMor (var x) δ)\nSubstMor-weakenMor {x = last} {δ , u} = refl\nSubstMor-weakenMor {x = prev x} {δ , u} = SubstMor-weakenMor {x = x} {δ}\n\nSubstMor-idMor : {n : ℕ} {k : _} (e : N.Expr Σ n k) → SubstMor e N.idMor ≡ e\nSubstAMor-idMor : {n : ℕ} {k : _} (es : N.Args Σ n k) → SubstAMor es N.idMor ≡ es\n\nSubstMor-idMor (var last) = refl\nSubstMor-idMor (var (prev x)) = SubstMor-weakenMor {x = x} {δ = N.idMor} ∙ ap (N.weaken last) (SubstMor-idMor (var x)) ∙ ap var (ap prev weakenV≤r)\nSubstMor-idMor (sym s es) = ap (sym s) (SubstAMor-idMor es)\n\nSubstAMor-idMor [] = refl\nSubstAMor-idMor (_,_ {m = m} es x) = ap2 _,_ (SubstAMor-idMor es) (ap (SubstMor x) (weakenMor+-idMor m) ∙ SubstMor-idMor x)\n\n\nSubst-insert-idMor : {k : SyntaxSort} {e : N.Expr Σ n k} {x : WeakPos n} {u : N.TmExpr Σ n} {p : _}\n → SubstMor (N.weaken {{p}} x e) (MorInsert x N.idMor u) ≡ e\nSubst-insert-idMor {e = e} {x} {u} {p} = Subst-insert {e = e} {x} {u} {N.idMor} {p} ∙ SubstMor-idMor e\n\ninj : WeakPos n → WeakPos (suc n)\ninj last = last\ninj (prev x) = prev (inj x)\n\nweakenPos-inj : {m : ℕ} (x : WeakPos n) → weakenPos (≤-+ {m = m}) (inj x) ≡ inj (weakenPos ≤-+ x)\nweakenPos-inj {m = zero} x = refl\nweakenPos-inj {m = suc m} last = ap prev (weakenPos-inj last)\nweakenPos-inj {m = suc m} (prev x) = ap prev (weakenPos-inj (prev x))\n\nSubstV-insert2 : {n m : ℕ} {y : VarPos n} {x : WeakPos n} {u : N.TmExpr Σ (suc m)} {δ : N.Mor Σ (suc m) (suc n)} {p : _}\n → SubstMor (var (weakenV {{≤S p}} x y)) (MorInsert (inj x) δ u) ≡ SubstMor (var (weakenV {{p}} x y)) δ\nSubstV-insert2 {y = last} {last} = refl\nSubstV-insert2 {y = prev y} {last} = refl\nSubstV-insert2 {y = last} {prev x} {δ = δ , u} = refl\nSubstV-insert2 {y = prev y} {prev x} {δ = δ , u} {≤S ≤r} = SubstV-insert2 {y = y} {x = x} {δ = δ}\nSubstV-insert2 {y = prev y} {prev x} {δ = δ , u} {≤S (≤S p)} = Impossible p\n\nSubst-insert2 : {k : SyntaxSort} {n m : ℕ} {e : N.Expr Σ n k} {x : WeakPos n} {u : N.TmExpr Σ (suc m)} {δ : N.Mor Σ (suc m) (suc n)} {p : _}\n → SubstMor (N.weaken {{≤S p}} x e) (MorInsert (inj x) δ u) ≡ SubstMor (N.weaken {{p}} x e) δ\nSubstA-insert2 : {args : SyntaxArityArgs} {n m : ℕ} {es : N.Args Σ n args} {x : WeakPos n} {u : N.TmExpr Σ (suc m)} {δ : N.Mor Σ (suc m) (suc n)} {p : _}\n → SubstAMor (N.weakenA {{≤S p}} x es) (MorInsert (inj x) δ u) ≡ SubstAMor (N.weakenA {{p}} x es) δ\n\nSubst-insert2 {e = var y} {x = x} = SubstV-insert2 {y = y} {x = x}\nSubst-insert2 {e = sym s es} = ap (sym s) SubstA-insert2\n\nSubstA-insert2 {es = []} = refl\nSubstA-insert2 {n = n} {m = m'} {es = _,_ {m = m} es e} {x = x} {u = u} =\n ap2 _,_ SubstA-insert2 ((ap (SubstMor (N.weaken {{_}} (weakenPos ≤-+ x) e)) (weaken+-MorInsert m ∙ ap3 MorInsert (weakenPos-inj x) refl refl)\n ∙ ap\n (λ z →\n SubstMor (N.weaken ⦃ z ⦄ (weakenPos ≤-+ x) e)\n (MorInsert (inj (weakenPos ≤-+ x)) (N.weakenMor+ m {n = suc n} {m = suc m'} _)\n (N.weaken last u)))\n (≤-ishProp _ _) ∙ Subst-insert2 {e = e} {x = weakenPos ≤-+ x} {u = N.weaken last u}))\n\nSubst-insert-idMor2 : {k : SyntaxSort} {e : N.Expr Σ n k} {x : WeakPos n} {u : N.TmExpr Σ (suc n)}\n → SubstMor (N.weaken x e) (MorInsert (inj x) (N.idMor {n = suc n}) u) ≡ N.weaken {{≤S ≤r}} x e\nSubst-insert-idMor2 {e = e} {x} {u} = Subst-insert2 {e = e} {x} {u} {N.idMor} ∙ SubstMor-idMor _\n\nT→NMor : T.Mor n m → N.Mor Σ n m\nT→NMor ◇ = ◇\nT→NMor (δ , u) = (T→NMor δ , T→N u)\n\nweakenMor-comm : {δ : T.Mor n m} → N.weakenMor (T→NMor δ) ≡ T→NMor (T.weakenMor δ)\nweakenMor-comm {δ = ◇} = refl\nweakenMor-comm {δ = δ , u} = ap2 _,_ weakenMor-comm (weaken-comm last)\n\nsubstV-lemma : (x : VarPos n) {δ : T.Mor m n} → SubstMor (var x) (T→NMor δ) ≡ T→N (var x [ δ ])\nsubstV-lemma last {δ , u} = refl\nsubstV-lemma (prev x) {δ , u} = substV-lemma x\n\n\nsubst-lemma : {k : _} (B : T.Expr k n) {δ : T.Mor m n} → SubstMor (T→N B) (T→NMor δ) ≡ T→N (B [ δ ])\nsubst-lemma uu = refl\nsubst-lemma (el v) = ap (λ z → sym new ([] , z)) (subst-lemma v)\nsubst-lemma (pi A B) = ap2 (λ z z' → sym (prev (prev (prev (prev new)))) ([] , z , z')) (subst-lemma A) (ap (SubstMor (T→N B)) (ap2 _,_ weakenMor-comm refl) ∙ subst-lemma B)\nsubst-lemma (var x) = substV-lemma x\nsubst-lemma (lam A B u) = ap3 (λ z z' z'' → sym (prev (prev (prev new))) ([] , z , z' , z''))\n (subst-lemma A) (ap (SubstMor (T→N B)) (ap2 _,_ weakenMor-comm refl) ∙ subst-lemma B) (ap (SubstMor (T→N u)) (ap2 _,_ weakenMor-comm refl) ∙ subst-lemma u)\nsubst-lemma (app A B f a) = ap4\n (λ z z' z'' z''' →\n sym (prev (prev new)) ([] , z , z' , z'' , z'''))\n (subst-lemma A) (ap (SubstMor (T→N B)) (ap2 _,_ weakenMor-comm refl) ∙ subst-lemma B) (subst-lemma f) (subst-lemma a)\n\nidMor-lemma : {n : ℕ} → N.idMor {n = n} ≡ T→NMor T.idMor\nidMor-lemma {zero} = refl\nidMor-lemma {suc n} = ap2 _,_ (ap N.weakenMor idMor-lemma ∙ weakenMor-comm) refl\n\nSubst-T→N : {k : _} (B : T.Expr k (suc n)) (a : T.TmExpr n) → N.SubstMor (T→N B) (N.idMor , T→N a) ≡ T→N (T.subst B a)\nSubst-T→N B a = ap (λ z → SubstMor (T→N B) (z , T→N a)) idMor-lemma ∙ subst-lemma B\n\n-- T→NDer : {j : T.Judgment} → T.Derivable j → NDerivable (T→NJ j)\n-- T→NDer (Var {Γ = Γ} k dA) = NDerivable=! (ap (λ x → njudgment (T→NCtx Γ) (◇ ⊢ var x :> T→N (T.get k Γ))) (fst-VarPos→ℕ k (T→NCtx Γ))) (´ apr S (var (VarPos→ℕ k)) ([] ,0Ty ` T→NDer dA) {{get-def k Γ , (snd-VarPos→ℕ k Γ , tt)}})\n-- T→NDer (TyRefl dA) = ´ apr S tyRefl ([] , ` T→NDer dA)\n-- T→NDer (TySymm dA=) = ´ apr S tySymm ([] , ` T→NDer dA=)\n-- T→NDer (TyTran dA= dB=) = ´ apr S tyTran ([] , ` T→NDer dA= , ` T→NDer dB=)\n-- T→NDer (TmRefl du) = ´ apr S tmRefl ([] , ` T→NDer du)\n-- T→NDer (TmSymm du=) = ´ apr S tmSymm ([] , ` T→NDer du=)\n-- -- T→NDer (TmTran du= dv=) = apr S tmTran ([] , T→NDer du= , T→NDer dv=)\n-- -- T→NDer (Conv du dA=) = apr S conv ([] , T→NDer du , T→NDer dA=)\n-- -- T→NDer (ConvEq du= dA=) = apr S convEq ([] , T→NDer du= , T→NDer dA=)\n-- -- T→NDer UU = apr T 1 []\n-- -- T→NDer UUCong = apr C 1 []\n-- -- T→NDer (El dv) = apr T 0 ([] ,0Tm T→NDer dv)\n-- -- T→NDer (ElCong dv=) = apr C 0 ([] ,0Tm= T→NDer dv=)\n-- -- T→NDer (Pi dA dB) = apr T 4 ([] ,0Ty T→NDer dA ,1Ty T→NDer dB)\n-- -- T→NDer (PiCong dA= dB=) = apr C 4 ([] ,0Ty= T→NDer dA= ,1Ty= T→NDer dB=)\n-- -- T→NDer (Lam {A = A} {B = B} {u = u} dA dB du) =\n-- -- NDerivable=! (ap (λ z → njudgment _ (◇ ⊢ sym (prev (prev (prev new))) ([] , T→N _ , T→N _ , T→N _) :> sym (prev (prev (prev (prev new)))) ([] , T→N _ , z))) Subst-insert-idMor)\n-- -- (apr T 3 ([] ,0Ty T→NDer dA ,1Ty T→NDer dB ,1Tm NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N _ :> z)) Subst-insert-idMor) (T→NDer du)))\n-- -- T→NDer (LamCong dA= dB= du=) =\n-- -- NDerivable=! (ap (λ z → njudgment _ (◇ ⊢ sym (prev (prev (prev new))) ([] , T→N _ , T→N _ , T→N _) == sym (prev (prev (prev new))) ([] , T→N _ , T→N _ , T→N _) :> sym (prev (prev (prev (prev new)))) ([] , T→N _ , z)))\n-- -- Subst-insert-idMor)\n-- -- (apr C 3 ([] ,0Ty= T→NDer dA= ,1Ty= T→NDer dB= ,1Tm= NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N _ == T→N _ :> z)) Subst-insert-idMor) (T→NDer du=)))\n-- -- T→NDer (App {A = A} {B} {f} {a} dA dB df da) =\n-- -- NDerivable=! (ap (λ z → njudgment _ (◇ ⊢ sym (prev (prev new)) ([] , T→N A , T→N B , T→N f , T→N a) :> z)) (Subst-T→N B a))\n-- -- (apr T 2 ([] ,0Ty T→NDer dA\n-- -- ,1Ty T→NDer dB\n-- -- ,0Tm NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N f :> sym (prev (prev (prev (prev new)))) ([] , T→N A , z))) Subst-insert-idMor) (T→NDer df)\n-- -- ,0Tm T→NDer da))\n-- -- T→NDer (AppCong {A = A} {A' = A'} {B = B} {B' = B'} {f = f} {f' = f'} {a = a} {a' = a'} dA= dB= df= da=) =\n-- -- NDerivable=! (ap (λ z → njudgment _ (◇ ⊢ sym (prev (prev new)) ([] , T→N A , T→N B , T→N f , T→N a) == sym (prev (prev new)) ([] , T→N A' , T→N B' , T→N f' , T→N a') :> z)) (Subst-T→N B a))\n-- -- (apr C 2 ([] ,0Ty= T→NDer dA=\n-- -- ,1Ty= T→NDer dB=\n-- -- ,0Tm= NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N f == T→N f' :> sym (prev (prev (prev (prev new)))) ([] , T→N A , z))) Subst-insert-idMor)\n-- -- (T→NDer df=)\n-- -- ,0Tm= T→NDer da=))\n-- -- T→NDer (BetaPi {A = A} {B = B} {u = u} {a = a} dA dB du da) =\n-- -- NDerivable=! (ap4\n-- -- (λ z z' z'' z''' →\n-- -- njudgment _\n-- -- (◇ ⊢\n-- -- sym (prev (prev new))\n-- -- ([] , T→N A , z ,\n-- -- sym (prev (prev (prev new))) ([] , T→N A , z , z')\n-- -- , T→N a)\n-- -- == z'' :> z'''))\n-- -- Subst-insert-idMor Subst-insert-idMor (Subst-T→N u a) (Subst-T→N B a))\n-- -- (apr Eq 1 ([] ,0Ty T→NDer dA ,1Ty T→NDer dB ,1Tm NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N u :> z)) Subst-insert-idMor) (T→NDer du) ,0Tm T→NDer da))\n-- -- T→NDer (EtaPi {n = n} {A = A} {B = B} {f = f} dA dB df) =\n-- -- NDerivable=! (ap4\n-- -- (λ z z' z'' z''' →\n-- -- njudgment _\n-- -- (◇ ⊢ T→N f ==\n-- -- sym (prev (prev (prev new)))\n-- -- ([] , T→N A , z ,\n-- -- sym (prev (prev new)) ([] , z' , z'' , z''' , var last))\n-- -- :> sym (prev (prev (prev (prev new)))) ([] , T→N A , z)))\n-- -- Subst-insert-idMor (weaken-comm last) (Subst-insert-idMor2 ∙ weaken-comm (prev last)) (weaken-comm last))\n-- -- (apr Eq 0 ([] ,0Ty T→NDer dA\n-- -- ,1Ty T→NDer dB\n-- -- ,0Tm NDerivable= (ap (λ z → njudgment _ (◇ ⊢ T→N f :> sym (prev (prev (prev (prev new)))) ([] , T→N A , z))) Subst-insert-idMor) (T→NDer df)))\n\n\nN→TCtx : {n : ℕ} → N.Ctx Σ n → T.Ctx n\nN→TCtx ◇ = ◇\nN→TCtx (Γ , A) = (N→TCtx Γ , N→T A)\n\nN→TMor : {n m : ℕ} → N.Mor Σ n m → T.Mor n m\nN→TMor ◇ = ◇\nN→TMor (δ , u) = (N→TMor δ , N→T u)\n\nweaken-comm' : {k : SyntaxSort} {n : ℕ} {A : N.Expr Σ n k} (p : WeakPos n) → N→T (N.weaken p A) ≡ T.weaken p (N→T A)\nweaken-comm' p = ap N→T (ap (N.weaken p) (! (TNT _))) ∙ ap N→T (weaken-comm p) ∙ NTN _\n\nget-eq : {n : ℕ} (k : ℕ) (Γ : N.Ctx Σ n) {def : _} → N→T (snd (N.get k Γ $ def)) ≡ T.get (fst (N.get k Γ $ def)) (N→TCtx Γ)\nget-eq zero (Γ , A) = weaken-comm' last\nget-eq (suc k) (Γ , A) = weaken-comm' last ∙ ap (T.weaken last) (get-eq k Γ)\n\nN→TJ : NJudgment → T.Judgment\nN→TJ (njudgment Γ (◇ ⊢ A)) = N→TCtx Γ ⊢ N→T A\nN→TJ (njudgment Γ (◇ ⊢ u :> A)) = N→TCtx Γ ⊢ N→T u :> N→T A\nN→TJ (njudgment Γ (◇ ⊢ A == B)) = N→TCtx Γ ⊢ N→T A == N→T B\nN→TJ (njudgment Γ (◇ ⊢ u == v :> A)) = N→TCtx Γ ⊢ N→T u == N→T v :> N→T A\n\ncongTy : {Γ : T.Ctx n} {A A' : T.TyExpr n} → A ≡ A' → T.Derivable (Γ ⊢ A) → T.Derivable (Γ ⊢ A')\ncongTy refl d = d\n\ncongTmTy : {Γ : T.Ctx n} {u : T.TmExpr n} {A A' : T.TyExpr n} → A ≡ A' → T.Derivable (Γ ⊢ u :> A) → T.Derivable (Γ ⊢ u :> A')\ncongTmTy refl d = d\n\ncongTmTy! : {Γ : T.Ctx n} {u : T.TmExpr n} {A A' : T.TyExpr n} → A' ≡ A → T.Derivable (Γ ⊢ u :> A) → T.Derivable (Γ ⊢ u :> A')\ncongTmTy! refl d = d\n\ncongTmEqTy : {Γ : T.Ctx n} {u u' : T.TmExpr n} {A A' : T.TyExpr n} → A ≡ A' → T.Derivable (Γ ⊢ u == u' :> A) → T.Derivable (Γ ⊢ u == u' :> A')\ncongTmEqTy refl d = d\n\ncongTmEqTy! : {Γ : T.Ctx n} {u u' : T.TmExpr n} {A A' : T.TyExpr n} → A' ≡ A → T.Derivable (Γ ⊢ u == u' :> A) → T.Derivable (Γ ⊢ u == u' :> A')\ncongTmEqTy! refl d = d\n\ncongTmEq : {Γ : T.Ctx n} {u u' v v' : T.TmExpr n} {A A' : T.TyExpr n} → A ≡ A' → u ≡ u' → v ≡ v' → T.Derivable (Γ ⊢ u == v :> A) → T.Derivable (Γ ⊢ u' == v' :> A')\ncongTmEq refl refl refl d = d\n\ncongTmEq! : {Γ : T.Ctx n} {u u' v v' : T.TmExpr n} {A A' : T.TyExpr n} → A' ≡ A → u' ≡ u → v' ≡ v → T.Derivable (Γ ⊢ u == v :> A) → T.Derivable (Γ ⊢ u' == v' :> A')\ncongTmEq! refl refl refl d = d\n\nN→T-Subst : {k : _} (B : N.Expr Σ (suc n) k) (a : N.TmExpr Σ n) → N→T (SubstMor B (N.idMor , a)) ≡ T.subst (N→T B) (N→T a)\nN→T-Subst B a = ap N→T (! (ap2 SubstMor (TNT B) (ap2 _,_ refl (TNT a))) ∙ Subst-T→N (N→T B) (N→T a)) ∙ NTN _\n\nN→TDer : {j : NJudgment} → NDerivable j → T.Derivable (N→TJ j)\n\n-- N→TDer {njudgment Γ _} (apr S (var k) {js = [] , ◇ ⊢ A} ([] , dA) {{xᵈ , (refl , tt)}}) = congTmTy! (get-eq k Γ) (Var (fst (N.get k Γ $ xᵈ)) (congTy (get-eq k Γ) (N→TDer dA)))\n-- N→TDer {njudgment Γ _} (apr S conv {js = [] , ◇ ⊢ u :> A , ◇ ⊢ A == B} ([] , du , dA=) {{refl , tt}}) = Conv (N→TDer du) (N→TDer dA=)\n-- N→TDer {njudgment Γ _} (apr S convEq {js = [] , ◇ ⊢ u == v :> A , ◇ ⊢ A == B} ([] , du= , dA=) {{refl , tt}}) = ConvEq (N→TDer du=) (N→TDer dA=)\n-- N→TDer {njudgment Γ _} (apr S tyRefl {js = [] , ◇ ⊢ A} ([] , dA)) = TyRefl (N→TDer dA)\n-- N→TDer {njudgment Γ _} (apr S tySymm {js = [] , ◇ ⊢ A == B} ([] , dA=)) = TySymm (N→TDer dA=)\n-- N→TDer {njudgment Γ _} (apr S tyTran {js = [] , ◇ ⊢ A == B , ◇ ⊢ B == D} ([] , dA= , dB=) {{refl , tt}}) = TyTran (N→TDer dA=) (N→TDer dB=)\n-- N→TDer {njudgment Γ _} (apr S tmRefl {js = [] , ◇ ⊢ u :> A} ([] , du)) = TmRefl (N→TDer du)\n-- N→TDer {njudgment Γ _} (apr S tmSymm {js = [] , ◇ ⊢ u == v :> A} ([] , du=)) = TmSymm (N→TDer du=)\n-- N→TDer {njudgment Γ _} (apr S tmTran {js = [] , ◇ ⊢ u == v :> A , ◇ ⊢ v == w :> A} ([] , du= , dv=) {{refl , (refl , tt)}}) = TmTran (N→TDer du=) (N→TDer dv=)\n-- N→TDer {njudgment Γ _} (apr T typingrule {js = [] , (◇ ⊢ v :> _)} ([] , dv) {{(tt , (tt , (refl , tt))) , tt}}) = El (N→TDer dv)\n-- N→TDer {njudgment Γ _} (apr T (prev typingrule) []) = UU\n-- N→TDer {njudgment Γ _} (apr T (prev (prev typingrule)) {js = [] , ◇ ⊢ A , (◇ , _) ⊢ B , (◇ ⊢ f :> _) , (◇ ⊢ a :> _)} ([] , dA , dB , df , da)\n-- {{(((((tt , (tt , tt)) , ((tt , refl) , tt)) , (tt , (refl , tt))) , (tt , (refl , tt))) , tt)}}) = congTmTy! (N→T-Subst B a) (App (N→TDer dA) (N→TDer dB) (congTmTy (ap (pi (N→T A)) (ap N→T Subst-insert-idMor)) (N→TDer df)) (N→TDer da))\n-- N→TDer {njudgment Γ _} (apr T (prev (prev (prev typingrule))) {js = [] , ◇ ⊢ A , ((◇ , A) ⊢ B) , ((◇ , A) ⊢ u :> B')} ([] , dA , dB , du) {{(((tt , (tt , tt)) , ((tt , refl) , tt)) , ((tt , refl) , (refl , tt)) ) , tt}})\n-- = congTmTy! (ap (pi (N→T A)) (ap N→T Subst-insert-idMor)) (Lam (N→TDer dA) (N→TDer dB) (congTmTy (ap N→T Subst-insert-idMor) (N→TDer du)))\n-- N→TDer {njudgment Γ _} (apr T (prev (prev (prev (prev typingrule)))) {js = [] , ◇ ⊢ A , (◇ , ._) ⊢ B} ([] , dA , dB) {{((tt , (tt , tt)) , ((tt , refl) , tt)) , tt}}) = Pi (N→TDer dA) (N→TDer dB)\n-- N→TDer {njudgment Γ _} (apr C congruencerule {js = [] , ◇ ⊢ v == v' :> _} ([] , dv=) {{((tt , (tt , (refl , tt))) , tt)}}) = ElCong (N→TDer dv=)\n-- N→TDer {njudgment Γ _} (apr C (prev congruencerule) []) = UUCong\n-- N→TDer {njudgment Γ _} (apr C (prev (prev congruencerule)) {js = [] , ◇ ⊢ A == A' , (◇ , _) ⊢ B == B' , (◇ ⊢ f == f' :> _) , (◇ ⊢ a == a' :> _)} ([] , dA= , dB= , df= , da=)\n-- {{(((((tt , (tt , tt)) , ((tt , refl) , tt)) , (tt , (refl , tt))) , (tt , (refl , tt))) , tt)}})\n-- = congTmEqTy! (N→T-Subst B a) (AppCong (N→TDer dA=) (N→TDer dB=) (congTmEqTy (ap (pi (N→T A)) (ap N→T Subst-insert-idMor)) (N→TDer df=)) (N→TDer da=))\n-- N→TDer {njudgment Γ _} (apr C (prev (prev (prev congruencerule))) {js = [] , ◇ ⊢ A == A' , ((◇ , A) ⊢ B == B') , ((◇ , A) ⊢ u == u' :> B'')} ([] , dA= , dB= , du=) {{(((tt , (tt , tt)) , ((tt , refl) , tt)) , ((tt , refl) , (refl , tt)) ) , tt}}) = congTmEqTy! (ap (pi (N→T A)) (ap N→T Subst-insert-idMor)) (LamCong (N→TDer dA=) (N→TDer dB=) (congTmEqTy (ap N→T Subst-insert-idMor) (N→TDer du=)))\n-- N→TDer {njudgment Γ _} (apr C (prev (prev (prev (prev congruencerule)))) {js = [] , ◇ ⊢ A == A' , (◇ , ._) ⊢ B == B'} ([] , dA= , dB=) {{(((tt , (tt , tt)) , ((tt , refl) , tt)) , tt)}}) = PiCong (N→TDer dA=) (N→TDer dB=)\n-- N→TDer {njudgment Γ _} (apr Eq equalityrule js-der) = {!Eta!}\nN→TDer {njudgment Γ _} (apr Eq (prev equalityrule) {js = [] , (◇ ⊢ A) , ((◇ , _) ⊢ B) , ((◇ , _) ⊢ u :> _) , (◇ ⊢ a :> _)} ([] , dA , dB , du , da)\n {{(((((tt , (tt , tt)) , ((tt , refl) , tt)) , ((tt , refl) , (refl , tt))) , (tt , (refl , tt))) , tt)}})\n = {!da --jdef --congTmEq! ? ? ? (BetaPi (N→TDer dA) (N→TDer dB) (congTmTy (ap N→T Subst-insert-idMor) (N→TDer du)) (N→TDer da))!}\n", "meta": {"hexsha": "c62a5543c82bdf364aa287006d9a1a5cce135df0", "size": 27867, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "comparison.agda", "max_stars_repo_name": "guillaumebrunerie/general-type-theories", "max_stars_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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": "comparison.agda", "max_issues_repo_name": "guillaumebrunerie/general-type-theories", "max_issues_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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": "comparison.agda", "max_forks_repo_name": "guillaumebrunerie/general-type-theories", "max_forks_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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.4179104478, "max_line_length": 399, "alphanum_fraction": 0.4903649478, "num_tokens": 12910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056167854461, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3634822413893096}} {"text": "\n{-# OPTIONS --cubical --no-import-sorts --safe #-}\n\nmodule Cubical.Algebra.Group.Higher where\n\nopen import Cubical.Core.Everything\nopen import Cubical.Data.Nat\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Unit\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Prelude hiding (comp)\nopen import Cubical.Foundations.Pointed\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Homotopy.Loopspace\nopen import Cubical.Homotopy.Connected\nopen import Cubical.Homotopy.Base\nopen import Cubical.Homotopy.PointedFibration\nopen import Cubical.Algebra.Group.Base\nopen import Cubical.Algebra.Group.EilenbergMacLane1\nopen import Cubical.HITs.EilenbergMacLane1\n\nopen import Cubical.Algebra.Group.Base\nopen import Cubical.Algebra.Group.Morphism\nopen import Cubical.Algebra.Group.MorphismProperties\nopen import Cubical.Foundations.GroupoidLaws\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Equiv.Properties\nopen import Cubical.HITs.PropositionalTruncation renaming (rec to propRec)\nopen import Cubical.HITs.Truncation.FromNegOne as Trunc renaming (rec to trRec)\nopen import Cubical.HITs.SetTruncation\nopen import Cubical.Functions.Surjection\nopen import Cubical.Functions.Embedding\n\nimport Cubical.Foundations.GroupoidLaws as GL\n\nprivate\n variable\n ℓ ℓ' : Level\n\n\nrecord HigherGroup ℓ : Type (ℓ-suc ℓ) where\n constructor highergroup\n field\n base : Pointed ℓ\n isConn : isConnected 2 (typ base)\n\nrecord BGroup ℓ (n k : ℕ) : Type (ℓ-suc ℓ) where\n no-eta-equality\n constructor bgroup\n field\n base : Pointed ℓ\n isConn : isConnected (k + 1) (typ base)\n isTrun : isOfHLevel (n + k + 2) (typ base)\n\nBGroupΣ : {ℓ : Level} (n k : ℕ) → Type (ℓ-suc ℓ)\nBGroupΣ {ℓ} n k = Σ[ A ∈ Type ℓ ] A × (isConnected (k + 1) A) × (isOfHLevel (n + k + 2) A)\n\nmodule _ where\n open BGroup\n η-BGroup : {n k : ℕ} {BG BH : BGroup ℓ n k}\n → (p : typ (base BG) ≡ typ (base BH))\n → (q : PathP (λ i → p i) (pt (base BG)) (pt (base BH)))\n → BG ≡ BH\n base (η-BGroup p q i) .fst = p i\n base (η-BGroup p q i) .snd = q i\n isConn (η-BGroup {k = k} {BG = BG} {BH = BH} p q i) = r i\n where\n r : PathP (λ i → isConnected (k + 1) (p i)) (isConn BG) (isConn BH)\n r = isProp→PathP (λ _ → isPropIsOfHLevel 0) (isConn BG) (isConn BH)\n isTrun (η-BGroup {n = n} {k = k} {BG = BG} {BH = BH} p q i) = s i\n where\n s : PathP (λ i → isOfHLevel (n + k + 2) (p i)) (isTrun BG) (isTrun BH)\n s = isProp→PathP (λ i → isPropIsOfHLevel (n + k + 2)) (isTrun BG) (isTrun BH)\n\n-- morphisms\n\nBGroupHom : {n k : ℕ} (G : BGroup ℓ n k) (H : BGroup ℓ' n k) → Type (ℓ-max ℓ ℓ')\nBGroupHom G H = (BGroup.base G) →∙ (BGroup.base H)\n\nBGroupHomΣ : {n k : ℕ} (BG : BGroupΣ {ℓ} n k) (BH : BGroupΣ {ℓ'} n k) → Type (ℓ-max ℓ ℓ')\nBGroupHomΣ (base , pt , _) (base' , pt' , _) = (base , pt) →∙ (base' , pt')\n\nisOfHLevel-BGroupHomΣ : {n k : ℕ} (BG : BGroupΣ {ℓ} n k) (BH : BGroupΣ {ℓ'} n k)\n → isOfHLevel (n + 2) (BGroupHomΣ BG BH)\nisOfHLevel-BGroupHomΣ {n = n} {k = k} BG BH = x'\n where\n z : isOfHLevel (n + k + 2) (fst BH)\n z = snd (snd (snd BH))\n z' : isOfHLevel (n + 1 + 1 + k) (fst BH)\n z' = subst (λ m → isOfHLevel m (fst BH))\n (n + k + 2 ≡⟨ sym (+-assoc n k 2) ⟩\n n + (k + 2) ≡⟨ cong (n +_) (+-comm k 2) ⟩\n n + (2 + k) ≡⟨ +-assoc n 2 k ⟩\n (n + 2) + k ≡⟨ cong (_+ k) (+-assoc n 1 1) ⟩\n n + 1 + 1 + k ∎)\n z\n x : isOfHLevel (n + 1 + 1) (BGroupHomΣ BG BH)\n x = sec∙Trunc (fst BG , fst (snd BG)) (fst (snd (snd BG))) λ _ → (fst BH , fst (snd BH)) , z'\n x' : isOfHLevel (n + 2) (BGroupHomΣ BG BH)\n x' = subst (λ m → isOfHLevel m (BGroupHomΣ BG BH)) (sym (+-assoc n 1 1)) x\n\nBGroupIso : {n k : ℕ} (G : BGroup ℓ n k) (H : BGroup ℓ' n k) → Type (ℓ-max ℓ ℓ')\nBGroupIso G H = (BGroup.base G) ≃∙ (BGroup.base H)\n\n\nBGroupIdIso : {n k : ℕ} (BG : BGroup ℓ n k) → BGroupIso BG BG\nBGroupIdIso BG = idEquiv∙ (BGroup.base BG)\n\nBGroupIso→≡ : {n k : ℕ} {BG BH : BGroup ℓ n k}\n (f : BGroupIso BG BH)\n → BG ≡ BH\nBGroupIso→≡ {BG = BG} {BH = BH} f = η-BGroup (ua (≃∙→≃ f)) (toPathP ((uaβ ((≃∙→≃ f)) (pt (BGroup.base BG))) ∙ f .fst .snd))\n\n\n-- getters\ncarrier : {ℓ : Level} {n k : ℕ} (G : BGroup ℓ n k) → Pointed ℓ\ncarrier {k = k} BG = (Ω^ k) base\n where\n open BGroup BG\n\nbasetype : {ℓ : Level} {n k : ℕ} (BG : BGroup ℓ n k) → Type ℓ\nbasetype BG = typ (BGroup.base BG)\n\nbasepoint : {ℓ : Level} {n k : ℕ} (BG : BGroup ℓ n k) → basetype BG\nbasepoint BG = pt (BGroup.base BG)\n\nbaseΣ : {ℓ : Level} {n k : ℕ} (BG : BGroupΣ {ℓ} n k) → Σ[ A ∈ Type ℓ ] A\nbaseΣ (base , * , _ , _) = (base , *)\n\n-- special cases\n1BGroup : (ℓ : Level) → Type (ℓ-suc ℓ)\n1BGroup ℓ = BGroup ℓ 0 1\n\n1BGroupΣ : {ℓ : Level} → Type (ℓ-suc ℓ)\n1BGroupΣ {ℓ} = BGroupΣ {ℓ} 0 1\n\n-- first fundamental group of 1BGroups\nπ₁-1BGroup : {ℓ : Level} (BG : 1BGroup ℓ) → Group {ℓ}\nπ₁-1BGroup BG =\n makeGroup {G = (pt base) ≡ (pt base)}\n refl\n _∙_\n sym\n (isTrun (pt base) (pt base))\n GL.assoc\n (λ a → sym (GL.rUnit a))\n (λ g → sym (GL.lUnit g))\n GL.rCancel\n GL.lCancel\n where\n open BGroup BG\n\nπ₁-1BGroupΣ : {ℓ : Level} (BG : BGroupΣ {ℓ} 0 1) → Group {ℓ}\nπ₁-1BGroupΣ (BG , pt , conn , trunc) = π₁-1BGroup (bgroup (BG , pt) conn trunc)\n\n-- coercions\nGroup→1BGroup : (G : Group {ℓ}) → 1BGroup ℓ\nBGroup.base (Group→1BGroup G) .fst = EM₁ G\nBGroup.base (Group→1BGroup G) .snd = embase\nBGroup.isConn (Group→1BGroup G) = EM₁Connected G\nBGroup.isTrun (Group→1BGroup G) = EM₁Groupoid G\n\n-- functoriality of π₁ on 1BGroups\nmodule _ (BG : 1BGroup ℓ) (BH : 1BGroup ℓ') where\n private\n π₁BG = π₁-1BGroup BG\n π₁BH = π₁-1BGroup BH\n\n π₁-1BGroup-functor : BGroupHom BG BH → GroupHom π₁BG π₁BH\n GroupHom.fun (π₁-1BGroup-functor f) g = sym (snd f) ∙∙ cong (fst f) g ∙∙ snd f\n GroupHom.isHom (π₁-1BGroup-functor f) g g' = q\n where\n f₁ = fst f\n f₂ = snd f\n f₂- = sym (snd f)\n abstract\n q = (f₂- ∙∙ cong f₁ (g ∙ g') ∙∙ f₂)\n ≡⟨ doubleCompPath-elim' f₂- (cong f₁ (g ∙ g')) f₂ ⟩\n f₂- ∙ cong f₁ (g ∙ g') ∙ f₂\n ≡⟨ cong (λ z → (f₂- ∙ z ∙ f₂))\n (congFunct f₁ g g') ⟩\n f₂- ∙ (cong f₁ g ∙ cong f₁ g') ∙ f₂\n ≡⟨ cong (λ z → (f₂- ∙ (cong f₁ g ∙ z) ∙ f₂))\n (lUnit (cong f₁ g')) ⟩\n f₂- ∙ (cong f₁ g ∙ refl ∙ cong f₁ g') ∙ f₂\n ≡⟨ cong (λ z → (f₂- ∙ (cong f₁ g ∙ z ∙ cong f₁ g') ∙ f₂))\n (sym (rCancel f₂)) ⟩\n f₂- ∙ (cong f₁ g ∙ (f₂ ∙ f₂-) ∙ cong f₁ g') ∙ f₂\n ≡⟨ cong (λ z → (f₂- ∙ (cong f₁ g ∙ z) ∙ f₂))\n (sym (assoc _ _ _)) ⟩\n f₂- ∙ (cong f₁ g ∙ (f₂ ∙ (f₂- ∙ cong f₁ g'))) ∙ f₂\n ≡⟨ cong (λ z → (f₂- ∙ z ∙ f₂))\n (assoc _ _ _) ⟩\n (f₂- ∙ ((cong f₁ g ∙ f₂) ∙ (f₂- ∙ cong f₁ g')) ∙ f₂)\n ≡⟨ cong (f₂- ∙_)\n (sym (assoc _ _ _)) ⟩\n (f₂- ∙ ((cong f₁ g ∙ f₂) ∙ ((f₂- ∙ cong f₁ g') ∙ f₂)))\n ≡⟨ cong (λ z → (f₂- ∙ ((cong f₁ g ∙ f₂) ∙ z)))\n (sym (assoc _ _ _)) ⟩\n (f₂- ∙ ((cong f₁ g ∙ f₂) ∙ (f₂- ∙ cong f₁ g' ∙ f₂)))\n ≡⟨ assoc _ _ _ ⟩\n (f₂- ∙ cong f₁ g ∙ f₂) ∙ (f₂- ∙ cong f₁ g' ∙ f₂)\n ≡⟨ cong (_∙ (f₂- ∙ cong f₁ g' ∙ f₂))\n (sym (doubleCompPath-elim' f₂- (cong f₁ g) f₂)) ⟩\n (f₂- ∙∙ cong f₁ g ∙∙ f₂) ∙ (f₂- ∙ cong f₁ g' ∙ f₂)\n ≡⟨ cong ((f₂- ∙∙ cong f₁ g ∙∙ f₂) ∙_)\n (sym (doubleCompPath-elim' f₂- (cong f₁ g') f₂)) ⟩\n (f₂- ∙∙ cong f₁ g ∙∙ f₂) ∙ (f₂- ∙∙ cong f₁ g' ∙∙ f₂) ∎\n\n\n-- π₁ is a left inverse to EM₁\nπ₁EM₁≃inv : (G : Group {ℓ}) → GroupEquiv G (π₁-1BGroup (Group→1BGroup G))\nGroupEquiv.eq (π₁EM₁≃inv G) = isoToEquiv (invIso (ΩEM₁Iso G))\nGroupEquiv.isHom (π₁EM₁≃inv G) g g' = emloop-comp G g g'\n\nπ₁EM₁≃ : (G : Group {ℓ}) → GroupEquiv (π₁-1BGroup (Group→1BGroup G)) G\nπ₁EM₁≃ G = invGroupEquiv (π₁EM₁≃inv G)\n\n\n-- the functorial action of EM₁ on groups\n-- is a left inverse to the functorial action of π₁\n-- on 1BGroups.\nmodule _ (H : Group {ℓ}) (BG : 1BGroup ℓ') where\n private\n EM₁H = Group→1BGroup H\n π₁EM₁H = π₁-1BGroup EM₁H\n π₁BG = π₁-1BGroup BG\n\n -- from the EM construction it follows\n -- that there is a homomorphism H → π₁ (EM₁ H)\n H→π₁EM₁H : GroupHom H π₁EM₁H\n H→π₁EM₁H = GroupEquiv.hom (π₁EM₁≃inv H)\n\n -- the promised functorial left inverse\n -- split up into the three components:\n -- function, is equivalence and pointedness.\n -- pointedness component is trivial\n\n -- on the object level\n EM₁-functor-lInv-function : GroupHom π₁EM₁H π₁BG → basetype EM₁H → basetype BG\n EM₁-functor-lInv-function f =\n rec' H\n (BGroup.isTrun BG)\n (basepoint BG)\n (GroupHom.fun (compGroupHom H→π₁EM₁H f))\n λ g h → sym (GroupHom.isHom (compGroupHom H→π₁EM₁H f) g h)\n\n EM₁-functor-lInv-pointed : (f : GroupHom π₁EM₁H π₁BG)\n → EM₁-functor-lInv-function f (basepoint EM₁H) ≡ basepoint BG\n EM₁-functor-lInv-pointed f = refl\n\n -- produces an equivalence proof when given a group iso\n EM₁-functor-lInv-onIso-isEquiv : (f : GroupEquiv π₁EM₁H π₁BG)\n → isEquiv (EM₁-functor-lInv-function (GroupEquiv.hom f))\n EM₁-functor-lInv-onIso-isEquiv f =\n isEmbedding×isSurjection→isEquiv (isEmbedding-φ , isSurjection-φ)\n where\n φ₁ : basetype EM₁H → basetype BG\n φ₁ = EM₁-functor-lInv-function (GroupEquiv.hom f)\n abstract\n isEmbedding-φ : isEmbedding φ₁\n isEmbedding-φ = reduceToBp isEmbPt\n where\n isEmb : (x y : basetype EM₁H) → Type (ℓ-max ℓ ℓ')\n isEmb x y = isEquiv (cong {x = x} {y = y} φ₁)\n\n isPropIsEmb : (x y : basetype EM₁H) → isProp (isEmb x y)\n isPropIsEmb x y = isPropIsEquiv (cong {x = x} {y = y} φ₁)\n\n f-equiv : (basepoint EM₁H ≡ basepoint EM₁H) ≃ (basepoint BG ≡ basepoint BG)\n f-equiv = GroupEquiv.eq f\n f₁ = fst f-equiv\n\n γ : ⟨ H ⟩ ≃ ⟨ π₁EM₁H ⟩\n γ = GroupEquiv.eq (π₁EM₁≃inv H)\n β : ⟨ π₁EM₁H ⟩ ≃ typ (carrier BG)\n β = f-equiv\n δ : ⟨ H ⟩ ≃ typ (carrier BG)\n δ = compEquiv γ β\n p : equivFun δ ≡ (λ h → cong φ₁ (equivFun γ h))\n p = refl\n η = (λ (h : ⟨ H ⟩) → cong φ₁ (equivFun γ h))\n isEquiv-η : isEquiv η\n isEquiv-η = equivFun≡→isEquiv δ η λ _ → refl\n congφ∼f : (h : ⟨ H ⟩) → f₁ (GroupHom.fun H→π₁EM₁H h) ≡ cong φ₁ (GroupHom.fun H→π₁EM₁H h)\n congφ∼f p = refl\n\n isEmbPt : isEmb (basepoint EM₁H) (basepoint EM₁H)\n isEmbPt = equivCompLCancel γ (cong φ₁) isEquiv-η\n\n g : Unit → basetype EM₁H\n g _ = basepoint EM₁H\n\n isConn-g : isConnectedFun 1 g\n isConn-g = isConnectedPoint 1 (BGroup.isConn EM₁H) (basepoint EM₁H)\n\n reduceToBp1 : ((a : Unit) → isEmb (basepoint EM₁H) (g a))\n → (h' : basetype EM₁H) → isEmb (basepoint EM₁H) h'\n reduceToBp1 =\n Iso.inv (elim.isIsoPrecompose g\n 1\n (λ h' → (isEmb (basepoint EM₁H) h') , isPropIsEmb (basepoint EM₁H) h')\n isConn-g)\n reduceToBp1' : isEmb (basepoint EM₁H) (basepoint EM₁H)\n → (h' : basetype EM₁H) → isEmb (basepoint EM₁H) h'\n reduceToBp1' p = reduceToBp1 λ _ → p\n\n\n reduceToBp2 : (h' : basetype EM₁H) → isEmb (basepoint EM₁H) h'\n → ((a : Unit) → isEmb (g a) h') → (h : basetype EM₁H) → isEmb h h'\n reduceToBp2 h' p =\n Iso.inv (elim.isIsoPrecompose g\n 1\n (λ h → (isEmb h h') , (isPropIsEmb h h'))\n isConn-g)\n reduceToBp2' : ((h' : basetype EM₁H) → isEmb (basepoint EM₁H) h')\n → (h h' : basetype EM₁H) → isEmb h h'\n reduceToBp2' Q h h' = reduceToBp2 h' (Q h') (λ _ → Q h') h\n\n\n reduceToBp : isEmb (basepoint EM₁H) (basepoint EM₁H) → (h h' : basetype EM₁H) → isEmb h h'\n reduceToBp p = reduceToBp2' (reduceToBp1' p)\n\n isSurjection-φ : isSurjection φ₁\n isSurjection-φ g = propTruncΣ← (λ x → φ₁ x ≡ g) ∣ basepoint EM₁H , fst r ∣\n where\n r : isContr ∥ φ₁ (basepoint EM₁H) ≡ g ∥\n r = isContrRespectEquiv (invEquiv propTrunc≃Trunc1)\n (isConnectedPath 1\n (BGroup.isConn BG)\n (φ₁ (basepoint EM₁H))\n g)\n", "meta": {"hexsha": "146ba1dc72a88ff88b560099811c57866cd88426", "size": 13050, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/Group/Higher.agda", "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/Algebra/Group/Higher.agda", "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/Algebra/Group/Higher.agda", "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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.0718562874, "max_line_length": 123, "alphanum_fraction": 0.5333333333, "num_tokens": 4992, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6791786861878392, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.3634274477357992}} {"text": "{-# OPTIONS --without-K --safe #-}\nmodule Cats.Category.Cat.Facts.Exponential where\n\nopen import Data.Product using (_,_)\nopen import Level using (_⊔_)\nopen import Relation.Binary using (IsEquivalence)\n\nopen import Cats.Bifunctor using\n (Bifunctor ; Bifunctor→Functor₁ ; transposeBifunctor₁ ; transposeBifunctor₁-resp)\nopen import Cats.Category\nopen import Cats.Category.Cat as Cat′ using\n (Cat ; Functor ; _∘_ ; _≈_) renaming\n (id to Id)\nopen import Cats.Category.Cat.Facts.Product using (hasBinaryProducts ; ⟨_×_⟩)\nopen import Cats.Category.Fun using (_↝_ ; Trans ; ≈-intro ; ≈-elim)\nopen import Cats.Category.Fun.Facts.Iso using (≈→≅)\nopen import Cats.Category.Product.Binary using (_×_)\nopen import Cats.Trans.Iso as NatIso using (NatIso)\nopen import Cats.Util.Conv\n\nimport Cats.Category.Base as Base\nimport Cats.Category.Constructions.Unique as Unique\nimport Cats.Category.Constructions.Iso as Iso\n\nopen Functor\nopen Trans\nopen Iso.Iso\n\n\nprivate\n module Cat≈ {lo la l≈ lo′ la′ l≈′}\n {C : Category lo la l≈} {D : Category lo′ la′ l≈′}\n = IsEquivalence (Cat′.equiv {C = C} {D})\n\n\n module Fun {lo la l≈ lo′ la′ l≈′}\n {C : Category lo la l≈} {D : Category lo′ la′ l≈′}\n = Category (C ↝ D)\n\n\nmodule _ {lo la l≈ lo′ la′ l≈′}\n {B : Category lo la l≈} {C : Category lo′ la′ l≈′}\n where\n\n private\n module B = Category B\n module C = Category C\n\n\n Eval : Bifunctor (B ↝ C) B C\n Eval = record\n { fobj = λ where\n (F , x) → fobj F x\n ; fmap = λ where\n {F , a} {G , b} (θ , f) → fmap G f C.∘ component θ a\n ; fmap-resp = λ where\n {F , a} {G , b} {θ , f} {ι , g} (θ≈ι , f≈g) →\n C.∘-resp (fmap-resp G f≈g) (≈-elim θ≈ι)\n ; fmap-id = λ { {F , b} → C.≈.trans (C.∘-resp-l (fmap-id F)) C.id-l }\n ; fmap-∘ = λ where\n {F , a} {G , b} {H , c} {θ , f} {ι , g} →\n begin\n (fmap H f C.∘ component θ b) C.∘ (fmap G g C.∘ component ι a)\n ≈⟨ C.∘-resp-l (C.≈.sym (natural θ)) ⟩\n (component θ c C.∘ fmap G f) C.∘ (fmap G g C.∘ component ι a)\n ≈⟨ C.assoc ⟩\n component θ c C.∘ fmap G f C.∘ (fmap G g C.∘ component ι a)\n ≈⟨ C.∘-resp-r C.unassoc ⟩\n component θ c C.∘ (fmap G f C.∘ fmap G g) C.∘ component ι a\n ≈⟨ C.∘-resp-r (C.∘-resp-l (fmap-∘ G)) ⟩\n component θ c C.∘ fmap G (f B.∘ g) C.∘ component ι a\n ≈⟨ C.unassoc ⟩\n (component θ c C.∘ fmap G (f B.∘ g)) C.∘ component ι a\n ≈⟨ C.∘-resp-l (natural θ) ⟩\n (fmap H (f B.∘ g) C.∘ component θ a) C.∘ component ι a\n ≈⟨ C.assoc ⟩\n fmap H (f B.∘ g) C.∘ component θ a C.∘ component ι a\n ∎\n }\n where\n open C.≈-Reasoning\n\n\nmodule _ {lo la l≈ lo′ la′ l≈′ lo″ la″ l≈″}\n {B : Category lo la l≈} {C : Category lo′ la′ l≈′} {D : Category lo″ la″ l≈″}\n where\n\n private\n module B = Category B\n module C = Category C\n module D = Category D\n\n\n Curry : Bifunctor B C D → Functor B (C ↝ D)\n Curry F = transposeBifunctor₁ F\n\n\n Curry-resp : ∀ {F G} → F ≈ G → Curry F ≈ Curry G\n Curry-resp = transposeBifunctor₁-resp\n\n\n Curry-correct : ∀ {F} → Eval ∘ ⟨ Curry F × Id ⟩ ≈ F\n Curry-correct {F} = record\n { iso = D.≅.refl\n ; forth-natural = λ where\n {a , a′} {b , b′} {f , f′} →\n begin\n D.id D.∘ fmap F (B.id , f′) D.∘ fmap F (f , C.id)\n ≈⟨ D.≈.trans D.id-l (fmap-∘ F) ⟩\n fmap F (B.id B.∘ f , f′ C.∘ C.id)\n ≈⟨ fmap-resp F (B.id-l , C.id-r) ⟩\n fmap F (f , f′)\n ≈⟨ D.≈.sym D.id-r ⟩\n fmap F (f , f′) D.∘ D.id\n ∎\n }\n where\n open D.≈-Reasoning\n\n\n Curry-unique : ∀ {F Curry′}\n → Eval ∘ ⟨ Curry′ × Id ⟩ ≈ F\n → Curry′ ≈ Curry F\n Curry-unique {F} {Curry′} eq@record { iso = iso ; forth-natural = fnat } = record\n { iso = λ {x} →\n let open Fun.≅-Reasoning in\n Fun.≅.sym (\n begin\n fobj (Curry F) x\n ≈⟨ NatIso.iso (Curry-resp (Cat≈.sym eq)) ⟩\n fobj (Curry (Eval ∘ ⟨ Curry′ × Id ⟩)) x\n ≈⟨ ≈→≅ (lem x) ⟩\n fobj Curry′ x\n ∎\n )\n ; forth-natural = λ {a} {b} {f} → ≈-intro λ {x} →\n -- TODO We need a simplification tactic.\n let open D.≈-Reasoning in\n triangle (forth iso D.∘ component (fmap Curry′ f) x)\n ( begin\n ((forth iso D.∘\n (fmap (fobj Curry′ b) C.id D.∘ component (fmap Curry′ B.id) x) D.∘ D.id) D.∘\n D.id D.∘ D.id) D.∘\n component (fmap Curry′ f) x\n ≈⟨ D.∘-resp-l (D.≈.trans (D.∘-resp-r D.id-l) (D.≈.trans D.id-r\n (D.≈.trans (D.∘-resp-r (D.≈.trans D.id-r (D.≈.trans\n (D.∘-resp (fmap-id (fobj Curry′ b))\n (≈-elim (fmap-id Curry′))) D.id-l))) D.id-r))) ⟩\n forth iso D.∘ component (fmap Curry′ f) x\n ∎\n )\n ( begin\n fmap F (f , C.id) D.∘\n (forth iso D.∘ (fmap (fobj Curry′ a) C.id D.∘ component (fmap Curry′ B.id) x) D.∘ D.id) D.∘\n D.id D.∘ D.id\n ≈⟨ D.∘-resp-r (D.≈.trans (D.∘-resp-r D.id-r) (D.≈.trans D.id-r\n (D.≈.trans (D.∘-resp-r (D.≈.trans D.id-r (D.≈.trans\n (D.∘-resp-l (fmap-id (fobj Curry′ a)))\n (D.≈.trans D.id-l (≈-elim (fmap-id Curry′)))))) D.id-r))) ⟩\n fmap F (f , C.id) D.∘ forth iso\n ≈⟨ D.≈.sym fnat ⟩\n forth iso D.∘ fmap (fobj Curry′ b) C.id D.∘ component (fmap Curry′ f) x\n ≈⟨ D.∘-resp-r (D.≈.trans (D.∘-resp-l (fmap-id (fobj Curry′ b))) D.id-l) ⟩\n forth iso D.∘ component (fmap Curry′ f) x\n ∎\n )\n }\n where\n lem : ∀ x\n → NatIso (Bifunctor→Functor₁ (Eval ∘ ⟨ Curry′ × Id ⟩) x) (fobj Curry′ x)\n lem x = record\n { iso = D.≅.refl\n ; forth-natural = D.≈.trans D.id-l (D.∘-resp-r (≈-elim (fmap-id Curry′)))\n }\n\n\n -- We get the following lemmas for free from HasExponentials, but only when\n -- all the categories are at the same (single) level.\n\n Uncurry : Functor B (C ↝ D) → Bifunctor B C D\n Uncurry F = Eval ∘ ⟨ F × Id ⟩\n\n\n Curry∘Uncurry : {F : Functor B (C ↝ D)}\n → Curry (Uncurry F) ≈ F\n Curry∘Uncurry {F} = Cat≈.sym (Curry-unique {Curry′ = F} Cat≈.refl)\n\n\n Uncurry∘Curry : {F : Bifunctor B C D}\n → Uncurry (Curry F) ≈ F\n Uncurry∘Curry {F} = Curry-correct {F = F}\n\n\ninstance\n hasExponentials : ∀ {l} → HasExponentials (Cat l l l)\n hasExponentials {l} = record\n { _↝′_ = λ B C → record\n { Cᴮ = B ↝ C\n ; eval = Eval\n ; curry′ = λ {A} F → record\n { arr = Curry F\n ; prop = Curry-correct {B = A} {B} {C} {F}\n ; unique = λ {g} eq → Cat≈.sym (Curry-unique eq)\n }\n }\n }\n", "meta": {"hexsha": "45dec570f6ea106eb6b2df7d7881c1302cf30151", "size": 6877, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cats/Category/Cat/Facts/Exponential.agda", "max_stars_repo_name": "JLimperg/cats", "max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z", "max_issues_repo_path": "Cats/Category/Cat/Facts/Exponential.agda", "max_issues_repo_name": "JLimperg/cats", "max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "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": "Cats/Category/Cat/Facts/Exponential.agda", "max_forks_repo_name": "JLimperg/cats", "max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z", "avg_line_length": 33.2222222222, "max_line_length": 105, "alphanum_fraction": 0.4898938491, "num_tokens": 2666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7154240079185319, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.36330079921121}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Some derivable properties\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nopen import Algebra\n\nmodule Algebra.Properties.CommutativeMonoid {g₁ g₂} (M : CommutativeMonoid g₁ g₂) where\n\nopen import Algebra.Operations.CommutativeMonoid M\nopen import Algebra.Solver.CommutativeMonoid M\nopen import Relation.Binary as B using (_Preserves_⟶_)\nopen import Function\nopen import Function.Equality using (_⟨$⟩_)\nopen import Data.Product\nopen import Data.Nat using (ℕ; zero; suc)\nopen import Data.Fin using (Fin; zero; suc)\nopen import Data.List as List using ([]; _∷_)\nimport Data.Fin.Properties as FP\nopen import Data.Fin.Permutation as Perm using (Permutation; Permutation′; _⟨$⟩ˡ_; _⟨$⟩ʳ_)\nopen import Data.Fin.Permutation.Components as PermC\nopen import Data.Table as Table\nopen import Data.Table.Relation.Binary.Equality as TE using (_≗_)\nopen import Data.Unit using (tt)\nimport Data.Table.Properties as TP\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\nopen import Relation.Nullary using (yes; no)\nopen import Relation.Nullary.Negation using (contradiction)\nopen import Relation.Nullary.Decidable using (⌊_⌋)\n\nopen CommutativeMonoid M\n renaming\n ( ε to 0#\n ; _∙_ to _+_\n ; ∙-cong to +-cong\n ; ∙-congˡ to +-congˡ\n ; ∙-congʳ to +-congʳ\n ; identityˡ to +-identityˡ\n ; identityʳ to +-identityʳ\n ; assoc to +-assoc\n ; comm to +-comm\n )\nopen import Algebra.FunctionProperties _≈_\nopen import Relation.Binary.Reasoning.Setoid setoid\n\nmodule _ {n} where\n open B.Setoid (TE.setoid setoid n) public\n using ()\n renaming (_≈_ to _≋_)\n\n-- When summing over a function from a finite set, we can pull out any value and move it to the front.\n\nsumₜ-remove : ∀ {n} {i : Fin (suc n)} t → sumₜ t ≈ lookup t i + sumₜ (remove i t)\nsumₜ-remove {_} {zero} t = refl\nsumₜ-remove {zero} {suc ()} t\nsumₜ-remove {suc n} {suc i} t′ =\n begin\n t₀ + ∑t ≈⟨ +-congˡ (sumₜ-remove t) ⟩\n t₀ + (tᵢ + ∑t′) ≈⟨ solve 3 (λ x y z → x ⊕ (y ⊕ z) ⊜ y ⊕ (x ⊕ z)) refl t₀ tᵢ ∑t′ ⟩\n tᵢ + (t₀ + ∑t′) ∎\n where\n t = tail t′\n t₀ = head t′\n tᵢ = lookup t i\n ∑t = sumₜ t\n ∑t′ = sumₜ (remove i t)\n\n-- '_≈_' is a congruence over 'sumTable n'.\n\nsumₜ-cong-≈ : ∀ {n} → sumₜ {n} Preserves _≋_ ⟶ _≈_\nsumₜ-cong-≈ {zero} p = refl\nsumₜ-cong-≈ {suc n} p = +-cong (p _) (sumₜ-cong-≈ (p ∘ suc))\n\n-- '_≡_' is a congruence over 'sum n'.\n\nsumₜ-cong-≡ : ∀ {n} → sumₜ {n} Preserves _≗_ ⟶ _≡_\nsumₜ-cong-≡ {zero} p = P.refl\nsumₜ-cong-≡ {suc n} p = P.cong₂ _+_ (p _) (sumₜ-cong-≡ (p ∘ suc))\n\n-- If addition is idempotent on a particular value 'x', then summing over a\n-- nonzero number of copies of 'x' gives back 'x'.\n\nsumₜ-idem-replicate : ∀ n {x} → _+_ IdempotentOn x → sumₜ (replicate {n = suc n} x) ≈ x\nsumₜ-idem-replicate zero idem = +-identityʳ _\nsumₜ-idem-replicate (suc n) {x} idem = begin\n x + (x + sumₜ (replicate {n = n} x)) ≈⟨ sym (+-assoc _ _ _) ⟩\n (x + x) + sumₜ (replicate {n = n} x) ≈⟨ +-congʳ idem ⟩\n x + sumₜ (replicate {n = n} x) ≈⟨ sumₜ-idem-replicate n idem ⟩\n x ∎\n\n-- The sum over the constantly zero function is zero.\n\nsumₜ-zero : ∀ n → sumₜ (replicate {n = n} 0#) ≈ 0#\nsumₜ-zero n = begin\n sumₜ (replicate {n = n} 0#) ≈⟨ sym (+-identityˡ _) ⟩\n 0# + sumₜ (replicate {n = n} 0#) ≈⟨ sumₜ-idem-replicate n (+-identityˡ 0#) ⟩\n 0# ∎\n\n-- The '∑' operator distributes over addition.\n\n∑-distrib-+ : ∀ n (f g : Fin n → Carrier) → ∑[ i < n ] (f i + g i) ≈ ∑[ i < n ] f i + ∑[ i < n ] g i\n∑-distrib-+ zero f g = sym (+-identityˡ _)\n∑-distrib-+ (suc n) f g = begin\n f₀ + g₀ + ∑fg ≈⟨ +-assoc _ _ _ ⟩\n f₀ + (g₀ + ∑fg) ≈⟨ +-congˡ (+-congˡ (∑-distrib-+ n _ _)) ⟩\n f₀ + (g₀ + (∑f + ∑g)) ≈⟨ solve 4 (λ a b c d → a ⊕ (c ⊕ (b ⊕ d)) ⊜ (a ⊕ b) ⊕ (c ⊕ d)) refl f₀ ∑f g₀ ∑g ⟩\n (f₀ + ∑f) + (g₀ + ∑g) ∎\n where\n f₀ = f zero\n g₀ = g zero\n ∑f = ∑[ i < n ] f (suc i)\n ∑g = ∑[ i < n ] g (suc i)\n ∑fg = ∑[ i < n ] (f (suc i) + g (suc i))\n\n-- The '∑' operator commutes with itself.\n\n∑-comm : ∀ n m (f : Fin n → Fin m → Carrier) → ∑[ i < n ] ∑[ j < m ] f i j ≈ ∑[ j < m ] ∑[ i < n ] f i j\n∑-comm zero m f = sym (sumₜ-zero m)\n∑-comm (suc n) m f = begin\n ∑[ j < m ] f zero j + ∑[ i < n ] ∑[ j < m ] f (suc i) j ≈⟨ +-congˡ (∑-comm n m _) ⟩\n ∑[ j < m ] f zero j + ∑[ j < m ] ∑[ i < n ] f (suc i) j ≈⟨ sym (∑-distrib-+ m _ _) ⟩\n ∑[ j < m ] (f zero j + ∑[ i < n ] f (suc i) j) ∎\n\n-- Any permutation of a table has the same sum as the original.\n\nsumₜ-permute : ∀ {m n} t (π : Permutation m n) → sumₜ t ≈ sumₜ (permute π t)\nsumₜ-permute {zero} {zero} t π = refl\nsumₜ-permute {zero} {suc n} t π = contradiction π (Perm.refute λ())\nsumₜ-permute {suc m} {zero} t π = contradiction π (Perm.refute λ())\nsumₜ-permute {suc m} {suc n} t π = begin\n sumₜ t ≡⟨⟩\n lookup t 0i + sumₜ (remove 0i t) ≡⟨ P.cong₂ _+_ (P.cong (lookup t) (P.sym (Perm.inverseʳ π))) P.refl ⟩\n lookup πt (π ⟨$⟩ˡ 0i) + sumₜ (remove 0i t) ≈⟨ +-congˡ (sumₜ-permute (remove 0i t) (Perm.remove (π ⟨$⟩ˡ 0i) π)) ⟩\n lookup πt (π ⟨$⟩ˡ 0i) + sumₜ (permute (Perm.remove (π ⟨$⟩ˡ 0i) π) (remove 0i t)) ≡⟨ P.cong₂ _+_ P.refl (sumₜ-cong-≡ (P.sym ∘ TP.remove-permute π 0i t)) ⟩\n lookup πt (π ⟨$⟩ˡ 0i) + sumₜ (remove (π ⟨$⟩ˡ 0i) πt) ≈⟨ sym (sumₜ-remove (permute π t)) ⟩\n sumₜ πt ∎\n where\n 0i = zero\n πt = permute π t\n\n∑-permute : ∀ {m n} f (π : Permutation m n) → ∑[ i < n ] f i ≈ ∑[ i < m ] f (π ⟨$⟩ʳ i)\n∑-permute = sumₜ-permute ∘ tabulate\n\n-- If the function takes the same value at 'i' and 'j', then transposing 'i' and\n-- 'j' then selecting 'j' is the same as selecting 'i'.\n\nselect-transpose : ∀ {n} t (i j : Fin n) → lookup t i ≈ lookup t j → ∀ k → (lookup (select 0# j t) ∘ PermC.transpose i j) k ≈ lookup (select 0# i t) k\nselect-transpose _ i j e k with k FP.≟ i\n... | yes p rewrite P.≡-≟-identity FP._≟_ {j} P.refl = sym e\n... | no ¬p with k FP.≟ j\n... | no ¬q rewrite proj₂ (P.≢-≟-identity FP._≟_ ¬q) = refl\n... | yes q rewrite proj₂ (P.≢-≟-identity FP._≟_\n (¬p ∘ P.trans q ∘ P.sym)) = refl\n\n-- Summing over a pulse gives you the single value picked out by the pulse.\n\nsumₜ-select : ∀ {n i} (t : Table Carrier n) → sumₜ (select 0# i t) ≈ lookup t i\nsumₜ-select {zero} {()}\nsumₜ-select {suc n} {i} t = begin\n sumₜ (select 0# i t) ≈⟨ sumₜ-remove {i = i} (select 0# i t) ⟩\n lookup (select 0# i t) i + sumₜ (remove i (select 0# i t)) ≡⟨ P.cong₂ _+_ (TP.select-lookup t) (sumₜ-cong-≡ (TP.select-remove i t)) ⟩\n lookup t i + sumₜ (replicate {n = n} 0#) ≈⟨ +-congˡ (sumₜ-zero n) ⟩\n lookup t i + 0# ≈⟨ +-identityʳ _ ⟩\n lookup t i ∎\n\n-- Converting to a table then summing is the same as summing the original list\n\nsumₜ-fromList : ∀ xs → sumₜ (fromList xs) ≡ sumₗ xs\nsumₜ-fromList [] = P.refl\nsumₜ-fromList (x ∷ xs) = P.cong (_ +_) (sumₜ-fromList xs)\n\n-- Converting to a list then summing is the same as summing the original table\n\nsumₜ-toList : ∀ {n} (t : Table Carrier n) → sumₜ t ≡ sumₗ (toList t)\nsumₜ-toList {zero} _ = P.refl\nsumₜ-toList {suc n} _ = P.cong (_ +_) (sumₜ-toList {n} _)\n", "meta": {"hexsha": "c1eee5255809c804193aa28828bd450a18b5d786", "size": 7634, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Properties/CommutativeMonoid.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": "test/asset/agda-stdlib-1.0/Algebra/Properties/CommutativeMonoid.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Algebra/Properties/CommutativeMonoid.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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.4111111111, "max_line_length": 156, "alphanum_fraction": 0.539166885, "num_tokens": 3059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947425132315, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3631197923814508}} {"text": "------------------------------------------------------------------------\n-- A lookahead operator cannot be defined\n------------------------------------------------------------------------\n\n-- In \"Parsing with First-Class Derivatives\" Brachthäuser, Rendel and\n-- Ostermann state that \"Lookahead and [...] cannot be expressed as\n-- user defined combinators\". Here I give a formal proof of a variant\n-- of this statement (in the present setting).\n\nmodule TotalParserCombinators.NoLookahead where\n\nopen import Data.List\nopen import Data.List.Properties\nopen import Data.Product\nopen import Data.Unit\nopen import Function.Base\nopen import Function.Equality using (_⟨$⟩_)\nopen import Function.Equivalence using (Equivalence; _⇔_)\nopen import Relation.Binary.PropositionalEquality as PE using (_≡_)\nopen import Relation.Nullary\n\nopen import TotalParserCombinators.Lib\nopen import TotalParserCombinators.Parser\nopen import TotalParserCombinators.Semantics.Continuation\n\n-- It is impossible to define a lookahead operator satisfying a\n-- certain specification (without changing the interface of the parser\n-- combinator library).\n\nno-lookahead :\n ¬ ∃ λ (look : ∀ {Tok R} {f-bag : List Tok → List R} →\n ((s : List Tok) → Parser Tok R (f-bag s)) →\n Parser Tok R (f-bag [])) →\n ∀ {Tok R x s₁ s₂} {f-bag : List Tok → List R}\n {f : (s : List Tok) → Parser Tok R (f-bag s)} →\n x ⊕ s₂ ∈ look f · s₁ ⇔ x ⊕ s₂ ∈ f s₁ · s₁\nno-lookahead (look , correct) = ¬f[-]·[-] f[-]·[-]\n where\n f-bag : List ⊤ → List ⊤\n f-bag [] = [ _ ]\n f-bag (_ ∷ _) = []\n\n f : (s : List ⊤) → Parser ⊤ ⊤ (f-bag s)\n f [] = return _\n f (_ ∷ _) = fail\n\n f[]·[] : _ ⊕ [] ∈ f [] · []\n f[]·[] = return\n\n look-f·[] : _ ⊕ [] ∈ look f · []\n look-f·[] = Equivalence.from correct ⟨$⟩ f[]·[]\n\n look-f·[-] : _ ⊕ [ _ ] ∈ look f · [ _ ]\n look-f·[-] = extend look-f·[]\n\n f[-]·[-] : _ ⊕ [ _ ] ∈ f [ _ ] · [ _ ]\n f[-]·[-] = Equivalence.to correct ⟨$⟩ look-f·[-]\n\n ¬f[-]·[-] : ¬ _ ⊕ [ _ ] ∈ f [ _ ] · [ _ ]\n ¬f[-]·[-] ()\n", "meta": {"hexsha": "2a88c0f78865c21c69e73f67a39d7d65f48cfc54", "size": 2030, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "TotalParserCombinators/NoLookahead.agda", "max_stars_repo_name": "nad/parser-combinators", "max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z", "max_issues_repo_path": "TotalParserCombinators/NoLookahead.agda", "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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": "TotalParserCombinators/NoLookahead.agda", "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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": 33.2786885246, "max_line_length": 72, "alphanum_fraction": 0.5561576355, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3631197849121215}} {"text": "------------------------------------------------------------------------\n-- Context extensions with the leftmost element in the outermost\n-- position\n------------------------------------------------------------------------\n\nopen import Data.Universe.Indexed\n\nmodule deBruijn.Context.Extension.Left\n {i u e} (Uni : IndexedUniverse i u e) where\n\nimport deBruijn.Context.Basics as Basics\nimport deBruijn.Context.Extension.Right as Right\nopen import Function\nopen import Level using (_⊔_)\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\n\nopen Basics Uni\nopen Right Uni\nopen P.≡-Reasoning\n\n------------------------------------------------------------------------\n-- Context extensions along with various operations making use of them\n\n-- Context extensions.\n\ninfixr 5 _◅_\n\ndata Ctxt₊ (Γ : Ctxt) : Set (i ⊔ u ⊔ e) where\n ε : Ctxt₊ Γ\n _◅_ : (σ : Type Γ) (Γ₊ : Ctxt₊ (Γ ▻ σ)) → Ctxt₊ Γ\n\n-- A synonym.\n\nε₊[_] : (Γ : Ctxt) → Ctxt₊ Γ\nε₊[ _ ] = ε\n\n-- Appends a context extension to a context.\n\ninfixl 5 _++₊_\n\n_++₊_ : (Γ : Ctxt) → Ctxt₊ Γ → Ctxt\nΓ ++₊ ε = Γ\nΓ ++₊ (σ ◅ Γ₊) = Γ ▻ σ ++₊ Γ₊\n\n-- The following operations append a context extension to a context\n-- extension.\n\ninfixl 5 _₊++₊_ _⁺++₊_\n\n_₊++₊_ : ∀ {Γ} Γ₊ → Ctxt₊ (Γ ++₊ Γ₊) → Ctxt₊ Γ\nε ₊++₊ Γ₊₊ = Γ₊₊\n(σ ◅ Γ₊) ₊++₊ Γ₊₊ = σ ◅ (Γ₊ ₊++₊ Γ₊₊)\n\n_⁺++₊_ : ∀ {Γ} Γ⁺ → Ctxt₊ (Γ ++⁺ Γ⁺) → Ctxt₊ Γ\nε ⁺++₊ Γ₊ = Γ₊\nΓ⁺ ▻ σ ⁺++₊ Γ₊ = Γ⁺ ⁺++₊ (σ ◅ Γ₊)\n\n-- Application of context morphisms to context extensions.\n\ninfixl 8 _/̂₊_\n\n_/̂₊_ : ∀ {Γ Δ} → Ctxt₊ Γ → Γ ⇨̂ Δ → Ctxt₊ Δ\nε /̂₊ ρ̂ = ε\n(σ ◅ Γ₊) /̂₊ ρ̂ = σ /̂ ρ̂ ◅ Γ₊ /̂₊ ρ̂ ↑̂\n\n-- N-ary lifting of context morphisms.\n\ninfixl 10 _↑̂₊_\n\n_↑̂₊_ : ∀ {Γ Δ} (ρ̂ : Γ ⇨̂ Δ) Γ₊ → Γ ++₊ Γ₊ ⇨̂ Δ ++₊ Γ₊ /̂₊ ρ̂\nρ̂ ↑̂₊ ε = ρ̂\nρ̂ ↑̂₊ (σ ◅ Γ₊) = ρ̂ ↑̂ ↑̂₊ Γ₊\n\n-- N-ary weakening.\n\nŵk₊ : ∀ {Γ} Γ₊ → Γ ⇨̂ Γ ++₊ Γ₊\nŵk₊ ε = îd\nŵk₊ (σ ◅ Γ₊) = ŵk[ σ ] ∘̂ ŵk₊ Γ₊\n\n------------------------------------------------------------------------\n-- Equality\n\n-- Equality of context extensions.\n\nrecord [Ctxt₊] : Set (i ⊔ u ⊔ e) where\n constructor [_]\n field\n {Γ} : Ctxt\n Γ₊ : Ctxt₊ Γ\n\ninfix 4 _≅-Ctxt₊_\n\n_≅-Ctxt₊_ : ∀ {Γ₁} (Γ₊₁ : Ctxt₊ Γ₁)\n {Γ₂} (Γ₊₂ : Ctxt₊ Γ₂) → Set _\nΓ₊₁ ≅-Ctxt₊ Γ₊₂ = _≡_ {A = [Ctxt₊]} [ Γ₊₁ ] [ Γ₊₂ ]\n\n≅-Ctxt₊-⇒-≡ : ∀ {Γ} {Γ₊₁ Γ₊₂ : Ctxt₊ Γ} →\n Γ₊₁ ≅-Ctxt₊ Γ₊₂ → Γ₊₁ ≡ Γ₊₂\n≅-Ctxt₊-⇒-≡ P.refl = P.refl\n\n-- Certain uses of substitutivity can be removed.\n\ndrop-subst-Ctxt₊ : ∀ {a} {A : Set a} {x₁ x₂}\n (f : A → Ctxt) {Γ₊} (x₁≡x₂ : x₁ ≡ x₂) →\n P.subst (λ x → Ctxt₊ (f x)) x₁≡x₂ Γ₊ ≅-Ctxt₊ Γ₊\ndrop-subst-Ctxt₊ f P.refl = P.refl\n\n------------------------------------------------------------------------\n-- Some congruences\n\nε₊-cong : ∀ {Γ₁ Γ₂} → Γ₁ ≅-Ctxt Γ₂ → ε₊[ Γ₁ ] ≅-Ctxt₊ ε₊[ Γ₂ ]\nε₊-cong P.refl = P.refl\n\n◅-cong : ∀ {Γ₁ σ₁} {Γ₊₁ : Ctxt₊ (Γ₁ ▻ σ₁)}\n {Γ₂ σ₂} {Γ₊₂ : Ctxt₊ (Γ₂ ▻ σ₂)} →\n Γ₊₁ ≅-Ctxt₊ Γ₊₂ → σ₁ ◅ Γ₊₁ ≅-Ctxt₊ σ₂ ◅ Γ₊₂\n◅-cong P.refl = P.refl\n\n++₊-cong : ∀ {Γ₁} {Γ₊₁ : Ctxt₊ Γ₁} {Γ₂} {Γ₊₂ : Ctxt₊ Γ₂} →\n Γ₊₁ ≅-Ctxt₊ Γ₊₂ → Γ₁ ++₊ Γ₊₁ ≅-Ctxt Γ₂ ++₊ Γ₊₂\n++₊-cong P.refl = P.refl\n\n₊++₊-cong : ∀ {Γ₁ Γ₊₁} {Γ₊₊₁ : Ctxt₊ (Γ₁ ++₊ Γ₊₁)}\n {Γ₂ Γ₊₂} {Γ₊₊₂ : Ctxt₊ (Γ₂ ++₊ Γ₊₂)} →\n Γ₊₁ ≅-Ctxt₊ Γ₊₂ → Γ₊₊₁ ≅-Ctxt₊ Γ₊₊₂ →\n Γ₊₁ ₊++₊ Γ₊₊₁ ≅-Ctxt₊ Γ₊₂ ₊++₊ Γ₊₊₂\n₊++₊-cong P.refl P.refl = P.refl\n\n⁺++₊-cong : ∀ {Γ₁ Γ⁺₁} {Γ₊₁ : Ctxt₊ (Γ₁ ++⁺ Γ⁺₁)}\n {Γ₂ Γ⁺₂} {Γ₊₂ : Ctxt₊ (Γ₂ ++⁺ Γ⁺₂)} →\n Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → Γ₊₁ ≅-Ctxt₊ Γ₊₂ →\n Γ⁺₁ ⁺++₊ Γ₊₁ ≅-Ctxt₊ Γ⁺₂ ⁺++₊ Γ₊₂\n⁺++₊-cong P.refl P.refl = P.refl\n\n/̂₊-cong : ∀ {Γ₁ Δ₁} {Γ₊₁ : Ctxt₊ Γ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁}\n {Γ₂ Δ₂} {Γ₊₂ : Ctxt₊ Γ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} →\n Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ρ̂₁ ≅-⇨̂ ρ̂₂ → Γ₊₁ /̂₊ ρ̂₁ ≅-Ctxt₊ Γ₊₂ /̂₊ ρ̂₂\n/̂₊-cong P.refl P.refl = P.refl\n\n↑̂₊-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {Γ₊₁ : Ctxt₊ Γ₁}\n {Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {Γ₊₂ : Ctxt₊ Γ₂} →\n ρ̂₁ ≅-⇨̂ ρ̂₂ → Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ρ̂₁ ↑̂₊ Γ₊₁ ≅-⇨̂ ρ̂₂ ↑̂₊ Γ₊₂\n↑̂₊-cong P.refl P.refl = P.refl\n\nŵk₊-cong : ∀ {Γ₁} {Γ₊₁ : Ctxt₊ Γ₁} {Γ₂} {Γ₊₂ : Ctxt₊ Γ₂} →\n Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ŵk₊ Γ₊₁ ≅-⇨̂ ŵk₊ Γ₊₂\nŵk₊-cong P.refl = P.refl\n\n------------------------------------------------------------------------\n-- Some properties\n\nabstract\n\n -- Γ ++₊_ has at most one right identity.\n\n private\n\n ++₊-right-identity-unique′ :\n ∀ {Γ} Γ⁺ Γ₊ → Γ ≅-Ctxt Γ ++⁺ Γ⁺ ++₊ Γ₊ → Γ₊ ≅-Ctxt₊ ε₊[ Γ ++⁺ Γ⁺ ]\n ++₊-right-identity-unique′ Γ⁺ ε _ = P.refl\n ++₊-right-identity-unique′ Γ⁺ (σ ◅ Γ₊) eq\n with ++₊-right-identity-unique′ (Γ⁺ ▻ σ) Γ₊ eq\n ++₊-right-identity-unique′ Γ⁺ (σ ◅ .ε) eq | P.refl\n with ++⁺-right-identity-unique (Γ⁺ ▻ σ) eq\n ... | ()\n\n ++₊-right-identity-unique :\n ∀ {Γ} Γ₊ → Γ ≅-Ctxt Γ ++₊ Γ₊ → Γ₊ ≅-Ctxt₊ ε₊[ Γ ]\n ++₊-right-identity-unique Γ₊ = ++₊-right-identity-unique′ ε Γ₊\n\n -- Γ ++₊_ is left cancellative.\n\n private\n\n cancel-++₊-left′ : ∀ {Γ} Γ⁺₁ Γ₊₁ Γ⁺₂ Γ₊₂ →\n Γ ++⁺ Γ⁺₁ ++₊ Γ₊₁ ≅-Ctxt Γ ++⁺ Γ⁺₂ ++₊ Γ₊₂ →\n Γ⁺₁ ⁺++₊ Γ₊₁ ≅-Ctxt₊ Γ⁺₂ ⁺++₊ Γ₊₂\n cancel-++₊-left′ Γ⁺₁ ε Γ⁺₂ ε eq = ⁺++₊-cong (cancel-++⁺-left Γ⁺₁ Γ⁺₂ eq) (ε₊-cong eq)\n cancel-++₊-left′ Γ⁺₁ (σ₁ ◅ Γ₊₁) Γ⁺₂ (σ₂ ◅ Γ₊₂) eq = cancel-++₊-left′ (Γ⁺₁ ▻ σ₁) Γ₊₁ (Γ⁺₂ ▻ σ₂) Γ₊₂ eq\n cancel-++₊-left′ Γ⁺₁ ε Γ⁺₂ (σ₂ ◅ Γ₊₂) eq = cancel-++₊-left′ Γ⁺₁ ε (Γ⁺₂ ▻ σ₂) Γ₊₂ eq\n cancel-++₊-left′ Γ⁺₁ (σ₁ ◅ Γ₊₁) Γ⁺₂ ε eq = cancel-++₊-left′ (Γ⁺₁ ▻ σ₁) Γ₊₁ Γ⁺₂ ε eq\n\n cancel-++₊-left : ∀ {Γ} (Γ₊₁ Γ₊₂ : Ctxt₊ Γ) →\n Γ ++₊ Γ₊₁ ≅-Ctxt Γ ++₊ Γ₊₂ → Γ₊₁ ≅-Ctxt₊ Γ₊₂\n cancel-++₊-left Γ₊₁ Γ₊₂ = cancel-++₊-left′ ε Γ₊₁ ε Γ₊₂\n\n -- _++₊_/_₊++₊_ are associative.\n\n ++₊-++₊ : ∀ {Γ} Γ₊ Γ₊₊ → Γ ++₊ Γ₊ ++₊ Γ₊₊ ≅-Ctxt Γ ++₊ (Γ₊ ₊++₊ Γ₊₊)\n ++₊-++₊ ε Γ₊₊ = P.refl\n ++₊-++₊ (σ ◅ Γ₊) Γ₊₊ = ++₊-++₊ Γ₊ Γ₊₊\n\n -- The identity substitution has no effect.\n\n /̂₊-îd : ∀ {Γ} (Γ₊ : Ctxt₊ Γ) → Γ₊ /̂₊ îd ≅-Ctxt₊ Γ₊\n /̂₊-îd ε = P.refl\n /̂₊-îd (σ ◅ Γ₊) = ◅-cong (/̂₊-îd Γ₊)\n\n -- The n-ary lifting of the identity substitution is the identity\n -- substitution.\n\n îd-↑̂₊ : ∀ {Γ} (Γ₊ : Ctxt₊ Γ) → îd ↑̂₊ Γ₊ ≅-⇨̂ îd[ Γ ++₊ Γ₊ ]\n îd-↑̂₊ ε = P.refl\n îd-↑̂₊ (σ ◅ Γ₊) = begin\n [ îd ↑̂ ↑̂₊ Γ₊ ] ≡⟨ P.refl ⟩\n [ îd ↑̂₊ Γ₊ ] ≡⟨ îd-↑̂₊ Γ₊ ⟩\n [ îd ] ∎\n\n -- The identity substitution has no effect even if lifted.\n\n /̂-îd-↑̂₊ : ∀ {Γ} Γ₊ (σ : Type (Γ ++₊ Γ₊)) → σ /̂ îd ↑̂₊ Γ₊ ≅-Type σ\n /̂-îd-↑̂₊ Γ₊ σ = begin\n [ σ /̂ îd ↑̂₊ Γ₊ ] ≡⟨ /̂-cong (P.refl {x = [ σ ]}) (îd-↑̂₊ Γ₊) ⟩\n [ σ /̂ îd ] ≡⟨ P.refl ⟩\n [ σ ] ∎\n\n -- Applying two substitutions is equivalent to applying their\n -- composition.\n\n /̂₊-∘̂ : ∀ {Γ Δ Ε} Γ₊ (ρ̂₁ : Γ ⇨̂ Δ) (ρ̂₂ : Δ ⇨̂ Ε) →\n Γ₊ /̂₊ ρ̂₁ ∘̂ ρ̂₂ ≅-Ctxt₊ Γ₊ /̂₊ ρ̂₁ /̂₊ ρ̂₂\n /̂₊-∘̂ ε ρ̂₁ ρ̂₂ = P.refl\n /̂₊-∘̂ (σ ◅ Γ₊) ρ̂₁ ρ̂₂ = ◅-cong (/̂₊-∘̂ Γ₊ (ρ̂₁ ↑̂) (ρ̂₂ ↑̂))\n\n -- _↑̂₊_ distributes over _∘̂_.\n\n ∘̂-↑̂₊ : ∀ {Γ Δ Ε} (ρ̂₁ : Γ ⇨̂ Δ) (ρ̂₂ : Δ ⇨̂ Ε) Γ₊ →\n (ρ̂₁ ∘̂ ρ̂₂) ↑̂₊ Γ₊ ≅-⇨̂ ρ̂₁ ↑̂₊ Γ₊ ∘̂ ρ̂₂ ↑̂₊ (Γ₊ /̂₊ ρ̂₁)\n ∘̂-↑̂₊ ρ̂₁ ρ̂₂ ε = P.refl\n ∘̂-↑̂₊ ρ̂₁ ρ̂₂ (σ ◅ Γ₊) = begin\n [ (ρ̂₁ ∘̂ ρ̂₂) ↑̂ ↑̂₊ Γ₊ ] ≡⟨ P.refl ⟩\n [ (ρ̂₁ ↑̂ ∘̂ ρ̂₂ ↑̂) ↑̂₊ Γ₊ ] ≡⟨ ∘̂-↑̂₊ (ρ̂₁ ↑̂) (ρ̂₂ ↑̂) Γ₊ ⟩\n [ (ρ̂₁ ↑̂ ↑̂₊ Γ₊) ∘̂ (ρ̂₂ ↑̂ ↑̂₊ (Γ₊ /̂₊ ρ̂₁ ↑̂)) ] ∎\n\n -- A corollary.\n\n /̂-↑̂₊-/̂-ŵk-↑̂₊ : ∀ {Γ Δ} σ (ρ̂ : Γ ⇨̂ Δ) (Γ₊ : Ctxt₊ Γ) τ →\n τ /̂ ρ̂ ↑̂₊ Γ₊ /̂ ŵk[ σ /̂ ρ̂ ] ↑̂₊ (Γ₊ /̂₊ ρ̂) ≅-Type\n τ /̂ ŵk[ σ ] ↑̂₊ Γ₊ /̂ ρ̂ ↑̂ ↑̂₊ (Γ₊ /̂₊ ŵk)\n /̂-↑̂₊-/̂-ŵk-↑̂₊ σ ρ̂ Γ₊ τ = /̂-cong (P.refl {x = [ τ ]}) (begin\n [ ρ̂ ↑̂₊ Γ₊ ∘̂ ŵk ↑̂₊ (Γ₊ /̂₊ ρ̂) ] ≡⟨ P.sym $ ∘̂-↑̂₊ ρ̂ ŵk Γ₊ ⟩\n [ (ρ̂ ∘̂ ŵk) ↑̂₊ Γ₊ ] ≡⟨ P.refl ⟩\n [ (ŵk[ σ ] ∘̂ ρ̂ ↑̂) ↑̂₊ Γ₊ ] ≡⟨ ∘̂-↑̂₊ ŵk[ σ ] (ρ̂ ↑̂) Γ₊ ⟩\n [ ŵk[ σ ] ↑̂₊ Γ₊ ∘̂ ρ̂ ↑̂ ↑̂₊ (Γ₊ /̂₊ ŵk) ] ∎)\n\n -- ŵk₊ commutes (modulo lifting) with arbitrary context morphisms.\n\n ∘̂-ŵk₊ : ∀ {Γ Δ} (ρ̂ : Γ ⇨̂ Δ) Γ₊ →\n ρ̂ ∘̂ ŵk₊ (Γ₊ /̂₊ ρ̂) ≅-⇨̂ ŵk₊ Γ₊ ∘̂ ρ̂ ↑̂₊ Γ₊\n ∘̂-ŵk₊ ρ̂ ε = P.refl\n ∘̂-ŵk₊ ρ̂ (σ ◅ Γ₊) = begin\n [ ρ̂ ∘̂ ŵk ∘̂ ŵk₊ (Γ₊ /̂₊ ρ̂ ↑̂) ] ≡⟨ P.refl ⟩\n [ ŵk[ σ ] ∘̂ ρ̂ ↑̂ ∘̂ ŵk₊ (Γ₊ /̂₊ ρ̂ ↑̂) ] ≡⟨ ∘̂-cong (P.refl {x = [ ŵk ]}) (∘̂-ŵk₊ (ρ̂ ↑̂) Γ₊) ⟩\n [ ŵk ∘̂ ŵk₊ Γ₊ ∘̂ ρ̂ ↑̂ ↑̂₊ Γ₊ ] ∎\n\n -- ŵk₊ is homomorphic with respect to _₊++₊_/_∘̂_.\n\n ŵk₊-₊++₊ : ∀ {Γ} (Γ₊ : Ctxt₊ Γ) (Γ₊₊ : Ctxt₊ (Γ ++₊ Γ₊)) →\n ŵk₊ (Γ₊ ₊++₊ Γ₊₊) ≅-⇨̂ ŵk₊ Γ₊ ∘̂ ŵk₊ Γ₊₊\n ŵk₊-₊++₊ ε Γ₊₊ = P.refl\n ŵk₊-₊++₊ (σ ◅ Γ₊) Γ₊₊ = ∘̂-cong (P.refl {x = [ ŵk ]}) (ŵk₊-₊++₊ Γ₊ Γ₊₊)\n\n -- Two n-ary liftings can be merged into one.\n\n ↑̂₊-₊++₊ : ∀ {Γ Δ} (ρ̂ : Γ ⇨̂ Δ) Γ₊ Γ₊₊ →\n ρ̂ ↑̂₊ (Γ₊ ₊++₊ Γ₊₊) ≅-⇨̂ ρ̂ ↑̂₊ Γ₊ ↑̂₊ Γ₊₊\n ↑̂₊-₊++₊ ρ̂ ε Γ₊₊ = P.refl\n ↑̂₊-₊++₊ ρ̂ (σ ◅ Γ₊) Γ₊₊ = ↑̂₊-₊++₊ (ρ̂ ↑̂) Γ₊ Γ₊₊\n\n -- _/̂₊_ distributes over _₊++₊_ (sort of).\n\n ++₊-₊++₊-/̂₊ :\n ∀ {Γ Δ} (ρ̂ : Γ ⇨̂ Δ) Γ₊ Γ₊₊ →\n Δ ++₊ (Γ₊ ₊++₊ Γ₊₊) /̂₊ ρ̂ ≅-Ctxt Δ ++₊ Γ₊ /̂₊ ρ̂ ++₊ Γ₊₊ /̂₊ ρ̂ ↑̂₊ Γ₊\n ++₊-₊++₊-/̂₊ ρ̂ ε Γ₊₊ = P.refl\n ++₊-₊++₊-/̂₊ {Δ = Δ} ρ̂ (σ ◅ Γ₊) Γ₊₊ = ++₊-₊++₊-/̂₊ (ρ̂ ↑̂) Γ₊ Γ₊₊\n", "meta": {"hexsha": "987ade6696c5d622d2b3bf964d873fd8b26ecc65", "size": 9200, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "deBruijn/Context/Extension/Left.agda", "max_stars_repo_name": "nad/dependently-typed-syntax", "max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z", "max_issues_repo_path": "deBruijn/Context/Extension/Left.agda", "max_issues_repo_name": "nad/dependently-typed-syntax", "max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "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": "deBruijn/Context/Extension/Left.agda", "max_forks_repo_name": "nad/dependently-typed-syntax", "max_forks_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "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": 33.2129963899, "max_line_length": 107, "alphanum_fraction": 0.3661956522, "num_tokens": 5900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6688802735722128, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3631105413607349}} {"text": "module OlderBasicILP.Direct.Translation where\n\nopen import Common.Context public\n\n-- import OlderBasicILP.Direct.Hilbert.Sequential as HS\nimport OlderBasicILP.Direct.Hilbert.Nested as HN\nimport OlderBasicILP.Direct.Gentzen as G\n\n-- open HS using () renaming (_⊢×_ to HS⟨_⊢×_⟩ ; _⊢_ to HS⟨_⊢_⟩) public\nopen HN using () renaming (_⊢_ to HN⟨_⊢_⟩ ; _⊢⋆_ to HN⟨_⊢⋆_⟩) public\nopen G using () renaming (_⊢_ to G⟨_⊢_⟩ ; _⊢⋆_ to G⟨_⊢⋆_⟩) public\n\n\n-- Translation from sequential Hilbert-style to nested.\n\n-- hs→hn : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → HN⟨ Γ ⊢ A ⟩\n-- hs→hn = ?\n\n\n-- Translation from nested Hilbert-style to sequential.\n\n-- hn→hs : ∀ {A Γ} → HN⟨ Γ ⊢ A ⟩ → HS⟨ Γ ⊢ A ⟩\n-- hn→hs = ?\n\n\n-- Deduction theorem for sequential Hilbert-style.\n\n-- hs-lam : ∀ {A B Γ} → HS⟨ Γ , A ⊢ B ⟩ → HS⟨ Γ ⊢ A ▻ B ⟩\n-- hs-lam = hn→hs ∘ HN.lam ∘ hs→hn\n\n\n-- Translation from Hilbert-style to Gentzen-style.\n\nmutual\n hn→gᵇᵒˣ : HN.Box → G.Box\n hn→gᵇᵒˣ HN.[ t ] = {!G.[ hn→g t ]!}\n\n hn→gᵀ : HN.Ty → G.Ty\n hn→gᵀ (HN.α P) = G.α P\n hn→gᵀ (A HN.▻ B) = hn→gᵀ A G.▻ hn→gᵀ B\n hn→gᵀ (T HN.⦂ A) = hn→gᵇᵒˣ T G.⦂ hn→gᵀ A\n hn→gᵀ (A HN.∧ B) = hn→gᵀ A G.∧ hn→gᵀ B\n hn→gᵀ HN.⊤ = G.⊤\n\n hn→gᵀ⋆ : Cx HN.Ty → Cx G.Ty\n hn→gᵀ⋆ ∅ = ∅\n hn→gᵀ⋆ (Γ , A) = hn→gᵀ⋆ Γ , hn→gᵀ A\n\n hn→gⁱ : ∀ {A Γ} → A ∈ Γ → hn→gᵀ A ∈ hn→gᵀ⋆ Γ\n hn→gⁱ top = top\n hn→gⁱ (pop i) = pop (hn→gⁱ i)\n\n hn→g : ∀ {A Γ} → HN⟨ Γ ⊢ A ⟩ → G⟨ hn→gᵀ⋆ Γ ⊢ hn→gᵀ A ⟩\n hn→g (HN.var i) = G.var (hn→gⁱ i)\n hn→g (HN.app t u) = G.app (hn→g t) (hn→g u)\n hn→g HN.ci = G.ci\n hn→g HN.ck = G.ck\n hn→g HN.cs = G.cs\n hn→g (HN.box t) = {!G.box (hn→g t)!}\n hn→g HN.cdist = {!G.cdist!}\n hn→g HN.cup = {!G.cup!}\n hn→g HN.cdown = G.cdown\n hn→g HN.cpair = G.cpair\n hn→g HN.cfst = G.cfst\n hn→g HN.csnd = G.csnd\n hn→g HN.unit = G.unit\n\n-- hs→g : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → G⟨ Γ ⊢ A ⟩\n-- hs→g = hn→g ∘ hs→hn\n\n\n-- Translation from Gentzen-style to Hilbert-style.\n\nmutual\n g→hnᵇᵒˣ : G.Box → HN.Box\n g→hnᵇᵒˣ G.[ t ] = {!HN.[ g→hn t ]!}\n\n g→hnᵀ : G.Ty → HN.Ty\n g→hnᵀ (G.α P) = HN.α P\n g→hnᵀ (A G.▻ B) = g→hnᵀ A HN.▻ g→hnᵀ B\n g→hnᵀ (T G.⦂ A) = g→hnᵇᵒˣ T HN.⦂ g→hnᵀ A\n g→hnᵀ (A G.∧ B) = g→hnᵀ A HN.∧ g→hnᵀ B\n g→hnᵀ G.⊤ = HN.⊤\n\n g→hnᵀ⋆ : Cx G.Ty → Cx HN.Ty\n g→hnᵀ⋆ ∅ = ∅\n g→hnᵀ⋆ (Γ , A) = g→hnᵀ⋆ Γ , g→hnᵀ A\n\n g→hnⁱ : ∀ {A Γ} → A ∈ Γ → g→hnᵀ A ∈ g→hnᵀ⋆ Γ\n g→hnⁱ top = top\n g→hnⁱ (pop i) = pop (g→hnⁱ i)\n\n g→hn : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → HN⟨ g→hnᵀ⋆ Γ ⊢ g→hnᵀ A ⟩\n g→hn (G.var i) = HN.var (g→hnⁱ i)\n g→hn (G.lam t) = HN.lam (g→hn t)\n g→hn (G.app t u) = HN.app (g→hn t) (g→hn u)\n-- g→hn (G.multibox ts u) = {!HN.multibox (g→hn⋆ ts) (g→hn u)!}\n g→hn (G.down t) = HN.down (g→hn t)\n g→hn (G.pair t u) = HN.pair (g→hn t) (g→hn u)\n g→hn (G.fst t) = HN.fst (g→hn t)\n g→hn (G.snd t) = HN.snd (g→hn t)\n g→hn G.unit = HN.unit\n\n g→hn⋆ : ∀ {Ξ Γ} → G⟨ Γ ⊢⋆ Ξ ⟩ → HN⟨ g→hnᵀ⋆ Γ ⊢⋆ g→hnᵀ⋆ Ξ ⟩\n g→hn⋆ {∅} ∙ = ∙\n g→hn⋆ {Ξ , A} (ts , t) = g→hn⋆ ts , g→hn t\n\n-- g→hs : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → HS⟨ Γ ⊢ A ⟩\n-- g→hs = hn→hs ∘ g→hn\n", "meta": {"hexsha": "18edd7f3f8de07c4efdcd52c84f3356c105cfafa", "size": 3091, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "OlderBasicILP/Direct/Translation.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": "OlderBasicILP/Direct/Translation.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": "OlderBasicILP/Direct/Translation.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": 28.1, "max_line_length": 71, "alphanum_fraction": 0.484309285, "num_tokens": 1821, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6370307944803832, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.36301368726711336}} {"text": "module PiQ.Invariants where\nopen import Data.Empty\nopen import Data.Unit\nopen import Data.Sum\nopen import Data.Product\nopen import Relation.Binary.Core\nopen import Relation.Binary\nopen import Relation.Nullary\nopen import Relation.Binary.PropositionalEquality\nopen import Data.Nat\nopen import Data.Nat.Properties\nopen import Function using (_∘_)\nopen import PiQ.Syntax\nopen import PiQ.Opsem\nopen import PiQ.NoRepeat\n\n-- Reconstruct the whole combinator from context\ngetℂκ : ∀ {A B} → A ↔ B → Context {A} {B} → ∃[ C ] ∃[ D ] (C ↔ D)\ngetℂκ c ☐ = _ , _ , c\ngetℂκ c (☐⨾ c₂ • κ) = getℂκ (c ⨾ c₂) κ\ngetℂκ c (c₁ ⨾☐• κ) = getℂκ (c₁ ⨾ c) κ\ngetℂκ c (☐⊕ c₂ • κ) = getℂκ (c ⊕ c₂) κ\ngetℂκ c (c₁ ⊕☐• κ) = getℂκ (c₁ ⊕ c) κ\ngetℂκ c (☐⊗[ c₂ , x ]• κ) = getℂκ (c ⊗ c₂) κ\ngetℂκ c ([ c₁ , x ]⊗☐• κ) = getℂκ (c₁ ⊗ c) κ\n\ngetℂ : (st : State) → st ≢ ⊠ → ∃[ A ] ∃[ B ] (A ↔ B)\ngetℂ ⟨ c ∣ _ ∣ κ ⟩▷ _ = getℂκ c κ\ngetℂ [ c ∣ _ ∣ κ ]▷ _ = getℂκ c κ\ngetℂ ⟨ c ∣ _ ∣ κ ⟩◁ _ = getℂκ c κ\ngetℂ [ c ∣ _ ∣ κ ]◁ _ = getℂκ c κ\ngetℂ ⊠ st≢⊠ = ⊥-elim (st≢⊠ refl)\n\n-- The reconstructed combinator stays the same\nℂInvariant : ∀ {st st'} → st ↦ st' → (¬fail : st ≢ ⊠) → (¬fail' : st' ≢ ⊠) → getℂ st ¬fail ≡ getℂ st' ¬fail'\nℂInvariant ↦⃗₁ _ _ = refl\nℂInvariant ↦⃗₂ _ _ = refl\nℂInvariant ↦⃗₃ _ _ = refl\nℂInvariant ↦⃗₄ _ _ = refl\nℂInvariant ↦⃗₅ _ _ = refl\nℂInvariant ↦⃗₆ _ _ = refl\nℂInvariant ↦⃗₇ _ _ = refl\nℂInvariant ↦⃗₈ _ _ = refl\nℂInvariant ↦⃗₉ _ _ = refl\nℂInvariant ↦⃗₁₀ _ _ = refl\nℂInvariant ↦⃗₁₁ _ _ = refl\nℂInvariant ↦⃗₁₂ _ _ = refl\nℂInvariant ↦⃖₁ _ _ = refl\nℂInvariant ↦⃖₂ _ _ = refl\nℂInvariant ↦⃖₃ _ _ = refl\nℂInvariant ↦⃖₄ _ _ = refl\nℂInvariant ↦⃖₅ _ _ = refl\nℂInvariant ↦⃖₆ _ _ = refl\nℂInvariant ↦⃖₇ _ _ = refl\nℂInvariant ↦⃖₈ _ _ = refl\nℂInvariant ↦⃖₉ _ _ = refl\nℂInvariant ↦⃖₁₀ _ _ = refl\nℂInvariant ↦⃖₁₁ _ _ = refl\nℂInvariant ↦⃖₁₂ _ _ = refl\nℂInvariant ↦η₊₁ _ _ = refl\nℂInvariant ↦η₊₂ _ _ = refl\nℂInvariant ↦ε₊₁ _ _ = refl\nℂInvariant ↦ε₊₂ _ _ = refl\nℂInvariant ↦⃗ηₓ _ _ = refl\nℂInvariant ↦⃖ηₓ₁ _ _ = refl\nℂInvariant ↦⃖ηₓ₂ _ ¬fail' = ⊥-elim (¬fail' refl)\nℂInvariant ↦⃗εₓ₁ _ _ = refl\nℂInvariant ↦⃗εₓ₂ _ ¬fail' = ⊥-elim (¬fail' refl)\nℂInvariant ↦⃖εₓ _ _ = refl\n\nℂInvariant* : ∀ {st st'} → st ↦* st' → (¬fail : st ≢ ⊠) → (¬fail' : st' ≢ ⊠) → getℂ st ¬fail ≡ getℂ st' ¬fail'\nℂInvariant* {⟨ _ ∣ _ ∣ _ ⟩▷} ◾ _ _ = refl\nℂInvariant* {[ _ ∣ _ ∣ _ ]▷} ◾ _ _ = refl\nℂInvariant* {⟨ _ ∣ _ ∣ _ ⟩◁} ◾ _ _ = refl\nℂInvariant* {[ _ ∣ _ ∣ _ ]◁} ◾ _ _ = refl\nℂInvariant* {⊠} ◾ ¬fail _ = ⊥-elim (¬fail refl)\nℂInvariant* (r ∷ ◾) ¬fail ¬fail' = ℂInvariant r ¬fail ¬fail'\nℂInvariant* (r ∷ (r' ∷ rs)) ¬fail ¬fail' = trans (ℂInvariant r ¬fail λ {refl → ⊠-is-stuck refl (_ , r')})\n (ℂInvariant* (r' ∷ rs) _ ¬fail')\n\n-- Get the type of the deepest context\nget𝕌 : ∀ {A B} → Context {A} {B} → 𝕌 × 𝕌\nget𝕌 {A} {B} ☐ = A , B\nget𝕌 (☐⨾ c₂ • κ) = get𝕌 κ\nget𝕌 (c₁ ⨾☐• κ) = get𝕌 κ\nget𝕌 (☐⊕ c₂ • κ) = get𝕌 κ\nget𝕌 (c₁ ⊕☐• κ) = get𝕌 κ\nget𝕌 (☐⊗[ c₂ , x ]• κ) = get𝕌 κ\nget𝕌 ([ c₁ , x ]⊗☐• κ) = get𝕌 κ\n\nget𝕌State : (st : State) → st ≢ ⊠ → 𝕌 × 𝕌\nget𝕌State ⟨ c ∣ v ∣ κ ⟩▷ _ = get𝕌 κ\nget𝕌State [ c ∣ v ∣ κ ]▷ _ = get𝕌 κ\nget𝕌State ⟨ c ∣ v ∣ κ ⟩◁ _ = get𝕌 κ\nget𝕌State [ c ∣ v ∣ κ ]◁ _ = get𝕌 κ\nget𝕌State ⊠ nf = ⊥-elim (nf refl)\n\n\n-- Append a context to another context\nappendκ : ∀ {A B} → (ctx : Context {A} {B}) → let (C , D) = get𝕌 ctx\n in Context {C} {D} → Context {A} {B}\nappendκ ☐ ctx = ctx\nappendκ (☐⨾ c₂ • κ) ctx = ☐⨾ c₂ • appendκ κ ctx\nappendκ (c₁ ⨾☐• κ) ctx = c₁ ⨾☐• appendκ κ ctx\nappendκ (☐⊕ c₂ • κ) ctx = ☐⊕ c₂ • appendκ κ ctx\nappendκ (c₁ ⊕☐• κ) ctx = c₁ ⊕☐• appendκ κ ctx\nappendκ (☐⊗[ c₂ , x ]• κ) ctx = ☐⊗[ c₂ , x ]• appendκ κ ctx\nappendκ ([ c₁ , x ]⊗☐• κ) ctx = [ c₁ , x ]⊗☐• appendκ κ ctx\n\nappendκState : ∀ st → (nf : st ≢ ⊠)\n → let (A , B) = get𝕌State st nf\n in Context {A} {B} → State\nappendκState ⟨ c ∣ v ∣ κ ⟩▷ _ ctx = ⟨ c ∣ v ∣ appendκ κ ctx ⟩▷\nappendκState [ c ∣ v ∣ κ ]▷ _ ctx = [ c ∣ v ∣ appendκ κ ctx ]▷\nappendκState ⟨ c ∣ v ∣ κ ⟩◁ _ ctx = ⟨ c ∣ v ∣ appendκ κ ctx ⟩◁\nappendκState [ c ∣ v ∣ κ ]◁ _ ctx = [ c ∣ v ∣ appendκ κ ctx ]◁\nappendκState ⊠ nf = ⊥-elim (nf refl)\n\n-- The type of context does not change during execution\n𝕌Invariant : ∀ {st st'} → st ↦ st' → (nf : st ≢ ⊠) → (nf' : st' ≢ ⊠) → get𝕌State st nf ≡ get𝕌State st' nf'\n𝕌Invariant ↦⃗₁ nf nf' = refl\n𝕌Invariant ↦⃗₂ nf nf' = refl\n𝕌Invariant ↦⃗₃ nf nf' = refl\n𝕌Invariant ↦⃗₄ nf nf' = refl\n𝕌Invariant ↦⃗₅ nf nf' = refl\n𝕌Invariant ↦⃗₆ nf nf' = refl\n𝕌Invariant ↦⃗₇ nf nf' = refl\n𝕌Invariant ↦⃗₈ nf nf' = refl\n𝕌Invariant ↦⃗₉ nf nf' = refl\n𝕌Invariant ↦⃗₁₀ nf nf' = refl\n𝕌Invariant ↦⃗₁₁ nf nf' = refl\n𝕌Invariant ↦⃗₁₂ nf nf' = refl\n𝕌Invariant ↦⃖₁ nf nf' = refl\n𝕌Invariant ↦⃖₂ nf nf' = refl\n𝕌Invariant ↦⃖₃ nf nf' = refl\n𝕌Invariant ↦⃖₄ nf nf' = refl\n𝕌Invariant ↦⃖₅ nf nf' = refl\n𝕌Invariant ↦⃖₆ nf nf' = refl\n𝕌Invariant ↦⃖₇ nf nf' = refl\n𝕌Invariant ↦⃖₈ nf nf' = refl\n𝕌Invariant ↦⃖₉ nf nf' = refl\n𝕌Invariant ↦⃖₁₀ nf nf' = refl\n𝕌Invariant ↦⃖₁₁ nf nf' = refl\n𝕌Invariant ↦⃖₁₂ nf nf' = refl\n𝕌Invariant ↦η₊₁ nf nf' = refl\n𝕌Invariant ↦η₊₂ nf nf' = refl\n𝕌Invariant ↦ε₊₁ nf nf' = refl\n𝕌Invariant ↦ε₊₂ nf nf' = refl\n𝕌Invariant ↦⃗ηₓ nf nf' = refl\n𝕌Invariant ↦⃖ηₓ₁ nf nf' = refl\n𝕌Invariant ↦⃖ηₓ₂ nf nf' = ⊥-elim (nf' refl)\n𝕌Invariant ↦⃗εₓ₁ nf nf' = refl\n𝕌Invariant ↦⃗εₓ₂ nf nf' = ⊥-elim (nf' refl)\n𝕌Invariant ↦⃖εₓ nf nf' = refl\n\n𝕌Invariant* : ∀ {st st'} → st ↦* st' → (nf : st ≢ ⊠) → (nf' : st' ≢ ⊠) → get𝕌State st nf ≡ get𝕌State st' nf'\n𝕌Invariant* {⟨ _ ∣ _ ∣ _ ⟩▷} ◾ nf nf' = refl\n𝕌Invariant* {[ _ ∣ _ ∣ _ ]▷} ◾ nf nf' = refl\n𝕌Invariant* {⟨ _ ∣ _ ∣ _ ⟩◁} ◾ nf nf' = refl\n𝕌Invariant* {[ _ ∣ _ ∣ _ ]◁} ◾ nf nf' = refl\n𝕌Invariant* {⊠} ◾ nf nf' = ⊥-elim (nf' refl)\n𝕌Invariant* (r ∷ ◾) nf nf' = 𝕌Invariant r nf nf'\n𝕌Invariant* (r ∷ (r' ∷ rs)) nf nf' = trans (𝕌Invariant r nf nf'') (𝕌Invariant* (r' ∷ rs) nf'' nf')\n where\n nf'' = λ eq → ⊠-is-stuck eq (_ , r')\n\n-- Appending context does not affect reductions\nappendκ↦ : ∀ {st st'} → (r : st ↦ st') (nf : st ≢ ⊠) (nf' : st' ≢ ⊠) (eq : get𝕌State st nf ≡ get𝕌State st' nf')\n → (κ : Context {proj₁ (get𝕌State st nf)} {proj₂ (get𝕌State st nf)})\n → appendκState st nf κ ↦ appendκState st' nf' (subst (λ {(A , B) → Context {A} {B}}) eq κ)\nappendκ↦ ↦⃗₁ nf nf' refl ctx = ↦⃗₁\nappendκ↦ ↦⃗₂ nf nf' refl ctx = ↦⃗₂\nappendκ↦ ↦⃗₃ nf nf' refl ctx = ↦⃗₃\nappendκ↦ ↦⃗₄ nf nf' refl ctx = ↦⃗₄\nappendκ↦ ↦⃗₅ nf nf' refl ctx = ↦⃗₅\nappendκ↦ ↦⃗₆ nf nf' refl ctx = ↦⃗₆\nappendκ↦ ↦⃗₇ nf nf' refl ctx = ↦⃗₇\nappendκ↦ ↦⃗₈ nf nf' refl ctx = ↦⃗₈\nappendκ↦ ↦⃗₉ nf nf' refl ctx = ↦⃗₉\nappendκ↦ ↦⃗₁₀ nf nf' refl ctx = ↦⃗₁₀\nappendκ↦ ↦⃗₁₁ nf nf' refl ctx = ↦⃗₁₁\nappendκ↦ ↦⃗₁₂ nf nf' refl ctx = ↦⃗₁₂\nappendκ↦ ↦⃖₁ nf nf' refl ctx = ↦⃖₁\nappendκ↦ ↦⃖₂ nf nf' refl ctx = ↦⃖₂\nappendκ↦ ↦⃖₃ nf nf' refl ctx = ↦⃖₃\nappendκ↦ ↦⃖₄ nf nf' refl ctx = ↦⃖₄\nappendκ↦ ↦⃖₅ nf nf' refl ctx = ↦⃖₅\nappendκ↦ ↦⃖₆ nf nf' refl ctx = ↦⃖₆\nappendκ↦ ↦⃖₇ nf nf' refl ctx = ↦⃖₇\nappendκ↦ ↦⃖₈ nf nf' refl ctx = ↦⃖₈\nappendκ↦ ↦⃖₉ nf nf' refl ctx = ↦⃖₉\nappendκ↦ ↦⃖₁₀ nf nf' refl ctx = ↦⃖₁₀\nappendκ↦ ↦⃖₁₁ nf nf' refl ctx = ↦⃖₁₁\nappendκ↦ ↦⃖₁₂ nf nf' refl ctx = ↦⃖₁₂\nappendκ↦ ↦η₊₁ nf nf' refl ctx = ↦η₊₁\nappendκ↦ ↦η₊₂ nf nf' refl ctx = ↦η₊₂\nappendκ↦ ↦ε₊₁ nf nf' refl ctx = ↦ε₊₁\nappendκ↦ ↦ε₊₂ nf nf' refl ctx = ↦ε₊₂\nappendκ↦ ↦⃗ηₓ nf nf' refl ctx = ↦⃗ηₓ\nappendκ↦ (↦⃖ηₓ₁ {eq = eq}) nf nf' refl ctx = ↦⃖ηₓ₁ {eq = eq}\nappendκ↦ ↦⃖ηₓ₂ nf nf' eq ctx = ⊥-elim (nf' refl)\nappendκ↦ (↦⃗εₓ₁ {eq = eq}) nf nf' refl ctx = ↦⃗εₓ₁ {eq = eq}\nappendκ↦ ↦⃗εₓ₂ nf nf' eq ctx = ⊥-elim (nf' refl)\nappendκ↦ ↦⃖εₓ nf nf' refl ctx = ↦⃖εₓ\n\nappendκ↦* : ∀ {st st'} → (r : st ↦* st') (nf : st ≢ ⊠) (nf' : st' ≢ ⊠) (eq : get𝕌State st nf ≡ get𝕌State st' nf')\n → (κ : Context {proj₁ (get𝕌State st nf)} {proj₂ (get𝕌State st nf)})\n → appendκState st nf κ ↦* appendκState st' nf' (subst (λ {(A , B) → Context {A} {B}}) eq κ)\nappendκ↦* {⟨ _ ∣ _ ∣ _ ⟩▷} ◾ nf nf' refl ctx = ◾\nappendκ↦* {[ _ ∣ _ ∣ _ ]▷} ◾ nf nf' refl ctx = ◾\nappendκ↦* {⟨ _ ∣ _ ∣ _ ⟩◁} ◾ nf nf' refl ctx = ◾\nappendκ↦* {[ _ ∣ _ ∣ _ ]◁} ◾ nf nf' refl ctx = ◾\nappendκ↦* {⊠} ◾ nf nf' eq ctx = ⊥-elim (nf' refl)\nappendκ↦* (↦⃗₁ {b = b} {v} {κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₁ {b = b} {v} {κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₂ {v = v} {κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₂ {v = v} {κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₃ {v = v} {κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₃ {v = v} {κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₄ {x = x} {κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₄ {x = x} {κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₅ {y = y} {κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₅ {y = y} {κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₆ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₆ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₇ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₇ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₈ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₈ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₉ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₉ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₁₀ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₁₀ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₁₁ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₁₁ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗₁₂ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗₁₂ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₁ {b = b} {v} {κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₁ {b = b} {v} {κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₂ {v = v} {κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₂ {v = v} {κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₃ {v = v} {κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₃ {v = v} {κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₄ {x = x} {κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₄ {x = x} {κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₅ {y = y} {κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₅ {y = y} {κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₆ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₆ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₇ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₇ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₈ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₈ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₉ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₉ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₁₀ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₁₀ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₁₁ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₁₁ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖₁₂ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖₁₂ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦η₊₁ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦η₊₁ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦η₊₂ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦η₊₂ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦ε₊₁ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦ε₊₁ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦ε₊₂ {κ = κ} ∷ rs) nf nf' eq ctx = appendκ↦ (↦ε₊₂ {κ = κ}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗ηₓ ∷ rs) nf nf' eq ctx = appendκ↦ ↦⃗ηₓ nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖ηₓ₁ {eq = eq'} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃖ηₓ₁ {eq = eq'}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃖ηₓ₂ ∷ ◾) nf nf' eq ctx = ⊥-elim (nf' refl)\nappendκ↦* (↦⃗εₓ₁ {eq = eq'} ∷ rs) nf nf' eq ctx = appendκ↦ (↦⃗εₓ₁ {eq = eq'}) nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\nappendκ↦* (↦⃗εₓ₂ ∷ ◾) nf nf' eq ctx = ⊥-elim (nf' refl)\nappendκ↦* (↦⃖εₓ ∷ rs) nf nf' eq ctx = appendκ↦ ↦⃖εₓ nf (λ ()) refl ctx ∷ appendκ↦* rs (λ ()) nf' eq ctx\n\nappendκ↦⊠ : ∀ {st} → (r : st ↦ ⊠) (nf : st ≢ ⊠)\n → (κ : Context {proj₁ (get𝕌State st nf)} {proj₂ (get𝕌State st nf)})\n → appendκState st nf κ ↦ ⊠\nappendκ↦⊠ (↦⃖ηₓ₂ {neq = neq}) nf ctx = ↦⃖ηₓ₂ {neq = neq}\nappendκ↦⊠ (↦⃗εₓ₂ {neq = neq}) nf ctx = ↦⃗εₓ₂ {neq = neq}\n\nappendκ↦*⊠ : ∀ {st} → (r : st ↦* ⊠) (nf : st ≢ ⊠)\n → (κ : Context {proj₁ (get𝕌State st nf)} {proj₂ (get𝕌State st nf)})\n → appendκState st nf κ ↦* ⊠\nappendκ↦*⊠ ◾ nf ctx = ⊥-elim (nf refl)\nappendκ↦*⊠ (r ∷ ◾) nf ctx = appendκ↦⊠ r nf ctx ∷ ◾\nappendκ↦*⊠ (↦⃗₁ ∷ (r' ∷ rs)) nf ctx = ↦⃗₁ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₂ ∷ (r' ∷ rs)) nf ctx = ↦⃗₂ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₃ ∷ (r' ∷ rs)) nf ctx = ↦⃗₃ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₄ ∷ (r' ∷ rs)) nf ctx = ↦⃗₄ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₅ ∷ (r' ∷ rs)) nf ctx = ↦⃗₅ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₆ ∷ (r' ∷ rs)) nf ctx = ↦⃗₆ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₇ ∷ (r' ∷ rs)) nf ctx = ↦⃗₇ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₈ ∷ (r' ∷ rs)) nf ctx = ↦⃗₈ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₉ ∷ (r' ∷ rs)) nf ctx = ↦⃗₉ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₁₀ ∷ (r' ∷ rs)) nf ctx = ↦⃗₁₀ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₁₁ ∷ (r' ∷ rs)) nf ctx = ↦⃗₁₁ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗₁₂ ∷ (r' ∷ rs)) nf ctx = ↦⃗₁₂ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₁ ∷ (r' ∷ rs)) nf ctx = ↦⃖₁ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₂ ∷ (r' ∷ rs)) nf ctx = ↦⃖₂ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₃ ∷ (r' ∷ rs)) nf ctx = ↦⃖₃ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₄ ∷ (r' ∷ rs)) nf ctx = ↦⃖₄ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₅ ∷ (r' ∷ rs)) nf ctx = ↦⃖₅ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₆ ∷ (r' ∷ rs)) nf ctx = ↦⃖₆ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₇ ∷ (r' ∷ rs)) nf ctx = ↦⃖₇ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₈ ∷ (r' ∷ rs)) nf ctx = ↦⃖₈ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₉ ∷ (r' ∷ rs)) nf ctx = ↦⃖₉ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₁₀ ∷ (r' ∷ rs)) nf ctx = ↦⃖₁₀ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₁₁ ∷ (r' ∷ rs)) nf ctx = ↦⃖₁₁ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖₁₂ ∷ (r' ∷ rs)) nf ctx = ↦⃖₁₂ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦η₊₁ ∷ (r' ∷ rs)) nf ctx = ↦η₊₁ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦η₊₂ ∷ (r' ∷ rs)) nf ctx = ↦η₊₂ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦ε₊₁ ∷ (r' ∷ rs)) nf ctx = ↦ε₊₁ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦ε₊₂ ∷ (r' ∷ rs)) nf ctx = ↦ε₊₂ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗ηₓ ∷ (r' ∷ rs)) nf ctx = ↦⃗ηₓ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖ηₓ₁ {eq = eq} ∷ (r' ∷ rs)) nf ctx = ↦⃖ηₓ₁ {eq = eq} ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃗εₓ₁ {eq = eq} ∷ (r' ∷ rs)) nf ctx = ↦⃗εₓ₁ {eq = eq} ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\nappendκ↦*⊠ (↦⃖εₓ ∷ (r' ∷ rs)) nf ctx = ↦⃖εₓ ∷ appendκ↦*⊠ (r' ∷ rs) (λ ()) ctx\n", "meta": {"hexsha": "4811b1906d79ada820fc811b8dfa6a96ad8181ec", "size": 15128, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "PiQ/Invariants.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "PiQ/Invariants.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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": "PiQ/Invariants.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 51.8082191781, "max_line_length": 135, "alphanum_fraction": 0.5159307245, "num_tokens": 8701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7431680086124812, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.36287659852054643}} {"text": "import Lvl\nopen import Type\n\nmodule Structure.Logic.Classical.NaturalDeduction {ℓₗ} {Formula : Type{ℓₗ}} {ℓₘₗ} (Proof : Formula → Type{ℓₘₗ}) where\n\nopen import Functional hiding (Domain)\nimport Structure.Logic.Constructive.NaturalDeduction\nprivate module Constructive = Structure.Logic.Constructive.NaturalDeduction(Proof)\n\n-- TODO: Maybe it is worth to try and take a more minimal approach? (Less axioms? Is this more practical/impractical?)\n\nmodule Propositional where\n open Constructive.Propositional hiding (Theory) public\n\n -- A theory of classical propositional logic expressed using natural deduction rules\n record Theory ⦃ sign : Signature ⦄ : Type{ℓₘₗ Lvl.⊔ ℓₗ} where\n open Signature(sign)\n\n field\n instance ⦃ constructive ⦄ : Constructive.Propositional.Theory ⦃ sign ⦄\n\n open Constructive.Propositional.Theory (constructive) public\n\n field\n excluded-middle : ∀{P} → Proof(P ∨ (¬ P))\n\nmodule Domained = Constructive.Domained\n\nmodule MultiSorted = Constructive.MultiSorted\n\n {-\n Propositional-from-[∧][∨][⊥] : ∀{ℓₗ} → (_∧_ _∨_ : Formula → Formula → Formula) → (⊥ : Formula) →\n ([∧]-intro : ∀{X Y} → X → Y → (X ∧ Y)) →\n ([∧]-elimₗ : ∀{X Y} → (X ∧ Y) → X) →\n ([∧]-elimᵣ : ∀{X Y} → (X ∧ Y) → Y) →\n ([∨]-introₗ : ∀{X Y} → X → (X ∨ Y)) →\n ([∨]-introᵣ : ∀{X Y} → Y → (X ∨ Y)) →\n ([∨]-elim : ∀{X Y Z : Formula} → (X → Z) → (Y → Z) → (X ∨ Y) → Z) →\n ([⊥]-intro : ∀{X : Formula} → X → (X → ⊥) → ⊥) →\n ([⊥]-elim : ∀{X : Formula} → ⊥ → X) →\n Propositional{ℓₗ}\n Propositional-from-[∧][∨][⊥]\n (_∧_) (_∨_) (⊥)\n ([∧]-intro)\n ([∧]-elimₗ)\n ([∧]-elimᵣ)\n ([∨]-introₗ)\n ([∨]-introᵣ)\n ([∨]-elim)\n ([⊥]-intro)\n ([⊥]-elim)\n = record{\n _∧_ = _∧_ ;\n _∨_ = _∨_ ;\n _⟶_ = (x ↦ y ↦ (x ∨ (¬ y))) ;\n _⟵_ = swap _⟶_ ;\n _⟷_ = (x ↦ y ↦ ((x ⟵ y)∧(x ⟶ y))) ;\n ¬_ = (x ↦ (x ⟶ ⊥)) ;\n ⊥ = ⊥ ;\n ⊤ = ¬ ⊥\n }\n -}\n\nmodule _ {ℓₒ} (Domain : Type{ℓₒ}) where\n record ClassicalLogicSignature : Type{ℓₘₗ Lvl.⊔ (ℓₗ Lvl.⊔ ℓₒ)} where\n open Domained(Domain)\n\n field\n instance ⦃ propositionalSignature ⦄ : Propositional.Signature\n instance ⦃ predicateSignature ⦄ : Predicate.Signature\n instance ⦃ equalitySignature ⦄ : Equality.Signature\n\n constructiveLogicSignature : Constructive.ConstructiveLogicSignature(Domain)\n constructiveLogicSignature =\n record{\n propositionalSignature = propositionalSignature ;\n predicateSignature = predicateSignature ;\n equalitySignature = equalitySignature\n }\n\n open Propositional.Signature(propositionalSignature) public\n open Predicate.Signature(predicateSignature) public\n open Equality.Signature(equalitySignature) public\n open Equality.PropositionallyDerivedSignature ⦃ propositionalSignature ⦄ ⦃ equalitySignature ⦄ public\n open Uniqueness.Signature ⦃ propositionalSignature ⦄ ⦃ predicateSignature ⦄ ⦃ equalitySignature ⦄ public\n\n -- A theory of classical predicate/(first-order) logic expressed using natural deduction rules\n record ClassicalLogic : Type{ℓₘₗ Lvl.⊔ (ℓₗ Lvl.⊔ ℓₒ)} where\n open Domained(Domain)\n\n field\n instance ⦃ classicalLogicSignature ⦄ : ClassicalLogicSignature\n open ClassicalLogicSignature(classicalLogicSignature) public\n\n field\n instance ⦃ propositionalTheory ⦄ : Propositional.Theory ⦃ propositionalSignature ⦄\n instance ⦃ predicateTheory ⦄ : Predicate.Theory\n instance ⦃ equalityTheory ⦄ : Equality.Theory\n instance ⦃ existentialWitness ⦄ : Predicate.ExistentialWitness(∃ₗ)\n ⦃ nonEmptyDomain ⦄ : NonEmptyDomain\n\n constructivePropositionalTheory = Propositional.Theory.constructive(propositionalTheory)\n\n constructiveLogic : Constructive.ConstructiveLogic(Domain)\n constructiveLogic =\n record{\n constructiveLogicSignature = constructiveLogicSignature ;\n propositionalTheory = constructivePropositionalTheory ;\n predicateTheory = predicateTheory ;\n equalityTheory = equalityTheory\n }\n\n open Propositional.Theory(propositionalTheory) public\n open Predicate.Theory(predicateTheory) public\n open Equality.Theory(equalityTheory) public\n open Predicate.ExistentialWitness(existentialWitness) public\n open Uniqueness.WitnessTheory ⦃ propositionalSignature ⦄ ⦃ predicateSignature ⦄ ⦃ equalitySignature ⦄ ⦃ constructivePropositionalTheory ⦄ ⦃ predicateTheory ⦄ ⦃ equalityTheory ⦄ ⦃ existentialWitness ⦄ public\n open NonEmptyDomain ⦃ nonEmptyDomain ⦄ public\n", "meta": {"hexsha": "b981723bcf85ecb056f7903f6af45bed37ed1444", "size": 4572, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "old/Structure/Logic/Classical/NaturalDeduction.agda", "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_issues_repo_path": "old/Structure/Logic/Classical/NaturalDeduction.agda", "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": "old/Structure/Logic/Classical/NaturalDeduction.agda", "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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.4201680672, "max_line_length": 210, "alphanum_fraction": 0.6541994751, "num_tokens": 1452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.3628765985205464}} {"text": " postulate\n F : Set₂ → Set₃\n #_ : Set₁ → Set₂\n !_ : Set₀ → Set₁\n\n infix 1 F\n infix 2 #_\n infix 3 !_\n\n syntax F x = ! x\n\n ok₁ : Set₁ → Set₃\n ok₁ X = ! # X\n\n ok₂ : Set₀ → Set₂\n ok₂ X = # ! X\n", "meta": {"hexsha": "d8f41dfcf5ec4412922a58a0162cfd3aecfc01a3", "size": 208, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1436-7.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue1436-7.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue1436-7.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 12.2352941176, "max_line_length": 20, "alphanum_fraction": 0.4711538462, "num_tokens": 99, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.3625295254065659}} {"text": "\nmodule _ where\n\nrecord R : Set₁ where\n field x : Set\n\ng : Set₁\n\nmodule M (r : R) where\n open R r\n f = x\n\ng = R\n", "meta": {"hexsha": "62dc1e9b5a42156d3d32baff36f417230c29c440", "size": 115, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/interaction/Issue3010.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/interaction/Issue3010.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/interaction/Issue3010.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": 8.2142857143, "max_line_length": 22, "alphanum_fraction": 0.5739130435, "num_tokens": 46, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.3625295254065659}} {"text": "open import Agda.Builtin.Char\nopen import Agda.Builtin.Coinduction\nopen import Agda.Builtin.IO\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Unit\nopen import Agda.Builtin.String\n\ndata Colist {a} (A : Set a) : Set a where\n [] : Colist A\n _∷_ : A → ∞ (Colist A) → Colist A\n\n{-# FOREIGN GHC\n data Colist a = Nil | Cons a (MAlonzo.RTE.Inf (Colist a))\n type Colist' l a = Colist a\n\n fromColist :: Colist a -> [a]\n fromColist Nil = []\n fromColist (Cons x xs) = x : fromColist (MAlonzo.RTE.flat xs)\n #-}\n\n{-# COMPILE GHC Colist = data Colist' (Nil | Cons) #-}\n\nto-colist : ∀ {a} {A : Set a} → List A → Colist A\nto-colist [] = []\nto-colist (x ∷ xs) = x ∷ ♯ to-colist xs\n\na-definition-that-uses-♭ :\n ∀ {a} {A : Set a} → Colist A → Colist A\na-definition-that-uses-♭ [] = []\na-definition-that-uses-♭ (x ∷ xs) =\n x ∷ ♯ a-definition-that-uses-♭ (♭ xs)\n\npostulate\n putStr : Colist Char → IO ⊤\n\n{-# COMPILE GHC putStr = putStr . fromColist #-}\n\nmain : IO ⊤\nmain = putStr (a-definition-that-uses-♭\n (to-colist (primStringToList \"apa\\n\")))\n", "meta": {"hexsha": "6c99c74c432347d7ae0ede7fc7cb4fb6dfb0b035", "size": 1075, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Compiler/simple/Issue2909-4.agda", "max_stars_repo_name": "alhassy/agda", "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z", "max_issues_repo_path": "test/Compiler/simple/Issue2909-4.agda", "max_issues_repo_name": "alhassy/agda", "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 16, "max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z", "max_forks_repo_path": "test/Compiler/simple/Issue2909-4.agda", "max_forks_repo_name": "alhassy/agda", "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "avg_line_length": 26.2195121951, "max_line_length": 63, "alphanum_fraction": 0.6158139535, "num_tokens": 385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6584175005616829, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.36252952540656586}} {"text": "module Luau.Type where\n\nopen import FFI.Data.Maybe using (Maybe; just; nothing; just-inv)\nopen import Agda.Builtin.Equality using (_≡_; refl)\nopen import Properties.Dec using (Dec; yes; no)\nopen import Properties.Equality using (cong)\nopen import FFI.Data.Maybe using (Maybe; just; nothing)\n\ndata Type : Set where\n nil : Type\n _⇒_ : Type → Type → Type\n never : Type\n unknown : Type\n boolean : Type\n number : Type\n string : Type\n _∪_ : Type → Type → Type\n _∩_ : Type → Type → Type\n\ndata Scalar : Type → Set where\n\n number : Scalar number\n boolean : Scalar boolean\n string : Scalar string\n nil : Scalar nil\n\nlhs : Type → Type\nlhs (T ⇒ _) = T\nlhs (T ∪ _) = T\nlhs (T ∩ _) = T\nlhs nil = nil\nlhs never = never\nlhs unknown = unknown\nlhs number = number\nlhs boolean = boolean\nlhs string = string\n\nrhs : Type → Type\nrhs (_ ⇒ T) = T\nrhs (_ ∪ T) = T\nrhs (_ ∩ T) = T\nrhs nil = nil\nrhs never = never\nrhs unknown = unknown\nrhs number = number\nrhs boolean = boolean\nrhs string = string\n\n_≡ᵀ_ : ∀ (T U : Type) → Dec(T ≡ U)\nnil ≡ᵀ nil = yes refl\nnil ≡ᵀ (S ⇒ T) = no (λ ())\nnil ≡ᵀ never = no (λ ())\nnil ≡ᵀ unknown = no (λ ())\nnil ≡ᵀ number = no (λ ())\nnil ≡ᵀ boolean = no (λ ())\nnil ≡ᵀ (S ∪ T) = no (λ ())\nnil ≡ᵀ (S ∩ T) = no (λ ())\nnil ≡ᵀ string = no (λ ())\n(S ⇒ T) ≡ᵀ string = no (λ ())\nnever ≡ᵀ string = no (λ ())\nunknown ≡ᵀ string = no (λ ())\nboolean ≡ᵀ string = no (λ ())\nnumber ≡ᵀ string = no (λ ())\n(S ∪ T) ≡ᵀ string = no (λ ())\n(S ∩ T) ≡ᵀ string = no (λ ())\n(S ⇒ T) ≡ᵀ nil = no (λ ())\n(S ⇒ T) ≡ᵀ (U ⇒ V) with (S ≡ᵀ U) | (T ≡ᵀ V) \n(S ⇒ T) ≡ᵀ (S ⇒ T) | yes refl | yes refl = yes refl\n(S ⇒ T) ≡ᵀ (U ⇒ V) | _ | no p = no (λ q → p (cong rhs q))\n(S ⇒ T) ≡ᵀ (U ⇒ V) | no p | _ = no (λ q → p (cong lhs q))\n(S ⇒ T) ≡ᵀ never = no (λ ())\n(S ⇒ T) ≡ᵀ unknown = no (λ ())\n(S ⇒ T) ≡ᵀ number = no (λ ())\n(S ⇒ T) ≡ᵀ boolean = no (λ ())\n(S ⇒ T) ≡ᵀ (U ∪ V) = no (λ ())\n(S ⇒ T) ≡ᵀ (U ∩ V) = no (λ ())\nnever ≡ᵀ nil = no (λ ())\nnever ≡ᵀ (U ⇒ V) = no (λ ())\nnever ≡ᵀ never = yes refl\nnever ≡ᵀ unknown = no (λ ())\nnever ≡ᵀ number = no (λ ())\nnever ≡ᵀ boolean = no (λ ())\nnever ≡ᵀ (U ∪ V) = no (λ ())\nnever ≡ᵀ (U ∩ V) = no (λ ())\nunknown ≡ᵀ nil = no (λ ())\nunknown ≡ᵀ (U ⇒ V) = no (λ ())\nunknown ≡ᵀ never = no (λ ())\nunknown ≡ᵀ unknown = yes refl\nunknown ≡ᵀ number = no (λ ())\nunknown ≡ᵀ boolean = no (λ ())\nunknown ≡ᵀ (U ∪ V) = no (λ ())\nunknown ≡ᵀ (U ∩ V) = no (λ ())\nnumber ≡ᵀ nil = no (λ ())\nnumber ≡ᵀ (T ⇒ U) = no (λ ())\nnumber ≡ᵀ never = no (λ ())\nnumber ≡ᵀ unknown = no (λ ())\nnumber ≡ᵀ number = yes refl\nnumber ≡ᵀ boolean = no (λ ())\nnumber ≡ᵀ (T ∪ U) = no (λ ())\nnumber ≡ᵀ (T ∩ U) = no (λ ())\nboolean ≡ᵀ nil = no (λ ())\nboolean ≡ᵀ (T ⇒ U) = no (λ ())\nboolean ≡ᵀ never = no (λ ())\nboolean ≡ᵀ unknown = no (λ ())\nboolean ≡ᵀ boolean = yes refl\nboolean ≡ᵀ number = no (λ ())\nboolean ≡ᵀ (T ∪ U) = no (λ ())\nboolean ≡ᵀ (T ∩ U) = no (λ ())\nstring ≡ᵀ nil = no (λ ())\nstring ≡ᵀ (x ⇒ x₁) = no (λ ())\nstring ≡ᵀ never = no (λ ())\nstring ≡ᵀ unknown = no (λ ())\nstring ≡ᵀ boolean = no (λ ())\nstring ≡ᵀ number = no (λ ())\nstring ≡ᵀ string = yes refl\nstring ≡ᵀ (U ∪ V) = no (λ ())\nstring ≡ᵀ (U ∩ V) = no (λ ())\n(S ∪ T) ≡ᵀ nil = no (λ ())\n(S ∪ T) ≡ᵀ (U ⇒ V) = no (λ ())\n(S ∪ T) ≡ᵀ never = no (λ ())\n(S ∪ T) ≡ᵀ unknown = no (λ ())\n(S ∪ T) ≡ᵀ number = no (λ ())\n(S ∪ T) ≡ᵀ boolean = no (λ ())\n(S ∪ T) ≡ᵀ (U ∪ V) with (S ≡ᵀ U) | (T ≡ᵀ V) \n(S ∪ T) ≡ᵀ (S ∪ T) | yes refl | yes refl = yes refl\n(S ∪ T) ≡ᵀ (U ∪ V) | _ | no p = no (λ q → p (cong rhs q))\n(S ∪ T) ≡ᵀ (U ∪ V) | no p | _ = no (λ q → p (cong lhs q))\n(S ∪ T) ≡ᵀ (U ∩ V) = no (λ ())\n(S ∩ T) ≡ᵀ nil = no (λ ())\n(S ∩ T) ≡ᵀ (U ⇒ V) = no (λ ())\n(S ∩ T) ≡ᵀ never = no (λ ())\n(S ∩ T) ≡ᵀ unknown = no (λ ())\n(S ∩ T) ≡ᵀ number = no (λ ())\n(S ∩ T) ≡ᵀ boolean = no (λ ())\n(S ∩ T) ≡ᵀ (U ∪ V) = no (λ ())\n(S ∩ T) ≡ᵀ (U ∩ V) with (S ≡ᵀ U) | (T ≡ᵀ V) \n(S ∩ T) ≡ᵀ (U ∩ V) | yes refl | yes refl = yes refl\n(S ∩ T) ≡ᵀ (U ∩ V) | _ | no p = no (λ q → p (cong rhs q))\n(S ∩ T) ≡ᵀ (U ∩ V) | no p | _ = no (λ q → p (cong lhs q))\n\n_≡ᴹᵀ_ : ∀ (T U : Maybe Type) → Dec(T ≡ U)\nnothing ≡ᴹᵀ nothing = yes refl\nnothing ≡ᴹᵀ just U = no (λ ())\njust T ≡ᴹᵀ nothing = no (λ ())\njust T ≡ᴹᵀ just U with T ≡ᵀ U\n(just T ≡ᴹᵀ just T) | yes refl = yes refl\n(just T ≡ᴹᵀ just U) | no p = no (λ q → p (just-inv q))\n\nsrc : Type → Type\nsrc nil = never\nsrc number = never\nsrc boolean = never\nsrc string = never\nsrc (S ⇒ T) = S\nsrc (S ∪ T) = (src S) ∩ (src T)\nsrc (S ∩ T) = (src S) ∪ (src T)\nsrc never = unknown\nsrc unknown = never\n\ntgt : Type → Type\ntgt nil = never\ntgt (S ⇒ T) = T\ntgt never = never\ntgt unknown = unknown\ntgt number = never\ntgt boolean = never\ntgt string = never\ntgt (S ∪ T) = (tgt S) ∪ (tgt T)\ntgt (S ∩ T) = (tgt S) ∩ (tgt T)\n\noptional : Type → Type\noptional nil = nil\noptional (T ∪ nil) = (T ∪ nil)\noptional T = (T ∪ nil)\n\nnormalizeOptional : Type → Type\nnormalizeOptional (S ∪ T) with normalizeOptional S | normalizeOptional T\nnormalizeOptional (S ∪ T) | (S′ ∪ nil) | (T′ ∪ nil) = (S′ ∪ T′) ∪ nil\nnormalizeOptional (S ∪ T) | S′ | (T′ ∪ nil) = (S′ ∪ T′) ∪ nil\nnormalizeOptional (S ∪ T) | (S′ ∪ nil) | T′ = (S′ ∪ T′) ∪ nil\nnormalizeOptional (S ∪ T) | S′ | nil = optional S′\nnormalizeOptional (S ∪ T) | nil | T′ = optional T′\nnormalizeOptional (S ∪ T) | S′ | T′ = S′ ∪ T′\nnormalizeOptional T = T\n", "meta": {"hexsha": "59d1107fcd84a5116bd6798e7e2af5cf7812d87c", "size": 5248, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "prototyping/Luau/Type.agda", "max_stars_repo_name": "MeltzDev/luau", "max_stars_repo_head_hexsha": "5bb9f379b07e378db0a170e7c4030e3a943b2f14", "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/Luau/Type.agda", "max_issues_repo_name": "MeltzDev/luau", "max_issues_repo_head_hexsha": "5bb9f379b07e378db0a170e7c4030e3a943b2f14", "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/Luau/Type.agda", "max_forks_repo_name": "MeltzDev/luau", "max_forks_repo_head_hexsha": "5bb9f379b07e378db0a170e7c4030e3a943b2f14", "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": 28.3675675676, "max_line_length": 72, "alphanum_fraction": 0.5179115854, "num_tokens": 2377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7606506418255928, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.3625106174626022}} {"text": "module CompleteSemantics.Iemhoff where\n\nopen import Syntax public\n\n\n-- Introspective brilliant Kripke models.\n\nrecord Model : Set₁ where\n infix 3 _⊩ᵅ_\n field\n World : Set\n _≤_ : World → World → Set\n refl≤ : ∀ {w} → w ≤ w\n trans≤ : ∀ {w w′ w″} → w ≤ w′ → w′ ≤ w″ → w ≤ w″\n _R_ : World → World → Set\n reflR : ∀ {w} → w R w\n transR : ∀ {w w′ w″} → w R w′ → w′ R w″ → w R w″\n _⊩ᵅ_ : World → Atom → Set\n mono⊩ᵅ : ∀ {w w′ P} → w ≤ w′ → w ⊩ᵅ P → w′ ⊩ᵅ P\n\n -- Introspection.\n field\n peek : World → Context\n\n _R⨾≤_ : World → World → Set\n _R⨾≤_ = _R_ ⨾ _≤_\n\n -- Brilliance.\n field\n R⨾≤→R : ∀ {w v′} → w R⨾≤ v′ → w R v′\n\n -- Vindication, as a consequence of brilliance.\n ≤→R : ∀ {w v′} → w ≤ v′ → w R v′\n ≤→R {w} ψ = R⨾≤→R (w , (reflR , ψ))\n\nopen Model {{…}} public\n\n\n-- Forcing in a particular world of a particular model.\n\nmodule _ {{_ : Model}} where\n mutual\n infix 3 _⊪_\n _⊪_ : World → Type → Set\n w ⊪ α P = w ⊩ᵅ P\n w ⊪ A ⇒ B = ∀ {w′} → w ≤ w′ → w′ ⊩ A → w′ ⊩ B\n w ⊪ □ A = ∀ {v′} → w R v′ → ∅ ⁏ π₂ (peek v′) ⊢ A ∧ v′ ⊩ A\n w ⊪ A ⩕ B = w ⊩ A ∧ w ⊩ B\n w ⊪ ⫪ = ⊤\n w ⊪ ⫫ = ⊥\n w ⊪ A ⩖ B = w ⊩ A ∨ w ⊩ B\n\n infix 3 _⊩_\n _⊩_ : World → Type → Set\n w ⊩ A = ∀ {C w′} → w ≤ w′ →\n (∀ {w″} → w′ ≤ w″ → w″ ⊪ A → peek w″ ⊢ⁿᶠ C) →\n peek w′ ⊢ⁿᶠ C\n\n infix 3 _⊩⋆_\n _⊩⋆_ : World → Stack Type → Set\n w ⊩⋆ ∅ = ⊤\n w ⊩⋆ Ξ , A = w ⊩⋆ Ξ ∧ w ⊩ A\n\n\n-- Monotonicity of forcing with respect to constructive accessibility.\n\nmodule _ {{_ : Model}} where\n mutual\n mono⊪ : ∀ {A w w′} → w ≤ w′ → w ⊪ A → w′ ⊪ A\n mono⊪ {α P} ψ s = mono⊩ᵅ ψ s\n mono⊪ {A ⇒ B} ψ f = λ ψ′ a → f (trans≤ ψ ψ′) a\n mono⊪ {□ A} ψ f = λ ρ → f (transR (≤→R ψ) ρ)\n mono⊪ {A ⩕ B} ψ (a , b) = mono⊩ {A} ψ a , mono⊩ {B} ψ b\n mono⊪ {⫪} ψ ∙ = ∙\n mono⊪ {⫫} ψ ()\n mono⊪ {A ⩖ B} ψ (ι₁ a) = ι₁ (mono⊩ {A} ψ a)\n mono⊪ {A ⩖ B} ψ (ι₂ b) = ι₂ (mono⊩ {B} ψ b)\n\n mono⊩ : ∀ {A w w′} → w ≤ w′ → w ⊩ A → w′ ⊩ A\n mono⊩ ψ a = λ ψ′ κ → a (trans≤ ψ ψ′) κ\n\n mono⊩⋆ : ∀ {Ξ w w′} → w ≤ w′ → w ⊩⋆ Ξ → w′ ⊩⋆ Ξ\n mono⊩⋆ {∅} ψ ∙ = ∙\n mono⊩⋆ {Ξ , A} ψ (ξ , s) = mono⊩⋆ {Ξ} ψ ξ , mono⊩ {A} ψ s\n\n\n-- Continuation-passing equipment.\n\nmodule _ {{_ : Model}} where\n return : ∀ {A w} → w ⊪ A → w ⊩ A\n return {A} a = λ ψ κ → κ refl≤ (mono⊪ {A} ψ a)\n\n bind : ∀ {A B w} → w ⊩ A →\n (∀ {w′} → w ≤ w′ → w′ ⊪ A → w′ ⊩ B) →\n w ⊩ B\n bind a κ = λ ψ κ′ → a ψ\n λ ψ′ a′ → κ (trans≤ ψ ψ′) a′ refl≤\n λ ψ″ a″ → κ′ (trans≤ ψ′ ψ″) a″\n\n\n-- Additional equipment.\n\nmodule _ {{_ : Model}} where\n lookup : ∀ {Ξ A w} → A ∈ Ξ → w ⊩⋆ Ξ → w ⊩ A\n lookup top (ξ , s) = s\n lookup (pop i) (ξ , s) = lookup i ξ\n\n\n-- Forcing in all worlds of all models, or semantic entailment.\n\ninfix 3 _⊨_\n_⊨_ : Context → Type → Set₁\nΓ ⁏ Δ ⊨ A = ∀ {{_ : Model}} {w} →\n w ⊩⋆ Γ →\n (∀ {v′} → w R v′ → ∅ ⁏ π₂ (peek v′) ⊢⋆ Δ) →\n (∀ {v′} → w R v′ → v′ ⊩⋆ Δ) →\n w ⊩ A\n\n\n-- Soundness of the semantics with respect to the syntax.\n\nreflect : ∀ {Γ Δ A} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊨ A\nreflect (var i) γ τ δ = lookup i γ\nreflect (mvar i) γ τ δ = lookup i (δ reflR)\nreflect (lam {A} {B} d) γ τ δ = return {A ⇒ B}\n λ ψ a → reflect d (mono⊩⋆ ψ γ , a)\n (λ ρ → τ (transR (≤→R ψ) ρ))\n (λ ρ → δ (transR (≤→R ψ) ρ))\nreflect (app {A} {B} d e) γ τ δ = bind {A ⇒ B} {B} (reflect d γ τ δ)\n λ ψ f → f refl≤ (mono⊩ {A} ψ (reflect e γ τ δ))\nreflect (box {A} d) γ τ δ = return {□ A}\n λ ρ → graft⊢ ∙ (τ ρ) d ,\n reflect d ∙\n (λ ρ′ → τ (transR ρ ρ′))\n (λ ρ′ → δ (transR ρ ρ′))\nreflect (unbox {A} {C} d e) γ τ δ = bind {□ A} {C} (reflect d γ τ δ)\n λ ψ s → reflect e (mono⊩⋆ ψ γ)\n (λ ρ → τ (transR (≤→R ψ) ρ) , π₁ (s ρ))\n (λ ρ → δ (transR (≤→R ψ) ρ) , π₂ (s ρ))\nreflect (pair {A} {B} d e) γ τ δ = return {A ⩕ B} (reflect d γ τ δ , reflect e γ τ δ)\nreflect (fst {A} {B} d) γ τ δ = bind {A ⩕ B} {A} (reflect d γ τ δ)\n λ { ψ (a , b) → a }\nreflect (snd {A} {B} d) γ τ δ = bind {A ⩕ B} {B} (reflect d γ τ δ)\n λ { ψ (a , b) → b }\nreflect unit γ τ δ = return {⫪} ∙\nreflect (boom {C} d) γ τ δ = bind {⫫} {C} (reflect d γ τ δ)\n λ ψ → elim⊥\nreflect (left {A} {B} d) γ τ δ = return {A ⩖ B} (ι₁ (reflect d γ τ δ))\nreflect (right {A} {B} d) γ τ δ = return {A ⩖ B} (ι₂ (reflect d γ τ δ))\nreflect (case {A} {B} {C} d e f) γ τ δ = bind {A ⩖ B} {C} (reflect d γ τ δ)\n λ { ψ (ι₁ a) → reflect e (mono⊩⋆ ψ γ , a)\n (λ ρ → τ (transR (≤→R ψ) ρ))\n (λ ρ → δ (transR (≤→R ψ) ρ))\n ; ψ (ι₂ b) → reflect f (mono⊩⋆ ψ γ , b)\n (λ ρ → τ (transR (≤→R ψ) ρ))\n (λ ρ → δ (transR (≤→R ψ) ρ))\n }\n\n\n-- The canonical model.\n\nprivate\n instance\n canon : Model\n canon = record\n { World = Context\n ; _≤_ = _⊆²_\n ; refl≤ = refl⊆²\n ; trans≤ = trans⊆²\n ; _R_ = λ { (_ ⁏ Δ) (_ ⁏ Δ′) → Δ ⊆ Δ′ }\n ; reflR = refl⊆\n ; transR = trans⊆\n ; _⊩ᵅ_ = λ { (Γ ⁏ Δ) P → Γ ⁏ Δ ⊢ⁿᵉ α P }\n ; mono⊩ᵅ = mono⊢ⁿᵉ\n ; peek = id\n ; R⨾≤→R = λ { (_ , (ρ , (_ , ρ′))) → trans⊆ ρ ρ′ }\n }\n\n\n-- Soundness and completeness of the canonical model with respect to the syntax.\n\nmutual\n reflectᶜ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ⁿᵉ A → Γ ⁏ Δ ⊩ A\n reflectᶜ {α P} d = return {α P} d\n reflectᶜ {A ⇒ B} d = return {A ⇒ B}\n λ ψ a → reflectᶜ (appⁿᵉ (mono⊢ⁿᵉ ψ d) (reifyᶜ a))\n reflectᶜ {□ A} d = λ ψ κ → neⁿᶠ (unboxⁿᵉ (mono⊢ⁿᵉ ψ d)\n (κ (refl⊆ , weak⊆)\n λ ρ′ → mono⊢ (bot , ρ′) mv₀ ,\n reflectᶜ (mono⊢ⁿᵉ (bot , ρ′) mv₀ⁿᵉ)))\n reflectᶜ {A ⩕ B} d = return {A ⩕ B} (reflectᶜ (fstⁿᵉ d) , reflectᶜ (sndⁿᵉ d))\n reflectᶜ {⫪} d = return {⫪} ∙\n reflectᶜ {⫫} d = λ ψ κ → neⁿᶠ (boomⁿᵉ (mono⊢ⁿᵉ ψ d))\n reflectᶜ {A ⩖ B} d = λ ψ κ → neⁿᶠ (caseⁿᵉ (mono⊢ⁿᵉ ψ d)\n (κ (weak⊆ , refl⊆) (ι₁ (reflectᶜ v₀ⁿᵉ)))\n (κ (weak⊆ , refl⊆) (ι₂ (reflectᶜ v₀ⁿᵉ))))\n\n reifyᶜ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊩ A → Γ ⁏ Δ ⊢ⁿᶠ A\n reifyᶜ {α P} κ = κ refl⊆²\n λ ψ s → neⁿᶠ s\n reifyᶜ {A ⇒ B} κ = κ refl⊆²\n λ ψ f → lamⁿᶠ (reifyᶜ (f (weak⊆ , refl⊆) (reflectᶜ v₀ⁿᵉ)))\n reifyᶜ {□ A} κ = κ refl⊆²\n λ ψ f → boxⁿᶠ (π₁ (f {∅ ⁏ _} refl⊆))\n reifyᶜ {A ⩕ B} κ = κ refl⊆²\n λ { ψ (a , b) → pairⁿᶠ (reifyᶜ a) (reifyᶜ b) }\n reifyᶜ {⫪} κ = κ refl⊆²\n λ { ψ ∙ → unitⁿᶠ }\n reifyᶜ {⫫} κ = κ refl⊆²\n λ ψ ()\n reifyᶜ {A ⩖ B} κ = κ refl⊆²\n λ { ψ (ι₁ a) → leftⁿᶠ (reifyᶜ a)\n ; ψ (ι₂ b) → rightⁿᶠ (reifyᶜ b)\n }\n\n\n-- Reflexivity of simultaneous forcing.\n\nrefl⊩⋆ : ∀ {Γ Δ} → Γ ⁏ Δ ⊩⋆ Γ\nrefl⊩⋆ {∅} = ∙\nrefl⊩⋆ {Γ , A} = mono⊩⋆ (weak⊆ , refl⊆) refl⊩⋆ , reflectᶜ v₀ⁿᵉ\n\nmrefl⊩⋆ : ∀ {Δ Γ} → Γ ⁏ Δ ⊩⋆ Δ\nmrefl⊩⋆ {∅} = ∙\nmrefl⊩⋆ {Δ , A} = mono⊩⋆ (refl⊆ , weak⊆) mrefl⊩⋆ , reflectᶜ mv₀ⁿᵉ\n\n\n-- Completeness of the semantics with respect to the syntax.\n\nreify : ∀ {Γ Δ A} → Γ ⁏ Δ ⊨ A → Γ ⁏ Δ ⊢ⁿᶠ A\nreify s = reifyᶜ (s refl⊩⋆ (λ ρ → mono⊢⋆ (refl⊆ , ρ) mrefl⊢⋆)\n (λ ρ → mono⊩⋆ (refl⊆ , ρ) mrefl⊩⋆))\n\n\n-- Normalisation by evaluation.\n\nnbe : ∀ {Γ Δ A} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ⁿᶠ A\nnbe = reify ∘ reflect\n", "meta": {"hexsha": "ff02449ca83473f32d3e3238e86a1456befc206e", "size": 8632, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/CompleteSemantics/Iemhoff.agda", "max_stars_repo_name": "mietek/imla2017", "max_stars_repo_head_hexsha": "accc6c57390c435728d568ae590a02b2776b8891", "max_stars_repo_licenses": ["X11"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2017-02-27T05:04:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T13:02:58.000Z", "max_issues_repo_path": "src/CompleteSemantics/Iemhoff.agda", "max_issues_repo_name": "mietek/imla2017", "max_issues_repo_head_hexsha": "accc6c57390c435728d568ae590a02b2776b8891", "max_issues_repo_licenses": ["X11"], "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/CompleteSemantics/Iemhoff.agda", "max_forks_repo_name": "mietek/imla2017", "max_forks_repo_head_hexsha": "accc6c57390c435728d568ae590a02b2776b8891", "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": 36.1171548117, "max_line_length": 101, "alphanum_fraction": 0.3620250232, "num_tokens": 3872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7248702761768249, "lm_q2_score": 0.5, "lm_q1q2_score": 0.36243513808841243}} {"text": "-- Andreas, 2012-10-30 Sections\n-- Reported by guillaume.brunerie, Oct 24 2012\nmodule Issue735 where\n\nimport Common.Level\nopen import Common.Prelude using (Nat; zero; suc)\n\n{- I often want to use something like sections in Coq. I usually use\nparametrized modules but this has at least two issues that Coq does\nnot have:\n\n1) I need to give a name to the module, and there is often no\n meaningful name to be given\n\n2) It exports the module, so I cannot define a module in another file\n with the same name\n\nI guess I can workaround 2) by declaring the module private, but this\nwill mean that everything will be indented further (again) and I\nreally want to avoid that.\n\nI think this can easily be fixed by adding a kind of anonymous\nmodules. An anonymous module would be declared by naming it `_`, and\nthe following code\n\n module _ params where\n declarations\n\nwould be translated to:\n\n private\n module Fresh params where\n declarations\n\n open Fresh public\n\nwhere Fresh is a new name. -}\n\n-- Andreas: this translation is not necessary, because Agda\n-- has a concept of sections internally (in Abstract syntax).\n\n-- However, the translation and the actual implementation should\n-- have the same semantics, except that a name 'Fresh' is never generated.\n\n-- An empty section with no parameters\n\nmodule _ where\n\n-- A section with a non-hidden parameter\n\nmodule _ {a} (A : Set a) where\n\n data List : Set a where\n [] : List\n _∷_ : (x : A) (xs : List) → List\n\n-- A section with all hidden parameters\n\nmodule _ {a} {A : Set a} where\n\n _++_ : List A → List A → List A\n [] ++ ys = ys\n (x ∷ xs) ++ ys = x ∷ (xs ++ ys)\n\n module _ (default : A) where\n\n head : List A → A\n head [] = default\n head (x ∷ _) = x\n\ntest : List Nat\ntest = head 1 [] ∷ ((2 ∷ []) ++ (3 ∷ []))\n", "meta": {"hexsha": "91b4680ba4a294310f12cdad167339f664efa34a", "size": 1801, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue735.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue735.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue735.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 24.6712328767, "max_line_length": 74, "alphanum_fraction": 0.686285397, "num_tokens": 488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.6113819732941511, "lm_q1q2_score": 0.3623456753854544}} {"text": "-- Andreas, 2012-09-17 documenting an internal error in InternalToAbstract.hs\n-- {-# OPTIONS -v syntax.reify.con:30 -v tc.with.type:30 #-}\nmodule NameFirstIfHidden where\n\nTotal : (D : (A : Set) → A → Set)(A : Set) → Set\nTotal D A = forall a → D A a\n\ndata D (A : Set) : (a : A) → Set where\n c : Total D A\n\npostulate P : {A : Set}{a : A} → D A a → Set\n\nf : (A : Set)(a : A) → P (c a) → D A a\nf A a p with Total\n... | _ = c a\n-- should succeed, triggered an internal error before\n", "meta": {"hexsha": "f3a83046d8ae1ca1423ffd42b4df60d676c3993b", "size": 478, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/NameFirstIfHidden.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/NameFirstIfHidden.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/NameFirstIfHidden.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 28.1176470588, "max_line_length": 77, "alphanum_fraction": 0.60041841, "num_tokens": 170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7025300449389326, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.36223848256429875}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import cohomology.Theory\nopen import homotopy.PushoutSplit\nopen import homotopy.DisjointlyPointedSet\nopen import cw.CW\n\nmodule cw.cohomology.WedgeOfCells {i} (OT : OrdinaryTheory i)\n {n} (⊙skel : ⊙Skeleton {i} (S n)) where\n\nopen OrdinaryTheory OT\nopen import cohomology.Sphere OT\n\nXₙ/Xₙ₋₁ : Ptd i\nXₙ/Xₙ₋₁ = ⊙Cofiber (⊙cw-incl-last ⊙skel)\n\nmodule _ (m : ℤ) where\n CXₙ/Xₙ₋₁ : Group i\n CXₙ/Xₙ₋₁ = C m Xₙ/Xₙ₋₁\n\n CEl-Xₙ/Xₙ₋₁ : Type i\n CEl-Xₙ/Xₙ₋₁ = Group.El CXₙ/Xₙ₋₁\n\n abstract\n CXₙ/Xₙ₋₁-is-abelian : is-abelian CXₙ/Xₙ₋₁\n CXₙ/Xₙ₋₁-is-abelian = C-is-abelian m Xₙ/Xₙ₋₁\n\n CXₙ/Xₙ₋₁-abgroup : AbGroup i\n CXₙ/Xₙ₋₁-abgroup = CXₙ/Xₙ₋₁ , CXₙ/Xₙ₋₁-is-abelian\n\n{- the equivalence is in the opposite direction because\n cohomology functors are contravariant. -}\nBigWedge-⊙equiv-Xₙ/Xₙ₋₁ : ⊙BigWedge {A = ⊙cells-last ⊙skel} (λ _ → ⊙Sphere (S n)) ⊙≃ Xₙ/Xₙ₋₁\nBigWedge-⊙equiv-Xₙ/Xₙ₋₁ = ≃-to-⊙≃\n (PS.split-equiv ∘e equiv to from to-from from-to) idp\n where\n open AttachedSkeleton (⊙Skeleton.skel ⊙skel)\n\n module PS = PushoutLSplit (uncurry attaching) (λ _ → tt) fst\n\n module SphereToCofiber (a : fst cells) = SuspRec {A = Sphere n}\n (cfbase' (fst :> (fst cells × Sphere n → fst cells)))\n (cfcod a) (λ s → cfglue (a , s))\n\n module To = BigWedgeRec {A = fst cells} {X = λ _ → ⊙Sphere (S n)}\n cfbase SphereToCofiber.f (λ _ → idp)\n to = To.f\n\n module From = CofiberRec {f = fst :> (fst cells × Sphere n → fst cells)}\n (bwbase {A = fst cells} {X = λ _ → ⊙Sphere (S n)})\n (λ a → bwin a south) (λ{(a , s) → bwglue a ∙ ap (bwin a) (merid s)})\n from = From.f\n\n abstract\n from-to : ∀ b → from (to b) == b\n from-to = BigWedge-elim\n idp\n (λ a → Susp-elim (bwglue a) idp\n (λ s → ↓-='-from-square $\n ( ap-∘ from (SphereToCofiber.f a) (merid s)\n ∙ ap (ap from) (SphereToCofiber.merid-β a s)\n ∙ From.glue-β (a , s))\n ∙v⊡ (tl-square (bwglue a) ⊡h vid-square)))\n (λ a → ↓-∘=idf-from-square from to $\n ap (ap from) (To.glue-β a) ∙v⊡ br-square (bwglue a))\n\n to-from : ∀ c → to (from c) == c\n to-from = Cofiber-elim\n idp (λ a → idp)\n (λ{(a , s) → ↓-∘=idf-in' to from $\n ap (ap to) (From.glue-β (a , s))\n ∙ ap-∙ to (bwglue a) (ap (bwin a) (merid s))\n ∙ ap2 _∙_ (To.glue-β a)\n ( ∘-ap to (bwin a) (merid s)\n ∙ SphereToCofiber.merid-β a s)})\n\nCXₙ/Xₙ₋₁-β : ∀ m → ⊙has-cells-with-choice 0 ⊙skel i\n → C m Xₙ/Xₙ₋₁ ≃ᴳ Πᴳ (⊙cells-last ⊙skel) (λ _ → C m (⊙Lift (⊙Sphere (S n))))\nCXₙ/Xₙ₋₁-β m ac = C-additive-iso m (λ _ → ⊙Lift (⊙Sphere (S n))) (⊙cells-last-has-choice ⊙skel ac)\n ∘eᴳ C-emap m ( BigWedge-⊙equiv-Xₙ/Xₙ₋₁\n ⊙∘e ⊙BigWedge-emap-r (λ _ → ⊙lower-equiv))\n\nCXₙ/Xₙ₋₁-β-diag : ⊙has-cells-with-choice 0 ⊙skel i\n → CXₙ/Xₙ₋₁ (ℕ-to-ℤ (S n)) ≃ᴳ Πᴳ (⊙cells-last ⊙skel) (λ _ → C2 0)\nCXₙ/Xₙ₋₁-β-diag ac = Πᴳ-emap-r (⊙cells-last ⊙skel) (λ _ → C-Sphere-diag (S n))\n ∘eᴳ CXₙ/Xₙ₋₁-β (ℕ-to-ℤ (S n)) ac\n\nabstract\n CXₙ/Xₙ₋₁-≠-is-trivial : ∀ {m} (m≠Sn : m ≠ ℕ-to-ℤ (S n))\n → ⊙has-cells-with-choice 0 ⊙skel i\n → is-trivialᴳ (CXₙ/Xₙ₋₁ m)\n CXₙ/Xₙ₋₁-≠-is-trivial {m} m≠Sn ac =\n iso-preserves'-trivial (CXₙ/Xₙ₋₁-β m ac) $\n Πᴳ-is-trivial (⊙cells-last ⊙skel)\n (λ _ → C m (⊙Lift (⊙Sphere (S n))))\n (λ _ → C-Sphere-≠-is-trivial m (S n) m≠Sn)\n\n CXₙ/Xₙ₋₁-<-is-trivial : ∀ {m} (m-is-trivial : ∀ {m} (m>Sn : S n < m)\n → ⊙has-cells-with-choice 0 ⊙skel i\n → is-trivialᴳ (CXₙ/Xₙ₋₁ (ℕ-to-ℤ m))\n CXₙ/Xₙ₋₁->-is-trivial m>Sn = CXₙ/Xₙ₋₁-≠-is-trivial (≠-inv (ℕ-to-ℤ-≠ (<-to-≠ m>Sn)))\n", "meta": {"hexsha": "334505a9146d8967f5e1a391e7315a8fa0d24a62", "size": 3886, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/cw/cohomology/WedgeOfCells.agda", "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/cw/cohomology/WedgeOfCells.agda", "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/cw/cohomology/WedgeOfCells.agda", "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "avg_line_length": 35.9814814815, "max_line_length": 98, "alphanum_fraction": 0.5540401441, "num_tokens": 1857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.36221434332600855}} {"text": "------------------------------------------------------------------------\n-- Some results related to strong bisimilarity for the delay monad\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nopen import Prelude\n\nmodule Bisimilarity.Delay-monad {a} {A : Type a} where\n\nopen import Delay-monad\nopen import Delay-monad.Bisimilarity as D using (force)\nopen import Equality.Propositional\nopen import Logical-equivalence using (_⇔_)\n\nopen import Function-universe equality-with-J hiding (id; _∘_)\n\nopen import Labelled-transition-system\nopen import Labelled-transition-system.Delay-monad A\n\nopen import Bisimilarity delay-monad\nimport Bisimilarity.Equational-reasoning-instances\nopen import Equational-reasoning\n\n------------------------------------------------------------------------\n-- The direct and the indirect definitions of strong bisimilarity are\n-- pointwise logically equivalent\n\n-- An emulation of the constructor D.later.\n\nlater-cong : ∀ {i x y} →\n [ i ] force x ∼′ force y → [ i ] later x ∼ later y\nlater-cong x∼′y =\n ⟨ (λ { later → _ , later , x∼′y })\n , (λ { later → _ , later , x∼′y })\n ⟩\n\n-- The direct definition of strong bisimilarity is contained in the\n-- one obtained from the transition relation.\n\ndirect→indirect : ∀ {i x y} →\n D.[ i ] x ∼ y → [ i ] x ∼ y\ndirect→indirect D.now = reflexive\ndirect→indirect (D.later p) = later-cong λ { .force →\n direct→indirect (force p) }\n\n-- The definition of strong bisimilarity obtained from the transition\n-- relation is contained in the direct one.\n\nindirect→direct : ∀ {i} x y → [ i ] x ∼ y → D.[ i ] x ∼ y\nindirect→direct (now x) (now y) nx∼ny\n with left-to-right nx∼ny now\n... | _ , now , _ = D.now\n\nindirect→direct (later x) (later y) lx∼ly\n with left-to-right lx∼ly later\n... | _ , later , x∼′y = D.later λ { .force →\n indirect→direct _ _ (force x∼′y) }\n\nindirect→direct (now x) (later y) nx∼ly\n with left-to-right nx∼ly now\n... | _ , () , _\n\nindirect→direct (later x) (now y) lx∼ny\n with left-to-right lx∼ny later\n... | _ , () , _\n\n-- The direct definition of strong bisimilarity is pointwise logically\n-- equivalent to the one obtained from the transition relation.\n--\n-- TODO: Are the two definitions isomorphic?\n\ndirect⇔indirect : ∀ {i x y} → D.[ i ] x ∼ y ⇔ [ i ] x ∼ y\ndirect⇔indirect = record\n { to = direct→indirect\n ; from = indirect→direct _ _\n }\n", "meta": {"hexsha": "3f2b17d38ea526355b8a194e120887bcfedf2988", "size": 2480, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Bisimilarity/Delay-monad.agda", "max_stars_repo_name": "nad/up-to", "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Bisimilarity/Delay-monad.agda", "max_issues_repo_name": "nad/up-to", "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Bisimilarity/Delay-monad.agda", "max_forks_repo_name": "nad/up-to", "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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": 31.7948717949, "max_line_length": 72, "alphanum_fraction": 0.5991935484, "num_tokens": 683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442250928250376, "lm_q2_score": 0.5621765008857982, "lm_q1q2_score": 0.36216820846720815}} {"text": "module Structure.Topology where\n\nopen import Logic\nimport Lvl\nopen import Sets.ExtensionalPredicateSet renaming (_≡_ to _≡ₛ_) hiding (map)\nopen import Structure.Setoid\nopen import Type\n\n-- Definition of topological spaces via open sets.\n-- The interpretation is that X is the collection of points and 𝓣 is the collection of open sets of X.\n-- (X,𝓣) is called a topological space.\n-- 𝓣 is called a topology on X.\nrecord TopologicalSpace {ℓ₁ ℓ₂ ℓ₃} {X : Type{ℓ₁}} ⦃ equiv : Equiv{ℓ₁ Lvl.⊔ ℓ₃}(X) ⦄ (𝓣 : PredSet{ℓ₂}(PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X))) : Type{Lvl.𝐒(Lvl.of(X)) Lvl.⊔ Lvl.of(Type.of(𝓣))} where\n field\n contains-empty : (∅ ∈ 𝓣)\n contains-universe : (𝐔 ∈ 𝓣)\n intersection-closure : ∀{A B} → (A ∈ 𝓣) → (B ∈ 𝓣) → ((A ∩ B) ∈ 𝓣)\n indexed-union-closure : ∀{I : Type{ℓ₁ Lvl.⊔ ℓ₃}}{Ai : I → PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)} → (∀{i} → (Ai(i) ∈ 𝓣)) → ((⋃ᵢ Ai) ∈ 𝓣)\n\n Open : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → Stmt\n Open(A) = (A ∈ 𝓣)\n\n Closed : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → Stmt\n Closed(A) = Open(∁ A)\n\n record Neighborhood (p : X) (N : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)) : Stmt{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂ Lvl.⊔ Lvl.𝐒(ℓ₃)} where\n constructor intro\n eta-equality\n field\n O : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)\n ⦃ open-set ⦄ : Open(O)\n ⦃ covers ⦄ : O ⊆ N\n ⦃ contains-point ⦄ : p ∈ O\n\n open import Data\n open import Data.Proofs\n open import Data.Either as Either using (_‖_)\n open import Data.Either.Setoid\n open import Data.Boolean\n open import Data.Tuple as Tuple using (_⨯_ ; _,_)\n open import Functional\n open import Lang.Instance\n open import Logic.Propositional\n open import Logic.Predicate\n open import Lvl.Proofs\n open import Structure.Function.Domain\n open import Structure.Function\n open import Structure.Relator.Proofs\n open import Structure.Relator.Properties\n open import Structure.Relator\n open import Syntax.Function\n open import Syntax.Transitivity\n\n module _ where\n open import Relator.Equals.Proofs.Equiv{T = Bool} renaming ([≡]-equiv to bool-equiv)\n\n union-closure : ∀{A B} → (A ∈ 𝓣) → (B ∈ 𝓣) → ((A ∪ B) ∈ 𝓣)\n union-closure {A}{B} pa pb = substitute₂(_∋_) (reflexivity(_≡_) {x = 𝓣}) (⋃ᵢ-of-bijection ([∃]-intro Lvl.Up.obj) 🝖 ⋃ᵢ-of-boolean) (indexed-union-closure f-proof) where\n f-proof : ∀{i} → ((if i then B else A) ∈ 𝓣)\n f-proof {𝐹} = pa\n f-proof {𝑇} = pb\n\n instance\n Neighborhood-unaryRelator : ∀{N} → UnaryRelator(p ↦ Neighborhood p N)\n UnaryRelator.substitution Neighborhood-unaryRelator xy (intro O ⦃ contains-point = p ⦄) = intro O ⦃ contains-point = substitute₁(_∈ O) xy p ⦄\n\n -- TODO: Is it usable when defined like this?\n record Base {I : Type{ℓ₁ Lvl.⊔ ℓ₃}} (Bi : I → PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)) : Stmt{Lvl.𝐒(ℓ₁ Lvl.⊔ ℓ₃)} where\n constructor intro\n field\n covers-space : (∀{x} → (x ∈ (⋃ᵢ Bi)))\n generator : (x : X) → (i₁ i₂ : I) → ⦃ _ : (x ∈ (Bi(i₁) ∩ Bi(i₂))) ⦄ → I\n generator-contains-point : ∀{x : X}{i₁ i₂ : I} ⦃ _ : x ∈ (Bi(i₁) ∩ Bi(i₂)) ⦄ → (x ∈ Bi(generator x i₁ i₂))\n generator-subset : ∀{x : X}{i₁ i₂ : I} ⦃ _ : x ∈ (Bi(i₁) ∩ Bi(i₂)) ⦄ → (Bi(generator x i₁ i₂) ⊆ (Bi(i₁) ∩ Bi(i₂)))\n\n record ClosurePoint (A : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)) (p : X) : Stmt{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂ Lvl.⊔ Lvl.𝐒(ℓ₃)} where\n constructor intro\n field proof : ∀{N} → ⦃ _ : Neighborhood(p)(N) ⦄ → NonEmpty(A ∩ N)\n\n instance\n ClosurePoint-unaryRelator : ∀{A} → UnaryRelator(ClosurePoint(A))\n ClosurePoint.proof (UnaryRelator.substitution ClosurePoint-unaryRelator xy Ax) {N} ⦃ neigh-y ⦄ = [∃]-map-proof id (ClosurePoint.proof Ax {N} ⦃ substitute₁ₗ(p ↦ Neighborhood p N) xy neigh-y ⦄)\n\n InternalPoint = swap Neighborhood\n\n record LimitPoint (A : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)) (p : X) : Stmt{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂ Lvl.⊔ Lvl.𝐒(ℓ₃)} where\n constructor intro\n field proof : ∀{N} → ⦃ _ : Neighborhood(p)(N) ⦄ → NonEmpty(A ∩ (N ∖ (• p)))\n\n -- TODO: Use how IsolatedPoint and LimitPoint are related to prove this\n instance\n postulate LimitPoint-unaryRelator : ∀{A} → UnaryRelator(LimitPoint(A))\n {-LimitPoint.proof (UnaryRelator.substitution (LimitPoint-unaryRelator {A = A}) xy (intro proof)) {N} ⦃ neigh ⦄ = substitute₁(_) xy (proof ⦃ substitute₁ₗ(_) xy neigh ⦄) where\n instance\n inst : UnaryRelator(x ↦ NonEmpty(A ∩ (N ∖ (• x))))\n inst = [∘]-unaryRelator {f = x ↦ A ∩ (N ∖ (• x))} ⦃ {!!} ⦄ {P = NonEmpty} ⦃ {!!} ⦄\n -}\n\n record IsolatedPoint (A : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)) (p : X) : Stmt{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂ Lvl.⊔ Lvl.𝐒(ℓ₃)} where\n constructor intro\n eta-equality\n field\n N : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)\n ⦃ neighborhood ⦄ : Neighborhood(p)(N)\n proof : ((A ∩ N) ≡ₛ (• p))\n\n instance\n IsolatedPoint-unaryRelator : ∀{A} → UnaryRelator(IsolatedPoint(A))\n UnaryRelator.substitution IsolatedPoint-unaryRelator xy (intro N p) = intro N ⦃ substitute₁(a ↦ Neighborhood a N) xy infer ⦄ (p 🝖 (congruence₁ (•_) ⦃ singleton-function ⦃ equiv ⦄ ⦄ xy))\n\n Closure : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → PredSet(X)\n Closure(A) = intro(ClosurePoint(A))\n\n Interior : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → PredSet(X)\n Interior(A) = intro(InternalPoint(A))\n\n ∂ : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → PredSet(X)\n ∂ A = Closure(A) ∖ Interior(A)\n\n Discrete : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → Stmt\n Discrete(A) = A ⊆ intro(IsolatedPoint(A))\n\n Dense : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → Stmt\n Dense(A) = Closure(A) ⊆ A\n\n Perfect : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → Stmt\n Perfect(A) = ∀{p} → (¬ IsolatedPoint(A)(p))\n\n open import Numeral.Natural\n open import Numeral.Natural.Relation.Order using (_>_)\n\n record _converges-to_ (f : ℕ → X) (L : X) : Stmt{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂ Lvl.⊔ Lvl.𝐒(ℓ₃)} where\n constructor intro\n field\n min : ∃(Neighborhood(L)) → ℕ\n proof : ∀{NN@([∃]-intro N) : ∃(Neighborhood(L))}{n : ℕ} → (n > min(NN)) → (f(n) ∈ N)\n lim : (f : ℕ → X) → ⦃ _ : ∃(f converges-to_) ⦄ → X\n lim f ⦃ [∃]-intro L ⦄ = L\n\nmodule _\n {ℓₗ₁ ℓₗ₂ ℓₗ₃} {X : Type{ℓₗ₁}} ⦃ equivₗ : Equiv{ℓₗ₁ Lvl.⊔ ℓₗ₃}(X) ⦄ (𝓣ₗ : PredSet{ℓₗ₂}(PredSet{ℓₗ₁ Lvl.⊔ ℓₗ₃}(X)))\n ⦃ _ : TopologicalSpace{ℓₗ₁}{ℓₗ₂}{ℓₗ₃} (𝓣ₗ) ⦄\n {ℓᵣ₁ ℓᵣ₂ ℓᵣ₃} {Y : Type{ℓᵣ₁}} ⦃ equivᵣ : Equiv{ℓᵣ₁ Lvl.⊔ ℓᵣ₃}(Y) ⦄ (𝓣ᵣ : PredSet{ℓᵣ₂}(PredSet{ℓᵣ₁ Lvl.⊔ ℓᵣ₃}(Y)))\n ⦃ _ : TopologicalSpace{ℓᵣ₁}{ℓᵣ₂}{ℓᵣ₃} (𝓣ᵣ) ⦄\n where\n open TopologicalSpace ⦃ … ⦄\n\n open import Logic.Predicate\n open import Structure.Function\n\n record ContinuousAt (f : X → Y) ⦃ _ : Function(f) ⦄ (x : X) : Stmt{Lvl.𝐒(ℓₗ₁ Lvl.⊔ ℓₗ₃ Lvl.⊔ ℓᵣ₁ Lvl.⊔ ℓᵣ₃) Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓᵣ₂} where\n constructor intro\n field\n map : ∃(Neighborhood(f(x))) → ∃(Neighborhood(x))\n proof : ∀{NB@([∃]-intro B) : ∃(Neighborhood(f(x)))}\n → let ([∃]-intro A) = map(NB)\n in (A ⊆ unmap f(B))\n\n Continuous : (f : X → Y) ⦃ _ : Function(f) ⦄ → Stmt{Lvl.𝐒(ℓₗ₁ Lvl.⊔ ℓₗ₃ Lvl.⊔ ℓᵣ₁ Lvl.⊔ ℓᵣ₃) Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓᵣ₂}\n Continuous(f) = ∀{x} → ContinuousAt f(x)\n\nmodule _\n {ℓₗ₁ ℓₗ₂ ℓₗ₃} {X : Type{ℓₗ₁}} ⦃ equivₗ : Equiv{ℓₗ₁ Lvl.⊔ ℓₗ₃}(X) ⦄ (𝓣ₗ : PredSet{ℓₗ₂}(PredSet{ℓₗ₁ Lvl.⊔ ℓₗ₃}(X)))\n ⦃ _ : TopologicalSpace{ℓₗ₁}{ℓₗ₂}{ℓₗ₃} (𝓣ₗ) ⦄\n {ℓᵣ₁ ℓᵣ₂ ℓᵣ₃} {Y : Type{ℓᵣ₁}} ⦃ equivᵣ : Equiv{ℓᵣ₁ Lvl.⊔ ℓᵣ₃}(Y) ⦄ (𝓣ᵣ : PredSet{ℓᵣ₂}(PredSet{ℓᵣ₁ Lvl.⊔ ℓᵣ₃}(Y)))\n ⦃ _ : TopologicalSpace{ℓᵣ₁}{ℓᵣ₂}{ℓᵣ₃} (𝓣ᵣ) ⦄\n where\n open TopologicalSpace ⦃ … ⦄\n\n open import Function.Inverse\n open import Structure.Function.Domain hiding (bijective)\n open import Structure.Function\n\n record Homeomorphism (f : X → Y) ⦃ func : Function(f) ⦄ : Stmt{Lvl.𝐒(ℓₗ₁ Lvl.⊔ ℓₗ₃ Lvl.⊔ ℓᵣ₁ Lvl.⊔ ℓᵣ₃) Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓᵣ₂} where\n constructor intro\n field\n ⦃ invertible ⦄ : Invertible(f)\n ⦃ continuous ⦄ : Continuous(𝓣ₗ)(𝓣ᵣ) (f)\n ⦃ continuous-inverse ⦄ : Continuous(𝓣ᵣ)(𝓣ₗ) (inv f) ⦃ inv-function ⦄\n", "meta": {"hexsha": "f9ab9224cde7a0c914e651fbf72454c0fc52a964", "size": 7616, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Structure/Topology.agda", "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_issues_repo_path": "Structure/Topology.agda", "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": "Structure/Topology.agda", "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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.3111111111, "max_line_length": 195, "alphanum_fraction": 0.6070115546, "num_tokens": 3605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.3621041485240509}} {"text": "\npostulate Name : Set\n{-# BUILTIN QNAME Name #-}\n\ndata ⊤ : Set where\n tt : ⊤\n\ndata Term : Set where\n con : Name → Term → Term\n\ndata X : ⊤ → Set where\n x : {t : ⊤} → X t\n\ndata Y : Set where\n y : Y\n\n\n-- this type checks\ng : {t : ⊤} → Term → X t\ng {t} (con nm args) = x {t}\n\n-- this doesn't\nf : {t : ⊤} → Term → X t\nf {t} (con (quote Y.y) args) = x {t}\n-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n-- offending line is above\nf t = x\n\n-- t != args of type ⊤\n-- when checking that the expression x {t} has type X args\n", "meta": {"hexsha": "6756204bcafdad40c93f9a94937c8d0f2332318e", "size": 509, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1610.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/Succeed/Issue1610.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/Succeed/Issue1610.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": 16.4193548387, "max_line_length": 58, "alphanum_fraction": 0.5049115914, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6187804196836383, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.36204913775525654}} {"text": "{-# OPTIONS --rewriting --without-K #-}\n\nopen import Agda.Primitive\nopen import Prelude\nopen import GSeTT.Syntax\nopen import GSeTT.Rules\n\n{- Categorical structure of the type theory for globular sets -}\nmodule GSeTT.CwF-structure where\n\n {- cut-admissibility : action of substitutions preserves derivability -}\n []T : ∀ {Γ A Δ γ} → Γ ⊢T A → Δ ⊢S γ > Γ → Δ ⊢T (A [ γ ]Pre-Ty)\n []t : ∀ {Γ A t Δ γ} → Γ ⊢t t # A → Δ ⊢S γ > Γ → Δ ⊢t (t [ γ ]Pre-Tm) # (A [ γ ]Pre-Ty)\n\n []T (ob Γ⊢) Δ⊢γ:Γ = ob (Δ⊢γ:Γ→Δ⊢ Δ⊢γ:Γ)\n []T (ar Γ⊢t:A Γ⊢u:A) Δ⊢γ:Γ = ar ([]t Γ⊢t:A Δ⊢γ:Γ) ([]t Γ⊢u:A Δ⊢γ:Γ)\n []t {Γ = (Γ :: _)} {t = Var x} (var Γ+⊢@(cc Γ⊢ _ idp) (inl x∈Γ)) Δ⊢γ+:Γ+@(sc Δ⊢γ:Γ _ _ idp) with (eqdecℕ x (length Γ))\n ... | inl idp = ⊥-elim (lΓ∉Γ Γ⊢ x∈Γ)\n ... | inr _ = trT (wk[]T (Γ⊢t:A→Γ⊢A (var Γ⊢ x∈Γ)) Δ⊢γ+:Γ+ ^) ([]t (var Γ⊢ x∈Γ) Δ⊢γ:Γ)\n []t {Γ = (Γ :: _)} {t = Var x} (var Γ+⊢@(cc Γ⊢ Γ⊢A idp) (inr (idp , idp))) Δ⊢γ+:Γ+@(sc Δ⊢γ:Γ x₁ Δ⊢t:A[γ] idp) with (eqdecℕ x (length Γ))\n ... | inl _ = trT (wk[]T Γ⊢A Δ⊢γ+:Γ+ ^) Δ⊢t:A[γ]\n ... | inr x≠x = ⊥-elim (x≠x idp)\n\n\n {- action of identity on types and terms is trivial (true on syntax) -}\n [id]T : ∀ Γ A → (A [ Pre-id Γ ]Pre-Ty) == A\n [id]t : ∀ Γ t → (t [ Pre-id Γ ]Pre-Tm) == t\n\n [id]T Γ ∗ = idp\n [id]T Γ (⇒ A t u) = ⇒= ([id]T Γ A) ([id]t Γ t) ([id]t Γ u)\n [id]t nil (Var x) = idp\n [id]t (Γ :: (y , B)) (Var x) with (eqdecℕ x y)\n ... | inl x=y = Var= (x=y ^)\n ... | inr _ = [id]t Γ (Var x)\n\n\n {- identity is well-formed -}\n Γ⊢id:Γ : ∀ {Γ} → Γ ⊢C → Γ ⊢S Pre-id Γ > Γ\n Γ⊢id:Γ ec = es ec\n Γ⊢id:Γ Γ,x:A⊢@(cc Γ⊢ Γ⊢A idp) = sc (wkS (Γ⊢id:Γ Γ⊢) Γ,x:A⊢) Γ,x:A⊢ (var Γ,x:A⊢ (inr (idp , [id]T _ _))) idp\n\n\n {- action of substitutions on types and terms respects composition -}\n [∘]T : ∀ {Γ Δ Θ A γ δ} → Γ ⊢T A → Δ ⊢S γ > Γ → Θ ⊢S δ > Δ → ((A [ γ ]Pre-Ty) [ δ ]Pre-Ty) == (A [ γ ∘ δ ]Pre-Ty)\n [∘]t : ∀ {Γ Δ Θ A t γ δ} → Γ ⊢t t # A → Δ ⊢S γ > Γ → Θ ⊢S δ > Δ → ((t [ γ ]Pre-Tm) [ δ ]Pre-Tm) == (t [ γ ∘ δ ]Pre-Tm)\n\n [∘]T (ob _) _ _ = idp\n [∘]T (ar Γ⊢t:A Γ⊢u:A) Δ⊢γ:Γ Θ⊢δ:Δ = ⇒= ([∘]T (Γ⊢t:A→Γ⊢A Γ⊢t:A) Δ⊢γ:Γ Θ⊢δ:Δ) ([∘]t Γ⊢t:A Δ⊢γ:Γ Θ⊢δ:Δ) ([∘]t Γ⊢u:A Δ⊢γ:Γ Θ⊢δ:Δ)\n [∘]t (var {x = x} Γ⊢ x∈Γ) (sc {x = y} Δ⊢γ:Γ _ Δ⊢t:A[γ] idp) Θ⊢δ:Δ with (eqdecℕ x y )\n ... | inl idp = idp\n [∘]t (var Γ,y:A⊢ (inr (idp , idp))) (sc Δ⊢γ:Γ _ Δ⊢t:A[γ] idp) Θ⊢δ:Δ | inr x≠x = ⊥-elim (x≠x idp)\n [∘]t (var (cc Γ⊢ _ _) (inl x∈Γ)) (sc Δ⊢γ:Γ _ Δ⊢t:A[γ] idp) Θ⊢δ:Δ | inr _ = [∘]t (var Γ⊢ x∈Γ) Δ⊢γ:Γ Θ⊢δ:Δ\n\n\n {- composition of well-formed substitutions is well-formed -}\n ∘-admissibility : ∀ {Γ Δ Θ γ δ} → Δ ⊢S γ > Γ → Θ ⊢S δ > Δ → Θ ⊢S (γ ∘ δ) > Γ\n ∘-admissibility (es Δ⊢) Θ⊢δ:Δ = es (Δ⊢γ:Γ→Δ⊢ Θ⊢δ:Δ)\n ∘-admissibility (sc Δ⊢γ:Γ Γ,x:A⊢@(cc _ Γ⊢A _) Δ⊢t:A[γ] idp) Θ⊢δ:Δ = sc (∘-admissibility Δ⊢γ:Γ Θ⊢δ:Δ) Γ,x:A⊢ (trT ([∘]T Γ⊢A Δ⊢γ:Γ Θ⊢δ:Δ) ([]t Δ⊢t:A[γ] Θ⊢δ:Δ)) idp\n\n {- composition is associative, this is true only for well-formed substitutions -}\n ∘-associativity : ∀ {Γ Δ Θ Ξ γ δ θ} → Δ ⊢S γ > Γ → Θ ⊢S δ > Δ → Ξ ⊢S θ > Θ → ((γ ∘ δ) ∘ θ) == (γ ∘ (δ ∘ θ))\n ∘-associativity (es _) _ _ = idp\n ∘-associativity (sc Δ⊢γ:Γ _ Δ⊢t:A[γ] idp) Θ⊢δ:Δ Ξ⊢θ:Θ = ::= (∘-associativity Δ⊢γ:Γ Θ⊢δ:Δ Ξ⊢θ:Θ) (×= idp ([∘]t Δ⊢t:A[γ] Θ⊢δ:Δ Ξ⊢θ:Θ))\n\n\n {- Left unitality of composition -}\n\n -- To prove right-unitality, we need a analoguous of wk[]T and wk[]t for substitutions\n -- Composing if θ is a subst without x, acting (γ :: (x , u)) on it is same as acting just γ on it\n wk[]S : ∀ {Γ Δ γ x u B Θ θ} → Γ ⊢S θ > Θ → Δ ⊢S (γ :: (x , u)) > (Γ :: (x , B)) → (θ ∘ (γ :: (x , u))) == (θ ∘ γ)\n wk[]S (es _) _ = idp\n wk[]S (sc Γ⊢θ:Θ _ Γ⊢t:A[θ] idp) Δ⊢γ+:Γ+ = ::= (wk[]S Γ⊢θ:Θ Δ⊢γ+:Γ+) (×= idp (wk[]t Γ⊢t:A[θ] Δ⊢γ+:Γ+))\n\n ∘-left-unit : ∀{Γ Δ γ} → Δ ⊢S γ > Γ → (Pre-id Γ ∘ γ) == γ\n ∘-left-unit (es _) = idp\n ∘-left-unit Δ⊢γ+:Γ+@(sc {x = x} Δ⊢γ:Γ (cc Γ⊢ _ _) _ idp) with (eqdecℕ x x)\n ... | inl _ = ::= (wk[]S (Γ⊢id:Γ Γ⊢) Δ⊢γ+:Γ+ >> ∘-left-unit Δ⊢γ:Γ) idp\n ... | inr x≠x = ⊥-elim (x≠x idp)\n\n {- Right unitality of composition (true on syntax)-}\n ∘-right-unit : ∀ {Δ γ} → (γ ∘ Pre-id Δ) == γ\n ∘-right-unit {Δ} {nil} = idp\n ∘-right-unit {Δ} {γ :: (y , t)} = ::= ∘-right-unit (×= idp ([id]t Δ t))\n\n {- Structure of CwF -}\n Γ,x:A⊢π:Γ : ∀ {Γ x A} → (Γ :: (x , A)) ⊢C → (Γ :: (x , A)) ⊢S Pre-π Γ x A > Γ\n Γ,x:A⊢π:Γ Γ,x:A⊢@(cc Γ⊢ _ _) = wkS (Γ⊢id:Γ Γ⊢) Γ,x:A⊢\n\n -- TODO : complete the CwF structure\n", "meta": {"hexsha": "5f80068ef46f78fed932162a2d45e81608ced06f", "size": 4799, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "GSeTT/CwF-structure.agda", "max_stars_repo_name": "thibautbenjamin/catt-formalization", "max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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": "GSeTT/CwF-structure.agda", "max_issues_repo_name": "thibautbenjamin/catt-formalization", "max_issues_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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": "GSeTT/CwF-structure.agda", "max_forks_repo_name": "thibautbenjamin/catt-formalization", "max_forks_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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": 53.3222222222, "max_line_length": 171, "alphanum_fraction": 0.4323817462, "num_tokens": 2631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081926, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.36171248182902893}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import lib.Basics\nopen import lib.NType2\nopen import lib.types.Pi\nopen import lib.types.Group\n\n{-\n The definition of G-sets. Thanks to Daniel Grayson.\n-}\n\nmodule lib.types.GroupSet {i} where\n\n -- The right group action with respect to the group [grp].\n record GsetStructure (grp : Group i) {j} (El : Type j)\n (_ : is-set El) : Type (lmax i j) where\n constructor gset-structure\n private\n module G = Group grp\n module GS = GroupStructure G.group-struct\n field\n act : El → G.El → El\n unit-r : ∀ x → act x GS.ident == x\n assoc : ∀ x g₁ g₂ → act (act x g₁) g₂ == act x (GS.comp g₁ g₂)\n\n -- The definition of a G-set. A set [El] equipped with\n -- a right group action with respect to [grp].\n record Gset (grp : Group i) j : Type (lsucc (lmax i j)) where\n constructor gset\n field\n El : Type j\n El-level : is-set El\n gset-struct : GsetStructure grp El El-level\n open GsetStructure gset-struct public\n El-is-set = El-level\n\n -- A helper function to establish equivalence between two G-sets.\n -- Many data are just props and this function do the coversion for them\n -- for you. You only need to show the non-trivial parts.\n module _ {grp : Group i} {j} {El : Type j} {El-level : is-set El} where\n private\n module G = Group grp\n module GS = GroupStructure G.group-struct\n open GsetStructure\n private\n gset-structure=' : ∀ {gss₁ gss₂ : GsetStructure grp El El-level}\n → (act= : act gss₁ == act gss₂)\n → unit-r gss₁ == unit-r gss₂\n [ (λ act → ∀ x → act x GS.ident == x) ↓ act= ]\n → assoc gss₁ == assoc gss₂\n [ (λ act → ∀ x g₁ g₂ →\n act (act x g₁) g₂ == act x (GS.comp g₁ g₂)) ↓ act= ]\n → gss₁ == gss₂\n gset-structure=' {gset-structure _ _ _} {gset-structure ._ ._ ._}\n idp idp idp = idp\n \n gset-structure= : ∀ {gss₁ gss₂ : GsetStructure grp El El-level}\n → (∀ x g → act gss₁ x g == act gss₂ x g)\n → gss₁ == gss₂\n gset-structure= act= = gset-structure='\n (λ= λ x → λ= λ g → act= x g)\n (prop-has-all-paths-↓ (Π-level λ _ → El-level _ _))\n (prop-has-all-paths-↓\n (Π-level λ _ → Π-level λ _ → Π-level λ _ → El-level _ _))\n\n module _ {grp : Group i} {j : ULevel} where\n private\n module G = Group grp\n module GS = GroupStructure G.group-struct\n open Gset {grp} {j}\n private\n gset='' : ∀ {gs₁ gs₂ : Gset grp j}\n → (El= : El gs₁ == El gs₂)\n → (El-level : El-level gs₁ == El-level gs₂ [ is-set ↓ El= ])\n → gset-struct gs₁ == gset-struct gs₂\n [ uncurry (GsetStructure grp) ↓ pair= El= El-level ]\n → gs₁ == gs₂\n gset='' {gset _ _ _} {gset ._ ._ ._} idp idp idp = idp\n\n gset=' : ∀ {gs₁ gs₂ : Gset grp j}\n → (El= : El gs₁ == El gs₂)\n → (El-level : El-level gs₁ == El-level gs₂ [ is-set ↓ El= ])\n → (∀ {x₁} {x₂} (p : x₁ == x₂ [ idf _ ↓ El= ]) g\n → act gs₁ x₁ g == act gs₂ x₂ g [ idf _ ↓ El= ])\n → gs₁ == gs₂\n gset=' {gset _ _ _} {gset ._ ._ _} idp idp act= =\n gset='' idp idp (gset-structure= λ x g → act= idp g)\n\n gset= : ∀ {gs₁ gs₂ : Gset grp j}\n → (El≃ : El gs₁ ≃ El gs₂)\n → (∀ {x₁} {x₂}\n → –> El≃ x₁ == x₂\n → ∀ g → –> El≃ (act gs₁ x₁ g) == act gs₂ x₂ g)\n → gs₁ == gs₂\n gset= El≃ act= =\n gset='\n (ua El≃)\n (prop-has-all-paths-↓ is-set-is-prop)\n (λ x= g → ↓-idf-ua-in El≃ $ act= (↓-idf-ua-out El≃ x=) g)\n\n -- The Gset homomorphism.\n record GsetHom {grp : Group i} {j}\n (gset₁ gset₂ : Gset grp j) : Type (lmax i j) where\n constructor gset-hom\n open Gset\n field\n f : El gset₁ → El gset₂\n pres-act : ∀ g x → f (act gset₁ x g) == act gset₂ (f x) g\n\n private\n gset-hom=' : ∀ {grp : Group i} {j} {gset₁ gset₂ : Gset grp j}\n {gsh₁ gsh₂ : GsetHom gset₁ gset₂}\n → (f= : GsetHom.f gsh₁ == GsetHom.f gsh₂)\n → (GsetHom.pres-act gsh₁ == GsetHom.pres-act gsh₂\n [ (λ f → ∀ g x → f (Gset.act gset₁ x g) == Gset.act gset₂ (f x) g) ↓ f= ] )\n → gsh₁ == gsh₂\n gset-hom=' idp idp = idp\n\n gset-hom= : ∀ {grp : Group i} {j} {gset₁ gset₂ : Gset grp j}\n {gsh₁ gsh₂ : GsetHom gset₁ gset₂}\n → (∀ x → GsetHom.f gsh₁ x == GsetHom.f gsh₂ x)\n → gsh₁ == gsh₂\n gset-hom= {gset₂ = gset₂} f= =\n gset-hom='\n (λ= f=)\n (prop-has-all-paths-↓ $\n Π-level λ _ → Π-level λ _ → Gset.El-level gset₂ _ _)\n", "meta": {"hexsha": "d85019e6eb1ea6f14b72d0ee41112cb59f9e3131", "size": 4458, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "lib/types/GroupSet.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": "lib/types/GroupSet.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": "lib/types/GroupSet.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": 34.828125, "max_line_length": 83, "alphanum_fraction": 0.5423956931, "num_tokens": 1637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081926, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.36171248182902893}} {"text": "{-# OPTIONS --without-K --safe #-}\nmodule PiFracMemSem where\n\nopen import Relation.Binary.Core\nopen import Data.Empty\nopen import Function\nopen import Data.Nat\nopen import Data.Nat.Properties\nopen import Data.Fin as Fin using (Fin; zero; suc)\nopen import Data.Vec\nopen import Data.Vec.Relation.Unary.Any.Properties\nopen import Data.Vec.Any hiding (map)\nopen import Data.Empty using (⊥)\nopen import Data.Unit using (⊤; tt)\nopen import Data.Sum using (_⊎_; inj₁; inj₂)\nopen import Data.Product using (_×_; _,_; proj₁; proj₂; Σ-syntax)\nopen import Relation.Nullary\nopen import Relation.Binary.PropositionalEquality\n renaming ([_] to R[_])\nopen import PiFracDyn\n\ninfix 80 ∣_∣\n\n∣_∣ : (A : 𝕌) → ℕ\n∣ 𝟘 ∣ = 0\n∣ 𝟙 ∣ = 1\n∣ A₁ +ᵤ A₂ ∣ = ∣ A₁ ∣ + ∣ A₂ ∣\n∣ A₁ ×ᵤ A₂ ∣ = ∣ A₁ ∣ * ∣ A₂ ∣\n∣ 𝟙/ A ∣ = 1\n\nVec× : ∀ {n m} {A B : Set} → Vec A n → Vec B m → Vec (A × B) (n * m)\nVec× va vb = concat (map (λ a₁ → map (a₁ ,_) vb) va)\n\n∈map : ∀ {ℓ₁ ℓ₂} {n} {A : Set ℓ₁} {B : Set ℓ₂} {v : Vec A n} → (f : A → B) → (a : A)\n → Any (a ≡_) v → Any (f a ≡_) (map f v)\n∈map f a (here refl) = here refl\n∈map f a (there a∈v) = there (∈map f a a∈v)\n\ninVec× : ∀ {n m} {A B : Set} → (va : Vec A n) → (vb : Vec B m)\n → (a : A) (b : B)\n → Any (a ≡_) va → Any (b ≡_) vb\n → Any ((a , b) ≡_) (Vec× va vb)\ninVec× (a ∷ va) vb .a b (here refl) b∈vb = ++⁺ˡ {xs = map (a ,_) vb} (∈map _ _ b∈vb)\ninVec× (x ∷ va) vb a b (there a∈va) b∈vb = ++⁺ʳ (map (x ,_) vb) (inVec× va vb a b a∈va b∈vb)\n\nany≡← : ∀ {ℓ} {A : Set ℓ} {n} {a} → (v : Vec A n) → (i : Fin n) → a ≡ lookup v i → Any (a ≡_) v\nany≡← (_ ∷ _) Fin.0F refl = here refl\nany≡← (_ ∷ v) (suc i) refl = there (any≡← v i refl)\n\nEnum : (A : 𝕌) → Vec ⟦ A ⟧ ∣ A ∣\nEnum 𝟘 = []\nEnum 𝟙 = tt ∷ []\nEnum (A₁ +ᵤ A₂) = map inj₁ (Enum A₁) ++ map inj₂ (Enum A₂)\nEnum (A₁ ×ᵤ A₂) = Vec× (Enum A₁) (Enum A₂)\nEnum (𝟙/ A) = ○ ∷ []\n\nFind : {A : 𝕌} (x : ⟦ A ⟧) → Σ[ i ∈ Fin ∣ A ∣ ] (x ≡ lookup (Enum A) i)\nFind {𝟘} ()\nFind {𝟙} tt = index tt∈𝟙 , lookup-index tt∈𝟙\n where\n tt∈𝟙 : Any (tt ≡_) (Enum 𝟙)\n tt∈𝟙 = here refl\nFind {A₁ +ᵤ A₂} (inj₁ x) =\n let i , p₁ = Find x in\n let x∈A₁ : Any ((inj₁ x) ≡_) (Enum (A₁ +ᵤ A₂))\n x∈A₁ = ++⁺ˡ {xs = map inj₁ (Enum A₁)} (∈map inj₁ x (any≡← _ i p₁)) in\n index x∈A₁ , lookup-index x∈A₁\nFind {A₁ +ᵤ A₂} (inj₂ y) =\n let j , p₂ = Find y in\n let y∈A₂ : Any ((inj₂ y) ≡_) (Enum (A₁ +ᵤ A₂))\n y∈A₂ = ++⁺ʳ (map inj₁ (Enum A₁)) (∈map inj₂ y (any≡← _ j p₂)) in\n index y∈A₂ , lookup-index y∈A₂\nFind {A₁ ×ᵤ A₂} (x , y) =\n let i , p₁ = Find x\n j , p₂ = Find y in\n let xy∈A₁×A₂ : Any ((x , y) ≡_) (Enum (A₁ ×ᵤ A₂))\n xy∈A₁×A₂ = inVec× (Enum A₁) (Enum A₂) x y (any≡← (Enum A₁) i p₁) (any≡← (Enum A₂) j p₂) in\n index xy∈A₁×A₂ , lookup-index xy∈A₁×A₂\nFind {𝟙/ A} ○ = index ○∈𝟙/A , lookup-index ○∈𝟙/A\n where\n ○∈𝟙/A : Any (○ ≡_) (Enum (𝟙/ A))\n ○∈𝟙/A = here refl\n\nFind' : {A : 𝕌} (x : ⟦ A ⟧) → Fin ∣ A ∣\nFind' = proj₁ ∘ Find\n\ndata State (A : 𝕌) : Set where\n ⟪_[_]⟫ : Vec ⟦ A ⟧ ∣ A ∣ → Fin ∣ A ∣ → State A\n\nresolve : {A : 𝕌} → State A → ⟦ A ⟧\nresolve ⟪ v [ i ]⟫ = lookup v i\n\nst : {A B : 𝕌} → ⟦ A ⟧ → (c : A ↔ B) → Σ[ C ∈ 𝕌 ] (C ↔ B × State C)\nst (inj₂ y) (unite₊l {t}) = _ , id↔ , ⟪ Enum t [ Find' y ]⟫\nst a (uniti₊l {t}) = _ , id↔ , ⟪ (Enum (𝟘 +ᵤ t)) [ Find' a ]⟫\nst (inj₁ x) (unite₊r {t}) = _ , id↔ , ⟪ Enum t [ Find' x ]⟫\nst a (uniti₊r {t}) = _ , id↔ , ⟪ (Enum (t +ᵤ 𝟘)) [ Find' {t +ᵤ 𝟘} (inj₁ a) ]⟫\nst (inj₁ x) (swap₊ {t₁} {t₂}) = _ , id↔ , ⟪ Enum _ [ Find' {t₂ +ᵤ t₁} (inj₂ x) ]⟫\nst (inj₂ y) (swap₊ {t₁} {t₂}) = _ , id↔ , ⟪ Enum _ [ Find' {t₂ +ᵤ t₁} (inj₁ y) ]⟫\nst (inj₁ x) (assocl₊ {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {(t₁ +ᵤ t₂) +ᵤ t₃} (inj₁ (inj₁ x)) ]⟫\nst (inj₂ (inj₁ x)) (assocl₊ {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {(t₁ +ᵤ t₂) +ᵤ t₃} (inj₁ (inj₂ x)) ]⟫\nst (inj₂ (inj₂ y)) (assocl₊ {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {(t₁ +ᵤ t₂) +ᵤ t₃} (inj₂ y) ]⟫\nst (inj₁ (inj₁ x)) (assocr₊ {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {t₁ +ᵤ t₂ +ᵤ t₃} (inj₁ x) ]⟫\nst (inj₁ (inj₂ y)) (assocr₊ {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {t₁ +ᵤ t₂ +ᵤ t₃} (inj₂ (inj₁ y)) ]⟫\nst (inj₂ y) (assocr₊ {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {t₁ +ᵤ t₂ +ᵤ t₃} (inj₂ (inj₂ y)) ]⟫\nst (tt , y) unite⋆l = _ , id↔ , ⟪ Enum _ [ Find' y ]⟫\nst a uniti⋆l = _ , id↔ , ⟪ Enum _ [ Find' (tt , a) ]⟫\nst (x , tt) unite⋆r = _ , id↔ , ⟪ Enum _ [ Find' x ]⟫\nst a uniti⋆r = _ , id↔ , ⟪ Enum _ [ Find' (a , tt) ]⟫\nst (x , y) swap⋆ = _ , id↔ , ⟪ Enum _ [ Find' (y , x) ]⟫\nst (x , y , z) assocl⋆ = _ , id↔ , ⟪ Enum _ [ Find' ((x , y) , z) ]⟫\nst ((x , y) , z) assocr⋆ = _ , id↔ , ⟪ Enum _ [ Find' (x , y , z) ]⟫\nst (inj₁ x , y) (dist {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {t₁ ×ᵤ t₃ +ᵤ t₂ ×ᵤ t₃} (inj₁ (x , y)) ]⟫\nst (inj₂ x , y) (dist {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {t₁ ×ᵤ t₃ +ᵤ t₂ ×ᵤ t₃} (inj₂ (x , y)) ]⟫\nst (inj₁ (x , y)) (factor {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {(t₁ +ᵤ t₂) ×ᵤ t₃} (inj₁ x , y) ]⟫\nst (inj₂ (y , z)) (factor {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {(t₁ +ᵤ t₂) ×ᵤ t₃} (inj₂ y , z) ]⟫\nst (x , inj₁ y) (distl {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {(t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃)} (inj₁ (x , y)) ]⟫\nst (x , inj₂ y) (distl {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {(t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃)} (inj₂ (x , y)) ]⟫\nst (inj₁ (x , y)) (factorl {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {t₁ ×ᵤ (t₂ +ᵤ t₃)} (x , inj₁ y) ]⟫\nst (inj₂ (x , z)) (factorl {t₁} {t₂} {t₃}) = _ , id↔ , ⟪ Enum _ [ Find' {t₁ ×ᵤ (t₂ +ᵤ t₃)} (x , inj₂ z) ]⟫\nst tt (η {t} v) = _ , id↔ , ⟪ Enum (t ×ᵤ (𝟙/ v)) [ Find' {t ×ᵤ (𝟙/ v)} (v , ○) ]⟫\nst (x , ○) (ε {t} v) with 𝕌dec t v x\nst (x , ○) (ε {t} v) | yes _ = _ , id↔ , ⟪ Enum _ [ Find' tt ]⟫\nst (x , ○) (ε {t} v) | no _ = _ , (ε {t} v) , ⟪ Enum (t ×ᵤ (𝟙/ v)) [ Find' {t ×ᵤ (𝟙/ v)} (x , ○) ]⟫\nst a id↔ = _ , id↔ , ⟪ Enum _ [ Find' a ]⟫\nst a (id↔ ⊚ c) = _ , c , ⟪ Enum _ [ Find' a ]⟫\nst a (c₁ ⊚ c₂) = let _ , c , st' = st a c₁ in\n _ , c ⊚ c₂ , st'\nst (inj₁ x) (_⊕_ {t₁} {t₂} {_} {t₄} id↔ c₂) = _ , id↔ , ⟪ Enum _ [ Find' {_ +ᵤ t₄} (inj₁ x) ]⟫\nst (inj₁ x) (_⊕_ {t₁} {t₂} c₁ c₂) = let _ , c , st' = st x c₁ in\n _ , c ⊕ c₂ , ⟪ Enum _ [ Find' {_ +ᵤ t₂} (inj₁ $ resolve st') ]⟫\nst (inj₂ y) (_⊕_ {t₁} {t₂} {t₃} {_} c₁ id↔) = _ , id↔ , ⟪ Enum _ [ Find' {t₃ +ᵤ _} (inj₂ y) ]⟫\nst (inj₂ y) (_⊕_ {t₁} c₁ c₂) = let _ , c , st' = st y c₂ in\n _ , c₁ ⊕ c , ⟪ Enum _ [ Find' {t₁ +ᵤ _} (inj₂ $ resolve st') ]⟫\nst (x , y) (id↔ ⊗ id↔) = _ , id↔ , ⟪ Enum _ [ Find' (x , y) ]⟫\nst (x , y) (id↔ ⊗ c₂) = let _ , c , st' = st y c₂ in\n _ , id↔ ⊗ c , ⟪ Enum _ [ Find' (x , resolve st') ]⟫\nst (x , y) (c₁ ⊗ c₂) = let _ , c , st' = st x c₁ in\n _ , c ⊗ c₂ , ⟪ Enum _ [ Find' (resolve st' , y) ]⟫\n\nstep : {A B : 𝕌} (c : A ↔ B) → State A → Σ[ C ∈ 𝕌 ] (C ↔ B × State C)\nstep c ⟪ v [ i ]⟫ = st (lookup v i) c\n\ndata State' : Set where\n ⟪_∥_[_]⟫ : {A B : 𝕌} → A ↔ B → Vec ⟦ A ⟧ ∣ A ∣ → Fin ∣ A ∣ → State'\n\nstep' : State' → State'\nstep' ⟪ c ∥ v [ i ]⟫ with step c ⟪ v [ i ]⟫\nstep' ⟪ c ∥ v [ i ]⟫ | _ , c' , ⟪ v' [ i' ]⟫ = ⟪ c' ∥ v' [ i' ]⟫\n\nrun : (n : ℕ) → State' → Vec State' (suc n)\nrun 0 st = [ st ]\nrun (suc n) st with run n st\n... | sts with last sts\n... | ⟪ cx ∥ vx [ ix ]⟫ rewrite +-comm 1 (suc n) = sts ++ [ step' ⟪ cx ∥ vx [ ix ]⟫ ]\n\nex₁ : Vec State' 33\nex₁ = run 32 ⟪ id' ∥ Enum 𝟚 [ Fin.fromℕ 1 ]⟫\n\n", "meta": {"hexsha": "ca192d65dd5d88bff1ab5b14c5faf752df38bb85", "size": 7988, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "fracGC/PiFracMemSem.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "fracGC/PiFracMemSem.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "fracGC/PiFracMemSem.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 49.925, "max_line_length": 117, "alphanum_fraction": 0.4242613921, "num_tokens": 4116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.3616005761267814}} {"text": "module Common.Context where\n\nopen import Common public\n\n\n-- Contexts.\n\ndata Cx (U : Set) : Set where\n ∅ : Cx U\n _,_ : Cx U → U → Cx U\n\n\n-- Vector contexts.\n\ndata VCx (U : Set) : ℕ → Set where\n ∅ : VCx U zero\n _,_ : ∀ {n} → VCx U n → U → VCx U (suc n)\n\n\n-- Inversion principles for contexts.\n\nmodule _ {U : Set} where\n inv,₁ : ∀ {Γ Γ′ : Cx U} {A A′ : U} → (Γ Cx., A) ≡ (Γ′ , A′) → Γ ≡ Γ′\n inv,₁ refl = refl\n\n inv,₂ : ∀ {Γ Γ′ : Cx U} {A A′ : U} → (Γ Cx., A) ≡ (Γ′ , A′) → A ≡ A′\n inv,₂ refl = refl\n\n\n-- Decidable equality for contexts.\n\nmodule ContextEquality {U : Set} (_≟ᵁ_ : (A A′ : U) → Dec (A ≡ A′)) where\n _≟ᵀ⋆_ : (Γ Γ′ : Cx U) → Dec (Γ ≡ Γ′)\n ∅ ≟ᵀ⋆ ∅ = yes refl\n ∅ ≟ᵀ⋆ (Γ′ , A′) = no λ ()\n (Γ , A) ≟ᵀ⋆ ∅ = no λ ()\n (Γ , A) ≟ᵀ⋆ (Γ′ , A′) with Γ ≟ᵀ⋆ Γ′ | A ≟ᵁ A′\n (Γ , A) ≟ᵀ⋆ (.Γ , .A) | yes refl | yes refl = yes refl\n (Γ , A) ≟ᵀ⋆ (Γ′ , A′) | no Γ≢Γ′ | _ = no (Γ≢Γ′ ∘ inv,₁)\n (Γ , A) ≟ᵀ⋆ (Γ′ , A′) | _ | no A≢A′ = no (A≢A′ ∘ inv,₂)\n\n\n-- Context membership, or nameless typed de Bruijn indices.\n\nmodule _ {U : Set} where\n infix 3 _∈_\n data _∈_ (A : U) : Cx U → Set where\n instance\n top : ∀ {Γ} → A ∈ Γ , A\n pop : ∀ {B Γ} → A ∈ Γ → A ∈ Γ , B\n\n pop² : ∀ {A B C Γ} → A ∈ Γ → A ∈ Γ , B , C\n pop² = pop ∘ pop\n\n i₀ : ∀ {A Γ} → A ∈ Γ , A\n i₀ = top\n\n i₁ : ∀ {A B Γ} → A ∈ Γ , A , B\n i₁ = pop top\n\n i₂ : ∀ {A B C Γ} → A ∈ Γ , A , B , C\n i₂ = pop² top\n\n [_]ⁱ : ∀ {A Γ} → A ∈ Γ → ℕ\n [ top ]ⁱ = zero\n [ pop i ]ⁱ = suc [ i ]ⁱ\n\n\n-- Context inclusion, or order-preserving embedding.\n\nmodule _ {U : Set} where\n infix 3 _⊆_\n data _⊆_ : Cx U → Cx U → Set where\n instance\n done : ∅ ⊆ ∅\n skip : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊆ Γ′ , A\n keep : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ , A ⊆ Γ′ , A\n\n skip² : ∀ {A B Γ Γ′} → Γ ⊆ Γ′ → Γ ⊆ Γ′ , B , A\n skip² = skip ∘ skip\n\n keep² : ∀ {A B Γ Γ′} → Γ ⊆ Γ′ → Γ , B , A ⊆ Γ′ , B , A\n keep² = keep ∘ keep\n\n instance\n refl⊆ : ∀ {Γ} → Γ ⊆ Γ\n refl⊆ {∅} = done\n refl⊆ {Γ , A} = keep refl⊆\n\n trans⊆ : ∀ {Γ Γ′ Γ″} → Γ ⊆ Γ′ → Γ′ ⊆ Γ″ → Γ ⊆ Γ″\n trans⊆ η done = η\n trans⊆ η (skip η′) = skip (trans⊆ η η′)\n trans⊆ (skip η) (keep η′) = skip (trans⊆ η η′)\n trans⊆ (keep η) (keep η′) = keep (trans⊆ η η′)\n\n unskip⊆ : ∀ {A Γ Γ′} → Γ , A ⊆ Γ′ → Γ ⊆ Γ′\n unskip⊆ (skip η) = skip (unskip⊆ η)\n unskip⊆ (keep η) = skip η\n\n unkeep⊆ : ∀ {A Γ Γ′} → Γ , A ⊆ Γ′ , A → Γ ⊆ Γ′\n unkeep⊆ (skip η) = unskip⊆ η\n unkeep⊆ (keep η) = η\n\n weak⊆ : ∀ {A Γ} → Γ ⊆ Γ , A\n weak⊆ = skip refl⊆\n\n weak²⊆ : ∀ {A B Γ} → Γ ⊆ Γ , A , B\n weak²⊆ = skip² refl⊆\n\n bot⊆ : ∀ {Γ} → ∅ ⊆ Γ\n bot⊆ {∅} = done\n bot⊆ {Γ , A} = skip bot⊆\n\n\n-- Monotonicity of context membership with respect to context inclusion.\n\nmodule _ {U : Set} where\n mono∈ : ∀ {A : U} {Γ Γ′} → Γ ⊆ Γ′ → A ∈ Γ → A ∈ Γ′\n mono∈ done ()\n mono∈ (skip η) i = pop (mono∈ η i)\n mono∈ (keep η) top = top\n mono∈ (keep η) (pop i) = pop (mono∈ η i)\n\n reflmono∈ : ∀ {A Γ} → (i : A ∈ Γ) → i ≡ mono∈ refl⊆ i\n reflmono∈ top = refl\n reflmono∈ (pop i) = cong pop (reflmono∈ i)\n\n transmono∈ : ∀ {A Γ Γ′ Γ″} → (η : Γ ⊆ Γ′) (η′ : Γ′ ⊆ Γ″) (i : A ∈ Γ)\n → mono∈ η′ (mono∈ η i) ≡ mono∈ (trans⊆ η η′) i\n transmono∈ done η′ ()\n transmono∈ η (skip η′) i = cong pop (transmono∈ η η′ i)\n transmono∈ (skip η) (keep η′) i = cong pop (transmono∈ η η′ i)\n transmono∈ (keep η) (keep η′) top = refl\n transmono∈ (keep η) (keep η′) (pop i) = cong pop (transmono∈ η η′ i)\n\n\n-- Concatenation of contexts.\n\nmodule _ {U : Set} where\n _⧺_ : Cx U → Cx U → Cx U\n Γ ⧺ ∅ = Γ\n Γ ⧺ (Γ′ , A) = (Γ ⧺ Γ′) , A\n\n id⧺₁ : ∀ {Γ} → Γ ⧺ ∅ ≡ Γ\n id⧺₁ = refl\n\n id⧺₂ : ∀ {Γ} → ∅ ⧺ Γ ≡ Γ\n id⧺₂ {∅} = refl\n id⧺₂ {Γ , A} = cong² _,_ id⧺₂ refl\n\n weak⊆⧺₁ : ∀ {Γ} Γ′ → Γ ⊆ Γ ⧺ Γ′\n weak⊆⧺₁ ∅ = refl⊆\n weak⊆⧺₁ (Γ′ , A) = skip (weak⊆⧺₁ Γ′)\n\n weak⊆⧺₂ : ∀ {Γ Γ′} → Γ′ ⊆ Γ ⧺ Γ′\n weak⊆⧺₂ {Γ} {∅} = bot⊆\n weak⊆⧺₂ {Γ} {Γ′ , A} = keep weak⊆⧺₂\n\n\n-- Thinning of contexts.\n\nmodule _ {U : Set} where\n _∖_ : ∀ {A} → (Γ : Cx U) → A ∈ Γ → Cx U\n ∅ ∖ ()\n (Γ , A) ∖ top = Γ\n (Γ , B) ∖ pop i = (Γ ∖ i) , B\n\n thin⊆ : ∀ {A Γ} → (i : A ∈ Γ) → Γ ∖ i ⊆ Γ\n thin⊆ top = weak⊆\n thin⊆ (pop i) = keep (thin⊆ i)\n\n\n-- Decidable equality of context membership.\n\nmodule _ {U : Set} where\n data _=∈_ {A : U} {Γ} (i : A ∈ Γ) : ∀ {B} → B ∈ Γ → Set where\n same : i =∈ i\n diff : ∀ {B} → (j : B ∈ Γ ∖ i) → i =∈ mono∈ (thin⊆ i) j\n\n _≟∈_ : ∀ {A B : U} {Γ} → (i : A ∈ Γ) (j : B ∈ Γ) → i =∈ j\n top ≟∈ top = same\n top ≟∈ pop j rewrite reflmono∈ j = diff j\n pop i ≟∈ top = diff top\n pop i ≟∈ pop j with i ≟∈ j\n pop i ≟∈ pop .i | same = same\n pop i ≟∈ pop ._ | diff j = diff (pop j)\n", "meta": {"hexsha": "484db1dd499ee51f8eb2247470b69eb08bf1e2fe", "size": 4713, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Common/Context.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": "Common/Context.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": "Common/Context.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": 25.2032085561, "max_line_length": 73, "alphanum_fraction": 0.4339062168, "num_tokens": 2509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.6261241842048093, "lm_q1q2_score": 0.36158381440902476}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\n{- Remember to keep CodeAP.agda in sync. -}\n\nopen import HoTT\nimport homotopy.RelativelyConstantToSetExtendsViaSurjection as SurjExt\n\nmodule homotopy.vankampen.CodeBP {i j k l}\n (span : Span {i} {j} {k})\n {D : Type l} (h : D → Span.C span) (h-is-surj : is-surj h) where\n\n open Span span\n\n data precodeBB (b₀ : B) : B → Type (lmax (lmax (lmax i j) k) l)\n data precodeBA (b₀ : B) (a₁ : A) : Type (lmax (lmax (lmax i j) k) l)\n\n data precodeBB b₀ where\n pc-b : ∀ {b₁} (pB : b₀ =₀ b₁) → precodeBB b₀ b₁\n pc-bab : ∀ d {b₁} (pc : precodeBA b₀ (f (h d))) (pB : g (h d) =₀ b₁) → precodeBB b₀ b₁\n\n infix 66 pc-b\n syntax pc-b p = ⟧b p\n infixl 65 pc-bab\n syntax pc-bab d pcBA pB = pcBA ba⟦ d ⟧b pB\n\n data precodeBA b₀ a₁ where\n pc-bba : ∀ d (pc : precodeBB b₀ (g (h d))) (pA : f (h d) =₀ a₁) → precodeBA b₀ a₁\n\n infixl 65 pc-bba\n syntax pc-bba d pcBB pA = pcBB bb⟦ d ⟧a pA\n\n data precodeBB-rel {b₀ : B} : {b₁ : B}\n → precodeBB b₀ b₁ → precodeBB b₀ b₁ → Type (lmax (lmax (lmax i j) k) l)\n data precodeBA-rel {b₀ : B} : {a₁ : A}\n → precodeBA b₀ a₁ → precodeBA b₀ a₁ → Type (lmax (lmax (lmax i j) k) l)\n data precodeBB-rel {b₀} where\n pcBBr-idp₀-idp₀ : ∀ {d} pcBB → precodeBB-rel (pcBB bb⟦ d ⟧a idp₀ ba⟦ d ⟧b idp₀) pcBB\n pcBBr-switch : ∀ {d₀ d₁ : D} pcBB (pC : h d₀ =₀ h d₁)\n → precodeBB-rel (pcBB bb⟦ d₀ ⟧a ap₀ f pC ba⟦ d₁ ⟧b idp₀) (pcBB bb⟦ d₀ ⟧a idp₀ ba⟦ d₀ ⟧b ap₀ g pC)\n pcBBr-cong : ∀ {d b₁ pcBA₁ pcBA₂} (r : precodeBA-rel pcBA₁ pcBA₂) (pB : g (h d) =₀ b₁)\n → precodeBB-rel (pcBA₁ ba⟦ d ⟧b pB) (pcBA₂ ba⟦ d ⟧b pB)\n data precodeBA-rel {b₀} where\n pcBAr-idp₀-idp₀ : ∀ {d} pcBA → precodeBA-rel (pcBA ba⟦ d ⟧b idp₀ bb⟦ d ⟧a idp₀) pcBA\n pcBAr-cong : ∀ {d a₁ pcBB₁ pcBB₂} (r : precodeBB-rel pcBB₁ pcBB₂) (pA : f (h d) =₀ a₁)\n → precodeBA-rel (pcBB₁ bb⟦ d ⟧a pA) (pcBB₂ bb⟦ d ⟧a pA)\n\n codeBB : B → B → Type (lmax (lmax (lmax i j) k) l)\n codeBB b₀ b₁ = SetQuot (precodeBB-rel {b₀} {b₁})\n\n codeBA : B → A → Type (lmax (lmax (lmax i j) k) l)\n codeBA b₀ a₁ = SetQuot (precodeBA-rel {b₀} {a₁})\n\n c-bba : ∀ {a₀} d {a₁} (pc : codeBB a₀ (g (h d))) (pA : f (h d) =₀ a₁) → codeBA a₀ a₁\n c-bba d {a₁} c pA = SetQuot-rec SetQuot-is-set\n (λ pc → q[ pc-bba d pc pA ])\n (λ r → quot-rel $ pcBAr-cong r pA) c\n\n c-bab : ∀ {a₀} d {b₁} (pc : codeBA a₀ (f (h d))) (pB : g (h d) =₀ b₁) → codeBB a₀ b₁\n c-bab d {a₁} c pB = SetQuot-rec SetQuot-is-set\n (λ pc → q[ pc-bab d pc pB ])\n (λ r → quot-rel $ pcBBr-cong r pB) c\n\n-- codeBP\n\n abstract\n pcBB-idp₀-idp₀-head : ∀ {d₀ b} (pB : g (h d₀) =₀ b)\n → q[ ⟧b idp₀ bb⟦ d₀ ⟧a idp₀ ba⟦ d₀ ⟧b pB ] == q[ ⟧b pB ] :> codeBB _ b\n pcBB-idp₀-idp₀-head {d₀} = Trunc-elim (λ _ → =-preserves-set SetQuot-is-set) lemma where\n lemma : ∀ {b} (pB : g (h d₀) == b)\n → q[ ⟧b idp₀ bb⟦ d₀ ⟧a idp₀ ba⟦ d₀ ⟧b [ pB ] ] == q[ ⟧b [ pB ] ] :> codeBB _ b\n lemma idp = quot-rel $ pcBBr-idp₀-idp₀ (⟧b idp₀)\n\n pcBA-prepend : ∀ {b₀} d₁ {b₂} → b₀ =₀ g (h d₁) → precodeBA (g (h d₁)) b₂ → precodeBA b₀ b₂\n pcBB-prepend : ∀ {b₀} d₁ {a₂} → b₀ =₀ g (h d₁) → precodeBB (g (h d₁)) a₂ → precodeBB b₀ a₂\n pcBA-prepend d₁ pB (pc-bba d pc pA) = pc-bba d (pcBB-prepend d₁ pB pc) pA\n pcBB-prepend d₁ pB (pc-b pB₁) = pc-bab d₁ (pc-bba d₁ (pc-b pB) idp₀) pB₁\n pcBB-prepend d₁ pB (pc-bab d pc pB₁) = pc-bab d (pcBA-prepend d₁ pB pc) pB₁\n\n abstract\n pcBA-prepend-idp₀ : ∀ {d₀ b₁} (pcBA : precodeBA (g (h d₀)) b₁)\n → q[ pcBA-prepend d₀ idp₀ pcBA ] == q[ pcBA ] :> codeBA (g (h d₀)) b₁\n pcBB-prepend-idp₀ : ∀ {d₀ a₁} (pcBB : precodeBB (g (h d₀)) a₁)\n → q[ pcBB-prepend d₀ idp₀ pcBB ] == q[ pcBB ] :> codeBB (g (h d₀)) a₁\n pcBA-prepend-idp₀ (pc-bba d pc pB) = pcBB-prepend-idp₀ pc |in-ctx λ c → c-bba d c pB\n pcBB-prepend-idp₀ (pc-b pB) = pcBB-idp₀-idp₀-head pB\n pcBB-prepend-idp₀ (pc-bab d pc pB) = pcBA-prepend-idp₀ pc |in-ctx λ c → c-bab d c pB\n\n transp-cBA-l : ∀ d {b₀ a₁} (p : g (h d) == b₀) (pcBA : precodeBA (g (h d)) a₁)\n → transport (λ x → codeBA x a₁) p q[ pcBA ] == q[ pcBA-prepend d [ ! p ] pcBA ]\n transp-cBA-l d idp pcBA = ! $ pcBA-prepend-idp₀ pcBA\n\n transp-cBB-l : ∀ d {b₀ b₁} (p : g (h d) == b₀) (pcBB : precodeBB (g (h d)) b₁)\n → transport (λ x → codeBB x b₁) p q[ pcBB ] == q[ pcBB-prepend d [ ! p ] pcBB ]\n transp-cBB-l d idp pcBB = ! $ pcBB-prepend-idp₀ pcBB\n\n transp-cBA-r : ∀ d {b₀ a₁} (p : f (h d) == a₁) (pcBA : precodeBA b₀ (f (h d)))\n → transport (λ x → codeBA b₀ x) p q[ pcBA ] == q[ pcBA ba⟦ d ⟧b idp₀ bb⟦ d ⟧a [ p ] ]\n transp-cBA-r d idp pcBA = ! $ quot-rel $ pcBAr-idp₀-idp₀ pcBA\n\n transp-cBB-r : ∀ d {b₀ b₁} (p : g (h d) == b₁) (pcBB : precodeBB b₀ (g (h d)))\n → transport (λ x → codeBB b₀ x) p q[ pcBB ] == q[ pcBB bb⟦ d ⟧a idp₀ ba⟦ d ⟧b [ p ] ]\n transp-cBB-r d idp pcBB = ! $ quot-rel $ pcBBr-idp₀-idp₀ pcBB\n\n module CodeBAEquivCodeBB (b₀ : B) where\n\n eqv-on-image : (d : D) → codeBA b₀ (f (h d)) ≃ codeBB b₀ (g (h d))\n eqv-on-image d = equiv to from to-from from-to where\n to = λ c → c-bab d c idp₀\n from = λ c → c-bba d c idp₀\n\n abstract\n from-to : ∀ cBA → from (to cBA) == cBA\n from-to = SetQuot-elim\n (λ _ → =-preserves-set SetQuot-is-set)\n (λ pcBA → quot-rel (pcBAr-idp₀-idp₀ pcBA))\n (λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))\n\n to-from : ∀ cBB → to (from cBB) == cBB\n to-from = SetQuot-elim\n (λ _ → =-preserves-set SetQuot-is-set)\n (λ pcBB → quot-rel (pcBBr-idp₀-idp₀ pcBB))\n (λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))\n\n abstract\n eqv-is-const : ∀ d₁ d₂ (p : h d₁ == h d₂)\n → eqv-on-image d₁ == eqv-on-image d₂\n [ (λ c → codeBA b₀ (f c) ≃ codeBB b₀ (g c)) ↓ p ]\n eqv-is-const d₁ d₂ p = ↓-Subtype-in (λ d → is-equiv-prop) $\n ↓-→-from-transp $ λ= $\n SetQuot-elim (λ _ → =-preserves-set SetQuot-is-set)\n (λ pcBA →\n transport (λ c → codeBB b₀ (g c)) p q[ pcBA ba⟦ d₁ ⟧b idp₀ ]\n =⟨ ap-∘ (codeBB b₀) g p |in-ctx (λ p → coe p q[ pcBA ba⟦ d₁ ⟧b idp₀ ]) ⟩\n transport (codeBB b₀) (ap g p) q[ pcBA ba⟦ d₁ ⟧b idp₀ ]\n =⟨ transp-cBB-r d₁ (ap g p) (pcBA ba⟦ d₁ ⟧b idp₀) ⟩\n q[ pcBA ba⟦ d₁ ⟧b idp₀ bb⟦ d₁ ⟧a idp₀ ba⟦ d₁ ⟧b [ ap g p ] ]\n =⟨ ! $ quot-rel $ pcBBr-switch (pcBA ba⟦ d₁ ⟧b idp₀) [ p ] ⟩\n q[ pcBA ba⟦ d₁ ⟧b idp₀ bb⟦ d₁ ⟧a [ ap f p ] ba⟦ d₂ ⟧b idp₀ ]\n =⟨ ! $ transp-cBA-r d₁ (ap f p) pcBA |in-ctx (λ c → c-bab d₂ c idp₀) ⟩\n c-bab d₂ (transport (codeBA b₀) (ap f p) q[ pcBA ]) idp₀\n =⟨ ∘-ap (codeBA b₀) f p |in-ctx (λ p → coe p q[ pcBA ]) |in-ctx (λ c → c-bab d₂ c idp₀) ⟩\n c-bab d₂ (transport (λ c → codeBA b₀ (f c)) p q[ pcBA ]) idp₀\n =∎)\n (λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _))\n\n module SE = SurjExt\n (λ c → ≃-is-set SetQuot-is-set SetQuot-is-set)\n h h-is-surj\n eqv-on-image\n eqv-is-const\n\n abstract\n eqv : ∀ c → codeBA b₀ (f c) ≃ codeBB b₀ (g c)\n eqv = SE.ext\n\n eqv-β : ∀ d → eqv (h d) == eqv-on-image d\n eqv-β = SE.β\n\n module CodeBP (b₀ : B) = PushoutRec (codeBA b₀) (codeBB b₀)\n (ua ∘ CodeBAEquivCodeBB.eqv b₀)\n\n codeBP : B → Pushout span → Type (lmax (lmax (lmax i j) k) l)\n codeBP = CodeBP.f\n\n abstract\n codeBP-level : ∀ {a₀ p₁} → is-set (codeBP a₀ p₁)\n codeBP-level {a₀} {p₁} = Pushout-elim\n {P = λ p₁ → is-set (codeBP a₀ p₁)}\n (λ a₁ → SetQuot-is-set)\n (λ b₁ → SetQuot-is-set)\n (λ c₁ → prop-has-all-paths-↓ is-set-is-prop)\n p₁\n codeBP-is-set = codeBP-level\n\n abstract\n transp-cBP-glue : ∀ {b₀} d₁ (pcBA : precodeBA b₀ (f (h d₁)))\n → transport (codeBP b₀) (glue (h d₁)) q[ pcBA ] == q[ pcBA ba⟦ d₁ ⟧b idp₀ ]\n transp-cBP-glue {b₀} d₁ pcBA =\n transport (codeBP b₀) (glue (h d₁)) q[ pcBA ]\n =⟨ ap (λ e → coe e q[ pcBA ]) (CodeBP.glue-β b₀ (h d₁) ∙ ap ua (CodeBAEquivCodeBB.eqv-β b₀ d₁)) ⟩\n coe (ua (CodeBAEquivCodeBB.eqv-on-image b₀ d₁)) q[ pcBA ]\n =⟨ coe-β (CodeBAEquivCodeBB.eqv-on-image b₀ d₁) q[ pcBA ] ⟩\n q[ pcBA ba⟦ d₁ ⟧b idp₀ ]\n =∎\n\n transp-cBP-!glue : ∀ {b₀} d₁ (pcBB : precodeBB b₀ (g (h d₁)))\n → transport (codeBP b₀) (! (glue (h d₁))) q[ pcBB ] == q[ pcBB bb⟦ d₁ ⟧a idp₀ ]\n transp-cBP-!glue {b₀} d₁ pcBB =\n transport (codeBP b₀) (! (glue (h d₁))) q[ pcBB ]\n =⟨ ap (λ e → coe e q[ pcBB ]) (ap-! (codeBP b₀) (glue (h d₁)))\n ∙ coe-! (ap (codeBP b₀) (glue (h d₁))) q[ pcBB ] ⟩\n transport! (codeBP b₀) (glue (h d₁)) q[ pcBB ]\n =⟨ ap (λ e → coe! e q[ pcBB ]) (CodeBP.glue-β b₀ (h d₁) ∙ ap ua (CodeBAEquivCodeBB.eqv-β b₀ d₁)) ⟩\n coe! (ua (CodeBAEquivCodeBB.eqv-on-image b₀ d₁)) q[ pcBB ]\n =⟨ coe!-β (CodeBAEquivCodeBB.eqv-on-image b₀ d₁) q[ pcBB ] ⟩\n q[ pcBB bb⟦ d₁ ⟧a idp₀ ]\n =∎\n\n -- code to path\n pcBA-to-path : ∀ {b₀ a₁} → precodeBA b₀ a₁ → right b₀ =₀ left a₁ :> Pushout span\n pcBB-to-path : ∀ {b₀ b₁} → precodeBB b₀ b₁ → right b₀ =₀ right b₁ :> Pushout span\n pcBA-to-path (pc-bba d pc pA) = pcBB-to-path pc ∙₀' !₀ [ glue (h d) ] ∙₀' ap₀ left pA\n pcBB-to-path (pc-b pB) = ap₀ right pB\n pcBB-to-path (pc-bab d pc pB) = pcBA-to-path pc ∙₀' [ glue (h d) ] ∙₀' ap₀ right pB\n\n abstract\n pcBA-to-path-rel : ∀ {b₀ a₁} {pcBA₀ pcBA₁ : precodeBA b₀ a₁}\n → precodeBA-rel pcBA₀ pcBA₁ → pcBA-to-path pcBA₀ == pcBA-to-path pcBA₁\n pcBB-to-path-rel : ∀ {b₀ b₁} {pcBB₀ pcBB₁ : precodeBB b₀ b₁}\n → precodeBB-rel pcBB₀ pcBB₁ → pcBB-to-path pcBB₀ == pcBB-to-path pcBB₁\n pcBA-to-path-rel (pcBAr-idp₀-idp₀ pcBA) =\n ∙₀'-assoc (pcBA-to-path pcBA) [ glue (h _) ] [ ! (glue (h _)) ]\n ∙ ap (λ p → pcBA-to-path pcBA ∙₀' [ p ]) (!-inv'-r (glue (h _)))\n ∙ ∙₀'-unit-r (pcBA-to-path pcBA)\n pcBA-to-path-rel (pcBAr-cong pcBB pA) = pcBB-to-path-rel pcBB |in-ctx _∙₀' !₀ [ glue (h _) ] ∙₀' ap₀ left pA\n pcBB-to-path-rel (pcBBr-idp₀-idp₀ pcBB) =\n ∙₀'-assoc (pcBB-to-path pcBB) [ ! (glue (h _)) ] [ glue (h _) ]\n ∙ ap (λ p → pcBB-to-path pcBB ∙₀' [ p ]) (!-inv'-l (glue (h _)))\n ∙ ∙₀'-unit-r (pcBB-to-path pcBB)\n pcBB-to-path-rel (pcBBr-switch pcBB pC) =\n ap (_∙₀' [ glue (h _) ]) (! (∙₀'-assoc (pcBB-to-path pcBB) [ ! (glue (h _)) ] (ap₀ left (ap₀ f pC))))\n ∙ ∙₀'-assoc (pcBB-to-path pcBB ∙₀' [ ! (glue (h _)) ]) (ap₀ left (ap₀ f pC)) [ glue (h _) ]\n ∙ ap ((pcBB-to-path pcBB ∙₀' [ ! (glue (h _)) ]) ∙₀'_) (natural₀ pC)\n where\n natural : ∀ {c₀ c₁} (p : c₀ == c₁)\n → (ap left (ap f p) ∙' glue c₁) == (glue c₀ ∙' ap right (ap g p))\n :> (left (f c₀) == right (g c₁) :> Pushout span)\n natural idp = ∙'-unit-l (glue _)\n\n natural₀ : ∀ {c₀ c₁} (p : c₀ =₀ c₁)\n → (ap₀ left (ap₀ f p) ∙₀' [ glue c₁ ]) == ([ glue c₀ ] ∙₀' ap₀ right (ap₀ g p))\n :> (left (f c₀) =₀ right (g c₁) :> Pushout span)\n natural₀ = Trunc-elim (λ _ → =-preserves-set Trunc-level) (ap [_] ∘ natural)\n pcBB-to-path-rel (pcBBr-cong pcBA pB) = pcBA-to-path-rel pcBA |in-ctx _∙₀' [ glue (h _) ] ∙₀' ap₀ right pB\n\n decodeBA : ∀ {b₀ a₁} → codeBA b₀ a₁ → right b₀ =₀ left a₁ :> Pushout span\n decodeBB : ∀ {b₀ b₁} → codeBB b₀ b₁ → right b₀ =₀ right b₁ :> Pushout span\n decodeBA = SetQuot-rec Trunc-level pcBA-to-path pcBA-to-path-rel\n decodeBB = SetQuot-rec Trunc-level pcBB-to-path pcBB-to-path-rel\n\n abstract\n decodeBA-is-decodeBB : ∀ {b₀} c₁ →\n decodeBA {b₀} {f c₁} == decodeBB {b₀} {g c₁}\n [ (λ p₁ → codeBP b₀ p₁ → right b₀ =₀ p₁) ↓ glue c₁ ]\n decodeBA-is-decodeBB {b₀ = b₀} = SurjExt.ext\n (λ _ → ↓-preserves-level $ Π-is-set λ _ → Trunc-level) h h-is-surj\n (λ d₁ → ↓-→-from-transp $ λ= $ SetQuot-elim\n {P = λ cBA → transport (right b₀ =₀_) (glue (h d₁)) (decodeBA cBA)\n == decodeBB (transport (codeBP b₀) (glue (h d₁)) cBA)}\n (λ _ → =-preserves-set Trunc-level)\n (λ pcBA →\n transport (right b₀ =₀_) (glue (h d₁)) (pcBA-to-path pcBA)\n =⟨ transp₀-cst=₀idf [ glue (h d₁) ] (pcBA-to-path pcBA) ⟩\n pcBA-to-path pcBA ∙₀' [ glue (h d₁) ]\n =⟨ ! $ ap (λ e → decodeBB (–> e q[ pcBA ])) (CodeBAEquivCodeBB.eqv-β b₀ d₁) ⟩\n decodeBB (–> (CodeBAEquivCodeBB.eqv b₀ (h d₁)) q[ pcBA ])\n =⟨ ! $ ap decodeBB (coe-β (CodeBAEquivCodeBB.eqv b₀ (h d₁)) q[ pcBA ]) ⟩\n decodeBB (coe (ua (CodeBAEquivCodeBB.eqv b₀ (h d₁))) q[ pcBA ])\n =⟨ ! $ ap (λ p → decodeBB (coe p q[ pcBA ])) (CodeBP.glue-β b₀ (h d₁)) ⟩\n decodeBB (transport (codeBP b₀) (glue (h d₁)) q[ pcBA ])\n =∎)\n (λ _ → prop-has-all-paths-↓ $ Trunc-level {n = 0} _ _))\n (λ _ _ _ → prop-has-all-paths-↓ $ ↓-level $ Π-is-set λ _ → Trunc-level)\n\n decodeBP : ∀ {b₀ p₁} → codeBP b₀ p₁ → right b₀ =₀ p₁\n decodeBP {p₁ = p₁} = Pushout-elim\n (λ a₁ → decodeBA) (λ b₁ → decodeBB)\n decodeBA-is-decodeBB\n p₁\n", "meta": {"hexsha": "18db204ee459d244d3352f9fb864451465b18c7a", "size": 12884, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/vankampen/CodeBP.agda", "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/homotopy/vankampen/CodeBP.agda", "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/homotopy/vankampen/CodeBP.agda", "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "avg_line_length": 47.7185185185, "max_line_length": 112, "alphanum_fraction": 0.5407482148, "num_tokens": 5715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.36141487379525444}} {"text": "-- Internal monoid in a strict monoidal category\n{-# OPTIONS --safe #-}\n\nopen import Cubical.Categories.Category.Base\nopen import Cubical.Categories.Monoidal.Base\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Path\nopen import Cubical.Categories.Functor.Base\nopen import Cubical.Reflection.RecordEquiv hiding (unit)\n\nmodule Cubical.Categories.Monoidal.Strict.Monoid {ℓ ℓ' : Level} (C : StrictMonCategory ℓ ℓ') where\n\nmodule _ where\n open StrictMonCategory C\n\n record Monoid : Type (ℓ-max ℓ ℓ') where\n constructor monoid\n field\n carrier : ob\n η : Hom[ unit , carrier ]\n μ : Hom[ carrier ⊗ carrier , carrier ]\n assoc-μ : PathP (λ i → Hom[ assoc carrier carrier carrier i , carrier ]) (μ ∘ (id ⊗ₕ μ)) (μ ∘ (μ ⊗ₕ id))\n idl-μ : PathP (λ i → Hom[ idl carrier i , carrier ]) (μ ∘ (η ⊗ₕ id)) id\n idr-μ : PathP (λ i → Hom[ idr carrier i , carrier ]) (μ ∘ (id ⊗ₕ η)) id\n\n open Monoid\n\n record Monoid[_,_] (monA monB : Monoid) : Type ℓ' where\n constructor monoidHom\n field\n carrierHom : Hom[ carrier monA , carrier monB ]\n nat-η : carrierHom ∘ η monA ≡ η monB\n nat-μ : carrierHom ∘ μ monA ≡ μ monB ∘ (carrierHom ⊗ₕ carrierHom)\n\n open Monoid[_,_]\n\n monoidHomExt : {monA monB : Monoid} (f g : Monoid[ monA , monB ]) → carrierHom f ≡ carrierHom g → f ≡ g\n carrierHom (monoidHomExt f g p i) = p i\n nat-η (monoidHomExt {monA} {monB} f g p i) = lemma i\n where lemma : PathP (λ i₁ → p i₁ ∘ η monA ≡ η monB) (nat-η f) (nat-η g)\n lemma = toPathP (isSetHom _ _ _ _)\n nat-μ (monoidHomExt {monA} {monB} f g p i) = lemma i\n where lemma : PathP (λ i₁ → p i₁ ∘ μ monA ≡ μ monB ∘ (p i₁ ⊗ₕ p i₁)) (nat-μ f) (nat-μ g)\n lemma = toPathP (isSetHom _ _ _ _)\n\nmodule C = StrictMonCategory C\nopen Category\nopen Monoid\nopen Monoid[_,_]\nopen Functor\n\nmonoidCategory : Category (ℓ-max ℓ ℓ') ℓ'\nob monoidCategory = Monoid\nHom[_,_] monoidCategory = Monoid[_,_]\ncarrierHom (id monoidCategory) = C.id\nnat-η (id monoidCategory {monA}) = C.⋆IdR (η monA)\nnat-μ (id monoidCategory {monA}) =\n C.id C.∘ μ monA\n ≡⟨ C.⋆IdR (μ monA) ⟩\n μ monA\n ≡⟨ sym (C.⋆IdL (μ monA)) ⟩\n μ monA C.∘ id C.C\n ≡⟨ cong (μ monA C.∘_) (sym (F-id C.─⊗─)) ⟩\n μ monA C.∘ (C.id C.⊗ₕ C.id) ∎\ncarrierHom (_⋆_ monoidCategory f g) = carrierHom g C.∘ carrierHom f\nnat-η (_⋆_ monoidCategory {monA} {monB} {monC} f g) =\n (carrierHom g C.∘ carrierHom f) C.∘ η monA\n ≡⟨ sym (C.⋆Assoc (η monA) (carrierHom f) (carrierHom g)) ⟩\n carrierHom g C.∘ (carrierHom f C.∘ η monA)\n ≡⟨ cong (carrierHom g C.∘_) (nat-η f) ⟩\n carrierHom g C.∘ η monB\n ≡⟨ nat-η g ⟩\n η monC ∎\nnat-μ (_⋆_ monoidCategory {monA} {monB} {monC} f g) =\n (carrierHom g C.∘ carrierHom f) C.∘ μ monA\n ≡⟨ sym (C.⋆Assoc (μ monA) (carrierHom f) (carrierHom g)) ⟩\n carrierHom g C.∘ (carrierHom f C.∘ μ monA)\n ≡⟨ cong (carrierHom g C.∘_) (nat-μ f) ⟩\n carrierHom g C.∘ (μ monB C.∘ (carrierHom f C.⊗ₕ carrierHom f))\n ≡⟨ C.⋆Assoc (carrierHom f C.⊗ₕ carrierHom f) (μ monB) (carrierHom g) ⟩\n (carrierHom g C.∘ μ monB) C.∘ (carrierHom f C.⊗ₕ carrierHom f)\n ≡⟨ cong (C._∘ (carrierHom f C.⊗ₕ carrierHom f)) (nat-μ g) ⟩\n (μ monC C.∘ (carrierHom g C.⊗ₕ carrierHom g)) C.∘ (carrierHom f C.⊗ₕ carrierHom f)\n ≡⟨ sym (C.⋆Assoc (carrierHom f C.⊗ₕ carrierHom f) (carrierHom g C.⊗ₕ carrierHom g) (μ monC)) ⟩\n μ monC C.∘ ((carrierHom g C.⊗ₕ carrierHom g) C.∘ (carrierHom f C.⊗ₕ carrierHom f))\n ≡⟨ cong (μ monC C.∘_) (sym (F-seq C.─⊗─ (carrierHom f , carrierHom f) (carrierHom g , carrierHom g))) ⟩\n μ monC C.∘ ((carrierHom g C.∘ carrierHom f) C.⊗ₕ (carrierHom g C.∘ carrierHom f)) ∎\n⋆IdL monoidCategory {monA} f = monoidHomExt _ _ (C.⋆IdL (carrierHom f))\n⋆IdR monoidCategory {monA} f = monoidHomExt _ _ (C.⋆IdR (carrierHom f))\n⋆Assoc monoidCategory {monA} {monB} {monC} {monD} f g h =\n monoidHomExt _ _ (C.⋆Assoc (carrierHom f) (carrierHom g) (carrierHom h))\nisSetHom monoidCategory {monA} {monB} =\n isOfHLevelRetractFromIso 2 isoToΣ\n (isSetΣ C.isSetHom λ _ → isProp→isSet (isProp× (C.isSetHom _ _) (C.isSetHom _ _)))\n where\n unquoteDecl isoToΣ = declareRecordIsoΣ isoToΣ (quote Monoid[_,_])\n", "meta": {"hexsha": "16db85daf082f412a38682920736567a86012c74", "size": 4206, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Categories/Monoidal/Strict/Monoid.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_issues_repo_path": "Cubical/Categories/Monoidal/Strict/Monoid.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Categories/Monoidal/Strict/Monoid.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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.9183673469, "max_line_length": 112, "alphanum_fraction": 0.6324298621, "num_tokens": 1762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7461389930307512, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.3614148683265795}} {"text": "-- Andreas, 2022-06-10\n-- A failed attempt to break Prop ≤ Set.\n-- See https://github.com/agda/agda/issues/5761#issuecomment-1151336715\n\n{-# OPTIONS --prop --cumulativity #-}\n\ndata ⊥ : Set where\nrecord ⊤ : Set where\n constructor tt\n\ndata Fool : Prop where\n true false : Fool\n\nBool : Set\nBool = Fool\n\nTrue : Bool → Set\nTrue true = ⊤\nTrue false = ⊥\n\nX : Fool → Set\n\ntrue≡false : X true → X false\ntrue≡false x = x\n\nX = True\n\n-- Now we have True true → True false which looks dangerous...\n-- But we cannot exploit it:\n\nfails : ⊥\nfails = true≡false tt\n\n-- ERROR:\n-- ⊤ !=< (True _)\n-- when checking that the expression tt has type X _\n", "meta": {"hexsha": "5a435557ff2081efb12f45d6c5e778bb6b7ac13e", "size": 636, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/PropCumulative.agda", "max_stars_repo_name": "KDr2/agda", "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": ["BSD-2-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/PropCumulative.agda", "max_issues_repo_name": "KDr2/agda", "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_licenses": ["BSD-2-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/PropCumulative.agda", "max_forks_repo_name": "KDr2/agda", "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.1891891892, "max_line_length": 71, "alphanum_fraction": 0.6525157233, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7401743505760728, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.3614148450101743}} {"text": "open import Nat\nopen import Prelude\nopen import core\nopen import contexts\n\nopen import progress\nopen import preservation\nopen import elaborability\nopen import typed-elaboration\n\nmodule continuity where\n -- we take the sensibilty theorem as a postulate; for a proof, refer to\n -- the POPL17 mechanization. we also postulate some glue that allows us\n -- to use our theorems here on the shape of results from that work.\n postulate\n action : Set\n zexp : Set\n _◆ : zexp → hexp\n _⊢_=>_~_~>_=>_ : (Γ : tctx) → (e1 : zexp) → (t1 : htyp)\n → (α : action) → (e2 : zexp) → (t2 : htyp) → Set\n sensibility : {Γ : tctx} {e e' : zexp} {τ τ' : htyp} {α : action} →\n Γ ⊢ (e ◆) => τ →\n Γ ⊢ e => τ ~ α ~> e' => τ' →\n Γ ⊢ (e' ◆) => τ'\n binders-unique-h : hexp → Set\n binders-unique-z : zexp → Set\n binders-unique-cursor1 : ∀{e} → binders-unique-z e → binders-unique-h (e ◆)\n binders-unique-cursor2 : ∀{e} → binders-unique-h (e ◆) → binders-unique-z e\n binders-unique-sensibility : {Γ : tctx} {e e' : zexp} {τ τ' : htyp} {α : action} →\n binders-unique-z e →\n Γ ⊢ e => τ ~ α ~> e' => τ' →\n binders-unique-z e'\n expansion-unique : ∀{Γ e τ d Δ} →\n binders-unique-h e →\n Γ ⊢ e ⇒ τ ~> d ⊣ Δ →\n binders-unique d\n\n\n continuity : ∀{ e τ α e' τ' }\n → binders-unique-z e\n → ∅ ⊢ (e ◆) => τ\n → ∅ ⊢ e => τ ~ α ~> e' => τ'\n → Σ[ Δ ∈ hctx ] Σ[ d ∈ ihexp ]\n ( ∅ ⊢ (e' ◆) ⇒ τ' ~> d ⊣ Δ\n × Δ , ∅ ⊢ d :: τ'\n × ( (Σ[ d' ∈ ihexp ]( d ↦ d' × Δ , ∅ ⊢ d' :: τ' ))\n + d boxedval\n + d indet\n )\n )\n continuity bu wt action with sensibility wt action\n ... | sense with elaborability-synth sense\n ... | d , Δ , exp with typed-elaboration-synth exp\n ... | d::τ' with progress d::τ'\n ... | (S (d' , stp)) = Δ , d , exp , d::τ' , Inl (d' , stp , preservation (expansion-unique (binders-unique-cursor1 (binders-unique-sensibility bu action)) exp) d::τ' stp)\n ... | (I ind) = Δ , d , exp , d::τ' , Inr (Inr ind)\n ... | (BV boxed) = Δ , d , exp , d::τ' , Inr (Inl boxed)\n", "meta": {"hexsha": "5e799f58d0519454009394fa94aedb9823cea24b", "size": 2324, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "continuity.agda", "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_issues_repo_path": "continuity.agda", "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_forks_repo_path": "continuity.agda", "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "avg_line_length": 40.0689655172, "max_line_length": 174, "alphanum_fraction": 0.4737521515, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.48047867804790695, "lm_q1q2_score": 0.3613260073155115}} {"text": "-- Andreas, 2017-08-10, issue #2667, reported by xekoukou,\n-- test case by gallais\n\n-- {-# OPTIONS -v tc.with.split:40 #-}\n\ndata Bot : Set where\n\ndata A : Set where\n s : A → A\n\ndata P : A → Set where\n p : ∀ {a} → P (s a)\n\npoo : ∀{b} → P b → Set\npoo p with Bot\npoo {b = s c} p | _ = P c\n\n-- Error WAS (2.5.3): Panic, unbound variable c\n\n-- Expected (as in 2.5.2):\n--\n-- Inaccessible (dotted) patterns from the parent clause must also be\n-- inaccessible in the with clause, when checking the pattern {b = s c},\n-- when checking that the clause\n-- poo p with Bot\n-- poo {b = s c} p | _ = P c\n-- has type {b : A} → P b → Set\n\n-- Ideally: succeed.\n\n-- 2018-01-05, Jesper: We're one step closer to an ideal world.\n", "meta": {"hexsha": "f95ba8c7da9c7486b043c674dc6b9768aae9fe1f", "size": 711, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue2667.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue2667.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue2667.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 22.21875, "max_line_length": 72, "alphanum_fraction": 0.6090014065, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3612269605789466}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\n\nmodule homotopy.FiberOfWedgeToProduct {i j} (X : Ptd i) (Y : Ptd j) where\n\n private\n X⊙×Y = X ⊙× Y\n\n private\n to-glue-template : ∀ {x y}\n {p p' : (pt X , pt Y) == (x , y)}\n (q : p == p' [ (λ w → ∨-to-× w == (x , y)) ↓ wglue ])\n → jright (snd×= p) == jleft (fst×= p') :> (pt X == x) * (pt Y == y)\n to-glue-template {p = p} {p' = p'} q =\n ! (jglue (fst×= p) (snd×= p)) ∙' ap (jleft ∘ fst×=) (↓-∨to×=cst-out q)\n\n module To (x : de⊙ X) (y : de⊙ Y) = WedgeElim\n {P = λ x∨y → ∨-to-× x∨y == (x , y) → (pt X == x) * (pt Y == y)}\n (λ x p → jright (snd×= p)) (λ y p → jleft (fst×= p))\n (↓-app→cst-in to-glue-template)\n\n to : ∀ x y → hfiber ∨-to-× (x , y) → (pt X == x) * (pt Y == y)\n to x y = uncurry (To.f x y)\n\n private\n -- the only needed β-rule for [to] applied to [wglue].\n abstract\n to-glue-idp-β : ap (to (pt X) (pt Y)) (pair= wglue (↓-∨to×=cst-in idp))\n == ! (jglue idp idp)\n to-glue-idp-β =\n split-ap2 (to _ _) wglue (↓-∨to×=cst-in idp)\n ∙ ap (λ p → ↓-app→cst-out p (↓-∨to×=cst-in idp)) (To.glue-β _ _)\n ∙ ↓-app→cst-β to-glue-template (↓-∨to×=cst-in idp)\n ∙ ap (λ p → ! (jglue idp idp) ∙' ap (left ∘ fst×=) p) (↓-∨to×=cst-β idp)\n\n private\n from-glue-template : ∀ {x y} (x-path : pt X == x) (y-path : pt Y == y)\n → (winr y , pair×= x-path idp) == (winl x , pair×= idp y-path)\n :> hfiber ∨-to-× (x , y)\n from-glue-template idp idp = ! $ pair= wglue (↓-∨to×=cst-in idp)\n\n module From (x : de⊙ X) (y : de⊙ Y) = JoinRec\n {C = hfiber ∨-to-× (x , y)}\n (λ x-path → winr y , pair×= x-path idp)\n (λ y-path → winl x , pair×= idp y-path)\n from-glue-template\n\n from : ∀ x y → (pt X == x) * (pt Y == y) → hfiber ∨-to-× (x , y)\n from = From.f\n\n private\n abstract\n to-from-glue-template : ∀ {x y} (x-path : pt X == x) (y-path : pt Y == y)\n → ap left (fst×=-β x-path idp) == ap right (snd×=-β idp y-path)\n [ (λ j → to x y (from x y j) == j) ↓ jglue x-path y-path ]\n to-from-glue-template idp idp = ↓-∘=idf-in' (to _ _) (from _ _) $\n ap (ap (to _ _)) (From.glue-β _ _ idp idp)\n ∙ ap-! (to _ _) (pair= wglue (↓-∨to×=cst-in idp))\n ∙ ap ! to-glue-idp-β\n ∙ !-! (jglue idp idp)\n\n to-from : ∀ x y j → to x y (from x y j) == j\n to-from x y = Join-elim\n {P = λ j → to x y (from x y j) == j}\n (λ x-path → ap left (fst×=-β x-path idp))\n (λ y-path → ap right (snd×=-β idp y-path))\n to-from-glue-template\n\n private\n abstract\n from-to-winl-template : ∀ {x x' y} (xy-path : (x' , pt Y) == (x , y))\n → (winl x , pair×= idp (snd×= xy-path)) == (winl x' , xy-path)\n :> hfiber (∨-to-× {X = X} {Y = Y}) (x , y)\n from-to-winl-template idp = idp\n\n from-to-winr-template : ∀ {x y y'} (xy-path : (pt X , y') == (x , y))\n → (winr y , pair×= (fst×= xy-path) idp) == (winr y' , xy-path)\n :> hfiber (∨-to-× {X = X} {Y = Y}) (x , y)\n from-to-winr-template idp = idp\n\n -- this version enables path induction on [q] which\n -- turns *both* [p] and [p'] into [idp]. yay!\n from-to-glue-template' : ∀ {x y}\n (p p' : (pt X , pt Y) == (x , y)) (q : p == p')\n → from-to-winl-template p == from-to-winr-template p'\n [ (λ xy → from x y (to x y xy) == xy) ↓ pair= wglue (↓-∨to×=cst-in q) ]\n from-to-glue-template' idp .idp idp =\n ↓-∘=idf-in' (from (pt X) (pt Y)) (to (pt X) (pt Y)) $\n ap (ap (from _ _)) to-glue-idp-β\n ∙ ap-! (from _ _) (jglue idp idp)\n ∙ ap ! (From.glue-β _ _ idp idp)\n ∙ !-! (pair= wglue (↓-∨to×=cst-in idp))\n\n from-to-glue-template : ∀ {x y}\n (p p' : (pt X , pt Y) == (x , y))\n (q : p == p' [ (λ w → ∨-to-× w == (x , y)) ↓ wglue ])\n → from-to-winl-template p == from-to-winr-template p'\n [ (λ xy → from x y (to x y xy) == xy) ↓ pair= wglue q ]\n from-to-glue-template {x} {y} p p' q =\n transport\n (λ q →\n from-to-winl-template p == from-to-winr-template p'\n [ (λ xy → from x y (to x y xy) == xy) ↓ pair= wglue q ])\n (↓-∨to×=cst-η q) \n (from-to-glue-template' p p' (↓-∨to×=cst-out q))\n\n from-to : ∀ x y hf → from x y (to x y hf) == hf\n from-to x y = uncurry $ Wedge-elim\n {P = λ w → ∀ p → from x y (To.f x y w p) == (w , p)}\n (λ x → from-to-winl-template)\n (λ y → from-to-winr-template)\n (↓-Π-in λ {p} {p'} → from-to-glue-template p p')\n\n fiber-thm : ∀ x y → hfiber ∨-to-× (x , y) ≃ (pt X == x) * (pt Y == y)\n fiber-thm x y = equiv (to x y) (from x y) (to-from x y) (from-to x y)\n", "meta": {"hexsha": "9e979386e976693ed0b7d507111f4b877a023a6c", "size": 4709, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/FiberOfWedgeToProduct.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/homotopy/FiberOfWedgeToProduct.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/homotopy/FiberOfWedgeToProduct.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 40.2478632479, "max_line_length": 81, "alphanum_fraction": 0.4595455511, "num_tokens": 1963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850402140659, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.3611619244293346}} {"text": "module TestsTransport where\n\nopen import Function\nopen import Data.Product\nopen import Relation.Binary.PropositionalEquality as P\nopen ≡-Reasoning\n\nopen import Isomorphisms\nopen import Tests\n\nFoo : (A : Set) → (T : Testable A) →\n (x y : A) → (φ : Test T) → Set\nFoo A T x y ⊤ =\n _⊨_ {A} {T} x ⊤ ≡ _⊨_ {A} {T} y ⊤\nFoo A T x y ⊥ =\n _⊨_ {A} {T} x ⊥ ≡ _⊨_ {A} {T} y ⊥\nFoo A T x y (nonTriv nt) = sat≡ (kind T) (subT nt) (obs T)\n where\n sat≡ : (k : Kind) → SubTests T k → (A → ObsTy (index T) (parts T) k) → Set\n sat≡ ind φs o =\n cotuple (λ i y → y ⊨ app φs i) (o x)\n ≡ cotuple (λ i y → y ⊨ app φs i) (o y)\n sat≡ coind (i , φ) o =\n app (o x) i ⊨ φ ≡ app (o y) i ⊨ φ\n\n-- Note: Maybe Reveal_is_ can help to match on (kind T)??\n\n{-\n≃-transport : {A B : Set} → {T : Testable A} → (I : Iso A B) →\n (x y : A) → x ≃〈 T 〉 y →\n (Iso.iso I x) ≃〈 iso-testable T I 〉 (Iso.iso I y)\n≃-transport {A} {B} {T₁} I x y p = record { eqProof = q }\n where\n T₂ = iso-testable T₁ I\n f : A → B\n f = Iso.iso I\n g : B → A\n g = IsIso.inv (Iso.indeedIso I)\n o₁ = obs T₁\n o₂ = obs T₂\n lem : (a : A) → (o₂ ∘ f) a ≡ o₁ a\n lem a =\n begin\n (o₂ ∘ f) a\n ≡⟨ refl ⟩\n (o₁ ∘ g ∘ f) a\n ≡⟨ cong (λ x₁ → o₁ x₁) (IsIso.isLeftInv (Iso.indeedIso I) a) ⟩\n o₁ a\n ∎\n q : (φ : Test T₂) → f x ⊨ φ ≡ f y ⊨ φ\n q ⊤ = refl\n q ⊥ = refl\n q (nonTriv (nonTrivTest t)) =\n begin\n sat (kind T₂) t (o₂ (f x))\n ≡⟨ cong (λ u → sat (kind T₂) t u) (lem x) ⟩\n sat (kind T₂) t (o₁ x)\n ≡⟨ sat≡ (index T₁) (parts T₁) (kind T₁)\n o₂ (obsIso T₂) (partsTestable T₁) o₁ (obsIso T₁) lem p t ⟩\n sat (kind T₂) t (o₁ y)\n ≡⟨ cong (λ u → sat (kind T₂) t u) (sym $ lem y) ⟩\n sat (kind T₂) t (o₂ (f y))\n ∎\n where\n -- Agda complains at this point that\n -- T₁ != record { index = index T₁ ; parts = parts T₁ ; kind = kind T₁\n -- ; obs = obs T₁ ; obsIso = obsIso T₁\n -- ; partsTestable = partsTestable T₁}\n -- ...\n -- Is it possible to circumvent this issue?\n\n sat≡ : (Idx : Set) → (P : Idx → Set) → (k : Kind) →\n (o₂ : B → ObsTy Idx P k) → (isoT₂ : IsIso o₂) →\n (pTestable : (i : Idx) → Testable (P i)) →\n (o₁ : A → ObsTy Idx P k) → (isoT₁ : IsIso o₁) →\n ((a : A) → (o₂ ∘ f) a ≡ o₁ a) →\n x ≃〈 record\n { index = Idx\n ; parts = P\n ; kind = k\n ; obs = o₁\n ; obsIso = isoT₁\n ; partsTestable = pTestable\n } 〉 y →\n (t' : SubTests\n ( record\n { index = Idx ; parts = P ; kind = k ; obs = o₂\n ; obsIso = isoT₂ ; partsTestable = pTestable }) k ) →\n sat k t' (o₁ x) ≡ sat k t' (o₁ y)\n sat≡ = {!!}\n-}\n\n{-\n≃-transport {A} {B} {T₁} I x y p =\n q (index T₁) (parts T₁) (kind T₁) (obs T₂) (obsIso T₂) (partsTestable T₁)\n (obs T₁) (obsIso T₁) lem {!!}\n -- Agda complains at this point that\n -- T₁ != record { index = index T₁ ; parts = parts T₁ ; kind = kind T₁\n -- ; obs = obs T₁ ; obsIso = obsIso T₁\n -- ; partsTestable = partsTestable T₁}\n -- ...\n -- Is it possible to circumvent this issue?\n where\n T₂ = iso-testable T₁ I\n f : A → B\n f = Iso.iso I\n g : B → A\n g = IsIso.inv (Iso.indeedIso I)\n o₁ = obs T₁\n o₂ = obs T₂\n lem : (a : A) → (o₂ ∘ f) a ≡ o₁ a\n lem a =\n begin\n (o₂ ∘ f) a\n ≡⟨ refl ⟩\n (o₁ ∘ g ∘ f) a\n ≡⟨ cong (λ x₁ → o₁ x₁) (IsIso.isLeftInv (Iso.indeedIso I) a) ⟩\n o₁ a\n ∎\n\n q : (Idx : Set) → (P : Idx → Set) → (k : Kind) →\n (o₂ : B → ObsTy Idx P k) → (isoT₂ : IsIso o₂) →\n (pTestable : (i : Idx) → Testable (P i)) →\n (o₁ : A → ObsTy Idx P k) → (isoT₁ : IsIso o₁) →\n ((a : A) → (o₂ ∘ f) a ≡ o₁ a) →\n x ≃〈 record\n { index = Idx\n ; parts = P\n ; kind = k\n ; obs = o₁\n ; obsIso = isoT₁\n ; partsTestable = pTestable\n } 〉 y →\n f x ≃〈 record\n { index = Idx\n ; parts = P\n ; kind = k\n ; obs = o₂\n ; obsIso = isoT₂\n ; partsTestable = pTestable\n } 〉\n f y\n q Idx P ind o₂ isoT₂ pTestable o₁ isoT₁ lem p = record { eqProof = qi }\n where\n T₁' = record\n { index = Idx ; parts = P ; kind = ind\n ; obs = o₁ ; obsIso = isoT₁ ; partsTestable = pTestable }\n T₂' = record\n { index = Idx ; parts = P ; kind = ind\n ; obs = o₂ ; obsIso = isoT₂ ; partsTestable = pTestable }\n qi : (φ : Test T₂') → f x ⊨ φ ≡ f y ⊨ φ\n qi ⊤ = refl\n qi ⊥ = refl\n qi (nonTriv (nonTrivTest φs)) =\n begin\n cotuple (λ i z → z ⊨ app φs i) (o₂ (f x))\n ≡⟨ cong (λ u → cotuple (λ i z → z ⊨ app φs i) u) (lem x) ⟩\n cotuple (λ i z → z ⊨ app φs i) (o₁ x)\n ≡⟨ refl ⟩\n _⊨_ {A} {T₁'} x (nonTriv (nonTrivTest φs))\n ≡⟨ eqProof p (nonTriv (nonTrivTest φs)) ⟩\n _⊨_ {A} {T₁'} y (nonTriv (nonTrivTest φs))\n ≡⟨ refl ⟩\n cotuple (λ i z → z ⊨ app φs i) (o₁ y)\n ≡⟨ cong (λ u → cotuple (λ i z → z ⊨ app φs i) u) (sym $ lem y) ⟩\n cotuple (λ i z → z ⊨ app φs i) (o₂ (f y))\n ∎\n q Idx P coind o₂ isoT₂ pTestable o₁ isoT₁ lem p = record { eqProof = qc }\n where\n T₁' = record\n { index = Idx ; parts = P ; kind = coind\n ; obs = o₁ ; obsIso = isoT₁ ; partsTestable = pTestable }\n T₂' = record\n { index = Idx ; parts = P ; kind = coind\n ; obs = o₂ ; obsIso = isoT₂ ; partsTestable = pTestable }\n qc : (φ : Test T₂') → f x ⊨ φ ≡ f y ⊨ φ\n qc ⊤ = refl\n qc ⊥ = refl\n qc (nonTriv (nonTrivTest (i , φ))) =\n begin\n app (o₂ (f x)) i ⊨ φ\n ≡⟨ cong (λ u → app u i ⊨ φ) (lem x) ⟩\n app (o₁ x) i ⊨ φ\n ≡⟨ {!!} ⟩\n app (o₁ y) i ⊨ φ\n ≡⟨ cong (λ u → app u i ⊨ φ) (sym $ lem y) ⟩\n app (o₂ (f y)) i ⊨ φ\n ∎\n-}\n", "meta": {"hexsha": "9cedbfc7636c5f9f7c5012a4b0db139489afaa2e", "size": 6381, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "OTTTests/TestsTransport.agda", "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "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": "OTTTests/TestsTransport.agda", "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "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": "OTTTests/TestsTransport.agda", "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "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": 33.5842105263, "max_line_length": 78, "alphanum_fraction": 0.4220341639, "num_tokens": 2482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.705785040214066, "lm_q2_score": 0.5117166047041652, "lm_q1q2_score": 0.36116192442933454}} {"text": "{-# OPTIONS --cubical --safe #-}\n\nmodule FreeReader where\n\nopen import Cubical.Core.Everything\nopen import Cubical.Foundations.Prelude\nopen import Function.Base using (id; _$_)\n\nopen import Class\nopen Functor\n\nvariable\n A B C : Set\n\n-- The Reader monad, as a free monad\ndata FreeReader (R : Set) : Set → Set₁ where\n Pure : A → FreeReader R A\n Bind : FreeReader R A → (A → FreeReader R B) → FreeReader R B\n Ask : FreeReader R R\n\n -- Monad laws\n LeftId : ∀ {A B}\n → (a : A)\n → (f : A → FreeReader R B)\n → Bind (Pure a) f ≡ f a\n RightId : ∀ {A}\n → (m : FreeReader R A)\n → Bind m Pure ≡ m\n Assoc : ∀ {A B C}\n → (m : FreeReader R A)\n → (f : A → FreeReader R B)\n → (g : B → FreeReader R C)\n → Bind (Bind m f) g ≡ Bind m (λ x → Bind (f x) g)\n\nfreereader-functor : ∀ {R} → Functor (FreeReader R)\nfreereader-functor .fmap f m = Bind m (Pure ∘ f)\nfreereader-functor .fmap-id-legit m i = RightId m i\nfreereader-functor .fmap-compose-legit m f g i\n = hcomp (λ j → λ { (i = i0) → Bind m (Pure ∘ f ∘ g)\n ; (i = i1) → Assoc m (Pure ∘ g) (Pure ∘ f) (~ j)\n })\n (Bind m (λ x → LeftId (g x) (Pure ∘ f) (~ i)))\n\n\nfreereader-ap : ∀ {R} → Applicative (FreeReader R)\nfreereader-ap .Applicative.functor = freereader-functor\nfreereader-ap .Applicative.pure = Pure\nfreereader-ap .Applicative._<*>_ mf m = Bind mf (λ f → Bind m (Pure ∘ f))\nfreereader-ap .Applicative.app-identity v i\n = hcomp (λ j → λ { (i = i0) → LeftId id (λ f → Bind v (Pure ∘ f)) (~ j)\n ; (i = i1) → v\n })\n (RightId v i)\nfreereader-ap .Applicative.app-compose u v w\n -- For some reason, Agda doesn't like wildcards in cubical proofs. Oh well.\n = Pure _∘_ <*> u <*> v <*> w\n ≡[ i ]⟨ LeftId _∘_ (λ f → Bind u (Pure ∘ f)) i <*> v <*> w ⟩\n Bind u (λ u' → Pure (u' ∘_)) <*> v <*> w\n ≡[ i ]⟨ Assoc u (λ u' → Pure (u' ∘_)) (λ f → Bind v (Pure ∘ f)) i <*> w ⟩\n Bind u (λ u' → Bind (Pure (u' ∘_)) (λ c → Bind v (Pure ∘ c))) <*> w\n ≡[ i ]⟨ Bind u (λ u' → LeftId (u' ∘_) (λ c → Bind v (Pure ∘ c)) i) <*> w ⟩\n Bind u (λ u' → Bind v (λ v' → Pure (u' ∘ v'))) <*> w\n ≡[ i ]⟨ Assoc u (λ u' → Bind v (λ v' → Pure (u' ∘ v'))) (λ f → Bind w (Pure ∘ f)) i ⟩\n Bind u (λ u' → Bind (Bind v (λ v' → Pure (u' ∘ v'))) (λ f → Bind w (Pure ∘ f)))\n ≡[ i ]⟨ Bind u (λ u' → Assoc v (λ v' → Pure (u' ∘ v')) (λ f → Bind w (Pure ∘ f)) i) ⟩\n Bind u (λ u' → Bind v (λ v' → Bind (Pure (u' ∘ v')) (λ f → Bind w (Pure ∘ f))))\n ≡[ i ]⟨ Bind u (λ u' → Bind v (λ v' → LeftId (u' ∘ v') (λ f → Bind w (Pure ∘ f)) i)) ⟩\n Bind u (λ u' → Bind v (λ v' → Bind w (Pure ∘ u' ∘ v')))\n ≡[ i ]⟨ Bind u (λ u' → Bind v (λ v' → Bind w (λ w' → LeftId (v' w') (Pure ∘ u') (~ i)))) ⟩\n Bind u (λ u' → Bind v (λ v' → Bind w (λ w' → Bind (Pure (v' w')) (Pure ∘ u'))))\n ≡[ i ]⟨ Bind u (λ u' → Bind v (λ v' → Assoc w (Pure ∘ v') (Pure ∘ u') (~ i))) ⟩\n Bind u (λ u' → Bind v (λ v' → Bind (Bind w (Pure ∘ v')) (Pure ∘ u')))\n ≡[ i ]⟨ Bind u (λ u' → Assoc v (λ f → Bind w (Pure ∘ f)) (Pure ∘ u') (~ i)) ⟩\n Bind u (λ u' → Bind (Bind v (λ v' → Bind w (Pure ∘ v'))) (Pure ∘ u'))\n ∎\n where open Applicative freereader-ap\nfreereader-ap .Applicative.app-homo f x\n = LeftId f (λ f' → Bind (Pure x) (λ x' → Pure (f' x')))\n ∙ LeftId x (λ x' → Pure (f x'))\nfreereader-ap .Applicative.app-intchg u y\n -- u <*> pure y\n = Bind u (λ u' → Bind (Pure y) (Pure ∘ u'))\n ≡[ i ]⟨ Bind u (λ u' → LeftId y (Pure ∘ u') i) ⟩\n Bind u (λ u' → Pure (u' y))\n ≡[ i ]⟨ LeftId (_$ y) (λ f → Bind u (Pure ∘ f)) (~ i) ⟩\n Bind (Pure (_$ y)) (λ _y' → Bind u (λ u' → Pure (u' y')))\n -- pure (_$ y) <*> u\n ∎\n\nfreereader-monad : ∀ {R} → Monad (FreeReader R)\nfreereader-monad .Monad.applicative = freereader-ap\nfreereader-monad .Monad._>>=_ = Bind\nfreereader-monad .Monad.monad-left-id = LeftId\nfreereader-monad .Monad.monad-right-id = RightId\nfreereader-monad .Monad.monad-assoc = Assoc\n", "meta": {"hexsha": "8f033d6bccad762471b58981c5dc5a66b16657e0", "size": 4031, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "FreeReader.agda", "max_stars_repo_name": "mb64/cubical-free-monads", "max_stars_repo_head_hexsha": "13364fa4af25720bf1d73bf960e8c04ebb34762f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-17T17:53:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-17T17:53:44.000Z", "max_issues_repo_path": "FreeReader.agda", "max_issues_repo_name": "mb64/cubical-free-monads", "max_issues_repo_head_hexsha": "13364fa4af25720bf1d73bf960e8c04ebb34762f", "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": "FreeReader.agda", "max_forks_repo_name": "mb64/cubical-free-monads", "max_forks_repo_head_hexsha": "13364fa4af25720bf1d73bf960e8c04ebb34762f", "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": 41.9895833333, "max_line_length": 92, "alphanum_fraction": 0.5026048127, "num_tokens": 1598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.36116191809579024}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import homotopy.HSpace renaming (HSpaceStructure to HSS)\nimport homotopy.WedgeExtension as WedgeExt\n\nmodule homotopy.Pi2HSusp {i} {X : Ptd i} {{_ : has-level 1 (de⊙ X)}}\n {{_ : is-connected 0 (de⊙ X)}} (H-X : HSS X)\n where\n\n {- TODO this belongs somewhere else, but where? -}\n private\n Type=-ext : ∀ {i} {A B : Type i} (p q : A == B)\n → (coe p ∼ coe q) → p == q\n Type=-ext p q α =\n ! (ua-η p)\n ∙ ap ua (Subtype=-out is-equiv-prop (λ= α))\n ∙ ua-η q\n\n module μ = ConnectedHSpace H-X\n μ = μ.μ\n private\n A = de⊙ X\n e = pt X\n\n P : Susp A → Type i\n P x = Trunc 1 (north == x)\n\n module Codes = SuspRec A A (λ a → ua (μ.r-equiv a))\n\n Codes : Susp A → Type i\n Codes = Codes.f\n\n Codes-level : (x : Susp A) → has-level 1 (Codes x)\n Codes-level = Susp-elim ⟨⟩ ⟨⟩\n (λ _ → prop-has-all-paths-↓)\n\n encode'₀ : {x : Susp A} → (north == x) → Codes x\n encode'₀ α = transport Codes α e\n\n encode' : {x : Susp A} → P x → Codes x\n encode' {x} = Trunc-rec {{Codes-level x}} encode'₀\n\n import homotopy.SuspAdjointLoop as SAL\n {- This should be [[_] ∘ η] where [η] is the functor in SuspAdjointLoop.agda -}\n decodeN' : A → P north\n decodeN' = [_] ∘ fst (SAL.η X)\n\n abstract\n transport-Codes-mer : (a a' : A)\n → transport Codes (merid a) a' == μ a a'\n transport-Codes-mer a a' =\n coe (ap Codes (merid a)) a'\n =⟨ Codes.merid-β a |in-ctx (λ w → coe w a') ⟩\n coe (ua (μ.r-equiv a)) a'\n =⟨ coe-β (μ.r-equiv a) a' ⟩\n μ a a' ∎\n\n transport-Codes-mer-e-! : (a : A)\n → transport Codes (! (merid e)) a == a\n transport-Codes-mer-e-! a =\n coe (ap Codes (! (merid e))) a\n =⟨ ap-! Codes (merid e) |in-ctx (λ w → coe w a) ⟩\n coe (! (ap Codes (merid e))) a\n =⟨ Codes.merid-β e |in-ctx (λ w → coe (! w) a) ⟩\n coe (! (ua (μ.r-equiv e))) a\n =⟨ Type=-ext (ua (μ.r-equiv e)) idp (λ x → coe-β _ x ∙ μ.unit-l x)\n |in-ctx (λ w → coe (! w) a) ⟩\n coe (! idp) a ∎\n\n abstract\n encode'-decodeN' : (a : A) → encode' (decodeN' a) == a\n encode'-decodeN' a =\n transport Codes (merid a ∙ ! (merid e)) e\n =⟨ transp-∙ {B = Codes} (merid a) (! (merid e)) e ⟩\n transport Codes (! (merid e)) (transport Codes (merid a) e)\n =⟨ transport-Codes-mer a e ∙ μ.unit-r a\n |in-ctx (λ w → transport Codes (! (merid e)) w) ⟩\n transport Codes (! (merid e)) a\n =⟨ transport-Codes-mer-e-! a ⟩\n a ∎\n\n abstract\n homomorphism : (a a' : A)\n → Path {A = Trunc 1 (north == south)}\n [ merid (μ a a' ) ] [ merid a' ∙ ! (merid e) ∙ merid a ]\n homomorphism = WedgeExt.ext args\n where\n args : WedgeExt.args {a₀ = e} {b₀ = e}\n args = record {m = -1; n = -1;\n P = λ a a' → (_ , ⟨⟩);\n f = λ a → ap [_] $\n merid (μ a e)\n =⟨ ap merid (μ.unit-r a) ⟩\n merid a\n =⟨ ap (λ w → w ∙ merid a) (! (!-inv-r (merid e)))\n ∙ ∙-assoc (merid e) (! (merid e)) (merid a) ⟩\n merid e ∙ ! (merid e) ∙ merid a ∎;\n g = λ a' → ap [_] $\n merid (μ e a')\n =⟨ ap merid (μ.unit-l a') ⟩\n merid a'\n =⟨ ! (∙-unit-r (merid a'))\n ∙ ap (λ w → merid a' ∙ w) (! (!-inv-l (merid e))) ⟩\n merid a' ∙ ! (merid e) ∙ merid e ∎ ;\n p = ap (λ {(p₁ , p₂) → ap [_] $\n merid (μ e e) =⟨ p₁ ⟩\n merid e =⟨ p₂ ⟩\n merid e ∙ ! (merid e) ∙ merid e ∎})\n (pair×= (ap (λ x → ap merid x) (! μ.coh)) (coh (merid e)))}\n where coh : {B : Type i} {b b' : B} (p : b == b')\n → ap (λ w → w ∙ p) (! (!-inv-r p)) ∙ ∙-assoc p (! p) p\n == ! (∙-unit-r p) ∙ ap (λ w → p ∙ w) (! (!-inv-l p))\n coh idp = idp\n\n decode' : {x : Susp A} → Codes x → P x\n decode' {x} = Susp-elim {P = λ x → Codes x → P x}\n decodeN'\n (λ a → [ merid a ])\n (λ a → ↓-→-from-transp (λ= $ STS a))\n x\n where\n abstract\n STS : (a a' : A) → transport P (merid a) (decodeN' a')\n == [ merid (transport Codes (merid a) a') ]\n STS a a' =\n transport P (merid a) [ merid a' ∙ ! (merid e) ]\n =⟨ transport-Trunc (north ==_) (merid a) _ ⟩\n [ transport (north ==_) (merid a) (merid a' ∙ ! (merid e)) ]\n =⟨ ap [_] (transp-cst=idf {A = Susp A} (merid a) _) ⟩\n [ (merid a' ∙ ! (merid e)) ∙ merid a ]\n =⟨ ap [_] (∙-assoc (merid a') (! (merid e)) (merid a)) ⟩\n [ merid a' ∙ ! (merid e) ∙ merid a ]\n =⟨ ! (homomorphism a a') ⟩\n [ merid (μ a a') ]\n =⟨ ap ([_] ∘ merid) (! (transport-Codes-mer a a')) ⟩\n [ merid (transport Codes (merid a) a') ] ∎\n\n abstract\n decode'-encode' : {x : Susp A} (tα : P x)\n → decode' {x} (encode' {x} tα) == tα\n decode'-encode' {x} = Trunc-elim\n {P = λ tα → decode' {x} (encode' {x} tα) == tα}\n -- FIXME: Agda very slow (looping?) when omitting the next line\n {{λ _ → =-preserves-level Trunc-level}}\n (J (λ y p → decode' {y} (encode' {y} [ p ]) == [ p ])\n (ap [_] (!-inv-r (merid e))))\n\n eq' : Trunc 1 (Ω (⊙Susp X)) ≃ A\n eq' = equiv encode' decodeN' encode'-decodeN' decode'-encode'\n\n ⊙decodeN : ⊙Trunc 1 X ⊙→ ⊙Trunc 1 (⊙Ω (⊙Susp X))\n ⊙decodeN = ⊙Trunc-fmap (SAL.η X)\n\n decodeN : Trunc 1 A → Trunc 1 (Ω (⊙Susp X))\n decodeN = fst ⊙decodeN\n\n encodeN : Trunc 1 (Ω (⊙Susp X)) → Trunc 1 A\n encodeN = [_] ∘ encode' {x = north}\n\n eq : Trunc 1 (Ω (⊙Susp X)) ≃ Trunc 1 A\n eq = encodeN ,\n replace-inverse (snd ((unTrunc-equiv A)⁻¹ ∘e eq'))\n {decodeN}\n (Trunc-elim (λ _ → idp))\n\n ⊙eq : ⊙Trunc 1 (⊙Ω (⊙Susp X)) ⊙≃ ⊙Trunc 1 X\n ⊙eq = ≃-to-⊙≃ eq idp\n\n ⊙eq⁻¹ : ⊙Trunc 1 X ⊙≃ ⊙Trunc 1 (⊙Ω (⊙Susp X))\n ⊙eq⁻¹ = ⊙decodeN , snd (eq ⁻¹)\n\n iso : Ω^S-group 0 (⊙Trunc 1 (⊙Ω (⊙Susp X)))\n ≃ᴳ Ω^S-group 0 (⊙Trunc 1 X)\n iso = Ω^S-group-emap 0 ⊙eq\n\n abstract\n π₂-Susp : πS 1 (⊙Susp X) ≃ᴳ πS 0 X\n π₂-Susp =\n πS 1 (⊙Susp X)\n ≃ᴳ⟨ πS-Ω-split-iso 0 (⊙Susp X) ⟩\n πS 0 (⊙Ω (⊙Susp X))\n ≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso 0 (⊙Ω (⊙Susp X)) ⁻¹ᴳ ⟩\n Ω^S-group 0 (⊙Trunc 1 (⊙Ω (⊙Susp X)))\n ≃ᴳ⟨ iso ⟩\n Ω^S-group 0 (⊙Trunc 1 X)\n ≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso 0 X ⟩\n πS 0 X ≃ᴳ∎\n", "meta": {"hexsha": "b3668b0eb36ffe2bdaea76af5aeae7b6e7565eba", "size": 6395, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/Pi2HSusp.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/homotopy/Pi2HSusp.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/homotopy/Pi2HSusp.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": 33.835978836, "max_line_length": 81, "alphanum_fraction": 0.4630179828, "num_tokens": 2679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7057850154599562, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.36116191176224566}} {"text": "{-# OPTIONS --cubical #-}\n\nopen import Agda.Builtin.Cubical.Path\nopen import Agda.Primitive\nopen import Agda.Primitive.Cubical\nopen import Agda.Builtin.Bool\n\nvariable\n a p : Level\n A : Set a\n P : A → Set p\n x y : A\n\nrefl : x ≡ x\nrefl {x = x} = λ _ → x\n\n\ndata 𝕊¹ : Set where\n base : 𝕊¹\n loop : base ≡ base\n\n\ng : Bool → I → 𝕊¹\ng true i = base\ng false i = loop i\n\n_ : g false i0 ≡ base\n_ = refl\n\n_ : g true i0 ≡ base\n_ = refl\n\n-- non-unique solutions, should not solve either of the metas.\n_ : g _ _ ≡ base\n_ = refl\n\n\nh : Bool → base ≡ base\nh true = \\ _ → base\nh false = loop\n\n_ : h false i0 ≡ base\n_ = refl\n\n_ : h true i0 ≡ base\n_ = refl\n\n-- non-unique solutions, should not solve either of the metas.\n_ : h _ _ ≡ base\n_ = refl\n", "meta": {"hexsha": "79c1c87399724ce2ee0e323724e0892cb2e363d8", "size": 760, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/InjectivityHITs.agda", "max_stars_repo_name": "cagix/agda", "max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_stars_repo_licenses": ["BSD-2-Clause"], "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/InjectivityHITs.agda", "max_issues_repo_name": "cagix/agda", "max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_issues_repo_licenses": ["BSD-2-Clause"], "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/InjectivityHITs.agda", "max_forks_repo_name": "cagix/agda", "max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_forks_repo_licenses": ["BSD-2-Clause"], "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": 14.9019607843, "max_line_length": 62, "alphanum_fraction": 0.5986842105, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548646660543, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3611570346656233}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- A categorical view of Delay\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe --sized-types #-}\n\nmodule Codata.Delay.Categorical where\n\nopen import Codata.Delay\nopen import Function\nopen import Category.Functor\nopen import Category.Applicative\nopen import Category.Monad\nopen import Data.These using (leftMost)\n\nfunctor : ∀ {i ℓ} → RawFunctor {ℓ} (λ A → Delay A i)\nfunctor = record { _<$>_ = λ f → map f }\n\nmodule Sequential where\n\n applicative : ∀ {i ℓ} → RawApplicative {ℓ} (λ A → Delay A i)\n applicative = record\n { pure = now\n ; _⊛_ = λ df da → bind df (λ f → map f da)\n }\n\n applicativeZero : ∀ {i ℓ} → RawApplicativeZero {ℓ} (λ A → Delay A i)\n applicativeZero = record\n { applicative = applicative\n ; ∅ = never\n }\n\n monad : ∀ {i ℓ} → RawMonad {ℓ} (λ A → Delay A i)\n monad = record\n { return = now\n ; _>>=_ = bind\n }\n\n monadZero : ∀ {i ℓ} → RawMonadZero {ℓ} (λ A → Delay A i)\n monadZero = record\n { monad = monad\n ; applicativeZero = applicativeZero\n }\n\nmodule Zippy where\n\n applicative : ∀ {i ℓ} → RawApplicative {ℓ} (λ A → Delay A i)\n applicative = record\n { pure = now\n ; _⊛_ = zipWith id\n }\n\n applicativeZero : ∀ {i ℓ} → RawApplicativeZero {ℓ} (λ A → Delay A i)\n applicativeZero = record\n { applicative = applicative\n ; ∅ = never\n }\n\n alternative : ∀ {i ℓ} → RawAlternative {ℓ} (λ A → Delay A i)\n alternative = record\n { applicativeZero = applicativeZero\n ; _∣_ = alignWith leftMost\n }\n", "meta": {"hexsha": "3762f22361bcacb2502e5b34fe92814753bb52e0", "size": 1679, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Codata/Delay/Categorical.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Codata/Delay/Categorical.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Codata/Delay/Categorical.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 25.4393939394, "max_line_length": 72, "alphanum_fraction": 0.5503275759, "num_tokens": 505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7217432062975978, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3608716031487989}} {"text": "module Context where\n\nopen import Level using (_⊔_)\nopen import Function\nopen import Data.List.Base\n\n-- | `ifix`. Check `docs/fomega/deep-isorecursive/README.md` for details.\n{-# NO_POSITIVITY_CHECK #-}\ndata IFix {ι φ} {I : Set ι} (F : (I -> Set φ) -> I -> Set φ) (i : I) : Set φ where\n Wrap : F (IFix F) i -> IFix F i\n\ninfix 3 _∈_ _⊆_\ninfixl 5 _▻_ _▻▻_ _▶_ _▷_\n\n-- | A context is a snoc-list.\ndata Con {α} (A : Set α) : Set α where\n ε : Con A\n _▻_ : (Γ : Con A) -> A -> Con A\n\n-- | The left fold over a context. Note that for contexts, the left fold is the lazy one,\n-- i.e. it's preferable.\nfoldlᶜ : ∀ {α ρ} {A : Set α} {R : Set ρ} -> (R -> A -> R) -> R -> Con A -> R\nfoldlᶜ f z ε = z\nfoldlᶜ f z (Γ ▻ σ) = f (foldlᶜ f z Γ) σ\n\n-- | Concatenate two contexts.\n_▻▻_ : ∀ {α} {A : Set α} -> Con A -> Con A -> Con A\nΓ ▻▻ Δ = foldlᶜ _▻_ Γ Δ\n{-# DISPLAY foldlᶜ _▻_ Γ Δ = Γ ▻▻ Δ #-}\n\n-- | The right fold over a context. Note that for contexts, the right fold is the strict one,\n-- i.e. it's not preferable.\nfoldrᶜ : ∀ {α ρ} {A : Set α} {R : Set ρ} -> (A -> R -> R) -> R -> Con A -> R\nfoldrᶜ f z ε = z\nfoldrᶜ f z (Γ ▻ σ) = foldrᶜ f (f σ z) Γ\n\n-- | Mapping over a context.\nmapᶜ : ∀ {α β} {A : Set α} {B : Set β} -> (A -> B) -> Con A -> Con B\nmapᶜ f = foldlᶜ (λ Ξ x -> Ξ ▻ f x) ε\n\njoinᶜ : ∀ {α} {A : Set α} -> Con (Con A) -> Con A\njoinᶜ = foldlᶜ _▻▻_ ε\n\nlistToCon : ∀ {α} {A : Set α} -> List A -> Con A\nlistToCon = foldl _▻_ ε\n{-# DISPLAY foldl _▻_ ε = listToCon #-}\n\n-- | A variable is a point in a context.\ndata _∈_ {α} {A : Set α} σ : Con A -> Set where\n vz : ∀ {Γ} -> σ ∈ Γ ▻ σ\n vs_ : ∀ {Γ τ} -> (v : σ ∈ Γ) -> σ ∈ Γ ▻ τ\n\n-- | Expand the context that a variable is defined in, but do not change the variable.\nwkᵛ : ∀ {α} {A : Set α} {Γ Δ : Con A} {σ} -> σ ∈ Δ -> σ ∈ Γ ▻▻ Δ\nwkᵛ vz = vz\nwkᵛ (vs v) = vs (wkᵛ v)\n\n-- | A variable in the middle of a context.\nvsⁿ : ∀ {α} {A : Set α} {Θ : Con A} {σ} Ξ -> σ ∈ Θ ▻ σ ▻▻ Ξ\nvsⁿ ε = vz\nvsⁿ (Ξ ▻ ν) = vs (vsⁿ Ξ)\n\nmapᵛ : ∀ {α β} {A : Set α} {B : Set β} {Γ σ} {f : A -> B} -> σ ∈ Γ -> f σ ∈ mapᶜ f Γ\nmapᵛ vz = vz\nmapᵛ (vs v) = vs (mapᵛ v)\n\n-- -- | Order-preserving embedding. I.e. in `Γ ⊆ Δ` `Δ` contains the same elements as `Γ` and\n-- -- they're in the same order, but there can be additional elements between them.\n-- -- See https://fplab.bitbucket.io/posts/2008-03-07-order-preserving-embeddin.html\n-- data _⊆_ {α} {A : Set α} : Con A -> Con A -> Set where\n-- -- We use this instead of `ε ⊆ ε`, because we this definition we have `idᵒ ∘ᵒ idᵒ ≡ idᵒ`\n-- -- definitionally and this is needed in order to type check some terms with open types.\n-- stop : ∀ {Γ} -> Γ ⊆ Γ\n-- skip : ∀ {Γ Δ σ} -> (ι : Γ ⊆ Δ) -> Γ ⊆ Δ ▻ σ\n-- keep : ∀ {Γ Δ σ} -> (ι : Γ ⊆ Δ) -> Γ ▻ σ ⊆ Δ ▻ σ\n\n_⊆_ : ∀ {α} {A : Set α} -> Con A -> Con A -> Set α\nΓ ⊆ Δ = ∀ {σ} -> σ ∈ Γ -> σ ∈ Δ\n\nstop : ∀ {α} {A : Set α} {Γ : Con A} -> Γ ⊆ Γ\nstop = id\n\ndupl : ∀ {α} {A : Set α} {Γ : Con A} {σ} -> Γ ▻ σ ▻ σ ⊆ Γ ▻ σ\ndupl vz = vz\ndupl (vs v) = v\n\nskip : ∀ {α} {A : Set α} {Γ Δ : Con A} {σ} -> Γ ⊆ Δ -> Γ ⊆ Δ ▻ σ\nskip ι = vs_ ∘ ι\n\nkeep : ∀ {α} {A : Set α} {Γ Δ : Con A} {σ} -> Γ ⊆ Δ -> Γ ▻ σ ⊆ Δ ▻ σ\nkeep ι vz = vz\nkeep ι (vs v) = vs (ι v)\n\nmove : ∀ {α} {A : Set α} {Γ Δ : Con A} {σ} -> Γ ⊆ Δ -> Γ ▻ σ ▻ σ ⊆ Δ ▻ σ\nmove ι vz = vz\nmove ι (vs v) = keep ι v\n\nskipⁿ : ∀ {α} {A : Set α} {Γ Δ : Con A} Ξ -> Γ ⊆ Δ -> Γ ⊆ Δ ▻▻ Ξ\nskipⁿ ε ι = ι\nskipⁿ (Ξ ▻ ν) ι = skip (skipⁿ Ξ ι)\n\nkeepⁿ : ∀ {α} {A : Set α} {Γ Δ : Con A} Ξ -> Γ ⊆ Δ -> Γ ▻▻ Ξ ⊆ Δ ▻▻ Ξ\nkeepⁿ ε ι = ι\nkeepⁿ (Ξ ▻ ν) ι = keep (keepⁿ Ξ ι)\n\nempᵒ : ∀ {α} {A : Set α} {Γ : Con A} -> ε ⊆ Γ\nempᵒ {Γ = ε} = stop\nempᵒ {Γ = Γ ▻ σ} = skip empᵒ\n\n-- | The identity embedding.\nidᵒ : ∀ {α} {A : Set α} {Γ : Con A} -> Γ ⊆ Γ\nidᵒ = stop\n\n-- | The left extension embedding.\nextˡ : ∀ {α} {A : Set α} {Γ Δ : Con A} -> Γ ⊆ Δ ▻▻ Γ\nextˡ {Γ = ε} = empᵒ\nextˡ {Γ = Γ ▻ σ} = keep extˡ\n\n-- | The right extension embedding.\nextʳ : ∀ {α} {A : Set α} {Γ : Con A} Δ -> Γ ⊆ Γ ▻▻ Δ\nextʳ Δ = skipⁿ Δ idᵒ\n\n-- | The one element extension embedding.\ntopᵒ : ∀ {α} {A : Set α} {Γ : Con A} {σ} -> Γ ⊆ Γ ▻ σ\ntopᵒ = extʳ (ε ▻ _)\n\nmapᶜ-⊆ : ∀ {α β} {A : Set α} {B : Set β} {Γ Δ} {f : A -> B} -> Γ ⊆ Δ -> mapᶜ f Γ ⊆ mapᶜ f Δ\nmapᶜ-⊆ {Γ = ε} ι ()\nmapᶜ-⊆ {Γ = Γ ▻ σ} ι vz = mapᵛ (ι vz)\nmapᶜ-⊆ {Γ = Γ ▻ σ} ι (vs v) = mapᶜ-⊆ (ι ∘ vs_) v\n\n-- | Rename a variable.\nrenᵛ : ∀ {α} {A : Set α} {Γ Δ : Con A} {σ} -> Γ ⊆ Δ -> σ ∈ Γ -> σ ∈ Δ\nrenᵛ ι = ι\n\nshiftᵛⁿ : ∀ {α} {A : Set α} {Γ : Con A} {σ} Δ -> σ ∈ Γ -> σ ∈ Γ ▻▻ Δ\nshiftᵛⁿ Δ = renᵛ (extʳ Δ)\n\nshiftᵛ : ∀ {α} {A : Set α} {Γ : Con A} {σ τ} -> σ ∈ Γ -> σ ∈ Γ ▻ τ\nshiftᵛ = shiftᵛⁿ (ε ▻ _)\n\n-- We need both first-order and higher-order environments, because the former are more convenient\n-- for compilation and the latter are more convenient for evaluation at the type level.\n\n-- | In `Seq P Γ` there a `P σ` for each `σ` from `Γ`.\ndata Seq {α π} {A : Set α} (P : A -> Set π) : Con A -> Set π where\n ø : Seq P ε\n _▶_ : ∀ {σ Γ} -> Seq P Γ -> P σ -> Seq P (Γ ▻ σ)\n\n-- We wrap this in `record` in order to get good inference.\n-- | In `Env P Γ` there a `P σ` for each `σ` from `Γ`.\nrecord Env {α π} {A : Set α} (P : A -> Set π) (Γ : Con A) : Set (α ⊔ π) where\n constructor PackEnv\n field unpackEnv : ∀ {σ} -> σ ∈ Γ -> P σ\nopen Env public\n\nfoldlˢ\n : ∀ {α π ρ} {A : Set α} {P : A -> Set π} {Γ}\n -> (R : Con A -> Set ρ) -> (∀ {Ξ σ} -> R Ξ -> P σ -> R (Ξ ▻ σ)) -> R ε -> Seq P Γ -> R Γ\nfoldlˢ R f z ø = z\nfoldlˢ R f z (ρ ▶ α) = f (foldlˢ R f z ρ) α\n\n-- | Apply a natural transformation to each element of a `Seq`.\nmapˢ\n : ∀ {α π₁ π₂} {A : Set α} {P₁ : A -> Set π₁} {P₂ : A -> Set π₂} {Γ}\n -> (∀ {σ} -> P₁ σ -> P₂ σ) -> Seq P₁ Γ -> Seq P₂ Γ\nmapˢ f = foldlˢ (Seq _) (λ ρ x -> ρ ▶ f x) ø\n\nmapElˢ\n : ∀ {α π₁ π₂} {A : Set α} {P₁ : A -> Set π₁} {P₂ : A -> Set π₂} {Γ}\n -> (∀ {σ} -> σ ∈ Γ -> P₁ σ -> P₂ σ) -> Seq P₁ Γ -> Seq P₂ Γ\nmapElˢ f ø = ø\nmapElˢ f (ρ ▶ α) = mapElˢ (f ∘ vs_) ρ ▶ f vz α\n\neraseˢ : ∀ {α π} {A : Set α} {P : Set π} {Γ : Con A} -> Seq (λ _ -> P) Γ -> Con P\neraseˢ = foldlˢ _ _▻_ ε\n\n∅ : ∀ {α π} {A : Set α} {P : A -> Set π} -> Env P ε\n∅ = PackEnv λ()\n\n_▷_ : ∀ {α π} {A : Set α} {Γ σ} {P : A -> Set π} -> Env P Γ -> P σ -> Env P (Γ ▻ σ)\nPackEnv ρ ▷ α = PackEnv λ\n { vz -> α\n ; (vs v) -> ρ v\n }\n\n_∘ᵉ_ : ∀ {α π} {A : Set α} {Γ Δ} {P : A -> Set π} -> Env P Δ -> Γ ⊆ Δ -> Env P Γ\nPackEnv ρ ∘ᵉ ι = PackEnv (ρ ∘ ι)\n\nwithSplitᵉ\n : ∀ {α π ρ} {A : Set α} {Γ σ} {P : A -> Set π} {R : Set ρ}\n -> Env P (Γ ▻ σ) -> (Env P Γ -> P σ -> R) -> R\nwithSplitᵉ (PackEnv ρ) k = k (PackEnv (ρ ∘ vs_)) (ρ vz)\n\nfoldlᵉ\n : ∀ {α π ρ} {A : Set α} {P : A -> Set π} {Γ}\n -> (R : Con A -> Set ρ) -> (∀ {Ξ σ} -> R Ξ -> P σ -> R (Ξ ▻ σ)) -> R ε -> Env P Γ -> R Γ\nfoldlᵉ {Γ = ε} R f z ρ = z\nfoldlᵉ {Γ = Γ ▻ σ} R f z ρ = withSplitᵉ ρ λ ρ′ α -> f (foldlᵉ R f z ρ′) α\n\n-- | Apply a natural transformation to each element of a `Env`.\nmapᵉ\n : ∀ {α π₁ π₂} {A : Set α} {P₁ : A -> Set π₁} {P₂ : A -> Set π₂} {Γ}\n -> (∀ {σ} -> P₁ σ -> P₂ σ) -> Env P₁ Γ -> Env P₂ Γ\nmapᵉ f = foldlᵉ (Env _) (λ ρ x -> ρ ▷ f x) ∅\n\nmapElᵉ\n : ∀ {α π₁ π₂} {A : Set α} {P₁ : A -> Set π₁} {P₂ : A -> Set π₂} {Γ}\n -> (∀ {σ} -> σ ∈ Γ -> P₁ σ -> P₂ σ) -> Env P₁ Γ -> Env P₂ Γ\nmapElᵉ f (PackEnv ρ) = PackEnv λ v -> f v (ρ v)\n\n-- | Look up a variable in an environment.\nlookupᵉ : ∀ {α π} {A : Set α} {P : A -> Set π} {Γ σ} -> σ ∈ Γ -> Env P Γ -> P σ\nlookupᵉ v (PackEnv ρ) = ρ v\n\neraseᵉ : ∀ {α π} {A : Set α} {P : Set π} {Γ : Con A} -> Env (λ _ -> P) Γ -> Con P\neraseᵉ = foldlᵉ _ _▻_ ε\n\nrecord Environment {α β} {A : Set α} (_◆_ : Con A -> A -> Set β) : Set (α ⊔ β) where\n infix 3 _⊢ᵉ_\n\n field\n varᵈ : ∀ {Γ σ} -> σ ∈ Γ -> Γ ◆ σ\n renᵈ : ∀ {Γ Δ σ} -> Γ ⊆ Δ -> Γ ◆ σ -> Δ ◆ σ\n\n idᵉ : ∀ {Γ} -> Env (Γ ◆_) Γ\n idᵉ = PackEnv varᵈ\n\n freshᵉ : ∀ {Γ σ} -> (Γ ▻ σ) ◆ σ\n freshᵉ = varᵈ vz\n\n _⊢ᵉ_ : Con A -> Con A -> Set (α ⊔ β)\n Ξ ⊢ᵉ Θ = Env (λ σ -> Ξ ◆ σ) Θ\n\n renᵉ : ∀ {Δ Ξ Γ} -> Δ ⊆ Ξ -> Δ ⊢ᵉ Γ -> Ξ ⊢ᵉ Γ\n renᵉ ι (PackEnv ρ) = PackEnv $ renᵈ ι ∘ ρ\n\n keepᵉ : ∀ {Δ Γ σ} -> Δ ⊢ᵉ Γ -> Δ ▻ σ ⊢ᵉ Γ ▻ σ\n keepᵉ ρ = renᵉ topᵒ ρ ▷ freshᵉ\n\n topᵉ : ∀ {Γ σ} -> Γ ◆ σ -> Γ ⊢ᵉ Γ ▻ σ\n topᵉ t = idᵉ ▷ t\n\n shiftᵉ : ∀ {Δ Γ τ} -> Δ ⊢ᵉ Γ -> Δ ▻ τ ⊢ᵉ Γ\n shiftᵉ = renᵉ topᵒ\n", "meta": {"hexsha": "75a3d6b691f7aa72363177be3c808be2cbef9640", "size": 8185, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "papers/unraveling-recursion/code/src/Context.agda", "max_stars_repo_name": "AriFordsham/plutus", "max_stars_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1299, "max_stars_repo_stars_event_min_datetime": "2018-10-02T13:41:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T01:10:02.000Z", "max_issues_repo_path": "papers/unraveling-recursion/code/src/Context.agda", "max_issues_repo_name": "AriFordsham/plutus", "max_issues_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2493, "max_issues_repo_issues_event_min_datetime": "2018-09-28T19:28:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T15:31:31.000Z", "max_forks_repo_path": "papers/unraveling-recursion/code/src/Context.agda", "max_forks_repo_name": "AriFordsham/plutus", "max_forks_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 399, "max_forks_repo_forks_event_min_datetime": "2018-10-05T09:36:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T11:18:25.000Z", "avg_line_length": 33.2723577236, "max_line_length": 97, "alphanum_fraction": 0.4785583384, "num_tokens": 4123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.689305616785446, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.36079658646160623}} {"text": "------------------------------------------------------------------------\n-- Parallel reduction in pure type systems (PTS)\n------------------------------------------------------------------------\n\nmodule Pts.Reduction.Parallel where\n\nopen import Data.Fin using (Fin)\nopen import Data.Fin.Substitution\nopen import Data.Fin.Substitution.ExtraLemmas\nopen import Data.Fin.Substitution.Relation\nopen import Data.Star using (Star; ε; _◅_; _◅◅_)\nopen import Data.Product using (_,_; ∃; _×_)\nopen import Data.Nat using (ℕ; _+_)\nopen import Data.Vec.All using (lookup₂)\nimport Function as Fun\nopen import Relation.Binary\nopen import Relation.Binary.EquivalenceClosure using (EqClosure)\nopen import Relation.Binary.SymmetricClosure using (fwd; bwd)\nopen import Relation.Binary.Reduction\nimport Relation.Binary.PropositionalEquality as P\n\nopen import Pts.Syntax\n\n-- All remaining submodules are parametrized by a given set of sorts.\nmodule _ {Sort : Set} where\n open Syntax Sort\n open Substitution Sort using (_[_])\n\n ----------------------------------------------------------------------\n -- Parallel reduction\n\n infixl 9 _·_\n infix 5 _⇛_\n\n -- One-step parallel reduction.\n data _⇛_ {n : ℕ} : Term n → Term n → Set where\n refl : ∀ {a} → a ⇛ a\n Π : ∀ {a₁ a₂ b₁ b₂} → a₁ ⇛ a₂ → b₁ ⇛ b₂ → Π a₁ b₁ ⇛ Π a₂ b₂\n ƛ : ∀ {a₁ a₂ b₁ b₂} → a₁ ⇛ a₂ → b₁ ⇛ b₂ → ƛ a₁ b₁ ⇛ ƛ a₂ b₂\n _·_ : ∀ {a₁ a₂ b₁ b₂} → a₁ ⇛ a₂ → b₁ ⇛ b₂ → a₁ · b₁ ⇛ a₂ · b₂\n cont : ∀ {a b₁ b₂ c₁ c₂} → b₁ ⇛ b₂ → c₁ ⇛ c₂ →\n (ƛ a b₁) · c₁ ⇛ b₂ [ c₂ ]\n\n reduction : Reduction Term\n reduction = record { _→1_ = _⇛_ }\n\n -- Parallel reduction and equivalence.\n open Reduction reduction public renaming (_→*_ to _⇛*_; _↔_ to _≡p_)\n\n\n ----------------------------------------------------------------------\n -- Simple properties of parallel reduction\n\n -- Inclusions.\n ⇛⇒⇛* = →1⇒→* reduction\n ⇛*⇒≡p = →*⇒↔ reduction\n ⇛⇒≡p = →1⇒↔ reduction\n\n -- parallel reduction is a preorder.\n ⇛*-predorder = →*-predorder reduction\n\n -- Terms together with parallel equivalence form a setoid.\n ≡p-setoid = ↔-setoid reduction\n\n open P using (_≡_)\n\n -- Shapes are preserved by one-step parallel reduction.\n\n sort-⇛ : ∀ {n s} {a : Term n} → sort s ⇛ a → sort s ≡ a\n sort-⇛ refl = P.refl\n\n ƛ-⇛ : ∀ {n} {a : Term n} {b c} → ƛ a b ⇛ c →\n ∃ λ a′ → ∃ λ b′ → a ⇛ a′ × b ⇛ b′ × ƛ a′ b′ ≡ c\n ƛ-⇛ refl = _ , _ , refl , refl , P.refl\n ƛ-⇛ (ƛ a⇛a′ b⇛b′) = _ , _ , a⇛a′ , b⇛b′ , P.refl\n\n Π-⇛ : ∀ {n} {a : Term n} {b c} → Π a b ⇛ c →\n ∃ λ a′ → ∃ λ b′ → a ⇛ a′ × b ⇛ b′ × Π a′ b′ ≡ c\n Π-⇛ refl = _ , _ , refl , refl , P.refl\n Π-⇛ (Π a⇛a′ b⇛b′) = _ , _ , a⇛a′ , b⇛b′ , P.refl\n\n -- Shapes are preserved by parallel reduction.\n\n sort-⇛* : ∀ {n s} {a : Term n} → sort s ⇛* a → sort s ≡ a\n sort-⇛* ε = P.refl\n sort-⇛* (refl ◅ s⇛*b) = sort-⇛* s⇛*b\n\n ƛ-⇛* : ∀ {n} {a : Term n} {b c} → ƛ a b ⇛* c →\n ∃ λ a′ → ∃ λ b′ → a ⇛* a′ × b ⇛* b′ × ƛ a′ b′ ≡ c\n ƛ-⇛* ε = _ , _ , ε , ε , P.refl\n ƛ-⇛* (refl ◅ λab⇛*d) = ƛ-⇛* λab⇛*d\n ƛ-⇛* (ƛ a⇛a₁ b⇛b₁ ◅ λa₁b₁⇛*d) =\n let a₂ , b₂ , a₁⇛*a₂ , b₁⇛*b₂ , λa₂b₂≡d = ƛ-⇛* λa₁b₁⇛*d\n in a₂ , b₂ , a⇛a₁ ◅ a₁⇛*a₂ , b⇛b₁ ◅ b₁⇛*b₂ , λa₂b₂≡d\n\n Π-⇛* : ∀ {n} {a : Term n} {b c} → Π a b ⇛* c →\n ∃ λ a′ → ∃ λ b′ → a ⇛* a′ × b ⇛* b′ × Π a′ b′ ≡ c\n Π-⇛* ε = _ , _ , ε , ε , P.refl\n Π-⇛* (refl ◅ Πab⇛*d) = Π-⇛* Πab⇛*d\n Π-⇛* (Π a⇛a₁ b⇛b₁ ◅ Πa₁b₁⇛*d) =\n let a₂ , b₂ , a₁⇛*a₂ , b₁⇛*b₂ , Πa₂b₂≡d = Π-⇛* Πa₁b₁⇛*d\n in a₂ , b₂ , a⇛a₁ ◅ a₁⇛*a₂ , b⇛b₁ ◅ b₁⇛*b₂ , Πa₂b₂≡d\n\n\n ----------------------------------------------------------------------\n -- Substitutions lifted to parallel reduction\n --\n -- The application _/⇛_ below may be considered a substitution\n -- lemma, i.e. it establishes that substitutions of terms preserve\n -- parallel reduction:\n --\n -- ⇛\n -- a ------→ b\n -- | |\n -- -/σ | | -/σ\n -- ↓ ⇛ ↓\n -- a/σ ····→ b/σ\n --\n -- ∀ (a b : Term n) (σ : Sub Term m n).\n\n -- Application of generic substitutions lifted to reduction.\n record ParSubstApp {T₁ T₂} (R : TermRel T₁ T₂)\n (l₁ : Lift T₁ Term) (l₂ : Lift T₂ Term)\n (rl : RelLift R _⇛_ l₁ l₂) : Set where\n infix 10 _↑₂\n infixl 8 _/₁_ _/₂_ _/_ _/⇛_\n\n open Substitution Sort using (termSubst)\n private\n _/₁_ = TermSubst.app termSubst l₁\n _/₂_ = TermSubst.app termSubst l₂\n _↑₂ = Lift._↑ l₂\n open LiftTermRel T₁ T₂ using (_⟨_⟩_)\n open RelLift rl\n open P using (sym; subst)\n\n -- T₂-substitutions commute.\n field /₂-sub-↑ : ∀ {m n b} {σ : Sub T₂ m n} a →\n (a [ b ]) /₂ σ ≡ (a /₂ (σ ↑₂)) [ b /₂ σ ]\n\n _/_ : ∀ {m n} {σ₁ : Sub T₁ m n} {σ₂ : Sub T₂ m n} →\n ∀ a → σ₁ ⟨ R ⟩ σ₂ → a /₁ σ₁ ⇛ a /₂ σ₂\n var x / σ₁∼σ₂ = lift (lookup₂ x σ₁∼σ₂)\n sort s / σ₁∼σ₂ = refl\n Π a b / σ₁∼σ₂ = Π (a / σ₁∼σ₂) (b / σ₁∼σ₂ ↑)\n ƛ a b / σ₁∼σ₂ = ƛ (a / σ₁∼σ₂) (b / σ₁∼σ₂ ↑)\n (a · b) / σ₁∼σ₂ = (a / σ₁∼σ₂) · (b / σ₁∼σ₂)\n\n _/⇛_ : ∀ {m n a₁ a₂} {σ₁ : Sub T₁ m n} {σ₂ : Sub T₂ m n} →\n a₁ ⇛ a₂ → σ₁ ⟨ R ⟩ σ₂ → a₁ /₁ σ₁ ⇛ a₂ /₂ σ₂\n refl {a} /⇛ σ₁∼σ₂ = a / σ₁∼σ₂\n Π a₁⇛a₂ b₁⇛b₂ /⇛ σ₁∼σ₂ = Π (a₁⇛a₂ /⇛ σ₁∼σ₂) (b₁⇛b₂ /⇛ σ₁∼σ₂ ↑)\n ƛ a₁⇛a₂ b₁⇛b₂ /⇛ σ₁∼σ₂ = ƛ (a₁⇛a₂ /⇛ σ₁∼σ₂) (b₁⇛b₂ /⇛ σ₁∼σ₂ ↑)\n a₁⇛a₂ · b₁⇛b₂ /⇛ σ₁∼σ₂ = (a₁⇛a₂ /⇛ σ₁∼σ₂) · (b₁⇛b₂ /⇛ σ₁∼σ₂)\n cont {b₂ = b₂} a₁⇛a₂ b₁⇛b₂ /⇛ σ₁∼σ₂ =\n P.subst (_⇛_ _) (sym (/₂-sub-↑ b₂))\n (cont (a₁⇛a₂ /⇛ σ₁∼σ₂ ↑) (b₁⇛b₂ /⇛ σ₁∼σ₂))\n\n -- Term substitutions lifted to parallel reduction.\n module ParSubstitution where\n open Substitution Sort using (termSubst; sub-commutes; varLiftSubLemmas)\n open P using (_≡_; refl)\n private\n module S = TermSubst termSubst\n module V = VarEqSubst\n\n varLift : RelLift _≡_ _⇛_ S.varLift S.varLift\n varLift = record { simple = V.simple; lift = lift }\n where\n lift : ∀ {n} {x₁ x₂ : Fin n} → x₁ ≡ x₂ → S.var x₁ ⇛ S.var x₂\n lift {x₁ = x} refl = refl\n\n varSubstApp : ParSubstApp _≡_ S.varLift S.varLift varLift\n varSubstApp = record { /₂-sub-↑ = λ a → /-sub-↑ a _ _ }\n where open LiftSubLemmas varLiftSubLemmas\n\n infix 8 _/Var-⇛_\n\n _/Var-⇛_ : ∀ {m n a₁ a₂} {σ₁ σ₂ : Sub Fin m n} →\n a₁ ⇛ a₂ → σ₁ V.⟨≡⟩ σ₂ → (a₁ S./Var σ₁) ⇛ (a₂ S./Var σ₂)\n _/Var-⇛_ = ParSubstApp._/⇛_ varSubstApp\n\n simple : RelSimple _⇛_ S.simple S.simple\n simple = record\n { extension = record { weaken = λ t₁⇛t₂ → t₁⇛t₂ /Var-⇛ V.wk }\n ; var = λ x → refl {a = var x}\n }\n\n termLift : RelLift _⇛_ _⇛_ S.termLift S.termLift\n termLift = record { simple = simple; lift = Fun.id }\n\n termSubstApp : ParSubstApp _⇛_ S.termLift S.termLift termLift\n termSubstApp = record { /₂-sub-↑ = sub-commutes }\n\n open ParSubstApp termSubstApp public\n\n subst : RelSubst _⇛_ S.subst S.subst\n subst = record\n { simple = simple\n ; application = record { _/_ = _/⇛_ }\n }\n\n open LiftTermRel Term Term public using (_⟨_⟩_)\n open RelSubst subst public hiding (var; simple; _/_)\n\n infix 10 _[⇛_]\n\n -- Shorthand for single-variable substitutions lifted to redcution.\n _[⇛_] : ∀ {n} {a₁ : Term (1 + n)} {a₂} {b₁ : Term n} {b₂} →\n a₁ ⇛ a₂ → b₁ ⇛ b₂ → a₁ S./ S.sub b₁ ⇛ a₂ S./ S.sub b₂\n a₁⇛a₂ [⇛ b₁⇛b₂ ] = a₁⇛a₂ /⇛ sub b₁⇛b₂\n\n open ParSubstitution\n\n\n ----------------------------------------------------------------------\n -- Confluence of parallel reduction\n --\n -- Parallel reduction enjoys the single-step diamond property,\n -- i.e. for any pair a ⇛ b₁, a ⇛ b₂ of parallel reductions, there is\n -- a term c, such that\n --\n -- ⇛\n -- a ------→ b₂\n -- | :\n -- ⇛ | : ⇛\n -- ↓ ⇛ ↓\n -- b₁ ·····→ c\n --\n -- commutes. Confluence (aka the Church-Rosser property) then\n -- follows by pasting of diagrams.\n\n infixl 4 _⋄_\n\n -- Diamond property of one-step reduction.\n _⋄_ : ∀ {n} {a b₁ b₂ : Term n} → a ⇛ b₁ → a ⇛ b₂ → ∃ λ c → b₁ ⇛ c × b₂ ⇛ c\n refl ⋄ a⇛b = _ , a⇛b , refl\n a⇛b ⋄ refl = _ , refl , a⇛b\n Π a₁⇛b₁₁ a₂⇛b₁₂ ⋄ Π a₁⇛b₂₁ a₂⇛b₂₂ =\n let c₁ , b₁₁⇛c₁ , b₂₁⇛c₁ = a₁⇛b₁₁ ⋄ a₁⇛b₂₁\n c₂ , b₁₂⇛c₂ , b₂₂⇛c₂ = a₂⇛b₁₂ ⋄ a₂⇛b₂₂\n in Π c₁ c₂ , Π b₁₁⇛c₁ b₁₂⇛c₂ , Π b₂₁⇛c₁ b₂₂⇛c₂\n ƛ a₁⇛b₁₁ a₂⇛b₁₂ ⋄ ƛ a₁⇛b₂₁ a₂⇛b₂₂ =\n let c₁ , b₁₁⇛c₁ , b₂₁⇛c₁ = a₁⇛b₁₁ ⋄ a₁⇛b₂₁\n c₂ , b₁₂⇛c₂ , b₂₂⇛c₂ = a₂⇛b₁₂ ⋄ a₂⇛b₂₂\n in ƛ c₁ c₂ , ƛ b₁₁⇛c₁ b₁₂⇛c₂ , ƛ b₂₁⇛c₁ b₂₂⇛c₂\n a₁⇛b₁₁ · a₂⇛b₁₂ ⋄ a₁⇛b₂₁ · a₂⇛b₂₂ =\n let c₁ , b₁₁⇛c₁ , b₂₁⇛c₁ = a₁⇛b₁₁ ⋄ a₁⇛b₂₁\n c₂ , b₁₂⇛c₂ , b₂₂⇛c₂ = a₂⇛b₁₂ ⋄ a₂⇛b₂₂\n in c₁ · c₂ , b₁₁⇛c₁ · b₁₂⇛c₂ , b₂₁⇛c₁ · b₂₂⇛c₂\n refl · a₂⇛b₁₂ ⋄ cont {b₂ = b₂₁} a₁⇛b₂₁ a₂⇛b₂₂ =\n let c₂ , b₁₂⇛c₂ , b₂₂⇛c₂ = a₂⇛b₁₂ ⋄ a₂⇛b₂₂\n in b₂₁ [ c₂ ] , cont a₁⇛b₂₁ b₁₂⇛c₂ , refl {a = b₂₁} [⇛ b₂₂⇛c₂ ]\n ƛ _ a₁⇛b₁₁ · a₂⇛b₁₂ ⋄ cont a₁⇛b₂₁ a₂⇛b₂₂ =\n let c₁ , b₁₁⇛c₁ , b₂₁⇛c₁ = a₁⇛b₁₁ ⋄ a₁⇛b₂₁\n c₂ , b₁₂⇛c₂ , b₂₂⇛c₂ = a₂⇛b₁₂ ⋄ a₂⇛b₂₂\n in c₁ [ c₂ ] , cont b₁₁⇛c₁ b₁₂⇛c₂ , b₂₁⇛c₁ [⇛ b₂₂⇛c₂ ]\n cont {b₂ = b₁₁} a₁⇛b₁₁ a₂⇛b₁₂ ⋄ refl · a₂⇛b₂₂ =\n let c₂ , b₁₂⇛c₂ , b₂₂⇛c₂ = a₂⇛b₁₂ ⋄ a₂⇛b₂₂\n in b₁₁ [ c₂ ] , refl {a = b₁₁} [⇛ b₁₂⇛c₂ ] , cont a₁⇛b₁₁ b₂₂⇛c₂\n cont a₁⇛b₁₁ a₂⇛b₁₂ ⋄ ƛ _ a₁⇛b₂₁ · a₂⇛b₂₂ =\n let c₁ , b₁₁⇛c₁ , b₂₁⇛c₁ = a₁⇛b₁₁ ⋄ a₁⇛b₂₁\n c₂ , b₁₂⇛c₂ , b₂₂⇛c₂ = a₂⇛b₁₂ ⋄ a₂⇛b₂₂\n in c₁ [ c₂ ] , b₁₁⇛c₁ [⇛ b₁₂⇛c₂ ] , cont b₂₁⇛c₁ b₂₂⇛c₂\n cont a₁⇛b₁₁ a₂⇛b₁₂ ⋄ cont a₁⇛b₂₁ a₂⇛b₂₂ =\n let c₁ , b₁₁⇛c₁ , b₂₁⇛c₁ = a₁⇛b₁₁ ⋄ a₁⇛b₂₁\n c₂ , b₁₂⇛c₂ , b₂₂⇛c₂ = a₂⇛b₁₂ ⋄ a₂⇛b₂₂\n in c₁ [ c₂ ] , b₁₁⇛c₁ [⇛ b₁₂⇛c₂ ] , b₂₁⇛c₁ [⇛ b₂₂⇛c₂ ]\n\n -- A strip lemma.\n _⋄′_ : ∀ {n} {a b₁ b₂ : Term n} →\n a ⇛ b₁ → a ⇛* b₂ → ∃ λ c → b₁ ⇛* c × b₂ ⇛ c\n a⇛b ⋄′ ε = _ , ε , a⇛b\n a⇛b₁ ⋄′ (a⇛b₂ ◅ b₂⇛*c₂) =\n let c₁ , b₁⇛c₁ , b₂⇛c₁ = a⇛b₁ ⋄ a⇛b₂\n d , c₁⇛*d , c₂⇛d = b₂⇛c₁ ⋄′ b₂⇛*c₂\n in d , b₁⇛c₁ ◅ c₁⇛*d , c₂⇛d\n\n -- Confluence (aka the Church-Rosser property) of _⇛*_\n _⋄*_ : ∀ {n} {a b₁ b₂ : Term n} →\n a ⇛* b₁ → a ⇛* b₂ → ∃ λ c → b₁ ⇛* c × b₂ ⇛* c\n ε ⋄* a⇛*b = _ , a⇛*b , ε\n (a⇛b₁ ◅ b₁⇛*c₁) ⋄* a⇛*b₂ =\n let c₂ , b₁⇛*c₂ , b₂⇛c₂ = a⇛b₁ ⋄′ a⇛*b₂\n d , c₁⇛*d , c₂⇛*d = b₁⇛*c₁ ⋄* b₁⇛*c₂\n in d , c₁⇛*d , b₂⇛c₂ ◅ c₂⇛*d\n\n -- Factorization of equivalence into parallel reductions.\n ≡p⇒⇛* : ∀ {n} {a b : Term n} → a ≡p b → ∃ λ c → a ⇛* c × b ⇛* c\n ≡p⇒⇛* ε = _ , ε , ε\n ≡p⇒⇛* (fwd a⇛b ◅ b≡c) =\n let d , b⇛*d , c⇛*d = ≡p⇒⇛* b≡c in d , a⇛b ◅ b⇛*d , c⇛*d\n ≡p⇒⇛* (bwd a⇚b ◅ b≡c) =\n let d , b⇛*d , c⇛*d = ≡p⇒⇛* b≡c\n e , a⇛*e , d⇛e = a⇚b ⋄′ b⇛*d\n in e , a⇛*e , c⇛*d ◅◅ (d⇛e ◅ ε)\n\n -- Π-injectivity (with respect to ≡p).\n Π-inj : ∀ {n} {a₁ a₂ : Term n} {b₁ b₂} → Π a₁ b₁ ≡p Π a₂ b₂ →\n a₁ ≡p a₂ × b₁ ≡p b₂\n Π-inj Πa₁b₁≡Πa₂b₂ with ≡p⇒⇛* Πa₁b₁≡Πa₂b₂\n Π-inj Πa₁b₁≡Πa₂b₂ | c , Πa₁b₁⇛*c , Πa₂b₂⇛*c with\n Π-⇛* Πa₁b₁⇛*c | Π-⇛* Πa₂b₂⇛*c\n Π-inj Πa₁b₁≡Πa₂b₂ | Π a₃ b₃ , Πa₁b₁⇛*c , Πa₂b₂⇛*c |\n ._ , ._ , a₁⇛*a₃ , b₁⇛*b₃ , P.refl | ._ , ._ , a₂⇛*a₃ , b₂⇛*b₃ , P.refl =\n ⇛*⇒≡p a₁⇛*a₃ ◅◅ sym (⇛*⇒≡p a₂⇛*a₃) , ⇛*⇒≡p b₁⇛*b₃ ◅◅ sym (⇛*⇒≡p b₂⇛*b₃)\n where\n module ParSetoid {n} where\n open Setoid (≡p-setoid {n}) public\n open ParSetoid\n\n -- Parallel equivalence on sorts implies syntactic equivalence.\n sort-≡p : ∀ {n s₁ s₂} → sort {n} s₁ ≡p sort s₂ → s₁ ≡ s₂\n sort-≡p s₁≡s₂ with ≡p⇒⇛* s₁≡s₂\n sort-≡p s₁≡s₂ | c , s₁⇛*c , s₂⇛*c with sort-⇛* s₁⇛*c | sort-⇛* s₂⇛*c\n sort-≡p s₁≡s₂ | ._ , s₁⇛*c , s₂⇛*c | P.refl | P.refl = P.refl\n", "meta": {"hexsha": "05bad7dfe5d7b612e8f9299dd6c67307c2d78f73", "size": 11822, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Pts/Reduction/Parallel.agda", "max_stars_repo_name": "asr/pts-agda", "max_stars_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2016-05-13T12:11:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-31T10:47:57.000Z", "max_issues_repo_path": "src/Pts/Reduction/Parallel.agda", "max_issues_repo_name": "asr/pts-agda", "max_issues_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-21T14:48:09.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-21T16:01:50.000Z", "max_forks_repo_path": "src/Pts/Reduction/Parallel.agda", "max_forks_repo_name": "asr/pts-agda", "max_forks_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-08-20T10:29:44.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-11T23:28:33.000Z", "avg_line_length": 37.2933753943, "max_line_length": 77, "alphanum_fraction": 0.4762307562, "num_tokens": 6318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6791786861878392, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.3607860842986531}} {"text": "{-# OPTIONS --without-K #-}\nmodule hott.equivalence.coind where\n\nopen import level\nopen import sum\nopen import equality.core\nopen import equality.calculus\nopen import equality.reasoning\nopen import function.core\nopen import function.extensionality\nopen import function.fibration\nopen import function.isomorphism\nopen import function.overloading\nopen import container.core\nopen import container.fixpoint\nopen import container.m\nopen import hott.equivalence.core\nopen import hott.equivalence.alternative\nopen import hott.level\nopen import sets.unit\n\napply≅' : ∀ {i j}{X : Set i}{Y : Set j}\n → X ≅' Y → X → Y\napply≅' (i , _) = _≅_.to i\n\nis-≅' : ∀ {i j}{X : Set i}{Y : Set j} → (X → Y) → Set _\nis-≅' {X = X}{Y = Y} f = apply≅' ⁻¹ f\n\nabstract\n ≅'-≈-fib-comm : ∀ {i j}{X : Set i}{Y : Set j}(eq : X ≅' Y)\n → proj₁ (≅'⇒≈ eq) ≡ apply≅' eq\n ≅'-≈-fib-comm eq = refl\n\n ≅'⇒≈-we : ∀ {i j}{X : Set i}{Y : Set j}\n → weak-equiv (≅'⇒≈ {X = X}{Y = Y})\n ≅'⇒≈-we = proj₂ (≅⇒≈ (sym≅ ≈⇔≅'))\n\n is-≅'-≈-iso : ∀ {i j}{X : Set i}{Y : Set j}(f : X → Y)\n → is-≅' f ≅ weak-equiv f\n is-≅'-≈-iso {X = X}{Y = Y} f = begin\n is-≅' f\n ≡⟨ refl ⟩\n (fib weak-equiv ∘' ≅'⇒≈) ⁻¹ f\n ≅⟨ fib-compose ≅'⇒≈ (fib weak-equiv) f ⟩\n ( Σ (fib weak-equiv ⁻¹ f) λ { (we , _) → ≅'⇒≈ ⁻¹ we } )\n ≅⟨ ( Σ-ap-iso refl≅ λ { (we , _)\n → contr-⊤-iso (≅'⇒≈-we we) } ) ⟩\n ( fib weak-equiv ⁻¹ f × ⊤ )\n ≅⟨ ×-right-unit ⟩\n fib weak-equiv ⁻¹ f\n ≅⟨ fib-iso f ⟩\n weak-equiv f\n ∎\n where open ≅-Reasoning\n\nis-≅'-h1 : ∀ {i j}{X : Set i}{Y : Set j}\n → (f : X → Y) → h 1 (is-≅' f)\nis-≅'-h1 f = iso-level (sym≅ (is-≅'-≈-iso f)) (weak-equiv-h1 f)\n\n≅'-Σ-iso : ∀ {i j}{X : Set i}{Y : Set j}\n → (X ≅' Y) ≅ (Σ (X → Y) λ f → is-≅' f)\n≅'-Σ-iso {X = X}{Y = Y} = sym≅ (total-iso apply≅')\n\n≅'-equality : ∀ {i j}{X : Set i}{Y : Set j}\n → {isom₁ isom₂ : X ≅' Y}\n → (apply isom₁ ≡ apply isom₂)\n → isom₁ ≡ isom₂\n≅'-equality {X = X}{Y = Y} {isom₁}{isom₂} p = iso⇒inj ≅'-Σ-iso q\n where\n q : apply ≅'-Σ-iso isom₁ ≡ apply ≅'-Σ-iso isom₂\n q = unapΣ (p , h1⇒prop (is-≅'-h1 _) _ _)\n\nrecord F {i j}(Z : ∀ {i j} → Set i → Set j → Set (i ⊔ j))\n (X : Set i)(Y : Set j) : Set (i ⊔ j) where\n constructor mk-F\n field\n f : X → Y\n g : Y → X\n φ : (x : X)(y : Y) → Z (f x ≡ y) (x ≡ g y)\n\n~-container : ∀ i → Container _ _ _\n~-container i = record\n { I = Set i × Set i\n ; A = λ { (X , Y) → (X → Y) × (Y → X) }\n ; B = λ { {X , Y} _ → X × Y }\n ; r = λ { {a = f , g} (x , y) → (f x ≡ y) , (x ≡ g y) } }\n\nmodule D {i} where\n open Definition (~-container i) public\n open Fixpoint (fix M fixpoint) public\n hiding (fixpoint)\n\nunfold≅' : ∀ {i}{X Y : Set i}\n → X ≅' Y → D.F (λ { (X , Y) → X ≅' Y }) (X , Y)\nunfold≅' (isom , _)\n = (to , from)\n , λ { (x , y) → ≅⇒≅' (iso-adjunction isom x y) }\n where\n open _≅_ isom\n\n--unfold≅' : ∀ {i}{X Y : Set i}\n-- → X ≅' Y → D.F (λ { (X , Y) → X ≅' Y }) (X , Y)\n--unfold≅' {X = X}{Y = Y} (iso f g α β , δ) =\n-- ((f , g) , λ {(x , y) → ≅⇒≅' (φ x y)})\n-- where\n-- open ≡-Reasoning\n--\n-- δ' = co-coherence (iso f g α β) δ\n--\n-- iso₁ : {x : X}{y : Y}(p : f x ≡ y)\n-- → ap f (sym (α x) · ap g p) · β y ≡ p\n-- iso₁ {x} .{f x} refl = begin\n-- ap f (sym (α x) · refl) · β (f x)\n-- ≡⟨ ap (λ z → ap f z · β (f x)) (left-unit (sym (α x))) ⟩\n-- ap f (sym (α x)) · β (f x)\n-- ≡⟨ ap (λ z → z · β (f x)) (ap-inv f (α x)) ⟩\n-- sym (ap f (α x)) · β (f x)\n-- ≡⟨ ap (λ z → sym z · β (f x)) (δ x) ⟩\n-- sym (β (f x)) · β (f x)\n-- ≡⟨ right-inverse (β (f x)) ⟩\n-- refl\n-- ∎\n--\n-- iso₂' : {x : X}{y : Y}(q : g y ≡ x)\n-- → sym (α x) · ap g (ap f (sym q) · β y) ≡ sym q\n-- iso₂' .{g y}{y} refl = begin\n-- sym (α (g y)) · ap g (refl · β y)\n-- ≡⟨ ap (λ z → sym (α (g y)) · ap g z) (right-unit (β y)) ⟩\n-- sym (α (g y)) · ap g (β y)\n-- ≡⟨ ap (λ z → sym (α (g y)) · z) (δ' y) ⟩\n-- sym (α (g y)) · α (g y)\n-- ≡⟨ right-inverse (α (g y)) ⟩\n-- refl\n-- ∎\n--\n-- iso₂ : {x : X}{y : Y}(q : x ≡ g y)\n-- → sym (α x) · ap g (ap f q · β y) ≡ q\n-- iso₂ {x}{y} q =\n-- subst (λ z → sym (α x) · ap g (ap f z · β y) ≡ z)\n-- (double-inverse q)\n-- (iso₂' (sym q))\n--\n-- φ : (x : X)(y : Y) → (f x ≡ y) ≅ (x ≡ g y)\n-- φ x y = record\n-- { to = λ p → sym (α x) · ap g p\n-- ; from = λ q → ap f q · β y\n-- ; iso₁ = iso₁\n-- ; iso₂ = iso₂ }\n\nIso' : ∀ {i} → Set i × Set i → Set _\nIso' (X , Y) = X ≅' Y\n\n_~_ : ∀ {i} → Set i → Set i → Set i\n_~_ {i} X Y = D.M (X , Y)\n\napply~ : ∀ {i}{X Y : Set i} → X ~ Y → X → Y\napply~ eq = proj₁ (D.head eq)\n\ninvert~ : ∀ {i}{X Y : Set i} → X ~ Y → Y → X\ninvert~ eq = proj₂ (D.head eq)\n\nprivate\n u : ∀ {i}(XY : Set i × Set i)\n → let (X , Y) = XY in X ~ Y → X ≅' Y\n u (X , Y) eq = ≅⇒≅' (iso f g α β)\n where\n f : X → Y\n f = apply~ eq\n\n g : Y → X\n g = invert~ eq\n\n φ : (x : X)(y : Y) → (f x ≡ y) ~ (x ≡ g y)\n φ x y = D.tail eq (x , y)\n\n α : (x : X) → g (f x) ≡ x\n α x = sym (apply~ (φ x (f x)) refl)\n\n β : (y : Y) → f (g y) ≡ y\n β y = invert~ (φ (g y) y) refl\n\n-- u-morphism : ∀ {i}{X Y : Set i}\n-- → (eq : X ~ Y)\n-- → unfold≅' (u _ eq)\n-- ≡ D.imap u _ (D.out _ eq)\n-- u-morphism {i}{X}{Y} eq = unapΣ (refl , funext λ {(x , y) → lem₂ x y})\n-- where\n-- f : X → Y\n-- f = apply~ eq\n-- \n-- g : Y → X\n-- g = invert~ eq\n-- \n-- φ : (x : X)(y : Y) → (f x ≡ y) ~ (x ≡ g y)\n-- φ x y = D.tail eq (x , y)\n-- \n-- σ τ : (x : X)(y : Y) → (f x ≡ y) ≅' (x ≡ g y)\n-- σ x y = proj₂ (unfold≅' (u _ eq)) (x , y)\n-- τ x y = u _ (φ x y)\n-- \n-- lem : (x : X)(y : Y)(p : f x ≡ y)\n-- → apply≅' (σ x y) p ≡ apply≅' (τ x y) p\n-- lem x .(f x) refl = ?\n-- \n-- lem₂ : (x : X)(y : Y) → proj₂ (unfold≅' (u (X , Y) eq)) (x , y)\n-- ≡ u _ (D.tail eq (x , y))\n-- lem₂ x y = ≅'-equality (funext (lem x y))\n-- \n-- v : ∀ {i}(XY : Set i × Set i) → let (X , Y) = XY in X ≅' Y → X ~ Y\n-- v = D.unfold (λ _ → unfold≅')\n-- \n-- vu-morphism : ∀ {i}{X Y : Set i}\n-- → (eq : X ~ Y)\n-- → D.out _ (v _ (u _ eq))\n-- ≡ D.imap (v D.∘ⁱ u) _ (D.out _ eq)\n-- vu-morphism {X = X}{Y = Y} eq = ap (D.imap v _) (u-morphism eq)\n-- \n-- vu-id : ∀ {i}{X Y : Set i} (eq : X ~ Y) → v _ (u _ eq) ≡ eq\n-- vu-id eq = D.unfold-η D.out (v D.∘ⁱ u) vu-morphism eq · D.unfold-id eq\n-- \n-- uv-id : ∀ {i}{X Y : Set i} (i : X ≅' Y) → u _ (v _ i) ≡ i\n-- uv-id {X = X}{Y = Y} i = ≅'-equality refl\n-- \n-- ~⇔≅' : ∀ {i}{X Y : Set i} → (X ~ Y) ≅ (X ≅' Y)\n-- ~⇔≅' = iso (u _) (v _) vu-id uv-id\n", "meta": {"hexsha": "4f67193aa6e3a3e90c74555018d2aebc9675e835", "size": 6806, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "hott/equivalence/coind.agda", "max_stars_repo_name": "HoTT/M-types", "max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z", "max_issues_repo_path": "src/hott/equivalence/coind.agda", "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_forks_repo_path": "hott/equivalence/coind.agda", "max_forks_repo_name": "HoTT/M-types", "max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z", "avg_line_length": 30.1150442478, "max_line_length": 75, "alphanum_fraction": 0.4025859536, "num_tokens": 3113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947290421276, "lm_q2_score": 0.5506073655352403, "lm_q1q2_score": 0.3605898614608009}} {"text": "module Reduction where\n\nopen import Data.Sum\nopen import Library\nopen import Terms\nopen import Substitution\nopen import TermShape\nopen import SN\n\ndata βECxt (Γ : Cxt) : (Δ : Cxt) (a b : Ty) → Set where\n appl : ∀ {a b} (u : Tm Γ a) → βECxt Γ Γ (a →̂ b) b\n appr : ∀ {a b} (t : Tm Γ (a →̂ b)) → βECxt Γ Γ a b\n abs : ∀ {a b} → βECxt Γ (a ∷ Γ) b (a →̂ b)\n\ndata βEhole {Γ : Cxt} : {Δ : Cxt} {b a : Ty} → Tm Γ b → βECxt Γ Δ a b → Tm Δ a → Set where\n appl : ∀ {a b} {t : Tm Γ (a →̂ b)} (u : Tm Γ a) → βEhole (app t u) (appl u) t\n appr : ∀ {a b u} (t : Tm Γ (a →̂ b)) → βEhole (app t u) (appr t) u\n abs : ∀ {a b} {t : Tm (a ∷ Γ) b} → βEhole (abs t) abs t\n\n-- Plugging a hole\nmkHole : ∀ {Γ Δ} {a b} (E : βECxt Γ Δ a b) {t} → ∃ λ E[t] → βEhole E[t] E t\nmkHole (appl u) = _ , appl u\nmkHole (appr t) = _ , appr t\nmkHole abs = _ , abs\n\ndata _⇒β_ {Γ} : ∀ {a} → Tm Γ a → Tm Γ a → Set where\n\n β : ∀ {a b}{t : Tm (a ∷ Γ) b}{u}\n → (app (abs t) u) ⇒β subst0 u t\n\n cong : ∀ {Δ a b t t' Et Et'}{E : βECxt Γ Δ a b}\n → (𝑬𝒕 : βEhole Et E t)\n → (𝑬𝒕' : βEhole Et' E t')\n → (t⇒β : t ⇒β t')\n → Et ⇒β Et'\n\n\nsubst⇒β : ∀ {m vt a Γ} {t t' : Tm Γ a} {Δ}\n (σ : RenSub {m} vt Γ Δ) → t ⇒β t' → subst σ t ⇒β subst σ t'\nsubst⇒β σ (β {t = t} {u = u}) = ≡.subst (λ t' → app (abs (subst (lifts σ) t)) (subst σ u) ⇒β t')\n (sgs-lifts-term {σ = σ} {u} {t})\n β\nsubst⇒β σ (cong (appl u) (appl .u) t⇒) = cong (appl _) (appl _) (subst⇒β σ t⇒)\nsubst⇒β σ (cong (appr t) (appr .t) t⇒) = cong (appr _) (appr _) (subst⇒β σ t⇒)\nsubst⇒β σ (cong abs abs t⇒) = cong abs abs (subst⇒β (lifts σ) t⇒)\n\n-- Multi-step β-reduction (β-reduction sequences).\n-- Reflexive-transitive closure of single-step β-reduction.\n\ninfix 7 _⇒β_ _⇒β*_\n\ndata _⇒β*_ {Γ} {a} : Tm Γ a → Tm Γ a → Set where\n [] : ∀ {t} → t ⇒β* t\n _∷_ : ∀ {ti tm to} → ti ⇒β tm → tm ⇒β* to → ti ⇒β* to\n\n-- Concatenating β-reduction sequences\n\n_++β_ : ∀ {Γ} {a} {t₀ t₁ t₂ : Tm Γ a} → t₀ ⇒β* t₁ → t₁ ⇒β* t₂ → t₀ ⇒β* t₂\n[] ++β ys = ys\n(x ∷ xs) ++β ys = x ∷ (xs ++β ys)\n\n-- Multi-step β-reduction is compatible with term constructors.\n\ncong* : ∀ {a Γ Δ} {b} {t tβ* : Tm Γ a} {E : βECxt Δ Γ a b} {E[t] E[tβ*]}\n → βEhole E[t] E t\n → βEhole E[tβ*] E tβ*\n → t ⇒β* tβ*\n → E[t] ⇒β* E[tβ*]\ncong* E1 E2 (x ∷ t⇒) = cong E1 (proj₂ (mkHole _)) x ∷ cong* (proj₂ (mkHole _)) E2 t⇒\ncong* (appl u) (appl .u) [] = []\ncong* (appr t₁) (appr .t₁) [] = []\ncong* abs abs [] = []\n\nEC→βEC : ∀ {Γ} {a b} (E : ECxt Γ a b) → βECxt Γ Γ a b\nEC→βEC (appl u) = appl u\n\nmkHole4 : ∀ {Γ} {a b} (E : ECxt Γ a b) {t : Tm Γ a} → βEhole (E [ t ]) (EC→βEC E) t\nmkHole4 (appl u) = appl u\n\ncong*3 : ∀ {Γ a b t t'}(E : ECxt* Γ a b)\n → (t⇒ : t ⇒β t')\n → E [ t ]* ⇒β E [ t' ]*\ncong*3 [] t⇒ = t⇒\ncong*3 (x ∷ E) t⇒ = cong*3 E (cong (mkHole4 x) (mkHole4 x) t⇒)\n\ncong*4 : ∀ {Γ a b t t'}(E : ECxt* Γ a b)\n → (t⇒ : t ⇒β* t')\n → E [ t ]* ⇒β* E [ t' ]*\ncong*4 E [] = []\ncong*4 E (x ∷ xs) = cong*3 E x ∷ cong*4 E xs\n\nsubst⇒β*₀ : ∀ {m vt a Γ} {t t' : Tm Γ a} {Δ} (σ : RenSub {m} vt Γ Δ) → t ⇒β* t' → subst σ t ⇒β* subst σ t'\nsubst⇒β*₀ σ [] = []\nsubst⇒β*₀ σ (x ∷ xs) = (subst⇒β σ x) ∷ (subst⇒β*₀ σ xs)\n\nmutual\n subst⇒β* : ∀ {m vt a Γ} {Δ} {σ ρ : RenSub {m} vt Γ Δ}\n → (∀ {b} (x : Var Γ b) → vt2tm _ (σ x) ⇒β* vt2tm _ (ρ x))\n → (t : Tm Γ a)\n → subst σ t ⇒β* subst ρ t\n subst⇒β* σ₁ (var x) = σ₁ x\n subst⇒β* {vt = vt} σ₁ (abs t) = cong* abs abs (subst⇒β* (lifts⇒β* {vt = vt} σ₁) t)\n subst⇒β* σ₁ (app t t₁) = cong* (appl _) (appl _) (subst⇒β* σ₁ t) ++β cong* (appr _) (appr _) (subst⇒β* σ₁ t₁)\n\n lifts⇒β* : ∀ {m vt a Γ} {Δ} {σ ρ : RenSub {m} vt Γ Δ}\n → (∀ {b} (x : Var Γ b) → vt2tm _ (σ x) ⇒β* vt2tm _ (ρ x))\n → ∀ {b} (x : Var (a ∷ Γ) b)\n → vt2tm _ (lifts {a = a} σ x) ⇒β* vt2tm _ (lifts {a = a} ρ x)\n lifts⇒β* {vt = `Var} σ (zero) = []\n lifts⇒β* {vt = `Tm} σ (zero) = []\n lifts⇒β* {vt = `Var} σ (suc x) = subst⇒β*₀ {vt = `Var} suc (σ x)\n lifts⇒β* {vt = `Tm} σ (suc x) = subst⇒β*₀ {vt = `Var} suc (σ x)\n\n-- Altenkirch's weak standardization lemma.\n\nmutual\n beta-shr : ∀ {i a Γ} {t tβ th : Tm Γ a}\n → t ⇒β tβ\n → t ⟨ i ⟩⇒ th\n → (tβ ≡ th) ⊎ ∃ λ t' → tβ ⟨ i ⟩⇒ t' × th ⇒β* t'\n beta-shr β (β 𝒖) = inj₁ ≡.refl\n beta-shr (cong (appl u) (appl .u) (cong abs abs tβ⇒)) (β 𝒖) = inj₂ (_ , β 𝒖 , (subst⇒β (sgs u) tβ⇒ ∷ []))\n beta-shr (cong (appr ._) (appr ._) tβ⇒) (β {t = t} 𝒖)\n = inj₂ (_ , β (mapβSN tβ⇒ 𝒖) , subst⇒β* {vt = `Tm} (λ { {._} (zero) → tβ⇒ ∷ [] ; (suc x) → [] }) t)\n beta-shr β (cong (appl u) (appl .u) (cong () 𝑬𝒕' th⇒))\n beta-shr (cong E1 E2 t⇒) (cong E0 E3 th⇒) = helper E1 E2 t⇒ E0 E3 th⇒\n\n where\n helper : ∀ {i}{a Γ} {t tβ th : Tm Γ a} {Δ a₁} {t₁ ta : Tm Δ a₁}\n {E : βECxt Γ Δ a₁ a} {a₂} {t₂ tb : Tm Γ a₂} {E₁ : ECxt Γ a₂ a}\n → βEhole t E t₁\n → βEhole tβ E ta\n → t₁ ⇒β ta\n → Ehole t E₁ t₂\n → Ehole th E₁ tb\n → t₂ ⟨ i ⟩⇒ tb\n → tβ ≡ th ⊎ ∃ λ t' → tβ ⟨ i ⟩⇒ t' × th ⇒β* t'\n helper (appl u) (appl .u) t⇒₁ (appl .u) (appl .u) th⇒₁ with beta-shr t⇒₁ th⇒₁\n helper (appl u) (appl .u) t⇒₁ (appl .u) (appl .u) th⇒₁ | inj₁ ≡.refl = inj₁ ≡.refl\n helper (appl u) (appl .u) t⇒₁ (appl .u) (appl .u) th⇒₁ | inj₂ (tm , h⇒tm , tm⇒β)\n = inj₂ (_ , cong (appl _) (appl _) h⇒tm , cong* (appl _) (appl _) tm⇒β)\n helper (appr t₂) (appr .t₂) t⇒₁ (appl t₁) (appl .t₁) th⇒₁ = inj₂ (_ , cong (appl _) (appl _) th⇒₁ , (cong (appr _) (appr _) t⇒₁ ∷ []))\n\n -- SNe is preserved under reduction.\n\n mapβSNe : ∀ {i a Γ} {t t' : Tm Γ a}\n → t ⇒β t'\n → SNe {i} t\n → SNe {i} t'\n mapβSNe (cong (appl u) (appl .u) t⇒) (elim 𝒏 (appl 𝒖)) = elim (mapβSNe t⇒ 𝒏) (appl 𝒖)\n mapβSNe (cong (appr u) (appr .u) t⇒) (elim 𝒏 (appl 𝒖)) = elim 𝒏 (appl (mapβSN t⇒ 𝒖))\n -- The other cases are impossible\n mapβSNe (cong abs abs t⇒) (elim 𝒏 ())\n mapβSNe β (elim (elim 𝒏 ()) (appl 𝒖))\n\n -- SN is preserved under reduction.\n\n mapβSN : ∀ {i a Γ} {t t' : Tm Γ a}\n → t ⇒β t'\n → SN {i} t\n → SN {i} t'\n mapβSN t⇒ (ne 𝒏) = ne (mapβSNe t⇒ 𝒏)\n mapβSN (cong abs abs t⇒) (abs 𝒕) = abs (mapβSN t⇒ 𝒕)\n mapβSN t⇒ (exp t⇒₁ 𝒕) with beta-shr t⇒ t⇒₁\n mapβSN t⇒ (exp t⇒₁ 𝒕) | inj₁ ≡.refl = 𝒕\n mapβSN t⇒ (exp t⇒₁ 𝒕) | inj₂ (_ , t⇒h , t⇒β*) = exp t⇒h (mapβ*SN t⇒β* 𝒕)\n\n -- SN is preserved under multi-step reduction.\n\n mapβ*SN : ∀ {i a Γ} {t t' : Tm Γ a}\n → t ⇒β* t'\n → SN {i} t\n → SN {i} t'\n mapβ*SN [] 𝒕 = 𝒕\n mapβ*SN (t⇒ ∷ t⇒β*) 𝒕 = mapβ*SN t⇒β* (mapβSN t⇒ 𝒕)\n", "meta": {"hexsha": "86e2a84bacd45720d9a95383fd714ee9daa6a604", "size": 6882, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-aplas14/Reduction.agda", "max_stars_repo_name": "ryanakca/strong-normalization", "max_stars_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2017-05-22T14:33:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-05T12:12:03.000Z", "max_issues_repo_path": "agda-aplas14/Reduction.agda", "max_issues_repo_name": "ryanakca/strong-normalization", "max_issues_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-02-14T16:42:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-20T14:54:18.000Z", "max_forks_repo_path": "agda-aplas14/Reduction.agda", "max_forks_repo_name": "ryanakca/strong-normalization", "max_forks_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-11-10T16:44:52.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-23T18:22:17.000Z", "avg_line_length": 39.1022727273, "max_line_length": 140, "alphanum_fraction": 0.4495786109, "num_tokens": 3456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.3605898614608009}} {"text": "postulate\n C : Set\n anything : C\n\nrecord I : Set where\n constructor c\n field\n f : C\n\ndata Wrap : (j : I) → Set where\n wrap : ∀ {j} → Wrap j\n\nworks1 : ∀ {j} → Wrap j → C\nworks1 {c ._} (wrap {j = c _}) with anything\n... | z = z\n", "meta": {"hexsha": "ccacd41aa968d0d8b3f1f49cf553a99f196644dc", "size": 234, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1605b.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue1605b.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue1605b.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 14.625, "max_line_length": 44, "alphanum_fraction": 0.5384615385, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6548947155710234, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.36058985404351174}} {"text": "{-# OPTIONS --without-K #-}\nopen import HoTT.Base\nopen import HoTT.HLevel\nopen import HoTT.HLevel.Truncate\nopen import HoTT.Logic\nopen import HoTT.Identity\nopen import HoTT.Identity.Identity\nopen import HoTT.Identity.Coproduct\nopen import HoTT.Identity.Sigma\nopen import HoTT.Identity.Pi\nopen import HoTT.Identity.Universe\nopen import HoTT.Equivalence\nopen import HoTT.Equivalence.Lift\nopen import HoTT.Sigma.Transport\n\nmodule HoTT.Exercises.Chapter3 where\n\nmodule Exercise1 {i} {A B : 𝒰 i} (e : A ≃ B) (A-set : isSet A)\n where\n □ : isSet B\n □ {x} {y} p q = ap⁻¹ (ap≃ (e ⁻¹ₑ) x y) (A-set (ap g p) (ap g q))\n where open Iso (eqv→iso e)\n\nmodule Exercise2 {i} {A B : 𝒰 i} (A-set : isSet A) (B-set : isSet B)\n where\n □ : isSet (A + B)\n □ {inl x} {inl y} p q = ap⁻¹ =+-equiv\n (ap lift (A-set (lower (=+-elim p)) (lower (=+-elim q))))\n □ {inl x} {inr y} p q = 𝟎-rec (=+-elim p)\n □ {inr x} {inl y} p q = 𝟎-rec (=+-elim p)\n □ {inr x} {inr y} p q = ap⁻¹ =+-equiv\n (ap lift (B-set (lower (=+-elim p)) (lower (=+-elim q))))\n\nmodule Exercise3\n {i} {A : 𝒰 i} (A-set : isSet A)\n {j} {B : A → 𝒰 j} (B-set : {x : A} → isSet (B x))\n where\n □ : isSet (Σ A B)\n □ {x = x@(x₁ , x₂)} {y = y@(y₁ , y₂)} p q =\n ap⁻¹ =Σ-equiv (lemma (pr₁ =Σ-equiv p) (pr₁ =Σ-equiv q))\n where\n lemma : (p q : Σ (x₁ == y₁) λ p₁ → (transport B p₁ x₂ == y₂)) → p == q\n lemma (p₁ , p₂) (q₁ , q₂) = pair⁼ (r₁ , r₂)\n where\n r₁ = A-set p₁ q₁\n r₂ = B-set (transport _ r₁ p₂) q₂\n\nmodule Exercise4 {i} {A : 𝒰 i} where\n _ : isProp A → isContr (A → A)\n _ = λ A-prop → id , λ f → funext λ x → A-prop x (f x)\n\n _ : isContr (A → A) → isProp A\n _ = λ where\n (f , contr) x y → happly (contr (const x) ⁻¹ ∙ contr (const y)) x\n\nmodule Exercise5 {i} {A : 𝒰 i} where\n open import HoTT.Pi.Transport\n open import HoTT.Sigma.Transport\n\n _ : isProp A ≃ (A → isContr A)\n _ = f , qinv→isequiv (g , η , ε)\n where\n f : isProp A → (A → isContr A)\n f A-prop x = x , A-prop x\n g : (A → isContr A) → isProp A\n g h x y = let contr = pr₂ (h x) in contr x ⁻¹ ∙ contr y\n η : g ∘ f ~ id\n η _ = isProp-prop _ _\n ε : f ∘ g ~ id\n ε h = funext λ _ → isContr-prop _ _\n\nmodule Exercise6 {i} {A : 𝒰 i} where\n instance\n LEM-prop : ⦃ hlevel 1 A ⦄ → hlevel 1 (A + ¬ A)\n LEM-prop = isProp→hlevel1 λ where\n (inl a) (inl a') → ap inl center\n (inl a) (inr f) → 𝟎-rec (f a)\n (inr f) (inl b') → 𝟎-rec (f b')\n (inr f) (inr f') → ap inr center\n\nmodule Exercise7\n {i} {A : 𝒰 i} {A-prop : isProp A}\n {j} {B : 𝒰 j} {B-prop : isProp B}\n where\n □ : ¬ (A × B) → isProp (A + B)\n □ f = λ where\n (inl x) (inl y) → ap inl (A-prop _ _)\n (inl x) (inr y) → 𝟎-rec (f (x , y))\n (inr x) (inl y) → 𝟎-rec (f (y , x))\n (inr x) (inr y) → ap inr (B-prop _ _)\n\nmodule Exercise8 {i j} {A : 𝒰 i} {B : 𝒰 j} {f : A → B} where\n open import HoTT.Equivalence.Proposition\n prop₁ : qinv f → ∥ qinv f ∥\n prop₁ e = ∣ e ∣\n prop₂ : ∥ qinv f ∥ → qinv f\n prop₂ e = isequiv→qinv (∥-rec ⦃ isProp→hlevel1 isequiv-prop ⦄ qinv→isequiv e)\n prop₃ : isProp ∥ qinv f ∥\n prop₃ = hlevel1→isProp\n\nmodule Exercise9 {i} (lem : LEM {i}) where\n open import HoTT.Logic\n open import HoTT.Equivalence.Lift\n\n _ : Prop𝒰 i ≃ 𝟐\n _ = f , qinv→isequiv (g , η , ε)\n where\n f : Prop𝒰 i → 𝟐\n f P with lem P\n ... | inl _ = 0₂\n ... | inr _ = 1₂\n g : 𝟐 → Prop𝒰 i\n g 0₂ = ⊤\n g 1₂ = ⊥\n η : g ∘ f ~ id\n η P with lem P\n ... | inl t = hlevel⁼ (ua (prop-equiv (const t) (const ★)))\n ... | inr f = hlevel⁼ (ua (prop-equiv 𝟎-rec (𝟎-rec ∘ f)))\n ε : f ∘ g ~ id\n ε 0₂ with lem (g 0₂)\n ... | inl _ = refl\n ... | inr f = 𝟎-rec (f ★)\n ε 1₂ with lem (g 1₂)\n ... | inl ()\n ... | inr _ = refl\n\nimport HoTT.Exercises.Chapter3.Exercise10\n\nmodule Exercise11 where\n open variables\n open import HoTT.Pi.Transport\n open import HoTT.Identity.Boolean\n\n prop : ¬ ((A : 𝒰₀) → ∥ A ∥ → A)\n prop f = 𝟎-rec (g (f 𝟐 ∣ 0₂ ∣) p)\n where\n not = 𝟐-rec 1₂ 0₂\n e : 𝟐 ≃ 𝟐\n e = not , qinv→isequiv (not , 𝟐-ind _ refl refl , 𝟐-ind _ refl refl)\n g : (x : 𝟐) → ¬ (not x == x)\n g 0₂ = 𝟎-rec ∘ pr₁ =𝟐-equiv\n g 1₂ = 𝟎-rec ∘ pr₁ =𝟐-equiv\n p : not (f 𝟐 ∣ 0₂ ∣) == f 𝟐 ∣ 0₂ ∣\n p =\n not (f 𝟐 ∣ 0₂ ∣)\n =⟨ ap (λ e → pr₁ e (f 𝟐 ∣ 0₂ ∣)) (=𝒰-β e) ⁻¹ ⟩\n transport id (ua e) (f 𝟐 ∣ 0₂ ∣)\n =⟨ ap (λ x → transport id (ua e) (f 𝟐 x)) center ⟩\n transport id (ua e) (f 𝟐 (transport ∥_∥ (ua e ⁻¹) ∣ 0₂ ∣))\n =⟨ happly (transport-→ ∥_∥ id (ua e) (f 𝟐) ⁻¹) ∣ 0₂ ∣ ⟩\n transport (λ A → ∥ A ∥ → A) (ua e) (f 𝟐) ∣ 0₂ ∣\n =⟨ happly (apd f (ua e)) ∣ 0₂ ∣ ⟩\n f 𝟐 ∣ 0₂ ∣\n ∎\n where open =-Reasoning\n\nmodule Exercise12 {i} {A : 𝒰 i} (lem : LEM {i}) where\n open variables using (B ; j)\n\n □ : ∥ (∥ A ∥ → A) ∥\n □ with lem (type ∥ A ∥)\n ... | inl x = swap ∥-rec x λ x → ∣ const x ∣\n ... | inr f = ∣ 𝟎-rec ∘ f ∣\n\nmodule Exercise13 {i} (lem : LEM∞ {i}) where\n □ : AC {i} {i} {i}\n □ {X = X} {A = A} {P = P} f = ∣ pr₁ ∘ g , pr₂ ∘ g ∣\n where\n g : (x : X) → Σ (A x) (P x)\n g x with lem (Σ (A x) (P x))\n ... | inl t = t\n ... | inr b = ∥-rec ⦃ hlevel-in (λ {x} → 𝟎-rec (b x)) ⦄ id (f x)\n\nmodule Exercise14 (lem : ∀ {i} → LEM {i}) where\n open import HoTT.Sigma.Universal\n\n open variables\n\n ∥_∥' : 𝒰 i → 𝒰 i\n ∥ A ∥' = ¬ ¬ A\n\n ∣_∣' : A → ∥ A ∥'\n ∣ a ∣' f = f a\n\n ∥'-hlevel : hlevel 1 ∥ A ∥'\n ∥'-hlevel = ⟨⟩\n\n ∥'-rec : ⦃ hlevel 1 B ⦄ → (f : A → B) →\n Σ[ g ∶ (∥ A ∥' → B) ] Π[ a ∶ A ] g ∣ a ∣' == f a\n ∥'-rec f = λ where\n .pr₁ a → +-rec id (λ b → 𝟎-rec (a (𝟎-rec ∘ b ∘ f))) (lem (type _))\n .pr₂ _ → center\n\n _ : ∥ A ∥' ≃ ∥ A ∥\n _ = let open Iso in iso→eqv λ where\n .f → pr₁ (∥'-rec ∣_∣)\n .g → ∥-rec ∣_∣'\n .η _ → center\n .ε _ → center\n\nmodule Exercise15\n (LiftProp-isequiv : ∀ {i j} → isequiv (LiftProp {i} {j}))\n where\n open import HoTT.Equivalence.Transport\n open variables\n\n open module LiftProp-qinv {i} {j} = qinv (isequiv→qinv (LiftProp-isequiv {i} {j}))\n renaming (g to LowerProp ; η to LiftProp-η ; ε to LiftProp-ε)\n\n ∥_∥' : 𝒰 (lsuc i) → 𝒰 (lsuc i)\n ∥_∥' {i} A = (P : Prop𝒰 i) → (A → P ty) → P ty\n\n ∣_∣' : A → ∥ A ∥'\n ∣ a ∣' _ f = f a\n\n ∥'-hlevel : hlevel 1 ∥ A ∥'\n ∥'-hlevel = ⟨⟩\n\n ∥'-rec : {A : 𝒰 (lsuc i)} {(type B) : Prop𝒰 (lsuc i)} → (f : A → B) →\n Σ (∥ A ∥' → B) λ g → (a : A) → g ∣ a ∣' == f a\n ∥'-rec {_} {_} {B} f = let p = ap _ty (LiftProp-ε B) in λ where\n .pr₁ a → transport id p (lift (a (LowerProp B) (lower ∘ transport id (p ⁻¹) ∘ f)))\n -- We do not get a definitional equality since our propositional\n -- resizing equivalence does not give us definitionally equal\n -- types, i.e. LowerProp B ‌≢ B. If it did, then we could write\n --\n -- ∥'-rec f a :≡ a (LowerProp B) f\n --\n -- and then we'd have ∥'-rec f ∣a∣' ≡ f a.\n .pr₂ a → Eqv.ε (transport-equiv p) (f a)\n\nmodule Exercise16\n {i} {(type X) : Set𝒰 i}\n {j} {Y : X → Prop𝒰 j}\n (lem : ∀ {i} → LEM {i})\n where\n _ : Π[ x ∶ X ] ¬ ¬ Y x ty ≃ ¬ ¬ (Π[ x ∶ X ] Y x ty)\n _ = let open Iso in iso→eqv λ where\n .f s t → t λ x → +-rec id (𝟎-rec ∘ s x) (lem (Y x))\n .g s x y → 𝟎-rec (s λ f → 𝟎-rec (y (f x)))\n .η _ → center\n .ε _ → center\n\nmodule Exercise17\n {i} {A : 𝒰 i}\n {j} {B : ∥ A ∥ → Prop𝒰 j}\n where\n ∥-ind : ((a : A) → B ∣ a ∣ ty) → (x : ∥ A ∥) → B x ty\n ∥-ind f x = ∥-rec (transport (_ty ∘ B) center ∘ f) x\n where instance _ = λ {x} → hlevel𝒰.h (B x)\n\nmodule Exercise18 {i} where\n open Exercise6\n\n _ : LEM {i} → LDN {i}\n _ = λ lem P f → +-rec id (𝟎-rec ∘ f) (lem P)\n\n _ : LDN {i} → LEM {i}\n _ = λ ldn P → ldn (type (P ty + ¬ P ty)) λ f → f (inr (f ∘ inl))\n\nmodule Exercise19\n {i} {P : ℕ → 𝒰 i}\n (P-lem : (n : ℕ) → P n + ¬ P n)\n -- Do not assume that all P n are mere propositions so we can\n -- reuse this solution for exercise 23.\n where\n open import HoTT.NaturalNumber renaming (_+_ to _+ₙ_ ; +-comm to +ₙ-comm)\n open import HoTT.Identity.NaturalNumber\n open import HoTT.Transport.Identity\n open import HoTT.Base.Inspect\n open import HoTT.Identity.Product\n open import HoTT.Equivalence.Sigma\n open import HoTT.Equivalence.Coproduct\n open import HoTT.Equivalence.Empty\n\n -- P n does not hold for any m < n\n ℕ* : ℕ → 𝒰 i\n ℕ* zero = 𝟏\n ℕ* (succ n) = ¬ P n × ℕ* n\n\n P* : {n : ℕ} → P n → 𝒰 i\n P* {n} p = inl p == P-lem n\n\n -- ℕ* is the product of 𝟏 and some ¬ P n, all of which are\n -- propositions, so it is a proposition as well.\n instance ℕ*-hlevel : {n : ℕ} → hlevel 1 (ℕ* n)\n ℕ*-hlevel {zero} = 𝟏-hlevel\n ℕ*-hlevel {succ n} = ×-hlevel\n\n P*-hlevel : {n : ℕ} → hlevel 1 (Σ (P n) P*)\n hlevel-out (P*-hlevel {n}) {p , _} = ⟨⟩\n where\n e : P n ≃ P n + ¬ P n\n e = +-empty₂ ⁻¹ₑ ∙ₑ +-equiv reflₑ (𝟎-equiv (_$ p))\n instance\n _ = =-contrᵣ (P-lem n)\n _ = raise ⦃ equiv-hlevel (Σ-equiv₁ e ⁻¹ₑ) ⦄\n instance _ = P*-hlevel\n\n -- Extract evidence that ¬ P m for some m < n\n extract : {m n : ℕ} → m < n → ℕ* n → ¬ P m\n extract {m} (k , p) = pr₁ ∘ weaken ∘ transport ℕ* p'\n where\n p' = p ⁻¹ ∙ +ₙ-comm (succ m) k\n weaken : {k : ℕ} → ℕ* (k +ₙ succ m) → ℕ* (succ m)\n weaken {zero} = id\n weaken {succ k} = weaken ∘ pr₂\n\n -- The smallest n such that P n holds\n Pₒ = Σ (Σ ℕ λ n → Σ (P n) P*) (ℕ* ∘ pr₁)\n\n Pₒ-prop : isProp Pₒ\n Pₒ-prop ((n , p , _) , n*) ((m , q , _) , m*) =\n pair⁼ (pair⁼ (n=m , center) , center)\n where\n n=m : n == m\n n=m with n <=> m\n -- If n = m, then there is nothing to do.\n ... | inl n=m = n=m\n -- If n < m, we have P n and we know ℕ* m contains ¬ P n\n -- somewhere inside, so we can just extract it to find a\n -- contradiction.\n ... | inr (inl n_)\nopen import Data.Nat.DivMod using (_mod_; _div_)\nopen import Data.Product using (_×_; _,_; proj₁)\nopen import Data.String using (String; intersperse) renaming (_++_ to _++s_)\nopen import Data.Vec using (Vec; []; _∷_; lookup; replicate; _[_]%=_; toList) renaming (map to vmap)\n\nopen import Relation.Nullary using (yes; no)\n\nopen import BitVec using (BitVec; insert; empty; show)\nopen import Util using (n∸k>=′_\n\n_>>=′_ : Squash A → (A → Squash B) → Squash B\n_>>=′_ {A = A} {B = B} (squash x) f = squash (lemma x)\n where\n lemma : Squash′ A → Squash′ B\n lemma (squash′ x) = Squash.squashed (f x)\n\ninstance\n\n -- Squash is a monad.\n\n raw-monad : Raw-monad {c = ℓ} Squash\n Raw-monad.return raw-monad = [_]\n Raw-monad._>>=_ raw-monad = _>>=′_\n\n monad : Monad {c = ℓ} Squash\n Monad.raw-monad monad = raw-monad\n Monad.left-identity monad = λ _ _ → refl _\n Monad.right-identity monad = λ _ → refl _\n Monad.associativity monad = λ _ _ _ → refl _\n\n------------------------------------------------------------------------\n-- Squash preserves all kinds of functions\n\nprivate\n\n -- Squash preserves functions.\n\n Squash-cong-→ : (A → B) → Squash A → Squash B\n Squash-cong-→ A→B x = x >>=′ return ∘ A→B\n\n-- If A and B are logically equivalent, then Squash A and Squash B are\n-- equivalent.\n\nSquash-cong-⇔ : A ⇔ B → Squash A ≃ Squash B\nSquash-cong-⇔ A⇔B = Eq.↔⇒≃ (record\n { surjection = record\n { logical-equivalence = record\n { to = Squash-cong-→ (_⇔_.to A⇔B)\n ; from = Squash-cong-→ (_⇔_.from A⇔B)\n }\n ; right-inverse-of = λ _ → refl _\n }\n ; left-inverse-of = λ _ → refl _\n })\n\n-- If there is a split surjection from A to B, then Squash A and\n-- Squash B are equivalent.\n\nSquash-cong-↠ : A ↠ B → Squash A ≃ Squash B\nSquash-cong-↠ = Squash-cong-⇔ ∘ _↠_.logical-equivalence\n\nprivate\n\n -- Some lemmas used in Squash-cong.\n\n Squash-cong-↔ : A ↔ B → Squash A ↔ Squash B\n Squash-cong-↔ =\n from-isomorphism ∘ Squash-cong-⇔ ∘ _↔_.logical-equivalence\n\n Squash-cong-≃ : A ≃ B → Squash A ≃ Squash B\n Squash-cong-≃ = Squash-cong-⇔ ∘ _≃_.logical-equivalence\n\n Squash-cong-≃ᴱ : A ≃ᴱ B → Squash A ≃ᴱ Squash B\n Squash-cong-≃ᴱ =\n from-isomorphism ∘ Squash-cong-⇔ ∘ _≃ᴱ_.logical-equivalence\n\n Squash-cong-↣ : A ↣ B → Squash A ↣ Squash B\n Squash-cong-↣ A↣B = record\n { to = Squash-cong-→ (_↣_.to A↣B)\n ; injective = λ _ → refl _\n }\n\n Squash-cong-Embedding :\n Embedding A B → Embedding (Squash A) (Squash B)\n Squash-cong-Embedding A↣B = record\n { to = Squash-cong-→ (Embedding.to A↣B)\n ; is-embedding = λ x y →\n _≃_.is-equivalence $\n _↠_.from (Eq.≃↠⇔ (⇒≡ 1 Squash-propositional)\n (⇒≡ 1 Squash-propositional))\n (record { from = λ _ → refl _ })\n }\n\nSquash-cong : A ↝[ k ] B → Squash A ↝[ k ] Squash B\nSquash-cong {k = implication} = Squash-cong-→\nSquash-cong {k = logical-equivalence} = from-isomorphism ∘ Squash-cong-⇔\nSquash-cong {k = injection} = Squash-cong-↣\nSquash-cong {k = embedding} = Squash-cong-Embedding\nSquash-cong {k = surjection} = from-isomorphism ∘ Squash-cong-↠\nSquash-cong {k = bijection} = Squash-cong-↔\nSquash-cong {k = equivalence} = Squash-cong-≃\nSquash-cong {k = equivalenceᴱ} = Squash-cong-≃ᴱ\n\n------------------------------------------------------------------------\n-- Some isomorphisms\n\n-- Squash ⊤ is isomorphic to ⊤.\n\nSquash-⊤↔⊤ : Squash ⊤ ↔ ⊤\nSquash-⊤↔⊤ = record\n { surjection = record\n { logical-equivalence = record\n { from = λ _ → [ _ ]\n }\n ; right-inverse-of = λ _ → refl _\n }\n ; left-inverse-of = λ _ → refl _\n }\n\n-- Squash ⊥ is isomorphic to ⊥.\n\nSquash-⊥↔⊥ : Squash (⊥ {ℓ = ℓ}) ↔ ⊥ {ℓ = ℓ}\nSquash-⊥↔⊥ = record\n { surjection = record\n { logical-equivalence = record\n { to = λ x → ⊥-in-prop→⊥ (Squash-⊥→⊥-in-prop x)\n ; from = λ ()\n }\n ; right-inverse-of = λ ()\n }\n ; left-inverse-of = λ _ → refl _\n }\n where\n\n -- An empty type in Prop.\n\n data ⊥-in-prop : Prop where\n\n -- Squash ⊥ implies ⊥-in-prop.\n\n Squash-⊥→⊥-in-prop : Squash (⊥ {ℓ = ℓ}) → ⊥-in-prop\n Squash-⊥→⊥-in-prop [ () ]\n\n -- ⊥-in-prop implies ⊥.\n\n ⊥-in-prop→⊥ : ⊥-in-prop → ⊥ {ℓ = ℓ}\n ⊥-in-prop→⊥ ()\n\n-- Squash commutes with _×_.\n--\n-- This lemma was suggested by Jesper Cockx.\n\nSquash-×↔× : Squash (A × B) ↔ Squash A × Squash B\nSquash-×↔× = record\n { surjection = record\n { logical-equivalence = record\n { to = λ p → Squash-cong proj₁ p , Squash-cong proj₂ p\n ; from = λ (x , y) → x >>=′ λ x → y >>=′ λ y → return (x , y)\n }\n ; right-inverse-of = refl\n }\n ; left-inverse-of = refl\n }\n\n-- Squash commutes with ↑ ℓ.\n\nSquash-↑↔↑ : Squash (↑ ℓ A) ↔ ↑ ℓ (Squash A)\nSquash-↑↔↑ = record\n { surjection = record\n { logical-equivalence = record\n { to = λ { x .lower → Squash-cong lower x }\n ; from = λ (lift x) → Squash-cong lift x\n }\n ; right-inverse-of = λ _ → refl _\n }\n ; left-inverse-of = λ _ → refl _\n }\n\n------------------------------------------------------------------------\n-- Some properties\n\n-- ∥ A ∥ implies Squash A.\n\n∥∥→Squash : ∥ A ∥ → Squash A\n∥∥→Squash = Trunc.rec Squash-propositional [_]\n\n-- Squash A implies ¬ ¬ A.\n\nSquash→¬¬ : Squash A → ¬ ¬ A\nSquash→¬¬ {A = A} = curry (\n Squash A × ¬ A ↝⟨ uncurry (flip Squash-cong) ⟩\n Squash ⊥ ↔⟨ Squash-⊥↔⊥ ⟩□\n ⊥ □)\n\n-- It is not in general the case that [ x ] ≡ [ y ] implies\n-- Squash (x ≡ y).\n\n¬-[]≡[]→Squash-≡ :\n ¬ ({A : Type a} {x y : A} → [ x ] ≡ [ y ] → Squash (x ≡ y))\n¬-[]≡[]→Squash-≡ {a = a} =\n ({A : Type a} {x y : A} → [ x ] ≡ [ y ] → Squash (x ≡ y)) ↝⟨ _$ refl _ ⟩\n Squash (lift true ≡ lift false) ↝⟨ Squash-cong (cong lower) ⟩\n Squash (true ≡ false) ↝⟨ Squash-cong Bool.true≢false ⟩\n Squash ⊥ ↔⟨ Squash-⊥↔⊥ ⟩□\n ⊥ □\n\n-- [_] is split surjective for decided types.\n\nSplit-surjective-[] : Dec A → Split-surjective {A = A} [_]\nSplit-surjective-[] (yes x) _ = x , refl _\nSplit-surjective-[] (no ¬x) x =\n ⊥-elim (_↔_.to Squash-⊥↔⊥ (Squash-cong ¬x x))\n\n------------------------------------------------------------------------\n-- Stability\n\n-- A type A is stable if Squash A implies A.\n\nStable : Type a → Type a\nStable A = Squash A → A\n\n-- A type A is very stable if Squash A is equivalent to A.\n\nVery-stable : Type a → Type a\nVery-stable A = Squash A ≃ A\n\n-- Variants of the definitions above for equality.\n\nStable-≡ : Type a → Type a\nStable-≡ = For-iterated-equality 1 Stable\n\nVery-stable-≡ : Type a → Type a\nVery-stable-≡ = For-iterated-equality 1 Very-stable\n\n------------------------------------------------------------------------\n-- Some lemmas related to stability\n\n-- Very stable types are stable.\n\nVery-stable→Stable :\n ∀ n →\n For-iterated-equality n Very-stable A →\n For-iterated-equality n Stable A\nVery-stable→Stable n =\n For-iterated-equality-cong₁ _ n _≃_.to\n\n-- Very-stable is propositional (assuming extensionality).\n\nVery-stable-propositional :\n {A : Type a} →\n Extensionality a a →\n Is-proposition (Very-stable A)\nVery-stable-propositional ext =\n Eq.left-closure ext 0 Squash-propositional\n\nprivate\n\n -- The previous result can be generalised.\n\n For-iterated-equality-Very-stable-propositional :\n {A : Type a} →\n Extensionality a a →\n ∀ n → Is-proposition (For-iterated-equality n Very-stable A)\n For-iterated-equality-Very-stable-propositional ext n =\n H-level-For-iterated-equality ext 1 n\n (Very-stable-propositional ext)\n\n-- A type is very stable if and only if [_] is an equivalence for that\n-- type.\n\nVery-stable↔Is-equivalence-[] :\n {A : Type a} →\n Very-stable A ↝[ a ∣ a ] Is-equivalence {A = A} [_]\nVery-stable↔Is-equivalence-[] =\n generalise-ext?-prop\n (record { from = inverse ∘ Eq.⟨ _ ,_⟩\n ; to = λ s →\n _≃_.is-equivalence $\n Eq.with-other-function\n (inverse s)\n [_]\n (λ _ → refl _)\n })\n Very-stable-propositional\n (λ ext → Eq.propositional ext _)\n\n-- A type is very stable if and only if it is a stable proposition.\n\nVery-stable↔Stable×Is-proposition :\n {A : Type a} →\n Very-stable A ↝[ a ∣ a ] Stable A × Is-proposition A\nVery-stable↔Stable×Is-proposition =\n generalise-ext?-prop\n (record { to = λ s → _≃_.to s\n , H-level-cong _ 1 s Squash-propositional\n ; from = λ (s , prop) →\n _↠_.from (Eq.≃↠⇔ Squash-propositional prop)\n (record { to = s; from = [_] })\n })\n Very-stable-propositional\n (λ ext →\n [inhabited⇒+]⇒+ 0 λ (_ , prop) →\n ×-closure 1\n (Π-closure ext 1 (λ _ → prop))\n (H-level-propositional ext 1))\n\n-- If A has h-level 1 + n and is stable \"n levels up\", then A is very\n-- stable \"n levels up\".\n\nStable→H-level-suc→Very-stable :\n ∀ n →\n For-iterated-equality n Stable A → H-level (suc n) A →\n For-iterated-equality n Very-stable A\nStable→H-level-suc→Very-stable {A = A} n = curry (\n For-iterated-equality n Stable A × H-level (suc n) A ↝⟨ (∃-cong λ _ → lemma) ⟩\n\n For-iterated-equality n Stable A ×\n For-iterated-equality n Is-proposition A ↝⟨ For-iterated-equality-commutes-× n _ ⟩\n\n For-iterated-equality n (λ A → Stable A × Is-proposition A) A ↝⟨ For-iterated-equality-cong₁ _ n $\n uncurry (curry $ _⇔_.from (Very-stable↔Stable×Is-proposition _)) ⟩\n For-iterated-equality n Very-stable A □)\n where\n lemma =\n H-level (suc n) A ↝⟨ _⇔_.to H-level⇔H-level′ ⟩\n H-level′ (suc n) A ↝⟨ inverse-ext? (For-iterated-equality-For-iterated-equality n 1) _ ⟩\n For-iterated-equality n (H-level′ 1) A ↝⟨ For-iterated-equality-cong₁ _ n $\n _⇔_.from (H-level⇔H-level′ {n = 1}) ⟩□\n For-iterated-equality n Is-proposition A □\n\n-- Types with h-level n are very stable \"n levels up\".\n\nH-level→Very-stable :\n ∀ n → H-level n A → For-iterated-equality n Very-stable A\nH-level→Very-stable {A = A} n =\n H-level n A ↝⟨ _⇔_.to H-level⇔H-level′ ⟩\n H-level′ n A ↝⟨ For-iterated-equality-cong₁ _ n Contractible→Very-stable ⟩□\n For-iterated-equality n Very-stable A □\n where\n Contractible→Very-stable :\n ∀ {A} → Contractible A → Very-stable A\n Contractible→Very-stable c =\n _⇔_.from (Very-stable↔Stable×Is-proposition _)\n ( (λ _ → proj₁ c)\n , mono₁ 0 c\n )\n\n-- If A is very stable, then [_] {A = A} is an embedding.\n\nVery-stable→Is-embedding-[] :\n Very-stable A → Is-embedding {A = A} [_]\nVery-stable→Is-embedding-[] s x y =\n _≃_.is-equivalence (\n x ≡ y ↝⟨ inverse $ Eq.≃-≡ $ Eq.⟨ _ , Very-stable↔Is-equivalence-[] _ s ⟩ ⟩□\n [ x ] ≡ [ y ] □)\n\n-- If A is very stable, then [_] {A = A} is split surjective.\n\nVery-stable→Split-surjective-[] :\n Very-stable A → Split-surjective {A = A} [_]\nVery-stable→Split-surjective-[] {A = A} =\n Very-stable A ↝⟨ Very-stable↔Is-equivalence-[] _ ⟩\n Is-equivalence [_] ↝⟨ (λ hyp → _↠_.split-surjective $ _≃_.surjection $ Eq.⟨ _ , hyp ⟩) ⟩\n Split-surjective [_] □\n\n-- Types that are stable for double negation are stable for Squash.\n\n¬¬-Stable→Stable : (¬ ¬ A → A) → Stable A\n¬¬-Stable→Stable ¬¬-Stable x = ¬¬-Stable (Squash→¬¬ x)\n\n-- Types for which it is known whether or not they are inhabited are\n-- stable.\n\nDec→Stable : Dec A → Stable A\nDec→Stable (yes x) _ = x\nDec→Stable (no ¬x) x with () ← Squash→¬¬ x ¬x\n\n-- Every type is stable in the double negation monad.\n\n¬¬-Stable : ¬¬ Stable A\n¬¬-Stable = DN.map′ Dec→Stable DN.excluded-middle\n\n-- Bool is not very stable. (But it is stable, see Dec→Stable above.)\n\n¬-Very-stable-Bool : ¬ Very-stable Bool\n¬-Very-stable-Bool =\n Very-stable Bool ↝⟨ proj₂ ∘ Very-stable↔Stable×Is-proposition _ ⟩\n Is-proposition Bool ↝⟨ ¬-Bool-propositional ⟩□\n ⊥ □\n\n-- If equality is decidable for A, then equality is very stable for A.\n\nDecidable-equality→Very-stable-≡ :\n Decidable-equality A → Very-stable-≡ A\nDecidable-equality→Very-stable-≡ dec _ _ =\n _⇔_.from (Very-stable↔Stable×Is-proposition _)\n ( Dec→Stable (dec _ _)\n , decidable⇒set dec\n )\n\n----------------------------------------------------------------------\n-- Preservation lemmas\n\n-- Stable preserves some kinds of functions (those that are\n-- \"symmetric\"), possibly assuming extensionality.\n\nStable-cong :\n {A : Type a} {B : Type b} →\n Extensionality? ⌊ k ⌋-sym (a ⊔ b) (a ⊔ b) →\n A ↝[ ⌊ k ⌋-sym ] B → Stable A ↝[ ⌊ k ⌋-sym ] Stable B\nStable-cong {k = k} {A = A} {B = B} ext A↝B =\n Stable A ↔⟨⟩\n (Squash A → A) ↝⟨ →-cong ext (Squash-cong A↝B) A↝B ⟩\n (Squash B → B) ↔⟨⟩\n Stable B □\n\n-- A kind of map function for Stable.\n\nStable-map : A ⇔ B → Stable A → Stable B\nStable-map = _⇔_.to ∘ Stable-cong _\n\n-- A kind of map function for Very-stable.\n\nVery-stable-map :\n A ↠ B → Very-stable A → Very-stable B\nVery-stable-map {A = A} {B = B} A↠B s =\n _↠_.from (Eq.≃↠⇔ Squash-propositional B-prop)\n (record { from = [_]\n ; to = Squash B ↝⟨ Squash-cong (_↠_.from A↠B) ⟩\n Squash A ↔⟨ s ⟩\n A ↝⟨ _↠_.to A↠B ⟩□\n B □\n })\n where\n A-prop : Is-proposition A\n A-prop = proj₂ $ Very-stable↔Stable×Is-proposition _ s\n\n B-prop : Is-proposition B\n B-prop = H-level.respects-surjection A↠B 1 A-prop\n\n-- Very-stable preserves equivalences (assuming extensionality).\n\nVery-stable-cong :\n {A : Type a} {B : Type b} →\n Extensionality? k (a ⊔ b) (a ⊔ b) →\n A ≃ B → Very-stable A ↝[ k ] Very-stable B\nVery-stable-cong {A = A} {B = B} ext A≃B =\n Very-stable A ↔⟨⟩\n Squash A ≃ A ↝⟨ generalise-ext?\n (Eq.≃-preserves-⇔ (Squash-cong A≃B) A≃B)\n (λ ext →\n let eq = Eq.≃-preserves ext (Squash-cong-≃ A≃B) A≃B in\n _≃_.right-inverse-of eq , _≃_.left-inverse-of eq)\n ext ⟩\n Squash B ≃ B ↔⟨⟩\n Very-stable B □\n\n------------------------------------------------------------------------\n-- Closure properties\n\n-- Squash A is very stable.\n\nVery-stable-Squash : Very-stable (Squash A)\nVery-stable-Squash =\n _⇔_.from (Very-stable↔Stable×Is-proposition _)\n ( _>>= id\n , Squash-propositional\n )\n\n-- ⊤ is very stable.\n\nVery-stable-⊤ : Very-stable ⊤\nVery-stable-⊤ = Eq.↔⇒≃ Squash-⊤↔⊤\n\n-- ⊥ is very stable.\n\nVery-stable-⊥ : Very-stable (⊥ {ℓ = ℓ})\nVery-stable-⊥ = Eq.↔⇒≃ Squash-⊥↔⊥\n\n-- Stable is closed under Π A.\n\nStable-Π :\n (∀ x → Stable (P x)) →\n Stable ((x : A) → P x)\nStable-Π {P = P} s =\n Squash (∀ x → P x) ↝⟨ (λ s x → Squash-cong (_$ x) s) ⟩\n (∀ x → Squash (P x)) ↝⟨ ∀-cong _ s ⟩□\n (∀ x → P x) □\n\n-- Very-stable is closed under Π A (assuming extensionality).\n\nVery-stable-Π :\n {A : Type a} {P : A → Type p} →\n Extensionality a p →\n (∀ x → Very-stable (P x)) →\n Very-stable ((x : A) → P x)\nVery-stable-Π {P = P} ext s =\n _⇔_.from (Very-stable↔Stable×Is-proposition _)\n ( Stable-Π (Very-stable→Stable 0 ∘ s)\n , (Π-closure ext 1 λ x →\n H-level-cong _ 1 (s x) Squash-propositional)\n )\n\n-- Stable is closed under _×_.\n\nStable-× : Stable A → Stable B → Stable (A × B)\nStable-× {A = A} {B = B} s₁ s₂ =\n Squash (A × B) ↔⟨ Squash-×↔× ⟩\n Squash A × Squash B ↝⟨ s₁ ×-cong s₂ ⟩□\n A × B □\n\n-- Very-stable is closed under _×_.\n\nVery-stable-× : Very-stable A → Very-stable B → Very-stable (A × B)\nVery-stable-× s₁ s₂ =\n _⇔_.from (Very-stable↔Stable×Is-proposition _)\n ( Stable-× (Very-stable→Stable 0 s₁) (Very-stable→Stable 0 s₂)\n , ×-closure 1 (H-level-cong _ 1 s₁ Squash-propositional)\n (H-level-cong _ 1 s₂ Squash-propositional)\n )\n\n-- Stable is closed under ↑ ℓ.\n\nStable-↑ : Stable A → Stable (↑ ℓ A)\nStable-↑ {A = A} s =\n Squash (↑ _ A) ↔⟨ Squash-↑↔↑ ⟩\n ↑ _ (Squash A) ↝⟨ ↑-cong s ⟩□\n ↑ _ A □\n\n-- Very-stable is closed under ↑ ℓ.\n\nVery-stable-↑ : Very-stable A → Very-stable (↑ ℓ A)\nVery-stable-↑ {A = A} s =\n Squash (↑ _ A) ↔⟨ Squash-↑↔↑ ⟩\n ↑ _ (Squash A) ↝⟨ ↑-cong s ⟩□\n ↑ _ A □\n\n-- If A is very stable, then equality is very stable for A.\n\nVery-stable→Very-stable-≡ :\n ∀ n →\n For-iterated-equality n Very-stable A →\n For-iterated-equality (suc n) Very-stable A\nVery-stable→Very-stable-≡ {A = A} n =\n For-iterated-equality n Very-stable A ↝⟨ For-iterated-equality-cong₁ _ n lemma ⟩\n For-iterated-equality n Very-stable-≡ A ↝⟨ For-iterated-equality-For-iterated-equality n 1 _ ⟩□\n For-iterated-equality (suc n) Very-stable A □\n where\n lemma : ∀ {A} → Very-stable A → Very-stable-≡ A\n lemma {A = A} s x y =\n _⇔_.from (Very-stable↔Stable×Is-proposition _)\n ( (Squash (x ≡ y) ↝⟨ const prop ⟩\n Is-proposition A ↝⟨ +⇒≡ ⟩\n Contractible (x ≡ y) ↝⟨ proj₁ ⟩□\n x ≡ y □)\n , ⇒≡ 1 prop\n )\n where\n prop : Is-proposition A\n prop = proj₂ $ _⇔_.to (Very-stable↔Stable×Is-proposition _) s\n\nprivate\n\n -- Some examples showing how Very-stable→Very-stable-≡ can be\n -- used.\n\n -- Equalities between erased values are very stable.\n\n Very-stable-≡₀ : Very-stable-≡ (Squash A)\n Very-stable-≡₀ = Very-stable→Very-stable-≡ 0 Very-stable-Squash\n\n -- Equalities between equalities between erased values are very\n -- stable.\n\n Very-stable-≡₁ : For-iterated-equality 2 Very-stable (Squash A)\n Very-stable-≡₁ = Very-stable→Very-stable-≡ 1 Very-stable-≡₀\n\n -- And so on…\n\nprivate\n\n -- A lemma.\n\n For-iterated-equality-Is-proposition↔H-level′-suc :\n {A : Type a} →\n ∀ n →\n For-iterated-equality n Is-proposition A ↝[ a ∣ a ]\n H-level′ (suc n) A\n For-iterated-equality-Is-proposition↔H-level′-suc {A = A} n ext =\n For-iterated-equality n Is-proposition A ↝⟨ For-iterated-equality-cong₁ ext n (H-level↔H-level′ {n = 1} ext) ⟩\n For-iterated-equality n (H-level′ 1) A ↝⟨ For-iterated-equality-For-iterated-equality n 1 ext ⟩□\n H-level′ (suc n) A □\n\n-- If A is \"stable 1 + n levels up\", then H-level′ (suc n) A is\n-- stable.\n\nStable-H-level′ :\n ∀ n →\n For-iterated-equality (suc n) Stable A →\n Stable (H-level′ (suc n) A)\nStable-H-level′ {A = A} n =\n For-iterated-equality (suc n) Stable A ↝⟨ inverse-ext? (For-iterated-equality-For-iterated-equality n 1) _ ⟩\n For-iterated-equality n Stable-≡ A ↝⟨ For-iterated-equality-cong₁ _ n lemma ⟩\n For-iterated-equality n (Stable ∘ Is-proposition) A ↝⟨ For-iterated-equality-commutes-← _ Stable n Stable-Π ⟩\n Stable (For-iterated-equality n Is-proposition A) ↝⟨ Stable-map (For-iterated-equality-Is-proposition↔H-level′-suc n _) ⟩□\n Stable (H-level′ (suc n) A) □\n where\n lemma : ∀ {A} → Stable-≡ A → Stable (Is-proposition A)\n lemma s =\n Stable-Π λ _ →\n Stable-Π λ _ →\n s _ _\n\n-- If A is \"stable 1 + n levels up\", then H-level (suc n) A is\n-- stable.\n\nStable-H-level :\n ∀ n →\n For-iterated-equality (suc n) Stable A →\n Stable (H-level (suc n) A)\nStable-H-level {A = A} n =\n For-iterated-equality (suc n) Stable A ↝⟨ Stable-H-level′ n ⟩\n Stable (H-level′ (suc n) A) ↝⟨ Stable-map (record { to = inverse-ext? H-level↔H-level′ _; from = H-level↔H-level′ _ }) ⟩□\n Stable (H-level (suc n) A) □\n\n-- If A is \"very stable 1 + n levels up\", then H-level′ (suc n) A is\n-- very stable (assuming extensionality).\n\nVery-stable-H-level′ :\n {A : Type a} →\n Extensionality a a →\n ∀ n →\n For-iterated-equality (suc n) Very-stable A →\n Very-stable (H-level′ (suc n) A)\nVery-stable-H-level′ {A = A} ext n =\n For-iterated-equality (suc n) Very-stable A ↝⟨ inverse-ext? (For-iterated-equality-For-iterated-equality n 1) _ ⟩\n For-iterated-equality n Very-stable-≡ A ↝⟨ For-iterated-equality-cong₁ _ n lemma ⟩\n For-iterated-equality n (Very-stable ∘ Is-proposition) A ↝⟨ For-iterated-equality-commutes-← _ Very-stable n (Very-stable-Π ext) ⟩\n Very-stable (For-iterated-equality n Is-proposition A) ↝⟨ Very-stable-map (For-iterated-equality-Is-proposition↔H-level′-suc n ext) ⟩□\n Very-stable (H-level′ (suc n) A) □\n where\n lemma : ∀ {A} → Very-stable-≡ A → Very-stable (Is-proposition A)\n lemma s =\n Very-stable-Π ext λ _ →\n Very-stable-Π ext λ _ →\n s _ _\n\n-- If A is \"very stable 1 + n levels up\", then H-level (suc n) A is\n-- very stable (assuming extensionality).\n\nVery-stable-H-level :\n {A : Type a} →\n Extensionality a a →\n ∀ n →\n For-iterated-equality (suc n) Very-stable A →\n Very-stable (H-level (suc n) A)\nVery-stable-H-level {A = A} ext n =\n For-iterated-equality (suc n) Very-stable A ↝⟨ Very-stable-H-level′ ext n ⟩\n Very-stable (H-level′ (suc n) A) ↝⟨ Very-stable-cong _ (inverse $ H-level↔H-level′ ext) ⟩□\n Very-stable (H-level (suc n) A) □\n\n-- If equality is stable for A and B, then it is stable for A ⊎ B.\n\nStable-≡-⊎ :\n ∀ n →\n For-iterated-equality (suc n) Stable A →\n For-iterated-equality (suc n) Stable B →\n For-iterated-equality (suc n) Stable (A ⊎ B)\nStable-≡-⊎ n sA sB =\n For-iterated-equality-⊎-suc\n n\n (Stable-map ∘ from-isomorphism)\n (Very-stable→Stable 0 Very-stable-⊥)\n (For-iterated-equality-↑ _ (suc n) (Stable-map ∘ from-isomorphism) sA)\n (For-iterated-equality-↑ _ (suc n) (Stable-map ∘ from-isomorphism) sB)\n\n-- If equality is very stable for A and B, then it is very stable\n-- for A ⊎ B.\n\nVery-stable-≡-⊎ :\n ∀ n →\n For-iterated-equality (suc n) Very-stable A →\n For-iterated-equality (suc n) Very-stable B →\n For-iterated-equality (suc n) Very-stable (A ⊎ B)\nVery-stable-≡-⊎ n sA sB =\n For-iterated-equality-⊎-suc\n n\n lemma\n Very-stable-⊥\n (For-iterated-equality-↑ _ (suc n) lemma sA)\n (For-iterated-equality-↑ _ (suc n) lemma sB)\n where\n lemma : A ↔ B → Very-stable A → Very-stable B\n lemma = Very-stable-cong _ ∘ from-isomorphism\n\n-- If equality is stable for A, then it is stable for List A.\n\nStable-≡-List :\n ∀ n →\n For-iterated-equality (suc n) Stable A →\n For-iterated-equality (suc n) Stable (List A)\nStable-≡-List n =\n For-iterated-equality-List-suc\n n\n (Stable-map ∘ from-isomorphism)\n (Very-stable→Stable 0 $ Very-stable-↑ Very-stable-⊤)\n (Very-stable→Stable 0 Very-stable-⊥)\n Stable-×\n\n-- If equality is very stable for A, then it is very stable for\n-- List A.\n\nVery-stable-≡-List :\n ∀ n →\n For-iterated-equality (suc n) Very-stable A →\n For-iterated-equality (suc n) Very-stable (List A)\nVery-stable-≡-List n =\n For-iterated-equality-List-suc\n n\n (Very-stable-cong _ ∘ from-isomorphism)\n (Very-stable-↑ Very-stable-⊤)\n Very-stable-⊥\n Very-stable-×\n\n----------------------------------------------------------------------\n-- Simple corollaries or variants of results above\n\n-- A generalisation of Stable-Π.\n\nStable-Πⁿ :\n {A : Type a} {P : A → Type p} →\n Extensionality a p →\n ∀ n →\n (∀ x → For-iterated-equality n Stable (P x)) →\n For-iterated-equality n Stable ((x : A) → P x)\nStable-Πⁿ ext n =\n For-iterated-equality-Π\n ext\n n\n (Stable-map ∘ from-isomorphism)\n Stable-Π\n\n-- A generalisation of Very-stable-Π.\n\nVery-stable-Πⁿ :\n {A : Type a} {P : A → Type p} →\n Extensionality a p →\n ∀ n →\n (∀ x → For-iterated-equality n Very-stable (P x)) →\n For-iterated-equality n Very-stable ((x : A) → P x)\nVery-stable-Πⁿ ext n =\n For-iterated-equality-Π\n ext\n n\n (Very-stable-cong _ ∘ from-isomorphism)\n (Very-stable-Π ext)\n\n-- A generalisation of Stable-×.\n\nStable-×ⁿ :\n ∀ n →\n For-iterated-equality n Stable A →\n For-iterated-equality n Stable B →\n For-iterated-equality n Stable (A × B)\nStable-×ⁿ n =\n For-iterated-equality-×\n n\n (Stable-map ∘ from-isomorphism)\n Stable-×\n\n-- A generalisation of Very-stable-×.\n\nVery-stable-×ⁿ :\n ∀ n →\n For-iterated-equality n Very-stable A →\n For-iterated-equality n Very-stable B →\n For-iterated-equality n Very-stable (A × B)\nVery-stable-×ⁿ n =\n For-iterated-equality-×\n n\n (Very-stable-cong _ ∘ from-isomorphism)\n Very-stable-×\n\n-- A generalisation of Stable-↑.\n\nStable-↑ⁿ :\n ∀ n →\n For-iterated-equality n Stable A →\n For-iterated-equality n Stable (↑ ℓ A)\nStable-↑ⁿ n =\n For-iterated-equality-↑ _ n (Stable-map ∘ from-isomorphism)\n\n-- A generalisation of Very-stable-↑.\n\nVery-stable-↑ⁿ :\n ∀ n →\n For-iterated-equality n Very-stable A →\n For-iterated-equality n Very-stable (↑ ℓ A)\nVery-stable-↑ⁿ n =\n For-iterated-equality-↑\n _\n n\n (Very-stable-cong _ ∘ from-isomorphism)\n", "meta": {"hexsha": "cd95c1f8532dea65fdda7c6255ebd441916396a1", "size": 26633, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Squash.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/Squash.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/Squash.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": 30.5774971297, "max_line_length": 139, "alphanum_fraction": 0.5733488529, "num_tokens": 9560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.640635868562172, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.3601504309302159}} {"text": "-- Andreas, 2014-05-20 Triggered by Andrea Vezzosi & NAD\n{-# OPTIONS --copatterns #-}\n-- {-# OPTIONS -v tc.conv.coerce:10 #-}\n\nopen import Common.Size\n\n-- Andreas, 2015-03-16: currently forbidden\n-- Size≤ : Size → SizeUniv\n-- Size≤ i = Size< ↑ i\n\npostulate\n Dom : Size → Set\n mapDom : ∀ i (j : Size< (↑ i)) → Dom i → Dom j\n\nrecord ∞Dom i : Set where\n field\n force : ∀ (j : Size< i) → Dom j\n\n∞mapDom : ∀ i (j : Size< (↑ i)) → ∞Dom i → ∞Dom j\n∞Dom.force (∞mapDom i j x) k = mapDom k k (∞Dom.force x k)\n\n-- The second k on the rhs has type\n-- k : Size< j\n-- and should have type\n-- k : Size≤ k = Size< ↑ k\n-- Since j <= ↑ k does not hold (we have only k < j),\n-- we cannot do the usual subtyping Size< j <= Size≤ k,\n-- but we have to use the \"singleton type property\"\n-- k : Size< ↑ k\n", "meta": {"hexsha": "1236419d33305dd973f66dc1ae7acf805f0eb748", "size": 798, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1136.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_issues_repo_path": "test/Succeed/Issue1136.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_forks_repo_path": "test/Succeed/Issue1136.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "avg_line_length": 26.6, "max_line_length": 58, "alphanum_fraction": 0.5827067669, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.640635868562172, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.3601504309302159}} {"text": "{-# OPTIONS --rewriting --prop #-}\n\nopen import common\nopen import common using (_===_)\nopen import syntx\nopen import derivability\nopen import structuralrules\nopen import typingrules\n\n\n{- Type theories -}\n\nΣ₀ : Signature\nSymbols Σ₀ ar = Empty\n\nE₀ : DerivabilityStructure Σ₀\nE₀ = StructuralRules Σ₀\n\n\ndata TypeTheory : Set\nTTSig : TypeTheory → Signature\nTTDer : (t : TypeTheory) → DerivabilityStructure (TTSig t)\n\ndata TypeTheory where\n ◇ : TypeTheory\n _,_ : (t : TypeTheory) {ar : SyntaxArity} (r : TypingRule (TTDer t) (args ar) (sort ar)) → TypeTheory\n _,=_ : (t : TypeTheory) {ar : SyntaxArityArgs} {k : SyntaxSort} (r : EqualityRule (TTDer t) ar k) → TypeTheory\n\nTTSig ◇ = Σ₀\nTTSig (_,_ t {ar} r) = ExtSig (TTSig t) ar\nTTSig (t ,= _) = TTSig t\n\nTTDer ◇ = E₀\nTTDer (t , r) = extend (TTDer t) (TRules r)\nTTDer (t ,= r) = extendE (TTDer t) (ERule r)\n\n{- Instances to make it possible to use numeric literals to refer to symbols and typing rules -}\n\ninstance\n NumΣ₀ : Number Empty\n Number.Constraint NumΣ₀ n = Empty\n\n NumExtSig : {A : SyntaxArity → Set} {ar ar' : SyntaxArity} {{_ : Number (A ar')}} → Number (ExtSigSymbols A ar ar')\n Number.Constraint (NumExtSig {ar = ar} {ar'}) zero = ar === ar'\n Number.Constraint (NumExtSig {{r}}) (suc n) = Number.Constraint r n\n Number.fromNat NumExtSig zero {{refl}} = new\n Number.fromNat (NumExtSig {{r}}) (suc n) = prev (Number.fromNat r n)\n\ninstance\n NumExtT : {A : JudgmentArity → Set} {ar : SyntaxArity} {ar' : JudgmentArity} {{_ : Number (A ar')}} → Number (ExtT A ar ar')\n Number.Constraint (NumExtT {ar = ar} {ar'}) zero = TArity ar === ar'\n Number.Constraint (NumExtT {{r}}) (suc n) = Number.Constraint r n\n Number.fromNat NumExtT zero {{refl}} = typingrule\n Number.fromNat (NumExtT {{r}}) (suc n) = prev (Number.fromNat r n)\n\n NumExtC : {A : JudgmentArity → Set} {ar : SyntaxArity} {ar' : JudgmentArity} {{_ : Number (A ar')}} → Number (ExtC A ar ar')\n Number.Constraint (NumExtC {ar = ar} {ar'}) zero = CArity ar === ar'\n Number.Constraint (NumExtC {{r}}) (suc n) = Number.Constraint r n\n Number.fromNat NumExtC zero {{refl}} = congruencerule\n Number.fromNat (NumExtC {{r}}) (suc n) = prev (Number.fromNat r n)\n\n NumExtE : {A : JudgmentArity → Set} {nar ar' : JudgmentArity} {{_ : Number (A ar')}} → Number (ExtE A nar ar')\n Number.Constraint (NumExtE {nar = nar} {ar'}) zero = nar === ar'\n Number.Constraint (NumExtE {{r}}) (suc n) = Number.Constraint r n\n Number.fromNat NumExtE zero {{refl}} = equalityrule\n Number.fromNat (NumExtE {{r}}) (suc n) = prev (Number.fromNat r n)\n", "meta": {"hexsha": "72deec14a20f02f50570ef94787b406b56fe7ac7", "size": 2555, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "typetheories.agda", "max_stars_repo_name": "guillaumebrunerie/general-type-theories", "max_stars_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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": "typetheories.agda", "max_issues_repo_name": "guillaumebrunerie/general-type-theories", "max_issues_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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": "typetheories.agda", "max_forks_repo_name": "guillaumebrunerie/general-type-theories", "max_forks_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "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.1343283582, "max_line_length": 126, "alphanum_fraction": 0.6618395303, "num_tokens": 863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191337850933, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3600483281370349}} {"text": "open import Data.Sum using ( _⊎_ ; inj₁ ; inj₂ )\nopen import Relation.Binary.PropositionalEquality using ( refl )\nopen import Web.Semantic.DL.ABox.Interp using ( ⌊_⌋ ; ind ; _*_ )\nopen import Web.Semantic.DL.ABox.Model using\n ( _⊨a_ ; ⊨a-resp-≡³ ; on-bnode ; bnodes ; _,_ )\nopen import Web.Semantic.DL.Category.Object using ( Object ; IN )\nopen import Web.Semantic.DL.Category.Morphism using\n ( _⇒_ ; BN ; impl ; _⊑_ ; _≣_ ; _,_ )\nopen import Web.Semantic.DL.Category.Composition using ( _∙_ )\nopen import Web.Semantic.DL.Category.Tensor using ( _⊗_ ; _⟨⊗⟩_ )\nopen import Web.Semantic.DL.Category.Wiring using ( identity ; id✓ )\nopen import Web.Semantic.DL.Category.Properties.Composition.Lemmas using\n ( compose-left ; compose-right ; compose-resp-⊨a )\nopen import Web.Semantic.DL.Category.Properties.Tensor.Lemmas using\n ( tensor-up ; tensor-down ; tensor-resp-⊨a )\nopen import Web.Semantic.DL.Category.Properties.Tensor.RespectsWiring using\n ( tensor-resp-wiring )\nopen import Web.Semantic.DL.Signature using ( Signature )\nopen import Web.Semantic.DL.TBox using ( TBox )\nopen import Web.Semantic.DL.TBox.Interp using ( Δ )\nopen import Web.Semantic.Util using\n ( id ; _∘_ ; _⊕_⊕_ ; inode ; bnode ; enode ; left ; right ; up ; down )\n\nmodule Web.Semantic.DL.Category.Properties.Tensor.Functor\n {Σ : Signature} {S T : TBox Σ} where\n\ntensor-resp-id : ∀ (A₁ A₂ : Object S T) →\n ((identity A₁ ⟨⊗⟩ identity A₂) ≣ identity (A₁ ⊗ A₂))\ntensor-resp-id A₁ A₂ = \n tensor-resp-wiring A₁ A₂ A₁ A₂ \n id (id✓ A₁) id (id✓ A₂) id (id✓ (A₁ ⊗ A₂))\n (λ x → refl) (λ x → refl)\n\ntensor-resp-compose : ∀ {A₁ A₂ B₁ B₂ C₁ C₂ : Object S T}\n (F₁ : A₁ ⇒ B₁) (F₂ : A₂ ⇒ B₂) (G₁ : B₁ ⇒ C₁) (G₂ : B₂ ⇒ C₂) →\n (((F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂)) ≣ ((F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂)))\ntensor-resp-compose {A₁} {A₂} {B₁} {B₂} {C₁} {C₂} F₁ F₂ G₁ G₂ = \n (LHS⊑RHS , RHS⊑LHS) where\n\n LHS⊑RHS : (F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂) ⊑ (F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂)\n LHS⊑RHS I I⊨STA₁A₂ I⊨LHS = (f , I⊨RHS) where\n\n f : ((BN F₁ ⊎ BN F₂) ⊕ (IN B₁ ⊎ IN B₂) ⊕ (BN G₁ ⊎ BN G₂)) → Δ ⌊ I ⌋\n f (inode (inj₁ v)) = ind I (bnode (inj₁ (inode v)))\n f (inode (inj₂ v)) = ind I (bnode (inj₂ (inode v)))\n f (bnode (inj₁ y)) = ind I (bnode (inj₁ (bnode y)))\n f (bnode (inj₂ y)) = ind I (bnode (inj₂ (bnode y)))\n f (enode (inj₁ w)) = ind I (bnode (inj₁ (enode w)))\n f (enode (inj₂ w)) = ind I (bnode (inj₂ (enode w)))\n\n Iˡ₁⊨F₁ : up * left * bnodes I f ⊨a impl F₁\n Iˡ₁⊨F₁ = ⊨a-resp-≡³ \n (left * up * I) (on-bnode f (ind I) ∘ left ∘ up) refl (impl F₁) \n (compose-left F₁ G₁ (up * I) (tensor-up (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS))\n\n Iˡ₂⊨F₂ : down * (left * bnodes I f) ⊨a impl F₂\n Iˡ₂⊨F₂ = ⊨a-resp-≡³ \n (left * down * I) (on-bnode f (ind I) ∘ left ∘ down) refl (impl F₂)\n (compose-left F₂ G₂ (down * I) (tensor-down (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS))\n\n Iʳ₁⊨G₁ : up * (right * bnodes I f) ⊨a impl G₁\n Iʳ₁⊨G₁ = ⊨a-resp-≡³\n (right * up * I) (on-bnode f (ind I) ∘ right ∘ up) refl (impl G₁) \n (compose-right F₁ G₁ (up * I) (tensor-up (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS))\n\n Iʳ₂⊨G₂ : down * (right * bnodes I f) ⊨a impl G₂\n Iʳ₂⊨G₂ = ⊨a-resp-≡³\n (right * down * I) (on-bnode f (ind I) ∘ right ∘ down) refl (impl G₂) \n (compose-right F₂ G₂ (down * I) (tensor-down (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS))\n\n I⊨RHS : bnodes I f ⊨a impl ((F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂))\n I⊨RHS = compose-resp-⊨a (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) (bnodes I f) \n (tensor-resp-⊨a F₁ F₂ (left * bnodes I f) Iˡ₁⊨F₁ Iˡ₂⊨F₂) \n (tensor-resp-⊨a G₁ G₂ (right * bnodes I f) Iʳ₁⊨G₁ Iʳ₂⊨G₂) \n\n RHS⊑LHS : (F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂) ⊑ (F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂)\n RHS⊑LHS I I⊨STA₁A₂ I⊨RHS = (f , I⊨LHS) where\n\n f : ((BN F₁ ⊕ IN B₁ ⊕ BN G₁) ⊎ (BN F₂ ⊕ IN B₂ ⊕ BN G₂)) → Δ ⌊ I ⌋\n f (inj₁ (inode v)) = ind I (bnode (inode (inj₁ v)))\n f (inj₁ (bnode y)) = ind I (bnode (bnode (inj₁ y)))\n f (inj₁ (enode w)) = ind I (bnode (enode (inj₁ w)))\n f (inj₂ (inode v)) = ind I (bnode (inode (inj₂ v)))\n f (inj₂ (bnode y)) = ind I (bnode (bnode (inj₂ y)))\n f (inj₂ (enode w)) = ind I (bnode (enode (inj₂ w)))\n\n I₁ˡ⊨F₁ : left * up * bnodes I f ⊨a impl F₁\n I₁ˡ⊨F₁ = ⊨a-resp-≡³\n (up * left * I) (on-bnode f (ind I) ∘ up ∘ left) refl (impl F₁)\n (tensor-up F₁ F₂ (left * I) (compose-left (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS))\n\n I₁ʳ⊨G₁ : right * up * bnodes I f ⊨a impl G₁\n I₁ʳ⊨G₁ = ⊨a-resp-≡³\n (up * right * I) (on-bnode f (ind I) ∘ up ∘ right) refl (impl G₁)\n (tensor-up G₁ G₂ (right * I) (compose-right (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS))\n\n I₂ˡ⊨F₂ : left * down * bnodes I f ⊨a impl F₂\n I₂ˡ⊨F₂ = ⊨a-resp-≡³\n (down * left * I) (on-bnode f (ind I) ∘ down ∘ left) refl (impl F₂)\n (tensor-down F₁ F₂ (left * I) (compose-left (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS))\n\n I₂ʳ⊨G₂ : right * down * bnodes I f ⊨a impl G₂\n I₂ʳ⊨G₂ = ⊨a-resp-≡³\n (down * right * I) (on-bnode f (ind I) ∘ down ∘ right) refl (impl G₂)\n (tensor-down G₁ G₂ (right * I) (compose-right (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS))\n \n I⊨LHS : bnodes I f ⊨a impl ((F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂))\n I⊨LHS = tensor-resp-⊨a (F₁ ∙ G₁) (F₂ ∙ G₂) (bnodes I f) \n (compose-resp-⊨a F₁ G₁ (up * bnodes I f) I₁ˡ⊨F₁ I₁ʳ⊨G₁) \n (compose-resp-⊨a F₂ G₂ (down * bnodes I f) I₂ˡ⊨F₂ I₂ʳ⊨G₂) \n", "meta": {"hexsha": "f75d055a1873f3d879ebda6e32fb15912b83309f", "size": 5229, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Web/Semantic/DL/Category/Properties/Tensor/Functor.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/Category/Properties/Tensor/Functor.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/Category/Properties/Tensor/Functor.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": 47.1081081081, "max_line_length": 85, "alphanum_fraction": 0.5656913368, "num_tokens": 2592, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191337850932, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.36004832813703486}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Empty type\n------------------------------------------------------------------------\n\nmodule Data.Empty where\n\nopen import Level\n\ndata ⊥ : Set where\n\n{-# IMPORT Data.FFI #-}\n{-# COMPILED_DATA ⊥ Data.FFI.AgdaEmpty #-}\n\n⊥-elim : ∀ {w} {Whatever : Set w} → ⊥ → Whatever\n⊥-elim ()\n", "meta": {"hexsha": "b32d11b5cb21f365328ae2b27164dc4f776d7d11", "size": 384, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Data/Empty.agda", "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_issues_repo_path": "agda-stdlib-0.9/src/Data/Empty.agda", "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_licenses": ["Apache-2.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": "agda-stdlib-0.9/src/Data/Empty.agda", "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.3333333333, "max_line_length": 72, "alphanum_fraction": 0.3880208333, "num_tokens": 80, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6113819874558604, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.3600362071599912}} {"text": "------------------------------------------------------------------------------\n-- Properties for the bisimilarity relation\n------------------------------------------------------------------------------\n\n{-# OPTIONS --exact-split #-}\n{-# OPTIONS --no-sized-types #-}\n{-# OPTIONS --no-universe-polymorphism #-}\n{-# OPTIONS --without-K #-}\n\nmodule FOTC.Relation.Binary.Bisimilarity.PropertiesI where\n\nopen import FOTC.Base\nopen import FOTC.Base.List\nopen import FOTC.Base.List.PropertiesI\nopen import FOTC.Base.PropertiesI\nopen import FOTC.Data.Stream.Type\nopen import FOTC.Relation.Binary.Bisimilarity.Type\n\n------------------------------------------------------------------------------\n-- Because a greatest post-fixed point is a fixed-point, the\n-- bisimilarity relation _≈_ on unbounded lists is also a pre-fixed\n-- point of the bisimulation functional (see\n-- FOTC.Relation.Binary.Bisimulation).\n≈-in : ∀ {xs ys} →\n ∃[ x' ] ∃[ xs' ] ∃[ ys' ]\n xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ xs' ≈ ys' →\n xs ≈ ys\n≈-in h = ≈-coind B h' h\n where\n B : D → D → Set\n B xs ys = ∃[ x' ] ∃[ xs' ] ∃[ ys' ]\n xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ xs' ≈ ys'\n\n h' : ∀ {xs} {ys} → B xs ys →\n ∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ B xs' ys'\n h' (x' , xs' , ys' , prf₁ , prf₂ , xs'≈ys') =\n x' , xs' , ys' , prf₁ , prf₂ , ≈-out xs'≈ys'\n\n≈-refl : ∀ {xs} → Stream xs → xs ≈ xs\n≈-refl {xs} Sxs = ≈-coind B h₁ h₂\n where\n B : D → D → Set\n B xs ys = Stream xs ∧ xs ≡ ys\n\n h₁ : ∀ {xs ys} → B xs ys →\n ∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ B xs' ys'\n h₁ (Sxs , refl) with Stream-out Sxs\n ... | x' , xs' , prf , Sxs' =\n x' , xs' , xs' , prf , prf , (Sxs' , refl)\n\n h₂ : B xs xs\n h₂ = Sxs , refl\n\n≈-sym : ∀ {xs ys} → xs ≈ ys → ys ≈ xs\n≈-sym {xs} {ys} xs≈ys = ≈-coind B h₁ h₂\n where\n B : D → D → Set\n B xs ys = ys ≈ xs\n\n h₁ : ∀ {ys xs} → B ys xs →\n ∃[ y' ] ∃[ ys' ] ∃[ xs' ] ys ≡ y' ∷ ys' ∧ xs ≡ y' ∷ xs' ∧ B ys' xs'\n h₁ Bxsys with ≈-out Bxsys\n ... | y' , ys' , xs' , prf₁ , prf₂ , ys'≈xs' =\n y' , xs' , ys' , prf₂ , prf₁ , ys'≈xs'\n\n h₂ : B ys xs\n h₂ = xs≈ys\n\n≈-trans : ∀ {xs ys zs} → xs ≈ ys → ys ≈ zs → xs ≈ zs\n≈-trans {xs} {ys} {zs} xs≈ys ys≈zs = ≈-coind B h₁ h₂\n where\n B : D → D → Set\n B xs zs = ∃[ ys ] xs ≈ ys ∧ ys ≈ zs\n\n h₁ : ∀ {as} {cs} → B as cs →\n ∃[ a' ] ∃[ as' ] ∃[ cs' ] as ≡ a' ∷ as' ∧ cs ≡ a' ∷ cs' ∧ B as' cs'\n h₁ {cs = cs} (bs , as≈bs , bs≈cs) with ≈-out as≈bs\n ... | a' , as' , bs' , prf₁ , prf₂ , as'≈bs' with ≈-out bs≈cs\n ... | b' , bs'' , cs' , prf₃ , prf₄ , bs''≈cs' =\n a'\n , as'\n , cs'\n , prf₁\n , subst (λ t → cs ≡ t ∷ cs') b'≡a' prf₄\n , (bs' , as'≈bs' , subst (λ t → t ≈ cs') bs''≡bs' bs''≈cs')\n where\n b'≡a' : b' ≡ a'\n b'≡a' = ∧-proj₁ (∷-injective (trans (sym prf₃) prf₂))\n\n bs''≡bs' : bs'' ≡ bs'\n bs''≡bs' = ∧-proj₂ (∷-injective (trans (sym prf₃) prf₂))\n\n h₂ : B xs zs\n h₂ = ys , (xs≈ys , ys≈zs)\n\n∷-injective≈ : ∀ {x xs ys} → x ∷ xs ≈ x ∷ ys → xs ≈ ys\n∷-injective≈ {x} {xs} {ys} h with ≈-out h\n... | x' , xs' , ys' , prf₁ , prf₂ , prf₃ = xs≈ys\n where\n xs≡xs' : xs ≡ xs'\n xs≡xs' = ∧-proj₂ (∷-injective prf₁)\n\n ys≡ys' : ys ≡ ys'\n ys≡ys' = ∧-proj₂ (∷-injective prf₂)\n\n xs≈ys : xs ≈ ys\n xs≈ys = subst (λ t → t ≈ ys)\n (sym xs≡xs')\n (subst (_≈_ xs') (sym ys≡ys') prf₃)\n\n∷-rightCong≈ : ∀ {x xs ys} → xs ≈ ys → x ∷ xs ≈ x ∷ ys\n∷-rightCong≈ {x} {xs} {ys} h = ≈-in (x , xs , ys , refl , refl , h)\n", "meta": {"hexsha": "2c4d54c1b56764afee4cff0736e6a73bb5cb98ee", "size": 3512, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/fot/FOTC/Relation/Binary/Bisimilarity/PropertiesI.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": "src/fot/FOTC/Relation/Binary/Bisimilarity/PropertiesI.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": "src/fot/FOTC/Relation/Binary/Bisimilarity/PropertiesI.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": 31.0796460177, "max_line_length": 78, "alphanum_fraction": 0.437642369, "num_tokens": 1559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.611381973294151, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.36003619882031446}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Base\n\nmodule lib.PathGroupoid where\n\nmodule _ {i} {A : Type i} where\n\n {- Concatenation of paths\n\n There are two different definitions of concatenation of paths, [_∙_] and [_∙'_],\n with different definitionnal behaviour. Maybe we should have only one but it’s\n sometimes useful to have both (in particular in lib.types.Paths).\n -}\n\n infixr 80 _∙_ _∙'_\n\n _∙_ : {x y z : A}\n → (x == y → y == z → x == z)\n idp ∙ q = q\n\n _∙'_ : {x y z : A}\n → (x == y → y == z → x == z)\n q ∙' idp = q\n\n ∙=∙' : {x y z : A} (p : x == y) (q : y == z)\n → p ∙ q == p ∙' q\n ∙=∙' idp idp = idp\n\n ∙'=∙ : {x y z : A} (p : x == y) (q : y == z)\n → p ∙' q == p ∙ q\n ∙'=∙ idp idp = idp\n\n ∙-assoc : {x y z t : A} (p : x == y) (q : y == z) (r : z == t)\n → (p ∙ q) ∙ r == p ∙ (q ∙ r)\n ∙-assoc idp _ _ = idp\n\n ∙'-assoc : {x y z t : A} (p : x == y) (q : y == z) (r : z == t)\n → (p ∙' q) ∙' r == p ∙' (q ∙' r)\n ∙'-assoc _ _ idp = idp\n\n -- [∙-unit-l] and [∙'-unit-r] are definitional\n\n ∙-unit-r : {x y : A} (q : x == y) → q ∙ idp == q\n ∙-unit-r idp = idp\n\n ∙'-unit-l : {x y : A} (q : x == y) → idp ∙' q == q\n ∙'-unit-l idp = idp\n\n {- Reversal of paths -}\n\n ! : {x y : A} → (x == y → y == x)\n ! idp = idp\n\n !-inv-l : {x y : A} (p : x == y) → (! p) ∙ p == idp\n !-inv-l idp = idp\n\n !-inv'-l : {x y : A} (p : x == y) → (! p) ∙' p == idp\n !-inv'-l idp = idp\n\n !-inv-r : {x y : A} (p : x == y) → p ∙ (! p) == idp\n !-inv-r idp = idp\n\n !-inv'-r : {x y : A} (p : x == y) → p ∙' (! p) == idp\n !-inv'-r idp = idp\n\n {- Interactions between operations\n\n A lemma of the form [!-∙ …] gives a result of the form [! (_∙_ …) == …],\n and so on.\n -}\n\n !-∙ : {x y z : A} (p : x == y) (q : y == z) → ! (p ∙ q) == ! q ∙ ! p\n !-∙ idp idp = idp\n\n ∙-! : {x y z : A} (q : y == z) (p : x == y) → ! q ∙ ! p == ! (p ∙ q)\n ∙-! idp idp = idp\n\n !-∙' : {x y z : A} (p : x == y) (q : y == z) → ! (p ∙' q) == ! q ∙' ! p\n !-∙' idp idp = idp\n\n ∙'-! : {x y z : A} (q : y == z) (p : x == y) → ! q ∙' ! p == ! (p ∙' q)\n ∙'-! idp idp = idp\n\n !-! : {x y : A} (p : x == y) → ! (! p) == p\n !-! idp = idp\n\n {- Horizontal compositions -}\n\n infixr 80 _∙2_ _∙'2_\n\n _∙2_ : {x y z : A} {p p' : x == y} {q q' : y == z} (α : p == p') (β : q == q')\n → p ∙ q == p' ∙ q'\n _∙2_ {p = idp} idp β = β\n\n _∙'2_ : {x y z : A} {p p' : x == y} {q q' : y == z} (α : p == p') (β : q == q')\n → p ∙' q == p' ∙' q'\n _∙'2_ {q = idp} α idp = α\n\n idp∙2idp : {x y z : A} (p : x == y) (q : y == z)\n → (idp {a = p}) ∙2 (idp {a = q}) == idp\n idp∙2idp idp idp = idp\n\n idp∙'2idp : {x y z : A} (p : x == y) (q : y == z)\n → (idp {a = p}) ∙'2 (idp {a = q}) == idp\n idp∙'2idp idp idp = idp\n\n{-\nSometimes we need to restart a new section in order to have everything in the\nprevious one generalized.\n-}\nmodule _ {i} {A : Type i} where\n {- Whisker and horizontal composition for Eckmann-Hilton argument -}\n\n infixr 80 _∙ᵣ_ _⋆2_ _⋆'2_\n infixl 80 _∙ₗ_\n\n _∙ᵣ_ : {x y z : A} {p p' : x == y} (α : p == p') (q : y == z)\n → p ∙ q == p' ∙ q\n _∙ᵣ_ {p = p} {p' = p'} α idp = ∙-unit-r p ∙ α ∙ ! (∙-unit-r p')\n\n _∙ₗ_ : {x y z : A} {q q' : y == z} (p : x == y) (β : q == q')\n → p ∙ q == p ∙ q'\n _∙ₗ_ {q = q} {q' = q'} idp β = β\n\n _⋆2_ : {x y z : A} {p p' : x == y} {q q' : y == z}\n (α : p == p') (β : q == q')\n → p ∙ q == p' ∙ q'\n _⋆2_ {p' = p'} {q = q} α β = (α ∙ᵣ q) ∙ (p' ∙ₗ β)\n\n _⋆'2_ : {x y z : A} {p p' : x == y} {q q' : y == z}\n (α : p == p') (β : q == q')\n → p ∙ q == p' ∙ q'\n _⋆'2_ {p = p} {q' = q'} α β = (p ∙ₗ β) ∙ (α ∙ᵣ q')\n\n ⋆2=⋆'2 : {x y z : A} {p p' : x == y} {q q' : y == z}\n (α : p == p') (β : q == q')\n → α ⋆2 β == α ⋆'2 β\n ⋆2=⋆'2 {p = idp} {q = idp} idp idp = idp\n\nmodule _ {i} {A : Type i} where\n\n anti-whisker-right : {x y z : A} (p : y == z) {q r : x == y}\n → (q ∙ p == r ∙ p → q == r)\n anti-whisker-right idp {q} {r} h =\n ! (∙-unit-r q) ∙ (h ∙ ∙-unit-r r)\n\n anti-whisker-left : {x y z : A} (p : x == y) {q r : y == z}\n → (p ∙ q == p ∙ r → q == r)\n anti-whisker-left idp h = h\n\n\n{- Dependent stuff -}\nmodule _ {i j} {A : Type i} {B : A → Type j} where\n\n {- Dependent constant path -}\n\n idpᵈ : {x : A} {u : B x} → u == u [ B ↓ idp ]\n idpᵈ = idp\n\n {- Dependent opposite path -}\n\n !ᵈ : {x y : A} {p : x == y} {u : B x} {v : B y}\n → (u == v [ B ↓ p ] → v == u [ B ↓ (! p)])\n !ᵈ {p = idp} = !\n\n !ᵈ' : {x y : A} {p : x == y} {u : B y} {v : B x}\n → (u == v [ B ↓ (! p) ] → v == u [ B ↓ p ])\n !ᵈ' {p = idp} = !\n\n !ᵈ-!ᵈ' : {x y : A} {p : x == y} {u : B y} {v : B x}\n → (q : u == v [ B ↓ (! p) ])\n → !ᵈ (!ᵈ' q) == q\n !ᵈ-!ᵈ' {p = idp} idp = idp\n\n {- Dependent concatenation -}\n\n infixr 80 _∙ᵈ_ _∙'ᵈ_ _◃_ _▹_ _!◃_ _▹!_\n\n _∙ᵈ_ : {x y z : A} {p : x == y} {p' : y == z}\n {u : B x} {v : B y} {w : B z}\n → (u == v [ B ↓ p ]\n → v == w [ B ↓ p' ]\n → u == w [ B ↓ (p ∙ p') ])\n _∙ᵈ_ {p = idp} {p' = idp} q r = q ∙ r\n\n _◃_ = _∙ᵈ_\n\n ◃idp : {x : A} {v w : B x} (q : w == v)\n → q ◃ idp == q\n ◃idp idp = idp\n\n idp◃ : {x y : A} {p : x == y}\n {u : B x} {v : B y} (r : u == v [ B ↓ p ])\n → idp ◃ r == r\n idp◃ {p = idp} r = idp\n\n\n _∙'ᵈ_ : {x y z : A} {p : x == y} {p' : y == z}\n {u : B x} {v : B y} {w : B z}\n → (u == v [ B ↓ p ]\n → v == w [ B ↓ p' ]\n → u == w [ B ↓ (p ∙' p') ])\n _∙'ᵈ_ {p = idp} {p' = idp} q r = q ∙' r\n\n _▹_ = _∙'ᵈ_\n\n {- That’s not perfect, because [q] could be a dependent path. But in that case\n this is not well typed… -}\n idp▹ : {x : A} {v w : B x} (q : v == w)\n → idp ▹ q == q\n idp▹ idp = idp\n\n ▹idp : {x y : A} {p : x == y}\n {u : B x} {v : B y} (q : u == v [ B ↓ p ])\n → q ▹ idp == q\n ▹idp {p = idp} idp = idp\n\n _▹!_ : {x y z : A} {p : x == y} {p' : z == y}\n {u : B x} {v : B y} {w : B z}\n → u == v [ B ↓ p ]\n → w == v [ B ↓ p' ]\n → u == w [ B ↓ p ∙' (! p') ]\n _▹!_ {p' = idp} q idp = q\n\n idp▹! : {x : A} {v w : B x} (q : w == v)\n → idp ▹! q == ! q\n idp▹! idp = idp\n\n _!◃_ : {x y z : A} {p : y == x} {p' : y == z}\n {u : B x} {v : B y} {w : B z}\n → v == u [ B ↓ p ]\n → v == w [ B ↓ p' ]\n → u == w [ B ↓ (! p) ∙ p' ]\n _!◃_ {p = idp} idp q = q\n\n !◃idp :{x : A} {v w : B x} (q : v == w)\n → q !◃ idp == ! q\n !◃idp idp = idp\n\n\n {-\n This is some kind of dependent horizontal composition (used in [apd∙]).\n -}\n\n infixr 80 _∙2ᵈ_ _∙'2ᵈ_\n\n _∙2ᵈ_ : {x y z : Π A B}\n {a a' : A} {p : a == a'} {q : x a == y a} {q' : x a' == y a'}\n {r : y a == z a} {r' : y a' == z a'}\n → (q == q' [ (λ a → x a == y a) ↓ p ])\n → (r == r' [ (λ a → y a == z a) ↓ p ])\n → (q ∙ r == q' ∙ r' [ (λ a → x a == z a) ↓ p ])\n _∙2ᵈ_ {p = idp} α β = α ∙2 β\n\n _∙'2ᵈ_ : {x y z : Π A B}\n {a a' : A} {p : a == a'} {q : x a == y a} {q' : x a' == y a'}\n {r : y a == z a} {r' : y a' == z a'}\n → (q == q' [ (λ a → x a == y a) ↓ p ])\n → (r == r' [ (λ a → y a == z a) ↓ p ])\n → (q ∙' r == q' ∙' r' [ (λ a → x a == z a) ↓ p ])\n _∙'2ᵈ_ {p = idp} α β = α ∙'2 β\n\n {-\n [apd∙] reduces a term of the form [apd (λ a → q a ∙ r a) p], do not confuse it\n with [apd-∙] which reduces a term of the form [apd f (p ∙ q)].\n -}\n\n apd∙ : {a a' : A} {x y z : Π A B}\n (q : (a : A) → x a == y a) (r : (a : A) → y a == z a)\n (p : a == a')\n → apd (λ a → q a ∙ r a) p == apd q p ∙2ᵈ apd r p\n apd∙ q r idp = ! (idp∙2idp (q _) (r _))\n\n apd∙' : {a a' : A} {x y z : Π A B}\n (q : (a : A) → x a == y a) (r : (a : A) → y a == z a)\n (p : a == a')\n → apd (λ a → q a ∙' r a) p == apd q p ∙'2ᵈ apd r p\n apd∙' q r idp = ! (idp∙'2idp (q _) (r _))\n\nmodule _ {i j} {A : Type i} {B : A → Type j} where\n\n {- Exchange -}\n\n ▹-∙'2ᵈ : {x y z : Π A B}\n {a a' a'' : A} {p : a == a'} {p' : a' == a''}\n {q0 : x a == y a} {q0' : x a' == y a'}\n {r0 : y a == z a} {r0' : y a' == z a'}\n {q0'' : x a'' == y a''} {r0'' : y a'' == z a''}\n (q : q0 == q0' [ (λ a → x a == y a) ↓ p ])\n (r : r0 == r0' [ (λ a → y a == z a) ↓ p ])\n (s : q0' == q0'' [ (λ a → x a == y a) ↓ p' ])\n (t : r0' == r0'' [ (λ a → y a == z a) ↓ p' ])\n → (q ∙'2ᵈ r) ▹ (s ∙'2ᵈ t) == (q ▹ s) ∙'2ᵈ (r ▹ t)\n ▹-∙'2ᵈ {p = idp} {p' = idp} {q0} {.q0} {r0} {.r0} idp idp idp idp =\n ap (λ u → (idp {a = q0} ∙'2 idp {a = r0}) ∙' u) (idp∙'2idp q0 r0)\n", "meta": {"hexsha": "f4a953ff3d9281fb45ff7433e4f531e2aaa53608", "size": 8251, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/PathGroupoid.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "core/lib/PathGroupoid.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "core/lib/PathGroupoid.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": 27.7811447811, "max_line_length": 82, "alphanum_fraction": 0.3547448794, "num_tokens": 4383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.359981967491423}} {"text": "{-# OPTIONS --type-in-type --no-termination-check\n #-}\n\nmodule Data where\n\n_-_ : {A : Set}{B : A -> Set}{C : (a : A) -> B a -> Set} ->\n ({a : A}(b : B a) -> C a b) -> (f : (a : A) -> B a) ->\n (a : A) -> C a (f a)\nf - g = \\ x -> f (g x)\n\nid : {X : Set} -> X -> X\nid x = x\n\nkonst : {S : Set}{T : S -> Set} -> ({x : S} -> T x) -> (x : S) -> T x\nkonst c x = c\n\ndata Zero : Set where\nrecord One : Set where\n\nrecord Sig (S : Set)(T : S -> Set) : Set where\n field\n fst : S\n snd : T fst\n\nopen module Sig' {S : Set}{T : S -> Set} = Sig {S}{T}\n\n_,_ : forall {S T}(s : S) -> T s -> Sig S T\ns , t = record {fst = s; snd = t}\n\ninfixr 40 _,_\n\n_*_ : Set -> Set -> Set\nS * T = Sig S \\ _ -> T\n\nsig : forall {S T}{P : Sig S T -> Set} ->\n ((s : S)(t : T s) -> P (s , t)) -> (st : Sig S T) -> P st\nsig f st = f (fst st) (snd st)\n\ndata Two : Set where\n tt : Two\n ff : Two\n\ncond : {S : Two -> Set} -> S tt -> S ff -> (b : Two) -> S b\ncond t f tt = t\ncond t f ff = f\n\n_+_ : Set -> Set -> Set\nS + T = Sig Two (cond S T)\n\n[_,_] : {S T : Set}{P : S + T -> Set} ->\n ((s : S) -> P (tt , s)) -> ((t : T) -> P (ff , t)) ->\n (x : S + T) -> P x\n[ f , g ] = sig (cond f g)\n\ndata PROP : Set where\n Absu : PROP\n Triv : PROP\n _/\\_ : PROP -> PROP -> PROP\n All : (S : Set) -> (S -> PROP) -> PROP\n\nPrf : PROP -> Set\nPrf Absu = Zero\nPrf Triv = One\nPrf (P /\\ Q) = Prf P * Prf Q\nPrf (All S P) = (x : S) -> Prf (P x)\n\ndata CON (I : Set) : Set where\n ?? : I -> CON I\n PrfC : PROP -> CON I\n _*C_ : CON I -> CON I -> CON I\n PiC : (S : Set) -> (S -> CON I) -> CON I\n SiC : (S : Set) -> (S -> CON I) -> CON I\n MuC : (O : Set) -> (O -> CON (I + O)) -> O -> CON I\n NuC : (O : Set) -> (O -> CON (I + O)) -> O -> CON I\n\nmutual\n [|_|] : {I : Set} -> CON I -> (I -> Set) -> Set\n [| ?? i |] X = X i\n [| PrfC P |] X = Prf P\n [| C *C D |] X = [| C |] X * [| D |] X\n [| PiC S C |] X = (s : S) -> [| C s |] X\n [| SiC S C |] X = Sig S \\ s -> [| C s |] X\n [| MuC O C o |] X = Mu C X o\n [| NuC O C o |] X = Nu C X o\n\n data Mu {I O : Set}(C : O -> CON (I + O))(X : I -> Set)(o : O) : Set where\n con : [| C o |] [ X , Mu C X ] -> Mu C X o\n codata Nu {I O : Set}(C : O -> CON (I + O))(X : I -> Set)(o : O) : Set where\n con : [| C o |] [ X , Nu C X ] -> Nu C X o\n\nnoc : {I O : Set}{C : O -> CON (I + O)}{X : I -> Set}{o : O} ->\n Nu C X o -> [| C o |] [ X , Nu C X ]\nnoc (con xs) = xs\n\nmutual\n map : {I : Set}{X Y : I -> Set} -> (C : CON I) -> ((i : I) -> X i -> Y i) ->\n [| C |] X -> [| C |] Y\n map (?? i) f = f i\n map (PrfC P) f = id\n map (C *C D) f = sig \\ c d -> map C f c , map D f d\n map (PiC S C) f = \\ c s -> map (C s) f (c s)\n map (SiC S C) f = sig \\ s c -> s , map (C s) f c\n map (MuC O C o) f = fold C (Mu C _) (\\ o xs -> con (map (C o) [ f , konst id ] xs)) o\n map (NuC O C o) f = unfold C (Nu C _) (\\ o ss -> map (C o) [ f , konst id ] (noc ss)) o\n\n fold : {I O : Set}(C : O -> CON (I + O)){X : I -> Set}(Y : O -> Set) ->\n ((o : O) -> [| C o |] [ X , Y ] -> Y o) ->\n (o : O) -> Mu C X o -> Y o\n fold C Y f o (con xs) = f o (map (C o) [ konst id , fold C Y f ] xs)\n\n unfold : {I O : Set}(C : O -> CON (I + O)){X : I -> Set}(Y : O -> Set) ->\n ((o : O) -> Y o -> [| C o |] [ X , Y ]) ->\n (o : O) -> Y o -> Nu C X o\n unfold C Y f o y = con (map (C o) [ konst id , unfold C Y f ] (f o y))\n\ninduction : {I O : Set}(C : O -> CON (I + O)){X : I -> Set}\n (P : (o : O) -> Mu C X o -> Set) ->\n ((o : O)(xyps : [| C o |] [ X , (\\ o -> Sig (Mu C X o) (P o)) ]) ->\n P o (con (map (C o) [ konst id , konst fst ] xyps))) ->\n (o : O)(y : Mu C X o) -> P o y\ninduction C P p o (con xys) =\n p o (map (C o) [ konst id , (\\ o y -> (y , induction C P p o y)) ] xys)\n\n\nmoo : {I O : Set}(C : O -> CON (I + O)){X : I -> Set}(o : O)\n (W : (o : O) -> Mu C X o -> Set)(w : (o : O)(y : Mu C X o) -> W o y)\n (P : (io : I + O) -> [| ?? io |] [ X , Mu C X ] -> Set)\n (io : I + O)(xy : [| ?? io |] [ X , Mu C X ]) -> P io xy ->\n let g : (io : I + O) ->\n [| ?? io |] [ X , Mu C X ] -> [| ?? io |] [ X , (\\ o -> Sig (Mu C X o) (W o)) ]\n g = [ konst id , (\\ o y -> (y , w o y)) ]\n f : (io : I + O) ->\n [| ?? io |] [ X , (\\ o -> Sig (Mu C X o) (W o)) ] -> [| ?? io |] [ X , Mu C X ]\n f = [ konst id , konst fst ]\n in P io (f io (g io xy))\nmoo C o W w P io xy p = {!p!}\n\n", "meta": {"hexsha": "c90ca72a7a60408bf15cfdf525465509e27ff17b", "size": 4480, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "models/Data.agda", "max_stars_repo_name": "mietek/epigram", "max_stars_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2016-01-09T17:36:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T01:55:28.000Z", "max_issues_repo_path": "models/Data.agda", "max_issues_repo_name": "mietek/epigram", "max_issues_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2", "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": "models/Data.agda", "max_forks_repo_name": "mietek/epigram", "max_forks_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2016-08-14T21:36:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T01:57:40.000Z", "avg_line_length": 32.4637681159, "max_line_length": 93, "alphanum_fraction": 0.3720982143, "num_tokens": 1918, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737473266735, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3599324153904646}} {"text": "module dynamic where\n\nopen import LSsyntax\nopen import static \nopen import Relation.Nullary\nopen import Data.Nat using (ℕ ; _+_)\nopen import Data.Fin using (Fin; toℕ)\nopen import Data.Vec using (Vec ; lookup; _∷_; [])\nopen import Data.Product\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Nullary\nopen import Data.Bool using (Bool; true ; false)\n\ndata _⊓ˡ_ : (ℓ₁ ℓ₂ : Label) → Set where\n ℓ⊓✭ : ∀ ℓ → ℓ ⊓ˡ ✭\n ✭⊓ℓ : ∀ ℓ → ✭ ⊓ˡ ℓ\n idℓ : ∀ ℓ → ℓ ⊓ˡ ℓ\n\n_⊓ᵣ_ : ∀ (ℓ₁ ℓ₂ : Label) → Dec (ℓ₁ ⊓ˡ ℓ₂)\n⊤ ⊓ᵣ ⊤ = yes (idℓ ⊤)\n⊤ ⊓ᵣ ⊥ = no (λ ())\n⊤ ⊓ᵣ ✭ = yes (ℓ⊓✭ ⊤)\n⊥ ⊓ᵣ ⊤ = no (λ ())\n⊥ ⊓ᵣ ⊥ = yes (idℓ ⊥)\n⊥ ⊓ᵣ ✭ = yes (ℓ⊓✭ ⊥)\n✭ ⊓ᵣ ⊤ = yes (✭⊓ℓ ⊤)\n✭ ⊓ᵣ ⊥ = yes (✭⊓ℓ ⊥)\n✭ ⊓ᵣ ✭ = yes (ℓ⊓✭ ✭)\n\n-- note that this is not actually correct. The meet of ⊤ and bottom for example should be undefined,\n-- but that isn't easy to model directly in Agda. However, if we only call this after induction over \n-- the proof of _⊓ᵣ_ it (should) be impossible to call one of the incorrect cases.\nrecMeet : ∀ (ℓ₁ ℓ₂ : Label) → Label\nrecMeet ⊤ ⊤ = ⊤\nrecMeet ⊤ ✭ = ⊤\nrecMeet ⊥ ⊥ = ⊥\nrecMeet ⊥ ✭ = ⊥\nrecMeet ✭ ⊤ = ⊤\nrecMeet ✭ ⊥ = ⊥\nrecMeet ✭ ✭ = ✭\nrecMeet _ _ = ✭ -- fake case\n\n_⊓_ : ∀ (t₁ t₂ : GType) → GType\nbool x ⊓ bool x₁ with x ⊓ᵣ x₁\nbool x ⊓ bool x₁ | yes p = bool (recMeet x x₁)\nbool x ⊓ bool x₁ | no ¬p = err\nbool x ⊓ _ = err\n(t₁ ⇒ x) t₂ ⊓ (t₃ ⇒ x₁) t₄ with x ⊓ᵣ x₁\n(t₁ ⇒ x) t₂ ⊓ (t₃ ⇒ x₁) t₄ | yes p with (t₁ ⊓ t₃) | (t₂ ⊓ t₄)\n(t₁ ⇒ x₂) t₂ ⊓ (t₃ ⇒ x₃) t₄ | yes p | (bool x) | (bool x₁) = ((bool x) ⇒ (recMeet x₂ x₃)) (bool x)\n-- this is probably not correct, but it keeps things simple. \n(t₁ ⇒ x₂) t₂ ⊓ (t₃ ⇒ x₃) t₄ | yes p | (bool x) | ((d ⇒ x₁) d₁) = err\n(t₁ ⇒ x₂) t₂ ⊓ (t₃ ⇒ x₃) t₄ | yes p | ((c ⇒ x) c₁) | (bool x₁) = err\n(t₁ ⇒ x₂) t₂ ⊓ (t₃ ⇒ x₃) t₄ | yes p | ((c ⇒ x) c₁) | ((d ⇒ x₁) d₁) = err\n(t₁ ⇒ x₁) t₂ ⊓ (t₃ ⇒ x₂) t₄ | yes p | (bool x) | err = err\n(t₁ ⇒ x₁) t₂ ⊓ (t₃ ⇒ x₂) t₄ | yes p | ((c ⇒ x) c₁) | err = err\n(t₁ ⇒ x₁) t₂ ⊓ (t₃ ⇒ x₂) t₄ | yes p | err | (bool x) = err\n(t₁ ⇒ x₁) t₂ ⊓ (t₃ ⇒ x₂) t₄ | yes p | err | ((d ⇒ x) d₁) = err\n(t₁ ⇒ x) t₂ ⊓ (t₃ ⇒ x₁) t₄ | yes p | err | err = err\n(t₁ ⇒ x) t₂ ⊓ (t₃ ⇒ x₁) t₄ | no ¬p = err\n_ ⊓ _ = err\n\nI≼ : ∀ (ℓ₁ ℓ₂ : Label) → (Label × Label)\nI≼ ⊤ ✭ = ⊤ , ⊤\nI≼ ✭ ⊤ = ✭ , ⊤\nI≼ ✭ ⊥ = ⊥ , ⊥\nI≼ ⊥ ✭ = ⊥ , ✭\nI≼ ℓ₁ ℓ₂ = ℓ₁ , ℓ₂\n\nΔ≼ : ∀ (triple : Label × Label × Label) → (Label × Label)\nΔ≼ (ℓ₁ , ⊤ , ⊤) = ℓ₁ , ⊤\nΔ≼ (ℓ₁ , ⊤ , ✭) = ℓ₁ , ⊤\nΔ≼ (⊥ , ⊥ , ℓ₃) = ⊥ , ℓ₃\nΔ≼ (⊥ , ✭ , ℓ₃) = ⊥ , ℓ₃\nΔ≼ (ℓ₁ , ✭ , ℓ₃) = ℓ₁ , ℓ₃\nΔ≼ (ℓ₁ , ℓ₂ , ℓ₃) = ℓ₁ , ℓ₃\n\nΔ< : ∀ (triple : GType × GType × GType) → (GType × GType)\nΔ< (bool ℓ₁ , bool ℓ₂ , bool ℓ₃) = \n let new = Δ≼ (ℓ₁ , ℓ₂ , ℓ₃) in \n bool (proj₁ new) , bool (proj₂ new)\nΔ< ((t₁ ⇒ ℓ₁) t′₁ , (t₂ ⇒ ℓ₂) t′₂ , (t₃ ⇒ ℓ₃) t′₃) = \n let new = Δ≼ (ℓ₁ , ℓ₂ , ℓ₃) in\n ((t₁ ⇒ (proj₁ new)) t′₁) , ((t₃ ⇒ (proj₂ new)) t′₃)\nΔ< (_ , _ , _) = err , err\n\ninterior : ∀ (t : GType) → (GType × GType)\ninterior (bool ℓ) = (bool ℓ) , (bool ℓ)\ninterior ((t ⇒ ℓ) t₁) =\n let (ℓ₁ , ℓ₂) = I≼ (getLabel t) ℓ in\n ((setLabel t ℓ₁) ⇒ ℓ₂) t₁ , ((setLabel t ℓ₁) ⇒ ℓ₂) t₁\ninterior err = err , err\n\n_∘<_ : ∀ (t₁ t₂ : (GType × GType)) → (GType × GType)\n(s₁ , s₂₁) ∘< (s₂₂ , s₃) = Δ< (s₁ , (s₂₁ ⊓ s₂₂) , s₃)\n\ndynamicCheck : ∀ {n} (Γ : Ctx n) (t : Term) → Check Γ t\n-- variables\ndynamicCheck {n} Γ (var v) with fromℕ n v\ndynamicCheck {n} Γ (var .(toℕ m)) | yes m = yes (lookup m Γ) (Sx m refl)\ndynamicCheck {n} Γ (var .(n + m)) | no m = no\n\n-- literals\ndynamicCheck Γ (litBool x ℓ) = yes (bool ℓ) (Sb x ℓ)\n\n-- lambda abstraction\ndynamicCheck Γ (lam x t x₁) with dynamicCheck (x ∷ Γ) t \ndynamicCheck Γ (lam x .(erase t) ℓ) | yes τ t = yes ((x ⇒ ℓ) τ) (Sλ x ℓ t)\ndynamicCheck Γ (lam x t x₁) | no = no\n\n-- logical and\ndynamicCheck Γ (t ∧ t₁) with dynamicCheck Γ t | dynamicCheck Γ t₁\ndynamicCheck Γ (.(erase t) ∧ .(erase t₁)) | yes τ t | (yes τ₁ t₁) with (interior τ) ∘< (interior τ₁)\ndynamicCheck Γ (.(erase t) ∧ .(erase t₁)) | yes τ t | (yes τ₁ t₁) | (bool x , bool x₁) = yes (bool (getLabel τ ~⋎~ getLabel τ₁)) (t S∧ t₁)\ndynamicCheck Γ (.(erase t) ∧ .(erase t₁)) | yes τ t | (yes τ₁ t₁) | (_ , _) = no\ndynamicCheck Γ (t ∧ t₁) | _ | _ = no\n\n-- logical or\ndynamicCheck Γ (t ∨ t₁) with dynamicCheck Γ t | dynamicCheck Γ t₁\ndynamicCheck Γ (.(erase t) ∨ .(erase t₁)) | yes τ t | (yes τ₁ t₁) with (interior τ) ∘< (interior τ₁) \ndynamicCheck Γ (.(erase t) ∨ .(erase t₁)) | yes τ t | (yes τ₁ t₁) | (bool x , bool x₁) = yes (bool (getLabel τ ~⋎~ getLabel τ₁)) (t S∨ t₁)\ndynamicCheck Γ (.(erase t) ∨ .(erase t₁)) | yes τ t | (yes τ₁ t₁) | (_ , _) = no\ndynamicCheck Γ (t ∨ t₁) | _ | _ = no\n\n-- application\n-- this needs to be doublechecked!\ndynamicCheck Γ (t ∙ t₁) with dynamicCheck Γ t | dynamicCheck Γ t₁ \ndynamicCheck Γ (.(erase t) ∙ .(erase t₁)) | yes ((τ ⇒ ℓ₁) τ₁) t | yes τ₂ t₁ with (interior ((τ ⇒ ℓ₁) τ₁)) ∘< (interior τ₂) \ndynamicCheck Γ (.(erase t) ∙ .(erase t₁)) | yes ((τ ⇒ ℓ₁) τ₁) t | (yes τ₂ t₁) | (bool x , bool x₁) = yes (bool (getLabel τ₁ ~⋎~ ℓ₁)) (S∙ t t₁ (yes τ₂ τ))\ndynamicCheck Γ (.(erase t) ∙ .(erase t₁)) | yes ((τ ⇒ ℓ₁) τ₁) t | (yes τ₂ t₁) | (bool x , (proj₄ ⇒ x₁) proj₅) = no\ndynamicCheck Γ (.(erase t) ∙ .(erase t₁)) | yes ((τ ⇒ ℓ₁) τ₁) t | (yes τ₂ t₁) | ((proj₃ ⇒ x) proj₄ , bool x₁) = no\ndynamicCheck Γ (.(erase t) ∙ .(erase t₁)) | yes ((τ ⇒ ℓ₁) τ₁) t | (yes τ₂ t₁) | ((proj₃ ⇒ x) proj₄ , (proj₅ ⇒ x₁) proj₆) = no\ndynamicCheck Γ (.(erase t) ∙ .(erase t₁)) | yes ((τ ⇒ ℓ₁) τ₁) t | (yes τ₂ t₁) | (_ , _) = no\ndynamicCheck Γ (.(erase t) ∙ .(erase t₁)) | yes _ t | (yes _ t₁) = no\ndynamicCheck Γ (.(erase t) ∙ t₁) | yes τ t | no = no\ndynamicCheck Γ (t₁ ∙ .(erase t)) | no | yes τ t = no\ndynamicCheck Γ (t ∙ t₁) | no | no = no\n\n-- if then else\ndynamicCheck Γ (if b then t₁ else t₂) with dynamicCheck Γ b\ndynamicCheck Γ (if .(erase b) then t₁ else t₂) | yes τ b with dynamicCheck Γ t₁ | dynamicCheck Γ t₂\ndynamicCheck Γ (if .(erase b) then .(erase t₁) else .(erase t₂)) | yes τ b | (yes τ₁ t₁) | (yes τ₂ t₂) with (interior τ₁) ∘< (interior τ₂)\ndynamicCheck Γ (if .(erase b) then .(erase t₁) else .(erase t₂)) | yes τ b | (yes τ₁ t₁) | (yes τ₂ t₂) | (bool ℓ , bool ℓ₁) = yes (bool (getLabel (τ₁ :∨: τ₂) ~⋎~ getLabel τ)) (Sif b t₁ t₂)\ndynamicCheck Γ (if .(erase b) then .(erase t₁) else .(erase t₂)) | yes τ b | (yes τ₁ t₁) | (yes τ₂ t₂) | (_ , _) = no\ndynamicCheck Γ (if .(erase b) then t₁ else t₂) | yes τ b | _ | _ = no\ndynamicCheck Γ (if b then t₁ else t₂) | no = no\n\n-- error \ndynamicCheck Γ error = no\n", "meta": {"hexsha": "cbe41c3079c861fae9c1b24233f3916940c34ee6", "size": 6394, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Agda/Gradual Security/dynamic.agda", "max_stars_repo_name": "kellino/TypeSystems", "max_stars_repo_head_hexsha": "acf5a153e14a7bdc0c9332fa602fa369fe7add46", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-27T08:05:40.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-26T23:06:17.000Z", "max_issues_repo_path": "Agda/Gradual Security/dynamic.agda", "max_issues_repo_name": "kellino/TypeSystems", "max_issues_repo_head_hexsha": "acf5a153e14a7bdc0c9332fa602fa369fe7add46", "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/Gradual Security/dynamic.agda", "max_forks_repo_name": "kellino/TypeSystems", "max_forks_repo_head_hexsha": "acf5a153e14a7bdc0c9332fa602fa369fe7add46", "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.6266666667, "max_line_length": 188, "alphanum_fraction": 0.547544573, "num_tokens": 3133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737344123242, "lm_q2_score": 0.5273165233795672, "lm_q1q2_score": 0.35993240858051484}} {"text": "module trie where\n\nopen import bool\nopen import char\nopen import list\nopen import maybe\nopen import product\nopen import string\nopen import unit\n\ncal : Set → Set\ncal A = 𝕃 (char × A)\n\nempty-cal : ∀{A : Set} → cal A\nempty-cal = []\n\ncal-lookup : ∀ {A : Set} → cal A → char → maybe A\ncal-lookup [] _ = nothing\ncal-lookup ((c , a) :: l) c' with c =char c'\n... | tt = just a\n... | ff = cal-lookup l c'\n\ncal-insert : ∀ {A : Set} → cal A → char → A → cal A\ncal-insert [] c a = (c , a) :: []\ncal-insert ((c' , a') :: l) c a with c =char c'\n... | tt = (c , a) :: l\n... | ff = (c' , a') :: (cal-insert l c a)\n\ncal-remove : ∀ {A : Set} → cal A → char → cal A\ncal-remove [] _ = []\ncal-remove ((c , a) :: l) c' with c =char c'\n... | tt = cal-remove l c'\n... | ff = (c , a) :: cal-remove l c'\n\ncal-add : ∀{A : Set} → cal A → char → A → cal A\ncal-add l c a = (c , a) :: l\n\ntest-cal-insert = cal-insert (('a' , 1) :: ('b' , 2) :: []) 'b' 20\n\ndata trie (A : Set) : Set where\n Node : maybe A → cal (trie A) → trie A\n\nempty-trie : ∀{A : Set} → trie A\nempty-trie = (Node nothing empty-cal)\n\ntrie-lookup-h : ∀{A : Set} → trie A → 𝕃 char → maybe A\ntrie-lookup-h (Node odata ts) (c :: cs) with cal-lookup ts c\ntrie-lookup-h (Node odata ts) (c :: cs) | nothing = nothing\ntrie-lookup-h (Node odata ts) (c :: cs) | just t = trie-lookup-h t cs\ntrie-lookup-h (Node odata ts) [] = odata\n\ntrie-lookup : ∀{A : Set} → trie A → string → maybe A\ntrie-lookup t s = trie-lookup-h t (string-to-𝕃char s)\n\ntrie-contains : ∀{A : Set} → trie A → string → 𝔹\ntrie-contains t s with trie-lookup t s\ntrie-contains t s | nothing = ff\ntrie-contains t s | just _ = tt\n\ntrie-insert-h : ∀{A : Set} → trie A → 𝕃 char → A → trie A\ntrie-insert-h (Node odata ts) [] x = (Node (just x) ts)\ntrie-insert-h (Node odata ts) (c :: cs) x with cal-lookup ts c\ntrie-insert-h (Node odata ts) (c :: cs) x | just t = \n (Node odata (cal-insert ts c (trie-insert-h t cs x)))\ntrie-insert-h (Node odata ts) (c :: cs) x | nothing = \n (Node odata (cal-add ts c (trie-insert-h empty-trie cs x)))\n\ntrie-insert : ∀{A : Set} → trie A → string → A → trie A\ntrie-insert t s x = trie-insert-h t (string-to-𝕃char s) x\n\ntrie-remove-h : ∀{A : Set} → trie A → 𝕃 char → trie A\ntrie-remove-h (Node odata ts) (c :: cs) with cal-lookup ts c\ntrie-remove-h (Node odata ts) (c :: cs) | nothing = Node odata ts\ntrie-remove-h (Node odata ts) (c :: cs) | just t = Node odata (cal-insert ts c (trie-remove-h t cs))\ntrie-remove-h (Node odata ts) [] = Node nothing ts\n\ntrie-remove : ∀{A : Set} → trie A → string → trie A\ntrie-remove t s = trie-remove-h t (string-to-𝕃char s) \n\ntrie-map : ∀{A B : Set} → (A → B) → trie A → trie B\ntrie-cal-map : ∀{A B : Set} → (A → B) → cal (trie A) → cal (trie B)\ntrie-map f (Node x x₁) = Node (maybe-map f x) (trie-cal-map f x₁)\ntrie-cal-map f [] = []\ntrie-cal-map f ((c , t) :: cs) = \n (c , trie-map f t) :: trie-cal-map f cs \n\ntrie-to-string-h : ∀{A : Set} → string → (A → string) → trie A → 𝕃 char → string\ntrie-cal-to-string-h : ∀{A : Set} → string → (A → string) → cal (trie A) → 𝕃 char → string\ntrie-to-string-h sep d (Node (just x) c) prev-str = \n (𝕃char-to-string (reverse prev-str)) ^ sep ^ (d x) ^ \"\\n\" ^ (trie-cal-to-string-h sep d c prev-str)\ntrie-to-string-h sep d (Node nothing c) prev-str = trie-cal-to-string-h sep d c prev-str\ntrie-cal-to-string-h sep d [] prev-str = \"\"\ntrie-cal-to-string-h sep d ((c , t) :: cs) prev-str = \n (trie-to-string-h sep d t (c :: prev-str)) ^ (trie-cal-to-string-h sep d cs prev-str)\n\n{- trie-to-string sep d t returns a string representation of the trie t, \n where each mapping from string s to data x is printed as\n s sep d x\n where sep is a string and d returns a string for any element A of the trie. -}\ntrie-to-string : ∀{A : Set} → string → (A → string) → trie A → string\ntrie-to-string sep d t = trie-to-string-h sep d t []\n\ntrie-mappings-h : ∀{A : Set} → trie A → 𝕃 char → 𝕃 (string × A)\ntrie-cal-mappings-h : ∀{A : Set} → cal (trie A) → 𝕃 char → 𝕃 (string × A)\ntrie-mappings-h (Node (just x) c) prev-str = (𝕃char-to-string (reverse prev-str) , x) :: (trie-cal-mappings-h c prev-str)\ntrie-mappings-h (Node nothing c) prev-str = (trie-cal-mappings-h c prev-str)\ntrie-cal-mappings-h [] prev-str = []\ntrie-cal-mappings-h ((c , t) :: cs) prev-str = trie-mappings-h t (c :: prev-str) ++ (trie-cal-mappings-h cs prev-str)\n\ntrie-mappings : ∀{A : Set} → trie A → 𝕃 (string × A)\ntrie-mappings t = trie-mappings-h t []\n\n-- return a list of all the strings which have associated data in the trie\ntrie-strings : ∀{A : Set} → trie A → 𝕃 string \ntrie-strings t = map fst (trie-mappings t)\n\ntrie-nonempty : ∀{A : Set} → trie A → 𝔹\ntrie-cal-nonempty : ∀{A : Set} → cal (trie A) → 𝔹\ntrie-nonempty (Node (just x) t) = tt\ntrie-nonempty (Node nothing c) = trie-cal-nonempty c\ntrie-cal-nonempty [] = ff\ntrie-cal-nonempty ((a , t) :: c) = trie-nonempty t || trie-cal-nonempty c\n\n----------------------------------------------------------------------\n-- stringset\n----------------------------------------------------------------------\n\nstringset : Set\nstringset = trie ⊤ \n\nstringset-contains : stringset → string → 𝔹\nstringset-contains ss s = trie-contains ss s\n\nstringset-insert : stringset → string → stringset\nstringset-insert ss s = trie-insert ss s triv\n\nstringset-remove : stringset → string → stringset\nstringset-remove ss s = trie-remove ss s\n\nstringset-insert𝕃 : stringset → 𝕃 char → stringset\nstringset-insert𝕃 ss s = trie-insert-h ss s triv\n\nempty-stringset : stringset\nempty-stringset = empty-trie\n\nstringset-insert* : stringset → 𝕃 string → stringset\nstringset-insert* s [] = s\nstringset-insert* s (x :: xs) = stringset-insert (stringset-insert* s xs) x\n\nstringset-strings : ∀{A : Set} → trie A → 𝕃 string\nstringset-strings t = map fst (trie-mappings t)\n", "meta": {"hexsha": "624e6cea54e6f1ee1d40744004c65a5f33b806c7", "size": 5749, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "trie.agda", "max_stars_repo_name": "heades/AUGL", "max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": "trie.agda", "max_issues_repo_name": "heades/AUGL", "max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": "trie.agda", "max_forks_repo_name": "heades/AUGL", "max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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.8223684211, "max_line_length": 121, "alphanum_fraction": 0.6070620978, "num_tokens": 1919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.6150878555160665, "lm_q1q2_score": 0.3598886141988408}} {"text": "open import Categories\nopen import Monads\n\nmodule Monads.CatofAdj.InitAdj {a b}{C : Cat {a}{b} }(M : Monad C) where\n\nopen import Library\nopen import Functors\nopen import Naturals hiding (Iso; module Iso)\nopen import Adjunctions\nopen import Monads.CatofAdj M\nopen import Categories.Initial\nopen import Monads.Kleisli M\nopen import Monads.Kleisli.Functors M\nopen import Monads.Kleisli.Adjunction M\nopen import Adjunctions.Adj2Mon\n\nopen Cat\nopen Fun\nopen Monad M\nopen NatT\nopen Adj\n\nlemX : R KlAdj ○ L KlAdj ≅ TFun M\nlemX = FunctorEq _ _ refl refl\n\nKlObj : Obj CatofAdj\nKlObj = record { \n D = Kl; \n adj = KlAdj; \n law = lemX;\n ηlaw = refl;\n bindlaw = λ{X}{Y}{f} → \n cong bind\n (stripsubst (Hom C X) f (fcong Y (cong OMap (sym lemX))))}\n\nopen ObjAdj\nopen import Isomorphism\nopen Iso\n\nlemZ : {D : Cat {a}{b}}{F G G' : Fun C D} → \n G ≅ G' → {α : NatT F G}{β : NatT F G'} → α ≅ β → \n ∀ {X} → cmp α {X} ≅ cmp β {X}\nlemZ refl refl = refl\n\nlemZ' : {D : Cat {a}{b}}{F F' G G' : Fun C D} → \n F ≅ F' → G ≅ G' → {α : NatT F G}{β : NatT F' G'} → α ≅ β → \n ∀ {X} → cmp α {X} ≅ cmp β {X}\nlemZ' refl refl refl = refl\n\n\nlemfid : {D : Cat {a}{b}}(L : Fun C D)(R : Fun D C)(T : Fun C C) \n (p : T ≅ R ○ L) (η : ∀ {X} → Hom C X (OMap T X))\n (right : {X : Obj C}{Y : Obj D} → Hom C X (OMap R Y) → Hom D (OMap L X) Y) →\n (left : {X : Obj C}{Y : Obj D} → Hom D (OMap L X) Y → Hom C X (OMap R Y)) → \n (q : {X : Obj C}{Y : Obj D}(f : Hom D (OMap L X) Y) → right (left f) ≅ f) → \n (r : {X : Obj C} → left (iden D {OMap L X}) ≅ η {X}) → \n {X : Obj C} → \n right (subst (Hom C X) (fcong X (cong OMap p)) η) \n ≅ \n iden D {OMap L X}\nlemfid {D = D} L R .(R ○ L) refl η right left q r {X} = \n trans (cong right (sym r)) (q (iden D))\n\nlemfcomp : {D : Cat {a}{b}}(L : Fun C D)(R : Fun D C)(T : Fun C C) \n (p : T ≅ R ○ L)\n (bind : ∀{X Y} → Hom C X (OMap T Y) → Hom C (OMap T X) (OMap T Y)) →\n (right : {X : Obj C} {Y : Obj D} → Hom C X (OMap R Y) → Hom D (OMap L X) Y) →\n (q : {X Y : Obj C} {f : Hom C X (OMap T Y)} → \n HMap R (right (subst (Hom C X) (fcong Y (cong OMap p)) f)) ≅ bind f) → \n (r : {X X' : Obj C}{Y Y' : Obj D}\n (f : Hom C X' X)(g : Hom D Y Y')\n (h : Hom C X (OMap R Y)) → \n right (comp C (HMap R g) (comp C h f)) \n ≅ \n comp D g (comp D (right h) (HMap L f))) → \n ∀{X Y Z : Obj C} {f : Hom C Y (OMap T Z)} {g : Hom C X (OMap T Y)} →\n right (subst (Hom C X) (fcong Z (cong OMap p)) (comp C (bind f) g))\n ≅\n comp D (right (subst (Hom C Y) (fcong Z (cong OMap p)) f))\n (right (subst (Hom C X) (fcong Y (cong OMap p)) g))\nlemfcomp {D = D} L R .(R ○ L) refl bind right q r {X}{Y}{Z}{f}{g} = \n trans (cong₂ (λ f g → right (comp C f g)) (sym (q {f = f})) (sym (idr C)))\n (trans (r (iden C) (right f) g) \n (cong (comp D (right f)) \n (trans (cong (comp D (right g)) (fid L)) (idr D))))\n\n\nlemLlaw : {D : Cat {a}{b}}(L : Fun C D)(R : Fun D C)(T : Fun C C) \n (p : T ≅ R ○ L) (η : ∀ {X} → Hom C X (OMap T X)) → \n (right : {X : Obj C} {Y : Obj D} → \n Hom C X (OMap R Y) → Hom D (OMap L X) Y) →\n (left : {X : Obj C} {Y : Obj D} → \n Hom D (OMap L X) Y → Hom C X (OMap R Y)) → \n (q : {X : Obj C} {Y : Obj D} (f : Hom D (OMap L X) Y) →\n right (left f) ≅ f) → \n (r : {X : Obj C} → left (iden D {OMap L X}) ≅ η {X}) → \n (t : {X X' : Obj C}{Y Y' : Obj D}\n (f : Hom C X' X)(g : Hom D Y Y')\n (h : Hom C X (OMap R Y)) → \n right (comp C (HMap R g) (comp C h f)) \n ≅ \n comp D g (comp D (right h) (HMap L f)) ) → \n {X Y : Obj C} (f : Hom C X Y) →\n right (subst (Hom C X) (fcong Y (cong OMap p)) (comp C η f)) \n ≅ \n HMap L f\nlemLlaw {D = D} L R .(R ○ L) refl η right left q r t {X}{Y} f = \n trans (cong (λ g → right (comp C g f)) (sym r)) \n (trans (trans (trans (cong right \n (trans (sym (idl C)) \n (cong (λ g → comp C g \n (comp C (left (iden D)) f)) \n (sym (fid R)))))\n (t f (iden D) (left (iden D)))) \n (cong (comp D (iden D)) \n (trans (cong (λ g → comp D g (HMap L f)) \n (q (iden D))) \n (idl D))))\n (idl D))\n\nK' : (A : Obj CatofAdj) → Fun (D KlObj) (D A)\nK' A = record {\n OMap = OMap (L (adj A));\n HMap =\n λ {X} {Y} f →\n right (adj A)\n (subst (Hom C X) (fcong Y (cong OMap (sym (law A)))) f);\n fid =\n lemfid (L (adj A)) (R (adj A)) (TFun M) (sym (law A)) η\n (right (adj A)) (left (adj A)) (lawa (adj A)) (ηlaw A);\n fcomp =\n lemfcomp (L (adj A)) \n (R (adj A)) \n (TFun M) \n (sym (law A)) \n bind\n (right (adj A)) \n (bindlaw A) \n (natright (adj A)) }\n\nLlaw' : (A : Obj CatofAdj) → K' A ○ L (adj KlObj) ≅ L (adj A)\nLlaw' A = FunctorEq \n _ \n _ \n refl\n (iext λ _ → iext λ _ → ext $ lemLlaw\n (L (adj A))\n (R (adj A)) \n (TFun M) \n (sym (law A)) \n η\n (right (adj A)) \n (left (adj A)) \n (lawa (adj A)) \n (ηlaw A)\n (natright (adj A)))\n\nRlaw' : (A : Obj CatofAdj) → R (adj KlObj) ≅ R (adj A) ○ K' A\nRlaw' A = FunctorEq \n _ \n _ \n (cong OMap (sym (law A)))\n (iext λ _ → iext λ _ → ext λ _ → sym (bindlaw A))\n\nrightlaw' : (A : Obj CatofAdj) → \n {X : Obj C} {Y : Obj (D KlObj)}\n {f : Hom C X (OMap (R (adj KlObj)) Y)} →\n HMap (K' A) (right (adj KlObj) f) ≅\n right (adj A) (subst (Hom C X) (fcong Y (cong OMap (Rlaw' A))) f)\nrightlaw' A {X}{Y}{f} =\n cong (right (adj A))\n (trans (stripsubst (Hom C X) f (fcong Y (cong OMap (sym (law A)))))\n (sym (stripsubst (Hom C X) f (fcong Y (cong OMap (Rlaw' A))))))\n\nKlHom : {A : Obj CatofAdj} → Hom CatofAdj KlObj A\nKlHom {A} = record { \n K = K' A; \n Llaw = Llaw' A; \n Rlaw = Rlaw' A; \n rightlaw = rightlaw' A }\n\nuniq : {X : Obj CatofAdj}{f : Hom CatofAdj KlObj X} → KlHom ≅ f\nuniq {X}{V} = HomAdjEq \n _ \n _\n (FunctorEq \n _ \n _ \n (cong OMap (sym (HomAdj.Llaw V))) \n (iext λ A → iext λ B → ext λ f →\n trans (cong₂ (λ B₁ → right (adj X) {A} {B₁})\n (sym (fcong B (cong OMap (HomAdj.Llaw V))))\n (trans (stripsubst \n (Hom C A) \n f \n (fcong B (cong OMap (sym (law X)))))\n (sym (stripsubst \n (Hom C A) \n f \n (fcong \n B \n (cong OMap (HomAdj.Rlaw V)))))))\n (sym (HomAdj.rightlaw V))))\n\n\nKlIsInit : Init CatofAdj KlObj\nKlIsInit = record { \n i = KlHom;\n law = uniq}\n-- -}\n", "meta": {"hexsha": "cdb70496286120f0203b7a3d0f2a79440a83bdea", "size": 7587, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Monads/CatofAdj/InitAdj.agda", "max_stars_repo_name": "jmchapman/Relative-Monads", "max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z", "max_issues_repo_path": "Monads/CatofAdj/InitAdj.agda", "max_issues_repo_name": "jmchapman/Relative-Monads", "max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z", "max_forks_repo_path": "Monads/CatofAdj/InitAdj.agda", "max_forks_repo_name": "jmchapman/Relative-Monads", "max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z", "avg_line_length": 35.9573459716, "max_line_length": 80, "alphanum_fraction": 0.4080664294, "num_tokens": 2727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.3598250882167638}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Base\nopen import lib.PathGroupoid\nopen import lib.PathOver\nopen import lib.cubical.Square\n\nmodule lib.cubical.SquareOver where\n\nSquareOver : ∀ {i j} {A : Type i} (B : A → Type j) {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n (sq : Square p₀₋ p₋₀ p₋₁ p₁₋)\n {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}\n (q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]) (q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ])\n (q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]) (q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ])\n → Type j\nSquareOver B ids = Square\n\napd-square : ∀ {i j} {A : Type i} {B : A → Type j} (f : Π A B)\n {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n (sq : Square p₀₋ p₋₀ p₋₁ p₁₋)\n → SquareOver B sq (apd f p₀₋) (apd f p₋₀) (apd f p₋₁) (apd f p₁₋)\napd-square f ids = ids\n\n↓-=-to-squareover : ∀ {i j} {A : Type i} {B : A → Type j}\n {f g : Π A B} {x y : A} {p : x == y}\n {u : f x == g x} {v : f y == g y}\n → u == v [ (λ z → f z == g z) ↓ p ]\n → SquareOver B vid-square u (apd f p) (apd g p) v\n↓-=-to-squareover {p = idp} idp = hid-square\n\n↓-=-from-squareover : ∀ {i j} {A : Type i} {B : A → Type j}\n {f g : Π A B} {x y : A} {p : x == y}\n {u : f x == g x} {v : f y == g y}\n → SquareOver B vid-square u (apd f p) (apd g p) v\n → u == v [ (λ z → f z == g z) ↓ p ]\n↓-=-from-squareover {p = idp} sq = horiz-degen-path sq\n\nsquareover-cst-in : ∀ {i j} {A : Type i} {B : Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n {sq : Square p₀₋ p₋₀ p₋₁ p₁₋}\n {b₀₀ b₀₁ b₁₀ b₁₁ : B}\n {q₀₋ : b₀₀ == b₀₁} {q₋₀ : b₀₀ == b₁₀} {q₋₁ : b₀₁ == b₁₁} {q₁₋ : b₁₀ == b₁₁}\n (sq' : Square q₀₋ q₋₀ q₋₁ q₁₋)\n → SquareOver (λ _ → B) sq\n (↓-cst-in q₀₋) (↓-cst-in q₋₀) (↓-cst-in q₋₁) (↓-cst-in q₁₋)\nsquareover-cst-in {sq = ids} sq' = sq'\n\n↓↓-from-squareover : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k}\n {x y : C → A} {u : (c : C) → B (x c)} {v : (c : C) → B (y c)}\n {p : (c : C) → x c == y c} {c₁ c₂ : C} {q : c₁ == c₂}\n {α : u c₁ == v c₁ [ B ↓ p c₁ ]} {β : u c₂ == v c₂ [ B ↓ p c₂ ]}\n → SquareOver B (natural-square p q)\n α (↓-ap-in _ _ (apd u q)) (↓-ap-in _ _ (apd v q)) β\n → α == β [ (λ c → u c == v c [ B ↓ p c ]) ↓ q ]\n↓↓-from-squareover {q = idp} sq = lemma sq\n where\n lemma : ∀ {i j} {A : Type i} {B : A → Type j}\n {x y : A} {u : B x} {v : B y} {p : x == y}\n {α β : u == v [ B ↓ p ]}\n → SquareOver B hid-square α idp idp β\n → α == β\n lemma {p = idp} sq = horiz-degen-path sq\n\n↓↓-to-squareover : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k}\n {x y : C → A} {u : (c : C) → B (x c)} {v : (c : C) → B (y c)}\n {p : (c : C) → x c == y c} {c₁ c₂ : C} {q : c₁ == c₂}\n {α : u c₁ == v c₁ [ B ↓ p c₁ ]} {β : u c₂ == v c₂ [ B ↓ p c₂ ]}\n → α == β [ (λ c → u c == v c [ B ↓ p c ]) ↓ q ]\n → SquareOver B (natural-square p q)\n α (↓-ap-in _ _ (apd u q)) (↓-ap-in _ _ (apd v q)) β\n↓↓-to-squareover {q = idp} r = lemma r\n where\n lemma : ∀ {i j} {A : Type i} {B : A → Type j}\n {x y : A} {u : B x} {v : B y} {p : x == y}\n {α β : u == v [ B ↓ p ]}\n → α == β\n → SquareOver B hid-square α idp idp β\n lemma {p = idp} r = horiz-degen-square r\n\ninfixr 80 _∙v↓⊡_ _∙h↓⊡_ _↓⊡v∙_ _↓⊡h∙_\n\n_∙h↓⊡_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n {sq : Square p₀₋ p₋₀ p₋₁ p₁₋}\n {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}\n {q₀₋ q₀₋' : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]}\n {q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]}\n → q₀₋ == q₀₋'\n → SquareOver B sq q₀₋' q₋₀ q₋₁ q₁₋\n → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋\n_∙h↓⊡_ {sq = ids} = _∙h⊡_\n\n_∙v↓⊡_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n {sq : Square p₀₋ p₋₀ p₋₁ p₁₋}\n {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}\n {q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ q₋₀' : b₀₀ == b₁₀ [ B ↓ p₋₀ ]}\n {q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]}\n → q₋₀ == q₋₀'\n → SquareOver B sq q₀₋ q₋₀' q₋₁ q₁₋\n → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋\n_∙v↓⊡_ {sq = ids} = _∙v⊡_\n\n_↓⊡v∙_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n {sq : Square p₀₋ p₋₀ p₋₁ p₁₋}\n {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}\n {q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]}\n {q₋₁ q₋₁' : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]}\n → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋\n → q₋₁ == q₋₁'\n → SquareOver B sq q₀₋ q₋₀ q₋₁' q₁₋\n_↓⊡v∙_ {sq = ids} = _⊡v∙_\n\n_↓⊡h∙_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A}\n {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}\n {sq : Square p₀₋ p₋₀ p₋₁ p₁₋}\n {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁}\n {q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]}\n {q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ q₁₋' : b₁₀ == b₁₁ [ B ↓ p₁₋ ]}\n → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋\n → q₁₋ == q₁₋'\n → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋'\n_↓⊡h∙_ {sq = ids} = _⊡h∙_\n", "meta": {"hexsha": "439d235139ea839162478e6c8b49e6e37412370a", "size": 5240, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "core/lib/cubical/SquareOver.agda", "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "core/lib/cubical/SquareOver.agda", "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "core/lib/cubical/SquareOver.agda", "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "avg_line_length": 41.2598425197, "max_line_length": 77, "alphanum_fraction": 0.447519084, "num_tokens": 3067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.3597636357466956}} {"text": "{-# OPTIONS --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Substitution.Weakening {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped\nopen import Definition.Untyped.Properties\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.Irrelevance\nopen import Definition.LogicalRelation.Substitution\nopen import Definition.LogicalRelation.Substitution.MaybeEmbed\nopen import Definition.LogicalRelation.Substitution.Introductions.Universe\n\nopen import Tools.Product\nimport Tools.PropositionalEquality as PE\n\n\n-- Weakening of valid types by one.\nwk1ᵛ : ∀ {A F rA rF Γ l l'}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ⊩ᵛ⟨ l' ⟩ F ^ rF / [Γ])\n → Γ ⊩ᵛ⟨ l ⟩ A ^ rA / [Γ]\n → Γ ∙ F ^ rF ⊩ᵛ⟨ l ⟩ wk1 A ^ rA / ([Γ] ∙ [F])\nwk1ᵛ {A} [Γ] [F] [A] ⊢Δ [σ] =\n let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ]))\n [σA]′ = irrelevance′ (PE.sym (subst-wk A)) [σA]\n in [σA]′\n , (λ [σ′] [σ≡σ′] →\n irrelevanceEq″ (PE.sym (subst-wk A))\n (PE.sym (subst-wk A)) PE.refl PE.refl\n [σA] [σA]′\n (proj₂ ([A] ⊢Δ (proj₁ [σ])) (proj₁ [σ′]) (proj₁ [σ≡σ′])))\n\n-- Weakening of valid type equality by one.\nwk1Eqᵛ : ∀ {A B F rA rF Γ l l'}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ⊩ᵛ⟨ l' ⟩ F ^ rF / [Γ])\n ([A] : Γ ⊩ᵛ⟨ l ⟩ A ^ rA / [Γ])\n ([A≡B] : Γ ⊩ᵛ⟨ l ⟩ A ≡ B ^ rA / [Γ] / [A])\n → Γ ∙ F ^ rF ⊩ᵛ⟨ l ⟩ wk1 A ≡ wk1 B ^ rA / [Γ] ∙ [F] / wk1ᵛ {A} {F} [Γ] [F] [A]\nwk1Eqᵛ {A} {B} [Γ] [F] [A] [A≡B] ⊢Δ [σ] =\n let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ]))\n [σA]′ = irrelevance′ (PE.sym (subst-wk A)) [σA]\n in irrelevanceEq″ (PE.sym (subst-wk A))\n (PE.sym (subst-wk B)) PE.refl PE.refl\n [σA] [σA]′\n ([A≡B] ⊢Δ (proj₁ [σ]))\n\n-- Weakening of valid term as a type by one.\nwk1ᵗᵛ : ∀ {F G rF rG lG Γ l'}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ⊩ᵛ⟨ l' ⟩ F ^ rF / [Γ]) →\n let l = ∞\n [UG] = maybeEmbᵛ {A = Univ rG _} [Γ] (Uᵛ (proj₂ (levelBounded lG)) [Γ])\n [wUG] = maybeEmbᵛ {A = Univ rG _} (_∙_ {A = F} [Γ] [F]) (λ {Δ} {σ} → Uᵛ (proj₂ (levelBounded lG)) (_∙_ {A = F} [Γ] [F]) {Δ} {σ})\n in Γ ⊩ᵛ⟨ l ⟩ G ∷ Univ rG lG ^ [ ! , next lG ] / [Γ] / [UG] →\n Γ ∙ F ^ rF ⊩ᵛ⟨ l ⟩ wk1 G ∷ Univ rG lG ^ [ ! , next lG ] / ([Γ] ∙ [F]) / (λ {Δ} {σ} → [wUG] {Δ} {σ})\nwk1ᵗᵛ {F} {G} {rF} {rG} {lG} [Γ] [F] [G]ₜ {Δ} {σ} ⊢Δ [σ] =\n let l = ∞\n [UG] = maybeEmbᵛ {A = Univ rG _} [Γ] (Uᵛ (proj₂ (levelBounded lG)) [Γ])\n [wUG] = maybeEmbᵛ {A = Univ rG _} (_∙_ {A = F} [Γ] [F]) (λ {Δ} {σ} → Uᵛ (proj₂ (levelBounded lG)) (_∙_ {A = F} [Γ] [F]) {Δ} {σ})\n [σG] = proj₁ ([G]ₜ ⊢Δ (proj₁ [σ]))\n [Geq] = PE.sym (subst-wk G)\n [σG]′ = irrelevanceTerm″ PE.refl PE.refl PE.refl [Geq] (proj₁ ([UG] ⊢Δ (proj₁ [σ]))) (proj₁ ([wUG] {Δ} {σ} ⊢Δ [σ])) [σG]\n in [σG]′\n , (λ [σ′] [σ≡σ′] →\n irrelevanceEqTerm″ PE.refl PE.refl\n (PE.sym (subst-wk G))\n (PE.sym (subst-wk G)) PE.refl \n (proj₁ ([UG] ⊢Δ (proj₁ [σ]))) (proj₁ ([wUG] {Δ} {σ} ⊢Δ [σ]))\n (proj₂ ([G]ₜ ⊢Δ (proj₁ [σ])) (proj₁ [σ′]) (proj₁ [σ≡σ′])))\n\n\nwk1Termᵛ : ∀ {F G rF rG t Γ l l'}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ⊩ᵛ⟨ l' ⟩ F ^ rF / [Γ]) →\n ([G] : Γ ⊩ᵛ⟨ l ⟩ G ^ rG / [Γ]) →\n Γ ⊩ᵛ⟨ l ⟩ t ∷ G ^ rG / [Γ] / [G] →\n Γ ∙ F ^ rF ⊩ᵛ⟨ l ⟩ wk1 t ∷ wk1 G ^ rG / ([Γ] ∙ [F]) / wk1ᵛ {A = G} {F = F} [Γ] [F] [G]\nwk1Termᵛ {F} {G} {rF} {rG} {t} [Γ] [F] [G] [t]ₜ {Δ} {σ} ⊢Δ [σ] =\n let [σt] = proj₁ ([t]ₜ ⊢Δ (proj₁ [σ]))\n [σG] = proj₁ ([G] ⊢Δ (proj₁ [σ]))\n [teq] = PE.sym (subst-wk {step id} {σ} t)\n [Geq] = PE.sym (subst-wk {step id} {σ} G)\n [σG]' = irrelevance′ [Geq] [σG]\n in irrelevanceTerm″ [Geq] PE.refl PE.refl [teq] [σG] [σG]' [σt] ,\n λ [σ′] [σ≡σ′] → irrelevanceEqTerm″ PE.refl PE.refl\n (PE.sym (subst-wk t)) (PE.sym (subst-wk t)) (PE.sym (subst-wk G))\n [σG] [σG]' (proj₂ ([t]ₜ ⊢Δ (proj₁ [σ])) (proj₁ [σ′]) (proj₁ [σ≡σ′]))\n\nwk1dᵛ : ∀ {F F' G rF rF' lG Γ l l'}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ⊩ᵛ⟨ l' ⟩ F ^ rF / [Γ]) →\n ([F'] : Γ ⊩ᵛ⟨ l' ⟩ F' ^ rF' / [Γ]) →\n let [ΓF] = _∙_ {A = F} [Γ] [F]\n [ΓF'] = _∙_ {A = F'} [Γ] [F']\n [ΓF'F] = _∙_ {A = wk1 F} [ΓF'] (wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F])\n in Γ ∙ F ^ rF ⊩ᵛ⟨ l ⟩ G ^ [ ! , lG ] / [ΓF] →\n Γ ∙ F' ^ rF' ∙ wk1 F ^ rF ⊩ᵛ⟨ l ⟩ wk1d G ^ [ ! , lG ] / [ΓF'F] \nwk1dᵛ {F} {F'} {G} [Γ] [F] [F'] [G] {Δ} {σ} ⊢Δ [σ] =\n let l = ∞\n [ΓF'] = _∙_ {A = F'} [Γ] [F']\n [ΓF'F] = _∙_ {A = wk1 F} [ΓF'] (wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F])\n [wσ] = proj₁ (proj₁ [σ]) , irrelevanceTerm″ (subst-wk F) PE.refl PE.refl PE.refl\n (proj₁ (wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F] ⊢Δ (proj₁ [σ])))\n (proj₁ ([F] ⊢Δ (proj₁ (proj₁ [σ]))))\n (proj₂ [σ]) \n [σG] = proj₁ ([G] ⊢Δ [wσ])\n [Geq] = PE.sym (subst-wk G)\n [σG]′ = irrelevance′ [Geq] [σG]\n in [σG]′\n , (λ {σ′} [σ′] [σ≡σ′] → let [wσ′] = proj₁ (proj₁ [σ′]) ,\n irrelevanceTerm″ (subst-wk F) PE.refl PE.refl PE.refl\n (proj₁ (wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F] ⊢Δ (proj₁ [σ′])))\n (proj₁ ([F] ⊢Δ (proj₁ (proj₁ [σ′]))))\n (proj₂ [σ′]) \n [wσ≡σ′] = (proj₁ (proj₁ [σ≡σ′])),\n irrelevanceEqTerm″ PE.refl PE.refl PE.refl PE.refl (subst-wk F)\n (proj₁ (wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F] ⊢Δ (proj₁ [σ])))\n (proj₁ ([F] ⊢Δ (proj₁ (proj₁ [σ]))))\n (proj₂ [σ≡σ′])\n in irrelevanceEq″ (PE.sym (subst-wk G)) (PE.sym (subst-wk G)) PE.refl PE.refl\n (proj₁ ([G] ⊢Δ [wσ])) [σG]′\n (proj₂ ([G] ⊢Δ [wσ]) [wσ′] [wσ≡σ′]))\n\n\nwk1dᵗᵛ : ∀ {F F' G rF rF' rG lG Γ l l'}\n ([Γ] : ⊩ᵛ Γ)\n ([F] : Γ ⊩ᵛ⟨ l' ⟩ F ^ rF / [Γ]) →\n ([F'] : Γ ⊩ᵛ⟨ l' ⟩ F' ^ rF' / [Γ]) →\n let [ΓF] = _∙_ {A = F} [Γ] [F]\n [ΓF'] = _∙_ {A = F'} [Γ] [F']\n [ΓF'F] = _∙_ {A = wk1 F} [ΓF'] (wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F])\n in ([UG] : (Γ ∙ F ^ rF) ⊩ᵛ⟨ l ⟩ Univ rG lG ^ [ ! , next lG ] / [ΓF]) →\n ([wUG] : (Γ ∙ F' ^ rF' ∙ wk1 F ^ rF) ⊩ᵛ⟨ l ⟩ Univ rG lG ^ [ ! , next lG ] / [ΓF'F]) →\n Γ ∙ F ^ rF ⊩ᵛ⟨ l ⟩ G ∷ Univ rG lG ^ [ ! , next lG ] / [ΓF] / (λ {Δ} {σ} → [UG] {Δ} {σ}) →\n Γ ∙ F' ^ rF' ∙ wk1 F ^ rF ⊩ᵛ⟨ l ⟩ wk1d G ∷ Univ rG lG ^ [ ! , next lG ] / [ΓF'F] / (λ {Δ} {σ} → [wUG] {Δ} {σ})\nwk1dᵗᵛ {F} {F'} {G} {rF} {rF'} {rG} {lG} [Γ] [F] [F'] [UG] [wUG] [G]ₜ {Δ} {σ} ⊢Δ [σ] =\n let l = ∞\n [ΓF'] = _∙_ {A = F'} [Γ] [F']\n [ΓF'F] = _∙_ {A = wk1 F} [ΓF'] (wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F])\n [wσ] = proj₁ (proj₁ [σ]) , irrelevanceTerm″ (subst-wk F) PE.refl PE.refl PE.refl\n (proj₁ (wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F] ⊢Δ (proj₁ [σ])))\n (proj₁ ([F] ⊢Δ (proj₁ (proj₁ [σ]))))\n (proj₂ [σ]) \n [σG] = proj₁ ([G]ₜ ⊢Δ [wσ])\n [Geq] = PE.sym (subst-wk G)\n [σG]′ = irrelevanceTerm″ PE.refl PE.refl PE.refl [Geq] (proj₁ ([UG] ⊢Δ [wσ])) (proj₁ ([wUG] {Δ} {σ} ⊢Δ [σ])) [σG]\n in [σG]′\n , (λ {σ′} [σ′] [σ≡σ′] → let [wσ′] = proj₁ (proj₁ [σ′]) ,\n irrelevanceTerm″ (subst-wk F) PE.refl PE.refl PE.refl\n (proj₁ (wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F] ⊢Δ (proj₁ [σ′])))\n (proj₁ ([F] ⊢Δ (proj₁ (proj₁ [σ′]))))\n (proj₂ [σ′]) \n [wσ≡σ′] = (proj₁ (proj₁ [σ≡σ′])),\n irrelevanceEqTerm″ PE.refl PE.refl PE.refl PE.refl (subst-wk F)\n (proj₁ (wk1ᵛ {A = F} {F = F'} [Γ] [F'] [F] ⊢Δ (proj₁ [σ])))\n (proj₁ ([F] ⊢Δ (proj₁ (proj₁ [σ]))))\n (proj₂ [σ≡σ′])\n in irrelevanceEqTerm″ PE.refl PE.refl\n (PE.sym (subst-wk G))\n (PE.sym (subst-wk G)) PE.refl \n (proj₁ ([UG] ⊢Δ [wσ])) (proj₁ ([wUG] {Δ} {σ} ⊢Δ [σ]))\n (proj₂ ([G]ₜ ⊢Δ [wσ]) [wσ′] [wσ≡σ′]))\n", "meta": {"hexsha": "f035f101107d493241bd9f1df8a804a603e99fd2", "size": 9257, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Weakening.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/LogicalRelation/Substitution/Weakening.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/LogicalRelation/Substitution/Weakening.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": 55.4311377246, "max_line_length": 140, "alphanum_fraction": 0.3531381657, "num_tokens": 4023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.35969897856552874}} {"text": "module Named where\n\nopen import Data.String\nopen import Data.Nat hiding (_≟_)\nopen import Data.Bool using (T; not)\nopen import Data.Product\nopen import Data.Sum\n-- open import Data.Nat.Properties using (strictTotalOrder)\n-- open import Relation.Binary using (StrictTotalOrder)\n-- open import Relation.Binary.Core\nopen import Function using (id)\nopen import Function.Equivalence using (_⇔_; equivalence)\n\nopen import Relation.Nullary\nopen import Relation.Unary\nopen import Relation.Nullary.Negation\nopen import Data.Unit using (⊤)\nopen import Function using (_∘_)\n-- open import Level renaming (zero to Lzero)\nopen import Relation.Binary.PropositionalEquality\n-- open ≡-Reasoning\n\n-- open ≡-Reasoning\n-- renaming (begin_ to beginEq_; _≡⟨_⟩_ to _≡Eq⟨_⟩_; _∎ to _∎Eq)\n\nopen import Data.Collection\nopen import Data.Collection.Properties\nopen import Data.Collection.Equivalence\nopen import Data.Collection.Inclusion\n\nopen import Relation.Binary.PartialOrderReasoning ⊆-Poset\n\nVariable = String\n\ndata PreTerm : Set where\n Var : (w : Variable) → PreTerm\n App : (P : PreTerm) → (Q : PreTerm) → PreTerm\n Abs : (w : Variable) → (Q : PreTerm) → PreTerm\n\nshowPreTerm : PreTerm → String\nshowPreTerm (Var x) = x\nshowPreTerm (App P Q) = \"(\" ++ showPreTerm P ++ \" \" ++ showPreTerm Q ++ \")\"\nshowPreTerm (Abs x M) = \"(λ\" ++ x ++ \".\" ++ showPreTerm M ++ \")\"\n\nI : PreTerm\nI = Abs \"x\" (Var \"x\")\n\nS : PreTerm\nS = Abs \"x\" (App (Var \"y\") (Var \"x\"))\n\nFV : PreTerm → Collection\nFV (Var x ) = singleton x\nFV (App f x) = union (FV f) (FV x)\nFV (Abs x m) = delete x (FV m)\n\n-- a = singleton \"x\" ∋ (elem \"x\" ∪ elem \"y\")\n\n\n-- b = C[ singleton \"x\" ] ∩ C[ singleton \"x\" ]\n\n-- M = FV S\n\n\n-- neither∈ : ∀ {x A B} → x ∉ C[ A union B ] →\n\n_[_≔_] : PreTerm → Variable → PreTerm → PreTerm\nVar x [ v ≔ N ] with x ≟ v\nVar x [ v ≔ N ] | yes p = N\nVar x [ v ≔ N ] | no ¬p = Var x\nApp P Q [ v ≔ N ] = App (P [ v ≔ N ]) (Q [ v ≔ N ])\nAbs x P [ v ≔ N ] with x ≟ v\nAbs x P [ v ≔ N ] | yes p = Abs v P\nAbs x P [ v ≔ N ] | no ¬p = Abs x (P [ v ≔ N ])\n\n-- If v ∉ FV(M) then M[v≔N] is defined and M[v≔N] ≡ M\nlem-1-2-5-a : ∀ M N v → v ∉ c[ FV M ] → M [ v ≔ N ] ≡ M\nlem-1-2-5-a (Var x) N v v∉M with x ≟ v\nlem-1-2-5-a (Var x) N .x v∉M | yes refl = contradiction here v∉M\nlem-1-2-5-a (Var x) N v v∉M | no ¬p = refl\nlem-1-2-5-a (App P Q) N v v∉M = cong₂\n App\n (lem-1-2-5-a P N v (not-in-left-union (FV P) (FV Q) v∉M))\n (lem-1-2-5-a Q N v (not-in-right-union (FV P) (FV Q) v∉M))\nlem-1-2-5-a (Abs x M) N v v∉M with x ≟ v\nlem-1-2-5-a (Abs x M) N v v∉M | yes p = cong (λ z → Abs z M) (sym p)\nlem-1-2-5-a (Abs x M) N v v∉M | no ¬p = cong (Abs x) (lem-1-2-5-a M N v (still-∉-after-recovered x (FV M) ¬p v∉M))\n\n\n-- begin\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ∎\n-- begin\n-- {! !}\n-- ≤⟨ {! !} ⟩\n-- {! !}\n-- ≤⟨ {! !} ⟩\n-- {! !}\n-- ∎\n\n-- If M[v≔N] is defined, v ≠ x and x ∈ FV(M) iff x ∈ FV(M[v≔N])\nlem-1-2-5-b-i : ∀ {v N} M → c[ FV M ] ≋[ _≢_ v ] c[ FV (M [ v ≔ N ]) ]\nlem-1-2-5-b-i {v} {N} M v≢x = equivalence (to M v≢x) (from M v≢x)\n where\n to : ∀ {v N} M → c[ FV M ] ⊆[ _≢_ v ] c[ FV (M [ v ≔ N ]) ]\n to {v} (Var w) v≢x ∈FV-M with w ≟ v\n to (Var w) v≢x ∈FV-M | yes p = contradiction (sym (trans (nach singleton-≡ ∈FV-M) p)) v≢x\n to (Var w) v≢x ∈FV-M | no ¬p = ∈FV-M\n to {v} {N} (App P Q) v≢x = begin\n c[ union (FV P) (FV Q) ]\n ≤⟨ union-monotone {! !} {! !} {! !} ⟩\n {! !}\n ≤⟨ {! !} ⟩\n {! !}\n ≤⟨ {! !} ⟩\n {! !}\n ≤⟨ {! !} ⟩\n {! !}\n ≤⟨ {! !} ⟩\n c[ union (FV (P [ v ≔ N ])) (FV (Q [ v ≔ N ])) ]\n ∎\n to (Abs w M) v≢x ∈FV-M = {! !}\n -- to (Var w) ∈FV-M with w ≟ v\n -- to (Var w) ∈FV-M | yes p = contradiction (sym (trans (nach singleton-≡ ∈FV-M) p)) v≢x\n -- to (Var w) ∈FV-M | no ¬p = ∈FV-M\n -- to (App P Q) = begin\n -- c[ union (FV P) (FV Q) ]\n -- ≤⟨ union-monotone {! !} {! !} {! !} ⟩\n -- {! !}\n -- ≤⟨ {! !} ⟩\n -- {! !}\n -- ≤⟨ {! !} ⟩\n -- c[ union (FV (P [ v ≔ N ])) (FV (Q [ v ≔ N ])) ]\n -- ∎\n -- to (Abs w M) ∈FV-M = {! !}\n\n from : ∀ {v N} M → c[ FV (M [ v ≔ N ]) ] ⊆[ _≢_ v ] c[ FV M ]\n from M = {! !}\n-- lem-1-2-5-b-i : ∀ {x v N} M → v ≢ x → x ∈ c[ FV M ] ⇔ x ∈ c[ FV (M [ v ≔ N ]) ]\n-- lem-1-2-5-b-i {x} {v} {N} (Var w) v≢x with w ≟ v -- x ≡ w\n-- lem-1-2-5-b-i {x} {v} {N} (Var w) v≢x | yes p =\n-- equivalence\n-- (λ ∈[w] → contradiction (sym (trans (nach singleton-≡ ∈[w]) p)) v≢x)\n-- from\n-- where to : x ∈ c[ w ∷ [] ] → x ∈ c[ FV N ]\n-- to ∈[w] = {! !}\n-- from : x ∈ c[ FV N ] → x ∈ c[ w ∷ [] ] -- x ∈ c[ FV (N [ v ≔ N ]) ]\n-- from ∈FV-N = {! !}\n-- lem-1-2-5-b-i {x} {v} {N} (Var w) v≢x | no ¬p = equivalence id id\n-- lem-1-2-5-b-i {x} {v} {N} (App P Q) v≢x = equivalence to {! !}\n-- where to : c[ union (FV P) (FV Q) ] ⊆ c[ union (FV (P [ v ≔ N ])) (FV (Q [ v ≔ N ])) ]\n-- to = map-⊆-union {FV P} {FV Q} {FV (P [ v ≔ N ])} {FV (Q [ v ≔ N ])} (_≢_ v) {! !} {! !} {! !}\n--\n--\n-- lem-1-2-5-b-i (Abs w M) v≢x = {! !}\n\n-- lem-1-2-5-b-i : ∀ {x v N} M → v ≢ x → (x ∈ FV M) ⇔ (x ∈ FV (M [ v ≔ N ]))\n-- lem-1-2-5-b-i : ∀ {x v N} M → v ≢ x → (x ∈ FV M) ≡ (x ∈ FV (M [ v ≔ N ]))\n-- lem-1-2-5-b-i : ∀ {x v N} M → v ≢ x → (x ∈ c[ FV M ]) ≡ (x ∈ c[ FV (M [ v ≔ N ]) ])\n-- lem-1-2-5-b-i {v = v} (Var w) v≢x with w ≟ v\n-- lem-1-2-5-b-i (Var v) v≢x | yes refl = {! !}\n-- lem-1-2-5-b-i {x} (Var w) v≢x | no ¬p = refl -- cong (_∈_ x) refl\n-- lem-1-2-5-b-i {x} {v} {N} (App P Q) v≢x =\n-- begin\n-- x ∈ c[ union (FV P) (FV Q) ]\n-- ≡⟨ sym {! ∪-union !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- x ∈ c[ union (FV (P [ v ≔ N ])) (FV (Q [ v ≔ N ])) ]\n-- ∎\n-- lem-1-2-5-b-i (Abs w P) v≢x = {! !}\n-- lem-1-2-5-b-i {v = v} (Var w) v≢x x∈FV-M with w ≟ v\n-- lem-1-2-5-b-i (Var w) v≢x x∈FV-M | yes p = ? -- contradiction (trans (singleton-≡ x∈FV-M) p) (v≢x ∘ sym)\n-- lem-1-2-5-b-i (Var w) v≢x x∈FV-M | no ¬p = ? -- x∈FV-M\n-- lem-1-2-5-b-i (App P Q) v≢x x∈FV-M = ? -- ∈-respects-≡ {! !} x∈FV-M\n-- lem-1-2-5-b-i (App P Q) v≢x x∈FV-M = ∈-respects-≡ (cong₂ union (cong FV {! !}) (cong FV {! !})) x∈FV-M\n-- lem-1-2-5-b-i (App P Q) v≢x x∈FV-M = ∈-respects-≡ (cong₂ union ({! !}) {! !}) x∈FV-M\n-- lem-1-2-5-b-i (Abs w P) v≢x x∈FV-M = {! !}\n\n\n-- If M[v≔N] is defined then y ∈ FV(M[v≔N]) iff either y ∈ FV(M) and v ≠ y\n-- or y ∈ FV(N) and x ∈ FV(M)\n\n\n\n-- lem-1-2-5-b-i : ∀ {x y N} M v → y ∈ FV (M [ v ≔ N ]) → y ∈ FV M × x ≢ y ⊎ y ∈ FV N × x ∈ FV M\n-- lem-1-2-5-b⇒ (Var w) v y∈Applied with w ≟ v\n-- lem-1-2-5-b⇒ (Var w) v y∈Applied | yes p = {! !}\n-- lem-1-2-5-b⇒ (Var w) v y∈Applied | no ¬p = inj₁ (y∈Applied , {! singleton-≡ ∈ !})\n-- lem-1-2-5-b⇒ (App P Q) v y∈Applied = {! !}\n-- lem-1-2-5-b⇒ (Abs w P) v y∈Applied = {! !}\n--\n-- lem-1-2-5-b⇐ : ∀ {x y v M N} → y ∈ FV M × x ≢ y ⊎ y ∈ FV N × x ∈ FV M → y ∈ FV (M [ v ≔ N ])\n-- lem-1-2-5-b⇐ = {! !}\n\n\nlem-1-2-5-c : (M : PreTerm) → (x : Variable) → M [ x ≔ Var x ] ≡ M\nlem-1-2-5-c (Var x ) y with x ≟ y\nlem-1-2-5-c (Var x ) y | yes p = sym (cong Var p)\nlem-1-2-5-c (Var x ) y | no ¬p = refl\nlem-1-2-5-c (App P Q) y = cong₂ App (lem-1-2-5-c P y) (lem-1-2-5-c Q y)\nlem-1-2-5-c (Abs x M) y with x ≟ y\nlem-1-2-5-c (Abs x M) y | yes p = cong (λ w → Abs w M) (sym p)\nlem-1-2-5-c (Abs x M) y | no ¬p = cong (Abs x) (lem-1-2-5-c M y)\n\n\nlength : PreTerm → ℕ\nlength (Var x) = 1\nlength (App P Q) = length P + length Q\nlength (Abs x M) = 1 + length M\n\n\n-- lem-1-2-5-c : (M : PreTerm) → (x : Variable) → (N : PreTerm) → T (not (x ∈? FV M)) → M [ x ≔ N ] ≡ M\n-- lem-1-2-5-c (Var x') x N x∉M with x' ≟ x\n-- lem-1-2-5-c (Var x') x N x∉M | yes p =\n-- begin\n-- N\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- Var x'\n-- ∎\n-- lem-1-2-5-c (Var x') x N x∉M | no ¬p = {! !}\n-- lem-1-2-5-c (App P Q) x N x∉M =\n-- begin\n-- App (P [ x ≔ N ]) (Q [ x ≔ N ])\n-- ≡⟨ refl ⟩\n-- App P Q [ x ≔ N ]\n-- ≡⟨ {! !} ⟩\n-- App P Q\n-- ∎\n-- lem-1-2-5-c (Abs x' M) x N x∉M = {! !}\n\n\n-- begin\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ∎\n", "meta": {"hexsha": "2d69c386e669dbe811ee187861fb83d0537544dc", "size": 8670, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Named.agda", "max_stars_repo_name": "banacorn/lambda-calculus", "max_stars_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a", "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": "Named.agda", "max_issues_repo_name": "banacorn/lambda-calculus", "max_issues_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a", "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": "Named.agda", "max_forks_repo_name": "banacorn/lambda-calculus", "max_forks_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a", "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": 34.5418326693, "max_line_length": 115, "alphanum_fraction": 0.4167243368, "num_tokens": 4000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442251201477016, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.35968827500741174}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- The lifting of a strict order to incorporate a new supremum\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\n-- This module is designed to be used with\n-- Relation.Nullary.Construct.Add.Supremum\n\nopen import Relation.Binary\n\nmodule Relation.Binary.Construct.Add.Supremum.Strict\n {a r} {A : Set a} (_<_ : Rel A r) where\n\nopen import Level using (_⊔_)\nopen import Data.Product\nopen import Function\nopen import Relation.Nullary\nimport Relation.Nullary.Decidable as Dec\nimport Relation.Binary.PropositionalEquality as P\nopen import Relation.Nullary.Construct.Add.Supremum\nimport Relation.Binary.Construct.Add.Supremum.Equality as Equality\nimport Relation.Binary.Construct.Add.Supremum.NonStrict as NonStrict\n\n------------------------------------------------------------------------\n-- Definition\n\ninfix 4 _<⁺_\n\ndata _<⁺_ : Rel (A ⁺) (a ⊔ r) where\n [_] : {k l : A} → k < l → [ k ] <⁺ [ l ]\n [_]<⊤⁺ : (k : A) → [ k ] <⁺ ⊤⁺\n\n------------------------------------------------------------------------\n-- Relational properties\n\n[<]-injective : ∀ {k l} → [ k ] <⁺ [ l ] → k < l\n[<]-injective [ p ] = p\n\n<⁺-asym : Asymmetric _<_ → Asymmetric _<⁺_\n<⁺-asym <-asym [ p ] [ q ] = <-asym p q\n<⁺-asym <-asym [ k ]<⊤⁺ ()\n\n<⁺-trans : Transitive _<_ → Transitive _<⁺_\n<⁺-trans <-trans [ p ] [ q ] = [ <-trans p q ]\n<⁺-trans <-trans [ p ] [ k ]<⊤⁺ = [ _ ]<⊤⁺\n\n<⁺-dec : Decidable _<_ → Decidable _<⁺_\n<⁺-dec _ (λ ()) (λ ()) [ l ]<⊤⁺\n <⁺-cmp <-cmp [ k ] ⊤⁺ = tri< [ k ]<⊤⁺ (λ ()) (λ ())\n <⁺-cmp <-cmp [ k ] [ l ] with <-cmp k l\n ... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ [≈]-injective) (¬c ∘ [<]-injective)\n ... | tri≈ ¬a b ¬c = tri≈ (¬a ∘ [<]-injective) [ b ] (¬c ∘ [<]-injective)\n ... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ [≈]-injective) [ c ]\n\n <⁺-irrefl : Irreflexive _≈_ _<_ → Irreflexive _≈⁺_ _<⁺_\n <⁺-irrefl <-irrefl [ p ] [ q ] = <-irrefl p q\n <⁺-irrefl <-irrefl ⊤⁺≈⊤⁺ ()\n\n <⁺-respˡ-≈⁺ : _<_ Respectsˡ _≈_ → _<⁺_ Respectsˡ _≈⁺_\n <⁺-respˡ-≈⁺ <-respˡ-≈ [ p ] [ q ] = [ <-respˡ-≈ p q ]\n <⁺-respˡ-≈⁺ <-respˡ-≈ [ p ] ([ l ]<⊤⁺) = [ _ ]<⊤⁺\n <⁺-respˡ-≈⁺ <-respˡ-≈ ⊤⁺≈⊤⁺ q = q\n\n <⁺-respʳ-≈⁺ : _<_ Respectsʳ _≈_ → _<⁺_ Respectsʳ _≈⁺_\n <⁺-respʳ-≈⁺ <-respʳ-≈ [ p ] [ q ] = [ <-respʳ-≈ p q ]\n <⁺-respʳ-≈⁺ <-respʳ-≈ ⊤⁺≈⊤⁺ q = q\n\n <⁺-resp-≈⁺ : _<_ Respects₂ _≈_ → _<⁺_ Respects₂ _≈⁺_\n <⁺-resp-≈⁺ = map <⁺-respʳ-≈⁺ <⁺-respˡ-≈⁺\n\nmodule _ {r} {_≤_ : Rel A r} where\n\n open NonStrict _≤_\n\n <⁺-transʳ : Trans _≤_ _<_ _<_ → Trans _≤⁺_ _<⁺_ _<⁺_\n <⁺-transʳ <-transʳ [ p ] [ q ] = [ <-transʳ p q ]\n <⁺-transʳ <-transʳ [ p ] [ k ]<⊤⁺ = [ _ ]<⊤⁺\n\n <⁺-transˡ : Trans _<_ _≤_ _<_ → Trans _<⁺_ _≤⁺_ _<⁺_\n <⁺-transˡ <-transˡ [ p ] [ q ] = [ <-transˡ p q ]\n <⁺-transˡ <-transˡ [ p ] ([ _ ] ≤⊤⁺) = [ _ ]<⊤⁺\n <⁺-transˡ <-transˡ [ k ]<⊤⁺ (⊤⁺ ≤⊤⁺) = [ k ]<⊤⁺\n\n------------------------------------------------------------------------\n-- Structures\n\nmodule _ {e} {_≈_ : Rel A e} where\n\n open Equality _≈_\n\n <⁺-isStrictPartialOrder : IsStrictPartialOrder _≈_ _<_ →\n IsStrictPartialOrder _≈⁺_ _<⁺_\n <⁺-isStrictPartialOrder strict = record\n { isEquivalence = ≈⁺-isEquivalence isEquivalence\n ; irrefl = <⁺-irrefl irrefl\n ; trans = <⁺-trans trans\n ; <-resp-≈ = <⁺-resp-≈⁺ <-resp-≈\n } where open IsStrictPartialOrder strict\n\n <⁺-isDecStrictPartialOrder : IsDecStrictPartialOrder _≈_ _<_ →\n IsDecStrictPartialOrder _≈⁺_ _<⁺_\n <⁺-isDecStrictPartialOrder dectot = record\n { isStrictPartialOrder = <⁺-isStrictPartialOrder isStrictPartialOrder\n ; _≟_ = ≈⁺-dec _≟_\n ; _; curry; uncurry) renaming (map to map-×)\nopen import Data.Sum public using (_⊎_; inj₁; inj₂; [_,_]; [_,_]′) renaming (map to map-⊎)\n\nopen import Data.List public using (List; []; _∷_) hiding (module List)\nopen import Data.List.Relation.Unary.All public using (All; []; _∷_) hiding (module All)\nopen import Data.List.Relation.Unary.Any public using (here; there)\nopen import Data.List.Membership.Propositional public using (_∈_)\nopen import Data.List.Relation.Binary.Sublist.Propositional public using (_⊆_; []; _∷_; _∷ʳ_; ⊆-refl; ⊆-trans) renaming (lookup to ⊆-lookup)\n\nopen import Function public using (_∘_; _∘′_; id; _$_; _ˢ_; case_of_; const; flip)\n\nopen import Relation.Binary.PropositionalEquality public using (_≡_; refl; sym; trans; cong; cong₂; subst; _≗_)\n\n{-# BUILTIN REWRITE _≡_ #-}\n\nmodule All where\n open import Data.List.Relation.Unary.All public\n\nmodule Any where\n open import Data.List.Relation.Unary.Any public\n\n-- open import Axiom.Extensionality.Propositional public using (Extensionality)\n-- postulate\n-- funExt : ∀{a b} → Extensionality a b -- inline to avoid library incomp.\n\npostulate\n funExt : ∀{a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x}\n → (∀ x → f x ≡ g x)\n → f ≡ g\n funExtH : ∀{a b} {A : Set a} {B : A → Set b} {f g : {x : A} → B x}\n → (∀ {x} → f {x} ≡ g {x})\n → (λ {x} → f {x}) ≡ g\n\n⊥-elim-ext : ∀{a b} {A : Set a} {B : Set b} {f : A → ⊥} {g : A → B} → ⊥-elim {b} {B} ∘ f ≡ g\n⊥-elim-ext {f = f} = funExt λ a → ⊥-elim (f a)\n\ncong₃ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d}\n (f : A → B → C → D) {a a' b b' c c'} → a ≡ a' → b ≡ b' → c ≡ c' → f a b c ≡ f a' b' c'\ncong₃ f refl refl refl = refl\n\n_×̇_ : ∀{A B C D : Set} → (A → C) → (B → D) → A × B → C × D\n(f ×̇ g) (x , y) = f x , g y\n\n-- Application (S-combinator)\n\napply : ∀{A B C : Set} (f : C → A → B) (d : C → A) → C → B\napply f a = λ c → f c (a c)\n\n-- Kripke application\n\nkapply : ∀{A B C D : Set} (f : C → A → B) (τ : D → C) (d : D → A) → D → B\nkapply f τ a = apply (f ∘ τ) a\n-- kapply f τ a = λ d → f (τ d) (a d)\n\ncaseof : ∀{A B C D : Set} (f : C → A ⊎ B) (g : C × A → D) (h : C × B → D) → C → D\ncaseof f g h = λ c → [ curry g c , curry h c ]′ (f c)\n\nsum-eta : ∀{A B : Set} (x : A ⊎ B) → [ inj₁ , inj₂ ] x ≡ x\nsum-eta (inj₁ x) = refl\nsum-eta (inj₂ y) = refl\n\ncaseof-eta : ∀{A B C : Set} (f : C → A ⊎ B) → caseof f (inj₁ ∘ proj₂) (inj₂ ∘ proj₂) ≡ f\ncaseof-eta f = funExt λ c → sum-eta (f c)\n\nsum-perm : ∀{A B C D : Set} (k : C → D) {g : A → C} {h : B → C} (x : A ⊎ B) →\n [ k ∘ g , k ∘ h ]′ x ≡ k ([ g , h ]′ x)\nsum-perm k (inj₁ x) = refl\nsum-perm k (inj₂ y) = refl\n\ncaseof-perm' : ∀{A B C D E : Set}\n (k : C → D → E) {f : C → A ⊎ B} {g : C × A → D} {h : C × B → D} →\n caseof f (apply (k ∘ proj₁) g) (apply (k ∘ proj₁) h)\n ≡ apply k (caseof f g h)\ncaseof-perm' k {f} = funExt λ c → sum-perm (k c) (f c)\n\ncaseof-perm : ∀{A B C D E : Set} (k : D → E) {f : C → A ⊎ B} {g : C × A → D} {h : C × B → D}\n → caseof f (k ∘ g) (k ∘ h) ≡ k ∘ caseof f g h\ncaseof-perm = caseof-perm' ∘ const\n\ncaseof-wk : ∀{A B C D E : Set} (k : D → C) {f : C → A ⊎ B} {g : C × A → E} {h : C × B → E}\n → caseof (f ∘ k) (g ∘ (k ×̇ id)) (h ∘ (k ×̇ id)) ≡ caseof f g h ∘ k\ncaseof-wk {A} {B} {C} {D} {E} k {f} {g} {h} = refl\n\ncaseof-apply : ∀{A B C D E : Set}\n (f : C → A ⊎ B) {g : C × A → D → E} {h : C × B → D → E} (d : C → D)\n\n → caseof f (apply g (d ∘ proj₁)) (apply h (d ∘ proj₁))\n ≡ apply (caseof f g h) d\n\ncaseof-apply f {g} {h} d = funExt λ c → sum-perm (λ z → z (d c)) {curry g c} {curry h c} (f c)\n\n-- caseof-apply {A} {B} {C} {D} {E} d {f} {g} {h} = funExt λ c → aux (f c)\n-- where\n-- aux : ∀ {c : C} (w : A ⊎ B) →\n-- [ (λ y → curry g c y (d c)) , (λ y → curry h c y (d c)) ]′ w ≡\n-- [ curry g c , curry h c ]′ w (d c)\n-- aux (inj₁ a) = refl\n-- aux (inj₂ b) = refl\n\n-- caseof (f ∘ τ)\n-- (apply (g ∘ (τ ×̇ id)) (a ∘ proj₁))\n-- (apply (h ∘ (τ ×̇ id)) (a ∘ proj₁))\n-- ≡\n-- apply (caseof f g h ∘ τ) a\n\ncaseof-kapply : ∀{A B C D E F : Set}\n (f : C → A ⊎ B) (g : C × A → E → F) (h : C × B → E → F) (τ : D → C) (a : D → E)\n → caseof (f ∘ τ)\n (kapply g (τ ×̇ id) (a ∘ proj₁))\n (kapply h (τ ×̇ id) (a ∘ proj₁))\n ≡\n kapply (caseof f g h) τ a\ncaseof-kapply f g h τ a = caseof-apply (f ∘ τ) a\n\ncaseof-swap : ∀{A B C D X Y : Set}\n (f : C → X ⊎ Y)\n (i : C × X → A ⊎ B)\n (j : C × Y → A ⊎ B)\n (g : C → A → D)\n (h : C → B → D) →\n caseof f (caseof i (uncurry (g ∘ proj₁)) (uncurry (h ∘ proj₁)))\n (caseof j (uncurry (g ∘ proj₁)) (uncurry (h ∘ proj₁)))\n ≡ caseof (caseof f i j) (uncurry g) (uncurry h)\ncaseof-swap {A} {B} {C} {D} {X} {Y} f i j g h = funExt λ c →\n sum-perm [ (g c) , (h c) ] (f c)\n", "meta": {"hexsha": "ccd61d8fc02f1e52bdfc4254521725eacc0c6540", "size": 5132, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Library.agda", "max_stars_repo_name": "andreasabel/ipl", "max_stars_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2018-05-16T08:08:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-27T19:10:49.000Z", "max_issues_repo_path": "src/Library.agda", "max_issues_repo_name": "andreasabel/ipl", "max_issues_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_issues_repo_licenses": ["Unlicense"], "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/Library.agda", "max_forks_repo_name": "andreasabel/ipl", "max_forks_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-11-13T16:01:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-25T20:39:03.000Z", "avg_line_length": 37.1884057971, "max_line_length": 142, "alphanum_fraction": 0.500974279, "num_tokens": 2259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.6619228758499942, "lm_q1q2_score": 0.3593336255909144}} {"text": "module rename where\n\nopen import lib\n\nopen import cedille-types \nopen import ctxt-types\nopen import is-free\nopen import syntax-util\n\nrenamectxt : Set\nrenamectxt = stringset × trie string {- the trie maps vars to their renamed versions, \n and the stringset stores all those renamed versions -}\n\nempty-renamectxt : renamectxt\nempty-renamectxt = empty-stringset , empty-trie\n\nrenamectxt-contains : renamectxt → string → 𝔹\nrenamectxt-contains (_ , r) s = trie-contains r s\n\nrenamectxt-insert : renamectxt → (s1 s2 : string) → renamectxt\nrenamectxt-insert (ranr , r) s x = stringset-insert ranr x , trie-insert r s x\n\nrenamectxt-single : var → var → renamectxt\nrenamectxt-single = renamectxt-insert empty-renamectxt\n\nrenamectxt-lookup : renamectxt → string → maybe string\nrenamectxt-lookup (ranr , r) s = trie-lookup r s\n\nrenamectxt-remove : renamectxt → string → renamectxt\nrenamectxt-remove (ranr , r) s with trie-lookup r s\nrenamectxt-remove (ranr , r) s | nothing = ranr , r\nrenamectxt-remove (ranr , r) s | just s' = stringset-remove ranr s' , trie-remove r s\n\nrenamectxt-in-range : renamectxt → string → 𝔹\nrenamectxt-in-range (ranr , r) s = stringset-contains ranr s\n\nrenamectxt-in-field : renamectxt → string → 𝔹\nrenamectxt-in-field m s = renamectxt-contains m s || renamectxt-in-range m s\n\nrenamectxt-rep : renamectxt → string → string\nrenamectxt-rep r x with renamectxt-lookup r x\nrenamectxt-rep r x | nothing = x\nrenamectxt-rep r x | just x' = x'\n\neq-var : renamectxt → string → string → 𝔹\neq-var r x y = renamectxt-rep r x =string renamectxt-rep r y\n\npick-new-name : string → string\npick-new-name x = x ^ \"'\"\n\n{- rename-away-from x g r rename the variable x to be some new name (related to x)\n which does not satisfy the given predicate on names (assuming this is possible),\n and is not in the domain of the renamectxt . -}\n{-# NON_TERMINATING #-}\nrename-away-from : string → (string → 𝔹) → renamectxt → string\nrename-away-from x g r =\n if (g x) then\n rename-away-from (pick-new-name x) g r\n else if (renamectxt-in-field r x) then\n rename-away-from (pick-new-name x) g r\n else x\n\nfresh-var : string → (string → 𝔹) → renamectxt → string\nfresh-var = rename-away-from\n\nrename-var-if : {ed : exprd} → ctxt → renamectxt → var → ⟦ ed ⟧ → var\nrename-var-if Γ ρ y t = \n if is-free-in check-erased y t || renamectxt-in-range ρ y then \n rename-away-from y (ctxt-binds-var Γ) ρ\n else\n y\n\nrenamectxt-insert* : renamectxt → (vs1 vs2 : 𝕃 string) → maybe renamectxt\nrenamectxt-insert* ρ [] [] = just ρ\nrenamectxt-insert* ρ (x :: vs1) (y :: vs2) = renamectxt-insert* (renamectxt-insert ρ x y) vs1 vs2\nrenamectxt-insert* ρ _ _ = nothing\n", "meta": {"hexsha": "931f4198bf6e094135fc6c3625fec23f81156647", "size": 2688, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/rename.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/rename.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/rename.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": 34.9090909091, "max_line_length": 97, "alphanum_fraction": 0.7005208333, "num_tokens": 783, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.35919392085984597}} {"text": "{-\nThis second-order term syntax was created from the following second-order syntax description:\n\nsyntax Prod | P\n\ntype\n _⊗_ : 2-ary | l40\n\nterm\n pair : α β -> α ⊗ β | ⟨_,_⟩\n fst : α ⊗ β -> α\n snd : α ⊗ β -> β\n\ntheory\n (fβ) a : α b : β |> fst (pair(a, b)) = a\n (sβ) a : α b : β |> snd (pair(a, b)) = b\n (pη) p : α ⊗ β |> pair (fst(p), snd(p)) = p\n-}\n\n\nmodule Prod.Syntax where\n\nopen import SOAS.Common\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.Families.Core\nopen import SOAS.Construction.Structure\nopen import SOAS.ContextMaps.Inductive\n\nopen import SOAS.Metatheory.Syntax\n\nopen import Prod.Signature\n\nprivate\n variable\n Γ Δ Π : Ctx\n α β : PT\n 𝔛 : Familyₛ\n\n-- Inductive term declaration\nmodule P:Terms (𝔛 : Familyₛ) where\n\n data P : Familyₛ where\n var : ℐ ⇾̣ P\n mvar : 𝔛 α Π → Sub P Π Γ → P α Γ\n\n ⟨_,_⟩ : P α Γ → P β Γ → P (α ⊗ β) Γ\n fst : P (α ⊗ β) Γ → P α Γ\n snd : P (α ⊗ β) Γ → P β Γ\n\n\n\n open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛\n\n Pᵃ : MetaAlg P\n Pᵃ = record\n { 𝑎𝑙𝑔 = λ where\n (pairₒ ⋮ a , b) → ⟨_,_⟩ a b\n (fstₒ ⋮ a) → fst a\n (sndₒ ⋮ a) → snd a\n ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }\n\n module Pᵃ = MetaAlg Pᵃ\n\n module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where\n\n open MetaAlg 𝒜ᵃ\n\n 𝕤𝕖𝕞 : P ⇾̣ 𝒜\n 𝕊 : Sub P Π Γ → Π ~[ 𝒜 ]↝ Γ\n 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t\n 𝕊 (t ◂ σ) (old v) = 𝕊 σ v\n 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)\n 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v\n\n 𝕤𝕖𝕞 (⟨_,_⟩ a b) = 𝑎𝑙𝑔 (pairₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 (fst a) = 𝑎𝑙𝑔 (fstₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (snd a) = 𝑎𝑙𝑔 (sndₒ ⋮ 𝕤𝕖𝕞 a)\n\n 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Pᵃ 𝒜ᵃ 𝕤𝕖𝕞\n 𝕤𝕖𝕞ᵃ⇒ = record\n { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }\n ; ⟨𝑣𝑎𝑟⟩ = refl\n ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }\n where\n open ≡-Reasoning\n ⟨𝑎𝑙𝑔⟩ : (t : ⅀ P α Γ) → 𝕤𝕖𝕞 (Pᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)\n ⟨𝑎𝑙𝑔⟩ (pairₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (fstₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (sndₒ ⋮ _) = refl\n\n 𝕊-tab : (mε : Π ~[ P ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)\n 𝕊-tab mε new = refl\n 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v\n\n module _ (g : P ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Pᵃ 𝒜ᵃ g) where\n\n open MetaAlg⇒ gᵃ⇒\n\n 𝕤𝕖𝕞! : (t : P α Γ) → 𝕤𝕖𝕞 t ≡ g t\n 𝕊-ix : (mε : Sub P Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)\n 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x\n 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v\n 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))\n = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))\n 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩\n\n 𝕤𝕖𝕞! (⟨_,_⟩ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (fst a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (snd a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n\n\n-- Syntax instance for the signature\nP:Syn : Syntax\nP:Syn = record\n { ⅀F = ⅀F\n ; ⅀:CS = ⅀:CompatStr\n ; mvarᵢ = P:Terms.mvar\n ; 𝕋:Init = λ 𝔛 → let open P:Terms 𝔛 in record\n { ⊥ = P ⋉ Pᵃ\n ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }\n ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }\n\n-- Instantiation of the syntax and metatheory\nopen Syntax P:Syn public\nopen P:Terms public\nopen import SOAS.Families.Build public\nopen import SOAS.Syntax.Shorthands Pᵃ public\nopen import SOAS.Metatheory P:Syn public\n", "meta": {"hexsha": "c4d56f6eac140cffb9948da865ce4fa507aa49ad", "size": 3271, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "out/Prod/Syntax.agda", "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_issues_repo_path": "out/Prod/Syntax.agda", "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_forks_repo_path": "out/Prod/Syntax.agda", "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "avg_line_length": 25.1615384615, "max_line_length": 93, "alphanum_fraction": 0.5191073066, "num_tokens": 2058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982043529715, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.359184971568122}} {"text": "------------------------------------------------------------------------\n-- Pointers to results from the paper\n------------------------------------------------------------------------\n\n-- Note that the code has evolved after the paper was published. For\n-- code that is closer to the paper, see the version of the code that\n-- is distributed with the paper.\n\n{-# OPTIONS --sized-types #-}\n\nmodule README.Pointers-to-results-from-the-paper where\n\nimport Bisimilarity\nimport Bisimilarity.CCS\nimport Bisimilarity.Classical\nimport Bisimilarity.Comparison\nimport Bisimilarity.Delay-monad\nimport Bisimilarity.Equational-reasoning-instances\nimport Bisimilarity.CCS.Examples\nimport Bisimilarity.CCS.Examples.Natural-numbers\nimport Bisimilarity.Step\nimport Bisimilarity.Up-to\nimport Bisimilarity.Up-to.CCS\nimport Bisimilarity.Up-to.Counterexamples\nimport Bisimilarity.Weak\nimport Bisimilarity.Weak.CCS\nimport Bisimilarity.Weak.Delay-monad\nimport Bisimilarity.Weak.Up-to\nimport Delay-monad\nimport Delay-monad.Bisimilarity\nimport Delay-monad.Bisimilarity.Alternative\nimport Delay-monad.Bisimilarity.Negative\nimport Expansion\nimport Expansion.CCS\nimport Expansion.Delay-monad\nimport Indexed-container\nimport Indexed-container.Delay-monad\nimport Labelled-transition-system\nimport Labelled-transition-system.CCS\nimport Labelled-transition-system.Delay-monad\nimport Relation\nimport Similarity\nimport Similarity.CCS\nimport Up-to\nimport Up-to.Closure\n\n------------------------------------------------------------------------\n-- Section 2\n\n-- The Delay monad.\n--\n-- Note that, unlike the definition in the paper, this definition is\n-- universe-polymorphic. Similar remarks apply to many definitions\n-- below as well.\n\nDelay = Delay-monad.Delay\nDelay′ = Delay-monad.Delay′\n\n-- The non-terminating computation never.\n\nnever = Delay-monad.never\n\n-- Strong bisimilarity for the delay monad.\n--\n-- Note that, unlike in the paper, strong bisimilarity, weak\n-- bisimilarity and the expansion relation are defined as a single\n-- family (with an extra index).\n\n[_]_∼D_ = Delay-monad.Bisimilarity.[_]_∼_\n[_]_∼′D_ = Delay-monad.Bisimilarity.[_]_∼′_\n\n-- Strong bisimilarity is transitive.\n--\n-- (The proof is more general than the one in the paper.)\n\ntransitiveˢ = Delay-monad.Bisimilarity.transitive-∼ʳ\n\n------------------------------------------------------------------------\n-- Section 3\n\n-- Indexed containers.\n--\n-- The paper defines indexed containers with one index type, but this\n-- definition uses two.\n\nContainer = Indexed-container.Container\n⟦_⟧ = Indexed-container.⟦_⟧\nmap = Indexed-container.map\n\n-- Index-preserving functions.\n\n_⊆_ = Relation._⊆_\n\n-- The greatest fixpoint.\n\nν = Indexed-container.ν\nν′ = Indexed-container.ν′\nν-out = Indexed-container.ν-out\nν-in = Indexed-container.ν-in\nunfold = Indexed-container.unfold\n\n-- Relation containment (_⊆_) is not antisymmetric if the index type\n-- is inhabited.\n\n⊆-not-antisymmetric = Relation.⊆-not-antisymmetric\n\n-- The shapes of a container are in pointwise bijective correspondence\n-- with the interpretation of the container applied to the constant\n-- function yielding the unit type.\n\nShape↔⟦⟧⊤ = Indexed-container.Shape↔⟦⟧⊤\n\n-- A container corresponding to the Delay monad.\n\nDelayC = Indexed-container.Delay-monad.DelayC\n\n-- A (size-preserving) logical equivalence between the direct\n-- definition of the delay monad and the indirect definition using ν\n-- and the container DelayC.\n\nDelay⇔νDelayC = Indexed-container.Delay-monad.Delay⇔νDelayC\n\n-- Bisimilarity for ν.\n\nν-bisimilar = Indexed-container.ν-bisimilar\n\n-- The two components of Delay⇔νDelayC {i = ∞} are inverses up to\n-- (strong) bisimilarity.\n\nDelay⇔νDelayC-inverses =\n Indexed-container.Delay-monad.Delay⇔νDelayC-inverses\n\n------------------------------------------------------------------------\n-- Section 4\n\n-- Labelled transition systems.\n\nLTS = Labelled-transition-system.LTS\n\n-- The record type B.\n--\n-- The type is parametrised so that it can also be used to define weak\n-- bisimilarity and expansion.\n\nB = Bisimilarity.Step.Step\n\n-- The container B^C, roughly as given in the paper.\n\nB^C = Bisimilarity.Step.StepC′\n\n-- The code mainly uses another definition of B^C, built up from\n-- smaller building blocks, and employing a trick to make it easier\n-- for Agda to infer implicit arguments.\n\nB^C-code = Bisimilarity.Step.StepC\n\n-- The two definitions of B^C have interpretations that are pointwise\n-- logically equivalent, and in the presence of extensionality they\n-- are pointwise isomorphic.\n\nB^C-code↔B^C = Bisimilarity.Step.StepC↔StepC′\n\n-- The interpretation of B^C is pointwise logically equivalent to B,\n-- and in the presence of extensionality they are pointwise\n-- isomorphic.\n\nB↔B^C = Bisimilarity.Step.Step↔StepC′\n\n-- The traditional definition of bisimilarity.\n\nBisimilar = Bisimilarity.Classical._∼_\n\n-- The definition using ν.\n\n[_]_∼_ = Bisimilarity.[_]_∼_\n\n-- The two definitions are pointwise logically equivalent.\n\nclassical-and-ν-equivalent =\n Bisimilarity.Comparison.classical⇔coinductive\n\n-- The definition using ν′.\n\n[_]_∼′_ = Bisimilarity.[_]_∼′_\n\n-- Derived transition relations.\n\n_⇒_ = Labelled-transition-system.LTS._⇒_\n_[_]⇒_ = Labelled-transition-system.LTS._[_]⇒_\n_[_]⇒̂_ = Labelled-transition-system.LTS._[_]⇒̂_\n_[_]→̂_ = Labelled-transition-system.LTS._[_]⟶̂_\n\n-- Weak bisimilarity.\n\n[_]_≈_ = Bisimilarity.Weak.[_]_≈_\n\n-- Expansion.\n\n[_]_≳_ = Expansion.[_]_≳_\n\n-- A general definition that can be instantiated with different\n-- transition relations to yield strong or weak bisimilarity or the\n-- expansion relation.\n\nimport Bisimilarity.General\n\n-- The labelled transition system for the delay monad.\n\ndelay-monad-lts = Labelled-transition-system.Delay-monad.delay-monad\n\n-- The definition of bisimilarity obtained from this LTS is pointwise\n-- logically equivalent to the direct definition of strong\n-- bisimilarity for the delay monad.\n\ndelay-monad-direct⇔indirect = Bisimilarity.Delay-monad.direct⇔indirect\n\n-- Symmetry of bisimilarity for an arbitrary LTS.\n--\n-- Note that, due to the use of a container in the definition of\n-- strong bisimilarity, the proof uses a helper function instead of\n-- the copatterns left-to-right and right-to-left. Furthermore the\n-- function map₃ is not used, but rather a combination of other\n-- functions. Similar remarks apply to several definitions below.\n\nsymmetric = Bisimilarity.symmetric-∼\nsymmetric′ = Bisimilarity.symmetric-∼′\n\n-- Transitivity of bisimilarity for an arbitrary LTS.\n\ntransitive = Bisimilarity.transitive-∼\n\n------------------------------------------------------------------------\n-- Section 5\n\n-- CCS.\n\nName-with-kind = Labelled-transition-system.CCS.Name-with-kind\nco = Labelled-transition-system.CCS.co\nAction = Labelled-transition-system.CCS.Action\nis-silent = Labelled-transition-system.CCS.is-silent\nProc = Labelled-transition-system.CCS.Proc\nProc′ = Labelled-transition-system.CCS.Proc′\n_[_]→_ = Labelled-transition-system.CCS._[_]⟶_\n_∉_ = Labelled-transition-system.CCS._∉_\n\n-- The transition relation takes finite processes to finite processes.\n\nfinite→finite = Labelled-transition-system.CCS.finite→finite\n\n-- Restricted and the corresponding lemma.\n\nRestricted = Bisimilarity.CCS.Examples.Restricted\nRestricted∼∅ = Bisimilarity.CCS.Examples.Restricted∼∅\n\n-- ∅ is a left identity for parallel composition.\n\n∣-left-identity = Bisimilarity.CCS.∣-left-identity\n\n-- Proofs showing that all the CCS process constructors preserve\n-- strong bisimilarity. (For ∅ the proof is simply reflexivity of\n-- strong bisimilarity.)\n--\n-- The proofs are written in such a way that the arguments can be\n-- reused for similar proofs about strong similarity. (See below for\n-- proofs that are closer to the proofs in the paper.)\n\nmodule Strong-bisimilarity-congruence where\n\n _∣-cong_ = Bisimilarity.CCS._∣-cong_\n ·-cong = Bisimilarity.CCS._·-cong_\n !-cong = Bisimilarity.CCS.!-cong_\n _⊕-cong_ = Bisimilarity.CCS._⊕-cong_\n ⟨ν_⟩-cong = Bisimilarity.CCS.⟨ν_⟩-cong\n ∅-cong = Bisimilarity.reflexive-∼\n\n-- Some proofs have been repeated in order to provide code which is\n-- closer to that presented in the paper.\n\nmodule As-in-the-paper where\n\n _∣-cong_ = Bisimilarity.CCS._∣-congP_\n ·-cong = Bisimilarity.CCS.·-congP\n !-cong = Bisimilarity.CCS.!-congP\n\n-- The code uses overloaded equational reasoning combinators.\n\nimport Equational-reasoning\n\n-- The proof As-in-the-paper._∣-cong_ does not use symmetric′, but the\n-- overloaded combinator symmetric. Agda resolves this use of\n-- symmetric to an instance corresponding to symmetric′.\n\nsymmetric′-instance =\n Bisimilarity.Equational-reasoning-instances.symmetric∼′\n\n-- Lemmas corresponding to ·-cong for expansion and weak bisimilarity.\n\nmodule ·-cong where\n\n expansion = Expansion.CCS._·-cong_\n weak-bisimilarity = Bisimilarity.Weak.CCS._·-cong_\n\n-- The example with P and Q.\n\nP = Bisimilarity.CCS.Examples.Natural-numbers.P\nQ = Bisimilarity.CCS.Examples.Natural-numbers.Q\nP∼Q = Bisimilarity.CCS.Examples.Natural-numbers.P∼Q\n\n-- The processes in the family P are irregular.\n\nP-irregular = Bisimilarity.CCS.Examples.Natural-numbers.P-irregular\n\n-- The combinators _■ and _∼⟨_⟩_ presented in the paper correspond to\n-- two instances.\n\n_■ = Bisimilarity.Equational-reasoning-instances.reflexive∼\n_∼⟨_⟩_ = Bisimilarity.Equational-reasoning-instances.trans∼∼\n\n-- Equations of the form [ ∞ ] P ∼ (C [ P ]) have unique solutions up\n-- to bisimilarity for contexts C where every hole is under a prefix.\n\nexistence = Bisimilarity.CCS.solutions-exist\nuniqueness = Bisimilarity.CCS.unique-solutions\n\n------------------------------------------------------------------------\n-- Section 6\n\n-- Up-to techniques.\n\nUp-to-technique = Up-to.Up-to-technique\n\n-- Relation transformers.\n\nTrans = Relation.Trans\n\n-- Size-preserving transformers.\n\nSize-preserving = Up-to.Size-preserving\n\n-- Composition of binary relations.\n\n_⊙_ = Relation._⊙_\n\n-- Up to bisimilarity.\n\nUp-to-bisimilarity =\n Bisimilarity.Up-to.Up-to-bisimilarity\nup-to-bisimilarity-size-preserving =\n Bisimilarity.Up-to.up-to-bisimilarity-size-preserving\n\n-- Up to context.\n\nUp-to-context = Bisimilarity.Up-to.CCS.Up-to-context\nup-to-context-size-preserving =\n Bisimilarity.Up-to.CCS.up-to-context-size-preserving\n\n-- Up to the simple context consisting of replication applied to a\n-- single hole.\n\nUp-to-! = Bisimilarity.Up-to.CCS.Up-to-!\nup-to-!-size-preserving = Bisimilarity.Up-to.CCS.up-to-!-size-preserving\n\n-- If a transformer is size-preserving, then it satisfies a\n-- corresponding property for ν′ (and vice versa).\n\nsize-preserving′ = Up-to.size-preserving⇔size-preserving′\n\n-- Size-preserving transformers are up-to techniques.\n\nsize-preserving→up-to = Up-to.size-preserving→up-to\n\n-- Monotonicity.\n\nMonotone = Relation.Monotone\n\n-- The definition of Size-preserving can be simplified for monotone\n-- transformers.\n\nsimplification = Up-to.monotone→⇔\n\n-- There are at least two size-preserving relation transformers that\n-- are not monotone (or extensive).\n\nnot-monotone =\n Bisimilarity.Up-to.Counterexamples.∃-2-size-preserving׬[monotone⊎extensive]\n\n-- There is a container C such that there are at least two\n-- transformers that, despite preserving every approximation of the\n-- greatest fixpoint of C, are not up-to techniques with respect to C.\n\nnot-up-to =\n Bisimilarity.Up-to.Counterexamples.∃special-case-of-size-preserving׬up-to\n\n-- There are monotone (and extensive) up-to techniques G and H such\n-- that G ∘ H is not an up-to-technique.\n\nnot-closed-under-composition =\n Bisimilarity.Up-to.Counterexamples.∃[monotone×extensive×up-to]²×¬∘-up-to\n\n-- Size-preserving is closed under composition.\n\n∘-closure = Up-to.∘-closure\n\n-- It is not the case that every (monotone and extensive) up-to\n-- technique is size-preserving.\n\n¬up-to→size-preserving =\n Bisimilarity.Up-to.Counterexamples.¬monotone×extensive×up-to→size-preserving\n\n-- There are at least two up-to techniques that are not\n-- size-preserving (despite being monotone and extensive).\n\nnot-size-preserving =\n Bisimilarity.Up-to.Counterexamples.∃monotone×extensive×up-to׬size-preserving\n\n-- Monotone and compatible transformers are up-to techniques.\n\nmonotone→compatible→up-to = Up-to.monotone→compatible→up-to\n\n-- If F is monotone and symmetric, and compatible for strong\n-- similarity for some LTS, then F is compatible for strong\n-- bisimilarity for this LTS.\n\ncompatible-for-similarity→compatible-for-bisimilarity =\n Up-to.Closure.compatible-for-similarity→compatible-for-bisimilarity\n\n-- It is not in general the case that if F is monotone and symmetric,\n-- and size-preserving for strong similarity for some LTS, then F is\n-- size-preserving for strong bisimilarity for this LTS.\n\n¬-compatible-for-similarity→compatible-for-bisimilarity =\n Up-to.Closure.¬-Size-preserving-⟷/⊗\n\n------------------------------------------------------------------------\n-- Section 7\n\n-- The companion.\n\nCompanion = Up-to.Companion\n\n-- Transformers below the companion.\n\nBelow-the-companion = Up-to.Below-the-companion\n\n-- Transformers are below the companion if and only if they are\n-- size-preserving.\n\nbelow-the-companion⇔size-preserving =\n Up-to.below-the-companion⇔size-preserving\n\n-- The companion is size-preserving.\n\ncompanion-size-preserving = Up-to.companion-size-preserving\n\n-- Compatibility.\n\nCompatible = Up-to.Compatible\n\n-- The large companion.\n\nCompanion₁ = Up-to.Companion₁\n\n-- Monotone and compatible transformers are size-preserving.\n\ncompatible→size-preserving = Up-to.monotone→compatible→size-preserving\n\n-- The large companion is below the small one.\n\ncompanion₁⊆companion = Up-to.companion₁⊆companion\n\n-- The small companion is monotone.\n\ncompanion-monotone = Up-to.companion-monotone\n\n-- The small companion is compatible if and only if it is below the\n-- large one.\n\ncompanion-compatible⇔companion⊆companion₁ =\n Up-to.companion-compatible⇔companion⊆companion₁\n\n-- The small companion is compatible if certain assumptions (including\n-- a strong version of excluded middle) are satisfied. However, at the\n-- time of writing I don't know if these assumptions are consistent\n-- with the variant of Agda that is used in this development.\n\ncompanion-compatible = Up-to.companion-compatible\n\n-- The identity function is below the companion.\n\nid-below = Up-to.id-below\n\n-- The interpretation ⟦ C ⟧ of a container C is below the\n-- corresponding companion.\n\n⟦⟧-below = Up-to.⟦⟧-below\n\n-- The companion composed with itself is below the companion.\n\ncompanion∘companion-below = Up-to.companion∘companion-below\n\n-- An example: If F is below the companion, then ⟦ C ⟧ ∘ F is below\n-- Companion ∘ Companion, which is below the companion.\n\nbelow-the-companion-example = Up-to.below-the-companion-example\n\n-- The greatest fixpoint is pointwise logically equivalent to the\n-- companion applied to an empty relation.\n\nν⊆companion-⊥ = Up-to.ν⇔companion-⊥\ncompanion-⊥⊆ν = Up-to.ν⇔companion-⊥\n\n-- The companion is an up-to technique.\n\ncompanion-up-to = Up-to.companion-up-to\n\n------------------------------------------------------------------------\n-- Section 8\n\n-- Pous and Sangiorgi's lemma 6.1.3, part (2).\n\n6-1-3-2 = Bisimilarity.CCS.6-1-3-2\n\n-- Instances corresponding to some equational reasoning combinators\n-- mentioned in the paper.\n\n_∼′⟨_⟩′_ = Bisimilarity.Equational-reasoning-instances.trans∼′∼′\n_∼⟨_⟩′_ = Bisimilarity.Equational-reasoning-instances.trans∼∼′\n_■′ = Bisimilarity.Equational-reasoning-instances.reflexive∼′\n\n-- The primed variant of _∣-cong_.\n\n_∣-cong′_ = Bisimilarity.CCS._∣-cong′_\n\n-- Replication preserves strong bisimilarity (already mentioned\n-- above).\n\n!-cong₂ = Bisimilarity.CCS.!-congP\n\n-- Proofs showing that all the CCS process constructors preserve\n-- strong bisimilarity (already mentioned above).\n\nmodule Strong-bisimilarity-congruence₂ = Strong-bisimilarity-congruence\n\n-- Proofs showing that all the CCS process constructors preserve\n-- strong similarity. (For ∅ the proof is simply reflexivity.)\n\nmodule Strong-similarity-congruence where\n\n _∣-cong_ = Similarity.CCS._∣-cong_\n ·-cong = Similarity.CCS._·-cong_\n !-cong = Similarity.CCS.!-cong_\n _⊕-cong_ = Similarity.CCS._⊕-cong_\n ⟨ν_⟩-cong = Similarity.CCS.⟨ν_⟩-cong\n ∅-cong = Similarity.reflexive-≤\n\n-- Proofs showing that all the CCS process constructors, except for\n-- sum, preserve the expansion relation. (For ∅ the proof is simply\n-- reflexivity.)\n\nmodule Expansion-almost-congruence where\n\n _∣-cong_ = Expansion.CCS._∣-cong_\n ·-cong = Expansion.CCS._·-cong_\n !-cong = Expansion.CCS.!-cong_\n ⟨ν_⟩-cong = Expansion.CCS.⟨ν_⟩-cong\n ∅-cong = Expansion.reflexive-≳\n\n-- Proofs showing that all the CCS process constructors, except for\n-- sum, preserve weak bisimilarity. (For ∅ the proof is simply\n-- reflexivity.)\n\nmodule Weak-bisimilarity-almost-congruence where\n\n _∣-cong_ = Bisimilarity.Weak.CCS._∣-cong_\n ·-cong = Bisimilarity.Weak.CCS._·-cong_\n !-cong = Bisimilarity.Weak.CCS.!-cong_\n ⟨ν_⟩-cong = Bisimilarity.Weak.CCS.⟨ν_⟩-cong\n ∅-cong = Bisimilarity.Weak.reflexive-≈\n\n------------------------------------------------------------------------\n-- Section 9\n\n-- Weak bisimilarity for the delay monad.\n--\n-- Note that, unlike in the paper, strong bisimilarity, weak\n-- bisimilarity and the expansion relation are defined as a single\n-- family (with an extra index).\n\n[_]_≈D_ = Delay-monad.Bisimilarity.[_]_≈_\n[_]_≈′D_ = Delay-monad.Bisimilarity.[_]_≈′_\n\n-- This definition is pointwise logically equivalent, in a\n-- size-preserving way, to the one obtained from the LTS for the delay\n-- monad.\n\ndirect⇔indirect = Bisimilarity.Weak.Delay-monad.direct⇔indirect\n\n-- Capretta's definition of weak bisimilarity, formulated using sized\n-- types.\n\nCapretta's-weak-bisimilarity =\n Delay-monad.Bisimilarity.Alternative.[_]_≈₃_\n\n-- Capretta's definition is pointwise logically equivalent, in a\n-- size-preserving way, to the one used in the paper.\n\ndirect⇔Capretta = Delay-monad.Bisimilarity.Alternative.≈⇔≈₃\n\n------------------------------------------------------------------------\n-- Section 9.1\n\n-- Weak bisimilarity is transitive for every LTS.\n\ntransitiveʷ-lts = Bisimilarity.Weak.transitive-≈\n\n-- The later constructors can be removed.\n--\n-- (Two of the proofs are more general than the corresponding proofs\n-- in the paper.)\n\nlaterʳ⁻¹ = Delay-monad.Bisimilarity.laterʳ⁻¹\nlaterˡ⁻¹ = Delay-monad.Bisimilarity.laterˡ⁻¹\nlater⁻¹ = Delay-monad.Bisimilarity.later⁻¹\n\n-- Weak bisimilarity for the delay monad is transitive.\n--\n-- (The proof is not quite identical to the one in the paper.)\n\ntransitiveʷ-now = Delay-monad.Bisimilarity.transitive-≈-now\ntransitiveʷ-later = Delay-monad.Bisimilarity.transitive-≈-later\ntransitiveʷ = Delay-monad.Bisimilarity.transitive-≈\n\n------------------------------------------------------------------------\n-- Section 9.2\n\n-- If transitivity of weak bisimilarity for the delay monad is\n-- size-preserving in both arguments, then weak bisimilarity is\n-- trivial.\n\nsize-preserving→trivial =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈→trivial\n\n-- Weak bisimilarity for the delay monad is reflexive.\n\n_∎ʷ = Delay-monad.Bisimilarity.reflexive\n\n-- The computation now x is not weakly bisimilar to never.\n--\n-- (The proof is more general than the one in the paper.)\n\nnow≉never = Delay-monad.Bisimilarity.now≉never\n\n-- If transitivity of weak bisimilarity for the delay monad is\n-- size-preserving in both arguments, then the carrier type is\n-- uninhabited.\n\nnot-size-preservingʷ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈→uninhabited\n\n-- If transitivity of weak bisimilarity is size-preserving in the\n-- first argument, then weak bisimulations up to weak bisimilarity are\n-- contained in weak bisimilarity.\n\nsize-preserving→weak-bisimulations-up-to-weak-bisimilarity-works =\n Bisimilarity.Weak.Up-to.size-preserving-transitivity→up-to-weak-bisimilarity-up-to\n\n-- The Drop-later predicate.\n\nDrop-later = Delay-monad.Bisimilarity.Negative.Laterˡ⁻¹-∼≈\n\n-- Drop-later A implies that A is not inhabited, and vice versa.\n--\n-- The implementation of basic-counterexample in the paper is\n-- different, because it does not include the \"and vice versa\" part.\n\nbasic-counterexample =\n Delay-monad.Bisimilarity.Negative.size-preserving-laterˡ⁻¹-∼≈⇔uninhabited\n\n-- If there is a transitivity-like proof that takes a fully defined\n-- weak bisimilarity proof and a strong bisimilarity proof of size i\n-- to a weak bisimilarity proof of size i, then the carrier type is\n-- uninhabited (and vice versa).\n--\n-- The implementation is superficially different from the one in the\n-- paper (except for the \"vice versa\" part, which is not present in\n-- the paper).\n\nnot-size-preservingʷˢ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈∼ʳ⇔uninhabited\n\n-- A size-preserving translation from strong to weak bisimilarity for\n-- the delay monad.\n--\n-- (The implementation is more general than the one in the paper.)\n\nstrong-to-weak = Delay-monad.Bisimilarity.∼→\n\n-- Size-preserving translations from strong bisimilarity to expansion\n-- and from expansion to weak bisimilarity for any LTS.\n\nstrong-to-expansion = Expansion.∼⇒≳\nexpansion-to-weak = Bisimilarity.Weak.≳⇒≈\n\n-- If there is a proof of transitivity that takes a fully defined weak\n-- bisimilarity proof and a weak bisimilarity proof of size i to a\n-- weak bisimilarity proof of size i, then the carrier type is\n-- uninhabited (and vice versa).\n--\n-- The implementation is superficially different from the one in the\n-- paper (except for the \"vice versa\" part, which is not present in\n-- the paper).\n\nnot-size-preservingʷʳ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈ʳ⇔uninhabited\n\n-- Size-preserving symmetry proofs for strong and weak bisimilarity.\n--\n-- (Actually a single proof that works for both relations.)\n\nsymmetryˢ = Delay-monad.Bisimilarity.symmetric\nsymmetryʷ = Delay-monad.Bisimilarity.symmetric\n\n-- If there is a proof of transitivity that takes a strong (or\n-- alternatively weak) bisimilarity proof of size i and a fully\n-- defined weak bisimilarity proof to a weak bisimilarity proof of\n-- size i, then the carrier type is uninhabited (and vice versa).\n\nnot-size-preservingˢʷ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-∼≈ˡ⇔uninhabited\nnot-size-preservingʷˡ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈ˡ⇔uninhabited\n\n-- If the carrier type is not inhabited, then weak bisimilarity is\n-- trivial.\n--\n-- (The proof is more general than the one in the paper.)\n\ntrivial = Delay-monad.Bisimilarity.uninhabited→trivial\n\n-- If the type A is uninhabited, then Drop-later A is inhabited (and\n-- vice versa).\n\nbasic-counterexample′ =\n Delay-monad.Bisimilarity.Negative.size-preserving-laterˡ⁻¹-∼≈⇔uninhabited\n\n-- If the carrier type is uninhabited, then there is a fully\n-- size-preserving transitivity proof for weak bisimilarity (and vice\n-- versa).\n\nsize-preservingʷ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈⇔uninhabited\n\n-- Size-preserving transitivity-like proofs involving strong and weak\n-- bisimilarity.\n--\n-- (The type signatures of the proofs are more general than those\n-- given in the paper.)\n\ntransitiveˢʷ = Delay-monad.Bisimilarity.transitive-∼ˡ\ntransitiveʷˢ = Delay-monad.Bisimilarity.transitive-∞∼ʳ\n\n-- A direct definition of expansion for the delay monad.\n\n[_]_≳D_ = Delay-monad.Bisimilarity.[_]_≳_\n\n-- The direct definition of expansion for the delay monad is pointwise\n-- logically equivalent, in a size-preserving way, to the one obtained\n-- from the LTS for the delay monad.\n\ndirect⇔indirect-expansion = Expansion.Delay-monad.direct⇔indirect\n\n-- Size-preserving transitivity-like proofs involving the direct\n-- definitions of weak bisimilarity and expansion for the delay monad.\n--\n-- (The type signatures of the first three proofs are more general\n-- than those given in the paper.)\n\ntransitiveᵉˢ = Delay-monad.Bisimilarity.transitive-∼ʳ\ntransitiveᵉ = Delay-monad.Bisimilarity.transitive-≳ˡ\ntransitiveᵉʷ = Delay-monad.Bisimilarity.transitive-≳ˡ\ntransitiveʷᵉ = Delay-monad.Bisimilarity.transitive-≈≲\n\n-- Size-preserving transitivity-like proofs involving weak\n-- bisimilarity and expansion defined for an arbitrary LTS.\n\ntransitiveᵉˢ-lts = Expansion.transitive-≳∼\ntransitiveᵉ-lts = Expansion.transitive-≳\ntransitiveᵉʷ-lts = Bisimilarity.Weak.transitive-≳≈\ntransitiveʷᵉ-lts = Bisimilarity.Weak.transitive-≈≲\n\n-- Negative results related to expansion.\n\nnot-size-preservingˢᵉ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-∼≳ˡ⇔uninhabited\nnot-size-preservingᵉʷ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≳≈ˡ⇔uninhabited\nnot-size-preservingʷᵉ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈≳ˡ⇔uninhabited\n\n-- The functions transitiveᵉ, transitiveᵉʷ and transitiveʷᵉ cannot in\n-- general be made fully size-preserving.\n\nnot-fully-size-preservingᵉ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≳⇔uninhabited\nnot-fully-size-preservingᵉʷ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≳≈⇔uninhabited\nnot-fully-size-preservingʷᵉ =\n Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-≈≲⇔uninhabited\n\n-- Up to expansion.\n\nUp-to-expansion =\n Bisimilarity.Weak.Up-to.Up-to-expansion\nup-to-expansion-size-preserving =\n Bisimilarity.Weak.Up-to.up-to-expansion-size-preserving\n\n-- Relations that satisfy the diagrams of the variant of up to\n-- expansion where two occurrences of the expansion relation have been\n-- replaced by weak bisimilarity are contained in weak bisimilarity.\n\nvariant-of-up-to-expansion = Bisimilarity.Weak.Up-to.6-5-2-4\n", "meta": {"hexsha": "f9f2e6f04f92594d9938ed918eecb750d3d8af6d", "size": 25783, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "README/Pointers-to-results-from-the-paper.agda", "max_stars_repo_name": "nad/up-to", "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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": "README/Pointers-to-results-from-the-paper.agda", "max_issues_repo_name": "nad/up-to", "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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": "README/Pointers-to-results-from-the-paper.agda", "max_forks_repo_name": "nad/up-to", "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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": 31.3661800487, "max_line_length": 84, "alphanum_fraction": 0.73443742, "num_tokens": 7149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081925, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.35903990309306943}} {"text": "{-\nThis second-order term syntax was created from the following second-order syntax description:\n\nsyntax CTLC | ΛC\n\ntype\n N : 0-ary\n _↣_ : 2-ary | r30\n ¬_ : 1-ary | r30\n\nterm\n app : α ↣ β α -> β | _$_ l20\n lam : α.β -> α ↣ β | ƛ_ r10\n throw : α ¬ α -> β\n callcc : ¬ α.α -> α\n\ntheory\n (ƛβ) b : α.β a : α |> app (lam(x.b[x]), a) = b[a]\n (ƛη) f : α ↣ β |> lam (x. app(f, x)) = f\n-}\n\n\nmodule CTLC.Syntax where\n\nopen import SOAS.Common\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.Families.Core\nopen import SOAS.Construction.Structure\nopen import SOAS.ContextMaps.Inductive\n\nopen import SOAS.Metatheory.Syntax\n\nopen import CTLC.Signature\n\nprivate\n variable\n Γ Δ Π : Ctx\n α β : ΛCT\n 𝔛 : Familyₛ\n\n-- Inductive term declaration\nmodule ΛC:Terms (𝔛 : Familyₛ) where\n\n data ΛC : Familyₛ where\n var : ℐ ⇾̣ ΛC\n mvar : 𝔛 α Π → Sub ΛC Π Γ → ΛC α Γ\n\n _$_ : ΛC (α ↣ β) Γ → ΛC α Γ → ΛC β Γ\n ƛ_ : ΛC β (α ∙ Γ) → ΛC (α ↣ β) Γ\n throw : ΛC α Γ → ΛC (¬ α) Γ → ΛC β Γ\n callcc : ΛC α ((¬ α) ∙ Γ) → ΛC α Γ\n\n infixl 20 _$_\n infixr 10 ƛ_\n\n open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛\n\n ΛCᵃ : MetaAlg ΛC\n ΛCᵃ = record\n { 𝑎𝑙𝑔 = λ where\n (appₒ ⋮ a , b) → _$_ a b\n (lamₒ ⋮ a) → ƛ_ a\n (throwₒ ⋮ a , b) → throw a b\n (callccₒ ⋮ a) → callcc a\n ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }\n\n module ΛCᵃ = MetaAlg ΛCᵃ\n\n module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where\n\n open MetaAlg 𝒜ᵃ\n\n 𝕤𝕖𝕞 : ΛC ⇾̣ 𝒜\n 𝕊 : Sub ΛC Π Γ → Π ~[ 𝒜 ]↝ Γ\n 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t\n 𝕊 (t ◂ σ) (old v) = 𝕊 σ v\n 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)\n 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v\n\n 𝕤𝕖𝕞 (_$_ a b) = 𝑎𝑙𝑔 (appₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 (ƛ_ a) = 𝑎𝑙𝑔 (lamₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (throw a b) = 𝑎𝑙𝑔 (throwₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 (callcc a) = 𝑎𝑙𝑔 (callccₒ ⋮ 𝕤𝕖𝕞 a)\n\n 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ ΛCᵃ 𝒜ᵃ 𝕤𝕖𝕞\n 𝕤𝕖𝕞ᵃ⇒ = record\n { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }\n ; ⟨𝑣𝑎𝑟⟩ = refl\n ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }\n where\n open ≡-Reasoning\n ⟨𝑎𝑙𝑔⟩ : (t : ⅀ ΛC α Γ) → 𝕤𝕖𝕞 (ΛCᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)\n ⟨𝑎𝑙𝑔⟩ (appₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (lamₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (throwₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (callccₒ ⋮ _) = refl\n\n 𝕊-tab : (mε : Π ~[ ΛC ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)\n 𝕊-tab mε new = refl\n 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v\n\n module _ (g : ΛC ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ ΛCᵃ 𝒜ᵃ g) where\n\n open MetaAlg⇒ gᵃ⇒\n\n 𝕤𝕖𝕞! : (t : ΛC α Γ) → 𝕤𝕖𝕞 t ≡ g t\n 𝕊-ix : (mε : Sub ΛC Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)\n 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x\n 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v\n 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))\n = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))\n 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩\n\n 𝕤𝕖𝕞! (_$_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (ƛ_ a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (throw a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (callcc a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n\n\n-- Syntax instance for the signature\nΛC:Syn : Syntax\nΛC:Syn = record\n { ⅀F = ⅀F\n ; ⅀:CS = ⅀:CompatStr\n ; mvarᵢ = ΛC:Terms.mvar\n ; 𝕋:Init = λ 𝔛 → let open ΛC:Terms 𝔛 in record\n { ⊥ = ΛC ⋉ ΛCᵃ\n ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }\n ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }\n\n-- Instantiation of the syntax and metatheory\nopen Syntax ΛC:Syn public\nopen ΛC:Terms public\nopen import SOAS.Families.Build public\nopen import SOAS.Syntax.Shorthands ΛCᵃ public\nopen import SOAS.Metatheory ΛC:Syn public\n", "meta": {"hexsha": "a346871f12bdf7799d45e6fbf226f1603d12a567", "size": 3635, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "out/CTLC/Syntax.agda", "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_issues_repo_path": "out/CTLC/Syntax.agda", "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_forks_repo_path": "out/CTLC/Syntax.agda", "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "avg_line_length": 26.3405797101, "max_line_length": 93, "alphanum_fraction": 0.5204951857, "num_tokens": 2374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494421679929, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.3590398963722477}} {"text": "------------------------------------------------------------------------\n-- Truncation, defined as a HIT\n------------------------------------------------------------------------\n\n{-# OPTIONS --erased-cubical --safe #-}\n\n-- The beginning of this module follows the HoTT book rather closely.\n\n-- The module is parametrised by a notion of equality. The higher\n-- constructor of the HIT defining the truncation uses path equality,\n-- but the supplied notion of equality is used for many other things.\n\nimport Equality.Path as P\n\nmodule H-level.Truncation\n {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where\n\nopen P.Derived-definitions-and-properties eq hiding (elim)\n\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude\n\nopen import Bijection equality-with-J using (_↔_)\nopen import Equality.Path.Isomorphisms eq\nopen import Equivalence equality-with-J as Eq using (_≃_)\nopen import Function-universe equality-with-J hiding (id; _∘_)\nopen import H-level equality-with-J\nopen import H-level.Closure equality-with-J\nopen import H-level.Truncation.Propositional eq as TP using (∥_∥)\nopen import Monad equality-with-J\nopen import Nat equality-with-J as Nat using (_≤_; min)\nimport Pointed-type equality-with-J as PT\nopen import Sphere eq\nopen import Suspension eq as Susp using (north)\nopen import Univalence-axiom equality-with-J\n\nprivate\n variable\n a b ℓ p : Level\n A B C : Type a\n P : A → Type p\n e x y : A\n f g r : A → B\n m n : ℕ\n k : Isomorphism-kind\n\n-- A truncation operator for positive h-levels.\n\ndata ∥_∥[1+_] (A : Type a) (n : ℕ) : Type a where\n ∣_∣ : A → ∥ A ∥[1+ n ]\n hub : (r : 𝕊 n → ∥ A ∥[1+ n ]) → ∥ A ∥[1+ n ]\n spokeᴾ : (r : 𝕊 n → ∥ A ∥[1+ n ]) (x : 𝕊 n) → r x P.≡ hub r\n\n-- Spoke equalities.\n\nspoke : (r : 𝕊 n → ∥ A ∥[1+ n ]) (x : 𝕊 n) → r x ≡ hub r\nspoke r x = _↔_.from ≡↔≡ (spokeᴾ r x)\n\n-- The truncation operator produces types of the right h-level.\n\ntruncation-has-correct-h-level : ∀ n → H-level (1 + n) ∥ A ∥[1+ n ]\ntruncation-has-correct-h-level {A = A} n =\n _↔_.from +↔∀contractible𝕊→ᴮ c\n where\n c : ∀ x → Contractible ((𝕊 n , north) PT.→ᴮ (∥ A ∥[1+ n ] , x))\n c x =\n (const x , (const x (north {A = 𝕊 n}) ≡⟨⟩\n x ∎))\n , λ { (f , fn≡x) → Σ-≡,≡→≡\n (⟨ext⟩ λ y →\n const x y ≡⟨⟩\n x ≡⟨ sym fn≡x ⟩\n f north ≡⟨ spoke f north ⟩\n hub f ≡⟨ sym $ spoke f y ⟩∎\n f y ∎)\n (subst (λ f → f north ≡ x)\n (⟨ext⟩ (λ y → trans (sym fn≡x)\n (trans (spoke f north)\n (sym (spoke f y)))))\n (refl x) ≡⟨ subst-ext _ _ ⟩\n\n subst (_≡ x)\n (trans (sym fn≡x)\n (trans (spoke f north) (sym (spoke f north))))\n (refl x) ≡⟨ cong (λ p → subst (_≡ x) (trans (sym fn≡x) p) (refl x)) $ trans-symʳ _ ⟩\n\n subst (_≡ x) (trans (sym fn≡x) (refl (f north))) (refl x) ≡⟨ cong (λ p → subst (_≡ x) p (refl x)) $ trans-reflʳ _ ⟩\n\n subst (_≡ x) (sym fn≡x) (refl x) ≡⟨ subst-trans _ ⟩\n\n trans fn≡x (refl x) ≡⟨ trans-reflʳ _ ⟩∎\n\n fn≡x ∎)\n }\n\n-- A dependent eliminator, expressed using paths.\n\nrecord Elimᴾ {A : Type a} (P : ∥ A ∥[1+ n ] → Type p) :\n Type (a ⊔ p) where\n no-eta-equality\n field\n ∣∣ʳ : ∀ x → P ∣ x ∣\n hubʳ : (r : 𝕊 n → ∥ A ∥[1+ n ]) →\n (∀ x → P (r x)) →\n P (hub r)\n spokeʳ : (r : 𝕊 n → ∥ A ∥[1+ n ])\n (p : ∀ x → P (r x))\n (x : 𝕊 n) →\n P.[ (λ i → P (spokeᴾ r x i)) ] p x ≡ hubʳ r p\n\nopen Elimᴾ public\n\nelimᴾ : Elimᴾ P → ∀ x → P x\nelimᴾ {P = P} e = helper\n where\n module E = Elimᴾ e\n\n helper : ∀ x → P x\n helper ∣ x ∣ = E.∣∣ʳ x\n helper (hub r) = E.hubʳ r (λ x → helper (r x))\n helper (spokeᴾ r x i) = E.spokeʳ r (λ x → helper (r x)) x i\n\n-- A non-dependent eliminator, expressed using paths.\n\nrecord Recᴾ (n : ℕ) (A : Type a) (B : Type b) : Type (a ⊔ b) where\n no-eta-equality\n field\n ∣∣ʳ : A → B\n hubʳ : (𝕊 n → ∥ A ∥[1+ n ]) → (𝕊 n → B) → B\n spokeʳ : (r : 𝕊 n → ∥ A ∥[1+ n ]) (p : 𝕊 n → B) (x : 𝕊 n) →\n p x P.≡ hubʳ r p\n\nopen Recᴾ public\n\nrecᴾ : Recᴾ n A B → ∥ A ∥[1+ n ] → B\nrecᴾ r = elimᴾ eᴾ\n where\n module R = Recᴾ r\n\n eᴾ : Elimᴾ _\n eᴾ .∣∣ʳ = r .∣∣ʳ\n eᴾ .hubʳ = r .hubʳ\n eᴾ .spokeʳ = r .spokeʳ\n\n-- A dependent eliminator.\n\nrecord Elim′ {A : Type a} (P : ∥ A ∥[1+ n ] → Type p) :\n Type (a ⊔ p) where\n no-eta-equality\n field\n ∣∣ʳ : ∀ x → P ∣ x ∣\n hubʳ : (r : 𝕊 n → ∥ A ∥[1+ n ]) →\n (∀ x → P (r x)) →\n P (hub r)\n spokeʳ : (r : 𝕊 n → ∥ A ∥[1+ n ])\n (p : ∀ x → P (r x))\n (x : 𝕊 n) →\n subst P (spoke r x) (p x) ≡ hubʳ r p\n\nopen Elim′ public\n\nelim′ : Elim′ P → ∀ x → P x\nelim′ e′ = elimᴾ eᴾ\n where\n module E′ = Elim′ e′\n\n eᴾ : Elimᴾ _\n eᴾ .∣∣ʳ = E′.∣∣ʳ\n eᴾ .hubʳ = E′.hubʳ\n eᴾ .spokeʳ r p x = subst≡→[]≡ (E′.spokeʳ r p x)\n\nelim′-spoke :\n dcong (elim′ e) (spoke r x) ≡\n Elim′.spokeʳ e r (λ x → elim′ e (r x)) x\nelim′-spoke = dcong-subst≡→[]≡ (refl _)\n\n-- A non-dependent eliminator.\n\nrecord Rec′ (n : ℕ) (A : Type a) (B : Type b) : Type (a ⊔ b) where\n no-eta-equality\n field\n ∣∣ʳ : A → B\n hubʳ : (𝕊 n → ∥ A ∥[1+ n ]) → (𝕊 n → B) → B\n spokeʳ : (r : 𝕊 n → ∥ A ∥[1+ n ]) (p : 𝕊 n → B) (x : 𝕊 n) →\n p x ≡ hubʳ r p\n\nopen Rec′ public\n\nrec′ : Rec′ n A B → ∥ A ∥[1+ n ] → B\nrec′ r′ = recᴾ rᴾ\n where\n module R′ = Rec′ r′\n\n rᴾ : Recᴾ _ _ _\n rᴾ .∣∣ʳ = R′.∣∣ʳ\n rᴾ .hubʳ = R′.hubʳ\n rᴾ .spokeʳ r p x = _↔_.to ≡↔≡ (R′.spokeʳ r p x)\n\nrec′-spoke :\n cong (rec′ e) (spoke r x) ≡ Rec′.spokeʳ e r (λ x → rec′ e (r x)) x\nrec′-spoke = cong-≡↔≡ (refl _)\n\n-- A dependent eliminator that can be used when the motive is a family\n-- of types, all of a certain h-level.\n\nrecord Elim {A : Type a} (P : ∥ A ∥[1+ n ] → Type p) :\n Type (a ⊔ p) where\n no-eta-equality\n field\n ∣∣ʳ : ∀ x → P ∣ x ∣\n h-levelʳ : ∀ x → H-level (1 + n) (P x)\n\nopen Elim public\n\nelim : Elim {n = n} {A = A} P → ∀ x → P x\nelim {n = n} {A = A} {P = P} e = elim′ e′\n where\n module _ (r : 𝕊 n → ∥ A ∥[1+ n ]) (p : ∀ x → P (r x)) where\n\n h′ : 𝕊 n → P (hub r)\n h′ x = subst P (spoke r x) (p x)\n\n h = h′ north\n\n lemma = $⟨ e .h-levelʳ ⟩\n (∀ x → H-level (1 + n) (P x)) ↝⟨ _$ _ ⟩\n H-level (1 + n) (P (hub r)) ↔⟨ +↔∀contractible𝕊→ᴮ ⟩\n (∀ h → Contractible ((𝕊 n , north) PT.→ᴮ (P (hub r) , h))) ↝⟨ _$ _ ⟩\n Contractible ((𝕊 n , north) PT.→ᴮ (P (hub r) , h)) ↝⟨ mono₁ _ ⟩□\n Is-proposition ((𝕊 n , north) PT.→ᴮ (P (hub r) , h)) □\n\n s = λ x →\n subst P (spoke r x) (p x) ≡⟨⟩\n h′ x ≡⟨ cong (λ f → proj₁ f x) $ lemma (h′ , refl _) (const h , refl _) ⟩\n const h x ≡⟨⟩\n h ∎\n\n e′ : Elim′ _\n e′ .∣∣ʳ = e .∣∣ʳ\n e′ .hubʳ = h\n e′ .spokeʳ = s\n\n-- A non-dependent eliminator that can be used when the motive is a\n-- type of a certain h-level.\n\nrecord Rec (n : ℕ) (A : Type a) (B : Type b) : Type (a ⊔ b) where\n no-eta-equality\n field\n ∣∣ʳ : A → B\n h-levelʳ : H-level (1 + n) B\n\nopen Rec public\n\nrec : Rec n A B → ∥ A ∥[1+ n ] → B\nrec r = elim λ where\n .∣∣ʳ → r .∣∣ʳ\n .h-levelʳ _ → r .h-levelʳ\n\n-- Dependent functions into P that agree on the image of ∣_∣ agree\n-- everywhere, if P is a family of types that all have a certain\n-- h-level.\n\nuniqueness′ :\n {f g : (x : ∥ A ∥[1+ n ]) → P x} →\n (∀ x → H-level (2 + n) (P x)) →\n ((x : A) → f ∣ x ∣ ≡ g ∣ x ∣) →\n ((x : ∥ A ∥[1+ n ]) → f x ≡ g x)\nuniqueness′ {n = n} P-h f≡g = elim λ where\n .∣∣ʳ → f≡g\n .h-levelʳ _ → +⇒≡ {n = suc n} (P-h _)\n\n-- A special case of the previous property.\n\nuniqueness :\n {f g : ∥ A ∥[1+ n ] → B} →\n H-level (1 + n) B →\n ((x : A) → f ∣ x ∣ ≡ g ∣ x ∣) →\n ((x : ∥ A ∥[1+ n ]) → f x ≡ g x)\nuniqueness h = uniqueness′ (λ _ → mono₁ _ h)\n\n-- The truncation operator's universal property.\n\nuniversal-property :\n H-level (1 + n) B →\n (∥ A ∥[1+ n ] → B) ↔ (A → B)\nuniversal-property h = record\n { surjection = record\n { logical-equivalence = record\n { to = _∘ ∣_∣\n ; from = λ f → rec λ where\n .∣∣ʳ → f\n .h-levelʳ → h\n }\n ; right-inverse-of = refl\n }\n ; left-inverse-of = λ f → ⟨ext⟩ $ uniqueness h (λ x → f ∣ x ∣ ∎)\n }\n\n-- The truncation operator ∥_∥[1+ n ] is a functor.\n\n∥∥-map : (A → B) → ∥ A ∥[1+ n ] → ∥ B ∥[1+ n ]\n∥∥-map f = rec λ where\n .∣∣ʳ x → ∣ f x ∣\n .h-levelʳ → truncation-has-correct-h-level _\n\n∥∥-map-id :\n (x : ∥ A ∥[1+ n ]) →\n ∥∥-map id x ≡ x\n∥∥-map-id = uniqueness\n (truncation-has-correct-h-level _)\n (λ x → ∣ x ∣ ∎)\n\n∥∥-map-∘ :\n (x : ∥ A ∥[1+ n ]) →\n ∥∥-map (f ∘ g) x ≡ ∥∥-map f (∥∥-map g x)\n∥∥-map-∘ {f = f} {g = g} = uniqueness\n (truncation-has-correct-h-level _)\n (λ x → ∣ f (g x) ∣ ∎)\n\n-- A zip function.\n\n∥∥-zip : (A → B → C) → ∥ A ∥[1+ n ] → ∥ B ∥[1+ n ] → ∥ C ∥[1+ n ]\n∥∥-zip f = rec λ where\n .∣∣ʳ x → ∥∥-map (f x)\n .h-levelʳ → Π-closure ext _ λ _ →\n truncation-has-correct-h-level _\n\n-- A has h-level 1 + n if and only if it is isomorphic to\n-- ∥ A ∥[1+ n ].\n\n+⇔∥∥↔ : H-level (1 + n) A ⇔ (∥ A ∥[1+ n ] ↔ A)\n+⇔∥∥↔ {n = n} {A = A} = record\n { to = λ h → record\n { surjection = record\n { logical-equivalence = record\n { from = ∣_∣\n ; to = rec λ where\n .∣∣ʳ → id\n .h-levelʳ → h\n }\n ; right-inverse-of = refl\n }\n ; left-inverse-of = elim λ where\n .∣∣ʳ x → ∣ x ∣ ∎\n .h-levelʳ _ → ⇒≡ _ $ truncation-has-correct-h-level _\n }\n ; from =\n ∥ A ∥[1+ n ] ↔ A ↝⟨ H-level-cong ext _ ⟩\n (H-level (1 + n) ∥ A ∥[1+ n ] ↔ H-level (1 + n) A) ↝⟨ (λ hyp → _↔_.to hyp (truncation-has-correct-h-level _)) ⟩□\n H-level (1 + n) A □\n }\n\n-- The (1 + n)-truncation of x ≡ y, where x and y have type A, is\n-- equivalent to the equality of ∣ x ∣ and ∣ y ∣ (as elements of the\n-- (2 + n)-truncation of A), assuming univalence.\n--\n-- Along with the fact that this lemma computes in a certain way (see\n-- below) this is more or less Theorem 7.3.12 from the HoTT book.\n\n∥≡∥≃∣∣≡∣∣ :\n {A : Type a} {x y : A} →\n Univalence a →\n ∥ x ≡ y ∥[1+ n ] ≃ _≡_ {A = ∥ A ∥[1+ suc n ]} ∣ x ∣ ∣ y ∣\n∥≡∥≃∣∣≡∣∣ {n = n} {A = A} univ = Eq.↔→≃\n (decode ∣ _ ∣ ∣ _ ∣)\n (encode ∣ _ ∣ ∣ _ ∣)\n (decode-encode _)\n (encode-decode _ _)\n where\n Eq : (_ _ : ∥ A ∥[1+ suc n ]) → ∃ λ (B : Type _) → H-level (suc n) B\n Eq = rec λ where\n .h-levelʳ →\n Π-closure ext (2 + n) λ _ →\n ∃-H-level-H-level-1+ ext univ (1 + n)\n .∣∣ʳ x → rec λ where\n .h-levelʳ → ∃-H-level-H-level-1+ ext univ (1 + n)\n .∣∣ʳ y →\n ∥ x ≡ y ∥[1+ n ] , truncation-has-correct-h-level n\n\n Eq-refl : (x : ∥ A ∥[1+ suc n ]) → proj₁ (Eq x x)\n Eq-refl = elim λ where\n .∣∣ʳ x → ∣ refl x ∣\n .h-levelʳ x → mono₁ (1 + n) $ proj₂ (Eq x x)\n\n decode : ∀ x y → proj₁ (Eq x y) → x ≡ y\n decode = elim λ where\n .h-levelʳ _ →\n Π-closure ext (2 + n) λ _ →\n Π-closure ext (2 + n) λ _ →\n mono₁ (2 + n) $ truncation-has-correct-h-level (1 + n)\n .∣∣ʳ x → elim λ where\n .h-levelʳ _ →\n Π-closure ext (2 + n) λ _ →\n mono₁ (2 + n) $ truncation-has-correct-h-level (1 + n)\n .∣∣ʳ y → rec λ where\n .h-levelʳ → truncation-has-correct-h-level (1 + n)\n .∣∣ʳ → cong ∣_∣\n\n encode : ∀ x y → x ≡ y → proj₁ (Eq x y)\n encode x y x≡y = subst (λ y → proj₁ (Eq x y)) x≡y (Eq-refl x)\n\n decode-encode : ∀ x (x≡y : x ≡ y) → decode x y (encode x y x≡y) ≡ x≡y\n decode-encode = elim λ where\n .h-levelʳ _ →\n Π-closure ext (2 + n) λ _ →\n mono₁ (3 + n) $ mono₁ (2 + n) $\n truncation-has-correct-h-level (1 + n)\n .∣∣ʳ x → elim¹\n (λ x≡y → decode _ _ (encode _ _ x≡y) ≡ x≡y)\n (decode (∣ x ∣) (∣ x ∣) (encode ∣ x ∣ ∣ x ∣ (refl ∣ x ∣)) ≡⟨⟩\n\n decode (∣ x ∣) (∣ x ∣)\n (subst (λ y → proj₁ (Eq ∣ x ∣ y)) (refl ∣ x ∣) ∣ refl x ∣) ≡⟨ cong (decode _ _) $ subst-refl _ _ ⟩\n\n decode (∣ x ∣) (∣ x ∣) (∣ refl x ∣) ≡⟨⟩\n\n cong ∣_∣ (refl x) ≡⟨ cong-refl _ ⟩∎\n\n refl ∣ x ∣ ∎)\n\n encode-decode :\n ∀ x y (eq : proj₁ (Eq x y)) → encode x y (decode x y eq) ≡ eq\n encode-decode = elim λ where\n .h-levelʳ x →\n Π-closure ext (2 + n) λ y →\n Π-closure ext (2 + n) λ _ →\n mono₁ (2 + n) $ mono₁ (1 + n) $\n proj₂ (Eq x y)\n .∣∣ʳ x → elim λ where\n .h-levelʳ y →\n Π-closure ext (2 + n) λ _ →\n mono₁ (2 + n) $ mono₁ (1 + n) $\n proj₂ (Eq ∣ x ∣ y)\n .∣∣ʳ y → elim λ where\n .h-levelʳ _ →\n mono₁ (1 + n) $ truncation-has-correct-h-level n\n .∣∣ʳ eq →\n encode ∣ x ∣ ∣ y ∣ (decode (∣ x ∣) (∣ y ∣) (∣ eq ∣)) ≡⟨⟩\n subst (λ y → proj₁ (Eq ∣ x ∣ y)) (cong ∣_∣ eq) (∣ refl x ∣) ≡⟨ sym $ subst-∘ _ _ _ ⟩\n subst (λ y → proj₁ (Eq ∣ x ∣ ∣ y ∣)) eq (∣ refl x ∣) ≡⟨⟩\n subst (λ y → ∥ x ≡ y ∥[1+ n ]) eq (∣ refl x ∣) ≡⟨ elim¹\n (λ eq → subst (λ y → ∥ x ≡ y ∥[1+ n ]) eq (∣ refl x ∣) ≡\n ∣ subst (x ≡_) eq (refl x) ∣)\n (trans (subst-refl _ _) $\n cong ∣_∣ $ sym $ subst-refl _ _)\n _ ⟩\n ∣ subst (x ≡_) eq (refl x) ∣ ≡⟨ cong ∣_∣ $ sym trans-subst ⟩\n ∣ trans (refl x) eq ∣ ≡⟨ cong ∣_∣ $ trans-reflˡ _ ⟩∎\n ∣ eq ∣ ∎\n\n_ :\n {A : Type a} {x y : A} {univ : Univalence a}\n {x≡y : x ≡ y} →\n _≃_.to (∥≡∥≃∣∣≡∣∣ {n = n} univ) ∣ x≡y ∣ ≡ cong ∣_∣ x≡y\n_ = refl _\n\n-- The truncation operator commutes with _×_.\n--\n-- This result is similar to Theorem 7.3.8 from the HoTT book.\n\n∥∥×∥∥≃∥×∥ : (∥ A ∥[1+ n ] × ∥ B ∥[1+ n ]) ≃ ∥ A × B ∥[1+ n ]\n∥∥×∥∥≃∥×∥ {n = n} = Eq.↔→≃\n (uncurry $ rec λ where\n .h-levelʳ → Π-closure ext _ λ _ →\n truncation-has-correct-h-level _\n .∣∣ʳ x → rec λ where\n .h-levelʳ → truncation-has-correct-h-level _\n .∣∣ʳ y → ∣ x , y ∣)\n (rec λ where\n .∣∣ʳ → Σ-map ∣_∣ ∣_∣\n .h-levelʳ → s)\n (elim λ where\n .∣∣ʳ _ → refl _\n .h-levelʳ _ →\n mono₁ (1 + n) $ truncation-has-correct-h-level n)\n (uncurry $ elim λ where\n .h-levelʳ _ → Π-closure ext (1 + n) λ _ →\n mono₁ (1 + n) s\n .∣∣ʳ _ → elim λ where\n .h-levelʳ _ → mono₁ (1 + n) s\n .∣∣ʳ _ → refl _)\n where\n s = ×-closure _\n (truncation-has-correct-h-level _)\n (truncation-has-correct-h-level _)\n\n-- Nested truncations where the inner truncation's h-level is at least\n-- as large as the outer truncation's h-level can be flattened.\n\nflatten-≥ : m ≤ n → ∥ ∥ A ∥[1+ n ] ∥[1+ m ] ↔ ∥ A ∥[1+ m ]\nflatten-≥ m≤n = record\n { surjection = record\n { logical-equivalence = record\n { from = ∥∥-map ∣_∣\n ; to = rec λ where\n .h-levelʳ → truncation-has-correct-h-level _\n .∣∣ʳ → rec λ where\n .∣∣ʳ → ∣_∣\n .h-levelʳ → mono (Nat.suc≤suc m≤n)\n (truncation-has-correct-h-level _)\n }\n ; right-inverse-of = uniqueness\n (truncation-has-correct-h-level _)\n (λ x → ∣ x ∣ ∎)\n }\n ; left-inverse-of = uniqueness\n (truncation-has-correct-h-level _)\n (uniqueness\n (mono (Nat.suc≤suc m≤n)\n (truncation-has-correct-h-level _))\n (λ x → ∣ ∣ x ∣ ∣ ∎))\n }\n\n-- The remainder of this module is not based on the HoTT book.\n\n-- Nested truncations where the inner truncation's h-level is at most\n-- as large as the outer truncation's h-level can be flattened.\n\nflatten-≤ : m ≤ n → ∥ ∥ A ∥[1+ m ] ∥[1+ n ] ↔ ∥ A ∥[1+ m ]\nflatten-≤ m≤n = record\n { surjection = record\n { logical-equivalence = record\n { from = ∣_∣\n ; to = rec λ where\n .∣∣ʳ → id\n .h-levelʳ → mono (Nat.suc≤suc m≤n)\n (truncation-has-correct-h-level _)\n }\n ; right-inverse-of = refl\n }\n ; left-inverse-of = uniqueness\n (truncation-has-correct-h-level _)\n (λ x → ∣ x ∣ ∎)\n }\n\n-- Nested truncations can be flattened.\n\nflatten : ∥ ∥ A ∥[1+ m ] ∥[1+ n ] ↔ ∥ A ∥[1+ min m n ]\nflatten {A = A} {m = m} {n = n} = case Nat.total m n of λ where\n (inj₁ m≤n) → ∥ ∥ A ∥[1+ m ] ∥[1+ n ] ↝⟨ flatten-≤ m≤n ⟩\n ∥ A ∥[1+ m ] ↝⟨ ≡⇒↝ _ $ cong ∥ A ∥[1+_] $ sym $ _⇔_.to Nat.≤⇔min≡ m≤n ⟩□\n ∥ A ∥[1+ min m n ] □\n (inj₂ m≥n) → ∥ ∥ A ∥[1+ m ] ∥[1+ n ] ↝⟨ flatten-≥ m≥n ⟩\n ∥ A ∥[1+ n ] ↝⟨ ≡⇒↝ _ $ cong ∥ A ∥[1+_] $ sym $ _⇔_.to Nat.≤⇔min≡ m≥n ⟩\n ∥ A ∥[1+ min n m ] ↝⟨ ≡⇒↝ _ $ cong ∥ A ∥[1+_] $ Nat.min-comm _ _ ⟩□\n ∥ A ∥[1+ min m n ] □\n\n-- The propositional truncation operator ∥_∥ is pointwise isomorphic\n-- to ∥_∥[1+ 0 ].\n\n∥∥↔∥∥ : ∥ A ∥ ↔ ∥ A ∥[1+ 0 ]\n∥∥↔∥∥ = record\n { surjection = record\n { logical-equivalence = record\n { to = TP.rec (truncation-has-correct-h-level 0) ∣_∣\n ; from = rec λ where\n .∣∣ʳ → TP.∣_∣\n .h-levelʳ → TP.truncation-is-proposition\n }\n ; right-inverse-of = λ _ → truncation-has-correct-h-level 0 _ _\n }\n ; left-inverse-of = λ _ → TP.truncation-is-proposition _ _\n }\n\n-- A universe-polymorphic variant of bind.\n\ninfixl 5 _>>=′_\n\n_>>=′_ : ∥ A ∥[1+ n ] → (A → ∥ B ∥[1+ n ]) → ∥ B ∥[1+ n ]\n_>>=′_ {A = A} {n = n} {B = B} = curry (\n ∥ A ∥[1+ n ] × (A → ∥ B ∥[1+ n ]) ↝⟨ uncurry (flip ∥∥-map) ⟩\n ∥ ∥ B ∥[1+ n ] ∥[1+ n ] ↔⟨ flatten-≤ Nat.≤-refl ⟩□\n ∥ B ∥[1+ n ] □)\n\n-- ∥_∥[1+ n ] is a monad.\n\ninstance\n\n monad : Monad {c = ℓ} (∥_∥[1+ n ])\n Raw-monad.return (Monad.raw-monad monad) = ∣_∣\n\n Raw-monad._>>=_ (Monad.raw-monad monad) = _>>=′_\n\n Monad.left-identity monad = λ _ _ → refl _\n\n Monad.right-identity monad =\n uniqueness (truncation-has-correct-h-level _) (λ _ → refl _)\n\n Monad.associativity monad = flip λ f → flip λ g → uniqueness\n (truncation-has-correct-h-level _)\n (λ x → f x >>=′ g ∎)\n\n-- The truncation operator preserves logical equivalences.\n\n∥∥-cong-⇔ : A ⇔ B → ∥ A ∥[1+ n ] ⇔ ∥ B ∥[1+ n ]\n∥∥-cong-⇔ A⇔B = record\n { to = ∥∥-map (_⇔_.to A⇔B)\n ; from = ∥∥-map (_⇔_.from A⇔B)\n }\n\n-- The truncation operator preserves bijections.\n\n∥∥-cong : A ↔[ k ] B → ∥ A ∥[1+ n ] ↔[ k ] ∥ B ∥[1+ n ]\n∥∥-cong {n = n} A↝B = from-bijection (record\n { surjection = record\n { logical-equivalence = record\n { to = ∥∥-map (_↔_.to A↔B)\n ; from = ∥∥-map (_↔_.from A↔B)\n }\n ; right-inverse-of = lemma A↔B\n }\n ; left-inverse-of = lemma (inverse A↔B)\n })\n where\n A↔B = from-isomorphism A↝B\n\n lemma :\n (A↔B : A ↔ B) (x : ∥ B ∥[1+ n ]) →\n ∥∥-map (_↔_.to A↔B) (∥∥-map (_↔_.from A↔B) x) ≡ x\n lemma A↔B x =\n ∥∥-map (_↔_.to A↔B) (∥∥-map (_↔_.from A↔B) x) ≡⟨ sym $ ∥∥-map-∘ x ⟩\n ∥∥-map (_↔_.to A↔B ∘ _↔_.from A↔B) x ≡⟨ cong (λ f → ∥∥-map f x) $ ⟨ext⟩ $ _↔_.right-inverse-of A↔B ⟩\n ∥∥-map id x ≡⟨ ∥∥-map-id x ⟩∎\n x ∎\n\n-- ∥ A ∥[1+_] is downwards closed.\n\ndownwards-closed : m ≤ n → ∥ A ∥[1+ n ] → ∥ A ∥[1+ m ]\ndownwards-closed {m = m} {n = n} {A = A} m≤n =\n ∥ A ∥[1+ n ] ↝⟨ ∥∥-map ∣_∣ ⟩\n ∥ ∥ A ∥[1+ m ] ∥[1+ n ] ↔⟨ flatten-≤ m≤n ⟩□\n ∥ A ∥[1+ m ] □\n", "meta": {"hexsha": "bcd1702f64663ce4b9abbf568a5e2d5d7d89e43b", "size": 20338, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/H-level/Truncation.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/H-level/Truncation.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/H-level/Truncation.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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": 32.1295418641, "max_line_length": 147, "alphanum_fraction": 0.4399154292, "num_tokens": 8590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.5312093733737562, "lm_q1q2_score": 0.3589724902554946}} {"text": "------------------------------------------------------------------------\n-- Validity of declarative kinding of Fω with interval kinds\n------------------------------------------------------------------------\n\n{-# OPTIONS --safe --without-K #-}\n\nmodule FOmegaInt.Kinding.Declarative.Validity where\n\nopen import Data.Fin using (zero)\nopen import Data.Fin.Substitution.ExtraLemmas\nopen import Data.Product as Prod using (_,_; _×_; proj₁; proj₂)\nopen import Relation.Binary.PropositionalEquality using (_≡_; refl; subst)\n\nopen import FOmegaInt.Syntax\nopen import FOmegaInt.Kinding.Declarative\n\n\n------------------------------------------------------------------------\n-- Validity of declarative kinding, subkinding and subtyping\n\nopen Syntax\nopen Substitution hiding (subst)\nopen TermCtx\nopen Kinding\nopen WfCtxOps using (lookup-kd)\nopen KindedSubstitution\nopen WfSubstitutionEquality\n\n-- An admissible rule for kinding η-expanded type operators.\nTp∈-η : ∀ {n} {Γ : Ctx n} {a j k} →\n Γ ⊢Tp a ∈ Π j k → Γ ⊢ j kd → kd j ∷ Γ ⊢ k kd →\n Γ ⊢Tp Λ j (weaken a · var zero) ∈ Π j k\nTp∈-η {k = k} a∈Πjk j-kd k-kd =\n ∈-Π-i j-kd (subst (_ ⊢Tp _ ∈_) k′[z]≡k (∈-Π-e a∈Πjk′ z∈k k-kd′ k[z]-kd)) k-kd\n where\n module KL = TermLikeLemmas termLikeLemmasKind\n\n j-wf = wf-kd j-kd\n j-kd′ = kd-weaken j-wf j-kd\n k-kd′ = kd-/Var k-kd (Var∈-↑ (wf-kd j-kd′) (Var∈-wk j-wf))\n z∈k = ∈-var zero (j-wf ∷ kd-ctx j-kd) refl\n a∈Πjk′ = Tp∈-weaken j-wf a∈Πjk\n k[z]-kd = kd-[] k-kd′ (∈-tp z∈k)\n k′[z]≡k = Kind-wk↑-sub-zero-vanishes k\n\nmutual\n\n -- Validity of kinding: the kinds of well-kinded types are well-formed.\n Tp∈-valid : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ k kd\n Tp∈-valid (∈-var x Γ-ctx Γ[x]≡kd-k) = lookup-kd x Γ-ctx Γ[x]≡kd-k\n Tp∈-valid (∈-⊥-f Γ-ctx) = *-kd Γ-ctx\n Tp∈-valid (∈-⊤-f Γ-ctx) = *-kd Γ-ctx\n Tp∈-valid (∈-∀-f k-kd a∈*) = *-kd (kd-ctx k-kd)\n Tp∈-valid (∈-→-f a∈* b∈*) = *-kd (Tp∈-ctx a∈*)\n Tp∈-valid (∈-Π-i j-kd a∈k k-kd) = kd-Π j-kd (Tp∈-valid a∈k)\n Tp∈-valid (∈-Π-e a∈Πjk b∈j k-kd k[b]-kd) = k[b]-kd\n Tp∈-valid (∈-s-i a∈b⋯c) = let a∈* = Tp∈-⋯-* a∈b⋯c in kd-⋯ a∈* a∈*\n Tp∈-valid (∈-⇑ a∈j j<∷k) = proj₂ (<∷-valid j<∷k)\n\n -- Validity of subkinding: subkinds are well-formed.\n <∷-valid : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → Γ ⊢ j kd × Γ ⊢ k kd\n <∷-valid (<∷-⋯ a₂<:a₁∈* b₁<:b₂∈*) =\n let a₂∈* , a₁∈* = <:-valid a₂<:a₁∈*\n b₁∈* , b₂∈* = <:-valid b₁<:b₂∈*\n in kd-⋯ a₁∈* b₁∈* , kd-⋯ a₂∈* b₂∈*\n <∷-valid (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) =\n Πj₁k₁-kd ,\n kd-Π (proj₁ (<∷-valid j₂<∷j₁)) (proj₂ (<∷-valid k₁<∷k₂))\n\n -- Validity of subtyping: subtypes that are related in some kind `k'\n -- inhabit `k'.\n <:-valid : ∀ {n} {Γ : Ctx n} {a b k} →\n Γ ⊢ a <: b ∈ k → Γ ⊢Tp a ∈ k × Γ ⊢Tp b ∈ k\n <:-valid (<:-refl a∈k) = a∈k , a∈k\n <:-valid (<:-trans a<:b∈k b<:c∈k) =\n proj₁ (<:-valid a<:b∈k) , proj₂ (<:-valid b<:c∈k)\n <:-valid (<:-β₁ a∈k b∈j a[b]∈k[b] k-kd k[b]-kd) =\n ∈-Π-e (∈-Π-i j-kd a∈k k-kd) b∈j k-kd k[b]-kd , a[b]∈k[b]\n where j-kd = wf-kd-inv (wf-∷₁ (Tp∈-ctx a∈k))\n <:-valid (<:-β₂ a∈k b∈j a[b]∈k[b] k-kd k[b]-kd) =\n a[b]∈k[b] , ∈-Π-e (∈-Π-i j-kd a∈k k-kd) b∈j k-kd k[b]-kd\n where j-kd = wf-kd-inv (wf-∷₁ (Tp∈-ctx a∈k))\n <:-valid (<:-η₁ a∈Πjk) with Tp∈-valid a∈Πjk\n ... | (kd-Π j-kd k-kd) = Tp∈-η a∈Πjk j-kd k-kd , a∈Πjk\n <:-valid (<:-η₂ a∈Πjk) with Tp∈-valid a∈Πjk\n ... | (kd-Π j-kd k-kd) = a∈Πjk , Tp∈-η a∈Πjk j-kd k-kd\n <:-valid (<:-⊥ b∈c⋯d) = ∈-⊥-f (Tp∈-ctx b∈c⋯d) , Tp∈-⋯-* b∈c⋯d\n <:-valid (<:-⊤ b∈c⋯d) = Tp∈-⋯-* b∈c⋯d , ∈-⊤-f (Tp∈-ctx b∈c⋯d)\n <:-valid (<:-∀ k₂<∷k₁ a₁<:a₂∈* ∀k₁a₁∈*) =\n ∀k₁a₁∈* ,\n ∈-∀-f (proj₁ (<∷-valid k₂<∷k₁)) (proj₂ (<:-valid a₁<:a₂∈*))\n <:-valid (<:-→ a₂<:a₁∈* b₁<:b₂∈*) =\n let a₂∈* , a₁∈* = <:-valid a₂<:a₁∈*\n b₁∈* , b₂∈* = <:-valid b₁<:b₂∈*\n in ∈-→-f a₁∈* b₁∈* , ∈-→-f a₂∈* b₂∈*\n <:-valid (<:-λ a₁<:a₂∈k Λj₁a₁∈Πjk Λj₂a₂∈Πjk) = Λj₁a₁∈Πjk , Λj₂a₂∈Πjk\n <:-valid (<:-· a₁<:a₂∈Πjk b₁≃b₂∈j b₁∈j k-kd k[b₁]-kd) =\n let a₁∈Πjk , a₂∈Πjk = <:-valid a₁<:a₂∈Πjk\n b₁∈j , b₂∈j = ≃-valid b₁≃b₂∈j\n in ∈-Π-e a₁∈Πjk b₁∈j k-kd k[b₁]-kd ,\n ∈-⇑ (∈-Π-e a₂∈Πjk b₂∈j k-kd (kd-[] k-kd (∈-tp b₂∈j)))\n (≅⇒<∷ (kd-[≃′] k-kd b₂∈j b₁∈j (≃-sym b₁≃b₂∈j)))\n <:-valid (<:-⟨| a∈b⋯c) with Tp∈-valid a∈b⋯c\n ... | (kd-⋯ b∈* c∈*) = b∈* , Tp∈-⋯-* a∈b⋯c\n <:-valid (<:-|⟩ a∈b⋯c) with Tp∈-valid a∈b⋯c\n ... | (kd-⋯ b∈* c∈*) = Tp∈-⋯-* a∈b⋯c , c∈*\n <:-valid (<:-⋯-i a<:b∈c⋯d) =\n let a∈c⋯d , b∈c⋯d = <:-valid a<:b∈c⋯d\n a<:b∈* = <:-⋯-* a<:b∈c⋯d\n in ∈-⇑ (∈-s-i a∈c⋯d) (<∷-⋯ (<:-refl (Tp∈-⋯-* a∈c⋯d)) a<:b∈*) ,\n ∈-⇑ (∈-s-i b∈c⋯d) (<∷-⋯ a<:b∈* (<:-refl (Tp∈-⋯-* b∈c⋯d)))\n <:-valid (<:-⇑ a<:b∈j j<∷k) =\n let a∈j , b∈j = <:-valid a<:b∈j\n in ∈-⇑ a∈j j<∷k , ∈-⇑ b∈j j<∷k\n\n -- Validity of type equality: types that are equal in some kind `k'\n -- inhabit `k'.\n ≃-valid : ∀ {n} {Γ : Ctx n} {a b k} →\n Γ ⊢ a ≃ b ∈ k → Γ ⊢Tp a ∈ k × Γ ⊢Tp b ∈ k\n ≃-valid (<:-antisym a<:b∈k b<:a∈k) = <:-valid a<:b∈k\n\n -- Subtypes inhabiting interval kinds are proper types.\n <:-⋯-* : ∀ {n} {Γ : Ctx n} {a b c d} → Γ ⊢ a <: b ∈ c ⋯ d → Γ ⊢ a <: b ∈ *\n <:-⋯-* a<:b∈c⋯d =\n let a∈c⋯d , b∈c⋯d = <:-valid a<:b∈c⋯d\n in <:-⇑ (<:-⋯-i a<:b∈c⋯d) (<∷-⋯ (<:-⊥ a∈c⋯d) (<:-⊤ b∈c⋯d))\n\n-- Validity of kind equality: equal kinds are well-formed.\n≅-valid : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ j kd × Γ ⊢ k kd\n≅-valid (<∷-antisym j<∷k k<∷j) = <∷-valid j<∷k\n\n-- A corollary.\n<:-valid-kd : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a <: b ∈ k → Γ ⊢ k kd\n<:-valid-kd a<:b∈k = Tp∈-valid (proj₁ (<:-valid a<:b∈k))\n\n\n----------------------------------------------------------------------\n-- Strengthened versions of kind formation and kinding functionality.\n\n-- Functionality of kind formation (strong version).\nkd-[≃] : ∀ {n} {Γ : Ctx n} {a b j k} →\n kd j ∷ Γ ⊢ k kd → Γ ⊢ a ≃ b ∈ j → Γ ⊢ k Kind[ a ] ≅ k Kind[ b ]\nkd-[≃] k-kd a≃b∈j = let a∈j , b∈j = ≃-valid a≃b∈j in kd-[≃′] k-kd a∈j b∈j a≃b∈j\n\n-- Functionality of kinding (strong version).\nTp∈-[≃] : ∀ {n} {Γ : Ctx n} {a b c j k} →\n kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢ b ≃ c ∈ j →\n Γ ⊢ a [ b ] ≃ a [ c ] ∈ k Kind[ b ]\nTp∈-[≃] a∈k b≃c∈j = let b∈j , c∈j = ≃-valid b≃c∈j in Tp∈-[≃′] a∈k b∈j c∈j b≃c∈j\n", "meta": {"hexsha": "2df62b3ba16be65e60892a6b6b64310bf8954912", "size": 6291, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/FOmegaInt/Kinding/Declarative/Validity.agda", "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z", "max_issues_repo_path": "src/FOmegaInt/Kinding/Declarative/Validity.agda", "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z", "max_forks_repo_path": "src/FOmegaInt/Kinding/Declarative/Validity.agda", "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z", "avg_line_length": 41.94, "max_line_length": 79, "alphanum_fraction": 0.4573199809, "num_tokens": 3477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7122321842389469, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.35889819248741023}} {"text": "-- Andreas, 2012-09-15\n{-# OPTIONS --show-implicit #-}\n-- {-# OPTIONS -v tc.meta:50 #-}\n-- {-# OPTIONS -v tc.conv:50 #-}\n-- {-# OPTIONS -v tc.polarity:10 #-}\n-- {-# OPTIONS -v tc.constr.findInScope:50 #-}\nmodule BrokenInferenceDueToNonvariantPolarity where\n\nimport Common.Level\n\ndata ⊥ : Set where\nrecord ⊤ : Set where\n\ndata Nat : Set where\n zero : Nat\n suc : Nat → Nat\n\nFalse : Nat → Set\nFalse zero = ⊥\nFalse (suc n) = False n\n\nmodule Invariant where\n record Bla (n : Nat)(p : False n) : Set where\n -- phantom arguments to Bla get polarity 'Invariant'\n\nmodule Nonvariant where\n Bla : (n : Nat) → False n → Set\n Bla n p = ⊤\n -- polarity checker infers arguments to be 'Nonvariant'\n\n-- open Invariant -- succeeds\nopen Nonvariant -- fails\n\nmodule Works where\n\n drop-suc : {n : Nat}{{p : False n}} → Bla (suc n) p → Bla n p\n drop-suc _ = _\n\n works : (n : Nat) → {{p : False n}} → Bla n p → ⊥\n works zero {{()}} b\n works (suc n) b = works n (drop-suc {n} b)\n\nmodule Fails where\n\n drop-suc : {n : Nat}{{p : False n}} → Bla (suc n) p → Bla n p\n drop-suc _ = _\n\n bla : (n : Nat) → {p : False n} → Bla n p → ⊥\n bla zero {()} b\n bla (suc n) b = bla n (drop-suc b)\n -- Since Bla is analysed as constant function, the constraint\n -- Bla n p = Bla X Y does not provide unique solutions for X and Y.\n -- And since the positivity checker runs after constraint solving,\n -- Agda does not recognize that bla is Nonvariant in argument p\n -- and that it hence could search for any solution.\n\n", "meta": {"hexsha": "5fc06db32dd1bdcbc116a401a6f8802925cefa5a", "size": 1502, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/BrokenInferenceDueToNonvariantPolarity.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/BrokenInferenceDueToNonvariantPolarity.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/BrokenInferenceDueToNonvariantPolarity.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.350877193, "max_line_length": 69, "alphanum_fraction": 0.6271637816, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6959583376458152, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.35884997940366525}} {"text": "\nmodule _ where\n\nopen import Agda.Primitive\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Nat hiding (_==_)\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Unit\nopen import Agda.Builtin.Bool\n\ninfix -1 _,_\nrecord _×_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where\n constructor _,_\n field fst : A\n snd : B\nopen _×_\n\ndata Constraint : Set₁ where\n mkConstraint : {A : Set} (x y : A) → x ≡ y → Constraint\n\ninfix 0 _==_\npattern _==_ x y = mkConstraint x y refl\n\nT : Bool → Set\nT false = Nat\nT true = Nat → Nat\n\nbla : (Nat → Nat) → Nat → Nat\nbla f zero = zero\nbla f = f -- underapplied clause!\n\npred : Nat → Nat\npred zero = zero\npred (suc n) = n\n\n-- 0 and 1 are both solutions, so should not be solved.\nbad! : Constraint\nbad! = bla pred _ == zero\n\n-- Should not fail, since 2 is a solution!\nmore-bad! : Constraint\nmore-bad! = bla pred _ == 1\n\n-- Same thing for projections\n\nblabla : Nat → Nat × Nat\nblabla zero = 1 , 1\nblabla (suc n) = 0 , n\n\n-- Don't fail: 0 is a valid solution\noops : Constraint\noops = fst (blabla _) == 1\n\nbla₂ : Bool → Nat × Nat\nbla₂ false = 0 , 1\nbla₂ true .fst = 0\nbla₂ true .snd = 1\n\n-- Don't solve: false and true are both solutions\nwrong : Constraint\nwrong = bla₂ _ .fst == 0\n", "meta": {"hexsha": "06d30e15542d2eb3b625e0dcfb0f494f80aa1277", "size": 1233, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue2944.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/Issue2944.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/Issue2944.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": 19.8870967742, "max_line_length": 60, "alphanum_fraction": 0.6512570965, "num_tokens": 425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.665410572017153, "lm_q2_score": 0.538983220687684, "lm_q1q2_score": 0.3586451331854392}} {"text": "{-\nThis second-order term syntax was created from the following second-order syntax description:\n\nsyntax Monad | M\n\ntype\n T : 1-ary\n\nterm\n ret : α -> T α\n bind : T α α.(T β) -> T β | _>>=_ r10\n\ntheory\n (LU) a : α b : α.(T β) |> bind (ret(a), x. b[x]) = b[a]\n (RU) t : T α |> bind (t, x. ret(x)) = t\n (AS) t : T α b : α.(T β) c : β.(T γ) |> bind (bind (t, x.b[x]), y.c[y]) = bind (t, x. bind (b[x], y.c[y]))\n-}\n\n\nmodule Monad.Syntax where\n\nopen import SOAS.Common\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.Families.Core\nopen import SOAS.Construction.Structure\nopen import SOAS.ContextMaps.Inductive\n\nopen import SOAS.Metatheory.Syntax\n\nopen import Monad.Signature\n\nprivate\n variable\n Γ Δ Π : Ctx\n α β : MT\n 𝔛 : Familyₛ\n\n-- Inductive term declaration\nmodule M:Terms (𝔛 : Familyₛ) where\n\n data M : Familyₛ where\n var : ℐ ⇾̣ M\n mvar : 𝔛 α Π → Sub M Π Γ → M α Γ\n\n ret : M α Γ → M (T α) Γ\n _>>=_ : M (T α) Γ → M (T β) (α ∙ Γ) → M (T β) Γ\n\n infixr 10 _>>=_\n\n open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛\n\n Mᵃ : MetaAlg M\n Mᵃ = record\n { 𝑎𝑙𝑔 = λ where\n (retₒ ⋮ a) → ret a\n (bindₒ ⋮ a , b) → _>>=_ a b\n ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }\n\n module Mᵃ = MetaAlg Mᵃ\n\n module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where\n\n open MetaAlg 𝒜ᵃ\n\n 𝕤𝕖𝕞 : M ⇾̣ 𝒜\n 𝕊 : Sub M Π Γ → Π ~[ 𝒜 ]↝ Γ\n 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t\n 𝕊 (t ◂ σ) (old v) = 𝕊 σ v\n 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)\n 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v\n\n 𝕤𝕖𝕞 (ret a) = 𝑎𝑙𝑔 (retₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (_>>=_ a b) = 𝑎𝑙𝑔 (bindₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n\n 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Mᵃ 𝒜ᵃ 𝕤𝕖𝕞\n 𝕤𝕖𝕞ᵃ⇒ = record\n { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }\n ; ⟨𝑣𝑎𝑟⟩ = refl\n ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }\n where\n open ≡-Reasoning\n ⟨𝑎𝑙𝑔⟩ : (t : ⅀ M α Γ) → 𝕤𝕖𝕞 (Mᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)\n ⟨𝑎𝑙𝑔⟩ (retₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (bindₒ ⋮ _) = refl\n\n 𝕊-tab : (mε : Π ~[ M ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)\n 𝕊-tab mε new = refl\n 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v\n\n module _ (g : M ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Mᵃ 𝒜ᵃ g) where\n\n open MetaAlg⇒ gᵃ⇒\n\n 𝕤𝕖𝕞! : (t : M α Γ) → 𝕤𝕖𝕞 t ≡ g t\n 𝕊-ix : (mε : Sub M Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)\n 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x\n 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v\n 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))\n = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))\n 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩\n\n 𝕤𝕖𝕞! (ret a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (_>>=_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n\n\n-- Syntax instance for the signature\nM:Syn : Syntax\nM:Syn = record\n { ⅀F = ⅀F\n ; ⅀:CS = ⅀:CompatStr\n ; mvarᵢ = M:Terms.mvar\n ; 𝕋:Init = λ 𝔛 → let open M:Terms 𝔛 in record\n { ⊥ = M ⋉ Mᵃ\n ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }\n ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }\n\n-- Instantiation of the syntax and metatheory\nopen Syntax M:Syn public\nopen M:Terms public\nopen import SOAS.Families.Build public\nopen import SOAS.Syntax.Shorthands Mᵃ public\nopen import SOAS.Metatheory M:Syn public\n", "meta": {"hexsha": "2058e722fdc8e34f529787309d8d6b1e90c4fbfb", "size": 3163, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "out/Monad/Syntax.agda", "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_issues_repo_path": "out/Monad/Syntax.agda", "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_forks_repo_path": "out/Monad/Syntax.agda", "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "avg_line_length": 25.5080645161, "max_line_length": 110, "alphanum_fraction": 0.5270312994, "num_tokens": 1939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.665410572017153, "lm_q2_score": 0.538983220687684, "lm_q1q2_score": 0.3586451331854392}} {"text": "open import Data.Nat using (ℕ; _+_; _≤?_)\nopen import Data.Bool using (Bool; true; false; not; _∧_)\nopen import Data.String using (String; _≟_)\nopen import Relation.Nullary using (¬_; yes; no)\nopen import Relation.Nullary.Negation using (contradiction)\nopen import Relation.Binary.PropositionalEquality using (_≡_; refl; sym)\nopen import Function.Equivalence using (_⇔_; equivalence)\n\nopen import IMP\n\ndata ⦅_,_⦆⇒_ : com → state → state → Set where\n Skip : ∀{s} → ⦅ SKIP , s ⦆⇒ s\n Loc : ∀{x a s}\n → ⦅ x ::= a , s ⦆⇒ (s [ x ::= aval a s ])\n Comp : ∀{c₁ c₂ s₁ s₂ s₃}\n → ⦅ c₁ , s₁ ⦆⇒ s₂\n → ⦅ c₂ , s₂ ⦆⇒ s₃\n → ⦅ c₁ :: c₂ , s₁ ⦆⇒ s₃\n IfTrue : ∀{c₁ c₂ b s t}\n → bval b s ≡ true\n → ⦅ c₁ , s ⦆⇒ t\n → ⦅ IF b THEN c₁ ELSE c₂ , s ⦆⇒ t\n IfFalse : ∀{c₁ c₂ b s t}\n → bval b s ≡ false\n → ⦅ c₂ , s ⦆⇒ t\n → ⦅ IF b THEN c₁ ELSE c₂ , s ⦆⇒ t\n WhileFalse : ∀{c b s}\n → bval b s ≡ false\n → ⦅ WHILE b DO c , s ⦆⇒ s\n WhileTrue : ∀{c b s₁ s₂ s₃}\n → bval b s₁ ≡ true\n → ⦅ c , s₁ ⦆⇒ s₂\n → ⦅ WHILE b DO c , s₂ ⦆⇒ s₃\n → ⦅ WHILE b DO c , s₁ ⦆⇒ s₃\n\ntrue≢false : ¬ (true ≡ false)\ntrue≢false = λ ()\n \ndeterministic : ∀{c s t t′}\n → ⦅ c , s ⦆⇒ t\n → ⦅ c , s ⦆⇒ t′\n → t ≡ t′\ndeterministic Skip Skip = refl\ndeterministic Loc Loc = refl\ndeterministic (Comp r₁ r₂) (Comp r₁′ r₂′) rewrite deterministic r₁ r₁′ = deterministic r₂ r₂′\ndeterministic (IfTrue v r) (IfTrue v′ r′) = deterministic r r′\ndeterministic (IfTrue v r) (IfFalse v′ r′) rewrite v = contradiction v′ true≢false\ndeterministic (IfFalse v r) (IfTrue v′ r′) rewrite v′ = contradiction v true≢false\ndeterministic (IfFalse v r) (IfFalse v′ r′) = deterministic r r′\ndeterministic (WhileFalse v) (WhileFalse x₁) = refl\ndeterministic (WhileFalse v) (WhileTrue x₁ r₁ r₂) rewrite x₁ = contradiction v true≢false\ndeterministic (WhileTrue v r₁ r₂) (WhileFalse v′) rewrite v = contradiction v′ true≢false\ndeterministic (WhileTrue v r₁ r₂) (WhileTrue v′ r₁′ r₂′) rewrite deterministic r₁ r₁′ = deterministic r₂ r₂′\n\nlemma2-3-5 : ∀{s t}\n → ¬ ( ⦅ WHILE (Bc true) DO SKIP , s ⦆⇒ t )\nlemma2-3-5 (WhileTrue x Skip (WhileTrue v r₁ r₂)) = lemma2-3-5 r₂\n\ninfixl 19 _∼_\n_∼_ : com → com → Set\nc ∼ c′ = ∀{s t} → ⦅ c , s ⦆⇒ t ⇔ ⦅ c′ , s ⦆⇒ t\n\nlemma2-4-3 : ∀{b c} → (WHILE b DO c) ∼ (IF b THEN (c :: (WHILE b DO c)) ELSE SKIP)\nlemma2-4-3 = equivalence (λ { (WhileFalse x) → IfFalse x Skip ; (WhileTrue x r r₁) → IfTrue x (Comp r r₁) })\n (λ { (IfTrue x (Comp r r₁)) → WhileTrue x r r₁ ; (IfFalse x Skip) → WhileFalse x })\n\ndata ⦅_,_⦆→⦅_,_⦆ : com → state → com → state → Set where\n Loc : ∀{x a s}\n → ⦅ x ::= a , s ⦆→⦅ SKIP , s [ x ::= aval a s ] ⦆\n Comp₁ : ∀{c s}\n → ⦅ SKIP :: c , s ⦆→⦅ c , s ⦆\n Comp₂ : ∀{c₁ c₁′ c₂ s s′}\n → ⦅ c₁ , s ⦆→⦅ c₁′ , s′ ⦆\n → ⦅ c₁ :: c₂ , s ⦆→⦅ c₁′ :: c₂ , s′ ⦆\n IfTrue : ∀{b s c₁ c₂}\n → bval b s ≡ true\n → ⦅ IF b THEN c₁ ELSE c₂ , s ⦆→⦅ c₁ , s ⦆\n IfFalse : ∀{b s c₁ c₂}\n → bval b s ≡ false\n → ⦅ IF b THEN c₁ ELSE c₂ , s ⦆→⦅ c₂ , s ⦆ \n While : ∀{b s c}\n → ⦅ WHILE b DO c , s ⦆→⦅ IF b THEN (c :: (WHILE b DO c)) ELSE SKIP , s ⦆\n\ninfix 3 ⦅_,_⦆∎\ninfixr 2 ⦅_,_⦆→⟨_⟩_ ⦅_,_⦆→*⟨_⟩_\n\ndata ⦅_,_⦆→*⦅_,_⦆ : com → state → com → state → Set where\n ⦅_,_⦆∎ : ∀ c s → ⦅ c , s ⦆→*⦅ c , s ⦆\n ⦅_,_⦆→⟨_⟩_ : ∀ c s {c′ c″ s′ s″}\n → ⦅ c , s ⦆→⦅ c′ , s′ ⦆\n → ⦅ c′ , s′ ⦆→*⦅ c″ , s″ ⦆\n → ⦅ c , s ⦆→*⦅ c″ , s″ ⦆\n\n⦅_,_⦆→*⟨_⟩_ : ∀ c s {c′ c″ s′ s″}\n → ⦅ c , s ⦆→*⦅ c′ , s′ ⦆\n → ⦅ c′ , s′ ⦆→*⦅ c″ , s″ ⦆\n → ⦅ c , s ⦆→*⦅ c″ , s″ ⦆\n⦅ c , s ⦆→*⟨ ⦅ _ , _ ⦆∎ ⟩ b = b\n⦅ c , s ⦆→*⟨ ⦅ _ , _ ⦆→⟨ x ⟩ r ⟩ b = ⦅ _ , _ ⦆→⟨ x ⟩ ⦅ _ , _ ⦆→*⟨ r ⟩ b\n\nlemma2-5-6 : ∀{c₁ c₁′ c₂ s s′}\n → ⦅ c₁ , s ⦆→*⦅ c₁′ , s′ ⦆\n → ⦅ c₁ :: c₂ , s ⦆→*⦅ c₁′ :: c₂ , s′ ⦆\nlemma2-5-6 ⦅ _ , _ ⦆∎ = ⦅ _ , _ ⦆∎\nlemma2-5-6 (⦅ _ , _ ⦆→⟨ x ⟩ r) = ⦅ _ , _ ⦆→⟨ Comp₂ x ⟩ lemma2-5-6 r\n\nbig-small : ∀{c s t}\n → ⦅ c , s ⦆⇒ t\n → ⦅ c , s ⦆→*⦅ SKIP , t ⦆\nbig-small (Skip {s}) =\n ⦅ SKIP , s ⦆∎\nbig-small (Loc {x}{s}{a}) =\n ⦅ x ::= s , a ⦆→⟨ Loc ⟩\n ⦅ SKIP , a [ x ::= aval s a ] ⦆∎\nbig-small (Comp {c₁}{c₂}{s}{s′}{t} r₁ r₂) =\n ⦅ c₁ :: c₂ , s ⦆→*⟨ lemma2-5-6 (big-small r₁) ⟩\n ⦅ SKIP :: c₂ , s′ ⦆→⟨ Comp₁ ⟩\n ⦅ c₂ , s′ ⦆→*⟨ big-small r₂ ⟩\n ⦅ SKIP , t ⦆∎\nbig-small (IfTrue {c₁}{c₂}{b}{s}{t} v r₁) =\n ⦅ IF b THEN c₁ ELSE c₂ , s ⦆→⟨ IfTrue v ⟩\n ⦅ c₁ , s ⦆→*⟨ big-small r₁ ⟩\n ⦅ SKIP , t ⦆∎\nbig-small (IfFalse {c₁}{c₂}{b}{s}{t} v r₂) =\n ⦅ IF b THEN c₁ ELSE c₂ , s ⦆→⟨ IfFalse v ⟩\n ⦅ c₂ , s ⦆→*⟨ big-small r₂ ⟩\n ⦅ SKIP , t ⦆∎\nbig-small (WhileFalse {c}{b}{s} v) =\n ⦅ WHILE b DO c , s ⦆→⟨ While ⟩\n ⦅ IF b THEN c :: (WHILE b DO c) ELSE SKIP , s ⦆→⟨ IfFalse v ⟩\n ⦅ SKIP , s ⦆∎\nbig-small (WhileTrue {c}{b}{s}{s′}{t} v r₁ r₂) = \n ⦅ WHILE b DO c , s ⦆→⟨ While ⟩\n ⦅ IF b THEN c :: (WHILE b DO c) ELSE SKIP , s ⦆→⟨ IfTrue v ⟩\n ⦅ c :: (WHILE b DO c) , s ⦆→*⟨ lemma2-5-6 (big-small r₁) ⟩\n ⦅ SKIP :: (WHILE b DO c) , s′ ⦆→⟨ Comp₁ ⟩\n ⦅ WHILE b DO c , s′ ⦆→*⟨ big-small r₂ ⟩\n ⦅ SKIP , t ⦆∎\n\nlemma2-5-8 : ∀{c s c′ s′ t}\n → ⦅ c , s ⦆→⦅ c′ , s′ ⦆ → ⦅ c′ , s′ ⦆⇒ t\n → ⦅ c , s ⦆⇒ t\nlemma2-5-8 Loc Skip = Loc\nlemma2-5-8 Comp₁ r₁ = Comp Skip r₁\nlemma2-5-8 (Comp₂ x) (Comp r₁ r₂) = Comp (lemma2-5-8 x r₁) r₂\nlemma2-5-8 (IfTrue x) r₁ = IfTrue x r₁\nlemma2-5-8 (IfFalse x) r₁ = IfFalse x r₁\nlemma2-5-8 While (IfTrue x (Comp r₁ r₂)) = WhileTrue x r₁ r₂\nlemma2-5-8 While (IfFalse x Skip) = WhileFalse x\n\nsmall-big : ∀{c s t}\n → ⦅ c , s ⦆→*⦅ SKIP , t ⦆\n → ⦅ c , s ⦆⇒ t \nsmall-big ⦅ SKIP , s ⦆∎ = Skip\nsmall-big (⦅ c , s ⦆→⟨ x ⟩ r) = lemma2-5-8 x (small-big r)\n", "meta": {"hexsha": "eeaef8d57642d56e7330256f2423dab35a7e148f", "size": 6118, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "OperationalSemantics.agda", "max_stars_repo_name": "iwilare/imp-semantics", "max_stars_repo_head_hexsha": "cb98e3b3b93362654b79152bfdf2c21eb4951fcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-09-08T11:54:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-24T22:29:44.000Z", "max_issues_repo_path": "OperationalSemantics.agda", "max_issues_repo_name": "iwilare/imp-semantics", "max_issues_repo_head_hexsha": "cb98e3b3b93362654b79152bfdf2c21eb4951fcc", "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": "OperationalSemantics.agda", "max_forks_repo_name": "iwilare/imp-semantics", "max_forks_repo_head_hexsha": "cb98e3b3b93362654b79152bfdf2c21eb4951fcc", "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.2179487179, "max_line_length": 108, "alphanum_fraction": 0.4462242563, "num_tokens": 3059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.35864512603294924}} {"text": "open import Nat\nopen import Prelude\nopen import dynamics-core\nopen import contexts\nopen import typed-elaboration\nopen import lemmas-gcomplete\nopen import lemmas-complete\n\nmodule complete-elaboration where\n mutual\n complete-elaboration-synth : ∀{e τ Γ Δ d} →\n Γ gcomplete →\n e ecomplete →\n Γ ⊢ e ⇒ τ ~> d ⊣ Δ →\n (d dcomplete × τ tcomplete × Δ == ∅)\n complete-elaboration-synth gc ec ESNum = DCNum , TCNum , refl\n complete-elaboration-synth gc (ECPlus ec₁ ec₂) (ESPlus {Δ1 = Δ1} {Δ2 = Δ2} apt dis x₁ x₂)\n with complete-elaboration-ana gc ec₁ TCNum x₁ | complete-elaboration-ana gc ec₂ TCNum x₂\n ... | d1comp , t1comp , refl | d2comp , t2comp , refl =\n DCPlus (DCCast d1comp t1comp TCNum) (DCCast d2comp t2comp TCNum) , TCNum , refl\n complete-elaboration-synth gc ec (ESVar x₁) = DCVar , gc _ _ x₁ , refl\n complete-elaboration-synth gc (ECLam2 ec x₁) (ESLam x₂ exp)\n with complete-elaboration-synth (gcomp-extend gc x₁ x₂) ec exp\n ... | ih1 , ih2 , ih3 = DCLam ih1 x₁ , TCArr x₁ ih2 , ih3\n complete-elaboration-synth gc (ECAp ec ec₁) (ESAp _ _ x MAHole x₂ x₃)\n with comp-synth gc ec x\n ... | ()\n complete-elaboration-synth gc (ECAp ec ec₁) (ESAp {Δ1 = Δ1} {Δ2 = Δ2} _ _ x MAArr x₂ x₃)\n with comp-synth gc ec x\n ... | TCArr t1 t2\n with complete-elaboration-ana gc ec (TCArr t1 t2) x₂ | complete-elaboration-ana gc ec₁ t1 x₃\n ... | ih1 , _ , ih4 | ih2 , _ , ih3 = DCAp (DCCast ih1 (comp-ana gc x₂ ih1) (TCArr t1 t2)) (DCCast ih2 (comp-ana gc x₃ ih2) t1) ,\n t2 ,\n tr (λ qq → (qq ∪ Δ2) == ∅) (! ih4) (tr (λ qq → (∅ ∪ qq) == ∅) (! ih3) refl)\n complete-elaboration-synth gc () ESEHole\n complete-elaboration-synth gc () (ESNEHole _ exp)\n complete-elaboration-synth gc (ECAsc x ec) (ESAsc x₁)\n with complete-elaboration-ana gc ec x x₁\n ... | ih1 , _ , ih2 = DCCast ih1 (comp-ana gc x₁ ih1) x , x , ih2\n complete-elaboration-synth gc (ECPair ec ec₁) (ESPair {Δ1 = Δ1} {Δ2 = Δ2} x x₁ x₂ x₃)\n with complete-elaboration-synth gc ec x₂ | complete-elaboration-synth gc ec₁ x₃\n ... | ih1 , ih2 , ih3 | ih1' , ih2' , ih3' = DCPair ih1 ih1' , TCProd ih2 ih2' , tr (λ qq → (qq ∪ Δ2) == ∅) (! ih3) ih3'\n complete-elaboration-synth gc (ECFst ec) (ESFst x MPHole x₂)\n with comp-synth gc ec x\n ... | ()\n complete-elaboration-synth gc (ECFst ec) (ESFst x MPProd x₂)\n with comp-synth gc ec x\n ... | TCProd τc1 τc2 with complete-elaboration-ana gc ec (TCProd τc1 τc2) x₂\n ... | ih1 , ih2 , ih3 = DCFst (DCCast ih1 ih2 (TCProd τc1 τc2)) , τc1 , ih3\n complete-elaboration-synth gc (ECSnd ec) (ESSnd x MPHole x₂)\n with comp-synth gc ec x\n ... | ()\n complete-elaboration-synth gc (ECSnd ec) (ESSnd x MPProd x₂)\n with comp-synth gc ec x\n ... | TCProd τc1 τc2 with complete-elaboration-ana gc ec (TCProd τc1 τc2) x₂\n ... | ih1 , ih2 , ih3 = DCSnd (DCCast ih1 ih2 (TCProd τc1 τc2)) , τc2 , ih3\n \n complete-elaboration-ana : ∀{e τ τ' Γ Δ d} →\n Γ gcomplete →\n e ecomplete →\n τ tcomplete →\n Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →\n (d dcomplete × τ' tcomplete × Δ == ∅)\n complete-elaboration-ana gc (ECLam1 ec) () (EALam x₁ MAHole exp)\n complete-elaboration-ana gc (ECLam1 ec) (TCArr t1 t2) (EALam x₁ MAArr exp)\n with complete-elaboration-ana (gcomp-extend gc t1 x₁) ec t2 exp\n ... | ih , ih3 , ih2 = DCLam ih t1 , TCArr t1 ih3 , ih2\n complete-elaboration-ana gc ec tc (EASubsume x x₁ x₂ x₃)\n with complete-elaboration-synth gc ec x₂\n ... | ih1 , ih2 , ih3 = ih1 , ih2 , ih3\n complete-elaboration-ana gc (ECInl ec) (TCSum tc tc₁) (EAInl MSSum x₁)\n with complete-elaboration-ana gc ec tc x₁\n ... | ih1 , ih2 , ih3 = DCInl tc₁ ih1 , TCSum ih2 tc₁ , ih3\n complete-elaboration-ana gc (ECInr ec) (TCSum tc tc₁) (EAInr MSSum x₁)\n with complete-elaboration-ana gc ec tc₁ x₁\n ... | ih1 , ih2 , ih3 = DCInr tc ih1 , TCSum tc ih2 , ih3\n complete-elaboration-ana gc (ECCase ec ec₁ ec₂) tc (EACase x x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈ MSHole x₁₀ x₁₁)\n with complete-elaboration-synth gc ec x₈ \n ... | ih1 , () , ih3\n complete-elaboration-ana gc (ECCase ec ec₁ ec₂) tc (EACase {Δ = Δ} {Δ1 = Δ1} {Δ2 = Δ2} x x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈ MSSum x₁₀ x₁₁) \n with complete-elaboration-synth gc ec x₈ \n ... | ih1 , TCSum ih2 ih4 , ih3 with complete-elaboration-ana (gcomp-extend gc ih2 x₆) ec₁ tc x₁₀\n ... | ih1' , ih2' , ih3' with complete-elaboration-ana (gcomp-extend gc ih4 x₇) ec₂ tc x₁₁\n ... | ih1'' , ih2'' , ih3'' = DCCase (DCCast ih1 (TCSum ih2 ih4) (TCSum ih2 ih4)) (DCCast ih1' ih2' tc) (DCCast ih1'' ih2'' tc) , tc , tr (λ qq → qq ∪ (Δ1 ∪ Δ2) == ∅) (! ih3) (tr (λ qq → ∅ ∪ (qq ∪ Δ2) == ∅) (! ih3') (tr (λ qq → ∅ ∪ (∅ ∪ qq) == ∅) (! ih3'') refl)) \n \n -- this is just a convenience since it shows up a few times above\n comp-ana : ∀{Γ e τ d τ' Δ} →\n Γ gcomplete →\n Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →\n d dcomplete →\n τ' tcomplete\n comp-ana gc ex dc = complete-ta gc (π2 (typed-elaboration-ana ex)) dc\n", "meta": {"hexsha": "680b87d94e479f914450940f6c5c717bd70d31d6", "size": 5358, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "complete-elaboration.agda", "max_stars_repo_name": "hazelgrove/hazelnut-agda", "max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": "complete-elaboration.agda", "max_issues_repo_name": "hazelgrove/hazelnut-agda", "max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": "complete-elaboration.agda", "max_forks_repo_name": "hazelgrove/hazelnut-agda", "max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": 57.6129032258, "max_line_length": 268, "alphanum_fraction": 0.5772676372, "num_tokens": 2039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7341195269001831, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.3584583751477932}} {"text": "{-# OPTIONS --cubical #-}\nmodule Agda.Primitive.Cubical where\n{-# BUILTIN INTERVAL I #-} -- I : Setω\n\n{-# BUILTIN IZERO i0 #-}\n{-# BUILTIN IONE i1 #-}\n\ninfix 30 primINeg\ninfixr 20 primIMin primIMax\n\nprimitive\n primIMin : I → I → I\n primIMax : I → I → I\n primINeg : I → I\n\n{-# BUILTIN ISONE IsOne #-} -- IsOne : I → Setω\n\n\npostulate\n itIsOne : IsOne i1\n IsOne1 : ∀ i j → IsOne i → IsOne (primIMax i j)\n IsOne2 : ∀ i j → IsOne j → IsOne (primIMax i j)\n\n{-# BUILTIN ITISONE itIsOne #-}\n{-# BUILTIN ISONE1 IsOne1 #-}\n{-# BUILTIN ISONE2 IsOne2 #-}\n{-# BUILTIN PARTIAL Partial #-}\n{-# BUILTIN PARTIALP PartialP #-}\n\npostulate\n isOneEmpty : ∀ {a} {A : Partial i0 (Set a)} → PartialP i0 A\n{-# BUILTIN ISONEEMPTY isOneEmpty #-}\n\nprimitive\n primPFrom1 : ∀ {a} {A : I → Set a} → A i1 → ∀ i j → Partial i (A (primIMax i j))\n primPOr : ∀ {a} (i j : I) {A : Partial (primIMax i j) (Set a)}\n → PartialP i (λ z → A (IsOne1 i j z)) → PartialP j (λ z → A (IsOne2 i j z))\n → PartialP (primIMax i j) A\n primComp : ∀ {a} (A : (i : I) → Set (a i)) (φ : I) → (∀ i → Partial φ (A i)) → (a : A i0) → A i1\n\nsyntax primPOr p q u t = [ p ↦ u , q ↦ t ]\n\nprimitive\n primTransp : ∀ {a} (A : (i : I) → Set (a i)) (φ : I) → (a : A i0) → A i1\n primHComp : ∀ {a} {A : Set a} {φ : I} → (∀ i → Partial φ A) → A → A\n", "meta": {"hexsha": "513798fc6910b494de6e09dc3c28bc68241968a0", "size": 1373, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/data/lib/prim/Agda/Primitive/Cubical.agda", "max_stars_repo_name": "bennn/agda", "max_stars_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed", "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": "src/data/lib/prim/Agda/Primitive/Cubical.agda", "max_issues_repo_name": "bennn/agda", "max_issues_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed", "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": "src/data/lib/prim/Agda/Primitive/Cubical.agda", "max_forks_repo_name": "bennn/agda", "max_forks_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed", "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": 29.847826087, "max_line_length": 98, "alphanum_fraction": 0.5273124545, "num_tokens": 546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7341195152660688, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.3584583694670484}} {"text": "open import FRP.JS.Bool using ( Bool )\nopen import FRP.JS.RSet using ( RSet ; ⟦_⟧ ; ⟨_⟩ ; _⇒_ )\nopen import FRP.JS.Behaviour using ( Beh ; map2 )\nopen import FRP.JS.Event using ( Evt ; ∅ ; _∪_ ; map )\nopen import FRP.JS.Product using ( _∧_ ; _,_ )\nopen import FRP.JS.String using ( String )\n\nmodule FRP.JS.DOM where\n\ninfixr 2 _≟*_\ninfixr 4 _++_ _+++_\n\npostulate\n Mouse Keyboard : RSet\n EventType : RSet → Set\n click : EventType Mouse\n press : EventType Keyboard\n\n{-# COMPILED_JS click \"click\" #-}\n{-# COMPILED_JS press \"press\" #-}\n\npostulate\n DOW : Set\n unattached : DOW\n left right : DOW → DOW\n child : String → DOW → DOW\n events : ∀ {A} → EventType A → DOW → ⟦ Evt A ⟧\n\n{-# COMPILED_JS unattached require(\"agda.frp\").unattached() #-}\n{-# COMPILED_JS left function(w) { return w.left(); } #-}\n{-# COMPILED_JS right function(w) { return w.right(); } #-}\n{-# COMPILED_JS child function(a) { return function(w) { return w.child(a); }; } #-}\n{-# COMPILED_JS events function(A) { return function(t) { return function(w) { return function(s) { return w.events(t); }; }; }; } #-}\n\npostulate\n DOM : DOW → RSet\n text : ∀ {w} → ⟦ Beh ⟨ String ⟩ ⇒ Beh (DOM w) ⟧\n attr : ∀ {w} → String → ⟦ Beh ⟨ String ⟩ ⇒ Beh (DOM w) ⟧\n element : ∀ a {w} → ⟦ Beh (DOM (child a w)) ⇒ Beh (DOM w) ⟧\n [] : ∀ {w} → ⟦ Beh (DOM w) ⟧\n _++_ : ∀ {w} → ⟦ Beh (DOM (left w)) ⇒ Beh (DOM (right w)) ⇒ Beh (DOM w) ⟧\n\n{-# COMPILED_JS attr function(w) { return function(k) { return function(s) { return function(b) { return b.attribute(k); }; }; }; } #-}\n{-# COMPILED_JS text function(w) { return function(s) { return function(b) { return b.text(); }; }; } #-}\n{-# COMPILED_JS element function(a) { return function(w) { return function(s) { return function(b) { return w.element(a,b); }; }; }; } #-}\n{-# COMPILED_JS [] function(w) { return require(\"agda.frp\").empty; } #-}\n{-# COMPILED_JS _++_ function(w) { return function(s) { return function(a) { return function(b) { return a.concat(b); }; }; }; } #-}\n \nlisten : ∀ {A w} → EventType A → ⟦ Beh (DOM w) ⇒ Evt A ⟧\nlisten {A} {w} t b = events t w\n\n{-# COMPILED_JS listen function(A) { return function(w) { return function(t) { return function(s) { return function(b) { return w.events(t); }; }; }; }; } #-}\n\nprivate\n postulate\n _≟_ : ∀ {w} → ⟦ DOM w ⇒ DOM w ⇒ ⟨ Bool ⟩ ⟧\n\n {-# COMPILED_JS _≟_ function(w) { return function(s) { return function(a) { return function(b) { return a.equals(b); }; }; }; } #-}\n\n_≟*_ : ∀ {w} → ⟦ Beh (DOM w) ⇒ Beh (DOM w) ⇒ Beh ⟨ Bool ⟩ ⟧\n_≟*_ = map2 _≟_\n\n[+] : ∀ {A w} → ⟦ Beh (DOM w) ∧ Evt A ⟧\n[+] = ([] , ∅)\n\n_+++_ : ∀ {A w} → ⟦ (Beh (DOM (left w)) ∧ Evt A) ⇒ (Beh (DOM (right w)) ∧ Evt A) ⇒ (Beh (DOM w) ∧ Evt A) ⟧\n(dom₁ , evt₁) +++ (dom₂ , evt₂) = ((dom₁ ++ dom₂) , (evt₁ ∪ evt₂))\n\ntext+ : ∀ {A w} → ⟦ Beh ⟨ String ⟩ ⇒ (Beh (DOM w) ∧ Evt A) ⟧\ntext+ msg = (text msg , ∅)\n\nattr+ : ∀ {A w} → String → ⟦ Beh ⟨ String ⟩ ⇒ (Beh (DOM w) ∧ Evt A) ⟧\nattr+ key val = (attr key val , ∅)\n\nelement+ : ∀ a {A w} → ⟦ (Beh (DOM (child a w)) ∧ Evt A) ⇒ (Beh (DOM w) ∧ Evt A) ⟧\nelement+ a (dom , evt) = (element a dom , evt)\n\nlisten+ : ∀ {A B w} → EventType A → ⟦ A ⇒ B ⟧ → ⟦ (Beh (DOM w) ∧ Evt B) ⇒ (Beh (DOM w) ∧ Evt B) ⟧\nlisten+ t f (dom , evt) = (dom , map f (listen t dom) ∪ evt)\n", "meta": {"hexsha": "5661625be5b4b83dd470abc54d66ecec08d67f47", "size": 3228, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/agda/FRP/JS/DOM.agda", "max_stars_repo_name": "agda/agda-frp-js", "max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_stars_repo_licenses": ["MIT", "BSD-3-Clause"], "max_stars_count": 63, "max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z", "max_issues_repo_path": "src/agda/FRP/JS/DOM.agda", "max_issues_repo_name": "agda/agda-frp-js", "max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_issues_repo_licenses": ["MIT", "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": "src/agda/FRP/JS/DOM.agda", "max_forks_repo_name": "agda/agda-frp-js", "max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72", "max_forks_repo_licenses": ["MIT", "BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z", "avg_line_length": 40.35, "max_line_length": 158, "alphanum_fraction": 0.5619578686, "num_tokens": 1185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.705785040214066, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3584060170514781}} {"text": "\nopen import Agda.Builtin.Unit\nopen import Agda.Builtin.Bool\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.IO\nopen import Agda.Builtin.String\n\npostulate\n putStr : String → IO ⊤\n\n{-# FOREIGN GHC import qualified Data.Text.IO #-}\n{-# COMPILE GHC putStr = Data.Text.IO.putStr #-}\n\ndata Sing : Nat → Set where\n sing : Sing zero\n\ndata Vec : Nat → Set where\n nil : Vec zero\n cons : ∀ n → Vec n → Vec (suc n)\n\nisTailNil : ∀ m n → Sing m → Vec n → Bool\nisTailNil .0 .1 sing (cons zero v) = true -- two `zero`s are buried in the dot patterns, which to resurrect?\nisTailNil _ _ _ _ = false\n\nshouldBeFalse = isTailNil 0 2 sing (cons 1 (cons 0 nil))\n\nisFalse : false ≡ shouldBeFalse\nisFalse = refl\n\nmagic : false ≡ true → String\nmagic ()\n\nf : (b : Bool) → false ≡ b → String\nf false eq = \"Phew!\"\nf true eq = magic eq\n\nmain = putStr (f shouldBeFalse refl)\n", "meta": {"hexsha": "ec6f155922bba48791c05e9efe0da2ee868f5bbd", "size": 891, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue3903.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue3903.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Succeed/Issue3903.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 22.8461538462, "max_line_length": 109, "alphanum_fraction": 0.6857463524, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3584060107662629}} {"text": "module Pi.Opsem where\nopen import Data.Empty\nopen import Data.Unit\nopen import Data.Sum\nopen import Data.Product\nopen import Relation.Binary.PropositionalEquality\nopen import Base\nopen import Pi.Syntax\n\ninfix 1 _↦_\n\n-- Base combinators\nbase : ∀ {A B} (c : A ↔ B) → Set\nbase unite₊l = ⊤\nbase uniti₊l = ⊤\nbase swap₊ = ⊤\nbase assocl₊ = ⊤\nbase assocr₊ = ⊤\nbase unite⋆l = ⊤\nbase uniti⋆l = ⊤\nbase swap⋆ = ⊤\nbase assocl⋆ = ⊤\nbase assocr⋆ = ⊤\nbase absorbr = ⊤\nbase factorzl = ⊤\nbase dist = ⊤\nbase factor = ⊤\nbase _ = ⊥\n\nbase-is-prop : ∀ {A B} (c : A ↔ B) → is-prop (base c)\nbase-is-prop unite₊l tt tt = refl\nbase-is-prop uniti₊l tt tt = refl\nbase-is-prop swap₊ tt tt = refl\nbase-is-prop assocl₊ tt tt = refl\nbase-is-prop assocr₊ tt tt = refl\nbase-is-prop unite⋆l tt tt = refl\nbase-is-prop uniti⋆l tt tt = refl\nbase-is-prop swap⋆ tt tt = refl\nbase-is-prop assocl⋆ tt tt = refl\nbase-is-prop assocr⋆ tt tt = refl\nbase-is-prop absorbr tt tt = refl\nbase-is-prop factorzl tt tt = refl\nbase-is-prop dist tt tt = refl\nbase-is-prop factor tt tt = refl\n\n-- Evaluator for base combinators\nδ : ∀ {A B} (c : A ↔ B) {_ : base c} → ⟦ A ⟧ → ⟦ B ⟧\nδ unite₊l (inj₂ v) = v\nδ uniti₊l v = inj₂ v\nδ swap₊ (inj₁ x) = inj₂ x\nδ swap₊ (inj₂ y) = inj₁ y\nδ assocl₊ (inj₁ v) = inj₁ (inj₁ v)\nδ assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v)\nδ assocl₊ (inj₂ (inj₂ v)) = inj₂ v\nδ assocr₊ (inj₁ (inj₁ v)) = inj₁ v\nδ assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v)\nδ assocr₊ (inj₂ v) = inj₂ (inj₂ v)\nδ unite⋆l (tt , v) = v\nδ uniti⋆l v = (tt , v)\nδ swap⋆ (x , y) = (y , x)\nδ assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃)\nδ assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃))\nδ absorbr ()\nδ factorzl ()\nδ dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃)\nδ dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃)\nδ factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃)\nδ factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃)\n\n-- Context\ndata Context : {A B : 𝕌} → Set where\n ☐ : ∀ {A B} → Context {A} {B}\n ☐⨾_•_ : ∀ {A B C} → (c₂ : B ↔ C) → Context {A} {C} → Context {A} {B}\n _⨾☐•_ : ∀ {A B C} → (c₁ : A ↔ B) → Context {A} {C} → Context {B} {C}\n ☐⊕_•_ : ∀ {A B C D} → (c₂ : C ↔ D) → Context {A +ᵤ C} {B +ᵤ D} → Context {A} {B}\n _⊕☐•_ : ∀ {A B C D} → (c₁ : A ↔ B) → Context {A +ᵤ C} {B +ᵤ D} → Context {C} {D}\n ☐⊗[_,_]•_ : ∀ {A B C D} → (c₂ : C ↔ D) → ⟦ C ⟧ → Context {A ×ᵤ C} {B ×ᵤ D} → Context {A} {B}\n [_,_]⊗☐•_ : ∀ {A B C D} → (c₁ : A ↔ B) → ⟦ B ⟧ → Context {A ×ᵤ C} {B ×ᵤ D} → Context {C} {D}\n\n-- Machine state\ndata State : Set where\n ⟨_∣_∣_⟩ : ∀ {A B} → (c : A ↔ B) → ⟦ A ⟧ → Context {A} {B} → State\n [_∣_∣_] : ∀ {A B} → (c : A ↔ B) → ⟦ B ⟧ → Context {A} {B} → State\n\n-- Reduction relation\ndata _↦_ : State → State → Set where\n ↦₁ : ∀ {A B} {c : A ↔ B} {b : base c} {v : ⟦ A ⟧} {κ : Context} → ⟨ c ∣ v ∣ κ ⟩ ↦ [ c ∣ δ c {b} v ∣ κ ]\n ↦₂ : ∀ {A} {v : ⟦ A ⟧} {κ : Context} → ⟨ id↔ ∣ v ∣ κ ⟩ ↦ [ id↔ ∣ v ∣ κ ]\n ↦₃ : ∀ {A B C} {c₁ : A ↔ B} {c₂ : B ↔ C} {v : ⟦ A ⟧} {κ : Context}\n → ⟨ c₁ ⨾ c₂ ∣ v ∣ κ ⟩ ↦ ⟨ c₁ ∣ v ∣ ☐⨾ c₂ • κ ⟩\n ↦₄ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ A ⟧} {κ : Context}\n → ⟨ c₁ ⊕ c₂ ∣ inj₁ x ∣ κ ⟩ ↦ ⟨ c₁ ∣ x ∣ ☐⊕ c₂ • κ ⟩\n ↦₅ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {y : ⟦ C ⟧} {κ : Context}\n → ⟨ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ⟩ ↦ ⟨ c₂ ∣ y ∣ c₁ ⊕☐• κ ⟩\n ↦₆ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ A ⟧} {y : ⟦ C ⟧} {κ : Context}\n → ⟨ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ⟩ ↦ ⟨ c₁ ∣ x ∣ ☐⊗[ c₂ , y ]• κ ⟩\n ↦₇ : ∀ {A B C} {c₁ : A ↔ B} {c₂ : B ↔ C} {v : ⟦ B ⟧} {κ : Context}\n → [ c₁ ∣ v ∣ ☐⨾ c₂ • κ ] ↦ ⟨ c₂ ∣ v ∣ (c₁ ⨾☐• κ) ⟩\n ↦₈ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ B ⟧} {y : ⟦ C ⟧} {κ : Context}\n → [ c₁ ∣ x ∣ ☐⊗[ c₂ , y ]• κ ] ↦ ⟨ c₂ ∣ y ∣ [ c₁ , x ]⊗☐• κ ⟩\n ↦₉ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ B ⟧} {y : ⟦ D ⟧} {κ : Context}\n → [ c₂ ∣ y ∣ [ c₁ , x ]⊗☐• κ ] ↦ [ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ]\n ↦₁₀ : ∀ {A B C} {c₁ : A ↔ B} {c₂ : B ↔ C} {v : ⟦ C ⟧} {κ : Context}\n → [ c₂ ∣ v ∣ (c₁ ⨾☐• κ) ] ↦ [ c₁ ⨾ c₂ ∣ v ∣ κ ]\n ↦₁₁ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ B ⟧} {κ : Context}\n → [ c₁ ∣ x ∣ ☐⊕ c₂ • κ ] ↦ [ c₁ ⊕ c₂ ∣ inj₁ x ∣ κ ]\n ↦₁₂ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {y : ⟦ D ⟧} {κ : Context}\n → [ c₂ ∣ y ∣ c₁ ⊕☐• κ ] ↦ [ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ]\n\n\n", "meta": {"hexsha": "feb5a5f4330167cefe3ac4aef9f7be8c6f1e82b1", "size": 4143, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Pi/Opsem.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "Pi/Opsem.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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": "Pi/Opsem.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 37.3243243243, "max_line_length": 106, "alphanum_fraction": 0.4542601979, "num_tokens": 2304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7520125737597972, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.35839388999794103}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import cohomology.Theory\nopen import groups.ExactSequence\nopen import groups.HomSequence\n\nmodule cw.cohomology.grid.LongExactSequence {i} (CT : CohomologyTheory i)\n {X Y Z : Ptd i} (n : ℤ) (f : X ⊙→ Y) (g : Y ⊙→ Z) where\n\nopen CohomologyTheory CT\nopen import cohomology.PtdMapSequence CT\nopen import cw.cohomology.grid.CofiberSplit (fst f) (fst g)\nopen import cw.cohomology.grid.PtdMap f g\n\n{-\n X --> Y ----> Z\n | | |\n v v v\n 1 -> Y/X --> Z/X\n | this |\n v one v\n 1 ---> Z/Y\n-}\n\nprivate\n ⊙D-span : ⊙Span\n ⊙D-span = ⊙span Y/X Z Y (⊙cfcod' f) g\n\n ⊙D : Ptd i\n ⊙D = ⊙Pushout ⊙D-span\n\n Y/X-to-D : Y/X ⊙→ ⊙D\n Y/X-to-D = B/A-to-D , idp\n\n open import cohomology.LongExactSequence CT n Y/X-to-D\n\n ⊙E : Ptd i\n ⊙E = ⊙Cofiber (⊙left ⊙D-span)\n\n Z/Y-to-E : Z/Y ⊙→ ⊙E\n Z/Y-to-E = C/B-to-E , idp\n\n Z/X-to-D : Z/X ⊙→ ⊙D\n Z/X-to-D = C/A-to-D , idp\n\ngrid-co∂ : C n Y/X →ᴳ C (succ n) Z/Y\ngrid-co∂ = record {f = CEl-fmap (succ n) Z/Y-to-E ∘ GroupHom.f co∂ ; pres-comp = lemma} where\n abstract lemma = ∘ᴳ-pres-comp (C-fmap (succ n) Z/Y-to-E) co∂\n\ngrid-∂-before-Susp : C/B → Susp B/A\ngrid-∂-before-Susp = extract-glue ∘ C/B-to-E\n\n⊙grid-∂-before-Susp : Z/Y ⊙→ ⊙Susp Y/X\n⊙grid-∂-before-Susp = grid-∂-before-Susp , lemma where\n abstract lemma = snd (⊙extract-glue ⊙∘ Z/Y-to-E)\n\nabstract\n grid-co∂-β : GroupHom.f grid-co∂ ∼ CEl-fmap (succ n) ⊙grid-∂-before-Susp ∘ <– (CEl-Susp n Y/X)\n grid-co∂-β x = ∘-CEl-fmap (succ n) Z/Y-to-E ⊙extract-glue _\n\nabstract\n grid-∂-before-Susp-glue-β : ∀ x →\n ap (fst ⊙grid-∂-before-Susp) (glue x) == merid (cfcod x)\n grid-∂-before-Susp-glue-β x =\n ap-∘ extract-glue C/B-to-E (glue x)\n ∙ ap (ap extract-glue) (C/B-to-E-glue-β x)\n ∙ ap-∙' extract-glue (glue (cfcod x)) (ap cfcod (glue x))\n ∙ ap2 _∙'_\n (ExtractGlue.glue-β (cfcod x))\n (∘-ap extract-glue cfcod (glue x) ∙ ap-cst south (glue x))\n\nC-grid-cofiber-seq : HomSequence (C n Z/X) (C (succ n) Y/X)\nC-grid-cofiber-seq =\n C n Z/X →⟨ C-fmap n Y/X-to-Z/X ⟩ᴳ\n C n Y/X →⟨ grid-co∂ ⟩ᴳ\n C (succ n) Z/Y →⟨ C-fmap (succ n) Z/X-to-Z/Y ⟩ᴳ\n C (succ n) Z/X →⟨ C-fmap (succ n) Y/X-to-Z/X ⟩ᴳ\n C (succ n) Y/X ⊣|ᴳ\n\nprivate\n C-cofiber-seq-to-C-grid-cofiber-seq :\n HomSeqMap C-cofiber-seq C-grid-cofiber-seq\n (C-fmap n Z/X-to-D) (idhom _)\n C-cofiber-seq-to-C-grid-cofiber-seq =\n C-fmap n Z/X-to-D ↓⟨ comm-sqrᴳ (λ d → ! (C-fmap-idf n _)\n ∙ (C-comm-square n B/A-to-C/A-comm-square □$ᴳ d)) ⟩ᴳ\n idhom _ ↓⟨ comm-sqrᴳ (λ _ → idp) ⟩ᴳ\n C-fmap (succ n) Z/Y-to-E ↓⟨ C-comm-square (succ n) C/A-to-C/B-comm-square ⟩ᴳ\n C-fmap (succ n) Z/X-to-D ↓⟨ comm-sqrᴳ (λ d → ! (C-fmap-idf (succ n) _)\n ∙ (C-comm-square (succ n) B/A-to-C/A-comm-square □$ᴳ d)) ⟩ᴳ\n idhom _ ↓|ᴳ\n\n C-cofiber-seq-equiv-C-grid-cofiber-seq :\n HomSeqEquiv C-cofiber-seq C-grid-cofiber-seq\n (C-fmap n Z/X-to-D) (idhom _)\n C-cofiber-seq-equiv-C-grid-cofiber-seq =\n C-cofiber-seq-to-C-grid-cofiber-seq ,\n CEl-isemap n Z/X-to-D C/A-to-D-is-equiv ,\n idf-is-equiv _ ,\n CEl-isemap (succ n) Z/Y-to-E C/B-to-E-is-equiv ,\n CEl-isemap (succ n) Z/X-to-D C/A-to-D-is-equiv ,\n idf-is-equiv _\n\nabstract\n C-grid-cofiber-seq-is-exact : is-exact-seq C-grid-cofiber-seq\n C-grid-cofiber-seq-is-exact = seq-equiv-preserves-exact\n C-cofiber-seq-equiv-C-grid-cofiber-seq C-cofiber-seq-is-exact\n\nC-grid-cofiber-exact-seq : ExactSequence (C n Z/X) (C (succ n) Y/X)\nC-grid-cofiber-exact-seq = C-grid-cofiber-seq , C-grid-cofiber-seq-is-exact\n", "meta": {"hexsha": "9e5b3e5246942b56b39cbe677b18c818938113bc", "size": 3724, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/cw/cohomology/grid/LongExactSequence.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/cw/cohomology/grid/LongExactSequence.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/cw/cohomology/grid/LongExactSequence.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": 33.25, "max_line_length": 107, "alphanum_fraction": 0.5668635875, "num_tokens": 1528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7905303087996142, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.358317228678687}} {"text": "{-# OPTIONS --guardedness --without-K #-}\n\nmodule ky where \n\nimport Relation.Binary.PropositionalEquality as Eq\nopen Eq using (_≡_; _≢_; refl; cong; cong₂; sym)\nopen Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)\nopen import Data.Rational using (ℚ; _+_; _*_; _-_)\nopen import Data.Bool\nopen import Data.Bool.Properties\nopen import Data.Rational\nopen import Data.Nat as ℕ using (ℕ; zero; suc; ⌊_/2⌋)\nopen import Data.Empty\nopen import Relation.Nullary \nopen import Relation.Nullary.Negation\nopen import Agda.Builtin.Size\nopen import Data.Product\nopen import Data.Unit\nopen import Data.Maybe\nopen import Data.List\n\nTyCon = List Set \n\ndata Env : TyCon → Set₁ where\n nil : Env []\n cons : ∀{t Γ} → t → Env Γ → Env (t ∷ Γ)\n\ndata Idx : Set → TyCon → Set₁ where\n fst : ∀{t Γ} → Idx t (t ∷ Γ)\n nxt : ∀{t t' Γ} → Idx t Γ → Idx t (t' ∷ Γ)\n\nget : ∀{t Γ} → Idx t Γ → Env Γ → t\nget fst (cons v _) = v\nget (nxt idx) (cons _ vs) = get idx vs\n\nupd : ∀{t Γ} → Idx t Γ → t -> Env Γ → Env Γ\nupd fst v' (cons _ vs) = cons v' vs\nupd (nxt idx) v' (cons v vs) = cons v (upd idx v' vs)\n\ndata Exp : TyCon → Set → Set₁ where\n EVal : ∀{t Γ} → t → Exp Γ t\n EVar : ∀{t Γ} → Idx t Γ → Exp Γ t\n EPlus : ∀{Γ} → Exp Γ ℚ → Exp Γ ℚ → Exp Γ ℚ\n\nrecord Cotree (i : Size) (A : Set) (Γ : TyCon) : Set₁\n\ndata Pattern : Size → TyCon → Set₁ where\n mkPattern : ∀{i Γ} → --{j₁ j₂ : Size< i} → \n (Cotree i Bool Γ → Cotree i Bool Γ → Cotree i Bool Γ) →\n Pattern i Γ\n\ndata Com : Size → TyCon → Set → Set₁ where\n CSkip : ∀{i Γ} → Com i Γ ⊤ \n CPrim : ∀{i t Γ} → Pattern i Γ → Com i Γ t → Com i Γ t → Com i Γ t\n --CFlip : ∀{i t Γ} → Com i Γ t → Com i Γ t → Com i Γ t\n CUpd : ∀{i t Γ} → Idx t Γ → Exp Γ t → Com i Γ ⊤ \n --CAlloc : ∀{t Γ} → Exp Γ t → Com (t ∷ Γ) ⊤ \n CIte : ∀{i t Γ} → Exp Γ Bool → Com i Γ t → Com i Γ t → Com i Γ t\n CSeq : ∀{i t Γ} → Com i Γ ⊤ → Com i Γ t → Com i Γ t\n CWhile : ∀{i t Γ} → Exp Γ Bool → Com i Γ t → Com i Γ ⊤\n\neval : ∀{t Γ} → Env Γ → Exp Γ t → t\neval ρ (EVal v) = v\neval ρ (EVar x) = get x ρ\neval ρ (EPlus e₁ e₂) = eval ρ e₁ + eval ρ e₂\n\n-- Cf. Abel 2017 (Equational Reasoning about Formal Languages in Coalgebraic Style)\nrecord Cotree i A Γ where\n coinductive\n field\n ν : Env Γ -> Maybe (Env Γ)\n δ : ∀{j : Size< i} → Env Γ → A → Cotree j A Γ \n\nopen Cotree\n\n∅ : ∀{i A Γ} → Cotree i A Γ\nν ∅ _ = nothing\nδ ∅ _ _ = ∅\n\nflip : ∀(i Γ) → Cotree i Bool Γ → Cotree i Bool Γ → Cotree i Bool Γ\nflip i Γ t₁ t₂ = t\n where t : Cotree i Bool Γ\n ν t ρ = nothing\n δ t ρ true = t₁\n δ t ρ false = t₂\n \ninterp : ∀(i){τ} → ∀(Γ) → Com i Γ τ → Cotree i Bool Γ\ninterp i Γ CSkip = t\n where t : ∀{j} → Cotree j Bool Γ\n ν t ρ = just ρ \n δ t ρ _ = ∅\ninterp i Γ (CPrim (mkPattern f) c₁ c₂) = t\n where t : Cotree i Bool Γ\n ν t ρ = nothing\n δ t ρ _ = f (interp i Γ c₁) (interp i Γ c₂)\n{-interp i Γ (CFlip c₁ c₂) = t\n where t : Cotree i Bool Γ\n ν t ρ = nothing\n δ t ρ true = interp i Γ c₁\n δ t ρ false = interp i Γ c₂-}\ninterp i Γ (CUpd x e) = t\n where t : ∀{j} → Cotree j Bool Γ\n ν t ρ = just (upd x (eval ρ e) ρ)\n δ t ρ _ = ∅\ninterp i Γ (CIte e c₁ c₂) = t\n where t : Cotree i Bool Γ \n ν t ρ with eval ρ e\n ... | true = ν (interp i Γ c₁) ρ \n ... | false = ν (interp i Γ c₂) ρ \n δ t ρ b with eval ρ e\n ... | true = δ (interp i Γ c₁) ρ b\n ... | false = δ (interp i Γ c₂) ρ b\ninterp i Γ (CSeq c₁ c₂) = t\n where t : Cotree i Bool Γ\n ν t ρ = nothing\n δ t ρ b with ν (interp i Γ c₁) ρ\n ... | nothing = δ (interp i Γ c₁) ρ b\n ... | just ρ' = δ (interp i Γ c₂) ρ' b\ninterp i Γ (CWhile e c) = t\n where t : Cotree i Bool Γ \n ν t ρ with eval ρ e\n ... | true = ν (interp i Γ c) ρ \n ... | false = just ρ \n δ t ρ b with eval ρ e\n ... | true = δ (interp i Γ c) ρ b\n ... | false = ∅ \n\n-- Flip as a derived command\ncflip : ∀(i Γ){τ} → Com i Γ τ → Com i Γ τ → Com i Γ τ\ncflip i Γ = CPrim (mkPattern (flip i Γ))\n", "meta": {"hexsha": "6008bd133596a14131db2d63dccb3c94f5e031ef", "size": 4089, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theory/ky.agda", "max_stars_repo_name": "OUPL/Zar", "max_stars_repo_head_hexsha": "9243f9d77d0c8af99afa4f536156a3e23b1c40e1", "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": "theory/ky.agda", "max_issues_repo_name": "OUPL/Zar", "max_issues_repo_head_hexsha": "9243f9d77d0c8af99afa4f536156a3e23b1c40e1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-09-13T15:40:08.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-06T16:32:25.000Z", "max_forks_repo_path": "theory/ky.agda", "max_forks_repo_name": "OUPL/Zar", "max_forks_repo_head_hexsha": "9243f9d77d0c8af99afa4f536156a3e23b1c40e1", "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": 31.213740458, "max_line_length": 83, "alphanum_fraction": 0.5292247493, "num_tokens": 1630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.3581421504026251}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\n\nopen import stash.modalities.gbm.GbmUtil\n\nmodule stash.modalities.gbm.PullbackSplit where\n\n-- L --> B K = A ×_D C / (f,h) d₁ = A -> D <- C\n-- | |g L = B ×_A K / (g,left) d₂ = B -> A <- K\n-- v v d = B -> D <- C\n-- K --> A\n-- | |f\n-- v v\n-- C --> D\n-- h\n\nmodule PullbackLSplit {i j k l} {A : Type i} {B : Type j} {C : Type k}\n {D : Type l} (f : A → D) (g : B → A) (h : C → D) where\n\n private\n d₁ : Cospan\n d₁ = cospan C A D h f\n\n d₂ : Cospan\n d₂ = cospan (Pullback d₁) B A Pullback.b g\n\n d : Cospan\n d = cospan C B D h (f ∘ g)\n\n split-equiv : Pullback d ≃ Pullback d₂\n split-equiv = equiv to from to-from from-to\n\n where to : Pullback d → Pullback d₂\n to (pullback c b p) = pullback (pullback c (g b) p) b idp\n\n from : Pullback d₂ → Pullback d\n from (pullback (pullback c a p) b idp) = pullback c b p\n\n to-from : (x : Pullback d₂) → to (from x) == x\n to-from (pullback _ b idp) = idp\n\n from-to : (x : Pullback d) → from (to x) == x\n from-to _ = idp\n\nrecord CospanMap {i₀ j₀ k₀ i₁ j₁ k₁} (cospan₀ : Cospan {i₀} {j₀} {k₀}) (cospan₁ : Cospan {i₁} {j₁} {k₁})\n : Type (lmax (lmax (lmax i₀ j₀) k₀) (lmax (lmax i₁ j₁) k₁)) where\n constructor cospan-map\n module cospan₀ = Cospan cospan₀\n module cospan₁ = Cospan cospan₁\n field\n hA : cospan₀.A → cospan₁.A\n hB : cospan₀.B → cospan₁.B\n hC : cospan₀.C → cospan₁.C\n f-commutes : CommSquare cospan₀.f cospan₁.f hA hC \n g-commutes : CommSquare cospan₀.g cospan₁.g hB hC \n\nCospanEquiv : ∀ {i₀ j₀ k₀ i₁ j₁ k₁} (cospan₀ : Cospan {i₀} {j₀} {k₀}) (cospan₁ : Cospan {i₁} {j₁} {k₁})\n → Type (lmax (lmax (lmax i₀ j₀) k₀) (lmax (lmax i₁ j₁) k₁))\nCospanEquiv cospan₀ cospan₁ = Σ (CospanMap cospan₀ cospan₁)\n (λ cospan-map → is-equiv (CospanMap.hA cospan-map)\n × is-equiv (CospanMap.hB cospan-map)\n × is-equiv (CospanMap.hC cospan-map))\n\nCospanEquiv-inverse : ∀ {i₀ j₀ k₀ i₁ j₁ k₁} {cospan₀ : Cospan {i₀} {j₀} {k₀}} {cospan₁ : Cospan {i₁} {j₁} {k₁}}\n → CospanEquiv cospan₀ cospan₁ → CospanEquiv cospan₁ cospan₀\nCospanEquiv-inverse (cospan-map hA hB hC f-commutes g-commutes , hA-ise , hB-ise , hC-ise)\n = (cospan-map hA.g hB.g hC.g\n (CommSquare-inverse-v f-commutes hA-ise hC-ise)\n (CommSquare-inverse-v g-commutes hB-ise hC-ise))\n , ( is-equiv-inverse hA-ise\n , is-equiv-inverse hB-ise\n , is-equiv-inverse hC-ise)\n where module hA = is-equiv hA-ise\n module hB = is-equiv hB-ise\n module hC = is-equiv hC-ise\n\nmodule PullbackFmap {i₀ j₀ k₀ i₁ j₁ k₁} {cospan₀ : Cospan {i₀} {j₀} {k₀}}\n {cospan₁ : Cospan {i₁} {j₁} {k₁}} (cospan-map : CospanMap cospan₀ cospan₁) where\n\n f : Pullback cospan₀ → Pullback cospan₁\n f (pullback a b h) = pullback\n (CospanMap.hA cospan-map a)\n (CospanMap.hB cospan-map b)\n (! (commutes (CospanMap.f-commutes cospan-map) a) ∙\n ap (λ x → CospanMap.hC cospan-map x) h ∙\n (commutes (CospanMap.g-commutes cospan-map) b))\n\nPullback-fmap = PullbackFmap.f\n\nmodule _ {i₀ j₀ k₀ i₁ j₁ k₁} {cospan₀ : Cospan {i₀} {j₀} {k₀}}\n {cospan₁ : Cospan {i₁} {j₁} {k₁}} (cospan-equiv : CospanEquiv cospan₀ cospan₁) where\n\n private\n module cospan₀ = Cospan cospan₀\n module cospan₁ = Cospan cospan₁\n cospan-to = fst cospan-equiv\n cospan-from = fst (CospanEquiv-inverse cospan-equiv)\n module cospan-to = CospanMap cospan-to\n module cospan-from = CospanMap cospan-from\n module To = PullbackFmap cospan-to\n module From = PullbackFmap cospan-from\n cospan-ise = snd cospan-equiv\n hA-ise = fst cospan-ise\n hB-ise = fst (snd cospan-ise)\n hC-ise = snd (snd cospan-ise)\n module hA-ise = is-equiv hA-ise\n module hB-ise = is-equiv hB-ise\n module hC-ise = is-equiv hC-ise\n\n f = cospan₀.f\n g = cospan₀.g\n f' = cospan₁.f\n g' = cospan₁.g\n\n α = commutes cospan-to.f-commutes\n β = commutes cospan-to.g-commutes\n\n α' = commutes cospan-from.f-commutes\n β' = commutes cospan-from.g-commutes\n \n hA = cospan-to.hA\n hB = cospan-to.hB\n hC = cospan-to.hC\n \n kA = cospan-from.hA\n kB = cospan-from.hB\n kC = cospan-from.hC\n\n module kA-ise = is-equiv (is-equiv-inverse hA-ise)\n module kB-ise = is-equiv (is-equiv-inverse hB-ise)\n module kC-ise = is-equiv (is-equiv-inverse hC-ise)\n\n kA-ise = is-equiv-inverse hA-ise\n kB-ise = is-equiv-inverse hB-ise\n kC-ise = is-equiv-inverse hC-ise\n\n to = To.f\n from = From.f\n\n from-to : ∀ x → from (to x) == x\n from-to (pullback a b h) = pullback= _ (hA-ise.g-f a) (hB-ise.g-f b) goal\n\n where eq₀ = hC-ise.g-f (f a) ∙ h ∙ ! (hC-ise.g-f (g b))\n =⟨ ! (ap-idf h) |in-ctx (λ x → hC-ise.g-f (f a) ∙ x ∙ ! (hC-ise.g-f (g b))) ⟩\n hC-ise.g-f (f a) ∙ ap (idf _) h ∙ ! (hC-ise.g-f (g b))\n =⟨ ! (∙-assoc (hC-ise.g-f (f a)) _ _) ⟩ \n (hC-ise.g-f (f a) ∙ ap (idf _) h) ∙ ! (hC-ise.g-f (g b))\n =⟨ ↓-==-out (apd hC-ise.g-f h) |in-ctx (λ x → x ∙ ! (hC-ise.g-f (g b))) ⟩\n (ap (kC ∘ hC) h ∙ hC-ise.g-f (g b)) ∙ ! (hC-ise.g-f (g b))\n =⟨ ∙-assoc (ap (kC ∘ hC) h) _ _ ⟩ \n ap (kC ∘ hC) h ∙ hC-ise.g-f (g b) ∙ ! (hC-ise.g-f (g b))\n =⟨ !-inv-r (hC-ise.g-f (g b)) |in-ctx (λ x → ap (kC ∘ hC) h ∙ x) ⟩ \n ap (kC ∘ hC) h ∙ idp\n =⟨ ∙-unit-r (ap (kC ∘ hC) h) ⟩ \n ap (kC ∘ hC) h ∎\n\n eq₁ = β' (hB b)\n =⟨ ! (hB-ise.adj b) |in-ctx (λ x → ap kC (! (β (kB (hB b)) ∙ ap g' x)) ∙ hC-ise.g-f (g (kB (hB b)))) ⟩ \n ap kC (! (β (kB (hB b)) ∙ ap g' (ap hB (hB-ise.g-f b)))) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ ∘-ap g' hB (hB-ise.g-f b) |in-ctx (λ x → ap kC (! (β (kB (hB b)) ∙ x)) ∙ hC-ise.g-f (g (kB (hB b)))) ⟩\n ap kC (! (β (kB (hB b)) ∙ ap (g' ∘ hB) (hB-ise.g-f b))) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ ↓-==-out (apd β (hB-ise.g-f b)) |in-ctx (λ x → ap kC (! x) ∙ hC-ise.g-f (g (kB (hB b)))) ⟩ \n ap kC (! (ap (hC ∘ g) (hB-ise.g-f b) ∙ β b)) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ ap-! kC (ap (hC ∘ g) (hB-ise.g-f b) ∙ β b) |in-ctx (λ x → x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩ \n ! (ap kC (ap (hC ∘ g) (hB-ise.g-f b) ∙ β b)) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ ap-∙ kC (ap (hC ∘ g) (hB-ise.g-f b)) (β b) |in-ctx (λ x → ! x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩ \n ! (ap kC (ap (hC ∘ g) (hB-ise.g-f b)) ∙ ap kC (β b)) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ !-∙ (ap kC (ap (hC ∘ g) (hB-ise.g-f b))) (ap kC (β b)) |in-ctx (λ x → x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩\n (! (ap kC (β b)) ∙ ! (ap kC (ap (hC ∘ g) (hB-ise.g-f b)))) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ ∙-assoc (! (ap kC (β b))) _ _ ⟩\n ! (ap kC (β b)) ∙ ! (ap kC (ap (hC ∘ g) (hB-ise.g-f b))) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ ∘-ap kC (hC ∘ g) (hB-ise.g-f b) |in-ctx (λ x → ! (ap kC (β b)) ∙ ! x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩ \n ! (ap kC (β b)) ∙ ! (ap (kC ∘ hC ∘ g) (hB-ise.g-f b)) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ ! (∘-ap (kC ∘ hC) g (hB-ise.g-f b)) |in-ctx (λ x → ! (ap kC (β b)) ∙ ! x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩ \n ! (ap kC (β b)) ∙ ! (ap (kC ∘ hC) (ap g (hB-ise.g-f b))) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ eqv-square' (hC , hC-ise) (ap g (hB-ise.g-f b)) |in-ctx (λ x → ! (ap kC (β b)) ∙ ! x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩ \n ! (ap kC (β b)) ∙ ! (hC-ise.g-f (g (kB (hB b))) ∙ (ap g (hB-ise.g-f b)) ∙ ! (hC-ise.g-f (g b))) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ !-∙ (hC-ise.g-f (g (kB (hB b)))) ((ap g (hB-ise.g-f b)) ∙ ! (hC-ise.g-f (g b))) |in-ctx (λ x → ! (ap kC (β b)) ∙ x ∙ hC-ise.g-f (g (kB (hB b)))) ⟩ \n ! (ap kC (β b)) ∙ (! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b))) ∙ ! (hC-ise.g-f (g (kB (hB b))))) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ ∙-assoc (! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b)))) _ _ |in-ctx (λ x → ! (ap kC (β b)) ∙ x) ⟩ \n ! (ap kC (β b)) ∙ ! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b))) ∙ ! (hC-ise.g-f (g (kB (hB b)))) ∙ hC-ise.g-f (g (kB (hB b)))\n =⟨ !-inv-l (hC-ise.g-f (g (kB (hB b)))) |in-ctx (λ x → ! (ap kC (β b)) ∙ ! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b))) ∙ x) ⟩ \n ! (ap kC (β b)) ∙ ! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b))) ∙ idp\n =⟨ ∙-unit-r (! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b)))) |in-ctx (λ x → ! (ap kC (β b)) ∙ x) ⟩ \n ! (ap kC (β b)) ∙ ! (ap g (hB-ise.g-f b) ∙ ! (hC-ise.g-f (g b)))\n =⟨ !-∙ (ap g (hB-ise.g-f b)) (! (hC-ise.g-f (g b))) |in-ctx (λ x → ! (ap kC (β b)) ∙ x) ⟩ \n ! (ap kC (β b)) ∙ ! (! (hC-ise.g-f (g b))) ∙ ! (ap g (hB-ise.g-f b))\n =⟨ !-! (hC-ise.g-f (g b)) |in-ctx (λ x → ! (ap kC (β b)) ∙ x ∙ ! (ap g (hB-ise.g-f b))) ⟩ \n ! (ap kC (β b)) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b)) ∎\n\n eq₂ = α' (hA a)\n =⟨ ! (hA-ise.adj a) |in-ctx (λ x → ap kC (! (α (kA (hA a)) ∙ ap f' x)) ∙ hC-ise.g-f (f (kA (hA a)))) ⟩ \n ap kC (! (α (kA (hA a)) ∙ ap f' (ap hA (hA-ise.g-f a)))) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ ∘-ap f' hA (hA-ise.g-f a) |in-ctx (λ x → ap kC (! (α (kA (hA a)) ∙ x)) ∙ hC-ise.g-f (f (kA (hA a)))) ⟩\n ap kC (! (α (kA (hA a)) ∙ ap (f' ∘ hA) (hA-ise.g-f a))) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ ↓-==-out (apd α (hA-ise.g-f a)) |in-ctx (λ x → ap kC (! x) ∙ hC-ise.g-f (f (kA (hA a)))) ⟩ \n ap kC (! (ap (hC ∘ f) (hA-ise.g-f a) ∙ α a)) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ ap-! kC (ap (hC ∘ f) (hA-ise.g-f a) ∙ α a) |in-ctx (λ x → x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩ \n ! (ap kC (ap (hC ∘ f) (hA-ise.g-f a) ∙ α a)) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ ap-∙ kC (ap (hC ∘ f) (hA-ise.g-f a)) (α a) |in-ctx (λ x → ! x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩ \n ! (ap kC (ap (hC ∘ f) (hA-ise.g-f a)) ∙ ap kC (α a)) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ !-∙ (ap kC (ap (hC ∘ f) (hA-ise.g-f a))) (ap kC (α a)) |in-ctx (λ x → x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩\n (! (ap kC (α a)) ∙ ! (ap kC (ap (hC ∘ f) (hA-ise.g-f a)))) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ ∙-assoc (! (ap kC (α a))) _ _ ⟩\n ! (ap kC (α a)) ∙ ! (ap kC (ap (hC ∘ f) (hA-ise.g-f a))) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ ∘-ap kC (hC ∘ f) (hA-ise.g-f a) |in-ctx (λ x → ! (ap kC (α a)) ∙ ! x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩ \n ! (ap kC (α a)) ∙ ! (ap (kC ∘ hC ∘ f) (hA-ise.g-f a)) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ ! (∘-ap (kC ∘ hC) f (hA-ise.g-f a)) |in-ctx (λ x → ! (ap kC (α a)) ∙ ! x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩ \n ! (ap kC (α a)) ∙ ! (ap (kC ∘ hC) (ap f (hA-ise.g-f a))) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ eqv-square' (hC , hC-ise) (ap f (hA-ise.g-f a)) |in-ctx (λ x → ! (ap kC (α a)) ∙ ! x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩ \n ! (ap kC (α a)) ∙ ! (hC-ise.g-f (f (kA (hA a))) ∙ (ap f (hA-ise.g-f a)) ∙ ! (hC-ise.g-f (f a))) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ !-∙ (hC-ise.g-f (f (kA (hA a)))) ((ap f (hA-ise.g-f a)) ∙ ! (hC-ise.g-f (f a))) |in-ctx (λ x → ! (ap kC (α a)) ∙ x ∙ hC-ise.g-f (f (kA (hA a)))) ⟩ \n ! (ap kC (α a)) ∙ (! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a))) ∙ ! (hC-ise.g-f (f (kA (hA a))))) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ ∙-assoc (! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a)))) _ _ |in-ctx (λ x → ! (ap kC (α a)) ∙ x) ⟩ \n ! (ap kC (α a)) ∙ ! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a))) ∙ ! (hC-ise.g-f (f (kA (hA a)))) ∙ hC-ise.g-f (f (kA (hA a)))\n =⟨ !-inv-l (hC-ise.g-f (f (kA (hA a)))) |in-ctx (λ x → ! (ap kC (α a)) ∙ ! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a))) ∙ x) ⟩ \n ! (ap kC (α a)) ∙ ! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a))) ∙ idp\n =⟨ ∙-unit-r (! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a)))) |in-ctx (λ x → ! (ap kC (α a)) ∙ x) ⟩ \n ! (ap kC (α a)) ∙ ! (ap f (hA-ise.g-f a) ∙ ! (hC-ise.g-f (f a)))\n =⟨ !-∙ (ap f (hA-ise.g-f a)) (! (hC-ise.g-f (f a))) |in-ctx (λ x → ! (ap kC (α a)) ∙ x) ⟩ \n ! (ap kC (α a)) ∙ ! (! (hC-ise.g-f (f a))) ∙ ! (ap f (hA-ise.g-f a))\n =⟨ !-! (hC-ise.g-f (f a)) |in-ctx (λ x → ! (ap kC (α a)) ∙ x ∙ ! (ap f (hA-ise.g-f a))) ⟩\n ! (ap kC (α a)) ∙ hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a)) ∎\n\n lem = ! (α' (hA a)) ∙ ap kC (! (α a) ∙ ap hC h ∙ β b) ∙ β' (hB b)\n =⟨ ap-∙ kC (! (α a)) (ap hC h ∙ β b) |in-ctx (λ x → ! (α' (hA a)) ∙ x ∙ β' (hB b)) ⟩\n ! (α' (hA a)) ∙ (ap kC (! (α a)) ∙ ap kC (ap hC h ∙ β b)) ∙ β' (hB b)\n =⟨ ∙-assoc (ap kC (! (α a))) (ap kC (ap hC h ∙ β b)) (β' (hB b)) |in-ctx (λ x → ! (α' (hA a)) ∙ x) ⟩ \n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap kC (ap hC h ∙ β b) ∙ β' (hB b)\n =⟨ ap-∙ kC (ap hC h) (β b) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x ∙ β' (hB b)) ⟩ \n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (ap kC (ap hC h) ∙ ap kC (β b)) ∙ β' (hB b)\n =⟨ ∙-assoc (ap kC (ap hC h)) (ap kC (β b)) (β' (hB b)) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x) ⟩ \n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap kC (ap hC h) ∙ ap kC (β b) ∙ β' (hB b)\n =⟨ ∘-ap kC hC h |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x ∙ ap kC (β b) ∙ β' (hB b)) ⟩\n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ ap kC (β b) ∙ β' (hB b)\n =⟨ eq₁ |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ ap kC (β b) ∙ x) ⟩ \n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ ap kC (β b) ∙ ! (ap kC (β b)) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))\n =⟨ ! (∙-assoc (ap kC (β b)) _ _) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ x) ⟩ \n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ (ap kC (β b) ∙ ! (ap kC (β b))) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b)) \n =⟨ !-inv-r (ap kC (β b)) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ x ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))) ⟩\n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ap (kC ∘ hC) h ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))\n =⟨ ! eq₀ |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))) ⟩\n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h ∙ ! (hC-ise.g-f (g b))) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b)) \n =⟨ ! (∙-assoc (hC-ise.g-f (f a)) _ _) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))) ⟩\n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ ((hC-ise.g-f (f a) ∙ h) ∙ ! (hC-ise.g-f (g b))) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))\n =⟨ ∙-assoc (hC-ise.g-f (f a) ∙ h) _ _ |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x) ⟩ \n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h) ∙ ! (hC-ise.g-f (g b)) ∙ hC-ise.g-f (g b) ∙ ! (ap g (hB-ise.g-f b))\n =⟨ ! (∙-assoc (! (hC-ise.g-f (g b))) _ _) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h) ∙ x) ⟩ \n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h) ∙ (! (hC-ise.g-f (g b)) ∙ hC-ise.g-f (g b)) ∙ ! (ap g (hB-ise.g-f b))\n =⟨ !-inv-l (hC-ise.g-f (g b)) |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h) ∙ x ∙ ! (ap g (hB-ise.g-f b))) ⟩\n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ (hC-ise.g-f (f a) ∙ h) ∙ ! (ap g (hB-ise.g-f b))\n =⟨ ∙-assoc (hC-ise.g-f (f a)) _ _ |in-ctx (λ x → ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ x) ⟩\n ! (α' (hA a)) ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ eq₂ |in-ctx (λ x → ! x ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩ \n ! (! (ap kC (α a)) ∙ hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ !-∙ (! (ap kC (α a))) _ |in-ctx (λ x → x ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩\n (! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ ! (! (ap kC (α a)))) ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ ∙-assoc (! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a)))) _ _ ⟩\n ! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ ! (! (ap kC (α a))) ∙ ap kC (! (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ ap-! kC (α a) |in-ctx (λ x → ! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ ! (! (ap kC (α a))) ∙ x ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩ \n ! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ ! (! (ap kC (α a))) ∙ ! (ap kC (α a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ ! (∙-assoc (! (! (ap kC (α a)))) _ _) |in-ctx (λ x → ! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ x) ⟩ \n ! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ (! (! (ap kC (α a))) ∙ ! (ap kC (α a))) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ !-inv-l (! (ap kC (α a))) |in-ctx (λ x → ! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ x ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩ \n ! (hC-ise.g-f (f a) ∙ ! (ap f (hA-ise.g-f a))) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ !-∙ (hC-ise.g-f (f a)) _ |in-ctx (λ x → x ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩ \n (! (! (ap f (hA-ise.g-f a))) ∙ ! (hC-ise.g-f (f a))) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ ∙-assoc (! (! (ap f (hA-ise.g-f a)))) _ _ ⟩\n ! (! (ap f (hA-ise.g-f a))) ∙ ! (hC-ise.g-f (f a)) ∙ hC-ise.g-f (f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ ! (∙-assoc (! (hC-ise.g-f (f a))) _ _) |in-ctx (λ x → ! (! (ap f (hA-ise.g-f a))) ∙ x) ⟩ \n ! (! (ap f (hA-ise.g-f a))) ∙ (! (hC-ise.g-f (f a)) ∙ hC-ise.g-f (f a)) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ !-inv-l (hC-ise.g-f (f a)) |in-ctx (λ x → ! (! (ap f (hA-ise.g-f a))) ∙ x ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩\n ! (! (ap f (hA-ise.g-f a))) ∙ h ∙ ! (ap g (hB-ise.g-f b))\n =⟨ !-! (ap f (hA-ise.g-f a)) |in-ctx (λ x → x ∙ h ∙ ! (ap g (hB-ise.g-f b))) ⟩ \n ap f (hA-ise.g-f a) ∙ h ∙ ! (ap g (hB-ise.g-f b)) ∎\n\n goal = (! (α' (hA a)) ∙ ap kC (! (α a) ∙ ap hC h ∙ β b) ∙ β' (hB b)) ∙ ap g (hB-ise.g-f b)\n =⟨ lem |in-ctx (λ x → x ∙ ap g (hB-ise.g-f b)) ⟩\n (ap f (hA-ise.g-f a) ∙ h ∙ ! (ap g (hB-ise.g-f b))) ∙ ap g (hB-ise.g-f b)\n =⟨ ∙-assoc (ap f (hA-ise.g-f a)) (h ∙ ! (ap g (hB-ise.g-f b))) _ ⟩ \n ap f (hA-ise.g-f a) ∙ (h ∙ ! (ap g (hB-ise.g-f b))) ∙ ap g (hB-ise.g-f b)\n =⟨ ∙-assoc h _ _ |in-ctx (λ x → ap f (hA-ise.g-f a) ∙ x) ⟩ \n ap f (hA-ise.g-f a) ∙ h ∙ ! (ap g (hB-ise.g-f b)) ∙ ap g (hB-ise.g-f b)\n =⟨ !-inv-l (ap g (hB-ise.g-f b)) |in-ctx (λ x → ap f (hA-ise.g-f a) ∙ h ∙ x) ⟩ \n ap f (hA-ise.g-f a) ∙ h ∙ idp\n =⟨ ∙-unit-r h |in-ctx (λ x → ap f (hA-ise.g-f a) ∙ x) ⟩ \n ap f (hA-ise.g-f a) ∙ h ∎\n\n\n postulate\n to-from : ∀ y → to (from y) == y\n -- to-from (pullback a b h) = pullback= _ (hA-ise.f-g a) (hB-ise.f-g b) {!!}\n\n Pullback-emap : Pullback cospan₀ ≃ Pullback cospan₁\n Pullback-emap = equiv to from to-from from-to\n\n", "meta": {"hexsha": "b1a4068d69c5ae46db6b7164fd08ee8fa5b5e5e3", "size": 20326, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/stash/modalities/gbm/PullbackSplit.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/stash/modalities/gbm/PullbackSplit.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/stash/modalities/gbm/PullbackSplit.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 68.2080536913, "max_line_length": 177, "alphanum_fraction": 0.3967332481, "num_tokens": 9685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.689305616785446, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.35810896526137775}} {"text": "open import core\n\nmodule focus-formation where\n -- every ε is an evaluation context -- trivially, here, since we don't\n -- include any of the premises in red brackets about finality\n focus-formation : ∀{d d' ε} → d == ε ⟦ d' ⟧ → ε evalctx\n focus-formation FHOuter = ECDot\n focus-formation (FHAp1 sub) = ECAp1 (focus-formation sub)\n focus-formation (FHAp2 sub) = ECAp2 (focus-formation sub)\n focus-formation (FHNEHole sub) = ECNEHole (focus-formation sub)\n focus-formation (FHCast sub) = ECCast (focus-formation sub)\n focus-formation (FHFailedCast x) = ECFailedCast (focus-formation x)\n", "meta": {"hexsha": "97d13d9d8809e56600098892991058959dc56677", "size": 594, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "focus-formation.agda", "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_issues_repo_path": "focus-formation.agda", "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_forks_repo_path": "focus-formation.agda", "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "avg_line_length": 45.6923076923, "max_line_length": 72, "alphanum_fraction": 0.7255892256, "num_tokens": 183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6548947155710234, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.35805592653579066}} {"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.Concept.Model using\n ( _⟦_⟧₁ ; ⟦⟧₁-resp-≈ ; ⟦⟧₁-resp-≃; ⟦⟧₁-refl-≃ )\nopen import Web.Semantic.DL.Role.Model using\n ( _⟦_⟧₂ ; ⟦⟧₂-resp-≈ ; ⟦⟧₂-resp-≃ ; ⟦⟧₂-refl-≃ )\nopen import Web.Semantic.DL.Signature using ( Signature )\nopen import Web.Semantic.DL.TBox using\n ( TBox ; Axioms ; ε ; _,_ ;_⊑₁_ ; _⊑₂_ ; Dis ; Ref ; Irr ; Tra )\nopen import Web.Semantic.DL.TBox.Interp using ( Interp )\nopen import Web.Semantic.DL.TBox.Interp.Morphism using ( _≃_ ; ≃-sym )\nopen import Web.Semantic.Util using ( True ; tt ; _∘_ )\n\nmodule Web.Semantic.DL.TBox.Model {Σ : Signature} where\n\ninfixr 2 _⊨t_\n\n_⊨t_ : Interp Σ → TBox Σ → Set\nI ⊨t ε = True\nI ⊨t (T , U) = (I ⊨t T) × (I ⊨t U)\nI ⊨t (C ⊑₁ D) = I ⟦ C ⟧₁ ⊆ I ⟦ D ⟧₁\nI ⊨t (Q ⊑₂ R) = I ⟦ Q ⟧₂ ⊆ I ⟦ R ⟧₂\nI ⊨t (Dis Q R) = ∀ {xy} → (xy ∈ I ⟦ Q ⟧₂) → (xy ∉ I ⟦ R ⟧₂)\nI ⊨t (Ref R) = ∀ x → ((x , x) ∈ I ⟦ R ⟧₂) \nI ⊨t (Irr R) = ∀ x → ((x , x) ∉ I ⟦ R ⟧₂) \nI ⊨t (Tra R) = ∀ {x y z} → \n ((x , y) ∈ I ⟦ R ⟧₂) → ((y , z) ∈ I ⟦ R ⟧₂) → ((x , z) ∈ I ⟦ R ⟧₂)\n\nAxioms✓ : ∀ I T {t} → (t ∈ Axioms T) → (I ⊨t T) → (I ⊨t t)\nAxioms✓ I ε () I⊨T\nAxioms✓ I (T , U) (inj₁ t∈T) (I⊨T , I⊨U) = Axioms✓ I T t∈T I⊨T\nAxioms✓ I (T , U) (inj₂ t∈U) (I⊨T , I⊨U) = Axioms✓ I U t∈U I⊨U\nAxioms✓ I (C ⊑₁ D) refl I⊨T = I⊨T\nAxioms✓ I (Q ⊑₂ R) refl I⊨T = I⊨T\nAxioms✓ I (Dis Q R) refl I⊨T = I⊨T\nAxioms✓ I (Ref R) refl I⊨T = I⊨T\nAxioms✓ I (Irr R) refl I⊨T = I⊨T\nAxioms✓ I (Tra R) refl I⊨T = I⊨T\n\n⊨t-resp-≃ : ∀ {I J : Interp Σ} → (I ≃ J) → ∀ T → (I ⊨t T) → (J ⊨t T)\n⊨t-resp-≃ {I} {J} I≃J ε _ = \n tt\n⊨t-resp-≃ {I} {J} I≃J (T , U) (I⊨T , I⊨U) = \n (⊨t-resp-≃ I≃J T I⊨T , ⊨t-resp-≃ I≃J U I⊨U)\n⊨t-resp-≃ {I} {J} I≃J (C ⊑₁ D) I⊨C⊑D = \n ⟦⟧₁-refl-≃ I≃J D ∘ I⊨C⊑D ∘ ⟦⟧₁-resp-≃ (≃-sym I≃J) C\n⊨t-resp-≃ {I} {J} I≃J (Q ⊑₂ R) I⊨Q⊑R = ⟦⟧₂-refl-≃ I≃J R ∘ I⊨Q⊑R ∘\n ⟦⟧₂-resp-≃ (≃-sym I≃J) Q\n⊨t-resp-≃ {I} {J} I≃J (Dis Q R) I⊨DisQR = λ xy∈⟦Q⟧ xy∈⟦R⟧ → \n I⊨DisQR (⟦⟧₂-resp-≃ (≃-sym I≃J) Q xy∈⟦Q⟧) (⟦⟧₂-resp-≃ (≃-sym I≃J) R xy∈⟦R⟧)\n⊨t-resp-≃ {I} {J} I≃J (Ref R) I⊨RefR = λ x → ⟦⟧₂-refl-≃ I≃J R (I⊨RefR _)\n⊨t-resp-≃ {I} {J} I≃J (Irr R) I⊨IrrR = λ x xx∈⟦R⟧ → \n I⊨IrrR _ (⟦⟧₂-resp-≃ (≃-sym I≃J) R xx∈⟦R⟧)\n⊨t-resp-≃ {I} {J} I≃J (Tra R) I⊨TraR = λ xy∈⟦R⟧ yz∈⟦R⟧ → \n ⟦⟧₂-refl-≃ I≃J R (I⊨TraR \n (⟦⟧₂-resp-≃ (≃-sym I≃J) R xy∈⟦R⟧) \n (⟦⟧₂-resp-≃ (≃-sym I≃J) R yz∈⟦R⟧))\n", "meta": {"hexsha": "a1c09b122b71b3dda7a04be6ded3b367e6ccb894", "size": 2609, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Web/Semantic/DL/TBox/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/TBox/Model.agda", "max_issues_repo_name": "bblfish/agda-web-semantic", "max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "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/TBox/Model.agda", "max_forks_repo_name": "bblfish/agda-web-semantic", "max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "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": 43.4833333333, "max_line_length": 77, "alphanum_fraction": 0.4741280184, "num_tokens": 1645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7217432062975979, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.3580523511067952}} {"text": "\nopen import Agda.Builtin.Reflection\nopen import Agda.Builtin.String\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.Unit\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Sigma\n\ndata Wrap (A : Set) : Set where\n [_] : A → Wrap A\n\nmacro\n give : Wrap Term → Term → TC ⊤\n give [ t ] hole = unify hole t\n\npattern vArg x = arg (arg-info visible relevant) x\npattern hArg x = arg (arg-info hidden relevant) x\n\n-- Naming the variable \"_\" doesn't affect the deBruijn indices for lambda and pi\n\n`id : Term\n`id = lam visible (abs \"_\" (var 0 []))\n\n`IdType : Term\n`IdType = pi (hArg (agda-sort (lit 0))) (abs \"_\" (pi (vArg (var 0 [])) (abs \"_\" (var 1 []))))\n\nid : give [ `IdType ]\nid = give [ `id ]\n\nid-ok : (λ {A : Set} (x : A) → x) ≡ id\nid-ok = refl\n\n-- Underscores should behave the same for clauses as for lambda and pi\n\nidClause : Clause\nidClause = clause\n ((\"_\" , vArg unknown) ∷ (\"_\" , hArg unknown) ∷ [])\n (hArg (var 1) ∷ vArg (var 0) ∷ [])\n (var 0 [])\n\ninfixr 4 _>>=_\n_>>=_ = bindTC\n\nunquoteDecl id₂ =\n declareDef (vArg id₂) `IdType >>= λ _ →\n defineFun id₂ (idClause ∷ [])\n\nid₂-ok : (λ {A : Set} (x : A) → x) ≡ id₂\nid₂-ok = refl\n", "meta": {"hexsha": "d4da3d57daeff99384d9803a391006bff60d07ef", "size": 1213, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue2129.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/Succeed/Issue2129.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/Succeed/Issue2129.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": 23.7843137255, "max_line_length": 93, "alphanum_fraction": 0.615004122, "num_tokens": 414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5888891451980403, "lm_q2_score": 0.6076631698328916, "lm_q1q2_score": 0.3578462446512231}} {"text": "{-# OPTIONS --without-K #-}\n\nmodule CauchyProofs where\n\n-- Proofs about permutations defined in module Cauchy (everything\n-- except the multiplicative ones which are defined in CauchyProofsT and\n-- CauchyProofsS\n\nopen import Relation.Binary.PropositionalEquality \n using (_≡_; refl; sym; trans; subst; subst₂; cong; cong₂; setoid; \n proof-irrelevance; module ≡-Reasoning)\nopen import Data.Nat.Properties\n using (m≤m+n; n≤m+n; n≤1+n; cancel-*-right-≤; ≰⇒>; ¬i+1+j≤i)\nopen import Data.Nat.Properties.Simple \n using (+-right-identity; +-suc; +-assoc; +-comm; \n *-assoc; *-comm; *-right-zero; distribʳ-*-+; +-*-suc)\n\nopen import Data.Nat using (ℕ; suc; _+_; _∸_; _*_; _<_; _≮_; _≤_; _≰_; \n _≥_; z≤n; s≤s; _≟_; _≤?_; ≤-pred; module ≤-Reasoning)\nopen import Data.Fin \n using (Fin; zero; suc; toℕ; fromℕ; fromℕ≤; _ℕ-_; _≺_; reduce≥; \n raise; inject+; inject₁; inject≤; _≻toℕ_) \n renaming (_+_ to _F+_)\nopen import Data.Fin.Properties using (bounded; inject+-lemma; to-from)\nopen import Data.Vec.Properties \n using (lookup∘tabulate; tabulate∘lookup; lookup-allFin; tabulate-∘; \n tabulate-allFin; allFin-map; lookup-++-inject+; lookup-++-≥)\n\nopen import Data.Vec \n using (Vec; tabulate; []; _∷_; tail; lookup; zip; zipWith; splitAt;\n _[_]≔_; allFin; toList)\n renaming (_++_ to _++V_; map to mapV; concat to concatV)\nopen import Function using (id; _∘_; _$_; _∋_; flip)\n\nopen import Proofs\nopen import Cauchy\n\n------------------------------------------------------------------------------\n-- Proofs about sequential composition\n\n-- sequential composition with id on the right is identity\n\nscomprid : ∀ {n} → (perm : Cauchy n) → scompcauchy perm (idcauchy n) ≡ perm\nscomprid {n} perm = \n begin (scompcauchy perm (idcauchy n)\n ≡⟨ refl ⟩ \n tabulate (λ i → lookup (lookup i perm) (allFin n))\n ≡⟨ finext (λ i → lookup-allFin (lookup i perm)) ⟩ \n tabulate (λ i → lookup i perm)\n ≡⟨ tabulate∘lookup perm ⟩ \n perm ∎)\n where open ≡-Reasoning\n\n-- sequential composition with id on the left is identity\n\nscomplid : ∀ {n} → (perm : Cauchy n) → scompcauchy (idcauchy n) perm ≡ perm\nscomplid {n} perm = \n trans (finext (λ i → cong (λ x → lookup x perm) (lookup-allFin i)))\n (tabulate∘lookup perm)\n\n-- sequential composition is associative\nscompassoc : ∀ {n} → (π₁ π₂ π₃ : Cauchy n) → \n scompcauchy π₁ (scompcauchy π₂ π₃) ≡ scompcauchy (scompcauchy π₁ π₂) π₃\nscompassoc π₁ π₂ π₃ = finext (lookupassoc π₁ π₂ π₃)\n\n------------------------------------------------------------------------------\n-- Proofs about additive permutations\n\nlookup-subst2 : ∀ {m m'}\n (i : Fin m) (xs : Vec (Fin m) m) (eq : m ≡ m') →\n lookup (subst Fin eq i)\n (subst Cauchy eq xs) ≡ subst Fin eq (lookup i xs)\nlookup-subst2 i xs refl = refl\n\nallFin+ : (m n : ℕ) → allFin (m + n) ≡ \n mapV (inject+ n) (allFin m) ++V mapV (raise m) (allFin n)\nallFin+ m n = trans (tabulate-split {m} {n})\n (cong₂ _++V_ (tabulate-allFin {m} (inject+ n)) (tabulate-allFin {n} (raise m)))\n\n-- swap+ is idempotent\n--\n-- outline of swap+idemp proof\n--\n-- allFin (m + n) ≡ mapV (inject+ n) (allFin m) ++V mapV (raise m) (allFin n)\n-- zero-m : Vec (Fin (m + n)) m ≡ mapV (inject+ n) (allFin m) \n-- m-sum : Vec (Fin (m + n)) n ≡ mapV (raise m) (allFin n)\n-- allFin (n + m) ≡ mapV (inject+ m) (allFin n) ++V mapV (raise n) (allFin m)\n-- zero-n : Vec (Fin (n + m)) n ≡ mapV (inject+ m) (allFin n) \n-- n-sum : Vec (Fin (n + m)) m ≡ mapV (raise n) (allFin m)\n-- \n-- first swap re-arranges allFin (n + m) to n-sum ++V zero-n\n-- second swap re-arranges allfin (m + n) to m-sum ++V zero-m\n-- \n-- for i = 0, ..., m-1, we have inject+ n i : Fin (m + n)\n-- lookup (lookup (inject+ n i) (n-sum ++V zero-n)) (m-sum ++V zero-m) ==> \n-- lookup (lookup i n-sum) (m-sum ++V zero-m) ==>\n-- lookup (raise n i) (m-sum ++V zero-m) ==> \n-- lookup i zero-m ==>\n-- inject+ n i\n-- \n-- for i = m, ..., m+n-1, we have raise m i : Fin (m + n)\n-- lookup (lookup (raise m i) (n-sum ++V zero-n)) (m-sum ++V zero-m) ==> \n-- lookup (lookup i zero-n) (m-sum ++V zero-m) ==> \n-- lookup (inject+ m i) (m-sum ++V zero-m) ==> \n-- lookup i m-sum ==> \n-- raise m i\n\nswap+-left : (m n : ℕ) → ∀ (i : Fin m) → \n let q = subst Cauchy (+-comm n m) (swap+cauchy n m) in\n lookup (lookup (inject+ n i) (swap+cauchy m n)) q ≡ inject+ n i\nswap+-left m n i = \n let q = subst Cauchy (+-comm n m) (swap+cauchy n m) in\n begin (\n lookup (lookup (inject+ n i) (swap+cauchy m n)) q\n ≡⟨ cong (flip lookup q) ( (lookup-++-inject+ (tabulate {m} (id+ {m} {n} ∘ raise n)) \n (tabulate {n} (id+ {m} {n} ∘ inject+ m)) i)) ⟩\n lookup (lookup i (tabulate (λ x → subst Fin (+-comm n m) (raise n x)))) q\n ≡⟨ cong (flip lookup q) (lookup∘tabulate (λ x → subst Fin (+-comm n m) (raise n x)) i) ⟩ \n lookup (subst Fin (+-comm n m) (raise n i)) q\n ≡⟨ lookup-subst2 (raise n i) (swap+cauchy n m) (+-comm n m) ⟩\n subst Fin (+-comm n m) (lookup (raise n i) (swap+cauchy n m))\n ≡⟨ cong (subst Fin (+-comm n m))\n (lookup-++-raise (tabulate {n} (id+ {n} ∘ raise m)) (tabulate {m} (id+ {n} ∘ inject+ n)) i) ⟩\n subst Fin (+-comm n m)\n (lookup i (tabulate (λ z → subst Fin (+-comm m n) (inject+ n z))))\n ≡⟨ subst-lookup-tabulate-inject+ i ⟩\n inject+ n i ∎) \n where open ≡-Reasoning\n\nswap+-right : (m n : ℕ) → (i : Fin n) →\n let q = subst Cauchy (+-comm n m) (swap+cauchy n m) in\n lookup (lookup (raise m i) (swap+cauchy m n)) q ≡ raise m i\nswap+-right m n i =\n let q = subst Cauchy (+-comm n m) (swap+cauchy n m) in\n begin (\n lookup (lookup (raise m i) (swap+cauchy m n)) q\n ≡⟨ cong (flip lookup q) ( (lookup-++-raise (tabulate {m} (id+ {m} {n} ∘ raise n)) \n (tabulate {n} (id+ {m} {n} ∘ inject+ m)) i)) ⟩\n lookup (lookup i (tabulate (λ x → subst Fin (+-comm n m) (inject+ m x)))) q\n ≡⟨ cong (flip lookup q) (lookup∘tabulate (λ x → subst Fin (+-comm n m) (inject+ m x)) i) ⟩ \n lookup (subst Fin (+-comm n m) (inject+ m i)) q\n ≡⟨ lookup-subst2 (inject+ m i) (swap+cauchy n m) (+-comm n m) ⟩\n subst Fin (+-comm n m) (lookup (inject+ m i) (swap+cauchy n m))\n ≡⟨ cong (subst Fin (+-comm n m))\n (lookup-++-inject+ (tabulate {n} (id+ {n} ∘ raise m)) (tabulate {m} (id+ {n} ∘ inject+ n)) i) ⟩\n subst Fin (+-comm n m)\n (lookup i (tabulate (λ z → subst Fin (+-comm m n) (raise m z))))\n ≡⟨ subst-lookup-tabulate-raise i ⟩\n raise m i ∎) \n where open ≡-Reasoning\n\nswap+idemp : (m n : ℕ) → \n scompcauchy \n (swap+cauchy m n) \n (subst Cauchy (+-comm n m) (swap+cauchy n m))\n ≡ \n allFin (m + n)\nswap+idemp m n =\n let q = subst Cauchy (+-comm n m) (swap+cauchy n m) in\n begin \n (tabulate (λ i → lookup (lookup i (swap+cauchy m n)) q)\n ≡⟨ tabulate-split {m} {n} ⟩ \n tabulate {m} (λ i → lookup (lookup (inject+ n i) (swap+cauchy m n)) q)\n ++V\n tabulate {n} (λ i → lookup (lookup (raise m i) (swap+cauchy m n)) q)\n ≡⟨ cong₂ _++V_ (finext (swap+-left m n)) \n (finext (swap+-right m n)) ⟩\n tabulate {m} (inject+ n) ++V tabulate {n} (raise m)\n ≡⟨ unSplit {m} {n} id ⟩\n allFin (m + n) ∎)\n where open ≡-Reasoning\n\n-- Behaviour of parallel additive composition wrt sequential\n\n-- a direct proof is hard, but this is really a statement about vectors\n\nlookup-left : ∀ {m n} → (i : Fin m) → (pm : Cauchy m) → (pn : Cauchy n) → \n lookup (inject+ n i) (mapV (inject+ n) pm ++V mapV (raise m) pn) \n ≡ inject+ n (lookup i pm)\nlookup-left {m} {n} i pm pn = look-left i (inject+ n) (raise m) pm pn\n\n-- as is this\n\nlookup-right : ∀ {m n} → (i : Fin n) → (pm : Cauchy m) → (pn : Cauchy n) → \n lookup (raise m i) (mapV (inject+ n) pm ++V mapV (raise m) pn) \n ≡ raise m (lookup i pn)\nlookup-right {m} {n} i pm pn = look-right i (inject+ n) (raise m) pm pn\n\n--- find a better name\nlook-left' : ∀ {m n} → (pm qm : Cauchy m) → (pn qn : Cauchy n) → \n (i : Fin m) →\n (lookup (lookup (inject+ n i) (pcompcauchy pm pn)) (pcompcauchy qm qn))\n ≡ inject+ n (lookup (lookup i pm) qm)\nlook-left' {m} {n} pm qm pn qn i = \n let pp = pcompcauchy pm pn in\n let qq = pcompcauchy qm qn in\n begin (\n lookup (lookup (inject+ n i) pp) qq\n ≡⟨ cong (flip lookup qq) (lookup-++-inject+ (mapV (inject+ n) pm) (mapV (raise m) pn) i) ⟩\n lookup (lookup i (mapV (inject+ n) pm)) qq\n ≡⟨ cong (flip lookup qq) (lookup-map i (inject+ n) pm) ⟩\n lookup (inject+ n (lookup i pm)) qq\n ≡⟨ lookup-left (lookup i pm) qm qn ⟩\n inject+ n (lookup (lookup i pm) qm) ∎)\n where open ≡-Reasoning\n\nlook-right' : ∀ {m n} → (pm qm : Cauchy m) → (pn qn : Cauchy n) → \n (i : Fin n) →\n (lookup (lookup (raise m i) (pcompcauchy pm pn)) (pcompcauchy qm qn))\n ≡ raise m (lookup (lookup i pn) qn)\nlook-right' {m} {n} pm qm pn qn i = \n let pp = pcompcauchy pm pn in\n let qq = pcompcauchy qm qn in\n begin (\n lookup (lookup (raise m i) pp) qq\n ≡⟨ cong (flip lookup qq) (lookup-++-raise (mapV (inject+ n) pm) (mapV (raise m) pn) i) ⟩\n lookup (lookup i (mapV (raise m) pn)) qq\n ≡⟨ cong (flip lookup qq) (lookup-map i (raise m) pn) ⟩\n lookup (raise m (lookup i pn)) qq\n ≡⟨ lookup-right (lookup i pn) qm qn ⟩\n raise m (lookup (lookup i pn) qn) ∎)\n where open ≡-Reasoning\n\npcomp-dist : ∀ {m n} → (pm qm : Cauchy m) → (pn qn : Cauchy n) → \n scompcauchy (pcompcauchy pm pn) (pcompcauchy qm qn) ≡\n pcompcauchy (scompcauchy pm qm) (scompcauchy pn qn)\npcomp-dist {m} {n} pm qm pn qn =\n let pp = pcompcauchy pm pn in\n let qq = pcompcauchy qm qn in\n let look = λ i → lookup (lookup i pp) qq in\n begin (scompcauchy pp qq\n ≡⟨ refl ⟩\n tabulate look\n ≡⟨ tabulate-split {m} {n} ⟩\n splitV+ {m} {n} {f = look}\n ≡⟨ cong₂ _++V_ (finext {m} (look-left' pm qm pn qn)) \n (finext {n} (look-right' pm qm pn qn)) ⟩\n tabulate (λ i → (inject+ n) (lookup (lookup i pm) qm)) ++V\n tabulate (λ i → (raise m) (lookup (lookup i pn) qn))\n ≡⟨ cong₂ _++V_ \n (tabulate-∘ (inject+ n) (λ i → lookup (lookup i pm) qm)) \n (tabulate-∘ (raise m) (λ i → lookup (lookup i pn) qn)) ⟩ \n mapV (inject+ n) (tabulate (λ i → lookup (lookup i pm) qm)) ++V \n mapV (raise m) (tabulate (λ i → lookup (lookup i pn) qn))\n ≡⟨ refl ⟩\n pcompcauchy (scompcauchy pm qm) (scompcauchy pn qn) ∎)\n where open ≡-Reasoning\n\npcomp-id : ∀ {m n} → pcompcauchy (idcauchy m) (idcauchy n) ≡ idcauchy (m + n)\npcomp-id {m} {n} = \n begin (mapV (inject+ n) (idcauchy m) ++V (mapV (raise m) (idcauchy n))\n ≡⟨ refl ⟩\n mapV (inject+ n) (allFin m) ++V mapV (raise m) (allFin n)\n ≡⟨ cong₂ _++V_ \n (sym (tabulate-allFin {m} (inject+ n))) \n (sym (tabulate-allFin (raise m))) ⟩\n tabulate {m} (inject+ n) ++V tabulate {n} (raise m)\n ≡⟨ unSplit {m} {n} id ⟩\n idcauchy (m + n) ∎)\n where open ≡-Reasoning\n\n------------------------------------------------------------------------------\n", "meta": {"hexsha": "4e5ca69ac85377ebe74c629cc27caa542b5d5ce6", "size": 11142, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Univalence/Obsolete/CauchyProofs.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "Univalence/Obsolete/CauchyProofs.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "Univalence/Obsolete/CauchyProofs.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 42.3650190114, "max_line_length": 120, "alphanum_fraction": 0.5517860348, "num_tokens": 4249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5888891163376235, "lm_q2_score": 0.6076631698328917, "lm_q1q2_score": 0.35784622711381087}} {"text": "module Data.QuadTree.LensProofs.Valid-LensWrappedTree where\n\nopen import Haskell.Prelude renaming (zero to Z; suc to S)\nopen import Data.Lens.Lens\nopen import Data.Logic\nopen import Data.QuadTree.InternalAgda\nopen import Agda.Primitive\nopen import Data.Lens.Proofs.LensLaws\nopen import Data.Lens.Proofs.LensPostulates\nopen import Data.Lens.Proofs.LensComposition\nopen import Data.QuadTree.Implementation.QuadrantLenses\nopen import Data.QuadTree.Implementation.Definition\nopen import Data.QuadTree.Implementation.ValidTypes\nopen import Data.QuadTree.Implementation.SafeFunctions\nopen import Data.QuadTree.Implementation.PublicFunctions\nopen import Data.QuadTree.Implementation.DataLenses\n\n---- Lens laws for lensWrappedTree\n\nValidLens-WrappedTree-ViewSet : \n {t : Set} {{eqT : Eq t}} {dep : Nat}\n -> ViewSet (lensWrappedTree {t} {dep})\nValidLens-WrappedTree-ViewSet (CVQuadrant qdi) (CVQuadTree (Wrapper (w , h) qdo)) = refl\n\nValidLens-WrappedTree-SetView : \n {t : Set} {{eqT : Eq t}} {dep : Nat}\n -> SetView (lensWrappedTree {t} {dep})\nValidLens-WrappedTree-SetView (CVQuadTree (Wrapper (w , h) qdo)) = refl\n\nValidLens-WrappedTree-SetSet : \n {t : Set} {{eqT : Eq t}} {dep : Nat}\n -> SetSet (lensWrappedTree {t} {dep})\nValidLens-WrappedTree-SetSet (CVQuadrant qd1) (CVQuadrant qd2) (CVQuadTree (Wrapper (w , h) qdo)) = refl\n\nValidLens-WrappedTree :\n {t : Set} {{eqT : Eq t}} {dep : Nat}\n -> ValidLens (VQuadTree t {dep}) (VQuadrant t {dep})\nValidLens-WrappedTree = CValidLens lensWrappedTree (ValidLens-WrappedTree-ViewSet) (ValidLens-WrappedTree-SetView) (ValidLens-WrappedTree-SetSet)", "meta": {"hexsha": "33a9b3da0e8a2d4394c3c8dbffd4ba4c418d1788", "size": 1609, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Data/QuadTree/LensProofs/Valid-LensWrappedTree.agda", "max_stars_repo_name": "JonathanBrouwer/research-project", "max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z", "max_issues_repo_path": "src/Data/QuadTree/LensProofs/Valid-LensWrappedTree.agda", "max_issues_repo_name": "JonathanBrouwer/research-project", "max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_issues_repo_licenses": ["Unlicense"], "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/Data/QuadTree/LensProofs/Valid-LensWrappedTree.agda", "max_forks_repo_name": "JonathanBrouwer/research-project", "max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.3421052632, "max_line_length": 145, "alphanum_fraction": 0.7563704164, "num_tokens": 480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7154239957834733, "lm_q2_score": 0.5, "lm_q1q2_score": 0.35771199789173663}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Properties.Escape {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped\nopen import Definition.Typed\nopen import Definition.Typed.Weakening\nopen import Definition.Typed.Properties\nopen import Definition.LogicalRelation\n\nopen import Tools.Embedding\nopen import Tools.Product\nimport Tools.PropositionalEquality as PE\n\n\n-- Reducible types are well-formed.\nescape : ∀ {l Γ A} → Γ ⊩⟨ l ⟩ A → Γ ⊢ A\nescape (Uᵣ′ l′ l< ⊢Γ) = Uⱼ ⊢Γ\nescape (ℕᵣ [ ⊢A , ⊢B , D ]) = ⊢A\nescape (ne′ K [ ⊢A , ⊢B , D ] neK K≡K) = ⊢A\nescape (Πᵣ′ F G [ ⊢A , ⊢B , D ] ⊢F ⊢G A≡A [F] [G] G-ext) = ⊢A\nescape (emb′ 0<1 [A]) = escape [A]\n\n-- Reducible type equality respect the equality relation.\nescapeEq : ∀ {l Γ A B} → ([A] : Γ ⊩⟨ l ⟩ A)\n → Γ ⊩⟨ l ⟩ A ≡ B / [A]\n → Γ ⊢ A ≅ B\nescapeEq (Uᵣ′ l' l< ⊢Γ) (U₌ PE.refl) = ≅-Urefl ⊢Γ\nescapeEq (ℕᵣ [ ⊢A , ⊢B , D ]) (ιx (ℕ₌ D′)) = ≅-red D D′ ℕₙ ℕₙ (≅-ℕrefl (wf ⊢A))\nescapeEq (ne′ K D neK K≡K) (ιx (ne₌ M D′ neM K≡M)) = ≅-red (red D) (red D′) (ne neK) (ne neM) (~-to-≅ K≡M)\nescapeEq (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =\n ≅-red (red D) D′ Πₙ Πₙ A≡B\nescapeEq (emb′ 0<1 A) (ιx A≡B) = escapeEq A A≡B\n\n-- Reducible terms are well-formed.\nescapeTerm : ∀ {l Γ A t} → ([A] : Γ ⊩⟨ l ⟩ A)\n → Γ ⊩⟨ l ⟩ t ∷ A / [A]\n → Γ ⊢ t ∷ A\nescapeTerm (Uᵣ′ l′ l< ⊢Γ) (Uₜ A [ ⊢t , ⊢u , d ] typeA A≡A [A]) = ⊢t\nescapeTerm (ℕᵣ D) (ιx (ℕₜ n [ ⊢t , ⊢u , d ] t≡t prop)) =\n conv ⊢t (sym (subset* (red D)))\nescapeTerm (ne′ K D neK K≡K) (ιx (neₜ k [ ⊢t , ⊢u , d ] nf)) =\n conv ⊢t (sym (subset* (red D)))\nescapeTerm (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext)\n (f , [ ⊢t , ⊢u , d ] , funcF , f≡f , [f] , [f]₁) =\n conv ⊢t (sym (subset* (red D)))\nescapeTerm (emb′ 0<1 A) (ιx t) = escapeTerm A t\n\n-- Reducible term equality respect the equality relation.\nescapeTermEq : ∀ {l Γ A t u} → ([A] : Γ ⊩⟨ l ⟩ A)\n → Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]\n → Γ ⊢ t ≅ u ∷ A\nescapeTermEq (Uᵣ′ l′ l< ⊢Γ) (Uₜ₌ A B d d′ typeA typeB A≡B [A] [B] [A≡B]) =\n ≅ₜ-red (id (Uⱼ ⊢Γ)) (redₜ d) (redₜ d′) Uₙ (typeWhnf typeA) (typeWhnf typeB) A≡B\nescapeTermEq (ℕᵣ D) (ιx (ℕₜ₌ k k′ d d′ k≡k′ prop)) =\n let natK , natK′ = split prop\n in ≅ₜ-red (red D) (redₜ d) (redₜ d′) ℕₙ\n (naturalWhnf natK) (naturalWhnf natK′) k≡k′\nescapeTermEq (ne′ K D neK K≡K)\n (ιx (neₜ₌ k m d d′ (neNfₜ₌ neT neU t≡u))) =\n ≅ₜ-red (red D) (redₜ d) (redₜ d′) (ne neK) (ne neT) (ne neU)\n (~-to-≅ₜ t≡u)\nescapeTermEq (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext)\n (Πₜ₌ f g d d′ funcF funcG f≡g [f] [g] [f≡g]) =\n ≅ₜ-red (red D) (redₜ d) (redₜ d′) Πₙ (functionWhnf funcF) (functionWhnf funcG) f≡g\nescapeTermEq (emb′ 0<1 A) (ιx t≡u) = escapeTermEq A t≡u\n", "meta": {"hexsha": "71d571afa263d2d39326bc3953a889e38905a901", "size": 2851, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Properties/Escape.agda", "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Properties/Escape.agda", "max_issues_repo_name": "loic-p/logrel-mltt", "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Properties/Escape.agda", "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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.7285714286, "max_line_length": 106, "alphanum_fraction": 0.5327955103, "num_tokens": 1427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6406358411176238, "lm_q2_score": 0.5583269943353744, "lm_q1q2_score": 0.3576842836347173}} {"text": "------------------------------------------------------------------------\n-- An example showing that transitivity-like proofs that are not\n-- size-preserving can sometimes be used in a compositional way\n------------------------------------------------------------------------\n\n-- One can use the technique from \"Beating the Productivity Checker\n-- Using Embedded Languages\" to make it possible to use\n-- transitivity-like proofs that are not size-preserving in\n-- corecursive definitions. However, it is unclear if this is ever\n-- useful: the example presented below is rather contrived.\n\n{-# OPTIONS --sized-types #-}\n\nopen import Prelude\n\nmodule Delay-monad.Bisimilarity.Transitivity-constructor\n {a} {A : Type a} where\n\nopen import Equality.Propositional\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude.Size\n\nopen import Function-universe equality-with-J hiding (Kind)\n\nopen import Delay-monad\nopen import Delay-monad.Bisimilarity hiding (never≉now)\nopen import Delay-monad.Bisimilarity.Negative\n\n------------------------------------------------------------------------\n-- Proof programs\n\n-- There are two kinds of proof \"programs\", corresponding to strong\n-- and weak bisimilarity.\n\ndata Kind : Type where\n strong weak : Kind\n\nmutual\n\n -- Proof \"programs\".\n\n data Prog (i : Size) : Kind → Delay A ∞ → Delay A ∞ → Type a where\n\n -- Congruences.\n\n now : ∀ {k x} → Prog i k (now x) (now x)\n later : ∀ {k x y} →\n Prog′ i k (force x) (force y) →\n Prog i k (later x) (later y)\n\n -- Weak bisimilarity.\n\n laterʳ : ∀ {x y} → Prog i weak x (force y) → Prog i weak x (later y)\n laterˡ : ∀ {x y} → Prog i weak (force x) y → Prog i weak (later x) y\n\n -- Equational reasoning.\n --\n -- Note that if A is inhabited, then there is no size-preserving\n -- transitivity-like proof taking strong bisimilarity and weak\n -- bisimilarity to weak bisimilarity (see\n -- Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-∼≈ˡ⇔uninhabited).\n\n reflP : ∀ {k} x → Prog i k x x\n symP : ∀ {k x y} → Prog i k x y → Prog i k y x\n transP : ∀ {k x y z} →\n Prog i strong x y → Prog i k y z → Prog i k x z\n\n record Prog′ (i : Size) (k : Kind) (x y : Delay A ∞) : Type a where\n coinductive\n field\n force : {j : Size< i} → Prog j k x y\n\nopen Prog′ public\n\n------------------------------------------------------------------------\n-- Completeness\n\n-- Proof programs are complete with respect to strong and weak\n-- bisimilarity. Note that these proofs are size-preserving.\n\ncomplete-strong : ∀ {i x y} →\n [ i ] x ∼ y → Prog i strong x y\ncomplete-strong now = now\ncomplete-strong (later p) =\n later λ { .force → complete-strong (force p) }\n\ncomplete-weak : ∀ {i x y} → [ i ] x ≈ y → Prog i weak x y\ncomplete-weak now = now\ncomplete-weak (laterʳ p) = laterʳ (complete-weak p)\ncomplete-weak (laterˡ p) = laterˡ (complete-weak p)\ncomplete-weak (later p) =\n later λ { .force → complete-weak (force p) }\n\n------------------------------------------------------------------------\n-- Soundness\n\n-- Proof WHNFs.\n\ndata WHNF (i : Size) : Kind → Delay A ∞ → Delay A ∞ → Type a where\n now : ∀ {k x} → WHNF i k (now x) (now x)\n later : ∀ {k x y} →\n Prog′ i k (force x) (force y) →\n WHNF i k (later x) (later y)\n laterʳ : ∀ {x y} →\n WHNF i weak x (force y) → WHNF i weak x (later y)\n laterˡ : ∀ {x y} →\n WHNF i weak (force x) y → WHNF i weak (later x) y\n\n-- Reflexivity.\n\nreflW : ∀ {i k} x → WHNF i k x x\nreflW (now x) = now\nreflW (later x) = later λ { .force → reflP (force x) }\n\n-- Symmetry.\n\nsymW : ∀ {i k x y} → WHNF i k x y → WHNF i k y x\nsymW now = now\nsymW (later p) = later λ { .force → symP (force p) }\nsymW (laterʳ p) = laterˡ (symW p)\nsymW (laterˡ p) = laterʳ (symW p)\n\n-- Transitivity for strong WHNFs.\n\ntrans∼∼W : ∀ {i x y z} →\n WHNF i strong x y → WHNF i strong y z → WHNF i strong x z\ntrans∼∼W now q = q\ntrans∼∼W (later p) (later q) =\n later λ { .force → transP (force p) (force q) }\n\n-- Strong equality programs can be turned into WHNFs.\n\nwhnf∼ : ∀ {i x y} → Prog i strong x y → WHNF i strong x y\nwhnf∼ now = now\nwhnf∼ (later p) = later p\nwhnf∼ (reflP x) = reflW x\nwhnf∼ (symP p) = symW (whnf∼ p)\nwhnf∼ (transP p q) = trans∼∼W (whnf∼ p) (whnf∼ q)\n\n-- Strong proof programs are sound with respect to strong\n-- bisimilarity. Note that these proofs are size-preserving.\n\nmutual\n\n sound-strong : ∀ {i x y} →\n Prog i strong x y → [ i ] x ∼ y\n sound-strong p = soundW-strong (whnf∼ p)\n\n soundW-strong : ∀ {i x y} →\n WHNF i strong x y → [ i ] x ∼ y\n soundW-strong now = now\n soundW-strong (later p) =\n later λ { .force → sound-strong (force p) }\n\n-- Another transitivity lemma. This lemma cannot, in general, be made\n-- fully size-preserving (see not-fully-size-preserving below).\n\ntrans∼-W : ∀ {i k x y z} →\n WHNF ∞ strong x y → WHNF i k y z → WHNF i k x z\ntrans∼-W now q = q\ntrans∼-W p (laterʳ q) = laterʳ (trans∼-W p q)\ntrans∼-W (later p) (laterˡ q) = laterˡ (trans∼-W (whnf∼ (force p)) q)\ntrans∼-W (later p) (later q) =\n later λ { .force → transP (force p) (force q) }\n\n-- All fully defined programs can be turned into WHNFs.\n\nwhnf : ∀ {i k x y} → Prog ∞ k x y → WHNF i k x y\nwhnf now = now\nwhnf (later p) = later p\nwhnf (laterʳ p) = laterʳ (whnf p)\nwhnf (laterˡ p) = laterˡ (whnf p)\nwhnf (reflP x) = reflW x\nwhnf (symP p) = symW (whnf p)\nwhnf (transP p q) = trans∼-W (whnf p) (whnf q)\n\n-- Weak proof programs are sound with respect to weak bisimilarity.\n-- Note that these proofs are /not/ guaranteed to be size-preserving.\n\nmutual\n\n sound-weak : ∀ {i x y} → Prog ∞ weak x y → [ i ] x ≈ y\n sound-weak p = soundW-weak (whnf p)\n\n soundW-weak : ∀ {i x y} → WHNF ∞ weak x y → [ i ] x ≈ y\n soundW-weak now = now\n soundW-weak (laterʳ p) = laterʳ (soundW-weak p)\n soundW-weak (laterˡ p) = laterˡ (soundW-weak p)\n soundW-weak (later p) =\n later λ { .force → sound-weak (force p) }\n\n------------------------------------------------------------------------\n-- Some negative results\n\n-- The soundness proof for weak proof programs can be made\n-- size-preserving iff A is uninhabited.\n\nsize-preserving⇔uninhabited :\n (∀ {i x y} → Prog i weak x y → [ i ] x ≈ y) ⇔ ¬ A\nsize-preserving⇔uninhabited = record\n { to = (∀ {i x y} → Prog i weak x y → [ i ] x ≈ y) ↝⟨ (λ sound p q → sound (transP (complete-strong p) (complete-weak q))) ⟩\n Transitivity-∼≈ˡ ↝⟨ _⇔_.to size-preserving-transitivity-∼≈ˡ⇔uninhabited ⟩□\n ¬ A □\n ; from = ¬ A ↝⟨ uninhabited→trivial ⟩\n (∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _} _ → trivial _ _) ⟩□\n (∀ {i x y} → Prog i weak x y → [ i ] x ≈ y) □\n }\n\n-- The lemma trans∼-W cannot be made fully size-preserving (assuming\n-- that A is inhabited).\n\nnot-fully-size-preserving :\n (∀ {i k x y z} →\n WHNF i strong x y → WHNF i k y z → WHNF i k x z) →\n ¬ A\nnot-fully-size-preserving trans x = contradiction ∞\n where\n\n never≉now : ∀ {i} → ¬ WHNF i weak never (now x)\n never≉now (laterˡ p) = never≉now p\n\n mutual\n\n never≈now : ∀ {i} → WHNF i weak never (now x)\n never≈now =\n trans (later {y = record { force = now x }} never∼now)\n (laterˡ now)\n\n never∼now : ∀ {i} → Prog′ i strong never (now x)\n force never∼now {j = j} = ⊥-elim (contradiction j)\n\n contradiction : Size → ⊥\n contradiction i = never≉now (never≈now {i = i})\n\n-- One might wonder why the counterexample above cannot be adapted so\n-- that it also applies to programs, for which a size-preserving\n-- transitivity constructor exists. The following lemma documents one\n-- attempt at adapting the counterexample. Note that the new\n-- counterexample is based on the assumption that one can convert a\n-- strong bisimilarity program /of any size/ relating never and x to a\n-- proof that x is /equal/ to never.\n\npartially-adapted-counterexample :\n (∀ {i x} → Prog i strong never x → x ≡ never) →\n ¬ A\npartially-adapted-counterexample convert x = contradiction ∞\n where\n mutual\n\n now∼→≡now : ∀ {i x y} → Prog i strong (now x) y → y ≡ now x\n now∼→≡now now = refl\n now∼→≡now (reflP _) = refl\n now∼→≡now (symP p) = ∼now→≡now p\n now∼→≡now (transP p q) rewrite now∼→≡now p = now∼→≡now q\n\n ∼now→≡now : ∀ {i x y} → Prog i strong x (now y) → x ≡ now y\n ∼now→≡now now = refl\n ∼now→≡now (reflP _) = refl\n ∼now→≡now (symP p) = now∼→≡now p\n ∼now→≡now (transP p q) rewrite ∼now→≡now q = ∼now→≡now p\n\n mutual\n\n now≉Pnever : ∀ {i} → ¬ Prog i weak (now x) never\n now≉Pnever (laterʳ p) = now≉Pnever p\n now≉Pnever (symP p) = never≉Pnow p\n now≉Pnever (transP p q) rewrite now∼→≡now p = now≉Pnever q\n\n never≉Pnow : ∀ {i} → ¬ Prog i weak never (now x)\n never≉Pnow (laterˡ p) = never≉Pnow p\n never≉Pnow (symP p) = now≉Pnever p\n never≉Pnow (transP p q) rewrite convert p = never≉Pnow q\n\n mutual\n\n never≈Pnow : ∀ {i} → Prog i weak never (now x)\n never≈Pnow =\n transP (later {y = record { force = now x }} never∼Pnow)\n (laterˡ now)\n\n never∼Pnow : ∀ {i} → Prog′ i strong never (now x)\n force never∼Pnow {j = j} = ⊥-elim (contradiction j)\n\n contradiction : Size → ⊥\n contradiction i = never≉Pnow (never≈Pnow {i = i})\n\n------------------------------------------------------------------------\n-- A contrived example\n\n-- Note the use of a strong bisimilarity program of size i as the\n-- first argument to transitivity in the following example; this is\n-- not supported by transitive-∼ˡ, which requires the first argument\n-- to have size ∞.\n\nexampleP : ∀ {i} → Prog i weak never never\nexampleP {i} =\n transP (reflP {i = i} never) (later λ { .force → exampleP })\n\nexample : ∀ {i} → [ i ] never ≈ never\nexample = sound-weak exampleP\n\n-- However, note that the first argument could just as well have been\n-- given the size ∞, in which case transitive-∼ˡ works:\n\ncounterargument : ∀ {i} → [ i ] never ≈ never {A = A}\ncounterargument =\n transitive-∼ˡ (reflexive never)\n (later λ { .force → counterargument })\n\n-- Are there any applications in which strong and weak bisimilarities\n-- are proved simultaneously? One can observe that, if the first\n-- argument is never, then weak bisimilarity is contained in strong\n-- (in a size-preserving way), as witnessed by →∼-neverˡ. Perhaps one\n-- can find some compelling application of the technique presented\n-- above if it can be combined with a lemma like →∼-neverˡ. However,\n-- it is unclear if such a combination is possible: the soundness\n-- proof above relies on the fact that strong bisimilarity programs\n-- contain no weak bisimilarity programs (in particular, no\n-- transitivity proofs with a weak bisimilarity as the second\n-- argument).\n", "meta": {"hexsha": "cd1b21c0dd61332b3efe5ee686ae116fca62b6e9", "size": 11026, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Delay-monad/Bisimilarity/Transitivity-constructor.agda", "max_stars_repo_name": "nad/delay-monad", "max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Bisimilarity/Transitivity-constructor.agda", "max_issues_repo_name": "nad/delay-monad", "max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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/Delay-monad/Bisimilarity/Transitivity-constructor.agda", "max_forks_repo_name": "nad/delay-monad", "max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "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": 34.3489096573, "max_line_length": 129, "alphanum_fraction": 0.5845274805, "num_tokens": 3594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7090191337850933, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.35727911653749217}} {"text": "------------------------------------------------------------------------------\n-- All the Peano arithmetic modules\n------------------------------------------------------------------------------\n\n{-# OPTIONS --exact-split #-}\n{-# OPTIONS --no-sized-types #-}\n{-# OPTIONS --no-universe-polymorphism #-}\n{-# OPTIONS --without-K #-}\n\nmodule PA.Everything where\n\nopen import PA.Axiomatic.Mendelson.Base\nopen import PA.Axiomatic.Mendelson.Base.Consistency.Axioms\nopen import PA.Axiomatic.Mendelson.PropertiesATP\nopen import PA.Axiomatic.Mendelson.PropertiesI\nopen import PA.Axiomatic.Mendelson.Relation.Binary.EqReasoning\nopen import PA.Axiomatic.Mendelson.Relation.Binary.PropositionalEqualityI\nopen import PA.Axiomatic.Mendelson.Relation.Binary.PropositionalEqualityATP\n\nopen import PA.Axiomatic.Standard.Base\nopen import PA.Axiomatic.Standard.Base.Consistency.Axioms\nopen import PA.Axiomatic.Standard.PropertiesATP\nopen import PA.Axiomatic.Standard.PropertiesI\n\nopen import PA.Inductive.Base\nopen import PA.Inductive.Base.Core\nopen import PA.Inductive.Existential\nopen import PA.Inductive.PropertiesATP\nopen import PA.Inductive.PropertiesI\nopen import PA.Inductive.PropertiesByInduction\nopen import PA.Inductive.PropertiesByInductionATP\nopen import PA.Inductive.PropertiesByInductionI\nopen import PA.Inductive.Relation.Binary.EqReasoning\nopen import PA.Inductive.Relation.Binary.PropositionalEquality\n\nopen import PA.Inductive2Mendelson\nopen import PA.Inductive2Standard\n", "meta": {"hexsha": "988107def442b34f8f5de3568b1e7136fc063a28", "size": 1506, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/fot/PA/Everything.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": "src/fot/PA/Everything.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": "src/fot/PA/Everything.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": 39.6315789474, "max_line_length": 78, "alphanum_fraction": 0.729747676, "num_tokens": 331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7090191337850932, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.3572791165374921}} {"text": "------------------------------------------------------------------------\n-- A parametrised coinductive definition that can be used to define\n-- various forms of similarity\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nopen import Prelude\n\nopen import Labelled-transition-system\n\nmodule Similarity.General\n {ℓ}\n (lts : LTS ℓ)\n (open LTS lts)\n (_[_]↝_ : Proc → Label → Proc → Type ℓ)\n (⟶→↝ : ∀ {p μ q} → p [ μ ]⟶ q → p [ μ ]↝ q)\n where\n\nopen import Equality.Propositional as Eq hiding (Extensionality)\nopen import Prelude.Size\n\nopen import Bijection equality-with-J using (_↔_)\nopen import Function-universe equality-with-J hiding (id; _∘_)\n\nopen import Indexed-container hiding (⟨_⟩)\nopen import Relation\nopen import Similarity.Step lts _[_]↝_ as Step public\n using (StepC)\n\nopen Indexed-container public using (force)\nopen StepC public using (⟨_⟩; challenge)\n\n-- Similarity. Note that this definition is small.\n\ninfix 4 _≤_ _≤′_ [_]_≤_ [_]_≤′_\n\nSimilarity : Size → Rel₂ ℓ Proc\nSimilarity i = ν StepC i\n\nSimilarity′ : Size → Rel₂ ℓ Proc\nSimilarity′ i = ν′ StepC i\n\n[_]_≤_ : Size → Proc → Proc → Type ℓ\n[_]_≤_ i = curry (Similarity i)\n\n[_]_≤′_ : Size → Proc → Proc → Type ℓ\n[_]_≤′_ i = curry (Similarity′ i)\n\n_≤_ : Proc → Proc → Type ℓ\n_≤_ = [ ∞ ]_≤_\n\n_≤′_ : Proc → Proc → Type ℓ\n_≤′_ = [ ∞ ]_≤′_\n\n-- Similarity is reflexive.\n\nmutual\n\n reflexive-≤ : ∀ {p i} → [ i ] p ≤ p\n reflexive-≤ =\n StepC.⟨ (λ p⟶p′ → _ , ⟶→↝ p⟶p′ , reflexive-≤′)\n ⟩\n\n reflexive-≤′ : ∀ {p i} → [ i ] p ≤′ p\n force reflexive-≤′ = reflexive-≤\n\n≡⇒≤ : ∀ {p q} → p ≡ q → p ≤ q\n≡⇒≤ refl = reflexive-≤\n\n-- Functions that can be used to aid the instance resolution\n-- mechanism.\n\ninfix -2 ≤:_ ≤′:_\n\n≤:_ : ∀ {i p q} → [ i ] p ≤ q → [ i ] p ≤ q\n≤:_ = id\n\n≤′:_ : ∀ {i p q} → [ i ] p ≤′ q → [ i ] p ≤′ q\n≤′:_ = id\n\n-- Bisimilarity of similarity proofs.\n\ninfix 4 [_]_≡_ [_]_≡′_\n\n[_]_≡_ : ∀ {p q} → Size → (_ _ : ν StepC ∞ (p , q)) → Type ℓ\n[_]_≡_ i = curry (ν-bisimilar i)\n\n[_]_≡′_ : ∀ {p q} → Size → (_ _ : ν′ StepC ∞ (p , q)) → Type ℓ\n[_]_≡′_ i = curry (ν′-bisimilar i)\n\n-- An alternative characterisation of bisimilarity of similarity\n-- proofs.\n\n[]≡↔ :\n Eq.Extensionality ℓ ℓ →\n ∀ {p q} {i : Size} (p≤q₁ p≤q₂ : ν StepC ∞ (p , q)) →\n\n [ i ] p≤q₁ ≡ p≤q₂\n\n ↔\n\n (∀ {p′ μ} (p⟶p′ : p [ μ ]⟶ p′) →\n let q′₁ , q⟶q′₁ , p′≤q′₁ = StepC.challenge p≤q₁ p⟶p′\n q′₂ , q⟶q′₂ , p′≤q′₂ = StepC.challenge p≤q₂ p⟶p′\n in ∃ λ (q′₁≡q′₂ : q′₁ ≡ q′₂) →\n subst (q [ μ ]↝_) q′₁≡q′₂ q⟶q′₁ ≡ q⟶q′₂\n ×\n [ i ] subst (ν′ StepC ∞ ∘ (p′ ,_)) q′₁≡q′₂ p′≤q′₁ ≡′ p′≤q′₂)\n\n[]≡↔ ext {p} {q} {i} p≤q₁@(s₁ , f₁) p≤q₂@(s₂ , f₂) =\n [ i ] p≤q₁ ≡ p≤q₂ ↝⟨ ν-bisimilar↔ ext (s₁ , f₁) (s₂ , f₂) ⟩\n\n (∃ λ (eq : s₁ ≡ s₂) →\n ∀ {o} (p : Container.Position StepC s₁ o) →\n [ i ] f₁ p ≡′ f₂ (subst (λ s → Container.Position StepC s o) eq p)) ↝⟨ Step.⟦StepC⟧₂↔ ext (ν′-bisimilar i) p≤q₁ p≤q₂ ⟩□\n\n (∀ {p′ μ} (p⟶p′ : p [ μ ]⟶ p′) →\n let q′₁ , q⟶q′₁ , p′≤q′₁ = StepC.challenge p≤q₁ p⟶p′\n q′₂ , q⟶q′₂ , p′≤q′₂ = StepC.challenge p≤q₂ p⟶p′\n in ∃ λ (q′₁≡q′₂ : q′₁ ≡ q′₂) →\n subst (q [ μ ]↝_) q′₁≡q′₂ q⟶q′₁ ≡ q⟶q′₂\n ×\n [ i ] subst (ν′ StepC ∞ ∘ (p′ ,_)) q′₁≡q′₂ p′≤q′₁ ≡′ p′≤q′₂) □\n\n-- A statement of extensionality for similarity.\n\nExtensionality : Type ℓ\nExtensionality = ν′-extensionality StepC\n\n-- This form of extensionality can be used to derive another form (in\n-- the presence of extensionality for functions).\n\nextensionality :\n Eq.Extensionality ℓ ℓ →\n Extensionality →\n ∀ {p q} {p≤q₁ p≤q₂ : ν StepC ∞ (p , q)} →\n [ ∞ ] p≤q₁ ≡ p≤q₂ → p≤q₁ ≡ p≤q₂\nextensionality ext ν-ext = ν-extensionality ext ν-ext\n", "meta": {"hexsha": "a2a52a21b04b1307adca5a7a08a3fb840f807d73", "size": 3769, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Similarity/General.agda", "max_stars_repo_name": "nad/up-to", "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Similarity/General.agda", "max_issues_repo_name": "nad/up-to", "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Similarity/General.agda", "max_forks_repo_name": "nad/up-to", "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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": 26.9214285714, "max_line_length": 123, "alphanum_fraction": 0.5181745821, "num_tokens": 1626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.3571489006203413}} {"text": "{-# OPTIONS --without-K #-}\nmodule SimpleHoTT where\n\nopen import Data.Empty\nopen import Data.Sum renaming (map to _⊎→_)\nopen import Function renaming (_∘_ to _○_)\n\ninfixr 8 _∘_ -- path composition\ninfix 4 _≡_ -- propositional equality\ninfix 2 _∎ -- equational reasoning for paths\ninfixr 2 _≡⟨_⟩_ -- equational reasoning for paths\n\n------------------------------------------------------------------------------\n-- Equivalences a la HoTT (using HoTT paths and path induction)\n\n-- Our own version of refl that makes 'a' explicit\ndata _≡_ {ℓ} {A : Set ℓ} : (a b : A) → Set ℓ where\n refl : (a : A) → (a ≡ a)\n\n-- not sure where else to put this [Z]\nhetType : {A B : Set} → (a : A) → A ≡ B → B\nhetType a (refl _) = a\n \n-- J\npathInd : ∀ {u ℓ} → {A : Set u} → \n (C : {x y : A} → x ≡ y → Set ℓ) → \n (c : (x : A) → C (refl x)) → \n ({x y : A} (p : x ≡ y) → C p)\npathInd C c (refl x) = c x\n\nbasedPathInd : {A : Set} → (a : A) → (C : (x : A) → (a ≡ x) → Set) →\n C a (refl a) → ((x : A) (p : a ≡ x) → C x p) \nbasedPathInd a C c .a (refl .a) = c\n\n! : ∀ {u} → {A : Set u} {x y : A} → (x ≡ y) → (y ≡ x)\n! = pathInd (λ {x} {y} _ → y ≡ x) refl\n\n_∘_ : ∀ {u} → {A : Set u} → {x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)\n_∘_ {u} {A} {x} {y} {z} p q = \n pathInd {u}\n (λ {x} {y} p → ((z : A) → (q : y ≡ z) → (x ≡ z)))\n (λ x z q → pathInd (λ {x} {z} _ → x ≡ z) refl {x} {z} q)\n {x} {y} p z q\n\n-- p = p . refl\n\nunitTransR : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ p ∘ refl y) \nunitTransR {A} {x} {y} p = \n pathInd\n (λ {x} {y} p → p ≡ p ∘ (refl y)) \n (λ x → refl (refl x))\n {x} {y} p \n\n-- p = refl . p\n\nunitTransL : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ refl x ∘ p) \nunitTransL {A} {x} {y} p = \n pathInd\n (λ {x} {y} p → p ≡ (refl x) ∘ p)\n (λ x → refl (refl x))\n {x} {y} p \n\nap : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {x y : A} → \n (f : A → B) → (x ≡ y) → (f x ≡ f y)\nap {ℓ} {ℓ'} {A} {B} {x} {y} f p = \n pathInd -- on p\n (λ {x} {y} p → f x ≡ f y) \n (λ x → refl (f x))\n {x} {y} p\n\nap2 : ∀ {ℓ ℓ' ℓ''} → {A : Set ℓ} {B : Set ℓ'} {C : Set ℓ''} \n {x₁ y₁ : A} {x₂ y₂ : B} → \n (f : A → B → C) → (x₁ ≡ y₁) → (x₂ ≡ y₂) → (f x₁ x₂ ≡ f y₁ y₂)\nap2 {ℓ} {ℓ'} {ℓ''} {A} {B} {C} {x₁} {y₁} {x₂} {y₂} f p₁ p₂ = \n pathInd -- on p₁\n (λ {x₁} {y₁} p₁ → f x₁ x₂ ≡ f y₁ y₂) \n (λ x →\n pathInd -- on p₂\n (λ {x₂} {y₂} p₂ → f x x₂ ≡ f x y₂)\n (λ y → refl (f x y))\n {x₂} {y₂} p₂)\n {x₁} {y₁} p₁\n\n-- Abbreviations for path compositions\n\n_≡⟨_⟩_ : ∀ {u} → {A : Set u} (x : A) {y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)\n_ ≡⟨ p ⟩ q = p ∘ q\n\nbydef : ∀ {u} → {A : Set u} {x : A} → (x ≡ x)\nbydef {u} {A} {x} = refl x\n\n_∎ : ∀ {u} → {A : Set u} (x : A) → x ≡ x\n_∎ x = refl x\n\n-- Transport; Lifting\n\ntransport : ∀ {ℓ ℓ'} → {A : Set ℓ} {x y : A} → \n (P : A → Set ℓ') → (p : x ≡ y) → P x → P y\ntransport {ℓ} {ℓ'} {A} {x} {y} P p = \n pathInd -- on p\n (λ {x} {y} p → (P x → P y))\n (λ _ → id)\n {x} {y} p\n\n-- Lemma 2.3.10\n\ntransport-f : ∀ {ℓ ℓ' ℓ''} → {A : Set ℓ} {B : Set ℓ'} {x y : A} → \n (f : A → B) → (P : B → Set ℓ'') →\n (p : x ≡ y) → (u : P (f x)) → \n transport (P ○ f) p u ≡ transport P (ap f p) u\ntransport-f {ℓ} {ℓ'} {ℓ''} {A} {B} {x} {y} f P p u = \n pathInd -- on p\n (λ {x} {y} p → (u : P (f x)) → \n transport (P ○ f) p u ≡ transport P (ap f p) u)\n (λ x u → refl u)\n {x} {y} p u\n\n-- Lemma 2.11.2\n\ntransportIdR : {A : Set} {a y z : A} → (p : y ≡ z) → (q : a ≡ y) → \n transport (λ x → a ≡ x) p q ≡ q ∘ p\ntransportIdR {A} {a} {y} {z} p q = \n pathInd \n (λ {y} {z} p → (q : a ≡ y) → transport (λ x → a ≡ x) p q ≡ q ∘ p)\n (λ y q → transport (λ x → a ≡ x) (refl y) q \n ≡⟨ bydef ⟩\n q \n ≡⟨ unitTransR q ⟩\n q ∘ refl y ∎)\n {y} {z} p q\n\ntransportIdL : {A : Set} {a y z : A} → (p : y ≡ z) → (q : y ≡ a) → \n transport (λ x → x ≡ a) p q ≡ ! p ∘ q\ntransportIdL {A} {a} {y} {z} p q = \n pathInd \n (λ {y} {z} p → (q : y ≡ a) → transport (λ x → x ≡ a) p q ≡ ! p ∘ q)\n (λ y q → transport (λ x → x ≡ a) (refl y) q \n ≡⟨ bydef ⟩\n q \n ≡⟨ unitTransL q ⟩\n ! (refl y) ∘ q ∎)\n {y} {z} p q\n\ntransportIdRefl : {A : Set} {y z : A} → (p : y ≡ z) → (q : y ≡ y) → \n transport (λ x → x ≡ x) p q ≡ ! p ∘ q ∘ p\ntransportIdRefl {A} {y} {z} p q = \n pathInd \n (λ {y} {z} p → (q : y ≡ y) → transport (λ x → x ≡ x) p q ≡ ! p ∘ q ∘ p)\n (λ y q → transport (λ x → x ≡ x) (refl y) q \n ≡⟨ bydef ⟩\n q \n ≡⟨ unitTransR q ⟩\n q ∘ refl y\n ≡⟨ unitTransL (q ∘ refl y) ⟩\n ! (refl y) ∘ q ∘ refl y ∎)\n {y} {z} p q\n\n-- tools for coproducts (Sec. 2.12) \n\nindCP : {A B : Set} → (C : A ⊎ B → Set) → \n ((a : A) → C (inj₁ a)) → ((b : B) → C (inj₂ b)) → ((x : A ⊎ B) → C x)\nindCP C f g (inj₁ a) = f a\nindCP C f g (inj₂ b) = g b\n\ncode : {A B : Set} → (a₀ : A) → A ⊎ B → Set\ncode a₀ (inj₁ a) = a₀ ≡ a\ncode a₀ (inj₂ b) = ⊥ \n\nencode : {A B : Set} → (a₀ : A) → (x : A ⊎ B) → (p : inj₁ a₀ ≡ x) → code a₀ x\nencode {A} {B} a₀ x p = transport (code a₀) p (refl a₀)\n\ndecode : {A B : Set} → (a₀ : A) → (x : A ⊎ B) → (c : code a₀ x) → inj₁ a₀ ≡ x\ndecode a₀ (inj₁ a) c = ap inj₁ c \ndecode a₀ (inj₂ b) () \n", "meta": {"hexsha": "7391211816b721681a5face2901feb93eba0c14f", "size": 5243, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Univalence/OldUnivalence/SimpleHoTT.agda", "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_issues_repo_path": "Univalence/OldUnivalence/SimpleHoTT.agda", "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_forks_repo_path": "Univalence/OldUnivalence/SimpleHoTT.agda", "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "avg_line_length": 29.96, "max_line_length": 78, "alphanum_fraction": 0.4003433149, "num_tokens": 2592, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.3571400009701551}} {"text": "module Pi.NoRepeat where\nopen import Data.Empty\nopen import Data.Unit\nopen import Data.Sum\nopen import Data.Product\nopen import Relation.Binary.PropositionalEquality\nopen import Pi.Syntax\nopen import Pi.Opsem\nopen import Pi.AuxLemmas\nimport RevNoRepeat\n\n-- Forward deterministic\ndeterministic : ∀ {st st₁ st₂} → st ↦ st₁ → st ↦ st₂ → st₁ ≡ st₂\ndeterministic (↦₁ {b = b₁}) (↦₁ {b = b₂}) with base-is-prop _ b₁ b₂\n... | refl = refl\ndeterministic ↦₂ ↦₂ = refl\ndeterministic ↦₃ ↦₃ = refl\ndeterministic ↦₄ ↦₄ = refl\ndeterministic ↦₅ ↦₅ = refl\ndeterministic ↦₆ ↦₆ = refl\ndeterministic ↦₇ ↦₇ = refl\ndeterministic ↦₈ ↦₈ = refl\ndeterministic ↦₉ ↦₉ = refl\ndeterministic ↦₁₀ ↦₁₀ = refl\ndeterministic ↦₁₁ ↦₁₁ = refl\ndeterministic ↦₁₂ ↦₁₂ = refl\n\n-- Backward deterministic\ndeterministicᵣₑᵥ : ∀ {st st₁ st₂} → st₁ ↦ st → st₂ ↦ st → st₁ ≡ st₂\ndeterministicᵣₑᵥ {[ c ∣ _ ∣ κ ]} {⟨ c ∣ v ∣ κ ⟩} {⟨ c' ∣ v' ∣ κ' ⟩} ↦₁ r with Lemma₁ r\n... | refl , refl with Lemma₂ r\ndeterministicᵣₑᵥ {[ unite₊l ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ y ∣ κ ⟩} {⟨ _ ∣ inj₂ y ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ uniti₊l ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {⟨ _ ∣ v ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ swap₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ x ∣ κ ⟩} {⟨ _ ∣ inj₁ x ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ swap₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ y ∣ κ ⟩} {⟨ _ ∣ inj₂ y ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ x ∣ κ ⟩} {⟨ _ ∣ inj₁ x ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ x ∣ κ ⟩} {⟨ _ ∣ inj₂ (inj₁ y) ∣ κ ⟩} ↦₁ () | refl , refl | refl , refl\ndeterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ x ∣ κ ⟩} {⟨ _ ∣ inj₂ (inj₂ z) ∣ κ ⟩} ↦₁ () | refl , refl | refl , refl\ndeterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ (inj₁ y) ∣ κ ⟩} {⟨ _ ∣ inj₂ (inj₁ y) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ (inj₂ z) ∣ κ ⟩} {⟨ _ ∣ inj₂ (inj₂ z) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ (inj₁ x) ∣ κ ⟩} {⟨ _ ∣ inj₁ (inj₁ x) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ (inj₂ y) ∣ κ ⟩} {⟨ _ ∣ inj₁ (inj₂ y) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ z ∣ κ ⟩} {⟨ _ ∣ inj₁ (inj₁ x) ∣ κ ⟩} ↦₁ () | refl , refl | refl , refl\ndeterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ z ∣ κ ⟩} {⟨ _ ∣ inj₁ (inj₂ y) ∣ κ ⟩} ↦₁ () | refl , refl | refl , refl\ndeterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ z ∣ κ ⟩} {⟨ _ ∣ inj₂ z ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ unite⋆l ∣ _ ∣ κ ]} {⟨ _ ∣ (tt , v) ∣ κ ⟩} {⟨ _ ∣ (tt , v) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ uniti⋆l ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {⟨ _ ∣ v ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ swap⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ (x , y) ∣ κ ⟩} {⟨ _ ∣ (x , y) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ assocl⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ (x , (y , z)) ∣ κ ⟩} {⟨ _ ∣ (x , (y , z)) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ assocr⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ ((x , y) , z) ∣ κ ⟩} {⟨ _ ∣ ((x , y) , z) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ dist ∣ _ ∣ κ ]} {⟨ _ ∣ (inj₁ x , z) ∣ κ ⟩} {⟨ _ ∣ (inj₁ x , z) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ dist ∣ _ ∣ κ ]} {⟨ _ ∣ (inj₂ y , z) ∣ κ ⟩} {⟨ _ ∣ (inj₂ y , z) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ factor ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ (x , z) ∣ κ ⟩} {⟨ _ ∣ inj₁ (x , z) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ factor ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ (y , z) ∣ κ ⟩} {⟨ _ ∣ inj₂ (y , z) ∣ κ ⟩} ↦₁ ↦₁ | refl , refl | refl , refl = refl\ndeterministicᵣₑᵥ {[ unite₊l ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ uniti₊l ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ swap₊ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ unite⋆l ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ uniti⋆l ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ swap⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ assocl⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ assocr⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ dist ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ factor ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()\ndeterministicᵣₑᵥ {[ id↔ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} (↦₁ {b = ()})\ndeterministicᵣₑᵥ {[ c₁ ⨾ c₂ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} (↦₁ {b = ()})\ndeterministicᵣₑᵥ {[ c₁ ⊕ c₂ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} (↦₁ {b = ()})\ndeterministicᵣₑᵥ {[ c₁ ⊗ c₂ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} (↦₁ {b = ()})\ndeterministicᵣₑᵥ ↦₂ ↦₂ = refl\ndeterministicᵣₑᵥ ↦₃ ↦₃ = refl\ndeterministicᵣₑᵥ ↦₄ ↦₄ = refl\ndeterministicᵣₑᵥ ↦₅ ↦₅ = refl\ndeterministicᵣₑᵥ ↦₆ ↦₆ = refl\ndeterministicᵣₑᵥ ↦₇ ↦₇ = refl\ndeterministicᵣₑᵥ ↦₈ ↦₈ = refl\ndeterministicᵣₑᵥ ↦₉ ↦₉ = refl\ndeterministicᵣₑᵥ ↦₁₀ ↦₁₀ = refl\ndeterministicᵣₑᵥ {[ c₁ ⊕ c₂ ∣ inj₁ v ∣ κ ]} {_} {⟨ c₁' ⊕ c₂' ∣ v' ∣ κ' ⟩} ↦₁₁ r with Lemma₁ r\n... | refl , refl with Lemma₂ r\n... | refl , refl with Lemma₃ r\n... | inj₂ refl with Lemma₄ r\n... | inj₁ ()\n... | inj₂ ()\ndeterministicᵣₑᵥ {[ c₁ ⊕ c₂ ∣ inj₁ v ∣ κ ]} {[ c₁ ∣ v ∣ ☐⊕ c₂ • κ ]} {[ c₁ ∣ v ∣ ☐⊕ c₂ • κ ]} ↦₁₁ ↦₁₁ = refl\ndeterministicᵣₑᵥ {[ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ]} {[ c₂ ∣ y ∣ c₁ ⊕☐• κ ]} {⟨ c ∣ x ∣ x₁ ⟩} ↦₁₂ r with Lemma₁ r\n... | refl , refl with Lemma₂ r\n... | refl , refl with Lemma₃ r\n... | inj₂ refl with Lemma₄ r\n... | inj₂ ()\ndeterministicᵣₑᵥ {[ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ]} {[ c₂ ∣ y ∣ c₁ ⊕☐• κ ]} {[ c₂ ∣ y ∣ (c₁ ⊕☐• κ) ]} ↦₁₂ ↦₁₂ = refl\n\n-- Non-repeating Lemma\nopen RevNoRepeat (record { State = State\n ; _↦_ = _↦_\n ; deterministic = deterministic\n ; deterministicᵣₑᵥ = deterministicᵣₑᵥ }) public\n", "meta": {"hexsha": "0fd416dd4835797291f184fbf25a6681a43c8d0c", "size": 6565, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Pi/NoRepeat.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "Pi/NoRepeat.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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": "Pi/NoRepeat.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 66.3131313131, "max_line_length": 136, "alphanum_fraction": 0.4781416603, "num_tokens": 3914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7745833841649233, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.3570959370765473}} {"text": "module examplesPaperJFP.Sized where\n\nopen import Data.Product using (_×_; _,_)\nopen import Data.String\n\nopen import Function using (case_of_)\nopen import Size\n\nopen import examplesPaperJFP.NativeIOSafe\nopen import examplesPaperJFP.BasicIO using (IOInterface; Command; Response)\nopen import examplesPaperJFP.ConsoleInterface\nopen import examplesPaperJFP.Console using (translateIOConsoleLocal)\nopen import examplesPaperJFP.Object using (Interface; Method; Result;\n cellJ; CellMethod; get; put; CellResult)\n\n\nmodule UnfoldF where\n open import examplesPaperJFP.Coalgebra using (F; mapF)\n record νF (i : Size) : Set where\n coinductive\n constructor delay\n field force : ∀(j : Size< i) → F (νF j)\n\n open νF using (force)\n\n unfoldF : ∀{S} (t : S → F S) → ∀ i → (S → νF i)\n force (unfoldF t i s) j = mapF (unfoldF t j) (t s)\n\nmutual\n record IO (Iᵢₒ : IOInterface) (i : Size) (A : Set) : Set where\n coinductive\n\n constructor delay\n field force : {j : Size< i} → IO′ Iᵢₒ j A\n\n data IO′ (Iᵢₒ : IOInterface) (i : Size) (A : Set) : Set where\n exec′ : (c : Command Iᵢₒ) (f : Response Iᵢₒ c → IO Iᵢₒ i A) → IO′ Iᵢₒ i A\n return′ : (a : A) → IO′ Iᵢₒ i A\n\nmodule NestedRecursion (Iᵢₒ : IOInterface) (A : Set) where\n\n data F (X : Set) : Set where\n exec′ : (c : Command Iᵢₒ) (f : Response Iᵢₒ c → X) → F X\n return′ : (a : A) → F X\n\n record νF (i : Size) : Set where\n coinductive\n constructor delay\n field force : {j : Size< i} → F (νF j)\n\nopen IO public\n\nmodule _ {Iᵢₒ : IOInterface } (let C = Command Iᵢₒ) (let R = Response Iᵢₒ) where\n\n infixl 2 _>>=_\n\n exec : ∀ {i A} (c : C) (f : R c → IO Iᵢₒ i A) → IO Iᵢₒ i A\n return : ∀ {i A} (a : A) → IO Iᵢₒ i A\n _>>=_ : ∀ {i A B} (m : IO Iᵢₒ i A) (k : A → IO Iᵢₒ i B) → IO Iᵢₒ i B\n\n force (exec c f) = exec′ c f\n force (return a) = return′ a\n\n force (_>>=_ {i} m k) {j} with force m {j}\n ... | exec′ c f = exec′ c λ r → _>>=_ {j} (f r) k\n ... | return′ a = force (k a) {j}\n\n\n {-# NON_TERMINATING #-}\n translateIO : ∀{A : Set}\n → (translateLocal : (c : C) → NativeIO (R c))\n → IO Iᵢₒ ∞ A\n → NativeIO A\n translateIO translateLocal m = case (force m) of\n λ{ (exec′ c f) → (translateLocal c) native>>= λ r →\n translateIO translateLocal (f r)\n ; (return′ a) → nativeReturn a\n }\n\nrecord IOObject (Iᵢₒ : IOInterface) (I : Interface) (i : Size) : Set where\n coinductive\n field method : ∀{j : Size< i} (m : Method I)\n → IO Iᵢₒ ∞ (Result I m × IOObject Iᵢₒ I j)\n\n\nopen IOObject public\n\n\nCellC : (i : Size) → Set\nCellC = IOObject ConsoleInterface (cellJ String)\n\nsimpleCell : ∀{i} (s : String) → CellC i\nforce (method (simpleCell {i} s) {j} get) =\n exec′ (putStrLn (\"getting (\" ++ s ++ \")\")) λ _ →\n return (s , simpleCell {j} s)\nforce (method (simpleCell _) (put s)) =\n exec′ (putStrLn (\"putting (\" ++ s ++ \")\")) λ _ →\n return (unit , simpleCell s)\n\nprogram : ∀{i} → IO ConsoleInterface i Unit\nforce program =\n let c₁ = simpleCell \"Start\" in\n exec′ getLine λ{ nothing → return unit; (just s) →\n method c₁ (put s) >>= λ{ (_ , c₂) →\n method c₂ get >>= λ{ (s′ , c₃) →\n exec (putStrLn s′) λ _ →\n program }}}\n\n\nmain : NativeIO Unit\nmain = translateIO translateIOConsoleLocal program\n", "meta": {"hexsha": "732b3c3eaa4b06218aace3eeb231b5427b9ef703", "size": 3372, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "examples/examplesPaperJFP/Sized.agda", "max_stars_repo_name": "agda/ooAgda", "max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z", "max_issues_repo_path": "examples/examplesPaperJFP/Sized.agda", "max_issues_repo_name": "agda/ooAgda", "max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "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": "examples/examplesPaperJFP/Sized.agda", "max_forks_repo_name": "agda/ooAgda", "max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z", "avg_line_length": 30.1071428571, "max_line_length": 84, "alphanum_fraction": 0.5806642942, "num_tokens": 1248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7371581510799252, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.35706472734556016}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.Algebra.Group.Algebra where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Structure\nopen import Cubical.Foundations.Function using (_∘_)\nopen import Cubical.Foundations.GroupoidLaws\n\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.Unit\n\nopen import Cubical.Algebra.Group.Base\nopen import Cubical.Algebra.Group.Properties\nopen import Cubical.Algebra.Group.Morphism\nopen import Cubical.Algebra.Group.MorphismProperties\n\nopen import Cubical.HITs.PropositionalTruncation hiding (map)\n\nopen Iso\nopen GroupHom\n\nprivate\n variable\n ℓ ℓ' ℓ₁ ℓ₂ ℓ₃ : Level\n\n------- elementary properties of morphisms --------\n\nmodule _ (G : Group {ℓ}) (H : Group {ℓ'}) where\n\n module G = GroupStr (snd G)\n module H = GroupStr (snd H)\n\n -0≡0 : G.- G.0g ≡ G.0g\n -0≡0 = sym (G.lid _) ∙ G.invr _\n\n -- ϕ(0) ≡ 0\n morph0→0 : (f : GroupHom G H) → f .fun G.0g ≡ H.0g\n morph0→0 fh@(grouphom f _) =\n f G.0g ≡⟨ sym (H.rid _) ⟩\n f G.0g H.+ H.0g ≡⟨ (λ i → f G.0g H.+ H.invr (f G.0g) (~ i)) ⟩\n f G.0g H.+ (f G.0g H.- f G.0g) ≡⟨ H.assoc _ _ _ ⟩\n (f G.0g H.+ f G.0g) H.- f G.0g ≡⟨ sym (cong (λ x → x H.+ (H.- f G.0g))\n (sym (cong f (G.lid _)) ∙ isHom fh G.0g G.0g)) ⟩\n f G.0g H.- f G.0g ≡⟨ H.invr _ ⟩\n H.0g ∎\n\n -- ϕ(- x) = - ϕ(x)\n morphMinus : (f : GroupHom G H) → (g : ⟨ G ⟩) → f .fun (G.- g) ≡ H.- (f .fun g)\n morphMinus fc@(grouphom f fh) g =\n f (G.- g) ≡⟨ sym (H.rid _) ⟩\n f (G.- g) H.+ H.0g ≡⟨ cong (f (G.- g) H.+_) (sym (H.invr _)) ⟩\n f (G.- g) H.+ (f g H.- f g) ≡⟨ H.assoc _ _ _ ⟩\n (f (G.- g) H.+ f g) H.- f g ≡⟨ cong (H._+ (H.- f g)) helper ⟩\n H.0g H.- f g ≡⟨ H.lid _ ⟩\n H.- f g ∎\n where\n helper : f (G.- g) H.+ f g ≡ H.0g\n helper = sym (fh (G.- g) g) ∙∙ cong f (G.invl g) ∙∙ morph0→0 fc\n\n\n-- ----------- Alternative notions of isomorphisms --------------\nrecord GroupIso {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where\n\n constructor iso\n field\n map : GroupHom G H\n inv : ⟨ H ⟩ → ⟨ G ⟩\n rightInv : section (GroupHom.fun map) inv\n leftInv : retract (GroupHom.fun map) inv\n\nrecord BijectionIso {ℓ ℓ'} (A : Group {ℓ}) (B : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where\n\n constructor bij-iso\n field\n map' : GroupHom A B\n inj : isInjective A B map'\n surj : isSurjective A B map'\n\n-- \"Very\" short exact sequences\n-- i.e. an exact sequence A → B → C → D where A and D are trivial\nrecord vSES {ℓ ℓ' ℓ'' ℓ'''} (A : Group {ℓ}) (B : Group {ℓ'}) (leftGr : Group {ℓ''}) (rightGr : Group {ℓ'''})\n : Type (ℓ-suc (ℓ-max ℓ (ℓ-max ℓ' (ℓ-max ℓ'' ℓ''')))) where\n\n constructor ses\n field\n isTrivialLeft : isProp ⟨ leftGr ⟩\n isTrivialRight : isProp ⟨ rightGr ⟩\n\n left : GroupHom leftGr A\n right : GroupHom B rightGr\n ϕ : GroupHom A B\n\n Ker-ϕ⊂Im-left : (x : ⟨ A ⟩)\n → isInKer A B ϕ x\n → isInIm leftGr A left x\n Ker-right⊂Im-ϕ : (x : ⟨ B ⟩)\n → isInKer B rightGr right x\n → isInIm A B ϕ x\n\nopen BijectionIso\nopen GroupIso\nopen vSES\n\nIso+Hom→GrIso : {G : Group {ℓ}} {H : Group {ℓ₁}} → (e : Iso ⟨ G ⟩ ⟨ H ⟩) → isGroupHom G H (Iso.fun e) → GroupIso G H\nfun (map (Iso+Hom→GrIso e hom)) = Iso.fun e\nisHom (map (Iso+Hom→GrIso e hom)) = hom\ninv (Iso+Hom→GrIso e hom) = Iso.inv e\nrightInv (Iso+Hom→GrIso e hom) = Iso.rightInv e\nleftInv (Iso+Hom→GrIso e hom) = Iso.leftInv e\n\ncompGroupIso : {G : Group {ℓ}} {H : Group {ℓ₁}} {A : Group {ℓ₂}} → GroupIso G H → GroupIso H A → GroupIso G A\nmap (compGroupIso iso1 iso2) = compGroupHom (map iso1) (map iso2)\ninv (compGroupIso iso1 iso2) = inv iso1 ∘ inv iso2\nrightInv (compGroupIso iso1 iso2) a = cong (fun (map iso2)) (rightInv iso1 _) ∙ rightInv iso2 a\nleftInv (compGroupIso iso1 iso2) a = cong (inv iso1) (leftInv iso2 _) ∙ leftInv iso1 a\n\nisGroupHomInv' : {G : Group {ℓ}} {H : Group {ℓ₁}} (f : GroupIso G H) → isGroupHom H G (inv f)\nisGroupHomInv' {G = G} {H = H} f h h' = isInj-f _ _ (\n f' (g (h ⋆² h')) ≡⟨ (rightInv f) _ ⟩\n (h ⋆² h') ≡⟨ sym (cong₂ _⋆²_ (rightInv f h) (rightInv f h')) ⟩\n (f' (g h) ⋆² f' (g h')) ≡⟨ sym (isHom (map f) _ _) ⟩\n f' (g h ⋆¹ g h') ∎)\n where\n f' = fun (map f)\n _⋆¹_ = GroupStr._+_ (snd G)\n _⋆²_ = GroupStr._+_ (snd H)\n g = inv f\n\n isInj-f : (x y : ⟨ G ⟩) → f' x ≡ f' y → x ≡ y\n isInj-f x y p = sym (leftInv f _) ∙∙ cong g p ∙∙ leftInv f _\n\ninvGroupIso : {G : Group {ℓ}} {H : Group {ℓ₁}} → GroupIso G H → GroupIso H G\nfun (map (invGroupIso iso1)) = inv iso1\nisHom (map (invGroupIso iso1)) = isGroupHomInv' iso1\ninv (invGroupIso iso1) = fun (map iso1)\nrightInv (invGroupIso iso1) = leftInv iso1\nleftInv (invGroupIso iso1) = rightInv iso1\n\ndirProdGroupIso : {G : Group {ℓ}} {H : Group {ℓ₁}} {A : Group {ℓ₂}} {B : Group {ℓ₃}}\n → GroupIso G H → GroupIso A B → GroupIso (dirProd G A) (dirProd H B)\nfun (map (dirProdGroupIso iso1 iso2)) prod = fun (map iso1) (fst prod) , fun (map iso2) (snd prod)\nisHom (map (dirProdGroupIso iso1 iso2)) a b = ΣPathP (isHom (map iso1) (fst a) (fst b) , isHom (map iso2) (snd a) (snd b))\ninv (dirProdGroupIso iso1 iso2) prod = (inv iso1) (fst prod) , (inv iso2) (snd prod)\nrightInv (dirProdGroupIso iso1 iso2) a = ΣPathP (rightInv iso1 (fst a) , (rightInv iso2 (snd a)))\nleftInv (dirProdGroupIso iso1 iso2) a = ΣPathP (leftInv iso1 (fst a) , (leftInv iso2 (snd a)))\n\nGrIsoToGrEquiv : {G : Group {ℓ}} {H : Group {ℓ₂}} → GroupIso G H → GroupEquiv G H\nGroupEquiv.eq (GrIsoToGrEquiv i) = isoToEquiv (iso (fun (map i)) (inv i) (rightInv i) (leftInv i))\nGroupEquiv.isHom (GrIsoToGrEquiv i) = isHom (map i)\n\n--- Proofs that BijectionIso and vSES both induce isomorphisms ---\nBijectionIsoToGroupIso : {A : Group {ℓ}} {B : Group {ℓ'}} → BijectionIso A B → GroupIso A B\nBijectionIsoToGroupIso {A = A} {B = B} i = grIso\n where\n module A = GroupStr (snd A)\n module B = GroupStr (snd B)\n f = fun (map' i)\n\n helper : (b : _) → isProp (Σ[ a ∈ ⟨ A ⟩ ] f a ≡ b)\n helper _ a b =\n Σ≡Prop (λ _ → isSetCarrier B _ _)\n (fst a ≡⟨ sym (A.rid _) ⟩\n fst a A.+ A.0g ≡⟨ cong (fst a A.+_) (sym (A.invl _)) ⟩\n fst a A.+ ((A.- fst b) A.+ fst b) ≡⟨ A.assoc _ _ _ ⟩\n (fst a A.- fst b) A.+ fst b ≡⟨ cong (A._+ fst b) idHelper ⟩\n A.0g A.+ fst b ≡⟨ A.lid _ ⟩\n fst b ∎)\n where\n idHelper : fst a A.- fst b ≡ A.0g\n idHelper =\n inj i _\n (isHom (map' i) (fst a) (A.- (fst b))\n ∙ (cong (f (fst a) B.+_) (morphMinus A B (map' i) (fst b))\n ∙∙ cong (B._+ (B.- f (fst b))) (snd a ∙ sym (snd b))\n ∙∙ B.invr (f (fst b))))\n\n grIso : GroupIso A B\n map grIso = map' i\n inv grIso b = (rec (helper b) (λ a → a) (surj i b)) .fst\n rightInv grIso b = (rec (helper b) (λ a → a) (surj i b)) .snd\n leftInv grIso b j = rec (helper (f b)) (λ a → a) (propTruncIsProp (surj i (f b)) ∣ b , refl ∣ j) .fst\n\nBijectionIsoToGroupEquiv : {A : Group {ℓ}} {B : Group {ℓ₂}} → BijectionIso A B → GroupEquiv A B\nBijectionIsoToGroupEquiv i = GrIsoToGrEquiv (BijectionIsoToGroupIso i)\n\nvSES→GroupIso : ∀ {ℓ ℓ' ℓ'' ℓ'''} {A : Group {ℓ}} {B : Group {ℓ'}} (leftGr : Group {ℓ''}) (rightGr : Group {ℓ'''})\n → vSES A B leftGr rightGr\n → GroupIso A B\nvSES→GroupIso {A = A} lGr rGr vses = BijectionIsoToGroupIso theIso\n where\n theIso : BijectionIso _ _\n map' theIso = vSES.ϕ vses\n inj theIso a inker = rec (isSetCarrier A _ _)\n (λ (a , p) → sym p\n ∙∙ cong (fun (left vses)) (isTrivialLeft vses a _)\n ∙∙ morph0→0 lGr A (left vses))\n (Ker-ϕ⊂Im-left vses a inker)\n surj theIso a = Ker-right⊂Im-ϕ vses a (isTrivialRight vses _ _)\n\nvSES→GroupEquiv : {A : Group {ℓ}} {B : Group {ℓ₁}} (leftGr : Group {ℓ₂}) (rightGr : Group {ℓ₃})\n → vSES A B leftGr rightGr\n → GroupEquiv A B\nvSES→GroupEquiv {A = A} lGr rGr vses = GrIsoToGrEquiv (vSES→GroupIso lGr rGr vses)\n\n-- The trivial group is a unit.\nlUnitGroupIso : ∀ {ℓ} {G : Group {ℓ}} → GroupIso (dirProd trivialGroup G) G\nfun (map lUnitGroupIso) = snd\nisHom (map lUnitGroupIso) _ _ = refl\ninv lUnitGroupIso g = tt , g\nrightInv lUnitGroupIso _ = refl\nleftInv lUnitGroupIso _ = refl\n\nrUnitGroupIso : ∀ {ℓ} {G : Group {ℓ}} → GroupIso (dirProd G trivialGroup) G\nfun (map rUnitGroupIso) = fst\nisHom (map rUnitGroupIso) _ _ = refl\ninv rUnitGroupIso g = g , tt\nrightInv rUnitGroupIso _ = refl\nleftInv rUnitGroupIso _ = refl\n\nlUnitGroupEquiv : ∀ {ℓ} {G : Group {ℓ}} → GroupEquiv (dirProd trivialGroup G) G\nlUnitGroupEquiv = GrIsoToGrEquiv lUnitGroupIso\n\nrUnitGroupEquiv : ∀ {ℓ} {G : Group {ℓ}} → GroupEquiv (dirProd G trivialGroup) G\nrUnitGroupEquiv = GrIsoToGrEquiv rUnitGroupIso\n\nIsoContrGroupTrivialGroup : {G : Group {ℓ}} → isContr ⟨ G ⟩ → GroupIso G trivialGroup\nfun (map (IsoContrGroupTrivialGroup contr)) _ = tt\nisHom (map (IsoContrGroupTrivialGroup contr)) _ _ = refl\ninv (IsoContrGroupTrivialGroup contr) x = fst contr\nrightInv (IsoContrGroupTrivialGroup contr) x = refl\nleftInv (IsoContrGroupTrivialGroup contr) x = snd contr x\n\ncontrGroup≅trivialGroup : {G : Group {ℓ}} → isContr ⟨ G ⟩ → GroupEquiv G trivialGroup\ncontrGroup≅trivialGroup contr = GrIsoToGrEquiv (IsoContrGroupTrivialGroup contr)\n\nGroupIso→Iso : {A : Group {ℓ}} {B : Group {ℓ₁}} → GroupIso A B → Iso ⟨ A ⟩ ⟨ B ⟩\nfun (GroupIso→Iso i) = fun (map i)\ninv (GroupIso→Iso i) = inv i\nrightInv (GroupIso→Iso i) = rightInv i\nleftInv (GroupIso→Iso i) = leftInv i\n\ncongIdLeft≡congIdRight : {A : Type ℓ} (_+A_ : A → A → A) (-A_ : A → A)\n (0A : A)\n (rUnitA : (x : A) → x +A 0A ≡ x)\n (lUnitA : (x : A) → 0A +A x ≡ x)\n → (r≡l : rUnitA 0A ≡ lUnitA 0A)\n → (p : 0A ≡ 0A) →\n cong (0A +A_) p ≡ cong (_+A 0A) p\ncongIdLeft≡congIdRight _+A_ -A_ 0A rUnitA lUnitA r≡l p =\n rUnit (cong (0A +A_) p)\n ∙∙ ((λ i → (λ j → lUnitA 0A (i ∧ j)) ∙∙ cong (λ x → lUnitA x i) p ∙∙ λ j → lUnitA 0A (i ∧ ~ j))\n ∙∙ cong₂ (λ x y → x ∙∙ p ∙∙ y) (sym r≡l) (cong sym (sym r≡l))\n ∙∙ λ i → (λ j → rUnitA 0A (~ i ∧ j)) ∙∙ cong (λ x → rUnitA x (~ i)) p ∙∙ λ j → rUnitA 0A (~ i ∧ ~ j))\n ∙∙ sym (rUnit (cong (_+A 0A) p))\n", "meta": {"hexsha": "1deae02bfeaaf1bb7f4ce390efa59210b7c5221d", "size": 10457, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/Group/Algebra.agda", "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/Algebra/Group/Algebra.agda", "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_forks_repo_path": "Cubical/Algebra/Group/Algebra.agda", "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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.6887159533, "max_line_length": 122, "alphanum_fraction": 0.5733958114, "num_tokens": 4189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.35679852250805627}} {"text": "{-\n\nDescriptor language for easily defining relational structures\n\n-}\n{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}\nmodule Cubical.Structures.Relational.Macro where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Structure\nopen import Cubical.Foundations.RelationalStructure\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Structures.Relational.Constant\nopen import Cubical.Structures.Relational.Function\nopen import Cubical.Structures.Relational.Maybe\nopen import Cubical.Structures.Relational.Parameterized\nopen import Cubical.Structures.Relational.Pointed\nopen import Cubical.Structures.Relational.Product\n\nopen import Cubical.Structures.Macro\nopen import Cubical.Structures.Maybe\n\ndata PosRelDesc (ℓ : Level) : Typeω where\n -- constant structure: X ↦ A\n constant : ∀ {ℓ'} → hSet ℓ' → PosRelDesc ℓ\n -- pointed structure: X ↦ X\n var : PosRelDesc ℓ\n -- product of structures S,T : X ↦ (S X × T X)\n _,_ : PosRelDesc ℓ → PosRelDesc ℓ → PosRelDesc ℓ\n -- Maybe on a structure S: X ↦ Maybe (S X)\n maybe : PosRelDesc ℓ → PosRelDesc ℓ\n\ndata RelDesc (ℓ : Level) : Typeω where\n -- constant structure: X ↦ A\n constant : ∀ {ℓ'} → hSet ℓ' → RelDesc ℓ\n -- pointed structure: X ↦ X\n var : RelDesc ℓ\n -- product of structures S,T : X ↦ (S X × T X)\n _,_ : RelDesc ℓ → RelDesc ℓ → RelDesc ℓ\n -- structure S parameterized by constant A : X ↦ (A → S X)\n param : ∀ {ℓ'} → (A : Type ℓ') → RelDesc ℓ → RelDesc ℓ\n -- function from positive structure S to T: X ↦ (S X → T X)\n function+ : PosRelDesc ℓ → RelDesc ℓ → RelDesc ℓ\n -- Maybe on a structure S: X ↦ Maybe (S X)\n maybe : RelDesc ℓ → RelDesc ℓ\n\ninfixr 4 _,_\n\nposRelDesc→TranspDesc : ∀ {ℓ} → PosRelDesc ℓ → TranspDesc ℓ\nposRelDesc→TranspDesc (constant A) = constant (A .fst)\nposRelDesc→TranspDesc var = var\nposRelDesc→TranspDesc (d₀ , d₁) = posRelDesc→TranspDesc d₀ , posRelDesc→TranspDesc d₁\nposRelDesc→TranspDesc (maybe d) = maybe (posRelDesc→TranspDesc d)\n\nposRelDesc→RelDesc : ∀ {ℓ} → PosRelDesc ℓ → RelDesc ℓ\nposRelDesc→RelDesc (constant A) = constant A\nposRelDesc→RelDesc var = var\nposRelDesc→RelDesc (d₀ , d₁) = posRelDesc→RelDesc d₀ , posRelDesc→RelDesc d₁\nposRelDesc→RelDesc (maybe d) = maybe (posRelDesc→RelDesc d)\n\nrelDesc→Desc : ∀ {ℓ} → RelDesc ℓ → Desc ℓ\nrelDesc→Desc (constant A) = constant (A .fst)\nrelDesc→Desc var = var\nrelDesc→Desc (d₀ , d₁) = relDesc→Desc d₀ , relDesc→Desc d₁\nrelDesc→Desc (param A d) = function+ (constant A) (relDesc→Desc d)\nrelDesc→Desc (function+ d₀ d₁) = function+ (posRelDesc→TranspDesc d₀) (relDesc→Desc d₁)\nrelDesc→Desc (maybe d) = maybe (relDesc→Desc d)\n\n{- Universe level calculations -}\n\nposRelMacroStrLevel : ∀ {ℓ} → PosRelDesc ℓ → Level\nposRelMacroStrLevel d = transpMacroLevel (posRelDesc→TranspDesc d)\n\nrelMacroStrLevel : ∀ {ℓ} → RelDesc ℓ → Level\nrelMacroStrLevel d = macroStrLevel (relDesc→Desc d)\n\nposRelMacroRelLevel : ∀ {ℓ} → PosRelDesc ℓ → Level\nposRelMacroRelLevel (constant {ℓ'} A) = ℓ'\nposRelMacroRelLevel {ℓ} var = ℓ\nposRelMacroRelLevel (d₀ , d₁) = ℓ-max (posRelMacroRelLevel d₀) (posRelMacroRelLevel d₁)\nposRelMacroRelLevel (maybe d) = posRelMacroRelLevel d\n\nrelMacroRelLevel : ∀ {ℓ} → RelDesc ℓ → Level\nrelMacroRelLevel (constant {ℓ'} A) = ℓ'\nrelMacroRelLevel {ℓ} var = ℓ\nrelMacroRelLevel (d₀ , d₁) = ℓ-max (relMacroRelLevel d₀) (relMacroRelLevel d₁)\nrelMacroRelLevel (param {ℓ'} A d) = ℓ-max ℓ' (relMacroRelLevel d)\nrelMacroRelLevel (function+ d₀ d₁) =\n ℓ-max (posRelMacroStrLevel d₀) (ℓ-max (posRelMacroRelLevel d₀) (relMacroRelLevel d₁))\nrelMacroRelLevel (maybe d) = relMacroRelLevel d\n\n{- Definition of structure -}\n\nPosRelMacroStructure : ∀ {ℓ} (d : PosRelDesc ℓ) → Type ℓ → Type (posRelMacroStrLevel d)\nPosRelMacroStructure d = TranspMacroStructure (posRelDesc→TranspDesc d)\n\nRelMacroStructure : ∀ {ℓ} (d : RelDesc ℓ) → Type ℓ → Type (relMacroStrLevel d)\nRelMacroStructure d = MacroStructure (relDesc→Desc d)\n\n{- Notion of structured relation defined by a descriptor -}\n\nPosRelMacroRelStr : ∀ {ℓ} (d : PosRelDesc ℓ) → StrRel {ℓ} (PosRelMacroStructure d) (posRelMacroRelLevel d)\nPosRelMacroRelStr (constant A) = ConstantRelStr A\nPosRelMacroRelStr var = PointedRelStr\nPosRelMacroRelStr (d₀ , d₁) = ProductRelStr (PosRelMacroRelStr d₀) (PosRelMacroRelStr d₁)\nPosRelMacroRelStr (maybe d) = MaybeRelStr (PosRelMacroRelStr d)\n\nRelMacroRelStr : ∀ {ℓ} (d : RelDesc ℓ) → StrRel {ℓ} (RelMacroStructure d) (relMacroRelLevel d)\nRelMacroRelStr (constant A) = ConstantRelStr A\nRelMacroRelStr var = PointedRelStr\nRelMacroRelStr (d₀ , d₁) = ProductRelStr (RelMacroRelStr d₀) (RelMacroRelStr d₁)\nRelMacroRelStr (param A d) = ParamRelStr A (λ _ → RelMacroRelStr d)\nRelMacroRelStr (function+ d₀ d₁) =\n FunctionRelStr (PosRelMacroRelStr d₀) (RelMacroRelStr d₁)\nRelMacroRelStr (maybe d) = MaybeRelStr (RelMacroRelStr d)\n\n{- Proof that structure induced by descriptor is suitable or positive -}\n\nposRelMacroSuitableRel : ∀ {ℓ} (d : PosRelDesc ℓ) → SuitableStrRel _ (PosRelMacroRelStr d)\nposRelMacroSuitableRel (constant A) = constantSuitableRel A\nposRelMacroSuitableRel var = pointedSuitableRel\nposRelMacroSuitableRel (d₀ , d₁) =\n productSuitableRel (posRelMacroSuitableRel d₀) (posRelMacroSuitableRel d₁)\nposRelMacroSuitableRel (maybe d) = maybeSuitableRel (posRelMacroSuitableRel d)\n\nposRelMacroPositiveRel : ∀ {ℓ} (d : PosRelDesc ℓ) → PositiveStrRel (posRelMacroSuitableRel d)\nposRelMacroPositiveRel (constant A) = constantPositiveRel A\nposRelMacroPositiveRel var = pointedPositiveRel\nposRelMacroPositiveRel (d₀ , d₁) =\n productPositiveRel (posRelMacroPositiveRel d₀) (posRelMacroPositiveRel d₁)\nposRelMacroPositiveRel (maybe d) = maybePositiveRel (posRelMacroPositiveRel d)\n\nrelMacroSuitableRel : ∀ {ℓ} (d : RelDesc ℓ) → SuitableStrRel _ (RelMacroRelStr d)\nrelMacroSuitableRel (constant A) = constantSuitableRel A\nrelMacroSuitableRel var = pointedSuitableRel\nrelMacroSuitableRel (d₀ , d₁) = productSuitableRel (relMacroSuitableRel d₀) (relMacroSuitableRel d₁)\nrelMacroSuitableRel (param A d) = paramSuitableRel A (λ _ → relMacroSuitableRel d)\nrelMacroSuitableRel (function+ d₀ d₁) =\n functionSuitableRel (posRelMacroSuitableRel d₀) (posRelMacroPositiveRel d₀) (relMacroSuitableRel d₁)\nrelMacroSuitableRel (maybe d) = maybeSuitableRel (relMacroSuitableRel d)\n\n{- Proof that structured relations and equivalences agree -}\n\nposRelMacroMatchesEquiv : ∀ {ℓ} (d : PosRelDesc ℓ)\n → StrRelMatchesEquiv (PosRelMacroRelStr d) (EquivAction→StrEquiv (transpMacroAction (posRelDesc→TranspDesc d)))\nposRelMacroMatchesEquiv (constant A) _ _ _ = idEquiv _\nposRelMacroMatchesEquiv var _ _ _ = idEquiv _\nposRelMacroMatchesEquiv (d₀ , d₁) =\n productRelMatchesTransp\n (PosRelMacroRelStr d₀) (transpMacroAction (posRelDesc→TranspDesc d₀))\n (PosRelMacroRelStr d₁) (transpMacroAction (posRelDesc→TranspDesc d₁))\n (posRelMacroMatchesEquiv d₀) (posRelMacroMatchesEquiv d₁)\nposRelMacroMatchesEquiv (maybe d) =\n maybeRelMatchesTransp\n (PosRelMacroRelStr d) (transpMacroAction (posRelDesc→TranspDesc d))\n (posRelMacroMatchesEquiv d)\n\nrelMacroMatchesEquiv : ∀ {ℓ} (d : RelDesc ℓ)\n → StrRelMatchesEquiv (RelMacroRelStr d) (MacroEquivStr (relDesc→Desc d))\nrelMacroMatchesEquiv (constant A) = constantRelMatchesEquiv A\nrelMacroMatchesEquiv var = pointedRelMatchesEquiv\nrelMacroMatchesEquiv (d₁ , d₂) =\n productRelMatchesEquiv\n (RelMacroRelStr d₁) (RelMacroRelStr d₂)\n (relMacroMatchesEquiv d₁) (relMacroMatchesEquiv d₂)\nrelMacroMatchesEquiv (param A d) =\n paramRelMatchesEquiv A (λ _ → RelMacroRelStr d) (λ _ → relMacroMatchesEquiv d)\nrelMacroMatchesEquiv (function+ d₀ d₁) =\n functionRelMatchesEquiv+\n (PosRelMacroRelStr d₀) (transpMacroAction (posRelDesc→TranspDesc d₀))\n (RelMacroRelStr d₁) (MacroEquivStr (relDesc→Desc d₁))\n (posRelMacroMatchesEquiv d₀) (relMacroMatchesEquiv d₁)\nrelMacroMatchesEquiv (maybe d) =\n maybeRelMatchesEquiv (RelMacroRelStr d) (relMacroMatchesEquiv d)\n\n-- Module for easy importing\nmodule RelMacro ℓ (d : RelDesc ℓ) where\n relation = RelMacroRelStr d\n suitable = relMacroSuitableRel d\n matches = relMacroMatchesEquiv d\n open Macro ℓ (relDesc→Desc d) public\n", "meta": {"hexsha": "2d7ee9a9bffa53f5dd21125725858a028242c8d8", "size": 8141, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Structures/Relational/Macro.agda", "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": "Cubical/Structures/Relational/Macro.agda", "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_forks_repo_path": "Cubical/Structures/Relational/Macro.agda", "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "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": 44.0054054054, "max_line_length": 113, "alphanum_fraction": 0.7625598821, "num_tokens": 2708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6619228625116081, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.3567653162833177}} {"text": "{-# OPTIONS --without-K #-}\n\nopen import Base\nopen import Homotopy.Pointed\nopen import Homotopy.Connected\n\nmodule Homotopy.Cover {i} (A⋆ : pType i)\n (A⋆-is-conn : is-connected⋆ ⟨0⟩ A⋆) where\nopen pType A⋆ renaming (∣_∣ to A ; ⋆ to a)\n\nopen import Homotopy.Cover.Def A\n\nmodule Reconstruct where\n open import Homotopy.Cover.HomotopyGroupSetIsomorphism A⋆ A⋆-is-conn public\n\n{-\n-- The following is still a mess. Don't read it.\nmodule _ (uc : universal-covering) where\n open covering (π₁ uc)\n\n{-\n path⇒deck-is-equiv : ∀ {a₂} (path : a ≡ a₂) → is-equiv (path⇒deck path)\n path⇒deck-is-equiv path = iso-is-eq\n (transport fiber path)\n (transport fiber (! path))\n (trans-trans-opposite fiber path)\n (trans-opposite-trans fiber path)\n-}\n\n is-nature : (fiber a → fiber a) → Set i\n is-nature f = (p : a ≡ a)\n → ∀ x → transport fiber p (f x) ≡ f (transport fiber p x)\n\n auto : Set i\n auto = fiber a ≃ fiber a\n\n -- This Lemma can be made more general as \"(m+1)-connected => has-all-paths_m\"\n uc-has-all-path₀ : ∀ (p q : Σ A fiber) → p ≡₀ q\n uc-has-all-path₀ p q = inverse τ-path-equiv-path-τ-S\n $ π₂ (π₂ uc) (proj p) ∘ ! (π₂ (π₂ uc) $ proj q)\n\n nature-auto-eq : ∀ (f₁ f₂ : auto)\n → (f₁-is-nature : is-nature (π₁ f₁))\n → (f₂-is-nature : is-nature (π₁ f₂))\n → Σ (fiber a) (λ x → f₁ ☆ x ≡ f₂ ☆ x)\n → f₁ ≡ f₂\n nature-auto-eq f₁ f₂ f₁-nat f₂-nat (x , path) = equiv-eq $ funext λ y →\n π₀-extend\n ⦃ λ _ → ≡-is-set {x = f₁ ☆ y} {y = f₂ ☆ y} $ fiber-is-set a ⦄\n (λ uc-path →\n f₁ ☆ y\n ≡⟨ ap (π₁ f₁) $ ! $ fiber-path uc-path ⟩\n f₁ ☆ transport fiber (base-path uc-path) x\n ≡⟨ ! $ f₁-nat (base-path uc-path) x ⟩\n transport fiber (base-path uc-path) (f₁ ☆ x)\n ≡⟨ ap (transport fiber $ base-path uc-path) path ⟩\n transport fiber (base-path uc-path) (f₂ ☆ x)\n ≡⟨ f₂-nat (base-path uc-path) x ⟩\n f₂ ☆ transport fiber (base-path uc-path) x\n ≡⟨ ap (π₁ f₂) $ fiber-path uc-path ⟩∎\n f₂ ☆ y\n ∎)\n (uc-has-all-path₀ (a , x) (a , y))\n-}\n", "meta": {"hexsha": "610528ff7999725d4a36450bd6244fccdef2daaf", "size": 2057, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "old/Homotopy/Cover.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "old/Homotopy/Cover.agda", "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "old/Homotopy/Cover.agda", "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 31.6461538462, "max_line_length": 80, "alphanum_fraction": 0.5731648031, "num_tokens": 780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.3567319354037151}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import homotopy.SuspSmash\nopen import homotopy.SuspSmashComm\n\nmodule homotopy.IterSuspSmash where\n\nmodule _ {i j} (X : Ptd i) (Y : Ptd j) where\n\n Σ^∧-out : (n : ℕ) → ⊙Susp^ n X ∧ Y → Susp^ n (X ∧ Y)\n Σ^∧-out O = idf _\n Σ^∧-out (S n) = Susp-fmap (Σ^∧-out n) ∘ Σ∧-out (⊙Susp^ n X) Y\n\n private\n Σ^∧-out-pt : (n : ℕ) → Σ^∧-out n (pt (⊙Susp^ n X ⊙∧ Y)) == pt (⊙Susp^ n (X ⊙∧ Y))\n Σ^∧-out-pt O = idp\n Σ^∧-out-pt (S n) = idp\n\n ⊙Σ^∧-out : (n : ℕ) → ⊙Susp^ n X ⊙∧ Y ⊙→ ⊙Susp^ n (X ⊙∧ Y)\n ⊙Σ^∧-out n = Σ^∧-out n , Σ^∧-out-pt n\n\n ∧Σ^-out : (n : ℕ) → X ∧ ⊙Susp^ n Y → Susp^ n (X ∧ Y)\n ∧Σ^-out O = idf _\n ∧Σ^-out (S n) = Susp-fmap (∧Σ^-out n) ∘ ∧Σ-out X (⊙Susp^ n Y)\n\n private\n ∧Σ^-out-pt : (n : ℕ) → ∧Σ^-out n (pt (X ⊙∧ ⊙Susp^ n Y)) == pt (⊙Susp^ n (X ⊙∧ Y))\n ∧Σ^-out-pt O = idp\n ∧Σ^-out-pt (S n) = idp\n\n ⊙∧Σ^-out : (n : ℕ) → X ⊙∧ ⊙Susp^ n Y ⊙→ ⊙Susp^ n (X ⊙∧ Y)\n ⊙∧Σ^-out n = ∧Σ^-out n , ∧Σ^-out-pt n\n\nprivate\n ⊙maybe-Susp^-flip-+ : ∀ {i} {X : Ptd i} (m n : ℕ) (b : Bool)\n → (m == 0 → b == false)\n → ⊙coe (⊙Susp^-+ m n {X}) ◃⊙∘\n ⊙maybe-Susp^-flip {X = ⊙Susp^ n X} m b ◃⊙idf\n =⊙∘\n ⊙maybe-Susp^-flip (m + n) b ◃⊙∘\n ⊙coe (⊙Susp^-+ m n) ◃⊙idf\n ⊙maybe-Susp^-flip-+ O O b h = =⊙∘-in idp\n ⊙maybe-Susp^-flip-+ O (S n) true h = ⊥-elim (Bool-true≠false (h idp))\n ⊙maybe-Susp^-flip-+ O (S n) false h = =⊙∘-in idp\n ⊙maybe-Susp^-flip-+ {X = X} (S m) n true h =\n ⊙coe (ap ⊙Susp (Susp^-+ m n)) ◃⊙∘\n ⊙Susp-flip (⊙Susp^ m (⊙Susp^ n X)) ◃⊙idf\n =⊙∘₁⟨ 0 & 1 & ! p ⟩\n ⊙Susp-fmap (fst (⊙coe (⊙Susp^-+ m n))) ◃⊙∘\n ⊙Susp-flip (⊙Susp^ m (⊙Susp^ n X)) ◃⊙idf\n =⊙∘⟨ =⊙∘-in $ ! $\n ⊙Susp-flip-natural (⊙coe (⊙Susp^-+ m n)) ⟩\n ⊙Susp-flip (⊙Susp^ (m + n) X) ◃⊙∘\n ⊙Susp-fmap (fst (⊙coe (⊙Susp^-+ m n))) ◃⊙idf\n =⊙∘₁⟨ 1 & 1 & p ⟩\n ⊙Susp-flip (⊙Susp^ (m + n) X) ◃⊙∘\n ⊙coe (ap ⊙Susp (Susp^-+ m n)) ◃⊙idf ∎⊙∘\n where\n p : ⊙Susp-fmap (fst (⊙coe (⊙Susp^-+ m n {X}))) ==\n ⊙coe (ap ⊙Susp (Susp^-+ m n))\n p =\n ap (⊙Susp-fmap ∘ coe) (de⊙-⊙Susp^-+ m n {X}) ∙\n ! (⊙transport-⊙Susp (Susp^-+ m n)) ∙\n ⊙transport-⊙coe ⊙Susp (Susp^-+ m n)\n ⊙maybe-Susp^-flip-+ (S m) n false h = =⊙∘-in $ ! $ ⊙λ= $ ⊙∘-unit-l _\n\n ⊙maybe-Susp^-flip-comm : ∀ {i} {X : Ptd i} (m n : ℕ) (b : Bool)\n → (m == 0 → b == false)\n → (n == 0 → b == false)\n → ⊙coe (⊙Susp^-comm m n {X = X}) ◃⊙∘\n ⊙maybe-Susp^-flip {X = ⊙Susp^ n X} m b ◃⊙idf\n =⊙∘\n ⊙maybe-Susp^-flip {X = ⊙Susp^ m X} n b ◃⊙∘\n ⊙coe (⊙Susp^-comm m n) ◃⊙idf\n ⊙maybe-Susp^-flip-comm O O b h₁ h₂ = =⊙∘-in (! (⊙λ= (⊙∘-unit-l (⊙coe (⊙Susp^-comm 0 0)))))\n ⊙maybe-Susp^-flip-comm O (S _) true h₁ h₂ = ⊥-elim (Bool-true≠false (h₁ idp))\n ⊙maybe-Susp^-flip-comm O (S _) false h₁ h₂ = =⊙∘-in (! (⊙λ= (⊙∘-unit-l _)))\n ⊙maybe-Susp^-flip-comm (S m) O true h₁ h₂ = ⊥-elim (Bool-true≠false (h₂ idp))\n ⊙maybe-Susp^-flip-comm (S m) O false h₁ h₂ = =⊙∘-in (! (⊙λ= (⊙∘-unit-l _)))\n ⊙maybe-Susp^-flip-comm {X = X} (S m) (S n) true h₁ h₂ =\n ⊙coe (⊙Susp^-comm (S m) (S n)) ◃⊙∘\n ⊙Susp-flip (⊙Susp^ m (⊙Susp^ (S n) X)) ◃⊙idf\n =⊙∘₁⟨ 0 & 1 & p ⟩\n ⊙Susp-fmap (fst (⊙coe (⊙Susp^-comm m (S n) ∙ ⊙Susp^-comm 1 n))) ◃⊙∘\n ⊙Susp-flip (⊙Susp^ m (⊙Susp^ (S n) X)) ◃⊙idf\n =⊙∘⟨ =⊙∘-in $ ! $\n ⊙Susp-flip-natural (⊙coe (⊙Susp^-comm m (S n) ∙ ⊙Susp^-comm 1 n)) ⟩\n ⊙Susp-flip (⊙Susp^ n (⊙Susp^ (S m) X)) ◃⊙∘\n ⊙Susp-fmap (fst (⊙coe (⊙Susp^-comm m (S n) ∙ ⊙Susp^-comm 1 n))) ◃⊙idf\n =⊙∘₁⟨ 1 & 1 & ! p ⟩\n ⊙Susp-flip (⊙Susp^ n (⊙Susp^ (S m) X)) ◃⊙∘\n ⊙Susp^-swap (S m) (S n) ◃⊙idf ∎⊙∘\n where\n p : ⊙Susp^-swap (S m) (S n) {X} ==\n ⊙Susp-fmap (fst (⊙coe (⊙Susp^-comm m (S n) {X} ∙ ⊙Susp^-comm 1 n {⊙Susp^ m X})))\n p =\n ap ⊙coe (⊙Susp^-comm-S-S m n) ∙\n ! (⊙transport-⊙coe ⊙Susp (Susp^-comm m (S n) ∙ Susp^-comm 1 n)) ∙\n ⊙transport-⊙Susp (Susp^-comm m (S n) ∙ Susp^-comm 1 n) ∙\n ! (ap (⊙Susp-fmap ∘ coe) (ap2 _∙_ (de⊙-⊙Susp^-comm m (S n)) (de⊙-⊙Susp^-comm 1 n))) ∙\n ap (⊙Susp-fmap ∘ coe) (∙-ap de⊙ (⊙Susp^-comm m (S n)) (⊙Susp^-comm 1 n))\n ⊙maybe-Susp^-flip-comm (S m) (S n) false h₁ h₂ = =⊙∘-in (! (⊙λ= (⊙∘-unit-l _)))\n\n⊙∧Σ-Σ^∧-out : ∀ {i} {j} (X : Ptd i) (Y : Ptd j) (m : ℕ)\n → ⊙Susp-fmap (∧Σ^-out X Y m) ◃⊙∘\n ⊙Σ∧-out X (⊙Susp^ m Y) ◃⊙idf\n =⊙∘\n ⊙Susp^-swap m 1 {X = X ⊙∧ Y} ◃⊙∘\n ⊙maybe-Susp^-flip m (odd m) ◃⊙∘\n ⊙Susp^-fmap m (⊙Σ∧-out X Y) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ X)) Y m ◃⊙idf\n⊙∧Σ-Σ^∧-out X Y 0 =\n ⊙Susp-fmap (idf (X ∧ Y)) ◃⊙∘\n ⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙idf\n =⊙∘⟨ 0 & 1 & ⊙Susp-fmap-idf _ ⟩\n ⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙idf\n =⊙∘⟨ 0 & 0 & ⊙contract ⟩\n ⊙idf _ ◃⊙∘\n ⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙idf\n =⊙∘₁⟨ 0 & 1 & ap ⊙coe (! (⊙Susp^-comm-0-l 1 (X ⊙∧ Y))) ⟩\n ⊙Susp^-swap 0 1 ◃⊙∘\n ⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙idf\n =⊙∘⟨ 1 & 0 & ⊙contract ⟩\n ⊙Susp^-swap 0 1 ◃⊙∘\n ⊙idf _ ◃⊙∘\n ⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙idf\n =⊙∘⟨ 3 & 0 & ⊙contract ⟩\n ⊙Susp^-swap 0 1 ◃⊙∘\n ⊙idf _ ◃⊙∘\n ⊙Σ∧-out X (⊙Susp^ 0 Y) ◃⊙∘\n ⊙idf _ ◃⊙idf ∎⊙∘\n⊙∧Σ-Σ^∧-out X Y (S m) =\n ⊙Susp-fmap (∧Σ^-out X Y (S m)) ◃⊙∘\n ⊙Σ∧-out X (⊙Susp^ (S m) Y) ◃⊙idf\n =⊙∘⟨ 0 & 1 & ⊙Susp-fmap-seq-∘ (Susp-fmap (∧Σ^-out X Y m) ◃∘\n ∧Σ-out X (⊙Susp^ m Y) ◃idf) ⟩\n ⊙Susp^-fmap 2 (⊙∧Σ^-out X Y m) ◃⊙∘\n ⊙Susp-fmap (∧Σ-out X (⊙Susp^ m Y)) ◃⊙∘\n ⊙Σ∧-out X (⊙Susp^ (S m) Y) ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙∧Σ-Σ∧-out X (⊙Susp^ m Y) ⟩\n ⊙Susp^-fmap 2 (⊙∧Σ^-out X Y m) ◃⊙∘\n ⊙Susp-flip (⊙Susp (X ∧ ⊙Susp^ m Y)) ◃⊙∘\n ⊙Susp-fmap (Σ∧-out X (⊙Susp^ m Y)) ◃⊙∘\n ⊙∧Σ-out (⊙Susp (de⊙ X)) (⊙Susp^ m Y) ◃⊙idf\n =⊙∘⟨ 0 & 2 & =⊙∘-in {gs = ⊙Susp-flip (⊙Susp (Susp^ m (X ∧ Y))) ◃⊙∘\n ⊙Susp^-fmap 2 (⊙∧Σ^-out X Y m) ◃⊙idf} $\n ! (⊙Susp-flip-natural (⊙Susp-fmap (∧Σ^-out X Y m))) ⟩\n ⊙Susp-flip (⊙Susp (Susp^ m (X ∧ Y))) ◃⊙∘\n ⊙Susp^-fmap 2 (⊙∧Σ^-out X Y m) ◃⊙∘\n ⊙Susp-fmap (Σ∧-out X (⊙Susp^ m Y)) ◃⊙∘\n ⊙∧Σ-out (⊙Susp (de⊙ X)) (⊙Susp^ m Y) ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙Susp-fmap-seq-=⊙∘ (de⊙-seq-=⊙∘ (⊙∧Σ-Σ^∧-out X Y m)) ⟩\n ⊙Susp-flip (⊙Susp (Susp^ m (X ∧ Y))) ◃⊙∘\n ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm m 1))) ◃⊙∘\n ⊙Susp-fmap (fst (⊙maybe-Susp^-flip m (odd m))) ◃⊙∘\n ⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘\n ⊙Susp-fmap (∧Σ^-out (⊙Susp (de⊙ X)) Y m) ◃⊙∘\n ⊙∧Σ-out (⊙Susp (de⊙ X)) (⊙Susp^ m Y) ◃⊙idf\n =⊙∘⟨ 0 & 2 & =⊙∘-in {gs = ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm m 1))) ◃⊙∘\n ⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙idf} $\n ⊙Susp-flip-natural (⊙coe (⊙Susp^-comm m 1)) ⟩\n ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm m 1))) ◃⊙∘\n ⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙∘\n ⊙Susp-fmap (fst (⊙maybe-Susp^-flip m (odd m))) ◃⊙∘\n ⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘\n ⊙Susp-fmap (∧Σ^-out (⊙Susp (de⊙ X)) Y m) ◃⊙∘\n ⊙∧Σ-out (⊙Susp (de⊙ X)) (⊙Susp^ m Y) ◃⊙idf\n =⊙∘⟨ 4 & 2 & ⊙contract ⟩\n ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm m 1))) ◃⊙∘\n ⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙∘\n ⊙Susp-fmap (fst (⊙maybe-Susp^-flip m (odd m))) ◃⊙∘\n ⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ X)) Y (S m) ◃⊙idf\n =⊙∘₁⟨ 0 & 1 & ! (⊙transport-⊙Susp (ap de⊙ (⊙Susp^-comm m 1))) ∙\n ap (⊙transport ⊙Susp) (de⊙-⊙Susp^-comm m 1) ∙\n ⊙transport-⊙coe ⊙Susp (Susp^-comm m 1) ∙\n ap ⊙coe (! (⊙Susp^-comm-S-1 m {X ⊙∧ Y})) ⟩\n ⊙coe (⊙Susp^-comm (S m) 1) ◃⊙∘\n ⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙∘\n ⊙Susp-fmap (fst (⊙maybe-Susp^-flip m (odd m))) ◃⊙∘\n ⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ X)) Y (S m) ◃⊙idf\n =⊙∘₁⟨ 2 & 1 & ap ⊙Susp-fmap (de⊙-⊙maybe-Susp^-flip m (odd m)) ⟩\n ⊙coe (⊙Susp^-comm (S m) 1) ◃⊙∘\n ⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙∘\n ⊙Susp-fmap (maybe-Susp^-flip m (odd m)) ◃⊙∘\n ⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ X)) Y (S m) ◃⊙idf\n =⊙∘₁⟨ 2 & 1 & ⊙Susp-fmap-maybe-Susp^-flip m (odd m) (ap odd) ⟩\n ⊙coe (⊙Susp^-comm (S m) 1) ◃⊙∘\n ⊙Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) ◃⊙∘\n ⊙maybe-Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) (odd m) ◃⊙∘\n ⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ X)) Y (S m) ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙maybe-Susp-flip-flip _ true (odd m) ⟩\n ⊙coe (⊙Susp^-comm (S m) 1) ◃⊙∘\n ⊙maybe-Susp-flip (⊙Susp^ m (⊙Susp (X ∧ Y))) (odd (S m)) ◃⊙∘\n ⊙Susp^-fmap (S m) (⊙Σ∧-out X Y) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ X)) Y (S m) ◃⊙idf ∎⊙∘\n\nmodule _ {i j} (X : Ptd i) (Y : Ptd j) where\n\n ⊙∧Σ^-Σ^∧-out : ∀ (m n : ℕ)\n → ⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘\n ⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf\n =⊙∘\n ⊙coe (⊙Susp^-comm n m) ◃⊙∘\n ⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf\n ⊙∧Σ^-Σ^∧-out O n =\n ⊙∧Σ^-out X Y n ◃⊙∘\n ⊙idf _ ◃⊙idf\n =⊙∘⟨ 1 & 1 & ⊙expand ⊙idf-seq ⟩\n ⊙∧Σ^-out X Y n ◃⊙idf\n =⊙∘⟨ 0 & 0 & !⊙∘ (⊙Susp^-fmap-idf n (X ⊙∧ Y)) ⟩\n ⊙Susp^-fmap n (⊙idf (X ⊙∧ Y)) ◃⊙∘\n ⊙∧Σ^-out X Y n ◃⊙idf\n =⊙∘₁⟨ 0 & 0 & ! (⊙maybe-Susp^-flip-false n) ⟩\n ⊙maybe-Susp^-flip n false ◃⊙∘\n ⊙Susp^-fmap n (⊙idf (X ⊙∧ Y)) ◃⊙∘\n ⊙∧Σ^-out X Y n ◃⊙idf\n =⊙∘₁⟨ 0 & 0 & ap ⊙coe (! (⊙Susp^-comm-0-r n _)) ⟩\n ⊙coe (⊙Susp^-comm n O) ◃⊙∘\n ⊙maybe-Susp^-flip n false ◃⊙∘\n ⊙Susp^-fmap n (⊙idf (X ⊙∧ Y)) ◃⊙∘\n ⊙∧Σ^-out X Y n ◃⊙idf ∎⊙∘\n ⊙∧Σ^-Σ^∧-out (S m) n =\n ⊙Susp^-fmap (S m) (⊙∧Σ^-out X Y n) ◃⊙∘\n ⊙Σ^∧-out X (⊙Susp^ n Y) (S m) ◃⊙idf\n =⊙∘⟨ 1 & 1 & ⊙expand (⊙Susp-fmap (Σ^∧-out X (⊙Susp^ n Y) m) ◃⊙∘\n ⊙Σ∧-out (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf) ⟩\n ⊙Susp^-fmap (S m) (⊙∧Σ^-out X Y n) ◃⊙∘\n ⊙Susp-fmap (Σ^∧-out X (⊙Susp^ n Y) m) ◃⊙∘\n ⊙Σ∧-out (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf\n =⊙∘⟨ 0 & 2 & ⊙Susp-fmap-seq-=⊙∘ (de⊙-seq-=⊙∘ (⊙∧Σ^-Σ^∧-out m n)) ⟩\n ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘\n ⊙Susp-fmap (fst (⊙maybe-Susp^-flip n (and (odd m) (odd n)))) ◃⊙∘\n ⊙Susp-fmap (Susp^-fmap n (Σ^∧-out X Y m)) ◃⊙∘\n ⊙Susp-fmap (∧Σ^-out (⊙Susp^ m X) Y n) ◃⊙∘\n ⊙Σ∧-out (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf\n =⊙∘⟨ 3 & 2 & ⊙∧Σ-Σ^∧-out (⊙Susp^ m X) Y n ⟩\n ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘\n ⊙Susp-fmap (fst (⊙maybe-Susp^-flip n (and (odd m) (odd n)))) ◃⊙∘\n ⊙Susp-fmap (Susp^-fmap n (Σ^∧-out X Y m)) ◃⊙∘\n ⊙Susp^-swap n 1 ◃⊙∘\n ⊙maybe-Susp^-flip n (odd n) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ∧-out (⊙Susp^ m X) Y) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf\n =⊙∘⟨ 2 & 2 & !⊙∘ $ ⊙Susp^-swap-natural n 1 (⊙Σ^∧-out X Y m) ⟩\n ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘\n ⊙Susp-fmap (fst (⊙maybe-Susp^-flip n (and (odd m) (odd n)))) ◃⊙∘\n ⊙Susp^-swap n 1 ◃⊙∘\n ⊙Susp^-fmap n (⊙Susp-fmap (Σ^∧-out X Y m)) ◃⊙∘\n ⊙maybe-Susp^-flip n (odd n) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ∧-out (⊙Susp^ m X) Y) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf\n =⊙∘⟨ 3 & 2 & ⊙maybe-Susp^-flip-natural-=⊙∘ (⊙Susp-fmap (Σ^∧-out X Y m)) n (odd n) ⟩\n ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘\n ⊙Susp-fmap (fst (⊙maybe-Susp^-flip n (and (odd m) (odd n)))) ◃⊙∘\n ⊙Susp^-swap n 1 ◃⊙∘\n ⊙maybe-Susp^-flip n (odd n) ◃⊙∘\n ⊙Susp^-fmap n (⊙Susp-fmap (Σ^∧-out X Y m)) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ∧-out (⊙Susp^ m X) Y) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf\n =⊙∘₁⟨ 4 & 2 & ! $ ⊙Susp^-fmap-∘ n (⊙Susp-fmap (Σ^∧-out X Y m)) (⊙Σ∧-out (⊙Susp^ m X) Y) ⟩\n ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘\n ⊙Susp-fmap (fst (⊙maybe-Susp^-flip n (and (odd m) (odd n)))) ◃⊙∘\n ⊙Susp^-swap n 1 ◃⊙∘\n ⊙maybe-Susp^-flip n (odd n) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙maybe-Susp^-flip-⊙Susp^-comm _ n 1 (and (odd m) (odd n)) ⟩\n ⊙Susp-fmap (coe (ap de⊙ (⊙Susp^-comm n m))) ◃⊙∘\n ⊙coe (⊙Susp^-comm n 1) ◃⊙∘\n ⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘\n ⊙maybe-Susp^-flip n (odd n) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf\n =⊙∘₁⟨ 0 & 1 & ! (⊙transport-⊙Susp (ap de⊙ (⊙Susp^-comm n m))) ∙\n ⊙transport-⊙coe ⊙Susp (ap de⊙ (⊙Susp^-comm n m)) ∙\n ap (⊙coe ∘ ap ⊙Susp) (de⊙-⊙Susp^-comm n m) ⟩\n ⊙coe (ap ⊙Susp (Susp^-comm n m)) ◃⊙∘\n ⊙coe (⊙Susp^-comm n 1) ◃⊙∘\n ⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘\n ⊙maybe-Susp^-flip n (odd n) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf\n =⊙∘₁⟨ 0 & 2 & ! (=⊙∘-out (⊙coe-∙ (⊙Susp^-comm n 1) (ap ⊙Susp (Susp^-comm n m)))) ∙\n ap ⊙coe (! (=ₛ-out (⊙Susp^-comm-S-r n m))) ⟩\n ⊙coe (⊙Susp^-comm n (S m)) ◃⊙∘\n ⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘\n ⊙maybe-Susp^-flip n (odd n) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙maybe-Susp^-flip-flip n (and (odd m) (odd n)) (odd n) ⟩\n ⊙coe (⊙Susp^-comm n (S m)) ◃⊙∘\n ⊙maybe-Susp^-flip n (xor (and (odd m) (odd n)) (odd n)) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf\n =⊙∘₁⟨ 1 & 1 & ap (⊙maybe-Susp^-flip n) (table (odd m) (odd n)) ⟩\n ⊙coe (⊙Susp^-comm n (S m)) ◃⊙∘\n ⊙maybe-Susp^-flip n (and (odd (S m)) (odd n)) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y (S m)) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp (de⊙ (⊙Susp^ m X))) Y n ◃⊙idf ∎⊙∘\n where\n table : ∀ (b c : Bool) → xor (and b c) c == and (negate b) c\n table true true = idp\n table true false = idp\n table false true = idp\n table false false = idp\n\n ⊙∧Σ^-Σ^∧-out' : ∀ (m n : ℕ)\n → ⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf\n =⊙∘\n ⊙coe (⊙Susp^-comm m n) ◃⊙∘\n ⊙maybe-Susp^-flip m (and (odd m) (odd n)) ◃⊙∘\n ⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘\n ⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf\n ⊙∧Σ^-Σ^∧-out' m n =\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf\n =⊙∘₁⟨ 0 & 0 & ! (⊙maybe-Susp^-flip-false n) ∙\n ap (⊙maybe-Susp^-flip n) (! (xor-diag (and (odd m) (odd n)))) ⟩\n ⊙maybe-Susp^-flip n (xor (and (odd m) (odd n)) (and (odd m) (odd n))) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf\n =⊙∘⟨ 0 & 1 & !⊙∘ $ ⊙maybe-Susp^-flip-flip n (and (odd m) (odd n)) (and (odd m) (odd n)) ⟩\n ⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘\n ⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf\n =⊙∘⟨ 1 & 0 & =⊙∘-in {gs = ⊙coe (! (⊙Susp^-comm n m)) ◃⊙∘\n ⊙coe (⊙Susp^-comm n m) ◃⊙idf} $\n ap ⊙coe (! (!-inv-r (⊙Susp^-comm n m))) ∙\n =⊙∘-out (⊙coe-∙ (⊙Susp^-comm n m) (! (⊙Susp^-comm n m))) ⟩\n ⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘\n ⊙coe (! (⊙Susp^-comm n m)) ◃⊙∘\n ⊙coe (⊙Susp^-comm n m) ◃⊙∘\n ⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘\n ⊙Susp^-fmap n (⊙Σ^∧-out X Y m) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp^ m X) Y n ◃⊙idf\n =⊙∘⟨ 2 & 4 & !⊙∘ $ ⊙∧Σ^-Σ^∧-out m n ⟩\n ⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘\n ⊙coe (! (⊙Susp^-comm n m)) ◃⊙∘\n ⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘\n ⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf\n =⊙∘₁⟨ 1 & 1 & ap ⊙coe (⊙Susp^-comm-! n m) ⟩\n ⊙maybe-Susp^-flip n (and (odd m) (odd n)) ◃⊙∘\n ⊙coe (⊙Susp^-comm m n) ◃⊙∘\n ⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘\n ⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf\n =⊙∘⟨ 0 & 2 & !⊙∘ $\n ⊙maybe-Susp^-flip-comm m n (and (odd m) (odd n))\n (ap (λ k → and (odd k) (odd n)))\n (λ p → ap (and (odd m) ∘ odd) p ∙ and-false-r (odd m)) ⟩\n ⊙coe (⊙Susp^-comm m n) ◃⊙∘\n ⊙maybe-Susp^-flip m (and (odd m) (odd n)) ◃⊙∘\n ⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘\n ⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf ∎⊙∘\n\n ⊙Σ^∧Σ^-out-seq : ∀ (m n : ℕ) → (⊙Susp^ m X ⊙∧ ⊙Susp^ n Y) ⊙–→ ⊙Susp^ (m + n) (X ⊙∧ Y)\n ⊙Σ^∧Σ^-out-seq m n =\n ⊙coe (⊙Susp^-+ m n {X ⊙∧ Y}) ◃⊙∘\n ⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘\n ⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf\n\n ⊙Σ^∧Σ^-out : ∀ (m n : ℕ) → ⊙Susp^ m X ⊙∧ ⊙Susp^ n Y ⊙→ ⊙Susp^ (m + n) (X ⊙∧ Y)\n ⊙Σ^∧Σ^-out m n = ⊙compose (⊙Σ^∧Σ^-out-seq m n)\n\n swap-⊙Σ^∧-out : ∀ (m : ℕ)\n → ⊙Susp^-fmap m (⊙∧-swap X Y) ◃⊙∘\n ⊙Σ^∧-out X Y m ◃⊙idf\n =⊙∘\n ⊙∧Σ^-out Y X m ◃⊙∘\n ⊙∧-swap (⊙Susp^ m X) Y ◃⊙idf\n swap-⊙Σ^∧-out O = =⊙∘-in $ ! $ ⊙λ= $ ⊙∘-unit-l (⊙∧-swap X Y)\n swap-⊙Σ^∧-out (S m) =\n ⊙Susp^-fmap (S m) (⊙∧-swap X Y) ◃⊙∘\n ⊙Σ^∧-out X Y (S m) ◃⊙idf\n =⊙∘⟨ 1 & 1 & ⊙expand (⊙Susp-fmap (Σ^∧-out X Y m) ◃⊙∘\n ⊙Σ∧-out (⊙Susp^ m X) Y ◃⊙idf) ⟩\n ⊙Susp^-fmap (S m) (⊙∧-swap X Y) ◃⊙∘\n ⊙Susp-fmap (Σ^∧-out X Y m) ◃⊙∘\n ⊙Σ∧-out (⊙Susp^ m X) Y ◃⊙idf\n =⊙∘⟨ 0 & 2 &\n ⊙Susp-fmap-seq-=⊙∘ (de⊙-seq-=⊙∘ (swap-⊙Σ^∧-out m)) ⟩\n ⊙Susp-fmap (∧Σ^-out Y X m) ◃⊙∘\n ⊙Susp-fmap (∧-swap (⊙Susp^ m X) Y) ◃⊙∘\n ⊙Σ∧-out (⊙Susp^ m X) Y ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙swap-Σ∧-out (⊙Susp^ m X) Y ⟩\n ⊙Susp-fmap (∧Σ^-out Y X m) ◃⊙∘\n ⊙∧Σ-out Y (⊙Susp^ m X) ◃⊙∘\n ⊙∧-swap (⊙Susp (de⊙ (⊙Susp^ m X))) Y ◃⊙idf\n =⊙∘⟨ 0 & 2 & ⊙contract ⟩\n ⊙∧Σ^-out Y X (S m) ◃⊙∘\n ⊙∧-swap (⊙Susp^ (S m) X) Y ◃⊙idf ∎⊙∘\n\n swap-⊙∧Σ^-out : ∀ (n : ℕ)\n → ⊙Susp^-fmap n (⊙∧-swap X Y) ◃⊙∘\n ⊙∧Σ^-out X Y n ◃⊙idf\n =⊙∘\n ⊙Σ^∧-out Y X n ◃⊙∘\n ⊙∧-swap X (⊙Susp^ n Y) ◃⊙idf\n swap-⊙∧Σ^-out O = =⊙∘-in $ ! $ ⊙λ= $ ⊙∘-unit-l (⊙∧-swap X Y)\n swap-⊙∧Σ^-out (S n) =\n ⊙Susp^-fmap (S n) (⊙∧-swap X Y) ◃⊙∘\n ⊙∧Σ^-out X Y (S n) ◃⊙idf\n =⊙∘⟨ 1 & 1 & ⊙expand (⊙Susp-fmap (∧Σ^-out X Y n) ◃⊙∘\n ⊙∧Σ-out X (⊙Susp^ n Y) ◃⊙idf) ⟩\n ⊙Susp^-fmap (S n) (⊙∧-swap X Y) ◃⊙∘\n ⊙Susp-fmap (∧Σ^-out X Y n) ◃⊙∘\n ⊙∧Σ-out X (⊙Susp^ n Y) ◃⊙idf\n =⊙∘⟨ 0 & 2 &\n ⊙Susp-fmap-seq-=⊙∘ (de⊙-seq-=⊙∘ (swap-⊙∧Σ^-out n))⟩\n ⊙Susp-fmap (fst (⊙Σ^∧-out Y X n)) ◃⊙∘\n ⊙Susp-fmap (fst (⊙∧-swap X (⊙Susp^ n Y))) ◃⊙∘\n ⊙∧Σ-out X (⊙Susp^ n Y) ◃⊙idf\n =⊙∘⟨ 1 & 2 & ⊙swap-∧Σ-out X (⊙Susp^ n Y) ⟩\n ⊙Susp-fmap (fst (⊙Σ^∧-out Y X n)) ◃⊙∘\n ⊙Σ∧-out (⊙Susp^ n Y) X ◃⊙∘\n ⊙∧-swap X (⊙Susp (de⊙ (⊙Susp^ n Y))) ◃⊙idf\n =⊙∘⟨ 0 & 2 & ⊙contract ⟩\n ⊙Σ^∧-out Y X (S n) ◃⊙∘\n ⊙∧-swap X (⊙Susp^ (S n) Y) ◃⊙idf ∎⊙∘\n\n⊙Σ^∧Σ^-out-swap : ∀ {i} {j} (X : Ptd i) (Y : Ptd j) (m n : ℕ)\n → ⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘\n ⊙Susp^-fmap (m + n) (⊙∧-swap X Y) ◃⊙∘\n ⊙Σ^∧Σ^-out X Y m n ◃⊙idf\n =⊙∘\n ⊙maybe-Susp^-flip (n + m) (and (odd n) (odd m)) ◃⊙∘\n ⊙Σ^∧Σ^-out Y X n m ◃⊙∘\n ⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf\n⊙Σ^∧Σ^-out-swap X Y m n =\n ⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘\n ⊙Susp^-fmap (m + n) (⊙∧-swap X Y) ◃⊙∘\n ⊙Σ^∧Σ^-out X Y m n ◃⊙idf\n =⊙∘⟨ 2 & 1 & ⊙expand (⊙Σ^∧Σ^-out-seq X Y m n) ⟩\n ⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘\n ⊙Susp^-fmap (m + n) (⊙∧-swap X Y) ◃⊙∘\n ⊙coe (⊙Susp^-+ m n) ◃⊙∘\n ⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘\n ⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf\n =⊙∘⟨ 1 & 2 & =⊙∘-in {gs = ⊙coe (⊙Susp^-+ m n) ◃⊙∘\n ⊙Susp^-fmap m (⊙Susp^-fmap n (⊙∧-swap X Y)) ◃⊙idf} $\n ! $ ⊙Susp^-+-natural m n (⊙∧-swap X Y) ⟩\n ⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘\n ⊙coe (⊙Susp^-+ m n) ◃⊙∘\n ⊙Susp^-fmap m (⊙Susp^-fmap n (⊙∧-swap X Y)) ◃⊙∘\n ⊙Susp^-fmap m (⊙∧Σ^-out X Y n) ◃⊙∘\n ⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf\n =⊙∘⟨ 2 & 2 & ⊙Susp^-fmap-seq-=⊙∘ m $ swap-⊙∧Σ^-out X Y n ⟩\n ⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘\n ⊙coe (⊙Susp^-+ m n) ◃⊙∘\n ⊙Susp^-fmap m (⊙Σ^∧-out Y X n) ◃⊙∘\n ⊙Susp^-fmap m (⊙∧-swap X (⊙Susp^ n Y)) ◃⊙∘\n ⊙Σ^∧-out X (⊙Susp^ n Y) m ◃⊙idf\n =⊙∘⟨ 3 & 2 & swap-⊙Σ^∧-out X (⊙Susp^ n Y) m ⟩\n ⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘\n ⊙coe (⊙Susp^-+ m n) ◃⊙∘\n ⊙Susp^-fmap m (⊙Σ^∧-out Y X n) ◃⊙∘\n ⊙∧Σ^-out (⊙Susp^ n Y) X m ◃⊙∘\n ⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf\n =⊙∘⟨ 2 & 2 & ⊙∧Σ^-Σ^∧-out' Y X n m ⟩\n ⊙transport (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃⊙∘\n ⊙coe (⊙Susp^-+ m n) ◃⊙∘\n ⊙coe (⊙Susp^-comm n m) ◃⊙∘\n ⊙maybe-Susp^-flip n (and (odd n) (odd m)) ◃⊙∘\n ⊙Susp^-fmap n (⊙∧Σ^-out Y X m) ◃⊙∘\n ⊙Σ^∧-out Y (⊙Susp^ m X) n ◃⊙∘\n ⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf\n =⊙∘₁⟨ 0 & 1 & ⊙transport-⊙coe (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ⟩\n ⊙coe (ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n)) ◃⊙∘\n ⊙coe (⊙Susp^-+ m n) ◃⊙∘\n ⊙coe (⊙Susp^-comm n m) ◃⊙∘\n ⊙maybe-Susp^-flip n (and (odd n) (odd m)) ◃⊙∘\n ⊙Susp^-fmap n (⊙∧Σ^-out Y X m) ◃⊙∘\n ⊙Σ^∧-out Y (⊙Susp^ m X) n ◃⊙∘\n ⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf\n =⊙∘⟨ 0 & 3 & ⊙coe-seq-=ₛ p ⟩\n ⊙coe (⊙Susp^-+ n m) ◃⊙∘\n ⊙maybe-Susp^-flip n (and (odd n) (odd m)) ◃⊙∘\n ⊙Susp^-fmap n (⊙∧Σ^-out Y X m) ◃⊙∘\n ⊙Σ^∧-out Y (⊙Susp^ m X) n ◃⊙∘\n ⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf\n =⊙∘⟨ 0 & 2 & ⊙maybe-Susp^-flip-+ n m (and (odd n) (odd m))\n (ap (λ k → and (odd k) (odd m))) ⟩\n ⊙maybe-Susp^-flip (n + m) (and (odd n) (odd m)) ◃⊙∘\n ⊙coe (⊙Susp^-+ n m) ◃⊙∘\n ⊙Susp^-fmap n (⊙∧Σ^-out Y X m) ◃⊙∘\n ⊙Σ^∧-out Y (⊙Susp^ m X) n ◃⊙∘\n ⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf\n =⊙∘⟨ 1 & 3 & ⊙contract ⟩\n ⊙maybe-Susp^-flip (n + m) (and (odd n) (odd m)) ◃⊙∘\n ⊙Σ^∧Σ^-out Y X n m ◃⊙∘\n ⊙∧-swap (⊙Susp^ m X) (⊙Susp^ n Y) ◃⊙idf ∎⊙∘\n where\n p : ⊙Susp^-comm n m ◃∙\n ⊙Susp^-+ m n {Y ⊙∧ X} ◃∙\n ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃∎\n =ₛ\n ⊙Susp^-+ n m {Y ⊙∧ X} ◃∎\n p =\n ⊙Susp^-comm n m ◃∙\n ⊙Susp^-+ m n {Y ⊙∧ X} ◃∙\n ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃∎\n =ₛ⟨ 0 & 1 & expand (⊙Susp^-comm-seq n m) ⟩\n ⊙Susp^-+ n m ◃∙\n ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm n m) ◃∙\n ! (⊙Susp^-+ m n) ◃∙\n ⊙Susp^-+ m n ◃∙\n ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃∎\n =ₛ⟨ 2 & 2 & seq-!-inv-l (⊙Susp^-+ m n ◃∎) ⟩\n ⊙Susp^-+ n m ◃∙\n ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm n m) ◃∙\n ap (λ k → ⊙Susp^ k (Y ⊙∧ X)) (+-comm m n) ◃∎\n =ₛ⟨ 1 & 2 & ap-seq-=ₛ (λ k → ⊙Susp^ k (Y ⊙∧ X)) $\n =ₛ-in {s = +-comm n m ◃∙ +-comm m n ◃∎} {t = []} $\n set-path ℕ-level _ _ ⟩\n ⊙Susp^-+ n m ◃∎ ∎ₛ\n", "meta": {"hexsha": "9f9d1019b2f2addfbb10c92c6bda0c94a4b41cad", "size": 21667, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/IterSuspSmash.agda", "max_stars_repo_name": "AntoineAllioux/HoTT-Agda", "max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/homotopy/IterSuspSmash.agda", "max_issues_repo_name": "AntoineAllioux/HoTT-Agda", "max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/homotopy/IterSuspSmash.agda", "max_forks_repo_name": "AntoineAllioux/HoTT-Agda", "max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 41.3492366412, "max_line_length": 95, "alphanum_fraction": 0.4183320257, "num_tokens": 14346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7185943925708562, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.3564902440468053}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import homotopy.elims.CofPushoutSection as CofPushoutSection\n\nmodule homotopy.SmashIsCofiber {i j} (X : Ptd i) (Y : Ptd j) where\n\n{- the proof that our smash matches the more classical definition as a cofiber -}\n\nSmash-equiv-Cof : Smash X Y ≃ Cofiber (∨-to-× {X = X} {Y = Y})\nSmash-equiv-Cof = equiv to from to-from from-to where\n module To = SmashRec {C = Cofiber (∨-to-× {X = X} {Y = Y})}\n (curry cfcod) cfbase cfbase\n (λ x → ! (cfglue (winl x)))\n (λ y → ! (cfglue (winr y)))\n to : Smash X Y → Cofiber (∨-to-× {X = X} {Y = Y})\n to = To.f\n\n module FromGlue = WedgeElim\n {P = λ x∨y → smin (pt X) (pt Y) == uncurry smin (∨-to-× {X = X} {Y = Y} x∨y)}\n (λ x → smgluel (pt X) ∙' ! (smgluel x))\n (λ y → smgluer (pt Y) ∙' ! (smgluer y))\n (↓-cst=app-in $\n ap2 _∙'_ (!-inv'-r (smgluel (pt X)))\n ( ap-∘ (uncurry smin) (∨-to-× {X = X} {Y = Y}) wglue\n ∙ ap (ap (uncurry smin)) (∨-to-×-glue-β {X = X} {Y = Y}))\n ∙ ! (!-inv'-r (smgluer (pt Y))))\n\n module From = CofiberRec {C = Smash X Y}\n (smin (pt X) (pt Y)) (uncurry smin)\n FromGlue.f\n\n from : Cofiber (∨-to-× {X = X} {Y = Y}) → Smash X Y\n from = From.f\n\n abstract\n from-to : ∀ x → from (to x) == x\n from-to = Smash-elim\n (λ _ _ → idp) (smgluel (pt X)) (smgluer (pt Y))\n (λ x → ↓-∘=idf-in' from to $\n ap from (ap to (smgluel x)) ∙' smgluel (pt X)\n =⟨ ap (_∙' smgluel (pt X)) $ \n ap from (ap to (smgluel x))\n =⟨ ap (ap from) (To.smgluel-β x) ⟩\n ap from (! (cfglue (winl x)))\n =⟨ ap-! from (cfglue (winl x)) ⟩\n ! (ap from (cfglue (winl x)))\n =⟨ ap ! $ From.glue-β (winl x) ⟩\n ! (smgluel (pt X) ∙' ! (smgluel x))\n =⟨ !-∙' (smgluel (pt X)) (! (smgluel x)) ⟩\n ! (! (smgluel x)) ∙' ! (smgluel (pt X))\n =∎ ⟩\n (! (! (smgluel x)) ∙' ! (smgluel (pt X))) ∙' smgluel (pt X)\n =⟨ ∙'-assoc (! (! (smgluel x))) (! (smgluel (pt X))) (smgluel (pt X)) ⟩\n ! (! (smgluel x)) ∙' ! (smgluel (pt X)) ∙' smgluel (pt X)\n =⟨ ap2 _∙'_ (!-! (smgluel x)) (!-inv'-l (smgluel (pt X))) ⟩\n smgluel x\n =∎)\n (λ y → ↓-∘=idf-in' from to $\n ap from (ap to (smgluer y)) ∙' smgluer (pt Y)\n =⟨ ap (_∙' smgluer (pt Y)) $ \n ap from (ap to (smgluer y))\n =⟨ ap (ap from) (To.smgluer-β y) ⟩\n ap from (! (cfglue (winr y)))\n =⟨ ap-! from (cfglue (winr y)) ⟩\n ! (ap from (cfglue (winr y)))\n =⟨ ap ! $ From.glue-β (winr y) ⟩\n ! (smgluer (pt Y) ∙' ! (smgluer y))\n =⟨ !-∙' (smgluer (pt Y)) (! (smgluer y)) ⟩\n ! (! (smgluer y)) ∙' ! (smgluer (pt Y))\n =∎ ⟩\n (! (! (smgluer y)) ∙' ! (smgluer (pt Y))) ∙' smgluer (pt Y)\n =⟨ ∙'-assoc (! (! (smgluer y))) (! (smgluer (pt Y))) (smgluer (pt Y)) ⟩\n ! (! (smgluer y)) ∙' ! (smgluer (pt Y)) ∙' smgluer (pt Y)\n =⟨ ap2 _∙'_ (!-! (smgluer y)) (!-inv'-l (smgluer (pt Y))) ⟩\n smgluer y\n =∎)\n\n to-from : ∀ x → to (from x) == x\n to-from = CofPushoutSection.elim\n (λ _ → unit) (λ _ → idp)\n (! (cfglue (winr (pt Y)))) (λ _ → idp)\n (λ x → ↓-∘=idf-in' to from $\n ap to (ap from (cfglue (winl x)))\n =⟨ ap (ap to) (From.glue-β (winl x)) ⟩\n ap to (FromGlue.f (winl x))\n =⟨ ap-∙' to (smgluel (pt X)) (! (smgluel x)) ⟩\n ap to (smgluel (pt X)) ∙' ap to (! (smgluel x))\n =⟨ ap2 _∙'_\n (To.smgluel-β (pt X))\n (ap-! to (smgluel x) ∙ ap ! (To.smgluel-β x) ∙ !-! (cfglue (winl x))) ⟩\n ! (cfglue (winl (pt X))) ∙' cfglue (winl x)\n =⟨ ap (λ p → ! p ∙' cfglue (winl x)) $\n ap (cfglue (winl (pt X)) ∙'_)\n ( ap (ap cfcod) (! ∨-to-×-glue-β)\n ∙ ∘-ap cfcod ∨-to-× wglue)\n ∙ ↓-cst=app-out (apd cfglue wglue)\n ⟩\n ! (cfglue (winr (pt Y))) ∙' cfglue (winl x)\n =⟨ ∙'=∙ (! (cfglue (winr (pt Y)))) (cfglue (winl x)) ⟩\n ! (cfglue (winr (pt Y))) ∙ cfglue (winl x)\n =∎)\n (λ y → ↓-∘=idf-in' to from $\n ap to (ap from (cfglue (winr y)))\n =⟨ ap (ap to) (From.glue-β (winr y)) ⟩\n ap to (FromGlue.f (winr y))\n =⟨ ap-∙' to (smgluer (pt Y)) (! (smgluer y)) ⟩\n ap to (smgluer (pt Y)) ∙' ap to (! (smgluer y))\n =⟨ ap2 _∙'_\n (To.smgluer-β (pt Y))\n (ap-! to (smgluer y) ∙ ap ! (To.smgluer-β y) ∙ !-! (cfglue (winr y))) ⟩\n ! (cfglue (winr (pt Y))) ∙' cfglue (winr y)\n =⟨ ∙'=∙ (! (cfglue (winr (pt Y)))) (cfglue (winr y)) ⟩\n ! (cfglue (winr (pt Y))) ∙ cfglue (winr y)\n =∎)\n\nSmash-⊙equiv-Cof : ⊙Smash X Y ⊙≃ ⊙Cofiber (∨-⊙to-× {X = X} {Y = Y})\nSmash-⊙equiv-Cof = ≃-to-⊙≃ Smash-equiv-Cof (! (cfglue (winl (pt X))))\n", "meta": {"hexsha": "a87a878e6e1575596b850003f1fb124ee7740df5", "size": 4958, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/SmashIsCofiber.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/homotopy/SmashIsCofiber.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/homotopy/SmashIsCofiber.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 41.6638655462, "max_line_length": 85, "alphanum_fraction": 0.4324324324, "num_tokens": 2121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7185943925708561, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.3564902440468053}} {"text": "module Base.Prelude.Integer where\n\nopen import Data.Nat using (ℕ; zero; suc)\nopen import Data.Integer using (+_; -_) renaming (ℤ to ℤᵖ; _+_ to _+ᵖ_; _-_ to _-ᵖ_; _*_ to _*ᵖ_)\nopen import Data.Integer.Properties using (_≤?_; _>=_)\nopen import Base.Partial using (Partial; error)\nopen import Base.Prelude.Bool using (𝔹; not)\nopen import Base.Prelude.Unit using (⊤ᵖ)\n\n\nℤ : (Shape : Set) → (Shape → Set) → Set\nℤ _ _ = ℤᵖ\n\n_+_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (ℤ S P)\nmx + my = mx >>= λ x → my >>= λ y → pure (x +ᵖ y)\n\n_-_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (ℤ S P)\nmx - my = mx >>= λ x → my >>= λ y → pure (x -ᵖ y)\n\n_*_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (ℤ S P)\nmx * my = mx >>= λ x → my >>= λ y → pure (x *ᵖ y)\n\n_≤_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)\nmx ≤ my = mx >>= λ x → my >>= λ y → pure ⌊ x ≤? y ⌋\n\n_<_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)\nmx < my = mx >>= λ x → my >>= λ y → pure ⌊ x _ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)\nmx > my = my ≤ mx\n\n_≥_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)\nmx ≥ my = my < mx\n\n_≟_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)\nmx ≟ my = mx >>= λ x → my >>= λ y → pure ⌊ x ≟ᵖ y ⌋\n\n_≠_ : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (𝔹 S P)\nmx ≠ my = not (mx ≟ my)\n\ninstance\n number : Number ℤᵖ\n number = record\n { Constraint = λ _ → ⊤ᵖ\n ; fromNat = λ n → + n\n }\n\n negative : Negative ℤᵖ\n negative = record\n { Constraint = λ _ → ⊤ᵖ\n ; fromNeg = λ n → - (+ n)\n }\n\n_^ᵖ_ : ℤᵖ → ℕ → ℤᵖ\nb ^ᵖ 0 = 1\nb ^ᵖ suc e = b *ᵖ (b ^ᵖ e)\n\n-- If it encounters a negative exponent the Haskell implementation of @(^)@ raises an exception using @errorWithoutStackTrace@.\n_^_ : ∀ {S P} → ⦃ Partial S P ⦄ → Free S P (ℤ S P) → Free S P (ℤ S P) → Free S P (ℤ S P)\nmb ^ me = me >>= λ where\n (ℤᵖ.negsuc _) → error \"Negative exponent\"\n (+ 0) → pure 1\n (+ (suc e)) → mb >>= λ b → pure (b ^ᵖ suc e)\n\nneg : ∀ {S P} → Free S P (ℤ S P) → Free S P (ℤ S P)\nneg x = pure -1 * x\n", "meta": {"hexsha": "56040a565b29ca879b6c33b5e9845a228d5782b3", "size": 2505, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "base/agda/Base/Prelude/Integer.agda", "max_stars_repo_name": "FreeProving/free-compiler", "max_stars_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2020-02-06T11:03:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-21T13:38:23.000Z", "max_issues_repo_path": "base/agda/Base/Prelude/Integer.agda", "max_issues_repo_name": "FreeProving/free-compiler", "max_issues_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 120, "max_issues_repo_issues_event_min_datetime": "2020-04-09T09:40:39.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-08T07:46:01.000Z", "max_forks_repo_path": "base/agda/Base/Prelude/Integer.agda", "max_forks_repo_name": "FreeProving/free-compiler", "max_forks_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-04-08T11:23:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-14T07:48:41.000Z", "avg_line_length": 33.4, "max_line_length": 127, "alphanum_fraction": 0.5125748503, "num_tokens": 1080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7185943805178139, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.3564902380673654}} {"text": "------------------------------------------------------------------------------\n-- Properties stated in the Burstall's paper\n------------------------------------------------------------------------------\n\n{-# OPTIONS --exact-split #-}\n{-# OPTIONS --no-sized-types #-}\n{-# OPTIONS --no-universe-polymorphism #-}\n{-# OPTIONS --without-K #-}\n\nmodule FOTC.Program.SortList.PropertiesATP where\n\nopen import FOTC.Base\nopen import FOTC.Base.List\nopen import FOTC.Data.Bool.PropertiesATP\nopen import FOTC.Data.Nat.Inequalities\nopen import FOTC.Data.Nat.Inequalities.PropertiesATP\nopen import FOTC.Data.Nat.List.Type\nopen import FOTC.Data.Nat.Type\nopen import FOTC.Data.List\nopen import FOTC.Data.List.PropertiesATP\nopen import FOTC.Program.SortList.Properties.Totality.BoolATP\nopen import FOTC.Program.SortList.Properties.Totality.ListN-ATP\nopen import FOTC.Program.SortList.Properties.Totality.OrdList.FlattenATP\nopen import FOTC.Program.SortList.Properties.Totality.OrdListATP\nopen import FOTC.Program.SortList.Properties.Totality.OrdTreeATP\nopen import FOTC.Program.SortList.Properties.Totality.TreeATP\nopen import FOTC.Program.SortList.SortList\n\n------------------------------------------------------------------------------\n-- Burstall's lemma: If t is ordered then totree(i, t) is ordered.\ntoTree-OrdTree : ∀ {item t} → N item → Tree t → OrdTree t →\n OrdTree (toTree · item · t)\ntoTree-OrdTree {item} Nitem tnil OTt = prf\n where postulate prf : OrdTree (toTree · item · nil)\n {-# ATP prove prf #-}\n\ntoTree-OrdTree {item} Nitem (ttip {i} Ni) OTt =\n case prf₁ prf₂ (x>y∨x≤y Ni Nitem)\n where\n postulate prf₁ : i > item → OrdTree (toTree · item · tip i)\n {-# ATP prove prf₁ x≤x xy→x≰y #-}\n\n postulate prf₂ : i ≤ item → OrdTree (toTree · item · tip i)\n {-# ATP prove prf₂ x≤x #-}\n\ntoTree-OrdTree {item} Nitem (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) OTtnode =\n case (prf₁ (toTree-OrdTree Nitem Tt₁ (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))\n (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))\n (prf₂ (toTree-OrdTree Nitem Tt₂ (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))\n (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))\n (x>y∨x≤y Ni Nitem)\n where\n postulate prf₁ : ordTree (toTree · item · t₁) ≡ true →\n OrdTree t₂ →\n i > item →\n OrdTree (toTree · item · node t₁ i t₂)\n {-# ATP prove prf₁ &&-list₄-t x>y→x≰y le-ItemTree-Bool le-TreeItem-Bool ordTree-Bool toTree-OrdTree-helper₁ #-}\n\n postulate prf₂ : ordTree (toTree · item · t₂) ≡ true →\n OrdTree t₁ →\n i ≤ item →\n OrdTree (toTree · item · node t₁ i t₂)\n {-# ATP prove prf₂ &&-list₄-t le-ItemTree-Bool le-TreeItem-Bool ordTree-Bool toTree-OrdTree-helper₂ #-}\n\n------------------------------------------------------------------------------\n-- Burstall's lemma: ord(maketree(is)).\n\n-- makeTree-TreeOrd : ∀ {is} → ListN is → OrdTree (makeTree is)\n-- makeTree-TreeOrd LNis =\n-- ind-lit OrdTree toTree nil LNis ordTree-nil\n-- (λ Nx y TOy → toTree-OrdTree Nx {!!} TOy)\n\nmakeTree-OrdTree : ∀ {is} → ListN is → OrdTree (makeTree is)\nmakeTree-OrdTree lnnil = prf\n where postulate prf : OrdTree (makeTree [])\n {-# ATP prove prf #-}\n\nmakeTree-OrdTree (lncons {i} {is} Ni Lis) = prf (makeTree-OrdTree Lis)\n where postulate prf : OrdTree (makeTree is) → OrdTree (makeTree (i ∷ is))\n {-# ATP prove prf makeTree-Tree toTree-OrdTree #-}\n\n------------------------------------------------------------------------------\n-- Burstall's lemma: If ord(is1) and ord(is2) and is1 ≤ is2 then\n-- ord(concat(is1, is2)).\n++-OrdList : ∀ {is js} → ListN is → ListN js → OrdList is → OrdList js →\n ≤-Lists is js → OrdList (is ++ js)\n\n++-OrdList {js = js} lnnil LNjs LOis LOjs is≤js =\n subst OrdList (sym (++-leftIdentity js)) LOjs\n\n++-OrdList {js = js} (lncons {i} {is} Ni LNis) LNjs OLi∷is OLjs i∷is≤js =\n subst OrdList\n (sym (++-∷ i is js))\n (lemma (++-OrdList LNis LNjs\n (subList-OrdList Ni LNis OLi∷is)\n OLjs\n (&&-list₂-t₂ (le-ItemList-Bool Ni LNjs)\n (le-Lists-Bool LNis LNjs)\n (trans (sym (le-Lists-∷ i is js)) i∷is≤js))))\n where postulate lemma : OrdList (is ++ js) → OrdList (i ∷ is ++ js)\n {-# ATP prove lemma &&-list₂-t ++-OrdList-helper le-ItemList-Bool le-Lists-Bool ordList-Bool #-}\n\n------------------------------------------------------------------------------\n-- Burstall's lemma: If t is ordered then (flatten t) is ordered.\nflatten-OrdList : ∀ {t} → Tree t → OrdTree t → OrdList (flatten t)\nflatten-OrdList tnil OTt =\n subst OrdList (sym flatten-nil) ordList-[]\n\nflatten-OrdList (ttip {i} Ni) OTt = prf\n where postulate prf : OrdList (flatten (tip i))\n {-# ATP prove prf #-}\n\nflatten-OrdList (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) OTt\n = prf (++-OrdList (flatten-ListN Tt₁)\n (flatten-ListN Tt₂)\n (flatten-OrdList Tt₁ (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTt))\n (flatten-OrdList Tt₂ (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTt))\n (flatten-OrdList-helper Tt₁ Ni Tt₂ OTt))\n where postulate prf : OrdList (flatten t₁ ++ flatten t₂) → -- Indirect IH.\n OrdList (flatten (node t₁ i t₂))\n {-# ATP prove prf #-}\n", "meta": {"hexsha": "4a2e4094ca5cf653a394d630c38c3a4ed2ffed8c", "size": 5453, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/fot/FOTC/Program/SortList/PropertiesATP.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": "src/fot/FOTC/Program/SortList/PropertiesATP.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": "src/fot/FOTC/Program/SortList/PropertiesATP.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": 44.6967213115, "max_line_length": 113, "alphanum_fraction": 0.5670273244, "num_tokens": 1635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5660185498374789, "lm_q2_score": 0.6297746213017459, "lm_q1q2_score": 0.35646411787366167}} {"text": "{-# OPTIONS --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Properties.Reflexivity {{eqrel : EqRelSet}} where\n\nopen import Definition.Untyped\nopen import Definition.Typed\nopen import Definition.LogicalRelation\n\nopen import Tools.Product\nopen import Tools.Empty\nimport Tools.PropositionalEquality as PE\n\n\nimport Data.Fin as Fin\nimport Data.Nat as Nat\n\n-- Reflexivity of reducible types.\nreflEq : ∀ {l Γ A r} ([A] : Γ ⊩⟨ l ⟩ A ^ r) → Γ ⊩⟨ l ⟩ A ≡ A ^ r / [A]\nreflEq (Uᵣ′ _ _ _ _ l< PE.refl D) = red D\nreflEq (ℕᵣ D) = red D\nreflEq (Emptyᵣ D) = red D\nreflEq (ne′ K [[ ⊢A , ⊢B , D ]] neK K≡K) =\n ne₌ _ [[ ⊢A , ⊢B , D ]] neK K≡K\nreflEq (Πᵣ′ rF lF lG _ _ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) =\n Π₌ _ _ D A≡A\n (λ ρ ⊢Δ → reflEq ([F] ρ ⊢Δ))\n (λ ρ ⊢Δ [a] → reflEq ([G] ρ ⊢Δ [a]))\nreflEq (∃ᵣ′ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) =\n ∃₌ _ _ D A≡A\n (λ ρ ⊢Δ → reflEq ([F] ρ ⊢Δ))\n (λ ρ ⊢Δ [a] → reflEq ([G] ρ ⊢Δ [a]))\nreflEq {ι ¹} (emb X [A]) = reflEq [A]\nreflEq {∞} (emb X [A]) = reflEq [A]\n\nreflNatural-prop : ∀ {Γ n}\n → Natural-prop Γ n\n → [Natural]-prop Γ n n\nreflNatural-prop (sucᵣ (ℕₜ n d t≡t prop)) =\n sucᵣ (ℕₜ₌ n n d d t≡t\n (reflNatural-prop prop))\nreflNatural-prop zeroᵣ = zeroᵣ\nreflNatural-prop (ne (neNfₜ neK ⊢k k≡k)) = ne (neNfₜ₌ neK neK k≡k)\n\nreflEmpty-prop : ∀ {Γ n l}\n → Empty-prop Γ n l\n → [Empty]-prop Γ n n l\nreflEmpty-prop (ne x) = ne x x\n\n-- Reflexivity of reducible terms.\n-- We proceed in a layered way because Agda does not understand our\n-- recursions are well founded\n\nreflEqTerm⁰ : ∀ {Γ A t r} ([A] : Γ ⊩⟨ ι ⁰ ⟩ A ^ r)\n → Γ ⊩⟨ ι ⁰ ⟩ t ∷ A ^ r / [A]\n → Γ ⊩⟨ ι ⁰ ⟩ t ≡ t ∷ A ^ r / [A]\nreflEqTerm⁰ (ℕᵣ D) (ℕₜ n [[ ⊢t , ⊢u , d ]] t≡t prop) =\n ℕₜ₌ n n [[ ⊢t , ⊢u , d ]] [[ ⊢t , ⊢u , d ]] t≡t\n (reflNatural-prop prop)\nreflEqTerm⁰ (Emptyᵣ D) (Emptyₜ (ne x)) = Emptyₜ₌ (ne x x)\nreflEqTerm⁰ {r = [ ! , l ]} (ne′ K D neK K≡K) (neₜ k d (neNfₜ neK₁ ⊢k k≡k)) =\n neₜ₌ k k d d (neNfₜ₌ neK₁ neK₁ k≡k)\nreflEqTerm⁰ {r = [ % , l ]} (ne′ K D neK K≡K) (neₜ d) = neₜ₌ d d\nreflEqTerm⁰ {r = [ ! , l ]} (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ f d funcF f≡f [f] [f]₁) =\n Πₜ₌ f f d d funcF funcF f≡f\n (Πₜ f d funcF f≡f [f] [f]₁)\n (Πₜ f d funcF f≡f [f] [f]₁)\n (λ ρ ⊢Δ [a] → [f] ρ ⊢Δ [a] [a] (reflEqTerm⁰ ([F] ρ ⊢Δ) [a]))\nreflEqTerm⁰ {r = [ % , l ]} (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) X = X , X\nreflEqTerm⁰ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) X = X , X\n\nreflEqTerm¹ : ∀ {Γ A t r} ([A] : Γ ⊩⟨ ι ¹ ⟩ A ^ r)\n → Γ ⊩⟨ ι ¹ ⟩ t ∷ A ^ r / [A]\n → Γ ⊩⟨ ι ¹ ⟩ t ≡ t ∷ A ^ r / [A]\nreflEqTerm¹ (Uᵣ (Uᵣ r ⁰ X PE.refl D)) (Uₜ A d typeA A≡A [A]) =\n Uₜ₌ (Uₜ A d typeA A≡A [A]) (Uₜ A d typeA A≡A [A])\n A≡A (λ [ρ] ⊢Δ → reflEq ([A] [ρ] ⊢Δ))\nreflEqTerm¹ (Uᵣ (Uᵣ r ¹ () PE.refl D)) (Uₜ A d typeA A≡A [A])\nreflEqTerm¹ (ℕᵣ D) (ℕₜ n [[ ⊢t , ⊢u , d ]] t≡t prop) =\n ℕₜ₌ n n [[ ⊢t , ⊢u , d ]] [[ ⊢t , ⊢u , d ]] t≡t\n (reflNatural-prop prop)\nreflEqTerm¹ (Emptyᵣ D) (Emptyₜ (ne x)) = Emptyₜ₌ (ne x x)\nreflEqTerm¹ {r = [ ! , l ]} (ne′ K D neK K≡K) (neₜ k d (neNfₜ neK₁ ⊢k k≡k)) =\n neₜ₌ k k d d (neNfₜ₌ neK₁ neK₁ k≡k)\nreflEqTerm¹ {r = [ % , l ]} (ne′ K D neK K≡K) (neₜ d) = neₜ₌ d d\nreflEqTerm¹ {r = [ ! , l ]} (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ f d funcF f≡f [f] [f]₁) =\n Πₜ₌ f f d d funcF funcF f≡f\n (Πₜ f d funcF f≡f [f] [f]₁)\n (Πₜ f d funcF f≡f [f] [f]₁)\n (λ ρ ⊢Δ [a] → [f] ρ ⊢Δ [a] [a] (reflEqTerm¹ ([F] ρ ⊢Δ) [a]))\nreflEqTerm¹ {r = [ % , l ]} (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) X = X , X\nreflEqTerm¹ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) X = X , X\nreflEqTerm¹ (emb X [A]) = reflEqTerm⁰ [A]\n\nreflEqTerm∞ : ∀ {Γ A t r} ([A] : Γ ⊩⟨ ∞ ⟩ A ^ r)\n → Γ ⊩⟨ ∞ ⟩ t ∷ A ^ r / [A]\n → Γ ⊩⟨ ∞ ⟩ t ≡ t ∷ A ^ r / [A]\nreflEqTerm∞ (Uᵣ (Uᵣ r ⁰ X eq D)) (Uₜ A d typeA A≡A [A]) =\n Uₜ₌ (Uₜ A d typeA A≡A [A]) (Uₜ A d typeA A≡A [A]) A≡A (λ [ρ] ⊢Δ → reflEq ([A] [ρ] ⊢Δ))\nreflEqTerm∞ (Uᵣ (Uᵣ r ¹ X eq D)) (Uₜ A d typeA A≡A [A]) =\n Uₜ₌ (Uₜ A d typeA A≡A [A]) (Uₜ A d typeA A≡A [A]) A≡A (λ [ρ] ⊢Δ → reflEq ([A] [ρ] ⊢Δ))\nreflEqTerm∞ (ℕᵣ D) (ℕₜ n [[ ⊢t , ⊢u , d ]] t≡t prop) =\n ℕₜ₌ n n [[ ⊢t , ⊢u , d ]] [[ ⊢t , ⊢u , d ]] t≡t\n (reflNatural-prop prop)\nreflEqTerm∞ (Emptyᵣ D) (Emptyₜ (ne x)) = Emptyₜ₌ (ne x x)\nreflEqTerm∞ {r = [ ! , l ]} (ne′ K D neK K≡K) (neₜ k d (neNfₜ neK₁ ⊢k k≡k)) =\n neₜ₌ k k d d (neNfₜ₌ neK₁ neK₁ k≡k)\nreflEqTerm∞ {r = [ % , l ]} (ne′ K D neK K≡K) (neₜ d) = neₜ₌ d d\nreflEqTerm∞ {r = [ ! , l ]} (Πᵣ′ rF lF lG _ _ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ f d funcF f≡f [f] [f]₁) =\n Πₜ₌ f f d d funcF funcF f≡f\n (Πₜ f d funcF f≡f [f] [f]₁)\n (Πₜ f d funcF f≡f [f] [f]₁)\n (λ ρ ⊢Δ [a] → [f] ρ ⊢Δ [a] [a] (reflEqTerm∞ ([F] ρ ⊢Δ) [a]))\nreflEqTerm∞ {r = [ % , l ]} (Πᵣ′ rF lF lG F G _ _ D ⊢F ⊢G A≡A [F] [G] G-ext) X = X , X\nreflEqTerm∞ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) X = X , X\nreflEqTerm∞ (emb X [A]) = reflEqTerm¹ [A]\n\nreflEqTerm : ∀ {l Γ A t r} ([A] : Γ ⊩⟨ l ⟩ A ^ r)\n → Γ ⊩⟨ l ⟩ t ∷ A ^ r / [A]\n → Γ ⊩⟨ l ⟩ t ≡ t ∷ A ^ r / [A]\nreflEqTerm {l = ι ⁰} [A] [t] = reflEqTerm⁰ [A] [t]\nreflEqTerm {l = ι ¹} [A] [t] = reflEqTerm¹ [A] [t]\nreflEqTerm {l = ∞} [A] [t] = reflEqTerm∞ [A] [t]\n", "meta": {"hexsha": "a3c08d0470b30a5fe208c9e87611c53eda0e1102", "size": 5288, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Properties/Reflexivity.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/LogicalRelation/Properties/Reflexivity.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/LogicalRelation/Properties/Reflexivity.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": 42.304, "max_line_length": 106, "alphanum_fraction": 0.4882753404, "num_tokens": 3051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494421679929, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.35636536098741645}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Names used in the reflection machinery\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Reflection.Name where\n\nopen import Data.List.Base\nimport Data.Product.Properties as Prodₚ\nimport Data.Word.Properties as Wₚ\nopen import Function\nopen import Relation.Nullary.Decidable using (map′)\nopen import Relation.Binary\nimport Relation.Binary.Construct.On as On\nopen import Relation.Binary.PropositionalEquality\n\n----------------------------------------------------------------------\n-- Re-export built-ins\n\nopen import Agda.Builtin.Reflection public\n using (Name) renaming (primQNameToWord64s to toWords)\n\nopen import Agda.Builtin.Reflection.Properties public\n renaming (primQNameToWord64sInjective to toWords-injective)\n\n----------------------------------------------------------------------\n-- More definitions\n----------------------------------------------------------------------\n\nNames : Set\nNames = List Name\n\n----------------------------------------------------------------------\n-- Decidable equality for names\n----------------------------------------------------------------------\n\n_≈_ : Rel Name _\n_≈_ = _≡_ on toWords\n\ninfix 4 _≈?_ _≟_\n\n_≈?_ : Decidable _≈_\n_≈?_ = On.decidable toWords _≡_ (Prodₚ.≡-dec Wₚ._≟_ Wₚ._≟_)\n\n_≟_ : DecidableEquality Name\nm ≟ n = map′ (toWords-injective _ _) (cong toWords) (m ≈? n)\n", "meta": {"hexsha": "26b579ea411fbc6ce6541b56ccdf93dbd856c8e8", "size": 1492, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "agda-stdlib/src/Reflection/Name.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "agda-stdlib/src/Reflection/Name.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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-stdlib/src/Reflection/Name.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 29.84, "max_line_length": 72, "alphanum_fraction": 0.5013404826, "num_tokens": 307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6859494421679929, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.3563653609874164}} {"text": "{- Formal verification of authenticated append-only skiplists in Agda, version 1.0.\n\n Copyright (c) 2020 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-}\nopen import Data.Unit.NonEta\nopen import Data.Empty\nopen import Data.Sum\nopen import Data.Product\nopen import Data.Product.Properties\nopen import Data.Fin hiding (_<_; _≤_)\nopen import Data.Fin.Properties using () renaming (_≟_ to _≟Fin_)\nopen import Data.Nat renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_)\nopen import Data.Nat.Properties\nopen import Data.List renaming (map to List-map)\nopen import Data.List.Properties using (∷-injective; length-map)\nopen import Data.List.Relation.Unary.Any renaming (map to Any-map)\nopen import Data.List.Relation.Unary.All renaming (lookup to All-lookup; map to All-map)\nopen import Data.List.Relation.Unary.All.Properties hiding (All-map)\nopen import Data.List.Relation.Unary.Any.Properties renaming (map⁺ to Any-map⁺)\nopen import Data.List.Relation.Binary.Pointwise using (decidable-≡)\nopen import Data.Bool hiding (_<_; _≤_)\nopen import Data.Maybe renaming (map to Maybe-map)\nopen import Function\n\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Binary.Core\nopen import Relation.Nullary\n\nopen import AAOSL.Lemmas\nopen import AAOSL.Abstract.Hash\nopen import AAOSL.Abstract.DepRel\n\n-- This module defines the DepRel type, which represents the class of AAOSLs we\n-- consider, and proves properties about any DepRel.\n\nmodule AAOSL.Abstract.Advancement\n -- A Hash function maps a bytestring into a hash.\n (hash : ByteString → Hash)\n -- And is collision resistant\n (hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y)\n\n -- Indexes can be encoded in an injective way\n (encodeI : ℕ → ByteString)\n (encodeI-inj : (m n : ℕ) → encodeI m ≡ encodeI n → m ≡ n)\n\n (dep : DepRel)\n where\n\n -- Brings the DepRel names into scope instantiated\n -- for the module parameters in question.\n open DepRel dep\n\n hop-prog : ∀{m}(h : HopFrom m) → hop-tgt h ≢ m\n hop-prog = <⇒≢ ∘ hop-<\n\n hop-≤ : ∀{m}(h : HopFrom m) → hop-tgt h ≤ m\n hop-≤ = <⇒≤ ∘ hop-<\n\n depsof : ℕ → List ℕ\n depsof 0 = []\n depsof (suc i) = List-map hop-tgt (nats (lvlof (suc i)))\n\n depsof-ne : ∀ m → depsof m ≡ [] → m ≡ 0\n depsof-ne 0 hyp = refl\n depsof-ne (suc m) hyp =\n let le0 = trans (sym (length-map hop-tgt (nats (lvlof (suc m)))) )\n (cong length hyp)\n le-nz = nats-length (lvlof-s m)\n in ⊥-elim (1≤0-⊥ (subst (1 ≤_) le0 le-nz))\n\n hopFromZ-⊥ : (h : HopFrom 0) → ⊥\n hopFromZ-⊥ h = fin0-⊥ (subst Fin lvlof-z h)\n where fin0-⊥ : Fin 0 → ⊥\n fin0-⊥ ()\n\n hop-tgt-is-dep : {m : ℕ}(h : HopFrom m)\n → hop-tgt h ∈ depsof m\n hop-tgt-is-dep {0} h = ⊥-elim (hopFromZ-⊥ h)\n hop-tgt-is-dep {suc m} h = Any-map⁺ (Any-map (cong hop-tgt) (nats-correct h))\n\n -- Two simple but useful lemmas made to work over our abstract\n -- index type.\n ≤-≢-mon : ∀{i j tgt} → tgt ≢ j → tgt ≤ j → i ≤ tgt → i ≢ j\n ≤-≢-mon tgt≢j tgt≤j i≤tgt i≡j\n = tgt≢j (sym (≤-antisym (subst (_≤ _) i≡j i≤tgt) tgt≤j))\n\n ≟ℕ-refl : (s : ℕ) → (s ≟ℕ s) ≡ yes refl\n ≟ℕ-refl s with s ≟ℕ s\n ...| no abs = ⊥-elim (abs refl)\n ...| yes refl = refl\n\n ⊥-prop : (a b : ⊥) → a ≡ b\n ⊥-prop () ()\n\n ≟ℕ-neg : (m n : ℕ) → (p : m ≢ n) → (m ≟ℕ n) ≡ no p\n ≟ℕ-neg m n p with m ≟ℕ n\n ...| yes imp = ⊥-elim (p imp)\n ...| no r = cong no (fun-ext (λ x → ⊥-prop (r x) (p x)))\n\n HopFrom≢0 : ∀{j}(h : HopFrom j) → j ≢ 0\n HopFrom≢0 {j} h refl = hopFromZ-⊥ h\n\n open WithCryptoHash hash hash-cr\n\n -- This function is total, even though we won't always know a hash for every\n -- index. That's ok, we only use the hashes of the relevant indexes.\n View : Set\n View = ℕ → Hash\n\n -- An inhabitant of 'Agree s t ixs' is a proof that the views s and t\n -- agree on the hash of every index i ∈ ixs.\n Agree : View → View → List ℕ → Set\n Agree v u = All (λ s → v s ≡ u s)\n\n -- Returns the list of hashes that the authenticator\n -- at the given index depends on.\n deps-hash : ℕ → View → List Hash\n deps-hash s tbl = List-map tbl (depsof s)\n\n -- TODO-2: Make auth, auth-inj-1 and auth-inj-2 module parameters\n -- TODO-1: Make sure the names are consistent with the paper\n\n --------------------------\n -- Defining authenticators\n\n -- Authenticators will depend on all p-auths of the\n -- dependencies of a node.\n auth : (s : ℕ) → Hash → View → Hash\n auth s h tbl = hash-concat (hash (encodeI s) ∷ h ∷ deps-hash s tbl)\n\n -- We will be using two separate injectivity functions. One is\n -- for the hash of the data in a node, which can't be the\n -- initial node!\n auth-inj-1 : {j : ℕ}{h₁ h₂ : Hash}{t₁ t₂ : View}\n → j ≢ 0\n → auth j h₁ t₁ ≡ auth j h₂ t₂\n → HashBroke ⊎ h₁ ≡ h₂\n auth-inj-1 {j} {h₁} {h₂} {t₁} {t₂} j≢s₀ hip\n with hash-concat-inj { hash (encodeI j) ∷ h₁ ∷ deps-hash j t₁ }\n { hash (encodeI j) ∷ h₂ ∷ deps-hash j t₂ } hip\n ...| inj₁ hb = inj₁ hb\n ...| inj₂ r = inj₂ (proj₁ (∷-injective (proj₂ (∷-injective r))))\n\n -- The second one does induction on the list of dependencies.\n auth-inj-2 : {i : ℕ}{h : Hash}(t₁ t₂ : View)\n → auth i h t₁ ≡ auth i h t₂\n → HashBroke ⊎ Agree t₁ t₂ (depsof i)\n auth-inj-2 {i} {h} t₁ t₂ hip\n with hash-concat-inj { hash (encodeI i) ∷ h ∷ deps-hash i t₁ }\n { hash (encodeI i) ∷ h ∷ deps-hash i t₂ } hip\n ...| inj₁ hb = inj₁ hb\n ...| inj₂ r = inj₂ (auth-inj-2-aux t₁ t₂ (depsof i) (proj₂ (∷-injective (proj₂ (∷-injective r)))))\n where\n auth-inj-2-aux : (t₁ t₂ : View)(l : List ℕ)\n → List-map t₁ l ≡ List-map t₂ l\n → Agree t₁ t₂ l\n auth-inj-2-aux t1 t2 [] hyp = []\n auth-inj-2-aux t1 t2 (x ∷ l) hyp = proj₁ (∷-injective hyp) ∷ auth-inj-2-aux t1 t2 l (proj₂ (∷-injective hyp))\n\n ------------------------\n ------------------------\n -- Advancement Proofs --\n ------------------------\n ------------------------\n\n -- Finally, advancement proofs in their simple variant\n data AdvPath : ℕ → ℕ → Set where\n AdvDone : ∀{i} → AdvPath i i\n AdvThere : ∀{j i}\n → Hash -- datum digest\n → (h : HopFrom j)\n → AdvPath (hop-tgt h) i\n → AdvPath j i\n\n -- Override a view with a hash for a specific index.\n _∪₁_ : View → ℕ × Hash → View\n _∪₁_ tbl (s , h) s'\n with s ≟ℕ s'\n ...| yes _ = h\n ...| no _ = tbl s'\n\n -- The rebuild function is, essentially, a transformer over\n -- the current view of the skiplog. It is PARAMOUNT to return\n -- a new 'view' of the world, as we can see in rebuild-⊕ lemma.\n -- Otherwise, it becomes seriously intricate to express\n -- that rebuilding the hash of index j \"depends on\" the rebuilt\n -- hashes of j's dependencies.\n rebuild : ∀{i j} → AdvPath j i → View → View\n rebuild {i} AdvDone tbl = tbl\n rebuild (AdvThere {j = j} x h prf) tbl\n = let tbl' = rebuild prf tbl\n in tbl' ∪₁ (j , auth j x tbl')\n\n lemma1 : ∀{j i} → AdvPath j i → i ≤ j\n lemma1 AdvDone = ≤-refl\n lemma1 {j} (AdvThere x h a) = ≤-trans (lemma1 a) (hop-≤ h)\n\n rebuild-tgt-lemma : ∀{j i}(a : AdvPath j i){t : View}\n → rebuild a t i ≡ t i\n rebuild-tgt-lemma AdvDone = refl\n rebuild-tgt-lemma {j} {i} (AdvThere x h a)\n rewrite ≟ℕ-neg j i (<⇒≢ (≤-<-trans (lemma1 a) (hop-< h)) ∘ sym)\n = rebuild-tgt-lemma a\n\n lemma2 : ∀{i}(a : AdvPath i i) → a ≡ AdvDone\n lemma2 AdvDone = refl\n lemma2 (AdvThere x h a)\n = ⊥-elim (hop-prog h (sym (≤-antisym (lemma1 a) (hop-≤ h))))\n\n -- Lemma3 states that if a hop exists, then it is not from\n -- s₀. This is necessary to eliminate some nasty cases.\n lemma3 : ∀{j i} → (h : HopFrom j) → AdvPath (hop-tgt h) i → j ≢ 0\n lemma3 h a = HopFrom≢0 h\n\n ----------------------\n -- Proof Splitting --\n ----------------------\n\n _⊕_ : ∀{j k i} → AdvPath j k → AdvPath k i → AdvPath j i\n AdvDone ⊕ rest = rest\n (AdvThere d h a) ⊕ rest = AdvThere d h (a ⊕ rest)\n\n ⊕-id-r : ∀{j i}(a : AdvPath j i) → a ⊕ AdvDone ≡ a\n ⊕-id-r AdvDone = refl\n ⊕-id-r (AdvThere x h a) = cong (AdvThere x h) (⊕-id-r a)\n\n -- A value of type 'i ∈AP a' illustrates index i as a dependency\n -- of 'a'.\n data _∈AP_ (i₀ : ℕ) : {j i : ℕ} → AdvPath j i → Set where\n hereTgtDone : i₀ ∈AP (AdvDone {i₀})\n\n hereTgtThere : ∀{i}{d : Hash}{hop : HopFrom i₀}{a : AdvPath (hop-tgt hop) i}\n → i₀ ∈AP (AdvThere d hop a)\n\n step : ∀{i j}{d : Hash}{hop : HopFrom j}{a : AdvPath (hop-tgt hop) i}\n → i₀ ≢ j\n → i₀ ∈AP a\n → i₀ ∈AP (AdvThere d hop a)\n\n ∈AP-src : ∀{j i}{a : AdvPath j i}\n → j ∈AP a\n ∈AP-src {a = AdvDone} = hereTgtDone\n ∈AP-src {a = AdvThere x h a} = hereTgtThere\n\n ∈AP-tgt : ∀{j i}{a : AdvPath j i}\n → i ∈AP a\n ∈AP-tgt {a = AdvDone} = hereTgtDone\n ∈AP-tgt {a = AdvThere x h a} = step (<⇒≢ (≤-<-trans (lemma1 a) (hop-< h))) ∈AP-tgt\n\n ∈AP-≤ : ∀{j i}{a : AdvPath j i}\n → {i0 : ℕ} → i0 ∈AP a\n → i0 ≤ j\n ∈AP-≤ hereTgtDone = ≤-refl\n ∈AP-≤ hereTgtThere = ≤-refl\n ∈AP-≤ (step _ hyp) = ≤-trans (∈AP-≤ hyp) (hop-≤ _)\n\n ∈AP-≥ : ∀{j i}{a : AdvPath j i}\n → {i0 : ℕ} → i0 ∈AP a\n → i ≤ i0\n ∈AP-≥ hereTgtDone = ≤-refl\n ∈AP-≥ {a = a} hereTgtThere = lemma1 a\n ∈AP-≥ (step _ hyp) = ∈AP-≥ hyp\n\n\n rebuild-⊕' : ∀{j k i}\n → {t : View}\n → (a₁ : AdvPath j k)\n → (a₂ : AdvPath k i)\n → ∀{l} → l ∈AP a₂\n → rebuild (a₁ ⊕ a₂) t l ≡ rebuild a₂ t l\n rebuild-⊕' AdvDone a₂ hyp = refl\n rebuild-⊕' {j} (AdvThere x h a₁) a₂ {l} hyp\n with j ≟ℕ l\n ...| yes nope = ⊥-elim (≤-≢-mon (hop-prog h) (hop-≤ h)\n (≤-trans (∈AP-≤ hyp) (lemma1 a₁)) (sym nope))\n ...| no ok = rebuild-⊕' a₁ a₂ hyp\n\n ∈AP-cut : ∀{j k i}\n → (a : AdvPath j i)\n → k ∈AP a\n → Σ (AdvPath j k × AdvPath k i)\n (λ { (x , y) → a ≡ x ⊕ y })\n ∈AP-cut AdvDone hereTgtDone\n = (AdvDone , AdvDone) , refl\n ∈AP-cut (AdvThere d h a) hereTgtThere\n = (AdvDone , AdvThere d h a) , refl\n ∈AP-cut (AdvThere d h a) (step x prf)\n with ∈AP-cut a prf\n ...| xy , ind = (AdvThere d h (proj₁ xy) , proj₂ xy)\n , cong (AdvThere d h) ind\n\n ∈AP-cut₁ : ∀{j k i}\n → (a : AdvPath j i)\n → k ∈AP a\n → AdvPath k i\n ∈AP-cut₁ a prf = proj₂ (proj₁ (∈AP-cut a prf))\n\n ∈AP-∈-cut\n : ∀{j k i}\n → (a : AdvPath j i)\n → (prf : k ∈AP a)\n → ∀{m} → m ∈AP a → m ≤ k\n → m ∈AP (∈AP-cut₁ a prf)\n ∈AP-∈-cut AdvDone hereTgtDone m∈ap hyp = m∈ap\n ∈AP-∈-cut (AdvThere _ _ _) hereTgtThere m∈ap hyp = m∈ap\n ∈AP-∈-cut (AdvThere d h a) (step x prf) hereTgtThere hyp\n = ⊥-elim (<⇒≱ (hop-< h) (≤-trans hyp (∈AP-≤ prf)))\n ∈AP-∈-cut (AdvThere d h a) (step x prf) (step x₁ m∈ap) hyp\n = ∈AP-∈-cut a prf m∈ap hyp\n\n ∈AP-cut₁-rebuild\n : ∀{j k i}\n → (a : AdvPath j i)\n → (prf : k ∈AP a)\n → {s : ℕ} → (s ∈AP (∈AP-cut₁ a prf))\n → ∀{t} → rebuild a t s ≡ rebuild (∈AP-cut₁ a prf) t s\n ∈AP-cut₁-rebuild a prf s∈cut {t}\n with ∈AP-cut a prf\n ...| (x , y) , refl = rebuild-⊕' x y s∈cut\n\n rebuild-⊕ : ∀{j k i}\n → {t : View}\n → (a₁ : AdvPath j k)\n → (a₂ : AdvPath k i)\n → rebuild (a₁ ⊕ a₂) t k ≡ rebuild a₂ t k\n rebuild-⊕ {k = k} a₁ AdvDone = rebuild-⊕' a₁ AdvDone {k} hereTgtDone\n rebuild-⊕ {k = k} {i = i} a₁ (AdvThere .{k} d h p) = rebuild-⊕' a₁ (AdvThere d h p) hereTgtThere\n\n\n ∈AP-⊕ : ∀{j i₁ k i₂ i}\n → {e : AdvPath j k}{a₁ : AdvPath k i₁}\n → {a₂ : AdvPath k i₂}\n → i ∈AP (e ⊕ a₁)\n → i ∈AP a₂\n → i ∈AP a₁\n ∈AP-⊕ {e = AdvDone} hyp1 hyp2 = hyp1\n ∈AP-⊕ {e = AdvThere x h e} hereTgtThere hyp2\n with ≤-antisym (∈AP-≤ hyp2) (lemma1 (AdvThere x h e))\n ...| refl = ⊥-elim (hop-prog h (≤-antisym (hop-≤ h) (lemma1 e)))\n ∈AP-⊕ {e = AdvThere x h e} (step x₁ hyp1) hyp2 = ∈AP-⊕ hyp1 hyp2\n\n ∈AP-point' : ∀{j k i}\n → {a₁ : AdvPath j k}\n → {a₂ : AdvPath k i}\n → {m : ℕ} → m ∈AP a₁ → m ∈AP a₂\n → m ≡ k\n ∈AP-point' hereTgtDone h2 = refl\n ∈AP-point' {a₁ = AdvThere d h a₁} {a₂} hereTgtThere h2\n = ⊥-elim (≤-≢-mon (≤-≢-mon (hop-prog h) (hop-≤ h) (lemma1 a₁) ∘ sym)\n (∈AP-≤ h2)\n (lemma1 (AdvThere d h a₁)) refl)\n ∈AP-point' (step x h1) h2 = ∈AP-point' h1 h2\n\n ∈AP-point'' : ∀{j₁ j₂ i₁ i₂}\n → {a₁ : AdvPath j₁ i₁}\n → {a₂ : AdvPath j₂ i₂}\n → j₂ < i₁\n → {i : ℕ} → i ∈AP a₁ → i ∈AP a₂\n → ⊥\n ∈AP-point'' jB′)\n rewrite whnfRed* D x₂ | whnfRed* D′ x₃ =\n [↑] A″ B″ x x₁ whnfA′ whnfB′ A′<>B′\n\n-- Weak head expansion of algorithmic equality of terms.\nreductionConv↑Term : ∀ {t t′ u u′ A B Γ l}\n → Γ ⊢ A ⇒* B ^ [ ! , l ]\n → Γ ⊢ t ⇒* t′ ∷ B ^ l \n → Γ ⊢ u ⇒* u′ ∷ B ^ l\n → Whnf B\n → Whnf t′\n → Whnf u′\n → Γ ⊢ t′ [conv↑] u′ ∷ B ^ l\n → Γ ⊢ t [conv↑] u ∷ A ^ l\nreductionConv↑Term x x₁ x₂ x₃ x₄ x₅\n ([↑]ₜ B₁ t″ u″ D d d′ whnfB whnft′ whnfu′ t<>u)\n rewrite whnfRed* D x₃ | whnfRed*Term d x₄ | whnfRed*Term d′ x₅ =\n [↑]ₜ B₁ t″ u″ x x₁ x₂ whnfB whnft′ whnfu′ t<>u\n \n", "meta": {"hexsha": "ada986f14981666d635f4225de246176bce8855d", "size": 1294, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Conversion/Reduction.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/Reduction.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/Reduction.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": 34.0526315789, "max_line_length": 83, "alphanum_fraction": 0.4544049459, "num_tokens": 466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6513548646660542, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.3561205549937067}} {"text": "{-# OPTIONS --safe --experimental-lossy-unification #-}\nmodule Cubical.Algebra.GradedRing.Instances.TrivialGradedRing where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Equiv\n\nopen import Cubical.Data.Unit\nopen import Cubical.Data.Nat using (ℕ ; zero ; suc ; +-assoc ; +-zero)\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Algebra.Monoid\nopen import Cubical.Algebra.Monoid.Instances.Nat\nopen import Cubical.Algebra.AbGroup\nopen import Cubical.Algebra.AbGroup.Instances.Unit\nopen import Cubical.Algebra.DirectSum.DirectSumHIT.Base\nopen import Cubical.Algebra.Ring\nopen import Cubical.Algebra.GradedRing.Base\nopen import Cubical.Algebra.GradedRing.DirectSumHIT\n\nprivate variable\n ℓ : Level\n\nopen Iso\nopen GradedRing-⊕HIT-index\nopen GradedRing-⊕HIT-⋆\n\nmodule _\n (ARing@(A , Astr) : Ring ℓ)\n where\n\n open RingStr Astr\n open RingTheory ARing\n\n private\n\n G : ℕ → Type ℓ\n G zero = A\n G (suc k) = Unit*\n\n Gstr : (k : ℕ) → AbGroupStr (G k)\n Gstr zero = snd (Ring→AbGroup ARing)\n Gstr (suc k) = snd UnitAbGroup\n\n ⋆ : {k l : ℕ} → G k → G l → G (k Cubical.Data.Nat.+ l)\n ⋆ {zero} {zero} x y = x · y\n ⋆ {zero} {suc l} x y = tt*\n ⋆ {suc k} {l} x y = tt*\n\n 0-⋆ : {k l : ℕ} (b : G l) → ⋆ (AbGroupStr.0g (Gstr k)) b ≡ AbGroupStr.0g (Gstr (k Cubical.Data.Nat.+ l))\n 0-⋆ {zero} {zero} b = 0LeftAnnihilates _\n 0-⋆ {zero} {suc l} b = refl\n 0-⋆ {suc k} {l} b = refl\n\n ⋆-0 : {k l : ℕ} (a : G k) → ⋆ a (AbGroupStr.0g (Gstr l)) ≡ AbGroupStr.0g (Gstr (k Cubical.Data.Nat.+ l))\n ⋆-0 {zero} {zero} a = 0RightAnnihilates _\n ⋆-0 {zero} {suc l} a = refl\n ⋆-0 {suc k} {l} a = refl\n\n ⋆Assoc : {k l m : ℕ} (a : G k) (b : G l) (c : G m) →\n _≡_ {A = Σ[ k ∈ ℕ ] G k}\n (k Cubical.Data.Nat.+ (l Cubical.Data.Nat.+ m) , ⋆ a (⋆ b c))\n (k Cubical.Data.Nat.+ l Cubical.Data.Nat.+ m , ⋆ (⋆ a b) c)\n ⋆Assoc {zero} {zero} {zero} a b c = ΣPathTransport→PathΣ _ _ (+-assoc _ _ _ , transportRefl _ ∙ ·Assoc _ _ _)\n ⋆Assoc {zero} {zero} {suc m} a b c = ΣPathTransport→PathΣ _ _ (+-assoc _ _ _ , transportRefl _)\n ⋆Assoc {zero} {suc l} {m} a b c = ΣPathTransport→PathΣ _ _ (+-assoc _ _ _ , transportRefl _)\n ⋆Assoc {suc k} {l} {m} a b c = ΣPathTransport→PathΣ _ _ (+-assoc _ _ _ , transportRefl _)\n\n ⋆IdR : {k : ℕ} (a : G k) → _≡_ {A = Σ[ k ∈ ℕ ] G k} (k Cubical.Data.Nat.+ 0 , ⋆ a 1r) (k , a)\n ⋆IdR {zero} a = ΣPathTransport→PathΣ _ _ (refl , (transportRefl _ ∙ ·IdR _))\n ⋆IdR {suc k} a = ΣPathTransport→PathΣ _ _ ((+-zero _) , (transportRefl _))\n\n ⋆IdL : {l : ℕ} (b : G l) → _≡_ {A = Σ[ k ∈ ℕ ] G k} (l , ⋆ 1r b) (l , b)\n ⋆IdL {zero} b = ΣPathTransport→PathΣ _ _ (refl , (transportRefl _ ∙ ·IdL _))\n ⋆IdL {suc l} b = ΣPathTransport→PathΣ _ _ (refl , (transportRefl _))\n\n ⋆DistR+ : {k l : ℕ} (a : G k) (b c : G l) →\n ⋆ a (Gstr l .AbGroupStr._+_ b c) ≡ Gstr (k Cubical.Data.Nat.+ l) .AbGroupStr._+_ (⋆ a b) (⋆ a c)\n ⋆DistR+ {zero} {zero} a b c = ·DistR+ _ _ _\n ⋆DistR+ {zero} {suc l} a b c = refl\n ⋆DistR+ {suc k} {l} a b c = refl\n\n ⋆DistL+ : {k l : ℕ} (a b : G k) (c : G l) →\n ⋆ (Gstr k .AbGroupStr._+_ a b) c ≡ Gstr (k Cubical.Data.Nat.+ l) .AbGroupStr._+_ (⋆ a c) (⋆ b c)\n ⋆DistL+ {zero} {zero} a b c = ·DistL+ _ _ _\n ⋆DistL+ {zero} {suc l} a b c = refl\n ⋆DistL+ {suc k} {l} a b c = refl\n\n trivialGradedRing : GradedRing ℓ-zero ℓ\n trivialGradedRing = makeGradedRing ARing NatMonoid\n G Gstr 1r ⋆ 0-⋆ ⋆-0\n ⋆Assoc ⋆IdR ⋆IdL ⋆DistR+ ⋆DistL+\n equivRing\n where\n equivRing : RingEquiv ARing (⊕HITgradedRing-Ring\n NatMonoid G Gstr 1r ⋆ 0-⋆ ⋆-0 ⋆Assoc ⋆IdR ⋆IdL ⋆DistR+ ⋆DistL+)\n fst equivRing = isoToEquiv is\n where\n is : Iso A (⊕HIT ℕ G Gstr)\n fun is a = base 0 a\n inv is = DS-Rec-Set.f _ _ _ _ is-set\n 0r (λ {zero a → a ; (suc k) a → 0r }) _+_ +Assoc +IdR +Comm\n (λ { zero → refl ; (suc k) → refl}) (λ {zero a b → refl ; (suc n) a b → +IdR _})\n rightInv is = DS-Ind-Prop.f _ _ _ _ (λ _ → trunc _ _)\n (base-neutral _)\n (λ { zero a → refl ; (suc k) a → base-neutral _ ∙ sym (base-neutral _)} )\n λ {U V} ind-U ind-V → sym (base-add _ _ _) ∙ cong₂ _add_ ind-U ind-V\n leftInv is = λ _ → refl\n snd equivRing = makeIsRingHom\n -- issue agda have trouble infering the Idx, G, Gstr\n {R = ARing}\n {S = ⊕HITgradedRing-Ring NatMonoid G Gstr 1r ⋆ 0-⋆ ⋆-0 ⋆Assoc ⋆IdR ⋆IdL ⋆DistR+ ⋆DistL+}\n {f = λ a → base 0 a}\n refl (λ _ _ → sym (base-add _ _ _)) λ _ _ → refl\n", "meta": {"hexsha": "9808b6c29cfd9e8b6d76d7b66915882c0330ac88", "size": 4772, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/GradedRing/Instances/TrivialGradedRing.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/GradedRing/Instances/TrivialGradedRing.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/GradedRing/Instances/TrivialGradedRing.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": 41.4956521739, "max_line_length": 114, "alphanum_fraction": 0.5515507125, "num_tokens": 1994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7122321720225278, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3561160860112639}} {"text": "------------------------------------------------------------------------\n-- Monotone functions\n------------------------------------------------------------------------\n\n{-# OPTIONS --erased-cubical --safe #-}\n\nmodule Partiality-algebra.Monotone where\n\nopen import Equality.Propositional.Cubical\nopen import Prelude hiding (⊥)\n\nopen import Bijection equality-with-J using (_↔_)\nimport Equivalence equality-with-J as Eq\nopen import Function-universe equality-with-J hiding (id; _∘_)\nopen import H-level.Closure equality-with-J\n\nopen import Partiality-algebra as PA hiding (id; _∘_)\nimport Partiality-algebra.Properties as PAP\n\n-- Definition of monotone functions.\n\nrecord [_⟶_]⊑\n {a₁ p₁ q₁} {A₁ : Type a₁} (P₁ : Partiality-algebra p₁ q₁ A₁)\n {a₂ p₂ q₂} {A₂ : Type a₂} (P₂ : Partiality-algebra p₂ q₂ A₂) :\n Type (p₁ ⊔ p₂ ⊔ q₁ ⊔ q₂) where\n private\n module P₁ = Partiality-algebra P₁\n module P₂ = Partiality-algebra P₂\n\n field\n function : P₁.T → P₂.T\n monotone : ∀ {x y} → x P₁.⊑ y → function x P₂.⊑ function y\n\nopen [_⟶_]⊑\n\n-- Identity.\n\nid⊑ : ∀ {a p q} {A : Type a} {P : Partiality-algebra p q A} →\n [ P ⟶ P ]⊑\nfunction id⊑ = id\nmonotone id⊑ = id\n\n-- Composition.\n\ninfixr 40 _∘⊑_\n\n_∘⊑_ :\n ∀ {a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}\n {a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂}\n {a₃ p₃ q₃} {A₃ : Type a₃} {P₃ : Partiality-algebra p₃ q₃ A₃} →\n [ P₂ ⟶ P₃ ]⊑ → [ P₁ ⟶ P₂ ]⊑ → [ P₁ ⟶ P₃ ]⊑\nfunction (f ∘⊑ g) = function f ∘ function g\nmonotone (f ∘⊑ g) = monotone f ∘ monotone g\n\n-- Equality characterisation lemma for monotone functions.\n\nequality-characterisation-monotone :\n ∀ {a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}\n {a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂}\n {f g : [ P₁ ⟶ P₂ ]⊑} →\n (∀ x → function f x ≡ function g x) ↔ f ≡ g\nequality-characterisation-monotone {P₁ = P₁} {P₂ = P₂} {f} {g} =\n (∀ x → function f x ≡ function g x) ↔⟨ Eq.extensionality-isomorphism ext ⟩\n\n function f ≡ function g ↝⟨ ignore-propositional-component\n (implicit-Π-closure ext 1 λ _ →\n implicit-Π-closure ext 1 λ _ →\n Π-closure ext 1 λ _ →\n P₂.⊑-propositional) ⟩\n _↔_.to rearrange f ≡ _↔_.to rearrange g ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ rearrange) ⟩□\n\n f ≡ g □\n where\n module P₁ = Partiality-algebra P₁\n module P₂ = Partiality-algebra P₂\n\n rearrange :\n [ P₁ ⟶ P₂ ]⊑\n ↔\n ∃ λ (h : P₁.T → P₂.T) →\n ∀ {x y} → x P₁.⊑ y → h x P₂.⊑ h y\n rearrange = record\n { surjection = record\n { logical-equivalence = record\n { to = λ f → function f , monotone f\n ; from = uncurry λ f m → record { function = f; monotone = m }\n }\n ; right-inverse-of = λ _ → refl\n }\n ; left-inverse-of = λ _ → refl\n }\n where\n open Partiality-algebra\n\n-- Composition is associative.\n\n∘⊑-assoc :\n ∀ {a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}\n {a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂}\n {a₃ p₃ q₃} {A₃ : Type a₃} {P₃ : Partiality-algebra p₃ q₃ A₃}\n {a₄ p₄ q₄} {A₄ : Type a₄} {P₄ : Partiality-algebra p₄ q₄ A₄}\n (f : [ P₃ ⟶ P₄ ]⊑) (g : [ P₂ ⟶ P₃ ]⊑) {h : [ P₁ ⟶ P₂ ]⊑} →\n f ∘⊑ (g ∘⊑ h) ≡ (f ∘⊑ g) ∘⊑ h\n∘⊑-assoc _ _ =\n _↔_.to equality-characterisation-monotone λ _ → refl\n\nmodule _\n {a₁ p₁ q₁} {A₁ : Type a₁} {P₁ : Partiality-algebra p₁ q₁ A₁}\n {a₂ p₂ q₂} {A₂ : Type a₂} {P₂ : Partiality-algebra p₂ q₂ A₂} where\n\n private\n module P₁ = Partiality-algebra P₁\n module P₂ = Partiality-algebra P₂\n module PAP₁ = PAP P₁\n module PAP₂ = PAP P₂\n\n -- If a monotone function is applied to an increasing sequence,\n -- then the result is another increasing sequence.\n\n [_$_]-inc :\n [ P₁ ⟶ P₂ ]⊑ → P₁.Increasing-sequence → P₂.Increasing-sequence\n [ f $ s ]-inc = (λ n → function f (s P₁.[ n ]))\n , (λ n → monotone f (P₁.increasing s n))\n\n -- A lemma relating monotone functions and least upper bounds.\n\n ⨆$⊑$⨆ : (f : [ P₁ ⟶ P₂ ]⊑) →\n ∀ s → P₂.⨆ [ f $ s ]-inc P₂.⊑ function f (P₁.⨆ s)\n ⨆$⊑$⨆ f s = P₂.least-upper-bound _ _ λ n →\n\n [ f $ s ]-inc P₂.[ n ] PAP₂.⊑⟨ monotone f (\n\n s P₁.[ n ] PAP₁.⊑⟨ P₁.upper-bound _ _ ⟩■\n P₁.⨆ s ■) ⟩■\n\n function f (P₁.⨆ s) ■\n", "meta": {"hexsha": "d0e2b4a0949415b4f3d399c6f29bda63382029a8", "size": 4729, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Partiality-algebra/Monotone.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/Partiality-algebra/Monotone.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/Partiality-algebra/Monotone.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": 34.5182481752, "max_line_length": 110, "alphanum_fraction": 0.5062381053, "num_tokens": 1746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.3557115942147574}} {"text": "-- Raw terms, weakening (renaming) and substitution.\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Definition.Untyped where\n\nopen import Tools.Fin\nopen import Tools.Nat\nopen import Tools.Product\nopen import Tools.List\nimport Tools.PropositionalEquality as PE\n\n\ninfixl 30 _∙_\ninfix 30 Π_▹_\ninfixr 22 _▹▹_\ninfix 30 Σ_▹_\ninfixr 22 _××_\ninfix 30 ⟦_⟧_▹_\ninfixl 30 _ₛ•ₛ_ _•ₛ_ _ₛ•_\ninfix 25 _[_]\ninfix 25 _[_]↑\n\n\n-- Typing contexts (length indexed snoc-lists, isomorphic to lists).\n-- Terms added to the context are well scoped in the sense that it cannot\n-- contain more unbound variables than can be looked up in the context.\n\ndata Con (A : Nat → Set) : Nat → Set where\n ε : Con A 0 -- Empty context.\n _∙_ : {n : Nat} → Con A n → A n → Con A (1+ n) -- Context extension.\n\nprivate\n variable\n n m ℓ : Nat\n\n-- Representation of sub terms using a list of binding levels\n\ndata GenTs (A : Nat → Set) : Nat → List Nat → Set where\n [] : {n : Nat} → GenTs A n []\n _∷_ : {n b : Nat} {bs : List Nat} (t : A (b + n)) (ts : GenTs A n bs) → GenTs A n (b ∷ bs)\n\n-- Kinds are indexed on the number of expected sub terms\n-- and the number of new variables bound by each sub term\n\ndata Kind : (ns : List Nat) → Set where\n Ukind : Kind []\n\n Pikind : Kind (0 ∷ 1 ∷ [])\n Lamkind : Kind (1 ∷ [])\n Appkind : Kind (0 ∷ 0 ∷ [])\n\n Sigmakind : Kind (0 ∷ 1 ∷ [])\n Prodkind : Kind (0 ∷ 0 ∷ [])\n Fstkind : Kind (0 ∷ [])\n Sndkind : Kind (0 ∷ [])\n\n Natkind : Kind []\n Zerokind : Kind []\n Suckind : Kind (0 ∷ [])\n Natreckind : Kind (1 ∷ 0 ∷ 0 ∷ 0 ∷ [])\n\n Unitkind : Kind []\n Starkind : Kind []\n\n Emptykind : Kind []\n Emptyreckind : Kind (0 ∷ 0 ∷ [])\n\n-- Terms are indexed by its number of unbound variables and are either:\n-- de Bruijn style variables or\n-- generic terms, formed by their kind and sub terms\n\ndata Term (n : Nat) : Set where\n var : (x : Fin n) → Term n\n gen : {bs : List Nat} (k : Kind bs) (c : GenTs Term n bs) → Term n\n\nprivate\n variable\n A F H t u v : Term n\n B E G : Term (1+ n)\n\n-- The Grammar of our language.\n\n-- We represent the expressions of our language as de Bruijn terms.\n-- Variables are natural numbers interpreted as de Bruijn indices.\n-- Π, lam, and natrec are binders.\n\n-- Type constructors.\nU : Term n -- Universe.\nU = gen Ukind []\n\nΠ_▹_ : (A : Term n) (B : Term (1+ n)) → Term n -- Dependent function type (B is a binder).\nΠ A ▹ B = gen Pikind (A ∷ B ∷ [])\n\nΣ_▹_ : (A : Term n) (B : Term (1+ n)) → Term n -- Dependent sum type (B is a binder).\nΣ A ▹ B = gen Sigmakind (A ∷ B ∷ [])\n\nℕ : Term n -- Type of natural numbers.\nℕ = gen Natkind []\n\nEmpty : Term n -- Empty type\nEmpty = gen Emptykind []\n\nUnit : Term n -- Unit type\nUnit = gen Unitkind []\n\nlam : (t : Term (1+ n)) → Term n -- Function abstraction (binder).\nlam t = gen Lamkind (t ∷ [])\n\n_∘_ : (t u : Term n) → Term n -- Application.\nt ∘ u = gen Appkind (t ∷ u ∷ [])\n\n\nprod : (t u : Term n) → Term n -- Dependent products\nprod t u = gen Prodkind (t ∷ u ∷ [])\n\nfst : (t : Term n) → Term n -- First projection\nfst t = gen Fstkind (t ∷ [])\n\nsnd : (t : Term n) → Term n -- Second projection\nsnd t = gen Sndkind (t ∷ [])\n\n-- Introduction and elimination of natural numbers.\nzero : Term n -- Natural number zero.\nzero = gen Zerokind []\n\nsuc : (t : Term n) → Term n -- Successor.\nsuc t = gen Suckind (t ∷ [])\n\nnatrec : (A : Term (1+ n)) (t u v : Term n) → Term n -- Natural number recursor (A is a binder).\nnatrec A t u v = gen Natreckind (A ∷ t ∷ u ∷ v ∷ [])\n\n\nstar : Term n -- Unit element\nstar = gen Starkind []\n\nEmptyrec : (A e : Term n) → Term n -- Empty type recursor\nEmptyrec A e = gen Emptyreckind (A ∷ e ∷ [])\n\n-- Binding types\n\ndata BindingType : Set where\n BΠ : BindingType\n BΣ : BindingType\n\n⟦_⟧_▹_ : BindingType → Term n → Term (1+ n) → Term n\n⟦ BΠ ⟧ F ▹ G = Π F ▹ G\n⟦ BΣ ⟧ F ▹ G = Σ F ▹ G\n\n-- Injectivity of term constructors w.r.t. propositional equality.\n\n-- If W F G = W H E then F = H and G = E.\n\nB-PE-injectivity : ∀ W → ⟦ W ⟧ F ▹ G PE.≡ ⟦ W ⟧ H ▹ E → F PE.≡ H × G PE.≡ E\nB-PE-injectivity BΠ PE.refl = PE.refl , PE.refl\nB-PE-injectivity BΣ PE.refl = PE.refl , PE.refl\n\n-- If suc n = suc m then n = m.\n\nsuc-PE-injectivity : suc t PE.≡ suc u → t PE.≡ u\nsuc-PE-injectivity PE.refl = PE.refl\n\n\n-- Neutral terms.\n\n-- A term is neutral if it has a variable in head position.\n-- The variable blocks reduction of such terms.\n\ndata Neutral : Term n → Set where\n var : (x : Fin n) → Neutral (var x)\n ∘ₙ : Neutral t → Neutral (t ∘ u)\n fstₙ : Neutral t → Neutral (fst t)\n sndₙ : Neutral t → Neutral (snd t)\n natrecₙ : Neutral v → Neutral (natrec G t u v)\n Emptyrecₙ : Neutral t → Neutral (Emptyrec A t)\n\n\n-- Weak head normal forms (whnfs).\n\n-- These are the (lazy) values of our language.\n\ndata Whnf {n : Nat} : Term n → Set where\n\n -- Type constructors are whnfs.\n Uₙ : Whnf U\n Πₙ : Whnf (Π A ▹ B)\n Σₙ : Whnf (Σ A ▹ B)\n ℕₙ : Whnf ℕ\n Unitₙ : Whnf Unit\n Emptyₙ : Whnf Empty\n\n -- Introductions are whnfs.\n lamₙ : Whnf (lam t)\n zeroₙ : Whnf zero\n sucₙ : Whnf (suc t)\n starₙ : Whnf star\n prodₙ : Whnf (prod t u)\n\n -- Neutrals are whnfs.\n ne : Neutral t → Whnf t\n\n\n-- Whnf inequalities.\n\n-- Different whnfs are trivially distinguished by propositional equality.\n-- (The following statements are sometimes called \"no-confusion theorems\".)\n\nU≢ne : Neutral A → U PE.≢ A\nU≢ne () PE.refl\n\nℕ≢ne : Neutral A → ℕ PE.≢ A\nℕ≢ne () PE.refl\n\nEmpty≢ne : Neutral A → Empty PE.≢ A\nEmpty≢ne () PE.refl\n\nUnit≢ne : Neutral A → Unit PE.≢ A\nUnit≢ne () PE.refl\n\nB≢ne : ∀ W → Neutral A → ⟦ W ⟧ F ▹ G PE.≢ A\nB≢ne BΠ () PE.refl\nB≢ne BΣ () PE.refl\n\nU≢B : ∀ W → U PE.≢ ⟦ W ⟧ F ▹ G\nU≢B BΠ ()\nU≢B BΣ ()\n\nℕ≢B : ∀ W → ℕ PE.≢ ⟦ W ⟧ F ▹ G\nℕ≢B BΠ ()\nℕ≢B BΣ ()\n\nEmpty≢B : ∀ W → Empty PE.≢ ⟦ W ⟧ F ▹ G\nEmpty≢B BΠ ()\nEmpty≢B BΣ ()\n\nUnit≢B : ∀ W → Unit PE.≢ ⟦ W ⟧ F ▹ G\nUnit≢B BΠ ()\nUnit≢B BΣ ()\n\nzero≢ne : Neutral t → zero PE.≢ t\nzero≢ne () PE.refl\n\nsuc≢ne : Neutral t → suc u PE.≢ t\nsuc≢ne () PE.refl\n\n-- Several views on whnfs (note: not recursive).\n\n-- A whnf of type ℕ is either zero, suc t, or neutral.\n\ndata Natural {n : Nat} : Term n → Set where\n zeroₙ : Natural zero\n sucₙ : Natural (suc t)\n ne : Neutral t → Natural t\n\n\n-- A (small) type in whnf is either Π A B, Σ A B, ℕ, Empty, Unit or neutral.\n-- Large types could also be U.\n\ndata Type {n : Nat} : Term n → Set where\n Πₙ : Type (Π A ▹ B)\n Σₙ : Type (Σ A ▹ B)\n ℕₙ : Type ℕ\n Emptyₙ : Type Empty\n Unitₙ : Type Unit\n ne : Neutral t → Type t\n\n⟦_⟧-type : ∀ (W : BindingType) → Type (⟦ W ⟧ F ▹ G)\n⟦ BΠ ⟧-type = Πₙ\n⟦ BΣ ⟧-type = Σₙ\n\n-- A whnf of type Π A ▹ B is either lam t or neutral.\n\ndata Function {n : Nat} : Term n → Set where\n lamₙ : Function (lam t)\n ne : Neutral t → Function t\n\n-- A whnf of type Σ A ▹ B is either prod t u or neutral.\n\ndata Product {n : Nat} : Term n → Set where\n prodₙ : Product (prod t u)\n ne : Neutral t → Product t\n\n-- These views classify only whnfs.\n-- Natural, Type, Function and Product are a subsets of Whnf.\n\nnaturalWhnf : Natural t → Whnf t\nnaturalWhnf sucₙ = sucₙ\nnaturalWhnf zeroₙ = zeroₙ\nnaturalWhnf (ne x) = ne x\n\ntypeWhnf : Type A → Whnf A\ntypeWhnf Πₙ = Πₙ\ntypeWhnf Σₙ = Σₙ\ntypeWhnf ℕₙ = ℕₙ\ntypeWhnf Emptyₙ = Emptyₙ\ntypeWhnf Unitₙ = Unitₙ\ntypeWhnf (ne x) = ne x\n\nfunctionWhnf : Function t → Whnf t\nfunctionWhnf lamₙ = lamₙ\nfunctionWhnf (ne x) = ne x\n\nproductWhnf : Product t → Whnf t\nproductWhnf prodₙ = prodₙ\nproductWhnf (ne x) = ne x\n\n⟦_⟧ₙ : (W : BindingType) → Whnf (⟦ W ⟧ F ▹ G)\n⟦_⟧ₙ BΠ = Πₙ\n⟦_⟧ₙ BΣ = Σₙ\n\n\n------------------------------------------------------------------------\n-- Weakening\n\n-- In the following we define untyped weakenings η : Wk.\n-- The typed form could be written η : Γ ≤ Δ with the intention\n-- that η transport a term t living in context Δ to a context Γ\n-- that can bind additional variables (which cannot appear in t).\n-- Thus, if Δ ⊢ t : A and η : Γ ≤ Δ then Γ ⊢ wk η t : wk η A.\n--\n-- Even though Γ is \"larger\" than Δ we write Γ ≤ Δ to be conformant\n-- with subtyping A ≤ B. With subtyping, relation Γ ≤ Δ could be defined as\n-- ``for all x ∈ dom(Δ) have Γ(x) ≤ Δ(x)'' (in the sense of subtyping)\n-- and this would be the natural extension of weakenings.\n\ndata Wk : Nat → Nat → Set where\n id : {n : Nat} → Wk n n -- η : Γ ≤ Γ.\n step : {n m : Nat} → Wk m n → Wk (1+ m) n -- If η : Γ ≤ Δ then step η : Γ∙A ≤ Δ.\n lift : {n m : Nat} → Wk m n → Wk (1+ m) (1+ n) -- If η : Γ ≤ Δ then lift η : Γ∙A ≤ Δ∙A.\n\n-- Composition of weakening.\n-- If η : Γ ≤ Δ and η′ : Δ ≤ Φ then η • η′ : Γ ≤ Φ.\n\ninfixl 30 _•_\n\n_•_ : {l m n : Nat} → Wk l m → Wk m n → Wk l n\nid • η′ = η′\nstep η • η′ = step (η • η′)\nlift η • id = lift η\nlift η • step η′ = step (η • η′)\nlift η • lift η′ = lift (η • η′)\n\nliftn : {k m : Nat} → Wk k m → (n : Nat) → Wk (n + k) (n + m)\nliftn ρ Nat.zero = ρ\nliftn ρ (1+ n) = lift (liftn ρ n)\n\n-- Weakening of variables.\n-- If η : Γ ≤ Δ and x ∈ dom(Δ) then wkVar η x ∈ dom(Γ).\n\nwkVar : {m n : Nat} (ρ : Wk m n) (x : Fin n) → Fin m\nwkVar id x = x\nwkVar (step ρ) x = (wkVar ρ x) +1\nwkVar (lift ρ) x0 = x0\nwkVar (lift ρ) (x +1) = (wkVar ρ x) +1\n\n -- Weakening of terms.\n -- If η : Γ ≤ Δ and Δ ⊢ t : A then Γ ⊢ wk η t : wk η A.\n\nmutual\n wkGen : {m n : Nat} {bs : List Nat} (ρ : Wk m n) (c : GenTs Term n bs) → GenTs Term m bs\n wkGen ρ [] = []\n wkGen ρ (_∷_ {b = b} t c) = (wk (liftn ρ b) t) ∷ (wkGen ρ c)\n\n wk : {m n : Nat} (ρ : Wk m n) (t : Term n) → Term m\n wk ρ (var x) = var (wkVar ρ x)\n wk ρ (gen k c) = gen k (wkGen ρ c)\n\n\n-- Adding one variable to the context requires wk1.\n-- If Γ ⊢ t : B then Γ∙A ⊢ wk1 t : wk1 B.\n\nwk1 : Term n → Term (1+ n)\nwk1 = wk (step id)\n\n-- Weakening of a neutral term.\n\nwkNeutral : ∀ ρ → Neutral t → Neutral {n} (wk ρ t)\nwkNeutral ρ (var n) = var (wkVar ρ n)\nwkNeutral ρ (∘ₙ n) = ∘ₙ (wkNeutral ρ n)\nwkNeutral ρ (fstₙ n) = fstₙ (wkNeutral ρ n)\nwkNeutral ρ (sndₙ n) = sndₙ (wkNeutral ρ n)\nwkNeutral ρ (natrecₙ n) = natrecₙ (wkNeutral ρ n)\nwkNeutral ρ (Emptyrecₙ e) = Emptyrecₙ (wkNeutral ρ e)\n\n-- Weakening can be applied to our whnf views.\n\nwkNatural : ∀ ρ → Natural t → Natural {n} (wk ρ t)\nwkNatural ρ sucₙ = sucₙ\nwkNatural ρ zeroₙ = zeroₙ\nwkNatural ρ (ne x) = ne (wkNeutral ρ x)\n\nwkType : ∀ ρ → Type t → Type {n} (wk ρ t)\nwkType ρ Πₙ = Πₙ\nwkType ρ Σₙ = Σₙ\nwkType ρ ℕₙ = ℕₙ\nwkType ρ Emptyₙ = Emptyₙ\nwkType ρ Unitₙ = Unitₙ\nwkType ρ (ne x) = ne (wkNeutral ρ x)\n\nwkFunction : ∀ ρ → Function t → Function {n} (wk ρ t)\nwkFunction ρ lamₙ = lamₙ\nwkFunction ρ (ne x) = ne (wkNeutral ρ x)\n\nwkProduct : ∀ ρ → Product t → Product {n} (wk ρ t)\nwkProduct ρ prodₙ = prodₙ\nwkProduct ρ (ne x) = ne (wkNeutral ρ x)\n\nwkWhnf : ∀ ρ → Whnf t → Whnf {n} (wk ρ t)\nwkWhnf ρ Uₙ = Uₙ\nwkWhnf ρ Πₙ = Πₙ\nwkWhnf ρ Σₙ = Σₙ\nwkWhnf ρ ℕₙ = ℕₙ\nwkWhnf ρ Emptyₙ = Emptyₙ\nwkWhnf ρ Unitₙ = Unitₙ\nwkWhnf ρ lamₙ = lamₙ\nwkWhnf ρ prodₙ = prodₙ\nwkWhnf ρ zeroₙ = zeroₙ\nwkWhnf ρ sucₙ = sucₙ\nwkWhnf ρ starₙ = starₙ\nwkWhnf ρ (ne x) = ne (wkNeutral ρ x)\n\n-- Non-dependent version of Π.\n\n_▹▹_ : Term n → Term n → Term n\nA ▹▹ B = Π A ▹ wk1 B\n\n-- Non-dependent products.\n\n_××_ : Term n → Term n → Term n\nA ×× B = Σ A ▹ wk1 B\n\n------------------------------------------------------------------------\n-- Substitution\n\n-- The substitution operation subst σ t replaces the free de Bruijn indices\n-- of term t by chosen terms as specified by σ.\n\n-- The substitution σ itself is a map from natural numbers to terms.\n\nSubst : Nat → Nat → Set\nSubst m n = Fin n → Term m\n\n-- Given closed contexts ⊢ Γ and ⊢ Δ,\n-- substitutions may be typed via Γ ⊢ σ : Δ meaning that\n-- Γ ⊢ σ(x) : (subst σ Δ)(x) for all x ∈ dom(Δ).\n--\n-- The substitution operation is then typed as follows:\n-- If Γ ⊢ σ : Δ and Δ ⊢ t : A, then Γ ⊢ subst σ t : subst σ A.\n--\n-- Although substitutions are untyped, typing helps us\n-- to understand the operation on substitutions.\n\n-- We may view σ as the infinite stream σ 0, σ 1, ...\n\n-- Extract the substitution of the first variable.\n--\n-- If Γ ⊢ σ : Δ∙A then Γ ⊢ head σ : subst σ A.\n\nhead : Subst m (1+ n) → Term m\nhead σ = σ x0\n\n-- Remove the first variable instance of a substitution\n-- and shift the rest to accommodate.\n--\n-- If Γ ⊢ σ : Δ∙A then Γ ⊢ tail σ : Δ.\n\ntail : Subst m (1+ n) → Subst m n\ntail σ x = σ (x +1)\n\n-- Substitution of a variable.\n--\n-- If Γ ⊢ σ : Δ then Γ ⊢ substVar σ x : (subst σ Δ)(x).\n\nsubstVar : (σ : Subst m n) (x : Fin n) → Term m\nsubstVar σ x = σ x\n\n-- Identity substitution.\n-- Replaces each variable by itself.\n--\n-- Γ ⊢ idSubst : Γ.\n\nidSubst : Subst n n\nidSubst = var\n\n-- Weaken a substitution by one.\n--\n-- If Γ ⊢ σ : Δ then Γ∙A ⊢ wk1Subst σ : Δ.\n\nwk1Subst : Subst m n → Subst (1+ m) n\nwk1Subst σ x = wk1 (σ x)\n\n-- Lift a substitution.\n--\n-- If Γ ⊢ σ : Δ then Γ∙A ⊢ liftSubst σ : Δ∙A.\n\nliftSubst : (σ : Subst m n) → Subst (1+ m) (1+ n)\nliftSubst σ x0 = var x0\nliftSubst σ (x +1) = wk1Subst σ x\n\nliftSubstn : {k m : Nat} → Subst k m → (n : Nat) → Subst (n + k) (n + m)\nliftSubstn σ Nat.zero = σ\nliftSubstn σ (1+ n) = liftSubst (liftSubstn σ n)\n\n-- Transform a weakening into a substitution.\n--\n-- If ρ : Γ ≤ Δ then Γ ⊢ toSubst ρ : Δ.\n\ntoSubst : Wk m n → Subst m n\ntoSubst pr x = var (wkVar pr x)\n\n-- Apply a substitution to a term.\n--\n-- If Γ ⊢ σ : Δ and Δ ⊢ t : A then Γ ⊢ subst σ t : subst σ A.\n\nmutual\n substGen : {bs : List Nat} (σ : Subst m n) (g : GenTs Term n bs) → GenTs Term m bs\n substGen σ [] = []\n substGen σ (_∷_ {b = b} t ts) = subst (liftSubstn σ b) t ∷ (substGen σ ts)\n\n subst : (σ : Subst m n) (t : Term n) → Term m\n subst σ (var x) = substVar σ x\n subst σ (gen x c) = gen x (substGen σ c)\n\n-- Extend a substitution by adding a term as\n-- the first variable substitution and shift the rest.\n--\n-- If Γ ⊢ σ : Δ and Γ ⊢ t : subst σ A then Γ ⊢ consSubst σ t : Δ∙A.\n\nconsSubst : Subst m n → Term m → Subst m (1+ n)\nconsSubst σ t x0 = t\nconsSubst σ t (x +1) = σ x\n\n-- Singleton substitution.\n--\n-- If Γ ⊢ t : A then Γ ⊢ sgSubst t : Γ∙A.\n\nsgSubst : Term n → Subst n (1+ n)\nsgSubst = consSubst idSubst\n\n-- Compose two substitutions.\n--\n-- If Γ ⊢ σ : Δ and Δ ⊢ σ′ : Φ then Γ ⊢ σ ₛ•ₛ σ′ : Φ.\n\n_ₛ•ₛ_ : Subst ℓ m → Subst m n → Subst ℓ n\n_ₛ•ₛ_ σ σ′ x = subst σ (σ′ x)\n\n-- Composition of weakening and substitution.\n--\n-- If ρ : Γ ≤ Δ and Δ ⊢ σ : Φ then Γ ⊢ ρ •ₛ σ : Φ.\n\n_•ₛ_ : Wk ℓ m → Subst m n → Subst ℓ n\n_•ₛ_ ρ σ x = wk ρ (σ x)\n\n-- If Γ ⊢ σ : Δ and ρ : Δ ≤ Φ then Γ ⊢ σ ₛ• ρ : Φ.\n\n_ₛ•_ : Subst ℓ m → Wk m n → Subst ℓ n\n_ₛ•_ σ ρ x = σ (wkVar ρ x)\n\n-- Substitute the first variable of a term with an other term.\n--\n-- If Γ∙A ⊢ t : B and Γ ⊢ s : A then Γ ⊢ t[s] : B[s].\n\n_[_] : (t : Term (1+ n)) (s : Term n) → Term n\nt [ s ] = subst (sgSubst s) t\n\n-- Substitute the first variable of a term with an other term,\n-- but let the two terms share the same context.\n--\n-- If Γ∙A ⊢ t : B and Γ∙A ⊢ s : A then Γ∙A ⊢ t[s]↑ : B[s]↑.\n\n_[_]↑ : (t : Term (1+ n)) (s : Term (1+ n)) → Term (1+ n)\nt [ s ]↑ = subst (consSubst (wk1Subst idSubst) s) t\n\n\nB-subst : (σ : Subst m n) (W : BindingType) (F : Term n) (G : Term (1+ n))\n → subst σ (⟦ W ⟧ F ▹ G) PE.≡ ⟦ W ⟧ (subst σ F) ▹ (subst (liftSubst σ) G)\nB-subst σ BΠ F G = PE.refl\nB-subst σ BΣ F G = PE.refl\n", "meta": {"hexsha": "b8658d985f26d897f85d7c88527a22ffde1c711d", "size": 15576, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/Untyped.agda", "max_stars_repo_name": "fhlkfy/logrel-mltt", "max_stars_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2017-05-20T03:05:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:01:07.000Z", "max_issues_repo_path": "Definition/Untyped.agda", "max_issues_repo_name": "fhlkfy/logrel-mltt", "max_issues_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-06-22T12:49:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-22T10:37:24.000Z", "max_forks_repo_path": "Definition/Untyped.agda", "max_forks_repo_name": "fhlkfy/logrel-mltt", "max_forks_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2017-10-18T14:18:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-27T15:58:33.000Z", "avg_line_length": 26.9015544041, "max_line_length": 97, "alphanum_fraction": 0.5697226502, "num_tokens": 6105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6039318479832804, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.35564890100188445}} {"text": "\nmodule UniDB.Examples.Lc where\n\nopen import UniDB\n\ndata Tm (γ : Dom) : Set where\n var : (i : Ix γ) → Tm γ\n abs : (t : Tm (suc γ)) → Tm γ\n app : (t₁ t₂ : Tm γ) → Tm γ\n\ninstance\n iVrTm : Vr Tm\n vr {{iVrTm}} = var\n vr-inj {{iVrTm}} refl = refl\n\n iApTm : Ap Tm Tm\n ap {{iApTm}} ξ (var i) = lk ξ i\n ap {{iApTm}} ξ (abs t) = abs (ap {Tm} (ξ ↑₁) t )\n ap {{iApTm}} ξ (app t t₁) = app (ap {Tm} ξ t) (ap {Tm} ξ t₁)\n\n iApVrTm : ApVr Tm\n ap-vr {{iApVrTm}} ξ i = refl\n\n iApIdmTm : ApIdm Tm Tm\n ap-idm {{iApIdmTm}} {Ξ} (var i) = lk-idm {Tm} {Ξ} i\n ap-idm {{iApIdmTm}} {Ξ} (abs t) = cong abs (begin\n ap {Tm} (idm {Ξ} _ ↑₁) t ≡⟨ cong₂ (ap {Tm}) (idm-↑₁ {Ξ}) (refl {x = t}) ⟩\n ap {Tm} (idm {Ξ} _) t ≡⟨ ap-idm {Tm} t ⟩\n t ∎)\n ap-idm {{iApIdmTm}} {Ξ} (app t t₁) =\n cong₂ app (ap-idm {Tm} t) (ap-idm {Tm} t₁)\n\n iApPairTm : ApPair Tm Tm\n ap-pair {{iApPairTm}} ξ ζ (var i) = refl\n ap-pair {{iApPairTm}} ξ ζ (abs x) = cong abs (ap-pair {Tm} (ξ ↑₁) (ζ ↑₁) x)\n ap-pair {{iApPairTm}} ξ ζ (app x₁ x₂) = cong₂ app (ap-pair {Tm} ξ ζ x₁) (ap-pair {Tm} ξ ζ x₂)\n\n iApRelTm : ApRel Tm Tm\n ap-rel≅ {{iApRelTm}} hyp (var i) = lk≃ (≅-to-≃ hyp) i\n ap-rel≅ {{iApRelTm}} hyp (abs t) = cong abs (ap-rel≅ {Tm} {Tm} (≅-↑₁ hyp) t)\n ap-rel≅ {{iApRelTm}} hyp (app t₁ t₂) = cong₂ app (ap-rel≅ {Tm} {Tm} hyp t₁) (ap-rel≅ {Tm} {Tm} hyp t₂)\n\npostulate\n Ρ : MOR\n instance\n iIdmΡ : Idm Ρ\n iWkmΡ : Wkm Ρ\n iUpΡ : Up Ρ\n iUpIdmΡ : UpIdm Ρ\n iCompΡ : Comp Ρ\n iWkmHomΡ : WkmHom Ρ\n iLkΡ : {T : STX} {{vrT : Vr T}} → Lk T Ρ\n iLkIdmΡ : {T : STX} {{vrT : Vr T}} → LkIdm T Ρ\n iLkWkmΡ : {T : STX} {{vrT : Vr T}} → LkWkm T Ρ\n iLkCompAp : {T : STX} {{vrT : Vr T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} → LkCompAp T Ρ\n iLkUpΡ : {T : STX} {{vrT : Vr T}} {{wkT : Wk T}} → LkUp T Ρ\n iLkRenΡ : {T : STX} {{vrT : Vr T}} → LkRen T Ρ\n\ninstance\n iWkTm : Wk Tm\n wk₁ {{iWkTm}} = ap {Tm} (wkm {Ρ} 1)\n wk {{iWkTm}} δ t = ap {Tm} (wkm {Ρ} δ) t\n wk-zero {{iWkTm}} t = begin\n ap {Tm} (wkm {Ρ} 0) t ≡⟨ ap-rel≅ {Tm} (Ix≅-to-≅ {Tm} (≃-to-≅` (≃-↑ {Ix} (record { lk≃ = λ i → begin\n lk (wkm {Ρ} 0) i ≡⟨ lk-wkm {Ix} {Ρ} 0 i ⟩\n i ≡⟨ sym (lk-idm {Ix} {Ρ} i) ⟩\n lk (idm {Ρ} _) i ∎\n })))) t ⟩\n ap {Tm} (idm {Ρ} _) t ≡⟨ ap-idm {Tm} {Tm} {Ρ} t ⟩\n t ∎\n wk-suc {{iWkTm}} δ t = begin\n ap {Tm} (wkm {Ρ} (suc δ)) t ≡⟨ cong (λ ζ → ap {Tm} {Tm} {Ρ} ζ t) (wkm-suc {Ρ} δ) ⟩\n ap {Tm} (wkm {Ρ} δ ⊙ wkm {Ρ} 1) t ≡⟨ ap-rel≅ {Tm} (Ix≅-to-≅ {Tm} {Ρ} {Pair Ρ Ρ} (≃-to-≅`\n (≃-↑ {Ix} {Ρ} {Pair Ρ Ρ} {ξ = wkm {Ρ} δ ⊙ wkm {Ρ} 1} {wkm {Ρ} δ ⊗ wkm {Ρ} 1} (record { lk≃ =\n lk-⊙-ap {Ix} {Ρ} (wkm {Ρ} δ) (wkm {Ρ} 1) })))) t ⟩\n ap {Tm} (wkm {Ρ} δ ⊗ wkm {Ρ} 1) t ≡⟨ ap-pair {Tm} (wkm {Ρ} δ) (wkm {Ρ} 1) t ⟩\n ap {Tm} (wkm {Ρ} 1) (ap {Tm} (wkm {Ρ} δ) t) ∎\n\ninstance\n iWkVrTm : WkVr Tm\n wk₁-vr {{iWkVrTm}} i = lk-wkm {Tm} {Ρ} 1 i\n wk-vr {{iWkVrTm}} δ i = lk-wkm {Tm} {Ρ} δ i\n\n iApWkmWkTm : ApWkmWk Tm Tm\n ap-wkm-wk₁ {{iApWkmWkTm}} {Ξ} = ap-wkm-rel Tm Tm Ξ Ρ 1\n ap-wkm-wk {{iApWkmWkTm}} {Ξ} = ap-wkm-rel Tm Tm Ξ Ρ\n\n -- iApCompTm : ApComp Tm Tm\n -- ap-⊙ {{iApCompTm}} {Ξ} ξ₁ ξ₂ (var i) = lk-⊙-ap {Tm} {Ξ} ξ₁ ξ₂ i\n -- ap-⊙ {{iApCompTm}} {Ξ} ξ₁ ξ₂ (abs t) rewrite ⊙-↑₁ {Ξ} ξ₁ ξ₂ =\n -- cong abs (ap-⊙ {Tm} (ξ₁ ↑₁) (ξ₂ ↑₁) t)\n -- ap-⊙ {{iApCompTm}} {Ξ} ξ₁ ξ₂ (app t₁ t₂) =\n -- cong₂ app (ap-⊙ {Tm} {Tm} {Ξ} ξ₁ ξ₂ t₁) (ap-⊙ {Tm} {Tm} {Ξ} ξ₁ ξ₂ t₂)\n\n iApCompTm : ApComp Tm Tm\n iApCompTm = iApComp Tm Tm\n\n iApWkTm : ApWk Tm Tm\n iApWkTm = iApWk Tm Tm\n\n{-}\n\n\n\n--------------------------------------------------------------------------------\n\nsubTm : {X : STX} {{apTmX : Ap Tm X}} {γ : Dom} (s : Tm γ) (x : X (suc γ)) → X γ\nsubTm {X} s x = ap Tm X (Sub Tm) (beta Tm (Sub Tm) s) x\n\ndata Eval {γ : Dom} : Tm γ → Tm γ → Set where\n e-app₁ : {t₁ t₁' t₂ : Tm γ} → Eval t₁ t₁' → Eval (app t₁ t₂) (app t₁' t₂)\n e-app₂ : {t₁ t₂ t₂' : Tm γ} → Eval t₂ t₂' → Eval (app t₁ t₂) (app t₁ t₂')\n e-abs : {t t' : Tm (suc γ)} → Eval t t' → Eval (abs t) (abs t')\n e-beta : {s : Tm γ} {t : Tm (suc γ)} → Eval (app (abs t) s) (subTm s t)\n\n--------------------------------------------------------------------------------\n-}\n", "meta": {"hexsha": "2ec5319c219b37239858cb674a90d7ba70c190fc", "size": 4262, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "UniDB/Examples/Lc.agda", "max_stars_repo_name": "skeuchel/unidb-agda", "max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "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": "UniDB/Examples/Lc.agda", "max_issues_repo_name": "skeuchel/unidb-agda", "max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "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": "UniDB/Examples/Lc.agda", "max_forks_repo_name": "skeuchel/unidb-agda", "max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "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": 36.1186440678, "max_line_length": 104, "alphanum_fraction": 0.4568277804, "num_tokens": 2406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7401743505760728, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.35563799348975955}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Properties related to All\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.Vec.Relation.Unary.All.Properties where\n\nopen import Data.List using ([]; _∷_)\nopen import Data.List.Relation.Unary.All as List using ([]; _∷_)\nopen import Data.Product as Prod using (_×_; _,_; uncurry; uncurry′)\nopen import Data.Vec as Vec\nopen import Data.Vec.Relation.Unary.All as All using (All; []; _∷_)\nopen import Function using (_∘_; id)\nopen import Function.Inverse using (_↔_; inverse)\nopen import Relation.Unary using (Pred) renaming (_⊆_ to _⋐_)\nopen import Relation.Binary.PropositionalEquality\n using (_≡_; refl; cong; cong₂; →-to-⟶)\n\n------------------------------------------------------------------------\n-- map\n\nmodule _ {a b p} {A : Set a} {B : Set b} {P : Pred B p} {f : A → B} where\n\n map⁺ : ∀ {n} {xs : Vec A n} → All (P ∘ f) xs → All P (map f xs)\n map⁺ [] = []\n map⁺ (px ∷ pxs) = px ∷ map⁺ pxs\n\n map⁻ : ∀ {n} {xs : Vec A n} → All P (map f xs) → All (P ∘ f) xs\n map⁻ {xs = []} [] = []\n map⁻ {xs = _ ∷ _} (px ∷ pxs) = px ∷ map⁻ pxs\n\n-- A variant of All.map\n\nmodule _ {a b p q} {A : Set a} {B : Set b} {f : A → B}\n {P : Pred A p} {Q : Pred B q} where\n\n gmap : ∀ {n} → P ⋐ Q ∘ f → All P {n} ⋐ All Q {n} ∘ map f\n gmap g = map⁺ ∘ All.map g\n\n------------------------------------------------------------------------\n-- _++_\n\nmodule _ {a n p} {A : Set a} {P : Pred A p} where\n\n ++⁺ : ∀ {m} {xs : Vec A m} {ys : Vec A n} →\n All P xs → All P ys → All P (xs ++ ys)\n ++⁺ [] pys = pys\n ++⁺ (px ∷ pxs) pys = px ∷ ++⁺ pxs pys\n\n ++ˡ⁻ : ∀ {m} (xs : Vec A m) {ys : Vec A n} →\n All P (xs ++ ys) → All P xs\n ++ˡ⁻ [] _ = []\n ++ˡ⁻ (x ∷ xs) (px ∷ pxs) = px ∷ ++ˡ⁻ xs pxs\n\n ++ʳ⁻ : ∀ {m} (xs : Vec A m) {ys : Vec A n} →\n All P (xs ++ ys) → All P ys\n ++ʳ⁻ [] pys = pys\n ++ʳ⁻ (x ∷ xs) (px ∷ pxs) = ++ʳ⁻ xs pxs\n\n ++⁻ : ∀ {m} (xs : Vec A m) {ys : Vec A n} →\n All P (xs ++ ys) → All P xs × All P ys\n ++⁻ [] p = [] , p\n ++⁻ (x ∷ xs) (px ∷ pxs) = Prod.map₁ (px ∷_) (++⁻ _ pxs)\n\n ++⁺∘++⁻ : ∀ {m} (xs : Vec A m) {ys : Vec A n} →\n (p : All P (xs ++ ys)) →\n uncurry′ ++⁺ (++⁻ xs p) ≡ p\n ++⁺∘++⁻ [] p = refl\n ++⁺∘++⁻ (x ∷ xs) (px ∷ pxs) = cong (px ∷_) (++⁺∘++⁻ xs pxs)\n\n ++⁻∘++⁺ : ∀ {m} {xs : Vec A m} {ys : Vec A n} →\n (p : All P xs × All P ys) →\n ++⁻ xs (uncurry ++⁺ p) ≡ p\n ++⁻∘++⁺ ([] , pys) = refl\n ++⁻∘++⁺ (px ∷ pxs , pys) rewrite ++⁻∘++⁺ (pxs , pys) = refl\n\n ++↔ : ∀ {m} {xs : Vec A m} {ys : Vec A n} →\n (All P xs × All P ys) ↔ All P (xs ++ ys)\n ++↔ {xs = xs} = inverse (uncurry ++⁺) (++⁻ xs) ++⁻∘++⁺ (++⁺∘++⁻ xs)\n\n------------------------------------------------------------------------\n-- concat\n\nmodule _ {a m p} {A : Set a} {P : Pred A p} where\n\n concat⁺ : ∀ {n} {xss : Vec (Vec A m) n} →\n All (All P) xss → All P (concat xss)\n concat⁺ [] = []\n concat⁺ (pxs ∷ pxss) = ++⁺ pxs (concat⁺ pxss)\n\n concat⁻ : ∀ {n} (xss : Vec (Vec A m) n) →\n All P (concat xss) → All (All P) xss\n concat⁻ [] [] = []\n concat⁻ (xs ∷ xss) pxss = ++ˡ⁻ xs pxss ∷ concat⁻ xss (++ʳ⁻ xs pxss)\n\n------------------------------------------------------------------------\n-- toList\n\nmodule _ {a p} {A : Set a} {P : A → Set p} where\n\n toList⁺ : ∀ {n} {xs : Vec A n} → All P xs → List.All P (toList xs)\n toList⁺ [] = []\n toList⁺ (px ∷ pxs) = px ∷ toList⁺ pxs\n\n toList⁻ : ∀ {n} {xs : Vec A n} → List.All P (toList xs) → All P xs\n toList⁻ {xs = []} [] = []\n toList⁻ {xs = x ∷ xs} (px ∷ pxs) = px ∷ toList⁻ pxs\n\n------------------------------------------------------------------------\n-- fromList\n\nmodule _ {a p} {A : Set a} {P : A → Set p} where\n\n fromList⁺ : ∀ {xs} → List.All P xs → All P (fromList xs)\n fromList⁺ [] = []\n fromList⁺ (px ∷ pxs) = px ∷ fromList⁺ pxs\n\n fromList⁻ : ∀ {xs} → All P (fromList xs) → List.All P xs\n fromList⁻ {[]} [] = []\n fromList⁻ {x ∷ xs} (px ∷ pxs) = px ∷ (fromList⁻ pxs)\n\n------------------------------------------------------------------------\n-- DEPRECATED NAMES\n------------------------------------------------------------------------\n-- Please use the new names as continuing support for the old names is\n-- not guaranteed.\n\n-- Version 0.16\n\nAll-map = map⁺\n{-# WARNING_ON_USAGE All-map\n\"Warning: All-map was deprecated in v0.16.\nPlease use map⁺ instead.\"\n#-}\nmap-All = map⁻\n{-# WARNING_ON_USAGE map-All\n\"Warning: map-All was deprecated in v0.16.\nPlease use map⁻ instead.\"\n#-}\nAll-++⁺ = ++⁺\n{-# WARNING_ON_USAGE All-++⁺\n\"Warning: All-++⁺ was deprecated in v0.16.\nPlease use ++⁺ instead.\"\n#-}\nAll-++ˡ⁻ = ++ˡ⁻\n{-# WARNING_ON_USAGE All-++ˡ⁻\n\"Warning: All-++ˡ⁻ was deprecated in v0.16.\nPlease use ++ˡ⁻ instead.\"\n#-}\nAll-++ʳ⁻ = ++ʳ⁻\n{-# WARNING_ON_USAGE All-++ʳ⁻\n\"Warning: All-++ʳ⁻ was deprecated in v0.16.\nPlease use ++ʳ⁻ instead.\"\n#-}\nAll-++⁻ = ++⁻\n{-# WARNING_ON_USAGE All-++⁻\n\"Warning: All-++⁻ was deprecated in v0.16.\nPlease use ++⁻ instead.\"\n#-}\nAll-++⁺∘++⁻ = ++⁺∘++⁻\n{-# WARNING_ON_USAGE All-++⁺∘++⁻\n\"Warning: All-++⁺∘++⁻ was deprecated in v0.16.\nPlease use ++⁺∘++⁻ instead.\"\n#-}\nAll-++⁻∘++⁺ = ++⁻∘++⁺\n{-# WARNING_ON_USAGE All-++⁻∘++⁺\n\"Warning: All-++⁻∘++⁺ was deprecated in v0.16.\nPlease use ++⁻∘++⁺ instead.\"\n#-}\nAll-concat⁺ = concat⁺\n{-# WARNING_ON_USAGE All-concat⁺\n\"Warning: All-concat⁺ was deprecated in v0.16.\nPlease use concat⁺ instead.\"\n#-}\nAll-concat⁻ = concat⁻\n{-# WARNING_ON_USAGE All-concat⁻\n\"Warning: All-concat⁻ was deprecated in v0.16.\nPlease use concat⁻ instead.\"\n#-}\n", "meta": {"hexsha": "ed878b33d9bea7d0dffa3d9860ea55877defb3ac", "size": 5764, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Unary/All/Properties.agda", "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Unary/All/Properties.agda", "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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/asset/agda-stdlib-1.0/Data/Vec/Relation/Unary/All/Properties.agda", "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "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": 31.4972677596, "max_line_length": 73, "alphanum_fraction": 0.4408396947, "num_tokens": 2198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.6076631698328916, "lm_q1q2_score": 0.35554442203601894}} {"text": "module Logic.Convenience {ℓ} where\n\nimport Lvl\nopen import Data.Tuple as Tuple using (_⨯_ ; _,_)\nopen import Functional\nopen import Logic.Propositional{ℓ}\nopen import Type\n\nrecord [⇒]-proof (Proof : Stmt → Stmt → Type{ℓ}) : Type{Lvl.𝐒(ℓ)} where\n infixl 10 _⇒_\n infixr 10 _⇐_\n\n field\n _⇒_ : ∀{X Y : Stmt} → X → Proof(X)(Y) → Y\n\n _⇐_ : ∀{X Y : Stmt} → Proof(X)(Y) → X → Y\n _⇐_ = swap(_⇒_)\nopen [⇒]-proof ⦃...⦄ public\n\ninstance\n [⇒]-proof-[→] : [⇒]-proof (X ↦ Y ↦ (X → Y))\n _⇒_ ⦃ [⇒]-proof-[→] ⦄ = apply\n\ninstance\n [⇒]-proof-[↔] : [⇒]-proof (X ↦ Y ↦ (X ↔ Y))\n _⇒_ ⦃ [⇒]-proof-[↔] ⦄ = swap(Tuple.right)\n\ninstance\n [⇒]-proof-unrelated : [⇒]-proof (X ↦ Y ↦ Y)\n _⇒_ ⦃ [⇒]-proof-unrelated ⦄ = swap(const)\n\n-- TODO: ⇔ probably means using transitivity\n", "meta": {"hexsha": "0c84c291ca7d436c5d5aafe8245dac722459ba03", "size": 762, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "old/Logic/Convenience.agda", "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_issues_repo_path": "old/Logic/Convenience.agda", "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": "old/Logic/Convenience.agda", "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": 23.0909090909, "max_line_length": 71, "alphanum_fraction": 0.5590551181, "num_tokens": 362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6791787121629466, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.3554959585104527}} {"text": "{-# OPTIONS --cubical-compatible #-}\n\nopen import Agda.Builtin.Equality\n\nsubst :\n {A : Set} {@0 x y : A}\n (@0 P : A → Set) → x ≡ y → P x → P y\nsubst P refl p = p\n", "meta": {"hexsha": "ffc6ebf8fd090c32e3fc651644921df10614bf00", "size": 164, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue5448-3.agda", "max_stars_repo_name": "KDr2/agda", "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": ["BSD-2-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/Issue5448-3.agda", "max_issues_repo_name": "KDr2/agda", "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_forks_repo_path": "test/Fail/Issue5448-3.agda", "max_forks_repo_name": "KDr2/agda", "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.2222222222, "max_line_length": 38, "alphanum_fraction": 0.5487804878, "num_tokens": 60, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.35549595171250287}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\n{-\nImports everything that is not imported by something else.\nThis is not supposed to be used anywhere, this is just a simple way to\ndo `make all'\n\nThis file is intentionally named index.agda so that\nAgda will generate index.html.\n-}\n\nmodule index where\n\n{- some group theory results -}\nimport groups.ReducedWord\nimport groups.ProductRepr\nimport groups.CoefficientExtensionality\n\n{- homotopy groups of circles -}\nimport homotopy.LoopSpaceCircle\nimport homotopy.PinSn\nimport homotopy.HopfJunior\nimport homotopy.Hopf\n\n{- cohomology -}\nimport cohomology.EMModel\nimport cohomology.Sigma\nimport cohomology.Coproduct\nimport cohomology.Torus\n-- import cohomology.MayerVietorisExact -- FIXME\n\n{- prop * prop is still a prop -}\nimport homotopy.PropJoinProp\n\n{- a space with preassigned homotopy groups -}\nimport homotopy.SpaceFromGroups\n\n{- pushout 3x3 lemma -}\n{- These takes lots of time and memory to check. -}\n-- import homotopy.3x3.Commutes -- commented out because this does not run on travis.\n-- import homotopy.JoinAssoc3x3 -- commented out because this does not run on travis.\n\n{- covering spaces -}\nimport homotopy.GroupSetsRepresentCovers\nimport homotopy.AnyUniversalCoverIsPathSet\nimport homotopy.PathSetIsInitalCover\n\n{- van kampen -}\nimport homotopy.VanKampen\n\n{- blakers massey -}\nimport homotopy.BlakersMassey\n\n{- cw complexes -}\nimport cw.CW\nimport cw.examples.Examples\n-- cellular cohomology groups\nimport cw.cohomology.CellularChainComplex\n-- Eilenberg-Steenred cohomology groups rephrased\nimport cw.cohomology.ReconstructedCohomologyGroups\n-- isomorphisms between the cochains the heads\nimport cw.cohomology.ReconstructedCochainsIsoCellularCochains\n\n-- There are some unported theorems\n\n-- import Spaces.IntervalProps\n-- import Algebra.F2NotCommutative\n-- import Spaces.LoopSpaceDecidableWedgeCircles\n-- import Homotopy.PullbackIsPullback\n-- import Homotopy.PushoutIsPushout\n-- import Homotopy.Truncation\n-- import Sets.QuotientUP\n", "meta": {"hexsha": "d34751414bea0e5763d5e7c6036e7f14740ca209", "size": 1983, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/index.agda", "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/index.agda", "max_issues_repo_name": "mikeshulman/HoTT-Agda", "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "theorems/index.agda", "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "avg_line_length": 27.1643835616, "max_line_length": 85, "alphanum_fraction": 0.802824004, "num_tokens": 533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5813030761371503, "lm_q2_score": 0.6113819732941511, "lm_q1q2_score": 0.3553982217706911}} {"text": "------------------------------------------------------------------------\n-- The parser data type\n------------------------------------------------------------------------\n\n-- This hybrid variant is coinductive /and/ includes !_.\n\nmodule RecursiveDescent.Hybrid.Type where\n\nopen import Data.Bool\nopen import Data.Product.Record\n\nopen import RecursiveDescent.Index\n\n-- A type for parsers which can be implemented using recursive\n-- descent. The types used ensure that the implemented backends are\n-- structurally recursive.\n\n-- The parsers are indexed on a type of nonterminals.\n\ncodata Parser (tok : Set) (nt : ParserType) : ParserType₁ where\n !_ : forall {e c r}\n -> nt (e , c) r -> Parser tok nt (e , step c) r\n symbol : Parser tok nt (false , leaf) tok\n return : forall {r} -> r -> Parser tok nt (true , leaf) r\n fail : forall {r} -> Parser tok nt (false , leaf) r\n _?>>=_ : forall {c₁ e₂ c₂ r₁ r₂}\n -> Parser tok nt (true , c₁) r₁\n -> (r₁ -> Parser tok nt (e₂ , c₂) r₂)\n -> Parser tok nt (e₂ , node c₁ c₂) r₂\n _!>>=_ : forall {c₁ r₁ r₂} {i₂ : r₁ -> Index}\n -> Parser tok nt (false , c₁) r₁\n -> ((x : r₁) -> Parser tok nt (i₂ x) r₂)\n -> Parser tok nt (false , step c₁) r₂\n alt : forall e₁ e₂ {c₁ c₂ r}\n -> Parser tok nt (e₁ , c₁) r\n -> Parser tok nt (e₂ , c₂) r\n -> Parser tok nt (e₁ ∨ e₂ , node c₁ c₂) r\n\n-- Grammars.\n\nGrammar : Set -> ParserType -> Set1\nGrammar tok nt = forall {i r} -> nt i r -> Parser tok nt i r\n", "meta": {"hexsha": "deefe192dcb7aa52a6ffecc13d0b7f7cc85bc962", "size": 1547, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "misc/RecursiveDescent/Hybrid/Type.agda", "max_stars_repo_name": "yurrriq/parser-combinators", "max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z", "max_issues_repo_path": "misc/RecursiveDescent/Hybrid/Type.agda", "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z", "max_forks_repo_path": "misc/RecursiveDescent/Hybrid/Type.agda", "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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.976744186, "max_line_length": 72, "alphanum_fraction": 0.5300581771, "num_tokens": 450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6992544085240401, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3550896847980452}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Fundamental {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped\nopen import Definition.Untyped.Properties\nopen import Definition.Typed\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.Irrelevance\nopen import Definition.LogicalRelation.Properties\nopen import Definition.LogicalRelation.Substitution\nopen import Definition.LogicalRelation.Substitution.Properties\nopen import Definition.LogicalRelation.Substitution.Conversion\nopen import Definition.LogicalRelation.Substitution.Reduction\nopen import Definition.LogicalRelation.Substitution.Reflexivity\nopen import Definition.LogicalRelation.Substitution.Introductions\nimport Definition.LogicalRelation.Substitution.Irrelevance as S\n\nopen import Agda.Primitive\nopen import Tools.Product\nopen import Tools.Unit\nopen import Tools.Nat\nimport Tools.PropositionalEquality as PE\n\nmutual\n -- Fundamental theorem for contexts.\n valid : ∀ {Γ} → ⊢ Γ → ⊩ᵛ Γ\n valid ε = ε′\n valid (⊢Γ ∙ A) = let [Γ] , [A] = fundamental A in [Γ] ∙′ [A]\n\n\n -- Fundamental theorem for types.\n fundamental : ∀ {Γ A} (⊢A : Γ ⊢ A) → Σω₄ (⊩ᵛ Γ) (λ [Γ] → Γ ⊩ᵛ⟨ ¹ ⟩ A / [Γ])\n fundamental (ℕⱼ x) = valid x , ℕᵛ (valid x)\n fundamental (Uⱼ x) = valid x , Uᵛ (valid x)\n fundamental (Πⱼ_▹_ {F} {G} ⊢F ⊢G) with fundamental ⊢F | fundamental ⊢G\n fundamental (Πⱼ_▹_ {F} {G} ⊢F ⊢G) | [Γ] , [F] | [Γ∙F] , [G] =\n [Γ] , Πᵛ {F} {G} [Γ] [F] (S.irrelevance {A = G} [Γ∙F] ([Γ] ∙′ [F]) [G])\n fundamental (univ {A} ⊢A) with fundamentalTerm ⊢A\n fundamental (univ {A} ⊢A) | [Γ] , [U] , [A] =\n [Γ] , univᵛ {A} [Γ] [U] [A]\n\n -- Fundamental theorem for type equality.\n fundamentalEq : ∀{Γ A B} → Γ ⊢ A ≡ B\n → ∃ω₄ λ ([Γ] : ⊩ᵛ Γ)\n → ∃ω₃² λ ([A] : Γ ⊩ᵛ⟨ ¹ ⟩ A / [Γ]) ([B] : Γ ⊩ᵛ⟨ ¹ ⟩ B / [Γ])\n → Γ ⊩ᵛ⟨ ¹ ⟩ A ≡ B / [Γ] / [A]\n fundamentalEq (univ {A} {B} x) with fundamentalTermEq x\n fundamentalEq (univ {A} {B} x) | [Γ] , modelsTermEq [U] [t] [u] [t≡u] =\n let [A] = univᵛ {A} [Γ] [U] [t]\n [B] = univᵛ {B} [Γ] [U] [u]\n in [Γ] , [A] , [B]\n , (λ ⊢Δ [σ] → univEqEq (proj₁ ([U] ⊢Δ [σ]))\n (proj₁ ([A] ⊢Δ [σ]))\n ([t≡u] ⊢Δ [σ]))\n fundamentalEq (refl D) =\n let [Γ] , [B] = fundamental D\n in [Γ] , [B] , [B] , (λ ⊢Δ [σ] → reflEq (proj₁ ([B] ⊢Δ [σ])))\n fundamentalEq (sym A≡B) with fundamentalEq A≡B\n fundamentalEq (sym A≡B) | [Γ] , [B] , [A] , [B≡A] =\n [Γ] , [A] , [B]\n , (λ ⊢Δ [σ] → symEq (proj₁ ([B] ⊢Δ [σ]))\n (proj₁ ([A] ⊢Δ [σ]))\n ([B≡A] ⊢Δ [σ]))\n fundamentalEq (trans {A} {B₁} {B} A≡B₁ B₁≡B)\n with fundamentalEq A≡B₁ | fundamentalEq B₁≡B\n fundamentalEq (trans {A} {B₁} {B} A≡B B≡C) | [Γ] , [A] , [B₁] , [A≡B₁]\n | [Γ]₁ , [B₁]₁ , [B] , [B₁≡B] =\n [Γ] , [A] , S.irrelevance {A = B} [Γ]₁ [Γ] [B]\n , (λ ⊢Δ [σ] →\n let [σ]′ = S.irrelevanceSubst [Γ] [Γ]₁ ⊢Δ ⊢Δ [σ]\n in transEq (proj₁ ([A] ⊢Δ [σ])) (proj₁ ([B₁] ⊢Δ [σ]))\n (proj₁ ([B] ⊢Δ [σ]′)) ([A≡B₁] ⊢Δ [σ])\n (irrelevanceEq (proj₁ ([B₁]₁ ⊢Δ [σ]′))\n (proj₁ ([B₁] ⊢Δ [σ]))\n ([B₁≡B] ⊢Δ [σ]′)))\n fundamentalEq (Π-cong {F} {H} {G} {E} ⊢F A≡B A≡B₁)\n with fundamentalEq A≡B | fundamentalEq A≡B₁\n fundamentalEq (Π-cong {F} {H} {G} {E} ⊢F A≡B A≡B₁) | [Γ] , [F] , [H] , [F≡H]\n | [Γ]₁ , [G] , [E] , [G≡E] =\n let [G]′ = S.irrelevance {A = G} [Γ]₁ ([Γ] ∙′ [F]) [G]\n [E]′ = S.irrelevanceLift {A = E} {F = F} {H = H} [Γ] [F] [H] [F≡H]\n (S.irrelevance {A = E} [Γ]₁ ([Γ] ∙′ [F]) [E])\n [G≡E]′ = S.irrelevanceEq {A = G} {B = E} [Γ]₁\n ([Γ] ∙′ [F]) [G] [G]′ [G≡E]\n in [Γ]\n , Πᵛ {F} {G} [Γ] [F] [G]′\n , Πᵛ {H} {E} [Γ] [H] [E]′\n , Π-congᵛ {F} {G} {H} {E} [Γ] [F] [G]′ [H] [E]′ [F≡H] [G≡E]′\n\n -- Fundamental theorem for variables.\n fundamentalVar : ∀ {Γ A x}\n → x ∷ A ∈ Γ\n → ([Γ] : ⊩ᵛ Γ)\n → ∃ω₃ λ ([A] : Γ ⊩ᵛ⟨ ¹ ⟩ A / [Γ])\n → Γ ⊩ᵛ⟨ ¹ ⟩ var x ∷ A / [Γ] / [A]\n fundamentalVar here (VPack _ _ (V∙ {A = A} {l = l} [Γ] [A])) =\n (λ ⊢Δ [σ] →\n let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ]))\n [σA′] = maybeEmb (irrelevance′ (PE.sym (subst-wk A)) [σA])\n in [σA′]\n , (λ [σ′] [σ≡σ′] →\n irrelevanceEq″ (PE.sym (subst-wk A)) (PE.sym (subst-wk A))\n [σA] [σA′] (proj₂ ([A] ⊢Δ (proj₁ [σ]))\n (proj₁ [σ′]) (proj₁ [σ≡σ′]))))\n , (λ ⊢Δ [σ] →\n let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ]))\n [σA′] = maybeEmb (irrelevance′ (PE.sym (subst-wk A)) [σA])\n in irrelevanceTerm′ (PE.sym (subst-wk A)) [σA] [σA′] (proj₂ [σ])\n , (λ [σ′] [σ≡σ′] → irrelevanceEqTerm′ (PE.sym (subst-wk A))\n [σA] [σA′] (proj₂ [σ≡σ′])))\n fundamentalVar (there {A = A} h) ([Γ] ∙′ [B]) =\n (λ ⊢Δ [σ] →\n let [h] = proj₁ (fundamentalVar h [Γ]) ⊢Δ (proj₁ [σ])\n [σA] = proj₁ [h]\n [σA′] = irrelevance′ (PE.sym (subst-wk A)) [σA]\n in [σA′]\n , (λ [σ′] [σ≡σ′] →\n irrelevanceEq″ (PE.sym (subst-wk A)) (PE.sym (subst-wk A))\n [σA] [σA′]\n (proj₂ [h] (proj₁ [σ′]) (proj₁ [σ≡σ′]))))\n , (λ ⊢Δ [σ] →\n let [h] = (proj₁ (fundamentalVar h [Γ])) ⊢Δ (proj₁ [σ])\n [σA] = proj₁ [h]\n [σA′] = irrelevance′ (PE.sym (subst-wk A)) [σA]\n [h′] = (proj₂ (fundamentalVar h [Γ])) ⊢Δ (proj₁ [σ])\n in irrelevanceTerm′ (PE.sym (subst-wk A)) [σA] [σA′] (proj₁ [h′])\n , (λ [σ′] [σ≡σ′] →\n irrelevanceEqTerm′ (PE.sym (subst-wk A)) [σA] [σA′]\n (proj₂ [h′] (proj₁ [σ′]) (proj₁ [σ≡σ′]))))\n\n -- Fundamental theorem for terms.\n fundamentalTerm : ∀{Γ A t} → Γ ⊢ t ∷ A\n → ∃ω₄ λ ([Γ] : ⊩ᵛ Γ)\n → ∃ω₃ λ ([A] : Γ ⊩ᵛ⟨ ¹ ⟩ A / [Γ])\n → Γ ⊩ᵛ⟨ ¹ ⟩ t ∷ A / [Γ] / [A]\n fundamentalTerm (ℕⱼ x) = valid x , Uᵛ (valid x) , ℕᵗᵛ (valid x)\n fundamentalTerm (Πⱼ_▹_ {F} {G} ⊢F ⊢G)\n with fundamentalTerm ⊢F | fundamentalTerm ⊢G\n ... | [Γ] , [U] , [F]ₜ | [Γ]₁ , [U]₁ , [G]ₜ =\n let [F] = univᵛ {F} [Γ] [U] [F]ₜ\n [U]′ = S.irrelevance {A = U} [Γ]₁ ([Γ] ∙′ [F]) [U]₁\n [F]ₜ′ = S.irrelevanceTerm {A = U} {t = F} [Γ] [Γ] [U] (Uᵛ [Γ]) [F]ₜ\n [G]ₜ′ = S.irrelevanceTerm {A = U} {t = G} [Γ]₁ ([Γ] ∙′ [F]) [U]₁\n (λ {Δ} {σ} → [U]′ {Δ} {σ}) [G]ₜ\n in [Γ] , [U]\n , S.irrelevanceTerm {A = U} {t = Π F ▹ G} [Γ] [Γ] (Uᵛ [Γ]) [U]\n (Πᵗᵛ {F} {G} [Γ] [F] (λ {Δ} {σ} → [U]′ {Δ} {σ})\n [F]ₜ′ [G]ₜ′)\n fundamentalTerm (var ⊢Γ x∷A) = valid ⊢Γ , fundamentalVar x∷A (valid ⊢Γ)\n fundamentalTerm (lamⱼ {F} {G} {t} ⊢F ⊢t)\n with fundamental ⊢F | fundamentalTerm ⊢t\n ... | [Γ] , [F] | [Γ]₁ , [G] , [t] =\n let [G]′ = S.irrelevance {A = G} [Γ]₁ ([Γ] ∙′ [F]) [G]\n [t]′ = S.irrelevanceTerm {A = G} {t = t} [Γ]₁ ([Γ] ∙′ [F]) [G] [G]′ [t]\n in [Γ] , Πᵛ {F} {G} [Γ] [F] [G]′\n , lamᵛ {F} {G} {t} [Γ] [F] [G]′ [t]′\n fundamentalTerm (_∘ⱼ_ {g} {a} {F} {G} Dt Du)\n with fundamentalTerm Dt | fundamentalTerm Du\n ... | [Γ] , [ΠFG] , [t] | [Γ]₁ , [F] , [u] =\n let [ΠFG]′ = S.irrelevance {A = Π F ▹ G} [Γ] [Γ]₁ [ΠFG]\n [t]′ = S.irrelevanceTerm {A = Π F ▹ G} {t = g} [Γ] [Γ]₁ [ΠFG] [ΠFG]′ [t]\n [G[t]] = substSΠ {F} {G} {a} [Γ]₁ [F] [ΠFG]′ [u]\n [t∘u] = appᵛ {F} {G} {g} {a} [Γ]₁ [F] [ΠFG]′ [t]′ [u]\n in [Γ]₁ , [G[t]] , [t∘u]\n fundamentalTerm (zeroⱼ x) = valid x , ℕᵛ (valid x) , zeroᵛ {l = ¹} (valid x)\n fundamentalTerm (sucⱼ {n} t) with fundamentalTerm t\n fundamentalTerm (sucⱼ {n} t) | [Γ] , [ℕ] , [n] =\n [Γ] , [ℕ] , sucᵛ {n = n} [Γ] [ℕ] [n]\n fundamentalTerm (natrecⱼ {G} {s} {z} {n} ⊢G ⊢z ⊢s ⊢n)\n with fundamental ⊢G | fundamentalTerm ⊢z | fundamentalTerm ⊢s\n | fundamentalTerm ⊢n\n ... | [Γ] , [G] | [Γ]₁ , [G₀] , [z] | [Γ]₂ , [G₊] , [s] | [Γ]₃ , [ℕ] , [n] =\n let sType = Π ℕ ▹ (G ▹▹ G [ suc (var 0) ]↑)\n [Γ]′ = [Γ]₃\n [G]′ = S.irrelevance {A = G} [Γ] ([Γ]′ ∙′ [ℕ]) [G]\n [G₀]′ = S.irrelevance {A = G [ zero ]} [Γ]₁ [Γ]′ [G₀]\n [G₊]′ = S.irrelevance {A = sType} [Γ]₂ [Γ]′ [G₊]\n [Gₙ]′ = substS {F = ℕ} {G = G} {t = n} [Γ]′ [ℕ] [G]′ [n]\n [z]′ = S.irrelevanceTerm {A = G [ zero ]} {t = z} [Γ]₁ [Γ]′\n [G₀] [G₀]′ [z]\n [s]′ = S.irrelevanceTerm {A = sType} {t = s} [Γ]₂ [Γ]′ [G₊] [G₊]′ [s]\n in [Γ]′ , [Gₙ]′\n , natrecᵛ {G} {z} {s} {n} [Γ]′ [ℕ] [G]′ [G₀]′ [G₊]′ [Gₙ]′ [z]′ [s]′ [n]\n fundamentalTerm (conv {t} {A} {B} ⊢t A′≡A)\n with fundamentalTerm ⊢t | fundamentalEq A′≡A\n fundamentalTerm (conv {t} {A} {B} ⊢t A′≡A) | [Γ] , [A′] , [t]\n | [Γ]₁ , [A′]₁ , [A] , [A′≡A] =\n let [Γ]′ = [Γ]₁\n [t]′ = S.irrelevanceTerm {A = A} {t = t} [Γ] [Γ]′ [A′] [A′]₁ [t]\n in [Γ]′ , [A]\n , convᵛ {t} {A} {B} [Γ]′ [A′]₁ [A] [A′≡A] [t]′\n\n -- Fundamental theorem for term equality.\n fundamentalTermEq : ∀{Γ A t t′} → Γ ⊢ t ≡ t′ ∷ A\n → ∃ω₄ λ ([Γ] : ⊩ᵛ Γ)\n → [ Γ ⊩ᵛ⟨ ¹ ⟩ t ≡ t′ ∷ A / [Γ] ]\n fundamentalTermEq (refl D) with fundamentalTerm D\n ... | [Γ] , [A] , [t] =\n [Γ] , modelsTermEq [A] [t] [t]\n (λ ⊢Δ [σ] → reflEqTerm (proj₁ ([A] ⊢Δ [σ]))\n (proj₁ ([t] ⊢Δ [σ])))\n fundamentalTermEq (sym D) with fundamentalTermEq D\n fundamentalTermEq (sym D) | [Γ] , modelsTermEq [A] [t′] [t] [t′≡t] =\n [Γ] , modelsTermEq [A] [t] [t′]\n (λ ⊢Δ [σ] → symEqTerm (proj₁ ([A] ⊢Δ [σ]))\n ([t′≡t] ⊢Δ [σ]))\n fundamentalTermEq (trans {t} {u} {r} {A} t≡u u≡t′)\n with fundamentalTermEq t≡u | fundamentalTermEq u≡t′\n fundamentalTermEq (trans {t} {u} {r} {A} t≡u u≡t′)\n | [Γ] , modelsTermEq [A] [t] [u] [t≡u]\n | [Γ]₁ , modelsTermEq [A]₁ [t]₁ [u]₁ [t≡u]₁ =\n let [r]′ = S.irrelevanceTerm {A = A} {t = r} [Γ]₁ [Γ] [A]₁ [A] [u]₁\n in [Γ] , modelsTermEq [A] [t] [r]′\n (λ ⊢Δ [σ] →\n let [σ]′ = S.irrelevanceSubst [Γ] [Γ]₁ ⊢Δ ⊢Δ [σ]\n [t≡u]₁′ = irrelevanceEqTerm (proj₁ ([A]₁ ⊢Δ [σ]′))\n (proj₁ ([A] ⊢Δ [σ]))\n ([t≡u]₁ ⊢Δ [σ]′)\n in transEqTerm (proj₁ ([A] ⊢Δ [σ]))\n ([t≡u] ⊢Δ [σ]) [t≡u]₁′)\n fundamentalTermEq (conv {A} {B} {t} {u} t≡u A′≡A)\n with fundamentalTermEq t≡u | fundamentalEq A′≡A\n fundamentalTermEq (conv {A} {B} {t} {u} t≡u A′≡A)\n | [Γ] , modelsTermEq [A′] [t] [u] [t≡u] | [Γ]₁ , [A′]₁ , [A] , [A′≡A] =\n let [t]′ = S.irrelevanceTerm {A = A} {t = t} [Γ] [Γ]₁ [A′] [A′]₁ [t]\n [u]′ = S.irrelevanceTerm {A = A} {t = u} [Γ] [Γ]₁ [A′] [A′]₁ [u]\n [t]″ = convᵛ {t} {A} {B} [Γ]₁ [A′]₁ [A] [A′≡A] [t]′\n [u]″ = convᵛ {u} {A} {B} [Γ]₁ [A′]₁ [A] [A′≡A] [u]′\n in [Γ]₁\n , modelsTermEq [A] [t]″ [u]″\n (λ ⊢Δ [σ] →\n let [σ]′ = S.irrelevanceSubst [Γ]₁ [Γ] ⊢Δ ⊢Δ [σ]\n [t≡u]′ = irrelevanceEqTerm (proj₁ ([A′] ⊢Δ [σ]′))\n (proj₁ ([A′]₁ ⊢Δ [σ]))\n ([t≡u] ⊢Δ [σ]′)\n in convEqTerm₁ (proj₁ ([A′]₁ ⊢Δ [σ])) (proj₁ ([A] ⊢Δ [σ]))\n ([A′≡A] ⊢Δ [σ]) [t≡u]′)\n fundamentalTermEq (Π-cong {E} {F} {G} {H} ⊢F F≡H G≡E)\n with fundamental ⊢F | fundamentalTermEq F≡H | fundamentalTermEq G≡E\n ... | [Γ] , [F] | [Γ]₁ , modelsTermEq [U] [F]ₜ [H]ₜ [F≡H]ₜ\n | [Γ]₂ , modelsTermEq [U]₁ [G]ₜ [E]ₜ [G≡E]ₜ =\n let [U]′ = Uᵛ [Γ]\n [F]ₜ′ = S.irrelevanceTerm {A = U} {t = F} [Γ]₁ [Γ] [U] [U]′ [F]ₜ\n [H]ₜ′ = S.irrelevanceTerm {A = U} {t = H} [Γ]₁ [Γ] [U] [U]′ [H]ₜ\n [F]′ = S.irrelevance {A = F} [Γ] [Γ]₁ [F]\n [H] = univᵛ {A = H} [Γ] [U]′ [H]ₜ′\n [F≡H] = S.irrelevanceEq {A = F} {B = H} [Γ]₁ [Γ] [F]′ [F]\n (univEqᵛ {F} {H} [Γ]₁ [U] [F]′ [F≡H]ₜ)\n [U]₁′ = Uᵛ (VPack _ _ (V∙ {A = F} [Γ] [F]))\n [U]₂′ = Uᵛ (VPack _ _ (V∙ {A = H} [Γ] [H]))\n [G]ₜ′ = S.irrelevanceTerm {A = U} {t = G} [Γ]₂ ([Γ] ∙′ [F])\n [U]₁ (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [G]ₜ\n [E]ₜ′ = S.irrelevanceTermLift {A = U} {F = F} {H = H} {t = E}\n [Γ] [F] [H] [F≡H]\n (λ {Δ} {σ} → [U]₁′ {Δ} {σ})\n (S.irrelevanceTerm {A = U} {t = E} [Γ]₂ ([Γ] ∙′ [F])\n [U]₁ (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [E]ₜ)\n [F≡H]ₜ′ = S.irrelevanceEqTerm {A = U} {t = F} {u = H}\n [Γ]₁ [Γ] [U] (Uᵛ [Γ]) [F≡H]ₜ\n [G≡E]ₜ′ = S.irrelevanceEqTerm {A = U} {t = G} {u = E} [Γ]₂\n (VPack _ _ (V∙ {A = F} [Γ] [F])) [U]₁\n (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [G≡E]ₜ\n in [Γ]\n , modelsTermEq\n [U]′\n (Πᵗᵛ {F} {G} [Γ] [F] (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) [F]ₜ′ [G]ₜ′)\n (Πᵗᵛ {H} {E} [Γ] [H] (λ {Δ} {σ} → [U]₂′ {Δ} {σ}) [H]ₜ′ [E]ₜ′)\n (Π-congᵗᵛ {F} {G} {H} {E} [Γ] [F] [H]\n (λ {Δ} {σ} → [U]₁′ {Δ} {σ}) (λ {Δ} {σ} → [U]₂′ {Δ} {σ})\n [F]ₜ′ [G]ₜ′ [H]ₜ′ [E]ₜ′ [F≡H]ₜ′ [G≡E]ₜ′)\n fundamentalTermEq (app-cong {a} {b} {f} {g} {F} {G} f≡g a≡b)\n with fundamentalTermEq f≡g | fundamentalTermEq a≡b\n ... | [Γ] , modelsTermEq [ΠFG] [f] [g] [f≡g]\n | [Γ]₁ , modelsTermEq [F] [a] [b] [a≡b] =\n let [ΠFG]′ = S.irrelevance {A = Π F ▹ G} [Γ] [Γ]₁ [ΠFG]\n [f]′ = S.irrelevanceTerm {A = Π F ▹ G} {t = f} [Γ] [Γ]₁ [ΠFG] [ΠFG]′ [f]\n [g]′ = S.irrelevanceTerm {A = Π F ▹ G} {t = g} [Γ] [Γ]₁ [ΠFG] [ΠFG]′ [g]\n [f≡g]′ = S.irrelevanceEqTerm {A = Π F ▹ G} {t = f} {u = g}\n [Γ] [Γ]₁ [ΠFG] [ΠFG]′ [f≡g]\n [G[a]] = substSΠ {F} {G} {a} [Γ]₁ [F] [ΠFG]′ [a]\n [G[b]] = substSΠ {F} {G} {b} [Γ]₁ [F] [ΠFG]′ [b]\n [G[a]≡G[b]] = substSΠEq {F} {G} {F} {G} {a} {b} [Γ]₁ [F] [F] [ΠFG]′\n [ΠFG]′ (reflᵛ {Π F ▹ G} [Γ]₁ [ΠFG]′) [a] [b] [a≡b]\n in [Γ]₁ , modelsTermEq [G[a]]\n (appᵛ {F} {G} {f} {a} [Γ]₁ [F] [ΠFG]′ [f]′ [a])\n (conv₂ᵛ {g ∘ b} {G [ a ]} {G [ b ]} [Γ]₁\n [G[a]] [G[b]] [G[a]≡G[b]]\n (appᵛ {F} {G} {g} {b}\n [Γ]₁ [F] [ΠFG]′ [g]′ [b]))\n (app-congᵛ {F} {G} {f} {g} {a} {b}\n [Γ]₁ [F] [ΠFG]′ [f≡g]′ [a] [b] [a≡b])\n fundamentalTermEq (β-red {a} {b} {F} {G} ⊢F ⊢b ⊢a)\n with fundamental ⊢F | fundamentalTerm ⊢b | fundamentalTerm ⊢a\n ... | [Γ] , [F] | [Γ]₁ , [G] , [b] | [Γ]₂ , [F]₁ , [a] =\n let [G]′ = S.irrelevance {A = G} [Γ]₁ ([Γ]₂ ∙′ [F]₁) [G]\n [b]′ = S.irrelevanceTerm {A = G} {t = b} [Γ]₁ ([Γ]₂ ∙′ [F]₁) [G] [G]′ [b]\n [G[a]] = substS {F} {G} {a} [Γ]₂ [F]₁ [G]′ [a]\n [b[a]] = substSTerm {F} {G} {a} {b} [Γ]₂ [F]₁ [G]′ [b]′ [a]\n [lam] , [eq] =\n redSubstTermᵛ {G [ a ]} {(lam b) ∘ a} {b [ a ]} [Γ]₂\n (λ {Δ} {σ} ⊢Δ [σ] →\n let [liftσ] = liftSubstS {F = F} [Γ]₂ ⊢Δ [F]₁ [σ]\n ⊢σF = escape (proj₁ ([F]₁ ⊢Δ [σ]))\n ⊢σb = escapeTerm (proj₁ ([G]′ (⊢Δ ∙ ⊢σF) [liftσ]))\n (proj₁ ([b]′ (⊢Δ ∙ ⊢σF) [liftσ]))\n ⊢σa = escapeTerm (proj₁ ([F]₁ ⊢Δ [σ]))\n (proj₁ ([a] ⊢Δ [σ]))\n in PE.subst₂ (λ x y → _ ⊢ (lam (subst (liftSubst σ) b))\n ∘ (subst σ a) ⇒ x ∷ y)\n (PE.sym (singleSubstLift b a))\n (PE.sym (singleSubstLift G a))\n (β-red ⊢σF ⊢σb ⊢σa))\n [G[a]] [b[a]]\n in [Γ]₂ , modelsTermEq [G[a]] [lam] [b[a]] [eq]\n fundamentalTermEq (η-eq {f} {g} {F} {G} ⊢F ⊢t ⊢t′ t≡t′) with\n fundamental ⊢F | fundamentalTerm ⊢t |\n fundamentalTerm ⊢t′ | fundamentalTermEq t≡t′\n ... | [Γ] , [F] | [Γ]₁ , [ΠFG] , [t] | [Γ]₂ , [ΠFG]₁ , [t′]\n | [Γ]₃ , modelsTermEq [G] [t0] [t′0] [t0≡t′0] =\n let [F]′ = S.irrelevance {A = F} [Γ] [Γ]₁ [F]\n [G]′ = S.irrelevance {A = G} [Γ]₃ ([Γ]₁ ∙′ [F]′) [G]\n [t′]′ = S.irrelevanceTerm {A = Π F ▹ G} {t = g}\n [Γ]₂ [Γ]₁ [ΠFG]₁ [ΠFG] [t′]\n [ΠFG]″ = Πᵛ {F} {G} [Γ]₁ [F]′ [G]′\n [t]″ = S.irrelevanceTerm {A = Π F ▹ G} {t = f}\n [Γ]₁ [Γ]₁ [ΠFG] [ΠFG]″ [t]\n [t′]″ = S.irrelevanceTerm {A = Π F ▹ G} {t = g}\n [Γ]₂ [Γ]₁ [ΠFG]₁ [ΠFG]″ [t′]\n [t0≡t′0]′ = S.irrelevanceEqTerm {A = G} {t = wk1 f ∘ var 0}\n {u = wk1 g ∘ var 0}\n [Γ]₃ ([Γ]₁ ∙′ [F]′) [G] [G]′ [t0≡t′0]\n [t≡t′] = η-eqᵛ {f} {g} {F} {G} [Γ]₁ [F]′ [G]′ [t]″ [t′]″ [t0≡t′0]′\n [t≡t′]′ = S.irrelevanceEqTerm {A = Π F ▹ G} {t = f} {u = g}\n [Γ]₁ [Γ]₁ [ΠFG]″ [ΠFG] [t≡t′]\n in [Γ]₁ , modelsTermEq [ΠFG] [t] [t′]′ [t≡t′]′\n fundamentalTermEq (suc-cong x) with fundamentalTermEq x\n fundamentalTermEq (suc-cong {t} {u} x)\n | [Γ] , modelsTermEq [A] [t] [u] [t≡u] =\n let [suct] = sucᵛ {n = t} [Γ] [A] [t]\n [sucu] = sucᵛ {n = u} [Γ] [A] [u]\n in [Γ] , modelsTermEq [A] [suct] [sucu]\n (λ ⊢Δ [σ] →\n sucEqTerm (proj₁ ([A] ⊢Δ [σ])) ([t≡u] ⊢Δ [σ]))\n fundamentalTermEq (natrec-cong {z} {z′} {s} {s′} {n} {n′} {F} {F′}\n F≡F′ z≡z′ s≡s′ n≡n′)\n with fundamentalEq F≡F′ |\n fundamentalTermEq z≡z′ |\n fundamentalTermEq s≡s′ |\n fundamentalTermEq n≡n′\n fundamentalTermEq (natrec-cong {z} {z′} {s} {s′} {n} {n′} {F} {F′}\n F≡F′ z≡z′ s≡s′ n≡n′) |\n [Γ] , [F] , [F′] , [F≡F′] |\n [Γ]₁ , modelsTermEq [F₀] [z] [z′] [z≡z′] |\n [Γ]₂ , modelsTermEq [F₊] [s] [s′] [s≡s′] |\n [Γ]₃ , modelsTermEq [ℕ] [n] [n′] [n≡n′] =\n let sType = Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)\n s′Type = Π ℕ ▹ (F′ ▹▹ F′ [ suc (var 0) ]↑)\n [0] = S.irrelevanceTerm {l = ¹} {A = ℕ} {t = zero}\n [Γ]₃ [Γ]₃ (ℕᵛ [Γ]₃) [ℕ] (zeroᵛ {l = ¹} [Γ]₃)\n [F]′ = S.irrelevance {A = F} [Γ] ([Γ]₃ ∙′ [ℕ]) [F]\n [F₀]′ = S.irrelevance {A = F [ zero ]} [Γ]₁ [Γ]₃ [F₀]\n [F₊]′ = S.irrelevance {A = sType} [Γ]₂ [Γ]₃ [F₊]\n [Fₙ]′ = substS {ℕ} {F} {n} [Γ]₃ [ℕ] [F]′ [n]\n [F′]′ = S.irrelevance {A = F′} [Γ] ([Γ]₃ ∙′ [ℕ]) [F′]\n [F₀]″ = substS {ℕ} {F} {zero} [Γ]₃ [ℕ] [F]′ [0]\n [F′₀]′ = substS {ℕ} {F′} {zero} [Γ]₃ [ℕ] [F′]′ [0]\n [F′₊]′ = sucCase {F′} [Γ]₃ [ℕ] [F′]′\n [F′ₙ′]′ = substS {ℕ} {F′} {n′} [Γ]₃ [ℕ] [F′]′ [n′]\n [ℕ≡ℕ] = reflᵛ {ℕ} [Γ]₃ [ℕ]\n [0≡0] = reflᵗᵛ {ℕ} {zero} [Γ]₃ [ℕ] [0]\n [F≡F′]′ = S.irrelevanceEq {A = F} {B = F′}\n [Γ] ([Γ]₃ ∙′ [ℕ]) [F] [F]′ [F≡F′]\n [F₀≡F′₀] = substSEq {ℕ} {ℕ} {F} {F′} {zero} {zero}\n [Γ]₃ [ℕ] [ℕ] [ℕ≡ℕ]\n [F]′ [F′]′ [F≡F′]′ [0] [0] [0≡0]\n [F₀≡F′₀]′ = S.irrelevanceEq {A = F [ zero ]} {B = F′ [ zero ]}\n [Γ]₃ [Γ]₃ [F₀]″ [F₀]′ [F₀≡F′₀]\n [F₊≡F′₊] = sucCaseCong {F} {F′} [Γ]₃ [ℕ] [F]′ [F′]′ [F≡F′]′\n [F₊≡F′₊]′ = S.irrelevanceEq {A = sType} {B = s′Type}\n [Γ]₃ [Γ]₃ (sucCase {F} [Γ]₃ [ℕ] [F]′)\n [F₊]′ [F₊≡F′₊]\n [Fₙ≡F′ₙ′]′ = substSEq {ℕ} {ℕ} {F} {F′} {n} {n′}\n [Γ]₃ [ℕ] [ℕ] [ℕ≡ℕ] [F]′ [F′]′ [F≡F′]′\n [n] [n′] [n≡n′]\n [z]′ = S.irrelevanceTerm {A = F [ zero ]} {t = z}\n [Γ]₁ [Γ]₃ [F₀] [F₀]′ [z]\n [z′]′ = convᵛ {z′} {F [ zero ]} {F′ [ zero ]}\n [Γ]₃ [F₀]′ [F′₀]′ [F₀≡F′₀]′\n (S.irrelevanceTerm {A = F [ zero ]} {t = z′}\n [Γ]₁ [Γ]₃ [F₀] [F₀]′ [z′])\n [z≡z′]′ = S.irrelevanceEqTerm {A = F [ zero ]} {t = z} {u = z′}\n [Γ]₁ [Γ]₃ [F₀] [F₀]′ [z≡z′]\n [s]′ = S.irrelevanceTerm {A = sType} {t = s} [Γ]₂ [Γ]₃ [F₊] [F₊]′ [s]\n [s′]′ = convᵛ {s′} {sType} {s′Type} [Γ]₃ [F₊]′ [F′₊]′ [F₊≡F′₊]′\n (S.irrelevanceTerm {A = sType} {t = s′}\n [Γ]₂ [Γ]₃ [F₊] [F₊]′ [s′])\n [s≡s′]′ = S.irrelevanceEqTerm {A = sType} {t = s} {u = s′}\n [Γ]₂ [Γ]₃ [F₊] [F₊]′ [s≡s′]\n in [Γ]₃\n , modelsTermEq [Fₙ]′\n (natrecᵛ {F} {z} {s} {n}\n [Γ]₃ [ℕ] [F]′ [F₀]′ [F₊]′ [Fₙ]′ [z]′ [s]′ [n])\n (conv₂ᵛ {natrec F′ z′ s′ n′} {F [ n ]} {F′ [ n′ ]}\n [Γ]₃ [Fₙ]′ [F′ₙ′]′ [Fₙ≡F′ₙ′]′\n (natrecᵛ {F′} {z′} {s′} {n′}\n [Γ]₃ [ℕ] [F′]′ [F′₀]′ [F′₊]′ [F′ₙ′]′\n [z′]′ [s′]′ [n′]))\n (natrec-congᵛ {F} {F′} {z} {z′} {s} {s′} {n} {n′}\n [Γ]₃ [ℕ] [F]′ [F′]′ [F≡F′]′\n [F₀]′ [F′₀]′ [F₀≡F′₀]′\n [F₊]′ [F′₊]′ [F₊≡F′₊]′ [Fₙ]′\n [z]′ [z′]′ [z≡z′]′\n [s]′ [s′]′ [s≡s′]′ [n] [n′] [n≡n′])\n fundamentalTermEq (natrec-zero {z} {s} {F} ⊢F ⊢z ⊢s)\n with fundamental ⊢F | fundamentalTerm ⊢z | fundamentalTerm ⊢s\n fundamentalTermEq (natrec-zero {z} {s} {F} ⊢F ⊢z ⊢s) | [Γ] , [F]\n | [Γ]₁ , [F₀] , [z] | [Γ]₂ , [F₊] , [s] =\n let sType = Π ℕ ▹ (F ▹▹ F [ suc (var 0) ]↑)\n [Γ]′ = [Γ]₁\n [ℕ]′ = ℕᵛ {l = ¹} [Γ]′\n [F₊]′ = S.irrelevance {A = sType} [Γ]₂ [Γ]′ [F₊]\n [s]′ = S.irrelevanceTerm {A = sType} {t = s} [Γ]₂ [Γ]′ [F₊] [F₊]′ [s]\n [F]′ = S.irrelevance {A = F} [Γ] ([Γ]′ ∙′ [ℕ]′) [F]\n d , r =\n redSubstTermᵛ {F [ zero ]} {natrec F z s zero} {z} [Γ]′\n (λ {Δ} {σ} ⊢Δ [σ] →\n let ⊢ℕ = escape (proj₁ ([ℕ]′ ⊢Δ [σ]))\n ⊢F = escape (proj₁ ([F]′ (⊢Δ ∙ ⊢ℕ)\n (liftSubstS {F = ℕ}\n [Γ]′ ⊢Δ [ℕ]′ [σ])))\n ⊢z = PE.subst (λ x → Δ ⊢ subst σ z ∷ x)\n (singleSubstLift F zero)\n (escapeTerm (proj₁ ([F₀] ⊢Δ [σ]))\n (proj₁ ([z] ⊢Δ [σ])))\n ⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x)\n (natrecSucCase σ F)\n (escapeTerm (proj₁ ([F₊]′ ⊢Δ [σ]))\n (proj₁ ([s]′ ⊢Δ [σ])))\n in PE.subst (λ x → Δ ⊢ subst σ (natrec F z s zero)\n ⇒ subst σ z ∷ x)\n (PE.sym (singleSubstLift F zero))\n (natrec-zero ⊢F ⊢z ⊢s))\n [F₀] [z]\n in [Γ]′ , modelsTermEq [F₀] d [z] r\n fundamentalTermEq (natrec-suc {n} {z} {s} {F} ⊢n ⊢F ⊢z ⊢s)\n with fundamentalTerm ⊢n | fundamental ⊢F\n | fundamentalTerm ⊢z | fundamentalTerm ⊢s\n ... | [Γ] , [ℕ] , [n] | [Γ]₁ , [F] | [Γ]₂ , [F₀] , [z] | [Γ]₃ , [F₊] , [s] =\n let [ℕ]′ = S.irrelevance {A = ℕ} [Γ] [Γ]₃ [ℕ]\n [n]′ = S.irrelevanceTerm {A = ℕ} {t = n} [Γ] [Γ]₃ [ℕ] [ℕ]′ [n]\n [sucn] = sucᵛ {n = n} [Γ]₃ [ℕ]′ [n]′\n [F₀]′ = S.irrelevance {A = F [ zero ]} [Γ]₂ [Γ]₃ [F₀]\n [z]′ = S.irrelevanceTerm {A = F [ zero ]} {t = z}\n [Γ]₂ [Γ]₃ [F₀] [F₀]′ [z]\n [F]′ = S.irrelevance {A = F} [Γ]₁ ([Γ]₃ ∙′ [ℕ]′) [F]\n [F[sucn]] = substS {ℕ} {F} {suc n} [Γ]₃ [ℕ]′ [F]′ [sucn]\n [Fₙ]′ = substS {ℕ} {F} {n} [Γ]₃ [ℕ]′ [F]′ [n]′\n [natrecₙ] = natrecᵛ {F} {z} {s} {n}\n [Γ]₃ [ℕ]′ [F]′ [F₀]′ [F₊] [Fₙ]′ [z]′ [s] [n]′\n t = (s ∘ n) ∘ (natrec F z s n)\n q = subst (liftSubst (sgSubst n))\n (wk1 (F [ suc (var 0) ]↑))\n y = S.irrelevanceTerm′\n {A = q [ natrec F z s n ]} {A′ = F [ suc n ]} {t = t}\n (natrecIrrelevantSubst′ F z s n) [Γ]₃ [Γ]₃\n (substSΠ {F [ n ]} {q} {natrec F z s n} [Γ]₃\n (substS {ℕ} {F} {n} [Γ]₃ [ℕ]′ [F]′ [n]′)\n (substSΠ {ℕ} {F ▹▹ F [ suc (var 0) ]↑} {n}\n [Γ]₃ [ℕ]′ [F₊] [n]′)\n [natrecₙ])\n [F[sucn]]\n (appᵛ {F [ n ]} {q} {s ∘ n} {natrec F z s n} [Γ]₃ [Fₙ]′\n (substSΠ {ℕ} {F ▹▹ F [ suc (var 0) ]↑} {n}\n [Γ]₃ [ℕ]′ [F₊] [n]′)\n (appᵛ {ℕ} {F ▹▹ F [ suc (var 0) ]↑} {s} {n}\n [Γ]₃ [ℕ]′ [F₊] [s] [n]′)\n [natrecₙ])\n d , r =\n redSubstTermᵛ {F [ suc n ]} {natrec F z s (suc n)} {t } {¹} {_} [Γ]₃\n (λ {Δ} {σ} ⊢Δ [σ] →\n let ⊢n = escapeTerm (proj₁ ([ℕ]′ ⊢Δ [σ]))\n (proj₁ ([n]′ ⊢Δ [σ]))\n ⊢ℕ = escape (proj₁ ([ℕ]′ ⊢Δ [σ]))\n ⊢F = escape (proj₁ ([F]′ (⊢Δ ∙ ⊢ℕ)\n (liftSubstS {F = ℕ}\n [Γ]₃ ⊢Δ [ℕ]′ [σ])))\n ⊢z = PE.subst (λ x → Δ ⊢ subst σ z ∷ x)\n (singleSubstLift F zero)\n (escapeTerm (proj₁ ([F₀]′ ⊢Δ [σ]))\n (proj₁ ([z]′ ⊢Δ [σ])))\n ⊢s = PE.subst (λ x → Δ ⊢ subst σ s ∷ x)\n (natrecSucCase σ F)\n (escapeTerm (proj₁ ([F₊] ⊢Δ [σ]))\n (proj₁ ([s] ⊢Δ [σ])))\n r = _⊢_⇒_∷_.natrec-suc {n = subst σ n}\n {z = subst σ z} {s = subst σ s}\n {F = subst (liftSubst σ) F}\n ⊢n ⊢F ⊢z ⊢s\n in PE.subst (λ x → Δ ⊢ subst σ (natrec F z s (suc n))\n ⇒ (subst σ t) ∷ x)\n (PE.trans (PE.trans (substCompEq F)\n (substVar-to-subst (λ { 0 → PE.refl\n ; (1+ x) → PE.trans (subst-wk (σ x))\n (subst-id (σ x))\n })\n F))\n (PE.sym (substCompEq F)))\n r)\n [F[sucn]] y\n in [Γ]₃ , modelsTermEq [F[sucn]] d y r\n\n-- Fundamental theorem for substitutions.\nfundamentalSubst : ∀ {Γ Δ σ} (⊢Γ : ⊢ Γ) (⊢Δ : ⊢ Δ)\n → Δ ⊢ˢ σ ∷ Γ\n → ∃ω₄ λ [Γ] → Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ\nfundamentalSubst ε ⊢Δ [σ] = ε′ , tt\nfundamentalSubst (⊢Γ ∙ ⊢A) ⊢Δ ([tailσ] , [headσ]) =\n let [Γ] , [A] = fundamental ⊢A\n [Δ] , [A]′ , [t] = fundamentalTerm [headσ]\n [Γ]′ , [σ] = fundamentalSubst ⊢Γ ⊢Δ [tailσ]\n [tailσ]′ = S.irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [σ]\n [idA] = proj₁ ([A]′ (soundContext [Δ]) (idSubstS [Δ]))\n [idA]′ = proj₁ ([A] ⊢Δ [tailσ]′)\n [idt] = proj₁ ([t] (soundContext [Δ]) (idSubstS [Δ]))\n in [Γ] ∙′ [A] , ([tailσ]′\n , irrelevanceTerm″ (subst-id _) (subst-id _) [idA] [idA]′ [idt])\n\n-- Fundamental theorem for substitution equality.\nfundamentalSubstEq : ∀ {Γ Δ σ σ′} (⊢Γ : ⊢ Γ) (⊢Δ : ⊢ Δ)\n → Δ ⊢ˢ σ ≡ σ′ ∷ Γ\n → ∃ω₄ λ [Γ]\n → ∃ω₃² λ [σ] ([σ′] : Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ)\n → Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]\nfundamentalSubstEq ε ⊢Δ σ = ε′ , tt , tt , tt\nfundamentalSubstEq (⊢Γ ∙ ⊢A) ⊢Δ (tailσ≡σ′ , headσ≡σ′) =\n let [Γ] , [A] = fundamental ⊢A\n [Γ]′ , [tailσ] , [tailσ′] , [tailσ≡σ′] = fundamentalSubstEq ⊢Γ ⊢Δ tailσ≡σ′\n [Δ] , modelsTermEq [A]′ [t] [t′] [t≡t′] = fundamentalTermEq headσ≡σ′\n [tailσ]′ = S.irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [tailσ]\n [tailσ′]′ = S.irrelevanceSubst [Γ]′ [Γ] ⊢Δ ⊢Δ [tailσ′]\n [tailσ≡σ′]′ = S.irrelevanceSubstEq [Γ]′ [Γ] ⊢Δ ⊢Δ [tailσ] [tailσ]′ [tailσ≡σ′]\n [idA] = proj₁ ([A]′ (soundContext [Δ]) (idSubstS [Δ]))\n [idA]′ = proj₁ ([A] ⊢Δ [tailσ]′)\n [idA]″ = proj₁ ([A] ⊢Δ [tailσ′]′)\n [idt] = proj₁ ([t] (soundContext [Δ]) (idSubstS [Δ]))\n [idt′] = proj₁ ([t′] (soundContext [Δ]) (idSubstS [Δ]))\n [idt≡t′] = [t≡t′] (soundContext [Δ]) (idSubstS [Δ])\n in [Γ] ∙′ [A]\n , ([tailσ]′ , irrelevanceTerm″ (subst-id _) (subst-id _) [idA] [idA]′ [idt])\n , ([tailσ′]′ , convTerm₁ [idA]′ [idA]″\n (proj₂ ([A] ⊢Δ [tailσ]′) [tailσ′]′ [tailσ≡σ′]′)\n (irrelevanceTerm″ (subst-id _) (subst-id _)\n [idA] [idA]′ [idt′]))\n , ([tailσ≡σ′]′ , irrelevanceEqTerm″ (subst-id _) (subst-id _) (subst-id _)\n [idA] [idA]′ [idt≡t′])\n", "meta": {"hexsha": "98a735e6a9712259b72ecaa266c639c52af8fe4b", "size": 29738, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation/Fundamental.agda", "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Fundamental.agda", "max_issues_repo_name": "loic-p/logrel-mltt", "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation/Fundamental.agda", "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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": 53.1035714286, "max_line_length": 83, "alphanum_fraction": 0.3635415966, "num_tokens": 13920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.3549809737929451}} {"text": "{-\nThis second-order term syntax was created from the following second-order syntax description:\n\nsyntax Sum | S\n\ntype\n _⊕_ : 2-ary | l30\n\nterm\n inl : α -> α ⊕ β\n inr : β -> α ⊕ β\n case : α ⊕ β α.γ β.γ -> γ\n\ntheory\n (lβ) a : α f : α.γ g : β.γ |> case (inl(a), x.f[x], y.g[y]) = f[a]\n (rβ) b : β f : α.γ g : β.γ |> case (inr(b), x.f[x], y.g[y]) = g[b]\n (cη) s : α ⊕ β c : (α ⊕ β).γ |> case (s, x.c[inl(x)], y.c[inr(y)]) = c[s]\n-}\n\n\nmodule Sum.Syntax where\n\nopen import SOAS.Common\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.Families.Core\nopen import SOAS.Construction.Structure\nopen import SOAS.ContextMaps.Inductive\n\nopen import SOAS.Metatheory.Syntax\n\nopen import Sum.Signature\n\nprivate\n variable\n Γ Δ Π : Ctx\n α β γ : ST\n 𝔛 : Familyₛ\n\n-- Inductive term declaration\nmodule S:Terms (𝔛 : Familyₛ) where\n\n data S : Familyₛ where\n var : ℐ ⇾̣ S\n mvar : 𝔛 α Π → Sub S Π Γ → S α Γ\n\n inl : S α Γ → S (α ⊕ β) Γ\n inr : S β Γ → S (α ⊕ β) Γ\n case : S (α ⊕ β) Γ → S γ (α ∙ Γ) → S γ (β ∙ Γ) → S γ Γ\n\n\n\n open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛\n\n Sᵃ : MetaAlg S\n Sᵃ = record\n { 𝑎𝑙𝑔 = λ where\n (inlₒ ⋮ a) → inl a\n (inrₒ ⋮ a) → inr a\n (caseₒ ⋮ a , b , c) → case a b c\n ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }\n\n module Sᵃ = MetaAlg Sᵃ\n\n module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where\n\n open MetaAlg 𝒜ᵃ\n\n 𝕤𝕖𝕞 : S ⇾̣ 𝒜\n 𝕊 : Sub S Π Γ → Π ~[ 𝒜 ]↝ Γ\n 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t\n 𝕊 (t ◂ σ) (old v) = 𝕊 σ v\n 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)\n 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v\n\n 𝕤𝕖𝕞 (inl a) = 𝑎𝑙𝑔 (inlₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (inr a) = 𝑎𝑙𝑔 (inrₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (case a b c) = 𝑎𝑙𝑔 (caseₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b , 𝕤𝕖𝕞 c)\n\n 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Sᵃ 𝒜ᵃ 𝕤𝕖𝕞\n 𝕤𝕖𝕞ᵃ⇒ = record\n { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }\n ; ⟨𝑣𝑎𝑟⟩ = refl\n ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }\n where\n open ≡-Reasoning\n ⟨𝑎𝑙𝑔⟩ : (t : ⅀ S α Γ) → 𝕤𝕖𝕞 (Sᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)\n ⟨𝑎𝑙𝑔⟩ (inlₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (inrₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (caseₒ ⋮ _) = refl\n\n 𝕊-tab : (mε : Π ~[ S ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)\n 𝕊-tab mε new = refl\n 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v\n\n module _ (g : S ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Sᵃ 𝒜ᵃ g) where\n\n open MetaAlg⇒ gᵃ⇒\n\n 𝕤𝕖𝕞! : (t : S α Γ) → 𝕤𝕖𝕞 t ≡ g t\n 𝕊-ix : (mε : Sub S Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)\n 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x\n 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v\n 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))\n = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))\n 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩\n\n 𝕤𝕖𝕞! (inl a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (inr a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (case a b c) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b | 𝕤𝕖𝕞! c = sym ⟨𝑎𝑙𝑔⟩\n\n\n-- Syntax instance for the signature\nS:Syn : Syntax\nS:Syn = record\n { ⅀F = ⅀F\n ; ⅀:CS = ⅀:CompatStr\n ; mvarᵢ = S:Terms.mvar\n ; 𝕋:Init = λ 𝔛 → let open S:Terms 𝔛 in record\n { ⊥ = S ⋉ Sᵃ\n ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }\n ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }\n\n-- Instantiation of the syntax and metatheory\nopen Syntax S:Syn public\nopen S:Terms public\nopen import SOAS.Families.Build public\nopen import SOAS.Syntax.Shorthands Sᵃ public\nopen import SOAS.Metatheory S:Syn public\n", "meta": {"hexsha": "3c736841ffdb4a80e8957160dcc35009897e336a", "size": 3402, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "out/Sum/Syntax.agda", "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_issues_repo_path": "out/Sum/Syntax.agda", "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_forks_repo_path": "out/Sum/Syntax.agda", "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "avg_line_length": 26.1692307692, "max_line_length": 93, "alphanum_fraction": 0.5149911817, "num_tokens": 2154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442250928250375, "lm_q2_score": 0.5506073655352403, "lm_q1q2_score": 0.3547150811720895}} {"text": "module Plylet where\r\n\r\nopen import Data.String.Base\r\nopen import Data.Char.Base\r\nopen import Data.List.Base\r\n\r\ndata Type : Set where\r\n -- The type of the unit value\r\n TUnit : Type\r\n -- The type constructor for functions →\r\n TFunc : Type -> Type -> Type\r\n -- A type loaded from the prelude\r\n TBuiltin : String -> Type\r\n\r\ndata Term : Set where\r\n -- The value of unit\r\n VUnit : Term\r\n -- An well-typed application is a valid term\r\n VApp : Term → Term → Term\r\n -- A well-formed let expression is a valid term\r\n VLet : Char -> Term -> Term -> Term\r\n -- A function from the prelude\r\n VFunc : String -> Term\r\n\r\ndata Judgment : Set where\r\n -- A typing judgment\r\n TypeJ : Term → Type → Judgment\r\n -- A coercion validity judgment\r\n CoerceJ : Type → Type → Judgment\r\n\r\nGamma : Set\r\nGamma = List Judgment\r\n\r\nbaseEnv : Gamma\r\nbaseEnv =\r\n TypeJ VUnit TUnit\r\n ∷ []\r\n", "meta": {"hexsha": "7a9726f09d71214cadb19b8a59c8ef8a6bdf15d1", "size": 871, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Plylet.agda", "max_stars_repo_name": "Kazark/plylet", "max_stars_repo_head_hexsha": "0fd0c9d0ff00529b48f65b638fe288172916bf71", "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": "Plylet.agda", "max_issues_repo_name": "Kazark/plylet", "max_issues_repo_head_hexsha": "0fd0c9d0ff00529b48f65b638fe288172916bf71", "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": "Plylet.agda", "max_forks_repo_name": "Kazark/plylet", "max_forks_repo_head_hexsha": "0fd0c9d0ff00529b48f65b638fe288172916bf71", "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": 22.9210526316, "max_line_length": 50, "alphanum_fraction": 0.6509758898, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737344123243, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.3546116088316675}} {"text": "open import Agda.Builtin.Equality\nopen import Agda.Primitive\n\nrecord R a : Set (lsuc a) where\n field\n P : {A : Set a} → A → A → Set a\n\nr : ∀ ℓ → R ℓ\nR.P (r _) = _≡_\n\npostulate\n cong : ∀ {a b} {A : Set a} {B : Set b} {x y : A}\n (f : A → B) → R.P (r a) x y → R.P (r b) (f x) (f y)\n magic : ∀ {a} {A : Set a} {x y : A} (z : A) → y ≡ z → x ≡ z\n\nrecord Raw-monad {f : Level → Level}\n (M : ∀ {ℓ} → Set ℓ → Set (f ℓ)) ℓ₁ ℓ₂ :\n Set (f ℓ₁ ⊔ f ℓ₂ ⊔ lsuc (ℓ₁ ⊔ ℓ₂)) where\n infixl 5 _>>=_\n field\n return : {A : Set ℓ₁} → A → M A\n _>>=_ : {A : Set ℓ₁} {B : Set ℓ₂} → M A → (A → M B) → M B\n\nmodule Raw-monad⁺\n {f : Level → Level}\n {M : ∀ {ℓ} → Set ℓ → Set (f ℓ)}\n (m : ∀ {ℓ₁ ℓ₂} → Raw-monad M ℓ₁ ℓ₂)\n where\n\n private\n module M′ {ℓ₁ ℓ₂} = Raw-monad (m {ℓ₁ = ℓ₁} {ℓ₂ = ℓ₂})\n open M′ public using (_>>=_)\n\n return : ∀ {a} {A : Set a} → A → M A\n return = M′.return {ℓ₂ = lzero}\n\nopen Raw-monad⁺ ⦃ … ⦄ public\n\nrecord Monad⁻ {f : Level → Level}\n (M : ∀ {ℓ} → Set ℓ → Set (f ℓ))\n ⦃ raw-monad : ∀ {ℓ₁ ℓ₂} → Raw-monad M ℓ₁ ℓ₂ ⦄\n ℓ₁ ℓ₂ ℓ₃ :\n Set (f ℓ₁ ⊔ f ℓ₂ ⊔ f ℓ₃ ⊔ lsuc (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃)) where\n field\n associativity :\n {A : Set ℓ₁} {B : Set ℓ₂} {C : Set ℓ₃} →\n (x : M A) (f : A → M B) (g : B → M C) →\n x >>= (λ x → f x >>= g) ≡ x >>= f >>= g\n\nmodule Monad⁻⁺\n {f : Level → Level}\n {M : ∀ {ℓ} → Set ℓ → Set (f ℓ)}\n ⦃ raw-monad : ∀ {ℓ₁ ℓ₂} → Raw-monad M ℓ₁ ℓ₂ ⦄\n (m : ∀ {ℓ₁ ℓ₂ ℓ₃} → Monad⁻ M ℓ₁ ℓ₂ ℓ₃)\n where\n\n private\n module M′ {ℓ₁ ℓ₂ ℓ₃} = Monad⁻ (m {ℓ₁ = ℓ₁} {ℓ₂ = ℓ₂} {ℓ₃ = ℓ₃})\n open M′ public\n\nopen Monad⁻⁺ ⦃ … ⦄ public\n\ndata Maybe {a} (A : Set a) : Set a where\n nothing : Maybe A\n just : A → Maybe A\n\npostulate\n maybe : ∀ {a b} {A : Set a} {B : Maybe A → Set b} →\n ((x : A) → B (just x)) → B nothing → (x : Maybe A) → B x\n\nrecord MaybeT {ℓ}\n (f : Level → Level)\n (M : Set ℓ → Set (f ℓ))\n (A : Set ℓ) : Set (f ℓ) where\n constructor wrap\n field\n run : M (Maybe A)\n\nopen MaybeT\n\ninstance\n\n transformʳ :\n ∀ {ℓ₁ ℓ₂}\n {f : Level → Level}\n {M : ∀ {ℓ} → Set ℓ → Set (f ℓ)} →\n ⦃ raw-monad : ∀ {ℓ₁ ℓ₂} → Raw-monad M ℓ₁ ℓ₂ ⦄ →\n Raw-monad (MaybeT f M) ℓ₁ ℓ₂\n run (Raw-monad.return transformʳ x) = return (just x)\n run (Raw-monad._>>=_ transformʳ x f) =\n run x >>= maybe (λ x → run (f x)) (return nothing)\n\ntransformᵐ :\n {f : Level → Level}\n {M : ∀ {ℓ} → Set ℓ → Set (f ℓ)}\n ⦃ raw-monad : ∀ {ℓ₁ ℓ₂} → Raw-monad M ℓ₁ ℓ₂ ⦄\n ⦃ monad : ∀ {ℓ₁ ℓ₂ ℓ₃} → Monad⁻ M ℓ₁ ℓ₂ ℓ₃ ⦄ →\n Monad⁻ (MaybeT f M) lzero lzero lzero\nMonad⁻.associativity transformᵐ x f g = cong wrap (\n magic ((run x >>= maybe (λ x → run (f x)) (return nothing)) >>=\n maybe (λ x → run (g x)) (return nothing))\n (associativity _ _ _))\n\n-- WAS: rejected in 2.6.0 with\n-- No instance of type Raw-monad _M_345 ℓ₁ ℓ₂ was found in scope.\n\n-- Should succeed.\n", "meta": {"hexsha": "2025ad04931cf9f85ca11af138615d8c51347e8e", "size": 2932, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue4066.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/Succeed/Issue4066.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/Succeed/Issue4066.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": 27.1481481481, "max_line_length": 67, "alphanum_fraction": 0.4826057299, "num_tokens": 1358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737214979745, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.35461160212238746}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import cw.CW\nopen import homotopy.DisjointlyPointedSet\nopen import groups.Int\nopen import cohomology.Theory\nopen import cohomology.ChainComplex\n\nmodule cw.cohomology.ReconstructedCochainsIsoCellularCochains {i : ULevel}\n (OT : OrdinaryTheory i) where\n\n open OrdinaryTheory OT\n open import cw.cohomology.WedgeOfCells OT\n open import cw.cohomology.cellular.ChainComplex as CCC\n open import cw.cohomology.reconstructed.cochain.Complex OT as RCC\n open import cw.cohomology.reconstructed.TipAndAugment OT\n\n private\n rcc-iso-ccc-nth : ∀ {n} (⊙skel : ⊙Skeleton n) {m} (m≤n : m ≤ n)\n → ⊙has-cells-with-choice 0 ⊙skel i\n → AbGroup.grp (RCC.cochain-template ⊙skel (inl m≤n))\n ≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) (inl m≤n))) (C2-abgroup 0)\n rcc-iso-ccc-nth ⊙skel {m = O} (inl idp) ac\n = FreeAbGroup-extend-iso (C2-abgroup 0)\n ∘eᴳ C2×CX₀-diag-β ⊙skel ac\n rcc-iso-ccc-nth ⊙skel {m = S m} (inl idp) ac\n = FreeAbGroup-extend-iso (C2-abgroup 0)\n ∘eᴳ CXₙ/Xₙ₋₁-diag-β ⊙skel ac\n rcc-iso-ccc-nth ⊙skel {m = O} (inr ltS) ac =\n rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inl idp) (⊙init-has-cells-with-choice ⊙skel ac)\n rcc-iso-ccc-nth ⊙skel {m = S m} (inr ltS) ac =\n rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inl idp) (⊙init-has-cells-with-choice ⊙skel ac)\n rcc-iso-ccc-nth ⊙skel {m = O} (inr (ltSR lt)) ac =\n rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inr lt) (⊙init-has-cells-with-choice ⊙skel ac)\n rcc-iso-ccc-nth ⊙skel {m = S m} (inr (ltSR lt)) ac =\n rcc-iso-ccc-nth (⊙cw-init ⊙skel) (inr lt) (⊙init-has-cells-with-choice ⊙skel ac)\n\n rcc-iso-ccc-above : ∀ {n} (⊙skel : ⊙Skeleton n) {m} (m≰n : ¬ (m ≤ n))\n → AbGroup.grp (RCC.cochain-template ⊙skel (inr m≰n))\n ≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) (inr m≰n))) (C2-abgroup 0)\n rcc-iso-ccc-above ⊙skel _\n = pre∘ᴳ-iso (C2-abgroup 0) lower-iso\n ∘eᴳ trivial-iso-Unit (hom₁-Unit-is-trivial (C2-abgroup 0)) ⁻¹ᴳ\n ∘eᴳ lower-iso\n\n rcc-iso-ccc-template : ∀ {n} (⊙skel : ⊙Skeleton n) {m : ℕ} (m≤n? : Dec (m ≤ n))\n → ⊙has-cells-with-choice 0 ⊙skel i\n → AbGroup.grp (RCC.cochain-template ⊙skel m≤n?)\n ≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) m≤n?)) (C2-abgroup 0)\n rcc-iso-ccc-template ⊙skel {m} (inl m≤n) ac = rcc-iso-ccc-nth ⊙skel m≤n ac\n rcc-iso-ccc-template ⊙skel {m} (inr m≰n) _ = rcc-iso-ccc-above ⊙skel m≰n\n\n rcc-iso-ccc : ∀ {n} (⊙skel : ⊙Skeleton n) (m : ℕ)\n → ⊙has-cells-with-choice 0 ⊙skel i\n → AbGroup.grp (RCC.cochain-template ⊙skel (≤-dec m n))\n ≃ᴳ hom-group (AbGroup.grp (CCC.chain-template (⊙Skeleton.skel ⊙skel) (≤-dec m n))) (C2-abgroup 0)\n rcc-iso-ccc {n} ⊙skel m = rcc-iso-ccc-template ⊙skel (≤-dec m n)\n\n rhead-iso-chead : C2 0 ≃ᴳ hom-group (Lift-group {j = i} ℤ-group) (C2-abgroup 0)\n rhead-iso-chead\n = pre∘ᴳ-iso (C2-abgroup 0) (lower-iso {j = i})\n ∘eᴳ ℤ→ᴳ-iso-idf (C2-abgroup 0) ⁻¹ᴳ\n", "meta": {"hexsha": "f79f6e64ab5d78b28a2f518fa97bdedeea72a59f", "size": 3010, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/cw/cohomology/ReconstructedCochainsIsoCellularCochains.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/cw/cohomology/ReconstructedCochainsIsoCellularCochains.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "theorems/cw/cohomology/ReconstructedCochainsIsoCellularCochains.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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.03125, "max_line_length": 101, "alphanum_fraction": 0.6352159468, "num_tokens": 1358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.3545588890469897}} {"text": "open import Prelude\nopen import Data.Vec\nopen import Data.List.Properties\nopen import Data.List.Any hiding (map)\nopen import Data.List.All as All using ()\nopen import Extensions.Vec\nopen import Data.Product hiding (map)\n\nmodule Implicits.Resolution.Ambiguous.Semantics where\n\nopen import Implicits.Syntax\nopen import Implicits.Resolution.Ambiguous.Resolution\nopen import Implicits.Substitutions\nopen import Implicits.Substitutions.Lemmas\nopen import Implicits.Semantics\nopen import Implicits.Semantics.Lemmas\n\n\nopen import SystemF.Everything as F using ()\n\nmodule DerivationSemantics where\n\n ⟦_,_⟧r : ∀ {ν n} {Δ} {Γ : Ctx ν n} {a} → Δ ⊢ᵣ a → Γ # Δ →\n ∃ λ t → ⟦ Γ ⟧ctx→ F.⊢ t ∈ ⟦ a ⟧tp→\n ⟦_,_⟧r (r-tabs {r = r} p) m with ⟦ p , #tvar m ⟧r\n ⟦_,_⟧r {Γ = Γ} (r-tabs {r = r} p) m | _ , x =\n , F.Λ (subst (λ u → u F.⊢ _ ∈ ⟦ r ⟧tp→) (⟦weaken⟧ctx→ Γ) x)\n ⟦_,_⟧r (r-tapp a p) m with ⟦ p , m ⟧r\n ⟦_,_⟧r {Γ = Γ} (r-tapp {r = a} b p) m | _ , x =\n , subst\n (λ u → ⟦ Γ ⟧ctx→ F.⊢ _ ∈ u)\n (sym $ ⟦a/sub⟧tp→ a b)\n (x F.[ ⟦ b ⟧tp→ ])\n ⟦_,_⟧r {Γ = Γ} {a = a} (r-ivar x) m with ∈⟶index (All.lookup m x)\n ⟦_,_⟧r {Γ = Γ} {a = a} (r-ivar x) m | i , lookup-i≡r =\n , subst (λ u → _ F.⊢ F.var i ∈ u) eq (F.var i)\n where\n eq = begin\n lookup i ⟦ Γ ⟧ctx→\n ≡⟨ sym $ lookup-⟦⟧ctx→ Γ i ⟩\n ⟦ lookup i Γ ⟧tp→\n ≡⟨ cong ⟦_⟧tp→ lookup-i≡r ⟩\n ⟦ a ⟧tp→ ∎\n ⟦_,_⟧r (r-iabs {a = a} p) m = , F.λ' ⟦ a ⟧tp→ (proj₂ ⟦ p , #ivar a m ⟧r)\n ⟦_,_⟧r (r-iapp p p₁) m = , (proj₂ ⟦ p , m ⟧r) F.· (proj₂ ⟦ p₁ , m ⟧r)\n\nopen Semantics _⊢ᵣ_ DerivationSemantics.⟦_,_⟧r public\n", "meta": {"hexsha": "270016f1ba133a46fd5cab81e10d7c54b9c09d1f", "size": 1607, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Implicits/Resolution/Ambiguous/Semantics.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/Ambiguous/Semantics.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/Ambiguous/Semantics.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": 33.4791666667, "max_line_length": 74, "alphanum_fraction": 0.5606720597, "num_tokens": 725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.35453161416909806}} {"text": "-- {-# OPTIONS --allow-unsolved-metas #-}\nmodule GUIgeneric.GUIFeaturesPart5 where\n\nopen import GUIgeneric.Prelude renaming (addButton to addButton')\n\nopen import GUIgeneric.GUIDefinitions renaming (add to add'; add' to add)\nopen import GUIgeneric.GUI\nopen import GUIgeneric.GUIExampleLib\nopen import StateSizedIO.GUI.WxGraphicsLibLevel3 renaming (addButton to addButton')\nopen import GUIgeneric.GUIFeatures\nopen import GUIgeneric.GUIFeaturesPart2 hiding ( main ; main1 )\nopen import GUIgeneric.GUIFeaturesPart3 hiding ( main ; Tea ; Cancel)\nopen import GUIgeneric.GUIFeaturesPart4 hiding ( main ; cancelNewStateSM ; cancelStateAdded ; cancelFeatureAdded )\nopen import GUIgeneric.GUIExample hiding (main )\n\n\n\ndata StatesBasicVM : Set where\n pay change soda serveSoda open' close : StatesBasicVM\n\nbasicVM : FMachine StatesBasicVM\nbasicVM .Features = ⊤\nbasicVM .AddStateF = ⊥\nbasicVM .GUIF f (inj₁ pay) =\n simpleSMState \"Pay\" (inj₁ change)\nbasicVM .GUIF f (inj₁ change) =\n simpleSMState \"Get Change\" (inj₁ soda)\nbasicVM .GUIF f (inj₁ soda) =\n simpleSMState \"Soda\" (inj₁ serveSoda)\nbasicVM .GUIF f (inj₁ serveSoda) =\n simpleSMState \"Serve Soda\" (inj₁ open')\nbasicVM .GUIF f (inj₁ open') =\n simpleSMState \"Open\" (inj₁ close)\nbasicVM .GUIF f (inj₁ close) =\n simpleSMState \"Close\" (inj₁ pay) \nbasicVM .GUIF f (inj₂ ())\n\nnewState : {A B : Set} → A ⊎ B ⊎ ⊤\nnewState = (inj₂ (inj₂ tt))\n\n{- handler for the new state to be added to the tea machine -}\nteaNewStateSM : (fm : FMachine StatesBasicVM)\n → SMachineState\n (StatesBasicVM ⊎ fm .AddStateF ⊎ ⊤)\n newState\nteaNewStateSM fm = simpleSMState \"Serve Tea\" (inj₁ open')\n\n{- add the new state to the feature machine -}\nTeaMAddNewState : FMachine StatesBasicVM\n → FMachine StatesBasicVM\nTeaMAddNewState fm =\n addOneStateFMachine fm (teaNewStateSM fm)\n\n{- add a dummy feature \"FeatureTea\" to the feature machine -}\nTeaMAddFeature : FMachine StatesBasicVM\n → FMachine StatesBasicVM\nTeaMAddFeature fm = addDummyFeatures\n (TeaMAddNewState fm)\n FeatureTea\n\n{- redefine in the feature machine one button -}\nTea : FMachine StatesBasicVM\n → FMachine StatesBasicVM\nTea fm .Features = TeaMAddFeature fm .Features\nTea fm .AddStateF = TeaMAddFeature fm .AddStateF\nTea fm .GUIF (f , yesTea) (inj₁ soda) =\n addBtn2StateMachine\n ( TeaMAddFeature fm .GUIF\n (f , yesTea) (inj₁ soda))\n \"Tea\" newState\nTea fm .GUIF f s = TeaMAddFeature fm .GUIF f s\n\n{- handler for the new state to be added to the cancel machine -}\ncancelNewStateSM : (fm : FMachine StatesBasicVM) →\n SMachineState (StatesBasicVM ⊎ fm .AddStateF ⊎ ⊤) newState\ncancelNewStateSM fm = simpleSMState \"Cancelling\" (inj₁ pay)\n\n{- add the state to the old feature machine -}\ncancelStateAdded : FMachine StatesBasicVM → FMachine StatesBasicVM\ncancelStateAdded fm = addOneStateFMachine fm (cancelNewStateSM fm)\n\n{- add a dummy feature \"FeatureCancel\" to the feature machine -}\ncancelFeatureAdded : FMachine StatesBasicVM → FMachine StatesBasicVM\ncancelFeatureAdded fm = addDummyFeatures\n (cancelStateAdded fm)\n FeatureCancel\n\n{- redefine in the feature machine one button -}\nCancel : FMachine StatesBasicVM\n → FMachine StatesBasicVM\nCancel fm .Features = cancelFeatureAdded fm .Features\nCancel fm .AddStateF = cancelFeatureAdded fm .AddStateF\nCancel fm .GUIF (f , yesCancel) (inj₁ soda) =\n addBtn2StateMachine (cancelFeatureAdded fm .GUIF (f , yesCancel) (inj₁ soda))\n \"Cancel\" newState\nCancel fm .GUIF f s = cancelFeatureAdded fm .GUIF f s\n\n{- add the Dummy free feature -}\nFreeMAddFeature : FMachine StatesBasicVM\n → FMachine StatesBasicVM\nFreeMAddFeature fm = addDummyFeatures fm FeatureFree\n\n{- redefine the pay button to free in case feature free is yesFree -}\nFree : FMachine StatesBasicVM\n → FMachine StatesBasicVM\nFree fm .Features = FreeMAddFeature fm .Features\nFree fm .AddStateF = FreeMAddFeature fm .AddStateF\nFree fm .GUIF (f , yesFree) (inj₁ pay) =\n simpleSMState \"Free\" (inj₁ soda)\nFree fm .GUIF (f , yesFree) (inj₁ open') =\n simpleSMState \"Skip\" (inj₁ pay)\nFree fm .GUIF f s = FreeMAddFeature fm .GUIF f s\n\nmain1 : NativeIO Unit\nmain1 = compileFeatureVM (Tea (Cancel basicVM)) ((_ , yesCancel) , yesTea) (inj₁ pay)\n\nmain2 : NativeIO Unit\nmain2 = compileFeatureVM (Free basicVM) (_ , yesFree) (inj₁ pay) --\n\nmultiFeatureMachine : FMachine StatesBasicVM\nmultiFeatureMachine = Free (Cancel (Tea basicVM))\n\nmain : NativeIO Unit\nmain = compileFeatureVM\n multiFeatureMachine\n (((_ , yesTea) , yesCancel) , noFree) (inj₁ pay)\n", "meta": {"hexsha": "fd9e4c7b74a0e4396f0e1cc5bcfdca246269121f", "size": 4846, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "examples/GUIgeneric/GUIFeaturesPart5.agda", "max_stars_repo_name": "stephanadls/state-dependent-gui", "max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z", "max_issues_repo_path": "examples/GUIgeneric/GUIFeaturesPart5.agda", "max_issues_repo_name": "stephanadls/state-dependent-gui", "max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "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": "examples/GUIgeneric/GUIFeaturesPart5.agda", "max_forks_repo_name": "stephanadls/state-dependent-gui", "max_forks_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "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.157480315, "max_line_length": 115, "alphanum_fraction": 0.6939744119, "num_tokens": 1383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7090191337850932, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3545095668925466}} {"text": "-- Basic intuitionistic propositional calculus, without ∨ or ⊥.\n-- Kripke-style semantics with contexts as concrete worlds, and glueing for α and ▻.\n-- Hilbert-style syntax.\n\nmodule BasicIPC.Semantics.KripkeConcreteGluedHilbert where\n\nopen import BasicIPC.Syntax.Common public\nopen import Common.Semantics public\n\nopen ConcreteWorlds (Ty) public\n\n\n-- Partial intuitionistic Kripke models with explicit syntax.\n\nrecord Model : Set₁ where\n infix 3 _⊩ᵅ_ _[⊢]_\n field\n -- Forcing for atomic propositions; monotonic.\n _⊩ᵅ_ : World → Atom → Set\n mono⊩ᵅ : ∀ {P w w′} → w ≤ w′ → w ⊩ᵅ P → w′ ⊩ᵅ P\n\n -- Hilbert-style syntax representation; monotonic.\n _[⊢]_ : Cx 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 [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: [lam] is necessary to give meaning to Gentzen-style syntax.\n [lam] : ∀ {A B Γ} → Γ , A [⊢] B → Γ [⊢] A ▻ B\n\n infix 3 _[⊢]⋆_\n _[⊢]⋆_ : Cx Ty → Cx Ty → Set\n Γ [⊢]⋆ ∅ = 𝟙\n Γ [⊢]⋆ Ξ , A = Γ [⊢]⋆ Ξ × Γ [⊢] A\n\nopen Model {{…}} public\n\n\n-- Forcing in a particular world of a particular model.\n\nmodule _ {{_ : Model}} where\n infix 3 _⊩_\n _⊩_ : World → Ty → Set\n w ⊩ α P = Glue (unwrap w [⊢] α P) (w ⊩ᵅ P)\n w ⊩ A ▻ B = Glue (unwrap w [⊢] (A ▻ B)) (∀ {w′} → w ≤ w′ → w′ ⊩ A → w′ ⊩ B)\n w ⊩ A ∧ B = w ⊩ A × w ⊩ B\n w ⊩ ⊤ = 𝟙\n\n infix 3 _⊩⋆_\n _⊩⋆_ : World → Cx Ty → Set\n w ⊩⋆ ∅ = 𝟙\n w ⊩⋆ Ξ , A = w ⊩⋆ Ξ × w ⊩ A\n\n\n-- Monotonicity with respect to context inclusion.\n\nmodule _ {{_ : Model}} where\n mono⊩ : ∀ {A w w′} → w ≤ w′ → w ⊩ A → w′ ⊩ A\n mono⊩ {α P} ξ s = mono[⊢] (unwrap≤ ξ) (syn s) ⅋ mono⊩ᵅ ξ (sem s)\n mono⊩ {A ▻ B} ξ s = mono[⊢] (unwrap≤ ξ) (syn s) ⅋ λ ξ′ → sem s (trans≤ ξ ξ′)\n mono⊩ {A ∧ B} ξ s = mono⊩ {A} ξ (π₁ s) , mono⊩ {B} ξ (π₂ s)\n mono⊩ {⊤} ξ s = ∙\n\n mono⊩⋆ : ∀ {Ξ w w′} → w ≤ w′ → w ⊩⋆ Ξ → w′ ⊩⋆ Ξ\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 w} → w ⊩ A → unwrap w [⊢] A\n reifyʳ {α P} s = syn s\n reifyʳ {A ▻ B} s = syn s\n reifyʳ {A ∧ B} s = [app] ([app] [cpair] (reifyʳ {A} (π₁ s))) (reifyʳ {B} (π₂ s))\n reifyʳ {⊤} s = [unit]\n\n reifyʳ⋆ : ∀ {Ξ w} → w ⊩⋆ Ξ → unwrap w [⊢]⋆ Ξ\n reifyʳ⋆ {∅} ∙ = ∙\n reifyʳ⋆ {Ξ , A} (ts , t) = reifyʳ⋆ ts , reifyʳ t\n\n\n-- Useful theorems in functional form.\n\nmodule _ {{_ : Model}} where\n [multicut] : ∀ {Ξ A Γ} → Γ [⊢]⋆ Ξ → Ξ [⊢] A → Γ [⊢] A\n [multicut] {∅} ∙ u = mono[⊢] bot⊆ u\n [multicut] {Ξ , B} (ts , t) u = [app] ([multicut] ts ([lam] u)) t\n\n [pair] : ∀ {A B Γ} → Γ [⊢] A → Γ [⊢] B → Γ [⊢] A ∧ B\n [pair] t u = [app] ([app] [cpair] t) u\n\n [fst] : ∀ {A B Γ} → Γ [⊢] A ∧ B → Γ [⊢] A\n [fst] t = [app] [cfst] t\n\n [snd] : ∀ {A B Γ} → Γ [⊢] A ∧ B → Γ [⊢] B\n [snd] t = [app] [csnd] t\n\n\n-- Additional useful equipment.\n\nmodule _ {{_ : Model}} where\n _⟪$⟫_ : ∀ {A B w} → w ⊩ A ▻ B → w ⊩ A → w ⊩ B\n s ⟪$⟫ a = sem s refl≤ a\n\n ⟪K⟫ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A\n ⟪K⟫ {A} a = [app] [ck] (reifyʳ a) ⅋ λ ξ →\n K (mono⊩ {A} ξ a)\n\n ⟪S⟫ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ A ▻ B → w ⊩ A → w ⊩ C\n ⟪S⟫ s₁ s₂ a = (s₁ ⟪$⟫ a) ⟪$⟫ (s₂ ⟪$⟫ a)\n\n ⟪S⟫′ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ (A ▻ B) ▻ A ▻ C\n ⟪S⟫′ {A} {B} {C} s₁ = [app] [cs] (syn s₁) ⅋ λ ξ s₂ →\n [app] ([app] [cs] (mono[⊢] (unwrap≤ ξ) (syn s₁))) (syn s₂) ⅋ λ ξ′ →\n ⟪S⟫ (mono⊩ {A ▻ B ▻ C} (trans≤ ξ ξ′) s₁) (mono⊩ {A ▻ B} ξ′ s₂)\n\n _⟪,⟫′_ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A ∧ B\n _⟪,⟫′_ {A} a = [app] [cpair] (reifyʳ a) ⅋ λ ξ →\n _,_ (mono⊩ {A} ξ a)\n\n\n-- Forcing in a particular world of a particular model, for sequents.\n\nmodule _ {{_ : Model}} where\n infix 3 _⊩_⇒_\n _⊩_⇒_ : World → Cx Ty → Ty → Set\n w ⊩ Γ ⇒ A = w ⊩⋆ Γ → w ⊩ A\n\n infix 3 _⊩_⇒⋆_\n _⊩_⇒⋆_ : World → Cx Ty → Cx Ty → Set\n w ⊩ Γ ⇒⋆ Ξ = w ⊩⋆ Γ → w ⊩⋆ Ξ\n\n\n-- Entailment, or forcing in all worlds of all models, for sequents.\n\ninfix 3 _⊨_\n_⊨_ : Cx Ty → Ty → Set₁\nΓ ⊨ A = ∀ {{_ : Model}} {w : World} → w ⊩ Γ ⇒ A\n\ninfix 3 _⊨⋆_\n_⊨⋆_ : Cx Ty → Cx Ty → Set₁\nΓ ⊨⋆ Ξ = ∀ {{_ : Model}} {w : World} → w ⊩ Γ ⇒⋆ Ξ\n\n\n-- Additional useful equipment, for sequents.\n\nmodule _ {{_ : Model}} where\n lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩ Γ ⇒ A\n lookup top (γ , a) = a\n lookup (pop i) (γ , b) = lookup i γ\n\n _⟦$⟧_ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ▻ B → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B\n (s₁ ⟦$⟧ s₂) γ = s₁ γ ⟪$⟫ s₂ γ\n\n ⟦K⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B ▻ A\n ⟦K⟧ {A} {B} a γ = ⟪K⟫ {A} {B} (a γ)\n\n ⟦S⟧ : ∀ {A B C Γ w} → w ⊩ Γ ⇒ A ▻ B ▻ C → w ⊩ Γ ⇒ A ▻ B → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ C\n ⟦S⟧ s₁ s₂ a γ = ⟪S⟫ (s₁ γ) (s₂ γ) (a γ)\n\n _⟦,⟧_ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A → w ⊩ Γ ⇒ B → w ⊩ Γ ⇒ A ∧ B\n (a ⟦,⟧ b) γ = a γ , b γ\n\n ⟦π₁⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ∧ B → w ⊩ Γ ⇒ A\n ⟦π₁⟧ s γ = π₁ (s γ)\n\n ⟦π₂⟧ : ∀ {A B Γ w} → w ⊩ Γ ⇒ A ∧ B → w ⊩ Γ ⇒ B\n ⟦π₂⟧ s γ = π₂ (s γ)\n", "meta": {"hexsha": "fc00fa545979712d2d7479ca459e53c119de023f", "size": 5283, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "BasicIPC/Semantics/KripkeConcreteGluedHilbert.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": "BasicIPC/Semantics/KripkeConcreteGluedHilbert.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": "BasicIPC/Semantics/KripkeConcreteGluedHilbert.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": 29.8474576271, "max_line_length": 93, "alphanum_fraction": 0.4285443877, "num_tokens": 2925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6619228625116081, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.3541938836019901}} {"text": "open import Nat\nopen import Prelude\nopen import core\n\nmodule judgemental-inconsistency where\n data incon : τ̇ → τ̇ → Set where\n ICNumArr1 : {t1 t2 : τ̇} → incon num (t1 ==> t2)\n ICNumArr2 : {t1 t2 : τ̇} → incon (t1 ==> t2) num\n ICArr1 : {t1 t2 t3 t4 : τ̇} →\n incon t1 t3 →\n incon (t1 ==> t2) (t3 ==> t4)\n ICArr2 : {t1 t2 t3 t4 : τ̇} →\n incon t2 t4 →\n incon (t1 ==> t2) (t3 ==> t4)\n\n -- inconsistency is symmetric\n inconsym : ∀ {t1 t2} → incon t1 t2 → incon t2 t1\n inconsym ICNumArr1 = ICNumArr2\n inconsym ICNumArr2 = ICNumArr1\n inconsym (ICArr1 x) = ICArr1 (inconsym x)\n inconsym (ICArr2 x) = ICArr2 (inconsym x)\n\n --inconsistency isn't reflexive\n incon-nrefl : ∀{t} → incon t t → ⊥\n incon-nrefl (ICArr1 x) = incon-nrefl x\n incon-nrefl (ICArr2 x) = incon-nrefl x\n\n -- first half of iso\n to~̸ : (t1 t2 : τ̇) → incon t1 t2 → t1 ~̸ t2\n to~̸ .num ._ ICNumArr1 ()\n to~̸ ._ .num ICNumArr2 ()\n to~̸ ._ ._ (ICArr1 incon) TCRefl = abort (incon-nrefl incon)\n to~̸ ._ ._ (ICArr1 incon) (TCArr x x₁) = to~̸ _ _ incon x\n to~̸ ._ ._ (ICArr2 incon) TCRefl = abort (incon-nrefl incon)\n to~̸ ._ ._ (ICArr2 incon) (TCArr x x₁) = (to~̸ _ _ incon x₁)\n\n -- second half of iso\n from~̸ : (t1 t2 : τ̇) → t1 ~̸ t2 → incon t1 t2\n from~̸ num (t2 ==> t3) ncon = ICNumArr1\n from~̸ (t1 ==> t2) num ncon = ICNumArr2\n from~̸ (t1 ==> t2) (t3 ==> t4) ncon with ~dec t1 t3\n ... | Inl qq = ICArr2 (from~̸ t2 t4 (λ x → ncon (TCArr qq x)))\n ... | Inr qq = ICArr1 (from~̸ _ _ qq)\n -- the remaining consistent types all lead to absurdities\n from~̸ num num ncon = abort (ncon TCRefl)\n from~̸ num ⦇-⦈ ncon = abort (ncon TCHole1)\n from~̸ ⦇-⦈ num ncon = abort (ncon TCHole2)\n from~̸ ⦇-⦈ ⦇-⦈ ncon = abort (ncon TCRefl)\n from~̸ ⦇-⦈ (t2 ==> t3) ncon = abort (ncon TCHole2)\n from~̸ (t1 ==> t2) ⦇-⦈ ncon = abort (ncon TCHole1)\n\n -- need to display that at least one of the round-trips above is stable\n -- for this to be structure preserving and really an iso.\n rt1 : (t1 t2 : τ̇) → (x : t1 ~̸ t2) → (to~̸ t1 t2 (from~̸ t1 t2 x)) == x\n rt1 num (t2 ==> t3) x = funext (λ x₁ → abort (x x₁))\n rt1 (t1 ==> t2) num x = funext (λ x₁ → abort (x x₁))\n rt1 (t1 ==> t2) (t3 ==> t4) x = funext (λ x₁ → abort (x x₁))\n rt1 num num x = abort (x TCRefl)\n rt1 num ⦇-⦈ x = abort (x TCHole1)\n rt1 ⦇-⦈ num x = abort (x TCHole2)\n rt1 ⦇-⦈ ⦇-⦈ x = abort (x TCRefl)\n rt1 ⦇-⦈ (t2 ==> t3) x = abort (x TCHole2)\n rt1 (t1 ==> t2) ⦇-⦈ x = abort (x TCHole1)\n\n -- if inconsistency at arrows is proof-irrelevant, then all of\n -- inconsistency is proof-irrelevant\n incon-irrelev : (arr-incon-irrelev : {t1 t2 t3 t4 : τ̇} (x y : incon (t1 ==> t2) (t3 ==> t4)) → x == y) →\n (t1 t2 : τ̇) (x y : incon t1 t2) → x == y\n incon-irrelev arr-incon-irrelev .num _ ICNumArr1 ICNumArr1 = refl\n incon-irrelev arr-incon-irrelev _ .num ICNumArr2 ICNumArr2 = refl\n incon-irrelev arr-incon-irrelev _ _ (ICArr1 x) (ICArr1 y) = ap1 ICArr1 (incon-irrelev arr-incon-irrelev _ _ x y)\n incon-irrelev arr-incon-irrelev _ _ (ICArr1 x) (ICArr2 y) = arr-incon-irrelev (ICArr1 x) (ICArr2 y)\n incon-irrelev arr-incon-irrelev _ _ (ICArr2 x) (ICArr1 y) = arr-incon-irrelev (ICArr2 x) (ICArr1 y)\n incon-irrelev arr-incon-irrelev _ _ (ICArr2 x) (ICArr2 y) = ap1 ICArr2 (incon-irrelev arr-incon-irrelev _ _ x y )\n\n -- if inconsistency at arrows is proof-irrelevant, then the round trip is\n -- stable up to equality\n rt2 : (arr-incon-irrelev : {t1 t2 t3 t4 : τ̇} (x y : incon (t1 ==> t2) (t3 ==> t4)) → x == y) →\n (t1 t2 : τ̇) → (x : incon t1 t2) → (from~̸ t1 t2 (to~̸ t1 t2 x)) == x\n rt2 arr-incon-irrelev .num _ ICNumArr1 = refl\n rt2 arr-incon-irrelev _ .num ICNumArr2 = refl\n rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr1 x) with ~dec t1 t3\n rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr1 x₁) | Inl x = abort (to~̸ t1 t3 x₁ x)\n rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr1 x₁) | Inr x = ap1 ICArr1 (incon-irrelev arr-incon-irrelev t1 t3 (from~̸ t1 t3 x) x₁)\n rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr2 x) with ~dec t1 t3\n rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr2 x₁) | Inl x = ap1 ICArr2 (incon-irrelev arr-incon-irrelev t2 t4 (from~̸ t2 t4 (to~̸ t2 t4 x₁)) x₁)\n rt2 arr-incon-irrelev (t1 ==> t2) (t3 ==> t4) (ICArr2 x₁) | Inr x = arr-incon-irrelev (ICArr1 (from~̸ t1 t3 x)) (ICArr2 x₁)\n\n -- if inconsistency at arrows is proof-irrelevant, then the two\n -- defintions of inconsistency are isomorphic\n incon-iso : (arr-incon-irrelev : {t1 t2 t3 t4 : τ̇} (x y : incon (t1 ==> t2) (t3 ==> t4)) → x == y)\n → (t1 t2 : τ̇) → (incon t1 t2) ≃ (t1 ~̸ t2)\n incon-iso arr-incon-irrelev t1 t2 = (to~̸ t1 t2) , (from~̸ t1 t2) , (rt2 arr-incon-irrelev t1 t2) , (rt1 t1 t2)\n", "meta": {"hexsha": "ba4b6c5221a88d0dae69a700aa1fd4621b2014a8", "size": 4888, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "judgemental-inconsistency.agda", "max_stars_repo_name": "hazelgrove/agda-popl17", "max_stars_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-07-01T22:44:11.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-11T12:30:50.000Z", "max_issues_repo_path": "judgemental-inconsistency.agda", "max_issues_repo_name": "hazelgrove/agda-popl17", "max_issues_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2016-07-07T16:23:11.000Z", "max_issues_repo_issues_event_max_datetime": "2016-11-09T18:13:55.000Z", "max_forks_repo_path": "judgemental-inconsistency.agda", "max_forks_repo_name": "hazelgrove/agda-popl17", "max_forks_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-03T03:45:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-03T03:45:07.000Z", "avg_line_length": 52.0, "max_line_length": 154, "alphanum_fraction": 0.5773322422, "num_tokens": 2209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.3541887794920539}} {"text": "------------------------------------------------------------------------\n-- A coinductive definition of weak similarity\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nopen import Labelled-transition-system\n\nmodule Similarity.Weak {ℓ} (lts : LTS ℓ) where\n\nopen import Equality.Propositional\nopen import Prelude\nopen import Prelude.Size\n\nopen import Bisimilarity.Weak lts as WB using ([_]_≈_; [_]_≈′_)\nopen import Expansion lts as E using ([_]_≳_; [_]_≳′_)\nopen import Indexed-container hiding (⟨_⟩)\nopen import Relation\nopen import Similarity lts as S using ([_]_≤_; [_]_≤′_)\nimport Similarity.General\n\nopen LTS lts\n\nprivate\n module General = Similarity.General lts _[_]⇒̂_ ⟶→⇒̂\n\nopen General public\n using (module StepC; ⟨_⟩; challenge; force;\n [_]_≡_; [_]_≡′_; []≡↔; Extensionality; extensionality)\n renaming ( reflexive-≤ to reflexive-≼\n ; reflexive-≤′ to reflexive-≼′\n ; ≡⇒≤ to ≡⇒≼\n ; ≤:_ to ≼:_\n ; ≤′:_ to ≼′:_\n )\n\n-- StepC is given in the following way, rather than via open public,\n-- to make hyperlinks to it more informative.\n\nStepC : Container (Proc × Proc) (Proc × Proc)\nStepC = General.StepC\n\n-- The following definitions are given explicitly, in order to make\n-- the code easier to follow.\n\nWeak-similarity : Size → Rel₂ ℓ Proc\nWeak-similarity = ν StepC\n\nWeak-similarity′ : Size → Rel₂ ℓ Proc\nWeak-similarity′ = ν′ StepC\n\ninfix 4 [_]_≼_ [_]_≼′_ _≼_ _≼′_\n\n[_]_≼_ : Size → Proc → Proc → Type ℓ\n[ i ] p ≼ q = ν StepC i (p , q)\n\n[_]_≼′_ : Size → Proc → Proc → Type ℓ\n[ i ] p ≼′ q = ν′ StepC i (p , q)\n\n_≼_ : Proc → Proc → Type ℓ\n_≼_ = [ ∞ ]_≼_\n\n_≼′_ : Proc → Proc → Type ℓ\n_≼′_ = [ ∞ ]_≼′_\n\nprivate\n\n -- However, these definitions are definitionally equivalent to\n -- corresponding definitions in General.\n\n indirect-Weak-similarity : Weak-similarity ≡ General.Similarity\n indirect-Weak-similarity = refl\n\n indirect-Weak-similarity′ : Weak-similarity′ ≡ General.Similarity′\n indirect-Weak-similarity′ = refl\n\n indirect-[]≼ : [_]_≼_ ≡ General.[_]_≤_\n indirect-[]≼ = refl\n\n indirect-[]≼′ : [_]_≼′_ ≡ General.[_]_≤′_\n indirect-[]≼′ = refl\n\n indirect-≼ : _≼_ ≡ General._≤_\n indirect-≼ = refl\n\n indirect-≼′ : _≼′_ ≡ General._≤′_\n indirect-≼′ = refl\n\nmutual\n\n -- Weak bisimilarity is contained in weak similarity.\n\n ≈⇒≼ : ∀ {i p q} → [ i ] p ≈ q → [ i ] p ≼ q\n ≈⇒≼ = λ p≈q →\n ⟨ (λ q⟶q′ →\n let p′ , p⇒̂p′ , p′≈′q′ = WB.left-to-right p≈q q⟶q′\n in p′ , p⇒̂p′ , ≈⇒≼′ p′≈′q′)\n ⟩\n\n ≈⇒≼′ : ∀ {i p q} → [ i ] p ≈′ q → [ i ] p ≼′ q\n force (≈⇒≼′ p≳′q) = ≈⇒≼ (S.force p≳′q)\n\nmutual\n\n -- Similarity is contained in weak similarity.\n\n ≤⇒≼ : ∀ {i p q} → [ i ] p ≤ q → [ i ] p ≼ q\n ≤⇒≼ = λ p≤q →\n ⟨ (λ q⟶q′ →\n let p′ , p⟶p′ , p′≤′q′ = S.challenge p≤q q⟶q′\n in p′ , ⟶→⇒̂ p⟶p′ , ≤⇒≼′ p′≤′q′)\n ⟩\n\n ≤⇒≼′ : ∀ {i p q} → [ i ] p ≤′ q → [ i ] p ≼′ q\n force (≤⇒≼′ p≳′q) = ≤⇒≼ (S.force p≳′q)\n\n-- Weak similarity is a weak simulation (of a certain kind).\n\nweak-is-weak⇒̂ :\n ∀ {p p′ q μ} →\n p ≼ q → p [ μ ]⇒̂ p′ →\n ∃ λ q′ → q [ μ ]⇒̂ q′ × p′ ≼ q′\nweak-is-weak⇒̂ = is-weak⇒̂ challenge (λ p≼′q → force p≼′q) ⇒̂→⇒ id\n\nmutual\n\n -- Weak similarity is transitive.\n --\n -- Note that the size of the second argument is not preserved.\n --\n -- TODO: Can one prove that the size cannot be preserved?\n\n transitive-≼ : ∀ {i p q r} → [ i ] p ≼ q → q ≼ r → [ i ] p ≼ r\n transitive-≼ p≼q q≼r =\n ⟨ (λ p⟶p′ →\n let q′ , q⇒̂q′ , p′≼q′ = challenge p≼q p⟶p′\n r′ , r⇒̂r′ , q′≼r′ = weak-is-weak⇒̂ q≼r q⇒̂q′\n in r′ , r⇒̂r′ , transitive-≼′ p′≼q′ q′≼r′)\n ⟩\n\n transitive-≼′ :\n ∀ {i p q r} → [ i ] p ≼′ q → q ≼ r → [ i ] p ≼′ r\n force (transitive-≼′ p≼q q≼r) = transitive-≼ (force p≼q) q≼r\n\nmutual\n\n -- A fully size-preserving transitivity-like lemma.\n --\n -- Note that expansion could be replaced by a kind of one-sided\n -- expansion.\n\n transitive-≳≼ : ∀ {i p q r} → [ i ] p ≳ q → [ i ] q ≼ r → [ i ] p ≼ r\n transitive-≳≼ p≳q q≼r =\n ⟨ (λ p⟶p′ → case E.left-to-right p≳q p⟶p′ of λ where\n (_ , done s , p′≳q) →\n _ , silent s done\n , transitive-≳≼′\n p′≳q (record { force = λ { {_} → q≼r } })\n\n (q′ , step q⟶q′ , p′≳q′) →\n let r′ , r⇒̂r′ , q′≼r′ = challenge q≼r q⟶q′\n in r′ , r⇒̂r′ , transitive-≳≼′ p′≳q′ q′≼r′)\n ⟩\n\n transitive-≳≼′ :\n ∀ {i p q r} → [ i ] p ≳′ q → [ i ] q ≼′ r → [ i ] p ≼′ r\n force (transitive-≳≼′ p≼q q≼r) =\n transitive-≳≼ (force p≼q) (force q≼r)\n", "meta": {"hexsha": "1a746bd12b5fa645db3f6bf9770d2510e65a7105", "size": 4601, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Similarity/Weak.agda", "max_stars_repo_name": "nad/up-to", "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Similarity/Weak.agda", "max_issues_repo_name": "nad/up-to", "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Similarity/Weak.agda", "max_forks_repo_name": "nad/up-to", "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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": 27.224852071, "max_line_length": 72, "alphanum_fraction": 0.5061943056, "num_tokens": 1959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982315512489, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.3541760079772308}} {"text": "{-# OPTIONS --without-K --exact-split --safe #-}\n\nmodule Fragment.Extensions.CSemigroup.Monomial where\n\nopen import Fragment.Equational.Theory.Bundles\n\nopen import Fragment.Algebra.Signature\nopen import Fragment.Algebra.Free Σ-magma hiding (_~_)\nopen import Fragment.Algebra.Homomorphism Σ-magma\nopen import Fragment.Algebra.Algebra Σ-magma\n using (Algebra; IsAlgebra; Interpretation; Congruence)\nopen import Fragment.Equational.Model Θ-csemigroup\n\nopen import Fragment.Setoid.Morphism using (_↝_)\n\nopen import Fragment.Extensions.CSemigroup.Nat\n\nopen import Data.Nat using (ℕ; zero; suc; _≟_)\nopen import Data.Fin using (Fin; #_; zero; suc; toℕ; fromℕ)\nopen import Data.Vec using (Vec; []; _∷_)\nopen import Data.Vec.Relation.Binary.Pointwise.Inductive using ([]; _∷_)\n\nopen import Relation.Nullary using (yes ; no)\nopen import Relation.Binary.PropositionalEquality as PE using (_≡_)\nopen import Relation.Binary using (Setoid; IsEquivalence)\nimport Relation.Binary.Reasoning.Setoid as Reasoning\n\ndata Monomial : ℕ → Set where\n leaf : ∀ {n} → ℕ⁺ → Monomial (suc n)\n skip : ∀ {n} → Monomial n → Monomial (suc n)\n cons : ∀ {n} → ℕ⁺ → Monomial n → Monomial (suc n)\n\nlift : ∀ {n} → Monomial n → Monomial (suc n)\nlift (leaf x) = leaf x\nlift (skip x) = skip (lift x)\nlift (cons x xs) = cons x (lift xs)\n\n_⊗_ : ∀ {n} → Monomial n → Monomial n → Monomial n\nleaf x ⊗ leaf y = leaf (x + y)\nleaf x ⊗ skip y = cons x y\nleaf x ⊗ cons y ys = cons (x + y) ys\nskip x ⊗ leaf y = cons y x\nskip x ⊗ skip y = skip (x ⊗ y)\nskip x ⊗ cons y ys = cons y (x ⊗ ys)\ncons x xs ⊗ leaf y = cons (x + y) xs\ncons x xs ⊗ skip y = cons x (xs ⊗ y)\ncons x xs ⊗ cons y ys = cons (x + y) (xs ⊗ ys)\n\n⊗-cong : ∀ {n} {x y z w : Monomial n}\n → x ≡ y → z ≡ w → x ⊗ z ≡ y ⊗ w\n⊗-cong = PE.cong₂ _⊗_\n\n⊗-comm : ∀ {n} (x y : Monomial n) → x ⊗ y ≡ y ⊗ x\n⊗-comm (leaf x) (leaf y) = PE.cong leaf (+-comm x y)\n⊗-comm (leaf x) (skip y) = PE.refl\n⊗-comm (leaf x) (cons y ys) = PE.cong₂ cons (+-comm x y) PE.refl\n⊗-comm (skip x) (leaf y) = PE.refl\n⊗-comm (skip x) (skip y) = PE.cong skip (⊗-comm x y)\n⊗-comm (skip x) (cons y ys) = PE.cong (cons y) (⊗-comm x ys)\n⊗-comm (cons x xs) (leaf y) = PE.cong₂ cons (+-comm x y) PE.refl\n⊗-comm (cons x xs) (skip y) = PE.cong (cons x) (⊗-comm xs y)\n⊗-comm (cons x xs) (cons y ys) = PE.cong₂ cons (+-comm x y) (⊗-comm xs ys)\n\n⊗-assoc : ∀ {n} (x y z : Monomial n) → (x ⊗ y) ⊗ z ≡ x ⊗ (y ⊗ z)\n⊗-assoc (leaf x) (leaf y) (leaf z) = PE.cong leaf (+-assoc x y z)\n⊗-assoc (leaf x) (leaf y) (skip z) = PE.refl\n⊗-assoc (leaf x) (leaf y) (cons z zs) = PE.cong₂ cons (+-assoc x y z) PE.refl\n⊗-assoc (leaf x) (skip y) (leaf z) = PE.refl\n⊗-assoc (leaf x) (skip y) (skip z) = PE.refl\n⊗-assoc (leaf x) (skip y) (cons z zs) = PE.refl\n⊗-assoc (leaf x) (cons y ys) (leaf z) = PE.cong₂ cons (+-assoc x y z) PE.refl\n⊗-assoc (leaf x) (cons y ys) (skip z) = PE.refl\n⊗-assoc (leaf x) (cons y ys) (cons z zs) = PE.cong₂ cons (+-assoc x y z) PE.refl\n⊗-assoc (skip x) (leaf y) (leaf z) = PE.refl\n⊗-assoc (skip x) (leaf y) (skip z) = PE.refl\n⊗-assoc (skip x) (leaf y) (cons z zs) = PE.refl\n⊗-assoc (skip x) (skip y) (leaf z) = PE.refl\n⊗-assoc (skip x) (skip y) (skip z) = PE.cong skip (⊗-assoc x y z)\n⊗-assoc (skip x) (skip y) (cons z zs) = PE.cong (cons z) (⊗-assoc x y zs)\n⊗-assoc (skip x) (cons y ys) (leaf z) = PE.refl\n⊗-assoc (skip x) (cons y ys) (skip z) = PE.cong (cons y) (⊗-assoc x ys z)\n⊗-assoc (skip x) (cons y ys) (cons z zs) = PE.cong (cons (y + z)) (⊗-assoc x ys zs)\n⊗-assoc (cons x xs) (leaf y) (leaf z) = PE.cong₂ cons (+-assoc x y z) PE.refl\n⊗-assoc (cons x xs) (leaf y) (skip z) = PE.refl\n⊗-assoc (cons x xs) (leaf y) (cons z zs) = PE.cong₂ cons (+-assoc x y z) PE.refl\n⊗-assoc (cons x xs) (skip y) (leaf z) = PE.refl\n⊗-assoc (cons x xs) (skip y) (skip z) = PE.cong (cons x) (⊗-assoc xs y z)\n⊗-assoc (cons x xs) (skip y) (cons z zs) = PE.cong (cons (x + z)) (⊗-assoc xs y zs)\n⊗-assoc (cons x xs) (cons y ys) (leaf z) = PE.cong₂ cons (+-assoc x y z) PE.refl\n⊗-assoc (cons x xs) (cons y ys) (skip z) = PE.cong (cons (x + y)) (⊗-assoc xs ys z)\n⊗-assoc (cons x xs) (cons y ys) (cons z zs) = PE.cong₂ cons (+-assoc x y z) (⊗-assoc xs ys zs)\n\nmodule _ (n : ℕ) where\n\n private\n\n Monomial/≡ : Setoid _ _\n Monomial/≡ = PE.setoid (Monomial n)\n\n Monomial⟦_⟧ : Interpretation Monomial/≡\n Monomial⟦ • ⟧ (x ∷ y ∷ []) = x ⊗ y\n\n Monomial⟦_⟧-cong : Congruence Monomial/≡ Monomial⟦_⟧\n Monomial⟦ • ⟧-cong (p ∷ q ∷ []) = PE.cong₂ _⊗_ p q\n\n Monomial/≡-isAlgebra : IsAlgebra (Monomial/≡)\n Monomial/≡-isAlgebra = record { ⟦_⟧ = Monomial⟦_⟧\n ; ⟦⟧-cong = Monomial⟦_⟧-cong\n }\n\n Monomial/≡-algebra : Algebra\n Monomial/≡-algebra =\n record { ∥_∥/≈ = Monomial/≡\n ; ∥_∥/≈-isAlgebra = Monomial/≡-isAlgebra\n }\n\n Monomial/≡-models : Models Monomial/≡-algebra\n Monomial/≡-models comm θ = ⊗-comm (θ (# 0)) (θ (# 1))\n Monomial/≡-models assoc θ = ⊗-assoc (θ (# 0)) (θ (# 1)) (θ (# 2))\n\n Monomial/≡-isModel : IsModel Monomial/≡\n Monomial/≡-isModel =\n record { isAlgebra = Monomial/≡-isAlgebra\n ; models = Monomial/≡-models\n }\n\n J' : Model\n J' = record { ∥_∥/≈ = Monomial/≡\n ; isModel = Monomial/≡-isModel\n }\n\nprivate\n\n module _ {n : ℕ} where\n\n open Setoid ∥ J n ∥/≈ using (_≈_)\n\n _·_ : ∥ J n ∥ → ∥ J n ∥ → ∥ J n ∥\n x · y = term • (x ∷ y ∷ [])\n\n ·-cong : ∀ {x y z w} → x ≈ y → z ≈ w → x · z ≈ y · w\n ·-cong p q = cong • (p ∷ q ∷ [])\n\n ·-comm : ∀ x y → x · y ≈ y · x\n ·-comm x y = axiom comm (env {A = ∥ J n ∥ₐ} (x ∷ y ∷ []))\n\n ·-assoc : ∀ x y z → (x · y) · z ≈ x · (y · z)\n ·-assoc x y z = axiom assoc (env {A = ∥ J n ∥ₐ} (x ∷ y ∷ z ∷ []))\n\n module _ (n : ℕ) where\n\n open Setoid ∥ J (suc n) ∥/≈ using (_≈_)\n\n exp : ℕ⁺ → ∥ J (suc n) ∥\n exp one = atomise n\n exp (suc k) = atomise n · exp k\n\n exp-hom : ∀ {j k} → exp j · exp k ≈ exp (j + k)\n exp-hom {one} {k} = refl\n exp-hom {suc j} {k} = begin\n (atomise n · exp j) · exp k\n ≈⟨ ·-assoc (atomise n) (exp j) (exp k) ⟩\n atomise n · (exp j · exp k)\n ≈⟨ ·-cong refl exp-hom ⟩\n atomise n · exp (j + k)\n ∎\n where open Reasoning ∥ J (suc n) ∥/≈\n\n ∣syn∣ : ∀ {n} → ∥ J' n ∥ → ∥ J n ∥\n ∣syn∣ {suc n} (leaf k) = exp n k\n ∣syn∣ {suc n} (skip x) = ∣ raise ∣ (∣syn∣ x)\n ∣syn∣ {suc n} (cons k xs) = exp n k · ∣ raise ∣ (∣syn∣ xs)\n\n ∣syn∣-cong : ∀ {n} → Congruent _≡_ ≈[ J n ] ∣syn∣\n ∣syn∣-cong {n} p = Setoid.reflexive ∥ J n ∥/≈ (PE.cong ∣syn∣ p)\n\n ∣syn∣⃗ : ∀ {n} → ∥ J' n ∥/≈ ↝ ∥ J n ∥/≈\n ∣syn∣⃗ {n} = record { ∣_∣ = ∣syn∣ {n}\n ; ∣_∣-cong = ∣syn∣-cong {n}\n }\n\n ∣syn∣-hom : ∀ {n} → Homomorphic ∥ J' n ∥ₐ ∥ J n ∥ₐ ∣syn∣\n ∣syn∣-hom {suc n} • (leaf x ∷ leaf y ∷ []) = exp-hom n\n ∣syn∣-hom {suc n} • (leaf x ∷ skip y ∷ []) = refl\n ∣syn∣-hom {suc n} • (leaf x ∷ cons y ys ∷ []) = begin\n exp n x · (exp n y · ∣ raise ∣ (∣syn∣ ys))\n ≈⟨ sym (·-assoc (exp n x) (exp n y) _) ⟩\n (exp n x · exp n y) · ∣ raise ∣ (∣syn∣ ys)\n ≈⟨ ·-cong (exp-hom n) refl ⟩\n exp n (x + y) · ∣ raise ∣ (∣syn∣ ys)\n ∎\n where open Reasoning ∥ J (suc n) ∥/≈\n ∣syn∣-hom {suc n} • (skip x ∷ leaf y ∷ []) = ·-comm _ (exp n y)\n ∣syn∣-hom {suc n} • (skip x ∷ skip y ∷ []) = begin\n ∣ raise ∣ (∣syn∣ x) · ∣ raise ∣ (∣syn∣ y)\n ≈⟨ ∣ raise ∣-hom • (∣syn∣ x ∷ ∣syn∣ y ∷ []) ⟩\n ∣ raise ∣ (∣syn∣ x · ∣syn∣ y)\n ≈⟨ ∣ raise ∣-cong (∣syn∣-hom • (x ∷ y ∷ [])) ⟩\n ∣ raise ∣ (∣syn∣ (x ⊗ y))\n ∎\n where open Reasoning ∥ J (suc n) ∥/≈\n ∣syn∣-hom {suc n} • (skip x ∷ cons y ys ∷ []) = begin\n ∣ raise ∣ (∣syn∣ x) · (exp n y · ∣ raise ∣ (∣syn∣ ys))\n ≈⟨ sym (·-assoc _ (exp n y) _) ⟩\n (∣ raise ∣ (∣syn∣ x) · exp n y) · ∣ raise ∣ (∣syn∣ ys)\n ≈⟨ ·-cong (·-comm _ (exp n y)) refl ⟩\n (exp n y · ∣ raise ∣ (∣syn∣ x)) · ∣ raise ∣ (∣syn∣ ys)\n ≈⟨ ·-assoc (exp n y) _ _ ⟩\n exp n y · (∣ raise ∣ (∣syn∣ x) · ∣ raise ∣ (∣syn∣ ys))\n ≈⟨ ·-cong refl (∣ raise ∣-hom • (∣syn∣ x ∷ ∣syn∣ ys ∷ [])) ⟩\n exp n y · ∣ raise ∣ (∣syn∣ x · ∣syn∣ ys)\n ≈⟨ ·-cong refl (∣ raise ∣-cong (∣syn∣-hom • (x ∷ ys ∷ []))) ⟩\n exp n y · ∣ raise ∣ (∣syn∣ (x ⊗ ys))\n ∎\n where open Reasoning ∥ J (suc n) ∥/≈\n ∣syn∣-hom {suc n} • (cons x xs ∷ leaf y ∷ []) = begin\n (exp n x · ∣ raise ∣ (∣syn∣ xs)) · exp n y\n ≈⟨ ·-assoc (exp n x) _ (exp n y) ⟩\n exp n x · (∣ raise ∣ (∣syn∣ xs) · exp n y)\n ≈⟨ ·-cong refl (·-comm _ (exp n y)) ⟩\n exp n x · (exp n y · ∣ raise ∣ (∣syn∣ xs))\n ≈⟨ sym (·-assoc (exp n x) (exp n y) _) ⟩\n (exp n x · exp n y) · ∣ raise ∣ (∣syn∣ xs)\n ≈⟨ ·-cong (exp-hom n) refl ⟩\n exp n (x + y) · ∣ raise ∣ (∣syn∣ xs)\n ∎\n where open Reasoning ∥ J (suc n) ∥/≈\n ∣syn∣-hom {suc n} • (cons x xs ∷ skip y ∷ []) = begin\n (exp n x · ∣ raise ∣ (∣syn∣ xs)) · ∣ raise ∣ (∣syn∣ y)\n ≈⟨ ·-assoc (exp n x) _ _ ⟩\n exp n x · (∣ raise ∣ (∣syn∣ xs) · ∣ raise ∣ (∣syn∣ y))\n ≈⟨ ·-cong refl (∣ raise ∣-hom • (∣syn∣ xs ∷ ∣syn∣ y ∷ [])) ⟩\n exp n x · ∣ raise ∣ (∣syn∣ xs · ∣syn∣ y)\n ≈⟨ ·-cong refl (∣ raise ∣-cong (∣syn∣-hom • (xs ∷ y ∷ []))) ⟩\n exp n x · ∣ raise ∣ (∣syn∣ (xs ⊗ y))\n ∎\n where open Reasoning ∥ J (suc n) ∥/≈\n ∣syn∣-hom {suc n} • (cons x xs ∷ cons y ys ∷ []) = begin\n (exp n x · ∣ raise ∣ (∣syn∣ xs)) · (exp n y · ∣ raise ∣ (∣syn∣ ys))\n ≈⟨ ·-assoc (exp n x) _ _ ⟩\n exp n x · (∣ raise ∣ (∣syn∣ xs) · (exp n y · ∣ raise ∣ (∣syn∣ ys)))\n ≈⟨ ·-cong refl (sym (·-assoc _ (exp n y) _)) ⟩\n exp n x · ((∣ raise ∣ (∣syn∣ xs) · exp n y) · ∣ raise ∣ (∣syn∣ ys))\n ≈⟨ ·-cong refl (·-cong (·-comm (∣ raise ∣ (∣syn∣ xs)) _) refl) ⟩\n exp n x · ((exp n y · ∣ raise ∣ (∣syn∣ xs)) · ∣ raise ∣ (∣syn∣ ys))\n ≈⟨ ·-cong refl (·-assoc (exp n y) _ _) ⟩\n exp n x · (exp n y · (∣ raise ∣ (∣syn∣ xs) · ∣ raise ∣ (∣syn∣ ys)))\n ≈⟨ sym (·-assoc (exp n x) (exp n y) _) ⟩\n (exp n x · exp n y) · (∣ raise ∣ (∣syn∣ xs) · ∣ raise ∣ (∣syn∣ ys))\n ≈⟨ ·-cong (exp-hom n) (∣ raise ∣-hom • (∣syn∣ xs ∷ ∣syn∣ ys ∷ [])) ⟩\n exp n (x + y) · ∣ raise ∣ (∣syn∣ xs · ∣syn∣ ys)\n ≈⟨ ·-cong refl (∣ raise ∣-cong (∣syn∣-hom • (xs ∷ ys ∷ []))) ⟩\n exp n (x + y) · ∣ raise ∣ (∣syn∣ (xs ⊗ ys))\n ∎\n where open Reasoning ∥ J (suc n) ∥/≈\n\nsyn : ∀ {n} → ∥ J' n ∥ₐ ⟿ ∥ J n ∥ₐ\nsyn = record { ∣_∣⃗ = ∣syn∣⃗\n ; ∣_∣-hom = ∣syn∣-hom\n }\n\nprivate\n\n tab : ∀ {n} → Fin n → ∥ J' n ∥\n tab {suc zero} zero = leaf one\n tab {suc (suc n)} zero = skip (tab {suc n} zero)\n tab {suc (suc n)} (suc k) = lift (tab {suc n} k)\n\nnorm : ∀ {n} → ∥ J n ∥ₐ ⟿ ∥ J' n ∥ₐ\nnorm {n} = interp (J' n) tab\n\nprivate\n\n step-exp : ∀ {n} → (k : ℕ⁺)\n → ≈[ J (suc (suc n)) ] (exp (suc n) k)\n (∣ step ∣ (exp n k))\n step-exp one = refl\n step-exp (suc k) = ·-cong refl (step-exp k)\n\n step-lift : ∀ {n} → (x : ∥ J' n ∥)\n → ≈[ J (suc n) ] (∣ syn ∣ (lift x))\n (∣ step ∣ (∣ syn ∣ x))\n step-lift {suc n} (leaf x) = step-exp x\n step-lift {suc n} (skip x) = begin\n ∣ raise ∣ (∣ syn ∣ (lift x))\n ≈⟨ ∣ raise ∣-cong (step-lift x) ⟩\n ∣ raise ∣ (∣ step ∣ (∣ syn ∣ x))\n ≈⟨ sym (step-raise {x = ∣ syn ∣ x}) ⟩\n ∣ step ∣ (∣ raise ∣ (∣ syn ∣ x))\n ∎\n where open Reasoning ∥ J (suc (suc n)) ∥/≈\n step-lift {suc n} (cons x xs) = begin\n exp (suc n) x · ∣ raise ∣ (∣ syn ∣ (lift xs))\n ≈⟨ ·-cong refl (∣ raise ∣-cong (step-lift xs)) ⟩\n exp (suc n) x · ∣ raise ∣ (∣ step ∣ (∣ syn ∣ xs))\n ≈⟨ ·-cong (step-exp x) (sym (step-raise {x = ∣ syn ∣ xs})) ⟩\n ∣ step ∣ (exp n x) · ∣ step ∣ (∣ raise ∣ (∣ syn ∣ xs))\n ≈⟨ ∣ step ∣-hom • (exp n x ∷ (∣ raise ∣ (∣ syn ∣ xs)) ∷ []) ⟩\n ∣ step ∣ (exp n x · ∣ raise ∣ (∣ syn ∣ xs))\n ∎\n where open Reasoning ∥ J (suc (suc n)) ∥/≈\n\n syn-tab : ∀ {n} → (k : Fin n)\n → ≈[ J n ] (∣ syn ∣ (tab k)) (atom (dyn k))\n syn-tab {suc zero} zero = refl\n syn-tab {suc (suc n)} zero = ∣ raise ∣-cong (syn-tab zero)\n syn-tab {suc (suc n)} (suc k) = begin\n ∣ syn ∣ (lift (tab {suc n} k))\n ≈⟨ step-lift (tab {suc n} k) ⟩\n ∣ step ∣ (∣ syn ∣ (tab {suc n} k))\n ≈⟨ ∣ step ∣-cong (syn-tab k) ⟩\n ∣ step ∣ (atom (dyn k))\n ∎\n where open Reasoning ∥ J (suc (suc n)) ∥/≈\n\nsyn⊙norm≗id : ∀ {n} → syn {n} ⊙ norm {n} ≗ id\nsyn⊙norm≗id {n} {atom (dyn k)} = syn-tab k\nsyn⊙norm≗id {n} {term • (x ∷ y ∷ [])} = begin\n ∣ syn ∣ (∣ norm ∣ x ⊗ ∣ norm ∣ y)\n ≈⟨ sym (∣ syn ∣-hom • (∣ norm ∣ x ∷ ∣ norm ∣ y ∷ [])) ⟩\n ∣ syn ∣ (∣ norm ∣ x) · ∣ syn ∣ (∣ norm ∣ y)\n ≈⟨ ·-cong syn⊙norm≗id syn⊙norm≗id ⟩\n x · y\n ∎\n where open Reasoning ∥ J n ∥/≈\n\nprivate\n\n tab-diag : ∀ n → tab {suc n} (fromℕ n) ≡ leaf one\n tab-diag zero = PE.refl\n tab-diag (suc n) = PE.cong lift (tab-diag n)\n\n norm-exp : ∀ {n} (k : ℕ⁺) → ∣ norm ∣ (exp n k) ≡ leaf k\n norm-exp {n} one = tab-diag n\n norm-exp {n} (suc k) = begin\n ∣ norm ∣ (atomise n · exp n k)\n ≈⟨ PE.sym (∣ norm ∣-hom • (atomise n ∷ exp n k ∷ [])) ⟩\n ∣ norm ∣ (atomise n) ⊗ ∣ norm ∣ (exp n k)\n ≈⟨ ⊗-cong (tab-diag n) (norm-exp k) ⟩\n leaf one ⊗ leaf k\n ∎\n where open Reasoning ∥ J' (suc n) ∥/≈\n\n tab-skip : ∀ {n} → (k : Fin n) → tab {suc n} (up k) ≡ skip (tab {n} k)\n tab-skip {suc zero} zero = PE.refl\n tab-skip {suc (suc n)} zero = PE.refl\n tab-skip {suc (suc n)} (suc k) = PE.cong lift (tab-skip k)\n\n norm-raise : ∀ {n x} → ∣ norm {suc n} ∣ (∣ raise ∣ x) ≡ skip (∣ norm {n} ∣ x)\n norm-raise {n} {atom (dyn k)} = tab-skip k\n norm-raise {n} {term • (x ∷ y ∷ [])} = begin\n ∣ norm ∣ (∣ raise ∣ (x · y))\n ≡⟨ ∣ norm ∣-cong (sym (∣ raise ∣-hom • (x ∷ y ∷ []))) ⟩\n ∣ norm ∣ (∣ raise ∣ x · ∣ raise ∣ y)\n ≡⟨ PE.sym (∣ norm ∣-hom • (∣ raise ∣ x ∷ ∣ raise ∣ y ∷ [])) ⟩\n ∣ norm ∣ (∣ raise ∣ x) ⊗ ∣ norm ∣ (∣ raise ∣ y)\n ≡⟨ ⊗-cong (norm-raise {x = x}) (norm-raise {x = y}) ⟩\n skip (∣ norm ∣ x ⊗ ∣ norm ∣ y)\n ≡⟨ PE.cong skip (∣ norm ∣-hom • (x ∷ y ∷ [])) ⟩\n skip (∣ norm ∣ (x · y))\n ∎\n where open PE.≡-Reasoning\n\nnorm⊙syn≗id : ∀ {n} → norm {n} ⊙ syn {n} ≗ id\nnorm⊙syn≗id {suc n} {leaf x} = norm-exp x\nnorm⊙syn≗id {suc n} {skip x} = begin\n ∣ norm ∣ (∣ raise ∣ (∣ syn ∣ x))\n ≈⟨ norm-raise {x = ∣ syn ∣ x} ⟩\n skip (∣ norm ∣ (∣ syn ∣ x))\n ≈⟨ PE.cong skip norm⊙syn≗id ⟩\n skip x\n ∎\n where open Reasoning ∥ J' (suc n) ∥/≈\nnorm⊙syn≗id {suc n} {cons x xs} = begin\n ∣ norm ∣ (exp n x · ∣ raise ∣ (∣ syn ∣ xs))\n ≈⟨ PE.sym (∣ norm ∣-hom • (exp n x ∷ ∣ raise ∣ (∣ syn ∣ xs) ∷ [])) ⟩\n ∣ norm ∣ (exp n x) ⊗ ∣ norm ∣ (∣ raise ∣ (∣ syn ∣ xs))\n ≈⟨ ⊗-cong (norm-exp x) (norm-raise {x = ∣ syn ∣ xs}) ⟩\n leaf x ⊗ skip (∣ norm ∣ (∣ syn ∣ xs))\n ≈⟨ ⊗-cong (PE.refl {x = leaf x}) (PE.cong skip (norm⊙syn≗id {x = xs})) ⟩\n leaf x ⊗ skip xs\n ∎\n where open Reasoning ∥ J' (suc n) ∥/≈\n\niso : ∀ {n} → ∥ J n ∥ₐ ≃ ∥ J' n ∥ₐ\niso = record { _⃗ = norm\n ; _⃖ = syn\n ; invˡ = norm⊙syn≗id\n ; invʳ = syn⊙norm≗id\n }\n", "meta": {"hexsha": "64a3a4b47f13193529bcb0aad8526a5a891a1d17", "size": 15290, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Fragment/Extensions/CSemigroup/Monomial.agda", "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_issues_repo_path": "src/Fragment/Extensions/CSemigroup/Monomial.agda", "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_forks_repo_path": "src/Fragment/Extensions/CSemigroup/Monomial.agda", "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "avg_line_length": 39.104859335, "max_line_length": 94, "alphanum_fraction": 0.4715500327, "num_tokens": 7185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.3541760005420629}} {"text": "module Syntax where\n\nimport Level\nopen import Data.Empty\nopen import Data.Unit as Unit\nopen import Data.Nat\nopen import Data.List as List renaming ([] to Ø; [_] to [_]L)\nopen import NonEmptyList as NList\nopen import Data.Vec as Vec hiding ([_]; _++_)\nopen import Data.Product as Prod\nopen import Function\n\nopen import Relation.Binary.PropositionalEquality as PE hiding ([_])\nopen import Relation.Binary using (module IsEquivalence; Setoid; module Setoid)\nopen ≡-Reasoning\n\nopen import Common.Context as Context\n\nopen import Algebra\nopen Monoid {{ ... }} hiding (refl)\n\nopen import SyntaxRaw\n\ninfixr 5 _§ₒ_ _§ₘ_\n\n-----------------------------------------\n--- Separate types and terms\n-----------------------------------------\n\nmutual\n data DecentType : {Θ : TyCtx} {Γ₁ Γ₂ : RawCtx} → Raw Θ Γ₁ Γ₂ → Set where\n DT-⊤ : (Θ : TyCtx) (Γ : RawCtx) → DecentType (⊤-Raw Θ Γ)\n DT-tyVar : {Θ : TyCtx} (Γ₁ : RawCtx) {Γ₂ : RawCtx} →\n (X : TyVar Θ Γ₂) → DecentType (tyVarRaw Γ₁ X)\n DT-inst : ∀{Θ Γ₁ Γ₂ A} →\n (B : Raw Θ Γ₁ (Γ₂ ↑ A)) → (t : Raw Ø Γ₁ Ø) →\n DecentType B → DecentTerm t →\n DecentType (instRaw {Γ₂ = Γ₂} B t)\n DT-paramAbstr : ∀{Θ Γ₂} {B : U} (Γ₁ : RawCtx) →\n {A : Raw Θ (B ∷ Γ₁) Γ₂} →\n DecentType A →\n DecentType (paramAbstrRaw Γ₁ A)\n DT-fp : ∀{Θ Γ₂} (Γ₁ : RawCtx) →\n (ρ : FP) → (D : FpData Raw Θ Γ₂) →\n DecentFpData D →\n DecentType (fpRaw Γ₁ ρ D)\n\n data DecentTerm : {Γ₁ Γ₂ : RawCtx} → Raw Ø Γ₁ Γ₂ → Set where\n DO-unit : (Γ : RawCtx) → DecentTerm (unitRaw Γ)\n DO-objVar : {Γ : RawCtx} {A : U} →\n (x : RawVar Γ A) → DecentTerm (objVarRaw x)\n DO-inst : {Γ₁ Γ₂ : RawCtx} {A : U} →\n (t : Raw Ø Γ₁ (Γ₂ ↑ A)) → (s : Raw Ø Γ₁ Ø) →\n DecentTerm t → DecentTerm s →\n DecentTerm (instRaw {Γ₂ = Γ₂} t s)\n DO-dialg : (Δ : RawCtx) (Γ : RawCtx) (A : U) →\n (ρ : FP) (k : ℕ) →\n DecentTerm (dialgRaw Δ Γ A ρ k)\n DO-mapping : (Γ : RawCtx) (Δ : RawCtx) →\n (gs : FpMapData Raw Γ) → (ρ : FP) →\n DecentFpMapData gs →\n DecentTerm (recRaw Γ Δ gs ρ)\n\n DecentFpMapData : {Γ : RawCtx} → FpMapData Raw Γ → Set\n DecentFpMapData [ (Γ' , A , f , t) ] =\n DecentType A × DecentCtxMor f × DecentTerm t\n DecentFpMapData ((Γ' , A , f , t) ∷ ts) =\n DecentType A × DecentCtxMor f × DecentTerm t × DecentFpMapData ts\n\n DecentCtxMor : {Γ₁ Γ₂ : RawCtx} → CtxMor Raw Γ₁ Γ₂ → Set\n DecentCtxMor {Γ₂ = Ø} [] = ⊤\n DecentCtxMor {Γ₂ = x ∷ Γ₂} (t ∷ f) = DecentTerm t × DecentCtxMor f\n\n DecentFpData : ∀{Θ Γ₂} → FpData Raw Θ Γ₂ → Set\n DecentFpData [ Γ , f , A ] = DecentCtxMor f × DecentType A\n DecentFpData ((Γ , f , A) ∷ D)\n = (DecentCtxMor f × DecentType A) × DecentFpData D\n\n{-\nDT-syntax : (Θ : TyCtx) (Γ₁ Γ₂ : RawCtx) → Raw Θ Γ₁ Γ₂ → Set\nDT-syntax _ _ _ A = DecentType A\n\nsyntax DT-syntax Θ Γ₁ Γ₁ A = Θ ∥ Γ₁ ⊨ A ε Γ₂ ━\n\nDO-syntax : (Γ₁ Γ₂ : RawCtx) → Raw Ø Γ₁ Γ₂ → Set\nDO-syntax _ _ t = DecentTerm t\n\nsyntax DO-syntax Γ₁ Γ₂ t = Γ₁ ⊢ t ∈ Γ₂ ⊸?\n-}\n\n\n-------------------------------------\n------- Pre-types and terms\n-------------------------------------\n\n\nPreType : (Θ : TyCtx) (Γ₁ Γ₂ : RawCtx) → Set\nPreType Θ Γ₁ Γ₂ = Σ (Raw Θ Γ₁ Γ₂) λ A → DecentType A\n\n_∣_/_⊸Ty = PreType\n\n\nmkPreType : ∀ {Θ Γ₁ Γ₂} {A : Raw Θ Γ₁ Γ₂} → DecentType A → PreType Θ Γ₁ Γ₂\nmkPreType {A = A} p = (A , p)\n\nPreTerm : (Γ₁ Γ₂ : RawCtx) → Set\nPreTerm Γ₁ Γ₂ = Σ (Raw Ø Γ₁ Γ₂) λ t → DecentTerm t\n\nmkPreTerm : ∀ {Γ₁ Γ₂} {t : Raw Ø Γ₁ Γ₂} → DecentTerm t → PreTerm Γ₁ Γ₂\nmkPreTerm {t = t} p = (t , p)\n\nCtxMorP = CtxMor (λ _ → PreTerm)\n\nmkCtxMorP : {Γ₁ Γ₂ : RawCtx} {f : CtxMor Raw Γ₁ Γ₂} →\n DecentCtxMor f → CtxMorP Γ₁ Γ₂\nmkCtxMorP {Γ₂ = Ø} p = []\nmkCtxMorP {Γ₂ = x ∷ Γ₂} {t ∷ f} (p , ps) = (t , p) ∷ (mkCtxMorP ps)\n\nTyCtxMorP : TyCtx → TyCtx → Set\nTyCtxMorP Θ₁ Ø = ⊤\nTyCtxMorP Θ₁ (Γ ∷ Θ₂) = PreType Θ₁ Ø Γ × TyCtxMorP Θ₁ Θ₂\n\nFpDataP : TyCtx → RawCtx → Set\nFpDataP Θ Γ = NList (Σ RawCtx (λ Γ' → CtxMorP Γ' Γ × PreType (Γ ∷ Θ) Γ' Ø))\n\nmkFpDataP : ∀ {Θ Γ} {D : FpData Raw Θ Γ} → DecentFpData D → FpDataP Θ Γ\nmkFpDataP {D = [ Γ , f , A ]} (p , q) = [ Γ , (mkCtxMorP p) , mkPreType q ]\nmkFpDataP {D = (Γ , f , A) ∷ D} ((p , q) , r) =\n (Γ , mkCtxMorP p , mkPreType q) ∷ mkFpDataP {D = D} r\n\n-- | List of types, context morphisms and terms (Aₖ, fₖ, gₖ) such that\n-- Γₖ, x : Aₖ[C/X] ⊢ gₖ : C fₖ or\n-- Γₖ, x : C fₖ ⊢ gₖ : Aₖ[C/X],\n-- which are the premisses of the rule for recursion and corecursion,\n-- respectively.\nFpMapDataP : RawCtx → Set\nFpMapDataP Γ = NList (Σ RawCtx λ Γ' →\n PreType [ Γ ]L Γ' Ø × CtxMorP Γ' Γ × PreTerm (∗ ∷ Γ') Ø)\n\nmkFpMapDataP : ∀{Γ} {gs : FpMapData Raw Γ} → DecentFpMapData gs → FpMapDataP Γ\nmkFpMapDataP {Γ} {[ Γ' , A , f , t ]} (A-decent , f-decent , t-decent) =\n [ Γ' , mkPreType A-decent , mkCtxMorP f-decent , mkPreTerm t-decent ]\nmkFpMapDataP {Γ} {(Γ' , A , f , t) ∷ gs} (A-decent , f-decent , t-decent , r) =\n (Γ' , mkPreType A-decent , mkCtxMorP f-decent , mkPreTerm t-decent)\n ∷ mkFpMapDataP {Γ} {gs} r\n\ngetFpData : ∀{Γ} → FpMapDataP Γ → FpDataP Ø Γ\ngetFpData [ Γ' , A , f , _ ] = [ Γ' , f , A ]\ngetFpData ((Γ' , A , f , _) ∷ d) = (Γ' , f , A) ∷ getFpData d\n\nprojCtxMor₁ : {Γ₁ Γ₂ : RawCtx} → CtxMorP Γ₂ Γ₁ → CtxMor Raw Γ₂ Γ₁\nprojCtxMor₁ = Vec.map proj₁\n\nprojCtxMor₂ : {Γ₁ Γ₂ : RawCtx} →\n (f : CtxMorP Γ₂ Γ₁) → DecentCtxMor (projCtxMor₁ f)\nprojCtxMor₂ {Ø} [] = tt\nprojCtxMor₂ {x ∷ Γ₁} ((t , p) ∷ f) = (p , projCtxMor₂ f)\n\nprojPTList₁ : ∀{Γ} → FpMapDataP Γ → FpMapData Raw Γ\nprojPTList₁ =\n NList.map (Prod.map id (Prod.map proj₁ (Prod.map projCtxMor₁ proj₁)))\n\nprojPTList₂ : ∀{Γ} → (gs : FpMapDataP Γ) → DecentFpMapData (projPTList₁ gs)\nprojPTList₂ [ (Γ' , A , f , t) ] = (proj₂ A , projCtxMor₂ f , proj₂ t)\nprojPTList₂ ((Γ' , A , f , t) ∷ gs) =\n (proj₂ A , projCtxMor₂ f , proj₂ t , projPTList₂ gs)\n\nprojFpData₁ : ∀ {Θ Γ} → FpDataP Θ Γ → FpData Raw Θ Γ\nprojFpData₁ = NList.map (Prod.map id (Prod.map projCtxMor₁ proj₁))\n\nprojFpData₂ : ∀ {Θ Γ} → (D : FpDataP Θ Γ) → DecentFpData (projFpData₁ D)\nprojFpData₂ [ (Γ , f , A) ] = (projCtxMor₂ f , proj₂ A)\nprojFpData₂ ((Γ , f , A) ∷ D) = ((projCtxMor₂ f , proj₂ A) , projFpData₂ D)\n\n-----------------------------------------\n----- Constructors for pre terms\n-----------------------------------------\n\n⊤-PT : (Θ : TyCtx) (Γ : RawCtx) → PreType Θ Γ Ø\n⊤-PT Θ Γ = mkPreType (DT-⊤ Θ Γ)\n\ninstPT : ∀ {Θ Γ₁ Γ₂ A} → PreType Θ Γ₁ (Γ₂ ↑ A) → PreTerm Γ₁ Ø → PreType Θ Γ₁ Γ₂\ninstPT (B , p) (t , q) = mkPreType (DT-inst _ _ p q)\n\n_⊙_ = instPT\n\ntyVarPT : {Θ : TyCtx} (Γ₁ : RawCtx) {Γ₂ : RawCtx} → TyVar Θ Γ₂ → PreType Θ Γ₁ Γ₂\ntyVarPT Γ₁ X = mkPreType (DT-tyVar _ X)\n\nparamAbstrPT : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) {A : U} →\n PreType Θ (A ∷ Γ₁) Γ₂ → PreType Θ Γ₁ (Γ₂ ↑ A)\nparamAbstrPT Γ₁ (A , p) = mkPreType (DT-paramAbstr Γ₁ p)\n\nfpPT : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) →\n FP → FpDataP Θ Γ₂ → PreType Θ Γ₁ Γ₂\nfpPT Γ₁ ρ D = mkPreType (DT-fp Γ₁ ρ (projFpData₁ D) (projFpData₂ D))\n\nunitPO : (Γ : RawCtx) → PreTerm Γ Ø\nunitPO Γ = mkPreTerm (DO-unit _)\n\nvarPO : {Γ : RawCtx} {A : U} → RawVar Γ A → PreTerm Γ Ø\nvarPO x = mkPreTerm (DO-objVar x)\n\ninstPO : ∀ {Γ₁ Γ₂ A} → PreTerm Γ₁ (Γ₂ ↑ A) → PreTerm Γ₁ Ø → PreTerm Γ₁ Γ₂\ninstPO (t , p) (s , q) = mkPreTerm (DO-inst _ _ p q)\n\n_§ₒ_ = instPO\n\ndialgPO : (Δ : RawCtx) (Γ : RawCtx) (A : U) → FP → ℕ → PreTerm Δ (A ∷ Γ)\ndialgPO Δ Γ A ρ k = mkPreTerm (DO-dialg _ Γ A ρ k)\n\nα : (Δ : RawCtx) (Γ : RawCtx) (A : U) → ℕ → PreTerm Δ (A ∷ Γ)\nα Δ Γ A k = dialgPO Δ Γ A μ k\n\nξ : (Δ : RawCtx) (Γ : RawCtx) (A : U) → ℕ → PreTerm Δ (A ∷ Γ)\nξ Δ Γ A k = dialgPO Δ Γ A ν k\n\n-- | Generalised recursion, does recursion or corecursion, depending on ρ\ngrec : (Γ : RawCtx) (Δ : RawCtx) →\n FpMapDataP Γ → FP → PreTerm Δ (∗ ∷ Γ)\ngrec Γ Δ gs ρ = mkPreTerm (DO-mapping Γ Δ (projPTList₁ gs) ρ (projPTList₂ gs))\n\n-- | Recursion for inductive types\nrec : (Γ : RawCtx) (Δ : RawCtx) →\n FpMapDataP Γ → PreTerm Δ (∗ ∷ Γ)\nrec Γ Δ gs = grec Γ Δ gs μ\n\n-- Corecursion\ncorec : (Γ : RawCtx) (Δ : RawCtx) →\n FpMapDataP Γ → PreTerm Δ (∗ ∷ Γ)\ncorec Γ Δ gs = grec Γ Δ gs ν\n\n\ninstWCtxMorP : {Γ₁ Γ₂ Γ₃ : RawCtx} →\n PreTerm Γ₁ (Γ₃ ++ Γ₂) → CtxMorP Γ₁ Γ₂ → PreTerm Γ₁ Γ₃\ninstWCtxMorP {Γ₁} {Ø} {Γ₃} t [] = subst (PreTerm Γ₁) (proj₂ identity Γ₃) t\ninstWCtxMorP {Γ₁} {x ∷ Γ₂} {Γ₃} t (s ∷ f) =\n instPO\n (instWCtxMorP {Γ₂ = Γ₂} {Γ₃ = Γ₃ ↑ x}\n (subst (PreTerm Γ₁) (mvVar _ Γ₃ x) t) f)\n s\n\n_§ₘ'_ = instWCtxMorP\n\n_§ₘ_ : {Γ₁ Γ₂ : RawCtx} →\n PreTerm Γ₁ Γ₂ → CtxMorP Γ₁ Γ₂ → PreTerm Γ₁ Ø\nt §ₘ f = instWCtxMorP {Γ₃ = Ø} t f\n\ninstTyWCtxMorP : ∀ {Θ Γ₁ Γ₂ Γ₃} →\n PreType Θ Γ₁ (Γ₃ ++ Γ₂) → CtxMorP Γ₁ Γ₂ → PreType Θ Γ₁ Γ₃\ninstTyWCtxMorP {Θ} {Γ₁} {Ø} {Γ₃} A [] =\n subst (PreType Θ Γ₁) (proj₂ identity Γ₃) A\ninstTyWCtxMorP {Θ} {Γ₁} {x ∷ Γ₂} {Γ₃} A (s ∷ f) =\n (instTyWCtxMorP (subst (PreType Θ Γ₁) (mvVar _ Γ₃ x) A) f) ⊙ s\n\n_§ₜ_ : ∀ {Θ Γ₁ Γ₂} →\n PreType Θ Γ₁ Γ₂ → CtxMorP Γ₁ Γ₂ → PreType Θ Γ₁ Ø\nA §ₜ f = instTyWCtxMorP {Γ₃ = Ø} A f\n\n\n---------------------------------------------------------\n--------- Recursion for pre-types\n---------------------------------------------------------\n\nFpDataP' : (TyCtx → RawCtx → RawCtx → Set) → TyCtx → RawCtx → Set\nFpDataP' V Θ Γ = NList (Σ RawCtx (λ Γ' → CtxMorP Γ' Γ × V (Γ ∷ Θ) Γ' Ø))\n\n{-# NON_TERMINATING #-}\nmapPT : {V : TyCtx → RawCtx → RawCtx → Set} →\n ((Θ : TyCtx) (Γ₁ : RawCtx) → V Θ Γ₁ Ø) →\n (∀{Θ Γ₁ Γ₂} → TyVar Θ Γ₂ → V Θ Γ₁ Γ₂) →\n (∀{Θ Γ₁ Γ₂ A} → V Θ Γ₁ (Γ₂ ↑ A) → PreTerm Γ₁ Ø → V Θ Γ₁ Γ₂) →\n (∀{Θ Γ₁ Γ₂ A} → V Θ (A ∷ Γ₁) Γ₂ → V Θ Γ₁ (Γ₂ ↑ A)) →\n (∀{Θ Γ₁ Γ₂} → FP → FpDataP' V Θ Γ₂ → V Θ Γ₁ Γ₂) →\n ∀{Θ Γ₁ Γ₂} → PreType Θ Γ₁ Γ₂ → V Θ Γ₁ Γ₂\nmapPT ⊤-x _ _ _ _ (._ , DT-⊤ Θ Γ) = ⊤-x Θ Γ\nmapPT _ var-x _ _ _ (._ , DT-tyVar Γ₁ X) = var-x X\nmapPT ⊤-x var-x inst-x abstr-x fp-x (._ , DT-inst B t B-dec t-dec) =\n let r = mapPT ⊤-x var-x inst-x abstr-x fp-x (B , B-dec)\n in inst-x r (t , t-dec)\nmapPT ⊤-x var-x inst-x abstr-x fp-x (._ , DT-paramAbstr Γ₁ {A} A-dec) =\n let r = mapPT ⊤-x var-x inst-x abstr-x fp-x (A , A-dec)\n in abstr-x r\nmapPT ⊤-x var-x inst-x abstr-x fp-x (._ , DT-fp Γ₁ ρ D D-dec) =\n let D' = NList.map\n (Prod.map id\n (Prod.map id\n (mapPT ⊤-x var-x inst-x abstr-x fp-x))) (mkFpDataP {D = D} D-dec)\n in fp-x ρ D'\n\n\n----------------------------------------------------------\n--------- Meta theory for decent type predicate\n---------------------------------------------------------\n\nweakenDO : (Γ₁ : RawCtx) → {Γ₂ Γ₃ : RawCtx} {t : Raw Ø (Γ₁ ++ Γ₂) Γ₃} →\n (A : U) → DecentTerm t → DecentTerm (weaken Γ₁ A t)\nweakenDO Γ₁ B (DO-unit ._) = DO-unit _\nweakenDO Γ₁ B (DO-objVar x) = DO-objVar (weakenObjVar Γ₁ B x)\nweakenDO Γ₁ B (DO-inst t s p q) =\n DO-inst _ _ (weakenDO Γ₁ B p) (weakenDO Γ₁ B q)\nweakenDO Γ₁ B (DO-dialg ._ Γ A ρ k) = DO-dialg _ _ A ρ k\nweakenDO Γ₁ B (DO-mapping Γ ._ gs ρ p) = DO-mapping Γ _ gs ρ p\n\nweakenDT : ∀ {Θ} → (Γ₁ : RawCtx) → {Γ₂ Γ₃ : RawCtx} {A : Raw Θ (Γ₁ ++ Γ₂) Γ₃} →\n (B : U) → DecentType A → DecentType (weaken Γ₁ B A)\nweakenDT Γ₁ B (DT-⊤ Θ ._) = DT-⊤ Θ _\nweakenDT Γ₁ B (DT-tyVar _ X) = DT-tyVar _ X\nweakenDT Γ₁ B (DT-inst A t p q) =\n DT-inst _ _ (weakenDT Γ₁ B p) (weakenDO Γ₁ B q)\nweakenDT Γ₁ B (DT-paramAbstr _ p) = DT-paramAbstr _ (weakenDT _ B p)\nweakenDT Γ₁ B (DT-fp _ ρ D p) = DT-fp _ ρ D p\n\nweakenDO₁ : ∀ {Γ₁ Γ₂} {t : Raw Ø Γ₁ Γ₂} →\n (A : U) → DecentTerm t → DecentTerm (weaken₁ A t)\nweakenDO₁ = weakenDO Ø\n\nweakenDT₁ : ∀ {Θ Γ₁ Γ₂} {A : Raw Θ Γ₁ Γ₂} →\n (B : U) → DecentType A → DecentType (weaken₁ B A)\nweakenDT₁ = weakenDT Ø\n\nweakenDecentCtxMor : {Γ₁ Γ₂ : RawCtx} {f : CtxMor Raw Γ₁ Γ₂} →\n (A : U) → DecentCtxMor f →\n DecentCtxMor (Vec.map (weaken₁ A) f)\nweakenDecentCtxMor {Γ₂ = Ø} {[]} A p = tt\nweakenDecentCtxMor {Γ₂ = x ∷ Γ₂} {t ∷ f} A (p , ps) =\n (weakenDO₁ A p , weakenDecentCtxMor A ps)\n\nweakenCtxMorP : {Γ₁ Γ₂ : RawCtx} → CtxMorP Γ₁ Γ₂ → CtxMorP (∗ ∷ Γ₁) Γ₂\nweakenCtxMorP f = mkCtxMorP (weakenDecentCtxMor ∗ (projCtxMor₂ f))\n\n-----------------------------------------------------\n------ Meta operations on pre-terms and pre-types\n-----------------------------------------------------\n\nweakenPT : {Θ : TyCtx} (Γ₁ : RawCtx) {Γ₂ Γ₃ : RawCtx} →\n (A : U) → PreType Θ (Γ₁ ++ Γ₂) Γ₃ → PreType Θ (Γ₁ ++ A ∷ Γ₂) Γ₃\nweakenPT Γ₁ A (B , p) = (_ , weakenDT Γ₁ A p)\n\nweakenPT₁ : ∀ {Θ Γ₁ Γ₂} → (A : U) → PreType Θ Γ₁ Γ₂ → PreType Θ (A ∷ Γ₁) Γ₂\nweakenPT₁ = weakenPT Ø\n\nweakenPO : (Γ₁ : RawCtx) {Γ₂ Γ₃ : RawCtx} →\n (A : U) → PreTerm (Γ₁ ++ Γ₂) Γ₃ → PreTerm (Γ₁ ++ A ∷ Γ₂) Γ₃\nweakenPO Γ₁ A (t , p) = (_ , weakenDO Γ₁ A p)\n\nweakenPO₁ : {Γ₁ Γ₂ : RawCtx} → (A : U) → PreTerm Γ₁ Γ₂ → PreTerm (A ∷ Γ₁) Γ₂\nweakenPO₁ = weakenPO Ø\n\nget' : {Γ₁ Γ₂ : RawCtx} {A : U} →\n (f : CtxMor (λ _ → PreTerm) Γ₂ Γ₁) →\n (x : RawVar Γ₁ A) →\n DecentTerm (get {Raw} (projCtxMor₁ f) x)\nget' (t ∷ f) zero = proj₂ t\nget' (t ∷ f) (succ {b = _} _ x) = get' f x\n\n-- | Lift substitutions to DecentTerm predicate\nsubstDO : {Γ₁ Γ Γ₂ : RawCtx} {t : Raw Ø Γ₁ Γ} →\n (f : CtxMorP Γ₂ Γ₁) →\n DecentTerm t → DecentTerm (substRaw t (projCtxMor₁ f))\nsubstDO f (DO-unit Γ₁) = DO-unit _\nsubstDO f (DO-objVar x) = get' f x\nsubstDO f (DO-inst t s p q) = DO-inst _ _ (substDO f p) (substDO f q)\nsubstDO f (DO-dialg Γ₁ Γ A ρ k) = DO-dialg _ _ A ρ k\nsubstDO f (DO-mapping Γ Γ₁ gs ρ p) = DO-mapping Γ _ _ _ p\n\n-- | Lift substRaw to pre terms\nsubstP : {Γ₁ Γ Γ₂ : RawCtx} →\n PreTerm Γ₁ Γ → CtxMorP Γ₂ Γ₁ → PreTerm Γ₂ Γ\nsubstP (t , p) f = (substRaw t (projCtxMor₁ f) , substDO f p)\n\n_↓[_] = substP\n\n-- | Context identity is a decent context morphism\nctxidDO : (Γ : RawCtx) → DecentCtxMor (ctxid Γ)\nctxidDO Ø = tt\nctxidDO (x ∷ Γ) = (DO-objVar zero , weakenDecentCtxMor _ (ctxidDO Γ))\n\nmkCtxMorP₁ : {Γ₁ Γ₂ : RawCtx} {f : CtxMor Raw Γ₁ Γ₂} →\n (p : DecentCtxMor f) → projCtxMor₁ (mkCtxMorP p) ≡ f\nmkCtxMorP₁ {Γ₂ = Ø} {[]} p = refl\nmkCtxMorP₁ {Γ₂ = A ∷ Γ₂} {t ∷ f} (p , ps) =\n begin\n projCtxMor₁ {A ∷ Γ₂} ((t , p) ∷ mkCtxMorP ps)\n ≡⟨ refl ⟩\n t ∷ projCtxMor₁ (mkCtxMorP ps)\n ≡⟨ cong (λ u → t ∷ u) (mkCtxMorP₁ ps) ⟩\n t ∷ f\n ∎\n\nctxidP : (Γ : RawCtx) → CtxMorP Γ Γ\nctxidP Γ = mkCtxMorP (ctxidDO Γ)\n\n_↓[_/0] : {Γ₁ Γ Γ₂ : RawCtx} →\n PreTerm (∗ ∷ Γ₁) Γ → PreTerm Γ₁ Ø → PreTerm Γ₁ Γ\n_↓[_/0] t s = t ↓[ s ∷ ctxidP _ ]\n\n_•_ : {Γ₁ Γ₂ Γ₃ : RawCtx} → CtxMorP Γ₂ Γ₃ → CtxMorP Γ₁ Γ₂ → CtxMorP Γ₁ Γ₃\n_•_ {Γ₃ = Ø} [] f = []\n_•_ {Γ₃ = A ∷ Γ₃} (t ∷ g) f = substP t f ∷ (g • f)\n\n-- | Context projection is a decent context morphism\nctxProjDO : (Γ₁ Γ₂ : RawCtx) → DecentCtxMor (ctxProjRaw Γ₁ Γ₂)\nctxProjDO Γ₁ Ø = ctxidDO Γ₁\nctxProjDO Γ₁ (x ∷ Γ₂) = weakenDecentCtxMor _ (ctxProjDO Γ₁ Γ₂)\n\nctxProjP : (Γ₁ Γ₂ : RawCtx) → CtxMorP (Γ₂ ++ Γ₁) Γ₁\nctxProjP Γ₁ Γ₂ = mkCtxMorP (ctxProjDO Γ₁ Γ₂)\n\nctxProjP' : (Γ₁ Γ₂ Γ₃ : RawCtx) → CtxMorP (Γ₁ ++ Γ₂ ++ Γ₃) Γ₂\nctxProjP' Γ₁ Γ₂ Ø =\n subst (λ Γ → CtxMorP (Γ₁ ++ Γ) Γ₂)\n (PE.sym (proj₂ identity Γ₂))\n (ctxProjP Γ₂ Γ₁)\nctxProjP' Γ₁ Γ₂ (A ∷ Γ₃) =\n let f = ctxProjP' Γ₁ Γ₂ Γ₃\n in subst (λ Γ → Vec (PreTerm Γ Ø) (length' Γ₂))\n (assoc Γ₁ Γ₂ (A ∷ Γ₃))\n (Vec.map (weakenPO (Γ₁ ++ Γ₂) A)\n (subst (λ Γ → Vec (PreTerm Γ Ø) (length' Γ₂))\n (PE.sym (assoc Γ₁ Γ₂ Γ₃))\n f\n )\n )\n\nweakenDO' : {Γ₁ Γ₃ : RawCtx} {t : Raw Ø Γ₁ Γ₃} →\n (Γ₂ : RawCtx) → DecentTerm t → DecentTerm (weaken' Γ₂ t)\nweakenDO' {Γ₁} {t = t} Γ₂ p =\n subst DecentTerm\n (cong (substRaw t) (mkCtxMorP₁ (ctxProjDO Γ₁ Γ₂)))\n (substDO (ctxProjP Γ₁ Γ₂) p)\n\nweakenPO' : {Γ₁ Γ₃ : RawCtx} →\n (Γ₂ : RawCtx) → PreTerm Γ₁ Γ₃ → PreTerm (Γ₂ ++ Γ₁) Γ₃\nweakenPO' Γ₂ (t , p) = (weaken' Γ₂ t , weakenDO' Γ₂ p)\n\n-- | Lift extension of context morphism to decent terms\nextendP : {Γ₁ Γ₂ : RawCtx} →\n (A : U) → (f : CtxMorP Γ₂ Γ₁) → CtxMorP (A ∷ Γ₂) (A ∷ Γ₁)\nextendP {Γ₁} {Γ₂} A f = varPO zero ∷ Vec.map (weakenPO₁ A) f\n\ngetPO : {Γ₁ Γ₂ : RawCtx} {A : U} → CtxMorP Γ₂ Γ₁ → RawVar Γ₁ A → PreTerm Γ₂ Ø\ngetPO f x = (get {Raw} (projCtxMor₁ f) x , get' f x)\n\nsubstPO : ∀ {Γ₁ Γ Γ₂} → PreTerm Γ₁ Γ → CtxMorP Γ₂ Γ₁ → PreTerm Γ₂ Γ\nsubstPO (._ , DO-unit Γ₁) f = unitPO _\nsubstPO (._ , DO-objVar x) f = getPO f x\nsubstPO (._ , DO-inst t s p q) f =\n instPO (substPO (t , p) f) (substPO (s , q) f)\nsubstPO (._ , DO-dialg Γ₁ Γ A ρ k) f = dialgPO _ Γ A ρ k\nsubstPO (._ , DO-mapping Γ Γ₁ gs ρ p) f = grec Γ _ (mkFpMapDataP {Γ} {gs} p) ρ\n\nweakenPO'' : {Γ₁ Γ₃ : RawCtx} →\n (Γ₂ Γ₂' : RawCtx) → PreTerm Γ₁ Γ₃ → PreTerm (Γ₂' ++ Γ₁ ++ Γ₂) Γ₃\nweakenPO'' Γ₂ Γ₂' t = substPO t (ctxProjP' Γ₂' _ Γ₂)\n\n-- | Lift substitution to pretypes\nsubstPT : ∀ {Θ Γ₁ Γ Γ₂} → PreType Θ Γ₁ Γ → CtxMorP Γ₂ Γ₁ → PreType Θ Γ₂ Γ\nsubstPT (._ , DT-⊤ Θ Γ) f = ⊤-PT _ _\nsubstPT (._ , DT-tyVar Γ₁ X) f = tyVarPT _ X\nsubstPT (._ , DT-inst B t p q) f =\n (substPT (B , p) f) ⊙ (substPO (t , q) f)\nsubstPT (._ , DT-paramAbstr Γ₁ {A} p) f =\n paramAbstrPT _ (substPT (A , p) (extendP _ f))\nsubstPT (._ , DT-fp Γ₁ ρ D q) f = fpPT _ ρ (mkFpDataP {D = D} q)\n\nweakenPT' : ∀ {Θ Γ₁ Γ₂} (Γ : RawCtx) → PreType Θ Γ₁ Γ₂ → PreType Θ (Γ ++ Γ₁) Γ₂\nweakenPT' {Γ₁ = Γ₁} Γ A = substPT A (ctxProjP Γ₁ Γ)\n\nweakenPT'' : ∀ {Θ Γ₁} (Γ : RawCtx) → PreType Θ Ø Γ₁ → PreType Θ Γ Γ₁\nweakenPT'' Γ A =\n subst (λ u → PreType _ u _) (proj₂ identity Γ) (weakenPT' Γ A)\n\n-- | Project a specific variable out\nprojVar : (Γ₁ Γ₂ : RawCtx) (A : U) → PreTerm (Γ₂ ++ A ∷ Γ₁) Ø\nprojVar Γ₁ Ø A = varPO zero\nprojVar Γ₁ (∗ ∷ Γ₂) A = weakenPO₁ _ (projVar Γ₁ Γ₂ A)\n\nextendProj : {Γ₁ Γ₂ : RawCtx} → (Γ₃ Γ₄ : RawCtx) →\n CtxMorP (Γ₄ ++ Γ₃ ++ Γ₂) Γ₁ →\n CtxMorP (Γ₄ ++ Γ₃ ++ Γ₂) (Γ₃ ++ Γ₁)\nextendProj Ø Γ₄ f = f\nextendProj {Γ₁} {Γ₂ = Γ₂} (A ∷ Γ₃) Γ₄ f =\n let p = (assoc Γ₄ (A ∷ Ø) (Γ₃ ++ Γ₂))\n f' = subst (λ u → CtxMorP u Γ₁) (PE.sym p) f\n g = extendProj {Γ₁} {Γ₂} Γ₃ (Γ₄ ↑ A) f'\n g' = subst (λ u → CtxMorP u (Γ₃ ++ Γ₁)) p g\n in projVar (Γ₃ ++ Γ₂) Γ₄ A ∷ g'\n\nweakenTyVar₁ : ∀{Θ₂ Γ₁} (Θ₁ : TyCtx) (Γ : RawCtx) →\n TyVar (Θ₁ ++ Θ₂) Γ₁ → TyVar (Θ₁ ++ Γ ∷ Θ₂) Γ₁\nweakenTyVar₁ Ø Γ X = succ _ X\nweakenTyVar₁ (Γ₁ ∷ Θ₁) Γ zero = zero\nweakenTyVar₁ (Γ₂ ∷ Θ₁) Γ (succ Γ₁ X) = succ Γ₁ (weakenTyVar₁ Θ₁ Γ X)\n\nweakenTyFpData'₁ : ∀ {Θ₂ Γ₁} (Θ₁ : TyCtx) →\n {D : FpData Raw (Θ₁ ++ Θ₂) Γ₁} →\n (Γ : RawCtx) → DecentFpData D →\n Σ (FpData Raw (Θ₁ ++ Γ ∷ Θ₂) Γ₁) DecentFpData\n\n-- | Auxiliary definition to allow Agda to see that it is provided with\n-- a well-defined reursion.\nweakenTy'₁ : ∀ {Θ₂ Γ₁ Γ₂} (Θ₁ : TyCtx) (Γ : RawCtx) →\n (A : Raw (Θ₁ ++ Θ₂) Γ₁ Γ₂) → DecentType A →\n PreType (Θ₁ ++ Γ ∷ Θ₂) Γ₁ Γ₂\nweakenTy'₁ Θ₁ Γ ._ (DT-⊤ ._ Γ₁) =\n ⊤-PT _ _\nweakenTy'₁ Θ₁ Γ .(tyVarRaw Γ₁ X) (DT-tyVar Γ₁ X) =\n tyVarPT Γ₁ (weakenTyVar₁ Θ₁ Γ X)\nweakenTy'₁ Θ₁ Γ .(instRaw B t) (DT-inst B t p q) =\n (weakenTy'₁ Θ₁ Γ B p) ⊙ (t , q)\nweakenTy'₁ Θ₁ Γ .(paramAbstrRaw Γ₁ A) (DT-paramAbstr Γ₁ {A} p) =\n paramAbstrPT Γ₁ (weakenTy'₁ Θ₁ Γ A p)\nweakenTy'₁ Θ₁ Γ .(fpRaw Γ₁ ρ D) (DT-fp Γ₁ ρ D p) =\n let (D' , p') = weakenTyFpData'₁ Θ₁ {D} Γ p\n in fpPT Γ₁ ρ (mkFpDataP {D = D'} p')\n\nweakenTyFpData'₁ {Γ₁ = Γ₁} Θ₁ {[ Γ₂ , f , A ]} Γ (p , q) =\n let (A' , q') = weakenTy'₁ (Γ₁ ∷ Θ₁) Γ A q\n in ([ Γ₂ , f , A' ] , p , q')\nweakenTyFpData'₁ {Γ₁ = Γ₁} Θ₁ {(Γ₂ , f , A) ∷ D} Γ ((p , q) , r) =\n let (A' , q') = weakenTy'₁ (Γ₁ ∷ Θ₁) Γ A q\n (D' , r') = weakenTyFpData'₁ Θ₁ {D} Γ r\n in ((Γ₂ , f , A') ∷ D' , (p , q') , r')\n\nweakenTy₁ : ∀ {Θ₂ Γ₁ Γ₂} (Θ₁ : TyCtx) (Γ : RawCtx) →\n PreType (Θ₁ ++ Θ₂) Γ₁ Γ₂ →\n PreType (Θ₁ ++ Γ ∷ Θ₂) Γ₁ Γ₂\nweakenTy₁ Θ₁ Γ (A , p) = weakenTy'₁ Θ₁ Γ A p\n\nweakenTyCtxMor₁ : ∀ {Θ₁ Θ₂} →\n (Γ : RawCtx) → TyCtxMorP Θ₂ Θ₁ → TyCtxMorP (Γ ∷ Θ₂) Θ₁\nweakenTyCtxMor₁ {Ø} Γ tt = tt\nweakenTyCtxMor₁ {Γ₁ ∷ Θ₁} Γ (A , f) = (weakenTy₁ Ø Γ A , weakenTyCtxMor₁ Γ f)\n\ngetTy : ∀ {Θ₁ Θ₂ Γ₁ Γ₂} → TyCtxMorP Θ₁ Θ₂ → TyVar Θ₂ Γ₂ → PreType Θ₁ Γ₁ Γ₂\ngetTy {Θ₂ = Ø} tt ()\ngetTy {Θ₁} {Θ₂ = Γ ∷ Θ₂} {Γ₁} (B , f) zero =\n subst (λ Γ' → PreType Θ₁ Γ' Γ) (proj₂ identity Γ₁) (weakenPT' Γ₁ B)\ngetTy {Θ₂ = Γ ∷ Θ₂} (B , f) (succ Γ₂ X) = getTy f X\n\nextendTy : ∀ {Θ₁ Θ₂} →\n TyCtxMorP Θ₁ Θ₂ → (Γ : RawCtx) → TyCtxMorP (Γ ∷ Θ₁) (Γ ∷ Θ₂)\nextendTy f Γ = (tyVarPT Ø zero , weakenTyCtxMor₁ Γ f)\n\nsubstTyFpData' : ∀ {Θ₁ Θ₂ Γ} →\n (D : FpData Raw Θ₂ Γ) → DecentFpData D →\n TyCtxMorP Θ₁ Θ₂ → FpDataP Θ₁ Γ\n\n-- | Substitution for type variables, auxilary version to have a clearly\n-- terminating definition.\nsubstTy' : ∀ {Θ₁ Θ₂ Γ₁ Γ₂} →\n (A : Raw Θ₂ Γ₁ Γ₂) → DecentType A → TyCtxMorP Θ₁ Θ₂ →\n PreType Θ₁ Γ₁ Γ₂\n\nsubstTy' {Θ₁} ._ (DT-⊤ Θ Γ) f = ⊤-PT Θ₁ _\nsubstTy' {Θ₁} ._ (DT-tyVar Γ₁ X) f = getTy f X\nsubstTy' {Θ₁} ._ (DT-inst B t p q) f =\n (substTy' B p f) ⊙ (t , q)\nsubstTy' {Θ₁} ._ (DT-paramAbstr Γ₁ {A} p) f =\n paramAbstrPT Γ₁ (substTy' A p f)\nsubstTy' {Θ₁} ._ (DT-fp Γ₁ ρ D p) f =\n fpPT Γ₁ ρ (substTyFpData' D p f)\n\nsubstTyFpData' {Γ = Γ} [ Γ₁ , g , A ] (p , q) f =\n [ Γ₁ , mkCtxMorP p , substTy' A q (extendTy f Γ) ]\nsubstTyFpData' {Γ = Γ} ((Γ₁ , g , A) ∷ D) ((p , q) , r) f =\n (Γ₁ , mkCtxMorP p , substTy' A q (extendTy f Γ))\n ∷ substTyFpData' D r f\n\n-- | Substitution for type variables\nsubstTy : ∀ {Θ₁ Θ₂ Γ₁ Γ₂} →\n PreType Θ₂ Γ₁ Γ₂ → TyCtxMorP Θ₁ Θ₂ → PreType Θ₁ Γ₁ Γ₂\nsubstTy (A , p) = substTy' A p\n\n{-\nweakenTy : {Θ₁ : TyCtx} {Γ₁ Γ₂ : RawCtx}\n (Θ₂ : TyCtx) → Raw Θ₁ Γ₁ Γ₂ → Raw (Θ₂ ++ Θ₁) Γ₁ Γ₂\nweakenTy = {!!}\n-}\n\n-----------------------------------------------\n--- Other operations\n----------------------------------------------\nΛ : ∀ {Θ Γ₁ Γ₂} → PreType Θ Γ₁ Γ₂ → PreType Θ Ø (Γ₂ ++ Γ₁)\nΛ {Γ₁ = Ø} A =\n subst (λ Γ → PreType _ Ø Γ) (PE.sym (proj₂ identity _)) A\nΛ {Γ₁ = B ∷ Γ₁} {Γ₂} A =\n let A' = Λ (paramAbstrPT Γ₁ A)\n in subst (λ Γ → PreType _ Ø Γ) (assoc Γ₂ (B ∷ Ø) Γ₁) A'\n\n--------------------------------------------------\n-- Examples\n--------------------------------------------------\n\n-- We could prove the following\n-- DT-Prod : (Γ : RawCtx) → DecentType (ProdRaw Γ)\n-- However, it is easier to construct the product directly as pretype.\n\nProd : (Γ : RawCtx) → PreType (Γ ︵ Γ) Ø Γ\nProd Γ = fpPT Ø ν D\n where\n Δ = Γ ︵ Γ\n\n A : TyVar (Γ ∷ Δ) Γ\n A = succ Γ zero\n\n B : TyVar (Γ ∷ Δ) Γ\n B = succ Γ (succ Γ zero)\n\n D₁ = (Γ , ctxidP Γ , instTyWCtxMorP (tyVarPT Γ A) (ctxidP Γ))\n\n D₂ = (Γ , ctxidP Γ , instTyWCtxMorP (tyVarPT Γ B) (ctxidP Γ))\n\n D : FpDataP Δ Γ\n D = D₁ ∷ [ D₂ ]\n", "meta": {"hexsha": "44f920dff546eabc67194b2663c7898203239bc5", "size": 22935, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Syntax/Syntax.agda", "max_stars_repo_name": "StillerHarpo/CoindDepTypes", "max_stars_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-27T14:45:11.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-06T02:10:49.000Z", "max_issues_repo_path": "Syntax/Syntax.agda", "max_issues_repo_name": "StillerHarpo/CoindDepTypes", "max_issues_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-24T12:53:30.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-24T12:53:30.000Z", "max_forks_repo_path": "Syntax/Syntax.agda", "max_forks_repo_name": "StillerHarpo/CoindDepTypes", "max_forks_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-24T10:54:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-24T10:54:38.000Z", "avg_line_length": 37.1717990276, "max_line_length": 80, "alphanum_fraction": 0.5346849793, "num_tokens": 10208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982043529715, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.3541759931068949}} {"text": "module Category.Functor.Either where\nopen import Agda.Primitive using (_⊔_)\nopen import Data.Sum using (_⊎_; inj₁; inj₂)\nopen import Category.Functor using (RawFunctor ; module RawFunctor )\nopen import Category.Applicative using (RawApplicative; module RawApplicative)\nopen import Function using (_∘_)\n\nEither : ∀ {l₁ l₂} (A : Set l₁) (B : Set l₂) → Set (l₁ ⊔ l₂)\nEither = _⊎_\n\neitherFunctor : ∀ {l₁ l₂} {A : Set l₁} → RawFunctor (Either {l₁} {l₂} A)\neitherFunctor = record\n { _<$>_ = λ f → λ { (inj₁ z) → inj₁ z ; (inj₂ a) → inj₂ (f a) }\n }\n\neitherApplicative : ∀ {l₁} {A : Set l₁} → RawApplicative (Either {l₁} {l₁} A)\neitherApplicative = record\n { pure = inj₂\n ; _⊛_ = λ { (inj₁ a) → λ _ → inj₁ a ; (inj₂ f) → λ { (inj₁ a) → inj₁ a ; (inj₂ b) → inj₂ (f b) } }\n }\n\n", "meta": {"hexsha": "76b1c3ae681c9167786930e133f5f21bd6e1bf5a", "size": 782, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Category/Functor/Either.agda", "max_stars_repo_name": "crisoagf/agda-optics", "max_stars_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74", "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": "src/Category/Functor/Either.agda", "max_issues_repo_name": "crisoagf/agda-optics", "max_issues_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74", "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": "src/Category/Functor/Either.agda", "max_forks_repo_name": "crisoagf/agda-optics", "max_forks_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74", "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": 35.5454545455, "max_line_length": 100, "alphanum_fraction": 0.6291560102, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.4843800842769844, "lm_q1q2_score": 0.35411021592821423}} {"text": "------------------------------------------------------------------------\n-- A coinductive definition of (strong) bisimilarity\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nopen import Labelled-transition-system\n\nmodule Bisimilarity {ℓ} (lts : LTS ℓ) where\n\nopen import Equality.Propositional\nopen import Prelude\nopen import Prelude.Size\n\nimport Function-universe equality-with-J as F\n\nimport Bisimilarity.General\nopen import Indexed-container using (Container; ν; ν′)\nopen import Relation\nopen import Up-to\n\nopen LTS lts\n\nprivate\n module General = Bisimilarity.General lts _[_]⟶_ _[_]⟶_ id id\n\nopen General public\n using (module StepC; ⟨_,_⟩; left-to-right; right-to-left; force;\n reflexive-∼; reflexive-∼′; ≡⇒∼; ∼:_; ∼′:_;\n [_]_≡_; [_]_≡′_; []≡↔; module Bisimilarity-of-∼;\n Extensionality; extensionality)\n\n-- StepC is given in the following way, rather than via open public,\n-- to make hyperlinks to it more informative.\n\nStepC : Container (Proc × Proc) (Proc × Proc)\nStepC = General.StepC\n\n-- The following definitions are given explicitly, to make the code\n-- easier to follow for readers of the paper.\n\nBisimilarity : Size → Rel₂ ℓ Proc\nBisimilarity = ν StepC\n\nBisimilarity′ : Size → Rel₂ ℓ Proc\nBisimilarity′ = ν′ StepC\n\ninfix 4 [_]_∼_ [_]_∼′_ _∼_ _∼′_\n\n[_]_∼_ : Size → Proc → Proc → Type ℓ\n[ i ] p ∼ q = ν StepC i (p , q)\n\n[_]_∼′_ : Size → Proc → Proc → Type ℓ\n[ i ] p ∼′ q = ν′ StepC i (p , q)\n\n_∼_ : Proc → Proc → Type ℓ\n_∼_ = [ ∞ ]_∼_\n\n_∼′_ : Proc → Proc → Type ℓ\n_∼′_ = [ ∞ ]_∼′_\n\nprivate\n\n -- However, these definitions are definitionally equivalent to\n -- corresponding definitions in General.\n\n indirect-Bisimilarity : Bisimilarity ≡ General.Bisimilarity\n indirect-Bisimilarity = refl\n\n indirect-Bisimilarity′ : Bisimilarity′ ≡ General.Bisimilarity′\n indirect-Bisimilarity′ = refl\n\n indirect-[]∼ : [_]_∼_ ≡ General.[_]_∼_\n indirect-[]∼ = refl\n\n indirect-[]∼′ : [_]_∼′_ ≡ General.[_]_∼′_\n indirect-[]∼′ = refl\n\n indirect-∼ : _∼_ ≡ General._∼_\n indirect-∼ = refl\n\n indirect-∼′ : _∼′_ ≡ General._∼′_\n indirect-∼′ = refl\n\n-- Combinators that can perhaps make the code a bit nicer to read.\n\ninfix -3 _⟶⟨_⟩ʳˡ_ _[_]⟶⟨_⟩ʳˡ_\n lr-result-with-action lr-result-without-action\n\n_⟶⟨_⟩ʳˡ_ : ∀ {i p′ q′ μ} p → p [ μ ]⟶ p′ → [ i ] p′ ∼′ q′ →\n ∃ λ p′ → p [ μ ]⟶ p′ × [ i ] p′ ∼′ q′\n_ ⟶⟨ p⟶p′ ⟩ʳˡ p′∼′q′ = _ , p⟶p′ , p′∼′q′\n\n_[_]⟶⟨_⟩ʳˡ_ : ∀ {i p′ q′} p μ → p [ μ ]⟶ p′ → [ i ] p′ ∼′ q′ →\n ∃ λ p′ → p [ μ ]⟶ p′ × [ i ] p′ ∼′ q′\n_ [ _ ]⟶⟨ p⟶p′ ⟩ʳˡ p′∼′q′ = _ ⟶⟨ p⟶p′ ⟩ʳˡ p′∼′q′\n\nlr-result-without-action :\n ∀ {i p′ q′ μ} → [ i ] p′ ∼′ q′ → ∀ q → q [ μ ]⟶ q′ →\n ∃ λ q′ → q [ μ ]⟶ q′ × [ i ] p′ ∼′ q′\nlr-result-without-action p′∼′q′ _ q⟶q′ = _ , q⟶q′ , p′∼′q′\n\nlr-result-with-action :\n ∀ {i p′ q′} → [ i ] p′ ∼′ q′ → ∀ μ q → q [ μ ]⟶ q′ →\n ∃ λ q′ → q [ μ ]⟶ q′ × [ i ] p′ ∼′ q′\nlr-result-with-action p′∼′q′ _ _ q⟶q′ =\n lr-result-without-action p′∼′q′ _ q⟶q′\n\nsyntax lr-result-without-action p′∼q′ q q⟶q′ = p′∼q′ ⟵⟨ q⟶q′ ⟩ q\nsyntax lr-result-with-action p′∼q′ μ q q⟶q′ = p′∼q′ [ μ ]⟵⟨ q⟶q′ ⟩ q\n\n-- Strong bisimilarity is a weak simulation (of a certain kind).\n\nstrong-is-weak⇒̂ :\n ∀ {p p′ q μ} →\n p ∼ q → p [ μ ]⇒̂ p′ →\n ∃ λ q′ → q [ μ ]⇒̂ q′ × p′ ∼ q′\nstrong-is-weak⇒̂ =\n is-weak⇒̂ StepC.left-to-right (λ p∼′q → force p∼′q)\n (λ s tr → step s tr done) ⟶→⇒̂\n\nmutual\n\n -- Bisimilarity is symmetric.\n\n symmetric-∼ : ∀ {i p q} → [ i ] p ∼ q → [ i ] q ∼ p\n symmetric-∼ p∼q =\n StepC.⟨ Σ-map id (Σ-map id symmetric-∼′) ∘ StepC.right-to-left p∼q\n , Σ-map id (Σ-map id symmetric-∼′) ∘ StepC.left-to-right p∼q\n ⟩\n\n symmetric-∼′ : ∀ {i p q} → [ i ] p ∼′ q → [ i ] q ∼′ p\n force (symmetric-∼′ p∼q) = symmetric-∼ (force p∼q)\n\nprivate\n\n -- An alternative proof of symmetry.\n\n alternative-proof-of-symmetry : ∀ {i p q} → [ i ] p ∼ q → [ i ] q ∼ p\n alternative-proof-of-symmetry {i} =\n uncurry [ i ]_∼_ ⁻¹ ⊆⟨ ν-symmetric _ _ swap refl F.id ⟩∎\n uncurry [ i ]_∼_ ∎\n\n-- Strong bisimilarity is transitive.\n\ntransitive-∼ : ∀ {i p q r} → [ i ] p ∼ q → [ i ] q ∼ r → [ i ] p ∼ r\ntransitive-∼ {i} = λ p q →\n StepC.⟨ lr p q\n , Σ-map id (Σ-map id symmetric-∼′) ∘\n lr (symmetric-∼ q) (symmetric-∼ p)\n ⟩\n where\n lr : ∀ {p p′ q r μ} →\n [ i ] p ∼ q → [ i ] q ∼ r → p [ μ ]⟶ p′ →\n ∃ λ r′ → r [ μ ]⟶ r′ × [ i ] p′ ∼′ r′\n lr p q tr =\n let (_ , tr′ , p′) = StepC.left-to-right p tr\n (_ , tr″ , q′) = StepC.left-to-right q tr′\n in (_ , tr″ , λ { .force → transitive-∼ (force p′) (force q′) })\n\ntransitive-∼′ :\n ∀ {i p q r} → [ i ] p ∼′ q → [ i ] q ∼′ r → [ i ] p ∼′ r\nforce (transitive-∼′ p∼q q∼r) = transitive-∼ (force p∼q) (force q∼r)\n", "meta": {"hexsha": "b785933aed9d974fac2de25e600dfef88c86a1b0", "size": 4746, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Bisimilarity.agda", "max_stars_repo_name": "nad/up-to", "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Bisimilarity.agda", "max_issues_repo_name": "nad/up-to", "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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/Bisimilarity.agda", "max_forks_repo_name": "nad/up-to", "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "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": 28.9390243902, "max_line_length": 72, "alphanum_fraction": 0.5284450063, "num_tokens": 2033, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6297745935070806, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.35404447732458644}} {"text": "open import Agda.Builtin.Reflection\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Unit\n\nmacro\n\n m-0 : Term → TC ⊤\n m-0 goal =\n bindTC (inferType goal) λ where\n (pi (arg (arg-info _ (modality _ quantity-0)) _) _) →\n bindTC (quoteTC (λ (_ : Set) → Set))\n (unify goal)\n type → typeError (termErr type ∷ [])\n\n m-ω : Term → TC ⊤\n m-ω goal =\n bindTC (inferType goal) λ where\n (pi (arg (arg-info _ (modality _ quantity-ω)) _) _) →\n bindTC (quoteTC (λ (_ : Set) → Set))\n (unify goal)\n type → typeError (termErr type ∷ [])\n\n_ : @0 Set → Set₁\n_ = m-0\n\n_ : @ω Set → Set₁\n_ = m-ω\n\npostulate\n f : @0 Set₁ → Set₁\n\nmacro\n\n m₁ : Set₁ → Term → TC ⊤\n m₁ A goal =\n bindTC (quoteTC A) λ A →\n unify goal\n (def (quote f)\n (arg (arg-info visible (modality relevant quantity-0)) A ∷\n []))\n\n_ : Set₁ → Set₁\n_ = λ A → m₁ A\n\nmacro\n\n m₂ : Set₁ → Term → TC ⊤\n m₂ A goal =\n bindTC (quoteTC A) λ A →\n unify goal\n (def (quote f)\n -- The modality is ignored.\n (arg (arg-info visible (modality irrelevant quantity-ω)) A ∷\n []))\n\n_ : Set₁ → Set₁\n_ = λ A → m₂ A\n", "meta": {"hexsha": "5e186fa3e3269e09fdeb9d4992a78e96bba4a2e0", "size": 1199, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue5317.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/Succeed/Issue5317.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/Succeed/Issue5317.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": 20.6724137931, "max_line_length": 69, "alphanum_fraction": 0.5296080067, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6757645879592641, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.35370893642844925}} {"text": "{-# OPTIONS --type-in-type --no-termination-check --no-positivity-check\n #-}\n\nmodule Data1 where\n\n_-_ : {A : Set}{B : A -> Set}{C : (a : A) -> B a -> Set} ->\n ({a : A}(b : B a) -> C a b) -> (f : (a : A) -> B a) ->\n (a : A) -> C a (f a)\nf - g = \\ x -> f (g x)\n\nid : {X : Set} -> X -> X\nid x = x\n\nkonst : {S : Set}{T : S -> Set} -> ({x : S} -> T x) -> (x : S) -> T x\nkonst c x = c\n\ndata Zero : Set where\nrecord One : Set where\n\nrecord Sig (S : Set)(T : S -> Set) : Set where\n field\n fst : S\n snd : T fst\n\nopen module Sig' {S : Set}{T : S -> Set} = Sig {S}{T}\n\n_,_ : forall {S T}(s : S) -> T s -> Sig S T\ns , t = record {fst = s; snd = t}\n\ninfixr 40 _,_\n\n_*_ : Set -> Set -> Set\nS * T = Sig S \\ _ -> T\n\nsig : forall {S T}{P : Sig S T -> Set} ->\n ((s : S)(t : T s) -> P (s , t)) -> (st : Sig S T) -> P st\nsig f st = f (fst st) (snd st)\n\ndata Cx : Set where\n E : Cx\n _/_ : Cx -> Set -> Cx\n\ndata _:>_ : Cx -> Set -> Set where\n ze : {G : Cx}{S : Set} -> (G / S) :> S\n su : {G : Cx}{S T : Set} -> G :> T -> (G / S) :> T\n\ndata PROP : Set where\n Absu : PROP\n Triv : PROP\n _/\\_ : PROP -> PROP -> PROP\n All : (S : Set) -> (S -> PROP) -> PROP\n\nPrf : PROP -> Set\nPrf Absu = Zero\nPrf Triv = One\nPrf (P /\\ Q) = Prf P * Prf Q\nPrf (All S P) = (x : S) -> Prf (P x)\n\ndata CON (G : Cx) : Set where\n ?? : {S : Set} -> G :> S -> S -> CON G\n PrfC : PROP -> CON G\n _*C_ : CON G -> CON G -> CON G\n PiC : (S : Set) -> (S -> CON G) -> CON G\n SiC : (S : Set) -> (S -> CON G) -> CON G\n MuC : (O : Set) -> (O -> CON (G / O)) -> O -> CON G\n NuC : (O : Set) -> (O -> CON (G / O)) -> O -> CON G\n\nBox : (G : Cx) -> ((S : Set) -> (G :> S) -> Set) -> Set\nBox E F = One\nBox (G / S) F = Box G (\\ S n -> F S (su n)) * F S ze\n\npr : {G : Cx}{S : Set}{F : (S : Set) -> (G :> S) -> Set} -> Box G F -> (n : G :> S) -> F S n\npr fsf ze = snd fsf\npr fsf (su n) = pr (fst fsf) n\n\nPay : Cx -> Set\nPay G = Box G (\\ I _ -> I -> Set)\n\nArr : (G : Cx) -> Pay G -> Pay G -> Set\nArr G X Y = Box G (\\ S n -> (s : S) -> pr X n s -> pr Y n s)\n\n\n\nmutual\n [|_|] : {G : Cx} -> CON G -> Pay G -> Set\n [| ?? n i |] X = pr X n i\n [| PrfC P |] X = Prf P\n [| C *C D |] X = [| C |] X * [| D |] X\n [| PiC S C |] X = (s : S) -> [| C s |] X\n [| SiC S C |] X = Sig S \\ s -> [| C s |] X\n [| MuC O C o |] X = Mu C X o\n [| NuC O C o |] X = Nu C X o\n\n data Mu {G : Cx}{O : Set}(C : O -> CON (G / O))(X : Pay G)(o : O) : Set where\n con : [| C o |] ( X , Mu C X ) -> Mu C X o\n codata Nu {G : Cx}{O : Set}(C : O -> CON (G / O))(X : Pay G)(o : O) : Set where\n con : [| C o |] ( X , Nu C X ) -> Nu C X o\n\nnoc : {G : Cx}{O : Set}{C : O -> CON (G / O)}{X : Pay G}{o : O} ->\n Nu C X o -> [| C o |] ( X , Nu C X )\nnoc (con xs) = xs\n\nmutual\n map : {G : Cx}{X Y : Pay G} -> (C : CON G) ->\n Arr G X Y ->\n [| C |] X -> [| C |] Y\n map (?? n i) f = pr f n i\n map (PrfC P) f = id\n map (C *C D) f = sig \\ c d -> map C f c , map D f d\n map (PiC S C) f = \\ c s -> map (C s) f (c s)\n map (SiC S C) f = sig \\ s c -> s , map (C s) f c\n map (MuC O C o) f = foldMap C (Mu C _) f (\\ o -> con) o\n map (NuC O C o) f = unfoldMap C (Nu C _) f (\\ o -> noc) o\n\n foldMap : {G : Cx}{O : Set}(C : O -> CON (G / O)){X Y : Pay G}(Z : O -> Set) ->\n Arr G X Y ->\n ((o : O) -> [| C o |] ( Y , Z ) -> Z o) ->\n (o : O) -> Mu C X o -> Z o\n foldMap C Z f alg o (con xs) = alg o (map (C o) (f , foldMap C Z f alg) xs)\n\n unfoldMap : {G : Cx}{O : Set}(C : O -> CON (G / O)){X Y : Pay G}(Z : O -> Set) ->\n Arr G X Y ->\n ((o : O) -> Z o -> [| C o |] ( X , Z )) ->\n (o : O) -> Z o -> Nu C Y o\n unfoldMap C Z f coalg o y = con (map (C o) (f , unfoldMap C Z f coalg) (coalg o y))\n\nida : (G : Cx) -> (X : Pay G) -> Arr G X X\nida E = id\nida (G / S) = sig \\ Xs X -> ida G Xs , \\ s x -> x\n\ncompa : (G : Cx) -> (X Y Z : Pay G) -> Arr G Y Z -> Arr G X Y -> Arr G X Z\ncompa E = \\ _ _ _ _ _ -> _\ncompa (G / S) = sig \\ Xs X -> sig \\ Ys Y -> sig \\ Zs Z -> sig \\ fs f -> sig \\ gs g ->\n compa G Xs Ys Zs fs gs , \\ s x -> f s (g s x)\n\ndata _==_ {X : Set}(x : X) : {Y : Set} -> Y -> Set where\n refl : x == x\n\nsubst : {X : Set}{P : X -> Set}{x y : X} -> x == y -> P x -> P y\nsubst refl p = p\n\n_=,=_ : {S : Set}{T : S -> Set}\n {s0 : S}{s1 : S} -> s0 == s1 ->\n {t0 : T s0}{t1 : T s1} -> t0 == t1 ->\n _==_ {Sig S T} (s0 , t0) {Sig S T} (s1 , t1)\nrefl =,= refl = refl\n \n\nmylem : (G : Cx) -> (X : Pay G) -> compa G X X X (ida G X) (ida G X) == ida G X\nmylem E X = refl\nmylem (G / S) X = mylem G (fst X) =,= refl\n\nclaim : (G : Cx){O : Set}(C : O -> CON (G / O))(X : Pay G)\n (P : (o : O) -> Mu C X o -> Set) -> (p : (o : O)(y : Mu C X o) -> P o y)\n (o : O) ->\n compa (G / O) (X , Mu C X) (X , (\\ o -> Sig (Mu C X o) (P o))) (X , Mu C X)\n (ida G X , konst fst) (ida G X , (\\ o y -> (y , p o y)))\n == ida (G / O) (X , Mu C X)\nclaim G C X P p o = mylem G X =,= refl\n\nidLem : {G : Cx}{S : Set}{X : Pay G}(n : G :> S) ->\n pr (ida G X) n == (\\ (s : S)(x : pr X n s) -> x)\nidLem ze = refl\nidLem (su y) = idLem y\n\n_=$_ : {S : Set}{T : S -> Set}{f g : (s : S) -> T s} ->\n f == g -> (s : S) -> f s == g s\nrefl =$ s = refl\n\nmutual -- and too intensional\n mapId : {G : Cx}{X : Pay G} -> (C : CON G) -> (xs : [| C |] X) ->\n map C (ida G X) xs == xs\n mapId (?? y y') xs = (idLem y =$ y') =$ xs\n mapId (PrfC y) xs = refl\n mapId (y *C y') xs = mapId y (fst xs) =,= mapId y' (snd xs)\n mapId (PiC S y) xs = {!!} -- no chance\n mapId (SiC S y) xs = refl =,= mapId (y (fst xs)) (snd xs)\n mapId (MuC O y y') xs = foldMapId y y' xs\n mapId (NuC O y y') xs = {!!}\n\n foldMapId : {G : Cx}{O : Set}(C : O -> CON (G / O)){X : Pay G}\n (o : O)(z : Mu C X o) ->\n foldMap C (Mu C X) (ida G X) (\\ o -> con) o z == z\n foldMapId C o (con xzs) = {!!} -- close but no banana\n\nmapComp : {G : Cx}{X Y Z : Pay G} (f : Arr G Y Z)(g : Arr G X Y)\n (C : CON G) -> (xs : [| C |] X) ->\n map C f (map C g xs) == map C (compa G X Y Z f g) xs\nmapComp = {!!}\n\n\n_-=-_ : {X : Set}{x y z : X} -> x == y -> y == z -> x == z\nrefl -=- refl = refl\n\ninduction : {G : Cx}{O : Set}(C : O -> CON (G / O)){X : Pay G}\n (P : (o : O) -> Mu C X o -> Set) ->\n ((o : O)(xyps : [| C o |] (X , (\\ o -> Sig (Mu C X o) (P o)))) ->\n P o (con (map (C o) (ida G X , konst fst) xyps))) ->\n (o : O)(y : Mu C X o) -> P o y\ninduction {G} C {X} P p o (con xys) =\n subst {P = \\ xys -> P o (con xys)}{y = xys}\n ((mapComp \n (ida G X , konst fst) (ida G X , (\\ o y -> (y , induction C P p o y))) (C o) xys\n -=- {!!}) \n -=- mapId (C o) xys)\n (p o (map (C o) (ida G X , (\\ o y -> (y , induction C P p o y))) xys))\n", "meta": {"hexsha": "8385e7b94654c6c347b7eeeaf5b10549bcd69a75", "size": 6778, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "models/Data1.agda", "max_stars_repo_name": "mietek/epigram", "max_stars_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 48, "max_stars_repo_stars_event_min_datetime": "2016-01-09T17:36:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T01:55:28.000Z", "max_issues_repo_path": "models/Data1.agda", "max_issues_repo_name": "mietek/epigram", "max_issues_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2", "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": "models/Data1.agda", "max_forks_repo_name": "mietek/epigram", "max_forks_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2016-08-14T21:36:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T01:57:40.000Z", "avg_line_length": 32.7439613527, "max_line_length": 92, "alphanum_fraction": 0.4001180289, "num_tokens": 2980, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081926, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.3536892001815728}} {"text": "module Impure.LFRef.Welltyped where\n\nopen import Prelude\n\nopen import Data.List hiding ([_])\nopen import Data.List.All hiding (map)\nopen import Data.Vec as Vec hiding ([_]; map)\nopen import Data.Star hiding (_▻▻_; map)\nopen import Data.Sum hiding (map)\nopen import Extensions.List as L using ()\n\nopen import Impure.LFRef.Syntax hiding (subst)\nopen import Relation.Binary.List.Pointwise using (Rel)\n\nCtx : (n : ℕ) → Set\nCtx n = Vec (Type n) n\n\n-- store typings\nWorld : Set\nWorld = List (Type 0)\n\nweaken₁-tp : ∀ {n} → Type n → Type (suc n)\nweaken₁-tp tp = tp tp/ wk\n\n_:+:_ : ∀ {n} → Type n → Ctx n → Ctx (suc n)\na :+: Γ = (weaken₁-tp a) ∷ (Vec.map (flip _tp/_ wk) Γ)\n\nweaken+-tm : ∀ {m} n → Term m → Term (n + m)\nweaken+-tm n t = t / (wk⋆ n)\n\nweaken+-tp : ∀ n → Type 0 → Type n\nweaken+-tp zero t = t\nweaken+-tp (suc n) t = subst Type (+-right-identity (suc n)) (t tp/ (wk⋆ (suc n)))\n\nweaken+-tele : ∀ {m n} k → Tele n m → Tele (n + k) m\nweaken+-tele k T = subst (flip Tele _) (+-comm k _) (T tele/ (wk⋆ k))\n\n-- mutually inductive welltypedness judgments for kinds/types and terms respectively\ndata _,_,_⊢_teleok : ∀ {n m} → (𝕊 : Sig) → World → Ctx n → Tele n m → Set\ndata _,_,_⊢_::_ : ∀ {n m} (𝕊 : Sig) → World → Ctx n → Type n → Tele n m → Set\ndata _,_,_⊢_∶_ : ∀ {n} (𝕊 : Sig) → World → Ctx n → Term n → Type n → Set\n\ndata _,_,_⊢_teleok where\n ε : ∀ {n 𝕊 Σ} {Γ : Ctx n} → 𝕊 , Σ , Γ ⊢ ε teleok\n\n _⟶_ : ∀ {n m 𝕊 Σ Γ} {A : Type n} {K : Tele (suc n) m}→\n 𝕊 , Σ , Γ ⊢ A :: ε →\n 𝕊 , Σ , (A :+: Γ) ⊢ K teleok →\n 𝕊 , Σ , Γ ⊢ (A ⟶ K) teleok\n\ndata _,_,_⊢_∶ⁿ_ {n} (𝕊 : Sig) (Σ : World) (Γ : Ctx n) :\n ∀ {m} → List (Term n) → Tele n m → Set where\n\n ε : 𝕊 , Σ , Γ ⊢ [] ∶ⁿ ε\n\n _⟶_ : ∀ {m A t ts} {B : Tele (suc n) m}→\n 𝕊 , Σ , Γ ⊢ t ∶ A →\n 𝕊 , Σ , Γ ⊢ ts ∶ⁿ (B tele/ (sub t)) →\n 𝕊 , Σ , Γ ⊢ (t ∷ ts) ∶ⁿ (A ⟶ B)\n\n-- specialize the returntype from a constructor from it's welltyped arguments\n_con[_/_] : ∀ {n} → (C : ConType) → (ts : List (Term n)) → length ts ≡ (ConType.m C) → Type n\n_con[_/_] {n} C ts p =\n (ConType.tp C) [\n map\n (flip _/_ (subst (Vec _) p (fromList ts)))\n (ConType.indices C)\n ]\n\n-- specialize the return type of a function from it's welltyped arguments\n_fun[_/_] : ∀ {n m} → Type m → (ts : List (Term n)) → length ts ≡ m → Type n\n_fun[_/_] {n} {m} a ts p = a tp/ subst (Vec _) p ((fromList ts))\n\ndata _,_,_⊢_::_ where\n\n Ref : ∀ {n 𝕊 Σ} {Γ : Ctx n} {A} →\n 𝕊 , Σ , Γ ⊢ A :: ε →\n ----------------------\n 𝕊 , Σ , Γ ⊢ Ref A :: ε\n\n Unit : ∀ {n 𝕊 Σ} {Γ : Ctx n} →\n ---------------------\n 𝕊 , Σ , Γ ⊢ Unit :: ε\n\n _[_] : ∀ {n 𝕊 Σ} {Γ : Ctx n} {k K ts} →\n (Sig.types 𝕊) L.[ k ]= K →\n 𝕊 , [] , [] ⊢ (proj₂ K) teleok →\n 𝕊 , Σ , Γ ⊢ ts ∶ⁿ (weaken+-tele n (proj₂ K)) →\n -------------------------\n 𝕊 , Σ , Γ ⊢ k [ ts ] :: ε\n\ndata _,_,_⊢_∶_ where\n\n unit : ∀ {n 𝕊 Σ} {Γ : Ctx n} →\n -----------------------\n 𝕊 , Σ , Γ ⊢ unit ∶ Unit\n\n var : ∀ {n 𝕊 Σ} {Γ : Ctx n} {i A} →\n Γ [ i ]= A →\n ---------------------\n 𝕊 , Σ , Γ ⊢ var i ∶ A\n\n con : ∀ {n 𝕊 Σ} {Γ : Ctx n} {c C ts} →\n (Sig.constructors 𝕊) L.[ c ]= C →\n (p : 𝕊 , Σ , Γ ⊢ ts ∶ⁿ weaken+-tele n (ConType.args C)) →\n (q : length ts ≡ (ConType.m C)) →\n ------------------------------------\n 𝕊 , Σ , Γ ⊢ con c ts ∶ (C con[ ts / q ])\n\n loc : ∀ {n 𝕊 Σ} {Γ : Ctx n} {i S} →\n Σ L.[ i ]= S →\n ---------------------\n 𝕊 , Σ , Γ ⊢ loc i ∶ Ref (weaken+-tp n S)\n\ndata _,_,_⊢ₑ_∶_ : ∀ {n} (𝕊 : Sig) → World → Ctx n → Exp n → Type n → Set where\n\n tm : ∀ {n t} {Γ : Ctx n} {𝕊 Σ A} →\n 𝕊 , Σ , Γ ⊢ t ∶ A →\n ---------------------\n 𝕊 , Σ , Γ ⊢ₑ tm t ∶ A\n\n _·★[_]_ : ∀ {n fn ts 𝕊 Σ φ} {Γ : Ctx n} →\n (Sig.funs 𝕊) L.[ fn ]= φ →\n (q : length ts ≡ (Fun.m φ)) →\n (p : 𝕊 , Σ , Γ ⊢ ts ∶ⁿ weaken+-tele n (Fun.args φ)) →\n -----------------------------------------------------\n 𝕊 , Σ , Γ ⊢ₑ (fn ·★ ts) ∶ ((Fun.returntype φ) fun[ ts / q ])\n\n ref : ∀ {n x A 𝕊 Σ} {Γ : Ctx n} →\n 𝕊 , Σ , Γ ⊢ₑ x ∶ A →\n --------------------------\n 𝕊 , Σ , Γ ⊢ₑ ref x ∶ Ref A\n\n !_ : ∀ {n x A} {Γ : Ctx n} {𝕊 Σ} →\n\n 𝕊 , Σ , Γ ⊢ₑ x ∶ Ref A →\n ----------------------\n 𝕊 , Σ , Γ ⊢ₑ (! x) ∶ A\n\n _≔_ : ∀ {n i x A} {Γ : Ctx n} {𝕊 Σ} →\n 𝕊 , Σ , Γ ⊢ₑ i ∶ Ref A →\n 𝕊 , Σ , Γ ⊢ₑ x ∶ A →\n --------------------------\n 𝕊 , Σ , Γ ⊢ₑ (i ≔ x) ∶ Unit\n\ndata _,_,_⊢ₛ_∶_ : ∀ {n} (𝕊 : Sig) → World → Ctx n → SeqExp n → Type n → Set where\n\n ret : ∀ {n x A 𝕊 Σ} {Γ : Ctx n} →\n 𝕊 , Σ , Γ ⊢ₑ x ∶ A →\n ---------------------\n 𝕊 , Σ , Γ ⊢ₛ ret x ∶ A\n\n lett : ∀ {n x c A B 𝕊 Σ} {Γ : Ctx n} →\n 𝕊 , Σ , Γ ⊢ₑ x ∶ A →\n 𝕊 , (Σ) , (A :+: Γ) ⊢ₛ c ∶ weaken₁-tp B →\n ---------------------------------------r\n 𝕊 , Σ , Γ ⊢ₛ lett x c ∶ B\n\n-- telescopes as context transformers\n_⊢⟦_⟧ : ∀ {n m} → Ctx n → Tele n m → Ctx (n + m)\nΓ ⊢⟦ ε ⟧ = subst Ctx (sym $ +-right-identity _) Γ\n_⊢⟦_⟧ {n} Γ (_⟶_ {m = m} x T) = subst Ctx (sym $ +-suc n m) ((x :+: Γ) ⊢⟦ T ⟧)\n\n_⊢_fnOk : Sig → Fun → Set\n_⊢_fnOk 𝕊 φ = 𝕊 , [] , ([] ⊢⟦ Fun.args φ ⟧) ⊢ₑ (Fun.body φ) ∶ (Fun.returntype φ)\n\n-- valid signature contexts\nrecord _,_⊢ok {n} (𝕊 : Sig) (Γ : Ctx n) : Set where\n field\n funs-ok : All (λ x → 𝕊 ⊢ x fnOk) (Sig.funs 𝕊)\n\n-- store welltypedness relation\n-- as a pointwise lifting of the welltyped relation on closed expressions between a world and a store\n_,_⊢_ : Sig → World → Store → Set\n_,_⊢_ 𝕊 Σ μ = Rel (λ A x → 𝕊 , Σ , [] ⊢ (proj₁ x) ∶ A) Σ μ\n\n-- a useful lemma about telescoped terms\ntele-fit-length : ∀ {n m 𝕊 Σ Γ ts} {T : Tele n m} → 𝕊 , Σ , Γ ⊢ ts ∶ⁿ T → length ts ≡ m\ntele-fit-length ε = refl\ntele-fit-length (x ⟶ p) with tele-fit-length p\ntele-fit-length (x ⟶ p) | refl = refl\n", "meta": {"hexsha": "53be2ad5017deb5706837113dc65e4a040889409", "size": 5850, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Impure/LFRef/Welltyped.agda", "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "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/Impure/LFRef/Welltyped.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/Impure/LFRef/Welltyped.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": 32.1428571429, "max_line_length": 101, "alphanum_fraction": 0.4370940171, "num_tokens": 2581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081926, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.35368920018157274}} {"text": "------------------------------------------------------------------------\n-- Admissible rules are sometimes not \"postulable\"\n------------------------------------------------------------------------\n\n-- Even though a rule is admissible it may not be sound to postulate\n-- it, i.e. add it as an inductive constructor. This was observed by\n-- Edsko de Vries in a message to the Coq-club mailing list (Re:\n-- [Coq-Club] Adding (inductive) transitivity to weak bisimilarity not\n-- sound? (was: Need help with coinductive proof), 2009-08-28).\n\nmodule AdmissibleButNotPostulable where\n\nopen import Codata.Musical.Notation using (∞; ♯_; ♭)\nopen import Data.Nat\nopen import Data.Product as Prod\nopen import Function\nopen import Relation.Binary.PropositionalEquality as P using (_≡_; [_])\nopen import Relation.Nullary using (¬_)\n\n------------------------------------------------------------------------\n-- The partiality monad\n\ndata _⊥ (A : Set) : Set where\n now : (v : A) → A ⊥\n later : (x : ∞ (A ⊥)) → A ⊥\n\n------------------------------------------------------------------------\n-- Weak equality of computations in the partiality monad\n\nmodule WeakEquality where\n\n infix 4 _≈_\n\n data _≈_ {A : Set} : A ⊥ → A ⊥ → Set where\n now : ∀ {v} → now v ≈ now v\n later : ∀ {x y} (x≈y : ∞ (♭ x ≈ ♭ y)) → later x ≈ later y\n laterʳ : ∀ {x y} (x≈y : x ≈ ♭ y ) → x ≈ later y\n laterˡ : ∀ {x y} (x≈y : ♭ x ≈ y ) → later x ≈ y\n\n -- Some lemmas.\n\n laterʳ⁻¹ : ∀ {A : Set} {x : A ⊥} {y} → x ≈ later y → x ≈ ♭ y\n laterʳ⁻¹ (later x≈y) = laterˡ (♭ x≈y)\n laterʳ⁻¹ (laterʳ x≈y) = x≈y\n laterʳ⁻¹ (laterˡ x≈ly) = laterˡ (laterʳ⁻¹ x≈ly)\n\n laterˡ⁻¹ : ∀ {A : Set} {x} {y : A ⊥} → later x ≈ y → ♭ x ≈ y\n laterˡ⁻¹ (later x≈y) = laterʳ (♭ x≈y)\n laterˡ⁻¹ (laterʳ lx≈y) = laterʳ (laterˡ⁻¹ lx≈y)\n laterˡ⁻¹ (laterˡ x≈y) = x≈y\n\n -- Weak equality is an equivalence relation.\n\n refl : {A : Set} (x : A ⊥) → x ≈ x\n refl (now v) = now\n refl (later x) = later (♯ refl (♭ x))\n\n sym : {A : Set} {x y : A ⊥} → x ≈ y → y ≈ x\n sym now = now\n sym (later x≈y) = later (♯ sym (♭ x≈y))\n sym (laterʳ x≈y) = laterˡ (sym x≈y)\n sym (laterˡ x≈y) = laterʳ (sym x≈y)\n\n trans : {A : Set} {x y z : A ⊥} → x ≈ y → y ≈ z → x ≈ z\n trans {x = now v} {z = z} p q = tr p q\n where\n tr : ∀ {y} → now v ≈ y → y ≈ z → now v ≈ z\n tr now y≈z = y≈z\n tr (laterʳ v≈y) ly≈z = tr v≈y (laterˡ⁻¹ ly≈z)\n trans {x = later x} lx≈y y≈z = tr lx≈y y≈z\n where\n tr : ∀ {y z} → later x ≈ y → y ≈ z → later x ≈ z\n tr lx≈ly (later y≈z) = later (♯ trans (laterˡ⁻¹ lx≈ly) (laterˡ (♭ y≈z)))\n tr lx≈y (laterʳ y≈z) = later (♯ trans (laterˡ⁻¹ lx≈y) y≈z )\n tr lx≈ly (laterˡ y≈z) = tr (laterʳ⁻¹ lx≈ly) y≈z\n tr (laterˡ x≈y) y≈z = laterˡ ( trans x≈y y≈z )\n\n -- Non-termination.\n\n never : {A : Set} → A ⊥\n never = later (♯ never)\n\n -- Weak equality is not trivial (assuming that the argument to _⊥ is\n -- non-empty).\n\n non-trivial : {A : Set} {v : A} → ¬ now v ≈ never\n non-trivial (laterʳ v≈⊥) = non-trivial v≈⊥\n\n------------------------------------------------------------------------\n-- Extended weak equality\n\nmodule ExtendedWeakEquality where\n\n infix 4 _≈_\n infix 3 _∎\n infixr 2 _≈⟨_⟩_\n\n -- Let us try to postulate transitivity using an inductive rule.\n\n data _≈_ {A : Set} : A ⊥ → A ⊥ → Set where\n now : ∀ {v} → now v ≈ now v\n later : ∀ {x y} (x≈y : ∞ (♭ x ≈ ♭ y)) → later x ≈ later y\n laterʳ : ∀ {x y} (x≈y : x ≈ ♭ y ) → x ≈ later y\n laterˡ : ∀ {x y} (x≈y : ♭ x ≈ y ) → later x ≈ y\n\n -- Transitivity.\n _≈⟨_⟩_ : ∀ x {y z} (x≈y : x ≈ y) (y≈z : y ≈ z) → x ≈ z\n\n -- Reflexivity.\n\n _∎ : {A : Set} (x : A ⊥) → x ≈ x\n now v ∎ = now\n later x ∎ = later (♯ (♭ x ∎))\n\n -- Extended weak equality is trivial.\n\n trivial : {A : Set} (x y : A ⊥) → x ≈ y\n trivial x y =\n x ≈⟨ laterʳ (x ∎) ⟩\n later (♯ x) ≈⟨ later (♯ trivial x y) ⟩\n later (♯ y) ≈⟨ laterˡ (y ∎) ⟩\n y ∎\n\n -- The problem is that there is no \"contractive\" proof of\n -- transitivity; the proof given above consumes the input\n -- certificate \"faster\" than it produces the output certificate.\n\n------------------------------------------------------------------------\n-- Capretta's definition of equality coincides with weak equality\n\n-- This is not really related to the problem discussed above, I just\n-- want to ensure that the definition of weak equality is not too\n-- strange.\n\nmodule Capretta'sEquality where\n\n infix 4 _⇓_ _≈_\n\n -- x ⇓ v means that x terminates with the value v.\n\n data _⇓_ {A : Set} : A ⊥ → A → Set where\n now : ∀ {v} → now v ⇓ v\n later : ∀ {x v} (x⇓v : ♭ x ⇓ v) → later x ⇓ v\n\n -- Equality as defined by Capretta in \"General Recursion via\n -- Coinductive Types\".\n\n data _≈_ {A : Set} : A ⊥ → A ⊥ → Set where\n now : ∀ {x y v} (x⇓v : x ⇓ v) (y⇓v : y ⇓ v) → x ≈ y\n later : ∀ {x y} (x≈y : ∞ (♭ x ≈ ♭ y)) → later x ≈ later y\n\n -- Soundness.\n\n open WeakEquality using () renaming (_≈_ to _≋_)\n\n sound : {A : Set} {x y : A ⊥} → x ≈ y → x ≋ y\n sound (later x≈y) = WeakEquality.later (♯ sound (♭ x≈y))\n sound (now x⇓v y⇓v) = nw x⇓v y⇓v\n where\n nw : ∀ {A : Set} {x y : A ⊥} {v} → x ⇓ v → y ⇓ v → x ≋ y\n nw now now = WeakEquality.now\n nw x⇓v (later y⇓v) = WeakEquality.laterʳ (nw x⇓v y⇓v)\n nw (later x⇓v) y⇓v = WeakEquality.laterˡ (nw x⇓v y⇓v)\n\n -- Completeness.\n\n data _≈P_ {A : Set} : A ⊥ → A ⊥ → Set where\n now : ∀ {x y v} (x⇓v : x ⇓ v) (y⇓v : y ⇓ v) → x ≈P y\n later : ∀ {x y} (x≈y : ∞ (♭ x ≈P ♭ y)) → later x ≈P later y\n laterʳ : ∀ {x y} (x≈y : x ≈P ♭ y ) → x ≈P later y\n laterˡ : ∀ {x y} (x≈y : ♭ x ≈P y ) → later x ≈P y\n\n data _≈W_ {A : Set} : A ⊥ → A ⊥ → Set where\n now : ∀ {x y v} (x⇓v : x ⇓ v) (y⇓v : y ⇓ v) → x ≈W y\n later : ∀ {x y} (x≈y : ♭ x ≈P ♭ y) → later x ≈W later y\n\n laterʳW : ∀ {A : Set} {x : A ⊥} {y} → x ≈W ♭ y → x ≈W later y\n laterʳW {y = y} x≈y with ♭ y | P.inspect ♭ y\n laterʳW x≈y | y′ | [ eq ] with x≈y\n laterʳW x≈y | y′ | [ eq ] | now {v = v} x⇓v y⇓v =\n now x⇓v (later (P.subst (λ y → y ⇓ v) (P.sym eq) y⇓v))\n laterʳW x≈y | later y′ | [ eq ] | later x′≈y′ =\n later (P.subst (_≈P_ _) (P.sym eq) (laterʳ x′≈y′))\n\n laterˡW : ∀ {A : Set} {x} {y : A ⊥} → ♭ x ≈W y → later x ≈W y\n laterˡW {x = x} x≈y with ♭ x | P.inspect ♭ x\n laterˡW x≈y | x′ | [ eq ] with x≈y\n laterˡW x≈y | x′ | [ eq ] | now {v = v} x⇓v y⇓v =\n now (later (P.subst (λ x → x ⇓ v) (P.sym eq) x⇓v)) y⇓v\n laterˡW x≈y | later x′ | [ eq ] | later {y = y′} x′≈y′ =\n later (P.subst (λ x → x ≈P ♭ y′) (P.sym eq) (laterˡ x′≈y′))\n\n whnf : {A : Set} {x y : A ⊥} → x ≈P y → x ≈W y\n whnf (now x⇓v y⇓v) = now x⇓v y⇓v\n whnf (later x≈y) = later (♭ x≈y)\n whnf (laterʳ x≈y) = laterʳW (whnf x≈y)\n whnf (laterˡ x≈y) = laterˡW (whnf x≈y)\n\n mutual\n\n ⟦_⟧W : {A : Set} {x y : A ⊥} → x ≈W y → x ≈ y\n ⟦ now x⇓v y⇓v ⟧W = now x⇓v y⇓v\n ⟦ later x≈y ⟧W = later (♯ ⟦ x≈y ⟧P)\n\n ⟦_⟧P : {A : Set} {x y : A ⊥} → x ≈P y → x ≈ y\n ⟦ x≈y ⟧P = ⟦ whnf x≈y ⟧W\n\n complete : {A : Set} {x y : A ⊥} → x ≋ y → x ≈ y\n complete x≋y = ⟦ completeP x≋y ⟧P\n where\n completeP : {A : Set} {x y : A ⊥} → x ≋ y → x ≈P y\n completeP WeakEquality.now = now now now\n completeP (WeakEquality.later x≈y) = later (♯ completeP (♭ x≈y))\n completeP (WeakEquality.laterʳ x≈y) = laterʳ (completeP x≈y)\n completeP (WeakEquality.laterˡ x≈y) = laterˡ (completeP x≈y)\n\n------------------------------------------------------------------------\n-- The weak equality above coincides with weak bisimilarity\n\nmodule WeakBisimilarity {A : Set} where\n\n -- The function drop n drops n later constructors (if possible).\n\n drop : ℕ → A ⊥ → A ⊥\n drop zero x = x\n drop _ (now v) = now v\n drop (suc n) (later x) = drop n (♭ x)\n\n -- Weak simulations and bisimulations. The removal of a later\n -- constructor is treated as a silent transition.\n\n record IsWeakSimulation (_R_ : A ⊥ → A ⊥ → Set) : Set where\n field\n match-later : ∀ {x y} → later x R y → ∃ λ n → ♭ x R drop n y\n match-now : ∀ {v y} → now v R y → ∃ λ n → now v ≡ drop n y\n\n record IsWeakBisimulation (_R_ : A ⊥ → A ⊥ → Set) : Set where\n field\n left : IsWeakSimulation _R_\n right : IsWeakSimulation (flip _R_)\n\n -- Weak bisimilarity.\n\n record _≈_ (x y : A ⊥) : Set₁ where\n field\n _R_ : A ⊥ → A ⊥ → Set\n xRy : x R y\n bisim : IsWeakBisimulation _R_\n\n open WeakEquality hiding (module _≈_) renaming (_≈_ to _≋_)\n\n -- Completeness.\n\n complete : ∀ {x y} → x ≋ y → x ≈ y\n complete x≋y = record\n { _R_ = _≋_\n ; xRy = x≋y\n ; bisim = record\n { left = record\n { match-later = λ lx≋y → (0 , laterˡ⁻¹ lx≋y)\n ; match-now = match-now\n }\n ; right = record\n { match-later = λ x≋ly → (0 , laterʳ⁻¹ x≋ly)\n ; match-now = match-now ∘ sym\n }\n }\n }\n where\n match-now : ∀ {v y} → now v ≋ y → ∃ λ n → now v ≡ drop n y\n match-now now = (0 , P.refl)\n match-now (laterʳ v≋y) = Prod.map suc id (match-now v≋y)\n\n -- Soundness.\n\n module Sound {x y} (x≈y : x ≈ y) where\n\n open _≈_ x≈y\n open IsWeakBisimulation\n open IsWeakSimulation\n\n helper₁ : ∀ {x} y → (∃ λ n → now x ≡ drop n y) → now x ≋ y\n helper₁ (now y) (zero , P.refl) = now\n helper₁ (now y) (suc n , P.refl) = now\n helper₁ (later y) (zero , ())\n helper₁ (later y) (suc n , nx≡y-n) =\n laterʳ (helper₁ (♭ y) (n , nx≡y-n))\n\n mutual\n\n helper₂ : ∀ {x} y → (∃ λ n → x R drop n y) → x ≋ y\n helper₂ y (zero , xRy) = sound _ _ xRy\n helper₂ (now y) (suc n , xRny) = sound _ _ xRny\n helper₂ (later y) (suc n , xRy-n) =\n laterʳ (helper₂ (♭ y) (n , xRy-n))\n\n helper₃ : ∀ x {y} → (∃ λ n → drop (suc n) x R y) → x ≋ y\n helper₃ (now x) (n , nxRy) = sound _ _ nxRy\n helper₃ (later x) (zero , xRy) = laterˡ (sound _ _ xRy)\n helper₃ (later x) (suc n , x-nRy) =\n laterˡ (helper₃ (♭ x) (n , x-nRy))\n\n sound : ∀ x y → x R y → x ≋ y\n sound (now x) y nxRy = helper₁ y $ match-now (left bisim) nxRy\n sound (later x) (now y) lxRny =\n sym $ helper₁ (later x) $ match-now (right bisim) lxRny\n sound (later x) (later y) lxRly\n with match-later (left bisim) lxRly\n ... | (suc n , xRy-n) = later (♯ helper₂ (♭ y) (n , xRy-n))\n ... | (zero , xRly) with match-later (right bisim) xRly\n ... | (zero , xRy) = later (♯ sound _ _ xRy)\n ... | (suc n , x-1+nRy) =\n later (♯ helper₃ (♭ x) (n , x-1+nRy))\n\n sound : ∀ {x y} → x ≈ y → x ≋ y\n sound x≈y = Sound.sound x≈y _ _ (_≈_.xRy x≈y)\n\n-- Note that the problem illustrated in ExtendedWeakEquality is\n-- related to the problem of weak bisimulation up to weak\n-- bisimilarity. Let R be a relation which is only inhabited for the\n-- pair (later (♯ x), later (♯ y)). R is a weak bisimulation up to\n-- weak bisimilarity (_≈_):\n--\n-- later (♯ x) R later (♯ y)\n-- ↓ =\n-- x ≈ later (♯ x) R later (♯ y)\n--\n-- later (♯ x) R later (♯ y)\n-- = ↓\n-- later (♯ x) R later (♯ y) ≈ y\n--\n-- Weak bisimilarity is transitive, so if every relation which is a\n-- weak bisimulation up to weak bisimilarity were contained in weak\n-- bisimilarity we would have x ≈ y for all x and y.\n", "meta": {"hexsha": "350814524508fa3bb8525d4307be46263dbc1cbf", "size": 11591, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "AdmissibleButNotPostulable.agda", "max_stars_repo_name": "nad/codata", "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_issues_repo_path": "AdmissibleButNotPostulable.agda", "max_issues_repo_name": "nad/codata", "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": "AdmissibleButNotPostulable.agda", "max_forks_repo_name": "nad/codata", "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": 34.6, "max_line_length": 86, "alphanum_fraction": 0.4868432404, "num_tokens": 4855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081925, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.3536892001815727}} {"text": "module OlderBasicILP.Indirect.Gentzen where\n\nopen import OlderBasicILP.Indirect public\n\n\n-- Derivations, as Gentzen-style natural deduction trees.\n\nmutual\n data Tm : Set where\n VAR : ℕ → Tm\n LAM : Tm → Tm\n APP : Tm → Tm → Tm\n MULTIBOX : Cx Tm → Tm → Tm\n DOWN : Tm → Tm\n PAIR : Tm → Tm → Tm\n FST : Tm → Tm\n SND : Tm → Tm\n UNIT : Tm\n\n infix 3 _⊢_\n data _⊢_ (Γ : Cx (Ty Tm)) : Ty Tm → Set where\n var : ∀ {A} → A ∈ Γ → Γ ⊢ A\n lam : ∀ {A B} → Γ , A ⊢ B → Γ ⊢ A ▻ B\n app : ∀ {A B} → Γ ⊢ A ▻ B → Γ ⊢ A → Γ ⊢ B\n multibox : ∀ {n A} {SS : VCx Tm n} {Ξ : VCx (Ty Tm) n}\n → Γ ⊢⋆ SS ⦂⋆ Ξ → (u : SS ⦂⋆ Ξ ⊢ A)\n → Γ ⊢ [ u ] ⦂ A\n down : ∀ {A T} → Γ ⊢ T ⦂ A → Γ ⊢ A\n pair : ∀ {A B} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B\n fst : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ A\n snd : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ B\n unit : Γ ⊢ ⊤\n\n infix 3 _⊢⋆_\n _⊢⋆_ : Cx (Ty Tm) → Cx (Ty Tm) → Set\n Γ ⊢⋆ ∅ = 𝟙\n Γ ⊢⋆ Ξ , A = Γ ⊢⋆ Ξ × Γ ⊢ A\n\n [_] : ∀ {A Γ} → Γ ⊢ A → Tm\n [ var i ] = VAR [ i ]ⁱ\n [ lam t ] = LAM [ t ]\n [ app t u ] = APP [ t ] [ u ]\n [ multibox ts u ] = MULTIBOX [ ts ]⋆ [ u ]\n [ down t ] = DOWN [ t ]\n [ pair t u ] = PAIR [ t ] [ u ]\n [ fst t ] = FST [ t ]\n [ snd t ] = SND [ t ]\n [ unit ] = UNIT\n\n [_]⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Cx Tm\n [_]⋆ {∅} ∙ = ∅\n [_]⋆ {Ξ , A} (ts , t) = [ ts ]⋆ , [ t ]\n\n\n-- Monotonicity with respect to context inclusion.\n\nmutual\n mono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A\n mono⊢ η (var i) = var (mono∈ η i)\n mono⊢ η (lam t) = lam (mono⊢ (keep η) t)\n mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)\n mono⊢ η (multibox ts u) = multibox (mono⊢⋆ η ts) u\n mono⊢ η (down t) = down (mono⊢ η t)\n mono⊢ η (pair t u) = pair (mono⊢ η t) (mono⊢ η u)\n mono⊢ η (fst t) = fst (mono⊢ η t)\n mono⊢ η (snd t) = snd (mono⊢ η t)\n mono⊢ η unit = unit\n\n mono⊢⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ Ξ → Γ′ ⊢⋆ Ξ\n mono⊢⋆ {∅} η ∙ = ∙\n mono⊢⋆ {Ξ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t\n\n\n-- Shorthand for variables.\n\nV₀ : Tm\nV₀ = VAR 0\n\nV₁ : Tm\nV₁ = VAR 1\n\nV₂ : Tm\nV₂ = VAR 2\n\nv₀ : ∀ {A Γ} → Γ , A ⊢ A\nv₀ = var i₀\n\nv₁ : ∀ {A B Γ} → (Γ , A) , B ⊢ A\nv₁ = var i₁\n\nv₂ : ∀ {A B C Γ} → ((Γ , A) , B) , C ⊢ A\nv₂ = var i₂\n\n\n-- Reflexivity.\n\nrefl⊢⋆ : ∀ {Γ} → Γ ⊢⋆ Γ\nrefl⊢⋆ {∅} = ∙\nrefl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀\n\n\n-- Deduction theorem is built-in.\n\n-- Detachment theorem.\n\nDET : Tm → Tm\nDET T = APP T V₀\n\ndet : ∀ {A B Γ} → Γ ⊢ A ▻ B → Γ , A ⊢ B\ndet t = app (mono⊢ weak⊆ t) v₀\n\n\n-- Cut and multicut.\n\nCUT : Tm → Tm → Tm\nCUT T U = APP (LAM U) T\n\nMULTICUT : Cx Tm → Tm → Tm\nMULTICUT ∅ U = U\nMULTICUT (TS , T) U = APP (MULTICUT TS (LAM U)) T\n\ncut : ∀ {A B Γ} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B\ncut t u = app (lam u) t\n\nmulticut : ∀ {Ξ A Γ} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A\nmulticut {∅} ∙ u = mono⊢ bot⊆ u\nmulticut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t\n\n\n-- Transitivity.\n\ntrans⊢⋆ : ∀ {Γ″ Γ′ Γ} → Γ ⊢⋆ Γ′ → Γ′ ⊢⋆ Γ″ → Γ ⊢⋆ Γ″\ntrans⊢⋆ {∅} ts ∙ = ∙\ntrans⊢⋆ {Γ″ , A} ts (us , u) = trans⊢⋆ ts us , multicut ts u\n\n\n-- Contraction.\n\nCCONT : Tm\nCCONT = LAM (LAM (APP (APP V₁ V₀) V₀))\n\nCONT : Tm → Tm\nCONT T = DET (APP CCONT (LAM (LAM T)))\n\nccont : ∀ {A B Γ} → Γ ⊢ (A ▻ A ▻ B) ▻ A ▻ B\nccont = lam (lam (app (app v₁ v₀) v₀))\n\ncont : ∀ {A B Γ} → Γ , A , A ⊢ B → Γ , A ⊢ B\ncont t = det (app ccont (lam (lam t)))\n\n\n-- Exchange, or Schönfinkel’s C combinator.\n\nCEXCH : Tm\nCEXCH = LAM (LAM (LAM (APP (APP V₂ V₀) V₁)))\n\nEXCH : Tm → Tm\nEXCH T = DET (DET (APP CEXCH (LAM (LAM T))))\n\ncexch : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C\ncexch = lam (lam (lam (app (app v₂ v₀) v₁)))\n\nexch : ∀ {A B C Γ} → Γ , A , B ⊢ C → Γ , B , A ⊢ C\nexch t = det (det (app cexch (lam (lam t))))\n\n\n-- Composition, or Schönfinkel’s B combinator.\n\nCCOMP : Tm\nCCOMP = LAM (LAM (LAM (APP V₂ (APP V₁ V₀))))\n\nCOMP : Tm → Tm → Tm\nCOMP T U = DET (APP (APP CCOMP (LAM T)) (LAM U))\n\nccomp : ∀ {A B C Γ} → Γ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C\nccomp = lam (lam (lam (app v₂ (app v₁ v₀))))\n\ncomp : ∀ {A B C Γ} → Γ , B ⊢ C → Γ , A ⊢ B → Γ , A ⊢ C\ncomp t u = det (app (app ccomp (lam t)) (lam u))\n\n\n-- Useful theorems in functional form.\n\nDIST : Tm → Tm → Tm\nDIST T U = MULTIBOX ((∅ , T) , U) (APP (DOWN V₁) (DOWN V₀))\n\nUP : Tm → Tm\nUP T = MULTIBOX (∅ , T) V₀\n\nDISTUP : Tm → Tm → Tm\nDISTUP T U = DIST T (UP U)\n\nBOX : Tm → Tm\nBOX T = MULTIBOX ∅ T\n\nUNBOX : Tm → Tm → Tm\nUNBOX T U = APP (LAM U) T\n\ndist : ∀ {A B T U Γ}\n → (t : Γ ⊢ T ⦂ (A ▻ B)) → (u : Γ ⊢ U ⦂ A)\n → Γ ⊢ APP (DOWN V₁) (DOWN V₀) ⦂ B\ndist t u = multibox ((∙ , t) , u) (app (down v₁) (down v₀))\n\nup : ∀ {A T Γ}\n → Γ ⊢ T ⦂ A\n → Γ ⊢ V₀ ⦂ T ⦂ A\nup t = multibox (∙ , t) v₀\n\ndistup : ∀ {A B T U Γ}\n → (t : Γ ⊢ T ⦂ (U ⦂ A ▻ B)) → (u : Γ ⊢ U ⦂ A)\n → Γ ⊢ APP (DOWN V₁) (DOWN V₀) ⦂ B\ndistup t u = dist t (up u)\n\nbox : ∀ {A Γ}\n → (t : ∅ ⊢ A)\n → Γ ⊢ [ t ] ⦂ A\nbox t = multibox ∙ t\n\nunbox : ∀ {A C T U Γ}\n → Γ ⊢ T ⦂ A → Γ , T ⦂ A ⊢ U ⦂ C\n → Γ ⊢ U ⦂ C\nunbox t u = app (lam u) t\n\n\n-- Useful theorems in combinatory form.\n\nCI : Tm\nCI = LAM V₀\n\nCK : Tm\nCK = LAM (LAM V₁)\n\nCS : Tm\nCS = LAM (LAM (LAM (APP (APP V₂ V₀) (APP V₁ V₀))))\n\nCDIST : Tm\nCDIST = LAM (LAM (DIST V₁ V₀))\n\nCUP : Tm\nCUP = LAM (UP V₀)\n\nCDOWN : Tm\nCDOWN = LAM (DOWN V₀)\n\nCDISTUP : Tm\nCDISTUP = LAM (LAM (DIST V₁ (UP V₀)))\n\nCUNBOX : Tm\nCUNBOX = LAM (LAM (APP V₀ V₁))\n\nCPAIR : Tm\nCPAIR = LAM (LAM (PAIR V₁ V₀))\n\nCFST : Tm\nCFST = LAM (FST V₀)\n\nCSND : Tm\nCSND = LAM (SND V₀)\n\nci : ∀ {A Γ} → Γ ⊢ A ▻ A\nci = lam v₀\n\nck : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A\nck = lam (lam v₁)\n\ncs : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C\ncs = lam (lam (lam (app (app v₂ v₀) (app v₁ v₀))))\n\ncdist : ∀ {A B T U Γ}\n → Γ ⊢ T ⦂ (A ▻ B) ▻ U ⦂ A ▻ APP (DOWN V₁) (DOWN V₀) ⦂ B\ncdist = lam (lam (dist v₁ v₀))\n\ncup : ∀ {A T Γ} → Γ ⊢ T ⦂ A ▻ V₀ ⦂ T ⦂ A\ncup = lam (up v₀)\n\ncdown : ∀ {A T Γ} → Γ ⊢ T ⦂ A ▻ A\ncdown = lam (down v₀)\n\ncdistup : ∀ {A B T U Γ}\n → Γ ⊢ T ⦂ (U ⦂ A ▻ B) ▻ U ⦂ A ▻ APP (DOWN V₁) (DOWN V₀) ⦂ B\ncdistup = lam (lam (dist v₁ (up v₀)))\n\ncunbox : ∀ {A C T Γ} → Γ ⊢ T ⦂ A ▻ (T ⦂ A ▻ C) ▻ C\ncunbox = lam (lam (app v₀ v₁))\n\ncpair : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A ∧ B\ncpair = lam (lam (pair v₁ v₀))\n\ncfst : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ A\ncfst = lam (fst v₀)\n\ncsnd : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ B\ncsnd = lam (snd v₀)\n\n\n-- Closure under context concatenation.\n\nconcat : ∀ {A B Γ} Γ′ → Γ , A ⊢ B → Γ′ ⊢ A → Γ ⧺ Γ′ ⊢ B\nconcat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)\n\n\n-- Substitution.\n\nmutual\n [_≔_]_ : ∀ {A B Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢ B → Γ ∖ i ⊢ B\n [ i ≔ s ] var j with i ≟∈ j\n [ i ≔ s ] var .i | same = s\n [ i ≔ s ] var ._ | diff j = var j\n [ i ≔ s ] lam t = lam ([ pop i ≔ mono⊢ weak⊆ s ] t)\n [ i ≔ s ] app t u = app ([ i ≔ s ] t) ([ i ≔ s ] u)\n [ i ≔ s ] multibox ts u = multibox ([ i ≔ s ]⋆ ts) u\n [ i ≔ s ] down t = down ([ i ≔ s ] t)\n [ i ≔ s ] pair t u = pair ([ i ≔ s ] t) ([ i ≔ s ] u)\n [ i ≔ s ] fst t = fst ([ i ≔ s ] t)\n [ i ≔ s ] snd t = snd ([ i ≔ s ] t)\n [ i ≔ s ] unit = unit\n\n [_≔_]⋆_ : ∀ {Ξ A Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢⋆ Ξ → Γ ∖ i ⊢⋆ Ξ\n [_≔_]⋆_ {∅} i s ∙ = ∙\n [_≔_]⋆_ {Ξ , B} i s (ts , t) = [ i ≔ s ]⋆ ts , [ i ≔ s ] t\n", "meta": {"hexsha": "bd6feb6296792fb54f9f028e81231893fe180609", "size": 7357, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "OlderBasicILP/Indirect/Gentzen.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": "OlderBasicILP/Indirect/Gentzen.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": "OlderBasicILP/Indirect/Gentzen.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": 22.9190031153, "max_line_length": 69, "alphanum_fraction": 0.426804404, "num_tokens": 3778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6334102775181399, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.3536500564278385}} {"text": "{-# OPTIONS --rewriting --prop --confluence-check #-}\n\nopen import Agda.Primitive\nopen import Agda.Builtin.Bool\nopen import Agda.Builtin.Nat\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Equality\nopen import Agda.Builtin.Equality.Rewrite\nopen import Agda.Builtin.Sigma\nopen import Agda.Builtin.Unit\nopen import Data.Vec.Base\nopen import Data.Bool\nopen import Data.Sum\n\n-- sigma type in Prop used to handle telescopes. \n\nrecord Tel {a b} (A : Prop a) (B : A → Prop b) : Prop (a ⊔ b) where\n constructor _,_\n field\n fstC : A\n sndC : B fstC\n\nopen Tel public\n\ninfixr 4 _,_\n\nrecord ΣCov {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where\n constructor _,_\n field\n fstCov : A\n sndCov : B fstCov\n\nopen ΣCov public\n\nrecord prod {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where\n constructor _,_\n field\n fstprod : A\n sndprod : B \n\nopen prod public\n\n\nvariable ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level\n\n-- a bit of boilerplate to deal with Prop\n\ndata ⊥ : Prop where\n\nrecord ⊤P : Prop ℓ where\n constructor ttP\n\nrecord Box (A : Prop ℓ) : Set ℓ where\n constructor box\n field\n unbox : A\n\nopen Box public\n\n_×_ : ∀ (A : Prop ℓ) (B : Prop ℓ₁) → Prop (ℓ ⊔ ℓ₁)\nA × B = Tel A (λ _ → B)\n\n-- we need this for cumulativity\n\nrecord i (A : Prop ℓ) : Prop (ℓ ⊔ ℓ₁) where\n constructor inj\n field\n uninj : A\n\nopen i public\n\nrecord iS (A : Set ℓ) : Set (ℓ ⊔ ℓ₁) where\n constructor inj\n field\n uninj : A\n\nopen iS public\n\n{- \n Axiomatisation of Id, Id-refl, transport (for proposition), cast \n\n Note that Id-refl, transport are axioms in Prop, \n so we don't need to give them a computation content. \n\n Also transport-refl is useless for transport on Prop\n-}\n\npostulate Id : (A : Set ℓ) → A → A → Prop ℓ\n\npostulate cast : (A B : Set ℓ) (e : Id (Set ℓ) A B) → A → B \n\npostulate Id-refl : {A : Set ℓ} (x : A) → Id A x x\n\npostulate cast-refl : {A : Set ℓ} (e : Id _ A A) (a : A) → Id A (cast A A e a) a\n\npostulate transport : {A : Set ℓ} (P : A → Prop ℓ₁) (x : A) (t : P x) (y : A) (e : Id A x y) → P y\n\n-- cast-refl' : {A : Set ℓ} (e : Id (Set ℓ) A A) (a : A) → Id A (cast A A e a) a\n-- cast-refl' {A = A} e a = transport (λ z → Id A z a) {!!} (Id-refl a) {!!} {!!}\n\n-- direct derived functions \n\nap : {A : Set ℓ} {B : Set ℓ₁} {x y : A} (f : A → B) (e : Id A x y) →\n Id B (f x) (f y)\nap {ℓ} {ℓ₁} {A} {B} {x} {y} f e = transport (λ z → Id B (f x) (f z)) x (Id-refl _) y e\n\ntransport-Id : {A : Set ℓ} (P : A → Set ℓ₁) (x : A) (t : P x) (y : A) (e : Id A x y) → P y\ntransport-Id P x t y e = cast (P x) (P y) (ap P e) t\n\ntransport-refl : {A : Set ℓ} (P : A → Set ℓ₁) (x : A) (t : P x) (e : Id A x x) → Id _ (transport-Id P x t x e) t\ntransport-refl P x t e = cast-refl (ap P e) t\n\n\ninverse : (A : Set ℓ) {x y : A} (p : Id {ℓ} A x y) → Id A y x\ninverse A {x} {y} p = transport (λ z → Id A z x) x (Id-refl x) y p\n\nconcatId : (A : Set ℓ) {x y z : A} (p : Id {ℓ} A x y)\n (q : Id {ℓ} A y z) → Id A x z\nconcatId A {x} {y} {z} p q = transport (λ t → Id A x t) y p z q\n\n-- we now state rewrite rules for the identity type\n\npostulate Id-Pi : (A : Set ℓ) (B : A → Set ℓ₁) (f g : (a : A) → B a) →\n Id ((a : A) → B a) f g ≡ ((a : A) → Id (B a) (f a) (g a))\n\n{-# REWRITE Id-Pi #-}\n\n-- rewrite rules on Id-refl are not needed because it is in Prop\n\nrefl-Pi : (A : Set ℓ) (B : A → Set ℓ₁) (f : (a : A) → B a) →\n box (Id-refl f) ≡ box (λ a → Id-refl (f a))\nrefl-Pi A B f = refl\n\n-- sanity check for funext\n\nfunext : (A : Set ℓ) (B : A → Set ℓ₁) (f g : (a : A) → B a) →\n ((a : A) → Id (B a) (f a) (g a)) → Id ((a : A) → B a) f g \nfunext A B f g e = e\n\n\n\npostulate Id-Sigma : (A : Set ℓ) (B : A → Set ℓ₁) (a a' : A)\n (b : B a) (b' : B a') → \n Id (Σ A B) (a , b) (a' , b') ≡\n Tel (Id A a a')\n (λ e → Id (B a') (transport-Id B a b a' e) b')\n\n{-# REWRITE Id-Sigma #-}\n\npostulate Id-SigmaCov : (A : Set ℓ) (B : A → Set ℓ₁) (a a' : A)\n (b : B a) (b' : B a') → \n Id (ΣCov A B) (a , b) (a' , b') ≡\n Tel (Id A a a')\n (λ e → Id (B a) b (transport-Id B a' b' a (inverse A e)))\n\n{-# REWRITE Id-SigmaCov #-}\n\npostulate Id-prod : (A : Set ℓ) (B : Set ℓ₁) (a a' : A)\n (b b' : B) → \n Id (prod A B) (a , b) (a' , b') ≡\n (Id A a a') × (Id B b b')\n\n{-# REWRITE Id-prod #-}\n\npostulate Id-Box : (A : Prop ℓ) (p q : A) → Id (Box A) (box p) (box q) ≡ ⊤P\n\n{-# REWRITE Id-Box #-}\n\npostulate Id-Unit : (p q : ⊤) → Id ⊤ p q ≡ ⊤P\n\n{-# REWRITE Id-Unit #-}\n\npostulate Id-list-nil-nil : (A : Set ℓ) →\n Id (List A) [] [] ≡ ⊤P\n\n-- postulate Id-list-nil-cons : (A : Set ℓ) (a' : A) (l' : List A) →\n-- Id (List A) [] (a' ∷ l') ≡ i ⊥\n\n-- postulate Id-list-cons-nil : (A : Set ℓ) (a : A) (l : List A) →\n-- Id (List A) (a ∷ l) [] ≡ i ⊥\n\npostulate Id-list-cons-cons : (A : Set ℓ) (a a' : A) (l l' : List A) →\n Id (List A) (a ∷ l) (a' ∷ l') ≡\n Id A a a' × Id (List A) l l'\n\n{-# REWRITE Id-list-nil-nil #-}\n{-# REWRITE Id-list-cons-cons #-}\n\npostulate Id-nat-zero-zero : Id Nat 0 0 ≡ ⊤P\n\n-- postulate Id-nat-zero-suc : (n : Nat) →\n-- Id Nat 0 (suc n) ≡ i ⊥\n\n-- postulate Id-nat-suc-zero : (n : Nat) →\n-- Id Nat (suc n) zero ≡ i ⊥\n\npostulate Id-nat-suc-suc : (n n' : Nat) →\n Id Nat (suc n) (suc n') ≡\n Id Nat n n'\n\n{-# REWRITE Id-nat-zero-zero #-}\n{-# REWRITE Id-nat-suc-suc #-}\n\npostulate Id-bool-true-true : Id Bool true true ≡ ⊤P\npostulate Id-bool-false-false : Id Bool false false ≡ ⊤P\n\n{-# REWRITE Id-bool-true-true #-}\n{-# REWRITE Id-bool-false-false #-}\n\npostulate Id-sum-inj₁-inj₁ : (A : Set ℓ) (B : Set ℓ₁) (a a' : A) →\n Id (A ⊎ B) (inj₁ a) (inj₁ a') ≡\n i {ℓ = ℓ} {ℓ₁ = ℓ₁} (Id A a a')\n\npostulate Id-sum-inj₂-inj₂ : (A : Set ℓ) (B : Set ℓ₁) (b b' : B) →\n Id (A ⊎ B) (inj₂ b) (inj₂ b') ≡\n i {ℓ = ℓ₁} {ℓ₁ = ℓ} (Id B b b')\n\n{-# REWRITE Id-sum-inj₁-inj₁ #-}\n{-# REWRITE Id-sum-inj₂-inj₂ #-}\n\n-- rewrite rules for the identity type on the universe\n\ntelescope-Sigma : Set (lsuc (ℓ ⊔ ℓ₁))\ntelescope-Sigma {ℓ} {ℓ₁} = ΣCov (Set ℓ) (λ A → A → Set ℓ₁)\n\npostulate Id-Type-Sigma : (A A' : Set ℓ) (B : A → Set ℓ₁) (B' : A' → Set ℓ₁) →\n Id (Set (ℓ ⊔ ℓ₁)) (Σ A B) (Σ A' B') ≡\n Id telescope-Sigma (A , B) (A' , B')\n\n{-# REWRITE Id-Type-Sigma #-}\n\ntelescope-Forall : Set (lsuc (ℓ ⊔ ℓ₁))\ntelescope-Forall {ℓ} {ℓ₁} = Σ (Set ℓ) (λ A → A → Set ℓ₁)\n\npostulate Id-Type-Pi : (A A' : Set ℓ) (B : A → Set ℓ₁) (B' : A' → Set ℓ₁) →\n Id (Set (ℓ ⊔ ℓ₁)) ((a : A) → B a) ((a' : A') → B' a') ≡\n Id telescope-Forall (A , B) (A' , B')\n\n{-# REWRITE Id-Type-Pi #-}\n\n\ntelescope-Sum : Set (lsuc (ℓ ⊔ ℓ₁))\ntelescope-Sum {ℓ} {ℓ₁} = Σ (Set ℓ) (λ _ → Set ℓ₁)\n\npostulate Id-Type-Sum : (A A' : Set ℓ) (B B' : Set ℓ₁) →\n Id (Set (ℓ ⊔ ℓ₁)) (A ⊎ B) (A' ⊎ B') ≡\n Id telescope-Sum (A , B) (A' , B')\n\n{-# REWRITE Id-Type-Sum #-}\n\npostulate Id-Type-prod : (A A' : Set ℓ) (B B' : Set ℓ₁) →\n Id (Set (ℓ ⊔ ℓ₁)) (prod A B) (prod A' B') ≡\n Id telescope-Sum (A , B) (A' , B')\n\n{-# REWRITE Id-Type-prod #-}\n\n\ntelescope-List : Set (lsuc ℓ)\ntelescope-List {ℓ} = Set ℓ\n\npostulate Id-Type-List : (A A' : Set ℓ) →\n Id (Set ℓ) (List A) (List A') ≡\n Id telescope-List A A'\n\n{-# REWRITE Id-Type-List #-}\n\npostulate Id-Type-Unit : Id Set ⊤ ⊤ ≡ ⊤P\n \n{-# REWRITE Id-Type-Unit #-}\n\npostulate Id-Type-Nat : Id Set Nat Nat ≡ Id Set ⊤ ⊤\n \n{-# REWRITE Id-Type-Nat #-}\n\npostulate Id-Type-Bool : Id Set Bool Bool ≡ Id Set ⊤ ⊤\n \n{-# REWRITE Id-Type-Bool #-}\n\ntelescope-Box : Set (lsuc ℓ)\ntelescope-Box {ℓ} = Prop ℓ\n\npostulate Id-Type-Box : (P P' : Prop ℓ) → Id (Set ℓ) (Box P) (Box P') ≡ Id telescope-Box P P'\n \n{-# REWRITE Id-Type-Box #-}\n\n-- rewrite rules for the identity type on Prop : Prop ext modulo cumul \n\npostulate Id-prop : (P Q : Prop ℓ) → Id (Prop ℓ) P Q ≡ i (P → Q) × (Q → P)\n\n{-# REWRITE Id-prop #-}\n\n\npostulate Id-set : Id (Set (lsuc ℓ₁)) (Set ℓ₁) (Set ℓ₁) ≡ ⊤P\n\n{-# REWRITE Id-set #-}\n\n\n-- non-diagonal cases\n\n{- There are n^2 cases, that's a pain, this is not exhaustive for the moment -}\n\npostulate Id-set-nat : Id _ (Set ℓ) (iS Nat) ≡ i ⊥\npostulate Id-nat-set : Id (Set (lsuc ℓ)) (iS Nat) (Set ℓ) ≡ i ⊥\npostulate Id-set-bool : Id _ (Set ℓ) (iS Bool) ≡ i ⊥\npostulate Id-bool-set : Id (Set (lsuc ℓ)) (iS Bool) (Set ℓ) ≡ i ⊥\npostulate Id-bool-nat : Id _ Bool Nat ≡ i ⊥\npostulate Id-nat-bool : Id _ Nat Bool ≡ i ⊥\npostulate Id-set-pi : (A : Set ℓ₁) (B : A → Set ℓ₂) → Id (Set (lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂)) (iS {lsuc ℓ} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Set ℓ))\n (iS {ℓ₁ ⊔ ℓ₂} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} ((a : A) → B a)) ≡ i ⊥\npostulate Id-pi-set : (A : Set ℓ₁) (B : A → Set ℓ₂) → Id (Set (lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂)) (iS {ℓ₁ ⊔ ℓ₂} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} ((a : A) → B a))\n (iS {lsuc ℓ} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Set ℓ)) ≡ i ⊥\npostulate Id-set-sigma : (A : Set ℓ₁) (B : A → Set ℓ₂) → Id (Set (lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂)) (iS {lsuc ℓ} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Set ℓ))\n (iS {ℓ₁ ⊔ ℓ₂} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Σ A B)) ≡ i ⊥\npostulate Id-sigma-set : (A : Set ℓ₁) (B : A → Set ℓ₂) → Id (Set (lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂)) (iS {ℓ₁ ⊔ ℓ₂} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Σ A B))\n (iS {lsuc ℓ} {lsuc ℓ ⊔ ℓ₁ ⊔ ℓ₂} (Set ℓ)) ≡ i ⊥\n\n{-# REWRITE Id-set-nat Id-nat-set Id-set-bool Id-bool-set Id-bool-nat Id-nat-bool Id-set-pi Id-pi-set Id-set-sigma Id-sigma-set #-}\n\n--- Contractibility of singletons and J can be defined\n\ncontr-sing : (A : Set ℓ) {x y : A} (p : Id {ℓ} A x y) →\n Id (Σ A (λ y → Box (Id A x y))) (x , box (Id-refl x)) (y , box p) \ncontr-sing A {x} {y} p = p , ttP\n\nJ : (A : Set ℓ) (x : A) (P : (y : A) → Id A x y → Prop ℓ₁) \n (t : P x (Id-refl x)) (y : A) (e : Id A x y) → P y e\nJ A x P t y e = transport (λ z → P (fst z) (unbox (snd z))) (x , box (Id-refl x)) t (y , box e) (contr-sing A e)\n\n-- tranporting back and forth is the identity\n\n-- cast-inv : (A B : Set ℓ) (e : Id _ A B) (a : A) →\n-- Id A (cast B A (inverse (Set ℓ) {x = A} {y = B} e) (cast A B e a)) a\n-- cast-inv {ℓ} A B e a = let e-refl = cast-refl (Id-refl A) a in\n-- let e-refl-cast = cast-refl (Id-refl A) (cast A A (Id-refl A) a) in\n-- J (Set ℓ) A (λ B e → Id A (cast B A (inverse (Set ℓ) {x = A} {y = B} e) (cast A B e a)) a)\n-- (concatId A e-refl-cast e-refl) B e\n\npostulate cast-set : (A : Set ℓ) (e : _) → cast (Set ℓ) (Set ℓ) e A ≡ A\n\n{-# REWRITE cast-set #-}\n\npostulate cast-prop : (A : Prop ℓ) (e : _) → cast (Prop ℓ) (Prop ℓ) e A ≡ A\n\n{-# REWRITE cast-prop #-}\n\npostulate cast-type-family : (A A' : Set ℓ) (f : (a : A) → Set ℓ₁) (e : _) →\n cast ((a : A) → Set ℓ₁) ((a' : A') → Set ℓ₁) e f ≡\n λ (a' : A') → let a = cast A' A (inverse (Set ℓ) {x = A} {y = A'} (fstC e)) a' in f a \n\n{-# REWRITE cast-type-family #-}\n\npostulate cast-Pi : (A A' : Set ℓ) (B : A → Set ℓ₁) (B' : A' → Set ℓ₁) (f : (a : A) → B a) (e : Id _ ((a : A) → B a) ((a' : A') → B' a')) →\n cast ((a : A) → B a) ((a' : A') → B' a') e f ≡\n λ (a' : A') → let a = cast A' A (inverse (Set ℓ) {x = A} {y = A'} (fstC e)) a' in\n cast _ _ (sndC e a') (f a)\n\n{-# REWRITE cast-Pi #-}\n\npostulate cast-Sigma : (A A' : Set ℓ) (B : A → Set ℓ₁) (B' : A' → Set ℓ₁) (x : A) (y : B x) (e : _) →\n let eA = fstC e in\n let x' = cast A A' eA x in \n let eB = sndC e x in\n cast (Σ A B) (Σ A' B') e (x , y) ≡\n (cast A A' eA x , cast (B x) (B' x') eB y)\n\n{-# REWRITE cast-Sigma #-}\n\npostulate cast-prod : (A A' : Set ℓ) (B B' : Set ℓ₁) (x : A) (y : B) (e : _) →\n let eA = fstC e in\n let eB = sndC e in\n cast (prod A B) (prod A' B') e (x , y) ≡\n (cast A A' eA x , cast B B' eB y)\n\n{-# REWRITE cast-prod #-}\n\npostulate cast-Sum-inj₁ : (A A' : Set ℓ) (B B' : Set ℓ₁) (a : A) (e : _) →\n let eA = fstC e in\n let eB = sndC e in\n cast (A ⊎ B) (A' ⊎ B') e (inj₁ a) ≡\n inj₁ (cast A A' eA a)\n\npostulate cast-Sum-inj₂ : (A A' : Set ℓ) (B B' : Set ℓ₁) (b : B) (e : _) →\n let eA = fstC e in\n let eB = sndC e in\n cast (A ⊎ B) (A' ⊎ B') e (inj₂ b) ≡\n inj₂ (cast B B' eB b)\n\n\n{-# REWRITE cast-Sum-inj₁ #-}\n{-# REWRITE cast-Sum-inj₂ #-}\n\n \npostulate cast-List-nil : (A A' : Set ℓ) (e : _) →\n cast (List A) (List A') e [] ≡ []\n\npostulate cast-List-cons : (A A' : Set ℓ) (e : _) (a : A) (l : List A) →\n cast (List A) (List A') e (a ∷ l) ≡\n cast A A' e a ∷ cast _ _ e l\n\n{-# REWRITE cast-List-nil #-}\n\n{-# REWRITE cast-List-cons #-}\n\n\npostulate cast-Nat : (e : _) (n : Nat) → cast Nat Nat e n ≡ n\n\n{-# REWRITE cast-Nat #-}\n\npostulate cast-Bool : (e : _) (b : Bool) → cast Bool Bool e b ≡ b\n\n{-# REWRITE cast-Bool #-}\n\npostulate cast-Unit : (e : _) (t : ⊤) → cast ⊤ ⊤ e t ≡ t\n\n{-# REWRITE cast-Unit #-}\n\npostulate cast-Box : (A A' : Prop ℓ) (a : A) (f : _) (g : _) →\n cast (Box A) (Box A') (f , g) (box a) ≡ box (uninj f a)\n\n{-# REWRITE cast-Box #-}\n\n-- sanity check on closed terms\n\nfoo : transport-Id (λ (T : Σ Set (λ A → Σ A (λ _ → A → Set))) → ((snd (snd T)) (fst (snd T))))\n (Nat , (0 , λ _ → Nat))\n 3\n (Nat , (0 , λ _ → Nat))\n (Id-refl {A = Σ Set (λ A → Σ A (λ _ → A → Set))} (Nat , (0 , λ _ → Nat)))\n ≡ 3\nfoo = refl\n\n\ntest-J-refl-on-closed-term : (X : Set ℓ) (x : X) →\n transport-Id (λ z → Σ ⊤ (λ z → ⊤)) x (tt , tt) x (Id-refl x) ≡ (tt , tt)\ntest-J-refl-on-closed-term X x = refl \n\n\n\n-- Quotient types\n\n{- \n Note that r s and t are not used in the definitions, they are just here\n to make sure the theory stays consistent, because postulating the quotient, \n we can derive them. In particular, with R = λ - - → ⊥, we would get\n a direct inconsistency using Id-refl\n-}\n\nrecord quotient-data ℓ : Set (lsuc ℓ) where\n constructor q-data\n field\n carrier : Set ℓ\n rel : carrier → carrier → Prop ℓ\n rel-refl : (x : carrier) → rel x x\n rel-sym : (x y : carrier) → rel x y → rel y x\n rel-trans : (x y z : carrier) → rel x y → rel y z → rel x z\n\nopen quotient-data public\n\npostulate Quotient : (Q : quotient-data ℓ) →\n Set ℓ\n\npostulate pi : {Q : quotient-data ℓ} →\n carrier Q → Quotient Q\n\ntelescope-Quotient : Set (lsuc ℓ)\ntelescope-Quotient {ℓ} = Σ (Set ℓ) (λ A → A → A → Prop ℓ)\n\npostulate Id-Quotient : (Q : quotient-data ℓ)\n (a a' : carrier Q) →\n Id (Quotient Q)\n (pi a) (pi a') ≡ rel Q a a'\n\n{-# REWRITE Id-Quotient #-}\n\npostulate Quotient-elim : (Q : quotient-data ℓ)\n (P : Quotient Q → Set ℓ₁) \n (p : (x : carrier Q) → P (pi x))\n (e : (x y : carrier Q) → (r : rel Q x y) →\n Id _ (transport-Id P (pi x) (p x) (pi y) r) (p y))\n (w : Quotient Q) → P w\n\npostulate Quotient-elim-red : (Q : quotient-data ℓ)\n (P : Quotient Q → Set ℓ₁) \n (p : (x : carrier Q) → P (pi x))\n (e : (x y : carrier Q) → (r : rel Q x y) →\n Id _ (transport-Id P (pi x) (p x) (pi y) r) (p y))\n (a : carrier Q) →\n Quotient-elim Q P p e (pi a)\n ≡ p a\n\n{-# REWRITE Quotient-elim-red #-}\n\npostulate Quotient-elim-prop : (Q : quotient-data ℓ)\n (P : Quotient Q → Prop ℓ₁) \n (p : (x : carrier Q) → P (pi x))\n (w : Quotient Q) → P w\n\n\npostulate Id-Type-Quotient : (Q Q' : quotient-data ℓ) →\n Id (Set ℓ) (Quotient Q) (Quotient Q')\n ≡\n Id telescope-Quotient (carrier Q , rel Q) (carrier Q' , rel Q')\n\n{-# REWRITE Id-Type-Quotient #-}\n\npostulate cast-Quotient : (Q Q' : quotient-data ℓ) \n (a : carrier Q) (e : _) →\n cast (Quotient Q) (Quotient Q') e (pi a) ≡\n pi (cast (carrier Q) (carrier Q') (fstC e) a)\n\n{-# REWRITE cast-Quotient #-}\n\n-- double induction principle\n\nQuotient-elim2-aux : (Q : quotient-data ℓ)\n (P : Quotient Q → Quotient Q → Set ℓ₁)\n (p : (x y : carrier Q) → P (pi x) (pi y))\n (e : (x x' y y' : carrier Q) → (Q-rel1 : rel Q x x') → (Q-rel2 : rel Q y y') →\n Id _ (transport-Id (P (pi x')) (pi y) (transport-Id (λ x → P x (pi y)) (pi x) (p x y) (pi x') Q-rel1) (pi y') Q-rel2) (p x' y')) (x : carrier Q) (w : Quotient Q) → P w (pi x)\nQuotient-elim2-aux Q P p e x = Quotient-elim Q (λ w → P w (pi x)) (λ y → p y x) (λ y y' r → let e-cst = e y y' x x r (rel-refl Q x) in transport (λ e → Id (P (pi y') (pi x))\n (e\n (cast (P (pi y) (pi x)) (P (pi y') (pi x)) (ap (λ y → P y (pi x)) r) (p y x)))\n (p y' x)) (cast (P (pi y') (pi x)) (P (pi y') (pi x)) (ap (P (pi y')) (rel-refl Q x)))\n e-cst (λ w → w) λ a → cast-refl {A = P (pi y') (pi x)} (Id-refl (P (pi y') (pi x))) a ) \n\nQuotient-elim2 : (Q : quotient-data ℓ)\n (P : Quotient Q → Quotient Q → Set ℓ₁)\n (p : (x y : carrier Q) → P (pi x) (pi y))\n (e : (x x' y y' : carrier Q) → (Q-rel1 : rel Q x x') → (Q-rel2 : rel Q y y') →\n Id _ (transport-Id (P (pi x')) (pi y) (transport-Id (λ x → P x (pi y)) (pi x) (p x y) (pi x') Q-rel1) (pi y') Q-rel2) (p x' y'))\n (w w' : Quotient Q) → P w w'\nQuotient-elim2 Q P p e w =\n Quotient-elim Q (P w) (λ x → Quotient-elim2-aux Q P p e x w)\n (λ x x' r → Quotient-elim-prop Q (λ w → Id (P w (pi x'))\n (transport-Id (P w) (pi x) (Quotient-elim2-aux Q P p e x w) (pi x') r)\n (Quotient-elim2-aux Q P p e x' w)) (λ y → let e-cst = e y y x x' (rel-refl Q y) r in\n transport (λ e → Id (P (pi y) (pi x'))\n (cast (P (pi y) (pi x)) (P (pi y) (pi x')) (ap (P (pi y)) r) (e (p y x)))\n (p y x')) (cast (P (pi y) (pi x)) (P (pi y) (pi x)) (ap (P (pi y)) (rel-refl Q x)))\n e-cst (λ w → w) λ a → cast-refl {A = P (pi y) (pi x)} (Id-refl (P (pi y) (pi x))) a ) w)\n\n\n\n{-\n-- Sanity Check: transport-refl on quotient type\n\ntransport-refl-Quotient : (X : Set ℓ)\n (carrier Q : X -> Set ℓ₁)\n (R : (x : X) → carrier Q x → carrier Q x → Prop ℓ₁)\n (r : (z : X) (x : carrier Q z) → R z x x)\n (s : (z : X) (x y : carrier Q z) → R z x y → R z y x)\n (t : (zz : X) (x y z : carrier Q zz) → R zz x y → R zz y z → R zz x z)\n (x : X) (q : Quotient (carrier Q x) (R x) (r x) (s x) (t x))\n (e : Id X x x) →\n Id _\n (transport-Id (λ x → Quotient (carrier Q x) (R x) (r x) (s x) (t x))\n x q x e)\n q\ntransport-refl-Quotient X carrier Q R r s t x q e =\n Quotient-elim-prop (carrier Q x) (R x) (r x) (s x) (t x)\n ((λ a → Id _ (transport-Id (λ (x : X) → Quotient (carrier Q x) (R x) (r x) (s x) (t x)) x a x e) a))\n (λ a → transport (λ a' → R x a' a) a (r x a) (cast (carrier Q x) (carrier Q x) _ a) (inverse (carrier Q x) (transport-refl carrier Q x a e)))\n q\n\n-}\n\n-- Now for Path\n\ntelescope-Path : Set (lsuc ℓ)\ntelescope-Path {ℓ} = Σ (Set ℓ) (λ A → prod A A)\n\npostulate Id-Path : (A : Set ℓ) (x : A) (y : A) (e e' : _)→\n Id (x ≡ y) e e' ≡ ⊤P\n\n{-# REWRITE Id-Path #-}\n\npostulate Id-Type-Path : (A A' : Set ℓ) (x y : A) (x' y' : A') →\n Id (Set ℓ) (x ≡ y) (x' ≡ y') ≡\n Id telescope-Path \n (A , (x , y))\n (A' , (x' , y' ))\n\n{-# REWRITE Id-Type-Path #-}\n\n-- not enough to get canonicity\n\n-- postulate cast-Path : (A A' : Set ℓ) (x : A) (x' : A') (e : _) →\n -- cast (x ≡ x) (x' ≡ x') e refl ≡ refl\n\n-- {-# REWRITE cast-Path #-}\n\ntransport-Path : {A : Set ℓ} (x : A) (P : (y : A) → Set ℓ₁) (t : P x) (y : A) (e : x ≡ y) → P y\ntransport-Path P x t y refl = t\n\ntransport-Path-refl : {A : Set ℓ} (P : A → Prop ℓ₁) (x : A) (t : P x) (y : A) (e : x ≡ y) → P y\ntransport-Path-refl P x t .x refl = t\n\n\npath-to-Id : {A : Set ℓ} {x y : A} → x ≡ y → Id A x y \npath-to-Id {ℓ} {A} {x} {y} = transport-Path-refl (Id A x) x (Id-refl x) y\n\n-- we treat cast X (a ≡ b) e x as a new constructor of equality\n\npostulate IdPath : {A : Set ℓ} {x y : A} → Id A x y → x ≡ y\n\npostulate transport-Path-cast-refl : {A B : Set ℓ} (a : A) (b b' : B) (e : Id (Set ℓ) (a ≡ a) (b ≡ b')) → \n cast (a ≡ a) (b ≡ b') e refl ≡\n IdPath ( let X = fstC (sndC e) in let Y = sndC (sndC e) in concatId B (inverse B X) Y)\n\n{-# REWRITE transport-Path-cast-refl #-}\n\npostulate transport-Path-IdPath : {A : Set ℓ} (x : A) (P : (y : A) → Set ℓ₁) (t : P x) (y : A) (e : Id A x y) →\n transport-Path x P t y (IdPath e) ≡ transport-Id P x t y e\n\n{-# REWRITE transport-Path-IdPath #-}\n\npostulate transport-Path-cast-IdPath : {A B : Set ℓ} (a a' : A) (b b' : B) (ea : Id A a a') (e : Id (Set ℓ) (a ≡ a') (b ≡ b')) → \n cast (a ≡ a') (b ≡ b') e (IdPath ea) ≡\n IdPath (concatId B (inverse B (fstC (sndC e)))\n (concatId B (ap (cast A B (fstC e)) ea) (sndC (sndC e))))\n\n{-# REWRITE transport-Path-cast-IdPath #-}\n\ntransport-refl-Path : {A : Set ℓ} (P : A → Set ℓ₁) (x : A) (t : P x) → transport-Path x P t x refl ≡ t\ntransport-refl-Path P x t = refl\n\nfunext-Path : (A : Set ℓ) (B : A → Set ℓ₁) (f g : (a : A) → B a) →\n ((a : A) → f a ≡ g a) → f ≡ g \nfunext-Path A B f g e = IdPath (λ a → path-to-Id (e a))\n\netaBool : (a : Bool) → a ≡ (if a then true else false)\netaBool true = refl\netaBool false = refl\n\neq_fun : (λ (b : Bool) → b) ≡ (λ (b : Bool) → if b then true else false)\neq_fun = funext-Path Bool (λ - → Bool) _ _ λ a → etaBool a\n\n-- standard boolean using equality\n\nstd-bool : Bool\nstd-bool = transport-Path (λ (b : Bool) → b) (λ f → Bool) true (λ (b : Bool) → if b then true else false) eq_fun\n\nsanity-check : std-bool ≡ true\nsanity-check = refl\n\n", "meta": {"hexsha": "c54027ed98195706bee262dcca64d930393d7ba5", "size": 23242, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "setoid_rr.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": "setoid_rr.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": "setoid_rr.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": 35.9783281734, "max_line_length": 202, "alphanum_fraction": 0.4591687462, "num_tokens": 8927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.5583269943353744, "lm_q1q2_score": 0.35365004870042543}} {"text": "open import Formalization.PredicateLogic.Signature\n\nmodule Formalization.PredicateLogic.Classical.Semantics.Homomorphism (𝔏 : Signature) where\nopen Signature(𝔏)\n\nimport Lvl\nopen import Data\nopen import Data.Boolean\nopen import Data.Boolean.Stmt\nopen import Data.ListSized\nopen import Data.ListSized.Functions\nopen import Formalization.PredicateLogic.Classical.Semantics(𝔏)\nopen import Formalization.PredicateLogic.Syntax(𝔏)\nopen import Functional using (_∘_ ; _∘₂_ ; _←_)\nopen import Logic.Propositional as Logic using (_↔_)\nimport Logic.Predicate as Logic\nopen import Numeral.Finite\nopen import Numeral.Finite.Bound\nopen import Numeral.Natural\nopen import Relator.Equals\nopen import Relator.Equals.Proofs.Equiv\nopen import Sets.PredicateSet using (PredSet)\nopen Sets.PredicateSet.BoundedQuantifiers\nopen import Structure.Function.Domain\nopen import Syntax.Function\nopen import Type.Dependent renaming (intro to _,_)\nopen import Type.Properties.Decidable\nopen import Type\n\nprivate variable ℓ ℓₘ ℓₘ₁ ℓₘ₂ ℓₑ : Lvl.Level\nprivate variable P : Type{ℓₚ}\nprivate variable args n vars : ℕ\nprivate variable 𝔐 : Model\n\nprivate variable A B C S : Model{ℓₘ}\nprivate variable fi : Obj n\nprivate variable ri : Prop n\nprivate variable xs : List(dom(S))(n)\n\nrecord Homomorphism (A : Model{ℓₘ₁}) (B : Model{ℓₘ₂}) (f : dom(A) → dom(B)) : Type{ℓₚ Lvl.⊔ ℓₒ Lvl.⊔ Lvl.of(Type.of A) Lvl.⊔ Lvl.of(Type.of B)} where\n field\n preserve-functions : ∀{xs} → (f(fn(A) fi xs) ≡ fn(B) fi (map f xs))\n preserve-relations : ∀{xs} → IsTrue(rel(A) ri xs) → IsTrue(rel(B) ri (map f xs))\n\n_→ₛₜᵣᵤ_ : Model{ℓₘ₁} → Model{ℓₘ₂} → Type\nA →ₛₜᵣᵤ B = Logic.∃(Homomorphism A B)\n\nrecord Embedding (A : Model{ℓₘ₁}) (B : Model{ℓₘ₂}) (f : dom(A) → dom(B)) : Type{ℓₚ Lvl.⊔ ℓₒ Lvl.⊔ Lvl.of(Type.of A) Lvl.⊔ Lvl.of(Type.of B)} where\n constructor intro\n field\n ⦃ homomorphism ⦄ : Homomorphism(A)(B)(f)\n ⦃ injection ⦄ : Injective(f)\n preserve-relations-converse : ∀{xs} → IsTrue(rel(A) ri xs) ← IsTrue(rel(B) ri (map f xs))\n\nopen import Data\nopen import Data.Boolean.Stmt\nopen import Data.ListSized.Proofs\nopen import Functional\nopen import Function.Equals\nopen import Function.Proofs\nopen import Lang.Instance\nopen import Logic.Predicate\nopen import Structure.Function\nopen import Structure.Operator\nopen import Structure.Relator.Properties\nopen import Structure.Relator\nopen import Syntax.Transitivity\n\nidₛₜᵣᵤ : A →ₛₜᵣᵤ A\n∃.witness idₛₜᵣᵤ = id\nHomomorphism.preserve-functions (∃.proof (idₛₜᵣᵤ {A = A})) {n} {fi} {xs} = congruence₁(fn A fi) (symmetry(_≡_) (_⊜_.proof map-id))\nHomomorphism.preserve-relations (∃.proof (idₛₜᵣᵤ {A = A})) {n} {ri} {xs} = substitute₁ₗ(IsTrue ∘ rel A ri) (_⊜_.proof map-id)\n\n_∘ₛₜᵣᵤ_ : let _ = A ; _ = B ; _ = C in (B →ₛₜᵣᵤ C) → (A →ₛₜᵣᵤ B) → (A →ₛₜᵣᵤ C)\n∃.witness (([∃]-intro f) ∘ₛₜᵣᵤ ([∃]-intro g)) = f ∘ g\nHomomorphism.preserve-functions (∃.proof (_∘ₛₜᵣᵤ_ {A = A} {B = B} {C = C} ([∃]-intro f ⦃ hom-f ⦄) ([∃]-intro g ⦃ hom-g ⦄))) {fi = fi} {xs} =\n congruence₁(f) (Homomorphism.preserve-functions hom-g)\n 🝖 Homomorphism.preserve-functions hom-f\n 🝖 congruence₁(fn C fi) (symmetry(_≡_) (_⊜_.proof (map-[∘] {f = f}{g = g}) {xs}))\nHomomorphism.preserve-relations (∃.proof (_∘ₛₜᵣᵤ_ {A = A} {B = B} {C = C} ([∃]-intro f ⦃ hom-f ⦄) ([∃]-intro g ⦃ hom-g ⦄))) {ri = ri} {xs} =\n substitute₁ₗ(IsTrue ∘ rel C ri) (_⊜_.proof map-[∘] {xs})\n ∘ Homomorphism.preserve-relations hom-f\n ∘ Homomorphism.preserve-relations hom-g\n\nimport Data.Tuple as Tuple\nopen import Function.Equals\nopen import Function.Equals.Proofs\nopen import Function.Inverse\nopen import Lang.Inspect\nopen import Logic.Predicate.Equiv\nopen import Structure.Category\nopen import Structure.Categorical.Properties\nopen import Structure.Function.Domain.Proofs\n\ninstance\n map-function : ∀{ℓ₁ ℓ₂}{A : Type{ℓ₁}}{B : Type{ℓ₂}} → Function ⦃ [⊜]-equiv ⦄ ⦃ [⊜]-equiv ⦄ (map{A = A}{B = B}{n = n})\n map-function {A = A}{B = B} = intro proof where\n proof : ∀{f g : A → B} → (f ⊜ g) → (map{n = n} f ⊜ map g)\n _⊜_.proof (proof p) {∅} = reflexivity(_≡_)\n _⊜_.proof (proof p) {x ⊰ l} = congruence₂(_⊰_) (_⊜_.proof p) (_⊜_.proof (proof p) {l})\n\ninstance\n Structure-Homomorphism-category : Category(_→ₛₜᵣᵤ_ {ℓₘ})\n Category._∘_ Structure-Homomorphism-category = _∘ₛₜᵣᵤ_\n Category.id Structure-Homomorphism-category = idₛₜᵣᵤ\n BinaryOperator.congruence (Category.binaryOperator Structure-Homomorphism-category) = [⊜][∘]-binaryOperator-raw\n _⊜_.proof (Morphism.Associativity.proof (Category.associativity Structure-Homomorphism-category) {_} {_} {_} {_} {[∃]-intro f} {[∃]-intro g} {[∃]-intro h}) {x} = reflexivity(_≡_) {f(g(h(x)))}\n _⊜_.proof (Morphism.Identityₗ.proof (Tuple.left (Category.identity Structure-Homomorphism-category)) {f = [∃]-intro f}) {x} = reflexivity(_≡_) {f(x)}\n _⊜_.proof (Morphism.Identityᵣ.proof (Tuple.right (Category.identity Structure-Homomorphism-category)) {f = [∃]-intro f}) {x} = reflexivity(_≡_) {f(x)}\n\nmodule _ {F@([∃]-intro f) : _→ₛₜᵣᵤ_ {ℓₘ}{ℓₘ} A B} where\n isomorphism-surjective-embedding : Morphism.Isomorphism ⦃ [≡∃]-equiv ⦃ [⊜]-equiv ⦄ ⦄ (\\{A} → _∘ₛₜᵣᵤ_ {A = A})(idₛₜᵣᵤ)(F) ↔ (Surjective(f) Logic.∧ Embedding(A)(B)(f))\n Tuple.left isomorphism-surjective-embedding (Logic.[∧]-intro surj embed) = [∃]-intro ([∃]-intro _ ⦃ hom ⦄) ⦃ Logic.[∧]-intro inverₗ inverᵣ ⦄ where\n f⁻¹ = invᵣ-surjective f ⦃ surj ⦄\n instance\n inver : Inverse(f)(f⁻¹)\n inver = Logic.[∧]-elimᵣ ([∃]-proof (bijective-to-invertible ⦃ bij = injective-surjective-to-bijective(f) ⦃ Embedding.injection embed ⦄ ⦃ surj ⦄ ⦄))\n\n instance\n hom : Homomorphism(B)(A)(f⁻¹)\n Homomorphism.preserve-functions hom {fi = fi} {xs = xs} =\n f⁻¹(fn B fi xs) 🝖[ _≡_ ]-[ congruence₁(f⁻¹) (congruence₁(fn B fi) (_⊜_.proof map-id)) ]-sym\n f⁻¹(fn B fi (map id xs)) 🝖[ _≡_ ]-[ congruence₁(f⁻¹) (congruence₁(fn B fi) (_⊜_.proof (congruence₁(map) (intro (Inverseᵣ.proof(Logic.[∧]-elimᵣ inver)))) {xs})) ]-sym\n f⁻¹(fn B fi (map (f ∘ f⁻¹) xs)) 🝖[ _≡_ ]-[ congruence₁(f⁻¹) (congruence₁(fn B fi) (_⊜_.proof map-[∘] {xs})) ]\n f⁻¹(fn B fi (map f (map f⁻¹ xs))) 🝖[ _≡_ ]-[ congruence₁(f⁻¹) (Homomorphism.preserve-functions (Embedding.homomorphism embed)) ]-sym\n f⁻¹(f(fn A fi (map f⁻¹ xs))) 🝖[ _≡_ ]-[ Inverseₗ.proof(Logic.[∧]-elimₗ inver) ]\n fn A fi (map f⁻¹ xs) 🝖-end\n\n Homomorphism.preserve-relations hom {ri = ri} {xs = xs} p = Embedding.preserve-relations-converse embed {xs = map f⁻¹ xs} (substitute₁(IsTrue ∘ rel B ri) (_⊜_.proof proof {xs}) p) where\n proof =\n id 🝖[ _⊜_ ]-[ map-id ]-sym\n map id 🝖[ _⊜_ ]-[ congruence₁(map) (intro (Inverseᵣ.proof(Logic.[∧]-elimᵣ inver))) ]-sym\n map(f ∘ f⁻¹) 🝖[ _⊜_ ]-[ map-[∘] ]\n (map f ∘ map f⁻¹) 🝖-end\n\n inverₗ : Morphism.Inverseₗ _ _ F ([∃]-intro f⁻¹)\n Morphism.Inverseₗ.proof inverₗ = intro(Inverseₗ.proof(Logic.[∧]-elimₗ inver))\n\n inverᵣ : Morphism.Inverseᵣ _ _ F ([∃]-intro f⁻¹)\n Morphism.Inverseᵣ.proof inverᵣ = intro(Inverseᵣ.proof(Logic.[∧]-elimᵣ inver))\n Tuple.right isomorphism-surjective-embedding iso = Logic.[∧]-intro infer (intro (\\{n}{ri}{xs} → {!proof!})) where\n instance\n bij : Bijective(f)\n instance\n inj : Injective(f)\n inj = bijective-to-injective(f)\n instance\n surj : Surjective(f)\n surj = bijective-to-surjective(f)\n proof : IsTrue(rel A ri xs) ← IsTrue(rel B ri (map f(xs)))\n proof p relation x = {!!}\n proof2 : let _ = (rel A ri xs) in Surjective(f)\n proof2 = {!!}\n-- (intro (proof {!!} {!!}))\n", "meta": {"hexsha": "eebe4b823c736662765ac666d152c33aef4620d7", "size": 7567, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Formalization/PredicateLogic/Classical/Semantics/Homomorphism.agda", "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_issues_repo_path": "Formalization/PredicateLogic/Classical/Semantics/Homomorphism.agda", "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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": "Formalization/PredicateLogic/Classical/Semantics/Homomorphism.agda", "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "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.8193548387, "max_line_length": 193, "alphanum_fraction": 0.6537597463, "num_tokens": 2977, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6513548782017745, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.35359664769104254}} {"text": "-- Hilbert-style formalisation of closed syntax.\n-- Sequences of terms.\n\nmodule OldBasicILP.Syntax.ClosedHilbertSequential where\n\nopen import OldBasicILP.Syntax.Common public\n\n\n-- Mutually-recursive declarations.\n\ndata Ty : Set\n\nrecord Proof (Ξ : Cx Ty) (A : Ty) : Set\n\ndata ⊢ᴰ_ : Cx Ty → Set\n\n_⧺ᴰ_ : ∀ {Ξ₁ Ξ₂} → ⊢ᴰ Ξ₁ → ⊢ᴰ Ξ₂ → ⊢ᴰ Ξ₁ ⧺ Ξ₂\n\n\n-- Types parametrised by closed derivations.\n\ninfixr 10 _⦂_\ninfixl 9 _∧_\ninfixr 7 _▻_\ndata Ty where\n α_ : Atom → Ty\n _▻_ : Ty → Ty → Ty\n _⦂_ : ∀ {Ξ A} → Proof Ξ A → Ty → Ty\n _∧_ : Ty → Ty → Ty\n ⊤ : Ty\n\n\n-- Anti-bug wrappers.\n\nrecord Proof (Ξ : Cx Ty) (A : Ty) where\n inductive\n constructor [_]\n field\n der : ⊢ᴰ Ξ , A\n\n\n-- More mutually-recursive declarations.\n\nappᴰ : ∀ {Ξ₁ Ξ₂ A B} → ⊢ᴰ Ξ₁ , A ▻ B → ⊢ᴰ Ξ₂ , A → ⊢ᴰ (Ξ₂ , A) ⧺ (Ξ₁ , A ▻ B) , B\n\nboxᴰ : ∀ {Ξ A} → (d : ⊢ᴰ Ξ , A) → ⊢ᴰ ∅ , [ d ] ⦂ A\n\n\n-- Derivations.\n\ninfix 3 ⊢ᴰ_\ndata ⊢ᴰ_ where\n nil : ⊢ᴰ ∅\n mp : ∀ {Ξ 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\n nec : ∀ {Ξ A} → ∀ {`Ξ} → (`d : ⊢ᴰ `Ξ , A)\n → ⊢ᴰ Ξ → ⊢ᴰ Ξ , [ `d ] ⦂ A\n\n cdist : ∀ {Ξ A B} → ∀ {`Ξ₁ `Ξ₂} → {`d₁ : ⊢ᴰ `Ξ₁ , A ▻ B} → {`d₂ : ⊢ᴰ `Ξ₂ , A}\n → ⊢ᴰ Ξ → ⊢ᴰ Ξ , [ `d₁ ] ⦂ (A ▻ B) ▻ [ `d₂ ] ⦂ A ▻ [ appᴰ `d₁ `d₂ ] ⦂ B\n\n cup : ∀ {Ξ A} → ∀ {`Ξ} → {`d : ⊢ᴰ `Ξ , A}\n → ⊢ᴰ Ξ → ⊢ᴰ Ξ , [ `d ] ⦂ A ▻ [ boxᴰ `d ] ⦂ [ `d ] ⦂ A\n\n cdown : ∀ {Ξ A} → ∀ {`Ξ} → {`d : ⊢ᴰ `Ξ , A}\n → ⊢ᴰ Ξ → ⊢ᴰ Ξ , [ `d ] ⦂ A ▻ A\n\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\n-- Anti-bug wrappers.\n\ninfix 3 ⊢_\n⊢_ : Ty → Set\n⊢ A = ∃ (λ Ξ → ⊢ᴰ Ξ , A)\n\n\n-- Concatenation of derivations.\n\nd₁ ⧺ᴰ nil = d₁\nd₁ ⧺ᴰ mp i j d₂ = mp (mono∈ weak⊆⧺₂ i) (mono∈ weak⊆⧺₂ j) (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ ci d₂ = ci (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ ck d₂ = ck (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ cs d₂ = cs (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ nec `d d₂ = nec `d (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ cdist d₂ = cdist (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ cup d₂ = cup (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ cdown d₂ = cdown (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ cpair d₂ = cpair (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ cfst d₂ = cfst (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ csnd d₂ = csnd (d₁ ⧺ᴰ d₂)\nd₁ ⧺ᴰ unit d₂ = unit (d₁ ⧺ᴰ d₂)\n\n\n-- Modus ponens and necessitation in nested form.\n\nappᴰ {Ξ₁} {Ξ₂} {A} {B} d₁ d₂ = mp top (mono∈ (weak⊆⧺₁ (Ξ₁ , A ▻ B)) top) (d₂ ⧺ᴰ d₁)\n\nboxᴰ {Ξ} {A} d = nec d nil\n\napp : ∀ {A B} → ⊢ A ▻ B → ⊢ A → ⊢ B\napp {A} {B} (Ξ₁ , d₁) (Ξ₂ , d₂) = Ξ₃ , d₃\n where Ξ₃ = (Ξ₂ , A) ⧺ (Ξ₁ , A ▻ B)\n d₃ = appᴰ d₁ d₂\n\nbox : ∀ {A} → (t : ⊢ A) → ⊢ [ π₂ t ] ⦂ A\nbox (Ξ , d) = ∅ , boxᴰ d\n", "meta": {"hexsha": "cac2c8f5ad6f10de8e51bf6a5e1ef8492a368b0b", "size": 2771, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "OldBasicILP/Syntax/ClosedHilbertSequential.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": "OldBasicILP/Syntax/ClosedHilbertSequential.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": "OldBasicILP/Syntax/ClosedHilbertSequential.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": 24.3070175439, "max_line_length": 92, "alphanum_fraction": 0.4323348971, "num_tokens": 1725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548646660543, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.35359664034299704}} {"text": "{-# OPTIONS --without-K --safe --overlapping-instances #-}\nmodule Interpreter where\n\nopen import Data.Char hiding (_≤_)\nopen import Data.Bool hiding (_≤_)\nopen import Data.Nat hiding (_≤_)\nopen import Data.Unit\nimport Data.Nat as N\nopen import Data.Product\nopen import Data.Sum\nopen import Relation.Binary.PropositionalEquality as PropEq\nopen import Relation.Nullary\nimport Data.String as Str\nopen import Data.Nat.Show\nimport Data.List as List\nopen import Data.Empty\n\ninfix 3 _:::_,_\ninfix 2 _∈_\n\ninfix 1 _⊢_\n\ndata `Set : Set where\n `ℕ : `Set\n `Bool : `Set\n _`⇨_ : `Set → `Set → `Set\n `⊤ : `Set\n _`×_ : `Set → `Set → `Set\n _`+_ : `Set → `Set → `Set\ninfixr 2 _`⇨_\n\ndata Var : Set where\n x' : Var\n y' : Var\n z' : Var\n\n-- Inequality proofs on variables\ndata _≠_ : Var → Var → Set where\n x≠y : x' ≠ y'\n x≠z : x' ≠ z'\n y≠x : y' ≠ x'\n y≠z : y' ≠ z'\n z≠x : z' ≠ x'\n z≠y : z' ≠ y'\n\n\n⟦_⟧ : `Set → Set\n⟦ `ℕ ⟧ = ℕ\n⟦ `Bool ⟧ = Bool\n⟦ (t `⇨ s) ⟧ = ⟦ t ⟧ → ⟦ s ⟧\n⟦ `⊤ ⟧ = ⊤\n⟦ (t `× s) ⟧ = ⟦ t ⟧ × ⟦ s ⟧\n⟦ (t `+ s) ⟧ = ⟦ t ⟧ ⊎ ⟦ s ⟧\n\ndata Γ : Set where\n · : Γ\n _:::_,_ : Var → `Set → Γ → Γ\n\ndata _∈_ : Var → Γ → Set where\n H : ∀ {x Δ t } → x ∈ x ::: t , Δ\n TH : ∀ {x y Δ t } → ⦃ prf : x ∈ Δ ⦄ → ⦃ neprf : x ≠ y ⦄ → x ∈ y ::: t , Δ\n\n!Γ_[_] : ∀ {x} → (Δ : Γ) → x ∈ Δ → `Set\n!Γ_[_] · ()\n!Γ _ ::: t , Δ [ H ] = t\n!Γ _ ::: _ , Δ [ TH ⦃ prf = i ⦄ ] = !Γ Δ [ i ]\n\ninfix 30 `v_\ninfix 30 `n_\ninfix 30 `¬_\n\ninfix 26 _`+_\ninfix 27 _`*_\ninfix 27 _`∧_\ninfix 26 _`∨_\ninfix 24 _`≤_\ninfix 24 _`,_\ninfixl 22 _`₋_\n\ndata _⊢_ : Γ → `Set → Set where\n `false : ∀ {Δ} → Δ ⊢ `Bool\n `true : ∀ {Δ} → Δ ⊢ `Bool\n `n_ : ∀ {Δ} → ℕ → Δ ⊢ `ℕ\n `v_ : ∀ {Δ} → (x : Var) → ⦃ i : x ∈ Δ ⦄ → Δ ⊢ !Γ Δ [ i ]\n _`₋_ : ∀ {Δ t s} → Δ ⊢ t `⇨ s → Δ ⊢ t → Δ ⊢ s --application\n `λ_`:_⇨_ : ∀ {Δ tr} → (x : Var) → (tx : `Set)\n → x ::: tx , Δ ⊢ tr → Δ ⊢ tx `⇨ tr\n _`+_ : ∀ {Δ} → Δ ⊢ `ℕ → Δ ⊢ `ℕ → Δ ⊢ `ℕ\n _`*_ : ∀ {Δ} → Δ ⊢ `ℕ → Δ ⊢ `ℕ → Δ ⊢ `ℕ\n _`∧_ : ∀ {Δ} → Δ ⊢ `Bool → Δ ⊢ `Bool → Δ ⊢ `Bool\n _`∨_ : ∀ {Δ} → Δ ⊢ `Bool → Δ ⊢ `Bool → Δ ⊢ `Bool\n _`≤_ : ∀ {Δ} → Δ ⊢ `ℕ → Δ ⊢ `ℕ → Δ ⊢ `Bool\n `¬_ : ∀ {Δ} → Δ ⊢ `Bool → Δ ⊢ `Bool\n _`,_ : ∀ {Δ t s} → Δ ⊢ t → Δ ⊢ s → Δ ⊢ t `× s\n `fst : ∀ {Δ t s} → Δ ⊢ t `× s → Δ ⊢ t\n `snd : ∀ {Δ t s} → Δ ⊢ t `× s → Δ ⊢ s\n `left : ∀ {Δ t s} → Δ ⊢ t → Δ ⊢ t `+ s\n `right : ∀ {Δ t s} → Δ ⊢ s → Δ ⊢ t `+ s\n `case_`of_||_ : ∀ {Δ t s u} → Δ ⊢ t `+ s\n → Δ ⊢ t `⇨ u → Δ ⊢ s `⇨ u → Δ ⊢ u\n `tt : ∀ {Δ} → Δ ⊢ `⊤\n `let_`=_`in_ : ∀ {Δ th tb} → (x : Var)\n → Δ ⊢ th → x ::: th , Δ ⊢ tb → Δ ⊢ tb\n `if_`then_`else_ : ∀ {Δ t} → Δ ⊢ `Bool → Δ ⊢ t → Δ ⊢ t → Δ ⊢ t\n\n\n\ndata ⟨_⟩ : Γ → Set₁ where\n [] : ⟨ · ⟩\n _∷_ : ∀ {x t Δ} → ⟦ t ⟧ → ⟨ Δ ⟩ → ⟨ x ::: t , Δ ⟩\n\n!_[_] : ∀ {x Δ} → ⟨ Δ ⟩ → (i : x ∈ Δ) → ⟦ !Γ Δ [ i ] ⟧\n!_[_] [] ()\n!_[_] (val ∷ env) H = val\n!_[_] (val ∷ env) (TH ⦃ prf = i ⦄) = ! env [ i ]\n\n\ninterpret : ∀ {t} → · ⊢ t → ⟦ t ⟧\ninterpret = interpret' []\n where interpret' : ∀ {Δ t} → ⟨ Δ ⟩ → Δ ⊢ t → ⟦ t ⟧\n interpret' env `true = true\n interpret' env `false = false\n interpret' env `tt = tt\n interpret' env (`n n) = n\n interpret' env ((`v x) ⦃ i = idx ⦄) = ! env [ idx ]\n interpret' env (f `₋ x) = (interpret' env f) (interpret' env x)\n interpret' env (`λ _ `: tx ⇨ body) = λ (x : ⟦ tx ⟧) → interpret' (x ∷ env) body\n interpret' env (l `+ r) = interpret' env l + interpret' env r\n interpret' env (l `* r) = interpret' env l * interpret' env r\n interpret' env (l `∧ r) = interpret' env l ∧ interpret' env r\n interpret' env (l `∨ r) = interpret' env l ∨ interpret' env r\n interpret' env (l `≤ r) with interpret' env l N.≤? interpret' env r\n ... | yes p = true\n ... | no ¬p = false\n interpret' env (`¬ x) = not (interpret' env x)\n interpret' env (f `, s) = interpret' env f ,′ interpret' env s\n interpret' env (`fst p) with interpret' env p\n interpret' env (`fst p) | f , s = f\n interpret' env (`snd p) with interpret' env p\n interpret' env (`snd p) | f , s = s\n interpret' env (`left v) = inj₁ (interpret' env v)\n interpret' env (`right v) = inj₂ (interpret' env v)\n interpret' env (`case s `of le || re) with interpret' env s\n interpret' env (`case s `of le || re) | inj₁ l = (interpret' env le) l\n interpret' env (`case s `of le || re) | inj₂ r = (interpret' env re) r\n interpret' env (`let _ `= h `in b) = let hval = interpret' env h in interpret' (hval ∷ env) b\n interpret' env (`if b `then et `else ef) with interpret' env b\n interpret' env (`if b `then et `else ef) | true = interpret' env et\n interpret' env (`if b `then et `else ef) | false = interpret' env ef\n\n\ninstance\n v_type₁ : ∀ {x Δ t} → x ∈ x ::: t , Δ\n v_type₁ = H\n\n v_type₂ : ∀ {x y Δ t} → ⦃ prf : x ∈ Δ ⦄ → ⦃ x ≠ y ⦄ → x ∈ y ::: t , Δ\n v_type₂ = TH\n\ninstance\n xy : x' ≠ y'\n xy = x≠y\n\n xz : x' ≠ z'\n xz = x≠z\n\n yx : y' ≠ x'\n yx = y≠x\n\n yz : y' ≠ z'\n yz = y≠z\n\n zx : z' ≠ x'\n zx = z≠x\n\n zy : z' ≠ y'\n zy = z≠y\n", "meta": {"hexsha": "988dac4843cabaeafba54ccbcfcffe73358f22c9", "size": 5371, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Interpreter.agda", "max_stars_repo_name": "sseefried/well-typed-agda-interpreter", "max_stars_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-06-18T12:06:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T12:37:46.000Z", "max_issues_repo_path": "Interpreter.agda", "max_issues_repo_name": "sseefried/well-typed-agda-interpreter", "max_issues_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c", "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": "Interpreter.agda", "max_forks_repo_name": "sseefried/well-typed-agda-interpreter", "max_forks_repo_head_hexsha": "2a85cc82934be9433648bca0b49b77db18de524c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-18T06:14:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-18T12:31:11.000Z", "avg_line_length": 30.3446327684, "max_line_length": 101, "alphanum_fraction": 0.4306460622, "num_tokens": 2335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6654105720171531, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.35347233299750463}} {"text": "module Holes.Prelude where\n\nopen import Agda.Primitive public\n using (Level; _⊔_; lzero; lsuc)\nopen import Agda.Builtin.List public\n using (List; _∷_; [])\nopen import Agda.Builtin.Unit public\n using (⊤; tt)\nopen import Agda.Builtin.Bool public\n using (Bool; true; false)\nopen import Agda.Builtin.Nat public\n using (zero; suc; _+_; _*_)\n renaming (Nat to ℕ; _==_ to _=ℕ?_)\nopen import Agda.Builtin.Reflection public\nopen import Agda.Builtin.String public\nopen import Agda.Builtin.Char public\n\ninfixr 4 _,_\ninfixr 2 _×_\ninfixr 9 _∘_\ninfixl 1 _⟨_⟩_\ninfixr 0 _$_\ninfix 0 case_of_\n\n--------------------------------------------------------------------------------\n-- Datatypes\n--------------------------------------------------------------------------------\n\ndata Maybe {a} (A : Set a) : Set a where\n just : (x : A) → Maybe A\n nothing : Maybe A\n\nrecord _×_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where\n constructor _,_\n\n field\n proj₁ : A\n proj₂ : B\n\nopen _×_ public\n\n--------------------------------------------------------------------------------\n-- Combinators\n--------------------------------------------------------------------------------\n\n_∘_ : ∀ {a b c}\n {A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} →\n (∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →\n ((x : A) → C (g x))\nf ∘ g = λ x → f (g x)\n\nid : ∀ {a} {A : Set a} → A → A\nid x = x\n\nconst : ∀ {a b} {A : Set a} {B : Set b} → A → B → A\nconst x = λ _ → x\n\nflip : ∀ {a b c} {A : Set a}{B : Set b}{C : Set c} → (A → B → C) → B → A → C\nflip f y x = f x y\n\n_$_ : ∀ {a b} {A : Set a} {B : A → Set b} →\n ((x : A) → B x) → ((x : A) → B x)\nf $ x = f x\n\n_⟨_⟩_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →\n A → (A → B → C) → B → C\nx ⟨ f ⟩ y = f x y\n\ncurry : ∀ {a b c}{A : Set a}{B : Set b}{C : Set c} → (A × B → C) → A → B → C\ncurry f x y = f (x , y)\n\nuncurry : ∀ {a b c}{A : Set a}{B : Set b}{C : Set c} → (A → B → C) → A × B → C\nuncurry f (x , y) = f x y\n\ncase_of_ : ∀ {a b}{A : Set a}{B : Set b} → A → (A → B) → B\ncase x of f = f x\n\n--------------------------------------------------------------------------------\n-- Boolean operations\n--------------------------------------------------------------------------------\n\n_∨_ : Bool → Bool → Bool\nfalse ∨ false = false\n_ ∨ _ = true\n\n_∧_ : Bool → Bool → Bool\ntrue ∧ true = true\n_ ∧ _ = false\n\nnot : Bool → Bool\nnot true = false\nnot false = true\n\nif_then_else_ : ∀ {a} {A : Set a} → (b : Bool) → A → A → A\nif true then x else y = x\nif false then x else y = y\n\n--------------------------------------------------------------------------------\n-- List operations\n--------------------------------------------------------------------------------\n\nsingleton : ∀ {a}{A : Set a} → A → List A\nsingleton x = x ∷ []\n\nmap : ∀ {a b}{A : Set a}{B : Set b} → (A → B) → List A → List B\nmap f [] = []\nmap f (x ∷ xs) = f x ∷ map f xs\n\nlength : ∀ {a}{A : Set a} → List A → ℕ\nlength [] = 0\nlength (_ ∷ xs) = suc (length xs)\n\nzip : ∀ {a b}{A : Set a}{B : Set b} → List A → List B → List (A × B)\nzip [] _ = []\nzip _ [] = []\nzip (x ∷ xs) (y ∷ ys) = (x , y) ∷ zip xs ys\n\nunzip : ∀ {a b}{A : Set a}{B : Set b} → List (A × B) → List A × List B\nunzip [] = [] , []\nunzip ((x , y) ∷ xys) with unzip xys\n... | xs , ys = x ∷ xs , y ∷ ys\n\ninfixr 6 _++_\n\n_++_ : ∀ {a}{A : Set a} → List A → List A → List A\n[] ++ ys = ys\n(x ∷ xs) ++ ys = x ∷ xs ++ ys\n\nconcatMap : ∀ {a b}{A : Set a}{B : Set b} → (A → List B) → List A → List B\nconcatMap f [] = []\nconcatMap f (x ∷ xs) = f x ++ concatMap f xs\n\nconcat : ∀ {a}{A : Set a} → List (List A) → List A\nconcat = concatMap id\n\nintersperse : ∀ {a}{A : Set a} → A → List A → List A\nintersperse e [] = []\nintersperse e (x ∷ []) = x ∷ []\nintersperse e (x ∷ y ∷ xs) = x ∷ e ∷ intersperse e (y ∷ xs)\n\nintercalate : ∀ {a}{A : Set a} → List A → List (List A) → List A\nintercalate e = concat ∘ intersperse e\n\n--------------------------------------------------------------------------------\n-- Nat operations\n--------------------------------------------------------------------------------\n\n-- A comparison view. Taken from \"View from the left\" (McBride/McKinna) via the\n-- Agda standard library\n\ndata Ordering : ℕ → ℕ → Set where\n less : ∀ m k → Ordering m (suc (m + k))\n equal : ∀ m → Ordering m m\n greater : ∀ m k → Ordering (suc (m + k)) m\n\ncompare : ∀ m n → Ordering m n\ncompare zero zero = equal zero\ncompare (suc m) zero = greater zero m\ncompare zero (suc n) = less zero n\ncompare (suc m) (suc n) with compare m n\ncompare (suc .m) (suc .(suc m + k)) | less m k = less (suc m) k\ncompare (suc .m) (suc .m) | equal m = equal (suc m)\ncompare (suc .(suc m + k)) (suc .m) | greater m k = greater (suc m) k\n\n__ : M → M → M\n mempty : M\n\nopen RawMonoid {{...}} public\n\ninstance\n listMonoid : ∀ {a} {A : Set a} → RawMonoid (List A)\n RawMonoid._<>_ listMonoid = _++_\n RawMonoid.mempty listMonoid = []\n\nrecord RawMonad {f} (M : Set f → Set f) : Set (lsuc f) where\n infixl 1 _>>=_ _>>_ _>=>_ _>>=²_\n infixr 1 _=<<_ _<=<_\n infixl 4 _<$>_\n infixl 4 _⊛_\n\n field\n _>>=_ : ∀ {A B} → M A → (A → M B) → M B\n return : ∀ {A} → A → M A\n\n _>>_ : ∀ {A B} → M A → M B → M B\n x >> y = x >>= λ _ → y\n\n _>=>_ : ∀ {ℓ}{A : Set ℓ}{B C} → (A → M B) → (B → M C) → A → M C\n f >=> g = λ x → f x >>= g\n\n _=<<_ : ∀ {A B} → (A → M B) → M A → M B\n f =<< x = x >>= f\n\n _<=<_ : ∀ {ℓ}{A : Set ℓ}{B C} → (B → M C) → (A → M B) → A → M C\n g <=< f = f >=> g\n\n _>>=²_ : {A B C : Set f} → M (A × B) → (A → B → M C) → M C\n x >>=² f = x >>= uncurry f\n\n join : ∀ {A} → M (M A) → M A\n join m = m >>= id\n\n fmap : ∀ {A B} → (A → B) → M A → M B\n fmap f x = x >>= return ∘ f\n\n _<$>_ = fmap\n\n _⊛_ : ∀ {A B} → M (A → B) → M A → M B\n f ⊛ x = f >>= flip fmap x\n\nopen RawMonad {{...}} public\n\nrecord RawTraversable {t} (T : Set t → Set t) : Set (lsuc t) where\n field\n traverse : {M : Set t → Set t} {{monad : RawMonad M}} {A B : Set t} → (A → M B) → T A → M (T B)\n\n sequence : {M : Set t → Set t} {{monad : RawMonad M}} {A : Set t} → T (M A) → M (T A)\n sequence = traverse id\n\nopen RawTraversable {{...}} public\n\ntraverse- : {T M : Set → Set} {{traversable : RawTraversable T}} {{monad : RawMonad M}} {A B : Set} → (A → M B) → T A → M ⊤\ntraverse- f xs = traverse f xs >> return tt\n\ninstance\n traversableList : ∀ {t} → RawTraversable (List {t})\n traverse {{traversableList}} f [] = return []\n traverse {{traversableList}} f (x ∷ xs) = _∷_ <$> f x ⊛ traverse f xs\n\n--------------------------------------------------------------------------------\n-- Propositional Equality\n--------------------------------------------------------------------------------\n\nmodule PropEq where\n open import Agda.Builtin.Equality using (_≡_; refl) public\n\n sym : ∀ {a} {A : Set a} {x y : A} → x ≡ y → y ≡ x\n sym refl = refl\n\n trans : ∀ {a} {A : Set a} {x y z : A} → x ≡ y → y ≡ z → x ≡ z\n trans refl eq = eq\n\n subst : ∀ {a p} {A : Set a} (P : A → Set p) {x y} → x ≡ y → P x → P y\n subst P refl p = p\n\n cong : ∀ {a b} {A : Set a} {B : Set b}\n (f : A → B) {x y} → x ≡ y → f x ≡ f y\n cong f refl = refl\n\n--------------------------------------------------------------------------------\n-- Monads and useful instances\n--------------------------------------------------------------------------------\n\ninfixl 1 _>>=′_\n\n-- _>>=_ in `RawMonad` only works on a single level, while bindTC is more\n-- level-polymorphic, which we will sometimes need.\n_>>=′_ = bindTC\n\ndata Result {e r} (E : Set e) (R : Set r) : Set (e ⊔ r) where\n ok : (x : R) → Result E R\n err : (e : E) → Result E R\n\nMaybe→Result : ∀ {e r} {E : Set e} {R : Set r} → E → Maybe R → Result E R\nMaybe→Result e (just x) = ok x\nMaybe→Result e nothing = err e\n\ninstance\n List-Monad : ∀ {a} → RawMonad (List {a})\n RawMonad._>>=_ List-Monad = flip concatMap\n RawMonad.return List-Monad x = x ∷ []\n\n TC-Monad : ∀ {a} → RawMonad {a} TC\n TC-Monad = record\n { return = returnTC\n ; _>>=_ = bindTC\n }\n\n Maybe-Monad : ∀ {a} → RawMonad {a} Maybe\n (RawMonad._>>=_ Maybe-Monad) (just x) f = f x\n (RawMonad._>>=_ Maybe-Monad) nothing f = nothing\n RawMonad.return Maybe-Monad = just\n\n Result-Monad : ∀ {ℓ}{E : Set ℓ} → RawMonad {ℓ} (Result E)\n Result-Monad = record\n { return = ok\n ; _>>=_ = λ\n { (err e) _ → err e\n ; (ok x) f → f x\n }\n }\n\n--------------------------------------------------------------------------------\n-- RTC: A type checking monad with errors other than normal type errors\n--------------------------------------------------------------------------------\n\nrecord RTC {e r} (E : Set e) (R : Set r) : Set (e ⊔ r) where\n field\n tryRunRTC : TC (Result E R)\n\nopen RTC public\n\nrunRTC : ∀ {e r} {E : Set e} {R : Set r} → (E → TC R) → RTC E R → TC R\nrunRTC f x =\n tryRunRTC x >>=′\n λ { (err e) → f e\n ; (ok y) → return y\n }\n\nmodule RTC′ {e} {E : Set e} where\n bind : ∀ {α β} {A : Set α}{B : Set β} → RTC E A → (A → RTC E B) → RTC E B\n tryRunRTC (bind x f) =\n tryRunRTC x >>=′\n λ { (err e) → return (err e)\n ; (ok y) → tryRunRTC (f y)\n }\n\ninstance\n RTC-monad : ∀ {ℓ} {E : Set ℓ} → RawMonad {ℓ} (RTC E)\n RTC-monad = record\n { return = λ x → record { tryRunRTC = return (return x) }\n ; _>>=_ = RTC′.bind\n }\n\ncatchRTC : ∀ {ℓ} {E : Set ℓ}{R : Set ℓ} → RTC E R → RTC E R → RTC E R\ntryRunRTC (catchRTC rtc fallback) =\n tryRunRTC rtc ⟨ catchTC ⟩ tryRunRTC fallback\n\n--------------------------------------------------------------------------------\n-- MonadCatch and instances\n--------------------------------------------------------------------------------\n\nrecord MonadCatch {a e} (E : Set e) (M : Set a → Set a) : Set (lsuc a ⊔ e) where\n field\n catch : ∀ {A : Set a} → (E → M A) → M A → M A\n\nopen MonadCatch {{...}} public\n\ninstance\n Maybe-MonadCatch : ∀ {a} → MonadCatch {a} ⊤ Maybe\n Maybe-MonadCatch = record\n { catch = λ\n { f (just x) → just x\n ; f nothing → f tt\n }\n }\n\n Result-MonadCatch : ∀ {ℓ} {E : Set ℓ} → MonadCatch {ℓ} E (Result E)\n Result-MonadCatch = record\n { catch = λ\n { f (err e) → f e\n ; f (ok x) → ok x}\n }\n\n RTC-MonadCatch : ∀ {ℓ} {E : Set ℓ} → MonadCatch {ℓ} E (RTC E)\n RTC-MonadCatch = record\n { catch = λ f x → record\n { tryRunRTC = tryRunRTC x >>= λ\n { (err e) → tryRunRTC (f e)\n ; (ok y) → return (ok y)\n }\n }\n }\n\n--------------------------------------------------------------------------------\n-- MonadThrow and instances\n--------------------------------------------------------------------------------\n\nrecord MonadThrow {a e} (E : Set e) (M : Set a → Set a) : Set (lsuc a ⊔ e) where\n field\n {{monad}} : RawMonad M\n throw : ∀ {A : Set a} → E → M A\n\nopen MonadThrow {{...}} public\n\ninstance\n Maybe-MonadThrow : ∀ {a} → MonadThrow {a} ⊤ Maybe\n Maybe-MonadThrow = record { throw = λ _ → nothing }\n\n Result-MonadThrow : ∀ {ℓ} {E : Set ℓ} → MonadThrow {ℓ} E (Result E)\n Result-MonadThrow = record { throw = err }\n\n RTC-MonadThrow : ∀ {ℓ} {E : Set ℓ} → MonadThrow {ℓ} E (RTC E)\n RTC-MonadThrow = record { throw = λ e → record { tryRunRTC = return (err e) } }\n\n TC-MonadThrow : ∀ {ℓ} → MonadThrow {ℓ} (List ErrorPart) TC\n TC-MonadThrow = record { throw = typeError }\n\nliftResult′ : ∀ {e ℓ} {E E′ : Set e} {M : Set ℓ → Set ℓ} {{monadThrow : MonadThrow E′ M}} {A : Set ℓ} → (E → E′) → Result E A → M A\nliftResult′ _ (ok x) = return x\nliftResult′ f (err e) = throw (f e)\n\nliftResult : ∀ {e ℓ} {E : Set e} {M : Set ℓ → Set ℓ} {{monadThrow : MonadThrow E M}} {A : Set ℓ} → Result E A → M A\nliftResult = liftResult′ id\n\nliftMaybe : ∀ {e ℓ}{E : Set e} {M : Set ℓ → Set ℓ} {{monadThrow : MonadThrow E M}} {A : Set ℓ} → E → Maybe A → M A\nliftMaybe error (just x) = return x\nliftMaybe error nothing = throw error\n\n--------------------------------------------------------------------------------\n-- Choice and instances\n--------------------------------------------------------------------------------\n\nrecord Choice {a} (F : Set a → Set a) : Set (lsuc a) where\n field\n _<|>_ : ∀ {A} → F A → F A → F A\n\nopen Choice {{...}} public\n\ninstance\n Maybe-Choice : ∀ {a} → Choice {a} Maybe\n Maybe-Choice = record\n { _<|>_ = λ\n { (just x) _ → just x\n ; nothing (just y) → just y\n ; nothing nothing → nothing\n }\n }\n\n Result-Choice : ∀ {ℓ}{E : Set ℓ} → Choice {ℓ} (Result E)\n Result-Choice = record\n { _<|>_ = λ\n { (ok x) _ → ok x\n ; (err _) (ok y) → ok y\n ; (err e) (err _) → err e\n }\n }\n\n--------------------------------------------------------------------------------\n-- General utility methods\n--------------------------------------------------------------------------------\n\nsuccesses : ∀ {ℓ e M} {E : Set e} {{monadCatch : MonadCatch E M}}{{monad : RawMonad M}} {A : Set ℓ} → List (M A) → M (List A)\nsuccesses [] = return []\nsuccesses {{monadCatch}} {A = A} (x ∷ xs) =\n successes {{monadCatch}} xs >>= λ xs′ →\n catch {{monadCatch}} (λ _ → return xs′) (fmap (_∷ xs′) x)\n\nmapErr : ∀ {e r}{R : Set r}{E E′ : Set e} → (E → E′) → Result E R → Result E′ R\nmapErr f (ok x) = ok x\nmapErr f (err e) = err (f e)\n\ndiscardErr : ∀ {e r} {E : Set e}{R : Set r} → Result E R → Maybe R\ndiscardErr (ok x) = just x\ndiscardErr (err _) = nothing\n\nresult : ∀ {e r a}{E : Set e}{R : Set r}{A : Set a} → (E → A) → (R → A) → Result E R → A\nresult g f (ok x) = f x\nresult g f (err e) = g e\n\n--------------------------------------------------------------------------------\n-- Reflection utility methods\n--------------------------------------------------------------------------------\n\ninfix 4 _=Name?_\n\n_=Name?_ : Name → Name → Bool\n_=Name?_ = primQNameEquality\n\nbasicArg : Term → Arg Term\nbasicArg = arg (arg-info visible relevant)\n\nimplicitArg : Term → Arg Term\nimplicitArg = arg (arg-info hidden relevant)\n\ngetArg : Arg Term → Term\ngetArg (arg _ x) = x\n\nmapArg : ∀ {A B} → (A → B) → Arg A → Arg B\nmapArg f (arg i x) = arg i (f x)\n\ngetArglist : Term → List (Arg Term)\ngetArglist (def _ args) = args\ngetArglist (con _ args) = args\ngetArglist (var _ args) = args\ngetArglist _ = []\n\ninstance\n traversableArg : RawTraversable Arg\n traverse {{traversableArg}} f (arg i x) = arg i <$> f x\n\nliftTC : ∀ {e r} {E : Set e}{R : Set r} → TC R → RTC E R\ntryRunRTC (liftTC x) = x >>=′ return ∘ ok\n\nmapRtcErr : ∀ {ℓ}{R E E′ : Set ℓ} → (E → E′) → RTC E R → RTC E′ R\ntryRunRTC (mapRtcErr f x) = tryRunRTC x >>= return ∘ mapErr f\n\nrunRtcOrTypeError : ∀ {ℓ} {E R : Set ℓ} → (E → List ErrorPart) → RTC E R → TC R\nrunRtcOrTypeError error = tryRunRTC >=> result (typeError ∘ error) return\n\ntypeError′ : ∀ {ℓ} {E R : Set ℓ} → List ErrorPart → RTC E R\ntypeError′ = liftTC ∘ typeError\n\n--------------------------------------------------------------------------------\n-- Macros that aid debugging\n--------------------------------------------------------------------------------\n\nrunTCTy : ∀ ℓ → Type → Term → Term → TC ⊤\nrunTCTy ℓ at-type tc-term target =\n unquoteTC at-type >>=′ λ (ty : Set ℓ) →\n unquoteTC tc-term >>=′ λ (TCx : TC ty) →\n TCx >>=′\n quoteTC >>=′\n unify target\n\nmacro\n -- Quotes a term and expands to its reified syntax tree as a `Term`.\n\n quote-term : Term → Term → TC ⊤\n quote-term term target = quoteTC term >>= unify target\n\n -- Runs a TC operation and splices its result into the expression. Only works\n -- with operations in Set₀.\n\n runTCTy′ : ∀ {ℓ} → Type → Term → Term → TC ⊤\n runTCTy′ {ℓ} = runTCTy ℓ\n\n runTC : ∀ {ℓ} → Term → Term → TC ⊤\n runTC {ℓ} tc-term target =\n inferType target >>=′\n unquoteTC >>=′ λ (ty : Set ℓ) →\n unquoteTC tc-term >>=′ λ (TCx : TC ty) →\n TCx >>=′\n quoteTC >>=′\n unify target\n", "meta": {"hexsha": "e8090258c3e48a4b9dfac59d809ce8f66a99a17c", "size": 15979, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Holes/Prelude.agda", "max_stars_repo_name": "bch29/agda-holes", "max_stars_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2017-01-28T10:56:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-03T15:02:41.000Z", "max_issues_repo_path": "src/Holes/Prelude.agda", "max_issues_repo_name": "bch29/agda-holes", "max_issues_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-01-16T10:47:58.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-31T20:58:33.000Z", "max_forks_repo_path": "src/Holes/Prelude.agda", "max_forks_repo_name": "bch29/agda-holes", "max_forks_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-01-27T14:57:39.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-02T18:57:17.000Z", "avg_line_length": 29.7560521415, "max_line_length": 131, "alphanum_fraction": 0.4531572689, "num_tokens": 5447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.665410558746814, "lm_q1q2_score": 0.3534723259481761}} {"text": "open import Coinduction using ( ∞ ; ♯_ ; ♭ )\nopen import Data.Product using ( _×_ ; _,_ ; proj₁ )\nopen import FRP.LTL.Time.Bound using \n ( Time∞ ; _≼_ ; _≺_ ; fin ; +∞ ; +∞-top\n ; ≼-refl ; _≼-trans_ ; ≡-impl-≽ ; ≺-impl-≼ ; ≺-impl-⋡ ; t≺+∞ \n ; _≼-case_ ; lt ; eq ; gt )\nopen import FRP.LTL.Time.Interval using ( [_⟩ ; _⊑_ ; _~_ ; _⌢_∵_ )\nopen import FRP.LTL.ISet.Causal using ( _⊵_ ; _∙_⊸_∙_ ; done ; inp ; out ; _/_/_ )\nopen import FRP.LTL.ISet.Core using ( ISet ; [_] ; _,_ ; ⟦_⟧ ; M⟦_⟧ ; splitM⟦_⟧ ; subsumM⟦_⟧ )\nopen import FRP.LTL.ISet.Stateless using ( _⇒_ )\nopen import FRP.LTL.Util using ( ⊥-elim ; ≡-relevant )\nopen import Relation.Binary.PropositionalEquality using ( _≡_ ; refl )\n\nmodule FRP.LTL.ISet.Product where\n\n_∧_ : ISet → ISet → ISet\nA ∧ B = [ (λ i → M⟦ A ⟧ i × M⟦ B ⟧ i) , split , subsum ] where\n\n split : ∀ i j i~j → \n (M⟦ A ⟧ (i ⌢ j ∵ i~j) × M⟦ B ⟧ (i ⌢ j ∵ i~j)) → \n ((M⟦ A ⟧ i × M⟦ B ⟧ i) × (M⟦ A ⟧ j × M⟦ B ⟧ j)) \n split i j i~j (σ , τ) with splitM⟦ A ⟧ i j i~j σ | splitM⟦ B ⟧ i j i~j τ\n split i j i~j (σ , τ) | (σ₁ , σ₂) | (τ₁ , τ₂) = ((σ₁ , τ₁) , (σ₂ , τ₂))\n\n subsum : ∀ i j → (i ⊑ j) → (M⟦ A ⟧ j × M⟦ B ⟧ j) → (M⟦ A ⟧ i × M⟦ B ⟧ i)\n subsum i j i⊑j (σ , τ) = (subsumM⟦ A ⟧ i j i⊑j σ , subsumM⟦ B ⟧ i j i⊑j τ)\n \n-- We could define fst and snd in terms of arr, but we define them explictly for efficiency.\n\nπ₁ : ∀ {A B} t → ((A ∧ B) ∙ t ⊸ A ∙ t)\nπ₁ {A} {B} +∞ = done refl\nπ₁ {A} {B} (fin t) = inp ≼-refl t≺+∞ P where\n\n P : ∀ {u} .(t≺u : fin t ≺ u) → M⟦ A ∧ B ⟧ [ t≺u ⟩ → ∞ ((A ∧ B) ∙ u ⊸ A ∙ fin t)\n P {u} t≺u [ σ , τ ] = ♯ out t≺u σ (♯ π₁ u)\n\nfst : ∀ {A B} → ⟦ A ∧ B ⊵ A ⟧\nfst = [ (λ t t∈i → π₁ (fin t)) ]\n\nπ₂ : ∀ {A B} t → ((A ∧ B) ∙ t ⊸ B ∙ t)\nπ₂ {A} {B} +∞ = done refl\nπ₂ {A} {B} (fin t) = inp ≼-refl t≺+∞ Q where\n\n Q : ∀ {u} .(t≺u : fin t ≺ u) → M⟦ A ∧ B ⟧ [ t≺u ⟩ → ∞ ((A ∧ B) ∙ u ⊸ B ∙ fin t)\n Q {u} t≺u [ σ , τ ] = ♯ out t≺u τ (♯ π₂ u)\n\nsnd : ∀ {A B} → ⟦ A ∧ B ⊵ B ⟧\nsnd = [ (λ t t∈i → π₂ (fin t)) ]\n\n-- Mediating morphism\n\n_&&_ : ∀ {A B C s t} → (A ∙ s ⊸ B ∙ t) → (A ∙ s ⊸ C ∙ t) → (A ∙ s ⊸ (B ∧ C) ∙ t)\ninp s≼t t≺∞ P && Q = inp s≼t t≺∞ (λ s≺u σ → ♯ (♭ (P s≺u σ) && (Q / s≺u / σ)))\nP && inp s≼t t≺∞ Q = inp s≼t t≺∞ (λ s≺u σ → ♯ ((P / s≺u / σ) && ♭ (Q s≺u σ)))\nP && done t≡∞ = done t≡∞\ndone t≡∞ && Q = done t≡∞\nout {u} t≺u σ P && out {v} t≺v τ Q with u ≼-case v\nout t≺u σ P && out t≺v τ Q | lt u≺v with splitM⟦ _ ⟧ [ t≺u ⟩ [ u≺v ⟩ refl τ \nout t≺u σ P && out t≺v τ Q | lt u≺v | (τ₁ , τ₂) = out t≺u [ σ , τ₁ ] (♯ (♭ P && out u≺v τ₂ Q))\nout t≺u σ P && out t≺v τ Q | eq u≡v with ≡-relevant u≡v\nout t≺u σ P && out t≺v τ Q | eq u≡v | refl = out t≺u [ σ , τ ] (♯ (♭ P && ♭ Q))\nout t≺u σ P && out t≺v τ Q | gt v≺u with splitM⟦ _ ⟧ [ t≺v ⟩ [ v≺u ⟩ refl σ\nout t≺u σ P && out t≺v τ Q | gt v≺u | (σ₁ , σ₂) = out t≺v [ σ₁ , τ ] (♯ (out v≺u σ₂ P && ♭ Q))\n\n_&&&_ : ∀ {A B C} → ⟦ (A ⊵ B) ⇒ (A ⊵ C) ⇒ (A ⊵ (B ∧ C)) ⟧\n[ [ f ] ] &&& [ [ g ] ] = [ (λ t t∈i → f t t∈i && g t t∈i) ]", "meta": {"hexsha": "565d491d6193563face20ee18a214f875c20ba3c", "size": 3030, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/FRP/LTL/ISet/Product.agda", "max_stars_repo_name": "agda/agda-frp-ltl", "max_stars_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-07-02T20:25:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-15T02:51:13.000Z", "max_issues_repo_path": "src/FRP/LTL/ISet/Product.agda", "max_issues_repo_name": "agda/agda-frp-ltl", "max_issues_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-03-01T07:01:31.000Z", "max_issues_repo_issues_event_max_datetime": "2015-03-02T15:23:53.000Z", "max_forks_repo_path": "src/FRP/LTL/ISet/Product.agda", "max_forks_repo_name": "agda/agda-frp-ltl", "max_forks_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-03-01T07:33:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:04.000Z", "avg_line_length": 45.9090909091, "max_line_length": 98, "alphanum_fraction": 0.4283828383, "num_tokens": 1658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7122321842389469, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.35333399175153657}} {"text": "\nmodule IID-Proof-Test where\n\nopen import LF\nopen import Identity\nopen import IID\nopen import IIDr\nopen import DefinitionalEquality\nopen import IID-Proof-Setup\n\nη : {I : Set}(γ : OPg I)(U : I -> Set) -> Args γ U -> Args γ U\nη (ι i)\t U _ = ★\nη (σ A γ) U a = < a₀ | η (γ a₀) U a₁ >\n where\n a₀ = π₀ a\n a₁ = π₁ a\nη (δ A i γ) U a = < a₀ | η γ U a₁ >\n where\n a₀ = π₀ a\n a₁ = π₁ a\n\nr←→gArgs-equal :\n {I : Set}(γ : OPg I)(U : I -> Set)\n (i : I)(a : Args (ε γ i) U) ->\n _==_ {I × \\i -> Args (ε γ i) U}\n < index γ U (r→gArgs γ U i a) |\n g→rArgs γ U (r→gArgs γ U i a)\n > < i | a >\nr←→gArgs-equal {I} (ι i) U j < p | ★ > = elim== i (\\k q -> _==_ {I × \\k -> Args (ε (ι i) k) U}\n\t\t\t\t\t\t\t\t< i | < refl | ★ > >\n\t\t\t\t\t\t\t\t< k | < q | ★ > >\n\t\t\t\t\t\t ) refl j p\nr←→gArgs-equal {I} (σ A γ) U j < a | b > = cong f ih\n where ih = r←→gArgs-equal (γ a) U j b\n\tf : (I × \\i -> Args (ε (γ a) i) U) -> (I × \\i -> Args (ε (σ A γ) i) U)\n\tf < k | q > = < k | < a | q > >\nr←→gArgs-equal {I} (δ H i γ) U j < g | b > = cong f ih\n where ih = r←→gArgs-equal γ U j b\n\tf : (I × \\k -> Args (ε γ k) U) -> (I × \\k -> Args (ε (δ H i γ) k) U)\n\tf < k | q > = < k | < g | q > >\n\n{-\nr←→gArgs-subst-identity' :\n {I : Set}(γ : OPg I) ->\n\n (\\(U : I -> Set)(C : (i : I) -> rArgs (ε γ) U i -> Set)\n (a : Args γ U)(h : C (index γ U (r→gArgs γ U (index γ U (η γ U a)) (g→rArgs γ U (η γ U a))))\n\t\t\t (g→rArgs γ U (r→gArgs γ U (index γ U (η γ U a)) (g→rArgs γ U (η γ U a))))\n\t\t ) -> r←→gArgs-subst γ U C (index γ U (η γ U a)) (g→rArgs γ U (η γ U a)) h\n ) ==¹\n (\\(U : I -> Set)(C : (i : I) -> rArgs (ε γ) U i -> Set)\n (a : Args γ U)(h : C (index γ U (r→gArgs γ U (index γ U (η γ U a)) (g→rArgs γ U (η γ U a))))\n\t\t\t (g→rArgs γ U (r→gArgs γ U (index γ U (η γ U a)) (g→rArgs γ U (η γ U a))))\n\t\t ) -> h\n )\nr←→gArgs-subst-identity' (ι i)\t = refl¹\nr←→gArgs-subst-identity' (σ A γ) = ?\nr←→gArgs-subst-identity' (δ A i γ) = subst¹ (\\ ∙ -> f ∙ ==¹ f (\\U C a h -> h))\n\t\t\t\t\t (r←→gArgs-subst-identity' γ) ?\n where\n ih = r←→gArgs-subst-identity' γ\n f = \\g U C a h -> g U (\\i c -> C i < π₀ a | c >) (π₁ a) h\n-}\n", "meta": {"hexsha": "2a5d335fdfc032160cc30defcf967f90c352fb38", "size": 2097, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "examples/outdated-and-incorrect/iird/IID-Proof-Test.agda", "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "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": "examples/outdated-and-incorrect/iird/IID-Proof-Test.agda", "max_issues_repo_name": "larrytheliquid/agda", "max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "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": "examples/outdated-and-incorrect/iird/IID-Proof-Test.agda", "max_forks_repo_name": "larrytheliquid/agda", "max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "avg_line_length": 32.765625, "max_line_length": 98, "alphanum_fraction": 0.4525512637, "num_tokens": 984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.35327422734299047}} {"text": "module STLCRef.Semantics where\n\n-- This file contains the definitional interpreter for STLC+Ref\n-- described in Section 3 of the paper.\n\nopen import Agda.Primitive\nopen import Data.Unit\nopen import Data.Nat hiding (_⊔_ ; _^_)\nopen import Data.Integer hiding (_⊔_)\nopen import Data.List\nopen import Data.List.Properties.Extra\nopen import Data.List.All.Properties.Extra\nopen import Data.List.Membership.Propositional\nopen import Data.List.Relation.Unary.Any\nopen import Data.List.Relation.Unary.All as All\nopen import Data.List.Prefix\nopen import Data.Product\nopen import Data.Maybe hiding (_>>=_)\nopen import Function\nopen import Common.Weakening\n\n------------\n-- SYNTAX --\n------------\n\n-- These definitions correspond to Section 3.1, except we have\n-- included numbers (integers) and integer operations in the language.\n\ndata Ty : Set\n\nCtx = List Ty\n\ndata Ty where\n _⇒_ : (a b : Ty) → Ty\n unit : Ty\n int : Ty\n ref : Ty -> Ty\n\ndata Expr (Γ : List Ty) : Ty → Set where\n unit : Expr Γ unit\n var : ∀ {t} → t ∈ Γ → Expr Γ t\n ƛ : ∀ {a b} → Expr (a ∷ Γ) b → Expr Γ (a ⇒ b)\n _·_ : ∀ {a b} → Expr Γ (a ⇒ b) → Expr Γ a → Expr Γ b\n num : ℤ → Expr Γ int\n iop : (ℤ → ℤ → ℤ) → (l r : Expr Γ int) → Expr Γ int\n ifz : ∀ {t} → Expr Γ int → Expr Γ t → Expr Γ t → Expr Γ t\n ref : ∀ {t} → Expr Γ t → Expr Γ (ref t)\n !_ : ∀ {t} → Expr Γ (ref t) → Expr Γ t\n _≔_ : ∀ {t} → Expr Γ (ref t) → Expr Γ t → Expr Γ unit\n\n\n-----------------------\n-- STORES AND VALUES --\n-----------------------\n\nStoreTy = List Ty\n\nmutual\n data Val : Ty → (Σ : StoreTy) → Set where\n loc : ∀ {Σ t} → t ∈ Σ → Val (ref t) Σ\n unit : ∀ {Σ} → Val unit Σ\n ⟨_,_⟩ : ∀ {Σ Γ a b} → Expr (a ∷ Γ) b → Env Γ Σ → Val (a ⇒ b) Σ\n num : ∀ {Σ} → ℤ → Val int Σ\n\n Env : (Γ : Ctx)(Σ : StoreTy) → Set\n Env Γ Σ = All (λ t → Val t Σ) Γ\n\nStore : (Σ : StoreTy) → Set\nStore Σ = All (λ t → Val t Σ) Σ\n\n-- The `lookup-store` function is defined in terms of the `lookup`\n-- function from `Data.List.All` in the Agda Standard Library.\nlookup-store : ∀ {Σ t} → t ∈ Σ → Store Σ → Val t Σ\nlookup-store x μ = All.lookup μ x\n\n-- The `update-store` function is defined in terms of the update\n-- function for the `All` type: `_All[_]≔'_` from the Standard Library\n-- extension (contained in the `lib/*` folder of this artifact).\nupdate-store : ∀ {Σ t} → t ∈ Σ → Val t Σ → Store Σ → Store Σ\nupdate-store ptr v μ = μ All.[ ptr ]≔ v\n\n\n-----------\n-- MONAD --\n-----------\n\n-- These definitions correspond to Section 3.3.\n\nM : ∀ {i}(Γ : Ctx) → (p : StoreTy → Set i) → (Σ : StoreTy) → Set i\nM Γ p Σ = Env Γ Σ → Store Σ → Maybe (∃ λ Σ' → Store Σ' × p Σ' × Σ ⊑ Σ')\n\nmutual\n weaken-val : ∀ {a}{Σ Σ' : StoreTy} → Σ ⊑ Σ' → Val a Σ → Val a Σ'\n weaken-val ext unit = unit\n weaken-val ext (loc l) = loc (∈-⊒ l ext)\n weaken-val ext ⟨ e , E ⟩ = ⟨ e , weaken-env ext E ⟩\n weaken-val ext (num z) = num z\n\n weaken-env : ∀ {Γ}{Σ Σ' : StoreTy} → Σ ⊑ Σ' → Env Γ Σ → Env Γ Σ'\n weaken-env ext (v ∷ vs) = weaken-val ext v ∷ weaken-env ext vs\n weaken-env ext [] = []\n\n-- The definition below asserts that values can be weakened, by adding\n-- an instance argument of `Weakenable (Val t)`.\n--\n-- Here, `Weakenable` is defined as in the paper Section 3.4; see\n-- `Common.Weakening` in this artifact.\n\ninstance\n weaken-val' : ∀ {t} → Weakenable (Val t)\n weaken-val' = record { wk = weaken-val }\n\nreturn : ∀ {Σ Γ}{p : List Ty → Set} → p Σ → M Γ p Σ\nreturn x E μ = just (_ , μ , x , ⊑-refl)\n\n_>>=_ : ∀ {Σ Γ}{p q : StoreTy → Set} →\n   (f : M Γ p Σ) → (g : ∀ {Σ'} → p Σ' → M Γ q Σ') → M Γ q Σ\n(f >>= c) E μ = case (f E μ) of λ{\n nothing → nothing ;\n (just (_ , μ' , x , ext)) → case (c x (weaken-env ext E) μ') of λ{\n nothing → nothing ;\n (just (_ , μ'' , y , ext')) → just (_ , μ'' , y , ext ⊚ ext')\n }}\n\ngetEnv : ∀ {Σ Γ} → M Γ (Env Γ) Σ\ngetEnv E = return E E\n\nusingEnv : ∀ {Σ Γ Γ'}{p : List Ty → Set} → Env Γ Σ → M Γ p Σ → M Γ' p Σ\nusingEnv E f _ = f E\n\ntimeout : ∀ {Σ Γ}{p : List Ty → Set} → M Γ p Σ\ntimeout _ _ = nothing\n\nstore : ∀ {Σ t Γ} → Val t Σ → M Γ (Val (ref t)) Σ\nstore {Σ} {t} v _ μ\n = let ext = ∷ʳ-⊒ t Σ\n v' = loc (∈-∷ʳ Σ t)\n μ' = (All.map (weaken-val ext) μ) all-∷ʳ (weaken-val ext v)\n in just (_ , μ' , v' , ext)\n\nderef : ∀ {Σ Γ t} → t ∈ Σ → M Γ (Val t) Σ\nderef x E μ = return (All.lookup μ x) E μ\n\nupdate : ∀ {Σ Γ t} → t ∈ Σ → Val t Σ → M Γ (λ _ → ⊤) Σ\nupdate x v E μ = return tt E (update-store x v μ)\n\nweaken : ∀ {i}{p : List Ty → Set i}⦃ w : Weakenable p ⦄ → ∀ {Σ Σ'} → Σ ⊑ Σ' → p Σ → p Σ'\nweaken ⦃ w ⦄ ext v = Weakenable.wk w ext v\n\n\n--------------------------------\n-- STRONG MONADIC INTERPRETER --\n--------------------------------\n\n-- These definitions correspond to Section 3.4.\n--\n-- The definition of `_^_` below is defined in terms of the `_⊗_`\n-- type, which is defined in `Common.Weakening` in this artifact.\n\n_^_ : ∀ {Σ Γ}{p q : StoreTy → Set} → ⦃ w : Weakenable q ⦄ → M Γ p Σ → q Σ → M Γ (p ⊗ q) Σ\n(f ^ x) E μ = case (f E μ) of λ {\n nothing → nothing ;\n (just (Σ , μ' , y , ext)) → just (Σ , μ' , (y , weaken ext x) , ext) }\n\n\neval : ℕ → ∀ {Σ Γ t} → Expr Γ t → M Γ (Val t) Σ\neval zero _ =\n timeout\neval (suc k) unit =\n return unit\neval (suc k) (var x) =\n getEnv >>= λ E →\n return (All.lookup E x)\neval (suc k) (ƛ e) =\n getEnv >>= λ E →\n return ⟨ e , E ⟩\neval (suc k) (l · r) =\n eval k l >>= λ{ ⟨ e , E ⟩ →\n (eval k r ^ E) >>= λ{ (v , E) →\n usingEnv (v ∷ E) (eval k e) }}\neval (suc k) (num x) =\n return (num x)\neval (suc k) (iop f l r) =\n eval k l >>= λ{ (num vₗ) →\n eval k r >>= λ{ (num vᵣ) →\n return (num (f vₗ vᵣ)) }}\neval (suc k) (ifz c t e) =\n eval k c >>= λ{ (num z) →\n case z of λ{ (+ zero) →\n eval k t\n ; _ →\n eval k e }}\neval (suc k) (ref e) =\n eval k e >>= λ v →\n store v\neval (suc k) (! e) =\n eval k e >>= λ{ (loc l) →\n deref l }\neval (suc k) (r ≔ e) =\n eval k r >>= λ{ (loc l) →\n (eval k e ^ l) >>= λ{ (v , l) →\n update l v >>= λ _ →\n return unit }}\n", "meta": {"hexsha": "d65c794a1b64626984615d7f0229d9529d077f11", "size": 6029, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/STLCRef/Semantics.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/STLCRef/Semantics.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/STLCRef/Semantics.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": 29.5539215686, "max_line_length": 90, "alphanum_fraction": 0.5277823851, "num_tokens": 2349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6370308082623217, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.3532147684513263}} {"text": "------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- The lifting of a strict order to incorporate a new supremum\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\n-- This module is designed to be used with\n-- Relation.Nullary.Construct.Add.Supremum\n\nopen import Relation.Binary\n\nmodule Relation.Binary.Construct.Add.Supremum.Strict\n {a r} {A : Set a} (_<_ : Rel A r) where\n\nopen import Level using (_⊔_)\nopen import Data.Product\nopen import Function\nopen import Relation.Nullary hiding (Irrelevant)\nimport Relation.Nullary.Decidable as Dec\nopen import Relation.Binary.PropositionalEquality as P\n using (_≡_; refl)\nopen import Relation.Nullary.Construct.Add.Supremum\nimport Relation.Binary.Construct.Add.Supremum.Equality as Equality\nimport Relation.Binary.Construct.Add.Supremum.NonStrict as NonStrict\n\n------------------------------------------------------------------------\n-- Definition\n\ninfix 4 _<⁺_\n\ndata _<⁺_ : Rel (A ⁺) (a ⊔ r) where\n [_] : {k l : A} → k < l → [ k ] <⁺ [ l ]\n [_]<⊤⁺ : (k : A) → [ k ] <⁺ ⊤⁺\n\n------------------------------------------------------------------------\n-- Relational properties\n\n[<]-injective : ∀ {k l} → [ k ] <⁺ [ l ] → k < l\n[<]-injective [ p ] = p\n\n<⁺-asym : Asymmetric _<_ → Asymmetric _<⁺_\n<⁺-asym <-asym [ p ] [ q ] = <-asym p q\n\n<⁺-trans : Transitive _<_ → Transitive _<⁺_\n<⁺-trans <-trans [ p ] [ q ] = [ <-trans p q ]\n<⁺-trans <-trans [ p ] [ k ]<⊤⁺ = [ _ ]<⊤⁺\n\n<⁺-dec : Decidable _<_ → Decidable _<⁺_\n<⁺-dec _ (λ ()) (λ ()) [ l ]<⊤⁺\n<⁺-cmp-≡ <-cmp [ k ] ⊤⁺ = tri< [ k ]<⊤⁺ (λ ()) (λ ())\n<⁺-cmp-≡ <-cmp [ k ] [ l ] with <-cmp k l\n... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ []-injective) (¬c ∘ [<]-injective)\n... | tri≈ ¬a refl ¬c = tri≈ (¬a ∘ [<]-injective) refl (¬c ∘ [<]-injective)\n... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ []-injective) [ c ]\n\n<⁺-irrefl-≡ : Irreflexive _≡_ _<_ → Irreflexive _≡_ _<⁺_\n<⁺-irrefl-≡ <-irrefl refl [ x ] = <-irrefl refl x\n\n<⁺-respˡ-≡ : _<⁺_ Respectsˡ _≡_\n<⁺-respˡ-≡ = P.subst (_<⁺ _)\n\n<⁺-respʳ-≡ : _<⁺_ Respectsʳ _≡_\n<⁺-respʳ-≡ = P.subst (_ <⁺_)\n\n<⁺-resp-≡ : _<⁺_ Respects₂ _≡_\n<⁺-resp-≡ = <⁺-respʳ-≡ , <⁺-respˡ-≡\n\n------------------------------------------------------------------------\n-- Relational properties + setoid equality\n\nmodule _ {e} {_≈_ : Rel A e} where\n\n open Equality _≈_\n\n <⁺-cmp : Trichotomous _≈_ _<_ → Trichotomous _≈⁺_ _<⁺_\n <⁺-cmp <-cmp ⊤⁺ ⊤⁺ = tri≈ (λ ()) ⊤⁺≈⊤⁺ (λ ())\n <⁺-cmp <-cmp ⊤⁺ [ l ] = tri> (λ ()) (λ ()) [ l ]<⊤⁺\n <⁺-cmp <-cmp [ k ] ⊤⁺ = tri< [ k ]<⊤⁺ (λ ()) (λ ())\n <⁺-cmp <-cmp [ k ] [ l ] with <-cmp k l\n ... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ [≈]-injective) (¬c ∘ [<]-injective)\n ... | tri≈ ¬a b ¬c = tri≈ (¬a ∘ [<]-injective) [ b ] (¬c ∘ [<]-injective)\n ... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ [≈]-injective) [ c ]\n\n <⁺-irrefl : Irreflexive _≈_ _<_ → Irreflexive _≈⁺_ _<⁺_\n <⁺-irrefl <-irrefl [ p ] [ q ] = <-irrefl p q\n\n <⁺-respˡ-≈⁺ : _<_ Respectsˡ _≈_ → _<⁺_ Respectsˡ _≈⁺_\n <⁺-respˡ-≈⁺ <-respˡ-≈ [ p ] [ q ] = [ <-respˡ-≈ p q ]\n <⁺-respˡ-≈⁺ <-respˡ-≈ [ p ] ([ l ]<⊤⁺) = [ _ ]<⊤⁺\n <⁺-respˡ-≈⁺ <-respˡ-≈ ⊤⁺≈⊤⁺ q = q\n\n <⁺-respʳ-≈⁺ : _<_ Respectsʳ _≈_ → _<⁺_ Respectsʳ _≈⁺_\n <⁺-respʳ-≈⁺ <-respʳ-≈ [ p ] [ q ] = [ <-respʳ-≈ p q ]\n <⁺-respʳ-≈⁺ <-respʳ-≈ ⊤⁺≈⊤⁺ q = q\n\n <⁺-resp-≈⁺ : _<_ Respects₂ _≈_ → _<⁺_ Respects₂ _≈⁺_\n <⁺-resp-≈⁺ = map <⁺-respʳ-≈⁺ <⁺-respˡ-≈⁺\n\n------------------------------------------------------------------------\n-- Structures + propositional equality\n\n<⁺-isStrictPartialOrder-≡ : IsStrictPartialOrder _≡_ _<_ →\n IsStrictPartialOrder _≡_ _<⁺_\n<⁺-isStrictPartialOrder-≡ strict = record\n { isEquivalence = P.isEquivalence\n ; irrefl = <⁺-irrefl-≡ irrefl\n ; trans = <⁺-trans trans\n ; <-resp-≈ = <⁺-resp-≡\n } where open IsStrictPartialOrder strict\n\n<⁺-isDecStrictPartialOrder-≡ : IsDecStrictPartialOrder _≡_ _<_ →\n IsDecStrictPartialOrder _≡_ _<⁺_\n<⁺-isDecStrictPartialOrder-≡ dectot = record\n { isStrictPartialOrder = <⁺-isStrictPartialOrder-≡ isStrictPartialOrder\n ; _≟_ = ≡-dec _≟_\n ; _ Set where\n win#def : ∀{T S} (w : Win T) (def : Defined S) -> Progress (T # S)\n inp#out : ∀{f g} (W : Witness g) -> Progress (inp f # out g)\n out#inp : ∀{f g} (W : Witness f) -> Progress (out f # inp g)\n\nprogress-sound : ∀{S} -> Progress S -> ProgressS S\nprogress-sound (win#def e def) = inj₁ (win#def e def)\nprogress-sound (inp#out (_ , !x)) = inj₂ (_ , sync inp (out !x))\nprogress-sound (out#inp (_ , !x)) = inj₂ (_ , sync (out !x) inp)\n\nprogress-complete : ∀{S} -> ProgressS S -> Progress S\nprogress-complete (inj₁ (win#def e def)) = win#def e def\nprogress-complete (inj₂ (_ , sync inp (out !x))) = inp#out (_ , !x)\nprogress-complete (inj₂ (_ , sync (out !x) inp)) = out#inp (_ , !x)\n", "meta": {"hexsha": "0389cf63b7090bdc41f8d1d0022171fcf4d6eddc", "size": 2112, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Progress.agda", "max_stars_repo_name": "boystrange/FairSubtypingAgda", "max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z", "max_issues_repo_path": "src/Progress.agda", "max_issues_repo_name": "boystrange/FairSubtypingAgda", "max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "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/Progress.agda", "max_forks_repo_name": "boystrange/FairSubtypingAgda", "max_forks_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "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.1111111111, "max_line_length": 68, "alphanum_fraction": 0.7069128788, "num_tokens": 554, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3528925139185056}} {"text": "-- MIT License\n\n-- Copyright (c) 2021 Luca Ciccone and Luca Padovani\n\n-- Permission is hereby granted, free of charge, to any person\n-- obtaining a copy of this software and associated documentation\n-- files (the \"Software\"), to deal in the Software without\n-- restriction, including without limitation the rights to use,\n-- copy, modify, merge, publish, distribute, sublicense, and/or sell\n-- copies of the Software, and to permit persons to whom the\n-- Software is furnished to do so, subject to the following\n-- conditions:\n\n-- The above copyright notice and this permission notice shall be\n-- included in all copies or substantial portions of the Software.\n\n-- THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n-- OTHER DEALINGS IN THE SOFTWARE.\n\n{-# OPTIONS --guardedness #-}\n\nimport Level\n\nopen import Data.Empty\nopen import Data.Product\nopen import Data.List using (_∷_; []; _++_)\nopen import Data.List.Properties using (∷-injectiveʳ)\n\nopen import Relation.Nullary\nopen import Relation.Unary\nopen import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; subst)\n\nopen import Common\n\nmodule Semantics {ℙ : Set} (message : Message ℙ)\n where\n\nopen import Trace message\nopen import HasTrace message\nopen import TraceSet message\nopen import SessionType message\nopen import Transitions message\n\nrecord Semantics (X : TraceSet) : Set where\n field\n closed : PrefixClosed X\n coherent : Coherent X\nopen Semantics public\n\ndata Classification : TraceSet -> Set where\n emp : ∀{X} -> X ⊆ ∅ -> Classification X\n eps : ∀{X} -> X ⊆⊇ { [] } -> Classification X\n inp : ∀{X x} -> I x ∷ [] ∈ X -> Classification X\n out : ∀{X x} -> O x ∷ [] ∈ X -> Classification X\n\nis-emp : ∀{X} -> Semantics X -> [] ∉ X -> X ⊆ ∅\nis-emp sem nxε xφ with closed sem none xφ\n... | xε = ⊥-elim (nxε xε)\n\nis-eps :\n ∀{X} ->\n Semantics X ->\n (¬ (∃[ x ] (I x ∷ [] ∈ X))) ->\n (¬ (∃[ x ] (O x ∷ [] ∈ X))) ->\n X ⊆ { [] }\nis-eps sem nix nox {[]} xφ = refl\nis-eps sem nix nox {I x ∷ φ} xφ with closed sem (some none) xφ\n... | ix = ⊥-elim (nix (x , ix))\nis-eps sem nix nox {O x ∷ φ} xφ with closed sem (some none) xφ\n... | ox = ⊥-elim (nox (x , ox))\n\nkind? : ∀{X} -> Semantics X -> Classification X\nkind? {X} sem with excluded-middle {∃[ x ] (I x ∷ [] ∈ X)}\n... | yes (_ , ix) = inp ix\n... | no nix with excluded-middle {∃[ x ] (O x ∷ [] ∈ X)}\n... | yes (_ , ox) = out ox\n... | no nox with excluded-middle {[] ∈ X}\n... | yes xε = eps (is-eps sem nix nox , λ { refl -> xε })\n... | no nxε = emp (is-emp sem nxε)\n\nsem-sound : (T : SessionType) -> Semantics ⟦ T ⟧\nclosed (sem-sound T) = ⊑-has-trace\ncoherent (sem-sound T) = trace-coherence\n\nderive-semantics : ∀{X} -> Semantics X -> (α : Action) -> Semantics (X ∂ α)\nclosed (derive-semantics sem _) pre hasφ = closed sem (some pre) hasφ\ncoherent (derive-semantics {X} sem γ) {φ} {α} {β} hasφα hasφβ = coherent {X} sem {γ ∷ φ} hasφα hasφβ\n\nco-semantics : ∀{X} -> Semantics X -> Semantics (CoSet X)\nclosed (co-semantics sem) le coφ = closed sem (⊑-co-trace le) coφ\ncoherent (co-semantics sem) {φ} {ψ₁} {ψ₂} {x} {y} iφx oφx\n rewrite co-trace-++ φ (I x ∷ ψ₁) | co-trace-++ φ (O y ∷ ψ₂) =\n coherent sem {co-trace φ} {co-trace ψ₂} {co-trace ψ₁} {y} {x} oφx iφx\n\nnon-empty-semantics-contains-[] : ∀{X : TraceSet}{φ} -> Semantics X -> φ ∈ X -> [] ∈ X\nnon-empty-semantics-contains-[] sem w = closed sem none w\n\ndecode : ∀{X} -> Semantics X -> ∞SessionType\nforce (decode sem) with kind? sem\n... | emp _ = nil\n... | eps _ = win\n... | inp _ = inp λ x -> decode (derive-semantics sem (I x))\n... | out _ = out λ x -> decode (derive-semantics sem (O x))\n\ndecode-sub : ∀{X} (sem : Semantics X) -> ⟦ decode sem .force ⟧ ⊆ X\ndecode-sub sem tφ with kind? sem\ndecode-sub _ (_ , () , refl) | emp _\ndecode-sub _ (_ , _ , step () _) | emp _\ndecode-sub _ (_ , _ , refl) | eps (_ , sup) = sup refl\ndecode-sub _ (_ , _ , step (out ()) _) | eps _\ndecode-sub sem (_ , _ , refl) | inp w = non-empty-semantics-contains-[] sem w\ndecode-sub sem (_ , def , step inp tr) | inp w =\n decode-sub (derive-semantics sem (I _)) (_ , def , tr)\ndecode-sub sem (_ , _ , refl) | out w = non-empty-semantics-contains-[] sem w\ndecode-sub sem (_ , def , step (out !x) tr) | out w =\n decode-sub (derive-semantics sem (O _)) (_ , def , tr)\n\ndecode-sup : ∀{X} (sem : Semantics X) -> X ⊆ ⟦ decode sem .force ⟧\ndecode-sup sem {φ} hasφ with kind? sem\n... | emp sub = ⊥-elim (sub hasφ)\n... | eps (sub , _) rewrite sym (sub hasφ) = _ , out , refl\ndecode-sup sem {[]} hasφ | inp _ = _ , inp , refl\ndecode-sup sem {I _ ∷ _} hasφ | inp _ =\n let _ , def , tr = decode-sup (derive-semantics sem (I _)) hasφ in\n _ , def , step inp tr\ndecode-sup sem {O _ ∷ _} hasφ | inp w = ⊥-elim (coherent sem {[]} w hasφ)\ndecode-sup sem {[]} hasφ | out _ = _ , out , refl\ndecode-sup sem {I _ ∷ _} hasφ | out w = ⊥-elim (coherent sem {[]} hasφ w)\ndecode-sup sem {O _ ∷ _} hasφ | out _ =\n let _ , def , tr = decode-sup (derive-semantics sem (O _)) hasφ in\n _ , def , step (out (transitions+defined->defined tr def)) tr\n\ndecode+maximal->win :\n ∀{X φ}\n (sem : Semantics X)\n (rφ : decode sem .force HasTrace φ) ->\n φ ∈ Maximal X ->\n Win (after rφ)\ndecode+maximal->win sem rφ comp with kind? sem\ndecode+maximal->win sem (_ , () , refl) comp | emp sub\ndecode+maximal->win sem (_ , _ , step () _) comp | emp sub\ndecode+maximal->win sem (_ , _ , refl) comp | eps _ = Win-win\ndecode+maximal->win sem (_ , _ , step (out ()) _) comp | eps _\ndecode+maximal->win sem (_ , def , refl) (maximal _ F) | inp w with F none w\n... | ()\ndecode+maximal->win sem (_ , def , step inp tr) comp | inp _ =\n decode+maximal->win (derive-semantics sem (I _)) (_ , def , tr) (derive-maximal comp)\ndecode+maximal->win sem (_ , def , refl) (maximal _ F) | out w with F none w\n... | ()\ndecode+maximal->win sem (_ , def , step (out !x) tr) comp | out w =\n decode+maximal->win (derive-semantics sem (O _)) (_ , def , tr) (derive-maximal comp)\n\nwin->maximal :\n ∀{T φ ψ} ->\n φ ⊑ ψ ->\n (tφ : T HasTrace φ) ->\n T HasTrace ψ ->\n Win (after tφ) ->\n φ ≡ ψ\nwin->maximal le (_ , tdef , refl) (_ , sdef , refl) w = refl\nwin->maximal le (_ , tdef , refl) (_ , sdef , step (out !x) sr) (out U) = ⊥-elim (U _ !x)\nwin->maximal (some le) (_ , tdef , step inp tr) (_ , sdef , step inp sr) w\n rewrite win->maximal le (_ , tdef , tr) (_ , sdef , sr) w = refl\nwin->maximal (some le) (_ , tdef , step (out _) tr) (_ , sdef , step (out _) sr) w\n rewrite win->maximal le (_ , tdef , tr) (_ , sdef , sr) w = refl\n\ndecode+win->maximal :\n ∀{X φ}\n (sem : Semantics X)\n (rφ : decode sem .force HasTrace φ) ->\n Win (after rφ) ->\n φ ∈ Maximal X\ndecode+win->maximal {X} {φ} sem rφ w =\n maximal (decode-sub sem rφ) λ le xψ -> let rψ = decode-sup sem xψ in\n sym (win->maximal le rφ rψ w)\n", "meta": {"hexsha": "6aebbc6af5c4deda4b1aa7e227ad11d6e2989034", "size": 7152, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Semantics.agda", "max_stars_repo_name": "boystrange/FairSubtypingAgda", "max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z", "max_issues_repo_path": "src/Semantics.agda", "max_issues_repo_name": "boystrange/FairSubtypingAgda", "max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "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/Semantics.agda", "max_forks_repo_name": "boystrange/FairSubtypingAgda", "max_forks_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "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.2967032967, "max_line_length": 100, "alphanum_fraction": 0.6208053691, "num_tokens": 2401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7057850154599562, "lm_q2_score": 0.5, "lm_q1q2_score": 0.3528925077299781}} {"text": "module Pi-.Interp where\nopen import Data.Empty\nopen import Data.Unit\nopen import Data.Sum\nopen import Data.Product\nopen import Pi-.Syntax\nopen import Pi-.Opsem\nopen import Pi-.Eval\n\n{-# TERMINATING #-}\nmutual\n interp : {A B : 𝕌} → (A ↔ B) → Val A B → Val B A\n -- Forward\n interp unite₊l (inj₂ y ⃗) = y ⃗\n interp uniti₊l (v ⃗) = inj₂ v ⃗\n interp swap₊ (inj₁ x ⃗) = inj₂ x ⃗\n interp swap₊ (inj₂ y ⃗) = inj₁ y ⃗\n interp assocl₊ (inj₁ x ⃗) = inj₁ (inj₁ x) ⃗\n interp assocl₊ (inj₂ (inj₁ y) ⃗) = inj₁ (inj₂ y) ⃗\n interp assocl₊ (inj₂ (inj₂ z) ⃗) = inj₂ z ⃗\n interp assocr₊ (inj₁ (inj₁ x) ⃗) = inj₁ x ⃗\n interp assocr₊ (inj₁ (inj₂ y) ⃗) = inj₂ (inj₁ y) ⃗\n interp assocr₊ (inj₂ z ⃗) = inj₂ (inj₂ z) ⃗\n interp unite⋆l ((tt , v) ⃗) = v ⃗\n interp uniti⋆l (v ⃗) = (tt , v) ⃗\n interp swap⋆ ((x , y) ⃗) = (y , x) ⃗\n interp assocl⋆ ((x , (y , z)) ⃗) = ((x , y) , z) ⃗\n interp assocr⋆ (((x , y) , z) ⃗) = (x , y , z) ⃗\n interp dist ((inj₁ x , z) ⃗) = inj₁ (x , z) ⃗\n interp dist ((inj₂ y , z) ⃗) = inj₂ (y , z) ⃗\n interp factor (inj₁ (x , z) ⃗) = (inj₁ x , z) ⃗\n interp factor (inj₂ (y , z) ⃗) = (inj₂ y , z) ⃗\n interp id↔ (v ⃗) = v ⃗\n interp (c₁ ⨾ c₂) (v ⃗) with interp c₁ (v ⃗)\n interp (c₁ ⨾ c₂) (v ⃗) | (v' ⃖) = v' ⃖\n interp (c₁ ⨾ c₂) (v ⃗) | (v' ⃗) = c₁ ⨾[ v' ⃗]⨾ c₂\n interp (c₁ ⊕ c₂) (inj₁ x ⃗) with interp c₁ (x ⃗)\n interp (c₁ ⊕ c₂) (inj₁ x ⃗) | (x' ⃗) = inj₁ x' ⃗\n interp (c₁ ⊕ c₂) (inj₁ x ⃗) | (x' ⃖) = inj₁ x' ⃖\n interp (c₁ ⊕ c₂) (inj₂ y ⃗) with interp c₂ (y ⃗)\n interp (c₁ ⊕ c₂) (inj₂ y ⃗) | (y' ⃗) = inj₂ y' ⃗\n interp (c₁ ⊕ c₂) (inj₂ y ⃗) | (y' ⃖) = inj₂ y' ⃖\n interp (c₁ ⊗ c₂) ((x , y) ⃗) with interp c₁ (x ⃗)\n interp (c₁ ⊗ c₂) ((x , y) ⃗) | (x' ⃖) = (x' , y) ⃖\n interp (c₁ ⊗ c₂) ((x , y) ⃗) | (x' ⃗) with interp c₂ (y ⃗)\n interp (c₁ ⊗ c₂) ((x , y) ⃗) | (x' ⃗) | (y' ⃗) = (x' , y') ⃗\n interp (c₁ ⊗ c₂) ((x , y) ⃗) | (x' ⃗) | (y' ⃖) = (x , y') ⃖\n interp ε₊ (inj₁ v ⃗) = inj₂ (- v) ⃖\n interp ε₊ (inj₂ (- v) ⃗) = inj₁ v ⃖\n -- Backward\n interp unite₊l (v ⃖) = inj₂ v ⃖\n interp uniti₊l (inj₂ v ⃖) = v ⃖\n interp swap₊ (inj₁ x ⃖) = inj₂ x ⃖\n interp swap₊ (inj₂ y ⃖) = inj₁ y ⃖\n interp assocl₊ (inj₁ (inj₁ x) ⃖) = inj₁ x ⃖\n interp assocl₊ (inj₁ (inj₂ y) ⃖) = inj₂ (inj₁ y) ⃖\n interp assocl₊ (inj₂ z ⃖) = inj₂ (inj₂ z) ⃖\n interp assocr₊ (inj₁ x ⃖) = inj₁ (inj₁ x) ⃖\n interp assocr₊ (inj₂ (inj₁ y) ⃖) = inj₁ (inj₂ y) ⃖\n interp assocr₊ (inj₂ (inj₂ z) ⃖) = inj₂ z ⃖\n interp unite⋆l (v ⃖) = (tt , v) ⃖\n interp uniti⋆l ((tt , v) ⃖) = v ⃖\n interp swap⋆ ((x , y) ⃖) = (y , x) ⃖\n interp assocl⋆ (((x , y) , z) ⃖) = (x , (y , z)) ⃖\n interp assocr⋆ ((x , (y , z)) ⃖) = ((x , y) , z) ⃖\n interp dist (inj₁ (x , z) ⃖) = (inj₁ x , z) ⃖\n interp dist (inj₂ (y , z) ⃖) = (inj₂ y , z) ⃖\n interp factor ((inj₁ x , z) ⃖) = inj₁ (x , z) ⃖\n interp factor ((inj₂ y , z) ⃖) = inj₂ (y , z) ⃖\n interp id↔ (v ⃖) = v ⃖\n interp (c₁ ⨾ c₂) (v ⃖) with interp c₂ (v ⃖)\n interp (c₁ ⨾ c₂) (v ⃖) | v' ⃗ = v' ⃗\n interp (c₁ ⨾ c₂) (v ⃖) | v' ⃖ = c₁ ⨾[ v' ⃖]⨾ c₂\n interp (c₁ ⊕ c₂) (inj₁ x ⃖) with interp c₁ (x ⃖)\n interp (c₁ ⊕ c₂) (inj₁ x ⃖) | (x' ⃖) = inj₁ x' ⃖\n interp (c₁ ⊕ c₂) (inj₁ x ⃖) | (x' ⃗) = inj₁ x' ⃗\n interp (c₁ ⊕ c₂) (inj₂ y ⃖) with interp c₂ (y ⃖)\n interp (c₁ ⊕ c₂) (inj₂ y ⃖) | (y' ⃖) = inj₂ y' ⃖\n interp (c₁ ⊕ c₂) (inj₂ y ⃖) | (y' ⃗) = inj₂ y' ⃗\n interp (c₁ ⊗ c₂) ((x , y) ⃖) with interp c₂ (y ⃖)\n interp (c₁ ⊗ c₂) ((x , y) ⃖) | (y' ⃗) = (x , y') ⃗\n interp (c₁ ⊗ c₂) ((x , y) ⃖) | (y' ⃖) with interp c₁ (x ⃖)\n interp (c₁ ⊗ c₂) ((x , y) ⃖) | (y' ⃖) | (x' ⃖) = (x' , y') ⃖\n interp (c₁ ⊗ c₂) ((x , y) ⃖) | (y' ⃖) | (x' ⃗) = (x' , y) ⃗\n interp η₊ (inj₁ v ⃖) = inj₂ (- v) ⃗\n interp η₊ (inj₂ (- v) ⃖) = inj₁ v ⃗\n\n _⨾[_⃗]⨾_ : ∀ {A B C} → (A ↔ B) → ⟦ B ⟧ → (B ↔ C) → Val C A\n c₁ ⨾[ b ⃗]⨾ c₂ with interp c₂ (b ⃗)\n c₁ ⨾[ b ⃗]⨾ c₂ | c ⃗ = c ⃗\n c₁ ⨾[ b ⃗]⨾ c₂ | b' ⃖ = c₁ ⨾[ b' ⃖]⨾ c₂\n\n _⨾[_⃖]⨾_ : ∀ {A B C} → (A ↔ B) → ⟦ B ⟧ → (B ↔ C) → Val C A\n c₁ ⨾[ b ⃖]⨾ c₂ with interp c₁ (b ⃖)\n c₁ ⨾[ b ⃖]⨾ c₂ | a ⃖ = a ⃖\n c₁ ⨾[ b ⃖]⨾ c₂ | b' ⃗ = c₁ ⨾[ b' ⃗]⨾ c₂\n", "meta": {"hexsha": "ef9dd58b5d007921464f4231b041f7ccdd577662", "size": 4187, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Pi-/Interp.agda", "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_issues_repo_path": "Pi-/Interp.agda", "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "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": "Pi-/Interp.agda", "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "avg_line_length": 43.1649484536, "max_line_length": 62, "alphanum_fraction": 0.4303797468, "num_tokens": 2562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7279754489059775, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.35261680929265293}} {"text": "------------------------------------------------------------------------\n-- The semantics in Lambda.Closure.Relational and\n-- Lambda.Closure.Functional are equivalent\n------------------------------------------------------------------------\n\nmodule Lambda.Closure.Equivalence where\n\nopen import Axiom.ExcludedMiddle\nopen import Category.Monad.Partiality as Partiality\n using (_⊥; never; steps; module Steps)\nopen import Codata.Musical.Notation\nopen import Data.Empty using (⊥-elim)\nopen import Data.Maybe hiding (_>>=_)\nopen import Data.Nat\nopen import Data.Nat.Induction\nimport Data.Nat.Properties as ℕ\nimport Data.Nat.Solver as ℕ\nopen import Data.Product\nopen import Data.Sum\nopen import Data.Vec using (Vec; []; _∷_)\nopen import Function\nimport Level\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\nopen import Relation.Nullary\nopen import Relation.Nullary.Negation\n\nopen ℕ.+-*-Solver using (solve; _:=_; _:+_; con)\nopen Partiality._⊥\nprivate\n open module PE {A : Set} = Partiality.Equality (_≡_ {A = A})\n open module PR {A : Set} =\n Partiality.Reasoning (P.isEquivalence {A = A})\n hiding (_≡⟨_⟩_) renaming (_∎ to _□)\n\nopen import Lambda.Syntax\nopen Closure Tm\nopen import Lambda.Closure.Relational as R\nopen import Lambda.Closure.Functional as F hiding (module Workaround)\nopen PF\n\n------------------------------------------------------------------------\n-- Successful, terminating computations\n\n-- The functional semantics is complete with respect to the relational\n-- one.\n\ncomplete⇓ : ∀ {n} {t : Tm n} {ρ v} →\n ρ ⊢ t ⇓ v → ⟦ t ⟧ ρ ≈ return v\ncomplete⇓ var = _ □\ncomplete⇓ con = _ □\ncomplete⇓ ƛ = _ □\ncomplete⇓ {ρ = ρ} {v} (app {t₁} {t₂} {t = t} {ρ′} {v′ = v′} t₁⇓ t₂⇓ t₁t₂⇓) =\n ⟦ t₁ · t₂ ⟧ ρ ≅⟨ ·-comp t₁ t₂ ⟩\n ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≈⟨ complete⇓ t₁⇓ ⟦·⟧-cong complete⇓ t₂⇓ ⟩\n return (ƛ t ρ′) ⟦·⟧ return v′ ≳⟨ laterˡ (_ □) ⟩\n ⟦ t ⟧ (v′ ∷ ρ′) ≈⟨ complete⇓ t₁t₂⇓ ⟩\n return v □\n\n-- The functional semantics is sound with respect to the relational\n-- one.\n\nsound⇓ : ∀ {n} (t : Tm n) {ρ : Env n} {v} →\n ⟦ t ⟧ ρ ≈ return v → ρ ⊢ t ⇓ v\nsound⇓ t t⇓ = <′-rec P sound⇓′ (steps t⇓) t t⇓ P.refl\n where\n P : ℕ → Set\n P s = ∀ {n} (t : Tm n) {ρ : Env n} {v}\n (t⇓ : ⟦ t ⟧ ρ ≈ return v) → steps t⇓ ≡ s → ρ ⊢ t ⇓ v\n\n sound⇓′ : ∀ s → <′-Rec P s → P s\n sound⇓′ s rec (con i) (now P.refl) _ = con\n sound⇓′ s rec (var x) (now P.refl) _ = var\n sound⇓′ s rec (ƛ t) (now P.refl) _ = ƛ\n sound⇓′ s rec (t₁ · t₂) {ρ} {v} t₁t₂⇓ eq\n with >>=-inversion-⇓ (⟦ t₁ ⟧ ρ) (\n ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≅⟨ sym $ ·-comp t₁ t₂ ⟩\n ⟦ t₁ · t₂ ⟧ ρ ≈⟨ t₁t₂⇓ ⟩\n return v □)\n sound⇓′ s rec (t₁ · t₂) {ρ} t₁t₂⇓ eq | (v₁ , t₁⇓ , t₂∙⇓ , eq₁) with >>=-inversion-⇓ (⟦ t₂ ⟧ ρ) t₂∙⇓\n sound⇓′ s rec (t₁ · t₂) t₁t₂⇓ eq | (con i , t₁⇓ , t₂∙⇓ , eq₁) | (v₂ , t₂⇓ , now () , _ )\n sound⇓′ s rec (t₁ · t₂) {ρ} {v} t₁t₂⇓ eq | (ƛ t _ , t₁⇓ , t₂∙⇓ , eq₁) | (v₂ , t₂⇓ , laterˡ ∙⇓ , eq₂) =\n app (rec (steps t₁⇓) ₁< t₁ t₁⇓ P.refl)\n (rec (steps t₂⇓) ₂< t₂ t₂⇓ P.refl)\n (rec (steps ∙⇓) ∙< t ∙⇓ P.refl)\n where\n open ℕ.≤-Reasoning\n\n ₁₂∙< = begin\n 1 + steps t₁⇓ + (steps t₂⇓ + steps ∙⇓) ≡⟨ solve 3 (λ x y z → con 1 :+ x :+ (y :+ z) :=\n x :+ (y :+ (con 1 :+ z)))\n P.refl (steps t₁⇓) (steps t₂⇓) _ ⟩\n steps t₁⇓ + (steps t₂⇓ + (1 + steps ∙⇓)) ≡⟨ P.cong (_+_ (steps t₁⇓)) eq₂ ⟩\n steps t₁⇓ + steps t₂∙⇓ ≡⟨ eq₁ ⟩\n steps (⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≅⟨ sym $ ·-comp t₁ t₂ ⟩\n ⟦ t₁ · t₂ ⟧ ρ ≈⟨ t₁t₂⇓ ⟩\n return v □) ≡⟨ Steps.left-identity (sym $ ·-comp t₁ t₂) _ ⟩\n steps (⟦ t₁ · t₂ ⟧ ρ ≈⟨ t₁t₂⇓ ⟩\n return v □) ≡⟨ Steps.right-identity t₁t₂⇓ (return v □) ⟩\n steps t₁t₂⇓ ≡⟨ eq ⟩\n s ∎\n\n ₁< = ℕ.≤⇒≤′ (begin\n 1 + steps t₁⇓ ≤⟨ ℕ.m≤m+n (1 + steps t₁⇓) _ ⟩\n 1 + steps t₁⇓ + (steps t₂⇓ + steps ∙⇓) ≤⟨ ₁₂∙< ⟩\n s ∎)\n\n ₂∙< = begin\n 1 + steps t₂⇓ + steps ∙⇓ ≤⟨ s≤s (ℕ.m≤n+m _ (steps t₁⇓)) ⟩\n 1 + steps t₁⇓ + (steps t₂⇓ + steps ∙⇓) ≤⟨ ₁₂∙< ⟩\n s ∎\n\n ₂< = ℕ.≤⇒≤′ (begin\n 1 + steps t₂⇓ ≤⟨ ℕ.m≤m+n (1 + steps t₂⇓) _ ⟩\n 1 + steps t₂⇓ + steps ∙⇓ ≤⟨ ₂∙< ⟩\n s ∎)\n\n ∙< = ℕ.≤⇒≤′ (begin\n 1 + steps ∙⇓ ≤⟨ s≤s (ℕ.m≤n+m _ (steps t₂⇓)) ⟩\n 1 + steps t₂⇓ + steps ∙⇓ ≤⟨ ₂∙< ⟩\n s ∎)\n\n------------------------------------------------------------------------\n-- Non-terminating computations\n\n-- The functional semantics is complete for non-terminating computations.\n\nmodule Complete⇑ where\n\n infix 4 _≈P_ _≈W_\n infixr 2 _≅⟪_⟫_ _≳⟪_⟫_ _≈⟪_⟫_\n\n data _≈P_ : Maybe Value ⊥ → Maybe Value ⊥ → Set₁ where\n ⌈_⌉ : ∀ {x y} (x≳y : x ≳ y) → x ≈P y\n\n later : ∀ {x y} (x≈y : ∞ (♭ x ≈P ♭ y)) → later x ≈P later y\n\n _>>=P_ : ∀ {x₁ x₂ f₁ f₂} →\n (x₁≈x₂ : x₁ ≈P x₂) (f₁≈f₂ : ∀ x → f₁ x ≈P f₂ x) →\n (x₁ >>= f₁) ≈P (x₂ >>= f₂)\n _⟦·⟧P_ : ∀ {v₁₁ v₁₂ v₂₁ v₂₂} →\n (v₁₁≈v₂₁ : v₁₁ ≈P v₂₁) (v₁₂≈v₂₂ : v₁₂ ≈P v₂₂) →\n v₁₁ ⟦·⟧ v₁₂ ≈P v₂₁ ⟦·⟧ v₂₂\n\n _≅⟪_⟫_ : ∀ x {y z} (x≅y : x ≅ y) (y≈z : y ≈P z) → x ≈P z\n _≳⟪_⟫_ : ∀ x {y z} (x≳y : x ≳ y) (y≈z : y ≈P z) → x ≈P z\n _≈⟪_⟫_ : ∀ x {y z} (x≈y : x ≈P y) (y≅z : y ≅ z) → x ≈P z\n\n private\n\n data _≈W_ : Maybe Value ⊥ → Maybe Value ⊥ → Set₁ where\n now : ∀ {v} → now v ≈W now v\n later : ∀ {x y} (x≈y : ♭ x ≈P ♭ y) → later x ≈W later y\n laterˡ : ∀ {x y} (x≈y : ♭ x ≈W y) → later x ≈W y\n\n ⌈_⌉W : ∀ {x y} → x ≳ y → x ≈W y\n ⌈ now P.refl ⌉W = now\n ⌈ later x≳y ⌉W = later ⌈ ♭ x≳y ⌉\n ⌈ laterˡ x≳y ⌉W = laterˡ ⌈ x≳y ⌉W\n\n program : ∀ {x y} → x ≈W y → x ≈P y\n program now = ⌈ now P.refl ⌉\n program (later x≈y) = later (♯ x≈y)\n program (laterˡ x≈y) = _ ≳⟪ laterˡ (_ □) ⟫ program x≈y\n\n _>>=W_ : ∀ {x₁ x₂ f₁ f₂} →\n x₁ ≈W x₂ → (∀ x → f₁ x ≈W f₂ x) →\n (x₁ >>= f₁) ≈W (x₂ >>= f₂)\n now {v = nothing} >>=W f₁≈f₂ = now\n now {v = just v } >>=W f₁≈f₂ = f₁≈f₂ v\n later x≈y >>=W f₁≈f₂ = later (x≈y >>=P (program ∘ f₁≈f₂))\n laterˡ x≈y >>=W f₁≈f₂ = laterˡ (x≈y >>=W f₁≈f₂)\n\n _⟦·⟧W_ : ∀ {v₁₁ v₁₂ v₂₁ v₂₂} →\n v₁₁ ≈W v₂₁ → v₁₂ ≈W v₂₂ → v₁₁ ⟦·⟧ v₁₂ ≈W v₂₁ ⟦·⟧ v₂₂\n v₁₁≈v₂₁ ⟦·⟧W v₁₂≈v₂₂ =\n v₁₁≈v₂₁ >>=W λ v₁ →\n v₁₂≈v₂₂ >>=W λ v₂ →\n ⌈ ⟪ v₁ ∙ v₂ ⟫P □ ⌉W\n where open F.Workaround\n\n trans≅≈W : ∀ {x y z} → x ≅ y → y ≈W z → x ≈W z\n trans≅≈W (now P.refl) now = now\n trans≅≈W (later x≅y) (later y≈z) = later (_ ≅⟪ ♭ x≅y ⟫ y≈z)\n trans≅≈W (later x≅y) (laterˡ y≈z) = laterˡ (trans≅≈W (♭ x≅y) y≈z)\n\n trans≳≈W : ∀ {x y z} → x ≳ y → y ≈W z → x ≈W z\n trans≳≈W (now P.refl) now = now\n trans≳≈W (later x≳y) (later y≈z) = later (_ ≳⟪ ♭ x≳y ⟫ y≈z)\n trans≳≈W (later x≳y) (laterˡ y≈z) = laterˡ (trans≳≈W (♭ x≳y) y≈z)\n trans≳≈W (laterˡ x≳y) y≈z = laterˡ (trans≳≈W x≳y y≈z)\n\n trans≈W≅ : ∀ {x y z} → x ≈W y → y ≅ z → x ≈W z\n trans≈W≅ now (now P.refl) = now\n trans≈W≅ (later x≈y) (later y≅z) = later (_ ≈⟪ x≈y ⟫ ♭ y≅z)\n trans≈W≅ (laterˡ x≈y) y≅z = laterˡ (trans≈W≅ x≈y y≅z)\n\n whnf : ∀ {x y} → x ≈P y → x ≈W y\n whnf ⌈ x≳y ⌉ = ⌈ x≳y ⌉W\n whnf (later x≈y) = later (♭ x≈y)\n whnf (x₁≈x₂ >>=P f₁≈f₂) = whnf x₁≈x₂ >>=W λ v → whnf (f₁≈f₂ v)\n whnf (v₁₁≈v₂₁ ⟦·⟧P v₁₂≈v₂₂) = whnf v₁₁≈v₂₁ ⟦·⟧W whnf v₁₂≈v₂₂\n whnf (x ≅⟪ x≅y ⟫ y≈z) = trans≅≈W x≅y (whnf y≈z)\n whnf (x ≳⟪ x≳y ⟫ y≈z) = trans≳≈W x≳y (whnf y≈z)\n whnf (x ≈⟪ x≈y ⟫ y≅z) = trans≈W≅ (whnf x≈y) y≅z\n\n mutual\n\n -- Note that the types of soundW and soundP could be strengthened:\n -- laterʳ is not used.\n\n private\n\n soundW : ∀ {x y} → x ≈W y → x ≈ y\n soundW now = now P.refl\n soundW (later x≈y) = later (♯ soundP x≈y)\n soundW (laterˡ x≈y) = laterˡ (soundW x≈y)\n\n soundP : ∀ {x y} → x ≈P y → x ≈ y\n soundP x≈y = soundW (whnf x≈y)\n\n -- The language _≈P_ does not include transitivity for weak\n -- equality, as this would be unsound. Instead some limited notions\n -- of transitivity are used:\n --\n -- • Weak equality can be combined with strong equality on both\n -- sides.\n --\n -- • The _≳_ order can be \"prepended\" to a weak equality. Note that\n -- results of the form \"x ≈ return v\" can be turned into\n -- \"x ≳ return v\", as in the first case below.\n\n complete⇑ : ∀ {n} {t : Tm n} {ρ : Env n} →\n ρ ⊢ t ⇑ → ⟦ t ⟧ ρ ≈P never\n complete⇑ {ρ = ρ} (app {t₁} {t₂} {t = t} {ρ′} {v} t₁⇓ t₂⇓ t₁t₂⇑) =\n ⟦ t₁ · t₂ ⟧ ρ ≅⟪ ·-comp t₁ t₂ ⟫\n ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≳⟪ Partiality.now⇒now (complete⇓ t₁⇓) ⟦·⟧-cong\n Partiality.now⇒now (complete⇓ t₂⇓) ⟫\n return (ƛ t ρ′) ⟦·⟧ return v ≅⟪ later (♯ (_ □)) ⟫\n later (♯ ⟦ t ⟧ (v ∷ ρ′)) ≈⟪ later (♯ complete⇑ (♭ t₁t₂⇑)) ⟫\n never □\n complete⇑ {ρ = ρ} (·ˡ {t₁} {t₂} t₁⇑) =\n ⟦ t₁ · t₂ ⟧ ρ ≅⟪ ·-comp t₁ t₂ ⟫\n ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≈⟪ complete⇑ (♭ t₁⇑) ⟦·⟧P ⌈ ⟦ t₂ ⟧ ρ □ ⌉ ⟫\n never ⟦·⟧ ⟦ t₂ ⟧ ρ ≅⟨ Partiality.left-zero _ ⟩\n never □\n complete⇑ {ρ = ρ} (·ʳ {t₁} {t₂} {v} t₁⇓ t₂⇑) =\n ⟦ t₁ · t₂ ⟧ ρ ≅⟪ ·-comp t₁ t₂ ⟫\n ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≈⟪ ⌈ Partiality.now⇒now (complete⇓ t₁⇓) ⌉ ⟦·⟧P complete⇑ (♭ t₂⇑) ⟫\n return v ⟦·⟧ never ≅⟨ Partiality.left-zero _ ⟩\n never □\n\ncomplete⇑ : ∀ {n} {t : Tm n} {ρ : Env n} →\n ρ ⊢ t ⇑ → ⟦ t ⟧ ρ ≈ never\ncomplete⇑ = Complete⇑.soundP ∘ Complete⇑.complete⇑\n\n-- The functional semantics is sound for non-terminating computations.\n-- I assume excluded middle here because double-negation elimination\n-- is used \"infinitely often\".\n\nsound⇑ : ExcludedMiddle Level.zero →\n ∀ {n} (t : Tm n) {ρ : Env n} →\n ⟦ t ⟧ ρ ≈ never → ρ ⊢ t ⇑\nsound⇑ em (con i) i⇑ = ⊥-elim (Partiality.now≉never i⇑)\nsound⇑ em (var x) x⇑ = ⊥-elim (Partiality.now≉never x⇑)\nsound⇑ em (ƛ t) ƛ⇑ = ⊥-elim (Partiality.now≉never ƛ⇑)\nsound⇑ em (t₁ · t₂) {ρ} t₁t₂⇑\n with decidable-stable em $ >>=-inversion-⇑ (⟦ t₁ ⟧ ρ) (\n ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≅⟨ sym $ ·-comp t₁ t₂ ⟩\n ⟦ t₁ · t₂ ⟧ ρ ≈⟨ t₁t₂⇑ ⟩\n never □)\nsound⇑ em (t₁ · t₂) ⇑ | inj₁ t₁⇑ = ·ˡ (♯ sound⇑ em t₁ t₁⇑)\nsound⇑ em (t₁ · t₂) {ρ} ⇑ | inj₂ (v₁ , t₁⇓ , t₂∙⇑)\n with decidable-stable em $ >>=-inversion-⇑ (⟦ t₂ ⟧ ρ) t₂∙⇑\nsound⇑ em (t₁ · t₂) ⇑ | inj₂ (v₁ , t₁⇓ , t₂∙⇑) | inj₁ t₂⇑ = ·ʳ (sound⇓ t₁ t₁⇓) (♯ sound⇑ em t₂ t₂⇑)\nsound⇑ em (t₁ · t₂) ⇑ | inj₂ (con i , t₁⇓ , t₂∙⇑) | inj₂ (v₂ , t₂⇓ , ∙⇑) = ⊥-elim (Partiality.now≉never ∙⇑)\nsound⇑ em (t₁ · t₂) ⇑ | inj₂ (ƛ t _ , t₁⇓ , t₂∙⇑) | inj₂ (v₂ , t₂⇓ , ∙⇑) =\n app (sound⇓ t₁ t₁⇓) (sound⇓ t₂ t₂⇓) (♯ sound⇑ em t (Partiality.later⁻¹ ∙⇑))\n\n------------------------------------------------------------------------\n-- Crashing computations\n\n-- The functional semantics is complete for crashing computations.\n\ncomplete↯ : ExcludedMiddle Level.zero →\n ∀ {n} (t : Tm n) (ρ : Env n) →\n ρ ⊢ t ↯ → ⟦ t ⟧ ρ ≈ fail\ncomplete↯ em t ρ ¬⇒\n with decidable-stable em $\n Partiality.now-or-never {_∼_ = _≡_} P.refl\n {k = Partiality.weak} (⟦ t ⟧ ρ)\n... | inj₂ t⇑ = ⊥-elim (proj₂ ¬⇒ (sound⇑ em t t⇑))\n... | inj₁ (nothing , t↯) = t↯\n... | inj₁ (just v , t⇓) = ⊥-elim (proj₁ ¬⇒ (-, sound⇓ t t⇓))\n\n-- The functional semantics is sound for crashing computations.\n\nsound↯ : ∀ {n} {t : Tm n} {ρ : Env n} →\n ⟦ t ⟧ ρ ≈ fail → ρ ⊢ t ↯\nsound↯ {t = t} {ρ} t↯ = (¬⇓ , ¬⇑)\n where\n ¬⇓ : ¬ (∃ λ v → ρ ⊢ t ⇓ v)\n ¬⇓ (v , t⇓) with\n fail ≈⟨ sym t↯ ⟩\n ⟦ t ⟧ ρ ≈⟨ complete⇓ t⇓ ⟩\n return v □\n ... | now ()\n\n ¬⇑ : ¬ (ρ ⊢ t ⇑)\n ¬⇑ t⇑ = Partiality.now≉never (\n fail ≈⟨ sym t↯ ⟩\n ⟦ t ⟧ ρ ≈⟨ complete⇑ t⇑ ⟩\n never □)\n", "meta": {"hexsha": "c4dcb48bac13bef45990635ddad197df4e25f080", "size": 12524, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Lambda/Closure/Equivalence.agda", "max_stars_repo_name": "nad/codata", "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_issues_repo_path": "Lambda/Closure/Equivalence.agda", "max_issues_repo_name": "nad/codata", "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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": "Lambda/Closure/Equivalence.agda", "max_forks_repo_name": "nad/codata", "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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.0127795527, "max_line_length": 114, "alphanum_fraction": 0.436521878, "num_tokens": 6052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7279754371026367, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.3526168035753497}} {"text": "{-# OPTIONS --without-K #-}\nmodule Model.Term where\n\nopen import Cats.Category\n\nopen import Model.Size as MS using (_<_ ; ⟦_⟧Δ ; ⟦_⟧n ; ⟦_⟧σ)\nopen import Model.Type as MT\nopen import Util.HoTT.Equiv\nopen import Util.Prelude hiding (id ; _∘_ ; _×_)\nopen import Source.Size as SS using (v0 ; v1 ; ⋆)\nopen import Source.Size.Substitution.Theory\nopen import Source.Size.Substitution.Universe as SU using (Sub⊢ᵤ)\nopen import Source.Term\n\nimport Model.RGraph as RG\nimport Source.Type as ST\n\nopen Category._≅_\nopen MS.Size\nopen MS._<_\nopen MS._≤_\nopen RG._⇒_\nopen SS.Size\nopen SS.Ctx\nopen ST.Ctx\n\n\n⟦_⟧x : ∀ {Δ Γ x T}\n → Δ , Γ ⊢ₓ x ∶ T\n → ⟦ Γ ⟧Γ ⇒ ⟦ T ⟧T\n⟦_⟧x {Γ = Γ ∙ T} zero = π₂ ⟦ Γ ⟧Γ\n⟦ suc {U = U} x ⟧x = ⟦ x ⟧x ∘ π₁ ⟦ U ⟧T\n\n\n⟦abs⟧ : ∀ Δ (Γ : ST.Ctx Δ) T U\n → ⟦ Γ ∙ T ⟧Γ ⇒ ⟦ U ⟧T\n → ⟦ Γ ⟧Γ ⇒ ⟦ T ⟧T ↝ ⟦ U ⟧T\n⟦abs⟧ Δ Γ T U t = curry ⟦ Γ ⟧Γ ⟦ T ⟧T ⟦ U ⟧T t\n\n\n⟦app⟧ : ∀ Δ (Γ : ST.Ctx Δ) T U\n → ⟦ Γ ⟧Γ ⇒ ⟦ T ⟧T ↝ ⟦ U ⟧T\n → ⟦ Γ ⟧Γ ⇒ ⟦ T ⟧T\n → ⟦ Γ ⟧Γ ⇒ ⟦ U ⟧T\n⟦app⟧ Δ Γ T U t u = eval ⟦ T ⟧T ⟦ U ⟧T ∘ ⟨ t , u ⟩\n\n\n⟦absₛ⟧ : ∀ Δ n (Γ : ST.Ctx Δ) (T : ST.Type (Δ ∙ n))\n → ⟦ Γ [ SU.Wk ]ᵤ ⟧Γ ⇒ ⟦ T ⟧T\n → ⟦ Γ ⟧Γ ⇒ ⟦ ST.Π n , T ⟧T\n⟦absₛ⟧ Δ n Γ T t = MT.absₛ (t ∘ ⟦subΓ⟧ SU.Wk Γ .back)\n\n\n⟦appₛ⟧ : ∀ Δ m n (Γ : ST.Ctx Δ) T\n → ⟦ Γ ⟧Γ ⇒ ⟦ ST.Π n , T ⟧T\n → m SS.< n\n → ⟦ Γ ⟧Γ ⇒ ⟦ T [ SU.Sing m ]ᵤ ⟧T\n⟦appₛ⟧ Δ m n Γ T t m z\n-- (_,_) false -> a\n-- _ false -> a\n-- splitting on 1 after expandCatchAlls False:\n-- d false -> a\n-- splitting on 1 after expandCatchAlls False: <== NOW: True\n-- x (y,z) true -> z\n-- _ (_,_) false -> a <== WAS MISSING\n-- _ _ false -> a\n-- splitting on 2 after expandCatchAlls False:\n-- _ _ false -> a\n-- splitting on 3 after expandCatchAlls False:\n-- x y z true -> z\n-- x y z false -> a <== WAS MISSING\n", "meta": {"hexsha": "3fc4d0c890498829ab692d62671ae7183cd0ab63", "size": 1238, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Succeed/Issue1650.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/Succeed/Issue1650.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/Succeed/Issue1650.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": 25.7916666667, "max_line_length": 80, "alphanum_fraction": 0.6033925687, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6584175139669997, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.35231817710398156}} {"text": "------------------------------------------------------------------------\n-- Representation-independent results for non-dependent lenses\n------------------------------------------------------------------------\n\nimport Equality.Path as P\n\nmodule Lens.Non-dependent\n {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where\n\nopen P.Derived-definitions-and-properties eq\n\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude\n\nopen import Bijection equality-with-J as Bij using (module _↔_)\nopen import Equality.Decision-procedures equality-with-J\nopen import Equivalence equality-with-J using (_≃_)\nopen import Erased.Cubical eq\nopen import Function-universe equality-with-J as F hiding (_∘_)\nopen import H-level equality-with-J as H-level\nopen import H-level.Closure equality-with-J\nopen import H-level.Truncation.Propositional eq as T using (∥_∥)\nopen import Surjection equality-with-J using (_↠_)\n\nprivate\n variable\n a b c c₁ c₂ c₃ l : Level\n A B : Type a\n Lens₁ Lens₂ Lens₃ : Type a → Type b → Type c\n\n------------------------------------------------------------------------\n-- Some existence results\n\n-- There is, in general, no lens for the first projection from a\n-- Σ-type, assuming that lenses with contractible domains have\n-- contractible codomains.\n\nno-first-projection-lens :\n (Lens : Type → Type → Type a) →\n @0 (∀ {A B} → Lens A B → Contractible A → Contractible B) →\n ¬ Lens (∃ λ (b : Bool) → b ≡ true) Bool\nno-first-projection-lens _ contractible-to-contractible l =\n _↔_.to Erased-⊥↔⊥\n [ $⟨ singleton-contractible _ ⟩\n Contractible (Singleton true) ↝⟨ contractible-to-contractible l ⟩\n Contractible Bool ↝⟨ mono₁ 0 ⟩\n Is-proposition Bool ↝⟨ ¬-Bool-propositional ⟩□\n ⊥ □\n ]\n\n-- A variant of the previous result: If A is merely inhabited, and one\n-- can \"project\" out a boolean from a value of type A, but this\n-- boolean is necessarily true, then there is no lens corresponding to\n-- this projection (if the get-set law holds).\n\nno-singleton-projection-lens :\n {Lens : Type l}\n (get : Lens → A → Bool)\n (set : Lens → A → Bool → A)\n (get-set : ∀ l a b → get l (set l a b) ≡ b) →\n ∥ A ∥ →\n (bool : A → Bool) →\n (∀ x → bool x ≡ true) →\n ¬ ∃ λ (l : Lens) →\n ∀ x → get l x ≡ bool x\nno-singleton-projection-lens\n get set get-set x bool is-true (l , get≡bool) =\n _↔_.to Erased-⊥↔⊥\n [ (flip (T.rec ⊥-propositional) x λ x →\n Bool.true≢false\n (true ≡⟨ sym $ is-true _ ⟩\n bool (set l x false) ≡⟨ sym $ get≡bool _ ⟩\n get l (set l x false) ≡⟨ get-set _ _ _ ⟩∎\n false ∎))\n ]\n\n------------------------------------------------------------------------\n-- Statements of preservation results, and some related lemmas\n\n-- Lens-like things with getters and setters.\n\nrecord Has-getter-and-setter\n (Lens : Type a → Type b → Type c) :\n Type (lsuc (a ⊔ b ⊔ c)) where\n field\n -- Getter.\n get : {A : Type a} {B : Type b} → Lens A B → A → B\n\n -- Typeter.\n set : {A : Type a} {B : Type b} → Lens A B → A → B → A\n\n-- A statement of what it means for two lenses to have the same getter\n-- and setter.\n\nSame-getter-and-setter :\n {Lens₁ : Type a → Type b → Type c₁}\n {Lens₂ : Type a → Type b → Type c₂}\n ⦃ L₁ : Has-getter-and-setter Lens₁ ⦄\n ⦃ L₂ : Has-getter-and-setter Lens₂ ⦄\n {A : Type a} {B : Type b} →\n Lens₁ A B → Lens₂ A B → Type (a ⊔ b)\nSame-getter-and-setter ⦃ L₁ = L₁ ⦄ ⦃ L₂ = L₂ ⦄ l₁ l₂ =\n get L₁ l₁ ≡ get L₂ l₂ ×\n set L₁ l₁ ≡ set L₂ l₂\n where\n open Has-getter-and-setter\n\n-- A statement of what it means for a function to preserve getters and\n-- setters for all inputs.\n\nPreserves-getters-and-setters-→ :\n {Lens₁ : Type a → Type b → Type c₁}\n {Lens₂ : Type a → Type b → Type c₂}\n ⦃ L₁ : Has-getter-and-setter Lens₁ ⦄\n ⦃ L₂ : Has-getter-and-setter Lens₂ ⦄\n (A : Type a) (B : Type b) →\n (Lens₁ A B → Lens₂ A B) →\n Type (a ⊔ b ⊔ c₁)\nPreserves-getters-and-setters-→ {Lens₁ = Lens₁} A B f =\n (l : Lens₁ A B) → Same-getter-and-setter (f l) l\n\n-- A statement of what it means for a logical equivalence to preserve\n-- getters and setters.\n\nPreserves-getters-and-setters-⇔ :\n {Lens₁ : Type a → Type b → Type c₁}\n {Lens₂ : Type a → Type b → Type c₂}\n ⦃ L₁ : Has-getter-and-setter Lens₁ ⦄\n ⦃ L₂ : Has-getter-and-setter Lens₂ ⦄\n (A : Type a) (B : Type b) →\n (Lens₁ A B ⇔ Lens₂ A B) →\n Type (a ⊔ b ⊔ c₁ ⊔ c₂)\nPreserves-getters-and-setters-⇔ A B eq =\n Preserves-getters-and-setters-→ A B (_⇔_.to eq) ×\n Preserves-getters-and-setters-→ A B (_⇔_.from eq)\n\n-- Composition preserves Preserves-getters-and-setters-→.\n\nPreserves-getters-and-setters-→-∘ :\n ⦃ L₁ : Has-getter-and-setter Lens₁ ⦄\n ⦃ L₂ : Has-getter-and-setter Lens₂ ⦄\n ⦃ L₃ : Has-getter-and-setter Lens₃ ⦄\n {f : Lens₂ A B → Lens₃ A B}\n {g : Lens₁ A B → Lens₂ A B} →\n Preserves-getters-and-setters-→ A B f →\n Preserves-getters-and-setters-→ A B g →\n Preserves-getters-and-setters-→ A B (f ∘ g)\nPreserves-getters-and-setters-→-∘ p-f p-g _ =\n trans (proj₁ (p-f _)) (proj₁ (p-g _))\n , trans (proj₂ (p-f _)) (proj₂ (p-g _))\n\n-- Composition preserves Preserves-getters-and-setters-⇔.\n\nPreserves-getters-and-setters-⇔-∘ :\n {Lens₁ : Type a → Type b → Type c₁}\n {Lens₂ : Type a → Type b → Type c₂}\n {Lens₃ : Type a → Type b → Type c₃}\n ⦃ L₁ : Has-getter-and-setter Lens₁ ⦄\n ⦃ L₂ : Has-getter-and-setter Lens₂ ⦄\n ⦃ L₃ : Has-getter-and-setter Lens₃ ⦄\n {f : Lens₂ A B ⇔ Lens₃ A B}\n {g : Lens₁ A B ⇔ Lens₂ A B} →\n Preserves-getters-and-setters-⇔ A B f →\n Preserves-getters-and-setters-⇔ A B g →\n Preserves-getters-and-setters-⇔ A B (f F.∘ g)\nPreserves-getters-and-setters-⇔-∘ p-f p-g =\n Preserves-getters-and-setters-→-∘ (proj₁ p-f) (proj₁ p-g)\n , Preserves-getters-and-setters-→-∘ (proj₂ p-g) (proj₂ p-f)\n\n-- The function inverse preserves Preserves-getters-and-setters-⇔.\n\nPreserves-getters-and-setters-⇔-inverse :\n {Lens₁ : Type a → Type b → Type c₁}\n {Lens₂ : Type a → Type b → Type c₂}\n ⦃ L₁ : Has-getter-and-setter Lens₁ ⦄\n ⦃ L₂ : Has-getter-and-setter Lens₂ ⦄\n {f : Lens₁ A B ⇔ Lens₂ A B} →\n Preserves-getters-and-setters-⇔ A B f →\n Preserves-getters-and-setters-⇔ A B (inverse f)\nPreserves-getters-and-setters-⇔-inverse = swap\n\n-- If the forward direction of a split surjection preserves getters\n-- and setters, then both directions do.\n\nPreserves-getters-and-setters-→-↠-⇔ :\n {Lens₁ : Type a → Type b → Type c₁}\n {Lens₂ : Type a → Type b → Type c₂}\n ⦃ L₁ : Has-getter-and-setter Lens₁ ⦄\n ⦃ L₂ : Has-getter-and-setter Lens₂ ⦄\n (f : Lens₁ A B ↠ Lens₂ A B) →\n Preserves-getters-and-setters-→ A B (_↠_.to f) →\n Preserves-getters-and-setters-⇔ A B (_↠_.logical-equivalence f)\nPreserves-getters-and-setters-→-↠-⇔ ⦃ L₁ = L₁ ⦄ ⦃ L₂ = L₂ ⦄ f p =\n p\n , λ l →\n (get L₁ (_↠_.from f l) ≡⟨ sym $ proj₁ $ p (_↠_.from f l) ⟩\n get L₂ (_↠_.to f (_↠_.from f l)) ≡⟨ cong (get L₂) $ _↠_.right-inverse-of f _ ⟩∎\n get L₂ l ∎)\n , (set L₁ (_↠_.from f l) ≡⟨ sym $ proj₂ $ p (_↠_.from f l) ⟩\n set L₂ (_↠_.to f (_↠_.from f l)) ≡⟨ cong (set L₂) $ _↠_.right-inverse-of f _ ⟩∎\n set L₂ l ∎)\n where\n open Has-getter-and-setter\n", "meta": {"hexsha": "00d5a56a3bc6a335b883ec9aef68bd97f01ffe78", "size": 7302, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Lens/Non-dependent.agda", "max_stars_repo_name": "nad/dependent-lenses", "max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z", "max_issues_repo_path": "src/Lens/Non-dependent.agda", "max_issues_repo_name": "nad/dependent-lenses", "max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "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/Lens/Non-dependent.agda", "max_forks_repo_name": "nad/dependent-lenses", "max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z", "avg_line_length": 35.7941176471, "max_line_length": 89, "alphanum_fraction": 0.5858668858, "num_tokens": 2581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6442250928250375, "lm_q2_score": 0.546738151984614, "lm_q1q2_score": 0.35222243671327735}} {"text": "-- Andreas, 2017-01-05, issue #2376\n-- Ensure correct printing for termination error\n\n-- {-# OPTIONS -v term.clause:30 #-}\n\npostulate\n id : ∀{a}{A : Set a} → A → A\n A : Set\n P : A → Set\n\nf : {a : A} → P a → {b : A} → P b → Set\nf = λ p → f (id p) -- id to prevent eta-contration before termination checking\n\n-- Expected termination error:\n-- ...\n-- Problematic calls:\n-- f (id p)\n", "meta": {"hexsha": "90efa55186abdfb221c8f0c3c99508ee21e9bef1", "size": 385, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "test/Fail/Issue2376Lambda.agda", "max_stars_repo_name": "shlevy/agda", "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": ["BSD-3-Clause"], "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/Issue2376Lambda.agda", "max_issues_repo_name": "shlevy/agda", "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_licenses": ["BSD-3-Clause"], "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/Issue2376Lambda.agda", "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": ["BSD-3-Clause"], "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": 21.3888888889, "max_line_length": 79, "alphanum_fraction": 0.5818181818, "num_tokens": 132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.626124191181315, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.35199230691826217}} {"text": "------------------------------------------------------------------------\n-- Semantics of the simplified parsers\n------------------------------------------------------------------------\n\nmodule StructurallyRecursiveDescentParsing.Simplified.Semantics where\n\nopen import Algebra\nopen import Codata.Musical.Notation\nopen import Data.Bool\nopen import Data.List\nimport Data.List.Properties\nprivate\n module LM {Tok : Set} = Monoid (Data.List.Properties.++-monoid Tok)\nopen import Data.Product as Prod\nopen import Function\nopen import Data.Empty\nopen import Relation.Binary.PropositionalEquality as P using (_≡_)\n\nopen import StructurallyRecursiveDescentParsing.Simplified\nopen import TotalParserCombinators.Parser using (○; ◌)\nopen import TotalParserCombinators.Semantics as Semantics\n using ([_-_]_>>=_) renaming (_∈_·_ to _∈′_·_)\nopen Semantics._∈_·_\n\n------------------------------------------------------------------------\n-- Semantics\n\n-- The semantics of the parsers. x ∈ p · s means that x can be the\n-- result of applying the parser p to the string s. Note that the\n-- semantics is defined inductively.\n\ninfixl 10 _?>>=_ _!>>=_\ninfix 4 _∈_·_\n\ndata _∈_·_ {Tok} : ∀ {R e} → R → Parser Tok e R → List Tok → Set1 where\n return : ∀ {R} {x : R} → x ∈ return x · []\n token : ∀ {x} → x ∈ token · [ x ]\n ∣ˡ : ∀ {R x e₁ e₂ s} {p₁ : Parser Tok e₁ R} {p₂ : Parser Tok e₂ R}\n (x∈p₁ : x ∈ p₁ · s) → x ∈ p₁ ∣ p₂ · s\n ∣ʳ : ∀ {R x e₂ s} e₁ {p₁ : Parser Tok e₁ R} {p₂ : Parser Tok e₂ R}\n (x∈p₂ : x ∈ p₂ · s) → x ∈ p₁ ∣ p₂ · s\n _?>>=_ : ∀ {R₁ R₂ x y e₂ s₁ s₂}\n {p₁ : Parser Tok true R₁} {p₂ : R₁ → Parser Tok e₂ R₂}\n (x∈p₁ : x ∈ p₁ · s₁) (y∈p₂x : y ∈ p₂ x · s₂) →\n y ∈ p₁ ?>>= p₂ · s₁ ++ s₂\n _!>>=_ : ∀ {R₁ R₂ x y} {e₂ : R₁ → Bool} {s₁ s₂}\n {p₁ : Parser Tok false R₁}\n {p₂ : (x : R₁) → ∞ (Parser Tok (e₂ x) R₂)}\n (x∈p₁ : x ∈ p₁ · s₁) (y∈p₂x : y ∈ ♭ (p₂ x) · s₂) →\n y ∈ p₁ !>>= p₂ · s₁ ++ s₂\n\n------------------------------------------------------------------------\n-- _∈_·_ is correct with respect to _∈′_·_\n\nsound : ∀ {Tok e R} {p : Parser Tok e R} {x s} →\n x ∈ p · s → x ∈′ ⟦ p ⟧ · s\nsound return = return\nsound token = token\nsound (∣ˡ x∈p₁) = cast (∣-left (sound x∈p₁))\nsound (∣ʳ _ {p₁} x∈p₂) = cast (∣-right (initial p₁) (sound x∈p₂))\nsound (_?>>=_ {p₂ = p₂}\n x∈p₁ y∈p₂x) = cast ([_-_]_>>=_ ○ ○ {p₂ = λ x → ⟦ p₂ x ⟧}\n (sound x∈p₁) (sound y∈p₂x))\nsound (x∈p₁ !>>= y∈p₂x) = [ ○ - ◌ ] sound x∈p₁ >>= sound y∈p₂x\n\ncomplete : ∀ {Tok e R} (p : Parser Tok e R) {x s} →\n x ∈′ ⟦ p ⟧ · s → x ∈ p · s\ncomplete (return x) return = return\ncomplete fail ()\ncomplete token token = token\ncomplete (p₁ ∣ p₂) (cast (∣-left x∈p₁)) = ∣ˡ (complete p₁ x∈p₁)\ncomplete (_∣_ {e₁} p₁ p₂) (cast (∣-right ._ x∈p₂)) = ∣ʳ e₁ (complete p₂ x∈p₂)\ncomplete (p₁ ?>>= p₂) (cast (x∈p₁ >>= y∈p₂x)) = complete p₁ x∈p₁ ?>>= complete (p₂ _) y∈p₂x\ncomplete (p₁ !>>= p₂) (x∈p₁ >>= y∈p₂x) = complete p₁ x∈p₁ !>>= complete (♭ (p₂ _)) y∈p₂x\n\n------------------------------------------------------------------------\n-- A lemma\n\n-- A simple cast lemma.\n\ncast∈ : ∀ {Tok e R} {p p′ : Parser Tok e R} {x x′ s s′} →\n x ≡ x′ → p ≡ p′ → s ≡ s′ → x ∈ p · s → x′ ∈ p′ · s′\ncast∈ P.refl P.refl P.refl x∈ = x∈\n\n------------------------------------------------------------------------\n-- A variant of the semantics\n\n-- The statement x ⊕ s₂ ∈ p · s means that there is some s₁ such that\n-- s ≡ s₁ ++ s₂ and x ∈ p · s₁. This variant of the semantics is\n-- perhaps harder to understand, but sometimes easier to work with\n-- (and it is proved equivalent to the semantics above).\n\ninfix 4 _⊕_∈_·_\n\ndata _⊕_∈_·_ {Tok} : ∀ {R e} → R → List Tok →\n Parser Tok e R → List Tok → Set1 where\n return : ∀ {R} {x : R} {s} → x ⊕ s ∈ return x · s\n token : ∀ {x s} → x ⊕ s ∈ token · x ∷ s\n ∣ˡ : ∀ {R x e₁ e₂ s s₁}\n {p₁ : Parser Tok e₁ R} {p₂ : Parser Tok e₂ R}\n (x∈p₁ : x ⊕ s₁ ∈ p₁ · s) → x ⊕ s₁ ∈ p₁ ∣ p₂ · s\n ∣ʳ : ∀ {R x e₂ s s₁} e₁\n {p₁ : Parser Tok e₁ R} {p₂ : Parser Tok e₂ R}\n (x∈p₂ : x ⊕ s₁ ∈ p₂ · s) → x ⊕ s₁ ∈ p₁ ∣ p₂ · s\n _?>>=_ : ∀ {R₁ R₂ x y e₂ s s₁ s₂}\n {p₁ : Parser Tok true R₁} {p₂ : R₁ → Parser Tok e₂ R₂}\n (x∈p₁ : x ⊕ s₁ ∈ p₁ · s) (y∈p₂x : y ⊕ s₂ ∈ p₂ x · s₁) →\n y ⊕ s₂ ∈ p₁ ?>>= p₂ · s\n _!>>=_ : ∀ {R₁ R₂ x y} {e₂ : R₁ → Bool} {s s₁ s₂}\n {p₁ : Parser Tok false R₁}\n {p₂ : (x : R₁) → ∞ (Parser Tok (e₂ x) R₂)}\n (x∈p₁ : x ⊕ s₁ ∈ p₁ · s) (y∈p₂x : y ⊕ s₂ ∈ ♭ (p₂ x) · s₁) →\n y ⊕ s₂ ∈ p₁ !>>= p₂ · s\n\n-- The definition is sound and complete with respect to the one above.\n\n⊕-sound′ : ∀ {Tok R e x s₂ s} {p : Parser Tok e R} →\n x ⊕ s₂ ∈ p · s → ∃ λ s₁ → (s ≡ s₁ ++ s₂) × (x ∈ p · s₁)\n⊕-sound′ return = ([] , P.refl , return)\n⊕-sound′ {x = x} token = ([ x ] , P.refl , token)\n⊕-sound′ (∣ˡ x∈p₁) with ⊕-sound′ x∈p₁\n⊕-sound′ (∣ˡ x∈p₁) | (s₁ , P.refl , x∈p₁′) = (s₁ , P.refl , ∣ˡ x∈p₁′)\n⊕-sound′ (∣ʳ e₁ x∈p₁) with ⊕-sound′ x∈p₁\n⊕-sound′ (∣ʳ e₁ x∈p₁) | (s₁ , P.refl , x∈p₁′) = (s₁ , P.refl , ∣ʳ e₁ x∈p₁′)\n⊕-sound′ (x∈p₁ ?>>= y∈p₂x) with ⊕-sound′ x∈p₁ | ⊕-sound′ y∈p₂x\n⊕-sound′ (x∈p₁ ?>>= y∈p₂x) | (s₁ , P.refl , x∈p₁′) | (s₂ , P.refl , y∈p₂x′) =\n (s₁ ++ s₂ , P.sym (LM.assoc s₁ s₂ _)\n , x∈p₁′ ?>>= y∈p₂x′)\n⊕-sound′ (x∈p₁ !>>= y∈p₂x) with ⊕-sound′ x∈p₁ | ⊕-sound′ y∈p₂x\n⊕-sound′ (x∈p₁ !>>= y∈p₂x) | (s₁ , P.refl , x∈p₁′) | (s₂ , P.refl , y∈p₂x′) =\n (s₁ ++ s₂ , P.sym (LM.assoc s₁ s₂ _)\n , x∈p₁′ !>>= y∈p₂x′)\n\n⊕-sound : ∀ {Tok R e x s} {p : Parser Tok e R} →\n x ⊕ [] ∈ p · s → x ∈ p · s\n⊕-sound x∈p with ⊕-sound′ x∈p\n⊕-sound x∈p | (s , P.refl , x∈p′) with s ++ [] | proj₂ LM.identity s\n⊕-sound x∈p | (s , P.refl , x∈p′) | .s | P.refl = x∈p′\n\nextend : ∀ {Tok R e x s s′ s″} {p : Parser Tok e R} →\n x ⊕ s′ ∈ p · s → x ⊕ s′ ++ s″ ∈ p · s ++ s″\nextend return = return\nextend token = token\nextend (∣ˡ x∈p₁) = ∣ˡ (extend x∈p₁)\nextend (∣ʳ e₁ x∈p₂) = ∣ʳ e₁ (extend x∈p₂)\nextend (x∈p₁ ?>>= y∈p₂x) = extend x∈p₁ ?>>= extend y∈p₂x\nextend (x∈p₁ !>>= y∈p₂x) = extend x∈p₁ !>>= extend y∈p₂x\n\n⊕-complete : ∀ {Tok R e x s} {p : Parser Tok e R} →\n x ∈ p · s → x ⊕ [] ∈ p · s\n⊕-complete return = return\n⊕-complete token = token\n⊕-complete (∣ˡ x∈p₁) = ∣ˡ (⊕-complete x∈p₁)\n⊕-complete (∣ʳ e₁ x∈p₂) = ∣ʳ e₁ (⊕-complete x∈p₂)\n⊕-complete (x∈p₁ ?>>= y∈p₂x) = extend (⊕-complete x∈p₁) ?>>=\n ⊕-complete y∈p₂x\n⊕-complete (x∈p₁ !>>= y∈p₂x) = extend (⊕-complete x∈p₁) !>>=\n ⊕-complete y∈p₂x\n\n⊕-complete′ : ∀ {Tok R e x s₂ s} {p : Parser Tok e R} →\n (∃ λ s₁ → s ≡ s₁ ++ s₂ × x ∈ p · s₁) →\n x ⊕ s₂ ∈ p · s\n⊕-complete′ (s₁ , P.refl , x∈p) = extend (⊕-complete x∈p)\n", "meta": {"hexsha": "36b4bf417ee4518bc210c2fae908010ddc2a7981", "size": 7254, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "StructurallyRecursiveDescentParsing/Simplified/Semantics.agda", "max_stars_repo_name": "nad/parser-combinators", "max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z", "max_issues_repo_path": "StructurallyRecursiveDescentParsing/Simplified/Semantics.agda", "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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": "StructurallyRecursiveDescentParsing/Simplified/Semantics.agda", "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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": 44.2317073171, "max_line_length": 100, "alphanum_fraction": 0.4440308795, "num_tokens": 3058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.35199229907420687}} {"text": "\nopen import Oscar.Prelude\nopen import Oscar.Class.Transitivity\n\nmodule Oscar.Class.Congruity where\n\nmodule _ where\n\n module _\n {ℓ} (_∼_ : ∀ {𝔬} {𝔒 : Ø 𝔬} → 𝔒 → 𝔒 → Ø ℓ)\n 𝔵 𝔶\n where\n 𝓬ongruity = ∀ {𝔛 : Ø 𝔵} {𝔜 : Ø 𝔶} {x₁ x₂} (f : 𝔛 → 𝔜) → x₁ ∼ x₂ → f x₁ ∼ f x₂\n record 𝓒ongruity : Ø ℓ ∙̂ ↑̂ (𝔵 ∙̂ 𝔶) where\n field congruity : 𝓬ongruity\n\n open 𝓒ongruity ⦃ … ⦄ public\n\n module _\n {ℓ} (_∼_ : ∀ {𝔬} {𝔒 : Ø 𝔬} → 𝔒 → 𝔒 → Ø ℓ)\n {𝔵 𝔶} (𝔛 : Ø 𝔵) (𝔜 : Ø 𝔶)\n where\n 𝓬ongruity' = ∀ {x₁ x₂} (f : 𝔛 → 𝔜) → x₁ ∼ x₂ → f x₁ ∼ f x₂\n record 𝓒ongruity' : Ø ℓ ∙̂ ↑̂ (𝔵 ∙̂ 𝔶) where\n field congruity' : 𝓬ongruity'\n\n open 𝓒ongruity' ⦃ … ⦄ public\n\n module _\n {ℓ} {𝔬} (_∼_ : ∀ {𝔒 : Ø 𝔬} → 𝔒 → 𝔒 → Ø ℓ)\n (𝔛 𝔜 : Ø 𝔬)\n where\n 𝓬ongruity'' = ∀ {x₁ x₂} (f : 𝔛 → 𝔜) → x₁ ∼ x₂ → f x₁ ∼ f x₂\n record 𝓒ongruity'' : Ø ℓ ∙̂ 𝔬 where\n field congruity'' : 𝓬ongruity''\n\n open 𝓒ongruity'' ⦃ … ⦄ public\n\n-- a functional replacement of 𝓒ongruity₂ (but note the additional requirement of 𝓣ransitivity)\ncongruity2 : ∀ {ℓ} {_∼_ : ∀ {x} {X : Ø x} → X → X → Ø ℓ}\n {𝔵 𝔶 𝔷}\n ⦃ _ : 𝓒ongruity _∼_ 𝔵 (𝔶 ∙̂ 𝔷) ⦄\n ⦃ _ : 𝓒ongruity _∼_ (𝔶 ∙̂ 𝔷) 𝔷 ⦄\n ⦃ _ : 𝓒ongruity _∼_ 𝔶 (𝔵 ∙̂ 𝔷) ⦄\n ⦃ _ : 𝓒ongruity _∼_ (𝔵 ∙̂ 𝔷) 𝔷 ⦄\n ⦃ _ : ∀ {x} {X : Ø x} → Transitivity.class (_∼_ {X = X}) ⦄\n → ∀ {𝔛 : Ø 𝔵} {𝔜 : Ø 𝔶} {ℨ : Ø 𝔷} {x₁ x₂} {y₁ y₂} (f : 𝔛 → 𝔜 → ℨ) → x₁ ∼ x₂ → y₁ ∼ y₂ → f x₁ y₁ ∼ f x₂ y₂\ncongruity2 {𝔛 = 𝔛}{𝔜}{ℨ}{x₁}{x₂}{y₁}{y₂} f x₁∼x₂ y₁∼y₂ =\n let fx1=fx2 = congruity f x₁∼x₂ in\n let g2 = λ (fx : 𝔜 → ℨ) → fx y₂ in\n let fx1y2=fx2y2 = congruity g2 fx1=fx2 in\n let e = flip f in\n let ey1=ey2 = congruity e y₁∼y₂ in\n let h1 = λ (ex : 𝔛 → ℨ) → ex x₁ in\n let fx1y1=fx1y2 = congruity h1 ey1=ey2 in\n transitivity fx1y1=fx1y2 fx1y2=fx2y2\n\nmodule _ where\n\n record 𝓒ongruity₂\n {ℓ} (_∼_ : ∀ {x} {X : Ø x} → X → X → Ø ℓ)\n 𝔵 𝔶 𝔷\n : Ø ℓ ∙̂ ↑̂ (𝔵 ∙̂ 𝔶 ∙̂ 𝔷) where\n field congruity₂ : ∀ {𝔛 : Ø 𝔵} {𝔜 : Ø 𝔶} {ℨ : Ø 𝔷} {x₁ x₂} {y₁ y₂} (f : 𝔛 → 𝔜 → ℨ) → x₁ ∼ x₂ → y₁ ∼ y₂ → f x₁ y₁ ∼ f x₂ y₂\n\n open 𝓒ongruity₂ ⦃ … ⦄ public\n\nmodule _ where\n\n module _\n 𝔬 𝔭\n {ℓ} (_∼̇_ : ∀ {⋆ : Ø 𝔬} {⋆̇ : ⋆ → Ø 𝔭} → ((𝓞 : ⋆) → ⋆̇ 𝓞) → ((𝓞 : ⋆) → ⋆̇ 𝓞) → Ø ℓ)\n (let infix 4 _∼̇_ ; _∼̇_ = _∼̇_)\n where\n record 𝓒̇ongruity : Ø ↑̂ (𝔬 ∙̂ 𝔭) ∙̂ ℓ where\n field ċongruity : ∀ {⋆ : Ø 𝔬} {⋆̇ : ⋆ → Ø 𝔭} {f₁ f₂ : (𝓞 : ⋆) → ⋆̇ 𝓞} (G : ∀ {𝓞 : ⋆} → ⋆̇ 𝓞 → ⋆̇ 𝓞) → f₁ ∼̇ f₂ → G ∘ f₁ ∼̇ G ∘ f₂\n\n open 𝓒̇ongruity ⦃ … ⦄ public\n", "meta": {"hexsha": "1313ba8b88ec1a88595204772b2e99aa89db2203", "size": 2440, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Congruity.agda", "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Congruity.agda", "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Congruity.agda", "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8860759494, "max_line_length": 136, "alphanum_fraction": 0.4790983607, "num_tokens": 1574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737473266735, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.35194861807132233}} {"text": "------------------------------------------------------------------------\n-- Well-typed substitutions\n------------------------------------------------------------------------\n\n{-# OPTIONS --safe --without-K #-}\n\nmodule Data.Fin.Substitution.Typed where\n\nopen import Data.Context as Ctx hiding (map)\nopen import Data.Context.WellFormed\nopen import Data.Context.Properties using (module ContextFormationLemmas)\nopen import Data.Fin using (Fin; zero; suc)\nopen import Data.Fin.Substitution\nopen import Data.Fin.Substitution.Lemmas\nopen import Data.Fin.Substitution.ExtraLemmas\nopen import Data.Nat using (ℕ; suc)\nopen import Data.Vec as Vec using (Vec; []; _∷_; map)\nopen import Data.Vec.Properties using (map-cong; map-∘; lookup-map)\nopen import Data.Vec.Relation.Binary.Pointwise.Inductive as PW\n using (Pointwise; []; _∷_)\nopen import Function as Fun using (_∘_)\nopen import Level using (_⊔_) renaming (zero to lzero; suc to lsuc)\nopen import Relation.Binary.PropositionalEquality\nopen ≡-Reasoning\nopen import Relation.Unary using (Pred)\n\n\n------------------------------------------------------------------------\n-- Abstract typing\n--\n-- Well-typed substitutions are defined over an abstract \"type\n-- system\", i.e. a pair of formation and typing judgments and\n-- substitution lemmas for raw terms and types.\n\n-- An abtract typing judgment _⊢_∈_ : Typing Bnd Term Type is a\n-- ternary relation which, in a given Bnd-context, relates Term-terms\n-- to their Type-types.\n\nTyping : ∀ {t₁ t₂ t₃} →\n Pred ℕ t₁ → Pred ℕ t₂ → Pred ℕ t₃ → ∀ ℓ →\n Set (t₁ ⊔ t₂ ⊔ t₃ ⊔ lsuc ℓ)\nTyping Bnd Term Type ℓ = ∀ {n} → Ctx Bnd n → Term n → Type n → Set ℓ\n\n\n------------------------------------------------------------------------\n-- Abstract well-typed substitutions (aka context morphisms)\n\nrecord TypedSub {t}\n (Type : Pred ℕ t) -- Type syntax\n (Term : Pred ℕ lzero) -- Term syntax\n ℓ\n : Set (lsuc (t ⊔ ℓ)) where\n\n -- The underlying type assignment system\n\n infix 4 _⊢_∈_ _⊢_wf\n\n field\n _⊢_wf : Wf Type Type ℓ -- Type formation judgment\n _⊢_∈_ : Typing Type Term Type ℓ -- Typing judgment\n\n -- Weakening and term substitutions in types.\n\n field\n typeExtension : Extension Type -- weakening of types\n typeTermApplication : Application Type Term -- app. of term subst.\n termSimple : Simple Term -- simple term subst.\n\n open ContextFormation _⊢_wf using (_wf)\n open Application typeTermApplication using (_/_)\n\n infix 4 _⊢/_∈_\n infixr 5 _∷_\n\n -- Typed substitutions.\n --\n -- A typed substitution Δ ⊢/ σ ∈ Γ is a substitution σ which, when\n -- applied to a well-typed term Γ ⊢ t ∈ a in a source context Γ,\n -- yields a well-typed term Δ ⊢ t / σ ∈ a / σ in a well-formed\n -- target context Δ.\n\n data _⊢/_∈_ {n} (Δ : Ctx Type n) :\n ∀ {m} → Sub Term m n → Ctx Type m → Set (t ⊔ ℓ) where\n [] : Δ wf → Δ ⊢/ [] ∈ []\n _∷_ : ∀ {m t} {a : Type m} {σ : Sub Term m n} {Γ} →\n Δ ⊢ t ∈ a / σ → Δ ⊢/ σ ∈ Γ → Δ ⊢/ t ∷ σ ∈ a ∷ Γ\n\n -- The domains of well-typed substitutions are well-formed.\n\n /∈-wf : ∀ {m n Δ} {σ : Sub Term m n} {Γ} → Δ ⊢/ σ ∈ Γ → Δ wf\n /∈-wf ([] Δ-wf) = Δ-wf\n /∈-wf (_ ∷ σ∈Γ) = /∈-wf σ∈Γ\n\n\n------------------------------------------------------------------------\n-- Operations on abstract well-typed substitutions\n\n-- Operations on abstract typed substitutions that require weakening\n-- of well-typed terms\n\nrecord TypedWeakenOps {t ℓ} {Type : Pred ℕ t} {Term : Pred ℕ lzero}\n (typedSub : TypedSub Type Term ℓ)\n : Set (lsuc (t ⊔ ℓ)) where\n\n open TypedSub typedSub\n\n -- Operations on contexts and raw terms that require weakening\n\n private\n termExtension : Extension Term\n termExtension = record { weaken = Simple.weaken termSimple }\n\n module E = Extension termExtension\n module C = WeakenOps typeExtension\n\n open Simple termSimple using (wk)\n open Application typeTermApplication using (_/_; _⊙_)\n open ContextFormation _⊢_wf using (_wf; _∷_; wf-∷₁)\n\n field\n\n -- Weakening preserves well-typed terms.\n\n ∈-weaken : ∀ {n} {Δ : Ctx Type n} {t a b} → Δ ⊢ a wf → Δ ⊢ t ∈ b →\n (a ∷ Δ) ⊢ E.weaken t ∈ C.weaken b\n\n -- Well-typedness implies well-formedness of contexts.\n\n ∈-wf : ∀ {n} {Δ : Ctx Type n} {t a} → Δ ⊢ t ∈ a → Δ wf\n\n -- Lemmas relating type weakening to term substitutions\n\n /-wk : ∀ {n} {a : Type n} → a / wk ≡ C.weaken a\n\n /-weaken : ∀ {m n} {σ : Sub Term m n} a →\n a / map E.weaken σ ≡ a / σ / wk\n\n weaken-/-∷ : ∀ {n m} {t} {σ : Sub Term m n} (a : Type m) →\n C.weaken a / (t ∷ σ) ≡ a / σ\n\n -- Some helper lemmas\n\n /-map-weaken : ∀ {m n} a (ρ : Sub Term m n) →\n C.weaken (a / ρ) ≡ a / map E.weaken ρ\n /-map-weaken a ρ = begin\n C.weaken (a / ρ) ≡⟨ sym /-wk ⟩\n a / ρ / wk ≡⟨ sym (/-weaken a) ⟩\n a / map E.weaken ρ ∎\n\n map-weaken-⊙-∷ : ∀ {m n} (σ : Sub Type m m) t (ρ : Sub Term m n) →\n σ ⊙ ρ ≡ map C.weaken σ ⊙ (t ∷ ρ)\n map-weaken-⊙-∷ σ t ρ = sym (begin\n map C.weaken σ ⊙ (t ∷ ρ) ≡⟨ sym (map-∘ _ C.weaken σ) ⟩\n map ((_/ (t ∷ ρ)) ∘ C.weaken) σ ≡⟨ map-cong weaken-/-∷ σ ⟩\n map (_/ ρ) σ ≡⟨⟩\n σ ⊙ ρ ∎)\n\n -- Weakening preserves well-typed substitutions.\n\n /∈-weaken : ∀ {m n Δ a} {σ : Sub Term m n} {Γ} →\n Δ ⊢ a wf → Δ ⊢/ σ ∈ Γ →\n (a ∷ Δ) ⊢/ map E.weaken σ ∈ Γ\n /∈-weaken a-wf ([] Δ-wf) = [] (a-wf ∷ Δ-wf)\n /∈-weaken {_} {_} {Δ} {a} {t ∷ σ} a-wf (t∈b/σ ∷ σ∈Γ) =\n subst (a ∷ Δ ⊢ _ ∈_) (/-map-weaken _ σ) (∈-weaken a-wf t∈b/σ) ∷\n (/∈-weaken a-wf σ∈Γ)\n\n\n -- A typed substitution consists of pointwise-typed terms.\n\n toPointwise : ∀ {m n Δ} {σ : Sub Term m n} {Γ} →\n Δ ⊢/ σ ∈ Γ → Pointwise (Δ ⊢_∈_) σ (C.toVec Γ ⊙ σ)\n toPointwise ([] Δ-wf) = []\n toPointwise {_} {_} {Δ} {t ∷ σ} (t∈a/σ ∷ σ∈Γ) =\n subst (Δ ⊢ t ∈_) (sym (weaken-/-∷ _)) t∈a/σ ∷\n subst (Pointwise (_⊢_∈_ Δ) σ) (map-weaken-⊙-∷ _ t σ) (toPointwise σ∈Γ)\n\n -- Look up an entry in a typed substitution.\n\n lookup : ∀ {m n Δ} {σ : Sub Term m n} {Γ} →\n Δ ⊢/ σ ∈ Γ → (x : Fin m) → Δ ⊢ Vec.lookup σ x ∈ C.lookup Γ x / σ\n lookup {_} {_} {Δ} {σ} {Γ} σ∈Γ x =\n subst (Δ ⊢ _ ∈_) (lookup-map x _ (C.toVec Γ))\n (PW.lookup (toPointwise σ∈Γ) x)\n\n -- Extension by a typed term.\n\n ∈-/∷ : ∀ {m n Δ} {σ : Sub Term m n} {Γ t a b} →\n (b ∷ Δ) ⊢ t ∈ C.weaken (a / σ) → Δ ⊢/ σ ∈ Γ →\n b ∷ Δ ⊢/ t E./∷ σ ∈ a ∷ Γ\n ∈-/∷ t∈a/σ σ∈Γ =\n subst (_⊢_∈_ _ _) (/-map-weaken _ _) t∈a/σ ∷ /∈-weaken b-wf σ∈Γ\n\n where\n b∷Δ-wf = ∈-wf t∈a/σ\n b-wf = wf-∷₁ b∷Δ-wf\n\n-- Operations on abstract typed substitutions that require simple term\n-- substitutions\n\nrecord TypedSimple {t ℓ} {Type : Pred ℕ t} {Term : Pred ℕ lzero}\n (typedSub : TypedSub Type Term ℓ)\n : Set (lsuc (t ⊔ ℓ)) where\n\n -- Operations on abstract typed substitutions that require weakening\n -- of terms\n\n field typedWeakenOps : TypedWeakenOps typedSub\n\n open TypedWeakenOps typedWeakenOps public\n open TypedSub typedSub\n open ContextFormation _⊢_wf using (_wf; _⊢_wfExt; []; _∷_; wf-∷₂)\n open Application typeTermApplication using (_/_)\n\n private\n module S = Simple termSimple\n module C = WeakenOps typeExtension\n open S using (_↑; _↑⋆_; id; wk; sub)\n\n -- Context operations that require term substitutions in types.\n\n open SubstOps typeTermApplication termSimple using (_E/_)\n\n field\n\n -- Takes variables to well-typed Tms.\n\n ∈-var : ∀ {n} {Γ : Ctx Type n} →\n ∀ x → Γ wf → Γ ⊢ S.var x ∈ C.lookup Γ x\n\n -- Well-formedness of types implies well-formedness of contexts.\n\n wf-wf : ∀ {n} {Γ : Ctx Type n} {a} → Γ ⊢ a wf → Γ wf\n\n -- The identity substitution is an identity\n\n id-vanishes : ∀ {n} (a : Type n) → a / id ≡ a\n\n -- Lifting.\n\n ∈-↑ : ∀ {m n Δ} {σ : Sub Term m n} {a Γ} →\n Δ ⊢ a / σ wf → Δ ⊢/ σ ∈ Γ → a / σ ∷ Δ ⊢/ σ ↑ ∈ a ∷ Γ\n ∈-↑ a/σ-wf σ∈Γ = ∈-/∷ (∈-var zero (a/σ-wf ∷ (wf-wf a/σ-wf))) σ∈Γ\n\n ∈-↑⋆ : ∀ {k m n Δ} {E : CtxExt Type m k} {σ : Sub Term m n} {Γ} →\n Δ ⊢ (E E/ σ) wfExt → Δ ⊢/ σ ∈ Γ → (E E/ σ) ++ Δ ⊢/ σ ↑⋆ k ∈ (E ++ Γ)\n ∈-↑⋆ {E = []} [] σ∈Γ = σ∈Γ\n ∈-↑⋆ {E = a ∷ E} {Δ} {Γ} (a/σ↑⋆1+k-wf ∷ E/σ-wfExt) σ∈Γ =\n ∈-↑ {Γ = E ++ Γ} a/σ↑⋆1+k-wf (∈-↑⋆ {E = E} E/σ-wfExt σ∈Γ)\n\n -- The identity substitution.\n\n ∈-id : ∀ {n} {Γ : Ctx Type n} → Γ wf → Γ ⊢/ id ∈ Γ\n ∈-id [] = [] []\n ∈-id (a-wf ∷ Γ-wf) =\n ∈-/∷ (subst (_ ⊢ S.var zero ∈_) (sym (cong C.weaken (id-vanishes _)))\n (∈-var zero (a-wf ∷ Γ-wf)))\n (∈-id Γ-wf)\n\n -- Weakening.\n\n ∈-wk : ∀ {n} {Γ : Ctx Type n} {a} → Γ ⊢ a wf → a ∷ Γ ⊢/ wk ∈ Γ\n ∈-wk a-wf = /∈-weaken a-wf (∈-id (wf-wf a-wf))\n\n -- A substitution which only replaces the first variable.\n\n ∈-sub : ∀ {n} {Γ : Ctx Type n} {t a} → Γ ⊢ t ∈ a → Γ ⊢/ sub t ∈ a ∷ Γ\n ∈-sub t∈a =\n (subst (_ ⊢ _ ∈_) (sym (id-vanishes _)) t∈a) ∷ (∈-id (∈-wf t∈a))\n\n\n -- A substitution which only changes the type of the first variable.\n\n ∈-tsub : ∀ {n} {Γ : Ctx Type n} {a b} → b ∷ Γ ⊢ S.var zero ∈ C.weaken a →\n b ∷ Γ ⊢/ id ∈ a ∷ Γ\n ∈-tsub z∈a =\n ∈-/∷ (subst (_ ⊢ _ ∈_) (cong C.weaken (sym (id-vanishes _))) z∈a)\n (∈-id (wf-∷₂ (∈-wf z∈a)))\n\n-- Application of typed substitutions to typed terms.\n\nrecord TypedApplication {t ℓ} {Type : Pred ℕ t} {Term : Pred ℕ lzero}\n (typedSub : TypedSub Type Term ℓ)\n : Set (lsuc (t ⊔ ℓ)) where\n\n open TypedSub typedSub\n open Application typeTermApplication using (_/_)\n\n -- Applications of term substitutions to terms\n\n field termTermApplication : Application Term Term\n\n private\n module C = WeakenOps typeExtension\n module A = Application termTermApplication\n open A using (_⊙_)\n\n field\n\n -- Post-application of substitutions to things.\n\n ∈-/ : ∀ {m n Δ} {σ : Sub Term m n} {Γ t a} →\n Γ ⊢ t ∈ a → Δ ⊢/ σ ∈ Γ → Δ ⊢ t A./ σ ∈ a / σ\n\n -- Application of composed substitutions is repeated application.\n\n /-⊙ : ∀ {m n k} {σ : Sub Term m n} {ρ : Sub Term n k} a →\n a / σ ⊙ ρ ≡ a / σ / ρ\n\n -- Reverse composition. (Fits well with post-application.)\n\n ∈-⊙ : ∀ {m n k Δ Γ E} {σ : Sub Term m n} {ρ : Sub Term n k} →\n Δ ⊢/ σ ∈ Γ → E ⊢/ ρ ∈ Δ → E ⊢/ σ ⊙ ρ ∈ Γ\n ∈-⊙ ([] Δ-wf) ρ∈Δ = [] (/∈-wf ρ∈Δ)\n ∈-⊙ (t∈a/σ ∷ σ∈Γ) ρ∈Δ =\n (subst (_ ⊢ _ ∈_) (sym (/-⊙ _)) (∈-/ t∈a/σ ρ∈Δ)) ∷ (∈-⊙ σ∈Γ ρ∈Δ)\n\n\n------------------------------------------------------------------------\n-- Instantiations and code for facilitating instantiations\n\n-- Abstract typed liftings from Term₁ to Term₂ terms\n\nrecord LiftTyped {t ℓ₁ ℓ₂} {Type : Pred ℕ t} {Term₁ Term₂ : Pred ℕ lzero}\n (typeTermSubst : TermLikeSubst Type Term₂)\n (_⊢_wf : Wf Type Type ℓ₁)\n (_⊢₁_∈_ : Typing Type Term₁ Type ℓ₁)\n (_⊢₂_∈_ : Typing Type Term₂ Type ℓ₂)\n : Set (lsuc (t ⊔ ℓ₁ ⊔ ℓ₂)) where\n\n field rawLift : Lift Term₁ Term₂ -- Lifting between raw terms\n\n open TermLikeSubst typeTermSubst using (app; weaken; termSubst)\n private module S₂ = TermSubst termSubst\n\n typedSub : TypedSub Type Term₁ ℓ₁\n typedSub = record\n { _⊢_wf = _⊢_wf\n ; _⊢_∈_ = _⊢₁_∈_\n ; typeExtension = record { weaken = weaken }\n ; typeTermApplication = record { _/_ = app rawLift }\n ; termSimple = Lift.simple rawLift\n }\n open TypedSub typedSub public hiding (_⊢_wf; _⊢_∈_; typeExtension)\n\n -- Simple typed Term₁ substitutions.\n\n field typedSimple : TypedSimple typedSub\n\n open Lift rawLift public\n open Application typeTermApplication public\n open TypedSimple typedSimple public hiding (_⊢_∈_)\n\n field\n\n -- Lifts well-typed Term₁-terms to well-typed Term₂-terms.\n\n ∈-lift : ∀ {n} {Γ : Ctx Type n} {t a} → Γ ⊢₁ t ∈ a → Γ ⊢₂ (lift t) ∈ a\n\n -- A usefule lemma: lifting preserves variables.\n\n lift-var : ∀ {n} (x : Fin n) → lift (var x) ≡ S₂.var x\n\n\n-- Abstract variable typings.\n\nmodule VarTyping {t ℓ} {Type : Pred ℕ t}\n (_⊢_wf : Wf Type Type (t ⊔ ℓ))\n (typeExtension : Extension Type) where\n\n open ContextFormation _⊢_wf\n open WeakenOps typeExtension\n\n infix 4 _⊢Var_∈_\n\n -- Abstract reflexive variable typings.\n\n data _⊢Var_∈_ {n} (Γ : Ctx Type n) : Fin n → Type n → Set (t ⊔ ℓ) where\n ∈-var : ∀ x → Γ wf → Γ ⊢Var x ∈ lookup Γ x\n\n -- Variable typing together with type formation forms\n -- a type assignment system.\n\n-- Abstract typed variable substitutions (renamings).\n\nrecord TypedVarSubst {t} (Type : Pred ℕ t) ℓ : Set (lsuc (t ⊔ ℓ)) where\n\n infix 4 _⊢_wf\n\n field\n _⊢_wf : Wf Type Type (t ⊔ ℓ) -- Type formation judgment\n\n -- Generic application of renamings to raw types\n\n typeExtension : Extension Type\n typeVarApplication : Application Type Fin\n\n open VarTyping {t} {t ⊔ ℓ} _⊢_wf typeExtension public\n\n open WeakenOps typeExtension using (weaken; toVec)\n open Application typeVarApplication using (_/_)\n open ContextFormation _⊢_wf using (_wf; _∷_)\n open VarSubst using (id; wk; _⊙_)\n\n field\n\n -- Context validity of type formation.\n\n wf-wf : ∀ {n} {Γ : Ctx Type n} {a} → Γ ⊢ a wf → Γ wf\n\n -- Lemmas about renamings in types\n\n /-wk : ∀ {n} {a : Type n} → a / wk ≡ weaken a\n id-vanishes : ∀ {n} (a : Type n) → a / id ≡ a\n /-⊙ : ∀ {m n k} {ρ₁ : Sub Fin m n} {ρ₂ : Sub Fin n k} a →\n a / ρ₁ ⊙ ρ₂ ≡ a / ρ₁ / ρ₂\n\n -- Typed renamings and associated lemmas.\n\n typedRenaming : TypedSub Type Fin (t ⊔ ℓ)\n typedRenaming = record\n { _⊢_wf = _⊢_wf\n ; _⊢_∈_ = _⊢Var_∈_\n ; typeExtension = typeExtension\n ; typeTermApplication = typeVarApplication\n ; termSimple = VarSubst.simple\n }\n\n appLemmas : AppLemmas Type Fin\n appLemmas = record\n { application = typeVarApplication\n ; lemmas₄ = VarLemmas.lemmas₄\n ; id-vanishes = id-vanishes\n ; /-⊙ = /-⊙\n }\n\n weakenLemmas : WeakenLemmas Type Fin\n weakenLemmas = record\n { appLemmas = appLemmas\n ; /-wk = /-wk\n }\n\n open AppLemmas appLemmas using (/-weaken)\n open WeakenLemmas weakenLemmas using (weaken-/-∷)\n\n -- Simple typed renamings.\n\n typedSimple : TypedSimple typedRenaming\n typedSimple = record\n { typedWeakenOps = record\n { ∈-weaken = ∈-weaken\n ; ∈-wf = ∈-wf\n ; /-wk = /-wk\n ; /-weaken = /-weaken\n ; weaken-/-∷ = weaken-/-∷\n }\n ; ∈-var = ∈-var\n ; wf-wf = wf-wf\n ; id-vanishes = id-vanishes\n }\n where\n\n ∈-weaken : ∀ {n} {Γ : Ctx Type n} {x a b} →\n Γ ⊢ a wf → Γ ⊢Var x ∈ b →\n a ∷ Γ ⊢Var suc x ∈ weaken b\n ∈-weaken {_} {Γ} a-wf (∈-var x Γ-wf) =\n subst (_ ∷ Γ ⊢Var _ ∈_) (lookup-map x weaken (toVec Γ))\n (∈-var (suc x) (a-wf ∷ Γ-wf))\n\n ∈-wf : ∀ {n} {Γ : Ctx Type n} {x a} → Γ ⊢Var x ∈ a → Γ wf\n ∈-wf (∈-var x Γ-wf) = Γ-wf\n\n open TypedSub typedRenaming public\n renaming (_⊢/_∈_ to _⊢/Var_∈_) hiding (_⊢_wf; _/_)\n open TypedSimple typedSimple public\n hiding (typeExtension; _/_; _⊢_∈_; ∈-var; _⊢_wf; wf-wf; /-wk; id-vanishes)\n\n -- Applications of typed renamings to typed variables\n\n typedApplication : TypedApplication typedRenaming\n typedApplication = record\n { termTermApplication = VarSubst.application\n ; ∈-/ = ∈-/\n ; /-⊙ = /-⊙\n }\n where\n\n ∈-/ : ∀ {m n Δ} {ρ : Sub Fin m n} {Γ x a} →\n Γ ⊢Var x ∈ a → Δ ⊢/Var ρ ∈ Γ → Δ ⊢Var Vec.lookup ρ x ∈ a / ρ\n ∈-/ (∈-var x Γ-wf) ρ∈Γ = lookup ρ∈Γ x\n\n open TypedApplication typedApplication public\n using (_/_; ∈-/; ∈-⊙)\n\n-- Abstract typed term substitutions.\n\nrecord TypedTermSubst {t h} (Type : Pred ℕ t) (Term : Pred ℕ lzero) ℓ\n (Helpers : ∀ {T} → Lift T Term → Set h)\n : Set (lsuc (t ⊔ ℓ) ⊔ h) where\n\n infix 4 _⊢_∈_ _⊢_wf\n\n field\n _⊢_wf : Wf Type Type (t ⊔ ℓ) -- Type formation judgment\n _⊢_∈_ : Typing Type Term Type (t ⊔ ℓ) -- Typing judgment\n\n -- Lemmas about term substitutions in Types\n\n termLikeLemmas : TermLikeLemmas Type Term\n\n private\n module Tp = TermLikeLemmas termLikeLemmas\n module Tm = TermLemmas Tp.termLemmas\n module S = TermSubst Tm.termSubst\n\n typeExtension : Extension Type\n typeExtension = record { weaken = Tp.weaken }\n\n private module C = WeakenOps typeExtension\n\n typedSub : TypedSub Type Term (t ⊔ ℓ)\n typedSub = record\n { _⊢_wf = _⊢_wf\n ; _⊢_∈_ = _⊢_∈_\n ; typeExtension = typeExtension\n ; termSimple = S.simple\n ; typeTermApplication = Tp.termApplication\n }\n\n open ContextFormation _⊢_wf using (_wf)\n\n field\n\n -- Custom helper lemmas used to implement application of typed\n -- substitutions\n\n varHelpers : Helpers S.varLift -- lemmas about renamings\n termHelpers : Helpers S.termLift -- lemmas about substitutions\n\n -- Context validity of type formation and typing.\n\n wf-wf : ∀ {n} {Γ : Ctx Type n} {a} → Γ ⊢ a wf → Γ wf\n ∈-wf : ∀ {n} {Γ : Ctx Type n} {t a} → Γ ⊢ t ∈ a → Γ wf\n\n -- Takes variables to well-typed Tms.\n\n ∈-var : ∀ {n} {Γ : Ctx Type n} →\n ∀ x → Γ wf → Γ ⊢ S.var x ∈ C.lookup Γ x\n\n -- Generic application of typed Term′ substitutions to typed Terms.\n\n typedApp : ∀ {Term′ : Pred ℕ lzero}\n (_⊢′_∈_ : Typing Type Term′ Type (t ⊔ ℓ))\n (liftTyped : LiftTyped Tp.termLikeSubst _⊢_wf _⊢′_∈_ _⊢_∈_) →\n let open LiftTyped liftTyped using (rawLift; _⊢/_∈_; _/_)\n in (helpers : Helpers rawLift) →\n ∀ {m n Γ Δ t a} {σ : Sub Term′ m n} →\n Γ ⊢ t ∈ a → Δ ⊢/ σ ∈ Γ → Δ ⊢ S.app rawLift t σ ∈ a / σ\n\n typedVarSubst : TypedVarSubst Type (t ⊔ ℓ)\n typedVarSubst = record\n { _⊢_wf = _⊢_wf\n ; typeVarApplication = Tp.varApplication\n ; typeExtension = typeExtension\n ; wf-wf = wf-wf\n ; /-wk = refl\n ; id-vanishes = id-vanishes\n ; /-⊙ = /-⊙\n }\n where\n open LiftSubLemmas Tp.varLiftSubLemmas using (liftAppLemmas)\n open LiftAppLemmas liftAppLemmas using (id-vanishes; /-⊙)\n\n open TypedVarSubst typedVarSubst public\n using (_⊢Var_∈_; _⊢/Var_∈_; typedRenaming)\n renaming\n ( typedSimple to varTypedSimple\n ; ∈-var to Var∈-var\n ; ∈-↑ to Var∈-↑\n ; ∈-id to Var∈-id\n ; ∈-wk to Var∈-wk\n ; ∈-sub to Var∈-sub\n ; ∈-tsub to Var∈-tsub\n )\n\n varLiftTyped : LiftTyped Tp.termLikeSubst _⊢_wf _⊢Var_∈_ _⊢_∈_\n varLiftTyped = record\n { rawLift = S.varLift\n ; typedSimple = varTypedSimple\n ; ∈-lift = ∈-lift\n ; lift-var = λ _ → refl\n }\n where\n\n ∈-lift : ∀ {n Γ x} {a : Type n} → Γ ⊢Var x ∈ a → Γ ⊢ S.var x ∈ a\n ∈-lift (Var∈-var x Γ-wf) = ∈-var x Γ-wf\n\n ∈-/Var : ∀ {m n} {Γ t a} {ρ : Sub Fin m n} {Δ} →\n Δ ⊢ t ∈ a → Γ ⊢/Var ρ ∈ Δ → Γ ⊢ t S./Var ρ ∈ a Tp./Var ρ\n ∈-/Var = typedApp _⊢Var_∈_ varLiftTyped varHelpers\n\n -- Operations on well-formed contexts that require weakening of\n -- well-formedness judgments.\n\n -- Simple typed substitutions.\n\n typedSimple : TypedSimple typedSub\n typedSimple = record\n { typedWeakenOps = record\n { ∈-weaken = λ a-wf t∈b → ∈-/Var t∈b (Var∈-wk a-wf)\n ; ∈-wf = ∈-wf\n ; /-wk = Tp./-wk\n ; /-weaken = Tp./-weaken\n ; weaken-/-∷ = Tp.weaken-/-∷\n }\n ; ∈-var = ∈-var\n ; wf-wf = wf-wf\n ; id-vanishes = Tp.id-vanishes\n }\n\n termLiftTyped : LiftTyped Tp.termLikeSubst _⊢_wf _⊢_∈_ _⊢_∈_\n termLiftTyped = record\n { rawLift = S.termLift\n ; typedSimple = typedSimple\n ; ∈-lift = Fun.id\n ; lift-var = λ _ → refl\n }\n\n -- Applications of typed term substitutions to typed terms\n\n typedApplication : TypedApplication typedSub\n typedApplication = record\n { termTermApplication = S.application\n ; ∈-/ = typedApp _⊢_∈_ termLiftTyped termHelpers\n ; /-⊙ = Tp./-⊙\n }\n\n open TypedSub typedSub public hiding (typeExtension)\n open TypedSimple typedSimple public hiding\n ( typeExtension; ∈-weaken; ∈-wf; ∈-var; wf-wf\n ; /-wk; /-weaken; weaken-/-∷; id-vanishes\n )\n open TypedApplication typedApplication public hiding (/-⊙)\n", "meta": {"hexsha": "45d8c37f0c97be1135d1e6cca438e3c5a2d51057", "size": 20684, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Data/Fin/Substitution/Typed.agda", "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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/Data/Fin/Substitution/Typed.agda", "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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/Data/Fin/Substitution/Typed.agda", "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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": 32.1180124224, "max_line_length": 78, "alphanum_fraction": 0.5370818024, "num_tokens": 7454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6825737344123242, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.3519486114124266}} {"text": "{-# OPTIONS --without-K #-}\nmodule well-typed-syntax-pre-interpreter where\nopen import common public\nopen import well-typed-syntax\nopen import well-typed-syntax-helpers\n\nmax-level : Level\nmax-level = lsuc lzero\n\nmodule inner\n (context-pick-if' : ∀ ℓ (P : Context → Set ℓ)\n (Γ : Context)\n (dummy : P (ε ▻ ‘Σ’ ‘Context’ ‘Typ’))\n (val : P Γ) →\n P (ε ▻ ‘Σ’ ‘Context’ ‘Typ’))\n (context-pick-if-refl' : ∀ ℓ P dummy val →\n context-pick-if' ℓ P (ε ▻ ‘Σ’ ‘Context’ ‘Typ’) dummy val ≡ val)\n where\n\n context-pick-if : ∀ {ℓ} {P : Context → Set ℓ}\n {Γ : Context}\n (dummy : P (ε ▻ ‘Σ’ ‘Context’ ‘Typ’))\n (val : P Γ) →\n P (ε ▻ ‘Σ’ ‘Context’ ‘Typ’)\n context-pick-if {P = P} dummy val = context-pick-if' _ P _ dummy val\n context-pick-if-refl : ∀ {ℓ P dummy val} →\n context-pick-if {ℓ} {P} {ε ▻ ‘Σ’ ‘Context’ ‘Typ’} dummy val ≡ val\n context-pick-if-refl {P = P} = context-pick-if-refl' _ P _ _\n\n private\n dummy : Typ ε\n dummy = ‘Context’\n\n cast-helper : ∀ {X T A} {x : Term X} → A ≡ T → Term {ε} (T ‘’ x ‘→'’ A ‘’ x)\n cast-helper refl = ‘λ∙’ ‘VAR₀’\n\n cast'-proof : ∀ {T} → Term {ε} (context-pick-if {P = Typ} (W dummy) T ‘’ ‘existT’ ⌜ ε ▻ ‘Σ’ ‘Context’ ‘Typ’ ⌝c ⌜ T ⌝T\n ‘→'’ T ‘’ ‘existT’ ⌜ ε ▻ ‘Σ’ ‘Context’ ‘Typ’ ⌝c ⌜ T ⌝T)\n cast'-proof {T} = cast-helper {‘Σ’ ‘Context’ ‘Typ’}\n {context-pick-if {P = Typ} {ε ▻ ‘Σ’ ‘Context’ ‘Typ’} (W dummy) T}\n {T} (sym (context-pick-if-refl {P = Typ} {dummy = W dummy}))\n\n cast-proof : ∀ {T} → Term {ε} (T ‘’ ‘existT’ ⌜ ε ▻ ‘Σ’ ‘Context’ ‘Typ’ ⌝c ⌜ T ⌝T\n ‘→'’ context-pick-if {P = Typ} (W dummy) T ‘’ ‘existT’ ⌜ ε ▻ ‘Σ’ ‘Context’ ‘Typ’ ⌝c ⌜ T ⌝T)\n cast-proof {T} = cast-helper {‘Σ’ ‘Context’ ‘Typ’} {T}\n {context-pick-if {P = Typ} {ε ▻ ‘Σ’ ‘Context’ ‘Typ’} (W dummy) T}\n (context-pick-if-refl {P = Typ} {dummy = W dummy})\n\n ‘idfun’ : ∀ {T} → Term {ε} (T ‘→'’ T)\n ‘idfun’ = ‘λ∙’ ‘VAR₀’\n\n mutual\n Context⇓ : (Γ : Context) → Set (lsuc max-level)\n Typ⇓ : {Γ : Context} → Typ Γ → Context⇓ Γ → Set max-level\n\n Context⇓ ε = ⊤\n Context⇓ (Γ ▻ T) = Σ (Context⇓ Γ) (λ Γ' → Typ⇓ T Γ')\n\n Typ⇓ (T₁ ‘’ x) Γ⇓ = Typ⇓ T₁ (Γ⇓ , Term⇓ x Γ⇓)\n Typ⇓ (T₂ ‘’₁ a) (Γ⇓ , A⇓) = Typ⇓ T₂ ((Γ⇓ , Term⇓ a Γ⇓) , A⇓)\n Typ⇓ (T₃ ‘’₂ a) ((Γ⇓ , A⇓) , B⇓) = Typ⇓ T₃ (((Γ⇓ , Term⇓ a Γ⇓) , A⇓) , B⇓)\n Typ⇓ (T₃ ‘’₃ a) (((Γ⇓ , A⇓) , B⇓) , C⇓) = Typ⇓ T₃ ((((Γ⇓ , Term⇓ a Γ⇓) , A⇓) , B⇓) , C⇓)\n Typ⇓ (W T₁) (Γ⇓ , _) = Typ⇓ T₁ Γ⇓\n Typ⇓ (W1 T₂) ((Γ⇓ , A⇓) , B⇓) = Typ⇓ T₂ (Γ⇓ , B⇓)\n Typ⇓ (W2 T₃) (((Γ⇓ , A⇓) , B⇓) , C⇓) = Typ⇓ T₃ ((Γ⇓ , B⇓) , C⇓)\n Typ⇓ (T ‘→’ T₁) Γ⇓ = (T⇓ : Typ⇓ T Γ⇓) → Typ⇓ T₁ (Γ⇓ , T⇓)\n Typ⇓ ‘Context’ Γ⇓ = Lifted Context\n Typ⇓ ‘Typ’ (Γ⇓ , T⇓) = Lifted (Typ (lower T⇓))\n Typ⇓ ‘Term’ (Γ⇓ , T⇓ , t⇓) = Lifted (Term (lower t⇓))\n Typ⇓ (‘Σ’ T T₁) Γ⇓ = Σ (Typ⇓ T Γ⇓) (λ T⇓ → Typ⇓ T₁ (Γ⇓ , T⇓))\n\n Term⇓ : ∀ {Γ : Context} {T : Typ Γ} → Term T → (Γ⇓ : Context⇓ Γ) → Typ⇓ T Γ⇓\n Term⇓ (w t) (Γ⇓ , A⇓) = Term⇓ t Γ⇓\n Term⇓ (‘λ∙’ t) Γ⇓ T⇓ = Term⇓ t (Γ⇓ , T⇓)\n Term⇓ (t ‘’ₐ t₁) Γ⇓ = Term⇓ t Γ⇓ (Term⇓ t₁ Γ⇓)\n Term⇓ ‘VAR₀’ (Γ⇓ , A⇓) = A⇓\n Term⇓ (⌜ Γ ⌝c) Γ⇓ = lift Γ\n Term⇓ (⌜ T ⌝T) Γ⇓ = lift T\n Term⇓ (⌜ t ⌝t) Γ⇓ = lift t\n Term⇓ ‘quote-term’ Γ⇓ (lift T⇓) = lift ⌜ T⇓ ⌝t\n Term⇓ (‘quote-sigma’ {Γ₀} {Γ₁}) Γ⇓ (lift Γ , lift T) = lift (‘existT’ {Γ₁} ⌜ Γ ⌝c ⌜ T ⌝T)\n Term⇓ ‘cast’ Γ⇓ T⇓ = lift (context-pick-if\n {P = Typ}\n {lower (Σ.proj₁ T⇓)}\n (W dummy)\n (lower (Σ.proj₂ T⇓)))\n Term⇓ (SW t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp-substTyp-tProd t) Γ⇓ T⇓ = Term⇓ t Γ⇓ T⇓\n Term⇓ (substTyp-weakenTyp1-VAR₀ t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp-tProd t) Γ⇓ T⇓ = Term⇓ t Γ⇓ T⇓\n Term⇓ (weakenTyp-tProd-inv t) Γ⇓ T⇓ = Term⇓ t Γ⇓ T⇓\n Term⇓ (weakenTyp-weakenTyp-tProd t) Γ⇓ T⇓ = Term⇓ t Γ⇓ T⇓\n Term⇓ (substTyp1-tProd t) Γ⇓ T⇓ = Term⇓ t Γ⇓ T⇓\n Term⇓ (weakenTyp1-tProd t) Γ⇓ T⇓ = Term⇓ t Γ⇓ T⇓\n Term⇓ (substTyp2-tProd t) Γ⇓ T⇓ = Term⇓ t Γ⇓ T⇓\n Term⇓ (substTyp1-substTyp-weakenTyp-inv t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (substTyp1-substTyp-weakenTyp t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp-weakenTyp-substTyp1-substTyp-weakenTyp t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp-substTyp2-substTyp1-substTyp-weakenTyp-inv t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (substTyp2-substTyp1-substTyp-weakenTyp t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp-substTyp2-substTyp1-substTyp-tProd t) Γ⇓ T⇓ = Term⇓ t Γ⇓ T⇓\n Term⇓ (weakenTyp2-weakenTyp1 t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp1-weakenTyp t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp1-weakenTyp-inv t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp1-weakenTyp1-weakenTyp t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (substTyp1-weakenTyp1 t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp1-substTyp-weakenTyp1-inv t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp1-substTyp-weakenTyp1 t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp-substTyp-substTyp-weakenTyp1 t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp-substTyp-substTyp-weakenTyp1-inv t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (substTyp-weakenTyp1-weakenTyp t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (substTyp3-substTyp2-substTyp1-substTyp-weakenTyp t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp-substTyp2-substTyp1-substTyp-weakenTyp1 t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (substTyp1-substTyp-tProd t) Γ⇓ T⇓ = Term⇓ t Γ⇓ T⇓\n Term⇓ (substTyp2-substTyp-substTyp-weakenTyp1-weakenTyp-weakenTyp t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (substTyp1-substTyp-weakenTyp2-weakenTyp t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (weakenTyp-weakenTyp1-weakenTyp t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ (beta-under-subst t) Γ⇓ = Term⇓ t Γ⇓\n Term⇓ ‘proj₁'’ Γ⇓ (x , p) = x\n Term⇓ ‘proj₂'’ (Γ⇓ , (x , p)) = p\n Term⇓ (‘existT’ x p) Γ⇓ = Term⇓ x Γ⇓ , Term⇓ p Γ⇓\n Term⇓ (f ‘‘’’ x) Γ⇓ = lift (lower (Term⇓ f Γ⇓) ‘’ lower (Term⇓ x Γ⇓))\n Term⇓ (f w‘‘’’ x) Γ⇓ = lift (lower (Term⇓ f Γ⇓) ‘’ lower (Term⇓ x Γ⇓))\n Term⇓ (f ‘‘→'’’ x) Γ⇓ = lift (lower (Term⇓ f Γ⇓) ‘→'’ lower (Term⇓ x Γ⇓))\n Term⇓ (f w‘‘→'’’ x) Γ⇓ = lift (lower (Term⇓ f Γ⇓) ‘→'’ lower (Term⇓ x Γ⇓))\n Term⇓ (w→ x) Γ⇓ A⇓ = Term⇓ x (Σ.proj₁ Γ⇓) A⇓\n Term⇓ w‘‘→'’’→‘‘→'’’ Γ⇓ T⇓ = T⇓\n Term⇓ ‘‘→'’’→w‘‘→'’’ Γ⇓ T⇓ = T⇓\n Term⇓ ‘tApp-nd’ Γ⇓ f⇓ x⇓ = lift (SW (lower f⇓ ‘’ₐ lower x⇓))\n Term⇓ ⌜←'⌝ Γ⇓ T⇓ = T⇓\n Term⇓ ⌜→'⌝ Γ⇓ T⇓ = T⇓\n Term⇓ (‘‘fcomp-nd’’ {A} {B} {C}) Γ⇓ g⇓ f⇓ = lift (_‘∘’_ {ε} (lower g⇓) (lower f⇓))\n Term⇓ (⌜‘’⌝ {B} {A} {b}) Γ⇓ = lift (‘λ∙’ {ε} (‘VAR₀’ {ε} {_‘’_ {ε} A b}))\n Term⇓ (⌜‘’⌝' {B} {A} {b}) Γ⇓ = lift (‘λ∙’ {ε} (‘VAR₀’ {ε} {_‘’_ {ε} A b}))\n Term⇓ (‘cast-refl’ {T}) Γ⇓ = lift (cast-proof {T})\n Term⇓ (‘cast-refl'’ {T}) Γ⇓ = lift (cast'-proof {T})\n Term⇓ (‘s→→’ {T} {B} {b} {c} {v}) Γ⇓ = lift (‘idfun’ {_‘’_ {ε} (lower (Term⇓ b tt (Term⇓ v Γ⇓))) (lower (Term⇓ c tt (Term⇓ v Γ⇓)))})\n Term⇓ (‘s←←’ {T} {B} {b} {c} {v}) Γ⇓ = lift (‘idfun’ {_‘’_ {ε} (lower (Term⇓ b tt (Term⇓ v Γ⇓))) (lower (Term⇓ c tt (Term⇓ v Γ⇓)))})\n", "meta": {"hexsha": "8b595a714e96453efcf686669aa21f9dd0569ab9", "size": 7128, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "internal/well-typed-syntax-pre-interpreter.agda", "max_stars_repo_name": "JasonGross/lob", "max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z", "max_issues_repo_path": "internal/well-typed-syntax-pre-interpreter.agda", "max_issues_repo_name": "JasonGross/lob", "max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z", "max_forks_repo_path": "internal/well-typed-syntax-pre-interpreter.agda", "max_forks_repo_name": "JasonGross/lob", "max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z", "avg_line_length": 51.2805755396, "max_line_length": 136, "alphanum_fraction": 0.4813411897, "num_tokens": 3912, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6723316860482762, "lm_q2_score": 0.5234203489363239, "lm_q1q2_score": 0.35191208571233573}} {"text": "------------------------------------------------------------------------\n-- Most of a virtual machine\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nmodule Lambda.Virtual-machine where\n\nopen import Equality.Propositional\nopen import Prelude\n\nopen import Vec.Function equality-with-J\n\nopen import Lambda.Syntax\n\n------------------------------------------------------------------------\n-- Instruction set\n\nmutual\n\n -- Instructions.\n\n data Instr (n : ℕ) : Type where\n var : (x : Fin n) → Instr n\n con : (i : ℕ) → Instr n\n clo : (c : Code (suc n)) → Instr n\n app : Instr n\n ret : Instr n\n\n -- Code.\n\n Code : ℕ → Type\n Code n = List (Instr n)\n\n-- Environments and values.\n\nopen Closure Code\n\n------------------------------------------------------------------------\n-- Stacks and states\n\n-- Stacks.\n\ndata StackElement : Type where\n val : (v : Value) → StackElement\n ret : ∀ {n} (c : Code n) (ρ : Env n) → StackElement\n\nStack : Type\nStack = List StackElement\n\n-- States.\n\ndata State : Type where\n ⟨_,_,_⟩ : ∀ {n} (c : Code n) (s : Stack) (ρ : Env n) → State\n\npattern ⟨_∣_,_,_⟩ n c s ρ = ⟨_,_,_⟩ {n} c s ρ\n\n------------------------------------------------------------------------\n-- A kind of small-step semantics for the virtual machine\n\n-- The result of running the VM one step.\n\ndata Result : Type where\n continue : (s : State) → Result\n done : (v : Value) → Result\n crash : Result\n\n-- A single step of the computation.\n\nstep : State → Result\nstep ⟨ var x ∷ c , s , ρ ⟩ = continue ⟨ c , val (ρ x) ∷ s , ρ ⟩\nstep ⟨ con i ∷ c , s , ρ ⟩ = continue ⟨ c , val (con i) ∷ s , ρ ⟩\nstep ⟨ clo c′ ∷ c , s , ρ ⟩ = continue ⟨ c , val (ƛ c′ ρ) ∷ s , ρ ⟩\nstep ⟨ app ∷ c , val v ∷ val (ƛ c′ ρ′) ∷ s , ρ ⟩ = continue ⟨ c′ , ret c ρ ∷ s , cons v ρ′ ⟩\nstep ⟨ ret ∷ c , val v ∷ ret c′ ρ′ ∷ s , ρ ⟩ = continue ⟨ c′ , val v ∷ s , ρ′ ⟩\nstep ⟨ zero ∣ [] , val v ∷ [] , ρ ⟩ = done v\nstep _ = crash\n", "meta": {"hexsha": "56cbfb16b67e3860f2fb661cefdd47aa0e9b3090", "size": 2162, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Lambda/Virtual-machine.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/Virtual-machine.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/Virtual-machine.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": 27.7179487179, "max_line_length": 101, "alphanum_fraction": 0.4236817761, "num_tokens": 618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7090191337850933, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.3517400172476011}} {"text": "{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.\n\n Copyright (c) 2020 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{-# OPTIONS --allow-unsolved-metas #-}\nopen import LibraBFT.Prelude\nopen import LibraBFT.Lemmas\nopen import LibraBFT.Abstract.Types\n\n-- For each desired property (VotesOnce and LockedRoundRule), we have a\n-- module containing a Type that defines a property that an implementation\n-- should prove, and a proof that it implies the corresponding rule used by\n-- the abstract proofs. Then, we use those proofs to instantiate thmS5,\n-- and the use thmS5 to prove a number of correctness conditions.\n--\n-- TODO-1: refactor this file to separate the definitions and proofs of\n-- VotesOnce and LockedRoundRule from their use in proving the correctness\n-- properties.\n\nmodule LibraBFT.Abstract.Properties\n (𝓔 : EpochConfig)\n (UID : Set)\n (_≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁))\n (𝓥 : VoteEvidence 𝓔 UID)\n where\n\n open import LibraBFT.Abstract.Records 𝓔 UID _≟UID_ 𝓥\n open import LibraBFT.Abstract.Records.Extends 𝓔 UID _≟UID_ 𝓥\n open import LibraBFT.Abstract.RecordChain 𝓔 UID _≟UID_ 𝓥\n import LibraBFT.Abstract.RecordChain.Assumptions 𝓔 UID _≟UID_ 𝓥\n as StaticAssumptions\n open import LibraBFT.Abstract.System 𝓔 UID _≟UID_ 𝓥\n\n open EpochConfig 𝓔\n\n open import LibraBFT.Abstract.Obligations.VotesOnce 𝓔 UID _≟UID_ 𝓥 as VO\n open import LibraBFT.Abstract.Obligations.LockedRound 𝓔 UID _≟UID_ 𝓥 as LR\n\n --------------------------------------------------------------------------------------------\n -- * A /ValidSysState/ is one in which both peer obligations are obeyed by honest peers * --\n --------------------------------------------------------------------------------------------\n\n record ValidSysState {ℓ}(𝓢 : AbsSystemState ℓ) : Set (ℓ+1 ℓ0 ℓ⊔ ℓ) where\n field\n vss-votes-once : VO.Type 𝓢\n vss-locked-round : LR.Type 𝓢\n open ValidSysState public\n\n -- And a valid system state offers the desired /CommitsDoNotConflict/ property\n -- and variants.\n module _ {ℓ}(𝓢 : AbsSystemState ℓ) (st-valid : ValidSysState 𝓢) where\n open AbsSystemState 𝓢\n open All-InSys-props InSys\n import LibraBFT.Abstract.RecordChain.Properties 𝓔 UID _≟UID_ 𝓥 as Props\n\n CommitsDoNotConflict : ∀{q q'}\n → {rc : RecordChain (Q q)} → All-InSys rc\n → {rc' : RecordChain (Q q')} → All-InSys rc'\n → {b b' : Block}\n → CommitRule rc b\n → CommitRule rc' b'\n → NonInjective-≡ bId ⊎ ((B b) ∈RC rc' ⊎ (B b') ∈RC rc)\n CommitsDoNotConflict = Props.WithInvariants.thmS5 InSys\n (VO.proof 𝓢 (vss-votes-once st-valid))\n (LR.proof 𝓢 (vss-locked-round st-valid))\n\n -- When we are dealing with a /Complete/ AbsSystem, we can go a few steps\n -- further and prove that commits do not conflict even if we have only partial\n -- knowledge about Records represented in the system.\n module _ (∈QC⇒AllSent : Complete 𝓢) where\n\n -- For a /complete/ system we can go even further; if we have evidence that\n -- only the tip of the record chains is in the system, we can infer\n -- the rest of it is also in the system (or blockIDs are not injective).\n CommitsDoNotConflict'\n : ∀{q q'}{rc : RecordChain (Q q)}{rc' : RecordChain (Q q')}{b b' : Block}\n → InSys (Q q) → InSys (Q q')\n → CommitRule rc b\n → CommitRule rc' b'\n → NonInjective-≡ bId ⊎ ((B b) ∈RC rc' ⊎ (B b') ∈RC rc)\n CommitsDoNotConflict' {q} {q'} {step {r = B bb} rc b←q} {step {r = B bb'} rc' b←q'} {b} {b'} q∈sys q'∈sys cr cr'\n with bft-assumption (qVotes-C2 q) (qVotes-C2 q')\n ...| α , α∈qmem , α∈q'mem , hα\n with Any-sym (Any-map⁻ α∈qmem) | Any-sym (Any-map⁻ α∈q'mem)\n ...| α∈q | α∈q'\n with ∈QC⇒AllSent {q = q} hα α∈q q∈sys | ∈QC⇒AllSent {q = q'} hα α∈q' q'∈sys\n ...| ab , ab←q , arc , ais | ab' , ab←q' , arc' , ais'\n with RecordChain-irrelevant (step arc ab←q) (step rc b←q) |\n RecordChain-irrelevant (step arc' ab←q') (step rc' b←q')\n ...| inj₁ hb | _ = inj₁ hb\n ...| inj₂ _ | inj₁ hb = inj₁ hb\n ...| inj₂ arc≈rc | inj₂ arc'≈rc'\n with CommitsDoNotConflict\n (All-InSys-step ais ab←q q∈sys )\n (All-InSys-step ais' ab←q' q'∈sys)\n (transp-CR (≈RC-sym arc≈rc ) cr )\n (transp-CR (≈RC-sym arc'≈rc') cr')\n ...| inj₁ hb = inj₁ hb\n ...| inj₂ (inj₁ b∈arc') = inj₂ (inj₁ (transp-B∈RC arc'≈rc' b∈arc'))\n ...| inj₂ (inj₂ b'∈arc) = inj₂ (inj₂ (transp-B∈RC arc≈rc b'∈arc))\n\n -- The final property is even stronger; it states that even if an observer\n -- has access only to suffixes of record chains that match the commit rule,\n -- we can still guarantee that b and b' are non-conflicting blocks. This\n -- will be important for showing that observers can have confidence in commit\n -- messages without participating in the protocol and without having access to\n -- all previously sent records.\n CommitsDoNotConflict''\n : ∀{o o' q q'}\n → {rcf : RecordChainFrom o (Q q)}\n → {rcf' : RecordChainFrom o' (Q q')}\n → {b b' : Block}\n → InSys (Q q)\n → InSys (Q q')\n → CommitRuleFrom rcf b\n → CommitRuleFrom rcf' b'\n → NonInjective-≡ bId ⊎ Σ (RecordChain (Q q')) ((B b) ∈RC_)\n ⊎ Σ (RecordChain (Q q)) ((B b') ∈RC_)\n CommitsDoNotConflict'' {cb} {q = q} {q'} {rcf} {rcf'} q∈sys q'∈sys crf crf'\n with bft-assumption (qVotes-C2 q) (qVotes-C2 q')\n ...| α , α∈qmem , α∈q'mem , hα\n with Any-sym (Any-map⁻ α∈qmem) | Any-sym (Any-map⁻ α∈q'mem)\n ...| α∈q | α∈q'\n with ∈QC⇒AllSent {q = q} hα α∈q q∈sys | ∈QC⇒AllSent {q = q'} hα α∈q' q'∈sys\n ...| ab , ab←q , arc , ais | ab' , ab←q' , arc' , ais'\n with step arc ab←q | step arc' ab←q'\n ...| rcq | rcq'\n with crf⇒cr rcf rcq crf | crf⇒cr rcf' rcq' crf'\n ...| inj₁ hb | _ = inj₁ hb\n ...| inj₂ _ | inj₁ hb = inj₁ hb\n ...| inj₂ cr | inj₂ cr'\n with CommitsDoNotConflict' q∈sys q'∈sys cr cr'\n ...| inj₁ hb = inj₁ hb\n ...| inj₂ (inj₁ b∈arc') = inj₂ (inj₁ (rcq' , b∈arc'))\n ...| inj₂ (inj₂ b'∈arc) = inj₂ (inj₂ (rcq , b'∈arc))\n", "meta": {"hexsha": "8b8e00ba2bd05b0b5d77bf2d211e873781c90e05", "size": 6244, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "LibraBFT/Abstract/Properties.agda", "max_stars_repo_name": "lisandrasilva/bft-consensus-agda-1", "max_stars_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d", "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": "LibraBFT/Abstract/Properties.agda", "max_issues_repo_name": "lisandrasilva/bft-consensus-agda-1", "max_issues_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d", "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": "LibraBFT/Abstract/Properties.agda", "max_forks_repo_name": "lisandrasilva/bft-consensus-agda-1", "max_forks_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d", "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": 45.5766423358, "max_line_length": 116, "alphanum_fraction": 0.6007367072, "num_tokens": 2166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.3516658674307807}} {"text": "open import Prelude\n\nmodule Implicits.Semantics.RewriteContext where\n\nopen import Implicits.Syntax\nopen import Implicits.Substitutions\nopen import Implicits.Substitutions.Lemmas\n\nopen import Data.Vec\nopen import Data.List.All as All\nopen import Extensions.Vec\n\n-- rewrite context (relation between implicit and explicit context)\n_#_ : ∀ {ν n} (Γ : Ctx ν n) (Δ : ICtx ν) → Set\nΓ # Δ = All (λ i → i ∈ Γ) Δ\n\nK# : ∀ {ν n} (K : Ktx ν n) → Set\nK# (Γ , Δ) = Γ # Δ\n\n#tvar : ∀ {ν n} {K : Ktx ν n} → K# K → K# (ktx-weaken K)\n#tvar All.[] = All.[]\n#tvar (px All.∷ K#K) = (∈⋆map px (λ t → t tp/tp TypeLemmas.wk)) All.∷ (#tvar K#K)\n\n#var : ∀ {ν n} {K : Ktx ν n} → (a : Type ν) → K# K → K# (a ∷Γ K)\n#var a All.[] = All.[]\n#var a (px All.∷ K#K) = there px All.∷ (#var a K#K)\n\n#ivar : ∀ {ν n} {K : Ktx ν n} → (a : Type ν) → K# K → K# (a ∷K K)\n#ivar a K#K = here All.∷ (All.map there K#K)\n", "meta": {"hexsha": "b97b796c5cb1e11af06e6d7cc51236c9cd7ead1e", "size": 872, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Implicits/Semantics/RewriteContext.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/Semantics/RewriteContext.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/Semantics/RewriteContext.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": 29.0666666667, "max_line_length": 81, "alphanum_fraction": 0.5871559633, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.6477982043529716, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.35166586004830763}} {"text": "open import Agda.Primitive\nopen import Data.Unit\nopen import Data.Nat hiding (_⊔_ ; _^_)\nopen import Data.Integer hiding (_⊔_)\nopen import Data.List\nopen import Data.List.Relation.Unary.Any\nopen import Data.List.Relation.Unary.All as All\nopen import Data.List.Membership.Propositional\nopen import Data.Product\nopen import Data.Maybe hiding (_>>=_)\nopen import Data.List.Prefix\nopen import Data.List.Properties.Extra\nopen import Data.List.All.Properties.Extra\nopen import Function\nopen import Relation.Binary.PropositionalEquality hiding ([_])\nopen ≡-Reasoning\nopen import Common.Weakening\n\n-- This file contains the definitional interpreter for STLC using\n-- scopes and frames, described in Section 4 of the paper.\n\n-- The scopes-and-frames library assumes that we are given a\n-- particular scope graph, with `k` scopes. The following module is\n-- parameterized by a `k` representing the number of scopes that a\n-- particular object language program has.\n\nmodule STLCSF.Semantics (k : ℕ) where\n\n\n-----------\n-- TYPES --\n-----------\n\ndata Ty : Set where\n unit : Ty\n _⇒_ : (a b : Ty) → Ty\n int : Ty\n\n-- The library is loaded and passed two arguments:\n--\n-- * `k` is the size of the scope graph for an object program\n--\n-- * `Ty` is the type of declarations in the scope graph\n\nopen import ScopesFrames.ScopesFrames k Ty\n\n-- Our interpreter is parameterized by a scope graph, via the module\n-- below.\n\nmodule Syntax (g : Graph) where\n\n -- We load all the scope graph definitions in the scope graph\n -- library, by passing the object scope graph `g` as module\n -- parameter:\n open UsesGraph g\n\n\n ------------\n -- SYNTAX --\n ------------\n\n -- We can now define our well-typed syntax as described in the paper\n -- Section 4.2:\n data Expr (s : Scope) : Ty → Set where\n unit : Expr s unit\n var : ∀ {t} → (s ↦ t) → Expr s t\n ƛ : ∀ {s' a b} → ⦃ shape : g s' ≡ ( [ a ] , [ s ] ) ⦄ → Expr s' b → Expr s (a ⇒ b)\n _·_ : ∀ {a b} → Expr s (a ⇒ b) → Expr s a → Expr s b\n num : ℤ → Expr s int\n iop : (ℤ → ℤ → ℤ) → (l r : Expr s int) → Expr s int\n\n\n ------------\n -- VALUES --\n ------------\n\n -- We can also define well-typed values as described in the paper\n -- Section 4.4:\n data Val : Ty → (Σ : HeapTy) → Set where\n unit : ∀ {Σ} → Val unit Σ\n ⟨_,_⟩ : ∀ {Σ s s' a b}⦃ shape : g s' ≡ ( [ a ] , [ s ] ) ⦄ →\n Expr s' b → Frame s Σ → Val (a ⇒ b) Σ\n num : ∀ {Σ} → ℤ → Val int Σ\n\n val-weaken : ∀ {t Σ Σ'} → Σ ⊑ Σ' → Val t Σ → Val t Σ'\n val-weaken ext ⟨ e , f ⟩ = ⟨ e , wk ext f ⟩\n val-weaken ext unit = unit\n val-weaken ext (num z) = num z\n\n -- We can now load the frames definitions of the scopes-and-frames\n -- library. As described in Section 4.3 of the paper, our notion of\n -- frame assumes a notion of weakenable value, to be passed as\n -- module arguments to `UsesVal`:\n open UsesVal Val val-weaken renaming (getFrame to getFrame')\n\n -- We rename `getFrame` from the scopes-and-frames library so that\n -- we can use `getFrame` as the name of the monadic operation which\n -- returns the \"current frame pointer\" below.\n\n\n -----------\n -- MONAD --\n -----------\n\n -- These definitions correspond to Section 4.4.\n\n M : (s : Scope) → (HeapTy → Set) → HeapTy → Set\n M s p Σ = Frame s Σ → Heap Σ → Maybe (∃ λ Σ' → (Heap Σ' × p Σ' × Σ ⊑ Σ'))\n\n _>>=_ : ∀ {s Σ}{p q : List Scope → Set} →\n M s p Σ → (∀ {Σ'} → p Σ' → M s q Σ') → M s q Σ\n (a >>= b) f h\n with (a f h)\n ... | nothing = nothing\n ... | just (Σ , h' , v , ext)\n with (b v (wk ext f) h')\n ... | nothing = nothing\n ... | just (Σ' , h'' , v' , ext') = just (Σ' , h'' , v' , ext ⊚ ext')\n\n return : ∀ {s Σ}{p : List Scope → Set} → p Σ → M s p Σ\n return v f h = just (_ , h , v , ⊑-refl)\n\n getFrame : ∀ {s Σ} → M s (Frame s) Σ\n getFrame f = return f f\n\n usingFrame : ∀ {s s' Σ}{p : List Scope → Set} → Frame s Σ → M s p Σ → M s' p Σ\n usingFrame f a _ = a f\n\n timeout : ∀ {s Σ}{p : List Scope → Set} → M s p Σ\n timeout _ _ = nothing\n\n init : ∀ {Σ s' ds es}(s : Scope)⦃ shape : g s ≡ (ds , es) ⦄ →\n Slots ds Σ → Links es Σ → M s' (Frame s) Σ\n init {Σ} s slots links _ h\n with (initFrame s slots links h)\n ... | (f' , h') = just (_ , h' , f' , ∷ʳ-⊒ s Σ)\n\n getv : ∀ {s t Σ} → (s ↦ t) → M s (Val t) Σ\n getv p f h = return (getVal p f h) f h\n\n _^_ : ∀ {Σ Γ}{p q : List Scope → Set} → ⦃ w : Weakenable q ⦄ →\n M Γ p Σ → q Σ → M Γ (p ⊗ q) Σ\n (a ^ x) f h\n with (a f h)\n ... | nothing = nothing\n ... | just (Σ , h' , v , ext) = just (Σ , h' , (v , wk ext x) , ext)\n\n sₑ : ∀ {s t} → Expr s t → Scope\n sₑ {s} _ = s\n\n eval : ℕ → ∀ {s t Σ} → Expr s t → M s (Val t) Σ\n eval zero _ =\n timeout\n eval (suc k) unit =\n return unit\n eval (suc k) (var x) =\n getv x\n eval (suc k) (ƛ e) =\n getFrame >>= λ f →\n return ⟨ e , f ⟩\n eval (suc k) (l · r) =\n eval k l >>= λ{ ⟨ e , f ⟩ →\n (eval k r ^ f) >>= λ{ (v , f) →\n init (sₑ e) (v ∷ []) (f ∷ []) >>= λ f' →\n usingFrame f' (eval k e) }}\n eval (suc k) (num z) =\n return (num z)\n eval (suc k) (iop f l r) =\n eval k l >>= λ{ (num z₁) →\n eval k r >>= λ{ (num z₂) →\n return (num (f z₁ z₂)) }}\n", "meta": {"hexsha": "aa39d1363fee40ee6c4d3e0965b5a9ff24141c6a", "size": 5254, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/STLCSF/Semantics.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/STLCSF/Semantics.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/STLCSF/Semantics.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": 30.5465116279, "max_line_length": 90, "alphanum_fraction": 0.5460601447, "num_tokens": 1896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.66192288918838, "lm_q2_score": 0.5312093733737562, "lm_q1q2_score": 0.3516196431875056}} {"text": "{- wip, coming to realise that the instance of IsSetoid defined in Data.Equality.properties is over-eager (defining _≡_ for all (A : Set (a : Level)), _≡̇_ for ∀ (x : A : Set (a : Level)) → (B : A → Set (b : Level)) x -}\n-- add samples of stuff from unification (AList, etc.)\nmodule Oscar.Data5 where\n\nrecord ⊤ : Set where\n constructor tt\n\nConst_ : ∀ {a} {A : Set a} {b} {B : Set b} → B → A → B\nConst_ x _ = x\n\ninfixr 20 _∷_\n\n-- List\ndata ⟦_⟧ {a} (A : Set a) : Set a where\n ∅ : ⟦ A ⟧\n _∷_ : A → ⟦ A ⟧ → ⟦ A ⟧\n\n-- Nat\n⟦⟧ = ⟦ ⊤ ⟧\n\ninfix 21 ¡_\npattern ¡_ ⟦A⟧ = tt ∷ ⟦A⟧\n--¡ : ⟦⟧ → ⟦⟧\n--¡ ⟦A⟧ = tt ∷ ⟦A⟧\n\n-- Fin (with a payload)\ndata ⟦_⟧[_] {a} (A : ⟦⟧ → Set a) : ⟦⟧ → Set a where\n ∅ : ∀ {n} → ⟦ A ⟧[ ¡ n ]\n _∷_ : ∀ {n} → A n → ⟦ A ⟧[ n ] → ⟦ A ⟧[ ¡ n ]\n\n⟦⟧[_] = ⟦ Const ⊤ ⟧[_]\n\n-- Vec (with an (optional) index)\ndata ⟦_⟧[_₀] {a} (A : ⟦⟧ → Set a) : ⟦⟧ → Set a where\n ∅ : ⟦ A ⟧[ ∅ ₀]\n _∷_ : ∀ {n} → A n → ⟦ A ⟧[ n ₀] → ⟦ A ⟧[ ¡ n ₀]\n\n⟦⟧[_₀] = ⟦ Const ⊤ ⟧[_₀]\n\n-- m ≤ n, counting down from n-1 to m\ndata ⟦_⟧[_≤_↓] {a} (A : ⟦⟧ → Set a) (m : ⟦⟧) : ⟦⟧ → Set a where\n ∅ : ⟦ A ⟧[ m ≤ m ↓]\n _∷_ : ∀ {n} → A n → ⟦ A ⟧[ m ≤ n ↓] → ⟦ A ⟧[ m ≤ ¡ n ↓]\n\n⟦⟧[_≤_↓] = ⟦ Const ⊤ ⟧[_≤_↓]\n\n-- m ≤ n, counting up from m to n-1\ndata ⟦_⟧[↑_≤_] {a} (A : ⟦⟧ → Set a) (m : ⟦⟧) : ⟦⟧ → Set a where\n ∅ : ⟦ A ⟧[↑ m ≤ m ]\n _∷_ : ∀ {n} → A m → ⟦ A ⟧[↑ ¡ m ≤ n ] → ⟦ A ⟧[↑ m ≤ n ]\n\n⟦⟧[↑_≤_] = ⟦ Const ⊤ ⟧[↑_≤_]\n\n-- Inj (almost)\ndata ⟦_⟧[↓_≤_↓] {a} (A : ⟦⟧ → ⟦⟧ → Set a) : ⟦⟧ → ⟦⟧ → Set a where\n ∅ : ∀ {n} → ⟦ A ⟧[↓ ∅ ≤ n ↓]\n _∷_ : ∀ {m n} → A m n → ⟦ A ⟧[↓ m ≤ n ↓] → ⟦ A ⟧[↓ ¡ m ≤ ¡ n ↓]\n\n⟦⟧[↓_≤_↓] = ⟦ Const Const ⊤ ⟧[↓_≤_↓]\n\n⟦_⟧[_⇒_]∞ : ∀ {a} (A : ⟦⟧ → Set a) → ⟦⟧ → ⟦⟧ → Set a\n⟦ A ⟧[ m ⇒ n ]∞ = A m → A n\n\nopen import Oscar.Category.Semigroupoid\nopen import Oscar.Category.Category\nopen import Oscar.Category.Morphism\nopen import Oscar.Category.Setoid\n--open import Oscar.Data.Equality\n--open import Oscar.Data.Equality.properties\nopen import Oscar.Function\n\nmodule _ {𝔬 𝔪 𝔮} (G : Semigroupoid 𝔬 𝔪 𝔮) where\n open Semigroupoid G\n\n\n{-\n _≋̇_ : ∀ {a} {A : ⋆ → Set a} {m n : ⋆} → (A m → A n) → (A m → A n) → Set 𝔮\n _≋̇_ {A = A} {m = m} m→n₁ m→n₂ = {!∀ (am : A m) → m→n₁ am ≋ m→n₂ am!}\n\n\n\n cat2 : ∀ {a} (A : ⋆ → Set a) → Category {!!} {!!} {!!}\n Semigroupoid.⋆ (Category.semigroupoid (cat2 A)) = ⋆\n Setoid.⋆ ((Semigroupoid.𝔐 (Category.semigroupoid (cat2 A)) Morphism.⇒ m) n) = A m → A n\n IsSetoid._≋_ (Setoid.isSetoid ((Semigroupoid.𝔐 (Category.semigroupoid (cat2 A)) Morphism.⇒ m) n)) = _≡̇_\n IsSetoid.isEquivalence (Setoid.isSetoid ((Semigroupoid.𝔐 (Category.semigroupoid (cat2 A)) Morphism.⇒ m) n)) = it\n Semigroupoid._∙_ (Category.semigroupoid (cat2 A)) g f = g ∘ f\n Semigroupoid.isSemigroupoid (Category.semigroupoid (cat2 A)) = it\n Category.ε (cat2 A) = id\n Category.isCategory (cat2 A) = it\n-}\n\n cat2G : ∀ {a} (A : ⋆ → Set a) → ∀ ℓ ⦃ _ : ∀ {n : ⋆} → IsSetoid (A n) ℓ ⦄ → Category {!!} {!!} {!!}\n Semigroupoid.⋆ (Category.semigroupoid (cat2G A ℓ)) = ⋆\n Setoid.⋆ ((Semigroupoid.𝔐 (Category.semigroupoid (cat2G A ℓ)) Morphism.⇒ m) n) = A m → A n\n IsSetoid._≋_ (Setoid.isSetoid ((Semigroupoid.𝔐 (Category.semigroupoid (cat2G A ℓ)) Morphism.⇒ m) n)) m↦n₁ m↦n₂ = ∀ (am : A m) → m↦n₁ am ≋ m↦n₂ am\n -- ∀ (am : A m) → m↦n₁ am ≋ m↦n₂ am\n {-\n _≋̇_ : ∀ {a} {A : ⋆ → Set a} {m n : ⋆} → (A m → A n) → (A m → A n) → Set 𝔮\n _≋̇_ {A = A} {m = m} m→n₁ m→n₂ = {!∀ (am : A m) → m→n₁ am ≋ m→n₂ am!}\n -}\n IsSetoid.isEquivalence (Setoid.isSetoid ((Semigroupoid.𝔐 (Category.semigroupoid (cat2G A ℓ)) Morphism.⇒ m) n)) = {!it!}\n Semigroupoid._∙_ (Category.semigroupoid (cat2G A ℓ)) g f = g ∘ f\n Semigroupoid.isSemigroupoid (Category.semigroupoid (cat2G A ℓ)) = {!it!}\n Category.ε (cat2G A ℓ) = id\n Category.isCategory (cat2G A ℓ) = {!it!}\n\n\ninfix 21 ‼_\npattern ‼_ ⟦A⟧ = tt ∷ ⟦A⟧ -- tricky, works for all above _∷_ constructors only because it is defined afterwards, won't work for any later-defined constructors\n\nopen import Agda.Primitive\nopen import Oscar.Data.Product\nopen import Oscar.Function\n\npostulate\n ℓ : Level\n Term : ⟦⟧ → Set ℓ\n Step : ⟦⟧ → Set ℓ\n\nFin = ⟦⟧[_]\n\nInj = ⟦ Const Fin ⟧[↓_≤_↓]\n\nTerms = λ N n → ⟦ Const (Term n) ⟧[ N ₀]\n\nAList = ⟦ (λ n → Term n × Fin (¡ n)) ⟧[_≤_↓]\n\nFx : ∀ {a} {A : Set a} → A → A → ∀ {b₁} (B₁ : A → Set b₁) → ∀ {b₂} (B₂ : A → Set b₂) → Set (b₁ ⊔ b₂)\nFx m n B₁ B₂ = B₁ m → B₂ n\n\nFx₁ : ∀ {a} {A : Set a} → A → ∀ {b₁} (B₁ : A → Set b₁) → ∀ {b₂} (B₂ : A → Set b₂) → Set (b₁ ⊔ b₂)\nFx₁ n B₁ B₂ = Fx n n B₁ B₂\n\nListStep = λ n → ⟦ Step n ⟧\n\nRel : ∀ {a} {A : Set a} {b₁} (B₁ : A → Set b₁) {b₂} (B₂ : A → Set b₂) {c₁} (C₁ : A → Set c₁) {c₂} (C₂ : A → Set c₂) → Set (a ⊔ b₁ ⊔ b₂ ⊔ c₁ ⊔ c₂)\nRel B₁ B₂ C₁ C₂ = ∀ {m n} → Fx m n B₁ B₂ → Fx m n C₁ C₂\n\nMorph : ∀ {a} {A : Set a} {b₁} {b₂} (B : (A → Set b₁) × (A → Set b₂)) {c₁} {c₂} (C₂ : (A → Set c₁) × (A → Set c₂)) → Set (a ⊔ b₁ ⊔ b₂ ⊔ c₁ ⊔ c₂)\nMorph (B₁ , B₂) (C₁ , C₂) = ∀ {m n} → Fx m n B₁ B₂ → Fx m n C₁ C₂\n\n-- functor mappings\npostulate\n _◃_ : Morph (Fin , Term) (Term , Term)\n _◃s_ : ∀ N → Morph (Fin , Term) (Terms N , Terms N)\n sub : ∀ {m n} → AList m n → Fx m n Fin Term\n fmapS : Morph (Term , Term) (Step , Step)\n _◃S_ : Morph (Fin , Term) (ListStep , ListStep)\n\n-- ?\npostulate\n _⊹_ : ∀ {n} → ⟦ Step n ⟧ → Fx₁ n Term Term\n\ntestNat : ⟦⟧\ntestNat = ¡ ∅\n\ntestListNat : ⟦ ⟦⟧ ⟧\ntestListNat = ¡ ∅ ∷ ‼ ∅ ∷ ‼ ‼ ∅ ∷ ∅ ∷ ¡ ¡ ¡ ∅ ∷ ∅\n\ntestFin : ⟦⟧[ ¡ ¡ ∅ ]\ntestFin = ‼ ∅\n\ntest≤↓ : ⟦⟧[ ‼ ‼ ‼ ∅ ≤ ‼ ‼ ‼ ‼ ‼ ∅ ↓]\ntest≤↓ = ‼ ‼ ∅\n\n⓪ ⑴ ⑵ ⑶ : ⟦⟧\n⓪ = ∅\n⑴ = ‼ ∅\n⑵ = ‼ ⑴\n⑶ = ‼ ⑵\n\ntestInj : Inj ⑵ ⑶\ntestInj = ‼ ∅ ∷ ∅ ∷ ∅\n", "meta": {"hexsha": "c2545d039caa9d4ec945bf63066f469c0b568c0b", "size": 5474, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "archive/agda-2/Oscar/Data5.agda", "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "archive/agda-2/Oscar/Data5.agda", "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_forks_repo_path": "archive/agda-2/Oscar/Data5.agda", "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.28, "max_line_length": 220, "alphanum_fraction": 0.5027402265, "num_tokens": 2829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.66192288918838, "lm_q2_score": 0.5312093733737562, "lm_q1q2_score": 0.3516196431875056}} {"text": "module STLC1.Kovacs.Substitution where\n\nopen import STLC1.Kovacs.Embedding public\nopen import Category\n\n\n--------------------------------------------------------------------------------\n\n\n-- Substitutions (Sub ; ∙ ; _,_)\ninfix 3 _⊢⋆_\ndata _⊢⋆_ : 𝒞 → 𝒞 → Set\n where\n ∅ : ∀ {Γ} → Γ ⊢⋆ ∅\n\n _,_ : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ) (M : Γ ⊢ A)\n → Γ ⊢⋆ Ξ , A\n\n\n-- (_ₛ∘ₑ_)\n-- NOTE: _◐_ = ren⋆\n_◐_ : ∀ {Γ Γ′ Ξ} → Γ ⊢⋆ Ξ → Γ′ ⊇ Γ → Γ′ ⊢⋆ Ξ\n∅ ◐ η = ∅\n(σ , M) ◐ η = σ ◐ η , ren η M\n\n-- (_ₑ∘ₛ_)\n_◑_ : ∀ {Γ Ξ Ξ′} → Ξ′ ⊇ Ξ → Γ ⊢⋆ Ξ′ → Γ ⊢⋆ Ξ\ndone ◑ σ = σ\nwkₑ η ◑ (σ , M) = η ◑ σ\nliftₑ η ◑ (σ , M) = η ◑ σ , M\n\n\n--------------------------------------------------------------------------------\n\n\n-- (dropₛ)\nwkₛ : ∀ {A Γ Ξ} → Γ ⊢⋆ Ξ → Γ , A ⊢⋆ Ξ\nwkₛ σ = σ ◐ wkₑ idₑ\n\n-- (keepₛ)\nliftₛ : ∀ {A Γ Ξ} → Γ ⊢⋆ Ξ → Γ , A ⊢⋆ Ξ , A\nliftₛ σ = wkₛ σ , 0\n\n-- (⌜_⌝ᵒᵖᵉ)\n⌊_⌋ : ∀ {Γ Γ′} → Γ′ ⊇ Γ → Γ′ ⊢⋆ Γ\n⌊ done ⌋ = ∅\n⌊ wkₑ η ⌋ = wkₛ ⌊ η ⌋\n⌊ liftₑ η ⌋ = liftₛ ⌊ η ⌋\n\n-- (∈ₛ)\ngetₛ : ∀ {Γ Ξ A} → Γ ⊢⋆ Ξ → Ξ ∋ A → Γ ⊢ A\ngetₛ (σ , M) zero = M\ngetₛ (σ , M) (suc i) = getₛ σ i\n\n-- (Tmₛ)\nsub : ∀ {Γ Ξ A} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A\nsub σ (𝓋 i) = getₛ σ i\nsub σ (ƛ M) = ƛ (sub (liftₛ σ) M)\nsub σ (M ∙ N) = sub σ M ∙ sub σ N\nsub σ (M , N) = sub σ M , sub σ N\nsub σ (π₁ M) = π₁ (sub σ M)\nsub σ (π₂ M) = π₂ (sub σ M)\nsub σ τ = τ\n\n-- (idₛ)\nidₛ : ∀ {Γ} → Γ ⊢⋆ Γ\nidₛ {∅} = ∅\nidₛ {Γ , A} = liftₛ idₛ\n\ncut : ∀ {Γ A B} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B\ncut M N = sub (idₛ , M) N\n\n-- (_∘ₛ_)\n-- NOTE: _●_ = sub⋆\n_●_ : ∀ {Γ Ξ Φ} → Ξ ⊢⋆ Φ → Γ ⊢⋆ Ξ → Γ ⊢⋆ Φ\n∅ ● σ₁ = ∅\n(σ₂ , M) ● σ₁ = σ₂ ● σ₁ , sub σ₁ M\n\n\n--------------------------------------------------------------------------------\n\n\n-- (assₛₑₑ)\ncomp◐○ : ∀ {Γ Γ′ Γ″ Ξ} → (η₁ : Γ″ ⊇ Γ′) (η₂ : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ)\n → (σ ◐ η₂) ◐ η₁ ≡ σ ◐ (η₂ ○ η₁)\ncomp◐○ η₁ η₂ ∅ = refl\ncomp◐○ η₁ η₂ (σ , M) = _,_ & comp◐○ η₁ η₂ σ\n ⊗ (ren○ η₁ η₂ M ⁻¹)\n\n-- (assₑₛₑ)\ncomp◑◐ : ∀ {Γ Γ′ Ξ Ξ′} → (η₁ : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ′) (η₂ : Ξ′ ⊇ Ξ)\n → (η₂ ◑ σ) ◐ η₁ ≡ η₂ ◑ (σ ◐ η₁)\ncomp◑◐ η₁ ∅ done = refl\ncomp◑◐ η₁ (σ , M) (wkₑ η₂) = comp◑◐ η₁ σ η₂\ncomp◑◐ η₁ (σ , M) (liftₑ η₂) = (_, ren η₁ M) & comp◑◐ η₁ σ η₂\n\n\n--------------------------------------------------------------------------------\n\n\n-- (idlₑₛ)\nlid◑ : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ)\n → idₑ ◑ σ ≡ σ\nlid◑ ∅ = refl\nlid◑ (σ , M) = (_, M) & lid◑ σ\n\n-- (idlₛₑ)\nlid◐ : ∀ {Γ Γ′} → (η : Γ′ ⊇ Γ)\n → idₛ ◐ η ≡ ⌊ η ⌋\nlid◐ done = refl\nlid◐ (wkₑ η) = ((idₛ ◐_) ∘ wkₑ) & rid○ η ⁻¹\n ⦙ comp◐○ (wkₑ idₑ) η idₛ ⁻¹\n ⦙ wkₛ & lid◐ η\nlid◐ (liftₑ η) = (_, 0) & ( comp◐○ (liftₑ η) (wkₑ idₑ) idₛ\n ⦙ ((idₛ ◐_) ∘ wkₑ) & ( lid○ η\n ⦙ rid○ η ⁻¹\n )\n ⦙ comp◐○ (wkₑ idₑ) η idₛ ⁻¹\n ⦙ (_◐ wkₑ idₑ) & lid◐ η\n )\n\n-- (idrₑₛ)\nrid◑ : ∀ {Γ Γ′} → (η : Γ′ ⊇ Γ)\n → η ◑ idₛ ≡ ⌊ η ⌋\nrid◑ done = refl\nrid◑ (wkₑ η) = comp◑◐ (wkₑ idₑ) idₛ η ⁻¹\n ⦙ wkₛ & rid◑ η\nrid◑ (liftₑ η) = (_, 0) & ( comp◑◐ (wkₑ idₑ) idₛ η ⁻¹\n ⦙ (_◐ wkₑ idₑ) & rid◑ η\n )\n\n\n--------------------------------------------------------------------------------\n\n\n-- (∈-ₑ∘ₛ)\nget◑ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (i : Ξ ∋ A)\n → getₛ (η ◑ σ) i ≡ (getₛ σ ∘ getₑ η) i\nget◑ σ done i = refl\nget◑ (σ , M) (wkₑ η) i = get◑ σ η i\nget◑ (σ , M) (liftₑ η) zero = refl\nget◑ (σ , M) (liftₑ η) (suc i) = get◑ σ η i\n\n-- (Tm-ₑ∘ₛ)\nmutual\n sub◑ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (M : Ξ ⊢ A)\n → sub (η ◑ σ) M ≡ (sub σ ∘ ren η) M\n sub◑ σ η (𝓋 i) = get◑ σ η i\n sub◑ σ η (ƛ M) = ƛ & sublift◑ σ η M\n sub◑ σ η (M ∙ N) = _∙_ & sub◑ σ η M\n ⊗ sub◑ σ η N\n sub◑ σ η (M , N) = _,_ & sub◑ σ η M\n ⊗ sub◑ σ η N\n sub◑ σ η (π₁ M) = π₁ & sub◑ σ η M\n sub◑ σ η (π₂ M) = π₂ & sub◑ σ η M\n sub◑ σ η τ = refl\n\n sublift◑ : ∀ {Γ Ξ Ξ′ A B} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (M : Ξ , B ⊢ A)\n → sub (liftₛ {B} (η ◑ σ)) M ≡\n (sub (liftₛ σ) ∘ ren (liftₑ η)) M\n sublift◑ σ η M = (λ σ′ → sub (σ′ , 0) M)\n & comp◑◐ (wkₑ idₑ) σ η\n ⦙ sub◑ (liftₛ σ) (liftₑ η) M\n\n\n--------------------------------------------------------------------------------\n\n\n-- (∈-ₛ∘ₑ)\nget◐ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ) (i : Ξ ∋ A)\n → getₛ (σ ◐ η) i ≡ (ren η ∘ getₛ σ) i\nget◐ η (σ , M) zero = refl\nget◐ η (σ , M) (suc i) = get◐ η σ i\n\n-- (Tm-ₛ∘ₑ)\nmutual\n sub◐ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ) (M : Ξ ⊢ A)\n → sub (σ ◐ η) M ≡ (ren η ∘ sub σ) M\n sub◐ η σ (𝓋 i) = get◐ η σ i\n sub◐ η σ (ƛ M) = ƛ & sublift◐ η σ M\n sub◐ η σ (M ∙ N) = _∙_ & sub◐ η σ M\n ⊗ sub◐ η σ N\n sub◐ η σ (M , N) = _,_ & sub◐ η σ M\n ⊗ sub◐ η σ N\n sub◐ η σ (π₁ M) = π₁ & sub◐ η σ M\n sub◐ η σ (π₂ M) = π₂ & sub◐ η σ M\n sub◐ η σ τ = refl\n\n sublift◐ : ∀ {Γ Γ′ Ξ A B} → (η : Γ′ ⊇ Γ) (σ : Γ ⊢⋆ Ξ) (M : Ξ , B ⊢ A)\n → sub (liftₛ {B} (σ ◐ η)) M ≡\n (ren (liftₑ η) ∘ sub (liftₛ σ)) M\n sublift◐ η σ M = (λ σ′ → sub (σ′ , 0) M)\n & ( comp◐○ (wkₑ idₑ) η σ\n ⦙ (σ ◐_) & (wkₑ & ( rid○ η\n ⦙ lid○ η ⁻¹\n ))\n ⦙ comp◐○ (liftₑ η) (wkₑ idₑ) σ ⁻¹\n )\n ⦙ sub◐ (liftₑ η) (liftₛ σ) M\n\n\n--------------------------------------------------------------------------------\n\n\n-- (assₛₑₛ)\ncomp●◑ : ∀ {Γ Ξ Ξ′ Φ} → (σ₁ : Γ ⊢⋆ Ξ′) (η : Ξ′ ⊇ Ξ) (σ₂ : Ξ ⊢⋆ Φ)\n → (σ₂ ◐ η) ● σ₁ ≡ σ₂ ● (η ◑ σ₁)\ncomp●◑ σ₁ η ∅ = refl\ncomp●◑ σ₁ η (σ₂ , M) = _,_ & comp●◑ σ₁ η σ₂\n ⊗ (sub◑ σ₁ η M ⁻¹)\n\n-- (assₛₛₑ)\ncomp●◐ : ∀ {Γ Γ′ Ξ Φ} → (η : Γ′ ⊇ Γ) (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ)\n → (σ₂ ● σ₁) ◐ η ≡ σ₂ ● (σ₁ ◐ η)\ncomp●◐ η σ₁ ∅ = refl\ncomp●◐ η σ₁ (σ₂ , M) = _,_ & comp●◐ η σ₁ σ₂\n ⊗ (sub◐ η σ₁ M ⁻¹)\n\n\n--------------------------------------------------------------------------------\n\n\n-- (∈-∘ₛ)\nget● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (i : Φ ∋ A)\n → getₛ (σ₂ ● σ₁) i ≡ (sub σ₁ ∘ getₛ σ₂) i\nget● σ₁ (σ₂ , M) zero = refl\nget● σ₁ (σ₂ , M) (suc i) = get● σ₁ σ₂ i\n\n-- (Tm-∘ₛ)\nmutual\n sub● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Φ ⊢ A)\n → sub (σ₂ ● σ₁) M ≡ (sub σ₁ ∘ sub σ₂) M\n sub● σ₁ σ₂ (𝓋 i) = get● σ₁ σ₂ i\n sub● σ₁ σ₂ (ƛ M) = ƛ & sublift● σ₁ σ₂ M\n sub● σ₁ σ₂ (M ∙ N) = _∙_ & sub● σ₁ σ₂ M\n ⊗ sub● σ₁ σ₂ N\n sub● σ₁ σ₂ (M , N) = _,_ & sub● σ₁ σ₂ M\n ⊗ sub● σ₁ σ₂ N\n sub● σ₁ σ₂ (π₁ M) = π₁ & sub● σ₁ σ₂ M\n sub● σ₁ σ₂ (π₂ M) = π₂ & sub● σ₁ σ₂ M\n sub● σ₁ σ₂ τ = refl\n\n sublift● : ∀ {Γ Ξ Φ A B} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Φ , B ⊢ A)\n → sub (liftₛ {B} (σ₂ ● σ₁)) M ≡\n (sub (liftₛ σ₁) ∘ sub (liftₛ σ₂)) M\n sublift● σ₁ σ₂ M = (λ σ′ → sub (σ′ , 0) M)\n & ( comp●◐ (wkₑ idₑ) σ₁ σ₂\n ⦙ (σ₂ ●_) & (lid◑ (wkₛ σ₁) ⁻¹)\n ⦙ comp●◑ (liftₛ σ₁) (wkₑ idₑ) σ₂ ⁻¹\n )\n ⦙ sub● (liftₛ σ₁) (liftₛ σ₂) M\n\n\n--------------------------------------------------------------------------------\n\n\n-- (∈-idₛ)\nidgetₛ : ∀ {Γ A} → (i : Γ ∋ A)\n → getₛ idₛ i ≡ 𝓋 i\nidgetₛ zero = refl\nidgetₛ (suc i) = get◐ (wkₑ idₑ) idₛ i\n ⦙ wk & idgetₛ i\n ⦙ 𝓋 ∘ suc & idgetₑ i\n\n-- (Tm-idₛ)\nidsub : ∀ {Γ A} → (M : Γ ⊢ A)\n → sub idₛ M ≡ M\nidsub (𝓋 i) = idgetₛ i\nidsub (ƛ M) = ƛ & idsub M\nidsub (M ∙ N) = _∙_ & idsub M\n ⊗ idsub N\nidsub (M , N) = _,_ & idsub M\n ⊗ idsub N\nidsub (π₁ M) = π₁ & idsub M\nidsub (π₂ M) = π₂ & idsub M\nidsub τ = refl\n\n\n--------------------------------------------------------------------------------\n\n\n-- (idrₛ)\nrid● : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ)\n → σ ● idₛ ≡ σ\nrid● ∅ = refl\nrid● (σ , M) = _,_ & rid● σ\n ⊗ idsub M\n\n-- (idlₛ)\nlid● : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ)\n → idₛ ● σ ≡ σ\nlid● ∅ = refl\nlid● (σ , M) = (_, M) & ( comp●◑ (σ , M) (wkₑ idₑ) idₛ\n ⦙ lid● (idₑ ◑ σ)\n ⦙ lid◑ σ\n )\n\n-- (assₛ)\nassoc● : ∀ {Γ Ξ Φ Ψ} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (σ₃ : Φ ⊢⋆ Ψ)\n → (σ₃ ● σ₂) ● σ₁ ≡ σ₃ ● (σ₂ ● σ₁)\nassoc● σ₁ σ₂ ∅ = refl\nassoc● σ₁ σ₂ (σ₃ , M) = _,_ & assoc● σ₁ σ₂ σ₃\n ⊗ (sub● σ₁ σ₂ M ⁻¹)\n\n\n--------------------------------------------------------------------------------\n\n\n𝗦𝗧𝗟𝗖 : Category 𝒞 _⊢⋆_\n𝗦𝗧𝗟𝗖 =\n record\n { idₓ = idₛ\n ; _⋄_ = _●_\n ; lid⋄ = lid●\n ; rid⋄ = rid●\n ; assoc⋄ = assoc●\n }\n\n\nsubPsh : 𝒯 → Presheaf₀ 𝗦𝗧𝗟𝗖\nsubPsh A =\n record\n { Fₓ = _⊢ A\n ; F = sub\n ; idF = fext! idsub\n ; F⋄ = λ σ₁ σ₂ → fext! (sub● σ₂ σ₁)\n }\n\n\n--------------------------------------------------------------------------------\n", "meta": {"hexsha": "211a5f0660175be469a28011730742afe443e892", "size": 9441, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/STLC1/Kovacs/Substitution.agda", "max_stars_repo_name": "mietek/coquand-kovacs", "max_stars_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79", "max_stars_repo_licenses": ["X11"], "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/STLC1/Kovacs/Substitution.agda", "max_issues_repo_name": "mietek/coquand-kovacs", "max_issues_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79", "max_issues_repo_licenses": ["X11"], "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/STLC1/Kovacs/Substitution.agda", "max_forks_repo_name": "mietek/coquand-kovacs", "max_forks_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79", "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": 28.5226586103, "max_line_length": 80, "alphanum_fraction": 0.2970024362, "num_tokens": 4753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.3516196361020301}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import homotopy.CoHSpace\n\nmodule homotopy.Cogroup where\n\nrecord CogroupStructure {i} (X : Ptd i) : Type i where\n field\n co-h-struct : CoHSpaceStructure X\n ⊙inv : X ⊙→ X\n open CoHSpaceStructure co-h-struct public\n\n inv : de⊙ X → de⊙ X\n inv = fst ⊙inv\n\n field\n ⊙inv-l : ⊙Wedge-rec ⊙inv (⊙idf X) ⊙∘ ⊙coμ ⊙∼ ⊙cst\n ⊙assoc : ⊙–> (⊙∨-assoc X X X) ⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ\n ⊙∼ ⊙∨-fmap (⊙idf X) ⊙coμ ⊙∘ ⊙coμ\n\n{-\nmodule _ {i j : ULevel} {X : Ptd i} (CGS : CogroupStructure X) where\n\n open CogroupStructure CGS\n\n private\n lemma-inv : ⊙Wedge-rec (⊙Lift-fmap ⊙inv) (⊙idf (⊙Lift {j = j} X))\n ⊙∘ ⊙∨-fmap (⊙lift {j = j}) (⊙lift {j = j})\n ⊙∘ ⊙coμ\n ⊙∘ ⊙lower {j = j}\n == ⊙cst\n abstract\n lemma-inv =\n ! (⊙λ= (⊙∘-assoc\n (⊙Wedge-rec (⊙Lift-fmap ⊙inv) (⊙idf (⊙Lift {j = j} X)))\n (⊙∨-fmap ⊙lift ⊙lift)\n (⊙coμ ⊙∘ ⊙lower)))\n ∙ ap (_⊙∘ ⊙coμ ⊙∘ ⊙lower) (⊙λ= (⊙Wedge-rec-fmap (⊙Lift-fmap ⊙inv) (⊙idf _) ⊙lift ⊙lift))\n ∙ ap (_⊙∘ ⊙coμ ⊙∘ ⊙lower) (! (⊙λ= (⊙Wedge-rec-post∘ ⊙lift ⊙inv (⊙idf _))))\n ∙ ⊙λ= (⊙∘-assoc ⊙lift (⊙Wedge-rec ⊙inv (⊙idf X)) (⊙coμ ⊙∘ ⊙lower))\n ∙ ap ⊙Lift-fmap (⊙λ= ⊙inv-l)\n\n private\n ⊙coμ' : ⊙Lift {j = j} X ⊙→ ⊙Lift {j = j} X ⊙∨ ⊙Lift {j = j} X\n ⊙coμ' = ⊙∨-fmap (⊙lift {j = j}) (⊙lift {j = j}) ⊙∘ ⊙coμ ⊙∘ ⊙lower {j = j}\n\n private\n lemma-assoc' :\n ⊙–> (⊙∨-assoc (⊙Lift {j = j} X) (⊙Lift {j = j} X) (⊙Lift {j = j} X))\n ⊙∘ ⊙∨-fmap ⊙coμ' (⊙idf (⊙Lift {j = j} X))\n ⊙∘ ⊙∨-fmap (⊙lift {j = j}) (⊙lift {j = j}) ⊙∘ ⊙coμ\n == ⊙∨-fmap (⊙idf (⊙Lift {j = j} X)) ⊙coμ'\n ⊙∘ ⊙∨-fmap (⊙lift {j = j}) (⊙lift {j = j}) ⊙∘ ⊙coμ\n abstract\n lemma-assoc' =\n ⊙–> (⊙∨-assoc (⊙Lift X) (⊙Lift X) (⊙Lift X))\n ⊙∘ ⊙∨-fmap ⊙coμ' (⊙idf (⊙Lift {j = j} X))\n ⊙∘ ⊙∨-fmap ⊙lift ⊙lift ⊙∘ ⊙coμ\n =⟨ ! $ ap (⊙–> (⊙∨-assoc _ _ _) ⊙∘_) $ ⊙λ= $\n ⊙∘-assoc\n (⊙∨-fmap ⊙coμ' (⊙idf (⊙Lift X)))\n (⊙∨-fmap ⊙lift ⊙lift)\n ⊙coμ ⟩\n ⊙–> (⊙∨-assoc (⊙Lift X) (⊙Lift X) (⊙Lift X))\n ⊙∘ (⊙∨-fmap ⊙coμ' (⊙idf (⊙Lift X)) ⊙∘ ⊙∨-fmap ⊙lift ⊙lift)\n ⊙∘ ⊙coμ\n =⟨ ap (λ f → ⊙–> (⊙∨-assoc _ _ _ ) ⊙∘ f ⊙∘ ⊙coμ) $\n ! (⊙λ= $ ⊙∨-fmap-∘ ⊙coμ' ⊙lift (⊙idf (⊙Lift X)) ⊙lift)\n ∙ (⊙λ= $ ⊙∨-fmap-∘ (⊙∨-fmap ⊙lift ⊙lift) ⊙coμ ⊙lift (⊙idf X)) ⟩\n ⊙–> (⊙∨-assoc (⊙Lift X) (⊙Lift X) (⊙Lift X))\n ⊙∘ (⊙∨-fmap (⊙∨-fmap ⊙lift ⊙lift) ⊙lift ⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X))\n ⊙∘ ⊙coμ\n =⟨ ap (⊙–> (⊙∨-assoc _ _ _ ) ⊙∘_) $ ⊙λ= $\n ⊙∘-assoc\n (⊙∨-fmap (⊙∨-fmap ⊙lift ⊙lift) ⊙lift)\n (⊙∨-fmap ⊙coμ (⊙idf X))\n ⊙coμ ⟩\n ⊙–> (⊙∨-assoc (⊙Lift X) (⊙Lift X) (⊙Lift X))\n ⊙∘ ⊙∨-fmap (⊙∨-fmap ⊙lift ⊙lift) ⊙lift\n ⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ\n =⟨ ! $ ⊙λ= $\n ⊙∘-assoc\n (⊙–> (⊙∨-assoc (⊙Lift X) (⊙Lift X) (⊙Lift X)))\n (⊙∨-fmap (⊙∨-fmap ⊙lift ⊙lift) ⊙lift)\n (⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ) ⟩\n (⊙–> (⊙∨-assoc (⊙Lift X) (⊙Lift X) (⊙Lift X)) ⊙∘ ⊙∨-fmap (⊙∨-fmap ⊙lift ⊙lift) ⊙lift)\n ⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ\n =⟨ ap (_⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ) $\n ⊙λ= $ ⊙∨-assoc-nat ⊙lift ⊙lift ⊙lift ⟩\n (⊙∨-fmap ⊙lift (⊙∨-fmap ⊙lift ⊙lift) ⊙∘ ⊙–> (⊙∨-assoc X X X))\n ⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ\n =⟨ ⊙λ= $ ⊙∘-assoc\n (⊙∨-fmap ⊙lift (⊙∨-fmap ⊙lift ⊙lift))\n (⊙–> (⊙∨-assoc X X X))\n (⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ) ⟩\n ⊙∨-fmap ⊙lift (⊙∨-fmap ⊙lift ⊙lift)\n ⊙∘ ⊙–> (⊙∨-assoc X X X) ⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ\n =⟨ ap (⊙∨-fmap ⊙lift (⊙∨-fmap ⊙lift ⊙lift) ⊙∘_) $ ⊙λ= ⊙assoc ⟩\n ⊙∨-fmap ⊙lift (⊙∨-fmap ⊙lift ⊙lift)\n ⊙∘ ⊙∨-fmap (⊙idf X) ⊙coμ ⊙∘ ⊙coμ\n =⟨ ! $ ⊙λ= $ ⊙∘-assoc\n (⊙∨-fmap ⊙lift (⊙∨-fmap ⊙lift ⊙lift))\n (⊙∨-fmap (⊙idf X) ⊙coμ)\n ⊙coμ ⟩\n (⊙∨-fmap ⊙lift (⊙∨-fmap ⊙lift ⊙lift)\n ⊙∘ ⊙∨-fmap (⊙idf X) ⊙coμ)\n ⊙∘ ⊙coμ\n =⟨ ap (_⊙∘ ⊙coμ) $\n ! (⊙λ= $ ⊙∨-fmap-∘ ⊙lift (⊙idf X) (⊙∨-fmap ⊙lift ⊙lift) ⊙coμ)\n ∙ (⊙λ= $ ⊙∨-fmap-∘ (⊙idf (⊙Lift X)) ⊙lift ⊙coμ' ⊙lift) ⟩\n (⊙∨-fmap (⊙idf (⊙Lift X)) ⊙coμ' ⊙∘ ⊙∨-fmap ⊙lift ⊙lift) ⊙∘ ⊙coμ\n =⟨ ⊙λ= $ ⊙∘-assoc (⊙∨-fmap (⊙idf (⊙Lift X)) ⊙coμ') (⊙∨-fmap ⊙lift ⊙lift) ⊙coμ ⟩\n ⊙∨-fmap (⊙idf (⊙Lift X)) ⊙coμ' ⊙∘ ⊙∨-fmap ⊙lift ⊙lift ⊙∘ ⊙coμ\n =∎\n\n private\n lemma-assoc :\n ⊙–> (⊙∨-assoc (⊙Lift {j = j} X) (⊙Lift {j = j} X) (⊙Lift {j = j} X))\n ⊙∘ ⊙∨-fmap ⊙coμ' (⊙idf (⊙Lift {j = j} X)) ⊙∘ ⊙coμ'\n == ⊙∨-fmap (⊙idf (⊙Lift {j = j} X)) ⊙coμ' ⊙∘ ⊙coμ'\n abstract\n lemma-assoc = ap (_⊙∘ ⊙lower) lemma-assoc'\n\n Lift-cogroup-structure : CogroupStructure (⊙Lift {j = j} X)\n Lift-cogroup-structure = record\n { co-h-struct = Lift-co-h-space-structure {j = j} co-h-struct\n ; ⊙inv = ⊙lift ⊙∘ ⊙inv ⊙∘ ⊙lower\n ; ⊙inv-l = ⊙app= lemma-inv\n ; ⊙assoc = ⊙app= lemma-assoc\n }\n-}\n\nmodule _ {i j} {X : Ptd i} (cogroup-struct : CogroupStructure X) (Y : Ptd j) where\n\n private\n module CGS = CogroupStructure cogroup-struct\n ⊙coμ = CGS.⊙coμ\n\n comp : (X ⊙→ Y) → (X ⊙→ Y) → (X ⊙→ Y)\n comp f g = ⊙Wedge-rec f g ⊙∘ ⊙coμ\n\n inv : (X ⊙→ Y) → (X ⊙→ Y)\n inv = _⊙∘ CGS.⊙inv\n\n abstract\n unit-l : ∀ f → comp ⊙cst f == f\n unit-l f =\n ⊙Wedge-rec ⊙cst f ⊙∘ ⊙coμ\n =⟨ ap2 (λ f g → ⊙Wedge-rec f g ⊙∘ ⊙coμ) (! $ ⊙λ= (⊙∘-cst-r f)) (! $ ⊙λ= (⊙∘-unit-r f)) ⟩\n ⊙Wedge-rec (f ⊙∘ ⊙cst) (f ⊙∘ ⊙idf X) ⊙∘ ⊙coμ\n =⟨ ap (_⊙∘ ⊙coμ) (! $ ⊙λ= $ ⊙Wedge-rec-post∘ f ⊙cst (⊙idf X)) ⟩\n (f ⊙∘ ⊙Wedge-rec ⊙cst (⊙idf X)) ⊙∘ ⊙coμ\n =⟨ ⊙λ= $ ⊙∘-assoc f (⊙Wedge-rec ⊙cst (⊙idf X)) ⊙coμ ⟩\n f ⊙∘ (⊙Wedge-rec ⊙cst (⊙idf X) ⊙∘ ⊙coμ)\n =⟨ ap (f ⊙∘_) (⊙λ= CGS.⊙unit-l) ⟩\n f ⊙∘ ⊙idf X\n =⟨ ⊙λ= (⊙∘-unit-r f) ⟩\n f\n =∎\n\n assoc : ∀ f g h → comp (comp f g) h == comp f (comp g h)\n assoc f g h =\n ⊙Wedge-rec (⊙Wedge-rec f g ⊙∘ ⊙coμ) h ⊙∘ ⊙coμ\n =⟨ ! $ ⊙λ= (⊙∘-unit-r h) |in-ctx (λ h → ⊙Wedge-rec (⊙Wedge-rec f g ⊙∘ ⊙coμ) h ⊙∘ ⊙coμ) ⟩\n ⊙Wedge-rec (⊙Wedge-rec f g ⊙∘ ⊙coμ) (h ⊙∘ ⊙idf X) ⊙∘ ⊙coμ\n =⟨ ! $ ⊙λ= (⊙Wedge-rec-fmap (⊙Wedge-rec f g) h ⊙coμ (⊙idf X)) |in-ctx _⊙∘ ⊙coμ ⟩\n (⊙Wedge-rec (⊙Wedge-rec f g) h ⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X)) ⊙∘ ⊙coμ\n =⟨ ⊙λ= $ ⊙∘-assoc (⊙Wedge-rec (⊙Wedge-rec f g) h) (⊙∨-fmap ⊙coμ (⊙idf X)) ⊙coμ ⟩\n ⊙Wedge-rec (⊙Wedge-rec f g) h ⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ\n =⟨ ⊙λ= (⊙Wedge-rec-assoc f g h) |in-ctx _⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ ⟩\n (⊙Wedge-rec f (⊙Wedge-rec g h) ⊙∘ ⊙–> (⊙∨-assoc X X X)) ⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ\n =⟨ ⊙λ= $ ⊙∘-assoc (⊙Wedge-rec f (⊙Wedge-rec g h)) (⊙–> (⊙∨-assoc X X X)) (⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ) ⟩\n ⊙Wedge-rec f (⊙Wedge-rec g h) ⊙∘ ⊙–> (⊙∨-assoc X X X) ⊙∘ ⊙∨-fmap ⊙coμ (⊙idf X) ⊙∘ ⊙coμ\n =⟨ ⊙λ= CGS.⊙assoc |in-ctx ⊙Wedge-rec f (⊙Wedge-rec g h) ⊙∘_ ⟩\n ⊙Wedge-rec f (⊙Wedge-rec g h) ⊙∘ ⊙∨-fmap (⊙idf X) ⊙coμ ⊙∘ ⊙coμ\n =⟨ ! $ ⊙λ= $ ⊙∘-assoc (⊙Wedge-rec f (⊙Wedge-rec g h)) (⊙∨-fmap (⊙idf X) ⊙coμ) ⊙coμ ⟩\n (⊙Wedge-rec f (⊙Wedge-rec g h) ⊙∘ ⊙∨-fmap (⊙idf X) ⊙coμ) ⊙∘ ⊙coμ\n =⟨ ⊙λ= (⊙Wedge-rec-fmap f (⊙Wedge-rec g h) (⊙idf X) ⊙coμ) |in-ctx _⊙∘ ⊙coμ ⟩\n ⊙Wedge-rec (f ⊙∘ ⊙idf X) (⊙Wedge-rec g h ⊙∘ ⊙coμ) ⊙∘ ⊙coμ\n =⟨ ⊙λ= (⊙∘-unit-r f) |in-ctx (λ f → ⊙Wedge-rec f (⊙Wedge-rec g h ⊙∘ ⊙coμ) ⊙∘ ⊙coμ) ⟩\n ⊙Wedge-rec f (⊙Wedge-rec g h ⊙∘ ⊙coμ) ⊙∘ ⊙coμ\n =∎\n\n inv-l : ∀ f → comp (inv f) f == ⊙cst\n inv-l f =\n ⊙Wedge-rec (f ⊙∘ CGS.⊙inv) f ⊙∘ ⊙coμ\n =⟨ ap (λ g → ⊙Wedge-rec (f ⊙∘ CGS.⊙inv) g ⊙∘ ⊙coμ) (! $ ⊙λ= (⊙∘-unit-r f)) ⟩\n ⊙Wedge-rec (f ⊙∘ CGS.⊙inv) (f ⊙∘ ⊙idf X) ⊙∘ ⊙coμ\n =⟨ ap (_⊙∘ ⊙coμ) (! $ ⊙λ= $ ⊙Wedge-rec-post∘ f CGS.⊙inv (⊙idf X)) ⟩\n (f ⊙∘ ⊙Wedge-rec CGS.⊙inv (⊙idf X)) ⊙∘ ⊙coμ\n =⟨ ⊙λ= $ ⊙∘-assoc f (⊙Wedge-rec CGS.⊙inv (⊙idf X)) ⊙coμ ⟩\n f ⊙∘ (⊙Wedge-rec CGS.⊙inv (⊙idf X) ⊙∘ ⊙coμ)\n =⟨ ap (f ⊙∘_) (⊙λ= CGS.⊙inv-l) ⟩\n f ⊙∘ ⊙cst\n =⟨ ⊙λ= (⊙∘-cst-r f) ⟩\n ⊙cst\n =∎\n\n cogroup⊙→-group-structure : GroupStructure (X ⊙→ Y)\n cogroup⊙→-group-structure = record\n { ident = ⊙cst\n ; inv = inv\n ; comp = comp\n ; unit-l = unit-l\n ; assoc = assoc\n ; inv-l = inv-l\n }\n", "meta": {"hexsha": "203aa9469741fbdf41b86000b9e5e81d000cef59", "size": 8436, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/homotopy/Cogroup.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/homotopy/Cogroup.agda", "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/homotopy/Cogroup.agda", "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 40.3636363636, "max_line_length": 116, "alphanum_fraction": 0.4110953058, "num_tokens": 5148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.7371581741774411, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.35131458542822136}} {"text": "------------------------------------------------------------------------\n-- A virtual machine\n------------------------------------------------------------------------\n\n{-# OPTIONS --cubical --safe #-}\n\nmodule Lambda.Simplified.Partiality-monad.Inductive.Virtual-machine\n where\n\nopen import Equality.Propositional\nopen import Prelude hiding (⊥)\n\nopen import Monad equality-with-J\n\nopen import Partiality-monad.Inductive\nopen import Partiality-monad.Inductive.Fixpoints\n\nopen import Lambda.Simplified.Syntax\nopen import Lambda.Simplified.Virtual-machine\n\nopen Closure Code\n\n-- A functional semantics for the VM.\n--\n-- For an alternative definition, see the semantics in\n-- Lambda.Partiality-monad.Inductive.Virtual-machine, which is defined\n-- without using a fixpoint combinator.\n\nexecP : State → Partial State (λ _ → Maybe Value) (Maybe Value)\nexecP s with step s\n... | continue s′ = rec s′\n... | done v = return (just v)\n... | crash = return nothing\n\nexec : State → Maybe Value ⊥\nexec s = fixP execP s\n", "meta": {"hexsha": "741d43799abcbb2b600e2f74df4ee02238bdb4c4", "size": 1015, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Lambda/Simplified/Partiality-monad/Inductive/Virtual-machine.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/Virtual-machine.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/Virtual-machine.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": 27.4324324324, "max_line_length": 72, "alphanum_fraction": 0.6344827586, "num_tokens": 219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7431680086124811, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.35128323802403133}} {"text": "\n-- Closed monoid in the skew-closed category of families\nmodule SOAS.Abstract.Monoid {T : Set} where\n\nopen import SOAS.Common\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.ContextMaps.Combinators\n\nopen import SOAS.Construction.Structure as Structure\n\nopen import SOAS.Abstract.Hom {T}\nopen import SOAS.Abstract.Coalgebra using (module Sorted) ; open Sorted\nopen import SOAS.Families.Core {T}\n\nopen import Categories.Category.Equivalence using (StrongEquivalence)\nopen import Categories.NaturalTransformation.NaturalIsomorphism using (niHelper)\n\nopen import SOAS.Coalgebraic.Map {T}\nopen import SOAS.Coalgebraic.Lift {T}\n\nprivate\n variable\n Γ Δ Θ : Ctx\n α β γ : T\n\nrecord Mon (𝒳 : Familyₛ) : Set where\n field\n η : ℐ ⇾̣ 𝒳\n μ : 𝒳 ⇾̣ 〖 𝒳 , 𝒳 〗\n\n lunit : {σ : Γ ~[ 𝒳 ]↝ Δ}{v : ℐ α Γ}\n → μ (η v) σ ≡ σ v\n runit : {t : 𝒳 α Γ} → μ t η ≡ t\n assoc : {σ : Γ ~[ 𝒳 ]↝ Δ}{ς : Δ ~[ 𝒳 ]↝ Θ} {t : 𝒳 α Γ}\n → μ (μ t σ) ς ≡ μ t (λ v → μ (σ v) ς)\n\n -- Congruence in both arguments of the multiplication\n μ≈₁ : {t₁ t₂ : 𝒳 α Γ}{σ : Γ ~[ 𝒳 ]↝ Δ}\n → t₁ ≡ t₂\n → μ t₁ σ ≡ μ t₂ σ\n μ≈₁ refl = refl\n\n μ≈₂ : {t : 𝒳 α Γ}{σ ς : Γ ~[ 𝒳 ]↝ Δ}\n → ({τ : T}{v : ℐ τ Γ} → σ v ≡ ς v)\n → μ t σ ≡ μ t ς\n μ≈₂ {t = t} p = cong (μ t) (dext′ p)\n\n -- Monoids are pointed coalgebras\n ᵇ : Coalg 𝒳\n ᵇ = record { r = λ t ρ → μ t (η ∘ ρ) ; counit = runit\n ; comult = λ { {t = t} → sym (trans assoc (μ≈₂ lunit)) } }\n\n ᴮ : Coalgₚ 𝒳\n ᴮ = record { ᵇ = ᵇ ; η = η ; r∘η = lunit }\n\n -- Single-variable substitution\n [_/] : 𝒳 α Γ → 𝒳 β (α ∙ Γ) → 𝒳 β Γ\n [ s /] t = μ t (add 𝒳 s η)\n\n -- Substitution for second variable\n [_/]′ : 𝒳 α Γ → 𝒳 γ (β ∙ α ∙ Γ) → 𝒳 γ (β ∙ Γ)\n [ s /]′ t = μ t (lift₁ ᴮ (add 𝒳 s η))\n\n -- Substitution for top two variables\n [_,_/]₂ : 𝒳 α Γ → 𝒳 β Γ → 𝒳 γ (α ∙ β ∙ Γ) → 𝒳 γ Γ\n [ s₁ , s₂ /]₂ t = μ t (add 𝒳 s₁ (add 𝒳 s₂ η))\n\n\n open Coalgₚ ᴮ public using (r ; r∘η)\n\n -- Multiplication is coalgebraic map\n μᶜ : Coalgebraic ᴮ ᴮ ᴮ μ\n μᶜ = record { r∘f = assoc ; f∘r = trans assoc (μ≈₂ lunit) ; f∘η = lunit }\n\n\n-- Monoid homomorphisms\nrecord Mon⇒ {𝒳 𝒴 : Familyₛ}(𝒳ᵐ : Mon 𝒳)(𝒴ᵐ : Mon 𝒴)\n (f : 𝒳 ⇾̣ 𝒴) : Set where\n\n private module 𝒳 = Mon 𝒳ᵐ\n private module 𝒴 = Mon 𝒴ᵐ\n\n field\n ⟨η⟩ : {v : ℐ α Γ} → f (𝒳.η v) ≡ 𝒴.η v\n ⟨μ⟩ : {σ : Γ ~[ 𝒳 ]↝ Δ}{t : 𝒳 α Γ}\n → f (𝒳.μ t σ) ≡ 𝒴.μ (f t) (f ∘ σ)\n\n ᵇ⇒ : Coalg⇒ 𝒳.ᵇ 𝒴.ᵇ f\n ᵇ⇒ = record { ⟨r⟩ = trans ⟨μ⟩ (𝒴.μ≈₂ ⟨η⟩) }\n\n ᴮ⇒ : Coalgₚ⇒ 𝒳.ᴮ 𝒴.ᴮ f\n ᴮ⇒ = record { ᵇ⇒ = ᵇ⇒ ; ⟨η⟩ = ⟨η⟩ }\n\n -- Preservation of multiplication and unit implies the semantic substitution\n -- lemma for single- and double-variable substitution\n sub-lemma : (s : 𝒳 α Γ)(t : 𝒳 β (α ∙ Γ)) →\n f (𝒳.[ s /] t) ≡ 𝒴.[ f s /] (f t)\n sub-lemma s t = trans ⟨μ⟩ (cong (𝒴.μ (f t))\n (dext λ{ new → refl ; (old y) → ⟨η⟩}))\n\n sub-lemma₂ : (s₁ : 𝒳 α Γ)(s₂ : 𝒳 β Γ)(t : 𝒳 γ (α ∙ β ∙ Γ)) →\n f (𝒳.[ s₁ , s₂ /]₂ t) ≡ 𝒴.[ f s₁ , f s₂ /]₂ (f t)\n sub-lemma₂ s₁ s₂ t = trans ⟨μ⟩ (cong (𝒴.μ (f t))\n (dext λ{ new → refl ; (old new) → refl\n ; (old (old y)) → ⟨η⟩}))\n\n\nmodule MonoidStructure = Structure 𝔽amiliesₛ Mon\n\n-- Category of substitution monoids\n𝕄onoids : Category 1ℓ 0ℓ 0ℓ\n𝕄onoids = MonoidStructure.StructCat record\n { IsHomomorphism = Mon⇒\n ; id-hom = record { ⟨η⟩ = refl ; ⟨μ⟩ = refl }\n ; comp-hom = λ g f gᵐ⇒ fᵐ⇒ → record\n { ⟨η⟩ = trans (cong g (⟨η⟩ fᵐ⇒)) (⟨η⟩ gᵐ⇒)\n ; ⟨μ⟩ = trans (cong g (⟨μ⟩ fᵐ⇒)) (⟨μ⟩ gᵐ⇒)\n }\n } where open Mon⇒\n\nmodule 𝕄on = Category 𝕄onoids\n\nMonoid : Set₁\nMonoid = 𝕄on.Obj\n\nMonoid⇒ : Monoid → Monoid → Set\nMonoid⇒ = 𝕄on._⇒_\n\nmodule AsMonoid (ℳᵐ : Monoid) where\n open Object ℳᵐ renaming (𝐶 to ℳ; ˢ to ᵐ) public\n open Mon ᵐ public\n\n\n\nmodule AsMonoid⇒ {ℳᵐ 𝒩ᵐ : Monoid} (fᵐ⇒ : Monoid⇒ ℳᵐ 𝒩ᵐ) where\n open Morphism fᵐ⇒ renaming (𝑓 to f ; ˢ⇒ to ᵐ⇒) public\n open Mon⇒ ᵐ⇒ public\n", "meta": {"hexsha": "feea3d8e79ab8d79f4e04967a7da86a2a59ba3c7", "size": 3917, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "SOAS/Abstract/Monoid.agda", "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_issues_repo_path": "SOAS/Abstract/Monoid.agda", "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_forks_repo_path": "SOAS/Abstract/Monoid.agda", "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "avg_line_length": 28.1798561151, "max_line_length": 80, "alphanum_fraction": 0.5394434516, "num_tokens": 1906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7490872243177518, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.35116506928563246}} {"text": "open import Data.Nat\nopen import Data.Fin\nopen import Data.List\nopen import Data.List.Membership.Propositional\nopen import Data.List.Relation.Unary.All as All\nopen import Data.List.All.Properties.Extra\nopen import Data.Vec hiding (_∷ʳ_ ; _>>=_ ; init)\nopen import Data.Product\nopen import Relation.Binary.PropositionalEquality hiding ([_])\nopen ≡-Reasoning\nopen import Data.Unit\nopen import Data.List.Prefix\nopen import Data.List.Properties.Extra\nopen import Data.Maybe\nopen import Common.Weakening\n\n-- This file contains the Agda Scope Graph Library described in\n-- Section 4 of the paper.\n\n-- The definitions are parameterized by a scope graph, where a scope\n-- graph is a finite map from scope identifiers to scope shape\n-- descriptors.\n--\n-- The scope graph library is also parametric in what the notion of\n-- type is for declarations in the scope graph.\n--\n-- We use modules for this library parameterization. The `k`\n-- parameter of the `ScopesFrames` module represents the number of\n-- scope identifiers in the scope graph that all definitions are\n-- parameterized over; and the `Ty` parameter is a language-specific\n-- notion of type.\n\nmodule ScopesFrames.ScopesFrames (k : ℕ) (Ty : Set) where\n\n\n------------------\n-- SCOPE GRAPHS --\n------------------\n\n-- Type aliases for scope identifiers (`Scope`s) and scope graphs\n-- (`Graph`s).\n--\n-- As described in the paper, scope shapes are given by a list of\n-- types corresponding to the declarations of the scope, and a list of\n-- scopes, corresponding to the edges of the scope.\n\nScope = Fin k\nGraph = Scope → (List Ty × List Scope)\n\n-- All the following definitions are parameterized by a scope graph\n-- `g`.\n\nmodule UsesGraph (g : Graph) where\n\n -- Some projection functions:\n declsOf : Scope → List Ty ; declsOf s = proj₁ (g s)\n edgesOf : Scope → List Scope ; edgesOf s = proj₂ (g s)\n\n -- A resolution path is a witness that we can traverse a sequence of\n -- scope edges (`_⟶_`) in `g` to arrive at a declaration of type\n -- `t`:\n\n data _⟶_ : Scope → Scope → Set where\n [] : ∀ {s} → s ⟶ s\n _∷_ : ∀ {s s' s''} → s' ∈ edgesOf s → s' ⟶ s'' → s ⟶ s''\n\n -- path concatenation\n concatₚ : ∀ {s s' s''} → s ⟶ s' → s' ⟶ s'' → s ⟶ s''\n concatₚ [] p₂ = p₂\n concatₚ (x ∷ p₁) p₂ = x ∷ (concatₚ p₁ p₂)\n\n data _↦_ (s : Scope) (t : Ty) : Set where\n path : ∀{s'} → s ⟶ s' → t ∈ declsOf s' → s ↦ t\n\n prepend : ∀ {s s' t} → s ⟶ s' → s' ↦ t → s ↦ t\n prepend p (path p' d) = path (concatₚ p p') d\n\n -- The definitions above fully define scope graphs. The remaining\n -- definitions in this file are intrinsically-typed by this notion\n -- of scope graph.\n\n\n ----------------------\n -- FRAMES AND HEAPS --\n ----------------------\n\n -- Heap types summarize what the scope is for each frame location in\n -- the heap:\n\n HeapTy = List Scope\n\n -- A frame pointer `Frame s Σ` is a witness that there is a frame\n -- location scoped by `s` in a heap typed by `Σ`:\n\n Frame : Scope → (Σ : HeapTy) → Set\n Frame s Σ = s ∈ Σ\n\n -- Concrete frames and heaps store values that are weakened when the\n -- heap is extended. The following definitions are parameterized by\n -- a language-specific notion of weakenable value.\n\n module UsesVal (Val : Ty → HeapTy → Set)\n (weaken-val : ∀ {t Σ Σ'} → Σ ⊑ Σ' → Val t Σ → Val t Σ') where\n\n -- Slots are given by a list of values that are in one-to-one\n -- correspondence with a list of declarations (types):\n\n Slots : (ds : List Ty) → (Σ : HeapTy) → Set\n Slots ds Σ = All (λ t → Val t Σ) ds\n\n -- Links are given by a list of frame pointers (links) that are in\n -- one-to-one correspondence with a list of edges (scopes):\n\n Links : (es : List Scope) → (Σ : HeapTy) → Set\n Links es Σ = All (λ s → Frame s Σ) es\n\n -- A heap frame for a scope `s` is given by a set of slots and\n -- links that are in one-to-one correspondence with the\n -- declarations and edges of the scope:\n\n HeapFrame : Scope → HeapTy → Set\n HeapFrame s Σ = Slots (declsOf s) Σ × Links (edgesOf s) Σ\n\n -- A heap typed by `Σ` is given by a list of heap frames such that\n -- each frame location is in the heap is typed by the\n -- corresponding location in `Σ`.\n\n Heap : (Σ : HeapTy) → Set\n Heap Σ = All (λ s → HeapFrame s Σ) Σ\n\n\n ----------------------\n -- FRAME OPERATIONS --\n ----------------------\n\n -- Frame initialization extends the heap, requiring heap type\n -- weakening. The `Common.Weakening` module defines a generic\n -- `Weakenable` record, which we instantiate for each entity that\n -- is required to be weakenable. We use Agda's instance arguments\n -- to automatically resolve the right notion of weakening where\n -- possible.\n\n -- We add some instances of the Weakenable typeclass\n -- to the instance argument scope:\n\n instance\n weaken-val' : ∀ {t} → Weakenable (λ Σ → Val t Σ)\n weaken-val' = record { wk = weaken-val }\n\n weaken-frame : ∀ {s} → Weakenable (Frame s)\n weaken-frame = record { wk = Weakenable.wk any-weakenable }\n\n -- Frame initialization takes as argument:\n --\n -- * a scope `s`;\n --\n -- * a scope shape witness which asserts that looking up `s` in\n -- the current scope graph `g` yields a scope shape where the\n -- declarations are given by a list of types `ds`, and scope\n -- edges are given by a list of scopes `es`;\n --\n -- * a set of slots typed by `ds`;\n --\n -- * a set of links typed by `es`; and\n --\n -- * a heap typed by the heap type `Σ` which also types the slots\n -- and links.\n --\n -- The operation returns an extended heap (`∷ʳ` appends a single\n -- element to a list, and is defined in `Data.List.Base` in the\n -- Agda Standard Library) and a frame pointer into the extended\n -- heap, i.e., the newly allocated and initialized frame.\n\n initFrame : (s : Scope) → ∀ {Σ ds es}⦃ shape : g s ≡ (ds , es) ⦄ →\n Slots ds Σ → Links es Σ → Heap Σ → Frame s (Σ ∷ʳ s) × Heap (Σ ∷ʳ s)\n initFrame s {Σ} ⦃ refl ⦄ slots links h =\n let ext = ∷ʳ-⊒ s Σ -- heap extension fact\n f' = ∈-∷ʳ Σ s -- updated frame pointer witness\n h' = (wk ext h) all-∷ʳ (wk ext slots , wk ext links) -- extended heap\n in (f' , h')\n\n -- Frames may be self-referential. For example, the values stored\n -- in the slots of a frame may contain pointers to the frame\n -- itself. The `initFrame` function above does not support\n -- initializing such self-referential slots, since the slots are\n -- assumed to be typed under the unextended heap.\n --\n -- The `initFrameι` function we now define takes as argument a\n -- function to be used to initialize possibly-self-referential\n -- frame slots. The function takes as argument a frame pointer\n -- into a heap extended by the scope that we are currently\n -- initializing, and slots are typed under this extended heap;\n -- hence the slots can have self-references to the frame currently\n -- being initialized.\n\n initFrameι : (s : Scope) → ∀ {Σ ds es}⦃ shape : g s ≡ (ds , es) ⦄ →\n (slotsf : Frame s (Σ ∷ʳ s) → Slots ds (Σ ∷ʳ s)) → Links es Σ → Heap Σ →\n Frame s (Σ ∷ʳ s) × Heap (Σ ∷ʳ s)\n initFrameι s {Σ} ⦃ refl ⦄ slotsf links h =\n let ext = ∷ʳ-⊒ s Σ -- heap extension fact\n f' = ∈-∷ʳ Σ s -- updated frame pointer witness\n h' = (wk ext h) all-∷ʳ (slotsf f' , wk ext links) -- extended heap\n in (f' , h')\n\n\n -- Given a witness that a declaration typed by `t` is in a scope,\n -- and a frame pointer, we can fetch the well-typed value stored\n -- in the corresponding frame slot:\n\n getSlot : ∀ {s t Σ} → t ∈ declsOf s → Frame s Σ → Heap Σ → Val t Σ\n getSlot d f h\n with (All.lookup h f)\n ... | (slots , links) = All.lookup slots d\n\n -- Given a witness that a declaration typed by `t` is in a scope,\n -- and a frame pointer, we can mutate the corresponding slot in a\n -- type preserving manner:\n\n setSlot : ∀ {s t Σ} → t ∈ declsOf s → Val t Σ → Frame s Σ → Heap Σ → Heap Σ\n setSlot d v f h\n with (All.lookup h f)\n ... | (slots , links) = h All.[ f ]≔ (slots All.[ d ]≔ v , links)\n\n -- ... and similarly for edges:\n\n getLink : ∀ {s s' Σ} → s' ∈ edgesOf s → Frame s Σ → Heap Σ → Frame s' Σ\n getLink e f h\n with (All.lookup h f)\n ... | (slots , links) = All.lookup links e\n\n setLink : ∀ {s s' Σ} → s' ∈ edgesOf s → Frame s' Σ → Frame s Σ → Heap Σ → Heap Σ\n setLink e f' f h\n with (All.lookup h f)\n ... | (slots , links) = h All.[ f ]≔ (slots , links All.[ e ]≔ f')\n\n -- Given a witness that there is a path through the scope graph\n -- from scope `s` to scope `s'`, a frame typed by `s`, and a\n -- well-typed heap, we can traverse the path by following the\n -- corresponding frame links in the heap to arrive at a frame\n -- scoped by `s'`:\n\n getFrame : ∀ {s s' Σ} → (s ⟶ s') → Frame s Σ → Heap Σ → Frame s' Σ\n getFrame [] f h = f\n getFrame (e ∷ p) f h\n with (All.lookup h f)\n ... | (slots , links) = getFrame p (All.lookup links e) h\n\n -- Given the definitions above, we can define some shorthand\n -- functions for getting and setting values:\n\n getVal : ∀ {s t} → (s ↦ t) → ∀ {Σ} → Frame s Σ → Heap Σ → Val t Σ\n getVal (path p d) f h = getSlot d (getFrame p f h) h\n\n setVal : ∀ {s t Σ} → (s ↦ t) → Val t Σ → Frame s Σ → Heap Σ → Heap Σ\n setVal (path p d) v f h = setSlot d v (getFrame p f h) h\n", "meta": {"hexsha": "4586446e3bd79c483284895c5f2b18f83e04dd44", "size": 9510, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/ScopesFrames/ScopesFrames.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/ScopesFrames/ScopesFrames.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/ScopesFrames/ScopesFrames.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": 37.1484375, "max_line_length": 88, "alphanum_fraction": 0.6124079916, "num_tokens": 2886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7490872131147276, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.3511650640337597}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import cohomology.CupProduct.OnEM.InAllDegrees\nopen import cohomology.CupProduct.OnEM.CommutativityInAllDegrees\nopen import cohomology.EMModel\nopen import cohomology.Theory\nopen import groups.ToOmega\nopen import homotopy.EilenbergMacLane\nopen import homotopy.EilenbergMacLaneFunctor\nopen import homotopy.Freudenthal\nopen import homotopy.SuspensionLoopSpaceInverse\n\nmodule cohomology.CupProduct.Definition {i} (X : Ptd i) where\n\nprivate\n module M {k} (A : AbGroup k) = CohomologyTheory (EM-Cohomology A)\n open M\n\n⊙×-diag : X ⊙→ X ⊙× X\n⊙×-diag = (λ x → x , x) , idp\n\nsmin-map : ∀ {j k} {Y : Ptd j} {Z : Ptd k}\n → X ⊙→ Y\n → X ⊙→ Z\n → X ⊙→ Y ⊙× Z\nsmin-map f g = ⊙×-fmap f g ⊙∘ ⊙×-diag\n\nsmin-map-⊙×-swap : ∀ {j k} (Y : Ptd j) (Z : Ptd k)\n (f : X ⊙→ Y)\n (g : X ⊙→ Z)\n → ⊙×-swap ⊙∘ smin-map g f == smin-map f g\nsmin-map-⊙×-swap Y Z (_ , idp) (_ , idp) = idp\n\nmodule _ (G : AbGroup i) (H : AbGroup i) where\n\n private\n module G⊗H = TensorProduct G H\n module H⊗G = TensorProduct H G\n open EMExplicit\n\n ⊙Ω×-cp-seq : ∀ (m n : ℕ) → (⊙Ω (⊙EM G (S m)) ⊙× ⊙Ω (⊙EM H (S n))) ⊙–→ ⊙Ω (⊙EM G⊗H.abgroup (S (m + n)))\n ⊙Ω×-cp-seq m n =\n ⊙<– (spectrum G⊗H.abgroup (m + n)) ◃⊙∘\n ⊙×-cp G H m n ◃⊙∘\n ⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf\n\n ⊙Ω×-cp : ∀ (m n : ℕ) → ⊙Ω (⊙EM G (S m)) ⊙× ⊙Ω (⊙EM H (S n)) ⊙→ ⊙Ω (⊙EM G⊗H.abgroup (S (m + n)))\n ⊙Ω×-cp m n = ⊙compose (⊙Ω×-cp-seq m n)\n\n _∪_ : ∀ {m n : ℕ} → CEl G (pos m) X → CEl H (pos n) X → CEl G⊗H.abgroup (pos (m + n)) X\n _∪_ {m} {n} = Trunc-fmap2 {n = 0} (λ s' t' → ⊙Ω×-cp m n ⊙∘ smin-map s' t')\n\nmodule _ (G : AbGroup i) (H : AbGroup i) where\n\n private\n module G⊗H = TensorProduct G H\n module H⊗G = TensorProduct H G\n open EMExplicit\n\n abstract\n ⊙Ω×-cp-comm : ∀ (m n : ℕ)\n → ⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘\n ⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ◃⊙∘\n ⊙Ω×-cp G H m n ◃⊙idf\n =⊙∘\n ⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘\n ⊙Ω×-cp H G n m ◃⊙∘\n ⊙×-swap ◃⊙idf\n ⊙Ω×-cp-comm m n =\n ⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘\n ⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ◃⊙∘\n ⊙Ω×-cp G H m n ◃⊙idf\n =⊙∘⟨ 2 & 1 & ⊙expand (⊙Ω×-cp-seq G H m n) ⟩\n ⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘\n ⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ◃⊙∘\n ⊙<– (spectrum G⊗H.abgroup (m + n)) ◃⊙∘\n ⊙×-cp G H m n ◃⊙∘\n ⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf\n =⊙∘⟨ 1 & 2 & !⊙∘ $ ⊙<–-spectrum-natural G⊗H.abgroup H⊗G.abgroup G⊗H.swap (m + n) ⟩\n ⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘\n ⊙<– (spectrum H⊗G.abgroup (m + n)) ◃⊙∘\n ⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (m + n) ◃⊙∘\n ⊙×-cp G H m n ◃⊙∘\n ⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf\n =⊙∘⟨ 0 & 2 & !⊙∘ $ ⊙transport-natural-=⊙∘\n (+-comm m n)\n (λ k → ⊙<– (spectrum H⊗G.abgroup k)) ⟩\n ⊙<– (spectrum H⊗G.abgroup (n + m)) ◃⊙∘\n ⊙transport (λ k → ⊙EM H⊗G.abgroup k) (+-comm m n) ◃⊙∘\n ⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (m + n) ◃⊙∘\n ⊙×-cp G H m n ◃⊙∘\n ⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf\n =⊙∘⟨ 1 & 3 & ⊙×-cp-comm G H m n ⟩\n ⊙<– (spectrum H⊗G.abgroup (n + m)) ◃⊙∘\n ⊙cond-neg H⊗G.abgroup (n + m) (and (odd m) (odd n)) ◃⊙∘\n ⊙×-cp H G n m ◃⊙∘\n ⊙×-swap ◃⊙∘\n ⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf\n =⊙∘⟨ 0 & 2 & ⊙transport-natural-=⊙∘\n (Bool-elim (inv-path H⊗G.abgroup) idp (and (odd m) (odd n)))\n (λ A → ⊙<– (spectrum A (n + m))) ⟩\n ⊙transport (λ A → ⊙Ω (⊙EM A (S (n + m)))) neg ◃⊙∘\n ⊙<– (spectrum H⊗G.abgroup (n + m)) ◃⊙∘\n ⊙×-cp H G n m ◃⊙∘\n ⊙×-swap ◃⊙∘\n ⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf\n =⊙∘₁⟨ 0 & 1 &\n ⊙transport-⊙coe (λ A → ⊙Ω (⊙EM A (S (n + m)))) neg ∙\n ap ⊙coe (ap-∘ ⊙Ω (λ A → ⊙EM A (S (n + m))) neg) ∙\n ! (⊙transport-⊙coe ⊙Ω (ap (λ A → ⊙EM A (S (n + m))) neg)) ∙\n ⊙transport-⊙Ω (ap (λ A → ⊙EM A (S (n + m))) neg) ∙\n ap ⊙Ω-fmap (! (⊙transport-⊙coe (λ A → ⊙EM A (S (n + m))) neg)) ⟩\n ⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘\n ⊙<– (spectrum H⊗G.abgroup (n + m)) ◃⊙∘\n ⊙×-cp H G n m ◃⊙∘\n ⊙×-swap ◃⊙∘\n ⊙×-fmap (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ◃⊙idf\n =⊙∘⟨ 3 & 2 & =⊙∘-in {gs = ⊙×-fmap (⊙–> (spectrum H n)) (⊙–> (spectrum G m)) ◃⊙∘\n ⊙×-swap ◃⊙idf} $\n ! $ ⊙λ= $ ⊙×-swap-natural (⊙–> (spectrum G m)) (⊙–> (spectrum H n)) ⟩\n ⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘\n ⊙<– (spectrum H⊗G.abgroup (n + m)) ◃⊙∘\n ⊙×-cp H G n m ◃⊙∘\n ⊙×-fmap (⊙–> (spectrum H n)) (⊙–> (spectrum G m)) ◃⊙∘\n ⊙×-swap ◃⊙idf\n =⊙∘⟨ 1 & 3 & ⊙contract ⟩\n ⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘\n ⊙Ω×-cp H G n m ◃⊙∘\n ⊙×-swap ◃⊙idf ∎⊙∘\n where\n neg : H⊗G.abgroup == H⊗G.abgroup\n neg = Bool-elim (inv-path H⊗G.abgroup) idp (and (odd m) (odd n))\n\n ∪-swap : ∀ (m n : ℕ)\n → CEl G⊗H.abgroup (pos (m + n)) X → CEl H⊗G.abgroup (pos (n + m)) X\n ∪-swap m n =\n transport (λ k → CEl H⊗G.abgroup (pos k) X) (+-comm m n) ∘\n EM-CEl-coeff-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (pos (m + n)) X\n\n maybe-inv : ∀ (n : ℤ) → Bool → CEl H⊗G.abgroup n X → CEl H⊗G.abgroup n X\n maybe-inv n = Bool-rec (Group.inv (C H⊗G.abgroup n X)) (idf _)\n\n private\n _G∪H_ = _∪_ G H\n _H∪G_ = _∪_ H G\n\n ∪-comm : ∀ {m n : ℕ}\n (s : CEl G (pos m) X)\n (t : CEl H (pos n) X)\n → ∪-swap m n (s G∪H t) ==\n maybe-inv (pos (n + m)) (and (odd m) (odd n)) (t H∪G s)\n ∪-comm {m} {n} =\n Trunc-elim {{λ s → Π-level (λ t → =-preserves-level Trunc-level)}} $ λ s' →\n Trunc-elim {{λ t → =-preserves-level Trunc-level}} $ λ t' →\n transport (λ k → CEl H⊗G.abgroup (pos k) X) (+-comm m n)\n [ ⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ⊙∘\n ⊙Ω×-cp G H m n ⊙∘\n smin-map s' t' ]\n =⟨ app= step₁\n [ ⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ⊙∘\n ⊙Ω×-cp G H m n ⊙∘\n smin-map s' t' ] ⟩\n [ ⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ⊙∘\n ⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ⊙∘\n ⊙Ω×-cp G H m n ⊙∘\n smin-map s' t' ]\n =⟨ ap [_] (=⊙∘-out (step₂ s' t')) ⟩\n Trunc-fmap (⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ⊙∘_)\n [ ⊙Ω×-cp H G n m ⊙∘ smin-map t' s' ]\n =⟨ app= (step₃ (n + m) (and (odd m) (odd n))) [ ⊙Ω×-cp H G n m ⊙∘ smin-map t' s' ] ⟩\n maybe-inv (pos (n + m)) (and (odd m) (odd n))\n [ ⊙Ω×-cp H G n m ⊙∘ smin-map t' s' ] =∎\n where\n step₁ : transport (λ k → CEl H⊗G.abgroup (pos k) X) (+-comm m n) ==\n Trunc-fmap (⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ⊙∘_)\n step₁ =\n transport (λ k → CEl H⊗G.abgroup (pos k) X) (+-comm m n)\n =⟨ ap coe (ap-∘ (Trunc 0) (λ k → X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)) ⟩\n transport (Trunc 0) (ap (λ k → X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n))\n =⟨ transport-Trunc (ap (λ k → X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)) ⟩\n Trunc-fmap (transport (λ k → X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n))\n =⟨ ap (Trunc-fmap ∘ coe) (ap-∘ (X ⊙→_) (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)) ⟩\n Trunc-fmap (transport (X ⊙→_) (ap (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)))\n =⟨ ap Trunc-fmap $ λ= $ transport-post⊙∘ X (ap (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)) ⟩\n Trunc-fmap (⊙coe (ap (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n)) ⊙∘_)\n =⟨ ap (λ g → Trunc-fmap (g ⊙∘_)) $\n ! $ ⊙transport-⊙coe (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ⟩\n Trunc-fmap (⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ⊙∘_) =∎\n step₂ : ∀ (s' : X ⊙→ ⊙Ω (⊙EM G (S m))) (t' : X ⊙→ ⊙Ω (⊙EM H (S n)))\n → ⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘\n ⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ◃⊙∘\n ⊙Ω×-cp G H m n ◃⊙∘\n smin-map s' t' ◃⊙idf\n =⊙∘\n ⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘\n ⊙Ω×-cp H G n m ◃⊙∘\n smin-map t' s' ◃⊙idf\n step₂ s' t' =\n ⊙transport (λ k → ⊙Ω (⊙EM H⊗G.abgroup (S k))) (+-comm m n) ◃⊙∘\n ⊙Ω-fmap (⊙EM-fmap G⊗H.abgroup H⊗G.abgroup G⊗H.swap (S (m + n))) ◃⊙∘\n ⊙Ω×-cp G H m n ◃⊙∘\n smin-map s' t' ◃⊙idf\n =⊙∘⟨ 0 & 3 & ⊙Ω×-cp-comm m n ⟩\n ⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘\n ⊙Ω×-cp H G n m ◃⊙∘\n ⊙×-swap ◃⊙∘\n smin-map s' t' ◃⊙idf\n =⊙∘⟨ 2 & 2 & =⊙∘-in {gs = smin-map t' s' ◃⊙idf} $\n smin-map-⊙×-swap (⊙Ω (⊙EM H (S n))) (⊙Ω (⊙EM G (S m))) t' s' ⟩\n ⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S (n + m)) (and (odd m) (odd n))) ◃⊙∘\n ⊙Ω×-cp H G n m ◃⊙∘\n smin-map t' s' ◃⊙idf ∎⊙∘\n step₃ : ∀ (k : ℕ) (b : Bool) →\n Trunc-fmap (⊙Ω-fmap (⊙cond-neg H⊗G.abgroup (S k) b) ⊙∘_) ==\n maybe-inv (pos k) b\n step₃ k false =\n Trunc-fmap (⊙Ω-fmap (⊙idf (⊙EM H⊗G.abgroup (S k))) ⊙∘_)\n =⟨ ap (λ g → Trunc-fmap (g ⊙∘_)) ⊙Ω-fmap-idf ⟩\n Trunc-fmap (⊙idf (⊙Ω (⊙EM H⊗G.abgroup (S k))) ⊙∘_)\n =⟨ ap Trunc-fmap (λ= (⊙λ= ∘ ⊙∘-unit-l)) ⟩\n Trunc-fmap (idf (X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k))))\n =⟨ λ= Trunc-fmap-idf ⟩\n idf (Trunc 0 (X ⊙→ ⊙Ω (⊙EM H⊗G.abgroup (S k)))) =∎\n step₃ k true =\n Trunc-fmap (⊙Ω-fmap (⊙transport (λ A → ⊙EM A (S k)) (inv-path H⊗G.abgroup)) ⊙∘_)\n =⟨ ap (λ f → Trunc-fmap (⊙Ω-fmap f ⊙∘_)) $\n ⊙transport-⊙EM-uaᴬᴳ H⊗G.abgroup H⊗G.abgroup (inv-iso H⊗G.abgroup) (S k) ⟩\n Trunc-fmap (⊙Ω-fmap (⊙EM-fmap H⊗G.abgroup H⊗G.abgroup (inv-hom H⊗G.abgroup) (S k)) ⊙∘_)\n =⟨ ap GroupHom.f (EM-C-coeff-fmap-inv-hom H⊗G.abgroup (pos k) X) ⟩\n Group.inv (C H⊗G.abgroup (pos k) X) =∎\n", "meta": {"hexsha": "e942301491e02ec5ba8f7e1f2ee00875873c1636", "size": 10221, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "theorems/cohomology/CupProduct/Definition.agda", "max_stars_repo_name": "AntoineAllioux/HoTT-Agda", "max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "theorems/cohomology/CupProduct/Definition.agda", "max_issues_repo_name": "AntoineAllioux/HoTT-Agda", "max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "theorems/cohomology/CupProduct/Definition.agda", "max_forks_repo_name": "AntoineAllioux/HoTT-Agda", "max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 44.0560344828, "max_line_length": 105, "alphanum_fraction": 0.457685158, "num_tokens": 5718, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.749087201911703, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.3511650587818868}} {"text": "module DoBlock3 where\n\ndata Id\n (A : Set)\n : Set\n where\n\n id\n : A\n → Id A\n\n_>>=_\n : {A B : Set}\n → Id A\n → (A → Id B)\n → Id B\nid x >>= f\n = f x\n\n_>>_\n : {A B : Set}\n → Id A\n → Id B\n → Id B\n_ >> y\n = y\n\nf\n : {A : Set}\n → A\n → Id A\nf x\n = do\n id x\n id x\n\n", "meta": {"hexsha": "1eabd3083954600d45ec71f31144b52d6ee2f662", "size": 283, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "data/expression/DoBlock3.agda", "max_stars_repo_name": "msuperdock/agda-unused", "max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z", "max_issues_repo_path": "data/expression/DoBlock3.agda", "max_issues_repo_name": "msuperdock/agda-unused", "max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "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": "data/expression/DoBlock3.agda", "max_forks_repo_name": "msuperdock/agda-unused", "max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z", "avg_line_length": 7.6486486486, "max_line_length": 21, "alphanum_fraction": 0.3674911661, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548646660543, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.35106934276830054}} {"text": "{-# OPTIONS --cubical --no-import-sorts --safe #-}\nmodule Cubical.ZCohomology.Properties where\n\nopen import Cubical.ZCohomology.Base\nopen import Cubical.HITs.S1\nopen import Cubical.HITs.Sn\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Pointed\nopen import Cubical.Foundations.Transport\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.GroupoidLaws\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Data.Empty\nopen import Cubical.Data.Sigma hiding (_×_)\nopen import Cubical.HITs.Susp\nopen import Cubical.HITs.Wedge\nopen import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2 ; setTruncIsSet to §)\nopen import Cubical.HITs.Nullification\nopen import Cubical.Data.Int renaming (_+_ to _ℤ+_)\nopen import Cubical.Data.Nat\nopen import Cubical.HITs.Truncation renaming (elim to trElim ; map to trMap ; rec to trRec ; elim3 to trElim3)\nopen import Cubical.Homotopy.Loopspace\nopen import Cubical.Homotopy.Connected\nopen import Cubical.Homotopy.Freudenthal\nopen import Cubical.HITs.SmashProduct.Base\nopen import Cubical.Algebra.Group\nopen import Cubical.Algebra.Semigroup\nopen import Cubical.Algebra.Monoid\nopen import Cubical.Foundations.Equiv.HalfAdjoint\n\n\nopen import Cubical.HITs.Pushout\nopen import Cubical.Data.Sum.Base\nopen import Cubical.Data.HomotopyGroup\n\nopen import Cubical.ZCohomology.KcompPrelims\n\nprivate\n variable\n ℓ ℓ' : Level\n A : Type ℓ\n B : Type ℓ'\n A' : Pointed ℓ\n\n\n{- Equivalence between cohomology of A and reduced cohomology of (A + 1) -}\ncoHomRed+1Equiv : (n : ℕ) →\n (A : Type ℓ) →\n (coHom n A) ≡ (coHomRed n ((A ⊎ Unit , inr (tt))))\ncoHomRed+1Equiv zero A i = ∥ helpLemma {C = (Int , pos 0)} i ∥₂\n module coHomRed+1 where\n helpLemma : {C : Pointed ℓ} → ( (A → (typ C)) ≡ ((((A ⊎ Unit) , inr (tt)) →∙ C)))\n helpLemma {C = C} = isoToPath (iso map1\n map2\n (λ b → linvPf b)\n (λ _ → refl))\n where\n map1 : (A → typ C) → ((((A ⊎ Unit) , inr (tt)) →∙ C))\n map1 f = map1' , refl\n module helpmap where\n map1' : A ⊎ Unit → fst C\n map1' (inl x) = f x\n map1' (inr x) = pt C\n\n map2 : ((((A ⊎ Unit) , inr (tt)) →∙ C)) → (A → typ C)\n map2 (g , pf) x = g (inl x)\n\n linvPf : (b :((((A ⊎ Unit) , inr (tt)) →∙ C))) → map1 (map2 b) ≡ b\n linvPf (f , snd) i = (λ x → helper x i) , λ j → snd ((~ i) ∨ j)\n where\n helper : (x : A ⊎ Unit) → ((helpmap.map1') (map2 (f , snd)) x) ≡ f x\n helper (inl x) = refl\n helper (inr tt) = sym snd\n\ncoHomRed+1Equiv (suc n) A i = ∥ coHomRed+1.helpLemma A i {C = ((coHomK (suc n)) , ∣ north ∣)} i ∥₂\n\n-----------\n\nKn→ΩKn+1 : (n : ℕ) → coHomK n → typ (Ω (coHomK-ptd (suc n)))\nKn→ΩKn+1 n = Iso.fun (Iso3-Kn-ΩKn+1 n)\n\nΩKn+1→Kn : {n : ℕ} → typ (Ω (coHomK-ptd (suc n))) → coHomK n\nΩKn+1→Kn {n = n} = Iso.inv (Iso3-Kn-ΩKn+1 n)\n\nKn≃ΩKn+1 : {n : ℕ} → coHomK n ≃ typ (Ω (coHomK-ptd (suc n)))\nKn≃ΩKn+1 {n = n} = isoToEquiv (Iso-Kn-ΩKn+1 n)\n\n---------- Algebra/Group stuff --------\n\n0ₖ : {n : ℕ} → coHomK n\n0ₖ {n = zero} = pt (coHomK-ptd 0)\n0ₖ {n = suc n} = pt (coHomK-ptd (suc n))\n\ninfixr 35 _+ₖ_\n\n_+ₖ_ : {n : ℕ} → coHomK n → coHomK n → coHomK n\n_+ₖ_ {n = n} x y = ΩKn+1→Kn (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y)\n\n-ₖ_ : {n : ℕ} → coHomK n → coHomK n\n-ₖ_ {n = n} x = ΩKn+1→Kn (sym (Kn→ΩKn+1 n x))\n\nKn→ΩKn+10ₖ : (n : ℕ) → Kn→ΩKn+1 n 0ₖ ≡ refl\nKn→ΩKn+10ₖ zero = refl\nKn→ΩKn+10ₖ (suc n) = (λ i → cong ∣_∣ (rCancel (merid north) i)) -- could also use refl for n = 1, but for computational reasons I don't want to expand the definition if not necessary.\n\n-0ₖ : {n : ℕ} → -ₖ 0ₖ {n = n} ≡ 0ₖ\n-0ₖ {n = n} = (λ i → ΩKn+1→Kn (sym (Kn→ΩKn+10ₖ n i)))\n ∙∙ (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ n (~ i)))\n ∙∙ Iso.leftInv (Iso3-Kn-ΩKn+1 n) 0ₖ\n\n+ₖ→∙ : (n : ℕ) (a b : coHomK n) → Kn→ΩKn+1 n (a +ₖ b) ≡ Kn→ΩKn+1 n a ∙ Kn→ΩKn+1 n b\n+ₖ→∙ n a b = Iso.rightInv (Iso3-Kn-ΩKn+1 n) (Kn→ΩKn+1 n a ∙ Kn→ΩKn+1 n b)\n\nlUnitₖ : {n : ℕ} (x : coHomK n) → 0ₖ +ₖ x ≡ x\nlUnitₖ {n = zero} x = cong ΩKn+1→Kn (sym (lUnit (Kn→ΩKn+1 zero x))) ∙\n Iso.leftInv (Iso3-Kn-ΩKn+1 zero) x\nlUnitₖ {n = suc n} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc n) i ∙ Kn→ΩKn+1 (suc n) x)) ∙\n (cong ΩKn+1→Kn (sym (lUnit (Kn→ΩKn+1 (suc n) x)))) ∙\n Iso.leftInv (Iso3-Kn-ΩKn+1 (suc n)) x\n\nrUnitₖ : {n : ℕ} (x : coHomK n) → x +ₖ 0ₖ ≡ x\nrUnitₖ {n = zero} x = cong ΩKn+1→Kn (sym (rUnit (Kn→ΩKn+1 zero x))) ∙\n Iso.leftInv (Iso3-Kn-ΩKn+1 zero) x\nrUnitₖ {n = suc n} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) x ∙ Kn→ΩKn+10ₖ (suc n) i)) ∙\n (cong ΩKn+1→Kn (sym (rUnit (Kn→ΩKn+1 (suc n) x)))) ∙\n Iso.leftInv (Iso3-Kn-ΩKn+1 (suc n)) x\n--\n\n\n\n\nrCancelₖ : {n : ℕ} (x : coHomK n) → x +ₖ (-ₖ x) ≡ 0ₖ\nrCancelₖ {n = zero} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 zero x ∙ Iso.rightInv (Iso3-Kn-ΩKn+1 zero) (sym (Kn→ΩKn+1 zero x)) i)) ∙\n cong ΩKn+1→Kn (rCancel (Kn→ΩKn+1 zero x))\nrCancelₖ {n = suc n} x = (λ i → ΩKn+1→Kn (Kn→ΩKn+1 (1 + n) x ∙ Iso.rightInv (Iso3-Kn-ΩKn+1 (1 + n)) (sym (Kn→ΩKn+1 (1 + n) x)) i)) ∙\n cong ΩKn+1→Kn (rCancel (Kn→ΩKn+1 (1 + n) x)) ∙\n (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc n) (~ i))) ∙\n Iso.leftInv (Iso3-Kn-ΩKn+1 (suc n)) 0ₖ\n\nlCancelₖ : {n : ℕ} (x : coHomK n) → (-ₖ x) +ₖ x ≡ 0ₖ\nlCancelₖ {n = zero} x = (λ i → ΩKn+1→Kn (Iso.rightInv (Iso3-Kn-ΩKn+1 zero) (sym (Kn→ΩKn+1 zero x)) i ∙ Kn→ΩKn+1 zero x)) ∙\n cong ΩKn+1→Kn (lCancel (Kn→ΩKn+1 zero x))\nlCancelₖ {n = suc n} x = (λ i → ΩKn+1→Kn (Iso.rightInv (Iso3-Kn-ΩKn+1 (1 + n)) (sym (Kn→ΩKn+1 (1 + n) x)) i ∙ Kn→ΩKn+1 (1 + n) x)) ∙\n cong ΩKn+1→Kn (lCancel (Kn→ΩKn+1 (1 + n) x)) ∙\n (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc n) (~ i))) ∙\n Iso.leftInv (Iso3-Kn-ΩKn+1 (suc n)) 0ₖ\n\n\nassocₖ : {n : ℕ} (x y z : coHomK n) → ((x +ₖ y) +ₖ z) ≡ (x +ₖ (y +ₖ z))\nassocₖ {n = n} x y z = ((λ i → ΩKn+1→Kn (Kn→ΩKn+1 n (ΩKn+1→Kn (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y)) ∙ Kn→ΩKn+1 n z)) ∙∙\n (λ i → ΩKn+1→Kn (Iso.rightInv (Iso3-Kn-ΩKn+1 n) (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y) i ∙ Kn→ΩKn+1 n z)) ∙∙\n (λ i → ΩKn+1→Kn (assoc (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) (Kn→ΩKn+1 n z) (~ i)))) ∙\n (λ i → ΩKn+1→Kn ((Kn→ΩKn+1 n x) ∙ Iso.rightInv (Iso3-Kn-ΩKn+1 n) ((Kn→ΩKn+1 n y ∙ Kn→ΩKn+1 n z)) (~ i)))\n\ncommₖ : {n : ℕ} (x y : coHomK n) → (x +ₖ y) ≡ (y +ₖ x)\ncommₖ {n = n} x y i = ΩKn+1→Kn (EH-instance (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) i)\n where\n EH-instance : (p q : typ (Ω ((∥ S₊ (suc n) ∥ (2 + (suc n))) , ∣ north ∣))) → p ∙ q ≡ q ∙ p\n EH-instance = transport (λ i → (p q : K-Id n (~ i)) → p ∙ q ≡ q ∙ p)\n λ p q → Eckmann-Hilton 0 p q\n where\n K-Id : (n : HLevel) → typ (Ω (hLevelTrunc (3 + n) (S₊ (1 + n)) , ∣ north ∣)) ≡ typ ((Ω^ 2) (hLevelTrunc (4 + n) (S₊ (2 + n)) , ∣ north ∣ ))\n K-Id n = (λ i → typ (Ω (isoToPath (Iso2-Kn-ΩKn+1 (suc n)) i , hcomp (λ k → λ { (i = i0) → ∣ north ∣\n ; (i = i1) → transportRefl (λ j → ∣ rCancel (merid north) k j ∣) k})\n (transp (λ j → isoToPath (Iso2-Kn-ΩKn+1 (suc n)) (i ∧ j)) (~ i) ∣ north ∣))))\n\nrUnitₖ' : {n : ℕ} (x : coHomK n) → x +ₖ 0ₖ ≡ x\nrUnitₖ' {n = n} x = commₖ x 0ₖ ∙ lUnitₖ x\n\n-distrₖ : {n : ℕ} → (x y : coHomK n) → -ₖ (x +ₖ y) ≡ (-ₖ x) +ₖ (-ₖ y)\n-distrₖ {n = n} x y = ((λ i → ΩKn+1→Kn (sym (Kn→ΩKn+1 n (ΩKn+1→Kn (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y))))) ∙∙\n (λ i → ΩKn+1→Kn (sym (Iso.rightInv (Iso3-Kn-ΩKn+1 n) (Kn→ΩKn+1 n x ∙ Kn→ΩKn+1 n y) i))) ∙∙\n (λ i → ΩKn+1→Kn (symDistr (Kn→ΩKn+1 n x) (Kn→ΩKn+1 n y) i))) ∙∙\n (λ i → ΩKn+1→Kn (Iso.rightInv (Iso3-Kn-ΩKn+1 n) (sym (Kn→ΩKn+1 n y)) (~ i) ∙ (Iso.rightInv (Iso3-Kn-ΩKn+1 n) (sym (Kn→ΩKn+1 n x)) (~ i)))) ∙∙\n commₖ (-ₖ y) (-ₖ x)\n\n\n---- Group structure of cohomology groups ---\n\n_+ₕ_ : {n : ℕ} → coHom n A → coHom n A → coHom n A\n_+ₕ_ = sElim2 (λ _ _ → §) λ a b → ∣ (λ x → a x +ₖ b x) ∣₂\n\n-ₕ : {n : ℕ} → coHom n A → coHom n A\n-ₕ = sRec § λ a → ∣ (λ x → -ₖ a x) ∣₂\n\n0ₕ : {n : ℕ} → coHom n A\n0ₕ = ∣ (λ _ → 0ₖ) ∣₂\n\nrUnitₕ : {n : ℕ} (x : coHom n A) → x +ₕ 0ₕ ≡ x\nrUnitₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))\n λ a i → ∣ funExt (λ x → rUnitₖ (a x)) i ∣₂\n\nlUnitₕ : {n : ℕ} (x : coHom n A) → 0ₕ +ₕ x ≡ x\nlUnitₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))\n λ a i → ∣ funExt (λ x → lUnitₖ (a x)) i ∣₂\n\nrCancelₕ : {n : ℕ} (x : coHom n A) → x +ₕ (-ₕ x) ≡ 0ₕ\nrCancelₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))\n λ a i → ∣ funExt (λ x → rCancelₖ (a x)) i ∣₂\n\nlCancelₕ : {n : ℕ} (x : coHom n A) → (-ₕ x) +ₕ x ≡ 0ₕ\nlCancelₕ = sElim (λ _ → isOfHLevelPath 1 (§ _ _))\n λ a i → ∣ funExt (λ x → lCancelₖ (a x)) i ∣₂\n\nassocₕ : {n : ℕ} (x y z : coHom n A) → ((x +ₕ y) +ₕ z) ≡ (x +ₕ (y +ₕ z))\nassocₕ = elim3 (λ _ _ _ → isOfHLevelPath 1 (§ _ _))\n λ a b c i → ∣ funExt (λ x → assocₖ (a x) (b x) (c x)) i ∣₂\n\ncommₕ : {n : ℕ} (x y : coHom n A) → (x +ₕ y) ≡ (y +ₕ x)\ncommₕ {n = n} = sElim2 (λ _ _ → isOfHLevelPath 1 (§ _ _))\n λ a b i → ∣ funExt (λ x → commₖ (a x) (b x)) i ∣₂\n\n\n-- Proof that rUnitₖ and lUnitₖ agree on 0ₖ. Needed for Mayer-Vietoris.\nrUnitlUnit0 : {n : ℕ} → rUnitₖ {n = n} 0ₖ ≡ lUnitₖ 0ₖ\nrUnitlUnit0 {n = zero} = refl\nrUnitlUnit0 {n = suc n} =\n (assoc (λ i → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) 0ₖ ∙ Kn→ΩKn+10ₖ (suc n) i))\n (cong ΩKn+1→Kn (sym (rUnit (Kn→ΩKn+1 (suc n) 0ₖ))))\n (Iso.leftInv (Iso3-Kn-ΩKn+1 (suc n)) 0ₖ))\n ∙∙ (λ j → helper j\n ∙ Iso.leftInv (Iso3-Kn-ΩKn+1 (suc n)) 0ₖ)\n ∙∙ sym (assoc (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc n) i ∙ Kn→ΩKn+1 (suc n) 0ₖ))\n (cong ΩKn+1→Kn (sym (lUnit (Kn→ΩKn+1 (suc n) 0ₖ))))\n (Iso.leftInv (Iso3-Kn-ΩKn+1 (suc n)) 0ₖ))\n\n where\n helper : (λ i → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) 0ₖ ∙ Kn→ΩKn+10ₖ (suc n) i))\n ∙ (cong ΩKn+1→Kn (sym (rUnit (Kn→ΩKn+1 (suc n) 0ₖ))))\n ≡ (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc n) i ∙ Kn→ΩKn+1 (suc n) 0ₖ))\n ∙ (cong ΩKn+1→Kn (sym (lUnit (Kn→ΩKn+1 (suc n) 0ₖ))))\n helper = ((λ j → lUnit (rUnit ((λ i → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) 0ₖ ∙ Kn→ΩKn+10ₖ (suc n) i))) j) j\n ∙ rUnit (cong ΩKn+1→Kn (sym (rUnit (Kn→ΩKn+1 (suc n) 0ₖ)))) j)\n ∙∙ (λ j → ((λ z → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) ∣ north ∣ ∙ (λ i → ∣ rCancel (merid north) (z ∧ j) i ∣)))\n ∙ (λ i → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) 0ₖ ∙ Kn→ΩKn+10ₖ (suc n) (i ∨ j)))\n ∙ λ z → ΩKn+1→Kn (((λ i → ∣ rCancel (merid north) (z ∧ j) i ∣)) ∙ refl))\n ∙ cong ΩKn+1→Kn (sym (rUnit (Kn→ΩKn+10ₖ (suc n) j)))\n ∙ λ z → ΩKn+1→Kn (λ i → ∣ rCancel (merid north) ((~ z) ∧ j) i ∣))\n ∙∙ (λ j → (((λ z → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) ∣ north ∣ ∙ (λ i → ∣ rCancel (merid north) z i ∣))))\n ∙ (λ i → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) 0ₖ ∙ refl))\n ∙ λ z → ΩKn+1→Kn ((λ i → ∣ rCancel (merid north) z i ∣) ∙ λ i → ∣ rCancel (merid north) ((~ z) ∨ (~ j)) i ∣))\n ∙ cong ΩKn+1→Kn (sym (lUnit (Kn→ΩKn+10ₖ (suc n) (~ j))))\n ∙ λ z → ΩKn+1→Kn (λ i → ∣ rCancel (merid north) (~ z ∧ (~ j)) i ∣)))\n ∙∙ (λ j → ((λ z → ΩKn+1→Kn (Kn→ΩKn+1 (suc n) ∣ north ∣ ∙ λ i → ∣ rCancel (merid north) (z ∧ (~ j)) i ∣))\n ∙ (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc n) (i ∧ j) ∙ Kn→ΩKn+10ₖ (suc n) (~ j)))\n ∙ λ z → ΩKn+1→Kn ((λ i → ∣ rCancel (merid north) (z ∨ j) i ∣) ∙ λ i → ∣ rCancel (merid north) (~ z ∧ ~ j) i ∣))\n ∙ rUnit (cong ΩKn+1→Kn (sym (lUnit (Kn→ΩKn+1 (suc n) 0ₖ)))) (~ j))\n ∙∙ (λ j → lUnit (rUnit (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc n) i ∙ Kn→ΩKn+1 (suc n) 0ₖ)) (~ j)) (~ j)\n ∙ cong ΩKn+1→Kn (sym (lUnit (Kn→ΩKn+1 (suc n) 0ₖ))))\n\n\n\n---- Group structure of reduced cohomology groups (in progress - might need K to compute properly first) ---\n\n+ₕ∙ : {A : Pointed ℓ} (n : ℕ) → coHomRed n A → coHomRed n A → coHomRed n A\n+ₕ∙ zero = sElim2 (λ _ _ → §) λ { (a , pa) (b , pb) → ∣ (λ x → a x +ₖ b x) , (λ i → (pa i +ₖ pb i)) ∣₂ }\n+ₕ∙ (suc n) = sElim2 (λ _ _ → §) λ { (a , pa) (b , pb) → ∣ (λ x → a x +ₖ b x) , (λ i → pa i +ₖ pb i) ∙ lUnitₖ 0ₖ ∣₂ }\n\n\n-ₕ∙ : {A : Pointed ℓ} (n : ℕ) → coHomRed n A → coHomRed n A\n-ₕ∙ zero = sRec § λ {(a , pt) → ∣ (λ x → -ₖ a x ) , (λ i → -ₖ (pt i)) ∣₂}\n-ₕ∙ (suc n) = sRec § λ {(a , pt) → ∣ (λ x → -ₖ a x ) , (λ i → -ₖ (pt i)) ∙\n (λ i → ΩKn+1→Kn (sym (Kn→ΩKn+10ₖ (suc n) i))) ∙\n (λ i → ΩKn+1→Kn (Kn→ΩKn+10ₖ (suc n) (~ i))) ∙\n Iso.leftInv (Iso3-Kn-ΩKn+1 (suc n)) ∣ north ∣ ∣₂}\n\n0ₕ∙ : {A : Pointed ℓ} (n : ℕ) → coHomRed n A\n0ₕ∙ zero = ∣ (λ _ → 0ₖ) , refl ∣₂\n0ₕ∙ (suc n) = ∣ (λ _ → 0ₖ) , refl ∣₂\n\nopen IsSemigroup\nopen IsMonoid\nopen Group\ncoHomGr : ∀ {ℓ} (n : ℕ) (A : Type ℓ) → Group\nCarrier (coHomGr n A) = coHom n A\n0g (coHomGr n A) = 0ₕ\nGroup._+_ (coHomGr n A) = _+ₕ_\nGroup.- coHomGr n A = -ₕ\nis-set (isSemigroup (IsGroup.isMonoid (Group.isGroup (coHomGr n A)))) = §\nIsSemigroup.assoc (isSemigroup (IsGroup.isMonoid (Group.isGroup (coHomGr n A)))) x y z = sym (assocₕ x y z)\nidentity (IsGroup.isMonoid (Group.isGroup (coHomGr n A))) x = (rUnitₕ x) , (lUnitₕ x)\nIsGroup.inverse (Group.isGroup (coHomGr n A)) x = (rCancelₕ x) , (lCancelₕ x)\n\n×coHomGr : (n : ℕ) (A : Type ℓ) (B : Type ℓ') → Group\n×coHomGr n A B = dirProd (coHomGr n A) (coHomGr n B)\n\ncoHomFun : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (n : ℕ) (f : A → B) → coHom n B → coHom n A\ncoHomFun n f = sRec § λ β → ∣ β ∘ f ∣₂\n\n--- ΩKₙ is commutative\nisCommΩK : (n : ℕ) → (p q : typ (Ω (coHomK n , coHom-pt n))) → p ∙ q ≡ q ∙ p\nisCommΩK zero p q = isSetInt _ _ (p ∙ q) (q ∙ p)\nisCommΩK (suc n) p q =\n cong₂ _∙_ (sym (Iso.rightInv (Iso3-Kn-ΩKn+1 n) p))\n (sym (Iso.rightInv (Iso3-Kn-ΩKn+1 n) q))\n ∙∙ (sym (Iso.rightInv (Iso3-Kn-ΩKn+1 n) (Kn→ΩKn+1 n (ΩKn+1→Kn p) ∙ Kn→ΩKn+1 n (ΩKn+1→Kn q)))\n ∙∙ cong (Kn→ΩKn+1 n) (commₖ (ΩKn+1→Kn p) (ΩKn+1→Kn q))\n ∙∙ Iso.rightInv (Iso3-Kn-ΩKn+1 n) (Kn→ΩKn+1 n (ΩKn+1→Kn q) ∙ Kn→ΩKn+1 n (ΩKn+1→Kn p)))\n ∙∙ sym (cong₂ _∙_ (sym (Iso.rightInv (Iso3-Kn-ΩKn+1 n) q))\n (sym (Iso.rightInv (Iso3-Kn-ΩKn+1 n) p)))\n\n--- the loopspace of Kₙ is commutative regardless of base\nisCommΩK-based : (n : ℕ) (x : coHomK n) (p q : x ≡ x) → p ∙ q ≡ q ∙ p\nisCommΩK-based zero x p q = isSetInt _ _ (p ∙ q) (q ∙ p)\nisCommΩK-based (suc n) x p q =\n sym (transport⁻Transport (typId x) (p ∙ q))\n ∙∙ (cong (transport (λ i → typId x (~ i))) (transpTypId p q)\n ∙∙ (λ i → transport (λ i → typId x (~ i)) (isCommΩK (suc n) (transport (λ i → typId x i) p) (transport (λ i → typId x i) q) i))\n ∙∙ cong (transport (λ i → typId x (~ i))) (sym (transpTypId q p)))\n ∙∙ transport⁻Transport (typId x) (q ∙ p)\n where\n congIsoHelper : (x : coHomK (suc n)) → Iso (coHomK (suc n)) (coHomK (suc n))\n Iso.fun (congIsoHelper x) = _+ₖ x\n Iso.inv (congIsoHelper x) = _+ₖ (-ₖ x)\n Iso.rightInv (congIsoHelper x) a = assocₖ a (-ₖ x) x ∙∙ cong (a +ₖ_) (lCancelₖ x) ∙∙ rUnitₖ a\n Iso.leftInv (congIsoHelper x) a = assocₖ a x (-ₖ x) ∙∙ cong (a +ₖ_) (rCancelₖ x) ∙∙ rUnitₖ a\n\n typId : (x : coHomK (suc n)) → (x ≡ x) ≡ Path (coHomK (suc n)) 0ₖ 0ₖ\n typId x = isoToPath (congIso (invIso (congIsoHelper x))) ∙ λ i → rCancelₖ x i ≡ rCancelₖ x i\n\n transpTypId : (p q : (x ≡ x)) → transport (λ i → typId x i) (p ∙ q) ≡ transport (λ i → typId x i) p ∙ transport (λ i → typId x i) q\n transpTypId p q =\n ((substComposite (λ x → x) (isoToPath ((congIso (invIso (congIsoHelper x)))))\n (λ i → rCancelₖ x i ≡ rCancelₖ x i) (p ∙ q))\n ∙∙ (λ i → transport (λ i → rCancelₖ x i ≡ rCancelₖ x i) (transportRefl (congFunct (_+ₖ (-ₖ x)) p q i) i))\n ∙∙ overPathFunct (cong (_+ₖ (-ₖ x)) p) (cong (_+ₖ (-ₖ x)) q) (rCancelₖ x))\n ∙∙ cong₂ (λ y z → transport (λ i → rCancelₖ x i ≡ rCancelₖ x i) y ∙ transport (λ i → rCancelₖ x i ≡ rCancelₖ x i) z)\n (sym (transportRefl (cong (_+ₖ (-ₖ x)) p)))\n (sym (transportRefl (cong (_+ₖ (-ₖ x)) q)))\n ∙∙ cong₂ (_∙_) (sym (substComposite (λ x → x) (isoToPath ((congIso (invIso (congIsoHelper x))))) (λ i → rCancelₖ x i ≡ rCancelₖ x i) p))\n (sym (substComposite (λ x → x) (isoToPath ((congIso (invIso (congIsoHelper x))))) (λ i → rCancelₖ x i ≡ rCancelₖ x i) q))\n\n\naddLemma : (a b : Int) → a +ₖ b ≡ (a ℤ+ b)\naddLemma a b = (cong ΩKn+1→Kn (sym (congFunct ∣_∣ (looper a) (looper b)))\n ∙∙ cong₂ (λ x y → ΩKn+1→Kn (cong ∣_∣ (x ∙ y))) (looper≡looper2 a) (looper≡looper2 b)\n ∙∙ (λ i → ΩKn+1→Kn (cong ∣_∣ (cong SuspBool→S1 (cong S¹→SuspBool (intLoop a)) ∙ cong SuspBool→S1 (cong S¹→SuspBool (intLoop b))))))\n ∙∙ (cong (λ x → ΩKn+1→Kn (cong ∣_∣ x)) (sym (congFunct SuspBool→S1 (cong S¹→SuspBool (intLoop a)) (cong S¹→SuspBool (intLoop b))))\n ∙∙ cong (λ x → ΩKn+1→Kn (cong ∣_∣ (cong SuspBool→S1 x))) (sym (congFunct S¹→SuspBool (intLoop a) (intLoop b)))\n ∙∙ cong (λ x → ΩKn+1→Kn (cong ∣_∣ (cong SuspBool→S1 (cong S¹→SuspBool x)))) (intLoop-hom a b))\n ∙∙ (cong (λ x → ΩKn+1→Kn (cong ∣_∣ x)) (sym (looper≡looper2 (a ℤ+ b)))\n ∙ Iso.leftInv (Iso3-Kn-ΩKn+1 zero) (a ℤ+ b))\n", "meta": {"hexsha": "36cccdbda218f72e3974757c2c8ab33dcb71c52e", "size": 17721, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/ZCohomology/Properties.agda", "max_stars_repo_name": "knrafto/cubical", "max_stars_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "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": "Cubical/ZCohomology/Properties.agda", "max_issues_repo_name": "knrafto/cubical", "max_issues_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "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": "Cubical/ZCohomology/Properties.agda", "max_forks_repo_name": "knrafto/cubical", "max_forks_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "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": 51.2167630058, "max_line_length": 183, "alphanum_fraction": 0.5080413069, "num_tokens": 8425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6513548646660543, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.35106934276830054}} {"text": "module Data.Num.Injection where\n\nopen import Data.Num.Core\n\nopen import Data.Nat hiding (compare)\nopen import Data.Nat.Properties\nopen import Data.Nat.Properties.Simple\nopen import Data.Nat.Properties.Extra\n\nopen import Data.Fin as Fin\n using (Fin; fromℕ≤; inject≤)\n renaming (zero to z; suc to s)\nopen import Data.Fin.Properties\n using (toℕ-fromℕ≤; to-from; bounded; inject≤-lemma)\n renaming (toℕ-injective to Fin→ℕ-injective; _≟_ to _Fin≟_)\nopen import Data.Fin.Properties.Extra\nopen import Data.Sum\nopen import Data.Product\nopen import Data.Empty using (⊥)\nopen import Data.Unit using (⊤; tt)\n\n\nopen import Function\nopen import Function.Injection\nopen Injection\n-- open import Function.Equality using (_⟶_; _⟨$⟩_)\nopen import Relation.Nullary.Decidable\nopen import Relation.Nullary\nopen import Relation.Nullary.Negation\nopen import Relation.Binary\nopen import Relation.Binary.PropositionalEquality\n\nopen ≡-Reasoning\nopen ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_)\nopen DecTotalOrder decTotalOrder using (reflexive) renaming (refl to ≤-refl)\nopen StrictTotalOrder strictTotalOrder using (compare)\n\ndata InjCond : ℕ → ℕ → ℕ → Set where\n Ordinary : ∀ {b d o} → (b≥d : b ≥ d) → (o≥1 : o ≥ 1) → InjCond b d o\n Digitless : ∀ {b d o} → (d≡0 : d ≡ 0) → InjCond b 0 o -- having no digits at all\n\ndata NonInjCond : ℕ → ℕ → ℕ → Set where\n Redundant : ∀ {b d o} → (d>b : d > b) → NonInjCond b d o -- having to many digits\n WithZeros : ∀ {b d o} → (o≡0 : o ≡ 0) → (d≢0 : d ≢ 0) → NonInjCond b d 0 -- with leading zeroes\n\ndata InjectionView : ℕ → ℕ → ℕ → Set where\n Inj : ∀ {b d o} → InjCond b d o → InjectionView b d o\n NonInj : ∀ {b d o} → NonInjCond b d o → InjectionView b d o\n\ninjectionView : (b d o : ℕ) → InjectionView b d o\ninjectionView b zero zero = Inj (Digitless refl)\ninjectionView b (suc d) zero = NonInj (WithZeros refl (λ ()))\ninjectionView b d (suc o) with d ≤? b\ninjectionView b d (suc o) | yes p = Inj (Ordinary p (s≤s z≤n))\ninjectionView b d (suc o) | no ¬p = NonInj (Redundant (≰⇒> ¬p))\n\n\nIsInjective : ℕ → ℕ → ℕ → Set\nIsInjective b d o with injectionView b d o\nIsInjective b d o | Inj _ = ⊤\nIsInjective b d o | NonInj _ = ⊥\n\nInjCond⇒IsInj : ∀ {b d o} → InjCond b d o → IsInjective b d o\nInjCond⇒IsInj {b} {d} {o} cond with injectionView b d o\nInjCond⇒IsInj _ | Inj _ = tt\nInjCond⇒IsInj (Ordinary b≥d o≥1) | NonInj (Redundant d>b) = contradiction b≥d (>⇒≰ d>b)\nInjCond⇒IsInj (Ordinary b≥d ()) | NonInj (WithZeros o≡0 d≢0)\nInjCond⇒IsInj (Digitless d≡0) | NonInj (Redundant ())\nInjCond⇒IsInj (Digitless d≡0) | NonInj (WithZeros refl d≢0) = contradiction refl d≢0\n\n-- InjCond⇒b≥1 : ∀ {b d o} → InjCond b (suc d) o → b ≥ 1\n-- InjCond⇒b≥1 {zero} (bijCond b≥d: o≥1:) = contradiction b≥d: (>⇒≰ (s≤s z≤n))\n-- InjCond⇒b≥1 {suc b} (bijCond b≥d: o≥1:) = s≤s z≤n\n--\n\n\nNonInjCond⇏IsInj : ∀ {b d o} → NonInjCond b d o → ¬ IsInjective b d o\nNonInjCond⇏IsInj {b} {d} {o} reason claim with injectionView b d o\nNonInjCond⇏IsInj (Redundant d>b) claim | Inj (Ordinary b≥d o≥1) = contradiction b≥d (>⇒≰ d>b)\nNonInjCond⇏IsInj (Redundant ()) claim | Inj (Digitless d≡0)\nNonInjCond⇏IsInj (WithZeros o≡0 d≢0) claim | Inj (Ordinary b≥d ())\nNonInjCond⇏IsInj (WithZeros o≡0 d≢0) claim | Inj (Digitless d≡0) = contradiction refl d≢0\nNonInjCond⇏IsInj reason () | NonInj _\n\nDigit-toℕ-injective : ∀ {d} o (x y : Fin d)\n → Digit-toℕ x o ≡ Digit-toℕ y o -- o + toℕ x ≡ o + toℕ y\n → x ≡ y\nDigit-toℕ-injective {_} o x y eq =\n Fin→ℕ-injective -- cancels `Fin.toℕ`\n $ cancel-+-left o -- cancels `o +`\n $ eq\n\n\nn∷-mono-strict : ∀ {b d o} (x y : Fin d) (xs ys : Num b d o)\n → InjCond b d o\n → toℕ xs < toℕ ys\n → toℕ (x ∷ xs) < toℕ (y ∷ ys)\nn∷-mono-strict {b} {_} {o} () () xs ys (Digitless d≡0) ⟦xs⟧<⟦ys⟧\nn∷-mono-strict {b} {d} {o} x y xs ys (Ordinary b≥d o≥1) ⟦xs⟧<⟦ys⟧ =\n start\n suc (Digit-toℕ x o) + toℕ xs * b\n ≤⟨ +n-mono (toℕ xs * b) $\n start\n suc (Digit-toℕ x o)\n ≈⟨ sym (+-suc o (Fin.toℕ x)) ⟩\n -- push `o` to the left\n o + suc (Fin.toℕ x)\n ≤⟨ n+-mono o $\n start\n suc (Fin.toℕ x)\n ≤⟨ bounded x ⟩\n d\n ≤⟨ b≥d ⟩\n b\n ≤⟨ n≤m+n (Fin.toℕ y) b ⟩\n Fin.toℕ y + b\n □ ⟩\n o + (Fin.toℕ y + b)\n ≈⟨ sym (+-assoc o (Fin.toℕ y) b) ⟩\n Digit-toℕ y o + b\n □ ⟩\n Digit-toℕ y o + b + toℕ xs * b\n ≈⟨ +-assoc (Digit-toℕ y o) b (toℕ xs * b) ⟩\n Digit-toℕ y o + (b + toℕ xs * b)\n ≤⟨ n+-mono (Digit-toℕ y o) (*n-mono b ⟦xs⟧<⟦ys⟧) ⟩ -- replace `xs` with `ys`\n Digit-toℕ y o + toℕ ys * b\n □\n\n∷ns-mono-strict : ∀ {b d o} (x y : Fin d) (xs ys : Num b d o)\n → toℕ xs ≡ toℕ ys\n → Digit-toℕ x o < Digit-toℕ y o\n → toℕ (x ∷ xs) < toℕ (y ∷ ys)\n∷ns-mono-strict {b} {d} {o} x y xs ys ⟦xs⟧≡⟦ys⟧ ⟦x⟧<⟦y⟧ = start\n suc (Digit-toℕ x o + toℕ xs * b)\n ≈⟨ cong (λ w → suc (Digit-toℕ x o + w * b)) ⟦xs⟧≡⟦ys⟧ ⟩\n suc (Digit-toℕ x o + toℕ ys * b)\n ≤⟨ +n-mono (toℕ ys * b) ⟦x⟧<⟦y⟧ ⟩\n Digit-toℕ y o + toℕ ys * b\n □\n\ntoℕ-injective-⟦x∷xs⟧>0-lemma : ∀ {b d o}\n → o ≥ 1\n → (x : Fin d)\n → (xs : Num b d o)\n → toℕ (x ∷ xs) > 0\ntoℕ-injective-⟦x∷xs⟧>0-lemma {b} {d} {o} o≥1 x xs =\n start\n suc zero\n ≤⟨ o≥1 ⟩\n o\n ≤⟨ m≤m+n o (Fin.toℕ x) ⟩\n o + Fin.toℕ x\n ≤⟨ m≤m+n (o + Fin.toℕ x) (toℕ xs * b) ⟩\n o + Fin.toℕ x + toℕ xs * b\n □\n\ntoℕ-injective : ∀ {b d o}\n → {isInj : IsInjective b d o}\n → (xs ys : Num b d o)\n → toℕ xs ≡ toℕ ys\n → xs ≡ ys\ntoℕ-injective {b} {d} {o} xs ys eq with injectionView b d o\ntoℕ-injective ∙ ∙ eq | Inj (Ordinary b≥d o≥1) = refl\ntoℕ-injective ∙ (y ∷ ys) eq | Inj (Ordinary b≥d o≥1) = contradiction eq (<⇒≢ (toℕ-injective-⟦x∷xs⟧>0-lemma o≥1 y ys))\ntoℕ-injective (x ∷ xs) ∙ eq | Inj (Ordinary b≥d o≥1) = contradiction eq (>⇒≢ (toℕ-injective-⟦x∷xs⟧>0-lemma o≥1 x xs))\ntoℕ-injective {b} {zero} {o} (() ∷ xs) (y ∷ ys) eq | Inj cond\ntoℕ-injective {b} {suc d} {o} (x ∷ xs) (y ∷ ys) eq | Inj cond with compare (toℕ xs) (toℕ ys)\ntoℕ-injective {b} {suc d} {o} (x ∷ xs) (y ∷ ys) eq | Inj cond | tri< ⟦xs⟧<⟦ys⟧ _ _ = contradiction eq (<⇒≢ (n∷-mono-strict x y xs ys cond ⟦xs⟧<⟦ys⟧))\ntoℕ-injective {b} {suc d} {o} (x ∷ xs) (y ∷ ys) eq | Inj cond | tri≈ _ ⟦xs⟧≡⟦ys⟧ _ with compare (Digit-toℕ x o) (Digit-toℕ y o)\ntoℕ-injective {b} {suc d} {o} (x ∷ xs) (y ∷ ys) eq | Inj cond | tri≈ _ ⟦xs⟧≡⟦ys⟧ _ | tri< ⟦x⟧<⟦y⟧ _ _ = contradiction eq (<⇒≢ (∷ns-mono-strict x y xs ys ⟦xs⟧≡⟦ys⟧ ⟦x⟧<⟦y⟧))\ntoℕ-injective {b} {suc d} {o} (x ∷ xs) (y ∷ ys) eq | Inj cond | tri≈ _ ⟦xs⟧≡⟦ys⟧ _ | tri≈ _ ⟦x⟧≡⟦y⟧ _ = cong₂ _∷_ (Digit-toℕ-injective o x y ⟦x⟧≡⟦y⟧) (toℕ-injective {isInj = InjCond⇒IsInj cond} xs ys ⟦xs⟧≡⟦ys⟧)\ntoℕ-injective {b} {suc d} {o} (x ∷ xs) (y ∷ ys) eq | Inj cond | tri≈ _ ⟦xs⟧≡⟦ys⟧ _ | tri> _ _ ⟦x⟧>⟦y⟧ = contradiction eq (>⇒≢ (∷ns-mono-strict y x ys xs (sym ⟦xs⟧≡⟦ys⟧) ⟦x⟧>⟦y⟧))\ntoℕ-injective {b} {suc d} {o} (x ∷ xs) (y ∷ ys) eq | Inj cond | tri> _ _ ⟦xs⟧>⟦ys⟧ = contradiction eq (>⇒≢ ((n∷-mono-strict y x ys xs cond ⟦xs⟧>⟦ys⟧)))\ntoℕ-injective ∙ ∙ eq | Inj (Digitless d≡0) = refl\ntoℕ-injective ∙ (() ∷ ys) eq | Inj (Digitless d≡0)\ntoℕ-injective (() ∷ xs) ys eq | Inj (Digitless d≡0)\ntoℕ-injective {isInj = ()} xs ys eq | NonInj reason\n\nInjCond⇒Injective : ∀ {b} {d} {o} → InjCond b d o → Injective (Num⟶ℕ b d o)\nInjCond⇒Injective condition {x} {y} = toℕ-injective {isInj = InjCond⇒IsInj condition} x y\n\nNonInjCond⇏Injective : ∀ {b} {d} {o} → NonInjCond b d o → ¬ (Injective (Num⟶ℕ b d o))\nNonInjCond⇏Injective {zero} {zero} (Redundant ()) claim\nNonInjCond⇏Injective {zero} {suc d} {o} (Redundant d>b) claim =\n contradiction\n (claim\n {z ∷ ∙}\n {z ∷ z ∷ ∙}\n ⟦1∷∙⟧≡⟦1∷1∷∙⟧)\n (λ ())\n where ⟦1∷∙⟧≡⟦1∷1∷∙⟧ : toℕ {zero} {suc d} {o} (z ∷ ∙) ≡ toℕ {zero} {suc d} {o} (z ∷ z ∷ ∙)\n ⟦1∷∙⟧≡⟦1∷1∷∙⟧ = cong (λ w → o + 0 + w) (sym (*-right-zero (o + 0 + 0)))\nNonInjCond⇏Injective {suc b} {zero} (Redundant ()) claim\nNonInjCond⇏Injective {suc b} {suc zero} (Redundant (s≤s ())) claim\nNonInjCond⇏Injective {suc b} {suc (suc d)} {o} (Redundant d>b) claim =\n contradiction\n (claim\n {z ∷ s z ∷ ∙}\n {fromℕ≤ d>b ∷ z ∷ ∙}\n ⟦1∷2⟧≡⟦b+1∷1⟧)\n (λ ())\n where ⟦1∷2⟧≡⟦b+1∷1⟧ : toℕ {suc b} {suc (suc d)} {o} (z ∷ s z ∷ ∙) ≡ toℕ {suc b} {suc (suc d)} {o} (fromℕ≤ {suc b} d>b ∷ z ∷ ∙)\n ⟦1∷2⟧≡⟦b+1∷1⟧ =\n begin\n o + zero + (o + suc zero + zero) * suc b\n ≡⟨ cong (λ x → x + (o + suc zero + zero) * suc b) (+-right-identity o) ⟩\n o + (o + suc zero + zero) * suc b\n ≡⟨ cong (λ x → o + (x + zero) * suc b) (+-suc o zero) ⟩\n o + (suc (o + zero) + zero) * suc b\n ≡⟨ refl ⟩\n o + (suc b + (o + zero + zero) * suc b)\n ≡⟨ sym (+-assoc o (suc b) ((o + zero + zero) * suc b)) ⟩\n o + suc b + (o + zero + zero) * suc b\n ≡⟨ cong (λ x → o + x + (o + zero + zero) * suc b) (sym (toℕ-fromℕ≤ d>b)) ⟩\n o + Fin.toℕ (fromℕ≤ d>b) + (o + zero + zero) * suc b\n ∎\nNonInjCond⇏Injective {b} {zero} {_} (WithZeros o≡0 d≢0) claim = contradiction refl d≢0\nNonInjCond⇏Injective {b} {suc d} {_} (WithZeros o≡0 d≢0) claim =\n contradiction\n (claim\n {z ∷ ∙}\n {∙}\n ⟦0∷∙⟧≡⟦∙⟧)\n (λ ())\n where ⟦0∷∙⟧≡⟦∙⟧ : toℕ {b} {suc d} {0} (z ∷ ∙) ≡ toℕ {b} {suc d} {0} ∙\n ⟦0∷∙⟧≡⟦∙⟧ = refl\n\nInjective? : ∀ b d o → Dec (Injective (Num⟶ℕ b d o))\nInjective? b d o with injectionView b d o\nInjective? b d o | Inj condition = yes (InjCond⇒Injective condition)\nInjective? b d o | NonInj reason = no (NonInjCond⇏Injective reason)\n\n-- begin\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ≡⟨ {! !} ⟩\n-- {! !}\n-- ∎\n", "meta": {"hexsha": "9bec3e3e8caa41dfcea4cdd200ce3c1b16238296", "size": 10262, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Data/Num/Injection.agda", "max_stars_repo_name": "banacorn/numeral", "max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z", "max_issues_repo_path": "Data/Num/Injection.agda", "max_issues_repo_name": "banacorn/numeral", "max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "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": "Data/Num/Injection.agda", "max_forks_repo_name": "banacorn/numeral", "max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z", "max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z", "avg_line_length": 42.0573770492, "max_line_length": 210, "alphanum_fraction": 0.5158838433, "num_tokens": 4703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6859494550081925, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.3510117261154649}} {"text": "{-# OPTIONS --without-K --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped as U\nopen import Definition.Typed\nopen import Definition.Typed.Weakening\nopen import Agda.Primitive\n\nopen import Tools.Product\nopen import Tools.Embedding\nimport Tools.PropositionalEquality as PE\n\n-- The different cases of the logical relation are spread out through out\n-- this file. This is due to them having different dependencies.\n\n-- We will refer to expressions that satisfies the logical relation as reducible.\n\n-- Reducibility of Neutrals:\n\n-- Neutral type\nrecord _⊩ne_ (Γ : Con Term) (A : Term) : Set where\n constructor ne\n field\n K : Term\n D : Γ ⊢ A :⇒*: K\n neK : Neutral K\n K≡K : Γ ⊢ K ~ K ∷ U\n\n-- Neutral type equality\nrecord _⊩ne_≡_/_ (Γ : Con Term) (A B : Term) ([A] : Γ ⊩ne A) : Set where\n constructor ne₌\n open _⊩ne_ [A]\n field\n M : Term\n D′ : Γ ⊢ B :⇒*: M\n neM : Neutral M\n K≡M : Γ ⊢ K ~ M ∷ U\n\n-- Neutral term in WHNF\nrecord _⊩neNf_∷_ (Γ : Con Term) (k A : Term) : Set where\n inductive\n constructor neNfₜ\n field\n neK : Neutral k\n ⊢k : Γ ⊢ k ∷ A\n k≡k : Γ ⊢ k ~ k ∷ A\n\n-- Neutral term\nrecord _⊩ne_∷_/_ (Γ : Con Term) (t A : Term) ([A] : Γ ⊩ne A) : Set where\n inductive\n constructor neₜ\n open _⊩ne_ [A]\n field\n k : Term\n d : Γ ⊢ t :⇒*: k ∷ K\n nf : Γ ⊩neNf k ∷ K\n\n-- Neutral term equality in WHNF\nrecord _⊩neNf_≡_∷_ (Γ : Con Term) (k m A : Term) : Set where\n inductive\n constructor neNfₜ₌\n field\n neK : Neutral k\n neM : Neutral m\n k≡m : Γ ⊢ k ~ m ∷ A\n\n-- Neutral term equality\nrecord _⊩ne_≡_∷_/_ (Γ : Con Term) (t u A : Term) ([A] : Γ ⊩ne A) : Set where\n constructor neₜ₌\n open _⊩ne_ [A]\n field\n k m : Term\n d : Γ ⊢ t :⇒*: k ∷ K\n d′ : Γ ⊢ u :⇒*: m ∷ K\n nf : Γ ⊩neNf k ≡ m ∷ K\n\n-- Reducibility of natural numbers:\n\n-- Natural number type\n_⊩ℕ_ : (Γ : Con Term) (A : Term) → Set\nΓ ⊩ℕ A = Γ ⊢ A :⇒*: ℕ\n\n-- Natural number type equality\ndata _⊩ℕ_≡_ (Γ : Con Term) (A B : Term) : Set where\n ℕ₌ : Γ ⊢ B ⇒* ℕ → Γ ⊩ℕ A ≡ B\n\nmutual\n -- Natural number term\n data _⊩ℕ_∷ℕ (Γ : Con Term) (t : Term) : Set where\n ℕₜ : (n : Term) (d : Γ ⊢ t :⇒*: n ∷ ℕ) (n≡n : Γ ⊢ n ≅ n ∷ ℕ)\n (prop : Natural-prop Γ n)\n → Γ ⊩ℕ t ∷ℕ\n\n -- WHNF property of natural number terms\n data Natural-prop (Γ : Con Term) : (n : Term) → Set where\n sucᵣ : ∀ {n} → Γ ⊩ℕ n ∷ℕ → Natural-prop Γ (suc n)\n zeroᵣ : Natural-prop Γ zero\n ne : ∀ {n} → Γ ⊩neNf n ∷ ℕ → Natural-prop Γ n\n\nmutual\n -- Natural number term equality\n data _⊩ℕ_≡_∷ℕ (Γ : Con Term) (t u : Term) : Set where\n ℕₜ₌ : (k k′ : Term) (d : Γ ⊢ t :⇒*: k ∷ ℕ) (d′ : Γ ⊢ u :⇒*: k′ ∷ ℕ)\n (k≡k′ : Γ ⊢ k ≅ k′ ∷ ℕ)\n (prop : [Natural]-prop Γ k k′) → Γ ⊩ℕ t ≡ u ∷ℕ\n\n -- WHNF property of Natural number term equality\n data [Natural]-prop (Γ : Con Term) : (n n′ : Term) → Set where\n sucᵣ : ∀ {n n′} → Γ ⊩ℕ n ≡ n′ ∷ℕ → [Natural]-prop Γ (suc n) (suc n′)\n zeroᵣ : [Natural]-prop Γ zero zero\n ne : ∀ {n n′} → Γ ⊩neNf n ≡ n′ ∷ ℕ → [Natural]-prop Γ n n′\n\n-- Natural extraction from term WHNF property\nnatural : ∀ {Γ n} → Natural-prop Γ n → Natural n\nnatural (sucᵣ x) = sucₙ\nnatural zeroᵣ = zeroₙ\nnatural (ne (neNfₜ neK ⊢k k≡k)) = ne neK\n\n-- Natural extraction from term equality WHNF property\nsplit : ∀ {Γ a b} → [Natural]-prop Γ a b → Natural a × Natural b\nsplit (sucᵣ x) = sucₙ , sucₙ\nsplit zeroᵣ = zeroₙ , zeroₙ\nsplit (ne (neNfₜ₌ neK neM k≡m)) = ne neK , ne neM\n\n-- Type levels\n\ndata TypeLevel : Set where\n ⁰ : TypeLevel\n ¹ : TypeLevel\n\ndata _<_ : (i j : TypeLevel) → Set where\n 0<1 : ⁰ < ¹\n\ntoLevel : TypeLevel → Level\ntoLevel ⁰ = lzero\ntoLevel ¹ = lsuc lzero\n\n-- Logical relation\n\nrecord LogRelKit (ℓ : Level) : Set (lsuc (lsuc ℓ)) where\n constructor Kit\n field\n _⊩U : (Γ : Con Term) → Set (lsuc ℓ)\n _⊩Π_ : (Γ : Con Term) → Term → Set (lsuc ℓ)\n\n _⊩_ : (Γ : Con Term) → Term → Set (lsuc ℓ)\n _⊩_≡_/_ : (Γ : Con Term) (A B : Term) → Γ ⊩ A → Set ℓ\n _⊩_∷_/_ : (Γ : Con Term) (t A : Term) → Γ ⊩ A → Set ℓ\n _⊩_≡_∷_/_ : (Γ : Con Term) (t u A : Term) → Γ ⊩ A → Set ℓ\n\nmodule LogRel (l : TypeLevel) (rec : ∀ {l′} → l′ < l → LogRelKit (toLevel l)) where\n\n record _⊩¹U (Γ : Con Term) : Set (lsuc (lsuc (toLevel l))) where\n constructor Uᵣ\n field\n l′ : TypeLevel\n l< : l′ < l\n ⊢Γ : ⊢ Γ\n\n -- Universe type equality\n record _⊩¹U≡_ (Γ : Con Term) (B : Term) : Set (lsuc (toLevel l)) where\n constructor U₌\n field\n B≡U : B PE.≡ U\n\n -- Universe term\n record _⊩¹U_∷U/_ {l′} (Γ : Con Term) (t : Term) (l< : l′ < l) : Set (lsuc (toLevel l)) where\n constructor Uₜ\n open LogRelKit (rec l<)\n field\n A : Term\n d : Γ ⊢ t :⇒*: A ∷ U\n typeA : Type A\n A≡A : Γ ⊢ A ≅ A ∷ U\n [t] : Γ ⊩ t\n\n -- Universe term equality\n record _⊩¹U_≡_∷U/_ {l′} (Γ : Con Term) (t u : Term) (l< : l′ < l) : Set (lsuc (toLevel l)) where\n constructor Uₜ₌\n open LogRelKit (rec l<)\n field\n A B : Term\n d : Γ ⊢ t :⇒*: A ∷ U\n d′ : Γ ⊢ u :⇒*: B ∷ U\n typeA : Type A\n typeB : Type B\n A≡B : Γ ⊢ A ≅ B ∷ U\n [t] : Γ ⊩ t\n [u] : Γ ⊩ u\n [t≡u] : Γ ⊩ t ≡ u / [t]\n\n RedRel : Set (lsuc (lsuc (lsuc (toLevel l))))\n RedRel = Con Term → Term → (Term → Set (lsuc (toLevel l))) → (Term → Set (lsuc (toLevel l))) → (Term → Term → Set (lsuc (toLevel l))) → Set (lsuc (lsuc (toLevel l)))\n\n record _⊩⁰_/_ (Γ : Con Term) (A : Term) (_⊩_▸_▸_▸_ : RedRel) : Set (lsuc (lsuc (toLevel l))) where\n inductive\n eta-equality\n constructor LRPack\n field\n ⊩Eq : Term → Set (lsuc (toLevel l))\n ⊩Term : Term → Set (lsuc (toLevel l))\n ⊩EqTerm : Term → Term → Set (lsuc (toLevel l))\n ⊩LR : Γ ⊩ A ▸ ⊩Eq ▸ ⊩Term ▸ ⊩EqTerm\n\n _⊩⁰_≡_/_ : {R : RedRel} (Γ : Con Term) (A B : Term) → Γ ⊩⁰ A / R → Set (lsuc (toLevel l))\n Γ ⊩⁰ A ≡ B / LRPack ⊩Eq ⊩Term ⊩EqTerm ⊩Red = ⊩Eq B\n\n _⊩⁰_∷_/_ : {R : RedRel} (Γ : Con Term) (t A : Term) → Γ ⊩⁰ A / R → Set (lsuc (toLevel l))\n Γ ⊩⁰ t ∷ A / LRPack ⊩Eq ⊩Term ⊩EqTerm ⊩Red = ⊩Term t\n\n _⊩⁰_≡_∷_/_ : {R : RedRel} (Γ : Con Term) (t u A : Term) → Γ ⊩⁰ A / R → Set (lsuc (toLevel l))\n Γ ⊩⁰ t ≡ u ∷ A / LRPack ⊩Eq ⊩Term ⊩EqTerm ⊩Red = ⊩EqTerm t u\n\n record _⊩¹Π_/_ (Γ : Con Term) (A : Term) (R : RedRel) : Set (lsuc (lsuc (toLevel l))) where\n inductive\n eta-equality\n constructor Πᵣ\n field\n F : Term\n G : Term\n D : Γ ⊢ A :⇒*: Π F ▹ G\n ⊢F : Γ ⊢ F\n ⊢G : Γ ∙ F ⊢ G\n A≡A : Γ ⊢ Π F ▹ G ≅ Π F ▹ G\n [F] : ∀ {ρ Δ} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ) → Δ ⊩⁰ U.wk ρ F / R\n [G] : ∀ {ρ Δ a}\n → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)\n → Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ\n → Δ ⊩⁰ U.wk (lift ρ) G [ a ] / R\n G-ext : ∀ {ρ Δ a b}\n → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)\n → ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ)\n → ([b] : Δ ⊩⁰ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ)\n → Δ ⊩⁰ a ≡ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ\n → Δ ⊩⁰ U.wk (lift ρ) G [ a ] ≡ U.wk (lift ρ) G [ b ] / [G] [ρ] ⊢Δ [a]\n\n record _⊩¹Π_≡_/_ {R : RedRel} (Γ : Con Term) (A B : Term) ([A] : Γ ⊩¹Π A / R) : Set (lsuc (toLevel l)) where\n inductive\n eta-equality\n constructor Π₌\n open _⊩¹Π_/_ [A]\n field\n F′ : Term\n G′ : Term\n D′ : Γ ⊢ B ⇒* Π F′ ▹ G′\n A≡B : Γ ⊢ Π F ▹ G ≅ Π F′ ▹ G′\n [F≡F′] : ∀ {ρ Δ}\n → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)\n → Δ ⊩⁰ U.wk ρ F ≡ U.wk ρ F′ / [F] [ρ] ⊢Δ\n [G≡G′] : ∀ {ρ Δ a}\n → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)\n → ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ)\n → Δ ⊩⁰ U.wk (lift ρ) G [ a ] ≡ U.wk (lift ρ) G′ [ a ] / [G] [ρ] ⊢Δ [a]\n\n -- Term of Π-type\n _⊩¹Π_∷_/_ : {R : RedRel} (Γ : Con Term) (t A : Term) ([A] : Γ ⊩¹Π A / R) → Set (lsuc (toLevel l))\n Γ ⊩¹Π t ∷ A / Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext =\n ∃ λ f → Γ ⊢ t :⇒*: f ∷ Π F ▹ G\n × Function f\n × Γ ⊢ f ≅ f ∷ Π F ▹ G\n × (∀ {ρ Δ a b}\n → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)\n ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ)\n ([b] : Δ ⊩⁰ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ)\n ([a≡b] : Δ ⊩⁰ a ≡ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ)\n → Δ ⊩⁰ U.wk ρ f ∘ a ≡ U.wk ρ f ∘ b ∷ U.wk (lift ρ) G [ a ] / [G] [ρ] ⊢Δ [a])\n × (∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)\n → ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ)\n → Δ ⊩⁰ U.wk ρ f ∘ a ∷ U.wk (lift ρ) G [ a ] / [G] [ρ] ⊢Δ [a])\n -- Issue: Agda complains about record use not being strictly positive.\n -- Therefore we have to use ×\n\n\n -- Term equality of Π-type\n _⊩¹Π_≡_∷_/_ : {R : RedRel} (Γ : Con Term) (t u A : Term) ([A] : Γ ⊩¹Π A / R) → Set (lsuc (toLevel l))\n Γ ⊩¹Π t ≡ u ∷ A / Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext =\n let [A] = Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext\n in ∃₂ λ f g →\n Γ ⊢ t :⇒*: f ∷ Π F ▹ G\n × Γ ⊢ u :⇒*: g ∷ Π F ▹ G\n × Function f\n × Function g\n × Γ ⊢ f ≅ g ∷ Π F ▹ G\n × Γ ⊩¹Π t ∷ A / [A]\n × Γ ⊩¹Π u ∷ A / [A]\n × (∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)\n → ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ)\n → Δ ⊩⁰ U.wk ρ f ∘ a ≡ U.wk ρ g ∘ a ∷ U.wk (lift ρ) G [ a ] / [G] [ρ] ⊢Δ [a])\n -- Issue: Same as above.\n\n\n -- Logical relation definition\n data _⊩LR_▸_▸_▸_ : RedRel where\n LRU : ∀ {Γ} (⊢Γ : ⊢ Γ) → (l' : TypeLevel) → (l< : l' < l) → Γ ⊩LR U\n ▸ (λ B → Γ ⊩¹U≡ B)\n ▸ (λ t → Γ ⊩¹U t ∷U/ l<)\n ▸ (λ t u → Γ ⊩¹U t ≡ u ∷U/ l<)\n LRℕ : ∀ {Γ A} → Γ ⊩ℕ A → Γ ⊩LR A\n ▸ (λ B → ι′ (Γ ⊩ℕ A ≡ B))\n ▸ (λ t → ι′ (Γ ⊩ℕ t ∷ℕ))\n ▸ (λ t u → ι′ (Γ ⊩ℕ t ≡ u ∷ℕ))\n LRne : ∀ {Γ A} → (neA : Γ ⊩ne A) → Γ ⊩LR A\n ▸ (λ B → ι′ (Γ ⊩ne A ≡ B / neA))\n ▸ (λ t → ι′ (Γ ⊩ne t ∷ A / neA))\n ▸ (λ t u → ι′ (Γ ⊩ne t ≡ u ∷ A / neA))\n LRΠ : ∀ {Γ A} → (ΠA : Γ ⊩¹Π A / _⊩LR_▸_▸_▸_) → Γ ⊩LR A\n ▸ (λ B → Γ ⊩¹Π A ≡ B / ΠA)\n ▸ (λ t → Γ ⊩¹Π t ∷ A / ΠA)\n ▸ (λ t u → Γ ⊩¹Π t ≡ u ∷ A / ΠA)\n LRemb : ∀ {Γ A l′} (l< : l′ < l) (let open LogRelKit (rec l<)) ([A] : Γ ⊩ A) → Γ ⊩LR A\n ▸ (λ B → ι (Γ ⊩ A ≡ B / [A]))\n ▸ (λ t → ι (Γ ⊩ t ∷ A / [A]))\n ▸ (λ t u → ι (Γ ⊩ t ≡ u ∷ A / [A]))\n\n _⊩¹_ : (Γ : Con Term) → (A : Term) → Set (lsuc (lsuc (toLevel l)))\n Γ ⊩¹ A = Γ ⊩⁰ A / _⊩LR_▸_▸_▸_\n\n _⊩¹_≡_/_ : (Γ : Con Term) (A B : Term) → Γ ⊩¹ A → Set (lsuc (toLevel l))\n Γ ⊩¹ A ≡ B / [A] = Γ ⊩⁰ A ≡ B / [A]\n\n _⊩¹_∷_/_ : (Γ : Con Term) (t A : Term) → Γ ⊩¹ A → Set (lsuc (toLevel l))\n Γ ⊩¹ t ∷ A / [A] = Γ ⊩⁰ t ∷ A / [A]\n\n _⊩¹_≡_∷_/_ : (Γ : Con Term) (t u A : Term) → Γ ⊩¹ A → Set (lsuc (toLevel l))\n Γ ⊩¹ t ≡ u ∷ A / [A] = Γ ⊩⁰ t ≡ u ∷ A / [A]\n\nopen LogRel public using (Uᵣ; Πᵣ; Π₌; U₌ ; Uₜ; Uₜ₌ ; LRU ; LRℕ ; LRne ; LRΠ ; LRemb ; LRPack)\n\npattern Πₜ f d funcF f≡f [f] [f]₁ = f , d , funcF , f≡f , [f] , [f]₁\npattern Πₜ₌ f g d d′ funcF funcG f≡g [f] [g] [f≡g] = f , g , d , d′ , funcF , funcG , f≡g , [f] , [g] , [f≡g]\npattern ℕᵣ a = LRPack _ _ _ (LRℕ a)\npattern emb′ a b = LRPack _ _ _ (LRemb a b)\npattern Uᵣ′ a b c = LRPack _ _ _ (LRU c a b)\npattern ne′ a b c d = LRPack _ _ _ (LRne (ne a b c d))\npattern Πᵣ′ a b c d e f g h i = LRPack _ _ _ (LRΠ (Πᵣ a b c d e f g h i))\n\nkit₀ : LogRelKit (lsuc (lzero))\nkit₀ = Kit _⊩¹U (λ Γ A → Γ ⊩¹Π A / _⊩LR_▸_▸_▸_) _⊩¹_ _⊩¹_≡_/_ _⊩¹_∷_/_ _⊩¹_≡_∷_/_ where open LogRel ⁰ (λ ())\n\nlogRelRec : ∀ l {l′} → l′ < l → LogRelKit (toLevel l)\nlogRelRec ⁰ = λ ()\nlogRelRec ¹ 0<1 = kit₀\n\nkit : ∀ (l : TypeLevel) → LogRelKit (lsuc (toLevel l))\nkit l = Kit _⊩¹U (λ Γ A → Γ ⊩¹Π A / _⊩LR_▸_▸_▸_) _⊩¹_ _⊩¹_≡_/_ _⊩¹_∷_/_ _⊩¹_≡_∷_/_ where open LogRel l (logRelRec l)\n\n-- a bit of repetition in \"kit ¹\" definition, would work better with Fin 2 for\n-- TypeLevel because you could recurse.\n\nrecord _⊩′⟨_⟩U (Γ : Con Term) (l : TypeLevel) : Set where\n constructor Uᵣ\n field\n l′ : TypeLevel\n l< : l′ < l\n ⊢Γ : ⊢ Γ\n\n_⊩′⟨_⟩Π_ : (Γ : Con Term) (l : TypeLevel) → Term → Set (lsuc (lsuc (toLevel l)))\nΓ ⊩′⟨ l ⟩Π A = Γ ⊩Π A where open LogRelKit (kit l)\n\n_⊩⟨_⟩_ : (Γ : Con Term) (l : TypeLevel) → Term → Set (lsuc (lsuc (toLevel l)))\nΓ ⊩⟨ l ⟩ A = Γ ⊩ A where open LogRelKit (kit l)\n\n_⊩⟨_⟩_≡_/_ : (Γ : Con Term) (l : TypeLevel) (A B : Term) → Γ ⊩⟨ l ⟩ A → Set (lsuc (toLevel l))\nΓ ⊩⟨ l ⟩ A ≡ B / [A] = Γ ⊩ A ≡ B / [A] where open LogRelKit (kit l)\n\n_⊩⟨_⟩_∷_/_ : (Γ : Con Term) (l : TypeLevel) (t A : Term) → Γ ⊩⟨ l ⟩ A → Set (lsuc (toLevel l))\nΓ ⊩⟨ l ⟩ t ∷ A / [A] = Γ ⊩ t ∷ A / [A] where open LogRelKit (kit l)\n\n_⊩⟨_⟩_≡_∷_/_ : (Γ : Con Term) (l : TypeLevel) (t u A : Term) → Γ ⊩⟨ l ⟩ A → Set (lsuc (toLevel l))\nΓ ⊩⟨ l ⟩ t ≡ u ∷ A / [A] = Γ ⊩ t ≡ u ∷ A / [A] where open LogRelKit (kit l)\n", "meta": {"hexsha": "149bd472fc276de373587569edf725c866936553", "size": 12561, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Definition/LogicalRelation.agda", "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation.agda", "max_issues_repo_name": "loic-p/logrel-mltt", "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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/LogicalRelation.agda", "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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": 33.496, "max_line_length": 167, "alphanum_fraction": 0.4754398535, "num_tokens": 6351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.35088198245842517}} {"text": "------------------------------------------------------------------------------\n-- Miscellaneous properties\n------------------------------------------------------------------------------\n\n{-# OPTIONS --exact-split #-}\n{-# OPTIONS --no-sized-types #-}\n{-# OPTIONS --no-universe-polymorphism #-}\n{-# OPTIONS --without-K #-}\n\nmodule FOTC.Program.SortList.Properties.MiscellaneousATP where\n\nopen import FOTC.Base\nopen import FOTC.Base.List\nopen import FOTC.Data.Bool\nopen import FOTC.Data.Bool.PropertiesATP\nopen import FOTC.Data.Nat.Inequalities\nopen import FOTC.Data.Nat.List.PropertiesATP\nopen import FOTC.Data.Nat.List.Type\nopen import FOTC.Data.Nat.Type\nopen import FOTC.Data.List\nopen import FOTC.Data.List.PropertiesATP\nopen import FOTC.Program.SortList.Properties.Totality.BoolATP\nopen import FOTC.Program.SortList.SortList\n\n------------------------------------------------------------------------------\n-- This is a weird result but recall that \"the relation ≤ between\n-- lists is only an ordering if nil is excluded\" (Burstall 1969,\n-- p. 46).\n-- xs≤[] : ∀ {is} → ListN is → OrdList is → ≤-Lists is []\n-- xs≤[] nilLN _ = ≤-Lists-[] []\n-- xs≤[] (lncons {i} {is} Ni LNis) LOconsL =\n-- prf $ xs≤[] LNis (subList-OrdList Ni LNis LOconsL)\n-- where\n-- postulate prf : ≤-Lists is [] → --IH.\n-- ≤-Lists (i ∷ is) []\n-- {-# ATP prove prf ≤-ItemList-Bool ordList-Bool x&&y≡true→x≡true #-}\n\nx≤ys→x≤zs→x≤ys++zs : ∀ {i js ks} → N i → ListN js → ListN ks →\n ≤-ItemList i js →\n ≤-ItemList i ks →\n ≤-ItemList i (js ++ ks)\nx≤ys→x≤zs→x≤ys++zs {i} {ks = ks} Ni lnnil LNks _ i≤k =\n subst (≤-ItemList i) (sym (++-leftIdentity ks)) i≤k\nx≤ys→x≤zs→x≤ys++zs {i} {ks = ks} Ni (lncons {j} {js} Nj LNjs) LNks i≤j∷js i≤k =\n prf (x≤ys→x≤zs→x≤ys++zs Ni LNjs LNks (&&-list₂-t₂ helper₁ helper₂ helper₃) i≤k)\n where\n helper₁ : Bool (le i j)\n helper₁ = le-Bool Ni Nj\n\n helper₂ : Bool (le-ItemList i js)\n helper₂ = le-ItemList-Bool Ni LNjs\n\n helper₃ : le i j && le-ItemList i js ≡ true\n helper₃ = trans (sym (le-ItemList-∷ i j js)) i≤j∷js\n\n postulate prf : ≤-ItemList i (js ++ ks) → ≤-ItemList i ((j ∷ js) ++ ks)\n {-# ATP prove prf &&-list₂-t helper₁ helper₂ helper₃ #-}\n\nxs≤ys→xs≤zs→xs≤ys++zs : ∀ {is js ks} → ListN is → ListN js → ListN ks →\n ≤-Lists is js →\n ≤-Lists is ks →\n ≤-Lists is (js ++ ks)\nxs≤ys→xs≤zs→xs≤ys++zs lnnil LNjs LNks _ _ = le-Lists-[] _\nxs≤ys→xs≤zs→xs≤ys++zs {js = js} {ks} (lncons {i} {is} Ni LNis)\n LNjs LNks i∷is≤js i∷is≤ks =\n prf ((xs≤ys→xs≤zs→xs≤ys++zs LNis LNjs LNks\n (&&-list₂-t₂ helper₁ helper₂ helper₃)\n (&&-list₂-t₂ helper₄ helper₅ helper₆)))\n where\n helper₁ = le-ItemList-Bool Ni LNjs\n helper₂ = le-Lists-Bool LNis LNjs\n helper₃ = trans (sym (le-Lists-∷ i is js)) i∷is≤js\n\n helper₄ = le-ItemList-Bool Ni LNks\n helper₅ = le-Lists-Bool LNis LNks\n helper₆ = trans (sym (le-Lists-∷ i is ks)) i∷is≤ks\n\n postulate prf : ≤-Lists is (js ++ ks) → ≤-Lists (i ∷ is) (js ++ ks)\n {-# ATP prove prf x≤ys→x≤zs→x≤ys++zs &&-list₂-t helper₁ helper₂ helper₃ helper₄ helper₅ helper₆ #-}\n\nxs≤zs→ys≤zs→xs++ys≤zs : ∀ {is js ks} → ListN is → ListN js → ListN ks →\n ≤-Lists is ks →\n ≤-Lists js ks →\n ≤-Lists (is ++ js) ks\nxs≤zs→ys≤zs→xs++ys≤zs {js = js} {ks} lnnil LNjs LNks is≤ks js≤ks =\n subst (λ t → ≤-Lists t ks)\n (sym (++-leftIdentity js))\n js≤ks\nxs≤zs→ys≤zs→xs++ys≤zs {js = js} {ks}\n (lncons {i} {is} Ni LNis) LNjs LNks i∷is≤ks js≤ks =\n prf (xs≤zs→ys≤zs→xs++ys≤zs LNis LNjs LNks\n (&&-list₂-t₂ helper₁ helper₂ helper₃)\n js≤ks)\n where\n helper₁ = le-ItemList-Bool Ni LNks\n helper₂ = le-Lists-Bool LNis LNks\n helper₃ = trans (sym (le-Lists-∷ i is ks)) i∷is≤ks\n\n postulate prf : ≤-Lists (is ++ js) ks → ≤-Lists ((i ∷ is) ++ js) ks\n {-# ATP prove prf &&-list₂-t helper₁ helper₂ helper₃ #-}\n\n------------------------------------------------------------------------------\n-- References\n--\n-- Burstall, R. M. (1969). Proving properties of programs by\n-- structural induction. The Computer Journal 12.1, pp. 41–48.\n", "meta": {"hexsha": "e665ea94b9476d415454c5db0385ea0fdc0441ba", "size": 4381, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/fot/FOTC/Program/SortList/Properties/MiscellaneousATP.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": "src/fot/FOTC/Program/SortList/Properties/MiscellaneousATP.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": "src/fot/FOTC/Program/SortList/Properties/MiscellaneousATP.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": 40.9439252336, "max_line_length": 101, "alphanum_fraction": 0.5268203606, "num_tokens": 1517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5506073802837477, "lm_q2_score": 0.6370307944803831, "lm_q1q2_score": 0.35075385690891825}} {"text": "{-# OPTIONS --cubical --safe #-}\n\nmodule DTLC.Base where\n\nopen import Cubical.Foundations.Prelude hiding (Σ; _,_)\nopen import Cubical.Foundations.Function\n\n\n--------------------------------------------------------------------------\n-- Adapted from: Type Theory in Type Theory using Quotient Inductive Types\n-- by Thorsten Altenkirch and Ambrus Kaposi\n-- See: http://www.cs.nott.ac.uk/~psztxa/publ/tt-in-tt.pdf\n--\n-- Note: We have changed a number of names relative to this paper, in the\n-- interest of clarity. In particular, Tms is now _~>_, with the\n-- arguments reversed. Thus, _∘_ (which we call _∘*_) also is reversed\n-- with respect to [AK16]. Furthermore, we renamed π₁ to tail*, π₂\n-- to head*, and app to unlam to make their functions more clear.\n--------------------------------------------------------------------------\n\n\ninfixl 6 _,_\ninfixl 6 _,*_\ninfixr 5 _∘*_\n\nPathPSyntax = PathP\nsyntax PathPSyntax A x y = x ≡[ A ]≡ y\ninfix 2 PathPSyntax\n\n\n\n-----------------\n-- Declarations\n-----------------\n\n-- We will mutually inductively define:\n\n-- The type of contexts\ndata Ctx : Type₀\n\n-- The type of types\ndata Typ : Ctx -> Type₀\n\n-- The type of judgements x : τ ⊣ Γ (\"x has type τ in context Γ\")\nTerm : (Γ : Ctx) -> Typ Γ -> Type₀\nsyntax Term Γ τ = τ ⊣ Γ\n\n-- The type of transformations / generalized subsitutions between contexts\n_~>_ : Ctx -> Ctx -> Type₀\n\n\n-- ...in fact, we define terms and transformations together:\n\ndata TmQV : Type₀ where\n TmV : TmQV\n TrV : TmQV\n\nTmQArg : TmQV -> Ctx -> Type₀\nTmQArg TmV Γ = Typ Γ\nTmQArg TrV _ = Ctx\n\ndata TmQ : (a : TmQV) -> (Γ : Ctx) -> TmQArg a Γ -> Type₀\n\nTerm = TmQ TmV\n_~>_ = TmQ TrV\n\n\n-- Some forward declarations:\nid* : ∀ {Γ} -> Γ ~> Γ\n_∘*_ : ∀ {Γ Δ Σ} -> (Δ ~> Σ) -> (Γ ~> Δ) -> Γ ~> Σ\n_[_]T : ∀ {Γ Δ} (τ : Typ Γ) (f : Γ ~> Δ) -> Typ Δ\n_[_] : ∀ {Γ Δ τ} (x : τ ⊣ Γ) (f : Γ ~> Δ) -> (τ [ f ]T) ⊣ Δ\n\n\n\n----------------\n-- Definitions\n----------------\n\ndata Ctx where\n ∙ : Ctx\n _,_ : (Γ : Ctx) -> Typ Γ -> Ctx\n\n\n-- Unlike Altenkirch-Kaposi, we have a universe of types U:\ndata Typ where\n U : ∀ {Γ} -> Typ Γ\n type : ∀ {Γ} (τ : U ⊣ Γ) -> Typ Γ\n\n\n-- Subsitution on types is defined in terms of substition on terms!\nU [ f ]T = U\n(type τ) [ f ]T = type (τ [ f ])\n\n-- Substitution on types is a functor -- definitions are below\n[id]T : ∀ {Γ} (τ : Typ Γ) -> τ [ id* ]T ≡ τ\n[][]T : ∀ {Γ Δ Σ} (g : Δ ~> Σ) (f : Γ ~> Δ) (τ : Typ Γ)\n -> τ [ f ]T [ g ]T ≡ τ [ g ∘* f ]T\n\n\n-- Having these is quite useful for readibility:\n\ncoeTm : ∀ {Γ} {x y : Typ Γ} -> x ≡ y -> Term Γ x -> Term Γ y\ncoeTm p = transport (cong (Term _) p)\n\ncoeTmTy : ∀ {Γ} {τ σ : Term Γ U} -> τ ≡ σ -> Term Γ (type τ) -> Term Γ (type σ)\ncoeTmTy p = transport (cong (Term _ ∘ type) p)\n\n\n-- We define terms and transformations together\ndata TmQ where\n\n -- Ctx and ~> form a category\n -- Note: these are the definitions of id* and ∘* -- see below\n id*C : ∀ {Γ} -> Γ ~> Γ\n _∘*C_ : ∀ {Γ Δ Σ} -> (Δ ~> Σ) -> (Γ ~> Δ) -> Γ ~> Σ\n \n id*-l : ∀ {Γ Δ} (f : Γ ~> Δ) -> id* ∘* f ≡ f\n id*-r : ∀ {Γ Δ} (f : Γ ~> Δ) -> f ∘* id* ≡ f\n assoc : ∀ {Γ Δ Σ P} (h : Σ ~> P) (g : Δ ~> Σ) (f : Γ ~> Δ)\n -> (h ∘* g) ∘* f ≡ h ∘* (g ∘* f)\n\n -- ~> has a list structure on its first argument\n ∙* : ∀ {Δ} -> ∙ ~> Δ\n _,*_ : ∀ {Γ Δ τ} (f : Γ ~> Δ) (x : Term Δ (τ [ f ]T)) -> (Γ , τ) ~> Δ\n \n tail* : ∀ {Γ Δ τ} (f : (Γ , τ) ~> Δ) -> Γ ~> Δ\n head* : ∀ {Γ Δ τ} (f : (Γ , τ) ~> Δ) -> (τ [ tail* f ]T) ⊣ Δ\n\n ,*-∘* : ∀ {Γ Δ Σ τ} (g : Δ ~> Σ) (f : Γ ~> Δ) (x : Term Δ (τ [ f ]T))\n -> g ∘* (f ,* x) ≡ (g ∘* f) ,* coeTm ([][]T g f τ) (x [ g ])\n\n -- Computation rules for tail* and head*\n tail*-β : ∀ {Γ Δ τ} (f : Γ ~> Δ) (x : Term Δ (τ [ f ]T)) -> tail* (f ,* x) ≡ f\n head*-β : ∀ {Γ Δ τ} (f : Γ ~> Δ) (x : Term Δ (τ [ f ]T))\n -> head* (f ,* x) ≡[ (λ i → (τ [ tail*-β f x i ]T) ⊣ Δ) ]≡ x\n\n -- Uniqueness rules for ~>\n ∙*-η : ∀ {Δ} (f : ∙ ~> Δ) -> f ≡ ∙*\n ,*-η : ∀ {Γ Δ τ} (f : (Γ , τ) ~> Δ) -> (tail* f ,* head* f) ≡ f\n\n -- A useful combinator, defined in terms of the above\n _↑_ : ∀ {Γ Δ} (f : Γ ~> Δ) (τ : Typ Γ) -> (Γ , τ) ~> (Δ , τ [ f ]T)\n ↑-β : ∀ {Γ Δ} (f : Γ ~> Δ) (τ : Typ Γ) -> (Γ , τ) ~> (Δ , τ [ f ]T)\n -> f ↑ τ ≡ (tail* id* ∘* f) ,* coeTm ([][]T (tail* id*) f τ) (head* id*)\n\n\n -- The definition of substitution on terms _[_]\n _[_]C : ∀ {Γ Δ τ} (x : τ ⊣ Γ) (f : Γ ~> Δ) -> (τ [ f ]T) ⊣ Δ\n\n -- Substitution on terms is a functor\n [id] : ∀ {Γ τ} (x : τ ⊣ Γ) -> x [ id* ] ≡[ (λ i → ([id]T τ i) ⊣ Γ) ]≡ x\n [][] : ∀ {Γ Δ Σ τ} (g : Δ ~> Σ) (f : Γ ~> Δ) (x : τ ⊣ Γ)\n -> x [ f ] [ g ] ≡[ (λ i → ([][]T g f τ i) ⊣ Σ) ]≡ x [ g ∘* f ]\n\n -- Pi types and their computation rule for substition\n Π : ∀ {Γ} (τ : Typ Γ) (σ : Typ (Γ , τ)) -> U ⊣ Γ\n Π[] : ∀ {Γ Δ} (τ : Typ Γ) (σ : Typ (Γ , τ)) (f : Γ ~> Δ)\n -> (Π τ σ) [ f ] ≡ Π (τ [ f ]T) (σ [ f ↑ τ ]T)\n\n -- lambdas and their computation rule for substitition\n lam : ∀ {Γ τ σ} (y : σ ⊣ (Γ , τ)) -> type (Π τ σ) ⊣ Γ\n lam[] : ∀ {Γ Δ τ σ} (y : σ ⊣ (Γ , τ)) (f : Γ ~> Δ)\n -> lam y [ f ] ≡[ (λ i → type (Π[] τ σ f i) ⊣ Δ) ]≡ lam (y [ f ↑ τ ])\n\n -- Pi type elim, whose computation rule for substition is derivable using Π-η\n -- (Note: application is defined in terms of this below)\n unlam : ∀ {Γ τ σ} (ℓ : type (Π τ σ) ⊣ Γ) -> σ ⊣ (Γ , τ)\n\n -- Computation and uniqueness for Pi types\n Π-β : ∀ {Γ τ σ} (y : σ ⊣ (Γ , τ)) -> unlam (lam y) ≡ y\n Π-η : ∀ {Γ τ σ} (ℓ : type (Π τ σ) ⊣ Γ) -> lam (unlam ℓ) ≡ ℓ\n\n-- The missing substitution computation rule for unlam, derivable because we have definitional η!\nunlam[] : ∀ {Γ Δ τ σ} (ℓ : type (Π τ σ) ⊣ Γ) (f : Γ ~> Δ)\n -> unlam ℓ [ f ↑ τ ] ≡ unlam (coeTmTy (Π[] τ σ f) (ℓ [ f ]))\nunlam[] {Γ} {Δ} {τ} {σ} ℓ f =\n (unlam ℓ) [ f ↑ τ ] ≡[ i ]⟨ Π-β ((unlam ℓ) [ f ↑ τ ]) (~ i) ⟩\n unlam (lam ((unlam ℓ) [ f ↑ τ ])) ≡[ i ]⟨ unlam (fromPathP (lam[] (unlam ℓ) f) (~ i)) ⟩\n unlam (coeTmTy (Π[] τ σ f) ((lam (unlam ℓ)) [ f ])) ≡[ i ]⟨ unlam (coeTmTy (Π[] τ σ f) ((Π-η ℓ i) [ f ])) ⟩\n unlam (coeTmTy (Π[] τ σ f) (ℓ [ f ])) ∎\n\n-- Missing definitions from above\n[id]T U = refl\n[id]T (type τ) = cong type ([id] τ)\n[][]T g f U = refl\n[][]T g f (type τ) = cong type ([][] g f τ)\nid* = id*C\n_∘*_ = _∘*C_\n_[_] = _[_]C\n\n\n\n--------------------\n-- Derived Notions\n--------------------\n\n-- Weakening on contexts\nwkn : ∀ {Γ τ} -> Γ ~> (Γ , τ)\nwkn = tail* id*\n\n-- A single substition at the top of a context\n<_> : ∀ {Γ τ} (x : τ ⊣ Γ) -> (Γ , τ) ~> Γ\n< x > = id* ,* coeTm (sym ([id]T _)) x\n\n-- Using substition, we can now write the usual definition of application\n_$_ : ∀ {Γ τ σ} (ℓ : (type (Π τ σ)) ⊣ Γ) (x : τ ⊣ Γ) -> (σ [ < x > ]T) ⊣ Γ\nℓ $ x = unlam ℓ [ < x > ]\ninfixl 4 _$_\n\n-- Variables (as de Bruijn indices) are also derived!\n\nvar₀ : ∀ {Γ τ} -> (τ [ wkn ]T) ⊣ (Γ , τ)\nvar₀ = head* id*\n\nvar₊ : ∀ {Γ τ σ} -> τ ⊣ Γ -> (τ [ wkn ]T) ⊣ (Γ , σ)\nvar₊ x = x [ wkn ]\n\nvar₁ : ∀ {Γ τ σ} -> (τ [ wkn ]T [ wkn ]T) ⊣ ((Γ , τ) , σ)\nvar₁ = var₊ var₀\n\nvar₂ : ∀ {Γ τ σ ρ} -> (τ [ wkn ]T [ wkn ]T [ wkn ]T) ⊣ (((Γ , τ) , σ) , ρ)\nvar₂ = var₊ var₁\n\n-- The other classical operations on contexts:\n\nctr : ∀ {Γ τ} -> (Γ , τ , τ [ wkn ]T) ~> (Γ , τ)\nctr {Γ} {τ} = id* ,* coeTm (sym p) var₀\n where p : τ [ wkn ]T [ id* ]T ≡ τ [ tail* id* ]T\n p = \n τ [ wkn ]T [ id* ]T ≡⟨ [][]T id* wkn _ ⟩\n τ [ id* ∘* wkn ]T ≡⟨ cong (τ [_]T) (id*-l wkn) ⟩\n τ [ tail* id* ]T ∎\n\n-- exg : ∀ {Γ τ σ} -> (Γ , τ , σ [ wkn ]T) ~> (Γ , σ , τ [ wkn ]T)\n-- exg {Γ} {τ} {σ} = wkn ∘* wkn ,*\n-- coeTm ([][]T wkn wkn τ) var₀ ,*\n-- coeTm (sym p) (coeTm ([][]T wkn wkn σ) var₁)\n-- where p : σ [ wkn ]T [ (wkn ∘* wkn) ,* coeTm ([][]T wkn wkn τ) var₀ ]T ≡ σ [ wkn ∘* wkn ]T\n-- p = begin\n-- σ [ wkn ]T [ (wkn ∘* wkn) ,* coeTm ([][]T wkn wkn τ) var₀ ]T ≡⟨ [][]T _ _ σ ⟩\n-- σ [ ((wkn ∘* wkn) ,* coeTm ([][]T wkn wkn τ) var₀) ∘* wkn ]T ≡⟨ cong (σ [_]T) {!!} ⟩\n-- σ [ wkn ∘* wkn ]T ∎\n-- -- p' : (wkn ∘* wkn) ,* coeTm ([][]T wkn wkn τ) var₁ ≡ wkn\n-- -- p' = begin\n-- -- (wkn ∘* wkn) ,* coeTm ([][]T wkn wkn τ) var₁ ≡⟨ sym (,*-∘* wkn wkn var₀) ⟩\n-- -- wkn ∘* (wkn ,* var₀) ≡⟨ cong (wkn ∘*_) (,*-η id*) ⟩\n-- -- wkn ∘* id* ≡⟨ id*-r wkn ⟩\n-- -- wkn ∎\n\n\n\n--------------------------------------\n-- Experimental: Encoding more types\n--------------------------------------\n\n_⇒_ : ∀ {Γ} (τ : U ⊣ Γ) (σ : U ⊣ (Γ , type τ)) -> U ⊣ Γ\nx ⇒ y = Π (type x) (type y)\ninfixr 4 _⇒_\n\n-- The natural number type\n\nN : ∀ {Γ} -> U ⊣ Γ\nN = Π U (type (var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂))\n\n-- N[] : ∀ {Γ Δ} (f : Γ ~> Δ) -> type N [ f ]T ≡ type N\n-- N[] f = cong type p\n-- where p : Π U (type (var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂)) [ f ] ≡ Π U (type (var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂))\n-- p = begin\n-- Π U (type (var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂)) [ f ] ≡⟨ Π[] _ _ f ⟩\n-- Π U (type ((var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂) [ f ↑ U ])) ≡⟨ {!!} ⟩\n-- Π U (type (var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂)) ∎\n\nz : ∀ {Γ} -> type N ⊣ Γ\nz = lam (lam (lam var₁))\n\n-- s : ∀ {Γ} (n : type N ⊣ Γ) -> type N ⊣ Γ\n-- s {Γ} n = lam (lam (lam {!!})) -- var₀ $ (n' $ var₀ $ var₁ $ var₂)\n-- where n' : type N ⊣ (((Γ , U) , type var₀) , type (var₁ ⇒ var₂))\n-- n' = coe (cong (Term _) {!!}) (var₊ (var₊ (var₊ n)))\n\n-- The dependent pair type\n\n-- Σ : ∀ {Γ} (τ : Typ Γ) (σ : Typ (Γ , τ)) -> U ⊣ Γ\n-- Σ τ σ = Π U (type ((Π (τ [ tail* id* ]T) (type (Π (σ [ tail* id* ↑ τ ]T) (type var₂)))) ⇒ var₀))\n\n-- pair : ∀ {Γ τ σ} (x : τ ⊣ Γ) (y : σ ⊣ (Γ , τ)) -> (type (Σ τ σ)) ⊣ Γ\n-- pair x y = lam (lam {!!})\n\n\n -- Σ : ∀ {Γ} (τ : Typ Γ) (σ : Typ (Γ , τ)) -> U ⊣ Γ\n -- Σ[] : ∀ {Γ Δ} (τ : Typ Γ) (σ : Typ (Γ , τ)) (f : Γ ~> Δ)\n -- -> (Σ τ σ) [ f ] ≡ Σ (τ [ f ]T) (σ [ f ↑ τ ]T)\n\n -- pair : ∀ {Γ τ σ} (x : τ ⊣ Γ) (y : σ ⊣ (Γ , τ)) -> (type (Σ τ σ)) ⊣ Γ\n -- pair[] : ∀ {Γ Δ τ σ} (x : τ ⊣ Γ) (y : σ ⊣ (Γ , τ)) (f : Γ ~> Δ)\n -- -> (pair x y) [ f ] ≡[ (λ i → type (Σ[] τ σ f i) ⊣ Δ) ]≡ pair (x [ f ]) (y [ f ↑ τ ])\n \n -- Σ-ind : ∀ {Γ τ σ} (ρ : Typ (Γ , type (Σ τ σ)))\n -- (xy : (ρ [ {!!} ∘* ({!!} ↑ type (Σ τ σ)) ]T) ⊣ ((Γ , τ) , σ))\n -- -> ρ ⊣ (Γ , type (Σ τ σ))\n", "meta": {"hexsha": "ea772fd0dbf7a2b704f9e3284438f684b7ab22fe", "size": 10208, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "data/github.com/m-yac/tt-in-cagda/d2c1c36cb3e09d8c3c73b8a043dbe36865765bce/src/DTLC/Base.agda", "max_stars_repo_name": "ajnavarro/language-dataset", "max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-08-07T11:54:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T09:48:45.000Z", "max_issues_repo_path": "data/github.com/m-yac/tt-in-cagda/d2c1c36cb3e09d8c3c73b8a043dbe36865765bce/src/DTLC/Base.agda", "max_issues_repo_name": "ajnavarro/language-dataset", "max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 91, "max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z", "max_forks_repo_path": "data/github.com/m-yac/tt-in-cagda/d2c1c36cb3e09d8c3c73b8a043dbe36865765bce/src/DTLC/Base.agda", "max_forks_repo_name": "ajnavarro/language-dataset", "max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-11-13T12:44:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T19:34:26.000Z", "avg_line_length": 33.8013245033, "max_line_length": 109, "alphanum_fraction": 0.4290752351, "num_tokens": 4558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6150878696277512, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.3505094533600594}} {"text": "------------------------------------------------------------------------\n-- M-types for indexed containers, defined coinductively (in Cubical\n-- Agda)\n------------------------------------------------------------------------\n\n{-# OPTIONS --erased-cubical --safe --guardedness #-}\n\nimport Equality.Path as P\n\nmodule Container.Indexed.M.Codata\n {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where\n\nopen P.Derived-definitions-and-properties eq\n\nopen import Logical-equivalence using (_⇔_)\nopen import Prelude\n\nopen import Bijection equality-with-J using (_↔_)\nopen import Container.Indexed equality-with-J\nimport Container.Indexed.M.Function equality-with-J as F\nimport Container.Indexed.Variant equality-with-J as V\nopen import Container.Indexed.Variant.M.Codata eq as VM using (out-M)\nopen import Equality.Path.Isomorphisms eq\nopen import Equivalence equality-with-J as Eq using (_≃_)\nopen import Function-universe equality-with-J hiding (id; _∘_)\nopen import H-level equality-with-J\nopen import H-level.Closure equality-with-J\nopen import Univalence-axiom equality-with-J\n\nprivate\n variable\n a iℓ s p : Level\n A I : Type a\n i x : A\n C : Container I s p\n n : ℕ\n\n------------------------------------------------------------------------\n-- The M-type and some basic results\n\n-- An M-type for a given container.\n--\n-- This definition is similar to one in \"Indexed containers\" by\n-- Altenkirch, Ghani, Hancock, McBride and Morris.\n\nrecord M {I : Type iℓ} (C : Container I s p) (i : I) :\n Type (iℓ ⊔ s ⊔ p) where\n coinductive\n constructor in-M\n field\n out-M : ⟦ C ⟧ (M C) i\n\nopen M public\n\n-- An η-law.\n\nη : in-M (out-M x) ≡ x\nη = _↔_.from ≡↔≡ η′\n where\n η′ : in-M (out-M x) P.≡ x\n η′ {x = x} _ .out-M = x .out-M\n\n-- M C is, in a certain sense, a fixpoint of ⟦ C ⟧.\n\nM-fixpoint : ⟦ C ⟧ (M C) i ≃ M C i\nM-fixpoint = Eq.↔→≃ in-M out-M (λ _ → η) refl\n\n-- A coalgebra defined using M and out-M.\n\nM-coalgebra : (C : Container I s p) → Coalgebra C\nM-coalgebra C = M C , λ _ → out-M\n\n------------------------------------------------------------------------\n-- Some conversion lemmas\n\n-- One can convert between M and VM.M.\n\nM≃M :\n ∀ p {I : Type i} {C : V.Container I s (i ⊔ p)} {i} →\n M (_⇔_.to (V.Container⇔Container p) C) i ≃ VM.M C i\nM≃M p {C = C} =\n Eq.↔→≃ to from\n (λ c → _↔_.from ≡↔≡ (to-from c))\n (λ c → _↔_.from ≡↔≡ (from-to c))\n where\n to : M (_⇔_.to (V.Container⇔Container p) C) i → VM.M C i\n to x .out-M .proj₁ = x .out-M .proj₁\n to x .out-M .proj₂ i p = to (x .out-M .proj₂ (i , p))\n\n from : VM.M C i → M (_⇔_.to (V.Container⇔Container p) C) i\n from x .out-M .proj₁ = x .out-M .proj₁\n from x .out-M .proj₂ (i , p) = from (x .out-M .proj₂ i p)\n\n to-from : (x : VM.M C i) → to (from x) P.≡ x\n to-from x i .out-M .proj₁ = x .out-M .proj₁\n to-from x i .out-M .proj₂ j p = to-from (x .out-M .proj₂ j p) i\n\n from-to :\n (x : M (_⇔_.to (V.Container⇔Container p) C) i) →\n from (to x) P.≡ x\n from-to x i .out-M .proj₁ = x .out-M .proj₁\n from-to x i .out-M .proj₂ p = from-to (x .out-M .proj₂ p) i\n\n-- M-coalgebra is related to VM.M-coalgebra (assuming univalence).\n\nM-coalgebra≡M-coalgebra :\n ∀ p {I : Type i} (C : V.Container I s (i ⊔ p)) →\n Univalence (i ⊔ s ⊔ p) →\n M-coalgebra (_⇔_.to (V.Container⇔Container p) C) ≡\n _≃_.to (V.Coalgebra≃Coalgebra p C ext) (VM.M-coalgebra C)\nM-coalgebra≡M-coalgebra p C univ =\n Σ-≡,≡→≡\n (⟨ext⟩ lemma₁)\n (⟨ext⟩ λ i → ⟨ext⟩ λ x →\n\n subst (λ P → P ⇾ ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P)\n (⟨ext⟩ lemma₁) (λ _ → out-M) i x ≡⟨ cong (_$ x) $ sym $\n push-subst-application _ _ ⟩\n subst (λ P → P i → ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P i)\n (⟨ext⟩ lemma₁) out-M x ≡⟨ subst-→ ⟩\n\n subst (λ P → ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P i)\n (⟨ext⟩ lemma₁)\n (subst (_$ i) (sym (⟨ext⟩ lemma₁)) x .out-M) ≡⟨ cong (subst (λ P → ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P i) _) $\n cong out-M $\n cong (flip (subst (_$ i)) _) $ sym $\n ext-sym lemma₁ ⟩\n subst (λ P → ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P i)\n (⟨ext⟩ lemma₁)\n (subst (_$ i) (⟨ext⟩ (sym ∘ lemma₁)) x .out-M) ≡⟨ cong (subst (λ P → ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P i) _) $\n cong out-M $\n subst-ext id (sym ∘ lemma₁) ⟩\n subst (λ P → ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P i)\n (⟨ext⟩ lemma₁)\n (subst id (sym (lemma₁ i)) x .out-M) ≡⟨ cong (subst (λ P → ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P i) _) $\n cong out-M $\n subst-id-in-terms-of-inverse∘≡⇒↝ equivalence {A≡B = lemma₁ i} ⟩\n subst (λ P → ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P i)\n (⟨ext⟩ lemma₁)\n (_≃_.from (≡⇒≃ (lemma₁ i)) x .out-M) ≡⟨ cong (subst (λ P → ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P i) _) $\n cong (λ (eq : M (_⇔_.to (V.Container⇔Container p) C) i ≃ VM.M C i) →\n _≃_.from eq x .out-M) $\n _≃_.right-inverse-of (≡≃≃ univ) _ ⟩\n subst (λ P → ⟦ _⇔_.to (V.Container⇔Container p) C ⟧ P i)\n (⟨ext⟩ lemma₁)\n (_≃_.from (M≃M p {i = i}) x .out-M) ≡⟨⟩\n\n subst (λ P → ∃ λ (s : V.Shape C i) →\n ((i , _) : ∃ (V.Position C s)) → P i)\n (⟨ext⟩ lemma₁)\n (_≃_.from (M≃M p {i = i}) x .out-M) ≡⟨ push-subst-pair-× _ _ ⟩\n\n ( x .out-M .proj₁\n , subst (λ P → ((i , _) : ∃ (V.Position C (x .out-M .proj₁))) →\n P i)\n (⟨ext⟩ lemma₁)\n (_≃_.from (M≃M p {i = i}) x .out-M .proj₂)\n ) ≡⟨ cong (x .out-M .proj₁ ,_) $\n ⟨ext⟩ (lemma₃ i x) ⟩∎\n Σ-map id uncurry (x .out-M) ∎)\n where\n lemma₁ = λ _ → ≃⇒≡ univ (M≃M p)\n\n lemma₂ : ∀ _ _ _ → _\n lemma₂ _ _ p =\n sym (Σ-≡,≡→≡ (sym (⟨ext⟩ lemma₁)) (refl p′)) ≡⟨ cong sym $ cong (Σ-≡,≡→≡ (sym (⟨ext⟩ lemma₁))) $ sym $\n trans-symʳ _ ⟩\n sym (Σ-≡,≡→≡ (sym (⟨ext⟩ lemma₁))\n (trans (subst-const _) (sym (subst-const _)))) ≡⟨ cong sym $ Σ-≡,≡→≡-subst-const _ _ ⟩\n\n sym (cong₂ _,_ (sym (⟨ext⟩ lemma₁)) (sym (subst-const _))) ≡⟨ cong sym cong₂-sym ⟩\n\n sym (sym (cong₂ _,_ (⟨ext⟩ lemma₁) (subst-const _))) ≡⟨ sym-sym _ ⟩∎\n\n cong₂ _,_ (⟨ext⟩ lemma₁) (subst-const _) ∎\n where\n p′ = subst (const _) (sym (⟨ext⟩ lemma₁)) p\n\n lemma₃ : ∀ _ _ _ → _\n lemma₃ i x (i′ , p′) =\n subst (λ P → ((i , _) : ∃ _) → P i)\n (⟨ext⟩ lemma₁)\n (_≃_.from (M≃M p {i = i}) x .out-M .proj₂)\n (i′ , p′) ≡⟨ subst-∀ ⟩\n\n subst (λ ((P , i , _) : _ × ∃ _) → P i)\n (sym $ Σ-≡,≡→≡ (sym (⟨ext⟩ lemma₁)) (refl _))\n (_≃_.from (M≃M p {i = i}) x .out-M .proj₂ $\n subst (const _) (sym (⟨ext⟩ lemma₁)) (i′ , p′)) ≡⟨ cong (flip (subst (λ ((P , i , _) : _ × ∃ _) → P i)) _) $\n lemma₂ i x _ ⟩\n subst (λ ((P , i , _) : _ × ∃ _) → P i)\n (cong₂ _,_ (⟨ext⟩ lemma₁) (subst-const _))\n (_≃_.from (M≃M p {i = i}) x .out-M .proj₂ $\n subst (const _) (sym (⟨ext⟩ lemma₁)) (i′ , p′)) ≡⟨ elim₁\n (λ {q} eq →\n subst (λ ((P , i , _) : _ × ∃ _) → P i)\n (cong₂ _,_ (⟨ext⟩ lemma₁) eq)\n (_≃_.from (M≃M p {i = i}) x .out-M .proj₂ q) ≡\n subst (λ ((P , i , _) : _ × ∃ (V.Position C (x .out-M .proj₁))) → P i)\n (cong₂ {u = i′ , p′} _,_ (⟨ext⟩ lemma₁) (refl _))\n (_≃_.from (M≃M p {i = i}) x .out-M .proj₂ (i′ , p′)))\n (refl _)\n _ ⟩\n subst (λ ((P , i , _) : _ × ∃ _) → P i)\n (cong₂ _,_ (⟨ext⟩ lemma₁) (refl _))\n (_≃_.from (M≃M p {i = i}) x .out-M .proj₂ (i′ , p′)) ≡⟨ cong (flip (subst (λ ((P , i , _) : _ × ∃ _) → P i)) _) $\n cong₂-reflʳ _ ⟩\n subst (λ ((P , i , _) : _ × ∃ _) → P i)\n (cong (_, i′ , p′) (⟨ext⟩ lemma₁))\n (_≃_.from (M≃M p {i = i}) x .out-M .proj₂ (i′ , p′)) ≡⟨ sym $ subst-∘ _ _ _ ⟩\n\n subst (_$ i′) (⟨ext⟩ lemma₁)\n (_≃_.from (M≃M p {i = i}) x .out-M .proj₂ (i′ , p′)) ≡⟨ subst-ext _ _ ⟩\n\n subst id (lemma₁ i′)\n (_≃_.from (M≃M p {i = i}) x .out-M .proj₂ (i′ , p′)) ≡⟨⟩\n\n subst id (≃⇒≡ univ (M≃M p {i = i′}))\n (_≃_.from (M≃M p {i = i′}) (x .out-M .proj₂ i′ p′)) ≡⟨ subst-id-in-terms-of-≡⇒↝ equivalence ⟩\n\n _≃_.to (≡⇒≃ (≃⇒≡ univ (M≃M p {i = i′})))\n (_≃_.from (M≃M p {i = i′}) (x .out-M .proj₂ i′ p′)) ≡⟨ cong (λ eq → _≃_.to eq (_≃_.from (M≃M p {i = i′}) (x .out-M .proj₂ i′ p′))) $\n _≃_.right-inverse-of (≡≃≃ univ) _ ⟩\n _≃_.to (M≃M p {i = i′})\n (_≃_.from (M≃M p {i = i′}) (x .out-M .proj₂ i′ p′)) ≡⟨ _≃_.right-inverse-of (M≃M p {i = i′}) _ ⟩\n\n x .out-M .proj₂ i′ p′ ≡⟨⟩\n\n Σ-map id uncurry (x .out-M) .proj₂ (i′ , p′) ∎\n\n------------------------------------------------------------------------\n-- Lemmas related to lift-positions\n\n-- Lifting the position type family using lift-positions does not\n-- affect the resulting M type (up to pointwise equivalence).\n\nM≃M-lift-positions : M C i ≃ M (lift-positions C) i\nM≃M-lift-positions =\n Eq.↔→≃ to from\n (λ c → _↔_.from ≡↔≡ (to-from c))\n (λ c → _↔_.from ≡↔≡ (from-to c))\n where\n to : M C i → M (lift-positions C) i\n to x .out-M .proj₁ = x .out-M .proj₁\n to x .out-M .proj₂ (lift p) = to (x .out-M .proj₂ p)\n\n from : M (lift-positions C) i → M C i\n from x .out-M .proj₁ = x .out-M .proj₁\n from x .out-M .proj₂ p = from (x .out-M .proj₂ (lift p))\n\n to-from : (x : M (lift-positions C) i) → to (from x) P.≡ x\n to-from x i .out-M .proj₁ = x .out-M .proj₁\n to-from x i .out-M .proj₂ p = to-from (x .out-M .proj₂ p) i\n\n from-to : (x : M C i) → from (to x) P.≡ x\n from-to x i .out-M .proj₁ = x .out-M .proj₁\n from-to x i .out-M .proj₂ p = from-to (x .out-M .proj₂ p) i\n\n-- M-coalgebra C is related to M-coalgebra (lift-positions C)\n-- (assuming univalence).\n\n≡M-coalgebra-lift-positions :\n {I : Type i} {C : Container I s p} →\n Univalence (i ⊔ s ⊔ p) →\n Coalgebra≃Coalgebra-lift-positions _ (M-coalgebra C) ≡\n M-coalgebra (lift-positions C)\n≡M-coalgebra-lift-positions {C = C} univ =\n Σ-≡,≡→≡\n (⟨ext⟩ lemma)\n (⟨ext⟩ λ i → ⟨ext⟩ λ x →\n\n subst (λ P → P ⇾ ⟦ lift-positions C ⟧ P)\n (⟨ext⟩ lemma)\n ((Σ-map id (_∘ lower) ∘_) ∘ (λ _ → out-M))\n i x ≡⟨ cong (_$ x) $ sym $\n push-subst-application _ _ ⟩\n subst (λ P → P i → ⟦ lift-positions C ⟧ P i)\n (⟨ext⟩ lemma) (Σ-map id (_∘ lower) ∘ out-M) x ≡⟨ subst-→ ⟩\n\n subst (λ P → ⟦ lift-positions C ⟧ P i)\n (⟨ext⟩ lemma)\n (Σ-map id (_∘ lower) $\n subst (_$ i) (sym (⟨ext⟩ lemma)) x .out-M) ≡⟨ cong (subst (λ P → ⟦ lift-positions C ⟧ P i) _) $\n cong (Σ-map id (_∘ lower)) $ cong out-M $\n cong (flip (subst (_$ i)) _) $ sym $\n ext-sym lemma ⟩\n subst (λ P → ⟦ lift-positions C ⟧ P i)\n (⟨ext⟩ lemma)\n (Σ-map id (_∘ lower) $\n subst (_$ i) (⟨ext⟩ (sym ∘ lemma)) x .out-M) ≡⟨ cong (subst (λ P → ⟦ lift-positions C ⟧ P i) _) $\n cong (Σ-map id (_∘ lower)) $ cong out-M $\n subst-ext id (sym ∘ lemma) ⟩\n subst (λ P → ⟦ lift-positions C ⟧ P i)\n (⟨ext⟩ lemma)\n (Σ-map id (_∘ lower) $\n subst id (sym (lemma i)) x .out-M) ≡⟨ cong (subst (λ P → ⟦ lift-positions C ⟧ P i) _) $\n cong (Σ-map id (_∘ lower)) $ cong out-M $\n subst-id-in-terms-of-inverse∘≡⇒↝ equivalence {A≡B = lemma i} ⟩\n subst (λ P → ⟦ lift-positions C ⟧ P i)\n (⟨ext⟩ lemma)\n (Σ-map id (_∘ lower) $\n _≃_.from (≡⇒≃ (lemma i)) x .out-M) ≡⟨ cong (subst (λ P → ⟦ lift-positions C ⟧ P i) _) $\n cong (λ (eq : M C i ≃ M (lift-positions C) i) →\n Σ-map id (_∘ lower) (_≃_.from eq x .out-M)) $\n _≃_.right-inverse-of (≡≃≃ univ) _ ⟩\n subst (λ P → ⟦ lift-positions C ⟧ P i)\n (⟨ext⟩ lemma)\n (Σ-map id (_∘ lower) $\n _≃_.from M≃M-lift-positions x .out-M) ≡⟨⟩\n\n subst (λ P → ⟦ lift-positions C ⟧ P i)\n (⟨ext⟩ lemma)\n ( x .out-M .proj₁\n , _≃_.from M≃M-lift-positions ∘ x .out-M .proj₂\n ) ≡⟨ (cong (subst (λ P → ⟦ lift-positions C ⟧ P i) _) $ cong (_ ,_) $\n ⟨ext⟩ λ p →\n cong (λ eq → _≃_.from eq (x .out-M .proj₂ p)) $ sym $\n _≃_.right-inverse-of (≡≃≃ univ) _) ⟩\n subst (λ P → ⟦ lift-positions C ⟧ P i)\n (⟨ext⟩ lemma)\n ( x .out-M .proj₁\n , _≃_.from (≡⇒≃ (lemma _)) ∘ x .out-M .proj₂\n ) ≡⟨ (cong (subst (λ P → ⟦ lift-positions C ⟧ P i) _) $ cong (_ ,_) $\n ⟨ext⟩ λ p →\n cong (λ (f : ∀ i → M C i ≡ M (lift-positions C) i) →\n _≃_.from (≡⇒≃ (f _)) (x .out-M .proj₂ p)) $ sym $\n _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) _) ⟩\n subst (λ P → ⟦ lift-positions C ⟧ P i)\n (⟨ext⟩ lemma)\n ( x .out-M .proj₁\n , _≃_.from (≡⇒≃ (ext⁻¹ (⟨ext⟩ lemma) _)) ∘ x .out-M .proj₂\n ) ≡⟨ elim₁\n (λ eq →\n subst (λ P → ⟦ lift-positions C ⟧ P i)\n eq\n ( x .out-M .proj₁\n , _≃_.from (≡⇒≃ (ext⁻¹ eq _)) ∘ x .out-M .proj₂\n ) ≡\n x .out-M)\n (\n subst (λ P → ⟦ lift-positions C ⟧ P i)\n (refl _)\n ( x .out-M .proj₁\n , _≃_.from (≡⇒≃ (ext⁻¹ (refl (M (lift-positions C))) _)) ∘\n x .out-M .proj₂\n ) ≡⟨ subst-refl _ _ ⟩\n\n x .out-M .proj₁\n , _≃_.from (≡⇒≃ (ext⁻¹ (refl (M (lift-positions C))) _)) ∘\n x .out-M .proj₂ ≡⟨ (cong (_ ,_) $ ⟨ext⟩ λ p →\n cong (λ eq → _≃_.from eq (x .out-M .proj₂ p)) $\n trans (cong ≡⇒≃ $ ext⁻¹-refl (M (lift-positions C))) $\n ≡⇒↝-refl) ⟩∎\n x .out-M ∎)\n (⟨ext⟩ lemma) ⟩∎\n x .out-M ∎)\n where\n lemma = λ _ → ≃⇒≡ univ M≃M-lift-positions\n\n------------------------------------------------------------------------\n-- Finality\n\nprivate\n\n -- M-coalgebra C is sometimes a final coalgebra (assuming\n -- univalence). Note that the last index argument of C is not\n -- unrestricted.\n\n M-final′ :\n ∀ p {I : Type i} {C : Container I s (i ⊔ p)} →\n Univalence (i ⊔ s ⊔ p) →\n Univalence (i ⊔ p) →\n Final′ (M-coalgebra C)\n M-final′ p {C = C} univ₁ univ₂ = $⟨ VM.M-final′ C′ ⟩\n V.Final′ (VM.M-coalgebra C′) ↝⟨ subst V.Final′ $ sym $ _≃_.to-from C≃C $ sym $\n M-coalgebra≡M-coalgebra p C′ univ₁ ⟩\n V.Final′ (_≃_.from C≃C (M-coalgebra (_⇔_.to C⇔C C′))) ↔⟨ V.Final′≃Final′ p C′ ext ext\n (_≃_.from C≃C (M-coalgebra (_⇔_.to C⇔C C′))) ⟩\n Final′ (_≃_.to C≃C $ _≃_.from C≃C $ M-coalgebra (_⇔_.to C⇔C C′)) ↝⟨ subst Final′ (_≃_.right-inverse-of C≃C (M-coalgebra (_⇔_.to C⇔C C′))) ⟩\n Final′ (M-coalgebra (_⇔_.to C⇔C C′)) ↝⟨ subst (Final′ ∘ M-coalgebra) $\n _≃_.right-inverse-of (V.Container≃Container p ext univ₂) _ ⟩□\n Final′ (M-coalgebra C) □\n where\n C⇔C = V.Container⇔Container p\n C′ = _⇔_.from C⇔C C\n C≃C = V.Coalgebra≃Coalgebra p C′ ext\n\n -- M-coalgebra C is sometimes a final coalgebra (assuming univalence).\n -- Note that the last index argument of C is not unrestricted.\n\n M-final″ :\n ∀ p {I : Type i} {C : Container I s (i ⊔ p)} →\n Univalence (i ⊔ s ⊔ p) →\n Univalence (i ⊔ p) →\n Final (M-coalgebra C)\n M-final″ p {C = C} univ₁ univ₂ =\n block λ b →\n Final′→Final\n ext\n ( F.M-coalgebra b ext C\n , F.M-final b ext ext\n )\n ( M-coalgebra C\n , M-final′ p univ₁ univ₂\n )\n\n-- M-coalgebra C is a final coalgebra (assuming univalence).\n--\n-- TODO: Can this be proved directly, without using VM.M-final′ or\n-- univalence?\n\nM-final :\n {I : Type i} {C : Container I s p} →\n Univalence (i ⊔ s ⊔ p) →\n Univalence (i ⊔ p) →\n Final (M-coalgebra C)\nM-final {p = p} {C = C} univ₁ univ₂ = $⟨ M-final″ p univ₁ univ₂ ⟩\n Final (M-coalgebra (lift-positions C)) ↔⟨⟩\n\n (∀ Y → Contractible (Y ⇨ M-coalgebra (lift-positions C))) ↝⟨ (Π-cong-contra-→ (Coalgebra≃Coalgebra-lift-positions _) λ Y →\n H-level-cong _ 0 (\n Coalgebra≃Coalgebra-lift-positions _ Y ⇨\n M-coalgebra (lift-positions C) ↝⟨ ≡⇒↝ _ $ cong (Coalgebra≃Coalgebra-lift-positions _ Y ⇨_) $ sym $\n ≡M-coalgebra-lift-positions univ₁ ⟩\n Coalgebra≃Coalgebra-lift-positions _ Y ⇨\n Coalgebra≃Coalgebra-lift-positions _ (M-coalgebra C) ↝⟨ inverse $ ⇨≃⇨-lift-positions ext _ (M-coalgebra C) ⟩□\n\n Y ⇨ M-coalgebra C □)) ⟩\n\n (∀ Y → Contractible (Y ⇨ M-coalgebra C)) ↔⟨⟩\n\n Final (M-coalgebra C) □\n\n------------------------------------------------------------------------\n-- H-levels\n\n-- If the shape types of C have h-level n, then M C i has h-level n\n-- (assuming univalence).\n\nH-level-M :\n {I : Type i} {C : Container I s p} →\n Univalence (i ⊔ s ⊔ p) →\n Univalence (i ⊔ p) →\n (∀ i → H-level n (Shape C i)) →\n ∀ {i} → H-level n (M C i)\nH-level-M {C = C} univ₁ univ₂ h =\n F.H-level-final-coalgebra\n ext\n (M-coalgebra C , M-final univ₁ univ₂)\n h\n", "meta": {"hexsha": "f576746780015e274a6cf4b7789ee97ae471cfdf", "size": 21814, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Container/Indexed/M/Codata.agda", "max_stars_repo_name": "nad/equality", "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_issues_repo_path": "src/Container/Indexed/M/Codata.agda", "max_issues_repo_name": "nad/equality", "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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/Container/Indexed/M/Codata.agda", "max_forks_repo_name": "nad/equality", "max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "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.3680709534, "max_line_length": 144, "alphanum_fraction": 0.3775556982, "num_tokens": 6907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.35050944531847844}} {"text": "{-# OPTIONS --without-K --rewriting #-}\n\nmodule Flat where\n open import lib.Basics\n open import Basics\n open import Bool\n\n open import lib.types.Bool\n open import lib.NType2\n open import lib.Equivalence2\n open import lib.types.Suspension\n open import lib.types.IteratedSuspension\n open import lib.types.Pushout as Pushout\n open import lib.types.Truncation\n\n -- The type of points of A, ♭ A, is inductively generated by the crisp elements of A\n data ♭ {@♭ l : ULevel} (@♭ A : Type l) : Type l where\n _^♭ : A ::→ ♭ A\n\n -- The deduced mapping principle of ♭ A: it represents crisp functions.\n ♭-elim : {c : ULevel} {@♭ l : ULevel}{@♭ A : Type l}\n → (C : ♭ A → Type c)\n → ((@♭ u : A) → C (u ^♭))\n → (x : ♭ A) → C x\n ♭-elim C f (x ^♭) = f x\n syntax ♭-elim C (λ u → t) a = let♭ u ^♭:= a in♭ t in-family C\n\n {- Mike's \"let\" notation (following Felix) -}\n -- An implicit version of ♭-elim\n let♭ : {@♭ i j : ULevel} {@♭ A : Type i} {B : ♭ A → Type j}\n (a : ♭ A) (f : (@♭ u : A) → B (u ^♭))\n → B a\n let♭ (u ^♭) f = f u\n syntax let♭ a (λ u → t) = let♭ u ^♭:= a in♭ t\n\n\n ♭-rec : {@♭ i : ULevel} {j : ULevel} {@♭ A : Type i} {B : Type j}\n → (A ::→ B) → (♭ A) → B\n ♭-rec f (a ^♭) = f a\n\n ♭-rec-eq : {@♭ i : ULevel} {j : ULevel} {@♭ A : Type i} {B : Type j}\n → (A ::→ B) ≃ (♭ A → B)\n ♭-rec-eq {A = A} {B = B} =\n equiv ♭-rec\n (λ f → λ (@♭ a : A) → f (a ^♭)) -- fro\n (λ f → λ= (λ { (a ^♭) → refl })) -- to-fro\n (λ f → refl) -- fro-to\n\n -- Crisp function types, but from A : ♭ Type\n _♭:→_ : {@♭ i : ULevel} {j : ULevel} (A : ♭ (Type i)) (B : Type j) → Type (lmax i j)\n (A ^♭) ♭:→ B = A ::→ B \n\n -- The inclusion of the points of A into A\n _↓♭ : {@♭ i : ULevel} {@♭ A : Type i} → (♭ A → A)\n _↓♭ (x ^♭) = x\n \n\n -- The (judgemental) computation rule for mapping out of points\n ♭-β : {@♭ i : ULevel} {@♭ A : Type i} (@♭ a : ♭ A)\n → ((a ↓♭) ^♭) == a\n ♭-β (a ^♭) = refl\n\n -- Application of crisp functions to crisp equalities\n -- Used mostly to apply _^♭.\n ♭-ap : {@♭ i j : ULevel} {@♭ A : Type i} {B : Type j}\n (f : (@♭ a : A) → B) {@♭ x y : A} (@♭ p : x == y)\n → (f x) == (f y)\n ♭-ap f refl = refl\n\n -- ♭ is a functor\n ♭→ : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j}\n → (@♭ f : A → B) → (♭ A → ♭ B)\n ♭→ f (x ^♭) = (f x) ^♭\n\n -- The naturality square of the inclusion of points (judgemental!)\n ♭→-nat : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j} (@♭ f : A → B)\n → (a : ♭ A) → (f ∘ _↓♭) a == (_↓♭ ∘ (♭→ f)) a\n ♭→-nat f (a ^♭) = refl\n\n -- Proof of functoriality\n ♭→∘ : {@♭ i j k : ULevel} {@♭ A : Type i} {@♭ B : Type j} {@♭ C : Type k}\n {@♭ f : A → B} {@♭ g : B → C}\n → ♭→ (g ∘ f) == (♭→ g) ∘ (♭→ f)\n ♭→∘ {f = f} {g = g} =\n λ= (λ a → -- We test on elements, but\n let♭ u ^♭:= a in♭ -- might as well assume those elements are crisp\n refl -- where it follows by definition.\n in-family (λ a → (♭→ (g ∘ f)) a == ((♭→ g) ∘ (♭→ f)) a) )\n \n\n -- ♭→ preserves crisp equivalences\n ♭→e : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j}\n → (@♭ e : A ≃ B) → (♭ A) ≃ (♭ B)\n ♭→e e =\n equiv (♭→ (–> e))\n (♭→ (<– e))\n (λ { (a ^♭) → ♭-ap _^♭ (<–-inv-r e a) })\n (λ { (a ^♭) → ♭-ap _^♭ (<–-inv-l e a) })\n \n\n -- A type is discrete if the inclusion of its point is an equivalence.\n _is-discrete : {@♭ l : ULevel} → (@♭ A : Type l) → Type l\n _is-discrete {l} A = is-equiv {l} {l} {♭ A} {A} _↓♭\n\n -- The equivalence between the points of a discrete type and itself\n discrete-eq : {@♭ l : ULevel} {@♭ A : Type l} → A is-discrete → (♭ A) ≃ A\n discrete-eq = _↓♭ ,_\n\n _is-discrete-is-a-prop : {@♭ l : ULevel} (@♭ A : Type l) → (A is-discrete) is-a-prop\n A is-discrete-is-a-prop = is-equiv-is-prop\n\n is-discrete-prop : {@♭ l : ULevel} → SubtypeProp (♭ (Type l)) l\n is-discrete-prop = (λ { (A ^♭) → A is-discrete }) , (λ { (A ^♭) → A is-discrete-is-a-prop }) \n\n -- The subtype of discrete types\n Discrete : (@♭ l : ULevel) → Type (lsucc l)\n Discrete l = Subtype is-discrete-prop\n\n Discrete-_-Type_ : (@♭ n : ℕ₋₂) (@♭ i : ULevel) → Type (lsucc i)\n Discrete- n -Type i = Subtype prop\n where prop : SubtypeProp (♭ (n -Type i)) i\n prop = (λ { (A ^♭) → (fst A) is-discrete }) , (λ { (A ^♭) → (fst A) is-discrete-is-a-prop })\n\n DiscSet : (@♭ i : ULevel) → Type (lsucc i)\n DiscSet i = Discrete- ⟨ S (S O) ⟩₋₂ -Type i\n\n DiscSet₀ = DiscSet lzero\n\n ∈Disc : {@♭ i : ULevel} (A : DiscSet i) → Type i\n ∈Disc A = ((♭→ ∈) (fst A)) ↓♭\n\n DiscSet-to-Set : {@♭ i : ULevel} → DiscSet i → hSet i\n DiscSet-to-Set A = (fst A) ↓♭\n\n -- DiscSet_is-discrete : {@♭ i : ULevel} → (@♭ A : DiscSet i) → (∈Disc A) is-discrete\n -- DiscSet A is-discrete = {!(snd A)!}\n\n \n -- Just in case, we apply univalence to the discrete-eq\n discrete-id : {@♭ l : ULevel} {@♭ A : Type l} → A is-discrete → (♭ A) == A\n discrete-id p = ua (discrete-eq p)\n\n -- Obviously, the points of a type are discrete\n ♭-is-discrete : {@♭ l : ULevel} {@♭ A : Type l} → (♭ A) is-discrete\n ♭-is-discrete {_} {A} =\n _↓♭ is-an-equivalence-because\n fro is-inverse-by\n to-fro\n and\n fro-to\n where\n fro : ♭ A → ♭ (♭ A)\n fro (a ^♭) = (a ^♭) ^♭\n\n to-fro : (a : ♭ A) → ((fro a) ↓♭) == a\n to-fro (a ^♭) = refl\n \n fro-to : (a : ♭ (♭ A)) → fro (a ↓♭) == a\n fro-to ((a ^♭) ^♭) = refl\n\n\n -- To prove the ♭i is an equivalence, it suffices to give a section of it.\n _is-discrete-because_is-section-by_ : {@♭ l : ULevel} (@♭ A : Type l)\n (@♭ s : A → ♭ A) (@♭ p : (a : A) → ((s a) ↓♭)== a)\n → A is-discrete\n A is-discrete-because s is-section-by p =\n _↓♭ is-an-equivalence-because s is-inverse-by p and\n (λ { (a ^♭) → ! (♭-β (s a)) ∙ (♭-ap _^♭ (p a))})\n\n\n \n\n -- ♭ commutes with identity types in the following sense\n module _ {@♭ i : ULevel} {@♭ A : Type i} where\n ♭-identity-eq : (@♭ x y : A) → ♭ (x == y) ≃ ((x ^♭) == (y ^♭))\n ♭-identity-eq _ _ = equiv to fro to-fro fro-to\n where\n to : {@♭ x y : A} → ♭ (x == y) → ((x ^♭) == (y ^♭))\n to (refl ^♭) = refl\n\n fro : {@♭ x y : A} → ((x ^♭) == (y ^♭)) → ♭ (x == y)\n fro refl = refl ^♭\n\n to-fro : {@♭ x y : A} → (p : (x ^♭) == (y ^♭)) → (to (fro p) == p)\n to-fro refl = refl\n\n fro-to : {@♭ x y : A} → (p : ♭ (x == y)) → fro (to p) == p\n fro-to (refl ^♭) = refl\n\n {- From Tslil:\n There once was a Bear in a Zoo\n Who didn't know quite what to do\n It bored him so\n To walk to and fro\n So he flipped it and walked fro and to\n -}\n\n -- ♭ preserves crisp level.\n ♭-preserves-level : {@♭ i : ULevel} {@♭ A : Type i}\n {@♭ n : ℕ₋₂} (@♭ p : has-level n A)\n → has-level n (♭ A)\n ♭-preserves-level {_}{A}{⟨-2⟩} p =\n has-level-in ((a ^♭) ,\n (λ {(y ^♭) → (–> (♭-identity-eq a y)) ((contr-path p y )^♭)}))\n where -- If A contracts onto a, then ♭ A contracts onto a ^♭\n a = contr-center p\n ♭-preserves-level {_}{A}{S n} p =\n has-level-in (λ {(x ^♭) (y ^♭) →\n equiv-preserves-level\n (♭-identity-eq x y)\n {{♭-preserves-level {_}{(x == y)}{n} (has-level-apply p x y)}}})\n {-\n Because the equality types of ♭ A are themselves ♭ (x == y) for x y : A,\n and because we know that x == y has level n if A has level (S n), we can recurse\n to show that ♭ (x == y) has level n and therefore ♭ A has level (S n).\n -}\n\n -- A version of ♭ that acts on n-types.\n ♭ₙ : {@♭ i : ULevel} {@♭ n : ℕ₋₂}\n → (@♭ A : n -Type i) → (n -Type i)\n ♭ₙ A = (♭ (fst A)) , ♭-preserves-level (snd A)\n\n \n ♭-Trunc-map : {@♭ i : ULevel} {@♭ n : ℕ₋₂} (@♭ X : Type i)\n → (Trunc n (♭ X)) → ♭ (Trunc n X)\n ♭-Trunc-map X =\n Trunc-elim {{p = ♭-preserves-level Trunc-level}}\n (λ { (a ^♭) → [ a ] ^♭ })\n\n -- Until ♯ works we have to postulate this.\n ♭-Trunc-eq : {@♭ i : ULevel} {@♭ n : ℕ₋₂} (@♭ X : Type i)\n → (Trunc n (♭ X)) ≃ ♭ (Trunc n X)\n ♭-Trunc-eq X = (♭-Trunc-map X) , unproven\n where\n postulate unproven : (♭-Trunc-map X) is-an-equiv\n\n ⊤-is-discrete : ⊤ is-discrete\n ⊤-is-discrete = _↓♭ is-an-equivalence-because\n (λ {unit → unit ^♭}) is-inverse-by\n (λ {unit → refl})\n and\n (λ {(unit ^♭) → refl})\n\n -- ♭ commutes with coproducts.\n ♭-commutes-with-⊔ : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j}\n → ♭ (A ⊔ B) ≃ (♭ A) ⊔ (♭ B)\n ♭-commutes-with-⊔ = to ,\n (to is-an-equivalence-because\n fro is-inverse-by\n (λ { (inl (a ^♭)) → refl ;\n (inr (b ^♭)) → refl })\n and\n (λ { ((inl a) ^♭) → refl ;\n ((inr b) ^♭) → refl }))\n where\n to : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j}\n → ♭ (A ⊔ B) → (♭ A) ⊔ (♭ B)\n to ((inl a) ^♭) = inl (a ^♭)\n to ((inr b) ^♭) = inr (b ^♭)\n\n fro : {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : Type j}\n → (♭ A) ⊔ (♭ B) → ♭ (A ⊔ B)\n fro (inl (a ^♭)) = (inl a) ^♭\n fro (inr (b ^♭)) = (inr b) ^♭\n\n \n -- ♭ commutes with Σ types for crisp families.\n module _ {@♭ i j : ULevel} {@♭ A : Type i} {@♭ B : A → Type j} where\n ♭-commutes-with-Σ : ♭ (Σ A B) ≃ Σ (♭ A) (λ a → let♭ u ^♭:= a in♭ ♭ (B u))\n ♭-commutes-with-Σ = equiv to fro ((λ { ((a ^♭) , (b ^♭)) → refl })) ((λ { ((a , b) ^♭) → refl }))\n where\n to : ♭ (Σ A B) → Σ (♭ A) (λ a → let♭ u ^♭:= a in♭ ♭ (B u))\n to ((a , b) ^♭) = ((a ^♭) , (b ^♭))\n\n fro : Σ (♭ A) (λ a → let♭ u ^♭:= a in♭ ♭ (B u)) → ♭ (Σ A B)\n fro ((a ^♭) , (b ^♭)) = (a , b) ^♭\n \n\n ℕ-is-discrete : ℕ is-discrete\n ℕ-is-discrete =\n ℕ is-discrete-because fro is-section-by to-fro\n where\n fro : ℕ → ♭ ℕ\n fro O = O ^♭\n fro (S n) = (♭→ S) (fro n)\n \n to-fro : (n : ℕ) → ((fro n) ↓♭) == n\n to-fro O = refl\n to-fro (S n) = (fro (S n)) ↓♭\n =⟨ ! ((♭→-nat S) (fro n)) ⟩\n (S ∘ _↓♭) (fro n)\n =⟨ ap S (to-fro n) ⟩\n S n\n =∎\n {-\n When proving this equality by induction on n, the case of 0 presents no problem,\n but when we work with (S n), we have to deal with the fact that n is not crisp.\n However, as a constructor (and therefore defined in the empty context), S is crisp.\n Therefore, we can use the naturality sqaure of ♭ to commute it past fro, and then recurse.\n -}\n\n -- We copy the proof for ULevel (or would but we can't pattern match on lsucc?)\n {-\n ULevel-is-discrete : ULevel is-discrete\n ULevel-is-discrete =\n ULevel is-discrete-because fro is-section-by to-fro\n where\n fro : ULevel → ♭ ULevel\n fro lzero = lzero ^♭\n fro (lsucc n) = (♭→ lsucc) (fro n)\n \n to-fro : (n : ULevel) → ♭i (fro n) == n\n to-fro lzero = refl\n to-fro (lsucc n) = ♭i (fro (lsucc n))\n =⟨ ! ((♭→-nat lsucc) (fro n)) ⟩\n (lsucc ∘ ♭i) (fro n)\n =⟨ ap lsucc (to-fro n) ⟩\n lsucc n\n =∎ -}\n\n Bool-is-discrete : Bool is-discrete\n Bool-is-discrete = Bool is-discrete-because fro is-section-by to-fro\n where\n fro : Bool → ♭ Bool\n fro true = true ^♭\n fro false = false ^♭\n\n to-fro : (b : Bool) → ((fro b) ↓♭)== b\n to-fro true = refl\n to-fro false = refl\n\n Bool-to-♭PropT₀ : Bool → ♭ PropT₀\n Bool-to-♭PropT₀ true = True ^♭\n Bool-to-♭PropT₀ false = False ^♭\n\n Bool-to-♭PropT₀∘↓♭=♭→Bool-to-PropT₀ : Bool-to-♭PropT₀ ∘ _↓♭ == (♭→ Bool-to-PropT₀)\n Bool-to-♭PropT₀∘↓♭=♭→Bool-to-PropT₀ = λ= (λ { (true ^♭) → refl ; (false ^♭) → refl })\n\n{-\n _-Sphere-is-discrete : (@♭ n : ℕ) → (Sphere n) is-discrete\n n -Sphere-is-discrete = (Sphere n) is-discrete-because\n (fro n) is-section-by {!!}\n where\n ♭-north : {@♭ n : ℕ} → ♭ (Sphere n)\n ♭-north {O} = true ^♭\n ♭-north {S n} = {!north!}\n \n ♭-south : {@♭ n : ℕ} → ♭ (Sphere n)\n ♭-south = {!!}\n\n fro : (@♭ n : ℕ) → (Sphere n) → ♭ (Sphere n)\n fro O = λ { true → true ^♭ ; false → false ^♭ } \n fro (S n) = {!Susp-rec {A = Sphere n} {C = ♭ (Sphere (S n))} ♭-north ♭-south!}\n\n \n-}\n", "meta": {"hexsha": "37423864d848ff876c2abf613b6840c3a695a06c", "size": 12740, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "cohesion/david_jaz_261/Flat.agda", "max_stars_repo_name": "glangmead/formalization", "max_stars_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-10-06T17:39:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T05:51:12.000Z", "max_issues_repo_path": "cohesion/david_jaz_261/Flat.agda", "max_issues_repo_name": "glangmead/formalization", "max_issues_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_issues_repo_licenses": ["CC0-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": "cohesion/david_jaz_261/Flat.agda", "max_forks_repo_name": "glangmead/formalization", "max_forks_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_forks_repo_licenses": ["CC0-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": 35.6862745098, "max_line_length": 102, "alphanum_fraction": 0.437833595, "num_tokens": 5103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.350433140426293}} {"text": "{-# OPTIONS --without-K #-}\n\n{-\nTruncated higher inductive types look like higher inductive types except that\nthey are truncated down to some fixed truncation level.\nThis allow to define truncations (obviously) but also free algebras for\nalgebraic theories, Eilenberg-MacLane spaces, etc.\n\nThe idea is that to get an n-truncated higher inductive type, you just have to\nadd the following two constructors, where [I] is the HIT you are defining.\n\n top : (f : Sⁿ n → I) → I\n rays : (f : Sⁿ n → I) (x : Sⁿ n) → top f ≡ f x\n\nIn this file, I prove whatever is needed to go from the usual elimination rules\ngenerated by the previous constructors to the elimination rules that we expect\nfrom truncated higher inductive types.\n\nWe have to note that the previous definition does not work for [n = 0], because\nthis only adds a point to I instead of turning it into a contractible space.\n0-truncated higher inductive types are not really interesting but handling\ntruncations is easier when 0 is not special\n\nHence I’m adding the following path constructor\n\n hack-prop : (p : n ≡ 0) (x y : τ) → (x ≡ y)\n\nThis will force [I] to be a prop (hence contractible because [top] of the empty\nfunction is of type [I]) and does not change anything when [n] is not 0.\n\n\nI may use the following syntax for [n]-truncated higher inductive types:\n\n (n)data I : Set i where\n …\n\n-}\n\nmodule Homotopy.TruncatedHIT where\n\nopen import Base\nopen import Spaces.Spheres public\nopen import Spaces.Suspension public\n\n_+1 : ℕ₋₂ → ℕ\n⟨-2⟩ +1 = 0\n(S ⟨-2⟩) +1 = 0\n(S n) +1 = S (n +1)\n\n-- [hSⁿ n] is what is supposed to be filled to get something n-truncated\nhSⁿ : ℕ₋₂ → Set\nhSⁿ ⟨-2⟩ = ⊥\nhSⁿ n = Sⁿ (n +1)\n\n-- Type of fillings of a sphere\nfilling : ∀ {i} (n : ℕ₋₂) {A : Set i} (f : hSⁿ n → A) → Set i\nfilling {i} n {A} f = Σ A (λ t → ((x : hSⁿ n) → t ≡ f x))\n\n-- Type of dependent fillings of a sphere above a ball\nfilling-dep : ∀ {i j} (n : ℕ₋₂) {A : Set i} (P : A → Set j) (f : hSⁿ n → A)\n (fill : filling n f) (p : (x : hSⁿ n) → P (f x)) → Set j\nfilling-dep {i} {j} n {A} P f fill p =\n Σ (P (π₁ fill)) (λ t → ((x : hSⁿ n) → transport P (π₂ fill x) t ≡ p x))\n\n-- [has-n-spheres-filled n A] is inhabited iff every n-sphere in [A] can be\n-- filled with an (n+1)-ball.\n-- We will show that this is equivalent to being n-truncated, *for n > 0*\n-- (for n = 0, having 0-spheres filled only means that A is inhabited)\nhas-spheres-filled : ∀ {i} (n : ℕ₋₂) (A : Set i) → Set i\nhas-spheres-filled n A = (f : hSⁿ n → A) → filling n f\n\n-- [has-n-spheres-filled] satisfy the same inductive property\n-- than [is-truncated]\nfill-paths : ∀ {i} (n : ℕ₋₂) (A : Set i) (t : has-spheres-filled (S n) A)\n → (n ≡ ⟨-2⟩ → is-contr A) → ((x y : A) → has-spheres-filled n (x ≡ y))\nfill-paths ⟨-2⟩ A t contr x y f =\n (contr-has-all-paths (contr refl) x y , abort)\nfill-paths (S n) A t _ x y f =\n ((! (π₂ u (north _)) ∘ π₂ u (south _))\n , (λ z → ! (lemma (paths _ z)) ∘ suspension-β-paths-nondep _ _ _ _ f _)) where\n\n -- [f] is a map from [hSⁿ (S n)] to [x ≡ y], we can build from it a map\n -- from [hSⁿ (S n)] to [A]\n newf : hSⁿ (S (S n)) → A\n newf = suspension-rec-nondep _ _ x y f\n\n u : filling (S (S n)) newf\n u = t newf\n -- I’ve got a filling\n\n -- Every path in the sphere is equal (in A) to the canonical path going\n -- through the center of the filled sphere\n lemma : {p q : hSⁿ (S (S n))} (l : p ≡ q)\n → ap newf l ≡ ! (π₂ u p) ∘ π₂ u q\n lemma {p = a} refl = ! (opposite-left-inverse (π₂ u a))\n\n-- We first prove that if n-spheres are filled, then the type is n-truncated,\n-- we have to prove it for n = -1, and then use the previous lemma\nabstract\n spheres-filled-is-truncated : ∀ {i} (n : ℕ₋₂) (A : Set i)\n → ((n ≡ ⟨-2⟩ → is-contr A) → has-spheres-filled n A → is-truncated n A)\n spheres-filled-is-truncated ⟨-2⟩ A contr t = contr refl\n spheres-filled-is-truncated (S ⟨-2⟩) A _ t =\n all-paths-is-prop (λ x y → ! (π₂ (t (f x y)) true) ∘ π₂ (t (f x y)) false)\n where\n f : (x y : A) → bool {zero} → A\n f x y true = x\n f x y false = y\n spheres-filled-is-truncated (S (S n)) A _ t = λ x y →\n spheres-filled-is-truncated (S n) (x ≡ y) (λ ())\n (fill-paths (S n) A t (λ ()) x y)\n\n-- We now prove the converse\nabstract\n truncated-has-spheres-filled : ∀ {i} (n : ℕ₋₂) (A : Set i)\n (t : is-truncated n A) → has-spheres-filled n A\n truncated-has-spheres-filled ⟨-2⟩ A t f = (π₁ t , abort)\n truncated-has-spheres-filled (S ⟨-2⟩) A t f =\n (f true , (λ {true → refl ; false → π₁ (t (f true) (f false))}))\n truncated-has-spheres-filled (S (S n)) A t f =\n (f (north _)\n , (suspension-rec _ _ refl (ap f (paths _ (⋆Sⁿ _)))\n (λ x → trans-cst≡app (f (north _)) f (paths _ _) _\n ∘ (! (π₂ filled-newf x) ∘ π₂ filled-newf (⋆Sⁿ _))))) where\n\n newf : hSⁿ (S n) → (f (north _) ≡ f (south _))\n newf x = ap f (paths _ x)\n\n filled-newf : filling (S n) newf\n filled-newf = truncated-has-spheres-filled (S n) _ (t _ _) newf\n\n-- I prove that if [A] has [S n]-spheres filled, then the type of fillings\n-- of [n]-spheres is a proposition. The idea is that two fillings of\n-- an [n]-sphere define an [S n]-sphere, which is then filled.\nfilling-has-all-paths : ∀ {i} (n : ℕ₋₂) (A : Set i)\n ⦃ fill : has-spheres-filled (S n) A ⦄ (f : hSⁿ n → A)\n → has-all-paths (filling n f)\nfilling-has-all-paths ⟨-2⟩ A ⦃ fill ⦄ f fill₁ fill₂ =\n Σ-eq (! (π₂ big-map-filled true) ∘ π₂ big-map-filled false) (funext abort)\n where\n\n big-map : hSⁿ ⟨-1⟩ → A\n big-map true = π₁ fill₁\n big-map false = π₁ fill₂\n\n big-map-filled : filling ⟨-1⟩ big-map\n big-map-filled = fill big-map\n\nfilling-has-all-paths (S n) A ⦃ fill ⦄ f fill₁ fill₂ =\n Σ-eq (! (π₂ big-map-filled (north _)) ∘ π₂ big-map-filled (south _))\n (funext (λ x →\n trans-Π2 _ (λ t x₁ → t ≡ f x₁)\n (! (π₂ big-map-filled (north _)) ∘\n π₂ big-map-filled (south _))\n (π₂ fill₁) x\n ∘ (trans-id≡cst\n (! (π₂ big-map-filled (north _)) ∘\n π₂ big-map-filled (south _))\n (π₂ fill₁ x)\n ∘ move!-right-on-left\n (! (π₂ big-map-filled (north _)) ∘\n π₂ big-map-filled (south _))\n _ _\n (move-left-on-right _\n (! (π₂ big-map-filled (north _)) ∘\n π₂ big-map-filled (south _))\n _\n (! (suspension-β-paths-nondep _ _ _ _ g x)\n ∘ lemma (paths _ x)))))) where\n\n g : hSⁿ (S n) → (π₁ fill₁ ≡ π₁ fill₂)\n g x = π₂ fill₁ x ∘ ! (π₂ fill₂ x)\n\n big-map : hSⁿ (S (S n)) → A\n big-map = suspension-rec-nondep _ _ (π₁ fill₁) (π₁ fill₂) g\n\n big-map-filled : filling (S (S n)) big-map\n big-map-filled = fill big-map\n\n lemma : {u v : hSⁿ (S (S n))} (p : u ≡ v)\n → ap big-map p ≡ (! (π₂ big-map-filled u) ∘ π₂ big-map-filled v)\n lemma {u = a} refl = ! (opposite-left-inverse (π₂ big-map-filled a))\n\nabstract\n truncated-has-filling-dep : ∀ {i j} (A : Set i) (P : A → Set j) (n : ℕ₋₂)\n ⦃ trunc : (x : A) → is-truncated n (P x) ⦄\n (contr : n ≡ ⟨-2⟩ → is-contr A)\n (fill : has-spheres-filled n A) (f : hSⁿ n → A) (p : (x : hSⁿ n) → P (f x))\n → filling-dep n P f (fill f) p\n truncated-has-filling-dep A P ⟨-2⟩ ⦃ trunc ⦄ contr fill f p =\n (π₁ (trunc (π₁ (fill f))) , abort)\n truncated-has-filling-dep A P (S n) ⦃ trunc ⦄ contr fill f p =\n transport (λ t → filling-dep (S n) P f t p) eq fill-dep where\n\n -- Combining [f] and [p] we have a sphere in the total space of [P]\n newf : hSⁿ (S n) → Σ A P\n newf x = (f x , p x)\n\n -- But this total space is (S n)-truncated\n ΣAP-truncated : is-truncated (S n) (Σ A P)\n ΣAP-truncated =\n Σ-is-truncated (S n) (spheres-filled-is-truncated (S n) A contr fill)\n trunc\n\n -- Hence the sphere is filled\n tot-fill : filling (S n) newf\n tot-fill = truncated-has-spheres-filled (S n) (Σ A P) ΣAP-truncated newf\n\n -- We can split this filling as a filling of [f] in [A] …\n new-fill : filling (S n) f\n new-fill = (π₁ (π₁ tot-fill) , (λ x → base-path (π₂ tot-fill x)))\n\n -- and a dependent filling above the previous filling of [f], along [p]\n fill-dep : filling-dep (S n) P f new-fill p\n fill-dep = (π₂ (π₁ tot-fill) , (λ x → fiber-path (π₂ tot-fill x)))\n\n A-has-spheres-filled-S : has-spheres-filled (S (S n)) A\n A-has-spheres-filled-S =\n truncated-has-spheres-filled (S (S n)) A\n (truncated-is-truncated-S (S n)\n (spheres-filled-is-truncated (S n) A contr fill))\n\n -- But both the new and the old fillings of [f] are equal, hence we will\n -- have a dependent filling above the old one\n eq : new-fill ≡ fill f\n eq = filling-has-all-paths (S n) A f new-fill (fill f)\n", "meta": {"hexsha": "58077c8bb8215218aae3538fcfd38bb4a9bae40d", "size": 8834, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "old/Homotopy/TruncatedHIT.agda", "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 294, "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_issues_repo_path": "old/Homotopy/TruncatedHIT.agda", "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_forks_repo_path": "old/Homotopy/TruncatedHIT.agda", "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 50, "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "avg_line_length": 38.9162995595, "max_line_length": 80, "alphanum_fraction": 0.5799184967, "num_tokens": 3123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6548947155710233, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.35043313321792624}} {"text": "----------------------------------------------------------------------\n-- Copyright: 2013, Jan Stolarek, Lodz University of Technology --\n-- --\n-- License: See LICENSE file in root of the repo --\n-- Repo address: https://github.com/jstolarek/dep-typed-wbl-heaps --\n-- --\n-- Weight biased leftist heap that proves rank invariant and uses --\n-- a single-pass merging algorithm. --\n----------------------------------------------------------------------\n\nmodule SinglePassMerge.RankProof where\n\nopen import Basics\n-- We import rank proofs conducted earlier - they will be re-used.\nopen import TwoPassMerge.RankProof\n using ( makeT-lemma )\n renaming ( proof-1 to proof-1a; proof-2 to proof-2a )\n\ndata Heap : Nat → Set where\n empty : Heap zero\n node : Priority → {l r : Nat} → l ≥ r → Heap l → Heap r → Heap (suc (l + r))\n\n-- Note [Privoving rank invariant in single-pass merge]\n-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n--\n-- Recall that in TwoPassMerge.RankProof we need to prove that:\n--\n-- 1) makeT constructs node of correct size. There were two cases:\n--\n-- a) constructing a node without swapping l and r subtrees passed\n-- to makeT. No extra proof was required as everything followed\n-- from definitions.\n--\n-- b) constructing a node by swapping l and r subtrees (when rank\n-- of r was greater than rank of l). We had to prove that:\n--\n-- suc (a + b) ≡ suc (b + a)\n--\n-- This proof is supplied by a function makeT-lemma.\n--\n-- 2) resulting heap produced by merge has correct size. Merge has 4\n-- cases (see [Two-pass merging algorithm]):\n--\n-- a) h1 is empty. No extra proof required (everything follows\n-- from definition of +). See [merge, proof 0a].\n--\n-- b) h2 is empty. We had to prove that:\n--\n-- h1 ≡ h1 + 0\n--\n-- This proof is supplied by +0 (in Basics.Reasoning) and is\n-- inlined in the definition of merge. See [merge, proof 0b].\n--\n-- c) priority p1 is higher than p2. We had to prove:\n--\n-- suc (l1 + (r1 + suc (l2 + r2)))\n-- ≡ suc ((l1 + r1) + suc (l2 + r2))\n--\n-- This proof is supplied by proof-1 (renamed to proof-1a in\n-- this module). See [merge, proof 1] for details.\n--\n-- d) priority p2 is higher than p1. We had to prove:\n--\n-- suc (l2 + (r2 + suc (l1 + r1)))\n-- ≡ suc ((l1 + r1) + suc (l2 + r2))\n--\n-- This proof is supplied by proof-2 (renamed to proof-2a in\n-- this module). See [merge, proof 2] for details.\n--\n-- Now that we inline makeT into merge and we will have to construct\n-- new proofs of merge that take into account the fact that makeT has\n-- been inlinined. Let's take a detailed look into the problem and\n-- analyze possible solutions.\n--\n-- First of all let us note that we only made calls to makeT in\n-- inductive cases of merge (points 2c and 2d above). This means that\n-- implementation of base cases of merge (2a and 2b above) remains\n-- unchanged. Let's take a look at proofs we need to supply for each\n-- of four inductive cases of merge (see [Single-pass merging\n-- algorithm] for description of each case):\n--\n-- 1) case c described in [Single-pass merging algorithm]. Call to\n-- makeT would not swap left and right when creating a node from\n-- parameters passed to it. Required proof is:\n--\n-- suc (l1 + (r1 + suc (l2 + r2)))\n-- ≡ suc ((l1 + r1) + suc (l2 + r2))\n--\n-- 2) case d described in [Single-pass merging algorithm]. Call to\n-- makeT would swap left and right when creating a node from\n-- parameters passed to it. Required proof is:\n--\n-- suc ((r1 + suc (l2 + r2)) + l1)\n-- ≡ suc ((l1 + r1) + suc (l2 + r2))\n--\n-- 3) case e described in [Single-pass merging algorithm]. Call to\n-- makeT would not swap left and right when creating a node from\n-- parameters passed to it. Required proof is:\n--\n-- suc (l2 + (r2 + suc (l1 + r1)))\n-- ≡ suc ((l1 + r1) + suc (l2 + r2))\n--\n-- 4) case f described in [Single-pass merging algorithm]. Call to\n-- makeT would swap left and right when creating a node from\n-- parameters passed to it. Required proof is:\n--\n-- suc ((r2 + suc (l1 + r1)) + l2)\n-- ≡ suc ((l1 + r1) + suc (l2 + r2))\n--\n-- First of all we must note that proofs required in cases 1 and 3 are\n-- exactly the same as in the two-pass merging algorithm. This allows\n-- us to re-use the old proofs (renamed to proof-1a and proof-2a\n-- here). What about proofs of cases 2 and 4? One thing we could do is\n-- construct proofs of these properties using technique described in\n-- Note [Constructing equality proofs using transitivity]. This is\n-- left as an exercise to the reader. Here we will proceed in a\n-- different way. Notice that properties we have to prove in cases for\n-- 2 and 4 are very similar to properties 1 and 3 (we omit the RHS\n-- since it is always the same):\n--\n-- 1: suc (l1 + (r1 + suc (l2 + r2)))\n-- 2: suc ((r1 + suc (l2 + r2)) + l1)\n--\n-- 3: suc (l2 + (r2 + suc (l1 + r1)))\n-- 4: suc ((r2 + suc (l1 + r1)) + l2)\n--\n-- The only difference between 1 and 2 and between 3 and 4 is the\n-- order of parameters inside outer suc. This is expected: in cases 2\n-- and 4 we swap left and right subtree passed to node and this is\n-- reflected in the types. Now, if we could prove that:\n--\n-- suc ((r1 + suc (l2 + r2)) + l1)\n-- ≡ suc (l1 + (r1 + suc (l2 + r2)))\n--\n-- and\n--\n-- suc ((r2 + suc (l1 + r1)) + l2)\n-- ≡ suc (l2 + (r2 + suc (l1 + r1)))\n--\n-- then we could use transitivity to combine these new proofs with old\n-- proof-1a and proof-2a. If we abstract the parameters in the above\n-- equalities we see that the property we need to prove is:\n--\n-- suc (a + b) ≡ suc (b + a)\n--\n-- And that happens to be makeT-lemma! New version of merge was\n-- created by inlining calls to make and now it turns out we can\n-- construct proofs of that implementation by using proofs of\n-- makeT. This leads us to very elegant solutions presented below.\n\nproof-1b : (l1 r1 l2 r2 : Nat) → suc ((r1 + suc (l2 + r2)) + l1)\n ≡ suc ((l1 + r1) + suc (l2 + r2))\nproof-1b l1 r1 l2 r2 = trans (makeT-lemma (r1 + suc (l2 + r2)) l1)\n (proof-1a l1 r1 l2 r2)\n\nproof-2b : (l1 r1 l2 r2 : Nat) → suc ((r2 + suc (l1 + r1)) + l2)\n ≡ suc ((l1 + r1) + suc (l2 + r2))\nproof-2b l1 r1 l2 r2 = trans (makeT-lemma (r2 + suc (l1 + r1)) l2)\n (proof-2a l1 r1 l2 r2)\n\n-- We can now use proof-1a, proof-1b, proof-2a and proof-2b in\n-- definition of merge.\nmerge : {l r : Nat} → Heap l → Heap r → Heap (l + r)\nmerge {zero} {_} empty h2 = h2\nmerge {suc l} {zero} h1 empty = subst Heap (sym (+0 (suc l))) h1\nmerge {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}\n (node p1 {l1-rank} {r1-rank} l1≥r1 l1 r1)\n (node p2 {l2-rank} {r2-rank} l2≥r2 l2 r2)\n with p1 < p2\n | order l1-rank (r1-rank + suc (l2-rank + r2-rank))\n | order l2-rank (r2-rank + suc (l1-rank + r1-rank))\nmerge {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}\n (node p1 {l1-rank} {r1-rank} l1≥r1 l1 r1)\n (node p2 {l2-rank} {r2-rank} l2≥r2 l2 r2)\n | true\n | ge l1≥r1+h2\n | _\n = subst Heap\n (proof-1a l1-rank r1-rank l2-rank r2-rank)\n (node p1 l1≥r1+h2 l1 (merge r1 (node p2 l2≥r2 l2 r2)))\nmerge {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}\n (node p1 {l1-rank} {r1-rank} l1≥r1 l1 r1)\n (node p2 {l2-rank} {r2-rank} l2≥r2 l2 r2)\n | true\n | le l1≤r1+h2\n | _\n = subst Heap\n (proof-1b l1-rank r1-rank l2-rank r2-rank)\n (node p1 l1≤r1+h2 (merge r1 (node p2 l2≥r2 l2 r2)) l1)\nmerge {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}\n (node p1 {l1-rank} {r1-rank} l1≥r1 l1 r1)\n (node p2 {l2-rank} {r2-rank} l2≥r2 l2 r2)\n | false\n | _\n | ge l2≥r2+h1\n = subst Heap\n (proof-2a l1-rank r1-rank l2-rank r2-rank)\n (node p2 l2≥r2+h1 l2 (merge r2 (node p1 l1≥r1 l1 r1)))\nmerge {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}\n (node p1 {l1-rank} {r1-rank} l1≥r1 l1 r1)\n (node p2 {l2-rank} {r2-rank} l2≥r2 l2 r2)\n | false\n | _\n | le l2≤r2+h1\n = subst Heap\n (proof-2b l1-rank r1-rank l2-rank r2-rank)\n (node p2 l2≤r2+h1 (merge r2 (node p1 l1≥r1 l1 r1)) l2)\n", "meta": {"hexsha": "d5e00bbf93142864f4d6ef41175f416092cfaca2", "size": 8710, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/SinglePassMerge/RankProof.agda", "max_stars_repo_name": "jstolarek/dep-typed-wbl-heaps", "max_stars_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-05-02T21:48:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-02T21:48:43.000Z", "max_issues_repo_path": "src/SinglePassMerge/RankProof.agda", "max_issues_repo_name": "jstolarek/dep-typed-wbl-heaps", "max_issues_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e", "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": "src/SinglePassMerge/RankProof.agda", "max_forks_repo_name": "jstolarek/dep-typed-wbl-heaps", "max_forks_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e", "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": 41.875, "max_line_length": 79, "alphanum_fraction": 0.5639494834, "num_tokens": 2841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6406358685621721, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.35026007087273997}} {"text": "{-# OPTIONS --safe #-}\nmodule Cubical.Algebra.Group.Exact where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Function\n\nopen import Cubical.Data.Unit\n\nopen import Cubical.Algebra.Group.Base\nopen import Cubical.Algebra.Group.Morphisms\nopen import Cubical.Algebra.Group.MorphismProperties\nopen import Cubical.Algebra.Group.GroupPath\nopen import Cubical.Algebra.Group.Instances.Unit\n\nopen import Cubical.HITs.PropositionalTruncation as PT\n\n\n-- TODO : Define exact sequences\n-- (perhaps short, finite, ℕ-indexed and ℤ-indexed)\n\nSES→isEquiv : ∀ {ℓ ℓ'} {L R : Group ℓ-zero}\n → {G : Group ℓ} {H : Group ℓ'}\n → UnitGroup₀ ≡ L\n → UnitGroup₀ ≡ R\n → (lhom : GroupHom L G) (midhom : GroupHom G H) (rhom : GroupHom H R)\n → ((x : _) → isInKer midhom x → isInIm lhom x)\n → ((x : _) → isInKer rhom x → isInIm midhom x)\n → isEquiv (fst midhom)\nSES→isEquiv {R = R} {G = G} {H = H} =\n J (λ L _ → UnitGroup₀ ≡ R →\n (lhom : GroupHom L G) (midhom : GroupHom G H)\n (rhom : GroupHom H R) →\n ((x : fst G) → isInKer midhom x → isInIm lhom x) →\n ((x : fst H) → isInKer rhom x → isInIm midhom x) →\n isEquiv (fst midhom))\n ((J (λ R _ → (lhom : GroupHom UnitGroup₀ G) (midhom : GroupHom G H)\n (rhom : GroupHom H R) →\n ((x : fst G) → isInKer midhom x → isInIm lhom x) →\n ((x : _) → isInKer rhom x → isInIm midhom x) →\n isEquiv (fst midhom))\n main))\n where\n main : (lhom : GroupHom UnitGroup₀ G) (midhom : GroupHom G H)\n (rhom : GroupHom H UnitGroup₀) →\n ((x : fst G) → isInKer midhom x → isInIm lhom x) →\n ((x : fst H) → isInKer rhom x → isInIm midhom x) →\n isEquiv (fst midhom)\n main lhom midhom rhom lexact rexact =\n BijectionIsoToGroupEquiv {G = G} {H = H}\n bijIso' .fst .snd\n where\n bijIso' : BijectionIso G H\n BijectionIso.fun bijIso' = midhom\n BijectionIso.inj bijIso' x inker =\n PT.rec (GroupStr.is-set (snd G) _ _)\n (λ s → sym (snd s) ∙ IsGroupHom.pres1 (snd lhom))\n (lexact _ inker)\n BijectionIso.surj bijIso' x = rexact x refl\n\n-- exact sequence of 4 groups. Useful for the proof of π₄S³\nrecord Exact4 {ℓ ℓ' ℓ'' ℓ''' : Level} (G : Group ℓ)\n (H : Group ℓ') (L : Group ℓ'') (R : Group ℓ''')\n (G→H : GroupHom G H) (H→L : GroupHom H L) (L→R : GroupHom L R)\n : Type (ℓ-max ℓ (ℓ-max ℓ' (ℓ-max ℓ'' ℓ'''))) where\n field\n ImG→H⊂KerH→L : (x : fst H) → isInIm G→H x → isInKer H→L x\n KerH→L⊂ImG→H : (x : fst H) → isInKer H→L x → isInIm G→H x\n\n ImH→L⊂KerL→R : (x : fst L) → isInIm H→L x → isInKer L→R x\n KerL→R⊂ImH→L : (x : fst L) → isInKer L→R x → isInIm H→L x\n\nopen Exact4\n\nextendExact4Surjective : {ℓ ℓ' ℓ'' ℓ''' ℓ'''' : Level}\n (G : Group ℓ) (H : Group ℓ') (L : Group ℓ'') (R : Group ℓ''') (S : Group ℓ'''')\n (G→H : GroupHom G H) (H→L : GroupHom H L) (L→R : GroupHom L R) (R→S : GroupHom R S)\n → isSurjective G→H\n → Exact4 H L R S H→L L→R R→S\n → Exact4 G L R S (compGroupHom G→H H→L) L→R R→S\nImG→H⊂KerH→L (extendExact4Surjective G H L R S G→H H→L L→R R→S surj ex) x =\n PT.rec (GroupStr.is-set (snd R) _ _)\n (uncurry λ g → J (λ x _ → isInKer L→R x)\n (ImG→H⊂KerH→L ex (fst H→L (fst G→H g))\n ∣ (fst G→H g) , refl ∣₁))\nKerH→L⊂ImG→H (extendExact4Surjective G H L R S G→H H→L L→R R→S surj ex) x ker =\n PT.rec squash₁\n (uncurry λ y → J (λ x _ → isInIm (compGroupHom G→H H→L) x)\n (PT.map (uncurry\n (λ y → J (λ y _ → Σ[ g ∈ fst G ] fst H→L (fst G→H g) ≡ H→L .fst y)\n (y , refl))) (surj y)))\n (KerH→L⊂ImG→H ex x ker)\nImH→L⊂KerL→R (extendExact4Surjective G H L R S G→H H→L L→R R→S surj ex) =\n ImH→L⊂KerL→R ex\nKerL→R⊂ImH→L (extendExact4Surjective G H L R S G→H H→L L→R R→S surj ex) =\n KerL→R⊂ImH→L ex\n\n-- Useful lemma in the proof of π₄S³≅ℤ\ntransportExact4 : {ℓ ℓ' ℓ'' : Level}\n {G G₂ : Group ℓ} {H H₂ : Group ℓ'} {L L₂ : Group ℓ''} {R : Group₀}\n (G≡G₂ : G ≡ G₂) (H≡H₂ : H ≡ H₂) (L≡L₂ : L ≡ L₂)\n → UnitGroup₀ ≡ R\n → (G→H : GroupHom G H) (G₂→H₂ : GroupHom G₂ H₂)\n (H→L : GroupHom H L) (H₂→L₂ : GroupHom H₂ L₂)\n (L→R : GroupHom L R)\n → Exact4 G H L R G→H H→L L→R\n → PathP (λ i → GroupHom (G≡G₂ i) (H≡H₂ i)) G→H G₂→H₂\n → PathP (λ i → GroupHom (H≡H₂ i) (L≡L₂ i)) H→L H₂→L₂\n → Exact4 G₂ H₂ L₂ UnitGroup₀ G₂→H₂ H₂→L₂ (→UnitHom L₂)\ntransportExact4 {G = G} {G₂ = G₂} {H = H} {H₂ = H₂} {L = L} {L₂ = L₂} {R = R} =\n J4 (λ G₂ H₂ L₂ R G≡G₂ H≡H₂ L≡L₂ Unit≡R\n → (G→H : GroupHom G H) (G₂→H₂ : GroupHom G₂ H₂)\n (H→L : GroupHom H L) (H₂→L₂ : GroupHom H₂ L₂)\n (L→R : GroupHom L R)\n → Exact4 G H L R G→H H→L L→R\n → PathP (λ i → GroupHom (G≡G₂ i) (H≡H₂ i)) G→H G₂→H₂\n → PathP (λ i → GroupHom (H≡H₂ i) (L≡L₂ i)) H→L H₂→L₂\n → Exact4 G₂ H₂ L₂ UnitGroup₀ G₂→H₂ H₂→L₂ (→UnitHom L₂))\n (λ G→H G₂→H₂ H→L H₂→L₂ L→R ex pp1 pp2\n → J4 (λ G₂→H₂ H₂→L₂ (x : Unit) (y : Unit)\n pp1 pp2 (_ : tt ≡ x) (_ : tt ≡ x)\n → Exact4 G H L UnitGroup₀ G₂→H₂ H₂→L₂ (→UnitHom L))\n ex G₂→H₂ H₂→L₂ tt tt pp1 pp2 refl refl )\n G₂ H₂ L₂ R\n where\n J4 : ∀ {ℓ ℓ₂ ℓ₃ ℓ₄ ℓ'} {A : Type ℓ}\n {A₂ : Type ℓ₂} {A₃ : Type ℓ₃} {A₄ : Type ℓ₄}\n {x : A} {x₂ : A₂} {x₃ : A₃} {x₄ : A₄}\n (B : (y : A) (z : A₂) (w : A₃) (u : A₄)\n → x ≡ y → x₂ ≡ z → x₃ ≡ w → x₄ ≡ u → Type ℓ')\n → B x x₂ x₃ x₄ refl refl refl refl\n → (y : A) (z : A₂) (w : A₃) (u : A₄)\n (p : x ≡ y) (q : x₂ ≡ z) (r : x₃ ≡ w) (s : x₄ ≡ u)\n → B y z w u p q r s\n J4 {x = x} {x₂ = x₂} {x₃ = x₃} {x₄ = x₄} B b y z w u =\n J (λ y p → (q : x₂ ≡ z) (r : x₃ ≡ w) (s : x₄ ≡ u) →\n B y z w u p q r s)\n (J (λ z q → (r : x₃ ≡ w) (s : x₄ ≡ u) → B x z w u refl q r s)\n (J (λ w r → (s : x₄ ≡ u) → B x x₂ w u refl refl r s)\n (J (λ u s → B x x₂ x₃ u refl refl refl s) b)))\n", "meta": {"hexsha": "6ba146876af38e8eb666f6627f15bbf9675c765d", "size": 6033, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Cubical/Algebra/Group/Exact.agda", "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/Group/Exact.agda", "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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": "Cubical/Algebra/Group/Exact.agda", "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "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.7872340426, "max_line_length": 85, "alphanum_fraction": 0.5246146196, "num_tokens": 2660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.640635868562172, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.3502600708727399}} {"text": "{-# OPTIONS --cubical #-}\n\nmodule Data.List.Permute where\n\nopen import Prelude\nopen import Data.Nat\nopen import Data.Nat.Properties using (_≤ᴮ_)\n\ninfixr 5 _∹_∷_\ndata Premuted {a} (A : Type a) : Type a where\n [] : Premuted A\n _∹_∷_ : ℕ → A → Premuted A → Premuted A\n\nmutual\n merge : Premuted A → Premuted A → Premuted A\n merge [] = id\n merge (n ∹ x ∷ xs) = mergeˡ n x (merge xs)\n\n mergeˡ : ℕ → A → (Premuted A → Premuted A) → Premuted A → Premuted A\n mergeˡ i x xs [] = i ∹ x ∷ xs []\n mergeˡ i x xs (j ∹ y ∷ ys) = merge⁺ i x xs j y ys (i ≤ᴮ j)\n\n merge⁺ : ℕ → A → (Premuted A → Premuted A) → ℕ → A → Premuted A → Bool → Premuted A\n merge⁺ i x xs j y ys true = i ∹ x ∷ xs ((j ∸ i) ∹ y ∷ ys)\n merge⁺ i x xs j y ys false = j ∹ y ∷ mergeˡ ((i ∸ j) ∸ 1) x xs ys\n\nmerge-idʳ : (xs : Premuted A) → merge xs [] ≡ xs\nmerge-idʳ [] = refl\nmerge-idʳ (i ∹ x ∷ xs) = cong (i ∹ x ∷_) (merge-idʳ xs)\n\nopen import Algebra\n\n≤≡-trans : ∀ x y z → (x ≤ᴮ y) ≡ true → (y ≤ᴮ z) ≡ true → (x ≤ᴮ z) ≡ true\n≤≡-trans zero y z p₁ p₂ = refl\n≤≡-trans (suc x) zero z p₁ p₂ = ⊥-elim (subst (bool ⊤ ⊥) p₁ tt)\n≤≡-trans (suc x) (suc y) zero p₁ p₂ = ⊥-elim (subst (bool ⊤ ⊥) p₂ tt)\n≤≡-trans (suc x) (suc y) (suc z) p₁ p₂ = ≤≡-trans x y z p₁ p₂\n\n<≡-trans : ∀ x y z → (x ≤ᴮ y) ≡ false → (y ≤ᴮ z) ≡ false → (x ≤ᴮ z) ≡ false\n<≡-trans zero y z p₁ p₂ = ⊥-elim (subst (bool ⊥ ⊤) p₁ tt)\n<≡-trans (suc x) zero z p₁ p₂ = ⊥-elim (subst (bool ⊥ ⊤) p₂ tt)\n<≡-trans (suc x) (suc y) zero p₁ p₂ = p₂\n<≡-trans (suc x) (suc y) (suc z) p₁ p₂ = <≡-trans x y z p₁ p₂\n\n≤≡-sub : ∀ i j k → (j ≤ᴮ k) ≡ true → (j ∸ i ≤ᴮ k ∸ i) ≡ true\n≤≡-sub zero j k p = p\n≤≡-sub (suc i) zero k p = refl\n≤≡-sub (suc i) (suc j) zero p = ⊥-elim (subst (bool ⊤ ⊥) p tt)\n≤≡-sub (suc i) (suc j) (suc k) p = ≤≡-sub i j k p\n\n≥≡-sub : ∀ i j k → (j ≤ᴮ k) ≡ false → (i ≤ᴮ k) ≡ true → (j ∸ i ≤ᴮ k ∸ i) ≡ false\n≥≡-sub i zero k p _ = ⊥-elim (subst (bool ⊥ ⊤) p tt)\n≥≡-sub zero (suc j) k p _ = p\n≥≡-sub (suc i) (suc j) zero p p₂ = ⊥-elim (subst (bool ⊤ ⊥) p₂ tt)\n≥≡-sub (suc i) (suc j) (suc k) p p₂ = ≥≡-sub i j k p p₂\n\n<≡-sub : ∀ i j k → (i ≤ᴮ j) ≡ false → (j ≤ᴮ k) ≡ false → (i ∸ k ∸ 1 ≤ᴮ j ∸ k ∸ 1) ≡ false\n<≡-sub zero j k p _ = ⊥-elim (subst (bool ⊥ ⊤) p tt)\n<≡-sub (suc i) zero k p p₂ = ⊥-elim (subst (bool ⊥ ⊤) p₂ tt)\n<≡-sub (suc i) (suc j) zero p p₂ = p\n<≡-sub (suc i) (suc j) (suc k) p p₂ = <≡-sub i j k p p₂\n\n>≡-sub : ∀ i j k → (i ≤ᴮ j) ≡ true → (j ≤ᴮ k) ≡ false → (i ≤ᴮ k) ≡ false → (i ∸ k ∸ 1 ≤ᴮ j ∸ k ∸ 1) ≡ true\n>≡-sub i zero k p₁ p₂ p₃ = ⊥-elim (subst (bool ⊥ ⊤) p₂ tt)\n>≡-sub zero (suc j) k p₁ p₂ p₃ = ⊥-elim (subst (bool ⊥ ⊤) p₃ tt)\n>≡-sub (suc i) (suc j) zero p₁ p₂ p₃ = p₁\n>≡-sub (suc i) (suc j) (suc k) p₁ p₂ p₃ = >≡-sub i j k p₁ p₂ p₃\n\nzero-sub : ∀ n → zero ∸ n ≡ zero\nzero-sub zero = refl\nzero-sub (suc n) = refl\n\n≤-sub-id : ∀ i j k → (i ≤ᴮ j) ≡ true → k ∸ i ∸ (j ∸ i) ≡ k ∸ j\n≤-sub-id zero j k p = refl\n≤-sub-id (suc i) zero k p = ⊥-elim (subst (bool ⊤ ⊥) p tt)\n≤-sub-id (suc i) (suc j) zero p = zero-sub (j ∸ i)\n≤-sub-id (suc i) (suc j) (suc k) p = ≤-sub-id i j k p\n\nlemma₁ : ∀ i j k → (j ≤ᴮ k) ≡ false → i ∸ k ∸ 1 ∸ (j ∸ k ∸ 1) ∸ 1 ≡ i ∸ j ∸ 1\nlemma₁ zero j k _ = cong (λ zk → zk ∸ 1 ∸ (j ∸ k ∸ 1) ∸ 1) (zero-sub k) ; cong (_∸ 1) (zero-sub (j ∸ k ∸ 1)) ; sym (cong (_∸ 1) (zero-sub j))\nlemma₁ (suc i) zero k p₂ = ⊥-elim (subst (bool ⊥ ⊤) p₂ tt)\nlemma₁ (suc i) (suc j) zero p₂ = refl\nlemma₁ (suc i) (suc j) (suc k) p₂ = lemma₁ i j k p₂\n\nlemma₂ : ∀ i j k → (i ≤ᴮ j) ≡ true → (j ≤ᴮ k) ≡ false → (i ≤ᴮ k) ≡ false → j ∸ i ≡ j ∸ k ∸ 1 ∸ (i ∸ k ∸ 1)\nlemma₂ i zero k p₁ p₂ p₃ = ⊥-elim (subst (bool ⊥ ⊤) p₂ tt)\nlemma₂ zero (suc j) k p₁ p₂ p₃ = ⊥-elim (subst (bool ⊥ ⊤) p₃ tt)\nlemma₂ (suc i) (suc j) zero p₁ p₂ p₃ = refl\nlemma₂ (suc i) (suc j) (suc k) p₁ p₂ p₃ = lemma₂ i j k p₁ p₂ p₃\n\n{-# TERMINATING #-}\nmerge-assoc : Associative (merge {A = A})\nmerge-assoc [] ys zs = refl\nmerge-assoc (i ∹ x ∷ xs) [] zs = cong (flip merge zs) (merge-idʳ (i ∹ x ∷ xs))\nmerge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) [] = merge-idʳ (merge (i ∹ x ∷ xs) (j ∹ y ∷ ys)) ; sym (cong (merge (i ∹ x ∷ xs)) (merge-idʳ (j ∹ y ∷ ys)))\nmerge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) with merge-assoc xs (j ∸ i ∹ y ∷ ys) (k ∸ i ∹ z ∷ zs) | merge-assoc (i ∸ k ∸ 1 ∹ x ∷ xs) (j ∸ k ∸ 1 ∹ y ∷ ys) zs | (merge-assoc (i ∸ j ∸ 1 ∹ x ∷ xs) ys (k ∸ j ∹ z ∷ zs)) | i ≤ᴮ j | inspect (i ≤ᴮ_) j | j ≤ᴮ k | inspect (j ≤ᴮ_) k\nmerge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | r | _ | _ | true | 〖 ij 〗 | true | 〖 jk 〗 = cong (merge⁺ i x (merge (merge xs (j ∸ i ∹ y ∷ ys))) k z zs) (≤≡-trans i j k ij jk) ;\n cong (i ∹ x ∷_) (r ;\n cong (merge xs) (cong (merge⁺ (j ∸ i) y (merge ys) (k ∸ i) z zs) (≤≡-sub i j k jk) ; cong (λ kij → j ∸ i ∹ y ∷ merge ys (kij ∹ z ∷ zs)) (≤-sub-id i j k ij))) ;\n cong (merge⁺ i x (merge xs) j y (merge ys (k ∸ j ∹ z ∷ zs))) (sym ij)\nmerge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | _ | r | _ | false | 〖 ij 〗 | false | 〖 jk 〗 = cong (merge⁺ j y (merge (mergeˡ (i ∸ j ∸ 1) x (merge xs) ys)) k z zs ) jk ;\n cong (k ∹ z ∷_) (cong (λ s → mergeˡ (j ∸ k ∸ 1) y (merge (mergeˡ s x (merge xs) ys)) zs) (sym (lemma₁ i j k jk)) ;\n cong (λ s → merge (merge⁺ (i ∸ k ∸ 1) x (merge xs) (j ∸ k ∸ 1) y ys s) zs) (sym (<≡-sub i j k ij jk)) ;\n r) ;\n cong (merge⁺ i x (merge xs) k z (mergeˡ (j ∸ k ∸ 1) y (merge ys) zs)) (sym (<≡-trans i j k ij jk))\nmerge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | _ | _ | r | false | 〖 ij 〗 | true | 〖 jk 〗 = cong (merge⁺ j y (merge (mergeˡ (i ∸ j ∸ 1) x (merge xs) ys)) k z zs) jk ;\n cong (j ∹ y ∷_) r ;\n cong (merge⁺ i x (merge xs) j y (merge ys (k ∸ j ∹ z ∷ zs))) (sym ij)\nmerge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | _ | _ | _ | true | ij | false | jk with i ≤ᴮ k | inspect (i ≤ᴮ_) k\nmerge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | _ | r | _ | true | 〖 ij 〗 | false | 〖 jk 〗 | false | 〖 ik 〗 = cong (k ∹ z ∷_) ((cong (λ s → mergeˡ (i ∸ k ∸ 1) x (merge (merge xs (s ∹ y ∷ ys))) zs) (lemma₂ i j k ij jk ik) ;\n cong (λ c → merge (merge⁺ (i ∸ k ∸ 1) x (merge xs) (j ∸ k ∸ 1) y ys c) zs) (sym (>≡-sub i j k ij jk ik ))) ;\n r )\nmerge-assoc (i ∹ x ∷ xs) (j ∹ y ∷ ys) (k ∹ z ∷ zs) | r | _ | _ | true | 〖 ij 〗 | false | 〖 jk 〗 | true | 〖 ik 〗 = cong (i ∹ x ∷_) (r ;\n cong (merge xs) (cong (merge⁺ (j ∸ i) y (merge ys) (k ∸ i) z zs) (≥≡-sub i j k jk ik) ;\n cong (λ s → k ∸ i ∹ z ∷ mergeˡ s y (merge ys) zs) (cong (_∸ 1) (≤-sub-id i k j ik)) ))\n\nopen import Data.List\n\nindex : List ℕ → List A → List (Premuted A)\nindex _ [] = []\nindex [] (x ∷ xs) = (0 ∹ x ∷ []) ∷ index [] xs\nindex (i ∷ is) (x ∷ xs) = (i ∹ x ∷ []) ∷ index is xs\n\nunindex : Premuted A → List A\nunindex [] = []\nunindex (_ ∹ x ∷ xs) = x ∷ unindex xs\n\nopen import TreeFold\n\nshuffle : List ℕ → List A → List A\nshuffle is = unindex ∘ treeFold merge [] ∘ index is\n\nopen import Data.List.Syntax\n\ne : List ℕ\ne = shuffle [ 0 , 1 , 0 ] [ 1 , 2 , 3 ]\n", "meta": {"hexsha": "436170396f94e19be3baf0d60cec6ee4af88e65e", "size": 7993, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "Data/List/Permute.agda", "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_issues_repo_path": "Data/List/Permute.agda", "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "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": "Data/List/Permute.agda", "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "avg_line_length": 58.3430656934, "max_line_length": 278, "alphanum_fraction": 0.4236206681, "num_tokens": 3622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056295505783, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.35003757680022984}} {"text": "open import Data.Graph\n\nmodule Data.Graph.Path.Cut {ℓᵥ ℓₑ} (g : FiniteGraph ℓᵥ ℓₑ) where\n\nopen import Data.Fin as Fin using (Fin; zero; suc)\nopen import Data.Fin.Properties as Fin-Props using (pigeonhole)\nopen import Data.List as List using (List; []; _∷_)\nopen import Data.List.Any as Any using (Any; here; there)\nopen import Data.List.Membership.Propositional as ∈L renaming (_∈_ to _∈L_)\nopen import Data.Nat as ℕ\nopen import Data.Nat.Properties as ℕ-Props\nopen import Data.Product as Σ\nopen import Data.Sum as ⊎\nopen import Finite\nimport Finite.Pigeonhole\nopen import Function\nopen import Induction.Nat\nopen import Induction.WellFounded\nimport Level as ℓ\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Binary.PreorderReasoning ≤-preorder\nopen import Relation.Nullary hiding (module Dec)\nopen import Relation.Nullary.Decidable as Dec\nopen import Relation.Nullary.Negation\n\nopen FiniteGraph g\nopen IsFinite\n\ninfix 3 _∈_\ndata _∈_ x : ∀ {a b n} → Path a b n → Set where\n here : ∀ {b c n} {e : Edge x b} {p : Path b c n} → x ∈ e ∷ p\n there : ∀ {a b c n} {e : Edge a b} {p : Path b c n} → x ∈ p → x ∈ e ∷ p\n\ninfix 3 _∈?_\n_∈?_ : ∀ {a b n} x (p : Path a b n) → Dec (x ∈ p)\nx ∈? [] = no λ ()\n_∈?_ {a} x (e ∷ p) =\n case decEqVertex a x of λ where\n (yes refl) → yes here\n (no a≢x) →\n case x ∈? p of λ where\n (yes i) → yes (there i)\n (no ¬i) →\n no λ where\n here → contradiction refl a≢x\n (there i) → contradiction i ¬i\n\nindex : ∀ {a b x n} {p : Path a b n} → x ∈ p → Fin n\nindex here = zero\nindex (there i) = suc (index i)\n\nlookup : ∀ {a b n} → Path a b n → Fin n → Vertex\nlookup {a} (e ∷ p) zero = a\nlookup (e ∷ p) (suc i) = lookup p i\n\n∈-lookup : ∀ {a b n} {p : Path a b n} (i : Fin n) → lookup p i ∈ p\n∈-lookup {p = []} ()\n∈-lookup {p = e ∷ p} zero = here\n∈-lookup {p = e ∷ p} (suc i) = there (∈-lookup i)\n\nfiniteIndex : ∀ {a b n} (p : Path a b n) → Fin n → Fin (size vertexFinite)\nfiniteIndex p = Any.index ∘ membership vertexFinite ∘ lookup p\n\nprefixLength : ∀ {a b x n} {p : Path a b n} → x ∈ p → ℕ\nprefixLength here = zero\nprefixLength (there i) = suc (prefixLength i)\n\nsuffixLength : ∀ {a b x n} {p : Path a b n} → x ∈ p → ℕ\nsuffixLength {n = n} here = n\nsuffixLength (there i) = suffixLength i\n\nsplit : ∀ {a b x n} {p : Path a b n}\n (i : x ∈ p) →\n Path a x (prefixLength i) × Path x b (suffixLength i)\nsplit {p = p} here = [] , p\nsplit {p = e ∷ p} (there i) = Σ.map₁ (e ∷_) (split i)\n\nprefix : ∀ {a b x n} {p : Path a b n} (i : x ∈ p) → Path a x (prefixLength i)\nprefix = proj₁ ∘ split\n\nsuffix : ∀ {a b x n} {p : Path a b n} (i : x ∈ p) → Path x b (suffixLength i)\nsuffix = proj₂ ∘ split\n\nsplitLengthsAddUp : ∀ {a b x n} {p : Path a b n}\n (i : x ∈ p) →\n n ≡ prefixLength i + suffixLength i\nsplitLengthsAddUp here = refl\nsplitLengthsAddUp (there i) = cong suc (splitLengthsAddUp i)\n\ndata Repeats : ∀ {a b n} → Path a b n → Set where\n here : ∀ {a b c n} {e : Edge a b} {p : Path b c n} → a ∈ p → Repeats (e ∷ p)\n there : ∀ {a b c n} {e : Edge a b} {p : Path b c n} → Repeats p → Repeats (e ∷ p)\n\nrepeats? : ∀ {a b n} (p : Path a b n) → Dec (Repeats p)\nrepeats? [] = no λ ()\nrepeats? {a} (e ∷ p) =\n case a ∈? p of λ where\n (yes i) → yes (here i)\n (no ¬i) →\n case repeats? p of λ where\n (yes r) → yes (there r)\n (no ¬r) →\n no λ where\n (here i) → contradiction i ¬i\n (there r) → contradiction r ¬r\n\nAcyclic : ∀ {a b n} → Path a b n → Set\nAcyclic p = ¬ Repeats p\n\nacyclic? : ∀ {a b n} (p : Path a b n) → Dec (Acyclic p)\nacyclic? = ¬? ∘ repeats?\n\ndata Segmented a b : ℕ → Set (ℓᵥ ℓ.⊔ ℓₑ) where\n _◄_◄_ : ∀ {x m n l} →\n Path a x m →\n Path x x (suc n) →\n Path x b l →\n Segmented a b (m + suc n + l)\n\nsegment : ∀ {a b n} {p : Path a b n} → Repeats p → Segmented a b n\nsegment {p = []} ()\nsegment {p = e ∷ p} (here i) rewrite splitLengthsAddUp i = [] ◄ e ∷ prefix i ◄ suffix i\nsegment {p = e ∷ p} (there r) =\n case segment r of λ where\n (p₁ ◄ p₂ ◄ p₃) → (e ∷ p₁) ◄ p₂ ◄ p₃\n\ncutLoop< : ∀ {a b n} {p : Path a b n} → Repeats p → Path< a b n\ncutLoop< r = case segment r of λ where (_◄_◄_ {m = m} p₁ p₂ p₃) → -, lengthLem m , p₁ ++ p₃\n where\n lengthLem : ∀ x {y z} → suc (x + z) ≤ x + suc y + z\n lengthLem zero = s≤s (n≤m+n _ _)\n lengthLem (suc x) = s≤s (lengthLem x)\n\nindicesLoop : ∀ {a b n i j} {p : Path a b n} → i ≢ j → lookup p i ≡ lookup p j → Repeats p\nindicesLoop {i = zero} {zero} {e ∷ p} z≢z eq = contradiction refl z≢z\nindicesLoop {i = zero} {suc j} {e ∷ p} _ refl = here (∈-lookup j)\nindicesLoop {i = suc i} {zero} {e ∷ p} _ refl = here (∈-lookup i)\nindicesLoop {i = suc i} {suc j} {e ∷ p} si≢sj eq = there (indicesLoop (si≢sj ∘ cong suc) eq)\n\nfindLoop : ∀ {a b n} (p : Path a b n) → n > size vertexFinite → Repeats p\nfindLoop p gt =\n let i , j , i≢j , eq = pigeonhole gt (finiteIndex p) in\n indicesLoop i≢j (indexOf-injective vertexFinite eq)\n\nacyclic-length-≤ : ∀ {a b n} (p : Path a b n) → Acyclic p → n ≤ size vertexFinite\nacyclic-length-≤ {n = n} p ¬r =\n case n ≤? size vertexFinite of λ where\n (yes le) → le\n (no ¬le) → contradiction (findLoop p (≰⇒> ¬le)) ¬r\n\nshortenPath : ∀ {a b n} → Path a b n → n > size vertexFinite → Path< a b n\nshortenPath p = cutLoop< ∘ findLoop p\n\nshortenPathEnough : ∀ {a b n}\n (p : Path a b n) →\n n > size vertexFinite →\n Path≤ a b (size vertexFinite)\nshortenPathEnough = <-rec _ wfRec _\n where\n wfRec =\n λ n rec p gt →\n let n′ , le , p′ = shortenPath p gt in\n case size vertexFinite v) → rec _ le p′ n′>v\n (no n′≯v) → -, ≮⇒≥ n′≯v , p′\n\nshortEnoughPath : ∀ {a b n} (p : Path a b n) → Path≤ a b (size vertexFinite)\nshortEnoughPath {n = n} p =\n case size vertexFinite v) → shortenPathEnough p n>v\n (no n≯v) → -, ≮⇒≥ n≯v , p\n\ncutAllLoops : ∀ {a b n} →\n (p : Path a b n) →\n Repeats p →\n ∃ λ (p : Path≤ a b n) → ¬ Repeats (proj₂ (proj₂ p))\ncutAllLoops = <-rec _ wfRec _\n where\n wfRec = λ x rec p r →\n case cutLoop< r of λ where\n (n′ , lt , p′) →\n case repeats? p′ of λ where\n (yes r) →\n case rec _ lt p′ r of λ where\n ((n′′ , le′′ , p′′) , ¬r′′) →\n (n′′ , ≤-trans le′′ (<⇒≤ lt) , p′′) , ¬r′′\n (no ¬r) → (n′ , <⇒≤ lt , p′) , ¬r\n\nacyclicPath : ∀ {a b n} →\n (p : Path a b n) →\n ∃ λ (p : Path≤ a b n) → ¬ Repeats (proj₂ (proj₂ p))\nacyclicPath p =\n case repeats? p of λ where\n (yes r) → cutAllLoops p r\n (no ¬r) → (-, ≤-refl , p) , ¬r\n\nminimalPath : ∀ {a b n} →\n Path a b n →\n ∃ λ (p : Path≤ a b (size vertexFinite)) → ¬ Repeats (proj₂ (proj₂ p))\nminimalPath p =\n let\n x , x≤max , p′ = shortEnoughPath p\n (y , y≤x , p′′) , ¬r = acyclicPath p′\n in\n (y , ≤-trans y≤x x≤max , p′′) , ¬r\n", "meta": {"hexsha": "989624a9e0ec7cc289e607a3d36abd657b659461", "size": 6812, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "src/Data/Graph/Path/Cut.agda", "max_stars_repo_name": "kcsmnt0/graph", "max_stars_repo_head_hexsha": "0196cf8a136a4933cd6358e4c9692aaf919ca603", "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/Data/Graph/Path/Cut.agda", "max_issues_repo_name": "kcsmnt0/graph", "max_issues_repo_head_hexsha": "0196cf8a136a4933cd6358e4c9692aaf919ca603", "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/Data/Graph/Path/Cut.agda", "max_forks_repo_name": "kcsmnt0/graph", "max_forks_repo_head_hexsha": "0196cf8a136a4933cd6358e4c9692aaf919ca603", "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": 33.067961165, "max_line_length": 92, "alphanum_fraction": 0.5609219025, "num_tokens": 2710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.6893056295505783, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.35003757680022984}} {"text": "{-\nThis second-order term syntax was created from the following second-order syntax description:\n\nsyntax TLC | Λ\n\ntype\n N : 0-ary\n _↣_ : 2-ary | r30\n 𝟙 : 0-ary\n _⊗_ : 2-ary | l40\n 𝟘 : 0-ary\n _⊕_ : 2-ary | l30\n\nterm\n app : α ↣ β α -> β | _$_ l20\n lam : α.β -> α ↣ β | ƛ_ r10\n unit : 𝟙\n pair : α β -> α ⊗ β | ⟨_,_⟩\n fst : α ⊗ β -> α\n snd : α ⊗ β -> β\n abort : 𝟘 -> α\n inl : α -> α ⊕ β\n inr : β -> α ⊕ β\n case : α ⊕ β α.γ β.γ -> γ\n ze : N\n su : N -> N\n nrec : N α (α,N).α -> α\n\ntheory\n (ƛβ) b : α.β a : α |> app (lam(x.b[x]), a) = b[a]\n (ƛη) f : α ↣ β |> lam (x. app(f, x)) = f\n (𝟙η) u : 𝟙 |> u = unit\n (fβ) a : α b : β |> fst (pair(a, b)) = a\n (sβ) a : α b : β |> snd (pair(a, b)) = b\n (pη) p : α ⊗ β |> pair (fst(p), snd(p)) = p\n (𝟘η) e : 𝟘 c : α |> abort(e) = c\n (lβ) a : α f : α.γ g : β.γ |> case (inl(a), x.f[x], y.g[y]) = f[a]\n (rβ) b : β f : α.γ g : β.γ |> case (inr(b), x.f[x], y.g[y]) = g[b]\n (cη) s : α ⊕ β c : (α ⊕ β).γ |> case (s, x.c[inl(x)], y.c[inr(y)]) = c[s]\n (zeβ) z : α s : (α,N).α |> nrec (ze, z, r m. s[r,m]) = z\n (suβ) z : α s : (α,N).α n : N |> nrec (su (n), z, r m. s[r,m]) = s[nrec (n, z, r m. s[r,m]), n]\n (ift) t f : α |> if (true, t, f) = t\n (iff) t f : α |> if (false, t, f) = f\n-}\n\n\nmodule TLC.Syntax where\n\nopen import SOAS.Common\nopen import SOAS.Context\nopen import SOAS.Variable\nopen import SOAS.Families.Core\nopen import SOAS.Construction.Structure\nopen import SOAS.ContextMaps.Inductive\n\nopen import SOAS.Metatheory.Syntax\n\nopen import TLC.Signature\n\nprivate\n variable\n Γ Δ Π : Ctx\n α β γ : ΛT\n 𝔛 : Familyₛ\n\n-- Inductive term declaration\nmodule Λ:Terms (𝔛 : Familyₛ) where\n\n data Λ : Familyₛ where\n var : ℐ ⇾̣ Λ\n mvar : 𝔛 α Π → Sub Λ Π Γ → Λ α Γ\n\n _$_ : Λ (α ↣ β) Γ → Λ α Γ → Λ β Γ\n ƛ_ : Λ β (α ∙ Γ) → Λ (α ↣ β) Γ\n unit : Λ 𝟙 Γ\n ⟨_,_⟩ : Λ α Γ → Λ β Γ → Λ (α ⊗ β) Γ\n fst : Λ (α ⊗ β) Γ → Λ α Γ\n snd : Λ (α ⊗ β) Γ → Λ β Γ\n abort : Λ 𝟘 Γ → Λ α Γ\n inl : Λ α Γ → Λ (α ⊕ β) Γ\n inr : Λ β Γ → Λ (α ⊕ β) Γ\n case : Λ (α ⊕ β) Γ → Λ γ (α ∙ Γ) → Λ γ (β ∙ Γ) → Λ γ Γ\n ze : Λ N Γ\n su : Λ N Γ → Λ N Γ\n nrec : Λ N Γ → Λ α Γ → Λ α (α ∙ N ∙ Γ) → Λ α Γ\n\n infixl 20 _$_\n infixr 10 ƛ_\n\n open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛\n\n Λᵃ : MetaAlg Λ\n Λᵃ = record\n { 𝑎𝑙𝑔 = λ where\n (appₒ ⋮ a , b) → _$_ a b\n (lamₒ ⋮ a) → ƛ_ a\n (unitₒ ⋮ _) → unit\n (pairₒ ⋮ a , b) → ⟨_,_⟩ a b\n (fstₒ ⋮ a) → fst a\n (sndₒ ⋮ a) → snd a\n (abortₒ ⋮ a) → abort a\n (inlₒ ⋮ a) → inl a\n (inrₒ ⋮ a) → inr a\n (caseₒ ⋮ a , b , c) → case a b c\n (zeₒ ⋮ _) → ze\n (suₒ ⋮ a) → su a\n (nrecₒ ⋮ a , b , c) → nrec a b c\n ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }\n\n module Λᵃ = MetaAlg Λᵃ\n\n module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where\n\n open MetaAlg 𝒜ᵃ\n\n 𝕤𝕖𝕞 : Λ ⇾̣ 𝒜\n 𝕊 : Sub Λ Π Γ → Π ~[ 𝒜 ]↝ Γ\n 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t\n 𝕊 (t ◂ σ) (old v) = 𝕊 σ v\n 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)\n 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v\n\n 𝕤𝕖𝕞 (_$_ a b) = 𝑎𝑙𝑔 (appₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 (ƛ_ a) = 𝑎𝑙𝑔 (lamₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 unit = 𝑎𝑙𝑔 (unitₒ ⋮ tt)\n 𝕤𝕖𝕞 (⟨_,_⟩ a b) = 𝑎𝑙𝑔 (pairₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)\n 𝕤𝕖𝕞 (fst a) = 𝑎𝑙𝑔 (fstₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (snd a) = 𝑎𝑙𝑔 (sndₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (abort a) = 𝑎𝑙𝑔 (abortₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (inl a) = 𝑎𝑙𝑔 (inlₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (inr a) = 𝑎𝑙𝑔 (inrₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (case a b c) = 𝑎𝑙𝑔 (caseₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b , 𝕤𝕖𝕞 c)\n 𝕤𝕖𝕞 ze = 𝑎𝑙𝑔 (zeₒ ⋮ tt)\n 𝕤𝕖𝕞 (su a) = 𝑎𝑙𝑔 (suₒ ⋮ 𝕤𝕖𝕞 a)\n 𝕤𝕖𝕞 (nrec a b c) = 𝑎𝑙𝑔 (nrecₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b , 𝕤𝕖𝕞 c)\n\n 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Λᵃ 𝒜ᵃ 𝕤𝕖𝕞\n 𝕤𝕖𝕞ᵃ⇒ = record\n { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }\n ; ⟨𝑣𝑎𝑟⟩ = refl\n ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }\n where\n open ≡-Reasoning\n ⟨𝑎𝑙𝑔⟩ : (t : ⅀ Λ α Γ) → 𝕤𝕖𝕞 (Λᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)\n ⟨𝑎𝑙𝑔⟩ (appₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (lamₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (unitₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (pairₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (fstₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (sndₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (abortₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (inlₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (inrₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (caseₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (zeₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (suₒ ⋮ _) = refl\n ⟨𝑎𝑙𝑔⟩ (nrecₒ ⋮ _) = refl\n\n 𝕊-tab : (mε : Π ~[ Λ ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)\n 𝕊-tab mε new = refl\n 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v\n\n module _ (g : Λ ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Λᵃ 𝒜ᵃ g) where\n\n open MetaAlg⇒ gᵃ⇒\n\n 𝕤𝕖𝕞! : (t : Λ α Γ) → 𝕤𝕖𝕞 t ≡ g t\n 𝕊-ix : (mε : Sub Λ Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)\n 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x\n 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v\n 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))\n = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))\n 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩\n\n 𝕤𝕖𝕞! (_$_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (ƛ_ a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! unit = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (⟨_,_⟩ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (fst a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (snd a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (abort a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (inl a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (inr a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (case a b c) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b | 𝕤𝕖𝕞! c = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! ze = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (su a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩\n 𝕤𝕖𝕞! (nrec a b c) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b | 𝕤𝕖𝕞! c = sym ⟨𝑎𝑙𝑔⟩\n\n\n-- Syntax instance for the signature\nΛ:Syn : Syntax\nΛ:Syn = record\n { ⅀F = ⅀F\n ; ⅀:CS = ⅀:CompatStr\n ; mvarᵢ = Λ:Terms.mvar\n ; 𝕋:Init = λ 𝔛 → let open Λ:Terms 𝔛 in record\n { ⊥ = Λ ⋉ Λᵃ\n ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }\n ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }\n\n-- Instantiation of the syntax and metatheory\nopen Syntax Λ:Syn public\nopen Λ:Terms public\nopen import SOAS.Families.Build public\nopen import SOAS.Syntax.Shorthands Λᵃ public\nopen import SOAS.Metatheory Λ:Syn public\n\n-- Derived operations\ntrue : Λ 𝔛 B Γ\ntrue = inl unit\nfalse : Λ 𝔛 B Γ\nfalse = inr unit\nif : Λ 𝔛 B Γ → Λ 𝔛 α Γ → Λ 𝔛 α Γ → Λ 𝔛 α Γ\nif b t e = case b (Theory.𝕨𝕜 _ t) (Theory.𝕨𝕜 _ e)\n\nplus : Λ 𝔛 (N ↣ N ↣ N) Γ\nplus = ƛ (ƛ (nrec x₁ x₀ (su x₀)))\n\nuncurry : Λ 𝔛 ((α ↣ β ↣ γ) ↣ (α ⊗ β) ↣ γ) Γ\nuncurry = ƛ ƛ x₁ $ fst x₀ $ snd x₀\n", "meta": {"hexsha": "3a0b1dc9ac44c7d84babdeeaeba5be710493e9c6", "size": 6620, "ext": "agda", "lang": "Agda", "max_stars_repo_path": "out/TLC/Syntax.agda", "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_issues_repo_path": "out/TLC/Syntax.agda", "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_forks_repo_path": "out/TLC/Syntax.agda", "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "avg_line_length": 29.9547511312, "max_line_length": 100, "alphanum_fraction": 0.4533232628, "num_tokens": 4454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.689305616785446, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.3500375703179442}}