Search is not available for this dataset
text
string
meta
dict
{-# OPTIONS --without-K #-} open import HoTT open import cohomology.CofiberSequence open import cohomology.Exactness open import cohomology.FunctionOver open import cohomology.Theory open import cohomology.ProductRepr open import cohomology.WedgeCofiber {- Finite additivity is provable (and in a stronger form) without using - the additivity axiom. For any m ≥ 0, Cⁿ(Σᵐ(X ∨ Y)) == Cⁿ(ΣᵐX) × Cⁿ(ΣᵐY) - and over this path \ - ∙ Cⁿ(Σᵐwinl) corresponds to fst : Cⁿ(ΣᵐX) × Cⁿ(ΣᵐY) → Cⁿ(ΣᵐX), - ∙ Cⁿ(Σᵐwinr) corresponds to snd : Cⁿ(ΣᵐX) × Cⁿ(ΣᵐY) → Cⁿ(ΣᵐY), - ∙ Cⁿ(Σᵐ(Wedge-rec winl* winr* wglue*)) : Cⁿ(ΣᵐZ) → Cⁿ(Σᵐ(X ∨ Y)) corresponds to Cⁿ(Σᵐwinl*) × Cⁿ(Σᵐwinr*). -} module cohomology.Wedge {i} (CT : CohomologyTheory i) where module CSusp^Wedge (n : ℤ) (X Y : Ptd i) (m : ℕ) where open WedgeCofiber X Y open CohomologyTheory CT open import cohomology.ConstantFunction CT private βl : CF-hom n (⊙susp^-fmap m ⊙winl) ∘ᴳ CF-hom n (⊙susp^-fmap m ⊙projl) == idhom _ βl = ! (CF-comp n (⊙susp^-fmap m ⊙projl) (⊙susp^-fmap m ⊙winl)) ∙ ap (CF-hom n) (! (⊙susp^-fmap-∘ m ⊙projl ⊙winl) ∙ ⊙susp^-fmap-idf m _) ∙ CF-ident n βr : CF-hom n (⊙susp^-fmap m ⊙winr) ∘ᴳ CF-hom n (⊙susp^-fmap m ⊙projr) == idhom _ βr = ! (CF-comp n (⊙susp^-fmap m ⊙projr) (⊙susp^-fmap m ⊙winr)) ∙ ap (CF-hom n) (! (⊙susp^-fmap-∘ m ⊙projr ⊙winr) ∙ ap (⊙susp^-fmap m) ⊙projr-winr ∙ ⊙susp^-fmap-idf m _) ∙ CF-ident n where ⊙projr-winr : ⊙projr ⊙∘ ⊙winr == ⊙idf _ ⊙projr-winr = ⊙λ= (λ _ → idp) $ ∙-unit-r _ ∙ ap-! projr wglue ∙ ap ! Projr.glue-β open ProductRepr (CF-hom n (⊙susp^-fmap m ⊙projl)) (CF-hom n (⊙susp^-fmap m ⊙projr)) (CF-hom n (⊙susp^-fmap m ⊙winl)) (CF-hom n (⊙susp^-fmap m ⊙winr)) (app= (ap GroupHom.f βl)) (app= (ap GroupHom.f βr)) (transport (λ {(_ , f , g) → is-exact (CF n g) (CF n f)}) (suspend^-cof= m ⊙winr ⊙projl (pair= CofWinr.⊙path CofWinr.cfcod-over)) (C-exact n (⊙susp^-fmap m ⊙winr))) (transport (λ {(_ , f , g) → is-exact (CF n g) (CF n f)}) (suspend^-cof= m ⊙winl ⊙projr (pair= CofWinl.⊙path CofWinl.cfcod-over)) (C-exact n (⊙susp^-fmap m ⊙winl))) public wedge-rec-over : {Z : Ptd i} (winl* : fst X → fst Z) (winr* : fst Y → fst Z) (wglue* : winl* (snd X) == winr* (snd Y)) (pt : winl* (snd X) == snd Z) → CF-hom n (⊙susp^-fmap m (WedgeRec.f winl* winr* wglue* , pt)) == ×ᴳ-hom-in (CF-hom n (⊙susp^-fmap m (winl* , pt))) (CF-hom n (⊙susp^-fmap m (winr* , ! wglue* ∙ pt))) [ (λ K → C n (⊙Susp^ m Z) →ᴳ K) ↓ iso ] wedge-rec-over winl* winr* wglue* pt = codomain-over-iso _ _ _ _ $ codomain-over-equiv (fst (CF n (⊙susp^-fmap m (WedgeRec.f winl* winr* wglue* , pt)))) _ ▹ ap2 (λ f g z → (f z , g z)) (ap GroupHom.f $ ! $ ap (CF-hom n) (⊙susp^-fmap-∘ m (rec , pt) ⊙winl) ∙ CF-comp n (⊙susp^-fmap m (rec , pt)) (⊙susp^-fmap m ⊙winl)) (ap GroupHom.f $ ! $ ap (CF-hom n) (ap (⊙susp^-fmap m) (pair= idp (! pt-lemma)) ∙ ⊙susp^-fmap-∘ m (rec , pt) ⊙winr) ∙ CF-comp n (⊙susp^-fmap m (rec , pt)) (⊙susp^-fmap m ⊙winr)) where rec = WedgeRec.f winl* winr* wglue* pt-lemma : ap rec (! wglue) ∙ pt == ! wglue* ∙ pt pt-lemma = ap (λ w → w ∙ pt) $ ap-! rec wglue ∙ ap ! (WedgeRec.glue-β winl* winr* wglue*) wedge-in-over : {Z : Ptd i} (f : fst (⊙Susp^ m Z ⊙→ ⊙Susp^ m (⊙Wedge X Y))) → CF-hom n f == ×ᴳ-sum-hom (C-abelian n _) (CF-hom n (⊙susp^-fmap m ⊙projl ⊙∘ f)) (CF-hom n (⊙susp^-fmap m ⊙projr ⊙∘ f)) [ (λ G → G →ᴳ C n (⊙Susp^ m Z)) ↓ iso ] wedge-in-over f = lemma (C-abelian n _) (C-abelian n _) inl-over inr-over ▹ ap2 (×ᴳ-sum-hom (C-abelian n _)) (! (CF-comp n (⊙susp^-fmap m ⊙projl) f)) (! (CF-comp n (⊙susp^-fmap m ⊙projr) f)) where lemma : {G H K L : Group i} (aG : is-abelian G) (aL : is-abelian L) {p : G == H ×ᴳ K} {φ : H →ᴳ G} {ψ : K →ᴳ G} {χ : G →ᴳ L} → φ == ×ᴳ-inl [ (λ J → H →ᴳ J) ↓ p ] → ψ == ×ᴳ-inr {G = H} [ (λ J → K →ᴳ J) ↓ p ] → χ == ×ᴳ-sum-hom aL (χ ∘ᴳ φ) (χ ∘ᴳ ψ) [ (λ J → J →ᴳ L) ↓ p ] lemma {H = H} {K = K} aG aL {p = idp} {χ = χ} idp idp = ap (λ α → χ ∘ᴳ α) (×ᴳ-sum-hom-η H K aG) ∙ ! (∘-×ᴳ-sum-hom aG aL χ (×ᴳ-inl {G = H}) (×ᴳ-inr {G = H}))
{ "alphanum_fraction": 0.4983720425, "avg_line_length": 37.1532258065, "ext": "agda", "hexsha": "b93d73892b9d147ecad5f3a2107c8b5386031985", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "danbornside/HoTT-Agda", "max_forks_repo_path": "cohomology/Wedge.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "danbornside/HoTT-Agda", "max_issues_repo_path": "cohomology/Wedge.agda", "max_line_length": 75, "max_stars_count": null, "max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "danbornside/HoTT-Agda", "max_stars_repo_path": "cohomology/Wedge.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2183, "size": 4607 }
-- Andreas, 2014-01-17 Issue 1402 -- where clauses after a pointless rewrite open import Common.Equality postulate eq : Set1 ≡ Set1 test : Set1 test rewrite eq = bla where bla = Set -- should succeed (or maybe alert the user of the pointless rewrite)
{ "alphanum_fraction": 0.7354085603, "avg_line_length": 19.7692307692, "ext": "agda", "hexsha": "67453dc2c38e58e5330307005ed8caa1d0b563fc", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue1402.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue1402.agda", "max_line_length": 68, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue1402.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 71, "size": 257 }
open import SystemT open import Data.List using ([]) module Examples where -- λ x . x ex1 : [] ⊢ base ⟶ base ex1 = lam (var i0) -- λ x . λ y . y ex2 : [] ⊢ base ⟶ base ⟶ base ex2 = lam (lam (var i0)) -- λ x . λ y . x ex3 : [] ⊢ base ⟶ base ⟶ base ex3 = lam (lam (var (iS i0)))
{ "alphanum_fraction": 0.5150501672, "avg_line_length": 17.5882352941, "ext": "agda", "hexsha": "4fd81072f7b27afc2c66d33003e65005c67e4ff7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "785c3d1f93ce2dac7801504b806abfd59f3875f6", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "ayberkt/system-t-normalization", "max_forks_repo_path": "examples.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "785c3d1f93ce2dac7801504b806abfd59f3875f6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "ayberkt/system-t-normalization", "max_issues_repo_path": "examples.agda", "max_line_length": 32, "max_stars_count": 3, "max_stars_repo_head_hexsha": "785c3d1f93ce2dac7801504b806abfd59f3875f6", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "ayberkt/system-t-normalization", "max_stars_repo_path": "examples.agda", "max_stars_repo_stars_event_max_datetime": "2016-06-25T03:40:58.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-24T14:36:42.000Z", "num_tokens": 122, "size": 299 }
{- Counting how many structured finite sets with a given cardinal https://github.com/EgbertRijke/OEIS-A000001 -} {-# OPTIONS --safe #-} module Cubical.Experiments.CountingFiniteStructure where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Data.Nat open import Cubical.Data.Bool open import Cubical.Data.Sigma open import Cubical.Data.FinSet open import Cubical.Data.FinSet.Induction open import Cubical.Data.FinSet.Constructors open import Cubical.Data.FinType open import Cubical.Data.FinType.FiniteStructure private variable ℓ : Level -- convenient abbreviation isFinStrCard : (S : FinSet ℓ-zero → FinSet ℓ) (n : ℕ) → isFinType 0 (FinSetWithStrOfCard S n) isFinStrCard S n = isFinTypeFinSetWithStrOfCard S n -- structure that there is no structure TrivialStr : FinSet ℓ → FinSet ℓ TrivialStr _ = 𝟙 -- structure that "picking an element in that set" IdentityStr : FinSet ℓ → FinSet ℓ IdentityStr X = X -- finite semi-groups FinSemiGroupStr : FinSet ℓ → FinSet ℓ FinSemiGroupStr X .fst = Σ[ p ∈ (X .fst → X .fst → X .fst) ] ((x y z : X .fst) → p (p x y) z ≡ p x (p y z)) FinSemiGroupStr X .snd = isFinSetΣ (_ , isFinSetΠ2 X (λ _ → X) (λ _ _ → X)) (λ p → _ , isFinSetΠ3 X (λ _ → X) (λ _ _ → X) (λ _ _ _ → _ , isFinSet≡ X _ _)) -- finite groups FinGroupStr : FinSet ℓ → FinSet ℓ FinGroupStr X .fst = Σ[ e ∈ X .fst ] Σ[ inv ∈ (X .fst → X .fst) ] Σ[ p ∈ (X .fst → X .fst → X .fst) ] ((x y z : X .fst) → p (p x y) z ≡ p x (p y z)) × ((x : X .fst) → (p x e ≡ x) × (p e x ≡ x) × (p (inv x) x ≡ e) × (p x (inv x) ≡ e)) FinGroupStr X .snd = isFinSetΣ X (λ _ → _ , isFinSetΣ (_ , isFinSetΠ X (λ _ → X)) (λ _ → _ , isFinSetΣ (_ , isFinSetΠ2 X (λ _ → X) (λ _ _ → X)) (λ _ → _ , isFinSet× (_ , isFinSetΠ3 X (λ _ → X) (λ _ _ → X) (λ _ _ _ → _ , isFinSet≡ X _ _)) (_ , isFinSetΠ X (λ _ → _ , isFinSet× (_ , isFinSet≡ X _ _) (_ , isFinSet× (_ , isFinSet≡ X _ _) (_ , isFinSet× (_ , isFinSet≡ X _ _) (_ , isFinSet≡ X _ _)))))))) -- two rather trivial numbers -- but the computation is essentially not that trivial -- Time: 5 ms a2 : ℕ a2 = card (_ , isFinStrCard TrivialStr 2) -- this is already hard to compute -- Time: 443 ms b2 : ℕ b2 = card (_ , isFinStrCard IdentityStr 2) -- the number of finite semi-groups numberOfFinSemiGroups : ℕ → ℕ numberOfFinSemiGroups n = card (_ , isFinStrCard FinSemiGroupStr n) -- two trivial cases of semi-groups -- Time: 29 ms n0 : ℕ n0 = numberOfFinSemiGroups 0 -- Time: 2,787ms n1 : ℕ n1 = numberOfFinSemiGroups 1 -- the number of finite semi-groups with cardinal 2 -- it should be 5 -- would you like to try? n2 : ℕ n2 = numberOfFinSemiGroups 2 -- OEIS-A000001 -- I think you'd better not evaluate this function with n > 1 numberOfFinGroups : ℕ → ℕ numberOfFinGroups n = card (_ , isFinStrCard FinGroupStr n) -- group with one element -- Time: 26,925ms g1 : ℕ g1 = numberOfFinGroups 1 -- Rijke's challenge -- seemed to big to do an exhaustive search g4 : ℕ g4 = numberOfFinGroups 4
{ "alphanum_fraction": 0.6448087432, "avg_line_length": 26.5897435897, "ext": "agda", "hexsha": "ba1d56845bdab88c4aa4f2177202e85048557604", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_path": "Cubical/Experiments/CountingFiniteStructure.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/Experiments/CountingFiniteStructure.agda", "max_line_length": 95, "max_stars_count": 1, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Experiments/CountingFiniteStructure.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "num_tokens": 1111, "size": 3111 }
module Types where import Level open import Data.Unit as Unit renaming (tt to ∗) open import Data.List as List open import Categories.Category using (Category) open import Function open import Relation.Binary.PropositionalEquality as PE hiding ([_]; subst) open import Relation.Binary using (module IsEquivalence; Setoid; module Setoid) open ≡-Reasoning Kind = ⊤ import Common.Context Kind as Context open import Common.Context Kind using (Ctx; Var; zero; ctx-cat; ctx-bin-coproducts; _≅V_; ≅V-setoid; Vrefl; Vsym; Vtrans) renaming (succ to succ′) open import Categories.Object.BinaryCoproducts ctx-cat open BinaryCoproducts ctx-bin-coproducts postulate η-≡ : {A : Set} {B : A → Set} {f₁ : (x : A) → B x}{f₂ : (y : A) → B y} → ((x : A) → f₁ x ≡ f₂ x) → f₁ ≡ f₂ TyCtx = Ctx TyVar : Ctx → Set TyVar Γ = Var Γ ∗ succ : ∀{Γ} (x : TyVar Γ) → TyVar (∗ ∷ Γ) succ = Context.succ ∗ open Categories.Category.Category ctx-cat renaming ( _⇒_ to _▹_ ; _≡_ to _≈_ ; _∘_ to _●_ ; id to ctx-id ) -- | Type syntax data Type (Γ : TyCtx) : Set where var : (x : TyVar Γ) → Type Γ _⊕_ : (t₁ : Type Γ) (t₂ : Type Γ) → Type Γ μ : (t : Type (_ ∷ Γ)) → Type Γ _⊗_ : (t₁ : Type Γ) (t₂ : Type Γ) → Type Γ _⇒_ : (t₁ : Type []) (t₂ : Type Γ) → Type Γ ν : (t : Type (_ ∷ Γ)) → Type Γ -- | Congruence for types data _≅T_ {Γ Γ' : Ctx} : Type Γ → Type Γ' → Set where var : ∀{x : TyVar Γ} {x' : TyVar Γ'} → (x ≅V x') → var x ≅T var x' _⊕_ : ∀{t₁ t₂ : Type Γ} {t₁' t₂' : Type Γ'} → (t₁ ≅T t₁') → (t₂ ≅T t₂') → (t₁ ⊕ t₂) ≅T (t₁' ⊕ t₂') _⊗_ : ∀{t₁ t₂ : Type Γ} {t₁' t₂' : Type Γ'} → (t₁ ≅T t₁') → (t₂ ≅T t₂') → (t₁ ⊗ t₂) ≅T (t₁' ⊗ t₂') μ : ∀{t : Type (∗ ∷ Γ)} {t' : Type (∗ ∷ Γ')} → (t ≅T t') → (μ t) ≅T (μ t') _⇒_ : ∀{t₁ t₁' : Type []} {t₂ : Type Γ} {t₂' : Type Γ'} → (t₁ ≅T t₁') → (t₂ ≅T t₂') → (t₁ ⇒ t₂) ≅T (t₁' ⇒ t₂') ν : ∀{t : Type (∗ ∷ Γ)} {t' : Type (∗ ∷ Γ')} → (t ≅T t') → (ν t) ≅T (ν t') Trefl : ∀ {Γ : Ctx} {t : Type Γ} → t ≅T t Trefl {t = var x} = var e.refl where module s = Setoid module e = IsEquivalence (s.isEquivalence ≅V-setoid) Trefl {t = t₁ ⊕ t₂} = Trefl ⊕ Trefl Trefl {t = μ t} = μ Trefl Trefl {t = t ⊗ t₁} = Trefl ⊗ Trefl Trefl {t = t ⇒ t₁} = Trefl ⇒ Trefl Trefl {t = ν t} = ν Trefl Tsym : ∀ {Γ Γ' : Ctx} {t : Type Γ} {t' : Type Γ'} → t ≅T t' → t' ≅T t Tsym (var u) = var (Vsym u) Tsym (u₁ ⊕ u₂) = Tsym u₁ ⊕ Tsym u₂ Tsym (u₁ ⊗ u₂) = Tsym u₁ ⊗ Tsym u₂ Tsym (μ u) = μ (Tsym u) Tsym (u₁ ⇒ u₂) = Tsym u₁ ⇒ Tsym u₂ Tsym (ν u) = ν (Tsym u) Ttrans : ∀ {Γ₁ Γ₂ Γ₃ : Ctx} {t₁ : Type Γ₁} {t₂ : Type Γ₂} {t₃ : Type Γ₃} → t₁ ≅T t₂ → t₂ ≅T t₃ → t₁ ≅T t₃ Ttrans (var u₁) (var u₂) = var (Vtrans u₁ u₂) Ttrans (u₁ ⊕ u₂) (u₃ ⊕ u₄) = Ttrans u₁ u₃ ⊕ Ttrans u₂ u₄ Ttrans (u₁ ⊗ u₂) (u₃ ⊗ u₄) = Ttrans u₁ u₃ ⊗ Ttrans u₂ u₄ Ttrans (μ u₁) (μ u₂) = μ (Ttrans u₁ u₂) Ttrans (u₁ ⇒ u₂) (u₃ ⇒ u₄) = Ttrans u₁ u₃ ⇒ Ttrans u₂ u₄ Ttrans (ν u₁) (ν u₂) = ν (Ttrans u₁ u₂) ≡→≅T : ∀ {Γ : Ctx} {t₁ t₂ : Type Γ} → t₁ ≡ t₂ → t₁ ≅T t₂ ≡→≅T {Γ} {t₁} {.t₁} refl = Trefl -- Note: makes the equality homogeneous in Γ ≅T-setoid : ∀ {Γ} → Setoid _ _ ≅T-setoid {Γ} = record { Carrier = Type Γ ; _≈_ = _≅T_ ; isEquivalence = record { refl = Trefl ; sym = Tsym ; trans = Ttrans } } import Relation.Binary.EqReasoning as EqR module ≅T-Reasoning where module _ {Γ : Ctx} where open EqR (≅T-setoid {Γ}) public hiding (_≡⟨_⟩_) renaming (_≈⟨_⟩_ to _≅T⟨_⟩_; begin_ to beginT_; _∎ to _∎T) -- | Variable renaming in types rename : {Γ Δ : TyCtx} → (ρ : Γ ▹ Δ) → Type Γ → Type Δ rename ρ (var x) = var (ρ ∗ x) rename ρ (t₁ ⊕ t₂) = rename ρ t₁ ⊕ rename ρ t₂ rename {Γ} {Δ} ρ (μ t) = μ (rename ρ' t) where ρ' : (∗ ∷ Γ) ▹ (∗ ∷ Δ) ρ' = ctx-id {[ ∗ ]} ⧻ ρ rename ρ (t₁ ⊗ t₂) = rename ρ t₁ ⊗ rename ρ t₂ rename ρ (t₁ ⇒ t₂) = t₁ ⇒ rename ρ t₂ rename {Γ} {Δ} ρ (ν t) = ν (rename ρ' t) where ρ' : (∗ ∷ Γ) ▹ (∗ ∷ Δ) ρ' = ctx-id {[ ∗ ]} ⧻ ρ ------------------------- ---- Generating structure on contexts (derived from renaming) weaken : {Γ : TyCtx} (Δ : TyCtx) → Type Γ -> Type (Δ ∐ Γ) weaken {Γ} Δ = rename {Γ} {Δ ∐ Γ} (i₂ {Δ} {Γ}) exchange : (Γ Δ : TyCtx) → Type (Γ ∐ Δ) -> Type (Δ ∐ Γ) exchange Γ Δ = rename [ i₂ {Δ} {Γ} , i₁ {Δ} {Γ} ] contract : {Γ : TyCtx} → Type (Γ ∐ Γ) -> Type Γ contract = rename [ ctx-id , ctx-id ] -- weaken-id-empty-ctx : (Δ : TyCtx) (t : GType) → weaken {[]} Δ t ≡ t -- weaken-id-empty-ctx = ? Subst : TyCtx → TyCtx → Set Subst Γ Δ = TyVar Γ → Type Δ id-subst : ∀{Γ : TyCtx} → Subst Γ Γ id-subst x = var x extend : ∀{Γ Δ : TyCtx} → Subst Γ Δ → Type Δ → (Subst (∗ ∷ Γ) Δ) extend σ a zero = a extend σ _ (succ′ _ x) = σ x single-subst : ∀{Γ : TyCtx} → Type Γ → (Subst (∗ ∷ Γ) Γ) single-subst a zero = a single-subst _ (succ′ _ x) = var x lift : ∀{Γ Δ} → Subst Γ Δ → Subst (∗ ∷ Γ) (∗ ∷ Δ) lift σ = extend (weaken [ ∗ ] ∘ σ) (var zero) -- | Simultaneous substitution subst : {Γ Δ : TyCtx} → (σ : Subst Γ Δ) → Type Γ → Type Δ subst σ (var x) = σ x subst σ (t₁ ⊕ t₂) = subst σ t₁ ⊕ subst σ t₂ subst {Γ} {Δ} σ (μ t) = μ (subst (lift σ) t) subst σ (t₁ ⊗ t₂) = subst σ t₁ ⊗ subst σ t₂ subst σ (t₁ ⇒ t₂) = t₁ ⇒ subst σ t₂ subst {Γ} {Δ} σ (ν t) = ν (subst (lift σ) t) subst₀ : {Γ : TyCtx} → Type Γ → Type (∗ ∷ Γ) → Type Γ subst₀ {Γ} a = subst (extend id-subst a) rename′ : {Γ Δ : TyCtx} → (ρ : Γ ▹ Δ) → Type Γ → Type Δ rename′ ρ = subst (var ∘ (ρ ∗)) -- | Ground type GType = Type [] -- | Unfold lfp unfold-μ : (Type [ ∗ ]) → GType unfold-μ a = subst₀ (μ a) a -- | Unfold gfp unfold-ν : (Type [ ∗ ]) → GType unfold-ν a = subst₀ (ν a) a -------------------------------------------------- ---- Examples unit' : GType unit' = ν (var zero) Nat : Type [] Nat = μ ((weaken [ ∗ ] unit') ⊕ x) where x = var zero Str-Fun : {Γ : TyCtx} → Type Γ → Type (∗ ∷ Γ) Str-Fun a = (weaken [ ∗ ] a ⊗ x) where x = var zero Str : {Γ : TyCtx} → Type Γ → Type Γ Str a = ν (Str-Fun a) postulate lem : ∀ {Γ : Ctx} (a : Type Γ) (σ : Subst Γ Γ) → lift (extend σ a) ≡ extend (lift σ) (weaken [ ∗ ] a) lem2 : ∀ {Γ : Ctx} → ctx-id {[ ∗ ]} ⧻ i₂ {[ ∗ ]} {Γ} ≡ i₂ {[ ∗ ]} {∗ ∷ Γ} {- lem {Γ} b σ = begin lift (extend σ b) ≡⟨ refl ⟩ extend (weaken [ ∗ ] ∘ (extend σ b)) (var zero) ≡⟨ {!!} ⟩ extend (extend (weaken [ ∗ ] ∘ σ) (var zero)) (rename {Γ} {[ ∗ ] ∐ Γ} (i₂ {[ ∗ ]} {Γ}) b) ≡⟨ refl ⟩ extend (extend (weaken [ ∗ ] ∘ σ) (var zero)) (weaken [ ∗ ] b) ≡⟨ refl ⟩ extend (lift σ) (weaken [ ∗ ] b) ∎ -} lem3 : ∀ {Γ : Ctx} (a : Type (∗ ∷ Γ)) → rename (ctx-id {[ ∗ ]} ⧻ i₂ {[ ∗ ]} {Γ}) a ≡ weaken [ ∗ ] a lem3 {Γ} a = begin rename (ctx-id {[ ∗ ]} ⧻ i₂ {[ ∗ ]} {Γ}) a ≡⟨ cong (λ x → rename x a) lem2 ⟩ rename {(∗ ∷ Γ)} {∗ ∷ ∗ ∷ Γ} (i₂ {[ ∗ ]}) a ≡⟨ refl ⟩ rename {(∗ ∷ Γ)} {[ ∗ ] ∐ (∗ ∷ Γ)} (i₂ {[ ∗ ]}) a ≡⟨ refl ⟩ weaken [ ∗ ] a ∎ lemma : ∀ {Γ : Ctx} {a b : Type Γ} {σ : Subst Γ Γ} → subst (extend σ b) (weaken [ ∗ ] a) ≅T subst σ a lemma {a = var x} = Trefl lemma {a = a₁ ⊕ a₂} = lemma {a = a₁} ⊕ lemma {a = a₂} lemma {Γ} {μ a} {b} {σ} = μ r where σ' : Subst (∗ ∷ Γ) (∗ ∷ Γ) σ' = lift σ b' : Type (∗ ∷ Γ) b' = weaken [ ∗ ] b a' = rename (ctx-id {[ ∗ ]} ⧻ i₂ {[ ∗ ]} {Γ}) a x : subst (extend σ' b') a' ≅T subst σ' a x = Ttrans (≡→≅T (cong (λ y → subst (extend σ' b') y) (lem3 a))) (lemma {∗ ∷ Γ} {a} {b'} {σ'}) r : subst (lift (extend σ b)) a' ≅T subst (lift σ) a r = Ttrans (≡→≅T (cong (λ y → subst y a') (lem b σ))) x lemma {a = a₁ ⊗ a₂} = lemma {a = a₁} ⊗ lemma {a = a₂} lemma {a = a₁ ⇒ a₂} = Trefl ⇒ lemma {a = a₂} lemma {Γ} {ν a} {b} {σ} = ν r where σ' : Subst (∗ ∷ Γ) (∗ ∷ Γ) σ' = lift σ b' : Type (∗ ∷ Γ) b' = weaken [ ∗ ] b a' = rename (ctx-id {[ ∗ ]} ⧻ i₂ {[ ∗ ]} {Γ}) a x : subst (extend σ' b') a' ≅T subst σ' a x = Ttrans (≡→≅T (cong (λ y → subst (extend σ' b') y) (lem3 a))) (lemma {∗ ∷ Γ} {a} {b'} {σ'}) r : subst (lift (extend σ b)) a' ≅T subst (lift σ) a r = Ttrans (≡→≅T (cong (λ y → subst y a') (lem b σ))) x lift-id-is-id-ext : ∀ {Γ : Ctx} (x : TyVar (∗ ∷ Γ)) → (lift (id-subst {Γ})) x ≡ id-subst x lift-id-is-id-ext zero = refl lift-id-is-id-ext (succ′ ∗ x) = refl lift-id-is-id : ∀ {Γ : Ctx} → lift (id-subst {Γ}) ≡ id-subst lift-id-is-id = η-≡ lift-id-is-id-ext id-subst-id : ∀ {Γ : Ctx} {a : Type Γ} → subst id-subst a ≅T a id-subst-id {a = var x} = var Vrefl id-subst-id {a = a ⊕ a₁} = id-subst-id ⊕ id-subst-id id-subst-id {a = μ a} = μ (Ttrans (≡→≅T (cong (λ u → subst u a) lift-id-is-id)) id-subst-id) id-subst-id {a = a ⊗ a₁} = id-subst-id ⊗ id-subst-id id-subst-id {a = a ⇒ a₁} = Trefl ⇒ id-subst-id id-subst-id {a = ν a} = ν (Ttrans (≡→≅T (cong (λ u → subst u a) lift-id-is-id)) id-subst-id) lemma₂ : ∀ {Γ : Ctx} {a b : Type Γ} → subst (extend id-subst b) (weaken [ ∗ ] a) ≅T a lemma₂ {Γ} {a} {b} = Ttrans (lemma {Γ} {a} {b} {σ = id-subst}) id-subst-id unfold-str : ∀{a : Type []} → (unfold-ν (Str-Fun a)) ≅T (a ⊗ Str a) unfold-str {a} = lemma₂ ⊗ Trefl LFair : {Γ : TyCtx} → Type Γ → Type Γ → Type Γ LFair a b = ν (μ ((w a ⊗ x) ⊕ (w b ⊗ y))) where x = var zero y = var (succ zero) Δ = ∗ ∷ [ ∗ ] w = weaken Δ
{ "alphanum_fraction": 0.4803502554, "avg_line_length": 31.0453074434, "ext": "agda", "hexsha": "2bea7f337d8b11441bb5d95d27802718536d22cd", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_path": "TypeTheory/SimpleOTT/Types.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_path": "TypeTheory/SimpleOTT/Types.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_path": "TypeTheory/SimpleOTT/Types.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4402, "size": 9593 }
-- Simple test to check if constraint solving for injective -- functions is working. module Injectivity where data Nat : Set where zero : Nat suc : Nat -> Nat _+_ : Nat -> Nat -> Nat zero + m = m suc n + m = suc (n + m) {-# BUILTIN NATURAL Nat #-} {-# BUILTIN ZERO zero #-} {-# BUILTIN SUC suc #-} {-# BUILTIN NATPLUS _+_ #-} infixr 40 _::_ data List (A : Set) : Set where [] : List A _::_ : A -> List A -> List A foldr : {A B : Set} -> (A -> B -> B) -> B -> List A -> B foldr f z [] = z foldr f z (x :: xs) = f x (foldr f z xs) data U : Set where nat : U list : U -> U El : U -> Set El nat = Nat El (list a) = List (El a) sum : {a : U} -> El a -> Nat sum {nat} n = n sum {list a} xs = foldr (\a b -> sum a + b) zero xs data _==_ {A : Set}(x : A) : A -> Set where refl : x == x test₁ = sum (1 :: 2 :: 3 :: []) ok₁ : test₁ == 6 ok₁ = refl test₂ = sum ((1 :: []) :: (3 :: 5 :: []) :: []) ok₂ : test₂ == 9 ok₂ = refl
{ "alphanum_fraction": 0.4964028777, "avg_line_length": 18.7115384615, "ext": "agda", "hexsha": "c9aafa6d9ee1effab2cdc4dc7e0777f3a1172ce1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "test/succeed/Injectivity.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "test/succeed/Injectivity.agda", "max_line_length": 59, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/Injectivity.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T07:26:06.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T07:26:06.000Z", "num_tokens": 365, "size": 973 }
{-# OPTIONS --cubical --safe #-} module Cubical.Data.SumFin.Base where open import Cubical.Foundations.Prelude open import Cubical.Data.Empty using (⊥; ⊥-elim) public open import Cubical.Data.Unit using (tt) renaming (Unit to ⊤) public open import Cubical.Data.Sum using (_⊎_; inl; inr) public open import Cubical.Data.Nat open import Cubical.Relation.Nullary open import Cubical.Relation.Nullary.DecidableEq private variable k : ℕ Fin : ℕ → Type₀ Fin zero = ⊥ Fin (suc n) = ⊤ ⊎ (Fin n) pattern fzero = inl tt pattern fsuc n = inr n finj : Fin k → Fin (suc k) finj {suc k} fzero = fzero finj {suc k} (fsuc n) = fsuc (finj {k} n) toℕ : Fin k → ℕ toℕ {suc k} (inl tt) = zero toℕ {suc k} (inr x) = suc (toℕ {k} x) toℕ-injective : {m n : Fin k} → toℕ m ≡ toℕ n → m ≡ n toℕ-injective {suc k} {fzero} {fzero} _ = refl toℕ-injective {suc k} {fzero} {fsuc x} p = ⊥-elim (znots p) toℕ-injective {suc k} {fsuc m} {fzero} p = ⊥-elim (snotz p) toℕ-injective {suc k} {fsuc m} {fsuc x} p = cong fsuc (toℕ-injective (injSuc p)) -- Thus, Fin k is discrete discreteFin : Discrete (Fin k) discreteFin fj fk with discreteℕ (toℕ fj) (toℕ fk) ... | yes p = yes (toℕ-injective p) ... | no ¬p = no (λ p → ¬p (cong toℕ p)) isSetFin : isSet (Fin k) isSetFin = Discrete→isSet discreteFin
{ "alphanum_fraction": 0.6606864275, "avg_line_length": 27.8695652174, "ext": "agda", "hexsha": "9df85e0e61a1b1355fcf4123a6f9f0afec58abf8", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_path": "Cubical/Data/SumFin/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "limemloh/cubical", "max_issues_repo_path": "Cubical/Data/SumFin/Base.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_path": "Cubical/Data/SumFin/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 516, "size": 1282 }
module Issue318 where data Bool : Set where module A where data _≤_ : Bool → Bool → Set where open A hiding (_≤_) data _≤_ : Bool → Bool → Set where
{ "alphanum_fraction": 0.6753246753, "avg_line_length": 15.4, "ext": "agda", "hexsha": "b50c6f297dd0cf647d588ac39b680cf169580ba9", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/fail/Issue318.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/fail/Issue318.agda", "max_line_length": 36, "max_stars_count": 1, "max_stars_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "np/agda-git-experiment", "max_stars_repo_path": "test/fail/Issue318.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 49, "size": 154 }
module NestedProjectRoots where import Imports.A
{ "alphanum_fraction": 0.86, "avg_line_length": 12.5, "ext": "agda", "hexsha": "a4e479ea7f3115eea32377405b47b11c5d002e10", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/customised/NestedProjectRoots.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/customised/NestedProjectRoots.agda", "max_line_length": 31, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/customised/NestedProjectRoots.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 11, "size": 50 }
{-# OPTIONS --guardedness-preserving-type-constructors #-} module TypeConstructorsWhichPreserveGuardedness4 where open import Common.Coinduction data Rec (A : ∞ Set) : Set where fold : ♭ A → Rec A D : Set D = Rec (♯ (D → D)) -- _·_ : D → D → D -- fold f · x = f x -- ω : D -- ω = fold (λ x → x · x) -- Ω : D -- Ω = ω · ω
{ "alphanum_fraction": 0.5757575758, "avg_line_length": 15.7142857143, "ext": "agda", "hexsha": "5e6af3942ab4110874fbfe9365a8c2b54477b311", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/TypeConstructorsWhichPreserveGuardedness4.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "hborum/agda", "max_issues_repo_path": "test/Fail/TypeConstructorsWhichPreserveGuardedness4.agda", "max_line_length": 58, "max_stars_count": 3, "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "hborum/agda", "max_stars_repo_path": "test/Fail/TypeConstructorsWhichPreserveGuardedness4.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 125, "size": 330 }
{-# OPTIONS --cubical --safe #-} module Class where open import Cubical.Core.Everything open import Function.Base using (id; _$_) private variable A B C : Set ℓ ℓ′ ℓ″ : Level -- Custom non-dependent definition, since the one in the prelude is too general _∘_ : {A : Set ℓ} {B : Set ℓ′} {C : Set ℓ″} → (B → C) → (A → B) → A → C (f ∘ g) x = f (g x) infixr 9 _∘_ record Functor (F : Set → Set₁) : Set₂ where field fmap : (A → B) → F A → F B fmap-id-legit : (m : F A) → fmap id m ≡ m fmap-compose-legit : (m : F A) → (f : B → C) → (g : A → B) → fmap (f ∘ g) m ≡ fmap f (fmap g m) _<$>_ : (A → B) → F A → F B f <$> x = fmap f x open Functor record Applicative (F : Set → Set₁) : Set₂ where infixl 4 _<*>_ field functor : Functor F pure : A → F A _<*>_ : F (A → B) → F A → F B app-identity : (v : F A) → (pure id <*> v) ≡ v app-compose : (u : F (B → C)) → (v : F (A → B)) → (w : F A) → (pure _∘_ <*> u <*> v <*> w) ≡ (u <*> (v <*> w)) app-homo : (f : A → B) → (x : A) → (pure f <*> pure x) ≡ pure (f x) app-intchg : (u : F (A → B)) → (y : A) → (u <*> pure y) ≡ (pure (_$ y) <*> u) open Functor functor public record Monad (M : Set → Set₁) : Set₂ where infixl 1 _>>=_ field applicative : Applicative M _>>=_ : M A → (A → M B) → M B open Applicative applicative public return : A → M A return = pure field monad-left-id : (a : A) → (f : A → M B) → (return a >>= f) ≡ f a monad-right-id : (m : M A) → (m >>= return) ≡ m monad-assoc : (m : M A) → (f : A → M B) → (g : B → M C) → (m >>= f >>= g) ≡ (m >>= (λ x → f x >>= g))
{ "alphanum_fraction": 0.4471590909, "avg_line_length": 21.4634146341, "ext": "agda", "hexsha": "49f3c127b15a601953f6106af52c13b8207962c7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "13364fa4af25720bf1d73bf960e8c04ebb34762f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mb64/cubical-free-monads", "max_forks_repo_path": "Class.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "13364fa4af25720bf1d73bf960e8c04ebb34762f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mb64/cubical-free-monads", "max_issues_repo_path": "Class.agda", "max_line_length": 79, "max_stars_count": 1, "max_stars_repo_head_hexsha": "13364fa4af25720bf1d73bf960e8c04ebb34762f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mb64/cubical-free-monads", "max_stars_repo_path": "Class.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-17T17:53:44.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-17T17:53:44.000Z", "num_tokens": 696, "size": 1760 }
{- The equivalent "goodness" of can w.r.t. the rmerge reduction. The lemma proved in this file is can-irr : ∀ {BV} {FV} θ₁ θ₂ q → CorrectBinding q BV FV → (distinct' (proj₁ FV) (proj₁ (Dom θ₂))) → Can q θ₁ ≡ Can q (θ₁ ← θ₂) That is, the result of the Can function will not change provided that the program does not refer to any variables in the new environment. -} module Esterel.Lang.CanFunction.MergePotentialRuleCan where open import utility open import Esterel.Lang open import Esterel.Lang.Binding open import Esterel.Lang.CanFunction open import Esterel.Lang.CanFunction.Base open import Esterel.Context open import Esterel.Context.Properties using (plug ; unplug) open import Esterel.Environment as Env using (Env ; Θ ; _←_ ; Dom ; module SigMap ; module ShrMap ; module VarMap) open import Esterel.CompletionCode as Code using () renaming (CompletionCode to Code) open import Esterel.Variable.Signal as Signal using (Signal ; _ₛ) open import Esterel.Variable.Shared as SharedVar using (SharedVar ; _ₛₕ) open import Esterel.Variable.Sequential as SeqVar using (SeqVar) open import Data.Bool using (Bool ; true ; false ; if_then_else_) open import Data.Empty using (⊥ ; ⊥-elim) open import Data.List using (List ; [] ; _∷_ ; _++_ ; map ; concatMap) open import Data.List.Properties using (map-id) open import Data.List.Any using (Any ; any ; here ; there) open import Data.List.Any.Properties using () renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ) open import Data.Maybe using (Maybe ; just ; nothing) open import Data.Nat using (ℕ ; zero ; suc ; _≟_ ; _+_) open import Data.Nat.Properties.Simple using (+-comm) open import Data.Product using (Σ ; proj₁ ; proj₂ ; ∃ ; _,_ ; _,′_ ; _×_) open import Data.Sum using (_⊎_ ; inj₁ ; inj₂) open import Function using (_∘_ ; _∋_ ; id) open import Relation.Nullary using (¬_ ; Dec ; yes ; no) open import Relation.Nullary.Decidable using (⌊_⌋) open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; trans ; sym ; cong ; subst) open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM open ListSet Data.Nat._≟_ using (set-subtract ; set-subtract-[] ; set-subtract-split ; set-subtract-merge ; set-subtract-notin ; set-remove-mono-∈ ; set-remove-removed ; set-remove-not-removed) can-new-irr : ∀ {BV} {FV} θ₁ θ₂ θo q → CorrectBinding q BV FV → (∀ S' → S' ∈ (proj₁ FV) → (S' ∉ proj₁ (Dom θ₂)) ⊎ (S' ∈ proj₁ (Dom θo))) → Can q (θ₁ ← θo) ≡ Can q ((θ₁ ← θ₂) ← θo) canθ-new-irr : ∀ {BV} {FV} sigs S θ₁ θ₂ θo q → CorrectBinding q BV FV → (∀ S' → S' ∈ (proj₁ FV) → ((S' ∉ proj₁ (Dom θ₂)) ⊎ (S' ∈ proj₁ (Dom θo))) ⊎ S' ∈ map (_+_ S) (SigMap.keys sigs)) → Canθ sigs S q (θ₁ ← θo) ≡ Canθ sigs S q ((θ₁ ← θ₂) ← θo) can-new-irr θ₁ θ₂ θo nothin CBnothing S-prop = refl can-new-irr θ₁ θ₂ θo pause CBpause S-prop = refl can-new-irr θ₁ θ₂ θo (signl S q) (CBsig cbq) S-prop rewrite canθ-new-irr (Env.sig ([S]-env S)) 0 θ₁ θ₂ θo q cbq (λ S' S'∈FV → Data.Sum.map (S-prop S') (subst (S' ∈_) (sym (map-id (proj₁ (Dom ([S]-env S))))) ∘ (λ S'∈[S] → subst (_∈ proj₁ (Dom ([S]-env S))) (sym (∈:: S'∈[S])) (Env.sig-∈-single S Signal.unknown))) (set-subtract-split {ys = Signal.unwrap S ∷ []} S'∈FV)) = refl can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent {FVp = FVp} cbp cbq) S-prop with S-prop (Signal.unwrap S) (here refl)| Env.Sig∈ S (θ₁ ← θo) | Env.Sig∈ S ((θ₁ ← θ₂) ← θo) ... | inj₂ S∈Domθo | no S∉domθ₁←θo | S∈domθ₁←θ₂←θo? = ⊥-elim (S∉domθ₁←θo (Env.sig-←-monoʳ S θo θ₁ S∈Domθo)) ... | inj₂ S∈Domθo | yes S∈domθ₁←θo | no S∉domθ₁←θ₂←θo = ⊥-elim (S∉domθ₁←θ₂←θo (Env.sig-←-monoʳ S θo (θ₁ ← θ₂) S∈Domθo)) ... | inj₂ S∈Domθo | yes S∈domθ₁←θo | yes S∈domθ₁←θ₂←θo rewrite SigMap.∈-get-U-irr-m S (Env.sig θ₁) (Env.sig (θ₁ ← θ₂)) (Env.sig θo) S∈domθ₁←θo S∈domθ₁←θ₂←θo S∈Domθo with Env.sig-stats {S} ((θ₁ ← θ₂) ← θo) S∈domθ₁←θ₂←θo ... | Signal.present = can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp))) ... | Signal.absent = can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq)) ... | Signal.unknown rewrite can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp))) | can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq)) = refl can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent {FVp = FVp} cbp cbq) S-prop | inj₁ S∉Domθ₂ | yes S∈domθ₁←θo | yes S∈domθ₁←θ₂←θo with Env.sig-←⁻ {θ₁} {θo} S S∈domθ₁←θo ... | inj₂ S∈Domθo rewrite SigMap.∈-get-U-irr-m S (Env.sig θ₁) (Env.sig (θ₁ ← θ₂)) (Env.sig θo) S∈domθ₁←θo S∈domθ₁←θ₂←θo S∈Domθo with Env.sig-stats {S} ((θ₁ ← θ₂) ← θo) S∈domθ₁←θ₂←θo ... | Signal.present = can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp))) ... | Signal.absent = can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq)) ... | Signal.unknown rewrite can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp))) | can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq)) = refl can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent {FVp = FVp} cbp cbq) S-prop | inj₁ S∉Domθ₂ | yes S∈domθ₁←θo | yes S∈domθ₁←θ₂←θo | inj₁ S∈domθ₁ with Env.sig-←-irr-get {θ₁} {θ₂} {S} S∈domθ₁ S∉Domθ₂ ... | a , b rewrite SigMap.get-U-both-irr-m S (Env.sig θ₁) (Env.sig (θ₁ ← θ₂)) (Env.sig θo) S∈domθ₁ a S∈domθ₁←θo S∈domθ₁←θ₂←θo b with Env.sig-stats {S} ((θ₁ ← θ₂) ← θo) S∈domθ₁←θ₂←θo ... | Signal.present = can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp))) ... | Signal.absent = can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq)) ... | Signal.unknown rewrite can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp))) | can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq)) = refl can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent cbp cbq) S-prop | inj₁ S∉Domθ₂ | yes S∈domθ₁←θo | no S∉domθ₁←θ₂←θo rewrite SigMap.keys-assoc-comm (Env.sig θ₁) (Env.sig θ₂) (Env.sig θo) = ⊥-elim (S∉domθ₁←θ₂←θo (SigMap.U-mono {m = Env.sig (θ₁ ← θo)} {k = S} S∈domθ₁←θo)) can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent cbp cbq) S-prop | inj₁ S∉Domθ₂ | no S∉domθ₁←θo | yes S∈domθ₁←θ₂←θo with Env.sig-←⁻ {θ₁ ← θo} {θ₂} S (subst (Signal.unwrap S ∈_) (SigMap.keys-assoc-comm (Env.sig θ₁) (Env.sig θ₂) (Env.sig θo)) S∈domθ₁←θ₂←θo) ... | (inj₁ S∈Domθ₁←θo) = ⊥-elim (S∉domθ₁←θo S∈Domθ₁←θo) ... | (inj₂ S∈Domθ₂) = ⊥-elim (S∉Domθ₂ S∈Domθ₂) can-new-irr θ₁ θ₂ θo (present S ∣⇒ p ∣⇒ q) (CBpresent {FVp = FVp} cbp cbq) S-prop | inj₁ S∉Domθ₂ | no S∉domθ₁←θo | no S∉domθ₁←θ₂←θo rewrite can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ʳ (Signal.unwrap S ∷ []) (++ˡ S'∈FVp))) | can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (Signal.unwrap S ∷ proj₁ FVp) S'∈FVq)) = refl can-new-irr θ₁ θ₂ θo (emit S) CBemit S-prop = refl can-new-irr θ₁ θ₂ θo (p ∥ q) (CBpar {FVp = FVp} cbp cbq BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) S-prop rewrite can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ˡ S'∈FVp)) | can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (proj₁ FVp) S'∈FVq)) = refl can-new-irr θ₁ θ₂ θo (loop q) (CBloop cbq BV≠FV) S-prop = can-new-irr θ₁ θ₂ θo q cbq S-prop can-new-irr θ₁ θ₂ θo (loopˢ p q) (CBloopˢ {BVp = BVp} {FVp = FVp} CBp CBq BVp≠FVq BVq≠FVq) S-prop rewrite can-new-irr θ₁ θ₂ θo p CBp (λ S' S'∈FVp → S-prop S' (++ˡ S'∈FVp)) | can-new-irr θ₁ θ₂ θo q CBq (λ S' S'∈FVq → S-prop S' (++ʳ (proj₁ FVp) S'∈FVq)) = refl can-new-irr θ₁ θ₂ θo (p >> q) (CBseq {BVp = BVp} {FVp = FVp} cbp cbq BVp≠FVq) S-prop with can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ˡ S'∈FVp)) ... | can-p-θ₁←θo≡can-p-θ₁←θ₂←θo with any (Code._≟_ Code.nothin) (Canₖ p (θ₁ ← θo)) | any (Code._≟_ Code.nothin) (Canₖ p ((θ₁ ← θ₂) ← θo)) ... | yes nothin∈can-p-θ₁←θo | yes nothin∈can-p-θ₁←θ₂←θo rewrite can-p-θ₁←θo≡can-p-θ₁←θ₂←θo | can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (proj₁ FVp) S'∈FVq)) = refl ... | yes nothin∈can-p-θ₁←θo | no nothin∉can-p-θ₁←θ₂←θo = ⊥-elim (nothin∉can-p-θ₁←θ₂←θo (subst (λ xs → Code.nothin ∈ proj₁ (proj₂ xs)) can-p-θ₁←θo≡can-p-θ₁←θ₂←θo nothin∈can-p-θ₁←θo)) ... | no nothin∉can-p-θ₁←θo | yes nothin∈can-p-θ₁←θ₂←θo = ⊥-elim (nothin∉can-p-θ₁←θo (subst (λ xs → Code.nothin ∈ proj₁ (proj₂ xs)) (sym can-p-θ₁←θo≡can-p-θ₁←θ₂←θo) nothin∈can-p-θ₁←θ₂←θo)) ... | no nothin∉can-p-θ₁←θo | no nothin∉can-p-θ₁←θ₂←θo rewrite can-p-θ₁←θo≡can-p-θ₁←θ₂←θo = refl can-new-irr θ₁ θ₂ θo (suspend q S) (CBsusp cbq [S]≠BVp) S-prop = can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FV → S-prop S' (there S'∈FV)) can-new-irr θ₁ θ₂ θo (exit n) CBexit S-prop = refl can-new-irr θ₁ θ₂ θo (trap q) (CBtrap cbq) S-prop rewrite can-new-irr θ₁ θ₂ θo q cbq S-prop = refl can-new-irr θ₁ θ₂ θo (shared s ≔ e in: q) (CBshared {FV = FV} cbq) S-prop rewrite set-subtract-[] (proj₁ FV) | can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FV → S-prop S' (++ʳ (proj₁ (FVₑ e)) S'∈FV)) = refl can-new-irr θ₁ θ₂ θo (s ⇐ e) CBsset S-prop = refl can-new-irr θ₁ θ₂ θo (var x ≔ e in: q) (CBvar {FV = FV} cbq) S-prop rewrite set-subtract-[] (proj₁ FV) = can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FV → S-prop S' (++ʳ (proj₁ (FVₑ e)) S'∈FV)) can-new-irr θ₁ θ₂ θo (x ≔ e) CBvset S-prop = refl can-new-irr θ₁ θ₂ θo (if x ∣⇒ p ∣⇒ q) (CBif {FVp = FVp} cbp cbq) S-prop rewrite can-new-irr θ₁ θ₂ θo p cbp (λ S' S'∈FVp → S-prop S' (++ˡ S'∈FVp)) | can-new-irr θ₁ θ₂ θo q cbq (λ S' S'∈FVq → S-prop S' (++ʳ (proj₁ FVp) S'∈FVq)) = refl can-new-irr θ₁ θ₂ θo (ρ⟨ θ , A ⟩· q) (CBρ {FV = FV} cbq) S-prop rewrite canθ-new-irr (Env.sig θ) 0 θ₁ θ₂ θo q cbq (λ S' S'∈FV → Data.Sum.map (S-prop S') (subst (S' ∈_) (sym (map-id (proj₁ (Dom θ))))) (set-subtract-split {ys = proj₁ (Dom θ)} S'∈FV)) = refl canθ-new-irr-S-prop-accumulate : ∀ {xs ys zs} S status θo → (∀ S' → S' ∈ xs → (S' ∉ ys ⊎ S' ∈ proj₁ (Dom θo)) ⊎ S' ∈ (S + 0 ∷ map (_+_ S) (map suc zs))) → ∀ S' → S' ∈ xs → (S' ∉ ys ⊎ S' ∈ proj₁ (Dom (θo ← [ (S ₛ) ↦ status ]))) ⊎ S' ∈ map (_+_ (suc S)) zs canθ-new-irr-S-prop-accumulate {zs = zs} S status θo S-prop S' S'∈xs with S-prop S' S'∈xs ... | inj₁ (inj₁ S'∉ys) = inj₁ (inj₁ S'∉ys) ... | inj₁ (inj₂ S'∈Domθo) = inj₁ (inj₂ (Env.sig-←-monoˡ (S' ₛ) θo [ (S ₛ) ↦ status ] S'∈Domθo)) ... | inj₂ (here refl) rewrite +-comm S 0 = inj₁ (inj₂ (Env.sig-←-monoʳ (S ₛ) [ S ₛ ↦ status ] θo (Env.sig-∈-single (S ₛ) status))) ... | inj₂ (there S'∈map-+-S-suc-zs) rewrite map-+-compose-suc S zs = inj₂ S'∈map-+-S-suc-zs canθ-new-irr {BV} {FV} [] S θ₁ θ₂ θo q cbq S-prop = can-new-irr θ₁ θ₂ θo q cbq S-prop' where S-prop' : ∀ S' → S' ∈ proj₁ FV → S' ∉ proj₁ (Dom θ₂) ⊎ S' ∈ proj₁ (Dom θo) S-prop' S' S'∈FV with S-prop S' S'∈FV ... | inj₁ S'∉Domθ₂⊎S'∈Domθo = S'∉Domθ₂⊎S'∈Domθo ... | inj₂ () canθ-new-irr (nothing ∷ sigs) S θ₁ θ₂ θo q cbq S-prop = canθ-new-irr sigs (suc S) θ₁ θ₂ θo q cbq (λ S' S'∈FV → Data.Sum.map id (subst (S' ∈_) (map-+-compose-suc S (SigMap.keys sigs))) (S-prop S' S'∈FV)) canθ-new-irr (just Signal.present ∷ sigs) S θ₁ θ₂ θo q cbq S-prop rewrite sym (Env.←-assoc θ₁ θo ([S]-env-present (S ₛ))) | sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env-present (S ₛ))) = canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env-present (S ₛ)) q cbq (canθ-new-irr-S-prop-accumulate S Signal.present θo S-prop) canθ-new-irr (just Signal.absent ∷ sigs) S θ₁ θ₂ θo q cbq S-prop rewrite sym (Env.←-assoc θ₁ θo ([S]-env-absent (S ₛ))) | sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env-absent (S ₛ))) = canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env-absent (S ₛ)) q cbq (canθ-new-irr-S-prop-accumulate S Signal.absent θo S-prop) canθ-new-irr (just Signal.unknown ∷ sigs) S θ₁ θ₂ θo q cbq S-prop with any (_≟_ S) (Canθₛ sigs (suc S) q ((θ₁ ← θo) ← [S]-env (S ₛ))) | any (_≟_ S) (Canθₛ sigs (suc S) q (((θ₁ ← θ₂) ← θo) ← [S]-env (S ₛ))) ... | yes S∈canθ-sigs-q-θ₁←θo←[S] | yes S∈canθ-sigs-q-θ₁←θ₂←θo←[S] rewrite sym (Env.←-assoc θ₁ θo ([S]-env (S ₛ))) | sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env (S ₛ))) = canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env (S ₛ)) q cbq (canθ-new-irr-S-prop-accumulate S Signal.unknown θo S-prop) ... | no S∉canθ-sigs-q-θ₁←θo←[S] | no S∉canθ-sigs-q-θ₁←θ₂←θo←[S] rewrite sym (Env.←-assoc θ₁ θo ([S]-env-absent (S ₛ))) | sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env-absent (S ₛ))) = canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env-absent (S ₛ)) q cbq (canθ-new-irr-S-prop-accumulate S Signal.absent θo S-prop) ... | yes S∈canθ-sigs-q-θ₁←θo←[S] | no S∉canθ-sigs-q-θ₁←θ₂←θo←[S] rewrite sym (Env.←-assoc θ₁ θo ([S]-env (S ₛ))) | sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env (S ₛ))) | canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env (S ₛ)) q cbq (canθ-new-irr-S-prop-accumulate S Signal.unknown θo S-prop) = ⊥-elim (S∉canθ-sigs-q-θ₁←θ₂←θo←[S] S∈canθ-sigs-q-θ₁←θo←[S]) ... | no S∉canθ-sigs-q-θ₁←θo←[S] | yes S∈canθ-sigs-q-θ₁←θ₂←θo←[S] rewrite sym (Env.←-assoc θ₁ θo ([S]-env (S ₛ))) | sym (Env.←-assoc (θ₁ ← θ₂) θo ([S]-env (S ₛ))) | canθ-new-irr sigs (suc S) θ₁ θ₂ (θo ← [S]-env (S ₛ)) q cbq (canθ-new-irr-S-prop-accumulate S Signal.unknown θo S-prop) = ⊥-elim (S∉canθ-sigs-q-θ₁←θo←[S] S∈canθ-sigs-q-θ₁←θ₂←θo←[S]) can-irr : ∀ {BV} {FV} θ₁ θ₂ q → CorrectBinding q BV FV → (distinct' (proj₁ FV) (proj₁ (Dom θ₂))) → Can q θ₁ ≡ Can q (θ₁ ← θ₂) can-irr θ₁ θ₂ q cbq FV≠Domθ₂ with can-new-irr θ₁ θ₂ Env.[]env q cbq (λ S' S'∈FV → inj₁ (FV≠Domθ₂ S' S'∈FV)) ... | eq rewrite cong (Can q) (Env.←-comm Env.[]env θ₁ distinct-empty-left) | cong (Can q) (Env.←-comm Env.[]env (θ₁ ← θ₂) distinct-empty-left) = eq
{ "alphanum_fraction": 0.5686790924, "avg_line_length": 46.5660377358, "ext": "agda", "hexsha": "500cf338e0a86cd85390fd32274db1d8d435a34b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z", "max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z", "max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "florence/esterel-calculus", "max_forks_repo_path": "agda/Esterel/Lang/CanFunction/MergePotentialRuleCan.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "florence/esterel-calculus", "max_issues_repo_path": "agda/Esterel/Lang/CanFunction/MergePotentialRuleCan.agda", "max_line_length": 128, "max_stars_count": 3, "max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "florence/esterel-calculus", "max_stars_repo_path": "agda/Esterel/Lang/CanFunction/MergePotentialRuleCan.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z", "num_tokens": 7189, "size": 14808 }
------------------------------------------------------------------------ -- Properties related to Fin, and operations making use of these -- properties (or other properties not available in Data.Fin) ------------------------------------------------------------------------ module Data.Fin.Props where open import Data.Fin open import Data.Nat as N using (ℕ; zero; suc; s≤s; z≤n) renaming (_≤_ to _ℕ≤_; _<_ to _ℕ<_; _+_ to _ℕ+_) open N.≤-Reasoning import Data.Nat.Properties as N open import Data.Function open import Relation.Nullary open import Relation.Unary open import Relation.Binary open import Relation.Binary.FunctionSetoid open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; cong; subst) open import Category.Functor open import Category.Applicative ------------------------------------------------------------------------ -- Properties private drop-suc : ∀ {o} {m n : Fin o} → suc m ≡ (Fin (suc o) ∶ suc n) → m ≡ n drop-suc refl = refl preorder : ℕ → Preorder preorder n = PropEq.preorder (Fin n) setoid : ℕ → Setoid setoid n = PropEq.setoid (Fin n) strictTotalOrder : ℕ → StrictTotalOrder strictTotalOrder n = record { carrier = Fin n ; _≈_ = _≡_ ; _<_ = _<_ ; isStrictTotalOrder = record { isEquivalence = PropEq.isEquivalence ; trans = N.<-trans ; compare = cmp ; <-resp-≈ = PropEq.resp₂ _<_ } } where cmp : ∀ {n} → Trichotomous _≡_ (_<_ {n}) cmp zero zero = tri≈ (λ()) refl (λ()) cmp zero (suc j) = tri< (s≤s z≤n) (λ()) (λ()) cmp (suc i) zero = tri> (λ()) (λ()) (s≤s z≤n) cmp (suc i) (suc j) with cmp i j ... | tri< lt ¬eq ¬gt = tri< (s≤s lt) (¬eq ∘ drop-suc) (¬gt ∘ N.≤-pred) ... | tri> ¬lt ¬eq gt = tri> (¬lt ∘ N.≤-pred) (¬eq ∘ drop-suc) (s≤s gt) ... | tri≈ ¬lt eq ¬gt = tri≈ (¬lt ∘ N.≤-pred) (cong suc eq) (¬gt ∘ N.≤-pred) decSetoid : ℕ → DecSetoid decSetoid n = StrictTotalOrder.decSetoid (strictTotalOrder n) infix 4 _≟_ _≟_ : {n : ℕ} → Decidable {Fin n} _≡_ _≟_ {n} = DecSetoid._≟_ (decSetoid n) to-from : ∀ n → toℕ (fromℕ n) ≡ n to-from zero = refl to-from (suc n) = cong suc (to-from n) bounded : ∀ {n} (i : Fin n) → toℕ i ℕ< n bounded zero = s≤s z≤n bounded (suc i) = s≤s (bounded i) prop-toℕ-≤ : ∀ {n} (x : Fin n) → toℕ x ℕ≤ N.pred n prop-toℕ-≤ zero = z≤n prop-toℕ-≤ (suc {n = zero} ()) prop-toℕ-≤ (suc {n = suc n} i) = s≤s (prop-toℕ-≤ i) nℕ-ℕi≤n : ∀ n i → n ℕ-ℕ i ℕ≤ n nℕ-ℕi≤n n zero = begin n ∎ nℕ-ℕi≤n zero (suc ()) nℕ-ℕi≤n (suc n) (suc i) = begin n ℕ-ℕ i ≤⟨ nℕ-ℕi≤n n i ⟩ n ≤⟨ N.n≤1+n n ⟩ suc n ∎ inject-lemma : ∀ {n} {i : Fin n} (j : Fin′ i) → toℕ (inject j) ≡ toℕ j inject-lemma {i = zero} () inject-lemma {i = suc i} zero = refl inject-lemma {i = suc i} (suc j) = cong suc (inject-lemma j) inject+-lemma : ∀ m k → m ≡ toℕ (inject+ k (fromℕ m)) inject+-lemma zero k = refl inject+-lemma (suc m) k = cong suc (inject+-lemma m k) inject₁-lemma : ∀ {m} (i : Fin m) → toℕ (inject₁ i) ≡ toℕ i inject₁-lemma zero = refl inject₁-lemma (suc i) = cong suc (inject₁-lemma i) inject≤-lemma : ∀ {m n} (i : Fin m) (le : m ℕ≤ n) → toℕ (inject≤ i le) ≡ toℕ i inject≤-lemma zero (N.s≤s le) = refl inject≤-lemma (suc i) (N.s≤s le) = cong suc (inject≤-lemma i le) ≺⇒<′ : _≺_ ⇒ N._<′_ ≺⇒<′ (n ≻toℕ i) = N.≤⇒≤′ (bounded i) <′⇒≺ : N._<′_ ⇒ _≺_ <′⇒≺ {n} N.≤′-refl = subst (λ i → i ≺ suc n) (to-from n) (suc n ≻toℕ fromℕ n) <′⇒≺ (N.≤′-step m≤′n) with <′⇒≺ m≤′n <′⇒≺ (N.≤′-step m≤′n) | n ≻toℕ i = subst (λ i → i ≺ suc n) (inject₁-lemma i) (suc n ≻toℕ (inject₁ i)) ------------------------------------------------------------------------ -- Operations infixl 6 _+′_ _+′_ : ∀ {m n} (i : Fin m) (j : Fin n) → Fin (N.pred m ℕ+ n) i +′ j = inject≤ (i + j) (N._+-mono_ (prop-toℕ-≤ i) ≤-refl) where open Poset N.poset renaming (refl to ≤-refl) -- reverse {n} "i" = "n ∸ 1 ∸ i". reverse : ∀ {n} → Fin n → Fin n reverse {zero} () reverse {suc n} i = inject≤ (n ℕ- i) (N.n∸m≤n (toℕ i) (suc n)) -- If there is an injection from a set to a finite set, then equality -- of the set can be decided. eq? : ∀ {S n} → Injection S (PropEq.setoid (Fin n)) → Decidable (Setoid._≈_ S) eq? inj x y with to ⟨$⟩ x ≟ to ⟨$⟩ y where open Injection inj ... | yes tox≡toy = yes (Injection.injective inj tox≡toy) ... | no tox≢toy = no (tox≢toy ∘ pres (Injection.to inj)) -- Quantification over finite sets commutes with applicative functors. sequence : ∀ {F n} {P : Pred (Fin n)} → RawApplicative F → (∀ i → F (P i)) → F (∀ i → P i) sequence {F} RA = helper _ _ where open RawApplicative RA helper : ∀ n (P : Pred (Fin n)) → (∀ i → F (P i)) → F (∀ i → P i) helper zero P ∀iPi = pure (λ()) helper (suc n) P ∀iPi = combine <$> ∀iPi zero ⊛ helper n (λ n → P (suc n)) (∀iPi ∘ suc) where combine : P zero → (∀ i → P (suc i)) → ∀ i → P i combine z s zero = z combine z s (suc i) = s i private -- Included just to show that sequence above has an inverse (under -- an equivalence relation with two equivalence classes, one with -- all inhabited sets and the other with all uninhabited sets). sequence⁻¹ : ∀ {F A} {P : Pred A} → RawFunctor F → F (∀ i → P i) → ∀ i → F (P i) sequence⁻¹ RF F∀iPi i = (λ f → f i) <$> F∀iPi where open RawFunctor RF
{ "alphanum_fraction": 0.5276759531, "avg_line_length": 32.2840236686, "ext": "agda", "hexsha": "66e3aa7c0e241ecaea85d180130d22237d25a798", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z", "max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "isabella232/Lemmachine", "max_forks_repo_path": "vendor/stdlib/src/Data/Fin/Props.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "larrytheliquid/Lemmachine", "max_issues_repo_path": "vendor/stdlib/src/Data/Fin/Props.agda", "max_line_length": 82, "max_stars_count": 56, "max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "isabella232/Lemmachine", "max_stars_repo_path": "vendor/stdlib/src/Data/Fin/Props.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z", "num_tokens": 2168, "size": 5456 }
{-# OPTIONS --safe #-} module Cubical.Categories.Limits where open import Cubical.Categories.Limits.Limits public open import Cubical.Categories.Limits.BinProduct public open import Cubical.Categories.Limits.BinCoproduct public open import Cubical.Categories.Limits.Initial public open import Cubical.Categories.Limits.Terminal public open import Cubical.Categories.Limits.Pullback public
{ "alphanum_fraction": 0.8461538462, "avg_line_length": 39, "ext": "agda", "hexsha": "63083fac5901c1d5055a2502527c8d13d4dc75fe", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Seanpm2001-web/cubical", "max_forks_repo_path": "Cubical/Categories/Limits.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Seanpm2001-web/cubical", "max_issues_repo_path": "Cubical/Categories/Limits.agda", "max_line_length": 57, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FernandoLarrain/cubical", "max_stars_repo_path": "Cubical/Categories/Limits.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z", "max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z", "num_tokens": 82, "size": 390 }
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.FOTC.Program.Mirror.StructurallySmaller.StructurallySmaller where open import FOTC.Base open import FOTC.Base.List open import FOTC.Program.Mirror.Type ------------------------------------------------------------------------------ {-# TERMINATING #-} foo : ∀ {ts} → Tree ts → D foo (tree d fnil) = d foo (tree d (fcons Tt Fts)) = foo (tree d Fts) {-# TERMINATING #-} bar : ∀ {ts} → Tree ts → D bar (tree d fnil) = d bar (tree d (fcons Tt Fts)) = helper (bar Tt) (bar (tree d Fts)) where postulate helper : D → D → D {-# TERMINATING #-} bar₁ : ∀ ts → Tree ts → D bar₁ .(node d []) (tree d fnil) = d bar₁ .(node d (t ∷ ts)) (tree d (fcons {t} {ts} Tt Fts)) = helper (bar₁ t Tt) (bar₁ (node d ts) (tree d Fts)) where postulate helper : D → D → D
{ "alphanum_fraction": 0.5322245322, "avg_line_length": 29.1515151515, "ext": "agda", "hexsha": "c7c93d6ea0174dde82388c20e15141d4fbe72898", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "notes/FOT/FOTC/Program/Mirror/StructurallySmaller/StructurallySmaller.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "notes/FOT/FOTC/Program/Mirror/StructurallySmaller/StructurallySmaller.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "notes/FOT/FOTC/Program/Mirror/StructurallySmaller/StructurallySmaller.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 291, "size": 962 }
open import Oscar.Prelude open import Oscar.Data.¶ module Oscar.Data.Descender where -- m ≤ n, counting down from n-1 to m data Descender⟨_⟩ {a} (A : ¶ → Ø a) (m : ¶) : ¶ → Ø a where ∅ : Descender⟨ A ⟩ m m _,_ : ∀ {n} → A n → Descender⟨ A ⟩ m n → Descender⟨ A ⟩ m (↑ n) Vec'⟨_⟩ = λ {a} (A : Ø a) N → Descender⟨ (λ _ → A) ⟩ 0 N ⟨_⟩¶⟨_≤_↓⟩ = Descender⟨_⟩ AList⟨_⟩ = ⟨_⟩¶⟨_≤_↓⟩
{ "alphanum_fraction": 0.5378590078, "avg_line_length": 25.5333333333, "ext": "agda", "hexsha": "ad5ac8050caf69cc4bc6460625a999133efc420c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Oscar/Data/Descender.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Oscar/Data/Descender.agda", "max_line_length": 65, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Oscar/Data/Descender.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 189, "size": 383 }
module Ferros.Resource.Untyped where open import Ferros.Resource.Untyped.Base public
{ "alphanum_fraction": 0.8390804598, "avg_line_length": 21.75, "ext": "agda", "hexsha": "6e045c8bbcf35ec08bbde3a74b54bd5de59f5965", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "8759d36ac9ec24c53f226a60fa3811eb1d4e5d93", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "auxoncorp/ferros-spec", "max_forks_repo_path": "Ferros/Resource/Untyped.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8759d36ac9ec24c53f226a60fa3811eb1d4e5d93", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "auxoncorp/ferros-spec", "max_issues_repo_path": "Ferros/Resource/Untyped.agda", "max_line_length": 48, "max_stars_count": 3, "max_stars_repo_head_hexsha": "8759d36ac9ec24c53f226a60fa3811eb1d4e5d93", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "auxoncorp/ferros-spec", "max_stars_repo_path": "Ferros/Resource/Untyped.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-27T23:18:55.000Z", "max_stars_repo_stars_event_min_datetime": "2021-09-11T01:06:56.000Z", "num_tokens": 20, "size": 87 }
module Selective.Simulate where open import Selective.ActorMonad public open import Selective.SimulationEnvironment open import Selective.EnvironmentOperations open import Prelude open import Data.List.All.Properties using (++⁺) open import Data.Nat.Properties using (≤-reflexive ; ≤-step) open import Data.Product using (Σ ; _,_ ; _×_ ; Σ-syntax) open Actor open ValidActor open Env open FoundReference open LiftedReferences open UpdatedInbox open ValidMessageList open NamedInbox open _comp↦_∈_ open NameSupply open NameSupplyStream data Trace (i : Size) : Set₂ record ∞Trace (i : Size) : Set₂ where coinductive constructor delay_ field force : {j : Size< i} → Trace j data Trace (i : Size) where TraceStop : (env : Env) → Done env → Trace i _∷_ : (x : Env) (xs : ∞Trace i) → Trace i reduce-unbound-return : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Return act → ActorHasNoContinuation act → Env reduce-unbound-return env Focused AtReturn no-cont = block-focused env Focused (BlockedReturn AtReturn no-cont) reduce-bound-return : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Return act → ActorHasContinuation act → Env reduce-bound-return env@record { acts = actor@record { computation = Return v ⟶ (f ∷ cont) } ∷ rest ; actors-valid = actor-valid ∷ rest-valid } Focused AtReturn HasContinuation = let actor' : Actor actor' = replace-actorM actor ((f v .force) ⟶ cont) env' : Env env' = replace-focused env Focused actor' (rewrap-valid-actor AreSame actor-valid) in env' reduce-bind : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Bind act → Env reduce-bind env@record { acts = actor@record { computation = (m ∞>>= f) ⟶ cont } ∷ rest ; actors-valid = actor-valid ∷ rest-valid } Focused AtBind = let actor' : Actor actor' = replace-actorM actor ((m .force) ⟶ (f ∷ cont)) env' : Env env' = replace-focused env Focused actor' (rewrap-valid-actor AreSame actor-valid) in env' reduce-spawn : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Spawn act → Env reduce-spawn env@record { acts = actor@record { computation = Spawn {NewIS} {B} act ⟶ cont } ∷ rest ; actors-valid = actor-valid ∷ rest-valid } Focused AtSpawn = let new-name : Name new-name = env .name-supply .supply .name new-store-entry : NamedInbox new-store-entry = inbox# new-name [ NewIS ] env' : Env env' = add-top (act ⟶ []) env valid' : ValidActor (env' .store) actor valid' = valid-actor-suc (env .name-supply .supply) actor-valid env'' : Env env'' = top-actor-to-back env' actor' : Actor actor' = add-reference actor new-store-entry (Return _ ⟶ cont) valid'' : ValidActor (env'' .store) actor' valid'' = add-reference-valid RefAdded valid' [p: zero ][handles: ⊆-refl ] env''' : Env env''' = replace-focused env'' Focused actor' valid'' in env''' reduce-send : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Send act → Env reduce-send env@record { acts = actor@record { computation = Send {ToIS = ToIS} canSendTo (SendM tag fields) ⟶ cont } ∷ rest ; actors-valid = actor-valid ∷ rest-valid } Focused AtSend = let to-reference : FoundReference (store env) ToIS to-reference = lookup-reference-act actor-valid canSendTo namedFields = name-fields-act (store env) actor fields actor-valid actor' : Actor actor' = replace-actorM actor (Return _ ⟶ cont) withM : Env withM = replace-focused env Focused actor' (rewrap-valid-actor AreSame actor-valid) message = NamedM (translate-message-pointer to-reference tag) namedFields message-is-valid : message-valid (env .store) message message-is-valid = make-pointers-compatible (env .store) (actor .pre) (actor .references) (actor .pre-eq-refs) fields (actor-valid .references-have-pointer) updater = add-message message message-is-valid withUpdatedInbox : Env withUpdatedInbox = update-inbox-env withM (underlying-pointer to-reference) updater in withUpdatedInbox reduce-receive-without-message : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Receive act → (p : has-inbox (env .store) act) → inbox-for-actor (env .env-inboxes) act p [] → Env reduce-receive-without-message env Focused AtReceive p ifa = block-focused env Focused (BlockedReceive AtReceive p ifa) reduce-receive-with-message : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Receive act → (p : has-inbox (env .store) act) → ∀ inbox → all-messages-valid (env .store) inbox → InboxInState NonEmpty inbox → inbox-for-actor (env .env-inboxes) act p inbox → Env reduce-receive-with-message env@record { acts = actor@record { computation = (Receive ⟶ cont) } ∷ rest ; actors-valid = actor-valid ∷ rest-valid } Focused AtReceive p (nm ∷ messages) (nmv ∷ vms) HasMessage ifa = let inboxesAfter = update-inbox (env .store) (env .env-inboxes) (env .messages-valid) (actor-valid .actor-has-inbox) remove-message actor' : Actor actor' = add-references-rewrite actor (named-inboxes nm) {unname-message nm} (add-references++ nm nmv (pre actor)) (Return (unname-message nm) ⟶ cont) actor-valid' : ValidActor (env .store) actor' actor-valid' = record { actor-has-inbox = actor-valid .actor-has-inbox ; references-have-pointer = valid++ nm nmv (actor-valid .references-have-pointer) } env' : Env env' = let updated = update-inbox (env .store) (env .env-inboxes) (env .messages-valid) (actor-valid .actor-has-inbox) remove-message unblock-split = unblock-actors updated (env .blocked) (env .blocked-valid) (env .blocked-no-progress) open UnblockedActors in record { acts = actor' ∷ unblock-split .unblocked ++ rest ; blocked = unblock-split .still-blocked ; store = env .store ; env-inboxes = updated .updated-inboxes ; name-supply = env .name-supply ; actors-valid = actor-valid' ∷ ++⁺ (unblock-split .unblocked-valid) rest-valid ; blocked-valid = unblock-split .blocked-valid ; messages-valid = updated .inboxes-valid ; blocked-no-progress = unblock-split .blocked-no-prog } in env' reduce-receive : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Receive act → Env reduce-receive env@record { acts = actor ∷ rest ; actors-valid = actor-valid ∷ _ } Focused AtReceive = choose-reduction (get-inbox env (actor-valid .actor-has-inbox)) where open GetInbox choose-reduction : (gi : GetInbox (env .store) (env .env-inboxes) (actor-valid .actor-has-inbox)) → Env choose-reduction gi@record { messages = [] } = reduce-receive-without-message env Focused AtReceive _ (gi .right-inbox) choose-reduction gi@record { messages = _ ∷ _ } = reduce-receive-with-message env Focused AtReceive _ (gi .messages) (gi .valid) HasMessage (gi .right-inbox) reduce-self : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Self act → Env reduce-self env@record { acts = actor@record { computation = Self ⟶ cont } ∷ _ ; actors-valid = actor-valid ∷ _ } Focused AtSelf = let actor' : Actor actor' = add-reference actor inbox# (actor .name) [ (actor .inbox-shape) ] ((Return _) ⟶ cont) actor-valid' : ValidActor (env .store) actor' actor-valid' = add-reference-valid RefAdded actor-valid [p: (actor-valid .actor-has-inbox) ][handles: ⊆-refl ] env' : Env env' = replace-focused env Focused actor' actor-valid' in env' reduce-selective-with-message : {act : Actor} → (env : Env) → Focus act env → (aac : ActorAtConstructor Selective act) → (point : has-inbox (env .store) act) → ∀ inbox → all-messages-valid (env .store) inbox → inbox-for-actor (env .env-inboxes) act point inbox → {split : SplitList inbox} → {p : (filter-named (selected-filter act aac)) (SplitList.el split) ≡ true} → InboxInFilterState {filter = filter-named (selected-filter act aac)} inbox (Found split p) → Env reduce-selective-with-message env@record { acts = actor@record { computation = SelectiveReceive filter ⟶ cont } ∷ rest ; actors-valid = actor-valid ∷ rest-valid } Focused AtSelective point inb amv ifa (HasMessage split ok) = let updated = update-inbox (env .store) (env .env-inboxes) (env .messages-valid) (actor-valid .actor-has-inbox) (remove-found-message filter) unblock-split = unblock-actors updated (env .blocked) (env .blocked-valid) (env .blocked-no-progress) open SplitList received-nm = split .el added-references = named-inboxes received-nm received-message = unname-message received-nm received-valid : message-valid (env .store) received-nm received-valid = split-all-el inb amv split adds-correct-references : map shape added-references ++ (actor .pre) ≡ add-references (actor .pre) received-message adds-correct-references = add-references++ received-nm received-valid (actor .pre) new-continuation = Return sm: received-message [ ok ] ⟶ cont act' : Actor act' = add-references-rewrite actor added-references {received-message} adds-correct-references new-continuation act-valid' : ValidActor (env .store) act' act-valid' = record { actor-has-inbox = actor-valid .actor-has-inbox ; references-have-pointer = valid++ received-nm received-valid (actor-valid .references-have-pointer) } open UnblockedActors in record { acts = act' ∷ unblock-split .unblocked ++ rest ; blocked = unblock-split .still-blocked ; store = env .store ; env-inboxes = updated-inboxes updated ; name-supply = env .name-supply ; actors-valid = act-valid' ∷ ++⁺ (unblock-split .unblocked-valid) rest-valid ; blocked-valid = unblock-split .blocked-valid ; messages-valid = inboxes-valid updated ; blocked-no-progress = unblock-split .blocked-no-prog } reduce-selective-without-message : {act : Actor} → (env : Env) → Focus act env → (aac : ActorAtConstructor Selective act) → (point : has-inbox (env .store) act) → ∀ inbox → {ps : All (misses-filter (filter-named (selected-filter act aac))) inbox} → inbox-for-actor (env .env-inboxes) act point inbox → InboxInFilterState inbox (Nothing ps) → Env reduce-selective-without-message env Focused AtSelective point inbox ifa iifs = block-focused env Focused (BlockedSelective AtSelective point inbox ifa iifs) reduce-selective : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Selective act → Env reduce-selective env@record { acts = actor@record { computation = SelectiveReceive filter ⟶ _ } ∷ _ ; actors-valid = actor-valid ∷ _ } Focused AtSelective = let inb = get-inbox env (actor-valid .actor-has-inbox) in choose-reduction inb (find-split (inb .messages) (filter-named filter)) where open GetInbox choose-reduction : (gi : GetInbox (env .store) (env .env-inboxes) (actor-valid .actor-has-inbox)) → FoundInList (gi .messages) (filter-named filter) → Env choose-reduction gi (Found split x) = reduce-selective-with-message env Focused AtSelective _ (gi .messages) (gi .valid) (gi .right-inbox) (HasMessage split x) choose-reduction gi (Nothing ps) = reduce-selective-without-message env Focused AtSelective _ (gi .messages) (gi .right-inbox) (IsEmpty ps) reduce-strengthen : {act : Actor} → (env : Env) → Focus act env → ActorAtConstructor Strengthen act → Env reduce-strengthen env@record { acts = actor@record { computation = Strengthen {ys} inc ⟶ cont } ∷ _ ; actors-valid = actor-valid ∷ _ } Focused AtStrengthen = let lifted-references = lift-references inc (references actor) (pre-eq-refs actor) actor' : Actor actor' = lift-actor actor (lifted-references .contained) (lifted-references .contained-eq-inboxes) (Return _ ⟶ cont) actor-valid' : ValidActor (env .store) actor' actor-valid' = lift-valid-actor (CanBeLifted lifted-references) actor-valid env' : Env env' = replace-focused env Focused actor' actor-valid' in env' reduce : {act : Actor} → (env : Env) → Focus act env → Env reduce env@record { acts = record { computation = (Return val ⟶ []) } ∷ _ } Focused = reduce-unbound-return env Focused AtReturn (NoContinuation {v = val}) reduce env@record { acts = record { computation = (Return val ⟶ (_ ∷ _)) } ∷ _ } Focused = reduce-bound-return env Focused AtReturn (HasContinuation {v = val}) reduce env@record { acts = record { computation = ((m ∞>>= f) ⟶ _)} ∷ _ } Focused = reduce-bind env Focused AtBind reduce env@record { acts = record { computation = (Spawn act ⟶ cont) } ∷ _ } Focused = reduce-spawn env Focused AtSpawn reduce env@record { acts = record { computation = (Send canSendTo msg ⟶ cont) } ∷ _ } Focused = reduce-send env Focused AtSend reduce env@record { acts = record { computation = (Receive ⟶ cont) } ∷ _ } Focused = reduce-receive env Focused AtReceive reduce env@record { acts = record { computation = (SelectiveReceive filter ⟶ cont) } ∷ _ } Focused = reduce-selective env Focused AtSelective reduce env@record { acts = record { computation = (Self ⟶ cont) } ∷ _ } Focused = reduce-self env Focused AtSelf reduce env@record { acts = record { computation = (Strengthen inc ⟶ cont) } ∷ _ } Focused = reduce-strengthen env Focused AtStrengthen simulate : Env → ∞Trace ∞ simulate env@record { acts = [] ; actors-valid = [] } = delay TraceStop env AllBlocked simulate env@record { acts = _ ∷ _ ; actors-valid = _ ∷ _ } = keep-stepping (reduce env Focused) where open ∞Trace keep-stepping : Env → ∞Trace ∞ keep-stepping env .force = env ∷ simulate env
{ "alphanum_fraction": 0.5983287619, "avg_line_length": 44.6638176638, "ext": "agda", "hexsha": "a9b4a950f323998a6c7dbc8207dfcd8cb4aef037", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Zalastax/singly-typed-actors", "max_forks_repo_path": "src/Selective/Simulate.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Zalastax/singly-typed-actors", "max_issues_repo_path": "src/Selective/Simulate.agda", "max_line_length": 166, "max_stars_count": 1, "max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Zalastax/thesis", "max_stars_repo_path": "src/Selective/Simulate.agda", "max_stars_repo_stars_event_max_datetime": "2018-02-02T16:44:43.000Z", "max_stars_repo_stars_event_min_datetime": "2018-02-02T16:44:43.000Z", "num_tokens": 3987, "size": 15677 }
module Oscar.Data.Vec.Core where open import Data.Vec public using (Vec; []; _∷_)
{ "alphanum_fraction": 0.7142857143, "avg_line_length": 16.8, "ext": "agda", "hexsha": "932a1b2d60d966a5f4c03684a88518852c5ca257", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-2/Oscar/Data/Vec/Core.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-2/Oscar/Data/Vec/Core.agda", "max_line_length": 48, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-2/Oscar/Data/Vec/Core.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 24, "size": 84 }
module OlderBasicILP.Indirect.Gentzen where open import OlderBasicILP.Indirect public -- Derivations, as Gentzen-style natural deduction trees. mutual data Tm : Set where VAR : ℕ → Tm LAM : Tm → Tm APP : Tm → Tm → Tm MULTIBOX : Cx Tm → Tm → Tm DOWN : Tm → Tm PAIR : Tm → Tm → Tm FST : Tm → Tm SND : Tm → Tm UNIT : Tm infix 3 _⊢_ data _⊢_ (Γ : Cx (Ty Tm)) : Ty Tm → Set where var : ∀ {A} → A ∈ Γ → Γ ⊢ A lam : ∀ {A B} → Γ , A ⊢ B → Γ ⊢ A ▻ B app : ∀ {A B} → Γ ⊢ A ▻ B → Γ ⊢ A → Γ ⊢ B multibox : ∀ {n A} {SS : VCx Tm n} {Ξ : VCx (Ty Tm) n} → Γ ⊢⋆ SS ⦂⋆ Ξ → (u : SS ⦂⋆ Ξ ⊢ A) → Γ ⊢ [ u ] ⦂ A down : ∀ {A T} → Γ ⊢ T ⦂ A → Γ ⊢ A pair : ∀ {A B} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B fst : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ A snd : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ B unit : Γ ⊢ ⊤ infix 3 _⊢⋆_ _⊢⋆_ : Cx (Ty Tm) → Cx (Ty Tm) → Set Γ ⊢⋆ ∅ = 𝟙 Γ ⊢⋆ Ξ , A = Γ ⊢⋆ Ξ × Γ ⊢ A [_] : ∀ {A Γ} → Γ ⊢ A → Tm [ var i ] = VAR [ i ]ⁱ [ lam t ] = LAM [ t ] [ app t u ] = APP [ t ] [ u ] [ multibox ts u ] = MULTIBOX [ ts ]⋆ [ u ] [ down t ] = DOWN [ t ] [ pair t u ] = PAIR [ t ] [ u ] [ fst t ] = FST [ t ] [ snd t ] = SND [ t ] [ unit ] = UNIT [_]⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Cx Tm [_]⋆ {∅} ∙ = ∅ [_]⋆ {Ξ , A} (ts , t) = [ ts ]⋆ , [ t ] -- Monotonicity with respect to context inclusion. mutual mono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A mono⊢ η (var i) = var (mono∈ η i) mono⊢ η (lam t) = lam (mono⊢ (keep η) t) mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u) mono⊢ η (multibox ts u) = multibox (mono⊢⋆ η ts) u mono⊢ η (down t) = down (mono⊢ η t) mono⊢ η (pair t u) = pair (mono⊢ η t) (mono⊢ η u) mono⊢ η (fst t) = fst (mono⊢ η t) mono⊢ η (snd t) = snd (mono⊢ η t) mono⊢ η unit = unit mono⊢⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ Ξ → Γ′ ⊢⋆ Ξ mono⊢⋆ {∅} η ∙ = ∙ mono⊢⋆ {Ξ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t -- Shorthand for variables. V₀ : Tm V₀ = VAR 0 V₁ : Tm V₁ = VAR 1 V₂ : Tm V₂ = VAR 2 v₀ : ∀ {A Γ} → Γ , A ⊢ A v₀ = var i₀ v₁ : ∀ {A B Γ} → (Γ , A) , B ⊢ A v₁ = var i₁ v₂ : ∀ {A B C Γ} → ((Γ , A) , B) , C ⊢ A v₂ = var i₂ -- Reflexivity. refl⊢⋆ : ∀ {Γ} → Γ ⊢⋆ Γ refl⊢⋆ {∅} = ∙ refl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀ -- Deduction theorem is built-in. -- Detachment theorem. DET : Tm → Tm DET T = APP T V₀ det : ∀ {A B Γ} → Γ ⊢ A ▻ B → Γ , A ⊢ B det t = app (mono⊢ weak⊆ t) v₀ -- Cut and multicut. CUT : Tm → Tm → Tm CUT T U = APP (LAM U) T MULTICUT : Cx Tm → Tm → Tm MULTICUT ∅ U = U MULTICUT (TS , T) U = APP (MULTICUT TS (LAM U)) T cut : ∀ {A B Γ} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B cut t u = app (lam u) t multicut : ∀ {Ξ A Γ} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A multicut {∅} ∙ u = mono⊢ bot⊆ u multicut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t -- Transitivity. trans⊢⋆ : ∀ {Γ″ Γ′ Γ} → Γ ⊢⋆ Γ′ → Γ′ ⊢⋆ Γ″ → Γ ⊢⋆ Γ″ trans⊢⋆ {∅} ts ∙ = ∙ trans⊢⋆ {Γ″ , A} ts (us , u) = trans⊢⋆ ts us , multicut ts u -- Contraction. CCONT : Tm CCONT = LAM (LAM (APP (APP V₁ V₀) V₀)) CONT : Tm → Tm CONT T = DET (APP CCONT (LAM (LAM T))) ccont : ∀ {A B Γ} → Γ ⊢ (A ▻ A ▻ B) ▻ A ▻ B ccont = lam (lam (app (app v₁ v₀) v₀)) cont : ∀ {A B Γ} → Γ , A , A ⊢ B → Γ , A ⊢ B cont t = det (app ccont (lam (lam t))) -- Exchange, or Schönfinkel’s C combinator. CEXCH : Tm CEXCH = LAM (LAM (LAM (APP (APP V₂ V₀) V₁))) EXCH : Tm → Tm EXCH T = DET (DET (APP CEXCH (LAM (LAM T)))) cexch : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C cexch = lam (lam (lam (app (app v₂ v₀) v₁))) exch : ∀ {A B C Γ} → Γ , A , B ⊢ C → Γ , B , A ⊢ C exch t = det (det (app cexch (lam (lam t)))) -- Composition, or Schönfinkel’s B combinator. CCOMP : Tm CCOMP = LAM (LAM (LAM (APP V₂ (APP V₁ V₀)))) COMP : Tm → Tm → Tm COMP T U = DET (APP (APP CCOMP (LAM T)) (LAM U)) ccomp : ∀ {A B C Γ} → Γ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C ccomp = lam (lam (lam (app v₂ (app v₁ v₀)))) comp : ∀ {A B C Γ} → Γ , B ⊢ C → Γ , A ⊢ B → Γ , A ⊢ C comp t u = det (app (app ccomp (lam t)) (lam u)) -- Useful theorems in functional form. DIST : Tm → Tm → Tm DIST T U = MULTIBOX ((∅ , T) , U) (APP (DOWN V₁) (DOWN V₀)) UP : Tm → Tm UP T = MULTIBOX (∅ , T) V₀ DISTUP : Tm → Tm → Tm DISTUP T U = DIST T (UP U) BOX : Tm → Tm BOX T = MULTIBOX ∅ T UNBOX : Tm → Tm → Tm UNBOX T U = APP (LAM U) T dist : ∀ {A B T U Γ} → (t : Γ ⊢ T ⦂ (A ▻ B)) → (u : Γ ⊢ U ⦂ A) → Γ ⊢ APP (DOWN V₁) (DOWN V₀) ⦂ B dist t u = multibox ((∙ , t) , u) (app (down v₁) (down v₀)) up : ∀ {A T Γ} → Γ ⊢ T ⦂ A → Γ ⊢ V₀ ⦂ T ⦂ A up t = multibox (∙ , t) v₀ distup : ∀ {A B T U Γ} → (t : Γ ⊢ T ⦂ (U ⦂ A ▻ B)) → (u : Γ ⊢ U ⦂ A) → Γ ⊢ APP (DOWN V₁) (DOWN V₀) ⦂ B distup t u = dist t (up u) box : ∀ {A Γ} → (t : ∅ ⊢ A) → Γ ⊢ [ t ] ⦂ A box t = multibox ∙ t unbox : ∀ {A C T U Γ} → Γ ⊢ T ⦂ A → Γ , T ⦂ A ⊢ U ⦂ C → Γ ⊢ U ⦂ C unbox t u = app (lam u) t -- Useful theorems in combinatory form. CI : Tm CI = LAM V₀ CK : Tm CK = LAM (LAM V₁) CS : Tm CS = LAM (LAM (LAM (APP (APP V₂ V₀) (APP V₁ V₀)))) CDIST : Tm CDIST = LAM (LAM (DIST V₁ V₀)) CUP : Tm CUP = LAM (UP V₀) CDOWN : Tm CDOWN = LAM (DOWN V₀) CDISTUP : Tm CDISTUP = LAM (LAM (DIST V₁ (UP V₀))) CUNBOX : Tm CUNBOX = LAM (LAM (APP V₀ V₁)) CPAIR : Tm CPAIR = LAM (LAM (PAIR V₁ V₀)) CFST : Tm CFST = LAM (FST V₀) CSND : Tm CSND = LAM (SND V₀) ci : ∀ {A Γ} → Γ ⊢ A ▻ A ci = lam v₀ ck : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A ck = lam (lam v₁) cs : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C cs = lam (lam (lam (app (app v₂ v₀) (app v₁ v₀)))) cdist : ∀ {A B T U Γ} → Γ ⊢ T ⦂ (A ▻ B) ▻ U ⦂ A ▻ APP (DOWN V₁) (DOWN V₀) ⦂ B cdist = lam (lam (dist v₁ v₀)) cup : ∀ {A T Γ} → Γ ⊢ T ⦂ A ▻ V₀ ⦂ T ⦂ A cup = lam (up v₀) cdown : ∀ {A T Γ} → Γ ⊢ T ⦂ A ▻ A cdown = lam (down v₀) cdistup : ∀ {A B T U Γ} → Γ ⊢ T ⦂ (U ⦂ A ▻ B) ▻ U ⦂ A ▻ APP (DOWN V₁) (DOWN V₀) ⦂ B cdistup = lam (lam (dist v₁ (up v₀))) cunbox : ∀ {A C T Γ} → Γ ⊢ T ⦂ A ▻ (T ⦂ A ▻ C) ▻ C cunbox = lam (lam (app v₀ v₁)) cpair : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A ∧ B cpair = lam (lam (pair v₁ v₀)) cfst : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ A cfst = lam (fst v₀) csnd : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ B csnd = lam (snd v₀) -- Closure under context concatenation. concat : ∀ {A B Γ} Γ′ → Γ , A ⊢ B → Γ′ ⊢ A → Γ ⧺ Γ′ ⊢ B concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u) -- Substitution. mutual [_≔_]_ : ∀ {A B Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢ B → Γ ∖ i ⊢ B [ i ≔ s ] var j with i ≟∈ j [ i ≔ s ] var .i | same = s [ i ≔ s ] var ._ | diff j = var j [ i ≔ s ] lam t = lam ([ pop i ≔ mono⊢ weak⊆ s ] t) [ i ≔ s ] app t u = app ([ i ≔ s ] t) ([ i ≔ s ] u) [ i ≔ s ] multibox ts u = multibox ([ i ≔ s ]⋆ ts) u [ i ≔ s ] down t = down ([ i ≔ s ] t) [ i ≔ s ] pair t u = pair ([ i ≔ s ] t) ([ i ≔ s ] u) [ i ≔ s ] fst t = fst ([ i ≔ s ] t) [ i ≔ s ] snd t = snd ([ i ≔ s ] t) [ i ≔ s ] unit = unit [_≔_]⋆_ : ∀ {Ξ A Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢⋆ Ξ → Γ ∖ i ⊢⋆ Ξ [_≔_]⋆_ {∅} i s ∙ = ∙ [_≔_]⋆_ {Ξ , B} i s (ts , t) = [ i ≔ s ]⋆ ts , [ i ≔ s ] t
{ "alphanum_fraction": 0.426804404, "avg_line_length": 22.9190031153, "ext": "agda", "hexsha": "bd6feb6296792fb54f9f028e81231893fe180609", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/hilbert-gentzen", "max_forks_repo_path": "OlderBasicILP/Indirect/Gentzen.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z", "max_issues_repo_licenses": [ "X11" ], "max_issues_repo_name": "mietek/hilbert-gentzen", "max_issues_repo_path": "OlderBasicILP/Indirect/Gentzen.agda", "max_line_length": 69, "max_stars_count": 29, "max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/hilbert-gentzen", "max_stars_repo_path": "OlderBasicILP/Indirect/Gentzen.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z", "max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z", "num_tokens": 3778, "size": 7357 }
module Luau.Type.ToString where open import FFI.Data.String using (String; _++_) open import Luau.Type using (Type; nil; _⇒_; none; any; number; _∪_; _∩_; normalizeOptional) {-# TERMINATING #-} typeToString : Type → String typeToStringᵁ : Type → String typeToStringᴵ : Type → String typeToString nil = "nil" typeToString (S ⇒ T) = "(" ++ (typeToString S) ++ ") -> " ++ (typeToString T) typeToString none = "none" typeToString any = "any" typeToString number = "number" typeToString (S ∪ T) with normalizeOptional(S ∪ T) typeToString (S ∪ T) | ((S′ ⇒ T′) ∪ nil) = "(" ++ typeToString (S′ ⇒ T′) ++ ")?" typeToString (S ∪ T) | (S′ ∪ nil) = typeToString S′ ++ "?" typeToString (S ∪ T) | (S′ ∪ T′) = "(" ++ typeToStringᵁ (S ∪ T) ++ ")" typeToString (S ∪ T) | T′ = typeToString T′ typeToString (S ∩ T) = "(" ++ typeToStringᴵ (S ∩ T) ++ ")" typeToStringᵁ (S ∪ T) = (typeToStringᵁ S) ++ " | " ++ (typeToStringᵁ T) typeToStringᵁ T = typeToString T typeToStringᴵ (S ∩ T) = (typeToStringᴵ S) ++ " & " ++ (typeToStringᴵ T) typeToStringᴵ T = typeToString T
{ "alphanum_fraction": 0.6263107722, "avg_line_length": 37.4642857143, "ext": "agda", "hexsha": "e7a7c1c07b2ae4391b8d84f37a82989243c14b12", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Tr4shh/Roblox-Luau", "max_forks_repo_path": "prototyping/Luau/Type/ToString.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Tr4shh/Roblox-Luau", "max_issues_repo_path": "prototyping/Luau/Type/ToString.agda", "max_line_length": 92, "max_stars_count": null, "max_stars_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Tr4shh/Roblox-Luau", "max_stars_repo_path": "prototyping/Luau/Type/ToString.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 376, "size": 1049 }
{-# OPTIONS --allow-unsolved-metas #-} module fin where open import Data.Fin hiding (_<_ ; _≤_ ) open import Data.Fin.Properties hiding ( <-trans ) open import Data.Nat open import logic open import nat open import Relation.Binary.PropositionalEquality -- toℕ<n fin<n : {n : ℕ} {f : Fin n} → toℕ f < n fin<n {_} {zero} = s≤s z≤n fin<n {suc n} {suc f} = s≤s (fin<n {n} {f}) -- toℕ≤n fin≤n : {n : ℕ} (f : Fin (suc n)) → toℕ f ≤ n fin≤n {_} zero = z≤n fin≤n {suc n} (suc f) = s≤s (fin≤n {n} f) pred<n : {n : ℕ} {f : Fin (suc n)} → n > 0 → Data.Nat.pred (toℕ f) < n pred<n {suc n} {zero} (s≤s z≤n) = s≤s z≤n pred<n {suc n} {suc f} (s≤s z≤n) = fin<n fin<asa : {n : ℕ} → toℕ (fromℕ< {n} a<sa) ≡ n fin<asa = toℕ-fromℕ< nat.a<sa -- fromℕ<-toℕ toℕ→from : {n : ℕ} {x : Fin (suc n)} → toℕ x ≡ n → fromℕ n ≡ x toℕ→from {0} {zero} refl = refl toℕ→from {suc n} {suc x} eq = cong (λ k → suc k ) ( toℕ→from {n} {x} (cong (λ k → Data.Nat.pred k ) eq )) 0≤fmax : {n : ℕ } → (# 0) Data.Fin.≤ fromℕ< {n} a<sa 0≤fmax = subst (λ k → 0 ≤ k ) (sym (toℕ-fromℕ< a<sa)) z≤n 0<fmax : {n : ℕ } → (# 0) Data.Fin.< fromℕ< {suc n} a<sa 0<fmax = subst (λ k → 0 < k ) (sym (toℕ-fromℕ< a<sa)) (s≤s z≤n) -- toℕ-injective i=j : {n : ℕ} (i j : Fin n) → toℕ i ≡ toℕ j → i ≡ j i=j {suc n} zero zero refl = refl i=j {suc n} (suc i) (suc j) eq = cong ( λ k → suc k ) ( i=j i j (cong ( λ k → Data.Nat.pred k ) eq) ) -- raise 1 fin+1 : { n : ℕ } → Fin n → Fin (suc n) fin+1 zero = zero fin+1 (suc x) = suc (fin+1 x) open import Data.Nat.Properties as NatP hiding ( _≟_ ) fin+1≤ : { i n : ℕ } → (a : i < n) → fin+1 (fromℕ< a) ≡ fromℕ< (<-trans a a<sa) fin+1≤ {0} {suc i} (s≤s z≤n) = refl fin+1≤ {suc n} {suc (suc i)} (s≤s (s≤s a)) = cong (λ k → suc k ) ( fin+1≤ {n} {suc i} (s≤s a) ) fin+1-toℕ : { n : ℕ } → { x : Fin n} → toℕ (fin+1 x) ≡ toℕ x fin+1-toℕ {suc n} {zero} = refl fin+1-toℕ {suc n} {suc x} = cong (λ k → suc k ) (fin+1-toℕ {n} {x}) open import Relation.Nullary open import Data.Empty fin-1 : { n : ℕ } → (x : Fin (suc n)) → ¬ (x ≡ zero ) → Fin n fin-1 zero ne = ⊥-elim (ne refl ) fin-1 {n} (suc x) ne = x fin-1-sx : { n : ℕ } → (x : Fin n) → fin-1 (suc x) (λ ()) ≡ x fin-1-sx zero = refl fin-1-sx (suc x) = refl fin-1-xs : { n : ℕ } → (x : Fin (suc n)) → (ne : ¬ (x ≡ zero )) → suc (fin-1 x ne ) ≡ x fin-1-xs zero ne = ⊥-elim ( ne refl ) fin-1-xs (suc x) ne = refl -- suc-injective -- suc-eq : {n : ℕ } {x y : Fin n} → Fin.suc x ≡ Fin.suc y → x ≡ y -- suc-eq {n} {x} {y} eq = subst₂ (λ j k → j ≡ k ) {!!} {!!} (cong (λ k → Data.Fin.pred k ) eq ) -- this is refl lemma3 : {a b : ℕ } → (lt : a < b ) → fromℕ< (s≤s lt) ≡ suc (fromℕ< lt) lemma3 (s≤s lt) = refl -- fromℕ<-toℕ lemma12 : {n m : ℕ } → (n<m : n < m ) → (f : Fin m ) → toℕ f ≡ n → f ≡ fromℕ< n<m lemma12 {zero} {suc m} (s≤s z≤n) zero refl = refl lemma12 {suc n} {suc m} (s≤s n<m) (suc f) refl = cong suc ( lemma12 {n} {m} n<m f refl ) open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ ) open import Data.Fin.Properties -- <-irrelevant <-nat=irr : {i j n : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → i<n ≅ j<n <-nat=irr {zero} {zero} {suc n} refl {s≤s z≤n} {s≤s z≤n} = HE.refl <-nat=irr {suc i} {suc i} {suc n} refl {s≤s i<n} {s≤s j<n} = HE.cong (λ k → s≤s k ) ( <-nat=irr {i} {i} {n} refl ) lemma8 : {i j n : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → i<n ≅ j<n lemma8 {zero} {zero} {suc n} refl {s≤s z≤n} {s≤s z≤n} = HE.refl lemma8 {suc i} {suc i} {suc n} refl {s≤s i<n} {s≤s j<n} = HE.cong (λ k → s≤s k ) ( lemma8 {i} {i} {n} refl ) -- fromℕ<-irrelevant lemma10 : {n i j : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → fromℕ< i<n ≡ fromℕ< j<n lemma10 {n} refl = HE.≅-to-≡ (HE.cong (λ k → fromℕ< k ) (lemma8 refl )) lemma31 : {a b c : ℕ } → { a<b : a < b } { b<c : b < c } { a<c : a < c } → NatP.<-trans a<b b<c ≡ a<c lemma31 {a} {b} {c} {a<b} {b<c} {a<c} = HE.≅-to-≡ (lemma8 refl) -- toℕ-fromℕ< lemma11 : {n m : ℕ } {x : Fin n } → (n<m : n < m ) → toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m)) ≡ toℕ x lemma11 {n} {m} {x} n<m = begin toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m)) ≡⟨ toℕ-fromℕ< _ ⟩ toℕ x ∎ where open ≡-Reasoning
{ "alphanum_fraction": 0.4969208906, "avg_line_length": 35.7796610169, "ext": "agda", "hexsha": "5bb370bc7bfc7599262b2726c457afeda2071051", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "shinji-kono/Galois", "max_forks_repo_path": "src/fin.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "shinji-kono/Galois", "max_issues_repo_path": "src/fin.agda", "max_line_length": 115, "max_stars_count": 1, "max_stars_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "shinji-kono/Galois", "max_stars_repo_path": "src/fin.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-16T03:37:05.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-16T03:37:05.000Z", "num_tokens": 2122, "size": 4222 }
module SingleSorted.Context where -- An attempt to define more structured context -- that directly support the cartesian structure data Context : Set where ctx-empty : Context ctx-slot : Context ctx-concat : Context → Context → Context -- the variables in a context data var : Context → Set where var-var : var ctx-slot var-inl : ∀ {Γ Δ} → var Γ → var (ctx-concat Γ Δ) var-inr : ∀ {Γ Δ} → var Δ → var (ctx-concat Γ Δ) -- It is absurd to have a variable in the empty context ctx-empty-absurd : ∀ {ℓ} {A : Set ℓ} → var ctx-empty → A ctx-empty-absurd ()
{ "alphanum_fraction": 0.6771929825, "avg_line_length": 28.5, "ext": "agda", "hexsha": "011081ecb2961fe8512445d28584656235cfb71c", "lang": "Agda", "max_forks_count": 6, "max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z", "max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z", "max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andrejbauer/formaltt", "max_forks_repo_path": "src/SingleSorted/Context.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z", "max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andrejbauer/formaltt", "max_issues_repo_path": "src/SingleSorted/Context.agda", "max_line_length": 56, "max_stars_count": 21, "max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cilinder/formaltt", "max_stars_repo_path": "src/SingleSorted/Context.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z", "max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z", "num_tokens": 166, "size": 570 }
{-# OPTIONS --cubical --safe --guardedness #-} module Data.PolyP.RecursionSchemes where open import Function hiding (_⟨_⟩_) open import Data.Sum open import Data.Sigma open import Level open import Data.Unit open import Data.Nat open import Data.Vec.Iterated open import Data.Empty open import WellFounded open import Literals.Number open import Data.Fin.Indexed.Literals open import Data.Fin.Indexed.Properties open import Data.Fin.Indexed open import Data.Nat.Literals open import Data.Maybe open import Path open import Data.PolyP.Universe --------------------------------------------------------------------------------- -- -- Helpers for Termination -- --------------------------------------------------------------------------------- -- This is just the identity type. We need to use it because, if --without-K is -- turned on, Agda will only use an argument to a function to prove structural -- descent if that argument is a concrete data type. -- -- wont-pass : (x : Bool) → (if x then ℕ else ℕ) → ℕ -- wont-pass false zero = zero -- wont-pass false (suc n) = wont-pass true n -- wont-pass true zero = zero -- wont-pass true (suc n) = wont-pass false n -- -- Even though we're clearly structurally descending on the second argument -- there, Agda won't use it unless we make it concrete, like so: -- -- will-pass : (x : Bool) → <! (if x then ℕ else ℕ) !> → ℕ -- will-pass false [! zero !] = zero -- will-pass false [! suc n !] = will-pass true [! n !] -- will-pass true [! zero !] = zero -- will-pass true [! suc n !] = will-pass false [! n !] record <!_!> (A : Type) : Type where eta-equality constructor [!_!] field !! : A open <!_!> -- For the map and cata functions to be structurally -- terminating, we can't do things like: -- -- cata f = f ∘ fmap (cata f) ∘ unwrap -- -- So instead we need to carry a stack of all of the functors -- we're under at any given point, and pattern match on that to -- tell whether we should do f or fmap f. data Layers (n : ℕ) : ℕ → Type₁ where [] : Layers n n _∷_ : Functor (1 + m) → Layers n m → Layers n (1 + m) _++∙_ : Layers n m → Params n → Params m [] ++∙ ys = ys (x ∷ xs) ++∙ ys = let zs = xs ++∙ ys in μ x zs ∷ zs infixr 5 _∷_ _++∙_ --------------------------------------------------------------------------------- -- -- Mapping -- --------------------------------------------------------------------------------- module Mapping {m} {As Bs : Params m} (f : (i : Fin m) → As [ i ] → Bs [ i ]) where mapRec : ∀ (F : Functor n) (Fs : Layers m n) → <! ⟦ F ⟧ (Fs ++∙ As) !> → ⟦ F ⟧ (Fs ++∙ Bs) mapRec (F ⊕ G) Fs [! inl x !] = inl (mapRec F Fs [! x !]) mapRec (F ⊕ G) Fs [! inr x !] = inr (mapRec G Fs [! x !]) mapRec (F ⊗ G) Fs [! x , y !] = mapRec F Fs [! x !] , mapRec G Fs [! y !] mapRec μ⟨ F ⟩ Fs [! ⟨ xs ⟩ !] = ⟨ mapRec F (F ∷ Fs) [! xs !] ⟩ mapRec (! i ) [] [! xs !] = f i xs mapRec (! f0 ) (F ∷ Fs) [! ⟨ xs ⟩ !] = ⟨ mapRec F (F ∷ Fs) [! xs !] ⟩ mapRec (! (fs i)) (F ∷ Fs) [! xs !] = mapRec (! i) Fs [! xs !] mapRec ① Fs _ = tt mapParamAt : (i : Fin n) → (As [ i ] → A) → (j : Fin n) → As [ j ] → As [ i ]≔ A [ j ] mapParamAt f0 f f0 x = f x mapParamAt f0 f (fs _) x = x mapParamAt (fs _) f f0 x = x mapParamAt (fs i) f (fs j) x = mapParamAt i f j x map : ∀ F → (i : Fin n) → (As [ i ] → A) → ⟦ F ⟧ As → ⟦ F ⟧ (As [ i ]≔ A) map F i f xs = Mapping.mapRec (mapParamAt i f) F [] [! xs !] module MapComp {m} {As Bs Cs : Params m} (f : (i : Fin m) → Bs [ i ] → Cs [ i ]) (g : (i : Fin m) → As [ i ] → Bs [ i ]) where open Mapping mapComp : ∀ (F : Functor n) (Fs : Layers m n) (xs : <! ⟦ F ⟧ (Fs ++∙ As) !>) → mapRec f F Fs [! mapRec g F Fs xs !] ≡ mapRec (λ i → f i ∘ g i) F Fs xs mapComp (F ⊕ G) Fs [! inl x !] = cong inl (mapComp F Fs [! x !]) mapComp (F ⊕ G) Fs [! inr x !] = cong inr (mapComp G Fs [! x !]) mapComp (F ⊗ G) Fs [! x , y !] = cong₂ _,_ (mapComp F Fs [! x !]) (mapComp G Fs [! y !]) mapComp μ⟨ F ⟩ Fs [! ⟨ x ⟩ !] = cong ⟨_⟩ (mapComp F (F ∷ Fs) [! x !]) mapComp (! i) [] [! xs !] = refl mapComp (! f0) (F ∷ Fs) [! ⟨ x ⟩ !] = cong ⟨_⟩ (mapComp F (F ∷ Fs) [! x !]) mapComp (! (fs i)) (F ∷ Fs) [! xs !] = mapComp (! i) Fs [! xs !] mapComp ① Fs xs = refl map-comp : ∀ (F : Functor (suc n)) → (f : B → C) → (g : A → B) → (x : ⟦ F ⟧ (A ∷ As)) → map F f0 f (map F f0 g x) ≡ map F f0 (f ∘ g) x map-comp F f g x = MapComp.mapComp (mapParamAt f0 f) (mapParamAt f0 g) F [] [! x !] ; cong (λ c → Mapping.mapRec c F [] [! x !]) (funExt λ { f0 → refl ; (fs x) → refl } ) module MapId {m} {As : Params m} where open Mapping {m = m} {As = As} {Bs = As} mapId : ∀ (F : Functor n) (Fs : Layers m n) (xs : <! ⟦ F ⟧ (Fs ++∙ As) !>) → mapRec (λ _ x → x) F Fs xs ≡ xs .!! mapId (F ⊕ G) Fs [! inl x !] = cong inl (mapId F Fs [! x !]) mapId (F ⊕ G) Fs [! inr x !] = cong inr (mapId G Fs [! x !]) mapId (F ⊗ G) Fs [! x , y !] = cong₂ _,_ (mapId F Fs [! x !]) (mapId G Fs [! y !]) mapId μ⟨ F ⟩ Fs [! ⟨ x ⟩ !] = cong ⟨_⟩ (mapId F (F ∷ Fs) [! x !]) mapId (! i) [] [! xs !] = refl mapId (! f0) (F ∷ Fs) [! ⟨ x ⟩ !] = cong ⟨_⟩ (mapId F (F ∷ Fs) [! x !]) mapId (! (fs i)) (F ∷ Fs) [! xs !] = mapId (! i) Fs [! xs !] mapId ① Fs xs = refl map-id : (F : Functor (suc n)) → (x : ⟦ F ⟧ (A ∷ As)) → map F f0 id x ≡ x map-id F x = cong (λ c → Mapping.mapRec c F [] [! x !]) (funExt (λ { f0 → refl ; (fs i) → refl})) ; MapId.mapId F [] [! x !] --------------------------------------------------------------------------------- -- -- Categorical -- --------------------------------------------------------------------------------- module Categorical (F : Functor (suc n)) (As : Params n) where infix 4 _≗_ _≗_ : (A → B) → (A → B) → Set _ f ≗ g = ∀ x → f x ≡ g x {-# INLINE _≗_ #-} Alg : Type₁ Alg = Σ[ A ⦂ Type ] × (⟦ F ⟧ (A ∷ As) → A) -- Hom _⟶_ : Alg → Alg → Type (A , a) ⟶ (B , b) = Σ[ h ⦂ (A → B) ] × (h ∘ a ≗ b ∘ map F f0 h) variable X Y Z : Alg _∙_ : (Y ⟶ Z) → (X ⟶ Y) → (X ⟶ Z) (f ∙ g) .fst = f .fst ∘ g .fst _∙_ {Y = Y} {Z = Z} {X = X} f g .snd x = cong (f .fst) (g .snd x) ; f .snd (map F f0 (g .fst) x) ; cong (Z .snd) (map-comp F (f .fst) (g .fst) x) id′ : X ⟶ X id′ .fst = id id′ {X = X} .snd x = cong (X .snd) (sym (map-id F x)) --------------------------------------------------------------------------------- -- -- Catamorphisms -- --------------------------------------------------------------------------------- module Cata {k} {F : Functor (suc k)} {As : Params k} (alg : ⟦ F ⟧ (A ∷ As) → A) where cataRec : (G : Functor n) (Gs : Layers (suc m) n) → <! ⟦ G ⟧ (Gs ++∙ μ F As ∷ Bs) !> → ⟦ G ⟧ (Gs ++∙ A ∷ Bs) cataRec (G₁ ⊕ G₂) Gs [! inl x !] = inl (cataRec G₁ Gs [! x !]) cataRec (G₁ ⊕ G₂) Gs [! inr x !] = inr (cataRec G₂ Gs [! x !]) cataRec (G₁ ⊗ G₂) Gs [! x , y !] = cataRec G₁ Gs [! x !] , cataRec G₂ Gs [! y !] cataRec μ⟨ G ⟩ Gs [! ⟨ x ⟩ !] = ⟨ cataRec G (G ∷ Gs) [! x !] ⟩ cataRec (! f0 ) [] [! ⟨ x ⟩ !] = alg (cataRec F [] [! x !]) cataRec (! (fs i)) [] [! x !] = x cataRec (! (fs i)) (G ∷ Gs) [! x !] = cataRec (! i) Gs [! x !] cataRec (! f0 ) (G ∷ Gs) [! ⟨ x ⟩ !] = ⟨ cataRec G (G ∷ Gs) [! x !] ⟩ cataRec ① Gs [! _ !] = tt module _ {F : Functor (suc n)} {As : Params n} where cata : (⟦ F ⟧ (A ∷ As) → A) → μ F As → A cata alg xs = Cata.cataRec alg {Bs = As} (! f0) [] [! xs !] module CataId {k} {F : Functor (suc k)} {As : Params k} where cataRecId : (G : Functor n) (Gs : Layers (suc m) n) → (x : <! ⟦ G ⟧ (Gs ++∙ μ F As ∷ Bs) !>) → Cata.cataRec ⟨_⟩ G Gs x ≡ !! x cataRecId (G₁ ⊕ G₂) Gs [! inl x !] = cong inl (cataRecId G₁ Gs [! x !]) cataRecId (G₁ ⊕ G₂) Gs [! inr x !] = cong inr (cataRecId G₂ Gs [! x !]) cataRecId (G₁ ⊗ G₂) Gs [! x , y !] = cong₂ _,_ (cataRecId G₁ Gs [! x !]) (cataRecId G₂ Gs [! y !]) cataRecId μ⟨ G ⟩ Gs [! ⟨ x ⟩ !] = cong ⟨_⟩ (cataRecId G (G ∷ Gs) [! x !]) cataRecId (! f0 ) [] [! ⟨ x ⟩ !] = cong ⟨_⟩ (cataRecId F [] [! x !]) cataRecId (! (fs i)) [] [! x !] = refl cataRecId (! (fs i)) (G ∷ Gs) [! x !] = cataRecId (! i) Gs [! x !] cataRecId (! f0 ) (G ∷ Gs) [! ⟨ x ⟩ !] = cong ⟨_⟩ ( cataRecId G (G ∷ Gs) [! x !] ) cataRecId ① Gs [! _ !] = refl module _ {F : Functor (suc n)} {As : Params n} where cataId : (x : μ F As) → cata ⟨_⟩ x ≡ x cataId x = CataId.cataRecId (! f0) [] [! x !] --------------------------------------------------------------------------------- -- -- Eliminators -- --------------------------------------------------------------------------------- module Eliminator {As : Params k} {F : Functor (suc k)} (P : μ F As → Type) (f : (x : ⟦ F ⟧ ((∃ x × P x) ∷ As)) → P ⟨ map F f0 fst x ⟩) where open import Path open Mapping open Cata alg : ⟦ F ⟧ ((∃ x × P x) ∷ As) → ∃ x × P x alg x = ⟨ map F f0 fst x ⟩ , f x mutual elimRec : (G : Functor n) (Gs : Layers (suc m) n) → (x : <! ⟦ G ⟧ (Gs ++∙ μ F As ∷ Bs) !>) → mapRec (mapParamAt f0 fst) G Gs [! cataRec alg G Gs x !] ≡ !! x elimRec (G₁ ⊕ G₂) Gs [! inl x !] = cong inl (elimRec G₁ Gs [! x !]) elimRec (G₁ ⊕ G₂) Gs [! inr x !] = cong inr (elimRec G₂ Gs [! x !]) elimRec (G₁ ⊗ G₂) Gs [! x , y !] = cong₂ _,_ (elimRec G₁ Gs [! x !]) (elimRec G₂ Gs [! y !]) elimRec μ⟨ G ⟩ Gs [! ⟨ x ⟩ !] = cong ⟨_⟩ (elimRec G (G ∷ Gs) [! x !]) elimRec (! f0 ) [] [! ⟨ x ⟩ !] = cong ⟨_⟩ (elimRec F [] [! x !]) elimRec (! (fs i)) [] [! x !] = refl elimRec (! (fs i)) (G ∷ Gs) [! x !] = elimRec (! i) Gs [! x !] elimRec (! f0 ) (G ∷ Gs) [! ⟨ x ⟩ !] = cong ⟨_⟩ (elimRec G (G ∷ Gs) [! x !]) elimRec ① Gs [! _ !] = refl elim : ∀ x → P x elim x = subst P (elimRec {Bs = As} (! f0) [] [! x !]) (snd (cata alg x)) module _ {F : Functor (suc n)} where elim : (P : μ F As → Type) → ((x : ⟦ F ⟧ ((∃ x × P x) ∷ As)) → P ⟨ map F f0 fst x ⟩) → (x : μ F As) → P x elim = Eliminator.elim module AlgIsomorphism {F : Functor (suc n)} {As : Params n} where Alg : Type → Type Alg A = ⟦ F ⟧ (A ∷ As) → A AsAlg : Type₁ AsAlg = ∀ A → Alg A → A open import Function.Isomorphism toAlg : μ F As → AsAlg toAlg xs A alg = cata alg xs {-# INLINE toAlg #-} fromAlg : AsAlg → μ F As fromAlg f = f _ ⟨_⟩ {-# INLINE fromAlg #-} rinv : (x : μ F As) → fromAlg (toAlg x) ≡ x rinv = cataId -- think you need parametricity for this -- linv : (x : AsAlg) (A : Type) (alg : Alg A) → toAlg (fromAlg x) A alg ≡ x A alg -- linv x A alg = {!!} -- isom : AsAlg ⇔ μ F As -- isom .fun = fromAlg -- isom .inv = toAlg -- isom .rightInv = rinv -- isom .leftInv x = funExt λ A → funExt λ alg → linv x A alg --------------------------------------------------------------------------------- -- -- Anamorphisms -- --------------------------------------------------------------------------------- -- Coinductive fixpoint record ν (F : Functor (suc n)) (As : Params n) : Type where coinductive; constructor ⟪_⟫ field unfold : ⟦ F ⟧ (ν F As ∷ As) open ν public -- The "proper" anamorphism, which is coinductive. module AnaInf {k} {F : Functor (suc k)} {As : Params k} (coalg : A → ⟦ F ⟧ (A ∷ As)) where mutual anaRec : (G : Functor n) (Gs : Layers (suc m) n) → <! ⟦ G ⟧ (Gs ++∙ A ∷ Bs) !> → <! ⟦ G ⟧ (Gs ++∙ ν F As ∷ Bs) !> anaRec (G₁ ⊕ G₂) Gs [! inl x !] .!! = inl (anaRec G₁ Gs [! x !] .!!) anaRec (G₁ ⊕ G₂) Gs [! inr x !] .!! = inr (anaRec G₂ Gs [! x !] .!!) anaRec (G₁ ⊗ G₂) Gs [! x , y !] .!! .fst = anaRec G₁ Gs [! x !] .!! anaRec (G₁ ⊗ G₂) Gs [! x , y !] .!! .snd = anaRec G₂ Gs [! y !] .!! anaRec μ⟨ G ⟩ Gs [! ⟨ x ⟩ !] .!! = ⟨ anaRec G (G ∷ Gs) [! x !] .!! ⟩ anaRec (! f0 ) [] [! x !] .!! = ana x anaRec (! (fs i)) [] [! x !] .!! = x anaRec (! (fs i)) (G ∷ Gs) [! x !] .!! = anaRec (! i) Gs [! x !] .!! anaRec (! f0 ) (G ∷ Gs) [! ⟨ x ⟩ !] .!! = ⟨ anaRec G (G ∷ Gs) [! x !] .!! ⟩ anaRec ① Gs [! _ !] .!! = tt ana : A → ν F As ana x .unfold = anaRec F [] [! coalg x !] .!! module AnaInfDisplay {F : Functor (suc n)} {As : Params n} where ana : (A → ⟦ F ⟧ (A ∷ As)) → A → ν F As ana = AnaInf.ana open AnaInfDisplay public -- The terminating anamorphism: uses well-founded recursion to ensure we're -- building a finite type. module AnaTerm {B : Type} {_<_ : B → B → Type} (<-wellFounded : WellFounded _<_) {k} {F : Functor (suc k)} {As : Params k} (coalg : (x : B) → ⟦ F ⟧ ((∃ y × (y < x)) ∷ As)) where pr-anaAcc : (x : B) → Acc _<_ x → μ F As pr-anaAcc x (acc wf) = ⟨ map F f0 (λ { (x , p) → pr-anaAcc x (wf x p) }) (coalg x) ⟩ pr-ana : B → μ F As pr-ana x = pr-anaAcc x (<-wellFounded x) module AnaTermDisplay {A : Type} {_<_ : A → A → Type} {F : Functor (suc n)} {As : Params n} where pr-ana : WellFounded _<_ → ((x : A) → ⟦ F ⟧ ((∃ y × (y < x)) ∷ As)) → A → μ F As pr-ana wf = AnaTerm.pr-ana wf module Truncate {B : Type} {_<_ : B → B → Type} (<-wellFounded : WellFounded _<_) {k} {F : Functor (suc k)} {As : Params k} (step : (x : B) -> ⟦ F ⟧ (ν F As ∷ As) → ⟦ F ⟧ ((ν F As × ∃ y × (y < x)) ∷ As)) where truncAcc : (x : B) → Acc _<_ x → ν F As → μ F As truncAcc x (acc wf) xs = ⟨ map F f0 (λ { (ys , z , z<x) → truncAcc z (wf z z<x) ys}) (step x (xs .unfold)) ⟩ trunc : B → ν F As → μ F As trunc x = truncAcc x (<-wellFounded x) module TruncDisplay {A : Type} {_<_ : A → A → Type} {F : Functor (suc n)} {As : Params n} where trunc : WellFounded _<_ → ((x : A) -> ⟦ F ⟧ (ν F As ∷ As) → ⟦ F ⟧ ((ν F As × ∃ y × (y < x)) ∷ As)) → A → ν F As → μ F As trunc wf step = Truncate.trunc wf step
{ "alphanum_fraction": 0.436459431, "avg_line_length": 38.163538874, "ext": "agda", "hexsha": "795a9ba3008dd26aa577746d04fa7c62850cf023", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Data/PolyP/RecursionSchemes.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Data/PolyP/RecursionSchemes.agda", "max_line_length": 117, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Data/PolyP/RecursionSchemes.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 5668, "size": 14235 }
module SystemF.WellTyped where open import Prelude hiding (id; erase) open import SystemF.Syntax public open import SystemF.Substitutions open import Data.Vec hiding ([_]) open import Data.Vec.Properties open import Data.Product infix 4 _⊢_∈_ data _⊢_∈_ {ν n} (Γ : Ctx ν n) : Term ν n → Type ν → Set where var : (x : Fin n) → Γ ⊢ var x ∈ lookup x Γ Λ : ∀ {t a} → (ctx-weaken Γ) ⊢ t ∈ a → Γ ⊢ Λ t ∈ ∀' a λ' : ∀ {t b} → (a : Type ν) → a ∷ Γ ⊢ t ∈ b → Γ ⊢ λ' a t ∈ a →' b _[_] : ∀ {t a} → Γ ⊢ t ∈ ∀' a → (b : Type ν) → Γ ⊢ t [ b ] ∈ a tp[/tp b ] _·_ : ∀ {f t a b} → Γ ⊢ f ∈ (a →' b) → Γ ⊢ t ∈ a → Γ ⊢ f · t ∈ b _⊢_∉_ : ∀ {ν n} → (Γ : Ctx ν n) → Term ν n → Type ν → Set _⊢_∉_ Γ t τ = ¬ Γ ⊢ t ∈ τ erase : ∀ {ν n} {Γ : Ctx ν n} {t τ} → Γ ⊢ t ∈ τ → Term ν n erase (var x) = var x erase (Λ {t} x) = Λ t erase (λ' {t} a x) = λ' a t erase (_[_] {t} x b) = t erase (_·_ {f} x x₁) = f ⊢f·a-inversion : ∀ {ν n f t b} {Γ : Ctx ν n} → Γ ⊢ f · t ∈ b → ∃ λ a → Γ ⊢ f ∈ a →' b × Γ ⊢ t ∈ a ⊢f·a-inversion (_·_ f∈a→b t∈a) = , (f∈a→b , t∈a) ⊢tc[a]-inversion : ∀ {ν n tc a' b} {Γ : Ctx ν n} → Γ ⊢ tc [ b ] ∈ a' → ∃ λ a → Γ ⊢ tc ∈ ∀' a ⊢tc[a]-inversion (_[_] tc∈∀'a b) = , tc∈∀'a unique-type : ∀ {ν n} {Γ : Ctx ν n} {t τ τ'} → Γ ⊢ t ∈ τ → Γ ⊢ t ∈ τ' → τ ≡ τ' unique-type (var x) (var .x) = refl unique-type (Λ l) (Λ r) = cong ∀' (unique-type l r) unique-type (λ' a l) (λ' .a r) = cong (λ b → a →' b) (unique-type l r) unique-type (l [ b ]) (r [ .b ]) = cong (λ{ (∀' fa) → fa tp[/tp b ]; a → a}) (unique-type l r) unique-type (f · e) (f' · e') = cong (λ{ (a →' b) → b; a → a }) (unique-type f f') unique-type′ : ∀ {ν n} {Γ : Ctx ν n} {t τ τ'} → Γ ⊢ t ∈ τ → τ ≢ τ' → Γ ⊢ t ∉ τ' unique-type′ ⊢t∈τ neq ⊢t∈τ' = neq $ unique-type ⊢t∈τ ⊢t∈τ' -- Collections of typing derivations for well-typed terms. data _⊢ⁿ_∈_ {m n} (Γ : Ctx n m) : ∀ {k} → Vec (Term n m) k → Vec (Type n) k → Set where [] : Γ ⊢ⁿ [] ∈ [] _∷_ : ∀ {t a k} {ts : Vec (Term n m) k} {as : Vec (Type n) k} → Γ ⊢ t ∈ a → Γ ⊢ⁿ ts ∈ as → Γ ⊢ⁿ t ∷ ts ∈ (a ∷ as) -- Lookup a well-typed term in a collection thereof. lookup-⊢ : ∀ {m n k} {Γ : Ctx n m} {ts : Vec (Term n m) k} {as : Vec (Type n) k} → (x : Fin k) → Γ ⊢ⁿ ts ∈ as → Γ ⊢ lookup x ts ∈ lookup x as lookup-⊢ zero (⊢t ∷ ⊢ts) = ⊢t lookup-⊢ (suc x) (⊢t ∷ ⊢ts) = lookup-⊢ x ⊢ts
{ "alphanum_fraction": 0.4668649108, "avg_line_length": 39.8983050847, "ext": "agda", "hexsha": "97d86f080a0ffeb1144dfc28d4c98e103501b665", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "metaborg/ts.agda", "max_forks_repo_path": "src/SystemF/WellTyped.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "metaborg/ts.agda", "max_issues_repo_path": "src/SystemF/WellTyped.agda", "max_line_length": 94, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_path": "src/SystemF/WellTyped.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z", "max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z", "num_tokens": 1163, "size": 2354 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Foundations.Pointed.Homotopy where {- This module defines two kinds of pointed homotopies, ∙∼ and ∙∼P, and proves their equivalence -} open import Cubical.Foundations.Prelude open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.Fiberwise open import Cubical.Foundations.Equiv.Properties open import Cubical.Foundations.Path open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Foundations.Pointed.Base open import Cubical.Foundations.Pointed.Properties open import Cubical.Homotopy.Base open import Cubical.Data.Sigma private variable ℓ ℓ' : Level module _ {A : Pointed ℓ} {B : typ A → Type ℓ'} {ptB : B (pt A)} where ⋆ = pt A -- pointed homotopy as pointed Π. This is just a Σ-type, see ∙∼Σ _∙∼_ : (f g : Π∙ A B ptB) → Type (ℓ-max ℓ ℓ') (f₁ , f₂) ∙∼ (g₁ , g₂) = Π∙ A (λ x → f₁ x ≡ g₁ x) (f₂ ∙ g₂ ⁻¹) -- pointed homotopy with PathP. Also a Σ-type, see ∙∼PΣ _∙∼P_ : (f g : Π∙ A B ptB) → Type (ℓ-max ℓ ℓ') (f₁ , f₂) ∙∼P (g₁ , g₂) = Σ[ h ∈ f₁ ∼ g₁ ] PathP (λ i → h ⋆ i ≡ ptB) f₂ g₂ -- Proof that f ∙∼ g ≃ f ∙∼P g -- using equivalence of the total map of φ private module _ (f g : Π∙ A B ptB) (H : f .fst ∼ g .fst) where -- convenient notation f₁ = fst f f₂ = snd f g₁ = fst g g₂ = snd g -- P is the predicate on a homotopy H to be pointed of the ∙∼ kind P : Type ℓ' P = H ⋆ ≡ f₂ ∙ g₂ ⁻¹ -- Q is the predicate on a homotopy H to be pointed of the ∙∼P kind Q : Type ℓ' Q = PathP (λ i → H ⋆ i ≡ ptB) f₂ g₂ -- simplify the notation even more to see that P≡Q -- is just a jingle of paths p = H ⋆ r = f₂ s = g₂ P≡Q : P ≡ Q P≡Q = p ≡ r ∙ s ⁻¹ ≡⟨ isoToPath (symIso p (r ∙ s ⁻¹)) ⟩ r ∙ s ⁻¹ ≡ p ≡⟨ cong (r ∙ s ⁻¹ ≡_) (rUnit p ∙∙ cong (p ∙_) (sym (rCancel s)) ∙∙ assoc p s (s ⁻¹)) ⟩ r ∙ s ⁻¹ ≡ (p ∙ s) ∙ s ⁻¹ ≡⟨ sym (ua (compr≡Equiv r (p ∙ s) (s ⁻¹))) ⟩ r ≡ p ∙ s ≡⟨ ua (compl≡Equiv (p ⁻¹) r (p ∙ s)) ⟩ p ⁻¹ ∙ r ≡ p ⁻¹ ∙ (p ∙ s) ≡⟨ cong (p ⁻¹ ∙ r ≡_ ) (assoc (p ⁻¹) p s ∙∙ (cong (_∙ s) (lCancel p)) ∙∙ sym (lUnit s)) ⟩ p ⁻¹ ∙ r ≡ s ≡⟨ cong (λ z → p ⁻¹ ∙ z ≡ s) (rUnit r) ⟩ p ⁻¹ ∙ (r ∙ refl) ≡ s ≡⟨ cong (_≡ s) (sym (doubleCompPath-elim' (p ⁻¹) r refl)) ⟩ p ⁻¹ ∙∙ r ∙∙ refl ≡ s ≡⟨ sym (ua (Square≃doubleComp r s p refl)) ⟩ PathP (λ i → p i ≡ ptB) r s ∎ -- φ is a fiberwise transformation (H : f ∼ g) → P H → Q H -- φ is even a fiberwise equivalence by P≡Q φ : P → Q φ = transport P≡Q -- The total map corresponding to φ totφ : (f g : Π∙ A B ptB) → f ∙∼ g → f ∙∼P g totφ f g p .fst = p .fst totφ f g p .snd = φ f g (p .fst) (p .snd) -- transformation of the homotopies using totφ ∙∼→∙∼P : (f g : Π∙ A B ptB) → (f ∙∼ g) → (f ∙∼P g) ∙∼→∙∼P f g = totφ f g -- Proof that ∙∼ and ∙∼P are equivalent using the fiberwise equivalence φ ∙∼≃∙∼P : (f g : Π∙ A B ptB) → (f ∙∼ g) ≃ (f ∙∼P g) ∙∼≃∙∼P f g = Σ-cong-equiv-snd (λ H → transportEquiv (P≡Q f g H)) -- inverse of ∙∼→∙∼P extracted from the equivalence ∙∼P→∙∼ : {f g : Π∙ A B ptB} → f ∙∼P g → f ∙∼ g ∙∼P→∙∼ {f = f} {g = g} = invEq (∙∼≃∙∼P f g) -- ∙∼≃∙∼P transformed to a path ∙∼≡∙∼P : (f g : Π∙ A B ptB) → (f ∙∼ g) ≡ (f ∙∼P g) ∙∼≡∙∼P f g = ua (∙∼≃∙∼P f g) -- Verifies that the pointed homotopies actually correspond -- to their Σ-type versions _∙∼Σ_ : (f g : Π∙ A B ptB) → Type (ℓ-max ℓ ℓ') f ∙∼Σ g = Σ[ H ∈ f .fst ∼ g .fst ] (P f g H) _∙∼PΣ_ : (f g : Π∙ A B ptB) → Type (ℓ-max ℓ ℓ') f ∙∼PΣ g = Σ[ H ∈ f .fst ∼ g .fst ] (Q f g H) ∙∼≡∙∼Σ : (f g : Π∙ A B ptB) → f ∙∼ g ≡ f ∙∼Σ g ∙∼≡∙∼Σ f g = refl ∙∼P≡∙∼PΣ : (f g : Π∙ A B ptB) → f ∙∼P g ≡ f ∙∼PΣ g ∙∼P≡∙∼PΣ f g = refl
{ "alphanum_fraction": 0.5139774399, "avg_line_length": 33.9833333333, "ext": "agda", "hexsha": "fc3ea2bb82328056e2896b3fef6ff56e62b64581", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "L-TChen/cubical", "max_forks_repo_path": "Cubical/Foundations/Pointed/Homotopy.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "L-TChen/cubical", "max_issues_repo_path": "Cubical/Foundations/Pointed/Homotopy.agda", "max_line_length": 103, "max_stars_count": null, "max_stars_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "L-TChen/cubical", "max_stars_repo_path": "Cubical/Foundations/Pointed/Homotopy.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1944, "size": 4078 }
open import Prelude open import core module lemmas-matching where -- matching produces unique answers for arrows, sums, and products ▸arr-unicity : ∀{ t t2 t3 } → t ▸arr t2 → t ▸arr t3 → t2 == t3 ▸arr-unicity MAHole MAHole = refl ▸arr-unicity MAArr MAArr = refl -- if an arrow matches, then it's consistent with the least restrictive -- function type matchconsisthole : ∀{t t'} → t ▸arr t' → t ~ (⦇-⦈ ==> ⦇-⦈) matchconsisthole MAHole = TCHole2 matchconsisthole MAArr = TCArr TCHole1 TCHole1 match-consist : ∀{τ1 τ2} → τ1 ▸arr τ2 → (τ2 ~ τ1) match-consist MAHole = TCHole1 match-consist MAArr = TCRefl match-unicity : ∀{ τ τ1 τ2} → τ ▸arr τ1 → τ ▸arr τ2 → τ1 == τ2 match-unicity MAHole MAHole = refl match-unicity MAArr MAArr = refl
{ "alphanum_fraction": 0.6028202115, "avg_line_length": 30.3928571429, "ext": "agda", "hexsha": "b07c4dc969e8d2bb5b12c16e6ef8cdf794cf5de5", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_path": "lemmas-matching.agda", "max_issues_count": 54, "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_path": "lemmas-matching.agda", "max_line_length": 73, "max_stars_count": 16, "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_path": "lemmas-matching.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "num_tokens": 318, "size": 851 }
-- Reported by Christian Sattler on 2019-12-07 open import Agda.Primitive postulate i : Level X : Set i mutual j : Level j = _ Y : Set j Y = X -- WAS: unsolved constraint i = _2 -- SHOULD: succeed with everything solved
{ "alphanum_fraction": 0.6624472574, "avg_line_length": 13.1666666667, "ext": "agda", "hexsha": "90ad91b95c75f6c05806a90ca4548a1525a1a368", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue4269.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue4269.agda", "max_line_length": 46, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue4269.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 79, "size": 237 }
module Warnings where -- empty rewrite pragma {-# REWRITE #-} -- termination checking error A : Set A = A data Nat : Set where zero : Nat suc : Nat -> Nat {-# BUILTIN NATURAL Nat #-} -- deprecated BUILTIN ZERO {-# BUILTIN ZERO zero #-} -- An open goal g : Set g = {!!}
{ "alphanum_fraction": 0.6200716846, "avg_line_length": 12.6818181818, "ext": "agda", "hexsha": "2b9ff552c6fc9013f1f69566f1d1a8e04f6dff7c", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/interaction/Warnings.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/interaction/Warnings.agda", "max_line_length": 29, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/interaction/Warnings.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 77, "size": 279 }
------------------------------------------------------------------------ -- The Agda standard library -- -- A universe which includes several kinds of "relatedness" for sets, -- such as equivalences, surjections and bijections ------------------------------------------------------------------------ module Function.Related where open import Level open import Function open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence as Eq using (Equivalence) open import Function.Injection as Inj using (Injection; _↣_) open import Function.Inverse as Inv using (Inverse; _↔_) open import Function.LeftInverse as LeftInv using (LeftInverse) open import Function.Surjection as Surj using (Surjection) open import Relation.Binary open import Relation.Binary.PropositionalEquality as P using (_≡_) ------------------------------------------------------------------------ -- Wrapper types -- Synonyms which are used to make _∼[_]_ below "constructor-headed" -- (which implies that Agda can deduce the universe code from an -- expression matching any of the right-hand sides). record _←_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where constructor lam field app-← : B → A open _←_ public record _↢_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where constructor lam field app-↢ : B ↣ A open _↢_ public ------------------------------------------------------------------------ -- Relatedness -- There are several kinds of "relatedness". -- The idea to include kinds other than equivalence and bijection came -- from Simon Thompson and Bengt Nordström. /NAD data Kind : Set where implication reverse-implication equivalence injection reverse-injection left-inverse surjection bijection : Kind -- Interpretation of the codes above. The code "bijection" is -- interpreted as Inverse rather than Bijection; the two types are -- equivalent. infix 4 _∼[_]_ _∼[_]_ : ∀ {ℓ₁ ℓ₂} → Set ℓ₁ → Kind → Set ℓ₂ → Set _ A ∼[ implication ] B = A → B A ∼[ reverse-implication ] B = A ← B A ∼[ equivalence ] B = Equivalence (P.setoid A) (P.setoid B) A ∼[ injection ] B = Injection (P.setoid A) (P.setoid B) A ∼[ reverse-injection ] B = A ↢ B A ∼[ left-inverse ] B = LeftInverse (P.setoid A) (P.setoid B) A ∼[ surjection ] B = Surjection (P.setoid A) (P.setoid B) A ∼[ bijection ] B = Inverse (P.setoid A) (P.setoid B) -- A non-infix synonym. Related : Kind → ∀ {ℓ₁ ℓ₂} → Set ℓ₁ → Set ℓ₂ → Set _ Related k A B = A ∼[ k ] B -- The bijective equality implies any kind of relatedness. ↔⇒ : ∀ {k x y} {X : Set x} {Y : Set y} → X ∼[ bijection ] Y → X ∼[ k ] Y ↔⇒ {implication} = _⟨$⟩_ ∘ Inverse.to ↔⇒ {reverse-implication} = lam ∘′ _⟨$⟩_ ∘ Inverse.from ↔⇒ {equivalence} = Inverse.equivalence ↔⇒ {injection} = Inverse.injection ↔⇒ {reverse-injection} = lam ∘′ Inverse.injection ∘ Inv.sym ↔⇒ {left-inverse} = Inverse.left-inverse ↔⇒ {surjection} = Inverse.surjection ↔⇒ {bijection} = id -- Actual equality also implies any kind of relatedness. ≡⇒ : ∀ {k ℓ} {X Y : Set ℓ} → X ≡ Y → X ∼[ k ] Y ≡⇒ P.refl = ↔⇒ Inv.id ------------------------------------------------------------------------ -- Special kinds of kinds -- Kinds whose interpretation is symmetric. data Symmetric-kind : Set where equivalence bijection : Symmetric-kind -- Forgetful map. ⌊_⌋ : Symmetric-kind → Kind ⌊ equivalence ⌋ = equivalence ⌊ bijection ⌋ = bijection -- The proof of symmetry can be found below. -- Kinds whose interpretation include a function which "goes in the -- forward direction". data Forward-kind : Set where implication equivalence injection left-inverse surjection bijection : Forward-kind -- Forgetful map. ⌊_⌋→ : Forward-kind → Kind ⌊ implication ⌋→ = implication ⌊ equivalence ⌋→ = equivalence ⌊ injection ⌋→ = injection ⌊ left-inverse ⌋→ = left-inverse ⌊ surjection ⌋→ = surjection ⌊ bijection ⌋→ = bijection -- The function. ⇒→ : ∀ {k x y} {X : Set x} {Y : Set y} → X ∼[ ⌊ k ⌋→ ] Y → X → Y ⇒→ {implication} = id ⇒→ {equivalence} = _⟨$⟩_ ∘ Equivalence.to ⇒→ {injection} = _⟨$⟩_ ∘ Injection.to ⇒→ {left-inverse} = _⟨$⟩_ ∘ LeftInverse.to ⇒→ {surjection} = _⟨$⟩_ ∘ Surjection.to ⇒→ {bijection} = _⟨$⟩_ ∘ Inverse.to -- Kinds whose interpretation include a function which "goes backwards". data Backward-kind : Set where reverse-implication equivalence reverse-injection left-inverse surjection bijection : Backward-kind -- Forgetful map. ⌊_⌋← : Backward-kind → Kind ⌊ reverse-implication ⌋← = reverse-implication ⌊ equivalence ⌋← = equivalence ⌊ reverse-injection ⌋← = reverse-injection ⌊ left-inverse ⌋← = left-inverse ⌊ surjection ⌋← = surjection ⌊ bijection ⌋← = bijection -- The function. ⇒← : ∀ {k x y} {X : Set x} {Y : Set y} → X ∼[ ⌊ k ⌋← ] Y → Y → X ⇒← {reverse-implication} = app-← ⇒← {equivalence} = _⟨$⟩_ ∘ Equivalence.from ⇒← {reverse-injection} = _⟨$⟩_ ∘ Injection.to ∘ app-↢ ⇒← {left-inverse} = _⟨$⟩_ ∘ LeftInverse.from ⇒← {surjection} = _⟨$⟩_ ∘ Surjection.from ⇒← {bijection} = _⟨$⟩_ ∘ Inverse.from -- Kinds whose interpretation include functions going in both -- directions. data Equivalence-kind : Set where equivalence left-inverse surjection bijection : Equivalence-kind -- Forgetful map. ⌊_⌋⇔ : Equivalence-kind → Kind ⌊ equivalence ⌋⇔ = equivalence ⌊ left-inverse ⌋⇔ = left-inverse ⌊ surjection ⌋⇔ = surjection ⌊ bijection ⌋⇔ = bijection -- The functions. ⇒⇔ : ∀ {k x y} {X : Set x} {Y : Set y} → X ∼[ ⌊ k ⌋⇔ ] Y → X ∼[ equivalence ] Y ⇒⇔ {equivalence} = id ⇒⇔ {left-inverse} = LeftInverse.equivalence ⇒⇔ {surjection} = Surjection.equivalence ⇒⇔ {bijection} = Inverse.equivalence -- Conversions between special kinds. ⇔⌊_⌋ : Symmetric-kind → Equivalence-kind ⇔⌊ equivalence ⌋ = equivalence ⇔⌊ bijection ⌋ = bijection →⌊_⌋ : Equivalence-kind → Forward-kind →⌊ equivalence ⌋ = equivalence →⌊ left-inverse ⌋ = left-inverse →⌊ surjection ⌋ = surjection →⌊ bijection ⌋ = bijection ←⌊_⌋ : Equivalence-kind → Backward-kind ←⌊ equivalence ⌋ = equivalence ←⌊ left-inverse ⌋ = left-inverse ←⌊ surjection ⌋ = surjection ←⌊ bijection ⌋ = bijection ------------------------------------------------------------------------ -- Opposites -- For every kind there is an opposite kind. _op : Kind → Kind implication op = reverse-implication reverse-implication op = implication equivalence op = equivalence injection op = reverse-injection reverse-injection op = injection left-inverse op = surjection surjection op = left-inverse bijection op = bijection -- For every morphism there is a corresponding reverse morphism of the -- opposite kind. reverse : ∀ {k a b} {A : Set a} {B : Set b} → A ∼[ k ] B → B ∼[ k op ] A reverse {implication} = lam reverse {reverse-implication} = app-← reverse {equivalence} = Eq.sym reverse {injection} = lam reverse {reverse-injection} = app-↢ reverse {left-inverse} = Surj.fromRightInverse reverse {surjection} = Surjection.right-inverse reverse {bijection} = Inv.sym ------------------------------------------------------------------------ -- Equational reasoning -- Equational reasoning for related things. module EquationalReasoning where private refl : ∀ {k ℓ} → Reflexive (Related k {ℓ}) refl {implication} = id refl {reverse-implication} = lam id refl {equivalence} = Eq.id refl {injection} = Inj.id refl {reverse-injection} = lam Inj.id refl {left-inverse} = LeftInv.id refl {surjection} = Surj.id refl {bijection} = Inv.id trans : ∀ {k ℓ₁ ℓ₂ ℓ₃} → Trans (Related k {ℓ₁} {ℓ₂}) (Related k {ℓ₂} {ℓ₃}) (Related k {ℓ₁} {ℓ₃}) trans {implication} = flip _∘′_ trans {reverse-implication} = λ f g → lam (app-← f ∘ app-← g) trans {equivalence} = flip Eq._∘_ trans {injection} = flip Inj._∘_ trans {reverse-injection} = λ f g → lam (Inj._∘_ (app-↢ f) (app-↢ g)) trans {left-inverse} = flip LeftInv._∘_ trans {surjection} = flip Surj._∘_ trans {bijection} = flip Inv._∘_ sym : ∀ {k ℓ₁ ℓ₂} → Sym (Related ⌊ k ⌋ {ℓ₁} {ℓ₂}) (Related ⌊ k ⌋ {ℓ₂} {ℓ₁}) sym {equivalence} = Eq.sym sym {bijection} = Inv.sym infix 2 _∎ infixr 2 _∼⟨_⟩_ _↔⟨_⟩_ _↔⟨⟩_ _≡⟨_⟩_ _∼⟨_⟩_ : ∀ {k x y z} (X : Set x) {Y : Set y} {Z : Set z} → X ∼[ k ] Y → Y ∼[ k ] Z → X ∼[ k ] Z _ ∼⟨ X↝Y ⟩ Y↝Z = trans X↝Y Y↝Z -- Isomorphisms can be combined with any other kind of relatedness. _↔⟨_⟩_ : ∀ {k x y z} (X : Set x) {Y : Set y} {Z : Set z} → X ↔ Y → Y ∼[ k ] Z → X ∼[ k ] Z X ↔⟨ X↔Y ⟩ Y⇔Z = X ∼⟨ ↔⇒ X↔Y ⟩ Y⇔Z _↔⟨⟩_ : ∀ {k x y} (X : Set x) {Y : Set y} → X ∼[ k ] Y → X ∼[ k ] Y X ↔⟨⟩ X⇔Y = X⇔Y _≡⟨_⟩_ : ∀ {k ℓ z} (X : Set ℓ) {Y : Set ℓ} {Z : Set z} → X ≡ Y → Y ∼[ k ] Z → X ∼[ k ] Z X ≡⟨ X≡Y ⟩ Y⇔Z = X ∼⟨ ≡⇒ X≡Y ⟩ Y⇔Z _∎ : ∀ {k x} (X : Set x) → X ∼[ k ] X X ∎ = refl -- For a symmetric kind and a fixed universe level we can construct a -- setoid. setoid : Symmetric-kind → (ℓ : Level) → Setoid _ _ setoid k ℓ = record { Carrier = Set ℓ ; _≈_ = Related ⌊ k ⌋ ; isEquivalence = record {refl = _ ∎; sym = sym; trans = _∼⟨_⟩_ _} } where open EquationalReasoning -- For an arbitrary kind and a fixed universe level we can construct a -- preorder. preorder : Kind → (ℓ : Level) → Preorder _ _ _ preorder k ℓ = record { Carrier = Set ℓ ; _≈_ = _↔_ ; _∼_ = Related k ; isPreorder = record { isEquivalence = Setoid.isEquivalence (setoid bijection ℓ) ; reflexive = ↔⇒ ; trans = _∼⟨_⟩_ _ } } where open EquationalReasoning ------------------------------------------------------------------------ -- Some induced relations -- Every unary relation induces a preorder and, for symmetric kinds, -- an equivalence. (No claim is made that these relations are unique.) InducedRelation₁ : Kind → ∀ {a s} {A : Set a} → (A → Set s) → A → A → Set _ InducedRelation₁ k S = λ x y → S x ∼[ k ] S y InducedPreorder₁ : Kind → ∀ {a s} {A : Set a} → (A → Set s) → Preorder _ _ _ InducedPreorder₁ k S = record { _≈_ = P._≡_ ; _∼_ = InducedRelation₁ k S ; isPreorder = record { isEquivalence = P.isEquivalence ; reflexive = reflexive ∘ Setoid.reflexive (setoid bijection _) ∘ P.cong S ; trans = trans } } where open Preorder (preorder _ _) InducedEquivalence₁ : Symmetric-kind → ∀ {a s} {A : Set a} → (A → Set s) → Setoid _ _ InducedEquivalence₁ k S = record { _≈_ = InducedRelation₁ ⌊ k ⌋ S ; isEquivalence = record {refl = refl; sym = sym; trans = trans} } where open Setoid (setoid _ _) -- Every binary relation induces a preorder and, for symmetric kinds, -- an equivalence. (No claim is made that these relations are unique.) InducedRelation₂ : Kind → ∀ {a b s} {A : Set a} {B : Set b} → (A → B → Set s) → B → B → Set _ InducedRelation₂ k _S_ = λ x y → ∀ {z} → (z S x) ∼[ k ] (z S y) InducedPreorder₂ : Kind → ∀ {a b s} {A : Set a} {B : Set b} → (A → B → Set s) → Preorder _ _ _ InducedPreorder₂ k _S_ = record { _≈_ = P._≡_ ; _∼_ = InducedRelation₂ k _S_ ; isPreorder = record { isEquivalence = P.isEquivalence ; reflexive = λ x≡y {z} → reflexive $ Setoid.reflexive (setoid bijection _) $ P.cong (_S_ z) x≡y ; trans = λ i↝j j↝k → trans i↝j j↝k } } where open Preorder (preorder _ _) InducedEquivalence₂ : Symmetric-kind → ∀ {a b s} {A : Set a} {B : Set b} → (A → B → Set s) → Setoid _ _ InducedEquivalence₂ k _S_ = record { _≈_ = InducedRelation₂ ⌊ k ⌋ _S_ ; isEquivalence = record { refl = refl ; sym = λ i↝j → sym i↝j ; trans = λ i↝j j↝k → trans i↝j j↝k } } where open Setoid (setoid _ _)
{ "alphanum_fraction": 0.5601391248, "avg_line_length": 31.9457364341, "ext": "agda", "hexsha": "2a08835bfe426b276a840da9132cdd0963b2481b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Function/Related.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Function/Related.agda", "max_line_length": 75, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Function/Related.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 4241, "size": 12363 }
{-# OPTIONS --cubical --no-sized-types --guardedness --safe #-} module Issue3564 where record Stream (A : Set) : Set where coinductive field head : A field tail : Stream A open Stream data A : Set where a : A someA : Stream A head someA = a tail someA = someA -- WAS: termination check failed -- NOW: OK
{ "alphanum_fraction": 0.678343949, "avg_line_length": 17.4444444444, "ext": "agda", "hexsha": "a645a42e89ba69d0e2c55589e8dc9760480c6d2d", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue3564.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue3564.agda", "max_line_length": 63, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue3564.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 94, "size": 314 }
------------------------------------------------------------------------------ -- The gcd is a common divisor ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module LTC-PCF.Program.GCD.Partial.CommonDivisor where open import LTC-PCF.Base open import LTC-PCF.Base.Properties open import LTC-PCF.Data.Nat open import LTC-PCF.Data.Nat.Divisibility.NotBy0 open import LTC-PCF.Data.Nat.Divisibility.NotBy0.Properties open import LTC-PCF.Data.Nat.Induction.NonAcc.Lexicographic open import LTC-PCF.Data.Nat.Inequalities open import LTC-PCF.Data.Nat.Inequalities.EliminationProperties open import LTC-PCF.Data.Nat.Inequalities.Properties open import LTC-PCF.Data.Nat.Properties open import LTC-PCF.Program.GCD.Partial.ConversionRules open import LTC-PCF.Program.GCD.Partial.Definitions open import LTC-PCF.Program.GCD.Partial.GCD open import LTC-PCF.Program.GCD.Partial.Totality ------------------------------------------------------------------------------ -- Some cases of the gcd-∣₁. -- We don't prove that -- -- gcd-∣₁ : ... → (gcd m n) ∣ m -- because this proof should be defined mutually recursive with the -- proof -- -- gcd-∣₂ : ... → (gcd m n) ∣ n. -- -- Therefore, instead of proving -- -- gcdCD : ... → CD m n (gcd m n) -- -- using these proofs (i.e. the conjunction of them), we proved it -- using well-founded induction. -- gcd 0 (succ n) ∣ 0. gcd-0S-∣₁ : ∀ {n} → N n → gcd zero (succ₁ n) ∣ zero gcd-0S-∣₁ {n} Nn = subst (λ x → x ∣ zero) (sym (gcd-0S n)) (S∣0 Nn) -- gcd (succ₁ m) 0 ∣ succ₁ m. gcd-S0-∣₁ : ∀ {m} → N m → gcd (succ₁ m) zero ∣ succ₁ m gcd-S0-∣₁ {m} Nm = subst (λ x → x ∣ succ₁ m) (sym (gcd-S0 m)) (∣-refl-S Nm) -- gcd (succ₁ m) (succ₁ n) ∣ succ₁ m, when succ₁ m ≯ succ₁ n. gcd-S≯S-∣₁ : ∀ {m n} → N m → N n → (gcd (succ₁ m) (succ₁ n ∸ succ₁ m) ∣ succ₁ m) → succ₁ m ≯ succ₁ n → gcd (succ₁ m) (succ₁ n) ∣ succ₁ m gcd-S≯S-∣₁ {m} {n} Nm Nn ih Sm≯Sn = subst (λ x → x ∣ succ₁ m) (sym (gcd-S≯S m n Sm≯Sn)) ih -- gcd (succ₁ m) (succ₁ n) ∣ succ₁ m when succ₁ m > succ₁ n. -- We use gcd-∣₂. -- We apply the theorem that if m∣n and m∣o then m∣(n+o). gcd-S>S-∣₁ : ∀ {m n} → N m → N n → (gcd (succ₁ m ∸ succ₁ n) (succ₁ n) ∣ (succ₁ m ∸ succ₁ n)) → (gcd (succ₁ m ∸ succ₁ n) (succ₁ n) ∣ succ₁ n) → succ₁ m > succ₁ n → gcd (succ₁ m) (succ₁ n) ∣ succ₁ m {- Proof: 1. gcd (Sm ∸ Sn) Sn | (Sm ∸ Sn) IH 2. gcd (Sm ∸ Sn) Sn | Sn gcd-∣₂ 3. gcd (Sm ∸ Sn) Sn | (Sm ∸ Sn) + Sn m∣n→m∣o→m∣n+o 1,2 4. Sm > Sn Hip 5. gcd (Sm ∸ Sn) Sn | Sm arith-gcd-m>n₂ 3,4 6. gcd Sm Sn = gcd (Sm ∸ Sn) Sn gcd eq. 4 7. gcd Sm Sn | Sm subst 5,6 -} gcd-S>S-∣₁ {m} {n} Nm Nn ih gcd-∣₂ Sm>Sn = -- The first substitution is based on -- gcd (succ₁ m) (succ₁ n) = gcd (succ₁ m ∸ succ₁ n) (succ₁ n). subst (λ x → x ∣ succ₁ m) (sym (gcd-S>S m n Sm>Sn)) -- The second substitution is based on -- m = (m ∸ n) + n. (subst (λ y → gcd (succ₁ m ∸ succ₁ n) (succ₁ n) ∣ y) (x>y→x∸y+y≡x (nsucc Nm) (nsucc Nn) Sm>Sn) (x∣y→x∣z→x∣y+z {gcd (succ₁ m ∸ succ₁ n) (succ₁ n)} {succ₁ m ∸ succ₁ n} {succ₁ n} (gcd-N Sm-Sn-N (nsucc Nn) (λ p → ⊥-elim (S≢0 (∧-proj₂ p)))) Sm-Sn-N (nsucc Nn) ih gcd-∣₂ ) ) where Sm-Sn-N : N (succ₁ m ∸ succ₁ n) Sm-Sn-N = ∸-N (nsucc Nm) (nsucc Nn) ------------------------------------------------------------------------------ -- Some case of the gcd-∣₂ -- We don't prove that gcd-∣₂ : ... → gcd m n ∣ n. The reason is -- the same to don't prove gcd-∣₁ : ... → gcd m n ∣ m. -- gcd 0 (succ₁ n) ∣₂ succ₁ n. gcd-0S-∣₂ : ∀ {n} → N n → gcd zero (succ₁ n) ∣ succ₁ n gcd-0S-∣₂ {n} Nn = subst (λ x → x ∣ succ₁ n) (sym (gcd-0S n)) (∣-refl-S Nn) -- gcd (succ₁ m) 0 ∣ 0. gcd-S0-∣₂ : ∀ {m} → N m → gcd (succ₁ m) zero ∣ zero gcd-S0-∣₂ {m} Nm = subst (λ x → x ∣ zero) (sym (gcd-S0 m)) (S∣0 Nm) -- gcd (succ₁ m) (succ₁ n) ∣ succ₁ n when succ₁ m > succ₁ n. gcd-S>S-∣₂ : ∀ {m n} → N m → N n → (gcd (succ₁ m ∸ succ₁ n) (succ₁ n) ∣ succ₁ n) → succ₁ m > succ₁ n → gcd (succ₁ m) (succ₁ n) ∣ succ₁ n gcd-S>S-∣₂ {m} {n} Nm Nn ih Sm>Sn = subst (λ x → x ∣ succ₁ n) (sym (gcd-S>S m n Sm>Sn)) ih -- gcd (succ₁ m) (succ₁ n) ∣ succ₁ n when succ₁ m ≯ succ₁ n. -- We use gcd-∣₁. -- We apply the theorem that if m∣n and m∣o then m∣(n+o). gcd-S≯S-∣₂ : ∀ {m n} → N m → N n → (gcd (succ₁ m) (succ₁ n ∸ succ₁ m) ∣ (succ₁ n ∸ succ₁ m)) → (gcd (succ₁ m) (succ₁ n ∸ succ₁ m) ∣ succ₁ m) → succ₁ m ≯ succ₁ n → gcd (succ₁ m) (succ₁ n) ∣ succ₁ n {- Proof: 1. gcd Sm (Sn ∸ Sm) | (Sn ∸ Sm) IH 2 gcd Sm (Sn ∸ Sm) | Sm gcd-∣₁ 3. gcd Sm (Sn ∸ Sm) | (Sn ∸ Sm) + Sm m∣n→m∣o→m∣n+o 1,2 4. Sm ≯ Sn Hip 5. gcd (Sm ∸ Sn) Sn | Sm arith-gcd-m≤n₂ 3,4 6. gcd Sm Sn = gcd Sm (Sn ∸ Sm) gcd eq. 4 7. gcd Sm Sn | Sn subst 5,6 -} gcd-S≯S-∣₂ {m} {n} Nm Nn ih gcd-∣₁ Sm≯Sn = -- The first substitution is based on gcd m n = gcd m (n ∸ m). subst (λ x → x ∣ succ₁ n) (sym (gcd-S≯S m n Sm≯Sn)) -- The second substitution is based on -- n = (n ∸ m) + m. (subst (λ y → gcd (succ₁ m) (succ₁ n ∸ succ₁ m) ∣ y) (x≤y→y∸x+x≡y (nsucc Nm) (nsucc Nn) (x≯y→x≤y (nsucc Nm) (nsucc Nn) Sm≯Sn)) (x∣y→x∣z→x∣y+z {gcd (succ₁ m) (succ₁ n ∸ succ₁ m)} {succ₁ n ∸ succ₁ m} {succ₁ m} (gcd-N (nsucc Nm) Sn-Sm-N (λ p → ⊥-elim (S≢0 (∧-proj₁ p)))) Sn-Sm-N (nsucc Nm) ih gcd-∣₁ ) ) where Sn-Sm-N : N (succ₁ n ∸ succ₁ m) Sn-Sm-N = ∸-N (nsucc Nn) (nsucc Nm) ------------------------------------------------------------------------------ -- The gcd is CD. -- We will prove that gcdCD : ... → CD m n (gcd m n). -- The gcd 0 (succ₁ n) is CD. gcd-0S-CD : ∀ {n} → N n → CD zero (succ₁ n) (gcd zero (succ₁ n)) gcd-0S-CD Nn = (gcd-0S-∣₁ Nn , gcd-0S-∣₂ Nn) -- The gcd (succ₁ m) 0 is CD. gcd-S0-CD : ∀ {m} → N m → CD (succ₁ m) zero (gcd (succ₁ m) zero) gcd-S0-CD Nm = (gcd-S0-∣₁ Nm , gcd-S0-∣₂ Nm) -- The gcd (succ₁ m) (succ₁ n) when succ₁ m > succ₁ n is CD. gcd-S>S-CD : ∀ {m n} → N m → N n → (CD (succ₁ m ∸ succ₁ n) (succ₁ n) (gcd (succ₁ m ∸ succ₁ n) (succ₁ n))) → succ₁ m > succ₁ n → CD (succ₁ m) (succ₁ n) (gcd (succ₁ m) (succ₁ n)) gcd-S>S-CD {m} {n} Nm Nn acc Sm>Sn = (gcd-S>S-∣₁ Nm Nn acc-∣₁ acc-∣₂ Sm>Sn , gcd-S>S-∣₂ Nm Nn acc-∣₂ Sm>Sn) where acc-∣₁ : gcd (succ₁ m ∸ succ₁ n) (succ₁ n) ∣ (succ₁ m ∸ succ₁ n) acc-∣₁ = ∧-proj₁ acc acc-∣₂ : gcd (succ₁ m ∸ succ₁ n) (succ₁ n) ∣ succ₁ n acc-∣₂ = ∧-proj₂ acc -- The gcd (succ₁ m) (succ₁ n) when succ₁ m ≯ succ₁ n is CD. gcd-S≯S-CD : ∀ {m n} → N m → N n → (CD (succ₁ m) (succ₁ n ∸ succ₁ m) (gcd (succ₁ m) (succ₁ n ∸ succ₁ m))) → succ₁ m ≯ succ₁ n → CD (succ₁ m) (succ₁ n) (gcd (succ₁ m) (succ₁ n)) gcd-S≯S-CD {m} {n} Nm Nn acc Sm≯Sn = (gcd-S≯S-∣₁ Nm Nn acc-∣₁ Sm≯Sn , gcd-S≯S-∣₂ Nm Nn acc-∣₂ acc-∣₁ Sm≯Sn) where acc-∣₁ : gcd (succ₁ m) (succ₁ n ∸ succ₁ m) ∣ succ₁ m acc-∣₁ = ∧-proj₁ acc acc-∣₂ : gcd (succ₁ m) (succ₁ n ∸ succ₁ m) ∣ (succ₁ n ∸ succ₁ m) acc-∣₂ = ∧-proj₂ acc -- The gcd m n when m > n is CD. gcd-x>y-CD : ∀ {m n} → N m → N n → (∀ {o p} → N o → N p → Lexi o p m n → x≢0≢y o p → CD o p (gcd o p)) → m > n → x≢0≢y m n → CD m n (gcd m n) gcd-x>y-CD nzero Nn _ 0>n _ = ⊥-elim (0>x→⊥ Nn 0>n) gcd-x>y-CD (nsucc Nm) nzero _ _ _ = gcd-S0-CD Nm gcd-x>y-CD (nsucc {m} Nm) (nsucc {n} Nn) ah Sm>Sn _ = gcd-S>S-CD Nm Nn ih Sm>Sn where -- Inductive hypothesis. ih : CD (succ₁ m ∸ succ₁ n) (succ₁ n) (gcd (succ₁ m ∸ succ₁ n) (succ₁ n)) ih = ah {succ₁ m ∸ succ₁ n} {succ₁ n} (∸-N (nsucc Nm) (nsucc Nn)) (nsucc Nn) ([Sx∸Sy,Sy]<[Sx,Sy] Nm Nn) (λ p → ⊥-elim (S≢0 (∧-proj₂ p))) -- The gcd m n when m ≯ n is CD. gcd-x≯y-CD : ∀ {m n} → N m → N n → (∀ {o p} → N o → N p → Lexi o p m n → x≢0≢y o p → CD o p (gcd o p)) → m ≯ n → x≢0≢y m n → CD m n (gcd m n) gcd-x≯y-CD nzero nzero _ _ h = ⊥-elim (h (refl , refl)) gcd-x≯y-CD nzero (nsucc Nn) _ _ _ = gcd-0S-CD Nn gcd-x≯y-CD (nsucc _) nzero _ Sm≯0 _ = ⊥-elim (S≯0→⊥ Sm≯0) gcd-x≯y-CD (nsucc {m} Nm) (nsucc {n} Nn) ah Sm≯Sn _ = gcd-S≯S-CD Nm Nn ih Sm≯Sn where -- Inductive hypothesis. ih : CD (succ₁ m) (succ₁ n ∸ succ₁ m) (gcd (succ₁ m) (succ₁ n ∸ succ₁ m)) ih = ah {succ₁ m} {succ₁ n ∸ succ₁ m} (nsucc Nm) (∸-N (nsucc Nn) (nsucc Nm)) ([Sx,Sy∸Sx]<[Sx,Sy] Nm Nn) (λ p → ⊥-elim (S≢0 (∧-proj₁ p))) -- The gcd is CD. gcdCD : ∀ {m n} → N m → N n → x≢0≢y m n → CD m n (gcd m n) gcdCD = Lexi-wfind A h where A : D → D → Set A i j = x≢0≢y i j → CD i j (gcd i j) h : ∀ {i j} → N i → N j → (∀ {k l} → N k → N l → Lexi k l i j → A k l) → A i j h Ni Nj ah = case (gcd-x>y-CD Ni Nj ah) (gcd-x≯y-CD Ni Nj ah) (x>y∨x≯y Ni Nj)
{ "alphanum_fraction": 0.4728198732, "avg_line_length": 34.3607142857, "ext": "agda", "hexsha": "7978afc2fc6410294265010175b55dd78094c052", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/CommonDivisor.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/CommonDivisor.agda", "max_line_length": 88, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/CommonDivisor.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 4052, "size": 9621 }
module Numeral.Natural.Function.GreatestCommonDivisor.Extended where import Lvl open import Data open import Data.Tuple as Tuple using (_⨯_ ; _,_) open import Logic.Propositional open import Numeral.Integer as ℤ open import Numeral.Integer.Oper open import Numeral.Integer.Proofs hiding (_≤_) open import Numeral.Natural as ℕ open import Numeral.Natural.Function.GreatestCommonDivisor import Numeral.Natural.Oper as ℕ open import Numeral.Natural.Oper.FlooredDivision open import Numeral.Natural.Oper.Modulo open import Numeral.Natural.Relation.Order open import Numeral.Natural.Relation.Order.Classical open import Syntax.Number open import Type -- TODO: Does the same algorithm work in the naturals? https://math.stackexchange.com/questions/237372/finding-positive-b%C3%A9zout-coefficients https://math.stackexchange.com/questions/1230224/positive-solutions-of-893x-2432y-19?rq=1 gcdExt : ℕ → ℕ → (ℕ ⨯ ℤ ⨯ ℤ) gcdExt a b = gcdFold(\{a (𝐒 b) _ (succ min) _ (x , y) → (y , (x − ((+ₙ(a ⌊/⌋ ℕ.𝐒(b))) ⋅ y)))}) (\_ _ _ _ _ → Tuple.swap) (1 , 0) a b open import Logic.IntroInstances open import Logic.Predicate open import Numeral.Natural.Inductions open import Numeral.Natural.Oper.Proofs open import Numeral.Natural.Oper.DivMod.Proofs open import Numeral.Natural.Oper.Modulo.Proofs open import Numeral.Natural.Relation.Order.Proofs open import Relator.Equals open import Relator.Equals.Proofs.Equiv open import Structure.Function open import Structure.Function.Domain open import Structure.Function.Multi open import Structure.Operator open import Structure.Operator.Proofs.Util open import Structure.Operator.Properties open import Syntax.Function open import Syntax.Transitivity private variable a b d : ℕ gcd-gcdExt-equal : (gcd a b ≡ Tuple.left(gcdExt a b)) gcd-gcdExt-equal {a}{b} = Gcd-unique {a}{b} Gcd-gcd Gcd-gcdFold -- Also called: Bézout's identity, extended Euclid's algorithm. gcd-linearCombination-existence : ∃{Obj = ℤ ⨯ ℤ}(\{(x , y) → (((+ₙ a) ⋅ x) + ((+ₙ b) ⋅ y) ≡ +ₙ(gcd a b))}) gcd-linearCombination-existence {a}{b} = [ℕ]-strong-induction {φ = b ↦ ∀{a} → ∃{Obj = ℤ ⨯ ℤ}(\{(x , y) → (((+ₙ a) ⋅ x) + ((+ₙ b) ⋅ y) ≡ +ₙ(gcd a b))})} base step {b}{a} where base : ∀{a} → ∃{Obj = ℤ ⨯ ℤ}(\{(x , y) → (((+ₙ a) ⋅ x) + (0 ⋅ y) ≡ +ₙ(gcd a 0))}) ∃.witness (base {a}) = (1 , 0) ∃.proof (base {ℕ.𝟎}) = [≡]-intro ∃.proof (base {ℕ.𝐒 a}) = [≡]-intro step : ∀{i} → (∀{j} → (j ≤ i) → ∀{a} → ∃{Obj = ℤ ⨯ ℤ}(\{(x , y) → (((+ₙ a) ⋅ x) + ((+ₙ j) ⋅ y) ≡ +ₙ(gcd a j))})) → ∀{a} → ∃{Obj = ℤ ⨯ ℤ}(\{(x , y) → (((+ₙ a) ⋅ x) + ((+𝐒ₙ i) ⋅ y) ≡ +ₙ(gcd a (ℕ.𝐒(i))))}) ∃.witness (step {i} prev {a}) with [≥]-or-[<] {a}{ℕ.𝐒(i)} ... | [∨]-introₗ ia with [∃]-intro (x , y) ← prev{a mod ℕ.𝐒(i)} ([≤]-without-[𝐒] (mod-maxᵣ {a = a})) {ℕ.𝐒(i)} = (y , ((x − ((+ₙ(a ⌊/⌋ ℕ.𝐒(i))) ⋅ y)))) ... | [∨]-introᵣ (succ ai) with [∃]-intro (x , y) ← prev{a} ai {ℕ.𝐒(i)} = (y , x) ∃.proof (step {i} prev {a}) with [≥]-or-[<] {a}{ℕ.𝐒(i)} ... | [∨]-introₗ ia with [∃]-intro (x , y) ⦃ p ⦄ ← prev{a mod ℕ.𝐒(i)} ([≤]-without-[𝐒] (mod-maxᵣ {a = a})) {ℕ.𝐒(i)} = ((+ₙ a) ⋅ y) + ((+𝐒ₙ i) ⋅ (x − ((+ₙ(a ⌊/⌋ ℕ.𝐒(i))) ⋅ y))) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)((+ₙ a) ⋅ y) (distributivityₗ(_⋅_)(_−_) {+𝐒ₙ i}{x}{(+ₙ(a ⌊/⌋ ℕ.𝐒(i))) ⋅ y}) ] ((+ₙ a) ⋅ y) + (((+𝐒ₙ i) ⋅ x) − ((+𝐒ₙ i) ⋅ ((+ₙ(a ⌊/⌋ ℕ.𝐒(i))) ⋅ y))) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)((+ₙ a) ⋅ y) (congruence₂ᵣ(_−_)((+𝐒ₙ i) ⋅ x) p1) ] ((+ₙ a) ⋅ y) + (((+𝐒ₙ i) ⋅ x) − ((+ₙ(a ℕ.−₀ (a mod ℕ.𝐒(i)))) ⋅ y)) 🝖[ _≡_ ]-[ One.commuteₗ-assocᵣ{a = (+ₙ a) ⋅ y}{b = (+𝐒ₙ i) ⋅ x} ] ((+𝐒ₙ i) ⋅ x) + (((+ₙ a) ⋅ y) − ((+ₙ(a ℕ.−₀ (a mod ℕ.𝐒(i)))) ⋅ y)) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)((+𝐒ₙ i) ⋅ x) (distributivityᵣ(_⋅_)(_−_) {+ₙ a}{_}{y}) ]-sym ((+𝐒ₙ i) ⋅ x) + (((+ₙ a) − (+ₙ(a ℕ.−₀ (a mod ℕ.𝐒(i))))) ⋅ y) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)((+𝐒ₙ i) ⋅ x) (congruence₂ₗ(_⋅_)(y) p2) ] ((+𝐒ₙ i) ⋅ x) + ((+ₙ(a mod ℕ.𝐒(i))) ⋅ y) 🝖[ _≡_ ]-[ p ] +ₙ(gcd (ℕ.𝐒(i)) (a mod ℕ.𝐒(i))) 🝖-end where p0 = (ℕ.𝐒 i) ℕ.⋅ (a ⌊/⌋ ℕ.𝐒(i)) 🝖[ _≡_ ]-[ commutativity(ℕ._⋅_) {ℕ.𝐒 i}{a ⌊/⌋ ℕ.𝐒(i)} ] (a ⌊/⌋ ℕ.𝐒(i)) ℕ.⋅ (ℕ.𝐒 i) 🝖[ _≡_ ]-[ OneTypeTwoOp.moveᵣ-to-invOp {b = a mod ℕ.𝐒(i)}{c = a} (([⌊/⌋][mod]-is-division-with-remainder {y = i})) ] a ℕ.−₀ (a mod ℕ.𝐒(i)) 🝖-end p1 = (+𝐒ₙ i) ⋅ ((+ₙ(a ⌊/⌋ ℕ.𝐒(i))) ⋅ y) 🝖[ _≡_ ]-[ associativity(_⋅_) {+𝐒ₙ i} ]-sym ((+𝐒ₙ i) ⋅ (+ₙ(a ⌊/⌋ ℕ.𝐒(i)))) ⋅ y 🝖[ _≡_ ]-[] ((+ₙ(ℕ.𝐒 i)) ⋅ (+ₙ(a ⌊/⌋ ℕ.𝐒(i)))) ⋅ y 🝖[ _≡_ ]-[ congruence₂ₗ(_⋅_)(y) (preserving₂(+ₙ_)(ℕ._⋅_)(_⋅_) {ℕ.𝐒 i}) ]-sym (+ₙ((ℕ.𝐒 i) ℕ.⋅ (a ⌊/⌋ ℕ.𝐒(i)))) ⋅ y 🝖[ _≡_ ]-[ congruence₂ₗ(_⋅_)(y) (congruence₁(+ₙ_) p0) ] (+ₙ(a ℕ.−₀ (a mod ℕ.𝐒(i)))) ⋅ y 🝖-end p2 = (+ₙ a) − (+ₙ(a ℕ.−₀ (a mod ℕ.𝐒(i)))) 🝖[ _≡_ ]-[ congruence₂ᵣ(_−_)(+ₙ a) ([+ₙ][−₀][−]-preserving (mod-maxₗ {a}{ℕ.𝐒(i)})) ] (+ₙ a) − ((+ₙ a) − (+ₙ(a mod ℕ.𝐒(i)))) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(+ₙ a) (preserving₂(−_)(_+_)(_+_) {+ₙ a}{−(+ₙ(a mod ℕ.𝐒(i)))}) ] (+ₙ a) + ((−(+ₙ a)) − (−(+ₙ(a mod ℕ.𝐒(i))))) 🝖[ _≡_ ]-[ associativity(_+_) {+ₙ a}{−(+ₙ a)} ]-sym ((+ₙ a) − (+ₙ a)) − (−(+ₙ(a mod ℕ.𝐒(i)))) 🝖[ _≡_ ]-[ congruence₂(_+_) (inverseFunctionᵣ(_+_)(−_) {+ₙ a}) (involution(−_)) ] 0 + (+ₙ(a mod ℕ.𝐒(i))) 🝖[ _≡_ ]-[ identityₗ(_+_)(0) ] +ₙ(a mod ℕ.𝐒(i)) 🝖[ _≡_ ]-end ... | [∨]-introᵣ (succ ai) with [∃]-intro (x , y) ⦃ p ⦄ ← prev{a} ai {ℕ.𝐒(i)} = commutativity(_+_) {(+ₙ a) ⋅ y}{(+ₙ ℕ.𝐒(i)) ⋅ x} 🝖 p
{ "alphanum_fraction": 0.5085110195, "avg_line_length": 62.7078651685, "ext": "agda", "hexsha": "674853f8ed8f08e05e7de36ad6ef278e447ad112", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Numeral/Natural/Function/GreatestCommonDivisor/Extended.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Numeral/Natural/Function/GreatestCommonDivisor/Extended.agda", "max_line_length": 234, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Numeral/Natural/Function/GreatestCommonDivisor/Extended.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 2881, "size": 5581 }
module Issue2229Reexport2 where open import Issue2229Base public
{ "alphanum_fraction": 0.8787878788, "avg_line_length": 16.5, "ext": "agda", "hexsha": "be355d841f54d5e4f5597e6d14a9a8d9956b21a4", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue2229Reexport2.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue2229Reexport2.agda", "max_line_length": 32, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue2229Reexport2.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 17, "size": 66 }
module View where open import Data.Unit open import Data.Char open import Data.Maybe open import Data.Container.Indexed open import Signature open import Model open import IO.Primitive ------------------------------------------------------------------------ postulate view : Model → IO ⊤ data VtyEvent : Set where key : Char → VtyEvent enter : VtyEvent vtyToCmd : VtyEvent → (m : Mode) → Maybe (Command Hårss m) vtyToCmd (key 'j') cmd = just (moveP down) vtyToCmd (key 'k') cmd = just (moveP up) vtyToCmd (key 'a') cmd = just (promptP addFeed) vtyToCmd (key '\t') cmd = just (promptP search) vtyToCmd (key 'R') cmd = just fetchP vtyToCmd _ cmd = nothing vtyToCmd enter (input p) = just doneP vtyToCmd (key '\t') (input search) = just searchNextP vtyToCmd (key c) (input p) = just (putCharP c)
{ "alphanum_fraction": 0.5774336283, "avg_line_length": 29.1612903226, "ext": "agda", "hexsha": "67447d0b5ba84f098fb7895641ae05d40e35f9f2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f767dbfbd82ce667b7cea667c4da76fe97f761eb", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "stevana/haarss", "max_forks_repo_path": "prototype/command-response/View.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f767dbfbd82ce667b7cea667c4da76fe97f761eb", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "stevana/haarss", "max_issues_repo_path": "prototype/command-response/View.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "f767dbfbd82ce667b7cea667c4da76fe97f761eb", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "stevana/haarss", "max_stars_repo_path": "prototype/command-response/View.agda", "max_stars_repo_stars_event_max_datetime": "2015-07-30T11:43:26.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-30T11:43:26.000Z", "num_tokens": 263, "size": 904 }
{- Basic combinators, basic permutations, and their relation -} module CombPerm where import Data.Fin as F -- open import Data.Unit open import Data.Nat using (ℕ ; zero ; suc ; _+_ ; _>_ ) open import Data.Sum using (inj₁ ; inj₂ ; _⊎_) open import Data.Vec open import Function using ( id ) renaming (_∘_ to _○_) open import Relation.Binary -- to make certain goals look nicer open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ; sym ; cong ; trans ; subst ; module ≡-Reasoning ) open ≡-Reasoning -- start re-splitting things up, as this is getting out of hand open import FT -- Finite Types open import VecHelpers open import NatSimple open import Eval open import Permutations -- This should really go elsewhere! finToVal : {n : ℕ} → F.Fin n → ⟦ fromℕ n ⟧ finToVal F.zero = inj₁ tt finToVal (F.suc n) = inj₂ (finToVal n) valToFin : {n : ℕ} → ⟦ fromℕ n ⟧ → F.Fin n valToFin {zero} () valToFin {suc n} (inj₁ tt) = F.zero valToFin {suc n} (inj₂ v) = F.suc (valToFin v) finToValToFin : {n : ℕ} → (v : ⟦ fromℕ n ⟧) → finToVal (valToFin v) ≡ v finToValToFin {zero} () finToValToFin {suc n} (inj₁ tt) = refl -- (inj₁ tt) finToValToFin {suc n} (inj₂ v) = cong inj₂ (finToValToFin v) valToFinToVal : {n : ℕ} → (i : F.Fin n) → valToFin (finToVal i) ≡ i valToFinToVal F.zero = refl -- F.zero valToFinToVal (F.suc i) = cong F.suc (valToFinToVal i) -- construct a combinator which represents the swapping of the i-th and -- (i+1)-th 'bit' of a finite type. -- Best to think of this as an 'elementary permutation', in the same way -- we have 'elementary matrices' (which turn out to be permutations when they -- are unitary). swapi : {n : ℕ} → F.Fin n → (fromℕ (suc n)) ⇛ (fromℕ (suc n)) swapi {zero} () swapi {suc n} F.zero = assocl₊⇛ ◎ (swap₊⇛ ⊕ id⇛) ◎ assocr₊⇛ swapi {suc n} (F.suc i) = id⇛ ⊕ swapi {n} i swapiPerm : {n : ℕ} → F.Fin n → Permutation (suc n) swapiPerm {zero} () swapiPerm {suc n} F.zero = F.suc F.zero ∷ idP swapiPerm {suc n} (F.suc i) = F.zero ∷ swapiPerm {n} i swapiAct : {n : ℕ} {A : Set} → (i : F.Fin n) → (v : Vec A (suc n)) → permute (swapiPerm i) v ≡ insert (remove (F.inject₁ i) v) (F.suc i) (v !! (F.inject₁ i)) swapiAct {zero} () v swapiAct {suc n} F.zero (x ∷ y ∷ v) = cong (λ z → y ∷ x ∷ z) (idP-id v) swapiAct {suc n} (F.suc i) (x ∷ v) = cong (_∷_ x) (swapiAct i v) -- swapUpTo i permutes the combinator left by one up to i -- if possible values are X a b c Y d e, swapUpTo 3's possible outputs -- are a b c X Y d e swapUpTo : {n : ℕ} → F.Fin n → (fromℕ (suc n)) ⇛ (fromℕ (suc n)) swapUpTo F.zero = id⇛ swapUpTo (F.suc i) = (id⇛ ⊕ swapUpTo i) ◎ swapi F.zero -- 1 i times, 0 for the rest 1iP : {n : ℕ} → F.Fin n → Permutation (suc n) 1iP F.zero = idP 1iP (F.suc i) = (F.suc F.zero) ∷ 1iP i -- The permutation we need: -- [i, 0, 0, 0, 0, ...] swapUpToPerm : {n : ℕ} → F.Fin n → Permutation (suc n) swapUpToPerm F.zero = idP swapUpToPerm (F.suc j) = (F.inject₁ (F.suc j)) ∷ idP -- swapDownFrom i permutes the combinator right by one up to i (the reverse -- of swapUpTo) swapDownFrom : {n : ℕ} → F.Fin n → (fromℕ (suc n)) ⇛ (fromℕ (suc n)) swapDownFrom F.zero = id⇛ swapDownFrom (F.suc i) = swapi F.zero ◎ (id⇛ ⊕ swapDownFrom i) -- The permutation we need: -- [1, 1, 1, ..., 1, 0, 0, 0, ...] -- |--i-1 times---| swapDownFromPerm : {n : ℕ} → F.Fin n → Permutation (suc n) swapDownFromPerm = 1iP -- swapDownFromPerm F.zero = idP -- swapDownFromPerm (F.suc i) = (F.suc F.zero) ∷ swapDownFromPerm i -- swapm i returns a combinator that swaps 0 and i swapm : {n : ℕ} → F.Fin n → (fromℕ n) ⇛ (fromℕ n) swapm F.zero = id⇛ swapm (F.suc i) = swapDownFrom i ◎ swapi i ◎ swapUpTo i swapOne : {n : ℕ} → (i : F.Fin n) → Permutation n swapOne F.zero = idP swapOne {suc zero} (F.suc ()) swapOne {suc (suc n)} (F.suc i) = (F.suc F.zero) ∷ swapOne i -- which should correspond to this permutation!! swapmPerm : {n : ℕ} → F.Fin n → Permutation n swapmPerm F.zero = idP swapmPerm {suc n} (F.suc i) = F.suc i ∷ swapOne i permToComb : {n : ℕ} → Permutation n → (fromℕ n ⇛ fromℕ n) permToComb [] = id⇛ permToComb (F.zero ∷ p) = id⇛ ⊕ permToComb p permToComb (F.suc n ∷ p) = swapm (F.suc n) ◎ (id⇛ ⊕ permToComb p) swap01 : (n : ℕ) → Permutation n swap01 zero = [] swap01 (suc zero) = F.zero ∷ [] swap01 (suc (suc n)) = F.suc (F.zero) ∷ idP vmap-insert : {n : ℕ} {A B : Set} {x : A} → (v : Vec A n) → (f : A → B) → (i : F.Fin (suc n)) → vmap f (insert v i x) ≡ insert (vmap f v) i (f x) vmap-insert {zero} [] f F.zero = refl vmap-insert {zero} [] f (F.suc ()) vmap-insert {suc n} v f F.zero = refl vmap-insert {suc n} {x = x} (y ∷ v) f (F.suc i) = cong (_∷_ (f y)) (vmap-insert v f i) vmap-permute : {n : ℕ} {A B : Set} → (p : Permutation n) → (v : Vec A n) → (f : A → B) → vmap f (permute p v) ≡ permute p (vmap f v) vmap-permute {zero} [] [] f = refl vmap-permute {suc n} (i ∷ p) (x ∷ v) f = trans (vmap-insert (permute p v) f i) (cong (λ y → insert y i (f x)) (vmap-permute p v f)) evalPerm : {n : ℕ} → Permutation n → F.Fin n → F.Fin n evalPerm {zero} _ () evalPerm {suc n} p k = lookup k (permute p (allFin (suc n))) testP5 : Vec (F.Fin five) five testP5 = permute (swapmPerm (F.inject (F.fromℕ three))) (allFin five) push-f-through : {n : ℕ} {A B : Set} → (f : A → B) → (j : F.Fin n) → (p : Permutation n) → (g : F.Fin n → A) → f (lookup j (permute p (tabulate g))) ≡ lookup j (permute p (tabulate (f ○ g))) push-f-through {zero} f () p g push-f-through {suc n} f j p g = begin f (lookup j (permute p (tabulate g))) ≡⟨ sym (map!! f (permute p (tabulate g)) j) ⟩ lookup j (vmap f (permute p (tabulate g))) ≡⟨ cong (lookup j) (vmap-permute p (tabulate g) f) ⟩ lookup j (permute p (vmap f (tabulate g))) ≡⟨ cong (λ x → lookup j (permute p x)) (mapTab f g) ⟩ lookup j (permute p (tabulate (f ○ g))) ∎ -- Just to make a lot of the proofs look nicer vId : {n : ℕ} → Vec (F.Fin n) n vId = tabulate id vS : {n : ℕ} → Vec (F.Fin (suc n)) n vS = tabulate F.suc vSS : {n : ℕ} → Vec (F.Fin (suc (suc n))) n vSS = tabulate (F.suc ○ F.suc) swapiCorrect : {n : ℕ} → (i : F.Fin n) → (j : F.Fin (1 + n)) → evalComb (swapi i) (finToVal j) ≡ finToVal (evalPerm (swapiPerm i) j) swapiCorrect {zero} () _ swapiCorrect {suc n} F.zero F.zero = refl swapiCorrect {suc zero} F.zero (F.suc F.zero) = refl swapiCorrect {suc zero} F.zero (F.suc (F.suc ())) swapiCorrect {suc zero} (F.suc ()) j swapiCorrect {suc (suc n)} (F.suc i) F.zero = refl swapiCorrect {suc (suc n)} F.zero (F.suc F.zero) = refl swapiCorrect {suc (suc n)} F.zero (F.suc (F.suc j)) = cong finToVal let F2 = F.suc ○ F.suc in begin F2 j ≡⟨ cong F2 (sym (lookupTab {f = id} j)) ⟩ F2 (lookup j (tabulate id)) ≡⟨ cong (λ x → F2 (lookup j x)) (sym (idP-id (tabulate id))) ⟩ F2 (lookup j (permute idP (tabulate id))) ≡⟨ push-f-through F2 j idP id ⟩ lookup j (permute idP (tabulate F2)) ∎ swapiCorrect {suc (suc n)} (F.suc i) (F.suc j) = begin evalComb (swapi (F.suc i)) (finToVal (F.suc j)) ≡⟨ refl ⟩ inj₂ (evalComb (swapi i) (finToVal j)) ≡⟨ cong inj₂ (swapiCorrect {suc n} i j) ⟩ inj₂ (finToVal (evalPerm (swapiPerm i) j)) ≡⟨ refl ⟩ inj₂ (finToVal (lookup j (permute (swapiPerm i) (tabulate id)))) ≡⟨ refl ⟩ finToVal (F.suc (lookup j (permute (swapiPerm i) (tabulate id)))) ≡⟨ cong finToVal (push-f-through F.suc j (swapiPerm i) id) ⟩ finToVal (lookup j (permute (swapiPerm i) (tabulate F.suc))) ∎ -- JC: Need seriously better names for the next 3 lemmas!! lookup-insert : {n : ℕ} {A : Set} → (v : Vec A (suc n)) → {i : F.Fin (suc n)} → {a : A} → lookup F.zero (insert v (F.suc i) a) ≡ lookup F.zero v lookup-insert (x ∷ v) = refl lookup-insert′ : {n : ℕ} {A : Set} (i : F.Fin (suc n)) {a : A} → (v : Vec A n) → lookup i (insert v i a) ≡ a lookup-insert′ F.zero [] = refl lookup-insert′ (F.suc ()) [] lookup-insert′ F.zero (x ∷ v) = refl lookup-insert′ (F.suc i) (x ∷ v) = lookup-insert′ i v -- this is what is needed in swapDownCorrect, but would be true for any j < i instead of F.suc F.zero < F.suc i lookup-insert′′ : {n : ℕ} {A : Set} {a : A} → (i : F.Fin n) → (v : Vec A (suc n)) → lookup (F.suc i) v ≡ lookup (F.suc (F.suc i)) (insert v (F.suc F.zero) a) lookup-insert′′ {zero} () v lookup-insert′′ {suc n} i (x ∷ v) = refl -- this should be unified with the previous lookup-insert3 : {n : ℕ} {A : Set} {a : A} → (i : F.Fin n) → (v : Vec A n) → lookup i v ≡ lookup (F.suc i) (insert v (F.inject₁ i) a) lookup-insert3 {zero} () v lookup-insert3 {suc n} F.zero (x ∷ v) = refl lookup-insert3 {suc n} (F.suc i) (x ∷ v) = lookup-insert3 i v lookup+1-insert-remove : {n : ℕ} {A : Set} {a : A} → (i : F.Fin n) → (v : Vec A (suc n)) → lookup (F.inject₁ i) (insert (remove (F.inject₁ i) v) (F.suc i) a) ≡ lookup (F.suc i) v lookup+1-insert-remove {zero} () _ lookup+1-insert-remove {suc n} F.zero (x ∷ x₁ ∷ v) = refl lookup+1-insert-remove {suc n} (F.suc i) (x ∷ v) = lookup+1-insert-remove i v -- insert (remove (F.inject₁ (F.suc i)) (tabulate id)) (F.suc (F.suc i)) (F.inject₁ (F.suc i)) !! (F.inject₁ (F.suc i)) lookup-idP-id : {n : ℕ} → (i : F.Fin n) → lookup i (permute idP vId) ≡ i lookup-idP-id i = trans (cong (lookup i) (idP-id vId)) (lookupTab i) swapUpToAct : {n : ℕ} {A : Set} → (i : F.Fin n) → (v : Vec A (suc n)) → permute (swapUpToPerm i) v ≡ insert (remove F.zero v) (F.inject₁ i) (v !! F.zero) swapUpToAct F.zero v = trans (idP-id v) (remove0 v) swapUpToAct (F.suc i) (x ∷ v) = cong (λ z → insert z (F.suc (F.inject₁ i)) x) (idP-id v) swapDownFromVec : {n : ℕ} {A : Set} → (i : F.Fin (suc n)) → Vec A (suc n) → Vec A (suc n) swapDownFromVec i v = (v !! i) ∷ remove i v swapDownFromAct : {n : ℕ} → {A : Set} → (i : F.Fin n) → (v : Vec A (suc n)) → permute (swapDownFromPerm i) v ≡ swapDownFromVec (F.inject₁ i) v swapDownFromAct {zero} () _ swapDownFromAct {suc n} F.zero (x ∷ v) = begin permute (swapDownFromPerm F.zero) (x ∷ v) ≡⟨ refl ⟩ permute idP (x ∷ v) ≡⟨ idP-id (x ∷ v) ⟩ swapDownFromVec F.zero (x ∷ v) ∎ swapDownFromAct {suc zero} (F.suc ()) _ swapDownFromAct {suc (suc n)} (F.suc i) (x ∷ y ∷ v) = begin permute (swapDownFromPerm (F.suc i)) (x ∷ y ∷ v) ≡⟨ refl ⟩ permute (F.suc F.zero ∷ 1iP i) (x ∷ y ∷ v) ≡⟨ refl ⟩ insert (permute (swapDownFromPerm i) (y ∷ v)) (F.suc F.zero) x ≡⟨ cong (λ q → insert q (F.suc F.zero) x) (swapDownFromAct i (y ∷ v)) ⟩ insert (swapDownFromVec (F.inject₁ i) (y ∷ v)) (F.suc F.zero) x ≡⟨ refl ⟩ ((y ∷ v) !! (F.inject₁ i)) ∷ x ∷ remove (F.inject₁ i) (y ∷ v) ≡⟨ refl ⟩ swapDownFromVec (F.inject₁ (F.suc i)) (x ∷ y ∷ v) ∎ swapmVec : {n : ℕ} {A : Set} → F.Fin n → Vec A n → Vec A n swapmVec {zero} () _ swapmVec {suc n} F.zero v = v swapmVec {suc zero} (F.suc ()) _ swapmVec {suc (suc n)} (F.suc i) (x ∷ v) = (v !! i) ∷ (insert (remove i v) i x) swapOneVec : {n : ℕ} {A : Set} → F.Fin n → Vec A n → Vec A n swapOneVec {zero} () _ swapOneVec {suc n} F.zero v = v swapOneVec {suc n} (F.suc i) v = (v !! (F.suc i)) ∷ (remove (F.suc i) v) swapOneAct : {n : ℕ} {A : Set} → (i : F.Fin n) → (v : Vec A n) → permute (swapOne i) v ≡ swapOneVec i v swapOneAct {zero} () _ swapOneAct {suc n} F.zero (x ∷ v) = cong (_∷_ x) (idP-id v) swapOneAct {suc zero} (F.suc ()) v swapOneAct {suc (suc n)} (F.suc F.zero) (x ∷ y ∷ v) = cong (λ z → y ∷ x ∷ z) (idP-id v) swapOneAct {suc (suc n)} (F.suc (F.suc i)) (x ∷ v) = begin permute (swapOne (F.suc (F.suc i))) (x ∷ v) ≡⟨ refl ⟩ insert (permute (swapOne (F.suc i)) v) (F.suc F.zero) x ≡⟨ cong (λ y → insert y (F.suc F.zero) x) (swapOneAct (F.suc i) v) ⟩ insert (swapOneVec (F.suc i) v) (F.suc F.zero) x ≡⟨ refl ⟩ -- lots of β reduction ((x ∷ v) !! (F.suc (F.suc i))) ∷ (remove (F.suc (F.suc i)) (x ∷ v)) ≡⟨ refl ⟩ swapOneVec (F.suc (F.suc i)) (x ∷ v) ∎ swapmAct : {n : ℕ} {A : Set} → (i : F.Fin n) → (v : Vec A n) → permute (swapmPerm i) v ≡ swapmVec i v swapmAct {zero} () _ swapmAct {suc n} F.zero (x ∷ v) = begin permute (swapmPerm F.zero) (x ∷ v) ≡⟨ idP-id (x ∷ v) ⟩ swapmVec F.zero (x ∷ v) ∎ swapmAct {suc zero} (F.suc ()) _ swapmAct {suc (suc n)} (F.suc F.zero) (x ∷ y ∷ v) = cong (λ z → y ∷ x ∷ z) (idP-id v) swapmAct {suc (suc n)} (F.suc (F.suc i)) (x ∷ y ∷ v) = begin permute (swapmPerm (F.suc (F.suc i))) (x ∷ y ∷ v) ≡⟨ refl ⟩ permute (F.suc (F.suc i) ∷ swapOne (F.suc i)) (x ∷ y ∷ v) ≡⟨ refl ⟩ insert (permute (swapOne (F.suc i)) (y ∷ v)) (F.suc (F.suc i)) x ≡⟨ cong (λ z → insert z (F.suc (F.suc i)) x) (swapOneAct (F.suc i) (y ∷ v)) ⟩ insert (swapOneVec (F.suc i) (y ∷ v)) (F.suc (F.suc i)) x ≡⟨ refl ⟩ -- by lots of beta on both sides ((y ∷ v) !! (F.suc i)) ∷ (insert (remove (F.suc i) (y ∷ v)) (F.suc i) x) ≡⟨ refl ⟩ swapmVec (F.suc (F.suc i)) (x ∷ y ∷ v) ∎ swapi≡swap01 : {n : ℕ} → (j : F.Fin (suc (suc n))) → evalComb (assocl₊⇛ ◎ (swap₊⇛ ⊕ id⇛) ◎ assocr₊⇛) (finToVal j) ≡ finToVal (evalPerm (swap01 (suc (suc n))) j) swapi≡swap01 F.zero = refl swapi≡swap01 (F.suc F.zero) = refl swapi≡swap01 (F.suc (F.suc j)) = sym (trans (cong (λ x → finToVal (x !! j)) (idP-id _)) (cong finToVal (lookupTab j))) -- this is the raw swap01 vector swap01vec : {n : ℕ} → Vec (F.Fin (2 + n)) (2 + n) swap01vec = F.suc F.zero ∷ F.zero ∷ vSS -- this is the one we 'naturally' get via permutation swap01vec′ : (n : ℕ) → Vec (F.Fin (2 + n)) (2 + n) swap01vec′ n = permute (swap01 (suc (suc n))) vId -- but they are the same! swap01Correct : (n : ℕ) → swap01vec′ n ≡ swap01vec {n} swap01Correct zero = refl swap01Correct (suc n) = cong (λ x → F.suc F.zero ∷ F.zero ∷ x) (idP-id _) newlemma6 : {m n : ℕ} → (i : F.Fin n) → (v : Vec (F.Fin m) n) → (vmap F.suc (insert (vmap F.suc v) (F.inject₁ i) F.zero)) ∘̬′ swap01vec ≡ insert (vmap F.suc (vmap F.suc v)) (F.inject₁ i) F.zero newlemma6 F.zero (x ∷ v) = let suc2v = vmap F.suc (vmap F.suc v) in begin vmap F.suc (insert (vmap F.suc (x ∷ v)) F.zero F.zero) ∘̬′ swap01vec ≡⟨ refl ⟩ (F.suc F.zero ∷ F.suc (F.suc x) ∷ suc2v) ∘̬′ swap01vec ≡⟨ refl ⟩ F.zero ∷ ((F.suc (F.suc x) ∷ suc2v) ∘̬′ swap01vec) ≡⟨ refl ⟩ F.zero ∷ (vSS !! x) ∷ (suc2v ∘̬′ swap01vec) ≡⟨ cong (λ x → F.zero ∷ x ∷ suc2v ∘̬′ swap01vec) (lookupTab x) ⟩ F.zero ∷ F.suc (F.suc x) ∷ (suc2v ∘̬′ swap01vec) ≡⟨ cong (λ q → F.zero ∷ F.suc (F.suc x) ∷ q) (map2+id v) ⟩ F.zero ∷ F.suc (F.suc x) ∷ suc2v ≡⟨ refl ⟩ insert (vmap F.suc (vmap F.suc (x ∷ v))) F.zero F.zero ∎ newlemma6 (F.suc i) (x ∷ v) = let v′ = insert (vmap F.suc v) (F.inject₁ i) F.zero in begin vmap F.suc (insert (vmap F.suc (x ∷ v)) (F.inject₁ (F.suc i)) F.zero) ∘̬′ swap01vec ≡⟨ refl ⟩ (tabulate (F.suc ○ F.suc) !! x) ∷ ((vmap F.suc v′) ∘̬′ swap01vec) ≡⟨ cong (λ q → q ∷ ((vmap F.suc v′) ∘̬′ swap01vec)) (lookupTab x) ⟩ F.suc (F.suc x) ∷ ((vmap F.suc v′) ∘̬′ swap01vec) ≡⟨ cong (_∷_ (F.suc (F.suc x))) (newlemma6 i v) ⟩ F.suc (F.suc x) ∷ insert (vmap F.suc (vmap F.suc v)) (F.inject₁ i) F.zero ≡⟨ refl ⟩ insert (vmap F.suc (vmap F.suc (x ∷ v))) (F.inject₁ (F.suc i)) F.zero ∎ --- --- testing tests01 : Vec (F.Fin five) five tests01 = permute (swap01 five) (allFin five) tests02 : (fromℕ five ⇛ fromℕ five) tests02 = permToComb (swap01 five) tests03 : Vec ⟦ PLUS ONE (PLUS ONE (PLUS ONE (PLUS ONE (PLUS ONE ZERO)))) ⟧ five tests03 = tabulate (λ i → evalComb tests02 (finToVal i)) l6test1 : _ l6test1 = (vmap F.suc (insert (tabulate {4} F.suc) (F.suc (F.suc F.zero)) F.zero)) ∘̬ (F.suc F.zero ∷ F.zero ∷ tabulate (F.suc ○ F.suc)) l6test1b : _ l6test1b = permute (swapUpToPerm {5} (F.suc (F.suc (F.suc F.zero)))) (tabulate id) test1a : Vec _ 5 -- Vec (F.Fin 5) 5 --test1a = (insert (tabulate {4} F.suc) (F.suc F.zero) F.zero) test1a = (vmap F.suc (insert (tabulate {4} F.suc) (F.suc F.zero) F.zero)) ∘̬ (F.suc F.zero ∷ F.zero ∷ tabulate (λ x → F.suc (F.suc x))) test1b : Vec _ 5 test1b = insert (tabulate (F.suc ○ F.suc)) (F.suc F.zero) F.zero aPerm : Permutation six aPerm = (F.suc (F.suc (F.suc F.zero))) ∷ (F.suc F.zero) ∷ (F.suc F.zero) ∷ F.zero ∷ F.zero ∷ F.zero ∷ [] test5 : Vec (F.Fin six) six test5 = permute aPerm (tabulate id) combToVec : {n : ℕ} → (fromℕ n) ⇛ (fromℕ n) → Vec (F.Fin n) n combToVec c = tabulate (valToFin ○ (evalComb c) ○ finToVal) test6a : Vec (F.Fin six) six test6a = combToVec (swapUpTo (F.suc F.zero)) test6b : Vec (F.Fin six) six test6b = permute (swapUpToPerm (F.suc F.zero)) (tabulate id) test7a : Vec (F.Fin six) six test7a = combToVec (swapUpTo (F.zero)) test7b : Vec (F.Fin six) six test7b = permute (swapUpToPerm (F.zero)) (tabulate id) test8a : Vec (F.Fin six) six test8a = combToVec (swapUpTo (F.suc (F.suc (F.suc (F.zero))))) test8b : Vec (F.Fin six) six test8b = permute (swapUpToPerm (F.suc (F.suc (F.suc F.zero)))) (tabulate id) test9 : Vec (F.Fin six) six test9 = permute (swapOne (F.suc (F.suc (F.suc F.zero)))) (tabulate id) test10 : Vec (F.Fin six) six test10 = permute (swapmPerm (F.suc (F.suc (F.suc F.zero)))) (tabulate id)
{ "alphanum_fraction": 0.5744263807, "avg_line_length": 40.9103773585, "ext": "agda", "hexsha": "66cc953afea740c453443b281a2f71709ea24ff7", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "Univalence/OldUnivalence/CombPerm.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "Univalence/OldUnivalence/CombPerm.agda", "max_line_length": 190, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "Univalence/OldUnivalence/CombPerm.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 7427, "size": 17346 }
{-# OPTIONS --cubical --safe #-} module Container.List.Isomorphism where open import Prelude open import Container open import Container.List open import Data.Fin open import Data.List using (tabulate; length ; _!_) renaming (_∷_ to _L∷_; [] to L[]; List to 𝕃) open import Data.List.Properties ℒ→𝕃 : List A → 𝕃 A ℒ→𝕃 = uncurry tabulate 𝕃→ℒ : 𝕃 A → List A 𝕃→ℒ xs .fst = length xs 𝕃→ℒ xs .snd i = xs ! i ℒ→𝕃→ℒ : ∀ n (xs : Fin n → A) → 𝕃→ℒ (ℒ→𝕃 (n , xs)) ≡ (n , xs) ℒ→𝕃→ℒ n xs i .fst = tab-length n xs i ℒ→𝕃→ℒ n xs i .snd = tab-id n xs i 𝕃→ℒ→𝕃 : ∀ (xs : 𝕃 A) → ℒ→𝕃 (𝕃→ℒ xs) ≡ xs 𝕃→ℒ→𝕃 L[] _ = L[] 𝕃→ℒ→𝕃 (x L∷ xs) i = x L∷ 𝕃→ℒ→𝕃 xs i 𝕃⇔ℒ : 𝕃 A ⇔ List A 𝕃⇔ℒ .fun = 𝕃→ℒ 𝕃⇔ℒ .inv = ℒ→𝕃 𝕃⇔ℒ .rightInv = uncurry ℒ→𝕃→ℒ 𝕃⇔ℒ .leftInv = 𝕃→ℒ→𝕃
{ "alphanum_fraction": 0.5921409214, "avg_line_length": 23.0625, "ext": "agda", "hexsha": "f80465d8c15bce0d4c6f08051b703e5a411284b1", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/Container/List/Isomorphism.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_path": "agda/Container/List/Isomorphism.agda", "max_line_length": 97, "max_stars_count": 6, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/Container/List/Isomorphism.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 432, "size": 738 }
-- Andreas, 2018-07-21, issue #3161 -- Insert space before brace if preceeded by `-`. -- (Symmetric case was already fixed in #269). data Pol : Set where + - : Pol f : {x : Pol} → Set f {x} = {!x!} -- Split on x here
{ "alphanum_fraction": 0.5990990991, "avg_line_length": 22.2, "ext": "agda", "hexsha": "7cddaf75e4e9b84a95b171918939bbfa26b5ea6c", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/interaction/Issue3161.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/interaction/Issue3161.agda", "max_line_length": 49, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/interaction/Issue3161.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 77, "size": 222 }
{-# OPTIONS --safe #-} module Cubical.Relation.Nullary.DecidablePropositions where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv renaming (_∙ₑ_ to _⋆_) open import Cubical.Data.Bool open import Cubical.Data.Sigma open import Cubical.Relation.Nullary.Base open import Cubical.Relation.Nullary.Properties private variable ℓ ℓ' : Level DecProp : (ℓ : Level) → Type (ℓ-suc ℓ) DecProp ℓ = Σ[ P ∈ hProp ℓ ] Dec (P .fst) isSetDecProp : isSet (DecProp ℓ) isSetDecProp = isOfHLevelΣ 2 isSetHProp (λ P → isProp→isSet (isPropDec (P .snd))) -- the following is an alternative formulation of decidable propositions -- it separates the boolean value from more proof-relevant part -- so it performs better when doing computation isDecProp : Type ℓ → Type ℓ isDecProp P = Σ[ t ∈ Bool ] P ≃ Bool→Type t DecProp' : (ℓ : Level) → Type (ℓ-suc ℓ) DecProp' ℓ = Σ[ P ∈ Type ℓ ] isDecProp P -- properties of the alternative formulation isDecProp→isProp : {P : Type ℓ} → isDecProp P → isProp P isDecProp→isProp h = isOfHLevelRespectEquiv 1 (invEquiv (h .snd)) isPropBool→Type isDecProp→Dec : {P : Type ℓ} → isDecProp P → Dec P isDecProp→Dec h = EquivPresDec (invEquiv (h .snd)) DecBool→Type isPropIsDecProp : {P : Type ℓ} → isProp (isDecProp P) isPropIsDecProp p q = Σ≡PropEquiv (λ _ → isOfHLevel⁺≃ᵣ 0 isPropBool→Type) .fst (Bool→TypeInj _ _ (invEquiv (p .snd) ⋆ q .snd)) isDecPropRespectEquiv : {P : Type ℓ} {Q : Type ℓ'} → P ≃ Q → isDecProp Q → isDecProp P isDecPropRespectEquiv e (t , e') = t , e ⋆ e'
{ "alphanum_fraction": 0.71600253, "avg_line_length": 31.62, "ext": "agda", "hexsha": "69b7ec8506e05436fe7ad598ca077c0a4d594f03", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_path": "Cubical/Relation/Nullary/DecidablePropositions.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/Relation/Nullary/DecidablePropositions.agda", "max_line_length": 81, "max_stars_count": 1, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Relation/Nullary/DecidablePropositions.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "num_tokens": 567, "size": 1581 }
-- Andreas, 2011-09-21, reported by Nisse -- {-# OPTIONS -v tc.lhs.unify:25 #-} module Issue292-23 where data ⊤ : Set where tt : ⊤ data D : (A : Set) → A → Set₁ where d : (A : Set) (x : A) → D A x data P : (x : ⊤) → D ⊤ x → Set₁ where p : (x : ⊤) → P x (d ⊤ x) Foo : P tt (d ⊤ tt) → Set₁ Foo (p .tt) = Set -- should work -- bug was caused by a use of ureduce instead of reduce
{ "alphanum_fraction": 0.5466321244, "avg_line_length": 22.7058823529, "ext": "agda", "hexsha": "e9f5ed1744f5dab19364af3f3501ef72398e93a4", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/succeed/Issue292-23.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/succeed/Issue292-23.agda", "max_line_length": 55, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/Issue292-23.agda", "max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z", "num_tokens": 160, "size": 386 }
module Everything where import Basic import Category import Functor import Nat import Yoneda import Adjoint import Monad import TAlgebra
{ "alphanum_fraction": 0.8550724638, "avg_line_length": 12.5454545455, "ext": "agda", "hexsha": "39b05d1d1f831a775db4a8a76f7e82e37f440f8f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "myuon/agda-cate", "max_forks_repo_path": "Everything.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "myuon/agda-cate", "max_issues_repo_path": "Everything.agda", "max_line_length": 23, "max_stars_count": 2, "max_stars_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "myuon/agda-cate", "max_stars_repo_path": "Everything.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-02T07:30:47.000Z", "max_stars_repo_stars_event_min_datetime": "2018-07-28T04:59:31.000Z", "num_tokens": 33, "size": 138 }
-- Andreas, 2016-07-29, issue #1720 reported by Mietek Bak postulate A B : Set a0 : A b0 : B record R (a1 : A) (b1 : B) : Set where field fa : A a : A a = {!!} field fb : B b : B b = {!!} field f : A -- Problem: -- Interaction points are doubled.
{ "alphanum_fraction": 0.5345454545, "avg_line_length": 11.4583333333, "ext": "agda", "hexsha": "8e2f0d9ea4c9ce1a2030ed237057ed445ff69e22", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/interaction/Issue1720-2.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/interaction/Issue1720-2.agda", "max_line_length": 58, "max_stars_count": 3, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/interaction/Issue1720-2.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 108, "size": 275 }
module L.Base.Unit.Core where -- Import the unit type and its only element tt : ⊤ open import Agda.Builtin.Unit renaming (tt to ⋆) public ⊤-elim : ∀{c} (C : ⊤ → Set c) → C ⋆ → (a : ⊤) → C a ⊤-elim = λ C c a → c
{ "alphanum_fraction": 0.5887850467, "avg_line_length": 23.7777777778, "ext": "agda", "hexsha": "884e4480f42d00b9076636051e5edb88315cbba5", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "83707537b182ba8906228ac0bcb9ccef972eaaa3", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "borszag/smallib", "max_forks_repo_path": "src/L/Base/Unit/Core.agda", "max_issues_count": 10, "max_issues_repo_head_hexsha": "83707537b182ba8906228ac0bcb9ccef972eaaa3", "max_issues_repo_issues_event_max_datetime": "2020-11-09T16:40:39.000Z", "max_issues_repo_issues_event_min_datetime": "2020-10-19T10:13:16.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "borszag/smallib", "max_issues_repo_path": "src/L/Base/Unit/Core.agda", "max_line_length": 55, "max_stars_count": null, "max_stars_repo_head_hexsha": "83707537b182ba8906228ac0bcb9ccef972eaaa3", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "borszag/smallib", "max_stars_repo_path": "src/L/Base/Unit/Core.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 86, "size": 214 }
-- {-# OPTIONS -v tc.cc:12 -v tc.cover.splittree:10 #-} -- {-# OPTIONS -v tc.cover.strategy:100 -v tc.cover.precomputed:100 #-} -- {-# OPTIONS -v tc.cover.split.con:20 #-} module CoverStrategy where import Common.Level open import Common.Prelude renaming (Nat to ℕ) data _∼_ : ℕ → ℕ → Set where pr : ∀ {n} → suc n ∼ n eq : ∀ {n} → n ∼ n max : ∀ {m n} → m ∼ n → ℕ max (pr {n}) = suc n max (eq {n}) = n data Tree : ℕ → Set where node : ∀ {hˡ hʳ} (bal : hˡ ∼ hʳ) → Tree (max bal) -- 'test' only passes if we split first on 'Tree hˡ' and then on 'hˡ ∼ hʳ' -- This refutes a split strategy that prefers all-constructor columns -- over those with catch-alls. test : ∀ {hˡ hʳ} → Tree hˡ → hˡ ∼ hʳ → Set test (node pr) pr = ℕ test (node eq) pr = ℕ test x eq = ℕ {- We cannot split on 'Tree hˡ' if we have already split on 'hˡ ∼ hʳ' bla : ∀ {hˡ hʳ} → Tree hˡ → hˡ ∼ hʳ → Set bla nod pr = {!nod!} bla nod eq = {!!} -}
{ "alphanum_fraction": 0.5859124867, "avg_line_length": 27.5588235294, "ext": "agda", "hexsha": "b03ad0f4b958b011c06a11ebdea9ae94403c7d14", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "test/succeed/CoverStrategy.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "test/succeed/CoverStrategy.agda", "max_line_length": 74, "max_stars_count": 1, "max_stars_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "np/agda-git-experiment", "max_stars_repo_path": "test/succeed/CoverStrategy.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 364, "size": 937 }
{-# OPTIONS --without-K --safe #-} -- 'Traditionally', meaning in nLab and in -- "Lectures on n-Categories and Cohomology" by Baez and Shulman -- https://arxiv.org/abs/math/0608420 -- (-2)-Categories are defined to be just a single value, with trivial Hom -- But that's hardly a definition of a class of things, it's a definition of -- a single structure! What we want is the definition of a class which turns -- out to be (essentially) unique. Rather like the reals are (essentially) the -- only ordered complete archimedean field. -- So we will take a -2-Category to be a full-fledge Category, but where -- 1. |Obj| is (Categorically) contractible -- 2. |Hom| is connected (all arrows are equal) -- Note that we don't need to say anything at all about ≈ module Categories.Minus2-Category where open import Level open import Categories.Category open import Data.Product using (Σ) import Categories.Morphism as M private variable o ℓ e : Level record -2-Category : Set (suc (o ⊔ ℓ ⊔ e)) where field cat : Category o ℓ e open Category cat public open M cat using (_≅_) field Obj-Contr : Σ Obj (λ x → (y : Obj) → x ≅ y) Hom-Conn : {x y : Obj} {f g : x ⇒ y} → f ≈ g
{ "alphanum_fraction": 0.6890547264, "avg_line_length": 31.7368421053, "ext": "agda", "hexsha": "cb3ff8fa9679b48e65965f64f244d794c540fa5d", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Minus2-Category.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Minus2-Category.agda", "max_line_length": 78, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Minus2-Category.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 360, "size": 1206 }
{-# OPTIONS --cumulativity #-} open import Agda.Primitive postulate X : Set P : (A : Set) → A → Set id : ∀ a (A : Set a) → A → A works : P (X → X) (id (lsuc lzero) X) fails : P _ (id (lsuc lzero) X)
{ "alphanum_fraction": 0.509009009, "avg_line_length": 20.1818181818, "ext": "agda", "hexsha": "89b6dde26df172a4d7cc46be05ef1ca7574d91c6", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue4090.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue4090.agda", "max_line_length": 39, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue4090.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 88, "size": 222 }
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Interval.Base where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude data Interval : Type₀ where zero : Interval one : Interval seg : zero ≡ one isContrInterval : isContr Interval isContrInterval = (zero , (λ x → rem x)) where rem : (x : Interval) → zero ≡ x rem zero = refl rem one = seg rem (seg i) j = seg (i ∧ j) funExtInterval : ∀ {ℓ} (A B : Type ℓ) (f g : A → B) → ((x : A) → f x ≡ g x) → f ≡ g funExtInterval A B f g p = λ i x → hmtpy x (seg i) where hmtpy : A → Interval → B hmtpy x zero = f x hmtpy x one = g x hmtpy x (seg i) = p x i intervalElim : (A : Interval → Type₀) (x : A zero) (y : A one) (p : PathP (λ i → A (seg i)) x y) → (x : Interval) → A x intervalElim A x y p zero = x intervalElim A x y p one = y intervalElim A x y p (seg i) = p i -- Note that this is not definitional (it is not proved by refl) intervalEta : ∀ {A : Type₀} (f : Interval → A) → intervalElim _ (f zero) (f one) (λ i → f (seg i)) ≡ f intervalEta f i zero = f zero intervalEta f i one = f one intervalEta f i (seg j) = f (seg j)
{ "alphanum_fraction": 0.5922165821, "avg_line_length": 29.55, "ext": "agda", "hexsha": "a454a7fb92c6843782421ae0fa0e7741b6cbf6a8", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_path": "Cubical/HITs/Interval/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "limemloh/cubical", "max_issues_repo_path": "Cubical/HITs/Interval/Base.agda", "max_line_length": 102, "max_stars_count": null, "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_path": "Cubical/HITs/Interval/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 427, "size": 1182 }
-- Andreas, 2012-05-14, issue reported by Nisse -- {-# OPTIONS -v term:20 #-} module Issue636 where open import Common.Coinduction data ⊥ : Set where data D : Set where c : ∞ D → D d : D d = c (♯ d) not-d : D → ⊥ not-d (c x) = not-d (♭ x) bad : ⊥ bad = not-d d
{ "alphanum_fraction": 0.5762081784, "avg_line_length": 13.45, "ext": "agda", "hexsha": "a60a644f07438cea2b913e1b208b03eef76465dc", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "alhassy/agda", "max_forks_repo_path": "test/Fail/Issue636.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "alhassy/agda", "max_issues_repo_path": "test/Fail/Issue636.agda", "max_line_length": 47, "max_stars_count": 3, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "test/Fail/Issue636.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 106, "size": 269 }
module xxx where open import Agda.Builtin.Unit using (⊤) open import IO as IO hiding (_>>=_; _>>_) import IO.Primitive as Primitive open import hcio as HCIO main : Primitive.IO ⊤ main = run do IO.putStrLn "enter file name:" f ← HCIO.getLine IO.putStrLn "enter file contents" c ← HCIO.getLine IO.writeFile f c c' ← IO.readFiniteFile f IO.putStrLn c' std ← IO.readFiniteFile "spacetrack-data-2021-05-31.txt" IO.putStrLn std IO.putStrLn "Bye"
{ "alphanum_fraction": 0.6507936508, "avg_line_length": 21, "ext": "agda", "hexsha": "141081047b2e566d741bb4c96cda4c9d6ff0760c", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_path": "agda/examples-that-run/xxx/src-agda/xxx.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_path": "agda/examples-that-run/xxx/src-agda/xxx.agda", "max_line_length": 58, "max_stars_count": 36, "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_path": "agda/examples-that-run/xxx/src-agda/xxx.agda", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "num_tokens": 151, "size": 504 }
{-# OPTIONS --without-K #-} module GPerm where -- Definition of a general permutation, and some combinators. -- This is the 'abstract' view, in terms of functions. Contrast with the -- concrete view in term of vectors (and restricted to Enumerable sets) -- In some sense, even better would be to consider 'weak' permutations -- as exactly _≃_. Having both side be syntactically equal is weird, as we -- are exactly trying to liberate ourselves from that! -- In other words, we won't actually use GPerm anywhere. open import Level using (_⊔_) open import Data.Sum using (_⊎_) open import Data.Product using (_×_) open import Equiv open import TypeEquiv GPerm : Set → Set GPerm A = A ≃ A -- composition. Stick to Set₀. _⊙_ : {A : Set} → GPerm A → GPerm A → GPerm A _⊙_ = trans≃ -- parallel composition. _⊕_ : {A C : Set} → GPerm A → GPerm C → GPerm (A ⊎ C) _⊕_ = path⊎ -- tensor product _⊗_ : {A B : Set} → GPerm A → GPerm B → GPerm (A × B) _⊗_ = path×
{ "alphanum_fraction": 0.6603396603, "avg_line_length": 27.8055555556, "ext": "agda", "hexsha": "ca82d4ef60694b494821782b24b5c7f8d3ccee48", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "Univalence/GPerm.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "Univalence/GPerm.agda", "max_line_length": 76, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "Univalence/GPerm.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 305, "size": 1001 }
------------------------------------------------------------------------ -- Definitions of "free in" and "closed", along with some properties ------------------------------------------------------------------------ open import Atom module Free-variables (atoms : χ-atoms) where open import Dec open import Equality.Propositional.Cubical open import Logical-equivalence using (_⇔_) open import Prelude hiding (const; swap) open import Bag-equivalence equality-with-J as B using (_∈_) open import Bijection equality-with-J as Bijection using (_↔_) import Erased.Cubical equality-with-paths as E open import Equivalence equality-with-J as Eq using (_≃_) open import Finite-subset.Listed equality-with-paths as S using (Finite-subset-of) open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional equality-with-paths as T using (∥_∥) open import List equality-with-J using (_++_; foldr) open import Chi atoms open import Propositional atoms open import Substitution atoms open import Values atoms open χ-atoms atoms private variable A : Type bs : List Br c c′ : Const e e₁ e₂ e′ e″ : Exp es : List Exp x y : Var xs xs′ : A private -- Two variants of V._≟_. _≟V₁_ : (x y : Var) → Dec T.∥ x ≡ y ∥ _≟V₁_ = T.decidable→decidable-∥∥ V._≟_ _≟V₂_ : (x y : Var) → E.Dec-Erased T.∥ x ≡ y ∥ x ≟V₂ y = E.Dec→Dec-Erased (x ≟V₁ y) ------------------------------------------------------------------------ -- Definitions -- Free variables. infix 4 _∈FV_ data _∈FV_ (x : Var) : Exp → Type where apply-left : ∀ {e₁ e₂} → x ∈FV e₁ → x ∈FV apply e₁ e₂ apply-right : ∀ {e₁ e₂} → x ∈FV e₂ → x ∈FV apply e₁ e₂ lambda : ∀ {y e} → x ≢ y → x ∈FV e → x ∈FV lambda y e case-head : ∀ {e bs} → x ∈FV e → x ∈FV case e bs case-body : ∀ {e bs c xs e′} → x ∈FV e′ → branch c xs e′ ∈ bs → ¬ x ∈ xs → x ∈FV case e bs rec : ∀ {y e} → x ≢ y → x ∈FV e → x ∈FV rec y e var : ∀ {y} → x ≡ y → x ∈FV var y const : ∀ {c es e} → x ∈FV e → e ∈ es → x ∈FV const c es -- Closed, except that the given variables may occur. Closed′ : List Var → Exp → Type Closed′ xs e = ∀ x → ¬ x ∈ xs → ¬ x ∈FV e -- The property of being closed. Closed : Exp → Type Closed = Closed′ [] -- Closed expressions. Closed-exp : Type Closed-exp = ∃ Closed ------------------------------------------------------------------------ -- Inversion lemmas for _∈_ ∈apply : (x ∈FV apply e₁ e₂) ≃ (x ∈FV e₁ ⊎ x ∈FV e₂) ∈apply = Eq.↔→≃ (λ { (apply-left x∈) → inj₁ x∈ ; (apply-right x∈) → inj₂ x∈ }) [ apply-left , apply-right ] [ (λ _ → refl) , (λ _ → refl) ] (λ { (apply-left _) → refl ; (apply-right _) → refl }) ∈lambda : (x ∈FV lambda y e) ≃ (x ≢ y × x ∈FV e) ∈lambda = Eq.↔→≃ (λ { (lambda x≢y x∈e) → x≢y , x∈e }) (uncurry lambda) (λ _ → refl) (λ { (lambda _ _) → refl }) ∈case : (x ∈FV case e bs) ≃ (x ∈FV e ⊎ ∃ λ c → ∃ λ xs → ∃ λ e′ → x ∈FV e′ × branch c xs e′ ∈ bs × ¬ x ∈ xs) ∈case = Eq.↔→≃ (λ { (case-head x∈) → inj₁ x∈ ; (case-body x∈ b∈ x∉) → inj₂ (_ , _ , _ , x∈ , b∈ , x∉) }) [ case-head , (λ (_ , _ , _ , x∈ , b∈ , x∉) → case-body x∈ b∈ x∉) ] [ (λ _ → refl) , (λ _ → refl) ] (λ { (case-head _) → refl ; (case-body _ _ _) → refl }) ∈rec : (x ∈FV rec y e) ≃ (x ≢ y × x ∈FV e) ∈rec = Eq.↔→≃ (λ { (rec x≢y x∈e) → x≢y , x∈e }) (uncurry rec) (λ _ → refl) (λ { (rec _ _) → refl }) ∈var : (x ∈FV var y) ≃ (x ≡ y) ∈var = Eq.↔→≃ (λ { (var x≡y) → x≡y }) var (λ _ → refl) (λ { (var _) → refl }) ∈const : (x ∈FV const c es) ≃ (∃ λ e → x ∈FV e × e ∈ es) ∈const = Eq.↔→≃ (λ { (const ∈e ∈es) → _ , ∈e , ∈es }) (λ (_ , ∈e , ∈es) → const ∈e ∈es) (λ _ → refl) (λ { (const _ _) → refl }) ------------------------------------------------------------------------ -- Characterisation lemmas for Closed′ Closed′-apply≃ : Closed′ xs (apply e₁ e₂) ≃ (Closed′ xs e₁ × Closed′ xs e₂) Closed′-apply≃ {xs = xs} {e₁ = e₁} {e₂ = e₂} = Closed′ xs (apply e₁ e₂) ↔⟨⟩ (∀ x → ¬ x ∈ xs → ¬ x ∈FV apply e₁ e₂) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈apply) ⟩ (∀ x → ¬ x ∈ xs → ¬ (x ∈FV e₁ ⊎ x ∈FV e₂)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬⊎↔¬×¬ ext) ⟩ (∀ x → ¬ x ∈ xs → (¬ x ∈FV e₁ × ¬ x ∈FV e₂)) ↔⟨ (∀-cong ext λ _ → ΠΣ-comm) ⟩ (∀ x → (¬ x ∈ xs → ¬ x ∈FV e₁) × (¬ x ∈ xs → ¬ x ∈FV e₂)) ↔⟨ ΠΣ-comm ⟩ (∀ x → ¬ x ∈ xs → ¬ x ∈FV e₁) × (∀ x → ¬ x ∈ xs → ¬ x ∈FV e₂) ↔⟨⟩ Closed′ xs e₁ × Closed′ xs e₂ □ Closed′-lambda≃ : Closed′ xs (lambda x e) ≃ Closed′ (x ∷ xs) e Closed′-lambda≃ {xs = xs} {x = x} {e = e} = Closed′ xs (lambda x e) ↔⟨⟩ (∀ y → ¬ y ∈ xs → ¬ y ∈FV lambda x e) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈lambda) ⟩ (∀ y → ¬ y ∈ xs → ¬ (y ≢ x × y ∈FV e)) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → currying) ⟩ (∀ y → ¬ y ∈ xs → y ≢ x → ¬ y ∈FV e) ↔⟨ (∀-cong ext λ _ → Π-comm) ⟩ (∀ y → y ≢ x → ¬ y ∈ xs → ¬ y ∈FV e) ↔⟨ (∀-cong ext λ _ → inverse currying) ⟩ (∀ y → y ≢ x × ¬ y ∈ xs → ¬ y ∈FV e) ↝⟨ (∀-cong ext λ _ → →-cong₁ {k₁ = equivalence} ext $ inverse $ ¬⊎↔¬×¬ ext) ⟩ (∀ y → ¬ (y ≡ x ⊎ y ∈ xs) → ¬ y ∈FV e) ↔⟨⟩ Closed′ (x ∷ xs) e □ Closed′-rec≃ : Closed′ xs (rec x e) ≃ Closed′ (x ∷ xs) e Closed′-rec≃ {xs = xs} {x = x} {e = e} = Closed′ xs (rec x e) ↔⟨⟩ (∀ y → ¬ y ∈ xs → ¬ y ∈FV rec x e) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈rec) ⟩ (∀ y → ¬ y ∈ xs → ¬ (y ≢ x × y ∈FV e)) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → currying) ⟩ (∀ y → ¬ y ∈ xs → y ≢ x → ¬ y ∈FV e) ↔⟨ (∀-cong ext λ _ → Π-comm) ⟩ (∀ y → y ≢ x → ¬ y ∈ xs → ¬ y ∈FV e) ↔⟨ (∀-cong ext λ _ → inverse currying) ⟩ (∀ y → y ≢ x × ¬ y ∈ xs → ¬ y ∈FV e) ↝⟨ (∀-cong ext λ _ → →-cong₁ {k₁ = equivalence} ext $ inverse $ ¬⊎↔¬×¬ ext) ⟩ (∀ y → ¬ (y ≡ x ⊎ y ∈ xs) → ¬ y ∈FV e) ↔⟨⟩ Closed′ (x ∷ xs) e □ Closed′-case≃ : Closed′ xs (case e bs) ≃ (Closed′ xs e × ∀ {c ys e} → branch c ys e ∈ bs → Closed′ (ys ++ xs) e) Closed′-case≃ {xs = xs} {e = e} {bs = bs} = Closed′ xs (case e bs) ↔⟨⟩ (∀ x → ¬ x ∈ xs → ¬ x ∈FV case e bs) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈case) ⟩ (∀ x → ¬ x ∈ xs → ¬ (x ∈FV e ⊎ ∃ λ c → ∃ λ ys → ∃ λ e′ → x ∈FV e′ × branch c ys e′ ∈ bs × ¬ x ∈ ys)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬⊎↔¬×¬ ext) ⟩ (∀ x → ¬ x ∈ xs → ¬ x ∈FV e × ¬ ∃ λ c → ∃ λ ys → ∃ λ e′ → x ∈FV e′ × branch c ys e′ ∈ bs × ¬ x ∈ ys) ↔⟨ ΠΣ-comm F.∘ (∀-cong ext λ _ → ΠΣ-comm) ⟩ (∀ x → ¬ x ∈ xs → ¬ x ∈FV e) × (∀ x → ¬ x ∈ xs → ¬ ∃ λ c → ∃ λ ys → ∃ λ e′ → x ∈FV e′ × branch c ys e′ ∈ bs × ¬ x ∈ ys) ↝⟨ ∃-cong lemma ⟩ (∀ x → ¬ x ∈ xs → ¬ x ∈FV e) × (∀ {c ys e} → branch c ys e ∈ bs → ∀ x → ¬ x ∈ ys ++ xs → ¬ x ∈FV e) ↔⟨⟩ Closed′ xs e × (∀ {c ys e} → branch c ys e ∈ bs → Closed′ (ys ++ xs) e) □ where lemma = λ hyp → (∀ x → ¬ x ∈ xs → ¬ ∃ λ c → ∃ λ ys → ∃ λ e → x ∈FV e × branch c ys e ∈ bs × ¬ x ∈ ys) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → (∀-cong ext λ _ → (∀-cong ext λ _ → (∀-cong ext λ _ → currying F.∘ Π-comm F.∘ currying) F.∘ currying) F.∘ currying) F.∘ currying) ⟩ (∀ x → ¬ x ∈ xs → ∀ c ys e → branch c ys e ∈ bs → ¬ x ∈ ys → ¬ x ∈FV e) ↔⟨ (∀-cong ext λ _ → (∀-cong ext λ _ → (∀-cong ext λ _ → (∀-cong ext λ _ → (∀-cong ext λ _ → inverse currying) F.∘ currying) F.∘ Π-comm) F.∘ Π-comm) F.∘ Π-comm) F.∘ Π-comm F.∘ inverse currying ⟩ (∀ c ys e → branch c ys e ∈ bs → ∀ x → ¬ x ∈ xs × ¬ x ∈ ys → ¬ x ∈FV e) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → →-cong₁ ext $ inverse $ ¬⊎↔¬×¬ {k = equivalence} ext) ⟩ (∀ c ys e → branch c ys e ∈ bs → ∀ x → ¬ (x ∈ xs ⊎ x ∈ ys) → ¬ x ∈FV e) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → →-cong₁ ext $ ¬-cong ext ⊎-comm) ⟩ (∀ c ys e → branch c ys e ∈ bs → ∀ x → ¬ (x ∈ ys ⊎ x ∈ xs) → ¬ x ∈FV e) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → →-cong₁ ext $ ¬-cong ext $ inverse $ B.Any-++ _ _ _) ⟩ (∀ c ys e → branch c ys e ∈ bs → ∀ x → ¬ x ∈ ys ++ xs → ¬ x ∈FV e) ↔⟨ inverse $ (∀-cong ext λ _ → (∀-cong ext λ _ → Bijection.implicit-Π↔Π) F.∘ Bijection.implicit-Π↔Π) F.∘ Bijection.implicit-Π↔Π ⟩□ (∀ {c ys e} → branch c ys e ∈ bs → ∀ x → ¬ x ∈ ys ++ xs → ¬ x ∈FV e) □ Closed′-const≃ : Closed′ xs (const c es) ≃ (∀ e → e ∈ es → Closed′ xs e) Closed′-const≃ {xs = xs} {c = c} {es = es} = Closed′ xs (const c es) ↔⟨⟩ (∀ x → ¬ x ∈ xs → ¬ x ∈FV const c es) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈const) ⟩ (∀ x → ¬ x ∈ xs → ¬ ∃ λ e → x ∈FV e × e ∈ es) ↔⟨ currying F.∘ (∀-cong ext λ _ → currying) F.∘ Π-comm F.∘ (∀-cong ext λ _ → inverse currying F.∘ (∀-cong ext λ _ → Π-comm F.∘ currying) F.∘ currying) F.∘ inverse currying ⟩ (∀ e → e ∈ es → ∀ x → ¬ x ∈ xs → ¬ x ∈FV e) ↔⟨⟩ (∀ e → e ∈ es → Closed′ xs e) □ Closed′-var≃ : Closed′ xs (var x) ≃ ∥ x ∈ xs ∥ Closed′-var≃ {xs = xs} {x = x} = Closed′ xs (var x) ↔⟨⟩ (∀ y → ¬ y ∈ xs → ¬ y ∈FV var x) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈var) ⟩ (∀ y → ¬ y ∈ xs → ¬ y ≡ x) ↝⟨ (∀-cong ext λ _ → →-cong₁ ext $ inverse T.¬∥∥↔¬) ⟩ (∀ y → ¬ ∥ y ∈ xs ∥ → ¬ y ≡ x) ↝⟨ (∀-cong ext λ _ → inverse $ →≃¬→¬ (λ _ _ → T.truncation-is-proposition) (λ _ → Dec-map (from-equivalence $ inverse S.∥∈∥≃∈-from-List) (S.member? _≟V₁_ _ _)) ext) ⟩ (∀ y → y ≡ x → ∥ y ∈ xs ∥) ↝⟨ (∀-cong ext λ _ → →-cong₁ ext ≡-comm) ⟩ (∀ y → x ≡ y → ∥ y ∈ xs ∥) ↝⟨ inverse $ ∀-intro _ ext ⟩□ ∥ x ∈ xs ∥ □ ------------------------------------------------------------------------ -- Some properties -- Closed is propositional. Closed-propositional : ∀ {e} → Is-proposition (Closed e) Closed-propositional = Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → ¬-propositional ext -- Closed-exp is a set. Closed-exp-set : Is-set Closed-exp Closed-exp-set = Σ-closure 2 Exp-set (λ _ → mono₁ 1 Closed-propositional) -- Two closed expressions are equal if the underlying expressions are -- equal. closed-equal-if-expressions-equal : {e₁ e₂ : Closed-exp} → proj₁ e₁ ≡ proj₁ e₂ → e₁ ≡ e₂ closed-equal-if-expressions-equal eq = Σ-≡,≡→≡ eq (Closed-propositional _ _) -- Constructor applications are closed. mutual const→closed : ∀ {e} → Constructor-application e → Closed e const→closed (const c cs) x x∉[] (const x∈e e∈es) = consts→closed cs e∈es x x∉[] x∈e consts→closed : ∀ {e es} → Constructor-applications es → e ∈ es → Closed e consts→closed [] () consts→closed (c ∷ cs) (inj₁ refl) = const→closed c consts→closed (c ∷ cs) (inj₂ e∈es) = consts→closed cs e∈es -- Closed e implies Closed′ xs e, for any xs. Closed→Closed′ : ∀ {xs e} → Closed e → Closed′ xs e Closed→Closed′ cl x _ = cl x (λ ()) -- If a variable is free in e [ x ← e′ ], then it is either free in e, -- or it is distinct from x and free in e′. mutual subst-∈FV : ∀ x e {x′ e′} → x′ ∈FV e [ x ← e′ ] → x′ ∈FV e × x′ ≢ x ⊎ x′ ∈FV e′ subst-∈FV x (apply e₁ e₂) (apply-left p) = ⊎-map (Σ-map apply-left id) id (subst-∈FV x e₁ p) subst-∈FV x (apply e₁ e₂) (apply-right p) = ⊎-map (Σ-map apply-right id) id (subst-∈FV x e₂ p) subst-∈FV x (lambda y e) (lambda x′≢y p) with x V.≟ y subst-∈FV x (lambda y e) (lambda x′≢y p) | yes x≡y = inj₁ (lambda x′≢y p , x′≢y ∘ flip trans x≡y) subst-∈FV x (lambda y e) (lambda x′≢y p) | no _ = ⊎-map (Σ-map (lambda x′≢y) id) id (subst-∈FV x e p) subst-∈FV x (case e bs) (case-head p) = ⊎-map (Σ-map case-head id) id (subst-∈FV x e p) subst-∈FV x (case e bs) (case-body p ps x′∉xs) = ⊎-map (Σ-map (λ (p : ∃ λ _ → ∃ λ _ → ∃ λ _ → _ × _ × _) → let _ , _ , _ , ps , p , ∉ = p in case-body p ps ∉) id) id (subst-∈FV-B⋆ bs p ps x′∉xs) subst-∈FV x (rec y e) p with x V.≟ y subst-∈FV x (rec y e) (rec x′≢y p) | yes x≡y = inj₁ (rec x′≢y p , x′≢y ∘ flip trans x≡y) subst-∈FV x (rec y e) (rec x′≢y p) | no x≢y = ⊎-map (Σ-map (rec x′≢y) id) id (subst-∈FV x e p) subst-∈FV x (var y) p with x V.≟ y subst-∈FV x (var y) p | yes x≡y = inj₂ p subst-∈FV x (var y) (var x′≡y) | no x≢y = inj₁ (var x′≡y , x≢y ∘ flip trans x′≡y ∘ sym) subst-∈FV x (const c es) (const p ps) = ⊎-map (Σ-map (λ { (_ , ps , p) → const p ps }) id) id (subst-∈FV-⋆ es p ps) subst-∈FV-⋆ : ∀ {x x′ e e′} es → x′ ∈FV e → e ∈ es [ x ← e′ ]⋆ → (∃ λ e → e ∈ es × x′ ∈FV e) × x′ ≢ x ⊎ x′ ∈FV e′ subst-∈FV-⋆ [] p () subst-∈FV-⋆ (e ∷ es) p (inj₁ refl) = ⊎-map (Σ-map (λ p → _ , inj₁ refl , p) id) id (subst-∈FV _ e p) subst-∈FV-⋆ (e ∷ es) p (inj₂ q) = ⊎-map (Σ-map (Σ-map id (Σ-map inj₂ id)) id) id (subst-∈FV-⋆ es p q) subst-∈FV-B⋆ : ∀ {x x′ e e′ c xs} bs → x′ ∈FV e → branch c xs e ∈ bs [ x ← e′ ]B⋆ → ¬ x′ ∈ xs → (∃ λ c → ∃ λ xs → ∃ λ e → branch c xs e ∈ bs × x′ ∈FV e × ¬ x′ ∈ xs) × x′ ≢ x ⊎ x′ ∈FV e′ subst-∈FV-B⋆ [] p () subst-∈FV-B⋆ {x} (branch c xs e ∷ bs) p (inj₁ eq) q with V.member x xs subst-∈FV-B⋆ {x} (branch c xs e ∷ bs) p (inj₁ refl) q | yes x∈xs = inj₁ ((c , xs , e , inj₁ refl , p , q) , λ x′≡x → q (subst (_∈ _) (sym x′≡x) x∈xs)) subst-∈FV-B⋆ {x} (branch c xs e ∷ bs) p (inj₁ refl) q | no x∉xs = ⊎-map (Σ-map (λ p → _ , _ , _ , inj₁ refl , p , q) id) id (subst-∈FV _ e p) subst-∈FV-B⋆ (b ∷ bs) p (inj₂ ps) q = ⊎-map (Σ-map (Σ-map _ (Σ-map _ (Σ-map _ (Σ-map inj₂ id)))) id) id (subst-∈FV-B⋆ bs p ps q) ------------------------------------------------------------------------ -- Various closure properties (or similar properties) for Closed′ Closed′-closed-under-apply : ∀ {xs e₁ e₂} → Closed′ xs e₁ → Closed′ xs e₂ → Closed′ xs (apply e₁ e₂) Closed′-closed-under-apply = curry $ _≃_.from Closed′-apply≃ Closed′-closed-under-lambda : ∀ {x xs e} → Closed′ (x ∷ xs) e → Closed′ xs (lambda x e) Closed′-closed-under-lambda = _≃_.from Closed′-lambda≃ Closed′-closed-under-rec : ∀ {x xs e} → Closed′ (x ∷ xs) e → Closed′ xs (rec x e) Closed′-closed-under-rec = _≃_.from Closed′-rec≃ Closed′-closed-under-case : ∀ {xs e bs} → Closed′ xs e → (∀ {c ys e} → branch c ys e ∈ bs → Closed′ (ys ++ xs) e) → Closed′ xs (case e bs) Closed′-closed-under-case = curry $ _≃_.from Closed′-case≃ Closed′-closed-under-const : ∀ {xs c es} → (∀ e → e ∈ es → Closed′ xs e) → Closed′ xs (const c es) Closed′-closed-under-const = _≃_.from Closed′-const≃ Closed′-closed-under-var : ∀ {x xs} → x ∈ xs → Closed′ xs (var x) Closed′-closed-under-var = _≃_.from Closed′-var≃ ∘ T.∣_∣ Closed′-closed-under-subst : ∀ {x xs e e′} → Closed′ (x ∷ xs) e → Closed′ xs e′ → Closed′ xs (e [ x ← e′ ]) Closed′-closed-under-subst cl-e cl-e′ y y∉xs = [ uncurry (λ y∈e y≢x → cl-e y [ y≢x , y∉xs ] y∈e) , cl-e′ y y∉xs ] ∘ subst-∈FV _ _ ------------------------------------------------------------------------ -- Computing free or fresh variables -- One can construct a finite set containing exactly the free -- variables in a term. mutual free : (e : Exp) → ∃ λ (fs : Finite-subset-of Var) → ∀ x → (x S.∈ fs) ⇔ (x ∈FV e) free (apply e₁ e₂) = Σ-zip S._∪_ (λ {fs₁ fs₂} hyp₁ hyp₂ x → x S.∈ fs₁ S.∪ fs₂ ↔⟨ S.∈∪≃ ⟩ x S.∈ fs₁ T.∥⊎∥ x S.∈ fs₂ ↝⟨ T.Dec→∥∥⇔ (Dec-⊎ (S.member? _≟V₁_ _ _) (S.member? _≟V₁_ _ _)) ⟩ x S.∈ fs₁ ⊎ x S.∈ fs₂ ↝⟨ hyp₁ x ⊎-cong hyp₂ x ⟩ x ∈FV e₁ ⊎ x ∈FV e₂ ↔⟨ inverse ∈apply ⟩□ x ∈FV apply e₁ e₂ □) (free e₁) (free e₂) free (lambda x e) = Σ-map (S.delete _≟V₂_ x) (λ {fs} hyp y → y S.∈ S.delete _≟V₂_ x fs ↔⟨ S.∈delete≃ _≟V₂_ ⟩ y ≢ x × y S.∈ fs ↝⟨ (∃-cong λ _ → hyp y) ⟩ y ≢ x × y ∈FV e ↔⟨ inverse ∈lambda ⟩□ y ∈FV lambda x e □) (free e) free (case e bs) = Σ-zip S._∪_ (λ {fs₁ fs₂} hyp₁ hyp₂ x → x S.∈ fs₁ S.∪ fs₂ ↔⟨ S.∈∪≃ ⟩ x S.∈ fs₁ T.∥⊎∥ x S.∈ fs₂ ↝⟨ T.Dec→∥∥⇔ (Dec-⊎ (S.member? _≟V₁_ _ _) (S.member? _≟V₁_ _ _)) ⟩ x S.∈ fs₁ ⊎ x S.∈ fs₂ ↝⟨ hyp₁ x ⊎-cong hyp₂ x ⟩ (x ∈FV e ⊎ ∃ λ c → ∃ λ xs → ∃ λ e′ → x ∈FV e′ × branch c xs e′ ∈ bs × ¬ x ∈ xs) ↔⟨ inverse ∈case ⟩□ x ∈FV case e bs □) (free e) (free-B⋆ bs) free (rec x e) = Σ-map (S.delete _≟V₂_ x) (λ {fs} hyp y → y S.∈ S.delete _≟V₂_ x fs ↔⟨ S.∈delete≃ _≟V₂_ ⟩ y ≢ x × y S.∈ fs ↝⟨ (∃-cong λ _ → hyp y) ⟩ y ≢ x × y ∈FV e ↔⟨ inverse ∈rec ⟩□ y ∈FV rec x e □) (free e) free (var x) = S.singleton x , λ y → y S.∈ S.singleton x ↔⟨ S.∈singleton≃ ⟩ T.∥ y ≡ x ∥ ↔⟨ T.∥∥↔ V.Name-set ⟩ y ≡ x ↔⟨ inverse ∈var ⟩□ y ∈FV var x □ free (const c es) = Σ-map id (λ {fs} hyp x → x S.∈ fs ↝⟨ hyp x ⟩ (∃ λ e → x ∈FV e × e ∈ es) ↔⟨ inverse ∈const ⟩□ x ∈FV const c es □) (free-⋆ es) free-⋆ : (es : List Exp) → ∃ λ (fs : Finite-subset-of Var) → ∀ x → (x S.∈ fs) ⇔ (∃ λ e → x ∈FV e × e ∈ es) free-⋆ [] = S.[] , λ x → x S.∈ S.[] ↔⟨ S.∈[]≃ ⟩ ⊥ ↔⟨ inverse ×-right-zero ⟩ Exp × ⊥₀ ↔⟨ (∃-cong λ _ → inverse ×-right-zero) ⟩ (∃ λ e → x ∈FV e × ⊥) ↔⟨⟩ (∃ λ e → x ∈FV e × e ∈ []) □ free-⋆ (e ∷ es) = Σ-zip S._∪_ (λ {fs₁ fs₂} hyp₁ hyp₂ x → x S.∈ fs₁ S.∪ fs₂ ↔⟨ S.∈∪≃ ⟩ x S.∈ fs₁ T.∥⊎∥ x S.∈ fs₂ ↝⟨ T.Dec→∥∥⇔ (Dec-⊎ (S.member? _≟V₁_ _ _) (S.member? _≟V₁_ _ _)) ⟩ x S.∈ fs₁ ⊎ x S.∈ fs₂ ↝⟨ hyp₁ x ⊎-cong hyp₂ x ⟩ x ∈FV e ⊎ (∃ λ e′ → x ∈FV e′ × e′ ∈ es) ↔⟨ inverse $ (drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ singleton-contractible _) ⊎-cong F.id ⟩ x ∈FV e × (∃ λ e′ → e′ ≡ e) ⊎ (∃ λ e′ → x ∈FV e′ × e′ ∈ es) ↔⟨ ∃-comm ⊎-cong F.id ⟩ (∃ λ e′ → x ∈FV e × e′ ≡ e) ⊎ (∃ λ e′ → x ∈FV e′ × e′ ∈ es) ↔⟨ inverse ∃-⊎-distrib-left ⟩ (∃ λ e′ → (x ∈FV e × e′ ≡ e) ⊎ (x ∈FV e′ × e′ ∈ es)) ↔⟨ (∃-cong λ _ → (×-cong₁ λ e′≡e → ≡⇒↝ equivalence $ cong (_ ∈FV_) $ sym e′≡e) ⊎-cong F.id) ⟩ (∃ λ e′ → (x ∈FV e′ × e′ ≡ e) ⊎ (x ∈FV e′ × e′ ∈ es)) ↔⟨ (∃-cong λ _ → inverse ×-⊎-distrib-left) ⟩ (∃ λ e′ → x ∈FV e′ × (e′ ≡ e ⊎ e′ ∈ es)) ↔⟨⟩ (∃ λ e′ → x ∈FV e′ × e′ ∈ e ∷ es) □) (free e) (free-⋆ es) free-B : (b : Br) → ∃ λ (fs : Finite-subset-of Var) → ∀ x → (x S.∈ fs) ⇔ (∃ λ c → ∃ λ xs → ∃ λ e → x ∈FV e × branch c xs e ≡ b × ¬ x ∈ xs) free-B (branch c xs e) = Σ-map (λ fs → S.minus _≟V₂_ fs (S.from-List xs)) (λ {fs} hyp x → x S.∈ S.minus _≟V₂_ fs (S.from-List xs) ↔⟨ S.∈minus≃ ⟩ x S.∈ fs × x S.∉ S.from-List xs ↔⟨ (∃-cong λ _ → ¬-cong ext $ inverse S.∥∈∥≃∈-from-List) ⟩ x S.∈ fs × ¬ T.∥ x ∈ xs ∥ ↔⟨ (∃-cong λ _ → T.¬∥∥↔¬) ⟩ x S.∈ fs × ¬ x ∈ xs ↝⟨ hyp x ×-cong F.id ⟩ x ∈FV e × ¬ x ∈ xs ↔⟨ (inverse $ drop-⊤-right λ _ → ×-left-identity F.∘ ×-left-identity) ⟩ (x ∈FV e × ¬ x ∈ xs) × ⊤ × ⊤ × ⊤ ↔⟨ (∃-cong λ _ → inverse $ (_⇔_.to contractible⇔↔⊤ $ singleton-contractible _) ×-cong (_⇔_.to contractible⇔↔⊤ $ singleton-contractible _) ×-cong (_⇔_.to contractible⇔↔⊤ $ singleton-contractible _)) ⟩ (x ∈FV e × ¬ x ∈ xs) × (∃ λ c′ → c′ ≡ c) × (∃ λ xs′ → xs′ ≡ xs) × (∃ λ e′ → e′ ≡ e) ↔⟨ (∃-cong λ _ → (∃-cong λ _ → (∃-cong λ _ → ∃-comm F.∘ (∃-cong λ _ → ∃-comm)) F.∘ ∃-comm F.∘ (∃-cong λ _ → inverse Σ-assoc)) F.∘ inverse Σ-assoc) ⟩ (x ∈FV e × ¬ x ∈ xs) × (∃ λ c′ → ∃ λ xs′ → ∃ λ e′ → c′ ≡ c × xs′ ≡ xs × e′ ≡ e) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) F.∘ (∃-cong λ _ → ∃-comm) F.∘ ∃-comm ⟩ (∃ λ c′ → ∃ λ xs′ → ∃ λ e′ → (x ∈FV e × ¬ x ∈ xs) × (c′ ≡ c × xs′ ≡ xs × e′ ≡ e)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → (∃-cong λ _ → ×-comm) F.∘ inverse Σ-assoc) ⟩ (∃ λ c′ → ∃ λ xs′ → ∃ λ e′ → x ∈FV e × (c′ ≡ c × xs′ ≡ xs × e′ ≡ e) × ¬ x ∈ xs) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ (_ , xs′≡xs , _) → ≡⇒↝ _ $ cong (¬_ ∘ (_ ∈_)) $ sym xs′≡xs) ⟩ (∃ λ c′ → ∃ λ xs′ → ∃ λ e′ → x ∈FV e × (c′ ≡ c × xs′ ≡ xs × e′ ≡ e) × ¬ x ∈ xs′) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ×-cong₁ λ ((_ , _ , e′≡e) , _) → ≡⇒↝ _ $ cong (_ ∈FV_) $ sym e′≡e) ⟩ (∃ λ c′ → ∃ λ xs′ → ∃ λ e′ → x ∈FV e′ × (c′ ≡ c × xs′ ≡ xs × e′ ≡ e) × ¬ x ∈ xs′) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ×-cong₁ λ _ → lemma) ⟩□ (∃ λ c′ → ∃ λ xs′ → ∃ λ e′ → x ∈FV e′ × branch c′ xs′ e′ ≡ branch c xs e × ¬ x ∈ xs′) □) (free e) where lemma : c′ ≡ c × xs′ ≡ xs × e′ ≡ e ⇔ branch c′ xs′ e′ ≡ branch c xs e lemma ._⇔_.to (c′≡c , xs′≡xs , e′≡e) = cong₂ (uncurry branch) (cong₂ _,_ c′≡c xs′≡xs) e′≡e lemma ._⇔_.from eq = cong (λ { (branch c _ _) → c }) eq , cong (λ { (branch _ xs _) → xs }) eq , cong (λ { (branch _ _ e) → e }) eq free-B⋆ : (bs : List Br) → ∃ λ (fs : Finite-subset-of Var) → ∀ x → (x S.∈ fs) ⇔ (∃ λ c → ∃ λ xs → ∃ λ e → x ∈FV e × branch c xs e ∈ bs × ¬ x ∈ xs) free-B⋆ [] = S.[] , λ x → x S.∈ S.[] ↔⟨ S.∈[]≃ ⟩ ⊥ ↔⟨ (inverse $ ×-right-zero {ℓ₁ = lzero} F.∘ ∃-cong λ _ → ×-right-zero {ℓ₁ = lzero} F.∘ ∃-cong λ _ → ×-right-zero {ℓ₁ = lzero} F.∘ ∃-cong λ _ → ×-right-zero {ℓ₁ = lzero} F.∘ ∃-cong λ _ → ×-left-zero) ⟩ Const × (∃ λ xs → ∃ λ e → x ∈FV e × ⊥ × ¬ x ∈ xs) ↔⟨⟩ (∃ λ c → ∃ λ xs → ∃ λ e → x ∈FV e × branch c xs e ∈ [] × ¬ x ∈ xs) □ free-B⋆ (b ∷ bs) = Σ-zip S._∪_ (λ {fs₁ fs₂} hyp₁ hyp₂ x → x S.∈ fs₁ S.∪ fs₂ ↔⟨ S.∈∪≃ ⟩ x S.∈ fs₁ T.∥⊎∥ x S.∈ fs₂ ↝⟨ T.Dec→∥∥⇔ (Dec-⊎ (S.member? _≟V₁_ _ _) (S.member? _≟V₁_ _ _)) ⟩ x S.∈ fs₁ ⊎ x S.∈ fs₂ ↝⟨ hyp₁ x ⊎-cong hyp₂ x ⟩ (∃ λ c → ∃ λ xs → ∃ λ e → x ∈FV e × branch c xs e ≡ b × ¬ x ∈ xs) ⊎ (∃ λ c → ∃ λ xs → ∃ λ e → x ∈FV e × branch c xs e ∈ bs × ¬ x ∈ xs) ↔⟨ (inverse $ ∃-⊎-distrib-left F.∘ ∃-cong λ _ → ∃-⊎-distrib-left F.∘ ∃-cong λ _ → ∃-⊎-distrib-left F.∘ ∃-cong λ _ → ∃-⊎-distrib-left F.∘ ∃-cong λ _ → ∃-⊎-distrib-right) ⟩ (∃ λ c → ∃ λ xs → ∃ λ e → x ∈FV e × (branch c xs e ≡ b ⊎ branch c xs e ∈ bs) × ¬ x ∈ xs) ↔⟨⟩ (∃ λ c → ∃ λ xs → ∃ λ e → x ∈FV e × branch c xs e ∈ b ∷ bs × ¬ x ∈ xs) □) (free-B b) (free-B⋆ bs) -- It is possible to find a variable that is neither free in a given -- expression, nor a member of a given finite set. fresh′ : (xs : Finite-subset-of Var) (e : Exp) → ∃ λ (x : Var) → ¬ x ∈FV e × x S.∉ xs fresh′ xs e = Σ-map id (λ {x} → x S.∉ proj₁ (free e) S.∪ xs ↔⟨ ¬-cong ext S.∈∪≃ ⟩ ¬ (x S.∈ proj₁ (free e) T.∥⊎∥ x S.∈ xs) ↔⟨ T.¬∥∥↔¬ ⟩ ¬ (x S.∈ proj₁ (free e) ⊎ x S.∈ xs) ↝⟨ ¬⊎↔¬×¬ _ ⟩ x S.∉ proj₁ (free e) × x S.∉ xs ↔⟨ ¬-cong-⇔ ext (proj₂ (free e) x) ×-cong F.id ⟩□ ¬ x ∈FV e × x S.∉ xs □) (V.fresh (proj₁ (free e) S.∪ xs)) -- It is possible to find a variable that is not free in a given -- expression. fresh : (e : Exp) → ∃ λ (x : Var) → ¬ x ∈FV e fresh e = Σ-map id proj₁ (fresh′ S.[] e) -- If two expressions have the same free variables (ignoring any -- variables in xs), then fresh′ xs returns the same fresh variable -- for both expressions. fresh′-unique : (∀ x → x S.∉ xs → x ∈FV e₁ ⇔ x ∈FV e₂) → proj₁ (fresh′ xs e₁) ≡ proj₁ (fresh′ xs e₂) fresh′-unique {xs = xs} {e₁ = e₁} {e₂ = e₂} same = proj₁ (V.fresh (proj₁ (free e₁) S.∪ xs)) ≡⟨ (cong (proj₁ ∘ V.fresh) $ _≃_.from S.extensionality λ x → x S.∈ proj₁ (free e₁) S.∪ xs ↝⟨ lemma x e₁ ⟩ x S.∉ xs × x ∈FV e₁ T.∥⊎∥ x S.∈ xs ↝⟨ ∃-cong (same x) T.∥⊎∥-cong F.id ⟩ x S.∉ xs × x ∈FV e₂ T.∥⊎∥ x S.∈ xs ↝⟨ inverse $ lemma x e₂ ⟩□ x S.∈ proj₁ (free e₂) S.∪ xs □) ⟩∎ proj₁ (V.fresh (proj₁ (free e₂) S.∪ xs)) ∎ where lemma : ∀ _ _ → _ ⇔ _ lemma x e = x S.∈ proj₁ (free e) S.∪ xs ↔⟨ S.∈∪≃ ⟩ x S.∈ proj₁ (free e) T.∥⊎∥ x S.∈ xs ↝⟨ proj₂ (free e) x T.∥⊎∥-cong F.id ⟩ x ∈FV e T.∥⊎∥ x S.∈ xs ↔⟨ T.∥⊎∥≃¬×∥⊎∥ $ T.Dec→Dec-∥∥ $ S.member? _≟V₁_ x xs ⟩□ x S.∉ xs × x ∈FV e T.∥⊎∥ x S.∈ xs □ -- If two expressions have the same free variables, then fresh returns -- the same fresh variable for both expressions. fresh-unique : (∀ x → x ∈FV e₁ ⇔ x ∈FV e₂) → proj₁ (fresh e₁) ≡ proj₁ (fresh e₂) fresh-unique same = fresh′-unique (λ x _ → same x) ------------------------------------------------------------------------ -- Decision procedures -- These decision procedures could presumably be implemented using -- free. -- The free variable relation, _∈FV_, is decidable. mutual _∈?_ : ∀ x e → Dec (x ∈FV e) x ∈? apply e₁ e₂ with x ∈? e₁ x ∈? apply e₁ e₂ | yes x∈e₁ = yes (apply-left x∈e₁) x ∈? apply e₁ e₂ | no x∉e₁ = ⊎-map apply-right (λ x∉e₂ → λ { (apply-left x∈e₁) → x∉e₁ x∈e₁ ; (apply-right x∈e₂) → x∉e₂ x∈e₂ }) (x ∈? e₂) x ∈? lambda y e with x V.≟ y x ∈? lambda y e | yes x≡y = no (λ { (lambda x≢y _) → x≢y x≡y }) x ∈? lambda y e | no x≢y = ⊎-map (lambda x≢y) (λ x∉e → λ { (lambda _ x∈e) → x∉e x∈e }) (x ∈? e) x ∈? rec y e with x V.≟ y x ∈? rec y e | yes x≡y = no (λ { (rec x≢y _) → x≢y x≡y }) x ∈? rec y e | no x≢y = ⊎-map (rec x≢y) (λ x∉e → λ { (rec _ x∈e) → x∉e x∈e }) (x ∈? e) x ∈? var y with x V.≟ y x ∈? var y | yes x≡y = yes (var x≡y) x ∈? var y | no x≢y = no (λ { (var x≡y) → x≢y x≡y }) x ∈? const c es = ⊎-map (λ { (_ , e∈es , x∈e) → const x∈e e∈es }) (λ x∉es → λ { (const x∈e e∈es) → x∉es (_ , e∈es , x∈e) }) (x ∈?-⋆ es) x ∈? case e bs with x ∈? e x ∈? case e bs | yes x∈e = yes (case-head x∈e) x ∈? case e bs | no x∉e = ⊎-map (λ { (_ , _ , _ , xs→e∈bs , x∈e , x∉xs) → case-body x∈e xs→e∈bs x∉xs }) (λ x∉bs → λ { (case-head x∈e) → x∉e x∈e ; (case-body x∈e xs→e∈bs x∉xs) → x∉bs (_ , _ , _ , xs→e∈bs , x∈e , x∉xs) }) (x ∈?-B⋆ bs) _∈?-⋆_ : ∀ x es → Dec (∃ λ e → e ∈ es × x ∈FV e) x ∈?-⋆ [] = no (λ { (_ , () , _) }) x ∈?-⋆ (e ∷ es) with x ∈? e x ∈?-⋆ (e ∷ es) | yes x∈e = yes (_ , inj₁ refl , x∈e) x ∈?-⋆ (e ∷ es) | no x∉e = ⊎-map (Σ-map id (Σ-map inj₂ id)) (λ x∉es → λ { (_ , inj₁ refl , x∈e) → x∉e x∈e ; (_ , inj₂ e∈es , x∈e) → x∉es (_ , e∈es , x∈e) }) (x ∈?-⋆ es) _∈?-B⋆_ : ∀ x bs → Dec (∃ λ c → ∃ λ xs → ∃ λ e → branch c xs e ∈ bs × x ∈FV e × ¬ x ∈ xs) x ∈?-B⋆ [] = no λ { (_ , _ , _ , () , _) } x ∈?-B⋆ (branch c xs e ∷ bs) with x ∈?-B⋆ bs x ∈?-B⋆ (branch c xs e ∷ bs) | yes x∈bs = yes (Σ-map id (Σ-map id (Σ-map id (Σ-map inj₂ id))) x∈bs) x ∈?-B⋆ (branch c xs e ∷ bs) | no x∉bs with V.member x xs x ∈?-B⋆ (branch c xs e ∷ bs) | no x∉bs | yes x∈xs = no (λ { (_ , _ , _ , inj₁ refl , _ , x∉xs) → x∉xs x∈xs ; (_ , _ , _ , inj₂ e∈es , x∈e , x∉xs) → x∉bs (_ , _ , _ , e∈es , x∈e , x∉xs) }) x ∈?-B⋆ (branch c xs e ∷ bs) | no x∉bs | no x∉xs = ⊎-map (λ x∈e → _ , _ , _ , inj₁ refl , x∈e , x∉xs) (λ x∉e → λ { (_ , _ , _ , inj₁ refl , x∈e , _) → x∉e x∈e ; (_ , _ , _ , inj₂ e∈es , x∈e , x∉xs) → x∉bs (_ , _ , _ , e∈es , x∈e , x∉xs) }) (x ∈? e) -- The Closed′ relation is decidable. mutual closed′? : ∀ e xs → Dec (Closed′ xs e) closed′? (apply e₁ e₂) xs with closed′? e₁ xs closed′? (apply e₁ e₂) xs | no ¬cl₁ = no (¬cl₁ ∘ (λ cl₁ x x∉xs → cl₁ x x∉xs ∘ apply-left)) closed′? (apply e₁ e₂) xs | yes cl₁ = ⊎-map (Closed′-closed-under-apply cl₁) (_∘ (λ cl₂ x x∉xs → cl₂ x x∉xs ∘ apply-right)) (closed′? e₂ xs) closed′? (lambda x e) xs = ⊎-map Closed′-closed-under-lambda (λ ¬cl cl → ¬cl (λ y y∉x∷xs y∈e → cl y (y∉x∷xs ∘ inj₂) (lambda (y∉x∷xs ∘ inj₁) y∈e))) (closed′? e (x ∷ xs)) closed′? (rec x e) xs = ⊎-map Closed′-closed-under-rec (λ ¬cl cl → ¬cl (λ y y∉x∷xs y∈e → cl y (y∉x∷xs ∘ inj₂) (rec (y∉x∷xs ∘ inj₁) y∈e))) (closed′? e (x ∷ xs)) closed′? (var x) xs = ⊎-map Closed′-closed-under-var (λ x∉xs cl → cl x x∉xs (var refl)) (V.member x xs) closed′? (const c es) xs = ⊎-map Closed′-closed-under-const (λ ¬cl cl → ¬cl (λ _ e∈es x x∉xs x∈e → cl x x∉xs (const x∈e e∈es))) (closed′?-⋆ es xs) closed′? (case e bs) xs with closed′? e xs closed′? (case e bs) xs | no ¬cl-e = no (λ cl → ¬cl-e (λ x x∉xs → cl x x∉xs ∘ case-head)) closed′? (case e bs) xs | yes cl-e = ⊎-map (Closed′-closed-under-case cl-e) (λ ¬cl-bs cl → ¬cl-bs (λ b∈bs x x∉ys++xs x∈e → let ¬[x∈ys⊎x∈xs] = x∉ys++xs ∘ _↔_.from (B.Any-++ _ _ _) in cl x (¬[x∈ys⊎x∈xs] ∘ inj₂) (case-body x∈e b∈bs (¬[x∈ys⊎x∈xs] ∘ inj₁)))) (closed′?-B⋆ bs xs) closed′?-⋆ : ∀ es xs → Dec (∀ e → e ∈ es → Closed′ xs e) closed′?-⋆ [] xs = yes (λ _ ()) closed′?-⋆ (e ∷ es) xs with closed′? e xs closed′?-⋆ (e ∷ es) xs | no ¬cl-e = no (λ cl → ¬cl-e (cl _ (inj₁ refl))) closed′?-⋆ (e ∷ es) xs | yes cl-e = ⊎-map (λ cl-es e → [ (λ e′≡e x x∉xs → subst (λ e → ¬ x ∈FV e) (sym e′≡e) (cl-e x x∉xs)) , cl-es e ]) (λ ¬cl-es cl → ¬cl-es (λ e → cl e ∘ inj₂)) (closed′?-⋆ es xs) closed′?-B⋆ : ∀ bs xs → Dec (∀ {c ys e} → branch c ys e ∈ bs → Closed′ (ys ++ xs) e) closed′?-B⋆ [] xs = yes (λ ()) closed′?-B⋆ (branch c ys e ∷ bs) xs with closed′?-B⋆ bs xs closed′?-B⋆ (branch c ys e ∷ bs) xs | no ¬cl-bs = no (λ cl → ¬cl-bs (cl ∘ inj₂)) closed′?-B⋆ (branch c ys e ∷ bs) xs | yes cl-bs = ⊎-map (λ cl-e {c′} {ys′} {e′} → [ (λ b′≡b x x∉ys++xs′ x∈e′ → cl-e x (subst (λ ys → ¬ x ∈ ys ++ xs) (ys-lemma b′≡b) x∉ys++xs′) (subst (x ∈FV_) (e-lemma b′≡b) x∈e′)) , cl-bs ]) (λ ¬cl-e cl → ¬cl-e (cl (inj₁ refl))) (closed′? e (ys ++ xs)) where e-lemma : ∀ {c ys e c′ ys′ e′} → branch c ys e ≡ branch c′ ys′ e′ → e ≡ e′ e-lemma refl = refl ys-lemma : ∀ {c ys e c′ ys′ e′} → branch c ys e ≡ branch c′ ys′ e′ → ys ≡ ys′ ys-lemma refl = refl -- The Closed relation is decidable. closed? : ∀ e → Dec (Closed e) closed? e = closed′? e [] ------------------------------------------------------------------------ -- Substituting something for a variable that is not free -- If x is not free in e, then nothing happens when a term is -- substituted for x in e. mutual subst-∉ : ∀ x e {e′} → ¬ x ∈FV e → e [ x ← e′ ] ≡ e subst-∉ x (apply e₁ e₂) x∉ = cong₂ apply (subst-∉ x e₁ (x∉ ∘ apply-left)) (subst-∉ x e₂ (x∉ ∘ apply-right)) subst-∉ x (lambda y e) x∉ with x V.≟ y subst-∉ x (lambda y e) x∉ | yes _ = refl subst-∉ x (lambda y e) x∉ | no x≢y = cong (lambda y) (subst-∉ x e (x∉ ∘ lambda x≢y)) subst-∉ x (case e bs) x∉ = cong₂ case (subst-∉ x e (x∉ ∘ case-head)) (subst-∉-B⋆ x bs _ (λ { (_ , _ , _ , ∈bs , x∈ , x∉xs) → x∉ (case-body x∈ ∈bs x∉xs) })) subst-∉ x (rec y e) x∉ with x V.≟ y subst-∉ x (rec y e) x∉ | yes _ = refl subst-∉ x (rec y e) x∉ | no x≢y = cong (rec y) (subst-∉ x e (x∉ ∘ rec x≢y)) subst-∉ x (var y) x∉ with x V.≟ y subst-∉ x (var y) x∉ | yes x≡y = ⊥-elim (x∉ (var x≡y)) subst-∉ x (var y) x∉ | no _ = refl subst-∉ x (const c es) x∉ = cong (const c) (subst-∉-⋆ x es (x∉ ∘ (λ { (_ , ps , p) → const p ps }))) subst-∉-⋆ : ∀ x es {e′} → ¬ (∃ λ e → e ∈ es × x ∈FV e) → es [ x ← e′ ]⋆ ≡ es subst-∉-⋆ x [] x∉ = refl subst-∉-⋆ x (e ∷ es) x∉ = cong₂ _∷_ (subst-∉ x e (λ x∈ → x∉ (_ , inj₁ refl , x∈))) (subst-∉-⋆ x es (x∉ ∘ Σ-map id (Σ-map inj₂ id))) subst-∉-B⋆ : ∀ x bs e′ → ¬ (∃ λ c → ∃ λ xs → ∃ λ e → branch c xs e ∈ bs × x ∈FV e × ¬ x ∈ xs) → bs [ x ← e′ ]B⋆ ≡ bs subst-∉-B⋆ x [] _ x∉ = refl subst-∉-B⋆ x (branch c xs e ∷ bs) _ x∉ with V.member x xs | subst-∉-B⋆ x bs _ (x∉ ∘ Σ-map id (Σ-map id (Σ-map id (Σ-map inj₂ id)))) ... | yes x∈xs | eq = cong₂ _∷_ refl eq ... | no x∉xs | eq = cong₂ (λ e bs → branch c xs e ∷ bs) (subst-∉ x e λ x∈e → x∉ (_ , _ , _ , inj₁ refl , x∈e , x∉xs)) eq -- If e is closed, then nothing happens when a term is substituted for -- x in e. subst-closed : ∀ x e′ {e} → Closed e → e [ x ← e′ ] ≡ e subst-closed _ _ c = subst-∉ _ _ (c _ (λ ())) -- An n-ary variant of the previous lemma. substs-closed : ∀ e → Closed e → ∀ ps → foldr (λ ye → _[ proj₁ ye ← proj₂ ye ]) e ps ≡ e substs-closed e cl [] = refl substs-closed e cl ((y , e′) ∷ ps) = foldr (λ { (y , e) → _[ y ← e ] }) e ps [ y ← e′ ] ≡⟨ cong _[ y ← e′ ] (substs-closed e cl ps) ⟩ e [ y ← e′ ] ≡⟨ subst-closed _ _ cl ⟩∎ e ∎ ------------------------------------------------------------------------ -- Evaluation and free variables -- If a value contains a free variable, then every term that evaluates -- to this value also contains the given free variable. mutual ⇓-does-not-introduce-variables : ∀ {x v e} → e ⇓ v → x ∈FV v → x ∈FV e ⇓-does-not-introduce-variables lambda q = q ⇓-does-not-introduce-variables (const ps) (const x∈v v∈vs) with ⇓⋆-does-not-introduce-variables ps (_ , v∈vs , x∈v) ... | _ , e∈es , x∈e = const x∈e e∈es ⇓-does-not-introduce-variables (apply {e = e} p₁ p₂ p₃) q with subst-∈FV _ e (⇓-does-not-introduce-variables p₃ q) ... | inj₂ x∈v₂ = apply-right (⇓-does-not-introduce-variables p₂ x∈v₂) ... | inj₁ (x∈e , x≢x′) = apply-left (⇓-does-not-introduce-variables p₁ (lambda x≢x′ x∈e)) ⇓-does-not-introduce-variables (rec {e = e} p) q with subst-∈FV _ e (⇓-does-not-introduce-variables p q) ... | inj₂ x∈rec = x∈rec ... | inj₁ (x∈e , x≢x′) = rec x≢x′ x∈e ⇓-does-not-introduce-variables {x} {w} (case {e = e} {bs = bs} {c = c} {es = es} {xs = xs} {e′ = e′} {e″ = e″} p₁ p₂ p₃ p₄) = x ∈FV w ↝⟨ ⇓-does-not-introduce-variables p₄ ⟩ x ∈FV e″ ↝⟨ lemma₁ p₃ ⟩ (x ∈FV e′ × ¬ x ∈ xs) ⊎ ∃ (λ e″₁ → e″₁ ∈ es × x ∈FV e″₁) ↝⟨ ⊎-map id (λ { (_ , ps , p) → const p ps }) ⟩ (x ∈FV e′ × ¬ x ∈ xs) ⊎ x ∈FV const c es ↝⟨ ⊎-map (λ p → lemma₂ p₂ , p) (⇓-does-not-introduce-variables p₁) ⟩ (branch c xs e′ ∈ bs × x ∈FV e′ × ¬ x ∈ xs) ⊎ x ∈FV e ↝⟨ [ (λ { (ps , p , q) → case-body p ps q }) , case-head ] ⟩ x ∈FV case e bs □ where lemma₁ : ∀ {e e′ x xs es} → e [ xs ← es ]↦ e′ → x ∈FV e′ → (x ∈FV e × ¬ x ∈ xs) ⊎ ∃ λ e″ → e″ ∈ es × x ∈FV e″ lemma₁ {e′ = e′} {x} [] = x ∈FV e′ ↝⟨ (λ p → inj₁ (p , (λ ()))) ⟩□ x ∈FV e′ × ¬ x ∈ [] ⊎ _ □ lemma₁ {e} {x = x} (∷_ {x = y} {xs = ys} {e′ = e′} {es′ = es′} {e″ = e″} p) = x ∈FV e″ [ y ← e′ ] ↝⟨ subst-∈FV _ _ ⟩ x ∈FV e″ × x ≢ y ⊎ x ∈FV e′ ↝⟨ ⊎-map (Σ-map (lemma₁ p) id) id ⟩ (x ∈FV e × ¬ x ∈ ys ⊎ ∃ λ e‴ → e‴ ∈ es′ × x ∈FV e‴) × x ≢ y ⊎ x ∈FV e′ ↝⟨ [ uncurry (λ p x≢y → ⊎-map (Σ-map id (λ x∉ys → [ x≢y , x∉ys ])) (Σ-map id (Σ-map inj₂ id)) p) , (λ p → inj₂ (_ , inj₁ refl , p)) ] ⟩□ x ∈FV e × ¬ x ∈ y ∷ ys ⊎ (∃ λ e″ → e″ ∈ e′ ∷ es′ × x ∈FV e″) □ lemma₂ : ∀ {c bs xs e} → Lookup c bs xs e → branch c xs e ∈ bs lemma₂ here = inj₁ refl lemma₂ (there _ p) = inj₂ (lemma₂ p) ⇓⋆-does-not-introduce-variables : ∀ {x es vs} → es ⇓⋆ vs → (∃ λ v → v ∈ vs × x ∈FV v) → (∃ λ e → e ∈ es × x ∈FV e) ⇓⋆-does-not-introduce-variables [] = id ⇓⋆-does-not-introduce-variables (p ∷ ps) (v , inj₁ refl , q) = _ , inj₁ refl , ⇓-does-not-introduce-variables p q ⇓⋆-does-not-introduce-variables (p ∷ ps) (v , inj₂ v∈ , q) = Σ-map id (Σ-map inj₂ id) (⇓⋆-does-not-introduce-variables ps (v , v∈ , q)) -- A closed term's value is closed. closed⇓closed : ∀ {e v xs} → e ⇓ v → Closed′ xs e → Closed′ xs v closed⇓closed {e} {v} {xs} p q x x∉xs = x ∈FV v ↝⟨ ⇓-does-not-introduce-variables p ⟩ x ∈FV e ↝⟨ q x x∉xs ⟩□ ⊥ □ ------------------------------------------------------------------------ -- More properties -- A constructor for closed expressions. apply-cl : Closed-exp → Closed-exp → Closed-exp apply-cl (e₁ , cl-e₁) (e₂ , cl-e₂) = apply e₁ e₂ , (Closed′-closed-under-apply (Closed→Closed′ cl-e₁) (Closed→Closed′ cl-e₂)) -- A certain "swapping" lemma does not hold. no-swapping : ¬ (∀ x y e e′ e″ → x ≢ y → Closed e′ → Closed (e″ [ x ← e′ ]) → e [ x ← e′ ] [ y ← e″ [ x ← e′ ] ] ≡ e [ y ← e″ ] [ x ← e′ ]) no-swapping hyp = distinct (hyp x′ y′ e₁′ e₂′ e₃′ x≢y cl₁ cl₂) where x′ = V.name 0 y′ = V.name 1 e₁′ : Exp e₁′ = lambda x′ (var y′) e₂′ : Exp e₂′ = const (C.name 0) [] e₃′ : Exp e₃′ = var x′ x≢y : x′ ≢ y′ x≢y = V.distinct-codes→distinct-names (λ ()) cl₁ : Closed e₂′ cl₁ = from-⊎ (closed? e₂′) cl₂ : Closed (e₃′ [ x′ ← e₂′ ]) cl₂ with x′ V.≟ x′ ... | no x≢x = ⊥-elim (x≢x refl) ... | yes _ = cl₁ lhs : e₁′ [ x′ ← e₂′ ] [ y′ ← e₃′ [ x′ ← e₂′ ] ] ≡ lambda x′ e₂′ lhs with x′ V.≟ x′ ... | no x≢x = ⊥-elim (x≢x refl) ... | yes _ with y′ V.≟ x′ ... | yes y≡x = ⊥-elim (x≢y (sym y≡x)) ... | no _ with y′ V.≟ y′ ... | no y≢y = ⊥-elim (y≢y refl) ... | yes _ = refl rhs : e₁′ [ y′ ← e₃′ ] [ x′ ← e₂′ ] ≡ lambda x′ (var x′) rhs with y′ V.≟ x′ ... | yes y≡x = ⊥-elim (x≢y (sym y≡x)) ... | no _ with y′ V.≟ y′ ... | no y≢y = ⊥-elim (y≢y refl) ... | yes _ with x′ V.≟ x′ ... | no x≢x = ⊥-elim (x≢x refl) ... | yes _ = refl distinct : e₁′ [ x′ ← e₂′ ] [ y′ ← e₃′ [ x′ ← e₂′ ] ] ≢ e₁′ [ y′ ← e₃′ ] [ x′ ← e₂′ ] distinct rewrite lhs | rhs = λ () -- Another swapping lemma does hold. module _ (x≢y : x ≢ y) (x∉e″ : ¬ x ∈FV e″) (y∉e′ : ¬ y ∈FV e′) where mutual swap : ∀ e → e [ x ← e′ ] [ y ← e″ ] ≡ e [ y ← e″ ] [ x ← e′ ] swap (apply e₁ e₂) = cong₂ apply (swap e₁) (swap e₂) swap (lambda z e) with x V.≟ z | y V.≟ z … | yes _ | yes _ = refl … | yes _ | no _ = refl … | no _ | yes _ = refl … | no _ | no _ = cong (lambda z) (swap e) swap (case e bs) = cong₂ case (swap e) (swap-B⋆ bs) swap (rec z e) with x V.≟ z | y V.≟ z … | yes _ | yes _ = refl … | yes _ | no _ = refl … | no _ | yes _ = refl … | no _ | no _ = cong (rec z) (swap e) swap (var z) with x V.≟ z | y V.≟ z … | yes x≡z | yes y≡z = ⊥-elim $ x≢y (trans x≡z (sym y≡z)) … | yes x≡z | no _ = e′ [ y ← e″ ] ≡⟨ subst-∉ _ _ y∉e′ ⟩ e′ ≡⟨ sym $ var-step-≡ x≡z ⟩∎ var z [ x ← e′ ] ∎ … | no _ | yes y≡z = var z [ y ← e″ ] ≡⟨ var-step-≡ y≡z ⟩ e″ ≡⟨ sym $ subst-∉ _ _ x∉e″ ⟩∎ e″ [ x ← e′ ] ∎ … | no x≢z | no y≢z = var z [ y ← e″ ] ≡⟨ var-step-≢ y≢z ⟩ var z ≡⟨ sym $ var-step-≢ x≢z ⟩∎ var z [ x ← e′ ] ∎ swap (const c es) = cong (const c) (swap-⋆ es) swap-B : ∀ b → b [ x ← e′ ]B [ y ← e″ ]B ≡ b [ y ← e″ ]B [ x ← e′ ]B swap-B (branch c zs e) with V.member x zs | V.member y zs … | yes x∈zs | yes y∈zs = branch c zs e [ y ← e″ ]B ≡⟨ branch-step-∈ y∈zs ⟩ branch c zs e ≡⟨ sym $ branch-step-∈ x∈zs ⟩∎ branch c zs e [ x ← e′ ]B ∎ … | yes x∈zs | no y∉zs = branch c zs e [ y ← e″ ]B ≡⟨ branch-step-∉ y∉zs ⟩ branch c zs (e [ y ← e″ ]) ≡⟨ sym $ branch-step-∈ x∈zs ⟩∎ branch c zs (e [ y ← e″ ]) [ x ← e′ ]B ∎ … | no x∉zs | yes y∈zs = branch c zs (e [ x ← e′ ]) [ y ← e″ ]B ≡⟨ branch-step-∈ y∈zs ⟩ branch c zs (e [ x ← e′ ]) ≡⟨ sym $ branch-step-∉ x∉zs ⟩∎ branch c zs e [ x ← e′ ]B ∎ … | no x∉zs | no y∉zs = branch c zs (e [ x ← e′ ]) [ y ← e″ ]B ≡⟨ branch-step-∉ y∉zs ⟩ branch c zs (e [ x ← e′ ] [ y ← e″ ]) ≡⟨ cong (branch c zs) (swap e) ⟩ branch c zs (e [ y ← e″ ] [ x ← e′ ]) ≡⟨ sym $ branch-step-∉ x∉zs ⟩∎ branch c zs (e [ y ← e″ ]) [ x ← e′ ]B ∎ swap-⋆ : ∀ es → es [ x ← e′ ]⋆ [ y ← e″ ]⋆ ≡ es [ y ← e″ ]⋆ [ x ← e′ ]⋆ swap-⋆ [] = refl swap-⋆ (e ∷ es) = cong₂ _∷_ (swap e) (swap-⋆ es) swap-B⋆ : ∀ bs → bs [ x ← e′ ]B⋆ [ y ← e″ ]B⋆ ≡ bs [ y ← e″ ]B⋆ [ x ← e′ ]B⋆ swap-B⋆ [] = refl swap-B⋆ (b ∷ bs) = cong₂ _∷_ (swap-B b) (swap-B⋆ bs)
{ "alphanum_fraction": 0.3470091065, "avg_line_length": 43.9433164129, "ext": "agda", "hexsha": "4bb75b4d076fe4863b3a86e85da3d6a465d6643e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/chi", "max_forks_repo_path": "src/Free-variables.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z", "max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/chi", "max_issues_repo_path": "src/Free-variables.agda", "max_line_length": 140, "max_stars_count": 2, "max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/chi", "max_stars_repo_path": "src/Free-variables.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z", "num_tokens": 19587, "size": 51941 }
{-# OPTIONS --cubical --safe #-} module README where -------------------------------------------------------------------------------- -- Section 1: Introduction -------------------------------------------------------------------------------- -- 0, 1, and 2 types import Data.Empty using (⊥) import Data.Unit using (⊤) import Data.Bool using (Bool) -- Dependent Sum and Product import Data.Sigma using (Σ) import Data.Pi using (Π) -- Disjoint Union import Data.Sum using (_⊎_) import Data.Sum.Properties using (sumAsSigma) -- Definition 1: Path types import Path using (_≡_) -- Definition 2: Homotopy Levels import HLevels using (isContr; isProp; isSet) -- Definition 3: Fibres import Function.Fiber using (fiber) -- Definition 4: Equivalences import Equiv using (isEquiv; _≃_) -- Definition 5: Decidable import Relation.Nullary.Decidable using (Dec) -- Definition 6: Discrete import Relation.Nullary.Discrete using (Discrete) import Relation.Nullary.Discrete.Properties using (Discrete→isSet) -- Definition 8: Propositional Truncation import HITs.PropositionalTruncation using (∥_∥) import HITs.PropositionalTruncation using (rec; rec→set) -------------------------------------------------------------------------------- -- Section 2: Finiteness Predicates -------------------------------------------------------------------------------- -- Definition 9: Split Enumerability import Cardinality.Finite.SplitEnumerable.Container using (ℰ!) -- Container based definition is isomophic to inductive import Cardinality.Finite.SplitEnumerable.Isomorphism using (𝕃⇔ℒ⟨ℰ!⟩) -- Definition 10: Container import Container using (Container; ⟦_⟧) -- Definition 11: List import Container.List using (List) -- Definition 12: Fin import Data.Fin.Base using (Fin) -- Definition 13: Surjections import Function.Surjective using (_↠!_; _↠_) -- Lemma 1 import Cardinality.Finite.SplitEnumerable using (ℰ!⇔Fin↠!) -- Lemma 2 import Function.Surjective.Properties using (Discrete-distrib-surj) -- Lemma 3 import Cardinality.Finite.SplitEnumerable using (ℰ!⇒Discrete) -- Definition 14: Manifest Bishop Finiteness import Cardinality.Finite.ManifestBishop.Container using (ℬ) -- Container based definition is isomophic to inductive import Cardinality.Finite.ManifestBishop.Isomorphism using (𝕃⇔ℒ⟨ℬ⟩) -- Definition 15: Unique Membership import Container.Membership using (_∈!_) -- Lemma 4 import Cardinality.Finite.ManifestBishop using (ℬ⇔Fin≃) -- Definition 16: Cardinal Finiteness import Cardinality.Finite.Cardinal using (𝒞; 𝒞≃Fin≃) -- Lemma 5 import Cardinality.Finite.Cardinal using (cardinality) -- Lemma 6 import Cardinality.Finite.Cardinal using (𝒞⇒Discrete) -- Definition 17: Manifest Enumerability import Cardinality.Finite.ManifestEnumerable.Container using (ℰ) -- Container based definition is isomorphic to inductive import Cardinality.Finite.ManifestEnumerable.Isomorphism using (𝕃⇔ℒ⟨ℰ⟩) -- Lemma 7 import Cardinality.Finite.ManifestEnumerable using (ℰ⇔Fin↠) -- Definition 18: S¹ open import Cubical.HITs.S1 using (S¹) -- Lemma 8 import Cardinality.Finite.ManifestEnumerable using (ℰ⟨S¹⟩) -- Definition 19: Kuratowski finite subset import Algebra.Construct.Free.Semilattice using (𝒦) -- Definition 20: Membership of 𝒦 import Algebra.Construct.Free.Semilattice.Relation.Unary using (_∈_) -- Definition 21: Kuratowski finiteness import Cardinality.Finite.Kuratowski using (𝒦ᶠ) -- Lemma 9 import Cardinality.Finite.Kuratowski using (isProp𝒦ᶠ) -- Lemma 10 import Cardinality.Finite.Kuratowski using (𝒦ᶠ⟨S¹⟩) -------------------------------------------------------------------------------- -- Section 3: Relations Between Each Finiteness Definition -------------------------------------------------------------------------------- -- Lemma 11 import Cardinality.Finite.ManifestBishop using (ℰ!⇒ℬ) -- Lemma 12 import Cardinality.Finite.ManifestBishop using (ℬ⇒ℰ!) -- Lemma 13 import Cardinality.Finite.ManifestEnumerable using (ℰ!⇒ℰ) -- Lemma 14 import Cardinality.Finite.ManifestEnumerable using (ℰ⇒ℰ!) -- Lemma 15 import Cardinality.Finite.Cardinal using (ℬ⇒𝒞) -- Theorem 1 import Cardinality.Finite.Cardinal using (𝒞⇒ℬ) -- Definition 22: List Permutations import Data.List.Relation.Binary.Permutation using (_↭_) -- Lemma 16 import Cardinality.Finite.Kuratowski using (𝒞⇔𝒦×Discrete) -------------------------------------------------------------------------------- -- Section 4: Relations Between Each Finiteness Definition -------------------------------------------------------------------------------- -- Lemma 17 import Cardinality.Finite.SplitEnumerable using (ℰ!⟨⊥⟩; ℰ!⟨⊤⟩; ℰ!⟨2⟩) -- Lemma 18 import Cardinality.Finite.SplitEnumerable using (_|Σ|_) -- Lemma 19 import Cardinality.Finite.ManifestBishop using (_|Π|_) -- Lemma 20 import Cardinality.Finite.Cardinal using (𝒞⇒Choice) -- Resulting closures on 𝒞: import Cardinality.Finite.Cardinal using (_∥Σ∥_; _∥⊎∥_; _∥Π∥_; _∥→∥_; _∥×∥_; _∥⇔∥_; 𝒞⟨⊥⟩; 𝒞⟨⊤⟩; 𝒞⟨Bool⟩) -- Theorem 2: import Cardinality.Finite.Cardinal.Category using (finSetCategory) -- Quotients are effective import Cubical.HITs.SetQuotients.Properties using (isEquivRel→isEffective) -- Theorem 3: import Cardinality.Finite.Cardinal.Category using ( finSetHasProducts ; finSetHasExp ; finSetHasPullbacks ; finSetTerminal ; finSetInitial ; finSetCoeq ; module PullbackSurjProofs ) -- Same for hSets import Categories.HSets using ( hSetProd ; hSetExp ; hSetHasPullbacks ; hSetTerminal ; hSetInitial ; hSetCoeq ; module PullbackSurjProofs ) -------------------------------------------------------------------------------- -- Section 5: Countably Infinite Types -------------------------------------------------------------------------------- -- Definition 23: Streams import Codata.Stream using (Stream) -- Definition 24: Split Countability import Cardinality.Infinite.Split using (ℰ!) -- Definition 25: Countability import Cardinality.Infinite.Split using (ℰ) -- Lemma 21 import Cardinality.Infinite.Split using (ℰ⇒Discrete) -- Theorem 4 import Cardinality.Infinite.Split using (_|Σ|_) -- Theorem 5 import Cardinality.Infinite.Split using (|star|) -------------------------------------------------------------------------------- -- Section 6: Search -------------------------------------------------------------------------------- -- Definition 26: Omniscience import Relation.Nullary.Omniscience using (Omniscient) -- Definition 27: Exhaustibility import Relation.Nullary.Omniscience using (Exhaustible) import Cardinality.Finite.Kuratowski using (𝒦ᶠ⇒Exhaustible) import Relation.Nullary.Omniscience using (Omniscient→Exhaustible) import Cardinality.Finite.ManifestEnumerable using (ℰ⇒Omniscient) import Cardinality.Finite.Kuratowski using (𝒦ᶠ⇒Prop-Omniscient) import Data.Pauli using (Pauli) import Data.Pauli using (assoc-·) import Data.Pauli using (not-spec)
{ "alphanum_fraction": 0.6608910891, "avg_line_length": 28.2633744856, "ext": "agda", "hexsha": "154c0d6f583f885bfbb0f5efbdfd06b75a832f41", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/README.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_path": "agda/README.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/README.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1857, "size": 6868 }
-- 2010-10-14 -- {-# OPTIONS -v term:20 #-} module FakeProjectionsDoNotPreserveGuardedness where import Common.Level open import Common.Coinduction -- Products infixr 4 _,_ infixr 2 _×_ -- fake product with projections postulate _×_ : (A B : Set) → Set _,_ : {A B : Set}(a : A)(b : B) → A × B proj₁ : {A B : Set}(p : A × B) → A proj₂ : {A B : Set}(p : A × B) → B -- Streams infixr 5 _∷_ data Stream (A : Set) : Set where _∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A mutual repeat : {A : Set}(a : A) → Stream A repeat a = a ∷ proj₂ (repeat' a) repeat' : {A : Set}(a : A) → A × ∞ (Stream A) repeat' a = a , ♯ repeat a
{ "alphanum_fraction": 0.56394453, "avg_line_length": 18.5428571429, "ext": "agda", "hexsha": "68fbd9d58936063f1be3f7518fd5b30b2f59e443", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/FakeProjectionsDoNotPreserveGuardedness.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/FakeProjectionsDoNotPreserveGuardedness.agda", "max_line_length": 52, "max_stars_count": 3, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/FakeProjectionsDoNotPreserveGuardedness.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 261, "size": 649 }
-- Export only the experiments that are expected to compile (without -- any holes) module Cubical.Experiments.Everything where open import Cubical.Experiments.Brunerie public open import Cubical.Experiments.EscardoSIP public open import Cubical.Experiments.Generic public open import Cubical.Experiments.NatMinusTwo open import Cubical.Experiments.IsoInt open import Cubical.Experiments.HAEquivInt open import Cubical.Experiments.Problem open import Cubical.Experiments.FunExtFromUA public open import Cubical.Experiments.HoTT-UF open import Cubical.Experiments.ZCohomologyOld.Base open import Cubical.Experiments.ZCohomologyOld.KcompPrelims open import Cubical.Experiments.ZCohomologyOld.Properties
{ "alphanum_fraction": 0.8659058488, "avg_line_length": 41.2352941176, "ext": "agda", "hexsha": "570538491bd225e206048cb645be0f39e33f0fcf", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "707825882556937ebcf15a53eac63f0afc4d0cfe", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "XiaohuWang0921/cubical", "max_forks_repo_path": "Cubical/Experiments/Everything.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "707825882556937ebcf15a53eac63f0afc4d0cfe", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "XiaohuWang0921/cubical", "max_issues_repo_path": "Cubical/Experiments/Everything.agda", "max_line_length": 68, "max_stars_count": null, "max_stars_repo_head_hexsha": "707825882556937ebcf15a53eac63f0afc4d0cfe", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "XiaohuWang0921/cubical", "max_stars_repo_path": "Cubical/Experiments/Everything.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 172, "size": 701 }
module StreamEnc where open import Data.Unit hiding (_≤_) open import Data.Nat open import Data.Product open import Data.Sum open import Relation.Binary.PropositionalEquality as P open ≡-Reasoning ≤-step : ∀{k n} → k ≤ n → k ≤ suc n ≤-step z≤n = z≤n ≤-step (s≤s p) = s≤s (≤-step p) pred-≤ : ∀{k n} → suc k ≤ n → k ≤ n pred-≤ (s≤s p) = ≤-step p Str : Set → Set Str A = ℕ → A hd : ∀{A} → Str A → A hd s = s 0 tl : ∀{A} → Str A → Str A tl s n = s (suc n) _ω : ∀{A} → A → Str A (a ω) n = a _∷_ : ∀{A} → A → Str A → Str A (a ∷ s) 0 = a (a ∷ s) (suc n) = s n module Mealy (A B : Set) where M : Set → Set M X = A → B × X M₁ : {X Y : Set} → (X → Y) → M X → M Y M₁ f g a = let (b , x) = g a in (b , f x) 𝓜 : Set 𝓜 = Str A → Str B d : 𝓜 → M 𝓜 d f a = (f (a ω) 0 , (λ s n → f (a ∷ s) (suc n))) corec : ∀{X} → (c : X → M X) → X → 𝓜 corec c x s zero = proj₁ (c x (hd s)) corec c x s (suc n) = corec c (proj₂ (c x (hd s))) (tl s) n compute' : ∀{X} (c : X → M X) (x : X) → ∀ a → d (corec c x) a ≡ M₁ (corec c) (c x) a compute' c x a = begin d (corec c x) a ≡⟨ refl ⟩ ((corec c x) (a ω) 0 , λ s n → (corec c x) (a ∷ s) (suc n)) ≡⟨ refl ⟩ (proj₁ (c x (hd (a ω))) , λ s n → corec c (proj₂ (c x (hd (a ∷ s)))) (tl (a ∷ s)) n) ≡⟨ refl ⟩ (proj₁ (c x a) , λ s n → corec c (proj₂ (c x a)) (λ n → s n) n) ≡⟨ refl ⟩ (proj₁ (c x a) , λ s n → corec c (proj₂ (c x a)) s n) ≡⟨ refl ⟩ (proj₁ (c x a) , λ s → corec c (proj₂ (c x a)) s) ≡⟨ refl ⟩ (proj₁ (c x a) , corec c (proj₂ (c x a))) ≡⟨ refl ⟩ M₁ (corec c) (c x) a ∎ compute : ∀{X} (c : X → M X) (x : X) → d (corec c x) ≡ M₁ (corec c) (c x) compute c x = begin d (corec c x) ≡⟨ refl ⟩ (λ a → d (corec c x) a) ≡⟨ refl ⟩ -- Same as in compute' (λ a → M₁ (corec c) (c x) a) ≡⟨ refl ⟩ M₁ (corec c) (c x) ∎ module MealyT (A B : Set) (a₀ : A) where M : Set → Set M X = ⊤ ⊎ (A → B × X) M₁ : {X Y : Set} → (X → Y) → M X → M Y M₁ f (inj₁ x) = inj₁ x M₁ f (inj₂ g) = inj₂ (λ a → let (b , x) = g a in (b , f x)) Mono : (Str A → Str (⊤ ⊎ B)) → Set -- Mono f = ∀ n → (∃ λ s → ∃ λ b → f s n ≡ inj₂ b) → -- ∀ s → ∀ k → k ≤ n → (∃ λ b → f s k ≡ inj₂ b) Mono f = ∀ n → ∀ s₁ b₁ → f s₁ n ≡ inj₂ b₁ → ∀ s → ∀ k → k ≤ n → (∃ λ b → f s k ≡ inj₂ b) 𝓜₁ : Set 𝓜₁ = Str A → Str (⊤ ⊎ B) 𝓜 : Set 𝓜 = Σ[ f ∈ 𝓜₁ ] (Mono f) d : 𝓜 → M 𝓜 d (f , m) = F (f (a₀ ω) 0) refl where F : (u : ⊤ ⊎ B) → (f (a₀ ω) 0) ≡ u → M 𝓜 F (inj₁ tt) _ = inj₁ tt F (inj₂ b) p = inj₂ (λ a → let (b' , p') = m 0 (a₀ ω) b p (a ω) 0 z≤n f' = λ s n → f (a ∷ s) (suc n) m' : Mono f' m' = λ {n s₁ b₁ p₁ s k k≤n → m (suc n) (a ∷ s₁) b₁ p₁ (a ∷ s) (suc k) (s≤s k≤n)} in b' , f' , m') corec₁ : ∀{X} → (c : X → M X) → X → 𝓜₁ corec₁ c x s n with c x corec₁ c x s n | inj₁ tt = inj₁ tt corec₁ c x s zero | inj₂ g = inj₂ (proj₁ (g (hd s))) corec₁ c x s (suc n) | inj₂ g = corec₁ c (proj₂ (g (hd s))) (tl s) n corec₂ : ∀{X} → (c : X → M X) (x : X) → Mono (corec₁ c x) corec₂ c x n s₁ b₁ p₁ s k k≤n with c x corec₂ c x n s₁ b₁ () s k k≤n | inj₁ tt corec₂ c x n s₁ b₁ p₁ s zero k≤n | inj₂ g = (proj₁ (g (hd s)) , refl) corec₂ c x n s₁ b₁ p₁ s (suc k) sk≤n | inj₂ g = {!!} -- corec₂ c -- (proj₂ (g (hd s))) -- n -- (tl s) -- (proj₁ (g (hd s))) -- {!!} -- (tl s) k (pred-≤ sk≤n) -- compute' : ∀{X} (c : X → M X) (x : X) → -- ∀ a → d (corec c x) a ≡ M₁ (corec c) (c x) a -- compute' c x a = -- begin -- d (corec c x) a -- ≡⟨ refl ⟩ -- ((corec c x) (a ω) 0 , λ s n → (corec c x) (a ∷ s) (suc n)) -- ≡⟨ refl ⟩ -- (proj₁ (c x (hd (a ω))) -- , λ s n → corec c (proj₂ (c x (hd (a ∷ s)))) (tl (a ∷ s)) n) -- ≡⟨ refl ⟩ -- (proj₁ (c x a) , λ s n → corec c (proj₂ (c x a)) (λ n → s n) n) -- ≡⟨ refl ⟩ -- (proj₁ (c x a) , λ s n → corec c (proj₂ (c x a)) s n) -- ≡⟨ refl ⟩ -- (proj₁ (c x a) , λ s → corec c (proj₂ (c x a)) s) -- ≡⟨ refl ⟩ -- (proj₁ (c x a) , corec c (proj₂ (c x a))) -- ≡⟨ refl ⟩ -- M₁ (corec c) (c x) a -- ∎ -- compute : ∀{X} (c : X → M X) (x : X) → -- d (corec c x) ≡ M₁ (corec c) (c x) -- compute c x = -- begin -- d (corec c x) -- ≡⟨ refl ⟩ -- (λ a → d (corec c x) a) -- ≡⟨ refl ⟩ -- Same as in compute' -- (λ a → M₁ (corec c) (c x) a) -- ≡⟨ refl ⟩ -- M₁ (corec c) (c x) -- ∎
{ "alphanum_fraction": 0.395329087, "avg_line_length": 26.4606741573, "ext": "agda", "hexsha": "d096e15e2f67090b5493f6f6ffec49dc2f8823d9", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_path": "Streams/StreamEnc.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_path": "Streams/StreamEnc.agda", "max_line_length": 73, "max_stars_count": null, "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_path": "Streams/StreamEnc.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2352, "size": 4710 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Equality over container extensions parametrised by some setoid ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Setoid) module Data.Container.Relation.Binary.Equality.Setoid {c e} (S : Setoid c e) where open import Level using (_⊔_; suc) open import Relation.Binary open import Data.Container.Core open import Data.Container.Relation.Binary.Pointwise import Data.Container.Relation.Binary.Pointwise.Properties as Pw private module S = Setoid S open S using (_≈_) renaming (Carrier to X) ------------------------------------------------------------------------ -- Definition of equality module _ {s p} (C : Container s p) where Eq : Rel (⟦ C ⟧ X) (e ⊔ s ⊔ p) Eq = Pointwise C _≈_ ------------------------------------------------------------------------ -- Relational properties refl : Reflexive Eq refl = Pw.refl C _ S.refl sym : Symmetric Eq sym = Pw.sym C _ S.sym trans : Transitive Eq trans = Pw.trans C _ S.trans isEquivalence : IsEquivalence Eq isEquivalence = record { refl = refl ; sym = sym ; trans = trans } setoid : Setoid (s ⊔ p ⊔ c) (s ⊔ p ⊔ e) setoid = record { isEquivalence = isEquivalence }
{ "alphanum_fraction": 0.5356104651, "avg_line_length": 25.0181818182, "ext": "agda", "hexsha": "d2a6157777f01306a72c888b250b569db98d59b2", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Relation/Binary/Equality/Setoid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Relation/Binary/Equality/Setoid.agda", "max_line_length": 82, "max_stars_count": 5, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Relation/Binary/Equality/Setoid.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 331, "size": 1376 }
--{-# OPTIONS --rewriting #-} --{-# OPTIONS --exact-split #-} --{-# OPTIONS --show-implicit #-} --{-# OPTIONS --allow-unsolved-metas #-} module NaturalDeduction where open import OscarPrelude open import Delay open import Successor open import Membership open import DecidableMembership renaming (DecidableMembership to RDecidableMembership) open import VariableName open import FunctionName open import PredicateName open import Arity open import Vector open import 𝕃ist open import TermByFunctionNames open import Term --open import TermUnification open import MGU-revised open import HasNegation open import Formula open import IsFormula open import 𝓕ormula open import HasNeitherNor open import IsLiteralFormula open import LiteralFormula open import IsPropositionalFormula open import 𝓐ssertion open import 𝓢equent open import Sequent open import 𝑱udgement open import IsLiteralSequent open import LiteralSequent open import Problem open import IsLiteralProblem open import LiteralProblem open import Element open import Elements open import TruthValue open import Interpretation open import HasSatisfaction open import InterpretationEqualityExceptAtVariableName open import HasDecidableSatisfaction open import Validation open import HasDecidableValidation open import HasSubstantiveDischarge open import HasDecidableSubstantiveDischarge open import HasVacuousDischarge open import HasSalvation open import SubstantiveDischargeIsConsistent open import SubstantiveDischargeIsReflexive open import HasDecidableVacuousDischarge open import HasDecidableSalvation open import TermCode open import TermNode open import FindTermNode open import Theorem1 -- infixr 1 ,_ -- pattern ,_ p = _ , p -- pattern ◁pattern c₁∈xs c₁≽s c₂∈xs c₂≽~s = , (((, (c₁∈xs , c₁≽s)) , (, (c₂∈xs , c₂≽~s)))) -- negationEliminationRule : (I : Interpretation) (φ : Formula) → I ⊨ ~ (~ φ) → I ⊨ φ -- negationEliminationRule I φ (¬[I⊭φ×I⊭φ] , _) with I ⊨? φ -- … | yes I⊨φ = I⊨φ -- … | no I⊭φ = ⊥-elim $ ¬[I⊭φ×I⊭φ] $ I⊭φ , I⊭φ -- -- justifieds simplification and ... more? -- simplificationRule₁ : (I : Interpretation) (φ₁ φ₂ : Formula) → I ⊨ Formula.logical φ₁ φ₂ → I ⊨ Formula.logical φ₁ φ₁ -- simplificationRule₁ I φ₁ φ₂ x = (fst x) , (fst x) -- simplificationRule₂ : (I : Interpretation) (φ₁ φ₂ : Formula) → I ⊨ Formula.logical φ₁ φ₂ → I ⊨ Formula.logical φ₂ φ₂ -- simplificationRule₂ I φ₁ φ₂ x = snd x , snd x -- -- logical (logical (logical p p) q) (logical (logical p p) q) -- {- -- conditionalizationRule : (I : Interpretation) (p q : Formula) → I ⊨ q → I ⊨ (p ⊃ q ╱ (p ∷ []) ) -- conditionalizationRule I p q ⊨q (_ , _) = let prf = λ { (_ , ⊭q) → ⊭q ⊨q} in prf , prf -- --let ⊨p = {!-⊨p p (here [])!} in (λ { (x , ~q) → ~q ⊨q}) , (λ { (x , y) → y ⊨q}) -- -} -- modusPonens : (I : Interpretation) (p q : Formula) → I ⊨ p → I ⊨ (p ⊃ q) → I ⊨ q -- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) with I ⊨? q -- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) | yes x = x -- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) | no x = ⊥-elim (~[~p&~p&~q] ((λ { (x₁ , y) → y P}) , (λ x₁ → x x₁))) -- -- -- -- -- -- data SkolemFormula {ι : Size} (α : Alphabet) : Set where -- -- -- -- -- -- atomic : Predication α → SkolemFormula α -- -- -- -- -- -- logical : {ι¹ : Size< ι} → SkolemFormula {ι¹} α → {ι² : Size< ι} → SkolemFormula {ι²} α → SkolemFormula {ι} α -- -- -- -- -- -- record Alphabet₊ᵥ (α : Alphabet) : Set where -- -- -- -- -- -- constructor α₊ᵥ⟨_⟩ -- -- -- -- -- -- field -- -- -- -- -- -- alphabet : Alphabet -- -- -- -- -- -- .one-variable-is-added : (number ∘ variables $ alphabet) ≡ suc (number ∘ variables $ α) -- -- -- -- -- -- .there-are-no-functions-of-maximal-arity : number (functions alphabet) zero ≡ zero -- -- -- -- -- -- .shifted-function-matches : ∀ {ytira₀ ytira₁} → finToNat ytira₁ ≡ finToNat ytira₀ → number (functions alphabet) (suc ytira₁) ≡ number (functions α) ytira₀ -- -- -- -- -- -- open Alphabet₊ᵥ -- -- -- -- -- -- record Alphabet₊ₛ (α : Alphabet) : Set where -- -- -- -- -- -- constructor α₊ₛ⟨_⟩ -- -- -- -- -- -- field -- -- -- -- -- -- alphabet : Alphabet -- -- -- -- -- -- open Alphabet₊ₛ -- -- -- -- -- -- {- -- -- -- -- -- -- toSkolemFormula -- -- -- -- -- -- ∀x(F x v₀ v₁) ⟿ F v₀ v₁ v₂ -- -- -- -- -- -- ∃x(F x v₀ v₁) ⟿ F (s₀͍₂ v₀ v₁) v₀ v₁ -- -- -- -- -- -- ∀x(F x (s₀͍₂ v₀ v₁) v₁) ⟿ F v₀ (s₀͍₂ v₁ v₂) v₂ -- -- -- -- -- -- ∃x(F x (s₀͍₂ v₀ v₁) v₁) ⟿ F (s₀͍₂ v₀ v₁) (s₁͍₂ v₁ v₂) v₂ -- -- -- -- -- -- F v₀ ⊗ G v₀ ⟿ F v₀ ⊗ G v₀ -- -- -- -- -- -- ∀x(F x v₀ v₁) ⊗ ∀x(G x (s₀͍₂ x v₁) v₁) ⟿ F v₀ v₂ v₃ ⊗ G v₁ (s₀͍₂ v₀ v₃) v₃ -- -- -- -- -- -- ∀x(F x v₀ v₁) ⊗ ∃x(G x (s₀͍₂ x v₁) v₁) ⟿ F v₀ v₁ v₂ ⊗ G (s₀͍₁ v₂) (s₁͍₂ (s₀͍₂ v₂) v₂) v₂ -- -- -- -- -- -- Φ₀ = ∃x(G x (s₀͍₂ x v₁) v₁) has alphabet of 2 variables, skolem functions: 0, 0, 1 -- -- -- -- -- -- this is existential {α₊ₛ} Φ₁, where -- -- -- -- -- -- Φ₁ = G (s₀͍₂ v₀ v₁) (s₁͍₂ (s₀͍₂ v₀ v₁)) v₁ -- -- -- -- -- -- α₊ₛ = ⟨ 2 , 0 ∷ 0 ∷ 2 ∷ [] ⟩ -- -- -- -- -- -- maybe Φ₋₁ = ∀y∃x(G x (s₀͍₂ x v₀) v₀) -- -- -- -- -- -- and Φ₋₂ = ∀z∀y∃x(G x (s₀͍₂ x z) z), finally having no free variables, but nevertheless having skolem functions! these are user-defined functions, so this notion of Alphabet is somehow wrong. we have also left out constants (i.e. user-defined skolem-functions of arity 0) -- -- -- -- -- -- Instead, take the alphabet as defining -- -- -- -- -- -- a stack of free variables -- -- -- -- -- -- a matrix (triangle?) of skolem functions -- -- -- -- -- -- Let's try to reverse Φ₁ from a Skolem to a 1st-order formula. Is there a unique way to do it? -- -- -- -- -- -- Φ₀' = ∀x(G (s₀͍₂ x v₀) (s₁͍₂ (s₀͍₂ x v₀)) v₀ -- -- -- -- -- -- Nope! -- -- -- -- -- -- toSkolemFormula of -- -- -- -- -- -- -} -- -- -- -- -- -- -- toSkolemFormula (logical Φ₁ Φ₂) ⟿ -- -- -- -- -- -- -- let α' , φ₁ = toSkolemFormula Φ₁ -- -- -- -- -- -- -- Φ₂' = transcodeToAugmentedAlphabet Φ₂ α' -- -- -- -- -- -- -- α'' , φ₂' = toSkolemFormula Φ₂' -- -- -- -- -- -- -- φ₁' = transcodeToAugmentedAlphabet φ₁ α'' -- -- -- -- -- -- {- -- -- -- -- -- -- given Δv = #varibles α' - #variables α -- -- -- -- -- -- for every variable v in α, v in Φ, v stays the same in Φ' -- -- -- -- -- -- for the added variable v⁺ in α₊ - α, v⁺ in Φ, v⁺ ⟿ v⁺ + Δv in transcode (universal {α₊} Φ) -- -- -- -- -- -- α'₊ = α' + 1 variable -- -- -- -- -- -- -} -- -- -- -- -- -- -- record AddVariable (A : Alphabet → Set) : Set where -- -- -- -- -- -- -- field -- -- -- -- -- -- -- addVariableToAlphabet : {α : Alphabet} → A α → {α₊ : Alphabet} → Alphabet₊ᵥ α₊ → A α₊ -- -- -- -- -- -- -- instance -- -- -- -- -- -- -- AddVariableFirstOrderFormula : AddVariable FirstOrderFormula -- -- -- -- -- -- -- AddVariableFirstOrderFormula = {!!} -- -- -- -- -- -- -- #variables = number ∘ variables -- -- -- -- -- -- -- #functions_ofArity_ : Alphabet → Nat → Nat -- -- -- -- -- -- -- #functions α⟨ V⟨ #variables ⟩ , S⟨ #functions ⟩ ⟩ ofArity arity = if′ lessNat arity (suc #variables) then #functions (natToFin arity) else 0 -- -- -- -- -- -- -- record _⊇_ (α' α : Alphabet) : Set where -- -- -- -- -- -- -- field -- -- -- -- -- -- -- at-least-as-many-variables : #variables α' ≥ #variables α -- -- -- -- -- -- -- at-least-as-many-functions : ∀ {arity} → arity < #variables α → #functions α' ofArity arity ≥ #functions α ofArity arity -- -- -- -- -- -- -- record AddAlphabet (α-top α-bottom : Alphabet) : Set where -- -- -- -- -- -- -- field -- -- -- -- -- -- -- alphabet : Alphabet -- -- -- -- -- -- -- record Transcodeable (A : Alphabet → Set) : Set where -- -- -- -- -- -- -- field -- -- -- -- -- -- -- transcode : {α' α : Alphabet} → ⦃ _ : α' ⊇ α ⦄ → A α → A α' -- -- -- -- -- -- -- open Transcodeable ⦃ … ⦄ -- -- -- -- -- -- -- record TransferAlphabet {α' α : Alphabet} (α'⊇α : α' ⊇ α) (α₊ : Alphabet₊ᵥ α) (Φ : FirstOrderFormula (alphabet α₊)) : Set where -- -- -- -- -- -- -- field -- -- -- -- -- -- -- alphabet : Alphabet -- -- -- -- -- -- -- firstOrderFormula : FirstOrderFormula alphabet -- -- -- -- -- -- -- instance -- -- -- -- -- -- -- TranscodeablePredication : Transcodeable Predication -- -- -- -- -- -- -- TranscodeablePredication = {!!} -- -- -- -- -- -- -- TranscodeableAlphabet+Variable : Transcodeable Alphabet₊ᵥ -- -- -- -- -- -- -- TranscodeableAlphabet+Variable = {!!} -- -- -- -- -- -- -- TranscodeableSkolemFormula : Transcodeable SkolemFormula -- -- -- -- -- -- -- TranscodeableSkolemFormula = {!!} -- -- -- -- -- -- -- TranscodeableFirstOrderFormula : Transcodeable FirstOrderFormula -- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (atomic p) = atomic (transcode p) -- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (logical Φ₁ Φ₂) = logical (transcode Φ₁) (transcode Φ₂) -- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula {α'} {α} ⦃ α'⊇α ⦄ (universal {α₊} Φ) = {!!} -- universal {_} {_} {transcode α₊} (transcode Φ) -- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (existential Φ) = {!!} -- -- -- -- -- -- -- --(α' α : Alphabet) (α'⊇α : α' ⊇ α) (α₊ : Alphabet+Variable α) (Φ : FirstOrderFormula (alphabet α₊)) → Σ _ λ (α''' : Alphabet) → FirstOrderFormula α''' -- -- -- -- -- -- -- --FirstOrderFormula (alphabet α₊) -- -- -- -- -- -- -- {- -- -- -- -- -- -- -- -} -- -- -- -- -- -- -- -- --transcodeIntoAugmentedAlphabet : -- -- -- -- -- -- -- -- --toSkolemFormula : {α : Alphabet} → FirstOrderFormula α → Σ _ λ (α¹ : AugmentedAlphabet α) → SkolemFormula (alphabet α¹) -- -- -- -- -- -- -- -- --record IsEquivalentFormulas {α₀ : Alphabet} (φ₀ : SkolemFormula α₀) {α₁ : Alphabet} (Φ₁ : FirstOrderFormula α₁) : Set where -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- .atomicCase : {p : Predication α₀} → φ₀ ≡ atomic p → Φ₁ ≡ atomic p -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Alphabet+Alphabet (α₀ α₁ α₂ : Alphabet) : Set where -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- alphabet : -- -- -- -- -- -- -- -- -- -- ∀xφ₁(x) ⊗ φ₂ ⟿ ∀x(φ₁ ⊗ φ₂) -- -- -- -- -- -- -- -- -- -- hasQuantifiers : FirstOrderFormula α → Bool -- -- -- -- -- -- -- -- -- --record Skolemization {α : Alphabet} (φ : FirstOrderFormula α) : Set where -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- alphabet : Alphabet -- -- -- -- -- -- -- -- -- -- skolemization : SkolemFormula alphabet -- -- -- -- -- -- -- -- -- record _IsAugmentationOf_ (α₁ α₀ : Alphabet) : Set where -- -- -- -- -- -- -- -- -- record AugmentedAlphabet (α : Alphabet) : Set where -- -- -- -- -- -- -- -- -- constructor ⟨_⟩ -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- alphabet : Alphabet -- -- -- -- -- -- -- -- -- ..laws : alphabet ≡ α -- -- -- -- -- -- -- -- -- open AugmentedAlphabet -- -- -- -- -- -- -- -- -- trivialAugmentation : (α : Alphabet) → AugmentedAlphabet α -- -- -- -- -- -- -- -- -- trivialAugmentation = {!!} -- -- -- -- -- -- -- -- -- record DisjointRelativeUnion {α : Alphabet} (α¹ α² : AugmentedAlphabet α) : Set where -- -- -- -- -- -- -- -- -- constructor ⟨_⟩ -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- augmentation : AugmentedAlphabet α -- -- -- -- -- -- -- -- -- .laws : {!!} -- -- -- -- -- -- -- -- -- open DisjointRelativeUnion -- -- -- -- -- -- -- -- -- disjointRelativeUnion : {α : Alphabet} → (α¹ α² : AugmentedAlphabet α) → DisjointRelativeUnion α¹ α² -- -- -- -- -- -- -- -- -- disjointRelativeUnion = {!!} -- -- -- -- -- -- -- -- -- -- inAugmentedAlphabet : {α : Alphabet} → (α¹ : AugmentedAlphabet α) → SkolemFormula α → SkolemFormula (alphabet α¹) -- -- -- -- -- -- -- -- -- -- inAugmentedAlphabet = {!!} -- -- -- -- -- -- -- -- -- -- toSkolemFormula : {α : Alphabet} → FirstOrderFormula α → Σ _ λ (α¹ : AugmentedAlphabet α) → SkolemFormula (alphabet α¹) -- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (atomic 𝑃) = trivialAugmentation α₀ , atomic 𝑃 -- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (logical φ₁ φ₂) with toSkolemFormula φ₁ | toSkolemFormula φ₂ -- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (logical φ₁ φ₂) | α¹ , Φ₁ | α² , Φ₂ = augmentation (disjointRelativeUnion α¹ α²) , logical {!inAugmentedAlphabet (augmentation (disjointRelativeUnion α¹ α²)) Φ₁!} {!Φ₂!} -- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (universal x) = {!!} -- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (existential x) = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula : ∀ {alphabet₀} → QFormula alphabet₀ → Σ _ λ alphabet₁ → NQFormula alphabet₁ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (atomic name terms) = alphabet₀ , atomic name terms -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (logical formula₁ formula₂) with toNQFormula formula₁ | toNQFormula formula₂ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- … | alphabet₁ , nqFormula₁ | alphabet₂ , nqFormula₂ = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (universal formula) = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (existential formula) = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- --VariableName = Fin ∘ |v| -- -- -- -- -- -- -- -- -- -- -- -- -- --FunctionArity = Fin ∘ suc ∘ size -- -- -- -- -- -- -- -- -- -- -- -- -- --FunctionName = λ alphabet ytira → Fin (|f| alphabet ytira) -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Alphabet : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩ -- -- -- -- -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- -- -- -- -- |v| : Nat -- number of variables -- -- -- -- -- -- -- -- -- -- -- -- -- -- |f| : Fin (suc |v|) → Nat -- number of functions of each arity, |v| through 0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- open Alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- VariableName = Fin ∘ |v| -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- FunctionArity = Fin ∘ suc ∘ |v| -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- FunctionName = λ alphabet ytira → Fin (|f| alphabet ytira) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Term {i : Size} (alphabet : Alphabet) : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- variable : VariableName alphabet → Term alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : ∀ {arity : FunctionArity alphabet} → -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- FunctionName alphabet (natToFin (|v| alphabet) - arity) → -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∀ {j : Size< i} → Vec (Term {j} alphabet) (finToNat arity) → -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Term {i} alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- PredicateArity = Nat -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- PredicateName = Nat -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a zeroth-order formula? (i.e. no quantifiers) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data NQFormula {i : Size} (alphabet : Alphabet) : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- atomic : PredicateName → ∀ {arity} → Vec (Term alphabet) arity → NQFormula alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- logical : {j : Size< i} → NQFormula {j} alphabet → {k : Size< i} → NQFormula {k} alphabet → NQFormula {i} alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentedByVariable (alphabet₀ alphabet₁ : Alphabet) : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- one-variable-is-added : |v| alphabet₁ ≡ suc (|v| alphabet₀) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function-domain-is-zero-at-new-variable : |f| alphabet₁ zero ≡ 0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- shifted-function-matches : ∀ {ytira₀ ytira₁} → finToNat ytira₁ ≡ finToNat ytira₀ → |f| alphabet₁ (suc ytira₁) ≡ |f| alphabet₀ ytira₀ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentVariables (alphabet₀ : Alphabet) : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- alphabet₁ : Alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentation : AugmentedByVariable alphabet₀ alphabet₁ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- open AugmentVariables -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables : (alphabet : Alphabet) → AugmentVariables alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables ⟨ |v| , |f| ⟩ = -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- { alphabet₁ = ⟨ suc |v| , (λ { zero → zero ; (suc ytira) → |f| ytira}) ⟩ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ; augmentation = -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- { one-variable-is-added = refl -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ; function-domain-is-zero-at-new-variable = refl -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ; shifted-function-matches = cong |f| ∘ finToNat-inj } } -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |f|₀ = |f|₀ + 1 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions : Alphabet → Alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions ⟨ |v| , |f| ⟩ = ⟨ |v| , (λ { zero → suc (|f| zero) ; (suc ytira) → |f| (suc ytira) }) ⟩ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data QFormula {i : Size} (alphabet : Alphabet) : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- atomic : PredicateName → ∀ {arity} → Vec (Term alphabet) arity → QFormula alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- logical : {j : Size< i} → QFormula {j} alphabet → {k : Size< i} → QFormula {k} alphabet → QFormula {i} alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- universal : QFormula (alphabet₁ (augmentVariables alphabet)) → QFormula alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- existential : QFormula (augmentFunctions alphabet) → QFormula alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Assignment (alphabet : Alphabet) : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- μ : VariableName alphabet → Domain -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑓 : ∀ {arity} → FunctionName alphabet arity → Vec Domain (finToNat arity) → Domain -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm : ∀ {i alphabet} → Assignment alphabet → Term {i} alphabet → Domain -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm ⟨ μ , _ ⟩ (variable x) = μ x -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm 𝑎@(⟨ μ , 𝑓 ⟩) (function f x) = 𝑓 f (evaluateTerm 𝑎 <$> x) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Interpretation (alphabet : Alphabet) : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- open Assignment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑎 : Assignment alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑃 : PredicateName → ∀ {arity} → Vec Domain arity → Bool -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula : ∀ {i alphabet} → Interpretation alphabet → NQFormula {i} alphabet → Bool -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula ⟨ 𝑎 , 𝑃 ⟩ (atomic name terms) = 𝑃 name $ evaluateTerm 𝑎 <$> terms -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula I (logical formula₁ formula₂) = not (evaluateNQFormula I formula₁) && not (evaluateNQFormula I formula₂) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula : ∀ {alphabet₀} → QFormula alphabet₀ → Σ _ λ alphabet₁ → NQFormula alphabet₁ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (atomic name terms) = alphabet₀ , atomic name terms -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (logical formula₁ formula₂) with toNQFormula formula₁ | toNQFormula formula₂ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- … | alphabet₁ , nqFormula₁ | alphabet₂ , nqFormula₂ = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (universal formula) = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (existential formula) = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record IsADisjointUnionOfNQFormulas -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {alphabet₁ alphabet₂ alphabet₁₊₂ : Alphabet} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₁ : NQFormula alphabet₁) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₂ : NQFormula alphabet₂) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₁₊₂ : NQFormula alphabet₁₊₂) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- alphabet-size : |v| alphabet₁₊₂ ≡ |v| alphabet₁ + |v| alphabet₂ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --|f| alphabet₁₊₂ ytira -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ----record AlphabetSummed (alphabet₀ alphabet₁ : Alphabet) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --addAlphabets : Alphabet → Alphabet → Alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --addAlphabets ⟨ |v|₁ , |f|₁ ⟩ ⟨ |v|₂ , |f|₂ ⟩ = ⟨ (|v|₁ + |v|₂) , (λ x → if′ finToNat x ≤? |v|₁ && finToNat x ≤? |v|₂ then {!!} else {!!}) ⟩ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- sup : ∀ {alphabet₁} → Formula alphabet₁ → ∀ {alphabet₂} → Formula alphabet₂ → Σ _ λ alphabet₁₊₂ → Formula alphabet₁₊₂ × Formula alphabet₁₊₂ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- sup {⟨ |v|₁ , |a|₁ , |f|₁ ⟩} φ₁ {⟨ |v|₂ , |a|₂ , |f|₂ ⟩} φ₂ = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- pnf : ∀ {alphabet} → Formula alphabet → Σ _ λ alphabet+ → Formula₀ alphabet+ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- pnf = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --universal (P 0) = ∀ x → P x -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (∀ x ∃ y (P x y)) ∨ (∀ x ∃ y (P x y)) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- P x₀ (s₀͍₁ x₀) ∨ P x₁ (s₁͍₁ x₁) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- extended|f| : (arity : Arity) → Vec ℕ (suc |a|) → Vec ℕ (++arity (max arity |a|)) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- extended|f| = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- add a variable to the alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables : Alphabet → Alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- increaseTabulationAtN : ∀ {n} → Fin n → (Fin n → Nat) → Fin n → Nat -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- increaseTabulationAtN = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentedFunctions {|a| : Arity} (arity : Arity) (|f| : Vec ℕ (++arity |a|)) : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- maxA : ℕ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- maxA-law : max arity |a| ≡ maxA -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ++|f| : Vec ℕ maxA -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- f-law : increaseTabulationAt arity (indexVec |f|) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- define -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ⊗ b ≡ False a and False b -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- now, we can define -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ¬a = a ⊗ a ≡ False a and False a -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ∨ b = ¬(a ⊗ b) ≡ False (False a and False b) and False (False a and False b) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ∧ b = ¬(¬a ∨ ¬b) = ¬(¬(¬a ⊗ ¬b)) = ¬a ⊗ ¬b = False (False a and False a) and False (False b and False b) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a → b = ¬a ∨ b = (a ⊗ a) ∨ b = ¬((a ⊗ a) ⊗ b) = ((a ⊗ a) ⊗ b) ⊗ ((a ⊗ a) ⊗ b) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- conversion to prenex -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∀xF ⊗ G ⟿ ∃x(F ⊗ wk(G)) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∃xF ⊗ G ⟿ ∀x(F ⊗ wk(G)) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- F ⊗ ∀xG ⟿ ∃x(wk(F) ⊗ G) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- F ⊗ ∃xG ⟿ ∀x(wk(F) ⊗ G) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ======================== -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (a ⊗ ∀xB) ⊗ c ⟿ ∃x(wk(a) ⊗ B) ⊗ c ⟿ ∀x((wk(a) ⊗ B) ⊗ wk(c)) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF : (arity : Arity) → ∀ {|a| : Arity} → Vec ℕ (++arity |a|) → Vec ℕ (++arity (max arity |a|)) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- with decBool (lessNat |a| arity) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | yes x with compare arity |a| -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.(suc (k + arity))} |f| | yes x | less (diff k refl) = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.arity} |f| | yes x | equal refl with lessNat arity arity -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.arity} |f| | yes x | equal refl | false = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF zero {.zero} |f| | yes true | equal refl | true = {!!} ∷ [] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF (suc arity) {.(suc arity)} |f| | yes true | equal refl | true = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | yes x | greater gt = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x with decBool (lessNat arity |a|) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x₁ | yes x = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x₁ | no x = {!!} -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- = case arity <? |a| of λ { false → {!!} ; true → {!!} } -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- add a function of a given arity to the alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions : Arity → Alphabet → Alphabet -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions arity ⟨ |v| , |a| , |f| ⟩ = ⟨ |v| , max arity |a| , augmentF arity |f| ⟩ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Alphabet : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data DomainSignifier : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- free : Nat → DomainSignifier -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data PartiallyAppliedFunction : Nat → Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- constant : PartiallyAppliedFunction 0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : ∀ {n} → PartiallyAppliedFunction 0 → PartiallyAppliedFunction (suc n) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Term = PartiallyAppliedFunction 0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data PartialyAppliedPredicate : Nat → Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- statement : PartialyAppliedPredicate 0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- partial : ∀ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Language : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Name = String -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Function : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- name : Name -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- number-of-arguments : Nat -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Vec -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Function : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Term : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : Function → -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Sentence : Set where -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- predication : Name → -- -- -- -- -- -- {- -- -- -- -- -- -- record Variables : Set where -- -- -- -- -- -- constructor V⟨_⟩ -- -- -- -- -- -- field -- -- -- -- -- -- number : Nat -- -- -- -- -- -- open Variables -- -- -- -- -- -- record Functions (υ : Variables) : Set where -- -- -- -- -- -- constructor S⟨_⟩ -- -- -- -- -- -- field -- -- -- -- -- -- number : Fin (suc (number υ)) → Nat -- -- -- -- -- -- open Functions -- -- -- -- -- -- record Alphabet : Set where -- -- -- -- -- -- constructor α⟨_,_⟩ -- -- -- -- -- -- field -- -- -- -- -- -- variables : Variables -- -- -- -- -- -- functions : Functions variables -- -- -- -- -- -- open Alphabet -- -- -- -- -- -- record Variable (α : Alphabet) : Set where -- -- -- -- -- -- constructor v⟨_⟩ -- -- -- -- -- -- field -- -- -- -- -- -- name : Fin (number (variables α)) -- -- -- -- -- -- open Variable -- -- -- -- -- -- record Function (α : Alphabet) : Set where -- -- -- -- -- -- constructor s⟨_,_⟩ -- -- -- -- -- -- field -- -- -- -- -- -- arity : Fin ∘ suc ∘ number ∘ variables $ α -- -- -- -- -- -- name : Fin $ number (functions α) arity -- -- -- -- -- -- open Function -- -- -- -- -- -- data Term (𝑽 : Nat) : Set where -- -- -- -- -- -- variable : Fin 𝑽 → Term 𝑽 -- -- -- -- -- -- function : (𝑓 : Function α) → {ι₋₁ : Size< ι₀} → Vec (Term {ι₋₁} α) (finToNat (arity 𝑓)) → -- -- -- -- -- -- Term {ι₀} α -- -- -- -- -- -- record Predication (alphabet : Alphabet) : Set where -- -- -- -- -- -- constructor P⟨_,_,_⟩ -- -- -- -- -- -- field -- -- -- -- -- -- name : Nat -- -- -- -- -- -- arity : Nat -- -- -- -- -- -- terms : Vec (Term alphabet) arity -- -- -- -- -- -- open Predication -- -- -- -- -- -- -} -- -- module NotUsed where -- -- -- thought it might be easier to use this -- -- module UsingContainerList where -- -- record TermNode : Set -- -- where -- -- inductive -- -- field -- -- children : List (TermCode × TermNode) -- -- number : Nat -- -- open TermNode -- -- _child∈_ : TermCode → TermNode → Set -- -- _child∈_ 𝔠 𝔫 = Any ((𝔠 ≡_) ∘ fst) (children 𝔫) -- -- -- this still has a lambda problem, albeit weirder -- -- module RememberChildren where -- -- record TermNode : Set -- -- where -- -- inductive -- -- field -- -- tests : List TermCode -- -- children : ∀ {𝔠} → 𝔠 ∈ tests → TermNode -- -- number : Nat -- -- open TermNode -- -- addChild : {𝔠 : TermCode} (𝔫 : TermNode) → 𝔠 ∉ tests 𝔫 → TermNode → TermNode -- -- addChild {𝔠} 𝔫 𝔠∉tests𝔫 𝔫' = -- -- record 𝔫 -- -- { tests = 𝔠 ∷ tests 𝔫 -- -- ; children = λ -- -- { (here _) → 𝔫' -- -- ; (there _ 𝔠'∈tests) → children 𝔫 𝔠'∈tests }} -- -- setChild : {𝔠 : TermCode} (𝔫 : TermNode) → 𝔠 ∈ tests 𝔫 → TermNode → TermNode -- -- setChild {𝔠} 𝔫 𝔠∈tests𝔫 𝔫' = -- -- record 𝔫 -- -- { children = λ {𝔠'} 𝔠'∈tests𝔫' → ifYes 𝔠' ≟ 𝔠 then 𝔫' else children 𝔫 𝔠'∈tests𝔫' } -- -- storeTermCodes : List TermCode → Nat → StateT TermNode Identity Nat -- -- storeTermCodes [] 𝔑 = return 𝔑 -- -- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 = -- -- 𝔫 ← get -| -- -- case 𝔠 ∈? tests 𝔫 of λ -- -- { (no 𝔠∉tests) → -- -- let 𝔑' , 𝔫' = runIdentity $ -- -- runStateT -- -- (storeTermCodes 𝔠s $ suc 𝔑) -- -- (record -- -- { tests = [] -- -- ; children = λ () -- -- ; number = suc 𝔑 }) in -- -- put (addChild 𝔫 𝔠∉tests 𝔫') ~| -- -- return 𝔑' -- -- ; (yes 𝔠∈tests) → -- -- let 𝔑' , 𝔫' = runIdentity $ -- -- runStateT -- -- (storeTermCodes 𝔠s $ suc 𝔑) -- -- (children 𝔫 𝔠∈tests) in -- -- put (setChild 𝔫 𝔠∈tests 𝔫') ~| -- -- return 𝔑' } -- -- topNode : TermNode -- -- topNode = record { tests = [] ; children = λ () ; number = 0 } -- -- example-store : TermNode -- -- example-store = snd ∘ runIdentity $ runStateT (storeTermCodes example-TermCodes 0) topNode -- -- foo : TermNode × TermNode -- -- foo = -- -- {!example-store!} , -- -- {!snd ∘ runIdentity $ runStateT (storeTermCodes example-TermCodes 10) example-store!} -- -- -- using a lambda for the children results in extra unnecessary structure when adding to an existing node; perhaps using an explicit mapping? or use another field to state what codes are present in the mapping? -- -- module NoParents where -- -- mutual -- -- record TermNode : Set -- -- where -- -- inductive -- -- field -- -- children : TermCode → Maybe TermNode -- Map TermCode TermNode -- -- self : TermCode -- -- number : Nat -- -- record TopTermNode : Set -- -- where -- -- inductive -- -- field -- -- children : TermCode → Maybe TermNode -- -- open TermNode -- -- open TopTermNode -- -- storeTermCodes : List TermCode → Nat → StateT TermNode Identity ⊤ -- -- storeTermCodes [] _ = return tt -- -- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 = -- -- 𝔫 ← get -| -- -- case children 𝔫 𝔠 of λ -- -- { nothing → -- -- put -- -- (record 𝔫 -- -- { children = -- -- λ 𝔠' → -- -- ifYes 𝔠' ≟ 𝔠 then -- -- just ∘ snd ∘ runIdentity $ -- -- (runStateT -- -- (storeTermCodes 𝔠s (suc 𝔑)) -- -- (record -- -- { self = 𝔠 -- -- ; children = const nothing -- -- ; number = suc 𝔑 })) -- -- else -- -- children 𝔫 𝔠' } ) ~| -- -- return tt -- -- ; (just 𝔫') → -- -- put (record 𝔫 -- -- { children = -- -- λ 𝔠' → -- -- ifYes 𝔠' ≟ 𝔠 then -- -- just ∘ snd ∘ runIdentity $ -- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫' -- -- else -- -- children 𝔫 𝔠' }) ~| -- -- return tt } -- -- storeTermCodesAtTop : List TermCode → Nat → StateT TopTermNode Identity ⊤ -- -- storeTermCodesAtTop [] _ = return tt -- -- storeTermCodesAtTop (𝔠 ∷ 𝔠s) 𝔑 = -- -- 𝔫 ← get -| -- -- case children 𝔫 𝔠 of λ -- -- { nothing → -- -- put -- -- (record 𝔫 -- -- { children = -- -- λ 𝔠' → -- -- ifYes 𝔠' ≟ 𝔠 then -- -- just ∘ snd ∘ runIdentity $ -- -- (runStateT -- -- (storeTermCodes 𝔠s (suc 𝔑)) -- -- (record -- -- { self = 𝔠 -- -- ; children = const nothing -- -- ; number = suc 𝔑 })) -- -- else -- -- children 𝔫 𝔠' } ) ~| -- -- return tt -- -- ; (just 𝔫') → -- -- put (record 𝔫 -- -- { children = -- -- λ 𝔠' → -- -- ifYes 𝔠' ≟ 𝔠 then -- -- just ∘ snd ∘ runIdentity $ -- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫' -- -- else -- -- children 𝔫 𝔠' }) ~| -- -- return tt } -- -- initialTopNode : TopTermNode -- -- initialTopNode = record { children = const nothing } -- -- example-store : TopTermNode -- -- example-store = snd ∘ runIdentity $ runStateT (storeTermCodesAtTop example-TermCodes 0) initialTopNode -- -- foo : TopTermNode × TopTermNode -- -- foo = -- -- {!example-store!} , -- -- {!snd ∘ runIdentity $ runStateT (storeTermCodesAtTop example-TermCodes 10) example-store!} -- -- -- it's tricky to keep the parents up to date when the children change (viz adolescence) -- -- module FirstTryWithParent where -- -- mutual -- -- record TermNode : Set -- -- where -- -- inductive -- -- field -- -- parent : TopTermNode ⊎ TermNode -- -- self : TermCode -- -- children : TermCode → Maybe TermNode -- Map TermCode TermNode -- -- number : Nat -- -- record TopTermNode : Set -- -- where -- -- inductive -- -- field -- -- children : TermCode → Maybe TermNode -- -- open TermNode -- -- open TopTermNode -- -- storeTermCodes : List TermCode → Nat → StateT TermNode Identity ⊤ -- -- storeTermCodes [] _ = return tt -- -- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 = -- -- 𝔫 ← get -| -- -- case children 𝔫 𝔠 of λ -- -- { nothing → -- -- put -- -- (record 𝔫 -- -- { children = -- -- λ 𝔠' → -- -- ifYes 𝔠' ≟ 𝔠 then -- -- just ∘ snd ∘ runIdentity $ -- -- (runStateT -- -- (storeTermCodes 𝔠s (suc 𝔑)) -- -- (record -- -- { parent = right 𝔫 -- -- ; self = 𝔠 -- -- ; children = const nothing -- -- ; number = suc 𝔑 })) -- -- else -- -- children 𝔫 𝔠' } ) ~| -- -- return tt -- -- ; (just 𝔫') → -- -- put (record 𝔫 -- -- { children = -- -- λ 𝔠' → -- -- ifYes 𝔠' ≟ 𝔠 then -- -- just ∘ snd ∘ runIdentity $ -- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫' -- -- else -- -- children 𝔫 𝔠' }) ~| -- -- return tt } -- -- storeTermCodesAtTop : List TermCode → Nat → StateT TopTermNode Identity ⊤ -- -- storeTermCodesAtTop [] _ = return tt -- -- storeTermCodesAtTop (𝔠 ∷ 𝔠s) 𝔑 = -- -- 𝔫 ← get -| -- -- case children 𝔫 𝔠 of λ -- -- { nothing → -- -- put -- -- (record 𝔫 -- -- { children = -- -- λ 𝔠' → -- -- ifYes 𝔠' ≟ 𝔠 then -- -- just ∘ snd ∘ runIdentity $ -- -- (runStateT -- -- (storeTermCodes 𝔠s (suc 𝔑)) -- -- (record -- -- { parent = left 𝔫 -- -- ; self = 𝔠 -- -- ; children = const nothing -- -- ; number = suc 𝔑 })) -- -- else -- -- children 𝔫 𝔠' } ) ~| -- -- return tt -- -- ; (just 𝔫') → -- -- put (record 𝔫 -- -- { children = -- -- λ 𝔠' → -- -- ifYes 𝔠' ≟ 𝔠 then -- -- just ∘ snd ∘ runIdentity $ -- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫' -- -- else -- -- children 𝔫 𝔠' }) ~| -- -- return tt } -- -- initialTopNode : TopTermNode -- -- initialTopNode = record { children = const nothing } -- -- example-store : TopTermNode -- -- example-store = snd ∘ runIdentity $ runStateT (storeTermCodesAtTop example-TermCodes 0) initialTopNode -- -- foo : TopTermNode -- -- foo = {!example-store!} -- -- -- -- -- -- _⟪_⟫_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} → -- -- A → (A → B → C) → B → C -- -- x ⟪ f ⟫ y = f x y -- -- -- -- {- -- -- infixr 9 _∘₂′_ -- -- _∘₂′_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → -- -- (C → D) → (A → B → C) → (A → B → D) -- -- _∘₂′_ = _∘′_ ∘ _∘′_ -- -- {-# INLINE _∘₂′_ #-} -- -- -- -- infixr 9 _∘₂′_ -- -- _∘₂′_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → -- -- (C → D) → (A → B → C) → (A → B → D) -- -- _∘₂′_ = _∘′_ ∘ _∘′_ -- -- {-# INLINE _∘₂′_ #-} -- -- -} -- -- {- -- -- infixr 9 _∘₂_ -- -- _∘₂_ : ∀ {a b c d} {A : Set a} {B : A → Set b} {C : ∀ x → B x → Set c} {D : ∀ x → B x → C x -- -- (f : ∀ {x} (y : B x) → C x y) (g : ∀ x → B x) → -- -- ∀ x → C x (g x) -- -- _∘₂_ = _∘′_ ∘ _∘′_ -- -- {-# INLINE _∘₂′_ #-} -- -- -}
{ "alphanum_fraction": 0.4016018857, "avg_line_length": 48.9129411765, "ext": "agda", "hexsha": "91df8322b1df7651668d4a9c9a4040f0a90a862a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-1/NaturalDeduction.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-1/NaturalDeduction.agda", "max_line_length": 292, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-1/NaturalDeduction.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 14029, "size": 41576 }
open import Level using (Level; _⊔_) open import Function using (id; case_of_) open import Data.Nat using (ℕ; suc) open import Data.Fin using (Fin; suc; zero) open import Data.Vec as Vec using (Vec) renaming (_∷_ to _,_; [] to ∅) open import Data.List using (_∷_; []) open import Data.List as List using (List; _++_) renaming (_∷_ to _,_; [] to ∅) open import Data.Product as Product using (∃; _×_; _,_) open import Relation.Binary.PropositionalEquality as P using (_≡_; refl; sym; cong) module IntuitionisticLogic (U : Set) (⟦_⟧ᵁ : U → Set) where infix 30 _⊗_ infixr 20 _⇒_ data Type : Set where el : (A : U) → Type _⊗_ : Type → Type → Type _⇒_ : Type → Type → Type module Implicit where infix 4 _⊢_ data _⊢_ : ∀ {k} (Γ : Vec Type k) (A : Type) → Set where var : ∀ {k} {Γ : Vec Type k} (x : Fin k) → Γ ⊢ Vec.lookup x Γ abs : ∀ {A B} {k} {Γ : Vec Type k} → A , Γ ⊢ B → Γ ⊢ A ⇒ B app : ∀ {A B} {k} {Γ : Vec Type k} → Γ ⊢ A ⇒ B → Γ ⊢ A → Γ ⊢ B pair : ∀ {A B} {k} {Γ : Vec Type k} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ⊗ B case : ∀ {A B C} {k} {Γ : Vec Type k} → Γ ⊢ A ⊗ B → A , B , Γ ⊢ C → Γ ⊢ C swap : ∀ {A B} {k} {Γ : Vec Type k} → Γ ⊢ A ⊗ B ⇒ B ⊗ A swap = abs (case (var zero) (pair (var (suc zero)) (var zero))) Vec-exch : ∀ {k} (i : Fin k) → Vec Type (suc k) → Vec Type (suc k) Vec-exch zero (A , B , Γ) = B , A , Γ Vec-exch (suc i) (A , Γ) = A , (Vec-exch i Γ) lemma-var : ∀ {k} {Γ : Vec Type (suc k)} → ∀ i x → ∃ λ y → Vec.lookup x Γ ≡ Vec.lookup y (Vec-exch i Γ) lemma-var {Γ = A , B , Γ} zero zero = suc zero , refl lemma-var {Γ = A , B , Γ} zero (suc zero) = zero , refl lemma-var {Γ = A , B , Γ} zero (suc (suc x)) = suc (suc x) , refl lemma-var {Γ = A , Γ} (suc i) zero = zero , refl lemma-var {Γ = A , Γ} (suc i) (suc x) = Product.map suc id (lemma-var {Γ = Γ} i x) exch : ∀ {k} {Γ : Vec Type (suc k)} {A} → ∀ i → Γ ⊢ A → Vec-exch i Γ ⊢ A exch {Γ = Γ} i (var x) with lemma-var {Γ = Γ} i x exch {Γ = Γ} i (var x) | y , p rewrite p = var y exch i (abs t) = abs (exch (suc i) t) exch i (app s t) = app (exch i s) (exch i t) exch i (pair s t) = pair (exch i s) (exch i t) exch i (case s t) = case (exch i s) (exch (suc (suc i)) t) module Explicit where infix 4 _⊢_ data _⊢_ : ∀ (X : List Type) (A : Type) → Set where var : ∀ {A} → A , ∅ ⊢ A abs : ∀ {X A B} → A , X ⊢ B → X ⊢ A ⇒ B app : ∀ {X Y A B} → X ⊢ A ⇒ B → Y ⊢ A → X ++ Y ⊢ B pair : ∀ {X Y A B} → X ⊢ A → Y ⊢ B → X ++ Y ⊢ A ⊗ B case : ∀ {X Y A B C} → X ⊢ A ⊗ B → A , B , Y ⊢ C → X ++ Y ⊢ C weak : ∀ {X Y A} → X ⊢ A → X ++ Y ⊢ A cont : ∀ {X A B} → A , A , X ⊢ B → A , X ⊢ B exch : ∀ {X Y Z W A} → (X ++ Z) ++ (Y ++ W) ⊢ A → (X ++ Y) ++ (Z ++ W) ⊢ A exch₀ : ∀ {X A B C} → B , A , X ⊢ C → A , B , X ⊢ C exch₀ {X} {A} {B} = exch {∅} {A , ∅} {B , ∅} {X} swap : ∀ {X A B} → X ⊢ A ⊗ B ⇒ B ⊗ A swap {X} {A} {B} = abs (case var (exch₀ (pair var (weak {A , ∅} {X} var)))) record Reify {a b : Level} (A : Set a) (B : Set b) : Set (a ⊔ b) where field ⟦_⟧ : A → B instance ReifyType : Reify Type Set ReifyType = record { ⟦_⟧ = ⟦_⟧ } where ⟦_⟧ : Type → Set ⟦ el A ⟧ = ⟦ A ⟧ᵁ ⟦ A ⊗ B ⟧ = ⟦ A ⟧ × ⟦ B ⟧ ⟦ A ⇒ B ⟧ = ⟦ A ⟧ → ⟦ B ⟧ data Ctxt : ∀ (X : List Set) → Set₁ where ∅ : Ctxt ∅ _,_ : ∀ {A X} → A → Ctxt X → Ctxt (A , X) open Reify {{...}} using (⟦_⟧) instance ReifyCtxt : Reify (List Type) (List Set) ReifyCtxt = record { ⟦_⟧ = List.map ⟦_⟧ } Ctxt-insert : {A : Type} {X Y : List Type} → ⟦ A ⟧ → Ctxt ⟦ X ++ Y ⟧ → Ctxt ⟦ X ++ (A , Y) ⟧ Ctxt-insert {A} {∅} {Y} A′ E = A′ , E Ctxt-insert {A} {B , X} {Y} A′ (B′ , E) = B′ , Ctxt-insert {A} {X} {Y} A′ E Ctxt-exch : {X Y Z W : List Type} → Ctxt ⟦ (X ++ Y) ++ (Z ++ W) ⟧ → Ctxt ⟦ (X ++ Z) ++ (Y ++ W) ⟧ Ctxt-exch {X = ∅} {Y = ∅} {Z} {W} E = E Ctxt-exch {X = ∅} {Y = A , Y} {Z} {W} (A′ , E) = Ctxt-insert {A} {Z} {Y ++ W} A′ (Ctxt-exch {∅} {Y} {Z} {W} E) Ctxt-exch {X = A , X} {Y} {Z} {W} (A′ , E) = A′ , Ctxt-exch {X} {Y} {Z} {W} E Ctxt-split : {X Y : List Type} → Ctxt ⟦ X ++ Y ⟧ → Ctxt ⟦ X ⟧ × Ctxt ⟦ Y ⟧ Ctxt-split {∅} {Y} E = ∅ , E Ctxt-split {A , X} {Y} (A′ , E) with Ctxt-split {X} {Y} E ... | Eˣ , Eʸ = ((A′ , Eˣ) , Eʸ) reify : {A : Type} {X : List Type} → X ⊢ A → (Ctxt ⟦ X ⟧ → ⟦ A ⟧) reify var (x , ∅) = x reify (abs t) E = λ x → reify t (x , E) reify (app s t) E with Ctxt-split E ... | Eˢ , Eᵗ = (reify s Eˢ) (reify t Eᵗ) reify (pair s t) E with Ctxt-split E ... | Eˢ , Eᵗ = (reify s Eˢ , reify t Eᵗ) reify (case s t) E with Ctxt-split E ... | Eˢ , Eᵗ = case reify s Eˢ of λ{ (x , y) → reify t (x , y , Eᵗ)} reify (weak {X} s) E with Ctxt-split {X} E ... | Eˢ , Eᵗ = reify s Eˢ reify (cont t) (x , E) = reify t (x , x , E) reify (exch {X} {Y} {Z} {W} t) E = reify t (Ctxt-exch {X} {Y} {Z} {W} E) [_] : {A : Type} {X : List Type} → X ⊢ A → (Ctxt ⟦ X ⟧ → ⟦ A ⟧) [_] = reify swap′ : ∀ {A B} → ⟦ A ⟧ × ⟦ B ⟧ → ⟦ B ⟧ × ⟦ A ⟧ swap′ {A} {B} = [ swap {∅} {A} {B} ] ∅
{ "alphanum_fraction": 0.4400987279, "avg_line_length": 39.6015037594, "ext": "agda", "hexsha": "193d04150ed4cffcaa58844c841b10f1cacdbcdb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b880cf25ed8e81b9a965ea9aad18377008d68a9f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "wenkokke/msla2014", "max_forks_repo_path": "src/IntuitionisticLogic.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b880cf25ed8e81b9a965ea9aad18377008d68a9f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "wenkokke/msla2014", "max_issues_repo_path": "src/IntuitionisticLogic.agda", "max_line_length": 112, "max_stars_count": 5, "max_stars_repo_head_hexsha": "b880cf25ed8e81b9a965ea9aad18377008d68a9f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "wenkokke/msla2014", "max_stars_repo_path": "src/IntuitionisticLogic.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-29T09:07:45.000Z", "max_stars_repo_stars_event_min_datetime": "2018-11-17T23:04:39.000Z", "num_tokens": 2509, "size": 5267 }
{-# OPTIONS --copatterns #-} {-# OPTIONS -v tc.constr.findInScope:15 #-} -- One-place functors (decorations) on Set module Control.Bug-Loop where open import Function using (id; _∘_) open import Relation.Binary.PropositionalEquality open ≡-Reasoning open import Control.Functor open IsFunctor {{...}} record IsDecoration (D : Set → Set) : Set₁ where field traverse : ∀ {F} {{ functor : IsFunctor F }} {A B} → (A → F B) → D A → F (D B) traverse-id : ∀ {A} → traverse {F = λ A → A} {A = A} id ≡ id traverse-∘ : ∀ {F G} {{ funcF : IsFunctor F}} {{ funcG : IsFunctor G}} → ∀ {A B C} {f : A → F B} {g : B → G C} → traverse ((map g) ∘ f) ≡ map {{funcF}} (traverse g) ∘ traverse f isFunctor : IsFunctor D isFunctor = record { ops = record { map = traverse } ; laws = record { map-id = traverse-id ; map-∘ = traverse-∘ } } open IsDecoration idIsDecoration : IsDecoration (λ A → A) traverse idIsDecoration f = f traverse-id idIsDecoration = refl traverse-∘ idIsDecoration = refl compIsDecoration : ∀ {D E} → IsDecoration D → IsDecoration E → IsDecoration (λ A → D (E A)) traverse (compIsDecoration d e) f = traverse d (traverse e f) traverse-id (compIsDecoration d e) = begin traverse d (traverse e id) ≡⟨ cong (traverse d) (traverse-id e) ⟩ traverse d id ≡⟨ traverse-id d ⟩ id ∎ traverse-∘ (compIsDecoration d e) {{funcF = funcF}} {{funcG = funcG}} {f = f} {g = g} = begin traverse (compIsDecoration d e) (map g ∘ f) ≡⟨⟩ traverse d (traverse e (map g ∘ f)) ≡⟨ cong (traverse d) (traverse-∘ e) ⟩ traverse d (map (traverse e g) ∘ traverse e f) ≡⟨ traverse-∘ d ⟩ map (traverse d (traverse e g)) ∘ traverse d (traverse e f) ≡⟨⟩ map (traverse (compIsDecoration d e) g) ∘ traverse (compIsDecoration d e) f ∎
{ "alphanum_fraction": 0.5894848646, "avg_line_length": 28.1044776119, "ext": "agda", "hexsha": "4a64e279e64489e5f4ab1c771659db3bde235eaf", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andreasabel/cubical", "max_forks_repo_path": "src/Control/Bug-Loop.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andreasabel/cubical", "max_issues_repo_path": "src/Control/Bug-Loop.agda", "max_line_length": 93, "max_stars_count": null, "max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andreasabel/cubical", "max_stars_repo_path": "src/Control/Bug-Loop.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 656, "size": 1883 }
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics module lib.types.Empty where Empty-rec : ∀ {i} {A : Type i} → (Empty → A) Empty-rec = Empty-elim ⊥-rec : ∀ {i} {A : Type i} → (⊥ → A) ⊥-rec = Empty-rec Empty-is-prop : is-prop Empty Empty-is-prop = has-level-in Empty-elim instance Empty-level : {n : ℕ₋₂} → has-level (S n) Empty Empty-level = prop-has-level-S Empty-is-prop Empty-is-set : is-set Empty Empty-is-set = raise-level -1 Empty-is-prop ⊥-is-prop = Empty-is-prop ⊥-is-set = Empty-is-set ⊥-level = Empty-level
{ "alphanum_fraction": 0.6408839779, "avg_line_length": 20.8846153846, "ext": "agda", "hexsha": "6b1772595140144d034b6d3e3a8e73e35240c26b", "lang": "Agda", "max_forks_count": 50, "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "core/lib/types/Empty.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "timjb/HoTT-Agda", "max_issues_repo_path": "core/lib/types/Empty.agda", "max_line_length": 49, "max_stars_count": 294, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "core/lib/types/Empty.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z", "num_tokens": 185, "size": 543 }
data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x postulate A : Set a : A record Eq (a : A) : Set where constructor mkEq field v : A p : a ≡ v open Eq record S : Set1 where constructor mkS field u : A e : Eq u open Eq e public open S test : ∀ (b : A) → S u (test b) = b v (e (test b)) = a p (e (test b)) = refl
{ "alphanum_fraction": 0.5138121547, "avg_line_length": 12.9285714286, "ext": "agda", "hexsha": "8e8f87787a5c553b728e56c10de69fa71bfeb26c", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "cagix/agda", "max_forks_repo_path": "test/Fail/Issue2806.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "cagix/agda", "max_issues_repo_path": "test/Fail/Issue2806.agda", "max_line_length": 50, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "cagix/agda", "max_stars_repo_path": "test/Fail/Issue2806.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 157, "size": 362 }
-- Jesper, 2018-11-29: Instances with explicit arguments will never be -- used, so declaring them should give a warning. postulate X : Set instance _ : Set → X -- this should give a warning it : {{_ : X}} → X it {{x}} = x -- OTOH, this is fine as the instance can be used inside the module module _ (A : Set) where postulate instance instX : X test : X test = it
{ "alphanum_fraction": 0.6631299735, "avg_line_length": 22.1764705882, "ext": "agda", "hexsha": "3511b0226337a8aabe42b5dc320175949186917d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/WarningInstanceWithExplicitArg.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "hborum/agda", "max_issues_repo_path": "test/Succeed/WarningInstanceWithExplicitArg.agda", "max_line_length": 70, "max_stars_count": 2, "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "hborum/agda", "max_stars_repo_path": "test/Succeed/WarningInstanceWithExplicitArg.agda", "max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z", "num_tokens": 116, "size": 377 }
-- {-# OPTIONS -v tc.cover.split.con:20 #-} open import Common.Prelude renaming (Nat to ℕ) open import Common.Equality infix 3 ¬_ ¬_ : Set → Set ¬ P = P → ⊥ -- Decidable relations. data Dec (P : Set) : Set where yes : ( p : P) → Dec P no : (¬p : ¬ P) → Dec P _≟_ : (m n : ℕ) → Dec (m ≡ n) zero ≟ zero = yes refl zero ≟ suc n = no λ() suc m ≟ zero = no λ() suc m ≟ suc n with m ≟ n suc m ≟ suc .m | yes refl = yes refl suc m ≟ suc n | no prf = no (λ x → prf (cong pred x)) data Ty : Set where data Cxt : Set where ε : Cxt _,_ : (Γ : Cxt) (a : Ty) → Cxt len : Cxt → ℕ len ε = 0 len (Γ , _) = suc (len Γ) -- De Bruijn index mutual Var : Cxt → Ty → Set Var Γ a = Var' a Γ data Var' (a : Ty) : (Γ : Cxt) → Set where zero : ∀ {Γ} → Var (Γ , a) a suc : ∀ {Γ b} (x : Var Γ a) → Var (Γ , b) a -- De Bruijn Level Lev = ℕ -- Valid de Bruijn levels. data LookupLev : (x : Lev) (Γ : Cxt) (a : Ty) (i : Var Γ a) → Set where lookupZero : ∀ {Γ a} → LookupLev (len Γ) (Γ , a) a zero lookupSuc : ∀ {Γ a b x i} → LookupLev x Γ a i → LookupLev x (Γ , b) a (suc i) record ValidLev (x : Lev) (Γ : Cxt) : Set where constructor validLev field {type } : Ty {index} : Var Γ type valid : LookupLev x Γ type index weakLev : ∀ {x Γ a} → ValidLev x Γ → ValidLev x (Γ , a) weakLev (validLev d) = validLev (lookupSuc d) -- Looking up a de Bruijn level. lookupLev : ∀ (x : Lev) (Γ : Cxt) → Dec (ValidLev x Γ) lookupLev x ε = no λ { (validLev ()) } lookupLev x (Γ , a) with x ≟ len Γ lookupLev ._ (Γ , a) | yes refl = yes (validLev lookupZero) lookupLev x (Γ , a) | no _ with lookupLev x Γ lookupLev x (Γ , a) | no ¬p | yes d = yes (weakLev d) lookupLev x (Γ , a) | no ¬p | no ¬d = no contra where contra : ¬ ValidLev x (Γ , a) contra (validLev (lookupSuc valid)) = ? {- Unbound indices showing up in error message: I'm not sure if there should be a case for the constructor lookupZero, because I get stuck when trying to solve the following unification problems (inferred index ≟ expected index): len Γ ≟ @8 Γ , a ≟ @7 , @4 a ≟ type zero ≟ index when checking the definition of contra -}
{ "alphanum_fraction": 0.5709721588, "avg_line_length": 23.8152173913, "ext": "agda", "hexsha": "d3dfbc2d108294d48e4aa5f07b693a46a2f4e8cf", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/fail/Issue985.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/fail/Issue985.agda", "max_line_length": 71, "max_stars_count": 1, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Fail/Issue985.agda", "max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z", "num_tokens": 868, "size": 2191 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Susp.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Path open import Cubical.Data.Bool open import Cubical.HITs.Join open import Cubical.HITs.Susp.Base open Iso Susp-iso-joinBool : ∀ {ℓ} {A : Type ℓ} → Iso (Susp A) (join A Bool) fun Susp-iso-joinBool north = inr true fun Susp-iso-joinBool south = inr false fun Susp-iso-joinBool (merid a i) = (sym (push a true) ∙ push a false) i inv Susp-iso-joinBool (inr true ) = north inv Susp-iso-joinBool (inr false) = south inv Susp-iso-joinBool (inl _) = north inv Susp-iso-joinBool (push a true i) = north inv Susp-iso-joinBool (push a false i) = merid a i rightInv Susp-iso-joinBool (inr true ) = refl rightInv Susp-iso-joinBool (inr false) = refl rightInv Susp-iso-joinBool (inl a) = sym (push a true) rightInv Susp-iso-joinBool (push a true i) j = push a true (i ∨ ~ j) rightInv Susp-iso-joinBool (push a false i) j = hcomp (λ k → λ { (i = i0) → push a true (~ j) ; (i = i1) → push a false k ; (j = i1) → push a false (i ∧ k) }) (push a true (~ i ∧ ~ j)) leftInv Susp-iso-joinBool north = refl leftInv Susp-iso-joinBool south = refl leftInv (Susp-iso-joinBool {A = A}) (merid a i) j = hcomp (λ k → λ { (i = i0) → transp (λ _ → Susp A) (k ∨ j) north ; (i = i1) → transp (λ _ → Susp A) (k ∨ j) (merid a k) ; (j = i1) → merid a (i ∧ k) }) (transp (λ _ → Susp A) j north) Susp≃joinBool : ∀ {ℓ} {A : Type ℓ} → Susp A ≃ join A Bool Susp≃joinBool = isoToEquiv Susp-iso-joinBool Susp≡joinBool : ∀ {ℓ} {A : Type ℓ} → Susp A ≡ join A Bool Susp≡joinBool = isoToPath Susp-iso-joinBool congSuspEquiv : ∀ {ℓ} {A B : Type ℓ} → A ≃ B → Susp A ≃ Susp B congSuspEquiv {ℓ} {A} {B} h = isoToEquiv isom where isom : Iso (Susp A) (Susp B) Iso.fun isom north = north Iso.fun isom south = south Iso.fun isom (merid a i) = merid (fst h a) i Iso.inv isom north = north Iso.inv isom south = south Iso.inv isom (merid a i) = merid (invEq h a) i Iso.rightInv isom north = refl Iso.rightInv isom south = refl Iso.rightInv isom (merid a i) j = merid (retEq h a j) i Iso.leftInv isom north = refl Iso.leftInv isom south = refl Iso.leftInv isom (merid a i) j = merid (secEq h a j) i suspToPropElim : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Susp A → Type ℓ'} (a : A) → ((x : Susp A) → isProp (B x)) → B north → (x : Susp A) → B x suspToPropElim a isProp Bnorth north = Bnorth suspToPropElim {B = B} a isProp Bnorth south = subst B (merid a) Bnorth suspToPropElim {B = B} a isProp Bnorth (merid a₁ i) = isOfHLevel→isOfHLevelDep 1 isProp Bnorth (subst B (merid a) Bnorth) (merid a₁) i suspToPropElim2 : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Susp A → Susp A → Type ℓ'} (a : A) → ((x y : Susp A) → isProp (B x y)) → B north north → (x y : Susp A) → B x y suspToPropElim2 _ _ Bnorth north north = Bnorth suspToPropElim2 {B = B} a _ Bnorth north south = subst (B north) (merid a) Bnorth suspToPropElim2 {B = B} a isprop Bnorth north (merid x i) = isProp→PathP (λ i → isprop north (merid x i)) Bnorth (subst (B north) (merid a) Bnorth) i suspToPropElim2 {B = B} a _ Bnorth south north = subst (λ x → B x north) (merid a) Bnorth suspToPropElim2 {B = B} a _ Bnorth south south = subst (λ x → B x x) (merid a) Bnorth suspToPropElim2 {B = B} a isprop Bnorth south (merid x i) = isProp→PathP (λ i → isprop south (merid x i)) (subst (λ x → B x north) (merid a) Bnorth) (subst (λ x → B x x) (merid a) Bnorth) i suspToPropElim2 {B = B} a isprop Bnorth (merid x i) north = isProp→PathP (λ i → isprop (merid x i) north) Bnorth (subst (λ x → B x north) (merid a) Bnorth) i suspToPropElim2 {B = B} a isprop Bnorth (merid x i) south = isProp→PathP (λ i → isprop (merid x i) south) (subst (B north) (merid a) Bnorth) (subst (λ x → B x x) (merid a) Bnorth) i suspToPropElim2 {B = B} a isprop Bnorth (merid x i) (merid y j) = isSet→SquareP (λ i j → isOfHLevelSuc 1 (isprop _ _)) (isProp→PathP (λ i₁ → isprop north (merid y i₁)) Bnorth (subst (B north) (merid a) Bnorth)) (isProp→PathP (λ i₁ → isprop south (merid y i₁)) (subst (λ x₁ → B x₁ north) (merid a) Bnorth) (subst (λ x₁ → B x₁ x₁) (merid a) Bnorth)) (isProp→PathP (λ i₁ → isprop (merid x i₁) north) Bnorth (subst (λ x₁ → B x₁ north) (merid a) Bnorth)) (isProp→PathP (λ i₁ → isprop (merid x i₁) south) (subst (B north) (merid a) Bnorth) (subst (λ x₁ → B x₁ x₁) (merid a) Bnorth)) i j {- Clever proof: suspToPropElim2 a isProp Bnorth = suspToPropElim a (λ x → isOfHLevelΠ 1 λ y → isProp x y) (suspToPropElim a (λ x → isProp north x) Bnorth) -}
{ "alphanum_fraction": 0.5955882353, "avg_line_length": 46.1428571429, "ext": "agda", "hexsha": "b03c56a2ced7ec54b885a4e33a661f3f7a5d0431", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_path": "Cubical/HITs/Susp/Properties.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_path": "Cubical/HITs/Susp/Properties.agda", "max_line_length": 89, "max_stars_count": null, "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_path": "Cubical/HITs/Susp/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1885, "size": 5168 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Fancy display functions for List-based tables ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module Text.Tabular.List where open import Data.String using (String) open import Data.List.Base import Data.Nat.Properties as ℕₚ open import Data.Product using (-,_; proj₂) open import Data.Vec.Base as Vec using (Vec) open import Data.Vec.Bounded.Base as Vec≤ using (Vec≤) open import Function.Base open import Text.Tabular.Base import Text.Tabular.Vec as Show display : TabularConfig → List Alignment → List (List String) → List String display c a rows = Show.display c alignment rectangle where alignment : Vec Alignment _ alignment = Vec≤.padRight Left $ Vec≤.≤-cast (ℕₚ.m⊓n≤m _ _) $ Vec≤.take _ (Vec≤.fromList a) rectangle : Vec (Vec String _) _ rectangle = Vec.fromList $ map (Vec≤.padRight "") $ proj₂ $ Vec≤.rectangle $ map (λ row → -, Vec≤.fromList row) rows
{ "alphanum_fraction": 0.581915846, "avg_line_length": 31.0277777778, "ext": "agda", "hexsha": "8a007bbeb3a02223892d08ea9c477847cb62326e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Text/Tabular/List.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Text/Tabular/List.agda", "max_line_length": 75, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Text/Tabular/List.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 270, "size": 1117 }
-- Andreas, Ulf, 2015-06-03 -- Issue 473 was not fixed for records without constructor record _×_ A B : Set where constructor _,_ field fst : A snd : B open _×_ data Nat : Set where zero : Nat suc : Nat → Nat data Zero : Nat → Set where zero : Zero zero data Zero₂ : Nat → Nat → Set where zero : Zero₂ zero zero f₁ : (p : Nat × Nat) → Zero₂ (fst p) (snd p) → Set f₁ (.zero , .zero) zero = Nat -- works -- f₁ .(zero , zero) zero = Nat -- fails f₂ : (p : Nat × Nat) → Zero (fst p) → Set f₂ (.zero , y) zero = Nat -- works -- foo .?? zero -- fails (nothing to write in place of ??) f₃ : {p : Nat × Nat} → Zero (fst p) → Set f₃ zero = Nat f₄ : {p : Nat × (Nat × Nat)} → Zero (fst (snd p)) → Set f₄ zero = Nat f₅ : {p : Nat × Nat} → Zero₂ (fst p) (snd p) → Set f₅ zero = Nat data I : Set where i : I record Box (A B : Set) : Set where -- no constructor [_] field contents : A [_] : ∀{A B} → A → Box A B [ a ] = record { contents = a } data D : Set → Set₁ where d₁ : (R : Set) → D R d₂ : (i : I) (R : I → Set) → D (R i) → D (Box I (R i)) data S : (R : Set) → R → D R → Set₁ where s : (j : I) (R : I → Set) (p : D (R j)) → S (Box I (R j)) [ j ] (d₂ j R p) postulate P : I → Set Fails : {e : Box I (P i)} → S (Box I (P i)) e (d₂ i P (d₁ (P i))) → Set₁ Fails (s .i .P .(d₁ (P i))) = Set -- Refuse to solve heterogeneous constraint p : D (P (Box.contents e)) -- =?= d₁ (P i) : D (P i) -- when checking that the pattern s .i .P .(d₁ (P i)) has type -- S (Box I (P i)) e (d₂ i P (d₁ (P i)))
{ "alphanum_fraction": 0.5231660232, "avg_line_length": 23.5454545455, "ext": "agda", "hexsha": "2c1ec35da281de8cd8f7defd0d61fb6224d8ecb0", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_path": "test/Succeed/Issue473b.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "redfish64/autonomic-agda", "max_issues_repo_path": "test/Succeed/Issue473b.agda", "max_line_length": 72, "max_stars_count": 3, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Succeed/Issue473b.agda", "max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z", "num_tokens": 623, "size": 1554 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Monoid.MorphismProperties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.HLevels open import Cubical.Foundations.Univalence open import Cubical.Foundations.SIP open import Cubical.Foundations.Function using (_∘_; id) open import Cubical.Foundations.GroupoidLaws open import Cubical.Functions.Embedding open import Cubical.Data.Sigma open import Cubical.Algebra open import Cubical.Algebra.Properties open import Cubical.Algebra.Monoid.Morphism open import Cubical.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Pointed open import Cubical.Algebra.Semigroup.Properties using (isPropIsSemigroup) open import Cubical.Relation.Binary.Reasoning.Equality open Iso private variable ℓ ℓ′ ℓ′′ : Level L : Monoid ℓ M : Monoid ℓ′ N : Monoid ℓ′′ isPropIsMonoidHom : ∀ (M : Monoid ℓ) (N : Monoid ℓ′) f → isProp (IsMonoidHom M N f) isPropIsMonoidHom M N f (ismonoidhom aOp aId) (ismonoidhom bOp bId) = cong₂ ismonoidhom (isPropHomomorphic₂ (Monoid.is-set N) f (Monoid._•_ M) (Monoid._•_ N) aOp bOp) (isPropHomomorphic₀ (Monoid.is-set N) f (Monoid.ε M) (Monoid.ε N) aId bId) isSetMonoidHom : isSet (M ⟶ᴴ N) isSetMonoidHom {M = M} {N = N} = isOfHLevelRespectEquiv 2 equiv (isSetΣ (isSetΠ λ _ → is-set N) (λ f → isProp→isSet (isPropIsMonoidHom M N f))) where open Monoid equiv : (Σ[ g ∈ (⟨ M ⟩ → ⟨ N ⟩) ] IsMonoidHom M N g) ≃ MonoidHom M N equiv = isoToEquiv (iso (λ (g , m) → monoidhom g m) (λ (monoidhom g m) → g , m) (λ _ → refl) λ _ → refl) isMonoidHomComp : {f : ⟨ L ⟩ → ⟨ M ⟩} {g : ⟨ M ⟩ → ⟨ N ⟩} → IsMonoidHom L M f → IsMonoidHom M N g → IsMonoidHom L N (g ∘ f) isMonoidHomComp {g = g} (ismonoidhom fOp fId) (ismonoidhom gOp gId) = ismonoidhom (λ _ _ → cong g (fOp _ _) ∙ gOp _ _) (cong g fId ∙ gId) private isMonoidHomComp′ : (f : L ⟶ᴴ M) (g : M ⟶ᴴ N) → IsMonoidHom L N (MonoidHom.fun g ∘ MonoidHom.fun f) isMonoidHomComp′ (monoidhom f (ismonoidhom fOp fId)) (monoidhom g (ismonoidhom gOp gId)) = ismonoidhom (λ _ _ → cong g (fOp _ _) ∙ gOp _ _) (cong g fId ∙ gId) compMonoidHom : (L ⟶ᴴ M) → (M ⟶ᴴ N) → (L ⟶ᴴ N) compMonoidHom f g = monoidhom _ (isMonoidHomComp′ f g) compMonoidEquiv : L ≃ᴴ M → M ≃ᴴ N → L ≃ᴴ N compMonoidEquiv f g = monoidequiv (compEquiv f.eq g.eq) (isMonoidHomComp′ f.hom g.hom) where module f = MonoidEquiv f module g = MonoidEquiv g isMonoidHomId : (M : Monoid ℓ) → IsMonoidHom M M id isMonoidHomId M = record { preservesOp = λ _ _ → refl ; preservesId = refl } idMonoidHom : (M : Monoid ℓ) → (M ⟶ᴴ M) idMonoidHom M = record { fun = id ; isHom = isMonoidHomId M } idMonoidEquiv : (M : Monoid ℓ) → M ≃ᴴ M idMonoidEquiv M = record { eq = idEquiv ⟨ M ⟩ ; isHom = isMonoidHomId M } -- Isomorphism inversion isMonoidHomInv : (eqv : M ≃ᴴ N) → IsMonoidHom N M (invEq (MonoidEquiv.eq eqv)) isMonoidHomInv {M = M} {N = N} (monoidequiv eq (ismonoidhom hOp hId)) = ismonoidhom (λ x y → isInj-f ( f (f⁻¹ (x N.• y)) ≡⟨ retEq eq _ ⟩ x N.• y ≡˘⟨ cong₂ N._•_ (retEq eq x) (retEq eq y) ⟩ f (f⁻¹ x) N.• f (f⁻¹ y) ≡˘⟨ hOp (f⁻¹ x) (f⁻¹ y) ⟩ f (f⁻¹ x M.• f⁻¹ y) ∎)) (isInj-f ( f (f⁻¹ N.ε) ≡⟨ retEq eq _ ⟩ N.ε ≡˘⟨ hId ⟩ f M.ε ∎)) where module M = Monoid M module N = Monoid N f = equivFun eq f⁻¹ = invEq eq isInj-f : {x y : ⟨ M ⟩} → f x ≡ f y → x ≡ y isInj-f {x} {y} = invEq (_ , isEquiv→isEmbedding (eq .snd) x y) invMonoidHom : M ≃ᴴ N → (N ⟶ᴴ M) invMonoidHom eq = record { isHom = isMonoidHomInv eq } invMonoidEquiv : M ≃ᴴ N → N ≃ᴴ M invMonoidEquiv eq = record { eq = invEquiv (MonoidEquiv.eq eq) ; isHom = isMonoidHomInv eq } monoidHomEq : {f g : M ⟶ᴴ N} → MonoidHom.fun f ≡ MonoidHom.fun g → f ≡ g monoidHomEq {M = M} {N = N} {monoidhom f fm} {monoidhom g gm} p i = monoidhom (p i) (p-hom i) where p-hom : PathP (λ i → IsMonoidHom M N (p i)) fm gm p-hom = toPathP (isPropIsMonoidHom M N _ _ _) monoidEquivEq : {f g : M ≃ᴴ N} → MonoidEquiv.eq f ≡ MonoidEquiv.eq g → f ≡ g monoidEquivEq {M = M} {N = N} {monoidequiv f fm} {monoidequiv g gm} p i = monoidequiv (p i) (p-hom i) where p-hom : PathP (λ i → IsMonoidHom M N (p i .fst)) fm gm p-hom = toPathP (isPropIsMonoidHom M N _ _ _) module MonoidΣTheory {ℓ} where RawMonoidStructure : Type ℓ → Type ℓ RawMonoidStructure X = (X → X → X) × X RawMonoidEquivStr = AutoEquivStr RawMonoidStructure rawMonoidUnivalentStr : UnivalentStr _ RawMonoidEquivStr rawMonoidUnivalentStr = autoUnivalentStr RawMonoidStructure MonoidAxioms : (M : Type ℓ) → RawMonoidStructure M → Type ℓ MonoidAxioms M (_•_ , ε) = IsSemigroup M _•_ × Identity ε _•_ MonoidStructure : Type ℓ → Type ℓ MonoidStructure = AxiomsStructure RawMonoidStructure MonoidAxioms MonoidΣ : Type (ℓ-suc ℓ) MonoidΣ = TypeWithStr ℓ MonoidStructure isPropMonoidAxioms : (M : Type ℓ) (s : RawMonoidStructure M) → isProp (MonoidAxioms M s) isPropMonoidAxioms M (_•_ , ε) = isPropΣ isPropIsSemigroup λ isSemiM → isPropIdentity (IsSemigroup.is-set isSemiM) _•_ ε MonoidEquivStr : StrEquiv MonoidStructure ℓ MonoidEquivStr = AxiomsEquivStr RawMonoidEquivStr MonoidAxioms MonoidAxiomsIsoIsMonoid : {M : Type ℓ} (s : RawMonoidStructure M) → Iso (MonoidAxioms M s) (IsMonoid M (s .fst) (s .snd)) fun (MonoidAxiomsIsoIsMonoid s) (x , y) = ismonoid x y inv (MonoidAxiomsIsoIsMonoid s) (ismonoid x y) = (x , y) rightInv (MonoidAxiomsIsoIsMonoid s) _ = refl leftInv (MonoidAxiomsIsoIsMonoid s) _ = refl MonoidAxioms≡IsMonoid : {M : Type ℓ} (s : RawMonoidStructure M) → MonoidAxioms M s ≡ IsMonoid M (s .fst) (s .snd) MonoidAxioms≡IsMonoid s = isoToPath (MonoidAxiomsIsoIsMonoid s) Monoid→MonoidΣ : Monoid ℓ → MonoidΣ Monoid→MonoidΣ (mkmonoid M _•_ ε isMonoidM) = M , (_•_ , ε) , MonoidAxiomsIsoIsMonoid (_•_ , ε) .inv isMonoidM MonoidΣ→Monoid : MonoidΣ → Monoid ℓ MonoidΣ→Monoid (M , (_•_ , ε) , isMonoidM) = mkmonoid M _•_ ε (MonoidAxiomsIsoIsMonoid (_•_ , ε) .fun isMonoidM) MonoidIsoMonoidΣ : Iso (Monoid ℓ) MonoidΣ MonoidIsoMonoidΣ = iso Monoid→MonoidΣ MonoidΣ→Monoid (λ _ → refl) (λ _ → refl) monoidUnivalentStr : UnivalentStr MonoidStructure MonoidEquivStr monoidUnivalentStr = axiomsUnivalentStr _ isPropMonoidAxioms rawMonoidUnivalentStr MonoidΣPath : (M N : MonoidΣ) → (M ≃[ MonoidEquivStr ] N) ≃ (M ≡ N) MonoidΣPath = SIP monoidUnivalentStr MonoidEquivΣ : (M N : Monoid ℓ) → Type ℓ MonoidEquivΣ M N = Monoid→MonoidΣ M ≃[ MonoidEquivStr ] Monoid→MonoidΣ N MonoidIsoΣPath : {M N : Monoid ℓ} → Iso (MonoidEquiv M N) (MonoidEquivΣ M N) fun MonoidIsoΣPath (monoidequiv eq (ismonoidhom hOp hId)) = (eq , hOp , hId) inv MonoidIsoΣPath (eq , hOp , hId) = monoidequiv eq (ismonoidhom hOp hId) rightInv MonoidIsoΣPath _ = refl leftInv MonoidIsoΣPath _ = refl MonoidPath : (M N : Monoid ℓ) → (MonoidEquiv M N) ≃ (M ≡ N) MonoidPath M N = MonoidEquiv M N ≃⟨ isoToEquiv MonoidIsoΣPath ⟩ MonoidEquivΣ M N ≃⟨ MonoidΣPath _ _ ⟩ Monoid→MonoidΣ M ≡ Monoid→MonoidΣ N ≃⟨ isoToEquiv (invIso (congIso MonoidIsoMonoidΣ)) ⟩ M ≡ N ■ RawMonoidΣ : Type (ℓ-suc ℓ) RawMonoidΣ = TypeWithStr ℓ RawMonoidStructure Monoid→RawMonoidΣ : Monoid ℓ → RawMonoidΣ Monoid→RawMonoidΣ (mkmonoid A _•_ ε _) = A , _•_ , ε InducedMonoid : (M : Monoid ℓ) (N : RawMonoidΣ) (e : M .Monoid.Carrier ≃ N .fst) → RawMonoidEquivStr (Monoid→RawMonoidΣ M) N e → Monoid ℓ InducedMonoid M N e r = MonoidΣ→Monoid (inducedStructure rawMonoidUnivalentStr (Monoid→MonoidΣ M) N (e , r)) InducedMonoidPath : (M : Monoid ℓ) (N : RawMonoidΣ) (e : M .Monoid.Carrier ≃ N .fst) (E : RawMonoidEquivStr (Monoid→RawMonoidΣ M) N e) → M ≡ InducedMonoid M N e E InducedMonoidPath M N e E = MonoidPath M (InducedMonoid M N e E) .fst (monoidequiv e (ismonoidhom (E .fst) (E .snd))) -- We now extract the important results from the above module open MonoidΣTheory public using (InducedMonoid; InducedMonoidPath) isPropIsMonoid : {M : Type ℓ} {_•_ : Op₂ M} {ε : M} → isProp (IsMonoid M _•_ ε) isPropIsMonoid {_•_ = _•_} {ε} = subst isProp (MonoidΣTheory.MonoidAxioms≡IsMonoid (_•_ , ε)) (MonoidΣTheory.isPropMonoidAxioms _ (_•_ , ε)) MonoidPath : (M ≃ᴴ N) ≃ (M ≡ N) MonoidPath {M = M} {N} = MonoidΣTheory.MonoidPath M N open Monoid uaMonoid : M ≃ᴴ N → M ≡ N uaMonoid = equivFun MonoidPath carac-uaMonoid : {M N : Monoid ℓ} (f : M ≃ᴴ N) → cong Carrier (uaMonoid f) ≡ ua (MonoidEquiv.eq f) carac-uaMonoid (monoidequiv f m) = (refl ∙∙ ua f ∙∙ refl) ≡˘⟨ rUnit (ua f) ⟩ ua f ∎ Monoid≡ : (M N : Monoid ℓ) → ( Σ[ p ∈ ⟨ M ⟩ ≡ ⟨ N ⟩ ] Σ[ q ∈ PathP (λ i → p i → p i → p i) (_•_ M) (_•_ N) ] Σ[ r ∈ PathP (λ i → p i) (ε M) (ε N) ] PathP (λ i → IsMonoid (p i) (q i) (r i)) (isMonoid M) (isMonoid N)) ≃ (M ≡ N) Monoid≡ M N = isoToEquiv (iso (λ (p , q , r , s) i → mkmonoid (p i) (q i) (r i) (s i)) (λ p → cong Carrier p , cong _•_ p , cong ε p , cong isMonoid p) (λ _ → refl) (λ _ → refl)) caracMonoid≡ : {M N : Monoid ℓ} (p q : M ≡ N) → cong Carrier p ≡ cong Carrier q → p ≡ q caracMonoid≡ {M = M} {N} p q t = cong (fst (Monoid≡ M N)) (Σ≡Prop (λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set N) _ _) λ _ → isPropΣ (isOfHLevelPathP' 1 (is-set N) _ _) λ _ → isOfHLevelPathP 1 isPropIsMonoid _ _) t) uaMonoidId : (M : Monoid ℓ) → uaMonoid (idMonoidEquiv M) ≡ refl uaMonoidId M = caracMonoid≡ _ _ (carac-uaMonoid (idMonoidEquiv M) ∙ uaIdEquiv) uaCompMonoidEquiv : {L M N : Monoid ℓ} (f : L ≃ᴴ M) (g : M ≃ᴴ N) → uaMonoid (compMonoidEquiv f g) ≡ uaMonoid f ∙ uaMonoid g uaCompMonoidEquiv f g = caracMonoid≡ _ _ ( cong Carrier (uaMonoid (compMonoidEquiv f g)) ≡⟨ carac-uaMonoid (compMonoidEquiv f g) ⟩ ua (eq (compMonoidEquiv f g)) ≡⟨ uaCompEquiv _ _ ⟩ ua (eq f) ∙ ua (eq g) ≡˘⟨ cong (_∙ ua (eq g)) (carac-uaMonoid f) ⟩ cong Carrier (uaMonoid f) ∙ ua (eq g) ≡˘⟨ cong (cong Carrier (uaMonoid f) ∙_) (carac-uaMonoid g) ⟩ cong Carrier (uaMonoid f) ∙ cong Carrier (uaMonoid g) ≡˘⟨ cong-∙ Carrier (uaMonoid f) (uaMonoid g) ⟩ cong Carrier (uaMonoid f ∙ uaMonoid g) ∎) where open MonoidEquiv
{ "alphanum_fraction": 0.6286266925, "avg_line_length": 38.775, "ext": "agda", "hexsha": "e8e8eec236afcb7d03e0cc8829493e7162a1d2e4", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bijan2005/univalent-foundations", "max_forks_repo_path": "Cubical/Algebra/Monoid/MorphismProperties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bijan2005/univalent-foundations", "max_issues_repo_path": "Cubical/Algebra/Monoid/MorphismProperties.agda", "max_line_length": 108, "max_stars_count": null, "max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bijan2005/univalent-foundations", "max_stars_repo_path": "Cubical/Algebra/Monoid/MorphismProperties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4473, "size": 10857 }
module json where open import lib open import general-util data json : Set where json-null : json json-raw : rope → json json-string : string → json json-nat : nat → json json-array : 𝕃 json → json json-object : trie json → json json-escape-string : string → string json-escape-string str = 𝕃char-to-string $ rec $ string-to-𝕃char str where rec : 𝕃 char → 𝕃 char rec [] = [] rec ('\b' :: chars) = '\\' :: 'b' :: rec chars rec ('\f' :: chars) = '\\' :: 'f' :: rec chars rec ('\n' :: chars) = '\\' :: 'n' :: rec chars rec ('\r' :: chars) = '\\' :: 'r' :: rec chars rec ('\t' :: chars) = '\\' :: 't' :: rec chars rec ('"' :: chars) = '\\' :: '"' :: rec chars rec ('\\' :: chars) = '\\' :: '\\' :: rec chars rec (char :: chars) = char :: rec chars {-# TERMINATING #-} json-to-rope : json → rope json-to-rope json-null = [[ "null" ]] json-to-rope (json-raw rope) = rope json-to-rope (json-string string) = [[ "\"" ]] ⊹⊹ [[ json-escape-string string ]] ⊹⊹ [[ "\"" ]] json-to-rope (json-nat nat) = [[ ℕ-to-string nat ]] json-to-rope (json-array array) = [[ "[" ]] ⊹⊹ 𝕃-to-rope json-to-rope "," array ⊹⊹ [[ "]" ]] json-to-rope (json-object t) = [[ "{" ]] ⊹⊹ 𝕃-to-rope key-to-rope "," (trie-strings t) ⊹⊹ [[ "}" ]] where key-to-rope : string → rope key-to-rope key with trie-lookup t key ...| just value = [[ "\"" ]] ⊹⊹ [[ json-escape-string key ]] ⊹⊹ [[ "\":" ]] ⊹⊹ json-to-rope value ...| nothing = [[ "\"" ]] ⊹⊹ [[ json-escape-string key ]] ⊹⊹ [[ "\":null" ]] -- shouldn't happen json-new : 𝕃 (string × json) → json json-new pairs = json-object $ foldr insert empty-trie pairs where insert : string × json → trie json → trie json insert (key , value) trie = trie-insert trie key value
{ "alphanum_fraction": 0.5494505495, "avg_line_length": 39.2954545455, "ext": "agda", "hexsha": "e98cfe0f94c6a3265ba0fd2319dcfea28831dd54", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CarlOlson/cedille", "max_forks_repo_path": "src/json.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "CarlOlson/cedille", "max_issues_repo_path": "src/json.agda", "max_line_length": 105, "max_stars_count": null, "max_stars_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CarlOlson/cedille", "max_stars_repo_path": "src/json.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 588, "size": 1729 }
-- Andreas, 2017-07-05, issue #2626 raised by cartazio -- shrunk by gallais -- There was an assignTerm inspite of -- dontAssignMetas (issued by checking inequations involving ⊔ˢ) -- {-# OPTIONS -v tc:45 #-} {-# OPTIONS --allow-unsolved-metas #-} module Issue2626 where open import Agda.Builtin.Equality open import Agda.Builtin.Size data D : (sz : Size) → Set where c : (q s : Size) → D (q ⊔ˢ s) postulate foo : c _ _ ≡ c _ _
{ "alphanum_fraction": 0.6750572082, "avg_line_length": 20.8095238095, "ext": "agda", "hexsha": "86aac6ecc239b08e6bf1cb957d31ab12daf16878", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z", "max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue2626.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue2626.agda", "max_line_length": 64, "max_stars_count": 2, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue2626.agda", "max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z", "num_tokens": 143, "size": 437 }
module Example where import Level open import Signature open import Function open import Data.Empty open import Data.Unit open import Data.Nat open import Data.Fin open import Data.Product as Prod renaming (Σ to ⨿) open import Data.Sum as Sum open import Relation.Nullary open import Relation.Unary hiding (_⇒_) open import Relation.Binary.PropositionalEquality hiding ([_]) open ≡-Reasoning postulate ext : Extensionality Level.zero Level.zero ------ -- Examples ----- module NatProg where Σ : Sig ∥ Σ ∥ = Fin 3 ar Σ zero = Fin 0 -- 0 ar Σ (suc zero) = Fin 1 -- succ ar Σ (suc (suc _)) = Fin 1 -- nat open import Terms Σ V = ℕ Z S N : ∥ Σ ∥ Z = # 0 S = # 1 N = # 2 z : T V z = μ (ι (Z , (λ ()))) s nat : T V → T V s t = μ (ι (S , (λ _ → t))) nat t = μ (ι (N , (λ _ → t))) z∞ : T∞ V z∞ = χ z s∞ nat∞ : ∀{X} → T∞ X → T∞ X s∞ t = μ∞ (ι∞ (S , (λ _ → t))) nat∞ t = μ∞ (ι∞ (N , (λ _ → t))) inf : T∞ ⊥ inf = corec (λ x → inj₁ (S , (λ _ → tt))) tt inf-nat : T∞ ⊥ inf-nat = nat∞ inf open import Program Σ V -- | Program consisting of -- ⇒ nat(0) -- nat(n) ⇒ nat(s n) P : Program P = ((0 , (λ ())) , ( , clauses)) where clauses : Fin 2 → Clause clauses zero = (0 , (λ ())) ⊢ nat z clauses (suc _) = (1 , b) ⊢ nat (s n) where n = η 0 b : Fin 1 → T V b _ = nat n open import Herbrand Σ V P lem : ¬ (∃ λ σ → (inf ~ app∞ σ (χ (geth-ν P (# 0))))) lem (σ , p) with out~ p lem (σ , p) | () , _ bad-ν : inf-nat ∈ Herbrand-ν bw-closed bad-ν = inj₁ p where p : (i : dom-ν P) {σ : V → T∞ ⊥} → inf-nat ~ (app∞ σ (χ (geth-ν P i))) → (j : dom (getb-ν P i)) → app∞ σ (χ (get (getb-ν P i) j)) ∈ Herbrand-ν {- p i {σ} p j with out inf-nat | out (σ 0) | out~ p p i p j | inj₁ (zero , α) | v | r = {!!} p i p j | inj₁ (suc zero , α) | v | r = {!!} p i p j | inj₁ (suc (suc _) , α) | v | r = {!!} p i p j | inj₂ () | v | r -} p i {σ} p j with out (σ 0) | out~ p p zero p () | u | refl , r p (suc i) p zero | inj₁ (zero , _) | refl , r = {!!} p (suc i) p zero | inj₁ (suc zero , _) | refl , r = {!!} p (suc i) p zero | inj₁ (suc (suc _) , proj₂) | refl , r = {!!} p (suc i) p zero | inj₂ () | refl , r p (suc _) p (suc ()) | u | refl , r {- f : ? f i {σ} p j with out~ p ... | u = ? -} bad : inf-nat ∈ Herbrand-μ bad = coind-μ bad-ν {- module BitList where Σ : Sig ∥ Σ ∥ = Fin 6 ar Σ zero = Fin 0 -- 0 ar Σ (suc zero) = Fin 0 -- 1 ar Σ (suc (suc zero)) = Fin 1 -- bit(x) ar Σ (suc (suc (suc zero))) = Fin 1 -- blist(x) ar Σ (suc (suc (suc (suc zero)))) = Fin 0 -- nil ar Σ (suc (suc (suc (suc (suc f))))) = Fin 2 -- cons(x,y) open import Terms Σ V = ℕ Z O Bit BList Nil Cons : ∥ Σ ∥ Z = # 0 O = # 1 Bit = # 2 BList = # 3 Nil = # 4 Cons = # 5 z o nil : T V z = μ (ι (Z , (λ ()))) o = μ (ι (O , (λ ()))) nil = μ (ι (Nil , (λ ()))) bit blist : T V → T V bit t = μ (ι (Bit , (λ _ → t))) blist t = μ (ι (BList , (λ _ → t))) bin-branch : {X : Set} → X → X → Fin 2 → X bin-branch x y zero = x bin-branch x y (suc _) = y cons-br-distr : ∀{X Y} (t s : X) (f : X → Y) → f ∘ bin-branch t s ≡ bin-branch (f t) (f s) cons-br-distr t s f = ext p where p : (i : Fin 2) → f (bin-branch t s i) ≡ bin-branch (f t) (f s) i p zero = refl p (suc _) = refl cons : T V → T V → T V cons t s = μ (ι (Cons , bin-branch t s)) bit0 bit1 : T V bit0 = bit z bit1 = bit o open import Program Σ V -- | Program consisting of -- ⇒ bit(0) -- ⇒ bit(1) -- ⇒ blist(nil) -- bit(x), blist(y) ⇒ blist(cons(x,y)) P : Program P = , clauses where clauses : Fin 4 → Clause clauses zero = (0 , (λ ())) ⊢ bit0 clauses (suc zero) = (0 , (λ ())) ⊢ bit1 clauses (suc (suc zero)) = (0 , (λ ())) ⊢ nil clauses (suc (suc (suc c))) = (2 , b) ⊢ blist (cons (η 0) (η 1)) where b : Fin 2 → T V b zero = bit (η 0) b (suc i) = blist (η 1) open import Rewrite Σ V P X S bitX : T V X = η 0 S = blist (cons X (cons X nil)) bitX = bit X bitX-val : Val bitX bitX-val zero () x bitX-val (suc zero) () x bitX-val (suc (suc zero)) () x bitX-val (suc (suc (suc _))) zero () bitX-val (suc (suc (suc _))) (suc _) () step1 : S ⟿ bitX step1 = rew-step (# 3) (# 0) {σ} σ-match where σ : Subst V V σ zero = X σ (suc zero) = cons X nil σ (suc (suc n)) = η (suc (suc n)) σ-match : matches (geth P (# 3)) S σ σ-match = begin app σ (blist (cons X (η 1))) ≡⟨ refl ⟩ μ (T₁ σ (blist (cons X (η 1)))) ≡⟨ refl ⟩ μ (T₁ σ (μ (ι (BList , (λ _ → (cons X (η 1))))))) ≡⟨ refl ⟩ μ (μ (ι (BList , (λ _ → T₁ σ (cons X (η 1)))))) ≡⟨ refl ⟩ μ (μ (ι (BList , (λ _ → T₁ σ (μ (ι (Cons , bin-branch X (η 1)))))))) ≡⟨ refl ⟩ μ (μ (ι (BList , (λ _ → μ (ι (Cons , T₁ σ ∘ (bin-branch X (η 1)))))))) ≡⟨ cong (λ u → μ (μ (ι (BList , (λ _ → μ (ι (Cons , u))))))) (cons-br-distr X (η 1) (T₁ σ)) ⟩ μ (μ (ι (BList , (λ _ → μ (ι (Cons , (bin-branch (T₁ σ X) (T₁ σ (η 1))))))))) ≡⟨ refl ⟩ μ (μ (ι (BList , (λ _ → μ (ι (Cons , (bin-branch (η (σ 0)) (η (σ 1))))))))) ≡⟨ cong (λ u → μ (μ (ι (BList , (λ _ → μ (ι (Cons , u))))))) (sym (cons-br-distr (σ 0) (σ 1) η)) ⟩ μ (μ (ι (BList , (λ _ → μ (ι (Cons , (η ∘ (bin-branch (σ 0) (σ 1))))))))) ≡⟨ refl ⟩ blist (cons (σ 0) (σ 1)) ≡⟨ refl ⟩ blist (cons X (cons X nil)) ≡⟨ refl ⟩ S ∎ term1 : S ↓ bitX term1 = step bitX bitX (val bitX-val) step1 -- Problem: The substitution needs to match _all_ leaves!!! -}
{ "alphanum_fraction": 0.424696873, "avg_line_length": 25.5836734694, "ext": "agda", "hexsha": "1c0ad3acf58efa84553cf3a2ad9ced9369f50afc", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_path": "LP/Example.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_path": "LP/Example.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_path": "LP/Example.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2582, "size": 6268 }
open import Prelude open import Nat open import core module binders-disjoint-checks where -- these are fairly mechanical lemmas that show that the -- judgementally-defined binders-disjoint is really a type-directed -- function mutual lem-bdσ-lam : ∀{σ x τ d} → binders-disjoint-σ σ (·λ_[_]_ x τ d) → binders-disjoint-σ σ d lem-bdσ-lam BDσId = BDσId lem-bdσ-lam (BDσSubst x₁ bd) = BDσSubst (lem-bd-lam x₁) (lem-bdσ-lam bd) lem-bd-lam : ∀{ d1 x τ1 d} → binders-disjoint d1 (·λ_[_]_ x τ1 d) → binders-disjoint d1 d lem-bd-lam BDConst = BDConst lem-bd-lam BDVar = BDVar lem-bd-lam (BDLam bd (UBLam2 x₂ x₃)) = BDLam (lem-bd-lam bd) x₃ lem-bd-lam (BDHole x₁) = BDHole (lem-bdσ-lam x₁) lem-bd-lam (BDNEHole x₁ bd) = BDNEHole (lem-bdσ-lam x₁) (lem-bd-lam bd) lem-bd-lam (BDAp bd bd₁) = BDAp (lem-bd-lam bd) (lem-bd-lam bd₁) lem-bd-lam (BDCast bd) = BDCast (lem-bd-lam bd) lem-bd-lam (BDFailedCast bd) = BDFailedCast (lem-bd-lam bd) mutual lem-bdσ-hole : ∀{d u σ σ'} → binders-disjoint-σ σ ⦇⌜ d ⌟⦈⟨ u , σ' ⟩ → binders-disjoint-σ σ d lem-bdσ-hole BDσId = BDσId lem-bdσ-hole (BDσSubst x bd) = BDσSubst (lem-bd-hole x) (lem-bdσ-hole bd) lem-bd-hole : ∀{d1 d u σ} → binders-disjoint d1 ⦇⌜ d ⌟⦈⟨ u , σ ⟩ → binders-disjoint d1 d lem-bd-hole BDConst = BDConst lem-bd-hole BDVar = BDVar lem-bd-hole (BDLam bd (UBNEHole x₁ x₂)) = BDLam (lem-bd-hole bd) x₂ lem-bd-hole (BDHole x) = BDHole (lem-bdσ-hole x) lem-bd-hole (BDNEHole x bd) = BDNEHole (lem-bdσ-hole x) (lem-bd-hole bd) lem-bd-hole (BDAp bd bd₁) = BDAp (lem-bd-hole bd) (lem-bd-hole bd₁) lem-bd-hole (BDCast bd) = BDCast (lem-bd-hole bd) lem-bd-hole (BDFailedCast bd) = BDFailedCast (lem-bd-hole bd) mutual lem-bdσ-cast : ∀{σ d τ1 τ2} → binders-disjoint-σ σ (d ⟨ τ1 ⇒ τ2 ⟩) → binders-disjoint-σ σ d lem-bdσ-cast BDσId = BDσId lem-bdσ-cast (BDσSubst x bd) = BDσSubst (lem-bd-cast x) (lem-bdσ-cast bd) lem-bd-cast : ∀{d1 d τ1 τ2} → binders-disjoint d1 (d ⟨ τ1 ⇒ τ2 ⟩) → binders-disjoint d1 d lem-bd-cast BDConst = BDConst lem-bd-cast BDVar = BDVar lem-bd-cast (BDLam bd (UBCast x₁)) = BDLam (lem-bd-cast bd) x₁ lem-bd-cast (BDHole x) = BDHole (lem-bdσ-cast x) lem-bd-cast (BDNEHole x bd) = BDNEHole (lem-bdσ-cast x) (lem-bd-cast bd) lem-bd-cast (BDAp bd bd₁) = BDAp (lem-bd-cast bd) (lem-bd-cast bd₁) lem-bd-cast (BDCast bd) = BDCast (lem-bd-cast bd) lem-bd-cast (BDFailedCast bd) = BDFailedCast (lem-bd-cast bd) mutual lem-bdσ-failedcast : ∀{σ d τ1 τ2} → binders-disjoint-σ σ (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) → binders-disjoint-σ σ d lem-bdσ-failedcast BDσId = BDσId lem-bdσ-failedcast (BDσSubst x bd) = BDσSubst (lem-bd-failedcast x) (lem-bdσ-failedcast bd) lem-bd-failedcast : ∀{d1 d τ1 τ2} → binders-disjoint d1 (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) → binders-disjoint d1 d lem-bd-failedcast BDConst = BDConst lem-bd-failedcast BDVar = BDVar lem-bd-failedcast (BDLam bd (UBFailedCast x₁)) = BDLam (lem-bd-failedcast bd) x₁ lem-bd-failedcast (BDHole x) = BDHole (lem-bdσ-failedcast x) lem-bd-failedcast (BDNEHole x bd) = BDNEHole (lem-bdσ-failedcast x) (lem-bd-failedcast bd) lem-bd-failedcast (BDAp bd bd₁) = BDAp (lem-bd-failedcast bd) (lem-bd-failedcast bd₁) lem-bd-failedcast (BDCast bd) = BDCast (lem-bd-failedcast bd) lem-bd-failedcast (BDFailedCast bd) = BDFailedCast (lem-bd-failedcast bd) mutual lem-bdσ-into-cast : ∀{σ d τ1 τ2} → binders-disjoint-σ σ d → binders-disjoint-σ σ (d ⟨ τ1 ⇒ τ2 ⟩) lem-bdσ-into-cast BDσId = BDσId lem-bdσ-into-cast (BDσSubst x bd) = BDσSubst (lem-bd-into-cast x) (lem-bdσ-into-cast bd) lem-bd-into-cast : ∀{d1 d2 τ1 τ2} → binders-disjoint d1 d2 → binders-disjoint d1 (d2 ⟨ τ1 ⇒ τ2 ⟩) lem-bd-into-cast BDConst = BDConst lem-bd-into-cast BDVar = BDVar lem-bd-into-cast (BDLam bd x₁) = BDLam (lem-bd-into-cast bd) (UBCast x₁) lem-bd-into-cast (BDHole x) = BDHole (lem-bdσ-into-cast x) lem-bd-into-cast (BDNEHole x bd) = BDNEHole (lem-bdσ-into-cast x) (lem-bd-into-cast bd) lem-bd-into-cast (BDAp bd bd₁) = BDAp (lem-bd-into-cast bd) (lem-bd-into-cast bd₁) lem-bd-into-cast (BDCast bd) = BDCast (lem-bd-into-cast bd) lem-bd-into-cast (BDFailedCast bd) = BDFailedCast (lem-bd-into-cast bd)
{ "alphanum_fraction": 0.6514059958, "avg_line_length": 51.2261904762, "ext": "agda", "hexsha": "dfb56e6feb00feb0467bbae1fe9a9bc5ce11596e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_path": "binders-disjoint-checks.agda", "max_issues_count": 54, "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_path": "binders-disjoint-checks.agda", "max_line_length": 106, "max_stars_count": 16, "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_path": "binders-disjoint-checks.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "num_tokens": 1886, "size": 4303 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Left inverses ------------------------------------------------------------------------ module Function.LeftInverse where open import Data.Product open import Level import Relation.Binary.EqReasoning as EqReasoning open import Relation.Binary open import Function.Equality as Eq using (_⟶_; _⟨$⟩_) renaming (_∘_ to _⟪∘⟫_) open import Function.Equivalence using (Equivalence) open import Function.Injection using (Injective; Injection) import Relation.Binary.PropositionalEquality as P -- Left and right inverses. _LeftInverseOf_ : ∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} → To ⟶ From → From ⟶ To → Set _ _LeftInverseOf_ {From = From} f g = ∀ x → f ⟨$⟩ (g ⟨$⟩ x) ≈ x where open Setoid From _RightInverseOf_ : ∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} → To ⟶ From → From ⟶ To → Set _ f RightInverseOf g = g LeftInverseOf f -- The set of all left inverses between two setoids. record LeftInverse {f₁ f₂ t₁ t₂} (From : Setoid f₁ f₂) (To : Setoid t₁ t₂) : Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where field to : From ⟶ To from : To ⟶ From left-inverse-of : from LeftInverseOf to private open module F = Setoid From open module T = Setoid To open EqReasoning From injective : Injective to injective {x} {y} eq = begin x ≈⟨ F.sym (left-inverse-of x) ⟩ from ⟨$⟩ (to ⟨$⟩ x) ≈⟨ Eq.cong from eq ⟩ from ⟨$⟩ (to ⟨$⟩ y) ≈⟨ left-inverse-of y ⟩ y ∎ injection : Injection From To injection = record { to = to; injective = injective } equivalence : Equivalence From To equivalence = record { to = to ; from = from } to-from : ∀ {x y} → to ⟨$⟩ x T.≈ y → from ⟨$⟩ y F.≈ x to-from {x} {y} to-x≈y = begin from ⟨$⟩ y ≈⟨ Eq.cong from (T.sym to-x≈y) ⟩ from ⟨$⟩ (to ⟨$⟩ x) ≈⟨ left-inverse-of x ⟩ x ∎ -- The set of all right inverses between two setoids. RightInverse : ∀ {f₁ f₂ t₁ t₂} (From : Setoid f₁ f₂) (To : Setoid t₁ t₂) → Set _ RightInverse From To = LeftInverse To From -- The set of all left inverses from one set to another. (Read A ↞ B -- as "surjection from B to A".) infix 3 _↞_ _↞_ : ∀ {f t} → Set f → Set t → Set _ From ↞ To = LeftInverse (P.setoid From) (P.setoid To) -- Identity and composition. id : ∀ {s₁ s₂} {S : Setoid s₁ s₂} → LeftInverse S S id {S = S} = record { to = Eq.id ; from = Eq.id ; left-inverse-of = λ _ → Setoid.refl S } infixr 9 _∘_ _∘_ : ∀ {f₁ f₂ m₁ m₂ t₁ t₂} {F : Setoid f₁ f₂} {M : Setoid m₁ m₂} {T : Setoid t₁ t₂} → LeftInverse M T → LeftInverse F M → LeftInverse F T _∘_ {F = F} f g = record { to = to f ⟪∘⟫ to g ; from = from g ⟪∘⟫ from f ; left-inverse-of = λ x → begin from g ⟨$⟩ (from f ⟨$⟩ (to f ⟨$⟩ (to g ⟨$⟩ x))) ≈⟨ Eq.cong (from g) (left-inverse-of f (to g ⟨$⟩ x)) ⟩ from g ⟨$⟩ (to g ⟨$⟩ x) ≈⟨ left-inverse-of g x ⟩ x ∎ } where open LeftInverse open EqReasoning F
{ "alphanum_fraction": 0.5316533497, "avg_line_length": 30.1296296296, "ext": "agda", "hexsha": "c4be351c4a876c582340e5942e29fe2070ae700f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Function/LeftInverse.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Function/LeftInverse.agda", "max_line_length": 109, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Function/LeftInverse.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 1108, "size": 3254 }
-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇. -- Canonical model equipment for Kripke-style semantics. module BasicIS4.Equipment.KripkeDyadicCanonical where open import BasicIS4.Syntax.Common public module Syntax (_⊢_ : Cx² Ty Ty → Ty → Set) (mono²⊢ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊢ A → Π′ ⊢ A) (up : ∀ {A Π} → Π ⊢ (□ A) → Π ⊢ (□ □ A)) (down : ∀ {A Π} → Π ⊢ (□ A) → Π ⊢ A) (lift : ∀ {A Γ Δ} → (Γ ⁏ Δ) ⊢ A → (□⋆ Γ ⁏ Δ) ⊢ (□ A)) where -- Worlds. Worldᶜ : Set Worldᶜ = Cx² Ty Ty -- Intuitionistic accessibility. infix 3 _≤ᶜ_ _≤ᶜ_ : Worldᶜ → Worldᶜ → Set _≤ᶜ_ = _⊆²_ refl≤ᶜ : ∀ {w} → w ≤ᶜ w refl≤ᶜ = refl⊆² trans≤ᶜ : ∀ {w w′ w″} → w ≤ᶜ w′ → w′ ≤ᶜ w″ → w ≤ᶜ w″ trans≤ᶜ = trans⊆² bot≤ᶜ : ∀ {w} → ∅² ≤ᶜ w bot≤ᶜ = bot⊆² -- The canonical modal accessibility, based on the T axiom. infix 3 _Rᶜ_ _Rᶜ_ : Worldᶜ → Worldᶜ → Set w Rᶜ w′ = ∀ {A} → w ⊢ (□ A) → w′ ⊢ A reflRᶜ : ∀ {w} → w Rᶜ w reflRᶜ = down transRᶜ : ∀ {w w′ w″} → w Rᶜ w′ → w′ Rᶜ w″ → w Rᶜ w″ transRᶜ ζ ζ′ = ζ′ ∘ ζ ∘ up botRᶜ : ∀ {w} → ∅² Rᶜ w botRᶜ = mono²⊢ bot≤ᶜ ∘ down liftRᶜ : ∀ {Γ Δ} → Γ ⁏ Δ Rᶜ □⋆ Γ ⁏ Δ liftRᶜ = down ∘ lift ∘ down -- Composition of accessibility. infix 3 _≤⨾Rᶜ_ _≤⨾Rᶜ_ : Worldᶜ → Worldᶜ → Set _≤⨾Rᶜ_ = _≤ᶜ_ ⨾ _Rᶜ_ infix 3 _R⨾≤ᶜ_ _R⨾≤ᶜ_ : Worldᶜ → Worldᶜ → Set _R⨾≤ᶜ_ = _Rᶜ_ ⨾ _≤ᶜ_ refl≤⨾Rᶜ : ∀ {w} → w ≤⨾Rᶜ w refl≤⨾Rᶜ {w} = w , (refl≤ᶜ , reflRᶜ) reflR⨾≤ᶜ : ∀ {w} → w R⨾≤ᶜ w reflR⨾≤ᶜ {w} = w , (reflRᶜ , refl≤ᶜ) -- Persistence condition, after Iemhoff; included by Ono. -- -- w′ v′ → v′ -- ◌───R───● → ● -- │ → ╱ -- ≤ ξ,ζ → R -- │ → ╱ -- ● → ● -- w → w ≤⨾R→Rᶜ : ∀ {v′ w} → w ≤⨾Rᶜ v′ → w Rᶜ v′ ≤⨾R→Rᶜ (w′ , (ξ , ζ)) = ζ ∘ mono²⊢ ξ -- Brilliance condition, after Iemhoff. -- -- v′ → v′ -- ● → ● -- │ → ╱ -- ζ,ξ ≤ → R -- │ → ╱ -- ●───R───◌ → ● -- w v → w R⨾≤→Rᶜ : ∀ {w v′} → w R⨾≤ᶜ v′ → w Rᶜ v′ R⨾≤→Rᶜ (v , (ζ , ξ)) = mono²⊢ ξ ∘ ζ -- Minor persistence condition, included by Božić and Došen. -- -- w′ v′ → v′ -- ◌───R───● → ● -- │ → │ -- ≤ ξ,ζ → ≤ -- │ → │ -- ● → ●───R───◌ -- w → w v -- -- w″ → w″ -- ● → ● -- │ → │ -- ξ′,ζ′ ≤ → │ -- │ → │ -- ●───R───◌ → ≤ -- │ v′ → │ -- ξ,ζ ≤ → │ -- │ → │ -- ●───R───◌ → ●───────R───────◌ -- w v → w v″ ≤⨾R→R⨾≤ᶜ : ∀ {v′ w} → w ≤⨾Rᶜ v′ → w R⨾≤ᶜ v′ ≤⨾R→R⨾≤ᶜ {v′} ξ,ζ = v′ , (≤⨾R→Rᶜ ξ,ζ , refl≤ᶜ) transR⨾≤ᶜ : ∀ {w′ w w″} → w R⨾≤ᶜ w′ → w′ R⨾≤ᶜ w″ → w R⨾≤ᶜ w″ transR⨾≤ᶜ {w′} (v , (ζ , ξ)) (v′ , (ζ′ , ξ′)) = let v″ , (ζ″ , ξ″) = ≤⨾R→R⨾≤ᶜ (w′ , (ξ , ζ′)) in v″ , (transRᶜ ζ ζ″ , trans≤ᶜ ξ″ ξ′) ≤→Rᶜ : ∀ {v′ w} → w ≤ᶜ v′ → w Rᶜ v′ ≤→Rᶜ {v′} ξ = ≤⨾R→Rᶜ (v′ , (ξ , reflRᶜ)) -- Minor brilliance condition, included by Ewald and Alechina et al. -- -- v′ → w′ v′ -- ● → ◌───R───● -- │ → │ -- ζ,ξ ≤ → ≤ -- │ → │ -- ●───R───◌ → ● -- w v → w -- -- v′ w″ → v″ w″ -- ◌───R───● → ◌───────R───────● -- │ → │ -- ≤ ξ′,ζ′ → │ -- v │ → │ -- ◌───R───● → ≤ -- │ w′ → │ -- ≤ ξ,ζ → │ -- │ → │ -- ● → ● -- w → w R⨾≤→≤⨾Rᶜ : ∀ {w v′} → w R⨾≤ᶜ v′ → w ≤⨾Rᶜ v′ R⨾≤→≤⨾Rᶜ {w} ζ,ξ = w , (refl≤ᶜ , R⨾≤→Rᶜ ζ,ξ) trans≤⨾Rᶜ : ∀ {w′ w w″} → w ≤⨾Rᶜ w′ → w′ ≤⨾Rᶜ w″ → w ≤⨾Rᶜ w″ trans≤⨾Rᶜ {w′} (v , (ξ , ζ)) (v′ , (ξ′ , ζ′)) = let v″ , (ξ″ , ζ″) = R⨾≤→≤⨾Rᶜ (w′ , (ζ , ξ′)) in v″ , (trans≤ᶜ ξ ξ″ , transRᶜ ζ″ ζ′) ≤→Rᶜ′ : ∀ {w v′} → w ≤ᶜ v′ → w Rᶜ v′ ≤→Rᶜ′ {w} ξ = R⨾≤→Rᶜ (w , (reflRᶜ , ξ)) -- Infimum (greatest lower bound) of accessibility. -- -- w′ -- ● -- │ -- ≤ ξ,ζ -- │ -- ◌───R───● -- w v infix 3 _≤⊓Rᶜ_ _≤⊓Rᶜ_ : Worldᶜ → Worldᶜ → Set _≤⊓Rᶜ_ = _≤ᶜ_ ⊓ _Rᶜ_ infix 3 _R⊓≤ᶜ_ _R⊓≤ᶜ_ : Worldᶜ → Worldᶜ → Set _R⊓≤ᶜ_ = _Rᶜ_ ⊓ _≤ᶜ_ ≤⊓R→R⊓≤ᶜ : ∀ {w′ v} → w′ ≤⊓Rᶜ v → v R⊓≤ᶜ w′ ≤⊓R→R⊓≤ᶜ (w , (ξ , ζ)) = w , (ζ , ξ) R⊓≤→≤⊓Rᶜ : ∀ {w′ v} → v R⊓≤ᶜ w′ → w′ ≤⊓Rᶜ v R⊓≤→≤⊓Rᶜ (w , (ζ , ξ)) = w , (ξ , ζ) -- Supremum (least upper bound) of accessibility. -- -- w′ v′ -- ●───R───◌ -- │ -- ξ,ζ ≤ -- │ -- ● -- v infix 3 _≤⊔Rᶜ_ _≤⊔Rᶜ_ : Worldᶜ → Worldᶜ → Set _≤⊔Rᶜ_ = _≤ᶜ_ ⊔ _Rᶜ_ infix 3 _R⊔≤ᶜ_ _R⊔≤ᶜ_ : Worldᶜ → Worldᶜ → Set _R⊔≤ᶜ_ = _Rᶜ_ ⊔ _≤ᶜ_ ≤⊔R→R⊔≤ᶜ : ∀ {w′ v} → w′ ≤⊔Rᶜ v → v R⊔≤ᶜ w′ ≤⊔R→R⊔≤ᶜ (v′ , (ξ , ζ)) = v′ , (ζ , ξ) R⊔≤→≤⊔Rᶜ : ∀ {w′ v} → v R⊔≤ᶜ w′ → w′ ≤⊔Rᶜ v R⊔≤→≤⊔Rᶜ (v′ , (ζ , ξ)) = v′ , (ξ , ζ) -- Infimum-to-supremum condition, included by Ewald. -- -- w′ → w′ v′ -- ● → ●───R───◌ -- │ → │ -- ≤ ξ,ζ → ≤ -- │ → │ -- ◌───R───● → ● -- w v → v -- NOTE: This could be more precise. ≤⊓R→≤⊔Rᶜ : ∀ {v w′} → w′ ≤⊓Rᶜ v → v ≤⊔Rᶜ w′ ≤⊓R→≤⊔Rᶜ {v} {w′} (w , (ξ , ζ)) = (w′ ⧺² v) , (weak⊆²⧺₂ , mono²⊢ (weak⊆²⧺₁ v) ∘ down) -- Supremum-to-infimum condition. -- -- w′ v′ → w′ -- ●───R───◌ → ● -- │ → │ -- ξ,ζ ≤ → ≤ -- │ → │ -- ● → ◌───R───● -- v → w v -- NOTE: This could be more precise. ≤⊔R→≤⊓Rᶜ : ∀ {w′ v} → v ≤⊔Rᶜ w′ → w′ ≤⊓Rᶜ v ≤⊔R→≤⊓Rᶜ (v′ , (ξ , ζ)) = ∅² , (bot≤ᶜ , botRᶜ)
{ "alphanum_fraction": 0.29125, "avg_line_length": 25.4980079681, "ext": "agda", "hexsha": "20acf3535af8c94d9aa0185d4b06bb44f290fcb1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/hilbert-gentzen", "max_forks_repo_path": "BasicIS4/Equipment/KripkeDyadicCanonical.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z", "max_issues_repo_licenses": [ "X11" ], "max_issues_repo_name": "mietek/hilbert-gentzen", "max_issues_repo_path": "BasicIS4/Equipment/KripkeDyadicCanonical.agda", "max_line_length": 95, "max_stars_count": 29, "max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/hilbert-gentzen", "max_stars_repo_path": "BasicIS4/Equipment/KripkeDyadicCanonical.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z", "max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z", "num_tokens": 3693, "size": 6400 }
{- Definition of the Klein bottle as a HIT -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.KleinBottle.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.HLevels open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Data.Nat open import Cubical.Data.Int public renaming (_+_ to _+Int_ ; +-assoc to +Int-assoc; +-comm to +Int-comm) open import Cubical.Data.Prod open import Cubical.Data.Sigma open import Cubical.HITs.S1 open import Cubical.HITs.PropositionalTruncation open import Cubical.HITs.KleinBottle.Base loop1 : S¹ → KleinBottle loop1 base = point loop1 (loop i) = line1 i invS¹Loop : S¹ → Set invS¹Loop base = S¹ invS¹Loop (loop i) = invS¹Path i loop1Inv : (s : S¹) → loop1 (inv s) ≡ loop1 s loop1Inv base = line2 loop1Inv (loop i) = square i twist : (s : S¹) → PathP (λ i → invS¹Path i) s (inv s) twist s i = glue (λ {(i = i0) → s; (i = i1) → inv s}) (inv s) twistBaseLoop : (s : S¹) → invS¹Loop s twistBaseLoop base = base twistBaseLoop (loop i) = twist base i kleinBottle≃Σ : KleinBottle ≃ Σ S¹ invS¹Loop kleinBottle≃Σ = isoToEquiv (iso fro to froTo toFro) where fro : KleinBottle → Σ S¹ invS¹Loop fro point = (base , base) fro (line1 i) = (base , loop i) fro (line2 j) = (loop (~ j) , twist base (~ j)) fro (square i j) = (loop (~ j) , twist (loop i) (~ j)) toLoopFiller : (j : I) → ua invS¹Equiv j → I → KleinBottle toLoopFiller j g l = hfill (λ l → λ { (j = i0) → loop1Inv g l ; (j = i1) → loop1 g }) (inS (loop1 (unglue (j ∨ ~ j) g))) l to : Σ S¹ invS¹Loop → KleinBottle to (base , s) = loop1 s to (loop j , g) = toLoopFiller j g i1 toFro : (a : KleinBottle) → to (fro a) ≡ a toFro point = refl toFro (line1 i) = refl toFro (line2 j) k = lUnit line2 (~ k) j toFro (square i j) k = lUnit (square i) (~ k) j froLoop1 : (s : S¹) → fro (loop1 s) ≡ (base , s) froLoop1 base = refl froLoop1 (loop i) = refl froLoop1Inv : PathP (λ k → (s : S¹) → froLoop1 (inv s) k ≡ froLoop1 s k) (λ s l → fro (loop1Inv s l)) (λ s l → loop (~ l) , twist s (~ l)) froLoop1Inv k base l = loop (~ l) , twist base (~ l) froLoop1Inv k (loop i) l = loop (~ l) , twist (loop i) (~ l) froTo : (a : Σ S¹ invS¹Loop) → fro (to a) ≡ a froTo (base , s) = froLoop1 s froTo (loop j , g) k = hcomp (λ l → λ { (j = i0) → froLoop1Inv k g l ; (j = i1) → froLoop1 g k ; (k = i0) → fro (toLoopFiller j g l) ; (k = i1) → ( loop (j ∨ ~ l) , glue (λ { (j = i0) (l = i1) → g ; (j = i1) → g ; (l = i0) → unglue (j ∨ ~ j) g }) (unglue (j ∨ ~ j) g) ) }) (froLoop1 (unglue (j ∨ ~ j) g) k) isGroupoidKleinBottle : isGroupoid KleinBottle isGroupoidKleinBottle = transport (λ i → isGroupoid (ua kleinBottle≃Σ (~ i))) (isOfHLevelΣ 3 isGroupoidS¹ (λ s → recPropTrunc (isPropIsOfHLevel 3 (invS¹Loop s)) (λ p → subst (λ s → isGroupoid (invS¹Loop s)) p isGroupoidS¹) (isConnectedS¹ s))) -- Transport across the following is too slow :( ΩKlein≡Int² : Path KleinBottle point point ≡ Int × Int ΩKlein≡Int² = Path KleinBottle point point ≡⟨ (λ i → basePath i ≡ basePath i) ⟩ Path (Σ S¹ invS¹Loop) (base , base) (base , base) ≡⟨ sym (ua Σ≡) ⟩ Σ ΩS¹ (λ p → PathP (λ j → invS¹Loop (p j)) base base) ≡⟨ (λ i → Σ ΩS¹ (λ p → PathP (λ j → invS¹Loop (p (j ∨ i))) (twistBaseLoop (p i)) base)) ⟩ Σ ΩS¹ (λ _ → ΩS¹) ≡⟨ sym A×B≡A×ΣB ⟩ ΩS¹ × ΩS¹ ≡⟨ (λ i → ΩS¹≡Int i × ΩS¹≡Int i) ⟩ Int × Int ∎ where basePath : PathP (λ i → ua kleinBottle≃Σ i) point (base , base) basePath i = glue (λ {(i = i0) → point; (i = i1) → base , base}) (base , base) -- We can at least define the winding function directly and get results on small examples windingKlein : Path KleinBottle point point → Int × Int windingKlein p = (z₀ , z₁) where step₀ : Path (Σ S¹ invS¹Loop) (base , base) (base , base) step₀ = (λ i → kleinBottle≃Σ .fst (p i)) z₀ : Int z₀ = winding (λ i → kleinBottle≃Σ .fst (p i) .fst) z₁ : Int z₁ = winding (transport (λ i → PathP (λ j → invS¹Loop (step₀ (j ∨ i) .fst)) (twistBaseLoop (step₀ i .fst)) base) (cong snd step₀)) _ : windingKlein line1 ≡ (pos 0 , pos 1) _ = refl _ : windingKlein line2 ≡ (negsuc 0 , pos 0) _ = refl _ : windingKlein (line1 ∙ line2) ≡ (negsuc 0 , negsuc 0) _ = refl _ : windingKlein (line1 ∙ line2 ∙ line1) ≡ (negsuc 0 , pos 0) _ = refl
{ "alphanum_fraction": 0.5941090453, "avg_line_length": 29.1890243902, "ext": "agda", "hexsha": "f0066e83763d3ccecea546f78f8fb4ebed6c56e0", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_path": "Cubical/HITs/KleinBottle/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "limemloh/cubical", "max_issues_repo_path": "Cubical/HITs/KleinBottle/Properties.agda", "max_line_length": 105, "max_stars_count": null, "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_path": "Cubical/HITs/KleinBottle/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1906, "size": 4787 }
-- An ATP hint must be used with functions. -- This error is detected by TypeChecking.Rules.Decl. module ATPBadHint2 where data Bool : Set where false true : Bool {-# ATP hint Bool #-}
{ "alphanum_fraction": 0.7120418848, "avg_line_length": 17.3636363636, "ext": "agda", "hexsha": "09f054616bfd65ea80777571553a03ed7537c466", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "asr/eagda", "max_forks_repo_path": "test/fail/ATPBadHint2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "asr/eagda", "max_issues_repo_path": "test/fail/ATPBadHint2.agda", "max_line_length": 53, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "asr/eagda", "max_stars_repo_path": "test/fail/ATPBadHint2.agda", "max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z", "max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z", "num_tokens": 47, "size": 191 }
-- Instances of semantic kits module Semantics.Substitution.Instances where open import Syntax.Types open import Syntax.Context renaming (_,_ to _,,_) open import Syntax.Terms open import Syntax.Substitution.Kits open import Syntax.Substitution.Instances open import Semantics.Types open import Semantics.Context open import Semantics.Terms open import Semantics.Substitution.Kits open import Semantics.Substitution.Traversal open import CategoryTheory.Categories using (ext) open import CategoryTheory.NatTrans open import CategoryTheory.Functor open import CategoryTheory.Monad open import CategoryTheory.Comonad open import CategoryTheory.Instances.Reactive renaming (top to ⊤) open import TemporalOps.Diamond open import TemporalOps.Box open import TemporalOps.Common.Rewriting open import Data.Sum open import Data.Product open import Relation.Binary.PropositionalEquality open import Relation.Binary.HeterogeneousEquality as ≅ using (_≅_) open import Holes.Term using (⌞_⌟) open import Holes.Cong.Propositional open ≡-Reasoning private module F-□ = Functor F-□ open Comonad W-□ -- Denotation of variable kits ⟦𝒱ar⟧ : ⟦Kit⟧ 𝒱ar ⟦𝒱ar⟧ = record { ⟦_⟧ = ⟦_⟧-var ; ⟦𝓋⟧ = λ A Δ → refl ; ⟦𝓉⟧ = ⟦𝓉⟧-var ; ⟦𝓌⟧ = λ B T → refl ; ⟦𝒶⟧ = ⟦𝒶⟧-var } where open Kit 𝒱ar ⟦_⟧-var : ∀{A Γ} → Var Γ A → ⟦ Γ ⟧ₓ ⇴ ⟦ A ⟧ⱼ ⟦ top ⟧-var n (_ , ⟦A⟧) = ⟦A⟧ ⟦ pop v ⟧-var n (⟦Γ⟧ , _) = ⟦ v ⟧-var n ⟦Γ⟧ ⟦𝓉⟧-var : ∀{A Γ} → (x : Var Γ A) -> ⟦ 𝓉 x ⟧ₘ ≈ ⟦ x ⟧-var ⟦𝓉⟧-var {A now} top = refl ⟦𝓉⟧-var {A always} top = refl ⟦𝓉⟧-var {A now} (pop x) = ⟦𝓉⟧-var x ⟦𝓉⟧-var {A always} (pop x) = ⟦𝓉⟧-var x ⟦𝒶⟧-var : ∀{A Δ} → (x : Var Δ (A always)) -> F-□.fmap ⟦ 𝒶 x ⟧-var ∘ ⟦ Δ ˢ⟧□ ≈ δ.at ⟦ A ⟧ₜ ∘ ⟦ x ⟧-var ⟦𝒶⟧-var top = refl ⟦𝒶⟧-var (pop {B = B now} x) = ⟦𝒶⟧-var x ⟦𝒶⟧-var (pop {B = B always} x) = ⟦𝒶⟧-var x -- Denotation of term kits ⟦𝒯erm⟧ : ⟦Kit⟧ 𝒯erm ⟦𝒯erm⟧ = record { ⟦_⟧ = ⟦_⟧ₘ ; ⟦𝓋⟧ = λ A Δ → refl ; ⟦𝓉⟧ = λ T → refl ; ⟦𝓌⟧ = ⟦𝓌⟧-term ; ⟦𝒶⟧ = ⟦𝒶⟧-term } where open Kit 𝒯erm open ⟦Kit⟧ ⟦𝒱ar⟧ open K open ⟦K⟧ ⟦𝒱ar⟧ ⟦𝓌⟧-term : ∀ B {Δ A} → (M : Term Δ A) -> ⟦ 𝓌 {B} M ⟧ₘ ≈ ⟦ M ⟧ₘ ∘ π₁ ⟦𝓌⟧-term B {Δ} M {n} {⟦Δ⟧ , ⟦B⟧} rewrite traverse-sound ⟦𝒱ar⟧ (_⁺_ {B} (idₛ 𝒱ar) 𝒱ar) M {n} {⟦Δ⟧ , ⟦B⟧} | ⟦⁺⟧ B {Δ} (idₛ 𝒱ar) {n} {⟦Δ⟧ , ⟦B⟧} | ⟦idₛ⟧ {Δ} {n} {⟦Δ⟧} = refl ⟦𝒶⟧-term : ∀{A Δ} (M : Δ ⊢ A always) -> F-□.fmap ⟦ 𝒶 M ⟧ₘ ∘ ⟦ Δ ˢ⟧□ ≈ δ.at ⟦ A ⟧ₜ ∘ ⟦ M ⟧ₘ ⟦𝒶⟧-term {A} {∙} (var ()) ⟦𝒶⟧-term {A} {∙} (stable M) = refl ⟦𝒶⟧-term {A} {Δ ,, B now} (var (pop x)) = ⟦𝒶⟧-term (var x) ⟦𝒶⟧-term {A} {Δ ,, B now} (stable M) = ⟦𝒶⟧-term {A} {Δ} (stable M) ⟦𝒶⟧-term {.B} {Δ ,, B always} (var top) = refl ⟦𝒶⟧-term {A} {Δ ,, B always} (var (pop x)) {n} {⟦Δ⟧ , □⟦B⟧} = ext lemma where lemma : ∀ l -> ⟦ traverse 𝒱ar (_⁺_ {B always} (idₛ 𝒱ar) 𝒱ar) (𝒶 (var x)) ⟧ₘ l (⟦ Δ ˢ⟧□ n ⟦Δ⟧ l , □⟦B⟧) ≡ ⟦ var x ⟧ₘ n ⟦Δ⟧ lemma l rewrite traverse-sound ⟦𝒱ar⟧ (_⁺_ {B always} (idₛ 𝒱ar) 𝒱ar) (𝒶 (var x)) {l} {⟦ Δ ˢ⟧□ n ⟦Δ⟧ l , □⟦B⟧} | ⟦⁺⟧ (B always) {Δ ˢ} (idₛ 𝒱ar) {l} {⟦ Δ ˢ⟧□ n ⟦Δ⟧ l , □⟦B⟧} | ⟦idₛ⟧ {Δ ˢ} {l} {⟦ Δ ˢ⟧□ n ⟦Δ⟧ l} | □-≡ n l (⟦𝒶⟧-term (var x) {n} {⟦Δ⟧}) l = refl ⟦𝒶⟧-term {A} {Δ ,, B always} (stable M) {n} {⟦Δ⟧ , □⟦B⟧} = ext λ x → ext (lemma2 x) where lemma1 : ∀ Δ (n l m : ℕ) (⟦Δ⟧ : ⟦ Δ ⟧ₓ n) -> (F-□.fmap ⟦ Δ ˢ ˢ⟧□ ∘ ⟦ Δ ˢ⟧□) n ⟦Δ⟧ l m ≡ (F-□.fmap ⟦ Δ ˢ ˢ⟧ ∘ ⟦ Δ ˢ⟧□) n ⟦Δ⟧ m lemma1 Δ n l m ⟦Δ⟧ rewrite □-≡ l m (□-≡ n l (⟦ˢ⟧□-twice Δ {n} {⟦Δ⟧}) l) m = □-≡ n m (⟦ˢ⟧-comm Δ) m lemma2 : ∀ l j -> (F-□.fmap ⟦ 𝒶 {Δ ,, B always} (stable M) ⟧ₘ ∘ ⟦ Δ ,, B always ˢ⟧□) n (⟦Δ⟧ , □⟦B⟧) l j ≡ (δ.at ⟦ A ⟧ₜ ∘ ⟦ stable {Δ ,, B always} M ⟧ₘ) n (⟦Δ⟧ , □⟦B⟧) l j lemma2 l j = begin ⟦ subst (λ x → x ,, B always ⊢ A now) (ˢ-idemp′ Δ) M ⟧ₘ j (⟦ Δ ˢ ˢ⟧□ l (⟦ Δ ˢ⟧□ n ⟦Δ⟧ l) j , □⟦B⟧) ≡⟨ cong (λ x → ⟦ subst (λ x → x ,, B always ⊢ A now) (ˢ-idemp′ Δ) M ⟧ₘ j (x , □⟦B⟧)) (lemma1 Δ n l j ⟦Δ⟧) ⟩ ⟦ subst (λ x → x ,, B always ⊢ A now) (ˢ-idemp′ Δ) M ⟧ₘ j (⟦ Δ ˢ ˢ⟧ j (⟦ Δ ˢ⟧□ n ⟦Δ⟧ j) , □⟦B⟧) ≡⟨ cong (λ x → ⟦ subst (λ x → x ,, B always ⊢ A now) (ˢ-idemp′ Δ) M ⟧ₘ j (x , □⟦B⟧)) (⟦ˢ⟧-rew Δ n j ⟦Δ⟧) ⟩ ⟦ subst (λ x → x ,, B always ⊢ A now) (ˢ-idemp′ Δ) M ⟧ₘ j (rew (⟦ˢ⟧-idemp Δ j) (⟦ Δ ˢ⟧□ n ⟦Δ⟧ j) , □⟦B⟧) ≅⟨ full-eq j M-eq (≅.sym (rew-to-≅ (⟦ˢ⟧-idemp Δ j))) □⟦B⟧ ⟩ ⟦ M ⟧ₘ j (⟦ Δ ˢ⟧□ n ⟦Δ⟧ j , □⟦B⟧) ∎ where ˢ-idemp′ : ∀ Γ -> Γ ˢ ≡ Γ ˢ ˢ ˢ-idemp′ Γ = sym (ˢ-idemp Γ) ⟦ˢ⟧-idemp : ∀ Δ n -> ⟦ Δ ˢ ⟧ₓ n ≡ ⟦ Δ ˢ ˢ ⟧ₓ n ⟦ˢ⟧-idemp Δ n = cong (λ x → ⟦ x ⟧ₓ n) (ˢ-idemp′ Δ) rew-lemma : ∀ Δ A n l ⟦Δ⟧ □⟦A⟧ -> (rew (cong (λ x → ⟦ x ⟧ₓ l) (ˢ-idemp′ Δ)) (⟦ Δ ˢ⟧□ n ⟦Δ⟧ l) , □⟦A⟧) ≡ rew (cong (λ x → ⟦ x ⟧ₓ l) (ˢ-idemp′ (Δ ,, A always))) (⟦ Δ ˢ⟧□ n ⟦Δ⟧ l , □⟦A⟧) rew-lemma Δ A n l ⟦Δ⟧ □⟦A⟧ rewrite ˢ-idemp Δ = refl ⟦ˢ⟧-rew : ∀ Δ n l ⟦Δ⟧ -> ⟦ Δ ˢ ˢ⟧ l (⟦ Δ ˢ⟧□ n ⟦Δ⟧ l) ≡ rew (⟦ˢ⟧-idemp Δ l) (⟦ Δ ˢ⟧□ n ⟦Δ⟧ l) ⟦ˢ⟧-rew ∙ n l ⟦Δ⟧ = refl ⟦ˢ⟧-rew (Δ ,, A now) n l (⟦Δ⟧ , ⟦A⟧) = ⟦ˢ⟧-rew Δ n l ⟦Δ⟧ ⟦ˢ⟧-rew (Δ ,, A always) n l (⟦Δ⟧ , □⟦A⟧) rewrite ⟦ˢ⟧-rew Δ n l ⟦Δ⟧ | rew-lemma Δ A n l ⟦Δ⟧ □⟦A⟧ = refl M-eq : subst (λ x → x ,, B always ⊢ A now) (ˢ-idemp′ Δ) M ≅ M M-eq = ≅.≡-subst-removable (λ x → x ,, B always ⊢ A now) (ˢ-idemp′ Δ) M full-eq : ∀ j {M₁ : Δ ˢ ˢ ,, B always ⊢ A now} {M₂ : Δ ˢ ,, B always ⊢ A now} {⟦Δ⟧₁ : ⟦ Δ ˢ ˢ ⟧ₓ j} {⟦Δ⟧₂ : ⟦ Δ ˢ ⟧ₓ j} (p-M : M₁ ≅ M₂) (p-⟦Δ⟧ : ⟦Δ⟧₁ ≅ ⟦Δ⟧₂) □⟦B⟧ -> ⟦ M₁ ⟧ₘ j (⟦Δ⟧₁ , □⟦B⟧) ≅ ⟦ M₂ ⟧ₘ j (⟦Δ⟧₂ , □⟦B⟧) full-eq j p-M p-⟦Δ⟧ □⟦B⟧ rewrite ˢ-idemp Δ = ≅.cong₂ ((λ x y → ⟦ x ⟧ₘ j (y , □⟦B⟧))) p-M p-⟦Δ⟧
{ "alphanum_fraction": 0.4325358852, "avg_line_length": 39.9363057325, "ext": "agda", "hexsha": "fecb5e080ba9b7b8eaff224aba304392bc43bbfa", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DimaSamoz/temporal-type-systems", "max_forks_repo_path": "src/Semantics/Substitution/Instances.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DimaSamoz/temporal-type-systems", "max_issues_repo_path": "src/Semantics/Substitution/Instances.agda", "max_line_length": 120, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DimaSamoz/temporal-type-systems", "max_stars_repo_path": "src/Semantics/Substitution/Instances.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z", "max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z", "num_tokens": 3482, "size": 6270 }
------------------------------------------------------------------------ -- The Agda standard library -- -- A larger example for sublists (propositional case): -- Simply-typed lambda terms with globally unique variables -- (both bound and free ones). ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Binary.Sublist.Propositional.Example.UniqueBoundVariables (Base : Set) where open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; cong; subst; module ≡-Reasoning) open ≡-Reasoning open import Data.List.Base using (List; []; _∷_; [_]) open import Data.List.Membership.Propositional using (_∈_) open import Data.List.Relation.Unary.All using (Null; []) open import Data.List.Relation.Binary.Sublist.Propositional using ( _⊆_; []; _∷_; _∷ʳ_ ; ⊆-refl; ⊆-trans; minimum ; from∈; to∈; lookup ; ⊆-pushoutˡ; RawPushout ; Disjoint; DisjointUnion ; separateˡ; Separation ) open import Data.List.Relation.Binary.Sublist.Propositional.Properties using ( ∷ˡ⁻ ; ⊆-trans-assoc ; from∈∘to∈; from∈∘lookup; lookup-⊆-trans ; ⊆-pushoutˡ-is-wpo ; Disjoint→DisjointUnion; DisjointUnion→Disjoint ; Disjoint-sym; DisjointUnion-inj₁; DisjointUnion-inj₂; DisjointUnion-[]ʳ ; weakenDisjoint; weakenDisjointUnion; shrinkDisjointˡ ; disjoint⇒disjoint-to-union; DisjointUnion-fromAny∘toAny-∷ˡ⁻ ; equalize-separators ) open import Data.Product using (_,_; proj₁; proj₂) -- Simple types over a set Base of base types. data Ty : Set where base : (o : Base) → Ty _⇒_ : (a b : Ty) → Ty -- Typing contexts are lists of types. Cxt = List Ty variable a b : Ty Γ Δ : Cxt x y : a ∈ Γ -- The familiar intrinsically well-typed formulation of STLC -- where a de Bruijn index x is a pointer into the context. module DeBruijn where data Tm (Δ : Cxt) : (a : Ty) → Set where var : (x : a ∈ Δ) → Tm Δ a abs : (t : Tm (a ∷ Δ) b) → Tm Δ (a ⇒ b) app : (t : Tm Δ (a ⇒ b)) (u : Tm Δ a) → Tm Δ b -- We formalize now intrinsically well-typed STLC with -- named variables that are globally unique, i.e., -- each variable can be bound at most once. -- List of bound variables of a term. BVars = List Ty variable B : BVars noBV : Null B -- There is a single global context Γ of all variables used in the terms. -- Each list of bound variables B is a sublist of Γ. variable β βₜ βᵤ yβ β\y : B ⊆ Γ -- Named terms are parameterized by a sublist β : B ⊆ Γ of bound variables. -- Variables outside B can occur as free variables in a term. -- -- * Variables x do not contain any bound variables (Null B). -- -- * The bound variables of an application (t u) is the disjoint union -- of the bound variables βₜ of t and βᵤ of u. -- -- * The bound variables β of an abstraction λyt is the disjoint union -- of the single variable y and the bound variables β\y of t. module UniquelyNamed where data Tm (β : B ⊆ Γ) : (a : Ty) → Set where var : (noBV : Null B) (x : a ∈ Γ) → Tm β a abs : (y : a ∈ Γ) (y# : DisjointUnion (from∈ y) β\y β) (t : Tm β\y b) → Tm β (a ⇒ b) app : (t : Tm βₜ (a ⇒ b)) (u : Tm βᵤ a) (t#u : DisjointUnion βₜ βᵤ β) → Tm β b pattern var! x = var [] x -- Bound variables β : B ⊆ Γ can be considered in a larger context Γ′ -- obtained by γ : Γ ⊆ Γ′. The embedding β′ : B ⊆ Γ′ is simply the -- composition of β and γ, and terms can be coerced recursively: weakenBV : ∀ {Γ B Γ′} {β : B ⊆ Γ} (γ : Γ ⊆ Γ′) → Tm β a → Tm (⊆-trans β γ) a weakenBV γ (var noBV x) = var noBV (lookup γ x) weakenBV γ (app t u t#u) = app (weakenBV γ t) (weakenBV γ u) (weakenDisjointUnion γ t#u) weakenBV γ (abs y y# t) = abs y′ y′# (weakenBV γ t) where y′ = lookup γ y -- Typing: y′# : DisjointUnion (from∈ y′) (⊆-trans β\y γ) (⊆-trans β γ) y′# = subst (λ □ → DisjointUnion □ _ _) (sym (from∈∘lookup _ _)) (weakenDisjointUnion γ y#) -- We bring de Bruijn terms into scope as Exp. open DeBruijn renaming (Tm to Exp) open UniquelyNamed variable t u : Tm β a f e : Exp Δ a -- Relating de Bruijn terms and uniquely named terms. -- -- The judgement δ ⊢ e ~ β ▷ t relates a de Bruijn term e with potentially free variables δ : Δ ⊆ Γ -- to a named term t with exact bound variables β : B ⊆ Γ. The intention is to relate exactly -- the terms with the same meaning. -- -- The judgement will imply the disjointness of Δ and B. variable δ yδ : Δ ⊆ Γ data _⊢_~_▷_ {Γ Δ : Cxt} (δ : Δ ⊆ Γ) : ∀{a} (e : Exp Δ a) {B} (β : B ⊆ Γ) (t : Tm β a) → Set where -- Free de Bruijn index x : a ∈ Δ is related to free variable y : a ∈ Γ -- if δ : Δ ⊆ Γ maps x to y. var : ∀{y} (δx≡y : lookup δ x ≡ y) (δ#β : Disjoint δ β) → δ ⊢ var x ~ β ▷ var! y -- Unnamed lambda δ ⊢ λ.e is related to named lambda y,β ▷ λy.t -- if body y,δ ⊢ e is related to body β ▷ t. abs : (y#δ : DisjointUnion (from∈ y) δ yδ) → (y#β : DisjointUnion (from∈ y) β yβ) → yδ ⊢ e ~ β ▷ t → δ ⊢ abs e ~ yβ ▷ abs y y#β t -- Application δ ⊢ f e is related to application βₜ,βᵤ ▷ t u -- if function δ ⊢ f is related to βₜ ▷ t -- and argument δ ⊢ e is related to βᵤ ▷ u. app : δ ⊢ f ~ βₜ ▷ t → δ ⊢ e ~ βᵤ ▷ u → (t#u : DisjointUnion βₜ βᵤ β) → δ ⊢ app f e ~ β ▷ app t u t#u -- A dependent substitution lemma for ~. -- Trivial, but needed because term equality t : Tm β a ≡ t′ : Tm β′ a is heterogeneous, -- or, more precisely, indexed by a sublist equality β ≡ β′. subst~ : ∀ {a Δ Γ B} {δ δ′ : Δ ⊆ Γ} {β β′ : B ⊆ Γ} {e : Exp Δ a} {t : Tm β a} {t′ : Tm β′ a} (δ≡δ′ : δ ≡ δ′) (β≡β′ : β ≡ β′) (t≡t′ : subst (λ □ → Tm □ a) β≡β′ t ≡ t′) → δ ⊢ e ~ β ▷ t → δ′ ⊢ e ~ β′ ▷ t′ subst~ refl refl refl d = d -- The judgement δ ⊢ e ~ β ▷ t relative to Γ -- can be transported to a bigger context γ : Γ ⊆ Γ′. weaken~ : ∀{a Δ B Γ Γ′} {δ : Δ ⊆ Γ} {β : B ⊆ Γ} {e : Exp Δ a} {t : Tm β a} (γ : Γ ⊆ Γ′) (let δ′ = ⊆-trans δ γ) (let β′ = ⊆-trans β γ) (let t′ = weakenBV γ t) → δ ⊢ e ~ β ▷ t → δ′ ⊢ e ~ β′ ▷ t′ weaken~ γ (var refl δ#β) = var (lookup-⊆-trans γ _) (weakenDisjoint γ δ#β) weaken~ γ (abs y#δ y#β d) = abs y′#δ′ y′#β′ (weaken~ γ d) where y′#δ′ = subst (λ □ → DisjointUnion □ _ _) (sym (from∈∘lookup _ _)) (weakenDisjointUnion γ y#δ) y′#β′ = subst (λ □ → DisjointUnion □ _ _) (sym (from∈∘lookup _ _)) (weakenDisjointUnion γ y#β) weaken~ γ (app dₜ dᵤ t#u) = app (weaken~ γ dₜ) (weaken~ γ dᵤ) (weakenDisjointUnion γ t#u) -- Lemma: If δ ⊢ e ~ β ▷ t, then -- the (potentially) free variables δ of the de Bruijn term e -- are disjoint from the bound variables β of the named term t. disjoint-fv-bv : δ ⊢ e ~ β ▷ t → Disjoint δ β disjoint-fv-bv (var _ δ#β) = δ#β disjoint-fv-bv {β = yβ} (abs y⊎δ y⊎β d) = δ#yβ where δ#y = Disjoint-sym (DisjointUnion→Disjoint y⊎δ) yδ#β = disjoint-fv-bv d δ⊆yδ,eq = DisjointUnion-inj₂ y⊎δ δ⊆yδ = proj₁ δ⊆yδ,eq eq = proj₂ δ⊆yδ,eq δ#β = subst (λ □ → Disjoint □ _) eq (shrinkDisjointˡ δ⊆yδ yδ#β) δ#yβ = disjoint⇒disjoint-to-union δ#y δ#β y⊎β disjoint-fv-bv (app dₜ dᵤ βₜ⊎βᵤ) = disjoint⇒disjoint-to-union δ#βₜ δ#βᵤ βₜ⊎βᵤ where δ#βₜ = disjoint-fv-bv dₜ δ#βᵤ = disjoint-fv-bv dᵤ -- Translating de Bruijn terms to uniquely named terms. -- -- Given a de Bruijn term Δ ⊢ e : a, we seek to produce a named term β ▷ t : a -- that is related to the de Bruijn term. On the way, we have to compute the -- global context Γ that hosts all free and bound variables of t. -- Record (NamedOf e) collects all the outputs of the translation of e. record NamedOf (e : Exp Δ a) : Set where constructor mkNamedOf field {glob} : Cxt -- Γ emb : Δ ⊆ glob -- δ : Δ ⊆ Γ {bv} : BVars -- B bound : bv ⊆ glob -- β : B ⊆ Γ {tm} : Tm bound a -- t : Tm β a relate : emb ⊢ e ~ bound ▷ tm -- δ ⊢ e ~ β ▷ t -- The translation. dB→Named : (e : Exp Δ a) → NamedOf e -- For the translation of a variable x : a ∈ Δ, we can pick Γ := Δ and B := []. -- Δ and B are obviously disjoint subsets of Γ. dB→Named (var x) = record { emb = ⊆-refl -- Γ := Δ ; bound = minimum _ -- no bound variables ; relate = var refl (DisjointUnion→Disjoint DisjointUnion-[]ʳ) } -- For the translation of an abstraction -- -- abs (t : Exp (a ∷ Δ) b) : Exp Δ (a ⇒ b) -- -- we recursively have Γ, B and β : B ⊆ Γ with z,δ : (a ∷ Δ) ⊆ Γ -- and know that B # a∷Δ. -- -- We keep Γ and produce embedding δ : Δ ⊆ Γ and bound variables z ⊎ β. dB→Named {Δ = Δ} {a = a ⇒ b} (abs e) with dB→Named e ... | record{ glob = Γ; emb = zδ; bound = β; relate = d } = record { glob = Γ ; emb = δ̇ ; bound = proj₁ (proj₂ z⊎β) ; relate = abs [a]⊆Γ⊎δ (proj₂ (proj₂ z⊎β)) d } where -- Typings: -- zδ : a ∷ Δ ⊆ Γ -- β : bv ⊆ Γ zδ#β = disjoint-fv-bv d z : a ∈ Γ z = to∈ zδ [a]⊆Γ = from∈ z δ̇ = ∷ˡ⁻ zδ [a]⊆Γ⊎δ = DisjointUnion-fromAny∘toAny-∷ˡ⁻ zδ [a]⊆aΔ : [ a ] ⊆ (a ∷ Δ) [a]⊆aΔ = refl ∷ minimum _ eq : ⊆-trans [a]⊆aΔ zδ ≡ [a]⊆Γ eq = sym (from∈∘to∈ _) z#β : Disjoint [a]⊆Γ β z#β = subst (λ □ → Disjoint □ β) eq (shrinkDisjointˡ [a]⊆aΔ zδ#β) z⊎β = Disjoint→DisjointUnion z#β -- For the translation of an application (f e) we have by induction hypothesis -- two independent extensions δ₁ : Δ ⊆ Γ₁ and δ₂ : Δ ⊆ Γ₂ -- and two bound variable lists β₁ : B₁ ⊆ Γ₁ and β₂ : B₂ ⊆ Γ₂. -- We need to find a common global context Γ such that -- -- (a) δ : Δ ⊆ Γ and -- (b) the bound variables embed disjointly as β₁″ : B₁ ⊆ Γ and β₂″ : B₂ ⊆ Γ. -- -- (a) δ is (eventually) found via a weak pushout of δ₁ and δ₂, giving -- ϕ₁ : Γ₁ ⊆ Γ₁₂ and ϕ₂ : Γ₂ ⊆ Γ₁₂. -- -- (b) The bound variable embeddings -- -- β₁′ = β₁ϕ₁ : B₁ ⊆ Γ₁₂ and -- β₂′ = β₂ϕ₂ : B₂ ⊆ Γ₁₂ and -- -- may be overlapping, but we can separate them by enlarging the global context -- to Γ with two embeddings -- -- γ₁ : Γ₁₂ ⊆ Γ -- γ₂ : Γ₁₂ ⊆ Γ -- -- such that -- -- β₁″ = β₁′γ₁ : B₁ ⊆ Γ -- β₂″ = β₂′γ₂ : B₂ ⊆ Γ -- -- are disjoint. Since Δ is disjoint to both B₁ and B₂ we have equality of -- -- δ₁ϕ₁γ₁ : Δ ⊆ Γ -- δ₂ϕ₂γ₂ : Δ ⊆ Γ -- -- Thus, we can return either of them as δ. dB→Named (app f e) with dB→Named f | dB→Named e ... | mkNamedOf {Γ₁} δ₁ β₁ {t} d₁ | mkNamedOf {Γ₂} δ₂ β₂ {u} d₂ = mkNamedOf δ̇ β̇ (app d₁″ d₂″ β₁″⊎β₂″) where -- Disjointness of δᵢ and βᵢ from induction hypotheses. δ₁#β₁ = disjoint-fv-bv d₁ δ₂#β₂ = disjoint-fv-bv d₂ -- join δ₁ and δ₂ via weak pushout po = ⊆-pushoutˡ δ₁ δ₂ Γ₁₂ = RawPushout.upperBound po ϕ₁ = RawPushout.leg₁ po ϕ₂ = RawPushout.leg₂ po δ₁′ = ⊆-trans δ₁ ϕ₁ δ₂′ = ⊆-trans δ₂ ϕ₂ β₁′ = ⊆-trans β₁ ϕ₁ β₂′ = ⊆-trans β₂ ϕ₂ δ₁′#β₁′ : Disjoint δ₁′ β₁′ δ₁′#β₁′ = weakenDisjoint ϕ₁ δ₁#β₁ δ₂′#β₂′ : Disjoint δ₂′ β₂′ δ₂′#β₂′ = weakenDisjoint ϕ₂ δ₂#β₂ δ₁′≡δ₂′ : δ₁′ ≡ δ₂′ δ₁′≡δ₂′ = ⊆-pushoutˡ-is-wpo δ₁ δ₂ δ₂′#β₁′ : Disjoint δ₂′ β₁′ δ₂′#β₁′ = subst (λ □ → Disjoint □ β₁′) δ₁′≡δ₂′ δ₁′#β₁′ -- separate β₁ and β₂ sep : Separation β₁′ β₂′ sep = separateˡ β₁′ β₂′ γ₁ = Separation.separator₁ sep γ₂ = Separation.separator₂ sep β₁″ = Separation.separated₁ sep β₂″ = Separation.separated₂ sep -- produce their disjoint union uni = Disjoint→DisjointUnion (Separation.disjoint sep) β̇ = proj₁ (proj₂ uni) β₁″⊎β₂″ : DisjointUnion β₁″ β₂″ β̇ β₁″⊎β₂″ = proj₂ (proj₂ uni) ι₁ = DisjointUnion-inj₁ β₁″⊎β₂″ ι₂ = DisjointUnion-inj₂ β₁″⊎β₂″ -- after separation, the FVs are still disjoint from the BVs. δ₁″ = ⊆-trans δ₂′ γ₁ δ₂″ = ⊆-trans δ₂′ γ₂ δ₁″≡δ₂″ : δ₁″ ≡ δ₂″ δ₁″≡δ₂″ = equalize-separators δ₂′#β₁′ δ₂′#β₂′ δ₁″#β₁″ : Disjoint δ₁″ β₁″ δ₁″#β₁″ = weakenDisjoint γ₁ δ₂′#β₁′ δ₂″#β₂″ : Disjoint δ₂″ β₂″ δ₂″#β₂″ = weakenDisjoint γ₂ δ₂′#β₂′ δ̇ = δ₂″ δ₂″#β₁″ : Disjoint δ₂″ β₁″ δ₂″#β₁″ = subst (λ □ → Disjoint □ β₁″) δ₁″≡δ₂″ δ₁″#β₁″ δ̇#β̇ : Disjoint δ̇ β̇ δ̇#β̇ = disjoint⇒disjoint-to-union δ₂″#β₁″ δ₂″#β₂″ β₁″⊎β₂″ -- Combined weakening from Γᵢ to Γ γ₁′ = ⊆-trans ϕ₁ γ₁ γ₂′ = ⊆-trans ϕ₂ γ₂ -- Weakening and converting the first derivation. d₁′ : ⊆-trans δ₁ γ₁′ ⊢ f ~ ⊆-trans β₁ γ₁′ ▷ weakenBV γ₁′ t d₁′ = weaken~ γ₁′ d₁ δ₁≤δ̇ : ⊆-trans δ₁ γ₁′ ≡ ⊆-trans δ₂′ γ₂ δ₁≤δ̇ = begin ⊆-trans δ₁ γ₁′ ≡⟨ ⊆-trans-assoc ⟩ ⊆-trans δ₁′ γ₁ ≡⟨ cong (λ □ → ⊆-trans □ γ₁) δ₁′≡δ₂′ ⟩ ⊆-trans δ₂′ γ₁ ≡⟨⟩ δ₁″ ≡⟨ δ₁″≡δ₂″ ⟩ δ₂″ ≡⟨⟩ δ̇ ∎ β₁≤β₁″ : ⊆-trans β₁ γ₁′ ≡ β₁″ β₁≤β₁″ = ⊆-trans-assoc d₁″ : δ̇ ⊢ f ~ β₁″ ▷ subst (λ □ → Tm □ _) β₁≤β₁″ (weakenBV γ₁′ t) d₁″ = subst~ δ₁≤δ̇ β₁≤β₁″ refl d₁′ -- Weakening and converting the second derivation. d₂′ : ⊆-trans δ₂ γ₂′ ⊢ e ~ ⊆-trans β₂ γ₂′ ▷ weakenBV γ₂′ u d₂′ = weaken~ γ₂′ d₂ β₂≤β₂″ : ⊆-trans β₂ γ₂′ ≡ β₂″ β₂≤β₂″ = ⊆-trans-assoc δ₂≤δ̇ : ⊆-trans δ₂ γ₂′ ≡ δ̇ δ₂≤δ̇ = ⊆-trans-assoc d₂″ : δ̇ ⊢ e ~ β₂″ ▷ subst (λ □ → Tm □ _) β₂≤β₂″ (weakenBV γ₂′ u) d₂″ = subst~ δ₂≤δ̇ β₂≤β₂″ refl d₂′
{ "alphanum_fraction": 0.565495448, "avg_line_length": 32.181598063, "ext": "agda", "hexsha": "76a2f4a72888c7856f0b707d0ba2b887abf72c1b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Sublist/Propositional/Example/UniqueBoundVariables.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Sublist/Propositional/Example/UniqueBoundVariables.agda", "max_line_length": 105, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Sublist/Propositional/Example/UniqueBoundVariables.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 5617, "size": 13291 }
{-# OPTIONS --rewriting #-} module Properties.TypeNormalization where open import Luau.Type using (Type; Scalar; nil; number; string; boolean; never; unknown; _⇒_; _∪_; _∩_) open import Luau.Subtyping using (Tree; Language; ¬Language; function; scalar; unknown; left; right; function-ok₁; function-ok₂; function-err; function-tgt; scalar-function; scalar-function-ok; scalar-function-err; scalar-function-tgt; function-scalar; _,_) open import Luau.TypeNormalization using (_∪ⁿ_; _∩ⁿ_; _∪ᶠ_; _∪ⁿˢ_; _∩ⁿˢ_; normalize) open import Luau.Subtyping using (_<:_; _≮:_; witness; never) open import Properties.Subtyping using (<:-trans; <:-refl; <:-unknown; <:-never; <:-∪-left; <:-∪-right; <:-∪-lub; <:-∩-left; <:-∩-right; <:-∩-glb; <:-∩-symm; <:-function; <:-function-∪-∩; <:-function-∩-∪; <:-function-∪; <:-everything; <:-union; <:-∪-assocl; <:-∪-assocr; <:-∪-symm; <:-intersect; ∪-distl-∩-<:; ∪-distr-∩-<:; <:-∪-distr-∩; <:-∪-distl-∩; ∩-distl-∪-<:; <:-∩-distl-∪; <:-∩-distr-∪; scalar-∩-function-<:-never; scalar-≢-∩-<:-never) -- Normal forms for types data FunType : Type → Set data Normal : Type → Set data FunType where _⇒_ : ∀ {S T} → Normal S → Normal T → FunType (S ⇒ T) _∩_ : ∀ {F G} → FunType F → FunType G → FunType (F ∩ G) data Normal where _⇒_ : ∀ {S T} → Normal S → Normal T → Normal (S ⇒ T) _∩_ : ∀ {F G} → FunType F → FunType G → Normal (F ∩ G) _∪_ : ∀ {S T} → Normal S → Scalar T → Normal (S ∪ T) never : Normal never unknown : Normal unknown data OptScalar : Type → Set where never : OptScalar never number : OptScalar number boolean : OptScalar boolean string : OptScalar string nil : OptScalar nil -- Top function type fun-top : ∀ {F} → (FunType F) → (F <: (never ⇒ unknown)) fun-top (S ⇒ T) = <:-function <:-never <:-unknown fun-top (F ∩ G) = <:-trans <:-∩-left (fun-top F) -- function types are inhabited fun-function : ∀ {F} → FunType F → Language F function fun-function (S ⇒ T) = function fun-function (F ∩ G) = (fun-function F , fun-function G) fun-≮:-never : ∀ {F} → FunType F → (F ≮: never) fun-≮:-never F = witness function (fun-function F) never -- function types aren't scalars fun-¬scalar : ∀ {F S t} → (s : Scalar S) → FunType F → Language F t → ¬Language S t fun-¬scalar s (S ⇒ T) function = scalar-function s fun-¬scalar s (S ⇒ T) (function-ok₁ p) = scalar-function-ok s fun-¬scalar s (S ⇒ T) (function-ok₂ p) = scalar-function-ok s fun-¬scalar s (S ⇒ T) (function-err p) = scalar-function-err s fun-¬scalar s (S ⇒ T) (function-tgt p) = scalar-function-tgt s fun-¬scalar s (F ∩ G) (p₁ , p₂) = fun-¬scalar s G p₂ ¬scalar-fun : ∀ {F S} → FunType F → (s : Scalar S) → ¬Language F (scalar s) ¬scalar-fun (S ⇒ T) s = function-scalar s ¬scalar-fun (F ∩ G) s = left (¬scalar-fun F s) scalar-≮:-fun : ∀ {F S} → FunType F → Scalar S → S ≮: F scalar-≮:-fun F s = witness (scalar s) (scalar s) (¬scalar-fun F s) unknown-≮:-fun : ∀ {F} → FunType F → unknown ≮: F unknown-≮:-fun F = witness (scalar nil) unknown (¬scalar-fun F nil) -- Normalization produces normal types normal : ∀ T → Normal (normalize T) normalᶠ : ∀ {F} → FunType F → Normal F normal-∪ⁿ : ∀ {S T} → Normal S → Normal T → Normal (S ∪ⁿ T) normal-∩ⁿ : ∀ {S T} → Normal S → Normal T → Normal (S ∩ⁿ T) normal-∪ⁿˢ : ∀ {S T} → Normal S → OptScalar T → Normal (S ∪ⁿˢ T) normal-∩ⁿˢ : ∀ {S T} → Normal S → Scalar T → OptScalar (S ∩ⁿˢ T) normal-∪ᶠ : ∀ {F G} → FunType F → FunType G → FunType (F ∪ᶠ G) normal nil = never ∪ nil normal (S ⇒ T) = (normal S) ⇒ (normal T) normal never = never normal unknown = unknown normal boolean = never ∪ boolean normal number = never ∪ number normal string = never ∪ string normal (S ∪ T) = normal-∪ⁿ (normal S) (normal T) normal (S ∩ T) = normal-∩ⁿ (normal S) (normal T) normalᶠ (S ⇒ T) = S ⇒ T normalᶠ (F ∩ G) = F ∩ G normal-∪ⁿ S (T₁ ∪ T₂) = (normal-∪ⁿ S T₁) ∪ T₂ normal-∪ⁿ S never = S normal-∪ⁿ S unknown = unknown normal-∪ⁿ never (T ⇒ U) = T ⇒ U normal-∪ⁿ never (G₁ ∩ G₂) = G₁ ∩ G₂ normal-∪ⁿ unknown (T ⇒ U) = unknown normal-∪ⁿ unknown (G₁ ∩ G₂) = unknown normal-∪ⁿ (R ⇒ S) (T ⇒ U) = normalᶠ (normal-∪ᶠ (R ⇒ S) (T ⇒ U)) normal-∪ⁿ (R ⇒ S) (G₁ ∩ G₂) = normalᶠ (normal-∪ᶠ (R ⇒ S) (G₁ ∩ G₂)) normal-∪ⁿ (F₁ ∩ F₂) (T ⇒ U) = normalᶠ (normal-∪ᶠ (F₁ ∩ F₂) (T ⇒ U)) normal-∪ⁿ (F₁ ∩ F₂) (G₁ ∩ G₂) = normalᶠ (normal-∪ᶠ (F₁ ∩ F₂) (G₁ ∩ G₂)) normal-∪ⁿ (S₁ ∪ S₂) (T₁ ⇒ T₂) = normal-∪ⁿ S₁ (T₁ ⇒ T₂) ∪ S₂ normal-∪ⁿ (S₁ ∪ S₂) (G₁ ∩ G₂) = normal-∪ⁿ S₁ (G₁ ∩ G₂) ∪ S₂ normal-∩ⁿ S never = never normal-∩ⁿ S unknown = S normal-∩ⁿ S (T ∪ U) = normal-∪ⁿˢ (normal-∩ⁿ S T) (normal-∩ⁿˢ S U ) normal-∩ⁿ never (T ⇒ U) = never normal-∩ⁿ unknown (T ⇒ U) = T ⇒ U normal-∩ⁿ (R ⇒ S) (T ⇒ U) = (R ⇒ S) ∩ (T ⇒ U) normal-∩ⁿ (R ∩ S) (T ⇒ U) = (R ∩ S) ∩ (T ⇒ U) normal-∩ⁿ (R ∪ S) (T ⇒ U) = normal-∩ⁿ R (T ⇒ U) normal-∩ⁿ never (T ∩ U) = never normal-∩ⁿ unknown (T ∩ U) = T ∩ U normal-∩ⁿ (R ⇒ S) (T ∩ U) = (R ⇒ S) ∩ (T ∩ U) normal-∩ⁿ (R ∩ S) (T ∩ U) = (R ∩ S) ∩ (T ∩ U) normal-∩ⁿ (R ∪ S) (T ∩ U) = normal-∩ⁿ R (T ∩ U) normal-∪ⁿˢ S never = S normal-∪ⁿˢ never number = never ∪ number normal-∪ⁿˢ unknown number = unknown normal-∪ⁿˢ (R ⇒ S) number = (R ⇒ S) ∪ number normal-∪ⁿˢ (R ∩ S) number = (R ∩ S) ∪ number normal-∪ⁿˢ (R ∪ number) number = R ∪ number normal-∪ⁿˢ (R ∪ boolean) number = normal-∪ⁿˢ R number ∪ boolean normal-∪ⁿˢ (R ∪ string) number = normal-∪ⁿˢ R number ∪ string normal-∪ⁿˢ (R ∪ nil) number = normal-∪ⁿˢ R number ∪ nil normal-∪ⁿˢ never boolean = never ∪ boolean normal-∪ⁿˢ unknown boolean = unknown normal-∪ⁿˢ (R ⇒ S) boolean = (R ⇒ S) ∪ boolean normal-∪ⁿˢ (R ∩ S) boolean = (R ∩ S) ∪ boolean normal-∪ⁿˢ (R ∪ number) boolean = normal-∪ⁿˢ R boolean ∪ number normal-∪ⁿˢ (R ∪ boolean) boolean = R ∪ boolean normal-∪ⁿˢ (R ∪ string) boolean = normal-∪ⁿˢ R boolean ∪ string normal-∪ⁿˢ (R ∪ nil) boolean = normal-∪ⁿˢ R boolean ∪ nil normal-∪ⁿˢ never string = never ∪ string normal-∪ⁿˢ unknown string = unknown normal-∪ⁿˢ (R ⇒ S) string = (R ⇒ S) ∪ string normal-∪ⁿˢ (R ∩ S) string = (R ∩ S) ∪ string normal-∪ⁿˢ (R ∪ number) string = normal-∪ⁿˢ R string ∪ number normal-∪ⁿˢ (R ∪ boolean) string = normal-∪ⁿˢ R string ∪ boolean normal-∪ⁿˢ (R ∪ string) string = R ∪ string normal-∪ⁿˢ (R ∪ nil) string = normal-∪ⁿˢ R string ∪ nil normal-∪ⁿˢ never nil = never ∪ nil normal-∪ⁿˢ unknown nil = unknown normal-∪ⁿˢ (R ⇒ S) nil = (R ⇒ S) ∪ nil normal-∪ⁿˢ (R ∩ S) nil = (R ∩ S) ∪ nil normal-∪ⁿˢ (R ∪ number) nil = normal-∪ⁿˢ R nil ∪ number normal-∪ⁿˢ (R ∪ boolean) nil = normal-∪ⁿˢ R nil ∪ boolean normal-∪ⁿˢ (R ∪ string) nil = normal-∪ⁿˢ R nil ∪ string normal-∪ⁿˢ (R ∪ nil) nil = R ∪ nil normal-∩ⁿˢ never number = never normal-∩ⁿˢ never boolean = never normal-∩ⁿˢ never string = never normal-∩ⁿˢ never nil = never normal-∩ⁿˢ unknown number = number normal-∩ⁿˢ unknown boolean = boolean normal-∩ⁿˢ unknown string = string normal-∩ⁿˢ unknown nil = nil normal-∩ⁿˢ (R ⇒ S) number = never normal-∩ⁿˢ (R ⇒ S) boolean = never normal-∩ⁿˢ (R ⇒ S) string = never normal-∩ⁿˢ (R ⇒ S) nil = never normal-∩ⁿˢ (R ∩ S) number = never normal-∩ⁿˢ (R ∩ S) boolean = never normal-∩ⁿˢ (R ∩ S) string = never normal-∩ⁿˢ (R ∩ S) nil = never normal-∩ⁿˢ (R ∪ number) number = number normal-∩ⁿˢ (R ∪ boolean) number = normal-∩ⁿˢ R number normal-∩ⁿˢ (R ∪ string) number = normal-∩ⁿˢ R number normal-∩ⁿˢ (R ∪ nil) number = normal-∩ⁿˢ R number normal-∩ⁿˢ (R ∪ number) boolean = normal-∩ⁿˢ R boolean normal-∩ⁿˢ (R ∪ boolean) boolean = boolean normal-∩ⁿˢ (R ∪ string) boolean = normal-∩ⁿˢ R boolean normal-∩ⁿˢ (R ∪ nil) boolean = normal-∩ⁿˢ R boolean normal-∩ⁿˢ (R ∪ number) string = normal-∩ⁿˢ R string normal-∩ⁿˢ (R ∪ boolean) string = normal-∩ⁿˢ R string normal-∩ⁿˢ (R ∪ string) string = string normal-∩ⁿˢ (R ∪ nil) string = normal-∩ⁿˢ R string normal-∩ⁿˢ (R ∪ number) nil = normal-∩ⁿˢ R nil normal-∩ⁿˢ (R ∪ boolean) nil = normal-∩ⁿˢ R nil normal-∩ⁿˢ (R ∪ string) nil = normal-∩ⁿˢ R nil normal-∩ⁿˢ (R ∪ nil) nil = nil normal-∪ᶠ (R ⇒ S) (T ⇒ U) = (normal-∩ⁿ R T) ⇒ (normal-∪ⁿ S U) normal-∪ᶠ (R ⇒ S) (G ∩ H) = normal-∪ᶠ (R ⇒ S) G ∩ normal-∪ᶠ (R ⇒ S) H normal-∪ᶠ (E ∩ F) G = normal-∪ᶠ E G ∩ normal-∪ᶠ F G scalar-∩-fun-<:-never : ∀ {F S} → FunType F → Scalar S → (F ∩ S) <: never scalar-∩-fun-<:-never (T ⇒ U) S = scalar-∩-function-<:-never S scalar-∩-fun-<:-never (F ∩ G) S = <:-trans (<:-intersect <:-∩-left <:-refl) (scalar-∩-fun-<:-never F S) flipper : ∀ {S T U} → ((S ∪ T) ∪ U) <: ((S ∪ U) ∪ T) flipper = <:-trans <:-∪-assocr (<:-trans (<:-union <:-refl <:-∪-symm) <:-∪-assocl) ∩-<:-∩ⁿ : ∀ {S T} → Normal S → Normal T → (S ∩ T) <: (S ∩ⁿ T) ∩ⁿ-<:-∩ : ∀ {S T} → Normal S → Normal T → (S ∩ⁿ T) <: (S ∩ T) ∩-<:-∩ⁿˢ : ∀ {S T} → Normal S → Scalar T → (S ∩ T) <: (S ∩ⁿˢ T) ∩ⁿˢ-<:-∩ : ∀ {S T} → Normal S → Scalar T → (S ∩ⁿˢ T) <: (S ∩ T) ∪ᶠ-<:-∪ : ∀ {F G} → FunType F → FunType G → (F ∪ᶠ G) <: (F ∪ G) ∪ⁿ-<:-∪ : ∀ {S T} → Normal S → Normal T → (S ∪ⁿ T) <: (S ∪ T) ∪-<:-∪ⁿ : ∀ {S T} → Normal S → Normal T → (S ∪ T) <: (S ∪ⁿ T) ∪ⁿˢ-<:-∪ : ∀ {S T} → Normal S → OptScalar T → (S ∪ⁿˢ T) <: (S ∪ T) ∪-<:-∪ⁿˢ : ∀ {S T} → Normal S → OptScalar T → (S ∪ T) <: (S ∪ⁿˢ T) ∩-<:-∩ⁿ S never = <:-∩-right ∩-<:-∩ⁿ S unknown = <:-∩-left ∩-<:-∩ⁿ S (T ∪ U) = <:-trans <:-∩-distl-∪ (<:-trans (<:-union (∩-<:-∩ⁿ S T) (∩-<:-∩ⁿˢ S U)) (∪-<:-∪ⁿˢ (normal-∩ⁿ S T) (normal-∩ⁿˢ S U)) ) ∩-<:-∩ⁿ never (T ⇒ U) = <:-∩-left ∩-<:-∩ⁿ unknown (T ⇒ U) = <:-∩-right ∩-<:-∩ⁿ (R ⇒ S) (T ⇒ U) = <:-refl ∩-<:-∩ⁿ (R ∩ S) (T ⇒ U) = <:-refl ∩-<:-∩ⁿ (R ∪ S) (T ⇒ U) = <:-trans <:-∩-distr-∪ (<:-trans (<:-union (∩-<:-∩ⁿ R (T ⇒ U)) (<:-trans <:-∩-symm (∩-<:-∩ⁿˢ (T ⇒ U) S))) (<:-∪-lub <:-refl <:-never)) ∩-<:-∩ⁿ never (T ∩ U) = <:-∩-left ∩-<:-∩ⁿ unknown (T ∩ U) = <:-∩-right ∩-<:-∩ⁿ (R ⇒ S) (T ∩ U) = <:-refl ∩-<:-∩ⁿ (R ∩ S) (T ∩ U) = <:-refl ∩-<:-∩ⁿ (R ∪ S) (T ∩ U) = <:-trans <:-∩-distr-∪ (<:-trans (<:-union (∩-<:-∩ⁿ R (T ∩ U)) (<:-trans <:-∩-symm (∩-<:-∩ⁿˢ (T ∩ U) S))) (<:-∪-lub <:-refl <:-never)) ∩ⁿ-<:-∩ S never = <:-never ∩ⁿ-<:-∩ S unknown = <:-∩-glb <:-refl <:-unknown ∩ⁿ-<:-∩ S (T ∪ U) = <:-trans (∪ⁿˢ-<:-∪ (normal-∩ⁿ S T) (normal-∩ⁿˢ S U)) (<:-trans (<:-union (∩ⁿ-<:-∩ S T) (∩ⁿˢ-<:-∩ S U)) ∩-distl-∪-<:) ∩ⁿ-<:-∩ never (T ⇒ U) = <:-never ∩ⁿ-<:-∩ unknown (T ⇒ U) = <:-∩-glb <:-unknown <:-refl ∩ⁿ-<:-∩ (R ⇒ S) (T ⇒ U) = <:-refl ∩ⁿ-<:-∩ (R ∩ S) (T ⇒ U) = <:-refl ∩ⁿ-<:-∩ (R ∪ S) (T ⇒ U) = <:-trans (∩ⁿ-<:-∩ R (T ⇒ U)) (<:-∩-glb (<:-trans <:-∩-left <:-∪-left) <:-∩-right) ∩ⁿ-<:-∩ never (T ∩ U) = <:-never ∩ⁿ-<:-∩ unknown (T ∩ U) = <:-∩-glb <:-unknown <:-refl ∩ⁿ-<:-∩ (R ⇒ S) (T ∩ U) = <:-refl ∩ⁿ-<:-∩ (R ∩ S) (T ∩ U) = <:-refl ∩ⁿ-<:-∩ (R ∪ S) (T ∩ U) = <:-trans (∩ⁿ-<:-∩ R (T ∩ U)) (<:-∩-glb (<:-trans <:-∩-left <:-∪-left) <:-∩-right) ∩-<:-∩ⁿˢ never number = <:-∩-left ∩-<:-∩ⁿˢ never boolean = <:-∩-left ∩-<:-∩ⁿˢ never string = <:-∩-left ∩-<:-∩ⁿˢ never nil = <:-∩-left ∩-<:-∩ⁿˢ unknown T = <:-∩-right ∩-<:-∩ⁿˢ (R ⇒ S) T = scalar-∩-fun-<:-never (R ⇒ S) T ∩-<:-∩ⁿˢ (F ∩ G) T = scalar-∩-fun-<:-never (F ∩ G) T ∩-<:-∩ⁿˢ (R ∪ number) number = <:-∩-right ∩-<:-∩ⁿˢ (R ∪ boolean) number = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R number) (scalar-≢-∩-<:-never boolean number (λ ()))) ∩-<:-∩ⁿˢ (R ∪ string) number = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R number) (scalar-≢-∩-<:-never string number (λ ()))) ∩-<:-∩ⁿˢ (R ∪ nil) number = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R number) (scalar-≢-∩-<:-never nil number (λ ()))) ∩-<:-∩ⁿˢ (R ∪ number) boolean = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R boolean) (scalar-≢-∩-<:-never number boolean (λ ()))) ∩-<:-∩ⁿˢ (R ∪ boolean) boolean = <:-∩-right ∩-<:-∩ⁿˢ (R ∪ string) boolean = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R boolean) (scalar-≢-∩-<:-never string boolean (λ ()))) ∩-<:-∩ⁿˢ (R ∪ nil) boolean = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R boolean) (scalar-≢-∩-<:-never nil boolean (λ ()))) ∩-<:-∩ⁿˢ (R ∪ number) string = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R string) (scalar-≢-∩-<:-never number string (λ ()))) ∩-<:-∩ⁿˢ (R ∪ boolean) string = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R string) (scalar-≢-∩-<:-never boolean string (λ ()))) ∩-<:-∩ⁿˢ (R ∪ string) string = <:-∩-right ∩-<:-∩ⁿˢ (R ∪ nil) string = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R string) (scalar-≢-∩-<:-never nil string (λ ()))) ∩-<:-∩ⁿˢ (R ∪ number) nil = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R nil) (scalar-≢-∩-<:-never number nil (λ ()))) ∩-<:-∩ⁿˢ (R ∪ boolean) nil = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R nil) (scalar-≢-∩-<:-never boolean nil (λ ()))) ∩-<:-∩ⁿˢ (R ∪ string) nil = <:-trans <:-∩-distr-∪ (<:-∪-lub (∩-<:-∩ⁿˢ R nil) (scalar-≢-∩-<:-never string nil (λ ()))) ∩-<:-∩ⁿˢ (R ∪ nil) nil = <:-∩-right ∩ⁿˢ-<:-∩ never T = <:-never ∩ⁿˢ-<:-∩ unknown T = <:-∩-glb <:-unknown <:-refl ∩ⁿˢ-<:-∩ (R ⇒ S) T = <:-never ∩ⁿˢ-<:-∩ (F ∩ G) T = <:-never ∩ⁿˢ-<:-∩ (R ∪ number) number = <:-∩-glb <:-∪-right <:-refl ∩ⁿˢ-<:-∩ (R ∪ boolean) number = <:-trans (∩ⁿˢ-<:-∩ R number) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ string) number = <:-trans (∩ⁿˢ-<:-∩ R number) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ nil) number = <:-trans (∩ⁿˢ-<:-∩ R number) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ number) boolean = <:-trans (∩ⁿˢ-<:-∩ R boolean) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ boolean) boolean = <:-∩-glb <:-∪-right <:-refl ∩ⁿˢ-<:-∩ (R ∪ string) boolean = <:-trans (∩ⁿˢ-<:-∩ R boolean) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ nil) boolean = <:-trans (∩ⁿˢ-<:-∩ R boolean) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ number) string = <:-trans (∩ⁿˢ-<:-∩ R string) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ boolean) string = <:-trans (∩ⁿˢ-<:-∩ R string) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ string) string = <:-∩-glb <:-∪-right <:-refl ∩ⁿˢ-<:-∩ (R ∪ nil) string = <:-trans (∩ⁿˢ-<:-∩ R string) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ number) nil = <:-trans (∩ⁿˢ-<:-∩ R nil) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ boolean) nil = <:-trans (∩ⁿˢ-<:-∩ R nil) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ string) nil = <:-trans (∩ⁿˢ-<:-∩ R nil) (<:-intersect <:-∪-left <:-refl) ∩ⁿˢ-<:-∩ (R ∪ nil) nil = <:-∩-glb <:-∪-right <:-refl ∪ᶠ-<:-∪ (R ⇒ S) (T ⇒ U) = <:-trans (<:-function (∩-<:-∩ⁿ R T) (∪ⁿ-<:-∪ S U)) <:-function-∪-∩ ∪ᶠ-<:-∪ (R ⇒ S) (G ∩ H) = <:-trans (<:-intersect (∪ᶠ-<:-∪ (R ⇒ S) G) (∪ᶠ-<:-∪ (R ⇒ S) H)) ∪-distl-∩-<: ∪ᶠ-<:-∪ (E ∩ F) G = <:-trans (<:-intersect (∪ᶠ-<:-∪ E G) (∪ᶠ-<:-∪ F G)) ∪-distr-∩-<: ∪-<:-∪ᶠ : ∀ {F G} → FunType F → FunType G → (F ∪ G) <: (F ∪ᶠ G) ∪-<:-∪ᶠ (R ⇒ S) (T ⇒ U) = <:-trans <:-function-∪ (<:-function (∩ⁿ-<:-∩ R T) (∪-<:-∪ⁿ S U)) ∪-<:-∪ᶠ (R ⇒ S) (G ∩ H) = <:-trans <:-∪-distl-∩ (<:-intersect (∪-<:-∪ᶠ (R ⇒ S) G) (∪-<:-∪ᶠ (R ⇒ S) H)) ∪-<:-∪ᶠ (E ∩ F) G = <:-trans <:-∪-distr-∩ (<:-intersect (∪-<:-∪ᶠ E G) (∪-<:-∪ᶠ F G)) ∪ⁿˢ-<:-∪ S never = <:-∪-left ∪ⁿˢ-<:-∪ never number = <:-refl ∪ⁿˢ-<:-∪ never boolean = <:-refl ∪ⁿˢ-<:-∪ never string = <:-refl ∪ⁿˢ-<:-∪ never nil = <:-refl ∪ⁿˢ-<:-∪ unknown number = <:-∪-left ∪ⁿˢ-<:-∪ unknown boolean = <:-∪-left ∪ⁿˢ-<:-∪ unknown string = <:-∪-left ∪ⁿˢ-<:-∪ unknown nil = <:-∪-left ∪ⁿˢ-<:-∪ (R ⇒ S) number = <:-refl ∪ⁿˢ-<:-∪ (R ⇒ S) boolean = <:-refl ∪ⁿˢ-<:-∪ (R ⇒ S) string = <:-refl ∪ⁿˢ-<:-∪ (R ⇒ S) nil = <:-refl ∪ⁿˢ-<:-∪ (R ∩ S) number = <:-refl ∪ⁿˢ-<:-∪ (R ∩ S) boolean = <:-refl ∪ⁿˢ-<:-∪ (R ∩ S) string = <:-refl ∪ⁿˢ-<:-∪ (R ∩ S) nil = <:-refl ∪ⁿˢ-<:-∪ (R ∪ number) number = <:-union <:-∪-left <:-refl ∪ⁿˢ-<:-∪ (R ∪ boolean) number = <:-trans (<:-union (∪ⁿˢ-<:-∪ R number) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ string) number = <:-trans (<:-union (∪ⁿˢ-<:-∪ R number) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ nil) number = <:-trans (<:-union (∪ⁿˢ-<:-∪ R number) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ number) boolean = <:-trans (<:-union (∪ⁿˢ-<:-∪ R boolean) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ boolean) boolean = <:-union <:-∪-left <:-refl ∪ⁿˢ-<:-∪ (R ∪ string) boolean = <:-trans (<:-union (∪ⁿˢ-<:-∪ R boolean) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ nil) boolean = <:-trans (<:-union (∪ⁿˢ-<:-∪ R boolean) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ number) string = <:-trans (<:-union (∪ⁿˢ-<:-∪ R string) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ boolean) string = <:-trans (<:-union (∪ⁿˢ-<:-∪ R string) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ string) string = <:-union <:-∪-left <:-refl ∪ⁿˢ-<:-∪ (R ∪ nil) string = <:-trans (<:-union (∪ⁿˢ-<:-∪ R string) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ number) nil = <:-trans (<:-union (∪ⁿˢ-<:-∪ R nil) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ boolean) nil = <:-trans (<:-union (∪ⁿˢ-<:-∪ R nil) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ string) nil = <:-trans (<:-union (∪ⁿˢ-<:-∪ R nil) <:-refl) flipper ∪ⁿˢ-<:-∪ (R ∪ nil) nil = <:-union <:-∪-left <:-refl ∪-<:-∪ⁿˢ T never = <:-∪-lub <:-refl <:-never ∪-<:-∪ⁿˢ never number = <:-refl ∪-<:-∪ⁿˢ never boolean = <:-refl ∪-<:-∪ⁿˢ never string = <:-refl ∪-<:-∪ⁿˢ never nil = <:-refl ∪-<:-∪ⁿˢ unknown number = <:-unknown ∪-<:-∪ⁿˢ unknown boolean = <:-unknown ∪-<:-∪ⁿˢ unknown string = <:-unknown ∪-<:-∪ⁿˢ unknown nil = <:-unknown ∪-<:-∪ⁿˢ (R ⇒ S) number = <:-refl ∪-<:-∪ⁿˢ (R ⇒ S) boolean = <:-refl ∪-<:-∪ⁿˢ (R ⇒ S) string = <:-refl ∪-<:-∪ⁿˢ (R ⇒ S) nil = <:-refl ∪-<:-∪ⁿˢ (R ∩ S) number = <:-refl ∪-<:-∪ⁿˢ (R ∩ S) boolean = <:-refl ∪-<:-∪ⁿˢ (R ∩ S) string = <:-refl ∪-<:-∪ⁿˢ (R ∩ S) nil = <:-refl ∪-<:-∪ⁿˢ (R ∪ number) number = <:-∪-lub <:-refl <:-∪-right ∪-<:-∪ⁿˢ (R ∪ boolean) number = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R number) <:-refl) ∪-<:-∪ⁿˢ (R ∪ string) number = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R number) <:-refl) ∪-<:-∪ⁿˢ (R ∪ nil) number = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R number) <:-refl) ∪-<:-∪ⁿˢ (R ∪ number) boolean = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R boolean) <:-refl) ∪-<:-∪ⁿˢ (R ∪ boolean) boolean = <:-∪-lub <:-refl <:-∪-right ∪-<:-∪ⁿˢ (R ∪ string) boolean = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R boolean) <:-refl) ∪-<:-∪ⁿˢ (R ∪ nil) boolean = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R boolean) <:-refl) ∪-<:-∪ⁿˢ (R ∪ number) string = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R string) <:-refl) ∪-<:-∪ⁿˢ (R ∪ boolean) string = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R string) <:-refl) ∪-<:-∪ⁿˢ (R ∪ string) string = <:-∪-lub <:-refl <:-∪-right ∪-<:-∪ⁿˢ (R ∪ nil) string = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R string) <:-refl) ∪-<:-∪ⁿˢ (R ∪ number) nil = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R nil) <:-refl) ∪-<:-∪ⁿˢ (R ∪ boolean) nil = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R nil) <:-refl) ∪-<:-∪ⁿˢ (R ∪ string) nil = <:-trans flipper (<:-union (∪-<:-∪ⁿˢ R nil) <:-refl) ∪-<:-∪ⁿˢ (R ∪ nil) nil = <:-∪-lub <:-refl <:-∪-right ∪ⁿ-<:-∪ S never = <:-∪-left ∪ⁿ-<:-∪ S unknown = <:-∪-right ∪ⁿ-<:-∪ never (T ⇒ U) = <:-∪-right ∪ⁿ-<:-∪ unknown (T ⇒ U) = <:-∪-left ∪ⁿ-<:-∪ (R ⇒ S) (T ⇒ U) = ∪ᶠ-<:-∪ (R ⇒ S) (T ⇒ U) ∪ⁿ-<:-∪ (R ∩ S) (T ⇒ U) = ∪ᶠ-<:-∪ (R ∩ S) (T ⇒ U) ∪ⁿ-<:-∪ (R ∪ S) (T ⇒ U) = <:-trans (<:-union (∪ⁿ-<:-∪ R (T ⇒ U)) <:-refl) (<:-∪-lub (<:-∪-lub (<:-trans <:-∪-left <:-∪-left) <:-∪-right) (<:-trans <:-∪-right <:-∪-left)) ∪ⁿ-<:-∪ never (T ∩ U) = <:-∪-right ∪ⁿ-<:-∪ unknown (T ∩ U) = <:-∪-left ∪ⁿ-<:-∪ (R ⇒ S) (T ∩ U) = ∪ᶠ-<:-∪ (R ⇒ S) (T ∩ U) ∪ⁿ-<:-∪ (R ∩ S) (T ∩ U) = ∪ᶠ-<:-∪ (R ∩ S) (T ∩ U) ∪ⁿ-<:-∪ (R ∪ S) (T ∩ U) = <:-trans (<:-union (∪ⁿ-<:-∪ R (T ∩ U)) <:-refl) (<:-∪-lub (<:-∪-lub (<:-trans <:-∪-left <:-∪-left) <:-∪-right) (<:-trans <:-∪-right <:-∪-left)) ∪ⁿ-<:-∪ S (T ∪ U) = <:-∪-lub (<:-trans (∪ⁿ-<:-∪ S T) (<:-union <:-refl <:-∪-left)) (<:-trans <:-∪-right <:-∪-right) ∪-<:-∪ⁿ S never = <:-∪-lub <:-refl <:-never ∪-<:-∪ⁿ S unknown = <:-unknown ∪-<:-∪ⁿ never (T ⇒ U) = <:-∪-lub <:-never <:-refl ∪-<:-∪ⁿ unknown (T ⇒ U) = <:-unknown ∪-<:-∪ⁿ (R ⇒ S) (T ⇒ U) = ∪-<:-∪ᶠ (R ⇒ S) (T ⇒ U) ∪-<:-∪ⁿ (R ∩ S) (T ⇒ U) = ∪-<:-∪ᶠ (R ∩ S) (T ⇒ U) ∪-<:-∪ⁿ (R ∪ S) (T ⇒ U) = <:-trans <:-∪-assocr (<:-trans (<:-union <:-refl <:-∪-symm) (<:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ R (T ⇒ U)) <:-refl))) ∪-<:-∪ⁿ never (T ∩ U) = <:-∪-lub <:-never <:-refl ∪-<:-∪ⁿ unknown (T ∩ U) = <:-unknown ∪-<:-∪ⁿ (R ⇒ S) (T ∩ U) = ∪-<:-∪ᶠ (R ⇒ S) (T ∩ U) ∪-<:-∪ⁿ (R ∩ S) (T ∩ U) = ∪-<:-∪ᶠ (R ∩ S) (T ∩ U) ∪-<:-∪ⁿ (R ∪ S) (T ∩ U) = <:-trans <:-∪-assocr (<:-trans (<:-union <:-refl <:-∪-symm) (<:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ R (T ∩ U)) <:-refl))) ∪-<:-∪ⁿ never (T ∪ U) = <:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ never T) <:-refl) ∪-<:-∪ⁿ unknown (T ∪ U) = <:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ unknown T) <:-refl) ∪-<:-∪ⁿ (R ⇒ S) (T ∪ U) = <:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ (R ⇒ S) T) <:-refl) ∪-<:-∪ⁿ (R ∩ S) (T ∪ U) = <:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ (R ∩ S) T) <:-refl) ∪-<:-∪ⁿ (R ∪ S) (T ∪ U) = <:-trans <:-∪-assocl (<:-union (∪-<:-∪ⁿ (R ∪ S) T) <:-refl) normalize-<: : ∀ T → normalize T <: T <:-normalize : ∀ T → T <: normalize T <:-normalize nil = <:-∪-right <:-normalize (S ⇒ T) = <:-function (normalize-<: S) (<:-normalize T) <:-normalize never = <:-refl <:-normalize unknown = <:-refl <:-normalize boolean = <:-∪-right <:-normalize number = <:-∪-right <:-normalize string = <:-∪-right <:-normalize (S ∪ T) = <:-trans (<:-union (<:-normalize S) (<:-normalize T)) (∪-<:-∪ⁿ (normal S) (normal T)) <:-normalize (S ∩ T) = <:-trans (<:-intersect (<:-normalize S) (<:-normalize T)) (∩-<:-∩ⁿ (normal S) (normal T)) normalize-<: nil = <:-∪-lub <:-never <:-refl normalize-<: (S ⇒ T) = <:-function (<:-normalize S) (normalize-<: T) normalize-<: never = <:-refl normalize-<: unknown = <:-refl normalize-<: boolean = <:-∪-lub <:-never <:-refl normalize-<: number = <:-∪-lub <:-never <:-refl normalize-<: string = <:-∪-lub <:-never <:-refl normalize-<: (S ∪ T) = <:-trans (∪ⁿ-<:-∪ (normal S) (normal T)) (<:-union (normalize-<: S) (normalize-<: T)) normalize-<: (S ∩ T) = <:-trans (∩ⁿ-<:-∩ (normal S) (normal T)) (<:-intersect (normalize-<: S) (normalize-<: T))
{ "alphanum_fraction": 0.5054919264, "avg_line_length": 52.0880195599, "ext": "agda", "hexsha": "cbd8139fa8f8ca34d2bbd498ec148b47f3eae425", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "39fbd2146a379fb0878369b48764cd7e8772c0fb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "sthagen/Roblox-luau", "max_forks_repo_path": "prototyping/Properties/TypeNormalization.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "39fbd2146a379fb0878369b48764cd7e8772c0fb", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "sthagen/Roblox-luau", "max_issues_repo_path": "prototyping/Properties/TypeNormalization.agda", "max_line_length": 443, "max_stars_count": 1, "max_stars_repo_head_hexsha": "f1b46f4b967f11fabe666da1de0e71b225368260", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Libertus-Lab/luau", "max_stars_repo_path": "prototyping/Properties/TypeNormalization.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-06T08:03:00.000Z", "max_stars_repo_stars_event_min_datetime": "2021-11-06T08:03:00.000Z", "num_tokens": 11533, "size": 21304 }
-- Soundness proofs of structural lemmas and substitution module Semantics.Substitution.Soundness where open import Syntax.Types open import Syntax.Context renaming (_,_ to _,,_) open import Syntax.Terms open import Syntax.Substitution.Kits open import Syntax.Substitution.Instances open import Syntax.Substitution.Lemmas open import Semantics.Types open import Semantics.Context open import Semantics.Terms open import Semantics.Substitution.Kits open import Semantics.Substitution.Traversal open import Semantics.Substitution.Instances open import Semantics.Bind open import CategoryTheory.Categories using (Category ; ext) open import CategoryTheory.Functor open import CategoryTheory.NatTrans open import CategoryTheory.Monad open import CategoryTheory.Comonad open import CategoryTheory.Linear open import CategoryTheory.Instances.Reactive renaming (top to ⊤) open import TemporalOps.Diamond open import TemporalOps.Box open import TemporalOps.OtherOps open import TemporalOps.StrongMonad open import TemporalOps.Linear open import Data.Sum open import Data.Product using (_,_) open import Relation.Binary.PropositionalEquality as ≡ using (_≡_ ; refl ; sym ; trans ; cong ; cong₂ ; subst) open ≡.≡-Reasoning open import Holes.Term using (⌞_⌟) open import Holes.Cong.Propositional open ⟦K⟧ ⟦𝒯erm⟧ -- | Interpretation of various types of substitution as context morphisms -- Denotation of term substitutions ⟦_⟧ₛ : ∀{Γ Δ} -> Subst Term Γ Δ -> ⟦ Δ ⟧ₓ ⇴ ⟦ Γ ⟧ₓ ⟦ σ ⟧ₛ = ⟦subst⟧ σ -- Denotation of OPEs ⟦_⟧⊆ : ∀{Γ Δ} -> Γ ⊆ Δ -> ⟦ Δ ⟧ₓ ⇴ ⟦ Γ ⟧ₓ ⟦ s ⟧⊆ = ⟦ s ⊆ₛ 𝒯erm ⟧ₛ -- Denotation of context exchange ⟦exch⟧ : ∀ Γ Γ′ Γ″ {A B} -> ⟦ Γ ⌊ B ⌋ Γ′ ⌊ A ⌋ Γ″ ⟧ₓ ⇴ ⟦ Γ ⌊ A ⌋ Γ′ ⌊ B ⌋ Γ″ ⟧ₓ ⟦exch⟧ Γ Γ′ Γ″ = ⟦ exₛ 𝒯ermₛ Γ Γ′ Γ″ ⟧ₛ -- Denotation of context contraction ⟦contr⟧ : ∀ Γ Γ′ Γ″ {A} -> ⟦ Γ ⌊ A ⌋ Γ′ ⌊⌋ Γ″ ⟧ₓ ⇴ ⟦ Γ ⌊ A ⌋ Γ′ ⌊ A ⌋ Γ″ ⟧ₓ ⟦contr⟧ Γ Γ′ Γ″ = ⟦ contr-lₛ 𝒯ermₛ Γ Γ′ Γ″ ⟧ₛ -- Denotation of middle context substitution ⟦_⌊⌋ₛ_⊢ₛ_⟧ : ∀ Γ Γ′ {A} -> Γ ⌊⌋ Γ′ ⊢ A -> ⟦ Γ ⌊⌋ Γ′ ⟧ₓ ⇴ ⟦ Γ ⌊ A ⌋ Γ′ ⟧ₓ ⟦ Γ ⌊⌋ₛ Γ′ ⊢ₛ M ⟧ = ⟦ sub-midₛ 𝒯ermₛ Γ Γ′ M ⟧ₛ -- Denotational soundness of top substitution ⟦sub-topₛ⟧ : ∀ {Γ A} -> (M : Γ ⊢ A) -> ⟦ sub-topₛ 𝒯ermₛ M ⟧ₛ ≈ ⟨ id , ⟦ M ⟧ₘ ⟩ ⟦sub-topₛ⟧ {Γ} M {n} {⟦Γ⟧} rewrite ⟦idₛ⟧ {Γ} {n} {⟦Γ⟧} = refl -- | Soundness theorems -- | Concrete soundness theorems for structural lemmas and substitution -- | are instances of the general traversal soundness proof -- Substituting traversal is sound substitute-sound : ∀{Γ Δ A} (σ : Subst Term Γ Δ) (M : Γ ⊢ A) -> ⟦ substitute σ M ⟧ₘ ≈ ⟦ M ⟧ₘ ∘ ⟦ σ ⟧ₛ substitute-sound σ M = traverse-sound ⟦𝒯erm⟧ σ M substitute′-sound : ∀{Γ Δ A} (σ : Subst Term Γ Δ) (M : Γ ⊨ A) -> ⟦ substitute′ σ M ⟧ᵐ ≈ ⟦ M ⟧ᵐ ∘ ⟦ σ ⟧ₛ substitute′-sound σ M = traverse′-sound ⟦𝒯erm⟧ σ M -- Weakening lemma is sound weakening-sound : ∀{Γ Δ A} (s : Γ ⊆ Δ) (M : Γ ⊢ A) -> ⟦ weakening s M ⟧ₘ ≈ ⟦ M ⟧ₘ ∘ ⟦ s ⟧⊆ weakening-sound s = substitute-sound (s ⊆ₛ 𝒯erm) -- Exchange lemma is sound exchange-sound : ∀{Γ Γ′ Γ″ A B C} (M : Γ ⌊ A ⌋ Γ′ ⌊ B ⌋ Γ″ ⊢ C) -> ⟦ exchange Γ Γ′ Γ″ M ⟧ₘ ≈ ⟦ M ⟧ₘ ∘ (⟦exch⟧ Γ Γ′ Γ″) exchange-sound {Γ} {Γ′} {Γ″} = substitute-sound (exₛ 𝒯ermₛ Γ Γ′ Γ″) -- Contraction lemma is sound contraction-sound : ∀{Γ Γ′ Γ″ A B} (M : Γ ⌊ A ⌋ Γ′ ⌊ A ⌋ Γ″ ⊢ B) -> ⟦ contraction Γ Γ′ Γ″ M ⟧ₘ ≈ ⟦ M ⟧ₘ ∘ (⟦contr⟧ Γ Γ′ Γ″) contraction-sound {Γ} {Γ′} {Γ″} = substitute-sound (contr-lₛ 𝒯ermₛ Γ Γ′ Γ″) -- Substitution lemma is sound substitution-sound : ∀{Γ Γ′ A B} (M : Γ ⌊⌋ Γ′ ⊢ A) (N : Γ ⌊ A ⌋ Γ′ ⊢ B) -> ⟦ substitution Γ Γ′ M N ⟧ₘ ≈ ⟦ N ⟧ₘ ∘ ⟦ Γ ⌊⌋ₛ Γ′ ⊢ₛ M ⟧ substitution-sound {Γ} {Γ′} M = substitute-sound (sub-midₛ 𝒯ermₛ Γ Γ′ M) -- Substitution lemma is sound substitution′-sound : ∀{Γ Γ′ A B} (M : Γ ⌊⌋ Γ′ ⊢ A) (N : Γ ⌊ A ⌋ Γ′ ⊨ B) -> ⟦ substitution′ Γ Γ′ M N ⟧ᵐ ≈ ⟦ N ⟧ᵐ ∘ ⟦ Γ ⌊⌋ₛ Γ′ ⊢ₛ M ⟧ substitution′-sound {Γ} {Γ′} M N = traverse′-sound ⟦𝒯erm⟧ (sub-midₛ 𝒯ermₛ Γ Γ′ M) N -- Top substitution is sound (full categorical proof) subst-sound : ∀{Γ A B} (M : Γ ⊢ A) (N : Γ ,, A ⊢ B) -> ⟦ [ M /] N ⟧ₘ ≈ ⟦ N ⟧ₘ ∘ ⟨ id , ⟦ M ⟧ₘ ⟩ subst-sound M N {n} {a} rewrite sym (⟦sub-topₛ⟧ M {n} {a}) = substitute-sound (sub-topₛ 𝒯ermₛ M) N -- Top substitution is sound (full categorical proof) subst′-sound : ∀{Γ A B} (M : Γ ⊢ A) (N : Γ ,, A ⊨ B) -> ⟦ [ M /′] N ⟧ᵐ ≈ ⟦ N ⟧ᵐ ∘ ⟨ id , ⟦ M ⟧ₘ ⟩ subst′-sound M N {n} {a} rewrite sym (⟦sub-topₛ⟧ M {n} {a}) = traverse′-sound ⟦𝒯erm⟧ (sub-topₛ 𝒯ermₛ M) N open K 𝒯erm open Monad M-◇ open Comonad W-□ open Functor F-□ renaming (fmap to □-f) open Functor F-◇ renaming (fmap to ◇-f) private module F-◇ = Functor F-◇ -- Lemma used in the soundness proof of computational substitution subst″-sound-lemma : ∀ Γ {A B} (n k l : ℕ) -> (D : Γ ˢ ,, A now ⊨ B now) -> (⟦Γ⟧ : ⟦ Γ ⟧ₓ n) (⟦A⟧ : ⟦ A ⟧ₜ l) -> ⟦ substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D ⟧ᵐ l (⟦ Γ ˢ ˢ⟧□ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k) l , ⟦A⟧) ≡ ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧) subst″-sound-lemma Γ {A} n k l D ⟦Γ⟧ ⟦A⟧ rewrite substitute′-sound ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D {l} {⟦ Γ ˢ ˢ⟧□ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k) l , ⟦A⟧} | ⟦↑⟧ (A now) (Γ ˢˢₛ 𝒯erm) {l} {⟦ Γ ˢ ˢ⟧□ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k) l , ⟦A⟧} | □-≡ k l (□-≡ n k (⟦ˢ⟧□-twice Γ {n} {⟦Γ⟧}) k) l | □-≡ k l (⟦ˢˢ⟧ Γ {n} {⟦Γ⟧}) l = refl subst″-sound : ∀{Γ A B} (C : Γ ⊨ A now) (D : Γ ˢ ,, A now ⊨ B now) -> ⟦ ⟨ C /⟩ D ⟧ᵐ ≈ bindEvent Γ ⟦ C ⟧ᵐ ⟦ D ⟧ᵐ subst″-sound {Γ}{A}{B} (pure M) D {n} {⟦Γ⟧} rewrite traverse′-sound ⟦𝒯erm⟧ (sub-topˢₛ 𝒯ermₛ M) D {n} {⟦Γ⟧} | ⟦subst⟧-Γˢ⊆Γ Γ {n} {⟦Γ⟧} | ⟦ˢ⟧-factor Γ {n} {⟦Γ⟧} = refl subst″-sound {Γ}{A}{B} (letSig_InC_ {A = G} S C) D {n} {⟦Γ⟧} rewrite subst″-sound C (substitute′ (idₛ 𝒯erm ⁺ 𝒯erm ↑ 𝒯erm) D) {n} {⟦Γ⟧ , ⟦ S ⟧ₘ n ⟦Γ⟧} = begin bindEvent (Γ ,, G always) ⟦ C ⟧ᵐ ⌞ ⟦ substitute′ ((_⁺_ {G always} (idₛ 𝒯erm) 𝒯erm) ↑ 𝒯erm) D ⟧ᵐ ⌟ n (⟦Γ⟧ , ⟦ S ⟧ₘ n ⟦Γ⟧) ≡⟨ bind-to->>= (Γ ,, G always) ⟦ C ⟧ᵐ ⟦ substitute′ ((_⁺_ {G always} (idₛ 𝒯erm) 𝒯erm) ↑ 𝒯erm) D ⟧ᵐ n (⟦Γ⟧ , ⟦ S ⟧ₘ n ⟦Γ⟧) ⟩ ⟦ C ⟧ᵐ n (⟦Γ⟧ , ⟦ S ⟧ₘ n ⟦Γ⟧) >>= (λ l ⟦A⟧ → ⟦ substitute′ (idₛ 𝒯erm ⁺ 𝒯erm ↑ 𝒯erm) D ⟧ᵐ l ((⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦ S ⟧ₘ n ⟦Γ⟧) , ⟦A⟧)) ≡⟨ cong (λ x → (⟦ C ⟧ᵐ n (⟦Γ⟧ , ⟦ S ⟧ₘ n ⟦Γ⟧) >>= x)) (ext λ l → ext λ ⟦A⟧ → begin ⟦ substitute′ (idₛ 𝒯erm ⁺ 𝒯erm ↑ 𝒯erm) D ⟧ᵐ l ((⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦ S ⟧ₘ n ⟦Γ⟧) , ⟦A⟧) ≡⟨ substitute′-sound (_↑_ {A now} (_⁺_ {G always} (idₛ 𝒯erm) 𝒯erm) 𝒯erm) D {l} {((⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦ S ⟧ₘ n ⟦Γ⟧) , ⟦A⟧)} ⟩ ⟦ D ⟧ᵐ l (⟦ (_↑_ {A now} {Γ = Γ ˢ} (_⁺_ {G always} (idₛ 𝒯erm) 𝒯erm) 𝒯erm) ⟧ₛ l ((⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦ S ⟧ₘ n ⟦Γ⟧) , ⟦A⟧)) ≡⟨ cong (⟦ D ⟧ᵐ l) (⟦↑⟧ (A now) {Γ ˢ ,, G always} (_⁺_ {G always} (idₛ 𝒯erm) 𝒯erm) {l} {(⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦ S ⟧ₘ n ⟦Γ⟧) , ⟦A⟧}) ⟩ ⟦ D ⟧ᵐ l (⟦ _⁺_ {G always} {Γ = Γ ˢ} (idₛ 𝒯erm) 𝒯erm ⟧ₛ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦ S ⟧ₘ n ⟦Γ⟧) , ⟦A⟧) ≡⟨ cong (λ x → ⟦ D ⟧ᵐ l (x , ⟦A⟧)) (⟦⁺⟧ (G always) {Γ ˢ} (idₛ 𝒯erm) {l} {⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦ S ⟧ₘ n ⟦Γ⟧}) ⟩ ⟦ D ⟧ᵐ l (⟦ idₛ {Γ ˢ} 𝒯erm ⟧ₛ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l) , ⟦A⟧) ≡⟨ cong (λ x → ⟦ D ⟧ᵐ l (x , ⟦A⟧)) (⟦idₛ⟧ {Γ ˢ} {l} {⟦ Γ ˢ⟧□ n ⟦Γ⟧ l}) ⟩ ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧) ∎ ) ⟩ ⟦ letSig S InC C ⟧ᵐ n ⟦Γ⟧ >>= (λ l ⟦A⟧ → ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧)) ≡⟨ sym (bind-to->>= Γ ⟦ letSig S InC C ⟧ᵐ ⟦ D ⟧ᵐ n ⟦Γ⟧) ⟩ bindEvent Γ ⟦ letSig S InC C ⟧ᵐ ⟦ D ⟧ᵐ n ⟦Γ⟧ ∎ subst″-sound {Γ}{A}{B} (letEvt_In_ {A = G} E C) D {n} {⟦Γ⟧} = begin ⟦ ⟨ letEvt E In C /⟩ D ⟧ᵐ n ⟦Γ⟧ ≡⟨ bind-to->>= Γ ⟦ E ⟧ₘ ⟦ ⟨ C /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ n ⟦Γ⟧ ⟩ ⟦ E ⟧ₘ n ⟦Γ⟧ >>= (λ k ⟦A⟧ → ⟦ ⟨ C /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k , ⟦A⟧)) ≡⟨ cong (λ x → ⟦ E ⟧ₘ n ⟦Γ⟧ >>= x) (ext λ k → ext λ ⟦A⟧ → (begin ⟦ ⟨ C /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k , ⟦A⟧) ≡⟨ subst″-sound C (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) {k} {⟦ Γ ˢ⟧□ n ⟦Γ⟧ k , ⟦A⟧} ⟩ bindEvent (Γ ˢ ,, G now) ⟦ C ⟧ᵐ ⟦ substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D ⟧ᵐ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k , ⟦A⟧) ≡⟨ bind-to->>= (Γ ˢ ,, G now) ⟦ C ⟧ᵐ ⟦ substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D ⟧ᵐ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k , ⟦A⟧) ⟩ ⟦ C ⟧ᵐ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k , ⟦A⟧) >>= (λ l ⟦A⟧₁ → ⟦ substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D ⟧ᵐ l (⟦ Γ ˢ ˢ⟧□ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k) l , ⟦A⟧₁)) ≡⟨ cong (λ x → ⟦ C ⟧ᵐ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k , ⟦A⟧) >>= x) (ext λ l → ext λ ⟦A⟧₁ → subst″-sound-lemma Γ n k l D ⟦Γ⟧ ⟦A⟧₁) ⟩ ⟦ C ⟧ᵐ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k , ⟦A⟧) >>= (λ l ⟦A⟧₁ → ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧₁)) ∎)) ⟩ ⟦ E ⟧ₘ n ⟦Γ⟧ >>= (λ k ⟦A⟧ → ⟦ C ⟧ᵐ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k , ⟦A⟧) >>= λ l ⟦A⟧ → ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧)) ≡⟨ sym (>>=-assoc (⟦ E ⟧ₘ n ⟦Γ⟧) _ _) ⟩ (⟦ E ⟧ₘ n ⟦Γ⟧ >>= λ k ⟦A⟧ → ⟦ C ⟧ᵐ k (⟦ Γ ˢ⟧□ n ⟦Γ⟧ k , ⟦A⟧)) >>= (λ l ⟦A⟧ → ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧)) ≡⟨ cong (λ x -> x >>= _) (sym (bind-to->>= Γ ⟦ E ⟧ₘ ⟦ C ⟧ᵐ n ⟦Γ⟧)) ⟩ (⟦ letEvt E In C ⟧ᵐ n ⟦Γ⟧ >>= (λ l ⟦A⟧ → ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧))) ≡⟨ sym (bind-to->>= Γ ⟦ letEvt E In C ⟧ᵐ ⟦ D ⟧ᵐ n ⟦Γ⟧) ⟩ bindEvent Γ ⟦ letEvt E In C ⟧ᵐ ⟦ D ⟧ᵐ n ⟦Γ⟧ ∎ subst″-sound {Γ}{A}{B} (select_↦_||_↦_||both↦_ {A = G}{H} E₁ C₁ E₂ C₂ C₃) D {n} {⟦Γ⟧} = begin ⟦ ⟨ select E₁ ↦ C₁ || E₂ ↦ C₂ ||both↦ C₃ /⟩ D ⟧ᵐ n ⟦Γ⟧ ≡⟨⟩ ⟦ select E₁ ↦ ⟨ C₁ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) || E₂ ↦ ⟨ C₂ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ||both↦ ⟨ C₃ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ n ⟦Γ⟧ ≡⟨⟩ bindEvent Γ (⟪ ⟦ E₁ ⟧ₘ , ⟦ E₂ ⟧ₘ ⟫) (handle ⟦ ⟨ C₁ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ ⟦ ⟨ C₂ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ ⟦ ⟨ C₃ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ) n ⟦Γ⟧ ≡⟨ bind-to->>= Γ (⟪ ⟦ E₁ ⟧ₘ , ⟦ E₂ ⟧ₘ ⟫) (handle ⟦ ⟨ C₁ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ ⟦ ⟨ C₂ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ ⟦ ⟨ C₃ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ) n ⟦Γ⟧ ⟩ ⟪ ⟦ E₁ ⟧ₘ , ⟦ E₂ ⟧ₘ ⟫ n ⟦Γ⟧ >>= (λ l ⟦A⟧ → handle ⟦ ⟨ C₁ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ ⟦ ⟨ C₂ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ ⟦ ⟨ C₃ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧)) ≡⟨ cong (λ x → ⟪ ⟦ E₁ ⟧ₘ , ⟦ E₂ ⟧ₘ ⟫ n ⟦Γ⟧ >>= x) (ext λ m → ext λ c → lemma m c) ⟩ ⟪ ⟦ E₁ ⟧ₘ , ⟦ E₂ ⟧ₘ ⟫ n ⟦Γ⟧ >>= (λ m c → handle ⟦ C₁ ⟧ᵐ ⟦ C₂ ⟧ᵐ ⟦ C₃ ⟧ᵐ m (⟦ Γ ˢ⟧□ n ⟦Γ⟧ m , c) >>= λ l ⟦A⟧ → ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧)) ≡⟨ sym (>>=-assoc (⟪ ⟦ E₁ ⟧ₘ , ⟦ E₂ ⟧ₘ ⟫ n ⟦Γ⟧) _ _) ⟩ (⟪ ⟦ E₁ ⟧ₘ , ⟦ E₂ ⟧ₘ ⟫ n ⟦Γ⟧ >>= λ m c -> handle ⟦ C₁ ⟧ᵐ ⟦ C₂ ⟧ᵐ ⟦ C₃ ⟧ᵐ m (⟦ Γ ˢ⟧□ n ⟦Γ⟧ m , c)) >>= (λ l ⟦A⟧ → ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧)) ≡⟨ cong (λ x -> x >>= _) (sym (bind-to->>= Γ (⟪ ⟦ E₁ ⟧ₘ , ⟦ E₂ ⟧ₘ ⟫) (handle ⟦ C₁ ⟧ᵐ ⟦ C₂ ⟧ᵐ ⟦ C₃ ⟧ᵐ) n ⟦Γ⟧)) ⟩ bindEvent Γ (⟪ ⟦ E₁ ⟧ₘ , ⟦ E₂ ⟧ₘ ⟫) (handle ⟦ C₁ ⟧ᵐ ⟦ C₂ ⟧ᵐ ⟦ C₃ ⟧ᵐ) n ⟦Γ⟧ >>= (λ l ⟦A⟧ → ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧)) ≡⟨ sym (bind-to->>= Γ (bindEvent Γ (⟪_,_⟫ ⟦ E₁ ⟧ₘ ⟦ E₂ ⟧ₘ) (handle ⟦ C₁ ⟧ᵐ ⟦ C₂ ⟧ᵐ ⟦ C₃ ⟧ᵐ)) ⟦ D ⟧ᵐ n ⟦Γ⟧) ⟩ bindEvent Γ (bindEvent Γ ⟪ ⟦ E₁ ⟧ₘ , ⟦ E₂ ⟧ₘ ⟫ (handle ⟦ C₁ ⟧ᵐ ⟦ C₂ ⟧ᵐ ⟦ C₃ ⟧ᵐ)) ⟦ D ⟧ᵐ n ⟦Γ⟧ ∎ where lemma : ∀ m c -> handle ⟦ ⟨ C₁ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ ⟦ ⟨ C₂ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ ⟦ ⟨ C₃ /⟩ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) ⟧ᵐ m (⟦ Γ ˢ⟧□ n ⟦Γ⟧ m , c) ≡ (handle ⟦ C₁ ⟧ᵐ ⟦ C₂ ⟧ᵐ ⟦ C₃ ⟧ᵐ m (⟦ Γ ˢ⟧□ n ⟦Γ⟧ m , c) >>= λ l ⟦A⟧ → ⟦ D ⟧ᵐ l (⟦ Γ ˢ⟧□ n ⟦Γ⟧ l , ⟦A⟧)) lemma m (inj₁ (inj₁ (⟦A⟧ , ⟦◇B⟧))) rewrite subst″-sound C₁ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) {m} {(⟦ Γ ˢ⟧□ n ⟦Γ⟧ m , ⟦A⟧) , ⟦◇B⟧} | bind-to->>= (Γ ˢ ,, G now ,, Event H now) ⟦ C₁ ⟧ᵐ ⟦ substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D ⟧ᵐ m ((⟦ Γ ˢ⟧□ n ⟦Γ⟧ m , ⟦A⟧) , ⟦◇B⟧) | (ext λ l → ext λ ⟦C⟧ → subst″-sound-lemma Γ n m l D ⟦Γ⟧ ⟦C⟧) = refl lemma m (inj₁ (inj₂ (⟦◇A⟧ , ⟦B⟧))) rewrite subst″-sound C₂ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) {m} {(⟦ Γ ˢ⟧□ n ⟦Γ⟧ m , ⟦◇A⟧) , ⟦B⟧} | bind-to->>= (Γ ˢ ,, Event G now ,, H now) ⟦ C₂ ⟧ᵐ ⟦ substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D ⟧ᵐ m ((⟦ Γ ˢ⟧□ n ⟦Γ⟧ m , ⟦◇A⟧) , ⟦B⟧) | (ext λ l → ext λ ⟦C⟧ → subst″-sound-lemma Γ n m l D ⟦Γ⟧ ⟦C⟧) = refl lemma m (inj₂ (⟦A⟧ , ⟦B⟧)) rewrite subst″-sound C₃ (substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D) {m} {(⟦ Γ ˢ⟧□ n ⟦Γ⟧ m , ⟦A⟧) , ⟦B⟧} | bind-to->>= (Γ ˢ ,, G now ,, H now) ⟦ C₃ ⟧ᵐ ⟦ substitute′ ((Γ ˢˢₛ 𝒯erm) ↑ 𝒯erm) D ⟧ᵐ m ((⟦ Γ ˢ⟧□ n ⟦Γ⟧ m , ⟦A⟧) , ⟦B⟧) | (ext λ l → ext λ ⟦C⟧ → subst″-sound-lemma Γ n m l D ⟦Γ⟧ ⟦C⟧) = refl
{ "alphanum_fraction": 0.4481085589, "avg_line_length": 48.4963235294, "ext": "agda", "hexsha": "69f5559499938c6cb00516cbc8e88e38c1c3a50a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DimaSamoz/temporal-type-systems", "max_forks_repo_path": "src/Semantics/Substitution/Soundness.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DimaSamoz/temporal-type-systems", "max_issues_repo_path": "src/Semantics/Substitution/Soundness.agda", "max_line_length": 142, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DimaSamoz/temporal-type-systems", "max_stars_repo_path": "src/Semantics/Substitution/Soundness.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z", "max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z", "num_tokens": 7873, "size": 13191 }
module Category.Monad.Maybe.Typeclass where open import Category.Monad open import Data.Maybe record MaybeMonad (M : Set → Set) : Set₁ where field no : ∀ {A} → M A yes : ∀ {A} → A → M A open MaybeMonad maybe-monad-ops : MaybeMonad Maybe no maybe-monad-ops = nothing yes maybe-monad-ops = just
{ "alphanum_fraction": 0.6915584416, "avg_line_length": 20.5333333333, "ext": "agda", "hexsha": "09f48d124a9f992ffc5819507b1bd5c05f03331b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "metaborg/mj.agda", "max_forks_repo_path": "src/Category/Monad/Maybe/Typeclass.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "metaborg/mj.agda", "max_issues_repo_path": "src/Category/Monad/Maybe/Typeclass.agda", "max_line_length": 46, "max_stars_count": 10, "max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "metaborg/mj.agda", "max_stars_repo_path": "src/Category/Monad/Maybe/Typeclass.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z", "max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z", "num_tokens": 94, "size": 308 }
module Lib.Nat where open import Lib.Bool open import Lib.Logic open import Lib.Id data Nat : Set where zero : Nat suc : Nat -> Nat {-# BUILTIN NATURAL Nat #-} {-# BUILTIN ZERO zero #-} {-# BUILTIN SUC suc #-} infixr 50 _*_ infixr 40 _+_ _+_ : Nat -> Nat -> Nat zero + m = m suc n + m = suc (n + m) lem-plus-zero : (n : Nat) -> n + 0 ≡ n lem-plus-zero zero = refl lem-plus-zero (suc n) = cong suc (lem-plus-zero n) lem-plus-suc : (n m : Nat) -> n + suc m ≡ suc (n + m) lem-plus-suc zero m = refl lem-plus-suc (suc n) m = cong suc (lem-plus-suc n m) lem-plus-commute : (n m : Nat) -> n + m ≡ m + n lem-plus-commute n zero = lem-plus-zero _ lem-plus-commute n (suc m) with n + suc m | lem-plus-suc n m ... | .(suc (n + m)) | refl = cong suc (lem-plus-commute n m) _*_ : Nat -> Nat -> Nat zero * m = zero suc n * m = m + n * m {-# BUILTIN NATPLUS _+_ #-} {-# BUILTIN NATTIMES _*_ #-} _==_ : Nat -> Nat -> Bool zero == zero = true zero == suc _ = false suc _ == zero = false suc n == suc m = n == m {-# BUILTIN NATEQUALS _==_ #-} NonZero : Nat -> Set NonZero zero = False NonZero (suc _) = True
{ "alphanum_fraction": 0.5694200351, "avg_line_length": 21.0740740741, "ext": "agda", "hexsha": "b9691d81977f99c578225348863e178069e91326", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "examples/simple-lib/Lib/Nat.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "examples/simple-lib/Lib/Nat.agda", "max_line_length": 61, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "examples/simple-lib/Lib/Nat.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 416, "size": 1138 }
{-# OPTIONS --without-K --safe #-} module Util.Relation.Binary.LogicalEquivalence where open import Relation.Binary using (IsEquivalence ; Setoid) open import Util.Prelude private variable α β γ : Level A B C : Set α infix 4 _↔_ record _↔_ (A : Set α) (B : Set β) : Set (α ⊔ℓ β) where field forth : A → B back : B → A open _↔_ public ↔-refl : A ↔ A ↔-refl .forth = id ↔-refl .back = id ↔-reflexive : A ≡ B → A ↔ B ↔-reflexive refl = ↔-refl ↔-sym : A ↔ B → B ↔ A ↔-sym A↔B .forth = A↔B .back ↔-sym A↔B .back = A↔B .forth ↔-trans : A ↔ B → B ↔ C → A ↔ C ↔-trans A↔B B↔C .forth = B↔C .forth ∘ A↔B .forth ↔-trans A↔B B↔C .back = A↔B .back ∘ B↔C .back ↔-isEquivalence : IsEquivalence (_↔_ {α}) ↔-isEquivalence = record { refl = ↔-refl ; sym = ↔-sym ; trans = ↔-trans } ↔-setoid : ∀ α → Setoid (lsuc α) α ↔-setoid α .Setoid.Carrier = Set α ↔-setoid α .Setoid._≈_ = _↔_ ↔-setoid α .Setoid.isEquivalence = ↔-isEquivalence
{ "alphanum_fraction": 0.5846313603, "avg_line_length": 16.8947368421, "ext": "agda", "hexsha": "b0724c446b7c49115ef633356fc346aa2ff2ff2a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JLimperg/msc-thesis-code", "max_forks_repo_path": "src/Util/Relation/Binary/LogicalEquivalence.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JLimperg/msc-thesis-code", "max_issues_repo_path": "src/Util/Relation/Binary/LogicalEquivalence.agda", "max_line_length": 58, "max_stars_count": 5, "max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JLimperg/msc-thesis-code", "max_stars_repo_path": "src/Util/Relation/Binary/LogicalEquivalence.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z", "num_tokens": 428, "size": 963 }
module Categories.Families where open import Library open import Categories open Cat Fam : Set → Cat Fam I = record { Obj = I → Set; Hom = λ A B → ∀ {i} → A i → B i; iden = id; comp = λ f g → f ∘ g; idl = refl; idr = refl; ass = refl}
{ "alphanum_fraction": 0.5680933852, "avg_line_length": 15.1176470588, "ext": "agda", "hexsha": "7fefc55804ef0391dfba7f8631cf0e51456ef3d4", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jmchapman/Relative-Monads", "max_forks_repo_path": "Categories/Families.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "jmchapman/Relative-Monads", "max_issues_repo_path": "Categories/Families.agda", "max_line_length": 35, "max_stars_count": 21, "max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jmchapman/Relative-Monads", "max_stars_repo_path": "Categories/Families.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z", "num_tokens": 95, "size": 257 }
-- Functors on Set module Control.Functor where open import Function using (id; flip) renaming (_∘′_ to _∘_) open import Relation.Binary.PropositionalEquality open ≡-Reasoning -- Operations of a functor. module T-FunctorOps (F : Set → Set) where -- Type of the map function. T-map = ∀ {A B} → (A → B) → F A → F B T-for = ∀ {A B} → F A → (A → B) → F B record FunctorOps (F : Set → Set) : Set₁ where open T-FunctorOps F -- The map function. field map : T-map -- Alternative notations. for : T-for for = flip map infixr 5 _<$>_ _<&>_ _<$>_ = map _<&>_ = for -- Laws of a functor. module T-FunctorLaws {F : Set → Set} (ops : FunctorOps F) where open FunctorOps ops public -- First functor law: identity. ∀ (m : F A) → id <$> m ≡ m T-map-id = ∀ {A : Set} → map {A = A} id ≡ id -- Second functor law: composition. ∀ (m : F A) → (g ∘ f) <$> m ≡ g <$> (f <$> m) T-map-∘ = ∀ {A B C} {f : A → B} {g : B → C} → map (g ∘ f) ≡ map g ∘ map f record FunctorLaws {F : Set → Set} (ops : FunctorOps F) : Set₁ where open T-FunctorLaws ops field map-id : T-map-id map-∘ : T-map-∘ -- Functoriality. record IsFunctor (F : Set → Set) : Set₁ where field ops : FunctorOps F laws : FunctorLaws ops open FunctorOps ops public open FunctorLaws laws public record Functor : Set₁ where constructor functor field F : Set → Set F! : IsFunctor F open IsFunctor F! public -- Id is a functor. idIsFunctor : IsFunctor (λ A → A) idIsFunctor = record { ops = record { map = λ f → f } ; laws = record { map-id = refl ; map-∘ = refl } } Id : Functor Id = record { F = λ A → A ; F! = idIsFunctor } -- Functors compose. -- open FunctorOps {{...}} -- open FunctorLaws {{...}} compIsFunctor : ∀ {F G} → IsFunctor F → IsFunctor G → IsFunctor (λ A → F (G A)) compIsFunctor f g = record { ops = record { map = λ h → F.map (G.map h) } ; laws = record { map-id = trans (cong F.map G.map-id) F.map-id ; map-∘ = map-comp } } where module F = IsFunctor f module G = IsFunctor g map-comp : ∀ {A B C} {h : A → B} {i : B → C} → F.map (G.map (i ∘ h)) ≡ F.map (G.map i) ∘ F.map (G.map h) map-comp {h = h}{i = i} = begin F.map (G.map (i ∘ h)) ≡⟨ cong F.map G.map-∘ ⟩ F.map (G.map i ∘ G.map h) ≡⟨ F.map-∘ ⟩ F.map (G.map i) ∘ F.map (G.map h) ∎ Comp : Functor → Functor → Functor Comp (functor F F!) (functor G G!) = functor (λ A → F (G A)) (compIsFunctor F! G!) -- The constant functor. constIsFunctor : ∀ A → IsFunctor (λ _ → A) constIsFunctor A = record { ops = record { map = λ f x → x } ; laws = record { map-id = refl ; map-∘ = refl } } Const : (A : Set) → Functor Const A = functor (λ _ → A) (constIsFunctor A)
{ "alphanum_fraction": 0.5504067917, "avg_line_length": 21.9147286822, "ext": "agda", "hexsha": "4ff78b180de6dc3f377f6eaa723dc9baf5ef2f74", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andreasabel/cubical", "max_forks_repo_path": "src/Control/Functor.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andreasabel/cubical", "max_issues_repo_path": "src/Control/Functor.agda", "max_line_length": 83, "max_stars_count": null, "max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andreasabel/cubical", "max_stars_repo_path": "src/Control/Functor.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1030, "size": 2827 }
module Homotopy where infixr 20 _◎_ open import Data.Product ------------------------------------------------------------------------------ -- Level 0 -- Start with this set and its elements data B : Set where ZERO : B ONE : B PLUS : B → B → B TIMES : B → B → B ------------------------------------------------------------------------------ -- Level 1 -- Now we introduce Id_B. Given b1 : B, b2 : B, we have the types -- Id_B(b1,b2) of equivalences data Id_B : B × B → Set where unite₊ : { b : B } → Id_B (PLUS ZERO b , b) uniti₊ : { b : B } → Id_B (b , PLUS ZERO b) swap₊ : { b₁ b₂ : B } → Id_B (PLUS b₁ b₂ , PLUS b₂ b₁) assocl₊ : { b₁ b₂ b₃ : B } → Id_B (PLUS b₁ (PLUS b₂ b₃) , PLUS (PLUS b₁ b₂) b₃) assocr₊ : { b₁ b₂ b₃ : B } → Id_B (PLUS (PLUS b₁ b₂) b₃ , PLUS b₁ (PLUS b₂ b₃)) unite⋆ : { b : B } → Id_B (TIMES ONE b , b) uniti⋆ : { b : B } → Id_B (b , TIMES ONE b) swap⋆ : { b₁ b₂ : B } → Id_B (TIMES b₁ b₂ , TIMES b₂ b₁) assocl⋆ : { b₁ b₂ b₃ : B } → Id_B (TIMES b₁ (TIMES b₂ b₃) , TIMES (TIMES b₁ b₂) b₃) assocr⋆ : { b₁ b₂ b₃ : B } → Id_B (TIMES (TIMES b₁ b₂) b₃ , TIMES b₁ (TIMES b₂ b₃)) dist : { b₁ b₂ b₃ : B } → Id_B (TIMES (PLUS b₁ b₂) b₃ , PLUS (TIMES b₁ b₃) (TIMES b₂ b₃)) factor : { b₁ b₂ b₃ : B } → Id_B (PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) , TIMES (PLUS b₁ b₂) b₃) id⟷ : { b : B } → Id_B (b , b) sym : { b₁ b₂ : B } → Id_B (b₁ , b₂) → Id_B (b₂ , b₁) _◎_ : { b₁ b₂ b₃ : B } → Id_B (b₁ , b₂) → Id_B (b₂ , b₃) → Id_B (b₁ , b₃) _⊕_ : { b₁ b₂ b₃ b₄ : B } → Id_B (b₁ , b₃) → Id_B (b₂ , b₄) → Id_B (PLUS b₁ b₂ , PLUS b₃ b₄) _⊗_ : { b₁ b₂ b₃ b₄ : B } → Id_B (b₁ , b₃) → Id_B (b₂ , b₄) → Id_B (TIMES b₁ b₂ , TIMES b₃ b₄) -- values data BVAL : B → Set where UNIT : BVAL ONE LEFT : {b₁ b₂ : B} → BVAL b₁ → BVAL (PLUS b₁ b₂) RIGHT : {b₁ b₂ : B} → BVAL b₂ → BVAL (PLUS b₁ b₂) PAIR : {b₁ b₂ : B} → BVAL b₁ → BVAL b₂ → BVAL (TIMES b₁ b₂) mutual eval : {b₁ b₂ : B} → Id_B (b₁ , b₂) → BVAL b₁ → BVAL b₂ eval unite₊ (LEFT ()) eval unite₊ (RIGHT v) = v eval uniti₊ v = RIGHT v eval swap₊ (LEFT v) = RIGHT v eval swap₊ (RIGHT v) = LEFT v eval assocl₊ (LEFT v) = LEFT (LEFT v) eval assocl₊ (RIGHT (LEFT v)) = LEFT (RIGHT v) eval assocl₊ (RIGHT (RIGHT v)) = RIGHT v eval assocr₊ (LEFT (LEFT v)) = LEFT v eval assocr₊ (LEFT (RIGHT v)) = RIGHT (LEFT v) eval assocr₊ (RIGHT v) = RIGHT (RIGHT v) eval unite⋆ (PAIR UNIT v) = v eval uniti⋆ v = PAIR UNIT v eval swap⋆ (PAIR v1 v2) = PAIR v2 v1 eval assocl⋆ (PAIR v1 (PAIR v2 v3)) = PAIR (PAIR v1 v2) v3 eval assocr⋆ (PAIR (PAIR v1 v2) v3) = PAIR v1 (PAIR v2 v3) eval dist (PAIR (LEFT v1) v3) = LEFT (PAIR v1 v3) eval dist (PAIR (RIGHT v2) v3) = RIGHT (PAIR v2 v3) eval factor (LEFT (PAIR v1 v3)) = PAIR (LEFT v1) v3 eval factor (RIGHT (PAIR v2 v3)) = PAIR (RIGHT v2) v3 eval id⟷ v = v eval (sym c) v = evalB c v eval (c₁ ◎ c₂) v = eval c₂ (eval c₁ v) eval (c₁ ⊕ c₂) (LEFT v) = LEFT (eval c₁ v) eval (c₁ ⊕ c₂) (RIGHT v) = RIGHT (eval c₂ v) eval (c₁ ⊗ c₂) (PAIR v₁ v₂) = PAIR (eval c₁ v₁) (eval c₂ v₂) evalB : {b₁ b₂ : B} → Id_B (b₁ , b₂) → BVAL b₂ → BVAL b₁ evalB unite₊ v = RIGHT v evalB uniti₊ (LEFT ()) evalB uniti₊ (RIGHT v) = v evalB swap₊ (LEFT v) = RIGHT v evalB swap₊ (RIGHT v) = LEFT v evalB assocl₊ (LEFT (LEFT v)) = LEFT v evalB assocl₊ (LEFT (RIGHT v)) = RIGHT (LEFT v) evalB assocl₊ (RIGHT v) = RIGHT (RIGHT v) evalB assocr₊ (LEFT v) = LEFT (LEFT v) evalB assocr₊ (RIGHT (LEFT v)) = LEFT (RIGHT v) evalB assocr₊ (RIGHT (RIGHT v)) = RIGHT v evalB unite⋆ v = PAIR UNIT v evalB uniti⋆ (PAIR UNIT v) = v evalB swap⋆ (PAIR v1 v2) = PAIR v2 v1 evalB assocl⋆ (PAIR (PAIR v1 v2) v3) = PAIR v1 (PAIR v2 v3) evalB assocr⋆ (PAIR v1 (PAIR v2 v3)) = PAIR (PAIR v1 v2) v3 evalB dist (LEFT (PAIR v1 v3)) = PAIR (LEFT v1) v3 evalB dist (RIGHT (PAIR v2 v3)) = PAIR (RIGHT v2) v3 evalB factor (PAIR (LEFT v1) v3) = LEFT (PAIR v1 v3) evalB factor (PAIR (RIGHT v2) v3) = RIGHT (PAIR v2 v3) evalB id⟷ v = v evalB (sym c) v = eval c v evalB (c₁ ◎ c₂) v = evalB c₁ (evalB c₂ v) evalB (c₁ ⊕ c₂) (LEFT v) = LEFT (evalB c₁ v) evalB (c₁ ⊕ c₂) (RIGHT v) = RIGHT (evalB c₂ v) evalB (c₁ ⊗ c₂) (PAIR v₁ v₂) = PAIR (evalB c₁ v₁) (evalB c₂ v₂) ------------------------------------------------------------------------------ -- Level 2 -- Now we introduce Id_{Id_B}. Given c1 : Id_B(b1,b2) and c2 : -- Id_B(b1,b2), we have the type of equivalences that show that c1 and -- c2 are isomorphic. -- -- We want: -- -- data Id_Id_B : {b₁ b₂ : B} → Id_B (b₁ , b₂) × Id_B (b₁ , b₂) → Set where -- ... -- but before we do that we need to embed the combinators as values that can -- be manipulated using combinators -- define the category Int C whose objects are pairs (B,B) and which has an -- inverse recip sending (B1,B2) to (B2,B1) and then the compact closed -- eta/epsilon where eta : I -> (A+,A-) * (recip (A+,A-)) -- the embedding send B to (B,I) -- INT B has as objects pairs of B objects {-- data Id_BB : (B × B) × (B × B) → Set where intarr : { b₁ b₂ b₃ b₄ : B } → Id_BB ((b₁ , b₂) , (b₃ , b₄)) embedArr : { b₁ b₂ b₃ b₄ : B } → Id_BB ((b₁ , b₂) , (b₃ , b₄)) → Id_B ((b₁ , b₄) , (b₂ , b₃)) embedArr x = ? Iuniti₊ : { b : B } → Id_BB (b , PLUS ZERO b) Iswap₊ : { b₁ b₂ : B } → Id_BB (PLUS b₁ b₂ , PLUS b₂ b₁) Iassocl₊ : { b₁ b₂ b₃ : B } → Id_BB (PLUS b₁ (PLUS b₂ b₃) , PLUS (PLUS b₁ b₂) b₃) Iassocr₊ : { b₁ b₂ b₃ : B } → Id_BB (PLUS (PLUS b₁ b₂) b₃ , PLUS b₁ (PLUS b₂ b₃)) Iunite⋆ : { b : B } → Id_BB (TIMES ONE b , b) Iuniti⋆ : { b : B } → Id_BB (b , TIMES ONE b) Iswap⋆ : { b₁ b₂ : B } → Id_BB (TIMES b₁ b₂ , TIMES b₂ b₁) Iassocl⋆ : { b₁ b₂ b₃ : B } → Id_BB (TIMES b₁ (TIMES b₂ b₃) , TIMES (TIMES b₁ b₂) b₃) Iassocr⋆ : { b₁ b₂ b₃ : B } → Id_BB (TIMES (TIMES b₁ b₂) b₃ , TIMES b₁ (TIMES b₂ b₃)) Idist : { b₁ b₂ b₃ : B } → Id_BB (TIMES (PLUS b₁ b₂) b₃ , PLUS (TIMES b₁ b₃) (TIMES b₂ b₃)) Ifactor : { b₁ b₂ b₃ : B } → Id_BB (PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) , TIMES (PLUS b₁ b₂) b₃) Iid⟷ : { b : B } → Id_BB (b , b) Isym : { b₁ b₂ : B } → Id_BB (b₁ , b₂) → Id_BB (b₂ , b₁) _I◎_ : { b₁ b₂ b₃ : B } → Id_BB (b₁ , b₂) → Id_BB (b₂ , b₃) → Id_BB (b₁ , b₃) _I⊕_ : { b₁ b₂ b₃ b₄ : B } → Id_BB (b₁ , b₃) → Id_BB (b₂ , b₄) → Id_BB (PLUS b₁ b₂ , PLUS b₃ b₄) _I⊗_ : { b₁ b₂ b₃ b₄ : B } → Id_BB (b₁ , b₃) → Id_BB (b₂ , b₄) → Id_BB (TIMES b₁ b₂ , TIMES b₃ b₄) data BRVAL : BR → Set where UNITR : BRVAL ONER LEFTR : {b₁ b₂ : BR} → BRVAL b₁ → BRVAL (PLUSR b₁ b₂) RIGHTR : {b₁ b₂ : BR} → BRVAL b₂ → BRVAL (PLUSR b₁ b₂) PAIRR : {b₁ b₂ : BR} → BRVAL b₁ → BRVAL b₂ → BRVAL (TIMESR b₁ b₂) RECIPR : {b : BR} → BRVAL b → BRVAL (RECIP b) embedT : B → BR embedT ZERO = ZEROR embedT ONE = ONER embedT (PLUS b₁ b₂) = PLUSR (embedT b₁) (embedT b₂) embedT (TIMES b₁ b₂) = TIMESR (embedT b₁) (embedT b₂) embedV : {b : B} → BVAL b → BRVAL (embedT b) embedV UNIT = UNITR embedV (LEFT v) = LEFTR (embedV v) embedV (RIGHT v) = RIGHTR (embedV v) embedV (PAIR v₁ v₂) = PAIRR (embedV v₁) (embedV v₂) embedC : {b₁ b₂ : B} → Id_B (b₁ , b₂) → BRVAL (TIMESR (RECIP (embedT b₁)) (embedT b₂)) embedC unite₊ = ? embedC uniti₊ = ? embedC swap₊ = ? embedC assocl₊ = ? embedC assocr₊ = ? embedC unite⋆ = ? embedC uniti⋆ = ? embedC swap⋆ = ? embedC assocl⋆ = ? embedC assocr⋆ = ? embedC dist = ? embedC factor = ? embedC id⟷ = ? embedC (sym c) = ? embedC (c₁ ◎ c₂) = ? embedC (c₁ ⊕ c₂) = ? embedC (c₁ ⊗ c₂) = ? --}
{ "alphanum_fraction": 0.5380193363, "avg_line_length": 36.7980769231, "ext": "agda", "hexsha": "7b7c6e54cbd814f848a6a9cb1a66e8be81d4daa6", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z", "max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "JacquesCarette/pi-dual", "max_forks_repo_path": "agda/Homotopy.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z", "max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "JacquesCarette/pi-dual", "max_issues_repo_path": "agda/Homotopy.agda", "max_line_length": 83, "max_stars_count": 14, "max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "JacquesCarette/pi-dual", "max_stars_repo_path": "agda/Homotopy.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z", "num_tokens": 3473, "size": 7654 }
{-# OPTIONS --safe --warning=error --without-K #-} open import Groups.Definition open import Functions.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import LogicalFormulae open import Setoids.Subset open import Setoids.Setoids open import Setoids.Orders.Partial.Definition open import Fields.Fields open import Rings.Orders.Total.Lemmas open import Rings.Orders.Partial.Definition open import Rings.Definition open import Fields.Orders.LeastUpperBounds.Definition open import Fields.Orders.Total.Definition open import Sets.EquivalenceRelations module Numbers.ClassicalReals.RealField.Lemmas {a b c : _} {A : Set a} {S : Setoid {_} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} (F : Field R) {_<_ : Rel {_} {c} A} {pOrder : SetoidPartialOrder S _<_} (pOrderedRing : PartiallyOrderedRing R pOrder) {orderNontrivialX orderNontrivialY : A} (orderNontrivial : orderNontrivialX < orderNontrivialY) where open Ring R open Group additiveGroup open Setoid S open Equivalence eq open SetoidPartialOrder pOrder open import Rings.Orders.Partial.Lemmas pOrderedRing open PartiallyOrderedRing pOrderedRing IsInterval : {d : _} {pred : A → Set d} (subset : subset S pred) → Set (a ⊔ c ⊔ d) IsInterval {pred = pred} subset = (x y : A) → (x<y : x < y) → pred x → pred y → (c : A) → (x < c) → (c < y) → pred c -- Example: (a, b) is an interval openBallPred : A → A → A → Set c openBallPred a b x = (a < x) && (x < b) openBallSubset : (a b : A) → subset S (openBallPred a b) openBallSubset a b {x} {y} x=y (a<x ,, x<y) = <WellDefined reflexive x=y a<x ,, <WellDefined x=y reflexive x<y openBallInterval : (a b : A) → IsInterval (openBallSubset a b) openBallInterval a b x y x<y (a<x ,, x<b) (a<y ,, y<b) c x<c c<y = <Transitive a<x x<c ,, <Transitive c<y y<b nonemptyBoundedIntervalHasLubImpliesAllLub : ({d : _} {pred : A → Set d} {subset : subset S pred} (interval : IsInterval subset) → (nonempty : Sg A pred) → (boundedAbove : Sg A (UpperBound pOrder subset)) → Sg A (LeastUpperBound pOrder subset)) → {d : _} → {pred : A → Set d} → (sub : subset S pred) → (nonempty : Sg A pred) → (boundedAbove : Sg A (UpperBound pOrder sub)) → Sg A (LeastUpperBound pOrder sub) nonemptyBoundedIntervalHasLubImpliesAllLub axiom {d} {pred} sub (member , predMember) (bound , isBound) = lub , lubIsLub where intervalPredicate : A → Set (a ⊔ b ⊔ c ⊔ d) intervalPredicate a = Sg A (λ k → ((a < k) || (a ∼ k)) && pred k) intervalIsSubset : subset S intervalPredicate intervalIsSubset {x} {y} x=y (bigger , (inl x<bigger ,, biggerWorks)) = (bigger , (inl (<WellDefined x=y reflexive x<bigger) ,, biggerWorks)) intervalIsSubset {x} {y} x=y (bigger , (inr x=bigger ,, biggerWorks)) = (bigger , (inr (transitive (symmetric x=y) x=bigger) ,, biggerWorks)) intervalIsInterval : IsInterval intervalIsSubset intervalIsInterval x y x<y (dominateX , (x<dominateX ,, predDominateX)) (dominateY , (inl y<dominateY ,, predDominateY)) c x<c c<y = dominateY , (inl (<Transitive c<y y<dominateY) ,, predDominateY) intervalIsInterval x y x<y (dominateX , (x<dominateX ,, predDominateX)) (dominateY , (inr y=dominateY ,, predDominateY)) c x<c c<y = dominateY , (inl (<WellDefined reflexive y=dominateY c<y) ,, predDominateY) intervalNonempty : Sg A intervalPredicate intervalNonempty = ((member + orderNontrivialX) + inverse orderNontrivialY) , (member , (inl (<WellDefined (transitive groupIsAbelian +Associative) identLeft (orderRespectsAddition (moveInequality' orderNontrivial) member)) ,, predMember)) intervalBounded : Sg A (UpperBound pOrder intervalIsSubset) intervalBounded = bound , ans where ans : (y : A) → intervalPredicate y → (y < bound) || (y ∼ bound) ans y (boundY , (y<boundY ,, predY)) with isBound boundY predY ans y (boundY , (inl y<boundY ,, predY)) | inl boundY<Bound = inl (<Transitive y<boundY boundY<Bound) ans y (boundY , (inr y=boundY ,, predY)) | inl boundY<Bound = inl (<WellDefined (symmetric y=boundY) reflexive boundY<Bound) ans y (boundY , (inl y<boundY ,, predY)) | inr boundY=Bound = inl (<WellDefined reflexive boundY=Bound y<boundY) ans y (boundY , (inr y=boundY ,, predY)) | inr boundY=Bound = inr (transitive y=boundY boundY=Bound) intervalLub : Sg A (LeastUpperBound pOrder intervalIsSubset) intervalLub = axiom intervalIsInterval intervalNonempty intervalBounded lub : A lub with intervalLub ... | b , _ = b lubProof : LeastUpperBound pOrder intervalIsSubset lub lubProof with intervalLub ... | b , pr = pr ubImpliesUbSub : {x : A} → UpperBound pOrder sub x → UpperBound pOrder intervalIsSubset x ubImpliesUbSub {x} ub y (bound , (y<bound ,, predBound)) with ub bound predBound ubImpliesUbSub {x} ub y (bound , (inl y<bound ,, predBound)) | inl bound<x = inl (<Transitive y<bound bound<x) ubImpliesUbSub {x} ub y (bound , (inr y=bound ,, predBound)) | inl bound<x = inl (<WellDefined (symmetric y=bound) reflexive bound<x) ubImpliesUbSub {x} ub y (bound , (inl y<bound ,, predBound)) | inr bound=x = inl (<WellDefined reflexive bound=x y<bound) ubImpliesUbSub {x} ub y (bound , (inr y=bound ,, predBound)) | inr bound=x = inr (transitive y=bound bound=x) ubSubImpliesUb : {x : A} → UpperBound pOrder intervalIsSubset x → UpperBound pOrder sub x ubSubImpliesUb {x} ub y predY with ub y (y , (inr reflexive ,, predY)) ubSubImpliesUb {x} ub y predY | inl t<x = inl t<x ubSubImpliesUb {x} ub y predY | inr t=x = inr t=x lubIsLub : LeastUpperBound pOrder sub lub LeastUpperBound.upperBound lubIsLub = ubSubImpliesUb (LeastUpperBound.upperBound lubProof) LeastUpperBound.leastUpperBound lubIsLub y yIsUpperBound = LeastUpperBound.leastUpperBound lubProof y (ubImpliesUbSub yIsUpperBound)
{ "alphanum_fraction": 0.6977065011, "avg_line_length": 70.7195121951, "ext": "agda", "hexsha": "8039d2dbcf3d85f9fe3fc3eb264850b2179f9c7b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Numbers/ClassicalReals/RealField/Lemmas.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Numbers/ClassicalReals/RealField/Lemmas.agda", "max_line_length": 408, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Numbers/ClassicalReals/RealField/Lemmas.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 1888, "size": 5799 }
module UniDB.Morph.StarPrime where open import UniDB.Spec open import UniDB.Morph.Depth mutual data Star* (Ξ : MOR) : MOR where refl : {γ : Dom} → Star* Ξ γ γ incl : {γ₁ γ₂ : Dom} (ξs : Star+ Ξ γ₁ γ₂) → Star* Ξ γ₁ γ₂ data Star+ (Ξ : MOR) : MOR where step : {γ₁ γ₂ γ₃ : Dom} (ξs : Star* Ξ γ₁ γ₂) (ξ : Ξ γ₂ γ₃) → Star+ Ξ γ₁ γ₃ module _ {Ξ : MOR} where mutual step` : {Ξ : MOR} {γ₁ γ₂ γ₃ : Dom} (ξ : Ξ γ₁ γ₂) (ζs : Star* Ξ γ₂ γ₃) → Star+ Ξ γ₁ γ₃ step` ξ refl = step refl ξ step` ξ (incl ζ) = step+ ξ ζ step+ : {Ξ : MOR} {γ₁ γ₂ γ₃ : Dom} (ξ : Ξ γ₁ γ₂) (ζs : Star+ Ξ γ₂ γ₃) → Star+ Ξ γ₁ γ₃ step+ ξ (step ζs ζ) = step (incl (step` ξ ζs)) ζ mutual comp** : {γ₁ γ₂ γ₃ : Dom} (ξs : Star* Ξ γ₁ γ₂) (ζs : Star* Ξ γ₂ γ₃) → Star* Ξ γ₁ γ₃ comp** ξs refl = ξs comp** ξs (incl ζs) = incl (comp*+ ξs ζs) comp*+ : {γ₁ γ₂ γ₃ : Dom} (ξs : Star* Ξ γ₁ γ₂) (ζs : Star+ Ξ γ₂ γ₃) → Star+ Ξ γ₁ γ₃ comp*+ ξs (step ζs ζ) = step (comp** ξs ζs) ζ mutual comp+* : {γ₁ γ₂ γ₃ : Dom} (ξs : Star+ Ξ γ₁ γ₂) (ζs : Star* Ξ γ₂ γ₃) → Star+ Ξ γ₁ γ₃ comp+* ξs refl = ξs comp+* ξs (incl ζs) = comp++ ξs ζs comp++ : {γ₁ γ₂ γ₃ : Dom} (ξs : Star+ Ξ γ₁ γ₂) (ζs : Star+ Ξ γ₂ γ₃) → Star+ Ξ γ₁ γ₃ comp++ ξs (step ζs ζ) = step (incl (comp+* ξs ζs)) ζ module _ {Ξ : MOR} {{upΞ : Up Ξ}} where mutual instance iUpStar* : Up (Star* Ξ) _↑₁ {{iUpStar*}} refl = refl _↑₁ {{iUpStar*}} (incl ξs) = incl (ξs ↑₁) _↑_ {{iUpStar*}} ξ 0 = ξ _↑_ {{iUpStar*}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁ ↑-zero {{iUpStar*}} ξ = refl ↑-suc {{iUpStar*}} ξ δ⁺ = refl iUpStar+ : Up (Star+ Ξ) _↑₁ {{iUpStar+}} (step ξs ξ) = step (ξs ↑₁) (ξ ↑₁) _↑_ {{iUpStar+}} ξ 0 = ξ _↑_ {{iUpStar+}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁ ↑-zero {{iUpStar+}} ξ = refl ↑-suc {{iUpStar+}} ξ δ⁺ = refl
{ "alphanum_fraction": 0.5002669514, "avg_line_length": 32.8596491228, "ext": "agda", "hexsha": "ba84ad11e8fc92f2226844dccf878da7e0621e73", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "skeuchel/unidb-agda", "max_forks_repo_path": "UniDB/Morph/StarPrime.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "skeuchel/unidb-agda", "max_issues_repo_path": "UniDB/Morph/StarPrime.agda", "max_line_length": 89, "max_stars_count": null, "max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "skeuchel/unidb-agda", "max_stars_repo_path": "UniDB/Morph/StarPrime.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 997, "size": 1873 }
-- Andreas, 2015-12-28, issue reported by effectfully -- {-# OPTIONS -v tc.data.fits:15 -v tc.conv.sort:30 -v tc.conv.nat:30 #-} open import Common.Level postulate fun : Level → Level data Test : Set (fun lzero) where c : Test → Test -- The primitive lzero in argument of neutral is what matters here. -- Agda reported: -- The type of the constructor does not fit in the sort of the -- datatype, since Set (fun lzero) is not less or equal than -- Set (fun lzero) -- Upon inspection of non-prettyTCM Terms, one side had turned -- `lzero` into `Level (Max [])`, whereas it remained `Def lzero []` -- on the other side. -- Should work now.
{ "alphanum_fraction": 0.6855828221, "avg_line_length": 29.6363636364, "ext": "agda", "hexsha": "3e188ca9fb472973b10171b8ae72401628a242a0", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue1757.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue1757.agda", "max_line_length": 74, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue1757.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 186, "size": 652 }
-- 2014-04-06 Andreas, issue reported by flickyfrans -- {-# OPTIONS --show-implicit -v tc.section.apply:60 #-} open import Common.Level renaming (lsuc to suc) record RawMonad {α β : Level} (M : {γ : Level} → Set γ → Set γ) : Set (suc (α ⊔ β)) where infixl 1 _>>=_ field return' : {A : Set α} → A → M A _>>=_ : {A : Set α} {B : Set β} → M A → (A → M B) → M B module MonoMonad {α} = RawMonad {α} {α} module MM = MonoMonad {{...}} -- return : {α : Level} {M : {γ : Level} → Set γ → Set γ} {{m : RawMonad {α} {α} M }} {A : Set α} → A → M A return : _ return = MM.return' -- WAS: Panic: deBruijn index out of scope: 2 in context [M,α] -- when checking that the expression MM.return' has type _15 -- CAUSE: Ill-formed section telescope produced by checkSectionApplication. -- NOW: Works.
{ "alphanum_fraction": 0.6007462687, "avg_line_length": 30.9230769231, "ext": "agda", "hexsha": "eabfb3fc8c569808ffbfe1c24433ff005699ea8f", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue1094.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue1094.agda", "max_line_length": 107, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue1094.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 277, "size": 804 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Some properties of reflexive closures ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module Relation.Binary.Construct.Closure.Reflexive.Properties where open import Data.Product as Prod open import Data.Sum.Base as Sum open import Function.Equivalence using (_⇔_; equivalence) open import Function using (id) open import Level open import Relation.Binary open import Relation.Binary.Construct.Closure.Reflexive open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl) open import Relation.Nullary import Relation.Nullary.Decidable as Dec open import Relation.Nullary.Negation using (contradiction) open import Relation.Nullary.Sum using (_⊎-dec_) open import Relation.Unary using (Pred) private variable a b ℓ p q : Level A : Set a B : Set b ------------------------------------------------------------------------ -- Relational properties module _ {P : Rel A p} {Q : Rel B q} where =[]⇒ : ∀ {f : A → B} → P =[ f ]⇒ Q → Refl P =[ f ]⇒ Refl Q =[]⇒ x [ x∼y ] = [ x x∼y ] =[]⇒ x refl = refl module _ {_~_ : Rel A ℓ} where sym : Symmetric _~_ → Symmetric (Refl _~_) sym ~-sym [ x∼y ] = [ ~-sym x∼y ] sym ~-sym refl = refl trans : Transitive _~_ → Transitive (Refl _~_) trans ~-trans [ x∼y ] [ x∼y₁ ] = [ ~-trans x∼y x∼y₁ ] trans ~-trans [ x∼y ] refl = [ x∼y ] trans ~-trans refl [ x∼y ] = [ x∼y ] trans ~-trans refl refl = refl antisym : ∀ {ℓ'} (_≈_ : Rel A ℓ') → Reflexive _≈_ → Asymmetric _~_ → Antisymmetric _≈_ (Refl _~_) antisym _≈_ ref asym [ x∼y ] [ y∼x ] = contradiction x∼y (asym y∼x) antisym _≈_ ref asym [ x∼y ] refl = ref antisym _≈_ ref asym refl _ = ref total : Trichotomous _≡_ _~_ → Total (Refl _~_) total compare x y with compare x y ... | tri< a _ _ = inj₁ [ a ] ... | tri≈ _ refl _ = inj₁ refl ... | tri> _ _ c = inj₂ [ c ] fromSum : ∀ {a b} → a ≡ b ⊎ a ~ b → Refl _~_ a b fromSum (inj₁ refl) = refl fromSum (inj₂ y) = [ y ] toSum : ∀ {a b} → Refl _~_ a b → a ≡ b ⊎ a ~ b toSum [ x∼y ] = inj₂ x∼y toSum refl = inj₁ refl ⊎⇔Refl : ∀ {a b} → (a ≡ b ⊎ a ~ b) ⇔ Refl _~_ a b ⊎⇔Refl = equivalence fromSum toSum dec : Decidable {A = A} _≡_ → Decidable _~_ → Decidable (Refl _~_) dec ≡-dec ~-dec a b = Dec.map ⊎⇔Refl (≡-dec a b ⊎-dec ~-dec a b) decidable : Trichotomous _≡_ _~_ → Decidable (Refl _~_) decidable ~-tri a b with ~-tri a b ... | tri< a~b _ _ = yes [ a~b ] ... | tri≈ _ refl _ = yes refl ... | tri> ¬a ¬b _ = no λ { refl → ¬b refl ; [ p ] → ¬a p } respˡ : ∀ {P : REL A B p} → P Respectsˡ _~_ → P Respectsˡ (Refl _~_) respˡ p-respˡ-~ [ x∼y ] = p-respˡ-~ x∼y respˡ _ refl = id respʳ : ∀ {P : REL B A p} → P Respectsʳ _~_ → P Respectsʳ (Refl _~_) respʳ = respˡ module _ {_~_ : Rel A ℓ} {P : Pred A p} where resp : P Respects _~_ → P Respects (Refl _~_) resp p-resp-~ [ x∼y ] = p-resp-~ x∼y resp _ refl = id module _ {_~_ : Rel A ℓ} {P : Rel A p} where resp₂ : P Respects₂ _~_ → P Respects₂ (Refl _~_) resp₂ = Prod.map respˡ respʳ ------------------------------------------------------------------------ -- Structures module _ {_~_ : Rel A ℓ} where isPreorder : Transitive _~_ → IsPreorder _≡_ (Refl _~_) isPreorder ~-trans = record { isEquivalence = PropEq.isEquivalence ; reflexive = λ { refl → refl } ; trans = trans ~-trans } isPartialOrder : IsStrictPartialOrder _≡_ _~_ → IsPartialOrder _≡_ (Refl _~_) isPartialOrder O = record { isPreorder = isPreorder O.trans ; antisym = antisym _≡_ refl O.asym } where module O = IsStrictPartialOrder O isDecPartialOrder : IsDecStrictPartialOrder _≡_ _~_ → IsDecPartialOrder _≡_ (Refl _~_) isDecPartialOrder O = record { isPartialOrder = isPartialOrder O.isStrictPartialOrder ; _≟_ = O._≟_ ; _≤?_ = dec O._≟_ O._<?_ } where module O = IsDecStrictPartialOrder O isTotalOrder : IsStrictTotalOrder _≡_ _~_ → IsTotalOrder _≡_ (Refl _~_) isTotalOrder O = record { isPartialOrder = isPartialOrder isStrictPartialOrder ; total = total compare } where open IsStrictTotalOrder O isDecTotalOrder : IsStrictTotalOrder _≡_ _~_ → IsDecTotalOrder _≡_ (Refl _~_) isDecTotalOrder O = record { isTotalOrder = isTotalOrder O ; _≟_ = _≟_ ; _≤?_ = dec _≟_ _<?_ } where open IsStrictTotalOrder O
{ "alphanum_fraction": 0.5649520488, "avg_line_length": 33.0071942446, "ext": "agda", "hexsha": "2ae820f18337f47644b26c3939441a73550fd01d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Relation/Binary/Construct/Closure/Reflexive/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Relation/Binary/Construct/Closure/Reflexive/Properties.agda", "max_line_length": 88, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Relation/Binary/Construct/Closure/Reflexive/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 1655, "size": 4588 }
{-# OPTIONS --safe --warning=error --without-K #-} open import Functions.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import LogicalFormulae open import Sets.EquivalenceRelations module Setoids.Setoids where record Setoid {a} {b} (A : Set a) : Set (a ⊔ lsuc b) where infix 1 _∼_ field _∼_ : A → A → Set b eq : Equivalence _∼_ open Equivalence eq ~refl : {r : A} → (r ∼ r) ~refl {r} = reflexive {r} record Quotient {a} {b} {c} {A : Set a} {image : Set b} (S : Setoid {a} {c} A) : Set (a ⊔ b ⊔ c) where open Setoid S field map : A → image mapWellDefined : {x y : A} → x ∼ y → map x ≡ map y mapSurjective : Surjection map mapInjective : {x y : A} → map x ≡ map y → x ∼ y record SetoidToSet {a b c : _} {A : Set a} (S : Setoid {a} {c} A) (quotient : Set b) : Set (a ⊔ b ⊔ c) where open Setoid S field project : A → quotient wellDefined : (x y : A) → (x ∼ y) → project x ≡ project y surj : Surjection project inj : (x y : A) → project x ≡ project y → x ∼ y open Setoid reflSetoid : {a : _} (A : Set a) → Setoid A _∼_ (reflSetoid A) a b = a ≡ b Equivalence.reflexive (eq (reflSetoid A)) = refl Equivalence.symmetric (eq (reflSetoid A)) {b} {.b} refl = refl Equivalence.transitive (eq (reflSetoid A)) {b} {.b} {.b} refl refl = refl record SetoidInjection {a b c d : _} {A : Set a} {B : Set b} (S : Setoid {a} {c} A) (T : Setoid {b} {d} B) (f : A → B) : Set (a ⊔ b ⊔ c ⊔ d) where open Setoid S renaming (_∼_ to _∼A_) open Setoid T renaming (_∼_ to _∼B_) field wellDefined : {x y : A} → x ∼A y → (f x) ∼B (f y) injective : {x y : A} → (f x) ∼B (f y) → x ∼A y reflSetoidWellDefined : {a b c : _} {A : Set a} (S : Setoid {a} {b} A) (C : Set c) (f : C → A) → {x y : C} → x ≡ y → Setoid._∼_ S (f x) (f y) reflSetoidWellDefined S C f refl = Equivalence.reflexive (Setoid.eq S) record SetoidSurjection {a b c d : _} {A : Set a} {B : Set b} (S : Setoid {a} {c} A) (T : Setoid {b} {d} B) (f : A → B) : Set (a ⊔ b ⊔ c ⊔ d) where open Setoid S renaming (_∼_ to _∼A_) open Setoid T renaming (_∼_ to _∼B_) field wellDefined : {x y : A} → x ∼A y → (f x) ∼B (f y) surjective : {x : B} → Sg A (λ a → f a ∼B x) record SetoidBijection {a b c d : _} {A : Set a} {B : Set b} (S : Setoid {a} {c} A) (T : Setoid {b} {d} B) (f : A → B) : Set (a ⊔ b ⊔ c ⊔ d) where field inj : SetoidInjection S T f surj : SetoidSurjection S T f wellDefined : {x y : A} → Setoid._∼_ S x y → Setoid._∼_ T (f x) (f y) wellDefined = SetoidInjection.wellDefined inj record SetoidsBiject {a b c d : _} {A : Set a} {B : Set b} (S : Setoid {a} {c} A) (T : Setoid {b} {d} B) : Set (a ⊔ b ⊔ c ⊔ d) where field bij : A → B bijIsBijective : SetoidBijection S T bij setoidInjComp : {a b c d e f : _} {A : Set a} {B : Set b} {C : Set c} {S : Setoid {a} {d} A} {T : Setoid {b} {e} B} {U : Setoid {c} {f} C} {g : A → B} {h : B → C} → (gB : SetoidInjection S T g) (hB : SetoidInjection T U h) → SetoidInjection S U (h ∘ g) SetoidInjection.wellDefined (setoidInjComp gI hI) x~y = SetoidInjection.wellDefined hI (SetoidInjection.wellDefined gI x~y) SetoidInjection.injective (setoidInjComp gI hI) hgx~hgy = SetoidInjection.injective gI (SetoidInjection.injective hI hgx~hgy) setoidSurjComp : {a b c d e f : _} {A : Set a} {B : Set b} {C : Set c} {S : Setoid {a} {d} A} {T : Setoid {b} {e} B} {U : Setoid {c} {f} C} {g : A → B} {h : B → C} → (gB : SetoidSurjection S T g) (hB : SetoidSurjection T U h) → SetoidSurjection S U (h ∘ g) SetoidSurjection.wellDefined (setoidSurjComp gI hI) x~y = SetoidSurjection.wellDefined hI (SetoidSurjection.wellDefined gI x~y) SetoidSurjection.surjective (setoidSurjComp gI hI) {x} with SetoidSurjection.surjective hI {x} SetoidSurjection.surjective (setoidSurjComp gI hI) {x} | a , prA with SetoidSurjection.surjective gI {a} SetoidSurjection.surjective (setoidSurjComp {U = U} gI hI) {x} | a , prA | b , prB = b , Equivalence.transitive (Setoid.eq U) (SetoidSurjection.wellDefined hI prB) prA where open Setoid U setoidBijComp : {a b c d e f : _} {A : Set a} {B : Set b} {C : Set c} {S : Setoid {a} {d} A} {T : Setoid {b} {e} B} {U : Setoid {c} {f} C} {g : A → B} {h : B → C} → (gB : SetoidBijection S T g) (hB : SetoidBijection T U h) → SetoidBijection S U (h ∘ g) SetoidBijection.inj (setoidBijComp gB hB) = setoidInjComp (SetoidBijection.inj gB) (SetoidBijection.inj hB) SetoidBijection.surj (setoidBijComp gB hB) = setoidSurjComp (SetoidBijection.surj gB) (SetoidBijection.surj hB) setoidIdIsBijective : {a b : _} {A : Set a} {S : Setoid {a} {b} A} → SetoidBijection S S (λ i → i) SetoidInjection.wellDefined (SetoidBijection.inj (setoidIdIsBijective {A = A})) = id SetoidInjection.injective (SetoidBijection.inj (setoidIdIsBijective {A = A})) = id SetoidSurjection.wellDefined (SetoidBijection.surj (setoidIdIsBijective {A = A})) = id SetoidSurjection.surjective (SetoidBijection.surj (setoidIdIsBijective {S = S})) {x} = x , Equivalence.reflexive (Setoid.eq S) record SetoidInvertible {a b c d : _} {A : Set a} {B : Set b} (S : Setoid {a} {c} A) (T : Setoid {b} {d} B) (f : A → B) : Set (a ⊔ b ⊔ c ⊔ d) where field fWellDefined : {x y : A} → Setoid._∼_ S x y → Setoid._∼_ T (f x) (f y) inverse : B → A inverseWellDefined : {x y : B} → Setoid._∼_ T x y → Setoid._∼_ S (inverse x) (inverse y) isLeft : (b : B) → Setoid._∼_ T (f (inverse b)) b isRight : (a : A) → Setoid._∼_ S (inverse (f a)) a setoidBijectiveImpliesInvertible : {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {f : A → B} (bij : SetoidBijection S T f) → SetoidInvertible S T f SetoidInvertible.fWellDefined (setoidBijectiveImpliesInvertible bij) x~y = SetoidInjection.wellDefined (SetoidBijection.inj bij) x~y SetoidInvertible.inverse (setoidBijectiveImpliesInvertible bij) x with SetoidSurjection.surjective (SetoidBijection.surj bij) {x} SetoidInvertible.inverse (setoidBijectiveImpliesInvertible bij) x | a , b = a SetoidInvertible.inverseWellDefined (setoidBijectiveImpliesInvertible bij) {x} {y} x~y with SetoidSurjection.surjective (SetoidBijection.surj bij) {x} SetoidInvertible.inverseWellDefined (setoidBijectiveImpliesInvertible {T = T} bij) {x} {y} x~y | a , prA with SetoidSurjection.surjective (SetoidBijection.surj bij) {y} ... | b , prB = SetoidInjection.injective (SetoidBijection.inj bij) (Equivalence.transitive (Setoid.eq T) prA (Equivalence.transitive (Setoid.eq T) x~y (Equivalence.symmetric (Setoid.eq T) prB))) where open Setoid T SetoidInvertible.isLeft (setoidBijectiveImpliesInvertible bij) b with SetoidSurjection.surjective (SetoidBijection.surj bij) {b} ... | a , prA = prA SetoidInvertible.isRight (setoidBijectiveImpliesInvertible {f = f} bij) b with SetoidSurjection.surjective (SetoidBijection.surj bij) {f b} ... | fb , prFb = SetoidInjection.injective (SetoidBijection.inj bij) prFb setoidInvertibleImpliesBijective : {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {f : A → B} (inv : SetoidInvertible S T f) → SetoidBijection S T f SetoidInjection.wellDefined (SetoidBijection.inj (setoidInvertibleImpliesBijective inv)) x~y = SetoidInvertible.fWellDefined inv x~y SetoidInjection.injective (SetoidBijection.inj (setoidInvertibleImpliesBijective {S = S} {f = f} inv)) {x} {y} pr = Equivalence.transitive (Setoid.eq S) (Equivalence.symmetric (Setoid.eq S) (SetoidInvertible.isRight inv x)) (Equivalence.transitive (Setoid.eq S) (SetoidInvertible.inverseWellDefined inv pr) (SetoidInvertible.isRight inv y)) where open Setoid S SetoidSurjection.wellDefined (SetoidBijection.surj (setoidInvertibleImpliesBijective inv)) x~y = SetoidInvertible.fWellDefined inv x~y SetoidSurjection.surjective (SetoidBijection.surj (setoidInvertibleImpliesBijective inv)) {x} = SetoidInvertible.inverse inv x , SetoidInvertible.isLeft inv x inverseInvertible : {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {f : A → B} (inv1 : SetoidInvertible S T f) → SetoidInvertible T S (SetoidInvertible.inverse inv1) SetoidInvertible.fWellDefined (inverseInvertible record { fWellDefined = fWellDefined ; inverse = inverse ; inverseWellDefined = inverseWellDefined ; isLeft = isLeft ; isRight = isRight }) x=y = inverseWellDefined x=y SetoidInvertible.inverse (inverseInvertible {f = f} record { fWellDefined = fWellDefined ; inverse = inverse ; inverseWellDefined = inverseWellDefined ; isLeft = isLeft ; isRight = isRight }) = f SetoidInvertible.inverseWellDefined (inverseInvertible record { fWellDefined = fWellDefined ; inverse = inverse ; inverseWellDefined = inverseWellDefined ; isLeft = isLeft ; isRight = isRight }) = fWellDefined SetoidInvertible.isLeft (inverseInvertible record { fWellDefined = fWellDefined ; inverse = inverse ; inverseWellDefined = inverseWellDefined ; isLeft = isLeft ; isRight = isRight }) = isRight SetoidInvertible.isRight (inverseInvertible record { fWellDefined = fWellDefined ; inverse = inverse ; inverseWellDefined = inverseWellDefined ; isLeft = isLeft ; isRight = isRight }) = isLeft
{ "alphanum_fraction": 0.675181678, "avg_line_length": 68.803030303, "ext": "agda", "hexsha": "9221fe3b0b2c3b2f895897a92d39d5b1e38d5481", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Setoids/Setoids.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Setoids/Setoids.agda", "max_line_length": 340, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Setoids/Setoids.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 3506, "size": 9082 }
-- Andreas, 2012-06-30, case reported by Noam Zeilbereger module Issue670 where infix 4 _≡_ data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x data Nat : Set where zero : Nat suc : Nat → Nat {-# BUILTIN NATURAL Nat #-} {-# BUILTIN SUC suc #-} {-# BUILTIN ZERO zero #-} record T : Set where field x : Nat .eq : x ≡ x foo : T foo = record { x = 0 ; eq = refl } bar : T bar = record { x = 0 ; eq = {!refl!} } -- give should succeed
{ "alphanum_fraction": 0.5517970402, "avg_line_length": 16.8928571429, "ext": "agda", "hexsha": "70c5e9c4c99339bdb19f8174b5f983223c9f9a31", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "test/interaction/Issue670.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "test/interaction/Issue670.agda", "max_line_length": 57, "max_stars_count": 1, "max_stars_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "np/agda-git-experiment", "max_stars_repo_path": "test/interaction/Issue670.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z", "num_tokens": 172, "size": 473 }
module ConsoleLib where open import NativeIO public open import SizedIO.Console public hiding (main) renaming (translateIOConsole to run) open import Size open import SizedIO.Base open import Data.List WriteString : (s : String) → IOConsole ∞ Unit WriteString s = Exec (putStrLn s) GetLine : IOConsole ∞ String GetLine = Exec getLine ConsoleProg : Set ConsoleProg = NativeIO Unit
{ "alphanum_fraction": 0.7844155844, "avg_line_length": 22.6470588235, "ext": "agda", "hexsha": "6501cea4d42f2d646fb913083a849552cfcf2962", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z", "max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "agda/ooAgda", "max_forks_repo_path": "src/ConsoleLib.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "agda/ooAgda", "max_issues_repo_path": "src/ConsoleLib.agda", "max_line_length": 86, "max_stars_count": 23, "max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/ooAgda", "max_stars_repo_path": "src/ConsoleLib.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z", "num_tokens": 98, "size": 385 }
-- Andreas, 2014-08-30, reported by asr -- All of the following corecursive functions from Data.Stream -- should pass the termination checker. {-# OPTIONS --cubical-compatible --guardedness #-} -- {-# OPTIONS -v term:20 #-} open import Common.Coinduction open import Common.Prelude renaming (Nat to ℕ) hiding (_∷_; map) infixr 5 _∷_ data Stream (A : Set) : Set where _∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A map : ∀ {A B} → (A → B) → Stream A → Stream B map f (x ∷ xs) = f x ∷ ♯ map f (♭ xs) zipWith : ∀ {A B C} → (A → B → C) → Stream A → Stream B → Stream C zipWith _∙_ (x ∷ xs) (y ∷ ys) = (x ∙ y) ∷ ♯ zipWith _∙_ (♭ xs) (♭ ys) drop : ∀ {A} → ℕ → Stream A → Stream A drop zero xs = xs drop (suc n) (x ∷ xs) = drop n (♭ xs) repeat : ∀ {A} → A → Stream A repeat x = x ∷ ♯ repeat x iterate : ∀ {A} → (A → A) → A → Stream A iterate f x = x ∷ ♯ iterate f (f x) -- Interleaves the two streams. infixr 5 _⋎_ _⋎_ : ∀ {A} → Stream A → Stream A → Stream A (x ∷ xs) ⋎ ys = x ∷ ♯ (ys ⋎ ♭ xs) mutual -- Takes every other element from the stream, starting with the -- first one. evens : ∀ {A} → Stream A → Stream A evens (x ∷ xs) = x ∷ ♯ odds (♭ xs) -- Takes every other element from the stream, starting with the -- second one. odds : ∀ {A} → Stream A → Stream A odds (x ∷ xs) = evens (♭ xs)
{ "alphanum_fraction": 0.5687593423, "avg_line_length": 25.2452830189, "ext": "agda", "hexsha": "27285870192545e0252e0ee7213c8c05aa6a7407", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Succeed/Issue1264.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/Succeed/Issue1264.agda", "max_line_length": 69, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Succeed/Issue1264.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 510, "size": 1338 }
{-# OPTIONS --safe #-} module Definition.Conversion.Symmetry where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Properties open import Definition.Conversion open import Definition.Conversion.Stability open import Definition.Conversion.Soundness open import Definition.Conversion.Conversion open import Definition.Typed.Consequences.Syntactic open import Definition.Typed.Consequences.Equality open import Definition.Typed.Consequences.Reduction open import Definition.Typed.Consequences.Injectivity open import Definition.Typed.Consequences.Substitution open import Definition.Typed.Consequences.SucCong open import Tools.Product import Tools.PropositionalEquality as PE mutual -- Symmetry of algorithmic equality of neutrals sym~↑! : ∀ {t u A Γ Δ l} → ⊢ Γ ≡ Δ → Γ ⊢ t ~ u ↑! A ^ l → ∃ λ B → Γ ⊢ A ≡ B ^ [ ! , l ] × Δ ⊢ u ~ t ↑! B ^ l sym~↑! Γ≡Δ (var-refl x x≡y) = let ⊢A = syntacticTerm x in _ , refl ⊢A , var-refl (PE.subst (λ y → _ ⊢ var y ∷ _ ^ _) x≡y (stabilityTerm Γ≡Δ x)) (PE.sym x≡y) sym~↑! Γ≡Δ (app-cong {rF = !} t~u x) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ t~u F′ , G′ , ΠF′G′≡B = Π≡A A≡B whnfB F≡F′ , rF≡rF′ , lF≡lF' , lG≡lG' , G≡G′ = injectivity (PE.subst (λ x → _ ⊢ _ ≡ x ^ _) ΠF′G′≡B A≡B) in _ , substTypeEq G≡G′ (soundnessConv↑Term x) , app-cong (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) ΠF′G′≡B u~t) (convConvTerm (symConv↑Term Γ≡Δ x) (stabilityEq Γ≡Δ F≡F′)) sym~↑! Γ≡Δ (app-cong {rF = %} t~u x) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ t~u F′ , G′ , ΠF′G′≡B = Π≡A A≡B whnfB F≡F′ , rF≡rF′ , lF≡lF' , lG≡lG' , G≡G′ = injectivity (PE.subst (λ x → _ ⊢ _ ≡ x ^ _) ΠF′G′≡B A≡B) in _ , substTypeEq G≡G′ (proj₂ (proj₂ (soundness~↑% x))) , app-cong (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) ΠF′G′≡B u~t) (sym~↑% Γ≡Δ (conv~↑% x (stabilityEq (reflConEq ⊢Γ) F≡F′))) sym~↑! Γ≡Δ (natrec-cong x x₁ x₂ t~u) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ t~u B≡ℕ = ℕ≡A A≡B whnfB F≡G = stabilityEq (Γ≡Δ ∙ refl (univ (ℕⱼ ⊢Γ))) (soundnessConv↑ x) F[0]≡G[0] = substTypeEq F≡G (refl (zeroⱼ ⊢Δ)) in _ , substTypeEq (soundnessConv↑ x) (soundness~↓! t~u) , natrec-cong (symConv↑ (Γ≡Δ ∙ (refl (univ (ℕⱼ ⊢Γ)))) x) (convConvTerm (symConv↑Term Γ≡Δ x₁) F[0]≡G[0]) (convConvTerm (symConv↑Term Γ≡Δ x₂) (sucCong F≡G)) (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ u~t) sym~↑! Γ≡Δ (Emptyrec-cong x t~u) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ u~t = sym~↑% Γ≡Δ t~u -- F≡G = stabilityEq Γ≡Δ (soundnessConv↑ x) in _ , soundnessConv↑ x , Emptyrec-cong (symConv↑ Γ≡Δ x) u~t sym~↑! Γ≡Δ (Id-cong X x x₁) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ X U≡B = U≡A-whnf A≡B whnfB A'≡A = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B u~t in _ , refl (Ugenⱼ ⊢Γ) , Id-cong A'≡A (convConvTerm (symConv↑Term Γ≡Δ x) (univ (soundness~↓! (stability~↓! Γ≡Δ X)))) (convConvTerm (symConv↑Term Γ≡Δ x₁) (univ (soundness~↓! (stability~↓! Γ≡Δ X)))) sym~↑! Γ≡Δ (Id-ℕ X x) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ X U≡B = ℕ≡A A≡B whnfB A'≡A = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B u~t in _ , refl (Ugenⱼ ⊢Γ) , Id-ℕ A'≡A (symConv↑Term Γ≡Δ x) sym~↑! Γ≡Δ (Id-ℕ0 X) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ X U≡B = ℕ≡A A≡B whnfB A'≡A = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B u~t in _ , refl (Ugenⱼ ⊢Γ) , Id-ℕ0 A'≡A sym~↑! Γ≡Δ (Id-ℕS x X) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ X U≡B = ℕ≡A A≡B whnfB A'≡A = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B u~t in _ , refl (Ugenⱼ ⊢Γ) , Id-ℕS (symConv↑Term Γ≡Δ x) A'≡A sym~↑! Γ≡Δ (Id-U X x) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ X U≡B = U≡A-whnf A≡B whnfB A'≡A = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B u~t in _ , refl (Ugenⱼ ⊢Γ) , Id-U A'≡A (symConv↑Term Γ≡Δ x) sym~↑! Γ≡Δ (Id-Uℕ X) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ X U≡B = U≡A-whnf A≡B whnfB A'≡A = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B u~t in _ , refl (Ugenⱼ ⊢Γ) , Id-Uℕ A'≡A sym~↑! Γ≡Δ (Id-UΠ x X) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ X U≡B = U≡A-whnf A≡B whnfB A'≡A = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B u~t in _ , refl (Ugenⱼ ⊢Γ) , Id-UΠ (symConv↑Term Γ≡Δ x) A'≡A sym~↑! Γ≡Δ (cast-cong X x x₁ x₂ x₃) = let U , whnfU , U≡U' , A'~A = sym~↓! Γ≡Δ X B'~B = symConv↑Term Γ≡Δ x U≡B = U≡A-whnf U≡U' whnfU A'≡A = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B A'~A in _ , univ (soundnessConv↑Term x), cast-cong A'≡A B'~B (convConvTerm (symConv↑Term Γ≡Δ x₁) (univ (soundness~↓! (stability~↓! Γ≡Δ X)))) (stabilityTerm Γ≡Δ x₃) (stabilityTerm Γ≡Δ x₂) sym~↑! Γ≡Δ (cast-ℕ X x x₁ x₂) = let U , whnfU , U≡U' , A'~A = sym~↓! Γ≡Δ X B'~B = symConv↑Term Γ≡Δ x U≡B = U≡A-whnf U≡U' whnfU A'≡A = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B A'~A in _ , univ (soundness~↓! X) , cast-ℕ A'≡A (symConv↑Term Γ≡Δ x) (stabilityTerm Γ≡Δ x₂) (stabilityTerm Γ≡Δ x₁) sym~↑! Γ≡Δ (cast-ℕℕ X x x₁) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ N , whnfN , N≡N' , t'~t = sym~↓! Γ≡Δ X ℕ≡B = ℕ≡A N≡N' whnfN t'≡t = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) ℕ≡B t'~t in _ , refl (univ (ℕⱼ ⊢Γ)) , cast-ℕℕ t'≡t (stabilityTerm Γ≡Δ x₁) (stabilityTerm Γ≡Δ x) sym~↑! Γ≡Δ (cast-Π x X x₁ x₂ x₃) = let U , whnfU , U≡U' , A'~A = sym~↓! Γ≡Δ X B'~B = symConv↑Term Γ≡Δ x U≡B = U≡A-whnf U≡U' whnfU A'≡A = PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B A'~A in _ , univ (soundness~↓! X) , cast-Π B'~B A'≡A (convConvTerm (symConv↑Term Γ≡Δ x₁) (univ (soundnessConv↑Term (stabilityConv↑Term Γ≡Δ x)))) (stabilityTerm Γ≡Δ x₃) (stabilityTerm Γ≡Δ x₂) sym~↑! Γ≡Δ (cast-Πℕ x x₁ x₂ x₃) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ in _ , refl (univ (ℕⱼ ⊢Γ)) , cast-Πℕ (symConv↑Term Γ≡Δ x) (convConvTerm (symConv↑Term Γ≡Δ x₁) (univ (soundnessConv↑Term (stabilityConv↑Term Γ≡Δ x)))) (stabilityTerm Γ≡Δ x₃) (stabilityTerm Γ≡Δ x₂) sym~↑! Γ≡Δ (cast-ℕΠ x x₁ x₂ x₃) = _ , univ (soundnessConv↑Term x) , cast-ℕΠ (symConv↑Term Γ≡Δ x) (symConv↑Term Γ≡Δ x₁) (stabilityTerm Γ≡Δ x₃) (stabilityTerm Γ≡Δ x₂) sym~↑! Γ≡Δ (cast-ΠΠ%! x x₁ x₂ x₃ x₄) = _ , univ (soundnessConv↑Term x₁) , cast-ΠΠ%! (symConv↑Term Γ≡Δ x) (symConv↑Term Γ≡Δ x₁) (convConvTerm (symConv↑Term Γ≡Δ x₂) (univ (soundnessConv↑Term (stabilityConv↑Term Γ≡Δ x)))) (stabilityTerm Γ≡Δ x₄) (stabilityTerm Γ≡Δ x₃) sym~↑! Γ≡Δ (cast-ΠΠ!% x x₁ x₂ x₃ x₄) = _ , univ (soundnessConv↑Term x₁) , cast-ΠΠ!% (symConv↑Term Γ≡Δ x) (symConv↑Term Γ≡Δ x₁) (convConvTerm (symConv↑Term Γ≡Δ x₂) (univ (soundnessConv↑Term (stabilityConv↑Term Γ≡Δ x)))) (stabilityTerm Γ≡Δ x₄) (stabilityTerm Γ≡Δ x₃) sym~↑% : ∀ {t u A Γ Δ l} → ⊢ Γ ≡ Δ → Γ ⊢ t ~ u ↑% A ^ l → Δ ⊢ u ~ t ↑% A ^ l sym~↑% Γ≡Δ (%~↑ ⊢k ⊢l) = %~↑ (stabilityTerm Γ≡Δ ⊢l) (stabilityTerm Γ≡Δ ⊢k) sym~↑ : ∀ {t u A rA Γ Δ l} → ⊢ Γ ≡ Δ → Γ ⊢ t ~ u ↑ A ^ [ rA , l ] → ∃ λ B → Γ ⊢ A ≡ B ^ [ rA , l ] × Δ ⊢ u ~ t ↑ B ^ [ rA , l ] sym~↑ Γ≡Δ (~↑! x) = let B , A≡B , x′ = sym~↑! Γ≡Δ x in B , A≡B , ~↑! x′ sym~↑ {A = A} Γ≡Δ (~↑% x) = let x′ = sym~↑% Γ≡Δ x ⊢A , _ , _ = syntacticEqTerm (proj₂ (proj₂ (soundness~↑% x))) in A , refl ⊢A , ~↑% x′ -- Symmetry of algorithmic equality of neutrals of types in WHNF. sym~↓! : ∀ {t u A Γ Δ l} → ⊢ Γ ≡ Δ → Γ ⊢ t ~ u ↓! A ^ l → ∃ λ B → Whnf B × Γ ⊢ A ≡ B ^ [ ! , l ] × Δ ⊢ u ~ t ↓! B ^ l sym~↓! Γ≡Δ ([~] A₁ D whnfA k~l) = let B , A≡B , k~l′ = sym~↑! Γ≡Δ k~l _ , ⊢B = syntacticEq A≡B B′ , whnfB′ , D′ = whNorm ⊢B A≡B′ = trans (sym (subset* D)) (trans A≡B (subset* (red D′))) in B′ , whnfB′ , A≡B′ , [~] B (stabilityRed* Γ≡Δ (red D′)) whnfB′ k~l′ -- Symmetry of algorithmic equality of types. symConv↑ : ∀ {A B r Γ Δ} → ⊢ Γ ≡ Δ → Γ ⊢ A [conv↑] B ^ r → Δ ⊢ B [conv↑] A ^ r symConv↑ Γ≡Δ ([↑] A′ B′ D D′ whnfA′ whnfB′ A′<>B′) = [↑] B′ A′ (stabilityRed* Γ≡Δ D′) (stabilityRed* Γ≡Δ D) whnfB′ whnfA′ (symConv↓ Γ≡Δ A′<>B′) -- Symmetry of algorithmic equality of types in WHNF. symConv↓ : ∀ {A B r Γ Δ} → ⊢ Γ ≡ Δ → Γ ⊢ A [conv↓] B ^ r → Δ ⊢ B [conv↓] A ^ r symConv↓ Γ≡Δ (U-refl PE.refl x) = let _ , ⊢Δ , _ = contextConvSubst Γ≡Δ in U-refl PE.refl ⊢Δ symConv↓ Γ≡Δ (univ x) = univ (symConv↓Term Γ≡Δ x) -- Symmetry of algorithmic equality of terms. symConv↑Term : ∀ {t u A Γ Δ l} → ⊢ Γ ≡ Δ → Γ ⊢ t [conv↑] u ∷ A ^ l → Δ ⊢ u [conv↑] t ∷ A ^ l symConv↑Term Γ≡Δ ([↑]ₜ B t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u) = [↑]ₜ B u′ t′ (stabilityRed* Γ≡Δ D) (stabilityRed*Term Γ≡Δ d′) (stabilityRed*Term Γ≡Δ d) whnfB whnfu′ whnft′ (symConv↓Term Γ≡Δ t<>u) -- Symmetry of algorithmic equality of terms in WHNF. symConv↓Term : ∀ {t u A Γ Δ l} → ⊢ Γ ≡ Δ → Γ ⊢ t [conv↓] u ∷ A ^ l → Δ ⊢ u [conv↓] t ∷ A ^ l symConv↓Term Γ≡Δ (U-refl x x₁) = let _ , ⊢Δ , _ = contextConvSubst Γ≡Δ in U-refl (PE.sym x) ⊢Δ symConv↓Term Γ≡Δ (ne t~u) = let ⊢Γ , ⊢Δ , _ = contextConvSubst Γ≡Δ B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ t~u U≡B = U≡A-whnf A≡B whnfB in ne (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) U≡B (proj₂ (proj₂ (proj₂ (sym~↓! Γ≡Δ t~u))))) symConv↓Term Γ≡Δ (ℕ-refl x) = let _ , ⊢Δ , _ = contextConvSubst Γ≡Δ in ℕ-refl ⊢Δ symConv↓Term Γ≡Δ (Empty-refl x _) = let _ , ⊢Δ , _ = contextConvSubst Γ≡Δ in Empty-refl x ⊢Δ symConv↓Term Γ≡Δ (∃-cong PE.refl x A<>B A<>B₁) = let F≡H = soundnessConv↑Term A<>B _ , ⊢H = syntacticEq (stabilityEq Γ≡Δ (univ F≡H)) in ∃-cong PE.refl ⊢H (symConv↑Term Γ≡Δ A<>B) (symConv↑Term (Γ≡Δ ∙ univ F≡H) A<>B₁) symConv↓Term Γ≡Δ (Π-cong PE.refl PE.refl PE.refl PE.refl l< l<' x A<>B A<>B₁) = let F≡H = soundnessConv↑Term A<>B _ , ⊢H = syntacticEq (stabilityEq Γ≡Δ (univ F≡H)) in Π-cong PE.refl PE.refl PE.refl PE.refl l< l<' ⊢H (symConv↑Term Γ≡Δ A<>B) (symConv↑Term (Γ≡Δ ∙ univ F≡H) A<>B₁) symConv↓Term Γ≡Δ (ℕ-ins t~u) = let B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ t~u B≡ℕ = ℕ≡A A≡B whnfB in ℕ-ins (PE.subst (λ x → _ ⊢ _ ~ _ ↓! x ^ _) B≡ℕ u~t) symConv↓Term Γ≡Δ (ne-ins t u x t~u) = let B , whnfB , A≡B , u~t = sym~↓! Γ≡Δ t~u in ne-ins (stabilityTerm Γ≡Δ u) (stabilityTerm Γ≡Δ t) x u~t symConv↓Term Γ≡Δ (zero-refl x) = let _ , ⊢Δ , _ = contextConvSubst Γ≡Δ in zero-refl ⊢Δ symConv↓Term Γ≡Δ (suc-cong t<>u) = suc-cong (symConv↑Term Γ≡Δ t<>u) symConv↓Term Γ≡Δ (η-eq l< l<' x x₁ x₂ y y₁ t<>u) = η-eq l< l<' (stability Γ≡Δ x) (stabilityTerm Γ≡Δ x₂) (stabilityTerm Γ≡Δ x₁) y₁ y (symConv↑Term (Γ≡Δ ∙ refl x) t<>u) -- Symmetry of algorithmic equality of types with preserved context. symConv : ∀ {A B r Γ} → Γ ⊢ A [conv↑] B ^ r → Γ ⊢ B [conv↑] A ^ r symConv A<>B = let ⊢Γ = wfEq (soundnessConv↑ A<>B) in symConv↑ (reflConEq ⊢Γ) A<>B -- Symmetry of algorithmic equality of terms with preserved context. symConvTerm : ∀ {t u A Γ l} → Γ ⊢ t [conv↑] u ∷ A ^ l → Γ ⊢ u [conv↑] t ∷ A ^ l symConvTerm t<>u = let ⊢Γ = wfEqTerm (soundnessConv↑Term t<>u) in symConv↑Term (reflConEq ⊢Γ) t<>u
{ "alphanum_fraction": 0.493205757, "avg_line_length": 49.3531746032, "ext": "agda", "hexsha": "1f38c3ef64f39da6ac72247f3aed4b419ed94ca1", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z", "max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z", "max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CoqHott/logrel-mltt", "max_forks_repo_path": "Definition/Conversion/Symmetry.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "CoqHott/logrel-mltt", "max_issues_repo_path": "Definition/Conversion/Symmetry.agda", "max_line_length": 142, "max_stars_count": 2, "max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CoqHott/logrel-mltt", "max_stars_repo_path": "Definition/Conversion/Symmetry.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z", "max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z", "num_tokens": 6045, "size": 12437 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Functions.Definition open import Functions.Lemmas open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Numbers.Naturals.Order.Lemmas open import Sets.Cardinality.Finite.Definition open import Semirings.Definition open import Sets.CantorBijection.CantorBijection open import Orders.Total.Definition module Sets.Cardinality where open import Semirings.Lemmas ℕSemiring record CountablyInfiniteSet {a : _} (A : Set a) : Set a where field counting : A → ℕ countingIsBij : Bijection counting data Countable {a : _} (A : Set a) : Set a where finite : FiniteSet A → Countable A infinite : CountablyInfiniteSet A → Countable A ℕCountable : CountablyInfiniteSet ℕ ℕCountable = record { counting = id ; countingIsBij = invertibleImpliesBijection (record { inverse = id ; isLeft = λ b → refl ; isRight = λ a → refl}) } doubleLemma : (a b : ℕ) → 2 *N a ≡ 2 *N b → a ≡ b doubleLemma a b pr = productCancelsLeft 2 a b (le 1 refl) pr evenCannotBeOdd : (a b : ℕ) → 2 *N a ≡ succ (2 *N b) → False evenCannotBeOdd zero b () evenCannotBeOdd (succ a) zero pr rewrite Semiring.commutative ℕSemiring a 0 | Semiring.commutative ℕSemiring a (succ a) = naughtE (equalityCommutative (succInjective pr)) evenCannotBeOdd (succ a) (succ b) pr = evenCannotBeOdd a b pr'' where pr' : a +N a ≡ (b +N succ b) pr' rewrite Semiring.commutative ℕSemiring a 0 | Semiring.commutative ℕSemiring b 0 | Semiring.commutative ℕSemiring a (succ a) = succInjective (succInjective pr) pr'' : 2 *N a ≡ succ (2 *N b) pr'' rewrite Semiring.commutative ℕSemiring a 0 | Semiring.commutative ℕSemiring b 0 | Semiring.commutative ℕSemiring (succ b) b = pr' aMod2 : (a : ℕ) → Sg ℕ (λ i → (2 *N i ≡ a) || (succ (2 *N i) ≡ a)) aMod2 zero = (0 , inl refl) aMod2 (succ a) with aMod2 a aMod2 (succ a) | b , inl x = b , inr (applyEquality succ x) aMod2 (succ a) | b , inr x = (succ b) , inl pr where pr : succ (b +N succ (b +N 0)) ≡ succ a pr rewrite Semiring.commutative ℕSemiring b (succ (b +N 0)) | Semiring.commutative ℕSemiring (b +N 0) b = applyEquality succ x sqrtFloor : (a : ℕ) → Sg (ℕ && ℕ) (λ pair → ((_&&_.fst pair) *N (_&&_.fst pair) +N (_&&_.snd pair) ≡ a) && ((_&&_.snd pair) <N 2 *N (_&&_.fst pair) +N 1)) sqrtFloor zero = (0 ,, 0) , (refl ,, le zero refl) sqrtFloor (succ n) with sqrtFloor n sqrtFloor (succ n) | (a ,, b) , pr with TotalOrder.totality ℕTotalOrder b (2 *N a) sqrtFloor (succ n) | (a ,, b) , pr | inl (inl x) = (a ,, succ b) , (p ,, q) where p : a *N a +N succ b ≡ succ n p rewrite Semiring.commutative ℕSemiring (a *N a) (succ b) | Semiring.commutative ℕSemiring b (a *N a) = applyEquality succ (_&&_.fst pr) q : succ b <N (a +N (a +N 0)) +N 1 q rewrite Semiring.commutative ℕSemiring (a +N (a +N 0)) (succ 0) | Semiring.commutative ℕSemiring a 0 = succPreservesInequality x sqrtFloor (succ n) | (a ,, b) , (_ ,, pr) | inl (inr x) rewrite Semiring.commutative ℕSemiring (a +N (a +N 0)) (succ 0) = exFalso (noIntegersBetweenXAndSuccX (a +N (a +N 0)) x pr) sqrtFloor (succ n) | (a ,, b) , pr | inr x = (succ a ,, 0) , (q ,, succIsPositive _) where p : a +N a *N succ a ≡ n p rewrite x | Semiring.commutative ℕSemiring a 0 | Semiring.commutative ℕSemiring (a +N a) (succ 0) | Semiring.commutative ℕSemiring (a *N a) (succ a +N a) | multiplicationNIsCommutative a (succ a) | Semiring.commutative ℕSemiring (a *N a) (a +N a) | Semiring.+Associative ℕSemiring a a (a *N a) = _&&_.fst pr q : succ ((a +N a *N succ a) +N 0) ≡ succ n q rewrite Semiring.commutative ℕSemiring (a +N a *N succ a) 0 = applyEquality succ p pairUnionIsCountable : {a b : _} {A : Set a} {B : Set b} → (X : CountablyInfiniteSet A) → (Y : CountablyInfiniteSet B) → CountablyInfiniteSet (A || B) CountablyInfiniteSet.counting (pairUnionIsCountable X Y) (inl r) = 2 *N (CountablyInfiniteSet.counting X r) CountablyInfiniteSet.counting (pairUnionIsCountable X Y) (inr s) = succ (2 *N (CountablyInfiniteSet.counting Y s)) Bijection.inj (CountablyInfiniteSet.countingIsBij (pairUnionIsCountable X Y)) {inl x} {inl y} pr rewrite Semiring.commutative ℕSemiring (CountablyInfiniteSet.counting X x) 0 | Semiring.commutative ℕSemiring (CountablyInfiniteSet.counting X y) 0 | doubleIsAddTwo (CountablyInfiniteSet.counting X x) | doubleIsAddTwo (CountablyInfiniteSet.counting X y) = applyEquality inl (Bijection.inj (CountablyInfiniteSet.countingIsBij X) inter) where inter : CountablyInfiniteSet.counting X x ≡ CountablyInfiniteSet.counting X y inter = doubleLemma (CountablyInfiniteSet.counting X x) (CountablyInfiniteSet.counting X y) pr Bijection.inj (CountablyInfiniteSet.countingIsBij (pairUnionIsCountable X Y)) {inl x} {inr y} pr = exFalso (evenCannotBeOdd (CountablyInfiniteSet.counting X x) (CountablyInfiniteSet.counting Y y) pr) Bijection.inj (CountablyInfiniteSet.countingIsBij (pairUnionIsCountable X Y)) {inr x} {inl y} pr = exFalso (evenCannotBeOdd (CountablyInfiniteSet.counting X y) (CountablyInfiniteSet.counting Y x) (equalityCommutative pr)) Bijection.inj (CountablyInfiniteSet.countingIsBij (pairUnionIsCountable X Y)) {inr x} {inr y} pr = applyEquality inr (Bijection.inj (CountablyInfiniteSet.countingIsBij Y) (doubleLemma (CountablyInfiniteSet.counting Y x) (CountablyInfiniteSet.counting Y y) (succInjective pr) )) Bijection.surj (CountablyInfiniteSet.countingIsBij (pairUnionIsCountable X Y)) b with aMod2 b Bijection.surj (CountablyInfiniteSet.countingIsBij (pairUnionIsCountable X Y)) b | a , inl x with Bijection.surj (CountablyInfiniteSet.countingIsBij X) a Bijection.surj (CountablyInfiniteSet.countingIsBij (pairUnionIsCountable X Y)) b | a , inl x | r , pr = inl r , ans where ans : 2 *N CountablyInfiniteSet.counting X r ≡ b ans rewrite pr = x Bijection.surj (CountablyInfiniteSet.countingIsBij (pairUnionIsCountable X Y)) b | a , inr x with Bijection.surj (CountablyInfiniteSet.countingIsBij Y) a Bijection.surj (CountablyInfiniteSet.countingIsBij (pairUnionIsCountable X Y)) b | a , inr x | r , pr = inr r , ans where ans : succ (2 *N CountablyInfiniteSet.counting Y r) ≡ b ans rewrite pr = x firstEqualityOfPair : {a b : _} {A : Set a} {B : Set b} → {x1 x2 : A} → {y1 y2 : B} → (x1 ,, y1) ≡ (x2 ,, y2) → x1 ≡ x2 firstEqualityOfPair {x1} {x2} {y1} {y2} refl = refl secondEqualityOfPair : {a b : _} {A : Set a} {B : Set b} → {x1 x2 : A} → {y1 y2 : B} → (x1 ,, y1) ≡ (x2 ,, y2) → y1 ≡ y2 secondEqualityOfPair {x1} {x2} {y1} {y2} refl = refl reflPair : {a b : _} {A : Set a} {B : Set b} {x1 x2 : A} {y1 y2 : B} → (x1 ≡ x2) → (y1 ≡ y2) → (x1 ,, y1) ≡ x2 ,, y2 reflPair refl refl = refl bijectionOfCountableSetIsCountable : {a b : _} {A : Set a} {B : Set b} → (X : CountablyInfiniteSet A) {f : A → B} → (bij : Bijection f) → CountablyInfiniteSet B CountablyInfiniteSet.counting (bijectionOfCountableSetIsCountable X {f} record { inj = inj ; surj = surj }) b with surj b CountablyInfiniteSet.counting (bijectionOfCountableSetIsCountable record { counting = counting ; countingIsBij = countingIsBij } {f} record { inj = inj ; surj = surj }) b | a , pr = counting a Bijection.inj (CountablyInfiniteSet.countingIsBij (bijectionOfCountableSetIsCountable X {f} record { inj = inj ; surj = surj })) {m} {n} m=n with surj m Bijection.inj (CountablyInfiniteSet.countingIsBij (bijectionOfCountableSetIsCountable X {f} record { inj = inj ; surj = surj })) {m} {n} m=n | a , b with surj n ... | c , d = transitivity (equalityCommutative b) (transitivity (applyEquality f (Bijection.inj (CountablyInfiniteSet.countingIsBij X) m=n)) d) Bijection.surj (CountablyInfiniteSet.countingIsBij (bijectionOfCountableSetIsCountable X {f} record { inj = inj ; surj = surj })) b with Bijection.surj (CountablyInfiniteSet.countingIsBij X) b Bijection.surj (CountablyInfiniteSet.countingIsBij (bijectionOfCountableSetIsCountable X {f} record { inj = inj ; surj = surj })) b | a , pr = f a , s where s : CountablyInfiniteSet.counting (bijectionOfCountableSetIsCountable X {f} record { inj = inj ; surj = surj }) (f a) ≡ b s with surj (f a) s | t , u = transitivity (applyEquality (CountablyInfiniteSet.counting X) (inj u)) pr N^2Countable : CountablyInfiniteSet (ℕ && ℕ) CountablyInfiniteSet.counting N^2Countable x = Invertible.inverse (bijectionImpliesInvertible (cantorBijection)) x CountablyInfiniteSet.countingIsBij N^2Countable = invertibleImpliesBijection (inverseIsInvertible (bijectionImpliesInvertible cantorBijection)) tupleRmap : {a b c : _} {A : Set a} {B : Set b} {C : Set c} → (f : B → C) → (A && B) → (A && C) tupleRmap f (a ,, b) = (a ,, f b) tupleLmap : {a b c : _} {A : Set a} {B : Set b} {C : Set c} → (f : A → C) → (A && B) → (C && B) tupleLmap f (a ,, b) = (f a ,, b) bijectionOnRightOfProduct : {a b c : _} {A : Set a} {B : Set b} {C : Set c} → {f : B → C} → Bijection f → Bijection (tupleRmap {A = A} f) Bijection.inj (bijectionOnRightOfProduct {A = A} {B} {C} {f} bij) {fst ,, snd} {fst₁ ,, snd₁} gx=gy rewrite firstEqualityOfPair gx=gy | Bijection.inj bij (secondEqualityOfPair gx=gy) = refl Bijection.surj (bijectionOnRightOfProduct {A = A} {B} {C} {f} bij) (fst ,, snd) with Bijection.surj bij snd Bijection.surj (bijectionOnRightOfProduct {A = A} {B} {C} {f} bij) (fst ,, snd) | b , pr = (fst ,, b) , reflPair refl pr bijectionOnLeftOfProduct : {a b c : _} {A : Set a} {B : Set b} {C : Set c} → {f : A → C} → Bijection f → Bijection (tupleLmap {B = B} f) Bijection.inj (bijectionOnLeftOfProduct {A = A} {B} {C} {f} bij) {a ,, b} {c ,, d} gx=gy rewrite secondEqualityOfPair gx=gy | Bijection.inj bij (firstEqualityOfPair gx=gy) = refl Bijection.surj (bijectionOnLeftOfProduct {A = A} {B} {C} {f} bij) (fst ,, snd) with Bijection.surj bij fst Bijection.surj (bijectionOnLeftOfProduct {A = A} {B} {C} {f} bij) (fst ,, snd) | a , b = (a ,, snd) , reflPair b refl pairProductIsCountable : {a b : _} {A : Set a} {B : Set b} → (X : CountablyInfiniteSet A) → (Y : CountablyInfiniteSet B) → CountablyInfiniteSet (A && B) pairProductIsCountable {A = A} {B = B} X Y = bijectionOfCountableSetIsCountable N^2Countable {(tupleLmap m) ∘ (tupleRmap n)} bijF where bijM = (bijectionImpliesInvertible (CountablyInfiniteSet.countingIsBij X)) bijN = (bijectionImpliesInvertible (CountablyInfiniteSet.countingIsBij Y)) m : ℕ → A m = Invertible.inverse bijM n : ℕ → B n = Invertible.inverse bijN bM : Bijection m bM = invertibleImpliesBijection (record { inverse = CountablyInfiniteSet.counting X ; isLeft = Invertible.isRight bijM ; isRight = Invertible.isLeft bijM }) bN : Bijection n bN = invertibleImpliesBijection (record { inverse = CountablyInfiniteSet.counting Y ; isLeft = Invertible.isRight bijN ; isRight = Invertible.isLeft bijN }) bijF : Bijection ((tupleLmap {A = ℕ} {B = B} {C = A} m) ∘ (tupleRmap {A = ℕ} {B = ℕ} {C = B} n)) bijF = bijectionComp {f = tupleRmap {A = ℕ} {B = ℕ} {C = B} n} {g = tupleLmap {A = ℕ} {B = B} {C = A} m} (bijectionOnRightOfProduct (invertibleImpliesBijection (bijectionImpliesInvertible bN))) (bijectionOnLeftOfProduct bM) -- injectionToNMeansCountable : {a : _} {A : Set a} {f : A → ℕ} → Injection f → InfiniteSet A → Countable A -- injectionToNMeansCountable {f = f} inj record { isInfinite = isInfinite } = {!!}
{ "alphanum_fraction": 0.6929467916, "avg_line_length": 74.4342105263, "ext": "agda", "hexsha": "7c6703eb05b72d084621162e489c1fb02f607abd", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Sets/Cardinality.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Sets/Cardinality.agda", "max_line_length": 431, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Sets/Cardinality.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 4137, "size": 11314 }
{-# OPTIONS --safe #-} module Cubical.Algebra.Ring.DirectProd where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.HLevels open import Cubical.Data.Sigma open import Cubical.Algebra.Ring.Base private variable ℓ ℓ' ℓ'' ℓ''' : Level module _ (A'@(A , Ar) : Ring ℓ) (B'@(B , Br) : Ring ℓ') where open RingStr Ar using () renaming ( 0r to 0A ; 1r to 1A ; _+_ to _+A_ ; -_ to -A_ ; _·_ to _·A_ ; +Assoc to +AAssoc ; +Identity to +AIdentity ; +Lid to +ALid ; +Rid to +ARid ; +Inv to +AInv ; +Linv to +ALinv ; +Rinv to +ARinv ; +Comm to +AComm ; ·Assoc to ·AAssoc ; ·Identity to ·AIdentity ; ·Lid to ·ALid ; ·Rid to ·ARid ; ·Rdist+ to ·ARdist+ ; ·Ldist+ to ·ALdist+ ; is-set to isSetA ) open RingStr Br using () renaming ( 0r to 0B ; 1r to 1B ; _+_ to _+B_ ; -_ to -B_ ; _·_ to _·B_ ; +Assoc to +BAssoc ; +Identity to +BIdentity ; +Lid to +BLid ; +Rid to +BRid ; +Inv to +BInv ; +Linv to +BLinv ; +Rinv to +BRinv ; +Comm to +BComm ; ·Assoc to ·BAssoc ; ·Identity to ·BIdentity ; ·Lid to ·BLid ; ·Rid to ·BRid ; ·Rdist+ to ·BRdist+ ; ·Ldist+ to ·BLdist+ ; is-set to isSetB ) DirectProd-Ring : Ring (ℓ-max ℓ ℓ') fst DirectProd-Ring = A × B RingStr.0r (snd DirectProd-Ring) = 0A , 0B RingStr.1r (snd DirectProd-Ring) = 1A , 1B (snd DirectProd-Ring RingStr.+ (a , b)) (a' , b') = (a +A a') , (b +B b') (snd DirectProd-Ring RingStr.· (a , b)) (a' , b') = (a ·A a') , (b ·B b') (RingStr.- snd DirectProd-Ring) (a , b) = (-A a) , (-B b) RingStr.isRing (snd DirectProd-Ring) = makeIsRing (isSet× isSetA isSetB) (λ x y z i → +AAssoc (fst x) (fst y) (fst z) i , +BAssoc (snd x) (snd y) (snd z) i) (λ x i → (+ARid (fst x) i) , (+BRid (snd x) i)) (λ x i → (+ARinv (fst x) i) , +BRinv (snd x) i) (λ x y i → (+AComm (fst x) (fst y) i) , (+BComm (snd x) (snd y) i)) (λ x y z i → (·AAssoc (fst x) (fst y) (fst z) i) , (·BAssoc (snd x) (snd y) (snd z) i)) (λ x i → (·ARid (fst x) i) , (·BRid (snd x) i)) (λ x i → (·ALid (fst x) i) , (·BLid (snd x) i)) (λ x y z i → (·ARdist+ (fst x) (fst y) (fst z) i) , (·BRdist+ (snd x) (snd y) (snd z) i)) (λ x y z i → (·ALdist+ (fst x) (fst y) (fst z) i) , (·BLdist+ (snd x) (snd y) (snd z) i)) module Coproduct-Equiv {Xr@(X , Xstr) : Ring ℓ} {Yr@(Y , Ystr) : Ring ℓ'} {X'r@(X' , X'str) : Ring ℓ''} {Y'r@(Y' , Y'str) : Ring ℓ'''} where open Iso open IsRingHom open RingStr _+X×X'_ : X × X' → X × X' → X × X' _+X×X'_ = _+_ (snd (DirectProd-Ring Xr X'r)) _+Y×Y'_ : Y × Y' → Y × Y' → Y × Y' _+Y×Y'_ = _+_ (snd (DirectProd-Ring Yr Y'r)) _·X×X'_ : X × X' → X × X' → X × X' _·X×X'_ = _·_ (snd (DirectProd-Ring Xr X'r)) _·Y×Y'_ : Y × Y' → Y × Y' → Y × Y' _·Y×Y'_ = _·_ (snd (DirectProd-Ring Yr Y'r)) re×re' : (re : RingEquiv Xr Yr) → (re' : RingEquiv X'r Y'r) → (X × X') ≃ (Y × Y') re×re' re re' = ≃-× (fst re) (fst re') Coproduct-Equiv-12 : (re : RingEquiv Xr Yr) → (re' : RingEquiv X'r Y'r) → RingEquiv (DirectProd-Ring Xr X'r) (DirectProd-Ring Yr Y'r) fst (Coproduct-Equiv-12 re re') = re×re' re re' snd (Coproduct-Equiv-12 re re') = makeIsRingHom fun-pres1 fun-pres+ fun-pres· where fun-pres1 : (fst (re×re' re re')) (1r Xstr , 1r X'str) ≡ (1r (Yr .snd) , 1r (Y'r .snd)) fun-pres1 = ≡-× (pres1 (snd re)) (pres1 (snd re')) fun-pres+ : (x1 x2 : X × X') → (fst (re×re' re re')) (x1 +X×X' x2) ≡ (( (fst (re×re' re re')) x1) +Y×Y' ( (fst (re×re' re re')) x2)) fun-pres+ (x1 , x'1) (x2 , x'2) = ≡-× (pres+ (snd re) x1 x2) (pres+ (snd re') x'1 x'2) fun-pres· : (x1 x2 : X × X') → (fst (re×re' re re')) (x1 ·X×X' x2) ≡ (( (fst (re×re' re re')) x1) ·Y×Y' ( (fst (re×re' re re')) x2)) fun-pres· (x1 , x'1) (x2 , x'2) = ≡-× (pres· (snd re) x1 x2) (pres· (snd re') x'1 x'2)
{ "alphanum_fraction": 0.4977397097, "avg_line_length": 33.8951612903, "ext": "agda", "hexsha": "974d9688cbb3edefc8bde9dbbb5f9f51955bb3d1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "guilhermehas/cubical", "max_forks_repo_path": "Cubical/Algebra/Ring/DirectProd.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "guilhermehas/cubical", "max_issues_repo_path": "Cubical/Algebra/Ring/DirectProd.agda", "max_line_length": 136, "max_stars_count": 1, "max_stars_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "guilhermehas/cubical", "max_stars_repo_path": "Cubical/Algebra/Ring/DirectProd.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "num_tokens": 1847, "size": 4203 }
{-# OPTIONS --safe --warning=error --without-K #-} open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import LogicalFormulae open import Sets.EquivalenceRelations open import Setoids.Setoids module Setoids.Union.Definition {a b : _} {A : Set a} (S : Setoid {a} {b} A) where open Setoid S open Equivalence eq open import Setoids.Subset S unionPredicate : {c d : _} {pred1 : A → Set c} {pred2 : A → Set d} (s1 : subset pred1) (s2 : subset pred2) → A → Set (c ⊔ d) unionPredicate {pred1 = pred1} {pred2} s1 s2 a = pred1 a || pred2 a union : {c d : _} {pred1 : A → Set c} {pred2 : A → Set d} (s1 : subset pred1) (s2 : subset pred2) → subset (unionPredicate s1 s2) union s1 s2 {x1} {x2} x1=x2 (inl x) = inl (s1 x1=x2 x) union s1 s2 {x1} {x2} x1=x2 (inr x) = inr (s2 x1=x2 x)
{ "alphanum_fraction": 0.654822335, "avg_line_length": 39.4, "ext": "agda", "hexsha": "bdfb31d179eeb276d00fe4a8a04919a479ba32bc", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Setoids/Union/Definition.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Setoids/Union/Definition.agda", "max_line_length": 129, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Setoids/Union/Definition.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 306, "size": 788 }
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Everything where import Cubical.HITs.Cylinder import Cubical.HITs.Hopf import Cubical.HITs.Interval import Cubical.HITs.Ints.BiInvInt import Cubical.HITs.Ints.DeltaInt import Cubical.HITs.Ints.HAEquivInt import Cubical.HITs.Ints.IsoInt import Cubical.HITs.Ints.QuoInt import Cubical.HITs.Join import Cubical.HITs.ListedFiniteSet import Cubical.HITs.Pushout import Cubical.HITs.Modulo import Cubical.HITs.S1 import Cubical.HITs.S2 import Cubical.HITs.S3 import Cubical.HITs.Rational import Cubical.HITs.Susp import Cubical.HITs.SmashProduct import Cubical.HITs.Torus import Cubical.HITs.PropositionalTruncation import Cubical.HITs.SetTruncation import Cubical.HITs.GroupoidTruncation import Cubical.HITs.2GroupoidTruncation import Cubical.HITs.SetQuotients import Cubical.HITs.FiniteMultiset import Cubical.HITs.Sn import Cubical.HITs.RPn import Cubical.HITs.Truncation import Cubical.HITs.Colimit import Cubical.HITs.MappingCones import Cubical.HITs.InfNat import Cubical.HITs.KleinBottle import Cubical.HITs.DunceCap import Cubical.HITs.Localization import Cubical.HITs.Nullification import Cubical.HITs.AssocList
{ "alphanum_fraction": 0.8545765612, "avg_line_length": 29.225, "ext": "agda", "hexsha": "90557e9a2019f7724fdbc07f7d747261794ba1fd", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "borsiemir/cubical", "max_forks_repo_path": "Cubical/HITs/Everything.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "borsiemir/cubical", "max_issues_repo_path": "Cubical/HITs/Everything.agda", "max_line_length": 43, "max_stars_count": null, "max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "borsiemir/cubical", "max_stars_repo_path": "Cubical/HITs/Everything.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 386, "size": 1169 }
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.Common.FOL.Existential.RequiredWitness where -- We need to use the existential witness in some proofs based on the -- non-empty domain hypothesis. ------------------------------------------------------------------------------ postulate D : Set D≢∅ : D -- Non-empty domain. -- The existential quantifier type on D. data ∃ (P : D → Set) : Set where ∃-intro : ∀ {x} → P x → ∃ P -- Theorem: Let A be a formula. If x is not free in A then ⊢ (∃x)A ↔ A -- (Mendelson, 1997, proposition 2.18 (b), p. 70). -- A version of the right-to-left implication. l→r : {A : Set} → A → ∃ (λ _ → A) l→r a = ∃-intro {x = D≢∅} a ------------------------------------------------------------------------------ -- References -- -- Mendelson, Elliott (1997). Introduction to Mathematical Logic. 4th -- ed. Chapman & Hall.
{ "alphanum_fraction": 0.5025125628, "avg_line_length": 30.1515151515, "ext": "agda", "hexsha": "54ae861a8622adf2ae6cee6c2aa08557b2bec7cb", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "notes/FOT/Common/FOL/Existential/RequiredWitness.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "notes/FOT/Common/FOL/Existential/RequiredWitness.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "notes/FOT/Common/FOL/Existential/RequiredWitness.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 264, "size": 995 }