Search is not available for this dataset
text
string
meta
dict
-- Andreas, 2018-03-12 -- The fix for #2963 introduced a change in the quotation behavior -- of method definitions inside a record. open import Agda.Builtin.Float open import Agda.Builtin.Reflection open import Agda.Builtin.List open import Agda.Builtin.Unit open import Agda.Builtin.Equality open import Agda.Builtin.Sigma infixl 6 _>>=_ _>>=_ = bindTC macro getDef : Name → Term → TC ⊤ getDef x a = getDefinition x >>= quoteTC >>= unify a record Foo (A : Set) : Set where constructor mkFoo field foo : A foo₁ : A foo₁ = foo open module FooI = Foo {{...}} postulate A : Set instance FooA : Foo A -- Projection-like foo₂ : {A : Set} {r : Foo A} → A foo₂ {r = mkFoo x} = x bar : A bar = foo bar₁ : A bar₁ = foo₁ bar₂ : A bar₂ = foo₂ {r = FooA} pattern rArg v x = arg (arg-info v relevant) x pattern vArg x = rArg visible x pattern hArg x = rArg hidden x pattern iArg x = rArg instance′ x pattern `? = hArg unknown pattern fun₀ b = function (clause [] [] b ∷ []) pattern fun₁ tel p b = function (clause tel (p ∷ []) b ∷ []) pattern fun₂ tel p q b = function (clause tel (p ∷ q ∷ []) b ∷ []) -- foo {{r}} = Foo.foo {_} r foo-def : getDef foo ≡ fun₁ (("r" , iArg (def (quote Foo) (vArg (var 0 []) ∷ []))) ∷ []) (iArg (var 0)) (def (quote Foo.foo) (`? ∷ vArg (var 0 []) ∷ [])) foo-def = refl -- Andreas, 2018-03-12: Behavior before fix of #2963: -- foo₁ {{r}} = Foo.foo₁ {_} r -- foo₁-def : getDef foo₁ ≡ fun₁ (iArg (var "r")) (def (quote Foo.foo₁) (`? ∷ vArg (var 0 []) ∷ [])) -- NOW: -- foo₁ {A} {{r}} = Foo.foo₁ {A} r foo₁-def : getDef foo₁ ≡ fun₂ (("A" , hArg (agda-sort (lit 0))) ∷ ("r" , iArg (def (quote Foo) (vArg (var 0 []) ∷ []))) ∷ []) (hArg (var 1)) (iArg (var 0)) (def (quote Foo.foo₁) (hArg (var 1 []) ∷ vArg (var 0 []) ∷ [])) foo₁-def = refl -- bar = foo {_} FooA bar-def : getDef bar ≡ fun₀ (def (quote Foo.foo) (`? ∷ vArg (def (quote FooA) []) ∷ [])) bar-def = refl -- bar₁ = Foo.foo₁ {A} FooA bar₁-def : getDef bar₁ ≡ fun₀ (def (quote Foo.foo₁) (hArg (def (quote A) []) ∷ vArg (def (quote FooA) []) ∷ [])) bar₁-def = refl -- bar₂ = foo₂ {_} {FooA} bar₂-def : getDef bar₂ ≡ fun₀ (def (quote foo₂) (`? ∷ hArg (def (quote FooA) []) ∷ [])) bar₂-def = refl --- Originally reported test case --- defToTerm : Name → Definition → List (Arg Term) → Term defToTerm _ (function cs) as = pat-lam cs as defToTerm _ (data-cons d) as = con d as defToTerm _ _ _ = unknown derefImmediate : Term → TC Term derefImmediate (def f args) = getDefinition f >>= λ f' → returnTC (defToTerm f f' args) derefImmediate x = returnTC x reflectTerm : Name → TC Term reflectTerm n = getType n >>= λ ty → getDefinition n >>= λ x → derefImmediate (defToTerm n x []) >>= λ x → checkType x ty macro reflect : Name → Term → TC ⊤ reflect n a = reflectTerm n >>= quoteTC >>= unify a {- Define typeclass Semigroup a => Plus a -} record SemigroupLaws {ℓ} (t : Set ℓ) : Set ℓ where infixr 5 _++_ field _++_ : t → t → t -- associative : ∀ {a b c} → (a ++ b) ++ c ≡ a ++ b ++ c record PlusOp {ℓ} (t : Set ℓ) : Set ℓ where field semigroup : SemigroupLaws t infixr 6 _+_ _+_ = SemigroupLaws._++_ semigroup instance floatPlus : PlusOp Float floatPlus = record { semigroup = record { _++_ = Agda.Builtin.Float.primFloatPlus } } open PlusOp {{...}} -- The issue: works : Float works = PlusOp._+_ floatPlus 3.0 5.0 resultWorks : Term resultWorks = reflect works fails : Float fails = 3.0 + 5.0 resultFails : Term resultFails = reflect fails
{ "alphanum_fraction": 0.6008943544, "avg_line_length": 26.1167883212, "ext": "agda", "hexsha": "07ed605a6eec7eeda56f932aed0fa449250982c5", "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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "shlevy/agda", "max_forks_repo_path": "test/Succeed/Issue2226.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "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": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue2226.agda", "max_line_length": 113, "max_stars_count": null, "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/Issue2226.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1266, "size": 3578 }
module Issue586 where {-# NO_TERMINATION_CHECK #-} Foo : Set Foo = Foo
{ "alphanum_fraction": 0.7083333333, "avg_line_length": 12, "ext": "agda", "hexsha": "77a7ab1c16467c144b1562bdbdca1f0ca320b484", "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/Issue586.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/Issue586.agda", "max_line_length": 28, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/Issue586.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": 19, "size": 72 }
{-# OPTIONS --without-K --safe #-} module Categories.NaturalTransformation.Dinatural where open import Level open import Data.Product open import Relation.Binary using (Rel; IsEquivalence; Setoid) open import Categories.Category open import Categories.NaturalTransformation as NT hiding (_∘ʳ_) open import Categories.Functor open import Categories.Functor.Construction.Constant open import Categories.Functor.Bifunctor open import Categories.Category.Product import Categories.Morphism.Reasoning as MR private variable o ℓ e : Level C D E : Category o ℓ e record DinaturalTransformation (F G : Bifunctor (Category.op C) C D) : Set (levelOfTerm F) where eta-equality private module C = Category C module D = Category D module F = Functor F module G = Functor G open D hiding (op) open Commutation field α : ∀ X → D [ F.F₀ (X , X) , G.F₀ (X , X) ] commute : ∀ {X Y} (f : C [ X , Y ]) → [ F.F₀ (Y , X) ⇒ G.F₀ (X , Y) ]⟨ F.F₁ (f , C.id) ⇒⟨ F.F₀ (X , X) ⟩ α X ⇒⟨ G.F₀ (X , X) ⟩ G.F₁ (C.id , f) ≈ F.F₁ (C.id , f) ⇒⟨ F.F₀ (Y , Y) ⟩ α Y ⇒⟨ G.F₀ (Y , Y) ⟩ G.F₁ (f , C.id) ⟩ -- We add this extra proof, because, again, we want to ensure the opposite of the -- opposite of dinatural transformation is definitionally equal to itself. op-commute : ∀ {X Y} (f : C [ X , Y ]) → [ F.F₀ (Y , X) ⇒ G.F₀ (X , Y) ]⟨ F.F₁ (C.id , f) ⇒⟨ F.F₀ (Y , Y) ⟩ (α Y ⇒⟨ G.F₀ (Y , Y) ⟩ G.F₁ (f , C.id)) ≈ F.F₁ (f , C.id) ⇒⟨ F.F₀ (X , X) ⟩ (α X ⇒⟨ G.F₀ (X , X) ⟩ G.F₁ (C.id , f)) ⟩ op : DinaturalTransformation G.op F.op op = record { α = α ; commute = op-commute ; op-commute = commute } -- to reduce the burden of constructing a DinaturalTransformation, we introduce -- another helper. record DTHelper (F G : Bifunctor (Category.op C) C D) : Set (levelOfTerm F) where private module C = Category C module D = Category D module F = Functor F module G = Functor G open D hiding (op) open Commutation field α : ∀ X → D [ F.F₀ (X , X) , G.F₀ (X , X) ] commute : ∀ {X Y} (f : C [ X , Y ]) → [ F.F₀ (Y , X) ⇒ G.F₀ (X , Y) ]⟨ F.F₁ (f , C.id) ⇒⟨ F.F₀ (X , X) ⟩ α X ⇒⟨ G.F₀ (X , X) ⟩ G.F₁ (C.id , f) ≈ F.F₁ (C.id , f) ⇒⟨ F.F₀ (Y , Y) ⟩ α Y ⇒⟨ G.F₀ (Y , Y) ⟩ G.F₁ (f , C.id) ⟩ dtHelper : ∀ {F G : Bifunctor (Category.op C) C D} → DTHelper F G → DinaturalTransformation F G dtHelper {D = D} θ = record { α = α ; commute = commute ; op-commute = λ f → assoc ○ ⟺ (commute f) ○ sym-assoc } where open DTHelper θ open Category D open HomReasoning module _ {F G H : Bifunctor (Category.op C) C D} where private module C = Category C open Category D open HomReasoning open Functor open MR D infixr 9 _<∘_ infixl 9 _∘>_ _<∘_ : NaturalTransformation G H → DinaturalTransformation F G → DinaturalTransformation F H θ <∘ β = dtHelper record { α = λ X → η (X , X) ∘ α X ; commute = λ {X Y} f → begin F₁ H (C.id , f) ∘ (η (X , X) ∘ α X) ∘ F₁ F (f , C.id) ≈˘⟨ pushˡ (pushˡ (θ.commute (C.id , f))) ⟩ ((η (X , Y) ∘ F₁ G (C.id , f)) ∘ α X) ∘ F₁ F (f , C.id) ≈⟨ assoc ○ pullʳ (β.commute f) ⟩ η (X , Y) ∘ F₁ G (f , C.id) ∘ α Y ∘ F₁ F (C.id , f) ≈⟨ pullˡ (θ.commute (f , C.id)) ○ pullʳ (⟺ assoc) ⟩ F₁ H (f , C.id) ∘ (η (Y , Y) ∘ α Y) ∘ F₁ F (C.id , f) ∎ } where module θ = NaturalTransformation θ module β = DinaturalTransformation β open θ open β _∘>_ : DinaturalTransformation G H → NaturalTransformation F G → DinaturalTransformation F H β ∘> θ = dtHelper record { α = λ X → α X ∘ η (X , X) ; commute = λ {X Y} f → begin F₁ H (C.id , f) ∘ (α X ∘ η (X , X)) ∘ F₁ F (f , C.id) ≈⟨ refl⟩∘⟨ pullʳ (θ.commute (f , C.id)) ⟩ F₁ H (C.id , f) ∘ α X ∘ F₁ G (f , C.id) ∘ η (Y , X) ≈˘⟨ assoc ○ ∘-resp-≈ʳ assoc ⟩ (F₁ H (C.id , f) ∘ α X ∘ F₁ G (f , C.id)) ∘ η (Y , X) ≈⟨ β.commute f ⟩∘⟨refl ⟩ (F₁ H (f , C.id) ∘ α Y ∘ F₁ G (C.id , f)) ∘ η (Y , X) ≈˘⟨ pushʳ (assoc ○ pushʳ (θ.commute (C.id , f))) ⟩ F₁ H (f , C.id) ∘ (α Y ∘ η (Y , Y)) ∘ F₁ F (C.id , f) ∎ } where module θ = NaturalTransformation θ module β = DinaturalTransformation β open θ open β module _ {F G : Bifunctor (Category.op C) C D} where private module C = Category C open Category D open HomReasoning open Functor open MR D infixl 9 _∘ʳ_ _∘ʳ_ : ∀ {E : Category o ℓ e} → DinaturalTransformation F G → (K : Functor E C) → DinaturalTransformation (F ∘F ((Functor.op K) ⁂ K)) (G ∘F ((Functor.op K) ⁂ K)) _∘ʳ_ {E = E} β K = dtHelper record { α = λ X → α (F₀ K X) ; commute = λ {X Y} f → begin F₁ G (F₁ K E.id , F₁ K f) ∘ α (F₀ K X) ∘ F₁ F (F₁ K f , F₁ K E.id) ≈⟨ F-resp-≈ G (identity K , C.Equiv.refl) ⟩∘⟨ refl ⟩∘⟨ F-resp-≈ F (C.Equiv.refl , identity K) ⟩ F₁ G (C.id , F₁ K f) ∘ α (F₀ K X) ∘ F₁ F (F₁ K f , C.id) ≈⟨ commute (F₁ K f) ⟩ F₁ G (F₁ K f , C.id) ∘ α (F₀ K Y) ∘ F₁ F (C.id , F₁ K f) ≈˘⟨ F-resp-≈ G (C.Equiv.refl , identity K) ⟩∘⟨ refl ⟩∘⟨ F-resp-≈ F (identity K , C.Equiv.refl) ⟩ F₁ G (F₁ K f , F₁ K E.id) ∘ α (F₀ K Y) ∘ F₁ F (F₁ K E.id , F₁ K f) ∎ } where module β = DinaturalTransformation β module E = Category E open β infix 4 _≃_ _≃_ : Rel (DinaturalTransformation F G) _ β ≃ δ = ∀ {X} → α β X ≈ α δ X where open DinaturalTransformation ≃-isEquivalence : IsEquivalence _≃_ ≃-isEquivalence = record { refl = refl ; sym = λ eq → sym eq ; trans = λ eq eq′ → trans eq eq′ } ≃-setoid : Setoid _ _ ≃-setoid = record { Carrier = DinaturalTransformation F G ; _≈_ = _≃_ ; isEquivalence = ≃-isEquivalence } -- for convenience, the following are some helpers for the cases -- in which the bifunctor on the right is extranatural. Extranaturalʳ : ∀ {C : Category o ℓ e} → Category.Obj D → (F : Bifunctor (Category.op C) C D) → Set _ Extranaturalʳ A F = DinaturalTransformation (const A) F Extranaturalˡ : ∀ {C : Category o ℓ e} → (F : Bifunctor (Category.op C) C D) → Category.Obj D → Set _ Extranaturalˡ F A = DinaturalTransformation F (const A) module _ {F : Bifunctor (Category.op C) C D} where open Category D private module C = Category C variable A : Obj X Y : C.Obj f : X C.⇒ Y open Functor F open HomReasoning open MR D extranaturalʳ : (a : ∀ X → A ⇒ F₀ (X , X)) → (∀ {X X′ f} → F₁ (C.id , f) ∘ a X ≈ F₁ (f , C.id) ∘ a X′) → Extranaturalʳ A F extranaturalʳ a comm = dtHelper record { α = a ; commute = λ f → ∘-resp-≈ʳ identityʳ ○ comm ○ ∘-resp-≈ʳ (⟺ identityʳ) } open DinaturalTransformation extranatural-commʳ : (β : DinaturalTransformation (const A) F) → F₁ (C.id , f) ∘ α β X ≈ F₁ (f , C.id) ∘ α β Y extranatural-commʳ {f = f} β = ∘-resp-≈ʳ (⟺ identityʳ) ○ commute β f ○ ∘-resp-≈ʳ identityʳ -- the dual case, the bifunctor on the left is extranatural. extranaturalˡ : (a : ∀ X → F₀ (X , X) ⇒ A) → (∀ {X X′ f} → a X ∘ F₁ (f , C.id) ≈ a X′ ∘ F₁ (C.id , f)) → Extranaturalˡ F A extranaturalˡ a comm = dtHelper record { α = a ; commute = λ f → pullˡ identityˡ ○ comm ○ ⟺ (pullˡ identityˡ) } extranatural-commˡ : (β : DinaturalTransformation F (const A)) → α β X ∘ F₁ (f , C.id) ≈ α β Y ∘ F₁ (C.id , f) extranatural-commˡ {f = f} β = ⟺ (pullˡ identityˡ) ○ commute β f ○ pullˡ identityˡ
{ "alphanum_fraction": 0.5044990272, "avg_line_length": 35.6017316017, "ext": "agda", "hexsha": "3d7188c2480a8e439931c246ee4e86295b33f501", "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": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Taneb/agda-categories", "max_forks_repo_path": "Categories/NaturalTransformation/Dinatural.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "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": "Taneb/agda-categories", "max_issues_repo_path": "Categories/NaturalTransformation/Dinatural.agda", "max_line_length": 140, "max_stars_count": null, "max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Taneb/agda-categories", "max_stars_repo_path": "Categories/NaturalTransformation/Dinatural.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3115, "size": 8224 }
open import Spire.Type module Spire.Hybrid where ---------------------------------------------------------------------- data Context : Set₁ Environment : Context → Set ScopedType : Context → Set₁ ScopedType Γ = Environment Γ → Set data Context where ∅ : Context _,_ : (Γ : Context) (A : ScopedType Γ) → Context Environment ∅ = ⊤ Environment (Γ , A) = Σ (Environment Γ) A data Var : (Γ : Context) (A : ScopedType Γ) → Set₁ where here : ∀{Γ A} → Var (Γ , A) (λ vs → A (proj₁ vs)) there : ∀{Γ A} {B : ScopedType Γ} → Var Γ A → Var (Γ , B) (λ vs → A (proj₁ vs)) lookup : ∀{Γ A} → Var Γ A → (vs : Environment Γ) → A vs lookup here (vs , v) = v lookup (there i) (vs , v) = lookup i vs ScopedType₂ : (Γ : Context) → ScopedType Γ → Set₁ ScopedType₂ Γ A = (vs : Environment Γ) → A vs → Set ---------------------------------------------------------------------- data Term (Γ : Context) : ScopedType Γ → Set₁ eval : ∀{Γ A} → Term Γ A → (vs : Environment Γ) → A vs -- ---------------------------------------------------------------------- data Term Γ where {- Type introduction -} `⊥ `⊤ `Bool `ℕ `Type : ∀{ℓ} → Term Γ (const (Type ℓ)) `Π `Σ : ∀{ℓ} (A : Term Γ (const (Type ℓ))) (B : Term (Γ , λ vs → ⟦ ℓ ∣ eval A vs ⟧) (const (Type ℓ))) → Term Γ (λ _ → Type ℓ) `⟦_⟧ : ∀{ℓ} (A : Term Γ (const (Type ℓ))) → Term Γ (const (Type (suc ℓ))) {- Value introduction -} `tt : Term Γ (const ⊤) `true `false : Term Γ (const Bool) `zero : Term Γ (const ℕ) `suc : Term Γ (const ℕ) → Term Γ (const ℕ) `λ : ∀{A} {B : ScopedType₂ Γ A} (f : Term (Γ , A) (λ vs → B (proj₁ vs) (proj₂ vs))) → Term Γ (λ vs → (v : A vs) → (B vs v)) _`,_ : ∀{A} {B : ScopedType₂ Γ A} (a : Term Γ A) (b : Term Γ (λ vs → B vs (eval a vs))) → Term Γ (λ vs → Σ (A vs) (λ v → B vs v)) {- Value elimination -} `var : ∀{A} (a : Var Γ A) → Term Γ A `elim⊥ : ∀{A ℓ} (P : Term Γ (const (Type ℓ))) (x : Term Γ (const ⊥)) → Term Γ A `elimBool : ∀{ℓ} (P : Term (Γ , const Bool) (const (Type ℓ))) (pt : Term Γ (λ vs → ⟦ ℓ ∣ eval P (vs , true) ⟧)) (pf : Term Γ (λ vs → ⟦ ℓ ∣ eval P (vs , false) ⟧)) (b : Term Γ (const Bool)) → Term Γ (λ vs → ⟦ ℓ ∣ eval P (vs , eval b vs) ⟧) `elimℕ : ∀{ℓ} (P : Term (Γ , (const ℕ)) (const (Type ℓ))) (pz : Term Γ (λ vs → ⟦ ℓ ∣ eval P (vs , zero) ⟧)) (ps : Term ((Γ , const ℕ) , (λ { (vs , n) → ⟦ ℓ ∣ eval P (vs , n) ⟧ })) (λ { ((vs , n) , p) → ⟦ ℓ ∣ eval P (vs , suc n) ⟧ })) (n : Term Γ (const ℕ)) → Term Γ (λ vs → ⟦ ℓ ∣ eval P (vs , eval n vs) ⟧) _`$_ : ∀{A} {B : ScopedType₂ Γ A} (f : Term Γ (λ vs → (v : A vs) → (B vs v))) (a : Term Γ A) → Term Γ (λ vs → B vs (eval a vs)) `proj₁ : ∀{A} {B : ScopedType₂ Γ A} (ab : Term Γ (λ vs → Σ (A vs) (B vs))) → Term Γ A `proj₂ : ∀{A} {B : ScopedType₂ Γ A} (ab : Term Γ (λ vs → Σ (A vs) (B vs))) → Term Γ (λ vs → B vs (proj₁ (eval ab vs))) ---------------------------------------------------------------------- {- Type introduction -} eval `⊥ vs = `⊥ eval `⊤ vs = `⊤ eval `Bool vs = `Bool eval `ℕ vs = `ℕ eval `Type vs = `Type eval (`Π A B) vs = `Π (eval A vs) λ v → eval B (vs , v) eval (`Σ A B) vs = `Σ (eval A vs) λ v → eval B (vs , v) eval `⟦ A ⟧ vs = `⟦ eval A vs ⟧ {- Value introduction -} eval `tt vs = tt eval `true vs = true eval `false vs = false eval `zero vs = zero eval (`suc n) vs = suc (eval n vs) eval (`λ f) vs = λ v → eval f (vs , v) eval (a `, b) vs = eval a vs , eval b vs {- Value elimination -} eval (`var i) vs = lookup i vs eval (`elim⊥ P x) vs = elim⊥ (eval x vs) eval (`elimBool {ℓ} P pt pf b) vs = elimBool (λ v → ⟦ ℓ ∣ eval P (vs , v) ⟧) (eval pt vs) (eval pf vs) (eval b vs) eval (`elimℕ {ℓ} P pz ps n) vs = elimℕ (λ v → ⟦ ℓ ∣ eval P (vs , v) ⟧) (eval pz vs) (λ n rec → eval ps ((vs , n) , rec)) (eval n vs) eval (f `$ a) vs = (eval f vs) (eval a vs) eval (`proj₁ ab) vs = proj₁ (eval ab vs) eval (`proj₂ ab) vs = proj₂ (eval ab vs) ----------------------------------------------------------------------
{ "alphanum_fraction": 0.4588755217, "avg_line_length": 30.8560606061, "ext": "agda", "hexsha": "2227f88da652d1b1ea394a735e2328267da7c53a", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-08-17T21:00:07.000Z", "max_forks_repo_forks_event_min_datetime": "2015-08-17T21:00:07.000Z", "max_forks_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "spire/spire", "max_forks_repo_path": "formalization/agda/Spire/Hybrid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "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": "spire/spire", "max_issues_repo_path": "formalization/agda/Spire/Hybrid.agda", "max_line_length": 76, "max_stars_count": 43, "max_stars_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "spire/spire", "max_stars_repo_path": "formalization/agda/Spire/Hybrid.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T17:10:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-28T23:25:33.000Z", "num_tokens": 1578, "size": 4073 }
------------------------------------------------------------------------ -- An example ------------------------------------------------------------------------ module Mixfix.Cyclic.Example where open import Codata.Musical.Notation open import Data.Vec using ([]; _∷_; [_]) open import Data.List as List using (List; []; _∷_) renaming ([_] to L[_]) open import Data.List.Relation.Unary.Any as Any using (here; there) import Codata.Musical.Colist as Colist open import Data.Product using (∃₂; -,_) open import Data.Unit.Polymorphic using (⊤) open import Data.Nat using (ℕ; zero; suc) open import Data.Fin using (Fin; #_; zero; suc) import Data.List.Relation.Binary.Pointwise as ListEq import Data.String as String open String using (String; _++_) import Data.String.Properties as String open import Relation.Binary open DecSetoid (ListEq.decSetoid String.≡-decSetoid) using (_≟_) open import Function using (_∘_) open import Data.Bool using (Bool; if_then_else_) open import Relation.Nullary.Decidable using (⌊_⌋) import Relation.Binary.PropositionalEquality as P open import IO import Level open import Mixfix.Fixity hiding (_≟_) open import Mixfix.Operator open import Mixfix.Expr open import Mixfix.Cyclic.PrecedenceGraph hiding (module PrecedenceGraph) import Mixfix.Cyclic.Grammar as Grammar import Mixfix.Cyclic.Show as Show import TotalParserCombinators.BreadthFirst as BreadthFirst ------------------------------------------------------------------------ -- Operators atom : Operator closed 0 atom = record { nameParts = "•" ∷ [] } plus : Operator (infx left) 0 plus = record { nameParts = "+" ∷ [] } ifThen : Operator prefx 1 ifThen = record { nameParts = "i" ∷ "t" ∷ [] } ifThenElse : Operator prefx 2 ifThenElse = record { nameParts = "i" ∷ "t" ∷ "e" ∷ [] } comma : Operator (infx left) 0 comma = record { nameParts = "," ∷ [] } wellTyped : Operator postfx 1 wellTyped = record { nameParts = "⊢" ∷ "∶" ∷ [] } ------------------------------------------------------------------------ -- Precedence graph mutual private levels : ℕ levels = 5 a = # 0 pl = # 1 ii = # 2 c = # 3 wt = #_ 4 {n = levels} g : PrecedenceGraph g = record { levels = levels ; ops = λ p fix → List.mapMaybe (hasFixity fix) (ops p) ; ↑ = ↑ } where Precedence : Set Precedence = Fin levels ops : Precedence → List (∃₂ Operator) ops zero = (-, -, atom) ∷ [] ops (suc zero) = (-, -, plus) ∷ [] ops (suc (suc zero)) = (-, -, ifThen) ∷ (-, -, ifThenElse) ∷ [] ops (suc (suc (suc zero))) = (-, -, comma) ∷ [] ops (suc (suc (suc (suc zero)))) = (-, -, wellTyped) ∷ [] ops (suc (suc (suc (suc (suc ()))))) ↑ : Precedence → List (Precedence) ↑ zero = [] ↑ (suc zero) = a ∷ [] ↑ (suc (suc zero)) = pl ∷ a ∷ [] ↑ (suc (suc (suc zero))) = ii ∷ pl ∷ a ∷ [] ↑ (suc (suc (suc (suc zero)))) = c ∷ a ∷ [] ↑ (suc (suc (suc (suc (suc ()))))) ------------------------------------------------------------------------ -- Expressions open PrecedenceCorrect cyclic g • : ExprIn a non • = ⟪ here P.refl ∙ [] ⟫ _+_ : Outer pl left → Expr (a ∷ []) → ExprIn pl left e₁ + e₂ = e₁ ⟨ here P.refl ∙ [] ⟩ˡ e₂ i_t_ : Expr anyPrecedence → Outer ii right → ExprIn ii right i e₁ t e₂ = ⟪ here P.refl ∙ e₁ ∷ [] ⟩ e₂ i_t_e_ : Expr anyPrecedence → Expr anyPrecedence → Outer ii right → ExprIn ii right i e₁ t e₂ e e₃ = ⟪ there (here P.refl) ∙ e₁ ∷ e₂ ∷ [] ⟩ e₃ _,_ : Outer c left → Expr (ii ∷ pl ∷ a ∷ []) → ExprIn c left e₁ , e₂ = e₁ ⟨ here P.refl ∙ [] ⟩ˡ e₂ _⊢_∶ : Outer wt left → Expr anyPrecedence → ExprIn wt left e₁ ⊢ e₂ ∶ = e₁ ⟨ here P.refl ∙ [ e₂ ] ⟫ ------------------------------------------------------------------------ -- Some tests open Show cyclic g fromNameParts : List NamePart → String fromNameParts = List.foldr _++_ "" toNameParts : String → List NamePart toNameParts = List.map (String.fromList ∘ L[_]) ∘ String.toList parseExpr : String → List String parseExpr = List.map (fromNameParts ∘ show) ∘ BreadthFirst.parse (Grammar.expression cyclic g) ∘ toNameParts runTest : String → List String → IO (⊤ {ℓ = Level.zero}) runTest s₁ s₂ = do putStrLn ("Testing: " ++ s₁) Colist.mapM′ putStrLn (Colist.fromList p₁) putStrLn (if ⌊ p₁ ≟ s₂ ⌋ then "Passed" else "Failed") where p₁ = parseExpr s₁ main = run do runTest "•+•⊢•∶" [] runTest "•,•⊢∶" [] runTest "•⊢•∶" L[ "•⊢•∶" ] runTest "•,i•t•+•⊢•∶" L[ "•,i•t•+•⊢•∶" ] runTest "i•ti•t•e•" ("i•ti•t•e•" ∷ "i•ti•t•e•" ∷ [])
{ "alphanum_fraction": 0.5279230287, "avg_line_length": 30.6474358974, "ext": "agda", "hexsha": "b875c347f791417421e219c1990319bcfd21be28", "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": "76774f54f466cfe943debf2da731074fe0c33644", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_path": "Mixfix/Cyclic/Example.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_path": "Mixfix/Cyclic/Example.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/parser-combinators", "max_stars_repo_path": "Mixfix/Cyclic/Example.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z", "num_tokens": 1533, "size": 4781 }
module Prelude where infixr 90 _∘_ infixr 50 _∧_ infix 20 _⟸⇒_ infixl 3 _from_ _from_ : (A : Set) -> A -> A A from a = a _∘_ : {A B C : Set} -> (A -> B) -> (C -> A) -> C -> B (f ∘ g) x = f (g x) record _∧_ (A B : Set) : Set where field p₁ : A p₂ : B open _∧_ public renaming (p₁ to fst; p₂ to snd) _,_ : {A B : Set} -> A -> B -> A ∧ B x , y = record { p₁ = x; p₂ = y } swap : {A B : Set} -> A ∧ B -> B ∧ A swap p = (snd p , fst p) _⇐⇒_ : Set -> Set -> Set A ⇐⇒ B = (A -> B) ∧ (B -> A)
{ "alphanum_fraction": 0.4604743083, "avg_line_length": 16.8666666667, "ext": "agda", "hexsha": "49ff3483babdd8a3781d838ba3eeb183b8083c1f", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "examples/outdated-and-incorrect/lattice/Prelude.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "examples/outdated-and-incorrect/lattice/Prelude.agda", "max_line_length": 53, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "examples/outdated-and-incorrect/lattice/Prelude.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": 247, "size": 506 }
-- Andreas, 2020-02-18, issue #4450 raised by Nisse -- -- ETA pragma should be considered unsafe, since type-checking may loop. {-# OPTIONS --safe --guardedness #-} open import Agda.Builtin.Equality record R : Set where coinductive field force : R open R {-# ETA R #-} foo : R foo .force .force = foo -- test : foo .force ≡ foo -- test = refl -- test makes type checker loop; -- ETA with --safe is a soft error and only raised after -- the whole file is processed.
{ "alphanum_fraction": 0.6750524109, "avg_line_length": 18.3461538462, "ext": "agda", "hexsha": "6012137a82c495c2602c8dc89cd270cfbb6378ce", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue4450.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue4450.agda", "max_line_length": 72, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue4450.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": 132, "size": 477 }
open import Relation.Binary.Core module PLRTree.Order {A : Set} where open import Data.Nat open import Data.Sum open import PLRTree {A} open import Relation.Binary open DecTotalOrder decTotalOrder hiding (refl) height : PLRTree → ℕ height leaf = zero height (node t x l r) with total (height l) (height r) ... | inj₁ hl≤hr = suc (height r) ... | inj₂ hr≤hl = suc (height l) _≺_ : PLRTree → PLRTree → Set t ≺ t' = height t <′ height t'
{ "alphanum_fraction": 0.6883408072, "avg_line_length": 21.2380952381, "ext": "agda", "hexsha": "0fdc139867139aace9d2dcfed7b4a26a2acc9287", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_path": "agda/PLRTree/Order.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bgbianchi/sorting", "max_issues_repo_path": "agda/PLRTree/Order.agda", "max_line_length": 46, "max_stars_count": 6, "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_path": "agda/PLRTree/Order.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "num_tokens": 143, "size": 446 }
{-# OPTIONS --without-K #-} module well-typed-quoted-syntax where open import common open import well-typed-syntax open import well-typed-syntax-helpers public open import well-typed-quoted-syntax-defs public open import well-typed-syntax-context-helpers public open import well-typed-syntax-eq-dec public infixr 2 _‘‘∘’’_ quote-sigma : (Γv : Σ Context Typ) → Term {ε} (‘Σ’ ‘Context’ ‘Typ’) quote-sigma (Γ , v) = ‘existT’ ⌜ Γ ⌝c ⌜ v ⌝T _‘‘∘’’_ : ∀ {A B C} → □ (‘□’ ‘’ (C ‘‘→'’’ B)) → □ (‘□’ ‘’ (A ‘‘→'’’ C)) → □ (‘□’ ‘’ (A ‘‘→'’’ B)) g ‘‘∘’’ f = (‘‘fcomp-nd’’ ‘'’ₐ f ‘'’ₐ g) Conv0 : ∀ {qH0 qX} → Term {Γ = (ε ▻ ‘□’ ‘’ qH0)} (W (‘□’ ‘’ ⌜ ‘□’ ‘’ qH0 ‘→'’ qX ⌝T)) → Term {Γ = (ε ▻ ‘□’ ‘’ qH0)} (W (‘□’ ‘’ (⌜ ‘□’ ‘’ qH0 ⌝T ‘‘→'’’ ⌜ qX ⌝T))) Conv0 {qH0} {qX} x = w→ ⌜→'⌝ ‘'’ₐ x
{ "alphanum_fraction": 0.4772727273, "avg_line_length": 29.8571428571, "ext": "agda", "hexsha": "1f06241fd0c4ff5c6970b08d780205bc0a8afa1b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JasonGross/lob", "max_forks_repo_path": "internal/well-typed-quoted-syntax.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JasonGross/lob", "max_issues_repo_path": "internal/well-typed-quoted-syntax.agda", "max_line_length": 67, "max_stars_count": 19, "max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JasonGross/lob", "max_stars_repo_path": "internal/well-typed-quoted-syntax.agda", "max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z", "num_tokens": 417, "size": 836 }
open import Relation.Binary using (Preorder) open import Relation.Binary.PropositionalEquality open import Relation.Unary module Category.Monad.Monotone.Reader {ℓ}(pre : Preorder ℓ ℓ ℓ) where open Preorder pre renaming (Carrier to I; _∼_ to _≤_; refl to ≤-refl) open import Relation.Unary.Monotone pre open import Relation.Unary.PredicateTransformer using (Pt) open import Data.Product open import Function open import Level hiding (lift) open import Category.Monad open import Category.Monad.Monotone.Identity pre open import Category.Monad.Monotone pre ReaderT : Pred I ℓ → Pt I ℓ → Pt I ℓ ReaderT E M P = λ i → E i → M P i Reader : (Pred I ℓ) → Pt I ℓ Reader E = ReaderT E Identity record ReaderMonad E (M : Pred I ℓ → Pt I ℓ) : Set (suc ℓ) where field ask : ∀ {i} → M E E i reader : ∀ {P} → (E ⇒ P) ⊆ M E P local : ∀ {P E'} → (E ⇒ E') ⊆ (M E' P ⇒ M E P) asks : ∀ {A} → (E ⇒ A) ⊆ M E A asks = reader module _ {M : Pt I ℓ}⦃ Mon : RawMPMonad M ⦄ where private module M = RawMPMonad Mon module _ {E}⦃ mono : Monotone E ⦄ where instance open RawMPMonad reader-monad : RawMPMonad (ReaderT E M) return reader-monad x e = M.return x _≥=_ reader-monad m f e = m e M.≥= λ i≤j px → f i≤j px (wk i≤j e) open ReaderMonad reader-monad-ops : ReaderMonad E (λ E → ReaderT E M) ask reader-monad-ops e = M.return e reader reader-monad-ops f e = M.return (f e) local reader-monad-ops f c e = c (f e) lift-reader : ∀ {P} E → M P ⊆ ReaderT E M P lift-reader _ z _ = z
{ "alphanum_fraction": 0.6453900709, "avg_line_length": 30.4117647059, "ext": "agda", "hexsha": "40535b7221f7d0f999f09a7a752fe0756a9748d8", "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/Monotone/Reader.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/Monotone/Reader.agda", "max_line_length": 72, "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/Monotone/Reader.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": 533, "size": 1551 }
open import Nat open import Prelude open import List open import core open import judgemental-erase open import checks open import moveerase module aasubsume-min where -- this predicate on derivations of actions bans the cases that induce -- non-determinism. mutual aasubmin-synth : ∀{Γ e t α e' t'} → (Γ ⊢ e => t ~ α ~> e' => t') → Set aasubmin-synth (SAZipAsc1 x) = aasubmin-ana x aasubmin-synth (SAZipApArr x x₁ x₂ d x₃) = aasubmin-synth d aasubmin-synth (SAZipApAna x x₁ x₂) = aasubmin-ana x₂ aasubmin-synth (SAZipPlus1 x) = aasubmin-ana x aasubmin-synth (SAZipPlus2 x) = aasubmin-ana x aasubmin-synth (SAZipHole x x₁ d) = aasubmin-synth d aasubmin-synth _ = ⊤ aasubmin-ana : ∀{Γ e α e' t} → (Γ ⊢ e ~ α ~> e' ⇐ t) → Set aasubmin-ana (AASubsume x x₁ SAConAsc x₃) = ⊥ aasubmin-ana (AASubsume x x₁ (SAConLam x₃) x₄) = ⊥ aasubmin-ana (AASubsume x x₁ s x₃) = aasubmin-synth s aasubmin-ana (AAZipLam x₁ x₂ d) = aasubmin-ana d aasubmin-ana _ = ⊤ -- the minimization predicate propagates through subsumption rules min-ana-lem : ∀{e e' e◆ Γ t t' t'' α} {a : erase-e e e◆} {b : Γ ⊢ e◆ => t'} {c : t ~ t''} → (d : Γ ⊢ e => t' ~ α ~> e' => t'') → aasubmin-ana (AASubsume a b d c) → aasubmin-synth d min-ana-lem (SAMove x) min = <> min-ana-lem (SADel) min = <> min-ana-lem (SAConAsc) min = <> min-ana-lem (SAConVar p) min = <> min-ana-lem (SAConLam x₁) min = <> min-ana-lem (SAConApArr x) min = <> min-ana-lem (SAConApOtw x) min = <> min-ana-lem (SAConNumlit) min = <> min-ana-lem (SAConPlus1 x) min = <> min-ana-lem (SAConPlus2 x) min = <> min-ana-lem (SAConNEHole) min = <> min-ana-lem (SAFinish x) min = <> min-ana-lem (SAZipAsc1 x) min = min min-ana-lem (SAZipAsc2 x x₁ x₂ x₃) min = <> min-ana-lem (SAZipApArr x x₁ x₂ c x₃) min = min min-ana-lem (SAZipApAna x x₁ x₂) min = min min-ana-lem (SAZipPlus1 x) min = min min-ana-lem (SAZipPlus2 x) min = min min-ana-lem (SAZipHole x x₁ c) min = min -- any derivation of an action can be minimized to avoid this cases that -- induce non-determinism. mutual min-synth : ∀{Γ e t α e' t'} → (d : Γ ⊢ e => t ~ α ~> e' => t') → Σ[ e'' ∈ ê ] Σ[ d' ∈ Γ ⊢ e => t ~ α ~> e'' => t' ] aasubmin-synth d' min-synth (SAMove x) = _ , SAMove x , <> min-synth SADel = _ , SADel , <> min-synth SAConAsc = _ , SAConAsc , <> min-synth (SAConVar p) = _ , SAConVar p , <> min-synth (SAConLam x₁) = _ , SAConLam x₁ , <> min-synth (SAConApArr x) = _ , SAConApArr x , <> min-synth (SAConApOtw x) = _ , SAConApOtw x , <> min-synth SAConNumlit = _ , SAConNumlit , <> min-synth (SAConPlus1 x) = _ , SAConPlus1 x , <> min-synth (SAConPlus2 x) = _ , SAConPlus2 x , <> min-synth SAConNEHole = _ , SAConNEHole , <> min-synth (SAFinish x) = _ , SAFinish x , <> min-synth (SAZipAsc2 x x₁ x₂ x₃) = _ , SAZipAsc2 x x₁ x₂ x₃ , <> min-synth (SAZipAsc1 x) with min-ana x ... | _ , a , b = _ , SAZipAsc1 a , b min-synth (SAZipApArr x x₁ x₂ d x₃) with min-synth d ... | _ , a , b = _ , (SAZipApArr x x₁ x₂ a x₃) , b min-synth (SAZipApAna x x₁ x₂) with min-ana x₂ ... | _ , a , b = _ , SAZipApAna x x₁ a , b min-synth (SAZipPlus1 x) with min-ana x ... | _ , a , b = _ , SAZipPlus1 a , b min-synth (SAZipPlus2 x) with min-ana x ... | _ , a , b = _ , SAZipPlus2 a , b min-synth (SAZipHole x x₁ d) with min-synth d ... | _ , a , b = _ , SAZipHole x x₁ a , b min-ana : ∀{Γ e α e' t} → (d : Γ ⊢ e ~ α ~> e' ⇐ t) → Σ[ e'' ∈ ê ] Σ[ d' ∈ Γ ⊢ e ~ α ~> e'' ⇐ t ] aasubmin-ana d' min-ana (AASubsume {Γ = Γ} x x₁ (SAMove x₂) x₃) = _ , AAMove x₂ , <> min-ana (AASubsume x x₁ SADel x₃) = _ , AADel , <> min-ana (AASubsume {Γ = Γ} {t = t} {t' = t'} x x₁ SAConAsc x₃) = _ , AAConAsc {Γ = Γ} {t = t} , <> min-ana (AASubsume x x₁ (SAConVar p) x₃) = _ , AASubsume x x₁ (SAConVar p) x₃ , <> min-ana (AASubsume EETop SEHole (SAConLam x₃) TCRefl) = _ , AAConLam1 x₃ MAArr , <> min-ana (AASubsume EETop SEHole (SAConLam x₃) TCHole2) = _ , AAConLam1 x₃ MAHole , <> min-ana (AASubsume EETop SEHole (SAConLam x₃) (TCArr x₄ x₅)) = _ , AAConLam1 x₃ MAArr , <> min-ana (AASubsume x x₁ (SAConApArr x₂) x₃) = _ , AASubsume x x₁ (SAConApArr x₂) x₃ , <> min-ana (AASubsume x x₁ (SAConApOtw x₂) x₃) = _ , AASubsume x x₁ (SAConApOtw x₂) x₃ , <> min-ana (AASubsume x x₁ SAConNumlit x₃) = _ , AASubsume x x₁ SAConNumlit x₃ , <> min-ana (AASubsume x x₁ (SAConPlus1 x₂) x₃) = _ , AASubsume x x₁ (SAConPlus1 x₂) x₃ , <> min-ana (AASubsume x x₁ (SAConPlus2 x₂) x₃) = _ , AASubsume x x₁ (SAConPlus2 x₂) x₃ , <> min-ana (AASubsume x x₁ SAConNEHole x₃) = _ , AASubsume x x₁ SAConNEHole x₃ , <> min-ana (AASubsume x x₁ (SAFinish x₂) x₃) = _ , AASubsume x x₁ (SAFinish x₂) x₃ , <> min-ana (AASubsume x x₁ (SAZipAsc2 x₂ x₃ x₄ x₅) x₆) = _ , AASubsume x x₁ (SAZipAsc2 x₂ x₃ x₄ x₅) x₆ , <> min-ana (AASubsume x x₁ (SAZipAsc1 x₂) x₃) with min-ana x₂ ... | a , b , c = _ , AASubsume x x₁ (SAZipAsc1 b) x₃ , c min-ana (AASubsume x x₁ (SAZipApArr x₂ x₃ x₄ x₅ x₆) x₇) with min-synth x₅ ... | a , b , c = _ , AASubsume x x₁ (SAZipApArr x₂ x₃ x₄ b x₆) x₇ , c min-ana (AASubsume x x₁ (SAZipApAna x₂ x₃ x₄) x₅) with min-ana x₄ ... | a , b , c = _ , AASubsume x x₁ (SAZipApAna x₂ x₃ b) x₅ , c min-ana (AASubsume x x₁ (SAZipPlus1 x₂) x₃) with min-ana x₂ ... | a , b , c = _ , AASubsume x x₁ (SAZipPlus1 b) x₃ , c min-ana (AASubsume x x₁ (SAZipPlus2 x₂) x₃) with min-ana x₂ ... | a , b , c = _ , AASubsume x x₁ (SAZipPlus2 b) x₃ , c min-ana (AASubsume x x₁ (SAZipHole x₂ x₃ x₄) x₅) with min-synth x₄ ... | a , b , c = _ , AASubsume x x₁ (SAZipHole x₂ x₃ b) x₅ , c min-ana (AAMove x) = _ , AAMove x , <> min-ana AADel = _ , AADel , <> min-ana AAConAsc = _ , AAConAsc , <> min-ana (AAConVar x₁ p) = _ , AAConVar x₁ p , <> min-ana (AAConLam1 x₁ x₂) = _ , AAConLam1 x₁ x₂ , <> min-ana (AAConLam2 x₁ x₂) = _ , AAConLam2 x₁ x₂ , <> min-ana (AAConNumlit x) = _ , AAConNumlit x , <> min-ana (AAFinish x) = _ , AAFinish x , <> min-ana (AAZipLam x₁ x₂ d) with min-ana d ... | a , b , c = _ , AAZipLam x₁ x₂ b , c -- these theorems argue that if a derivation is already subsumption -- minimal than the minimzer does not change the resultant -- expression--that it's conservative in this sense. they do not argue -- that the derivation that's computer is itself the same as the input -- derivation. mutual min-fixed-synth : ∀ {Γ e t α e' t'} → (d : Γ ⊢ e => t ~ α ~> e' => t') → aasubmin-synth d → e' == π1 (min-synth d) min-fixed-synth (SAMove x) min = refl min-fixed-synth SADel min = refl min-fixed-synth SAConAsc min = refl min-fixed-synth (SAConVar p) min = refl min-fixed-synth (SAConLam x₁) min = refl min-fixed-synth (SAConApArr x) min = refl min-fixed-synth (SAConApOtw x) min = refl min-fixed-synth SAConNumlit min = refl min-fixed-synth (SAConPlus1 x) min = refl min-fixed-synth (SAConPlus2 x) min = refl min-fixed-synth SAConNEHole min = refl min-fixed-synth (SAFinish x) min = refl min-fixed-synth (SAZipAsc1 x) min with min-fixed-ana x min ... | qq with min-ana x ... | (e'' , d' , min') = ap1 (λ q → q ·:₁ _) qq min-fixed-synth (SAZipAsc2 x x₁ x₂ x₃) min = refl min-fixed-synth (SAZipApArr x x₁ x₂ d x₃) min with min-fixed-synth d min ... | qq with min-synth d ... | (e'' , d' , min') = ap1 (λ q → q ∘₁ _) qq min-fixed-synth (SAZipApAna x x₁ x₂) min with min-fixed-ana x₂ min ... | qq with min-ana x₂ ... | (e'' , _ , _) = ap1 (λ q → _ ∘₂ q) qq min-fixed-synth (SAZipPlus1 x) min with min-fixed-ana x min ... | qq with min-ana x ... | (e'' , _ , _) = ap1 (λ q → q ·+₁ _) qq min-fixed-synth (SAZipPlus2 x) min with min-fixed-ana x min ... | qq with min-ana x ... | (e'' , _ , _) = ap1 (λ q → _ ·+₂ q) qq min-fixed-synth (SAZipHole x x₁ d) min with min-fixed-synth d min ... | qq with min-synth d ... | (e'' , _ , _) = ap1 ⦇⌜_⌟⦈ qq min-fixed-ana : ∀ {Γ e t α e' } → (d : Γ ⊢ e ~ α ~> e' ⇐ t) → aasubmin-ana d → e' == π1 (min-ana d) min-fixed-ana (AASubsume x x₁ (SAMove x₂) x₃) min = refl min-fixed-ana (AASubsume x x₁ SADel x₃) min = refl min-fixed-ana (AASubsume x x₁ SAConAsc x₃) min = abort min min-fixed-ana (AASubsume x₁ x₂ (SAConVar p) x₃) min = refl min-fixed-ana (AASubsume x₁ x₂ (SAConLam x₃) x₄) min = abort min min-fixed-ana (AASubsume x x₁ (SAConApArr x₂) x₃) min = refl min-fixed-ana (AASubsume x x₁ (SAConApOtw x₂) x₃) min = refl min-fixed-ana (AASubsume x x₁ SAConNumlit x₃) min = refl min-fixed-ana (AASubsume x x₁ (SAConPlus1 x₂) x₃) min = refl min-fixed-ana (AASubsume x x₁ (SAConPlus2 x₂) x₃) min = refl min-fixed-ana (AASubsume x x₁ SAConNEHole x₃) min = refl min-fixed-ana (AASubsume x x₁ (SAFinish x₂) x₃) min = refl min-fixed-ana (AASubsume x x₁ (SAZipAsc1 x₂) x₃) min with min-fixed-ana x₂ min ... | qq with min-ana x₂ ... | (e'' , _ , _) = ap1 (λ q → q ·:₁ _) qq min-fixed-ana (AASubsume x x₁ (SAZipAsc2 x₂ x₃ x₄ x₅) x₆) min = refl min-fixed-ana (AASubsume x x₁ (SAZipApArr x₂ x₃ x₄ x₅ x₆) x₇) min with min-fixed-synth x₅ min ... | qq with min-synth x₅ ... | (e'' , d' , min') = ap1 (λ q → q ∘₁ _) qq min-fixed-ana (AASubsume x x₁ (SAZipApAna x₂ x₃ x₄) x₅) min with min-fixed-ana x₄ min ... | qq with min-ana x₄ ... | (e'' , _ , _) = ap1 (λ q → _ ∘₂ q) qq min-fixed-ana (AASubsume x x₁ (SAZipPlus1 x₂) x₃) min with min-fixed-ana x₂ min ... | qq with min-ana x₂ ... | (e'' , _ , _) = ap1 (λ q → q ·+₁ _) qq min-fixed-ana (AASubsume x x₁ (SAZipPlus2 x₂) x₃) min with min-fixed-ana x₂ min ... | qq with min-ana x₂ ... | (e'' , _ , _) = ap1 (λ q → _ ·+₂ q) qq min-fixed-ana (AASubsume x x₁ (SAZipHole x₂ x₃ x₄) x₅) min with min-fixed-synth x₄ min ... | qq with min-synth x₄ ... | (e'' , _ , _) = ap1 ⦇⌜_⌟⦈ qq min-fixed-ana (AAMove x) min = refl min-fixed-ana AADel min = refl min-fixed-ana AAConAsc min = refl min-fixed-ana (AAConVar x₁ p) min = refl min-fixed-ana (AAConLam1 x₁ x₂) min = refl min-fixed-ana (AAConLam2 x₁ x₂) min = refl min-fixed-ana (AAConNumlit x) min = refl min-fixed-ana (AAFinish x) min = refl min-fixed-ana (AAZipLam x₁ x₂ d) min with min-fixed-ana d min ... | qq with min-ana d ... | (e'' , _ , _) = ap1 (λ q → ·λ _ q) qq
{ "alphanum_fraction": 0.5796562935, "avg_line_length": 50.3037383178, "ext": "agda", "hexsha": "e7b28ff905711006892aacc875767434e75fb1da", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-07-03T03:45:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-07-03T03:45:07.000Z", "max_forks_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/agda-popl17", "max_forks_repo_path": "aasubsume-min.agda", "max_issues_count": 37, "max_issues_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_issues_repo_issues_event_max_datetime": "2016-11-09T18:13:55.000Z", "max_issues_repo_issues_event_min_datetime": "2016-07-07T16:23:11.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hazelgrove/agda-popl17", "max_issues_repo_path": "aasubsume-min.agda", "max_line_length": 119, "max_stars_count": 14, "max_stars_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/agda-popl17", "max_stars_repo_path": "aasubsume-min.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-11T12:30:50.000Z", "max_stars_repo_stars_event_min_datetime": "2016-07-01T22:44:11.000Z", "num_tokens": 4640, "size": 10765 }
module Basic.Compiler.Test where open import Basic.AST open import Basic.Compiler.Code open import Basic.Compiler.Machine open import Basic.BigStep open import Data.Fin open import Data.Nat open import Data.Vec open import Data.Product open import Data.Bool open import Data.List open Basic.BigStep.Fac {- Just a sandbox for testing the interpreters in Compiler.Machine -} fac' : Code 3 fac' = 𝓒⟦ fac ⟧ˢ test = trace fac' [] (1 ∷ 0 ∷ 0 ∷ []) 1000 -- normal form of "test" -- (PUSH 0 ∷ -- STORE (suc zero) ∷ -- PUSH 1 ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , [] , 1 ∷ 0 ∷ 0 ∷ []) -- ∷ -- (STORE (suc zero) ∷ -- PUSH 1 ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , nat 0 ∷ [] , 1 ∷ 0 ∷ 0 ∷ []) -- ∷ -- (PUSH 1 ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , [] , 1 ∷ 0 ∷ 0 ∷ []) -- ∷ -- (STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , nat 1 ∷ [] , 1 ∷ 0 ∷ 0 ∷ []) -- ∷ -- (LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , [] , 1 ∷ 0 ∷ 1 ∷ []) -- ∷ -- (FETCH zero ∷ -- FETCH (suc zero) ∷ -- LT ∷ -- BRANCH -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ []) -- (NOOP ∷ []) -- ∷ [] -- , [] , 1 ∷ 0 ∷ 1 ∷ []) -- ∷ -- (FETCH (suc zero) ∷ -- LT ∷ -- BRANCH -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ []) -- (NOOP ∷ []) -- ∷ [] -- , nat 1 ∷ [] , 1 ∷ 0 ∷ 1 ∷ []) -- ∷ -- (LT ∷ -- BRANCH -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ []) -- (NOOP ∷ []) -- ∷ [] -- , nat 0 ∷ nat 1 ∷ [] , 1 ∷ 0 ∷ 1 ∷ []) -- ∷ -- (BRANCH -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ []) -- (NOOP ∷ []) -- ∷ [] -- , bool true ∷ [] , 1 ∷ 0 ∷ 1 ∷ []) -- ∷ -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , [] , 1 ∷ 0 ∷ 1 ∷ []) -- ∷ -- (PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , nat 0 ∷ [] , 1 ∷ 0 ∷ 1 ∷ []) -- ∷ -- (ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , nat 1 ∷ nat 0 ∷ [] , 1 ∷ 0 ∷ 1 ∷ []) -- ∷ -- (STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , nat 1 ∷ [] , 1 ∷ 0 ∷ 1 ∷ []) -- ∷ -- (FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , [] , 1 ∷ 1 ∷ 1 ∷ []) -- ∷ -- (FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , nat 1 ∷ [] , 1 ∷ 1 ∷ 1 ∷ []) -- ∷ -- (MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , nat 1 ∷ nat 1 ∷ [] , 1 ∷ 1 ∷ 1 ∷ []) -- ∷ -- (STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , nat 1 ∷ [] , 1 ∷ 1 ∷ 1 ∷ []) -- ∷ -- (LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ [] -- , [] , 1 ∷ 1 ∷ 1 ∷ []) -- ∷ -- (FETCH zero ∷ -- FETCH (suc zero) ∷ -- LT ∷ -- BRANCH -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ []) -- (NOOP ∷ []) -- ∷ [] -- , [] , 1 ∷ 1 ∷ 1 ∷ []) -- ∷ -- (FETCH (suc zero) ∷ -- LT ∷ -- BRANCH -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ []) -- (NOOP ∷ []) -- ∷ [] -- , nat 1 ∷ [] , 1 ∷ 1 ∷ 1 ∷ []) -- ∷ -- (LT ∷ -- BRANCH -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ []) -- (NOOP ∷ []) -- ∷ [] -- , nat 1 ∷ nat 1 ∷ [] , 1 ∷ 1 ∷ 1 ∷ []) -- ∷ -- (BRANCH -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ -- MUL ∷ -- STORE (suc (suc zero)) ∷ -- LOOP (FETCH zero ∷ FETCH (suc zero) ∷ LT ∷ []) -- (FETCH (suc zero) ∷ -- PUSH 1 ∷ -- ADD ∷ -- STORE (suc zero) ∷ -- FETCH (suc (suc zero)) ∷ -- FETCH (suc zero) ∷ MUL ∷ STORE (suc (suc zero)) ∷ []) -- ∷ []) -- (NOOP ∷ []) -- ∷ [] -- , bool false ∷ [] , 1 ∷ 1 ∷ 1 ∷ []) -- ∷ -- (NOOP ∷ [] , [] , 1 ∷ 1 ∷ 1 ∷ []) ∷ ([] , [] , 1 ∷ 1 ∷ 1 ∷ []) ∷ []
{ "alphanum_fraction": 0.4421984266, "avg_line_length": 22.9949748744, "ext": "agda", "hexsha": "c595a1600fa3affd9c078bb951605eae73d5a95c", "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": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_forks_repo_path": "Basic/Compiler/Test.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "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": "AndrasKovacs/SemanticsWithApplications", "max_issues_repo_path": "Basic/Compiler/Test.agda", "max_line_length": 70, "max_stars_count": 8, "max_stars_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_stars_repo_path": "Basic/Compiler/Test.agda", "max_stars_repo_stars_event_max_datetime": "2020-02-02T10:01:52.000Z", "max_stars_repo_stars_event_min_datetime": "2016-09-12T04:25:39.000Z", "num_tokens": 4401, "size": 9152 }
module List.Permutation.Base.Preorder (A : Set) where open import List.Permutation.Base A open import List.Permutation.Base.Equivalence A open import Data.List open import Relation.Binary open import Relation.Binary.PropositionalEquality hiding ([_]) ∼-preorder : Preorder _ _ _ ∼-preorder = record { Carrier = List A; _≈_ = _≡_; _∼_ = _∼_; isPreorder = record { isEquivalence = Relation.Binary.Setoid.isEquivalence (setoid (List A)) ; reflexive = reflexive-aux; trans = trans∼ } } where reflexive-aux : {i j : List A} → i ≡ j → i ∼ j reflexive-aux {i = i} {j = .i} refl = refl∼
{ "alphanum_fraction": 0.4982035928, "avg_line_length": 34.7916666667, "ext": "agda", "hexsha": "aa638665904a0b888a49eae043b55a736a9b437b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_path": "agda/List/Permutation/Base/Preorder.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bgbianchi/sorting", "max_issues_repo_path": "agda/List/Permutation/Base/Preorder.agda", "max_line_length": 106, "max_stars_count": 6, "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_path": "agda/List/Permutation/Base/Preorder.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "num_tokens": 202, "size": 835 }
-- div shouldn't termination check, but it also shouldn't make the termination -- checker loop. module Issue503 where data Bool : Set where true : Bool false : Bool if_then_else_ : {C : Set} -> Bool -> C -> C -> C if true then a else b = a if false then a else b = b data Nat : Set where zero : Nat succ : Nat -> Nat pred : Nat -> Nat pred zero = zero pred (succ n) = n _+_ : Nat -> Nat -> Nat zero + b = b succ a + b = succ (a + b) _*_ : Nat -> Nat -> Nat zero * _ = zero succ a * b = (a * b) + b {-# BUILTIN NATURAL Nat #-} {-# BUILTIN ZERO zero #-} {-# BUILTIN SUC succ #-} {-# BUILTIN NATPLUS _+_ #-} {-# BUILTIN NATTIMES _*_ #-} _-_ : Nat -> Nat -> Nat a - zero = a a - succ b = pred (a - b) _<_ : Nat -> Nat -> Bool a < zero = false zero < succ b = true succ a < succ b = a < b div : Nat -> Nat -> Nat div m n = if (m < n) then zero else succ (div (m - n) n)
{ "alphanum_fraction": 0.570781427, "avg_line_length": 19.1956521739, "ext": "agda", "hexsha": "59945a9d43a0c12fb38fbbe1f82be6bc31ad1dcf", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "test/fail/Issue503.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "test/fail/Issue503.agda", "max_line_length": 78, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/Issue503.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": 294, "size": 883 }
module rewriting where open import lib open import cedille-types open import conversion open import ctxt open import general-util open import is-free open import lift open import rename open import subst open import syntax-util private mk-phi : var → (eq t t' : term) → term mk-phi x eq t t' = Phi posinfo-gen (Rho posinfo-gen RhoPlain NoNums eq (Guide posinfo-gen x (TpEq posinfo-gen t t' posinfo-gen)) (Beta posinfo-gen (SomeTerm t posinfo-gen) (SomeTerm id-term posinfo-gen))) t t' posinfo-gen head-types-match : ctxt → trie term → (complete partial : type) → 𝔹 head-types-match Γ σ (TpApp T _) (TpApp T' _) = conv-type Γ T (substs Γ σ T') head-types-match Γ σ (TpAppt T _) (TpAppt T' _) = conv-type Γ T (substs Γ σ T') head-types-match Γ σ T T' = tt rewrite-t : Set → Set rewrite-t T = ctxt → (is-plus : 𝔹) → (nums : maybe stringset) → (eq left : term) → (right : var) → (total-matches : ℕ) → T {- Returned value -} × ℕ {- Number of rewrites actually performed -} × ℕ {- Total number of matches, including skipped ones -} infixl 4 _≫rewrite_ _≫rewrite_ : ∀ {A B : Set} → rewrite-t (A → B) → rewrite-t A → rewrite-t B (f ≫rewrite a) Γ op on eq t₁ t₂ n with f Γ op on eq t₁ t₂ n ...| f' , n' , sn with a Γ op on eq t₁ t₂ sn ...| b , n'' , sn' = f' b , n' + n'' , sn' rewriteR : ∀ {A : Set} → A → rewrite-t A rewriteR a Γ op on eq t₁ t₂ n = a , 0 , n {-# TERMINATING #-} rewrite-term : term → rewrite-t term rewrite-terma : term → rewrite-t term rewrite-termh : term → rewrite-t term rewrite-type : type → rewrite-t type rewrite-typeh : type → rewrite-t type rewrite-kind : kind → rewrite-t kind rewrite-tk : tk → rewrite-t tk rewrite-liftingType : liftingType → rewrite-t liftingType rewrite-rename-var : ∀ {A} → var → (var → rewrite-t A) → rewrite-t A rewrite-rename-var x r Γ op on eq t₁ t₂ n = let x' = rename-var-if Γ (renamectxt-insert empty-renamectxt t₂ t₂) x t₁ in r x' Γ op on eq t₁ t₂ n rewrite-abs : ∀ {ed} → var → var → (⟦ ed ⟧ → rewrite-t ⟦ ed ⟧) → ⟦ ed ⟧ → rewrite-t ⟦ ed ⟧ rewrite-abs x x' g a Γ = let Γ = ctxt-var-decl x' Γ in g (rename-var Γ x x' a) Γ rewrite-term t Γ op on eq t₁ t₂ sn = case rewrite-terma (erase-term t) Γ op on eq t₁ t₂ sn of λ where (t' , 0 , sn') → t , 0 , sn' (t' , n , sn') → mk-phi t₂ eq t t' , n , sn' rewrite-terma t Γ op on eq t₁ t₂ sn = case conv-term Γ t₁ t of λ where tt → case on of λ where (just ns) → case trie-contains ns (ℕ-to-string (suc sn)) of λ where tt → Var posinfo-gen t₂ , 1 , suc sn -- ρ nums contains n ff → t , 0 , suc sn -- ρ nums does not contain n nothing → Var posinfo-gen t₂ , 1 , suc sn ff → case op of λ where tt → case rewrite-termh (hnf Γ unfold-head t tt) Γ op on eq t₁ t₂ sn of λ where (t' , 0 , sn') → t , 0 , sn' -- if no rewrites were performed, return the pre-hnf t (t' , n' , sn') → t' , n' , sn' ff → rewrite-termh t Γ op on eq t₁ t₂ sn rewrite-termh (App t e t') = rewriteR App ≫rewrite rewrite-terma t ≫rewrite rewriteR e ≫rewrite rewrite-terma t' rewrite-termh (Lam pi NotErased pi' y NoClass t) = rewrite-rename-var y λ y' → rewriteR (Lam pi NotErased pi' y' NoClass) ≫rewrite rewrite-abs y y' rewrite-terma t rewrite-termh (Var pi x) = rewriteR (Var pi x) rewrite-termh = rewriteR rewrite-type T Γ tt on eq t₁ t₂ sn with rewrite-typeh (hnf Γ unfold-head-no-lift T tt) Γ tt on eq t₁ t₂ sn ...| T' , 0 , sn' = T , 0 , sn' ...| T' , n , sn' = T' , n , sn' rewrite-type = rewrite-typeh rewrite-typeh (Abs pi b pi' x atk T) = rewrite-rename-var x λ x' → rewriteR (Abs pi b pi' x') ≫rewrite rewrite-tk atk ≫rewrite rewrite-abs x x' rewrite-type T rewrite-typeh (Iota pi pi' x T T') = rewrite-rename-var x λ x' → rewriteR (Iota pi pi' x') ≫rewrite rewrite-type T ≫rewrite rewrite-abs x x' rewrite-type T' rewrite-typeh (Lft pi pi' x t l) = rewrite-rename-var x λ x' → rewriteR (Lft pi pi' x') ≫rewrite rewrite-abs x x' rewrite-term t ≫rewrite rewrite-liftingType l rewrite-typeh (TpApp T T') = rewriteR TpApp ≫rewrite rewrite-typeh T ≫rewrite rewrite-type T' rewrite-typeh (TpAppt T t) = rewriteR TpAppt ≫rewrite rewrite-typeh T ≫rewrite rewrite-term t rewrite-typeh (TpEq pi t₁ t₂ pi') = rewriteR (TpEq pi) ≫rewrite rewrite-term t₁ ≫rewrite rewrite-term t₂ ≫rewrite rewriteR pi' rewrite-typeh (TpLambda pi pi' x atk T) = rewrite-rename-var x λ x' → rewriteR (TpLambda pi pi' x') ≫rewrite rewrite-tk atk ≫rewrite rewrite-abs x x' rewrite-type T rewrite-typeh (TpArrow T a T') = rewriteR TpArrow ≫rewrite rewrite-type T ≫rewrite rewriteR a ≫rewrite rewrite-type T' rewrite-typeh (TpLet pi (DefTerm pi' x T t) T') Γ = rewrite-type (subst Γ (Chi posinfo-gen T t) x T') Γ rewrite-typeh (TpLet pi (DefType pi' x k T) T') Γ = rewrite-type (subst Γ T x T') Γ rewrite-typeh (TpParens _ T _) = rewrite-type T rewrite-typeh (NoSpans T _) = rewrite-type T rewrite-typeh (TpHole pi) = rewriteR (TpHole pi) rewrite-typeh (TpVar pi x) = rewriteR (TpVar pi x) -- If we ever implement kind-level rewriting, we will need to go through -- all the types of kind pi binding a term or type-to-kind arrow -- if the right-hand side variable is free in the types of the bound variable, -- and substitute each occurence of the term variable (eta-expanding if necessary) -- in the body of the type with itself surrounded by a rewrite back the original -- expected type (unless we lifted a term, then it gets really tricky because -- we may not want to rewrite back?). rewrite-kind = rewriteR rewrite-liftingType = rewriteR rewrite-tk (Tkt T) = rewriteR Tkt ≫rewrite rewrite-type T rewrite-tk (Tkk k) = rewriteR Tkk ≫rewrite rewrite-kind k post-rewriteh : ctxt → var → term → (ctxt → var → term → tk → tk) → (var → tk → ctxt → ctxt) → type → type × kind post-rewriteh Γ x eq prtk tk-decl (Abs pi b pi' x' atk T) = let atk' = prtk Γ x eq atk in Abs pi b pi' x' atk' (fst (post-rewriteh (tk-decl x' atk' Γ) x eq prtk tk-decl T)) , star post-rewriteh Γ x eq prtk tk-decl (Iota pi pi' x' T T') = let T = fst (post-rewriteh Γ x eq prtk tk-decl T) in Iota pi pi' x' T (fst (post-rewriteh (tk-decl x' (Tkt T) Γ) x eq prtk tk-decl T')) , star post-rewriteh Γ x eq prtk tk-decl (Lft pi pi' x' t lT) = Lft pi pi' x' t lT , liftingType-to-kind lT post-rewriteh Γ x eq prtk tk-decl (TpApp T T') = flip uncurry (post-rewriteh Γ x eq prtk tk-decl T') λ T' k' → flip uncurry (post-rewriteh Γ x eq prtk tk-decl T) λ where T (KndPi pi pi' x' atk k) → TpApp T T' , hnf Γ unfold-head-no-lift (subst Γ T' x' k) tt T (KndArrow k k'') → TpApp T T' , hnf Γ unfold-head-no-lift k'' tt T k → TpApp T T' , k post-rewriteh Γ x eq prtk tk-decl (TpAppt T t) = let t2 T' = if is-free-in check-erased x T' then Rho posinfo-gen RhoPlain NoNums eq (Guide posinfo-gen x T') t else t in flip uncurry (post-rewriteh Γ x eq prtk tk-decl T) λ where T (KndPi pi pi' x' (Tkt T') k) → let t3 = t2 T' in TpAppt T t3 , hnf Γ unfold-head-no-lift (subst Γ t3 x' k) tt T (KndTpArrow T' k) → TpAppt T (t2 T') , hnf Γ unfold-head-no-lift k tt T k → TpAppt T t , k post-rewriteh Γ x eq prtk tk-decl (TpArrow T a T') = TpArrow (fst (post-rewriteh Γ x eq prtk tk-decl T)) a (fst (post-rewriteh Γ x eq prtk tk-decl T')) , star post-rewriteh Γ x eq prtk tk-decl (TpLambda pi pi' x' atk T) = let atk' = prtk Γ x eq atk in flip uncurry (post-rewriteh (tk-decl x' atk' Γ) x eq prtk tk-decl T) λ T k → TpLambda pi pi' x' atk' T , KndPi pi pi' x' atk' k post-rewriteh Γ x eq prtk tk-decl (TpParens pi T pi') = post-rewriteh Γ x eq prtk tk-decl T post-rewriteh Γ x eq prtk tk-decl (TpVar pi x') with env-lookup Γ x' ...| just (type-decl k , _) = mtpvar x' , hnf Γ unfold-head-no-lift k tt ...| just (type-def nothing _ T k , _) = mtpvar x' , hnf Γ unfold-head-no-lift k tt ...| just (type-def (just ps) _ T k , _) = mtpvar x' , abs-expand-kind ps (hnf Γ unfold-head-no-lift k tt) ...| _ = mtpvar x' , star post-rewriteh Γ x eq prtk tk-decl T = T , star {-# TERMINATING #-} post-rewrite : ctxt → var → (eq t₂ : term) → type → type post-rewrite Γ x eq t₂ T = subst Γ t₂ x (fst (post-rewriteh Γ x eq prtk tk-decl T)) where prtk : ctxt → var → term → tk → tk tk-decl : var → tk → ctxt → ctxt prtk Γ x t (Tkt T) = Tkt (fst (post-rewriteh Γ x t prtk tk-decl T)) prtk Γ x t (Tkk k) = Tkk (hnf Γ unfold-head-no-lift k tt) tk-decl x atk (mk-ctxt mod ss is os d) = mk-ctxt mod ss (trie-insert is x (h atk , "" , "")) os d where h : tk → ctxt-info h (Tkt T) = term-decl T h (Tkk k) = type-decl k -- Functions for substituting the type T in ρ e @ x . T - t {-# TERMINATING #-} rewrite-at : ctxt → var → term → 𝔹 → type → type → type rewrite-ath : ctxt → var → term → 𝔹 → type → type → type rewrite-at-tk : ctxt → var → term → 𝔹 → tk → tk → tk rewrite-at-tk Γ x eq b (Tkt T) (Tkt T') = Tkt (rewrite-at Γ x eq b T T') rewrite-at-tk Γ x eq b atk atk' = atk rewrite-at Γ x eq b T T' = if ~ is-free-in tt x T' then T else if b && ~ head-types-match Γ (trie-single x (Hole posinfo-gen)) T T' then rewrite-ath Γ x eq ff (hnf Γ unfold-head-no-lift T tt) (hnf Γ unfold-head-no-lift T' tt) else rewrite-ath Γ x eq b T T' rewrite-ath Γ x eq b (Abs pi1 b1 pi1' x1 atk1 T1) (Abs pi2 b2 pi2' x2 atk2 T2) = Abs pi1 b1 pi1' x1 (rewrite-at-tk Γ x eq tt atk1 atk2) (rewrite-at (ctxt-var-decl x1 Γ) x eq b T1 (rename-var Γ x2 x1 T2)) rewrite-ath Γ x eq b (Iota pi1 pi1' x1 T1 T1') (Iota pi2 pi2' x2 T2 T2') = Iota pi1 pi1' x1 (rewrite-at Γ x eq tt T1 T2) (rewrite-at (ctxt-var-decl x1 Γ) x eq b T1' (rename-var Γ x2 x1 T2')) rewrite-ath Γ x eq b (Lft pi1 pi1' x1 t1 lT1) (Lft pi2 pi2' x2 t2 lT2) = Lft pi1 pi1' x1 (if is-free-in tt x (mlam x2 t2) then mk-phi x eq t1 t2 else t1) lT1 rewrite-ath Γ x eq b (TpApp T1 T1') (TpApp T2 T2') = TpApp (rewrite-at Γ x eq b T1 T2) (rewrite-at Γ x eq b T1' T2') rewrite-ath Γ x eq b (TpAppt T1 t1) (TpAppt T2 t2) = TpAppt (rewrite-at Γ x eq b T1 T2) (if is-free-in tt x t2 then mk-phi x eq t1 t2 else t1) rewrite-ath Γ x eq b (TpArrow T1 a1 T1') (TpArrow T2 a2 T2') = TpArrow (rewrite-at Γ x eq tt T1 T2) a1 (rewrite-at Γ x eq tt T1' T2') rewrite-ath Γ x eq b (TpEq pi1 t1 t1' pi1') (TpEq pi2 t2 t2' pi2') = TpEq pi1 t2 t2' pi1' rewrite-ath Γ x eq b (TpLambda pi1 pi1' x1 atk1 T1) (TpLambda pi2 pi2' x2 atk2 T2) = TpLambda pi1 pi1' x1 (rewrite-at-tk Γ x eq tt atk1 atk2) (rewrite-at (ctxt-var-decl x1 Γ) x eq b T1 (rename-var Γ x2 x1 T2)) rewrite-ath Γ x eq b (TpLet pi1 (DefTerm pi1' x1 oc1 t1) T1) T2 = rewrite-at Γ x eq b (subst Γ t1 x1 T1) T2 rewrite-ath Γ x eq b T1 (TpLet pi2 (DefTerm pi2' x2 oc2 t2) T2) = rewrite-at Γ x eq b T1 (subst Γ t2 x2 T2) rewrite-ath Γ x eq b (TpLet pi1 (DefType pi1' x1 k1 T1ₗ) T1) T2 = rewrite-at Γ x eq b (subst Γ T1ₗ x1 T1) T2 rewrite-ath Γ x eq b T1 (TpLet pi2 (DefType pi2' x2 k2 T2ₗ) T2) = rewrite-at Γ x eq b T1 (subst Γ T2ₗ x2 T2) rewrite-ath Γ x eq b (TpVar pi1 x1) (TpVar pi2 x2) = TpVar pi1 x1 rewrite-ath Γ x eq b (TpHole pi1) (TpHole pi2) = TpHole pi1 rewrite-ath Γ x eq b (TpParens pi1 T1 pi1') T2 = rewrite-at Γ x eq b T1 T2 rewrite-ath Γ x eq b T1 (TpParens pi2 T2 pi2') = rewrite-at Γ x eq b T1 T2 rewrite-ath Γ x eq b (NoSpans T1 pi1) T2 = rewrite-at Γ x eq b T1 T2 rewrite-ath Γ x eq b T1 (NoSpans T2 pi2) = rewrite-at Γ x eq b T1 T2 rewrite-ath Γ x eq tt T1 T2 = rewrite-at Γ x eq ff (hnf Γ unfold-head-no-lift T1 tt) (hnf Γ unfold-head-no-lift T2 tt) rewrite-ath Γ x eq ff T1 T2 = T1
{ "alphanum_fraction": 0.6403380185, "avg_line_length": 48.7268907563, "ext": "agda", "hexsha": "6370269840c0a1376e00d480e32dccc0ff398923", "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": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "xoltar/cedille", "max_forks_repo_path": "src/rewriting.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "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": "xoltar/cedille", "max_issues_repo_path": "src/rewriting.agda", "max_line_length": 158, "max_stars_count": null, "max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "xoltar/cedille", "max_stars_repo_path": "src/rewriting.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4350, "size": 11597 }
{-# OPTIONS --cubical --safe --postfix-projections #-} module Lens.Pair where open import Prelude open import Lens.Definition ⦅fst⦆ : Lens (A × B) A ⦅fst⦆ .fst (x , y) = lens-part x (_, y) ⦅fst⦆ .snd .get-set s v i = v ⦅fst⦆ .snd .set-get s i = s ⦅fst⦆ .snd .set-set s v₁ v₂ i = v₂ , s .snd ⦅snd⦆ : Lens (A × B) B ⦅snd⦆ .fst (x , y) = lens-part y (x ,_) ⦅snd⦆ .snd .get-set s v i = v ⦅snd⦆ .snd .set-get s i = s ⦅snd⦆ .snd .set-set s v₁ v₂ i = s .fst , v₂
{ "alphanum_fraction": 0.5739130435, "avg_line_length": 24.2105263158, "ext": "agda", "hexsha": "47ab57c37b65d843c1d4db3efd9e500ba5c92dd8", "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": "Lens/Pair.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": "Lens/Pair.agda", "max_line_length": 54, "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": "Lens/Pair.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": 227, "size": 460 }
{-# OPTIONS --without-K --safe #-} module Categories.Category.Instance.Rels where open import Data.Product open import Function hiding (_⇔_) open import Level open import Relation.Binary open import Relation.Binary.Construct.Composition open import Relation.Binary.PropositionalEquality open import Categories.Category.Core -- the category whose objects are sets and whose morphisms are binary relations. Rels : ∀ o ℓ → Category (suc o) (suc (o ⊔ ℓ)) (o ⊔ ℓ) Rels o ℓ = record { Obj = Set o ; _⇒_ = λ A B → REL A B (o ⊔ ℓ) ; _≈_ = λ L R → L ⇔ R ; id = λ x y → Lift ℓ (x ≡ y) ; _∘_ = λ L R → R ; L ; assoc = (λ { (b , fxb , c , gbc , hcy) → c , ((b , (fxb , gbc)) , hcy)}) , λ { (c , (b , fxb , gbc) , hcy) → b , fxb , c , gbc , hcy} ; sym-assoc = (λ { (c , (b , fxb , gbc) , hcy) → b , fxb , c , gbc , hcy}) , (λ { (b , fxb , c , gbc , hcy) → c , ((b , (fxb , gbc)) , hcy)}) ; identityˡ = (λ { (b , fxb , lift refl) → fxb}) , λ {_} {y} fxy → y , fxy , lift refl ; identityʳ = (λ { (a , lift refl , fxy) → fxy}) , λ {x} {_} fxy → x , lift refl , fxy ; identity² = (λ { (_ , lift p , lift q) → lift (trans p q)}) , λ { (lift refl) → _ , lift refl , lift refl } ; equiv = record { refl = id , id ; sym = swap ; trans = λ { (p₁ , p₂) (q₁ , q₂) → (q₁ ∘′ p₁) , p₂ ∘′ q₂} } ; ∘-resp-≈ = λ f⇔h g⇔i → (λ { (b , gxb , fky) → b , proj₁ g⇔i gxb , proj₁ f⇔h fky }) , λ { (b , ixb , hby) → b , proj₂ g⇔i ixb , proj₂ f⇔h hby } }
{ "alphanum_fraction": 0.5210984595, "avg_line_length": 40.3513513514, "ext": "agda", "hexsha": "667d1f7883820cbd27eeba3359532dcc3b165c6c", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Category/Instance/Rels.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Category/Instance/Rels.agda", "max_line_length": 111, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Category/Instance/Rels.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": 612, "size": 1493 }
open import Data.Nat using (ℕ; zero; suc) open import Data.Bool using (Bool; true; false) data even : ℕ → Set data odd : ℕ → Set data even where zero : even zero suc : ∀ {n : ℕ} → odd n → even (suc n) data odd where suc : ∀ {n : ℕ} → even n → odd (suc n) mutual data even′ : ℕ → Set where zero : even′ zero suc : ∀ {n : ℕ} → odd′ n → even′ (suc n) data odd′ : ℕ → Set where suc : ∀ {n : ℕ} → even′ n → odd′ (suc n) {- /Users/wadler/sf/src/extra/Mutual.agda:3,6-10 Missing definition for even -}
{ "alphanum_fraction": 0.5823754789, "avg_line_length": 20.88, "ext": "agda", "hexsha": "4c6604d0410449a2b9580418bccc76d69a8d87e5", "lang": "Agda", "max_forks_count": 304, "max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z", "max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z", "max_forks_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "manikdv/plfa.github.io", "max_forks_repo_path": "extra/extra/Mutual.agda", "max_issues_count": 323, "max_issues_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z", "max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z", "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "manikdv/plfa.github.io", "max_issues_repo_path": "extra/extra/Mutual.agda", "max_line_length": 47, "max_stars_count": 1003, "max_stars_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "manikdv/plfa.github.io", "max_stars_repo_path": "extra/extra/Mutual.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z", "max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z", "num_tokens": 194, "size": 522 }
{-# OPTIONS --without-K --exact-split #-} module 03-natural-numbers where import 02-pi open 02-pi public -- Section 3.1 The formal specification of the type of natural numbers data ℕ : UU lzero where zero-ℕ : ℕ succ-ℕ : ℕ → ℕ {- We define the numbers one-ℕ to ten-ℕ -} one-ℕ : ℕ one-ℕ = succ-ℕ zero-ℕ two-ℕ : ℕ two-ℕ = succ-ℕ one-ℕ three-ℕ : ℕ three-ℕ = succ-ℕ two-ℕ four-ℕ : ℕ four-ℕ = succ-ℕ three-ℕ five-ℕ : ℕ five-ℕ = succ-ℕ four-ℕ six-ℕ : ℕ six-ℕ = succ-ℕ five-ℕ seven-ℕ : ℕ seven-ℕ = succ-ℕ six-ℕ eight-ℕ : ℕ eight-ℕ = succ-ℕ seven-ℕ nine-ℕ : ℕ nine-ℕ = succ-ℕ eight-ℕ ten-ℕ : ℕ ten-ℕ = succ-ℕ nine-ℕ -- Remark 3.1.2 ind-ℕ : {i : Level} {P : ℕ → UU i} → P zero-ℕ → ((n : ℕ) → P n → P(succ-ℕ n)) → ((n : ℕ) → P n) ind-ℕ p0 pS zero-ℕ = p0 ind-ℕ p0 pS (succ-ℕ n) = pS n (ind-ℕ p0 pS n) -- Section 3.2 Addition on the natural numbers -- Definition 3.2.1 add-ℕ : ℕ → ℕ → ℕ add-ℕ x zero-ℕ = x add-ℕ x (succ-ℕ y) = succ-ℕ (add-ℕ x y) add-ℕ' : ℕ → ℕ → ℕ add-ℕ' m n = add-ℕ n m -- Exercises -- Exercise 3.1 min-ℕ : ℕ → (ℕ → ℕ) min-ℕ zero-ℕ n = zero-ℕ min-ℕ (succ-ℕ m) zero-ℕ = zero-ℕ min-ℕ (succ-ℕ m) (succ-ℕ n) = succ-ℕ (min-ℕ m n) max-ℕ : ℕ → (ℕ → ℕ) max-ℕ zero-ℕ n = n max-ℕ (succ-ℕ m) zero-ℕ = succ-ℕ m max-ℕ (succ-ℕ m) (succ-ℕ n) = succ-ℕ (max-ℕ m n) -- Exercise 3.2 mul-ℕ : ℕ → (ℕ → ℕ) mul-ℕ zero-ℕ n = zero-ℕ mul-ℕ (succ-ℕ m) n = add-ℕ (mul-ℕ m n) n -- Exercise 3.3 pow-ℕ : ℕ → (ℕ → ℕ) pow-ℕ m zero-ℕ = one-ℕ pow-ℕ m (succ-ℕ n) = mul-ℕ m (pow-ℕ m n) -- Exercise 3.4 factorial : ℕ → ℕ factorial zero-ℕ = one-ℕ factorial (succ-ℕ m) = mul-ℕ (succ-ℕ m) (factorial m) -- Exercise 3.5 _choose_ : ℕ → ℕ → ℕ zero-ℕ choose zero-ℕ = one-ℕ zero-ℕ choose succ-ℕ k = zero-ℕ (succ-ℕ n) choose zero-ℕ = one-ℕ (succ-ℕ n) choose (succ-ℕ k) = add-ℕ (n choose k) (n choose (succ-ℕ k)) -- Exercise 3.6 Fibonacci : ℕ → ℕ Fibonacci zero-ℕ = zero-ℕ Fibonacci (succ-ℕ zero-ℕ) = one-ℕ Fibonacci (succ-ℕ (succ-ℕ n)) = add-ℕ (Fibonacci n) (Fibonacci (succ-ℕ n)) {- The above definition of the Fibonacci sequence uses Agda's rather strong pattern matching definitions. Below, we will give a definition of the Fibonacci sequence in terms of ind-ℕ. In particular, the following is a solution that can be given in terms of the material in the book. The problem with defining the Fibonacci sequence using ind-ℕ, is that ind-ℕ doesn't give us a way to refer to both (F n) and (F (succ-ℕ n)). So, we have to give a workaround, where we store two values in the Fibonacci sequence at once. The basic idea is that we define a sequence of pairs of integers, which will be consecutive Fibonacci numbers. This would be a function of type ℕ → ℕ². Such a function is easy to give with induction, using the map ℕ² → ℕ² that takes a pair (m,n) to the pair (n,n+m). Starting the iteration with (0,1) we obtain the Fibonacci sequence by taking the first projection. However, we haven't defined cartesian products or booleans yet. Therefore we mimic the above idea, using ℕ → ℕ instead of ℕ². -} shift-one : ℕ → (ℕ → ℕ) → (ℕ → ℕ) shift-one n f = ind-ℕ n (λ x y → f x) shift-two : ℕ → ℕ → (ℕ → ℕ) → (ℕ → ℕ) shift-two m n f = shift-one m (shift-one n f) Fibo-zero-ℕ : ℕ → ℕ Fibo-zero-ℕ = shift-two zero-ℕ one-ℕ (const ℕ ℕ zero-ℕ) Fibo-succ-ℕ : (ℕ → ℕ) → (ℕ → ℕ) Fibo-succ-ℕ f = shift-two (f one-ℕ) (add-ℕ (f one-ℕ) (f zero-ℕ)) (λ x → f (succ-ℕ (succ-ℕ x))) Fibo-function : ℕ → ℕ → ℕ Fibo-function = ind-ℕ ( Fibo-zero-ℕ) ( λ n → Fibo-succ-ℕ) Fibo : ℕ → ℕ Fibo k = Fibo-function k zero-ℕ
{ "alphanum_fraction": 0.6241554054, "avg_line_length": 23.0649350649, "ext": "agda", "hexsha": "43ad8cd399399439fe0a0465b075ea40fb227a4f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_path": "Agda/03-natural-numbers.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_path": "Agda/03-natural-numbers.agda", "max_line_length": 95, "max_stars_count": null, "max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "hemangandhi/HoTT-Intro", "max_stars_repo_path": "Agda/03-natural-numbers.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1543, "size": 3552 }
module Basic.Axiomatic.Total where open import Data.Bool hiding (not; if_then_else_; _∧_) open import Data.Vec hiding ([_]; _++_; split) open import Function open import Relation.Binary.PropositionalEquality open import Data.Product renaming (map to prodMap) open import Data.Nat open import Relation.Nullary open import Data.Empty import Level as L open import Utils.Decidable open import Basic.AST open import Basic.BigStep {- Total axiomatic correctness (The first part of chapter 6.4). For general notes on axiomatic correctness see Partial.agda The most interesting part is here is the proof of completeness (exercise 6.33). -} _∧_ : ∀ {α β γ}{A : Set α} → (A → Set β) → (A → Set γ) → (A → Set _) _∧_ f g x = f x × g x _==>_ : ∀ {α β γ}{A : Set α} → (A → Set β) → (A → Set γ) → Set _ _==>_ f g = ∀ {x} → f x → g x infixr 4 _,_ data 〈_〉_〈_〉 {n} : (State n → Set) → St n → (State n → Set) → Set₁ where skip : ∀ {P} → ----------------- 〈 P 〉 skip 〈 P 〉 ass : ∀ {x a P} → ---------------------------------------------- 〈 (λ s → P (s [ x ]≔ ⟦ a ⟧ᵉ s)) 〉 x := a 〈 P 〉 _,_ : ∀ {P Q R S₁ S₂} → 〈 P 〉 S₁ 〈 Q 〉 → 〈 Q 〉 S₂ 〈 R 〉 → -------------------------------- 〈 P 〉 S₁ , S₂ 〈 R 〉 if : ∀ {P Q b S₁ S₂} → 〈 (T ∘ ⟦ b ⟧ᵉ) ∧ P 〉 S₁ 〈 Q 〉 → 〈 (F ∘ ⟦ b ⟧ᵉ) ∧ P 〉 S₂ 〈 Q 〉 → -------------------------------------------------------------- 〈 P 〉 if b then S₁ else S₂ 〈 Q 〉 {- This is the only difference between the partial and total system. The definition is exactly the same as in the book. -} while : ∀ {b S} → (P : ℕ → State n → Set) → (∀ n → P (suc n) ==> (T ∘ ⟦ b ⟧ᵉ)) → (P 0 ==> (F ∘ ⟦ b ⟧ᵉ)) → (∀ n → 〈 P (suc n) 〉 S 〈 P n 〉) → --------------------------------- 〈 (λ s → ∃ λ n → P n s) 〉 while b do S 〈 P 0 〉 cons : ∀ {P' Q' P Q S} → P ==> P' → 〈 P' 〉 S 〈 Q' 〉 → Q' ==> Q → ----------------------------------------- 〈 P 〉 S 〈 Q 〉 -- Weakest precondition ------------------------------------------------------------ wp : ∀ {n} → St n → (State n → Set) → State n → Set wp S Q s = ∃ λ s' → ⟨ S , s ⟩⟱ s' × Q s' -- Soundness ------------------------------------------------------------ {- This is more complicated than the soundess proof for the partial system, because we have to construct an actual big-step derivation. In the "if" case we have to evaluate the branch condition to see whether we should return an "if-true" or an "if-false" derivation. In the "while" case we recurse on the natural number "measure" of the loop, building an appropriately sized derivation for the loop -} sound : ∀ {n}{S : St n}{P Q} → 〈 P 〉 S 〈 Q 〉 → (P ==> wp S Q) sound skip ps = _ , skip , ps sound ass ps = _ , ass , ps sound (p , p₁) ps with sound p ps ... | s' , runp , qs' with sound p₁ qs' ... | s'' , runp₁ , qs'' = s'' , (runp , runp₁) , qs'' sound (if {b = b} p p₁) {s} ps with ⟦ b ⟧ᵉ s | inspect ⟦ b ⟧ᵉ s ... | true | [ b≡true ] = let Tb = ≡true→T b≡true in prodMap id (λ x₁ → (if-true Tb (proj₁ x₁)) , (proj₂ x₁)) (sound p {s} (Tb , ps)) ... | false | [ b≡false ] = let Fb = ≡false→F b≡false in prodMap id (λ x₁ → (if-false Fb (proj₁ x₁)) , (proj₂ x₁)) (sound p₁ {s} (Fb , ps)) sound (while{b = b}{S = S} P pre post decr) {s} (start , ps) = go s start ps where go : ∀ s n → P n s → wp (while b do S) (P 0) s go s zero ps = s , while-false (post ps) , ps go s (suc n) ps with sound (decr n) ps ... | s' , runS , ps' with go s' n ps' ... | s'' , runW , ps'' = s'' , while-true (pre n ps) runS runW , ps'' sound (cons x p x₁) ps with sound p (x ps) ... | s' , runp , qs' = s' , runp , x₁ qs' -- Completeness ------------------------------------------------------------ complete : ∀ {n}(S : St n){P Q} → (P ==> wp S Q) → 〈 P 〉 S 〈 Q 〉 complete (x := exp) {P}{Q} f = cons go ass id where go : P ==> (λ s → Q (s [ x ]≔ ⟦ exp ⟧ᵉ s)) go {s} ps with f ps go ps | ._ , ass , qs' = qs' complete skip {P}{Q} f = cons go skip id where go : P ==> Q go {s} ps with f ps go ps | x , skip , qs' = qs' complete (S , S₁){P}{Q} f = complete S {P} {wp S₁ Q} go , complete S₁ id where go : P ==> wp S (wp S₁ Q) go {s} ps with f ps go {s} ps | s' , (run , run₂) , qs' = _ , run , s' , run₂ , qs' complete (if b then S else S₁){P}{Q} f = if (complete S {(T ∘ ⟦ b ⟧ᵉ) ∧ P} {Q} go1) (complete S₁ {(F ∘ ⟦ b ⟧ᵉ) ∧ P} {Q} go2) where go1 : ((T ∘ ⟦ b ⟧ᵉ) ∧ P) ==> wp S Q go1 {s} (pb , ps) with f ps go1 (pb , ps) | s' , if-true pb' run , qs' = s' , run , qs' go1 (pb , ps) | s' , if-false pb' run , qs' with trans (sym (F→≡false pb')) (T→≡true pb) ... | () go2 : ((F ∘ ⟦ b ⟧ᵉ) ∧ P) ==> wp S₁ Q go2 {s} (pb , ps) with f ps go2 (pb , ps) | s' , if-true pb' run , qs' with trans (sym $ F→≡false pb) (T→≡true pb') ... | () go2 (pb , ps) | s' , if-false pb' run , qs' = s' , run , qs' {- This is the interesting part. I needed to do quite a bit of thinking to get this right. So, we'd like to construct a proof of total corectness given the validity of a Hoare triple. We're much less constrained here than in pretty much all of the other proofs, because our objective is to construct a suitable P *predicate* for the loop body. Recall the axiom for "while" while : ∀ {b S} → (P : ℕ → State n → Set) → (∀ n → P (suc n) ==> (T ∘ ⟦ b ⟧ᵉ)) → (P 0 ==> (F ∘ ⟦ b ⟧ᵉ)) → (∀ n → 〈 P (suc n) 〉 S 〈 P n 〉) → --------------------------------- 〈 (λ s → ∃ λ n → P n s) 〉 while b do S 〈 P 0 〉 -} complete {n}(while b do S){P}{Q} f = cons pre-loop loop post-loop where {- P must decrease on each iteration, and P 0 must imply that the loop has finished, and P (suc n) must imply that the loop's still running. The only sensible choice for the decreasing loop variant is the length of the derivation of the loop: -} loop-size : ∀ {n b s s'}{S : St n} → ⟨ while b do S , s ⟩⟱ s' → ℕ loop-size (while-true x runS runW) = suc (loop-size runW) loop-size (while-false x) = zero {- And now the loop predicate can be defined as: -} P' : ℕ → State n → Set P' n s = ∃₂ λ s' (runW : ⟨ while b do S , s ⟩⟱ s') → (loop-size runW ≡ n) × Q s' {- The construction of the loop body proof is slightly complicated by the fact that if we want to recurse on the measure "n" argument, then we have to unfold the loop derivation two layers deep (because the successor case for indction on "n" implies "(suc (suc n))" value for the derivation length -} body : ∀ n → 〈 P' (suc n) 〉 S 〈 P' n 〉 body n = complete S (go n) where go : ∀ n → P' (suc n) ==> wp S (P' n) go zero (x , while-false x₁ , () , qs') go zero (s''' , while-true x₁ runW (while-true x₂ runW₁ runW₂) , () , qs') go (suc n₂) (x , while-false x₁ , () , qs') go (suc n₂) (s' , while-true x₁ runW (while-false x₂) , () , qs') go zero (s' , while-true x₁ runW (while-false x₂) , psize , qs') = s' , runW , s' , while-false x₂ , refl , qs' go (suc n) {s1} (slast , while-true pb1 runS1 (while-true pb2 runS2 runW2) , psize1 , qslast) with go n (slast , while-true pb2 runS2 runW2 , cong pred psize1 , qslast) ... | s2 , runS3 , s3 , runW3 , psize3 , q3 = _ , runS1 , s3 , (while-true pb2 runS3 runW3) , cong suc psize3 , q3 pre-loop : P ==> (λ s → ∃ λ n → P' n s) pre-loop {s} ps with f ps ... | s' , runW , qs' = loop-size runW , s' , runW , refl , qs' post-loop : P' 0 ==> Q post-loop (s' , while-false pb , psize , qs') = qs' post-loop (s' , while-true pb x₁ x₂ , () , qs') loop : 〈 (λ s → ∃ λ n → P' n s) 〉 while b do S 〈 P' 0 〉 loop = while P' pre post body where pre : ∀ n → P' (suc n) ==> (T ∘ ⟦ b ⟧ᵉ) pre n (s' , while-true pb _ _ , _) = pb pre n (s' , while-false _ , () , qs') post : P' 0 ==> (F ∘ ⟦ b ⟧ᵉ) post (s' , while-true pb runS runW , () , qs') post (s' , while-false pb , refl , qs') = pb
{ "alphanum_fraction": 0.4767110266, "avg_line_length": 33.2648221344, "ext": "agda", "hexsha": "1937ed508e03fd865675c6bd3c795b24e3c589e2", "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": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_forks_repo_path": "Basic/Axiomatic/Total.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "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": "AndrasKovacs/SemanticsWithApplications", "max_issues_repo_path": "Basic/Axiomatic/Total.agda", "max_line_length": 101, "max_stars_count": 8, "max_stars_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_stars_repo_path": "Basic/Axiomatic/Total.agda", "max_stars_repo_stars_event_max_datetime": "2020-02-02T10:01:52.000Z", "max_stars_repo_stars_event_min_datetime": "2016-09-12T04:25:39.000Z", "num_tokens": 3163, "size": 8416 }
{-# OPTIONS --without-K --safe #-} module Categories.Functor.Construction.Limit where open import Function using (_$_) open import Categories.Adjoint open import Categories.Adjoint.Equivalence open import Categories.Adjoint.Properties open import Categories.Category open import Categories.Category.Equivalence open import Categories.Category.Construction.Cones open import Categories.Category.Complete open import Categories.Category.Cocomplete open import Categories.Category.Construction.Functors open import Categories.Functor open import Categories.Functor.Construction.Diagonal open import Categories.Functor.Construction.Constant open import Categories.NaturalTransformation renaming (id to idN) open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_; module ≃) open import Categories.Diagram.Cone.Properties open import Categories.Diagram.Duality import Categories.Diagram.Limit as Lim import Categories.Diagram.Cone as Con import Categories.Morphism.Reasoning as MR module _ {o ℓ e o′ ℓ′ e′} (C : Category o ℓ e) (Com : Complete o′ ℓ′ e′ C) {J : Category o′ ℓ′ e′} where private module C = Category C module J = Category J open C open HomReasoning open Lim.Limit open Con.Cone⇒ renaming (commute to ⇒-commute) open MR C K⇒lim : ∀ {F G : Functor J C} (α : NaturalTransformation F G) (K : Con.Cone F) → Cones G [ nat-map-Cone α K , limit (Com G) ] K⇒lim {G = G} α K = rep-cone (Com G) (nat-map-Cone α K) lim⇒lim : ∀ {F G : Functor J C} (α : NaturalTransformation F G) → Cones G [ nat-map-Cone α (limit (Com F)) , limit (Com G) ] lim⇒lim {F} α = K⇒lim α (limit (Com F)) id-Cone : ∀ X → Con.Cone {C = C} {J = J} (const X) id-Cone X = record { apex = record { ψ = λ _ → C.id ; commute = λ _ → C.identity² } } X⇒limΔ : ∀ X → Cones (const {C = J} X) [ id-Cone X , limit (Com (const X)) ] X⇒limΔ X = rep-cone (Com (const X)) _ LimitF : Functor (Functors J C) C LimitF = record { F₀ = λ F → apex (Com F) ; F₁ = λ {F G} α → arr (lim⇒lim α) ; identity = λ {F} → terminal.!-unique (Com F) $ record { arr = C.id ; commute = id-comm } ; homomorphism = λ {F G H} {α β} → let module α = NaturalTransformation α module β = NaturalTransformation β in terminal.!-unique₂ (Com H) {_} {terminal.! (Com H)} {record { commute = λ {j} → begin proj (Com H) j ∘ arr (lim⇒lim β) ∘ arr (lim⇒lim α) ≈⟨ pullˡ (⇒-commute (lim⇒lim β)) ⟩ (β.η j ∘ proj (Com G) j) ∘ arr (lim⇒lim α) ≈⟨ assoc ⟩ β.η j ∘ proj (Com G) j ∘ arr (lim⇒lim α) ≈⟨ pushʳ (⇒-commute (lim⇒lim α)) ⟩ (β.η j ∘ α.η j) ∘ proj (Com F) j ∎ }} ; F-resp-≈ = λ {F G} {α β} eq → terminal.!-unique (Com G) $ record { commute = ⇒-commute (lim⇒lim β) ○ ∘-resp-≈ˡ (⟺ eq) } } Δ⊣LimitF : ΔF J ⊣ LimitF Δ⊣LimitF = record { unit = ntHelper record { η = λ X → rep (Com (const X)) (id-Cone X) ; commute = λ {X Y} f → terminal.!-unique₂ (Com (const Y)) {record { apex = record { ψ = λ _ → f ; commute = λ _ → C.identityˡ } }} {record { commute = cancelˡ (⇒-commute (X⇒limΔ Y)) }} {record { commute = ⇒-commute (Cones (const Y) [ lim⇒lim (constNat f) ∘ nat-map-Cone⇒ (constNat f) (terminal.! (Com (const X)) {id-Cone X}) ]) ○ identityʳ }} } ; counit = ntHelper record { η = counit-nat ; commute = λ α → ⇒-commute (lim⇒lim α) } ; zig = λ {X} → ⇒-commute (X⇒limΔ X) ; zag = λ {F} → let apF = apex (Com F) align : Cones F [ limit (Com F) , nat-map-Cone (counit-nat F) (id-Cone apF) ] align = record { arr = C.id ; commute = identityʳ ○ identityʳ } limF⇒limF : Cones F [ limit (Com F) , limit (Com F) ] limF⇒limF = Cones F [ Cones F [ lim⇒lim (counit-nat F) ∘ nat-map-Cone⇒ (counit-nat F) (terminal.! (Com (const apF))) ] ∘ align ] in terminal.!-unique₂ (Com F) {limit (Com F)} {record { commute = ∘-resp-≈ʳ (⟺ identityʳ) ○ ⇒-commute limF⇒limF }} {record { commute = identityʳ }} } where counit-nat : (F : Functor J C) → NaturalTransformation (const (apex (Com F))) F counit-nat F = ntHelper record { η = proj (Com F) ; commute = λ f → identityʳ ○ ⟺ (limit-commute (Com F) f) } module _ {o ℓ e o′ ℓ′ e′} (C : Category o ℓ e) (Coc : Cocomplete o′ ℓ′ e′ C) {J : Category o′ ℓ′ e′} where private module C = Category C module J = Category J open C open MR C Com : Complete o′ ℓ′ e′ C.op Com F = Colimit⇒coLimit C (Coc (Functor.op F)) LF : Functor (Functors J.op op) C.op LF = LimitF C.op Com {J.op} ColimitF : Functor (Functors J C) C ColimitF = Functor.op LF ∘F opF⇐ ColimitF⊣Δ : ColimitF ⊣ ΔF J ColimitF⊣Δ = ⊣×≃⇒⊣ helper ≃.refl ΔF≃ where Δ⊣LimitFᵒᵖ : ΔF J.op ⊣ LF Δ⊣LimitFᵒᵖ = Δ⊣LimitF op Com {J.op} opF⊣ : opF⇐ {A = J} {C} ⊣ opF⇒ opF⊣ = StrongEquivalence.F⊣G.R⊣L Functorsᵒᵖ-equiv helper : ColimitF ⊣ opF⇒ ∘F Functor.op (ΔF J.op) helper = opF⊣ ∘⊣ Adjoint.op Δ⊣LimitFᵒᵖ ΔF≃ : opF⇒ ∘F Functor.op (ΔF J.op) ≃ ΔF J ΔF≃ = record { F⇒G = record { η = λ _ → idN ; commute = λ _ → id-comm-sym ; sym-commute = λ _ → id-comm } ; F⇐G = record { η = λ _ → idN ; commute = λ _ → id-comm-sym ; sym-commute = λ _ → id-comm } ; iso = λ X → record { isoˡ = identity² ; isoʳ = identity² } }
{ "alphanum_fraction": 0.5259878669, "avg_line_length": 36.5209580838, "ext": "agda", "hexsha": "6c696a299afae7cbd73504d83824367700204c4f", "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": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Taneb/agda-categories", "max_forks_repo_path": "Categories/Functor/Construction/Limit.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "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": "Taneb/agda-categories", "max_issues_repo_path": "Categories/Functor/Construction/Limit.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Taneb/agda-categories", "max_stars_repo_path": "Categories/Functor/Construction/Limit.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2123, "size": 6099 }
------------------------------------------------------------------------ -- Strong bisimilarity for partially defined values, along with a -- proof showing that this relation is pointwise isomorphic to path -- equality ------------------------------------------------------------------------ {-# OPTIONS --cubical --sized-types #-} module Delay-monad.Bisimilarity.For-all-sizes where open import Equality.Path hiding (ext) open import Prelude open import Prelude.Size open import Bijection equality-with-J using (_↔_) open import Delay-monad private variable a : Level A : Type a x : A i : Size mutual -- A variant of strong bisimilarity that relates values of any size, -- not only those of size ∞. -- -- Note: I have not managed to prove that this relation is pointwise -- isomorphic to strong bisimilarity as defined in -- Delay-monad.Bisimilarity (when the relation is restricted to -- fully defined values). infix 4 [_]_∼ˢ_ [_]_∼ˢ′_ data [_]_∼ˢ_ {A : Type a} (i : Size) : Delay A i → Delay A i → Type a where now : [ i ] now x ∼ˢ now x later : {x y : Delay′ A i} → [ i ] x ∼ˢ′ y → [ i ] later x ∼ˢ later y record [_]_∼ˢ′_ {A : Type a} (i : Size) (x y : Delay′ A i) : Type a where coinductive field force : {j : Size< i} → [ j ] x .force ∼ˢ y .force open [_]_∼ˢ′_ public mutual -- Strong bisimilarity is reflexive. Note that the proof is -- size-preserving. reflexiveˢ : (x : Delay A i) → [ i ] x ∼ˢ x reflexiveˢ (now x) = now reflexiveˢ (later x) = later (reflexiveˢ′ x) reflexiveˢ′ : (x : Delay′ A i) → [ i ] x ∼ˢ′ x reflexiveˢ′ x .force = reflexiveˢ (x .force) mutual -- Extensionality: Strong bisimilarity implies equality. ext : {x y : Delay A i} → [ i ] x ∼ˢ y → x ≡ y ext now = refl ext (later p) = cong later (ext′ p) ext′ : {x y : Delay′ A i} → [ i ] x ∼ˢ′ y → x ≡ y ext′ p i .force = ext (p .force) i mutual -- The extensionality proof maps reflexivity to reflexivity. ext-reflexiveˢ : (x : Delay A i) → ext (reflexiveˢ x) ≡ refl {x = x} ext-reflexiveˢ (now x) = refl ext-reflexiveˢ {i = i} (later x) = ext (reflexiveˢ (later x)) ≡⟨⟩ cong later (ext′ (reflexiveˢ′ x)) ≡⟨ cong (cong later) (ext′-reflexiveˢ′ x) ⟩ cong later refl ≡⟨⟩ refl ∎ ext′-reflexiveˢ′ : (x : Delay′ A i) → ext′ (reflexiveˢ′ x) ≡ refl {x = x} ext′-reflexiveˢ′ x i j .force = ext-reflexiveˢ (x .force) i j -- Equality implies strong bisimilarity. ≡⇒∼ : {x y : Delay A i} → x ≡ y → [ i ] x ∼ˢ y ≡⇒∼ {x = x} eq = subst ([ _ ] x ∼ˢ_) eq (reflexiveˢ x) ≡⇒∼′ : {x y : Delay′ A i} → x ≡ y → [ i ] x ∼ˢ′ y ≡⇒∼′ eq .force = ≡⇒∼ (cong (λ x → x .force) eq) private ≡⇒∼″ : {x y : Delay′ A i} → x ≡ y → [ i ] x ∼ˢ′ y ≡⇒∼″ {x = x} eq = subst ([ _ ] x ∼ˢ′_) eq (reflexiveˢ′ x) -- The three lemmas above map reflexivity to reflexivity. ≡⇒∼-refl : {x : Delay A i} → ≡⇒∼ (refl {x = x}) ≡ reflexiveˢ x ≡⇒∼-refl {x = x} = ≡⇒∼ refl ≡⟨⟩ subst ([ _ ] x ∼ˢ_) refl (reflexiveˢ x) ≡⟨ subst-refl ([ _ ] x ∼ˢ_) (reflexiveˢ x) ⟩∎ reflexiveˢ x ∎ ≡⇒∼′-refl : {x : Delay′ A i} → ≡⇒∼′ (refl {x = x}) ≡ reflexiveˢ′ x ≡⇒∼′-refl i .force = ≡⇒∼-refl i private ≡⇒∼″-refl : {x : Delay′ A i} → ≡⇒∼″ (refl {x = x}) ≡ reflexiveˢ′ x ≡⇒∼″-refl {x = x} = ≡⇒∼″ refl ≡⟨⟩ subst ([ _ ] x ∼ˢ′_) refl (reflexiveˢ′ x) ≡⟨ subst-refl ([ _ ] x ∼ˢ′_) (reflexiveˢ′ x) ⟩∎ reflexiveˢ′ x ∎ -- ≡⇒∼′ and ≡⇒″ are pointwise equal. ≡⇒∼′≡≡⇒∼″ : {x y : Delay′ A i} {eq : x ≡ y} → ≡⇒∼′ eq ≡ ≡⇒∼″ eq ≡⇒∼′≡≡⇒∼″ = elim (λ eq → ≡⇒∼′ eq ≡ ≡⇒∼″ eq) (λ x → ≡⇒∼′ refl ≡⟨ ≡⇒∼′-refl ⟩ reflexiveˢ′ x ≡⟨ sym ≡⇒∼″-refl ⟩∎ ≡⇒∼″ refl ∎) _ private -- Extensionality and ≡⇒∼/≡⇒∼′ are inverses. ext∘≡⇒∼ : {x y : Delay A i} (eq : x ≡ y) → ext (≡⇒∼ eq) ≡ eq ext∘≡⇒∼ = elim (λ eq → ext (≡⇒∼ eq) ≡ eq) (λ x → ext (≡⇒∼ refl) ≡⟨ cong ext ≡⇒∼-refl ⟩ ext (reflexiveˢ x) ≡⟨ ext-reflexiveˢ x ⟩∎ refl ∎) ext′∘≡⇒∼′ : {x y : Delay′ A i} (eq : x ≡ y) → ext′ (≡⇒∼′ eq) ≡ eq ext′∘≡⇒∼′ = elim (λ eq → ext′ (≡⇒∼′ eq) ≡ eq) (λ x → ext′ (≡⇒∼′ refl) ≡⟨ cong ext′ ≡⇒∼′-refl ⟩ ext′ (reflexiveˢ′ x) ≡⟨ ext′-reflexiveˢ′ x ⟩∎ refl ∎) mutual ≡⇒∼∘ext : {x y : Delay A i} (eq : [ i ] x ∼ˢ y) → ≡⇒∼ (ext eq) ≡ eq ≡⇒∼∘ext now = ≡⇒∼ (ext now) ≡⟨⟩ ≡⇒∼ refl ≡⟨ ≡⇒∼-refl ⟩∎ now ∎ ≡⇒∼∘ext (later {x = x} {y = y} p) = ≡⇒∼ (ext (later p)) ≡⟨⟩ ≡⇒∼ (cong later (ext′ p)) ≡⟨⟩ subst ([ _ ] later x ∼ˢ_) (cong later (ext′ p)) (later (reflexiveˢ′ x)) ≡⟨ sym $ subst-∘ ([ _ ] later x ∼ˢ_) later _ {p = later (reflexiveˢ′ x)} ⟩ subst (λ y → [ _ ] later x ∼ˢ later y) (ext′ p) (later (reflexiveˢ′ x)) ≡⟨ elim¹ (λ eq → subst (λ y → [ _ ] later x ∼ˢ later y) eq (later (reflexiveˢ′ x)) ≡ later (subst ([ _ ] x ∼ˢ′_) eq (reflexiveˢ′ x))) ( subst (λ y → [ _ ] later x ∼ˢ later y) refl (later (reflexiveˢ′ x)) ≡⟨ subst-refl (λ y → [ _ ] later x ∼ˢ later y) _ ⟩ later (reflexiveˢ′ x) ≡⟨ cong later $ sym $ subst-refl ([ _ ] x ∼ˢ′_) _ ⟩∎ later (subst ([ _ ] x ∼ˢ′_) refl (reflexiveˢ′ x)) ∎) (ext′ p) ⟩ later (subst ([ _ ] x ∼ˢ′_) (ext′ p) (reflexiveˢ′ x)) ≡⟨⟩ later (≡⇒∼″ (ext′ p)) ≡⟨ cong later $ sym ≡⇒∼′≡≡⇒∼″ ⟩ later (≡⇒∼′ (ext′ p)) ≡⟨ cong later (≡⇒∼′∘ext′ p) ⟩∎ later p ∎ ≡⇒∼′∘ext′ : {x y : Delay′ A i} (eq : [ i ] x ∼ˢ′ y) → ≡⇒∼′ (ext′ eq) ≡ eq ≡⇒∼′∘ext′ eq i .force = ≡⇒∼∘ext (eq .force) i -- Strong bisimilarity and equality are pointwise isomorphic. ∼↔≡ : {x y : Delay A i} → [ i ] x ∼ˢ y ↔ x ≡ y ∼↔≡ = record { surjection = record { logical-equivalence = record { to = ext ; from = ≡⇒∼ } ; right-inverse-of = ext∘≡⇒∼ } ; left-inverse-of = ≡⇒∼∘ext } ∼′↔≡ : {x y : Delay′ A i} → [ i ] x ∼ˢ′ y ↔ x ≡ y ∼′↔≡ = record { surjection = record { logical-equivalence = record { to = ext′ ; from = ≡⇒∼′ } ; right-inverse-of = ext′∘≡⇒∼′ } ; left-inverse-of = ≡⇒∼′∘ext′ }
{ "alphanum_fraction": 0.4276306371, "avg_line_length": 29.4725738397, "ext": "agda", "hexsha": "994d4ba1f3799d16e280b203e2481e725304ba69", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/delay-monad", "max_forks_repo_path": "src/Delay-monad/Bisimilarity/For-all-sizes.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/delay-monad", "max_issues_repo_path": "src/Delay-monad/Bisimilarity/For-all-sizes.agda", "max_line_length": 141, "max_stars_count": null, "max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/delay-monad", "max_stars_repo_path": "src/Delay-monad/Bisimilarity/For-all-sizes.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3001, "size": 6985 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import homotopy.FunctionOver open import groups.ProductRepr open import cohomology.Theory open import cohomology.WedgeCofiber {- For the cohomology group of a suspension ΣX, the group inverse has the - explicit form Cⁿ(flip-susp) : Cⁿ(ΣX) → Cⁿ(ΣX). -} module cohomology.InverseInSusp {i} (CT : CohomologyTheory i) (n : ℤ) {X : Ptd i} where open CohomologyTheory CT open import cohomology.Functor CT open import cohomology.BaseIndependence CT open import cohomology.Wedge CT private module CW = CWedge n (⊙Susp X) (⊙Susp X) module Subtract = SuspRec {C = fst (⊙Susp X ⊙∨ ⊙Susp X)} (winl south) (winr south) (λ x → ap winl (! (merid x)) ∙ wglue ∙ ap winr (merid x)) subtract = Subtract.f ⊙subtract : ⊙Susp X ⊙→ ⊙Susp X ⊙∨ ⊙Susp X ⊙subtract = (subtract , ! (ap winl (merid (pt X)))) projl-subtract : ∀ σ → projl _ _ (subtract σ) == Susp-flip σ projl-subtract = Susp-elim idp idp $ ↓-='-from-square ∘ vert-degen-square ∘ λ x → ap-∘ (projl _ _) subtract (merid x) ∙ ap (ap (projl _ _)) (Subtract.merid-β x) ∙ ap-∙ (projl _ _) (ap winl (! (merid x))) (wglue ∙ ap winr (merid x)) ∙ ((∘-ap (projl _ _) winl (! (merid x)) ∙ ap-idf _) ∙2 (ap-∙ (projl _ _) wglue (ap winr (merid x)) ∙ (Projl.glue-β _ _ ∙2 (∘-ap (projl _ _) winr (merid x) ∙ ap-cst _ _)))) ∙ ∙-unit-r _ ∙ ! (FlipSusp.merid-β x) projr-subtract : ∀ σ → projr _ _ (subtract σ) == σ projr-subtract = Susp-elim idp idp $ ↓-∘=idf-in' (projr _ _) subtract ∘ λ x → ap (ap (projr _ _)) (Subtract.merid-β x) ∙ ap-∙ (projr _ _) (ap winl (! (merid x))) (wglue ∙ ap winr (merid x)) ∙ ((∘-ap (projr _ _) winl (! (merid x)) ∙ ap-cst _ _) ∙2 (ap-∙ (projr _ _) wglue (ap winr (merid x)) ∙ (Projr.glue-β _ _ ∙2 (∘-ap (projr _ _) winr (merid x) ∙ ap-idf _)))) fold-subtract : ∀ σ → fold (subtract σ) == south fold-subtract = Susp-elim idp idp $ ↓-app=cst-in ∘ ! ∘ λ x → ∙-unit-r _ ∙ ap-∘ fold subtract (merid x) ∙ ap (ap fold) (Subtract.merid-β x) ∙ ap-∙ fold (ap winl (! (merid x))) (wglue ∙ ap winr (merid x)) ∙ ((∘-ap fold winl (! (merid x)) ∙ ap-idf _) ∙2 (ap-∙ fold wglue (ap winr (merid x)) ∙ (Fold.glue-β ∙2 (∘-ap fold winr (merid x) ∙ ap-idf _)))) ∙ !-inv-l (merid x) cancel : ×ᴳ-fanin (C-is-abelian n _) (CF-hom n (⊙Susp-flip X)) (idhom _) ∘ᴳ ×ᴳ-diag == cst-hom cancel = ap2 (λ φ ψ → ×ᴳ-fanin (C-is-abelian n _) φ ψ ∘ᴳ ×ᴳ-diag) (! (CF-λ= n projl-subtract)) (! (CF-ident n) ∙ ! (CF-λ= n projr-subtract)) ∙ transport (λ {(G , φ , ψ) → φ ∘ᴳ ψ == cst-hom}) (pair= (CW.path) $ ↓-×-in (CW.Wedge-in-over ⊙subtract) (CW.⊙Wedge-rec-over (⊙idf _) (⊙idf _) ▹ ap2 ×ᴳ-fanout (CF-ident n) (CF-ident n))) (! (CF-comp n ⊙fold ⊙subtract) ∙ CF-λ= n (λ σ → fold-subtract σ ∙ ! (merid (pt X))) ∙ CF-cst n) C-Susp-flip-is-inv : CF-hom n (⊙Susp-flip X) == inv-hom (C n (⊙Susp X)) (C-is-abelian _ _) C-Susp-flip-is-inv = group-hom= $ λ= λ g → ! (Group.inv-unique-l (C n (⊙Susp X)) _ g (app= (ap GroupHom.f cancel) g))
{ "alphanum_fraction": 0.543544458, "avg_line_length": 36.0879120879, "ext": "agda", "hexsha": "9a9310aaa4506c8ae582f774e283ba60579865d1", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_path": "theorems/stash/cohomology/InverseInSusp.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "mikeshulman/HoTT-Agda", "max_issues_repo_path": "theorems/stash/cohomology/InverseInSusp.agda", "max_line_length": 78, "max_stars_count": null, "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_path": "theorems/stash/cohomology/InverseInSusp.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1350, "size": 3284 }
{-# OPTIONS --safe --warning=error #-} open import Setoids.Setoids open import Groups.SymmetricGroups.Definition open import Groups.FreeGroup.Definition open import Decidable.Sets open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import LogicalFormulae open import Boolean.Definition module Groups.FreeGroup.Word {a : _} {A : Set a} (decA : DecidableSet A) where data ReducedWord : Set a wordLength : ReducedWord → ℕ firstLetter : (w : ReducedWord) → .(0 <N wordLength w) → FreeCompletion A data PrependIsValid (w : ReducedWord) (l : FreeCompletion A) : Set a where wordEmpty : wordLength w ≡ 0 → PrependIsValid w l wordEnding : .(pr : 0 <N wordLength w) → .(freeCompletionEqual decA l (freeInverse (firstLetter w pr)) ≡ BoolFalse) → PrependIsValid w l data ReducedWord where empty : ReducedWord prependLetter : (letter : FreeCompletion A) → (w : ReducedWord) → PrependIsValid w letter → ReducedWord firstLetter empty () firstLetter (prependLetter letter w x) pr = letter wordLength empty = 0 wordLength (prependLetter letter w pr) = succ (wordLength w) prependLetterRefl : {x : FreeCompletion A} {w : ReducedWord} → {pr1 pr2 : PrependIsValid w x} → prependLetter x w pr1 ≡ prependLetter x w pr2 prependLetterRefl {x} {empty} {wordEmpty refl} {wordEmpty refl} = refl prependLetterRefl {x} {empty} {wordEmpty refl} {wordEnding () x₂} prependLetterRefl {x} {empty} {wordEnding () x₁} {pr2} prependLetterRefl {x} {prependLetter letter w x₁} {wordEmpty ()} {pr2} prependLetterRefl {x} {prependLetter letter w x₁} {wordEnding pr x₂} {wordEmpty ()} prependLetterRefl {x} {prependLetter letter w x₁} {wordEnding pr2 r2} {wordEnding pr1 r1} = refl prependLetterInjective : {x : FreeCompletion A} {w1 w2 : ReducedWord} {pr1 : PrependIsValid w1 x} {pr2 : PrependIsValid w2 x} → prependLetter x w1 pr1 ≡ prependLetter x w2 pr2 → w1 ≡ w2 prependLetterInjective {x = x} {empty} {empty} {pr1} {pr2} pr = refl prependLetterInjective {x = x} {prependLetter l1 w1 x1} {prependLetter .l1 .w1 .x1} {wordEnding pr₁ x₁} {wordEnding pr₂ x₂} refl = refl prependLetterInjective' : {x y : FreeCompletion A} {w1 w2 : ReducedWord} {pr1 : PrependIsValid w1 x} {pr2 : PrependIsValid w2 y} → prependLetter x w1 pr1 ≡ prependLetter y w2 pr2 → x ≡ y prependLetterInjective' refl = refl badPrepend : {x : A} {w : ReducedWord} {pr : PrependIsValid w (ofInv x)} → (PrependIsValid (prependLetter (ofInv x) w pr) (ofLetter x)) → False badPrepend (wordEmpty ()) badPrepend {x = x} (wordEnding pr bad) with decidableFreeCompletion decA (ofLetter x) (ofLetter x) badPrepend {x} (wordEnding pr ()) | inl x₁ badPrepend {x} (wordEnding pr bad) | inr pr2 = pr2 refl badPrepend' : {x : A} {w : ReducedWord} {pr : PrependIsValid w (ofLetter x)} → (PrependIsValid (prependLetter (ofLetter x) w pr) (ofInv x)) → False badPrepend' (wordEmpty ()) badPrepend' {x = x} (wordEnding pr x₁) with decidableFreeCompletion decA (ofInv x) (ofInv x) badPrepend' {x} (wordEnding pr ()) | inl x₂ badPrepend' {x} (wordEnding pr x₁) | inr pr2 = pr2 refl
{ "alphanum_fraction": 0.7307439105, "avg_line_length": 52.3793103448, "ext": "agda", "hexsha": "1821abad4bd1c8ec808cdd4a58700db91d725f37", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Groups/FreeGroup/Word.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Groups/FreeGroup/Word.agda", "max_line_length": 186, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Groups/FreeGroup/Word.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": 986, "size": 3038 }
{-# OPTIONS --allow-unsolved-metas #-} {- Diamond operator. -} module TemporalOps.Diamond where open import CategoryTheory.Categories open import CategoryTheory.Instances.Reactive open import CategoryTheory.Functor open import CategoryTheory.NatTrans open import CategoryTheory.Monad open import TemporalOps.Common open import TemporalOps.Next open import TemporalOps.Delay open import TemporalOps.Diamond.Functor public open import TemporalOps.Diamond.Join open import TemporalOps.Diamond.JoinLemmas import Relation.Binary.PropositionalEquality as ≡ open import Data.Product open import Relation.Binary.HeterogeneousEquality as ≅ using (_≅_ ; ≅-to-≡ ; ≡-to-≅ ; cong₂) open import Data.Nat.Properties using (+-identityʳ ; +-comm ; +-suc ; +-assoc) open import Holes.Term using (⌞_⌟) open import Holes.Cong.Propositional M-◇ : Monad ℝeactive M-◇ = record { T = F-◇ ; η = η-◇ ; μ = μ-◇ ; η-unit1 = refl ; η-unit2 = η-unit2-◇ ; μ-assoc = λ{A}{n}{k} -> μ-assoc-◇ {A} {n} {k} } where η-◇ : I ⟹ F-◇ η-◇ = record { at = λ A n x -> zero , x ; nat-cond = λ {A} {B} {f} {n} {a} → refl } private module μ = _⟹_ μ-◇ private module η = _⟹_ η-◇ private module F-◇ = Functor F-◇ open ≡.≡-Reasoning η-unit2-◇ : {A : τ} {n : ℕ} {a : ◇ A at n} → (μ.at A n (F-◇.fmap (η.at A) n a)) ≡ a η-unit2-◇ {A} {n} {k , v} with inspect (compareLeq k n) -- n = k + l η-unit2-◇ {A} {.(k + l)} {k , v} | snd==[ .k + l ] with≡ pf = begin μ.at A (k + l) (F-◇.fmap (η.at A) (k + l) (k , v)) ≡⟨⟩ μ.at A (k + l) (k , (Functor.fmap (F-delay k) (η.at A) at (k + l)) v) ≡⟨⟩ μ-compare A (k + l) k ((Functor.fmap (F-delay k) (η.at A) at (k + l)) v) (compareLeq k (k + l)) ≡⟨ cong (λ x → μ-compare A (k + l) k ((Functor.fmap (F-delay k) (η.at A) at (k + l)) v) x) pf ⟩ μ-compare A (k + l) k ((Functor.fmap (F-delay k) (η.at A) at (k + l)) v) snd==[ k + l ] ≡⟨⟩ μ-shift k l ⌞ (rew (delay-+-left0 k l) ((Functor.fmap (F-delay k) (η.at A) at (k + l)) v)) ⌟ ≡⟨ cong! (delay-+-left0-eq k l ((Functor.fmap (F-delay k) (η.at A) at (k + l)) v) ((Functor.fmap (F-delay (k + 0)) (η.at A) at (k + l)) v′) pr) ⟩ μ-shift k l (rew (delay-+ k 0 l) ((Functor.fmap (F-delay (k + 0)) (η.at A) at (k + l)) v′)) ≡⟨ cong (λ x → μ-shift k l x) (fmap-delay-+-n+k k 0 l v′) ⟩ μ-shift k l ((Functor.fmap (F-delay 0) (η.at A) at l) (rew (delay-+ k 0 l) v′)) ≡⟨⟩ -- Def. of Functor.fmap (F-delay 0) μ-shift k l ((η.at A) l (rew (delay-+ k 0 l) v′)) ≡⟨⟩ -- Def. of η.at μ-shift k l (0 , rew (delay-+ k 0 l) v′) ≡⟨⟩ k + 0 , rew (sym (delay-+ k 0 l)) (rew (delay-+ k 0 l) v′) ≡⟨ cong (λ x → k + 0 , x) (rew-cancel v′ (delay-+ k 0 l)) ⟩ k + 0 , rew (delay-+0-left k (k + l)) v ≡⟨ ≅-to-≡ {_} {◇ A at (k + l)} (cong₂ {A = ℕ} {_} {λ n v → ◇ A at (k + l)} (λ x y → x , y) (≡-to-≅ (+-identityʳ k)) (≅.sym v≅v′)) ⟩ k , v ∎ where v′ : delay A by (k + 0) at (k + l) v′ = rew (delay-+0-left k (k + l)) v v≅v′ : v ≅ v′ v≅v′ = rew-to-≅ (delay-+0-left k (k + l)) pr : (Functor.fmap (F-delay k) (η.at A) at (k + l)) v ≅ (Functor.fmap (F-delay (k + 0)) (η.at A) at (k + l)) v′ pr = cong₂ (λ x y → (Functor.fmap (F-delay x) (η.at A) at (k + l)) y) (≡-to-≅ (sym (+-identityʳ k))) v≅v′ v-no-delay : A at l v-no-delay = rew (delay-+-left0 k l) v -- k = suc n + l η-unit2-◇ {A} {n} {.(n + suc l) , v} | fst==suc[ .n + l ] with≡ pf = begin μ.at A n (F-◇.fmap (η.at A) n (n + suc l , v)) ≡⟨⟩ μ.at A n (n + suc l , (Functor.fmap (F-delay (n + suc l)) (η.at A) at n) v) ≡⟨⟩ μ-compare A n (n + suc l) ((Functor.fmap (F-delay (n + suc l)) (η.at A) at n) v) (compareLeq (n + suc l) n) ≡⟨ cong (λ x → μ-compare A n (n + suc l) ((Functor.fmap (F-delay (n + suc l)) (η.at A) at n) v) x) pf ⟩ μ-compare A n (n + suc l) ((Functor.fmap (F-delay (n + suc l)) (η.at A) at n) v) fst==suc[ n + l ] ≡⟨⟩ n + suc l , rew (delay-⊤ n l) top.tt ≡⟨ cong (λ x → n + suc l , x) (eq n l v) ⟩ n + suc l , v ∎ where eq : ∀ (n l : ℕ) -> (v : delay A by (n + suc l) at n ) -> rew (delay-⊤ n l) top.tt ≡ v eq zero l v = refl eq (suc n) l v = eq n l v μ-assoc-◇ : {A : τ} {n : ℕ} {a : ◇ ◇ ◇ A at n} -> (μ.at A n (μ.at (F-◇.omap A) n a)) ≡ (μ.at A n (F-◇.fmap (μ.at A) n a)) μ-assoc-◇ {A} {n} {k , v} with inspect (compareLeq k n) -- n = k + l μ-assoc-◇ {A} {.(k + l)} {k , v} | snd==[ .k + l ] with≡ pf = begin μ.at A (k + l) (μ.at (F-◇.omap A) (k + l) (k , v)) ≡⟨⟩ μ.at A (k + l) (μ-compare (F-◇.omap A) (k + l) k v ⌞ compareLeq k (k + l) ⌟) ≡⟨ cong! pf ⟩ μ.at A (k + l) (μ-compare (F-◇.omap A) (k + l) k v (snd==[ k + l ])) ≡⟨⟩ μ.at A (k + l) (μ-shift k l (rew (delay-+-left0 k l) v)) ≡⟨ ≅-to-≡ (μ-interchange {A} {l} {k} {rew (delay-+-left0 k l) v}) ⟩ μ-shift k l (μ.at A l ⌞ rew (delay-+-left0 k l) v ⌟) ≡⟨ cong! (v≡v′-rew k l v v′ v≅v′) ⟩ μ-shift k l (μ.at A l (rew (delay-+ k 0 l) v′)) ≡⟨⟩ -- Def. of (F-delay 0).fmap μ-shift k l ((Functor.fmap (F-delay 0) (μ.at A) at l) (rew (delay-+ k 0 l) v′)) ≡⟨ cong (λ x → μ-shift k l x) (sym (fmap-delay-+-n+k k 0 l v′)) ⟩ μ-shift k l ⌞ rew (delay-+ k 0 l) ((Functor.fmap (F-delay (k + 0)) (μ.at A) at (k + l)) v′) ⌟ ≡⟨ cong! (sym (delay-+-left0-eq k l ((Functor.fmap (F-delay k) (μ.at A) at (k + l)) v) ((Functor.fmap (F-delay (k + 0)) (μ.at A) at (k + l)) v′) pr)) ⟩ μ-shift k l (rew (delay-+-left0 k l) ((Functor.fmap (F-delay k) (μ.at A) at (k + l)) v)) ≡⟨⟩ μ-compare A (k + l) k ((Functor.fmap (F-delay k) (μ.at A) at (k + l)) v) (snd==[ k + l ]) ≡⟨ cong (λ x → μ-compare A (k + l) k ((Functor.fmap (F-delay k) (μ.at A) at (k + l)) v) x) (sym pf) ⟩ μ-compare A (k + l) k ((Functor.fmap (F-delay k) (μ.at A) at (k + l)) v) (compareLeq k (k + l)) ≡⟨⟩ μ.at A (k + l) (k , (Functor.fmap (F-delay k) (μ.at A) at (k + l)) v) ≡⟨⟩ μ.at A (k + l) (F-◇.fmap (μ.at A) (k + l) (k , ?)) ∎ where v′ : delay (◇ ◇ A) by (k + 0) at (k + l) v′ = rew (delay-+0-left k (k + l)) v v≅v′ : v ≅ v′ v≅v′ = rew-to-≅ (delay-+0-left k (k + l)) pr : (Functor.fmap (F-delay k) (μ.at A) at (k + l)) v ≅ (Functor.fmap (F-delay (k + 0)) (μ.at A) at (k + l)) v′ pr = ≅.cong₂ (λ x y → (Functor.fmap (F-delay x) (μ.at A) at (k + l)) y) (≡-to-≅ (sym (+-identityʳ k))) v≅v′ v≡v′-rew : ∀ {A} (k l : ℕ) -> Proof-≡ (delay-+-left0 {A} k l) (delay-+ {A} k 0 l) v≡v′-rew zero l v v′ ≅.refl = refl v≡v′-rew (suc k) l = v≡v′-rew k l -- k = suc n + l μ-assoc-◇ {A} {.n} {.(n + suc l) , v} | fst==suc[ n + l ] with≡ pf = begin μ.at A n (μ.at (F-◇.omap A) n (n + suc l , v)) ≡⟨⟩ μ.at A n (μ-compare (F-◇.omap A) n (n + suc l) v ⌞ compareLeq (n + suc l) n ⌟) ≡⟨ cong! pf ⟩ μ.at A n (μ-compare (F-◇.omap A) n (n + suc l) v (fst==suc[ n + l ])) ≡⟨⟩ μ.at A n (n + suc l , rew (delay-⊤ n l) top.tt) ≡⟨⟩ μ-compare A n (n + suc l) (rew (delay-⊤ n l) top.tt) ⌞ compareLeq (n + suc l) n ⌟ ≡⟨ cong! pf ⟩ μ-compare A n (n + suc l) (rew (delay-⊤ n l) top.tt) (fst==suc[ n + l ]) ≡⟨⟩ n + suc l , rew (delay-⊤ n l) top.tt ≡⟨⟩ μ-compare A n (n + suc l) ((Functor.fmap (F-delay (n + suc l)) (μ.at A) at n) v) (fst==suc[ n + l ]) ≡⟨ cong (λ x -> μ-compare A n (n + suc l) ((Functor.fmap (F-delay (n + suc l)) (μ.at A) at n) v) x) (sym pf) ⟩ μ-compare A n (n + suc l) ((Functor.fmap (F-delay (n + suc l)) (μ.at A) at n) v) (compareLeq (n + suc l) n) ≡⟨⟩ μ.at A n (n + suc l , (Functor.fmap (F-delay (n + suc l)) (μ.at A) at n) v) ≡⟨⟩ μ.at A n (F-◇.fmap (μ.at A) n (n + suc l , v)) ∎
{ "alphanum_fraction": 0.4302218115, "avg_line_length": 45.7989417989, "ext": "agda", "hexsha": "171de18e7f59caf15f4be05fe9da83ec2acb782a", "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/TemporalOps/Diamond.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/TemporalOps/Diamond.agda", "max_line_length": 119, "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/TemporalOps/Diamond.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": 3714, "size": 8656 }
module Ex1Sol where ---------------------------------------------------------------------------- -- EXERCISE 1 -- NUMBERS, LISTS, VECTORS (a driving lesson) -- -- VALUE: 15% -- DEADLINE: 5pm, Friday 2 October (week 2) -- -- DON'T SUBMIT, COMMIT! Create your own private version of the CS410 repo, -- hosted somewhere like BitBucket, and invite users "pigworker" and -- "jmchapman" to collaborate with you on the project. The last version of -- your repo committed before the deadline is the "official" version, for -- marking purposes, but we're unlikely to penalise submission over the -- weekend. You can trust us not to look until Monday! -- -- The purpose of this exercise is to get you used to using Agda and its -- emacs interface. ---------------------------------------------------------------------------- open import CS410-Prelude -- HINT: your tasks are heralded with the eminently searchable tag, "???" -- TIP: when you load this file, you should see 11 open goals, which is -- too many to think about at once; use comments {- .. -} to switch off the -- parts of the file you haven't reached yet. ---------------------------------------------------------------------------- -- "Nat" -- the type of unary natural numbers ---------------------------------------------------------------------------- data Nat : Set where zero : Nat suc : Nat -> Nat {-# BUILTIN NATURAL Nat #-} -- means we can write 2 for suc (suc zero) -- TERMINOLOGY Set and "type". By "type", I mean anything you can put to -- the right of : to classify the thing to the left of :, so "Set" is a -- type, as in Nat : Set, and Nat is a type, as in zero : Nat. Being a -- Set is *one* way of being a type, but it is not the only way. In -- particular, try uncommenting this (and then change your mind). {-+} mySet : Set mySet = Set {+-} -- SPOT THE DIFFERENCE: in Haskell, we'd write -- -- data Nat = Zero | Suc Nat -- -- saying what the type is called and what is in it, and then we'd find -- that Zero :: Nat and Suc :: Nat -> Nat. Also, constructors live in a -- separate namespace, with capital initial letters. -- -- In Agda, we say what type each thing belongs to. Everything lives in -- the same namespace. Capitalisation is only a social convention. I tend -- to use capitals for typey things and lower case for valuey things. -- And we use just the one colon for typing, not two, because types are -- more important than lists. ---------------------------------------------------------------------------- -- ??? 1.1 addition (score: ? / 1) -- -- There are lots of ways to add two numbers together. Do you inspect the -- first? Do you inspect the second? Make sure you get the correct numerical -- answer, whatever you do. You may need to revisit this problem later, when -- the way addition works has a significant impact on types. ---------------------------------------------------------------------------- _+N_ : Nat -> Nat -> Nat zero +N n = n suc m +N n = suc (m +N n) infixr 3 _+N_ -- NOTATION: a name _+N_ with underscores in it serves double duty. -- (1) it is a perfectly sensible PREFIX operator, so _+N_ 2 2 makes sense -- (2) it describes the INFIX usage of the operator, with the underscores -- showing where the arguments go, with EXTRA SPACING, so the infix -- version of _+N_ 2 2 is 2 +N 2. -- When you think you're done, uncomment these unit tests, e.g., by turning -- {-+} to {-(-} and {+-} to {-)-}. They should typecheck ok. {-+} testPlus1 : 2 +N 2 == 4 testPlus1 = refl testPlus2 : 0 +N 5 == 5 testPlus2 = refl testPlus3 : 5 +N 0 == 5 testPlus3 = refl {+-} ---------------------------------------------------------------------------- -- ??? 1.2 multiplication (score: ? / 1) -- -- There's also a lot of choice in how to multiply, but they all rely on -- repeated addition. Find a way to do it. ---------------------------------------------------------------------------- _*N_ : Nat -> Nat -> Nat m *N n = {!!} infixr 4 _*N_ -- unit tests {-+} testMult1 : 2 *N 2 == 4 testMult1 = refl testMult2 : 0 *N 5 == 0 testMult2 = refl testMult3 : 5 *N 0 == 0 testMult3 = refl testMult4 : 1 *N 5 == 5 testMult4 = refl testMult5 : 5 *N 1 == 5 testMult5 = refl testMult6 : 2 *N 3 == 6 testMult6 = refl {+-} ---------------------------------------------------------------------------- -- ??? 1.3 subtraction I (score: ? / 1) -- -- Subtraction is a nuisance. How do you take a big number away from a -- smaller one? Give the closest answer you can to the correct answer. ---------------------------------------------------------------------------- _-N1_ : Nat -> Nat -> Nat m -N1 n = {!!} -- unit tests {-+} testSubN1-1 : 4 -N1 2 == 2 testSubN1-1 = refl testSubN1-2 : 42 -N1 37 == 5 testSubN1-2 = refl {+-} ---------------------------------------------------------------------------- -- "Maybe" allows for the possibility of errors ---------------------------------------------------------------------------- data Maybe (X : Set) : Set where yes : X -> Maybe X no : Maybe X -- SPOT THE DIFFERENCE: in Haskell, these are "Just" and "Nothing" -- LATER, we'll revisit Maybe and define it in terms of more basic ideas. ---------------------------------------------------------------------------- -- ??? 1.4 subtraction II (score: ? / 1) -- -- Implement subtraction with a type acknowledging that failure can happen. ---------------------------------------------------------------------------- _-N2_ : Nat -> Nat -> Maybe Nat m -N2 n = {!!} -- unit tests {-+} testSubN2-1 : 4 -N2 2 == yes 2 testSubN2-1 = refl testSubN2-2 : 42 -N2 37 == yes 5 testSubN2-2 = refl testSubN2-3 : 37 -N2 42 == no testSubN2-3 = refl {+-} ---------------------------------------------------------------------------- -- _N>=_ as a relation, not a test ---------------------------------------------------------------------------- _N>=_ : Nat -> Nat -> Set -- not Two (a.k.a. Bool), but Set -- the set of "ways it can be true" -- i.e., what counts as EVIDENCE m N>= zero = One -- anything is at least zero in a boring way zero N>= suc n = Zero -- no way is zero bigger than a successor suc m N>= suc n = m N>= n -- the way to compare successors -- What's funny is that it's just an ordinary program, computing by -- pattern matching and recursion. ---------------------------------------------------------------------------- -- ??? 1.5 subtraction III (score: ? / 1) -- -- Implement subtraction with explicit evidence that the inputs are -- amenable to subtraction. ---------------------------------------------------------------------------- _-N3_-:_ : (m : Nat) -> (n : Nat) -> m N>= n -> Nat m -N3 n -: p = {!!} -- DON'T PANIC about the syntax (m : Nat) -> (n : Nat) -> -- The type of both those arguments is Nat. However, when we write the -- type this way, we can name those arguments for use further along in -- the type, i.e. in the third argument. That's an example of a *dependent* -- type. In fact, the regular syntax Nat -> is short for (_ : Nat) -> where -- we don't bother naming the thing. -- NOTICE that we can have fancy multi-place operators. -- HINT: you will need to learn about the "absurd" pattern, written (). -- unit tests {-+} testSubN3-1 : 4 -N3 2 -: <> == 2 testSubN3-1 = refl testSubN3-2 : 42 -N3 37 -: <> == 5 testSubN3-2 = refl {+-} -- Uncomment this test and try to fill in the missing bits to make it work. {-+} testSubN3-3 : 37 -N3 42 -: {!!} == {!!} testSubN3-3 = refl {+-} -- HAHA! YA CANNAE! So comment it out again. -- EXTRA! You can -- write (m : Nat) -> (n : Nat) -> -- as (m : Nat)(n : Nat) -> -- omitting all but the last -> -- or as (m n : Nat) -> -- two named args sharing a type. -- NOTICE how the defining equations for _N>=_ play a crucial role in the -- typechecking of the above. -- NOTICE that attempts II and III take contrasting approaches to the -- problem with I. II broadens the output to allow failure. III narrows the -- input to ensure success. -- LATER, we'll see how to make the proof-plumbing less explicit -- SUSPICIOUS: why aren't they asking us to define division? ---------------------------------------------------------------------------- -- List -- the thing that was [ .. ] in Haskell ---------------------------------------------------------------------------- data List (X : Set) : Set where -- X scopes over the whole declaration... [] : List X -- ...so you can use it here... _::_ : X -> List X -> List X -- ...and here. infixr 3 _::_ ---------------------------------------------------------------------------- -- ??? 1.6 concatenation (score: ? / 1) ---------------------------------------------------------------------------- _+L_ : {X : Set} -> List X -> List X -> List X [] +L ys = ys (x :: xs) +L ys = x :: (xs +L ys) infixr 3 _+L_ -- DON'T PANIC about the "curly braces" syntax. It's very similar to the -- (m : Nat) -> syntax we saw, above. It describes an argument by giving -- its type, Set, and a name X to allow dependency. All the braces do is -- set the default usage convention that X is by default INVISIBLE. Any -- time you use the function _+L_, Agda will try to figure out what is -- the appropriate thing to put for the invisible argument, which is the -- element type for the lists. She will usually succeed, because the types -- of the lists you feed in will be a dead giveaway. -- SPOT THE DIFFERENCE: back when you learned Haskell, you learned about -- TWO ideas, FUNCTIONS and POLYMORPHISM. Now you can see that there was -- only ONE IDEA, after all. This sort of collapse will keep happening. -- The world is simpler, made of a smaller number of better articulated -- parts. -- unit test {-+} testConcL : (0 :: 1 :: 2 :: []) +L (3 :: 4 :: []) == 0 :: 1 :: 2 :: 3 :: 4 :: [] testConcL = refl {+-} ---------------------------------------------------------------------------- -- ??? 1.7 take I (score: ? / 1) -- -- Given a number, n, and a list, xs, compute the first n elements of xs. -- Of course, there will be a tiny little problem if the caller asks for -- more elements than are available, hence the name of the function. -- You must ensure that the list returned is indeed a prefix of the list -- supplied, and that it has the requested length if possible, and at most -- that length if not. ---------------------------------------------------------------------------- mis-take : {X : Set} -> Nat -> List X -> List X mis-take n xs = {!!} -- unit test {-+} testMisTake : mis-take 3 (0 :: 1 :: 2 :: 3 :: 4 :: []) == 0 :: 1 :: 2 :: [] testMisTake = refl {+-} ---------------------------------------------------------------------------- -- ??? 1.8 take II (score: ? / 2) -- -- Fix mis-take by acknowledging the possibility of error. Ensure that your -- function returns "yes" with a list of exactly the right length if -- possible, or says "no". You may need to use the "with" construct to -- inspect the result of the recursive call. ---------------------------------------------------------------------------- may-take : {X : Set} -> Nat -> List X -> Maybe (List X) may-take n xs = {!!} -- unit test {-+} testMayTake1 : may-take 3 (0 :: 1 :: 2 :: 3 :: 4 :: []) == yes (0 :: 1 :: 2 :: []) testMayTake1 = refl testMayTake2 : may-take 6 (0 :: 1 :: 2 :: 3 :: 4 :: []) == no testMayTake2 = refl testMayTake3 : may-take 5 (0 :: 1 :: 2 :: 3 :: 4 :: []) == yes (0 :: 1 :: 2 :: 3 :: 4 :: []) testMayTake3 = refl {+-} ---------------------------------------------------------------------------- -- ??? 1.9 length (score: ? / 1) ---------------------------------------------------------------------------- -- Show how to compute the length of a list. length : {X : Set} -> List X -> Nat length xs = {!!} -- unit test {-+} testLength : length (0 :: 1 :: 2 :: 3 :: 4 :: []) == 5 testLength = refl {+-} ---------------------------------------------------------------------------- -- "Vectors" -- Lists indexed by length ---------------------------------------------------------------------------- -- We seem to be troubled by things fouling up when lists have the wrong -- length. Here's a way to make list-like structures whose types let us -- keep tabs on length: the "vectors". data Vec (X : Set) : (n : Nat) -> Set where -- n's not in scope after "where" [] : Vec X zero -- it's zero here,... _::_ : {n : Nat} -> X -> Vec X n -> Vec X (suc n) -- ...successor, there -- DON'T PANIC -- Vec X is not a Set, but rather an INDEXED FAMILY of sets. For each n in -- Nat, Vec X n is a Set. The index, n, is the length. The constructors are -- just like those of List, except that their types also tell the truth -- about length, via the index. -- NOTICE that when we write a "cons", x :: xs, the length of the tail, xs, -- is an invisible argument. -- DON'T PANIC about the reuse of constructor names. We're usually starting -- with types and working towards code, so it is almost always clear which -- type's constructors we mean. -- SUSPICION: we declared List, then wrote length, then invented Vec. -- Perhaps there is some way to say "Vec is List indexed by length" and -- have it invented for us. ---------------------------------------------------------------------------- -- ??? 1.10 concatenation (score: ? / 1) ---------------------------------------------------------------------------- -- When we concatenate vectors, we add their lengths. _+V_ : {X : Set}{m n : Nat} -> Vec X m -> Vec X n -> Vec X (m +N n) [] +V ys = ys (x :: xs) +V ys = x :: (xs +V ys) infixr 3 _+V_ -- NOTICE that even though m and n are numbers, not types, they can -- still be invisible. -- DON'T PANIC if this doesn't work out to be just as easy (or even easier) -- than for lists. You may need to tinker with your definition of _+N_ to -- make _+V_ typecheck smoothly. That's because the defining equations for -- _+N_ are all the typechecker has to go on when seeing that your code -- here fits together properly. -- unit test {-+} testConcV : (0 :: 1 :: 2 :: []) +V (3 :: 4 :: []) == 0 :: 1 :: 2 :: 3 :: 4 :: [] testConcV = refl {+-} ---------------------------------------------------------------------------- -- ??? 1.11 take (score: ? / 2) ---------------------------------------------------------------------------- -- Now we know the lengths, we can give a PRECONDITION for taking. take : {X : Set}{m : Nat}(n : Nat) -> m N>= n -> Vec X m -> Vec X n take n p xs = {!!} -- unit test {-+} testTake1 : take 3 <> (0 :: 1 :: 2 :: 3 :: 4 :: []) == 0 :: 1 :: 2 :: [] testTake1 = refl testTake3 : take 5 <> (0 :: 1 :: 2 :: 3 :: 4 :: []) == 0 :: 1 :: 2 :: 3 :: 4 :: [] testTake3 = refl {+-} -- check you can't finish this {-+} testTake2 : take 6 {!!} (0 :: 1 :: 2 :: 3 :: 4 :: []) == {!!} testTake2 = refl {+-} ---------------------------------------------------------------------------- -- Chopping: one last wild weird new thing ---------------------------------------------------------------------------- -- Here's a thing you'd struggle to do in Haskell. It's really about seeing. -- A vector of length m +N n is "Choppable" if you can show how it is given -- by concatenating a vector of length m and a vector of length n. data Choppable {X : Set}(m n : Nat) : Vec X (m +N n) -> Set where chopTo : (xs : Vec X m)(ys : Vec X n) -> Choppable m n (xs +V ys) ---------------------------------------------------------------------------- -- ??? 1.12 chop (score: ? / 2) ---------------------------------------------------------------------------- chop : {X : Set}(m n : Nat)(xs : Vec X (m +N n)) -> Choppable m n xs chop zero n xs = chopTo [] xs chop (suc m) n (x :: xs) with chop m n xs chop (suc m) n (x :: .(xs +V ys)) | chopTo xs ys = chopTo (x :: xs) ys -- DON'T PANIC if you can't pattern match on the vector right away, because -- the fact is that without looking at WHERE TO CHOP, you don't know if you -- need to. -- HINT You can access vectors only from the "left end", which is a big -- clue about which number you should inspect. -- HINT Much like in -N2 and may-take, you will probably benefit from using -- the "with" feature to allow you to match on the outcome of a recursive -- call. -- DON'T PANIC if dotty things appear spontaneously in your patterns. That's -- knowledge for free: the pattern checker is saying "you don't need to ask, -- because I know that the only thing which goes here is such-and-such". -- unit test {-+} testChop : chop 3 2 (0 :: 1 :: 2 :: 3 :: 4 :: []) == chopTo (0 :: 1 :: 2 :: []) (3 :: 4 :: []) testChop = refl {+-} -- SUSPICION: unit tests may, in this case, be a little beside the point -- TERMINOLOGY: we call this method "constructing a view" of vectors. The -- datatype Choppable explains how we would like to be able to look at -- vectors. The chop function *proves* that we always can. We get for free -- that we can look at vectors as being made by [] and _::_, but now we -- can PROGRAM new ways of looking: vectors as made by _+V_. -- Welcome to the new programming.
{ "alphanum_fraction": 0.5169848319, "avg_line_length": 34.6087824351, "ext": "agda", "hexsha": "0877980b5cfbcc64613b5fb55349d4fb76667262", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "clarkdm/CS410", "max_forks_repo_path": "Ex1Sol.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "clarkdm/CS410", "max_issues_repo_path": "Ex1Sol.agda", "max_line_length": 77, "max_stars_count": null, "max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "clarkdm/CS410", "max_stars_repo_path": "Ex1Sol.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4519, "size": 17339 }
{-# OPTIONS --without-K --exact-split --safe #-} module Homotopy_Equivalence where open import Basic_Types open import Identity -- ------------------------------------ -- In homotopy type theory, a homotopy is just a point-wise equality (path) -- between to (dependent) functions f and g infix 2 _~_ _~_ : ∀ {A : Set} {B : A → Set} → ∀ (f g : ∀ (x : A) → B x) → Set _~_ {A} f g = ∀ (x : A) → f x ≡ g x -- operations on homotopies, which give them groupoid-like structures hp-refl : ∀ {A : Set} {B : A → Set} → ∀ (f : ∀ (a : A) → B a) → f ~ f hp-refl {A} f = λ (x : A) → refl (f x) hp-inv : ∀ {A : Set} {B : A → Set} {f g : ∀ (a : A) → B a} → f ~ g → g ~ f hp-inv {A} H = λ (x : A) → inv (H x) hp-concat : ∀ {A : Set} {B : A → Set} {f g h : ∀ (a : A) → B a} → f ~ g → g ~ h → f ~ h hp-concat {A} H K = λ (x : A) → (H x) ∙ (K x) -- naturality of homotopies <<<<<<< HEAD hpna : ∀ {A B : Set} {x y : A} → ∀ (p : x ≡ y) → ∀ (f g : A → B) → ∀ (H : f ~ g) → (H x) ∙ (ap g p) ≡ (ap f p) ∙ (H y) hpna {_} {_} {x} {x} (refl x) f g H = (right_unit (H x)) ∙ (inv (left_unit (H x))) ======= >>>>>>> a0dc66dca08059f740d9290f3d1cad1bb007d721 infix 3 _·_ _·_ : ∀ {A : Set} {B : A → Set} {f g h : ∀ (a : A) → B a} → f ~ g → g ~ h → f ~ h H · K = hp-concat H K hp-ass : ∀ {A : Set} {B : A → Set} {f g h k : ∀ (a : A) → B a} → ∀ (H : f ~ g) (K : g ~ h) (L : h ~ k) → H · (K · L) ~ (H · K) · L hp-ass {A} H K L = λ (x : A) → p-ass (H x) (K x) (L x) hp-left_unit : ∀ {A : Set} {B : A → Set} {f g : ∀ (a : A) → B a} → ∀ (H : f ~ g) → (hp-refl f) · H ~ H hp-left_unit {A} H = λ (x : A) → left_unit (H x) hp-right_unit : ∀ {A : Set} {B : A → Set} {f g : ∀ (a : A) → B a} → ∀ (H : f ~ g) → H · (hp-refl g) ~ H hp-right_unit {A} H = λ (x : A) → right_unit (H x) -- whiskering operations whis-r : ∀ {A B C : Set} {f g : A → B} → ∀ (H : f ~ g) → ∀ (h : B → C) → (comp h f) ~ (comp h g) <<<<<<< HEAD whis-r {A} H h = λ (x : A) → ap h (H x) ======= whis-f {A} h H = λ (x : A) → ap h (H x) >>>>>>> a0dc66dca08059f740d9290f3d1cad1bb007d721 whis-l : ∀ {A B C : Set} {g h : B → C} → ∀ (H : g ~ h) → ∀ (f : A → B) → (comp g f) ~ (comp h f) whis-l {A} H f = λ (x : A) → H (f x) -- ------------------------------------ -- equivalences -- first, let's consider quasi-equivalences qinv : ∀ {A B : Set} → ∀ (f : A → B) → Set qinv {A} {B} f = Σ g ∶ (B → A) , (((comp f g) ~ id) × ((comp g f) ~ id)) isequiv : ∀ {A B : Set} → ∀ (f : A → B) → Set isequiv {A} {B} f = (Σ g ∶ (B → A) , ((comp f g) ~ id)) × (Σ h ∶ (B → A) , ((comp h f) ~ id)) isequivid : ∀ {A : Set} → isequiv (id {A}) isequivid {A} = ((id {A} , hp-refl (id {A})) , (id {A} , hp-refl (id {A}))) -- the relation between quasi-inverse and equivalence is as following: q→e : ∀ {A B : Set} → ∀ (f : A → B) → qinv f → isequiv f q→e f q = ((π₁ q , π₁ (π₂ q)) , (π₁ q , π₂ (π₂ q))) e→q : ∀ {A B : Set} → ∀ (f : A → B) → isequiv f → qinv f e→q {A} {B} f ((g , fgid) , (h , hfid)) = (comp h (comp f g) , (e→q1 , e→q2)) where e→q1 : comp f (comp h (comp f g)) ~ id e→q1 = (whis-l {B} {A} {B} (whis-r {A} {A} {B} hfid f) g) · fgid e→q2 : comp (comp h (comp f g)) f ~ id e→q2 = (whis-l {A} {B} {A} (whis-r {B} {B} {A} fgid h) f) · hfid -- the above two lemmas shows that quasi-equivalence and equivalence are -- logically equivalent -- ------------------------------------ -- type equivalence infix 3 _≃_ _≃_ : ∀ (A B : Set) → Set A ≃ B = Σ f ∶ (A → B) , (isequiv f) -- type equivalence is an equivalence relation on Set ≃-refl : ∀ (A : Set) → A ≃ A ≃-refl A = id {A} , isequivid {A} -- ------------------------------------ -- The higher groupoid structure of type formers -- Cartesian product types p×1 : ∀ {A B : Set} {x y : A × B} → x ≡ y → π₁ x ≡ π₁ y p×1 {_} {_} {x} {x} (refl x) = refl (π₁ x) p×2 : ∀ {A B : Set} {x y : A × B} → x ≡ y → π₂ x ≡ π₂ y p×2 {_} {_} {x} {x} (refl x) = refl (π₂ x) p≡p× : ∀ {A B : Set} {x y : A × B} → ∀ (p : x ≡ y) → (π₁ x ≡ π₁ y) × (π₂ x ≡ π₂ y) p≡p× = λ p → (p×1 p , p×2 p) p×≡p : ∀ {A B : Set} {x1 y1 : A} {x2 y2 : B} → ((x1 ≡ y1) × (x2 ≡ y2)) → (x1 , x2) ≡ (y1 , y2) p×≡p {_} {_} {x1} {x1} {x2} {x2} (refl x1 , refl x2) = refl (x1 , x2)
{ "alphanum_fraction": 0.4376181474, "avg_line_length": 35.5630252101, "ext": "agda", "hexsha": "019d80992f1d7306ede9c703f9aac929257c01ac", "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": "76b9ef64626b6d3bbb7ace4f1a16aeb447c54328", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andyfreeyy/agda_and_math", "max_forks_repo_path": "HoTT/Homotopy_Equivalence.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "76b9ef64626b6d3bbb7ace4f1a16aeb447c54328", "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": "andyfreeyy/agda_and_math", "max_issues_repo_path": "HoTT/Homotopy_Equivalence.agda", "max_line_length": 93, "max_stars_count": 2, "max_stars_repo_head_hexsha": "76b9ef64626b6d3bbb7ace4f1a16aeb447c54328", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andyfreeyy/agda_and_math", "max_stars_repo_path": "HoTT/Homotopy_Equivalence.agda", "max_stars_repo_stars_event_max_datetime": "2020-05-24T10:56:36.000Z", "max_stars_repo_stars_event_min_datetime": "2020-03-23T09:01:42.000Z", "num_tokens": 1917, "size": 4232 }
open import Numeral.Natural open import Relator.Equals open import Type.Properties.Decidable open import Type module Formalization.ClassicalPredicateLogic.Semantics {ℓₘ ℓₚ ℓᵥ ℓₒ} (Prop : ℕ → Type{ℓₚ}) (Var : Type{ℓᵥ}) ⦃ var-eq-dec : Decidable(2)(_≡_ {T = Var}) ⦄ (Obj : ℕ → Type{ℓₒ}) where import Lvl open import Data open import Data.Boolean open import Data.Boolean.Stmt open import Data.ListSized import Data.ListSized.Functions as List open import Formalization.ClassicalPredicateLogic.Syntax(Prop)(Var)(Obj) open import Functional using (_∘_ ; _∘₂_) import Logic.Propositional as Logic import Logic.Predicate as Logic open import Sets.PredicateSet using (PredSet) open Sets.PredicateSet.BoundedQuantifiers open import Syntax.Function open import Type.Dependent renaming (intro to _,_) open import Type private variable ℓ ℓ₁ ℓ₂ : Lvl.Level module _ where private variable P : Type{ℓₚ} private variable n : ℕ -- Model. -- A model decides which propositional constants that are true or false. record Model : Type{ℓₚ Lvl.⊔ ℓₒ Lvl.⊔ ℓᵥ Lvl.⊔ Lvl.𝐒(ℓₘ)} where field Domain : Type{ℓₘ} function : Obj(n) → List(Domain)(n) → Domain predicate : Prop(n) → List(Domain)(n) → Bool private variable 𝔐 : Model -- Also called: Variable assignment. VarMapping : Model → Type VarMapping(𝔐) = Var → Model.Domain(𝔐) mapSingle : VarMapping(𝔐) → Var → Model.Domain(𝔐) → VarMapping(𝔐) mapSingle 𝔰 x t y = if decide(2)(_≡_) ⦃ var-eq-dec ⦄ x y then t else 𝔰(y) private variable 𝔰 : VarMapping(𝔐) module _ ((𝔐 , 𝔰) : Σ Model VarMapping) where val : Term → Model.Domain(𝔐) val₊ : List(Term)(n) → List(Model.Domain(𝔐))(n) val(var v) = 𝔰(v) val(func f x) = Model.function 𝔐 f (val₊ x) val₊ {0} ∅ = ∅ val₊ {𝐒(n)} (t ⊰ ts) = (val t ⊰ val₊ {n} ts) --val₊ = List.map val -- Satisfication relation. -- ((𝔐 , 𝔰) ⊧ φ) means that the formula φ is satisfied in the model 𝔐 with the variable mapping. -- Or in other words: A formula is true in the model 𝔐. _⊧_ : (Σ Model VarMapping) → Formula → Type{ℓₘ} (𝔐 , 𝔰) ⊧ (f $ x) = Lvl.Up(IsTrue(Model.predicate 𝔐 f (val₊(𝔐 , 𝔰) x))) -- A model decides whether a relation is satisfied. (𝔐 , 𝔰) ⊧ ⊤ = Unit -- All models satisfy top. (𝔐 , 𝔰) ⊧ ⊥ = Empty -- No model satisfies bottom. (𝔐 , 𝔰) ⊧ (φ ∧ ψ) = ((𝔐 , 𝔰) ⊧ φ) Logic.∧ ((𝔐 , 𝔰) ⊧ ψ) -- A model satisfies a conjunction when it satisfies both of the propositions. (𝔐 , 𝔰) ⊧ (φ ∨ ψ) = ((𝔐 , 𝔰) ⊧ φ) Logic.∨ ((𝔐 , 𝔰) ⊧ ψ) -- A model satisfies a disjunction when it satisfies any one of the propositions. (𝔐 , 𝔰) ⊧ (φ ⟶ ψ) = Logic.¬((𝔐 , 𝔰) ⊧ φ) Logic.∨ ((𝔐 , 𝔰) ⊧ ψ) (𝔐 , 𝔰) ⊧ (Ɐ(x) φ) = Logic.∀ₗ(t ↦ (𝔐 , mapSingle{𝔐 = 𝔐} 𝔰 x t) ⊧ φ) (𝔐 , 𝔰) ⊧ (∃(x) φ) = Logic.∃(t ↦ (𝔐 , mapSingle{𝔐 = 𝔐} 𝔰 x t) ⊧ φ) -- Satisfication of a set of formulas. -- This means that a model satisfies all formulas at the same time. _⊧₊_ : (Σ Model VarMapping) → PredSet{ℓ}(Formula) → Type 𝔐 ⊧₊ Γ = ∀ₛ(Γ) (𝔐 ⊧_) -- Validity of a formula. -- A formula is valid when it is true independent of any model. Valid : Formula → Type Valid(φ) = Logic.∀ₗ(_⊧ φ) -- Satisfiability of sets of formulas. -- A set of formulas is valid when there is a model that satisfies all of them at the same time. Satisfiable : PredSet{ℓ}(Formula) → Type Satisfiable(Γ) = Logic.∃(_⊧₊ Γ) -- Unsatisfiability of sets of formulas. Unsatisfiable : PredSet{ℓ}(Formula) → Type Unsatisfiable{ℓ} = Logic.¬_ ∘ Satisfiable{ℓ} -- Semantic entailment of a formula. -- A hypothetical statement. If a model would satisfy all formulas in Γ, then this same model satisifes the formula φ. _⊨_ : PredSet{ℓ}(Formula) → Formula → Type Γ ⊨ φ = ∀{𝔐} → (𝔐 ⊧₊ Γ) → (𝔐 ⊧ φ) _⊭_ : PredSet{ℓ}(Formula) → Formula → Type _⊭_ = (Logic.¬_) ∘₂ (_⊨_) -- Axiomatization of a theory by a set of axioms. -- A set of axioms is a set of formulas. -- A theory is the closure of a set of axioms. -- An axiomatization is a subset of formulas of the theory which entails all formulas in the axiomatized theory. _axiomatizes_ : PredSet{ℓ₁}(Formula) → PredSet{ℓ₂}(Formula) → Type Γ₁ axiomatizes Γ₂ = ∀{φ} → (Γ₁ ⊨ φ) → Γ₂(φ) -- A set of formulas is closed when it includes all formulas that it entails. Closed : PredSet{ℓ}(Formula) → Type Closed(Γ) = Γ axiomatizes Γ _⊨₊_ : PredSet{ℓ₁}(Formula) → PredSet{ℓ₂}(Formula) → Type Γ₁ ⊨₊ Γ₂ = ∀{𝔐} → (𝔐 ⊧₊ Γ₁) → (𝔐 ⊧₊ Γ₂) _⊭₊_ : PredSet{ℓ₁}(Formula) → PredSet{ℓ₂}(Formula) → Type _⊭₊_ = (Logic.¬_) ∘₂ (_⊨₊_)
{ "alphanum_fraction": 0.6160525201, "avg_line_length": 38.3902439024, "ext": "agda", "hexsha": "aecc4b75845f993d931fd7110a353b4272e3509c", "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": "Formalization/ClassicalPredicateLogic/Semantics.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": "Formalization/ClassicalPredicateLogic/Semantics.agda", "max_line_length": 157, "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": "Formalization/ClassicalPredicateLogic/Semantics.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": 1830, "size": 4722 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Some examples of how to use non-trivial induction over the natural -- numbers. ------------------------------------------------------------------------ module README.Data.Nat.Induction where open import Data.Nat open import Data.Nat.Induction open import Data.Product using (_,_) open import Function using (_∘_) open import Induction.WellFounded open import Relation.Binary.PropositionalEquality -- Doubles its input. twice : ℕ → ℕ twice = rec _ λ { zero _ → zero ; (suc n) twice-n → suc (suc twice-n) } -- Halves its input (rounding downwards). -- -- The step function is mentioned in a proof below, so it has been -- given a name. (The mutual keyword is used to avoid having to give -- a type signature for the step function.) mutual half₁-step = λ { zero _ → zero ; (suc zero) _ → zero ; (suc (suc n)) (_ , half₁n , _) → suc half₁n } half₁ : ℕ → ℕ half₁ = cRec _ half₁-step -- An alternative implementation of half₁. mutual half₂-step = λ { zero _ → zero ; (suc zero) _ → zero ; (suc (suc n)) rec → suc (rec n (≤′-step ≤′-refl)) } half₂ : ℕ → ℕ half₂ = <′-rec _ half₂-step -- The application half₁ (2 + n) is definitionally equal to -- 1 + half₁ n. Perhaps it is instructive to see why. half₁-2+ : ∀ n → half₁ (2 + n) ≡ 1 + half₁ n half₁-2+ n = begin half₁ (2 + n) ≡⟨⟩ cRec _ half₁-step (2 + n) ≡⟨⟩ half₁-step (2 + n) (cRecBuilder _ half₁-step (2 + n)) ≡⟨⟩ half₁-step (2 + n) (let ih = cRecBuilder _ half₁-step (1 + n) in half₁-step (1 + n) ih , ih) ≡⟨⟩ half₁-step (2 + n) (let ih = cRecBuilder _ half₁-step n in half₁-step (1 + n) (half₁-step n ih , ih) , half₁-step n ih , ih) ≡⟨⟩ 1 + half₁-step n (cRecBuilder _ half₁-step n) ≡⟨⟩ 1 + cRec _ half₁-step n ≡⟨⟩ 1 + half₁ n ∎ where open ≡-Reasoning -- The application half₂ (2 + n) is definitionally equal to -- 1 + half₂ n. Perhaps it is instructive to see why. half₂-2+ : ∀ n → half₂ (2 + n) ≡ 1 + half₂ n half₂-2+ n = begin half₂ (2 + n) ≡⟨⟩ <′-rec _ half₂-step (2 + n) ≡⟨⟩ half₂-step (2 + n) (<′-recBuilder _ half₂-step (2 + n)) ≡⟨⟩ 1 + <′-recBuilder _ half₂-step (2 + n) n (≤′-step ≤′-refl) ≡⟨⟩ 1 + Some.wfRecBuilder _ half₂-step (2 + n) (<′-wellFounded (2 + n)) n (≤′-step ≤′-refl) ≡⟨⟩ 1 + Some.wfRecBuilder _ half₂-step (2 + n) (acc (<′-wellFounded′ (2 + n))) n (≤′-step ≤′-refl) ≡⟨⟩ 1 + half₂-step n (Some.wfRecBuilder _ half₂-step n (<′-wellFounded′ (2 + n) n (≤′-step ≤′-refl))) ≡⟨⟩ 1 + half₂-step n (Some.wfRecBuilder _ half₂-step n (<′-wellFounded′ (1 + n) n ≤′-refl)) ≡⟨⟩ 1 + half₂-step n (Some.wfRecBuilder _ half₂-step n (<′-wellFounded n)) ≡⟨⟩ 1 + half₂-step n (<′-recBuilder _ half₂-step n) ≡⟨⟩ 1 + <′-rec _ half₂-step n ≡⟨⟩ 1 + half₂ n ∎ where open ≡-Reasoning -- Some properties that the functions above satisfy, proved using -- cRec. half₁-+₁ : ∀ n → half₁ (twice n) ≡ n half₁-+₁ = cRec _ λ { zero _ → refl ; (suc zero) _ → refl ; (suc (suc n)) (_ , half₁twice-n≡n , _) → cong (suc ∘ suc) half₁twice-n≡n } half₂-+₁ : ∀ n → half₂ (twice n) ≡ n half₂-+₁ = cRec _ λ { zero _ → refl ; (suc zero) _ → refl ; (suc (suc n)) (_ , half₁twice-n≡n , _) → cong (suc ∘ suc) half₁twice-n≡n } -- Some properties that the functions above satisfy, proved using -- <′-rec. half₁-+₂ : ∀ n → half₁ (twice n) ≡ n half₁-+₂ = <′-rec _ λ { zero _ → refl ; (suc zero) _ → refl ; (suc (suc n)) rec → cong (suc ∘ suc) (rec n (≤′-step ≤′-refl)) } half₂-+₂ : ∀ n → half₂ (twice n) ≡ n half₂-+₂ = <′-rec _ λ { zero _ → refl ; (suc zero) _ → refl ; (suc (suc n)) rec → cong (suc ∘ suc) (rec n (≤′-step ≤′-refl)) }
{ "alphanum_fraction": 0.4656690141, "avg_line_length": 28.4, "ext": "agda", "hexsha": "a338c1c10f4b24bc8172bc255b2e3516738acc4f", "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/README/Data/Nat/Induction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/README/Data/Nat/Induction.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/README/Data/Nat/Induction.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 1557, "size": 4544 }
{-# OPTIONS --without-K #-} module LeftCancellation where open import Data.Empty open import Data.Unit open import Data.Sum open import Data.Product using (_,_; _,′_; proj₁; proj₂) open import Function renaming (_∘_ to _○_) -- explicit 'using', to show how little of HoTT is needed open import SimpleHoTT using (refl; ap; _∘_; !; _≡_; _≡⟨_⟩_ ; _∎) open import Equivalences open import TypeEquivalences using (swap₊) open import Inspect ---------------------------------------------------------------------------- -- Very complex proof that we can cancel units on the left of ⊎ -- Some repeated patterns: -- use injectivity of equivalences to go from f x ≡ f y to x ≡ y injectivity : {A B : Set} (equiv : (⊤ ⊎ A) ≃ (⊤ ⊎ B)) → (a : A) → equiv ⋆ inj₁ tt ≡ equiv ⋆ inj₂ a → (inj₁ tt ≡ inj₂ a) injectivity equiv x path = inj≃ equiv (inj₁ tt) (inj₂ x) path -- Use that disjoint unions are, well, disjoint, to derive a contradiction bad-path : {A : Set} → (x : A) → inj₁ tt ≡ inj₂ x → ⊥ bad-path x path = proj₁ (thm2-12-5 tt (inj₂ x)) path left-cancel-⊤ : {A B : Set} → ((⊤ ⊎ A) ≃ (⊤ ⊎ B)) → A ≃ B left-cancel-⊤ {A} {B} (f₁ , mkisequiv g₁ α₁ h₁ β₁) with f₁ (inj₁ tt) | inspect f₁ (inj₁ tt) | g₁ (inj₁ tt) | inspect g₁ (inj₁ tt) left-cancel-⊤ {A} {B} (f₁ , mkisequiv g₁ α₁ h₁ β₁) | inj₁ tt | ⟪ eq₁ ⟫ | inj₁ tt | ⟪ eq₂ ⟫ = f , equiv₁ (mkqinv g α β) where equiv = (f₁ , mkisequiv g₁ α₁ h₁ β₁) f : A → B f a with f₁ (inj₂ a) | inspect f₁ (inj₂ a) f a | inj₂ b | _ = b f a | inj₁ tt | ⟪ eq ⟫ with bad-path a inject where inject = injectivity equiv a (eq₁ ∘ ! eq) f a | inj₁ tt | ⟪ eq ⟫ | () g : B → A g b with g₁ (inj₂ b) | inspect g₁ (inj₂ b) g b | inj₂ a | _ = a g b | inj₁ tt | ⟪ eq ⟫ with bad-path b inject where inject = injectivity (sym≃ equiv) b (eq₂ ∘ ! eq) g b | inj₁ tt | ⟪ eq ⟫ | () α : f ○ g ∼ id α b with g₁ (inj₂ b) | inspect g₁ (inj₂ b) α b | inj₁ tt | ⟪ eq ⟫ with bad-path b inject where inject = injectivity (sym≃ equiv) b (eq₂ ∘ ! eq) α b | inj₁ tt | ⟪ eq ⟫ | () α b | inj₂ a | ⟪ eq ⟫ with f₁ (inj₂ a) | inspect f₁ (inj₂ a) α b | inj₂ a | ⟪ eq ⟫ | inj₁ tt | ⟪ eq₃ ⟫ with bad-path a inject where inject = injectivity equiv a (eq₁ ∘ ! eq₃) α b | inj₂ a | ⟪ eq ⟫ | inj₁ tt | ⟪ eq₃ ⟫ | () α b | inj₂ a | ⟪ eq ⟫ | inj₂ b′ | ⟪ eq₃ ⟫ = proj₁ (inj₁₁path b′ b) (ap swap₊ (! (ap f₁ eq ∘ eq₃) ∘ α₁ (inj₂ b))) β : g ○ f ∼ id β a with f₁ (inj₂ a) | inspect f₁ (inj₂ a) β a | inj₁ tt | ⟪ eq ⟫ with bad-path a inject where inject = injectivity equiv a (! (eq ∘ ! eq₁)) ... | () β a | inj₂ b | ⟪ eq ⟫ with g₁ (inj₂ b) | inspect g₁ (inj₂ b) ... | inj₁ tt | ⟪ eq₃ ⟫ with bad-path a inject where inject = injectivity equiv a (! (ap f₁ eq₃) ∘ (α₁ (inj₂ b)) ∘ ! eq) β a | inj₂ b | ⟪ eq ⟫ | inj₁ tt | ⟪ eq₃ ⟫ | () β a | inj₂ b | ⟪ eq ⟫ | inj₂ a′ | ⟪ eq₃ ⟫ = proj₁ (inj₁₁path a′ a) (ap swap₊ ((! eq₃) ∘ ap g₁ (! eq) ∘ β₂ (inj₂ a))) where module EQ = qinv (equiv₂ {f = f₁} (proj₂ equiv)) β₂ = EQ.β left-cancel-⊤ (f₁ , mkisequiv g α h β) | inj₁ tt | ⟪ eq₁ ⟫ | inj₂ a | ⟪ eq₂ ⟫ with bad-path a inject where equiv = (f₁ , mkisequiv g α h β) inject = injectivity equiv a (eq₁ ∘ ! (α (inj₁ tt)) ∘ (ap f₁ eq₂)) left-cancel-⊤ (f₁ , mkisequiv g α h β) | inj₁ tt | ⟪ eq₁ ⟫ | inj₂ a | ⟪ eq₂ ⟫ | () left-cancel-⊤ (f₁ , mkisequiv g α h β) | inj₂ b | ⟪ eq₁ ⟫ | inj₁ tt | ⟪ eq₂ ⟫ with bad-path b (! (α (inj₁ tt)) ∘ (ap f₁ eq₂) ∘ eq₁ ) ... | () left-cancel-⊤ {A} {B} (f₁ , mkisequiv g₁ α₁ h₁ β₁) | inj₂ b₁ | ⟪ eq₁ ⟫ | inj₂ a₁ | ⟪ eq₂ ⟫ = f , equiv₁ (mkqinv g α β) where equiv = (f₁ ,′ mkisequiv g₁ α₁ h₁ β₁) module EQ = qinv (equiv₂ {f = f₁} (proj₂ equiv)) β₂ = EQ.β f : A → B f a with f₁ (inj₂ a) f a | inj₂ b′ = b′ f a | inj₁ tt = b₁ g : B → A g b with g₁ (inj₂ b) g b | inj₂ a′ = a′ g b | inj₁ tt = a₁ α : f ○ g ∼ id α b with g₁ (inj₂ b) | inspect g₁ (inj₂ b) ... | inj₂ a′ | ⟪ eq ⟫ with f₁ (inj₂ a′) | inspect f₁ (inj₂ a′) ... | inj₂ b′ | ⟪ eq₃ ⟫ = ! (proj₁ (inj₁₁path b b′) (ap swap₊ (! (α₁ (inj₂ b)) ∘ ap f₁ eq ∘ eq₃))) ... | inj₁ tt | ⟪ eq₃ ⟫ with bad-path b (! (! (α₁ (inj₂ b)) ∘ (ap f₁ eq) ∘ eq₃)) α b | inj₂ a′ | ⟪ eq ⟫ | inj₁ tt | ⟪ eq₃ ⟫ | () α b | inj₁ tt | ⟪ eq ⟫ with f₁ (inj₂ a₁) | inspect f₁ (inj₂ a₁) α b | inj₁ tt | ⟪ eq ⟫ | inj₁ tt | ⟪ eq₃ ⟫ = proj₁ (inj₁₁path b₁ b) (ap swap₊ (!(! (α₁ (inj₂ b)) ∘ ap f₁ eq ∘ eq₁))) α b | inj₁ tt | ⟪ eq ⟫ | inj₂ b′ | ⟪ eq₃ ⟫ with bad-path b′ (! (α₁ (inj₁ tt)) ∘ ap f₁ eq₂ ∘ eq₃) ... | () β : g ○ f ∼ id β a with f₁ (inj₂ a) | inspect f₁ (inj₂ a) β a | inj₁ tt | ⟪ eq ⟫ with g₁ (inj₂ b₁) | inspect g₁ (inj₂ b₁) ... | inj₁ tt | ⟪ eq₃ ⟫ = proj₁ (inj₁₁path a₁ a) (ap swap₊ (! eq₂ ∘ ! (ap g₁ eq) ∘ β₂ (inj₂ a))) β a | inj₁ tt | ⟪ eq ⟫ | inj₂ a′ | ⟪ eq₃ ⟫ with bad-path a′ ((! (β₂ (inj₁ tt)) ∘ ap g₁ eq₁) ∘ eq₃) ... | () β a | inj₂ b | ⟪ eq ⟫ with g₁ (inj₂ b) | inspect g₁ (inj₂ b) β a | inj₂ b | ⟪ eq₃ ⟫ | inj₁ tt | ⟪ eq ⟫ with bad-path a (! eq ∘ ap g₁ (! eq₃) ∘ β₂ (inj₂ a)) ... | () β a | inj₂ b | ⟪ eq₃ ⟫ | inj₂ a′ | ⟪ eq ⟫ = proj₁ (inj₁₁path a′ a) (ap swap₊ (! eq ∘ ap g₁ (! eq₃) ∘ β₂ (inj₂ a)))
{ "alphanum_fraction": 0.4906685994, "avg_line_length": 51.1018518519, "ext": "agda", "hexsha": "6f765490d640fb73cbdd414c2858748daff576d7", "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/LeftCancellation.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/LeftCancellation.agda", "max_line_length": 132, "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/LeftCancellation.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": 2356, "size": 5519 }
{- Basic theory about transport: - transport is invertible - transport is an equivalence ([pathToEquiv]) -} {-# OPTIONS --safe #-} module Cubical.Foundations.Transport where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Function using (_∘_) -- Direct definition of transport filler, note that we have to -- explicitly tell Agda that the type is constant (like in CHM) transpFill : ∀ {ℓ} {A : Type ℓ} (φ : I) (A : (i : I) → Type ℓ [ φ ↦ (λ _ → A) ]) (u0 : outS (A i0)) → -------------------------------------- PathP (λ i → outS (A i)) u0 (transp (λ i → outS (A i)) φ u0) transpFill φ A u0 i = transp (λ j → outS (A (i ∧ j))) (~ i ∨ φ) u0 transport⁻ : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → B → A transport⁻ p = transport (λ i → p (~ i)) subst⁻ : ∀ {ℓ ℓ'} {A : Type ℓ} {x y : A} (B : A → Type ℓ') (p : x ≡ y) → B y → B x subst⁻ B p pa = transport⁻ (λ i → B (p i)) pa transport-fillerExt : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → PathP (λ i → A → p i) (λ x → x) (transport p) transport-fillerExt p i x = transport-filler p x i transport⁻-fillerExt : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → PathP (λ i → p i → A) (λ x → x) (transport⁻ p) transport⁻-fillerExt p i x = transp (λ j → p (i ∧ ~ j)) (~ i) x transport-fillerExt⁻ : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → PathP (λ i → p i → B) (transport p) (λ x → x) transport-fillerExt⁻ p = symP (transport⁻-fillerExt (sym p)) transport⁻-fillerExt⁻ : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → PathP (λ i → B → p i) (transport⁻ p) (λ x → x) transport⁻-fillerExt⁻ p = symP (transport-fillerExt (sym p)) transport⁻-filler : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) (x : B) → PathP (λ i → p (~ i)) x (transport⁻ p x) transport⁻-filler p x = transport-filler (λ i → p (~ i)) x transport⁻Transport : ∀ {ℓ} {A B : Type ℓ} → (p : A ≡ B) → (a : A) → transport⁻ p (transport p a) ≡ a transport⁻Transport p a j = transport⁻-fillerExt p (~ j) (transport-fillerExt p (~ j) a) transportTransport⁻ : ∀ {ℓ} {A B : Type ℓ} → (p : A ≡ B) → (b : B) → transport p (transport⁻ p b) ≡ b transportTransport⁻ p b j = transport-fillerExt⁻ p j (transport⁻-fillerExt⁻ p j b) substEquiv : ∀ {ℓ ℓ'} {A : Type ℓ} {a a' : A} (P : A → Type ℓ') (p : a ≡ a') → P a ≃ P a' substEquiv P p = (subst P p , isEquivTransport (λ i → P (p i))) liftEquiv : ∀ {ℓ ℓ'} {A B : Type ℓ} (P : Type ℓ → Type ℓ') (e : A ≃ B) → P A ≃ P B liftEquiv P e = substEquiv P (ua e) transpEquiv : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → ∀ i → p i ≃ B transpEquiv P i .fst = transp (λ j → P (i ∨ j)) i transpEquiv P i .snd = transp (λ k → isEquiv (transp (λ j → P (i ∨ (j ∧ k))) (i ∨ ~ k))) i (idIsEquiv (P i)) uaTransportη : ∀ {ℓ} {A B : Type ℓ} (P : A ≡ B) → ua (pathToEquiv P) ≡ P uaTransportη P i j = Glue (P i1) λ where (j = i0) → P i0 , pathToEquiv P (i = i1) → P j , transpEquiv P j (j = i1) → P i1 , idEquiv (P i1) pathToIso : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → Iso A B Iso.fun (pathToIso x) = transport x Iso.inv (pathToIso x) = transport⁻ x Iso.rightInv (pathToIso x) = transportTransport⁻ x Iso.leftInv (pathToIso x) = transport⁻Transport x isInjectiveTransport : ∀ {ℓ : Level} {A B : Type ℓ} {p q : A ≡ B} → transport p ≡ transport q → p ≡ q isInjectiveTransport {p = p} {q} α i = hcomp (λ j → λ { (i = i0) → retEq univalence p j ; (i = i1) → retEq univalence q j }) (invEq univalence ((λ a → α i a) , t i)) where t : PathP (λ i → isEquiv (λ a → α i a)) (pathToEquiv p .snd) (pathToEquiv q .snd) t = isProp→PathP (λ i → isPropIsEquiv (λ a → α i a)) _ _ transportUaInv : ∀ {ℓ} {A B : Type ℓ} (e : A ≃ B) → transport (ua (invEquiv e)) ≡ transport (sym (ua e)) transportUaInv e = cong transport (uaInvEquiv e) -- notice that transport (ua e) would reduce, thus an alternative definition using EquivJ can give -- refl for the case of idEquiv: -- transportUaInv e = EquivJ (λ _ e → transport (ua (invEquiv e)) ≡ transport (sym (ua e))) refl e isSet-subst : ∀ {ℓ ℓ'} {A : Type ℓ} {B : A → Type ℓ'} → (isSet-A : isSet A) → ∀ {a : A} → (p : a ≡ a) → (x : B a) → subst B p x ≡ x isSet-subst {B = B} isSet-A p x = subst (λ p′ → subst B p′ x ≡ x) (isSet-A _ _ refl p) (substRefl {B = B} x) -- substituting along a composite path is equivalent to substituting twice substComposite : ∀ {ℓ ℓ'} {A : Type ℓ} → (B : A → Type ℓ') → {x y z : A} (p : x ≡ y) (q : y ≡ z) (u : B x) → subst B (p ∙ q) u ≡ subst B q (subst B p u) substComposite B p q Bx i = transport (cong B (compPath-filler' p q (~ i))) (transport-fillerExt (cong B p) i Bx) -- transporting along a composite path is equivalent to transporting twice transportComposite : ∀ {ℓ} {A B C : Type ℓ} (p : A ≡ B) (q : B ≡ C) (x : A) → transport (p ∙ q) x ≡ transport q (transport p x) transportComposite = substComposite (λ D → D) -- substitution commutes with morphisms in slices substCommSlice : ∀ {ℓ ℓ′} {A : Type ℓ} → (B C : A → Type ℓ′) → (F : ∀ a → B a → C a) → {x y : A} (p : x ≡ y) (u : B x) → subst C p (F x u) ≡ F y (subst B p u) substCommSlice B C F p Bx a = transport-fillerExt⁻ (cong C p) a (F _ (transport-fillerExt (cong B p) a Bx)) constSubstCommSlice : ∀ {ℓ ℓ'} {A : Type ℓ} → (B : A → Type ℓ') → (C : Type ℓ') → (F : ∀ a → B a → C) → {x y : A} (p : x ≡ y) (u : B x) → (F x u) ≡ F y (subst B p u) constSubstCommSlice B C F p Bx = (sym (transportRefl (F _ Bx)) ∙ substCommSlice B (λ _ → C) F p Bx) -- transporting over (λ i → B (p i) → C (p i)) divides the transport into -- transports over (λ i → C (p i)) and (λ i → B (p (~ i))) funTypeTransp : ∀ {ℓ ℓ'} {A : Type ℓ} (B C : A → Type ℓ') {x y : A} (p : x ≡ y) (f : B x → C x) → PathP (λ i → B (p i) → C (p i)) f (subst C p ∘ f ∘ subst B (sym p)) funTypeTransp B C {x = x} p f i b = transp (λ j → C (p (j ∧ i))) (~ i) (f (transp (λ j → B (p (i ∧ ~ j))) (~ i) b)) -- transports between loop spaces preserve path composition overPathFunct : ∀ {ℓ} {A : Type ℓ} {x y : A} (p q : x ≡ x) (P : x ≡ y) → transport (λ i → P i ≡ P i) (p ∙ q) ≡ transport (λ i → P i ≡ P i) p ∙ transport (λ i → P i ≡ P i) q overPathFunct p q = J (λ y P → transport (λ i → P i ≡ P i) (p ∙ q) ≡ transport (λ i → P i ≡ P i) p ∙ transport (λ i → P i ≡ P i) q) (transportRefl (p ∙ q) ∙ cong₂ _∙_ (sym (transportRefl p)) (sym (transportRefl q))) -- substition over families of paths -- theorem 2.11.3 in The Book substInPaths : ∀ {ℓ} {A B : Type ℓ} {a a' : A} → (f g : A → B) → (p : a ≡ a') (q : f a ≡ g a) → subst (λ x → f x ≡ g x) p q ≡ sym (cong f p) ∙ q ∙ cong g p substInPaths {a = a} f g p q = J (λ x p' → (subst (λ y → f y ≡ g y) p' q) ≡ (sym (cong f p') ∙ q ∙ cong g p')) p=refl p where p=refl : subst (λ y → f y ≡ g y) refl q ≡ refl ∙ q ∙ refl p=refl = subst (λ y → f y ≡ g y) refl q ≡⟨ substRefl {B = (λ y → f y ≡ g y)} q ⟩ q ≡⟨ (rUnit q) ∙ lUnit (q ∙ refl) ⟩ refl ∙ q ∙ refl ∎ -- special cases of substInPaths from lemma 2.11.2 in The Book module _ {ℓ : Level} {A : Type ℓ} {a x1 x2 : A} (p : x1 ≡ x2) where substInPathsL : (q : a ≡ x1) → subst (λ x → a ≡ x) p q ≡ q ∙ p substInPathsL q = subst (λ x → a ≡ x) p q ≡⟨ substInPaths (λ _ → a) (λ x → x) p q ⟩ sym (cong (λ _ → a) p) ∙ q ∙ cong (λ x → x) p ≡⟨ assoc (λ _ → a) q p ⟩ (refl ∙ q) ∙ p ≡⟨ cong (_∙ p) (sym (lUnit q)) ⟩ q ∙ p ∎ substInPathsR : (q : x1 ≡ a) → subst (λ x → x ≡ a) p q ≡ sym p ∙ q substInPathsR q = subst (λ x → x ≡ a) p q ≡⟨ substInPaths (λ x → x) (λ _ → a) p q ⟩ sym (cong (λ x → x) p) ∙ q ∙ cong (λ _ → a) p ≡⟨ assoc (sym p) q refl ⟩ (sym p ∙ q) ∙ refl ≡⟨ sym (rUnit (sym p ∙ q))⟩ sym p ∙ q ∎
{ "alphanum_fraction": 0.5141818182, "avg_line_length": 43.8829787234, "ext": "agda", "hexsha": "d80d99b461346103f757faccb68a7e270949f299", "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/Foundations/Transport.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/Foundations/Transport.agda", "max_line_length": 113, "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/Foundations/Transport.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": 3333, "size": 8250 }
{-# OPTIONS --without-K --safe #-} module Cats.Category.Constructions.Terminal where open import Data.Product using (proj₁ ; proj₂) open import Level open import Cats.Category.Base import Cats.Category.Constructions.Iso as Iso import Cats.Category.Constructions.Unique as Unique module Build {lo la l≈} (Cat : Category lo la l≈) where open Category Cat open Iso.Build Cat open Unique.Build Cat IsTerminal : Obj → Set (lo ⊔ la ⊔ l≈) IsTerminal ⊤ = ∀ X → ∃! X ⊤ record HasTerminal : Set (lo ⊔ la ⊔ l≈) where field ⊤ : Obj isTerminal : IsTerminal ⊤ ! : ∀ X → X ⇒ ⊤ ! X = ∃!′.arr (isTerminal X) !-unique : ∀ {X} (f : X ⇒ ⊤) → ! X ≈ f !-unique {X} f = ∃!′.unique (isTerminal X) _ ⇒⊤-unique : ∀ {X} (f g : X ⇒ ⊤) → f ≈ g ⇒⊤-unique f g = ≈.trans (≈.sym (!-unique f)) (!-unique g) ⊤-unique : ∀ {X} → IsTerminal X → X ≅ ⊤ ⊤-unique {X} term = record { forth = ! X ; back = term ⊤ .∃!′.arr ; back-forth = ≈.trans (≈.sym (term X .∃!′.unique _)) (term X .∃!′.unique _) ; forth-back = ⇒⊤-unique _ _ } terminal-unique : ∀ {X Y} → IsTerminal X → IsTerminal Y → X ≅ Y terminal-unique X-term Y-term = HasTerminal.⊤-unique (record { isTerminal = Y-term }) X-term open Build public using (HasTerminal) private open module Build′ {lo la l≈} {C : Category lo la l≈} = Build C public using (IsTerminal ; terminal-unique)
{ "alphanum_fraction": 0.5803508772, "avg_line_length": 23.3606557377, "ext": "agda", "hexsha": "59d34030e3c027ac7a820564057131655e15b902", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z", "max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JLimperg/cats", "max_forks_repo_path": "Cats/Category/Constructions/Terminal.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "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/cats", "max_issues_repo_path": "Cats/Category/Constructions/Terminal.agda", "max_line_length": 82, "max_stars_count": 24, "max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JLimperg/cats", "max_stars_repo_path": "Cats/Category/Constructions/Terminal.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z", "max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z", "num_tokens": 505, "size": 1425 }
-- 2012-10-20 Andreas module Issue721c where data Bool : Set where false true : Bool record Foo (b : Bool) : Set where field _*_ : Bool → Bool → Bool data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x record ∃ {A : Set} (B : A → Set) : Set where constructor pack field fst : A snd : B fst dontExpandTooMuch : (F : Foo false) → ∃ λ t → t ≡ t dontExpandTooMuch F = pack t t where open Foo F d = λ x → x * x t = d (d (d (d true))) -- t should not be expanded in the error message
{ "alphanum_fraction": 0.5768500949, "avg_line_length": 21.08, "ext": "agda", "hexsha": "d6ae45c8ad66bf3423cfb4fe3e48d666076ed509", "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/Issue721c.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/Issue721c.agda", "max_line_length": 51, "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/Issue721c.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": 187, "size": 527 }
{-# OPTIONS --no-termination-check #-} module Lambda where module Prelude where data Bool : Set where true : Bool false : Bool if_then_else_ : {A : Set} -> Bool -> A -> A -> A if true then x else y = x if false then x else y = y _∧_ : Bool -> Bool -> Bool true ∧ y = y false ∧ y = false _∨_ : Bool -> Bool -> Bool true ∨ y = true false ∨ y = y ¬_ : Bool -> Bool ¬ true = false ¬ false = true data List (A : Set) : Set where nil : List A _::_ : A -> List A -> List A _++_ : {A : Set} -> List A -> List A -> List A nil ++ ys = ys (x :: xs) ++ ys = x :: xs ++ ys filter : {A : Set} -> (A -> Bool) -> List A -> List A filter p nil = nil filter p (x :: xs) = if p x then x :: filter p xs else filter p xs postulate String : Set Char : Set {-# BUILTIN BOOL Bool #-} {-# BUILTIN FALSE false #-} {-# BUILTIN TRUE true #-} {-# BUILTIN STRING String #-} {-# BUILTIN CHAR Char #-} {-# BUILTIN LIST List #-} {-# BUILTIN NIL nil #-} {-# BUILTIN CONS _::_ #-} primitive primStringEquality : String -> String -> Bool _==_ = primStringEquality infix 10 if_then_else_ infixr 50 _::_ _++_ infixl 5 _∨_ infixl 7 _∧_ infix 50 ¬_ infix 15 _==_ open Prelude Name : Set Name = String data Exp : Set where var : Name -> Exp ƛ_⟶_ : Name -> Exp -> Exp _$_ : Exp -> Exp -> Exp infixl 50 _$_ infix 20 ƛ_⟶_ infix 80 _[_/_] infix 15 _∈_ _∈_ : Name -> List Name -> Bool x ∈ y :: ys = x == y ∨ x ∈ ys x ∈ nil = false -- Free variables FV : Exp -> List Name FV (var x) = x :: nil FV (s $ t) = FV s ++ FV t FV (ƛ x ⟶ t) = filter (\y -> ¬ (x == y)) (FV t) -- Fresh names fresh : Name -> Exp -> Name fresh x e = fresh' (FV e) where fresh' : List Name -> Name fresh' xs = "z" -- TODO -- Substitution _[_/_] : Exp -> Exp -> Name -> Exp var x [ r / z ] = if x == z then r else var x (s $ t) [ r / z ] = s [ r / z ] $ t [ r / z ] (ƛ x ⟶ t) [ r / z ] = if x == z then ƛ x ⟶ t else if x ∈ FV r then ( let y : Name y = fresh x r in ƛ y ⟶ t [ var y / x ] [ r / z ] ) else ƛ x ⟶ t [ r / z ]
{ "alphanum_fraction": 0.4806508355, "avg_line_length": 20.8623853211, "ext": "agda", "hexsha": "0dedd0bd966af5fbc7eeb78e998889e6d542d525", "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/Lambda.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/Lambda.agda", "max_line_length": 68, "max_stars_count": 3, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Succeed/Lambda.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": 829, "size": 2274 }
{-# OPTIONS --without-K --safe #-} module Categories.Functor.Construction.LiftSetoids where open import Level open import Relation.Binary open import Function.Equality open import Function using (_$_) renaming (id to idf) open import Categories.Category open import Categories.Category.Instance.Setoids open import Categories.Functor private variable c ℓ : Level -- Use pattern-matching (instead of explicit calls to lower) to minimize the -- number of needed parens, and also make it syntactically apparent that -- this is indeed just a Lift. LiftedSetoid : ∀ c′ ℓ′ → Setoid c ℓ → Setoid (c ⊔ c′) (ℓ ⊔ ℓ′) LiftedSetoid c′ ℓ′ S = record { Carrier = Lift c′ Carrier ; _≈_ = λ where (lift x) (lift y) → Lift ℓ′ $ x ≈ y ; isEquivalence = record { refl = lift refl ; sym = λ where (lift eq) → lift $ sym eq ; trans = λ where (lift eq) (lift eq′) → lift $ trans eq eq′ } } where open Setoid S LiftSetoids : ∀ c′ ℓ′ → Functor (Setoids c ℓ) (Setoids (c ⊔ c′) (ℓ ⊔ ℓ′)) LiftSetoids c′ ℓ′ = record { F₀ = LiftedSetoid c′ ℓ′ ; F₁ = λ f → record { _⟨$⟩_ = λ where (lift x) → lift $ f ⟨$⟩ x ; cong = λ where (lift eq) → lift $ cong f eq } ; identity = idf ; homomorphism = λ where {f = f} {g = g} (lift eq) → lift $ cong g $ cong f eq ; F-resp-≈ = λ where fx≈gy (lift x≈y) → lift $ fx≈gy x≈y }
{ "alphanum_fraction": 0.6046676096, "avg_line_length": 32.1363636364, "ext": "agda", "hexsha": "643cd797caa90147d5da2797358c6884b8043522", "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/Functor/Construction/LiftSetoids.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/Functor/Construction/LiftSetoids.agda", "max_line_length": 80, "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/Functor/Construction/LiftSetoids.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": 484, "size": 1414 }
{-# OPTIONS --cubical #-} module Type.Cubical.SubtypeSet where open import Function.Axioms open import Functional open import Logic.Predicate as PTLogic using () renaming ([∃]-intro to intro) import Lvl open import Structure.Function.Domain using (intro ; Inverseₗ ; Inverseᵣ) open import Structure.Relator.Properties open import Structure.Type.Identity open import Type.Cubical.Equiv import Type.Cubical.Logic as Logic open import Type.Cubical.Path.Equality open import Type.Cubical.Univalence open import Type.Cubical open import Type.Properties.MereProposition open import Type.Properties.Singleton.Proofs open import Type private variable ℓ ℓ₁ ℓ₂ ℓₑ : Lvl.Level private variable T A B P Q : Type{ℓ} {- module _ {P Q : T → Type} ⦃ prop-P : ∀{x} → MereProposition{ℓ}(P(x)) ⦄ ⦃ prop-Q : ∀{x} → MereProposition{ℓ}(Q(x)) ⦄ where prop-set-extensionalityₗ : (P ≡ Q) ← (∀{x} → P(x) ↔ Q(x)) prop-set-extensionalityₗ pq = functionExtensionalityOn P Q (propositional-extensionalityₗ pq) -} --data Prop{ℓ} : Type{Lvl.𝐒(ℓ)} where -- intro : (T : Type{ℓ}) → ⦃ MereProposition(T) ⦄ → Prop Prop = \{ℓ} → PTLogic.∃{Obj = Type{ℓ}} (T ↦ MereProposition(T)) ⊤ : Prop ⊤ = intro(Logic.⊤) ⦃ prop-top ⦄ ⊥ : Prop ⊥ = intro(Logic.⊥) ⦃ prop-bottom ⦄ ¬_ : Prop{ℓ} → Prop ¬(intro A) = intro(Logic.¬ A) ⦃ prop-negation ⦄ _⟶_ : Prop{ℓ₁} → Prop{ℓ₂} → Prop (intro A) ⟶ (intro B) = intro(A → B) ⦃ prop-implication ⦄ _∨_ : Prop{ℓ₁} → Prop{ℓ₂} → Prop (intro A) ∨ (intro B) = intro(A Logic.∨ B) _∧_ : Prop{ℓ₁} → Prop{ℓ₂} → Prop (intro A) ∧ (intro B) = intro(A Logic.∧ B) ⦃ prop-conjunction ⦄ ∃ : (T → Prop{ℓ}) → Prop ∃ P = intro(Logic.∃(PTLogic.[∃]-witness ∘ P)) -- ∀ₚ : (T → Prop{ℓ}) → Prop -- ∀ₚ P = intro(PTLogic.∀ₗ(PTLogic.[∃]-witness ∘ P)) ⦃ {!prop-universal!} ⦄ record SubtypeSet {ℓₑ ℓ} (T : Type{ℓ}) : Type{ℓ Lvl.⊔ Lvl.𝐒(ℓₑ)} where constructor filter field _∋_ : T → Prop{ℓₑ} open SubtypeSet using (_∋_) public {- TODO: When Structure is generalized to arbitrary logic symbols import Structure.Sets.Names open Structure.Sets.Names.From-[∋] (_∋_) public -} _∈_ : T → SubtypeSet{ℓ}(T) → Prop _∈_ = swap(_∋_) _∉_ : T → SubtypeSet{ℓ}(T) → Prop _∉_ = (¬_) ∘₂ (_∈_) _∌_ : SubtypeSet{ℓ}(T) → T → Prop _∌_ = (¬_) ∘₂ (_∋_) ∅ : SubtypeSet(T) ∅ ∋ _ = ⊥ 𝐔 : SubtypeSet(T) 𝐔 ∋ _ = ⊤ ∁ : SubtypeSet{ℓ}(T) → SubtypeSet(T) (∁ A) ∋ x = A ∌ x _∪_ : SubtypeSet{ℓ₁}(T) → SubtypeSet{ℓ₂}(T) → SubtypeSet(T) (A ∪ B) ∋ x = (A ∋ x) ∨ (B ∋ x) _∩_ : SubtypeSet{ℓ₁}(T) → SubtypeSet{ℓ₂}(T) → SubtypeSet(T) (A ∩ B) ∋ x = (A ∋ x) ∧ (B ∋ x) _∖_ : SubtypeSet{ℓ₁}(T) → SubtypeSet{ℓ₂}(T) → SubtypeSet(T) (A ∖ B) ∋ x = (A ∋ x) ∧ (B ∌ x) unmap : (A → B) → SubtypeSet{ℓ}(B) → SubtypeSet(A) unmap f(A) ∋ x = A ∋ f(x) -- map : (A → B) → SubtypeSet{ℓ}(A) → SubtypeSet(B) -- map f(A) ∋ y = ∃(x ↦ (A ∋ x) ∧ (f(x) ≡ y)) -- TODO: Maybe SubtypeSet should require that the witness is a HSet? -- ⊶ : (A → B) → SubtypeSet(B) -- (⊶ f) ∋ y = ∃(x ↦ PTLogic.[∃]-intro (f(x) ≡ y) ⦃ {!!} ⦄)
{ "alphanum_fraction": 0.6091644205, "avg_line_length": 28.5384615385, "ext": "agda", "hexsha": "333cf94252d1d632c24ffab609119eb4cd9c4272", "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": "Type/Cubical/SubtypeSet.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": "Type/Cubical/SubtypeSet.agda", "max_line_length": 121, "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": "Type/Cubical/SubtypeSet.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": 1312, "size": 2968 }
module _ where open import Haskell.Prelude open import Agda.Builtin.Equality -- ** Foreign HS code -- language extensions {-# FOREIGN AGDA2HS {-# LANGUAGE LambdaCase #-} {-# LANGUAGE FlexibleInstances #-} #-} -- imports {-# FOREIGN AGDA2HS import Data.Monoid #-} -- ** Datatypes & functions data Exp (v : Set) : Set where Plus : Exp v → Exp v → Exp v Lit : Nat → Exp v Var : v → Exp v {-# COMPILE AGDA2HS Exp deriving (Show,Eq) #-} eval : (a → Nat) → Exp a → Nat eval env (Plus a b) = eval env a + eval env b eval env (Lit n) = n eval env (Var x) = env x {-# COMPILE AGDA2HS eval #-} -- ** Natural numbers listSum : List Int → Int listSum [] = 0 listSum (x ∷ xs) = x + sum xs {-# COMPILE AGDA2HS listSum #-} monoSum : List Integer → Integer monoSum xs = sum xs {-# COMPILE AGDA2HS monoSum #-} polySum : ⦃ iNum : Num a ⦄ → List a → a polySum xs = sum xs {-# COMPILE AGDA2HS polySum #-} {-# FOREIGN AGDA2HS -- comment -- another comment bla :: Int -> Int bla n = n * 4 {- multi line comment -} #-} -- ** Extra builtins ex_float : Double ex_float = 0.0 {-# COMPILE AGDA2HS ex_float #-} postulate toInteger : Word → Integer ex_word : Word ex_word = fromInteger 0 {-# COMPILE AGDA2HS ex_word #-} ex_char : Char ex_char = 'a' {-# COMPILE AGDA2HS ex_char #-} char_d : Char char_d = toEnum 100 {-# COMPILE AGDA2HS char_d #-} -- ** Polymorphic functions _+++_ : List a → List a → List a [] +++ ys = ys (x ∷ xs) +++ ys = x ∷ (xs +++ ys) {-# COMPILE AGDA2HS _+++_ #-} listMap : (a → b) → List a → List b listMap f [] = [] listMap f (x ∷ xs) = f x ∷ listMap f xs {-# COMPILE AGDA2HS listMap #-} mapTest : List Nat → List Nat mapTest = map (id ∘ _+_ 5) {-# COMPILE AGDA2HS mapTest #-} -- ** Lambdas plus3 : List Nat → List Nat plus3 = map (λ n → n + 3) {-# COMPILE AGDA2HS plus3 #-} doubleLambda : Nat → Nat → Nat doubleLambda = λ a b → a + 2 * b {-# COMPILE AGDA2HS doubleLambda #-} cnst : a → b → a cnst = λ x _ → x {-# COMPILE AGDA2HS cnst #-} -- ** Constraints second : (b → c) → a × b → a × c second f (x , y) = x , f y {-# COMPILE AGDA2HS second #-} doubleTake : (n m : Int) → ⦃ IsNonNegativeInt n ⦄ → ⦃ IsNonNegativeInt m ⦄ → List a → List a × List a doubleTake n m = second (take m) ∘ splitAt n {-# COMPILE AGDA2HS doubleTake #-} initLast : (xs : List a) → ⦃ NonEmpty xs ⦄ → List a × a initLast xs = init xs , last xs {-# COMPILE AGDA2HS initLast #-} -- ** Proofs assoc : (a b c : Nat) → a + (b + c) ≡ (a + b) + c assoc zero b c = refl assoc (suc a) b c rewrite assoc a b c = refl thm : (xs ys : List Nat) → sum (xs ++ ys) ≡ sum xs + sum ys thm [] ys = refl thm (x ∷ xs) ys rewrite thm xs ys | assoc x (sum xs) (sum ys) = refl -- (custom) Monoid class record MonoidX (a : Set) : Set where field memptyX : a mappendX : a → a → a open MonoidX {{...}} public {-# COMPILE AGDA2HS MonoidX #-} instance MonoidNat : MonoidX Nat memptyX {{MonoidNat}} = 0 mappendX {{MonoidNat}} i j = i + j {-# COMPILE AGDA2HS MonoidNat #-} instance MonoidFunNat : {a : Set} → MonoidX (a → Nat) memptyX {{MonoidFunNat}} _ = memptyX mappendX {{MonoidFunNat}} f g x = mappendX (f x) (g x) {-# COMPILE AGDA2HS MonoidFunNat #-} instance MonoidFun : {a b : Set} → {{MonoidX b}} → MonoidX (a → b) memptyX {{MonoidFun}} _ = memptyX mappendX {{MonoidFun}} f g x = mappendX (f x) (g x) {-# COMPILE AGDA2HS MonoidFun #-} sumMonX : ∀{a} → {{MonoidX a}} → List a → a sumMonX [] = memptyX sumMonX (x ∷ xs) = mappendX x (sumMonX xs) {-# COMPILE AGDA2HS sumMonX #-} sumMon : ∀{a} → {{Monoid a}} → List a → a sumMon [] = mempty sumMon (x ∷ xs) = x <> sumMon xs {-# COMPILE AGDA2HS sumMon #-} -- Using the Monoid class from the Prelude data NatSum : Set where MkSum : Nat → NatSum {-# COMPILE AGDA2HS NatSum #-} instance SemigroupNatSum : Semigroup NatSum SemigroupNatSum ._<>_ (MkSum a) (MkSum b) = MkSum (a + b) MonoidNatSum : Monoid NatSum MonoidNatSum .mempty = MkSum 0 double : ⦃ Monoid a ⦄ → a → a double x = x <> x doubleSum : NatSum → NatSum doubleSum = double {-# COMPILE AGDA2HS SemigroupNatSum #-} {-# COMPILE AGDA2HS MonoidNatSum #-} {-# COMPILE AGDA2HS double #-} {-# COMPILE AGDA2HS doubleSum #-} -- Instance argument proof obligation that should not turn into a class constraint hd : (xs : List a) → ⦃ NonEmpty xs ⦄ → a hd [] = error "hd: empty list" hd (x ∷ _) = x {-# COMPILE AGDA2HS hd #-} five : Int five = hd (5 ∷ 3 ∷ []) {-# COMPILE AGDA2HS five #-} -- ** Booleans ex_bool : Bool ex_bool = true {-# COMPILE AGDA2HS ex_bool #-} ex_if : Nat ex_if = if true then 1 else 0 {-# COMPILE AGDA2HS ex_if #-} if_over : Nat if_over = (if true then (λ x → x) else (λ x → x + 1)) 0 {-# COMPILE AGDA2HS if_over #-} if_partial₁ : List Nat → List Nat if_partial₁ = map (if true then 1 else_) {-# COMPILE AGDA2HS if_partial₁ #-} if_partial₂ : List Nat → List (Nat → Nat) if_partial₂ = map (if true then_else_) {-# COMPILE AGDA2HS if_partial₂ #-} if_partial₃ : List Bool → List (Nat → Nat → Nat) if_partial₃ = map if_then_else_ {-# COMPILE AGDA2HS if_partial₃ #-} if_partial₄ : List Bool → List (Nat → Nat) if_partial₄ = map (if_then 1 else_) {-# COMPILE AGDA2HS if_partial₄ #-} if_partial₅ : Bool → Nat → List Nat → List Nat if_partial₅ b f = map (if b then f else_) {-# COMPILE AGDA2HS if_partial₅ #-}
{ "alphanum_fraction": 0.6165638437, "avg_line_length": 21.9221311475, "ext": "agda", "hexsha": "c2d6ab16b60e62e515316a78ce8553b940eabec6", "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": "4cb28f1b5032948b19b977b390fa260be292abf6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "flupe/agda2hs", "max_forks_repo_path": "test/Test.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6", "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": "flupe/agda2hs", "max_issues_repo_path": "test/Test.agda", "max_line_length": 101, "max_stars_count": null, "max_stars_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "flupe/agda2hs", "max_stars_repo_path": "test/Test.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1891, "size": 5349 }
{- Conatural number properties (Tesla Ice Zhang et al., Feb. 2019) This file defines operations and properties on conatural numbers: - Infinity (∞). - Proof that ∞ + 1 is equivalent to ∞. - Proof that conatural is an hSet. - Bisimulation on conatural - Proof that bisimulation is equivalent to equivalence (Coinductive Proof Principle). - Proof that this bisimulation is prop valued The standard library also defines bisimulation on conaturals: https://github.com/agda/agda-stdlib/blob/master/src/Codata/Conat/Bisimilarity.agda -} {-# OPTIONS --cubical --safe --guardedness #-} module Cubical.Codata.Conat.Properties where open import Cubical.Data.Unit open import Cubical.Data.Sum open import Cubical.Data.Empty open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Path open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Relation.Nullary open import Cubical.Relation.Nullary.DecidableEq open import Cubical.Codata.Conat.Base Unwrap-prev : Conat′ → Type₀ Unwrap-prev zero = Unit Unwrap-prev (suc _) = Conat unwrap-prev : (n : Conat′) -> Unwrap-prev n unwrap-prev zero = _ unwrap-prev (suc x) = x private -- tests 𝟘 = conat zero 𝟙 = succ 𝟘 𝟚 = succ 𝟙 succ𝟙≡𝟚 : succ 𝟙 ≡ 𝟚 succ𝟙≡𝟚 i = 𝟚 pred𝟚≡𝟙 : unwrap-prev (force 𝟚) ≡ 𝟙 pred𝟚≡𝟙 i = 𝟙 ∞ : Conat force ∞ = suc ∞ ∞+1≡∞ : succ ∞ ≡ ∞ force (∞+1≡∞ _) = suc ∞ ∞+2≡∞ : succ (succ ∞) ≡ ∞ ∞+2≡∞ = (cong succ ∞+1≡∞) ∙ ∞+1≡∞ _+_ : Conat → Conat → Conat _+′_ : Conat′ → Conat → Conat′ force (x + y) = force x +′ y zero +′ y = force y suc x +′ y = suc (x + y) n+∞≡∞ : ∀ n → n + ∞ ≡ ∞ n+′∞≡∞′ : ∀ n → n +′ ∞ ≡ suc ∞ force (n+∞≡∞ n i) = n+′∞≡∞′ (force n) i n+′∞≡∞′ zero = refl n+′∞≡∞′ (suc n) = λ i → suc (n+∞≡∞ n i) ∞+∞≡∞ : ∞ + ∞ ≡ ∞ force (∞+∞≡∞ i) = suc (∞+∞≡∞ i) conat-absurd : ∀ {y : Conat} {ℓ} {Whatever : Type ℓ} → zero ≡ suc y → Whatever conat-absurd eq = ⊥-elim (transport (cong diag eq) tt) where diag : Conat′ → Type₀ diag zero = Unit diag (suc _) = ⊥ module IsSet where ≡-stable : {x y : Conat} → Stable (x ≡ y) ≡′-stable : {x y : Conat′} → Stable (x ≡ y) force (≡-stable ¬¬p i) = ≡′-stable (λ ¬p → ¬¬p (λ p → ¬p (cong force p))) i ≡′-stable {zero} {zero} ¬¬p′ = refl ≡′-stable {suc x} {suc y} ¬¬p′ = cong′ suc (≡-stable λ ¬p → ¬¬p′ λ p → ¬p (cong pred′′ p)) ≡′-stable {zero} {suc y} ¬¬p′ = ⊥-elim (¬¬p′ conat-absurd) ≡′-stable {suc x} {zero} ¬¬p′ = ⊥-elim (¬¬p′ λ p → conat-absurd (sym p)) isSetConat : isSet Conat isSetConat _ _ = Stable≡→isSet (λ _ _ → ≡-stable) _ _ isSetConat′ : isSet Conat′ isSetConat′ m n p′ q′ = cong (cong force) (isSetConat (conat m) (conat n) p q) where p = λ where i .force → p′ i q = λ where i .force → q′ i module Bisimulation where open IsSet using (isSetConat) record _≈_ (x y : Conat) : Type₀ data _≈′_ (x y : Conat′) : Type₀ _≈′′_ : Conat′ → Conat′ → Type₀ zero ≈′′ zero = Unit suc x ≈′′ suc y = x ≈ y -- So impossible proofs are preserved x ≈′′ y = ⊥ record _≈_ x y where coinductive field prove : force x ≈′ force y data _≈′_ x y where con : x ≈′′ y → x ≈′ y open _≈_ public bisim : ∀ {x y} → x ≈ y → x ≡ y bisim′ : ∀ {x y} → x ≈′ y → x ≡ y bisim′ {zero} {zero} (con tt) = refl bisim′ {zero} {suc x} (con ()) bisim′ {suc x} {zero} (con ()) bisim′ {suc x} {suc y} (con eq) i = suc (bisim eq i) force (bisim eq i) = bisim′ (prove eq) i misib : ∀ {x y} → x ≡ y → x ≈ y misib′ : ∀ {x y} → x ≡ y → x ≈′ y misib′ {zero} {zero} _ = con tt misib′ {zero} {suc x} = conat-absurd misib′ {suc x} {zero} p = conat-absurd (sym p) -- misib′ {suc x} {suc y} p = con λ where .prove → misib′ (cong pred′ p) misib′ {suc x} {suc y} p = con (misib (cong pred′′ p)) prove (misib x≡y) = misib′ (cong force x≡y) iso″ : ∀ {x y} → (p : x ≈ y) → misib (bisim p) ≡ p iso′ : ∀ {x y} → (p : x ≈′ y) → misib′ (bisim′ p) ≡ p iso′ {zero} {zero} (con p) = refl iso′ {zero} {suc x} (con ()) iso′ {suc x} {zero} (con ()) iso′ {suc x} {suc y} (con p) = cong con (iso″ p) prove (iso″ p i) = iso′ (prove p) i osi : ∀ {x y} → (p : x ≡ y) → bisim (misib p) ≡ p osi p = isSetConat _ _ _ p path≃bisim : ∀ {x y} → (x ≡ y) ≃ (x ≈ y) path≃bisim = isoToEquiv (iso misib bisim iso″ osi) path≡bisim : ∀ {x y} → (x ≡ y) ≡ (x ≈ y) path≡bisim = ua path≃bisim isProp≈ : ∀ {x y} → isProp (x ≈ y) isProp≈ = subst isProp path≡bisim (isSetConat _ _)
{ "alphanum_fraction": 0.5782761653, "avg_line_length": 26.4418604651, "ext": "agda", "hexsha": "031826651a3dab05451847119f7848589dd85a38", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_path": "Cubical/Codata/Conat/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/Codata/Conat/Properties.agda", "max_line_length": 82, "max_stars_count": null, "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_path": "Cubical/Codata/Conat/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2032, "size": 4548 }
module Generic.Test.DeriveEq where open import Generic.Main open import Data.Vec using (Vec) renaming ([] to []ᵥ; _∷_ to _∷ᵥ_) module DeriveEqStar where open import Relation.Binary open import Relation.Binary.Construct.Closure.ReflexiveTransitive instance StarEq : ∀ {i t} {I : Set i} {T : Rel I t} {i j} {{iEq : Eq I}} {{tEq : ∀ {i j} -> Eq (T i j)}} -> Eq (Star T i j) unquoteDef StarEq = deriveEqTo StarEq (quote Star) module DeriveEqVec where instance VecEq : ∀ {n α} {A : Set α} {{aEq : Eq A}} -> Eq (Vec A n) unquoteDef VecEq = deriveEqTo VecEq (quote Vec) xs : Vec ℕ 3 xs = 2 ∷ᵥ 4 ∷ᵥ 1 ∷ᵥ []ᵥ test₁ : xs ≟ xs ≡ yes refl test₁ = refl test₂ : xs ≟ (2 ∷ᵥ 4 ∷ᵥ 2 ∷ᵥ []ᵥ) ≡ no _ test₂ = refl module DeriveEqD where data D {α β} (A : Set α) (B : A -> Set β) : ∀ {n x} -> Vec (B x) n -> ℕ -> Set (α ⊔ β) where c₁ : ∀ {x n} (ys : Vec (B x) n) m -> .A -> D A B ys m c₂ : ∀ {x n m y} {ys zs : Vec (B x) n} -> D A B (y ∷ᵥ ys) 0 -> Vec A m -> D A B ys (suc n) -> D A B zs n -- `VecEq` is in scope. instance DEq : ∀ {α β} {A : Set α} {B : A -> Set β} {n m x} {ys : Vec (B x) n} {{aEq : Eq A}} {{bEq : ∀ {x} -> Eq (B x)}} -> Eq (D A B ys m) unquoteDef DEq = deriveEqTo DEq (quote D) -- -- Seems like the problem is that irrelevance and metavariables resolution do not play well. -- module DeriveEqE where -- data E {α} (A : Set α) : ∀ {n} -> .(Vec A n) -> Set α where -- c₁ : ∀ {n} -> .(xs : Vec A n) -> E A xs -- instance EEq : ∀ {α n} {A : Set α} .{xs : Vec A n} -> Eq (E A xs) -- unquoteDef EEq = deriveEqTo EEq (quote E) -- -- Variable xs is declared irrelevant, so it cannot be used here -- -- when checking that the expression xs has type _B_76 A _ n₁ _ n₁ module DeriveEqF where data F {α} (A : Set α) : Set α where c₁ : ∀ {n} -> .(Vec A n) -> F A instance FEq : ∀ {α} {A : Set α} -> Eq (F A) unquoteDef FEq = deriveEqTo FEq (quote F)
{ "alphanum_fraction": 0.5507394187, "avg_line_length": 35.6545454545, "ext": "agda", "hexsha": "93c7ad6a981ee75e30528978e9c18b82c234ca72", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z", "max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z", "max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "turion/Generic", "max_forks_repo_path": "src/Generic/Test/DeriveEq.agda", "max_issues_count": 9, "max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z", "max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "turion/Generic", "max_issues_repo_path": "src/Generic/Test/DeriveEq.agda", "max_line_length": 95, "max_stars_count": 30, "max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "turion/Generic", "max_stars_repo_path": "src/Generic/Test/DeriveEq.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z", "max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z", "num_tokens": 786, "size": 1961 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Convenient syntax for "equational reasoning" in multiple Setoids. ------------------------------------------------------------------------ -- Example use: -- -- open import Data.Maybe.Properties -- open import Data.Maybe.Relation.Binary.Equality -- open import Relation.Binary.Reasoning.MultiSetoid -- -- begin⟨ S ⟩ -- x ≈⟨ drop-just (begin⟨ setoid S ⟩ -- just x ≈⟨ justx≈mz ⟩ -- mz ≈⟨ mz≈justy ⟩ -- just y ∎)⟩ -- y ≈⟨ y≈z ⟩ -- z ∎ -- Note this module is not reimplemented in terms of `Reasoning.Setoid` -- as this introduces unsolved metas as the underlying base module -- `Base.Single` does not require `_≈_` be symmetric. {-# OPTIONS --without-K --safe #-} module Relation.Binary.Reasoning.MultiSetoid where open import Function.Base using (flip) open import Level using (_⊔_) open import Relation.Binary open import Relation.Binary.PropositionalEquality as P using (_≡_) import Relation.Binary.Reasoning.Setoid as EqR ------------------------------------------------------------------------ -- Combinators that take the current setoid as an explicit argument. module _ {c ℓ} (S : Setoid c ℓ) where open Setoid S data IsRelatedTo (x y : _) : Set (c ⊔ ℓ) where relTo : (x∼y : x ≈ y) → IsRelatedTo x y infix 1 begin⟨_⟩_ begin⟨_⟩_ : ∀ {x y} → IsRelatedTo x y → x ≈ y begin⟨_⟩_ (relTo eq) = eq ------------------------------------------------------------------------ -- Combinators that take the current setoid as an implicit argument. module _ {c ℓ} {S : Setoid c ℓ} where open Setoid S renaming (_≈_ to _≈_) infixr 2 step-≈ step-≈˘ step-≡ step-≡˘ _≡⟨⟩_ infix 3 _∎ step-≈ : ∀ x {y z} → IsRelatedTo S y z → x ≈ y → IsRelatedTo S x z step-≈ x (relTo y∼z) x∼y = relTo (trans x∼y y∼z) step-≈˘ : ∀ x {y z} → IsRelatedTo S y z → y ≈ x → IsRelatedTo S x z step-≈˘ x y∼z x≈y = step-≈ x y∼z (sym x≈y) step-≡ : ∀ x {y z} → IsRelatedTo S y z → x ≡ y → IsRelatedTo S x z step-≡ _ x∼z P.refl = x∼z step-≡˘ : ∀ x {y z} → IsRelatedTo S y z → y ≡ x → IsRelatedTo S x z step-≡˘ _ x∼z P.refl = x∼z _≡⟨⟩_ : ∀ x {y} → IsRelatedTo S x y → IsRelatedTo S x y _ ≡⟨⟩ x∼y = x∼y _∎ : ∀ x → IsRelatedTo S x x _∎ _ = relTo refl syntax step-≈ x y∼z x≈y = x ≈⟨ x≈y ⟩ y∼z syntax step-≈˘ x y∼z y≈x = x ≈˘⟨ y≈x ⟩ y∼z syntax step-≡ x y≡z x≡y = x ≡⟨ x≡y ⟩ y≡z syntax step-≡˘ x y≡z y≡x = x ≡˘⟨ y≡x ⟩ y≡z
{ "alphanum_fraction": 0.5339456869, "avg_line_length": 30.5365853659, "ext": "agda", "hexsha": "42ddd8ad4595b78fa17e18e0ffba1e1e07523d48", "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/Reasoning/MultiSetoid.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/Reasoning/MultiSetoid.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Relation/Binary/Reasoning/MultiSetoid.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": 945, "size": 2504 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020 Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Function open import Data.Unit open import Data.List as List open import Data.Char open import Data.Nat as ℕ open import Data.Product open import Data.String open import Relation.Nullary using (Dec; yes; no) open import Category.Functor open import Reflection open import Optics.Functorial module Optics.Reflection where private tcMapM : {A B : Set} → (A → TC B) → List A → TC (List B) tcMapM f [] = return [] tcMapM f (x ∷ xs) = do y ← f x ys ← tcMapM f xs return (y ∷ ys) count : ℕ → List ℕ count 0 = [] count (suc n) = 0 ∷ List.map suc (count n) List-last : {A : Set} → A → List A → A List-last d [] = d List-last d (x ∷ []) = x List-last d (x ∷ xs) = List-last d xs ai : {A : Set} → A → Arg A ai x = arg (arg-info visible relevant) x record MetaLens : Set where constructor ml field mlName : Name mlType : Type mkDef : Term -- Example call: -- Let: -- > record Test : Set where -- > constructor test -- > field -- > firstField : ℕ -- > secondField : Maybe String -- -- Then; consider the call: -- -- > go Test test [x , y] 2 secondField -- -- What we want to generate is: -- -- -- > secondField : Lens Name (Maybe String) -- > secondField = lens (λ { F rf f (test x y) -- > → (RawFunctor._<$>_ rf) -- > (λ y' → test x y') (f y) -- > }) -- -- Which is captured by the MetaLens go : Name → Name → List String → ℕ → (Name × Arg Name) → TC MetaLens go rec cName vars curr (lensName , (arg _ fld)) = do -- Get the type of the field; in our case: Mabe String tyFld ← (getType fld >>= parseTy) -- compute the full lens type: Lens Test (Maybe String) let finalTy = def (quote Lens) (ai (def rec []) ∷ ai tyFld ∷ []) -- compute the clause of the lens: return (ml lensName finalTy genTerm) where parseTy : Type → TC Type parseTy (pi _ (abs _ t)) = parseTy t parseTy (var (suc x) i) = return (var x i) parseTy r = return r -- We might be at field 0; but our de Bruijn index depends -- on the total of fields curr' : ℕ curr' = List.length vars ∸ suc curr testxy : Pattern testxy = Pattern.con cName (List.map (ai ∘ Pattern.var) vars) myabs : Term → Term myabs t = pat-lam (Clause.clause (ai (Pattern.var "F") ∷ ai (Pattern.var "rf") ∷ ai (Pattern.var "f") ∷ ai testxy ∷ []) t ∷ []) [] myvar : ℕ → List (Arg Term) → Term myvar n args = var (List.length vars + n) args RawFunctor-<$>-var2 : Term → Term → Term RawFunctor-<$>-var2 testxy' fy = let rawf = quote RawFunctor._<$>_ in def rawf (ai (myvar 1 []) ∷ (ai testxy') ∷ (ai fy) ∷ []) f-varN : Term f-varN = myvar 0 (ai (var curr' []) ∷ []) xy' : List (Arg Term) xy' = let xs = reverse (count (List.length vars)) in List.map (λ m → ai (var (suc+set0 m) [])) xs where suc+set0 : ℕ → ℕ suc+set0 m = case m ℕ.≟ curr' of λ { (no _) → suc m ; (yes _) → zero } testxy' : Term testxy' = lam visible (abs "y'" (con cName xy')) -- We will now generate the RHS of second field: lens (λ { F rf ⋯ genTerm : Term genTerm = con (quote lens) (ai (myabs (RawFunctor-<$>-var2 testxy' f-varN)) ∷ []) mkLensFrom : Name → Definition → List Name → TC (List MetaLens) mkLensFrom rec (record-type c fs) lnames = do let xs = count (List.length fs) let vars = List.map (flip Data.String.replicate 'v' ∘ suc) xs tcMapM (uncurry (go rec c vars)) (List.zip xs (List.zip lnames fs)) mkLensFrom _ _ _ = typeError (strErr "Not a record" ∷ []) defineLens : MetaLens → TC ⊤ defineLens (ml n ty trm) = do -- typeError (nameErr n ∷ strErr "%%" ∷ termErr ty ∷ strErr "%%" ∷ termErr trm ∷ []) declareDef (arg (arg-info visible relevant) n) ty defineFun n (Clause.clause [] trm ∷ []) mkLens : Name → List Name → TC ⊤ mkLens rec lenses = do r ← getDefinition rec res ← mkLensFrom rec r lenses tcMapM defineLens res return tt -- usage will be: unquoteDecl = mkLens RecordName
{ "alphanum_fraction": 0.5710491368, "avg_line_length": 31.375, "ext": "agda", "hexsha": "07234d049f07c26faf9f9c30cf7d9844b6c7baf1", "lang": "Agda", "max_forks_count": 6, "max_forks_repo_forks_event_max_datetime": "2022-02-18T01:04:32.000Z", "max_forks_repo_forks_event_min_datetime": "2020-12-16T19:43:52.000Z", "max_forks_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "cwjnkins/bft-consensus-agda", "max_forks_repo_path": "Optics/Reflection.agda", "max_issues_count": 72, "max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:36:11.000Z", "max_issues_repo_issues_event_min_datetime": "2021-02-04T05:04:33.000Z", "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "cwjnkins/bft-consensus-agda", "max_issues_repo_path": "Optics/Reflection.agda", "max_line_length": 135, "max_stars_count": 4, "max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "cwjnkins/bft-consensus-agda", "max_stars_repo_path": "Optics/Reflection.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-18T19:24:05.000Z", "max_stars_repo_stars_event_min_datetime": "2020-12-16T19:43:41.000Z", "num_tokens": 1424, "size": 4518 }
{- This second-order signature was created from the following second-order syntax description: syntax CommRing | CR type * : 0-ary term zero : * | 𝟘 add : * * -> * | _⊕_ l20 one : * | 𝟙 mult : * * -> * | _⊗_ l30 neg : * -> * | ⊖_ r50 theory (𝟘U⊕ᴸ) a |> add (zero, a) = a (𝟘U⊕ᴿ) a |> add (a, zero) = a (⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c)) (⊕C) a b |> add(a, b) = add(b, a) (𝟙U⊗ᴸ) a |> mult (one, a) = a (𝟙U⊗ᴿ) a |> mult (a, one) = a (⊗A) a b c |> mult (mult(a, b), c) = mult (a, mult(b, c)) (⊗D⊕ᴸ) a b c |> mult (a, add (b, c)) = add (mult(a, b), mult(a, c)) (⊗D⊕ᴿ) a b c |> mult (add (a, b), c) = add (mult(a, c), mult(b, c)) (𝟘X⊗ᴸ) a |> mult (zero, a) = zero (𝟘X⊗ᴿ) a |> mult (a, zero) = zero (⊖N⊕ᴸ) a |> add (neg (a), a) = zero (⊖N⊕ᴿ) a |> add (a, neg (a)) = zero (⊗C) a b |> mult(a, b) = mult(b, a) -} module CommRing.Signature where open import SOAS.Context open import SOAS.Common open import SOAS.Syntax.Signature *T public open import SOAS.Syntax.Build *T public -- Operator symbols data CRₒ : Set where zeroₒ addₒ oneₒ multₒ negₒ : CRₒ -- Term signature CR:Sig : Signature CRₒ CR:Sig = sig λ { zeroₒ → ⟼₀ * ; addₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ * ; oneₒ → ⟼₀ * ; multₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ * ; negₒ → (⊢₀ *) ⟼₁ * } open Signature CR:Sig public
{ "alphanum_fraction": 0.5062916358, "avg_line_length": 23.2931034483, "ext": "agda", "hexsha": "21e448f32f7ffe0ba851a14c7895613d0300ff13", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_path": "out/CommRing/Signature.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_path": "out/CommRing/Signature.agda", "max_line_length": 91, "max_stars_count": 39, "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_path": "out/CommRing/Signature.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "num_tokens": 686, "size": 1351 }
module examplesPaperJFP.Console where open import examplesPaperJFP.NativeIOSafe open import examplesPaperJFP.BasicIO hiding (main) open import examplesPaperJFP.ConsoleInterface public IOConsole : Set → Set IOConsole = IO ConsoleInterface --IOConsole+ : Set → Set --IOConsole+ = IO+ ConsoleInterface translateIOConsoleLocal : (c : ConsoleCommand) → NativeIO (ConsoleResponse c) translateIOConsoleLocal (putStrLn s) = nativePutStrLn s translateIOConsoleLocal getLine = nativeGetLine translateIOConsole : {A : Set} → IOConsole A → NativeIO A translateIOConsole = translateIO translateIOConsoleLocal main : NativeIO Unit main = nativePutStrLn "Console"
{ "alphanum_fraction": 0.7991004498, "avg_line_length": 30.3181818182, "ext": "agda", "hexsha": "38e20ccbd1cb8c1bec373c62530f52d5b011de9c", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z", "max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "agda/ooAgda", "max_forks_repo_path": "examples/examplesPaperJFP/Console.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "agda/ooAgda", "max_issues_repo_path": "examples/examplesPaperJFP/Console.agda", "max_line_length": 77, "max_stars_count": 23, "max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/ooAgda", "max_stars_repo_path": "examples/examplesPaperJFP/Console.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": 168, "size": 667 }
open import Signature import Program -- | Herbrand model that takes the distinction between inductive -- and coinductive clauses into account. module Herbrand (Σ : Sig) (V : Set) (P : Program.Program Σ V) where open import Function open import Data.Empty open import Data.Product as Prod renaming (Σ to ⨿) open import Data.Sum as Sum open import Relation.Unary hiding (_⇒_) open import Relation.Binary.PropositionalEquality hiding ([_]) open import Program Σ V open import Terms Σ mutual record Herbrand-ν (t : T∞ ⊥) : Set where coinductive field bw-closed : (∀ (i : dom-ν P) {σ} → (t ~ app∞ σ (χ (geth-ν P i))) → ∀ (j : dom (getb-ν P i)) → (app∞ σ (χ (get (getb-ν P i) j))) ∈ Herbrand-ν) ⊎ (t ∈ Herbrand-μ) data Herbrand-μ : T∞ ⊥ → Set where fw-closed : (t : T∞ ⊥) → (t ∈ Herbrand-μ) → (i : dom-μ P) (σ : Subst∞ V ⊥) → t ≡ app∞ σ (χ (geth-μ P i)) → (j : dom (getb-μ P i)) → Herbrand-μ (app∞ σ (χ (get (getb-μ P i) j))) coind-μ : {t : T∞ ⊥} → t ∈ Herbrand-ν → Herbrand-μ t open Herbrand-ν public
{ "alphanum_fraction": 0.5834084761, "avg_line_length": 30.8055555556, "ext": "agda", "hexsha": "afdc71420798a8b498d86517f0721513026d3459", "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/Herbrand.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/Herbrand.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/Herbrand.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 399, "size": 1109 }
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Bool.Base where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Data.Empty open import Cubical.Relation.Nullary open import Cubical.Relation.Nullary.DecidableEq -- Obtain the booleans open import Agda.Builtin.Bool public infixr 6 _and_ infixr 5 _or_ not : Bool → Bool not true = false not false = true _or_ : Bool → Bool → Bool false or false = false false or true = true true or false = true true or true = true _and_ : Bool → Bool → Bool false and false = false false and true = false true and false = false true and true = true caseBool : ∀ {ℓ} → {A : Type ℓ} → (a0 aS : A) → Bool → A caseBool att aff true = att caseBool att aff false = aff _≟_ : Discrete Bool false ≟ false = yes refl false ≟ true = no λ p → subst (caseBool ⊥ Bool) p true true ≟ false = no λ p → subst (caseBool Bool ⊥) p true true ≟ true = yes refl Dec→Bool : ∀ {ℓ} {A : Type ℓ} → Dec A → Bool Dec→Bool (yes p) = true Dec→Bool (no ¬p) = false
{ "alphanum_fraction": 0.6883988495, "avg_line_length": 21.7291666667, "ext": "agda", "hexsha": "e4c5f37352e54000c1f8d72db89f0e84fd6cf0b6", "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/Bool/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/Bool/Base.agda", "max_line_length": 56, "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/Bool/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 344, "size": 1043 }
{-# OPTIONS --safe #-} module Cubical.Algebra.CommRing.QuotientRing where open import Cubical.Foundations.Prelude open import Cubical.HITs.SetQuotients hiding (_/_) open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.Ideal open import Cubical.Algebra.Ring open import Cubical.Algebra.Ring.QuotientRing renaming (_/_ to _/Ring_) hiding (asRing) private variable ℓ : Level _/_ : (R : CommRing ℓ) → (I : IdealsIn R) → CommRing ℓ R / I = fst asRing , commringstr _ _ _ _ _ (iscommring (RingStr.isRing (snd asRing)) (elimProp2 (λ _ _ → squash/ _ _) commEq)) where asRing = (CommRing→Ring R) /Ring (CommIdeal→Ideal I) _·/_ : fst asRing → fst asRing → fst asRing _·/_ = RingStr._·_ (snd asRing) commEq : (x y : fst R) → ([ x ] ·/ [ y ]) ≡ ([ y ] ·/ [ x ]) commEq x y i = [ CommRingStr.·Comm (snd R) x y i ] [_]/ : {R : CommRing ℓ} {I : IdealsIn R} → (a : fst R) → fst (R / I) [ a ]/ = [ a ]
{ "alphanum_fraction": 0.5823754789, "avg_line_length": 32.625, "ext": "agda", "hexsha": "f5e2e55e58d506ef411151aa9f97a05fbbe39044", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "howsiyu/cubical", "max_forks_repo_path": "Cubical/Algebra/CommRing/QuotientRing.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "howsiyu/cubical", "max_issues_repo_path": "Cubical/Algebra/CommRing/QuotientRing.agda", "max_line_length": 87, "max_stars_count": null, "max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "howsiyu/cubical", "max_stars_repo_path": "Cubical/Algebra/CommRing/QuotientRing.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 333, "size": 1044 }
{-# OPTIONS --rewriting #-} module RingSolving where open import Data.Nat hiding (_≟_) open import Data.Nat.Properties hiding (_≟_) import Relation.Binary.PropositionalEquality open Relation.Binary.PropositionalEquality open import Agda.Builtin.Equality.Rewrite open import Function import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl) module _ (A : Set) where infixr 5 _+H_ infixr 6 _*H_ infixr 5 _:+_ infixr 6 _:*_ infixr 5 _+A_ infixr 6 _*A_ postulate #0 : A #1 : A _+A_ : A → A → A _*A_ : A → A → A data Poly : Set where con : A → Poly var : Poly _:+_ : Poly → Poly → Poly _:*_ : Poly → Poly → Poly data Horner : Set where PC : A → Horner PX : A → Horner → Horner scalMapHorner : (A → A) → Horner → Horner scalMapHorner f (PC x) = PC (f x) scalMapHorner f (PX x xs) = PX (f x) (scalMapHorner f xs) postulate extensionality : {S : Set}{T : S -> Set} {f g : (x : S) -> T x} -> ((x : S) -> f x ≡ g x) -> f ≡ g postulate +A-id-l : ∀ m → #0 +A m ≡ m *A-id-l : ∀ m → #1 *A m ≡ m +A-id-r : ∀ m → m +A #0 ≡ m *A-id-r : ∀ m → m *A #1 ≡ m +A-assoc : ∀ m n p → (m +A n) +A p ≡ m +A n +A p *A-assoc : ∀ m n p → (m *A n) *A p ≡ m *A n *A p +A-comm : ∀ m n → m +A n ≡ n +A m *A-comm : ∀ m n → m *A n ≡ n *A m *A-+A-distrib : ∀ m n p → m *A (n +A p) ≡ m *A n +A m *A p *A-annhiliate-r : ∀ m → m *A #0 ≡ #0 *A-annhiliate-l : ∀ m → #0 *A m ≡ #0 *A-+A-distrib′ : ∀ m n p → (m +A n) *A p ≡ m *A p +A n *A p *A-+A-distrib′ m n p = begin (m +A n) *A p ≡⟨ *A-comm (m +A n) p ⟩ p *A (m +A n) ≡⟨ *A-+A-distrib p m n ⟩ p *A m +A p *A n ≡⟨ cong₂ (_+A_) (*A-comm p m) (*A-comm p n) ⟩ m *A p +A n *A p ∎ where open ≡-Reasoning {-# REWRITE +A-id-l *A-id-l +A-id-r *A-id-r *A-annhiliate-r *A-annhiliate-l +A-assoc *A-assoc *A-+A-distrib #-} _+H_ : Horner → Horner → Horner _+H_ (PC x) (PC y) = PC (x +A y) _+H_ (PC x) (PX y ys) = PX (x +A y) ys _+H_ (PX x xs) (PC y) = PX (x +A y) xs _+H_ (PX x xs) (PX y ys) = PX (x +A y) (_+H_ xs ys) is-lt : (m : ℕ) → (n : ℕ) → n ⊔ (m Data.Nat.+ suc n) ≡ m Data.Nat.+ suc n is-lt m n = m≤n⇒m⊔n≡n $ begin n ≤⟨ n≤1+n n ⟩ suc n ≤⟨ m≤n+m (suc n) m ⟩ m Data.Nat.+ suc n ∎ where open ≤-Reasoning _*H_ : Horner → Horner → Horner _*H_ (PC x) y = scalMapHorner (x *A_) y _*H_ (PX x xs) y = (scalMapHorner (x *A_) y) +H (PX #0 (xs *H y)) evaluate : Horner → A → A evaluate (PC x) v = x evaluate (PX x xs) v = x +A (v *A evaluate xs v) varH : Horner varH = PX #0 $ PC #1 conH : A → Horner conH = PC construct : Poly → A → A construct (con x) a = x construct var a = a construct (p :+ p2) a = construct p a +A construct p2 a construct (p :* p2) a = construct p a *A construct p2 a normalize : Poly → Horner normalize (con x) = conH x normalize var = varH normalize (x :+ y) = normalize x +H normalize y normalize (x :* y) = normalize x *H normalize y swap : ∀ m n j k → (m +A n) +A (j +A k) ≡ (m +A j) +A (n +A k) swap m n j k = begin (m +A n) +A (j +A k) ≡⟨ +A-assoc m n (j +A k) ⟩ m +A (n +A (j +A k)) ≡⟨ cong (m +A_) $ sym $ +A-assoc n j k ⟩ m +A ((n +A j) +A k) ≡⟨ cong (\ φ → m +A (φ +A k)) $ +A-comm n j ⟩ m +A ((j +A n) +A k) ≡⟨ cong (m +A_) $ +A-assoc j n k ⟩ m +A (j +A (n +A k)) ≡⟨ sym $ +A-assoc m j (n +A k) ⟩ (m +A j) +A (n +A k) ∎ where open Eq.≡-Reasoning swap2-+A : ∀ m n p → m +A (n +A p) ≡ n +A (m +A p) swap2-+A m n p = begin m +A (n +A p) ≡⟨ +A-assoc m n p ⟩ (m +A n) +A p ≡⟨ cong ( _+A p) $ +A-comm m n ⟩ (n +A m) +A p ≡⟨ sym $ +A-assoc n m p ⟩ n +A (m +A p) ∎ where open Eq.≡-Reasoning swap2-*A : ∀ m n p → m *A (n *A p) ≡ n *A (m *A p) swap2-*A m n p = begin m *A (n *A p) ≡⟨ *A-assoc m n p ⟩ (m *A n) *A p ≡⟨ cong ( _*A p) $ *A-comm m n ⟩ (n *A m) *A p ≡⟨ sym $ *A-assoc n m p ⟩ n *A (m *A p) ∎ where open Eq.≡-Reasoning +A-+H-homo : ∀ j k a → evaluate j a +A evaluate k a ≡ evaluate (j +H k) a +A-+H-homo (PC x) (PC x₁) a = refl +A-+H-homo (PC x) (PX x₁ k) a = refl +A-+H-homo (PX x x₁) (PC x₂) a = begin x +A ((a *A evaluate x₁ a) +A x₂) ≡⟨ cong (x +A_) $ +A-comm (a *A evaluate x₁ a) x₂ ⟩ x +A (x₂ +A (a *A evaluate x₁ a)) ∎ where open Eq.≡-Reasoning +A-+H-homo (PX x x₁) (PX x₂ y) a rewrite +A-+H-homo x₁ y a = begin (x +A (a *A evaluate x₁ a)) +A (x₂ +A (a *A evaluate y a)) ≡⟨ swap x (a *A evaluate x₁ a) x₂ (a *A evaluate y a) ⟩ (x +A x₂) +A ((a *A evaluate x₁ a) +A (a *A evaluate y a)) ≡⟨ cong (\φ → (x +A x₂) +A φ) (sym $ *A-+A-distrib a (evaluate x₁ a) (evaluate y a)) ⟩ (x +A x₂) +A (a *A (evaluate x₁ a +A evaluate y a)) ≡⟨ cong (\φ → (x +A x₂) +A (a *A φ)) (+A-+H-homo x₁ y a) ⟩ (x +A x₂) +A (a *A evaluate (x₁ +H y) a) ∎ where open Eq.≡-Reasoning scale-evaluate : ∀ x k a → x *A evaluate k a ≡ evaluate (scalMapHorner (x *A_) k) a scale-evaluate x (PC x₁) a = refl scale-evaluate x (PX x₁ k) a = begin x *A evaluate (PX x₁ k) a ≡⟨⟩ x *A (x₁ +A (a *A evaluate k a)) ≡⟨ *A-+A-distrib x x₁ (a *A evaluate k a) ⟩ (x *A x₁) +A (x *A (a *A evaluate k a)) ≡⟨ cong ((x *A x₁) +A_) $ swap2-*A x a $ evaluate k a ⟩ (x *A x₁) +A (a *A (x *A evaluate k a)) ≡⟨ cong (\ φ → (x *A x₁) +A (a *A φ)) $ scale-evaluate x k a ⟩ (x *A x₁) +A (a *A evaluate (scalMapHorner (x *A_) k) a) ≡⟨⟩ evaluate (PX (x *A x₁) (scalMapHorner (x *A_) k)) a ≡⟨⟩ evaluate (scalMapHorner (x *A_) (PX x₁ k)) a ∎ where open Eq.≡-Reasoning *A-*H-homo : ∀ j k a → evaluate j a *A evaluate k a ≡ evaluate (j *H k) a *A-*H-homo (PC x) k a = scale-evaluate x k a *A-*H-homo (PX x j) k a = begin evaluate (PX x j) a *A evaluate k a ≡⟨⟩ (x +A a *A evaluate j a) *A evaluate k a ≡⟨ *A-+A-distrib′ x (a *A evaluate j a) (evaluate k a) ⟩ x *A (evaluate k a) +A (a *A evaluate j a) *A evaluate k a ≡⟨ cong₂ _+A_ (scale-evaluate x k a) (cong (a *A_) (*A-*H-homo j k a)) ⟩ evaluate (scalMapHorner (_*A_ x) k) a +A evaluate (PX #0 (j *H k)) a ≡⟨ +A-+H-homo (scalMapHorner (_*A_ x) k) (PX #0 (j *H k)) a ⟩ evaluate (scalMapHorner (_*A_ x) k +H PX #0 (j *H k)) a ≡⟨⟩ evaluate (PX x j *H k) a ∎ where open Eq.≡-Reasoning isoToConstruction : (x : Poly) → (a : A) → construct x a ≡ evaluate (normalize x) a isoToConstruction (con x) a = refl isoToConstruction var a = refl isoToConstruction (x :+ y) a rewrite isoToConstruction x a | isoToConstruction y a | +A-+H-homo (normalize x) (normalize y) a = refl isoToConstruction (x :* y) a rewrite isoToConstruction x a | isoToConstruction y a | *A-*H-homo (normalize x) (normalize y) a = refl solve : (x y : Poly) → normalize x ≡ normalize y → (a : A) → construct x a ≡ construct y a solve x y eq a = begin construct x a ≡⟨ isoToConstruction x a ⟩ evaluate (normalize x) a ≡⟨ cong (\φ → evaluate φ a) eq ⟩ evaluate (normalize y) a ≡⟨ sym $ isoToConstruction y a ⟩ construct y a ∎ where open Eq.≡-Reasoning test-a : Poly test-a = (var :+ con #1) :* (var :+ con #1) test-b : Poly test-b = var :* var :+ two :* var :+ con #1 where two = con #1 :+ con #1 blah : (x : A) → (x +A #1) *A (x +A #1) ≡ (x *A x) +A (#1 +A #1) *A x +A #1 blah x = solve test-a test-b refl x
{ "alphanum_fraction": 0.4891025641, "avg_line_length": 33.9130434783, "ext": "agda", "hexsha": "ccbf7cf90c4ac28651ac1bfdb2b751bc9cb4b39e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-02-17T08:46:57.000Z", "max_forks_repo_forks_event_min_datetime": "2022-02-17T08:46:57.000Z", "max_forks_repo_head_hexsha": "cf6faf7103acd54c67f3464b1968387a98dd8fa2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "dominiquedevriese/reviews", "max_forks_repo_path": "agda-src/RingSolving.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "cf6faf7103acd54c67f3464b1968387a98dd8fa2", "max_issues_repo_issues_event_max_datetime": "2022-02-17T16:51:24.000Z", "max_issues_repo_issues_event_min_datetime": "2022-02-17T09:10:00.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "dominiquedevriese/reviews", "max_issues_repo_path": "agda-src/RingSolving.agda", "max_line_length": 152, "max_stars_count": 7, "max_stars_repo_head_hexsha": "cf6faf7103acd54c67f3464b1968387a98dd8fa2", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "dominiquedevriese/reviews", "max_stars_repo_path": "agda-src/RingSolving.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-22T15:07:19.000Z", "max_stars_repo_stars_event_min_datetime": "2022-02-08T00:57:08.000Z", "num_tokens": 3445, "size": 7800 }
import Lvl open import Data.Boolean open import Type module Data.List.Sorting.Functions {ℓ} {T : Type{ℓ}} (_≤?_ : T → T → Bool) where open import Data.List import Data.List.Functions as List -- Inserts an element to a sorted list so that the resulting list is still sorted. insert : T → List(T) → List(T) insert x ∅ = List.singleton(x) insert x (y ⊰ l) = if(x ≤? y) then (x ⊰ y ⊰ l) else (y ⊰ insert x l) -- Merges two sorted lists so that the resulting list is still sorted. merge : List(T) → List(T) → List(T) merge = List.foldᵣ insert -- Merges a list of sorted lists so that the resulting list is still sorted. mergeAll : List(List(T)) → List(T) mergeAll = List.foldᵣ merge ∅ open import Data.Tuple open import Data.Option import Data.Option.Functions as Option -- Extracts a smallest element from a list. extractMinimal : List(T) → Option(T ⨯ List(T)) extractMinimal ∅ = None extractMinimal (x ⊰ ∅) = Some(x , ∅) extractMinimal (x ⊰ l@(_ ⊰ _)) = Option.map(\{(la , las) → if(x ≤? la) then (x , l) else (la , x ⊰ las)}) (extractMinimal l)
{ "alphanum_fraction": 0.6550777676, "avg_line_length": 34.15625, "ext": "agda", "hexsha": "619ba9d085a64ad5d58892eb88af4b0dd479d3f9", "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": "Data/List/Sorting/Functions.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": "Data/List/Sorting/Functions.agda", "max_line_length": 124, "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": "Data/List/Sorting/Functions.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": 331, "size": 1093 }
{-# OPTIONS --without-K #-} module Types where -- Universe levels postulate -- Universe levels Level : Set zero : Level suc : Level → Level max : Level → Level → Level {-# BUILTIN LEVEL Level #-} {-# BUILTIN LEVELZERO zero #-} {-# BUILTIN LEVELSUC suc #-} {-# BUILTIN LEVELMAX max #-} -- Empty type data ⊥ {i} : Set i where -- \bot abort : ∀ {i j} {P : ⊥ {i} → Set j} → ((x : ⊥) → P x) abort () abort-nondep : ∀ {i j} {A : Set j} → (⊥ {i} → A) abort-nondep () ¬ : ∀ {i} (A : Set i) → Set i ¬ A = A → ⊥ {zero} -- Unit type record unit {i} : Set i where constructor tt ⊤ = unit -- \top -- Booleans data bool {i} : Set i where true : bool false : bool -- Dependent sum record Σ {i j} (A : Set i) (P : A → Set j) : Set (max i j) where -- \Sigma constructor _,_ field π₁ : A -- \pi\_1 π₂ : P (π₁) -- \pi\_2 open Σ public -- Disjoint sum data _⊔_ {i j} (A : Set i) (B : Set j) : Set (max i j) where -- \sqcup inl : A → A ⊔ B inr : B → A ⊔ B -- Product _×_ : ∀ {i j} (A : Set i) (B : Set j) → Set (max i j) -- \times A × B = Σ A (λ _ → B) -- Dependent product Π : ∀ {i j} (A : Set i) (P : A → Set j) → Set (max i j) Π A P = (x : A) → P x -- Natural numbers data ℕ : Set where -- \bn O : ℕ S : (n : ℕ) → ℕ {-# BUILTIN NATURAL ℕ #-} {-# BUILTIN ZERO O #-} {-# BUILTIN SUC S #-} -- Truncation index (isomorphic to the type of integers ≥ -2) data ℕ₋₂ : Set where ⟨-2⟩ : ℕ₋₂ S : (n : ℕ₋₂) → ℕ₋₂ ⟨-1⟩ : ℕ₋₂ ⟨-1⟩ = S ⟨-2⟩ ⟨0⟩ : ℕ₋₂ ⟨0⟩ = S ⟨-1⟩ _-1 : ℕ → ℕ₋₂ O -1 = ⟨-1⟩ (S n) -1 = S (n -1) ⟨_⟩ : ℕ → ℕ₋₂ ⟨ n ⟩ = S (n -1) ⟨1⟩ = ⟨ 1 ⟩ ⟨2⟩ = ⟨ 2 ⟩ _+2+_ : ℕ₋₂ → ℕ₋₂ → ℕ₋₂ ⟨-2⟩ +2+ n = n S m +2+ n = S (m +2+ n) -- Integers data ℤ : Set where -- \bz O : ℤ pos : (n : ℕ) → ℤ neg : (n : ℕ) → ℤ -- Lifting record lift {i} (j : Level) (A : Set i) : Set (max i j) where constructor ↑ -- \u field ↓ : A -- \d open lift public
{ "alphanum_fraction": 0.4855794442, "avg_line_length": 16.2991452991, "ext": "agda", "hexsha": "1bc05a3599c20dd4e18b3d7aa7cf8f6d92004285", "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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "old/Types.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "old/Types.agda", "max_line_length": 75, "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": "old/Types.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": 843, "size": 1907 }
------------------------------------------------------------------------------ -- Auxiliary properties of the McCarthy 91 function ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.McCarthy91.AuxiliaryPropertiesATP where open import FOTC.Base open import FOTC.Data.Nat open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.Inequalities.PropertiesATP using ( x<y→y≤z→x<z ) open import FOTC.Data.Nat.PropertiesATP using ( +-N ; ∸-N ) open import FOTC.Data.Nat.UnaryNumbers open import FOTC.Data.Nat.UnaryNumbers.Inequalities.PropertiesATP using ( x<x+1 ) open import FOTC.Program.McCarthy91.ArithmeticATP open import FOTC.Program.McCarthy91.McCarthy91 ------------------------------------------------------------------------------ --- Auxiliary properties postulate x>100→x<f₉₁-x+11 : ∀ {n} → N n → n > 100' → n < f₉₁ n + 11' {-# ATP prove x>100→x<f₉₁-x+11 +-N ∸-N x<y→y≤z→x<z x<x+1 x+1≤x∸10+11 #-} -- Case n ≡ 100 can be proved automatically postulate f₉₁-100 : f₉₁ 100' ≡ 91' {-# ATP prove f₉₁-100 100+11>100 100+11∸10>100 101≡100+11∸10 91≡100+11∸10∸10 #-} postulate f₉₁x+11<f₉₁x+11 : ∀ n → n ≯ 100' → f₉₁ (n + 11') < f₉₁ (f₉₁ (n + 11')) + 11' → f₉₁ (n + 11') < f₉₁ n + 11' {-# ATP prove f₉₁x+11<f₉₁x+11 #-} postulate f₉₁-x≯100-helper : ∀ m n → m ≯ 100' → f₉₁ (m + 11') ≡ n → f₉₁ n ≡ 91' → f₉₁ m ≡ 91' {-# ATP prove f₉₁-x≯100-helper #-} postulate f₉₁-110 : f₉₁ (99' + 11') ≡ 100' f₉₁-109 : f₉₁ (98' + 11') ≡ 99' f₉₁-108 : f₉₁ (97' + 11') ≡ 98' f₉₁-107 : f₉₁ (96' + 11') ≡ 97' f₉₁-106 : f₉₁ (95' + 11') ≡ 96' f₉₁-105 : f₉₁ (94' + 11') ≡ 95' f₉₁-104 : f₉₁ (93' + 11') ≡ 94' f₉₁-103 : f₉₁ (92' + 11') ≡ 93' f₉₁-102 : f₉₁ (91' + 11') ≡ 92' f₉₁-101 : f₉₁ (90' + 11') ≡ 91' {-# ATP prove f₉₁-110 99+11>100 x+11∸10≡Sx #-} {-# ATP prove f₉₁-109 98+11>100 x+11∸10≡Sx #-} {-# ATP prove f₉₁-108 97+11>100 x+11∸10≡Sx #-} {-# ATP prove f₉₁-107 96+11>100 x+11∸10≡Sx #-} {-# ATP prove f₉₁-106 95+11>100 x+11∸10≡Sx #-} {-# ATP prove f₉₁-105 94+11>100 x+11∸10≡Sx #-} {-# ATP prove f₉₁-104 93+11>100 x+11∸10≡Sx #-} {-# ATP prove f₉₁-103 92+11>100 x+11∸10≡Sx #-} {-# ATP prove f₉₁-102 91+11>100 x+11∸10≡Sx #-} {-# ATP prove f₉₁-101 90+11>100 x+11∸10≡Sx #-} postulate f₉₁-99 : f₉₁ 99' ≡ 91' f₉₁-98 : f₉₁ 98' ≡ 91' f₉₁-97 : f₉₁ 97' ≡ 91' f₉₁-96 : f₉₁ 96' ≡ 91' f₉₁-95 : f₉₁ 95' ≡ 91' f₉₁-94 : f₉₁ 94' ≡ 91' f₉₁-93 : f₉₁ 93' ≡ 91' f₉₁-92 : f₉₁ 92' ≡ 91' f₉₁-91 : f₉₁ 91' ≡ 91' f₉₁-90 : f₉₁ 90' ≡ 91' {-# ATP prove f₉₁-99 f₉₁-x≯100-helper f₉₁-110 f₉₁-100 #-} {-# ATP prove f₉₁-98 f₉₁-x≯100-helper f₉₁-109 f₉₁-99 #-} {-# ATP prove f₉₁-97 f₉₁-x≯100-helper f₉₁-108 f₉₁-98 #-} {-# ATP prove f₉₁-96 f₉₁-x≯100-helper f₉₁-107 f₉₁-97 #-} {-# ATP prove f₉₁-95 f₉₁-x≯100-helper f₉₁-106 f₉₁-96 #-} {-# ATP prove f₉₁-94 f₉₁-x≯100-helper f₉₁-105 f₉₁-95 #-} {-# ATP prove f₉₁-93 f₉₁-x≯100-helper f₉₁-104 f₉₁-94 #-} {-# ATP prove f₉₁-92 f₉₁-x≯100-helper f₉₁-103 f₉₁-93 #-} {-# ATP prove f₉₁-91 f₉₁-x≯100-helper f₉₁-102 f₉₁-92 #-} {-# ATP prove f₉₁-90 f₉₁-x≯100-helper f₉₁-101 f₉₁-91 #-} f₉₁-x≡y : ∀ {m n o} → f₉₁ m ≡ n → o ≡ m → f₉₁ o ≡ n f₉₁-x≡y h refl = h
{ "alphanum_fraction": 0.5222568755, "avg_line_length": 37.1263157895, "ext": "agda", "hexsha": "d1bc19e731f762e475469ad6c287bd791b79e602", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Program/McCarthy91/AuxiliaryPropertiesATP.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Program/McCarthy91/AuxiliaryPropertiesATP.agda", "max_line_length": 80, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Program/McCarthy91/AuxiliaryPropertiesATP.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": 1639, "size": 3527 }
{-# OPTIONS --allow-unsolved-metas #-} module ExtractFunction where open import Agda.Builtin.Nat open import Agda.Builtin.Bool plus : Nat -> Nat -> Nat plus = {! !} function1 : (x : Nat) -> (y : Nat) -> Nat function1 x y = plus x y pickTheFirst : Nat -> Bool -> Nat pickTheFirst x y = x function2 : Nat -> Bool -> Nat function2 x y = pickTheFirst x y
{ "alphanum_fraction": 0.6527777778, "avg_line_length": 20, "ext": "agda", "hexsha": "7c3aaba3c81865926290b27b713c90ead5ba3362", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z", "max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z", "max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "omega12345/RefactorAgda", "max_forks_repo_path": "RefactorAgdaEngine/Test/Tests/input/ExtractFunction.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "omega12345/RefactorAgda", "max_issues_repo_path": "RefactorAgdaEngine/Test/Tests/input/ExtractFunction.agda", "max_line_length": 41, "max_stars_count": 5, "max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "omega12345/RefactorAgda", "max_stars_repo_path": "RefactorAgdaEngine/Test/Tests/input/ExtractFunction.agda", "max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z", "num_tokens": 112, "size": 360 }
{-# OPTIONS --without-K #-} open import Base open import Algebra.Groups open import Integers open import Homotopy.Truncation open import Homotopy.Pointed open import Homotopy.PathTruncation open import Homotopy.Connected -- Definitions and properties of homotopy groups module Homotopy.HomotopyGroups {i} where -- Loop space Ω : (X : pType i) → pType i Ω X = ⋆[ ⋆ X ≡ ⋆ X , refl ] Ω-pregroup : (X : pType i) → pregroup i Ω-pregroup X = record { carrier = (⋆ X) ≡ (⋆ X) ; _∙_ = _∘_ ; e = refl ; _′ = ! ; assoc = concat-assoc ; right-unit = refl-right-unit ; left-unit = λ _ → refl ; right-inverse = opposite-right-inverse ; left-inverse = opposite-left-inverse } Ωⁿ-pregroup : (n : ℕ) ⦃ ≢0 : n ≢ O ⦄ (X : pType i) → pregroup i Ωⁿ-pregroup O ⦃ ≢0 ⦄ X = abort-nondep (≢0 refl) Ωⁿ-pregroup 1 X = Ω-pregroup X Ωⁿ-pregroup (S (S n)) X = Ωⁿ-pregroup (S n) (Ω X) -- Homotopy groups πⁿ-group : (n : ℕ) ⦃ >0 : n ≢ O ⦄ (X : pType i) → group i πⁿ-group n X = π₀-pregroup (Ωⁿ-pregroup n X) fundamental-group : (X : pType i) → group i fundamental-group X = πⁿ-group 1 ⦃ ℕ-S≢O 0 ⦄ X -- Homotopy groups of loop space πⁿ-group-from-πⁿΩ : (n : ℕ) ⦃ ≢0 : n ≢ 0 ⦄ (X : pType i) → πⁿ-group (S n) X ≡ πⁿ-group n (Ω X) πⁿ-group-from-πⁿΩ O ⦃ ≢0 ⦄ X = abort-nondep (≢0 refl) πⁿ-group-from-πⁿΩ 1 X = refl πⁿ-group-from-πⁿΩ (S (S n)) X = refl -- Homotopy groups of spaces of a given h-level abstract truncated-πⁿ-group : (n : ℕ) ⦃ ≢0 : n ≢ 0 ⦄ (X : pType i) (p : is-truncated (n -1) ∣ X ∣) → πⁿ-group n X ≡ unit-group truncated-πⁿ-group O ⦃ ≢0 ⦄ X p = abort-nondep (≢0 refl) truncated-πⁿ-group 1 X p = unit-group-unique _ (proj refl , π₀-extend ⦃ p = λ x → truncated-is-truncated-S _ (π₀-is-set _ _ _) ⦄ (λ x → ap proj (π₁ (p _ _ _ _)))) truncated-πⁿ-group (S (S n)) X p = truncated-πⁿ-group (S n) (Ω X) (λ x y → p _ _ x y) Ωⁿ : (n : ℕ) (X : pType i) → pType i Ωⁿ 0 X = X Ωⁿ (S n) X = Ω (Ωⁿ n X) πⁿ : (n : ℕ) (X : pType i) → pType i πⁿ n X = τ⋆ ⟨0⟩ (Ωⁿ n X) other-πⁿ : (n : ℕ) (X : pType i) → pType i other-πⁿ n X = Ωⁿ n (τ⋆ ⟨ n ⟩ X) ap-Ω-equiv : (X Y : pType i) (e : X ≃⋆ Y) → Ω X ≃⋆ Ω Y ap-Ω-equiv X Y e = transport (λ u → Ω X ≃⋆ Ω u) (pType-eq e) (id-equiv⋆ _) τ⋆Ω-is-Ωτ⋆S : (n : ℕ₋₂) (X : pType i) → τ⋆ n (Ω X) ≃⋆ Ω (τ⋆ (S n) X) τ⋆Ω-is-Ωτ⋆S n X = (τ-path-equiv-path-τ-S , refl) τ⋆kΩⁿ-is-Ωⁿτ⋆n+k : (k n : ℕ) (X : pType i) → τ⋆ ⟨ k ⟩ (Ωⁿ n X) ≃⋆ Ωⁿ n (τ⋆ ⟨ n + k ⟩ X) τ⋆kΩⁿ-is-Ωⁿτ⋆n+k k O X = id-equiv⋆ _ τ⋆kΩⁿ-is-Ωⁿτ⋆n+k k (S n) X = equiv-compose⋆ (τ⋆Ω-is-Ωτ⋆S _ _) (ap-Ω-equiv _ _ (equiv-compose⋆ (τ⋆kΩⁿ-is-Ωⁿτ⋆n+k (S k) n _) (transport (λ u → Ωⁿ n (τ⋆ ⟨ n + S k ⟩ X) ≃⋆ Ωⁿ n (τ⋆ ⟨ u ⟩ X)) (+S-is-S+ n k) (id-equiv⋆ _)))) πⁿ-is-other-πⁿ : (n : ℕ) (X : pType i) → πⁿ n X ≃⋆ other-πⁿ n X πⁿ-is-other-πⁿ n X = transport (λ u → πⁿ n X ≃⋆ Ωⁿ n (τ⋆ ⟨ u ⟩ X)) (+0-is-id n) (τ⋆kΩⁿ-is-Ωⁿτ⋆n+k 0 n X) contr-is-contr-Ω : (X : pType i) → (is-contr⋆ X → is-contr⋆ (Ω X)) contr-is-contr-Ω X p = ≡-is-truncated ⟨-2⟩ p contr-is-contr-Ωⁿ : (n : ℕ) (X : pType i) → (is-contr⋆ X) → is-contr⋆ (Ωⁿ n X) contr-is-contr-Ωⁿ O X p = p contr-is-contr-Ωⁿ (S n) X p = contr-is-contr-Ω _ (contr-is-contr-Ωⁿ n X p) connected-other-πⁿ : (k n : ℕ) (lt : k < S n) (X : pType i) → (is-connected⋆ ⟨ n ⟩ X → is-contr⋆ (other-πⁿ k X)) connected-other-πⁿ k n lt X p = contr-is-contr-Ωⁿ k _ (connected⋆-lt k n lt X p) connected-πⁿ : (k n : ℕ) (lt : k < S n) (X : pType i) → (is-connected⋆ ⟨ n ⟩ X → is-contr⋆ (πⁿ k X)) connected-πⁿ k n lt X p = equiv-types-truncated _ (π₁ (πⁿ-is-other-πⁿ k X) ⁻¹) (connected-other-πⁿ k n lt X p)
{ "alphanum_fraction": 0.5505036755, "avg_line_length": 32.2192982456, "ext": "agda", "hexsha": "c658083bdbcdb3ebafa13a328507b7ddf1bf5811", "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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "old/Homotopy/HomotopyGroups.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "old/Homotopy/HomotopyGroups.agda", "max_line_length": 78, "max_stars_count": 294, "max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda", "max_stars_repo_path": "old/Homotopy/HomotopyGroups.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": 1881, "size": 3673 }
{-# OPTIONS -W ignore #-} module Issue2596b where -- This warning will be ignored {-# REWRITE #-} -- but this error will still be raised f : Set f = f
{ "alphanum_fraction": 0.660130719, "avg_line_length": 15.3, "ext": "agda", "hexsha": "c1c574cc275200f3e35958ebcb759fce0cbd297e", "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/Issue2596b.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/Issue2596b.agda", "max_line_length": 38, "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/Issue2596b.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": 41, "size": 153 }
{-# OPTIONS --without-K #-} module hott.level.sets.core where open import sum open import equality.core open import sets.unit open import sets.empty open import hott.level.core ⊤-contr : ∀ {i} → contr (⊤ {i}) ⊤-contr = tt , λ { tt → refl } ⊥-prop : ∀ {i} → h 1 (⊥ {i}) ⊥-prop x _ = ⊥-elim x
{ "alphanum_fraction": 0.6224489796, "avg_line_length": 19.6, "ext": "agda", "hexsha": "9bd99c35ee3e92169a8cea0e4c90dcfe4ebc5280", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z", "max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pcapriotti/agda-base", "max_forks_repo_path": "src/hott/level/sets/core.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_path": "src/hott/level/sets/core.agda", "max_line_length": 33, "max_stars_count": 20, "max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pcapriotti/agda-base", "max_stars_repo_path": "src/hott/level/sets/core.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z", "num_tokens": 107, "size": 294 }
{-# OPTIONS --without-K #-} module equality.core where open import sum open import level using () open import function.core infix 4 _≡_ data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x sym : ∀ {i} {A : Set i} {x y : A} → x ≡ y → y ≡ x sym refl = refl _·_ : ∀ {i}{X : Set i}{x y z : X} → x ≡ y → y ≡ z → x ≡ z refl · p = p infixl 9 _·_ ap : ∀ {i j}{A : Set i}{B : Set j}{x y : A} → (f : A → B) → x ≡ y → f x ≡ f y ap f refl = refl ap₂ : ∀ {i j k}{A : Set i}{B : Set j}{C : Set k} {x x' : A}{y y' : B} → (f : A → B → C) → x ≡ x' → y ≡ y' → f x y ≡ f x' y' ap₂ f refl refl = refl subst : ∀ {i j} {A : Set i}{x y : A} → (B : A → Set j) → x ≡ y → B x → B y subst B refl = id subst₂ : ∀ {i j k} {A : Set i}{x x' : A} {B : Set j}{y y' : B} → (C : A → B → Set k) → x ≡ x' → y ≡ y' → C x y → C x' y' subst₂ C refl refl = id singleton : ∀ {i}{A : Set i} → A → Set i singleton {A = A} a = Σ A λ a' → a ≡ a' singleton' : ∀ {i}{A : Set i} → A → Set i singleton' {A = A} a = Σ A λ a' → a' ≡ a J' : ∀ {i j}{X : Set i}{x : X} → (P : (y : X) → x ≡ y → Set j) → P x refl → (y : X) → (p : x ≡ y) → P y p J' P u y refl = u J : ∀ {i j}{X : Set i} → (P : (x y : X) → x ≡ y → Set j) → ((x : X) → P x x refl) → (x y : X) → (p : x ≡ y) → P x y p J P u x y p = J' (P x) (u x) y p
{ "alphanum_fraction": 0.3981213873, "avg_line_length": 21.2923076923, "ext": "agda", "hexsha": "3821c6b1fc0cd49f7f1d930a4a667458661a15f2", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z", "max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "HoTT/M-types", "max_forks_repo_path": "equality/core.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_path": "src/equality/core.agda", "max_line_length": 50, "max_stars_count": 27, "max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "HoTT/M-types", "max_stars_repo_path": "equality/core.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z", "num_tokens": 651, "size": 1384 }
-- The ATP pragma with the role <hint> can be used with functions. module ATPHint where postulate D : Set data _≡_ (x : D) : D → Set where refl : x ≡ x sym : ∀ {m n} → m ≡ n → n ≡ m sym refl = refl {-# ATP hint sym #-}
{ "alphanum_fraction": 0.5859030837, "avg_line_length": 16.2142857143, "ext": "agda", "hexsha": "236010f509616d05866b812877e743ce9bd1507c", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z", "max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/apia", "max_forks_repo_path": "examples/ATPHint.agda", "max_issues_count": 121, "max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/apia", "max_issues_repo_path": "examples/ATPHint.agda", "max_line_length": 66, "max_stars_count": 10, "max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/apia", "max_stars_repo_path": "examples/ATPHint.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z", "num_tokens": 81, "size": 227 }
{-# OPTIONS --cubical-compatible #-} open import Agda.Builtin.Bool data D : Bool → Set where true : D true false : D false F : @0 D false → Set₁ F false = Set
{ "alphanum_fraction": 0.6407185629, "avg_line_length": 15.1818181818, "ext": "agda", "hexsha": "cdc0703418ae6cf51874a26af15b87972bba9e55", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Fail/Issue4172-2.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/Fail/Issue4172-2.agda", "max_line_length": 36, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Fail/Issue4172-2.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 52, "size": 167 }
------------------------------------------------------------------------ -- Abstract well-formed typing contexts ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module Data.Context.WellFormed where open import Level using (suc; _⊔_; Lift; lift) open import Data.Fin using (Fin) open import Data.Fin.Substitution.ExtraLemmas open import Data.Nat using (ℕ) open import Data.Unit using (⊤; tt) open import Data.Vec.Relation.Unary.All as All using (All; []; _∷_) open import Data.Vec.Relation.Unary.All.Properties using (gmap) open import Relation.Binary using (REL) open import Relation.Unary using (Pred) open import Data.Context ------------------------------------------------------------------------ -- Abstract well-formed typing -- An abtract well-formedness judgment _⊢_wf : Wf Tp Tm is a binary -- relation which, in a given Tp-context, asserts the well-formedness -- of Tm-terms. Wf : ∀ {t₁ t₂} → Pred ℕ t₁ → Pred ℕ t₂ → ∀ ℓ → Set (t₁ ⊔ t₂ ⊔ suc ℓ) Wf Tp Tm ℓ = ∀ {n} → REL (Ctx Tp n) (Tm n) ℓ ------------------------------------------------------------------------ -- Abstract well-formed typing contexts and context extensions. -- -- A well-formed typing context (Γ wf) is a context Γ in which every -- participating T-type is well-formed. module ContextFormation {t ℓ} {T : Pred ℕ t} (_⊢_wf : Wf T T ℓ) where infix 4 _wf _⊢_wfExt infixr 5 _∷_ -- Well-formed typing contexts and context extensions. data _wf : ∀ {n} → Ctx T n → Set (t ⊔ ℓ) where [] : [] wf _∷_ : ∀ {n t} {Γ : Ctx T n} → Γ ⊢ t wf → Γ wf → t ∷ Γ wf data _⊢_wfExt {m} (Γ : Ctx T m) : ∀ {n} → CtxExt T m n → Set (t ⊔ ℓ) where [] : Γ ⊢ [] wfExt _∷_ : ∀ {n t} {Δ : CtxExt T m n} → (Δ ++ Γ) ⊢ t wf → Γ ⊢ Δ wfExt → Γ ⊢ t ∷ Δ wfExt -- Inversions. wf-∷₁ : ∀ {n} {Γ : Ctx T n} {a} → a ∷ Γ wf → Γ ⊢ a wf wf-∷₁ (a-wf ∷ _) = a-wf wf-∷₂ : ∀ {n} {Γ : Ctx T n} {a} → a ∷ Γ wf → Γ wf wf-∷₂ (_ ∷ Γ-wf) = Γ-wf wfExt-∷₁ : ∀ {m n} {Γ : Ctx T m} {Δ : CtxExt T m n} {a} → Γ ⊢ a ∷ Δ wfExt → (Δ ++ Γ) ⊢ a wf wfExt-∷₁ (a-wf ∷ _) = a-wf wfExt-∷₂ : ∀ {m n} {Γ : Ctx T m} {Δ : CtxExt T m n} {a} → Γ ⊢ a ∷ Δ wfExt → Γ ⊢ Δ wfExt wfExt-∷₂ (_ ∷ Γ-wf) = Γ-wf -- Operations on well-formed contexts that require weakening of -- well-formedness judgments. record WellFormedWeakenOps (typeExtension : Extension T) : Set (suc (t ⊔ ℓ)) where private module C = WeakenOps typeExtension open C hiding (lookup; extLookup) -- Weakening of well-formedness judgments. field wf-weaken : ∀ {n} {Γ : Ctx T n} {a b} → Γ ⊢ a wf → Γ ⊢ b wf → (a ∷ Γ) ⊢ weaken b wf -- Convert a well-formed context (extension) to its All representation. toAll : ∀ {n} {Γ : Ctx T n} → Γ wf → All (λ t → Γ ⊢ t wf) (toVec Γ) toAll [] = [] toAll (t-wf ∷ Γ-wf) = wf-weaken t-wf t-wf ∷ gmap (wf-weaken t-wf) (toAll Γ-wf) extToAll : ∀ {m n} {Γ : Ctx T m} {Δ : CtxExt T m n} → All (λ t → Γ ⊢ t wf) (toVec Γ) → Γ ⊢ Δ wfExt → All (λ a → (Δ ++ Γ) ⊢ a wf) (toVec (Δ ++ Γ)) extToAll ts-wf [] = ts-wf extToAll ts-wf (t-wf ∷ Δ-wfExt) = wf-weaken t-wf t-wf ∷ gmap (wf-weaken t-wf) (extToAll ts-wf Δ-wfExt) -- Lookup the well-formedness proof of a variable in a context. lookup : ∀ {n} {Γ : Ctx T n} → Γ wf → (x : Fin n) → Γ ⊢ (C.lookup Γ x) wf lookup Γ-wf x = All.lookup x (toAll Γ-wf) extLookup : ∀ {m n} {Γ : Ctx T m} {Δ : CtxExt T m n} → All (λ t → Γ ⊢ t wf) (toVec Γ) → Γ ⊢ Δ wfExt → ∀ x → (Δ ++ Γ) ⊢ (C.lookup (Δ ++ Γ) x) wf extLookup ts-wf Γ-wf x = All.lookup x (extToAll ts-wf Γ-wf) ------------------------------------------------------------------------ -- Trivial well-formedness. -- -- This module provides a trivial well-formedness relation and the -- corresponding trivially well-formed contexts. This is useful when -- implmenting typed substitutions on types that either lack or do not -- necessitate a notion of well-formedness. module ⊤-WellFormed {ℓ} {T : Pred ℕ ℓ} (typeExtension : Extension T) where infix 4 _⊢_wf -- Trivial well-formedness. _⊢_wf : Wf T T ℓ _ ⊢ _ wf = Lift ℓ ⊤ open ContextFormation _⊢_wf public -- Trivial well-formedness of contexts and context extensions. ctx-wf : ∀ {n} (Γ : Ctx T n) → Γ wf ctx-wf [] = [] ctx-wf (a ∷ Γ) = lift tt ∷ ctx-wf Γ ctx-wfExt : ∀ {m n} (Δ : CtxExt T m n) {Γ : Ctx T m} → Γ ⊢ Δ wfExt ctx-wfExt [] = [] ctx-wfExt (a ∷ Δ) = lift tt ∷ ctx-wfExt Δ module ⊤-WfWeakenOps where wfWeakenOps : WellFormedWeakenOps typeExtension wfWeakenOps = record { wf-weaken = λ _ _ → lift tt } open WellFormedWeakenOps public
{ "alphanum_fraction": 0.5263266146, "avg_line_length": 33.5310344828, "ext": "agda", "hexsha": "532afdd778e18116bfd6732475b97db09bc4d715", "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": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_path": "src/Data/Context/WellFormed.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "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": "Blaisorblade/f-omega-int-agda", "max_issues_repo_path": "src/Data/Context/WellFormed.agda", "max_line_length": 77, "max_stars_count": null, "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_path": "src/Data/Context/WellFormed.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1718, "size": 4862 }
{-# OPTIONS --without-K --safe #-} module Definition.Typed.Properties where open import Definition.Untyped open import Definition.Typed open import Tools.Empty using (⊥; ⊥-elim) open import Tools.Product import Tools.PropositionalEquality as PE -- Escape context extraction wfTerm : ∀ {Γ A t} → Γ ⊢ t ∷ A → ⊢ Γ wfTerm (ℕⱼ ⊢Γ) = ⊢Γ wfTerm (Emptyⱼ ⊢Γ) = ⊢Γ wfTerm (Unitⱼ ⊢Γ) = ⊢Γ wfTerm (Πⱼ F ▹ G) = wfTerm F wfTerm (var ⊢Γ x₁) = ⊢Γ wfTerm (lamⱼ F t) with wfTerm t wfTerm (lamⱼ F t) | ⊢Γ ∙ F′ = ⊢Γ wfTerm (g ∘ⱼ a) = wfTerm a wfTerm (zeroⱼ ⊢Γ) = ⊢Γ wfTerm (sucⱼ n) = wfTerm n wfTerm (natrecⱼ F z s n) = wfTerm z wfTerm (Emptyrecⱼ A e) = wfTerm e wfTerm (starⱼ ⊢Γ) = ⊢Γ wfTerm (conv t A≡B) = wfTerm t wfTerm (Σⱼ a ▹ a₁) = wfTerm a wfTerm (prodⱼ F G a a₁) = wfTerm a wfTerm (fstⱼ _ _ a) = wfTerm a wfTerm (sndⱼ _ _ a) = wfTerm a wf : ∀ {Γ A} → Γ ⊢ A → ⊢ Γ wf (ℕⱼ ⊢Γ) = ⊢Γ wf (Emptyⱼ ⊢Γ) = ⊢Γ wf (Unitⱼ ⊢Γ) = ⊢Γ wf (Uⱼ ⊢Γ) = ⊢Γ wf (Πⱼ F ▹ G) = wf F wf (Σⱼ F ▹ G) = wf F wf (univ A) = wfTerm A wfEqTerm : ∀ {Γ A t u} → Γ ⊢ t ≡ u ∷ A → ⊢ Γ wfEqTerm (refl t) = wfTerm t wfEqTerm (sym t≡u) = wfEqTerm t≡u wfEqTerm (trans t≡u u≡r) = wfEqTerm t≡u wfEqTerm (conv t≡u A≡B) = wfEqTerm t≡u wfEqTerm (Π-cong F F≡H G≡E) = wfEqTerm F≡H wfEqTerm (app-cong f≡g a≡b) = wfEqTerm f≡g wfEqTerm (β-red F t a) = wfTerm a wfEqTerm (η-eq F f g f0≡g0) = wfTerm f wfEqTerm (suc-cong n) = wfEqTerm n wfEqTerm (natrec-cong F≡F′ z≡z′ s≡s′ n≡n′) = wfEqTerm z≡z′ wfEqTerm (natrec-zero F z s) = wfTerm z wfEqTerm (natrec-suc n F z s) = wfTerm n wfEqTerm (Emptyrec-cong A≡A' e≡e') = wfEqTerm e≡e' wfEqTerm (η-unit e e') = wfTerm e wfEqTerm (Σ-cong F _ _) = wf F wfEqTerm (fst-cong _ _ a) = wfEqTerm a wfEqTerm (snd-cong _ _ a) = wfEqTerm a wfEqTerm (Σ-η _ _ x _ _ _) = wfTerm x wfEqTerm (Σ-β₁ F G x x₁) = wfTerm x wfEqTerm (Σ-β₂ F G x x₁) = wfTerm x wfEq : ∀ {Γ A B} → Γ ⊢ A ≡ B → ⊢ Γ wfEq (univ A≡B) = wfEqTerm A≡B wfEq (refl A) = wf A wfEq (sym A≡B) = wfEq A≡B wfEq (trans A≡B B≡C) = wfEq A≡B wfEq (Π-cong F F≡H G≡E) = wf F wfEq (Σ-cong F x₁ x₂) = wf F -- Reduction is a subset of conversion subsetTerm : ∀ {Γ A t u} → Γ ⊢ t ⇒ u ∷ A → Γ ⊢ t ≡ u ∷ A subsetTerm (natrec-subst F z s n⇒n′) = natrec-cong (refl F) (refl z) (refl s) (subsetTerm n⇒n′) subsetTerm (natrec-zero F z s) = natrec-zero F z s subsetTerm (natrec-suc n F z s) = natrec-suc n F z s subsetTerm (Emptyrec-subst A n⇒n′) = Emptyrec-cong (refl A) (subsetTerm n⇒n′) subsetTerm (app-subst t⇒u a) = app-cong (subsetTerm t⇒u) (refl a) subsetTerm (β-red A t a) = β-red A t a subsetTerm (conv t⇒u A≡B) = conv (subsetTerm t⇒u) A≡B subsetTerm (fst-subst F G x) = fst-cong F G (subsetTerm x) subsetTerm (snd-subst F G x) = snd-cong F G (subsetTerm x) subsetTerm (Σ-β₁ F G x x₁) = Σ-β₁ F G x x₁ subsetTerm (Σ-β₂ F G x x₁) = Σ-β₂ F G x x₁ subset : ∀ {Γ A B} → Γ ⊢ A ⇒ B → Γ ⊢ A ≡ B subset (univ A⇒B) = univ (subsetTerm A⇒B) subset*Term : ∀ {Γ A t u} → Γ ⊢ t ⇒* u ∷ A → Γ ⊢ t ≡ u ∷ A subset*Term (id t) = refl t subset*Term (t⇒t′ ⇨ t⇒*u) = trans (subsetTerm t⇒t′) (subset*Term t⇒*u) subset* : ∀ {Γ A B} → Γ ⊢ A ⇒* B → Γ ⊢ A ≡ B subset* (id A) = refl A subset* (A⇒A′ ⇨ A′⇒*B) = trans (subset A⇒A′) (subset* A′⇒*B) -- Can extract left-part of a reduction redFirstTerm : ∀ {Γ t u A} → Γ ⊢ t ⇒ u ∷ A → Γ ⊢ t ∷ A redFirstTerm (conv t⇒u A≡B) = conv (redFirstTerm t⇒u) A≡B redFirstTerm (app-subst t⇒u a) = (redFirstTerm t⇒u) ∘ⱼ a redFirstTerm (β-red A t a) = (lamⱼ A t) ∘ⱼ a redFirstTerm (natrec-subst F z s n⇒n′) = natrecⱼ F z s (redFirstTerm n⇒n′) redFirstTerm (natrec-zero F z s) = natrecⱼ F z s (zeroⱼ (wfTerm z)) redFirstTerm (natrec-suc n F z s) = natrecⱼ F z s (sucⱼ n) redFirstTerm (Emptyrec-subst A n⇒n′) = Emptyrecⱼ A (redFirstTerm n⇒n′) redFirstTerm (fst-subst F G x) = fstⱼ F G (redFirstTerm x) redFirstTerm (snd-subst F G x) = sndⱼ F G (redFirstTerm x) redFirstTerm (Σ-β₁ F G x x₁) = fstⱼ F G (prodⱼ F G x x₁) redFirstTerm (Σ-β₂ F G x x₁) = sndⱼ F G (prodⱼ F G x x₁) redFirst : ∀ {Γ A B} → Γ ⊢ A ⇒ B → Γ ⊢ A redFirst (univ A⇒B) = univ (redFirstTerm A⇒B) redFirst*Term : ∀ {Γ t u A} → Γ ⊢ t ⇒* u ∷ A → Γ ⊢ t ∷ A redFirst*Term (id t) = t redFirst*Term (t⇒t′ ⇨ t′⇒*u) = redFirstTerm t⇒t′ redFirst* : ∀ {Γ A B} → Γ ⊢ A ⇒* B → Γ ⊢ A redFirst* (id A) = A redFirst* (A⇒A′ ⇨ A′⇒*B) = redFirst A⇒A′ -- No neutral terms are well-formed in an empty context noNe : ∀ {t A} → ε ⊢ t ∷ A → Neutral t → ⊥ noNe (conv ⊢t x) n = noNe ⊢t n noNe (var x₁ ()) (var x) noNe (⊢t ∘ⱼ ⊢t₁) (∘ₙ neT) = noNe ⊢t neT noNe (fstⱼ _ _ ⊢t) (fstₙ neT) = noNe ⊢t neT noNe (sndⱼ _ _ ⊢t) (sndₙ neT) = noNe ⊢t neT noNe (natrecⱼ x ⊢t ⊢t₁ ⊢t₂) (natrecₙ neT) = noNe ⊢t₂ neT noNe (Emptyrecⱼ A ⊢e) (Emptyrecₙ neT) = noNe ⊢e neT -- Neutrals do not weak head reduce neRedTerm : ∀ {Γ t u A} (d : Γ ⊢ t ⇒ u ∷ A) (n : Neutral t) → ⊥ neRedTerm (conv d x) n = neRedTerm d n neRedTerm (app-subst d x) (∘ₙ n) = neRedTerm d n neRedTerm (β-red x x₁ x₂) (∘ₙ ()) neRedTerm (natrec-subst x x₁ x₂ d) (natrecₙ n₁) = neRedTerm d n₁ neRedTerm (natrec-zero x x₁ x₂) (natrecₙ ()) neRedTerm (natrec-suc x x₁ x₂ x₃) (natrecₙ ()) neRedTerm (Emptyrec-subst x d) (Emptyrecₙ n₁) = neRedTerm d n₁ neRedTerm (fst-subst _ _ d) (fstₙ n) = neRedTerm d n neRedTerm (snd-subst _ _ d) (sndₙ n) = neRedTerm d n neRedTerm (Σ-β₁ F G x x₁) (fstₙ ()) neRedTerm (Σ-β₂ F G x x₁) (sndₙ ()) neRed : ∀ {Γ A B} (d : Γ ⊢ A ⇒ B) (N : Neutral A) → ⊥ neRed (univ x) N = neRedTerm x N -- Whnfs do not weak head reduce whnfRedTerm : ∀ {Γ t u A} (d : Γ ⊢ t ⇒ u ∷ A) (w : Whnf t) → ⊥ whnfRedTerm (conv d x) w = whnfRedTerm d w whnfRedTerm (app-subst d x) (ne (∘ₙ x₁)) = neRedTerm d x₁ whnfRedTerm (β-red x x₁ x₂) (ne (∘ₙ ())) whnfRedTerm (natrec-subst x x₁ x₂ d) (ne (natrecₙ x₃)) = neRedTerm d x₃ whnfRedTerm (natrec-zero x x₁ x₂) (ne (natrecₙ ())) whnfRedTerm (natrec-suc x x₁ x₂ x₃) (ne (natrecₙ ())) whnfRedTerm (Emptyrec-subst x d) (ne (Emptyrecₙ x₂)) = neRedTerm d x₂ whnfRedTerm (fst-subst _ _ d) (ne (fstₙ n)) = neRedTerm d n whnfRedTerm (snd-subst _ _ d) (ne (sndₙ n)) = neRedTerm d n whnfRedTerm (Σ-β₁ F G x x₁) (ne (fstₙ ())) whnfRedTerm (Σ-β₂ F G x x₁) (ne (sndₙ ())) whnfRed : ∀ {Γ A B} (d : Γ ⊢ A ⇒ B) (w : Whnf A) → ⊥ whnfRed (univ x) w = whnfRedTerm x w whnfRed*Term : ∀ {Γ t u A} (d : Γ ⊢ t ⇒* u ∷ A) (w : Whnf t) → t PE.≡ u whnfRed*Term (id x) Uₙ = PE.refl whnfRed*Term (id x) Πₙ = PE.refl whnfRed*Term (id x) Σₙ = PE.refl whnfRed*Term (id x) ℕₙ = PE.refl whnfRed*Term (id x) Emptyₙ = PE.refl whnfRed*Term (id x) Unitₙ = PE.refl whnfRed*Term (id x) lamₙ = PE.refl whnfRed*Term (id x) prodₙ = PE.refl whnfRed*Term (id x) zeroₙ = PE.refl whnfRed*Term (id x) sucₙ = PE.refl whnfRed*Term (id x) starₙ = PE.refl whnfRed*Term (id x) (ne x₁) = PE.refl whnfRed*Term (conv x x₁ ⇨ d) w = ⊥-elim (whnfRedTerm x w) whnfRed*Term (x ⇨ d) (ne x₁) = ⊥-elim (neRedTerm x x₁) whnfRed* : ∀ {Γ A B} (d : Γ ⊢ A ⇒* B) (w : Whnf A) → A PE.≡ B whnfRed* (id x) w = PE.refl whnfRed* (x ⇨ d) w = ⊥-elim (whnfRed x w) -- Whr is deterministic whrDetTerm : ∀{Γ t u A u′ A′} (d : Γ ⊢ t ⇒ u ∷ A) (d′ : Γ ⊢ t ⇒ u′ ∷ A′) → u PE.≡ u′ whrDetTerm (conv d x) d′ = whrDetTerm d d′ whrDetTerm d (conv d′ x₁) = whrDetTerm d d′ whrDetTerm (app-subst d x) (app-subst d′ x₁) rewrite whrDetTerm d d′ = PE.refl whrDetTerm (β-red x x₁ x₂) (β-red x₃ x₄ x₅) = PE.refl whrDetTerm (fst-subst _ _ x) (fst-subst _ _ y) rewrite whrDetTerm x y = PE.refl whrDetTerm (snd-subst _ _ x) (snd-subst _ _ y) rewrite whrDetTerm x y = PE.refl whrDetTerm (Σ-β₁ F G x x₁) (Σ-β₁ F₁ G₁ x₂ x₃) = PE.refl whrDetTerm (Σ-β₂ F G x x₁) (Σ-β₂ F₁ G₁ x₂ x₃) = PE.refl whrDetTerm (natrec-subst x x₁ x₂ d) (natrec-subst x₃ x₄ x₅ d′) rewrite whrDetTerm d d′ = PE.refl whrDetTerm (natrec-zero x x₁ x₂) (natrec-zero x₃ x₄ x₅) = PE.refl whrDetTerm (natrec-suc x x₁ x₂ x₃) (natrec-suc x₄ x₅ x₆ x₇) = PE.refl whrDetTerm (Emptyrec-subst x d) (Emptyrec-subst x₂ d′) rewrite whrDetTerm d d′ = PE.refl whrDetTerm (app-subst d x) (β-red x₁ x₂ x₃) = ⊥-elim (whnfRedTerm d lamₙ) whrDetTerm (β-red x x₁ x₂) (app-subst d x₃) = ⊥-elim (whnfRedTerm d lamₙ) whrDetTerm (natrec-subst x x₁ x₂ d) (natrec-zero x₃ x₄ x₅) = ⊥-elim (whnfRedTerm d zeroₙ) whrDetTerm (natrec-subst x x₁ x₂ d) (natrec-suc x₃ x₄ x₅ x₆) = ⊥-elim (whnfRedTerm d sucₙ) whrDetTerm (natrec-zero x x₁ x₂) (natrec-subst x₃ x₄ x₅ d′) = ⊥-elim (whnfRedTerm d′ zeroₙ) whrDetTerm (natrec-suc x x₁ x₂ x₃) (natrec-subst x₄ x₅ x₆ d′) = ⊥-elim (whnfRedTerm d′ sucₙ) whrDetTerm (fst-subst _ _ x) (Σ-β₁ F G x₁ x₂) = ⊥-elim (whnfRedTerm x prodₙ) whrDetTerm (snd-subst _ _ x) (Σ-β₂ F G x₁ x₂) = ⊥-elim (whnfRedTerm x prodₙ) whrDetTerm (Σ-β₁ F G x x₁) (fst-subst _ _ y) = ⊥-elim (whnfRedTerm y prodₙ) whrDetTerm (Σ-β₂ F G x x₁) (snd-subst _ _ y) = ⊥-elim (whnfRedTerm y prodₙ) whrDet : ∀{Γ A B B′} (d : Γ ⊢ A ⇒ B) (d′ : Γ ⊢ A ⇒ B′) → B PE.≡ B′ whrDet (univ x) (univ x₁) = whrDetTerm x x₁ whrDet↘Term : ∀{Γ t u A u′} (d : Γ ⊢ t ↘ u ∷ A) (d′ : Γ ⊢ t ⇒* u′ ∷ A) → Γ ⊢ u′ ⇒* u ∷ A whrDet↘Term (proj₁ , proj₂) (id x) = proj₁ whrDet↘Term (id x , proj₂) (x₁ ⇨ d′) = ⊥-elim (whnfRedTerm x₁ proj₂) whrDet↘Term (x ⇨ proj₁ , proj₂) (x₁ ⇨ d′) = whrDet↘Term (PE.subst (λ x₂ → _ ⊢ x₂ ↘ _ ∷ _) (whrDetTerm x x₁) (proj₁ , proj₂)) d′ whrDet*Term : ∀{Γ t u A u′} (d : Γ ⊢ t ↘ u ∷ A) (d′ : Γ ⊢ t ↘ u′ ∷ A) → u PE.≡ u′ whrDet*Term (id x , proj₂) (id x₁ , proj₄) = PE.refl whrDet*Term (id x , proj₂) (x₁ ⇨ proj₃ , proj₄) = ⊥-elim (whnfRedTerm x₁ proj₂) whrDet*Term (x ⇨ proj₁ , proj₂) (id x₁ , proj₄) = ⊥-elim (whnfRedTerm x proj₄) whrDet*Term (x ⇨ proj₁ , proj₂) (x₁ ⇨ proj₃ , proj₄) = whrDet*Term (proj₁ , proj₂) (PE.subst (λ x₂ → _ ⊢ x₂ ↘ _ ∷ _) (whrDetTerm x₁ x) (proj₃ , proj₄)) whrDet* : ∀{Γ A B B′} (d : Γ ⊢ A ↘ B) (d′ : Γ ⊢ A ↘ B′) → B PE.≡ B′ whrDet* (id x , proj₂) (id x₁ , proj₄) = PE.refl whrDet* (id x , proj₂) (x₁ ⇨ proj₃ , proj₄) = ⊥-elim (whnfRed x₁ proj₂) whrDet* (x ⇨ proj₁ , proj₂) (id x₁ , proj₄) = ⊥-elim (whnfRed x proj₄) whrDet* (A⇒A′ ⇨ A′⇒*B , whnfB) (A⇒A″ ⇨ A″⇒*B′ , whnfB′) = whrDet* (A′⇒*B , whnfB) (PE.subst (λ x → _ ⊢ x ↘ _) (whrDet A⇒A″ A⇒A′) (A″⇒*B′ , whnfB′)) -- Identity of syntactic reduction idRed:*: : ∀ {Γ A} → Γ ⊢ A → Γ ⊢ A :⇒*: A idRed:*: A = [ A , A , id A ] idRedTerm:*: : ∀ {Γ A t} → Γ ⊢ t ∷ A → Γ ⊢ t :⇒*: t ∷ A idRedTerm:*: t = [ t , t , id t ] -- U cannot be a term UnotInA : ∀ {A Γ} → Γ ⊢ U ∷ A → ⊥ UnotInA (conv U∷U x) = UnotInA U∷U UnotInA[t] : ∀ {A B t a Γ} → t [ a ] PE.≡ U → Γ ⊢ a ∷ A → Γ ∙ A ⊢ t ∷ B → ⊥ UnotInA[t] () x₁ (ℕⱼ x₂) UnotInA[t] () x₁ (Emptyⱼ x₂) UnotInA[t] () x₁ (Πⱼ x₂ ▹ x₃) UnotInA[t] x₁ x₂ (var x₃ here) rewrite x₁ = UnotInA x₂ UnotInA[t] () x₂ (var x₃ (there x₄)) UnotInA[t] () x₁ (lamⱼ x₂ x₃) UnotInA[t] () x₁ (x₂ ∘ⱼ x₃) UnotInA[t] () x₁ (zeroⱼ x₂) UnotInA[t] () x₁ (sucⱼ x₂) UnotInA[t] () x₁ (natrecⱼ x₂ x₃ x₄ x₅) UnotInA[t] () x₁ (Emptyrecⱼ x₂ x₃) UnotInA[t] x x₁ (conv x₂ x₃) = UnotInA[t] x x₁ x₂ redU*Term′ : ∀ {A B U′ Γ} → U′ PE.≡ U → Γ ⊢ A ⇒ U′ ∷ B → ⊥ redU*Term′ U′≡U (conv A⇒U x) = redU*Term′ U′≡U A⇒U redU*Term′ () (app-subst A⇒U x) redU*Term′ U′≡U (β-red x x₁ x₂) = UnotInA[t] U′≡U x₂ x₁ redU*Term′ () (natrec-subst x x₁ x₂ A⇒U) redU*Term′ PE.refl (natrec-zero x x₁ x₂) = UnotInA x₁ redU*Term′ () (natrec-suc x x₁ x₂ x₃) redU*Term′ () (Emptyrec-subst x A⇒U) redU*Term′ PE.refl (Σ-β₁ F G x x₁) = UnotInA x redU*Term′ PE.refl (Σ-β₂ F G x x₁) = UnotInA x₁ redU*Term : ∀ {A B Γ} → Γ ⊢ A ⇒* U ∷ B → ⊥ redU*Term (id x) = UnotInA x redU*Term (x ⇨ A⇒*U) = redU*Term A⇒*U -- Nothing reduces to U redU : ∀ {A Γ} → Γ ⊢ A ⇒ U → ⊥ redU (univ x) = redU*Term′ PE.refl x redU* : ∀ {A Γ} → Γ ⊢ A ⇒* U → A PE.≡ U redU* (id x) = PE.refl redU* (x ⇨ A⇒*U) rewrite redU* A⇒*U = ⊥-elim (redU x)
{ "alphanum_fraction": 0.5951848667, "avg_line_length": 38.2565789474, "ext": "agda", "hexsha": "24d44724f7dd019d7007736bdacc38cead9db14d", "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": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Vtec234/logrel-mltt", "max_forks_repo_path": "Definition/Typed/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "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": "Vtec234/logrel-mltt", "max_issues_repo_path": "Definition/Typed/Properties.agda", "max_line_length": 96, "max_stars_count": null, "max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Vtec234/logrel-mltt", "max_stars_repo_path": "Definition/Typed/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6090, "size": 11630 }
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Algebra.Signature open import Relation.Binary using (Setoid) module Fragment.Algebra.Free.Syntax {a ℓ} (Σ : Signature) (A : Setoid a ℓ) where open import Fragment.Algebra.Algebra Σ open import Fragment.Algebra.Free.Base Σ open import Data.Fin using (Fin) open import Data.Vec using ([]; _∷_) module _ {n} where ⟨_⟩ : Fin n → ∥ Free (Atoms A n) ∥ ⟨ n ⟩ = atom (dyn n) ⟨_⟩ₛ : Setoid.Carrier A → ∥ Free (Atoms A n) ∥ ⟨ x ⟩ₛ = atom (sta x) ⟨_⟩₀ : ops Σ 0 → ∥ Free (Atoms A n) ∥ ⟨ f ⟩₀ = term f [] ⟨_⟩₁_ : ops Σ 1 → ∥ Free (Atoms A n) ∥ → ∥ Free (Atoms A n) ∥ ⟨ f ⟩₁ t = term f (t ∷ []) _⟨_⟩₂_ : ∥ Free (Atoms A n) ∥ → ops Σ 2 → ∥ Free (Atoms A n) ∥ → ∥ Free (Atoms A n) ∥ s ⟨ f ⟩₂ t = term f (s ∷ t ∷ [])
{ "alphanum_fraction": 0.5511904762, "avg_line_length": 23.3333333333, "ext": "agda", "hexsha": "052caeb68939f6e521c854d1ab402330b267505b", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_path": "src/Fragment/Algebra/Free/Syntax.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_path": "src/Fragment/Algebra/Free/Syntax.agda", "max_line_length": 63, "max_stars_count": 18, "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_path": "src/Fragment/Algebra/Free/Syntax.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "num_tokens": 331, "size": 840 }
-- Transport properties {-# OPTIONS --without-K --safe --exact-split #-} module Constructive.Axiom.Properties.Transport where -- agda-stdlib open import Level renaming (suc to lsuc; zero to lzero) open import Data.Sum as Sum open import Data.Product as Prod open import Relation.Binary.PropositionalEquality open import Function.Base import Function.LeftInverse as LInv -- TODO use new packages import Function.Equality as Eq -- agda-misc open import Constructive.Common open import Constructive.Combinators open import Constructive.Axiom open import Constructive.Axiom.Properties.Base module Transport {a b p} {A : Set a} {B : Set b} (f : A → B) (g : B → A) (inv : ∀ x → f (g x) ≡ x) where private ∃Pf→∃P : {P : B → Set p} → ∃ (λ x → P (f x)) → ∃ P ∃Pf→∃P (x , Pfx) = (f x , Pfx) ∃P→∃Pf : {P : B → Set p} → ∃ P → ∃ (λ x → P (f x)) ∃P→∃Pf {P = P} (x , Px) = g x , subst P (sym (inv x)) Px ∃Qg→∃Q : {Q : A → Set p} → ∃ (λ x → Q (g x)) → ∃ Q ∃Qg→∃Q (x , Qgx) = g x , Qgx lpo-transport : LPO A p → LPO B p lpo-transport lpo P? = Sum.map ∃Pf→∃P (contraposition ∃P→∃Pf) $ lpo (DecU-map f P?) llpo-transport : LLPO A p → LLPO B p llpo-transport llpo P? Q? w = Sum.map (contraposition ∃P→∃Pf) (contraposition ∃P→∃Pf) $ llpo (DecU-map f P?) (DecU-map f Q?) (contraposition (Prod.map ∃Pf→∃P ∃Pf→∃P) w) wlpo-Alt-transport : WLPO-Alt A p → WLPO-Alt B p wlpo-Alt-transport wlpo-Alt P? = Sum.map (contraposition ∃P→∃Pf) (DN-map ∃Pf→∃P) $ wlpo-Alt (DecU-map f P?) wlpo-transport : WLPO A p → WLPO B p wlpo-transport = wlpo-Alt⇒wlpo ∘′ wlpo-Alt-transport ∘′ wlpo⇒wlpo-Alt mr-transport : MR A p → MR B p mr-transport mr P? ¬¬∃P = ∃Pf→∃P $ mr (DecU-map f P?) (DN-map ∃P→∃Pf ¬¬∃P) mp-transport : MP A p → MP B p mp-transport = mr⇒mp ∘′ mr-transport ∘′ mp⇒mr wmp-transport : WMP A p → WMP B p wmp-transport wmp {P = P} P? hyp = ∃Pf→∃P $ wmp (DecU-map f P?) λ Q? → Sum.map (DN-map ∃Qg→∃Q) (DN-map λ {(x , Px , ¬Qgx) → g x , (subst P (sym (inv x)) Px) , ¬Qgx }) $ hyp (DecU-map g Q?) mp⊎-transport : MP⊎ A p → MP⊎ B p mp⊎-transport mp⊎ P? Q? w = Sum.map (DN-map ∃Pf→∃P) (DN-map ∃Pf→∃P) $ mp⊎ (DecU-map f P?) (DecU-map f Q?) (contraposition (Prod.map (contraposition ∃P→∃Pf) (contraposition ∃P→∃Pf)) w) open Transport public module TransportByLeftInverse {a b p} {A : Set a} {B : Set b} (linv : B LInv.↞ A) = Transport {p = p} (LInv.LeftInverse.from linv Eq.⟨$⟩_) (LInv.LeftInverse.to linv Eq.⟨$⟩_) (LInv.LeftInverse.left-inverse-of linv)
{ "alphanum_fraction": 0.582038651, "avg_line_length": 33.4050632911, "ext": "agda", "hexsha": "7ca926cf57e7a8e6e5a59d173037e42277bf417c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "rei1024/agda-misc", "max_forks_repo_path": "Constructive/Axiom/Properties/Transport.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "rei1024/agda-misc", "max_issues_repo_path": "Constructive/Axiom/Properties/Transport.agda", "max_line_length": 78, "max_stars_count": 3, "max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "rei1024/agda-misc", "max_stars_repo_path": "Constructive/Axiom/Properties/Transport.agda", "max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z", "num_tokens": 1091, "size": 2639 }
open import Preliminaries module Idea where {- de Bruijn indices are representd as proofs that an element is in a list -} data _∈_ {A : Set} : (x : A) (l : List A) → Set where -- type \in i0 : {x : A} {xs : List A} → x ∈ x :: xs iS : {x y : A} {xs : List A} → x ∈ xs → x ∈ y :: xs {- types of the STLC -} data Tp : Set where b : Tp -- uninterpreted base type _⇒_ : Tp → Tp → Tp -- type \=> {- contexts are lists of Tp's -} Ctx = List Tp _,,_ : Ctx → Tp → Ctx Γ ,, τ = τ :: Γ infixr 10 _⇒_ infixr 9 _,,_ infixr 8 _⊢_ -- type \entails infix 9 _⊇_ data _⊢_ (Γ : Ctx) : Tp → Set data _≡_ {Γ : Ctx} : {τ : Tp} → Γ ⊢ τ → Γ ⊢ τ → Set _⊢c_ : Ctx → Ctx → Set _⊇_ : Ctx → Ctx → Set -- type \sup= ids : {Γ : Ctx} → Γ ⊢c Γ rename : {Γ Γ' : Ctx} {τ : Tp} → Γ' ⊇ Γ → Γ ⊢ τ → Γ' ⊢ τ subst : {Γ Γ' : Ctx}{τ : Tp} → Γ ⊢c Γ' → Γ' ⊢ τ → Γ ⊢ τ _·ss_ : {Γ1 Γ2 Γ3 : Ctx} → Γ1 ⊢c Γ2 → Γ2 ⊢c Γ3 → Γ1 ⊢c Γ3 subst1 : {Γ : Ctx} {τ τ0 : Tp} → Γ ⊢ τ0 → (Γ ,, τ0) ⊢ τ → Γ ⊢ τ {- Γ ⊢ τ represents a term of type τ in context Γ -} data _⊢_ (Γ : Ctx) where c : Γ ⊢ b -- some constant of the base type v : {τ : Tp} → τ ∈ Γ → Γ ⊢ τ lam : {τ1 τ2 : Tp} → Γ ,, τ1 ⊢ τ2 → Γ ⊢ τ1 ⇒ τ2 app : {τ1 τ2 : Tp} → Γ ⊢ τ1 ⇒ τ2 → Γ ⊢ τ1 → Γ ⊢ τ2 foo : {A : Tp} (e1 e2 : Γ ⊢ A) → e1 ≡ e2 → Γ ⊢ A {-foo : (e1 : ™ Gamma A) (e2 : ™ Gamma A) -> e1 \equiv e2 -> ™ Gamma A-} Γ' ⊇ [] = Unit Γ' ⊇ (τ :: Γ) = (Γ' ⊇ Γ) × (τ ∈ Γ') rename-var : {Γ Γ' : Ctx} {τ : Tp} → Γ' ⊇ Γ → τ ∈ Γ → τ ∈ Γ' rename-var (ρ , x') i0 = x' rename-var (ρ , _) (iS x) = rename-var ρ x p· : {Γ : Ctx} {Γ' : Ctx} → Γ ⊇ Γ' → {τ : Tp} → (Γ ,, τ) ⊇ Γ' p· {Γ' = []} ren = <> p· {Γ' = (τ :: Γ')} (ρ , x) = p· ρ , iS x idr : {Γ : Ctx} → Γ ⊇ Γ idr {[]} = <> idr {τ :: Γ} = p· idr , i0 -- category with families notation p : {Γ : Ctx} {τ : Tp} → (Γ ,, τ ⊇ Γ) p = p· idr addvar-ren : {Γ Γ' : Ctx} {τ : Tp} → Γ' ⊇ Γ → Γ' ,, τ ⊇ Γ ,, τ addvar-ren ρ = (p· ρ , i0) data _≡_ {Γ : Ctx} where CongApp : {τ1 τ2 : Tp} {e e' : Γ ⊢ τ1 ⇒ τ2} {e1 e1' : Γ ⊢ τ1} → e ≡ e' → e1 ≡ e1' → (app e e1) ≡ (app e' e1') CongLam : {τ1 τ2 : Tp} {e e' : (τ1 :: Γ) ⊢ τ2} → e ≡ e' → (lam e) ≡ (lam e') SubstId : ∀ {τ} {e : Γ ⊢ τ} → subst ids e ≡ e SubstComp : ∀ {Γ1 Γ2} {τ} {θ' : Γ ⊢c Γ2} {θ : Γ2 ⊢c Γ1} {e : Γ1 ⊢ τ} → subst θ' (subst θ e) ≡ subst (θ' ·ss θ) e Stepβ : {τ1 τ2 : Tp} {e : Γ ,, τ1 ⊢ τ2} {e1 : Γ ⊢ τ1} → (app (lam e) e1) ≡ subst1 e1 e Refl : {τ : Tp} {e : Γ ⊢ τ} → e ≡ e Trans : {τ : Tp} {e1 e2 e3 : Γ ⊢ τ} → e1 ≡ e2 → e2 ≡ e3 → e1 ≡ e3 SubstCong : ∀ {Γ2} {τ} {Θ : Γ ⊢c Γ2} {e1 e2 : Γ2 ⊢ τ} → e1 ≡ e2 → subst Θ e1 ≡ subst Θ e2 RenCong : ∀ {Γ2} {τ} {ρ : Γ ⊇ Γ2} {e1 e2 : Γ2 ⊢ τ} → e1 ≡ e2 → rename ρ e1 ≡ rename ρ e2 rename ρ c = c rename ρ (v x) = v (rename-var ρ x) rename ρ (lam e) = lam (rename (addvar-ren ρ) e) rename ρ (app e e') = app (rename ρ e) (rename ρ e') rename ρ (foo e1 e2 p) = foo (rename ρ e1) (rename ρ e2) (RenCong p) _·rr_ : {Γ1 Γ2 Γ3 : Ctx} → Γ1 ⊇ Γ2 → Γ2 ⊇ Γ3 → Γ1 ⊇ Γ3 _·rr_ {Γ1} {Γ2} {[]} ρ2 ρ3 = <> _·rr_ {Γ1} {Γ2} {x :: Γ3} ρ2 (ρ3 , x3) = (ρ2 ·rr ρ3) , rename-var ρ2 x3 Γ' ⊢c [] = Unit Γ' ⊢c (τ :: Γ) = (Γ' ⊢c Γ) × (Γ' ⊢ τ) _·rs_ : {Γ1 Γ2 Γ3 : Ctx} → Γ1 ⊇ Γ2 → Γ2 ⊢c Γ3 → Γ1 ⊢c Γ3 _·rs_ {Γ1} {Γ2} {[]} ρ θ = <> _·rs_ {Γ1} {Γ2} {τ3 :: Γ3} ρ (θ , e) = ρ ·rs θ , rename ρ e addvar : {Γ Γ' : Ctx} {τ : Tp} → Γ ⊢c Γ' → (Γ ,, τ) ⊢c (Γ' ,, τ) addvar θ = p ·rs θ , v i0 ids {[]} = <> ids {τ :: Γ} = p ·rs ids , v i0 subst-var : {Γ Γ' : Ctx}{τ : Tp} → Γ ⊢c Γ' → τ ∈ Γ' → Γ ⊢ τ subst-var (θ , e) i0 = e subst-var (θ , _) (iS x) = subst-var θ x subst1 e0 e = subst (ids , e0) e -- composition of renamings and substitutions _·sr_ : {Γ1 Γ2 Γ3 : Ctx} → Γ1 ⊢c Γ2 → Γ2 ⊇ Γ3 → Γ1 ⊢c Γ3 _·sr_ {Γ1} {Γ2} {[]} θ ρ = <> _·sr_ {Γ1} {Γ2} {τ3 :: Γ3} θ (ρ , x) = _·sr_ θ ρ , subst-var θ x _·ss_ {Γ3 = []} θ1 θ2 = <> _·ss_ {Γ1} {Γ2} {τ :: Γ3} θ1 (θ2 , e2) = θ1 ·ss θ2 , subst θ1 e2 subst θ c = c subst θ (v x) = subst-var θ x subst θ (lam e) = lam (subst (addvar θ) e) subst θ (app e e') = app (subst θ e) (subst θ e') subst {Γ} {Γ'} {τ} Θ (foo e1 e2 p) = foo (subst Θ e1) (subst Θ e2) (SubstCong p) postulate semfoo : (A : Set) (x y : A) -> x == y -> A module Semantics (B : Set) (elB : B) where ⟦_⟧t : Tp → Set ⟦_⟧c : Ctx → Set ⟦_⟧v : {Γ : Ctx} {τ : Tp} → τ ∈ Γ → ⟦ Γ ⟧c → ⟦ τ ⟧t ⟦_⟧ : {Γ : Ctx} {τ : Tp} → Γ ⊢ τ → ⟦ Γ ⟧c → ⟦ τ ⟧t sound : {Γ : Ctx} {τ : Tp} {e : Γ ⊢ τ} {e' : Γ ⊢ τ} → e ≡ e' → (γ : ⟦ Γ ⟧c) → ⟦ e ⟧ γ == ⟦ e' ⟧ γ ⟦ b ⟧t = B ⟦ τ1 ⇒ τ2 ⟧t = ⟦ τ1 ⟧t → ⟦ τ2 ⟧t ⟦ [] ⟧c = Unit ⟦ τ :: Γ ⟧c = ⟦ Γ ⟧c × ⟦ τ ⟧t ⟦_⟧v i0 γ = snd γ ⟦_⟧v (iS x) γ = ⟦ x ⟧v (fst γ) ⟦ c ⟧ γ = elB ⟦ v x ⟧ γ = ⟦ x ⟧v γ ⟦ lam e ⟧ γ = \ x → ⟦ e ⟧ (γ , x) ⟦ app e1 e2 ⟧ γ = ⟦ e1 ⟧ γ (⟦ e2 ⟧ γ) ⟦ (foo e1 e2 p) ⟧ γ = semfoo {!!} (⟦ e1 ⟧ γ) (⟦ e2 ⟧ γ) (sound {_} {_} {e1} {e2} p γ) ⟦_⟧s : {Γ Γ' : Ctx} → Γ ⊢c Γ' → ⟦ Γ ⟧c → ⟦ Γ' ⟧c ⟦_⟧s {Γ' = []} θ _ = <> ⟦_⟧s {Γ' = τ :: Γ'} (θ , e) γ = ⟦ θ ⟧s γ , ⟦ e ⟧ γ ⟦_⟧r : {Γ Γ' : Ctx} → Γ ⊇ Γ' → ⟦ Γ ⟧c → ⟦ Γ' ⟧c ⟦_⟧r {Γ' = []} θ _ = <> ⟦_⟧r {Γ' = τ :: Γ'} (θ , x) γ = ⟦ θ ⟧r γ , ⟦ x ⟧v γ interp-rename-var : {Γ' Γ : Ctx} {τ : Tp} (x : τ ∈ Γ) (θ : Γ' ⊇ Γ) → (γ' : ⟦ Γ' ⟧c) → ⟦ rename-var θ x ⟧v γ' == (⟦ x ⟧v (⟦ θ ⟧r γ')) interp-rename-var i0 θ γ' = Refl interp-rename-var (iS x) θ γ' = interp-rename-var x (fst θ) γ' interp-subst-var : {Γ' Γ : Ctx} {τ : Tp} (x : τ ∈ Γ) (θ : Γ' ⊢c Γ) → (γ' : ⟦ Γ' ⟧c) → ⟦ subst-var θ x ⟧ γ' == (⟦ x ⟧v (⟦ θ ⟧s γ')) interp-subst-var i0 θ γ' = Refl interp-subst-var (iS x) θ γ' = interp-subst-var x (fst θ) γ' interp-p· : {Γ : Ctx} {Γ' : Ctx} → (θ : Γ ⊇ Γ') → {τ : Tp} (γ' : _) → ⟦ p· θ {τ = τ} ⟧r γ' == ⟦ θ ⟧r (fst γ') interp-p· {Γ' = []} θ γ' = Refl interp-p· {Γ' = τ' :: Γ'} θ γ' = ap2 _,_ (interp-p· (fst θ) _) Refl interp-idr : {Γ : Ctx} (γ : _) → ⟦ idr {Γ} ⟧r γ == γ interp-idr {[]} γ = Refl interp-idr {x :: Γ} γ = ap (λ x₁ → x₁ , snd γ) (interp-idr (fst γ) ∘ interp-p· idr γ) interp-rename : {Γ' Γ : Ctx} {τ : Tp} (e : Γ ⊢ τ) (θ : Γ' ⊇ Γ) → (γ' : ⟦ Γ' ⟧c) → ⟦ rename θ e ⟧ γ' == (⟦ e ⟧ (⟦ θ ⟧r γ')) interp-rename c θ γ' = Refl interp-rename (v x) θ γ' = interp-rename-var x θ γ' interp-rename (lam e) θ γ' = λ= (λ x → ap ⟦ e ⟧ (ap2 _,_ (interp-p· θ (γ' , x)) Refl) ∘ interp-rename e (addvar-ren θ) (γ' , x)) interp-rename (app e e₁) θ γ' = ap2 (λ f x → f x) (interp-rename e θ γ') (interp-rename e₁ θ γ') interp-rename (foo e1 e2 p) Θ γ' = {!!} --interp-rename e1 Θ γ' interp-·rs : {Γ1 Γ2 Γ3 : Ctx} → (θ1 : Γ1 ⊇ Γ2) (θ2 : Γ2 ⊢c Γ3) (γ : _) → ⟦ θ1 ·rs θ2 ⟧s γ == ⟦ θ2 ⟧s (⟦ θ1 ⟧r γ) interp-·rs {Γ3 = []} θ1 θ2 γ = Refl interp-·rs {Γ3 = τ :: Γ3} θ1 (θ2 , e) γ = ap2 _,_ (interp-·rs θ1 θ2 γ) (interp-rename e θ1 γ) interp-subst : {Γ' Γ : Ctx} {τ : Tp} (e : Γ ⊢ τ) (θ : Γ' ⊢c Γ) → (γ' : ⟦ Γ' ⟧c) → ⟦ subst θ e ⟧ γ' == (⟦ e ⟧ (⟦ θ ⟧s γ')) interp-subst c θ γ' = Refl interp-subst (v x) θ γ' = interp-subst-var x θ γ' interp-subst (lam e) θ γ' = λ= (λ x → ap (λ h → ⟦ e ⟧ (h , x)) (ap ⟦ θ ⟧s (interp-idr γ' ∘ interp-p· idr (γ' , x)) ∘ interp-·rs (p· idr) θ _) ∘ interp-subst e (addvar θ) (γ' , x)) interp-subst (app e e₁) θ γ' = ap2 (λ f x → f x) (interp-subst e θ γ') (interp-subst e₁ θ γ') interp-subst (foo e1 e2 p) Θ γ' = {!!} --interp-subst e1 Θ γ' interp-·ss : {Γ1 Γ2 Γ3 : Ctx} → (θ1 : Γ1 ⊢c Γ2) (θ2 : Γ2 ⊢c Γ3) (γ : _) → ⟦ θ1 ·ss θ2 ⟧s γ == ⟦ θ2 ⟧s (⟦ θ1 ⟧s γ) interp-·ss {Γ3 = []} θ1 θ2 γ = Refl interp-·ss {Γ3 = τ :: Γ3} θ1 (θ2 , e) γ = ap2 _,_ (interp-·ss θ1 θ2 γ) (interp-subst e θ1 γ) interp-ids : ∀ {Γ} (γ : _) → ⟦ ids {Γ} ⟧s γ == γ interp-ids {[]} γ = Refl interp-ids {τ :: Γ} γ = ap (λ x → x , snd γ) (((interp-idr (fst γ) ∘ interp-p· idr γ) ∘ interp-ids (⟦ p ⟧r γ)) ∘ interp-·rs p ids γ) sound (CongApp D D') γ = ap2 (λ f x → f x) (sound D γ) (sound D' γ) sound (CongLam D) γ = λ= (λ x → sound D (γ , x)) sound {e' = e'} SubstId γ = ap ⟦ e' ⟧ (interp-ids γ) ∘ interp-subst e' ids γ sound (SubstComp {θ' = θ'}{θ}{e = e}) γ = ((! (interp-subst e _ γ) ∘ ap ⟦ e ⟧ (! (interp-·ss θ' θ γ))) ∘ interp-subst e θ (⟦ θ' ⟧s γ)) ∘ interp-subst (subst θ e) θ' γ sound (Stepβ {e = e} {e1 = e1}) γ = ! (interp-subst e (ids , e1) γ) ∘ ap (λ x → ⟦ e ⟧ (x , ⟦ e1 ⟧ γ)) (! (interp-ids γ)) sound Refl γ = Refl sound (Trans D D₁) γ = sound D₁ γ ∘ sound D γ sound {Γ'} (SubstCong {Γ} {τ} {Θ} {e1} {e2} D) γ = {!!} --(! (interp-subst e2 Θ γ) ∘ sound D (⟦ Θ ⟧s γ)) ∘ interp-subst e1 Θ γ sound {Γ'} (RenCong {Γ} {τ} {ρ} {e1} {e2} D) γ = {!!} --(! (interp-rename e2 ρ γ) ∘ sound D (⟦ ρ ⟧r γ)) ∘ interp-rename e1 ρ γ
{ "alphanum_fraction": 0.4285872453, "avg_line_length": 39.6140350877, "ext": "agda", "hexsha": "c582334b1d4b3e093d040f58531505738296912c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "benhuds/Agda", "max_forks_repo_path": "complexity/Idea.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e", "max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z", "max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "benhuds/Agda", "max_issues_repo_path": "complexity/Idea.agda", "max_line_length": 183, "max_stars_count": 2, "max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "benhuds/Agda", "max_stars_repo_path": "complexity/Idea.agda", "max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z", "max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z", "num_tokens": 4831, "size": 9032 }
{-# OPTIONS --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution.Reducibility {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.Untyped.Properties open import Definition.Typed open import Definition.LogicalRelation open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Substitution open import Definition.LogicalRelation.Substitution.Properties open import Tools.Product import Tools.PropositionalEquality as PE -- Valid types are reducible. reducibleᵛ : ∀ {A rA Γ l} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ l ⟩ A ^ rA / [Γ] → Γ ⊩⟨ l ⟩ A ^ rA reducibleᵛ [Γ] [A] = let ⊢Γ = soundContext [Γ] [id] = idSubstS [Γ] in irrelevance′ (subst-id _) (proj₁ ([A] ⊢Γ [id])) -- Valid type equality is reducible. reducibleEqᵛ : ∀ {A B rA Γ l} ([Γ] : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A ^ rA / [Γ]) → Γ ⊩ᵛ⟨ l ⟩ A ≡ B ^ rA / [Γ] / [A] → Γ ⊩⟨ l ⟩ A ≡ B ^ rA / reducibleᵛ [Γ] [A] reducibleEqᵛ {A = A} [Γ] [A] [A≡B] = let [σA] = reducibleᵛ {A = A} [Γ] [A] ⊢Γ = soundContext [Γ] [id] = idSubstS [Γ] in irrelevanceEq″ (subst-id _) (subst-id _) PE.refl PE.refl (proj₁ ([A] ⊢Γ [id])) [σA] ([A≡B] ⊢Γ [id]) -- Valid terms are reducible. reducibleTermᵛ : ∀ {t A rA Γ l} ([Γ] : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A ^ rA / [Γ]) → Γ ⊩ᵛ⟨ l ⟩ t ∷ A ^ rA / [Γ] / [A] → Γ ⊩⟨ l ⟩ t ∷ A ^ rA / reducibleᵛ [Γ] [A] reducibleTermᵛ {A = A} [Γ] [A] [t] = let [σA] = reducibleᵛ {A = A} [Γ] [A] ⊢Γ = soundContext [Γ] [id] = idSubstS [Γ] in irrelevanceTerm″ (subst-id _) PE.refl PE.refl (subst-id _) (proj₁ ([A] ⊢Γ [id])) [σA] (proj₁ ([t] ⊢Γ [id])) -- Valid term equality is reducible. reducibleEqTermᵛ : ∀ {t u A rA Γ l} ([Γ] : ⊩ᵛ Γ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A ^ rA / [Γ]) → Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ A ^ rA / [Γ] / [A] → Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ rA / reducibleᵛ [Γ] [A] reducibleEqTermᵛ {A = A} [Γ] [A] [t≡u] = let [σA] = reducibleᵛ {A = A} [Γ] [A] ⊢Γ = soundContext [Γ] [id] = idSubstS [Γ] in irrelevanceEqTerm″ PE.refl PE.refl (subst-id _) (subst-id _) (subst-id _) (proj₁ ([A] ⊢Γ [id])) [σA] ([t≡u] ⊢Γ [id])
{ "alphanum_fraction": 0.5099337748, "avg_line_length": 35.5294117647, "ext": "agda", "hexsha": "bb6b696cdfb892597eba845bc68ac587e850ea80", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z", "max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z", "max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CoqHott/logrel-mltt", "max_forks_repo_path": "Definition/LogicalRelation/Substitution/Reducibility.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "CoqHott/logrel-mltt", "max_issues_repo_path": "Definition/LogicalRelation/Substitution/Reducibility.agda", "max_line_length": 86, "max_stars_count": 2, "max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CoqHott/logrel-mltt", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Reducibility.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": 1008, "size": 2416 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Impl.OBM.Logging.Logging open import LibraBFT.ImplShared.Consensus.Types import LibraBFT.ImplShared.Util.Crypto as Crypto open import Optics.All open import Util.Prelude module LibraBFT.Impl.Types.Ledger2WaypointConverter where new : LedgerInfo → Ledger2WaypointConverter new ledgerInfo = mkLedger2WaypointConverter (ledgerInfo ^∙ liEpoch) (ledgerInfo ^∙ liTransactionAccumulatorHash) (ledgerInfo ^∙ liVersion) --(ledgerInfo ^∙ liTimestamp) (ledgerInfo ^∙ liNextEpochState)
{ "alphanum_fraction": 0.7886393659, "avg_line_length": 34.4090909091, "ext": "agda", "hexsha": "f2780f47725ac4082fedbc51f2ad1e7bfca2f2e4", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_path": "src/LibraBFT/Impl/Types/Ledger2WaypointConverter.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_path": "src/LibraBFT/Impl/Types/Ledger2WaypointConverter.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_path": "src/LibraBFT/Impl/Types/Ledger2WaypointConverter.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 212, "size": 757 }
module Sessions.Syntax.Expr where open import Prelude open import Sessions.Syntax.Types open import Relation.Ternary.Separation.Construct.List Type data Exp : Type → LCtx → Set where var : ∀[ Just a ⇒ Exp a ] -- value constructors unit : ε[ Exp unit ] letunit : ∀[ Exp unit ✴ Exp a ⇒ Exp a ] -- linear function introduction and elimination lam : ∀ a → ∀[ ((a ∷_) ⊢ Exp b) ⇒ Exp (a ⊸ b) ] ap : ∀[ Exp (a ⊸ b) ✴ Exp a ⇒ Exp b ] -- product introduction and elimination pairs : ∀[ Exp a ✴ Exp b ⇒ Exp (prod a b) ] letpair : ∀[ Exp (prod a b) ✴ (λ Γ → a ∷ b ∷ Γ) ⊢ Exp c ⇒ Exp c ] -- communication mkchan : ∀ α → ε[ Exp (prod (cref α) (cref (α ⁻¹))) ] send : ∀ {b} → ∀[ Exp a ✴ Exp (cref (a ! b)) ⇒ Exp (cref b) ] recv : ∀ {b} → ∀[ Exp (cref (a ¿ b)) ⇒ Exp (prod (cref b) a) ] -- fork ; TODO unit fork : ∀[ Exp (unit ⊸ unit) ⇒ Exp unit ] -- termination terminate : ∀[ Exp (cref end) ⇒ Exp unit ]
{ "alphanum_fraction": 0.5337361531, "avg_line_length": 29.2058823529, "ext": "agda", "hexsha": "e60a3a9176b2013b451f347b75daeef4716f1432", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z", "max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z", "max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "laMudri/linear.agda", "max_forks_repo_path": "src/Sessions/Syntax/Expr.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "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": "laMudri/linear.agda", "max_issues_repo_path": "src/Sessions/Syntax/Expr.agda", "max_line_length": 69, "max_stars_count": 34, "max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "laMudri/linear.agda", "max_stars_repo_path": "src/Sessions/Syntax/Expr.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z", "num_tokens": 345, "size": 993 }
{-# 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 open import Setoids.Subset module Setoids.Intersection.Lemmas {a b : _} {A : Set a} (S : Setoid {a} {b} A) {c d : _} {pred1 : A → Set c} {pred2 : A → Set d} (s1 : subset S pred1) (s2 : subset S pred2) where open import Setoids.Intersection.Definition S open import Setoids.Equality S intersectionCommutative : intersection s1 s2 =S intersection s2 s1 intersectionCommutative i = (λ t → _&&_.snd t ,, _&&_.fst t) ,, λ t → _&&_.snd t ,, _&&_.fst t intersectionAssociative : {e : _} {pred3 : A → Set e} (s3 : subset S pred3) → intersection (intersection s1 s2) s3 =S intersection s1 (intersection s2 s3) intersectionAssociative s3 x = (λ pr → _&&_.fst (_&&_.fst pr) ,, (_&&_.snd (_&&_.fst pr) ,, _&&_.snd pr)) ,, λ z → (_&&_.fst z ,, _&&_.fst (_&&_.snd z)) ,, _&&_.snd (_&&_.snd z)
{ "alphanum_fraction": 0.6680161943, "avg_line_length": 52, "ext": "agda", "hexsha": "a3966c3e69cd8a78d21b745a0459625a0d042196", "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/Intersection/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": "Setoids/Intersection/Lemmas.agda", "max_line_length": 179, "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/Intersection/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": 332, "size": 988 }
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.types.Sigma open import lib.types.Paths module lib.types.CommutingSquare where {- maps between two functions -} infix 0 _□$_ _□$_ = CommSquare.commutes CommSquare-∘v : ∀ {i₀ i₁ i₂ j₀ j₁ j₂} {A₀ : Type i₀} {A₁ : Type i₁} {A₂ : Type i₂} {B₀ : Type j₀} {B₁ : Type j₁} {B₂ : Type j₂} {f₀ : A₀ → B₀} {f₁ : A₁ → B₁} {f₂ : A₂ → B₂} {hA : A₀ → A₁} {hB : B₀ → B₁} {kA : A₁ → A₂} {kB : B₁ → B₂} → CommSquare f₁ f₂ kA kB → CommSquare f₀ f₁ hA hB → CommSquare f₀ f₂ (kA ∘ hA) (kB ∘ hB) CommSquare-∘v {hA = hA} {kB = kB} (comm-sqr □₁₂) (comm-sqr □₀₁) = comm-sqr λ a₀ → ap kB (□₀₁ a₀) ∙ □₁₂ (hA a₀) CommSquare-inverse-v : ∀ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁} {f₀ : A₀ → B₀} {f₁ : A₁ → B₁} {hA : A₀ → A₁} {hB : B₀ → B₁} → CommSquare f₀ f₁ hA hB → (hA-ise : is-equiv hA) (hB-ise : is-equiv hB) → CommSquare f₁ f₀ (is-equiv.g hA-ise) (is-equiv.g hB-ise) CommSquare-inverse-v {f₀ = f₀} {f₁} {hA} {hB} (comm-sqr □) hA-ise hB-ise = comm-sqr λ a₁ → ap hB.g (! (□ (hA.g a₁) ∙ ap f₁ (hA.f-g a₁))) ∙ hB.g-f (f₀ (hA.g a₁)) where module hA = is-equiv hA-ise module hB = is-equiv hB-ise abstract -- 'r' with respect to '∘v' CommSquare-inverse-inv-r : ∀ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁} {f₀ : A₀ → B₀} {f₁ : A₁ → B₁} {hA : A₀ → A₁} {hB : B₀ → B₁} (cs : CommSquare f₀ f₁ hA hB) (hA-ise : is-equiv hA) (hB-ise : is-equiv hB) → ∀ a₁ → (CommSquare-∘v cs (CommSquare-inverse-v cs hA-ise hB-ise) □$ a₁) == is-equiv.f-g hB-ise (f₁ a₁) ∙ ! (ap f₁ (is-equiv.f-g hA-ise a₁)) CommSquare-inverse-inv-r {f₀ = f₀} {f₁} {hA} {hB} (comm-sqr □) hA-ise hB-ise a₁ = ap hB ( ap hB.g (! (□ (hA.g a₁) ∙ ap f₁ (hA.f-g a₁))) ∙ hB.g-f (f₀ (hA.g a₁))) ∙ □ (hA.g a₁) =⟨ ap-∙ hB (ap hB.g (! (□ (hA.g a₁) ∙ ap f₁ (hA.f-g a₁)))) (hB.g-f (f₀ (hA.g a₁))) |in-ctx _∙ □ (hA.g a₁) ⟩ ( ap hB (ap hB.g (! (□ (hA.g a₁) ∙ ap f₁ (hA.f-g a₁)))) ∙ ap hB (hB.g-f (f₀ (hA.g a₁)))) ∙ □ (hA.g a₁) =⟨ ap2 _∙_ (∘-ap hB hB.g (! (□ (hA.g a₁) ∙ ap f₁ (hA.f-g a₁)))) (hB.adj (f₀ (hA.g a₁))) |in-ctx _∙ □ (hA.g a₁) ⟩ ( ap (hB ∘ hB.g) (! (□ (hA.g a₁) ∙ ap f₁ (hA.f-g a₁))) ∙ hB.f-g (hB (f₀ (hA.g a₁)))) ∙ □ (hA.g a₁) =⟨ ! (↓-app=idf-out $ apd hB.f-g (! (□ (hA.g a₁) ∙ ap f₁ (hA.f-g a₁)))) |in-ctx _∙ □ (hA.g a₁) ⟩ ( hB.f-g (f₁ a₁) ∙' (! (□ (hA.g a₁) ∙ ap f₁ (hA.f-g a₁)))) ∙ □ (hA.g a₁) =⟨ lemma (hB.f-g (f₁ a₁)) (□ (hA.g a₁)) (ap f₁ (hA.f-g a₁)) ⟩ hB.f-g (f₁ a₁) ∙ ! (ap f₁ (hA.f-g a₁)) =∎ where module hA = is-equiv hA-ise module hB = is-equiv hB-ise lemma : ∀ {i} {A : Type i} {a₀ a₁ a₂ a₃ : A} (p₀ : a₀ == a₁) (p₁ : a₃ == a₂) (p₂ : a₂ == a₁) → (p₀ ∙' (! (p₁ ∙ p₂))) ∙ p₁ == p₀ ∙ ! p₂ lemma idp idp idp = idp -- 'l' with respect to '∘v' CommSquare-inverse-inv-l : ∀ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁} {f₀ : A₀ → B₀} {f₁ : A₁ → B₁} {hA : A₀ → A₁} {hB : B₀ → B₁} (cs : CommSquare f₀ f₁ hA hB) (hA-ise : is-equiv hA) (hB-ise : is-equiv hB) → ∀ a₀ → (CommSquare-∘v (CommSquare-inverse-v cs hA-ise hB-ise) cs □$ a₀) == is-equiv.g-f hB-ise (f₀ a₀) ∙ ! (ap f₀ (is-equiv.g-f hA-ise a₀)) CommSquare-inverse-inv-l {f₀ = f₀} {f₁} {hA} {hB} (comm-sqr □) hA-ise hB-ise a₀ = ap hB.g (□ a₀) ∙ ( ap hB.g (! (□ (hA.g (hA a₀)) ∙ ap f₁ (hA.f-g (hA a₀)))) ∙ hB.g-f (f₀ (hA.g (hA a₀)))) =⟨ ! (hA.adj a₀) |in-ctx ap f₁ |in-ctx □ (hA.g (hA a₀)) ∙_ |in-ctx ! |in-ctx ap hB.g |in-ctx _∙ hB.g-f (f₀ (hA.g (hA a₀))) |in-ctx ap hB.g (□ a₀) ∙_ ⟩ ap hB.g (□ a₀) ∙ ( ap hB.g (! (□ (hA.g (hA a₀)) ∙ ap f₁ (ap hA (hA.g-f a₀)))) ∙ hB.g-f (f₀ (hA.g (hA a₀)))) =⟨ ∘-ap f₁ hA (hA.g-f a₀) |in-ctx □ (hA.g (hA a₀)) ∙_ |in-ctx ! |in-ctx ap hB.g |in-ctx _∙ hB.g-f (f₀ (hA.g (hA a₀))) |in-ctx ap hB.g (□ a₀) ∙_ ⟩ ap hB.g (□ a₀) ∙ ( ap hB.g (! (□ (hA.g (hA a₀)) ∙ ap (f₁ ∘ hA) (hA.g-f a₀))) ∙ hB.g-f (f₀ (hA.g (hA a₀)))) =⟨ ↓-='-out' (apd □ (hA.g-f a₀)) |in-ctx ! |in-ctx ap hB.g |in-ctx _∙ hB.g-f (f₀ (hA.g (hA a₀))) |in-ctx ap hB.g (□ a₀) ∙_ ⟩ ap hB.g (□ a₀) ∙ ( ap hB.g (! (ap (hB ∘ f₀) (hA.g-f a₀) ∙' □ a₀)) ∙ hB.g-f (f₀ (hA.g (hA a₀)))) =⟨ lemma hB.g (□ a₀) (ap (hB ∘ f₀) (hA.g-f a₀)) (hB.g-f (f₀ (hA.g (hA a₀)))) ⟩ ! (ap hB.g (ap (hB ∘ f₀) (hA.g-f a₀))) ∙' hB.g-f (f₀ (hA.g (hA a₀))) =⟨ ∘-ap hB.g (hB ∘ f₀) (hA.g-f a₀) |in-ctx ! |in-ctx _∙' hB.g-f (f₀ (hA.g (hA a₀))) ⟩ ! (ap (hB.g ∘ hB ∘ f₀) (hA.g-f a₀)) ∙' hB.g-f (f₀ (hA.g (hA a₀))) =⟨ !-ap (hB.g ∘ hB ∘ f₀) (hA.g-f a₀) |in-ctx _∙' hB.g-f (f₀ (hA.g (hA a₀))) ⟩ ap (hB.g ∘ hB ∘ f₀) (! (hA.g-f a₀)) ∙' hB.g-f (f₀ (hA.g (hA a₀))) =⟨ ! (↓-='-out' (apd (hB.g-f ∘ f₀) (! (hA.g-f a₀)))) ⟩ hB.g-f (f₀ a₀) ∙ ap f₀ (! (hA.g-f a₀)) =⟨ ap-! f₀ (hA.g-f a₀) |in-ctx hB.g-f (f₀ a₀) ∙_ ⟩ hB.g-f (f₀ a₀) ∙ ! (ap f₀ (hA.g-f a₀)) =∎ where module hA = is-equiv hA-ise module hB = is-equiv hB-ise lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {a₀ a₁ a₂ : A} {b : B} (p₀ : a₀ == a₁) (p₁ : a₂ == a₀) (q₀ : f a₂ == b) → ap f p₀ ∙ (ap f (! (p₁ ∙' p₀)) ∙ q₀) == ! (ap f p₁) ∙' q₀ lemma f idp idp idp = idp
{ "alphanum_fraction": 0.4496332081, "avg_line_length": 41.7089552239, "ext": "agda", "hexsha": "d1da78a7b73e8a7a3d26da9a73584def9982a6b6", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mikeshulman/HoTT-Agda", "max_forks_repo_path": "core/lib/types/CommutingSquare.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "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": "mikeshulman/HoTT-Agda", "max_issues_repo_path": "core/lib/types/CommutingSquare.agda", "max_line_length": 88, "max_stars_count": null, "max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mikeshulman/HoTT-Agda", "max_stars_repo_path": "core/lib/types/CommutingSquare.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2915, "size": 5589 }
-- This is an example emphasizing the important of a linearity check -- in the positivity check. -- -- Currently it does not type check since there is no universe subtyping. module PositivityCheckNeedsLinearityCheck where data Eq (S : Set2) : Set2 -> Set where refl : Eq S S subst' : {S S' : Set2} -> Eq S S' -> S -> S' subst' refl s = s -- what happens if Eq is considered covariant in its first argument? -- then because of subtyping, p : Eq Set1 Set p = refl S : Set S = subst' p Set -- now S, which evaluates to Set, is in Set
{ "alphanum_fraction": 0.6800731261, "avg_line_length": 17.6451612903, "ext": "agda", "hexsha": "d2027ac399acec09da32fb8644814732a43ae824", "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/PositivityCheckNeedsLinearityCheck.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/PositivityCheckNeedsLinearityCheck.agda", "max_line_length": 73, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/PositivityCheckNeedsLinearityCheck.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": 152, "size": 547 }
{-# OPTIONS --erased-cubical --safe --no-sized-types --no-guardedness --no-subtyping #-} module Agda.Builtin.Cubical.HCompU where open import Agda.Primitive open import Agda.Builtin.Sigma open import Agda.Primitive.Cubical renaming (primINeg to ~_; primIMax to _∨_; primIMin to _∧_; primHComp to hcomp; primTransp to transp; primComp to comp; itIsOne to 1=1) open import Agda.Builtin.Cubical.Path open import Agda.Builtin.Cubical.Sub renaming (Sub to _[_↦_]; primSubOut to outS; inc to inS) module Helpers where -- Homogeneous filling hfill : ∀ {ℓ} {A : Set ℓ} {φ : I} (u : ∀ i → Partial φ A) (u0 : A [ φ ↦ u i0 ]) (i : I) → A hfill {φ = φ} u u0 i = hcomp (λ j → \ { (φ = i1) → u (i ∧ j) 1=1 ; (i = i0) → outS u0 }) (outS u0) -- Heterogeneous filling defined using comp fill : ∀ {ℓ : I → Level} (A : ∀ i → Set (ℓ i)) {φ : I} (u : ∀ i → Partial φ (A i)) (u0 : A i0 [ φ ↦ u i0 ]) → ∀ i → A i fill A {φ = φ} u u0 i = comp (λ j → A (i ∧ j)) (λ j → \ { (φ = i1) → u (i ∧ j) 1=1 ; (i = i0) → outS u0 }) (outS {φ = φ} u0) module _ {ℓ} {A : Set ℓ} where refl : {x : A} → x ≡ x refl {x = x} = λ _ → x sym : {x y : A} → x ≡ y → y ≡ x sym p = λ i → p (~ i) cong : ∀ {ℓ'} {B : A → Set ℓ'} {x y : A} (f : (a : A) → B a) (p : x ≡ y) → PathP (λ i → B (p i)) (f x) (f y) cong f p = λ i → f (p i) isContr : ∀ {ℓ} → Set ℓ → Set ℓ isContr A = Σ A \ x → (∀ y → x ≡ y) fiber : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) (y : B) → Set (ℓ ⊔ ℓ') fiber {A = A} f y = Σ A \ x → f x ≡ y open Helpers primitive prim^glueU : {la : Level} {φ : I} {T : I → Partial φ (Set la)} {A : Set la [ φ ↦ T i0 ]} → PartialP φ (T i1) → outS A → hcomp T (outS A) prim^unglueU : {la : Level} {φ : I} {T : I → Partial φ (Set la)} {A : Set la [ φ ↦ T i0 ]} → hcomp T (outS A) → outS A -- Needed for transp. primFaceForall : (I → I) → I transpProof : ∀ {l} → (e : I → Set l) → (φ : I) → (a : Partial φ (e i0)) → (b : e i1 [ φ ↦ (\ o → transp (\ i → e i) i0 (a o)) ] ) → fiber (transp (\ i → e i) i0) (outS b) transpProof e φ a b = f , \ j → comp (\ i → e i) (\ i → \ { (φ = i1) → transp (\ j → e (j ∧ i)) (~ i) (a 1=1) ; (j = i0) → transp (\ j → e (j ∧ i)) (~ i) f ; (j = i1) → g (~ i) }) f where b' = outS {u = (\ o → transp (\ i → e i) i0 (a o))} b g : (k : I) → e (~ k) g k = fill (\ i → e (~ i)) (\ i → \ { (φ = i1) → transp (\ j → e (j ∧ ~ i)) i (a 1=1) ; (φ = i0) → transp (\ j → e (~ j ∨ ~ i)) (~ i) b' }) (inS b') k f = comp (\ i → e (~ i)) (\ i → \ { (φ = i1) → transp (\ j → e (j ∧ ~ i)) i (a 1=1); (φ = i0) → transp (\ j → e (~ j ∨ ~ i)) (~ i) b' }) b' {-# BUILTIN TRANSPPROOF transpProof #-}
{ "alphanum_fraction": 0.3844036697, "avg_line_length": 40.875, "ext": "agda", "hexsha": "cb074778afa666bde0170e5a17471343ac14cb2b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/HCompU.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "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": "cruhland/agda", "max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/HCompU.agda", "max_line_length": 171, "max_stars_count": null, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/HCompU.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1237, "size": 3270 }
{-# OPTIONS --safe #-} module Invert where open import Relation.Binary.PropositionalEquality open import Data.Nat open import Data.Nat.Properties _∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C) (g ∘ f) x = g (f x) pred₂ : ℕ → ℕ pred₂ = pred ∘ pred lemma : (a b : ℕ) → pred₂ (suc a + suc a) ≡ pred₂ (suc b + suc b) → a + a ≡ b + b lemma a b p = begin a + a ≡⟨⟩ pred₂ (suc (suc (a + a))) ≡⟨⟩ pred₂ (suc (suc a + a)) ≡⟨ cong (pred₂ ∘ suc) (+-comm (suc a) a) ⟩ pred₂ (suc (a + suc a)) ≡⟨⟩ pred₂ (suc a + suc a) ≡⟨ p ⟩ pred₂ (suc b + suc b) ≡⟨⟩ pred₂ (suc (b + suc b)) ≡⟨ cong (pred₂ ∘ suc) (+-comm b (suc b)) ⟩ pred₂ (suc (suc b + b)) ≡⟨⟩ b + b ∎ where open ≡-Reasoning invert : (a b : ℕ) → a + a ≡ b + b → a ≡ b invert zero zero p = refl invert (suc m) (suc n) p = cong suc (invert m n (lemma m n (cong pred₂ p)))
{ "alphanum_fraction": 0.5216881594, "avg_line_length": 25.0882352941, "ext": "agda", "hexsha": "74049821bde48b8b288184acf2e4c6ca9ee734b2", "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": "9576d5b76e6a868992dbe52930712ac67697bed2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "anqurvanillapy/fpl", "max_forks_repo_path": "agda/Invert.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2", "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": "anqurvanillapy/fpl", "max_issues_repo_path": "agda/Invert.agda", "max_line_length": 75, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "anqurvanillapy/fpl", "max_stars_repo_path": "agda/Invert.agda", "max_stars_repo_stars_event_max_datetime": "2019-08-24T22:47:47.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-24T22:47:47.000Z", "num_tokens": 394, "size": 853 }
module _ where postulate D : Set module A where infixr 5 _∷_ postulate _∷_ : Set₁ → D → D module B where infix 5 _∷_ postulate _∷_ : Set₁ → Set₁ → D open A open B foo : D foo = Set ∷ Set -- Expected error: -- -- <preciseErrorLocation> -- Ambiguous name _∷_. It could refer to any one of -- A._∷_ bound at ... -- B._∷_ bound at ...
{ "alphanum_fraction": 0.5983379501, "avg_line_length": 11.6451612903, "ext": "agda", "hexsha": "1204be9268681716198cf4430218f1f2b914adc7", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue1194m.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue1194m.agda", "max_line_length": 51, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue1194m.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": 135, "size": 361 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Tables, basic types and operations ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Table.Base where open import Data.Nat open import Data.Fin open import Data.Product using (_×_ ; _,_) open import Data.List as List using (List) open import Data.Vec as Vec using (Vec) open import Function using (_∘_; flip) ------------------------------------------------------------------------ -- Type record Table {a} (A : Set a) n : Set a where constructor tabulate field lookup : Fin n → A open Table public ------------------------------------------------------------------------ -- Basic operations module _ {a} {A : Set a} where head : ∀ {n} → Table A (suc n) → A head t = lookup t zero tail : ∀ {n} → Table A (suc n) → Table A n tail t = tabulate (lookup t ∘ suc) uncons : ∀ {n} → Table A (suc n) → A × Table A n uncons t = head t , tail t remove : ∀ {n} → Fin (suc n) → Table A (suc n) → Table A n remove i t = tabulate (lookup t ∘ punchIn i) ------------------------------------------------------------------------ -- Operations for transforming tables module _ {a} {A : Set a} where rearrange : ∀ {m n} → (Fin m → Fin n) → Table A n → Table A m rearrange f t = tabulate (lookup t ∘ f) module _ {a b} {A : Set a} {B : Set b} where map : ∀ {n} → (A → B) → Table A n → Table B n map f t = tabulate (f ∘ lookup t) _⊛_ : ∀ {n} → Table (A → B) n → Table A n → Table B n fs ⊛ xs = tabulate λ i → lookup fs i (lookup xs i) ------------------------------------------------------------------------ -- Operations for reducing tables module _ {a b} {A : Set a} {B : Set b} where foldr : ∀ {n} → (A → B → B) → B → Table A n → B foldr {n = zero} f z t = z foldr {n = suc n} f z t = f (head t) (foldr f z (tail t)) foldl : ∀ {n} → (B → A → B) → B → Table A n → B foldl {n = zero} f z t = z foldl {n = suc n} f z t = foldl f (f z (head t)) (tail t) ------------------------------------------------------------------------ -- Operations for building tables module _ {a} {A : Set a} where replicate : ∀ {n} → A → Table A n replicate x = tabulate (λ _ → x) ------------------------------------------------------------------------ -- Operations for converting tables module _ {a} {A : Set a} where toList : ∀ {n} → Table A n → List A toList = List.tabulate ∘ lookup fromList : ∀ (xs : List A) → Table A (List.length xs) fromList = tabulate ∘ List.lookup fromVec : ∀ {n} → Vec A n → Table A n fromVec = tabulate ∘ Vec.lookup toVec : ∀ {n} → Table A n → Vec A n toVec = Vec.tabulate ∘ lookup
{ "alphanum_fraction": 0.4631655726, "avg_line_length": 28.5625, "ext": "agda", "hexsha": "1e4eec31ec7a6fe62b67ceea11a122db3bf3dba3", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Table/Base.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/Table/Base.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Table/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 791, "size": 2742 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category using () renaming (Category to Setoid-Category) open import Categories.Category.Monoidal module Categories.Enriched.NaturalTransformation {o ℓ e} {V : Setoid-Category o ℓ e} (M : Monoidal V) where open import Level open import Categories.Category.Monoidal.Properties M using (module Kelly's) open import Categories.Category.Monoidal.Reasoning M open import Categories.Category.Monoidal.Utilities M open import Categories.Enriched.Category M open import Categories.Enriched.Functor M renaming (id to idF) open import Categories.Morphism.Reasoning V import Categories.Morphism.IsoEquiv V as IsoEquiv open import Categories.NaturalTransformation using (ntHelper) renaming (NaturalTransformation to Setoid-NT) open Setoid-Category V renaming (Obj to ObjV; id to idV) open Commutation open Monoidal M open Shorthands module _ {c d} {C : Category c} {D : Category d} where private module C = Category C module D = Category D module U = Underlying D record NaturalTransformation (F G : Functor C D) : Set (ℓ ⊔ e ⊔ c) where eta-equality private module F = Functor F module G = Functor G field comp : ∀ X → F.₀ X U.⇒ G.₀ X commute : ∀ {X Y} → [ C [ X , Y ] ⇒ D [ F.₀ X , G.₀ Y ] ]⟨ unitorˡ.to ⇒⟨ unit ⊗₀ C [ X , Y ] ⟩ comp Y ⊗₁ F.₁ ⇒⟨ D [ F.₀ Y , G.₀ Y ] ⊗₀ D [ F.₀ X , F.₀ Y ] ⟩ D.⊚ ≈ unitorʳ.to ⇒⟨ C [ X , Y ] ⊗₀ unit ⟩ G.₁ ⊗₁ comp X ⇒⟨ D [ G.₀ X , G.₀ Y ] ⊗₀ D [ F.₀ X , G.₀ X ] ⟩ D.⊚ ⟩ -- A shorthand for the components of a natural transformation: -- -- α [ X ] -- -- is the X-component of the family { αₓ } of "morphisms" that -- forms the natural transformation α. infixl 16 _[_] _[_] = comp open NaturalTransformation open D hiding (id) open IsoEquiv._≃_ id : ∀ {F : Functor C D} → NaturalTransformation F F id {F} = record { comp = λ _ → D.id ; commute = λ {X} {Y} → begin ⊚ ∘ D.id ⊗₁ F.₁ ∘ λ⇐ ≈⟨ refl⟩∘⟨ pushˡ serialize₁₂ ⟩ ⊚ ∘ D.id ⊗₁ idV ∘ idV ⊗₁ F.₁ ∘ λ⇐ ≈⟨ pullˡ unitˡ ⟩ unitorˡ.from ∘ idV ⊗₁ F.₁ ∘ λ⇐ ≈⟨ pullˡ unitorˡ-commute-from ⟩ (F.₁ ∘ unitorˡ.from) ∘ λ⇐ ≈⟨ cancelʳ unitorˡ.isoʳ ⟩ F.₁ ≈˘⟨ cancelʳ unitorʳ.isoʳ ⟩ (F.₁ ∘ unitorʳ.from) ∘ ρ⇐ ≈˘⟨ pullˡ unitorʳ-commute-from ⟩ unitorʳ.from ∘ F.₁ ⊗₁ idV ∘ ρ⇐ ≈˘⟨ pullˡ unitʳ ⟩ ⊚ ∘ idV ⊗₁ D.id ∘ F.₁ ⊗₁ idV ∘ ρ⇐ ≈˘⟨ refl⟩∘⟨ pushˡ serialize₂₁ ⟩ ⊚ ∘ F.₁ ⊗₁ D.id ∘ ρ⇐ ∎ } where module F = Functor F infixr 9 _∘ᵥ_ -- Vertical composition _∘ᵥ_ : {F G H : Functor C D} → NaturalTransformation G H → NaturalTransformation F G → NaturalTransformation F H _∘ᵥ_ {F} {G} {H} α β = record { comp = λ X → α [ X ] U.∘ β [ X ] ; commute = λ {X} {Y} → begin ⊚ ∘ (⊚ ∘ α [ Y ] ⊗₁ β [ Y ] ∘ λ⇐) ⊗₁ F.₁ ∘ λ⇐ ≈⟨ helper (α [ Y ]) (β [ Y ]) F.₁ λ⇐ ⟩ ⊚ ∘ α [ Y ] ⊗₁ (⊚ ∘ β [ Y ] ⊗₁ F.₁ ∘ λ⇐) ∘ λ⇐ ≈⟨ refl⟩∘⟨ refl⟩⊗⟨ commute β ⟩∘⟨refl ⟩ ⊚ ∘ α [ Y ] ⊗₁ (⊚ ∘ G.₁ ⊗₁ β [ X ] ∘ ρ⇐) ∘ λ⇐ ≈˘⟨ helper (α [ Y ]) G.₁ (β [ X ]) ρ⇐ ⟩ ⊚ ∘ (⊚ ∘ α [ Y ] ⊗₁ G.₁ ∘ λ⇐) ⊗₁ β [ X ] ∘ ρ⇐ ≈⟨ refl⟩∘⟨ commute α ⟩⊗⟨refl ⟩∘⟨refl ⟩ ⊚ ∘ (⊚ ∘ H.₁ ⊗₁ α [ X ] ∘ ρ⇐) ⊗₁ β [ X ] ∘ ρ⇐ ≈˘⟨ refl⟩∘⟨ assoc ⟩⊗⟨refl ⟩∘⟨refl ⟩ ⊚ ∘ ((⊚ ∘ H.₁ ⊗₁ α [ X ]) ∘ ρ⇐) ⊗₁ β [ X ] ∘ ρ⇐ ≈⟨ refl⟩∘⟨ split₁ʳ ⟩∘⟨refl ⟩ ⊚ ∘ ((⊚ ∘ H.₁ ⊗₁ α [ X ]) ⊗₁ β [ X ] ∘ ρ⇐ ⊗₁ idV) ∘ ρ⇐ ≈⟨ pullˡ (pullˡ ⊚-assoc-var) ⟩ ((⊚ ∘ H.₁ ⊗₁ (⊚ ∘ α [ X ] ⊗₁ β [ X ]) ∘ α⇒) ∘ ρ⇐ ⊗₁ idV) ∘ ρ⇐ ≈˘⟨ pushʳ (pushʳ (switch-tofromˡ associator (to-≈ triangle-iso))) ⟩∘⟨refl ⟩ (⊚ ∘ H.₁ ⊗₁ (⊚ ∘ α [ X ] ⊗₁ β [ X ]) ∘ idV ⊗₁ λ⇐) ∘ ρ⇐ ≈˘⟨ pushʳ (split₂ʳ ⟩∘⟨refl) ⟩ ⊚ ∘ H.₁ ⊗₁ ((⊚ ∘ α [ X ] ⊗₁ β [ X ]) ∘ λ⇐) ∘ ρ⇐ ≈⟨ refl⟩∘⟨ refl⟩⊗⟨ assoc ⟩∘⟨refl ⟩ ⊚ ∘ H.₁ ⊗₁ (⊚ ∘ α [ X ] ⊗₁ β [ X ] ∘ λ⇐) ∘ ρ⇐ ∎ } where module F = Functor F module G = Functor G module H = Functor H helper : ∀ {X₁ X₂ X₃ X₄ Y₁ Y₂ Z} (f : X₃ U.⇒ X₄) (g : Y₁ ⇒ D [ X₂ , X₃ ]) (h : Y₂ ⇒ D [ X₁ , X₂ ]) (i : Z ⇒ Y₁ ⊗₀ Y₂) → ⊚ ∘ (⊚ ∘ f ⊗₁ g ∘ λ⇐) ⊗₁ h ∘ i ≈ ⊚ ∘ f ⊗₁ (⊚ ∘ g ⊗₁ h ∘ i) ∘ λ⇐ helper f g h i = begin ⊚ ∘ (⊚ ∘ f ⊗₁ g ∘ λ⇐) ⊗₁ h ∘ i ≈˘⟨ refl⟩∘⟨ assoc ⟩⊗⟨refl ⟩∘⟨refl ⟩ ⊚ ∘ ((⊚ ∘ f ⊗₁ g) ∘ λ⇐) ⊗₁ h ∘ i ≈⟨ refl⟩∘⟨ split₁ʳ ⟩∘⟨refl ⟩ ⊚ ∘ ((⊚ ∘ f ⊗₁ g) ⊗₁ h ∘ λ⇐ ⊗₁ idV) ∘ i ≈⟨ pullˡ (pullˡ ⊚-assoc-var) ⟩ ((⊚ ∘ f ⊗₁ (⊚ ∘ g ⊗₁ h) ∘ α⇒) ∘ λ⇐ ⊗₁ idV) ∘ i ≈˘⟨ pushʳ (pushʳ (switch-tofromˡ associator (to-≈ Kelly's.coherence-iso₁))) ⟩∘⟨refl ⟩ (⊚ ∘ f ⊗₁ (⊚ ∘ g ⊗₁ h) ∘ λ⇐) ∘ i ≈⟨ pullʳ (pullʳ unitorˡ-commute-to) ⟩ ⊚ ∘ f ⊗₁ (⊚ ∘ g ⊗₁ h) ∘ idV ⊗₁ i ∘ λ⇐ ≈˘⟨ refl⟩∘⟨ pushˡ split₂ʳ ⟩ ⊚ ∘ f ⊗₁ ((⊚ ∘ g ⊗₁ h) ∘ i) ∘ λ⇐ ≈⟨ refl⟩∘⟨ refl⟩⊗⟨ assoc ⟩∘⟨refl ⟩ ⊚ ∘ f ⊗₁ (⊚ ∘ g ⊗₁ h ∘ i) ∘ λ⇐ ∎ -- A V-enriched natural transformation induces an ordinary natural -- transformation on the underlying functors. UnderlyingNT : {F G : Functor C D} → NaturalTransformation F G → Setoid-NT (UnderlyingFunctor F) (UnderlyingFunctor G) UnderlyingNT {F} {G} α = ntHelper (record { η = comp α ; commute = λ {X Y} f → begin ⊚ ∘ α [ Y ] ⊗₁ (F.₁ ∘ f) ∘ λ⇐ ≈⟨ refl⟩∘⟨ split₂ʳ ⟩∘⟨refl ⟩ ⊚ ∘ (α [ Y ] ⊗₁ F.₁ ∘ idV ⊗₁ f) ∘ λ⇐ ≈˘⟨ refl⟩∘⟨ extendˡ unitorˡ-commute-to ⟩ ⊚ ∘ (α [ Y ] ⊗₁ F.₁ ∘ λ⇐) ∘ f ≈⟨ extendʳ (commute α) ⟩ ⊚ ∘ (G.₁ ⊗₁ α [ X ] ∘ ρ⇐) ∘ f ≈⟨ refl⟩∘⟨ extendˡ unitorʳ-commute-to ⟩ ⊚ ∘ (G.₁ ⊗₁ α [ X ] ∘ f ⊗₁ idV) ∘ ρ⇐ ≈˘⟨ refl⟩∘⟨ split₁ʳ ⟩∘⟨refl ⟩ ⊚ ∘ (G.₁ ∘ f) ⊗₁ α [ X ] ∘ ρ⇐ ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ to-≈ Kelly's.coherence-iso₃ ⟩ ⊚ ∘ (G.₁ ∘ f) ⊗₁ α [ X ] ∘ λ⇐ ∎ }) where module F = Functor F module G = Functor G module UnderlyingNT {F} {G} α = Setoid-NT (UnderlyingNT {F} {G} α) module _ {c d e} {C : Category c} {D : Category d} {E : Category e} where private module C = Category C module D = Category D module E = Category E module U = Underlying E open NaturalTransformation infixr 9 _∘ₕ_ _∘ˡ_ _∘ʳ_ -- Left- and right-hand composition with a functor _∘ˡ_ : {G H : Functor C D} (F : Functor D E) → NaturalTransformation G H → NaturalTransformation (F ∘F G) (F ∘F H) _∘ˡ_ {G} {H} F α = record { comp = λ X → F.₁ ∘ α [ X ] ; commute = λ {X Y} → begin E.⊚ ∘ (F.₁ ∘ α [ Y ]) ⊗₁ (F.₁ ∘ G.₁) ∘ λ⇐ ≈⟨ refl⟩∘⟨ pushˡ ⊗-distrib-over-∘ ⟩ E.⊚ ∘ (F.₁ ⊗₁ F.₁) ∘ (α [ Y ] ⊗₁ G.₁) ∘ λ⇐ ≈˘⟨ extendʳ F.homomorphism ⟩ F.₁ ∘ D.⊚ ∘ (α [ Y ] ⊗₁ G.₁) ∘ λ⇐ ≈⟨ refl⟩∘⟨ commute α ⟩ F.₁ ∘ D.⊚ ∘ (H.₁ ⊗₁ α [ X ]) ∘ ρ⇐ ≈⟨ extendʳ F.homomorphism ⟩ E.⊚ ∘ (F.₁ ⊗₁ F.₁) ∘ (H.₁ ⊗₁ α [ X ]) ∘ ρ⇐ ≈˘⟨ refl⟩∘⟨ pushˡ ⊗-distrib-over-∘ ⟩ E.⊚ ∘ (F.₁ ∘ H.₁) ⊗₁ (F.₁ ∘ α [ X ]) ∘ ρ⇐ ∎ } where module F = Functor F module G = Functor G module H = Functor H _∘ʳ_ : {G H : Functor D E} → NaturalTransformation G H → (F : Functor C D) → NaturalTransformation (G ∘F F) (H ∘F F) _∘ʳ_ {G} {H} α F = record { comp = λ X → α [ F.₀ X ] ; commute = λ {X Y} → begin E.⊚ ∘ α [ F.₀ Y ] ⊗₁ (G.₁ ∘ F.₁) ∘ λ⇐ ≈⟨ refl⟩∘⟨ split₂ʳ ⟩∘⟨refl ⟩ E.⊚ ∘ (α [ F.₀ Y ] ⊗₁ G.₁ ∘ idV ⊗₁ F.₁) ∘ λ⇐ ≈˘⟨ refl⟩∘⟨ extendˡ unitorˡ-commute-to ⟩ E.⊚ ∘ (α [ F.₀ Y ] ⊗₁ G.₁ ∘ λ⇐) ∘ F.₁ ≈⟨ extendʳ (commute α) ⟩ E.⊚ ∘ (H.₁ ⊗₁ α [ F.₀ X ] ∘ ρ⇐) ∘ F.₁ ≈⟨ refl⟩∘⟨ extendˡ unitorʳ-commute-to ⟩ E.⊚ ∘ (H.₁ ⊗₁ α [ F.₀ X ] ∘ F.₁ ⊗₁ idV) ∘ ρ⇐ ≈˘⟨ refl⟩∘⟨ split₁ʳ ⟩∘⟨refl ⟩ E.⊚ ∘ (H.₁ ∘ F.₁) ⊗₁ α [ F.₀ X ] ∘ ρ⇐ ∎ } where module F = Functor F module G = Functor G module H = Functor H -- Horizontal composition _∘ₕ_ : {H I : Functor D E} {F G : Functor C D} → NaturalTransformation H I → NaturalTransformation F G → NaturalTransformation (H ∘F F) (I ∘F G) _∘ₕ_ {_} {I} {F} {_} α β = (I ∘ˡ β) ∘ᵥ (α ∘ʳ F)
{ "alphanum_fraction": 0.4623181493, "avg_line_length": 37.7747747748, "ext": "agda", "hexsha": "6b1c6944a261b0591600b58170e545ac0f70fcad", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "MirceaS/agda-categories", "max_forks_repo_path": "src/Categories/Enriched/NaturalTransformation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "MirceaS/agda-categories", "max_issues_repo_path": "src/Categories/Enriched/NaturalTransformation.agda", "max_line_length": 96, "max_stars_count": null, "max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "MirceaS/agda-categories", "max_stars_repo_path": "src/Categories/Enriched/NaturalTransformation.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4192, "size": 8386 }
-- This file tests that implicit record fields are not printed out (by -- default). -- Andreas, 2016-07-20 Repaired this long disfunctional test case. module ImplicitRecordFields where record R : Set₁ where field {A} : Set f : A → A {B C} D {E} : Set g : B → C → E postulate A : Set r : R data _≡_ {A : Set₁} (x : A) : A → Set where refl : x ≡ x foo : r ≡ record { A = A ; f = λ x → x ; B = A ; C = A ; D = A ; g = λ x _ → x } foo = refl -- EXPECTED ERROR: -- .R.A r != A of type Set -- when checking that the expression refl has type -- r ≡ record { f = λ x → x ; D = A ; g = λ x _ → x }
{ "alphanum_fraction": 0.5211480363, "avg_line_length": 18.3888888889, "ext": "agda", "hexsha": "183342e4e44018aea301f8552001d389ba2ee53e", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/ImplicitRecordFields.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/ImplicitRecordFields.agda", "max_line_length": 70, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/ImplicitRecordFields.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": 241, "size": 662 }
module with-equalities where open import Agda.Builtin.List open import Common.Bool open import Common.Equality module _ {A : Set} where filter : (A → Bool) → List A → List A filter p [] = [] filter p (x ∷ xs) = if p x then x ∷ filter p xs else filter p xs filter-filter : ∀ p xs → filter p (filter p xs) ≡ filter p xs filter-filter p [] = refl filter-filter p (x ∷ xs) with p x in eq ... | false = filter-filter p xs -- easy ... | true -- second filter stuck on `p x`: rewrite by `eq`! rewrite eq = cong (x ∷_) (filter-filter p xs) open import Agda.Builtin.Nat open import Agda.Builtin.Sigma double : Nat → Set double m = Σ Nat λ n → n + n ≡ m -- 2*_ : Nat → Σ Nat double -- 2*_ n with m ← n + n = m , n , {!!} -- At this point we do not remember that m ≡ n + n and cannot -- conclude the proof. -- If only we could give a name to the proof that -- `p ≡ e` after a `with p ← e` clause ! 2*_ : Nat → Σ Nat double 2*_ n with m ← n + n in eq = m , n , eq data ⊥ : Set where ⊥-elim : ⊥ → {A : Set} → A ⊥-elim () ¬odd0 : ∀ n → 2 * n + 1 ≡ 0 → ⊥ ¬odd0 zero () ¬odd0 (suc n) () data Vec (A : Set) : Nat → Set where [] : Vec A 0 _∷_ : ∀ {n} → A → Vec A n → Vec A (suc n) module _ {A : Set} where oddhead : ∀ {n} → Vec A (2 * n + 1) → A oddhead {n} xs -- here we cannot split on `xs` because Agda does not know -- whether `2 * n + 1` can unify with `0` or not -- A possible solution: abstract over p and then match on xs. -- with p ← (2 * n + 1) | xs -- ... | x ∷ _ = x -- ... | [] = {!!} -- The problem however is that Agda insists we should consider -- two cases: `xs = []` and `xs = x ∷ _`. And in the `[]` branch -- we only know that: -- p : Nat -- n : Nat -- xs : Vec A 0 -- If only we had somehow recorded that `p ← (2 * n + 1)` happened! -- This is what the inspect construct allows us to do. with p ← (2 * n + 1) in eq | xs ... | x ∷ _ = x -- we can now use this equality proof to dismiss the impossible case. ... | [] = ⊥-elim (¬odd0 n eq) -- If you do not want to name the nat corresponding to `2 * n + 1`, -- you can use inspect together with an implicit with oddhead' : ∀ {n} → Vec A (2 * n + 1) → A oddhead' {n} xs with {2 * n + 1} in eq | xs ... | x ∷ _ = x ... | [] = ⊥-elim (¬odd0 n eq)
{ "alphanum_fraction": 0.5468483816, "avg_line_length": 27.9523809524, "ext": "agda", "hexsha": "08397c0dd1528c227d0c4d9e8aec9cec5455d6bd", "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/with-equalities.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/with-equalities.agda", "max_line_length": 71, "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/with-equalities.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": 838, "size": 2348 }
module Algebra.LabelledGraph.Theorems where open import Algebra.LabelledGraph open import Algebra.LabelledGraph.Reasoning open import Algebra.Dioid open import Algebra.Graph using (Graph) import Algebra.Graph as Graph import Algebra.Graph.Reasoning as Graph import Algebra.Graph.Theorems as Graph import Algebra.Dioid.Bool as Bool import Algebra.Dioid.Bool.Theorems as Bool -- | Laws of labelled graphs associativity : ∀ {A D eq} {d : Dioid D eq} {a b c : LabelledGraph d A} {r : D} -> (a [ r ]> b) [ r ]> c ≡ a [ r ]> (b [ r ]> c) associativity {_} {_} {_} {_} {a} {b} {c} {r} = right-decomposition >> symmetry left-decomposition absorption : ∀ {A D eq} {d : Dioid D eq} {a b : LabelledGraph d A} {r : D} -> a [ r ]> b ≡ a [ r ]> b + a + b absorption {_} {_} {_} {d} {a} {b} {r} = begin (a [ r ]> b) ≡⟨ symmetry right-identity ⟩ (a [ r ]> b) [ Dioid.zero d ]> ε ≡⟨ right-decomposition ⟩ (a [ r ]> b) + (a + ε) + (b + ε) ≡⟨ L (R right-identity ) ⟩ (a [ r ]> b) + a + (b + ε) ≡⟨ R right-identity ⟩ (a [ r ]> b) + a + b ∎ idempotence : ∀ {A D eq} {d : Dioid D eq} {a : LabelledGraph d A} -> a ≡ a + a idempotence {_} {_} {_} {_} {a} = begin a ≡⟨ symmetry right-identity ⟩ a + ε ≡⟨ symmetry right-identity ⟩ a + ε + ε ≡⟨ right-decomposition ⟩ (a + ε) + (a + ε) + (ε + ε) ≡⟨ right-congruence left-identity ⟩ (a + ε) + (a + ε) + ε ≡⟨ right-identity ⟩ (a + ε) + (a + ε) ≡⟨ right-congruence right-identity ⟩ (a + ε) + a ≡⟨ left-congruence right-identity ⟩ a + a ∎ left-absorption : ∀ {A D eq} {d : Dioid D eq} {a b : LabelledGraph d A} {r : D} -> a [ r ]> b ≡ a [ r ]> b + a left-absorption {_} {_} {_} {_} {a} {b} {r} = begin (a [ r ]> b) ≡⟨ absorption ⟩ (a [ r ]> b) + a + b ≡⟨ L (R idempotence) ⟩ (a [ r ]> b) + (a + a) + b ≡⟨ associativity ⟩ (a [ r ]> b) + (a + a + b) ≡⟨ R zero-commutativity ⟩ (a [ r ]> b) + (b + (a + a)) ≡⟨ R (symmetry associativity) ⟩ (a [ r ]> b) + ((b + a) + a) ≡⟨ R (L zero-commutativity) ⟩ (a [ r ]> b) + ((a + b) + a) ≡⟨ symmetry associativity ⟩ (a [ r ]> b) + (a + b) + a ≡⟨ L (symmetry associativity) ⟩ (a [ r ]> b) + a + b + a ≡⟨ L (symmetry absorption) ⟩ (a [ r ]> b) + a ∎ right-absorption : ∀ {A D eq} {d : Dioid D eq} {a b : LabelledGraph d A} {r : D} -> a [ r ]> b ≡ a [ r ]> b + b right-absorption {_} {_} {_} {_} {a} {b} {r} = begin (a [ r ]> b) ≡⟨ absorption ⟩ (a [ r ]> b) + a + b ≡⟨ R idempotence ⟩ (a [ r ]> b) + a + (b + b) ≡⟨ symmetry associativity ⟩ (a [ r ]> b) + a + b + b ≡⟨ L (symmetry absorption) ⟩ (a [ r ]> b) + b ∎ right-distributivity : ∀ {A D eq} {d : Dioid D eq} {a b c : LabelledGraph d A} {r : D} -> (a + b) [ r ]> c ≡ a [ r ]> c + b [ r ]> c right-distributivity {_} {_} {_} {_} {a} {b} {c} {r} = begin (a + b) [ r ]> c ≡⟨ right-decomposition ⟩ a + b + (a [ r ]> c) + (b [ r ]> c) ≡⟨ L zero-commutativity ⟩ (a [ r ]> c) + (a + b) + (b [ r ]> c) ≡⟨ L (symmetry associativity) ⟩ ((a [ r ]> c) + a) + b + (b [ r ]> c) ≡⟨ L (L (symmetry left-absorption)) ⟩ (a [ r ]> c) + b + (b [ r ]> c) ≡⟨ associativity ⟩ (a [ r ]> c) + (b + (b [ r ]> c)) ≡⟨ R zero-commutativity ⟩ (a [ r ]> c) + ((b [ r ]> c) + b) ≡⟨ R (symmetry left-absorption) ⟩ (a [ r ]> c) + (b [ r ]> c) ∎ left-distributivity : ∀ {A D eq} {d : Dioid D eq} {a b c : LabelledGraph d A} {r : D} -> a [ r ]> (b + c) ≡ a [ r ]> b + a [ r ]> c left-distributivity {_} {_} {_} {_} {a} {b} {c} {r} = begin a [ r ]> (b + c) ≡⟨ left-decomposition ⟩ a [ r ]> b + a [ r ]> c + (b + c) ≡⟨ symmetry associativity ⟩ a [ r ]> b + a [ r ]> c + b + c ≡⟨ L associativity ⟩ a [ r ]> b + (a [ r ]> c + b) + c ≡⟨ L (R zero-commutativity) ⟩ a [ r ]> b + (b + a [ r ]> c) + c ≡⟨ L (symmetry associativity) ⟩ a [ r ]> b + b + a [ r ]> c + c ≡⟨ L (L (symmetry right-absorption)) ⟩ a [ r ]> b + a [ r ]> c + c ≡⟨ associativity ⟩ a [ r ]> b + (a [ r ]> c + c) ≡⟨ R (symmetry right-absorption) ⟩ a [ r ]> b + a [ r ]> c ∎ -- | Conversion functions -- These allow for a conversion between LabelledGraphs labelled by Bools and ordinary Graphs. -- As `graph-laws` and `labelled-graph-laws` demonstrates, these preserve their respective laws. to-graph : ∀ {A} -> LabelledGraph Bool.bool-dioid A -> Graph A to-graph ε = Graph.ε to-graph (v x) = Graph.v x to-graph (x [ Bool.false ]> y) = to-graph x Graph.+ to-graph y to-graph (x [ Bool.true ]> y) = to-graph x Graph.* to-graph y labelled-graph-laws : ∀ {A} {x y : LabelledGraph Bool.bool-dioid A} -> x ≡ y -> (to-graph x) Graph.≡ (to-graph y) labelled-graph-laws reflexivity = Graph.reflexivity labelled-graph-laws (symmetry eq) = Graph.symmetry (labelled-graph-laws eq) labelled-graph-laws (transitivity eq eq₁) = Graph.transitivity (labelled-graph-laws eq) (labelled-graph-laws eq₁) labelled-graph-laws (left-congruence {r = r} eq) with r ... | Bool.true = Graph.*left-congruence (labelled-graph-laws eq) ... | Bool.false = Graph.+left-congruence (labelled-graph-laws eq) labelled-graph-laws (right-congruence {r = r} eq) with r ... | Bool.true = Graph.*right-congruence (labelled-graph-laws eq) ... | Bool.false = Graph.+right-congruence (labelled-graph-laws eq) labelled-graph-laws (dioid-congruence eq) = dioid-recur eq where dioid-recur : ∀ {A} {x y : LabelledGraph Bool.bool-dioid A} {r s : Bool.Bool} -> r Bool.≡ s -> (to-graph (x [ r ]> y)) Graph.≡ (to-graph (x [ s ]> y)) dioid-recur Bool.reflexivity = Graph.reflexivity dioid-recur (Bool.symmetry eq) = Graph.symmetry (dioid-recur eq) dioid-recur (Bool.transitivity eq eq₁) = Graph.transitivity (dioid-recur eq) (dioid-recur eq₁) labelled-graph-laws zero-commutativity = Graph.+commutativity labelled-graph-laws (left-identity {r = r}) with r ... | Bool.true = Graph.*left-identity ... | Bool.false = Graph.+commutativity Graph.>> Graph.+identity labelled-graph-laws (right-identity {r = r}) with r ... | Bool.true = Graph.*right-identity ... | Bool.false = Graph.+identity labelled-graph-laws (left-decomposition {r = r} {s}) with r | s ... | Bool.true | Bool.true = Graph.*associativity Graph.>> Graph.decomposition ... | Bool.true | Bool.false = Graph.*+ltriple ... | Bool.false | Bool.true = Graph.+*ltriple ... | Bool.false | Bool.false = Graph.++ltriple labelled-graph-laws (right-decomposition {r = r} {s}) with r | s ... | Bool.true | Bool.true = Graph.decomposition ... | Bool.true | Bool.false = Graph.*+rtriple ... | Bool.false | Bool.true = Graph.+*rtriple ... | Bool.false | Bool.false = Graph.++rtriple labelled-graph-laws (label-addition {r = r} {s}) with r | s ... | Bool.true | Bool.true = Graph.+idempotence ... | Bool.true | Bool.false = Graph.+associativity Graph.>> Graph.absorption ... | Bool.false | Bool.true = (Graph.+commutativity Graph.>> Graph.+associativity) Graph.>> Graph.absorption ... | Bool.false | Bool.false = Graph.+idempotence from-graph : ∀ {A D eq} {d : Dioid D eq} -> Graph A -> LabelledGraph d A from-graph Graph.ε = ε from-graph (Graph.v x) = v x from-graph {_} {_} {_} {d} (x Graph.+ y) = from-graph x [ Dioid.zero d ]> from-graph y from-graph {_} {_} {_} {d} (x Graph.* y) = from-graph x [ Dioid.one d ]> from-graph y graph-laws : ∀ {A D eq} {d : Dioid D eq} {x y : Graph A} -> x Graph.≡ y -> _≡_ {A} {D} {eq} {d} (from-graph x) (from-graph y) graph-laws {x = x} {.x} Graph.reflexivity = reflexivity graph-laws {x = x} {y} (Graph.symmetry eq) = symmetry (graph-laws eq) graph-laws {x = x} {y} (Graph.transitivity eq eq₁) = transitivity (graph-laws eq) (graph-laws eq₁) graph-laws {x = .(_ Graph.+ _)} {.(_ Graph.+ _)} (Graph.+left-congruence eq) = left-congruence (graph-laws eq) graph-laws {x = .(_ Graph.* _)} {.(_ Graph.* _)} (Graph.*left-congruence eq) = left-congruence (graph-laws eq) graph-laws {x = .(_ Graph.* _)} {.(_ Graph.* _)} (Graph.*right-congruence eq) = right-congruence (graph-laws eq) graph-laws {x = .(_ Graph.+ _)} {.(_ Graph.+ _)} Graph.+commutativity = zero-commutativity graph-laws {x = .(_ Graph.+ (_ Graph.+ _))} {.(_ Graph.+ _ Graph.+ _)} Graph.+associativity = symmetry associativity graph-laws {x = .(Graph.ε Graph.* y)} {y} Graph.*left-identity = left-identity graph-laws {x = .(y Graph.* Graph.ε)} {y} Graph.*right-identity = right-identity graph-laws {x = .(_ Graph.* (_ Graph.* _))} {.(_ Graph.* _ Graph.* _)} Graph.*associativity = symmetry associativity graph-laws {x = .(_ Graph.* (_ Graph.+ _))} {.(_ Graph.* _ Graph.+ _ Graph.* _)} Graph.left-distributivity = left-distributivity graph-laws {x = .((_ Graph.+ _) Graph.* _)} {.(_ Graph.* _ Graph.+ _ Graph.* _)} Graph.right-distributivity = right-distributivity graph-laws {x = .(_ Graph.* _ Graph.* _)} {.(_ Graph.* _ Graph.+ _ Graph.* _ Graph.+ _ Graph.* _)} Graph.decomposition = right-decomposition to-from-identity : ∀ {A} {x : Graph A} -> (to-graph (from-graph x)) Graph.≡ x to-from-identity {x = Graph.ε} = Graph.reflexivity to-from-identity {x = Graph.v x} = Graph.reflexivity to-from-identity {x = x₁ Graph.+ x₂} = Graph.symmetry (Graph.+left-congruence (Graph.symmetry (to-from-identity {x = x₁}))) Graph.>> Graph.symmetry (Graph.+right-congruence (Graph.symmetry (to-from-identity {x = x₂}))) to-from-identity {x = x₁ Graph.* x₂} = Graph.symmetry (Graph.*left-congruence (Graph.symmetry (to-from-identity {x = x₁}))) Graph.>> Graph.symmetry (Graph.*right-congruence (Graph.symmetry (to-from-identity {x = x₂}))) from-to-identity : ∀ {A} {x : LabelledGraph Bool.bool-dioid A} -> (from-graph (to-graph x)) ≡ x from-to-identity {x = ε} = reflexivity from-to-identity {x = v x} = reflexivity from-to-identity {x = x₁ [ d ]> x₂} with d ... | Bool.true = symmetry (left-congruence (symmetry (from-to-identity {x = x₁}))) >> symmetry (right-congruence (symmetry (from-to-identity {x = x₂}))) ... | Bool.false = symmetry (left-congruence (symmetry (from-to-identity {x = x₁}))) >> symmetry (right-congruence (symmetry (from-to-identity {x = x₂})))
{ "alphanum_fraction": 0.574632713, "avg_line_length": 55.7923497268, "ext": "agda", "hexsha": "be64e777a8554ac9bf665a5999b5684d061c9d9e", "lang": "Agda", "max_forks_count": 6, "max_forks_repo_forks_event_max_datetime": "2019-05-09T23:53:28.000Z", "max_forks_repo_forks_event_min_datetime": "2017-12-17T20:48:20.000Z", "max_forks_repo_head_hexsha": "0fdb96c0233d9be83eba637f0434d0fd22aefb1d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "snowleopard/alga-proofs", "max_forks_repo_path": "src/Algebra/LabelledGraph/Theorems.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "0fdb96c0233d9be83eba637f0434d0fd22aefb1d", "max_issues_repo_issues_event_max_datetime": "2018-06-23T13:54:02.000Z", "max_issues_repo_issues_event_min_datetime": "2018-04-12T16:25:13.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "snowleopard/alga-proofs", "max_issues_repo_path": "src/Algebra/LabelledGraph/Theorems.agda", "max_line_length": 140, "max_stars_count": 60, "max_stars_repo_head_hexsha": "0fdb96c0233d9be83eba637f0434d0fd22aefb1d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "snowleopard/alga-proofs", "max_stars_repo_path": "src/Algebra/LabelledGraph/Theorems.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:05:29.000Z", "max_stars_repo_stars_event_min_datetime": "2017-12-27T14:57:04.000Z", "num_tokens": 3778, "size": 10210 }
------------------------------------------------------------------------------ -- Examples of translation of logical schemata ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOL.SchemataATP where open import FOL.Base ------------------------------------------------------------------------------ module NonSchemas where postulate A B C : Set A¹ : D → Set A² B² : D → D → Set A³ B³ C³ : D → D → D → Set postulate id : A → A {-# ATP prove id #-} postulate id¹ : ∀ {x} → A¹ x → A¹ x {-# ATP prove id¹ #-} postulate id² : ∀ {x y} → A² x y → A² x y {-# ATP prove id² #-} postulate ∨-comm : A ∨ B → B ∨ A {-# ATP prove ∨-comm #-} postulate ∨-comm² : ∀ {x y} → A² x y ∨ B² x y → B² x y ∨ A² x y {-# ATP prove ∨-comm² #-} postulate ∧∨-dist : A ∧ (B ∨ C) ↔ A ∧ B ∨ A ∧ C {-# ATP prove ∧∨-dist #-} postulate ∧∨-dist³ : ∀ {x y z} → (A³ x y z ∧ (B³ x y z ∨ C³ x y z)) ↔ (A³ x y z ∧ B³ x y z ∨ A³ x y z ∧ C³ x y z) {-# ATP prove ∧∨-dist³ #-} module Schemas where postulate id : {A : Set} → A → A {-# ATP prove id #-} postulate id¹ : {A¹ : D → Set} → ∀ {x} → A¹ x → A¹ x {-# ATP prove id¹ #-} postulate id² : {A² : D → D → Set} → ∀ {x y} → A² x y → A² x y {-# ATP prove id² #-} postulate ∨-comm : {A B : Set} → A ∨ B → A ∨ B {-# ATP prove ∨-comm #-} postulate ∨-comm² : {A² B² : D → D → Set} → ∀ {x y} → A² x y ∨ B² x y → B² x y ∨ A² x y {-# ATP prove ∨-comm² #-} postulate ∧∨-dist : {A B C : Set} → A ∧ (B ∨ C) ↔ A ∧ B ∨ A ∧ C {-# ATP prove ∧∨-dist #-} postulate ∧∨-dist³ : {A³ B³ C³ : D → D → D → Set} → ∀ {x y z} → (A³ x y z ∧ (B³ x y z ∨ C³ x y z)) ↔ (A³ x y z ∧ B³ x y z ∨ A³ x y z ∧ C³ x y z) {-# ATP prove ∧∨-dist³ #-} module SchemaInstances where -- A schema -- Current translation: ∀ p q x. app(p,x) → app(q,x). postulate schema : (A B : D → Set) → ∀ {x} → A x → B x -- Using the current translation, the ATPs can prove an instance of -- the schema. postulate d : D A B : D → Set instanceC : A d → B d {-# ATP prove instanceC schema #-}
{ "alphanum_fraction": 0.4214703425, "avg_line_length": 27.5172413793, "ext": "agda", "hexsha": "64876c272ba7b06b6b11e7936dac9939f2bb6bd1", "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/FOL/SchemataATP.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/FOL/SchemataATP.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOL/SchemataATP.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": 848, "size": 2394 }
-------------------------------------------------------------------------------- -- This is part of Agda Inference Systems {-# OPTIONS --guardedness #-} open import Agda.Builtin.Equality open import Data.Product open import Level open import Relation.Unary using (_⊆_) module is-lib.InfSys.Coinduction {𝓁} where private variable U : Set 𝓁 open import is-lib.InfSys.Base {𝓁} open import is-lib.InfSys.Induction {𝓁} open MetaRule open IS {- Coinductive interpretation -} record CoInd⟦_⟧ {𝓁c 𝓁p 𝓁n : Level} (is : IS {𝓁c} {𝓁p} {𝓁n} U) (u : U) : Set (𝓁 ⊔ 𝓁c ⊔ 𝓁p ⊔ 𝓁n) where coinductive constructor cofold_ field unfold : ISF[ is ] CoInd⟦ is ⟧ u {- Coinduction Principle -} coind[_] : ∀{𝓁c 𝓁p 𝓁n 𝓁'} → (is : IS {𝓁c} {𝓁p} {𝓁n} U) → (S : U → Set 𝓁') → (S ⊆ ISF[ is ] S) -- S is consistent → S ⊆ CoInd⟦ is ⟧ CoInd⟦_⟧.unfold (coind[ is ] S cn Su) with cn Su ... | rn , c , refl , pr = rn , c , refl , λ i → coind[ is ] S cn (pr i) {- Apply Rule -} apply-coind : ∀{𝓁c 𝓁p 𝓁n}{is : IS {𝓁c} {𝓁p} {𝓁n} U} → (rn : is .Names) → RClosed (is .rules rn) CoInd⟦ is ⟧ apply-coind {is = is} rn = prefix⇒closed (is .rules rn) {P = CoInd⟦ _ ⟧} λ{(c , refl , pr) → cofold (rn , c , refl , pr)} {- Postfix - Prefix -} coind-postfix : ∀{𝓁c 𝓁p 𝓁n}{is : IS {𝓁c} {𝓁p} {𝓁n} U} → CoInd⟦ is ⟧ ⊆ ISF[ is ] CoInd⟦ is ⟧ coind-postfix x = x .CoInd⟦_⟧.unfold coind-prefix : ∀{𝓁c 𝓁p 𝓁n}{is : IS {𝓁c} {𝓁p} {𝓁n} U} → ISF[ is ] CoInd⟦ is ⟧ ⊆ CoInd⟦ is ⟧ coind-prefix x = cofold x
{ "alphanum_fraction": 0.5364281109, "avg_line_length": 30.4117647059, "ext": "agda", "hexsha": "714e91a63f45bef9ec4e29b80e4b557768267314", "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": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "boystrange/FairSubtypingAgda", "max_forks_repo_path": "src/is-lib/InfSys/Coinduction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "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": "boystrange/FairSubtypingAgda", "max_issues_repo_path": "src/is-lib/InfSys/Coinduction.agda", "max_line_length": 123, "max_stars_count": 4, "max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "boystrange/FairSubtypingAgda", "max_stars_repo_path": "src/is-lib/InfSys/Coinduction.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z", "max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z", "num_tokens": 688, "size": 1551 }
{-# OPTIONS --without-K #-} import Level as L open L using (Lift; lift) open import Type hiding (★) open import Function.NP open import Algebra open import Algebra.FunctionProperties.NP open import Data.Nat.NP hiding (_^_) open import Data.Nat.Properties open import Data.One hiding (_≤_) open import Data.Sum open import Data.Maybe.NP open import Data.Product open import Data.Bits open import Data.Bool.NP as Bool open import Data.Fin using (Fin) open import Function.NP open import Function.Equality using (_⟨$⟩_) import Function.Inverse.NP as FI open FI using (_↔_; inverses; module Inverse) renaming (_$₁_ to to; _$₂_ to from) import Function.Related as FR open import Function.Related.TypeIsomorphisms.NP open import Relation.Binary.NP import Relation.Binary.PropositionalEquality.NP as ≡ open ≡ using (_≡_; _≗_) open import Search.Type open import Search.Searchable renaming (Searchable to Searchable) open import Search.Searchable.Product open import Search.Searchable.Sum open import Search.Searchable.Maybe --open import Search.Searchable.Fin open import Search.Derived module sum where _≈Sum_ : ∀ {A} → (sum₀ sum₁ : Sum A) → ★ _ sum₀ ≈Sum sum₁ = ∀ f → sum₀ f ≡ sum₁ f _≈Search_ : ∀ {A} → (s₀ s₁ : Search _ A) → ★₁ s₀ ≈Search s₁ = ∀ {B} (op : Op₂ B) f → s₀ op f ≡ s₁ op f _⊎'_ : ★₀ → ★₀ → ★₀ A ⊎' B = Σ Bool (cond A B) _μ⊎'_ : ∀ {A B} → Searchable A → Searchable B → Searchable (A ⊎' B) μA μ⊎' μB = μΣ μBit (λ { {true} → μA ; {false} → μB }) open import Data.Fin using (Fin; zero; suc) open import Data.Vec.NP as Vec using (Vec; tabulate; _++_) renaming (map to vmap; sum to vsum; foldr to vfoldr; foldr₁ to vfoldr₁) vmsum : ∀ {c ℓ} (m : Monoid c ℓ) {n} → let open Mon m in Vec C n → C vmsum m = vfoldr _ _∙_ ε where open Mon m vsgsum : ∀ {c ℓ} (sg : Semigroup c ℓ) {n} → let open Sgrp sg in Vec C (suc n) → C vsgsum sg = vfoldr₁ _∙_ where open Sgrp sg -- let's recall that: tabulate f ≗ vmap f (allFin n) -- searchMonFin : ∀ n → SearchMon (Fin n) -- searchMonFin n m f = vmsum m (tabulate f) searchFinSuc : ∀ {m} n → Search m (Fin (suc n)) searchFinSuc n _∙_ f = vfoldr₁ _∙_ (tabulate f) searchVec : ∀ {m A} n → Search m A → Search m (Vec A n) searchVec zero searchᴬ op f = f [] searchVec (suc n) searchᴬ op f = searchᴬ op (λ x → searchVec n searchᴬ op (f ∘ _∷_ x)) searchVec-spec : ∀ {A} (μA : Searchable A) n → searchVec n (search μA) ≈Search search (μVec μA n) searchVec-spec μA zero op f = ≡.refl searchVec-spec μA (suc n) op f = search-ext μA op (λ x → searchVec-spec μA n op (f ∘ _∷_ x)) searchVec-++ : ∀ {A} n {m} (μA : Searchable A) sg → let open Sgrp sg in (f : Vec A (n + m) → C) → search (μVec μA (n + m)) _∙_ f ≈ search (μVec μA n) _∙_ (λ xs → search (μVec μA m) _∙_ (λ ys → f (xs ++ ys))) searchVec-++ zero μA sg f = Sgrp.refl sg searchVec-++ (suc n) μA sg f = search-sg-ext μA sg (λ x → searchVec-++ n μA sg (f ∘ _∷_ x)) sumVec-swap : ∀ {A} n {m} (μA : Searchable A)(f : Vec A (n + m) → ℕ) → sum (μVec μA n) (λ xs → sum (μVec μA m) (λ ys → f (xs ++ ys))) ≡ sum (μVec μA m) (λ ys → sum (μVec μA n) (λ xs → f (xs ++ ys))) sumVec-swap n {m} μA f = sum-swap (μVec μA n) (μVec μA m) (λ xs ys → f (xs ++ ys)) simple : ∀ {A : Set}{P : A → A → Set} → (∀ x → P x x) → {x y : A} → x ≡ y → P x y simple r ≡.refl = r _ -- -} -- -} -- -}
{ "alphanum_fraction": 0.6048850575, "avg_line_length": 34.8, "ext": "agda", "hexsha": "956e9d03c4207d46d06ed8d6d38a6ca03b103c0e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "crypto-agda/explore", "max_forks_repo_path": "lib/Explore/Old/Sum/sum.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "crypto-agda/explore", "max_issues_repo_path": "lib/Explore/Old/Sum/sum.agda", "max_line_length": 130, "max_stars_count": 2, "max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "crypto-agda/explore", "max_stars_repo_path": "lib/Explore/Old/Sum/sum.agda", "max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z", "num_tokens": 1282, "size": 3480 }
open import Coinduction hiding (unfold) renaming (♯_ to Thunk; ♭ to Force) module Brainfuck where ---------- A very basic Prelude ---------- record Pair (a b : Set) : Set where constructor _,_ field fst : a snd : b data Maybe (a : Set) : Set where Nothing : Maybe a Just : (x : a) -> Maybe a return : {a : Set} -> a -> Maybe a return x = Just x data Nat : Set where Zero : Nat Succ : Nat -> Nat {-# BUILTIN NATURAL Nat #-} data Bool : Set where True : Bool False : Bool if_then_else : {a : Set} -> Bool -> a -> a -> a if True then t else f = t if False then t else f = f data List (a : Set) : Set where Nil : List a Cons : a -> List a -> List a ---------- Bits and Bytes ---------- data Bit : Set where O : Bit I : Bit data Vec (a : Set) : Nat -> Set where Nil : Vec a 0 Cons : {n : Nat} -> (x : a) -> (xs : Vec a n) -> Vec a (Succ n) Byte : Set Byte = Vec Bit 8 incr : {n : Nat} -> Vec Bit n -> Vec Bit n incr Nil = Nil incr (Cons O xs) = Cons I xs incr (Cons I xs) = Cons O (incr xs) decr : {n : Nat} -> Vec Bit n -> Vec Bit n decr Nil = Nil decr (Cons O xs) = Cons I (decr xs) decr (Cons I xs) = Cons O xs isZero : {n : Nat} -> Vec Bit n -> Bool isZero Nil = True isZero (Cons O xs) = isZero xs isZero (Cons I xs) = False zero : {n : Nat} -> Vec Bit n zero {Zero} = Nil zero {Succ k} = Cons O zero ---------- The state of the machine ---------- data Stream (a : Set) : Set where Cons : a -> ∞ (Stream a) -> Stream a zeros : Stream Byte zeros = Cons zero (Thunk zeros) record State : Set where constructor _,_,_,_,_ field left : Stream Byte current : Byte right : Stream Byte stdin : Stream Byte stdout : List Byte init : Stream Byte -> State init stdin = zeros , zero , zeros , stdin , Nil stepLeft : State -> State stepLeft (Cons left lefts , current , right , stdin , stdout) = (Force lefts) , left , (Cons current (Thunk right)) , stdin , stdout stepRight : State -> State stepRight (left , current , Cons right rights , stdin , stdout) = Cons current (Thunk left) , right , Force rights , stdin , stdout output : State -> State output (left , current , right , stdin , stdout) = left , current , right , stdin , (Cons current stdout) input : State -> State input (left , current , right , Cons b stdin , stdout) = left , b , right , Force stdin , stdout increment : State -> State increment (left , current , right , stdin , stdout) = left , (incr current) , right , stdin , stdout decrement : State -> State decrement (left , current , right , stdin , stdout) = left , (decr current) , right , stdin , stdout ---------- The Brainfuck language ---------- data Command : Set where >_ : (c : Command) -> Command <_ : (c : Command) -> Command +_ : (c : Command) -> Command -_ : (c : Command) -> Command ·_ : (c : Command) -> Command ,_ : (c : Command) -> Command [_]_ : (body : Command) -> (c : Command) -> Command □ : Command infix 25 [_]_ -- sequence c1 c2 computes a new command equivalent to c1 followed by c2 sequence : Command -> Command -> Command sequence (> c) c' = > (sequence c c') sequence (< c) c' = < (sequence c c') sequence (+ c) c' = + (sequence c c') sequence (- c) c' = - (sequence c c') sequence (· c) c' = · (sequence c c') sequence (, c) c' = , (sequence c c') sequence ([ body ] c) c' = [ body ] (sequence c c') sequence □ c' = c' step : Pair Command State -> Maybe (Pair Command State) step ((> cmd) , s) = return (cmd , stepRight s) step ((< cmd) , s) = return (cmd , stepLeft s) step ((+ cmd) , s) = return (cmd , increment s) step ((- cmd) , s) = return (cmd , decrement s) step ((· cmd) , s) = return (cmd , output s) step ((, cmd) , s) = return (cmd , input s) step ([ body ] cmd , s) = if isZero (State.current s) then return (cmd , s) else (return ((sequence body ([ body ] cmd)) , s)) step (□ , s) = Nothing data Trace : Set where Step : State -> ∞ Trace -> Trace Stop : State -> Trace run : Pair Command State -> Trace run (cmd , s) with step (cmd , s) run (cmd , s) | Nothing = Stop s run (cmd , s) | Just x = Step s (Thunk (run x)) interpret : Command -> (stdin : Stream Byte) -> Trace interpret c stdin = run (c , init stdin)
{ "alphanum_fraction": 0.5850340136, "avg_line_length": 25.993902439, "ext": "agda", "hexsha": "e7ea6f8a3cd8632ba2e60e9bace4e6ea878d6d22", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2021-11-05T17:14:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-22T21:07:11.000Z", "max_forks_repo_head_hexsha": "66702edbf12366c35c04e201a381be555616deec", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "wouter-swierstra/Brainfuck", "max_forks_repo_path": "Brainfuck.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "66702edbf12366c35c04e201a381be555616deec", "max_issues_repo_issues_event_max_datetime": "2021-08-09T12:49:13.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-18T17:57:28.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "wouter-swierstra/Brainfuck", "max_issues_repo_path": "Brainfuck.agda", "max_line_length": 76, "max_stars_count": 32, "max_stars_repo_head_hexsha": "66702edbf12366c35c04e201a381be555616deec", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "wouter-swierstra/Brainfuck", "max_stars_repo_path": "Brainfuck.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-28T17:11:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-04T22:21:32.000Z", "num_tokens": 1317, "size": 4263 }
------------------------------------------------------------------------ -- Various equality checkers (some complete, all sound) ------------------------------------------------------------------------ import Axiom.Extensionality.Propositional as E import Level open import Data.Universe -- The code makes use of the assumption that propositional equality of -- functions is extensional. module README.DependentlyTyped.Equality-checker (Uni₀ : Universe Level.zero Level.zero) (ext : E.Extensionality Level.zero Level.zero) where open import Category.Monad open import Data.Maybe import Data.Maybe.Categorical as Maybe open import Data.Product open import Function hiding (_∋_) renaming (const to k) import README.DependentlyTyped.NBE as NBE; open NBE Uni₀ ext import README.DependentlyTyped.NormalForm as NF; open NF Uni₀ import README.DependentlyTyped.Term as Term; open Term Uni₀ open import Relation.Binary.PropositionalEquality as P using (_≡_) open import Relation.Nullary as Dec using (Dec; yes) import Relation.Nullary.Decidable as Dec open import Relation.Nullary.Product open P.≡-Reasoning open RawMonadZero (Maybe.monadZero {f = Level.zero}) -- Decides if two "atomic type proofs" are equal. infix 4 _≟-atomic-type_ _≟-atomic-type_ : ∀ {Γ σ} (σ′₁ σ′₂ : Γ ⊢ σ atomic-type) → Dec (σ′₁ ≡ σ′₂) ⋆ ≟-atomic-type ⋆ = yes P.refl el ≟-atomic-type el = yes P.refl mutual private -- A helper lemma. helper-lemma : ∀ {Γ₁ sp₁₁ sp₂₁ σ₁} (t₁₁ : Γ₁ ⊢ π sp₁₁ sp₂₁ , σ₁ ⟨ ne ⟩) (t₂₁ : Γ₁ ⊢ fst σ₁ ⟨ no ⟩) {Γ₂ sp₁₂ sp₂₂ σ₂} (t₁₂ : Γ₂ ⊢ π sp₁₂ sp₂₂ , σ₂ ⟨ ne ⟩) (t₂₂ : Γ₂ ⊢ fst σ₂ ⟨ no ⟩) → t₁₁ · t₂₁ ≅-⊢n t₁₂ · t₂₂ → t₁₁ ≅-⊢n t₁₂ × t₂₁ ≅-⊢n t₂₂ helper-lemma _ _ ._ ._ P.refl = P.refl , P.refl -- Decides if two neutral terms are identical. Note that the terms -- must have the same context, but they do not need to have the same -- type. infix 4 _≟-⊢ne_ _≟-⊢ne_ : ∀ {Γ σ₁} (t₁ : Γ ⊢ σ₁ ⟨ ne ⟩) {σ₂} (t₂ : Γ ⊢ σ₂ ⟨ ne ⟩) → Dec (t₁ ≅-⊢n t₂) var x₁ ≟-⊢ne var x₂ = Dec.map′ var-n-cong helper (x₁ ≟-∋ x₂) where helper : ∀ {Γ₁ σ₁} {x₁ : Γ₁ ∋ σ₁} {Γ₂ σ₂} {x₂ : Γ₂ ∋ σ₂} → var x₁ ≅-⊢n var x₂ → x₁ ≅-∋ x₂ helper P.refl = P.refl t₁₁ · t₂₁ ≟-⊢ne t₁₂ · t₂₂ with t₁₁ ≟-⊢ne t₁₂ ... | Dec.no neq = Dec.no (neq ∘ proj₁ ∘ helper-lemma _ t₂₁ _ t₂₂) ... | yes eq = Dec.map′ (·n-cong eq) (proj₂ ∘ helper-lemma t₁₁ _ t₁₂ _) (t₂₁ ≟-⊢no t₂₂ [ fst-cong $ indexed-type-cong $ helper eq ]) where helper : ∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ σ₁ ⟨ ne ⟩} {Γ₂ σ₂} {t₂ : Γ₂ ⊢ σ₂ ⟨ ne ⟩} → t₁ ≅-⊢n t₂ → σ₁ ≅-Type σ₂ helper P.refl = P.refl var _ ≟-⊢ne _ · _ = Dec.no λ () _ · _ ≟-⊢ne var _ = Dec.no λ () -- Decides if two normal forms are identical. Note that the terms -- must have the same type. infix 4 _≟-⊢no_[_] _≟-⊢no_[_] : ∀ {Γ₁ σ₁} (t₁ : Γ₁ ⊢ σ₁ ⟨ no ⟩) {Γ₂ σ₂} (t₂ : Γ₂ ⊢ σ₂ ⟨ no ⟩) → σ₁ ≅-Type σ₂ → Dec (t₁ ≅-⊢n t₂) ne σ′₁ t₁ ≟-⊢no ne σ′₂ t₂ [ P.refl ] = ne≟ne σ′₁ σ′₂ (t₁ ≟-⊢ne t₂) where ne≟ne : ∀ {Γ σ} {t₁ t₂ : Γ ⊢ σ ⟨ ne ⟩} (σ′₁ : Γ ⊢ σ atomic-type) (σ′₂ : Γ ⊢ σ atomic-type) → Dec (t₁ ≅-⊢n t₂) → Dec (ne σ′₁ t₁ ≅-⊢n ne σ′₂ t₂) ne≟ne ⋆ ⋆ (yes P.refl) = yes P.refl ne≟ne el el (yes P.refl) = yes P.refl ne≟ne _ _ (Dec.no neq) = Dec.no (neq ∘ helper) where helper : ∀ {Γ₁ σ₁ σ′₁} {t₁ : Γ₁ ⊢ σ₁ ⟨ ne ⟩} {Γ₂ σ₂ σ′₂} {t₂ : Γ₂ ⊢ σ₂ ⟨ ne ⟩} → ne σ′₁ t₁ ≅-⊢n ne σ′₂ t₂ → t₁ ≅-⊢n t₂ helper P.refl = P.refl ƛ t₁ ≟-⊢no ƛ t₂ [ eq ] = Dec.map′ ƛn-cong helper (t₁ ≟-⊢no t₂ [ snd-cong $ indexed-type-cong eq ]) where helper : ∀ {Γ₁ σ₁ τ₁} {t₁ : Γ₁ ▻ σ₁ ⊢ τ₁ ⟨ no ⟩} {Γ₂ σ₂ τ₂} {t₂ : Γ₂ ▻ σ₂ ⊢ τ₂ ⟨ no ⟩} → ƛ t₁ ≅-⊢n ƛ t₂ → t₁ ≅-⊢n t₂ helper P.refl = P.refl ne _ _ ≟-⊢no ƛ _ [ _ ] = Dec.no λ () ƛ _ ≟-⊢no ne _ _ [ _ ] = Dec.no λ () -- Tries to prove that two terms have the same semantics. The terms -- must have the same type. ⟦_⟧≟⟦_⟧ : ∀ {Γ σ} (t₁ t₂ : Γ ⊢ σ) → Maybe (⟦ t₁ ⟧ ≅-Value ⟦ t₂ ⟧) ⟦ t₁ ⟧≟⟦ t₂ ⟧ with normalise t₁ ≟-⊢no normalise t₂ [ P.refl ] ... | Dec.no _ = ∅ ... | yes eq = return (begin [ ⟦ t₁ ⟧ ] ≡⟨ normalise-lemma t₁ ⟩ [ ⟦ normalise t₁ ⟧n ] ≡⟨ ⟦⟧n-cong eq ⟩ [ ⟦ normalise t₂ ⟧n ] ≡⟨ P.sym $ normalise-lemma t₂ ⟩ [ ⟦ t₂ ⟧ ] ∎) -- Tries to prove that two semantic types are equal, given -- corresponding syntactic types. The types must have the same -- context. infix 4 _≟-Type_ _≟-Type_ : ∀ {Γ σ₁} (σ₁′ : Γ ⊢ σ₁ type) {σ₂} (σ₂′ : Γ ⊢ σ₂ type) → Maybe (σ₁ ≅-Type σ₂) ⋆ ≟-Type ⋆ = return P.refl el t₁ ≟-Type el t₂ = helper <$> ⟦ t₁ ⟧≟⟦ t₂ ⟧ where helper : ∀ {Γ₁} {v₁ : Value Γ₁ (⋆ , _)} {Γ₂} {v₂ : Value Γ₂ (⋆ , _)} → v₁ ≅-Value v₂ → (el , v₁) ≅-Type (el , v₂) helper P.refl = P.refl π σ′₁ τ′₁ ≟-Type π σ′₂ τ′₂ = helper τ′₁ τ′₂ =<< σ′₁ ≟-Type σ′₂ where helper : ∀ {Γ₁ σ₁ τ₁} (τ′₁ : Γ₁ ▻ σ₁ ⊢ τ₁ type) {Γ₂ σ₂ τ₂} (τ′₂ : Γ₂ ▻ σ₂ ⊢ τ₂ type) → σ₁ ≅-Type σ₂ → Maybe (Type-π σ₁ τ₁ ≅-Type Type-π σ₂ τ₂) helper τ′₁ τ′₂ P.refl = Type-π-cong <$> (τ′₁ ≟-Type τ′₂) _ ≟-Type _ = ∅
{ "alphanum_fraction": 0.527761986, "avg_line_length": 32.5740740741, "ext": "agda", "hexsha": "864a6b8c4b1ffafc1000c761f48355b49ef2a9e4", "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": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/dependently-typed-syntax", "max_forks_repo_path": "README/DependentlyTyped/Equality-checker.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/dependently-typed-syntax", "max_issues_repo_path": "README/DependentlyTyped/Equality-checker.agda", "max_line_length": 73, "max_stars_count": 5, "max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/dependently-typed-syntax", "max_stars_repo_path": "README/DependentlyTyped/Equality-checker.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z", "num_tokens": 2315, "size": 5277 }
{-# OPTIONS --cubical --no-import-sorts #-} module SetQuotientTest where open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc) open import Cubical.Foundations.Logic renaming (inl to inlᵖ; inr to inrᵖ) open import Cubical.Data.Empty renaming (elim to ⊥-elim; ⊥ to ⊥⊥) open import Cubical.Relation.Nullary.Base renaming (¬_ to ¬ᵗ_) open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_) open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_) open import Cubical.Data.NatPlusOne using (HasFromNat; 1+_; ℕ₊₁; ℕ₊₁→ℕ) open import Cubical.HITs.Ints.QuoInt using (HasFromNat; signed) renaming ( abs to absᶻ ; pos to pos ; neg to neg ) open import Cubical.HITs.Ints.QuoInt hiding (_+_; -_; +-assoc; +-comm) open import Cubical.HITs.Rationals.QuoQ using ( ℚ ; onCommonDenom ; onCommonDenomSym ; eq/ ; _//_ ; _∼_ ; isSetℚ ) renaming ( [_] to [_]ᶠ ; ℕ₊₁→ℤ to [1+_ⁿ]ᶻ ) open import Cubical.HITs.SetQuotients as SetQuotient using () renaming (_/_ to _//_) postulate _<ᶻ_ : ℤ → ℤ → hProp ℓ-zero _<'_ : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → hProp ℓ-zero (aᶻ , aⁿ) <' (bᶻ , bⁿ) = let aⁿᶻ = [1+ aⁿ ⁿ]ᶻ bⁿᶻ = [1+ bⁿ ⁿ]ᶻ in (aᶻ * bⁿᶻ) <ᶻ (bᶻ * aⁿᶻ) postulate <'-respects-∼ˡ : ∀ a b x → a ∼ b → a <' x ≡ b <' x <'-respects-∼ʳ : ∀ x a b → a ∼ b → x <' a ≡ x <' b _<_ : ℚ → ℚ → hProp ℓ-zero a < b = SetQuotient.rec2 {R = _∼_} {B = hProp ℓ-zero} isSetHProp _<'_ <'-respects-∼ˡ <'-respects-∼ʳ a b isProp⊎ˡ : ∀{ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → isProp A → isProp B → (A → ¬ᵗ B) → isProp (A ⊎ B) isProp⊎ˡ pA pB A⇒¬B (inl x) (inl y) = cong inl (pA x y) isProp⊎ˡ pA pB A⇒¬B (inr x) (inr y) = cong inr (pB x y) isProp⊎ˡ pA pB A⇒¬B (inl x) (inr y) = ⊥-elim (A⇒¬B x y) isProp⊎ˡ pA pB A⇒¬B (inr x) (inl y) = ⊥-elim (A⇒¬B y x) ⊎ᵖ-syntax : ∀{ℓ ℓ'} (P : hProp ℓ) (Q : hProp ℓ') → {[ P ] → [ ¬ Q ]} → hProp _ ⊎ᵖ-syntax P Q {P⇒¬Q} = ([ P ] ⊎ [ Q ]) , isProp⊎ˡ (isProp[] P) (isProp[] Q) P⇒¬Q syntax ⊎ᵖ-syntax P Q {P⇒¬Q} = [ P⇒¬Q ] P ⊎ᵖ Q postulate <-asym : ∀ x y → [ x < y ] → [ ¬(y < x) ] _#_ : ℚ → ℚ → hProp ℓ-zero x # y = [ <-asym x y ] (x < y) ⊎ᵖ (y < x) _⁻¹''' : (x : ℚ) → [ x # 0 ] → ℚ _⁻¹''' = SetQuotient.elim {R = _∼_} {B = λ x → [ x # 0 ] → ℚ} φ _⁻¹'' ⁻¹''-respects-∼ where φ : ∀ x → isSet ([ x # 0 ] → ℚ) φ x = isSetΠ (λ _ → isSetℚ) _⁻¹'' : (a : ℤ × ℕ₊₁) → [ [ a ]ᶠ # 0 ] → ℚ x ⁻¹'' = {!!} ⁻¹''-respects-∼ : (a b : ℤ × ℕ₊₁) (r : a ∼ b) → PathP (λ i → [ eq/ a b r i # 0 ] → ℚ) (a ⁻¹'') (b ⁻¹'') ⁻¹''-respects-∼ a b r = {!!}
{ "alphanum_fraction": 0.537887711, "avg_line_length": 33.96, "ext": "agda", "hexsha": "219e51b894ccb1f1ff1f536302a42d526f729935", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mchristianl/synthetic-reals", "max_forks_repo_path": "test/SetQuotientTest.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mchristianl/synthetic-reals", "max_issues_repo_path": "test/SetQuotientTest.agda", "max_line_length": 103, "max_stars_count": 3, "max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mchristianl/synthetic-reals", "max_stars_repo_path": "test/SetQuotientTest.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z", "num_tokens": 1326, "size": 2547 }
open import Agda.Builtin.List open import Agda.Builtin.Reflection open import Agda.Builtin.Unit open import Agda.Builtin.Nat -- setup infixl 5 _>>=_ _>>=_ = bindTC defToTerm : Name → Definition → List (Arg Term) → Term defToTerm _ (function cs) as = pat-lam cs as defToTerm _ (data-cons d) as = con d as defToTerm _ _ _ = unknown data Tm : Set where tm : Term → Tm macro unfold : Name → Term → TC ⊤ unfold x a = getDefinition x >>= λ d → unify a (defToTerm x d []) data Vec (A : Set) : Nat → Set where [] : Vec A zero _∷_ : ∀ {n} → A → Vec A n → Vec A (suc n) Point = Vec Nat 3 renderBuffer : List Point → List Nat renderBuffer [] = [] renderBuffer ((x ∷ y ∷ z ∷ []) ∷ xs) = x ∷ y ∷ z ∷ renderBuffer xs renderBuffer' : List Point → List Nat renderBuffer' = unfold renderBuffer ps : List Point ps = (1 ∷ 2 ∷ 3 ∷ []) ∷ (4 ∷ 5 ∷ 6 ∷ []) ∷ [] open import Agda.Builtin.Equality check : renderBuffer' ps ≡ 1 ∷ 2 ∷ 3 ∷ 4 ∷ 5 ∷ 6 ∷ [] check = refl
{ "alphanum_fraction": 0.6230529595, "avg_line_length": 21.8863636364, "ext": "agda", "hexsha": "6a8317b8d0c94f65cc8ce11e00bba9af9bac2b38", "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/Issue2203.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/Issue2203.agda", "max_line_length": 67, "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/Issue2203.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": 356, "size": 963 }
-------------------------------------------------------------------------------- -- This file contains the definition of a context-free grammar, as well as a -- parser for those grammars that are actually of LL1 type. There is currently -- no check if the grammar is actually a LL1 grammar, so the parser might loop -- indefinitely or return an error message in certain cases, even if the string -- actually matches the grammar. -------------------------------------------------------------------------------- {-# OPTIONS --type-in-type #-} module Parse.LL1 where import Data.String as S open import Data.Sum using (isInj₁) open import Class.Monad.Except open import Data.String using (fromList; toList; uncons) open import Data.List using (boolDropWhile) open import Data.Tree open import Prelude record CFG (V : Set) (MultiChar : Set) : Set₁ where field S : V R : V → Set AllRules : (v : V) → List (R v) -- whether to keep track of the result V' : Set V' = V × Bool field Rstring'' : {v : V} → R v → List (V' ⊎ MultiChar ⊎ String) Terminal : Set Terminal = MultiChar ⊎ String isMultiChar : Terminal → Bool isMultiChar (inj₁ _) = true isMultiChar (inj₂ _) = false terminalLength : Terminal → ℕ terminalLength (inj₁ x) = 1 terminalLength (inj₂ y) = S.length y Rule : Set Rule = ∃[ v ] R v Rstring : {v : V} → R v → List (V ⊎ MultiChar ⊎ String) Rstring r = map (Data.Sum.map₁ proj₁) (Rstring'' r) Rstring' : Rule → List (V ⊎ Terminal) Rstring' (_ , r) = Rstring r SynTree : Set SynTree = Tree (Rule ⊎ Char) private variable v : V produces-ε : R v → Bool produces-ε = null ∘ Rstring module _ {V MultiChar : Set} (showV : V → String) (matchMulti : MultiChar → Char → Bool) (showMulti : MultiChar → String) (G : CFG V MultiChar) (M : Set → Set) {{_ : Monad M}} {{_ : MonadExcept M String}} where -- we don't care if it is actually a LL1 grammar private variable v : V open CFG G showTerminal : Terminal → String showTerminal (inj₁ x) = showMulti x showTerminal (inj₂ y) = y match : String → Terminal → Bool match s (inj₁ x) with strHead s ... | nothing = false ... | just c = matchMulti x c match s (inj₂ y) = strTake (S.length y) s ≣ y -- select the first rule satisfying the predicate firstRule : (v : V) → (R v → Bool) → Maybe (R v) firstRule v P = head $ boolDropWhile (not ∘ P) $ AllRules v {-# NON_TERMINATING #-} parsingTable : V → String → Maybe Rule parsingTable v' x = -,_ <$> firstRule v' (startWith x) <∣> firstRule v' produces-ε -- select the first rule starting with x, or the first that is empty where startWith : String → R v → Bool startWith x = helper x ∘ Rstring where helper : String → List (V ⊎ Terminal) → Bool helper x [] = false helper x (inj₁ v ∷ rest) with boolFilter (startWith x) (AllRules v) ... | [] = if null $ boolFilter produces-ε (AllRules v) then false else helper x rest ... | _ = true helper x (inj₂ t ∷ _) = match x t {-# NON_TERMINATING #-} parseWithInitNT : V → String → M (SynTree × String) parseWithInitNT v a = do (y , rest) ← helper [ inj₁ v ] a maybe (λ z → return (z , rest)) (throwError "BUG: Error while creating syntax tree.") (resToTree y) where helper : List (V ⊎ Terminal) → String → M (List (Rule ⊎ Char) × String) helper [] s = return ([] , s) helper (inj₁ x ∷ stack) s with parsingTable x s ... | just r = map₁ (inj₁ r ∷_) <$> helper (Rstring' r ++ stack) s ... | nothing = throwError $ "No applicable rule found for non-terminal " + showV x + "\nRemaining:\n" + s helper (inj₂ y ∷ stack) s with uncons s | match s y ... | just (x , _) | true = let prepend = if isMultiChar y then inj₂ x ∷_ else id in map₁ prepend <$> helper stack (strDrop (terminalLength y) s) ... | just _ | false = throwError $ "Mismatch while parsing characters: tried to parse " + showTerminal y + " but got '" + s + "'" ... | nothing | _ = throwError ("Unexpected end of input while trying to parse " + showTerminal y) resToTree : List (Rule ⊎ Char) → Maybe SynTree resToTree x = proj₁ <$> resToTree' x where needsChild : V' ⊎ Terminal → Bool needsChild (inj₁ x) = true needsChild (inj₂ (inj₁ x)) = true needsChild (inj₂ (inj₂ y)) = false attachChild : V' ⊎ Terminal → Bool attachChild (inj₁ (_ , b)) = b attachChild _ = true resToTree' : List (Rule ⊎ Char) → Maybe (SynTree × List (Rule ⊎ Char)) ruleChildren : List (V' ⊎ Terminal) → List (Rule ⊎ Char) → Maybe (List SynTree × List (Rule ⊎ Char)) resToTree' [] = nothing resToTree' (inj₁ l ∷ l₁) with ruleChildren (Rstring'' (proj₂ l)) l₁ ... | just (fst , snd) = just (Node (inj₁ l) fst , snd) ... | nothing = nothing resToTree' (inj₂ l ∷ l₁) = just (Node (inj₂ l) [] , l₁) ruleChildren [] l = just ([] , l) ruleChildren (x ∷ s) l with needsChild x | resToTree' l ... | false | _ = ruleChildren s l ... | true | just (t , rest) = (if attachChild x then map₁ (t ∷_) else id) <$> ruleChildren s rest ... | true | nothing = nothing
{ "alphanum_fraction": 0.5713497609, "avg_line_length": 36.4966442953, "ext": "agda", "hexsha": "d58ff05892df3816bb254b3dd5d80ccb7fdf0697", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z", "max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "WhatisRT/meta-cedille", "max_forks_repo_path": "src/Parse/LL1.agda", "max_issues_count": 10, "max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c", "max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "WhatisRT/meta-cedille", "max_issues_repo_path": "src/Parse/LL1.agda", "max_line_length": 110, "max_stars_count": 35, "max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "WhatisRT/meta-cedille", "max_stars_repo_path": "src/Parse/LL1.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z", "num_tokens": 1612, "size": 5438 }
{-# OPTIONS --safe #-} module Cubical.Categories.Limits where open import Cubical.Categories.Limits.Base 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.8321167883, "avg_line_length": 34.25, "ext": "agda", "hexsha": "96e88f017ad6aa4e0b4e841bf1f95c17e5815c81", "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": "63c770b381039c0132c17d7913f4566b35984701", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mzeuner/cubical", "max_forks_repo_path": "Cubical/Categories/Limits.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "63c770b381039c0132c17d7913f4566b35984701", "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": "mzeuner/cubical", "max_issues_repo_path": "Cubical/Categories/Limits.agda", "max_line_length": 53, "max_stars_count": null, "max_stars_repo_head_hexsha": "63c770b381039c0132c17d7913f4566b35984701", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mzeuner/cubical", "max_stars_repo_path": "Cubical/Categories/Limits.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 55, "size": 274 }
------------------------------------------------------------------------ -- A terminating parser data type and the accompanying interpreter ------------------------------------------------------------------------ module RecursiveDescent.InductiveWithFix.Internal where open import Data.Bool open import Data.Product.Record open import Data.Maybe open import Data.BoundedVec.Inefficient import Data.List as L open import Data.Nat open import Category.Applicative.Indexed open import Category.Monad.Indexed open import Category.Monad.State open import RecursiveDescent.Index open import Utilities ------------------------------------------------------------------------ -- Lifting non-terminals -- Extends a non-terminal type with a fresh non-terminal. data Lift (i : Index) (r : Set) (nt : ParserType₁) : ParserType₁ where fresh : Lift i r nt i r ↟ : forall {i' r'} -> nt i' r' -> Lift i r nt i' r' ------------------------------------------------------------------------ -- Parser data type -- A type for parsers which can be implemented using recursive -- descent. The types used ensure that the implementation below is -- structurally recursive. -- The parsers are indexed on a type of nonterminals. data Parser (tok : Set) (nt : ParserType₁) : ParserType₁ where !_ : forall {e c r} -> nt (e , c) r -> Parser tok nt (e , step c) r fix : forall {e c r} -> Parser tok (Lift (e , step c) r nt) (e , c) r -> Parser tok nt (e , step c) r symbol : Parser tok nt (false , leaf) tok ret : forall {r} -> r -> Parser tok nt (true , leaf) r fail : forall {r} -> Parser tok nt (false , leaf) r bind₀ : forall {c₁ e₂ c₂ r₁ r₂} -> Parser tok nt (true , c₁) r₁ -> (r₁ -> Parser tok nt (e₂ , c₂) r₂) -> Parser tok nt (e₂ , node c₁ c₂) r₂ bind₁ : forall {c₁ r₁ r₂} {i₂ : r₁ -> Index} -> Parser tok nt (false , c₁) r₁ -> ((x : r₁) -> Parser tok nt (i₂ x) r₂) -> Parser tok nt (false , step c₁) r₂ alt₀ : forall {c₁ e₂ c₂ r} -> Parser tok nt (true , c₁) r -> Parser tok nt (e₂ , c₂) r -> Parser tok nt (true , node c₁ c₂) r alt₁ : forall {c₁} e₂ {c₂ r} -> Parser tok nt (false , c₁) r -> Parser tok nt (e₂ , c₂) r -> Parser tok nt (e₂ , node c₁ c₂) r ------------------------------------------------------------------------ -- Lifting parsers Map : (ParserType₁ -> ParserType₁) -> Set2 Map F = forall {nt nt' i r} -> (nt i r -> nt' i r) -> (F nt i r -> F nt' i r) liftMap : forall (F : ParserType₁ -> ParserType₁) {i' r'} -> Map F -> Map (Lift i' r' ∘₂ F) liftMap F map g fresh = fresh liftMap F map g (↟ x) = ↟ (map g x) lift' : forall {tok nt i r i' r'} (F : ParserType₁ -> ParserType₁) -> Map F -> Parser tok (F nt) i r -> Parser tok (F (Lift i' r' nt)) i r lift' F map (! x) ~ ! (map ↟ x) lift' F map (fix {e} {c} {r} p) ~ fix (lift' (Lift (e , step c) r ∘₂ F) (liftMap F map) p) lift' F map symbol ~ symbol lift' F map (ret x) ~ ret x lift' F map fail ~ fail lift' F map (bind₀ p₁ p₂) ~ bind₀ (lift' F map p₁) (\x -> lift' F map (p₂ x)) lift' F map (bind₁ p₁ p₂) ~ bind₁ (lift' F map p₁) (\x -> lift' F map (p₂ x)) lift' F map (alt₀ p₁ p₂) ~ alt₀ (lift' F map p₁) (lift' F map p₂) lift' F map (alt₁ e p₁ p₂) ~ alt₁ e (lift' F map p₁) (lift' F map p₂) -- Note that lift p is linear in the size of p (in a sense; note that -- p can contain higher-order components), assuming that p contains at -- most <some constant> occurrences of fix. lift : forall {tok nt i r i' r'} -> Parser tok nt i r -> Parser tok (Lift i' r' nt) i r lift p = lift' (\nt -> nt) (\f -> f) p ------------------------------------------------------------------------ -- Run function for the parsers -- Grammars. Grammar : Set -> ParserType₁ -> Set1 Grammar tok nt = forall {i r} -> nt i r -> Parser tok nt i r -- Extends a grammar with a case for a fresh non-terminal. _▷_ : forall {tok nt i r} -> Grammar tok nt -> Parser tok nt i r -> Grammar tok (Lift i r nt) (g ▷ p) fresh = lift p (g ▷ p) (↟ x) = lift (g x) -- Parser monad. P : Set -> IFun ℕ P tok = IStateT (BoundedVec tok) L.List PIMonadPlus : (tok : Set) -> RawIMonadPlus (P tok) PIMonadPlus tok = StateTIMonadPlus (BoundedVec tok) L.monadPlus PIMonadState : (tok : Set) -> RawIMonadState (BoundedVec tok) (P tok) PIMonadState tok = StateTIMonadState (BoundedVec tok) L.monad private open module LM {tok} = RawIMonadPlus (PIMonadPlus tok) open module SM {tok} = RawIMonadState (PIMonadState tok) using (get; put; modify) -- For every successful parse the run function returns the remaining -- string. (Since there can be several successful parses a list of -- strings is returned.) -- This function is structurally recursive with respect to the -- following lexicographic measure: -- -- 1) The upper bound of the length of the input string. -- 2) The parser's proper left corner tree. mutual parse : forall {tok nt} -> Grammar tok nt -> forall n {e c r} -> Parser tok nt (e , c) r -> P tok n (if e then n else pred n) r parse g n (! x) = parse g n (g x) parse g n (fix p) = parse (g ▷ fix p) n p parse g zero symbol = ∅ parse g (suc n) symbol = eat =<< get parse g n (ret x) = return x parse g n fail = ∅ parse g n (bind₀ p₁ p₂) = parse g n p₁ >>= parse g n ∘′ p₂ parse g zero (bind₁ p₁ p₂) = ∅ parse g (suc n) (bind₁ p₁ p₂) = parse g (suc n) p₁ >>= parse↑ g n ∘′ p₂ parse g n (alt₀ p₁ p₂) = parse g n p₁ ∣ parse↑ g n p₂ parse g n (alt₁ true p₁ p₂) = parse↑ g n p₁ ∣ parse g n p₂ parse g n (alt₁ false p₁ p₂) = parse g n p₁ ∣ parse g n p₂ parse↑ : forall {tok nt} -> Grammar tok nt -> forall n {e c r} -> Parser tok nt (e , c) r -> P tok n n r parse↑ g n {true} p = parse g n p parse↑ g zero {false} p = ∅ parse↑ g (suc n) {false} p = parse g (suc n) p >>= \r -> modify ↑ >> return r eat : forall {tok n} -> BoundedVec tok (suc n) -> P tok (suc n) n tok eat [] = ∅ eat (c ∷ s) = put s >> return c
{ "alphanum_fraction": 0.5221780361, "avg_line_length": 38.6863905325, "ext": "agda", "hexsha": "bcebc17ed783cb280b970758fd700597b0247292", "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": "76774f54f466cfe943debf2da731074fe0c33644", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_path": "misc/RecursiveDescent/InductiveWithFix/Internal.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z", "max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_path": "misc/RecursiveDescent/InductiveWithFix/Internal.agda", "max_line_length": 84, "max_stars_count": 7, "max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yurrriq/parser-combinators", "max_stars_repo_path": "misc/RecursiveDescent/InductiveWithFix/Internal.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z", "num_tokens": 2031, "size": 6538 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} -- This module proves the two "VotesOnce" proof obligations for our fake handler open import Optics.All open import LibraBFT.Prelude open import LibraBFT.Lemmas open import LibraBFT.Base.KVMap open import LibraBFT.Base.PKCS import LibraBFT.Concrete.Properties.VotesOnce as VO open import LibraBFT.Impl.Base.Types open import LibraBFT.Impl.Consensus.Types open import LibraBFT.Impl.Consensus.RoundManager.Properties open import LibraBFT.Impl.Handle open import LibraBFT.Impl.Handle.Properties open import LibraBFT.Impl.NetworkMsg open import LibraBFT.Impl.Util.Crypto open import LibraBFT.Impl.Util.Util open import LibraBFT.Concrete.System open import LibraBFT.Concrete.System.Parameters open EpochConfig open import LibraBFT.Yasm.Types open import LibraBFT.Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms PeerCanSignForPK (λ {st} {part} {pk} → PeerCanSignForPK-stable {st} {part} {pk}) open WithSPS impl-sps-avp open Structural impl-sps-avp -- In this module, we prove the two implementation obligations for the VotesOnce rule. Note -- that it is not yet 100% clear that the obligations are the best definitions to use. See comments -- in Concrete.VotesOnce. We will want to prove these obligations for the fake/simple -- implementation (or some variant on it) and streamline the proof before we proceed to tackle more -- ambitious properties. module LibraBFT.Impl.Properties.VotesOnce where -- This is the information we can establish about the state after the first time a signature is -- sent, and that we can carry forward to subsequent states, so we can use it to prove -- VO.ImplObligation₁. LvrProp : CarrierProp LvrProp v rm = ( v ^∙ vEpoch ≢ (₋rmEC rm) ^∙ rmEpoch ⊎ (v ^∙ vEpoch ≡ (₋rmEC rm) ^∙ rmEpoch × v ^∙ vRound ≤ (₋rmEC rm) ^∙ rmLastVotedRound)) LvrCarrier = PropCarrier LvrProp firstSendEstablishes : Vote → PK → (origSt : SystemState) → SystemStateRel Step firstSendEstablishes _ _ _ (step-peer (step-cheat _)) = Lift (ℓ+1 ℓ-RoundManager) ⊥ firstSendEstablishes v' pk origSt sysStep@(step-peer {pid'} {pre = pre} pstep@(step-honest _)) = ( ReachableSystemState pre × ¬ MsgWithSig∈ pk (signature v' unit) (msgPool pre) × LvrCarrier pk (₋vSignature v') (StepPeer-post pstep) ) open PeerCanSignForPK isValidNewPart⇒fSE : ∀ {pk v'}{pre : SystemState} {post : SystemState} {theStep : Step pre post} → Meta-Honest-PK pk → (ivnp : IsValidNewPart (₋vSignature v') pk theStep) → firstSendEstablishes v' pk pre theStep isValidNewPart⇒fSE {pre = pre} {theStep = step-peer {pid = β} {outs = outs} pstep} hpk (_ , ¬init , ¬sentb4 , mws , _) with Any-++⁻ (actionsToSentMessages β outs) (msg∈pool mws) -- TODO-1 : Much of this proof is not specific to the particular property being proved, and could be -- refactored into Yasm.Properties. See proof of unwind and refactor to avoid redundancy? ...| inj₂ furtherBack = ⊥-elim (¬sentb4 (MsgWithSig∈-transp mws furtherBack)) ...| inj₁ thisStep with pstep ...| step-cheat isCheat with thisStep ...| here refl with isCheat (msg⊆ mws) (msgSigned mws) (transp-¬∈GenInfo₁ ¬init mws) ...| inj₁ dis = ⊥-elim (hpk dis) ...| inj₂ sentb4 rewrite msgSameSig mws = ⊥-elim (¬sentb4 sentb4) isValidNewPart⇒fSE {pk}{v'}{pre}{theStep = step-peer {β} {postst} {outs} {.pre} pstep} hpk (r , ¬init , ¬sentb4 , mws , refl , zefl , vpk) | inj₁ thisStep | step-honest {.β} hstep with senderMsgPair∈⇒send∈ outs thisStep ...| nm∈outs , refl with hstep ...| step-msg {_ , P m} m∈pool ini with impl-sps-avp {m = msgWhole mws} r hpk hstep nm∈outs (msg⊆ mws) (msgSigned mws) (transp-¬∈GenInfo₁ ¬init mws ) ...| inj₂ sentb4 rewrite msgSameSig mws = ⊥-elim (¬sentb4 sentb4) ...| inj₁ (vpk' , _) with noEpochIdChangeYet {ppre = peerStates pre β} r refl hstep ini ...| eids≡ with newVoteSameEpochGreaterRound r hstep (¬subst ¬init (msgSameSig mws)) hpk (msg⊆ mws) nm∈outs (msgSigned mws) (¬subst ¬sentb4 (msgSameSig mws)) ...| refl , refl , newlvr with StepPeer-post-lemma pstep ...| post≡ = r , ¬sentb4 , mkCarrier (step-s r (step-peer (step-honest hstep))) mws (override-target-≡ {a = β}) vpk' (inj₂ ( trans eids≡ (auxEid post≡) , ≤-reflexive (trans newlvr (auxLvr post≡)))) where auxEid = cong (_^∙ rmEpoch ∘ ₋rmEC) auxLvr = cong (_^∙ rmLastVotedRound ∘ ₋rmEC) ImplPreservesLvr : PeerStepPreserves LvrProp -- We don't have a real model for the initial peer state, so we can't prove this case yet. -- Eventually, we'll prove something like a peer doesn't initialize to an epoch for which -- it has already sent votes. ImplPreservesLvr r prop (step-init uni) = ⊥-elim (uninitd≢initd (trans (sym uni) (carrInitd prop))) ImplPreservesLvr {pre = pre} r prop (step-msg {m} m∈pool inited) with carrProp prop ...| preprop with noEpochIdChangeYet r refl (step-msg m∈pool inited) (carrInitd prop) ...| eids≡ with preprop ...| inj₁ diffEpoch = inj₁ λ x → diffEpoch (trans x (sym eids≡)) ...| inj₂ (sameEpoch , rnd≤ppre) with (msgPart (carrSent prop)) ^∙ vEpoch ≟ (₋rmEC (peerStates pre (msgSender (carrSent prop)))) ^∙ rmEpoch ...| no neq = ⊥-elim (neq sameEpoch) ...| yes refl with lastVoteRound-mono r refl (step-msg m∈pool inited) (carrInitd prop) ...| es≡⇒lvr≤ = inj₂ (eids≡ , ≤-trans rnd≤ppre (es≡⇒lvr≤ eids≡)) LvrCarrier-transp* : ∀ {pk sig} {start : SystemState}{final : SystemState} → LvrCarrier pk sig start → (step* : Step* start final) → LvrCarrier pk sig final LvrCarrier-transp* lvrc step-0 = lvrc LvrCarrier-transp* lvrc (step-s s* s) = Carrier-transp LvrProp ImplPreservesLvr s (LvrCarrier-transp* lvrc s*) fSE⇒rnd≤lvr : ∀ {v' pk} → {final : SystemState} → Meta-Honest-PK pk → ∀ {pre : SystemState}{post : SystemState}{theStep : Step pre post} → firstSendEstablishes v' pk post theStep → Step* post final → LvrCarrier pk (signature v' unit) final fSE⇒rnd≤lvr hpk {theStep = step-peer (step-honest _)} (_ , _ , lvrc) step* = LvrCarrier-transp* lvrc step* vo₁ : VO.ImplObligation₁ -- Initialization doesn't send any messages at all so far; Agda figures that out so no proof -- required here. In future it may send messages, but any verifiable Signatures for honest PKs -- they contain will be from GenesisInfo. vo₁ {pid} {pk = pk} {pre = pre} r sm@(step-msg {(_ , nm)} m∈pool pidini) {m = m} {v'} hpk v⊂m m∈outs sig ¬init ¬sentb4 vpb v'⊂m' m'∈pool sig' ¬init' refl rnds≡ with msgsToSendWereSent {pid} {nm} m∈outs ...| _ , vm , _ , refl , _ with newVoteSameEpochGreaterRound r (step-msg m∈pool pidini) ¬init hpk v⊂m m∈outs sig ¬sentb4 ...| eIds≡' , suclvr≡v'rnd , _ -- Use unwind to find the step that first sent the signature for v', then Any-Step-elim to -- prove that going from the poststate of that step to pre results in a state in which the -- round of v' is at most the last voted round recorded in the peerState of the peer that -- sent v' with Any-Step-elim {Q = LvrCarrier pk (₋vSignature v') pre} (fSE⇒rnd≤lvr {v'} hpk) (Any-Step-map (λ _ ivnp → isValidNewPart⇒fSE {v' = v'} hpk ivnp) (unwind r hpk v'⊂m' m'∈pool sig' ¬init')) ...| mkCarrier r' mws ini vpf' preprop -- The fake/trivial handler always sends a vote for its current epoch, but for a -- round greater than its last voted round with sameSig⇒sameVoteData (msgSigned mws) sig' (msgSameSig mws) ...| inj₁ hb = ⊥-elim (PerState.meta-sha256-cr pre r hb) ...| inj₂ refl with msgSender mws ≟NodeId pid ...| no neq = -- We know that *after* the step, pid can sign v (vpb is about the post-state). For v', we -- know it about state "pre"; we transport this to the post-state using -- PeerCanSignForPK-Stable. Because EpochConfigs known in a system state are consistent with -- each other (i.e., trivially, for now because only the initial EpochConfig is known), we can -- use PK-inj to contradict the assumption that v and v' were sent by different peers (neq). let theStep = step-peer (step-honest sm) vpf'' = PeerCanSignForPK-stable r theStep vpf' 𝓔s≡ = availEpochsConsistent {pid} {msgSender mws} (step-s r theStep) vpb vpf'' in ⊥-elim (neq (trans (trans (sym (nid≡ vpf'')) (PK-inj-same-ECs (sym 𝓔s≡) (trans (pk≡ vpf'') (sym (pk≡ vpb))))) (nid≡ vpb))) vo₁ {pid} {pk = pk} {pre = pre} r sm@(step-msg m∈pool ps≡) {v' = v'} hpk v⊂m m∈outs sig ¬init ¬sentb4 vpb v'⊂m' m'∈pool sig' _ refl rnds≡ | _ , vm , _ , refl , _ | eIds≡' , suclvr≡v'rnd , _ | mkCarrier r' mws ini vpf' preprop | inj₂ refl | yes refl with preprop ...| inj₁ diffEpoch = ⊥-elim (diffEpoch eIds≡') ...| inj₂ (sameEpoch , v'rnd≤lvr) -- So we have proved both that the round of v' is ≤ the lastVotedRound of -- the peer's state and that the round of v' is one greater than that value, -- which leads to a contradiction = ⊥-elim (1+n≰n (≤-trans (≤-reflexive suclvr≡v'rnd) (≤-trans (≤-reflexive rnds≡) v'rnd≤lvr))) -- TODO-1: This proof should be refactored to reduce redundant reasoning about the two votes. The -- newVoteSameEpochGreaterRound property uses similar reasoning. vo₂ : VO.ImplObligation₂ vo₂ {pid = pid} {pk = pk} {pre = pre} r (step-msg {_ , nm} m∈pool pinit) {v = v} {m} hpk v⊂m m∈outs sig ¬init vnew vpk v'⊂m' m'∈outs sig' ¬init' v'new vpk' es≡ rnds≡ with msgsToSendWereSent {pid} {nm} m∈outs ...| _ , vm , pm , refl , refl with proposalHandlerSentVote {pid} {0} {pm} {vm} {peerStates pre pid} m∈outs ...| _ , v∈outs with v⊂m -- Rebuilding keeps the same signature, and the SyncInfo included with the -- VoteMsg sent comprises QCs from the peer's state. Votes represented in -- those QCS have signatures that have been sent before, contradicting the -- assumption that v's signature has not been sent before. ...| vote∈qc {vs = vs} {qc} vs∈qc v≈rbld (inV qc∈m) rewrite cong ₋vSignature v≈rbld | procPMCerts≡ {0} {pm} {peerStates pre pid} {vm} v∈outs | SendVote-inj-v (Any-singleton⁻ v∈outs) with qcVotesSentB4 r pinit (VoteMsgQCsFromRoundManager r (step-msg m∈pool pinit) hpk v⊂m m∈outs qc∈m) vs∈qc ¬init ...| mws = ⊥-elim (vnew mws) vo₂ {pid = pid} {pk = pk} {pre = pre} r (step-msg {_ , nm} m∈pool pinit) {v = v} {m} {v'} {m'} hpk v⊂m m∈outs sig ¬init vnew vpk v'⊂m' m'∈outs sig' ¬init' v'new vpk' es≡ rnds≡ | _ , vm , pm , refl , refl | _ , v∈outs | vote∈vm with msgsToSendWereSent {pid} {nm} {m'} {st = peerStates pre pid} m'∈outs ...| _ , vm' , pm , refl , refl with proposalHandlerSentVote {pid} {0} {pm} {vm'} {peerStates pre pid} m'∈outs ...| _ , v'∈outs rewrite cong ₋vmVote (SendVote-inj-v (trans (Any-singleton⁻ v∈outs) (sym (Any-singleton⁻ v'∈outs)))) with v'⊂m' ...| vote∈vm = refl ...| vote∈qc {vs = vs} {qc} vs∈qc v≈rbld (inV qc∈m) rewrite cong ₋vSignature v≈rbld | procPMCerts≡ {0} {pm} {peerStates pre pid} {vm} v∈outs | SendVote-inj-v (Any-singleton⁻ v∈outs) | cong ₋vmVote (SendVote-inj-v (trans (Any-singleton⁻ v∈outs) (sym (Any-singleton⁻ v'∈outs)))) with qcVotesSentB4 r pinit (VoteMsgQCsFromRoundManager r (step-msg m∈pool pinit) hpk v'⊂m' m'∈outs qc∈m) vs∈qc ¬init' ...| mws = ⊥-elim (v'new mws)
{ "alphanum_fraction": 0.610699069, "avg_line_length": 53.9319148936, "ext": "agda", "hexsha": "aa4fe33f6c3f2379b58ec9fcbb7d316955dc8d26", "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": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "cwjnkins/bft-consensus-agda", "max_forks_repo_path": "LibraBFT/Impl/Properties/VotesOnce.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "cwjnkins/bft-consensus-agda", "max_issues_repo_path": "LibraBFT/Impl/Properties/VotesOnce.agda", "max_line_length": 146, "max_stars_count": null, "max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "cwjnkins/bft-consensus-agda", "max_stars_repo_path": "LibraBFT/Impl/Properties/VotesOnce.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4146, "size": 12674 }
module Prelude.Exit where open import Prelude.Char open import Prelude.IO open import Prelude.Unit postulate exit : Char → IO Unit {-# COMPILED_EPIC exit (n : Int, u : Unit) -> Unit = foreign Unit "exit" (n : Int) #-} exitSuccess : Char exitSuccess = '\NUL' exitFailure : Char exitFailure = '\SOH'
{ "alphanum_fraction": 0.6493902439, "avg_line_length": 18.2222222222, "ext": "agda", "hexsha": "aaaa2260d289f2e34b156138c4651273fe153702", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_path": "test/epic/Prelude/Exit.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/epic/Prelude/Exit.agda", "max_line_length": 63, "max_stars_count": null, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/epic/Prelude/Exit.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 86, "size": 328 }
-- Agda program using the Iowa Agda library open import bool module PROOF-evendoublecoin (Choice : Set) (choose : Choice → 𝔹) (lchoice : Choice → Choice) (rchoice : Choice → Choice) where open import eq open import nat open import list open import maybe --------------------------------------------------------------------------- -- Translated Curry operations: add : ℕ → ℕ → ℕ add zero x = x add (suc y) z = suc (add y z) coin : Choice → ℕ → ℕ coin c1 x = if choose c1 then x else suc x double : ℕ → ℕ double x = add x x even : ℕ → 𝔹 even zero = tt even (suc zero) = ff even (suc (suc x)) = even x --------------------------------------------------------------------------- add-suc : ∀ (x y : ℕ) → add x (suc y) ≡ suc (add x y) add-suc zero y = refl add-suc (suc x) y rewrite add-suc x y = refl -- auxiliary property for x+x instead of double: even-add-x-x : ∀ (x : ℕ) → even (add x x) ≡ tt even-add-x-x zero = refl even-add-x-x (suc x) rewrite add-suc x x | even-add-x-x x = refl evendoublecoin : (c1 : Choice) → (x : ℕ) → (even (double (coin c1 x))) ≡ tt evendoublecoin c1 x rewrite even-add-x-x (coin c1 x) = refl ---------------------------------------------------------------------------
{ "alphanum_fraction": 0.5176663928, "avg_line_length": 24.34, "ext": "agda", "hexsha": "ac4ee4d205a1dd99f5004efe35792271019b4114", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-10-09T16:02:18.000Z", "max_forks_repo_forks_event_min_datetime": "2021-10-09T16:02:18.000Z", "max_forks_repo_head_hexsha": "c34d76595b23e5152e6a5883ad3b0ec1d840f6d9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "DouglasRMiles/pakcs_lib", "max_forks_repo_path": "docs/src/tooldocs/verify/PROOF-evendoublecoin.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "c34d76595b23e5152e6a5883ad3b0ec1d840f6d9", "max_issues_repo_issues_event_max_datetime": "2021-02-24T12:41:30.000Z", "max_issues_repo_issues_event_min_datetime": "2021-02-21T22:25:13.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "DouglasRMiles/pakcs_lib", "max_issues_repo_path": "docs/src/tooldocs/verify/PROOF-evendoublecoin.agda", "max_line_length": 75, "max_stars_count": 2, "max_stars_repo_head_hexsha": "c34d76595b23e5152e6a5883ad3b0ec1d840f6d9", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "DouglasRMiles/pakcs_lib", "max_stars_repo_path": "docs/src/tooldocs/verify/PROOF-evendoublecoin.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-21T22:25:28.000Z", "max_stars_repo_stars_event_min_datetime": "2021-01-06T18:32:48.000Z", "num_tokens": 357, "size": 1217 }
-- Andreas, 2018-06-03, issue #3057 reported by nad. -- We should not allow the public import of an ambiguous identifier -- {-# OPTIONS -v scope:20 #-} module Issue3057 where module M where postulate A : Set a : A open M public renaming (a to A) -- Should fail
{ "alphanum_fraction": 0.6714801444, "avg_line_length": 16.2941176471, "ext": "agda", "hexsha": "ce6d12cf7c80969701499395f87aee4301a172c9", "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/Issue3057.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/Issue3057.agda", "max_line_length": 67, "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/Issue3057.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": 277 }
{- This file contains: - Definition of set truncations -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.SetTruncation.Base where open import Cubical.Core.Primitives -- set truncation as a higher inductive type: data ∥_∥₂ {ℓ} (A : Type ℓ) : Type ℓ where ∣_∣₂ : A → ∥ A ∥₂ squash₂ : ∀ (x y : ∥ A ∥₂) (p q : x ≡ y) → p ≡ q
{ "alphanum_fraction": 0.6281690141, "avg_line_length": 19.7222222222, "ext": "agda", "hexsha": "0a2e801936bb60cc82a0ad3f42145177152d1121", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/HITs/SetTruncation/Base.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/HITs/SetTruncation/Base.agda", "max_line_length": 50, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/HITs/SetTruncation/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 133, "size": 355 }
------------------------------------------------------------------------ -- "Equational" reasoning combinator setup ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} open import Prelude open import Labelled-transition-system module Bisimilarity.Classical.Equational-reasoning-instances {ℓ} {lts : LTS ℓ} where open import Bisimilarity.Classical lts open import Equational-reasoning instance reflexive∼ : Reflexive _∼_ reflexive∼ = is-reflexive reflexive-∼ symmetric∼ : Symmetric _∼_ symmetric∼ = is-symmetric symmetric-∼ trans∼∼ : Transitive _∼_ _∼_ trans∼∼ = is-transitive transitive-∼ convert∼∼ : Convertible _∼_ _∼_ convert∼∼ = is-convertible id
{ "alphanum_fraction": 0.581300813, "avg_line_length": 23.8064516129, "ext": "agda", "hexsha": "f5c1e2d747f03fb8a03334227d8ecb491cad7f5d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/up-to", "max_forks_repo_path": "src/Bisimilarity/Classical/Equational-reasoning-instances.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/up-to", "max_issues_repo_path": "src/Bisimilarity/Classical/Equational-reasoning-instances.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/up-to", "max_stars_repo_path": "src/Bisimilarity/Classical/Equational-reasoning-instances.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 197, "size": 738 }
{-# OPTIONS -v 2 #-} module Leftovers.Examples where open import Leftovers.Utils open import Leftovers.Leftovers open import Leftovers.Equality open import Data.Bool open import Relation.Binary.PropositionalEquality open import Data.Nat open import Data.Product open import Data.Unit -- notNot : ∀ b → not (not b) ≡ b -- notNot = (by {A = ∀ b → not (not b) ≡ b} (cases (quote Bool)) {!!}) -- (refl , refl) -- applyTo : ∀ {ℓ1 ℓ2} {X : Set ℓ1} { Y : Set ℓ2 } → (X → Y) → X → Y -- applyTo f x = f x -- infixr 40 applyTo -- syntax applyTo e₁ (λ x → e₂) = x ≔ e₁ ︔ e₂ plusZero : ∀ n → n ≡ n + 0 plusZero = getNormal (by {A = ∀ n → n ≡ n + 0} (cases (quote ℕ)) ((λ x → cong suc (plusZero x)) , refl)) -- (by {A = ∀ n → n ≡ n + 0} (cases (quote ℕ)) ((λ x → cong suc (plusZero x)) , refl)) -- plusZero' : ∀ n → n ≡ n + 0 -- plusZero' = getNormal -- ((the ((zero ≡ zero × (∀ x → suc x ≡ suc x + 0)) → ∀ n → n ≡ n + 0) λ h → identity (λ { zero → proj₁ h ; (suc x) → (proj₂ h) x })) -- (refl , λ x → cong suc (plusZero' x))) -- -- plusZero'' : ∀ n → n ≡ n + 0 -- -- plusZero'' = (the (zero ≡ zero → (∀ x → suc x ≡ suc x + 0) → ∀ n → n ≡ n + 0) λ h1 h2 → (λ { zero → h1 ; (suc x) → h2 x})) refl ((the (Dummy → ∀ x → suc x ≡ suc x + 0) (λ {dummy → λ x → cong suc (plusZero'' x)})) dummy) -- -- plusZero' = -- -- let -- -- h : (zero ≡ zero × ∀ n → suc n ≡ (suc n) + 0) -- -- h = refl , λ n → cong suc (plusZero' n) -- -- in λ { zero → proj₁ h ; (suc x) → (proj₂ h) x} -- -- plusZeroR : ∀ n → n + 0 ≡ n -- -- plusZeroR = by (refl-cases (quote ℕ)) ?
{ "alphanum_fraction": 0.5164765526, "avg_line_length": 30.3461538462, "ext": "agda", "hexsha": "1a3ca2e30681a9acba0d3a34f0046f3c04534e20", "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": "01b60b405009feaada181af175f019ceb89e42b2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "JoeyEremondi/AgdaLeftovers", "max_forks_repo_path": "src/Leftovers/Examples.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "JoeyEremondi/AgdaLeftovers", "max_issues_repo_path": "src/Leftovers/Examples.agda", "max_line_length": 226, "max_stars_count": null, "max_stars_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "JoeyEremondi/AgdaLeftovers", "max_stars_repo_path": "src/Leftovers/Examples.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 633, "size": 1578 }
-- This example comes from the discussion on Issue423. module SolveNeutralApplication where postulate A : Set a b : A T : A → Set mkT : ∀ a → T a phantom : A → A → A data Bool : Set where true false : Bool f : Bool → A → A f true x = phantom x a f false x = phantom x b -- Andreas, 2012-09-07: the original f did not have "phantom x", -- thus, x was cleary unused. With fixing issue 691 Agda tracks -- constant functions in the type system, thus, reasoning as below -- no longer works. We have to make f use its second argument. -- We can solve the constraint -- f x _4 == f x y -- with -- _4 := y -- since the application of f is neutral. g : (x : Bool)(y : A) → T (f x y) g x y = mkT (f x _)
{ "alphanum_fraction": 0.6420612813, "avg_line_length": 23.9333333333, "ext": "agda", "hexsha": "9759975315e1b24accc8bc64e9e0b06e01c8c75f", "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/SolveNeutralApplication.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/SolveNeutralApplication.agda", "max_line_length": 66, "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/SolveNeutralApplication.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": 232, "size": 718 }
open import Coinduction using ( ∞ ; ♯_ ; ♭ ) open import Data.Bool using ( Bool ; true ; false ; if_then_else_ ) open import Data.Empty using ( ⊥ ) open import Data.Maybe using ( Maybe ; just ; nothing ) open import Data.Sum using ( _⊎_ ; inj₁ ; inj₂ ) open import Data.Unit using ( ⊤ ; tt ) open import Data.Natural using ( Natural ; # ) open import Data.String using ( String ) open import Data.ByteString using ( ByteString ; strict ; length ) open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ) module System.IO.Transducers.Session where -- Unidirectional sessions. These can be viewed as trees, -- where each node is labelled by a set A, and has a child -- for each element of A. -- These are a lot like session types, but are unidirectional, -- not bidirectional, and are not designed to support session -- mobility. -- They are also a lot like arenas in game semantics, but again -- are unidirectional. -- They're a lot like the container types from Ghani, Hancock -- and Pattison's "Continuous functions on final coalgebras". -- Note that we are supporting weighted sets, similar to theirs, -- in order to support induction over weights of input, -- e.g. on bytestring input we can do induction over the length -- of the bytestring. -- Finally, they are a lot like automata: states are sessions, -- acceptors are leaves, transitions correspond to children. infixr 4 _∼_ infixr 6 _⊕_ infixr 7 _&_ _&*_ -- Weighting for a set Weighted : Set → Set Weighted A = A → Natural -- Discrete weighting function δ : ∀ {A} → (Weighted A) δ a = # 1 -- Sessions are trees of weighted sets data Session : Set₁ where I : Session Σ : {A : Set} → (W : Weighted A) → (F : ∞ (A → Session)) → Session -- Equivalence of sessions data _∼_ : Session → Session → Set₁ where I : I ∼ I Σ : {A : Set} → (W : Weighted A) → {F₁ F₂ : ∞ (A → Session)} → ∞ (∀ a → ♭ F₁ a ∼ ♭ F₂ a) → (Σ W F₁ ∼ Σ W F₂) ∼-refl : ∀ {S} → (S ∼ S) ∼-refl {I} = I ∼-refl {Σ V F} = Σ V (♯ λ a → ∼-refl {♭ F a}) ∼-sym : ∀ {S T} → (S ∼ T) → (T ∼ S) ∼-sym I = I ∼-sym (Σ V F) = Σ V (♯ λ a → ∼-sym (♭ F a)) ∼-trans : ∀ {S T U} → (S ∼ T) → (T ∼ U) → (S ∼ U) ∼-trans I I = I ∼-trans (Σ V F) (Σ .V G) = Σ V (♯ λ a → ∼-trans (♭ F a) (♭ G a)) -- Inital alphabet Γ : Session → Set Γ I = ⊥ Γ (Σ {A} W F) = A Δ : ∀ S → (Weighted (Γ S)) Δ I () Δ (Σ W F) a = W a _/_ : ∀ S → (Γ S) → Session I / () (Σ W F) / a = ♭ F a -- IsI S is inhabited whenever S ≡ I IsI : Session → Set IsI I = ⊤ IsI (Σ V F) = ⊥ -- IsΣ S is inhabited whenever S is of the form Σ V F IsΣ : Session → Set IsΣ I = ⊥ IsΣ (Σ V F) = ⊤ -- IsΣ respects ≡. IsΣ-≡ : ∀ {S} {isΣ : IsΣ S} {T} → (S ≡ T) → (IsΣ T) IsΣ-≡ {Σ V F} refl = tt IsΣ-≡ {I} {} refl -- Singletons ⟨_w/_⟩ : (A : Set) → (Weighted A) → Session ⟨ A w/ W ⟩ = Σ W (♯ λ a → I) ⟨_⟩ : Set → Session ⟨ A ⟩ = ⟨ A w/ δ ⟩ -- Sequencing _&_ : Session → Session → Session I & T = T (Σ V F) & T = Σ V (♯ λ a → ♭ F a & T) -- Units and associativity unit₁ : ∀ {S} → (I & S ∼ S) unit₁ = ∼-refl unit₂ : ∀ {S} → (S & I ∼ S) unit₂ {I} = I unit₂ {Σ V F} = Σ V (♯ λ a → unit₂ {♭ F a}) assoc : ∀ {S T U} → (S & (T & U) ∼ (S & T) & U) assoc {I} = ∼-refl assoc {Σ V F} = Σ V (♯ λ a → assoc {♭ F a}) -- Lazy choice _+_ : Session → Session → Session S + T = Σ δ (♯ λ b → if b then S else T) -- Strict choice _⊕_ : Session → Session → Session I ⊕ T = I S ⊕ I = I S ⊕ T = S + T -- Lazy option ¿ : Session → Session ¿ S = S + I -- Lazy Kleene star -- It would be nice if I could just define * S = ¿ (S & * S), -- but that doesn't pass the termination checker, so I have -- to expand out the definition. hd : Session → Set hd I = Bool hd (Σ {A} W F) = A wt : ∀ S → (Weighted (hd S)) wt I = δ wt (Σ W F) = W mutual tl : ∀ S T → (hd S) → Session tl I T true = T &* T tl I T false = I tl (Σ W F) T a = (♭ F a) &* T _&*_ : Session → Session → Session S &* T = Σ (wt S) (♯ tl S T) * : Session → Session * S = I &* S + : Session → Session + S = S &* S -- Bytes Bytes' : Session Bytes' = + ⟨ ByteString strict w/ length ⟩ Bytes : Session Bytes = * ⟨ ByteString strict w/ length ⟩ -- TODO: weight strings by their length? Strings' : Session Strings' = + ⟨ String ⟩ Strings : Session Strings = * ⟨ String ⟩
{ "alphanum_fraction": 0.5674053555, "avg_line_length": 22.2153846154, "ext": "agda", "hexsha": "4f0eef6a478572c8bc60754c7ff0a7180f4a907d", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z", "max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z", "max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ilya-fiveisky/agda-system-io", "max_forks_repo_path": "src/System/IO/Transducers/Session.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "ilya-fiveisky/agda-system-io", "max_issues_repo_path": "src/System/IO/Transducers/Session.agda", "max_line_length": 70, "max_stars_count": 10, "max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ilya-fiveisky/agda-system-io", "max_stars_repo_path": "src/System/IO/Transducers/Session.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z", "num_tokens": 1662, "size": 4332 }
module Structure.Relator.Names where import Lvl open import Data.Tuple as Tuple using (_⨯_ ; _,_) open import Functional open import Lang.Instance open import Logic open import Logic.Propositional open import Logic.Propositional.Xor open import Numeral.Natural open import Type private variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Lvl.Level private variable T A B C D E : Type{ℓ} ConversePattern : (Stmt{ℓ₁} → Stmt{ℓ₂} → Stmt{ℓ}) → (A → B → Stmt) → (B → A → Stmt) → Stmt ConversePattern(_▫_)(_▫₁_)(_▫₂_) = ∀{x}{y} → (x ▫₁ y) ▫ (y ▫₂ x) Subrelation : (A → B → Stmt{ℓ₁}) → (A → B → Stmt{ℓ₂}) → Stmt Subrelation(_▫₁_)(_▫₂_) = ∀{x}{y} → (x ▫₁ y) → (x ▫₂ y) TransitivityPattern : (A → B → Stmt{ℓ₁}) → (B → C → Stmt{ℓ₂}) → (A → C → Stmt{ℓ₃}) → Stmt TransitivityPattern(_▫₁_)(_▫₂_)(_▫₃_) = ∀{x}{y}{z} → (x ▫₁ y) → (y ▫₂ z) → (x ▫₃ z) FlippedTransitivityₗPattern : (A → C → Stmt{ℓ₁}) → (B → C → Stmt{ℓ₂}) → (A → B → Stmt{ℓ₃}) → Stmt FlippedTransitivityₗPattern(_▫₁_)(_▫₂_)(_▫₃_) = ∀{x}{y}{z} → (x ▫₁ z) → (y ▫₂ z) → (x ▫₃ y) FlippedTransitivityᵣPattern : (A → B → Stmt{ℓ₁}) → (A → C → Stmt{ℓ₂}) → (B → C → Stmt{ℓ₃}) → Stmt FlippedTransitivityᵣPattern(_▫₁_)(_▫₂_)(_▫₃_) = ∀{x}{y}{z} → (x ▫₁ y) → (x ▫₂ z) → (y ▫₃ z) module _ (_▫_ : T → T → Stmt{ℓ}) where Symmetry : Stmt Symmetry = ConversePattern(_→ᶠ_)(_▫_)(_▫_) Asymmetry : Stmt Asymmetry = ConversePattern(_→ᶠ_)(_▫_)((¬_) ∘₂ (_▫_)) Reflexivity : Stmt Reflexivity = ∀{x : T} → (x ▫ x) Transitivity : Stmt Transitivity = TransitivityPattern(_▫_)(_▫_)(_▫_) SwappedTransitivity : Stmt SwappedTransitivity = ∀{x y z : T} → (y ▫ z) → (x ▫ y) → (x ▫ z) -- Also called: Left Euclidean. FlippedTransitivityₗ : Stmt FlippedTransitivityₗ = FlippedTransitivityₗPattern(_▫_)(_▫_)(_▫_) -- Also called: Right Euclidean. FlippedTransitivityᵣ : Stmt FlippedTransitivityᵣ = FlippedTransitivityᵣPattern(_▫_)(_▫_)(_▫_) Irreflexivity : Stmt Irreflexivity = ∀{x : T} → ¬(x ▫ x) -- Also called: Total, complete, connex. ConverseTotal : Stmt ConverseTotal = ConversePattern(_∨_)(_▫_)(_▫_) ConverseDichotomy : Stmt ConverseDichotomy = ConversePattern(_⊕_)(_▫_)(_▫_) -- Also called: Comparison. CoTransitivity : Stmt CoTransitivity = ∀{x y z : T} → (x ▫ z) → ((x ▫ y) ∨ (y ▫ z)) module _ (_▫₁_ : T → T → Stmt{ℓ₁}) (_▫₂_ : T → T → Stmt{ℓ₂}) where Antisymmetry : Stmt Antisymmetry = ∀{a b} → (a ▫₁ b) → (b ▫₁ a) → (a ▫₂ b) ConverseTrichotomy : Stmt ConverseTrichotomy = ∀{x y} → (x ▫₁ y) ∨ (x ▫₂ y) ∨ (y ▫₁ x) module _ (_▫₁_ : A → B → Stmt{ℓ₁}) (_▫₂_ : A → A → Stmt{ℓ₂}) where Subtransitivityₗ : Stmt Subtransitivityₗ = TransitivityPattern(_▫₂_)(_▫₁_)(_▫₁_) module _ (_▫₁_ : A → B → Stmt{ℓ₁}) (_▫₂_ : B → B → Stmt{ℓ₂}) where Subtransitivityᵣ : Stmt Subtransitivityᵣ = TransitivityPattern(_▫₁_)(_▫₂_)(_▫₁_)
{ "alphanum_fraction": 0.6135144798, "avg_line_length": 33.6987951807, "ext": "agda", "hexsha": "d584cb0cfbb8ce2fb2283a45cfbd581b74872840", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Structure/Relator/Names.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Structure/Relator/Names.agda", "max_line_length": 97, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Structure/Relator/Names.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": 1249, "size": 2797 }
open import Agda.Builtin.Unit open import Agda.Builtin.Bool open import Agda.Builtin.Nat open import Agda.Builtin.Equality open import Agda.Builtin.IO open import Agda.Builtin.String postulate putStr : String → IO ⊤ {-# FOREIGN GHC import qualified Data.Text.IO #-} {-# COMPILE GHC putStr = Data.Text.IO.putStr #-} data Sing : Nat → Set where sing : Sing zero data Vec : Nat → Set where nil : Vec zero cons : ∀ n → Vec n → Vec (suc n) isTailNil : ∀ m n → Sing m → Vec n → Bool isTailNil .0 .1 sing (cons zero v) = true -- two `zero`s are buried in the dot patterns, which to resurrect? isTailNil _ _ _ _ = false shouldBeFalse = isTailNil 0 2 sing (cons 1 (cons 0 nil)) isFalse : false ≡ shouldBeFalse isFalse = refl magic : false ≡ true → String magic () f : (b : Bool) → false ≡ b → String f false eq = "Phew!" f true eq = magic eq main = putStr (f shouldBeFalse refl)
{ "alphanum_fraction": 0.6857463524, "avg_line_length": 22.8461538462, "ext": "agda", "hexsha": "ec6f155922bba48791c05e9efe0da2ee868f5bbd", "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/Issue3903.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/Issue3903.agda", "max_line_length": 109, "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/Issue3903.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": 274, "size": 891 }
------------------------------------------------------------------------------ -- Elimination properties for the inequalities ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Data.Nat.Inequalities.EliminationPropertiesI where open import FOTC.Base open import FOTC.Data.Nat open import FOTC.Data.Nat.Inequalities ------------------------------------------------------------------------------ 0<0→⊥ : ¬ (zero < zero) 0<0→⊥ 0<0 = t≢f (trans (sym 0<0) lt-00) S<0→⊥ : ∀ {n} → ¬ (succ₁ n < zero) S<0→⊥ {n} h = t≢f (trans (sym h) (lt-S0 n)) x<0→⊥ : ∀ {n} → N n → ¬ (n < zero) x<0→⊥ nzero 0<0 = 0<0→⊥ 0<0 x<0→⊥ (nsucc _) Sn<0 = S<0→⊥ Sn<0 x<x→⊥ : ∀ {n} → N n → ¬ (n < n) x<x→⊥ nzero 0<0 = 0<0→⊥ 0<0 x<x→⊥ (nsucc {n} Nn) Sn<Sn = ⊥-elim (x<x→⊥ Nn (trans (sym (lt-SS n n)) Sn<Sn)) 0>0→⊥ : ¬ (zero > zero) 0>0→⊥ 0>0 = t≢f (trans (sym 0>0) lt-00) 0>S→⊥ : ∀ {n} → ¬ (zero > succ₁ n) 0>S→⊥ {n} h = t≢f (trans (sym h) (lt-S0 n)) 0>x→⊥ : ∀ {n} → N n → ¬ (zero > n) 0>x→⊥ nzero 0>0 = 0>0→⊥ 0>0 0>x→⊥ (nsucc _) 0>Sn = 0>S→⊥ 0>Sn x>x→⊥ : ∀ {n} → N n → ¬ (n > n) x>x→⊥ Nn = x<x→⊥ Nn S≤0→⊥ : ∀ {n} → N n → ¬ (succ₁ n ≤ zero) S≤0→⊥ nzero S0≤0 = t≢f (trans (sym S0≤0) (trans (lt-SS zero zero) lt-00)) S≤0→⊥ (nsucc {n} _) SSn≤0 = t≢f (trans (sym SSn≤0) (trans (lt-SS (succ₁ n) zero) (lt-S0 n))) 0≥S→⊥ : ∀ {n} → N n → ¬ (zero ≥ succ₁ n) 0≥S→⊥ Nn 0≥Sn = S≤0→⊥ Nn 0≥Sn x<y→y<x→⊥ : ∀ {m n} → N m → N n → m < n → ¬ (n < m) x<y→y<x→⊥ nzero Nn 0<n n<0 = ⊥-elim (0>x→⊥ Nn n<0) x<y→y<x→⊥ (nsucc Nm) nzero Sm<0 0<Sm = ⊥-elim (0>x→⊥ (nsucc Nm) Sm<0) x<y→y<x→⊥ (nsucc {m} Nm) (nsucc {n} Nn) Sm<Sn Sn<Sm = x<y→y<x→⊥ Nm Nn (trans (sym (lt-SS m n)) Sm<Sn) (trans (sym (lt-SS n m)) Sn<Sm) S≯0→⊥ : ∀ {n} → ¬ (succ₁ n ≯ zero) S≯0→⊥ {n} h = ⊥-elim (t≢f (trans (sym (lt-0S n)) h))
{ "alphanum_fraction": 0.4187992126, "avg_line_length": 33.3114754098, "ext": "agda", "hexsha": "ed93db98cc499feb56b26953e0b20c93e6d192ca", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Data/Nat/Inequalities/EliminationPropertiesI.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Data/Nat/Inequalities/EliminationPropertiesI.agda", "max_line_length": 84, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Data/Nat/Inequalities/EliminationPropertiesI.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": 1000, "size": 2032 }
data Bool : Set where true : Bool false : Bool not : Bool → Bool not true = false not false = true data ℕ : Set where O : ℕ S : ℕ → ℕ _+_ : ℕ → ℕ → ℕ O + a = a S a + b = S (a + b) _*_ : ℕ → ℕ → ℕ O * a = O S a * b = a + (a * b) _or_ : Bool → Bool → Bool true or _ = true false or b = b if_then_else_ : {A : Set} → Bool → A → A → A if true then x else y = x if false then x else y = y infixl 60 _*_ infixl 40 _+_ infixr 20 _or_ infix 5 if_then_else_ infixr 40 _::_ data List (A : Set) : Set where [] : List A _::_ : A -> List A -> List A _∘_ : {A : Set} -> {B : A -> Set} -> {C : (x : A) -> B x -> Set} -> (f : {x : A} -> (y : B x) -> C x y) -> (g : (x : A) -> B x) -> (x : A) -> C x (g x) _∘_ f g a = f (g a) plus-two = S ∘ S map : {A B : Set} -> (A -> B) -> List A -> List B map f [] = [] map f (x :: xs) = f x :: map f xs _++_ : {A : Set} -> List A -> List A -> List A [] ++ ys = ys x :: xs ++ ys = x :: (xs ++ ys) data Vec (A : Set) : ℕ -> Set where nil : Vec A O cons : (n : ℕ) -> A -> Vec A n -> Vec A (S n) head : {A : Set} {n : ℕ} -> Vec A (S n) -> A head (cons n v vs) = v vmap : {A B : Set} (n : ℕ) -> (A -> B) -> Vec A n -> Vec B n vmap .O f nil = nil vmap .(S n) f (cons n x xs) = cons n (f x) (vmap n f xs) vmap′ : {A B : Set} (n : ℕ) -> (A -> B) -> Vec A n -> Vec B n vmap′ O f nil = nil vmap′ (S n) f (cons .n x xs) = cons n (f x) (vmap n f xs) data Fin : ℕ -> Set where fzero : {n : ℕ} -> Fin (S n) fsuc : {n : ℕ} -> Fin n -> Fin (S n) _!_ : {n : ℕ}{A : Set} -> Vec A n -> Fin n -> A nil ! () cons n x a ! fzero = x cons n x a ! fsuc b = a ! b tabulate : {n : ℕ}{A : Set} -> (Fin n -> A) -> Vec A n tabulate {O} f = nil tabulate {S n} f = cons n (f fzero) (tabulate (f ∘ fsuc)) data False : Set where record True : Set where trivial : True trivial = _ isTrue : Bool -> Set isTrue true = True isTrue false = False _<_ : ℕ -> ℕ -> Bool _ < O = false O < S n = true S m < S n = m < n length : {A : Set} -> List A -> ℕ length [] = O length (x :: xs) = S (length xs) lookup : {A : Set}(xs : List A)(n : ℕ) -> isTrue (n < length xs) -> A lookup (x :: xs) O b = x lookup (x :: xs) (S n) b = lookup xs n b lookup [] a () data _==_ {A : Set}(x : A) : A -> Set where refl : x == x data _≤_ : ℕ -> ℕ -> Set where ≤O : {m n : ℕ} -> m == n -> m ≤ n ≤I : {m n : ℕ} -> m ≤ n -> m ≤ S n leq-trans : {l m n : ℕ} -> l ≤ m -> m ≤ n -> l ≤ n leq-trans a (≤O refl) = a leq-trans a (≤I b) = ≤I (leq-trans a b) min : ℕ -> ℕ -> ℕ min a b with a < b min a b | true = a min a b | false = b filter : {A : Set} -> (A -> Bool) -> List A -> List A filter f [] = [] filter f (x :: xs) with f x ... | true = x :: filter f xs ... | false = filter f xs data _≠_ : ℕ -> ℕ -> Set where z≠s : {n : ℕ} -> O ≠ S n s≠z : {n : ℕ} -> S n ≠ O s≠s : {m n : ℕ} -> n ≠ m → S n ≠ S m data Equal? (n m : ℕ) : Set where eq : n == m -> Equal? n m neq : n ≠ m -> Equal? n m
{ "alphanum_fraction": 0.4543028686, "avg_line_length": 18.6211180124, "ext": "agda", "hexsha": "08277dcd5fa4a72d9f6428edda57223223eaa22e", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2017-06-03T06:32:26.000Z", "max_forks_repo_forks_event_min_datetime": "2015-12-02T02:10:26.000Z", "max_forks_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "shouya/thinking-dumps", "max_forks_repo_path": "agda-tutorial/basics.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_issues_repo_issues_event_max_datetime": "2015-08-04T22:05:11.000Z", "max_issues_repo_issues_event_min_datetime": "2015-06-14T06:07:33.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "shouya/thinking-dumps", "max_issues_repo_path": "agda-tutorial/basics.agda", "max_line_length": 69, "max_stars_count": 24, "max_stars_repo_head_hexsha": "a6fc111e02dc631f56302bb059d855446792bebc", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "shouya/thinking-dumps", "max_stars_repo_path": "agda-tutorial/basics.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-09T01:02:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-02-14T17:18:34.000Z", "num_tokens": 1289, "size": 2998 }
{- formatted printing like printf, except type-safe (as proposed in "Cayenne -- a language with dependent types" by Augustsson). The types of the rest of the arguments are computed from the format string. -} module string-format where open import char open import eq open import list open import nat open import nat-to-string open import string {- We will first convert the format string to the following type, so we can avoid default cases in the definition of format-th (cf. string-format-issue.agda). -} data format-d : Set where format-nat : format-d → format-d format-string : format-d → format-d not-format : (c : char) → format-d → format-d empty-format : format-d format-cover : 𝕃 char → format-d format-cover ('%' :: 'n' :: s) = format-nat (format-cover s) format-cover ('%' :: 's' :: s) = format-string (format-cover s) format-cover (c :: s) = not-format c (format-cover s) format-cover [] = empty-format format-th : format-d → Set format-th (format-nat v) = ℕ → format-th v format-th (format-string v) = string → format-th v format-th (not-format c v) = format-th v format-th empty-format = string format-t : string → Set format-t s = format-th (format-cover (string-to-𝕃char s)) format-h : 𝕃 char → (d : format-d) → format-th d format-h s (format-nat v) = λ n → format-h (s ++ (string-to-𝕃char (ℕ-to-string n))) v format-h s (format-string v) = λ s' → format-h (s ++ (string-to-𝕃char s')) v format-h s (not-format c v) = format-h (s ++ [ c ] ) v format-h s empty-format = 𝕃char-to-string s format : (f : string) → format-t f format f = format-h [] (format-cover (string-to-𝕃char f)) format-type-test : Set format-type-test = format-t "%n% of the %ss are in the %s %s" format-test : string format-test = format "%n% of the %ss are in the %s %s" 25 "dog" "toasty" "doghouse" format-test-lem : format-test ≡ "25% of the dogs are in the toasty doghouse" format-test-lem = refl
{ "alphanum_fraction": 0.6770833333, "avg_line_length": 34.2857142857, "ext": "agda", "hexsha": "50e162f21eaa93d6b997b583516dc52fdf3436ec", "lang": "Agda", "max_forks_count": 17, "max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z", "max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z", "max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "rfindler/ial", "max_forks_repo_path": "string-format.agda", "max_issues_count": 8, "max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z", "max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "rfindler/ial", "max_issues_repo_path": "string-format.agda", "max_line_length": 85, "max_stars_count": 29, "max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "rfindler/ial", "max_stars_repo_path": "string-format.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z", "max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z", "num_tokens": 571, "size": 1920 }