Search is not available for this dataset
text
string
meta
dict
------------------------------------------------------------------------ -- The Agda standard library -- -- Vectors defined in terms of Data.Star ------------------------------------------------------------------------ module Data.Star.Vec where open import Data.Star open import Data.Star.Nat open import Data.Star.Fin using (Fin) open import Data.Star.Decoration open import Data.Star.Pointer as Pointer hiding (lookup) open import Data.Star.List using (List) open import Relation.Binary open import Relation.Binary.Consequences open import Function open import Data.Unit -- The vector type. Vectors are natural numbers decorated with extra -- information (i.e. elements). Vec : Set → ℕ → Set Vec a = All (λ _ → a) -- Nil and cons. [] : ∀ {a} → Vec a zero [] = ε infixr 5 _∷_ _∷_ : ∀ {a n} → a → Vec a n → Vec a (suc n) x ∷ xs = ↦ x ◅ xs -- Projections. head : ∀ {a n} → Vec a (1# + n) → a head (↦ x ◅ _) = x tail : ∀ {a n} → Vec a (1# + n) → Vec a n tail (↦ _ ◅ xs) = xs -- Append. infixr 5 _++_ _++_ : ∀ {a m n} → Vec a m → Vec a n → Vec a (m + n) _++_ = _◅◅◅_ -- Safe lookup. lookup : ∀ {a n} → Fin n → Vec a n → a lookup i xs with Pointer.lookup i xs ... | result _ x = x ------------------------------------------------------------------------ -- Conversions fromList : ∀ {a} → (xs : List a) → Vec a (length xs) fromList ε = [] fromList (x ◅ xs) = x ∷ fromList xs toList : ∀ {a n} → Vec a n → List a toList = gmap (const tt) decoration
{ "alphanum_fraction": 0.5248468346, "avg_line_length": 22.2575757576, "ext": "agda", "hexsha": "e7e0a53450e704d76ff2f9bc664e1be552cf159a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Data/Star/Vec.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Data/Star/Vec.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Data/Star/Vec.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 440, "size": 1469 }
module Nats.Add.Comm where open import Equality open import Nats open import Function ------------------------------------------------------------------------ -- internal stuffs private a+0=0+a : ∀ a → a + 0 ≡ a a+0=0+a zero = refl a+0=0+a (suc a) = cong suc $ a+0=0+a a ++a+b=a+b++ : ∀ a b → suc (a + b) ≡ a + suc b ++a+b=a+b++ zero b = refl ++a+b=a+b++ (suc a) b = cong suc $ ++a+b=a+b++ a b a+b=b+a : ∀ a b → a + b ≡ b + a a+b=b+a zero b = sym (a+0=0+a b) a+b=b+a (suc a) b = suc (a + b) ≡⟨ cong suc (a+b=b+a a b) ⟩ ++a+b=a+b++ b a ------------------------------------------------------------------------ -- public aliases nat-add-comm : ∀ a b → a + b ≡ b + a nat-add-comm = a+b=b+a
{ "alphanum_fraction": 0.3997214485, "avg_line_length": 24.7586206897, "ext": "agda", "hexsha": "7b6f1464f23ebfe28254b968d1919ba464ff58a6", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ice1k/Theorems", "max_forks_repo_path": "src/Nats/Add/Comm.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ice1k/Theorems", "max_issues_repo_path": "src/Nats/Add/Comm.agda", "max_line_length": 77, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ice1k/Theorems", "max_stars_repo_path": "src/Nats/Add/Comm.agda", "max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z", "num_tokens": 262, "size": 718 }
{-# OPTIONS --no-unicode #-} module Issue2749 where -- testing ascii only lambda and arrow id : {A : Set} -> A -> A id = {!!} -- testing ascii only double braces it : {A : Set} {{a : A}} → A → A it = {!!} data B : Set where mkB : B → B → B -- testing ascii only suffixes left : B → B left b1 = {!!} open import Agda.Builtin.Equality -- testing ascii only forall allq : (∀ m n → m ≡ n) ≡ {!!} allq = refl
{ "alphanum_fraction": 0.5762711864, "avg_line_length": 16.52, "ext": "agda", "hexsha": "8be6cf41490b3fdae28a76085b3d77b66dfbeed1", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/interaction/Issue2749.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/interaction/Issue2749.agda", "max_line_length": 38, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/interaction/Issue2749.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": 137, "size": 413 }
{-# OPTIONS --copatterns --sized-types #-} -- {-# OPTIONS -v tc.size:60 #-} -- {-# OPTIONS -v term:20 -vterm.matrices:40 #-} module SizedTypesMutual where open import Common.Size -- Syntax: Types, terms and contexts. infixr 6 _⇒_ infixl 1 _,_ -- Types and contexts. data Ty : Set where _⇒_ : (a b : Ty) → Ty data Cxt : Set where _,_ : (Γ : Cxt) (a : Ty) → Cxt -- Generic reversed Spines (last application available first). data RSpine (V : Ty → Set) (a : Ty) : (c : Ty) → Set where _,_ : ∀ {b c} → RSpine V a (b ⇒ c) → V b → RSpine V a c -- Functoriality for RSpine mapRSp : ∀ {V W : Ty → Set} → (∀ {d} → V d → W d) → ∀ {a c} → RSpine V a c → RSpine W a c mapRSp f (rs , r) = mapRSp f rs , f r -- Values and environments mutual data Env {i : Size} (Δ : Cxt) : Set where _,_ : ∀ {a} (ρ : Env {i = i} Δ) (v : Val {i = i} Δ a) → Env Δ data Val {i : Size} (Δ : Cxt) : (a : Ty) → Set where ne : ∀ {j : Size< i}{a c} (vs : ValSpine {i = j} Δ a c) → Val Δ c lam : ∀ {a b} (ρ : Env {i = i} Δ) → Val Δ (a ⇒ b) ValSpine : {i : Size} (Δ : Cxt) (a c : Ty) → Set ValSpine {i = i} Δ = RSpine (Val {i = i} Δ) -- Weakening mutual weakEnv : ∀ {i Δ a} → Env {i = i} Δ → Env {i = i} (Δ , a) weakEnv {i = i} (ρ , v) = weakEnv ρ , weakVal v weakVal : ∀ {i Δ a c} → Val {i = i} Δ c → Val {i = i} (Δ , a) c weakVal (ne {j = j} vs) = ne (mapRSp (weakVal {i = j}) vs) weakVal (lam ρ) = lam (weakEnv ρ) -- This mutual block produces garbage size solutions -- if solving is not done on a per-definition basis. -- The reason is that the current solver assumes -- that all size constraints live in (an extension of) -- the same context (which is not true here).
{ "alphanum_fraction": 0.5492468134, "avg_line_length": 27.3968253968, "ext": "agda", "hexsha": "9bb21542935bf78741719d6299e64e246a44d1af", "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/SizedTypesMutual.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/SizedTypesMutual.agda", "max_line_length": 89, "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/SizedTypesMutual.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": 672, "size": 1726 }
module Issue402 where record Unit : Set where constructor inn field out : Unit data _==_ {A : Set}(a : A) : A -> Set where refl : a == a test : (x y : Unit) -> x == y test x y = refl -- this used to cause an infinite loop in the conversion checker -- now it fails, because no eta-laws are generated for the -- unguarded recursive record Unit
{ "alphanum_fraction": 0.6601123596, "avg_line_length": 20.9411764706, "ext": "agda", "hexsha": "1f08f8b2d523c456a4eede6f695c3b48230ba528", "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/Issue402.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/Issue402.agda", "max_line_length": 64, "max_stars_count": 1, "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_path": "test/fail/Issue402.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": 103, "size": 356 }
{-# OPTIONS --safe #-} module Generics.Reflection where open import Function.Base import Data.Unit as ⊤ import Data.Product as Product import Relation.Binary.PropositionalEquality as Eq open import Data.Nat.Base hiding (_⊔_) open import Data.List.Base as List hiding (_++_) import Data.Vec.Base as Vec open import Data.String as S using (String; _++_) open import Data.Bool.Base open import Data.Maybe.Base using (Maybe; just; nothing; maybe) open import Agda.Builtin.Reflection renaming ( primQNameEquality to _Name≈_ ) open import Reflection.Abstraction using (unAbs) open import Reflection.Argument using (_⟨∷⟩_; _⟅∷⟆_) open import Reflection.Term hiding (Telescope; var) open import Relation.Nullary using (yes; no) open import Category.Monad as Monad import Data.List.Categorical as List import Data.Nat.Induction as Nat import Data.Char as C open import Reflection.TypeChecking.Monad.Instances using (tcMonad) open import Reflection.Traversal hiding (_,_) open import Generics.Prelude open import Generics.Telescope open import Generics.Desc renaming (_,_ to _,ω_) import Generics.Accessibility as Accessibility open import Generics.HasDesc import Function.Identity.Categorical as Identity open List.TraversableM ⦃...⦄ open Monad.RawMonad ⦃...⦄ tErr : Term → TC ⊤ tErr = typeError ∘ [_] ∘ termErr sErr : String → TC ⊤ sErr = typeError ∘ [_] ∘ strErr open Actions -- `liftN n f` maps numbers 0..(n-1) to themselves, and numbers -- `n + k` to `n + (f k)` liftN : ℕ → (ℕ → ℕ) → (ℕ → ℕ) liftN zero f k = f k liftN (suc n) f zero = zero liftN (suc n) f (suc k) = suc (liftN n f k) mapVars : (ℕ → ℕ) → Term → Term mapVars f = traverseTerm Identity.applicative actions (0 Reflection.Traversal., []) where actions : Actions Identity.applicative actions .onVar ctx = liftN (ctx .Cxt.len) f actions .onMeta _ = id actions .onCon _ = id actions .onDef _ = id prettyName : Name → String prettyName f = maybe id "" (List.last (S.wordsBy ('.' C.≟_) (showName f))) {- When converting types to telescopes variables are converted to context lookups: Given K := [(oₒ : Oₒ) ⋯ (o₁ : O₁)] "forced" arguments (reversed) P := [A₁ ⋯ Aₙ] parameters I := [B₁ ⋯ Bₘ] indices, we want to replace a term in context (Γ , O₁ , ⋯ , Oₒ , A₁ , ⋯ , Aₙ , B₁ , ⋯ , Bₘ , C₁ , ⋯ , Cₚ) into a term in context (Γ , Σ P I , C₁ , ⋯ , Cₚ) A term (var k) should be replaced by: - (var k) if k < p - (proj₂ (proj₂ (var p))) if p <= k < p + m (inside I) (proj₂ (proj₁ (proj₂ (var p)))) ... (proj₂ (proj₁ (proj₁ (proj₂ (var p))))) ... - (proj₂ (proj₁ (var p)) if p + m <= k < p + m + n (inside P) - (proj₂ (proj₁ (proj₁ (var p))) ... - (proj₂ (proj₁ (proj₁ (proj₁ (var p)))) ... - K[k - (n + m + p)] if p + m + n <= k < p + m + n + o - var (k + 1 - n - m - o) if p + m + n + o <= k -} -- o: position of (PI : Σ P I) in the context -- (i.e number of locally bound variables) mkVar : (o k : ℕ) → Name → List (Arg Term) → Term mkVar o k t args = def (quote proj₂) (aux o k ⟨∷⟩ args) where aux : (o k : ℕ) → Term aux o zero = def t (var o [] ⟨∷⟩ []) aux o (suc k) = def (quote proj₁) (aux o k ⟨∷⟩ []) mkPVar : (o k : ℕ) → List (Arg Term) → Term mkPVar o k = mkVar o k (quote proj₁) mkIVar : (o k : ℕ) → List (Arg Term) → Term mkIVar o k = mkVar o k (quote proj₂) -- TODO: telescopize should account for forced arguments module _ (fargs : List Term) (nP nI : ℕ) where telescopize : ℕ → Term → Term telescopizeSort : ℕ → Sort → Sort telescopizeArgs : ℕ → List (Arg Term) → List (Arg Term) telescopizeTel : ℕ → List (String × Arg Type) → List (String × Arg Type) telescopizeClause : ℕ → List Clause → List Clause lookupForced : List Term → ℕ → ℕ → List (Arg Term) → Term lookupForced [] n o = var (suc (n + o)) -- WARN: we ignore args, this should go alright -- ALSO, we might/should lift everything up, probably lookupForced (x ∷ xs) zero o = const (mapVars (λ n → n + suc o) x) lookupForced (x ∷ xs) (suc n) o = lookupForced xs n o telescopize o (var k args) = let args′ = telescopizeArgs o args in if k <ᵇ o then var k args′ else if k ∸ o <ᵇ nI then mkIVar o (k ∸ o ) args′ else if k ∸ o <ᵇ nI + nP then mkPVar o (k ∸ o ∸ nI) args′ else lookupForced fargs (k ∸ (nI + nP + o)) o args -- else var (k ∸ pred (nP + nI)) args′ telescopize o (con c args) = con c (telescopizeArgs o args) telescopize o (def f args) = def f (telescopizeArgs o args) telescopize o (lam v (abs s t)) = lam v (abs s (telescopize (suc o) t)) telescopize o (pat-lam cs args) = pat-lam (telescopizeClause o cs) (telescopizeArgs o args) telescopize o (Π[ s ∶ arg i a ] b) = Π[ s ∶ arg i (telescopize o a) ] telescopize (suc o) b telescopize o (sort s) = sort (telescopizeSort o s) telescopize o (lit l) = lit l telescopize o (meta x args) = meta x (telescopizeArgs o args) telescopize o unknown = unknown telescopizeSort o (set t) = set (telescopize o t) telescopizeSort o (prop t) = prop (telescopize o t) telescopizeSort o x = x telescopizeArgs o [] = [] telescopizeArgs o (arg i x ∷ xs) = arg i (telescopize o x) ∷ telescopizeArgs o xs telescopizeTel o [] = [] telescopizeTel o ((s , arg i t) ∷ xs) = (s , arg i (telescopize o t)) ∷ telescopizeTel (suc o) xs telescopizeClause o [] = [] telescopizeClause o (clause tel ps t ∷ xs) -- careful: telescopes bring (length tel) variables in scope = clause (telescopizeTel o tel) ps (telescopize (o + length tel) t) ∷ telescopizeClause o xs telescopizeClause o (absurd-clause tel ps ∷ xs) = absurd-clause (telescopizeTel o tel) ps ∷ telescopizeClause o xs -- sanity check private module TelescopizeTests where t : Term t = var 4 [] -- locally bound variable t₁ : Term t₁ = telescopize [] 0 0 5 t t₁-ok : t₁ ≡ var 4 [] t₁-ok = refl -- retrieving var in index telescope, 4 variable locally-bound t₂ : Term t₂ = telescopize [] 2 1 4 t t₂-ok : t₂ ≡ def (quote proj₂) (def (quote proj₂) (var 4 [] ⟨∷⟩ []) ⟨∷⟩ []) t₂-ok = refl -- retrieving var in parameter telescope, 2 variable locally-bound t₃ : Term t₃ = telescopize [] 1 2 2 t t₃-ok : t₃ ≡ def (quote proj₂) (def (quote proj₁) (var 2 [] ⟨∷⟩ []) ⟨∷⟩ []) t₃-ok = refl -- retrieving var outside parameter & index telescope t₄ : Term t₄ = telescopize [] 1 1 2 t t₄-ok : t₄ ≡ var 3 [] t₄-ok = refl -- retrieving 4th var in index telescope t₅ : Term t₅ = telescopize [] 0 5 1 t t₅-ok : t₅ ≡ def (quote proj₂) (def (quote proj₁) (def (quote proj₁) (def (quote proj₁) (def (quote proj₂) (var 1 [] ⟨∷⟩ []) ⟨∷⟩ []) ⟨∷⟩ []) ⟨∷⟩ []) ⟨∷⟩ []) t₅-ok = refl ----------------------------- -- Deriving telescopes getIndexTel : List Term → ℕ → Type → TC Term getIndexTel fargs nP ty = aux ty 0 (con (quote ε) []) where aux : Type → ℕ → Term → TC Term aux (agda-sort s) n I = return I aux (Π[ s ∶ arg i a ] b) n I = do i′ ← quoteTC i >>= normalise aux b (suc n) (con (quote _⊢<_>_) (I ⟨∷⟩ con (quote Product._,_) (lit (string s) ⟨∷⟩ i′ ⟨∷⟩ []) ⟨∷⟩ vLam "PI" (telescopize fargs nP n 0 a) ⟨∷⟩ [])) aux _ _ _ = typeError [ strErr "ill-formed type signature when deriving index telescope" ] getTels : List Term → ℕ → Type → TC (Term × Term) getTels fargs nP ty = aux nP ty 0 (quoteTerm (ε {A = ⊤})) where aux : ℕ → Type → ℕ → Term → TC (Term × Term) aux zero ty _ P = (P ,_) <$> getIndexTel fargs nP ty aux (suc nP) (Π[ s ∶ arg i a ] b) n P = do i′ ← quoteTC i >>= normalise aux nP b (suc n) (con (quote _⊢<_>_) (P ⟨∷⟩ con (quote Product._,_) (lit (string s) ⟨∷⟩ i′ ⟨∷⟩ []) ⟨∷⟩ vLam "PI" (telescopize fargs 0 n 0 a) ⟨∷⟩ [])) aux _ _ _ _ = typeError [ strErr "ill-formed type signature when deriving parameter telescope" ] ----------------------------- -- Deriving descriptions -- we cannot unquote things in Setω directly -- so we can't unquote Terms of type Telescope directly -- instead we produce skeletons to ease code generation data Skel : Set where Cκ : Skel Cπ : ArgInfo → Skel → Skel _C⊗_ : Skel → Skel → Skel dropPis : ℕ → Type → Type dropPis (suc n) (pi a (abs _ b)) = dropPis n b dropPis _ t = t module _ (fargs : List Term) (dt : Name) (nP : ℕ) where toIndex : ℕ → List (Arg Term) → Term toIndex nV xs = vLam "PV" $ foldl cons (quoteTerm ⊤.tt) (drop (nP + List.length fargs) xs) where cons : Term → Arg Term → Term cons x (arg _ y) = con (quote Product._,_) ( x ⟨∷⟩ telescopize fargs nP nV 0 y ⟨∷⟩ []) getRecDesc : ℕ → Type → TC (Maybe (Term × Skel)) getRecDesc n (def nm args) = do if nm Name≈ dt then return (just (con (quote ConDesc.var) (toIndex n args ⟨∷⟩ []) , Cκ)) else return nothing getRecDesc n (Π[ s ∶ arg i a ] b) = do getRecDesc (suc n) b >>= λ where (just (right , skright)) → do i′ ← quoteTC i >>= normalise return $ just ( con (quote ConDesc.π) (con (quote Product._,_) (lit (string s) ⟨∷⟩ i′ ⟨∷⟩ []) ⟨∷⟩ vLam "PV" (telescopize fargs nP n 0 a) ⟨∷⟩ right ⟨∷⟩ []) , Cπ i skright ) nothing → return nothing getRecDesc n ty = return nothing getDesc : (ℕ → ℕ) → ℕ → Type → TC (Term × Skel) getDesc f n (def nm args) = -- we're gonna assume nm == dt -- TODO: why does this work??? -- surely args contain parameters return (con (quote ConDesc.var) (toIndex n (List.map (Arg.map (mapVars f)) args) ⟨∷⟩ []) , Cκ) getDesc f n (Π[ s ∶ arg i a ] b) = getRecDesc n (mapVars f a) >>= λ where -- (possibly higher order) inductive argument (just (left , skleft)) → do -- we cannot depend on inductive argument (for now) -- note: inductive arguments are relevant (for now) -- /!\ inductive arguments to not bind a variable, so we strengthen the term (right , skright) ← getDesc ((_- 1) ∘ f) n b return (con (quote ConDesc._⊗_) (left ⟨∷⟩ right ⟨∷⟩ []) , (skleft C⊗ skright)) -- plain old argument nothing → do (right , skright) ← getDesc (liftN 1 f) (suc n) b i′ ← quoteTC i >>= normalise return ( con (quote ConDesc.π) (con (quote Product._,_) (lit (string s) ⟨∷⟩ i′ ⟨∷⟩ []) ⟨∷⟩ vLam "PV" (telescopize fargs nP n 0 a) ⟨∷⟩ right ⟨∷⟩ []) , Cπ i skright ) getDesc _ _ _ = typeError [ strErr "ill-formed constructor type" ] -- TODO: the reason we do this is that I've failed to make the PI arguments -- implicit in the reflection code record HD {P} {I : ExTele P} {ℓ} (A : Indexed P I ℓ) : Setω where constructor mkHD A′ : ⟦ P , I ⟧xtel → Set ℓ A′ = uncurry P I A field {n} : ℕ D : DataDesc P I n names : Vec String n constr : ∀ pi → ⟦ D ⟧Data A′ pi → A′ pi split : ∀ pi → A′ pi → ⟦ D ⟧Data A′ pi split∘constr : ∀ pi → (x : ⟦ D ⟧Data A′ pi) → split pi (constr pi x) ≡ω x constr∘split : ∀ pi → (x : A′ pi ) → constr pi (split pi x) ≡ x open Accessibility A D (λ {pi} → split pi) field wf : ∀ pi (x : A′ pi) → Acc x badconvert : ∀ {P} {I : ExTele P} {ℓ} {A : Indexed P I ℓ} → HD {P} {I} {ℓ} A → HasDesc {P} {I} {ℓ} A badconvert d = record { D = HD.D d ; names = HD.names d ; constr = λ {PI} → HD.constr d PI ; split = λ {PI} → HD.split d PI ; split∘constr = λ {PI} → HD.split∘constr d PI ; constr∘split = λ {PI} → HD.constr∘split d PI ; wf = λ {PI} → HD.wf d PI } withAI : ArgInfo → Term → Term withAI i t with relevance i ... | relevant = t ... | irrelevant = con (quote irrv) [ vArg t ] patAI : ArgInfo → Pattern → Pattern patAI i t with relevance i ... | relevant = t ... | irrelevant = con (quote irrv) [ vArg t ] deriveThings : (gargs : List (Arg Term)) (nP : ℕ) (qconstr qsplit qsplitconstr qconstrsplit qwf : Name) (cons : List (Name × Skel)) → TC ⊤ deriveThings gargs nP qconstr qsplit qsplitconstr qconstrsplit qwf cons = do let clauses = deriveDef cons -- TODO: use some n-ary magic let (constr_cls , rest ) = unzip clauses let (split_cls , rest ) = unzip rest let (splitconstr_cls , rest ) = unzip rest let (constrsplit_cls , wf_cls) = unzip rest defineFun qconstr constr_cls defineFun qsplit split_cls defineFun qsplitconstr splitconstr_cls defineFun qconstrsplit constrsplit_cls defineFun qwf wf_cls where deriveIndArg : Skel → ℕ × List (String × Arg Type) × List (Arg Pattern) × List (Arg Term) deriveIndArg Cκ = 0 , [] , [] , [] deriveIndArg (Cπ ia C) = let (o , tel , pat , args) = deriveIndArg C in suc o , ("x" , vArg unknown) ∷ tel , arg ia (var o) ∷ pat , arg ia (var o []) ∷ args -- WARNING: intentionally wrong, never used when deriving descriptions deriveIndArg (A C⊗ B) = 0 , [] , [] , [] deriveCon : Skel → ℕ × List (String × Arg Type) -- variable types × Pattern -- pattern for ⟦_⟧Data × List (Arg Pattern) -- pattern for arguments of A′ cons × List (Arg Term) -- arguments for constructor × Term -- return value for split × Term -- body of wf deriveCon Cκ = 0 , [] -- we bind zero vars , con (quote Eq.refl) [] , [] , [] , con (quote Eq.refl) [] , def (quote ttω) [] deriveCon (Cπ ia C) = let (o , vars , datapat , apat , cargs , sval , wfval) = deriveCon C in suc o , ("s" , arg ia unknown) ∷ vars -- TODO: unsure about ia here , con (quote Product._,_) (patAI ia (var o) ⟨∷⟩ datapat ⟨∷⟩ []) , arg ia (var o) ∷ apat , arg ia (var o []) ∷ cargs , con (quote Product._,_) (withAI ia (var o []) ⟨∷⟩ sval ⟨∷⟩ []) , wfval deriveCon (A C⊗ B) = let (ro , rtel , rpat , rargs) = deriveIndArg A in let (o , vars , datapat , apat , cargs , sval , wfval) = deriveCon B in suc o , ("x" , vArg unknown) ∷ vars -- we only support visible relevant inductive args , con (quote Product._,_) (var o ⟨∷⟩ datapat ⟨∷⟩ []) , var o ⟨∷⟩ apat , var o [] ⟨∷⟩ cargs , con (quote Product._,_) (var o [] ⟨∷⟩ sval ⟨∷⟩ []) , def (quote _ω,ω_) (pat-lam [ clause rtel rpat (def qwf (unknown -- PI of inductive argument ⟨∷⟩ var (o + ro) rargs ⟨∷⟩ [])) ] [] ⟨∷⟩ wfval ⟨∷⟩ []) -- TODOOOO deriveClause : Pattern → Term → Name × Skel → Clause × Clause × Clause × Clause × Clause deriveClause kp kt (consname , shape) = let (o , vars , datapat , apat , cargs , sval , wfval) = deriveCon shape in clause (("pi" , vArg unknown) ∷ vars) (var o ⟨∷⟩ con (quote _,ω_) (kp ⟨∷⟩ datapat ⟨∷⟩ []) ⟨∷⟩ []) (con consname (nP ⋯⟅∷⟆ cargs)) -- TODO: maybe forced args go here , clause (("pi" , vArg unknown) ∷ vars) (var o ⟨∷⟩ con consname apat ⟨∷⟩ []) (con (quote _,ω_) (kt ⟨∷⟩ sval ⟨∷⟩ [])) , clause (("pi" , vArg unknown) ∷ vars) (var o ⟨∷⟩ con (quote _,ω_) (kp ⟨∷⟩ datapat ⟨∷⟩ []) ⟨∷⟩ []) (def (quote reflω) []) , clause (("pi" , vArg unknown) ∷ vars) (var o ⟨∷⟩ con consname apat ⟨∷⟩ []) (con (quote Eq.refl) []) , clause (("pi" , vArg unknown) ∷ vars) (var o ⟨∷⟩ con consname apat ⟨∷⟩ []) (con (quote Accessibility.Acc.acc) (wfval ⟨∷⟩ [])) deriveClauses : Pattern -- pattern for index of constructor → Term -- term for index constructor → List (Name × Skel) → List (Clause × Clause × Clause × Clause × Clause) deriveClauses _ _ [] = [] deriveClauses kp kt (x ∷ xs) = deriveClause kp kt x ∷ deriveClauses (con (quote Fin.suc) (kp ⟨∷⟩ [])) (con (quote Fin.suc) (kt ⟨∷⟩ [])) xs deriveDef : List (Name × Skel) → List (Clause × Clause × Clause × Clause × Clause) deriveDef [] = [ cls , cls , cls , cls , cls ] where cls = absurd-clause (("PI" , hArg unknown) ∷ ("x" , vArg unknown) ∷ []) (var 1 ⟨∷⟩ absurd 0 ⟨∷⟩ [] ) deriveDef xs = deriveClauses (con (quote Fin.zero) []) (con (quote Fin.zero) []) xs macro deriveDesc : Term → Term → TC ⊤ deriveDesc t hole = do -- Arguments are used for enabling universe-polymorphic defintions -- these arguments should be prepended to every use of nm as a type def nm gargs ← return t where _ → typeError [ strErr "Expected name with arguments." ] let fargs = reverse (List.map Arg.unArg gargs) data-type nP cs ← getDefinition nm where _ → typeError [ strErr "Name given is not a datatype." ] let nCons = List.length cs let nArgs = List.length gargs names ← quoteTC (Vec.fromList (List.map prettyName cs)) -- we get the type of the family, with the provided arguments removed ty ← getType nm >>= normalise <&> dropPis nArgs >>= normalise -- (nP - nArgs) is the amount of actual parameters we consider in our encoding -- the remaining Pi types are indices (P , I) ← getTels fargs (nP - nArgs) ty descs&skels ← forM cs λ cn → do -- get the type of current constructor, with explicit arguments and parameters stripped conTyp ← getType cn >>= normalise <&> dropPis nP (desc , skel) ← getDesc fargs nm (nP - nArgs) id 0 conTyp return $ (cn , skel) , desc let descs = List.map proj₂ descs&skels let skels = List.map proj₁ descs&skels let D = foldr (λ C D → con (quote DataDesc._∷_) (C ⟨∷⟩ D ⟨∷⟩ [])) (con (quote DataDesc.[]) []) descs qconstr ← freshName "constr" qsplit ← freshName "split" qsplitconstr ← freshName "split∘constr" qconstrsplit ← freshName "constr∘split" qwf ← freshName "wf" declareDef (vArg qconstr) (pi (vArg (def (quote ⟦_,_⟧xtel) (P ⟨∷⟩ I ⟨∷⟩ []))) (abs "PI" (pi (vArg unknown) (abs "x" unknown)))) declareDef (vArg qsplit) (pi (vArg (def (quote ⟦_,_⟧xtel) (P ⟨∷⟩ I ⟨∷⟩ []))) (abs "PI" (pi (vArg unknown) (abs "x" unknown)))) declareDef (vArg qconstrsplit) (pi (vArg (def (quote ⟦_,_⟧xtel) (P ⟨∷⟩ I ⟨∷⟩ []))) (abs "PI" (pi (vArg unknown) (abs "x" unknown)))) declareDef (vArg qsplitconstr) (pi (vArg (def (quote ⟦_,_⟧xtel) (P ⟨∷⟩ I ⟨∷⟩ []))) (abs "PI" (pi (vArg unknown) (abs "x" unknown)))) declareDef (vArg qwf) (pi (vArg (def (quote ⟦_,_⟧xtel) (P ⟨∷⟩ I ⟨∷⟩ []))) (abs "PI" (pi (vArg unknown) (abs "x" unknown)))) deriveThings gargs (nP - nArgs) qconstr qsplit qsplitconstr qconstrsplit qwf skels unify hole (def (quote badconvert) ((con (quote mkHD) ( P -- P ⟅∷⟆ I -- I ⟅∷⟆ unknown -- ℓ ⟅∷⟆ def nm gargs -- A ⟅∷⟆ lit (nat nCons) -- n ⟅∷⟆ D -- D ⟨∷⟩ names -- names ⟨∷⟩ def qconstr [] ⟨∷⟩ def qsplit [] ⟨∷⟩ def qsplitconstr [] ⟨∷⟩ def qconstrsplit [] ⟨∷⟩ def qwf [] ⟨∷⟩ [])) ⟨∷⟩ []))
{ "alphanum_fraction": 0.5352607931, "avg_line_length": 37.9888682746, "ext": "agda", "hexsha": "22568721623b7f733ff899ee8e0dd1ea178578f5", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "flupe/generics", "max_forks_repo_path": "src/Generics/Reflection.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "flupe/generics", "max_issues_repo_path": "src/Generics/Reflection.agda", "max_line_length": 104, "max_stars_count": 11, "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "flupe/generics", "max_stars_repo_path": "src/Generics/Reflection.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "num_tokens": 6736, "size": 20476 }
{-# OPTIONS --without-K --safe #-} -- This module shows that D<: subtyping without transitivity, or equivalently, without -- bad bounds, remains undecidable. module DsubNoTrans where open import Data.List as List open import Data.List.All as All open import Data.Nat as ℕ open import Data.Maybe as Maybe open import Data.Product open import Data.Sum open import Data.Empty renaming (⊥ to False) open import Data.Vec as Vec renaming (_∷_ to _‼_ ; [] to nil) hiding (_++_) open import Function open import Data.Maybe.Properties as Maybeₚ open import Data.Nat.Properties as ℕₚ open import Relation.Nullary open import Relation.Binary.PropositionalEquality as ≡ open import Induction.Nat open import DsubDef open import DsubReduced open import FsubMinus open import FsubMinus2 open import Utils infix 4 _⊢_<:_ data _⊢_<:_ : Env → Typ → Typ → Set where <:⊤ : ∀ {Γ T} → Γ ⊢ T <: ⊤ ⊥<: : ∀ {Γ T} → Γ ⊢ ⊥ <: T refl : ∀ {Γ T} → Γ ⊢ T <: T bnd : ∀ {Γ S U S′ U′} → Γ ⊢ S′ <: S → Γ ⊢ U <: U′ → Γ ⊢ ⟨A: S ⋯ U ⟩ <: ⟨A: S′ ⋯ U′ ⟩ Π<: : ∀ {Γ S U S′ U′} → Γ ⊢ S′ <: S → Γ ‣ S′ ! ⊢ U <: U′ → Γ ⊢ Π S ∙ U <: Π S′ ∙ U′ sel₁ : ∀ {Γ n T S} → env-lookup Γ n ≡ just T → Γ ⊢ T <: ⟨A: S ⋯ ⊤ ⟩ → Γ ⊢ S <: n ∙A sel₂ : ∀ {Γ n T U} → env-lookup Γ n ≡ just T → Γ ⊢ T <: ⟨A: ⊥ ⋯ U ⟩ → Γ ⊢ n ∙A <: U module Contravariant where open InvertibleProperties contraInvertible _⊢_<:_ public D⇒Dᵢ : ∀ {Γ S U} → Γ ⊢ S <: U → ContraEnv Γ → Γ ⊢ᵢ S <: U D⇒Dᵢ <:⊤ all = ditop D⇒Dᵢ ⊥<: all = dibot D⇒Dᵢ refl all = direfl D⇒Dᵢ (bnd S′<:S U<:U′) all = dibnd (D⇒Dᵢ S′<:S all) (D⇒Dᵢ U<:U′ all) D⇒Dᵢ (Π<: S′<:S U<:U′) all = diall (D⇒Dᵢ S′<:S all) U<:U′ D⇒Dᵢ (sel₁ T∈Γ S<:U) all with lookupContraEnv T∈Γ all ... | ctt _ with ⟨A:⟩<:⟨A:⟩ (D⇒Dᵢ S<:U all) all ... | S<:⊥ , _ with <:⊥ S<:⊥ all ... | refl = dibot D⇒Dᵢ (sel₂ T∈Γ S<:U) all with lookupContraEnv T∈Γ all ... | ctt _ with ⟨A:⟩<:⟨A:⟩ (D⇒Dᵢ S<:U all) all ... | _ , U′<:U = ditrans _ (disel T∈Γ) U′<:U module Undecidability′ where open FsubMinusToDsubR open Contravariant hiding (Π<:) ⟨A:⊥⟩<:-lb : ∀ {Γ T S U} → Γ ⊢ ⟨A: ⊥ ⋯ T ⟩ <: ⟨A: S ⋯ U ⟩ → ContraEnv Γ → S ≡ ⊥ ⟨A:⊥⟩<:-lb D cΓ with ⟨A:⟩<:⟨A:⟩ (D⇒Dᵢ D cΓ) cΓ ... | S<:⊥ , _ with <:⊥ S<:⊥ cΓ ... | S≡⊥ = S≡⊥ <:⇒<:ᵣ : ∀ {Γ S U} → Γ ⊢ S <: U → ContraEnv Γ → Covar S → Covar U → Γ ⊢ᵣ S <: U <:⇒<:ᵣ <:⊤ cΓ cS cU = drtop cS <:⇒<:ᵣ ⊥<: cΓ () cU <:⇒<:ᵣ refl cΓ cS cU = drrefl cU <:⇒<:ᵣ (bnd S′<:S U<:U′) cΓ cS () <:⇒<:ᵣ (Π<: <:⊤ U<:U′) cΓ () cU <:⇒<:ᵣ (Π<: ⊥<: U<:U′) cΓ cS () <:⇒<:ᵣ (Π<: refl U<:U′) cΓ (cvΠ cS cU) (cvΠ cS′ cU′) = drall cS′ cU cS′ cU′ (drrefl cS′) (<:⇒<:ᵣ U<:U′ (ctt cS′ ∷ cΓ) cU cU′) <:⇒<:ᵣ (Π<: (bnd _ S′<:S) U<:U′) cΓ (cvΠ cS cU) (cvΠ cS′ cU′) = drall cS cU cS′ cU′ (<:⇒<:ᵣ S′<:S cΓ cS′ cS) (<:⇒<:ᵣ U<:U′ (ctt cS′ ∷ cΓ) cU cU′) <:⇒<:ᵣ (Π<: (Π<: S′<:S S′<:S₁) U<:U′) cΓ () cU <:⇒<:ᵣ (Π<: (sel₁ x S′<:S) U<:U′) cΓ () cU <:⇒<:ᵣ (Π<: (sel₂ x S′<:S) U<:U′) cΓ cS () <:⇒<:ᵣ (sel₁ T∈Γ T<:B) cΓ cS cU with lookupContraEnv T∈Γ cΓ ... | ctt _ with ⟨A:⊥⟩<:-lb T<:B cΓ ... | refl = case cS of λ () <:⇒<:ᵣ (sel₂ T∈Γ T<:B) cΓ cS cU with lookupContraEnv T∈Γ cΓ ... | ctt cT = drsel T∈Γ cT (aux T<:B cΓ cT cU) where aux : ∀ {Γ T S U} → Γ ⊢ ⟨A: ⊥ ⋯ T ⟩ <: ⟨A: S ⋯ U ⟩ → ContraEnv Γ → Covar T → Covar U → Γ ⊢ᵣ T <: U aux refl cΓ cT cU = drrefl cU aux (bnd _ T<:U) cΓ cT cU = <:⇒<:ᵣ T<:U cΓ cT cU <:ᵣ⇒<: : ∀ {Γ S U} → Γ ⊢ᵣ S <: U → Γ ⊢ S <: U <:ᵣ⇒<: (drtop _) = <:⊤ <:ᵣ⇒<: (drrefl _) = refl <:ᵣ⇒<: (drall _ _ _ _ S′<:S U<:U′) = Π<: (bnd ⊥<: (<:ᵣ⇒<: S′<:S)) (<:ᵣ⇒<: U<:U′) <:ᵣ⇒<: (drsel T∈Γ _ T<:B) = sel₂ T∈Γ (bnd ⊥<: (<:ᵣ⇒<: T<:B)) open FsubMinus.FsubMinus F<:⇒D<: : ∀ {Γ S U} → Γ ⊢F S <: U → ⟪ Γ ⟫ ⊢ ⟦ S ⟧ <: ⟦ U ⟧ F<:⇒D<: = <:ᵣ⇒<: ∘ F<:⇒D<:ᵣ D<:⇒F<: : ∀ {Γ S U} → ⟪ Γ ⟫ ⊢ ⟦ S ⟧ <: ⟦ U ⟧ → Γ ⊢F S <: U D<:⇒F<: S<:U = D<:ᵣ⇒F<: (<:⇒<:ᵣ S<:U (⟪⟫-contraEnv _) (⟦⟧-covar _) (⟦⟧-covar _)) refl refl refl
{ "alphanum_fraction": 0.3983739837, "avg_line_length": 39.6446280992, "ext": "agda", "hexsha": "cb08e4a6cfc551af9917f5f1776381f484ad9424", "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": "48214a55ebb484fd06307df4320813d4a002535b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "HuStmpHrrr/popl20-artifact", "max_forks_repo_path": "agda/DsubNoTrans.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b", "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": "HuStmpHrrr/popl20-artifact", "max_issues_repo_path": "agda/DsubNoTrans.agda", "max_line_length": 108, "max_stars_count": 1, "max_stars_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "HuStmpHrrr/popl20-artifact", "max_stars_repo_path": "agda/DsubNoTrans.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-23T08:40:28.000Z", "max_stars_repo_stars_event_min_datetime": "2021-09-23T08:40:28.000Z", "num_tokens": 2418, "size": 4797 }
{- This file contains: - Properties of set truncations -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.SetTruncation.Properties where open import Cubical.HITs.SetTruncation.Base open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Univalence open import Cubical.Data.Sigma private variable ℓ ℓ' : Level A B C D : Type ℓ rec : isSet B → (A → B) → ∥ A ∥₂ → B rec Bset f ∣ x ∣₂ = f x rec Bset f (squash₂ x y p q i j) = Bset _ _ (cong (rec Bset f) p) (cong (rec Bset f) q) i j rec2 : isSet C → (A → B → C) → ∥ A ∥₂ → ∥ B ∥₂ → C rec2 Cset f ∣ x ∣₂ ∣ y ∣₂ = f x y rec2 Cset f ∣ x ∣₂ (squash₂ y z p q i j) = Cset _ _ (cong (rec2 Cset f ∣ x ∣₂) p) (cong (rec2 Cset f ∣ x ∣₂) q) i j rec2 Cset f (squash₂ x y p q i j) z = Cset _ _ (cong (λ a → rec2 Cset f a z) p) (cong (λ a → rec2 Cset f a z) q) i j -- Old version: -- rec2 Cset f = rec (isSetΠ λ _ → Cset) λ x → rec Cset (f x) -- lemma 6.9.1 in HoTT book elim : {B : ∥ A ∥₂ → Type ℓ} (Bset : (x : ∥ A ∥₂) → isSet (B x)) (f : (a : A) → B (∣ a ∣₂)) (x : ∥ A ∥₂) → B x elim Bset f ∣ a ∣₂ = f a elim Bset f (squash₂ x y p q i j) = isOfHLevel→isOfHLevelDep 2 Bset _ _ (cong (elim Bset f) p) (cong (elim Bset f) q) (squash₂ x y p q) i j elim2 : {C : ∥ A ∥₂ → ∥ B ∥₂ → Type ℓ} (Cset : ((x : ∥ A ∥₂) (y : ∥ B ∥₂) → isSet (C x y))) (f : (a : A) (b : B) → C ∣ a ∣₂ ∣ b ∣₂) (x : ∥ A ∥₂) (y : ∥ B ∥₂) → C x y elim2 Cset f ∣ x ∣₂ ∣ y ∣₂ = f x y elim2 Cset f ∣ x ∣₂ (squash₂ y z p q i j) = isOfHLevel→isOfHLevelDep 2 (λ a → Cset ∣ x ∣₂ a) _ _ (cong (elim2 Cset f ∣ x ∣₂) p) (cong (elim2 Cset f ∣ x ∣₂) q) (squash₂ y z p q) i j elim2 Cset f (squash₂ x y p q i j) z = isOfHLevel→isOfHLevelDep 2 (λ a → Cset a z) _ _ (cong (λ a → elim2 Cset f a z) p) (cong (λ a → elim2 Cset f a z) q) (squash₂ x y p q) i j -- Old version: -- elim2 Cset f = elim (λ _ → isSetΠ (λ _ → Cset _ _)) -- (λ a → elim (λ _ → Cset _ _) (f a)) -- TODO: generalize elim3 : {B : (x y z : ∥ A ∥₂) → Type ℓ} (Bset : ((x y z : ∥ A ∥₂) → isSet (B x y z))) (g : (a b c : A) → B ∣ a ∣₂ ∣ b ∣₂ ∣ c ∣₂) (x y z : ∥ A ∥₂) → B x y z elim3 Bset g = elim2 (λ _ _ → isSetΠ (λ _ → Bset _ _ _)) (λ a b → elim (λ _ → Bset _ _ _) (g a b)) map : (A → B) → ∥ A ∥₂ → ∥ B ∥₂ map f = rec squash₂ λ x → ∣ f x ∣₂ setTruncUniversal : isSet B → (∥ A ∥₂ → B) ≃ (A → B) setTruncUniversal {B = B} Bset = isoToEquiv (iso (λ h x → h ∣ x ∣₂) (rec Bset) (λ _ → refl) rinv) where rinv : (f : ∥ A ∥₂ → B) → rec Bset (λ x → f ∣ x ∣₂) ≡ f rinv f i x = elim (λ x → isProp→isSet (Bset (rec Bset (λ x → f ∣ x ∣₂) x) (f x))) (λ _ → refl) x i setTruncIsSet : isSet ∥ A ∥₂ setTruncIsSet a b p q = squash₂ a b p q setTruncIdempotent≃ : isSet A → ∥ A ∥₂ ≃ A setTruncIdempotent≃ {A = A} hA = isoToEquiv f where f : Iso ∥ A ∥₂ A Iso.fun f = rec hA (idfun A) Iso.inv f x = ∣ x ∣₂ Iso.rightInv f _ = refl Iso.leftInv f = elim (λ _ → isSet→isGroupoid setTruncIsSet _ _) (λ _ → refl) setTruncIdempotent : isSet A → ∥ A ∥₂ ≡ A setTruncIdempotent hA = ua (setTruncIdempotent≃ hA) isContr→isContrSetTrunc : isContr A → isContr (∥ A ∥₂) isContr→isContrSetTrunc contr = ∣ fst contr ∣₂ , elim (λ _ → isOfHLevelPath 2 (setTruncIsSet) _ _) λ a → cong ∣_∣₂ (snd contr a) setTruncIso : Iso A B → Iso ∥ A ∥₂ ∥ B ∥₂ Iso.fun (setTruncIso is) = rec setTruncIsSet (λ x → ∣ Iso.fun is x ∣₂) Iso.inv (setTruncIso is) = rec setTruncIsSet (λ x → ∣ Iso.inv is x ∣₂) Iso.rightInv (setTruncIso is) = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ a → cong ∣_∣₂ (Iso.rightInv is a) Iso.leftInv (setTruncIso is) = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ a → cong ∣_∣₂ (Iso.leftInv is a) setSigmaIso : {B : A → Type ℓ} → Iso ∥ Σ A B ∥₂ ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ setSigmaIso {A = A} {B = B} = iso fun funinv sect retr where {- writing it out explicitly to avoid yellow highlighting -} fun : ∥ Σ A B ∥₂ → ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ fun = rec setTruncIsSet λ {(a , p) → ∣ a , ∣ p ∣₂ ∣₂} funinv : ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ → ∥ Σ A B ∥₂ funinv = rec setTruncIsSet (λ {(a , p) → rec setTruncIsSet (λ p → ∣ a , p ∣₂) p}) sect : section fun funinv sect = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ { (a , p) → elim {B = λ p → fun (funinv ∣ a , p ∣₂) ≡ ∣ a , p ∣₂} (λ p → isOfHLevelPath 2 setTruncIsSet _ _) (λ _ → refl) p } retr : retract fun funinv retr = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ { _ → refl } sigmaElim : {B : ∥ A ∥₂ → Type ℓ} {C : Σ ∥ A ∥₂ B → Type ℓ'} (Bset : (x : Σ ∥ A ∥₂ B) → isSet (C x)) (g : (a : A) (b : B ∣ a ∣₂) → C (∣ a ∣₂ , b)) (x : Σ ∥ A ∥₂ B) → C x sigmaElim {B = B} {C = C} set g (x , y) = elim {B = λ x → (y : B x) → C (x , y)} (λ _ → isSetΠ λ _ → set _) g x y sigmaProdElim : {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ} {D : Σ (∥ A ∥₂ × ∥ B ∥₂) C → Type ℓ'} (Bset : (x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → isSet (D x)) (g : (a : A) (b : B) (c : C (∣ a ∣₂ , ∣ b ∣₂)) → D ((∣ a ∣₂ , ∣ b ∣₂) , c)) (x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → D x sigmaProdElim {B = B} {C = C} {D = D} set g ((x , y) , c) = elim {B = λ x → (y : ∥ B ∥₂) (c : C (x , y)) → D ((x , y) , c)} (λ _ → isSetΠ λ _ → isSetΠ λ _ → set _) (λ x → elim (λ _ → isSetΠ λ _ → set _) (g x)) x y c prodElim : {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ} → ((x : ∥ A ∥₂ × ∥ B ∥₂) → isSet (C x)) → ((a : A) (b : B) → C (∣ a ∣₂ , ∣ b ∣₂)) → (x : ∥ A ∥₂ × ∥ B ∥₂) → C x prodElim setC f (a , b) = elim2 (λ x y → setC (x , y)) f a b prodRec : {C : Type ℓ} → isSet C → (A → B → C) → ∥ A ∥₂ × ∥ B ∥₂ → C prodRec setC f (a , b) = rec2 setC f a b prodElim2 : {E : (∥ A ∥₂ × ∥ B ∥₂) → (∥ C ∥₂ × ∥ D ∥₂) → Type ℓ} → ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → isSet (E x y)) → ((a : A) (b : B) (c : C) (d : D) → E (∣ a ∣₂ , ∣ b ∣₂) (∣ c ∣₂ , ∣ d ∣₂)) → ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → (E x y)) prodElim2 isset f = prodElim (λ _ → isSetΠ λ _ → isset _ _) λ a b → prodElim (λ _ → isset _ _) λ c d → f a b c d setTruncOfProdIso : Iso ∥ A × B ∥₂ (∥ A ∥₂ × ∥ B ∥₂) Iso.fun setTruncOfProdIso = rec (isSet× setTruncIsSet setTruncIsSet) λ { (a , b) → ∣ a ∣₂ , ∣ b ∣₂ } Iso.inv setTruncOfProdIso = prodRec setTruncIsSet λ a b → ∣ a , b ∣₂ Iso.rightInv setTruncOfProdIso = prodElim (λ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _) λ _ _ → refl Iso.leftInv setTruncOfProdIso = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ {(a , b) → refl} IsoSetTruncateSndΣ : {A : Type ℓ} {B : A → Type ℓ'} → Iso ∥ Σ A B ∥₂ ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ Iso.fun IsoSetTruncateSndΣ = map λ a → (fst a) , ∣ snd a ∣₂ Iso.inv IsoSetTruncateSndΣ = rec setTruncIsSet (uncurry λ x → map λ b → x , b) Iso.rightInv IsoSetTruncateSndΣ = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) (uncurry λ a → elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ _ → refl) Iso.leftInv IsoSetTruncateSndΣ = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ _ → refl
{ "alphanum_fraction": 0.5126726566, "avg_line_length": 39.8770053476, "ext": "agda", "hexsha": "cfed4cf9006434f0d3fd64f6e533325e22e8811d", "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": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ayberkt/cubical", "max_forks_repo_path": "Cubical/HITs/SetTruncation/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f", "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": "ayberkt/cubical", "max_issues_repo_path": "Cubical/HITs/SetTruncation/Properties.agda", "max_line_length": 100, "max_stars_count": null, "max_stars_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ayberkt/cubical", "max_stars_repo_path": "Cubical/HITs/SetTruncation/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3423, "size": 7457 }
open import Relation.Binary using (Rel) open import Algebra.Bundles using (CommutativeRing) open import Normed module Beside {r ℓr} {CR : CommutativeRing r ℓr} (open CommutativeRing CR using () renaming (Carrier to X)) {rel} {_≤_ : Rel X rel} {ma ℓma} (MA : NormedModule CR _≤_ ma ℓma) {mb ℓmb} (MB : NormedModule CR _≤_ mb ℓmb) {mc ℓmc} (MC : NormedModule CR _≤_ mc ℓmc) {md ℓmd} (MD : NormedModule CR _≤_ md ℓmd) where open import Data.Product using (_,_; map) open import Function using (_∘_) open CommutativeRing CR open import Limit using (D[_,_][_,_]) open import Assume using (assume) private MAC = directProduct MA MC MBD = directProduct MB MD module MA = NormedModule MA module MB = NormedModule MB module MC = NormedModule MC module MD = NormedModule MD module MAC = NormedModule MAC module MBD = NormedModule MBD ⊗-differentiable-at : ∀ {f g x y} → D[ MA , MB ][ f , x ] → D[ MC , MD ][ g , y ] → D[ MAC , MBD ][ map f g , (x , y) ] ⊗-differentiable-at (f' , _) (g' , _) = (λ (x , y) (dx , dy) → f' x dx , g' y dy) , assume
{ "alphanum_fraction": 0.6527001862, "avg_line_length": 29.8333333333, "ext": "agda", "hexsha": "f3c1901d096aeca5c7919e4cf86a3c7eb332601a", "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": "78c3dec24834ffeca5e74cb75578e9b210a5be62", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "cspollard/diff", "max_forks_repo_path": "src/Beside.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "78c3dec24834ffeca5e74cb75578e9b210a5be62", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "cspollard/diff", "max_issues_repo_path": "src/Beside.agda", "max_line_length": 119, "max_stars_count": null, "max_stars_repo_head_hexsha": "78c3dec24834ffeca5e74cb75578e9b210a5be62", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "cspollard/diff", "max_stars_repo_path": "src/Beside.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 392, "size": 1074 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties satisfied by total orders ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Relation.Binary.Properties.TotalOrder {t₁ t₂ t₃} (T : TotalOrder t₁ t₂ t₃) where open TotalOrder T open import Data.Sum.Base using (inj₁; inj₂) import Relation.Binary.Construct.Converse as Converse import Relation.Binary.Construct.NonStrictToStrict _≈_ _≤_ as ToStrict import Relation.Binary.Properties.Poset poset as PosetProperties open import Relation.Binary.Consequences open import Relation.Nullary using (¬_) open import Relation.Nullary.Negation using (contradiction) ------------------------------------------------------------------------ -- Total orders are almost decidable total orders decTotalOrder : Decidable _≈_ → DecTotalOrder _ _ _ decTotalOrder ≟ = record { isDecTotalOrder = record { isTotalOrder = isTotalOrder ; _≟_ = ≟ ; _≤?_ = total+dec⟶dec reflexive antisym total ≟ } } ------------------------------------------------------------------------ -- _≥_ - the flipped relation is also a total order open PosetProperties public using ( _≥_ ; ≥-refl ; ≥-reflexive ; ≥-trans ; ≥-antisym ; ≥-isPreorder ; ≥-isPartialOrder ; ≥-preorder ; ≥-poset ) ≥-isTotalOrder : IsTotalOrder _≈_ _≥_ ≥-isTotalOrder = Converse.isTotalOrder isTotalOrder ≥-totalOrder : TotalOrder _ _ _ ≥-totalOrder = record { isTotalOrder = ≥-isTotalOrder } open TotalOrder ≥-totalOrder public using () renaming (total to ≥-total) ------------------------------------------------------------------------ -- _<_ - the strict version is a strict partial order -- Note that total orders can NOT be turned into strict total orders as -- in order to distinguish between the _≤_ and _<_ cases we must have -- decidable equality _≈_. open PosetProperties public using ( _<_ ; <-resp-≈ ; <-respʳ-≈ ; <-respˡ-≈ ; <-irrefl ; <-asym ; <-trans ; <-isStrictPartialOrder ; <-strictPartialOrder ; <⇒≉ ; ≤∧≉⇒< ; <⇒≱ ; ≤⇒≯ ) ≰⇒> : ∀ {x y} → ¬ (x ≤ y) → y < x ≰⇒> = ToStrict.≰⇒> Eq.sym reflexive total
{ "alphanum_fraction": 0.5707360071, "avg_line_length": 25.4943820225, "ext": "agda", "hexsha": "377880bd1da9db89db9b253ce537d053f40358bd", "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/Properties/TotalOrder.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/Properties/TotalOrder.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/Properties/TotalOrder.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": 650, "size": 2269 }
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Equational.Theory module Fragment.Equational.FreeExtension (Θ : Theory) where open import Fragment.Equational.FreeExtension.Base Θ public open import Fragment.Equational.FreeExtension.Synthetic Θ using (SynFrex) public open import Fragment.Equational.FreeExtension.Properties Θ public
{ "alphanum_fraction": 0.812849162, "avg_line_length": 35.8, "ext": "agda", "hexsha": "1d30a84b68747d31150e8a12f396f0b5c161fd48", "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/Equational/FreeExtension.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/Equational/FreeExtension.agda", "max_line_length": 80, "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/Equational/FreeExtension.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": 82, "size": 358 }
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- The values of terms in Parametric.Change.Term. ------------------------------------------------------------------------ import Parametric.Syntax.Type as Type import Parametric.Syntax.Term as Term import Parametric.Denotation.Value as Value import Parametric.Change.Type as ChangeType module Parametric.Change.Value {Base : Type.Structure} (Const : Term.Structure Base) (⟦_⟧Base : Value.Structure Base) (ΔBase : ChangeType.Structure Base) where open Type.Structure Base open Term.Structure Base Const open Value.Structure Base ⟦_⟧Base open ChangeType.Structure Base ΔBase open import Base.Denotation.Notation -- Extension point 1: The value of ⊕ for base types. ApplyStructure : Set ApplyStructure = ∀ ι → ⟦ ι ⟧Base → ⟦ ΔBase ι ⟧Type → ⟦ ι ⟧Base -- Extension point 2: The value of ⊝ for base types. DiffStructure : Set DiffStructure = ∀ ι → ⟦ ι ⟧Base → ⟦ ι ⟧Base → ⟦ ΔBase ι ⟧Type NilStructure : Set NilStructure = ∀ ι → ⟦ ι ⟧Base → ⟦ ΔBase ι ⟧Type module Structure (⟦apply-base⟧ : ApplyStructure) (⟦diff-base⟧ : DiffStructure) (⟦nil-base⟧ : NilStructure) where -- We provide: The value of ⊕ and ⊝ for arbitrary types. ⟦apply⟧ : ∀ τ → ⟦ τ ⟧ → ⟦ ΔType τ ⟧ → ⟦ τ ⟧ ⟦diff⟧ : ∀ τ → ⟦ τ ⟧ → ⟦ τ ⟧ → ⟦ ΔType τ ⟧ ⟦nil₍_₎⟧ : ∀ τ → ⟦ τ ⟧ → ⟦ ΔType τ ⟧ infixl 6 ⟦apply⟧ ⟦diff⟧ syntax ⟦apply⟧ τ v dv = v ⟦⊕₍ τ ₎⟧ dv syntax ⟦diff⟧ τ u v = u ⟦⊝₍ τ ₎⟧ v v ⟦⊕₍ base ι ₎⟧ Δv = ⟦apply-base⟧ ι v Δv f ⟦⊕₍ σ ⇒ τ ₎⟧ Δf = λ v → f v ⟦⊕₍ τ ₎⟧ Δf v (⟦nil₍ σ ₎⟧ v) u ⟦⊝₍ base ι ₎⟧ v = ⟦diff-base⟧ ι u v g ⟦⊝₍ σ ⇒ τ ₎⟧ f = λ v Δv → (g (v ⟦⊕₍ σ ₎⟧ Δv)) ⟦⊝₍ τ ₎⟧ (f v) ⟦nil₍ base ι ₎⟧ v = ⟦nil-base⟧ ι v ⟦nil₍ σ ⇒ τ ₎⟧ f = f ⟦⊝₍ σ ⇒ τ ₎⟧ f _⟦⊕⟧_ : ∀ {τ} → ⟦ τ ⟧ → ⟦ ΔType τ ⟧ → ⟦ τ ⟧ _⟦⊕⟧_ {τ} = ⟦apply⟧ τ _⟦⊝⟧_ : ∀ {τ} → ⟦ τ ⟧ → ⟦ τ ⟧ → ⟦ ΔType τ ⟧ _⟦⊝⟧_ {τ} = ⟦diff⟧ τ ⟦nil⟧ : ∀ {τ} → ⟦ τ ⟧ → ⟦ ΔType τ ⟧ ⟦nil⟧ {τ} = ⟦nil₍ τ ₎⟧ alternate : ∀ {Γ} → ⟦ Γ ⟧ → ⟦ mapContext ΔType Γ ⟧ → ⟦ ΔContext Γ ⟧ alternate {∅} ∅ ∅ = ∅ alternate {τ • Γ} (v • ρ) (dv • dρ) = dv • v • alternate ρ dρ
{ "alphanum_fraction": 0.5230125523, "avg_line_length": 29.4657534247, "ext": "agda", "hexsha": "b541879d2910508b6c914d9d22804f2e2522b685", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Parametric/Change/Value.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Parametric/Change/Value.agda", "max_line_length": 72, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Parametric/Change/Value.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 988, "size": 2151 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category -- Properties relating Initial and Terminal Objects, -- and Product / Coproduct via op module Categories.Object.Duality {o ℓ e} (C : Category o ℓ e) where open Category C open import Level open import Categories.Morphism C open import Categories.Object.Terminal op open import Categories.Object.Initial C open import Categories.Object.Product op open import Categories.Object.Coproduct C IsInitial⇒coIsTerminal : ∀ {X} → IsInitial X → IsTerminal X IsInitial⇒coIsTerminal is⊥ = record { ! = ! ; !-unique = !-unique } where open IsInitial is⊥ ⊥⇒op⊤ : Initial → Terminal ⊥⇒op⊤ i = record { ⊤ = ⊥ ; ⊤-is-terminal = IsInitial⇒coIsTerminal ⊥-is-initial } where open Initial i coIsTerminal⇒IsInitial : ∀ {X} → IsTerminal X → IsInitial X coIsTerminal⇒IsInitial is⊤ = record { ! = ! ; !-unique = !-unique } where open IsTerminal is⊤ op⊤⇒⊥ : Terminal → Initial op⊤⇒⊥ t = record { ⊥ = ⊤ ; ⊥-is-initial = coIsTerminal⇒IsInitial ⊤-is-terminal } where open Terminal t Coproduct⇒coProduct : ∀ {A B} → Coproduct A B → Product A B Coproduct⇒coProduct A+B = record { A×B = A+B.A+B ; π₁ = A+B.i₁ ; π₂ = A+B.i₂ ; ⟨_,_⟩ = A+B.[_,_] ; project₁ = A+B.inject₁ ; project₂ = A+B.inject₂ ; unique = A+B.unique } where module A+B = Coproduct A+B coProduct⇒Coproduct : ∀ {A B} → Product A B → Coproduct A B coProduct⇒Coproduct A×B = record { A+B = A×B.A×B ; i₁ = A×B.π₁ ; i₂ = A×B.π₂ ; [_,_] = A×B.⟨_,_⟩ ; inject₁ = A×B.project₁ ; inject₂ = A×B.project₂ ; unique = A×B.unique } where module A×B = Product A×B
{ "alphanum_fraction": 0.6203866432, "avg_line_length": 23.3835616438, "ext": "agda", "hexsha": "efc7bdd5fa1bc1a4a6b2d2d7f50c3f9177be5a3e", "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": "6cbfdf3f1be15ef513435e3b85faae92cb1ac36f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bond15/agda-categories", "max_forks_repo_path": "src/Categories/Object/Duality.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6cbfdf3f1be15ef513435e3b85faae92cb1ac36f", "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": "bond15/agda-categories", "max_issues_repo_path": "src/Categories/Object/Duality.agda", "max_line_length": 67, "max_stars_count": null, "max_stars_repo_head_hexsha": "6cbfdf3f1be15ef513435e3b85faae92cb1ac36f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bond15/agda-categories", "max_stars_repo_path": "src/Categories/Object/Duality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 639, "size": 1707 }
{-# OPTIONS --termination-depth=2 #-} module TerminationWithMerge where data List (a : Set) : Set where [] : List a _∷_ : a -> List a -> List a open import Agda.Builtin.Bool postulate a : Set _≤?_ : a -> a -> Bool merge : List a -> List a -> List a merge xs [] = xs merge [] ys = ys merge (x ∷ xs) (y ∷ ys) with x ≤? y ... | true = x ∷ merge xs (y ∷ ys) ... | false = y ∷ merge (x ∷ xs) ys
{ "alphanum_fraction": 0.5044843049, "avg_line_length": 21.2380952381, "ext": "agda", "hexsha": "e8c884d50c8b46d83c768e318fcb77280704fbba", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "alhassy/agda", "max_forks_repo_path": "test/Succeed/TerminationWithMerge.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "alhassy/agda", "max_issues_repo_path": "test/Succeed/TerminationWithMerge.agda", "max_line_length": 37, "max_stars_count": 3, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "test/Succeed/TerminationWithMerge.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": 155, "size": 446 }
open import Agda.Builtin.List open import Agda.Builtin.Reflection open import Agda.Builtin.Sigma open import Agda.Builtin.Unit @0 m : Name → TC ⊤ m F = defineFun F (clause (( "A" , arg (arg-info visible (modality relevant quantity-0)) (agda-sort (lit 0))) ∷ []) (arg (arg-info visible (modality relevant quantity-0)) (var 0) ∷ []) (var 0 []) ∷ []) F : @0 Set → Set unquoteDef F = m F
{ "alphanum_fraction": 0.5967741935, "avg_line_length": 21.7, "ext": "agda", "hexsha": "e26a1f4c687bd8b68665a75f38ba56a3e5a36495", "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/ErasedMacro4.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/ErasedMacro4.agda", "max_line_length": 69, "max_stars_count": 1, "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/ErasedMacro4.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:25:14.000Z", "max_stars_repo_stars_event_min_datetime": "2022-03-05T00:25:14.000Z", "num_tokens": 141, "size": 434 }
{-# OPTIONS --cubical --no-import-sorts #-} open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc) open import Function.Base using (_∋_; _$_) open import MorePropAlgebra.Bundles import Cubical.Algebra.Ring as Std module MorePropAlgebra.Properties.Ring {ℓ} (assumptions : Ring {ℓ}) where open Ring assumptions renaming (Carrier to R) import MorePropAlgebra.Properties.AbGroup module AbGroup'Properties = MorePropAlgebra.Properties.AbGroup (record { Ring assumptions renaming (+-AbGroup to is-AbGroup) }) module AbGroup' = AbGroup (record { Ring assumptions renaming (+-AbGroup to is-AbGroup) }) ( AbGroup') = AbGroup ∋ (record { Ring assumptions renaming (+-AbGroup to is-AbGroup) }) import MorePropAlgebra.Properties.Monoid module Monoid'Properties = MorePropAlgebra.Properties.Monoid (record { Ring assumptions renaming (·-Monoid to is-Monoid) }) module Monoid' = Monoid (record { Ring assumptions renaming (·-Monoid to is-Monoid) }) ( Monoid') = Monoid ∋ (record { Ring assumptions renaming (·-Monoid to is-Monoid) }) stdIsRing : Std.IsRing 0r 1r _+_ _·_ (-_) stdIsRing .Std.IsRing.+-isAbGroup = AbGroup'Properties.stdIsAbGroup stdIsRing .Std.IsRing.·-isMonoid = Monoid'Properties.stdIsMonoid stdIsRing .Std.IsRing.dist = is-dist stdRing : Std.Ring {ℓ} stdRing = record { Ring assumptions ; isRing = stdIsRing } module RingTheory' = Std.Theory stdRing {- -- NOTE: a few facts about rings that might be collected from elsewhere a+b-b≡a : ∀ a b → a ≡ (a + b) - b a+b-b≡a a b = let P = sym (fst (+-inv b)) Q = sym (fst (+-identity a)) R = transport (λ i → a ≡ a + P i) Q S = transport (λ i → a ≡ (+-assoc a b (- b)) i ) R in S -- NOTE: this is called `simplL` and `simplL` in `Cubical.Structures.Group.Properties.GroupLemmas` +-preserves-≡ : ∀{a b} → ∀ c → a ≡ b → a + c ≡ b + c +-preserves-≡ c a≡b i = a≡b i + c +-preserves-≡-l : ∀{a b} → ∀ c → a ≡ b → c + a ≡ c + b +-preserves-≡-l c a≡b i = c + a≡b i a+b≡0→a≡-b : ∀{a b} → a + b ≡ 0r → a ≡ - b a+b≡0→a≡-b {a} {b} a+b≡0 = transport (λ i → let RHS = snd (+-identity (- b)) LHS₁ : a + (b + - b) ≡ a + 0r LHS₁ = +-preserves-≡-l a (fst (+-inv b)) LHS₂ : (a + b) - b ≡ a LHS₂ = transport (λ j → (+-assoc a b (- b)) j ≡ fst (+-identity a) j) LHS₁ in LHS₂ i ≡ RHS i ) (+-preserves-≡ (- b) a+b≡0) -- NOTE: there is already -- -commutesWithRight-· : (x y : R) → x · (- y) ≡ - (x · y) a·-b≡-a·b : ∀ a b → a · (- b) ≡ - (a · b) a·-b≡-a·b a b = let P : a · 0r ≡ 0r P = 0-rightNullifies a Q : a · (- b + b) ≡ 0r Q = transport (λ i → a · snd (+-inv b) (~ i) ≡ 0r) P R : a · (- b) + a · b ≡ 0r R = transport (λ i → ·-rdist-+ a (- b) b i ≡ 0r) Q in a+b≡0→a≡-b R a·b-a·c≡a·[b-c] : ∀ a b c → a · b - (a · c) ≡ a · (b - c) a·b-a·c≡a·[b-c] a b c = let P : a · b + a · (- c) ≡ a · (b + - c) P = sym (·-rdist-+ a b (- c)) Q : a · b - a · c ≡ a · (b + - c) Q = transport (λ i → a · b + a·-b≡-a·b a c i ≡ a · (b + - c) ) P in Q -}
{ "alphanum_fraction": 0.5348052745, "avg_line_length": 38.3647058824, "ext": "agda", "hexsha": "ad45aa4dafe31eab50930db6bf478e19fa72b542", "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": "agda/MorePropAlgebra/Properties/Ring.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": "agda/MorePropAlgebra/Properties/Ring.agda", "max_line_length": 129, "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": "agda/MorePropAlgebra/Properties/Ring.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": 1239, "size": 3261 }
{- Type class for comonads. -} module CategoryTheory.Comonad where open import CategoryTheory.Categories open import CategoryTheory.Functor open import CategoryTheory.NatTrans -- A comonad on a category record Comonad {n} (ℂ : Category n) : Set (lsuc n) where open Category ℂ field -- Underlying endofunctor W : Endofunctor ℂ open Functor W field -- || Definitions -- Counit / extract ε : W ⟹ I -- Comultiplication / duplicate δ : W ⟹ (W ²) module ε = _⟹_ ε module δ = _⟹_ δ field -- || Laws -- Duplication is cancelled by extraction on both sides (counit) ε-unit1 : ∀ {A : obj} -> (ε.at (omap A)) ∘ (δ.at A) ≈ id ε-unit2 : ∀ {A : obj} -> (fmap (ε.at A)) ∘ (δ.at A) ≈ id -- Duplication can be performed on both sides (coassociativity) δ-assoc : ∀ {A : obj} -> (δ.at (omap A)) ∘ (δ.at A) ≈ (fmap (δ.at A)) ∘ (δ.at A)
{ "alphanum_fraction": 0.5512690355, "avg_line_length": 28.1428571429, "ext": "agda", "hexsha": "eabae152dde6c6bb0befa1ceb738d186f3902152", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DimaSamoz/temporal-type-systems", "max_forks_repo_path": "src/CategoryTheory/Comonad.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DimaSamoz/temporal-type-systems", "max_issues_repo_path": "src/CategoryTheory/Comonad.agda", "max_line_length": 72, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DimaSamoz/temporal-type-systems", "max_stars_repo_path": "src/CategoryTheory/Comonad.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": 312, "size": 985 }
{-# OPTIONS --without-K --rewriting #-} module LEM where open import Basics open import Flat open import Bool open import lib.Basics open import lib.types.Bool open import Bool open import lib.NType2 open import Axiom.LEM public flat-set-has-dec-eq : {@♭ i : ULevel} (@♭ A : hSet i) → has-dec-eq (♭ (∈ A)) flat-set-has-dec-eq A = λ {(x ^♭) (y ^♭) → LEM (_==ₚ_ {A = ♭ₙ A} (x ^♭) (y ^♭))} discrete-set-has-dec-eq : {@♭ i : ULevel} (@♭ A : hSet i) → (@♭ _ : (∈ A) is-discrete) → has-dec-eq (∈ A) discrete-set-has-dec-eq A p = transport has-dec-eq (discrete-id p) (flat-set-has-dec-eq A) _=bool=ₚ_ : {@♭ i : ULevel} {@♭ A : hSet i} {@♭ p : (∈ A) is-discrete} (x y : ∈ A) → Bool _=bool=ₚ_ {A = A} {p = p} x y = _=bool=_ {_} {∈ A} {discrete-set-has-dec-eq A p} x y un¬¬-crisp : {@♭ i : ULevel} {@♭ P : PropT i} (nnp : ¬ (¬ (P holds))) → P holds un¬¬-crisp {P = P} nnp with (LEM P) ... | (inl p) = p ... | (inr np) = quodlibet (nnp np) ♭PropT₀≃Bool : ♭ PropT₀ ≃ Bool ♭PropT₀≃Bool = equiv to fro to-fro fro-to where to : ♭ PropT₀ → Bool to (P ^♭) = Dec-Prop-to-Bool P (LEM P) fro : Bool → ♭ PropT₀ fro = Bool-to-♭PropT₀ to-fro : (b : Bool) → to (fro b) == b to-fro true = Dec-Prop-to-Bool-true-id True (LEM True) unit to-fro false = Dec-Prop-to-Bool-false-id False (LEM False) quodlibet fro-to : (P : ♭ PropT₀) → fro (to P) == P fro-to (P ^♭) = case P (LEM P) where case₀♭ : (@♭ P : PropT₀) → ♭ (P holds) → fro (to (P ^♭)) == (P ^♭) case₀♭ P (p ^♭) = fro (to (P ^♭)) =⟨ (ap fro (Dec-Prop-to-Bool-true-id P (LEM P) p)) ⟩ fro true -- Since P holds, it equals true =⟨ ! (♭-ap _^♭ (P holds-by p implies-=-True)) ⟩ P ^♭ =∎ case₁♭ : (@♭ P : PropT₀) → ♭ (¬ (P holds)) → fro (to (P ^♭)) == (P ^♭) case₁♭ P (np ^♭) = fro (to (P ^♭)) =⟨ (ap fro (Dec-Prop-to-Bool-false-id P (LEM P) np)) ⟩ fro false =⟨ ! (♭-ap _^♭ (¬- P holds-by np implies-=-False)) ⟩ P ^♭ =∎ case : (@♭ P : PropT₀) → (@♭ d : Dec (P holds)) → fro (to (P ^♭)) == (P ^♭) case P (inl p ) = case₀♭ P (p ^♭) case P (inr np) = case₁♭ P (np ^♭) {- -- We prove that this equivalence preserves the relevant logical structure. module ♭PropT₀≃Bool-properties where preserves-⇒ : {@♭ P Q : PropT₀} (p : (P ⇒ Q) holds) → (((–> ♭PropT₀≃Bool) (P ^♭)) ≤b ((–> ♭PropT₀≃Bool) (Q ^♭))) holds preserves-⇒ {P} {Q} p = {!!} -- As a corollary, we find that the points of the upper naturals are the conaturals. module Points-Of-Upper-Naturals-Are-Conaturals where open import UpperNaturals open import Conaturals theorem : ℕ∞ ≃ ♭ ℕ↑ theorem = {!!} -}
{ "alphanum_fraction": 0.4536977492, "avg_line_length": 34.5555555556, "ext": "agda", "hexsha": "2f2825cdbb0c9095075f55d0665b0659f458592e", "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": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "glangmead/formalization", "max_forks_repo_path": "cohesion/david_jaz_261/LEM.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "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": "glangmead/formalization", "max_issues_repo_path": "cohesion/david_jaz_261/LEM.agda", "max_line_length": 92, "max_stars_count": 6, "max_stars_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "glangmead/formalization", "max_stars_repo_path": "cohesion/david_jaz_261/LEM.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-13T05:51:12.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-06T17:39:22.000Z", "num_tokens": 1182, "size": 3110 }
{-# OPTIONS --without-K --safe #-} module Definition.Conversion.Soundness where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Properties open import Definition.Conversion open import Definition.Conversion.Whnf open import Definition.Typed.Consequences.InverseUniv open import Definition.Typed.Consequences.Syntactic open import Definition.Typed.Consequences.NeTypeEq open import Tools.Product import Tools.PropositionalEquality as PE mutual -- Algorithmic equality of neutrals is well-formed. soundness~↑ : ∀ {k l A Γ} → Γ ⊢ k ~ l ↑ A → Γ ⊢ k ≡ l ∷ A soundness~↑ (var-refl x x≡y) = PE.subst (λ y → _ ⊢ _ ≡ var y ∷ _) x≡y (refl x) soundness~↑ (app-cong k~l x₁) = app-cong (soundness~↓ k~l) (soundnessConv↑Term x₁) soundness~↑ (fst-cong x) = let p≡ = soundness~↓ x ⊢ΣFG = proj₁ (syntacticEqTerm p≡) ⊢F , ⊢G = syntacticΣ ⊢ΣFG in fst-cong ⊢F ⊢G p≡ soundness~↑ (snd-cong x) = let p≡ = soundness~↓ x ⊢ΣFG = proj₁ (syntacticEqTerm p≡) ⊢F , ⊢G = syntacticΣ ⊢ΣFG in snd-cong ⊢F ⊢G p≡ soundness~↑ (natrec-cong x₁ x₂ x₃ k~l) = natrec-cong (soundnessConv↑ x₁) (soundnessConv↑Term x₂) (soundnessConv↑Term x₃) (soundness~↓ k~l) soundness~↑ (Emptyrec-cong x₁ k~l) = Emptyrec-cong (soundnessConv↑ x₁) (soundness~↓ k~l) -- Algorithmic equality of neutrals in WHNF is well-formed. soundness~↓ : ∀ {k l A Γ} → Γ ⊢ k ~ l ↓ A → Γ ⊢ k ≡ l ∷ A soundness~↓ ([~] A₁ D whnfA k~l) = conv (soundness~↑ k~l) (subset* D) -- Algorithmic equality of types is well-formed. soundnessConv↑ : ∀ {A B Γ} → Γ ⊢ A [conv↑] B → Γ ⊢ A ≡ B soundnessConv↑ ([↑] A′ B′ D D′ whnfA′ whnfB′ A′<>B′) = trans (subset* D) (trans (soundnessConv↓ A′<>B′) (sym (subset* D′))) -- Algorithmic equality of types in WHNF is well-formed. soundnessConv↓ : ∀ {A B Γ} → Γ ⊢ A [conv↓] B → Γ ⊢ A ≡ B soundnessConv↓ (U-refl ⊢Γ) = refl (Uⱼ ⊢Γ) soundnessConv↓ (ℕ-refl ⊢Γ) = refl (ℕⱼ ⊢Γ) soundnessConv↓ (Empty-refl ⊢Γ) = refl (Emptyⱼ ⊢Γ) soundnessConv↓ (Unit-refl ⊢Γ) = refl (Unitⱼ ⊢Γ) soundnessConv↓ (ne x) = univ (soundness~↓ x) soundnessConv↓ (Π-cong F c c₁) = Π-cong F (soundnessConv↑ c) (soundnessConv↑ c₁) soundnessConv↓ (Σ-cong F c c₁) = Σ-cong F (soundnessConv↑ c) (soundnessConv↑ c₁) -- Algorithmic equality of terms is well-formed. soundnessConv↑Term : ∀ {a b A Γ} → Γ ⊢ a [conv↑] b ∷ A → Γ ⊢ a ≡ b ∷ A soundnessConv↑Term ([↑]ₜ B t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u) = conv (trans (subset*Term d) (trans (soundnessConv↓Term t<>u) (sym (subset*Term d′)))) (sym (subset* D)) -- Algorithmic equality of terms in WHNF is well-formed. soundnessConv↓Term : ∀ {a b A Γ} → Γ ⊢ a [conv↓] b ∷ A → Γ ⊢ a ≡ b ∷ A soundnessConv↓Term (ℕ-ins x) = soundness~↓ x soundnessConv↓Term (Empty-ins x) = soundness~↓ x soundnessConv↓Term (Unit-ins x) = soundness~↓ x soundnessConv↓Term (ne-ins t u x x₁) = let _ , neA , _ = ne~↓ x₁ _ , t∷M , _ = syntacticEqTerm (soundness~↓ x₁) M≡A = neTypeEq neA t∷M t in conv (soundness~↓ x₁) M≡A soundnessConv↓Term (univ x x₁ x₂) = inverseUnivEq x (soundnessConv↓ x₂) soundnessConv↓Term (zero-refl ⊢Γ) = refl (zeroⱼ ⊢Γ) soundnessConv↓Term (suc-cong c) = suc-cong (soundnessConv↑Term c) soundnessConv↓Term (η-eq x x₁ y y₁ c) = let ⊢ΠFG = syntacticTerm x ⊢F , _ = syntacticΠ ⊢ΠFG in η-eq ⊢F x x₁ (soundnessConv↑Term c) soundnessConv↓Term (Σ-η ⊢p ⊢r pProd rProd fstConv sndConv) = let ⊢ΣFG = syntacticTerm ⊢p ⊢F , ⊢G = syntacticΣ ⊢ΣFG fst≡ = soundnessConv↑Term fstConv snd≡ = soundnessConv↑Term sndConv in Σ-η ⊢F ⊢G ⊢p ⊢r fst≡ snd≡ soundnessConv↓Term (η-unit [a] [b] aUnit bUnit) = η-unit [a] [b]
{ "alphanum_fraction": 0.6226265823, "avg_line_length": 41.2173913043, "ext": "agda", "hexsha": "4bcce2845d9dc6c6386c5905defdfeffedee2f25", "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/Conversion/Soundness.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/Conversion/Soundness.agda", "max_line_length": 84, "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/Conversion/Soundness.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1526, "size": 3792 }
{-# OPTIONS --without-K #-} open import HoTT open import cohomology.FunctionOver {- Flipping the pushout diagram (switching left and right) gives the - same pushout. -} module cohomology.FlipPushout where {- Span-flipping functions -} flip-span : ∀ {i j k} → Span {i} {j} {k} → Span {j} {i} {k} flip-span (span A B C f g) = span B A C g f flip-⊙span : ∀ {i j k} → ⊙Span {i} {j} {k} → ⊙Span {j} {i} {k} flip-⊙span (⊙span X Y Z f g) = ⊙span Y X Z g f {- Pushout-flipping function -} module _ {i j k} {d : Span {i} {j} {k}} where module FlipPushout = PushoutRec (right {d = flip-span d}) (left {d = flip-span d}) (λ z → ! (glue {d = flip-span d} z)) flip-pushout : Pushout d → Pushout (flip-span d) flip-pushout = FlipPushout.f flip-pushout-involutive : ∀ {i j k} (d : Span {i} {j} {k}) (s : Pushout d) → flip-pushout (flip-pushout s) == s flip-pushout-involutive d = Pushout-elim (λ a → idp) (λ b → idp) (λ c → ↓-∘=idf-in flip-pushout flip-pushout $ ap flip-pushout (ap flip-pushout (glue c)) =⟨ ap (ap flip-pushout) (FlipPushout.glue-β c) ⟩ ap flip-pushout (! (glue c)) =⟨ ap-! flip-pushout (glue c) ⟩ ! (ap flip-pushout (glue c)) =⟨ ap ! (FlipPushout.glue-β c) ⟩ ! (! (glue c)) =⟨ !-! (glue c) ⟩ glue c ∎) {- Equivalence for spans with proofs that the equivalence swaps the - injections -} module _ {i j k} (d : Span {i} {j} {k}) where open Span d flip-pushout-equiv : Pushout d ≃ Pushout (flip-span d) flip-pushout-equiv = equiv flip-pushout flip-pushout (flip-pushout-involutive (flip-span d)) (flip-pushout-involutive d) flip-pushout-path : Pushout d == Pushout (flip-span d) flip-pushout-path = ua flip-pushout-equiv flip-left : left == right [ (λ D → (A → D)) ↓ flip-pushout-path ] flip-left = codomain-over-equiv _ _ flip-right : right == left [ (λ D → (B → D)) ↓ flip-pushout-path ] flip-right = codomain-over-equiv _ _ {- Path for pointed spans with proofs that the path swaps the pointed - injections -} module _ {i j k} (ps : ⊙Span {i} {j} {k}) where open ⊙Span ps private s = ⊙span-out ps preserves : –> (flip-pushout-equiv s) (left (snd X)) == left (snd Y) preserves = snd (⊙right (flip-⊙span ps)) flip-⊙pushout : fst (⊙Pushout ps ⊙→ ⊙Pushout (flip-⊙span ps)) flip-⊙pushout = (FlipPushout.f , preserves) flip-⊙pushout-path : ⊙Pushout ps == ⊙Pushout (flip-⊙span ps) flip-⊙pushout-path = ⊙ua (⊙≃-in (flip-pushout-equiv s) preserves) {- action of [flip-pushout] on [snd ⊙right] -} ap-flip-right : ap flip-pushout (snd (⊙right ps)) == ! (snd (⊙right (flip-⊙span ps))) ap-flip-right = lemma f g where lemma : {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (f : fst (Z ⊙→ X)) (g : fst (Z ⊙→ Y)) → ap (flip-pushout {d = ⊙span-out (⊙span X Y Z f g)}) (ap right (! (snd g)) ∙ ! (glue (snd Z)) ∙' ap left (snd f)) == ! (ap right (! (snd f)) ∙ ! (glue (snd Z)) ∙' ap left (snd g)) lemma {Z = Z} (f , idp) (g , idp) = ap flip-pushout (! (glue (snd Z))) =⟨ ap-! flip-pushout (glue (snd Z)) ⟩ ! (ap flip-pushout (glue (snd Z))) =⟨ FlipPushout.glue-β (snd Z) |in-ctx ! ⟩ ! (! (glue (snd Z))) ∎ flip-⊙left : ⊙left ps == ⊙right (flip-⊙span ps) [ (λ W → fst (X ⊙→ W)) ↓ flip-⊙pushout-path ] flip-⊙left = codomain-over-⊙equiv _ _ flip-⊙right : ⊙right ps == ⊙left (flip-⊙span ps) [ (λ W → fst (Y ⊙→ W)) ↓ flip-⊙pushout-path ] flip-⊙right = codomain-over-⊙equiv _ _ ▹ pair= idp (ap (λ w → w ∙ preserves) ap-flip-right ∙ !-inv-l preserves) flip-⊙pushout-involutive : ∀ {i j k} (ps : ⊙Span {i} {j} {k}) → flip-⊙pushout (flip-⊙span ps) ⊙∘ flip-⊙pushout ps == ⊙idf _ flip-⊙pushout-involutive ps = ⊙λ= (flip-pushout-involutive _) lemma where lemma : ap flip-pushout (snd (⊙right (flip-⊙span ps))) ∙ snd (⊙right ps) == idp lemma = ap flip-pushout (snd (⊙right (flip-⊙span ps))) ∙ snd (⊙right ps) =⟨ ap-flip-right (flip-⊙span ps) |in-ctx (λ w → w ∙ snd (⊙right ps)) ⟩ ! (snd (⊙right ps)) ∙ snd (⊙right ps) =⟨ !-inv-l (snd (⊙right ps)) ⟩ idp
{ "alphanum_fraction": 0.5636059302, "avg_line_length": 33.1904761905, "ext": "agda", "hexsha": "8199b73f75f82e9092cd3f675af88c6b2bd61548", "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": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_path": "theorems/cohomology/FlipPushout.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "cmknapp/HoTT-Agda", "max_issues_repo_path": "theorems/cohomology/FlipPushout.agda", "max_line_length": 76, "max_stars_count": null, "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_path": "theorems/cohomology/FlipPushout.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1631, "size": 4182 }
open import x1-Base open import x4-Nat open import x3-PropositionalEquality using (_≡_; refl; cong; equivalence) open import x2-Sort _≤?_ totalOrder module x5-Test where empty : OList ⊥ ⊤ empty = nil ⊥≤̂ l-9 : OList ⊥ ⊤ l-9 = insert 9 empty ⊥≤̂ ≤̂⊤ _ : l-9 ≡ cons 9 (nil ≤̂⊤) ⊥≤̂ _ = refl l-5-9 : OList ⊥ ⊤ l-5-9 = insert 5 l-9 ⊥≤̂ ≤̂⊤ _ : l-5-9 ≡ cons 5 (cons 9 (nil ≤̂⊤) (≤-lift (s≤s (s≤s (s≤s (s≤s (s≤s z≤n))))))) ⊥≤̂ _ = refl l-1-5-9 : OList ⊥ ⊤ l-1-5-9 = insert 1 l-5-9 ⊥≤̂ ≤̂⊤ _ : l-1-5-9 ≡ cons 1 (cons 5 (cons 9 (nil ≤̂⊤) (≤-lift (s≤s (s≤s (s≤s (s≤s (s≤s z≤n))))))) (≤-lift (s≤s z≤n))) -- NOTE CHANGE ⊥≤̂ _ = refl sl : List ℕ sl = t-sort (12 ∷ 3 ∷ 7 ∷ 4 ∷ 40 ∷ 5 ∷ 0 ∷ []) _ : sl ≡ (0 ∷ 3 ∷ 4 ∷ 5 ∷ 7 ∷ 12 ∷ 40 ∷ []) _ = refl
{ "alphanum_fraction": 0.3829568789, "avg_line_length": 22.1363636364, "ext": "agda", "hexsha": "883d36b7ea0a845209b06b8931c6a04c8d4bd24f", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_path": "agda/topic/order/2013-04-01-sorting-francesco-mazzo/x5-Test.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_path": "agda/topic/order/2013-04-01-sorting-francesco-mazzo/x5-Test.agda", "max_line_length": 74, "max_stars_count": 36, "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_path": "agda/topic/order/2013-04-01-sorting-francesco-mazzo/x5-Test.agda", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "num_tokens": 478, "size": 974 }
module io-test where open import io open import string open import unit main : IO ⊤ main = (readFiniteFile "hello-world.txt") >>= λ x → writeFile "output.txt" x
{ "alphanum_fraction": 0.7134146341, "avg_line_length": 16.4, "ext": "agda", "hexsha": "66bef5e056b1f44359d3646356b255ec00c56f27", "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": "io-test.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": "io-test.agda", "max_line_length": 76, "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": "io-test.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": 45, "size": 164 }
module calculus where open import utility open import Esterel.Lang open import Esterel.Lang.Binding open import Esterel.Lang.Properties open import Esterel.Lang.CanFunction using (Canθₛ ; Canθₛₕ ; [S]-env) open import Esterel.Environment as Env using (Env ; Θ ; _←_ ; sig ; []env ; module SigMap ; module ShrMap ; module VarMap) open import Esterel.Context using (EvaluationContext ; EvaluationContext1 ; _⟦_⟧e ; _≐_⟦_⟧e ; Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c) open import Esterel.Variable.Signal as Signal using (Signal) open import Esterel.Variable.Shared as SharedVar using (SharedVar) open import Esterel.Variable.Sequential as SeqVar using (SeqVar) open import Esterel.Context.Properties open import Relation.Nullary using (¬_) open import Relation.Binary.PropositionalEquality using (_≡_ ; refl) open import Data.Empty using (⊥ ; ⊥-elim) import Data.FiniteMap open import Data.List using (List ; _∷_ ; [] ; _++_) open import Data.List.All as All using (All ; _∷_ ; []) open import Data.Nat using (ℕ ; zero ; suc ; _+_) renaming (_⊔_ to _⊔ℕ_) open import Data.Product using (Σ-syntax ; Σ ; _,_ ; proj₁ ; proj₂ ; _×_ ; _,′_) open import Data.Sum using (_⊎_ ; inj₁ ; inj₂) open import Relation.Binary.PropositionalEquality open import sn-calculus open _≐_⟦_⟧e open _≐_⟦_⟧c open EvaluationContext1 open Context1 infix 4 _⟶₁_ infix 4 _⟶_ infix 4 _⟶*_ data _⟶₁_ : Term → Term → Set where [par-swap] : ∀{p q} → (p ∥ q) ⟶₁ (q ∥ p) [par-nothing] : ∀ {q} -> done q -> (nothin ∥ q) ⟶₁ q [par-1exit] : ∀ {q} -> ∀ n -> (pausedq : paused q) -> (exit n ∥ q) ⟶₁ exit n [par-2exit] : ∀ n m -> (exit n ∥ exit m) ⟶₁ exit (n ⊔ℕ m) [is-present] : ∀{θ r p q E A} → ∀ S -> (S∈ : (Env.isSig∈ S θ)) → (θ[S]≡present : Env.sig-stats{S} θ S∈ ≡ Signal.present) → (de : r ≐ E ⟦ present S ∣⇒ p ∣⇒ q ⟧e) → (ρ⟨ θ , A ⟩· r) ⟶₁ (ρ⟨ θ , A ⟩· E ⟦ p ⟧e) [is-absent] : ∀{θ r p q E A} → ∀ S -> (S∈ : (Env.isSig∈ S θ)) → (θ[S]≡absent : Env.sig-stats{S} θ S∈ ≡ Signal.absent) → (de : r ≐ E ⟦ present S ∣⇒ p ∣⇒ q ⟧e) → (ρ⟨ θ , A ⟩· r) ⟶₁ (ρ⟨ θ , A ⟩· E ⟦ q ⟧e) [emit] : ∀{θ r S E} → (S∈ : (Env.isSig∈ S θ)) → (¬S≡a : ¬ (Env.sig-stats{S} θ S∈) ≡ Signal.absent) → (de : r ≐ E ⟦ emit S ⟧e) → (ρ⟨ θ , GO ⟩· r) ⟶₁ (ρ⟨ (Env.set-sig{S} θ S∈ Signal.present) , GO ⟩· E ⟦ nothin ⟧e) [loop-unroll] : ∀{p} → (loop p) ⟶₁ (loopˢ p p) [seq-done] : ∀{q} → (nothin >> q) ⟶₁ q [seq-exit] : ∀{q n} → (exit n >> q) ⟶₁ (exit n) [loopˢ-exit] : ∀{q n} → (loopˢ (exit n) q) ⟶₁ (exit n) [suspend-done] : ∀{p S} → (haltedp : halted p) → (suspend p S) ⟶₁ p -- traps [trap-done] : ∀{p} → (haltedp : halted p) → (trap p) ⟶₁ (↓ haltedp) -- lifting signals [raise-signal] : ∀{p S} → (signl S p) ⟶₁ (ρ⟨ (Θ SigMap.[ S ↦ Signal.unknown ] ShrMap.empty VarMap.empty) , WAIT ⟩· p) -- shared state [raise-shared] : ∀{θ r s e p E A} → (all-readyeθ : all-ready e θ) → (de : r ≐ E ⟦ shared s ≔ e in: p ⟧e) → (ρ⟨ θ , A ⟩· r) ⟶₁ (ρ⟨ θ , A ⟩· E ⟦ (ρ⟨ [s,δe]-env s (δ all-readyeθ) , WAIT ⟩· p) ⟧e) [set-shared-value-old] : ∀{θ r s e E} → (e' : all-ready e θ) → (s∈ : (Env.isShr∈ s θ)) → (θ[s]≡old : Env.shr-stats{s} θ s∈ ≡ SharedVar.old) → (de : r ≐ E ⟦ s ⇐ e ⟧e) → (ρ⟨ θ , GO ⟩· r) ⟶₁ (ρ⟨ (Env.set-shr{s} θ s∈ (SharedVar.new) (δ e')) , GO ⟩· E ⟦ nothin ⟧e) [set-shared-value-new] : ∀{θ r s e E} → (e' : all-ready e θ) → (s∈ : (Env.isShr∈ s θ)) → (θ[s]≡n : Env.shr-stats{s} θ s∈ ≡ SharedVar.new) → (de : r ≐ E ⟦ s ⇐ e ⟧e) → (ρ⟨ θ , GO ⟩· r) ⟶₁ (ρ⟨ (Env.set-shr{s} θ s∈ (SharedVar.new) (Env.shr-vals{s} θ s∈ + δ e')) , GO ⟩· E ⟦ nothin ⟧e) -- unshared state [raise-var] : ∀{θ r x p e E A} → (all-readyeθ : all-ready e θ) → (de : r ≐ E ⟦ var x ≔ e in: p ⟧e) → (ρ⟨ θ , A ⟩· r) ⟶₁ (ρ⟨ θ , A ⟩· E ⟦ (ρ⟨ [x,δe]-env x (δ all-readyeθ) , WAIT ⟩· p) ⟧e) [set-var] : ∀{θ r x e E A} → (x∈ : (Env.isVar∈ x θ)) → (all-readyeθ : all-ready e θ) → (de : r ≐ E ⟦ x ≔ e ⟧e) → (ρ⟨ θ , A ⟩· r) ⟶₁ (ρ⟨ (Env.set-var{x} θ x∈ (δ all-readyeθ)) , A ⟩· E ⟦ nothin ⟧e) -- if [if-false] : ∀{θ r p q x E A} → (x∈ : (Env.isVar∈ x θ)) → (θ[x]≡z : Env.var-vals{x} θ x∈ ≡ zero) → (de : r ≐ E ⟦ if x ∣⇒ p ∣⇒ q ⟧e) → (ρ⟨ θ , A ⟩· r) ⟶₁ (ρ⟨ θ , A ⟩· E ⟦ q ⟧e) [if-true] : ∀{θ r p q x E n A} → (x∈ : (Env.isVar∈ x θ)) → (θ[x]≡s : Env.var-vals{x} θ x∈ ≡ suc n) → (de : r ≐ E ⟦ if x ∣⇒ p ∣⇒ q ⟧e) → (ρ⟨ θ , A ⟩· r) ⟶₁ (ρ⟨ θ , A ⟩· E ⟦ p ⟧e) -- progression [absence] : ∀{θ p A} -> ∀ S → (S∈ : (Env.isSig∈ S θ)) → (θ[S]≡unknown : Env.sig-stats{S} θ S∈ ≡ Signal.unknown) → (S∉Canθₛ : (Signal.unwrap S) ∉ Canθₛ (sig θ) 0 p []env) → (ρ⟨ θ , A ⟩· p) ⟶₁ (ρ⟨ (Env.set-sig{S} θ S∈ (Signal.absent)) , A ⟩· p) [readyness] : ∀{θ p A} -> ∀ s → (s∈ : (Env.isShr∈ s θ)) → (θ[s]≡old⊎θ[s]≡new : (Env.shr-stats{s} θ s∈ ≡ SharedVar.old) ⊎ (Env.shr-stats{s} θ s∈ ≡ SharedVar.new)) → (s∉Canθₛₕ : (SharedVar.unwrap s) ∉ Canθₛₕ (sig θ) 0 p []env) → (ρ⟨ θ , A ⟩· p) ⟶₁ (ρ⟨ (Env.set-shr{s} θ s∈ (SharedVar.ready) (Env.shr-vals{s} θ s∈)) , A ⟩· p) [merge] : ∀{θ₁ θ₂ r p E A₁ A₂} → (de : r ≐ E ⟦ ρ⟨ θ₂ , A₂ ⟩· p ⟧e) → (ρ⟨ θ₁ , A₁ ⟩· r) ⟶₁ (ρ⟨ (θ₁ ← θ₂) , (A-max A₁ A₂) ⟩· E ⟦ p ⟧e) -- The compatible closure of _⟶₁_. data _⟶_ : Term → Term → Set where [context] : ∀{r p p'} → (C : Context) → (dc : r ≐ C ⟦ p ⟧c) → (p⟶₁p' : p ⟶₁ p') → r ⟶ (C ⟦ p' ⟧c) -- The reflexive transitive closure of ⟶ data _⟶*_ : Term → Term → Set where [refl] : ∀{p} → (p ⟶* p) [step] : ∀{p q r} → (p⟶q : p ⟶ q) → (q⟶*r : q ⟶* r) → (p ⟶* r) data _≡ₑ_#_ : Term -> Term -> List Context1 -> Set where ≡ₑrefl : ∀ {p C} -> ------------ p ≡ₑ p # C ≡ₑtran : ∀ {p r q C} -> (p≡ₑr#C : p ≡ₑ r # C) -> (r≡ₑq#C : r ≡ₑ q # C) -> ----------------------- p ≡ₑ q # C ≡ₑsymm : ∀ {p q C BVq FVq} -> (CBq : CorrectBinding (C ⟦ q ⟧c) BVq FVq) -> (q≡ₑp : q ≡ₑ p # C) -> ------------------------------------------- p ≡ₑ q # C ≡ₑctxt : ∀ {C C′ p q C′⟦p⟧ C′⟦q⟧ } -> (C′⟦p⟧≐C′⟦p⟧c : C′⟦p⟧ ≐ C′ ⟦ p ⟧c) -> (C′⟦q⟧≐C′⟦q⟧c : C′⟦q⟧ ≐ C′ ⟦ q ⟧c) -> (p≡ₑq : p ≡ₑ q # (C ++ C′)) -> ----------------------------------- C′⟦p⟧ ≡ₑ C′⟦q⟧ # C ≡ₑstep : ∀ {C p q} -> (p⟶₁q : p ⟶₁ q) -> -------------------- p ≡ₑ q # C
{ "alphanum_fraction": 0.46589171, "avg_line_length": 27.1286307054, "ext": "agda", "hexsha": "95112fec727f6818b2f9fece1302eba3eed2ce85", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z", "max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z", "max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "florence/esterel-calculus", "max_forks_repo_path": "agda/calculus.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "florence/esterel-calculus", "max_issues_repo_path": "agda/calculus.agda", "max_line_length": 85, "max_stars_count": 3, "max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "florence/esterel-calculus", "max_stars_repo_path": "agda/calculus.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z", "num_tokens": 3263, "size": 6538 }
data I : Set where i : I variable x : I abstract data D : I → Set where d : D i accepted : {x : I} → D x → Set₁ accepted {x = i} d = Set rejected : D x → Set₁ rejected {x = i} d = Set
{ "alphanum_fraction": 0.5192307692, "avg_line_length": 11.5555555556, "ext": "agda", "hexsha": "0bf1638b20ea29811aaac2c81688919d45921705", "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/Issue4006.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/Issue4006.agda", "max_line_length": 33, "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/Issue4006.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": 82, "size": 208 }
{-# OPTIONS --without-K #-} module Cham.Molecule where open import Cham.Agent open import Cham.Context open import Cham.Label open import Cham.Name open import Data.List open import Data.Product using (_×_) data Molecule : Context → Set₁ where Reagent : ∀ {Γ} → Agent Γ → Molecule Γ _·ₘ_ : ∀ {Γ} → (Valence : Label) → Molecule Γ → Molecule (Γ ⊢ Valence) _∣ₘ_ : ∀ {Γ₁ Γ₂} → Molecule Γ₁ → Molecule Γ₂ → Molecule (Γ₁ , Γ₂) _/ₘ_ : ∀ {Γ} → (Ion : Name) → Molecule Γ → Molecule (Γ ⊢ Ion ⁻) ⟨_,_⟩ : ∀ {Γ₁ Γ₂} → Molecule Γ₁ → Molecule Γ₂ → Molecule (Γ₁ , Γ₂) l∶⟨_,_⟩ : ∀ {Γ₁ Γ₂} → Molecule (Γ₁ , Γ₂) → Molecule Γ₁ r∶⟨_,_⟩ : ∀ {Γ₁ Γ₂} → Molecule (Γ₁ , Γ₂) → Molecule Γ₂ -- molecular solutions Sol : ∀ {Γ₁ Γ₂} → Molecule Γ₁ → Molecule Γ₂ → Molecule (permeate Γ₁ Γ₂)
{ "alphanum_fraction": 0.4884189325, "avg_line_length": 19.86, "ext": "agda", "hexsha": "56d4a74cd9c247677666b79d5fe9eb47249fae14", "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": "292023fc36fa67ca4a81cff9a875a325a79b9d6f", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "riz0id/chemical-abstract-machine", "max_forks_repo_path": "agda/Cham/Molecule.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "292023fc36fa67ca4a81cff9a875a325a79b9d6f", "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": "riz0id/chemical-abstract-machine", "max_issues_repo_path": "agda/Cham/Molecule.agda", "max_line_length": 40, "max_stars_count": null, "max_stars_repo_head_hexsha": "292023fc36fa67ca4a81cff9a875a325a79b9d6f", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "riz0id/chemical-abstract-machine", "max_stars_repo_path": "agda/Cham/Molecule.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 355, "size": 993 }
module Using where module Dummy where data DummySet1 : Set where ds1 : DummySet1 data DummySet2 : Set where ds2 : DummySet2 open Dummy using (DummySet1) open Dummy -- checking that newline + comment is allowed before "using" using (DummySet2)
{ "alphanum_fraction": 0.7480314961, "avg_line_length": 21.1666666667, "ext": "agda", "hexsha": "d844d6d2b9b21a86569caa0bca602888535bde38", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Using.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "hborum/agda", "max_issues_repo_path": "test/Succeed/Using.agda", "max_line_length": 71, "max_stars_count": 3, "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "hborum/agda", "max_stars_repo_path": "test/Succeed/Using.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": 69, "size": 254 }
-- Testcase for #2028 by Ulf record ⊤ : Set where constructor tt data Either (A B : Set) : Set where inl : A → Either A B inr : B → Either A B Subset : Set → Set₁ Subset X = X → Set U : ∀ {X} → Subset X U _ = {!⊤!} _⊆_ : ∀ {X} → Subset X → Subset X → Set A ⊆ B = ∀ {x} → A x → B x _∪_ : ∀ {X} → Subset X → Subset X → Subset X (A ∪ B) x = Either (A x) (B x) ∪-bound : ∀ {X} {A : Subset X} → (A ∪ U) ⊆ U ∪-bound {X} {A} = aux where aux : _ → _ aux (inl _) = tt aux (inr tt) = tt
{ "alphanum_fraction": 0.494047619, "avg_line_length": 18, "ext": "agda", "hexsha": "dfae9086da771455508f4d00073d0bb8f8af5b6e", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/interaction/Issue2028-where.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/interaction/Issue2028-where.agda", "max_line_length": 44, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/interaction/Issue2028-where.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": 224, "size": 504 }
open import Coinduction using ( ♯_ ) open import Data.Natural using ( Natural ; # ; _+_ ) open import Data.Strict using ( Strict ; ! ) open import System.IO.Transducers.Session using ( I ; Σ ; ⟨_⟩ ) open import System.IO.Transducers.Lazy using ( _⇒_ ; inp ; out ; done ) module System.IO.Transducers.Weight where -- Weight of a trace weight' : ∀ {S} → (Strict Natural) → S ⇒ ⟨ Natural ⟩ weight' {I} (! n) = out n done weight' {Σ W F} (! n) = inp (♯ λ a → weight' (! (n + W a))) weight : ∀ {S} → S ⇒ ⟨ Natural ⟩ weight = weight' (! (# 0))
{ "alphanum_fraction": 0.6110091743, "avg_line_length": 34.0625, "ext": "agda", "hexsha": "1f5bb47b7cd0b5abba5862c7d8276f5e142fc865", "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/Weight.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/Weight.agda", "max_line_length": 71, "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/Weight.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": 174, "size": 545 }
open import Everything module Test.Thickandthin where module _ {x a b ℓb c ℓc} ⦃ _ : Thickandthin x a b ℓb c ℓc ⦄ where open Thickandthin ⦃ … ⦄ test-thin : 𝓽hin A B test-thin = thin test-check/thin=1 : 𝓬heck/thin=1 A B C _≈C_ test-check/thin=1 = check/thin=1 test-injectivity : ∀ {m : X} {x : A (⇑₀ m)} → 𝓶ap (_≈B_ on thin x) _≈B_ test-injectivity {x = x} = injectivity₂,₁ x
{ "alphanum_fraction": 0.6379746835, "avg_line_length": 23.2352941176, "ext": "agda", "hexsha": "fcfb3486a0fc5240f194373b69c1981982b8e04c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Test/Thickandthin.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Test/Thickandthin.agda", "max_line_length": 73, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Test/Thickandthin.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 180, "size": 395 }
--{-# OPTIONS --rewriting #-} module Array.Rewrites where open import Array.Base open import Data.Nat open import Data.Fin using (Fin; zero; suc) open import Data.Vec open import Data.Vec.Properties open import Relation.Binary.PropositionalEquality open import Function --{-# BUILTIN REWRITE _≡_ #-} thm : ∀ {a}{X : Set a}{s : Vec X 1} → head s ∷ [] ≡ s thm {s = x ∷ []} = refl expand-s→a∘a→s : ∀ {el}{ar : Ar ℕ 1 (el ∷ [])} → ∀ (iv : Ix 1 (el ∷ [])) → lookup (a→s ar) (ix-lookup iv zero) ≡ unimap ar iv expand-s→a∘a→s {ar = imap f} (x ∷ []) rewrite (lookup∘tabulate (f ∘ (_∷ [])) x) = refl imap∘unimap : ∀ {a}{X : Set a}{d s} → (ar : Ar X d s) → imap (λ iv → unimap ar iv) ≡ ar imap∘unimap (imap ar) = refl --{-# REWRITE expand-s→a∘a→s #-} --{-# REWRITE imap∘unimap #-} --{-# REWRITE tabulate∘lookup #-} --{-# REWRITE lookup∘tabulate #-} n+0≡n : ∀ n → n + 0 ≡ n n+0≡n zero = refl n+0≡n (suc n) = cong suc (n+0≡n n) --{-# REWRITE n+0≡n #-} test = λ x → x + 0
{ "alphanum_fraction": 0.5558852621, "avg_line_length": 24.6585365854, "ext": "agda", "hexsha": "c1065934d3c1bbf48d55b791c5c34db98370a624", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2020-10-12T07:19:48.000Z", "max_forks_repo_forks_event_min_datetime": "2020-10-12T07:19:48.000Z", "max_forks_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "ashinkarov/agda-array", "max_forks_repo_path": "Array/Rewrites.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "ashinkarov/agda-array", "max_issues_repo_path": "Array/Rewrites.agda", "max_line_length": 87, "max_stars_count": 6, "max_stars_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "ashinkarov/agda-array", "max_stars_repo_path": "Array/Rewrites.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-15T14:21:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-09T13:53:46.000Z", "num_tokens": 401, "size": 1011 }
{-# OPTIONS --without-K --safe #-} open import Algebra open import Relation.Unary open import Relation.Binary hiding (Decidable) module Data.FingerTree.Split.Structures {r m} (ℳ : Monoid r m) {s} {ℙ : Pred (Monoid.Carrier ℳ) s} (ℙ-resp : ℙ Respects (Monoid._≈_ ℳ)) (ℙ? : Decidable ℙ) where open import Relation.Nullary using (¬_; yes; no; Dec) open import Level using (_⊔_) open import Data.Product open import Function open import Data.List as List using (List; _∷_; []) open import Data.FingerTree.Measures ℳ open import Data.FingerTree.Structures ℳ open import Data.FingerTree.Reasoning ℳ open import Data.FingerTree.View ℳ using (deepₗ; deepᵣ) open import Data.FingerTree.Cons ℳ using (listToTree) open import Relation.Nullary using (Dec; yes; no) open import Relation.Nullary.Decidable using (True; toWitness; False; toWitnessFalse) open σ ⦃ ... ⦄ open Monoid ℳ renaming (Carrier to 𝓡) open import Data.FingerTree.Relation.Binary.Reasoning.FasterInference.Setoid setoid open import Data.FingerTree.Split.Point ℳ ℙ-resp ℙ? open import Data.FingerTree.Split.StoredPredicate ℳ ℙ-resp ℙ? open import Data.FingerTree.Split.Intermediate ℳ ℙ-resp ℙ? open import Data.Empty.Irrelevant using (⊥-elim) module _ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ where splitList : (i : 𝓡) → (xs : List Σ) → .(i ∣ μ xs) → μ⟨ Split′ i (List Σ) Σ ⟩≈ (i ∙ μ xs) splitList i [] s = ⊥-elim (¬∄ℙ s) splitList i (x ∷ xs) s with ⟪ℙ?⟫ (i ∙ μ x) ... | yes p ≈ℙ i∙x [ i∙x≈ ] = [] ∷⟨ x ⟩∷ xs [ s ▻ p ≈◄⟅ ℳ ↯ ⟆ ] ⇑[ ℳ ↯ ] ... | no ¬p ≈ℙ i∙x [ i∙x≈ ] with splitList i∙x xs (s ◄ ¬p ≈◄⟅ sym i∙x≈ ⟆) i≈[ i∙x≈ ] ... | ys ∷⟨ y ⟩∷ zs [ s′ ] ⇑[ ys≈ ] = (x ∷ ys) ∷⟨ y ⟩∷ zs [ s′ ≈◄⟅ ℳ ↯ ⟆ ] ⇑[ ℳ ↯ ] ≈[ ys≈ ]′ ≈[ ℳ ↯ ] splitNode : ∀ i → (xs : Node Σ) → .(i ∣ μ xs) → μ⟨ Split′ i (List Σ) Σ ⟩≈ (i ∙ μ xs) splitNode i xs s = do ys ← nodeToList xs [ _ ∙> sz ⟿ sz ] splitList i ys (s ≈▻⟅ sym (_ ≈? _) ⟆) splitDigit : ∀ i → (xs : Digit Σ) → .(i ∣ μ xs) → μ⟨ Split′ i (List Σ) Σ ⟩≈ (i ∙ μ xs) splitDigit i xs s = digitToList xs [ _ ∙> sz ⟿ sz ] >>= λ ys → splitList i ys (s ≈▻⟅ sym (_ ≈? _) ⟆) splitTree-l : ∀ i → (ls : Digit Σ) → (m : Tree ⟪ Node Σ ⟫) → (rs : Digit Σ) → .(i ∣ μ ls) → μ⟨ Split′ i (Tree Σ) Σ ⟩≈ (i ∙ (μ ls ∙ (μ m ∙ μ rs))) splitTree-l i ls m rs s with splitDigit i ls s splitTree-l i ls m rs s | lsₗ ∷⟨ mₗ ⟩∷ rsₗ [ p ] ⇑[ l≈ ] = [ ( ℳ ↯ ⍮′ ≪∙ l≈ ⍮ assoc _ _ _) ]≈ do ls′ ← listToTree lsₗ [ i ∙> (sz <∙ _) ⟿ sz ] rs′ ← deepₗ rsₗ m rs [ i ∙> (_ ∙> (_ ∙> sz)) ⟿ sz ] ls′ ∷⟨ mₗ ⟩∷ rs′ [ p ≈◄⟅ ∙≫ sym (μ ls′ ≈? μ lsₗ) ⟆ ] ⇑ splitTree-r : ∀ i → (ls : Digit Σ) → (m : Tree ⟪ Node Σ ⟫) → (rs : Digit Σ) → ∀ i∙ls∙m → .(i∙ls∙m ≈ (i ∙ μ ls ∙ μ m)) → .((i ∙ μ ls ∙ μ m) ∣ μ rs) → μ⟨ Split′ i (Tree Σ) Σ ⟩≈ (i ∙ (μ ls ∙ (μ m ∙ μ rs))) splitTree-r i ls m rs i′ i′≈ s with splitDigit i′ rs (s ≈◄⟅ sym i′≈ ⟆) splitTree-r i ls m rs i′ i′≈ s | lsᵣ ∷⟨ mᵣ ⟩∷ rsᵣ [ p ] ⇑[ r≈ ] = [ lemma r≈ i′≈ ]≈ do ls′ ← deepᵣ ls m lsᵣ [ i ∙> (sz <∙ _) ⟿ sz ] rs′ ← listToTree rsᵣ [ i ∙> (_ ∙> (_ ∙> sz)) ⟿ sz ] ls′ ∷⟨ mᵣ ⟩∷ rs′ [ p ≈◄⟅ ≪∙ i′≈ ⍮ ℳ ↯ ⍮′ ∙≫ sym (μ ls′ ≈? (μ ls ∙ (μ m ∙ μ lsᵣ))) ⟆ ] ⇑ where lemma = λ r≈ i′≈ → begin i ∙ (μ ls ∙ (μ m ∙ μ lsᵣ) ∙ (μ mᵣ ∙ μ rsᵣ)) ≈⟨ ℳ ↯ ⟩ i ∙ μ ls ∙ μ m ∙ (μ lsᵣ ∙ (μ mᵣ ∙ μ rsᵣ)) ≈⟨ ≪∙ sym i′≈ ⟩ i′ ∙ (μ lsᵣ ∙ (μ mᵣ ∙ μ rsᵣ)) ≈⟨ r≈ ⟩ i′ ∙ μ rs ≈⟨ ≪∙ i′≈ ⟩ i ∙ μ ls ∙ μ m ∙ μ rs ≈⟨ ℳ ↯ ⟩ i ∙ (μ ls ∙ (μ m ∙ μ rs)) ∎ splitTree : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → ∀ i → (xs : Tree Σ) → .(i ∣ μ xs) → μ⟨ Split′ i (Tree Σ) Σ ⟩≈ (i ∙ μ xs) splitTree i empty s = ⊥-elim (¬∄ℙ s) splitTree i (single x) s = empty ∷⟨ x ⟩∷ empty [ s ≈◄⟅ ℳ ↯ ⟆ ] ⇑[ ℳ ↯ ] splitTree i (deep (𝓂 ↤ ls & m & rs ⇑[ 𝓂≈ ])) s with ⟪ℙ?⟫ (i ∙ μ ls) ... | yes p₁ ≈ℙ i∙ls [ i∙ls≈ ] = splitTree-l i ls m rs ¬[ ¬ℙ s ]ℙ[ p₁ ] ≈[ ∙≫ 𝓂≈ ] ... | no ¬p₁ ≈ℙ i∙ls [ i∙ls≈ ] with ⟪ℙ?⟫ (i∙ls ∙ μ m) ... | no ¬p₂ ≈ℙ i∙ls∙m [ i∙ls∙m≈ ] = splitTree-r i ls m rs i∙ls∙m (i∙ls∙m≈ ⍮ ≪∙ i∙ls≈) (s ≈▻⟅ sym 𝓂≈ ⟆ ◄ ¬p₁ ≈◄⟅ sym i∙ls≈ ⟆ ◄ ¬p₂ ≈◄⟅ ≪∙ i∙ls≈ ⟆) ≈[ ∙≫ 𝓂≈ ] ... | yes p₂ ≈ℙ i∙ls∙m [ i∙ls∙m≈ ] with splitTree i∙ls m (s ≈▻⟅ sym 𝓂≈ ⟆ ◄ ¬p₁ ≈◄⟅ sym i∙ls≈ ⟆ ▻ p₂) ... | lsₘ ∷⟨ μmₘ ↤ mₘ ⇑[ mₘ≈ ] ⟩∷ rsₘ [ sₘ ] ⇑[ m≈ ] with splitNode (i∙ls ∙ μ lsₘ) mₘ (sₘ ≈▻⟅ sym mₘ≈ ⟆) ... | lsₗ ∷⟨ mₗ ⟩∷ rsₗ [ sₗ ] ⇑[ l≈ ] = [ lemma 𝓂≈ m≈ mₘ≈ l≈ ]≈ do ll ← deepᵣ ls lsₘ lsₗ [ i ∙> (sz <∙ _) ⟿ sz ] rr ← deepₗ rsₗ rsₘ rs [ i ∙> (_ ∙> (μ mₗ ∙> sz)) ⟿ sz ] ll ∷⟨ mₗ ⟩∷ rr [ sₗ ≈◄⟅ ≪∙ ≪∙ i∙ls≈ ⍮ ℳ ↯ ⍮′ ∙≫ sym (μ ll ≈? (μ ls ∙ (μ lsₘ ∙ μ lsₗ))) ⟆ ] ⇑ where lemma = λ 𝓂≈ m≈ mₘ≈ l≈ → begin i ∙ (μ ls ∙ (μ lsₘ ∙ μ lsₗ) ∙ (μ mₗ ∙ (μ rsₗ ∙ (μ rsₘ ∙ μ rs)))) ≈⟨ ℳ ↯ ⟩ i ∙ μ ls ∙ μ lsₘ ∙ (μ lsₗ ∙ (μ mₗ ∙ μ rsₗ)) ∙ (μ rsₘ ∙ μ rs) ≈⟨ ≪∙ ≪∙ ≪∙ sym i∙ls≈ ⍮ l≈ <∙ (μ rsₘ ∙ μ rs) ⟩ i∙ls ∙ μ lsₘ ∙ μ mₘ ∙ (μ rsₘ ∙ μ rs) ≈⟨ ≪∙ ∙≫ mₘ≈ ⟩ i∙ls ∙ μ lsₘ ∙ μmₘ ∙ (μ rsₘ ∙ μ rs) ≈⟨ ℳ ↯ ⟩ i∙ls ∙ (μ lsₘ ∙ (μmₘ ∙ μ rsₘ)) ∙ μ rs ≈⟨ m≈ <∙ μ rs ⟩ i∙ls ∙ μ m ∙ μ rs ≈⟨ ≪∙ ≪∙ i∙ls≈ ⟩ i ∙ μ ls ∙ μ m ∙ μ rs ≈⟨ ℳ ↯ ⟩ i ∙ (μ ls ∙ (μ m ∙ μ rs)) ≈⟨ ∙≫ 𝓂≈ ⟩ i ∙ 𝓂 ∎ init-ℙ : ∀ {𝓂} → (¬ℙ⟨ε⟩ : False (ℙ? ε)) → (ℙ⟨xs⟩ : True (ℙ? 𝓂)) → ε ∣ 𝓂 ¬ℙ (init-ℙ fl tr) = toWitnessFalse fl !ℙ (init-ℙ fl tr) = ℙ-resp (sym (identityˡ _)) (toWitness tr)
{ "alphanum_fraction": 0.4682048396, "avg_line_length": 41.9763779528, "ext": "agda", "hexsha": "8962b2fbd22fb2b3caa70c443cbad83c0bb1670b", "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": "39c3d96937384b052b782ffddf4fdec68c5d139f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-indexed-fingertree", "max_forks_repo_path": "src/Data/FingerTree/Split/Structures.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f", "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-indexed-fingertree", "max_issues_repo_path": "src/Data/FingerTree/Split/Structures.agda", "max_line_length": 205, "max_stars_count": 1, "max_stars_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-indexed-fingertree", "max_stars_repo_path": "src/Data/FingerTree/Split/Structures.agda", "max_stars_repo_stars_event_max_datetime": "2019-02-26T07:04:54.000Z", "max_stars_repo_stars_event_min_datetime": "2019-02-26T07:04:54.000Z", "num_tokens": 3033, "size": 5331 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Orders.Total.Definition open import Orders.Partial.Definition open import Setoids.Setoids open import Functions open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Setoids.Orders where partialOrderToSetoidPartialOrder : {a b : _} {A : Set a} (P : PartialOrder {a} A {b}) → SetoidPartialOrder (reflSetoid A) (PartialOrder._<_ P) SetoidPartialOrder.<WellDefined (partialOrderToSetoidPartialOrder P) a=b c=d a<c rewrite a=b | c=d = a<c SetoidPartialOrder.irreflexive (partialOrderToSetoidPartialOrder P) = PartialOrder.irreflexive P SetoidPartialOrder.<Transitive (partialOrderToSetoidPartialOrder P) = PartialOrder.<Transitive P totalOrderToSetoidTotalOrder : {a b : _} {A : Set a} (T : TotalOrder {a} A {b}) → SetoidTotalOrder (partialOrderToSetoidPartialOrder (TotalOrder.order T)) SetoidTotalOrder.totality (totalOrderToSetoidTotalOrder T) = TotalOrder.totality T
{ "alphanum_fraction": 0.7876923077, "avg_line_length": 48.75, "ext": "agda", "hexsha": "3a41764a1991cc92fca1a47f212bada32796e191", "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/Orders/Orders.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/Orders/Orders.agda", "max_line_length": 154, "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/Orders/Orders.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": 282, "size": 975 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category.Core using (Category) module Categories.Category.BicartesianClosed {o ℓ e} (𝒞 : Category o ℓ e) where open import Level open import Categories.Category.CartesianClosed 𝒞 open import Categories.Category.Cocartesian 𝒞 record BicartesianClosed : Set (levelOfTerm 𝒞) where field cartesianClosed : CartesianClosed cocartesian : Cocartesian
{ "alphanum_fraction": 0.7695961995, "avg_line_length": 26.3125, "ext": "agda", "hexsha": "742e4a774c6e8ead9031b771da3f2aeb68aa3297", "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/BicartesianClosed.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/BicartesianClosed.agda", "max_line_length": 79, "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/BicartesianClosed.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": 109, "size": 421 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties of Any predicate transformer for fresh lists ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Fresh.Relation.Unary.Any.Properties where open import Level using (Level; _⊔_; Lift) open import Data.Bool.Base using (true; false) open import Data.Empty open import Data.Nat.Base using (ℕ; zero; suc) open import Data.Product using (_,_) open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂) open import Function using (_∘′_) open import Relation.Nullary.Reflects using (invert) open import Relation.Nullary open import Relation.Unary as U using (Pred) open import Relation.Binary as B using (Rel) open import Relation.Nary open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong) open import Data.List.Fresh open import Data.List.Fresh.Relation.Unary.All open import Data.List.Fresh.Relation.Unary.Any private variable a b p q r s : Level A : Set a B : Set b ------------------------------------------------------------------------ -- NonEmpty module _ {R : Rel A r} {P : Pred A p} where Any⇒NonEmpty : {xs : List# A R} → Any P xs → NonEmpty xs Any⇒NonEmpty {xs = cons x xs pr} p = cons x xs pr ------------------------------------------------------------------------ -- Correspondence between Any and All module _ {R : Rel A r} {P : Pred A p} {Q : Pred A q} (P⇒¬Q : ∀[ P ⇒ ∁ Q ]) where Any⇒¬All : {xs : List# A R} → Any P xs → ¬ (All Q xs) Any⇒¬All (here p) (q ∷ _) = P⇒¬Q p q Any⇒¬All (there ps) (_ ∷ qs) = Any⇒¬All ps qs All⇒¬Any : {xs : List# A R} → All P xs → ¬ (Any Q xs) All⇒¬Any (p ∷ _) (here q) = P⇒¬Q p q All⇒¬Any (_ ∷ ps) (there qs) = All⇒¬Any ps qs module _ {R : Rel A r} {P : Pred A p} {Q : Pred A q} (P? : Decidable P) where ¬All⇒Any : {xs : List# A R} → ¬ (All P xs) → Any (∁ P) xs ¬All⇒Any {xs = []} ¬ps = ⊥-elim (¬ps []) ¬All⇒Any {xs = x ∷# xs} ¬ps with P? x ... | true because [p] = there (¬All⇒Any (¬ps ∘′ (invert [p] ∷_))) ... | false because [¬p] = here (invert [¬p]) ¬Any⇒All : {xs : List# A R} → ¬ (Any P xs) → All (∁ P) xs ¬Any⇒All {xs = []} ¬ps = [] ¬Any⇒All {xs = x ∷# xs} ¬ps with P? x ... | true because [p] = ⊥-elim (¬ps (here (invert [p]))) ... | false because [¬p] = invert [¬p] ∷ ¬Any⇒All (¬ps ∘′ there) ------------------------------------------------------------------------ -- remove module _ {R : Rel A r} {P : Pred A p} where length-remove : {xs : List# A R} (k : Any P xs) → length xs ≡ suc (length (xs ─ k)) length-remove (here _) = refl length-remove (there p) = cong suc (length-remove p) ------------------------------------------------------------------------ -- append module _ {R : Rel A r} {P : Pred A p} where append⁺ˡ : {xs ys : List# A R} {ps : All (_# ys) xs} → Any P xs → Any P (append xs ys ps) append⁺ˡ (here px) = here px append⁺ˡ (there p) = there (append⁺ˡ p) append⁺ʳ : {xs ys : List# A R} {ps : All (_# ys) xs} → Any P ys → Any P (append xs ys ps) append⁺ʳ {xs = []} p = p append⁺ʳ {xs = x ∷# xs} p = there (append⁺ʳ p) append⁻ : ∀ xs {ys : List# A R} {ps : All (_# ys) xs} → Any P (append xs ys ps) → Any P xs ⊎ Any P ys append⁻ [] p = inj₂ p append⁻ (x ∷# xs) (here px) = inj₁ (here px) append⁻ (x ∷# xs) (there p) = Sum.map₁ there (append⁻ xs p)
{ "alphanum_fraction": 0.5048543689, "avg_line_length": 35.02, "ext": "agda", "hexsha": "f4d3a8cdf1ef6ff7716051a514baeba4030bdaf1", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda", "max_line_length": 80, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 1191, "size": 3502 }
module Web.Semantic.DL.Category.Properties where open import Web.Semantic.DL.Category.Properties.Equivalence public using ( ≣-refl ; ≣-sym ; ≣-trans ) open import Web.Semantic.DL.Category.Properties.Composition public using ( compose-resp-≣ ; compose-unit₁ ; compose-unit₂ ; compose-assoc ) open import Web.Semantic.DL.Category.Properties.Tensor public using ( tensor-resp-≣ ; tensor-resp-id ; tensor-resp-compose ; symm-iso ; assoc-iso ; assoc⁻¹-iso ; unit₁-iso ; unit₁⁻¹-iso ; unit₂-iso ; unit₂⁻¹-iso ; assoc-unit ; assoc-assoc ; assoc-symm ; unit₁-natural ; unit₂-natural ; symm-natural ; assoc-natural )
{ "alphanum_fraction": 0.7277070064, "avg_line_length": 39.25, "ext": "agda", "hexsha": "ba03209ee5665da668fedf4fa31bc2b2dd9c2bae", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z", "max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z", "max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-web-semantic", "max_forks_repo_path": "src/Web/Semantic/DL/Category/Properties.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bblfish/agda-web-semantic", "max_issues_repo_path": "src/Web/Semantic/DL/Category/Properties.agda", "max_line_length": 72, "max_stars_count": 9, "max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/agda-web-semantic", "max_stars_repo_path": "src/Web/Semantic/DL/Category/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z", "num_tokens": 194, "size": 628 }
{-# OPTIONS --without-K #-} module Lecture3 where import Lecture2 open Lecture2 public data unit : U where star : unit 𝟙 = unit ind-unit : {i : Level} {P : unit → UU i} → P star → ((x : unit) → P x) ind-unit p star = p data empty : U where 𝟘 = empty ind-empty : {i : Level} {P : empty → UU i} → ((x : empty) → P x) ind-empty () ¬ : {i : Level} → UU i → UU i ¬ A = A → empty data bool : U where true false : bool not : bool → bool not true = false not false = true ind-bool : {i : Level} {P : bool → UU i} → P true → P false → (x : bool) → P x ind-bool Pt Pf true = Pt ind-bool Pt Pf false = Pf data coprod {i j : Level} (A : UU i) (B : UU j) : UU (i ⊔ j) where inl : A → coprod A B inr : B → coprod A B data Sigma {i j : Level} (A : UU i) (B : A → UU j) : UU (i ⊔ j) where dpair : (x : A) → (B x → Sigma A B) Σ = Sigma ind-Σ : {i j k : Level} {A : UU i} {B : A → UU j} {C : Σ A B → UU k} → ((x : A) (y : B x) → C (dpair x y)) → ((t : Σ A B) → C t) ind-Σ f (dpair x y) = f x y pr1 : {i j : Level} {A : UU i} {B : A → UU j} → Sigma A B → A pr1 (dpair a b) = a pr2 : {i j : Level} {A : UU i} {B : A → UU j} → (t : Sigma A B) → B (pr1 t) pr2 (dpair a b) = b weaken : {i j : Level} (A : UU i) (B : UU j) → (A → UU j) weaken A B = λ a → B prod : {i j : Level} (A : UU i) (B : UU j) → UU (i ⊔ j) prod A B = Sigma A (λ a → B) _×_ : {i j : Level} (A : UU i) (B : UU j) → UU (i ⊔ j) A × B = prod A B -- WARNING, can't use pair in pattern matching as it's not recognized as a ctor pair : {i j : Level} {A : UU i} {B : UU j} → A → (B → prod A B) pair a b = dpair a b -- Pointed types U-pt : Type U-pt = Sigma U (λ X → X) -- Graphs Gph : Type Gph = Sigma U (λ X → (X → X → U)) -- Reflexive graphs rGph : Type rGph = Sigma U (λ X → Sigma (X → X → U) (λ R → (x : X) → R x x)) -- Finite sets Fin : ℕ → U Fin Nzero = empty Fin (Nsucc n) = coprod (Fin n) unit -- Observational equality on the natural numbers EqN : ℕ → (ℕ → U) EqN Nzero Nzero = 𝟙 EqN Nzero (Nsucc n) = 𝟘 EqN (Nsucc m) Nzero = 𝟘 EqN (Nsucc m) (Nsucc n) = EqN m n -- The integers ℤ : U ℤ = coprod ℕ (coprod unit ℕ) -- ^ ^^^^ ^ -- (-∞, -1] 0 [1, ∞) -- -(n+1) n+1 -- Inclusion of the negative integers in-neg : ℕ → ℤ in-neg n = inl n -- Negative one Zneg-one : ℤ Zneg-one = in-neg Nzero -- Zero Zzero : ℤ Zzero = inr (inl star) -- One Zone : ℤ Zone = inr (inr Nzero) -- Inclusion of the positive integers in-pos : ℕ → ℤ in-pos n = inr (inr n) -- Since Agda is already strong with nested induction, I dont think we need this definition. ind-ℤ : {i : Level} (P : ℤ → UU i) → P Zneg-one → ((n : ℕ) → P (inl n) → P (inl (Nsucc n))) → P Zzero → P Zone → ((n : ℕ) → P (inr (inr (n))) → P (inr (inr (Nsucc n)))) → (k : ℤ) → P k ind-ℤ P p-1 p-S p0 p1 pS (inl Nzero) = p-1 ind-ℤ P p-1 p-S p0 p1 pS (inl (Nsucc x)) = p-S x (ind-ℤ P p-1 p-S p0 p1 pS (inl x)) ind-ℤ P p-1 p-S p0 p1 pS (inr (inl star)) = p0 ind-ℤ P p-1 p-S p0 p1 pS (inr (inr Nzero)) = p1 ind-ℤ P p-1 p-S p0 p1 pS (inr (inr (Nsucc x))) = pS x (ind-ℤ P p-1 p-S p0 p1 pS (inr (inr (x)))) Zsucc : ℤ → ℤ Zsucc (inl Nzero) = Zzero Zsucc (inl (Nsucc x)) = inl x Zsucc (inr (inl star)) = Zone Zsucc (inr (inr x)) = inr (inr (Nsucc x)) -- Exercise 3.1 -- In this exercise we were asked to show that (A + ¬A) implies (¬¬A → A). -- In other words, we get double negation elimination for the types that are decidable dne-dec : {i : Level} (A : UU i) → (coprod A (¬ A)) → (¬ (¬ A) → A) dne-dec A (inl x) = λ f → x dne-dec A (inr x) = λ f → ind-empty (f x) -- Exercise 3.3 -- In this exercise we were asked to show that the observational equality on ℕ is an equivalence relation. reflexive-EqN : (n : ℕ) → EqN n n reflexive-EqN Nzero = star reflexive-EqN (Nsucc n) = reflexive-EqN n symmetric-EqN : (m n : ℕ) → EqN m n → EqN n m symmetric-EqN Nzero Nzero t = t symmetric-EqN Nzero (Nsucc n) t = t symmetric-EqN (Nsucc n) Nzero t = t symmetric-EqN (Nsucc m) (Nsucc n) t = symmetric-EqN m n t transitive-EqN : (l m n : ℕ) → EqN l m → EqN m n → EqN l n transitive-EqN Nzero Nzero Nzero s t = star transitive-EqN (Nsucc n) Nzero Nzero s t = ind-empty s transitive-EqN Nzero (Nsucc n) Nzero s t = ind-empty s transitive-EqN Nzero Nzero (Nsucc n) s t = ind-empty t transitive-EqN (Nsucc l) (Nsucc m) Nzero s t = ind-empty t transitive-EqN (Nsucc l) Nzero (Nsucc n) s t = ind-empty s transitive-EqN Nzero (Nsucc m) (Nsucc n) s t = ind-empty s transitive-EqN (Nsucc l) (Nsucc m) (Nsucc n) s t = transitive-EqN l m n s t -- Exercise 3.4 -- In this exercise we were asked to show that observational equality on the natural numbers is the least reflexive relation, in the sense that it implies all other reflexive relation. As we will see once we introduce the identity type, it follows that observationally equal natural numbers can be identified. -- We first make an auxilary construction, where the relation is quantified over inside the scope of the variables n and m. This is to ensure that the inductive hypothesis is strong enough to make the induction go through. least-reflexive-EqN' : {i : Level} (n m : ℕ) (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) → EqN n m → R n m least-reflexive-EqN' Nzero Nzero R ρ p = ρ Nzero least-reflexive-EqN' Nzero (Nsucc m) R ρ = ind-empty least-reflexive-EqN' (Nsucc n) Nzero R ρ = ind-empty least-reflexive-EqN' (Nsucc n) (Nsucc m) R ρ = least-reflexive-EqN' n m (λ x y → R (Nsucc x) (Nsucc y)) (λ x → ρ (Nsucc x)) -- Now we solve the actual exercise by rearranging the order of the variables. least-reflexive-EqN : {i : Level} {R : ℕ → ℕ → UU i} (ρ : (n : ℕ) → R n n) → (n m : ℕ) → EqN n m → R n m least-reflexive-EqN ρ n m p = least-reflexive-EqN' n m _ ρ p -- Exercise 3.5 -- In this exercise we were asked to show that any function on the natural numbers preserves observational equality. The quick solution uses the fact that observational equality is the least reflexive relation. preserve_EqN : (f : ℕ → ℕ) (n m : ℕ) → (EqN n m) → (EqN (f n) (f m)) preserve_EqN f = least-reflexive-EqN {_} {λ x y → EqN (f x) (f y)} (λ x → reflexive-EqN (f x)) -- Exercise 3.6 -- In this exercise we were asked to construct the relations ≤ and < on the natural numbers, and show basic properties about them. -- Definition of ≤ leqN : ℕ → ℕ → U leqN Nzero Nzero = unit leqN Nzero (Nsucc m) = unit leqN (Nsucc n) Nzero = empty leqN (Nsucc n) (Nsucc m) = leqN n m _≤_ = leqN -- Definition of < leN : ℕ → ℕ → U leN Nzero Nzero = empty leN Nzero (Nsucc m) = unit leN (Nsucc n) Nzero = empty leN (Nsucc n) (Nsucc m) = leN n m _<_ = leN reflexive-leqN : (n : ℕ) → n ≤ n reflexive-leqN Nzero = star reflexive-leqN (Nsucc n) = reflexive-leqN n anti-reflexive-leN : (n : ℕ) → ¬ (n < n) anti-reflexive-leN Nzero = ind-empty anti-reflexive-leN (Nsucc n) = anti-reflexive-leN n transitive-leqN : (n m l : ℕ) → (n ≤ m) → (m ≤ l) → (n ≤ l) transitive-leqN Nzero Nzero Nzero p q = reflexive-leqN Nzero transitive-leqN Nzero Nzero (Nsucc l) p q = q transitive-leqN Nzero (Nsucc m) Nzero p q = star transitive-leqN Nzero (Nsucc m) (Nsucc l) p q = star transitive-leqN (Nsucc n) Nzero l p q = ind-empty p transitive-leqN (Nsucc n) (Nsucc m) Nzero p q = ind-empty q transitive-leqN (Nsucc n) (Nsucc m) (Nsucc l) p q = transitive-leqN n m l p q transitive-leN : (n m l : ℕ) → (leN n m) → (leN m l) → (leN n l) transitive-leN Nzero Nzero Nzero p q = p transitive-leN Nzero Nzero (Nsucc l) p q = q transitive-leN Nzero (Nsucc m) Nzero p q = ind-empty q transitive-leN Nzero (Nsucc m) (Nsucc l) p q = star transitive-leN (Nsucc n) Nzero l p q = ind-empty p transitive-leN (Nsucc n) (Nsucc m) Nzero p q = ind-empty q transitive-leN (Nsucc n) (Nsucc m) (Nsucc l) p q = transitive-leN n m l p q succ-leN : (n : ℕ) → leN n (Nsucc n) succ-leN Nzero = star succ-leN (Nsucc n) = succ-leN n -- Exercise 3.7 -- With the construction of the divisibility relation we open the door to basic number theory. divides : (d n : ℕ) → U divides d n = Σ ℕ (λ m → EqN (d ** m) n) -- Exercise 3.8 -- In this exercise we were asked to construct observational equality on the booleans. This construction is analogous to, but simpler than, the construction of observational equality on the natural numbers. Eq2 : bool → bool → U Eq2 true true = unit Eq2 true false = empty Eq2 false true = empty Eq2 false false = unit reflexive-Eq2 : (x : bool) → Eq2 x x reflexive-Eq2 true = star reflexive-Eq2 false = star least-reflexive-Eq2 : {i : Level} (R : bool → bool → UU i) (ρ : (x : bool) → R x x) (x y : bool) → Eq2 x y → R x y least-reflexive-Eq2 R ρ true true p = ρ true least-reflexive-Eq2 R ρ true false p = ind-empty p least-reflexive-Eq2 R ρ false true p = ind-empty p least-reflexive-Eq2 R ρ false false p = ρ false -- Exercise 3.9 -- In this exercise we were asked to show that 1 + 1 satisfies the induction principle of the booleans. In other words, type theory cannot distinguish the booleans from the type 1 + 1. We will see later that they are indeed equivalent types. t0 : coprod unit unit t0 = inl star t1 : coprod unit unit t1 = inr star ind-coprod-unit-unit : {i : Level} {P : coprod unit unit → UU i} → P t0 → P t1 → (x : coprod unit unit) → P x ind-coprod-unit-unit p0 p1 (inl star) = p0 ind-coprod-unit-unit p0 p1 (inr star) = p1 -- Exercise 3.10 -- In this exercise we were asked to define the relations ≤ and < on the integers. As a criterion of correctness, we were then also asked to show that the type of all integers l satisfying k ≤ l satisfy the induction principle of the natural numbers. -- It turns out that this is a long exercise that requires to develop intermediate properties of the relation ≤, involving long proofs. None of them is really hard, but they are probably unintelligible because induction on the integers splits into so many cases. leqZ : ℤ → ℤ → U leqZ (inl Nzero) (inl Nzero) = unit leqZ (inl Nzero) (inl (Nsucc x)) = empty leqZ (inl Nzero) (inr l) = unit leqZ (inl (Nsucc x)) (inl Nzero) = unit leqZ (inl (Nsucc x)) (inl (Nsucc y)) = leqZ (inl x) (inl y) leqZ (inl (Nsucc x)) (inr l) = unit leqZ (inr k) (inl x) = empty leqZ (inr (inl star)) (inr l) = unit leqZ (inr (inr x)) (inr (inl star)) = empty leqZ (inr (inr Nzero)) (inr (inr y)) = unit leqZ (inr (inr (Nsucc x))) (inr (inr Nzero)) = empty leqZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) = leqZ (inr (inr (x))) (inr (inr (y))) reflexive-leqZ : (k : ℤ) → leqZ k k reflexive-leqZ (inl Nzero) = star reflexive-leqZ (inl (Nsucc x)) = reflexive-leqZ (inl x) reflexive-leqZ (inr (inl star)) = star reflexive-leqZ (inr (inr Nzero)) = star reflexive-leqZ (inr (inr (Nsucc x))) = reflexive-leqZ (inr (inr x)) transitive-leqZ : (k l m : ℤ) → leqZ k l → leqZ l m → leqZ k m transitive-leqZ (inl Nzero) (inl Nzero) m p q = q transitive-leqZ (inl Nzero) (inl (Nsucc x)) m p q = ind-empty p transitive-leqZ (inl Nzero) (inr (inl star)) (inl Nzero) star q = reflexive-leqZ (inl Nzero) transitive-leqZ (inl Nzero) (inr (inl star)) (inl (Nsucc x)) star q = ind-empty q transitive-leqZ (inl Nzero) (inr (inl star)) (inr (inl star)) star q = star transitive-leqZ (inl Nzero) (inr (inl star)) (inr (inr x)) star q = star transitive-leqZ (inl Nzero) (inr (inr x)) (inl y) star q = ind-empty q transitive-leqZ (inl Nzero) (inr (inr x)) (inr (inl star)) star q = ind-empty q transitive-leqZ (inl Nzero) (inr (inr x)) (inr (inr y)) star q = star transitive-leqZ (inl (Nsucc x)) (inl Nzero) (inl Nzero) star q = star transitive-leqZ (inl (Nsucc x)) (inl Nzero) (inl (Nsucc y)) star q = ind-empty q transitive-leqZ (inl (Nsucc x)) (inl Nzero) (inr m) star q = star transitive-leqZ (inl (Nsucc x)) (inl (Nsucc y)) (inl Nzero) p q = star transitive-leqZ (inl (Nsucc x)) (inl (Nsucc y)) (inl (Nsucc z)) p q = transitive-leqZ (inl x) (inl y) (inl z) p q transitive-leqZ (inl (Nsucc x)) (inl (Nsucc y)) (inr m) p q = star transitive-leqZ (inl (Nsucc x)) (inr y) (inl z) star q = ind-empty q transitive-leqZ (inl (Nsucc x)) (inr y) (inr z) star q = star transitive-leqZ (inr k) (inl x) m p q = ind-empty p transitive-leqZ (inr (inl star)) (inr l) (inl x) star q = ind-empty q transitive-leqZ (inr (inl star)) (inr l) (inr m) star q = star transitive-leqZ (inr (inr x)) (inr (inl star)) m p q = ind-empty p transitive-leqZ (inr (inr Nzero)) (inr (inr Nzero)) m p q = q transitive-leqZ (inr (inr Nzero)) (inr (inr (Nsucc y))) (inl x) star q = ind-empty q transitive-leqZ (inr (inr Nzero)) (inr (inr (Nsucc y))) (inr (inl star)) star q = ind-empty q transitive-leqZ (inr (inr Nzero)) (inr (inr (Nsucc y))) (inr (inr z)) star q = star transitive-leqZ (inr (inr (Nsucc x))) (inr (inr Nzero)) m p q = ind-empty p transitive-leqZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) (inl z) p q = ind-empty q transitive-leqZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) (inr (inl star)) p q = ind-empty q transitive-leqZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) (inr (inr Nzero)) p q = ind-empty q transitive-leqZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) (inr (inr (Nsucc z))) p q = transitive-leqZ (inr (inr x)) (inr (inr y)) (inr (inr z)) p q succ-leqZ : (k : ℤ) → leqZ k (Zsucc k) succ-leqZ (inl Nzero) = star succ-leqZ (inl (Nsucc Nzero)) = star succ-leqZ (inl (Nsucc (Nsucc x))) = succ-leqZ (inl (Nsucc x)) succ-leqZ (inr (inl star)) = star succ-leqZ (inr (inr Nzero)) = star succ-leqZ (inr (inr (Nsucc x))) = succ-leqZ (inr (inr x)) leqZ-succ-leqZ : (k l : ℤ) → leqZ k l → leqZ k (Zsucc l) leqZ-succ-leqZ k l p = transitive-leqZ k l (Zsucc l) p (succ-leqZ l) leZ : ℤ → ℤ → U leZ (inl Nzero) (inl x) = empty leZ (inl Nzero) (inr y) = unit leZ (inl (Nsucc x)) (inl Nzero) = unit leZ (inl (Nsucc x)) (inl (Nsucc y)) = leZ (inl x) (inl y) leZ (inl (Nsucc x)) (inr y) = unit leZ (inr x) (inl y) = empty leZ (inr (inl star)) (inr (inl star)) = empty leZ (inr (inl star)) (inr (inr x)) = unit leZ (inr (inr x)) (inr (inl star)) = empty leZ (inr (inr Nzero)) (inr (inr Nzero)) = empty leZ (inr (inr Nzero)) (inr (inr (Nsucc y))) = unit leZ (inr (inr (Nsucc x))) (inr (inr Nzero)) = empty leZ (inr (inr (Nsucc x))) (inr (inr (Nsucc y))) = leZ (inr (inr x)) (inr (inr y)) fam-shift-leqZ : (k : ℤ) {i : Level} (P : (l : ℤ) → leqZ k l → UU i) → (l : ℤ) → (leqZ (Zsucc k) l) → UU i fam-shift-leqZ k P l p = P l (transitive-leqZ k (Zsucc k) l (succ-leqZ k) p) -- ind-Z-leqZ : (k : ℤ) {i : Level} (P : (l : ℤ) → (leqZ k l) → UU i) → -- P k (reflexive-leqZ k) → -- ((l : ℤ) (p : leqZ k l) → P l p → P (Zsucc l) (leqZ-succ-leqZ k l p)) → -- (l : ℤ) (p : leqZ k l) → P l p -- ind-Z-leqZ (inl Nzero) P pk pS (inl Nzero) star = pk -- ind-Z-leqZ (inl Nzero) P pk pS (inl (Nsucc x)) () -- ind-Z-leqZ (inl Nzero) P pk pS (inr (inl star)) star = pS (inl Nzero) star pk -- ind-Z-leqZ (inl Nzero) P pk pS (inr (inr Nzero)) star = pS (inr (inl star)) star (pS (inl Nzero) star pk) -- ind-Z-leqZ (inl Nzero) P pk pS (inr (inr (Nsucc x))) star = pS (inr (inr x)) star (ind-Z-leqZ (inl Nzero) P pk pS (inr (inr x)) star) -- ind-Z-leqZ (inl (Nsucc Nzero)) {i} P pk pS (inl Nzero) star = pS {!!} {!!} {!!} -- ind-Z-leqZ (inl (Nsucc (Nsucc x))) {i} P pk pS (inl Nzero) star = {!!} -- ind-Z-leqZ (inl (Nsucc x)) P pk pS (inl (Nsucc y)) p = {!!} -- ind-Z-leqZ (inl (Nsucc x)) P pk pS (inr y) p = {!!} -- ind-Z-leqZ (inr k) P pk pS l p = {!!} -- Exercise 3.11 Zpred : ℤ → ℤ Zpred (inl x) = inl (Nsucc x) Zpred (inr (inl star)) = inl Nzero Zpred (inr (inr Nzero)) = inr (inl star) Zpred (inr (inr (Nsucc x))) = inr (inr x) -- Exercise 3.12 Zadd : ℤ → ℤ → ℤ Zadd (inl Nzero) l = Zpred l Zadd (inl (Nsucc x)) l = Zpred (Zadd (inl x) l) Zadd (inr (inl star)) l = l Zadd (inr (inr Nzero)) l = Zsucc l Zadd (inr (inr (Nsucc x))) l = Zsucc (Zadd (inr (inr x)) l) Zneg : ℤ → ℤ Zneg (inl x) = inr (inr x) Zneg (inr (inl star)) = inr (inl star) Zneg (inr (inr x)) = inl x
{ "alphanum_fraction": 0.6227120147, "avg_line_length": 38.322815534, "ext": "agda", "hexsha": "a16826f44c06bdf7148fe15178743ab2af5034eb", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2018-06-25T15:05:21.000Z", "max_forks_repo_forks_event_min_datetime": "2018-02-22T19:58:46.000Z", "max_forks_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "glangmead/hott_cmu80818", "max_forks_repo_path": "Lecture3.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b", "max_issues_repo_issues_event_max_datetime": "2018-03-25T14:44:31.000Z", "max_issues_repo_issues_event_min_datetime": "2018-02-22T21:01:16.000Z", "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "glangmead/hott_cmu80818", "max_issues_repo_path": "Lecture3.agda", "max_line_length": 309, "max_stars_count": 4, "max_stars_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "glangmead/hott_cmu80818", "max_stars_repo_path": "Lecture3.agda", "max_stars_repo_stars_event_max_datetime": "2018-09-04T02:52:25.000Z", "max_stars_repo_stars_event_min_datetime": "2018-05-03T20:32:19.000Z", "num_tokens": 6597, "size": 15789 }
{-# OPTIONS --without-K #-} module PathStructure.Product {a b} {A : Set a} {B : Set b} where open import Equivalence open import PathOperations open import Types split-path : {x y : A × B} → x ≡ y → (π₁ x ≡ π₁ y) × (π₂ x ≡ π₂ y) split-path p = ap π₁ p , ap π₂ p merge-path : {x₁ x₂ : A} {y₁ y₂ : B} → (x₁ ≡ x₂) × (y₁ ≡ y₂) → Id (A × B) (x₁ , y₁) (x₂ , y₂) merge-path (p , q) = ap₂ _,_ p q split-merge-eq : {x y : A × B} → (x ≡ y) ≃ (π₁ x ≡ π₁ y) × (π₂ x ≡ π₂ y) split-merge-eq = split-path , (merge-path , λ pq → J (λ _ _ p → ∀ {b₁ b₂} (q : b₁ ≡ b₂) → split-path (merge-path (p , q)) ≡ p , q) (λ _ q → J (λ _ _ q → split-path (merge-path (refl , q)) ≡ refl , q) (λ _ → refl) _ _ q) _ _ (π₁ pq) (π₂ pq)) , (merge-path , J (λ _ _ p → merge-path (split-path p) ≡ p) (λ _ → refl) _ _)
{ "alphanum_fraction": 0.49003517, "avg_line_length": 29.4137931034, "ext": "agda", "hexsha": "b564bd0a737a1ff686bd2bccf0e880d3c4b0742e", "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": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "vituscze/HoTT-lectures", "max_forks_repo_path": "src/PathStructure/Product.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "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": "vituscze/HoTT-lectures", "max_issues_repo_path": "src/PathStructure/Product.agda", "max_line_length": 66, "max_stars_count": null, "max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "vituscze/HoTT-lectures", "max_stars_repo_path": "src/PathStructure/Product.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 372, "size": 853 }
module Data.List.Size where import Lvl open import Data.List open import Logic.Predicate open import Logic.Propositional open import Numeral.Natural open import Numeral.Natural.Oper open import Relator.Equals open import Relator.Equals.Proofs open import Structure.Function.Domain open import Type open import Data.Boolean private variable ℓ : Lvl.Level private variable T : Type{ℓ} -- TODO: For general types, not just Bool. index : (T → ℕ) → (List(T) → ℕ) index f ∅ = 1 index f (x ⊰ l) = (2 ^ 𝐒(f(x))) ⋅ index f l -- TODO: 2 is temporary. Use unique primes (does not have to include all or even be in order). {- index-injective : ∀{f : T → ℕ} → ⦃ Injective(f) ⦄ → Injective(index f) index-injective = {!!} -}
{ "alphanum_fraction": 0.7046703297, "avg_line_length": 26, "ext": "agda", "hexsha": "6d61bf67f7a16c0922f5f83f72fdfe6621008756", "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/Size.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/Size.agda", "max_line_length": 138, "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/Size.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": 214, "size": 728 }
{-# OPTIONS --cubical #-} module all where import 00-preamble import 02-pi import 03-natural-numbers import 04-inductive-types import 05-identity-types import 06-universes import 07-finite-sets import 08-equivalences import 09-contractible-types import 10-fundamental-theorem import 11-truncation-levels import 12-function-extensionality import 13-propositional-truncation import 14-univalence import 15-groups import 16-sets import 17-number-theory import 18-circle import 19-fundamental-cover import 20-pullbacks import 21-pushouts import 22-cubical-diagrams -- import 22-descent -- import 23-id-pushout -- import 24-sequences import abelian-groups import abelian-subgroups -- import categories -- import coinductive-types import combinatorial-objects import cubical-circle -- import dn-sheaves -- import free-group -- import group-completion -- import hott-i import ideals import integers -- import lists -- import localizations-rings -- import models -- import mwe import polynomial-rings import quotient-groups -- import rational-numbers -- import rings import rings-with-properties -- import SAT-solver import subgroups -- import subrings -- import subuniverses
{ "alphanum_fraction": 0.8076923077, "avg_line_length": 21.2727272727, "ext": "agda", "hexsha": "5676dac8d42b0aa617cf648ec16059d9849e883f", "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": "22023fd35023cb6804424ce12cd10d252b80fd29", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "tmoux/HoTT-Intro", "max_forks_repo_path": "Agda/all.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29", "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": "tmoux/HoTT-Intro", "max_issues_repo_path": "Agda/all.agda", "max_line_length": 34, "max_stars_count": null, "max_stars_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "tmoux/HoTT-Intro", "max_stars_repo_path": "Agda/all.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 321, "size": 1170 }
{- This second-order signature was created from the following second-order syntax description: syntax PDiff | PD type * : 0-ary term zero : * | 𝟘 add : * * -> * | _⊕_ l20 one : * | 𝟙 mult : * * -> * | _⊗_ l20 neg : * -> * | ⊖_ r50 pd : *.* * -> * | ∂_∣_ 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) (∂⊕) a : * |> x : * |- d0 (add (x, a)) = one (∂⊗) a : * |> x : * |- d0 (mult(a, x)) = a (∂C) f : (*,*).* |> x : * y : * |- d1 (d0 (f[x,y])) = d0 (d1 (f[x,y])) (∂Ch₂) f : (*,*).* g h : *.* |> x : * |- d0 (f[g[x], h[x]]) = add (mult(pd(z. f[z, h[x]], g[x]), d0(g[x])), mult(pd(z. f[g[x], z], h[x]), d0(h[x]))) (∂Ch₁) f g : *.* |> x : * |- d0 (f[g[x]]) = mult (pd (z. f[z], g[x]), d0(g[x])) -} module PDiff.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 PDₒ : Set where zeroₒ addₒ oneₒ multₒ negₒ pdₒ : PDₒ -- Term signature PD:Sig : Signature PDₒ PD:Sig = sig λ { zeroₒ → ⟼₀ * ; addₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ * ; oneₒ → ⟼₀ * ; multₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ * ; negₒ → (⊢₀ *) ⟼₁ * ; pdₒ → (* ⊢₁ *) , (⊢₀ *) ⟼₂ * } open Signature PD:Sig public
{ "alphanum_fraction": 0.4442613948, "avg_line_length": 28.0153846154, "ext": "agda", "hexsha": "d91de6595d33cd7b66ecdffee2f73fa302418232", "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/PDiff/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/PDiff/Signature.agda", "max_line_length": 151, "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/PDiff/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": 939, "size": 1821 }
{-# OPTIONS --without-K --safe #-} module Definition.Typed.RedSteps where open import Definition.Untyped open import Definition.Typed -- Concatenation of type reduction closures _⇨*_ : ∀ {Γ A B C} → Γ ⊢ A ⇒* B → Γ ⊢ B ⇒* C → Γ ⊢ A ⇒* C id ⊢B ⇨* B⇒C = B⇒C (A⇒A′ ⇨ A′⇒B) ⇨* B⇒C = A⇒A′ ⇨ (A′⇒B ⇨* B⇒C) -- Concatenation of term reduction closures _⇨∷*_ : ∀ {Γ A t u r} → Γ ⊢ t ⇒* u ∷ A → Γ ⊢ u ⇒* r ∷ A → Γ ⊢ t ⇒* r ∷ A id ⊢u ⇨∷* u⇒r = u⇒r (t⇒t′ ⇨ t′⇒u) ⇨∷* u⇒r = t⇒t′ ⇨ (t′⇒u ⇨∷* u⇒r) -- Conversion of reduction closures conv* : ∀ {Γ A B t u} → Γ ⊢ t ⇒* u ∷ A → Γ ⊢ A ≡ B → Γ ⊢ t ⇒* u ∷ B conv* (id x) A≡B = id (conv x A≡B) conv* (x ⇨ d) A≡B = conv x A≡B ⇨ conv* d A≡B -- Universe of reduction closures univ* : ∀ {Γ A B} → Γ ⊢ A ⇒* B ∷ U → Γ ⊢ A ⇒* B univ* (id x) = id (univ x) univ* (x ⇨ A⇒B) = univ x ⇨ univ* A⇒B -- Application substitution of reduction closures app-subst* : ∀ {Γ A B t t′ a} → Γ ⊢ t ⇒* t′ ∷ Π A ▹ B → Γ ⊢ a ∷ A → Γ ⊢ t ∘ a ⇒* t′ ∘ a ∷ B [ a ] app-subst* (id x) a₁ = id (x ∘ⱼ a₁) app-subst* (x ⇨ t⇒t′) a₁ = app-subst x a₁ ⇨ app-subst* t⇒t′ a₁
{ "alphanum_fraction": 0.4990723562, "avg_line_length": 31.7058823529, "ext": "agda", "hexsha": "7e16c6aa2a473328e0c91d4c480cbb8a3444b247", "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/RedSteps.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/RedSteps.agda", "max_line_length": 72, "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/RedSteps.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 584, "size": 1078 }
open import Agda.Primitive variable A : Set _ levelOf : A → Level levelOf {a} _ = a
{ "alphanum_fraction": 0.6704545455, "avg_line_length": 11, "ext": "agda", "hexsha": "8bcdf4d14f7c174e0f1416a7c5e8855a3750a2bd", "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/Issue5363.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/Issue5363.agda", "max_line_length": 26, "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/Issue5363.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": 30, "size": 88 }
open import Structures open import Data.String using (String; _≈?_) open import Data.List as L using (List; []; _∷_; [_]) open import Data.List.Categorical open import Data.Nat as ℕ using (ℕ; zero; suc; _+_) import Data.Nat.Properties as ℕ open import Data.Nat.DivMod open import Agda.Builtin.Nat using (div-helper; mod-helper) open import Data.Nat.Show using () renaming (show to showNat) open import Data.Vec as V using (Vec; []; _∷_) open import Data.Fin as F using (Fin; zero; suc; #_) open import Category.Monad open import Category.Monad.State open import Data.Product as Σ open import Data.Unit open import Data.Bool using (Bool; true; false; if_then_else_) open import Data.Maybe using (Maybe; just; nothing) open import Data.Fin using (Fin; zero; suc; fromℕ<) open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; sym; subst) open import Relation.Nullary open import Reflection hiding (return; _>>=_; _>>_) open import Reflection.Term import Reflection.Name as RN open import Function open import Strict open RawMonad ⦃ ... ⦄ Id = String data Op : Set where Plus Minus Times Divide Eq Neq And Gt Lt : Op data Expr : Set where Nat : ℕ → Expr BinOp : Op → Expr → Expr → Expr Var : String → Expr Call : Id → List Expr → Expr Function : Id → List Id → Expr → Expr Extern : Id → List Id → Expr Let : Id → Expr → Expr → Expr Assert : Expr → Expr If : Expr → Expr → Expr → Expr op-to-string : Op → String op-to-string Plus = "+" op-to-string Minus = "-" op-to-string Times = "*" op-to-string Divide = "/" op-to-string Eq = "==" op-to-string Neq = "!=" op-to-string And = "&&" op-to-string Gt = ">" op-to-string Lt = "<" indent : ℕ → String indent n = "" ++/ L.replicate n " " flatten-lets : List Expr → List (Id × Expr) × List Expr -- Lift all the assigns from the (potentially) nested let flatten-let : Expr → List (Id × Expr) × Expr flatten-let (Let x e e₁) = let a₁ , e = flatten-let e a₂ , e₁ = flatten-let e₁ in (a₁ ++ [(x , e)] ++ a₂) , e₁ flatten-let e@(Nat _) = [] , e flatten-let (BinOp x e e₁) = let a , e = flatten-let e a₁ , e₁ = flatten-let e₁ in (a ++ a₁) , BinOp x e e₁ flatten-let e@(Var _) = [] , e flatten-let (Call x es) = let as , es' = flatten-lets es in as , Call x es' flatten-let (Function x args e) = let a , e = flatten-let e in [] , (Function x args $ L.foldr (uncurry Let) e a) flatten-let e@(Extern _ _) = [] , e flatten-let (Assert e) = let a , e = flatten-let e in a , Assert e flatten-let (If e e₁ e₂) = let a , e = flatten-let e a₁ , e₁ = flatten-let e₁ a₂ , e₂ = flatten-let e₂ e₁' = L.foldr (uncurry Let) e₁ a₁ e₂' = L.foldr (uncurry Let) e₂ a₂ in a , (If e e₁' e₂') flatten-lets [] = [] , [] flatten-lets (e ∷ es) = let a , e = flatten-let e a₁ , es = flatten-lets es in (a ++ a₁) , (e ∷ es) {-# TERMINATING #-} expr-to-string : ℕ → Expr → String expr-to-string ind (Nat x) = indent ind ++ showNat x expr-to-string ind (BinOp op e e₁) = indent ind ++ "(" ++ expr-to-string 0 e ++ ") " ++ op-to-string op ++ " (" ++ expr-to-string 0 e₁ ++ ")" expr-to-string ind (Var x) = indent ind ++ x expr-to-string ind (Call f args) = indent ind ++ f ++ " (" ++ (", " ++/ L.map (expr-to-string 0) args) ++ ")" expr-to-string ind (Function n ids e) = indent ind ++ "def " ++ n ++ "(" ++ (", " ++/ ids) ++ "):\n" ++ expr-to-string (ind + 1) e expr-to-string ind (Extern n ids) = indent ind ++ "extern def " ++ n ++ " (" ++ (", " ++/ ids) ++ ")" expr-to-string ind (Let x e@(If _ _ _) e₁) = indent ind ++ "let " ++ x ++ " =\n" ++ expr-to-string (ind + 1) e ++ "\n" ++ expr-to-string ind e₁ expr-to-string ind (Let x e e₁) = indent ind ++ "let " ++ x ++ " = " ++ expr-to-string 0 e ++ "\n" ++ expr-to-string ind e₁ expr-to-string ind (Assert e) = indent ind ++ "assert (" ++ expr-to-string 0 e ++ ")" expr-to-string ind (If e e₁ e₂) = indent ind ++ "if " ++ expr-to-string 0 e ++ ":\n" ++ expr-to-string (ind + 1) e₁ ++ "\n" ++ indent ind ++ "else:\n" ++ expr-to-string (ind + 1) e₂ ++ "\n" -- Glorified sigma type for variable-assertion pairs record Assrt : Set where constructor mk field v : Id a : Expr Assrts = List Assrt -- The state used when traversing a Pi type. record PS : Set where field cnt : ℕ -- The source of unique variable names cur : Id -- Current variable name (used to collect assertions from its type) ctx : Telescope -- Names in the telscopes to resolve deBruijn indices ret : Id -- Variable that the function returns as a result. -- We assume that there is always a single variable and its name -- is known upfront. We need this to generate assertions from the -- return type. assrts : Assrts -- Assertions that we generate per each variable. kst : KS -- Compilation state (in case we have to extract some functions used in types) defaultPS : PS defaultPS = record { cnt = 1 ; cur = "" ; ctx = [] ; ret = "__ret" ; assrts = [] ; kst = defaultKS } record PatSt : Set where constructor mk field vars : List (String × ℕ) --Strings assigns : List (Id × Expr) conds : List Expr cnt : ℕ defaultPatSt : PatSt defaultPatSt = mk [] [] [] 1 SPS = State PS kompile-fun : Type → Term → Name → SKS $ Err Expr kompile-pi : Type → SPS $ Err ⊤ --{-# TERMINATING #-} kompile-cls : Clauses → (vars : Strings) → (ret : String) → SKS $ Err Expr kompile-clpats : Telescope → (pats : List $ Arg Pattern) → (exprs : List Expr) → PatSt → Err PatSt --{-# TERMINATING #-} kompile-term : Term → Telescope → SKS $ Err Expr kompile-funp : Type → Term → Name → SKS Prog kompile-funp ty te n = do (ok e) ← kompile-fun ty te n where (error x) → return $ error x let a , e = flatten-let e e = case a of λ where [] → e a → L.foldr (uncurry Let) e a return $ ok $ expr-to-string 0 e ++ "\n" private kf : String → Err Expr kf x = error $ "kompile-fun: " ++ x module R = RawMonadState (StateMonadState KS) kompile-fun ty (pat-lam [] []) n = return $ kf "got zero clauses in a lambda term" kompile-fun ty (pat-lam cs []) n = do kst ← R.get let (_ , ps) = kompile-pi ty $ record defaultPS{ kst = kst } rv = PS.ret ps ns = showName n vars = L.map proj₁ $ PS.ctx ps args = ok $ ", " ++/ vars ret-assrts = list-filter (λ where (mk v _) → v ≈? rv) $ PS.assrts ps arg-assrts = list-filter (dec-neg λ where (mk v _) → v ≈? rv) $ PS.assrts ps R.put $ PS.kst ps (ok b) ← kompile-cls cs vars rv where (error x) → return $ error x return $! ok $ Function ns vars $ flip (L.foldr (λ where (mk v a) → Let (v ++ "_assrt") $ Assert a)) arg-assrts $ Let rv b $ flip (L.foldr (λ where (mk v a) → Let (v ++ "_assrt") $ Assert a)) ret-assrts $ Var rv kompile-fun _ _ _ = return $ kf "expected pattern-matching lambda" private kp : ∀ {X} → String → SPS (Err X) kp x = return $ error $ "kompile-pi: " ++ x ke : ∀ {X} → String → SPS (Err X) ke x = return $ error x module P = RawMonadState (StateMonadState PS) infixl 10 _p+=c_ _p+=a_ _p+=c_ : PS → ℕ → PS ps p+=c n = record ps{ cnt = PS.cnt ps + n } _p+=a_ : PS → Assrt → PS ps p+=a a = record ps{ assrts = a ∷ PS.assrts ps } ps-fresh : String → SPS String ps-fresh x = do ps ← P.get P.modify (_p+=c 1) return $ x ++ showNat (PS.cnt ps) lift-ks : ∀ {X} → SKS X → SPS X lift-ks xf sps = let (x , sks) = xf (PS.kst sps) in x , record sps {kst = sks} sps-kompile-term : Term → SPS $ Err Expr sps-kompile-term t = do ps ← P.get lift-ks $ kompile-term t (PS.ctx ps) kompile-ty : Type → (pi-ok : Bool) → SPS (Err ⊤) kompile-ty (Π[ s ∶ arg i x ] y) false = kp "higher-order functions are not supported" kompile-ty (Π[ s ∶ ty@(arg i x) ] y) true = do v ← ps-fresh "x_" P.modify λ k → record k { cur = v } (ok t) ← kompile-ty x false where e → return e P.modify λ k → record k { cur = PS.ret k -- In case this is a return type ; ctx = PS.ctx k ++ L.[(v , ty)] } kompile-ty y true kompile-ty (con c args) pi-ok = kp $ "don't know how to handle `" ++ showName c ++ "` constructor" kompile-ty (def (quote ℕ) args) _ = return $ ok tt kompile-ty (def (quote Bool) args) _ = return $ ok tt kompile-ty (def (quote Fin) (arg _ x ∷ [])) _ = do ok p ← sps-kompile-term x where error x → ke x v ← PS.cur <$> P.get P.modify $ _p+=a (mk v (BinOp Lt (Var v) p)) return $ ok tt kompile-ty (def (quote _≡_) (_ ∷ arg _ ty ∷ arg _ x ∷ arg _ y ∷ [])) _ = do ok x ← sps-kompile-term x where error x → ke x ok y ← sps-kompile-term y where error x → ke x v ← PS.cur <$> P.get P.modify $ _p+=a (mk v (BinOp Eq x y)) return $ ok tt kompile-ty (def (quote Dec) (_ ∷ arg _ p ∷ [])) _ = do --_ ← kompile-ty p false return $ ok tt kompile-ty (def n _) _ = kp $ "cannot handle `" ++ showName n ++ "` type" kompile-ty t _ = kp $ "failed with the term `" ++ showTerm t ++ "`" kompile-pi x = kompile-ty x true -- The names in the telescopes very oftern are not unique, which -- would be pretty disasterous if the code generation relies on them. -- see https://github.com/agda/agda/issues/5048 for more details. -- -- This function simply ensures that variable names are unique in -- in the telescope. tel-rename : Telescope → (db : List (String × ℕ)) → Telescope tel-rename [] db = [] tel-rename ((v , ty) ∷ tel) db with list-find-el ((_≈? v) ∘ proj₁) db ... | just (_ , n) = (v ++ "_" ++ showNat n , ty) ∷ tel-rename tel (list-update-fst ((_≈? v) ∘ proj₁) db (Σ.map₂ suc)) ... | nothing = (v , ty) ∷ tel-rename tel ((v , 1) ∷ db) private kc : String → SKS $ Err Expr kc x = return $ error $ "kompile-cls: " ++ x _>>=e_ : ∀ {a}{X : Set a} → Err X → (X → SKS $ Err Expr) → SKS $ Err Expr (error s) >>=e _ = return $ error s (ok x) >>=e f = f x kompile-tel : Telescope → SPS (Err ⊤) kompile-tel [] = return $ ok tt kompile-tel ((v , t@(arg i x)) ∷ tel) = do (ok τ) ← kompile-ty x false where (error x) → return $ error x P.modify λ k → record k{ ctx = PS.ctx k ++ [( v , t )] } kompile-tel tel fold-expr : (Expr → Expr → Expr) → Expr → List Expr → Expr fold-expr f e [] = e fold-expr f _ (x ∷ []) = x fold-expr f e (x ∷ xs) = f x (fold-expr f e xs) emap : ∀ {a b}{X : Set a}{Y : Set b} → (X → Y) → Err X → Err Y emap f (error x) = error x emap f (ok x) = ok $ f x emap₂ : ∀ {a b c}{X : Set a}{Y : Set b}{Z : Set c} → (X → Y → Z) → Err X → Err Y → Err Z emap₂ f (error x) _ = error x emap₂ f _ (error x) = error x emap₂ f (ok x) (ok y) = ok (f x y) kompile-cls [] ctx ret = kc "zero clauses found" kompile-cls (clause tel ps t ∷ []) ctx ret = -- Make telscope names unique. let tel = (tel-rename $! tel) $! [] in kompile-clpats tel ps (L.map Var ctx) defaultPatSt >>=e λ pst → do let (mk vars assgns _ _) = pst --in ok t ← kompile-term t $! tel where (error x) → kc x let as = flip (L.foldr (uncurry Let)) assgns return $ ok $ as $ t --Let ret t --$ Var ret kompile-cls (absurd-clause tel ps ∷ []) ctx ret = -- Exactly the same as above -- We don't really need to make this call, but we keep it -- for sanity checks. I.e. if we'll get an error in the -- patterns, it will bubble up to the caller. kompile-clpats ((tel-rename $! tel) $! []) ps (L.map Var ctx) defaultPatSt >>=e λ pst → do return $ ok $ Assert (Nat 0) kompile-cls (absurd-clause tel ps ∷ ts@(_ ∷ _)) ctx ret = kompile-clpats ((tel-rename $! tel) $! []) ps (L.map Var ctx) defaultPatSt >>=e λ pst → do let (mk vars _ conds _) = pst cs = fold-expr (BinOp And) (Nat 1) conds ok r ← kompile-cls ts ctx ret where (error x) → kc x return $ ok $ If cs (Assert (Nat 0)) r kompile-cls (clause tel ps t ∷ ts@(_ ∷ _)) ctx ret = kompile-clpats ((tel-rename $! tel) $! []) ps (L.map Var ctx) defaultPatSt >>=e λ pst → do let (mk vars assgns conds _) = pst cs = fold-expr (BinOp And) (Nat 1) conds as = flip (L.foldr (uncurry Let)) assgns --ok t ← kompile-term t tel where (error x) → kc x --ok r ← kompile-cls ts ctx ret where (error x) → kc x --return $ ok $ If cs (as t) r t ← kompile-term t tel r ← kompile-cls ts ctx ret return $ emap₂ (If cs) (emap as t) r tel-lookup-name : Telescope → ℕ → Prog tel-lookup-name tel n with n ℕ.<? L.length (L.reverse tel) ... | yes n<l = ok $ proj₁ $ L.lookup (L.reverse tel) $ fromℕ< n<l ... | no _ = error "Variable lookup in telescope failed" private kcp : String → Err PatSt kcp x = error $ "kompile-clpats: " ++ x infixl 10 _+=c_ _+=a_ _+=v_ _+=n_ _+=c_ : PatSt → Expr → PatSt p +=c c = record p { conds = PatSt.conds p ++ [ c ] } _+=a_ : PatSt → _ → PatSt p +=a a = record p { assigns = PatSt.assigns p ++ [ a ] } _+=v_ : PatSt → String × ℕ → PatSt p +=v v = record p { vars = PatSt.vars p ++ [ v ] } _+=n_ : PatSt → ℕ → PatSt p +=n n = record p { cnt = PatSt.cnt p + 1 } pst-fresh : PatSt → String → Err $ String × PatSt pst-fresh pst x = return $ x ++ showNat (PatSt.cnt pst) , pst +=n 1 sz : List $ Arg Pattern → ℕ sz [] = 0 sz (arg i (con c ps) ∷ l) = 1 + sz ps + sz l sz (arg i _ ∷ l) = 1 + sz l sz++ : ∀ (a b : List $ Arg Pattern) → sz (a L.++ b) ≡ sz a + sz b sz++ [] b = refl sz++ (arg i (con c ps) ∷ a) b rewrite ℕ.+-assoc (sz ps) (sz a) (sz b) = cong suc (cong (sz ps +_) (sz++ a b)) sz++ (arg i (dot t) ∷ a) b = cong suc $ sz++ a b sz++ (arg i (var x₁) ∷ a) b = cong suc $ sz++ a b sz++ (arg i (lit l) ∷ a) b = cong suc $ sz++ a b sz++ (arg i (proj f) ∷ a) b = cong suc $ sz++ a b sz++ (arg i (absurd x₁) ∷ a) b = cong suc $ sz++ a b ++-strict : ∀ {X : Set} (a b : List X) → a ++ b ≡ a L.++ b ++-strict a b rewrite force′-≡ a L._++_ | force′-≡ b (L._++_ a) = refl ps++l<m : ∀ {m} ps l → suc (sz ps + sz l) ℕ.< suc m → sz (ps ++ l) ℕ.< m ps++l<m {m} ps l sz<m rewrite ++-strict ps l = subst (ℕ._< m) (sym $ sz++ ps l) (ℕ.≤-pred sz<m) a<b⇒a<1+b : ∀ {a b} → a ℕ.< b → a ℕ.< 1 + b a<b⇒a<1+b {a} {b} a<b = ℕ.s≤s (ℕ.<⇒≤ a<b) a+b<c⇒b<c : ∀ {a b c} → a + b ℕ.< c → b ℕ.< c a+b<c⇒b<c {zero} {b} {c} a+b<c = a+b<c a+b<c⇒b<c {suc a} {b} {suc c} a+b<c = a<b⇒a<1+b $ a+b<c⇒b<c (ℕ.≤-pred a+b<c) sz[l]<m : ∀ {m} ps l → suc (sz ps + sz l) ℕ.< suc m → sz l ℕ.< m sz[l]<m {m} ps l sz<m = a+b<c⇒b<c $ ℕ.≤-pred sz<m --kompile-cls : Clauses → (vars : Strings) → (ret : String) → SKS $ Err String kompile-clpats′ : ∀ {m} → Telescope → (pats : List $ Arg Pattern) → .(sz pats ℕ.< m) → (exprs : List Expr) → PatSt → Err PatSt kompile-clpats′ {suc m} tel (arg i (con (quote true) ps) ∷ l) sz<m (v ∷ ctx) pst = kompile-clpats′ tel l (sz[l]<m ps l sz<m) ctx $ pst +=c v {- != 0 -} --is true kompile-clpats′ {suc m} tel (arg i (con (quote false) ps) ∷ l) sz<m (v ∷ ctx) pst = kompile-clpats′ tel l (sz[l]<m ps l sz<m) ctx $ pst +=c BinOp Eq v (Nat 0) kompile-clpats′ {suc m} tel (arg i (con (quote ℕ.zero) ps) ∷ l) sz<m (v ∷ ctx) pst = kompile-clpats′ tel l (sz[l]<m ps l sz<m) ctx $ pst +=c BinOp Eq v (Nat 0) --(v == 0) kompile-clpats′ {suc m} tel (arg i (con (quote ℕ.suc) ps) ∷ l) sz<m (v ∷ ctx) pst = kompile-clpats′ tel (ps ++ l) (ps++l<m ps l sz<m) (BinOp Minus v (Nat 1) ∷ ctx) $ pst +=c BinOp Gt v (Nat 0) --(v > 0) kompile-clpats′ {suc m} tel (arg i (con (quote F.zero) ps) ∷ l) sz<m (v ∷ ctx) pst = kompile-clpats′ tel l (sz[l]<m ps l sz<m) ctx $ pst +=c BinOp Eq v (Nat 0) --(v ++ " == 0") kompile-clpats′ {suc m} tel (arg i (con (quote F.suc) ps@(_ ∷ _ ∷ [])) ∷ l) sz<m (v ∷ ctx) pst = do (ub , pst) ← pst-fresh pst "ub_" -- XXX here we are not using `ub` in conds. For two reasons: -- 1) as we have assertions, we should check the upper bound on function entry -- 2) typically, the value of this argument would be Pat.dot, which we ignore -- right now. It is possible to capture the value of the dot-patterns, as -- they carry the value when reconstructed. kompile-clpats′ tel (ps ++ l) (ps++l<m ps l sz<m) (Var ub ∷ (BinOp Minus v (Nat 1)) ∷ ctx) $ pst +=c BinOp Gt v (Nat 0) --(v ++ " > 0") -- For refl we don't need to generate a predicate, as refl is an element of a singleton type. kompile-clpats′ {suc m} tel (arg i (con (quote refl) ps) ∷ l) sz<m (v ∷ ctx) pst = kompile-clpats′ tel l (sz[l]<m ps l sz<m) ctx pst kompile-clpats′ {suc m} tel (arg i (con (quote _because_) ps) ∷ l) sz<m (v ∷ ctx) pst = do pf , pst ← pst-fresh pst $ "pf_" kompile-clpats′ tel (ps ++ l) (ps++l<m ps l sz<m) (v ∷ Var pf ∷ ctx) pst kompile-clpats′ {suc m} tel (arg i (con (quote Reflects.ofʸ) ps) ∷ l) sz<m (v ∷ ctx) pst = kompile-clpats′ tel (ps ++ l) (ps++l<m ps l sz<m) (Nat 1 ∷ ctx) pst kompile-clpats′ {suc m} tel (arg i (con (quote Reflects.ofⁿ) ps) ∷ l) sz<m (v ∷ ctx) pst = kompile-clpats′ tel (ps ++ l) (ps++l<m ps l sz<m) (Nat 0 ∷ ctx) pst kompile-clpats′ {suc m} tel (arg (arg-info _ r) (var i) ∷ l) sz<m (v ∷ vars) pst = do s ← tel-lookup-name tel i let pst = pst +=v (s , i) let pst = if does (s ≈? "_") then pst else pst +=a (s , v) kompile-clpats′ tel l (ℕ.≤-pred sz<m) vars pst kompile-clpats′ {suc m} tel (arg i (dot t) ∷ l) sz<m (v ∷ vars) pst = -- For now we just skip dot patterns. kompile-clpats′ tel l (ℕ.≤-pred sz<m) vars pst kompile-clpats′ {suc m} tel (arg i (absurd _) ∷ l) sz<m (v ∷ ctx) pst = -- If have met the absurd pattern, we'd still have to -- accumulate remaining conditions, as patterns are not -- linear :( For example, see test4-f in examples. kompile-clpats′ tel l (ℕ.≤-pred sz<m) ctx pst kompile-clpats′ _ [] _ [] pst = ok pst kompile-clpats′ tel ps _ ctx patst = kcp $ "failed on pattern: [" ++ (", " ++/ L.map (λ where (arg _ x) → showPattern x) ps) ++ "], ctx: [" ++ (", " ++/ (L.map (expr-to-string 0) ctx)) ++ "]" kompile-clpats tel pats ctx pst = kompile-clpats′ {m = suc (sz pats)} tel pats ℕ.≤-refl ctx pst private kt : ∀ {X} → String → SKS $ Err X kt x = return $ error $ "kompile-term: " ++ x mk-mask : (n : ℕ) → List $ Fin n mk-mask zero = [] mk-mask (suc n) = L.reverse $ go n (suc n) ℕ.≤-refl where sa<b⇒a<b : ∀ a b → suc a ℕ.< b → a ℕ.< b sa<b⇒a<b zero (suc b) _ = ℕ.s≤s ℕ.z≤n sa<b⇒a<b (suc a) (suc n) (ℕ.s≤s pf) = ℕ.s≤s $ sa<b⇒a<b a n pf go : (m n : ℕ) → m ℕ.< n → List $ Fin n go 0 (suc _) _ = zero ∷ [] go (suc m) n pf = F.fromℕ< pf ∷ go m n (sa<b⇒a<b m n pf) le-to-el : ∀ {a}{X : Set a} → List (Err X) → Err (List X) le-to-el [] = ok [] le-to-el (x ∷ l) = _∷_ <$> x ⊛ le-to-el l mk-iota-mask : ℕ → List ℕ mk-iota-mask n = L.reverse $! go n [] where go : ℕ → List ℕ → List ℕ go zero l = l go (suc n) l = n ∷ go n l {- kompile-arglist : (n : ℕ) → List $ Arg Term → List $ Fin n → Telescope → SKS $ Err (List Expr) kompile-arglist n args mask varctx with L.length args ℕ.≟ n | V.fromList args ... | yes p | vargs rewrite p = do l ← mapM (λ where (arg _ x) → kompile-term x varctx) $ L.map (V.lookup vargs) mask return $ le-to-el l where open TraversableM (StateMonad KS) ... | no ¬p | _ = kt "Incorrect argument mask" -} kompile-arglist-idx : List $ Arg Term → (idx : ℕ) → Telescope → SKS $ Err Expr kompile-arglist-idx [] _ tel = return $ error "incorrect arglist index" kompile-arglist-idx (arg _ x ∷ args) zero tel = kompile-term x tel kompile-arglist-idx (x ∷ args) (suc n) tel = kompile-arglist-idx args n tel kompile-arglist : List $ Arg Term → List ℕ → Telescope → SKS $ Err (List Expr) kompile-arglist args [] tel = return $ ok [] kompile-arglist args (x ∷ idxs) tel = do ok t ← kompile-arglist-idx args x tel where (error x) → return $ error x ok ts ← kompile-arglist args idxs tel where (error x) → return $ error x return $ ok $ t ∷ ts kompile-term (var x []) vars = return $ Var <$> tel-lookup-name vars x kompile-term (var x args@(_ ∷ _)) vars = do let f = tel-lookup-name vars x l = L.length args --args ← kompile-arglist l args (mk-mask l) vars args ← kompile-arglist args (mk-iota-mask l) vars return $ Call <$> f ⊛ args kompile-term (lit l@(nat x)) vars = return $ ok $ Nat x kompile-term (con (quote ℕ.zero) _) _ = return $ ok $ Nat 0 kompile-term (con (quote ℕ.suc) (arg _ a ∷ [])) vars = do a ← kompile-term a vars return $ BinOp <$> ok Plus ⊛ ok (Nat 1) ⊛ a kompile-term (con (quote F.zero) _) _ = return $ ok $ Nat 0 kompile-term (con (quote F.suc) (_ ∷ arg _ a ∷ [])) vars = do a ← kompile-term a vars return $ BinOp <$> ok Plus ⊛ ok (Nat 1) ⊛ a kompile-term (con (quote refl) _) _ = return $ ok $ Nat 1 kompile-term (con c _) vars = kt $ "don't know constructor " ++ (showName c) -- From Agda.Builtin.Nat: div-helper k m n j = k + (n + m - j) div (1 + m) kompile-term (def (quote div-helper) (arg _ k ∷ arg _ m ∷ arg _ n ∷ arg _ j ∷ [])) vars = do k ← kompile-term k vars m ← kompile-term m vars n ← kompile-term n vars j ← kompile-term j vars let n+m = BinOp <$> ok Plus ⊛ n ⊛ m n+m-j = BinOp <$> ok Minus ⊛ n+m ⊛ j k+[n+m-j] = BinOp <$> ok Plus ⊛ k ⊛ n+m-j 1+m = BinOp <$> ok Plus ⊛ ok (Nat 1) ⊛ m return $ BinOp <$> ok Divide ⊛ k+[n+m-j] ⊛ 1+m kompile-term (def (quote ℕ._≟_) (arg _ a ∷ arg _ b ∷ [])) vars = do a ← kompile-term a vars b ← kompile-term b vars return $ BinOp <$> ok Eq ⊛ a ⊛ b kompile-term (def (quote _+_) args@(arg _ a ∷ arg _ b ∷ [])) vars = do a ← kompile-term a vars b ← kompile-term b vars return $ BinOp <$> ok Plus ⊛ a ⊛ b kompile-term (def (quote ℕ._*_) args@(arg _ a ∷ arg _ b ∷ [])) vars = do a ← kompile-term a vars b ← kompile-term b vars return $ BinOp <$> ok Times ⊛ a ⊛ b kompile-term (def (quote F.fromℕ<) args) vars = do ok (x ∷ []) ← kompile-arglist args (0 ∷ []) vars where _ → kt "kopmile-arglist is broken" return $ ok x -- The last pattern in the list of `def` matches kompile-term (def n []) _ = kt $ "attempting to compile `" ++ showName n ++ "` as function with 0 arguments" kompile-term (def n args@(_ ∷ _)) vars = do R.modify λ k → record k { funs = KS.funs k ++ [ n ] } let n = {-nnorm $-} showName n l = L.length args --args ← kompile-arglist l args (mk-mask l) vars args ← kompile-arglist args (mk-iota-mask l) vars return $ Call <$> ok n ⊛ args kompile-term t vctx = kt $ "failed to compile term `" ++ showTerm t ++ "`"
{ "alphanum_fraction": 0.5501656614, "avg_line_length": 36.2184615385, "ext": "agda", "hexsha": "c899d6134b1f2815cbf39ef75cd8aa804c8fbf25", "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": "c8954c8acd8089ced82af9e05084fbbc7fedb36c", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "ashinkarov/agda-extractor", "max_forks_repo_path": "Kaleid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "ashinkarov/agda-extractor", "max_issues_repo_path": "Kaleid.agda", "max_line_length": 141, "max_stars_count": 1, "max_stars_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "ashinkarov/agda-extractor", "max_stars_repo_path": "Kaleid.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-11T14:52:59.000Z", "max_stars_repo_stars_event_min_datetime": "2021-01-11T14:52:59.000Z", "num_tokens": 8291, "size": 23542 }
F : {_ : Set₁} → Set₁ F {A} = A
{ "alphanum_fraction": 0.40625, "avg_line_length": 10.6666666667, "ext": "agda", "hexsha": "4acdfbf4bdb7fa829ed701d6eb8ad00e06224b59", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/interaction/Issue2728-2.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/interaction/Issue2728-2.agda", "max_line_length": 21, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/interaction/Issue2728-2.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": 18, "size": 32 }
module Jumble where open import Basics swap : {I J : Set} -> I * J -> J * I swap (i , j) = j , i _+L_ : {X : Set} -> List X -> List X -> List X [] +L ys = ys (x ,- xs) +L ys = x ,- (xs +L ys) infixr 4 _+L_ catNatural : {X Y : Set}(f : X -> Y)(xs xs' : List X) -> (list f xs +L list f xs') == list f (xs +L xs') catNatural f [] xs' = refl (list f xs') catNatural f (x ,- xs) xs' = refl (f x ,-_) =$= catNatural f xs xs' listlist : {X Y Z : Set}(f : Y -> Z)(g : X -> Y)(h : X -> Z) (q : (x : X) -> f (g x) == h x) -> (xs : List X) -> list f (list g xs) == list h xs listlist f g h q [] = refl [] listlist f g h q (x ,- xs) = refl (_,-_) =$= q x =$= listlist f g h q xs _-:>_ : {I : Set} -> (I -> Set) -> (I -> Set) -> (I -> Set) (S -:> T) i = S i -> T i infixr 4 _-:>_ [_] : {I : Set} -> (I -> Set) -> Set [ P ] = forall i -> P i All : {X : Set} -> (X -> Set) -> (List X -> Set) All P [] = One All P (x ,- xs) = P x * All P xs allPu : forall {X}{T : X -> Set} -> [ T ] -> [ All T ] allPu t [] = <> allPu t (x ,- xs) = t x , allPu t xs allAp : forall {X}{S T : X -> Set} -> [ All (S -:> T) -:> All S -:> All T ] allAp [] <> <> = <> allAp (x ,- xs) (f , fs) (s , ss) = f s , allAp xs fs ss all : {X : Set}{S T : X -> Set} -> [ S -:> T ] -> [ All S -:> All T ] all f xs = allAp xs (allPu f xs) allRe : forall {X Y}(f : X -> Y){P : Y -> Set} (xs : List X) -> All (\ x -> P (f x)) xs -> All P (list f xs) allRe f [] <> = <> allRe f (x ,- xs) (p , ps) = p , allRe f xs ps collect : {I J : Set}(is : List I) -> All (\ i -> List J) is -> List J collect [] <> = [] collect (i ,- is) (js , jss) = js +L collect is jss allRePu : forall {X Y}(f : X -> Y){P : Y -> Set}(xs : List X)(g : [ P ]) -> allRe f xs (allPu (\ x -> g (f x)) xs) == allPu g (list f xs) allRePu f [] g = refl <> allRePu f (x ,- xs) g = refl (g (f x) ,_) =$= allRePu f xs g all-Pu : forall {X}{S T : X -> Set}(f : [ S -:> T ])(s : [ S ])(xs : List X) -> all f xs (allPu s xs) == allPu (\ x -> f x (s x)) xs all-Pu f s [] = refl <> all-Pu f s (x ,- xs) = refl (f x (s x) ,_) =$= all-Pu f s xs cart : forall {I J} -> List I -> List J -> List (I * J) cart [] js = [] cart (i ,- is) js = list (i ,_) js +L cart is js {- all-grr : forall {X Y}{S : X -> Set}{T : Y -> Set} (f : X -> Y)(xs : List X)(g : [ S -:> (\ x -> T (f x)) ])(h : [ S ]) -> allAp (list f xs) (allPu g ?) (allRe f xs (allPu h xs)) == ? all-grr = ? -} data _<[_]>_ {X : Set} : List X -> List X -> List X -> Set where sz : [] <[ [] ]> [] sl : forall {l ls ms rs} -> ls <[ ms ]> rs -> (l ,- ls) <[ l ,- ms ]> rs sr : forall {r ls ms rs} -> ls <[ ms ]> rs -> ls <[ r ,- ms ]> (r ,- rs) riffle : {X : Set}{ls ms rs : List X} -> ls <[ ms ]> rs -> {P : X -> Set} -> All P ls -> All P rs -> All P ms riffle sz <> <> = <> riffle (sl x) (p , lp) rp = p , riffle x lp rp riffle (sr x) lp (p , rp) = p , riffle x lp rp srs : forall {X : Set}(xs : List X) -> [] <[ xs ]> xs srs [] = sz srs (x ,- xs) = sr (srs xs) slrs : forall {X : Set}(xs ys : List X) -> xs <[ xs +L ys ]> ys slrs [] ys = srs ys slrs (x ,- xs) ys = sl (slrs xs ys) cat : forall {X}{P : X -> Set}(xs ys : List X) -> All P xs -> All P ys -> All P (xs +L ys) cat xs ys ps qs = riffle (slrs xs ys) ps qs data IsRiffle {X : Set}{ls ms rs : List X}(i : ls <[ ms ]> rs){P : X -> Set} : All P ms -> Set where mkRiffle : (lp : All P ls)(rp : All P rs) -> IsRiffle i (riffle i lp rp) isRiffle : {X : Set}{ls ms rs : List X}(i : ls <[ ms ]> rs){P : X -> Set}(mp : All P ms) -> IsRiffle i mp isRiffle sz <> = mkRiffle <> <> isRiffle (sl i) (p , mp) with isRiffle i mp isRiffle (sl i) (p , .(riffle i lp rp)) | mkRiffle lp rp = mkRiffle (p , lp) rp isRiffle (sr i) (p , mp) with isRiffle i mp isRiffle (sr i) (p , .(riffle i lp rp)) | mkRiffle lp rp = mkRiffle lp (p , rp) data _~_ {X : Set} : List X -> List X -> Set where [] : [] ~ [] _,-_ : forall {x xs ys zs} -> (x ,- []) <[ ys ]> zs -> xs ~ zs -> (x ,- xs) ~ ys permute : {X : Set}{xs ys : List X} -> xs ~ ys -> {P : X -> Set} -> All P xs -> All P ys permute [] <> = <> permute (i ,- is) (p , ps) = riffle i (p , <>) (permute is ps) data SRS {X : Set}(ms : List X) : (xs : List X) -> [] <[ ms ]> xs -> Set where mkSRS : SRS ms ms (srs ms) isSRS : {X : Set}{ms xs : List X}(i : [] <[ ms ]> xs) -> SRS ms xs i isSRS sz = mkSRS isSRS (sr i) with isSRS i isSRS (sr .(srs _)) | mkSRS = mkSRS mirror : {X : Set}{ls ms rs : List X} -> ls <[ ms ]> rs -> rs <[ ms ]> ls mirror sz = sz mirror (sl x) = sr (mirror x) mirror (sr x) = sl (mirror x) rotatel : {X : Set}{ls ms rs lrs rrs : List X} -> ls <[ ms ]> rs -> lrs <[ rs ]> rrs -> Sg (List X) \ ns -> (ls <[ ns ]> lrs) * (ns <[ ms ]> rrs) rotatel sz sz = [] , sz , sz rotatel (sl x) y with rotatel x y ... | _ , a , b = _ , sl a , sl b rotatel (sr x) (sl y) with rotatel x y ... | _ , a , b = _ , sr a , sl b rotatel (sr x) (sr y) with rotatel x y ... | _ , a , b = _ , a , sr b rotater : {X : Set}{lls rls ls ms rs : List X} -> lls <[ ls ]> rls -> ls <[ ms ]> rs -> Sg (List X) \ ns -> (lls <[ ms ]> ns) * (rls <[ ns ]> rs) rotater x y with rotatel (mirror y) (mirror x) ... | _ , a , b = _ , mirror b , mirror a llswap : {X : Set}{ls ms lrs rrs : List X} -> (Sg (List X) \ rs -> (ls <[ ms ]> rs) * (lrs <[ rs ]> rrs)) -> Sg (List X) \ ns -> (lrs <[ ms ]> ns) * (ls <[ ns ]> rrs) llswap (_ , x , y) with rotatel x y ... | _ , a , b = rotater (mirror a) b reflP : {X : Set}(xs : List X) -> xs ~ xs reflP [] = [] reflP (x ,- xs) = sl (srs xs) ,- reflP xs insP : forall {X : Set}{x : X}{xs xs' ys ys'} -> (x ,- []) <[ xs' ]> xs -> (x ,- []) <[ ys' ]> ys -> xs ~ ys -> xs' ~ ys' insP (sl i) j p with isSRS i insP (sl .(srs _)) j p | mkSRS = j ,- p insP (sr i) j (k ,- p) = let _ , k' , j' = llswap (_ , j , k) in k' ,- insP i j' p l2r : forall {X : Set}{x : X}{xs xs' ys'}(i : (x ,- []) <[ xs' ]> xs)(p' : xs' ~ ys') -> Sg (List X) \ ys -> Sg ((x ,- []) <[ ys' ]> ys) \ j -> xs ~ ys l2r (sl i) (j ,- p) with isSRS i l2r (sl .(srs _)) (j ,- p) | mkSRS = _ , j , p l2r (sr i) (k' ,- p') with l2r i p' ... | _ , j' , p with llswap (_ , k' , j') ... | _ , j , k = _ , j , (k ,- p) transP : {X : Set}{xs ys zs : List X} -> xs ~ ys -> ys ~ zs -> xs ~ zs transP [] [] = [] transP (i ,- p) q' with l2r i q' ... | _ , j , q = j ,- transP p q symP : {X : Set}{xs ys : List X} -> xs ~ ys -> ys ~ xs symP [] = [] symP (i ,- p) = insP i (sl (srs _)) (symP p) _+L[] : {X : Set}(xs : List X) -> (xs +L []) == xs [] +L[] = refl [] (x ,- xs) +L[] = refl (x ,-_) =$= (xs +L[]) assoc : {X : Set}(xs ys zs : List X) -> ((xs +L ys) +L zs) == (xs +L ys +L zs) assoc [] ys zs = refl (ys +L zs) assoc (x ,- xs) ys zs = refl (x ,-_) =$= assoc xs ys zs insS : {X : Set}(xs : List X)(y : X)(zs : List X) -> (y ,- []) <[ (xs +L y ,- zs) ]> (xs +L zs) insS [] y zs = sl (srs zs) insS (x ,- xs) y zs = sr (insS xs y zs) swapP : {X : Set}(xs ys : List X) -> (xs +L ys) ~ (ys +L xs) swapP [] ys rewrite ys +L[] = reflP ys swapP (x ,- xs) ys = insS ys x xs ,- swapP xs ys catS : forall {X}{as abs bs cs cds ds : List X} -> as <[ abs ]> bs -> cs <[ cds ]> ds -> (as +L cs) <[ (abs +L cds) ]> (bs +L ds) catS sz y = y catS (sl x) y = sl (catS x y) catS (sr x) y = sr (catS x y) catP : forall {X : Set}{as bs cs ds : List X} -> as ~ cs -> bs ~ ds -> (as +L bs) ~ (cs +L ds) catP [] q = q catP (x ,- p) q = catS x (srs _) ,- catP p q splimap : forall {X Y}(f : X -> Y){xs xys ys} -> xs <[ xys ]> ys -> list f xs <[ list f xys ]> list f ys splimap f sz = sz splimap f (sl s) = sl (splimap f s) splimap f (sr s) = sr (splimap f s) permap : forall {X Y}(f : X -> Y){xs xs' : List X} -> xs ~ xs' -> list f xs ~ list f xs' permap f [] = [] permap f (x ,- p) = splimap f x ,- permap f p cartNil : forall {I}(is : List I){J} -> cart {J = J} is [] == [] cartNil [] = refl [] cartNil (i ,- is) = cartNil is cartCons : forall {I J}(is : List I)(j : J)(js : List J) -> cart is (j ,- js) ~ (list (_, j) is +L cart is js) cartCons [] j js = [] cartCons (i ,- is) j js with catP (swapP (list (i ,_) js) (list (_, j) is)) (reflP (cart is js)) ... | z rewrite assoc (list (i ,_) js) (list (_, j) is) (cart is js) | assoc (list (_, j) is) (list (i ,_) js) (cart is js) = (sl (srs (list (_, j) is +L cart (i ,- is) js))) ,- transP (catP (reflP (list (i ,_) js)) (cartCons is j js)) z cartLemma : forall {I J}(is : List I)(js : List J) -> cart is js ~ list swap (cart js is) cartLemma {I}{J} [] js rewrite cartNil js {I} = [] cartLemma {I}{J} (i ,- is) js with catP (reflP (list (i ,_) js)) (cartLemma is js) ... | z rewrite sym (listlist swap (_, i) (i ,_) (\ j -> refl (i , j)) js) | catNatural swap (list (_, i) js) (cart js is) = transP z (symP (permap (\ ji -> snd ji , fst ji) (cartCons js i is))) record _|>_ (I O : Set) : Set1 where field Cuts : O -> Set inners : {o : O} -> Cuts o -> List I NatCut : Nat |> Nat NatCut = record { Cuts = \ mn -> Sg Nat \ m -> Sg Nat \ n -> (m +N n) == mn ; inners = \ { (m , n , _) -> m ,- n ,- [] } } module TENSOR where open _|>_ _><_ : forall {I J} -> (I |> I) -> (J |> J) -> (I * J) |> (I * J) Cuts (C >< D) (i , j) = Cuts C i + Cuts D j inners (C >< D) {i , j} (inl c) = list (_, j) (inners C c) inners (C >< D) {i , j} (inr d) = list (i ,_) (inners D d) open TENSOR record Cutting {I O}(C : I |> O)(P : I -> Set)(o : O) : Set where constructor _8><_ open _|>_ C field cut : Cuts o pieces : All P (inners cut) infixr 3 _8><_ open Cutting public module INTERIOR {I}(C : I |> I) where open _|>_ C data Interior (P : I -> Set)(i : I) : Set where tile : P i -> Interior P i <_> : Cutting C (Interior P) i -> Interior P i ifold : forall {P Q} -> [ P -:> Q ] -> [ Cutting C Q -:> Q ] -> [ Interior P -:> Q ] ifolds : forall {P Q} -> [ P -:> Q ] -> [ Cutting C Q -:> Q ] -> [ All (Interior P) -:> All Q ] ifold pq cq i (tile p) = pq i p ifold pq cq i < c 8>< ps > = cq i (c 8>< ifolds pq cq _ ps) ifolds pq cq [] <> = <> ifolds pq cq (i ,- is) (x , xs) = ifold pq cq i x , ifolds pq cq is xs extend : forall {P Q} -> [ P -:> Interior Q ] -> [ Interior P -:> Interior Q ] extend k = ifold k (\ i x -> < x >) SubCut : (i : I)(c : Cuts i) -> Set SubCut i c = All (\ i -> One + Cuts i) (inners c) subCollect : (is : List I) -> All (\ i -> One + Cuts i) is -> List I subCollect is ds = collect is (all (\ i -> (\ _ -> i ,- []) <+> inners) is ds) subPieces : (i : I)(c : Cuts i) -> SubCut i c -> List I subPieces i c cs = subCollect (inners c) cs Recutter : Set Recutter = (i : I)(c c' : Cuts i) -> Sg (SubCut i c) \ d -> Sg (SubCut i c') \ d' -> subPieces i c d ~ subPieces i c' d' CutKit : (I -> Set) -> Set CutKit P = (i : I)(c : Cuts i) -> P i -> All P (inners c) module CHOP {P}(pc : CutKit P)(rec : Recutter) where glue : (is : List I) -> (d : All (\ i -> One + Cuts i) is) -> All (Interior P) (subCollect is d) -> All (Interior P) is glue [] <> <> = <> glue (i ,- is) (inl <> , ds) (p , ps) = p , glue is ds ps glue (i ,- is) (inr c , ds) ps with isRiffle (slrs (inners c) (subCollect is ds)) ps glue (i ,- is) (inr c , ds) .(riffle (slrs (inners c) (subCollect is ds)) lp rp) | mkRiffle lp rp = < c 8>< lp > , glue is ds rp chop : (i : I)(c c' : Cuts i)(ps : All (Interior P) (inners c)) -> All (Interior P) (inners c') chops : (is : List I) -> All (Interior P) is -> (d : All (\ i -> One + Cuts i) is) -> All (Interior P) (subCollect is d) chop i c c' ps with rec i c c' ... | d , d' , m with chops (inners c) ps d ... | qs = glue (inners c') d' (permute m qs) chops [] <> <> = <> chops (i ,- is) (p , ps) (inl <> , ds) = p , chops is ps ds chops (i ,- is) (tile p , ps) (inr c' , ds) = cat (inners c') (subCollect is ds) (all (\ _ -> tile) _ (pc i c' p)) (chops is ps ds) chops (i ,- is) (< c 8>< ps' > , ps) (inr c' , ds) = cat (inners c') (subCollect is ds) (chop i c c' ps') (chops is ps ds) mash : forall {Q} -> [ Interior (Interior P -:> Interior Q) -:> Interior P -:> Interior Q ] mash {Q} = ifold (\ i f -> f) help where help : [ Cutting C (Interior P -:> Interior Q) -:> Interior P -:> Interior Q ] help i (c 8>< fs) (tile p) with pc i c p ... | ps = < c 8>< allAp (inners c) fs (all (\ _ -> tile) _ ps) > help i (c 8>< fs) < c' 8>< ps > = < c 8>< allAp (inners c) fs (chop i c' c ps) > mask : forall {O Q} -> [ O -:> Interior P -:> Interior Q ] -> [ Interior O -:> Interior P -:> Interior Q ] mask {O}{Q} f = ifold f help where help : [ Cutting C (Interior P -:> Interior Q) -:> Interior P -:> Interior Q ] help i (c 8>< fs) (tile p) with pc i c p ... | ps = < c 8>< allAp (inners c) fs (all (\ _ -> tile) _ ps) > help i (c 8>< fs) < c' 8>< ps > = < c 8>< allAp (inners c) fs (chop i c' c ps) > open CHOP public data Holey {I : Set}(P : I -> Set)(i : I) : Set where hole : Holey P i fill : P i -> Holey P i cutHole : forall {P : I -> Set} -> CutKit P -> CutKit (Holey P) cutHole f i c hole = allPu (\ i -> hole) (inners c) cutHole f i c (fill p) = all (\ _ -> fill) (inners c) (f i c p) superimpose : forall {P} -> CutKit P -> Recutter -> [ Interior (Holey P) -:> Interior (Holey P) -:> Interior (Holey P) ] superimpose pc rec = mask (cutHole pc) rec \ { i hole y -> y ; i (fill x) y -> tile (fill x) } open INTERIOR module SUBCOLLECTLEMMA where open _|>_ subCollectLemma : forall {I J}(C : I |> I)(D : J |> J) (f : I -> J)(g : (i : I) -> Cuts C i -> Cuts D (f i)) -> (q : (i : I)(c : Cuts C i) -> inners D (g i c) == list f (inners C c)) -> (is : List I)(ps : All (\ i -> One + Cuts C i) is) -> subCollect D (list f is) (allRe f is (all (\ i -> id +map g i) is ps)) == list f (subCollect C is ps) subCollectLemma C D f g q [] <> = refl [] subCollectLemma C D f g q (i ,- is) (inl <> , ps) = refl (f i ,-_) =$= subCollectLemma C D f g q is ps subCollectLemma C D f g q (i ,- is) (inr c , ps) = (inners D (g i c) +L subCollect D (list f is) (allRe f is (allAp is (allPu (\ i -> id +map g i) is) ps))) =[ refl _+L_ =$= q i c =$= subCollectLemma C D f g q is ps >= (list f (inners C c) +L list f (subCollect C is ps)) =[ catNatural f (inners C c) (subCollect C is ps) >= list f (inners C c +L subCollect C is ps) [QED] open SUBCOLLECTLEMMA data CutCompare (x x' y y' n : Nat) : Set where cutLt : (d : Nat) -> (x +N suc d) == y -> (suc d +N y') == x' -> CutCompare x x' y y' n cutEq : x == y -> x' == y' -> CutCompare x x' y y' n cutGt : (d : Nat) -> (y +N suc d) == x -> (suc d +N x') == y' -> CutCompare x x' y y' n sucInj : {x y : Nat} -> suc x == suc y -> x == y sucInj (refl (suc _)) = refl _ cutCompare : (x x' y y' n : Nat) -> (x +N x') == n -> (y +N y') == n -> CutCompare x x' y y' n cutCompare zero .n zero .n n (refl _) (refl _) = cutEq (refl _) (refl _) cutCompare zero .(suc (y +N y')) (suc y) y' .(suc (y +N y')) (refl _) (refl _) = cutLt y (refl _) (refl _) cutCompare (suc x) x' zero .(suc (x +N x')) .(suc (x +N x')) (refl _) (refl _) = cutGt x (refl _) (refl _) cutCompare (suc x) x' (suc y) y' zero () () cutCompare (suc x) x' (suc y) y' (suc n) xq yq with cutCompare x x' y y' n (sucInj xq) (sucInj yq) cutCompare (suc x) x' (suc .(x +N suc d)) y' (suc n) xq yq | cutLt d (refl _) bq = cutLt d (refl _) bq cutCompare (suc x) x' (suc .x) y' (suc n) xq yq | cutEq (refl _) bq = cutEq (refl _) bq cutCompare (suc .(y +N suc d)) x' (suc y) y' (suc n) xq yq | cutGt d (refl _) bq = cutGt d (refl _) bq NatRecut : Recutter NatCut NatRecut n (a , b , qab) (c , d , qcd) with cutCompare a b c d n qab qcd NatRecut n (a , b , qab) (c , d , qcd) | cutLt e q0 q1 = (inl <> , inr (suc e , d , q1) , <>) , (inr (a , suc e , q0) , inl <> , <>) , reflP _ NatRecut n (a , b , qab) (.a , .b , qcd) | cutEq (refl .a) (refl .b) = (inl <> , inl <> , <>) , (inl <> , inl <> , <>) , reflP _ NatRecut n (a , b , qab) (c , d , qcd) | cutGt e q0 q1 = (inr (c , suc e , q0) , inl <> , <>) , (inl <> , inr (suc e , b , q1) , <>) , reflP _ module TENSORRECUT {I J}(C : I |> I)(D : J |> J)(rec : Recutter C)(red : Recutter D) where open _|>_ cartLeftLemma : (is : List I)(j : J)(d : Cuts D j) -> subCollect (C >< D) (list (_, j) is) (allRe (_, j) is (allPu (\ _ -> inr (inr d)) is)) == cart is (inners D d) cartLeftLemma [] j d = refl [] cartLeftLemma (i ,- is) j d = refl (list (i ,_) (inners D d) +L_) =$= cartLeftLemma is j d cartRightLemma : (i : I)(c : Cuts C i)(js : List J) -> subCollect (C >< D) (list (i ,_) js) (allRe (i ,_) js (allPu (\ _ -> inr (inl c)) js)) == list swap (cart js (inners C c)) cartRightLemma i c [] = refl [] cartRightLemma i c (j ,- js) rewrite sym (catNatural swap (list (j ,_) (inners C c)) (cart js (inners C c))) | listlist swap (j ,_) (_, j) (\ i -> refl (i , j)) (inners C c) = refl (list (_, j) (inners C c) +L_) =$= cartRightLemma i c js TensorRecut : Recutter (C >< D) TensorRecut (i , j) (inl c) (inl c') with rec i c c' ... | x , y , m = allRe (_, j) (inners C c) (all (\ _ -> id +map inl) _ x) , allRe (_, j) (inners C c') (all (\ _ -> id +map inl) _ y) , lemma where lemma : subCollect (C >< D) (list (_, j) (inners C c)) (allRe (_, j) (inners C c) (all (\ _ -> id +map inl) (inners C c) x)) ~ subCollect (C >< D) (list (_, j) (inners C c')) (allRe (_, j) (inners C c') (all (\ _ -> id +map inl) (inners C c') y)) lemma rewrite subCollectLemma C (C >< D) (_, j) (\ _ -> inl) (\ i c -> refl _) (inners C c) x | subCollectLemma C (C >< D) (_, j) (\ _ -> inl) (\ i c -> refl _) (inners C c') y = permap (_, j) m fst (TensorRecut (i , j) (inl c) (inr d)) = allRe (_, j) (inners C c) (allPu (\ i -> inr (inr d)) (inners C c)) fst (snd (TensorRecut (i , j) (inl c) (inr d))) = allRe (i ,_) (inners D d) (allPu (\ i -> inr (inl c)) (inners D d)) snd (snd (TensorRecut (i , j) (inl c) (inr d))) rewrite cartLeftLemma (inners C c) j d | cartRightLemma i c (inners D d) = cartLemma (inners C c) (inners D d) fst (TensorRecut (i , j) (inr d) (inl c)) = allRe (i ,_) (inners D d) (allPu (\ i -> inr (inl c)) (inners D d)) fst (snd (TensorRecut (i , j) (inr d) (inl c))) = allRe (_, j) (inners C c) (allPu (\ i -> inr (inr d)) (inners C c)) snd (snd (TensorRecut (i , j) (inr d) (inl c))) rewrite cartLeftLemma (inners C c) j d | cartRightLemma i c (inners D d) = symP (cartLemma (inners C c) (inners D d)) TensorRecut (i , j) (inr d) (inr d') with red j d d' ... | x , y , m = allRe (i ,_) (inners D d) (all (\ _ -> id +map inr) _ x) , allRe (i ,_) (inners D d') (all (\ _ -> id +map inr) _ y) , lemma where lemma : subCollect (C >< D) (list (i ,_) (inners D d)) (allRe (i ,_) (inners D d) (all (\ _ -> id +map inr) (inners D d) x)) ~ subCollect (C >< D) (list (i ,_) (inners D d')) (allRe (i ,_) (inners D d') (all (\ _ -> id +map inr) (inners D d') y)) lemma rewrite subCollectLemma D (C >< D) (i ,_) (\ _ -> inr) (\ i d -> refl _) (inners D d) x | subCollectLemma D (C >< D) (i ,_) (\ _ -> inr) (\ i d -> refl _) (inners D d') y = permap (i ,_) m open TENSORRECUT public RectangleRecut : Recutter (NatCut >< NatCut) RectangleRecut = TensorRecut NatCut NatCut NatRecut NatRecut
{ "alphanum_fraction": 0.4755795522, "avg_line_length": 39.6620825147, "ext": "agda", "hexsha": "253350f2a5bbef8b917e979559b2e6c04eb2c9c0", "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": "454cdd18f56db0b0d1643a1fcf36951b5ece395c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pigworker/InteriorDesign", "max_forks_repo_path": "Jumble.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c", "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": "pigworker/InteriorDesign", "max_issues_repo_path": "Jumble.agda", "max_line_length": 105, "max_stars_count": 6, "max_stars_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pigworker/InteriorDesign", "max_stars_repo_path": "Jumble.agda", "max_stars_repo_stars_event_max_datetime": "2018-07-31T02:00:13.000Z", "max_stars_repo_stars_event_min_datetime": "2018-06-18T15:25:39.000Z", "num_tokens": 8072, "size": 20188 }
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Strict2Group.Explicit.Path where open import Cubical.Foundations.Prelude open import Cubical.Data.Group.Base open import Cubical.Data.Strict2Group.Explicit.Base open import Cubical.Data.Strict2Group.Explicit.Notation S2G : (ℓ : Level) → Type (ℓ-suc ℓ) S2G ℓ = Strict2GroupExp ℓ S2GΣBase : (ℓ : Level) → Type (ℓ-suc ℓ) S2GΣBase ℓ = Σ[ C₀ ∈ Group ℓ ] Σ[ C₁ ∈ Group ℓ ] Σ[ s ∈ morph C₁ C₀ ] Σ[ t ∈ morph C₁ C₀ ] Σ[ i ∈ morph C₀ C₁ ] ((g f : Group.type C₁) → s .fst g ≡ t .fst f → Group.type C₁) -- ∘ S2GΣRest : {ℓ : Level} → (S2GΣBase ℓ) → Type ℓ S2GΣRest (C₀ , C₁ , s , t , i , ∘) = Σ[ si ∈ ((x : TC₀) → src (id x) ≡ x) ] Σ[ ti ∈ ((x : TC₀) → tar (id x) ≡ x) ] Σ[ s∘ ∈ ((g f : TC₁) → (coh : CohCond g f) → src (∘ g f coh) ≡ src f) ] Σ[ t∘ ∈ ((g f : TC₁) → (coh : CohCond g f) → tar (∘ g f coh) ≡ tar g) ] Σ[ isMorph∘ ∈ ({g f g' f' : TC₁} (c : CohCond g f) (c' : CohCond g' f') → ∘ (g ∙₁ g') (f ∙₁ f') (∙c c c') ≡ (∘ g f c) ∙₁ (∘ g' f' c')) ] Σ[ assoc∘ ∈ ({h g f : TC₁} → (c1 : CohCond g f) → (c2 : CohCond h g) → ∘ (∘ h g c2) f ((s∘ h g c2) ∙ c1) ≡ ∘ h (∘ g f c1) (c2 ∙ (sym (t∘ g f c1)))) ] Σ[ lUnit∘ ∈ ((f : TC₁) → ∘ (id (tar f)) f (si (tar f)) ≡ f) ] ((f : TC₁) → ∘ f (id (src f)) (sym (ti (src f))) ≡ f) -- rUnit∘ where open S2GBaseNotation C₀ C₁ s t i ∘ S2GΣ : (ℓ : Level) → Type (ℓ-suc ℓ) S2GΣ ℓ = Σ[ X ∈ S2GΣBase ℓ ] (S2GΣRest X) S2GΣ→S2G : {ℓ : Level} → S2GΣ ℓ → S2G ℓ S2GΣ→S2G ((C₀ , C₁ , s , t , i , ∘) , (si , ti , s∘ , t∘ , isMorph∘ , assoc∘ , lUnit∘ , rUnit∘)) = strict2groupexp C₀ C₁ s t i ∘ si ti s∘ t∘ isMorph∘ assoc∘ lUnit∘ rUnit∘ -- Σ-type of data needed to define the type of PathPs between the base data for an S2G S2GΣBase≡ : {ℓ : Level} → (SB SB' : S2GΣBase ℓ) → Type (ℓ-suc ℓ) S2GΣBase≡ (C₀ , C₁ , s , t , i , ∘ ) (C₀' , C₁' , s' , t' , i' , ∘') = Σ[ p-C₀ ∈ (C₀ ≡ C₀') ] Σ[ p-C₁ ∈ (C₁ ≡ C₁') ] Σ[ p-s ∈ (PathP (λ j → morph (p-C₁ j) (p-C₀ j)) s s') ] Σ[ p-t ∈ (PathP (λ j → morph (p-C₁ j) (p-C₀ j)) t t') ] Σ[ p-i ∈ (PathP (λ j → morph (p-C₀ j) (p-C₁ j)) i i') ] (PathP (λ j → (g f : Group.type (p-C₁ j)) → (fst (p-s j)) g ≡ (fst (p-t j)) f → Group.type (p-C₁ j)) ∘ ∘') -- p∘ S2GΣRest≡ : {ℓ : Level} {SB SB' : S2GΣBase ℓ} (SR : S2GΣRest {ℓ = ℓ} SB) (SR' : S2GΣRest {ℓ = ℓ} SB') (pSB : S2GΣBase≡ {ℓ = ℓ} SB SB') → Type ℓ S2GΣRest≡ {ℓ} {C₀ , C₁ , s , t , i , ∘} {C₀' , C₁' , s' , t' , i' , ∘'} (si , ti , s∘ , t∘ , isMorph∘ , assoc∘ , lUnit∘ , rUnit∘) (si' , ti' , s∘' , t∘' , isMorph∘' , assoc∘' , lUnit∘' , rUnit∘') (p-C₀ , p-C₁ , p-s , p-t , p-i , p∘) = Σ[ p-si ∈ (PathP (λ j → (x : Group.type (p-C₀ j)) → ((p-s j) .fst) (((p-i j) .fst) x) ≡ x) si si') ] Σ[ p-ti ∈ (PathP (λ j → (x : Group.type (p-C₀ j)) → ((p-t j) .fst) (((p-i j) .fst) x) ≡ x) ti ti') ] Σ[ p-s∘ ∈ (PathP (λ j → (g f : Group.type (p-C₁ j)) → (coh : (p-s j) .fst g ≡ (p-t j) .fst f) → (p-s j) .fst ((p∘ j) g f coh) ≡ (p-s j) .fst f) s∘ s∘') ] Σ[ p-t∘ ∈ (PathP (λ j → (g f : Group.type (p-C₁ j)) → (coh : (p-s j) .fst g ≡ (p-t j) .fst f) → (p-t j) .fst ((p∘ j) g f coh) ≡ (p-t j) .fst g) t∘ t∘') ] Σ[ p-isMorph∘ ∈ PathP (λ j → {g f g' f' : TC₁j j} (coh1 : CohCondj j g f) (coh2 : CohCondj j g' f') → (p∘ j) (∙₁j j g g') (∙₁j j f f') (∙cj j coh1 coh2) ≡ ∙₁j j (p∘ j g f coh1) (p∘ j g' f' coh2)) isMorph∘ isMorph∘' ] Σ[ p-assococ∘ ∈ (PathP (λ j → {h g f : TC₁j j} (coh1 : CohCondj j g f) (coh2 : CohCondj j h g) → (p∘ j (p∘ j h g coh2) f (p-s∘ j h g coh2 ∙ coh1)) ≡ (p∘ j h (p∘ j g f coh1) (coh2 ∙ (sym (p-t∘ j g f coh1))))) assoc∘ assoc∘') ] Σ[ p-lUnit∘ ∈ (PathP (λ j → (f : TC₁j j) → p∘ j (idj j (tarj j f)) f (p-si j (tarj j f)) ≡ f) lUnit∘ lUnit∘') ] (PathP (λ j → (f : TC₁j j) → p∘ j f (idj j (srcj j f)) (sym (p-ti j (srcj j f))) ≡ f) rUnit∘ rUnit∘') -- p-rUnit∘ where TC₁j = λ (j : I) → Group.type (p-C₁ j) TC₀j = λ (j : I) → Group.type (p-C₀ j) CohCondj : (j : I) (g f : TC₁j j) → Type ℓ CohCondj j g f = (p-s j) .fst g ≡ (p-t j) .fst f ∙₁j = λ (j : I) → isGroup.comp (Group.groupStruc (p-C₁ j)) ∙₀j = λ (j : I) → isGroup.comp (Group.groupStruc (p-C₀ j)) idj = λ (j : I) → fst (p-i j) srcj = λ (j : I) → fst (p-s j) tarj = λ (j : I) → fst (p-t j) src∙₁j = λ (j : I) → snd (p-s j) tar∙₁j = λ (j : I) → snd (p-t j) ∙cj : (j : I) → {g f g' f' : TC₁j j} → (c1 : CohCondj j g f) → (c2 : CohCondj j g' f') → (p-s j) .fst (∙₁j j g g') ≡ (p-t j) .fst (∙₁j j f f') ∙cj j {g} {f} {g'} {f'} c1 c2 = src∙₁j j g g' ∙ cong (λ z → ∙₀j j z (srcj j g')) c1 ∙ cong (λ z → ∙₀j j (tarj j f) z) c2 ∙ sym (tar∙₁j j f f') S2GR≡ : {ℓ : Level} {SB SB' : S2GΣBase ℓ} {SR : S2GΣRest {ℓ = ℓ} SB} {SR' : S2GΣRest {ℓ = ℓ} SB'} {pSB : S2GΣBase≡ {ℓ = ℓ} SB SB'} (pSR : S2GΣRest≡ {ℓ = ℓ} {SB = SB} {SB' = SB'} SR SR' pSB) → S2GΣ→S2G (SB , SR) ≡ S2GΣ→S2G (SB' , SR') S2GR≡ {ℓ} {C₀ , C₁ , s , t , i , ∘} -- SB {C₀' , C₁' , s' , t' , i' , ∘'} --SB' {si , ti , s∘ , t∘} -- SR {si' , ti' , s∘' , t∘'} -- SR' {p-C₀ , p-C₁ , p-s , p-t , p-i , p∘} -- pSB (p-si , p-ti , p-s∘ , p-t∘ , p-isMorph∘ , p-assococ∘ , p-lUnit∘ , p-rUnit∘) j = strict2groupexp (p-C₀ j) (p-C₁ j) (p-s j) (p-t j) (p-i j) (p∘ j) (p-si j) (p-ti j) (p-s∘ j) (p-t∘ j) (p-isMorph∘ j) (p-assococ∘ j) (p-lUnit∘ j) (p-rUnit∘ j)
{ "alphanum_fraction": 0.4535201019, "avg_line_length": 46.1932773109, "ext": "agda", "hexsha": "0cd32fe94418914e0ef50e70dd44d1126d36bcf2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Schippmunk/cubical", "max_forks_repo_path": "Cubical/Data/Strict2Group/Explicit/Path.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Schippmunk/cubical", "max_issues_repo_path": "Cubical/Data/Strict2Group/Explicit/Path.agda", "max_line_length": 170, "max_stars_count": null, "max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Schippmunk/cubical", "max_stars_repo_path": "Cubical/Data/Strict2Group/Explicit/Path.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2905, "size": 5497 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category.Core -- Idempotents and Split Idempotents module Categories.Morphism.Idempotent {o ℓ e} (𝒞 : Category o ℓ e) where open import Level open import Categories.Morphism 𝒞 open import Categories.Morphism.Reasoning 𝒞 open Category 𝒞 open HomReasoning record Idempotent (A : Obj) : Set (ℓ ⊔ e) where field idem : A ⇒ A idempotent : idem ∘ idem ≈ idem record IsSplitIdempotent {A : Obj} (i : A ⇒ A) : Set (o ⊔ ℓ ⊔ e) where field {obj} : Obj retract : A ⇒ obj section : obj ⇒ A retracts : retract ∘ section ≈ id splits : section ∘ retract ≈ i retract-absorb : retract ∘ i ≈ retract retract-absorb = begin retract ∘ i ≈˘⟨ refl⟩∘⟨ splits ⟩ retract ∘ section ∘ retract ≈⟨ cancelˡ retracts ⟩ retract ∎ section-absorb : i ∘ section ≈ section section-absorb = begin i ∘ section ≈˘⟨ splits ⟩∘⟨refl ⟩ (section ∘ retract) ∘ section ≈⟨ cancelʳ retracts ⟩ section ∎ idempotent : i ∘ i ≈ i idempotent = begin i ∘ i ≈˘⟨ splits ⟩∘⟨ splits ⟩ (section ∘ retract) ∘ (section ∘ retract) ≈⟨ cancelInner retracts ⟩ section ∘ retract ≈⟨ splits ⟩ i ∎ record SplitIdempotent (A : Obj) : Set (o ⊔ ℓ ⊔ e) where field idem : A ⇒ A isSplitIdempotent : IsSplitIdempotent idem open IsSplitIdempotent isSplitIdempotent public -- All split idempotents are idempotent SplitIdempotent⇒Idempotent : ∀ {A} → SplitIdempotent A → Idempotent A SplitIdempotent⇒Idempotent Split = record { Split } where module Split = SplitIdempotent Split module _ {A} {f : A ⇒ A} (S T : IsSplitIdempotent f) where private module S = IsSplitIdempotent S module T = IsSplitIdempotent T split-idempotent-unique : S.obj ≅ T.obj split-idempotent-unique = record { from = T.retract ∘ S.section ; to = S.retract ∘ T.section ; iso = record { isoˡ = begin (S.retract ∘ T.section) ∘ (T.retract ∘ S.section) ≈⟨ center T.splits ⟩ S.retract ∘ f ∘ S.section ≈⟨ pullˡ S.retract-absorb ⟩ S.retract ∘ S.section ≈⟨ S.retracts ⟩ id ∎ ; isoʳ = begin (T.retract ∘ S.section) ∘ (S.retract ∘ T.section) ≈⟨ center S.splits ⟩ T.retract ∘ f ∘ T.section ≈⟨ pullˡ T.retract-absorb ⟩ T.retract ∘ T.section ≈⟨ T.retracts ⟩ id ∎ } }
{ "alphanum_fraction": 0.5409474844, "avg_line_length": 32.8072289157, "ext": "agda", "hexsha": "f550cb7bfb2d0d8a79a6ec81e55d59606c782507", "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/Morphism/Idempotent.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/Morphism/Idempotent.agda", "max_line_length": 85, "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/Morphism/Idempotent.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": 873, "size": 2723 }
-- {-# OPTIONS --verbose tc.proj.like:100 #-} -- Apparently, there can be projection like functions working on arguments of type Axiom. module Issue558c where data ⊤ : Set where tt : ⊤ data V : Set where aV : ⊤ → V postulate D : ⊤ → Set zero : D tt suc : ∀ {t} → D t → V test : {{v : V}} → ⊤ test {{v}} = tt module test {t : ⊤} {d : D t} where inst : V inst = aV tt someT : ⊤ someT = test
{ "alphanum_fraction": 0.5490654206, "avg_line_length": 17.12, "ext": "agda", "hexsha": "82ff271d85ec0fdb10a1393327b552e1f491bdb6", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/succeed/Issue558c.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/succeed/Issue558c.agda", "max_line_length": 89, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/Issue558c.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": 151, "size": 428 }
module _ where module M where data D : Set where c : D pattern c′ = c open M hiding (c′) x : D x = c′
{ "alphanum_fraction": 0.5565217391, "avg_line_length": 8.2142857143, "ext": "agda", "hexsha": "b3ec5614e649d86ccda3081785e4465700604a3c", "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/Issue4121-2.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/Issue4121-2.agda", "max_line_length": 20, "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/Issue4121-2.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 43, "size": 115 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Sums of binary relations ------------------------------------------------------------------------ module Relation.Binary.Sum where open import Data.Sum as Sum open import Data.Product open import Data.Unit using (⊤) open import Data.Empty open import Function open import Function.Equality as F using (_⟶_; _⟨$⟩_) open import Function.Equivalence as Eq using (Equivalence; _⇔_; module Equivalence) open import Function.Injection as Inj using (Injection; _↣_; module Injection) open import Function.Inverse as Inv using (Inverse; _↔_; module Inverse) open import Function.LeftInverse as LeftInv using (LeftInverse; _↞_; module LeftInverse) open import Function.Related open import Function.Surjection as Surj using (Surjection; _↠_; module Surjection) open import Level open import Relation.Nullary import Relation.Nullary.Decidable as Dec open import Relation.Binary open import Relation.Binary.PropositionalEquality as P using (_≡_) module _ {a₁ a₂} {A₁ : Set a₁} {A₂ : Set a₂} where ---------------------------------------------------------------------- -- Sums of relations infixr 1 _⊎-Rel_ _⊎-<_ -- Generalised sum. data ⊎ʳ {ℓ₁ ℓ₂} (P : Set) (_∼₁_ : Rel A₁ ℓ₁) (_∼₂_ : Rel A₂ ℓ₂) : A₁ ⊎ A₂ → A₁ ⊎ A₂ → Set (a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂) where ₁∼₂ : ∀ {x y} (p : P) → ⊎ʳ P _∼₁_ _∼₂_ (inj₁ x) (inj₂ y) ₁∼₁ : ∀ {x y} (x∼₁y : x ∼₁ y) → ⊎ʳ P _∼₁_ _∼₂_ (inj₁ x) (inj₁ y) ₂∼₂ : ∀ {x y} (x∼₂y : x ∼₂ y) → ⊎ʳ P _∼₁_ _∼₂_ (inj₂ x) (inj₂ y) -- Pointwise sum. _⊎-Rel_ : ∀ {ℓ₁ ℓ₂} → Rel A₁ ℓ₁ → Rel A₂ ℓ₂ → Rel (A₁ ⊎ A₂) _ _⊎-Rel_ = ⊎ʳ ⊥ -- All things to the left are "smaller than" all things to the -- right. _⊎-<_ : ∀ {ℓ₁ ℓ₂} → Rel A₁ ℓ₁ → Rel A₂ ℓ₂ → Rel (A₁ ⊎ A₂) _ _⊎-<_ = ⊎ʳ ⊤ ---------------------------------------------------------------------- -- Helpers private ₁≁₂ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} → ∀ {x y} → ¬ (inj₁ x ⟨ ∼₁ ⊎-Rel ∼₂ ⟩ inj₂ y) ₁≁₂ (₁∼₂ ()) drop-inj₁ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} → ∀ {P x y} → inj₁ x ⟨ ⊎ʳ P ∼₁ ∼₂ ⟩ inj₁ y → ∼₁ x y drop-inj₁ (₁∼₁ x∼y) = x∼y drop-inj₂ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} → ∀ {P x y} → inj₂ x ⟨ ⊎ʳ P ∼₁ ∼₂ ⟩ inj₂ y → ∼₂ x y drop-inj₂ (₂∼₂ x∼y) = x∼y ---------------------------------------------------------------------- -- Some properties which are preserved by the relation formers above _⊎-reflexive_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {∼₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {∼₂ : Rel A₂ ℓ₂′} → ≈₁ ⇒ ∼₁ → ≈₂ ⇒ ∼₂ → ∀ {P} → (≈₁ ⊎-Rel ≈₂) ⇒ (⊎ʳ P ∼₁ ∼₂) refl₁ ⊎-reflexive refl₂ = refl where refl : (_ ⊎-Rel _) ⇒ (⊎ʳ _ _ _) refl (₁∼₁ x₁≈y₁) = ₁∼₁ (refl₁ x₁≈y₁) refl (₂∼₂ x₂≈y₂) = ₂∼₂ (refl₂ x₂≈y₂) refl (₁∼₂ ()) _⊎-refl_ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} → Reflexive ∼₁ → Reflexive ∼₂ → Reflexive (∼₁ ⊎-Rel ∼₂) refl₁ ⊎-refl refl₂ = refl where refl : Reflexive (_ ⊎-Rel _) refl {x = inj₁ _} = ₁∼₁ refl₁ refl {x = inj₂ _} = ₂∼₂ refl₂ _⊎-irreflexive_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {<₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {<₂ : Rel A₂ ℓ₂′} → Irreflexive ≈₁ <₁ → Irreflexive ≈₂ <₂ → ∀ {P} → Irreflexive (≈₁ ⊎-Rel ≈₂) (⊎ʳ P <₁ <₂) irrefl₁ ⊎-irreflexive irrefl₂ = irrefl where irrefl : Irreflexive (_ ⊎-Rel _) (⊎ʳ _ _ _) irrefl (₁∼₁ x₁≈y₁) (₁∼₁ x₁<y₁) = irrefl₁ x₁≈y₁ x₁<y₁ irrefl (₂∼₂ x₂≈y₂) (₂∼₂ x₂<y₂) = irrefl₂ x₂≈y₂ x₂<y₂ irrefl (₁∼₂ ()) _ _⊎-symmetric_ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} → Symmetric ∼₁ → Symmetric ∼₂ → Symmetric (∼₁ ⊎-Rel ∼₂) sym₁ ⊎-symmetric sym₂ = sym where sym : Symmetric (_ ⊎-Rel _) sym (₁∼₁ x₁∼y₁) = ₁∼₁ (sym₁ x₁∼y₁) sym (₂∼₂ x₂∼y₂) = ₂∼₂ (sym₂ x₂∼y₂) sym (₁∼₂ ()) _⊎-transitive_ : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} → Transitive ∼₁ → Transitive ∼₂ → ∀ {P} → Transitive (⊎ʳ P ∼₁ ∼₂) trans₁ ⊎-transitive trans₂ = trans where trans : Transitive (⊎ʳ _ _ _) trans (₁∼₁ x∼y) (₁∼₁ y∼z) = ₁∼₁ (trans₁ x∼y y∼z) trans (₂∼₂ x∼y) (₂∼₂ y∼z) = ₂∼₂ (trans₂ x∼y y∼z) trans (₁∼₂ p) (₂∼₂ _) = ₁∼₂ p trans (₁∼₁ _) (₁∼₂ p) = ₁∼₂ p _⊎-antisymmetric_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {≤₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {≤₂ : Rel A₂ ℓ₂′} → Antisymmetric ≈₁ ≤₁ → Antisymmetric ≈₂ ≤₂ → ∀ {P} → Antisymmetric (≈₁ ⊎-Rel ≈₂) (⊎ʳ P ≤₁ ≤₂) antisym₁ ⊎-antisymmetric antisym₂ = antisym where antisym : Antisymmetric (_ ⊎-Rel _) (⊎ʳ _ _ _) antisym (₁∼₁ x≤y) (₁∼₁ y≤x) = ₁∼₁ (antisym₁ x≤y y≤x) antisym (₂∼₂ x≤y) (₂∼₂ y≤x) = ₂∼₂ (antisym₂ x≤y y≤x) antisym (₁∼₂ _) () _⊎-asymmetric_ : ∀ {ℓ₁ ℓ₂} {<₁ : Rel A₁ ℓ₁} {<₂ : Rel A₂ ℓ₂} → Asymmetric <₁ → Asymmetric <₂ → ∀ {P} → Asymmetric (⊎ʳ P <₁ <₂) asym₁ ⊎-asymmetric asym₂ = asym where asym : Asymmetric (⊎ʳ _ _ _) asym (₁∼₁ x<y) (₁∼₁ y<x) = asym₁ x<y y<x asym (₂∼₂ x<y) (₂∼₂ y<x) = asym₂ x<y y<x asym (₁∼₂ _) () _⊎-≈-respects₂_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {∼₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {∼₂ : Rel A₂ ℓ₂′} → ∼₁ Respects₂ ≈₁ → ∼₂ Respects₂ ≈₂ → ∀ {P} → (⊎ʳ P ∼₁ ∼₂) Respects₂ (≈₁ ⊎-Rel ≈₂) _⊎-≈-respects₂_ {≈₁ = ≈₁} {∼₁ = ∼₁}{≈₂ = ≈₂} {∼₂ = ∼₂} resp₁ resp₂ {P} = (λ {_ _ _} → resp¹) , (λ {_ _ _} → resp²) where resp¹ : ∀ {x} → ((⊎ʳ P ∼₁ ∼₂) x) Respects (≈₁ ⊎-Rel ≈₂) resp¹ (₁∼₁ y≈y') (₁∼₁ x∼y) = ₁∼₁ (proj₁ resp₁ y≈y' x∼y) resp¹ (₂∼₂ y≈y') (₂∼₂ x∼y) = ₂∼₂ (proj₁ resp₂ y≈y' x∼y) resp¹ (₂∼₂ y≈y') (₁∼₂ p) = (₁∼₂ p) resp¹ (₁∼₂ ()) _ resp² : ∀ {y} → (flip (⊎ʳ P ∼₁ ∼₂) y) Respects (≈₁ ⊎-Rel ≈₂) resp² (₁∼₁ x≈x') (₁∼₁ x∼y) = ₁∼₁ (proj₂ resp₁ x≈x' x∼y) resp² (₂∼₂ x≈x') (₂∼₂ x∼y) = ₂∼₂ (proj₂ resp₂ x≈x' x∼y) resp² (₁∼₁ x≈x') (₁∼₂ p) = (₁∼₂ p) resp² (₁∼₂ ()) _ _⊎-substitutive_ : ∀ {ℓ₁ ℓ₂ ℓ₃} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} → Substitutive ∼₁ ℓ₃ → Substitutive ∼₂ ℓ₃ → Substitutive (∼₁ ⊎-Rel ∼₂) ℓ₃ subst₁ ⊎-substitutive subst₂ = subst where subst : Substitutive (_ ⊎-Rel _) _ subst P (₁∼₁ x∼y) Px = subst₁ (λ z → P (inj₁ z)) x∼y Px subst P (₂∼₂ x∼y) Px = subst₂ (λ z → P (inj₂ z)) x∼y Px subst P (₁∼₂ ()) Px ⊎-decidable : ∀ {ℓ₁ ℓ₂} {∼₁ : Rel A₁ ℓ₁} {∼₂ : Rel A₂ ℓ₂} → Decidable ∼₁ → Decidable ∼₂ → ∀ {P} → (∀ {x y} → Dec (inj₁ x ⟨ ⊎ʳ P ∼₁ ∼₂ ⟩ inj₂ y)) → Decidable (⊎ʳ P ∼₁ ∼₂) ⊎-decidable {∼₁ = ∼₁} {∼₂ = ∼₂} dec₁ dec₂ {P} dec₁₂ = dec where dec : Decidable (⊎ʳ P ∼₁ ∼₂) dec (inj₁ x) (inj₁ y) with dec₁ x y ... | yes x∼y = yes (₁∼₁ x∼y) ... | no x≁y = no (x≁y ∘ drop-inj₁) dec (inj₂ x) (inj₂ y) with dec₂ x y ... | yes x∼y = yes (₂∼₂ x∼y) ... | no x≁y = no (x≁y ∘ drop-inj₂) dec (inj₁ x) (inj₂ y) = dec₁₂ dec (inj₂ x) (inj₁ y) = no (λ()) _⊎-<-total_ : ∀ {ℓ₁ ℓ₂} {≤₁ : Rel A₁ ℓ₁} {≤₂ : Rel A₂ ℓ₂} → Total ≤₁ → Total ≤₂ → Total (≤₁ ⊎-< ≤₂) total₁ ⊎-<-total total₂ = total where total : Total (_ ⊎-< _) total (inj₁ x) (inj₁ y) = Sum.map ₁∼₁ ₁∼₁ $ total₁ x y total (inj₂ x) (inj₂ y) = Sum.map ₂∼₂ ₂∼₂ $ total₂ x y total (inj₁ x) (inj₂ y) = inj₁ (₁∼₂ _) total (inj₂ x) (inj₁ y) = inj₂ (₁∼₂ _) _⊎-<-trichotomous_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {<₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {<₂ : Rel A₂ ℓ₂′} → Trichotomous ≈₁ <₁ → Trichotomous ≈₂ <₂ → Trichotomous (≈₁ ⊎-Rel ≈₂) (<₁ ⊎-< <₂) _⊎-<-trichotomous_ {≈₁ = ≈₁} {<₁ = <₁} {≈₂ = ≈₂} {<₂ = <₂} tri₁ tri₂ = tri where tri : Trichotomous (≈₁ ⊎-Rel ≈₂) (<₁ ⊎-< <₂) tri (inj₁ x) (inj₂ y) = tri< (₁∼₂ _) ₁≁₂ (λ()) tri (inj₂ x) (inj₁ y) = tri> (λ()) (λ()) (₁∼₂ _) tri (inj₁ x) (inj₁ y) with tri₁ x y ... | tri< x<y x≉y x≯y = tri< (₁∼₁ x<y) (x≉y ∘ drop-inj₁) (x≯y ∘ drop-inj₁) ... | tri≈ x≮y x≈y x≯y = tri≈ (x≮y ∘ drop-inj₁) (₁∼₁ x≈y) (x≯y ∘ drop-inj₁) ... | tri> x≮y x≉y x>y = tri> (x≮y ∘ drop-inj₁) (x≉y ∘ drop-inj₁) (₁∼₁ x>y) tri (inj₂ x) (inj₂ y) with tri₂ x y ... | tri< x<y x≉y x≯y = tri< (₂∼₂ x<y) (x≉y ∘ drop-inj₂) (x≯y ∘ drop-inj₂) ... | tri≈ x≮y x≈y x≯y = tri≈ (x≮y ∘ drop-inj₂) (₂∼₂ x≈y) (x≯y ∘ drop-inj₂) ... | tri> x≮y x≉y x>y = tri> (x≮y ∘ drop-inj₂) (x≉y ∘ drop-inj₂) (₂∼₂ x>y) ---------------------------------------------------------------------- -- Some collections of properties which are preserved _⊎-isEquivalence_ : ∀ {ℓ₁ ℓ₂} {≈₁ : Rel A₁ ℓ₁} {≈₂ : Rel A₂ ℓ₂} → IsEquivalence ≈₁ → IsEquivalence ≈₂ → IsEquivalence (≈₁ ⊎-Rel ≈₂) eq₁ ⊎-isEquivalence eq₂ = record { refl = refl eq₁ ⊎-refl refl eq₂ ; sym = sym eq₁ ⊎-symmetric sym eq₂ ; trans = trans eq₁ ⊎-transitive trans eq₂ } where open IsEquivalence _⊎-isPreorder_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {∼₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {∼₂ : Rel A₂ ℓ₂′} → IsPreorder ≈₁ ∼₁ → IsPreorder ≈₂ ∼₂ → ∀ {P} → IsPreorder (≈₁ ⊎-Rel ≈₂) (⊎ʳ P ∼₁ ∼₂) pre₁ ⊎-isPreorder pre₂ = record { isEquivalence = isEquivalence pre₁ ⊎-isEquivalence isEquivalence pre₂ ; reflexive = reflexive pre₁ ⊎-reflexive reflexive pre₂ ; trans = trans pre₁ ⊎-transitive trans pre₂ } where open IsPreorder _⊎-isDecEquivalence_ : ∀ {ℓ₁ ℓ₂} {≈₁ : Rel A₁ ℓ₁} {≈₂ : Rel A₂ ℓ₂} → IsDecEquivalence ≈₁ → IsDecEquivalence ≈₂ → IsDecEquivalence (≈₁ ⊎-Rel ≈₂) eq₁ ⊎-isDecEquivalence eq₂ = record { isEquivalence = isEquivalence eq₁ ⊎-isEquivalence isEquivalence eq₂ ; _≟_ = ⊎-decidable (_≟_ eq₁) (_≟_ eq₂) (no ₁≁₂) } where open IsDecEquivalence _⊎-isPartialOrder_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {≤₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {≤₂ : Rel A₂ ℓ₂′} → IsPartialOrder ≈₁ ≤₁ → IsPartialOrder ≈₂ ≤₂ → ∀ {P} → IsPartialOrder (≈₁ ⊎-Rel ≈₂) (⊎ʳ P ≤₁ ≤₂) po₁ ⊎-isPartialOrder po₂ = record { isPreorder = isPreorder po₁ ⊎-isPreorder isPreorder po₂ ; antisym = antisym po₁ ⊎-antisymmetric antisym po₂ } where open IsPartialOrder _⊎-isStrictPartialOrder_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {<₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {<₂ : Rel A₂ ℓ₂′} → IsStrictPartialOrder ≈₁ <₁ → IsStrictPartialOrder ≈₂ <₂ → ∀ {P} → IsStrictPartialOrder (≈₁ ⊎-Rel ≈₂) (⊎ʳ P <₁ <₂) spo₁ ⊎-isStrictPartialOrder spo₂ = record { isEquivalence = isEquivalence spo₁ ⊎-isEquivalence isEquivalence spo₂ ; irrefl = irrefl spo₁ ⊎-irreflexive irrefl spo₂ ; trans = trans spo₁ ⊎-transitive trans spo₂ ; <-resp-≈ = <-resp-≈ spo₁ ⊎-≈-respects₂ <-resp-≈ spo₂ } where open IsStrictPartialOrder _⊎-<-isTotalOrder_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {≤₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {≤₂ : Rel A₂ ℓ₂′} → IsTotalOrder ≈₁ ≤₁ → IsTotalOrder ≈₂ ≤₂ → IsTotalOrder (≈₁ ⊎-Rel ≈₂) (≤₁ ⊎-< ≤₂) to₁ ⊎-<-isTotalOrder to₂ = record { isPartialOrder = isPartialOrder to₁ ⊎-isPartialOrder isPartialOrder to₂ ; total = total to₁ ⊎-<-total total to₂ } where open IsTotalOrder _⊎-<-isDecTotalOrder_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {≤₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {≤₂ : Rel A₂ ℓ₂′} → IsDecTotalOrder ≈₁ ≤₁ → IsDecTotalOrder ≈₂ ≤₂ → IsDecTotalOrder (≈₁ ⊎-Rel ≈₂) (≤₁ ⊎-< ≤₂) to₁ ⊎-<-isDecTotalOrder to₂ = record { isTotalOrder = isTotalOrder to₁ ⊎-<-isTotalOrder isTotalOrder to₂ ; _≟_ = ⊎-decidable (_≟_ to₁) (_≟_ to₂) (no ₁≁₂) ; _≤?_ = ⊎-decidable (_≤?_ to₁) (_≤?_ to₂) (yes (₁∼₂ _)) } where open IsDecTotalOrder _⊎-<-isStrictTotalOrder_ : ∀ {ℓ₁ ℓ₁′} {≈₁ : Rel A₁ ℓ₁} {<₁ : Rel A₁ ℓ₁′} {ℓ₂ ℓ₂′} {≈₂ : Rel A₂ ℓ₂} {<₂ : Rel A₂ ℓ₂′} → IsStrictTotalOrder ≈₁ <₁ → IsStrictTotalOrder ≈₂ <₂ → IsStrictTotalOrder (≈₁ ⊎-Rel ≈₂) (<₁ ⊎-< <₂) sto₁ ⊎-<-isStrictTotalOrder sto₂ = record { isEquivalence = isEquivalence sto₁ ⊎-isEquivalence isEquivalence sto₂ ; trans = trans sto₁ ⊎-transitive trans sto₂ ; compare = compare sto₁ ⊎-<-trichotomous compare sto₂ ; <-resp-≈ = <-resp-≈ sto₁ ⊎-≈-respects₂ <-resp-≈ sto₂ } where open IsStrictTotalOrder ------------------------------------------------------------------------ -- The game can be taken even further... _⊎-setoid_ : ∀ {s₁ s₂ s₃ s₄} → Setoid s₁ s₂ → Setoid s₃ s₄ → Setoid _ _ s₁ ⊎-setoid s₂ = record { isEquivalence = isEquivalence s₁ ⊎-isEquivalence isEquivalence s₂ } where open Setoid _⊎-preorder_ : ∀ {p₁ p₂ p₃ p₄ p₅ p₆} → Preorder p₁ p₂ p₃ → Preorder p₄ p₅ p₆ → Preorder _ _ _ p₁ ⊎-preorder p₂ = record { _∼_ = _∼_ p₁ ⊎-Rel _∼_ p₂ ; isPreorder = isPreorder p₁ ⊎-isPreorder isPreorder p₂ } where open Preorder _⊎-decSetoid_ : ∀ {s₁ s₂ s₃ s₄} → DecSetoid s₁ s₂ → DecSetoid s₃ s₄ → DecSetoid _ _ ds₁ ⊎-decSetoid ds₂ = record { isDecEquivalence = isDecEquivalence ds₁ ⊎-isDecEquivalence isDecEquivalence ds₂ } where open DecSetoid _⊎-poset_ : ∀ {p₁ p₂ p₃ p₄ p₅ p₆} → Poset p₁ p₂ p₃ → Poset p₄ p₅ p₆ → Poset _ _ _ po₁ ⊎-poset po₂ = record { _≤_ = _≤_ po₁ ⊎-Rel _≤_ po₂ ; isPartialOrder = isPartialOrder po₁ ⊎-isPartialOrder isPartialOrder po₂ } where open Poset _⊎-<-poset_ : ∀ {p₁ p₂ p₃ p₄ p₅ p₆} → Poset p₁ p₂ p₃ → Poset p₄ p₅ p₆ → Poset _ _ _ po₁ ⊎-<-poset po₂ = record { _≤_ = _≤_ po₁ ⊎-< _≤_ po₂ ; isPartialOrder = isPartialOrder po₁ ⊎-isPartialOrder isPartialOrder po₂ } where open Poset _⊎-<-strictPartialOrder_ : ∀ {p₁ p₂ p₃ p₄ p₅ p₆} → StrictPartialOrder p₁ p₂ p₃ → StrictPartialOrder p₄ p₅ p₆ → StrictPartialOrder _ _ _ spo₁ ⊎-<-strictPartialOrder spo₂ = record { _<_ = _<_ spo₁ ⊎-< _<_ spo₂ ; isStrictPartialOrder = isStrictPartialOrder spo₁ ⊎-isStrictPartialOrder isStrictPartialOrder spo₂ } where open StrictPartialOrder _⊎-<-totalOrder_ : ∀ {t₁ t₂ t₃ t₄ t₅ t₆} → TotalOrder t₁ t₂ t₃ → TotalOrder t₄ t₅ t₆ → TotalOrder _ _ _ to₁ ⊎-<-totalOrder to₂ = record { isTotalOrder = isTotalOrder to₁ ⊎-<-isTotalOrder isTotalOrder to₂ } where open TotalOrder _⊎-<-decTotalOrder_ : ∀ {t₁ t₂ t₃ t₄ t₅ t₆} → DecTotalOrder t₁ t₂ t₃ → DecTotalOrder t₄ t₅ t₆ → DecTotalOrder _ _ _ to₁ ⊎-<-decTotalOrder to₂ = record { isDecTotalOrder = isDecTotalOrder to₁ ⊎-<-isDecTotalOrder isDecTotalOrder to₂ } where open DecTotalOrder _⊎-<-strictTotalOrder_ : ∀ {p₁ p₂ p₃ p₄ p₅ p₆} → StrictTotalOrder p₁ p₂ p₃ → StrictTotalOrder p₄ p₅ p₆ → StrictTotalOrder _ _ _ sto₁ ⊎-<-strictTotalOrder sto₂ = record { _<_ = _<_ sto₁ ⊎-< _<_ sto₂ ; isStrictTotalOrder = isStrictTotalOrder sto₁ ⊎-<-isStrictTotalOrder isStrictTotalOrder sto₂ } where open StrictTotalOrder ------------------------------------------------------------------------ -- Some properties related to "relatedness" private to-cong : ∀ {a b} {A : Set a} {B : Set b} → (_≡_ ⊎-Rel _≡_) ⇒ _≡_ {A = A ⊎ B} to-cong (₁∼₂ ()) to-cong (₁∼₁ P.refl) = P.refl to-cong (₂∼₂ P.refl) = P.refl from-cong : ∀ {a b} {A : Set a} {B : Set b} → _≡_ {A = A ⊎ B} ⇒ (_≡_ ⊎-Rel _≡_) from-cong P.refl = P.refl ⊎-refl P.refl ⊎-Rel↔≡ : ∀ {a b} (A : Set a) (B : Set b) → Inverse (P.setoid A ⊎-setoid P.setoid B) (P.setoid (A ⊎ B)) ⊎-Rel↔≡ _ _ = record { to = record { _⟨$⟩_ = id; cong = to-cong } ; from = record { _⟨$⟩_ = id; cong = from-cong } ; inverse-of = record { left-inverse-of = λ _ → P.refl ⊎-refl P.refl ; right-inverse-of = λ _ → P.refl } } _⊎-≟_ : ∀ {a b} {A : Set a} {B : Set b} → Decidable {A = A} _≡_ → Decidable {A = B} _≡_ → Decidable {A = A ⊎ B} _≡_ (dec₁ ⊎-≟ dec₂) s₁ s₂ = Dec.map′ to-cong from-cong (s₁ ≟ s₂) where open DecSetoid (P.decSetoid dec₁ ⊎-decSetoid P.decSetoid dec₂) _⊎-⟶_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → A ⟶ B → C ⟶ D → (A ⊎-setoid C) ⟶ (B ⊎-setoid D) _⊎-⟶_ {A = A} {B} {C} {D} f g = record { _⟨$⟩_ = fg ; cong = fg-cong } where open Setoid (A ⊎-setoid C) using () renaming (_≈_ to _≈AC_) open Setoid (B ⊎-setoid D) using () renaming (_≈_ to _≈BD_) fg = Sum.map (_⟨$⟩_ f) (_⟨$⟩_ g) fg-cong : _≈AC_ =[ fg ]⇒ _≈BD_ fg-cong (₁∼₂ ()) fg-cong (₁∼₁ x∼₁y) = ₁∼₁ $ F.cong f x∼₁y fg-cong (₂∼₂ x∼₂y) = ₂∼₂ $ F.cong g x∼₂y _⊎-equivalence_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → Equivalence A B → Equivalence C D → Equivalence (A ⊎-setoid C) (B ⊎-setoid D) A⇔B ⊎-equivalence C⇔D = record { to = to A⇔B ⊎-⟶ to C⇔D ; from = from A⇔B ⊎-⟶ from C⇔D } where open Equivalence _⊎-⇔_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ⇔ B → C ⇔ D → (A ⊎ C) ⇔ (B ⊎ D) _⊎-⇔_ {A = A} {B} {C} {D} A⇔B C⇔D = Inverse.equivalence (⊎-Rel↔≡ B D) ⟨∘⟩ A⇔B ⊎-equivalence C⇔D ⟨∘⟩ Eq.sym (Inverse.equivalence (⊎-Rel↔≡ A C)) where open Eq using () renaming (_∘_ to _⟨∘⟩_) _⊎-injection_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → Injection A B → Injection C D → Injection (A ⊎-setoid C) (B ⊎-setoid D) _⊎-injection_ {A = A} {B} {C} {D} A↣B C↣D = record { to = to A↣B ⊎-⟶ to C↣D ; injective = inj _ _ } where open Injection open Setoid (A ⊎-setoid C) using () renaming (_≈_ to _≈AC_) open Setoid (B ⊎-setoid D) using () renaming (_≈_ to _≈BD_) inj : ∀ x y → (to A↣B ⊎-⟶ to C↣D) ⟨$⟩ x ≈BD (to A↣B ⊎-⟶ to C↣D) ⟨$⟩ y → x ≈AC y inj (inj₁ x) (inj₁ y) (₁∼₁ x∼₁y) = ₁∼₁ (injective A↣B x∼₁y) inj (inj₂ x) (inj₂ y) (₂∼₂ x∼₂y) = ₂∼₂ (injective C↣D x∼₂y) inj (inj₁ x) (inj₂ y) (₁∼₂ ()) inj (inj₂ x) (inj₁ y) () _⊎-↣_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ↣ B → C ↣ D → (A ⊎ C) ↣ (B ⊎ D) _⊎-↣_ {A = A} {B} {C} {D} A↣B C↣D = Inverse.injection (⊎-Rel↔≡ B D) ⟨∘⟩ A↣B ⊎-injection C↣D ⟨∘⟩ Inverse.injection (Inv.sym (⊎-Rel↔≡ A C)) where open Inj using () renaming (_∘_ to _⟨∘⟩_) _⊎-left-inverse_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → LeftInverse A B → LeftInverse C D → LeftInverse (A ⊎-setoid C) (B ⊎-setoid D) A↞B ⊎-left-inverse C↞D = record { to = Equivalence.to eq ; from = Equivalence.from eq ; left-inverse-of = [ ₁∼₁ ∘ left-inverse-of A↞B , ₂∼₂ ∘ left-inverse-of C↞D ] } where open LeftInverse eq = LeftInverse.equivalence A↞B ⊎-equivalence LeftInverse.equivalence C↞D _⊎-↞_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ↞ B → C ↞ D → (A ⊎ C) ↞ (B ⊎ D) _⊎-↞_ {A = A} {B} {C} {D} A↞B C↞D = Inverse.left-inverse (⊎-Rel↔≡ B D) ⟨∘⟩ A↞B ⊎-left-inverse C↞D ⟨∘⟩ Inverse.left-inverse (Inv.sym (⊎-Rel↔≡ A C)) where open LeftInv using () renaming (_∘_ to _⟨∘⟩_) _⊎-surjection_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → Surjection A B → Surjection C D → Surjection (A ⊎-setoid C) (B ⊎-setoid D) A↠B ⊎-surjection C↠D = record { to = LeftInverse.from inv ; surjective = record { from = LeftInverse.to inv ; right-inverse-of = LeftInverse.left-inverse-of inv } } where open Surjection inv = right-inverse A↠B ⊎-left-inverse right-inverse C↠D _⊎-↠_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ↠ B → C ↠ D → (A ⊎ C) ↠ (B ⊎ D) _⊎-↠_ {A = A} {B} {C} {D} A↠B C↠D = Inverse.surjection (⊎-Rel↔≡ B D) ⟨∘⟩ A↠B ⊎-surjection C↠D ⟨∘⟩ Inverse.surjection (Inv.sym (⊎-Rel↔≡ A C)) where open Surj using () renaming (_∘_ to _⟨∘⟩_) _⊎-inverse_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → Inverse A B → Inverse C D → Inverse (A ⊎-setoid C) (B ⊎-setoid D) A↔B ⊎-inverse C↔D = record { to = Surjection.to surj ; from = Surjection.from surj ; inverse-of = record { left-inverse-of = LeftInverse.left-inverse-of inv ; right-inverse-of = Surjection.right-inverse-of surj } } where open Inverse surj = Inverse.surjection A↔B ⊎-surjection Inverse.surjection C↔D inv = Inverse.left-inverse A↔B ⊎-left-inverse Inverse.left-inverse C↔D _⊎-↔_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ↔ B → C ↔ D → (A ⊎ C) ↔ (B ⊎ D) _⊎-↔_ {A = A} {B} {C} {D} A↔B C↔D = ⊎-Rel↔≡ B D ⟨∘⟩ A↔B ⊎-inverse C↔D ⟨∘⟩ Inv.sym (⊎-Rel↔≡ A C) where open Inv using () renaming (_∘_ to _⟨∘⟩_) _⊎-cong_ : ∀ {k a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ∼[ k ] B → C ∼[ k ] D → (A ⊎ C) ∼[ k ] (B ⊎ D) _⊎-cong_ {implication} = Sum.map _⊎-cong_ {reverse-implication} = λ f g → lam (Sum.map (app-← f) (app-← g)) _⊎-cong_ {equivalence} = _⊎-⇔_ _⊎-cong_ {injection} = _⊎-↣_ _⊎-cong_ {reverse-injection} = λ f g → lam (app-↢ f ⊎-↣ app-↢ g) _⊎-cong_ {left-inverse} = _⊎-↞_ _⊎-cong_ {surjection} = _⊎-↠_ _⊎-cong_ {bijection} = _⊎-↔_
{ "alphanum_fraction": 0.4979105539, "avg_line_length": 37.8686868687, "ext": "agda", "hexsha": "8a84e63a6e3aac9f3b58309b8a6205e7d1da5126", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Sum.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Sum.agda", "max_line_length": 74, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Sum.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 10580, "size": 22494 }
module Eq where open import Prelude open import T open import Contexts open import Eq.Defs import Eq.KleeneTheory import Eq.ObsTheory import Eq.LogicalTheory import Eq.Theory open Eq.Defs public open Eq.KleeneTheory public using (kleene-is-equivalence ; nats-halt) open Eq.ObsTheory public using (obs-is-coarsest ; obs-is-con-congruence) open Eq.LogicalTheory public using (log-is-con-congruence) open Eq.Theory public
{ "alphanum_fraction": 0.8123515439, "avg_line_length": 24.7647058824, "ext": "agda", "hexsha": "06b1d21487c59a58803fd36e4e40bef2c3735b55", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2021-05-04T22:37:18.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-26T11:39:14.000Z", "max_forks_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "msullivan/godels-t", "max_forks_repo_path": "Eq.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91", "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": "msullivan/godels-t", "max_issues_repo_path": "Eq.agda", "max_line_length": 72, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "msullivan/godels-t", "max_stars_repo_path": "Eq.agda", "max_stars_repo_stars_event_max_datetime": "2021-03-22T00:28:03.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-25T01:52:57.000Z", "num_tokens": 117, "size": 421 }
-- Andreas, 2014-09-01 restored this test case module ClashingModuleImport where module M where open import Imports.Module public
{ "alphanum_fraction": 0.8045112782, "avg_line_length": 16.625, "ext": "agda", "hexsha": "93911bdba44f9e230c7bef0efa7faf7eeefe263d", "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/ClashingModuleImport.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/ClashingModuleImport.agda", "max_line_length": 46, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/ClashingModuleImport.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": 32, "size": 133 }
{-# OPTIONS --without-K #-} {-# OPTIONS --type-in-type #-} module pisearch where open import Type hiding (★_) open import Function.NP open import Data.Product open import Data.Sum open import Data.Bool.NP open import Search.Type open import Search.Searchable.Product open import Search.Searchable open import sum fromFun-searchInd : ∀ {A} {sA : Search A} → SearchInd sA → FromFun sA fromFun-searchInd indA = indA (λ s → Data s _) _,_ open import Relation.Binary.PropositionalEquality hiding ([_]) ToFrom : ∀ {A} (sA : Search A) (toFunA : ToFun sA) (fromFunA : FromFun sA) → ★ ToFrom {A} sA toFunA fromFunA = ∀ {B} (f : Π A B) x → toFunA (fromFunA f) x ≡ f x FromTo : ∀ {A} (sA : Search A) (toFunA : ToFun sA) (fromFunA : FromFun sA) → ★ FromTo sA toFunA fromFunA = ∀ {B} (d : Data sA B) → fromFunA (toFunA d) ≡ d module Σ-props {A} {B : A → ★} (μA : Searchable A) (μB : ∀ {x} → Searchable (B x)) where sA = search μA sB : ∀ {x} → Search (B x) sB {x} = search (μB {x}) fromFunA : FromFun sA fromFunA = fromFun-searchInd (search-ind μA) fromFunB : ∀ {x} → FromFun (sB {x}) fromFunB {x} = fromFun-searchInd (search-ind (μB {x})) module ToFrom (toFunA : ToFun sA) (toFunB : ∀ {x} → ToFun (sB {x})) (toFromA : ToFrom sA toFunA fromFunA) (toFromB : ∀ {x} → ToFrom (sB {x}) toFunB fromFunB) where toFrom-Σ : ToFrom (ΣSearch sA (λ {x} → sB {x})) (toFun-Σ sA sB toFunA toFunB) (fromFun-Σ sA sB fromFunA fromFunB) toFrom-Σ f (x , y) rewrite toFromA (fromFunB ∘ curry f) x = toFromB (curry f x) y {- we need a search-ind-ext... module FromTo (toFunA : ToFun sA) (toFunB : ∀ {x} → ToFun (sB {x})) (toFromA : FromTo sA toFunA fromFunA) (toFromB : ∀ {x} → FromTo (sB {x}) toFunB fromFunB) where toFrom-Σ : FromTo (ΣSearch sA (λ {x} → sB {x})) (toFun-Σ sA sB toFunA toFunB) (fromFun-Σ sA sB fromFunA fromFunB) toFrom-Σ t = {!toFromA!} -- {!(λ x → toFromB (toFunA t x))!} -} toFun-× : ∀ {A B} (sA : Search A) (sB : Search B) → ToFun sA → ToFun sB → ToFun (sA ×Search sB) toFun-× sA sB toFunA toFunB = toFun-Σ sA sB toFunA toFunB fromFun-× : ∀ {A B} (sA : Search A) (sB : Search B) → FromFun sA → FromFun sB → FromFun (sA ×Search sB) fromFun-× sA sB fromFunA fromFunB = fromFun-Σ sA sB fromFunA fromFunB toFun-Bit : ToFun (search μBit) toFun-Bit (f , t) false = f toFun-Bit (f , t) true = t fromFun-Bit : FromFun (search μBit) fromFun-Bit f = f false , f true toFun-⊎ : ∀ {A B} (sA : Search A) (sB : Search B) → ToFun sA → ToFun sB → ToFun (sA +Search sB) toFun-⊎ sA sB toFunA toFunB (x , y) = [ toFunA x , toFunB y ] fromFun-⊎ : ∀ {A B} (sA : Search A) (sB : Search B) → FromFun sA → FromFun sB → FromFun (sA +Search sB) fromFun-⊎ sA sB fromFunA fromFunB f = fromFunA (f ∘ inj₁) , fromFunB (f ∘ inj₂) toPair-searchInd : ∀ {A} {sA : Search A} → SearchInd sA → ToPair sA toPair-searchInd indA = indA ToPair (λ P0 P1 → [ P0 , P1 ]) (λ η → _,_ η) -- toFun-searchInd : ∀ {A} {sA : Search A} → SearchInd sA → ToFun sA -- toFun-searchInd {A} {sA} indA {B} t = ?
{ "alphanum_fraction": 0.5869228385, "avg_line_length": 39.8395061728, "ext": "agda", "hexsha": "94f5b70087dc7a801c3de5ca8874180bbd086b36", "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/Experimental/pisearch.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/Experimental/pisearch.agda", "max_line_length": 121, "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/Experimental/pisearch.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": 1281, "size": 3227 }
{-# OPTIONS --without-K --safe #-} module Math.NumberTheory.Summation.Generic.Properties where -- agda-stdlib open import Algebra import Algebra.Operations.CommutativeMonoid as CommutativeMonoidOperations open import Data.Nat as ℕ hiding (_+_; _*_) import Data.Fin as Fin import Data.Nat.Properties as ℕₚ open import Relation.Nullary open import Relation.Binary.PropositionalEquality as ≡ using (_≡_) import Relation.Binary.Reasoning.Setoid as SetoidReasoning open import Function.Base -- agda-misc open import Math.NumberTheory.Summation.Generic import Math.NumberTheory.Summation.Generic.Properties.Lemma as Lemma module MonoidSummationProperties {c e} (M : Monoid c e) where open MonoidSummation M open Monoid M open SetoidReasoning setoid -- Congruence Σ<-cong : ∀ {m n f g} → m ≡ n → (∀ x → f x ≈ g x) → Σ< m f ≈ Σ< n g Σ<-cong {0} {.0} {f} {g} ≡.refl f≈g = refl Σ<-cong {suc m} {.(suc m)} {f} {g} ≡.refl f≈g = begin Σ< m f ∙ f m ≈⟨ ∙-cong (Σ<-cong {m = m} {n = m} ≡.refl f≈g) (f≈g m) ⟩ Σ< m g ∙ g m ∎ Σ<-congˡ : ∀ n {f g} → (∀ x → f x ≈ g x) → Σ< n f ≈ Σ< n g Σ<-congˡ n f≈g = Σ<-cong {m = n} ≡.refl f≈g Σ<-congʳ : ∀ {m n} f → m ≡ n → Σ< m f ≈ Σ< n f Σ<-congʳ f m≡n = Σ<-cong {f = f} m≡n (λ _ → refl) Σ≤-cong : ∀ {m n f g} → m ≡ n → (∀ x → f x ≈ g x) → Σ≤ m f ≈ Σ≤ n g Σ≤-cong m≡n f≈g = Σ<-cong (≡.cong suc m≡n) f≈g Σ≤-congˡ : ∀ n {f g} → (∀ x → f x ≈ g x) → Σ≤ n f ≈ Σ≤ n g Σ≤-congˡ n = Σ<-congˡ (suc n) Σ≤-congʳ : ∀ {m n} f → m ≡ n → Σ≤ m f ≈ Σ≤ n f Σ≤-congʳ f m≡n = Σ<-congʳ f (≡.cong suc m≡n) Σ<range-cong : ∀ {m n o p} {f g : ℕ → Carrier} → m ≡ n → o ≡ p → (∀ x → f x ≈ g x) → Σ<range m o f ≈ Σ<range n p g Σ<range-cong {m} {.m} {o} {.o} {f} {g} ≡.refl ≡.refl f≈g = begin Σ< (o ∸ m) (λ k → f (m ℕ.+ k)) ≈⟨ Σ<-congˡ (o ∸ m) (λ x → f≈g (m ℕ.+ x)) ⟩ Σ< (o ∸ m) (λ k → g (m ℕ.+ k)) ∎ Σ<range-cong₃ : ∀ m n {f g : ℕ → Carrier} → (∀ x → f x ≈ g x) → Σ<range m n f ≈ Σ<range m n g Σ<range-cong₃ m n f≈g = Σ<range-cong {m = m} {o = n} ≡.refl ≡.refl f≈g Σ<range-cong₁₂ : ∀ {m n o p} (f : ℕ → Carrier) → m ≡ n → o ≡ p → Σ<range m o f ≈ Σ<range n p f Σ<range-cong₁₂ f ≡.refl ≡.refl = refl Σ<range-cong₁ : ∀ {m n} o (f : ℕ → Carrier)→ m ≡ n → Σ<range m o f ≈ Σ<range n o f Σ<range-cong₁ o f m≡n = Σ<range-cong₁₂ {o = o} f m≡n ≡.refl Σ<range-cong₂ : ∀ m {n o} (f : ℕ → Carrier) → n ≡ o → Σ<range m n f ≈ Σ<range m o f Σ<range-cong₂ m f n≡o = Σ<range-cong₁₂ {m = m} f ≡.refl n≡o Σ≤range-cong : ∀ {m n o p} {f g : ℕ → Carrier} → m ≡ n → o ≡ p → (∀ x → f x ≈ g x) → Σ≤range m o f ≈ Σ≤range n p g Σ≤range-cong m≡n o≡p f≈g = Σ<range-cong m≡n (≡.cong suc o≡p) f≈g Σ<-congˡ-with-< : ∀ n {f g} → (∀ i → i < n → f i ≈ g i) → Σ< n f ≈ Σ< n g Σ<-congˡ-with-< 0 {f} {g} f≈g = refl Σ<-congˡ-with-< (suc n) {f} {g} f≈g = ∙-cong (Σ<-congˡ-with-< n (λ i i<n → f≈g i (ℕₚ.≤-step i<n))) (f≈g n ℕₚ.≤-refl) Σ≤-congˡ-with-≤ : ∀ n {f g} → (∀ i → i ≤ n → f i ≈ g i) → Σ≤ n f ≈ Σ≤ n g Σ≤-congˡ-with-≤ n f≈g = Σ<-congˡ-with-< (suc n) λ i 1+i≤1+n → f≈g i (ℕₚ.≤-pred 1+i≤1+n) Σ<-0 : ∀ n → Σ< n (λ _ → ε) ≈ ε Σ<-0 zero = refl Σ<-0 (suc n) = begin Σ< n (λ _ → ε) ∙ ε ≈⟨ ∙-congʳ $ Σ<-0 n ⟩ ε ∙ ε ≈⟨ identityʳ ε ⟩ ε ∎ Σ≤-0 : ∀ n → Σ≤ n (λ _ → ε) ≈ ε Σ≤-0 n = Σ<-0 (suc n) Σ<[1,f]≈f[0] : ∀ f → Σ< 1 f ≈ f 0 Σ<[1,f]≈f[0] f = identityˡ (f 0) Σ≤[0,f]≈f[0] : ∀ f → Σ≤ 0 f ≈ f 0 Σ≤[0,f]≈f[0] f = Σ<[1,f]≈f[0] f n≤m⇒Σ<range[m,n,f]≈0 : ∀ {m n} f → n ≤ m → Σ<range m n f ≈ ε n≤m⇒Σ<range[m,n,f]≈0 {m} {n} f n≤m = begin Σ< (n ∸ m) (λ k → f (m ℕ.+ k)) ≈⟨ Σ<-congʳ (λ k → f (m ℕ.+ k)) $ ℕₚ.m≤n⇒m∸n≡0 n≤m ⟩ Σ< 0 (λ k → f (m ℕ.+ k)) ∎ n<m⇒Σ≤range[m,n,f]≈0 : ∀ {m n} f → n < m → Σ≤range m n f ≈ ε n<m⇒Σ≤range[m,n,f]≈0 {m} {n} f n<m = n≤m⇒Σ<range[m,n,f]≈0 f n<m Σ<range[n,n,f]≈0 : ∀ n f → Σ<range n n f ≈ ε Σ<range[n,n,f]≈0 n f = n≤m⇒Σ<range[m,n,f]≈0 {n} {n} f ℕₚ.≤-refl Σ<range-cong₃-with-< : ∀ m n {f g} → (∀ i → m ≤ i → i < n → f i ≈ g i) → Σ<range m n f ≈ Σ<range m n g Σ<range-cong₃-with-< m n {f} {g} f≈g with m ℕₚ.≤? n ... | yes m≤n = Σ<-congˡ-with-< (n ∸ m) {λ i → f (m ℕ.+ i)} {λ i → g (m ℕ.+ i)} λ i i<n∸m → f≈g (m ℕ.+ i) (ℕₚ.m≤m+n m i) (≤R.begin 1 ℕ.+ (m ℕ.+ i) ≤R.≡⟨ ≡.cong (1 ℕ.+_) $ ℕₚ.+-comm m i ⟩ suc i ℕ.+ m ≤R.≤⟨ ℕₚ.+-monoˡ-≤ m i<n∸m ⟩ o ℕ.+ m ≤R.≡⟨ ≡.sym n≡o+m ⟩ n ≤R.∎ ) where o = n ∸ m n≡o+m : n ≡ o ℕ.+ m n≡o+m = ≡.sym $ ℕₚ.m∸n+n≡m m≤n module ≤R = ℕₚ.≤-Reasoning ... | no m≰n = trans (n≤m⇒Σ<range[m,n,f]≈0 f n≤m) (sym $ n≤m⇒Σ<range[m,n,f]≈0 g n≤m) where n≤m = ℕₚ.<⇒≤ $ ℕₚ.≰⇒> m≰n Σ≤range-cong₃-with-≤ : ∀ m n {f g} → (∀ i → m ≤ i → i ≤ n → f i ≈ g i) → Σ≤range m n f ≈ Σ≤range m n g Σ≤range-cong₃-with-≤ m n {f} {g} f≈g = Σ<range-cong₃-with-< m (suc n) λ i i≤n 1+i≤1+n → f≈g i i≤n (ℕₚ.≤-pred 1+i≤1+n) Σ<range[n,1+n,f]≈f[n] : ∀ n f → Σ<range n (suc n) f ≈ f n Σ<range[n,1+n,f]≈f[n] n f = begin Σ< (suc n ∸ n) (λ k → f (n ℕ.+ k)) ≈⟨ Σ<-congʳ (λ k → f (n ℕ.+ k)) $ ℕₚ.m+n∸n≡m 1 n ⟩ Σ< 1 (λ k → f (n ℕ.+ k)) ≈⟨ Σ<[1,f]≈f[0] (λ k → f (n ℕ.+ k)) ⟩ f (n ℕ.+ 0) ≈⟨ reflexive (≡.cong f (ℕₚ.+-identityʳ n)) ⟩ f n ∎ Σ≤range[n,n,f]≈f[n] : ∀ n f → Σ≤range n n f ≈ f n Σ≤range[n,n,f]≈f[n] = Σ<range[n,1+n,f]≈f[n] Σ<-+ : ∀ m n f → Σ< (m ℕ.+ n) f ≈ Σ< m f ∙ Σ< n (λ k → f (m ℕ.+ k)) Σ<-+ m zero f = begin Σ< (m ℕ.+ 0) f ≈⟨ Σ<-congʳ f $ ℕₚ.+-identityʳ m ⟩ Σ< m f ≈⟨ sym $ identityʳ (Σ< m f) ⟩ Σ< m f ∙ ε ∎ Σ<-+ m (suc n) f = begin Σ< (m ℕ.+ suc n) f ≈⟨ Σ<-congʳ f $ ℕₚ.+-suc m n ⟩ Σ< (suc m ℕ.+ n) f ≡⟨⟩ Σ< (m ℕ.+ n) f ∙ f (m ℕ.+ n) ≈⟨ ∙-congʳ $ Σ<-+ m n f ⟩ Σ< m f ∙ Σ< n (λ k → f (m ℕ.+ k)) ∙ f (m ℕ.+ n) ≈⟨ assoc (Σ< m f) (Σ< n (λ k → f (m ℕ.+ k))) (f (m ℕ.+ n)) ⟩ Σ< m f ∙ Σ< (suc n) (λ k → f (m ℕ.+ k)) ∎ Σ≤-Σ<-+ : ∀ m n f → Σ≤ (m ℕ.+ n) f ≈ Σ≤ m f ∙ Σ< n (λ k → f (1 ℕ.+ m ℕ.+ k)) Σ≤-Σ<-+ m n f = Σ<-+ (suc m) n f Σ≤-+ : ∀ m n f → Σ≤ (1 ℕ.+ m ℕ.+ n) f ≈ Σ≤ m f ∙ Σ≤ n (λ k → f (1 ℕ.+ m ℕ.+ k)) Σ≤-+ m n f = begin Σ< (2 ℕ.+ m ℕ.+ n) f ≈⟨ Σ<-congʳ f $ Lemma.lemma₁ m n ⟩ Σ< (suc m ℕ.+ suc n) f ≈⟨ Σ<-+ (suc m) (suc n) f ⟩ Σ< (suc m) f ∙ Σ< (suc n) (λ k → f (1 ℕ.+ m ℕ.+ k)) ∎ Σ<-push-suc : ∀ n f → Σ< (suc n) f ≈ f 0 ∙ Σ< n (λ k → f (suc k)) Σ<-push-suc n f = begin Σ< (suc n) f ≈⟨ Σ<-+ 1 n f ⟩ Σ< 1 f ∙ Σ< n (λ k → f (suc k)) ≈⟨ ∙-congʳ $ Σ<[1,f]≈f[0] f ⟩ f 0 ∙ Σ< n (λ k → f (suc k)) ∎ Σ≤-push-suc : ∀ n f → Σ≤ (suc n) f ≈ f 0 ∙ Σ≤ n (λ k → f (suc k)) Σ≤-push-suc n f = Σ<-push-suc (suc n) f Σ<range[0,n,f]≈Σ<[n,f] : ∀ n f → Σ<range 0 n f ≈ Σ< n f Σ<range[0,n,f]≈Σ<[n,f] n f = refl Σ≤range[0,n,f]≈Σ≤[n,f] : ∀ n f → Σ≤range 0 n f ≈ Σ≤ n f Σ≤range[0,n,f]≈Σ≤[n,f] n f = refl Σ<range[m,m+n+o,f]≈Σ<range[m,m+n,f]+Σ<range[m+n,m+n+o,f] : ∀ m n o f → Σ<range m (m ℕ.+ n ℕ.+ o) f ≈ Σ<range m (m ℕ.+ n) f ∙ Σ<range (m ℕ.+ n) (m ℕ.+ n ℕ.+ o) f Σ<range[m,m+n+o,f]≈Σ<range[m,m+n,f]+Σ<range[m+n,m+n+o,f] m n o f = begin Σ< (m+n+o ∸ m) f′ ≈⟨ Σ<-congʳ f′ (≡.cong (_∸ m) $ ℕₚ.+-assoc m n o) ⟩ Σ< (m ℕ.+ n+o ∸ m) f′ ≈⟨ Σ<-congʳ f′ (ℕₚ.m+n∸m≡n m n+o) ⟩ Σ< n+o f′ ≈⟨ Σ<-+ n o f′ ⟩ Σ< n f′ ∙ Σ< o (λ k → f (m ℕ.+ (n ℕ.+ k))) ≈⟨ ∙-cong (sym $ Σ<-congʳ f′ $ ℕₚ.m+n∸m≡n m n) (sym $ Σ<-cong (ℕₚ.m+n∸m≡n m+n o) (λ x → reflexive (≡.cong f (ℕₚ.+-assoc m n x)))) ⟩ Σ< (m+n ∸ m) f′ ∙ Σ< (m+n+o ∸ m+n) (λ k → f (m+n ℕ.+ k)) ∎ where m+n = m ℕ.+ n n+o = n ℕ.+ o m+n+o = m+n ℕ.+ o f′ = λ k → f (m ℕ.+ k) Σ<range[m,n,f]≈Σ<range[m,o,f]+Σ<range[o,n,f] : ∀ {m n o} f → m ≤ o → o ≤ n → Σ<range m n f ≈ Σ<range m o f ∙ Σ<range o n f Σ<range[m,n,f]≈Σ<range[m,o,f]+Σ<range[o,n,f] {m} {n} {o} f m≤o o≤n = begin Σ<range m n f ≈⟨ reflexive (≡.cong (λ v → Σ<range m v f) n≡m+p+q) ⟩ Σ<range m m+p+q f ≈⟨ Σ<range[m,m+n+o,f]≈Σ<range[m,m+n,f]+Σ<range[m+n,m+n+o,f] m p q f ⟩ Σ<range m m+p f ∙ Σ<range m+p m+p+q f ≈⟨ sym $ ∙-cong (Σ<range-cong₂ m f o≡m+p) (Σ<range-cong₁₂ f o≡m+p n≡m+p+q) ⟩ Σ<range m o f ∙ Σ<range o n f ∎ where p = o ∸ m q = n ∸ o m+p = m ℕ.+ p m+p+q = m+p ℕ.+ q o≡m+p : o ≡ m+p o≡m+p = ≡.sym $ ℕₚ.m+[n∸m]≡n m≤o n≡m+p+q : n ≡ m+p+q n≡m+p+q = ≡.sym ( ≡R.begin m ℕ.+ p ℕ.+ q ≡R.≡⟨ ≡.cong (ℕ._+ q) $ ≡.sym o≡m+p ⟩ o ℕ.+ (n ∸ o) ≡R.≡⟨ ℕₚ.m+[n∸m]≡n o≤n ⟩ n ≡R.∎ ) where module ≡R = ≡.≡-Reasoning -- Reindex Σ<range[m,n,f]≈Σ<range[o+m,o+n,i→f[i∸o]] : ∀ m n o f → Σ<range m n f ≈ Σ<range (o ℕ.+ m) (o ℕ.+ n) (λ i → f (i ∸ o)) Σ<range[m,n,f]≈Σ<range[o+m,o+n,i→f[i∸o]] m n o f = begin Σ< (n ∸ m) (λ k → f (m ℕ.+ k)) ≈⟨ Σ<-cong (≡.sym $ ℕₚ.[m+n]∸[m+o]≡n∸o o n m) (λ x → reflexive $ ≡.cong f $ ≡.sym $ (≡R.begin o ℕ.+ m ℕ.+ x ∸ o ≡R.≡⟨ ≡.cong (_∸ o) $ ℕₚ.+-assoc o m x ⟩ o ℕ.+ (m ℕ.+ x) ∸ o ≡R.≡⟨ ℕₚ.m+n∸m≡n o (m ℕ.+ x) ⟩ m ℕ.+ x ≡R.∎ )) ⟩ Σ< ((o ℕ.+ n) ∸ (o ℕ.+ m)) (λ k → f ((o ℕ.+ m ℕ.+ k) ∸ o)) ∎ where module ≡R = ≡.≡-Reasoning Σ≤range[m,n,f]≈Σ≤range[o+m,o+n,i→f[i∸o]] : ∀ m n o f → Σ≤range m n f ≈ Σ≤range (o ℕ.+ m) (o ℕ.+ n) (λ i → f (i ∸ o)) Σ≤range[m,n,f]≈Σ≤range[o+m,o+n,i→f[i∸o]] m n o f = begin Σ<range m (suc n) f ≈⟨ Σ<range[m,n,f]≈Σ<range[o+m,o+n,i→f[i∸o]] m (suc n) o f ⟩ Σ<range (o ℕ.+ m) (o ℕ.+ suc n) (λ i → f (i ∸ o)) ≈⟨ Σ<range-cong₂ (o ℕ.+ m) (λ i → f (i ∸ o)) $ ℕₚ.+-suc o n ⟩ Σ<range (o ℕ.+ m) (suc o ℕ.+ n) (λ i → f (i ∸ o)) ∎ module CommutativeMonoidSummationProperties {c e} (CM : CommutativeMonoid c e) where open CommutativeMonoid CM open MonoidSummation monoid open MonoidSummationProperties monoid public open CommutativeMonoidOperations CM open SetoidReasoning setoid private n×x+x≈x+n×x : ∀ n x → n × x ∙ x ≈ x ∙ n × x n×x+x≈x+n×x zero x = trans (identityˡ x) (sym $ identityʳ x) n×x+x≈x+n×x (suc n) x = begin x ∙ n × x ∙ x ≈⟨ assoc x (n × x) x ⟩ x ∙ (n × x ∙ x) ≈⟨ ∙-congˡ $ n×x+x≈x+n×x n x ⟩ x ∙ (x ∙ n × x) ∎ Σ<-const : ∀ n x → Σ< n (const x) ≈ n × x Σ<-const zero x = refl Σ<-const (suc n) x = begin Σ< n (const x) ∙ x ≈⟨ ∙-congʳ $ Σ<-const n x ⟩ n × x ∙ x ≈⟨ n×x+x≈x+n×x n x ⟩ x ∙ n × x ∎ Σ≤-const : ∀ n x → Σ≤ n (const x) ≈ suc n × x Σ≤-const n x = Σ<-const (suc n) x Σ<range-const : ∀ m n x → Σ<range m n (const x) ≈ (n ∸ m) × x Σ<range-const m n x = Σ<-const (n ∸ m) x Σ≤range-const : ∀ m n x → Σ≤range m n (const x) ≈ (suc n ∸ m) × x Σ≤range-const m n x = Σ<range-const m (suc n) x private lemma : ∀ a b c d → a ∙ b ∙ (c ∙ d) ≈ a ∙ c ∙ (b ∙ d) lemma a b c d = begin (a ∙ b) ∙ (c ∙ d) ≈⟨ assoc a b (c ∙ d) ⟩ a ∙ (b ∙ (c ∙ d)) ≈⟨ sym $ ∙-congˡ $ assoc b c d ⟩ a ∙ ((b ∙ c) ∙ d) ≈⟨ ∙-congˡ $ ∙-congʳ $ comm b c ⟩ a ∙ ((c ∙ b) ∙ d) ≈⟨ ∙-congˡ $ assoc c b d ⟩ a ∙ (c ∙ (b ∙ d)) ≈⟨ sym $ assoc a c (b ∙ d) ⟩ (a ∙ c) ∙ (b ∙ d) ∎ Σ<-distrib-+ : ∀ n f g → Σ< n (λ k → f k ∙ g k) ≈ Σ< n f ∙ Σ< n g Σ<-distrib-+ zero f g = sym $ identityʳ ε Σ<-distrib-+ (suc n) f g = begin Σ< n (λ k → f k ∙ g k) ∙ (f n ∙ g n) ≈⟨ ∙-congʳ $ Σ<-distrib-+ n f g ⟩ (Σ< n f ∙ Σ< n g) ∙ (f n ∙ g n) ≈⟨ lemma (Σ< n f) (Σ< n g) (f n) (g n) ⟩ (Σ< n f ∙ f n) ∙ (Σ< n g ∙ g n) ∎ Σ≤-distrib-+ : ∀ n f g → Σ≤ n (λ k → f k ∙ g k) ≈ Σ≤ n f ∙ Σ≤ n g Σ≤-distrib-+ n f g = Σ<-distrib-+ (suc n) f g Σ<range-distrib-+ : ∀ m n f g → Σ<range m n (λ k → f k ∙ g k) ≈ Σ<range m n f ∙ Σ<range m n g Σ<range-distrib-+ m n f g = Σ<-distrib-+ (n ∸ m) (λ k → f (m ℕ.+ k)) (λ k → g (m ℕ.+ k)) Σ≤range-distrib-+ : ∀ m n f g → Σ≤range m n (λ k → f k ∙ g k) ≈ Σ≤range m n f ∙ Σ≤range m n g Σ≤range-distrib-+ m n f g = Σ<range-distrib-+ m (suc n) f g Σ<-comm : ∀ m n (f : ℕ → ℕ → Carrier) → Σ< m (λ i → Σ< n (λ j → f i j)) ≈ Σ< n (λ j → Σ< m (λ i → f i j)) Σ<-comm zero n f = sym $ Σ<-0 n Σ<-comm (suc m) n f = begin Σ< (suc m) (λ i → Σ< n (f i)) ≡⟨⟩ Σ< m (λ i → Σ< n (f i)) ∙ Σ< n (f m) ≈⟨ ∙-congʳ $ Σ<-comm m n f ⟩ Σ< n (λ j → Σ< m (λ i → f i j)) ∙ Σ< n (λ j → f m j) ≈⟨ sym $ Σ<-distrib-+ n (λ j → Σ< m (λ i → f i j)) (λ j → f m j) ⟩ Σ< n (λ j → Σ< m (λ i → f i j) ∙ f m j) ≡⟨⟩ Σ< n (λ j → Σ< (suc m) (λ i → f i j)) ∎ Σ≤-comm : ∀ m n (f : ℕ → ℕ → Carrier) → Σ≤ m (λ i → Σ≤ n (λ j → f i j)) ≈ Σ≤ n (λ j → Σ≤ m (λ i → f i j)) Σ≤-comm m n f = Σ<-comm (suc m) (suc n) f Σ<range-comm : ∀ m n o p (f : ℕ → ℕ → Carrier) → Σ<range m n (λ i → Σ<range o p (λ j → f i j)) ≈ Σ<range o p (λ j → Σ<range m n (λ i → f i j)) Σ<range-comm m n o p f = Σ<-comm (n ∸ m) (p ∸ o) (λ i j → f (m ℕ.+ i) (o ℕ.+ j)) Σ≤range-comm : ∀ m n o p (f : ℕ → ℕ → Carrier) → Σ≤range m n (λ i → Σ≤range o p (λ j → f i j)) ≈ Σ≤range o p (λ j → Σ≤range m n (λ i → f i j)) Σ≤range-comm m n o p f = Σ<range-comm m (suc n) o (suc p) f Σ<-sumₜ-syntax : ∀ n f → Σ< n f ≈ sumₜ-syntax n (λ i → f (Fin.toℕ i)) Σ<-sumₜ-syntax 0 f = refl Σ<-sumₜ-syntax (suc n) f = begin Σ< (suc n) f ≈⟨ Σ<-push-suc n f ⟩ f 0 ∙ Σ< n (λ k → f (suc k)) ≈⟨ ∙-congˡ $ Σ<-sumₜ-syntax n (λ k → f (suc k)) ⟩ f 0 ∙ sumₜ-syntax n (λ i → f (Fin.toℕ (Fin.suc i))) ∎ Σ<-reverse : ∀ n f → Σ< n f ≈ Σ< n (λ i → f (n ∸ suc i)) Σ<-reverse 0 f = refl Σ<-reverse (suc n) f = begin Σ< (suc n) f ≈⟨ Σ<-push-suc n f ⟩ f 0 ∙ Σ< n (λ i → f (suc i)) ≈⟨ comm (f 0) (Σ< n (λ i → f (suc i))) ⟩ Σ< n (λ i → f (suc i)) ∙ f 0 ≈⟨ ∙-congʳ $ Σ<-reverse n (λ i → f (suc i)) ⟩ Σ< n (λ i → f (suc (n ∸ suc i))) ∙ f 0 ≈⟨ ∙-congʳ $ Σ<-congˡ-with-< n $ (λ i i<n → reflexive $ ≡.cong f $ ≡.sym $ ℕₚ.+-∸-assoc 1 i<n) ⟩ Σ< n (λ i → f (suc n ∸ suc i)) ∙ f 0 ≈⟨ ∙-congˡ $ reflexive $ ≡.cong f $ ≡.sym $ ℕₚ.n∸n≡0 (suc n) ⟩ Σ< n (λ i → f (suc n ∸ suc i)) ∙ f (suc n ∸ suc n) ≡⟨⟩ Σ< (suc n) (λ i → f (suc n ∸ suc i)) ∎ Σ≤-reverse : ∀ n f → Σ≤ n f ≈ Σ≤ n (λ i → f (n ∸ i)) Σ≤-reverse n f = Σ<-reverse (suc n) f Σ<range-reverse : ∀ m n f → Σ<range m n f ≈ Σ<range m n (λ i → f (m ℕ.+ (n ∸ suc i))) Σ<range-reverse m n f = begin Σ< (n ∸ m) (λ i → f (m ℕ.+ i)) ≈⟨ Σ<-reverse (n ∸ m) (λ i → f (m ℕ.+ i)) ⟩ Σ< (n ∸ m) (λ i → f (m ℕ.+ ((n ∸ m) ∸ suc i))) ≈⟨ Σ<-congˡ (n ∸ m) $ (λ i → reflexive $ ≡.cong f $ ≡.cong (m ℕ.+_) $ (≤R.begin-equality n ∸ m ∸ suc i ≤R.≡⟨ ℕₚ.∸-+-assoc n m (suc i) ⟩ n ∸ (m ℕ.+ suc i) ≤R.≡⟨ ≡.cong (n ∸_) $ ℕₚ.+-suc m i ⟩ n ∸ suc (m ℕ.+ i) ≤R.∎) ) ⟩ Σ< (n ∸ m) (λ i → f (m ℕ.+ (n ∸ suc (m ℕ.+ i)))) ≡⟨⟩ Σ<range m n (λ i → f (m ℕ.+ (n ∸ suc i))) ∎ where module ≤R = ℕₚ.≤-Reasoning Σ≤range-reverse : ∀ m n f → Σ≤range m n f ≈ Σ≤range m n (λ i → f (m ℕ.+ (n ∸ i))) Σ≤range-reverse m n f = Σ<range-reverse m (suc n) f Σ<-split-even : ∀ n f → Σ< (2 ℕ.* n) f ≈ Σ< n (λ i → f (2 ℕ.* i)) ∙ Σ< n (λ i → f (1 ℕ.+ 2 ℕ.* i)) Σ<-split-even 0 f = sym $ identityʳ ε Σ<-split-even (suc n) f = begin Σ< (2 ℕ.* suc n) f ≈⟨ Σ<-congʳ f $ ℕₚ.*-distribˡ-+ 2 1 n ⟩ Σ< (2 ℕ.+ 2 ℕ.* n) f ≡⟨⟩ Σ< (2 ℕ.* n) f ∙ f[2n] ∙ f[1+2n] ≈⟨ ∙-congʳ $ ∙-congʳ $ Σ<-split-even n f ⟩ Σ< n ev ∙ Σ< n od ∙ f[2n] ∙ f[1+2n] ≈⟨ assoc (Σ< n ev ∙ Σ< n od) f[2n] f[1+2n] ⟩ Σ< n ev ∙ Σ< n od ∙ (f[2n] ∙ f[1+2n]) ≈⟨ lemma (Σ< n ev) (Σ< n od) f[2n] f[1+2n] ⟩ Σ< (suc n) ev ∙ Σ< (suc n) od ∎ where f[2n] = f (2 ℕ.* n) f[1+2n] = f (1 ℕ.+ 2 ℕ.* n) ev = λ i → f (2 ℕ.* i) od = λ i → f (1 ℕ.+ 2 ℕ.* i) Σ<-split-odd : ∀ n f → Σ< (1 ℕ.+ 2 ℕ.* n) f ≈ Σ< (suc n) (λ i → f (2 ℕ.* i)) ∙ Σ< n (λ i → f (1 ℕ.+ 2 ℕ.* i)) Σ<-split-odd n f = begin Σ< (2 ℕ.* n) f ∙ f[2n] ≈⟨ ∙-congʳ $ Σ<-split-even n f ⟩ Σ< n ev ∙ Σ< n od ∙ f[2n] ≈⟨ trans (assoc (Σ< n ev) (Σ< n od) f[2n]) (∙-congˡ $ comm (Σ< n od) f[2n]) ⟩ Σ< n ev ∙ (f[2n] ∙ Σ< n od) ≈⟨ sym $ assoc (Σ< n ev) f[2n] (Σ< n od) ⟩ Σ< n ev ∙ f[2n] ∙ Σ< n od ∎ where f[2n] = f (2 ℕ.* n) ev = λ i → f (2 ℕ.* i) od = λ i → f (1 ℕ.+ 2 ℕ.* i) -- Σ<-comm-triangle : ∀ n f → Σ n (λ i → Σ< i (λ j → f i j)) ≈ module SemiringSummationProperties {c e} (SR : Semiring c e) where open Semiring SR open MonoidSummation +-monoid open CommutativeMonoidSummationProperties +-commutativeMonoid public open SetoidReasoning setoid Σ<-*-commute : ∀ n c f → Σ< n (λ k → c * f k) ≈ c * Σ< n f Σ<-*-commute ℕ.zero c f = sym $ zeroʳ c Σ<-*-commute (suc n) c f = begin Σ< n (λ k → c * f k) + c * f n ≈⟨ +-congʳ $ Σ<-*-commute n c f ⟩ c * Σ< n f + c * f n ≈⟨ sym $ distribˡ c (Σ< n f) (f n) ⟩ c * (Σ< n f + f n) ∎ Σ≤-*-commute : ∀ n c f → Σ≤ n (λ k → c * f k) ≈ c * Σ≤ n f Σ≤-*-commute n c f = Σ<-*-commute (suc n) c f Σ<range-*-commute : ∀ m n c f → Σ<range m n (λ k → c * f k) ≈ c * Σ<range m n f Σ<range-*-commute m n c f = Σ<-*-commute (n ∸ m) c (λ k → f (m ℕ.+ k)) Σ≤range-*-commute : ∀ m n c f → Σ≤range m n (λ k → c * f k) ≈ c * Σ≤range m n f Σ≤range-*-commute m n c f = Σ<range-*-commute m (suc n) c f Σ<-distrib-* : ∀ m n f g → Σ< m f * Σ< n g ≈ Σ< m (λ i → Σ< n (λ j → f i * g j)) Σ<-distrib-* 0 n f g = zeroˡ (Σ< n g) Σ<-distrib-* (suc m) n f g = begin Σ< (suc m) f * Σ< n g ≡⟨⟩ (Σ< m f + f m) * Σ< n g ≈⟨ distribʳ (Σ< n g) (Σ< m f) (f m) ⟩ Σ< m f * Σ< n g + f m * Σ< n g ≈⟨ +-cong (Σ<-distrib-* m n f g) (sym $ Σ<-*-commute n (f m) g) ⟩ Σ< m (λ i → Σ< n (λ j → f i * g j)) + Σ< n (λ j → f m * g j) ≡⟨⟩ Σ< (suc m) (λ i → Σ< n (λ j → f i * g j)) ∎ Σ≤-distrib-* : ∀ m n f g → Σ≤ m f * Σ≤ n g ≈ Σ≤ m (λ i → Σ≤ n (λ j → f i * g j)) Σ≤-distrib-* m n f g = Σ<-distrib-* (suc m) (suc n) f g Σ<range-distrib-* : ∀ m n o p f g → Σ<range m n f * Σ<range o p g ≈ Σ<range m n (λ i → Σ<range o p (λ j → f i * g j)) Σ<range-distrib-* m n o p f g = Σ<-distrib-* (n ∸ m) (p ∸ o) (λ i → f (m ℕ.+ i)) λ j → g (o ℕ.+ j) Σ≤range-distrib-* : ∀ m n o p f g → Σ≤range m n f * Σ≤range o p g ≈ Σ≤range m n (λ i → Σ≤range o p (λ j → f i * g j)) Σ≤range-distrib-* m n o p = Σ<range-distrib-* m (suc n) o (suc p) module GroupSummationProperties {c e} (G : Group c e) where open Group G open MonoidSummation monoid open MonoidSummationProperties monoid open SetoidReasoning setoid Σ<-telescope : ∀ n (f : ℕ → Carrier) → Σ< n (λ i → f i - f (suc i)) ≈ f 0 - f n Σ<-telescope 0 f = sym $ inverseʳ (f 0) Σ<-telescope (suc n) f = begin Σ< n (λ i → f i - f (suc i)) ∙ (f n - f (suc n)) ≈⟨ ∙-congʳ $ Σ<-telescope n f ⟩ (f 0 - f n) ∙ (f n - f (suc n)) ≈⟨ assoc (f 0) (f n ⁻¹) (f n - f (suc n)) ⟩ f 0 ∙ (f n ⁻¹ ∙ (f n - f (suc n))) ≈⟨ ∙-congˡ $ sym $ assoc (f n ⁻¹) (f n) (f (suc n) ⁻¹) ⟩ f 0 ∙ ((f n ⁻¹ ∙ f n) - f (suc n)) ≈⟨ ∙-congˡ $ ∙-congʳ $ inverseˡ (f n) ⟩ f 0 ∙ (ε - f (suc n)) ≈⟨ ∙-congˡ $ identityˡ (f (suc n) ⁻¹) ⟩ f 0 - f (suc n) ∎ Σ≤-telescope : ∀ n (f : ℕ → Carrier) → Σ≤ n (λ i → f i - f (suc i)) ≈ f 0 - f (suc n) Σ≤-telescope n f = Σ<-telescope (suc n) f Σ<range-telescope : ∀ {m n} (f : ℕ → Carrier) → m ≤ n → Σ<range m n (λ i → f i - f (suc i)) ≈ f m - f n Σ<range-telescope {m} {n} f m≤n = begin Σ< (n ∸ m) (λ i → f (m ℕ.+ i) - f (suc (m ℕ.+ i))) ≈⟨ Σ<-congˡ (n ∸ m) $ (λ i → ∙-congˡ $ ⁻¹-cong $ reflexive $ ≡.cong f $ ≡.sym $ ℕₚ.+-suc m i) ⟩ Σ< (n ∸ m) (λ i → f (m ℕ.+ i) - f (m ℕ.+ suc i)) ≈⟨ Σ<-telescope (n ∸ m) (λ i → f (m ℕ.+ i)) ⟩ f (m ℕ.+ 0) - f (m ℕ.+ (n ∸ m)) ≈⟨ ∙-cong (reflexive $ ≡.cong f $ ℕₚ.+-identityʳ m) (⁻¹-cong $ reflexive $ ≡.cong f $ ℕₚ.m+[n∸m]≡n m≤n) ⟩ f m - f n ∎ Σ≤range-telescope : ∀ {m n} (f : ℕ → Carrier) → m ≤ suc n → Σ≤range m n (λ i → f i - f (suc i)) ≈ f m - f (suc n) Σ≤range-telescope {m} {n} f m≤1+n = Σ<range-telescope {m} {suc n} f m≤1+n -- module AbelianGroupSummationProperties -- Σ<-minus-commute : ∀ n f → Σ< n (λ i → f i ⁻¹) ≈ Σ< n f ⁻¹
{ "alphanum_fraction": 0.430816066, "avg_line_length": 37.8550185874, "ext": "agda", "hexsha": "6a884eac2e39c67eb164aa717868b084d0872114", "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": "Math/NumberTheory/Summation/Generic/Properties.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": "Math/NumberTheory/Summation/Generic/Properties.agda", "max_line_length": 111, "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": "Math/NumberTheory/Summation/Generic/Properties.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": 11638, "size": 20366 }
-- Andreas, 2013-03-22 module Issue473a where data D : Set where d : D data P : D → Set where p : P d record Rc : Set where constructor c field f : D works : {r : Rc} → P (Rc.f r) → Set works p = D works' : (r : Rc) → P (Rc.f r) → Set works' (c .d) p = D -- If we remove the constructor, the example fails: record R : Set where field f : D fails : {r : R} → P (R.f r) → Set fails p = D -- d != R.f r of type D -- when checking that the pattern p has type P (R.f r) -- The error is justified since there is no pattern we could write down -- for r. It would have to look like -- -- record { f = .d } -- -- but anonymous record patterns are not supported.
{ "alphanum_fraction": 0.6079881657, "avg_line_length": 18.2702702703, "ext": "agda", "hexsha": "e3e8fee8b3f78d035db1b2615e54013cbfa95bf9", "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/Issue473a.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/Issue473a.agda", "max_line_length": 71, "max_stars_count": 1, "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_path": "test/fail/Issue473a.agda", "max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z", "num_tokens": 228, "size": 676 }
module Data.List.Relation.Quantification where import Lvl open import Data.List open import Logic open import Type private variable ℓ ℓₑ : Lvl.Level private variable T A B : Type{ℓ} private variable l l₁ l₂ : List(T) private variable x y px py : T private variable P : T → Stmt{ℓ} -- TODO: How about this as an alternative definition? -- module _ (P : T → Type{ℓ}) where -- open import Type.Dependent -- open Data.IndexedList(Σ T P){List(T)} using (IndexedList ; intro) -- -- AllElements : List(T) → Stmt{Lvl.of(T) Lvl.⊔ ℓ} -- AllElements = IndexedList(intro ∅ ((_⊰_) ∘ Σ.left)) data AllElements (P : T → Stmt{ℓ}) : List(T) → Stmt{Lvl.of(T) Lvl.⊔ ℓ} where ∅ : AllElements(P)(∅) _⊰_ : P(x) → AllElements(P)(l) → AllElements(P)(x ⊰ l) data ExistsElement (P : T → Stmt{ℓ}) : List(T) → Stmt{Lvl.of(T) Lvl.⊔ ℓ} where •_ : P(x) → ExistsElement(P)(x ⊰ l) ⊰_ : ExistsElement(P)(l) → ExistsElement(P)(x ⊰ l) -- TODO: Maybe remove this and use AllElements with map₂ instead data AllElements₂ (P : A → B → Stmt{ℓ}) : List(A) → List(B) → Stmt{Lvl.of(A) Lvl.⊔ Lvl.of(B) Lvl.⊔ ℓ} where ∅ : AllElements₂(P)(∅)(∅) _⊰_ : P(x)(y) → AllElements₂(P)(l₁)(l₂) → AllElements₂(P)(x ⊰ l₁)(y ⊰ l₂) ∀ₗᵢₛₜ : List(T) → (T → Stmt{ℓ}) → Stmt ∀ₗᵢₛₜ(l) P = AllElements P l ∃ₗᵢₛₜ : List(T) → (T → Stmt{ℓ}) → Stmt ∃ₗᵢₛₜ(l) P = ExistsElement P l module _ {P : T → Type{ℓ}} where open import Logic.Propositional open import Structure.Relator.Equivalence import Structure.Relator.Names as Names open import Structure.Relator.Properties open import Structure.Setoid data ExistsElementEquivalence : ExistsElement(P)(l) → ExistsElement(P)(l) → Stmt{Lvl.of(T) Lvl.⊔ ℓ} where use : ExistsElementEquivalence{l = x ⊰ l}(• px)(• py) skip : ExistsElementEquivalence(px)(py) → ExistsElementEquivalence{l = x ⊰ l}(⊰ px)(⊰ py) instance ExistsElementEquivalence-equiv : Equiv(ExistsElement(P)(l)) Equiv._≡_ ExistsElementEquivalence-equiv = ExistsElementEquivalence Equiv.equivalence ExistsElementEquivalence-equiv = intro ⦃ intro refl ⦄ ⦃ intro sym ⦄ ⦃ intro trans ⦄ where refl : Names.Reflexivity(ExistsElementEquivalence{l = l}) refl{x = • _} = use refl{x = ⊰ p} = skip(refl{x = p}) sym : Names.Symmetry(ExistsElementEquivalence{l = l}) sym {x = • px} {y = • py} use = use sym {x = ⊰ px} {y = ⊰ py} (skip p) = skip(sym{x = px}{y = py} p) trans : Names.Transitivity(ExistsElementEquivalence{l = l}) trans {x = • px} {y = • py} {z = • pz} use use = use trans {x = ⊰ px} {y = ⊰ py} {z = ⊰ pz} (skip p) (skip q) = skip(trans {x = px} {y = py} {z = pz} p q) module _ where open import Type.Properties.Singleton ExistsUniqueElement : (T → Stmt{ℓ}) → List(T) → Stmt ExistsUniqueElement P l = IsUnit(ExistsElement(P)(l)) ⦃ ExistsElementEquivalence-equiv ⦄ ∃!ₗᵢₛₜ : List(T) → (T → Stmt{ℓ}) → Stmt ∃!ₗᵢₛₜ(l) P = ExistsUniqueElement P l
{ "alphanum_fraction": 0.6301184433, "avg_line_length": 39.4, "ext": "agda", "hexsha": "fecbc52a14f59e56ac90e539f3b055907a01e766", "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/Relation/Quantification.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/Relation/Quantification.agda", "max_line_length": 111, "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/Relation/Quantification.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": 1099, "size": 2955 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Semigroup.MorphismProperties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.HLevels open import Cubical.Foundations.Univalence open import Cubical.Foundations.SIP open import Cubical.Foundations.Function using (_∘_; id) open import Cubical.Foundations.GroupoidLaws open import Cubical.Functions.Embedding open import Cubical.Data.Sigma open import Cubical.Algebra open import Cubical.Algebra.Properties open import Cubical.Algebra.Semigroup.Morphism open import Cubical.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Pointed open import Cubical.Algebra.Magma.Properties using (isPropIsMagma) open import Cubical.Relation.Binary.Reasoning.Equality open Iso private variable ℓ ℓ′ ℓ′′ : Level R : Semigroup ℓ S : Semigroup ℓ′ T : Semigroup ℓ′′ isPropIsSemigroupHom : ∀ (S : Semigroup ℓ) (T : Semigroup ℓ′) f → isProp (IsSemigroupHom S T f) isPropIsSemigroupHom S T f = isPropHomomorphic₂ (Semigroup.is-set T) f (Semigroup._•_ S) (Semigroup._•_ T) isSetSemigroupHom : isSet (S ⟶ᴴ T) isSetSemigroupHom {S = S} {T = T} = isOfHLevelRespectEquiv 2 equiv (isSetΣ (isSetΠ λ _ → is-set T) (λ f → isProp→isSet (isPropIsSemigroupHom S T f))) where open Semigroup equiv : (Σ[ g ∈ (⟨ S ⟩ → ⟨ T ⟩) ] IsSemigroupHom S T g) ≃ SemigroupHom S T equiv = isoToEquiv (iso (λ (g , m) → semigrouphom g m) (λ (semigrouphom g m) → g , m) (λ _ → refl) λ _ → refl) isSemigroupHomComp : {f : ⟨ R ⟩ → ⟨ S ⟩} {g : ⟨ S ⟩ → ⟨ T ⟩} → IsSemigroupHom R S f → IsSemigroupHom S T g → IsSemigroupHom R T (g ∘ f) isSemigroupHomComp {g = g} fHom gHom _ _ = cong g (fHom _ _) ∙ gHom _ _ private isSemigroupHomComp′ : (f : R ⟶ᴴ S) (g : S ⟶ᴴ T) → IsSemigroupHom R T (SemigroupHom.fun g ∘ SemigroupHom.fun f) isSemigroupHomComp′ (semigrouphom f fHom) (semigrouphom g gHom) _ _ = cong g (fHom _ _) ∙ gHom _ _ compSemigroupHom : (R ⟶ᴴ S) → (S ⟶ᴴ T) → (R ⟶ᴴ T) compSemigroupHom f g = semigrouphom _ (isSemigroupHomComp′ f g) compSemigroupEquiv : R ≃ᴴ S → S ≃ᴴ T → R ≃ᴴ T compSemigroupEquiv f g = semigroupequiv (compEquiv f.eq g.eq) (isSemigroupHomComp′ f.hom g.hom) where module f = SemigroupEquiv f module g = SemigroupEquiv g isSemigroupHomId : (S : Semigroup ℓ) → IsSemigroupHom S S id isSemigroupHomId S _ _ = refl idSemigroupHom : (S : Semigroup ℓ) → (S ⟶ᴴ S) idSemigroupHom S = record { fun = id ; isHom = isSemigroupHomId S } idSemigroupEquiv : (S : Semigroup ℓ) → S ≃ᴴ S idSemigroupEquiv S = record { eq = idEquiv ⟨ S ⟩ ; isHom = isSemigroupHomId S } -- Isomorphism inversion isSemigroupHomInv : (eqv : S ≃ᴴ T) → IsSemigroupHom T S (invEq (SemigroupEquiv.eq eqv)) isSemigroupHomInv {S = S} {T = T} (semigroupequiv eq isHom) x y = isInj-f _ _ ( f (f⁻¹ (x •ᵀ y)) ≡⟨ retEq eq _ ⟩ x •ᵀ y ≡˘⟨ cong₂ _•ᵀ_ (retEq eq x) (retEq eq y) ⟩ f (f⁻¹ x) •ᵀ f (f⁻¹ y) ≡˘⟨ isHom (f⁻¹ x) (f⁻¹ y) ⟩ f (f⁻¹ x • f⁻¹ y) ∎) where _•_ = Semigroup._•_ S -- superscript S isn't available for some reason _•ᵀ_ = Semigroup._•_ T f = equivFun eq f⁻¹ = invEq eq isInj-f : (x y : ⟨ S ⟩) → f x ≡ f y → x ≡ y isInj-f x y = invEq (_ , isEquiv→isEmbedding (eq .snd) x y) invSemigroupHom : S ≃ᴴ T → (T ⟶ᴴ S) invSemigroupHom eq = record { isHom = isSemigroupHomInv eq } invSemigroupEquiv : S ≃ᴴ T → T ≃ᴴ S invSemigroupEquiv eq = record { eq = invEquiv (SemigroupEquiv.eq eq) ; isHom = isSemigroupHomInv eq } semigroupHomEq : {f g : S ⟶ᴴ T} → (SemigroupHom.fun f ≡ SemigroupHom.fun g) → f ≡ g semigroupHomEq {S = S} {T = T} {semigrouphom f fm} {semigrouphom g gm} p i = semigrouphom (p i) (p-hom i) where p-hom : PathP (λ i → IsSemigroupHom S T (p i)) fm gm p-hom = toPathP (isPropIsSemigroupHom S T _ _ _) semigroupEquivEq : {f g : S ≃ᴴ T} → (SemigroupEquiv.eq f ≡ SemigroupEquiv.eq g) → f ≡ g semigroupEquivEq {S = S} {T = T} {semigroupequiv f fm} {semigroupequiv g gm} p i = semigroupequiv (p i) (p-hom i) where p-hom : PathP (λ i → IsSemigroupHom S T (p i .fst)) fm gm p-hom = toPathP (isPropIsSemigroupHom S T _ _ _) module SemigroupΣTheory {ℓ} where RawSemigroupStructure : Type ℓ → Type ℓ RawSemigroupStructure X = X → X → X RawSemigroupEquivStr = AutoEquivStr RawSemigroupStructure rawSemigroupUnivalentStr : UnivalentStr _ RawSemigroupEquivStr rawSemigroupUnivalentStr = autoUnivalentStr RawSemigroupStructure SemigroupAxioms : (A : Type ℓ) → RawSemigroupStructure A → Type ℓ SemigroupAxioms A _•_ = IsMagma A _•_ × Associative _•_ SemigroupStructure : Type ℓ → Type ℓ SemigroupStructure = AxiomsStructure RawSemigroupStructure SemigroupAxioms SemigroupΣ : Type (ℓ-suc ℓ) SemigroupΣ = TypeWithStr ℓ SemigroupStructure isPropSemigroupAxioms : (A : Type ℓ) (_•_ : RawSemigroupStructure A) → isProp (SemigroupAxioms A _•_) isPropSemigroupAxioms A _•_ = isPropΣ isPropIsMagma λ isMagmaA → isPropAssociative (IsMagma.is-set isMagmaA) _•_ SemigroupEquivStr : StrEquiv SemigroupStructure ℓ SemigroupEquivStr = AxiomsEquivStr RawSemigroupEquivStr SemigroupAxioms SemigroupAxiomsIsoIsSemigroup : {A : Type ℓ} {_•_ : RawSemigroupStructure A} → Iso (SemigroupAxioms A _•_) (IsSemigroup A _•_) fun SemigroupAxiomsIsoIsSemigroup (x , y) = issemigroup x y inv SemigroupAxiomsIsoIsSemigroup (issemigroup x y) = (x , y) rightInv SemigroupAxiomsIsoIsSemigroup _ = refl leftInv SemigroupAxiomsIsoIsSemigroup _ = refl SemigroupAxioms≡IsSemigroup : {A : Type ℓ} {_•_ : RawSemigroupStructure A} → SemigroupAxioms _ _•_ ≡ IsSemigroup A _•_ SemigroupAxioms≡IsSemigroup = isoToPath SemigroupAxiomsIsoIsSemigroup Semigroup→SemigroupΣ : Semigroup ℓ → SemigroupΣ Semigroup→SemigroupΣ (mksemigroup A _•_ isSemigroupA) = A , _•_ , SemigroupAxiomsIsoIsSemigroup .inv isSemigroupA SemigroupΣ→Semigroup : SemigroupΣ → Semigroup ℓ SemigroupΣ→Semigroup (A , _•_ , isSemigroupA) = mksemigroup A _•_ (SemigroupAxiomsIsoIsSemigroup .fun isSemigroupA) SemigroupIsoSemigroupΣ : Iso (Semigroup ℓ) SemigroupΣ SemigroupIsoSemigroupΣ = iso Semigroup→SemigroupΣ SemigroupΣ→Semigroup (λ _ → refl) (λ _ → refl) semigroupUnivalentStr : UnivalentStr SemigroupStructure SemigroupEquivStr semigroupUnivalentStr = axiomsUnivalentStr _ isPropSemigroupAxioms rawSemigroupUnivalentStr SemigroupΣPath : (S T : SemigroupΣ) → (S ≃[ SemigroupEquivStr ] T) ≃ (S ≡ T) SemigroupΣPath = SIP semigroupUnivalentStr SemigroupEquivΣ : (S T : Semigroup ℓ) → Type ℓ SemigroupEquivΣ S T = Semigroup→SemigroupΣ S ≃[ SemigroupEquivStr ] Semigroup→SemigroupΣ T SemigroupIsoΣPath : {S T : Semigroup ℓ} → Iso (SemigroupEquiv S T) (SemigroupEquivΣ S T) fun SemigroupIsoΣPath (semigroupequiv e h) = (e , h) inv SemigroupIsoΣPath (e , h) = semigroupequiv e h rightInv SemigroupIsoΣPath _ = refl leftInv SemigroupIsoΣPath _ = refl SemigroupPath : (S T : Semigroup ℓ) → (SemigroupEquiv S T) ≃ (S ≡ T) SemigroupPath S T = SemigroupEquiv S T ≃⟨ isoToEquiv SemigroupIsoΣPath ⟩ SemigroupEquivΣ S T ≃⟨ SemigroupΣPath _ _ ⟩ Semigroup→SemigroupΣ S ≡ Semigroup→SemigroupΣ T ≃⟨ isoToEquiv (invIso (congIso SemigroupIsoSemigroupΣ)) ⟩ S ≡ T ■ RawSemigroupΣ : Type (ℓ-suc ℓ) RawSemigroupΣ = TypeWithStr ℓ RawSemigroupStructure Semigroup→RawSemigroupΣ : Semigroup ℓ → RawSemigroupΣ Semigroup→RawSemigroupΣ S = (⟨ S ⟩ , Semigroup._•_ S) InducedSemigroup : (S : Semigroup ℓ) (T : RawSemigroupΣ) (e : ⟨ S ⟩ ≃ ⟨ T ⟩) → RawSemigroupEquivStr (Semigroup→RawSemigroupΣ S) T e → Semigroup ℓ InducedSemigroup S T e r = SemigroupΣ→Semigroup (inducedStructure rawSemigroupUnivalentStr (Semigroup→SemigroupΣ S) T (e , r)) InducedSemigroupPath : (S : Semigroup ℓ) (T : RawSemigroupΣ) (e : ⟨ S ⟩ ≃ ⟨ T ⟩) (E : RawSemigroupEquivStr (Semigroup→RawSemigroupΣ S) T e) → S ≡ InducedSemigroup S T e E InducedSemigroupPath S T e E = SemigroupPath S (InducedSemigroup S T e E) .fst (semigroupequiv e E) -- We now extract the important results from the above module open SemigroupΣTheory public using (InducedSemigroup; InducedSemigroupPath) SemigroupPath : (S ≃ᴴ T) ≃ (S ≡ T) SemigroupPath = SemigroupΣTheory.SemigroupPath _ _ isPropIsSemigroup : {A : Type ℓ} {_•_ : Op₂ A} → isProp (IsSemigroup A _•_) isPropIsSemigroup = subst isProp SemigroupΣTheory.SemigroupAxioms≡IsSemigroup (SemigroupΣTheory.isPropSemigroupAxioms _ _) open Semigroup uaSemigroup : S ≃ᴴ T → S ≡ T uaSemigroup = equivFun SemigroupPath carac-uaSemigroup : {S T : Semigroup ℓ} (f : S ≃ᴴ T) → cong Carrier (uaSemigroup f) ≡ ua (SemigroupEquiv.eq f) carac-uaSemigroup (semigroupequiv f m) = (refl ∙∙ ua f ∙∙ refl) ≡˘⟨ rUnit (ua f) ⟩ ua f ∎ Semigroup≡ : (S T : Semigroup ℓ) → ( Σ[ p ∈ ⟨ S ⟩ ≡ ⟨ T ⟩ ] Σ[ q ∈ PathP (λ i → p i → p i → p i) (_•_ S) (_•_ T) ] PathP (λ i → IsSemigroup (p i) (q i)) (isSemigroup S) (isSemigroup T)) ≃ (S ≡ T) Semigroup≡ S T = isoToEquiv (iso (λ (p , q , r) i → mksemigroup (p i) (q i) (r i)) (λ p → cong Carrier p , cong _•_ p , cong isSemigroup p) (λ _ → refl) (λ _ → refl)) caracSemigroup≡ : {S T : Semigroup ℓ} (p q : S ≡ T) → cong Carrier p ≡ cong Carrier q → p ≡ q caracSemigroup≡ {S = S} {T} p q t = cong (fst (Semigroup≡ S T)) (Σ≡Prop (λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set T) _ _) λ _ → isOfHLevelPathP 1 isPropIsSemigroup _ _) t) uaSemigroupId : (S : Semigroup ℓ) → uaSemigroup (idSemigroupEquiv S) ≡ refl uaSemigroupId S = caracSemigroup≡ _ _ (carac-uaSemigroup (idSemigroupEquiv S) ∙ uaIdEquiv) uaCompSemigroupEquiv : {R S T : Semigroup ℓ} (f : R ≃ᴴ S) (g : S ≃ᴴ T) → uaSemigroup (compSemigroupEquiv f g) ≡ uaSemigroup f ∙ uaSemigroup g uaCompSemigroupEquiv f g = caracSemigroup≡ _ _ ( cong Carrier (uaSemigroup (compSemigroupEquiv f g)) ≡⟨ carac-uaSemigroup (compSemigroupEquiv f g) ⟩ ua (eq (compSemigroupEquiv f g)) ≡⟨ uaCompEquiv _ _ ⟩ ua (eq f) ∙ ua (eq g) ≡˘⟨ cong (_∙ ua (eq g)) (carac-uaSemigroup f) ⟩ cong Carrier (uaSemigroup f) ∙ ua (eq g) ≡˘⟨ cong (cong Carrier (uaSemigroup f) ∙_) (carac-uaSemigroup g) ⟩ cong Carrier (uaSemigroup f) ∙ cong Carrier (uaSemigroup g) ≡˘⟨ cong-∙ Carrier (uaSemigroup f) (uaSemigroup g) ⟩ cong Carrier (uaSemigroup f ∙ uaSemigroup g) ∎) where open SemigroupEquiv
{ "alphanum_fraction": 0.6618392469, "avg_line_length": 40.4688644689, "ext": "agda", "hexsha": "085eadbe472f2705da7870a0ffe434b29af05e34", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bijan2005/univalent-foundations", "max_forks_repo_path": "Cubical/Algebra/Semigroup/MorphismProperties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bijan2005/univalent-foundations", "max_issues_repo_path": "Cubical/Algebra/Semigroup/MorphismProperties.agda", "max_line_length": 114, "max_stars_count": null, "max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bijan2005/univalent-foundations", "max_stars_repo_path": "Cubical/Algebra/Semigroup/MorphismProperties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4116, "size": 11048 }
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Unary.Any.Properties directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Any.Properties where open import Data.List.Relation.Unary.Any.Properties public {-# WARNING_ON_IMPORT "Data.List.Any.Properties was deprecated in v1.0. Use Data.List.Relation.Unary.Any.Properties instead." #-}
{ "alphanum_fraction": 0.5501858736, "avg_line_length": 29.8888888889, "ext": "agda", "hexsha": "0b6ea86a4ee0ddbe1a933299b9b4fb0697ce211f", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Data/List/Any/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Data/List/Any/Properties.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Data/List/Any/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 92, "size": 538 }
module Thesis.ANormalDTerm where open import Thesis.ANormal public open import Thesis.Changes public open import Thesis.LangChanges public ΔΔ : Context → Context ΔΔ ∅ = ∅ ΔΔ (τ • Γ) = Δt τ • ΔΔ Γ -- Because the standard name is so irregular. Δτ = Δt ChΔ : ∀ (Δ : Context) → Set ChΔ Δ = ⟦ ΔΔ Δ ⟧Context -- [_]Δ_from_to_ : ∀ Δ → ChΔ Δ → (ρ1 ρ2 : ⟦ Δ ⟧Context) → Set -- [ ∅ ]Δ ∅ from ∅ to ∅ = ⊤ -- [ τ • Δ ]Δ dv • dρ from v1 • ρ1 to (v2 • ρ2) = [ τ ]τ dv from v1 to v2 × [ Δ ]Δ dρ from ρ1 to ρ2 data [_]Δ_from_to_ : ∀ Δ → ChΔ Δ → (ρ1 ρ2 : ⟦ Δ ⟧Context) → Set where v∅ : [ ∅ ]Δ ∅ from ∅ to ∅ _v•_ : ∀ {τ Δ dv v1 v2 dρ ρ1 ρ2} → (dvv : [ τ ]τ dv from v1 to v2) → (dρρ : [ Δ ]Δ dρ from ρ1 to ρ2) → [ τ • Δ ]Δ (dv • dρ) from (v1 • ρ1) to (v2 • ρ2) derive-dvar : ∀ {Δ σ} → (x : Var Δ σ) → Var (ΔΔ Δ) (Δτ σ) derive-dvar this = this derive-dvar (that x) = that (derive-dvar x) fromtoDeriveDVar : ∀ {Δ τ} → (x : Var Δ τ) → ∀ {dρ ρ1 ρ2} → [ Δ ]Δ dρ from ρ1 to ρ2 → [ τ ]τ (⟦ derive-dvar x ⟧Var dρ) from (⟦ x ⟧Var ρ1) to (⟦ x ⟧Var ρ2) fromtoDeriveDVar this (dvv v• dρρ) = dvv fromtoDeriveDVar (that x) (dvv v• dρρ) = fromtoDeriveDVar x dρρ -- A DTerm evaluates in normal context Δ, change context (ΔΔ Δ), and produces -- a result of type (Δt τ). data DTerm : (Δ : Context) (τ : Type) → Set where dvar : ∀ {Δ τ} (x : Var (ΔΔ Δ) (Δt τ)) → DTerm Δ τ dlett : ∀ {Δ τ σ τ₁} → (f : Var Δ (σ ⇒ τ₁)) → (x : Var Δ σ) → (t : Term (τ₁ • Δ) τ) → (df : Var (ΔΔ Δ) (Δτ (σ ⇒ τ₁))) → (dx : Var (ΔΔ Δ) (Δτ σ)) → (dt : DTerm (τ₁ • Δ) τ) → DTerm Δ τ data DFun (Δ : Context) : (τ : Type) → Set where dterm : ∀ {τ} → DTerm Δ τ → DFun Δ τ dabs : ∀ {σ τ} → DFun (σ • Δ) τ → DFun Δ (σ ⇒ τ) derive-dterm : ∀ {Δ σ} → (t : Term Δ σ) → DTerm Δ σ derive-dterm (var x) = dvar (derive-dvar x) derive-dterm (lett f x t) = dlett f x t (derive-dvar f) (derive-dvar x) (derive-dterm t) ⟦_⟧DTerm : ∀ {Δ τ} → DTerm Δ τ → ⟦ Δ ⟧Context → ⟦ ΔΔ Δ ⟧Context → ⟦ Δt τ ⟧Type ⟦ dvar x ⟧DTerm ρ dρ = ⟦ x ⟧Var dρ ⟦ dlett f x t df dx dt ⟧DTerm ρ dρ = let v = (⟦ x ⟧Var ρ) in ⟦ dt ⟧DTerm (⟦ f ⟧Var ρ v • ρ) (⟦ df ⟧Var dρ v (⟦ dx ⟧Var dρ) • dρ) fromtoDeriveDTerm : ∀ {Δ τ} → (t : Term Δ τ) → ∀ {dρ ρ1 ρ2} → [ Δ ]Δ dρ from ρ1 to ρ2 → [ τ ]τ (⟦ derive-dterm t ⟧DTerm ρ1 dρ) from (⟦ t ⟧Term ρ1) to (⟦ t ⟧Term ρ2) fromtoDeriveDTerm (var x) dρρ = fromtoDeriveDVar x dρρ fromtoDeriveDTerm (lett f x t) dρρ = let fromToF = fromtoDeriveDVar f dρρ fromToX = fromtoDeriveDVar x dρρ fromToFX = fromToF _ _ _ fromToX in fromtoDeriveDTerm t (fromToFX v• dρρ) derive-dfun : ∀ {Δ σ} → (t : Fun Δ σ) → DFun Δ σ derive-dfun (term t) = dterm (derive-dterm t) derive-dfun (abs f) = dabs (derive-dfun f) ⟦_⟧DFun : ∀ {Δ τ} → DFun Δ τ → ⟦ Δ ⟧Context → ⟦ ΔΔ Δ ⟧Context → ⟦ Δt τ ⟧Type ⟦ dterm t ⟧DFun = ⟦ t ⟧DTerm ⟦ dabs df ⟧DFun ρ dρ = λ v dv → ⟦ df ⟧DFun (v • ρ) (dv • dρ) fromtoDeriveDFun : ∀ {Δ τ} → (f : Fun Δ τ) → ∀ {dρ ρ1 ρ2} → [ Δ ]Δ dρ from ρ1 to ρ2 → [ τ ]τ (⟦ derive-dfun f ⟧DFun ρ1 dρ) from (⟦ f ⟧Fun ρ1) to (⟦ f ⟧Fun ρ2) fromtoDeriveDFun (term t) = fromtoDeriveDTerm t fromtoDeriveDFun (abs f) dρρ = λ dv v1 v2 dvv → fromtoDeriveDFun f (dvv v• dρρ)
{ "alphanum_fraction": 0.5591734502, "avg_line_length": 34.3440860215, "ext": "agda", "hexsha": "5c2ed5920bcb395c8b0a61060a5d75bb440670a6", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Thesis/ANormalDTerm.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Thesis/ANormalDTerm.agda", "max_line_length": 99, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Thesis/ANormalDTerm.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 1598, "size": 3194 }
module _ where postulate A B C D E F : Set a : A b : B c : C d : D e : E f : F T : {A : Set} → A → Set module M1 (a : A) where module M2 (b : B) where postulate g : T a → T b module M3 (c : C) where postulate h : T a → T b → T c module M4 (d : D) where module M5 (e : E) (f : F) where open M2 public open M2.M3 public open M3 public renaming (h to h') module M = M1.M4 a d module M' = M.M5 e f M'g : (x : B) → T a → T x M'g = M'.g M'M3h M'h M'h' : (x : B) (y : C) → T a → T x → T y M'M3h = M'.M3.h M'h = M'.h M'h' = M'.h'
{ "alphanum_fraction": 0.4769230769, "avg_line_length": 16.7142857143, "ext": "agda", "hexsha": "8536df9a673d2f47442f3975e7d1be1880918cef", "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/Issue1985b.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/Issue1985b.agda", "max_line_length": 50, "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/Issue1985b.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": 271, "size": 585 }
{-# OPTIONS --without-K #-} open import HoTT.Base open import HoTT.Identity open import HoTT.Homotopy module HoTT.Equivalence where open variables private variable C : 𝒰 i module _ (f : A → B) where qinv = Σ[ g ∶ (B → A) ] (g ∘ f ~ id) × (f ∘ g ~ id) -- Bi-invertible map linv = Σ[ g ∶ (B → A) ] g ∘ f ~ id rinv = Σ[ g ∶ (B → A) ] f ∘ g ~ id -- The book uses a flipped version rinv × linv for the definition in §2.4. biinv = linv × rinv -- Half-adjoint equivalence ishae = Σ[ g ∶ (B → A) ] Σ[ η ∶ g ∘ f ~ id ] Σ[ ε ∶ f ∘ g ~ id ] ap f ∘ η ~ ε ∘ f module _ {f : A → B} where module qinv (e : qinv f) where g = pr₁ e η = pr₁ (pr₂ e) ε = pr₂ (pr₂ e) qinv→linv : qinv f → linv f qinv→linv e = g , η where open qinv e qinv→rinv : qinv f → rinv f qinv→rinv e = g , ε where open qinv e module ishae (e : ishae f) where g = pr₁ e η = pr₁ (pr₂ e) ε = pr₁ (pr₂ (pr₂ e)) τ = pr₂ (pr₂ (pr₂ e)) ishae→qinv : ishae f → qinv f ishae→qinv e = g , η , ε where open ishae e qinv→ishae : qinv f → ishae f qinv→ishae e = g , η , ε' , τ where open qinv e ε' : f ∘ g ~ id ε' b = ε (f (g b)) ⁻¹ ∙ (ap f (η (g b)) ∙ ε b) τ : ap f ∘ η ~ ε' ∘ f τ a = ap f (η a) =⟨ unitₗ ⟩ refl ∙ ap f (η a) =⟨ invₗ ⁻¹ ∙ᵣ _ ⟩ _ ∙ ε (f (g (f a))) ∙ ap f (η a) =⟨ assoc ⁻¹ ⟩ _ ∙ (_ ∙ ap f (η a)) =⟨ _ ∙ₗ (_ ∙ₗ ap-id (ap f (η a)) ⁻¹) ⟩ _ ∙ (ε (f (g (f a))) ∙ ap id _) =⟨ _ ∙ₗ ~-natural ε (ap f (η a)) ⟩ _ ∙ (ap (f ∘ g) (ap f (η a)) ∙ _) =⟨ _ ∙ₗ (ap-∘ (f ∘ g) f (η a) ⁻¹ ∙ᵣ _) ⟩ _ ∙ (ap (f ∘ g ∘ f) (η a) ∙ _) =⟨ _ ∙ₗ (ap-∘ f (g ∘ f) (η a) ∙ᵣ _) ⟩ _ ∙ (ap f (ap (g ∘ f) (η a)) ∙ _) =⟨ _ ∙ₗ (ap (ap f) (~-natural-comm η a ⁻¹) ∙ᵣ _) ⟩ ε' (f a) ∎ where open =-Reasoning module biinv (e : biinv f) where h = pr₁ (pr₁ e) β = pr₂ (pr₁ e) g = pr₁ (pr₂ e) α = pr₂ (pr₂ e) biinv→qinv : biinv f → qinv f biinv→qinv e = g , β' , α where open biinv e γ : g ~ h γ x = β (g x) ⁻¹ ∙ ap h (α x) β' : g ∘ f ~ id β' x = γ (f x) ∙ β x qinv→biinv : qinv f → biinv f qinv→biinv e = (g , η) , (g , ε) where open qinv e module _ {f₁ : B → C} {f₂ : A → B} where ishae-∘ : ishae f₁ → ishae f₂ → ishae (f₁ ∘ f₂) ishae-∘ e₁ e₂ = g , η , ε , τ where open ishae e₁ renaming (g to g₁ ; η to η₁ ; ε to ε₁ ; τ to τ₁) open ishae e₂ renaming (g to g₂ ; η to η₂ ; ε to ε₂ ; τ to τ₂) f = f₁ ∘ f₂ g = g₂ ∘ g₁ η : g ∘ f ~ id η x = ap g₂ (η₁ (f₂ x)) ∙ η₂ x ε : f ∘ g ~ id ε x = ap f₁ (ε₂ (g₁ x)) ∙ ε₁ x τ : ap f ∘ η ~ ε ∘ f τ x = ap f (η x) =⟨ ap-∘ f₁ f₂ (ap g₂ (η₁ (f₂ x)) ∙ η₂ x) ⟩ ap f₁ (ap f₂ (η x)) =⟨ ap (ap f₁) (ap-∙ f₂ (ap g₂ (η₁ (f₂ x))) (η₂ x)) ⟩ ap f₁ (ap f₂ (ap g₂ (η₁ (f₂ x))) ∙ ap f₂ (η₂ x)) =⟨ ap (ap f₁) (ap f₂ _ ∙ₗ τ₂ x) ⟩ ap f₁ (ap f₂ (ap g₂ (η₁ (f₂ x))) ∙ ε₂ (f₂ x)) =⟨ ap (ap f₁) (ap-∘ f₂ g₂ _ ⁻¹ ∙ᵣ ε₂ (f₂ x)) ⟩ ap f₁ (ap (f₂ ∘ g₂) (η₁ (f₂ x)) ∙ ε₂ (f₂ x)) =⟨ ap (ap f₁) (~-natural ε₂ (η₁ (f₂ x))) ⁻¹ ⟩ ap f₁ (ε₂ (g₁ (f x)) ∙ ap id (η₁ (f₂ x))) =⟨ ap (ap f₁) (ε₂ (g₁ (f x)) ∙ₗ ap-id (η₁ (f₂ x))) ⟩ ap f₁ (ε₂ (g₁ (f x)) ∙ η₁ (f₂ x)) =⟨ ap-∙ f₁ (ε₂ (g₁ (f x))) (η₁ (f₂ x)) ⟩ ap f₁ (ε₂ (g₁ (f x))) ∙ ap f₁ (η₁ (f₂ x)) =⟨ _ ∙ₗ τ₁ (f₂ x) ⟩ ε (f x) ∎ where open =-Reasoning biinv-∘ : biinv f₁ → biinv f₂ → biinv (f₁ ∘ f₂) biinv-∘ e₁ e₂ = (h , β) , (g , α) where open biinv e₁ renaming (h to h₁ ; β to β₁ ; g to g₁ ; α to α₁) open biinv e₂ renaming (h to h₂ ; β to β₂ ; g to g₂ ; α to α₂) f = f₁ ∘ f₂ h = h₂ ∘ h₁ β : h ∘ f ~ id β x = ap h₂ (β₁ (f₂ x)) ∙ β₂ x g = g₂ ∘ g₁ α : f ∘ g ~ id α x = ap f₁ (α₂ (g₁ x)) ∙ α₁ x -- Choose isequiv :≡ biinv since it is quicker to compute. isequiv = biinv qinv→isequiv = qinv→biinv isequiv→qinv = biinv→qinv isequiv-∘ = biinv-∘ _≃_ : 𝒰 i → 𝒰 j → 𝒰 (i ⊔ j) A ≃ B = Σ (A → B) isequiv infixr 5 _≃_ record Iso (A : 𝒰 i) (B : 𝒰 j) : 𝒰 (i ⊔ j) where field f : A → B g : B → A η : g ∘ f ~ id ε : f ∘ g ~ id iso→eqv : Iso A B → A ≃ B iso→eqv iso = f , qinv→isequiv (g , η , ε) where open Iso iso eqv→iso : A ≃ B → Iso A B eqv→iso e = record { f = pr₁ e ; g = g ; η = η ; ε = ε } where open qinv (isequiv→qinv (pr₂ e)) module Eqv {i} {j} {A : 𝒰 i} {B : 𝒰 j} (e : A ≃ B) = Iso (eqv→iso e) -- Lemma 2.4.12 -- (i) reflₑ : A ≃ A reflₑ = id , qinv→isequiv (id , (λ _ → refl) , (λ _ → refl)) -- (ii) _⁻¹ₑ : A ≃ B → B ≃ A e ⁻¹ₑ = g , qinv→isequiv (pr₁ e , ε , η) where open qinv (isequiv→qinv (pr₂ e)) infix 30 _⁻¹ₑ -- (iii) _∙ₑ_ : A ≃ B → B ≃ C → A ≃ C e₁ ∙ₑ e₂ = pr₁ e₂ ∘ pr₁ e₁ , isequiv-∘ (pr₂ e₂) (pr₂ e₁) infixl 20 _∙ₑ_ idtoeqv : A == B → A ≃ B idtoeqv p = transport id p , e where e : isequiv (transport id p) e rewrite p = pr₂ reflₑ module ≃-Reasoning where _≃⟨_⟩_ : (A : 𝒰 i) → A ≃ B → B ≃ C → A ≃ C x ≃⟨ e₁ ⟩ e₂ = e₁ ∙ₑ e₂ infixr 2 _≃⟨_⟩_ _∎ : (A : 𝒰 i) → A ≃ A _ ∎ = reflₑ infix 3 _∎
{ "alphanum_fraction": 0.4467676961, "avg_line_length": 28.6428571429, "ext": "agda", "hexsha": "de6d702c54ae34b7b9373e8dbcde54da9e1d481b", "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": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "michaelforney/hott", "max_forks_repo_path": "HoTT/Equivalence.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "michaelforney/hott", "max_issues_repo_path": "HoTT/Equivalence.agda", "max_line_length": 107, "max_stars_count": null, "max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "michaelforney/hott", "max_stars_repo_path": "HoTT/Equivalence.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2683, "size": 5213 }
module CTL.Modalities.EU where -- TODO
{ "alphanum_fraction": 0.75, "avg_line_length": 10, "ext": "agda", "hexsha": "e82008d8c67d1363d1b2c4adb3f7963581a21fcc", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-12-13T15:56:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-12-13T15:56:38.000Z", "max_forks_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "zimbatm/condatis", "max_forks_repo_path": "CTL/Modalities/EU.agda", "max_issues_count": 5, "max_issues_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_issues_repo_issues_event_max_datetime": "2020-09-01T16:52:07.000Z", "max_issues_repo_issues_event_min_datetime": "2017-06-03T20:02:22.000Z", "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "zimbatm/condatis", "max_issues_repo_path": "CTL/Modalities/EU.agda", "max_line_length": 30, "max_stars_count": 1, "max_stars_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "Aerate/condatis", "max_stars_repo_path": "CTL/Modalities/EU.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-13T16:52:28.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-13T16:52:28.000Z", "num_tokens": 12, "size": 40 }
module BBHeap.Last {A : Set}(_≤_ : A → A → Set) where open import BBHeap _≤_ open import BBHeap.Compound _≤_ open import BBHeap.DropLast _≤_ open import Bound.Lower A open import Data.Sum last : {b : Bound}(h : BBHeap b) → Compound h → A last (left {b} {x} {l} {r} b≤x l⋘r) (cl .b≤x .l⋘r) with l | r | l⋘r | lemma-dropLast⋘ l⋘r ... | leaf | leaf | lf⋘ | _ = x ... | left x≤y₁ l₁⋘r₁ | left x≤y₂ l₂⋘r₂ | ll⋘ .x≤y₁ .x≤y₂ .l₁⋘r₁ .l₂⋘r₂ l₂≃r₂ r₁≃l₂ | inj₁ l≃r = last (left x≤y₂ l₂⋘r₂) (cl x≤y₂ l₂⋘r₂) ... | left x≤y₁ l₁⋘r₁ | left x≤y₂ l₂⋘r₂ | ll⋘ .x≤y₁ .x≤y₂ .l₁⋘r₁ .l₂⋘r₂ l₂≃r₂ r₁≃l₂ | inj₂ dl⋘r = last (left x≤y₁ l₁⋘r₁) (cl x≤y₁ l₁⋘r₁) ... | right x≤y₁ l₁⋙r₁ | left x≤y₂ l₂⋘r₂ | lr⋘ .x≤y₁ .x≤y₂ .l₁⋙r₁ .l₂⋘r₂ l₂≃r₂ l₁⋗l₂ | inj₁ () ... | right x≤y₁ l₁⋙r₁ | left x≤y₂ l₂⋘r₂ | lr⋘ .x≤y₁ .x≤y₂ .l₁⋙r₁ .l₂⋘r₂ l₂≃r₂ l₁⋗l₂ | inj₂ dl⋘r = last (right x≤y₁ l₁⋙r₁) (cr x≤y₁ l₁⋙r₁) last (right {b} {x} {l} {r} b≤x l⋙r) (cr .b≤x .l⋙r) with l | r | l⋙r | lemma-dropLast⋙ l⋙r ... | left x≤y lf⋘ | leaf | ⋙lf {x = y} .x≤y | _ = y ... | left x≤y₁ l₁⋘r₁ | left x≤y₂ l₂⋘r₂ | ⋙rl .x≤y₁ .x≤y₂ .l₁⋘r₁ l₁≃r₁ .l₂⋘r₂ l₁⋗r₂ | inj₁ l⋗r = last (left x≤y₁ l₁⋘r₁) (cl x≤y₁ l₁⋘r₁) ... | left x≤y₁ l₁⋘r₁ | left x≤y₂ l₂⋘r₂ | ⋙rl .x≤y₁ .x≤y₂ .l₁⋘r₁ l₁≃r₁ .l₂⋘r₂ l₁⋗r₂ | inj₂ l⋙dr = last (left x≤y₂ l₂⋘r₂) (cl x≤y₂ l₂⋘r₂) ... | left x≤y₁ l₁⋘r₁ | right x≤y₂ l₂⋙r₂ | ⋙rr .x≤y₁ .x≤y₂ .l₁⋘r₁ l₁≃r₁ .l₂⋙r₂ l₁≃l₂ | inj₁ () ... | left x≤y₁ l₁⋘r₁ | right x≤y₂ l₂⋙r₂ | ⋙rr .x≤y₁ .x≤y₂ .l₁⋘r₁ l₁≃r₁ .l₂⋙r₂ l₁≃l₂ | inj₂ l⋙dr = last (right x≤y₂ l₂⋙r₂) (cr x≤y₂ l₂⋙r₂)
{ "alphanum_fraction": 0.560130719, "avg_line_length": 63.75, "ext": "agda", "hexsha": "6d22bce572648cdd1789d10a5a096e0ac3b151ba", "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/BBHeap/Last.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/BBHeap/Last.agda", "max_line_length": 138, "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/BBHeap/Last.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": 1098, "size": 1530 }
module Categories.Functor.Discrete where open import Categories.Category open import Categories.Functor open import Categories.Agda open import Categories.Categories open import Categories.Support.PropositionalEquality import Categories.Discrete as D Discrete : ∀ {o} -> Functor (Sets o) (Categories o o _) Discrete {o} = record { F₀ = D.Discrete; F₁ = F₁; identity = λ f → Heterogeneous.≡⇒∼ _; homomorphism = λ f → Heterogeneous.≡⇒∼ _; F-resp-≡ = F-resp-≡} where F₁ : {A B : Category.Obj (Sets o)} → Sets o [ A , B ] → Categories o o _ [ D.Discrete A , D.Discrete B ] F₁ f = record { F₀ = f; F₁ = ≣-cong f; identity = _; homomorphism = _; F-resp-≡ = _ } F-resp-≡ : {A B : Set o} {F G : Sets o [ A , B ]} → Sets o [ F ≡ G ] → Categories o o _ [ F₁ F ≡ F₁ G ] F-resp-≡ F≡G {a} ≣-refl rewrite F≡G {a} = Heterogeneous.≡⇒∼ _
{ "alphanum_fraction": 0.531496063, "avg_line_length": 33.8666666667, "ext": "agda", "hexsha": "7f6e9dd815b71b6bf3a7726fd0779844a4af83a6", "lang": "Agda", "max_forks_count": 23, "max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z", "max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "p-pavel/categories", "max_forks_repo_path": "Categories/Functor/Discrete.agda", "max_issues_count": 19, "max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z", "max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "p-pavel/categories", "max_issues_repo_path": "Categories/Functor/Discrete.agda", "max_line_length": 72, "max_stars_count": 98, "max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "copumpkin/categories", "max_stars_repo_path": "Categories/Functor/Discrete.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z", "num_tokens": 328, "size": 1016 }
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Queue where open import Cubical.Data.Queue.Base public
{ "alphanum_fraction": 0.7297297297, "avg_line_length": 15.8571428571, "ext": "agda", "hexsha": "09eec2b0ddd17bce8d844e7368acb83010e28e90", "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": "c67854d2e11aafa5677e25a09087e176fafd3e43", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmester0/cubical", "max_forks_repo_path": "Cubical/Data/Queue.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43", "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": "cmester0/cubical", "max_issues_repo_path": "Cubical/Data/Queue.agda", "max_line_length": 42, "max_stars_count": 1, "max_stars_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmester0/cubical", "max_stars_repo_path": "Cubical/Data/Queue.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z", "max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z", "num_tokens": 26, "size": 111 }
open import OutsideIn.Prelude open import OutsideIn.X module OutsideIn.Proof.Soundness(x : X) where open import Data.Vec hiding (map; _>>=_) open X(x) import OutsideIn.Environments as EV import OutsideIn.Expressions as E import OutsideIn.TypeSchema as TS import OutsideIn.TopLevel as TL import OutsideIn.Constraints as CN import OutsideIn.Inference as I import OutsideIn.Inference.Separator as S import OutsideIn.Inference.Prenexer as P import OutsideIn.Inference.ConstraintGen as CG import OutsideIn.Inference.Solver as SL open EV(x) open E(x) open CN(x) open TS(x) open TL(x) open I(x) open CG(x) open S(x) open SL(x) open P(x) open import Relation.Binary.PropositionalEquality renaming ([_] to inspectC) module Ax-f = Functor(axiomscheme-is-functor) module QC-f = Functor(qconstraint-is-functor) module Exp-f {r}{s} = Functor(expression-is-functor₂ {r}{s}) module TS-f {n} = Functor(type-schema-is-functor {n}) module pn-m {n} = Monad(PlusN-is-monad{n}) module Vec-f {n} = Functor(vec-is-functor {n}) open Monad(type-is-monad) open Functor(is-functor) type-substitute : ∀{a b} → (a → Type b) → Type a → Type b type-substitute f t = (join ∘ map f) t applyAll : ∀{tv}(n : ℕ) → Type tv → Type (tv ⨁ n) applyAll zero x = x applyAll (suc n) x = applyAll n (appType (map suc x) (unit zero)) constraint-substitute : ∀{a b} → (a → Type b) → QConstraint a → QConstraint b constraint-substitute f t = constraint-types (type-substitute f) t mutual data _,_,_⊢_∶_ {ev tv : Set}(Q : AxiomScheme tv)(Qg : QConstraint tv)(Γ : Environment ev tv): {r : Shape} → Expression ev tv r → Type tv → Set where TyEq : ∀ {τ₁ τ₂}{r}{e : Expression ev tv r} → Q , Qg , Γ ⊢ e ∶ τ₁ → Q , Qg ⊩ (τ₁ ∼ τ₂) → Q , Qg , Γ ⊢ e ∶ τ₂ Abst : ∀ {τ₁ τ₂}{r}{e : Expression (Ⓢ ev) tv r} → Q , Qg , (⟨ ∀′ 0 · ε ⇒ τ₁ ⟩, Γ) ⊢ e ∶ τ₂ → Q , Qg , Γ ⊢ λ′ e ∶ funType τ₁ τ₂ Appl : ∀ {τ₁ τ₂}{r₁ r₂}{e₁ : Expression ev tv r₁}{e₂ : Expression ev tv r₂} → Q , Qg , Γ ⊢ e₁ ∶ funType τ₁ τ₂ → Q , Qg , Γ ⊢ e₂ ∶ τ₁ → Q , Qg , Γ ⊢ (e₁ · e₂) ∶ τ₂ Let1 : ∀ {τ₁ τ₂}{r₁ r₂}{e₁ : Expression ev tv r₁}{e₂ : Expression (Ⓢ ev) tv r₂} → Q , Qg , Γ ⊢ e₁ ∶ τ₁ → Q , Qg , (⟨ ∀′ 0 · ε ⇒ τ₁ ⟩, Γ) ⊢ e₂ ∶ τ₂ → Q , Qg , Γ ⊢ (let₁ e₁ in′ e₂) ∶ τ₂ Let2 : ∀ {τ₁ τ₂}{r₁ r₂}{e₁ : Expression ev tv r₁}{e₂ : Expression (Ⓢ ev) tv r₂} → Q , Qg , Γ ⊢ e₁ ∶ τ₁ → Q , Qg , (⟨ ∀′ 0 · ε ⇒ τ₁ ⟩, Γ) ⊢ e₂ ∶ τ₂ → Q , Qg , Γ ⊢ (let₂ e₁ ∷ τ₁ in′ e₂) ∶ τ₂ Let3 : ∀ {n}{τ₁ τ₂}{r₁ r₂}{Qv}{e₁ : Expression ev (tv ⨁ n) r₁}{e₂ : Expression (Ⓢ ev) tv r₂} → Ax-f.map (pn-m.unit {n}) Q , QC-f.map (pn-m.unit {n}) Qg ∧ Qv , TS-f.map (pn-m.unit {n}) ∘ Γ ⊢ e₁ ∶ τ₁ → Q , Qg , (⟨ ∀′ n · Qv ⇒ τ₁ ⟩, Γ) ⊢ e₂ ∶ τ₂ → Q , Qg , Γ ⊢ (let₃ n · e₁ ∷ Qv ⇒ τ₁ in′ e₂) ∶ τ₂ VarN : ∀ {n}{v}{τ}{Qv} → (θ : (tv ⨁ n) → Type tv) → Γ v ≡ ∀′ n · Qv ⇒ τ → Q , Qg ⊩ constraint-substitute θ Qv → Q , Qg , Γ ⊢ (Var {_}{_}{Regular} v) ∶ (τ >>= θ ) DCn1 : ∀ {n}{l}{v}{K}{args} → (θ : (tv ⨁ n) → Type tv) → Γ v ≡ (DC∀ n · args ⟶ K) → Q , Qg , Γ ⊢ (Var {_}{_}{Datacon l} v) ∶ (applyAll n (unit K) >>= θ) DCn2 : ∀ {a b}{l}{v}{K}{args}{Qv} → (θ : (tv ⨁ a) ⨁ b → Type tv) → Γ v ≡ (DC∀′ a , b · Qv ⇒ args ⟶ K) → Q , Qg ⊩ constraint-substitute θ Qv → Q , Qg , Γ ⊢ (Var {_}{_}{Datacon l} v) ∶ (map (pn-m.unit {b}) (applyAll a (unit K)) >>= θ) Case : ∀ {τ}{r r′}{e : Expression ev tv r}{alts : Alternatives ev tv r′} {n : ℕ} → (T : tv) → (θ : (tv ⨁ n) → Type tv) → Q , Qg , Γ ⊢ e ∶ (applyAll n (unit T) >>= θ) → AltsType {n = n} Q Qg Γ θ T alts τ → Q , Qg , Γ ⊢ case e of alts ∶ τ data AltsType {ev tv : Set}{n : ℕ}(Q : AxiomScheme tv)(Qg : QConstraint tv)(Γ : Environment ev tv)( θ : (tv ⨁ n) → Type tv)(T : tv) : {r : Shape} → Alternatives ev tv r → Type tv → Set where NoAlts : ∀ {τ} → AltsType Q Qg Γ θ T esac τ OneAlt : ∀ {τ}{a}{r₁ r₂}{p : Name ev (Datacon a)}{e : Expression (ev ⨁ a) tv r₁}{as : Alternatives ev tv r₂}{vs} → AltsType {n = n} Q Qg Γ θ T as τ → Γ p ≡ DC∀ n · vs ⟶ T → Q , Qg , addAll (Vec-f.map (λ x → x >>= θ) vs) Γ ⊢ e ∶ τ → AltsType Q Qg Γ θ T ((p →′ e) ∣ as) τ GATAlt : ∀ {x}{τ}{a}{r₁ r₂}{p : Name ev (Datacon a)}{e : Expression (ev ⨁ a) tv r₁}{as : Alternatives ev tv r₂}{vs}{Qv} → let θ′ : PlusN x (PlusN n tv) → Type (PlusN x tv) θ′ v = sequence-PlusN {Type}{x} ⦃ type-is-monad ⦄ (Functor.map (pn-m.is-functor {x}) θ v) Q′ = Ax-f.map (pn-m.unit {x}) Q Qg′ = QC-f.map (pn-m.unit {x}) Qg in AltsType {n = n} Q Qg Γ θ T as τ → Γ p ≡ DC∀′ n , x · Qv ⇒ vs ⟶ T → Q′ , Qg′ ∧ (constraint-substitute θ′ Qv) , addAll (Vec-f.map (λ x → x >>= θ′) vs) (TS-f.map (pn-m.unit {x}) ∘ Γ) ⊢ Exp-f.map (pn-m.unit {x}) e ∶ map (pn-m.unit {x}) τ → AltsType Q Qg Γ θ T ((p →′ e) ∣ as) τ data _,_,_⊢′_ {ev tv : Set}(Q : AxiomScheme tv)(Qg : QConstraint tv)(Γ : Environment ev tv): Program ev tv → Set where Empty : Q , Qg , Γ ⊢′ end Bind : {r : Shape}{n : ℕ}{e : Expression ev tv r}{p : Program (Ⓢ ev) tv}{Qv Q₁ : QConstraint (tv ⨁ n)}{τ : Type (tv ⨁ n)} → let Q′ = Ax-f.map (pn-m.unit {n}) Q Qg′ = QC-f.map (pn-m.unit {n}) Qg e′ = Exp-f.map (pn-m.unit {n}) e in Q′ , Qv ∧ Qg′ ⊩ Q₁ → Q′ , Q₁ , (TS-f.map (pn-m.unit {n}) ∘ Γ) ⊢ e′ ∶ τ → Q , Qg , (⟨ ∀′ n · Qv ⇒ τ ⟩, Γ) ⊢′ p → Q , Qg , Γ ⊢′ bind₁ e , p BindA : {r : Shape}{n : ℕ}{e : Expression ev (tv ⨁ n) r}{p : Program (Ⓢ ev) tv}{Qv Q₁ : QConstraint (tv ⨁ n)}{τ : Type (tv ⨁ n)} → let Q′ = Ax-f.map (pn-m.unit {n}) Q Qg′ = QC-f.map (pn-m.unit {n}) Qg in Q′ , Qv ∧ Qg′ ⊩ Q₁ → Q′ , Q₁ , (TS-f.map (pn-m.unit {n}) ∘ Γ) ⊢ e ∶ τ → Q , Qg , (⟨ ∀′ n · Qv ⇒ τ ⟩, Γ) ⊢′ p → Q , Qg , Γ ⊢′ bind₂ n · e ∷ Qv ⇒ τ , p open import Data.Empty -- I know that Γ (N v) == ∀′ α · q₁ ⇒ τ₁ -- I know that gen≡ soundness-lemma : ∀{r}{n}{ev}{tv}{Γ : Environment ev tv}{e : Expression ev tv r}{r′}{τ}{C}{C′}{C′′}{n′}{Q}{Qg}{Qr}{θ}{eq : Eq (tv ⨁ n)}{Cext} → Γ ► e ∶ τ ↝ C → C prenex: n , C′ → C′ separate: r′ , C′′ → Q , Qg , n solv► C′′ ↝ n′ , Qr , θ → let Q′ = Ax-f.map (pn-m.unit {n′}) Q Qg′ = QC-f.map (pn-m.unit {n′}) Qg e′ = Exp-f.map (pn-m.unit {n′}) e in ∃ (λ Qe → (Q′ , Qe , TS-f.map (pn-m.unit {n′}) ∘ Γ ⊢ e′ ∶ map (pn-m.unit {n′}) τ) × Q′ , (Qg′ ∧ Qr) ⊩ Qe ) {- soundness-lemma (VarCon₁ Γv≡∀n·q⇒t) pnx sep sol = {!_ , VarN ? ? ? , ?!} -} {- soundness-lemma (App {C₁ = C₁}{C₂} Pe₁ Pe₂) pnx sep sol with prenex (C₁ ∧′ C₂) | prenex (C₂ ∧′ C₁) ... | f₁ , C₁′ , p₁ | f₂ , C₂′ , p₂ with separate C₁′ | separate C₂′ ... | r₁ , C₁′′ , p₁′ | r₂ , C₂′′ , p₂′ with soundness-lemma Pe₁ p₁ p₁′ {!!} | soundness-lemma Pe₂ p₂ p₂′ {!!} ... | Q₁ , P₁ , P₁′ | Q₂ , P₂ , P₂′ = Q₁ ∧ (Q₂ ∧ {!!}) , Appl P₁ P₂ , {!!} -} soundness-lemma {n = suc (suc .(na + nb))} {e = λ′ e′} {τ = τ} (Abs {C = Ⅎ Ⅎ (C ∧′ rest)} p) (PN-Ext (PN-Ext (PN-∧ {._}{._}{na}{nb} p₁ p₂))) (Separate (Simpl-∧ p₁s p₂s) (Implic-∧ p₁i p₂i)) (SOLVE simpl impls) with soundness-lemma {e = Exp-f.map (suc ∘ suc) e′} p p₁ (Separate {!p₁s!} {!!}) {!!} ... | Q₁ , t , e = {!!} soundness-lemma (_) pnx sep sol = {!!} {- soundness-proof : ∀ {ev}{tv}{eq : Eq tv}{Q}{Γ : Environment ev tv}{p} → Q , Γ ► p → Q , ε , Γ ⊢′ p soundness-proof (Empty) = Empty soundness-proof (Bind _ _ _ _ _) = Bind {!!} {!!} {!!} soundness-proof (BindA _ _ _ _ _) = BindA {!!} {!!} {!!} -}
{ "alphanum_fraction": 0.4647972809, "avg_line_length": 47.8953488372, "ext": "agda", "hexsha": "093fade6d7a0656c6dd2ad166011a82d8cfcd4be", "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": "fc1fc1bba2af95806d9075296f9ed1074afa4c24", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "liamoc/outside-in", "max_forks_repo_path": "OutsideIn/Proof/Soundness.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fc1fc1bba2af95806d9075296f9ed1074afa4c24", "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": "liamoc/outside-in", "max_issues_repo_path": "OutsideIn/Proof/Soundness.agda", "max_line_length": 171, "max_stars_count": 2, "max_stars_repo_head_hexsha": "fc1fc1bba2af95806d9075296f9ed1074afa4c24", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "liamoc/outside-in", "max_stars_repo_path": "OutsideIn/Proof/Soundness.agda", "max_stars_repo_stars_event_max_datetime": "2020-11-19T14:30:07.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-14T05:22:15.000Z", "num_tokens": 3408, "size": 8238 }
open import SOAS.Common open import SOAS.Families.Core -- Algebras for a signature endofunctor module SOAS.Metatheory.Algebra {T : Set} (⅀F : Functor (𝔽amiliesₛ {T}) (𝔽amiliesₛ {T})) where module ⅀ = Functor ⅀F ⅀ : Familyₛ → Familyₛ ⅀ = ⅀.₀ ⅀₁ : {𝒳 𝒴 : Familyₛ} → 𝒳 ⇾̣ 𝒴 → ⅀ 𝒳 ⇾̣ ⅀ 𝒴 ⅀₁ = Functor.₁ ⅀F
{ "alphanum_fraction": 0.6310679612, "avg_line_length": 18.1764705882, "ext": "agda", "hexsha": "43b2358713e0f3ecaa8c921343e6650a064b5d20", "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": "SOAS/Metatheory/Algebra.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": "SOAS/Metatheory/Algebra.agda", "max_line_length": 93, "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": "SOAS/Metatheory/Algebra.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": 157, "size": 309 }
-- Jesper, 2017-08-13: This test case now fails since instantiation -- of metavariables during case splitting was disabled (see #2621). {-# OPTIONS --allow-unsolved-metas #-} record ⊤ : Set where constructor tt data I : Set where i : ⊤ → I data D : I → Set where d : D (i tt) postulate P : (x : I) → D x → Set foo : (y : _) → P _ y foo d = {!!}
{ "alphanum_fraction": 0.6100278552, "avg_line_length": 17.95, "ext": "agda", "hexsha": "889299ab4a0b2da8340a01c1bd268d0e12423a37", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue1863.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "hborum/agda", "max_issues_repo_path": "test/Fail/Issue1863.agda", "max_line_length": 67, "max_stars_count": 2, "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "hborum/agda", "max_stars_repo_path": "test/Fail/Issue1863.agda", "max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z", "num_tokens": 120, "size": 359 }
{- Day 2 task of https://adventofcode.com/ -} module a2 where open import Agda.Builtin.IO using (IO) open import Agda.Builtin.Unit using (⊤) open import Agda.Builtin.String using (String; primShowNat; primStringAppend) open import Agda.Builtin.Equality open import Data.Nat open import Data.Bool using (if_then_else_) open import Data.List open import Data.Maybe renaming (map to maybeMap) postulate putStrLn : String → IO ⊤ {-# FOREIGN GHC import qualified Data.Text as T #-} {-# COMPILE GHC putStrLn = putStrLn . T.unpack #-} -- helper shopMaybeNat : Maybe ℕ → String shopMaybeNat (just n) = primShowNat n shopMaybeNat nothing = "nothing" data Command : Set where forward : ℕ → Command up : ℕ → Command down : ℕ → Command record Position : Set where constructor pos field h : ℕ d : ℕ open Position apply : Command → Position → Maybe Position apply (forward x) (pos h d) = just (pos (h + x) d) apply (up x) (pos h d) = if d <ᵇ x then nothing else just (pos h ∣ d - x ∣) apply (down x) (pos h d) = just (pos h (d + x)) iterate : List Command → Position → Maybe Position iterate [] p = just p iterate (command ∷ list) p with apply command p ... | just q = iterate list q ... | nothing = nothing doTask : List Command → Maybe ℕ doTask list = let maybeResult = iterate list (pos 0 0) in maybeMap multiplyComponents maybeResult where multiplyComponents : Position → ℕ multiplyComponents (pos h d) = h * d input : List Command input = forward 2 ∷ forward 3 ∷ forward 5 ∷ forward 6 ∷ down 7 ∷ forward 8 ∷ forward 4 ∷ forward 7 ∷ forward 5 ∷ forward 5 ∷ down 4 ∷ down 9 ∷ forward 8 ∷ forward 5 ∷ up 5 ∷ down 5 ∷ forward 3 ∷ down 4 ∷ down 8 ∷ forward 9 ∷ down 1 ∷ up 9 ∷ down 7 ∷ up 7 ∷ up 1 ∷ forward 1 ∷ down 1 ∷ down 4 ∷ down 4 ∷ down 8 ∷ down 4 ∷ up 3 ∷ down 1 ∷ down 3 ∷ forward 7 ∷ down 6 ∷ forward 3 ∷ forward 5 ∷ forward 2 ∷ up 9 ∷ forward 7 ∷ up 5 ∷ down 3 ∷ forward 1 ∷ forward 2 ∷ down 3 ∷ down 8 ∷ down 3 ∷ forward 8 ∷ up 5 ∷ down 5 ∷ forward 3 ∷ down 5 ∷ forward 9 ∷ down 3 ∷ down 4 ∷ down 9 ∷ down 7 ∷ up 3 ∷ down 9 ∷ up 9 ∷ up 1 ∷ forward 3 ∷ up 4 ∷ down 3 ∷ forward 7 ∷ forward 7 ∷ up 7 ∷ forward 6 ∷ down 7 ∷ down 6 ∷ forward 2 ∷ forward 9 ∷ down 5 ∷ forward 4 ∷ up 6 ∷ down 1 ∷ down 9 ∷ down 9 ∷ forward 4 ∷ down 1 ∷ forward 6 ∷ down 1 ∷ down 5 ∷ down 4 ∷ down 4 ∷ forward 4 ∷ forward 9 ∷ up 1 ∷ down 2 ∷ down 8 ∷ down 5 ∷ down 8 ∷ down 8 ∷ up 2 ∷ forward 8 ∷ up 1 ∷ forward 4 ∷ down 5 ∷ down 1 ∷ up 2 ∷ forward 6 ∷ forward 9 ∷ forward 2 ∷ forward 6 ∷ forward 9 ∷ up 6 ∷ forward 9 ∷ up 4 ∷ down 7 ∷ up 6 ∷ forward 2 ∷ down 1 ∷ up 3 ∷ forward 1 ∷ forward 8 ∷ down 6 ∷ down 8 ∷ down 8 ∷ forward 8 ∷ forward 2 ∷ forward 2 ∷ down 2 ∷ up 1 ∷ down 9 ∷ up 9 ∷ down 9 ∷ up 3 ∷ forward 9 ∷ up 4 ∷ up 7 ∷ up 6 ∷ down 9 ∷ forward 1 ∷ down 3 ∷ down 4 ∷ forward 8 ∷ down 3 ∷ down 9 ∷ up 3 ∷ forward 2 ∷ up 5 ∷ down 3 ∷ forward 8 ∷ up 3 ∷ down 3 ∷ forward 2 ∷ forward 9 ∷ down 1 ∷ down 9 ∷ down 4 ∷ up 7 ∷ down 4 ∷ up 6 ∷ forward 5 ∷ down 6 ∷ forward 3 ∷ down 2 ∷ forward 1 ∷ forward 8 ∷ down 4 ∷ forward 1 ∷ up 7 ∷ forward 6 ∷ up 9 ∷ forward 6 ∷ down 3 ∷ forward 2 ∷ down 4 ∷ forward 6 ∷ down 3 ∷ down 6 ∷ down 1 ∷ down 1 ∷ down 5 ∷ forward 3 ∷ forward 9 ∷ forward 8 ∷ down 3 ∷ forward 7 ∷ up 9 ∷ forward 9 ∷ up 2 ∷ forward 4 ∷ up 3 ∷ forward 1 ∷ up 6 ∷ up 8 ∷ down 5 ∷ down 6 ∷ up 9 ∷ down 6 ∷ down 9 ∷ up 9 ∷ down 4 ∷ forward 5 ∷ up 2 ∷ down 3 ∷ up 3 ∷ down 1 ∷ forward 3 ∷ down 5 ∷ forward 7 ∷ down 6 ∷ down 7 ∷ down 5 ∷ forward 2 ∷ up 6 ∷ down 9 ∷ down 4 ∷ down 3 ∷ forward 9 ∷ up 8 ∷ forward 2 ∷ down 2 ∷ forward 4 ∷ up 6 ∷ down 4 ∷ up 8 ∷ down 7 ∷ down 2 ∷ up 6 ∷ up 4 ∷ down 2 ∷ forward 5 ∷ up 4 ∷ down 8 ∷ forward 3 ∷ forward 1 ∷ down 7 ∷ forward 8 ∷ forward 7 ∷ down 7 ∷ up 4 ∷ forward 8 ∷ down 5 ∷ up 9 ∷ forward 1 ∷ forward 4 ∷ forward 9 ∷ forward 7 ∷ down 9 ∷ up 9 ∷ down 1 ∷ down 7 ∷ forward 7 ∷ down 7 ∷ down 7 ∷ down 3 ∷ down 5 ∷ forward 3 ∷ down 2 ∷ forward 6 ∷ down 9 ∷ up 5 ∷ up 3 ∷ forward 5 ∷ down 6 ∷ down 1 ∷ forward 4 ∷ down 3 ∷ forward 8 ∷ down 7 ∷ forward 7 ∷ forward 7 ∷ up 7 ∷ up 2 ∷ up 3 ∷ forward 9 ∷ down 5 ∷ up 2 ∷ forward 5 ∷ up 5 ∷ forward 2 ∷ forward 2 ∷ down 8 ∷ forward 2 ∷ up 4 ∷ forward 1 ∷ forward 3 ∷ up 8 ∷ up 9 ∷ forward 5 ∷ down 1 ∷ up 8 ∷ down 4 ∷ down 8 ∷ up 4 ∷ forward 9 ∷ down 6 ∷ down 8 ∷ up 2 ∷ up 3 ∷ down 7 ∷ down 4 ∷ forward 5 ∷ down 6 ∷ forward 3 ∷ forward 3 ∷ forward 8 ∷ down 1 ∷ down 7 ∷ down 9 ∷ down 2 ∷ down 7 ∷ forward 7 ∷ down 7 ∷ down 6 ∷ up 6 ∷ forward 8 ∷ forward 5 ∷ up 5 ∷ down 2 ∷ up 8 ∷ up 4 ∷ down 9 ∷ up 2 ∷ forward 5 ∷ up 2 ∷ down 4 ∷ up 4 ∷ forward 2 ∷ forward 4 ∷ forward 9 ∷ forward 9 ∷ up 4 ∷ up 5 ∷ down 1 ∷ down 6 ∷ down 1 ∷ down 4 ∷ down 5 ∷ down 3 ∷ forward 3 ∷ down 9 ∷ forward 6 ∷ down 3 ∷ down 9 ∷ down 2 ∷ up 2 ∷ down 2 ∷ down 7 ∷ forward 9 ∷ down 3 ∷ down 3 ∷ down 2 ∷ down 3 ∷ forward 2 ∷ down 9 ∷ down 9 ∷ up 5 ∷ up 3 ∷ forward 4 ∷ up 7 ∷ forward 8 ∷ up 6 ∷ forward 7 ∷ down 7 ∷ down 1 ∷ forward 5 ∷ down 2 ∷ up 1 ∷ down 8 ∷ up 3 ∷ forward 2 ∷ up 9 ∷ down 1 ∷ down 3 ∷ down 6 ∷ down 2 ∷ down 7 ∷ up 2 ∷ forward 5 ∷ forward 7 ∷ down 2 ∷ forward 5 ∷ forward 4 ∷ forward 5 ∷ down 3 ∷ forward 7 ∷ down 7 ∷ forward 8 ∷ down 3 ∷ down 2 ∷ up 1 ∷ forward 6 ∷ down 4 ∷ down 2 ∷ forward 7 ∷ up 3 ∷ down 4 ∷ forward 2 ∷ up 6 ∷ down 3 ∷ up 6 ∷ up 8 ∷ down 9 ∷ up 6 ∷ forward 8 ∷ forward 9 ∷ forward 4 ∷ forward 7 ∷ down 2 ∷ forward 9 ∷ down 7 ∷ up 9 ∷ down 5 ∷ down 6 ∷ up 5 ∷ down 4 ∷ forward 8 ∷ forward 4 ∷ forward 4 ∷ down 6 ∷ forward 3 ∷ forward 6 ∷ down 9 ∷ down 9 ∷ up 2 ∷ forward 7 ∷ down 8 ∷ down 9 ∷ down 9 ∷ forward 7 ∷ forward 3 ∷ down 7 ∷ down 8 ∷ forward 8 ∷ down 6 ∷ down 5 ∷ down 9 ∷ down 3 ∷ forward 1 ∷ down 5 ∷ forward 2 ∷ forward 8 ∷ down 2 ∷ forward 6 ∷ forward 3 ∷ down 7 ∷ down 4 ∷ forward 8 ∷ forward 1 ∷ down 6 ∷ forward 9 ∷ forward 6 ∷ up 1 ∷ up 3 ∷ down 8 ∷ forward 1 ∷ up 5 ∷ down 4 ∷ forward 7 ∷ up 3 ∷ down 2 ∷ forward 1 ∷ forward 9 ∷ down 9 ∷ down 7 ∷ forward 8 ∷ down 4 ∷ up 3 ∷ down 4 ∷ forward 2 ∷ forward 6 ∷ down 7 ∷ forward 6 ∷ down 6 ∷ down 4 ∷ down 1 ∷ up 9 ∷ down 4 ∷ down 7 ∷ up 4 ∷ down 9 ∷ forward 6 ∷ down 3 ∷ forward 2 ∷ down 4 ∷ forward 3 ∷ down 5 ∷ up 9 ∷ forward 8 ∷ up 7 ∷ up 6 ∷ up 4 ∷ forward 1 ∷ down 1 ∷ forward 4 ∷ up 6 ∷ forward 5 ∷ forward 4 ∷ forward 5 ∷ up 6 ∷ down 1 ∷ forward 3 ∷ up 7 ∷ down 9 ∷ up 9 ∷ down 5 ∷ forward 6 ∷ forward 4 ∷ up 1 ∷ down 4 ∷ up 1 ∷ forward 3 ∷ forward 1 ∷ down 3 ∷ forward 7 ∷ down 2 ∷ forward 3 ∷ up 2 ∷ forward 8 ∷ down 3 ∷ up 9 ∷ down 5 ∷ forward 6 ∷ down 1 ∷ down 8 ∷ down 5 ∷ forward 1 ∷ down 6 ∷ up 2 ∷ forward 6 ∷ down 2 ∷ down 1 ∷ up 6 ∷ up 7 ∷ down 5 ∷ forward 7 ∷ forward 6 ∷ forward 6 ∷ down 7 ∷ forward 4 ∷ down 5 ∷ up 5 ∷ down 1 ∷ up 8 ∷ down 8 ∷ down 2 ∷ down 2 ∷ down 9 ∷ up 9 ∷ forward 2 ∷ forward 7 ∷ down 7 ∷ down 4 ∷ down 4 ∷ down 8 ∷ forward 5 ∷ forward 2 ∷ up 9 ∷ down 9 ∷ forward 7 ∷ up 9 ∷ down 2 ∷ down 7 ∷ up 2 ∷ up 8 ∷ forward 8 ∷ down 4 ∷ forward 3 ∷ forward 4 ∷ forward 6 ∷ forward 2 ∷ down 1 ∷ down 2 ∷ forward 2 ∷ up 1 ∷ down 1 ∷ forward 5 ∷ up 3 ∷ up 3 ∷ down 3 ∷ down 1 ∷ down 4 ∷ up 5 ∷ up 6 ∷ forward 5 ∷ up 7 ∷ forward 6 ∷ down 4 ∷ down 7 ∷ up 8 ∷ forward 1 ∷ down 5 ∷ up 4 ∷ up 3 ∷ up 5 ∷ down 1 ∷ up 5 ∷ forward 3 ∷ up 5 ∷ forward 2 ∷ forward 2 ∷ forward 5 ∷ forward 2 ∷ up 9 ∷ forward 4 ∷ down 1 ∷ down 3 ∷ down 5 ∷ up 2 ∷ down 8 ∷ forward 8 ∷ forward 9 ∷ down 1 ∷ down 3 ∷ forward 8 ∷ forward 2 ∷ down 2 ∷ down 1 ∷ up 7 ∷ forward 2 ∷ forward 8 ∷ down 9 ∷ forward 1 ∷ forward 4 ∷ down 7 ∷ down 4 ∷ up 7 ∷ down 3 ∷ down 1 ∷ down 4 ∷ up 7 ∷ down 6 ∷ forward 7 ∷ down 8 ∷ up 2 ∷ up 4 ∷ up 6 ∷ down 9 ∷ down 9 ∷ down 8 ∷ forward 6 ∷ up 3 ∷ up 1 ∷ forward 9 ∷ forward 6 ∷ up 4 ∷ up 2 ∷ up 7 ∷ forward 5 ∷ up 9 ∷ up 9 ∷ forward 9 ∷ up 6 ∷ down 1 ∷ down 3 ∷ forward 3 ∷ down 2 ∷ down 2 ∷ down 6 ∷ down 9 ∷ forward 3 ∷ forward 7 ∷ up 3 ∷ forward 3 ∷ down 5 ∷ forward 9 ∷ up 6 ∷ down 2 ∷ forward 8 ∷ down 3 ∷ up 5 ∷ down 6 ∷ forward 9 ∷ down 5 ∷ down 2 ∷ down 6 ∷ forward 8 ∷ forward 6 ∷ down 1 ∷ forward 6 ∷ up 1 ∷ up 7 ∷ down 4 ∷ down 7 ∷ forward 4 ∷ forward 7 ∷ down 4 ∷ forward 8 ∷ down 8 ∷ down 7 ∷ forward 9 ∷ down 1 ∷ down 3 ∷ down 6 ∷ forward 7 ∷ forward 6 ∷ forward 3 ∷ forward 8 ∷ down 5 ∷ down 3 ∷ up 1 ∷ down 9 ∷ down 8 ∷ forward 3 ∷ down 6 ∷ down 1 ∷ forward 5 ∷ forward 5 ∷ forward 9 ∷ up 5 ∷ down 6 ∷ up 9 ∷ down 7 ∷ down 6 ∷ up 1 ∷ forward 5 ∷ forward 7 ∷ forward 8 ∷ forward 7 ∷ forward 6 ∷ forward 3 ∷ forward 1 ∷ forward 2 ∷ up 4 ∷ forward 3 ∷ forward 4 ∷ forward 5 ∷ up 2 ∷ up 3 ∷ forward 4 ∷ down 9 ∷ up 4 ∷ forward 7 ∷ down 6 ∷ down 6 ∷ down 1 ∷ forward 2 ∷ down 2 ∷ forward 2 ∷ down 3 ∷ forward 7 ∷ forward 8 ∷ down 4 ∷ up 7 ∷ forward 7 ∷ down 7 ∷ forward 7 ∷ forward 9 ∷ down 7 ∷ up 2 ∷ down 3 ∷ forward 7 ∷ down 1 ∷ forward 8 ∷ forward 2 ∷ up 9 ∷ down 3 ∷ forward 2 ∷ up 4 ∷ forward 9 ∷ down 4 ∷ down 4 ∷ forward 4 ∷ down 2 ∷ down 9 ∷ forward 4 ∷ down 2 ∷ down 6 ∷ forward 9 ∷ forward 2 ∷ up 1 ∷ forward 2 ∷ forward 3 ∷ down 5 ∷ up 8 ∷ down 4 ∷ down 4 ∷ forward 7 ∷ down 2 ∷ up 6 ∷ down 9 ∷ forward 9 ∷ up 1 ∷ forward 3 ∷ down 5 ∷ forward 3 ∷ down 3 ∷ forward 4 ∷ up 3 ∷ down 6 ∷ down 7 ∷ down 4 ∷ down 8 ∷ down 4 ∷ down 5 ∷ up 9 ∷ up 1 ∷ down 7 ∷ up 3 ∷ up 3 ∷ down 3 ∷ up 4 ∷ up 6 ∷ forward 8 ∷ down 1 ∷ forward 7 ∷ forward 4 ∷ down 9 ∷ down 1 ∷ forward 7 ∷ forward 9 ∷ forward 1 ∷ down 3 ∷ down 2 ∷ forward 3 ∷ forward 2 ∷ down 7 ∷ forward 9 ∷ forward 6 ∷ up 9 ∷ down 2 ∷ forward 9 ∷ up 6 ∷ forward 8 ∷ up 1 ∷ down 5 ∷ down 8 ∷ forward 1 ∷ down 1 ∷ forward 9 ∷ up 1 ∷ forward 9 ∷ forward 1 ∷ forward 1 ∷ down 7 ∷ forward 3 ∷ forward 6 ∷ down 5 ∷ forward 7 ∷ forward 1 ∷ down 7 ∷ down 6 ∷ down 6 ∷ forward 5 ∷ up 6 ∷ down 6 ∷ forward 8 ∷ up 2 ∷ down 8 ∷ down 3 ∷ up 5 ∷ up 8 ∷ down 6 ∷ forward 4 ∷ forward 2 ∷ up 3 ∷ forward 5 ∷ forward 3 ∷ up 8 ∷ forward 6 ∷ up 8 ∷ forward 1 ∷ up 8 ∷ up 7 ∷ up 6 ∷ forward 2 ∷ down 9 ∷ down 9 ∷ forward 3 ∷ down 7 ∷ forward 3 ∷ down 6 ∷ forward 9 ∷ up 5 ∷ down 1 ∷ forward 7 ∷ down 1 ∷ down 5 ∷ down 9 ∷ forward 8 ∷ forward 9 ∷ forward 7 ∷ down 9 ∷ up 4 ∷ forward 5 ∷ down 5 ∷ forward 5 ∷ down 9 ∷ forward 9 ∷ forward 3 ∷ up 5 ∷ forward 8 ∷ up 5 ∷ down 1 ∷ forward 8 ∷ down 3 ∷ forward 6 ∷ up 9 ∷ forward 8 ∷ down 4 ∷ forward 3 ∷ down 5 ∷ forward 8 ∷ forward 9 ∷ forward 2 ∷ down 1 ∷ down 6 ∷ down 4 ∷ forward 9 ∷ up 2 ∷ down 3 ∷ down 6 ∷ down 3 ∷ down 9 ∷ down 1 ∷ up 6 ∷ down 2 ∷ down 7 ∷ up 5 ∷ forward 5 ∷ up 1 ∷ down 7 ∷ forward 6 ∷ up 6 ∷ down 2 ∷ down 3 ∷ forward 3 ∷ down 5 ∷ forward 8 ∷ down 9 ∷ down 7 ∷ down 8 ∷ up 7 ∷ down 1 ∷ forward 1 ∷ forward 1 ∷ down 2 ∷ up 4 ∷ forward 2 ∷ down 3 ∷ up 2 ∷ down 3 ∷ down 2 ∷ forward 7 ∷ down 1 ∷ up 7 ∷ down 2 ∷ down 1 ∷ forward 6 ∷ down 9 ∷ up 9 ∷ down 4 ∷ down 6 ∷ up 9 ∷ forward 7 ∷ forward 9 ∷ forward 7 ∷ down 4 ∷ down 1 ∷ forward 7 ∷ down 4 ∷ down 7 ∷ down 3 ∷ down 5 ∷ forward 3 ∷ down 8 ∷ forward 8 ∷ forward 7 ∷ forward 8 ∷ down 4 ∷ down 9 ∷ forward 2 ∷ forward 7 ∷ up 8 ∷ forward 4 ∷ down 6 ∷ up 8 ∷ down 2 ∷ forward 3 ∷ down 6 ∷ down 8 ∷ forward 8 ∷ forward 2 ∷ forward 9 ∷ up 6 ∷ forward 7 ∷ down 3 ∷ down 5 ∷ forward 8 ∷ forward 9 ∷ down 3 ∷ forward 3 ∷ forward 2 ∷ forward 3 ∷ down 8 ∷ up 9 ∷ up 5 ∷ up 2 ∷ up 6 ∷ up 1 ∷ up 1 ∷ up 5 ∷ forward 3 ∷ forward 2 ∷ down 3 ∷ forward 4 ∷ [] main : IO ⊤ main = putStrLn (shopMaybeNat (doTask input)) private -- checks from the exercise text _ : apply (forward 5) (pos 0 0) ≡ just (pos 5 0) _ = refl _ : apply (down 5) (pos 5 0) ≡ just (pos 5 5) _ = refl _ : apply (forward 8) (pos 5 5) ≡ just (pos 13 5) _ = refl _ : apply (up 3) (pos 13 5) ≡ just (pos 13 2) _ = refl _ : apply (down 8) (pos 13 2) ≡ just (pos 13 10) _ = refl _ : apply (forward 2) (pos 13 10) ≡ just (pos 15 10) _ = refl -- submarine does not 'fly' _ : apply (up 7) (pos 13 2) ≡ nothing _ = refl
{ "alphanum_fraction": 0.5060293162, "avg_line_length": 12.6822344322, "ext": "agda", "hexsha": "d21e839a97e9cafdbbd3ec44f6c16ac395904304", "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": "834bc9e291a76bdbcd58cbff9805161f1b1cfe71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "felixwellen/adventOfCode", "max_forks_repo_path": "a2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "834bc9e291a76bdbcd58cbff9805161f1b1cfe71", "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": "felixwellen/adventOfCode", "max_issues_repo_path": "a2.agda", "max_line_length": 77, "max_stars_count": null, "max_stars_repo_head_hexsha": "834bc9e291a76bdbcd58cbff9805161f1b1cfe71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "felixwellen/adventOfCode", "max_stars_repo_path": "a2.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 7676, "size": 13849 }
{-# OPTIONS --prop #-} module Miscellaneous.ClassicalWitness where open import Agda.Primitive using (Prop) open import Data open import Data.Either open import Functional import Lvl open import Type.Dependent open import Type private variable ℓ ℓ₁ ℓ₂ : Lvl.Level private variable T A B Obj : Type{ℓ} private variable P Q R : Prop(ℓ) private variable Pred : T → Prop(ℓ) private variable x y z : T empty-prop : Empty{ℓ} → P empty-prop () data Proof(P : Prop(ℓ)) : Type{ℓ} where intro : P → Proof(P) data ⊥ : Prop(Lvl.𝟎) where [⊥]-elim : ⊥ → P [⊥]-elim () [⊥]-elim-type : ⊥ → T [⊥]-elim-type () ¬_ : Prop(ℓ) → Prop(ℓ) ¬ P = P → ⊥ data _∧_ (P : Prop(ℓ₁)) (Q : Prop(ℓ₂)) : Prop(ℓ₁ Lvl.⊔ ℓ₂) where [∧]-intro : P → Q → (P ∧ Q) data _∨_ (P : Prop(ℓ₁)) (Q : Prop(ℓ₂)) : Prop(ℓ₁ Lvl.⊔ ℓ₂) where [∨]-introₗ : P → (P ∨ Q) [∨]-introᵣ : Q → (P ∨ Q) [∨]-elim : (P → R) → (Q → R) → (P ∨ Q) → R [∨]-elim pr qr ([∨]-introₗ p) = pr p [∨]-elim pr qr ([∨]-introᵣ q) = qr q data ∃ {Obj : Type{ℓ₁}} (P : Obj → Prop(ℓ₂)) : Prop(ℓ₁ Lvl.⊔ ℓ₂) where [∃]-intro : (witness : Obj) → ⦃ proof : P(witness) ⦄ → ∃(P) [∃]-elim : (∀{x} → Pred(x) → P) → (∃ Pred) → P [∃]-elim pr ([∃]-intro _ ⦃ p ⦄) = pr p ∃-empty-type : (∀{x : Obj} → Pred(x) → Empty{ℓ}) → ¬(∃{Obj = Obj} Pred) ∃-empty-type empty-p ep = [∃]-elim (\px → empty-prop (empty-p px)) ep data Inhabited(T : Type{ℓ}) : Prop(Lvl.𝐒(ℓ)) where intro : T → Inhabited(T) Inhabited-elim : (T → P) → (Inhabited(T) → P) Inhabited-elim f (intro obj) = f(obj) Inhabited-empty-type : (T → Empty{ℓ}) → (¬ Inhabited(T)) Inhabited-empty-type empty-T inhab-T = Inhabited-elim (\t → empty-prop(empty-T t)) inhab-T ∃-to-Inhabited : (∃{Obj = Obj} Pred) → Inhabited(Obj) ∃-to-Inhabited = [∃]-elim (\{x} _ → intro x) data _≡_ {T : Type{ℓ}} : T → T → Prop(Lvl.of(T)) where refl : ∀{x} → (x ≡ x) sym : ∀{x y : T} → (x ≡ y) → (y ≡ x) sym refl = refl subst : (P : T → Prop(ℓ)) → ∀{x y : T} → (x ≡ y) → (P(x) → P(y)) subst P refl = (\x → x) data Singleton(T : Type{ℓ}) : Prop(Lvl.𝐒(ℓ)) where intro : (x : T) → (∀{y} → (x ≡ y)) → Singleton(T) data ∃! {Obj : Type{ℓ₁}} (P : Obj → Prop(ℓ₂)) : Prop(ℓ₁ Lvl.⊔ ℓ₂) where [∃!]-intro : (witness : Obj) → ⦃ proof : P(witness) ⦄ → (∀{x} → P(x) → (witness ≡ x)) → ∃!(P) [∃!]-elim : (∀{x} → Pred(x) → (∀{y} → (Pred(y)) → (x ≡ y)) → P) → (∃! Pred) → P [∃!]-elim pr ([∃!]-intro _ ⦃ p ⦄ eq) = pr p eq ∃!-to-∃ : (∃!{Obj = Obj} Pred) → (∃{Obj = Obj} Pred) ∃!-to-∃ = [∃!]-elim (\{x} p _ → [∃]-intro x ⦃ p ⦄) ∃!-empty-type : (∀{x : Obj} → Pred(x) → Empty{ℓ}) → ¬(∃!{Obj = Obj} Pred) ∃!-empty-type empty-p ep = [∃!]-elim (\px → empty-prop (empty-p px)) ep module WhenExcludedMiddle (excluded-middle : ∀{ℓ}(P : Prop(ℓ)) → (P ∨ (¬ P))) where {-[¬¬]-elim-type : ((T → ⊥) → ⊥) → T [¬¬]-elim-type {T = T} nnt with excluded-middle(T) ... | p = ?-} {- decidable : ∀{ℓ ℓₑ}(T : Type{ℓ}) → (T ‖ (T → Empty{ℓₑ})) decidable(T) = {!excluded-middle!} -} {- singleton-witness : Singleton(T) → T singleton-witness x = {!!} -} module WhenDNEType ([¬¬]-elim-type : ∀{ℓ}{T : Type{ℓ}} → ((T → ⊥) → ⊥) → T) where inhabited-witness : Inhabited(T) → T inhabited-witness p = [¬¬]-elim-type (\nt → Inhabited-elim nt p) module WhenDecidable {ℓₑ} (decidable : ∀{ℓ}(T : Type{ℓ}) → (T ‖ (T → Empty{ℓₑ}))) where excluded-middle : ∀{ℓ}(P : Prop(ℓ)) → (P ∨ (¬ P)) excluded-middle(P) with decidable(Proof P) ... | Left (intro p) = [∨]-introₗ p ... | Right np = [∨]-introᵣ (\p → empty-prop(np(intro p))) inhabited-witness : Inhabited(T) → T -- TODO: Are there any other ways (with weaker assumptions) of doing this? inhabited-witness{T = T} x with decidable(T) ... | Left t = t ... | Right nt = [⊥]-elim-type (Inhabited-empty-type nt x) ∃-to-Σ : (∃{Obj = Obj} Pred) → (Σ Obj (\p → Proof(Pred p))) ∃-to-Σ {Obj = Obj}{Pred = Pred} ep with decidable(Σ Obj (\p → Proof(Pred p))) ... | Left s = s ... | Right ns = [⊥]-elim-type (∃-empty-type (\{x} px → ns (intro x (intro px))) ep) [∃]-witness : (∃{Obj = Obj} Pred) → Obj [∃]-witness {Obj = Obj}{Pred = Pred} ep = Σ.left (∃-to-Σ ep) -- inhabited-witness(∃-to-Inhabited(∃!-to-∃ ep)) [∃]-proof : (ep : ∃{Obj = Obj} Pred) → Pred([∃]-witness ep) [∃]-proof {Obj = Obj}{Pred = Pred} ep with intro p ← Σ.right (∃-to-Σ ep) = p -- [∃!]-elim (\p eq → subst(Pred) {!eq p!} p) ep module WhenInhabitedWitness (inhabited-witness : ∀{ℓ}{T : Type{ℓ}} → Inhabited(T) → T) where [∨]-elim-type : (P → T) → (Q → T) → (P ∨ Q) → T [∨]-elim-type pt qt pq = inhabited-witness([∨]-elim (\t → intro(pt t)) (\t → intro(qt t)) pq) {- [∃]-witness : ∀{P : T → Prop(ℓ)} → (∃ P) → T -- TODO: Not really the witness. See TODO in [∃]-proof below [∃]-witness ep = inhabited-witness(∃-to-Inhabited ep) [∃]-proof : ∀{P : T → Prop(ℓ)} → (ep : ∃ P) → P([∃]-witness ep) -- TODO: Will not work because the witness obtained from `inhabited-witness` (this one is from `decidable`) can obviously be different from the one provided to prove (∃ P) (this one is from `[∃]-intro`). Though, a correct witness _is_ obtainable from (∃! P) as usual in classical logic. [∃]-proof{T = T} ep with decidable(T) ... | Left t = {!!} ... | Right nt = {!!} -}
{ "alphanum_fraction": 0.5393799345, "avg_line_length": 34.8523489933, "ext": "agda", "hexsha": "25bc3a99b4b5c491d092942be417691c7e3eec19", "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": "Miscellaneous/ClassicalWitness.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": "Miscellaneous/ClassicalWitness.agda", "max_line_length": 352, "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": "Miscellaneous/ClassicalWitness.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": 2255, "size": 5193 }
{-# OPTIONS --warning=error --safe --without-K #-} open import Orders.Total.Definition open import LogicalFormulae open import Maybe module KeyValue.LinearStore.Definition {a b : _} (keySet : Set a) (valueSet : Set b) {c : _} (keyOrder : TotalOrder keySet {c}) where open import KeyValue.KeyValue keySet valueSet open import KeyValue.LinearStore.Implementation keySet valueSet keyOrder LinearStore : KeyValue Map KeyValue.tryFind LinearStore = lookup KeyValue.add LinearStore = addMap KeyValue.empty LinearStore = empty KeyValue.count LinearStore = count KeyValue.lookupAfterAdd LinearStore empty k v with TotalOrder.totality keyOrder k k KeyValue.lookupAfterAdd LinearStore empty k v | inl (inl x) = exFalso (TotalOrder.irreflexive keyOrder x) KeyValue.lookupAfterAdd LinearStore empty k v | inl (inr x) = exFalso (TotalOrder.irreflexive keyOrder x) KeyValue.lookupAfterAdd LinearStore empty k v | inr x = refl KeyValue.lookupAfterAdd LinearStore (nonempty x) k v = lookupReducedSucceedsAfterAdd k v x KeyValue.lookupAfterAdd' LinearStore empty k1 v k2 with TotalOrder.totality keyOrder k1 k2 KeyValue.lookupAfterAdd' LinearStore empty k1 v k2 | inl (inl x) = inr refl KeyValue.lookupAfterAdd' LinearStore empty k1 v k2 | inl (inr x) = inr refl KeyValue.lookupAfterAdd' LinearStore empty k1 v k2 | inr x = inl x KeyValue.lookupAfterAdd' LinearStore (nonempty x) k1 v k2 with TotalOrder.totality keyOrder k1 k2 KeyValue.lookupAfterAdd' LinearStore (nonempty map) k1 v k2 | inl (inl x) with inspect (lookupReduced map k2) KeyValue.lookupAfterAdd' LinearStore (nonempty map) k1 v k2 | inl (inl x) | no with≡ pr rewrite pr = inr (lookupReducedFailsAfterUnrelatedAdd k1 v k2 (inl x) map pr) KeyValue.lookupAfterAdd' LinearStore (nonempty map) k1 v k2 | inl (inl x) | (yes lookedUp) with≡ pr rewrite pr = inr (lookupReducedSucceedsAfterUnrelatedAdd k1 v k2 lookedUp (inl x) map pr) KeyValue.lookupAfterAdd' LinearStore (nonempty map) k1 v k2 | inl (inr x) with inspect (lookupReduced map k2) KeyValue.lookupAfterAdd' LinearStore (nonempty map) k1 v k2 | inl (inr x) | no with≡ pr rewrite pr = inr (lookupReducedFailsAfterUnrelatedAdd k1 v k2 (inr x) map pr) KeyValue.lookupAfterAdd' LinearStore (nonempty map) k1 v k2 | inl (inr x) | yes lookedUp with≡ pr rewrite pr = inr (lookupReducedSucceedsAfterUnrelatedAdd k1 v k2 lookedUp (inr x) map pr) KeyValue.lookupAfterAdd' LinearStore (nonempty map) k1 v k2 | inr x = inl x KeyValue.countAfterAdd' LinearStore empty _ _ _ = refl KeyValue.countAfterAdd' LinearStore (nonempty x) k v = countReducedBehavesWhenAddingNotPresent k v x KeyValue.countAfterAdd LinearStore empty _ _ _ () KeyValue.countAfterAdd LinearStore (nonempty map) k v1 v2 = countReducedBehavesWhenAddingPresent k v1 v2 map
{ "alphanum_fraction": 0.7872807018, "avg_line_length": 72, "ext": "agda", "hexsha": "6b6c43f569311342e570d8bd46608c11b778dac6", "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": "KeyValue/LinearStore/Definition.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "KeyValue/LinearStore/Definition.agda", "max_line_length": 189, "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": "KeyValue/LinearStore/Definition.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z", "num_tokens": 815, "size": 2736 }
{-# OPTIONS --without-K --safe #-} module Algebra.Linear.Construct where import Algebra.Linear.Construct.Vector import Algebra.Linear.Construct.Matrix
{ "alphanum_fraction": 0.7843137255, "avg_line_length": 21.8571428571, "ext": "agda", "hexsha": "907ed8a26ab62c5012deab6f6a3a270431a862a2", "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": "d87c5a1eb5dd0569238272e67bce1899616b789a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "felko/linear-algebra", "max_forks_repo_path": "src/Algebra/Linear/Construct.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a", "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": "felko/linear-algebra", "max_issues_repo_path": "src/Algebra/Linear/Construct.agda", "max_line_length": 38, "max_stars_count": 15, "max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "felko/linear-algebra", "max_stars_repo_path": "src/Algebra/Linear/Construct.agda", "max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z", "num_tokens": 29, "size": 153 }
{-# OPTIONS --without-K #-} open import HoTT open import homotopy.HSpace module homotopy.CircleHSpace where S¹-hSpace : HSpaceStructure S¹ S¹-hSpace = hSpaceStructure base μ μ-e-l μ-e-r μ-coh where turn-around : (x : S¹) → x == x turn-around = S¹-elim loop (↓-idf=idf-in (∙=∙' loop loop)) module Mu = S¹Rec (idf S¹) (λ= turn-around) μ : S¹ → S¹ → S¹ μ = Mu.f μ-e-l : (x : S¹) → μ base x == x μ-e-l x = idp μ-e-r : (x : S¹) → μ x base == x μ-e-r = S¹-elim idp (↓-app=idf-in (idp ∙' loop =⟨ ∙'-unit-l loop ⟩ loop =⟨ idp ⟩ turn-around base =⟨ ! (app=-β turn-around base) ⟩ ap (λ z → z base) (λ= turn-around) =⟨ ! (Mu.loop-β |in-ctx (ap (λ z → z base))) ⟩ ap (λ z → z base) (ap μ loop) =⟨ ! (ap-∘ (λ z → z base) μ loop) ⟩ ap (λ z → μ z base) loop =⟨ ! (∙-unit-r _) ⟩ ap (λ z → μ z base) loop ∙ idp ∎)) μ-coh = idp
{ "alphanum_fraction": 0.4799176107, "avg_line_length": 29.4242424242, "ext": "agda", "hexsha": "f5060097312d68a1d8e36265ed3bbfab98bba26c", "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": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_path": "theorems/homotopy/CircleHSpace.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "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": "cmknapp/HoTT-Agda", "max_issues_repo_path": "theorems/homotopy/CircleHSpace.agda", "max_line_length": 88, "max_stars_count": null, "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_path": "theorems/homotopy/CircleHSpace.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 381, "size": 971 }
open import Agda.Builtin.Nat -- splitting on a 'with' argument should not expand the ellipsis foo : Nat → Nat foo m with 0 ... | n = {!n!} -- splitting on variable hidden by ellipsis should expand the ellipsis bar : Nat → Nat bar m with 0 ... | n = {!m!} -- test case with nested with baz : Nat → Nat baz m with m ... | n with n ... | p = {!p!}
{ "alphanum_fraction": 0.6303724928, "avg_line_length": 18.3684210526, "ext": "agda", "hexsha": "c5bbd51599da7b39add0b090611ab0144138b759", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/interaction/Issue2589.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/interaction/Issue2589.agda", "max_line_length": 70, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/interaction/Issue2589.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": 111, "size": 349 }
-- Andreas, 2017-11-01, issue #2824 -- Don't allow built-ins defined in parametrized modules module _ {a} {A : Set a} where data _≡_ (x : A) : A → Set a where refl : x ≡ x {-# BUILTIN EQUALITY _≡_ #-} -- This is forbidden, could maybe allowed using lambda-lifting.
{ "alphanum_fraction": 0.642599278, "avg_line_length": 23.0833333333, "ext": "agda", "hexsha": "dba4f7db3d70087ba2f28125afdc9c7e10d60f53", "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/Issue2824EqualityParametrized.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/Issue2824EqualityParametrized.agda", "max_line_length": 63, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue2824EqualityParametrized.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": 93, "size": 277 }
import Common import Global import Local import Projection import Soundness import Completeness import Example
{ "alphanum_fraction": 0.8584070796, "avg_line_length": 11.3, "ext": "agda", "hexsha": "0e76dd38ddd72aaf0d0117659386c518084820db", "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": "3d12eed9d340207d242d70f43c6b34e01d3620de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "fangyi-zhou/mpst-in-agda", "max_forks_repo_path": "Everything.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "3d12eed9d340207d242d70f43c6b34e01d3620de", "max_issues_repo_issues_event_max_datetime": "2021-11-24T11:30:17.000Z", "max_issues_repo_issues_event_min_datetime": "2021-08-31T10:15:38.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "fangyi-zhou/mpst-in-agda", "max_issues_repo_path": "Everything.agda", "max_line_length": 19, "max_stars_count": 1, "max_stars_repo_head_hexsha": "3d12eed9d340207d242d70f43c6b34e01d3620de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "fangyi-zhou/mpst-in-agda", "max_stars_repo_path": "Everything.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-14T17:36:53.000Z", "max_stars_repo_stars_event_min_datetime": "2021-08-14T17:36:53.000Z", "num_tokens": 23, "size": 113 }
{-# OPTIONS --show-implicit #-} open import Agda.Builtin.Nat renaming (Nat to ℕ) open import Agda.Builtin.Equality postulate funext : {X : Set} {Y : X → Set} {f g : (x : X) → Y x} → (∀ x → f x ≡ g x) → f ≡ g _::_ : {X : ℕ → Set} → X 0 → ((n : ℕ) → X (suc n)) → ((n : ℕ) → X n) (x :: α) 0 = x (x :: α) (suc n) = α n hd : {X : ℕ → Set} → ((n : ℕ) → X n) → X 0 hd α = α 0 tl : {X : ℕ → Set} → ((n : ℕ) → X n) → ((n : ℕ) → X (suc n)) tl α n = α(suc n) -- Needed to add the implicit arguments for funext in Agda 2.5.2: hd-tl-eta : (X : ℕ → Set) {α : (n : ℕ) → X n} → (hd α :: tl α) ≡ α hd-tl-eta X {α} = funext {Y = _} lemma where lemma : ∀ {α} → ∀ i → _::_ {_} (hd α) (tl α) i ≡ α i lemma 0 = refl lemma (suc i) = refl
{ "alphanum_fraction": 0.4684931507, "avg_line_length": 28.0769230769, "ext": "agda", "hexsha": "3904f5ce86bb956ba9ff41aeddeca02e73c174df", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "alhassy/agda", "max_forks_repo_path": "test/Succeed/Issue2384.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "alhassy/agda", "max_issues_repo_path": "test/Succeed/Issue2384.agda", "max_line_length": 84, "max_stars_count": 3, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "test/Succeed/Issue2384.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": 335, "size": 730 }
module Haskell.RangedSets.Ranges where open import Haskell.Prim open import Haskell.Prim.Ord open import Haskell.Prim.Bool open import Haskell.Prim.Maybe open import Haskell.Prim.Enum open import Haskell.Prim.Num open import Haskell.Prim.Eq open import Haskell.Prim.Functor open import Haskell.Prim.Foldable open import Haskell.Prim.Monoid open import Haskell.Prim.Monad open import Haskell.Prim.Applicative open import Haskell.Prim.Int open import Haskell.Prim.List open import Haskell.Prim.Integer open import Haskell.Prim.Real open import Haskell.Prim.Show open import Haskell.Prim.String open import Haskell.Prim.Tuple open import Haskell.RangedSets.Boundaries {-# FOREIGN AGDA2HS import Haskell.RangedSets.Boundaries #-} data Range (a : Set) ⦃ o : Ord a ⦄ ⦃ dio : DiscreteOrdered a ⦄ : Set where Rg : Boundary a → Boundary a → Range a {-# COMPILE AGDA2HS Range #-} rangeLower : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Boundary a rangeUpper : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Boundary a rangeIsEmpty : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Bool emptyRange : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a rangeHas : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → a → Bool rangeListHas : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → List (Range a) → a → Bool fullRange : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a singletonRange : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → a → Range a rangeIsFull : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Bool rangeOverlap : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Range a → Bool rangeEncloses : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Range a → Bool rangeUnion : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Range a → List (Range a) rangeIntersection : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Range a → Range a rangeDifference : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Range a → List (Range a) rangeSingletonValue : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Maybe a instance isRangeEq : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Eq (Range a) isRangeEq . _==_ r1 r2 = (rangeIsEmpty r1 && rangeIsEmpty r2) || (rangeLower r1 == rangeLower r2 && rangeUpper r1 == rangeUpper r2) {-# COMPILE AGDA2HS isRangeEq #-} instance isRangeOrd : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Ord (Range a) isRangeOrd . compare r1 r2 = if_then_else_ (r1 == r2) EQ (if_then_else_ (rangeIsEmpty r1) LT (if_then_else_ (rangeIsEmpty r2) GT (compare (rangeLower r1) (rangeUpper r1) <> compare (rangeLower r2) (rangeUpper r2)))) isRangeOrd ._<_ x y = compare x y == LT isRangeOrd ._>_ x y = compare x y == GT isRangeOrd ._<=_ x y = (compare x y == LT) || (compare x y == EQ) isRangeOrd ._>=_ x y = (compare x y == GT) || (compare x y == EQ) isRangeOrd .max x y = if (compare x y == GT) then x else y isRangeOrd .min x y = if (compare x y == LT) then x else y {-# COMPILE AGDA2HS isRangeOrd #-} h : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → ⦃ Show a ⦄ → Boundary a → String h BoundaryBelowAll = "" h (BoundaryBelow x) = show x ++ " <= " h (BoundaryAbove x) = show x ++ " < " h BoundaryAboveAll = "show Range: lower bound is BoundaryAboveAll" {-# COMPILE AGDA2HS h #-} h2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → ⦃ Show a ⦄ → Boundary a → String h2 BoundaryBelowAll = "show Range: upper bound is BoundaryBelowAll" h2 (BoundaryBelow x) = " < " ++ show x h2 (BoundaryAbove x) = " <= " ++ show x h2 BoundaryAboveAll = "" {-# COMPILE AGDA2HS h2 #-} showHelper : ⦃ Show a ⦄ → ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Maybe a → String showHelper r (Just v) = "x == " ++ show v showHelper r Nothing = lowerBound ++ "x" ++ upperBound where lowerBound = h (rangeLower r) upperBound = h2 (rangeUpper r) showHelper2 : ⦃ Show a ⦄ → ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → String showHelper2 r = if_then_else_ (rangeIsEmpty r) "Empty" (if_then_else_ (rangeIsFull r) "All x" (showHelper r (rangeSingletonValue r))) {-# COMPILE AGDA2HS showHelper #-} {-# COMPILE AGDA2HS showHelper2 #-} instance isRangeShow : ⦃ Show a ⦄ → ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Show (Range a) isRangeShow .showsPrec _ = showString ∘ showHelper2 isRangeShow .showList = defaultShowList (showString ∘ showHelper2) {-# COMPILE AGDA2HS isRangeShow #-} rangeLower ⦃ o ⦄ ⦃ dio ⦄ (Rg x y) = x {-# COMPILE AGDA2HS rangeLower #-} rangeUpper ⦃ o ⦄ ⦃ dio ⦄ (Rg x y) = y {-# COMPILE AGDA2HS rangeUpper #-} rangeIsEmpty r@(Rg lower upper) = upper <= lower {-# COMPILE AGDA2HS rangeIsEmpty #-} emptyRange = Rg BoundaryAboveAll BoundaryBelowAll {-# COMPILE AGDA2HS emptyRange #-} rangeHas r@(Rg b1 b2) v = (v />/ b1) && not (v />/ b2) {-# COMPILE AGDA2HS rangeHas #-} rangeHas1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → a → Range a → Bool rangeHas1 v r@(Rg b1 b2) = (v />/ b1) && not (v />/ b2) rangeListHas (r@(Rg _ _) ∷ []) v = rangeHas r v rangeListHas (r1@(Rg _ _) ∷ r2@(Rg _ _) ∷ []) v = (rangeHas r1 v) || (rangeHas r2 v) rangeListHas ls v = or $ map (\r → rangeHas r v) ls {-# COMPILE AGDA2HS rangeListHas #-} rangeListHas1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → a → List (Range a) → Bool rangeListHas1 v (r@(Rg _ _) ∷ []) = rangeHas r v rangeListHas1 v (r1@(Rg _ _) ∷ r2@(Rg _ _) ∷ []) = (rangeHas r1 v) || (rangeHas r2 v) rangeListHas1 v ls = or $ map (\r → rangeHas r v) ls fullRange ⦃ o ⦄ ⦃ dio ⦄ = Rg BoundaryBelowAll BoundaryAboveAll {-# COMPILE AGDA2HS fullRange #-} singletonRange v = Rg (BoundaryBelow v) (BoundaryAbove v) {-# COMPILE AGDA2HS singletonRange #-} rangeIsFull range = (range == fullRange) {-# COMPILE AGDA2HS rangeIsFull #-} rangeOverlap r1 r2 = not (rangeIsEmpty r1) && not (rangeIsEmpty r2) && not (rangeUpper r1 <= rangeLower r2 || rangeUpper r2 <= rangeLower r1) {-# COMPILE AGDA2HS rangeOverlap #-} rangeEncloses r1 r2 = (rangeLower r1 <= rangeLower r2 && rangeUpper r2 <= rangeUpper r1) || rangeIsEmpty r2 {-# COMPILE AGDA2HS rangeEncloses #-} rangeIntersection r1@(Rg l1 u1) r2@(Rg l2 u2) = if_then_else_ (rangeIsEmpty r1 || rangeIsEmpty r2) emptyRange (Rg (max l1 l2) (min u1 u2)) {-# COMPILE AGDA2HS rangeIntersection #-} rangeU2 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Range a → List (Range a) rangeU2 r1@(Rg l1 u1) r2@(Rg l2 u2) = (if_then_else_ touching ((Rg lower upper) ∷ []) (r1 ∷ r2 ∷ [])) where touching = (max l1 l2) <= (min u1 u2) lower = min l1 l2 upper = max u1 u2 {-# COMPILE AGDA2HS rangeU2 #-} rangeU1 : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → Range a → Range a → List (Range a) rangeU1 r1@(Rg l1 u1) r2@(Rg l2 u2) = if_then_else_ (rangeIsEmpty r2) (r1 ∷ []) (rangeU2 r1 r2) {-# COMPILE AGDA2HS rangeU1 #-} rangeUnion r1@(Rg l1 u1) r2@(Rg l2 u2) = if_then_else_ (rangeIsEmpty r1) (r2 ∷ []) (rangeU1 r1 r2) {-# COMPILE AGDA2HS rangeUnion #-} rangeDifference (Rg lower1 upper1) (Rg lower2 upper2) = if_then_else_ intersects filtered (r1 ∷ []) where intersects = ((max lower1 lower2) < (min upper1 upper2)) r1 = Rg lower1 upper1 list = ((Rg lower1 lower2) ∷ (Rg upper2 upper1) ∷ []) filtered = filter (λ x → (rangeIsEmpty x) == false) list {-# COMPILE AGDA2HS rangeDifference #-} rangeSingletonValue (Rg (BoundaryBelow v1) (BoundaryBelow v2)) = if_then_else_ (adjacent v1 v2) (Just v1) Nothing rangeSingletonValue (Rg (BoundaryBelow v1) (BoundaryAbove v2)) = if_then_else_ (v1 == v2) (Just v1) Nothing rangeSingletonValue (Rg (BoundaryAbove v1) (BoundaryBelow v2)) = adjacentBelow v2 >>= λ x → adjacentBelow x >>= λ y → if_then_else_ (v1 == y) (return x) Nothing rangeSingletonValue (Rg (BoundaryAbove v1) (BoundaryAbove v2)) = if_then_else_ (adjacent v1 v2) (Just v2) Nothing rangeSingletonValue (Rg _ _) = Nothing {-# COMPILE AGDA2HS rangeSingletonValue #-}
{ "alphanum_fraction": 0.6452092102, "avg_line_length": 42.5157894737, "ext": "agda", "hexsha": "55e85688fbc1223669c3347d95110f37bc2a7843", "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": "17cdbeb36af3d0b735c5db83bb811034c39a19cd", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ioanasv/agda2hs", "max_forks_repo_path": "lib/Haskell/RangedSets/Ranges.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd", "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": "ioanasv/agda2hs", "max_issues_repo_path": "lib/Haskell/RangedSets/Ranges.agda", "max_line_length": 160, "max_stars_count": 1, "max_stars_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ioanasv/agda2hs", "max_stars_repo_path": "lib/Haskell/RangedSets/Ranges.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-25T09:41:34.000Z", "max_stars_repo_stars_event_min_datetime": "2021-05-25T09:41:34.000Z", "num_tokens": 2947, "size": 8078 }
open import Common.Prelude open import Common.Reflect id : Nat → Nat id x = x -- Used to give error: -- unquote must be applied to a term -- when checking that the expression unquote has type _3 x i : Nat → Nat i x = unquote (def (quote id) []) x
{ "alphanum_fraction": 0.692, "avg_line_length": 19.2307692308, "ext": "agda", "hexsha": "936bdebf354136b60f8b4470d53774da9bc8bed5", "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": "477c8c37f948e6038b773409358fd8f38395f827", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "larrytheliquid/agda", "max_forks_repo_path": "test/succeed/Issue1210.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "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": "larrytheliquid/agda", "max_issues_repo_path": "test/succeed/Issue1210.agda", "max_line_length": 58, "max_stars_count": null, "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_path": "test/succeed/Issue1210.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 74, "size": 250 }
{-# OPTIONS --without-K #-} module hott.types.coproduct where open import hott.core.universe data _∐_ {ℓ₀ ℓ₁ : Level} (A : Type ℓ₀) (B : Type ℓ₁) : Type (ℓ₀ ⊔ ℓ₁) where inl : (a : A) → A ∐ B -- left introduction inr : (b : B) → A ∐ B -- right introduction -- A more suggestive way of building elements of nested co-product -- types. For example if we have a : A, b : B and c : C then the -- expressions, a ∣∙, ∙∣ b ∣∙ and ∙∣ ∙∣ c are elements inl a, inr (inl -- b) and inr (inr c) of A ∐ B ∐ C respectively. _∣∙ : {ℓ₀ ℓ₁ : Level}{A : Type ℓ₀}{B : Type ℓ₁} → A → A ∐ B _∣∙ = inl ∙∣_ : {ℓ₀ ℓ₁ : Level}{A : Type ℓ₀}{B : Type ℓ₁} → B → A ∐ B ∙∣_ = inr infixr 0 ∙∣_ infixr 0 _∣∙ -- A more suggestive way of building a case by case analysis. -- For example, one can just write f1 ∣ f2 ∣ f3 _∣_ : {a b c : Level} {A : Type a} {B : Type b} {C : Type c} → (A → C) → (B → C) → (A ∐ B → C) (f ∣ g) (inl a) = f a (f ∣ g) (inr b) = g b infixr 0 _∐_ infixr 0 _∣_ -- Case by case analysis. either : {ℓ₀ ℓ₁ ℓ₃ : Level} {A : Type ℓ₀}{B : Type ℓ₁}{C : Type ℓ₃} → (A → C) → (B → C) → (A ∐ B → C) either f g (inl a) = f a either f g (inr b) = g b
{ "alphanum_fraction": 0.517579722, "avg_line_length": 23.0754716981, "ext": "agda", "hexsha": "392ccdff6016bc66ec0028558d639ef55de62c9d", "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": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "piyush-kurur/hott", "max_forks_repo_path": "agda/hott/types/coproduct.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc", "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": "piyush-kurur/hott", "max_issues_repo_path": "agda/hott/types/coproduct.agda", "max_line_length": 70, "max_stars_count": null, "max_stars_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "piyush-kurur/hott", "max_stars_repo_path": "agda/hott/types/coproduct.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 547, "size": 1223 }
{-# OPTIONS --safe #-} open import Generics.Prelude open import Generics.Telescope open import Generics.Desc open import Generics.Mu open import Generics.Mu.All open import Data.Fin.Properties as Fin open import Data.Product.Properties open import Data.Empty open import Relation.Nullary module Generics.Mu.NoConfusion {P I n} {D : DataDesc P I n} where private variable V : ExTele P p : ⟦ P ⟧tel tt v : ⟦ V ⟧tel p i : ⟦ I ⟧tel p NoConfusionCon : (C : ConDesc P V I) → ⟦ C ⟧Conω (μ D) (p , v , i) → ⟦ C ⟧Conω (μ D) (p , v , i) → Setω NoConfusionCon (var f) _ _ = ⊤ω NoConfusionCon (π ai S C) (s₁ , x) (s₂ , y) = Σω (s₁ ≡ s₂) {!!} NoConfusionCon (A ⊗ B) x y = {!!} {- module NoConfusion {P} {I : ExTele P} {n ℓ} (D : DataDesc P I ℓ n) where NoConfusionIndArg : ∀ {ℓ} (C : ConDesc P V I ℓ) {ℓ₂} {X : ⟦ P , I ⟧xtel → Set (ℓ ⊔ ℓ₂)} → ∀ {pv} → (x y : ⟦ C ⟧IndArg ℓ₂ X pv) → Set (ℓ ⊔ ℓ₂) NoConfusionIndArgᵇ : ∀ {ℓ₁ ℓ₂ ℓ₃ ℓ₄} (e : ℓ₁ ≡ ℓ₂ ⊔ ℓ₃) (i : ArgInfo) {X : ⟦ P , I ⟧xtel → Set (ℓ₃ ⊔ ℓ₄)} (S : ⟦ P , V ⟧xtel → Set ℓ₂) (C : ConDesc P (V ⊢< i > S) I ℓ₃) → ∀ {pv} (x y : IndArgᵇ ℓ₄ e i X S C pv) → Set (ℓ₁ ⊔ ℓ₄) NoConfusionIndArg (var i) x y = x ≡ y NoConfusionIndArg (A ⊗ B) (xa , xb) (ya , yb) = NoConfusionIndArg A xa ya × NoConfusionIndArg B xb yb NoConfusionIndArg (π p i S C) x y = NoConfusionIndArgᵇ p i S C x y NoConfusionIndArgᵇ refl i S C {pv} x y = x ≡ y NoConfusionConᵇ : ∀ {ℓ₁ ℓ₂ ℓ₃ ℓ₄} (e : ℓ₁ ≡ ℓ₂ ⊔ ℓ₃) (i : ArgInfo) {X : ⟦ P , I ⟧xtel → Set (ℓ₃ ⊔ ℓ₄)} (S : ⟦ P , V ⟧xtel → Set ℓ₂) (C : ConDesc P (V ⊢< i > S) I ℓ₃) → ∀ {pvi} (x y : Conᵇ ℓ₄ e i X S C pvi) → Set (ℓ₁ ⊔ ℓ₄) NoConfusionCon (var i) x y = Lift _ ⊤ NoConfusionCon (π p i S C) x y = NoConfusionConᵇ p i S C x y NoConfusionCon (A ⊗ B) (xa , xb) (ya , yb) = NoConfusionIndArg A xa ya × NoConfusionCon B xb yb NoConfusionConᵇ refl i S C (xs , xd) (ys , yd) = Σ (xs ≡ ys) λ { refl → NoConfusionCon C xd yd } NoConf : ∀ {ℓ′} {X : ⟦ P , I ⟧xtel → Set (ℓ ⊔ ℓ′)} → ∀ {pi} (x y : ⟦ D ⟧Data ℓ′ X pi) → Set (ℓ ⊔ ℓ′) NoConf (kx , x) (ky , y) with kx Fin.≟ ky ... | yes refl = NoConfusionCon (lookupCon D kx) x y ... | no _ = Lift _ ⊥ noConfIndArg-refl : ∀ {ℓ} (C : ConDesc P V I ℓ) {ℓ₂} {X : ⟦ P , I ⟧xtel → Set (ℓ ⊔ ℓ₂)} → ∀ {pvi} → (x : ⟦ C ⟧IndArg ℓ₂ X pvi) → NoConfusionIndArg C x x noConfIndArgᵇ-refl : ∀ {ℓ₁ ℓ₂ ℓ₃ ℓ₄} (e : ℓ₁ ≡ ℓ₂ ⊔ ℓ₃) (i : ArgInfo) {X : ⟦ P , I ⟧xtel → Set (ℓ₃ ⊔ ℓ₄)} (S : ⟦ P , V ⟧xtel → Set ℓ₂) (C : ConDesc P (V ⊢< i > S) I ℓ₃) → ∀ {pvi} (x : IndArgᵇ ℓ₄ e i X S C pvi) → NoConfusionIndArgᵇ e i S C x x noConfIndArg-refl (var i) x = refl noConfIndArg-refl (A ⊗ B) (xa , xb) = noConfIndArg-refl A xa , noConfIndArg-refl B xb noConfIndArg-refl (π p i S C) x = noConfIndArgᵇ-refl p i S C x noConfIndArgᵇ-refl refl i S C x = refl noConfCon-refl : ∀ {ℓ} (C : ConDesc P V I ℓ) {ℓ₂} {X : ⟦ P , I ⟧xtel → Set (ℓ ⊔ ℓ₂)} → ∀ {pvi} → (x : ⟦_⟧Con C ℓ₂ X pvi) → NoConfusionCon C x x noConfConᵇ-refl : ∀ {ℓ₁ ℓ₂ ℓ₃ ℓ₄} (e : ℓ₁ ≡ ℓ₂ ⊔ ℓ₃) (i : ArgInfo) {X : ⟦ P , I ⟧xtel → Set (ℓ₃ ⊔ ℓ₄)} (S : ⟦ P , V ⟧xtel → Set ℓ₂) (C : ConDesc P (V ⊢< i > S) I ℓ₃) → ∀ {pvi} (x : Conᵇ ℓ₄ e i X S C pvi) → NoConfusionConᵇ e i S C x x noConfCon-refl (var i) x = lift tt noConfCon-refl (A ⊗ B) (xa , xb) = noConfIndArg-refl A xa , noConfCon-refl B xb noConfCon-refl (π p i S C) x = noConfConᵇ-refl p i S C x noConfConᵇ-refl refl i S C (_ , x) = refl , noConfCon-refl C x noConfIndArg : ∀ {ℓ} (C : ConDesc P V I ℓ) {ℓ₂} {X : ⟦ P , I ⟧xtel → Set (ℓ ⊔ ℓ₂)} → ∀ {pvi} {x y : ⟦ C ⟧IndArg ℓ₂ X pvi} → NoConfusionIndArg C x y → x ≡ y noConfIndArgᵇ : ∀ {ℓ₁ ℓ₂ ℓ₃ ℓ₄} (e : ℓ₁ ≡ ℓ₂ ⊔ ℓ₃) (i : ArgInfo) {X : ⟦ P , I ⟧xtel → Set (ℓ₃ ⊔ ℓ₄)} (S : ⟦ P , V ⟧xtel → Set ℓ₂) (C : ConDesc P (V ⊢< i > S) I ℓ₃) → ∀ {pvi} {x y : IndArgᵇ ℓ₄ e i X S C pvi} → NoConfusionIndArgᵇ e i S C x y → x ≡ y noConfIndArg (var i) nc = nc noConfIndArg (A ⊗ B) (nca , ncb) = cong₂ _,_ (noConfIndArg A nca) (noConfIndArg B ncb) noConfIndArg (π p i S C) nc = noConfIndArgᵇ p i S C nc noConfIndArgᵇ refl i S C nc = nc noConfCon : ∀ {ℓ} (C : ConDesc P V I ℓ) {ℓ₂} {X : ⟦ P , I ⟧xtel → Set (ℓ ⊔ ℓ₂)} → ∀ {pvi} → {x y : ⟦_⟧Con C ℓ₂ X pvi} → NoConfusionCon C x y → x ≡ y noConfConᵇ : ∀ {ℓ₁ ℓ₂ ℓ₃ ℓ₄} (e : ℓ₁ ≡ ℓ₂ ⊔ ℓ₃) (i : ArgInfo) {X : ⟦ P , I ⟧xtel → Set (ℓ₃ ⊔ ℓ₄)} (S : ⟦ P , V ⟧xtel → Set ℓ₂) (C : ConDesc P (V ⊢< i > S) I ℓ₃) → ∀ {pvi} {x y : Conᵇ ℓ₄ e i X S C pvi} → NoConfusionConᵇ e i S C x y → x ≡ y noConfCon (var i) {x = lift refl} {lift refl} nc = refl noConfCon (A ⊗ B) (nca , ncb) = cong₂ _,_ (noConfIndArg A nca) (noConfCon B ncb) noConfCon (π p i S C) nc = noConfConᵇ p i S C nc noConfConᵇ refl i S C (refl , nc) = cong (_ ,_) (noConfCon C nc) noConf : ∀ {ℓ′} {X : ⟦ P , I ⟧xtel → Set (ℓ ⊔ ℓ′)} → ∀ {pi} {x y : ⟦ D ⟧Data ℓ′ X pi} → x ≡ y → NoConf x y noConf {x = kx , x} {ky , _} refl with kx Fin.≟ ky ... | yes refl = noConfCon-refl (lookupCon D kx) x ... | no kx≢kx = lift (kx≢kx refl) noConf₂ : ∀ {ℓ′} {X : ⟦ P , I ⟧xtel → Set (ℓ ⊔ ℓ′)} → ∀ {pi} {x y : ⟦ D ⟧Data ℓ′ X pi} → NoConf x y → x ≡ y noConf₂ {x = kx , x} {ky , y} nc with kx Fin.≟ ky ... | yes refl = cong (kx ,_) (noConfCon (lookupCon D kx) nc) ... | no kx≢ky = ⊥-elim (Lift.lower nc) -}
{ "alphanum_fraction": 0.4928547125, "avg_line_length": 38.6710526316, "ext": "agda", "hexsha": "5322829f2d6cd7f4cb934d548f530165865e6cde", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z", "max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "flupe/generics", "max_forks_repo_path": "src/Generics/Mu/NoConfusion.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z", "max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "flupe/generics", "max_issues_repo_path": "src/Generics/Mu/NoConfusion.agda", "max_line_length": 103, "max_stars_count": 11, "max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "flupe/generics", "max_stars_repo_path": "src/Generics/Mu/NoConfusion.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z", "num_tokens": 2765, "size": 5878 }
module Numeral.Real where import Lvl open import Syntax.Number open import Data open import Functional open import Logic.Propositional{Lvl.𝟎} open import Logic.Predicate{Lvl.𝟎}{Lvl.𝟎} open import Numeral.Integer hiding (𝟎) open import Numeral.Natural open import Sets.PredicateSet.Filter{Lvl.𝟎}{Lvl.𝟎} open import Structure.Setoid{Lvl.𝟎} open import Structure.Operator.Field{Lvl.𝟎}{Lvl.𝟎} open import Structure.Operator.Group{Lvl.𝟎}{Lvl.𝟎} open import Structure.Operator.Properties{Lvl.𝟎}{Lvl.𝟎} open import Structure.Real{Lvl.𝟎}{Lvl.𝟎} open import Structure.Relator.Ordering{Lvl.𝟎}{Lvl.𝟎} -- TODO: Write it properly (maybe with a "construction of the reals"?). The following in this file is something to get this started -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [The set] postulate ℝ : Set -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [Relations] -- infixr 100 _≡_ _≢_ _<_ _>_ _≤_ _≥_ _<_<_ -- Equals instance postulate [≡]-equiv : Equiv(ℝ) -- Lesser than postulate _<_ : ℝ → ℝ → Stmt open From-[<][≡] (_<_) (_≡_) public -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [Conversions] record [ℝ]-conversion (T : Set) : Set where infixl 10000 #_ field #_ : T → ℝ open [ℝ]-conversion ⦃ ... ⦄ public instance postulate [ℤ]-to-[ℝ] : [ℝ]-conversion(ℤ) instance postulate [ℕ]-to-[ℝ] : [ℝ]-conversion(ℕ) instance postulate ℝ-InfiniteNumeral : InfiniteNumeral (ℝ) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [Subsets] instance subset-to-[ℝ] : ∀{P} → [ℝ]-conversion(Filter{ℝ}(P)) subset-to-[ℝ] {P} = record{#_ = f} where f : Filter{ℝ}(P) → ℝ f(subelem x) = x -- Positive real numbers ℝ₊ = Filter{ℝ}(x ↦ (x > 0)) -- Negative real numbers ℝ₋ = Filter{ℝ}(x ↦ (x < 0)) -- Non-zero real numbers ℝ₊₋ = Filter{ℝ}(x ↦ (x ≢ 0)) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [Elements] postulate e : ℝ postulate π : ℝ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [Operators] infixl 1000 _+_ _−_ infixl 1001 _⋅_ _/_ infixl 1002 _^_ _√_ postulate _+_ : ℝ → ℝ → ℝ postulate _−_ : ℝ → ℝ → ℝ postulate _⋅_ : ℝ → ℝ → ℝ postulate _/_ : ℝ → ℝ → ℝ -- TODO: Some of these are partial functions/have smaller domains postulate _^_ : ℝ → ℝ → ℝ postulate log : ℝ → ℝ → ℝ postulate _√_ : ℝ → ℝ → ℝ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [Functions] abs : ℝ → ℝ abs(x) = 2 √ (x ^ 2) postulate sin : ℝ → ℝ cos : ℝ → ℝ cos(x) = sin(x − (π / 2)) tan : ℝ → ℝ tan(x) = sin(x) / cos(x) postulate asin : ℝ → ℝ postulate acos : ℝ → ℝ postulate atan : ℝ → ℝ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [Stuctures] instance postulate [ℝ]-realTheory : RealTheory(_+_)(_⋅_)(_≤_) instance postulate [ℝ][<]-strictPartialOrder : Strict.Order {ℝ} (_<_) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [Properties of functions in ℝ] instance postulate abs-positive : ∀{x} → (abs(x) ≥ 0) instance postulate cos-periodicity : ∀{v}{n : ℕ} → (cos(v) ≡ cos(v + 2 ⋅ π ⋅ #(n))) instance postulate sin-periodicity : ∀{v}{n : ℕ} → (sin(v) ≡ sin(v + 2 ⋅ π ⋅ #(n))) instance postulate cos-even : ∀{v} → (cos(v) ≡ cos(0 − v)) instance postulate sin-odd : ∀{v} → (sin(v) ≡ 0 − sin(0 − v)) instance postulate circle : ∀{v} → (cos(v) ^ 2 + sin(v) ^ 2 ≡ 1) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [Properties on functions of ℝ] -- postulate Axiom1 : {x y : ℝ} → (x < y) → ¬ (y < x) -- postulate Axiom2 : {x z : ℝ} → (x < z) → ∃(y ↦ (x < y) ∧ (y < z)) -- postulate Axiom4 : {x y z : ℝ} → ((x + y) + z) ≡ (x + (y + z)) -- postulate Axiom5 : {x y : ℝ} → ∃(z ↦ (x + z) ≡ y)
{ "alphanum_fraction": 0.534916596, "avg_line_length": 25.2642857143, "ext": "agda", "hexsha": "bd404d55ea0ad0b0c5f3ef5978b8d9352c92a497", "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": "old/Numeral/Real.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": "old/Numeral/Real.agda", "max_line_length": 131, "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": "old/Numeral/Real.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": 1382, "size": 3537 }
-- An ATP type must be used with data-types or postulates. -- This error is detected by TypeChecking.Rules.Decl. module ATPBadType2 where foo : Set → Set foo A = A {-# ATP type foo #-}
{ "alphanum_fraction": 0.6984126984, "avg_line_length": 17.1818181818, "ext": "agda", "hexsha": "53d94024e7384fba141c7a2a0b51c276dacd8ed5", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "asr/eagda", "max_forks_repo_path": "test/fail/ATPBadType2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "asr/eagda", "max_issues_repo_path": "test/fail/ATPBadType2.agda", "max_line_length": 58, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "asr/eagda", "max_stars_repo_path": "test/fail/ATPBadType2.agda", "max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z", "max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z", "num_tokens": 50, "size": 189 }
{-# OPTIONS --without-K --safe --exact-split #-} module Constructive.Common where open import Level open import Data.Product open import Data.Sum open import Function.Base open import Relation.Nullary infix 2 _<=>_ -- Logical equivalence _<=>_ : ∀ {a b} → Set a → Set b → Set (a ⊔ b) A <=> B = (A → B) × (B → A) module _ {a b} {A : Set a} {B : Set b} where mk<=> : (A → B) → (B → A) → A <=> B mk<=> = _,_ fwd : A <=> B → A → B fwd = proj₁ bwd : A <=> B → B → A bwd = proj₂ _∘<=>_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} → B <=> C → A <=> B → A <=> C (f , g) ∘<=> (h , i) = f ∘ h , i ∘ g Stable : ∀ {a} → Set a → Set a Stable A = ¬ ¬ A → A Dec⊎ : ∀ {a} → Set a → Set a Dec⊎ A = A ⊎ ¬ A -- Unary decidable predicate DecU : ∀ {a p} {A : Set a} → (A → Set p) → Set (a ⊔ p) DecU P = ∀ x → P x ⊎ ¬ P x Inhabited : ∀ {a} → Set a → Set a Inhabited A = A
{ "alphanum_fraction": 0.4870349493, "avg_line_length": 20.6279069767, "ext": "agda", "hexsha": "067c6c94975379ddebb37c740e31c212b3efddf9", "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/Common.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/Common.agda", "max_line_length": 56, "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/Common.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": 370, "size": 887 }
{-# OPTIONS --without-K #-} module Agda.Builtin.List where infixr 5 _∷_ data List {a} (A : Set a) : Set a where [] : List A _∷_ : (x : A) (xs : List A) → List A {-# BUILTIN LIST List #-} {-# BUILTIN NIL [] #-} {-# BUILTIN CONS _∷_ #-} {-# FOREIGN GHC type AgdaList a b = [b] #-} {-# COMPILE GHC List = data MAlonzo.Code.Agda.Builtin.List.AgdaList ([] | (:)) #-} {-# COMPILE UHC List = data __LIST__ (__NIL__ | __CONS__) #-} {-# COMPILE JS List = function(x,v) { if (x.length < 1) { return v["[]"](); } else { return v["_∷_"](x[0], x.slice(1)); } } #-} {-# COMPILE JS [] = Array() #-} {-# COMPILE JS _∷_ = function (x) { return function(y) { return Array(x).concat(y); }; } #-}
{ "alphanum_fraction": 0.5475504323, "avg_line_length": 30.1739130435, "ext": "agda", "hexsha": "d3df015645ba0c927ff7cc76b8b545f5778bf876", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Blaisorblade/Agda", "max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/List.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "Blaisorblade/Agda", "max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/List.agda", "max_line_length": 92, "max_stars_count": 3, "max_stars_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "Blaisorblade/Agda", "max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/List.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": 237, "size": 694 }
module Issue215 where open import Imports.Bool {-# COMPILED_DATA Bool Bool True False #-}
{ "alphanum_fraction": 0.752688172, "avg_line_length": 13.2857142857, "ext": "agda", "hexsha": "cc02bf734213fdd740c9ba2fcc8ab09c8a289a45", "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/Issue215.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/Issue215.agda", "max_line_length": 42, "max_stars_count": 1, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Fail/Issue215.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": 21, "size": 93 }
{-# OPTIONS --rewriting #-} module Luau.VarCtxt where open import Agda.Builtin.Equality using (_≡_) open import Luau.Type using (Type; _∪_; _∩_) open import Luau.Var using (Var) open import FFI.Data.Aeson using (KeyMap; Key; empty; unionWith; singleton; insert; delete; lookup; toString; fromString; lookup-insert; lookup-insert-not; lookup-empty; to-from; insert-swap; insert-over) open import FFI.Data.Maybe using (Maybe; just; nothing) open import Properties.Equality using (_≢_; cong; sym; trans) VarCtxt : Set VarCtxt = KeyMap Type ∅ : VarCtxt ∅ = empty _⋒_ : VarCtxt → VarCtxt → VarCtxt _⋒_ = unionWith _∩_ _⋓_ : VarCtxt → VarCtxt → VarCtxt _⋓_ = unionWith _∪_ _[_] : VarCtxt → Var → Maybe Type Γ [ x ] = lookup (fromString x) Γ _⊝_ : VarCtxt → Var → VarCtxt Γ ⊝ x = delete (fromString x) Γ _↦_ : Var → Type → VarCtxt x ↦ T = singleton (fromString x) T _⊕_↦_ : VarCtxt → Var → Type → VarCtxt Γ ⊕ x ↦ T = insert (fromString x) T Γ ⊕-over : ∀ {Γ x y T U} → (x ≡ y) → ((Γ ⊕ x ↦ T) ⊕ y ↦ U) ≡ (Γ ⊕ y ↦ U) ⊕-over p = insert-over _ _ _ _ _ (cong fromString (sym p)) ⊕-swap : ∀ {Γ x y T U} → (x ≢ y) → ((Γ ⊕ x ↦ T) ⊕ y ↦ U) ≡ ((Γ ⊕ y ↦ U) ⊕ x ↦ T) ⊕-swap p = insert-swap _ _ _ _ _ (λ q → p (trans (sym (to-from _)) (trans (cong toString (sym q) ) (to-from _))) ) ⊕-lookup-miss : ∀ x y T Γ → (x ≢ y) → (Γ [ y ] ≡ (Γ ⊕ x ↦ T) [ y ]) ⊕-lookup-miss x y T Γ p = lookup-insert-not (fromString x) (fromString y) T Γ λ q → p (trans (sym (to-from x)) (trans (cong toString q) (to-from y)))
{ "alphanum_fraction": 0.6148693905, "avg_line_length": 33.9318181818, "ext": "agda", "hexsha": "76f64dfe3e4c5c17b8b4004bb4a1d58289868346", "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": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "XanderYZZ/luau", "max_forks_repo_path": "prototyping/Luau/VarCtxt.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f", "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": "XanderYZZ/luau", "max_issues_repo_path": "prototyping/Luau/VarCtxt.agda", "max_line_length": 204, "max_stars_count": 1, "max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "TheGreatSageEqualToHeaven/luau", "max_stars_repo_path": "prototyping/Luau/VarCtxt.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z", "max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z", "num_tokens": 618, "size": 1493 }
{-# OPTIONS --allow-unsolved-metas #-} import cedille-options module elaboration-helpers (options : cedille-options.options) where open import lib open import monad-instances open import general-util open import cedille-types open import syntax-util open import ctxt open import conversion open import constants open import to-string options open import subst open import rename open import is-free open import toplevel-state options {id} open import spans options {id} uncurry' : ∀ {A B C D : Set} → (A → B → C → D) → (A × B × C) → D uncurry' f (a , b , c) = f a b c uncurry'' : ∀ {A B C D E : Set} → (A → B → C → D → E) → (A × B × C × D) → E uncurry'' f (a , b , c , d) = f a b c d uncurry''' : ∀ {A B C D E F : Set} → (A → B → C → D → E → F) → (A × B × C × D × E) → F uncurry''' f (a , b , c , d , e) = f a b c d e ctxt-term-decl' : posinfo → var → type → ctxt → ctxt ctxt-term-decl' pi x T (mk-ctxt (fn , mn , ps , q) ss is os d) = mk-ctxt (fn , mn , ps , trie-insert q x (x , ArgsNil)) ss (trie-insert is x (term-decl T , fn , pi)) os d ctxt-type-decl' : posinfo → var → kind → ctxt → ctxt ctxt-type-decl' pi x k (mk-ctxt (fn , mn , ps , q) ss is os d) = mk-ctxt (fn , mn , ps , trie-insert q x (x , ArgsNil)) ss (trie-insert is x (type-decl k , fn , pi)) os d ctxt-tk-decl' : posinfo → var → tk → ctxt → ctxt ctxt-tk-decl' pi x (Tkt T) = ctxt-term-decl' pi x T ctxt-tk-decl' pi x (Tkk k) = ctxt-type-decl' pi x k ctxt-param-decl : var → var → tk → ctxt → ctxt ctxt-param-decl x x' atk Γ @ (mk-ctxt (fn , mn , ps , q) ss is os ds) = let d = case atk of λ {(Tkt T) → term-decl T; (Tkk k) → type-decl k} in mk-ctxt (fn , mn , ps , trie-insert q x (x , ArgsNil)) ss (trie-insert is x' (d , fn , posinfo-gen)) os ds ctxt-term-def' : var → var → term → type → opacity → ctxt → ctxt ctxt-term-def' x x' t T op Γ @ (mk-ctxt (fn , mn , ps , q) ss is os d) = mk-ctxt (fn , mn , ps , qualif-insert-params q (mn # x) x ps) ss (trie-insert is x' (term-def (just ps) op (hnf Γ unfold-head t tt) T , fn , x)) os d ctxt-type-def' : var → var → type → kind → opacity → ctxt → ctxt ctxt-type-def' x x' T k op Γ @ (mk-ctxt (fn , mn , ps , q) ss is os d) = mk-ctxt (fn , mn , ps , qualif-insert-params q (mn # x) x ps) ss (trie-insert is x' (type-def (just ps) op (hnf Γ (unfolding-elab unfold-head) T tt) k , fn , x)) os d ctxt-let-term-def : posinfo → var → term → type → ctxt → ctxt ctxt-let-term-def pi x t T (mk-ctxt (fn , mn , ps , q) ss is os d) = mk-ctxt (fn , mn , ps , trie-insert q x (x , ArgsNil)) ss (trie-insert is x (term-def nothing OpacTrans t T , fn , pi)) os d ctxt-let-type-def : posinfo → var → type → kind → ctxt → ctxt ctxt-let-type-def pi x T k (mk-ctxt (fn , mn , ps , q) ss is os d) = mk-ctxt (fn , mn , ps , trie-insert q x (x , ArgsNil)) ss (trie-insert is x (type-def nothing OpacTrans T k , fn , pi)) os d ctxt-kind-def' : var → var → params → kind → ctxt → ctxt ctxt-kind-def' x x' ps2 k Γ @ (mk-ctxt (fn , mn , ps1 , q) ss is os d) = mk-ctxt (fn , mn , ps1 , qualif-insert-params q (mn # x) x ps1) ss (trie-insert is x' (kind-def (append-params ps1 $ qualif-params Γ ps2) k' , fn , posinfo-gen)) os d where k' = hnf Γ unfold-head k tt ctxt-lookup-term-var' : ctxt → var → maybe type ctxt-lookup-term-var' Γ @ (mk-ctxt (fn , mn , ps , q) ss is os d) x = env-lookup Γ x ≫=maybe λ where (term-decl T , _) → just T (term-def ps _ _ T , _ , x') → let ps = maybe-else ParamsNil id ps in just $ abs-expand-type ps T _ → nothing -- TODO: Could there be parameter/argument clashes if the same parameter variable is defined multiple times? -- TODO: Could variables be parameter-expanded multiple times? ctxt-lookup-type-var' : ctxt → var → maybe kind ctxt-lookup-type-var' Γ @ (mk-ctxt (fn , mn , ps , q) ss is os d) x = env-lookup Γ x ≫=maybe λ where (type-decl k , _) → just k (type-def ps _ _ k , _ , x') → let ps = maybe-else ParamsNil id ps in just $ abs-expand-kind ps k _ → nothing subst-qualif : ∀ {ed : exprd} → ctxt → renamectxt → ⟦ ed ⟧ → ⟦ ed ⟧ subst-qualif{TERM} Γ ρ = subst-renamectxt Γ ρ ∘ qualif-term Γ subst-qualif{TYPE} Γ ρ = subst-renamectxt Γ ρ ∘ qualif-type Γ subst-qualif{KIND} Γ ρ = subst-renamectxt Γ ρ ∘ qualif-kind Γ subst-qualif Γ ρ = id rename-validify : string → string rename-validify = 𝕃char-to-string ∘ (h ∘ string-to-𝕃char) where validify-char : char → 𝕃 char validify-char c with (c =char 'a') || (c =char 'z') || (c =char 'A') || (c =char 'Z') || (c =char '\'') || (c =char '-') || (c =char '_') || is-digit c || (('a' <char c) && (c <char 'z')) || (('A' <char c) && (c <char 'Z')) ...| tt = [ c ] ...| ff = 'Z' :: string-to-𝕃char (ℕ-to-string (toNat c)) ++ [ 'Z' ] h : 𝕃 char → 𝕃 char h [] = [] h (c :: cs) = validify-char c ++ h cs -- Returns a fresh variable name by adding primes and replacing invalid characters fresh-var' : string → (string → 𝔹) → renamectxt → string fresh-var' = fresh-var ∘ rename-validify rename-new_from_for_ : ∀ {X : Set} → var → ctxt → (var → X) → X rename-new "_" from Γ for f = f $ fresh-var' "x" (ctxt-binds-var Γ) empty-renamectxt rename-new x from Γ for f = f $ fresh-var' x (ctxt-binds-var Γ) empty-renamectxt rename_from_for_ : ∀ {X : Set} → var → ctxt → (var → X) → X rename "_" from Γ for f = f "_" rename x from Γ for f = f $ fresh-var' x (ctxt-binds-var Γ) empty-renamectxt fresh-id-term : ctxt → term fresh-id-term Γ = rename "x" from Γ for λ x → mlam x $ mvar x get-renaming : renamectxt → var → var → var × renamectxt get-renaming ρ xₒ x = let x' = fresh-var' x (renamectxt-in-range ρ) ρ in x' , renamectxt-insert ρ xₒ x' rename_-_from_for_ : ∀ {X : Set} → var → var → renamectxt → (var → renamectxt → X) → X rename xₒ - "_" from ρ for f = f "_" ρ rename xₒ - x from ρ for f = uncurry f $ get-renaming ρ xₒ x rename_-_lookup_for_ : ∀ {X : Set} → var → var → renamectxt → (var → renamectxt → X) → X rename xₒ - x lookup ρ for f with renamectxt-lookup ρ xₒ ...| nothing = rename xₒ - x from ρ for f ...| just x' = f x' ρ qualif-new-var : ctxt → var → var qualif-new-var Γ x = ctxt-get-current-modname Γ # x mbeta : term → term → term mrho : term → var → type → term → term mtpeq : term → term → type mbeta t t' = Beta posinfo-gen (SomeTerm t posinfo-gen) (SomeTerm t' posinfo-gen) mrho t x T t' = Rho posinfo-gen RhoPlain NoNums t (Guide posinfo-gen x T) t' mtpeq t1 t2 = TpEq posinfo-gen t1 t2 posinfo-gen subst-args-params : ctxt → args → params → kind → kind subst-args-params Γ (ArgsCons (TermArg _ t) ys) (ParamsCons (Decl _ _ _ x _ _) ps) k = subst-args-params Γ ys ps $ subst Γ t x k subst-args-params Γ (ArgsCons (TypeArg t) ys) (ParamsCons (Decl _ _ _ x _ _) ps) k = subst-args-params Γ ys ps $ subst Γ t x k subst-args-params Γ ys ps k = k data indx : Set where Index : var → tk → indx data ctr : Set where Ctr : var → type → ctr parameters = 𝕃 decl indices = 𝕃 indx constructors = 𝕃 ctr data datatype : Set where Data : var → parameters → indices → constructors → datatype params-to-parameters : params → parameters params-to-parameters ParamsNil = [] params-to-parameters (ParamsCons p ps) = p :: params-to-parameters ps {-# TERMINATING #-} decompose-arrows : ctxt → type → parameters × type decompose-arrows Γ (Abs pi me pi' x atk T) = rename-new x from Γ for λ x' → case decompose-arrows (ctxt-var-decl x' Γ) (rename-var Γ x x' T) of λ where (ps , T') → Decl posinfo-gen posinfo-gen me x' atk posinfo-gen :: ps , T' decompose-arrows Γ (TpArrow T me T') = rename-new "_" from Γ for λ x → case decompose-arrows (ctxt-var-decl x Γ) T' of λ where (ps , T'') → Decl posinfo-gen posinfo-gen me x (Tkt T) posinfo-gen :: ps , T'' decompose-arrows Γ (TpParens pi T pi') = decompose-arrows Γ T decompose-arrows Γ T = [] , T decompose-ctr-type : ctxt → type → type × parameters × 𝕃 tty decompose-ctr-type Γ T with decompose-arrows Γ T ...| ps , Tᵣ with decompose-tpapps Tᵣ ...| Tₕ , as = Tₕ , ps , as {-# TERMINATING #-} kind-to-indices : ctxt → kind → indices kind-to-indices Γ (KndArrow k k') = rename "x" from Γ for λ x' → Index x' (Tkk k) :: kind-to-indices (ctxt-var-decl x' Γ) k' kind-to-indices Γ (KndParens pi k pi') = kind-to-indices Γ k kind-to-indices Γ (KndPi pi pi' x atk k) = rename x from Γ for λ x' → Index x' atk :: kind-to-indices (ctxt-var-decl x' Γ) k kind-to-indices Γ (KndTpArrow T k) = rename "x" from Γ for λ x' → Index x' (Tkt T) :: kind-to-indices (ctxt-var-decl x' Γ) k kind-to-indices Γ (KndVar pi x as) with ctxt-lookup-kind-var-def Γ x ...| nothing = [] ...| just (ps , k) = kind-to-indices Γ $ subst-args-params Γ as ps k kind-to-indices Γ (Star pi) = [] dataConsts-to-ctrs : dataConsts → constructors dataConsts-to-ctrs DataNull = [] dataConsts-to-ctrs (DataCons (DataConst _ x T) cs) = Ctr x T :: dataConsts-to-ctrs cs defDatatype-to-datatype : ctxt → defDatatype → datatype defDatatype-to-datatype Γ (Datatype _ _ x ps k dcs _) = Data x (params-to-parameters ps) (kind-to-indices Γ k) (dataConsts-to-ctrs dcs) indices-to-kind : indices → kind → kind indices-to-kind = flip $ foldr λ {(Index x atk) → KndPi posinfo-gen posinfo-gen x atk} parameters-to-kind : parameters → kind → kind parameters-to-kind = flip $ foldr λ {(Decl pi pi' me x atk pi'') → KndPi pi pi' x atk} indices-to-tplams : indices → (body : type) → type indices-to-tplams = flip $ foldr λ where (Index x atk) → TpLambda posinfo-gen posinfo-gen x atk parameters-to-tplams : parameters → (body : type) → type parameters-to-tplams = flip $ foldr λ where (Decl pi pi' me x atk pi'') → TpLambda pi pi' x atk indices-to-alls : indices → (body : type) → type indices-to-alls = flip $ foldr λ where (Index x atk) → Abs posinfo-gen Erased posinfo-gen x atk parameters-to-alls : parameters → (body : type) → type parameters-to-alls = flip $ foldr λ where (Decl pi pi' me x atk pi'') → Abs pi me pi' x atk indices-to-lams : indices → (body : term) → term indices-to-lams = flip $ foldr λ where (Index x atk) → Lam posinfo-gen Erased posinfo-gen x (SomeClass atk) indices-to-lams' : indices → (body : term) → term indices-to-lams' = flip $ foldr λ where (Index x atk) → Lam posinfo-gen Erased posinfo-gen x NoClass parameters-to-lams : parameters → (body : term) → term parameters-to-lams = flip $ foldr λ where (Decl pi pi' me x atk pi'') → Lam pi me pi' x (SomeClass atk) parameters-to-lams' : parameters → (body : term) → term parameters-to-lams' = flip $ foldr λ where (Decl pi pi' me x atk pi'') → Lam pi me pi' x NoClass indices-to-apps : indices → (body : term) → term indices-to-apps = flip $ foldl λ where (Index x (Tkt T)) t → App t Erased (mvar x) (Index x (Tkk k)) t → AppTp t (mtpvar x) parameters-to-apps : parameters → (body : term) → term parameters-to-apps = flip $ foldl λ where (Decl pi pi' me x (Tkt T) pi'') t → App t me (mvar x) (Decl pi pi' me x (Tkk k) pi'') t → AppTp t (mtpvar x) indices-to-tpapps : indices → (body : type) → type indices-to-tpapps = flip $ foldl λ where (Index x (Tkt T)) T' → TpAppt T' (mvar x) (Index x (Tkk k)) T → TpApp T (mtpvar x) parameters-to-tpapps : parameters → (body : type) → type parameters-to-tpapps = flip $ foldl λ where (Decl pi pi' me x (Tkt T) pi'') T' → TpAppt T' (mvar x) (Decl pi pi' me x (Tkk k) pi'') T → TpApp T (mtpvar x) constructors-to-lams' : constructors → (body : term) → term constructors-to-lams' = flip $ foldr λ where (Ctr x T) → Lam posinfo-gen NotErased posinfo-gen x NoClass constructors-to-lams : ctxt → var → parameters → constructors → (body : term) → term constructors-to-lams Γ x ps cs t = foldr (λ {(Ctr y T) f Γ → Lam posinfo-gen NotErased posinfo-gen y (SomeClass $ Tkt $ subst Γ (parameters-to-tpapps ps $ mtpvar y) y T) $ f $ ctxt-var-decl y Γ}) (λ Γ → t) cs Γ add-indices-to-ctxt : indices → ctxt → ctxt add-indices-to-ctxt = flip $ foldr λ {(Index x atk) → ctxt-var-decl x} add-parameters-to-ctxt : parameters → ctxt → ctxt add-parameters-to-ctxt = flip $ foldr λ {(Decl _ _ _ x'' _ _) → ctxt-var-decl x''} add-constructors-to-ctxt : constructors → ctxt → ctxt add-constructors-to-ctxt = flip $ foldr λ where (Ctr x T) → ctxt-var-decl x module reindexing (Γ : ctxt) (isₒ : indices) where reindex-fresh-var : renamectxt → trie indices → var → var reindex-fresh-var ρ is "_" = "_" reindex-fresh-var ρ is x = fresh-var x (λ x' → ctxt-binds-var Γ x' || trie-contains is x') ρ rename-indices : renamectxt → trie indices → indices rename-indices ρ is = foldr {B = renamectxt → indices} (λ {(Index x atk) f ρ → let x' = reindex-fresh-var ρ is x in Index x' (substh-tk {TERM} Γ ρ empty-trie atk) :: f (renamectxt-insert ρ x x')}) (λ ρ → []) isₒ ρ reindex-t : Set → Set reindex-t X = renamectxt → trie indices → X → X reindex : ∀ {ed} → reindex-t ⟦ ed ⟧ reindex-term : reindex-t term reindex-type : reindex-t type reindex-kind : reindex-t kind reindex-tk : reindex-t tk reindex-liftingType : reindex-t liftingType reindex-optTerm : reindex-t optTerm reindex-optType : reindex-t optType reindex-optGuide : reindex-t optGuide reindex-optClass : reindex-t optClass reindex-lterms : reindex-t lterms reindex-args : reindex-t args reindex-arg : reindex-t arg reindex-theta : reindex-t theta reindex-vars : reindex-t (maybe vars) reindex-defTermOrType : renamectxt → trie indices → defTermOrType → defTermOrType × renamectxt reindex{TERM} = reindex-term reindex{TYPE} = reindex-type reindex{KIND} = reindex-kind reindex{TK} = reindex-tk reindex = λ ρ is x → x rc-is : renamectxt → indices → renamectxt rc-is = foldr λ {(Index x atk) ρ → renamectxt-insert ρ x x} index-var = "indices" index-type-var = "Indices" is-index-var = isJust ∘ is-pfx index-var is-index-type-var = isJust ∘ is-pfx index-type-var reindex-term ρ is (App t me (Var pi x)) with trie-lookup is x ...| nothing = App (reindex-term ρ is t) me (reindex-term ρ is (Var pi x)) ...| just is' = indices-to-apps is' $ reindex-term ρ is t reindex-term ρ is (App t me t') = App (reindex-term ρ is t) me (reindex-term ρ is t') reindex-term ρ is (AppTp t T) = AppTp (reindex-term ρ is t) (reindex-type ρ is T) reindex-term ρ is (Beta pi ot ot') = Beta pi (reindex-optTerm ρ is ot) (reindex-optTerm ρ is ot') reindex-term ρ is (Chi pi oT t) = Chi pi (reindex-optType ρ is oT) (reindex-term ρ is t) reindex-term ρ is (Delta pi oT t) = Delta pi (reindex-optType ρ is oT) (reindex-term ρ is t) reindex-term ρ is (Epsilon pi lr m t) = Epsilon pi lr m (reindex-term ρ is t) reindex-term ρ is (Hole pi) = Hole pi reindex-term ρ is (IotaPair pi t t' g pi') = IotaPair pi (reindex-term ρ is t) (reindex-term ρ is t') (reindex-optGuide ρ is g) pi' reindex-term ρ is (IotaProj t n pi) = IotaProj (reindex-term ρ is t) n pi reindex-term ρ is (Lam pi me pi' x oc t) with is-index-var x ...| ff = let x' = reindex-fresh-var ρ is x in Lam pi me pi' x' (reindex-optClass ρ is oc) (reindex-term (renamectxt-insert ρ x x') is t) ...| tt with rename-indices ρ is | oc ...| isₙ | NoClass = indices-to-lams' isₙ $ reindex-term (rc-is ρ isₙ) (trie-insert is x isₙ) t ...| isₙ | SomeClass atk = indices-to-lams isₙ $ reindex-term (rc-is ρ isₙ) (trie-insert is x isₙ) t reindex-term ρ is (Let pi d t) = elim-pair (reindex-defTermOrType ρ is d) λ d' ρ' → Let pi d' (reindex-term ρ' is t) reindex-term ρ is (Open pi x t) = Open pi x (reindex-term ρ is t) reindex-term ρ is (Parens pi t pi') = reindex-term ρ is t reindex-term ρ is (Phi pi t₌ t₁ t₂ pi') = Phi pi (reindex-term ρ is t₌) (reindex-term ρ is t₁) (reindex-term ρ is t₂) pi' reindex-term ρ is (Rho pi op on t og t') = Rho pi op on (reindex-term ρ is t) (reindex-optGuide ρ is og) (reindex-term ρ is t') reindex-term ρ is (Sigma pi t) = Sigma pi (reindex-term ρ is t) reindex-term ρ is (Theta pi θ t ts) = Theta pi (reindex-theta ρ is θ) (reindex-term ρ is t) (reindex-lterms ρ is ts) reindex-term ρ is (Var pi x) = Var pi $ renamectxt-rep ρ x reindex-term ρ is (Mu pi x t oT pi' cs pi'') = Var posinfo-gen "template-mu-not-allowed" reindex-term ρ is (Mu' pi t oT pi' cs pi'') = Var posinfo-gen "template-mu-not-allowed" reindex-type ρ is (Abs pi me pi' x atk T) with is-index-var x ...| ff = let x' = reindex-fresh-var ρ is x in Abs pi me pi' x' (reindex-tk ρ is atk) (reindex-type (renamectxt-insert ρ x x') is T) ...| tt = let isₙ = rename-indices ρ is in indices-to-alls isₙ $ reindex-type (rc-is ρ isₙ) (trie-insert is x isₙ) T reindex-type ρ is (Iota pi pi' x T T') = let x' = reindex-fresh-var ρ is x in Iota pi pi' x' (reindex-type ρ is T) (reindex-type (renamectxt-insert ρ x x') is T') reindex-type ρ is (Lft pi pi' x t lT) = let x' = reindex-fresh-var ρ is x in Lft pi pi' x' (reindex-term (renamectxt-insert ρ x x') is t) (reindex-liftingType ρ is lT) reindex-type ρ is (NoSpans T pi) = NoSpans (reindex-type ρ is T) pi reindex-type ρ is (TpLet pi d T) = elim-pair (reindex-defTermOrType ρ is d) λ d' ρ' → TpLet pi d' (reindex-type ρ' is T) reindex-type ρ is (TpApp T T') = TpApp (reindex-type ρ is T) (reindex-type ρ is T') reindex-type ρ is (TpAppt T (Var pi x)) with trie-lookup is x ...| nothing = TpAppt (reindex-type ρ is T) (reindex-term ρ is (Var pi x)) ...| just is' = indices-to-tpapps is' $ reindex-type ρ is T reindex-type ρ is (TpAppt T t) = TpAppt (reindex-type ρ is T) (reindex-term ρ is t) reindex-type ρ is (TpArrow (TpVar pi x) Erased T) with is-index-type-var x ...| ff = TpArrow (reindex-type ρ is (TpVar pi x)) Erased (reindex-type ρ is T) ...| tt = let isₙ = rename-indices ρ is in indices-to-alls isₙ $ reindex-type (rc-is ρ isₙ) (trie-insert is x isₙ) T reindex-type ρ is (TpArrow T me T') = TpArrow (reindex-type ρ is T) me (reindex-type ρ is T') reindex-type ρ is (TpEq pi t t' pi') = TpEq pi (reindex-term ρ is t) (reindex-term ρ is t') pi' reindex-type ρ is (TpHole pi) = TpHole pi reindex-type ρ is (TpLambda pi pi' x atk T) with is-index-var x ...| ff = let x' = reindex-fresh-var ρ is x in TpLambda pi pi' x' (reindex-tk ρ is atk) (reindex-type (renamectxt-insert ρ x x') is T) ...| tt = let isₙ = rename-indices ρ is in indices-to-tplams isₙ $ reindex-type (rc-is ρ isₙ) (trie-insert is x isₙ) T reindex-type ρ is (TpParens pi T pi') = reindex-type ρ is T reindex-type ρ is (TpVar pi x) = TpVar pi $ renamectxt-rep ρ x reindex-kind ρ is (KndParens pi k pi') = reindex-kind ρ is k reindex-kind ρ is (KndArrow k k') = KndArrow (reindex-kind ρ is k) (reindex-kind ρ is k') reindex-kind ρ is (KndPi pi pi' x atk k) with is-index-var x ...| ff = let x' = reindex-fresh-var ρ is x in KndPi pi pi' x' (reindex-tk ρ is atk) (reindex-kind (renamectxt-insert ρ x x') is k) ...| tt = let isₙ = rename-indices ρ is in indices-to-kind isₙ $ reindex-kind (rc-is ρ isₙ) (trie-insert is x isₙ) k reindex-kind ρ is (KndTpArrow (TpVar pi x) k) with is-index-type-var x ...| ff = KndTpArrow (reindex-type ρ is (TpVar pi x)) (reindex-kind ρ is k) ...| tt = let isₙ = rename-indices ρ is in indices-to-kind isₙ $ reindex-kind (rc-is ρ isₙ) is k reindex-kind ρ is (KndTpArrow T k) = KndTpArrow (reindex-type ρ is T) (reindex-kind ρ is k) reindex-kind ρ is (KndVar pi x as) = KndVar pi (renamectxt-rep ρ x) (reindex-args ρ is as) reindex-kind ρ is (Star pi) = Star pi reindex-tk ρ is (Tkt T) = Tkt $ reindex-type ρ is T reindex-tk ρ is (Tkk k) = Tkk $ reindex-kind ρ is k -- Can't reindex large indices in a lifting type (LiftPi requires a type, not a tk), -- so for now we will just ignore reindexing lifting types. -- Types withing lifting types will still be reindexed, though. reindex-liftingType ρ is (LiftArrow lT lT') = LiftArrow (reindex-liftingType ρ is lT) (reindex-liftingType ρ is lT') reindex-liftingType ρ is (LiftParens pi lT pi') = reindex-liftingType ρ is lT reindex-liftingType ρ is (LiftPi pi x T lT) = let x' = reindex-fresh-var ρ is x in LiftPi pi x' (reindex-type ρ is T) (reindex-liftingType (renamectxt-insert ρ x x') is lT) reindex-liftingType ρ is (LiftStar pi) = LiftStar pi reindex-liftingType ρ is (LiftTpArrow T lT) = LiftTpArrow (reindex-type ρ is T) (reindex-liftingType ρ is lT) reindex-optTerm ρ is NoTerm = NoTerm reindex-optTerm ρ is (SomeTerm t pi) = SomeTerm (reindex-term ρ is t) pi reindex-optType ρ is NoType = NoType reindex-optType ρ is (SomeType T) = SomeType (reindex-type ρ is T) reindex-optClass ρ is NoClass = NoClass reindex-optClass ρ is (SomeClass atk) = SomeClass (reindex-tk ρ is atk) reindex-optGuide ρ is NoGuide = NoGuide reindex-optGuide ρ is (Guide pi x T) = let x' = reindex-fresh-var ρ is x in Guide pi x' (reindex-type (renamectxt-insert ρ x x') is T) reindex-lterms ρ is (LtermsNil pi) = LtermsNil pi reindex-lterms ρ is (LtermsCons me t ts) = LtermsCons me (reindex-term ρ is t) (reindex-lterms ρ is ts) reindex-theta ρ is (AbstractVars xs) = maybe-else Abstract AbstractVars $ reindex-vars ρ is $ just xs reindex-theta ρ is θ = θ reindex-vars''' : vars → vars → vars reindex-vars''' (VarsNext x xs) xs' = VarsNext x $ reindex-vars''' xs xs' reindex-vars''' (VarsStart x) xs = VarsNext x xs reindex-vars'' : vars → maybe vars reindex-vars'' (VarsNext x (VarsStart x')) = just $ VarsStart x reindex-vars'' (VarsNext x xs) = maybe-map (VarsNext x) $ reindex-vars'' xs reindex-vars'' (VarsStart x) = nothing reindex-vars' : renamectxt → trie indices → var → maybe vars reindex-vars' ρ is x = maybe-else (just $ VarsStart $ renamectxt-rep ρ x) (reindex-vars'' ∘ flip foldr (VarsStart "") λ {(Index x atk) → VarsNext x}) (trie-lookup is x) reindex-vars ρ is (just (VarsStart x)) = reindex-vars' ρ is x reindex-vars ρ is (just (VarsNext x xs)) = maybe-else (reindex-vars ρ is $ just xs) (λ xs' → maybe-map (reindex-vars''' xs') $ reindex-vars ρ is $ just xs) $ reindex-vars' ρ is x reindex-vars ρ is nothing = nothing reindex-arg ρ is (TermArg me t) = TermArg me (reindex-term ρ is t) reindex-arg ρ is (TypeArg T) = TypeArg (reindex-type ρ is T) reindex-args ρ is ArgsNil = ArgsNil reindex-args ρ is (ArgsCons a as) = ArgsCons (reindex-arg ρ is a) (reindex-args ρ is as) reindex-defTermOrType ρ is (DefTerm pi x oT t) = let x' = reindex-fresh-var ρ is x in DefTerm pi x' (reindex-optType ρ is oT) (reindex-term ρ is t) , renamectxt-insert ρ x x' reindex-defTermOrType ρ is (DefType pi x k T) = let x' = reindex-fresh-var ρ is x in DefType pi x' (reindex-kind ρ is k) (reindex-type ρ is T) , renamectxt-insert ρ x x' reindex-cmds : renamectxt → trie indices → cmds → cmds × renamectxt reindex-cmds ρ is CmdsStart = CmdsStart , ρ reindex-cmds ρ is (CmdsNext (ImportCmd i) cs) = elim-pair (reindex-cmds ρ is cs) $ _,_ ∘ CmdsNext (ImportCmd i) reindex-cmds ρ is (CmdsNext (DefTermOrType op d pi) cs) = elim-pair (reindex-defTermOrType ρ is d) λ d' ρ' → elim-pair (reindex-cmds ρ' is cs) $ _,_ ∘ CmdsNext (DefTermOrType op d' pi) reindex-cmds ρ is (CmdsNext (DefKind pi x ps k pi') cs) = let x' = reindex-fresh-var ρ is x in elim-pair (reindex-cmds (renamectxt-insert ρ x x') is cs) $ _,_ ∘ CmdsNext (DefKind pi x' ps (reindex-kind ρ is k) pi') reindex-cmds ρ is (CmdsNext (DefDatatype dt pi) cs) = reindex-cmds ρ is cs -- Templates can't use datatypes! reindex-file : ctxt → indices → start → cmds × renamectxt reindex-file Γ is (File pi csᵢ pi' pi'' x ps cs pi''') = reindex-cmds empty-renamectxt empty-trie cs where open reindexing Γ is mk-ctr-term : maybeErased → (x X : var) → constructors → parameters → term mk-ctr-term me x X cs ps = let t = Mlam X $ constructors-to-lams' cs $ parameters-to-apps ps $ mvar x in case me of λ where Erased → Beta posinfo-gen NoTerm $ SomeTerm t posinfo-gen NotErased → IotaPair posinfo-gen (Beta posinfo-gen NoTerm $ SomeTerm t posinfo-gen) t NoGuide posinfo-gen mk-ctr-type : maybeErased → ctxt → ctr → constructors → var → type mk-ctr-type me Γ (Ctr x T) cs Tₕ with decompose-ctr-type (ctxt-var-decl Tₕ Γ) T ...| Tₓ , ps , is = parameters-to-alls ps $ TpAppt (curry recompose-tpapps (mtpvar Tₕ) is) $ rename "X" from add-parameters-to-ctxt ps (ctxt-var-decl Tₕ Γ) for λ X → mk-ctr-term me x X cs ps record encoded-datatype-names : Set where constructor mk-encoded-datatype-names field data-functor : var data-fmap : var data-functor-ind : var cast : var fixpoint-type : var fixpoint-in : var fixpoint-ind : var record elab-mus : Set where field elab-check-mu : var → type → maybe term elab-synth-mu : var → maybe (term × type) elab-check-mu' : type → maybe term elab-synth-mu' : maybe (term × type) record encoded-datatype : Set where constructor mk-encoded-datatype field data-def : datatype names : encoded-datatype-names elab-mu : datatype → encoded-datatype-names → ctxt → term → optType → cases → elab-mus elab-check-mu = λ Γ t oT ms → elab-mus.elab-check-mu $ elab-mu data-def names Γ t oT ms elab-synth-mu = λ Γ t oT ms → elab-mus.elab-synth-mu $ elab-mu data-def names Γ t oT ms elab-check-mu' = λ Γ t oT ms → elab-mus.elab-check-mu' $ elab-mu data-def names Γ t oT ms elab-synth-mu' = λ Γ t oT ms → elab-mus.elab-synth-mu' $ elab-mu data-def names Γ t oT ms record datatype-encoding : Set where constructor mk-datatype-encoding field template : start functor : var cast : var fixpoint-type : var fixpoint-in : var fixpoint-ind : var elab-mu : datatype → encoded-datatype-names → ctxt → term → optType → cases → elab-mus mk-defs : ctxt → datatype → cmds × encoded-datatype mk-defs Γ'' (Data x ps is cs) = append-cmds tcs (csn functor-cmd $ csn functor-ind-cmd $ csn fmap-cmd $ csn type-cmd $ foldr (csn ∘ ctr-cmd) CmdsStart cs) , record { elab-mu = elab-mu; data-def = Data x ps is cs; names = record { data-functor = data-functorₓ; data-fmap = data-fmapₓ; data-functor-ind = data-functor-indₓ; cast = castₓ; fixpoint-type = fixpoint-typeₓ; fixpoint-in = fixpoint-inₓ; fixpoint-ind = fixpoint-indₓ}} where csn = CmdsNext ∘ flip (DefTermOrType OpacTrans) posinfo-gen k = indices-to-kind is $ Star posinfo-gen Γ' = add-parameters-to-ctxt ps $ add-constructors-to-ctxt cs $ ctxt-var-decl x Γ'' tcs-ρ = reindex-file Γ' is template tcs = fst tcs-ρ ρ = snd tcs-ρ data-functorₓ = fresh-var (x ^ "F") (ctxt-binds-var Γ') ρ data-fmapₓ = fresh-var (x ^ "Fmap") (ctxt-binds-var Γ') ρ data-functor-indₓ = fresh-var (x ^ "IndF") (ctxt-binds-var Γ') ρ functorₓ = renamectxt-rep ρ functor castₓ = renamectxt-rep ρ cast fixpoint-typeₓ = renamectxt-rep ρ fixpoint-type fixpoint-inₓ = renamectxt-rep ρ fixpoint-in fixpoint-indₓ = renamectxt-rep ρ fixpoint-ind Γ = add-indices-to-ctxt is $ ctxt-var-decl data-functorₓ $ ctxt-var-decl data-fmapₓ $ ctxt-var-decl data-functor-indₓ Γ' new-var : ∀ {ℓ} {X : Set ℓ} → var → (var → X) → X new-var x f = f $ fresh-var x (ctxt-binds-var Γ) ρ functor-cmd = DefType posinfo-gen data-functorₓ (parameters-to-kind ps $ KndArrow k k) $ parameters-to-tplams ps $ TpLambda posinfo-gen posinfo-gen x (Tkk $ k) $ indices-to-tplams is $ new-var "x" λ xₓ → new-var "X" λ Xₓ → Iota posinfo-gen posinfo-gen xₓ (mtpeq id-term id-term) $ Abs posinfo-gen Erased posinfo-gen Xₓ (Tkk $ indices-to-kind is $ KndTpArrow (mtpeq id-term id-term) star) $ foldr (λ c → flip TpArrow NotErased $ mk-ctr-type Erased Γ c cs Xₓ) (TpAppt (indices-to-tpapps is $ mtpvar Xₓ) (mvar xₓ)) cs functor-ind-cmd = DefTerm posinfo-gen data-functor-indₓ NoType $ parameters-to-lams ps $ Lam posinfo-gen Erased posinfo-gen x (SomeClass $ Tkk k) $ indices-to-lams is $ new-var "x" λ xₓ → new-var "y" λ yₓ → new-var "e" λ eₓ → new-var "X" λ Xₓ → let T = indices-to-tpapps is $ TpApp (parameters-to-tpapps ps $ mtpvar data-functorₓ) (mtpvar x) in Lam posinfo-gen NotErased posinfo-gen xₓ (SomeClass $ Tkt T) $ Lam posinfo-gen Erased posinfo-gen Xₓ (SomeClass $ Tkk $ indices-to-kind is $ KndTpArrow T star) $ flip (foldr λ {c @ (Ctr x' _) → Lam posinfo-gen NotErased posinfo-gen x' $ SomeClass $ Tkt $ mk-ctr-type NotErased Γ c cs Xₓ}) cs $ flip mappe (Beta posinfo-gen NoTerm NoTerm) $ flip mappe (mvar xₓ) $ let Γ' = ctxt-var-decl xₓ $ ctxt-var-decl yₓ $ ctxt-var-decl eₓ $ ctxt-var-decl Xₓ Γ in flip (foldl λ {(Ctr x' T) → flip mapp $ elim-pair (decompose-arrows Γ T) λ ps' Tₕ → parameters-to-lams' ps' $ Mlam yₓ $ Mlam eₓ $ parameters-to-apps ps' $ mvar x'}) cs $ AppTp (IotaProj (mvar xₓ) "2" posinfo-gen) $ indices-to-tplams is $ TpLambda posinfo-gen posinfo-gen xₓ (Tkt $ mtpeq id-term id-term) $ Abs posinfo-gen Erased posinfo-gen yₓ (Tkt T) $ Abs posinfo-gen Erased posinfo-gen eₓ (Tkt $ mtpeq (mvar yₓ) (mvar xₓ)) $ TpAppt (indices-to-tpapps is $ mtpvar Xₓ) $ Phi posinfo-gen (mvar eₓ) (mvar yₓ) (mvar xₓ) posinfo-gen fmap-cmd : defTermOrType fmap-cmd with new-var "A" id | new-var "B" id | new-var "c" id ...| Aₓ | Bₓ | cₓ = DefTerm posinfo-gen data-fmapₓ (SomeType $ parameters-to-alls ps $ TpApp (mtpvar functorₓ) $ parameters-to-tpapps ps $ mtpvar data-functorₓ) $ parameters-to-lams ps $ Mlam Aₓ $ Mlam Bₓ $ Mlam cₓ $ IotaPair posinfo-gen (indices-to-lams is $ new-var "x" λ xₓ → mlam xₓ $ IotaPair posinfo-gen (IotaProj (mvar xₓ) "1" posinfo-gen) (new-var "X" λ Xₓ → Mlam Xₓ $ constructors-to-lams' cs $ foldl (flip mapp ∘ eta-expand-fmap) (AppTp (IotaProj (mvar xₓ) "2" posinfo-gen) $ mtpvar Xₓ) cs) NoGuide posinfo-gen) (Beta posinfo-gen NoTerm NoTerm) NoGuide posinfo-gen where eta-expand-fmaph-type : ctxt → var → type → term eta-expand-fmaph-type Γ x' T with decompose-ctr-type Γ T ...| Tₕ , ps , as with add-parameters-to-ctxt ps Γ ...| Γ' = parameters-to-lams' ps $ flip mapp (parameters-to-apps ps $ mvar x') $ recompose-apps Erased as $ flip mappe (mvar cₓ) $ flip AppTp (mtpvar Bₓ) $ AppTp (mvar castₓ) (mtpvar Aₓ) eta-expand-fmap : ctr → term eta-expand-fmap (Ctr x' T) with ctxt-var-decl Aₓ $ ctxt-var-decl Bₓ $ ctxt-var-decl cₓ Γ ...| Γ' with decompose-ctr-type Γ' T ...| Tₕ , ps , as with foldr (λ {(Decl _ _ _ x'' _ _) → ctxt-var-decl x''}) Γ' ps ...| Γ'' = parameters-to-lams' ps $ foldl (λ {(Decl pi pi' me x'' (Tkt T) pi'') t → App t me $ if ~ is-free-in tt x T then mvar x'' else eta-expand-fmaph-type Γ'' x'' T; (Decl pi pi' me x'' (Tkk k) pi'') t → AppTp t $ mtpvar x''}) (mvar x') $ ps type-cmd = DefType posinfo-gen x (parameters-to-kind ps $ k) $ parameters-to-tplams ps $ TpAppt (TpApp (mtpvar fixpoint-typeₓ) $ parameters-to-tpapps ps $ mtpvar data-functorₓ) (parameters-to-apps ps $ mvar data-fmapₓ) ctr-cmd : ctr → defTermOrType ctr-cmd (Ctr x' T) with decompose-ctr-type Γ (subst Γ (parameters-to-tpapps ps $ mtpvar x) x T) ...| Tₕ , ps' , as' = DefTerm posinfo-gen x' NoType $ parameters-to-lams ps $ parameters-to-lams ps' $ mapp (recompose-apps Erased (take (length as' ∸ length ps) as') $ mappe (AppTp (mvar fixpoint-inₓ) $ parameters-to-tpapps ps $ mtpvar data-functorₓ) $ parameters-to-apps ps $ mvar data-fmapₓ) $ rename "X" from add-parameters-to-ctxt ps' Γ for λ Xₓ → mk-ctr-term NotErased x' Xₓ cs ps'
{ "alphanum_fraction": 0.6321583179, "avg_line_length": 43.2352941176, "ext": "agda", "hexsha": "5d12fbf8d2056eb1b52522e6d6ae3e6c2a46ba7a", "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/elaboration-helpers.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/elaboration-helpers.agda", "max_line_length": 124, "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/elaboration-helpers.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 11541, "size": 32340 }
open import Function using (const; id) open import Auto.Core using (IsHintDB; simpleHintDB; Rules; Rule; name2rule) open import Data.List using ([]; [_]; _++_) open import Data.Nat using (ℕ) open import Data.Product using (_,_) open import Data.Sum using (inj₁; inj₂) open import Reflection using (Name; Term; TC) module Auto where open import Auto.Extensible simpleHintDB public renaming (auto to auto′) auto : ℕ → HintDB → Term → TC Term auto = auto′ dfs macro autoMacro = auto
{ "alphanum_fraction": 0.7075098814, "avg_line_length": 28.1111111111, "ext": "agda", "hexsha": "1afb832a9857e1dcc9fdb6381c6eb24d0e74368e", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2019-07-07T07:37:07.000Z", "max_forks_repo_forks_event_min_datetime": "2018-07-10T10:47:30.000Z", "max_forks_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "wenkokke/AutoInAgda", "max_forks_repo_path": "src/Auto.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716", "max_issues_repo_issues_event_max_datetime": "2017-11-06T16:49:27.000Z", "max_issues_repo_issues_event_min_datetime": "2017-11-03T09:46:19.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "wenkokke/AutoInAgda", "max_issues_repo_path": "src/Auto.agda", "max_line_length": 79, "max_stars_count": 22, "max_stars_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "wenkokke/AutoInAgda", "max_stars_repo_path": "src/Auto.agda", "max_stars_repo_stars_event_max_datetime": "2021-03-20T15:04:47.000Z", "max_stars_repo_stars_event_min_datetime": "2017-07-18T18:14:09.000Z", "num_tokens": 137, "size": 506 }
{-# OPTIONS --allow-unsolved-metas #-} module Term where open import OscarPrelude open import VariableName open import FunctionName open import Arity open import Vector mutual data Term : Set where variable : VariableName → Term function : FunctionName → Terms → Term record Terms : Set where constructor ⟨_⟩ inductive field {arity} : Arity terms : Vector Term arity open Terms public termVariable-inj : ∀ {𝑥₁ 𝑥₂} → Term.variable 𝑥₁ ≡ variable 𝑥₂ → 𝑥₁ ≡ 𝑥₂ termVariable-inj refl = refl termFunction-inj₁ : ∀ {𝑓₁ 𝑓₂ τ₁s τ₂s} → Term.function 𝑓₁ τ₁s ≡ function 𝑓₂ τ₂s → 𝑓₁ ≡ 𝑓₂ termFunction-inj₁ refl = refl termFunction-inj₂ : ∀ {𝑓₁ 𝑓₂ τ₁s τ₂s} → Term.function 𝑓₁ τ₁s ≡ function 𝑓₂ τ₂s → τ₁s ≡ τ₂s termFunction-inj₂ refl = refl terms-inj : ∀ {𝑎} → {τs₁ τs₂ : Vector Term 𝑎} → (τs₁≡τs₂ : (Terms.⟨_⟩ {𝑎} τs₁) ≡ ⟨ τs₂ ⟩) → τs₁ ≡ τs₂ terms-inj refl = refl module _ where open import TermByFunctionNames mutual termToTermByFunctionNames : Term → Σ Nat TermByFunctionNames termToTermByFunctionNames (variable x) = _ , (variable x) termToTermByFunctionNames (function x x₁) = {!!} termsToVec : Terms → Σ Nat (λ arity → Σ (Vec (Σ Nat TermByFunctionNames) arity) λ τs → Σ Nat λ n → n ≡ sum (vecToList $ (fst <$> τs))) termsToVec (⟨_⟩ {arity = arity₁} ⟨ vector₁ ⟩) = {!!} iTermToTerm : Σ Nat TermByFunctionNames → Term iTermToTerm = {!!} eq-term-round : ∀ τ → iTermToTerm (termToTermByFunctionNames τ) ≡ τ eq-term-round = {!!} eq-iterm-round : ∀ τ → termToTermByFunctionNames (iTermToTerm τ) ≡ τ eq-iterm-round = {!!} instance EqTerm : Eq Term Eq._==_ EqTerm x y with termToTermByFunctionNames x | graphAt termToTermByFunctionNames x | termToTermByFunctionNames y | graphAt termToTermByFunctionNames y Eq._==_ EqTerm x y | ix | ingraph eqx | iy | ingraph eqy with ix ≟ iy Eq._==_ EqTerm x y | ix | ingraph eqx | .ix | ingraph eqy | yes refl = yes $ ((cong iTermToTerm eqy ⟨≡⟩ʳ cong iTermToTerm eqx) ⟨≡⟩ eq-term-round x) ʳ⟨≡⟩ eq-term-round y Eq._==_ EqTerm x y | ix | ingraph eqx | iy | ingraph eqy | no neq = {!!} instance EqTerms : Eq Terms EqTerms = {!!} {- module _ {i : Size} where mutual EqTerm⇑ : (x y : Term) → Delay i ∘ Dec $ x ≡ y EqTerm⇑ (variable _) (variable _) = now (decEq₁ termVariable-inj $ _≟_ _ _) EqTerm⇑ (function 𝑓₁ τ₁s) (function 𝑓₂ τ₂s) = {- τ₁s≟τ₂s ← EqTerms⇑ τ₁s τ₂s -| (now $ decEq₂ termFunction-inj₁ termFunction-inj₂ (𝑓₁ ≟ 𝑓₂) τ₁s≟τ₂s) -} EqTerms⇑ τ₁s τ₂s >>= λ τ₁s≟τ₂s → now $ decEq₂ termFunction-inj₁ termFunction-inj₂ (𝑓₁ ≟ 𝑓₂) τ₁s≟τ₂s EqTerm⇑ (variable _) (function _ _) = now $ no λ () EqTerm⇑ (function _ _) (variable _) = now $ no λ () EqTerms⇑ : (x y : Terms) → Delay i ∘ Dec $ x ≡ y EqTerms⇑ (⟨_⟩ {𝑎₁} τ₁s) (⟨_⟩ {𝑎₂} τ₂s) with 𝑎₁ ≟ 𝑎₂ … | no 𝑎₁≢𝑎₂ = now $ no λ {τ₁≡τ₂ → 𝑎₁≢𝑎₂ (cong arity τ₁≡τ₂)} … | yes refl = EqVectorTerm⇑ τ₁s τ₂s >>= λ { (yes refl) → now $ yes refl ; (no τ₁s≢τ₂s) → now $ no (λ ⟨τ₁s⟩≡⟨τ₂s⟩ → τ₁s≢τ₂s (terms-inj ⟨τ₁s⟩≡⟨τ₂s⟩)) } EqVectorTerm⇑ : ∀ {n} → (x y : Vector Term n) → Delay i ∘ Dec $ x ≡ y EqVectorTerm⇑ ⟨ [] ⟩ ⟨ [] ⟩ = now (yes refl) EqVectorTerm⇑ ⟨ τ₁ ∷ τ₁s ⟩ ⟨ τ₂ ∷ τ₂s ⟩ = EqTerm⇑ τ₁ τ₂ >>= λ { (yes refl) → EqVectorTerm⇑ ⟨ τ₁s ⟩ ⟨ τ₂s ⟩ >>= λ { (yes refl) → now $ yes refl ; (no τ₁s≢τ₂s) → now $ no λ τ₁₁s≡τ₁₂s → τ₁s≢τ₂s $ cong ⟨_⟩ ((vcons-inj-tail (cong vector τ₁₁s≡τ₁₂s))) } ; (no τ₁≢τ₂) → now $ no λ τ₁₁s≡τ₂₂s → τ₁≢τ₂ $ vcons-inj-head (cong vector τ₁₁s≡τ₂₂s) } EqVectorTerm⇓ : ∀ {n} → (x y : Vector Term n) → EqVectorTerm⇑ x y ⇓ EqVectorTerm⇓ ⟨ [] ⟩ ⟨ [] ⟩ = _ , now⇓ EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable 𝑥₂ ∷ τ₂s ⟩ with 𝑥₁ ≟ 𝑥₂ … | yes refl with EqVectorTerm⇓ ⟨ τ₁s ⟩ ⟨ τ₂s ⟩ EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable .𝑥₁ ∷ .τ₁s ⟩ | yes refl | (yes refl , snd₁) = _ , snd₁ >>=⇓ now⇓ EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable .𝑥₁ ∷ τ₂s ⟩ | yes refl | (no x , snd₁) = _ , snd₁ >>=⇓ now⇓ EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable 𝑥₂ ∷ τ₂s ⟩ | no 𝑥₁≢𝑥₂ = _ , now⇓ EqVectorTerm⇓ ⟨ variable x ∷ τ₁s ⟩ ⟨ function x₁ x₂ ∷ τ₂s ⟩ = _ , now⇓ EqVectorTerm⇓ ⟨ function x x₁ ∷ τ₁s ⟩ ⟨ variable x₂ ∷ τ₂s ⟩ = _ , now⇓ EqVectorTerm⇓ ⟨ function 𝑓₁ (⟨_⟩ {𝑎₁} τ₁s) ∷ τ₁₂s ⟩ ⟨ function 𝑓₂ (⟨_⟩ {𝑎₂} τ₂s) ∷ τ₂₂s ⟩ with 𝑎₁ ≟ 𝑎₂ | 𝑓₁ ≟ 𝑓₂ … | no 𝑎₁≢𝑎₂ | no 𝑓₁≢𝑓₂ = _ , now⇓ … | no 𝑎₁≢𝑎₂ | yes refl = _ , now⇓ … | yes refl | no 𝑓₁≢𝑓₂ with EqVectorTerm⇓ τ₁s τ₂s … | (no τ₁s≢τ₂s , τ⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓ … | (yes refl , τ⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓ EqVectorTerm⇓ ⟨ function 𝑓₁ (⟨_⟩ {𝑎₁} τ₁s) ∷ τ₁₂s ⟩ ⟨ function 𝑓₂ (⟨_⟩ {𝑎₂} τ₂s) ∷ τ₂₂s ⟩ | yes refl | yes refl with EqVectorTerm⇓ τ₁s τ₂s | EqVectorTerm⇓ ⟨ τ₁₂s ⟩ ⟨ τ₂₂s ⟩ … | (no τ₁s≢τ₂s , τ⇓) | (no τ₁₂s≢τ₂₂s , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓ … | (yes refl , τ⇓) | (no τ₁₂s≢τ₂₂s , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ (τs⇓ >>=⇓ now⇓) … | (no τ₁s≢τ₂s , τ⇓) | (yes refl , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓ … | (yes refl , τ⇓) | (yes refl , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ (τs⇓ >>=⇓ now⇓) EqTerms⇓ : (x y : Terms) → EqTerms⇑ x y ⇓ EqTerms⇓ (⟨_⟩ {𝑎₁} τ₁s) (⟨_⟩ {𝑎₂} τ₂s) with 𝑎₁ ≟ 𝑎₂ … | no 𝑎₁≢𝑎₂ = _ , now⇓ … | yes refl with EqVectorTerm⇓ τ₁s τ₂s … | (yes refl , τ⇓) = _ , τ⇓ >>=⇓ now⇓ … | (no _ , τ⇓) = _ , τ⇓ >>=⇓ now⇓ EqTerm⇓ : (x y : Term) → EqTerm⇑ x y ⇓ EqTerm⇓ (variable x) (variable x₁) = _ , now⇓ EqTerm⇓ (function _ τ₁s) (function _ τ₂s) with EqTerms⇓ τ₁s τ₂s … | (_ , τ⇓) = _ , τ⇓ >>=⇓ now⇓ EqTerm⇓ (variable x) (function x₁ x₂) = _ , now⇓ EqTerm⇓ (function x x₁) (variable x₂) = _ , now⇓ instance EqTerm : Eq Term EqTerm = record { _==_ = λ x y → fst (EqTerm⇓ x y) } instance EqTerms : Eq Terms Eq._==_ EqTerms x y = fst (EqTerms⇓ x y) -} module _ where open import Membership instance MembershipTermTerms : Membership Term Terms Membership._∈_ MembershipTermTerms = _ᵗ∈ᵗˢ_ where data _ᵗ∈ᵗˢ_ (τ : Term) : Terms → Set where zero : τ ᵗ∈ᵗˢ ⟨ ⟨ τ ∷ [] ⟩ ⟩ suc : ∀ {τs} → τ ᵗ∈ᵗˢ τs → τ ᵗ∈ᵗˢ ⟨ ⟨ τ ∷ vector (terms τs) ⟩ ⟩ Membership._∉_ MembershipTermTerms x X = ¬ x ∈ X fst (Membership.xor-membership MembershipTermTerms) x₁ x₂ = x₂ x₁ snd (Membership.xor-membership MembershipTermTerms) x₁ x₂ = x₁ x₂ instance MembershipVariableNameTerm : Membership VariableName Term Membership._∈_ MembershipVariableNameTerm = _ᵛ∈ᵗ_ where data _ᵛ∈ᵗ_ (𝑥 : VariableName) : Term → Set where variable : 𝑥 ᵛ∈ᵗ variable 𝑥 function : ∀ 𝑓 {τ : Term} {τs} → {_ : 𝑥 ∈ τ} → τ ∈ τs → 𝑥 ᵛ∈ᵗ function 𝑓 τs Membership._∉_ MembershipVariableNameTerm x X = ¬ x ∈ X fst (Membership.xor-membership MembershipVariableNameTerm) x₁ x₂ = x₂ x₁ snd (Membership.xor-membership MembershipVariableNameTerm) x₁ x₂ = x₁ x₂ module _ where import UnifyTermL import UnifyMguCorrectL module L where open UnifyTermL (Maybe FunctionName) public open UnifyMguCorrectL (Maybe FunctionName) public mutual TermLtoTerm : ∃ L.Term → Term TermLtoTerm (fst₁ , UnifyTermL.i x) = {!!} TermLtoTerm (fst₁ , UnifyTermL.leaf nothing) = {!!} TermLtoTerm (fst₁ , UnifyTermL.leaf (just x)) = {!!} TermLtoTerm (fst₁ , (snd₁ UnifyTermL.fork snd₂)) = {!!} TermtoTermL : Term → ∃ L.Term TermtoTermL (variable x) = {!!} , (L.i {!!}) TermtoTermL (function x ⟨ ⟨ [] ⟩ ⟩) = {!!} , L.leaf (just x) L.fork L.leaf nothing TermtoTermL (function x ⟨ ⟨ x₁ ∷ vector₁ ⟩ ⟩) = {!!} , {!!} L.fork {!!}
{ "alphanum_fraction": 0.5955804047, "avg_line_length": 37.56, "ext": "agda", "hexsha": "ffb1119f06386846e8b7cf3750b7a0e8ec03acc4", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-1/Term.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-1/Term.agda", "max_line_length": 168, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-1/Term.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3567, "size": 7512 }
module PLRTree.Equality.Properties {A : Set} where open import PLRTree {A} open import PLRTree.Equality {A} open import Relation.Binary.Core sym≃ : Symmetric _≃_ sym≃ ≃lf = ≃lf sym≃ (≃nd x x' l≃r l'≃r' l≃l') = ≃nd x' x l'≃r' l≃r (sym≃ l≃l') trans≃ : Transitive _≃_ trans≃ ≃lf t≃t'' = t≃t'' trans≃ (≃nd x x' l≃r l'≃r' l≃l') (≃nd .x' x'' _ l''≃r'' l'≃r'') = ≃nd x x'' l≃r l''≃r'' (trans≃ l≃l' l'≃r'') lemma-≃-≃ : {t t' : PLRTree} → t ≃ t' → t ≃ t lemma-≃-≃ ≃lf = ≃lf lemma-≃-≃ (≃nd x x' l≃r l≃r' l≃l') = ≃nd x x l≃r l≃r (lemma-≃-≃ l≃l')
{ "alphanum_fraction": 0.5277777778, "avg_line_length": 28.4210526316, "ext": "agda", "hexsha": "5b72d481d8113fe34451fb4d5ee38fe67d30c746", "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/Equality/Properties.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/Equality/Properties.agda", "max_line_length": 108, "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/Equality/Properties.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": 317, "size": 540 }
module Generic.Test.Data.Fin where open import Generic.Main import Data.Fin as Fin Fin : ℕ -> Set Fin = readData Fin.Fin pattern fzero {n} = #₀ (relv n , lrefl) pattern fsuc {n} i = !#₁ (relv n , i , lrefl) elimFin : ∀ {n π} -> (P : ∀ {n} -> Fin n -> Set π) -> (∀ {n} {i : Fin n} -> P i -> P (fsuc i)) -> (∀ {n} -> P {suc n} fzero) -> (i : Fin n) -> P i elimFin P f x fzero = x elimFin P f x (fsuc i) = f (elimFin P f x i)
{ "alphanum_fraction": 0.4947368421, "avg_line_length": 22.619047619, "ext": "agda", "hexsha": "6d634387d59ec696c957d2a17f400e44aaffe1ad", "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/Data/Fin.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/Data/Fin.agda", "max_line_length": 51, "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/Data/Fin.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": 186, "size": 475 }
module Data.Nat.Literal where open import Data.Nat using (ℕ; suc; zero) open import Data.Fin using (Fin; suc; zero) open import Data.Unit using (⊤) open import Data.Empty using (⊥) open import Agda.Builtin.FromNat using (Number; fromNat) public _≤_ : ℕ → ℕ → Set zero ≤ n = ⊤ suc m ≤ zero = ⊥ suc m ≤ suc n = m ≤ n instance ℕ-num : Number ℕ ℕ-num .Number.Constraint _ = ⊤ ℕ-num .Number.fromNat n = n instance Fin-num : {n : ℕ} → Number (Fin (suc n)) Fin-num {n} .Number.Constraint m = m ≤ n Fin-num {n} .Number.fromNat m ⦃ p ⦄ = from m n p where from : (m n : ℕ) → m ≤ n → Fin (suc n) from zero _ _ = zero from (suc _) zero () from (suc m) (suc n) p = suc (from m n p)
{ "alphanum_fraction": 0.6067892504, "avg_line_length": 26.1851851852, "ext": "agda", "hexsha": "df010b3202fe630f912cd06312b3416397d508af", "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": "9f5129d97ee7b89fb8e43136779a78806b7506ab", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "brunoczim/Celeste", "max_forks_repo_path": "formalization/Data/Nat/Literal.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9f5129d97ee7b89fb8e43136779a78806b7506ab", "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": "brunoczim/Celeste", "max_issues_repo_path": "formalization/Data/Nat/Literal.agda", "max_line_length": 63, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9f5129d97ee7b89fb8e43136779a78806b7506ab", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "brunoczim/Celeste", "max_stars_repo_path": "formalization/Data/Nat/Literal.agda", "max_stars_repo_stars_event_max_datetime": "2020-09-16T17:31:57.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-16T17:31:57.000Z", "num_tokens": 261, "size": 707 }
{-# OPTIONS --without-K #-} module higher where open import higher.circle public
{ "alphanum_fraction": 0.7228915663, "avg_line_length": 13.8333333333, "ext": "agda", "hexsha": "edf922c966d7704dafcdd9f95425a4e95130fd06", "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/higher.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/higher.agda", "max_line_length": 32, "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/higher.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": 16, "size": 83 }
open import Prelude hiding (All; module All; _>>=_; ⊥; sym) module Implicits.Resolution.Infinite.Algorithm.Completeness where open import Data.Bool open import Data.Unit.Base open import Data.Maybe as Maybe using (Is-just; to-witness) open import Coinduction open import Data.Fin.Substitution open import Data.List.Any hiding (tail) open Membership-≡ open import Data.Fin.Substitution open import Relation.Binary.HeterogeneousEquality as H using () open import Induction.WellFounded open import Implicits.Syntax open import Implicits.Substitutions open import Implicits.Substitutions.Lemmas.MetaType open import Implicits.Syntax.Type.Unification open import Implicits.Syntax.Type.Unification.Lemmas as Unification hiding (complete) open import Implicits.Resolution.Infinite.Resolution open import Implicits.Resolution.Infinite.Algorithm open import Implicits.Resolution.Termination private module HR = H.≅-Reasoning open import Category.Monad.Partiality as P open Workaround open Workaround.Correct open import Category.Monad.Partiality.All using (All; module Alternative) open Alternative renaming (sound to AllP-sound) hiding (complete) open import Category.Functor private module MaybeFunctor {f} = RawFunctor (Maybe.functor {f}) private module M = MetaTypeMetaSubst module Lemmas where private open import Relation.Binary.PropositionalEquality as PEq using (_≡_) open module PartialEq = P.Equality {A = Bool} _≡_ open Lemmas mutual {-# NO_TERMINATION_CHECK #-} delayed-resolve-complete : ∀ {ν} (Δ : ICtx ν) r → Δ ⊢ᵣ r → AllP (_≡_ true) (delayed-resolve Δ r) delayed-resolve-complete Δ r p = later (♯ (complete' Δ r p)) resolve-context-complete : ∀ {ν m} (Δ : ICtx ν) a (u : Maybe (Sub (flip MetaType ν) m zero)) → (p : Is-just u) → Δ ⊢ᵣ (from-meta (a M./ (to-witness p))) → AllP Is-just (resolve-context Δ a u) resolve-context-complete Δ a ._ (just {x = u} px) x = _ ≅⟨ resolve-context-comp Δ a u ⟩P delayed-resolve-complete Δ (from-meta (M._/_ a u)) x >>=-congP lem where lem : ∀ {b} → true ≡ b → AllP Is-just (map-bool u b) lem refl = now (just tt) lemx : ∀ {ν m} {Δ : ICtx ν} r c τ (u : M.MetaSub MetaType ν m zero) → Δ ⊢ from-meta (r M./ u M.↑tp) tp[/tp c ] ↓ τ → Δ ⊢ from-meta (open-meta r M./ (to-meta c ∷ u)) ↓ τ lemx r c τ u p = {!!} a/u-↓-unique : ∀ {ν m} {Δ} (a : MetaType m ν) {τ} u v → Δ ⊢ from-meta (a M./ u) ↓ τ → Δ ⊢ from-meta (a M./ v) ↓ τ → (a M./ u) ≡ (a M./ v) a/u-↓-unique (a ⇒ b) u v (i-iabs _ p) (i-iabs _ q) = {!a/u-↓-unique b u v p q!} a/u-↓-unique (∀' a) u v p q = {!!} a/u-↓-unique (simpl x) u v p q = {!!} match-u-complete' : ∀ {ν m} (Δ : ICtx ν) → (τ : SimpleType ν) → (r : MetaType m ν) → (ac : m<-Acc r) → ∀ u → Δ ⊢ from-meta (r M./ u) ↓ τ → AllP Is-just (match-u Δ τ r ac) match-u-complete' Δ τ (a ⇒ b) (acc f) u (i-iabs q p) = _ ≅⟨ match-u-iabs-comp Δ τ a b f ⟩P match-u-complete' Δ τ b (f _ (b-m<-a⇒b a b)) u p >>=-congP lem where lem : ∀ {v : Maybe (Sub (flip MetaType _) _ zero)} → Is-just v → AllP Is-just (resolve-context Δ a v) lem x = resolve-context-complete Δ a _ x q' where -- from q : Δ ⊢ᵣ a / u -- we derive q' : Δ ⊢ᵣ a / x -- based on the idea that we have Δ ⊢ b / u ↓ τ and -- soundness gives us Δ ⊢ b / (to-witness x) ↓ τ. -- And assuming ⊢unamb b, we should have u ≡ (to-witness x) q' : Δ ⊢ᵣ from-meta (a M./ to-witness x ) q' = subst (_⊢ᵣ_ Δ) {!!} q match-u-complete' {m = m} Δ τ (∀' r) (acc f) u (i-tabs c p) = _ ≅⟨ match-u-tabs-comp Δ τ r f ⟩P (match-u-complete' Δ τ (open-meta r) (f _ _) (to-meta {zero} c ∷ u) (lemx r c τ u p)) >>=-congP now∘tail-compl where now∘tail-compl : ∀ {ν} {v : Maybe (Sub (flip MetaType ν) (suc m) zero)} → Is-just v → AllP Is-just ((now ∘ (MaybeFunctor._<$>_ tail)) v) now∘tail-compl (just px) = now (just tt) -- Maybe surprisingly 'u' is ignored in the proofs below. -- But if you think about it, it makes sense: mgu doesn't necessarily find the same unifier. -- All we need to know is that there is a unifier u; the structure of Δ ⊢ (a / u) ↓ τ does the rest match-u-complete' Δ .(tvar x) (simpl (tvar x)) ac u (i-simp .(tvar x)) = now (Unification.complete (simpl (tvar x)) (tvar x) u refl) match-u-complete' Δ .(tc x) (simpl (tc x)) ac u (i-simp .(tc x)) = now (Unification.complete (simpl (tc x)) (tc x) u refl) match-u-complete' Δ τ (simpl (mvar x)) ac u p = let (u' , u'-uni) = mvar-unifiable x τ in now (Unification.complete (simpl (mvar x)) τ u' u'-uni) match-u-complete' Δ ._ (simpl (a →' b)) ac u (i-simp ._) = now (Unification.complete (simpl (a →' b)) _ u refl) -- the trivial predicate holds for all terminating problems trivial-allP : ∀ {a} {A : Set a} (a : A ⊥) → AllP (const ⊤) a trivial-allP (now x) = now tt trivial-allP (later x) = later (♯ (trivial-allP (♭ x))) -- Match succeeds if we have a proof Δ ⊢ r ↓ τ match-complete : ∀ {ν} (Δ : ICtx ν) → (τ : SimpleType ν) → (r : Type ν) → Δ ⊢ r ↓ τ → AllP (_≡_ true) (match Δ τ r) match-complete Δ τ r p = _ ≅⟨ match-comp Δ τ r ⟩P match-u-complete' Δ τ (to-meta {zero} r) (m<-well-founded _) [] (subst (λ z → Δ ⊢ z ↓ τ) (Prelude.sym $ from-to-meta-/-vanishes) p) >>=-congP lem where lem : ∀ {ν} {v : Maybe (Sub (flip MetaType ν) zero zero)} → (Is-just v) → AllP (_≡_ true) (⟦ (now ∘ Maybe.is-just) v ⟧P) lem (just tt) = now refl -- 'recovery' of a non failed match succeeds recover-true-complete : ∀ {ν} {Δ : ICtx ν} {ρs τ v} → v ≡ true → AllP (_≡_ true) (match1st-recover Δ ρs τ v) recover-true-complete refl = now refl -- recovery of a failed match succeeds if we know that the recursive match1st succeeds recover-false-complete : ∀ {ν} (Δ : ICtx ν) ρs τ v → AllP (_≡_ true) (match1st Δ ρs τ) → AllP (_≡_ true) (match1st-recover Δ ρs τ v) recover-false-complete Δ ρs τ true p = now refl recover-false-complete Δ ρs τ false p = p -- match1st succeeds if we have a proof that some r from the context -- should be a match match1st-complete : ∀ {ν} (Δ : ICtx ν) {r} → (ρs : ICtx ν) → (τ : SimpleType ν) → r List.∈ ρs → Δ ⊢ r ↓ τ → AllP (_≡_ true) (match1st Δ ρs τ) match1st-complete Δ List.[] τ () r↓τ match1st-complete Δ (x List.∷ ρs) τ (here refl) r↓τ = _ ≅⟨ match1st-comp Δ x ρs τ ⟩P match-complete Δ τ x r↓τ >>=-congP (λ{ v → recover-true-complete (Prelude.sym v)}) match1st-complete Δ (x List.∷ ρs) τ (there r∈Δ) r↓τ = _ ≅⟨ match1st-comp Δ x ρs τ ⟩P ((trivial-allP (match Δ τ x)) >>=-congP (λ {v} _ → recover-false-complete Δ ρs τ v (match1st-complete Δ ρs τ r∈Δ r↓τ))) -- Mirroring Abel & Altenkirch's work on partial type checking, we say: -- Because resolution without an additional termination condition -- seems to be undecidable, an appropriate completeness result would be: -- if Δ resolves r, then the resolution algorithm searching for a proof of that fact, -- will not fail finetely. I.e. the algorithm might diverge or succeed, but not report an error. -- We can make this formal using the *coinductive* resolution rules -- (Together with soundness we have a 'minimal' completeness result, because the rules allow -- for many derivations, while the algorithm will only find *one*.) complete' : ∀ {ν} (Δ : ICtx ν) r → Δ ⊢ᵣ r → AllP (_≡_ true) (resolve Δ r) complete' Δ (simpl x) (r-simp r∈Δ r↓τ) = (match1st-complete Δ Δ x r∈Δ r↓τ) complete' Δ (a ⇒ b) (r-iabs p) = complete' (a List.∷ Δ) b p complete' Δ (∀' r) (r-tabs p) = complete' (ictx-weaken Δ) r p complete : ∀ {ν} (Δ : ICtx ν) r → Δ ⊢ᵣ r → All (_≡_ true) (resolve Δ r) complete Δ r p = AllP-sound (complete' Δ r p) module Test where open import Category.Monad.Partiality.All trivial-all : ∀ {a p} {A : Set a} (P : A → Set p) → All P never trivial-all p = later (♯ (trivial-all p))
{ "alphanum_fraction": 0.5971084337, "avg_line_length": 44.385026738, "ext": "agda", "hexsha": "faa9e9d0ab1a87569f59097855540ebb44a403d1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "metaborg/ts.agda", "max_forks_repo_path": "src/Implicits/Resolution/Infinite/Algorithm/Completeness.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "metaborg/ts.agda", "max_issues_repo_path": "src/Implicits/Resolution/Infinite/Algorithm/Completeness.agda", "max_line_length": 104, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_path": "src/Implicits/Resolution/Infinite/Algorithm/Completeness.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z", "max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z", "num_tokens": 2856, "size": 8300 }
{-# OPTIONS --universe-polymorphism #-} module Categories.Support.Equivalence where open import Level open import Relation.Binary using (Rel; IsEquivalence; module IsEquivalence; IsPreorder; Preorder; Reflexive; Transitive; Symmetric; _⇒_) renaming (Setoid to RSetoid; module Setoid to RSetoid) open import Data.Product using (_×_; _,_) open import Relation.Binary.Product.Pointwise using (×-isEquivalence) open import Relation.Binary.PropositionalEquality as PropEq using (_≡_) ------------------------------------------------------------------------ -- Setoids -- Equivalence relations are defined in Relation.Binary.Core. record Setoid c ℓ : Set (suc (c ⊔ ℓ)) where infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ .isEquivalence : IsEquivalence _≈_ .refl : Reflexive _≈_ refl = IsEquivalence.refl isEquivalence .trans : Transitive _≈_ trans = IsEquivalence.trans isEquivalence .sym : Symmetric _≈_ sym = IsEquivalence.sym isEquivalence .reflexive : _≡_ ⇒ _≈_ reflexive = IsEquivalence.reflexive isEquivalence .isPreorder : IsPreorder _≡_ _≈_ isPreorder = record { isEquivalence = PropEq.isEquivalence ; reflexive = reflexive ; trans = trans } .preorder : Preorder c c ℓ preorder = record { isPreorder = isPreorder } -- A trivially indexed setoid. {- indexedSetoid : ∀ {i} {I : Set i} → I.Setoid I c _ indexedSetoid = record { Carrier = λ _ → Carrier ; _≈_ = _≈_ ; isEquivalence = record { refl = refl ; sym = sym ; trans = trans } } -} setoid-r→i : ∀ {c ℓ} → RSetoid c ℓ → Setoid c ℓ setoid-r→i Base = record { Carrier = Base.Carrier ; _≈_ = Base._≈_ ; isEquivalence = Base.isEquivalence } where module Base = RSetoid Base record I→R-Wrapper {c ℓ} {Carrier : Set c} (Base : Rel Carrier ℓ) (x y : Carrier) : Set ℓ where constructor squash field .anonymous-witness : Base x y setoid-i→r : ∀ {c ℓ} → Setoid c ℓ → RSetoid c ℓ setoid-i→r Base = record { Carrier = Base.Carrier ; _≈_ = I→R-Wrapper Base._≈_ ; isEquivalence = record { refl = squash Base.refl ; sym = λ pf → squash (Base.sym (anonymous-witness pf)) ; trans = λ i≈j j≈k → squash (Base.trans (anonymous-witness i≈j) (anonymous-witness j≈k)) } } where module Base = Setoid Base open I→R-Wrapper set→setoid : ∀ {ℓ} → Set ℓ → Setoid ℓ ℓ set→setoid Base = record { Carrier = Base ; _≈_ = _≡_ ; isEquivalence = PropEq.isEquivalence } _×-setoid_ : ∀ {s₁ s₂ s₃ s₄} → Setoid s₁ s₂ → Setoid s₃ s₄ → Setoid _ _ S₁ ×-setoid S₂ = record { isEquivalence = ×-isEquivalence (isEquivalence S₁) (isEquivalence S₂) } where open Setoid Lift-setoid : ∀ {c ℓ a b} -> Setoid c ℓ -> Setoid (c ⊔ a) (ℓ ⊔ b) Lift-setoid {c} {ℓ} {a} {b} s = record { Carrier = Lift {c} a Carrier; _≈_ = λ x₁ x₂ → Lift {ℓ} b (lower x₁ ≈ lower x₂); isEquivalence = record { refl = lift refl; sym = λ x₁ → lift (sym (lower x₁)); trans = λ x₁ x₂ → lift (trans (lower x₁) (lower x₂))}} where open Setoid s ∀[_]-setoid_ : ∀ {ℓ s₁ s₂} → (A : Set ℓ) → (A → Setoid s₁ s₂) → Setoid _ _ ∀[ A ]-setoid B = record { Carrier = ∀ a → B.Carrier a ; _≈_ = λ f g → ∀ a → B._≈_ a (f a) (g a) ; isEquivalence = record { refl = λ a → B.refl a ; sym = λ f≈g a → B.sym a (f≈g a) ; trans = λ f≈g g≈h a → B.trans a (f≈g a) (g≈h a) } } where module B a = Setoid (B a) Fam-setoid : ∀ {ℓ s₁ s₂} → (A : Set ℓ) → (B : Setoid s₁ s₂) → (A → Setoid.Carrier B) → Setoid _ _ Fam-setoid A B p = record { Carrier = A ; _≈_ = λ a₁ a₂ → p a₁ ≈ p a₂ ; isEquivalence = record { refl = refl ; sym = sym ; trans = trans } } where open Setoid B
{ "alphanum_fraction": 0.5989901674, "avg_line_length": 28.7251908397, "ext": "agda", "hexsha": "4f30c8abeed60d03a5a18115cf2d7bad5786377c", "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": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "p-pavel/categories", "max_forks_repo_path": "Categories/Support/Equivalence.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "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": "p-pavel/categories", "max_issues_repo_path": "Categories/Support/Equivalence.agda", "max_line_length": 192, "max_stars_count": 1, "max_stars_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "p-pavel/categories", "max_stars_repo_path": "Categories/Support/Equivalence.agda", "max_stars_repo_stars_event_max_datetime": "2018-12-29T21:51:57.000Z", "max_stars_repo_stars_event_min_datetime": "2018-12-29T21:51:57.000Z", "num_tokens": 1362, "size": 3763 }
-- Andreas, 2015-06-24 open import Common.Equality open import Common.Product Sing : {A : Set} (a : A) → Set Sing a = ∃ λ b → a ≡ b works : {A : Set} (f : ∀{a : A} → Sing a) (a : A) → Sing a works f a = let b , p = f {_} in b , p test : {A : Set} (f : ∀{a : A} → Sing a) (a : A) → Sing a test f a = let b , p = f in b , p -- ERROR WAS: -- Type mismatch -- when checking that the pattern b , p has type -- {a = a₁ : .A} → Sing a₁ -- should work now
{ "alphanum_fraction": 0.5352422907, "avg_line_length": 21.619047619, "ext": "agda", "hexsha": "0e53000a716987c45387117c5f4d1b8e68f90007", "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/Issue1584.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/Issue1584.agda", "max_line_length": 58, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue1584.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": 180, "size": 454 }
------------------------------------------------------------------------ -- The Agda standard library -- -- The Pair type which calls out to Haskell via the FFI ------------------------------------------------------------------------ {-# OPTIONS --without-K #-} module Foreign.Haskell.Pair where open import Level open import Data.Product using (_×_; _,_) private variable a b : Level A : Set a B : Set b ------------------------------------------------------------------------ -- Definition record Pair (A : Set a) (B : Set b) : Set (a ⊔ b) where constructor _,_ field fst : A snd : B open Pair public {-# FOREIGN GHC type AgdaPair l1 l2 a b = (a , b) #-} {-# COMPILE GHC Pair = data MAlonzo.Code.Foreign.Haskell.Pair.AgdaPair ((,)) #-} ------------------------------------------------------------------------ -- Conversion toForeign : A × B → Pair A B toForeign (a , b) = (a , b) fromForeign : Pair A B → A × B fromForeign (a , b) = (a , b)
{ "alphanum_fraction": 0.4322120285, "avg_line_length": 24.525, "ext": "agda", "hexsha": "078e02db5baa3e1410623a124d3bebcca2214a77", "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/Foreign/Haskell/Pair.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/Foreign/Haskell/Pair.agda", "max_line_length": 80, "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/Foreign/Haskell/Pair.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": 225, "size": 981 }
{-# OPTIONS --cubical-compatible #-} module Common.String where open import Agda.Builtin.String public open import Common.Bool open import Common.Char open import Common.List open import Common.Nat open import Common.Integer strEq : (x y : String) -> Bool strEq = primStringEquality infixr 30 _+S+_ _+S+_ : (x y : String) -> String _+S+_ = primStringAppend fromList : List Char -> String fromList = primStringFromList stringToList : String -> List Char stringToList = primStringToList charToStr : Char → String charToStr c = primStringFromList (c ∷ []) intToString : Integer → String intToString = primShowInteger natToString : Nat -> String natToString n = intToString (pos n)
{ "alphanum_fraction": 0.7510917031, "avg_line_length": 20.8181818182, "ext": "agda", "hexsha": "04fae8237fdf64d45838c89ebeaacaba30948b04", "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/Common/String.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/Common/String.agda", "max_line_length": 41, "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/Common/String.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 182, "size": 687 }
------------------------------------------------------------------------ -- Generic support for reduction relations. ------------------------------------------------------------------------ module Relation.Binary.Reduction where open import Data.Fin using (Fin) open import Data.Fin.Substitution open import Data.Star as Star using (Star; ε; _◅_) import Data.Star.Properties as StarProp open import Data.Nat using (ℕ; _+_) open import Function using (_∘_) open import Relation.Binary open import Relation.Binary.EquivalenceClosure open import Relation.Binary.SymmetricClosure using (fwd) import Relation.Binary.PropositionalEquality as PropEq import Relation.Binary.EqReasoning as EqReasoning ---------------------------------------------------------------------- -- Generic reduction and equivalence relations record Reduction (T : ℕ → Set) : Set₁ where infix 5 _→1_ _→*_ _↔_ -- One-step reduction. field _→1_ : ∀ {n} → T n → T n → Set -- The reflexive transitive closure of _→1_, i.e. finite sequences -- of reduction steps. _→*_ : ∀ {n} → T n → T n → Set _→*_ = Star _→1_ -- The reflexive, transitive and symmetric closure (aka the -- equivalence closure) of _→1_. _↔_ : ∀ {n} → T n → T n → Set _↔_ = EqClosure _→1_ -- All remaining submodules are parametrized by a given reduction. module _ {T} (reduction : Reduction T) where open Reduction reduction ---------------------------------------------------------------------- -- Properties of the reductions/equivalence -- Inclusions. →1⇒→* : ∀ {n} {a b : T n} → a →1 b → a →* b →1⇒→* a→b = a→b ◅ ε →*⇒↔ : ∀ {n} {a b : T n} → a →* b → a ↔ b →*⇒↔ a→*b = Star.map fwd a→*b →1⇒↔ : ∀ {n} {a b : T n} → a →1 b → a ↔ b →1⇒↔ = →*⇒↔ ∘ →1⇒→* -- Reductions are preorders. →*-predorder : ∀ {n : ℕ} → Preorder _ _ _ →*-predorder {n} = StarProp.preorder (_→1_ {n}) -- Preorder reasoning for reductions. module →*-Reasoning {n} = StarProp.StarReasoning (_→1_ {n}) -- Terms together with equivalence form a setoid. ↔-setoid : ∀ {n : ℕ} → Setoid _ _ ↔-setoid {n} = setoid (_→1_ {n}) -- Equational reasoning for ↔-equivalence. module ↔-Reasoning {n : ℕ} where open EqReasoning (↔-setoid {n}) public open Setoid (↔-setoid {n}) using (sym) infixr 2 _→⟨_⟩_ _←⟨_⟩_ _→*⟨_⟩_ _←*⟨_⟩_ _→⟨_⟩_ : ∀ a {b c} → a →1 b → b IsRelatedTo c → a IsRelatedTo c a →⟨ a→b ⟩ b≡c = a ≈⟨ →1⇒↔ a→b ⟩ b≡c _←⟨_⟩_ : ∀ a {b c} → b →1 a → b IsRelatedTo c → a IsRelatedTo c a ←⟨ a←b ⟩ b≡c = a ≈⟨ sym (→1⇒↔ a←b) ⟩ b≡c _→*⟨_⟩_ : ∀ a {b c} → a →* b → b IsRelatedTo c → a IsRelatedTo c a →*⟨ a→*b ⟩ b≡c = a ≈⟨ →*⇒↔ a→*b ⟩ b≡c _←*⟨_⟩_ : ∀ a {b c} → b →* a → b IsRelatedTo c → a IsRelatedTo c a ←*⟨ a←*b ⟩ b≡c = a ≈⟨ sym (→*⇒↔ a←*b) ⟩ b≡c ---------------------------------------------------------------------- -- Substitutions in reductions/equivalence -- -- The applications _/→1_, _/→*_ and _/↔_ below may be considered -- substitution lemmas, i.e. they establish the commutativity of the -- respective reductions/equivalence with substitutions. record RedSubstApp {T′} (app : Application T T′) : Set where open Application app open PropEq infixl 8 _/→1_ _/→*_ _/↔_ field -- Substitution commutes with one-step reduction. _/→1_ : ∀ {m n a b} → a →1 b → (σ : Sub T′ m n) → a / σ →1 b / σ -- Substitution commutes with β-reduction. _/→*_ : ∀ {m n a b} → a →* b → (σ : Sub T′ m n) → a / σ →* b / σ a→*b /→* σ = Star.gmap (λ a → a / σ) (λ a→b → a→b /→1 σ) a→*b -- Substitution commutes with β-equivalence. _/↔_ : ∀ {m n a b} → a ↔ b → (σ : Sub T′ m n) → a / σ ↔ b / σ a≡b /↔ σ = gmap (λ a → a / σ) (λ a→b → a→b /→1 σ) a≡b
{ "alphanum_fraction": 0.5283525934, "avg_line_length": 32.9292035398, "ext": "agda", "hexsha": "30720693d7873ffc3d79bcd810c4d834b0ba7a63", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-08-11T23:28:33.000Z", "max_forks_repo_forks_event_min_datetime": "2017-08-20T10:29:44.000Z", "max_forks_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "asr/pts-agda", "max_forks_repo_path": "src/Relation/Binary/Reduction.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_issues_repo_issues_event_max_datetime": "2017-08-21T16:01:50.000Z", "max_issues_repo_issues_event_min_datetime": "2017-08-21T14:48:09.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "asr/pts-agda", "max_issues_repo_path": "src/Relation/Binary/Reduction.agda", "max_line_length": 72, "max_stars_count": 21, "max_stars_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "asr/pts-agda", "max_stars_repo_path": "src/Relation/Binary/Reduction.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-31T10:47:57.000Z", "max_stars_repo_stars_event_min_datetime": "2016-05-13T12:11:10.000Z", "num_tokens": 1368, "size": 3721 }