Search is not available for this dataset
text
string
meta
dict
open import Data.Nat hiding (_^_ ; _+_) open import Data.List as List hiding (null) open import Data.List.Membership.Propositional open import Data.List.Relation.Unary.Any open import Data.List.Relation.Unary.All as All open import Data.List.All.Properties.Extra open import Data.Integer open import Data.Unit open import Data.Empty open import Data.Product hiding (map) open import Relation.Binary.PropositionalEquality hiding ([_]) open ≡-Reasoning open import Function open import Data.Sum using (_⊎_; inj₁; inj₂) open import Data.Star hiding (return ; _>>=_ ; map) module MJSF.Semantics (k : ℕ) where open import MJSF.Syntax k open import MJSF.Values k open import MJSF.Monad k open import ScopesFrames.ScopesFrames k Ty open import Common.Weakening -- This file contains the definitional interpreter for MJ using scopes -- and frames, described in Section 5 of the paper. module Semantics (g : Graph) where open SyntaxG g open ValuesG g open MonadG g open UsesVal Valᵗ valᵗ-weaken renaming (getFrame to getFrame') public ----------------- -- AUXILIARIES -- ----------------- -- The interpreter relies on a number of auxiliary function. We -- briefly summarize each. -- In Java (and MJ), each field member of an object is initialized -- to have a default value. The `default` function defines a -- default value for each value type in MJ. default : {Σ : List Scope} → (t : VTy) → Val t Σ default int = num (+ 0) default (ref s) = null default void = void -- An alias for mapping `default` over a list of well-typed values: defaults : ∀ {fs : List Ty}{Σ} → All (#v (λ _ → ⊤)) fs → Slots fs Σ defaults fs = All.map (λ{ (#v' {t} _) → vᵗ (default t) }) fs -- `override` overrides methods in parent objects by overwriting -- method slots in super class frames by overriding child methods. -- -- This notion of overriding does not straightforwardly scale to -- deal with `super`, but `super` is not a part of MJ. See the -- paper or the MJ semantics in the appendix of this artifact for -- discussion and inspiration for how to represent class methods -- separately from object representations. override : ∀ {s Σ oms} → All (#m (λ ts t → (s ↦ (mᵗ ts t)) × Meth s ts t)) oms → M s (λ _ → ⊤) Σ override [] = return tt override (#m' (p , m) ∷ oms) = getFrame >>= λ f → setv p (mᵗ f m) >>= λ _ → override oms -- `init-obj` takes as input a class definition and a witness that -- the class has a finite inheritance chain. The function is -- structurally recursive over the inheritance chain finity witness. -- -- Each object is initialized by using the `initι` function, which -- allows us to refer to the "self" frame and store it in method -- definitions (i.e., the `fc` passed to the method value -- constructor `mᵗ` in `map-all` below). -- -- Method slots are initialized using the method members in the -- class definition. Field slots are initialized using `defaults` -- defined above. -- -- After frame initialization, overrides are applied by using -- `override` defined above. -- -- `init-obj` is assumed to be invoked in the context of the root -- frame, which all objects are linked to (because all scopes have -- an edge to the root scope). init-obj : ∀ {sʳ s s' Σ} → Class sʳ s → Inherits s s' → M sʳ (Frame s) Σ init-obj (class0 ms fs oms) (obj _) = getFrame >>= λ f → initι _ (λ fc → (All.map (λ{ (#m' m) → mᵗ fc m }) ms) ++-all (defaults fs)) (f ∷ []) >>= λ f' → (usingFrame f' (override oms) ^ f') >>= λ{ (_ , f') → return f' } init-obj (class0 ⦃ shape ⦄ _ _ _) (super ⦃ shape' ⦄ _) with (trans (sym shape) shape') ... | () -- absurd case: the scope shapes of `class0` and `super` do not match init-obj (class1 p ⦃ shape ⦄ ms fs oms) (super ⦃ shape' ⦄ x) with (trans (sym shape) shape') ... | refl = getv p >>= λ{ (cᵗ class' ic f') → (usingFrame f' (init-obj class' x) ^ f') >>= λ{ (f , f') → initι _ ⦃ shape ⦄ (λ fc → (All.map (λ{ (#m' m) → mᵗ fc m }) ms) ++-all (defaults fs)) (f' ∷ f ∷ []) >>= λ f'' → (usingFrame f'' (override oms) ^ f'') >>= λ{ (_ , f'') → return f'' }}} init-obj (class1 _ ⦃ shape ⦄ _ _ _) (obj _ ⦃ shape' ⦄) with (trans (sym shape) shape') ... | () -- absurd case: the scope shapes of `class1` and `obj` do not match ------------------------- -- EARLY RETURNS MONAD -- ------------------------- -- In order to deal with early returns, we define a specialized bind -- which stops evaluation and returns the yielded value. _>>=ᶜ_ : ∀ {s s' s'' r Σ} → M s (λ Σ → Val r Σ ⊎ Frame s' Σ) Σ → (∀ {Σ'} → Frame s' Σ' → M s (λ Σ → Val r Σ ⊎ Frame s'' Σ) Σ') → M s (λ Σ → Val r Σ ⊎ Frame s'' Σ) Σ (m >>=ᶜ f) = m >>= λ{ (inj₁ v) → return (inj₁ v) ; (inj₂ fr) → f fr } -- Continue is used to indicate that evaluation should continue. continue : ∀ {s r Σ} → M s (λ Σ → Val r Σ ⊎ Frame s Σ) Σ continue = fmap inj₂ getFrame mutual --------------------------- -- EXPRESSION EVALUATION -- --------------------------- eval : ℕ → ∀ {t s Σ} → Expr s t → M s (Val t) Σ eval zero _ = timeoutᴹ eval (suc k) (upcast σ e) = eval k e >>= λ v → return (upcastRef σ v) eval (suc k) (num x) = return (num x) eval (suc k) (iop x l r) = eval k l >>= λ{ (num il) → eval k r >>= λ{ (num ir) → return (num (il + ir)) }} eval (suc k) null = return null eval (suc k) (var x) = getv x >>= λ{ (vᵗ v) → return v } eval (suc k) (new x) = getv x >>= λ{ (cᵗ class ic f) → usingFrame f (init-obj class ic) >>= λ{ f' → return (ref [] f') }} eval (suc k) (get e p) = eval k e >>= λ{ null → raise ; (ref p' f) → usingFrame f (getv (prepend p' p)) >>= λ{ (vᵗ v) → return v }} eval (suc k) (call e p args) = eval k e >>= λ { null → raise ; (ref p' f) → usingFrame f (getv (prepend p' p)) >>= λ{ (mᵗ f' (meth s b)) → -- f' is the "self" (eval-args k args ^ f') >>= λ{ (slots , f') → init s slots (f' ∷ []) >>= λ f'' → -- f' is the static link of the method call frame usingFrame f'' (eval-body k b) }}} eval (suc k) (this p e) = getf p >>= λ f → usingFrame f (getl e) >>= λ f' → return (ref [] f') eval-args : ℕ → ∀ {s ts Σ} → All (Expr s) ts → M s (Slots (List.map vᵗ ts)) Σ eval-args zero _ = timeoutᴹ eval-args (suc k) [] = return [] eval-args (suc k) (e ∷ es) = eval k e >>= λ v → (eval-args k es ^ v) >>= λ{ (slots , v) → return (vᵗ v ∷ slots) } -------------------------- -- STATEMENT EVALUATION -- -------------------------- -- The following functions use the early returns monadic bind and -- `continue` operation defined above. eval-stmt : ℕ → ∀ {s s' r Σ} → Stmt s r s' → M s (λ Σ → Val r Σ ⊎ Frame s' Σ) Σ eval-stmt zero _ = timeoutᴹ eval-stmt (suc k) (run e) = eval k e >>= λ _ → continue eval-stmt (suc k) (ifz c t e) = eval k c >>= λ{ (num (+ zero)) → eval-stmt k t ; (num i) → eval-stmt k e } eval-stmt (suc k) (set e p e') = eval k e >>= λ{ null → raise ; (ref p' f) → (eval k e' ^ f) >>= λ{ (v , f) → usingFrame f (setv (prepend p' p) (vᵗ v)) >>= λ _ → continue }} eval-stmt (suc k) (loc s t) = getFrame >>= λ f → fmap inj₂ (init s (vᵗ (default t) ∷ []) (f ∷ [])) -- initializes a new local variable frame eval-stmt (suc k) (asgn x e) = eval k e >>= λ{ v → setv x (vᵗ v) >>= λ _ → continue } eval-stmt (suc k) (block stmts) = eval-stmts k stmts >>= λ{ _ → continue } eval-stmt (suc k) (ret e) = eval k e >>= λ{ v → return (inj₁ v) } eval-stmts : ℕ → ∀ {s r s' Σ} → Stmts s r s' → M s (λ Σ → Val r Σ ⊎ Frame s' Σ) Σ eval-stmts zero _ = timeoutᴹ eval-stmts (suc k) ε = continue eval-stmts (suc k) (stmt ◅ stmts) = eval-stmt k stmt >>=ᶜ λ f' → usingFrame f' (eval-stmts k stmts) --------------------- -- BODY EVALUATION -- --------------------- -- Defined in terms of statement evaluation; handles early returns: eval-body : ℕ → ∀ {s t Σ} → Body s t → M s (Val t) Σ eval-body zero _ = timeoutᴹ eval-body (suc k) (body stmts e) = eval-stmts k stmts >>= λ{ (inj₁ v) → return v ; (inj₂ fr) → usingFrame fr (eval k e) } eval-body (suc k) (body-void stmts) = eval-stmts k stmts >>= λ _ → return void ------------------------ -- PROGRAM EVALUATION -- ------------------------ -- Program evaluation first initializes the root frame to store all -- class definitions, and subsequently evaluates the program main -- function in the context of this root scope. -- -- We use `initι` to initialize the root frame since class -- definition values (`cᵗ`) store a pointer to the root frame, i.e., -- slots in the root frame are self-referential. eval-program : ℕ → ∀ {sʳ t} → Program sʳ t → Res (∃ λ Σ' → (Heap Σ' × Val t Σ')) eval-program k (program _ cs b) = let (f₀ , h₀) = initFrameι _ (λ f → All.map (λ{ (#c' (c , _ , ic)) → cᵗ c ic f }) cs) [] [] in case (eval-body k b f₀ h₀) of λ{ (ok (Σ' , h' , v , _)) → ok (Σ' , h' , v) ; timeout → timeout ; nullpointer → nullpointer } -- For the purpose of running the interpreter on test programs, we -- introduce some short-hand notation: -- The program will terminate succesfully in a state where p holds _⇓⟨_⟩_ : ∀ {sʳ a} → Program sʳ a → ℕ → (p : ∀ {Σ} → Val a Σ → Set) → Set p ⇓⟨ k ⟩ P with eval-program k p ... | nullpointer = ⊥ ... | timeout = ⊥ ... | ok (_ , _ , v) = P v -- The program will raise an exception in a state where p holds _⇓⟨_⟩!_ : ∀ {sʳ a} → Program sʳ a → ℕ → (p : ∀ {Σ} → Val a Σ → Set) → Set p ⇓⟨ k ⟩! P with eval-program k p ... | nullpointer = ⊤ ... | timeout = ⊥ ... | ok (_ , _ , v) = ⊥
{ "alphanum_fraction": 0.5475628931, "avg_line_length": 34.612244898, "ext": "agda", "hexsha": "90940a26e452435f68af11c7b5ac3f9d9f8a7e91", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "metaborg/mj.agda", "max_forks_repo_path": "src/MJSF/Semantics.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "metaborg/mj.agda", "max_issues_repo_path": "src/MJSF/Semantics.agda", "max_line_length": 115, "max_stars_count": 10, "max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "metaborg/mj.agda", "max_stars_repo_path": "src/MJSF/Semantics.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z", "max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z", "num_tokens": 3406, "size": 10176 }
------------------------------------------------------------------------ -- A terminating parser data type and the accompanying interpreter ------------------------------------------------------------------------ module RecursiveDescent.Coinductive.Internal where open import RecursiveDescent.Index open import Data.Bool open import Data.Product.Record open import Data.Maybe open import Data.BoundedVec.Inefficient import Data.List as L open import Data.Nat open import Category.Applicative.Indexed open import Category.Monad.Indexed open import Category.Monad.State open import Utilities ------------------------------------------------------------------------ -- Parser data type -- A type for parsers which can be implemented using recursive -- descent. The types used ensure that the implementation below is -- structurally recursive. codata Parser (tok : Set) : ParserType₁ where symbol : Parser tok (false , leaf) tok ret : forall {r} -> r -> Parser tok (true , leaf) r fail : forall {r} -> Parser tok (false , leaf) r bind₀ : forall {c₁ e₂ c₂ r₁ r₂} -> Parser tok (true , c₁) r₁ -> (r₁ -> Parser tok (e₂ , c₂) r₂) -> Parser tok (e₂ , node c₁ c₂) r₂ bind₁ : forall {c₁ r₁ r₂} {i₂ : r₁ -> Index} -> Parser tok (false , c₁) r₁ -> ((x : r₁) -> Parser tok (i₂ x) r₂) -> Parser tok (false , step c₁) r₂ alt₀ : forall {c₁ e₂ c₂ r} -> Parser tok (true , c₁) r -> Parser tok (e₂ , c₂) r -> Parser tok (true , node c₁ c₂) r alt₁ : forall {c₁} e₂ {c₂ r} -> Parser tok (false , c₁) r -> Parser tok (e₂ , c₂) r -> Parser tok (e₂ , node c₁ c₂) r ------------------------------------------------------------------------ -- Run function for the parsers -- Parser monad. P : Set -> IFun ℕ P tok = IStateT (BoundedVec tok) L.List PIMonadPlus : (tok : Set) -> RawIMonadPlus (P tok) PIMonadPlus tok = StateTIMonadPlus (BoundedVec tok) L.monadPlus PIMonadState : (tok : Set) -> RawIMonadState (BoundedVec tok) (P tok) PIMonadState tok = StateTIMonadState (BoundedVec tok) L.monad private open module LM {tok} = RawIMonadPlus (PIMonadPlus tok) open module SM {tok} = RawIMonadState (PIMonadState tok) using (get; put; modify) -- For every successful parse the run function returns the remaining -- string. (Since there can be several successful parses a list of -- strings is returned.) -- This function is structurally recursive with respect to the -- following lexicographic measure: -- -- 1) The upper bound of the length of the input string. -- 2) The parser's proper left corner tree. mutual parse : forall n {tok e c r} -> Parser tok (e , c) r -> P tok n (if e then n else pred n) r parse zero symbol = ∅ parse (suc n) symbol = eat =<< get parse n (ret x) = return x parse n fail = ∅ parse n (bind₀ p₁ p₂) = parse n p₁ >>= parse n ∘′ p₂ parse zero (bind₁ p₁ p₂) = ∅ parse (suc n) (bind₁ p₁ p₂) = parse (suc n) p₁ >>= parse↑ n ∘′ p₂ parse n (alt₀ p₁ p₂) = parse n p₁ ∣ parse↑ n p₂ parse n (alt₁ true p₁ p₂) = parse↑ n p₁ ∣ parse n p₂ parse n (alt₁ false p₁ p₂) = parse n p₁ ∣ parse n p₂ parse↑ : forall n {e tok c r} -> Parser tok (e , c) r -> P tok n n r parse↑ n {true} p = parse n p parse↑ zero {false} p = ∅ parse↑ (suc n) {false} p = parse (suc n) p >>= \r -> modify ↑ >> return r eat : forall {tok n} -> BoundedVec tok (suc n) -> P tok (suc n) n tok eat [] = ∅ eat (c ∷ s) = put s >> return c
{ "alphanum_fraction": 0.5403628714, "avg_line_length": 37.2843137255, "ext": "agda", "hexsha": "7254776f934f2269f74941fd45e84fb4aa45a481", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_path": "misc/RecursiveDescent/Coinductive/Internal.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z", "max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_path": "misc/RecursiveDescent/Coinductive/Internal.agda", "max_line_length": 72, "max_stars_count": 7, "max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yurrriq/parser-combinators", "max_stars_repo_path": "misc/RecursiveDescent/Coinductive/Internal.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z", "num_tokens": 1123, "size": 3803 }
-- Exploit by Jesper Cockx open import Agda.Builtin.Equality data Bool : Set where tt ff : Bool const : Bool → (Bool → Bool) const = λ x _ → x mutual Bool→cBool : Set Bool→cBool = _ const-tt : Bool→cBool const-tt = const tt constant : (f : Bool→cBool) (x y : Bool) → f x ≡ f y constant f x y = refl constant' : (f : Bool → Bool) (x y : Bool) → f x ≡ f y constant' = constant swap : Bool → Bool swap tt = ff swap ff = tt fireworks : tt ≡ ff fireworks = constant' swap ff tt
{ "alphanum_fraction": 0.6280487805, "avg_line_length": 16.4, "ext": "agda", "hexsha": "c780d14c3775dfa076deb51d20ddf11a14e60521", "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/Issue2480false2.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/Issue2480false2.agda", "max_line_length": 54, "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/Issue2480false2.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": 176, "size": 492 }
{- 2010-09-28 Andreas, example from Alan Jeffery, see Issue 336 -} module WhyWeNeedTypedLambda where data Bool : Set where true false : Bool F : Bool -> Set F true = Bool -> Bool F false = Bool bool : {b : Bool} -> F b -> Bool bool {b} _ = b {- -- untyped lambda leaves some yellow -- the problem \ x -> x : F ?b is postponed bla : Bool bla = bool (\ x -> x) -} -- typed lambda succeeds -- \ (x : _) -> x infers as ?X -> ?X, yielding constraint F ?b = ?X -> ?X bla' : Bool bla' = bool (\ (x : _) -> x)
{ "alphanum_fraction": 0.5875486381, "avg_line_length": 19.7692307692, "ext": "agda", "hexsha": "f8f08211bab0436ac5913cb3a7e40b5603acf054", "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": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/agda-kanso", "max_forks_repo_path": "test/succeed/WhyWeNeedTypedLambda.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "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": "asr/agda-kanso", "max_issues_repo_path": "test/succeed/WhyWeNeedTypedLambda.agda", "max_line_length": 73, "max_stars_count": null, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/WhyWeNeedTypedLambda.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 173, "size": 514 }
-- Andreas, 2019-12-03, issue #4200 reported and testcase by nad open import Agda.Builtin.Bool data D : Set where c₁ : D @0 c₂ : D -- Not allowed d : D d = c₂ f : D → Bool f c₁ = true f c₂ = false -- Expected error: -- Erased constructors are not supported -- when checking the constructor c₂ in the declaration of D
{ "alphanum_fraction": 0.6768292683, "avg_line_length": 16.4, "ext": "agda", "hexsha": "539dd551767b316d6b1938e4b721fba997870b14", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-06-14T11:07:38.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-14T11:07: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/Issue4200.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue4200.agda", "max_line_length": 64, "max_stars_count": 1, "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/Issue4200.agda", "max_stars_repo_stars_event_max_datetime": "2019-09-27T06:54:44.000Z", "max_stars_repo_stars_event_min_datetime": "2019-09-27T06:54:44.000Z", "num_tokens": 105, "size": 328 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Many properties which hold for `∼` also hold for `flip ∼`. Unlike -- the module `Relation.Binary.Construct.Converse` this module flips -- both the relation and the underlying equality. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Relation.Binary.Construct.Flip where open import Function open import Data.Product ------------------------------------------------------------------------ -- Properties module _ {a ℓ} {A : Set a} (∼ : Rel A ℓ) where reflexive : Reflexive ∼ → Reflexive (flip ∼) reflexive refl = refl symmetric : Symmetric ∼ → Symmetric (flip ∼) symmetric sym = sym transitive : Transitive ∼ → Transitive (flip ∼) transitive trans = flip trans asymmetric : Asymmetric ∼ → Asymmetric (flip ∼) asymmetric asym = asym total : Total ∼ → Total (flip ∼) total total x y = total y x respects : ∀ {p} (P : A → Set p) → Symmetric ∼ → P Respects ∼ → P Respects flip ∼ respects _ sym resp ∼ = resp (sym ∼) max : ∀ {⊥} → Minimum ∼ ⊥ → Maximum (flip ∼) ⊥ max min = min min : ∀ {⊤} → Maximum ∼ ⊤ → Minimum (flip ∼) ⊤ min max = max module _ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} (≈ : REL A B ℓ₁) (∼ : REL A B ℓ₂) where implies : ≈ ⇒ ∼ → flip ≈ ⇒ flip ∼ implies impl = impl irreflexive : Irreflexive ≈ ∼ → Irreflexive (flip ≈) (flip ∼) irreflexive irrefl = irrefl module _ {a ℓ₁ ℓ₂} {A : Set a} (≈ : Rel A ℓ₁) (∼ : Rel A ℓ₂) where antisymmetric : Antisymmetric ≈ ∼ → Antisymmetric (flip ≈) (flip ∼) antisymmetric antisym = antisym trichotomous : Trichotomous ≈ ∼ → Trichotomous (flip ≈) (flip ∼) trichotomous compare x y = compare y x module _ {a ℓ₁ ℓ₂} {A : Set a} (∼₁ : Rel A ℓ₁) (∼₂ : Rel A ℓ₂) where respects₂ : Symmetric ∼₂ → ∼₁ Respects₂ ∼₂ → flip ∼₁ Respects₂ flip ∼₂ respects₂ sym (resp₁ , resp₂) = (resp₂ ∘ sym , resp₁ ∘ sym) module _ {a b ℓ} {A : Set a} {B : Set b} (∼ : REL A B ℓ) where decidable : Decidable ∼ → Decidable (flip ∼) decidable dec x y = dec y x module _ {a ℓ} {A : Set a} {≈ : Rel A ℓ} where isEquivalence : IsEquivalence ≈ → IsEquivalence (flip ≈) isEquivalence eq = record { refl = reflexive ≈ Eq.refl ; sym = symmetric ≈ Eq.sym ; trans = transitive ≈ Eq.trans } where module Eq = IsEquivalence eq isDecEquivalence : IsDecEquivalence ≈ → IsDecEquivalence (flip ≈) isDecEquivalence dec = record { isEquivalence = isEquivalence Dec.isEquivalence ; _≟_ = decidable ≈ Dec._≟_ } where module Dec = IsDecEquivalence dec ------------------------------------------------------------------------ -- Structures module _ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} {∼ : Rel A ℓ₂} where isPreorder : IsPreorder ≈ ∼ → IsPreorder (flip ≈) (flip ∼) isPreorder O = record { isEquivalence = isEquivalence O.isEquivalence ; reflexive = implies ≈ ∼ O.reflexive ; trans = transitive ∼ O.trans } where module O = IsPreorder O isPartialOrder : IsPartialOrder ≈ ∼ → IsPartialOrder (flip ≈) (flip ∼) isPartialOrder O = record { isPreorder = isPreorder O.isPreorder ; antisym = antisymmetric ≈ ∼ O.antisym } where module O = IsPartialOrder O isTotalOrder : IsTotalOrder ≈ ∼ → IsTotalOrder (flip ≈) (flip ∼) isTotalOrder O = record { isPartialOrder = isPartialOrder O.isPartialOrder ; total = total ∼ O.total } where module O = IsTotalOrder O isDecTotalOrder : IsDecTotalOrder ≈ ∼ → IsDecTotalOrder (flip ≈) (flip ∼) isDecTotalOrder O = record { isTotalOrder = isTotalOrder O.isTotalOrder ; _≟_ = decidable ≈ O._≟_ ; _≤?_ = decidable ∼ O._≤?_ } where module O = IsDecTotalOrder O isStrictPartialOrder : IsStrictPartialOrder ≈ ∼ → IsStrictPartialOrder (flip ≈) (flip ∼) isStrictPartialOrder O = record { isEquivalence = isEquivalence O.isEquivalence ; irrefl = irreflexive ≈ ∼ O.irrefl ; trans = transitive ∼ O.trans ; <-resp-≈ = respects₂ ∼ ≈ O.Eq.sym O.<-resp-≈ } where module O = IsStrictPartialOrder O isStrictTotalOrder : IsStrictTotalOrder ≈ ∼ → IsStrictTotalOrder (flip ≈) (flip ∼) isStrictTotalOrder O = record { isEquivalence = isEquivalence O.isEquivalence ; trans = transitive ∼ O.trans ; compare = trichotomous ≈ ∼ O.compare } where module O = IsStrictTotalOrder O module _ {a ℓ} where setoid : Setoid a ℓ → Setoid a ℓ setoid S = record { _≈_ = flip S._≈_ ; isEquivalence = isEquivalence S.isEquivalence } where module S = Setoid S decSetoid : DecSetoid a ℓ → DecSetoid a ℓ decSetoid S = record { _≈_ = flip S._≈_ ; isDecEquivalence = isDecEquivalence S.isDecEquivalence } where module S = DecSetoid S module _ {a ℓ₁ ℓ₂} where preorder : Preorder a ℓ₁ ℓ₂ → Preorder a ℓ₁ ℓ₂ preorder O = record { isPreorder = isPreorder O.isPreorder } where module O = Preorder O poset : Poset a ℓ₁ ℓ₂ → Poset a ℓ₁ ℓ₂ poset O = record { isPartialOrder = isPartialOrder O.isPartialOrder } where module O = Poset O totalOrder : TotalOrder a ℓ₁ ℓ₂ → TotalOrder a ℓ₁ ℓ₂ totalOrder O = record { isTotalOrder = isTotalOrder O.isTotalOrder } where module O = TotalOrder O decTotalOrder : DecTotalOrder a ℓ₁ ℓ₂ → DecTotalOrder a ℓ₁ ℓ₂ decTotalOrder O = record { isDecTotalOrder = isDecTotalOrder O.isDecTotalOrder } where module O = DecTotalOrder O strictPartialOrder : StrictPartialOrder a ℓ₁ ℓ₂ → StrictPartialOrder a ℓ₁ ℓ₂ strictPartialOrder O = record { isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder } where module O = StrictPartialOrder O strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂ → StrictTotalOrder a ℓ₁ ℓ₂ strictTotalOrder O = record { isStrictTotalOrder = isStrictTotalOrder O.isStrictTotalOrder } where module O = StrictTotalOrder O
{ "alphanum_fraction": 0.6041027298, "avg_line_length": 30.955, "ext": "agda", "hexsha": "b193ea50674bf40c272741c91a202b007e51215d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Flip.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Flip.agda", "max_line_length": 75, "max_stars_count": 5, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Flip.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": 2017, "size": 6191 }
module Issue148 where data I : Set where i : I F : I → Set → Set F i A = A data T (p : I) : Set where t₁ : T p → T p t₂ : F p (T p) → T p fold : ((x : T i) → T i) → T i → T i fold f (t₁ x) = f (fold f x) fold f (t₂ x) = f (fold f x) data E : T i → Set where e : ∀ x → E x postulate t₂′ : ∀ {p} → F p (T p) → T p foo : (x : T i) → E (fold t₂ x) foo x with x foo x | x′ = e (fold t₂ x′)
{ "alphanum_fraction": 0.466992665, "avg_line_length": 15.1481481481, "ext": "agda", "hexsha": "d3b7e98b433780f3b4467de3f30ad24b11403bb0", "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": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/agda-kanso", "max_forks_repo_path": "test/succeed/Issue148.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "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": "asr/agda-kanso", "max_issues_repo_path": "test/succeed/Issue148.agda", "max_line_length": 36, "max_stars_count": null, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/Issue148.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 191, "size": 409 }
module Named where open import Data.String open import Data.Nat hiding (_≟_) open import Data.Bool using (T; not) open import Data.Product open import Data.Sum -- open import Data.Nat.Properties using (strictTotalOrder) -- open import Relation.Binary using (StrictTotalOrder) -- open import Relation.Binary.Core open import Function using (id) open import Function.Equivalence using (_⇔_; equivalence) open import Relation.Nullary open import Relation.Unary open import Relation.Nullary.Negation open import Data.Unit using (⊤) open import Function using (_∘_) -- open import Level renaming (zero to Lzero) open import Relation.Binary.PropositionalEquality -- open ≡-Reasoning -- open ≡-Reasoning -- renaming (begin_ to beginEq_; _≡⟨_⟩_ to _≡Eq⟨_⟩_; _∎ to _∎Eq) open import Data.Collection open import Data.Collection.Properties open import Data.Collection.Equivalence open import Data.Collection.Inclusion open import Relation.Binary.PartialOrderReasoning ⊆-Poset Variable = String data PreTerm : Set where Var : (w : Variable) → PreTerm App : (P : PreTerm) → (Q : PreTerm) → PreTerm Abs : (w : Variable) → (Q : PreTerm) → PreTerm showPreTerm : PreTerm → String showPreTerm (Var x) = x showPreTerm (App P Q) = "(" ++ showPreTerm P ++ " " ++ showPreTerm Q ++ ")" showPreTerm (Abs x M) = "(λ" ++ x ++ "." ++ showPreTerm M ++ ")" I : PreTerm I = Abs "x" (Var "x") S : PreTerm S = Abs "x" (App (Var "y") (Var "x")) FV : PreTerm → Collection FV (Var x ) = singleton x FV (App f x) = union (FV f) (FV x) FV (Abs x m) = delete x (FV m) -- a = singleton "x" ∋ (elem "x" ∪ elem "y") -- b = C[ singleton "x" ] ∩ C[ singleton "x" ] -- M = FV S -- neither∈ : ∀ {x A B} → x ∉ C[ A union B ] → _[_≔_] : PreTerm → Variable → PreTerm → PreTerm Var x [ v ≔ N ] with x ≟ v Var x [ v ≔ N ] | yes p = N Var x [ v ≔ N ] | no ¬p = Var x App P Q [ v ≔ N ] = App (P [ v ≔ N ]) (Q [ v ≔ N ]) Abs x P [ v ≔ N ] with x ≟ v Abs x P [ v ≔ N ] | yes p = Abs v P Abs x P [ v ≔ N ] | no ¬p = Abs x (P [ v ≔ N ]) -- If v ∉ FV(M) then M[v≔N] is defined and M[v≔N] ≡ M lem-1-2-5-a : ∀ M N v → v ∉ c[ FV M ] → M [ v ≔ N ] ≡ M lem-1-2-5-a (Var x) N v v∉M with x ≟ v lem-1-2-5-a (Var x) N .x v∉M | yes refl = contradiction here v∉M lem-1-2-5-a (Var x) N v v∉M | no ¬p = refl lem-1-2-5-a (App P Q) N v v∉M = cong₂ App (lem-1-2-5-a P N v (not-in-left-union (FV P) (FV Q) v∉M)) (lem-1-2-5-a Q N v (not-in-right-union (FV P) (FV Q) v∉M)) lem-1-2-5-a (Abs x M) N v v∉M with x ≟ v lem-1-2-5-a (Abs x M) N v v∉M | yes p = cong (λ z → Abs z M) (sym p) lem-1-2-5-a (Abs x M) N v v∉M | no ¬p = cong (Abs x) (lem-1-2-5-a M N v (still-∉-after-recovered x (FV M) ¬p v∉M)) -- begin -- {! !} -- ≡⟨ {! !} ⟩ -- {! !} -- ≡⟨ {! !} ⟩ -- {! !} -- ∎ -- begin -- {! !} -- ≤⟨ {! !} ⟩ -- {! !} -- ≤⟨ {! !} ⟩ -- {! !} -- ∎ -- If M[v≔N] is defined, v ≠ x and x ∈ FV(M) iff x ∈ FV(M[v≔N]) lem-1-2-5-b-i : ∀ {v N} M → c[ FV M ] ≋[ _≢_ v ] c[ FV (M [ v ≔ N ]) ] lem-1-2-5-b-i {v} {N} M v≢x = equivalence (to M v≢x) (from M v≢x) where to : ∀ {v N} M → c[ FV M ] ⊆[ _≢_ v ] c[ FV (M [ v ≔ N ]) ] to {v} (Var w) v≢x ∈FV-M with w ≟ v to (Var w) v≢x ∈FV-M | yes p = contradiction (sym (trans (nach singleton-≡ ∈FV-M) p)) v≢x to (Var w) v≢x ∈FV-M | no ¬p = ∈FV-M to {v} {N} (App P Q) v≢x = begin c[ union (FV P) (FV Q) ] ≤⟨ union-monotone {! !} {! !} {! !} ⟩ {! !} ≤⟨ {! !} ⟩ {! !} ≤⟨ {! !} ⟩ {! !} ≤⟨ {! !} ⟩ {! !} ≤⟨ {! !} ⟩ c[ union (FV (P [ v ≔ N ])) (FV (Q [ v ≔ N ])) ] ∎ to (Abs w M) v≢x ∈FV-M = {! !} -- to (Var w) ∈FV-M with w ≟ v -- to (Var w) ∈FV-M | yes p = contradiction (sym (trans (nach singleton-≡ ∈FV-M) p)) v≢x -- to (Var w) ∈FV-M | no ¬p = ∈FV-M -- to (App P Q) = begin -- c[ union (FV P) (FV Q) ] -- ≤⟨ union-monotone {! !} {! !} {! !} ⟩ -- {! !} -- ≤⟨ {! !} ⟩ -- {! !} -- ≤⟨ {! !} ⟩ -- c[ union (FV (P [ v ≔ N ])) (FV (Q [ v ≔ N ])) ] -- ∎ -- to (Abs w M) ∈FV-M = {! !} from : ∀ {v N} M → c[ FV (M [ v ≔ N ]) ] ⊆[ _≢_ v ] c[ FV M ] from M = {! !} -- lem-1-2-5-b-i : ∀ {x v N} M → v ≢ x → x ∈ c[ FV M ] ⇔ x ∈ c[ FV (M [ v ≔ N ]) ] -- lem-1-2-5-b-i {x} {v} {N} (Var w) v≢x with w ≟ v -- x ≡ w -- lem-1-2-5-b-i {x} {v} {N} (Var w) v≢x | yes p = -- equivalence -- (λ ∈[w] → contradiction (sym (trans (nach singleton-≡ ∈[w]) p)) v≢x) -- from -- where to : x ∈ c[ w ∷ [] ] → x ∈ c[ FV N ] -- to ∈[w] = {! !} -- from : x ∈ c[ FV N ] → x ∈ c[ w ∷ [] ] -- x ∈ c[ FV (N [ v ≔ N ]) ] -- from ∈FV-N = {! !} -- lem-1-2-5-b-i {x} {v} {N} (Var w) v≢x | no ¬p = equivalence id id -- lem-1-2-5-b-i {x} {v} {N} (App P Q) v≢x = equivalence to {! !} -- where to : c[ union (FV P) (FV Q) ] ⊆ c[ union (FV (P [ v ≔ N ])) (FV (Q [ v ≔ N ])) ] -- to = map-⊆-union {FV P} {FV Q} {FV (P [ v ≔ N ])} {FV (Q [ v ≔ N ])} (_≢_ v) {! !} {! !} {! !} -- -- -- lem-1-2-5-b-i (Abs w M) v≢x = {! !} -- lem-1-2-5-b-i : ∀ {x v N} M → v ≢ x → (x ∈ FV M) ⇔ (x ∈ FV (M [ v ≔ N ])) -- lem-1-2-5-b-i : ∀ {x v N} M → v ≢ x → (x ∈ FV M) ≡ (x ∈ FV (M [ v ≔ N ])) -- lem-1-2-5-b-i : ∀ {x v N} M → v ≢ x → (x ∈ c[ FV M ]) ≡ (x ∈ c[ FV (M [ v ≔ N ]) ]) -- lem-1-2-5-b-i {v = v} (Var w) v≢x with w ≟ v -- lem-1-2-5-b-i (Var v) v≢x | yes refl = {! !} -- lem-1-2-5-b-i {x} (Var w) v≢x | no ¬p = refl -- cong (_∈_ x) refl -- lem-1-2-5-b-i {x} {v} {N} (App P Q) v≢x = -- begin -- x ∈ c[ union (FV P) (FV Q) ] -- ≡⟨ sym {! ∪-union !} ⟩ -- {! !} -- ≡⟨ {! !} ⟩ -- {! !} -- ≡⟨ {! !} ⟩ -- {! !} -- ≡⟨ {! !} ⟩ -- {! !} -- ≡⟨ {! !} ⟩ -- x ∈ c[ union (FV (P [ v ≔ N ])) (FV (Q [ v ≔ N ])) ] -- ∎ -- lem-1-2-5-b-i (Abs w P) v≢x = {! !} -- lem-1-2-5-b-i {v = v} (Var w) v≢x x∈FV-M with w ≟ v -- lem-1-2-5-b-i (Var w) v≢x x∈FV-M | yes p = ? -- contradiction (trans (singleton-≡ x∈FV-M) p) (v≢x ∘ sym) -- lem-1-2-5-b-i (Var w) v≢x x∈FV-M | no ¬p = ? -- x∈FV-M -- lem-1-2-5-b-i (App P Q) v≢x x∈FV-M = ? -- ∈-respects-≡ {! !} x∈FV-M -- lem-1-2-5-b-i (App P Q) v≢x x∈FV-M = ∈-respects-≡ (cong₂ union (cong FV {! !}) (cong FV {! !})) x∈FV-M -- lem-1-2-5-b-i (App P Q) v≢x x∈FV-M = ∈-respects-≡ (cong₂ union ({! !}) {! !}) x∈FV-M -- lem-1-2-5-b-i (Abs w P) v≢x x∈FV-M = {! !} -- If M[v≔N] is defined then y ∈ FV(M[v≔N]) iff either y ∈ FV(M) and v ≠ y -- or y ∈ FV(N) and x ∈ FV(M) -- lem-1-2-5-b-i : ∀ {x y N} M v → y ∈ FV (M [ v ≔ N ]) → y ∈ FV M × x ≢ y ⊎ y ∈ FV N × x ∈ FV M -- lem-1-2-5-b⇒ (Var w) v y∈Applied with w ≟ v -- lem-1-2-5-b⇒ (Var w) v y∈Applied | yes p = {! !} -- lem-1-2-5-b⇒ (Var w) v y∈Applied | no ¬p = inj₁ (y∈Applied , {! singleton-≡ ∈ !}) -- lem-1-2-5-b⇒ (App P Q) v y∈Applied = {! !} -- lem-1-2-5-b⇒ (Abs w P) v y∈Applied = {! !} -- -- lem-1-2-5-b⇐ : ∀ {x y v M N} → y ∈ FV M × x ≢ y ⊎ y ∈ FV N × x ∈ FV M → y ∈ FV (M [ v ≔ N ]) -- lem-1-2-5-b⇐ = {! !} lem-1-2-5-c : (M : PreTerm) → (x : Variable) → M [ x ≔ Var x ] ≡ M lem-1-2-5-c (Var x ) y with x ≟ y lem-1-2-5-c (Var x ) y | yes p = sym (cong Var p) lem-1-2-5-c (Var x ) y | no ¬p = refl lem-1-2-5-c (App P Q) y = cong₂ App (lem-1-2-5-c P y) (lem-1-2-5-c Q y) lem-1-2-5-c (Abs x M) y with x ≟ y lem-1-2-5-c (Abs x M) y | yes p = cong (λ w → Abs w M) (sym p) lem-1-2-5-c (Abs x M) y | no ¬p = cong (Abs x) (lem-1-2-5-c M y) length : PreTerm → ℕ length (Var x) = 1 length (App P Q) = length P + length Q length (Abs x M) = 1 + length M -- lem-1-2-5-c : (M : PreTerm) → (x : Variable) → (N : PreTerm) → T (not (x ∈? FV M)) → M [ x ≔ N ] ≡ M -- lem-1-2-5-c (Var x') x N x∉M with x' ≟ x -- lem-1-2-5-c (Var x') x N x∉M | yes p = -- begin -- N -- ≡⟨ {! !} ⟩ -- {! !} -- ≡⟨ {! !} ⟩ -- Var x' -- ∎ -- lem-1-2-5-c (Var x') x N x∉M | no ¬p = {! !} -- lem-1-2-5-c (App P Q) x N x∉M = -- begin -- App (P [ x ≔ N ]) (Q [ x ≔ N ]) -- ≡⟨ refl ⟩ -- App P Q [ x ≔ N ] -- ≡⟨ {! !} ⟩ -- App P Q -- ∎ -- lem-1-2-5-c (Abs x' M) x N x∉M = {! !} -- begin -- {! !} -- ≡⟨ {! !} ⟩ -- {! !} -- ≡⟨ {! !} ⟩ -- {! !} -- ∎
{ "alphanum_fraction": 0.4167243368, "avg_line_length": 34.5418326693, "ext": "agda", "hexsha": "2d69c386e669dbe811ee187861fb83d0537544dc", "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": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "banacorn/lambda-calculus", "max_forks_repo_path": "Named.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a", "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": "banacorn/lambda-calculus", "max_issues_repo_path": "Named.agda", "max_line_length": 115, "max_stars_count": null, "max_stars_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "banacorn/lambda-calculus", "max_stars_repo_path": "Named.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4000, "size": 8670 }
module Rationals.Add.Comm where open import Equality open import Function open import Nats using (zero; ℕ) renaming (suc to s; _+_ to _:+:_; _*_ to _:*:_) open import Rationals open import Rationals.Properties open import Nats.Add.Comm open import Nats.Multiply.Distrib open import Nats.Multiply.Comm ------------------------------------------------------------------------ -- internal stuffs private a/c+b/c=a*b/c : ∀ a b c → a ÷ c + b ÷ c ≡ (a :+: b) ÷ c a/c+b/c=a*b/c a b c rewrite (a :+: b) ÷ c ↑ c | sym $ nat-multiply-distrib a b c = refl a+b=b+a : ∀ x y → x + y ≡ y + x a+b=b+a (a ÷ c) (b ÷ d) rewrite a ÷ c ↑ d | b ÷ d ↑ c | a/c+b/c=a*b/c (a :*: d) (b :*: c) $ d :*: c | nat-add-comm (a :*: d) $ b :*: c | nat-multiply-comm c d = refl ------------------------------------------------------------------------ -- public aliases rational-add-comm : ∀ x y → x + y ≡ y + x rational-add-comm = a+b=b+a
{ "alphanum_fraction": 0.4474975466, "avg_line_length": 26.1282051282, "ext": "agda", "hexsha": "09d99b99e8b689037045bc7f1db4c62df5ecae1d", "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/Rationals/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/Rationals/Add/Comm.agda", "max_line_length": 72, "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/Rationals/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": 315, "size": 1019 }
{- Jesper Cockx, 26-05-2014 Issue 1023 Example by Maxime Denes, adapted by Andreas Abel -} {-# OPTIONS --cubical-compatible --guardedness #-} module CoinductionAndUnivalence where open import Common.Coinduction open import Common.Equality prop = Set data False : prop where magic : ∀ {a} {A : Set a} → False → A magic () data Pandora : prop where C : ∞ False → Pandora postulate ext : (f : False → Pandora) → (g : Pandora → False) → (∀ x → f (g x) ≡ x) → (∀ y → g (f y) ≡ y) → False ≡ Pandora foo : False ≡ Pandora foo = ext f g fg gf where f : False → Pandora f () g : Pandora → False g (C c) = ♭ c fg : ∀ x → f (g x) ≡ x fg x = magic (g x) gf : ∀ y → g (f y) ≡ y gf () loop : False loop rewrite foo = C (♯ loop)
{ "alphanum_fraction": 0.5667090216, "avg_line_length": 17.4888888889, "ext": "agda", "hexsha": "63624c2ef762ef67411066979f573b6d9ae87db7", "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/CoinductionAndUnivalence.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/CoinductionAndUnivalence.agda", "max_line_length": 55, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Fail/CoinductionAndUnivalence.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 273, "size": 787 }
module Untyped.Monads where open import Function open import Data.Unit open import Data.Product as Prod open import Data.Sum open import Data.Sum public using () renaming (_⊎_ to Exceptional; inj₁ to exc; inj₂ to ✓) open import Category.Monad id-monad : ∀ {ℓ} → RawMonad {ℓ} id id-monad = record { return = id ; _>>=_ = λ a f → f a } record MonadReader (m : Set → Set) (e : Set) : Set₁ where field ask : m e local : ∀ {a} → (e → e) → m a → m a asks : ∀ ⦃ _ : RawMonad m ⦄ {a} → (e → a) → m a asks ⦃ m ⦄ f = let open RawMonad m in do e ← ask return $ f (e) ReaderT : Set → (M : Set → Set) → Set → Set ReaderT E M A = E → M A module _ (E : Set) (M : Set → Set) ⦃ mon : RawMonad M ⦄ where open RawMonad mon reader-monad : RawMonad (ReaderT E M) reader-monad = record { return = const ∘ return ; _>>=_ = λ m f e → m e >>= λ x → f x e } reader-monad-reader : MonadReader (ReaderT E M) E reader-monad-reader = record { ask = return ; local = λ f c e → c (f e) } record MonadWriter (m : Set → Set) (w : Set) : Set₁ where field write : w → m ⊤ record MonadState (m : Set → Set) (s : Set) : Set₁ where field state : ∀ {a} → (s → s × a) → m a put : s → m ⊤ put s = state λ _ → (s , tt) get : m s get = state λ s → (s , s) gets : ∀ {a} → (s → a) → m a gets f = state λ s → (s , f s) modify : ⦃ _ : RawMonad m ⦄ → (s → s) → m ⊤ modify ⦃ M ⦄ f = let open RawMonad M in do s ← get put (f s) StateT : Set → (M : Set → Set) → Set → Set StateT S M A = S → M (S × A) module _ (S : Set) (M : Set → Set) ⦃ mon : RawMonad M ⦄ where state-monad : RawMonad (StateT S M) state-monad = record { return = λ a s → return (s , a) ; _>>=_ = λ m f s → m s >>= λ where (s' , a) → f a s' } where open RawMonad mon state-monad-state : MonadState (StateT S M) S state-monad-state = record { state = λ f s → return (f s) } where open RawMonad mon open MonadState state-monad-state {- State focussing -} module _ {S F M} (focus : S → F) (update : F → S → S) ⦃ mon : RawMonad M ⦄ (st : MonadState M S) where focus-monad-state : MonadState M F focus-monad-state = record { state = λ f → MonadState.state st λ s → Prod.map₁ (λ f → update f s) (f (focus s)) } module _ {M S} ⦃ m : RawMonad M ⦄ (stm : MonadState M S) where open RawMonad m open MonadState stm state-monad-reader : MonadReader M S state-monad-reader = record { ask = get ; local = λ f m → do backup ← get modify f a ← m put backup return a } state-monad-writer : MonadWriter M S state-monad-writer = record { write = put } ExceptT : Set → (Set → Set) → Set → Set ExceptT E M A = M (E ⊎ A) record MonadExcept (m : Set → Set) (e : Set) : Set₁ where field throw : ∀ {a} → e → m a module _ {E : Set} {M : Set → Set} ⦃ mon : RawMonad M ⦄ where open RawMonad mon except-monad : RawMonad (ExceptT E M) except-monad = record { return = λ a → return (✓ a) ; _>>=_ = λ where c f → c >>= λ where (exc x) → return $ exc x (✓ y) → f y } except-monad-except : MonadExcept (ExceptT E M) E except-monad-except = record { throw = λ e → return (exc e) } record MonadResumption (m : Set → Set) (c h : Set) : Set₁ where field yield : m ⊤ fork : c → m h record MonadComm (m : Set → Set) (c v : Set) : Set₁ where field recv : c → m v send : c → v → m ⊤ close : c → m ⊤ module _ c (r : c → Set) where mutual Cont = λ cmd a → (r cmd → Free a) data Free a : Set where pure : a → Free a impure : (cmd : c) → Cont cmd a → Free a free-monad : ∀ {c r} → RawMonad (Free c r) free-monad = record { return = pure ; _>>=_ = bind } where bind : ∀ {c r a b} → Free c r a → (a → Free c r b) → Free c r b bind = λ where (pure a) f → f a (impure c k) f → impure c (flip bind f ∘ k) -- one cannot easily define instances like free-monad-comm generically -- for some command type and interpretation, because MonadComm -- requires that the recv return type is fixed a priori, whereas -- free allows it to be dependent on the command payload. module M where open RawMonad ⦃...⦄ public open MonadReader ⦃...⦄ public open MonadWriter ⦃...⦄ public renaming (write to schedule) open MonadResumption ⦃...⦄ public open MonadComm ⦃...⦄ public open MonadExcept ⦃...⦄ public open MonadState ⦃...⦄ public
{ "alphanum_fraction": 0.5619889503, "avg_line_length": 25.2793296089, "ext": "agda", "hexsha": "9daefe6eea147d2028aeab82aab1987a157a72bb", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z", "max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z", "max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "laMudri/linear.agda", "max_forks_repo_path": "src/Untyped/Monads.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "laMudri/linear.agda", "max_issues_repo_path": "src/Untyped/Monads.agda", "max_line_length": 90, "max_stars_count": 34, "max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "laMudri/linear.agda", "max_stars_repo_path": "src/Untyped/Monads.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z", "num_tokens": 1623, "size": 4525 }
{-# OPTIONS --without-K #-} open import library.Basics hiding (Type ; Σ) open import library.types.Sigma module Sec2preliminaries where -- is-prop, is-contr, is-set, has-dec-eq exist in library.Basicss -- Let us redefine Type and Σ so that they only refer to the lowest universe. Type = Type₀ Σ = library.Basics.Σ {lzero} {lzero} _+_ : Type → Type → Type X + Y = Coprod X Y const : {X Y : Type} → (f : X → Y) → Type const {X} f = (x₁ x₂ : X) → (f x₁) == (f x₂) hasConst : Type → Type hasConst X = Σ (X → X) const pathHasConst : Type → Type pathHasConst X = (x₁ x₂ : X) → hasConst (x₁ == x₂) LEM : Type₁ LEM = (P : Type) → is-prop P → P + (¬ P) LEM∞ : Type₁ LEM∞ = (X : Type) → X + (¬ X) Funext : {X Y : Type} → Type Funext {X} {Y} = (f g : X → Y) → ((x : X) → (f x) == (g x)) → f == g -- In the rest of this file, we define several auxiliary notations or lemmata that are not mentioned -- explicitly in the article but are somewhat self-explaining. -- for convenience, we also define ↔ to mean logical equivalence (maps in both directions) _↔_ : Type → Type → Type X ↔ Y = (X → Y) × (Y → X) -- we define it for types in the higher universe separately -- (because most of the time, we only need the lowest universe and do not want to carry around indices) _↔₀₁_ : Type → Type₁ → Type₁ A ↔₀₁ B = (A → B) × (B → A) _↔₁₁_ : Type₁ → Type₁ → Type₁ X ↔₁₁ Y = (X → Y) × (Y → X) -- composition of ↔ _◎_ : {X Y Z : Type} → (X ↔ Y) → (Y ↔ Z) → (X ↔ Z) e₁ ◎ e₂ = fst e₂ ∘ fst e₁ , snd e₁ ∘ snd e₂ -- A trivial, but useful lemma. The only thing we do is hiding the arguments. prop-eq-triv : {P : Type} → {p₁ p₂ : P} → is-prop P → p₁ == p₂ prop-eq-triv h = prop-has-all-paths h _ _ -- A second such useful lemma second-comp-triv : {X : Type} → {P : X → Type} → ((x : X) → is-prop (P x)) → (a b : Σ X P) → (fst a == fst b) → a == b second-comp-triv {X} {P} h a b q = pair= q (from-transp P q (prop-eq-triv (h (fst b)))) open import library.types.Pi -- Note that this lemma needs function extensionality (we use Π-level). neutral-codomain : {X : Type} → {Y : X → Type} → ((x : X) → is-contr (Y x)) → Π X Y ≃ Unit neutral-codomain = contr-equiv-Unit ∘ Π-level -- the following is the function which the univalence axiom postulates to be an equivalence -- (we define it ourselves as we do not want to implicitly import the whole univalence library) path-to-equiv : {X Y : Type} → X == Y → X ≃ Y path-to-equiv {X} idp = ide X -- some rather silly lemmata delete-idp : {X : Type} → {x₁ x₂ : X} → (p q : x₁ == x₂) → (p ∙ idp == q) ≃ (p == q) delete-idp idp q = ide _ add-path : {X : Type} → {x₁ x₂ x₃ : X} → (p q : x₁ == x₂) → (r : x₂ == x₃) → (p == q) == (p ∙ r == q ∙ r) add-path idp q idp = transport (λ q₁ → (idp == q₁) == (idp == q ∙ idp)) {x = q ∙ idp} {y = q} (∙-unit-r _) idp open import library.types.Paths reverse-paths : {X : Type} → {x₁ x₂ : X} → (p : x₂ == x₁) → (q : x₁ == x₂) → (! p == q) ≃ (p == ! q) reverse-paths p idp = ! p == idp ≃⟨ path-to-equiv (add-path _ _ _) ⟩ ! p ∙ p == p ≃⟨ path-to-equiv (transport (λ p₁ → (! p ∙ p == p) == (p₁ == p)) (!-inv-l p) idp) ⟩ idp == p ≃⟨ !-equiv ⟩ p == idp ≃∎ switch-args : {X Y : Type} → {Z : X → Y → Type} → ((x : X) → (y : Y) → Z x y) ≃ ((y : Y) → (x : X) → Z x y) switch-args = equiv f g h₁ h₂ where f = λ k y x → k x y g = λ i x y → i y x h₁ = λ _ → idp h₂ = λ _ → idp -- another useful (but simple) lemma: if we have a proof of (x , y₁) == (x , y₂) and the type of x is a set, we get a proof of y₁ == y₂. set-lemma : {X : Type} → (is-set X) → {Y : X → Type} → (x₀ : X) → (y₁ y₂ : Y x₀) → _==_ {A = Σ X Y} (x₀ , y₁) (x₀ , y₂) → y₁ == y₂ set-lemma {X} h {Y} x₀ y₁ y₂ p = y₁ =⟨ idp ⟩ transport Y idp y₁ =⟨ transport {A = x₀ == x₀} (λ q → y₁ == transport Y q y₁) {x = idp} {y = ap fst p} (prop-has-all-paths (h x₀ x₀) _ _) idp ⟩ transport Y (ap fst p) y₁ =⟨ snd-of-p ⟩ y₂ ∎ where pairs : =Σ {B = Y} (x₀ , y₁) (x₀ , y₂) pairs = <– (=Σ-eqv _ _) p paov : y₁ == y₂ [ Y ↓ fst (pairs) ] paov = snd pairs snd-of-p : transport Y (ap fst p) y₁ == y₂ snd-of-p = to-transp paov
{ "alphanum_fraction": 0.5445262408, "avg_line_length": 35.686440678, "ext": "agda", "hexsha": "e4e02fbf7bff5ab38c4ed56ab5b712c784d19ebc", "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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "nicolai/anonymousExistence/Sec2preliminaries.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "nicolai/anonymousExistence/Sec2preliminaries.agda", "max_line_length": 136, "max_stars_count": 1, "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_path": "nicolai/anonymousExistence/Sec2preliminaries.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z", "num_tokens": 1656, "size": 4211 }
{-# OPTIONS --safe #-} module Issue2442-terminating where {-# NON_TERMINATING #-} f : Set f = f
{ "alphanum_fraction": 0.6428571429, "avg_line_length": 12.25, "ext": "agda", "hexsha": "638e9579bb1cfaf4b69af70842db96d5e370b82c", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Fail/Issue2442-terminating.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Fail/Issue2442-terminating.agda", "max_line_length": 34, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Fail/Issue2442-terminating.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": 27, "size": 98 }
open import Theory module Categories.Category.Construction.Classifying {ℓ₁ ℓ₂ ℓ₃} (Th : Theory ℓ₁ ℓ₂ ℓ₃) where open import Relation.Binary using (Rel) open import Data.List using ([]; _∷_) open import Data.Fin using () renaming (zero to fzero; suc to fsuc) open import Level using (_⊔_) open import Categories.Category open import Syntax open Theory.Theory Th open Signature Sg open Term Sg private arr : Rel Type (ℓ₁ ⊔ ℓ₂) arr A B = A ∷ [] ⊢ B identityʳ : forall {A B} {e : A ∷ [] ⊢ B} -> A ∷ [] ⊢ e [ ext ! var ] ≡ e identityʳ {A} {e = e} = trans (cong/sub (trans (cong/ext !-unique refl) η-pair) refl) sub/id assoc : {A B C D : Type} {f : arr A B} {g : arr B C} {h : arr C D} -> A ∷ [] ⊢ h [ ext ! g ] [ ext ! f ] ≡ h [ ext ! (g [ ext ! f ]) ] assoc {f = f} {g = g} {h = h} = trans (sym sub/∙) (cong/sub (trans ext∙ (cong/ext (sym !-unique) refl)) refl) Cl : Category ℓ₁ (ℓ₁ ⊔ ℓ₂) (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃) Cl = record { Obj = Type ; _⇒_ = arr ; _≈_ = λ e₁ e₂ → _ ∷ [] ⊢ e₁ ≡ e₂ ; id = var ; _∘_ = λ e₁ e₂ → e₁ [ ext ! e₂ ] ; assoc = assoc ; sym-assoc = sym assoc ; identityˡ = λ {A} {B} {f} -> var/ext ! f ; identityʳ = identityʳ ; identity² = var/ext ! var ; equiv = record { refl = refl ; sym = sym ; trans = trans } ; ∘-resp-≈ = λ x x₁ → cong/sub (cong/ext refl x₁) x } open import Categories.Category.BinaryProducts Cl module M where open import Categories.Category.CartesianClosed.Canonical Cl CC : CartesianClosed CC = record { ⊤ = Unit ; _×_ = _*_ ; ! = unit ; π₁ = fst var ; π₂ = snd var ; ⟨_,_⟩ = pair ; !-unique = eta/Unit ; π₁-comp = trans comm/fst (trans (cong/fst (var/ext ! (pair _ _))) (beta/*₁ _ _)) ; π₂-comp = trans comm/snd (trans (cong/snd (var/ext ! (pair _ _))) (beta/*₂ _ _)) ; ⟨,⟩-unique = ⟨,⟩-unique ; _^_ = λ A B → B => A ; eval = app (fst var) (snd var) ; curry = λ e → abs (e [ ext ! (pair (var [ weaken ]) var) ]) ; eval-comp = eval-comp ; curry-resp-≈ = λ x → cong/abs (cong/sub refl x) ; curry-unique = λ x → curry-unique x } where ⟨,⟩-unique : forall {A B C} {h : C ∷ [] ⊢ A * B} {i : C ∷ [] ⊢ A} {j : C ∷ [] ⊢ B} -> C ∷ [] ⊢ fst var [ ext ! h ] ≡ i -> C ∷ [] ⊢ snd var [ ext ! h ] ≡ j -> C ∷ [] ⊢ pair i j ≡ h ⟨,⟩-unique x y = trans (cong/pair (sym (trans (cong/fst (sym (var/ext ! _))) (trans (sym comm/fst) x))) (sym (trans (cong/snd (sym (var/ext ! _))) (trans (sym comm/snd) y))) ) (eta/* _) open import Categories.Object.Product.Morphisms Cl using ([_⇒_]_×_) open import Categories.Object.Product Cl using (Product) product : forall {A B} -> Product A B product {A} {B} = record { A×B = A * B ; π₁ = fst var ; π₂ = snd var ; ⟨_,_⟩ = pair ; project₁ = trans comm/fst (trans (cong/fst (var/ext ! (pair _ _))) (beta/*₁ _ _)) ; project₂ = trans comm/snd (trans (cong/snd (var/ext ! (pair _ _))) (beta/*₂ _ _)) ; unique = ⟨,⟩-unique } eval-comp : forall {B A C} {f : arr (C * A) B} -> C * A ∷ [] ⊢ app (fst var) (snd var) [ ext ! ([ product ⇒ product ] (abs (f [ ext ! (pair (var [ weaken ]) var)])) × var) ] ≡ f eval-comp = trans comm/app (trans (cong/app (trans comm/fst (cong/fst (var/ext _ _))) (trans comm/snd (cong/snd (var/ext _ _)))) (trans (cong/app (trans (beta/*₁ _ _) comm/abs) (beta/*₂ _ _)) (trans (beta/=> _ _) (trans (sym sub/∙) (trans (cong/sub (trans ext∙ (cong/ext (trans (cong/∙ (trans ext∙ (cong/ext (sym !-unique) comm/fst)) refl) (trans ext∙ (cong/ext (sym !-unique) (trans comm/fst (cong/fst (trans (sym sub/∙) (cong/sub weaken/ext refl))))))) (trans (var/ext _ _) (var/ext _ _)))) refl) (trans (sym sub/∙) (trans (cong/sub (trans ext∙ (trans (cong/ext (sym !-unique) (trans comm/pair (cong/pair (trans (sym sub/∙) (trans (cong/sub weaken/ext refl) (trans (var/ext _ _) (cong/fst sub/id)))) (var/ext _ _)))) (trans (cong/ext !-unique (eta/* _)) η-pair))) refl) sub/id))))))) open BinaryProducts (record { product = product }) open Category Cl helper : forall {A B C} {f : A ⇒ B => C} -> B ∷ A ∷ [] ⊨ ext ! (var [ weaken ]) ≡ weaken helper = trans (cong/ext (!-unique {γ = weaken ∙ weaken}) refl) (trans (sym ext∙) (trans (cong/∙ η-pair refl) id∙ˡ)) curry-unique : forall {A B C} {f : A ⇒ B => C} {g : A × B ⇒ C} -> app (fst var) (snd var) ∘ (f ⁂ Category.id Cl) ≈ g -> f ≈ abs (g [ ext ! (pair (var [ weaken ]) var) ]) curry-unique {A} {B} {C} {f = f} {g = g} x = begin f ≈˘⟨ eta/=> _ ⟩ abs (app (f [ weaken ]) var) ≈˘⟨ cong/abs (cong/app (cong/sub (helper {f = f}) refl) refl) ⟩ abs (app (f [ ext ! (var [ weaken ]) ]) var) ≈˘⟨ cong/abs (cong/app (beta/*₁ _ _) (beta/*₂ _ _)) ⟩ abs (app (fst (pair (f [ ext ! (var [ weaken ]) ]) var)) (snd (pair (f [ ext ! (var [ weaken ]) ]) var))) ≈˘⟨ cong/abs (cong/app (trans comm/fst (cong/fst (var/ext _ _))) (trans comm/snd (cong/snd (var/ext _ _)))) ⟩ abs (app (fst var [ ext ! (pair (f [ ext ! (var [ weaken ]) ]) var) ]) (snd var [ ext ! (pair (f [ ext ! (var [ weaken ]) ]) var) ])) ≈˘⟨ cong/abs comm/app ⟩ abs (app (fst var) (snd var) [ ext ! (pair (f [ ext ! (var [ weaken ]) ]) var) ]) ≈˘⟨ cong/abs (cong/sub (cong/ext refl (cong/pair (cong/sub (cong/ext refl (trans comm/fst (trans (cong/fst (var/ext _ _)) (beta/*₁ _ _)))) refl) refl)) refl) ⟩ abs (app (fst var) (snd var) [ ext ! (pair (f [ ext ! (fst var [ ext ! (pair (var [ weaken ]) var)]) ]) var) ]) ≈˘⟨ cong/abs (cong/sub (cong/ext refl (cong/pair (cong/sub (trans ext∙ (cong/ext (sym !-unique) refl)) refl) (trans (cong/snd (var/ext _ _)) (beta/*₂ _ _)))) refl) ⟩ abs (app (fst var) (snd var) [ ext ! (pair (f [ ext ! (fst var) ∙ ext ! (pair (var [ weaken ]) var) ]) (snd (var [ ext ! (pair (var [ weaken ]) var) ]))) ]) ≈˘⟨ cong/abs (cong/sub (cong/ext refl (cong/pair (sym sub/∙) comm/snd)) refl) ⟩ abs (app (fst var) (snd var) [ ext ! (pair (f [ ext ! (fst var) ] [ ext ! (pair (var [ weaken ]) var) ]) (snd var [ ext ! (pair (var [ weaken ]) var) ])) ]) ≈˘⟨ cong/abs (cong/sub (cong/ext refl comm/pair) refl) ⟩ abs (app (fst var) (snd var) [ ext ! (pair (f [ ext ! (fst var) ]) (snd var) [ ext ! (pair (var [ weaken ]) var) ]) ]) ≈⟨ cong/abs (cong/sub (cong/ext !-unique (cong/sub refl (cong/pair refl (sym (var/ext _ _))))) refl) ⟩ abs (app (fst var) (snd var) [ ext (! ∙ ext ! (pair (var [ weaken ]) var)) (pair (f [ ext ! (fst var) ]) (var [ ext ! (snd var) ]) [ ext ! (pair (var [ weaken ]) var) ]) ]) ≈˘⟨ cong/abs (cong/sub ext∙ refl) ⟩ abs (app (fst var) (snd var) [ ext ! (pair (f [ ext ! (fst var) ]) (var [ ext ! (snd var) ])) ∙ ext ! (pair (var [ weaken ]) var) ]) ≡⟨⟩ abs (app (fst var) (snd var) [ ext ! ⟨ f ∘ fst var , Category.id Cl ∘ snd var ⟩ ∙ ext ! (pair (var [ weaken ]) var) ]) ≈⟨ cong/abs sub/∙ ⟩ abs ((app (fst var) (snd var) ∘ ⟨ f ∘ fst var , Category.id Cl ∘ snd var ⟩) [ ext ! (pair (var [ weaken ]) var) ]) ≡⟨⟩ abs ((app (fst var) (snd var) ∘ (f ⁂ Category.id Cl)) [ ext ! (pair (var [ weaken ]) var) ]) ≈⟨ cong/abs (cong/sub refl x) ⟩ abs (g [ ext ! (pair (var [ weaken ]) var) ]) ∎ where open import Relation.Binary.Reasoning.Setoid TermSetoid open import Categories.Category.CartesianClosed Cl import Categories.Category.CartesianClosed.Canonical Cl as Can CC : CartesianClosed CC = Can.Equivalence.fromCanonical M.CC open import Semantics Cl CC Sg open Category Cl private open import Data.Product using (_,_) open import Categories.Morphism Cl using (Iso; _≅_) open import Categories.Category.Cartesian using (Cartesian) open import Categories.Functor open import Categories.Functor.Properties using ([_]-resp-∘) open import Categories.Functor.Construction.Product using (Product) open import Categories.Functor.Construction.Exponential using (Exp) open import Categories.Functor.Bifunctor using (Bifunctor) open CartesianClosed CC open BinaryProducts (Cartesian.products cartesian) open I ⌊_⌋ P : Bifunctor Cl Cl Cl P = Product Cl cartesian E : Bifunctor Cl op Cl E = Exp Cl CC from/⟦⟧T : forall (A : Type) -> ⟦ A ⟧T ⇒ A to/⟦⟧T : forall (A : Type) -> A ⇒ ⟦ A ⟧T from/⟦⟧T ⌊ x ⌋ = Category.id Cl from/⟦⟧T Unit = Category.id Cl from/⟦⟧T (A * A₁) = from/⟦⟧T A ⁂ from/⟦⟧T A₁ from/⟦⟧T (A => A₁) = λg (from/⟦⟧T A₁ ∘ eval′ ∘ (Category.id Cl ⁂ to/⟦⟧T A)) to/⟦⟧T ⌊ x ⌋ = Category.id Cl to/⟦⟧T Unit = Category.id Cl to/⟦⟧T (A * A₁) = to/⟦⟧T A ⁂ to/⟦⟧T A₁ to/⟦⟧T (A => A₁) = λg (to/⟦⟧T A₁ ∘ eval′ ∘ (Category.id Cl ⁂ from/⟦⟧T A)) to∘from : forall {A} -> ⟦ A ⟧T ∷ [] ⊢ to/⟦⟧T A [ ext ! (from/⟦⟧T A) ] ≡ var to∘from {⌊ x ⌋} = var/ext _ _ to∘from {Unit} = var/ext _ _ to∘from {A * A₁} = trans ([ P ]-resp-∘ (to∘from , to∘from)) (Functor.identity P) to∘from {A => A₁} = trans ([ E ]-resp-∘ (to∘from , to∘from)) (Functor.identity E) from∘to : forall {A} -> A ∷ [] ⊢ from/⟦⟧T A [ ext ! (to/⟦⟧T A) ] ≡ var from∘to {⌊ x ⌋} = var/ext _ _ from∘to {Unit} = var/ext _ _ from∘to {A * A₁} = trans ([ P ]-resp-∘ (from∘to , from∘to)) (Functor.identity P) from∘to {A => A₁} = trans ([ E ]-resp-∘ (from∘to , from∘to)) (Functor.identity E) Iso/⟦⟧T : forall {A : Type} -> ⟦ A ⟧T ≅ A Iso/⟦⟧T {A} = record { from = from/⟦⟧T A ; to = to/⟦⟧T A ; iso = record { isoˡ = to∘from ; isoʳ = from∘to } } ⟦_⟧F : (f : Func) -> ⟦ dom f ⟧T ⇒ ⟦ cod f ⟧T ⟦_⟧F f = _≅_.to Iso/⟦⟧T ∘ x ∘ _≅_.from Iso/⟦⟧T where x : dom f ⇒ cod f x = func f var S : Structure S = record { ⟦_⟧G = ⌊_⌋ ; ⟦_⟧F = λ f → ⟦ f ⟧F } open Structure S private γC : forall {Γ} -> ⟦ Γ ⟧C ∷ [] ⊨ Γ γC {[]} = ! γC {A ∷ Γ} = ext (γC {Γ} ∙ ext ! π₁) (from/⟦⟧T A ∘ π₂) open HomReasoning open import Categories.Morphism.Reasoning Cl import Categories.Object.Product Cl as Prod open import Categories.Object.Terminal Cl using (Terminal) module T = Terminal (Cartesian.terminal cartesian) helper : forall {Γ} {A} {e : Γ ⊢ A} -> ⟦ e ⟧ ≈ to/⟦⟧T A ∘ (e [ γC ]) helperS : forall {Γ Γ′} {γ : Γ ⊨ Γ′} -> _ ⊨ γC ∙ ext ! ⟦ γ ⟧S ≡ γ ∙ γC helper {e = func f e} = begin (to/⟦⟧T (cod f) ∘ func f var ∘ from/⟦⟧T (dom f)) ∘ ⟦ e ⟧ ≈⟨ ∘-resp-≈ʳ (helper {e = e}) ⟩ (to/⟦⟧T (cod f) ∘ func f var ∘ from/⟦⟧T (dom f)) ∘ to/⟦⟧T _ ∘ (e [ γC ]) ≈⟨ assoc²' ⟩ to/⟦⟧T (cod f) ∘ func f var ∘ from/⟦⟧T (dom f) ∘ to/⟦⟧T (dom f) ∘ (e [ γC ]) ≈⟨ ∘-resp-≈ʳ (∘-resp-≈ʳ (cancelˡ from∘to)) ⟩ to/⟦⟧T (cod f) ∘ func f var ∘ (e [ γC ]) ≈⟨ ∘-resp-≈ʳ (comm/func _ _ _ _ _) ⟩ to/⟦⟧T (cod f) ∘ func f (var ∘ (e [ γC ])) ≈⟨ ∘-resp-≈ʳ (cong/func identityˡ) ⟩ to/⟦⟧T (cod f) ∘ func f (e [ γC ]) ≈˘⟨ ∘-resp-≈ʳ (comm/func _ _ _ _ _) ⟩ to/⟦⟧T (cod f) ∘ (func f e [ γC ]) ∎ helper {e = var} = begin π₂ ≈⟨ insertˡ to∘from ⟩ to/⟦⟧T _ ∘ (from/⟦⟧T _ ∘ π₂) ≈˘⟨ ∘-resp-≈ʳ (var/ext _ _) ⟩ to/⟦⟧T _ ∘ (var [ ext _ (from/⟦⟧T _ ∘ π₂) ]) ∎ helper {e = unit} = T.!-unique _ helper {e = pair e₁ e₂} = begin ⟨ ⟦ e₁ ⟧ , ⟦ e₂ ⟧ ⟩ ≈⟨ ⟨⟩-cong₂ (helper {e = e₁}) (helper {e = e₂}) ⟩ ⟨ to/⟦⟧T _ ∘ (e₁ [ γC ]) , to/⟦⟧T _ ∘ (e₂ [ γC ]) ⟩ ≈˘⟨ ⁂∘⟨⟩ ⟩ (to/⟦⟧T _ ⁂ to/⟦⟧T _) ∘ (pair (e₁ [ γC ]) (e₂ [ γC ])) ≈˘⟨ ∘-resp-≈ʳ comm/pair ⟩ (to/⟦⟧T _ ⁂ to/⟦⟧T _) ∘ (pair e₁ e₂ [ γC ]) ∎ helper {e = fst {A = A} {B = B} e} = switch-fromtoˡ Iso/⟦⟧T ( begin from/⟦⟧T _ ∘ π₁ ∘ ⟦ e ⟧ ≈⟨ ∘-resp-≈ʳ (∘-resp-≈ʳ (helper {e = e})) ⟩ from/⟦⟧T A ∘ π₁ ∘ to/⟦⟧T (A * B) ∘ (e [ γC ]) ≈⟨ ∘-resp-≈ʳ (pullˡ π₁∘⁂) ⟩ from/⟦⟧T A ∘ (to/⟦⟧T A ∘ π₁) ∘ (e [ γC ]) ≈⟨ assoc²'' ⟩ (from/⟦⟧T A ∘ to/⟦⟧T A) ∘ π₁ ∘ (e [ γC ]) ≈⟨ elimˡ from∘to ⟩ π₁ ∘ (e [ γC ]) ≈⟨ comm/fst ⟩ fst (var [ ext ! (e [ γC ]) ]) ≈⟨ cong/fst (var/ext _ _) ⟩ fst (e [ γC ]) ≈˘⟨ comm/fst ⟩ fst e [ γC ] ∎) helper {e = snd e} = begin π₂ ∘ ⟦ e ⟧ ≈⟨ ∘-resp-≈ʳ (helper {e = e}) ⟩ π₂ ∘ (to/⟦⟧T _ ∘ (e [ γC ])) ≈⟨ pullˡ π₂∘⁂ ⟩ (to/⟦⟧T _ ∘ snd var) ∘ (e [ γC ]) ≈⟨ pullʳ comm/snd ⟩ to/⟦⟧T _ ∘ snd (var ∘ (e [ γC ])) ≈⟨ ∘-resp-≈ʳ (cong/snd identityˡ) ⟩ to/⟦⟧T _ ∘ snd (e [ γC ]) ≈˘⟨ ∘-resp-≈ʳ comm/snd ⟩ to/⟦⟧T _ ∘ (snd e [ γC ]) ∎ helper {e = abs e} = begin λg ⟦ e ⟧ ≈⟨ λ-cong (helper {e = e}) ⟩ λg (to/⟦⟧T _ ∘ (e [ γC ])) ≈⟨ refl ⟩ λg (to/⟦⟧T _ ∘ (e [ ext (γC ∙ ext ! π₁) (from/⟦⟧T _ ∘ π₂) ])) ≈˘⟨ λ-cong (∘-resp-≈ʳ (cong/sub (cong/ext id∙ʳ refl) refl)) ⟩ λg (to/⟦⟧T _ ∘ (e [ ext ((γC ∙ ext ! π₁) ∙ _⊨_.id) (from/⟦⟧T _ ∘ π₂) ])) ≈˘⟨ λ-cong (∘-resp-≈ʳ (cong/sub ×id′-ext refl)) ⟩ λg (to/⟦⟧T _ ∘ (e [ (γC ∙ ext ! π₁) ×id′ ∙ ext _⊨_.id (from/⟦⟧T _ ∘ π₂)])) ≈⟨ λ-cong (∘-resp-≈ʳ sub/∙) ⟩ λg (to/⟦⟧T _ ∘ (e [ (γC ∙ ext ! π₁) ×id′ ] [ ext _⊨_.id (from/⟦⟧T _ ∘ π₂)])) ≈˘⟨ λ-cong (∘-resp-≈ʳ (cong/sub refl (cong/sub ×id′-∙ refl))) ⟩ λg (to/⟦⟧T _ ∘ (e [ γC ×id′ ∙ ext ! π₁ ×id′ ] [ ext _⊨_.id (from/⟦⟧T _ ∘ π₂)])) ≈⟨ λ-cong (∘-resp-≈ʳ (cong/sub refl sub/∙)) ⟩ λg (to/⟦⟧T _ ∘ (e [ ext (γC ∙ weaken) var ] [ ext (ext ! π₁ ∙ weaken) var ] [ ext _⊨_.id (from/⟦⟧T _ ∘ π₂)])) ≈˘⟨ λ-cong (∘-resp-≈ʳ (beta/=> _ _)) ⟩ λg (to/⟦⟧T _ ∘ app (abs (e [ ext (γC ∙ weaken) var ] [ ext (ext ! π₁ ∙ weaken) var ])) (from/⟦⟧T _ ∘ π₂)) ≈˘⟨ λ-cong (∘-resp-≈ʳ (cong/app comm/abs refl)) ⟩ λg (to/⟦⟧T _ ∘ app (abs (e [ ext (γC ∙ weaken) var ]) ∘ π₁) (from/⟦⟧T _ ∘ π₂)) ≈˘⟨ λ-cong (∘-resp-≈ʳ (cong/app (beta/*₁ _ _) (beta/*₂ _ _))) ⟩ λg (to/⟦⟧T _ ∘ app (fst (abs (e [ ext (γC ∙ weaken) var ]) ⁂ from/⟦⟧T _)) (snd (abs (e [ ext (γC ∙ weaken) var ]) ⁂ from/⟦⟧T _))) ≈˘⟨ λ-cong (∘-resp-≈ʳ (trans comm/app (cong/app (trans comm/fst (cong/fst (var/ext _ _))) (trans comm/snd (cong/snd (var/ext _ _)))))) ⟩ λg (to/⟦⟧T _ ∘ (app π₁ π₂) ∘ (abs (e [ ext (γC ∙ weaken) var ]) ⁂ from/⟦⟧T _)) ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ˡ (cong/app (beta/*₁ _ _) (beta/*₂ _ _)))) ⟩ λg (to/⟦⟧T _ ∘ (app (fst (pair π₁ π₂)) (snd (pair π₁ π₂))) ∘ (abs (e [ ext (γC ∙ weaken) var ]) ⁂ from/⟦⟧T _)) ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ˡ (cong/app (trans comm/fst (cong/fst (var/ext _ _))) (trans comm/snd (cong/snd (var/ext _ _)))))) ⟩ λg (to/⟦⟧T _ ∘ (app (fst var ∘ pair π₁ π₂) (snd var ∘ pair π₁ π₂)) ∘ (abs (e [ ext (γC ∙ weaken) var ]) ⁂ from/⟦⟧T _)) ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ˡ comm/app)) ⟩ λg (to/⟦⟧T _ ∘ (app (fst var) (snd var) ∘ (pair π₁ π₂)) ∘ (abs (e [ ext (γC ∙ weaken) var ]) ⁂ from/⟦⟧T _)) ≈⟨ refl ⟩ λg (to/⟦⟧T _ ∘ (eval ∘ Prod.repack product exp.product) ∘ (abs (e [ ext (γC ∙ weaken) var ]) ⁂ from/⟦⟧T _)) ≈⟨ refl ⟩ λg (to/⟦⟧T _ ∘ eval′ ∘ (abs (e [ ext (γC ∙ weaken) var ]) ⁂ from/⟦⟧T _)) ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ comm/abs refl))) ⟩ λg (to/⟦⟧T _ ∘ eval′ ∘ ((abs e [ γC ]) ⁂ from/⟦⟧T _)) ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ identityˡ (Category.identityʳ Cl)))) ⟩ λg (to/⟦⟧T _ ∘ eval′ ∘ (var ∘ (abs e [ γC ]) ⁂ from/⟦⟧T _ ∘ var)) ≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ ⁂∘⁂)) ⟩ λg (to/⟦⟧T _ ∘ eval′ ∘ (var ⁂ from/⟦⟧T _) ∘ ((abs e [ γC ]) ⁂ var)) ≈˘⟨ λ-cong assoc²' ⟩ λg ((to/⟦⟧T _ ∘ eval′ ∘ (var ⁂ from/⟦⟧T _)) ∘ ((abs e [ γC ]) ⁂ var)) ≈˘⟨ exp.subst product product ⟩ (λg (to/⟦⟧T _ ∘ eval′ ∘ (var ⁂ from/⟦⟧T _))) ∘ (abs e [ γC ]) ≈⟨ refl ⟩ to/⟦⟧T (_ => _) ∘ (abs e [ γC ]) ∎ helper {e = app e₁ e₂} = begin eval′ ∘ ⟨ ⟦ e₁ ⟧ , ⟦ e₂ ⟧ ⟩ ≈⟨ refl ⟩ (app (fst var) (snd var) ∘ _) ∘ ⟨ ⟦ e₁ ⟧ , ⟦ e₂ ⟧ ⟩ ≈⟨ ∘-resp-≈ˡ (elimʳ η) ⟩ app (fst var) (snd var) ∘ ⟨ ⟦ e₁ ⟧ , ⟦ e₂ ⟧ ⟩ ≈⟨ ∘-resp-≈ʳ (⟨⟩-cong₂ (helper {e = e₁}) (helper {e = e₂})) ⟩ app (fst var) (snd var) ∘ ⟨ to/⟦⟧T _ ∘ (e₁ [ γC ]) , to/⟦⟧T _ ∘ (e₂ [ γC ]) ⟩ ≈⟨ comm/app ⟩ app (fst var ∘ ⟨ to/⟦⟧T _ ∘ (e₁ [ γC ]) , to/⟦⟧T _ ∘ (e₂ [ γC ]) ⟩) (snd var ∘ ⟨ to/⟦⟧T _ ∘ (e₁ [ γC ]) , to/⟦⟧T _ ∘ (e₂ [ γC ]) ⟩) ≈⟨ cong/app comm/fst comm/snd ⟩ app (fst (var ∘ ⟨ to/⟦⟧T _ ∘ (e₁ [ γC ]) , to/⟦⟧T _ ∘ (e₂ [ γC ]) ⟩)) (snd (var ∘ ⟨ to/⟦⟧T _ ∘ (e₁ [ γC ]) , to/⟦⟧T _ ∘ (e₂ [ γC ]) ⟩)) ≈⟨ cong/app (cong/fst (var/ext _ _)) (cong/snd (var/ext _ _)) ⟩ app (fst ⟨ to/⟦⟧T _ ∘ (e₁ [ γC ]) , to/⟦⟧T _ ∘ (e₂ [ γC ]) ⟩) (snd ⟨ to/⟦⟧T _ ∘ (e₁ [ γC ]) , to/⟦⟧T _ ∘ (e₂ [ γC ]) ⟩) ≈⟨ cong/app (beta/*₁ _ _) (beta/*₂ _ _) ⟩ app (to/⟦⟧T (_ => _) ∘ (e₁ [ γC ])) (to/⟦⟧T _ ∘ (e₂ [ γC ])) ≈⟨ refl ⟩ app (λg (to/⟦⟧T _ ∘ eval′ ∘ (var ⁂ from/⟦⟧T _)) ∘ (e₁ [ γC ])) (to/⟦⟧T _ ∘ (e₂ [ γC ])) ≈⟨ refl ⟩ app (curry ((to/⟦⟧T _ ∘ eval′ ∘ (var ⁂ from/⟦⟧T _)) ∘ Prod.repack product product) ∘ (e₁ [ γC ])) (to/⟦⟧T _ ∘ (e₂ [ γC ])) ≈⟨ refl ⟩ app (abs (((to/⟦⟧T _ ∘ eval′ ∘ (var ⁂ from/⟦⟧T _)) ∘ Prod.repack product product) [ ext ! (pair (var [ weaken ]) var) ]) ∘ (e₁ [ γC ])) (to/⟦⟧T _ ∘ (e₂ [ γC ])) ≈⟨ cong/app (cong/sub refl (cong/abs (cong/sub refl (elimʳ η)))) refl ⟩ app (abs ((to/⟦⟧T _ ∘ eval′ ∘ (var ⁂ from/⟦⟧T _)) [ ext ! (pair (var [ weaken ]) var) ]) ∘ (e₁ [ γC ])) (to/⟦⟧T _ ∘ (e₂ [ γC ])) ≈⟨ cong/app comm/abs refl ⟩ app (abs ((to/⟦⟧T _ ∘ eval′ ∘ (var ⁂ from/⟦⟧T _)) [ ext ! (pair (var [ weaken ]) var) ] [ ext ! (e₁ [ γC ]) ×id′ ])) (to/⟦⟧T _ ∘ (e₂ [ γC ])) ≈⟨ beta/=> _ _ ⟩ (to/⟦⟧T _ ∘ eval′ ∘ (var ⁂ from/⟦⟧T _)) [ ext ! (pair (var [ weaken ]) var) ] [ ext ! (e₁ [ γC ]) ×id′ ] [ ext _⊨_.id (to/⟦⟧T _ ∘ (e₂ [ γC ])) ] ≈⟨ refl ⟩ (to/⟦⟧T _ ∘ (eval ∘ Prod.repack product product) ∘ (var ⁂ from/⟦⟧T _)) [ ext ! (pair (var [ weaken ]) var) ] [ ext ! (e₁ [ γC ]) ×id′ ] [ ext _⊨_.id (to/⟦⟧T _ ∘ (e₂ [ γC ])) ] ≈⟨ cong/sub refl (cong/sub refl (cong/sub refl (∘-resp-≈ʳ (∘-resp-≈ˡ (elimʳ η))))) ⟩ (to/⟦⟧T _ ∘ (app (fst var) (snd var)) ∘ (var ⁂ from/⟦⟧T _)) [ ext ! (pair (var [ weaken ]) var) ] [ ext ! (e₁ [ γC ]) ×id′ ] [ ext _⊨_.id (to/⟦⟧T _ ∘ (e₂ [ γC ])) ] ≈˘⟨ sub/∙ ⟩ (to/⟦⟧T _ ∘ (app (fst var) (snd var)) ∘ (var ⁂ from/⟦⟧T _)) [ ext ! (pair (var [ weaken ]) var) ] [ ext ! (e₁ [ γC ]) ×id′ ∙ ext _⊨_.id (to/⟦⟧T _ ∘ (e₂ [ γC ])) ] ≈⟨ cong/sub (×id′-ext) refl ⟩ (to/⟦⟧T _ ∘ (app (fst var) (snd var)) ∘ (var ⁂ from/⟦⟧T _)) [ ext ! (pair (var [ weaken ]) var) ] [ ext (ext ! (e₁ [ γC ]) ∙ _⊨_.id) (to/⟦⟧T _ ∘ (e₂ [ γC ])) ] ≈⟨ cong/sub (cong/ext id∙ʳ refl) refl ⟩ (to/⟦⟧T _ ∘ (app (fst var) (snd var)) ∘ (var ⁂ from/⟦⟧T _)) [ ext ! (pair (var [ weaken ]) var) ] [ ext (ext ! (e₁ [ γC ])) (to/⟦⟧T _ ∘ (e₂ [ γC ])) ] ≈˘⟨ sub/∙ ⟩ (to/⟦⟧T _ ∘ (app (fst var) (snd var)) ∘ (var ⁂ from/⟦⟧T _)) [ ext ! (pair (var [ weaken ]) var) ∙ ext (ext ! (e₁ [ γC ])) (to/⟦⟧T _ ∘ (e₂ [ γC ])) ] ≈⟨ cong/sub (trans ext∙ (cong/ext (sym !-unique) refl)) refl ⟩ (to/⟦⟧T _ ∘ (app (fst var) (snd var)) ∘ (var ⁂ from/⟦⟧T _)) ∘ (pair (var [ weaken ]) var [ ext (ext ! (e₁ [ γC ])) (to/⟦⟧T _ ∘ (e₂ [ γC ])) ]) ≈⟨ ∘-resp-≈ʳ (trans comm/pair (cong/pair (trans (sym sub/∙) (cong/sub weaken/ext refl)) (var/ext _ _))) ⟩ (to/⟦⟧T _ ∘ (app (fst var) (snd var)) ∘ (var ⁂ from/⟦⟧T _)) ∘ (pair (var [ (ext ! (e₁ [ γC ])) ]) (to/⟦⟧T _ ∘ (e₂ [ γC ]))) ≈⟨ ∘-resp-≈ʳ (cong/pair (var/ext _ _) refl) ⟩ (to/⟦⟧T _ ∘ (app (fst var) (snd var)) ∘ (var ⁂ from/⟦⟧T _)) ∘ (pair (e₁ [ γC ]) (to/⟦⟧T _ ∘ (e₂ [ γC ]))) ≈⟨ pull-last ⁂∘⟨⟩ ⟩ to/⟦⟧T _ ∘ (app (fst var) (snd var)) ∘ (pair (var ∘ (e₁ [ γC ])) (from/⟦⟧T _ ∘ to/⟦⟧T _ ∘ (e₂ [ γC ]))) ≈⟨ ∘-resp-≈ʳ (cong/sub (cong/ext refl (cong/pair identityˡ (cancelˡ from∘to))) refl) ⟩ to/⟦⟧T _ ∘ (app (fst var) (snd var)) ∘ (pair (e₁ [ γC ]) (e₂ [ γC ])) ≈⟨ ∘-resp-≈ʳ (trans comm/app (cong/app (trans comm/fst (trans (cong/fst (var/ext _ _)) (beta/*₁ _ _))) (trans comm/snd (trans (cong/snd (var/ext _ _)) (beta/*₂ _ _))))) ⟩ to/⟦⟧T _ ∘ (app (e₁ [ γC ]) (e₂ [ γC ])) ≈˘⟨ ∘-resp-≈ʳ (comm/app) ⟩ to/⟦⟧T _ ∘ (app e₁ e₂ [ γC ]) ∎ where curry : _ -> _ curry e = abs (e [ ext ! (pair (var [ weaken ]) var) ]) helper {e = e [ γ ]} = begin ⟦ e ⟧ ∘ ⟦ γ ⟧S ≈⟨ pushˡ (helper {e = e}) ⟩ to/⟦⟧T _ ∘ (e [ γC ]) ∘ ⟦ γ ⟧S ≈⟨ refl ⟩ to/⟦⟧T _ ∘ (e [ γC ] [ ext ! ⟦ γ ⟧S ]) ≈˘⟨ ∘-resp-≈ʳ sub/∙ ⟩ to/⟦⟧T _ ∘ (e [ γC ∙ ext ! ⟦ γ ⟧S ]) ≈⟨ ∘-resp-≈ʳ (cong/sub (helperS {γ = γ}) refl) ⟩ to/⟦⟧T _ ∘ (e [ γ ∙ γC ]) ≈⟨ ∘-resp-≈ʳ sub/∙ ⟩ to/⟦⟧T _ ∘ (e [ γ ] [ γC ]) ∎ helperS {γ = id} = trans (trans (cong/∙ refl (cong/ext !-unique refl)) (trans (cong/∙ refl η-pair) id∙ʳ)) (sym id∙ˡ) helperS {γ = γ ∙ γ₁} = S.begin γC ∙ ext ! (⟦ γ ⟧S ∘ ⟦ γ₁ ⟧S) S.≈˘⟨ cong/∙ refl (trans ext∙ (cong/ext (sym !-unique) refl)) ⟩ γC ∙ (ext ! ⟦ γ ⟧S ∙ ext ! ⟦ γ₁ ⟧S) S.≈˘⟨ assoc∙ ⟩ (γC ∙ ext ! ⟦ γ ⟧S) ∙ ext ! ⟦ γ₁ ⟧S S.≈⟨ cong/∙ (helperS {γ = γ}) refl ⟩ (γ ∙ γC) ∙ ext ! ⟦ γ₁ ⟧S S.≈⟨ assoc∙ ⟩ γ ∙ (γC ∙ ext ! ⟦ γ₁ ⟧S) S.≈⟨ cong/∙ refl (helperS {γ = γ₁}) ⟩ γ ∙ (γ₁ ∙ γC) S.≈˘⟨ assoc∙ ⟩ (γ ∙ γ₁) ∙ γC S.∎ where import Relation.Binary.Reasoning.Setoid SubstSetoid as S helperS {γ = weaken} = sym weaken/ext helperS {γ = ext γ e} = S.begin γC {_ ∷ _} ∙ (ext ! ⟨ ⟦ γ ⟧S , ⟦ e ⟧ ⟩) S.≡⟨⟩ ext (γC ∙ ext ! π₁) (from/⟦⟧T _ ∘ π₂) ∙ (ext ! ⟨ ⟦ γ ⟧S , ⟦ e ⟧ ⟩) S.≈⟨ ext∙ ⟩ ext ((γC ∙ ext ! π₁) ∙ (ext ! ⟨ ⟦ γ ⟧S , ⟦ e ⟧ ⟩)) ((from/⟦⟧T _ ∘ π₂) ∘ ⟨ ⟦ γ ⟧S , ⟦ e ⟧ ⟩) S.≈⟨ cong/ext assoc∙ (pullʳ project₂) ⟩ ext (γC ∙ (ext ! π₁ ∙ (ext ! ⟨ ⟦ γ ⟧S , ⟦ e ⟧ ⟩))) (from/⟦⟧T _ ∘ ⟦ e ⟧) S.≈⟨ cong/ext (cong/∙ refl (trans ext∙ (cong/ext (sym !-unique) refl))) refl ⟩ ext (γC ∙ (ext ! (π₁ [ ext ! ⟨ ⟦ γ ⟧S , ⟦ e ⟧ ⟩ ]))) (from/⟦⟧T _ ∘ ⟦ e ⟧) S.≈⟨ cong/ext (cong/∙ refl (cong/ext refl project₁)) refl ⟩ ext (γC ∙ ext ! ⟦ γ ⟧S) (from/⟦⟧T _ ∘ ⟦ e ⟧) S.≈⟨ cong/ext (helperS {γ = γ}) (sym (switch-tofromˡ Iso/⟦⟧T (sym (helper {e = e})))) ⟩ ext (γ ∙ γC) (e [ γC ]) S.≈˘⟨ ext∙ ⟩ ext γ e ∙ γC S.∎ where import Relation.Binary.Reasoning.Setoid SubstSetoid as S helperS {γ = !} = trans (sym !-unique) !-unique satisfyAxiom : forall {Γ} {A} {e₁ e₂ : Γ ⊢ A} -> Ax Γ A e₁ e₂ -> ⟦ e₁ ⟧ ≈ ⟦ e₂ ⟧ satisfyAxiom {Γ} {A} {e₁} {e₂} x = trans (helper {e = e₁}) (trans (∘-resp-≈ʳ a) (sym (helper {e = e₂}))) where a : (e₁ [ γC ]) ≈ (e₂ [ γC ]) a = cong/sub refl (ax x) M : Model Cl CC Th M = S , satisfyAxiom
{ "alphanum_fraction": 0.4662097684, "avg_line_length": 47.4362139918, "ext": "agda", "hexsha": "4b58aca47fafa37795962b8271751a06b1f51cbb", "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": "7541ab22debdfe9d529ac7a210e5bd102c788ad9", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "elpinal/exsub-ccc", "max_forks_repo_path": "Categories/Category/Construction/Classifying.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9", "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": "elpinal/exsub-ccc", "max_issues_repo_path": "Categories/Category/Construction/Classifying.agda", "max_line_length": 791, "max_stars_count": 3, "max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "elpinal/exsub-ccc", "max_stars_repo_path": "Categories/Category/Construction/Classifying.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z", "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z", "num_tokens": 11021, "size": 23054 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import homotopy.Bouquet open import homotopy.FinWedge open import homotopy.SphereEndomorphism open import groups.SphereEndomorphism open import cw.CW open import cw.FinCW open import cw.WedgeOfCells open import cw.FinBoundary open import cohomology.Theory module cw.cohomology.cochainequiv.HigherCoboundary (OT : OrdinaryTheory lzero) {n} (⊙fin-skel : ⊙FinSkeleton (S (S n))) where open OrdinaryTheory OT open import cohomology.SubFinBouquet OT open import cohomology.RephraseSubFinCoboundary OT private fin-skel = ⊙FinSkeleton.skel ⊙fin-skel I = AttachedFinSkeleton.numCells fin-skel ac = ⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero dec = ⊙FinSkeleton-has-cells-with-dec-eq ⊙fin-skel ⊙fin-skel₋₁ = ⊙fcw-init ⊙fin-skel fin-skel₋₁ = ⊙FinSkeleton.skel ⊙fin-skel₋₁ I₋₁ = AttachedFinSkeleton.numCells fin-skel₋₁ ac₋₁ = ⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel₋₁ lzero dec₋₁ = ⊙FinSkeleton-has-cells-with-dec-eq ⊙fin-skel₋₁ open import cw.cohomology.WedgeOfCells OT open import cw.cohomology.reconstructed.HigherCoboundary OT ⊙⦉ ⊙fin-skel ⦊ open import cw.cohomology.cochainequiv.HigherCoboundaryAbstractDefs OT ⊙fin-skel abstract rephrase-cw-co∂-last-in-degree : ∀ g → GroupIso.f (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel ⦊ ac) (GroupHom.f cw-co∂-last (GroupIso.g (CXₙ/Xₙ₋₁-diag-β ⊙⦉ ⊙fin-skel₋₁ ⦊ ac₋₁) g)) ∼ λ <I → Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (fdegree-last fin-skel <I <I₋₁)) rephrase-cw-co∂-last-in-degree g <I = GroupIso.f (C-FinBouquet-diag (S (S n)) I) (CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊)) (GroupHom.f cw-co∂-last (CEl-fmap (ℕ-to-ℤ (S n)) (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊)) (GroupIso.g (C-FinBouquet-diag (S n) I₋₁) g)))) <I =⟨ ap (λ g → GroupIso.f (C-FinBouquet-diag (S (S n)) I) (CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊)) g) <I) $ cw-co∂-last-β (CEl-fmap (ℕ-to-ℤ (S n)) (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊)) (GroupIso.g (C-FinBouquet-diag (S n) I₋₁) g)) ⟩ GroupIso.f (C-FinBouquet-diag (S (S n)) I) (CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊)) (CEl-fmap (ℕ-to-ℤ (S (S n))) ⊙cw-∂-before-Susp (<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊)) (CEl-fmap (ℕ-to-ℤ (S n)) (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊)) (GroupIso.g (C-FinBouquet-diag (S n) I₋₁) g))))) <I =⟨ ap (λ g → GroupIso.f (C-FinBouquet-diag (S (S n)) I) (CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊)) (CEl-fmap (ℕ-to-ℤ (S (S n))) ⊙cw-∂-before-Susp g)) <I) $ C-Susp-fmap' (ℕ-to-ℤ (S n)) (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊)) □$ᴳ (GroupIso.g (C-FinBouquet-diag (S n) I₋₁) g) ⟩ GroupIso.f (C-FinBouquet-diag (S (S n)) I) (CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊)) (CEl-fmap (ℕ-to-ℤ (S (S n))) ⊙cw-∂-before-Susp (CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙Susp-fmap (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊))) (<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙FinBouquet _ (S n))) (GroupIso.g (C-FinBouquet-diag (S n) I₋₁) g))))) <I =⟨ ap (λ g → GroupIso.f (C-FinBouquet-diag (S (S n)) I) g <I) $ ∘-CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊)) ⊙cw-∂-before-Susp (CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙Susp-fmap (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊))) (<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙FinBouquet _ (S n))) (GroupIso.g (C-FinBouquet-diag (S n) I₋₁) g))) ∙ ∘-CEl-fmap (ℕ-to-ℤ (S (S n))) (⊙cw-∂-before-Susp ⊙∘ ⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel ⦊)) (⊙Susp-fmap (⊙<– (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ ⦉ fin-skel₋₁ ⦊))) (<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙FinBouquet _ (S n))) (GroupIso.g (C-FinBouquet-diag (S n) I₋₁) g)) ∙ ap (λ f → CEl-fmap (ℕ-to-ℤ (S (S n))) f (<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙FinBouquet _ (S n))) (GroupIso.g (C-FinBouquet-diag (S n) I₋₁) g))) (! ⊙function₀'-β) ⟩ GroupIso.f (C-FinBouquet-diag (S (S n)) I) (CEl-fmap (ℕ-to-ℤ (S (S n))) ⊙function₀' (<– (CEl-Susp (ℕ-to-ℤ (S n)) (⊙FinBouquet _ (S n))) (GroupIso.g (C-FinBouquet-diag (S n) I₋₁) g))) <I =⟨ rephrase-in-degree' (S n) {I = I} {J = I₋₁} ⊙function₀' g <I ⟩ Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (⊙SphereS-endo-degree (S n) (⊙Susp-fmap (⊙fwproj <I₋₁) ⊙∘ ⊙function₀' ⊙∘ ⊙fwin <I))) =⟨ ap (Group.sum (C2 0)) (λ= λ <I₋₁ → ap (Group.exp (C2 0) (g <I₋₁)) $ ⊙SphereS-endo-degree-base-indep (S n) {f = ( ⊙Susp-fmap (⊙fwproj <I₋₁) ⊙∘ ⊙function₀' ⊙∘ ⊙fwin <I)} {g = (Susp-fmap (function₁' <I <I₋₁) , idp)} (mega-reduction <I <I₋₁)) ⟩ Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (⊙SphereS-endo-degree (S n) (Susp-fmap (function₁' <I <I₋₁) , idp))) =⟨ ap (Group.sum (C2 0)) (λ= λ <I₋₁ → ap (Group.exp (C2 0) (g <I₋₁)) $ ⊙SphereS-endo-degree-Susp' n (function₁' <I <I₋₁)) ⟩ Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (Trunc-⊙SphereS-endo-degree n (Trunc-⊙SphereS-endo-in n [ function₁' <I <I₋₁ ]))) =⟨ ap (Group.sum (C2 0)) (λ= λ <I₋₁ → ap (λ f → Group.exp (C2 0) (g <I₋₁) (Trunc-⊙SphereS-endo-degree n (Trunc-⊙SphereS-endo-in n [ f ]))) (function₁'-β <I <I₋₁)) ⟩ Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (Trunc-⊙SphereS-endo-degree n (Trunc-⊙SphereS-endo-in n [ function₁ <I <I₋₁ ]))) =∎
{ "alphanum_fraction": 0.5062882941, "avg_line_length": 44.9420289855, "ext": "agda", "hexsha": "6f2f18c5fe7207ce455281d03d3ca0ead42fc963", "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": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "theorems/cw/cohomology/cochainequiv/HigherCoboundary.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "timjb/HoTT-Agda", "max_issues_repo_path": "theorems/cw/cohomology/cochainequiv/HigherCoboundary.agda", "max_line_length": 132, "max_stars_count": null, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "theorems/cw/cohomology/cochainequiv/HigherCoboundary.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2895, "size": 6202 }
module UnSized.Parrot where open import Data.Product open import Data.String.Base open import UnSizedIO.IOObject open import UnSizedIO.Base hiding (main) open import UnSizedIO.Console hiding (main) open import NativeIO open import UnSized.SimpleCell hiding (program; main) --ParrotC : Set --ParrotC = ConsoleObject (cellI String) -- but reusing cellC from SimpleCell, as interface is ident! -- class Parrot implements Cell { -- Cell cell; -- Parrot (Cell c) { cell = c; } -- public String get() { -- return "(" + cell.get() + ") is what parrot got"; -- } -- public void put (String s) { -- cell.put("parrot puts (" + s + ")"); -- } -- } -- parrotP is constructor for the consoleObject for interface (cellI String) {-# NON_TERMINATING #-} parrotP : (c : CellC) → CellC (method (parrotP c) get) = exec1 (putStrLn "printing works") >> method c get >>= λ { (s , c') → return ("(" ++ s ++ ") is what parrot got" , parrotP c') } (method (parrotP c) (put s)) = method c (put ("parrot puts (" ++ s ++ ")")) -- public static void main (String[] args) { -- Parrot c = new Parrot(new SimpleCell("Start")); -- System.out.println(c.get()); -- c.put(args[1]); -- System.out.println(c.get()); -- } -- } program : String → IOConsole Unit program arg = let c₀ = parrotP (cellP "Start") in method c₀ get >>= λ{ (s , c₁) → exec1 (putStrLn s) >> method c₁ (put arg) >>= λ{ (_ , c₂) → method c₂ get >>= λ{ (s' , c₃) → exec1 (putStrLn s') }}} main : NativeIO Unit main = translateIOConsole (program "hello")
{ "alphanum_fraction": 0.6059082338, "avg_line_length": 24.859375, "ext": "agda", "hexsha": "49a7b6ba263721bd63e7c44226baef38b0f11689", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z", "max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "agda/ooAgda", "max_forks_repo_path": "examples/UnSized/Parrot.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "agda/ooAgda", "max_issues_repo_path": "examples/UnSized/Parrot.agda", "max_line_length": 76, "max_stars_count": 23, "max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/ooAgda", "max_stars_repo_path": "examples/UnSized/Parrot.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z", "num_tokens": 480, "size": 1591 }
module ExtendedLam where data Bool : Set where false : Bool true : Bool f : Bool → Bool → Bool f = λ { x false → true ; y true → y }
{ "alphanum_fraction": 0.4914285714, "avg_line_length": 7.2916666667, "ext": "agda", "hexsha": "170bf666a7b88e0560788975a745837704d25f92", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z", "max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "msuperdock/agda-unused", "max_forks_repo_path": "data/expression/ExtendedLam.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "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": "msuperdock/agda-unused", "max_issues_repo_path": "data/expression/ExtendedLam.agda", "max_line_length": 24, "max_stars_count": 6, "max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "msuperdock/agda-unused", "max_stars_repo_path": "data/expression/ExtendedLam.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z", "num_tokens": 70, "size": 175 }
{- This file contains: - The quotient of finite sets by decidable equivalence relation is still finite, by using equivalence class. -} {-# OPTIONS --safe #-} module Cubical.Data.FinSet.Quotients where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv renaming (_∙ₑ_ to _⋆_) open import Cubical.Foundations.Equiv.Properties open import Cubical.Foundations.Univalence open import Cubical.HITs.PropositionalTruncation as Prop open import Cubical.HITs.SetQuotients as SetQuot open import Cubical.HITs.SetQuotients.EqClass open import Cubical.Data.Nat open import Cubical.Data.Bool open import Cubical.Data.Sigma open import Cubical.Data.SumFin open import Cubical.Data.FinSet.Base open import Cubical.Data.FinSet.Properties open import Cubical.Data.FinSet.DecidablePredicate open import Cubical.Data.FinSet.Constructors open import Cubical.Data.FinSet.Cardinality open import Cubical.Relation.Nullary open import Cubical.Relation.Nullary.DecidablePropositions open import Cubical.Relation.Binary private variable ℓ ℓ' ℓ'' : Level LiftDecProp : {ℓ ℓ' : Level}{P : Type ℓ} → (p : isDecProp P) → P ≃ Bool→Type* {ℓ'} (p .fst) LiftDecProp p = p .snd ⋆ BoolProp≃BoolProp* open Iso module _ (X : Type ℓ) where ℙEff : Type ℓ ℙEff = X → Bool isSetℙEff : isSet ℙEff isSetℙEff = isSetΠ (λ _ → isSetBool) ℙEff→ℙDec : ℙEff → ℙDec {ℓ' = ℓ'} X ℙEff→ℙDec f .fst x = Bool→Type* (f x) , isPropBool→Type* ℙEff→ℙDec f .snd x = DecBool→Type* Iso-ℙEff-ℙDec : Iso ℙEff (ℙDec {ℓ' = ℓ'} X) Iso-ℙEff-ℙDec .fun = ℙEff→ℙDec Iso-ℙEff-ℙDec .inv (P , dec) x = Dec→Bool (dec x) Iso-ℙEff-ℙDec {ℓ' = ℓ'} .leftInv f i x = Bool≡BoolDec* {ℓ = ℓ'} {a = f x} (~ i) Iso-ℙEff-ℙDec .rightInv (P , dec) i .fst x .fst = ua (Dec≃DecBool* (P x .snd) (dec x)) (~ i) Iso-ℙEff-ℙDec .rightInv (P , dec) i .fst x .snd = isProp→PathP {B = λ i → isProp (Iso-ℙEff-ℙDec .rightInv (P , dec) i .fst x .fst)} (λ i → isPropIsProp) (Iso-ℙEff-ℙDec .fun (Iso-ℙEff-ℙDec .inv (P , dec)) .fst x .snd) (P x .snd) i Iso-ℙEff-ℙDec .rightInv (P , dec) i .snd x = isProp→PathP {B = λ i → Dec (Iso-ℙEff-ℙDec .rightInv (P , dec) i .fst x .fst)} (λ i → isPropDec (Iso-ℙEff-ℙDec .rightInv (P , dec) i .fst x .snd)) (Iso-ℙEff-ℙDec .fun (Iso-ℙEff-ℙDec .inv (P , dec)) .snd x) (dec x) i ℙEff≃ℙDec : ℙEff ≃ (ℙDec {ℓ' = ℓ'} X) ℙEff≃ℙDec = isoToEquiv Iso-ℙEff-ℙDec module _ (X : Type ℓ)(p : isFinOrd X) where private e = p .snd isFinOrdℙEff : isFinOrd (ℙEff X) isFinOrdℙEff = _ , preCompEquiv (invEquiv e) ⋆ SumFinℙ≃ _ module _ (X : FinSet ℓ) where isFinSetℙEff : isFinSet (ℙEff (X .fst)) isFinSetℙEff = 2 ^ (card X) , Prop.elim (λ _ → isPropPropTrunc {A = _ ≃ Fin _}) (λ p → ∣ isFinOrdℙEff (X .fst) (_ , p) .snd ∣) (X .snd .snd) module _ (X : FinSet ℓ) (R : X .fst → X .fst → Type ℓ') (dec : (x x' : X .fst) → isDecProp (R x x')) where isEqClassEff : ℙEff (X .fst) → Type ℓ isEqClassEff f = ∥ Σ[ x ∈ X .fst ] ((a : X .fst) → f a ≡ dec a x .fst) ∥ isDecPropIsEqClassEff : {f : ℙEff (X .fst)} → isDecProp (isEqClassEff f) isDecPropIsEqClassEff = isDecProp∃ X (λ _ → _ , isDecProp∀ X (λ _ → _ , _ , Bool≡≃ _ _)) isEqClassEff→isEqClass' : (f : ℙEff (X .fst))(x : X .fst) → ((a : X .fst) → f a ≡ dec a x .fst) → (a : X .fst) → Bool→Type* {ℓ = ℓ'} (f a) ≃ ∥ R a x ∥ isEqClassEff→isEqClass' f x h a = pathToEquiv (cong Bool→Type* (h a)) ⋆ invEquiv (LiftDecProp (dec a x)) ⋆ invEquiv (propTruncIdempotent≃ (isDecProp→isProp (dec a x))) isEqClass→isEqClassEff' : (f : ℙEff (X .fst))(x : X .fst) → ((a : X .fst) → Bool→Type* {ℓ = ℓ'} (f a) ≃ ∥ R a x ∥) → (a : X .fst) → f a ≡ dec a x .fst isEqClass→isEqClassEff' f x h a = Bool→TypeInj* _ _ (h a ⋆ propTruncIdempotent≃ (isDecProp→isProp (dec a x)) ⋆ LiftDecProp (dec a x)) isEqClassEff→isEqClass : (f : ℙEff (X .fst)) → isEqClassEff f ≃ isEqClass {ℓ' = ℓ'} _ R (ℙEff→ℙDec _ f .fst) isEqClassEff→isEqClass f = propBiimpl→Equiv isPropPropTrunc isPropPropTrunc (Prop.map (λ (x , p) → x , isEqClassEff→isEqClass' f x p)) (Prop.map (λ (x , p) → x , isEqClass→isEqClassEff' f x p)) _∥Eff_ : Type ℓ _∥Eff_ = Σ[ f ∈ ℙEff (X .fst) ] isEqClassEff f ∥Eff≃∥Dec : _∥Eff_ ≃ _∥Dec_ (X .fst) R (λ x x' → isDecProp→Dec (dec x x')) ∥Eff≃∥Dec = Σ-cong-equiv (ℙEff≃ℙDec (X .fst)) isEqClassEff→isEqClass isFinSet∥Eff : isFinSet _∥Eff_ isFinSet∥Eff = isFinSetSub (_ , isFinSetℙEff X) (λ _ → _ , isDecPropIsEqClassEff) open BinaryRelation module _ (X : FinSet ℓ) (R : X .fst → X .fst → Type ℓ') (h : isEquivRel R) (dec : (x x' : X .fst) → isDecProp (R x x')) where isFinSetQuot : isFinSet (X .fst / R) isFinSetQuot = EquivPresIsFinSet ( ∥Eff≃∥Dec X _ dec ⋆ ∥Dec≃∥ _ _ (λ x x' → isDecProp→Dec (dec x x')) ⋆ invEquiv (equivQuot {ℓ' = ℓ'} _ _ h)) (isFinSet∥Eff X _ dec)
{ "alphanum_fraction": 0.6334669339, "avg_line_length": 33.2666666667, "ext": "agda", "hexsha": "d376366b6d9ccf172cfbacdd6b6bf0e24fc14093", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "howsiyu/cubical", "max_forks_repo_path": "Cubical/Data/FinSet/Quotients.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "howsiyu/cubical", "max_issues_repo_path": "Cubical/Data/FinSet/Quotients.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "howsiyu/cubical", "max_stars_repo_path": "Cubical/Data/FinSet/Quotients.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2130, "size": 4990 }
open import Data.Nat using (ℕ; zero; suc; _+_; _*_) open import Data.Product using (∃; _,_) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym) +-identity : ∀ (m : ℕ) → m + zero ≡ m +-identity zero = refl +-identity (suc m) rewrite +-identity m = refl +-suc : ∀ (m n : ℕ) → n + suc m ≡ suc (n + m) +-suc m zero = refl +-suc m (suc n) rewrite +-suc m n = refl +-comm : ∀ (m n : ℕ) → m + n ≡ n + m +-comm zero n rewrite +-identity n = refl +-comm (suc m) n rewrite +-suc m n | +-comm m n = refl mutual data even : ℕ → Set where zero : even zero suc : ∀ {n : ℕ} → odd n → even (suc n) data odd : ℕ → Set where suc : ∀ {n : ℕ} → even n → odd (suc n) +-lemma : ∀ (m : ℕ) → suc (suc (m + (m + 0))) ≡ suc m + suc (m + 0) +-lemma m rewrite +-identity m | +-suc m m = refl mutual is-even : ∀ (n : ℕ) → even n → ∃(λ (m : ℕ) → n ≡ 2 * m) is-even zero zero = zero , refl is-even (suc n) (suc oddn) with is-odd n oddn ... | m , n≡1+2*m rewrite n≡1+2*m | +-lemma m = suc m , refl is-odd : ∀ (n : ℕ) → odd n → ∃(λ (m : ℕ) → n ≡ 1 + 2 * m) is-odd (suc n) (suc evenn) with is-even n evenn ... | m , n≡2*m rewrite n≡2*m = m , refl +-lemma′ : ∀ (m : ℕ) → suc (suc (m + (m + 0))) ≡ suc m + suc (m + 0) +-lemma′ m rewrite +-suc (m + 0) m = refl is-even′ : ∀ (n : ℕ) → even n → ∃(λ (m : ℕ) → n ≡ 2 * m) is-even′ zero zero = zero , refl is-even′ (suc n) (suc oddn) with is-odd n oddn ... | m , n≡1+2*m rewrite n≡1+2*m | +-identity m | +-suc m m = suc m , {!!}
{ "alphanum_fraction": 0.5206666667, "avg_line_length": 33.3333333333, "ext": "agda", "hexsha": "a36e33cd3976ebca247d1e9b37e900187db2559a", "lang": "Agda", "max_forks_count": 304, "max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z", "max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z", "max_forks_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "manikdv/plfa.github.io", "max_forks_repo_path": "extra/extra/EvenOdd.agda", "max_issues_count": 323, "max_issues_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z", "max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z", "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "manikdv/plfa.github.io", "max_issues_repo_path": "extra/extra/EvenOdd.agda", "max_line_length": 75, "max_stars_count": 1003, "max_stars_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "manikdv/plfa.github.io", "max_stars_repo_path": "extra/extra/EvenOdd.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z", "max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z", "num_tokens": 634, "size": 1500 }
open import Relation.Binary.Core module Mergesort.Everything {A : Set} (_≤_ : A → A → Set) (tot≤ : Total _≤_) where open import Mergesort.Impl1.Correctness.Order _≤_ tot≤ open import Mergesort.Impl1.Correctness.Permutation _≤_ tot≤ open import Mergesort.Impl2.Correctness.Order _≤_ tot≤ open import Mergesort.Impl2.Correctness.Permutation _≤_ tot≤
{ "alphanum_fraction": 0.7002583979, "avg_line_length": 32.25, "ext": "agda", "hexsha": "f67258cee666bd4e1fedbf6dec9533442885941b", "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/Mergesort/Everything.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/Mergesort/Everything.agda", "max_line_length": 60, "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/Mergesort/Everything.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": 132, "size": 387 }
import Data.Bool import Relation.Nullary.Negation import Relation.Nullary.Decidable
{ "alphanum_fraction": 0.8390804598, "avg_line_length": 12.4285714286, "ext": "agda", "hexsha": "09af6fb8f97068857d12991e937e79613651d0d7", "lang": "Agda", "max_forks_count": 304, "max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z", "max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z", "max_forks_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "manikdv/plfa.github.io", "max_forks_repo_path": "extra/extra/Dummy.agda", "max_issues_count": 323, "max_issues_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z", "max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z", "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "manikdv/plfa.github.io", "max_issues_repo_path": "extra/extra/Dummy.agda", "max_line_length": 33, "max_stars_count": 1003, "max_stars_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "manikdv/plfa.github.io", "max_stars_repo_path": "extra/extra/Dummy.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z", "max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z", "num_tokens": 19, "size": 87 }
------------------------------------------------------------------------ -- Library parsers which do not require the complicated setup used in -- RecursiveDescent.Inductive.Lib ------------------------------------------------------------------------ -- This module also provides more examples of parsers for which the -- indices cannot be inferred. module RecursiveDescent.Inductive.SimpleLib where open import RecursiveDescent.Inductive open import RecursiveDescent.Index open import Data.Nat open import Data.Vec hiding (_⊛_; _>>=_) open import Data.Vec1 using (Vec₁; []; _∷_) open import Data.List using (List; []; _∷_) open import Relation.Nullary open import Data.Product.Record hiding (_×_) open import Data.Product using (_×_) renaming (_,_ to pair) open import Data.Bool open import Data.Function open import Data.Maybe open import Data.Unit open import Data.Bool.Properties as Bool open import Algebra private module BCS = CommutativeSemiring Bool.commutativeSemiring-∨-∧ open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------ -- Applicative functor parsers -- We could get these for free with better library support. infixl 50 _⊛_ _⊛!_ _<⊛_ _⊛>_ _<$>_ _<$_ _⊗_ _⊗!_ _⊛_ : forall {tok nt i₁ i₂ r₁ r₂} -> Parser tok nt i₁ (r₁ -> r₂) -> Parser tok nt i₂ r₁ -> Parser tok nt _ r₂ p₁ ⊛ p₂ = p₁ >>= \f -> p₂ >>= \x -> return (f x) -- A variant: If the second parser does not accept the empty string, -- then neither does the combination. (This is immediate for the first -- parser, but for the second one a small lemma is needed, hence this -- variant.) _⊛!_ : forall {tok nt i₁ c₂ r₁ r₂} -> Parser tok nt i₁ (r₁ -> r₂) -> Parser tok nt (false , c₂) r₁ -> Parser tok nt (false , _) r₂ _⊛!_ {i₁ = i₁} p₁ p₂ = cast (BCS.*-comm (proj₁ i₁) false) refl (p₁ ⊛ p₂) _<$>_ : forall {tok nt i r₁ r₂} -> (r₁ -> r₂) -> Parser tok nt i r₁ -> Parser tok nt _ r₂ f <$> x = return f ⊛ x _<⊛_ : forall {tok nt i₁ i₂ r₁ r₂} -> Parser tok nt i₁ r₁ -> Parser tok nt i₂ r₂ -> Parser tok nt _ r₁ x <⊛ y = const <$> x ⊛ y _⊛>_ : forall {tok nt i₁ i₂ r₁ r₂} -> Parser tok nt i₁ r₁ -> Parser tok nt i₂ r₂ -> Parser tok nt _ r₂ x ⊛> y = flip const <$> x ⊛ y _<$_ : forall {tok nt i r₁ r₂} -> r₁ -> Parser tok nt i r₂ -> Parser tok nt _ r₁ x <$ y = const x <$> y _⊗_ : forall {tok nt i₁ i₂ r₁ r₂} -> Parser tok nt i₁ r₁ -> Parser tok nt i₂ r₂ -> Parser tok nt _ (r₁ × r₂) p₁ ⊗ p₂ = pair <$> p₁ ⊛ p₂ _⊗!_ : forall {tok nt i₁ c₂ r₁ r₂} -> Parser tok nt i₁ r₁ -> Parser tok nt (false , c₂) r₂ -> Parser tok nt (false , _) (r₁ × r₂) p₁ ⊗! p₂ = pair <$> p₁ ⊛! p₂ ------------------------------------------------------------------------ -- Parsing sequences -- Note that the resulting index here cannot be inferred... private exactly'-corners : Corners -> ℕ -> Corners exactly'-corners c zero = _ exactly'-corners c (suc n) = _ exactly' : forall {tok nt c r} n -> Parser tok nt (false , c) r -> Parser tok nt (false , exactly'-corners c n) (Vec r (suc n)) exactly' zero p = [_] <$> p exactly' (suc n) p = _∷_ <$> p ⊛ exactly' n p -- ...so we might as well generalise the function a little. -- exactly n p parses n occurrences of p. exactly-index : Index -> ℕ -> Index exactly-index i zero = _ exactly-index i (suc n) = _ exactly : forall {tok nt i r} n -> Parser tok nt i r -> Parser tok nt (exactly-index i n) (Vec r n) exactly zero p = return [] exactly (suc n) p = _∷_ <$> p ⊛ exactly n p -- A function with a similar type: sequence : forall {tok nt i r n} -> Vec₁ (Parser tok nt i r) n -> Parser tok nt (exactly-index i n) (Vec r n) sequence [] = return [] sequence (p ∷ ps) = _∷_ <$> p ⊛ sequence ps -- p between ps parses p repeatedly, between the elements of ps: -- ∙ between (x ∷ y ∷ z ∷ []) ≈ x ∙ y ∙ z. between-corners : Corners -> ℕ -> Corners between-corners c′ zero = _ between-corners c′ (suc n) = _ _between_ : forall {tok nt i r c′ r′ n} -> Parser tok nt i r -> Vec₁ (Parser tok nt (false , c′) r′) (suc n) -> Parser tok nt (false , between-corners c′ n) (Vec r n) p between (x ∷ []) = [] <$ x p between (x ∷ y ∷ xs) = _∷_ <$> (x ⊛> p) ⊛ (p between (y ∷ xs)) ------------------------------------------------------------------------ -- N-ary variants of _∣_ -- choice ps parses one of the elements in ps. choice-corners : Corners -> ℕ -> Corners choice-corners c zero = _ choice-corners c (suc n) = _ choice : forall {tok nt c r n} -> Vec₁ (Parser tok nt (false , c) r) n -> Parser tok nt (false , choice-corners c n) r choice [] = fail choice (p ∷ ps) = p ∣ choice ps -- choiceMap f xs ≈ choice (map f xs), but avoids use of Vec₁ and -- fromList. choiceMap-corners : forall {a} -> (a -> Corners) -> List a -> Corners choiceMap-corners c [] = _ choiceMap-corners c (x ∷ xs) = _ choiceMap : forall {tok nt r a} {c : a -> Corners} -> ((x : a) -> Parser tok nt (false , c x) r) -> (xs : List a) -> Parser tok nt (false , choiceMap-corners c xs) r choiceMap f [] = fail choiceMap f (x ∷ xs) = f x ∣ choiceMap f xs ------------------------------------------------------------------------ -- sat and friends sat : forall {tok nt r} -> (tok -> Maybe r) -> Parser tok nt (0I ·I 1I) r sat {tok} {nt} {r} p = symbol !>>= \c -> ok (p c) where okIndex : Maybe r -> Index okIndex nothing = _ okIndex (just _) = _ ok : (x : Maybe r) -> Parser tok nt (okIndex x) r ok nothing = fail ok (just x) = return x sat' : forall {tok nt} -> (tok -> Bool) -> Parser tok nt _ ⊤ sat' p = sat (boolToMaybe ∘ p) any : forall {tok nt} -> Parser tok nt _ tok any = sat just
{ "alphanum_fraction": 0.5456823117, "avg_line_length": 31.1822916667, "ext": "agda", "hexsha": "d557577f214eccc3980bfa2a327257a9a9f6f621", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_path": "misc/RecursiveDescent/Inductive/SimpleLib.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z", "max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_path": "misc/RecursiveDescent/Inductive/SimpleLib.agda", "max_line_length": 72, "max_stars_count": 7, "max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yurrriq/parser-combinators", "max_stars_repo_path": "misc/RecursiveDescent/Inductive/SimpleLib.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z", "num_tokens": 1833, "size": 5987 }
------------------------------------------------------------------------------ -- The Collatz function: A function without a termination proof ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.Collatz.Collatz where open import FOTC.Base open import FOTC.Data.Nat open import FOTC.Data.Nat.UnaryNumbers open import FOTC.Program.Collatz.Data.Nat ------------------------------------------------------------------------------ -- The Collatz function. postulate collatz : D → D collatz-0 : collatz 0' ≡ 1' collatz-1 : collatz 1' ≡ 1' collatz-even : ∀ {n} → Even (succ₁ (succ₁ n)) → collatz (succ₁ (succ₁ n)) ≡ collatz (div (succ₁ (succ₁ n)) 2') collatz-noteven : ∀ {n} → NotEven (succ₁ (succ₁ n)) → collatz (succ₁ (succ₁ n)) ≡ collatz (3' * (succ₁ (succ₁ n)) + 1') {-# ATP axioms collatz-0 collatz-1 collatz-even collatz-noteven #-}
{ "alphanum_fraction": 0.4543125534, "avg_line_length": 39.0333333333, "ext": "agda", "hexsha": "ffc351e62e9cadd0ac38262e252ff480344f036e", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Program/Collatz/Collatz.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Program/Collatz/Collatz.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Program/Collatz/Collatz.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 285, "size": 1171 }
open import Signature import Program module Observations (Σ : Sig) (V : Set) (P : Program.Program Σ V) where open import Terms Σ open import Program Σ V open import Rewrite Σ V P open import Relation.Nullary open import Relation.Unary open import Data.Product as Prod renaming (Σ to ⨿) NonTrivial : T V → Pred (Subst V V) _ NonTrivial t σ = ∃ λ v → (v ∈ fv t) × ¬ isVar (σ v) {- | We can make an observation according to the following rule. t ↓ s fv(s) ≠ ∅ ∃ k, σ. s ~[σ]~ Pₕ(k) -------------------------------------------- t ----> t[σ] -} data _↦_ (t : T V) : T V → Set where obs-step : {s : T V} → t ↓ s → ¬ Empty (fv s) → (cl : dom P) {σ : Subst V V} → mgu s (geth P cl) σ → t ↦ app σ t GroundTerm : Pred (T V) _ GroundTerm t = Empty (fv t) -------- -- FLAW: This does not allow us to distinguish between inductive -- and coinductive definitions on the clause level. -- The following definitions are _global_ for a derivation! ------- data IndDerivable (t : T V) : Set where ground : GroundTerm t → Valid t → IndDerivable t der-step : (s : T V) → t ↦ s → IndDerivable s → IndDerivable t record CoindDerivable (t : T V) : Set where coinductive field term-SN : SN t der-obs : ⨿ (T V) λ s → t ↦ s × CoindDerivable s open CoindDerivable record _↥[_]_ (t : T V) (σ : Subst∞ V V) (s : T∞ V) : Set where coinductive field conv-match : app∞ σ (χ t) ~ s conv-step : ⨿ (T V) λ t₁ → t ↦ t₁ × t₁ ↥[ ? ] s coind-converges-to : (t : T V) → CoindDerivable t → T∞ V out (coind-converges-to t p) with der-obs p ... | (._ , obs-step t↓s _ cl {σ} _ , q) = {!!} coind-converges : (t : T V) → CoindDerivable t → ∃₂ λ s σ → Empty (fv∞ s) × t ↥[ σ ] s coind-converges = {!!}
{ "alphanum_fraction": 0.5738636364, "avg_line_length": 28.8524590164, "ext": "agda", "hexsha": "8d5c253d90e494bf35e72fb32f757e9a22f3a749", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_path": "LP2/Observations.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_path": "LP2/Observations.agda", "max_line_length": 71, "max_stars_count": null, "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_path": "LP2/Observations.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 630, "size": 1760 }
module Categories.Functor.Coalgebras where
{ "alphanum_fraction": 0.8837209302, "avg_line_length": 21.5, "ext": "agda", "hexsha": "730e93306eb706ef52ae4bdc83d78ceccf701683", "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/Coalgebras.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/Coalgebras.agda", "max_line_length": 42, "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/Coalgebras.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": 11, "size": 43 }
-- Andreas, 2015-11-19 Issue 1692 -- With-abstract also in types of variables mentioned in with-expressions -- unless they are also mentioned in the types of the with-expressions. -- {-# OPTIONS -v tc.with:40 #-} open import Common.Equality postulate A : Set a : A test : (dummy : A) (f : ∀ x → a ≡ x) (b : A) → b ≡ a test dummy f b rewrite f b = f b -- WAS: -- The `a` is not with-abstracted in the type of `f`, as `f` occurs -- in the rewrite expression `f b : a ≡ b`. -- NOW: with abstracts also in type of f, changing it to (f : ∀ x → b ≡ x) test-with : (f : ∀ x → a ≡ x) (b : A) → b ≡ a test-with f b with a | f b test-with f b | .b | refl = f b -- WAS: -- Manually, we can construct what `magic with` DID not do: -- abstract `a` also in the type of `f`, even though `f` is part of the -- rewrite expression. bla : (f : ∀ x → a ≡ x) (b : A) → b ≡ a bla f b = aux b a (f b) f where aux : (b w : A) (p : w ≡ b) (f : ∀ x → w ≡ x) → b ≡ w aux b .b refl f = f b
{ "alphanum_fraction": 0.5776649746, "avg_line_length": 27.3611111111, "ext": "agda", "hexsha": "f69457802d5299c0cbe746fcc1eecc6a143cfb51", "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/Issue1692a.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/Issue1692a.agda", "max_line_length": 74, "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/Issue1692a.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": 361, "size": 985 }
module STLC4 where open import Data.Nat open import Data.Nat.Properties using (≤-antisym; ≤-trans; ≰⇒>; ≤-step) -- open import Data.List open import Data.Empty using (⊥-elim) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong; cong₂; subst) open import Relation.Nullary.Decidable using (map) open import Relation.Nullary open import Data.Product -- de Bruijn indexed lambda calculus infix 5 ƛ_ infixl 7 _∙_ infix 9 var_ data Term : Set where var_ : (x : ℕ) → Term ƛ_ : Term → Term _∙_ : Term → Term → Term shift : (n i : ℕ) → Term → Term shift free i (var x) with x ≥? free shift free i (var x) | yes p = var (x + i) -- free shift free i (var x) | no ¬p = var x -- bound shift free i (ƛ M) = ƛ shift (suc free) i M shift free i (M ∙ N) = shift free i M ∙ shift free i N infixl 10 _[_/_] _[_/_] : Term → Term → ℕ → Term (var x) [ N / i ] with compare x i ((var x) [ N / .(suc (x + k)) ]) | less .x k = var x ((var x) [ N / .x ]) | equal .x = shift 0 x N ((var .(suc (i + k))) [ N / i ]) | greater .i k = var (i + k) (ƛ M) [ N / i ] = ƛ (M [ N / suc i ]) (L ∙ M) [ N / i ] = L [ N / i ] ∙ M [ N / i ] -- substitute the 0th var in M for N infixl 10 _[_] _[_] : Term → Term → Term M [ N ] = M [ N / 0 ] -- β reduction infix 3 _β→_ data _β→_ : Term → Term → Set where β-ƛ-∙ : ∀ {M N} → ((ƛ M) ∙ N) β→ (M [ N ]) β-ƛ : ∀ {M N} → M β→ N → ƛ M β→ ƛ N β-∙-l : ∀ {L M N} → M β→ N → M ∙ L β→ N ∙ L β-∙-r : ∀ {L M N} → M β→ N → L ∙ M β→ L ∙ N module TransRefl where -- the reflexive and transitive closure of _β→_ infix 2 _β→*_ infixr 2 _→*_ data _β→*_ : Term → Term → Set where ∎ : ∀ {M} → M β→* M _→*_ : ∀ {L M N} → L β→ M → M β→* N -------------- → L β→* N infixl 3 _<β>_ _<β>_ : ∀ {M N O} → M β→* N → N β→* O → M β→* O _<β>_ {M} {.M} {O} ∎ N→O = N→O _<β>_ {M} {N} {O} (L→M →* M→N) N→O = L→M →* M→N <β> N→O infixr 2 _→⟨⟩_ _→⟨⟩_ : ∀ {M} → ∀ N → N β→* M -------------- → N β→* M M →⟨⟩ Q = Q infixr 2 _→⟨_⟩_ _→⟨_⟩_ : ∀ {M N} → ∀ L → L β→ M → M β→* N -------------- → L β→* N L →⟨ P ⟩ Q = P →* Q infixr 2 _→*⟨_⟩_ _→*⟨_⟩_ : ∀ {M N} → ∀ L → L β→* M → M β→* N -------------- → L β→* N L →*⟨ P ⟩ Q = P <β> Q infix 3 _→∎ _→∎ : ∀ M → M β→* M M →∎ = ∎ hop : ∀ {M N} → M β→ N → M β→* N hop {M} {N} M→N = M→N →* ∎ open TransRefl -- the symmetric closure of _β→*_ module Eq where infix 1 _β≡_ data _β≡_ : Term → Term → Set where β-sym : ∀ {M N} → M β→* N → N β→* M ------- → M β≡ N infixr 2 _=*⟨_⟩_ _=*⟨_⟩_ : ∀ {M N} → ∀ L → L β≡ M → M β≡ N -------------- → L β≡ N L =*⟨ β-sym A B ⟩ β-sym C D = β-sym (A <β> C) (D <β> B) infixr 2 _=*⟨⟩_ _=*⟨⟩_ : ∀ {N} → ∀ L → L β≡ N -------------- → L β≡ N L =*⟨⟩ β-sym C D = β-sym C D infix 3 _=∎ _=∎ : ∀ M → M β≡ M M =∎ = β-sym ∎ ∎ forward : ∀ {M N} → M β≡ N → M β→* N forward (β-sym A _) = A backward : ∀ {M N} → M β≡ N → N β→* M backward (β-sym _ B) = B module Example where test-1 : ƛ (ƛ var 1) ∙ var 0 β→* ƛ var 0 test-1 = ƛ (ƛ var 1) ∙ var 0 →⟨ β-ƛ β-ƛ-∙ ⟩ ƛ var 0 →∎ test-0 : ƛ (ƛ var 0 ∙ var 1) ∙ (ƛ var 0 ∙ var 1) β→* ƛ var 0 ∙ var 0 test-0 = ƛ (ƛ var 0 ∙ var 1) ∙ (ƛ var 0 ∙ var 1) →⟨ β-ƛ β-ƛ-∙ ⟩ ƛ (var 0 ∙ var 1) [ ƛ var 0 ∙ var 1 ] →⟨⟩ ƛ (var 0 ∙ var 1) [ ƛ var 0 ∙ var 1 / 0 ] →⟨⟩ ƛ (var 0) [ ƛ var 0 ∙ var 1 / 0 ] ∙ (var 1) [ ƛ var 0 ∙ var 1 / 0 ] →⟨⟩ ƛ shift 0 0 (ƛ var 0 ∙ var 1) ∙ var 0 →⟨⟩ ƛ (ƛ shift 1 0 (var 0 ∙ var 1)) ∙ var 0 →⟨⟩ ƛ (ƛ shift 1 0 (var 0) ∙ shift 1 0 (var 1)) ∙ var 0 →⟨⟩ ƛ ((ƛ var 0 ∙ var 1) ∙ var 0) →⟨ β-ƛ β-ƛ-∙ ⟩ ƛ (var 0 ∙ var 1) [ var 0 / 0 ] →⟨⟩ ƛ var 0 ∙ var 0 →∎ Z : Term Z = ƛ ƛ var 0 SZ : Term SZ = ƛ ƛ var 1 ∙ var 0 PLUS : Term PLUS = ƛ ƛ ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0) test-2 : PLUS ∙ Z ∙ SZ β→* SZ test-2 = PLUS ∙ Z ∙ SZ →⟨ β-∙-l β-ƛ-∙ ⟩ (ƛ ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 0 ] ∙ SZ →⟨⟩ (ƛ ((ƛ ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 1 ])) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 2 ])) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ ((var 3 ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)) [ ƛ ƛ var 0 / 3 ])))) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ (ƛ (ƛ var 0)) ∙ var 1 ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ →⟨ β-∙-l (β-ƛ (β-ƛ (β-ƛ (β-∙-l β-ƛ-∙)))) ⟩ (ƛ (ƛ (ƛ (ƛ var 0) [ var 1 / 0 ] ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ (ƛ (var 0) [ var 1 / 1 ]) ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ (ƛ var 0) ∙ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ →⟨ β-∙-l (β-ƛ (β-ƛ (β-ƛ β-ƛ-∙))) ⟩ (ƛ (ƛ (ƛ (var 0) [ var 2 ∙ var 1 ∙ var 0 / 0 ]))) ∙ SZ →⟨⟩ (ƛ (ƛ (ƛ (var 2 ∙ var 1 ∙ var 0)))) ∙ SZ →⟨ β-ƛ-∙ ⟩ (ƛ (ƛ (var 2 ∙ var 1 ∙ var 0))) [ SZ / 0 ] →⟨⟩ ƛ (ƛ (var 2 ∙ var 1 ∙ var 0) [ SZ / 2 ]) →⟨⟩ ƛ (ƛ shift 0 2 SZ ∙ var 1 ∙ var 0) →⟨⟩ ƛ (ƛ (ƛ ƛ var 1 ∙ var 0) ∙ var 1 ∙ var 0) →⟨ β-ƛ (β-ƛ (β-∙-l β-ƛ-∙)) ⟩ ƛ (ƛ (ƛ var 1 ∙ var 0) [ var 1 / 0 ] ∙ var 0) →⟨⟩ ƛ (ƛ (ƛ ((var 1 ∙ var 0) [ var 1 / 1 ])) ∙ var 0) →⟨⟩ ƛ (ƛ (ƛ ((var 1) [ var 1 / 1 ] ∙ (var 0) [ var 1 / 1 ])) ∙ var 0) →⟨⟩ ƛ (ƛ (ƛ (shift 0 1 (var 1) ∙ var 0)) ∙ var 0) →⟨⟩ ƛ (ƛ (ƛ (var 2 ∙ var 0)) ∙ var 0) →⟨ β-ƛ (β-ƛ β-ƛ-∙) ⟩ ƛ (ƛ (var 2 ∙ var 0) [ var 0 / 0 ]) →⟨⟩ ƛ (ƛ (var 2) [ var 0 / 0 ] ∙ var 0) →⟨⟩ ƛ (ƛ var 1 ∙ var 0) →∎ -- lemmas cong-ƛ : {M N : Term} → M β→* N → ƛ M β→* ƛ N cong-ƛ ∎ = ∎ cong-ƛ (M→N →* N→O) = β-ƛ M→N →* cong-ƛ N→O cong-∙-l : {L M N : Term} → M β→* N → M ∙ L β→* N ∙ L cong-∙-l ∎ = ∎ cong-∙-l (M→N →* N→O) = β-∙-l M→N →* cong-∙-l N→O cong-∙-r : {L M N : Term} → M β→* N → L ∙ M β→* L ∙ N cong-∙-r ∎ = ∎ cong-∙-r (M→N →* N→O) = β-∙-r M→N →* cong-∙-r N→O -- shift-subst : ∀ freeM i n M N → (shift (suc (suc free)) i M) [ shift free i N / n ] β→* shift (suc free) i (M [ N / n ]) -- -- N ---- shfit n ---> N' -- | | -- M[_] shfit n+2 [_] -- | | -- M[N] ---- shfit n+1 ---> N' -- shift-subst : ∀ free i n M N → (shift (suc (suc free)) i M) [ shift free i N / n ] β→* shift (suc free) i (M [ N / n ]) shift-subst free i n (var x) N with compare x n shift-subst free i .(suc (x + k)) (var x) N | less .x k with x ≥? suc free shift-subst free i .(suc (x + k)) (var x) N | less .x k | yes p with suc (suc free) ≤? x shift-subst free i .(suc (x + k)) (var x) N | less .x k | yes p | yes q = {! !} shift-subst free i .(suc (x + k)) (var x) N | less .x k | yes p | no ¬q = {! !} shift-subst free i .(suc (x + k)) (var x) N | less .x k | no ¬p = {! !} shift-subst free i n (var .n) N | equal .n = {! !} shift-subst free i n (var .(suc (n + k))) N | greater .n k = {! !} shift-subst free i n (ƛ M) N = ƛ (shift (suc (suc (suc free))) i M [ shift free i N / suc n ]) →*⟨ cong-ƛ {! shift-subst (suc free) i (suc n) M N !} ⟩ {! !} →*⟨ {! !} ⟩ ƛ (shift (suc (suc (suc free))) i M [ shift (suc free) i N / suc n ]) →*⟨ cong-ƛ (shift-subst (suc free) i (suc n) M N) ⟩ ƛ (shift (suc (suc free)) i (M [ N / suc n ])) →∎ shift-subst free i n (M ∙ L) N = shift (suc (suc free)) i M [ shift free i N / n ] ∙ shift (suc (suc free)) i L [ shift free i N / n ] →*⟨ cong-∙-l (shift-subst free i n M N) ⟩ shift (suc free) i (M [ N / n ]) ∙ shift (suc (suc free)) i L [ shift free i N / n ] →*⟨ cong-∙-r (shift-subst free i n L N) ⟩ shift (suc free) i (M [ N / n ]) ∙ shift (suc free) i (L [ N / n ]) →∎ cong-shift-app0 : (free i : ℕ) → (M N : Term) → shift free i ((ƛ M) ∙ N) β→* shift free i (M [ N ]) cong-shift-app0 free i (var x) N = {! !} cong-shift-app0 free i (ƛ M) N = (ƛ (ƛ shift (suc (suc free)) i M)) ∙ shift free i N →*⟨ hop β-ƛ-∙ ⟩ (ƛ shift (suc (suc free)) i M) [ shift free i N / 0 ] →⟨⟩ ƛ (shift (suc (suc free)) i M) [ shift free i N / 1 ] →*⟨ cong-ƛ (shift-subst free i _ M N) ⟩ ƛ shift (suc free) i (M [ N / 1 ]) →∎ cong-shift-app0 free i (M ∙ L) N = (ƛ shift (suc free) i M ∙ shift (suc free) i L) ∙ shift free i N →*⟨ cong-∙-l {! cong-shift-app0 free i M L !} ⟩ {! !} ∙ shift free i N →*⟨ {! !} ⟩ {! !} →*⟨ {! !} ⟩ {! !} →*⟨ {! !} ⟩ shift free i (M [ N ]) ∙ shift free i (L [ N ]) →∎ -- cong-shift-app : (free i : ℕ) → (M N : Term) → shift free i ((ƛ M) ∙ N) β→* shift free i (M [ N ]) -- cong-shift-app free i (var x) (var y) = {! !} -- cong-shift-app free i (var x) (ƛ N) = {! !} -- cong-shift-app free i (var x) (N ∙ O) = {! !} -- cong-shift-app free i (ƛ M) (var y) = {! !} -- cong-shift-app free i (ƛ M) (ƛ N) = {! !} -- cong-shift-app free i (ƛ M) (N ∙ O) = {! !} -- cong-shift-app free i (M ∙ L) (var y) = {! !} -- cong-shift-app free i (M ∙ L) (ƛ N) = {! !} -- cong-shift-app free i (M ∙ L) (N ∙ O) = {! !} cong-shift : (free i : ℕ) → (M N : Term) → M β→ N → shift free i M β→* shift free i N cong-shift free i (ƛ M) (ƛ N) (β-ƛ M→N) = cong-ƛ (cong-shift (suc free) i M N M→N) cong-shift free i (.(ƛ M) ∙ N) .(M [ N / 0 ]) (β-ƛ-∙ {M}) = cong-shift-app0 free i M N cong-shift free i (M ∙ L) .(N ∙ L) (β-∙-l {N = N} M→N) = cong-∙-l (cong-shift free i M N M→N) cong-shift free i (M ∙ L) .(M ∙ N) (β-∙-r {N = N} M→N) = cong-∙-r (cong-shift free i L N M→N) cong-[] : ∀ {i M N} (L : Term) → M β→ N → L [ M / i ] β→* L [ N / i ] cong-[] {i} (var x) M→N with compare x i cong-[] {.(suc (x + k))} (var x) M→N | less .x k = ∎ cong-[] {.x} {M} {N} (var x) M→N | equal .x = cong-shift 0 x M N M→N cong-[] {.m} (var .(suc (m + k))) M→N | greater m k = ∎ cong-[] (ƛ L) M→N = cong-ƛ (cong-[] L M→N) cong-[] {i} {M} {N} (L ∙ K) M→N = L [ M / i ] ∙ K [ M / i ] →*⟨ cong-∙-l (cong-[] L M→N) ⟩ L [ N / i ] ∙ K [ M / i ] →*⟨ cong-∙-r (cong-[] K M→N) ⟩ L [ N / i ] ∙ K [ N / i ] →∎ lemma : ∀ {M N O} → ƛ M β→ N → M [ O ] β→* N ∙ O lemma {ƛ M} (β-ƛ {N = ƛ N} M→N) = {! !} lemma {M ∙ L} (β-ƛ {N = var x} M→N) = {! !} lemma {M ∙ L} (β-ƛ {N = ƛ N} M→N) = {! !} lemma {M ∙ L} (β-ƛ {N = N ∙ K} M→N) = {! !} -- single-step β→confluent : ∀ {M N O} → (M β→ N) → (M β→ O) → ∃ (λ P → (N β→* P) × (O β→* P)) β→confluent (β-ƛ-∙ {M} {N}) β-ƛ-∙ = M [ N ] , ∎ , ∎ β→confluent (β-ƛ-∙ {M} {N}) (β-∙-l {N = O} M→O) = {! !} -- O ∙ N , lemma M→O , ∎ β→confluent (β-ƛ-∙ {M} {N}) (β-∙-r {N = O} M→O) = M [ O ] , cong-[] M M→O , hop β-ƛ-∙ β→confluent (β-ƛ {M} {N} M→N) (β-ƛ {N = O} M→O) with β→confluent M→N M→O β→confluent (β-ƛ {M} {N} M→N) (β-ƛ {N = O} M→O) | P , N→P , O→P = ƛ P , cong-ƛ N→P , cong-ƛ O→P β→confluent (β-∙-l {L} {N = N} M→N) (β-ƛ-∙ {M}) = N ∙ L , ∎ , lemma M→N β→confluent (β-∙-l {L} {M} {N} M→N) (β-∙-l {N = O} M→O) with β→confluent M→N M→O β→confluent (β-∙-l {L} {M} {N} M→N) (β-∙-l {N = O} M→O) | P , N→P , O→P = P ∙ L , cong-∙-l N→P , cong-∙-l O→P β→confluent (β-∙-l {L} {M} {N} M→N) (β-∙-r {N = O} L→O) = N ∙ O , hop (β-∙-r L→O) , hop (β-∙-l M→N) β→confluent (β-∙-r {M = M} {N} M→N) (β-ƛ-∙ {L}) = L [ N ] , (hop β-ƛ-∙) , cong-[] L M→N β→confluent (β-∙-r {L} {M} {N} M→N) (β-∙-l {N = O} M→O) = O ∙ N , hop (β-∙-l M→O) , hop (β-∙-r M→N) β→confluent (β-∙-r {M = M} {N} M→N) (β-∙-r {N = O} M→O) with β→confluent M→N M→O β→confluent (β-∙-r {L} {M} {N} M→N) (β-∙-r {N = O} M→O) | P , N→P , O→P = (L ∙ P) , cong-∙-r N→P , cong-∙-r O→P -- β→confluent : (M N O : Term) → (M β→ N) → (M β→ O) → ∃ (λ P → (N β→* P) × (O β→* P)) -- β→confluent .((ƛ _) ∙ _) ._ ._ β-ƛ-∙ β-ƛ-∙ = {! !} -- β→confluent .((ƛ _) ∙ _) ._ .(_ ∙ _) β-ƛ-∙ (β-∙-l M→O) = {! !} -- β→confluent .((ƛ _) ∙ _) ._ .((ƛ _) ∙ _) β-ƛ-∙ (β-∙-r M→O) = {! !} -- β→confluent .(ƛ _) .(ƛ _) .(ƛ _) (β-ƛ M→N) (β-ƛ M→O) = {! !} -- β→confluent .((ƛ _) ∙ _) .(_ ∙ _) ._ (β-∙-l M→N) β-ƛ-∙ = {! !} -- β→confluent .(_ ∙ _) .(_ ∙ _) .(_ ∙ _) (β-∙-l M→N) (β-∙-l M→O) = {! !} -- β→confluent .(_ ∙ _) .(_ ∙ _) .(_ ∙ _) (β-∙-l M→N) (β-∙-r M→O) = {! !} -- β→confluent .((ƛ _) ∙ _) .((ƛ _) ∙ _) ._ (β-∙-r M→N) β-ƛ-∙ = {! !} -- β→confluent .(_ ∙ _) .(_ ∙ _) .(_ ∙ _) (β-∙-r M→N) (β-∙-l M→O) = {! !} -- β→confluent .(_ ∙ M) .(_ ∙ N) .(_ ∙ O) (β-∙-r {M = M} {N} M→N) (β-∙-r {N = O} M→O) with β→confluent M N O M→N M→O -- β→confluent .(_ ∙ M) .(_ ∙ N) .(_ ∙ O) (β-∙-r {M = M} {N} M→N) (β-∙-r {N = O} M→O) | P , N→P , O→P = {! !}
{ "alphanum_fraction": 0.3949567067, "avg_line_length": 33.3316455696, "ext": "agda", "hexsha": "d155a61bc5577c54e1f0e97a5bc5b60a0c4c9e68", "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": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "banacorn/bidirectional", "max_forks_repo_path": "LC/stash/STLC4.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "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": "banacorn/bidirectional", "max_issues_repo_path": "LC/stash/STLC4.agda", "max_line_length": 130, "max_stars_count": 2, "max_stars_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "banacorn/bidirectional", "max_stars_repo_path": "LC/stash/STLC4.agda", "max_stars_repo_stars_event_max_datetime": "2020-08-25T14:05:01.000Z", "max_stars_repo_stars_event_min_datetime": "2020-08-25T07:34:40.000Z", "num_tokens": 6965, "size": 13166 }
{-# OPTIONS --without-K --safe #-} module Definition.Typed.Consequences.Reduction where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Properties open import Definition.Typed.EqRelInstance open import Definition.Typed.Consequences.Syntactic open import Definition.LogicalRelation open import Definition.LogicalRelation.Properties open import Definition.LogicalRelation.Fundamental.Reducibility open import Tools.Product -- Helper function where all reducible types can be reduced to WHNF. whNorm′ : ∀ {A Γ l} ([A] : Γ ⊩⟨ l ⟩ A) → ∃ λ B → Whnf B × Γ ⊢ A :⇒*: B whNorm′ (Uᵣ′ .⁰ 0<1 ⊢Γ) = U , Uₙ , idRed:*: (Uⱼ ⊢Γ) whNorm′ (ℕᵣ D) = ℕ , ℕₙ , D whNorm′ (Emptyᵣ D) = Empty , Emptyₙ , D whNorm′ (Unitᵣ D) = Unit , Unitₙ , D whNorm′ (ne′ K D neK K≡K) = K , ne neK , D whNorm′ (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) = Π F ▹ G , Πₙ , D whNorm′ (Σᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) = Σ F ▹ G , Σₙ , D whNorm′ (emb 0<1 [A]) = whNorm′ [A] -- Well-formed types can all be reduced to WHNF. whNorm : ∀ {A Γ} → Γ ⊢ A → ∃ λ B → Whnf B × Γ ⊢ A :⇒*: B whNorm A = whNorm′ (reducible A) -- Helper function where reducible all terms can be reduced to WHNF. whNormTerm′ : ∀ {a A Γ l} ([A] : Γ ⊩⟨ l ⟩ A) → Γ ⊩⟨ l ⟩ a ∷ A / [A] → ∃ λ b → Whnf b × Γ ⊢ a :⇒*: b ∷ A whNormTerm′ (Uᵣ x) (Uₜ A d typeA A≡A [t]) = A , typeWhnf typeA , d whNormTerm′ (ℕᵣ x) (ℕₜ n d n≡n prop) = let natN = natural prop in n , naturalWhnf natN , convRed:*: d (sym (subset* (red x))) whNormTerm′ (Emptyᵣ x) (Emptyₜ n d n≡n prop) = let emptyN = empty prop in n , ne emptyN , convRed:*: d (sym (subset* (red x))) whNormTerm′ (Unitᵣ x) (Unitₜ n d prop) = n , prop , convRed:*: d (sym (subset* (red x))) whNormTerm′ (ne (ne K D neK K≡K)) (neₜ k d (neNfₜ neK₁ ⊢k k≡k)) = k , ne neK₁ , convRed:*: d (sym (subset* (red D))) whNormTerm′ (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ f d funcF f≡f [f] [f]₁) = f , functionWhnf funcF , convRed:*: d (sym (subset* (red D))) whNormTerm′ (Σᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Σₜ p d pProd p≡p [fst] [snd]) = p , productWhnf pProd , convRed:*: d (sym (subset* (red D))) whNormTerm′ (emb 0<1 [A]) [a] = whNormTerm′ [A] [a] -- Well-formed terms can all be reduced to WHNF. whNormTerm : ∀ {a A Γ} → Γ ⊢ a ∷ A → ∃ λ b → Whnf b × Γ ⊢ a :⇒*: b ∷ A whNormTerm {a} {A} ⊢a = let [A] , [a] = reducibleTerm ⊢a in whNormTerm′ [A] [a] redMany : ∀ {t u A Γ} → Γ ⊢ t ⇒ u ∷ A → Γ ⊢ t ⇒* u ∷ A redMany d = let _ , _ , ⊢u = syntacticEqTerm (subsetTerm d) in d ⇨ id ⊢u
{ "alphanum_fraction": 0.592183182, "avg_line_length": 40.2063492063, "ext": "agda", "hexsha": "60eb4f17e15e05209dd0ef78b6ee78b0205a61b4", "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/Consequences/Reduction.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/Consequences/Reduction.agda", "max_line_length": 80, "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/Consequences/Reduction.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1127, "size": 2533 }
------------------------------------------------------------------------ -- Asymmetric choice ------------------------------------------------------------------------ module TotalParserCombinators.AsymmetricChoice where open import Data.Bool open import Data.Empty open import Data.List open import Data.List.Membership.Propositional using (_∈_) open import Data.List.Properties open import Data.List.Relation.Binary.BagAndSetEquality using () renaming (_∼[_]_ to _List-∼[_]_) open import Data.List.Relation.Unary.Any using (here) open import Data.Product import Data.Product.Function.Dependent.Propositional as Σ open import Data.Unit open import Function.Base open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence as Equiv using (module Equivalence; _⇔_) open import Function.Inverse as Inv using (_↔_) open import Function.Related as Related open import Function.Related.TypeIsomorphisms open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_) open import Relation.Nullary open import TotalParserCombinators.Congruence using (_∼[_]P_; _≅P_) open import TotalParserCombinators.Derivative using (D) open import TotalParserCombinators.Parser import TotalParserCombinators.Pointwise as Pointwise open import TotalParserCombinators.Semantics using (_∈_·_) open import TotalParserCombinators.Semantics.Continuation as S using (_⊕_∈_·_) ------------------------------------------------------------------------ -- An initial bag operator -- first-nonempty returns the left-most non-empty initial bag, if any. first-nonempty : {R : Set} → List R → List R → List R first-nonempty [] ys = ys first-nonempty xs ys = xs -- first-nonempty preserves equality. first-nonempty-cong : ∀ {k R} {xs₁ xs₁′ xs₂ xs₂′ : List R} → xs₁ List-∼[ ⌊ k ⌋⇔ ] xs₁′ → xs₂ List-∼[ ⌊ k ⌋⇔ ] xs₂′ → first-nonempty xs₁ xs₂ List-∼[ ⌊ k ⌋⇔ ] first-nonempty xs₁′ xs₂′ first-nonempty-cong {xs₁ = []} {[]} eq₁ eq₂ = eq₂ first-nonempty-cong {xs₁ = _ ∷ _} {_ ∷ _} eq₁ eq₂ = eq₁ first-nonempty-cong {xs₁ = []} {_ ∷ _} eq₁ eq₂ with Equivalence.from (⇒⇔ eq₁) ⟨$⟩ here P.refl ... | () first-nonempty-cong {xs₁ = _ ∷ _} {[]} eq₁ eq₂ with Equivalence.to (⇒⇔ eq₁) ⟨$⟩ here P.refl ... | () -- first-nonempty is correct. first-nonempty-left : ∀ {k R} {xs₁ xs₂ : List R} → (∃ λ y → y ∈ xs₁) → first-nonempty xs₁ xs₂ List-∼[ k ] xs₁ first-nonempty-left {xs₁ = []} (_ , ()) first-nonempty-left {xs₁ = _ ∷ _} _ = _ ∎ where open Related.EquationalReasoning first-nonempty-right : ∀ {k R} {xs₁ xs₂ : List R} → (∄ λ y → y ∈ xs₁) → first-nonempty xs₁ xs₂ List-∼[ k ] xs₂ first-nonempty-right {xs₁ = x ∷ _} ∉x∷ = ⊥-elim $ ∉x∷ (x , here P.refl) first-nonempty-right {xs₁ = []} _ = _ ∎ where open Related.EquationalReasoning ------------------------------------------------------------------------ -- Asymmetric choice -- _◃_ is defined as a pointwise lifting of first-nonempty. Note that -- _◃_ preserves parser and language equality, but not the -- sub-/superparser and sub-/superlanguage relations. private module AC {R} = Pointwise R R ⌊_⌋⇔ first-nonempty first-nonempty-cong -- p₁ ◃ p₂ returns a result if either p₁ or p₂ does. For a given -- string results are returned either from p₁ or from p₂, not both. infixl 5 _◃_ _◃-cong_ _◃_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Parser Tok R (first-nonempty xs₁ xs₂) _◃_ = AC.lift -- D distributes over _◃_. D-◃ : ∀ {Tok R xs₁ xs₂ t} (p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) → D t (p₁ ◃ p₂) ≅P D t p₁ ◃ D t p₂ D-◃ = AC.D-lift -- _◃_ preserves equality. _◃-cong_ : ∀ {k Tok R xs₁ xs₁′ xs₂ xs₂′} {p₁ : Parser Tok R xs₁} {p₁′ : Parser Tok R xs₁′} {p₂ : Parser Tok R xs₂} {p₂′ : Parser Tok R xs₂′} → p₁ ∼[ ⌊ k ⌋⇔ ]P p₁′ → p₂ ∼[ ⌊ k ⌋⇔ ]P p₂′ → p₁ ◃ p₂ ∼[ ⌊ k ⌋⇔ ]P p₁′ ◃ p₂′ _◃-cong_ = AC.lift-cong -- If p₁ accepts s, then p₁ ◃ p₂ behaves as p₁ when applied to s. left : ∀ {Tok R xs₁ xs₂ x s} (p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) → (∃ λ y → y ∈ p₁ · s) → x ∈ p₁ ◃ p₂ · s ↔ x ∈ p₁ · s left {x = x} = AC.lift-property (λ F _ H → ∃ F → H x ↔ F x) (λ F↔F′ _ H↔H′ → Σ.cong Inv.id (λ {x} → ↔⇒ (F↔F′ x)) →-cong-⇔ Related-cong (H↔H′ x) (F↔F′ x)) (λ ∈xs₁ → first-nonempty-left ∈xs₁) -- If p₁ does not accept s, then p₁ ◃ p₂ behaves as p₂ when applied to -- s. right : ∀ {Tok R xs₁ xs₂ x s} (p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) → (∄ λ y → y ∈ p₁ · s) → x ∈ p₁ ◃ p₂ · s ↔ x ∈ p₂ · s right {x = x} = AC.lift-property (λ F G H → ∄ F → H x ↔ G x) (λ F↔F′ G↔G′ H↔H′ → ((Σ.cong Inv.id λ {x} → ↔⇒ (F↔F′ x)) →-cong-⇔ Equiv.id) →-cong-⇔ Related-cong (H↔H′ x) (G↔G′ x)) (λ ∉xs₁ → first-nonempty-right ∉xs₁) -- In "Parsing with First-Class Derivatives" Brachthäuser, Rendel and -- Ostermann state that "[...] and biased alternative cannot be -- expressed as user defined combinators". Here I give a formal proof -- of a variant of this statement (in the present setting): it is not -- possible to construct an asymmetric choice operator that, in a -- certain sense, is more like the prioritised choice of parsing -- expression grammars (see Ford's "Parsing Expression Grammars: A -- Recognition-Based Syntactic Foundation") without changing the -- interface of the parser combinator library. not-PEG-choice : ¬ ∃₂ λ (_◅-bag_ : {R : Set} → List R → List R → List R) (_◅_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Parser Tok R (xs₁ ◅-bag xs₂)) → ∀ {Tok R xs₁ xs₂ s₁} (p₁ : Parser Tok R xs₁) (p₂ : Parser Tok R xs₂) → ((∃₂ λ y s₂ → y ⊕ s₂ ∈ p₁ · s₁) → ∀ {x s₂} → x ⊕ s₂ ∈ p₁ ◅ p₂ · s₁ ⇔ x ⊕ s₂ ∈ p₁ · s₁) × (¬ (∃₂ λ y s₂ → y ⊕ s₂ ∈ p₁ · s₁) → ∀ {x s₂} → x ⊕ s₂ ∈ p₁ ◅ p₂ · s₁ ⇔ x ⊕ s₂ ∈ p₂ · s₁) not-PEG-choice (_ , _◅_ , correct) = false∉p₁⊛·[-] false∈p₁⊛·[-] where p₁ p₂ : Parser ⊤ Bool _ p₁ = const true <$> token p₂ = return false false∈p₂·[] : false ⊕ [] ∈ p₂ · [] false∈p₂·[] = S.return ∄∈p₁·[] : ¬ ∃₂ (λ b s → b ⊕ s ∈ p₁ · []) ∄∈p₁·[] (_ , _ , S.<$> ()) false∈p₁◅p₂·[] : false ⊕ [] ∈ p₁ ◅ p₂ · [] false∈p₁◅p₂·[] = Equivalence.from (proj₂ (correct _ _) ∄∈p₁·[]) ⟨$⟩ false∈p₂·[] false∈p₁◅p₂·[-] : false ⊕ [ _ ] ∈ p₁ ◅ p₂ · [ _ ] false∈p₁◅p₂·[-] = S.extend false∈p₁◅p₂·[] true∈p₁·[-] : true ⊕ [] ∈ p₁ · [ _ ] true∈p₁·[-] = S.<$> S.token false∈p₁·[-] : false ⊕ [ _ ] ∈ p₁ · [ _ ] false∈p₁·[-] = Equivalence.to (proj₁ (correct _ _) (-, -, true∈p₁·[-])) ⟨$⟩ false∈p₁◅p₂·[-] false∈p₁⊛·[-] : false ⊕ [] ∈ const <$> p₁ ⊛ (return _ ∣ token) · [ _ ] false∈p₁⊛·[-] = S.[ _ - _ ] S.<$> false∈p₁·[-] ⊛ S.∣-right _ S.token false∉p₁⊛·[-] : ¬ false ⊕ [] ∈ const <$> p₁ ⊛ (return _ ∣ token) · [ _ ] false∉p₁⊛·[-] = flip lemma P.refl where lemma : ∀ {b} → b ⊕ [] ∈ const <$> p₁ ⊛ (return _ ∣ token) · [ _ ] → b ≢ false lemma (S.[ _ - _ ] S.<$> (S.<$> S.token) ⊛ _) ()
{ "alphanum_fraction": 0.5643928673, "avg_line_length": 34.8078817734, "ext": "agda", "hexsha": "79ec5c233840f115f3fa7fc4ee70090a6266bdc7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_path": "TotalParserCombinators/AsymmetricChoice.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_path": "TotalParserCombinators/AsymmetricChoice.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/parser-combinators", "max_stars_repo_path": "TotalParserCombinators/AsymmetricChoice.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z", "num_tokens": 2703, "size": 7066 }
------------------------------------------------------------------------ -- The Agda standard library -- -- This module provides alternative ways of providing instances of -- structures in the Algebra.Module hierarchy. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Rel; Setoid; IsEquivalence) module Algebra.Module.Structures.Biased where open import Algebra.Bundles open import Algebra.Core open import Algebra.Module.Consequences open import Algebra.Module.Structures open import Function.Base using (flip) open import Level using (Level; _⊔_) private variable m ℓm r ℓr s ℓs : Level M : Set m module _ (commutativeSemiring : CommutativeSemiring r ℓr) where open CommutativeSemiring commutativeSemiring renaming (Carrier to R) -- A left semimodule over a commutative semiring is already a semimodule. record IsSemimoduleFromLeft (≈ᴹ : Rel {m} M ℓm) (+ᴹ : Op₂ M) (0ᴹ : M) (*ₗ : Opₗ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where field isLeftSemimodule : IsLeftSemimodule semiring ≈ᴹ +ᴹ 0ᴹ *ₗ open IsLeftSemimodule isLeftSemimodule isBisemimodule : IsBisemimodule semiring semiring ≈ᴹ +ᴹ 0ᴹ *ₗ (flip *ₗ) isBisemimodule = record { +ᴹ-isCommutativeMonoid = +ᴹ-isCommutativeMonoid ; isPreleftSemimodule = isPreleftSemimodule ; isPrerightSemimodule = record { *ᵣ-cong = flip *ₗ-cong ; *ᵣ-zeroʳ = *ₗ-zeroˡ ; *ᵣ-distribˡ = *ₗ-distribʳ ; *ᵣ-identityʳ = *ₗ-identityˡ ; *ᵣ-assoc = *ₗ-assoc+comm⇒*ᵣ-assoc _≈_ ≈ᴹ-setoid *ₗ-congʳ *ₗ-assoc *-comm ; *ᵣ-zeroˡ = *ₗ-zeroʳ ; *ᵣ-distribʳ = *ₗ-distribˡ } ; *ₗ-*ᵣ-assoc = *ₗ-assoc+comm⇒*ₗ-*ᵣ-assoc _≈_ ≈ᴹ-setoid *ₗ-congʳ *ₗ-assoc *-comm } isSemimodule : IsSemimodule commutativeSemiring ≈ᴹ +ᴹ 0ᴹ *ₗ (flip *ₗ) isSemimodule = record { isBisemimodule = isBisemimodule } -- Similarly, a right semimodule over a commutative semiring -- is already a semimodule. record IsSemimoduleFromRight (≈ᴹ : Rel {m} M ℓm) (+ᴹ : Op₂ M) (0ᴹ : M) (*ᵣ : Opᵣ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where field isRightSemimodule : IsRightSemimodule semiring ≈ᴹ +ᴹ 0ᴹ *ᵣ open IsRightSemimodule isRightSemimodule isBisemimodule : IsBisemimodule semiring semiring ≈ᴹ +ᴹ 0ᴹ (flip *ᵣ) *ᵣ isBisemimodule = record { +ᴹ-isCommutativeMonoid = +ᴹ-isCommutativeMonoid ; isPreleftSemimodule = record { *ₗ-cong = flip *ᵣ-cong ; *ₗ-zeroˡ = *ᵣ-zeroʳ ; *ₗ-distribʳ = *ᵣ-distribˡ ; *ₗ-identityˡ = *ᵣ-identityʳ ; *ₗ-assoc = *ᵣ-assoc+comm⇒*ₗ-assoc _≈_ ≈ᴹ-setoid *ᵣ-congˡ *ᵣ-assoc *-comm ; *ₗ-zeroʳ = *ᵣ-zeroˡ ; *ₗ-distribˡ = *ᵣ-distribʳ } ; isPrerightSemimodule = isPrerightSemimodule ; *ₗ-*ᵣ-assoc = *ᵣ-assoc+comm⇒*ₗ-*ᵣ-assoc _≈_ ≈ᴹ-setoid *ᵣ-congˡ *ᵣ-assoc *-comm } isSemimodule : IsSemimodule commutativeSemiring ≈ᴹ +ᴹ 0ᴹ (flip *ᵣ) *ᵣ isSemimodule = record { isBisemimodule = isBisemimodule } module _ (commutativeRing : CommutativeRing r ℓr) where open CommutativeRing commutativeRing renaming (Carrier to R) -- A left module over a commutative ring is already a module. record IsModuleFromLeft (≈ᴹ : Rel {m} M ℓm) (+ᴹ : Op₂ M) (0ᴹ : M) (-ᴹ : Op₁ M) (*ₗ : Opₗ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where field isLeftModule : IsLeftModule ring ≈ᴹ +ᴹ 0ᴹ -ᴹ *ₗ open IsLeftModule isLeftModule isModule : IsModule commutativeRing ≈ᴹ +ᴹ 0ᴹ -ᴹ *ₗ (flip *ₗ) isModule = record { isBimodule = record { isBisemimodule = IsSemimoduleFromLeft.isBisemimodule {commutativeSemiring = commutativeSemiring} (record { isLeftSemimodule = isLeftSemimodule }) ; -ᴹ‿cong = -ᴹ‿cong ; -ᴹ‿inverse = -ᴹ‿inverse } } -- Similarly, a right module over a commutative ring is already a module. record IsModuleFromRight (≈ᴹ : Rel {m} M ℓm) (+ᴹ : Op₂ M) (0ᴹ : M) (-ᴹ : Op₁ M) (*ᵣ : Opᵣ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where field isRightModule : IsRightModule ring ≈ᴹ +ᴹ 0ᴹ -ᴹ *ᵣ open IsRightModule isRightModule isModule : IsModule commutativeRing ≈ᴹ +ᴹ 0ᴹ -ᴹ (flip *ᵣ) *ᵣ isModule = record { isBimodule = record { isBisemimodule = IsSemimoduleFromRight.isBisemimodule {commutativeSemiring = commutativeSemiring} (record { isRightSemimodule = isRightSemimodule }) ; -ᴹ‿cong = -ᴹ‿cong ; -ᴹ‿inverse = -ᴹ‿inverse } }
{ "alphanum_fraction": 0.5976256095, "avg_line_length": 34.9407407407, "ext": "agda", "hexsha": "e1bad86c4582c5b0ed35619703a1a45f8c9b0a3d", "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/Algebra/Module/Structures/Biased.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/Algebra/Module/Structures/Biased.agda", "max_line_length": 76, "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/Algebra/Module/Structures/Biased.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": 1862, "size": 4717 }
{- Freudenthal suspension theorem -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Homotopy.Freudenthal where open import Cubical.Foundations.Everything open import Cubical.Data.HomotopyGroup open import Cubical.Data.Nat open import Cubical.Data.Sigma open import Cubical.HITs.Nullification open import Cubical.HITs.Susp open import Cubical.HITs.Truncation as Trunc renaming (rec to trRec) open import Cubical.Homotopy.Connected open import Cubical.Homotopy.WedgeConnectivity open import Cubical.Homotopy.Loopspace module _ {ℓ} (n : HLevel) {A : Pointed ℓ} (connA : isConnected (suc (suc n)) (typ A)) where σ : typ A → typ (Ω (∙Susp (typ A))) σ a = merid a ∙ merid (pt A) ⁻¹ private 2n+2 = suc n + suc n module WC (p : north ≡ north) = WedgeConnectivity (suc n) (suc n) A connA A connA (λ a b → ( (σ b ≡ p → hLevelTrunc 2n+2 (fiber (λ x → merid x ∙ merid a ⁻¹) p)) , isOfHLevelΠ 2n+2 λ _ → isOfHLevelTrunc 2n+2 )) (λ a r → ∣ a , (rCancel' (merid a) ∙ rCancel' (merid (pt A)) ⁻¹) ∙ r ∣) (λ b r → ∣ b , r ∣) (funExt λ r → cong′ (λ w → ∣ pt A , w ∣) (cong (_∙ r) (rCancel' (rCancel' (merid (pt A)))) ∙ lUnit r ⁻¹)) fwd : (p : north ≡ north) (a : typ A) → hLevelTrunc 2n+2 (fiber σ p) → hLevelTrunc 2n+2 (fiber (λ x → merid x ∙ merid a ⁻¹) p) fwd p a = Trunc.rec (isOfHLevelTrunc 2n+2) (uncurry (WC.extension p a)) isEquivFwd : (p : north ≡ north) (a : typ A) → isEquiv (fwd p a) isEquivFwd p a .equiv-proof = elim.isEquivPrecompose (λ _ → pt A) (suc n) (λ a → ( (∀ t → isContr (fiber (fwd p a) t)) , isProp→isOfHLevelSuc n (isPropΠ λ _ → isPropIsContr) )) (isConnectedPoint (suc n) connA (pt A)) .equiv-proof (λ _ → Trunc.elim (λ _ → isProp→isOfHLevelSuc (n + suc n) isPropIsContr) (λ fib → subst (λ k → isContr (fiber k ∣ fib ∣)) (cong (Trunc.rec (isOfHLevelTrunc 2n+2) ∘ uncurry) (funExt (WC.right p) ⁻¹)) (subst isEquiv (funExt (Trunc.mapId) ⁻¹) (idIsEquiv _) .equiv-proof ∣ fib ∣) )) .fst .fst a interpolate : (a : typ A) → PathP (λ i → typ A → north ≡ merid a i) (λ x → merid x ∙ merid a ⁻¹) merid interpolate a i x j = compPath-filler (merid x) (merid a ⁻¹) (~ i) j Code : (y : Susp (typ A)) → north ≡ y → Type ℓ Code north p = hLevelTrunc 2n+2 (fiber σ p) Code south q = hLevelTrunc 2n+2 (fiber merid q) Code (merid a i) p = Glue (hLevelTrunc 2n+2 (fiber (interpolate a i) p)) (λ { (i = i0) → _ , (fwd p a , isEquivFwd p a) ; (i = i1) → _ , idEquiv _ }) encode : (y : Susp (typ A)) (p : north ≡ y) → Code y p encode y = J Code ∣ pt A , rCancel' (merid (pt A)) ∣ encodeMerid : (a : typ A) → encode south (merid a) ≡ ∣ a , refl ∣ encodeMerid a = cong (transport (λ i → gluePath i)) (funExt⁻ (WC.left refl a) _ ∙ cong ∣_∣ (cong (a ,_) (lem _ _))) ∙ transport (PathP≡Path gluePath _ _) (λ i → ∣ a , (λ j k → rCancel-filler' (merid a) i j k) ∣) where gluePath : I → Type _ gluePath i = hLevelTrunc 2n+2 (fiber (interpolate a i) (λ j → merid a (i ∧ j))) lem : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : z ≡ y) → (p ∙ q ⁻¹) ∙ q ≡ p lem p q = assoc p (q ⁻¹) q ⁻¹ ∙ cong (p ∙_) (lCancel q) ∙ rUnit p ⁻¹ contractCodeSouth : (p : north ≡ south) (c : Code south p) → encode south p ≡ c contractCodeSouth p = Trunc.elim (λ _ → isOfHLevelPath 2n+2 (isOfHLevelTrunc 2n+2) _ _) (uncurry λ a → J (λ p r → encode south p ≡ ∣ a , r ∣) (encodeMerid a)) isConnectedMerid : isConnectedFun 2n+2 (merid {A = typ A}) isConnectedMerid p = encode south p , contractCodeSouth p isConnectedσ : isConnectedFun 2n+2 σ isConnectedσ = transport (λ i → isConnectedFun 2n+2 (interpolate (pt A) (~ i))) isConnectedMerid FreudenthalEquiv : ∀ {ℓ} (n : HLevel) (A : Pointed ℓ) → isConnected (2 + n) (typ A) → hLevelTrunc ((suc n) + (suc n)) (typ A) ≃ hLevelTrunc ((suc n) + (suc n)) (typ (Ω (Susp (typ A) , north))) FreudenthalEquiv n A iscon = connectedTruncEquiv _ (σ n {A = A} iscon) (isConnectedσ _ iscon) FreudenthalIso : ∀ {ℓ} (n : HLevel) (A : Pointed ℓ) → isConnected (2 + n) (typ A) → Iso (hLevelTrunc ((suc n) + (suc n)) (typ A)) (hLevelTrunc ((suc n) + (suc n)) (typ (Ω (Susp (typ A) , north)))) FreudenthalIso n A iscon = connectedTruncIso _ (σ n {A = A} iscon) (isConnectedσ _ iscon)
{ "alphanum_fraction": 0.5420386132, "avg_line_length": 37.9291338583, "ext": "agda", "hexsha": "106267de5a732725944dce5b45735e41ac08c5c7", "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": "f6771617374bfe65a7043d00731fed5a673aa729", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "knrafto/cubical", "max_forks_repo_path": "Cubical/Homotopy/Freudenthal.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "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": "knrafto/cubical", "max_issues_repo_path": "Cubical/Homotopy/Freudenthal.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "knrafto/cubical", "max_stars_repo_path": "Cubical/Homotopy/Freudenthal.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1801, "size": 4817 }
-- A formalised proof of the soundness and completeness of -- a simply typed lambda-calculus with explicit substitutions -- -- Catarina Coquand -- -- Higher-Order and Symbolic Computation, 15, 57-90, 2002 -- -- http://dx.doi.org/10.1023/A:1019964114625 module Everything where -- 1. Introduction import Section1 -- 2. The proof editor -- NOTE: Not relevant to this formalisation -- 3. The calculus of proof trees import Section3 -- 4. The semantic model import Section4a import Section4b -- 5. Normal form import Section5 -- 6. Application to terms import Section6 -- 7. Correspondence between proof trees and terms import Section7 -- 8. Correctness of conversion between terms import Section8 -- 9. A decision algorithm for terms import Section9 -- 10. Conclusions import Section10
{ "alphanum_fraction": 0.7569269521, "avg_line_length": 18.9047619048, "ext": "agda", "hexsha": "6d0168c56579c53659e9fe2acb918ed773288058", "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": "7c000654c4f97024d2939c412702f64dc821d4ec", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/coquand", "max_forks_repo_path": "src/Everything.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7c000654c4f97024d2939c412702f64dc821d4ec", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "X11" ], "max_issues_repo_name": "mietek/coquand", "max_issues_repo_path": "src/Everything.agda", "max_line_length": 61, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7c000654c4f97024d2939c412702f64dc821d4ec", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/coquand", "max_stars_repo_path": "src/Everything.agda", "max_stars_repo_stars_event_max_datetime": "2017-09-07T12:44:40.000Z", "max_stars_repo_stars_event_min_datetime": "2017-03-27T01:29:58.000Z", "num_tokens": 220, "size": 794 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Finding the maximum/minimum values in a list, specialised for Nat ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} -- This specialised module is needed as `m < n` for Nat is not -- implemented as `m ≤ n × m ≢ n`. module Data.List.Extrema.Nat where open import Data.Nat.Base using (ℕ; _≤_; _<_) open import Data.Nat.Properties as ℕₚ using (≤∧≢⇒<; <⇒≤; <⇒≢) open import Data.Sum.Base as Sum using (_⊎_) open import Data.List.Base using (List) import Data.List.Extrema open import Data.List.Relation.Unary.Any as Any using (Any) open import Data.List.Relation.Unary.All as All using (All) open import Data.Product using (_×_; _,_; uncurry′) open import Level using (Level) open import Relation.Binary.PropositionalEquality using (_≢_) private variable a : Level A : Set a <⇒<× : ∀ {x y} → x < y → x ≤ y × x ≢ y <⇒<× x<y = <⇒≤ x<y , <⇒≢ x<y <×⇒< : ∀ {x y} → x ≤ y × x ≢ y → x < y <×⇒< (x≤y , x≢y) = ≤∧≢⇒< x≤y x≢y module Extrema = Data.List.Extrema ℕₚ.≤-totalOrder ------------------------------------------------------------------------ -- Re-export the contents of Extrema open Extrema public hiding ( f[argmin]<v⁺; v<f[argmin]⁺; argmin[xs]<argmin[ys]⁺ ; f[argmax]<v⁺; v<f[argmax]⁺; argmax[xs]<argmax[ys]⁺ ; min<v⁺; v<min⁺; min[xs]<min[ys]⁺ ; max<v⁺; v<max⁺; max[xs]<max[ys]⁺ ) ------------------------------------------------------------------------ -- New versions of the proofs involving _<_ -- Argmin f[argmin]<v⁺ : ∀ {f : A → ℕ} {v} ⊤ xs → (f ⊤ < v) ⊎ (Any (λ x → f x < v) xs) → f (argmin f ⊤ xs) < v f[argmin]<v⁺ ⊤ xs arg = <×⇒< (Extrema.f[argmin]<v⁺ ⊤ xs (Sum.map <⇒<× (Any.map <⇒<×) arg)) v<f[argmin]⁺ : ∀ {f : A → ℕ} {v ⊤ xs} → v < f ⊤ → All (λ x → v < f x) xs → v < f (argmin f ⊤ xs) v<f[argmin]⁺ {v} v<f⊤ v<fxs = <×⇒< (Extrema.v<f[argmin]⁺ (<⇒<× v<f⊤) (All.map <⇒<× v<fxs)) argmin[xs]<argmin[ys]⁺ : ∀ {f g : A → ℕ} ⊤₁ {⊤₂} xs {ys} → (f ⊤₁ < g ⊤₂) ⊎ Any (λ x → f x < g ⊤₂) xs → All (λ y → (f ⊤₁ < g y) ⊎ Any (λ x → f x < g y) xs) ys → f (argmin f ⊤₁ xs) < g (argmin g ⊤₂ ys) argmin[xs]<argmin[ys]⁺ ⊤₁ xs xs<⊤₂ xs<ys = v<f[argmin]⁺ (f[argmin]<v⁺ ⊤₁ _ xs<⊤₂) (All.map (f[argmin]<v⁺ ⊤₁ xs) xs<ys) -- Argmax v<f[argmax]⁺ : ∀ {f : A → ℕ} {v} ⊥ xs → (v < f ⊥) ⊎ (Any (λ x → v < f x) xs) → v < f (argmax f ⊥ xs) v<f[argmax]⁺ ⊥ xs leq = <×⇒< (Extrema.v<f[argmax]⁺ ⊥ xs (Sum.map <⇒<× (Any.map <⇒<×) leq)) f[argmax]<v⁺ : ∀ {f : A → ℕ} {v ⊥ xs} → f ⊥ < v → All (λ x → f x < v) xs → f (argmax f ⊥ xs) < v f[argmax]<v⁺ ⊥<v xs<v = <×⇒< (Extrema.f[argmax]<v⁺ (<⇒<× ⊥<v) (All.map <⇒<× xs<v)) argmax[xs]<argmax[ys]⁺ : ∀ {f g : A → ℕ} {⊥₁} ⊥₂ {xs} ys → (f ⊥₁ < g ⊥₂) ⊎ Any (λ y → f ⊥₁ < g y) ys → All (λ x → (f x < g ⊥₂) ⊎ Any (λ y → f x < g y) ys) xs → f (argmax f ⊥₁ xs) < g (argmax g ⊥₂ ys) argmax[xs]<argmax[ys]⁺ ⊥₂ ys ⊥₁<ys xs<ys = f[argmax]<v⁺ (v<f[argmax]⁺ ⊥₂ _ ⊥₁<ys) (All.map (v<f[argmax]⁺ ⊥₂ ys) xs<ys) -- Min min<v⁺ : ∀ {v} ⊤ xs → ⊤ < v ⊎ Any (_< v) xs → min ⊤ xs < v min<v⁺ = f[argmin]<v⁺ v<min⁺ : ∀ {v ⊤ xs} → v < ⊤ → All (v <_) xs → v < min ⊤ xs v<min⁺ = v<f[argmin]⁺ min[xs]<min[ys]⁺ : ∀ ⊤₁ {⊤₂} xs {ys} → (⊤₁ < ⊤₂) ⊎ Any (_< ⊤₂) xs → All (λ y → (⊤₁ < y) ⊎ Any (λ x → x < y) xs) ys → min ⊤₁ xs < min ⊤₂ ys min[xs]<min[ys]⁺ = argmin[xs]<argmin[ys]⁺ -- Max max<v⁺ : ∀ {v ⊥ xs} → ⊥ < v → All (_< v) xs → max ⊥ xs < v max<v⁺ = f[argmax]<v⁺ v<max⁺ : ∀ {v} ⊥ xs → v < ⊥ ⊎ Any (v <_) xs → v < max ⊥ xs v<max⁺ = v<f[argmax]⁺ max[xs]<max[ys]⁺ : ∀ {⊥₁} ⊥₂ {xs} ys → ⊥₁ < ⊥₂ ⊎ Any (⊥₁ <_) ys → All (λ x → x < ⊥₂ ⊎ Any (x <_) ys) xs → max ⊥₁ xs < max ⊥₂ ys max[xs]<max[ys]⁺ = argmax[xs]<argmax[ys]⁺
{ "alphanum_fraction": 0.4360119048, "avg_line_length": 35.0608695652, "ext": "agda", "hexsha": "6fc0d7f82cd7a90fd685834d2a7ad4e65da07518", "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/Extrema/Nat.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/Extrema/Nat.agda", "max_line_length": 90, "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/Extrema/Nat.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": 1787, "size": 4032 }
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-} module Cubical.HITs.InfNat.Base where open import Cubical.Core.Everything open import Cubical.Data.Maybe open import Cubical.Data.Nat open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism data ℕ+∞ : Type₀ where zero : ℕ+∞ suc : ℕ+∞ → ℕ+∞ ∞ : ℕ+∞ suc-inf : ∞ ≡ suc ∞
{ "alphanum_fraction": 0.704787234, "avg_line_length": 22.1176470588, "ext": "agda", "hexsha": "742803f049a9ecfaa62d575426cf5c3154278ddb", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/HITs/InfNat/Base.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/HITs/InfNat/Base.agda", "max_line_length": 67, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/HITs/InfNat/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 127, "size": 376 }
module Data.Integer where import Prelude import Data.Nat as Nat import Data.Bool open Nat using (Nat; suc; zero) renaming ( _+_ to _+'_ ; _*_ to _*'_ ; _<_ to _<'_ ; _-_ to _-'_ ; _==_ to _=='_ ; div to div' ; mod to mod' ; gcd to gcd' ; lcm to lcm' ) open Data.Bool open Prelude data Int : Set where pos : Nat -> Int neg : Nat -> Int -- neg n = -(n + 1) infix 40 _==_ _<_ _>_ _≤_ _≥_ infixl 60 _+_ _-_ infixl 70 _*_ infix 90 -_ -_ : Int -> Int - pos zero = pos zero - pos (suc n) = neg n - neg n = pos (suc n) _+_ : Int -> Int -> Int pos n + pos m = pos (n +' m) neg n + neg m = neg (n +' m +' 1) pos n + neg m = ! m <' n => pos (n -' m -' 1) ! otherwise neg (m -' n) neg n + pos m = pos m + neg n _-_ : Int -> Int -> Int x - y = x + - y !_! : Int -> Nat ! pos n ! = n ! neg n ! = suc n _*_ : Int -> Int -> Int pos 0 * _ = pos 0 _ * pos 0 = pos 0 pos n * pos m = pos (n *' m) neg n * neg m = pos (suc n *' suc m) pos n * neg m = neg (n *' suc m -' 1) neg n * pos m = neg (suc n *' m -' 1) div : Int -> Int -> Int div _ (pos 0) = pos 0 div (pos n) (pos m) = pos (div' n m) div (neg n) (neg m) = pos (div' (suc n) (suc m)) div (pos 0) (neg _) = pos 0 div (pos (suc n)) (neg m) = neg (div' n (suc m)) div (neg n) (pos (suc m)) = div (pos (suc n)) (neg m) mod : Int -> Int -> Int mod _ (pos 0) = pos 0 mod (pos n) (pos m) = pos (mod' n m) mod (neg n) (pos m) = adjust (mod' (suc n) m) where adjust : Nat -> Int adjust 0 = pos 0 adjust n = pos (m -' n) mod n (neg m) = adjust (mod n (pos (suc m))) where adjust : Int -> Int adjust (pos 0) = pos 0 adjust (neg n) = neg n -- impossible adjust x = x + neg m gcd : Int -> Int -> Int gcd a b = pos (gcd' ! a ! ! b !) lcm : Int -> Int -> Int lcm a b = pos (lcm' ! a ! ! b !) _==_ : Int -> Int -> Bool pos n == pos m = n ==' m neg n == neg m = n ==' m pos _ == neg _ = false neg _ == pos _ = false _<_ : Int -> Int -> Bool pos _ < neg _ = false neg _ < pos _ = true pos n < pos m = n <' m neg n < neg m = m <' n _≤_ : Int -> Int -> Bool x ≤ y = x == y || x < y _≥_ = flip _≤_ _>_ = flip _<_
{ "alphanum_fraction": 0.4468802698, "avg_line_length": 22.3773584906, "ext": "agda", "hexsha": "eb2c43b839c22d699b035e2512244d762761de52", "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": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Integer.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": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Integer.agda", "max_line_length": 60, "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": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Integer.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": 910, "size": 2372 }
------------------------------------------------------------------------ -- Groups ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Equality module Group {e⁺} (eq : ∀ {a p} → Equality-with-J a p e⁺) where open Derived-definitions-and-properties eq open import Logical-equivalence using (_⇔_) open import Prelude as P hiding (id; _∘_) renaming (_×_ to _⊗_) import Bijection eq as B open import Equivalence eq as Eq using (_≃_) open import Function-universe eq as F hiding (id; _∘_) open import Groupoid eq using (Groupoid) open import H-level eq open import H-level.Closure eq open import Integer.Basics eq using (+_; -[1+_]) open import Univalence-axiom eq private variable a g₁ g₂ : Level A : Type a g x y : A k : Kind ------------------------------------------------------------------------ -- Groups -- Groups. -- -- Note that the carrier type is required to be a set (following the -- HoTT book). record Group g : Type (lsuc g) where infix 8 _⁻¹ infixr 7 _∘_ field Carrier : Type g Carrier-is-set : Is-set Carrier _∘_ : Carrier → Carrier → Carrier id : Carrier _⁻¹ : Carrier → Carrier left-identity : ∀ x → (id ∘ x) ≡ x right-identity : ∀ x → (x ∘ id) ≡ x assoc : ∀ x y z → (x ∘ (y ∘ z)) ≡ ((x ∘ y) ∘ z) left-inverse : ∀ x → ((x ⁻¹) ∘ x) ≡ id right-inverse : ∀ x → (x ∘ (x ⁻¹)) ≡ id -- Groups are groupoids. groupoid : Groupoid lzero g groupoid = record { Object = ⊤ ; _∼_ = λ _ _ → Carrier ; id = id ; _∘_ = _∘_ ; _⁻¹ = _⁻¹ ; left-identity = left-identity ; right-identity = right-identity ; assoc = assoc ; left-inverse = left-inverse ; right-inverse = right-inverse } open Groupoid groupoid public hiding (Object; _∼_; id; _∘_; _⁻¹; left-identity; right-identity; assoc; left-inverse; right-inverse) private variable G G₁ G₁′ G₂ G₂′ G₃ : Group g -- The type of groups can be expressed using a nested Σ-type. Group-as-Σ : Group g ≃ ∃ λ (A : Set g) → let A = ⌞ A ⌟ in ∃ λ (_∘_ : A → A → A) → ∃ λ (id : A) → ∃ λ (_⁻¹ : A → A) → (∀ x → (id ∘ x) ≡ x) ⊗ (∀ x → (x ∘ id) ≡ x) ⊗ (∀ x y z → (x ∘ (y ∘ z)) ≡ ((x ∘ y) ∘ z)) ⊗ (∀ x → ((x ⁻¹) ∘ x) ≡ id) ⊗ (∀ x → (x ∘ (x ⁻¹)) ≡ id) Group-as-Σ = Eq.↔→≃ (λ G → let open Group G in (Carrier , Carrier-is-set) , _∘_ , id , _⁻¹ , left-identity , right-identity , assoc , left-inverse , right-inverse) _ refl refl ------------------------------------------------------------------------ -- Group homomorphisms and isomorphisms -- Group homomorphisms (generalised to several kinds of underlying -- "functions"). record Homomorphic (k : Kind) (G₁ : Group g₁) (G₂ : Group g₂) : Type (g₁ ⊔ g₂) where private module G₁ = Group G₁ module G₂ = Group G₂ field related : G₁.Carrier ↝[ k ] G₂.Carrier to : G₁.Carrier → G₂.Carrier to = to-implication related field homomorphic : ∀ x y → to (x G₁.∘ y) ≡ to x G₂.∘ to y open Homomorphic public using (related; homomorphic) open Homomorphic using (to) -- The type of (generalised) group homomorphisms can be expressed -- using a nested Σ-type. Homomorphic-as-Σ : {G₁ : Group g₁} {G₂ : Group g₂} → Homomorphic k G₁ G₂ ≃ let module G₁ = Group G₁ module G₂ = Group G₂ in ∃ λ (f : G₁.Carrier ↝[ k ] G₂.Carrier) → ∀ x y → to-implication f (x G₁.∘ y) ≡ to-implication f x G₂.∘ to-implication f y Homomorphic-as-Σ = Eq.↔→≃ (λ G₁↝G₂ → G₁↝G₂ .related , G₁↝G₂ .homomorphic) _ refl refl -- A variant of Homomorphic. infix 4 _↝[_]ᴳ_ _→ᴳ_ _≃ᴳ_ _↝[_]ᴳ_ : Group g₁ → Kind → Group g₂ → Type (g₁ ⊔ g₂) _↝[_]ᴳ_ = flip Homomorphic -- Group homomorphisms. _→ᴳ_ : Group g₁ → Group g₂ → Type (g₁ ⊔ g₂) _→ᴳ_ = _↝[ implication ]ᴳ_ -- Group isomorphisms. _≃ᴳ_ : Group g₁ → Group g₂ → Type (g₁ ⊔ g₂) _≃ᴳ_ = _↝[ equivalence ]ᴳ_ -- "Functions" of type G₁ ↝[ k ]ᴳ G₂ can be converted to group -- homomorphisms. ↝ᴳ→→ᴳ : G₁ ↝[ k ]ᴳ G₂ → G₁ →ᴳ G₂ ↝ᴳ→→ᴳ f .related = to f ↝ᴳ→→ᴳ f .homomorphic = f .homomorphic -- _↝[ k ]ᴳ_ is reflexive. ↝ᴳ-refl : G ↝[ k ]ᴳ G ↝ᴳ-refl .related = F.id ↝ᴳ-refl {G = G} {k = k} .homomorphic x y = to-implication {k = k} F.id (x ∘ y) ≡⟨ cong (_$ _) $ to-implication-id k ⟩ x ∘ y ≡⟨ sym $ cong₂ (λ f g → f _ ∘ g _) (to-implication-id k) (to-implication-id k) ⟩∎ to-implication {k = k} F.id x ∘ to-implication {k = k} F.id y ∎ where open Group G -- _↝[ k ]ᴳ_ is transitive. ↝ᴳ-trans : G₁ ↝[ k ]ᴳ G₂ → G₂ ↝[ k ]ᴳ G₃ → G₁ ↝[ k ]ᴳ G₃ ↝ᴳ-trans {G₁ = G₁} {k = k} {G₂ = G₂} {G₃ = G₃} G₁↝G₂ G₂↝G₃ = λ where .related → G₂↝G₃ .related F.∘ G₁↝G₂ .related .homomorphic x y → to-implication (G₂↝G₃ .related F.∘ G₁↝G₂ .related) (x G₁.∘ y) ≡⟨ cong (_$ _) $ to-implication-∘ k ⟩ to G₂↝G₃ (to G₁↝G₂ (x G₁.∘ y)) ≡⟨ cong (to G₂↝G₃) $ homomorphic G₁↝G₂ _ _ ⟩ to G₂↝G₃ (to G₁↝G₂ x G₂.∘ to G₁↝G₂ y) ≡⟨ homomorphic G₂↝G₃ _ _ ⟩ to G₂↝G₃ (to G₁↝G₂ x) G₃.∘ to G₂↝G₃ (to G₁↝G₂ y) ≡⟨ sym $ cong₂ (λ f g → f _ G₃.∘ g _) (to-implication-∘ k) (to-implication-∘ k) ⟩∎ to-implication (G₂↝G₃ .related F.∘ G₁↝G₂ .related) x G₃.∘ to-implication (G₂↝G₃ .related F.∘ G₁↝G₂ .related) y ∎ where module G₁ = Group G₁ module G₂ = Group G₂ module G₃ = Group G₃ -- _≃ᴳ_ is symmetric. ≃ᴳ-sym : G₁ ≃ᴳ G₂ → G₂ ≃ᴳ G₁ ≃ᴳ-sym {G₁ = G₁} {G₂ = G₂} G₁≃G₂ = λ where .related → inverse (G₁≃G₂ .related) .homomorphic x y → _≃_.injective (G₁≃G₂ .related) (to G₁≃G₂ (_≃_.from (G₁≃G₂ .related) (x G₂.∘ y)) ≡⟨ _≃_.right-inverse-of (G₁≃G₂ .related) _ ⟩ x G₂.∘ y ≡⟨ sym $ cong₂ G₂._∘_ (_≃_.right-inverse-of (G₁≃G₂ .related) _) (_≃_.right-inverse-of (G₁≃G₂ .related) _) ⟩ to G₁≃G₂ (_≃_.from (G₁≃G₂ .related) x) G₂.∘ to G₁≃G₂ (_≃_.from (G₁≃G₂ .related) y) ≡⟨ sym $ G₁≃G₂ .homomorphic _ _ ⟩∎ to G₁≃G₂ (_≃_.from (G₁≃G₂ .related) x G₁.∘ _≃_.from (G₁≃G₂ .related) y) ∎) where module G₁ = Group G₁ module G₂ = Group G₂ -- Group homomorphisms preserve identity elements. →ᴳ-id : (G₁↝G₂ : G₁ ↝[ k ]ᴳ G₂) → to G₁↝G₂ (Group.id G₁) ≡ Group.id G₂ →ᴳ-id {G₁ = G₁} {G₂ = G₂} G₁↝G₂ = G₂.idempotent⇒≡id (to G₁↝G₂ G₁.id G₂.∘ to G₁↝G₂ G₁.id ≡⟨ sym $ G₁↝G₂ .homomorphic _ _ ⟩ to G₁↝G₂ (G₁.id G₁.∘ G₁.id) ≡⟨ cong (to G₁↝G₂) $ G₁.left-identity _ ⟩∎ to G₁↝G₂ G₁.id ∎) where module G₁ = Group G₁ module G₂ = Group G₂ -- Group homomorphisms are homomorphic with respect to the inverse -- operators. →ᴳ-⁻¹ : ∀ (G₁↝G₂ : G₁ ↝[ k ]ᴳ G₂) x → to G₁↝G₂ (Group._⁻¹ G₁ x) ≡ Group._⁻¹ G₂ (to G₁↝G₂ x) →ᴳ-⁻¹ {G₁ = G₁} {G₂ = G₂} G₁↝G₂ x = G₂.⁻¹∘≡id→≡ (to G₁↝G₂ x G₂.⁻¹ G₂.⁻¹ G₂.∘ to G₁↝G₂ (x G₁.⁻¹) ≡⟨ cong (G₂._∘ to G₁↝G₂ (x G₁.⁻¹)) $ G₂.involutive _ ⟩ to G₁↝G₂ x G₂.∘ to G₁↝G₂ (x G₁.⁻¹) ≡⟨ sym $ G₁↝G₂ .homomorphic _ _ ⟩ to G₁↝G₂ (x G₁.∘ x G₁.⁻¹) ≡⟨ cong (to G₁↝G₂) (G₁.right-inverse _) ⟩ to G₁↝G₂ G₁.id ≡⟨ →ᴳ-id G₁↝G₂ ⟩∎ G₂.id ∎) where module G₁ = Group G₁ module G₂ = Group G₂ -- Group homomorphisms are homomorphic with respect to exponentiation. →ᴳ-^ : ∀ (G₁↝G₂ : G₁ ↝[ k ]ᴳ G₂) x i → to G₁↝G₂ (Group._^_ G₁ x i) ≡ Group._^_ G₂ (to G₁↝G₂ x) i →ᴳ-^ {G₁ = G₁} {G₂ = G₂} G₁↝G₂ x = lemma₂ where module G₁ = Group G₁ module G₂ = Group G₂ lemma₁ : ∀ n → to G₁↝G₂ (y G₁.^+ n) ≡ to G₁↝G₂ y G₂.^+ n lemma₁ zero = to G₁↝G₂ G₁.id ≡⟨ →ᴳ-id G₁↝G₂ ⟩∎ G₂.id ∎ lemma₁ {y = y} (suc n) = to G₁↝G₂ (y G₁.∘ y G₁.^+ n) ≡⟨ G₁↝G₂ .homomorphic _ _ ⟩ to G₁↝G₂ y G₂.∘ to G₁↝G₂ (y G₁.^+ n) ≡⟨ cong (_ G₂.∘_) $ lemma₁ n ⟩∎ to G₁↝G₂ y G₂.∘ to G₁↝G₂ y G₂.^+ n ∎ lemma₂ : ∀ i → to G₁↝G₂ (x G₁.^ i) ≡ to G₁↝G₂ x G₂.^ i lemma₂ (+ n) = lemma₁ n lemma₂ -[1+ n ] = to G₁↝G₂ ((x G₁.⁻¹) G₁.^+ suc n) ≡⟨ lemma₁ (suc n) ⟩ to G₁↝G₂ (x G₁.⁻¹) G₂.^+ suc n ≡⟨ cong (G₂._^+ suc n) $ →ᴳ-⁻¹ G₁↝G₂ _ ⟩∎ (to G₁↝G₂ x G₂.⁻¹) G₂.^+ suc n ∎ -- Group equality can be expressed in terms of equality of pairs of -- carrier types and binary operators (assuming extensionality). ≡≃,∘≡,∘ : {G₁ G₂ : Group g} → Extensionality g g → let module G₁ = Group G₁ module G₂ = Group G₂ in (G₁ ≡ G₂) ≃ ((G₁.Carrier , G₁._∘_) ≡ (G₂.Carrier , G₂._∘_)) ≡≃,∘≡,∘ {g = g} {G₁ = G₁} {G₂ = G₂} ext = G₁ ≡ G₂ ↝⟨ inverse $ Eq.≃-≡ Group≃ ⟩ ((G₁.Carrier , G₁._∘_) , _) ≡ ((G₂.Carrier , G₂._∘_) , _) ↔⟨ (inverse $ ignore-propositional-component $ The-rest-propositional _) ⟩□ (G₁.Carrier , G₁._∘_) ≡ (G₂.Carrier , G₂._∘_) □ where module G₁ = Group G₁ module G₂ = Group G₂ Carrier-∘ = ∃ λ (C : Type g) → (C → C → C) The-rest : Carrier-∘ → Type g The-rest (C , _∘_) = ∃ λ ((id , _⁻¹) : C ⊗ (C → C)) → Is-set C ⊗ (∀ x → (id ∘ x) ≡ x) ⊗ (∀ x → (x ∘ id) ≡ x) ⊗ (∀ x y z → (x ∘ (y ∘ z)) ≡ ((x ∘ y) ∘ z)) ⊗ (∀ x → ((x ⁻¹) ∘ x) ≡ id) ⊗ (∀ x → (x ∘ (x ⁻¹)) ≡ id) Group≃ : Group g ≃ Σ Carrier-∘ The-rest Group≃ = Eq.↔→≃ (λ G → let open Group G in (Carrier , _∘_) , (id , _⁻¹) , Carrier-is-set , left-identity , right-identity , assoc , left-inverse , right-inverse) _ refl refl The-rest-propositional : ∀ C → Is-proposition (The-rest C) The-rest-propositional C R₁ R₂ = Σ-≡,≡→≡ (cong₂ _,_ id-unique inverse-unique) ((×-closure 1 (H-level-propositional ext 2) $ ×-closure 1 (Π-closure ext 1 λ _ → G₂′.Carrier-is-set) $ ×-closure 1 (Π-closure ext 1 λ _ → G₂′.Carrier-is-set) $ ×-closure 1 (Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → G₂′.Carrier-is-set) $ ×-closure 1 (Π-closure ext 1 λ _ → G₂′.Carrier-is-set) $ (Π-closure ext 1 λ _ → G₂′.Carrier-is-set)) _ _) where module G₁′ = Group (_≃_.from Group≃ (C , R₁)) module G₂′ = Group (_≃_.from Group≃ (C , R₂)) id-unique : G₁′.id ≡ G₂′.id id-unique = G₂′.idempotent⇒≡id (G₁′.left-identity G₁′.id) inverse-unique : G₁′._⁻¹ ≡ G₂′._⁻¹ inverse-unique = apply-ext ext λ x → G₂′.⁻¹-unique-right (x G₁′.∘ x G₁′.⁻¹ ≡⟨ G₁′.right-inverse _ ⟩ G₁′.id ≡⟨ id-unique ⟩∎ G₂′.id ∎) -- Group isomorphisms are equivalent to equalities (assuming -- extensionality and univalence). ≃ᴳ≃≡ : {G₁ G₂ : Group g} → Extensionality g g → Univalence g → (G₁ ≃ᴳ G₂) ≃ (G₁ ≡ G₂) ≃ᴳ≃≡ {G₁ = G₁} {G₂ = G₂} ext univ = G₁ ≃ᴳ G₂ ↝⟨ Homomorphic-as-Σ ⟩ (∃ λ (eq : G₁.Carrier ≃ G₂.Carrier) → ∀ x y → _≃_.to eq (x G₁.∘ y) ≡ _≃_.to eq x G₂.∘ _≃_.to eq y) ↝⟨ (∃-cong λ eq → Π-cong ext eq λ _ → Π-cong ext eq λ _ → ≡⇒≃ $ sym $ cong (_≡ _≃_.to eq _ G₂.∘ _≃_.to eq _) $ cong (_≃_.to eq) $ cong₂ G₁._∘_ (_≃_.left-inverse-of eq _) (_≃_.left-inverse-of eq _)) ⟩ (∃ λ (eq : G₁.Carrier ≃ G₂.Carrier) → ∀ x y → _≃_.to eq (_≃_.from eq x G₁.∘ _≃_.from eq y) ≡ x G₂.∘ y) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → Eq.extensionality-isomorphism ext) ⟩ (∃ λ (eq : G₁.Carrier ≃ G₂.Carrier) → ∀ x → (λ y → _≃_.to eq (_≃_.from eq x G₁.∘ _≃_.from eq y)) ≡ (x G₂.∘_)) ↝⟨ (∃-cong λ _ → Eq.extensionality-isomorphism ext) ⟩ (∃ λ (eq : G₁.Carrier ≃ G₂.Carrier) → (λ x y → _≃_.to eq (_≃_.from eq x G₁.∘ _≃_.from eq y)) ≡ G₂._∘_) ↝⟨ (∃-cong λ eq → ≡⇒≃ $ cong (_≡ _) $ sym $ lemma eq) ⟩ (∃ λ (eq : G₁.Carrier ≃ G₂.Carrier) → subst (λ A → A → A → A) (≃⇒≡ univ eq) G₁._∘_ ≡ G₂._∘_) ↝⟨ (Σ-cong (inverse $ ≡≃≃ univ) λ _ → Eq.id) ⟩ (∃ λ (eq : G₁.Carrier ≡ G₂.Carrier) → subst (λ A → A → A → A) eq G₁._∘_ ≡ G₂._∘_) ↔⟨ B.Σ-≡,≡↔≡ ⟩ ((G₁.Carrier , G₁._∘_) ≡ (G₂.Carrier , G₂._∘_)) ↝⟨ inverse $ ≡≃,∘≡,∘ ext ⟩□ G₁ ≡ G₂ □ where module G₁ = Group G₁ module G₂ = Group G₂ lemma : ∀ _ → _ lemma = λ eq → apply-ext ext λ x → apply-ext ext λ y → subst (λ A → A → A → A) (≃⇒≡ univ eq) G₁._∘_ x y ≡⟨ cong (_$ y) subst-→ ⟩ subst (λ A → A → A) (≃⇒≡ univ eq) (subst P.id (sym (≃⇒≡ univ eq)) x G₁.∘_) y ≡⟨ subst-→ ⟩ subst P.id (≃⇒≡ univ eq) (subst P.id (sym (≃⇒≡ univ eq)) x G₁.∘ subst P.id (sym (≃⇒≡ univ eq)) y) ≡⟨ cong₂ (λ f g → f (g x G₁.∘ g y)) (trans (apply-ext ext λ _ → subst-id-in-terms-of-≡⇒↝ equivalence) $ cong _≃_.to $ _≃_.right-inverse-of (≡≃≃ univ) _) (trans (apply-ext ext λ _ → subst-id-in-terms-of-inverse∘≡⇒↝ equivalence) $ cong _≃_.from $ _≃_.right-inverse-of (≡≃≃ univ) _) ⟩∎ _≃_.to eq (_≃_.from eq x G₁.∘ _≃_.from eq y) ∎ ------------------------------------------------------------------------ -- Abelian groups -- The property of being abelian. Abelian : Group g → Type g Abelian G = ∀ x y → x ∘ y ≡ y ∘ x where open Group G -- If two groups are isomorphic, and one is abelian, then the other -- one is abelian. ≃ᴳ→Abelian→Abelian : G₁ ≃ᴳ G₂ → Abelian G₁ → Abelian G₂ ≃ᴳ→Abelian→Abelian {G₁ = G₁} {G₂ = G₂} G₁≃G₂ ∘-comm x y = _≃_.injective (G₂≃G₁ .related) (to G₂≃G₁ (x G₂.∘ y) ≡⟨ G₂≃G₁ .homomorphic _ _ ⟩ to G₂≃G₁ x G₁.∘ to G₂≃G₁ y ≡⟨ ∘-comm _ _ ⟩ to G₂≃G₁ y G₁.∘ to G₂≃G₁ x ≡⟨ sym $ G₂≃G₁ .homomorphic _ _ ⟩∎ to G₂≃G₁ (y G₂.∘ x) ∎) where module G₁ = Group G₁ module G₂ = Group G₂ G₂≃G₁ = ≃ᴳ-sym G₁≃G₂ ------------------------------------------------------------------------ -- A group construction -- The direct product of two groups. infixr 2 _×_ _×_ : Group g₁ → Group g₂ → Group (g₁ ⊔ g₂) G₁ × G₂ = λ where .Carrier → G₁.Carrier ⊗ G₂.Carrier .Carrier-is-set → ×-closure 2 G₁.Carrier-is-set G₂.Carrier-is-set ._∘_ → Σ-zip G₁._∘_ G₂._∘_ .id → G₁.id , G₂.id ._⁻¹ → Σ-map G₁._⁻¹ G₂._⁻¹ .left-identity _ → cong₂ _,_ (G₁.left-identity _) (G₂.left-identity _) .right-identity _ → cong₂ _,_ (G₁.right-identity _) (G₂.right-identity _) .assoc _ _ _ → cong₂ _,_ (G₁.assoc _ _ _) (G₂.assoc _ _ _) .left-inverse _ → cong₂ _,_ (G₁.left-inverse _) (G₂.left-inverse _) .right-inverse _ → cong₂ _,_ (G₁.right-inverse _) (G₂.right-inverse _) where open Group module G₁ = Group G₁ module G₂ = Group G₂ -- The direct product operator preserves group homomorphisms. ↝-× : G₁ ↝[ k ]ᴳ G₂ → G₁′ ↝[ k ]ᴳ G₂′ → (G₁ × G₁′) ↝[ k ]ᴳ (G₂ × G₂′) ↝-× {G₁ = G₁} {k = k} {G₂ = G₂} {G₁′ = G₁′} {G₂′ = G₂′} G₁↝G₂ G₁′↝G₂′ = λ where .related → G₁↝G₂ .related ×-cong G₁′↝G₂′ .related .homomorphic x@(x₁ , x₂) y@(y₁ , y₂) → to-implication (G₁↝G₂ .related ×-cong G₁′↝G₂′ .related) (Σ-zip (Group._∘_ G₁) (Group._∘_ G₁′) x y) ≡⟨ cong (_$ _) $ to-implication-×-cong k ⟩ Σ-map (to G₁↝G₂) (to G₁′↝G₂′) (Σ-zip (Group._∘_ G₁) (Group._∘_ G₁′) x y) ≡⟨⟩ to G₁↝G₂ (Group._∘_ G₁ x₁ y₁) , to G₁′↝G₂′ (Group._∘_ G₁′ x₂ y₂) ≡⟨ cong₂ _,_ (G₁↝G₂ .homomorphic _ _) (G₁′↝G₂′ .homomorphic _ _) ⟩ Group._∘_ G₂ (to G₁↝G₂ x₁) (to G₁↝G₂ y₁) , Group._∘_ G₂′ (to G₁′↝G₂′ x₂) (to G₁′↝G₂′ y₂) ≡⟨⟩ Group._∘_ (G₂ × G₂′) (to G₁↝G₂ x₁ , to G₁′↝G₂′ x₂) (to G₁↝G₂ y₁ , to G₁′↝G₂′ y₂) ≡⟨ sym $ cong₂ (λ f g → Group._∘_ (G₂ × G₂′) (f _) (g _)) (to-implication-×-cong k) (to-implication-×-cong k) ⟩∎ Group._∘_ (G₂ × G₂′) (to-implication (G₁↝G₂ .related ×-cong G₁′↝G₂′ .related) x) (to-implication (G₁↝G₂ .related ×-cong G₁′↝G₂′ .related) y) ∎ -- Exponentiation for the direct product of G₁ and G₂ can be expressed -- in terms of exponentiation for G₁ and exponentiation for G₂. ^-× : ∀ (G₁ : Group g₁) (G₂ : Group g₂) {x y} i → Group._^_ (G₁ × G₂) (x , y) i ≡ (Group._^_ G₁ x i , Group._^_ G₂ y i) ^-× G₁ G₂ = helper where module G₁ = Group G₁ module G₂ = Group G₂ module G₁₂ = Group (G₁ × G₂) +-helper : ∀ n → (x , y) G₁₂.^+ n ≡ (x G₁.^+ n , y G₂.^+ n) +-helper zero = refl _ +-helper {x = x} {y = y} (suc n) = (x , y) G₁₂.∘ (x , y) G₁₂.^+ n ≡⟨ cong (_ G₁₂.∘_) $ +-helper n ⟩ (x , y) G₁₂.∘ (x G₁.^+ n , y G₂.^+ n) ≡⟨⟩ (x G₁.∘ x G₁.^+ n , y G₂.∘ y G₂.^+ n) ∎ helper : ∀ i → (x , y) G₁₂.^ i ≡ (x G₁.^ i , y G₂.^ i) helper (+ n) = +-helper n helper -[1+ n ] = +-helper (suc n) ------------------------------------------------------------------------ -- The centre of a group -- Centre ext G is the centre of the group G, sometimes denoted Z(G). Centre : Extensionality g g → Group g → Group g Centre ext G = λ where .Carrier → ∃ λ (x : Carrier) → ∀ y → x ∘ y ≡ y ∘ x .Carrier-is-set → Σ-closure 2 Carrier-is-set λ _ → Π-closure ext 2 λ _ → mono₁ 2 Carrier-is-set ._∘_ → Σ-zip _∘_ λ {x y} hyp₁ hyp₂ z → (x ∘ y) ∘ z ≡⟨ sym $ assoc _ _ _ ⟩ x ∘ (y ∘ z) ≡⟨ cong (x ∘_) $ hyp₂ z ⟩ x ∘ (z ∘ y) ≡⟨ assoc _ _ _ ⟩ (x ∘ z) ∘ y ≡⟨ cong (_∘ y) $ hyp₁ z ⟩ (z ∘ x) ∘ y ≡⟨ sym $ assoc _ _ _ ⟩∎ z ∘ (x ∘ y) ∎ .id → id , λ x → id ∘ x ≡⟨ left-identity _ ⟩ x ≡⟨ sym $ right-identity _ ⟩∎ x ∘ id ∎ ._⁻¹ → Σ-map _⁻¹ λ {x} hyp y → x ⁻¹ ∘ y ≡⟨ cong (x ⁻¹ ∘_) $ sym $ involutive _ ⟩ x ⁻¹ ∘ y ⁻¹ ⁻¹ ≡⟨ sym ∘⁻¹ ⟩ (y ⁻¹ ∘ x) ⁻¹ ≡⟨ cong _⁻¹ $ sym $ hyp (y ⁻¹) ⟩ (x ∘ y ⁻¹) ⁻¹ ≡⟨ ∘⁻¹ ⟩ y ⁻¹ ⁻¹ ∘ x ⁻¹ ≡⟨ cong (_∘ x ⁻¹) $ involutive _ ⟩∎ y ∘ x ⁻¹ ∎ .left-identity → λ _ → Σ-≡,≡→≡ (left-identity _) ((Π-closure ext 1 λ _ → Carrier-is-set) _ _) .right-identity → λ _ → Σ-≡,≡→≡ (right-identity _) ((Π-closure ext 1 λ _ → Carrier-is-set) _ _) .assoc → λ _ _ _ → Σ-≡,≡→≡ (assoc _ _ _) ((Π-closure ext 1 λ _ → Carrier-is-set) _ _) .left-inverse → λ _ → Σ-≡,≡→≡ (left-inverse _) ((Π-closure ext 1 λ _ → Carrier-is-set) _ _) .right-inverse → λ _ → Σ-≡,≡→≡ (right-inverse _) ((Π-closure ext 1 λ _ → Carrier-is-set) _ _) where open Group G -- The centre of an abelian group is isomorphic to the group. Abelian→Centre≃ : (ext : Extensionality g g) (G : Group g) → Abelian G → Centre ext G ≃ᴳ G Abelian→Centre≃ ext G abelian = ≃ᴳ-sym λ where .Homomorphic.related → inverse equiv .Homomorphic.homomorphic _ _ → cong (_ ,_) ((Π-closure ext 1 λ _ → Carrier-is-set) _ _) where open Group G equiv = (∃ λ (x : Carrier) → ∀ y → x ∘ y ≡ y ∘ x) ↔⟨ (drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ Π-closure ext 0 λ _ → propositional⇒inhabited⇒contractible Carrier-is-set (abelian _ _)) ⟩□ Carrier □
{ "alphanum_fraction": 0.4346118721, "avg_line_length": 35.960591133, "ext": "agda", "hexsha": "68a5b529d6bf7f0e484fab197dd411a859882011", "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": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/equality", "max_forks_repo_path": "src/Group.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/equality", "max_issues_repo_path": "src/Group.agda", "max_line_length": 147, "max_stars_count": 3, "max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/equality", "max_stars_repo_path": "src/Group.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z", "num_tokens": 8775, "size": 21900 }
module examplesPaperJFP.CatNonTerm where open import examplesPaperJFP.BasicIO hiding (main) open import examplesPaperJFP.Console hiding (main) open import examplesPaperJFP.NativeIOSafe module _ where {-# NON_TERMINATING #-} cat : IO ConsoleInterface Unit cat = exec getLine λ{ nothing → return unit ; (just line) → exec (putStrLn line) λ _ → cat }
{ "alphanum_fraction": 0.5447316103, "avg_line_length": 38.6923076923, "ext": "agda", "hexsha": "f12a58bf861e6683fda924b93e1a86f4929c0841", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z", "max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z", "max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "agda/ooAgda", "max_forks_repo_path": "examples/examplesPaperJFP/CatNonTerm.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "agda/ooAgda", "max_issues_repo_path": "examples/examplesPaperJFP/CatNonTerm.agda", "max_line_length": 76, "max_stars_count": 23, "max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/ooAgda", "max_stars_repo_path": "examples/examplesPaperJFP/CatNonTerm.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z", "num_tokens": 105, "size": 503 }
open import Data.Nat open import Data.Bool open import Data.Product open import Function open import Data.List hiding (lookup) open import Data.List.All open import Data.List.Membership.Propositional open import Data.Maybe.Categorical open import Category.Monad open import Agda.Primitive open import Size open import Codata.Thunk open import Codata.Delay open import Codata.Delay.Categorical module Typed.STLC.Delay where data Ty : Set where numt boolt : Ty _⟶_ : Ty → Ty → Ty data Expr : List Ty → Ty → Set where add : ∀ {Γ} → Expr Γ numt → Expr Γ numt → Expr Γ numt num : ∀ {Γ} → ℕ → Expr Γ numt true′ false′ : ∀ {Γ} → Expr Γ boolt if′_then_else : ∀ {Γ} → ∀ {t} → Expr Γ boolt → Expr Γ t → Expr Γ t → Expr Γ t ƛ_ : ∀ {Γ t₁ t₂} → Expr (t₁ ∷ Γ) t₂ → Expr Γ (t₁ ⟶ t₂) _∙_ : ∀ {Γ t₁ t₂} → Expr Γ (t₁ ⟶ t₂) → Expr Γ t₁ → Expr Γ t₂ var : ∀ {Γ t} → t ∈ Γ → Expr Γ t mutual data Val : Ty → Set where numv : ℕ → Val numt boolv : Bool → Val boolt ⟨ƛ_,_⟩ : ∀ {Γ t₁ t₂} → Expr (t₁ ∷ Γ) t₂ → Env Γ → Val (t₁ ⟶ t₂) Env : List Ty → Set Env Γ = All Val Γ ReaderT : ∀ {a} {M : Set a → Set a} (R : Set a) → RawMonad M → RawMonad (λ A → R → M A) ReaderT _ M = record { return = λ a _ → return a ; _>>=_ = λ f k r → f r >>= λ x → k x r } where open RawMonad M module _ {Γ : List Ty} {i} where open RawMonad {lzero} (ReaderT (Env Γ) (Sequential.monad {i})) public M : List Ty → Size → Set → Set M Γ i A = Env Γ → Delay A i getEnv : ∀ {Γ i} → M Γ i (Env Γ) getEnv E = now E withEnv : ∀ {Γ Γ' i A} → Env Γ → M Γ i A → M Γ' i A withEnv E m _ = m E get : ∀ {Γ t i} → t ∈ Γ → M Γ i (Val t) get x E = now (lookup E x) mutual eval : ∀ {Γ t} → Expr Γ t → ∀ {i} → M Γ i (Val t) eval (add e₁ e₂) = do numv n₁ ← eval e₁ numv n₂ ← eval e₁ return (numv (n₁ + n₂)) eval (num n) = do return (numv n) eval true′ = do return (boolv true) eval false′ = do return (boolv false) eval (if′ c then t else e) = do (boolv b) ← eval c if b then eval t else eval e eval (ƛ e) = do E ← getEnv return ⟨ƛ e , E ⟩ eval (f ∙ a) = do ⟨ƛ e , E ⟩ ← eval f v ← eval a withEnv (v ∷ E) (▹eval e) eval (var x) = do get x ▹eval : ∀ {Γ i t} → Expr Γ t → M Γ i (Val t) ▹eval e E = later λ where .force → eval e E
{ "alphanum_fraction": 0.555179704, "avg_line_length": 23.1862745098, "ext": "agda", "hexsha": "317a8de5a527d5dc51a7e69e0bbbeef029ecfdb0", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z", "max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z", "max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "laMudri/linear.agda", "max_forks_repo_path": "src/Typed/STLC/Delay.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "laMudri/linear.agda", "max_issues_repo_path": "src/Typed/STLC/Delay.agda", "max_line_length": 87, "max_stars_count": 34, "max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "laMudri/linear.agda", "max_stars_repo_path": "src/Typed/STLC/Delay.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z", "num_tokens": 942, "size": 2365 }
{-# OPTIONS --cubical --safe --postfix-projections #-} open import Prelude hiding (_×_) module Categories.HSets {ℓ : Level} where open import Categories open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence open import Data.Sigma.Properties open import Categories.Product open import Categories.Exponential hSetPreCategory : PreCategory (ℓsuc ℓ) ℓ hSetPreCategory .PreCategory.Ob = hSet _ hSetPreCategory .PreCategory.Hom (X , _) (Y , _) = X → Y hSetPreCategory .PreCategory.Id = id hSetPreCategory .PreCategory.Comp f g = f ∘ g hSetPreCategory .PreCategory.assoc-Comp _ _ _ = refl hSetPreCategory .PreCategory.Comp-Id _ = refl hSetPreCategory .PreCategory.Id-Comp _ = refl hSetPreCategory .PreCategory.Hom-Set {X} {Y} = hLevelPi 2 λ _ → Y .snd open PreCategory hSetPreCategory _⟨×⟩_ : isSet A → isSet B → isSet (A Prelude.× B) xs ⟨×⟩ ys = isOfHLevelΣ 2 xs (const ys) module _ {X Y : Ob} where iso-iso : (X ≅ Y) ⇔ (fst X ⇔ fst Y) iso-iso .fun (f , g , f∘g , g∘f) = iso f g (λ x i → g∘f i x) (λ x i → f∘g i x) iso-iso .inv (iso f g g∘f f∘g) = f , g , (λ i x → f∘g x i) , (λ i x → g∘f x i) iso-iso .rightInv _ = refl iso-iso .leftInv _ = refl univ⇔ : (X ≡ Y) ⇔ (X ≅ Y) univ⇔ = equivToIso (≃ΣProp≡ (λ _ → isPropIsSet)) ⟨ trans-⇔ ⟩ equivToIso univalence ⟨ trans-⇔ ⟩ sym-⇔ (iso⇔equiv (snd X)) ⟨ trans-⇔ ⟩ sym-⇔ iso-iso hSetCategory : Category (ℓsuc ℓ) ℓ hSetCategory .Category.preCategory = hSetPreCategory hSetCategory .Category.univalent = isoToEquiv univ⇔ hSetProd : HasProducts hSetCategory hSetProd .HasProducts.product X Y .Product.obj = (X .fst Prelude.× Y .fst) , X .snd ⟨×⟩ Y .snd hSetProd .HasProducts.product X Y .Product.proj₁ = fst hSetProd .HasProducts.product X Y .Product.proj₂ = snd hSetProd .HasProducts.product X Y .Product.ump f g .fst z = f z , g z hSetProd .HasProducts.product X Y .Product.ump f g .snd .fst .fst = refl hSetProd .HasProducts.product X Y .Product.ump f g .snd .fst .snd = refl hSetProd .HasProducts.product X Y .Product.ump f g .snd .snd (f≡ , g≡) i x = f≡ (~ i) x , g≡ (~ i) x hSetExp : HasExponentials hSetCategory hSetProd hSetExp X Y .Exponential.obj = (X .fst → Y .fst) , hLevelPi 2 λ _ → Y .snd hSetExp X Y .Exponential.eval (f , x) = f x hSetExp X Y .Exponential.uniq X₁ f .fst = curry f hSetExp X Y .Exponential.uniq X₁ f .snd .fst = refl hSetExp X Y .Exponential.uniq X₁ f .snd .snd {y} x = cong curry (sym x) open import Categories.Pullback hSetHasPullbacks : HasPullbacks hSetCategory hSetHasPullbacks {X = X} {Y = Y} {Z = Z} f g .Pullback.P = ∃[ ab ] (f (fst ab) ≡ g (snd ab)) , isOfHLevelΣ 2 (X .snd ⟨×⟩ Y .snd) λ xy → isProp→isSet (Z .snd (f (xy .fst)) (g (xy .snd))) hSetHasPullbacks f g .Pullback.p₁ ((x , _) , _) = x hSetHasPullbacks f g .Pullback.p₂ ((_ , y) , _) = y hSetHasPullbacks f g .Pullback.commute = funExt snd hSetHasPullbacks f g .Pullback.ump {A = A} h₁ h₂ p .fst x = (h₁ x , h₂ x) , λ i → p i x hSetHasPullbacks f g .Pullback.ump {A = A} h₁ h₂ p .snd .fst .fst = refl hSetHasPullbacks f g .Pullback.ump {A = A} h₁ h₂ p .snd .fst .snd = refl hSetHasPullbacks {Z = Z} f g .Pullback.ump {A = A} h₁ h₂ p .snd .snd {i} (p₁e , p₂e) = funExt (λ x → ΣProp≡ (λ _ → Z .snd _ _) λ j → p₁e (~ j) x , p₂e (~ j) x) hSetTerminal : Terminal hSetTerminal .fst = Lift _ ⊤ , isProp→isSet λ _ _ → refl hSetTerminal .snd .fst x .lower = tt hSetTerminal .snd .snd y = funExt λ _ → refl hSetInitial : Initial hSetInitial .fst = Lift _ ⊥ , λ () hSetInitial .snd .fst () hSetInitial .snd .snd y i () open import HITs.PropositionalTruncation open import Categories.Coequalizer ∃!′ : (A : Type a) → (A → Type b) → Type (a ℓ⊔ b) ∃!′ A P = ∥ Σ A P ∥ Prelude.× AtMostOne P lemma23 : ∀ {p} {P : A → hProp p} → ∃!′ A (fst ∘ P) → Σ A (fst ∘ P) lemma23 {P = P} (x , y) = rec (λ xs ys → ΣProp≡ (snd ∘ P) (y (xs .fst) (ys .fst) (xs .snd) (ys .snd))) id x module _ {A : Type a} {P : A → Type b} (R : ∀ x → P x → hProp c) where uniqueChoice : (Π[ x ⦂ A ] (∃!′ (P x) (λ u → R x u .fst))) → Σ[ f ⦂ Π[ x ⦂ A ] P x ] Π[ x ⦂ A ] (R x (f x) .fst) uniqueChoice H = fst ∘ mid , snd ∘ mid where mid : Π[ x ⦂ A ] Σ[ u ⦂ P x ] (R x u .fst) mid x = lemma23 {P = R x} (H x) open import HITs.PropositionalTruncation.Sugar module CoeqProofs {X Y : Ob} (f : X ⟶ Y) where KernelPair : Pullback hSetCategory {X = X} {Z = Y} {Y = X} f f KernelPair = hSetHasPullbacks f f Im : Ob Im = ∃[ b ] ∥ fiber f b ∥ , isOfHLevelΣ 2 (Y .snd) λ _ → isProp→isSet squash im : X ⟶ Im im x = f x , ∣ x , refl ∣ open Pullback KernelPair lem : ∀ {H : Ob} (h : X ⟶ H) → h ∘ p₁ ≡ h ∘ p₂ → Σ[ f ⦂ (Im ⟶ H) ] Π[ x ⦂ Im .fst ] (∀ y → im y ≡ x → h y ≡ f x) lem {H = H} h eq = uniqueChoice R prf where R : Im .fst → H .fst → hProp _ R w x .fst = ∀ y → im y ≡ w → h y ≡ x R w x .snd = hLevelPi 1 λ _ → hLevelPi 1 λ _ → H .snd _ _ prf : Π[ x ⦂ Im .fst ] ∃!′ (H .fst) (λ u → ∀ y → im y ≡ x → h y ≡ u) prf (xy , p) .fst = (λ { (z , r) → h z , λ y imy≡xyp → cong (_$ ((y , z) , cong fst imy≡xyp ; sym r)) eq }) ∥$∥ p prf (xy , p) .snd x₁ x₂ Px₁ Px₂ = rec (H .snd x₁ x₂) (λ { (z , zs) → sym (Px₁ z (ΣProp≡ (λ _ → squash) zs)) ; Px₂ z (ΣProp≡ (λ _ → squash) zs) } ) p lem₂ : ∀ (H : Ob) (h : X ⟶ H) (i : Im ⟶ H) (x : Im .fst) (hi : h ≡ i ∘ im) (eq : h ∘ p₁ ≡ h ∘ p₂) → i x ≡ lem {H = H} h eq .fst x lem₂ H h i x hi eq = rec (H .snd _ _) (λ { (y , ys) → (cong i (ΣProp≡ (λ _ → squash) (sym ys)) ; sym (cong (_$ y) hi)) ; lem {H = H} h eq .snd x y (ΣProp≡ (λ _ → squash) ys) }) (x .snd) hSetCoeq : Coequalizer hSetCategory {X = P} {Y = X} p₁ p₂ hSetCoeq .Coequalizer.obj = Im hSetCoeq .Coequalizer.arr = im hSetCoeq .Coequalizer.equality = funExt λ x → ΣProp≡ (λ _ → squash) λ i → commute i x hSetCoeq .Coequalizer.coequalize {H = H} {h = h} eq = lem {H = H} h eq .fst hSetCoeq .Coequalizer.universal {H = H} {h = h} {eq = eq} = funExt λ x → lem {H = H} h eq .snd (im x) x refl hSetCoeq .Coequalizer.unique {H = H} {h = h} {i = i} {eq = eq} prf = funExt λ x → lem₂ H h i x prf eq open CoeqProofs using (hSetCoeq) public module PullbackSurjProofs {X Y : Ob} (f : X ⟶ Y) (fSurj : Surjective f) where KernelPair : Pullback hSetCategory {X = X} {Z = Y} {Y = X} f f KernelPair = hSetHasPullbacks f f open Pullback KernelPair p₁surj : Surjective p₁ p₁surj y = ∣ ((y , y) , refl) , refl ∣ p₂surj : Surjective p₂ p₂surj y = ∣ ((y , y) , refl) , refl ∣ open import Relation.Binary open import Cubical.HITs.SetQuotients module _ {A : Type a} {R : A → A → Type b} {C : Type c} (isSetC : isSet C) (f : A → C) (coh : ∀ x y → R x y → f x ≡ f y) where recQuot : A / R → C recQuot [ a ] = f a recQuot (eq/ a b r i) = coh a b r i recQuot (squash/ xs ys x y i j) = isSetC (recQuot xs) (recQuot ys) (cong recQuot x) (cong recQuot y) i j open import Path.Reasoning module ExtactProofs {X : Ob} {R : X .fst → X .fst → hProp ℓ} (symR : Symmetric (λ x y → R x y .fst)) (transR : Transitive (λ x y → R x y .fst)) (reflR : Reflexive (λ x y → R x y .fst)) where ℛ : X .fst → X .fst → Type ℓ ℛ x y = R x y .fst Src : Ob Src .fst = ∃[ x,y ] (uncurry ℛ x,y) Src .snd = isOfHLevelΣ 2 (X .snd ⟨×⟩ X .snd) λ _ → isProp→isSet (R _ _ .snd) pr₁ pr₂ : Src ⟶ X pr₁ = fst ∘ fst pr₂ = snd ∘ fst ROb : Ob ROb = X .fst / ℛ , squash/ CR : Coequalizer hSetCategory {X = Src} {Y = X} pr₁ pr₂ CR .Coequalizer.obj = ROb CR .Coequalizer.arr = [_] CR .Coequalizer.equality = funExt λ { ((x , y) , x~y) → eq/ x y x~y} CR .Coequalizer.coequalize {H = H} {h = h} e = recQuot (H .snd) h λ x y x~y → cong (_$ ((x , y) , x~y)) e CR .Coequalizer.universal {H = H} {h = h} {eq = e} = refl CR .Coequalizer.unique {H = H} {h = h} {i = i} {eq = e} p = funExt (elimSetQuotientsProp (λ _ → H .snd _ _) λ x j → p (~ j) x)
{ "alphanum_fraction": 0.5928508049, "avg_line_length": 40.6649484536, "ext": "agda", "hexsha": "d6f33987df2b69b48fb71291479a132bee2329f3", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/Categories/HSets.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_path": "agda/Categories/HSets.agda", "max_line_length": 187, "max_stars_count": null, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/Categories/HSets.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3382, "size": 7889 }
{-# OPTIONS --type-in-type #-} module Record where infixr 2 _,_ record Σ (A : Set)(B : A → Set) : Set where constructor _,_ field fst : A snd : B fst open Σ data ⊤ : Set where tt : ⊤ ∃ : {A : Set}(B : A → Set) → Set ∃ B = Σ _ B infix 10 _≡_ data _≡_ {A : Set}(a : A) : {B : Set} → B → Set where refl : a ≡ a trans : ∀ {A B C}{a : A}{b : B}{c : C} → a ≡ b → b ≡ c → a ≡ c trans refl p = p sym : ∀ {A B}{a : A}{b : B} → a ≡ b → b ≡ a sym refl = refl resp : ∀ {A}{B : A → Set}{a a' : A} → (f : (a : A) → B a) → a ≡ a' → f a ≡ f a' resp f refl = refl Cat : Set Cat = ∃ λ (Obj : Set) → ∃ λ (Hom : Obj → Obj → Set) → ∃ λ (id : ∀ X → Hom X X) → ∃ λ (_○_ : ∀ {X Y Z} → Hom Y Z → Hom X Y → Hom X Z) → ∃ λ (idl : ∀ {X Y}{f : Hom X Y} → id Y ○ f ≡ f) → ∃ λ (idr : ∀ {X Y}{f : Hom X Y} → f ○ id X ≡ f) → ∃ λ (assoc : ∀ {W X Y Z}{f : Hom W X}{g : Hom X Y}{h : Hom Y Z} → (h ○ g) ○ f ≡ h ○ (g ○ f)) → ⊤ Obj : (C : Cat) → Set Obj C = fst C Hom : (C : Cat) → Obj C → Obj C → Set Hom C = fst (snd C) id : (C : Cat) → ∀ X → Hom C X X id C = fst (snd (snd C)) comp : (C : Cat) → ∀ {X Y Z} → Hom C Y Z → Hom C X Y → Hom C X Z comp C = fst (snd (snd (snd C))) idl : (C : Cat) → ∀ {X Y}{f : Hom C X Y} → comp C (id C Y) f ≡ f idl C = fst (snd (snd (snd (snd C)))) idr : (C : Cat) → ∀ {X Y}{f : Hom C X Y} → comp C f (id C X) ≡ f idr C = fst (snd (snd (snd (snd (snd C))))) assoc : (C : Cat) → ∀ {W X Y Z}{f : Hom C W X}{g : Hom C X Y}{h : Hom C Y Z} → comp C (comp C h g) f ≡ comp C h (comp C g f) assoc C = fst (snd (snd (snd (snd (snd (snd C))))))
{ "alphanum_fraction": 0.4322139303, "avg_line_length": 24.3636363636, "ext": "agda", "hexsha": "84a1b075c7942e5b2c8d205309391741af76db6c", "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": "benchmark/proj/Record.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": "benchmark/proj/Record.agda", "max_line_length": 78, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "benchmark/proj/Record.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": 748, "size": 1608 }
module Basics where data Zero : Set where record One : Set where constructor <> data Two : Set where tt ff : Two data Nat : Set where ze : Nat su : Nat -> Nat data _+_ (S T : Set) : Set where inl : S -> S + T inr : T -> S + T record Sg (S : Set)(T : S -> Set) : Set where constructor _,_ field fst : S snd : T fst open Sg public _*_ : Set -> Set -> Set S * T = Sg S \ _ -> T infixr 4 _,_ _*_ data _==_ {X : Set}(x : X) : X -> Set where refl : x == x
{ "alphanum_fraction": 0.55, "avg_line_length": 17.1428571429, "ext": "agda", "hexsha": "7d271c2a3a62e4c4e50e16dbf03f42e645f228d0", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-06-09T05:39:02.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-09T05:39:02.000Z", "max_forks_repo_head_hexsha": "21ac5be5a0a04fc75699d595c08b5ae4b7d7712d", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "pigworker/WhatRTypes4", "max_forks_repo_path": "Basics.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "21ac5be5a0a04fc75699d595c08b5ae4b7d7712d", "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": "pigworker/WhatRTypes4", "max_issues_repo_path": "Basics.agda", "max_line_length": 45, "max_stars_count": 11, "max_stars_repo_head_hexsha": "21ac5be5a0a04fc75699d595c08b5ae4b7d7712d", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "pigworker/WhatRTypes4", "max_stars_repo_path": "Basics.agda", "max_stars_repo_stars_event_max_datetime": "2019-06-09T05:38:44.000Z", "max_stars_repo_stars_event_min_datetime": "2016-06-11T09:12:25.000Z", "num_tokens": 176, "size": 480 }
-- Homotopy type theory -- https://github.com/agda/cubical {-# OPTIONS --without-K --safe #-} module TypeTheory.HoTT.Base where -- agda-stdlib open import Level renaming (zero to lzero; suc to lsuc) open import Data.Product open import Relation.Binary.PropositionalEquality private variable a b : Level fiber : {A : Set a} {B : Set b} (f : A → B) (y : B) → Set (a ⊔ b) fiber f y = ∃ λ x → f x ≡ y isContr : Set a → Set a isContr A = Σ A λ x → ∀ y → x ≡ y isProp : Set a → Set a isProp A = (x y : A) → x ≡ y isSet : Set a → Set a isSet A = (x y : A) → isProp (x ≡ y)
{ "alphanum_fraction": 0.6110154905, "avg_line_length": 20.0344827586, "ext": "agda", "hexsha": "04df4be4123e9c59cba694108c3632fae1325abf", "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": "TypeTheory/HoTT/Base.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": "TypeTheory/HoTT/Base.agda", "max_line_length": 65, "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": "TypeTheory/HoTT/Base.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": 210, "size": 581 }
{-# OPTIONS --without-K --safe #-} module Dodo.Binary.Equality where -- Stdlib imports import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl) open import Level using (Level; _⊔_) open import Function using (_∘_) open import Relation.Unary using (Pred) open import Relation.Binary using (Rel; REL) open import Relation.Binary using (Symmetric) -- Local imports open import Dodo.Unary.Equality infix 4 _⊆₂'_ _⊆₂_ _⇔₂_ _⊇₂_ -- | Binary relation subset helper. Generally, use `_⊆₂_` (below). -- -- -- # Design decision: Explicit variables -- -- `x` and `y` are passed /explicitly/. If they were implicit, Agda tries (and often fails) to -- instantiate them at inappropriate applications. _⊆₂'_ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} → (P : REL A B ℓ₁) → (R : REL A B ℓ₂) → Set _ _⊆₂'_ {A = A} {B = B} P R = ∀ (x : A) (y : B) → P x y → R x y -- | Binary relation subset -- -- Note that this does /not/ describe structural equality between inhabitants, only -- "(directed) co-inhabitation". -- `P ⊆₂ Q` denotes: If `P x y` is inhabited, then `Q x y` is inhabited. -- -- Whatever these inhabitants are, is irrelevant w.r.t. the subset constraint. -- -- -- # Design decision: Include P and R in the type -- -- Somehow, Agda cannot infer P and R from `P ⇒ R`, and requires them explicitly passed. -- For proof convenience, wrap the proof in this structure, which explicitly conveys P and R -- to the type-checker. data _⊆₂_ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} (P : REL A B ℓ₁) (R : REL A B ℓ₂) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where ⊆: : P ⊆₂' R → P ⊆₂ R -- | Binary relation equality -- -- Note that this does /not/ describe structural equality between inhabitants, only -- "co-inhabitation". -- `P ⇔₂ Q` denotes: `P x y` is inhabited iff `Q x y` is inhabited. -- -- Whatever these inhabitants are, is irrelevant w.r.t. the equality constraint. -- -- -- # Design decision: Include P and R in the type -- -- Somehow, Agda cannot infer P and R from `P ⇔ R`, and requires them explicitly passed. -- For proof convenience, wrap the proof in this structure, which explicitly conveys P and R -- to the type-checker. data _⇔₂_ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} (P : REL A B ℓ₁) (R : REL A B ℓ₂) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where ⇔: : P ⊆₂' R → R ⊆₂' P → P ⇔₂ R -- | Binary relation superset _⊇₂_ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} (P : REL A B ℓ₁) (R : REL A B ℓ₂) → Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) P ⊇₂ R = R ⊆₂ P -- # Helpers -- | Unwraps the `⊆:` constructor un-⊆₂ : ∀ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {R : REL A B ℓ₂} → P ⊆₂ R ------- → P ⊆₂' R un-⊆₂ (⊆: P⊆R) = P⊆R -- | Unlifts a function over `⊆₂` to its unwrapped variant over `⊆₂'`. unlift-⊆₂ : ∀ {a b c d ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL C D ℓ₃} {S : REL C D ℓ₄} → ( P ⊆₂ Q → R ⊆₂ S ) --------------------- → ( P ⊆₂' Q → R ⊆₂' S ) unlift-⊆₂ f P⊆Q = un-⊆₂ (f (⊆: P⊆Q)) -- | Lifts a function over `⊆₂'` to its wrapped variant over `⊆₂`. lift-⊆₂ : ∀ {a b c d ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL C D ℓ₃} {S : REL C D ℓ₄} → ( P ⊆₂' Q → R ⊆₂' S ) --------------------- → ( P ⊆₂ Q → R ⊆₂ S ) lift-⊆₂ f (⊆: P⊆Q) = ⊆: (f P⊆Q) -- | Introduces an equality `⇔₂` from both bi-directional components. ⇔₂-intro : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} → {P : REL A B ℓ₁} {R : REL A B ℓ₂} → P ⊆₂ R → R ⊆₂ P ------ → P ⇔₂ R ⇔₂-intro (⊆: P⊆R) (⊆: R⊆P) = ⇔: P⊆R R⊆P -- | Construct an equality `⇔₂` from a mapping over both bi-directional components. ⇔₂-compose : ∀ {a b c d ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c} {D : Set d} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL C D ℓ₃} {S : REL C D ℓ₄} → ( P ⊆₂ Q → R ⊆₂ S ) → ( Q ⊆₂ P → S ⊆₂ R ) → P ⇔₂ Q ------------------- → R ⇔₂ S ⇔₂-compose ⊆-proof ⊇-proof (⇔: P⊆Q R⊆S) = ⇔₂-intro (⊆-proof (⊆: P⊆Q)) (⊇-proof (⊆: R⊆S)) -- | Construct a /binary/ equality `⇔₂` from a mapping over both bi-directional components of a /unary/ relation. ⇔₂-compose-⇔₁ : ∀ {a b c ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c} {P : Pred A ℓ₁} {Q : Pred A ℓ₂} {R : REL B C ℓ₃} {S : REL B C ℓ₄} → ( P ⊆₁ Q → R ⊆₂ S ) → ( Q ⊆₁ P → S ⊆₂ R ) → P ⇔₁ Q ------------------- → R ⇔₂ S ⇔₂-compose-⇔₁ ⊆-proof ⊇-proof (⇔: P⊆Q R⊆S) = ⇔₂-intro (⊆-proof (⊆: P⊆Q)) (⊇-proof (⊆: R⊆S)) -- | Construct a /unary/ equalty `⇔₁` from a mapping over both bi-directional components of a /binary/ relation. ⇔₁-compose-⇔₂ : ∀ {a b c ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level} {A : Set a} {B : Set b} {C : Set c} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : Pred C ℓ₃} {S : Pred C ℓ₄} → ( P ⊆₂ Q → R ⊆₁ S ) → ( Q ⊆₂ P → S ⊆₁ R ) → P ⇔₂ Q ------------------- → R ⇔₁ S ⇔₁-compose-⇔₂ ⊆-proof ⊇-proof (⇔: P⊆Q R⊆S) = ⇔₁-intro (⊆-proof (⊆: P⊆Q)) (⊇-proof (⊆: R⊆S)) -- # Properties -- ## Properties: ⊆₂ module _ {a b ℓ : Level} {A : Set a} {B : Set b} {R : REL A B ℓ} where ⊆₂-refl : R ⊆₂ R ⊆₂-refl = ⊆: (λ _ _ Rxy → Rxy) module _ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL A B ℓ₃} where ⊆₂-trans : P ⊆₂ Q → Q ⊆₂ R → P ⊆₂ R ⊆₂-trans (⊆: P⊆Q) (⊆: Q⊆R) = ⊆: (λ x y Pxy → Q⊆R x y (P⊆Q x y Pxy)) -- ## Properties: ⇔₂ module _ {a b ℓ : Level} {A : Set a} {B : Set b} {R : REL A B ℓ} where ⇔₂-refl : R ⇔₂ R ⇔₂-refl = ⇔₂-intro ⊆₂-refl ⊆₂-refl module _ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {Q : REL A B ℓ₁} {R : REL A B ℓ₂} where -- | Symmetry of the `_⇔₂_` operation. -- -- -- # Design decision: No Symmetric -- -- Do /not/ use `Symmetric _⇔₂_` as its type. It messes up the universe levels. ⇔₂-sym : Q ⇔₂ R → R ⇔₂ Q ⇔₂-sym (⇔: Q⊆R R⊆Q) = ⇔: R⊆Q Q⊆R module _ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL A B ℓ₃} where ⇔₂-trans : P ⇔₂ Q → Q ⇔₂ R → P ⇔₂ R ⇔₂-trans (⇔: P⊆Q Q⊆P) (⇔: Q⊆R R⊆Q) = ⇔₂-intro (⊆₂-trans (⊆: P⊆Q) (⊆: Q⊆R)) (⊆₂-trans (⊆: R⊆Q) (⊆: Q⊆P)) -- # Operations -- ## Operations: ⇔₂ and ⊆₂ conversion ⇔₂-to-⊆₂ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⇔₂ Q ------ → P ⊆₂ Q ⇔₂-to-⊆₂ (⇔: P⊆Q _) = ⊆: P⊆Q ⇔₂-to-⊇₂ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⇔₂ Q ------ → Q ⊆₂ P ⇔₂-to-⊇₂ (⇔: _ Q⊆P) = ⊆: Q⊆P -- ## Operations: ⊆₂ ⊆₂-apply : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⊆₂ Q → {x : A} {y : B} → P x y --------------- → Q x y ⊆₂-apply (⊆: P⊆Q) {x} {y} = P⊆Q x y -- | Substitute an equal relation (under `⇔₂`) for the left-hand side of a subset definition. ⊆₂-substˡ : ∀ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL A B ℓ₃} → P ⇔₂ Q → P ⊆₂ R ------ → Q ⊆₂ R ⊆₂-substˡ (⇔: _ Q⊆P) P⊆R = ⊆₂-trans (⊆: Q⊆P) P⊆R -- | Substitute an equal relation (under `⇔₂`) for the right-hand side of a subset definition. ⊆₂-substʳ : ∀ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL A B ℓ₃} → Q ⇔₂ R → P ⊆₂ Q ------ → P ⊆₂ R ⊆₂-substʳ (⇔: Q⊆R _) P⊆Q = ⊆₂-trans P⊆Q (⊆: Q⊆R) -- | Weaken intentional equality of relations to their subset `⊆₂` definition. ≡-to-⊆₂ : {a b ℓ : Level} {A : Set a} {B : Set b} {P Q : REL A B ℓ} → P ≡ Q ------ → P ⊆₂ Q ≡-to-⊆₂ refl = ⊆: (λ _ _ Pxy → Pxy) -- | Weaken intentional equality of relations to their superset definition (inverted `⊆₂`). ≡-to-⊇₂ : {a b ℓ : Level} {A : Set a} {B : Set b} {P Q : REL A B ℓ} → P ≡ Q ------ → Q ⊆₂ P ≡-to-⊇₂ refl = ⊆: (λ _ _ Qxy → Qxy) -- | Substitute both elements of the relation's instantiation. subst-rel : {a b ℓ : Level} → {A : Set a} {B : Set b} → (R : REL A B ℓ) → {x₁ x₂ : A} → x₁ ≡ x₂ → {y₁ y₂ : B} → y₁ ≡ y₂ → R x₁ y₁ ----------------------- → R x₂ y₂ subst-rel _ refl refl Rxy = Rxy -- ## Operations: ⇔₂ ⇔₂-apply-⊆₂ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⇔₂ Q → {x : A} {y : B} → P x y --------------- → Q x y ⇔₂-apply-⊆₂ = ⊆₂-apply ∘ ⇔₂-to-⊆₂ ⇔₂-apply-⊇₂ : {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⇔₂ Q → {x : A} {y : B} → Q x y --------------- → P x y ⇔₂-apply-⊇₂ = ⊆₂-apply ∘ ⇔₂-to-⊇₂ ≡-to-⇔₂ : {a b ℓ : Level} {A : Set a} {B : Set b} {P Q : REL A B ℓ} → P ≡ Q ------ → P ⇔₂ Q ≡-to-⇔₂ refl = ⇔₂-intro ⊆₂-refl ⊆₂-refl -- # Reasoning -- ## Reasoning: ⊆₂ -- | A collection of functions for writing subset proofs over binary relations. -- -- -- # Example -- -- ``` -- proof P Q R S = -- begin⊆₂ -- (P ⨾ Q) ⨾ (R ⨾ S) -- ⊆₂⟨ ⇔₂-to-⊇₂ ⨾-assoc ⟩ -- ((P ⨾ Q) ⨾ R) ⨾ S -- ⊆₂⟨ ⨾-substˡ-⊆₂ (⇔₂-to-⊆₂ ⨾-assoc) ⟩ -- P ⨾ (Q ⨾ R) ⨾ S -- ⊆₂∎ -- ``` module ⊆₂-Reasoning {a b ℓ₁ : Level} {A : Set a} {B : Set b} where infix 3 _⊆₂∎ infixr 2 step-⊆₂ infix 1 begin⊆₂_ begin⊆₂_ : {ℓ₂ : Level} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⊆₂ Q → P ⊆₂ Q begin⊆₂_ P⊆Q = P⊆Q step-⊆₂ : ∀ {ℓ₂ ℓ₃ : Level} → (P : REL A B ℓ₁) → {Q : REL A B ℓ₂} → {R : REL A B ℓ₃} → Q ⊆₂ R → P ⊆₂ Q → P ⊆₂ R step-⊆₂ P Q⊆R P⊆Q = ⊆₂-trans P⊆Q Q⊆R _⊆₂∎ : ∀ (P : REL A B ℓ₁) → P ⊆₂ P _⊆₂∎ P = ⊆: (λ _ _ z → z) syntax step-⊆₂ P Q⊆R P⊆Q = P ⊆₂⟨ P⊆Q ⟩ Q⊆R -- ## Reasoning: ⇔₂ -- | A collection of functions for writing equality proofs over binary relations. -- -- -- # Example -- -- ``` -- proof P Q R S = -- begin⇔₂ -- (P ⨾ Q) ⨾ (R ⨾ S) -- ⇔₂⟨ ⇔₂-sym ⨾-assoc ⟩ -- ((P ⨾ Q) ⨾ R) ⨾ S -- ⇔₂⟨ ⨾-substˡ ⨾-assoc ⟩ -- P ⨾ (Q ⨾ R) ⨾ S -- ⇔₂∎ -- ``` module ⇔₂-Reasoning {a b ℓ₁ : Level} {A : Set a} {B : Set b} where infix 3 _⇔₂∎ infixr 2 _⇔₂⟨⟩_ step-⇔₂ infix 1 begin⇔₂_ begin⇔₂_ : {ℓ₂ : Level} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} → P ⇔₂ Q → P ⇔₂ Q begin⇔₂_ P⇔Q = P⇔Q _⇔₂⟨⟩_ : {ℓ₂ : Level} (P : REL A B ℓ₁) → {Q : REL A B ℓ₂} → P ⇔₂ Q → P ⇔₂ Q _ ⇔₂⟨⟩ x≡y = x≡y step-⇔₂ : ∀ {ℓ₂ ℓ₃ : Level} → (P : REL A B ℓ₁) → {Q : REL A B ℓ₂} → {R : REL A B ℓ₃} → Q ⇔₂ R → P ⇔₂ Q → P ⇔₂ R step-⇔₂ _ Q⇔R P⇔Q = ⇔₂-trans P⇔Q Q⇔R _⇔₂∎ : ∀ (P : REL A B ℓ₁) → P ⇔₂ P _⇔₂∎ _ = ⇔₂-refl syntax step-⇔₂ P Q⇔R P⇔Q = P ⇔₂⟨ P⇔Q ⟩ Q⇔R
{ "alphanum_fraction": 0.479527266, "avg_line_length": 28.579787234, "ext": "agda", "hexsha": "cbe61913d82833189df3f3392c87b8f791b84e1b", "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": "376f0ccee1e1aa31470890e494bcb534324f598a", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "sourcedennis/agda-dodo", "max_forks_repo_path": "src/Dodo/Binary/Equality.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "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": "sourcedennis/agda-dodo", "max_issues_repo_path": "src/Dodo/Binary/Equality.agda", "max_line_length": 118, "max_stars_count": null, "max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "sourcedennis/agda-dodo", "max_stars_repo_path": "src/Dodo/Binary/Equality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5322, "size": 10746 }
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-} module Light.Implementation.Action where open import Light.Library.Action using (Library ; Dependencies) open import Light.Level using (++_ ; 0ℓ) open import Light.Library.Data.Unit using (Unit) open import Light.Library.Data.Natural using (ℕ) open import Light.Variable.Sets open import Light.Variable.Levels import Light.Package import Light.Implementation.Data.Natural import Light.Implementation.Data.Unit instance dependencies : Dependencies dependencies = record {} instance library : Library dependencies library = record { Implementation } where module Implementation where postulate Main : Set private postulate pure′ : 𝕒 → Main bind′ : Main → (𝕒 → Main) → Main follow : Main → Main → Main {-# COMPILE JS pure′ = () => () => () => a => () => a #-} {-# COMPILE JS bind′ = () => () => () => m => f => f(m()) #-} {-# COMPILE JS follow = () => () => m => m2 => () => (m(), m2()) #-} {-# NO_UNIVERSE_CHECK #-} data Action (𝕒 : Set ℓ) : Set ℓ where pure : 𝕒 → Action 𝕒 _>>=_ : Action 𝕓 → (𝕓 → Action 𝕒) → Action 𝕒 _>>_ : Action 𝕓 → Action 𝕒 → Action 𝕒 lift : Main → Action 𝕒 run : Action 𝕒 → Main run (pure a) = pure′ a run (a >>= f) = bind′ (run a) (λ a → run (f a)) run (a >> b) = follow (run a) (run b) run (lift m) = m private postulate log′ alert′ : 𝕒 → Main postulate prompt′ : Main log : 𝕒 → Action Unit log a = lift (log′ a) prompt = lift prompt′ alert : 𝕒 → Action Unit alert a = lift (alert′ a) {-# COMPILE JS log′ = () => () => a => () => console.log(a) #-} {-# COMPILE JS prompt′ = () => () => BigInt(prompt()) #-} {-# COMPILE JS alert′ = () => () => () => a => alert(a) #-}
{ "alphanum_fraction": 0.4678571429, "avg_line_length": 36.7213114754, "ext": "agda", "hexsha": "a2beaa866a7ebe9871800ee0e8409277909dbde9", "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": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "Zambonifofex/lightlib", "max_forks_repo_path": "Light/Implementation/Action.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "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": "Zambonifofex/lightlib", "max_issues_repo_path": "Light/Implementation/Action.agda", "max_line_length": 80, "max_stars_count": 1, "max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "zamfofex/lightlib", "max_stars_repo_path": "Light/Implementation/Action.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z", "num_tokens": 553, "size": 2240 }
module Impure.LFRef.Properties.Soundness where open import Data.Nat open import Data.Sum open import Data.Product as Pr open import Data.List as List hiding (monad) open import Data.Fin using (fromℕ≤; Fin) open import Data.Vec hiding (_∷ʳ_; _>>=_) open import Data.Star hiding (_>>=_) open import Function open import Extensions.List as L open import Relation.Binary.PropositionalEquality as P open import Relation.Binary.Core using (REL; Reflexive) open import Relation.Binary.List.Pointwise as PRel hiding (refl) open import Impure.LFRef.Syntax open import Impure.LFRef.Welltyped open import Impure.LFRef.Eval open import Impure.LFRef.Properties.Decidable progress : ∀ {𝕊 Σ A} {e : Exp 0} {μ} → 𝕊 , Σ ⊢ μ → 𝕊 , Σ , [] ⊢ₑ e ∶ A → -------------------------------------- (ExpVal e) ⊎ (∃₂ λ e' μ' → (𝕊 ⊢ e , μ ≻ e' , μ')) progress p (tm (con k ts _)) = inj₁ (tm con) progress p (tm unit) = inj₁ (tm unit) progress p (tm (var ())) progress p (tm (loc x)) = inj₁ (tm loc) progress p (fn ·★[ q ] ts) = inj₂ (, (, funapp-β fn (tele-fit-length ts))) progress p (ref e) with progress p e progress p (ref {_} {tm _} (tm _)) | inj₁ (tm v) = inj₂ (, (, ref-val v)) progress p (ref {_} {_ ·★ _} e) | inj₁ () progress p (ref {_} {ref x} e) | inj₁ () progress p (ref {_} { ! x } e) | inj₁ () progress p (ref {_} {x ≔ x₁} e) | inj₁ () progress p (ref e) | inj₂ (e' , μ' , step) = inj₂ (, (, ref-clos step)) progress p (!_ {x = x} e) with progress p e progress p (!_ {_} {tm .(loc _)} (tm (loc x))) | inj₁ (tm _) = inj₂ (, (, !-val (P.subst (_<_ _) (pointwise-length p) ([]=-length x)))) progress p (!_ {_} {tm (var ())} e) | _ progress p (!_ {_} {_ ·★ _} e) | inj₁ () progress p (!_ {_} {ref x} e) | inj₁ () progress p (!_ {_} { ! x } e) | inj₁ () progress p (!_ {_} {x ≔ x₁} e) | inj₁ () progress p (! e) | inj₂ (e' , μ' , step) = inj₂ (, (, !-clos step)) progress p (l ≔ e) with progress p l | progress p e progress p (tm () ≔ e) | inj₁ (tm unit) | (inj₁ (tm x₁)) progress p (tm () ≔ e) | inj₁ (tm con) | (inj₁ (tm x₁)) progress p (tm (loc x) ≔ e) | inj₁ (tm loc) | (inj₁ (tm v)) = inj₂ (, (, ≔-val (P.subst (_<_ _) (pointwise-length p) ([]=-length x)) v)) progress p (l ≔ e) | inj₂ (_ , _ , step) | _ = inj₂ (, (, ≔-clos₁ step)) progress p (l ≔ e) | inj₁ v | (inj₂ (_ , _ , step)) = inj₂ (, (, ≔-clos₂ v step)) progress-seq : ∀ {𝕊 Σ A} {e : SeqExp 0} {μ} → 𝕊 , Σ ⊢ μ → 𝕊 , Σ , [] ⊢ₛ e ∶ A → -------------------------------------- SeqExpVal e ⊎ ∃₂ λ e' μ' → (𝕊 ⊢ e , μ ≻ₛ e' , μ') progress-seq p (ret e) with progress p e ... | inj₁ (tm v) = inj₁ (ret-tm v) ... | inj₂ (e' , μ' , step) = inj₂ (, , ret-clos step) progress-seq p (lett x e) with progress p x progress-seq p (lett x e) | inj₁ (tm v) = inj₂ (, (, lett-β)) progress-seq p (lett x e) | inj₂ (x' , μ' , step) = inj₂ (, (, lett-clos step)) postulate lem₂ : ∀ {n 𝕊 Σ e a b t} {Γ : Ctx n} → 𝕊 , Σ , (a :+: Γ) ⊢ₑ e ∶ weaken₁-tp b → 𝕊 , Σ , Γ ⊢ t ∶ a → 𝕊 , Σ , Γ ⊢ₑ (e exp/ (sub t)) ∶ b lem₃ : ∀ {n 𝕊 Σ e a b t} {Γ : Ctx n} → 𝕊 , Σ , (a :+: Γ) ⊢ₛ e ∶ weaken₁-tp b → 𝕊 , Σ , Γ ⊢ t ∶ a → 𝕊 , Σ , Γ ⊢ₛ (e seq/ (sub t)) ∶ b lem₁ : ∀ {n 𝕊 Σ φ ts} {Γ : Ctx n} → 𝕊 ⊢ φ fnOk → (p : 𝕊 , Σ , Γ ⊢ ts ∶ⁿ weaken+-tele n (Fun.args φ)) → (q : length ts ≡ (Fun.m φ)) → 𝕊 , Σ , Γ ⊢ₑ (!call (Fun.body φ) ts q) ∶ ((Fun.returntype φ) fun[ ts / q ]) -- loading from a welltyped store results in a welltyped term !load-ok : ∀ {Σ Σ' A μ i 𝕊} → -- store-welltypedness type (strengthened for induction) Rel (λ A x → 𝕊 , Σ , [] ⊢ (proj₁ x) ∶ A) Σ' μ → Σ' L.[ i ]= A → (l : i < length μ) → 𝕊 , Σ , [] ⊢ (!load μ l) ∶ A !load-ok [] () !load-ok (x∼y ∷ p) here (s≤s z≤n) = x∼y !load-ok (x∼y ∷ p) (there q) (s≤s l) = !load-ok p q l mutual ⊒-preserves-tm : ∀ {n Γ Σ Σ' A 𝕊} {t : Term n} → Σ' ⊒ Σ → 𝕊 , Σ , Γ ⊢ t ∶ A → 𝕊 , Σ' , Γ ⊢ t ∶ A ⊒-preserves-tm ext unit = unit ⊒-preserves-tm ext (var x) = var x ⊒-preserves-tm ext (con x p q) = con x (⊒-preserves-tele ext p) q ⊒-preserves-tm ext (loc x) = loc (xs⊒ys[i] x ext) ⊒-preserves-tele : ∀ {n m Γ Σ Σ' 𝕊} {ts : List (Term n)} {T : Tele n m} → Σ' ⊒ Σ → 𝕊 , Σ , Γ ⊢ ts ∶ⁿ T → 𝕊 , Σ' , Γ ⊢ ts ∶ⁿ T ⊒-preserves-tele ext ε = ε ⊒-preserves-tele ext (x ⟶ p) = ⊒-preserves-tm ext x ⟶ (⊒-preserves-tele ext p) -- welltypedness is preseved under store extensions ⊒-preserves : ∀ {n Γ Σ Σ' A 𝕊} {e : Exp n} → Σ' ⊒ Σ → 𝕊 , Σ , Γ ⊢ₑ e ∶ A → 𝕊 , Σ' , Γ ⊢ₑ e ∶ A ⊒-preserves ext (tm x) = tm (⊒-preserves-tm ext x) ⊒-preserves ext (x ·★[ refl ] p) with ⊒-preserves-tele ext p ... | p' = x ·★[ refl ] p' ⊒-preserves ext (ref p) = ref (⊒-preserves ext p) ⊒-preserves ext (! p) = ! (⊒-preserves ext p) ⊒-preserves ext (p ≔ q) = ⊒-preserves ext p ≔ ⊒-preserves ext q ⊒-preserves-seq : ∀ {n Γ Σ Σ' A 𝕊} {e : SeqExp n} → Σ' ⊒ Σ → 𝕊 , Σ , Γ ⊢ₛ e ∶ A → 𝕊 , Σ' , Γ ⊢ₛ e ∶ A ⊒-preserves-seq ext (ret e) = ret (⊒-preserves ext e) ⊒-preserves-seq ext (lett e c) = lett (⊒-preserves ext e) (⊒-preserves-seq ext c) -- helper for lifting preserving reductions into their closure clos-cong : ∀ {Σ μ 𝕊 A B} {e : Exp 0} (c : Exp 0 → Exp 0) → (f : ∀ {Σ'} (ext : Σ' ⊒ Σ) → 𝕊 , Σ' , [] ⊢ₑ e ∶ A → 𝕊 , Σ' , [] ⊢ₑ c e ∶ B) → (∃ λ Σ' → 𝕊 , Σ' , [] ⊢ₑ e ∶ A × Σ' ⊒ Σ × 𝕊 , Σ' ⊢ μ) → ∃ λ Σ' → 𝕊 , Σ' , [] ⊢ₑ c e ∶ B × Σ' ⊒ Σ × 𝕊 , Σ' ⊢ μ clos-cong _ f (Σ , wte , ext , μ-wt) = Σ , f ext wte , ext , μ-wt ≻-preserves : ∀ {𝕊 Σ A} {e : Exp 0} {e' μ' μ} → 𝕊 , [] ⊢ok → 𝕊 , Σ , [] ⊢ₑ e ∶ A → 𝕊 , Σ ⊢ μ → 𝕊 ⊢ e , μ ≻ e' , μ' → ---------------------------------------------------- ∃ λ Σ' → 𝕊 , Σ' , [] ⊢ₑ e' ∶ A × Σ' ⊒ Σ × 𝕊 , Σ' ⊢ μ' -- variables ≻-preserves ok (tm x) q () -- function application ≻-preserves {Σ = Σ} ok (fn ·★[ refl ] ts) q (funapp-β x refl) with []=-functional _ _ fn x | all-lookup fn (_,_⊢ok.funs-ok ok) ... | refl | fn-ok = Σ , (lem₁ fn-ok ts refl) , ⊑-refl , q -- new references ≻-preserves {Σ = Σ} ok (ref {A = A} (tm x)) q (ref-val v) = let ext = (∷ʳ-⊒ A Σ) in Σ ∷ʳ A , (tm (loc (P.subst (λ i → _ L.[ i ]= _) (pointwise-length q) (∷ʳ[length] Σ A)))) , ext , pointwise-∷ʳ (PRel.map (⊒-preserves-tm ext) q) (⊒-preserves-tm ext x) ≻-preserves ok (ref p) q (ref-clos step) = clos-cong ref (const ref) (≻-preserves ok p q step) -- dereferencing ≻-preserves {Σ = Σ₁} ok (! tm (loc x)) q (!-val p) = Σ₁ , tm (!load-ok q x p) , ⊑-refl , q ≻-preserves ok (! p) q (!-clos step) = clos-cong !_ (const !_) (≻-preserves ok p q step) -- assignment ≻-preserves {Σ = Σ₁} ok (_≔_ (tm (loc x)) (tm y)) q (≔-val p v) = Σ₁ , tm unit , ⊑-refl , pointwise-[]≔ q x p y ≻-preserves ok (p ≔ p₁) q (≔-clos₁ step) = clos-cong (λ p' → p' ≔ _) (λ ext p' → p' ≔ ⊒-preserves ext p₁) (≻-preserves ok p q step) ≻-preserves ok (p ≔ p₁) q (≔-clos₂ v step) = clos-cong (λ p' → _ ≔ p') (λ ext p' → ⊒-preserves ext p ≔ p') (≻-preserves ok p₁ q step) -- let binding ≻ₛ-preserves : ∀ {𝕊 Σ A} {e : SeqExp 0} {e' μ' μ} → 𝕊 , [] ⊢ok → 𝕊 , Σ , [] ⊢ₛ e ∶ A → 𝕊 , Σ ⊢ μ → 𝕊 ⊢ e , μ ≻ₛ e' , μ' → ------------------------------------------------------- ∃ λ Σ' → 𝕊 , Σ' , [] ⊢ₛ e' ∶ A × Σ' ⊒ Σ × 𝕊 , Σ' ⊢ μ' ≻ₛ-preserves {Σ = Σ} ok (lett (tm x) p) q lett-β = Σ , lem₃ p x , ⊑-refl , q ≻ₛ-preserves ok (lett p p₁) q (lett-clos step) with ≻-preserves ok p q step ... | Σ₂ , wte' , Σ₂⊒Σ₁ , q' = Σ₂ , lett wte' ((⊒-preserves-seq Σ₂⊒Σ₁ p₁)) , Σ₂⊒Σ₁ , q' ≻ₛ-preserves ok (ret e) q (ret-clos step) with ≻-preserves ok e q step ... | Σ₂ , wte' , Σ₂⊒Σ₁ , q' = Σ₂ , ret wte' , Σ₂⊒Σ₁ , q' module SafeEval where open import Category.Monad.Partiality open import Category.Monad open import Coinduction open import Level as Lev open RawMonad {f = Lev.zero} monad -- typesafe evaluation in the partiality/delay-monad; -- or "soundness" modulo non-trivial divergence eval : ∀ {𝕊 Σ a μ} {e : SeqExp 0} → 𝕊 , [] ⊢ok → -- given an ok signature context, 𝕊 , Σ , [] ⊢ₛ e ∶ a → -- a welltyped closed expression, 𝕊 , Σ ⊢ μ → -- and a welltyped store --------------------------------------------------------------------------------------- -- eval will either diverge or provide evidence of a term v, store μ' and storetype Σ' (∃ λ v → ∃ λ μ' → ∃ λ Σ' → -- such that v is a value, (SeqExpVal v) × -- ...there is a sequence of small steps from e to v (𝕊 ⊢ e , μ ≻⋆ v , μ') × -- ...v has the same type as e (𝕊 , Σ' , [] ⊢ₛ v ∶ a) × -- ...μ' is typed by Σ' (𝕊 , Σ' ⊢ μ') × -- ...and finally, Σ' is an extension of Σ (Σ' ⊒ Σ)) ⊥ eval 𝕊-ok wte μ-ok with progress-seq μ-ok wte eval 𝕊-ok wte μ-ok | inj₁ v = now (_ , _ , _ , v , ε , wte , μ-ok , ⊑-refl) eval 𝕊-ok wte μ-ok | inj₂ (e' , μ' , step) with ≻ₛ-preserves 𝕊-ok wte μ-ok step ... | (Σ' , wte' , ext₁ , μ'-ok) with later (♯ (eval 𝕊-ok wte' μ'-ok)) ... | (now (v' , μ'' , Σ'' , val , steps , wte'' , μ''-ok , ext₂)) = now (v' , (μ'' , (Σ'' , val , ((steps ▻ step) , (wte'' , μ''-ok , ⊑-trans ext₁ ext₂))))) ... | (later x) = later (♯ (♭ x >>= λ{ (v' , μ'' , Σ'' , val , steps , wte'' , μ''-ok , ext₂) → now (v' , μ'' , Σ'' , val , steps ▻ step , wte'' , μ''-ok , ⊑-trans ext₁ ext₂) }))
{ "alphanum_fraction": 0.4791147132, "avg_line_length": 40.7796610169, "ext": "agda", "hexsha": "40514b81bea072bb8e4abf50f28aa30c0206edf8", "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/Impure/LFRef/Properties/Soundness.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/Impure/LFRef/Properties/Soundness.agda", "max_line_length": 101, "max_stars_count": null, "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_path": "src/Impure/LFRef/Properties/Soundness.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4199, "size": 9624 }
{-# OPTIONS --cubical --safe --postfix-projections #-} module HITs.PropositionalTruncation.Properties where open import HITs.PropositionalTruncation open import Prelude open import Data.Empty.Properties using (isProp⊥) refute-trunc : ¬ A → ¬ ∥ A ∥ refute-trunc = rec isProp⊥ recompute : Dec A → ∥ A ∥ → A recompute (yes p) _ = p recompute (no ¬p) p = ⊥-elim (rec isProp⊥ ¬p p) open import HITs.PropositionalTruncation.Sugar bij-iso : A ↔ B → ∥ A ∥ ⇔ ∥ B ∥ bij-iso A↔B .fun = _∥$∥_ (A↔B .fun) bij-iso A↔B .inv = _∥$∥_ (A↔B .inv) bij-iso A↔B .rightInv x = squash _ x bij-iso A↔B .leftInv x = squash _ x bij-eq : A ↔ B → ∥ A ∥ ≡ ∥ B ∥ bij-eq = isoToPath ∘ bij-iso
{ "alphanum_fraction": 0.646359584, "avg_line_length": 25.8846153846, "ext": "agda", "hexsha": "e8dc60d6314f007388b72a5f094dfb7b9bce32d1", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "HITs/PropositionalTruncation/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "HITs/PropositionalTruncation/Properties.agda", "max_line_length": 54, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "HITs/PropositionalTruncation/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 284, "size": 673 }
open import Relation.Binary using (Decidable; Setoid; DecSetoid) open import Level module CP.Session3 {a} {b} (ChanDecSetoid : DecSetoid zero a) (TypeDecSetoid : DecSetoid zero b) where module TS = DecSetoid TypeDecSetoid Type : Set Type = DecSetoid.Carrier TypeDecSetoid open DecSetoid ChanDecSetoid Chan : Set Chan = Carrier module _ where -- type of infix 6 _∶_ data TypeOf : Set a where _∶_ : (x : Chan) → (A : Type) → TypeOf chanOf : TypeOf → Chan chanOf (x ∶ _) = x import Relation.Binary.Construct.On as On decSetoid : DecSetoid _ _ decSetoid = On.decSetoid ChanDecSetoid chanOf open import Data.List.Relation.Binary.Subset.DecSetoid decSetoid open import Data.List Session : Set a Session = List TypeOf open import Relation.Nullary open import Relation.Nullary.Decidable open import Data.Product open import Data.Maybe seperate : (Γ : Session) → (x : Chan) → Maybe (∃[ Δ ] ∃[ A ] (Γ ≋ x ∶ A ∷ Δ)) seperate [] x = nothing seperate (y ∶ A ∷ Γ) x with y ≟ x ... | yes P = just (Γ , A , ∷-cong P ≋-refl) ... | no ¬P with seperate Γ x ... | just (Δ , B , eq) = just (y ∶ A ∷ Δ , B , reasoning) where open EqReasoning reasoning : y ∶ A ∷ Γ ≋ x ∶ B ∷ y ∶ A ∷ Δ reasoning = begin y ∶ A ∷ Γ ≈⟨ ∷-cong refl eq ⟩ y ∶ A ∷ x ∶ B ∷ Δ ≈⟨ ≋-swap ⟩ x ∶ B ∷ y ∶ A ∷ Δ ∎ ... | nothing = nothing -- insertion infixl 5 _#_ _#_ : Session → TypeOf → Session Γ # (x ∶ A) with seperate Γ x ... | nothing = x ∶ A ∷ Γ ... | just (Δ , _ , _) = x ∶ A ∷ Δ insert-idempotent : ∀ Γ x A → Γ # x ∶ A # x ∶ A ≋ Γ # x ∶ A insert-idempotent Γ x A with seperate Γ x insert-idempotent Γ x A | nothing with seperate (x ∶ A ∷ Γ) x ... | nothing = {! !} ... | just x₁ = {! !} insert-idempotent Γ x A | just x₁ = {! !}
{ "alphanum_fraction": 0.5936123348, "avg_line_length": 23.2820512821, "ext": "agda", "hexsha": "76d7fc9ff4e4a0c0d0bba0081fe246008f8a3a43", "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": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "banacorn/bidirectional", "max_forks_repo_path": "CP/Session3.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "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": "banacorn/bidirectional", "max_issues_repo_path": "CP/Session3.agda", "max_line_length": 103, "max_stars_count": 2, "max_stars_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "banacorn/bidirectional", "max_stars_repo_path": "CP/Session3.agda", "max_stars_repo_stars_event_max_datetime": "2020-08-25T14:05:01.000Z", "max_stars_repo_stars_event_min_datetime": "2020-08-25T07:34:40.000Z", "num_tokens": 668, "size": 1816 }
{-# OPTIONS --cubical --safe --postfix-projections #-} module Data.Binary.Isomorphism where open import Data.Binary.Definition open import Data.Binary.Conversion open import Data.Binary.Increment open import Prelude import Data.Nat as ℕ inc-suc : ∀ x → ⟦ inc x ⇓⟧ ≡ suc ⟦ x ⇓⟧ inc-suc 0ᵇ i = 1 inc-suc (1ᵇ x) i = 2 ℕ.+ ⟦ x ⇓⟧ ℕ.* 2 inc-suc (2ᵇ x) i = suc (inc-suc x i ℕ.* 2) inc-2*-1ᵇ : ∀ n → inc ⟦ n ℕ.* 2 ⇑⟧ ≡ 1ᵇ ⟦ n ⇑⟧ inc-2*-1ᵇ zero i = 1ᵇ 0ᵇ inc-2*-1ᵇ (suc n) i = inc (inc (inc-2*-1ᵇ n i)) 𝔹-rightInv : ∀ x → ⟦ ⟦ x ⇑⟧ ⇓⟧ ≡ x 𝔹-rightInv zero = refl 𝔹-rightInv (suc x) = inc-suc ⟦ x ⇑⟧ ; cong suc (𝔹-rightInv x) 𝔹-leftInv : ∀ x → ⟦ ⟦ x ⇓⟧ ⇑⟧ ≡ x 𝔹-leftInv 0ᵇ = refl 𝔹-leftInv (1ᵇ x) = inc-2*-1ᵇ ⟦ x ⇓⟧ ; cong 1ᵇ_ (𝔹-leftInv x) 𝔹-leftInv (2ᵇ x) = cong inc (inc-2*-1ᵇ ⟦ x ⇓⟧) ; cong 2ᵇ_ (𝔹-leftInv x) 𝔹⇔ℕ : 𝔹 ⇔ ℕ 𝔹⇔ℕ .fun = ⟦_⇓⟧ 𝔹⇔ℕ .inv = ⟦_⇑⟧ 𝔹⇔ℕ .rightInv = 𝔹-rightInv 𝔹⇔ℕ .leftInv = 𝔹-leftInv
{ "alphanum_fraction": 0.5685005394, "avg_line_length": 27.2647058824, "ext": "agda", "hexsha": "f5b3696f145cc2f107a7a9b206925aa37cc3ba8e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Data/Binary/Isomorphism.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Data/Binary/Isomorphism.agda", "max_line_length": 71, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Data/Binary/Isomorphism.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 538, "size": 927 }
module Numeral.Natural.Prime.Proofs where import Lvl open import Data open import Data.Boolean.Stmt open import Data.Either as Either using () open import Data.Tuple as Tuple using (_⨯_ ; _,_) open import Functional open import Lang.Instance open import Logic open import Logic.Propositional open import Logic.Propositional.Theorems open import Logic.Predicate open import Numeral.Natural open import Numeral.Natural.Relation.Divisibility open import Numeral.Natural.Relation.Divisibility.Proofs open import Numeral.Natural.Oper open import Numeral.Natural.Oper.Comparisons open import Numeral.Natural.Oper.Proofs open import Numeral.Natural.Prime open import Numeral.Natural.Relation.Order open import Numeral.Natural.Relation.Order.Proofs open import Relator.Equals open import Relator.Equals.Proofs open import Structure.Function.Domain open import Structure.Operator.Properties open import Structure.Relator.Properties open import Type [0]-nonprime : ¬ Prime(0) [0]-nonprime () [1]-nonprime : ¬ Prime(1) [1]-nonprime () [0]-noncomposite : ¬ Composite(0) [0]-noncomposite () [1]-noncomposite : ¬ Composite(1) [1]-noncomposite () [2]-prime : Prime(2) [2]-prime = intro p where p : PrimeProof p {0} _ = [∨]-introₗ [≡]-intro p {1} _ = [∨]-introᵣ [≡]-intro [3]-prime : Prime(3) [3]-prime = intro p where p : PrimeProof p {0} _ = [∨]-introₗ [≡]-intro p {1} (Div𝐒 ()) p {2} _ = [∨]-introᵣ [≡]-intro [4]-composite : Composite(4) [4]-composite = intro 0 0 [5]-prime : Prime(5) [5]-prime = intro p where p : PrimeProof p {0} _ = [∨]-introₗ [≡]-intro p {1} (Div𝐒 (Div𝐒 ())) p {2} (Div𝐒 ()) p {3} (Div𝐒 ()) p {4} _ = [∨]-introᵣ [≡]-intro [6]-composite : Composite(6) [6]-composite = Composite-intro 2 3 [7]-prime : Prime(7) [7]-prime = intro p where p : PrimeProof p {0} _ = [∨]-introₗ [≡]-intro p {1} (Div𝐒 (Div𝐒 (Div𝐒 ()))) p {2} (Div𝐒 (Div𝐒 ())) p {3} (Div𝐒 ()) p {4} (Div𝐒 ()) p {5} (Div𝐒 ()) p {6} d = [∨]-introᵣ [≡]-intro [8]-composite : Composite(8) [8]-composite = Composite-intro 2 4 [9]-composite : Composite(9) [9]-composite = Composite-intro 3 3 [10]-composite : Composite(10) [10]-composite = Composite-intro 2 5 [11]-prime : Prime(11) [11]-prime = intro p where p : PrimeProof p {0} _ = [∨]-introₗ [≡]-intro p {1} (Div𝐒 (Div𝐒 (Div𝐒 (Div𝐒 (Div𝐒 ()))))) p {2} (Div𝐒 (Div𝐒 (Div𝐒 ()))) p {3} (Div𝐒 (Div𝐒 ())) p {4} (Div𝐒 (Div𝐒 ())) p {5} (Div𝐒 ()) p {6} (Div𝐒 ()) p {7} (Div𝐒 ()) p {8} (Div𝐒 ()) p {9} (Div𝐒 ()) p {10} d = [∨]-introᵣ [≡]-intro prime-only-divisors : ∀{n} → Prime(n) → (∀{x} → (x ∣ n) → ((x ≡ 1) ∨ (x ≡ n))) prime-only-divisors {𝐒 (𝐒 n)} (intro prime) {𝟎} = [⊥]-elim ∘ [0]-divides-not prime-only-divisors {𝐒 (𝐒 n)} (intro prime) {𝐒 x} = Either.map ([≡]-with(𝐒)) ([≡]-with(𝐒)) ∘ prime prime-when-only-divisors : ∀{n} → (n ≥ 2) → (∀{x} → (x ∣ n) → ((x ≡ 1) ∨ (x ≡ n))) → Prime(n) prime-when-only-divisors {𝐒(𝐒 n)} (succ _) proof = intro p where p : PrimeProof p {𝟎} _ = [∨]-introₗ [≡]-intro p {𝐒 x} = Either.map (injective(𝐒)) (injective(𝐒)) ∘ proof prime-prime-divisor : ∀{a b} → Prime(a) → Prime(b) → (a ∣ b) → (a ≡ b) prime-prime-divisor pa pb div with prime-only-divisors pb div ... | [∨]-introₗ [≡]-intro with () ← [1]-nonprime pa ... | [∨]-introᵣ ab = ab module _ where open import Sets.PredicateSet renaming (_≡_ to _≡ₛ_) private variable a b n p : ℕ -- All prime numbers are prime factors of 0. [0]-primeFactors : PrimeFactor(0) ⊇ Prime [0]-primeFactors prime = intro where instance _ = prime instance _ = Div𝟎 -- There are no prime factors of 1. [1]-primeFactors : PrimeFactor(1) ⊆ ∅ {Lvl.𝟎} [1]-primeFactors {𝐒 𝟎} (intro ⦃ () ⦄) [1]-primeFactors {𝐒 (𝐒 x)} (intro ⦃ factor = factor ⦄) with succ() ← divides-upper-limit factor -- The only prime factors of a prime number is itself. prime-primeFactors : ⦃ _ : Prime(p) ⦄ → (PrimeFactor(p) ≡ₛ (• p)) prime-primeFactors {p}{x} = [↔]-intro (\{[≡]-intro → intro}) (\{intro → symmetry(_≡_) (prime-prime-divisor infer infer infer)}) -- When a number is a prime factor of itself, it is a prime number. -- A very obvious fact (it follows by definition). reflexive-primeFactor-is-prime : (n ∈ PrimeFactor(n)) → Prime(n) reflexive-primeFactor-is-prime intro = infer divisor-primeFactors : ∀{a b} → (a ∣ b) → (PrimeFactor(a) ⊆ PrimeFactor(b)) divisor-primeFactors div (intro ⦃ p ⦄ ⦃ xa ⦄) = intro ⦃ p ⦄ ⦃ transitivity(_∣_) xa div ⦄ composite-existence : ∀{n} → Composite(n) ↔ ∃{Obj = ℕ ⨯ ℕ}(\(a , b) → (a + 2) ⋅ (b + 2) ≡ n) composite-existence = [↔]-intro (\{([∃]-intro (a , b) ⦃ [≡]-intro ⦄) → intro a b}) \{(intro a b) → [∃]-intro (a , b) ⦃ [≡]-intro ⦄}
{ "alphanum_fraction": 0.621731676, "avg_line_length": 31.1066666667, "ext": "agda", "hexsha": "81155ff7df6368a9586e73e2cf3cbe4bba680820", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Numeral/Natural/Prime/Proofs.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Numeral/Natural/Prime/Proofs.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": "Numeral/Natural/Prime/Proofs.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": 1874, "size": 4666 }
{-# OPTIONS --rewriting #-} --{-# OPTIONS -v rewriting:100 #-} postulate _↦_ : ∀ {i} {A : Set i} → A → A → Set i {-# BUILTIN REWRITE _↦_ #-} data _==_ {i} {A : Set i} (a : A) : A → Set i where idp : a == a ap : ∀ i j (A : Set i) (B : Set j) (f : A → B) (x y : A) → (x == y → f x == f y) ap _ _ _ _ f _ ._ idp = idp postulate ap∘-rewr : ∀ {i j k} {A : Set i} {B : Set j} {C : Set k} (g : B → C) (f : A → B) {x y : A} (p : x == y) → ap j k B C g (f x) (f y) (ap i j A B f x y p) ↦ ap i k A C (λ x → g (f x)) x y p {-# REWRITE ap∘-rewr #-} -- This one works, rewriting the RHS to the LHS using the previous rewrite rule as expected {-ap∘ : ∀ {i j k} {A : Set i} {B : Set j} {C : Set k} (g : B → C) (f : A → B) {x y : A} (p : x == y) → ap (λ x → g (f x)) p == ap g (ap f p) ap∘ g f p = idp -} postulate P : ∀ i (A : Set i) (x y : A) (p : x == y) → Set -- This one doesn’t work, although it should just have to rewrite [P (ap g (ap f p))] to [P (ap (λ x → g (f x)) p)] test : ∀ {i j k} {A : Set i} {B : Set j} {C : Set k} (g : B → C) (f : A → B) {x y : A} (p : x == y) → P k C (g (f x)) (g (f y)) (ap i k A C (λ x → g (f x)) x y p) → P k C (g (f x)) (g (f y)) (ap j k B C g (f x) (f y) (ap i j A B f x y p)) test g f p s = s {- .i != .j of type .Agda.Primitive.Level when checking that the expression s has type P (ap g (ap f p)) -}
{ "alphanum_fraction": 0.4599559148, "avg_line_length": 33.1951219512, "ext": "agda", "hexsha": "55c1da3ba582f0c70b8f016bbe5625958a5a9ad6", "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/Issue1553.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/Issue1553.agda", "max_line_length": 140, "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/Issue1553.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": 616, "size": 1361 }
------------------------------------------------------------------------------ -- Testing the translation of definitions ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module Definition01a where postulate D : Set _≡_ : D → D → Set d : D -- We test the translation of the definition of a nullary function. e : D e = d {-# ATP definition e #-} postulate foo : e ≡ d {-# ATP prove foo #-}
{ "alphanum_fraction": 0.4231404959, "avg_line_length": 25.2083333333, "ext": "agda", "hexsha": "9dc0a98a56f8d936f6ff2285356a67f3401de98b", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z", "max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/apia", "max_forks_repo_path": "test/Succeed/fol-theorems/Definition01a.agda", "max_issues_count": 121, "max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/apia", "max_issues_repo_path": "test/Succeed/fol-theorems/Definition01a.agda", "max_line_length": 78, "max_stars_count": 10, "max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/apia", "max_stars_repo_path": "test/Succeed/fol-theorems/Definition01a.agda", "max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z", "num_tokens": 117, "size": 605 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.DStructures.Structures.Action where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Structure open import Cubical.Functions.FunExtEquiv open import Cubical.Data.Sigma open import Cubical.Algebra.Group open import Cubical.Structures.LeftAction open import Cubical.DStructures.Base open import Cubical.DStructures.Meta.Properties open import Cubical.DStructures.Structures.Constant open import Cubical.DStructures.Structures.Type open import Cubical.DStructures.Structures.Group private module _ {ℓ ℓ' : Level} where Las : ((G , H) : Group {ℓ} × Group {ℓ'}) → Type (ℓ-max ℓ ℓ') Las (G , H) = LeftActionStructure ⟨ G ⟩ ⟨ H ⟩ module _ (ℓ ℓ' : Level) where G²Las = Σ[ GH ∈ G² ℓ ℓ' ] Las GH GGLas = Σ[ G ∈ Group {ℓ} ] Σ[ H ∈ Group {ℓ'} ] Las (G , H) Action = Σ[ ((G , H) , _α_) ∈ G²Las ] (IsGroupAction G H _α_) G²LasAct = Σ[ (G , H) ∈ G² ℓ ℓ' ] Σ[ α ∈ Las (G , H) ] IsGroupAction G H α GGLasAct = Σ[ G ∈ Group {ℓ} ] Σ[ H ∈ Group {ℓ'} ] Σ[ α ∈ Las (G , H) ] IsGroupAction G H α IsoAction : Iso Action GGLasAct IsoAction = compIso Σ-assoc-Iso Σ-assoc-Iso -- two groups with an action structure, i.e. a map ⟨ G ⟩ → ⟨ H ⟩ → ⟨ H ⟩ 𝒮ᴰ-G²\Las : URGStrᴰ (𝒮-group ℓ ×𝒮 𝒮-group ℓ') (λ GH → Las GH) (ℓ-max ℓ ℓ') 𝒮ᴰ-G²\Las = make-𝒮ᴰ (λ {(G , H)} _α_ (eG , eH) _β_ → (g : ⟨ G ⟩) (h : ⟨ H ⟩) → GroupEquiv.eq eH .fst (g α h) ≡ (GroupEquiv.eq eG .fst g) β (GroupEquiv.eq eH .fst h)) (λ _ _ _ → refl) λ (G , H) _α_ → isContrRespectEquiv -- (Σ[ _β_ ∈ Las (G , H) ] (_α_ ≡ _β_) (Σ-cong-equiv-snd (λ _β_ → invEquiv funExt₂Equiv)) (isContrSingl _α_) 𝒮-G²Las : URGStr G²Las (ℓ-max ℓ ℓ') 𝒮-G²Las = ∫⟨ 𝒮-group ℓ ×𝒮 𝒮-group ℓ' ⟩ 𝒮ᴰ-G²\Las open ActionΣTheory 𝒮ᴰ-G²Las\Action : URGStrᴰ 𝒮-G²Las (λ ((G , H) , _α_) → IsGroupAction G H _α_) ℓ-zero 𝒮ᴰ-G²Las\Action = Subtype→Sub-𝒮ᴰ (λ ((G , H) , _α_) → IsGroupAction G H _α_ , isPropIsGroupAction G H _α_) 𝒮-G²Las 𝒮-G²LasAction : URGStr Action (ℓ-max ℓ ℓ') 𝒮-G²LasAction = ∫⟨ 𝒮-G²Las ⟩ 𝒮ᴰ-G²Las\Action 𝒮-Action = 𝒮-G²LasAction 𝒮ᴰ-G\GLasAction : URGStrᴰ (𝒮-group ℓ) (λ G → Σ[ H ∈ Group {ℓ'} ] Σ[ α ∈ Las (G , H) ] IsGroupAction G H α) (ℓ-max ℓ ℓ') 𝒮ᴰ-G\GLasAction = splitTotal-𝒮ᴰ (𝒮-group ℓ) (𝒮ᴰ-const (𝒮-group ℓ) (𝒮-group ℓ')) (splitTotal-𝒮ᴰ (𝒮-group ℓ ×𝒮 𝒮-group ℓ') 𝒮ᴰ-G²\Las 𝒮ᴰ-G²Las\Action)
{ "alphanum_fraction": 0.5414309484, "avg_line_length": 38.5256410256, "ext": "agda", "hexsha": "a74b95bf19e08cbca64e6a5aa95c5ebc2503e3db", "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/DStructures/Structures/Action.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/DStructures/Structures/Action.agda", "max_line_length": 109, "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/DStructures/Structures/Action.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1151, "size": 3005 }
{-# OPTIONS --without-K --safe #-} open import Level -- This is really a degenerate version of Categories.Category.Instance.Zero -- Here EmptySet is not given an explicit name, it is an alias for Lift o ⊥ module Categories.Category.Instance.EmptySet where open import Data.Empty using (⊥; ⊥-elim) open import Relation.Binary.PropositionalEquality using (refl) open import Categories.Category.Instance.Sets import Categories.Object.Initial as Init module _ {o : Level} where open Init (Sets o) EmptySet-⊥ : Initial EmptySet-⊥ = record { ⊥ = Lift o ⊥ ; ! = λ { {A} (lift x) → ⊥-elim x } ; !-unique = λ { f {()} } }
{ "alphanum_fraction": 0.7008, "avg_line_length": 31.25, "ext": "agda", "hexsha": "90ffd17707a19b1d5837437c6b767124bb9d04c4", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "MirceaS/agda-categories", "max_forks_repo_path": "src/Categories/Category/Instance/EmptySet.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "MirceaS/agda-categories", "max_issues_repo_path": "src/Categories/Category/Instance/EmptySet.agda", "max_line_length": 100, "max_stars_count": null, "max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "MirceaS/agda-categories", "max_stars_repo_path": "src/Categories/Category/Instance/EmptySet.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 172, "size": 625 }
-- Andreas, 2016-02-11. Irrelevant constructors are not (yet?) supported data D : Set where .c : D -- Should fail, e.g., with parse error.
{ "alphanum_fraction": 0.6713286713, "avg_line_length": 20.4285714286, "ext": "agda", "hexsha": "aad9adf88142dbcb248fe0233f0a6d5a2c56152a", "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/IrrelevantConstructor.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/IrrelevantConstructor.agda", "max_line_length": 72, "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/IrrelevantConstructor.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": 44, "size": 143 }
------------------------------------------------------------------------ -- Pretty-printing (documents and document combinators) ------------------------------------------------------------------------ {-# OPTIONS --guardedness #-} module Pretty where open import Data.Bool open import Data.Char open import Data.List hiding ([_]) open import Data.List.NonEmpty using (List⁺; _∷_; _∷⁺_) open import Data.List.Properties open import Data.Maybe hiding (_>>=_) open import Data.Nat open import Data.Product open import Data.Unit open import Function open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Tactic.MonoidSolver open import Grammar.Infinite as G hiding (_<$>_; _<$_; _⊛_; _<⊛_; _⊛>_; token; tok; if-true; sat; tok-sat; symbol; list; list⁺) ------------------------------------------------------------------------ -- Pretty-printers mutual -- Pretty-printer documents, indexed by grammars and corresponding -- values. -- -- For convenience I have chosen to parametrise Doc by "extended" -- grammars rather than basic ones. infixr 20 _◇_ data Doc : ∀ {A} → Grammar A → A → Set₁ where -- Concatenation. _◇_ : ∀ {c₁ c₂ A B x y} {g₁ : ∞Grammar c₁ A} {g₂ : A → ∞Grammar c₂ B} → Doc (♭? g₁) x → Doc (♭? (g₂ x)) y → Doc (g₁ >>= g₂) y -- A string. Note that I do /not/ enforce Wadler's convention -- that the string does not contain newline characters. text : ∀ {s} → Doc (string s) s -- One or more whitespace characters. line : Doc (tt G.<$ whitespace +) tt -- Grouping construct. group : ∀ {A x} {g : Grammar A} → Doc g x → Doc g x -- Increases the nesting level. (Whatever this means. Renderers -- are free to ignore group and nest, see ugly-renderer below.) nest : ∀ {A x} {g : Grammar A} → ℕ → Doc g x → Doc g x -- Embedding operator: Documents for one grammar/result also -- work for other grammars/results, given that the semantics -- are, in a certain sense, compatible. emb : ∀ {A B x y} {g₁ : Grammar A} {g₂ : Grammar B} → (∀ {s} → x ∈ g₁ · s → y ∈ g₂ · s) → Doc g₁ x → Doc g₂ y -- Fill operator. fill : ∀ {A xs} {g : Grammar A} → Docs g xs → Doc (g sep-by whitespace +) xs -- Sequences of documents, all based on the same grammar. infixr 5 _∷_ data Docs {A} (g : Grammar A) : List⁺ A → Set₁ where [_] : ∀ {x} → Doc g x → Docs g (x ∷ []) _∷_ : ∀ {x xs} → Doc g x → Docs g xs → Docs g (x ∷⁺ xs) -- Pretty-printers. A pretty-printer is a function that for every -- value constructs a matching document. Pretty-printer : {A : Set} → Grammar A → Set₁ Pretty-printer g = ∀ x → Doc g x Pretty-printer-for : {A : Set} → Grammar-for A → Set₁ Pretty-printer-for g = ∀ x → Doc (g x) (x , refl) ------------------------------------------------------------------------ -- Derived document combinators -- A "smart" variant of emb. Can be used to avoid long chains of emb -- constructors. embed : ∀ {A B} {g₁ : Grammar A} {g₂ : Grammar B} {x y} → (∀ {s} → x ∈ g₁ · s → y ∈ g₂ · s) → Doc g₁ x → Doc g₂ y embed f (emb g d) = emb (f ∘ g) d embed f d = emb f d -- A document for the empty string. nil : ∀ {A} {x : A} → Doc (return x) x nil = embed lemma text where lemma : ∀ {x s} → [] ∈ string [] · s → x ∈ return x · s lemma return-sem = return-sem -- A document for the given character. token : ∀ {t} → Doc G.token t token {t} = embed lemma text where lemma′ : ∀ {x s} → x ∈ string (t ∷ []) · s → x ≡ t ∷ [] → t ∈ G.token · s lemma′ (⊛-sem (<$>-sem tok-sem) return-sem) refl = token-sem lemma : ∀ {s} → t ∷ [] ∈ string (t ∷ []) · s → t ∈ G.token · s lemma t∈ = lemma′ t∈ refl -- A document for the given character. tok : ∀ {t} → Doc (G.tok t) t tok {t} = embed lemma token where lemma : ∀ {s} → t ∈ G.token · s → t ∈ G.tok t · s lemma token-sem = tok-sem -- Some mapping combinators. infix 21 <$>_ <$_ <$>_ : ∀ {c A B} {f : A → B} {x} {g : ∞Grammar c A} → Doc (♭? g) x → Doc (f G.<$> g) (f x) <$> d = embed <$>-sem d <$_ : ∀ {c A B} {x : A} {y} {g : ∞Grammar c B} → Doc (♭? g) y → Doc (x G.<$ g) x <$ d = embed <$-sem d -- Some sequencing combinators. infixl 20 _⊛_ _<⊛_ _⊛>_ _<⊛-tt_ _tt-⊛>_ _⊛_ : ∀ {c₁ c₂ A B f x} {g₁ : ∞Grammar c₁ (A → B)} {g₂ : ∞Grammar c₂ A} → Doc (♭? g₁) f → Doc (♭? g₂) x → Doc (g₁ G.⊛ g₂) (f x) _⊛_ {g₁ = g₁} {g₂} d₁ d₂ = embed lemma (d₁ ◇ <$> d₂) where lemma : ∀ {x s} → x ∈ (g₁ >>= λ f → f G.<$> g₂) · s → x ∈ g₁ G.⊛ g₂ · s lemma (>>=-sem f∈ (<$>-sem x∈)) = ⊛-sem f∈ x∈ _<⊛_ : ∀ {c₁ c₂ A B x y} {g₁ : ∞Grammar c₁ A} {g₂ : ∞Grammar c₂ B} → Doc (♭? g₁) x → Doc (♭? g₂) y → Doc (g₁ G.<⊛ g₂) x _<⊛_ {g₁ = g₁} {g₂} d₁ d₂ = embed lemma (d₁ ◇ <$ d₂) where lemma : ∀ {x s} → x ∈ (g₁ >>= λ x → x G.<$ g₂) · s → x ∈ g₁ G.<⊛ g₂ · s lemma (>>=-sem x∈ (<$-sem y∈)) = <⊛-sem x∈ y∈ _⊛>_ : ∀ {c₁ c₂ A B x y} {g₁ : ∞Grammar c₁ A} {g₂ : ∞Grammar c₂ B} → Doc (♭? g₁) x → Doc (♭? g₂) y → Doc (g₁ G.⊛> g₂) y _⊛>_ {g₁ = g₁} {g₂} d₁ d₂ = embed lemma (d₁ ◇ d₂) where lemma : ∀ {y s} → y ∈ (g₁ >>= λ _ → g₂) · s → y ∈ g₁ G.⊛> g₂ · s lemma (>>=-sem x∈ y∈) = ⊛>-sem x∈ y∈ _<⊛-tt_ : ∀ {c₁ c₂ A B x} {g₁ : ∞Grammar c₁ A} {g₂ : ∞Grammar c₂ B} → Doc (♭? g₁) x → Doc (tt G.<$ g₂) tt → Doc (g₁ G.<⊛ g₂) x _<⊛-tt_ {g₁ = g₁} {g₂} d₁ d₂ = embed lemma (d₁ <⊛ d₂) where lemma : ∀ {x s} → x ∈ g₁ G.<⊛ (tt G.<$ g₂) · s → x ∈ g₁ G.<⊛ g₂ · s lemma (<⊛-sem x∈ (<$-sem y∈)) = <⊛-sem x∈ y∈ _tt-⊛>_ : ∀ {c₁ c₂ A B x} {g₁ : ∞Grammar c₁ A} {g₂ : ∞Grammar c₂ B} → Doc (tt G.<$ g₁) tt → Doc (♭? g₂) x → Doc (g₁ G.⊛> g₂) x _tt-⊛>_ {g₁ = g₁} {g₂} d₁ d₂ = embed lemma (d₁ ⊛> d₂) where lemma : ∀ {x s} → x ∈ (tt G.<$ g₁) G.⊛> g₂ · s → x ∈ g₁ G.⊛> g₂ · s lemma (⊛>-sem (<$-sem x∈) y∈) = ⊛>-sem x∈ y∈ -- Document combinators for choices. left : ∀ {c₁ c₂ A x} {g₁ : ∞Grammar c₁ A} {g₂ : ∞Grammar c₂ A} → Doc (♭? g₁) x → Doc (g₁ ∣ g₂) x left d = embed left-sem d right : ∀ {c₁ c₂ A x} {g₁ : ∞Grammar c₁ A} {g₂ : ∞Grammar c₂ A} → Doc (♭? g₂) x → Doc (g₁ ∣ g₂) x right d = embed right-sem d -- Some Kleene star and plus combinators. nil-⋆ : ∀ {c A} {g : ∞Grammar c A} → Doc (g ⋆) [] nil-⋆ {A = A} {g} = embed lemma nil where lemma : ∀ {s} → [] ∈ return {A = List A} [] · s → [] ∈ g ⋆ · s lemma return-sem = ⋆-[]-sem cons-⋆+ : ∀ {c A} {g : ∞Grammar c A} {x xs} → Doc (♭? g) x → Doc (g ⋆) xs → Doc (g +) (x ∷ xs) cons-⋆+ d₁ d₂ = <$> d₁ ⊛ d₂ cons-⋆ : ∀ {c A} {g : ∞Grammar c A} {x xs} → Doc (♭? g) x → Doc (g ⋆) xs → Doc (g ⋆) (x ∷ xs) cons-⋆ d₁ d₂ = embed ⋆-+-sem (cons-⋆+ d₁ d₂) -- A document for the empty string. if-true : ∀ b → Pretty-printer (G.if-true b) if-true true _ = nil if-true false () -- Documents for the given character. sat : (p : Char → Bool) → Pretty-printer (G.sat p) sat p (t , proof) = token ◇ <$> if-true (p t) proof tok-sat : {p : Char → Bool} → Pretty-printer-for (G.tok-sat p) tok-sat _ = <$ tok -- A single space character. space : Doc (whitespace ⋆) (' ' ∷ []) space = embed lemma tok where lemma : ∀ {s} → ' ' ∈ G.tok ' ' · s → (' ' ∷ []) ∈ whitespace ⋆ · s lemma tok-sem = ⋆-+-sem single-space-sem -- A variant of line (with _⋆ instead of _+ in the grammar). line⋆ : Doc (tt G.<$ whitespace ⋆) tt line⋆ = embed lemma line where lemma : ∀ {s} → tt ∈ tt G.<$ whitespace + · s → tt ∈ tt G.<$ whitespace ⋆ · s lemma (<$-sem w+) = <$-sem (⋆-+-sem w+) -- Combinators that add a final "line" to the document, nested i -- steps. (The grammars have to satisfy certain predicates.) final-line′ : ∀ {A} {g : Grammar A} {x} → Trailing-whitespace g → Doc g x → (i : ℕ) → Doc g x final-line′ trailing d i = embed trailing (d <⊛-tt nest i line⋆) final-line : ∀ {A} {g : Grammar A} {x} (n : ℕ) {trailing : T (is-just (trailing-whitespace n g))} → Doc g x → (i : ℕ) → Doc g x final-line n {trailing} = final-line′ (to-witness-T (trailing-whitespace n _) trailing) -- Trailing-whitespace never holds for grammars of the form g ⋆, but -- if the list to be pretty-printed has at least one element, then -- final-line may still work. final-line-+⋆ : ∀ {c A} {g : ∞Grammar c A} {x xs} (n : ℕ) {trailing : T (is-just (trailing-whitespace n (g +)))} → Doc (g +) (x ∷ xs) → (i : ℕ) → Doc (g ⋆) (x ∷ xs) final-line-+⋆ n {trailing} d i = embed ⋆-+-sem (final-line n {trailing} d i) -- A document for the given symbol (and no following whitespace). symbol : ∀ {s} → Doc (G.symbol s) s symbol = text <⊛ nil-⋆ -- A document for the given symbol plus a "line". symbol-line : ∀ {s} → Doc (G.symbol s) s symbol-line = final-line 1 symbol 0 -- A document for the given symbol plus a space character. symbol-space : ∀ {s} → Doc (G.symbol s) s symbol-space = text <⊛ space -- A combinator for bracketed output, based on one in Wadler's "A -- prettier printer". bracket : ∀ {c A x s₁ s₂} {g : ∞Grammar c A} (n : ℕ) → {trailing : T (is-just (trailing-whitespace n (♭? g)))} → Doc (♭? g) x → Doc (G.symbol s₁ G.⊛> g G.<⊛ G.symbol s₂) x bracket n {trailing} d = group (nest 2 symbol-line ⊛> final-line n {trailing = trailing} (nest 2 d) 0 <⊛ symbol) mutual -- Conversion of pretty-printers for elements into pretty-printers -- for lists. map⋆ : ∀ {c A} {g : ∞Grammar c A} → Pretty-printer (♭? g) → Pretty-printer (g ⋆) map⋆ p [] = nil-⋆ map⋆ p (x ∷ xs) = embed ⋆-+-sem (map+ p (x ∷ xs)) map+ : ∀ {c A} {g : ∞Grammar c A} → Pretty-printer (♭? g) → Pretty-printer (g +) map+ p (x ∷ xs) = cons-⋆+ (p x) (map⋆ p xs) mutual -- Conversion of pretty-printers for specific elements into -- pretty-printers for specific lists. list : ∀ {A} {elem : Grammar-for A} → Pretty-printer-for elem → Pretty-printer-for (G.list elem) list e [] = nil list e (x ∷ xs) = <$> (list⁺ e (x ∷ xs)) list⁺ : ∀ {A} {elem : Grammar-for A} → Pretty-printer-for elem → Pretty-printer-for (G.list⁺ elem) list⁺ e (x ∷ xs) = <$> (e x) ⊛ list e xs -- A variant of fill. (The grammar has to satisfy a certain -- predicate.) fill+ : ∀ {c A} {g : ∞Grammar c A} (n : ℕ) {trailing : T (is-just (trailing-whitespace n (♭? g)))} → ∀ {xs} → Docs (♭? g) xs → Doc (g +) xs fill+ {g = g} n {trailing} ds = embed lemma (fill ds) where trailing! = to-witness-T (trailing-whitespace n (♭? g)) trailing lemma′ : ∀ {x xs s₁ s₂} → x ∈ ♭? g · s₁ → xs ∈ ♭? g prec-by whitespace + · s₂ → x ∷ xs ∈ g + · s₁ ++ s₂ lemma′ x∈ ⋆-[]-sem = +-sem x∈ ⋆-[]-sem lemma′ {s₁ = s₁} x∈ (⋆-+-sem (⊛-sem (<$>-sem (⊛>-sem w+ x′∈)) xs∈)) = cast lemma″ (+-∷-sem (trailing! (<⊛-sem x∈ (⋆-+-sem w+))) (lemma′ x′∈ xs∈)) where lemma″ : ∀ {s₂ s₃ s₄} → (s₁ ++ s₂) ++ s₃ ++ s₄ ≡ s₁ ++ (s₂ ++ s₃) ++ s₄ lemma″ = solve (++-monoid Char) lemma : ∀ {s xs} → xs ∈ ♭? g sep-by whitespace + · s → xs ∈ g + · s lemma (⊛-sem (<$>-sem x∈) xs∈) = lemma′ x∈ xs∈ -- Variants of map+/map⋆ that use fill. (The grammars have to satisfy -- a certain predicate.) map+-fill : ∀ {c A} {g : ∞Grammar c A} (n : ℕ) {trailing : T (is-just (trailing-whitespace n (♭? g)))} → Pretty-printer (♭? g) → Pretty-printer (g +) map+-fill {g = g} n {trailing} p (x ∷ xs) = fill+ n {trailing = trailing} (to-docs x xs) where to-docs : ∀ x xs → Docs (♭? g) (x ∷ xs) to-docs x [] = [ p x ] to-docs x (x′ ∷ xs) = p x ∷ to-docs x′ xs map⋆-fill : ∀ {c A} {g : ∞Grammar c A} (n : ℕ) {trailing : T (is-just (trailing-whitespace n (♭? g)))} → Pretty-printer (♭? g) → Pretty-printer (g ⋆) map⋆-fill n p [] = nil-⋆ map⋆-fill n {trailing} p (x ∷ xs) = embed ⋆-+-sem (map+-fill n {trailing = trailing} p (x ∷ xs))
{ "alphanum_fraction": 0.5138346489, "avg_line_length": 32.0079787234, "ext": "agda", "hexsha": "d6a6ba4afddf55700a4e3e40b6cbde28bced1037", "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": "b956803ba90b6c5f57bbbaab01bb18485d948492", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/pretty", "max_forks_repo_path": "Pretty.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/pretty", "max_issues_repo_path": "Pretty.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/pretty", "max_stars_repo_path": "Pretty.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4744, "size": 12035 }
{-# OPTIONS --without-K --safe #-} module Categories.Category.Concrete.Properties where open import Data.Unit.Polymorphic open import Function.Equality using (Π; _⟨$⟩_; const; _∘_) open import Level open import Relation.Binary using (Setoid) import Relation.Binary.Reasoning.Setoid as SR open import Categories.Adjoint using (_⊣_; Adjoint) open import Categories.Category.Core using (Category) open import Categories.Category.Instance.Setoids using (Setoids) open import Categories.Category.Concrete open import Categories.Functor.Core using (Functor) open import Categories.Functor.Representable using (Representable) open import Categories.Functor.Properties using (Faithful) import Categories.Morphism.Reasoning as MR open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper) open Concrete ⊣⇒Representable : {o ℓ e : Level} (C : Category o ℓ e) (conc : Concrete C ℓ e) → (F : Functor (Setoids ℓ e) C) → F ⊣ concretize conc → RepresentablyConcrete C ⊣⇒Representable {_} {ℓ} {e} C conc F L = record { conc = conc ; representable = record { A = F.₀ OneS ; Iso = record { F⇒G = ntHelper record { η = λ X → record { _⟨$⟩_ = λ x → L.counit.η X C.∘ F.₁ (const x) ; cong = λ i≈j → C.∘-resp-≈ʳ (F.F-resp-≈ λ _ → i≈j) } ; commute = λ {X} {Y} f {x} {y} x≈y → let open C.HomReasoning in begin L.counit.η Y C.∘ F.₁ (const (U.₁ f ⟨$⟩ x)) ≈⟨ refl⟩∘⟨ F.F-resp-≈ (λ _ → Π.cong (U.₁ f) x≈y) ⟩ L.counit.η Y C.∘ F.₁ (U.F₁ f ∘ const y) ≈⟨ pushʳ F.homomorphism ⟩ ((L.counit.η Y C.∘ F.₁ (U.₁ f)) C.∘ F.₁ (const y)) ≈⟨ pushˡ (commute L.counit f) ⟩ f C.∘ L.counit.η X C.∘ F.₁ (const y) ≈˘⟨ C.identityʳ ⟩ (f C.∘ L.counit.η X C.∘ F.₁ (const y)) C.∘ C.id ∎ } ; F⇐G = ntHelper record { η = λ c → record { _⟨$⟩_ = λ 1⇒c → U.₁ 1⇒c ⟨$⟩ η1 ; cong = λ i≈j → U.F-resp-≈ i≈j (Setoid.refl (U.₀ (F.₀ OneS))) } ; commute = λ {X} {Y} f {x} {y} x≈y → let module CH = C.HomReasoning in let open SR (U.₀ Y) in begin U.₁ ((f C.∘ x) C.∘ C.id) ⟨$⟩ η1 ≈⟨ U.F-resp-≈ (C.identityʳ CH.○ (CH.refl⟩∘⟨ x≈y)) Srefl ⟩ U.₁ (f C.∘ y) ⟨$⟩ η1 ≈⟨ U.homomorphism Srefl ⟩ U.₁ f ⟨$⟩ (U.₁ y ⟨$⟩ η1) ∎ } ; iso = λ X → record { isoˡ = λ {x} {y} x≈y → Setoid.trans (U.₀ X) (L.LRadjunct≈id {OneS} {X} {const x} tt) x≈y ; isoʳ = λ {1⇒x} {1⇒y} x≈y → let open C.HomReasoning in begin L.counit.η X C.∘ F.₁ (const (U.₁ 1⇒x ⟨$⟩ η1)) ≈⟨ (refl⟩∘⟨ F.F-resp-≈ λ _ → U.F-resp-≈ x≈y Srefl) ⟩ L.counit.η X C.∘ F.₁ (U.₁ 1⇒y ∘ L.unit.η OneS) ≈⟨ L.RLadjunct≈id {OneS} {X} {1⇒y} ⟩ 1⇒y ∎ } } } } where module C = Category C module U = Functor (concretize conc) module F = Functor F module L = Adjoint L open NaturalTransformation open MR C -- Is this somewhere else? Should it be? OneS : Setoid ℓ e OneS = record { Carrier = ⊤ {ℓ} ; _≈_ = λ _ _ → ⊤ {e}} η1 : Setoid.Carrier (U.₀ (F.₀ OneS)) η1 = L.unit.η OneS ⟨$⟩ tt Srefl = Setoid.refl (U.₀ (F.₀ OneS))
{ "alphanum_fraction": 0.546208167, "avg_line_length": 40.7125, "ext": "agda", "hexsha": "5d305df6a1d79fa01b05db2dda252c7f827a2f87", "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/Concrete/Properties.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/Concrete/Properties.agda", "max_line_length": 114, "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/Concrete/Properties.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": 1339, "size": 3257 }
{-# OPTIONS --without-K --exact-split #-} module 18-circle where import 17-groups open 17-groups public {- Section 11.1 The induction principle of the circle -} free-loops : { l1 : Level} (X : UU l1) → UU l1 free-loops X = Σ X (λ x → Id x x) base-free-loop : { l1 : Level} {X : UU l1} → free-loops X → X base-free-loop = pr1 loop-free-loop : { l1 : Level} {X : UU l1} (l : free-loops X) → Id (base-free-loop l) (base-free-loop l) loop-free-loop = pr2 -- Now we characterize the identity types of free loops Eq-free-loops : { l1 : Level} {X : UU l1} (l l' : free-loops X) → UU l1 Eq-free-loops (pair x l) l' = Σ (Id x (pr1 l')) (λ p → Id (l ∙ p) (p ∙ (pr2 l'))) reflexive-Eq-free-loops : { l1 : Level} {X : UU l1} (l : free-loops X) → Eq-free-loops l l reflexive-Eq-free-loops (pair x l) = pair refl right-unit Eq-free-loops-eq : { l1 : Level} {X : UU l1} (l l' : free-loops X) → Id l l' → Eq-free-loops l l' Eq-free-loops-eq l .l refl = reflexive-Eq-free-loops l abstract is-contr-total-Eq-free-loops : { l1 : Level} {X : UU l1} (l : free-loops X) → is-contr (Σ (free-loops X) (Eq-free-loops l)) is-contr-total-Eq-free-loops (pair x l) = is-contr-total-Eq-structure ( λ x l' p → Id (l ∙ p) (p ∙ l')) ( is-contr-total-path x) ( pair x refl) ( is-contr-is-equiv' ( Σ (Id x x) (λ l' → Id l l')) ( tot (λ l' α → right-unit ∙ α)) ( is-equiv-tot-is-fiberwise-equiv ( λ l' → is-equiv-concat right-unit l')) ( is-contr-total-path l)) abstract is-equiv-Eq-free-loops-eq : { l1 : Level} {X : UU l1} (l l' : free-loops X) → is-equiv (Eq-free-loops-eq l l') is-equiv-Eq-free-loops-eq l = fundamental-theorem-id l ( reflexive-Eq-free-loops l) ( is-contr-total-Eq-free-loops l) ( Eq-free-loops-eq l) {- We introduce dependent free loops, which are used in the induction principle of the circle. -} dependent-free-loops : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) → UU l2 dependent-free-loops l P = Σ ( P (base-free-loop l)) ( λ p₀ → Id (tr P (loop-free-loop l) p₀) p₀) Eq-dependent-free-loops : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) → ( p p' : dependent-free-loops l P) → UU l2 Eq-dependent-free-loops (pair x l) P (pair y p) p' = Σ ( Id y (pr1 p')) ( λ q → Id (p ∙ q) ((ap (tr P l) q) ∙ (pr2 p'))) reflexive-Eq-dependent-free-loops : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) → ( p : dependent-free-loops l P) → Eq-dependent-free-loops l P p p reflexive-Eq-dependent-free-loops (pair x l) P (pair y p) = pair refl right-unit Eq-dependent-free-loops-eq : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) → ( p p' : dependent-free-loops l P) → Id p p' → Eq-dependent-free-loops l P p p' Eq-dependent-free-loops-eq l P p .p refl = reflexive-Eq-dependent-free-loops l P p abstract is-contr-total-Eq-dependent-free-loops : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) → ( p : dependent-free-loops l P) → is-contr (Σ (dependent-free-loops l P) (Eq-dependent-free-loops l P p)) is-contr-total-Eq-dependent-free-loops (pair x l) P (pair y p) = is-contr-total-Eq-structure ( λ y' p' q → Id (p ∙ q) ((ap (tr P l) q) ∙ p')) ( is-contr-total-path y) ( pair y refl) ( is-contr-is-equiv' ( Σ (Id (tr P l y) y) (λ p' → Id p p')) ( tot (λ p' α → right-unit ∙ α)) ( is-equiv-tot-is-fiberwise-equiv ( λ p' → is-equiv-concat right-unit p')) ( is-contr-total-path p)) abstract is-equiv-Eq-dependent-free-loops-eq : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) ( p p' : dependent-free-loops l P) → is-equiv (Eq-dependent-free-loops-eq l P p p') is-equiv-Eq-dependent-free-loops-eq l P p = fundamental-theorem-id p ( reflexive-Eq-dependent-free-loops l P p) ( is-contr-total-Eq-dependent-free-loops l P p) ( Eq-dependent-free-loops-eq l P p) eq-Eq-dependent-free-loops : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) ( p p' : dependent-free-loops l P) → Eq-dependent-free-loops l P p p' → Id p p' eq-Eq-dependent-free-loops l P p p' = inv-is-equiv (is-equiv-Eq-dependent-free-loops-eq l P p p') {- We now define the induction principle of the circle. -} ev-free-loop' : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (P : X → UU l2) → ( (x : X) → P x) → dependent-free-loops l P ev-free-loop' (pair x₀ p) P f = pair (f x₀) (apd f p) induction-principle-circle : { l1 : Level} (l2 : Level) {X : UU l1} (l : free-loops X) → UU ((lsuc l2) ⊔ l1) induction-principle-circle l2 {X} l = (P : X → UU l2) → sec (ev-free-loop' l P) {- Section 11.2 The universal property of the circle -} {- We first state the universal property of the circle -} ev-free-loop : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (Y : UU l2) → ( X → Y) → free-loops Y ev-free-loop l Y f = pair (f (pr1 l)) (ap f (pr2 l)) universal-property-circle : { l1 : Level} (l2 : Level) {X : UU l1} (l : free-loops X) → UU _ universal-property-circle l2 l = ( Y : UU l2) → is-equiv (ev-free-loop l Y) {- A fairly straightforward proof of the universal property of the circle factors through the dependent universal property of the circle. -} dependent-universal-property-circle : { l1 : Level} (l2 : Level) {X : UU l1} (l : free-loops X) → UU ((lsuc l2) ⊔ l1) dependent-universal-property-circle l2 {X} l = ( P : X → UU l2) → is-equiv (ev-free-loop' l P) {- We first prove that the dependent universal property of the circle follows from the induction principle of the circle. To show this, we have to show that the section of ev-free-loop' is also a retraction. This construction is also by the induction principle of the circle, but it requires (a minimal amount of) preparations. -} Eq-subst : { l1 l2 : Level} {X : UU l1} {P : X → UU l2} (f g : (x : X) → P x) → X → UU _ Eq-subst f g x = Id (f x) (g x) tr-Eq-subst : { l1 l2 : Level} {X : UU l1} {P : X → UU l2} (f g : (x : X) → P x) { x y : X} (p : Id x y) (q : Id (f x) (g x)) (r : Id (f y) (g y))→ ( Id ((apd f p) ∙ r) ((ap (tr P p) q) ∙ (apd g p))) → ( Id (tr (Eq-subst f g) p q) r) tr-Eq-subst f g refl q .((ap id q) ∙ refl) refl = inv (right-unit ∙ (ap-id q)) dependent-free-loops-htpy : {l1 l2 : Level} {X : UU l1} {l : free-loops X} {P : X → UU l2} {f g : (x : X) → P x} → ( Eq-dependent-free-loops l P (ev-free-loop' l P f) (ev-free-loop' l P g)) → ( dependent-free-loops l (λ x → Id (f x) (g x))) dependent-free-loops-htpy {l = (pair x l)} (pair p q) = pair p (tr-Eq-subst _ _ l p p q) isretr-ind-circle : { l1 l2 : Level} {X : UU l1} (l : free-loops X) → ( ind-circle : induction-principle-circle l2 l) (P : X → UU l2) → ( (pr1 (ind-circle P)) ∘ (ev-free-loop' l P)) ~ id isretr-ind-circle l ind-circle P f = eq-htpy ( pr1 ( ind-circle ( λ t → Id (pr1 (ind-circle P) (ev-free-loop' l P f) t) (f t))) ( dependent-free-loops-htpy ( Eq-dependent-free-loops-eq l P _ _ ( pr2 (ind-circle P) (ev-free-loop' l P f))))) abstract dependent-universal-property-induction-principle-circle : { l1 l2 : Level} {X : UU l1} (l : free-loops X) → induction-principle-circle l2 l → dependent-universal-property-circle l2 l dependent-universal-property-induction-principle-circle l ind-circle P = is-equiv-has-inverse ( pr1 (ind-circle P)) ( pr2 (ind-circle P)) ( isretr-ind-circle l ind-circle P) {- We use the dependent universal property to derive a uniqeness property of dependent functions on the circle. -} dependent-uniqueness-circle : { l1 l2 : Level} {X : UU l1} (l : free-loops X) → dependent-universal-property-circle l2 l → { P : X → UU l2} (k : dependent-free-loops l P) → is-contr ( Σ ( (x : X) → P x) ( λ h → Eq-dependent-free-loops l P (ev-free-loop' l P h) k)) dependent-uniqueness-circle l dup-circle {P} k = is-contr-is-equiv' ( fib (ev-free-loop' l P) k) ( tot (λ h → Eq-dependent-free-loops-eq l P (ev-free-loop' l P h) k)) ( is-equiv-tot-is-fiberwise-equiv (λ h → is-equiv-Eq-dependent-free-loops-eq l P (ev-free-loop' l P h) k)) ( is-contr-map-is-equiv (dup-circle P) k) {- Now that we have established the dependent universal property, we can reduce the (non-dependent) universal property to the dependent case. We do so by constructing a commuting triangle relating ev-free-loop to ev-free-loop' via a comparison equivalence. -} tr-const : {i j : Level} {A : UU i} {B : UU j} {x y : A} (p : Id x y) (b : B) → Id (tr (λ (a : A) → B) p b) b tr-const refl b = refl apd-const : {i j : Level} {A : UU i} {B : UU j} (f : A → B) {x y : A} (p : Id x y) → Id (apd f p) ((tr-const p (f x)) ∙ (ap f p)) apd-const f refl = refl comparison-free-loops : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (Y : UU l2) → free-loops Y → dependent-free-loops l (λ x → Y) comparison-free-loops l Y = tot (λ y l' → (tr-const (pr2 l) y) ∙ l') abstract is-equiv-comparison-free-loops : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (Y : UU l2) → is-equiv (comparison-free-loops l Y) is-equiv-comparison-free-loops l Y = is-equiv-tot-is-fiberwise-equiv ( λ y → is-equiv-concat (tr-const (pr2 l) y) y) triangle-comparison-free-loops : { l1 l2 : Level} {X : UU l1} (l : free-loops X) (Y : UU l2) → ( (comparison-free-loops l Y) ∘ (ev-free-loop l Y)) ~ ( ev-free-loop' l (λ x → Y)) triangle-comparison-free-loops (pair x l) Y f = eq-Eq-dependent-free-loops ( pair x l) ( λ x → Y) ( comparison-free-loops (pair x l) Y (ev-free-loop (pair x l) Y f)) ( ev-free-loop' (pair x l) (λ x → Y) f) ( pair refl (right-unit ∙ (inv (apd-const f l)))) abstract universal-property-dependent-universal-property-circle : { l1 l2 : Level} {X : UU l1} (l : free-loops X) → ( dependent-universal-property-circle l2 l) → ( universal-property-circle l2 l) universal-property-dependent-universal-property-circle l dup-circle Y = is-equiv-right-factor ( ev-free-loop' l (λ x → Y)) ( comparison-free-loops l Y) ( ev-free-loop l Y) ( htpy-inv (triangle-comparison-free-loops l Y)) ( is-equiv-comparison-free-loops l Y) ( dup-circle (λ x → Y)) {- Now we get the universal property of the circle from the induction principle of the circle by composing the earlier two proofs. -} abstract universal-property-induction-principle-circle : { l1 l2 : Level} {X : UU l1} (l : free-loops X) → induction-principle-circle l2 l → universal-property-circle l2 l universal-property-induction-principle-circle l = ( universal-property-dependent-universal-property-circle l) ∘ ( dependent-universal-property-induction-principle-circle l) unique-mapping-property-circle : { l1 : Level} (l2 : Level) {X : UU l1} (l : free-loops X) → UU (l1 ⊔ (lsuc l2)) unique-mapping-property-circle l2 {X} l = ( Y : UU l2) (l' : free-loops Y) → is-contr (Σ (X → Y) (λ f → Eq-free-loops (ev-free-loop l Y f) l')) abstract unique-mapping-property-universal-property-circle : { l1 l2 : Level} {X : UU l1} (l : free-loops X) → universal-property-circle l2 l → unique-mapping-property-circle l2 l unique-mapping-property-universal-property-circle l up-circle Y l' = is-contr-is-equiv' ( fib (ev-free-loop l Y) l') ( tot (λ f → Eq-free-loops-eq (ev-free-loop l Y f) l')) ( is-equiv-tot-is-fiberwise-equiv ( λ f → is-equiv-Eq-free-loops-eq (ev-free-loop l Y f) l')) ( is-contr-map-is-equiv (up-circle Y) l') {- We assume that we have a circle. -} postulate 𝕊¹ : UU lzero postulate base-𝕊¹ : 𝕊¹ postulate loop-𝕊¹ : Id base-𝕊¹ base-𝕊¹ free-loop-𝕊¹ : free-loops 𝕊¹ free-loop-𝕊¹ = pair base-𝕊¹ loop-𝕊¹ postulate ind-𝕊¹ : {l : Level} → induction-principle-circle l free-loop-𝕊¹ dependent-universal-property-𝕊¹ : {l : Level} → dependent-universal-property-circle l free-loop-𝕊¹ dependent-universal-property-𝕊¹ = dependent-universal-property-induction-principle-circle free-loop-𝕊¹ ind-𝕊¹ dependent-uniqueness-𝕊¹ : {l : Level} {P : 𝕊¹ → UU l} (k : dependent-free-loops free-loop-𝕊¹ P) → is-contr (Σ ((x : 𝕊¹) → P x) (λ h → Eq-dependent-free-loops free-loop-𝕊¹ P (ev-free-loop' free-loop-𝕊¹ P h) k)) dependent-uniqueness-𝕊¹ {l} {P} k = dependent-uniqueness-circle free-loop-𝕊¹ dependent-universal-property-𝕊¹ k universal-property-𝕊¹ : {l : Level} → universal-property-circle l free-loop-𝕊¹ universal-property-𝕊¹ = universal-property-dependent-universal-property-circle free-loop-𝕊¹ dependent-universal-property-𝕊¹ -- Section 14.3 Multiplication on the circle {- Exercises -} -- Exercise 11.1 {- The dependent universal property of the circle (and hence also the induction principle of the circle, implies that the circle is connected in the sense that for any family of propositions parametrized by the circle, if the proposition at the base holds, then it holds for any x : circle. -} abstract is-connected-circle' : { l1 l2 : Level} {X : UU l1} (l : free-loops X) → ( dup-circle : dependent-universal-property-circle l2 l) ( P : X → UU l2) (is-prop-P : (x : X) → is-prop (P x)) → P (base-free-loop l) → (x : X) → P x is-connected-circle' l dup-circle P is-prop-P p = inv-is-equiv ( dup-circle P) ( pair p (center (is-prop-P _ (tr P (pr2 l) p) p)))
{ "alphanum_fraction": 0.6125360337, "avg_line_length": 36.2707774799, "ext": "agda", "hexsha": "2c02e77a280147a066ad0007d02e2a328a865737", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_path": "Agda/18-circle.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_path": "Agda/18-circle.agda", "max_line_length": 113, "max_stars_count": null, "max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "hemangandhi/HoTT-Intro", "max_stars_repo_path": "Agda/18-circle.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4808, "size": 13529 }
open import OutsideIn.Prelude open import OutsideIn.X module OutsideIn.TypeSchema(x : X) where open X(x) open import Data.Vec hiding (_>>=_) data NameType : Set where Regular : NameType Datacon : ℕ → NameType data TypeSchema ( n : Set) : NameType → Set where ∀′_·_⇒_ : (v : ℕ) → QConstraint (n ⨁ v) → Type (n ⨁ v) → TypeSchema n Regular DC∀′_,_·_⇒_⟶_ : (a b : ℕ){l : ℕ} → QConstraint ((n ⨁ a) ⨁ b) → Vec (Type ((n ⨁ a) ⨁ b)) l → n → TypeSchema n (Datacon l) DC∀_·_⟶_ : (a : ℕ){l : ℕ} → Vec (Type (n ⨁ a)) l → n → TypeSchema n (Datacon l) private module PlusN-f n = Functor (Monad.is-functor (PlusN-is-monad {n})) module Vec-f {n} = Functor (vec-is-functor {n}) module Type-f = Functor (type-is-functor) module QC-f = Functor (qconstraint-is-functor) private fmap-schema : {A B : Set}{x : NameType} → (A → B) → TypeSchema A x → TypeSchema B x fmap-schema f (∀′ n · Q ⇒ τ) = ∀′ n · QC-f.map (pn.map f) Q ⇒ Type-f.map (pn.map f) τ where module pn = PlusN-f n fmap-schema f (DC∀′ a , b · Q ⇒ τs ⟶ K) = DC∀′ a , b · QC-f.map (pb.map (pa.map f)) Q ⇒ map (Type-f.map (pb.map (pa.map f))) τs ⟶ f K where module pa = PlusN-f a module pb = PlusN-f b fmap-schema f (DC∀ a · τs ⟶ K) = DC∀ a · map (Type-f.map (pa.map f)) τs ⟶ f K where module pa = PlusN-f a fmap-schema-id : {A : Set}{x : NameType} {f : A → A} → isIdentity f → isIdentity (fmap-schema {A}{A}{x} f) fmap-schema-id isid {∀′ n · Q ⇒ τ} = cong₂ (∀′_·_⇒_ n) (QC-f.identity (pn.identity isid)) (Type-f.identity (pn.identity isid)) where module pn = PlusN-f n fmap-schema-id isid {DC∀′ a , b · Q ⇒ τs ⟶ K} = cong₃ (DC∀′_,_·_⇒_⟶_ a b) (QC-f.identity (pb.identity (pa.identity isid))) (Vec-f.identity (Type-f.identity (pb.identity (pa.identity isid)))) isid where module pa = PlusN-f a module pb = PlusN-f b fmap-schema-id isid {DC∀ a · τs ⟶ K} = cong₂ (DC∀_·_⟶_ a) (Vec-f.identity (Type-f.identity (pa.identity isid))) isid where module pa = PlusN-f a fmap-schema-comp : {A B C : Set}{s : NameType} {f : A → B} {g : B → C} {x : TypeSchema A s} → fmap-schema (g ∘ f) x ≡ fmap-schema g (fmap-schema f x) fmap-schema-comp {x = ∀′ n · Q ⇒ τ} = cong₂ (∀′_·_⇒_ n) (Functor.composite (qconstraint-is-functor ∘f pnf)) (Functor.composite (type-is-functor ∘f pnf)) where pnf = Monad.is-functor (PlusN-is-monad {n}) fmap-schema-comp {x = DC∀′ a , b · Q ⇒ τs ⟶ K} = cong₃ (DC∀′_,_·_⇒_⟶_ a b) (Functor.composite (qconstraint-is-functor ∘f pbf ∘f paf )) (Functor.composite (vec-is-functor ∘f type-is-functor ∘f pbf ∘f paf)) refl where module pa = PlusN-f a module pb = PlusN-f b paf = Monad.is-functor (PlusN-is-monad {a}) pbf = Monad.is-functor (PlusN-is-monad {b}) fmap-schema-comp {x = DC∀ a · τs ⟶ K} = cong₂ (DC∀_·_⟶_ a) (Functor.composite (vec-is-functor ∘f type-is-functor ∘f paf)) refl where module pa = PlusN-f a paf = Monad.is-functor (PlusN-is-monad {a}) type-schema-is-functor : ∀{s} → Functor (λ x → TypeSchema x s) type-schema-is-functor = record { map = fmap-schema ; identity = fmap-schema-id ; composite = fmap-schema-comp }
{ "alphanum_fraction": 0.488372093, "avg_line_length": 46.0714285714, "ext": "agda", "hexsha": "03d5881b8b1194f2b27a29fe135248dfdde7e6ab", "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/TypeSchema.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/TypeSchema.agda", "max_line_length": 100, "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/TypeSchema.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": 1269, "size": 3870 }
{-# OPTIONS --allow-unsolved-metas #-} open import Level open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Ordinals module partfunc {n : Level } (O : Ordinals {n}) where open import logic open import Relation.Binary open import Data.Empty open import Data.List hiding (filter) open import Data.Maybe open import Relation.Binary open import Relation.Binary.Core open import Data.Nat renaming ( zero to Zero ; suc to Suc ; ℕ to Nat ; _⊔_ to _n⊔_ ) open import filter O open _∧_ open _∨_ open Bool ---- -- -- Partial Function without ZF -- record PFunc (Dom : Set n) (Cod : Set n) : Set (suc n) where field dom : Dom → Set n pmap : (x : Dom ) → dom x → Cod meq : {x : Dom } → { p q : dom x } → pmap x p ≡ pmap x q ---- -- -- PFunc (Lift n Nat) Cod is equivalent to List (Maybe Cod) -- data Findp : {Cod : Set n} → List (Maybe Cod) → (x : Nat) → Set where v0 : {Cod : Set n} → {f : List (Maybe Cod)} → ( v : Cod ) → Findp ( just v ∷ f ) Zero vn : {Cod : Set n} → {f : List (Maybe Cod)} {d : Maybe Cod} → {x : Nat} → Findp f x → Findp (d ∷ f) (Suc x) open PFunc find : {Cod : Set n} → (f : List (Maybe Cod) ) → (x : Nat) → Findp f x → Cod find (just v ∷ _) 0 (v0 v) = v find (_ ∷ n) (Suc i) (vn p) = find n i p findpeq : {Cod : Set n} → (f : List (Maybe Cod)) → {x : Nat} {p q : Findp f x } → find f x p ≡ find f x q findpeq n {0} {v0 _} {v0 _} = refl findpeq [] {Suc x} {()} findpeq (just x₁ ∷ n) {Suc x} {vn p} {vn q} = findpeq n {x} {p} {q} findpeq (nothing ∷ n) {Suc x} {vn p} {vn q} = findpeq n {x} {p} {q} List→PFunc : {Cod : Set n} → List (Maybe Cod) → PFunc (Lift n Nat) Cod List→PFunc fp = record { dom = λ x → Lift n (Findp fp (lower x)) ; pmap = λ x y → find fp (lower x) (lower y) ; meq = λ {x} {p} {q} → findpeq fp {lower x} {lower p} {lower q} } ---- -- -- to List (Maybe Two) is a Latice -- _3⊆b_ : (f g : List (Maybe Two)) → Bool [] 3⊆b [] = true [] 3⊆b (nothing ∷ g) = [] 3⊆b g [] 3⊆b (_ ∷ g) = true (nothing ∷ f) 3⊆b [] = f 3⊆b [] (nothing ∷ f) 3⊆b (_ ∷ g) = f 3⊆b g (just i0 ∷ f) 3⊆b (just i0 ∷ g) = f 3⊆b g (just i1 ∷ f) 3⊆b (just i1 ∷ g) = f 3⊆b g _ 3⊆b _ = false _3⊆_ : (f g : List (Maybe Two)) → Set f 3⊆ g = (f 3⊆b g) ≡ true _3∩_ : (f g : List (Maybe Two)) → List (Maybe Two) [] 3∩ (nothing ∷ g) = nothing ∷ ([] 3∩ g) [] 3∩ g = [] (nothing ∷ f) 3∩ [] = nothing ∷ f 3∩ [] f 3∩ [] = [] (just i0 ∷ f) 3∩ (just i0 ∷ g) = just i0 ∷ ( f 3∩ g ) (just i1 ∷ f) 3∩ (just i1 ∷ g) = just i1 ∷ ( f 3∩ g ) (_ ∷ f) 3∩ (_ ∷ g) = nothing ∷ ( f 3∩ g ) 3∩⊆f : { f g : List (Maybe Two) } → (f 3∩ g ) 3⊆ f 3∩⊆f {[]} {[]} = refl 3∩⊆f {[]} {just _ ∷ g} = refl 3∩⊆f {[]} {nothing ∷ g} = 3∩⊆f {[]} {g} 3∩⊆f {just _ ∷ f} {[]} = refl 3∩⊆f {nothing ∷ f} {[]} = 3∩⊆f {f} {[]} 3∩⊆f {just i0 ∷ f} {just i0 ∷ g} = 3∩⊆f {f} {g} 3∩⊆f {just i1 ∷ f} {just i1 ∷ g} = 3∩⊆f {f} {g} 3∩⊆f {just i0 ∷ f} {just i1 ∷ g} = 3∩⊆f {f} {g} 3∩⊆f {just i1 ∷ f} {just i0 ∷ g} = 3∩⊆f {f} {g} 3∩⊆f {nothing ∷ f} {just _ ∷ g} = 3∩⊆f {f} {g} 3∩⊆f {just i0 ∷ f} {nothing ∷ g} = 3∩⊆f {f} {g} 3∩⊆f {just i1 ∷ f} {nothing ∷ g} = 3∩⊆f {f} {g} 3∩⊆f {nothing ∷ f} {nothing ∷ g} = 3∩⊆f {f} {g} 3∩sym : { f g : List (Maybe Two) } → (f 3∩ g ) ≡ (g 3∩ f ) 3∩sym {[]} {[]} = refl 3∩sym {[]} {just _ ∷ g} = refl 3∩sym {[]} {nothing ∷ g} = cong (λ k → nothing ∷ k) (3∩sym {[]} {g}) 3∩sym {just _ ∷ f} {[]} = refl 3∩sym {nothing ∷ f} {[]} = cong (λ k → nothing ∷ k) (3∩sym {f} {[]}) 3∩sym {just i0 ∷ f} {just i0 ∷ g} = cong (λ k → just i0 ∷ k) (3∩sym {f} {g}) 3∩sym {just i0 ∷ f} {just i1 ∷ g} = cong (λ k → nothing ∷ k) (3∩sym {f} {g}) 3∩sym {just i1 ∷ f} {just i0 ∷ g} = cong (λ k → nothing ∷ k) (3∩sym {f} {g}) 3∩sym {just i1 ∷ f} {just i1 ∷ g} = cong (λ k → just i1 ∷ k) (3∩sym {f} {g}) 3∩sym {just i0 ∷ f} {nothing ∷ g} = cong (λ k → nothing ∷ k) (3∩sym {f} {g}) 3∩sym {just i1 ∷ f} {nothing ∷ g} = cong (λ k → nothing ∷ k) (3∩sym {f} {g}) 3∩sym {nothing ∷ f} {just i0 ∷ g} = cong (λ k → nothing ∷ k) (3∩sym {f} {g}) 3∩sym {nothing ∷ f} {just i1 ∷ g} = cong (λ k → nothing ∷ k) (3∩sym {f} {g}) 3∩sym {nothing ∷ f} {nothing ∷ g} = cong (λ k → nothing ∷ k) (3∩sym {f} {g}) 3⊆-[] : { h : List (Maybe Two) } → [] 3⊆ h 3⊆-[] {[]} = refl 3⊆-[] {just _ ∷ h} = refl 3⊆-[] {nothing ∷ h} = 3⊆-[] {h} 3⊆trans : { f g h : List (Maybe Two) } → f 3⊆ g → g 3⊆ h → f 3⊆ h 3⊆trans {[]} {[]} {[]} f<g g<h = refl 3⊆trans {[]} {[]} {just _ ∷ h} f<g g<h = refl 3⊆trans {[]} {[]} {nothing ∷ h} f<g g<h = 3⊆trans {[]} {[]} {h} refl g<h 3⊆trans {[]} {nothing ∷ g} {[]} f<g g<h = refl 3⊆trans {[]} {just _ ∷ g} {just _ ∷ h} f<g g<h = refl 3⊆trans {[]} {nothing ∷ g} {just _ ∷ h} f<g g<h = refl 3⊆trans {[]} {nothing ∷ g} {nothing ∷ h} f<g g<h = 3⊆trans {[]} {g} {h} f<g g<h 3⊆trans {nothing ∷ f} {[]} {[]} f<g g<h = f<g 3⊆trans {nothing ∷ f} {[]} {just _ ∷ h} f<g g<h = 3⊆trans {f} {[]} {h} f<g (3⊆-[] {h}) 3⊆trans {nothing ∷ f} {[]} {nothing ∷ h} f<g g<h = 3⊆trans {f} {[]} {h} f<g g<h 3⊆trans {nothing ∷ f} {nothing ∷ g} {[]} f<g g<h = 3⊆trans {f} {g} {[]} f<g g<h 3⊆trans {nothing ∷ f} {nothing ∷ g} {just _ ∷ h} f<g g<h = 3⊆trans {f} {g} {h} f<g g<h 3⊆trans {nothing ∷ f} {nothing ∷ g} {nothing ∷ h} f<g g<h = 3⊆trans {f} {g} {h} f<g g<h 3⊆trans {[]} {just i0 ∷ g} {[]} f<g () 3⊆trans {[]} {just i1 ∷ g} {[]} f<g () 3⊆trans {[]} {just x ∷ g} {nothing ∷ h} f<g g<h = 3⊆-[] {h} 3⊆trans {just i0 ∷ f} {[]} {h} () g<h 3⊆trans {just i1 ∷ f} {[]} {h} () g<h 3⊆trans {just x ∷ f} {just i0 ∷ g} {[]} f<g () 3⊆trans {just x ∷ f} {just i1 ∷ g} {[]} f<g () 3⊆trans {just i0 ∷ f} {just i0 ∷ g} {just i0 ∷ h} f<g g<h = 3⊆trans {f} {g} {h} f<g g<h 3⊆trans {just i1 ∷ f} {just i1 ∷ g} {just i1 ∷ h} f<g g<h = 3⊆trans {f} {g} {h} f<g g<h 3⊆trans {just x ∷ f} {just i0 ∷ g} {nothing ∷ h} f<g () 3⊆trans {just x ∷ f} {just i1 ∷ g} {nothing ∷ h} f<g () 3⊆trans {just i0 ∷ f} {nothing ∷ g} {_} () g<h 3⊆trans {just i1 ∷ f} {nothing ∷ g} {_} () g<h 3⊆trans {nothing ∷ f} {just i0 ∷ g} {[]} f<g () 3⊆trans {nothing ∷ f} {just i1 ∷ g} {[]} f<g () 3⊆trans {nothing ∷ f} {just i0 ∷ g} {just i0 ∷ h} f<g g<h = 3⊆trans {f} {g} {h} f<g g<h 3⊆trans {nothing ∷ f} {just i1 ∷ g} {just i1 ∷ h} f<g g<h = 3⊆trans {f} {g} {h} f<g g<h 3⊆trans {nothing ∷ f} {just i0 ∷ g} {nothing ∷ h} f<g () 3⊆trans {nothing ∷ f} {just i1 ∷ g} {nothing ∷ h} f<g () 3⊆∩f : { f g h : List (Maybe Two) } → f 3⊆ g → f 3⊆ h → f 3⊆ (g 3∩ h ) 3⊆∩f {[]} {[]} {[]} f<g f<h = refl 3⊆∩f {[]} {[]} {x ∷ h} f<g f<h = 3⊆-[] {[] 3∩ (x ∷ h)} 3⊆∩f {[]} {x ∷ g} {h} f<g f<h = 3⊆-[] {(x ∷ g) 3∩ h} 3⊆∩f {nothing ∷ f} {[]} {[]} f<g f<h = 3⊆∩f {f} {[]} {[]} f<g f<h 3⊆∩f {nothing ∷ f} {[]} {just _ ∷ h} f<g f<h = f<g 3⊆∩f {nothing ∷ f} {[]} {nothing ∷ h} f<g f<h = 3⊆∩f {f} {[]} {h} f<g f<h 3⊆∩f {just i0 ∷ f} {just i0 ∷ g} {just i0 ∷ h} f<g f<h = 3⊆∩f {f} {g} {h} f<g f<h 3⊆∩f {just i1 ∷ f} {just i1 ∷ g} {just i1 ∷ h} f<g f<h = 3⊆∩f {f} {g} {h} f<g f<h 3⊆∩f {nothing ∷ f} {just _ ∷ g} {[]} f<g f<h = f<h 3⊆∩f {nothing ∷ f} {just i0 ∷ g} {just i0 ∷ h} f<g f<h = 3⊆∩f {f} {g} {h} f<g f<h 3⊆∩f {nothing ∷ f} {just i0 ∷ g} {just i1 ∷ h} f<g f<h = 3⊆∩f {f} {g} {h} f<g f<h 3⊆∩f {nothing ∷ f} {just i1 ∷ g} {just i0 ∷ h} f<g f<h = 3⊆∩f {f} {g} {h} f<g f<h 3⊆∩f {nothing ∷ f} {just i1 ∷ g} {just i1 ∷ h} f<g f<h = 3⊆∩f {f} {g} {h} f<g f<h 3⊆∩f {nothing ∷ f} {just i0 ∷ g} {nothing ∷ h} f<g f<h = 3⊆∩f {f} {g} {h} f<g f<h 3⊆∩f {nothing ∷ f} {just i1 ∷ g} {nothing ∷ h} f<g f<h = 3⊆∩f {f} {g} {h} f<g f<h 3⊆∩f {nothing ∷ f} {nothing ∷ g} {[]} f<g f<h = 3⊆∩f {f} {g} {[]} f<g f<h 3⊆∩f {nothing ∷ f} {nothing ∷ g} {just _ ∷ h} f<g f<h = 3⊆∩f {f} {g} {h} f<g f<h 3⊆∩f {nothing ∷ f} {nothing ∷ g} {nothing ∷ h} f<g f<h = 3⊆∩f {f} {g} {h} f<g f<h 3↑22 : (f : Nat → Two) (i j : Nat) → List (Maybe Two) 3↑22 f Zero j = [] 3↑22 f (Suc i) j = just (f j) ∷ 3↑22 f i (Suc j) _3↑_ : (Nat → Two) → Nat → List (Maybe Two) _3↑_ f i = 3↑22 f i 0 3↑< : {f : Nat → Two} → { x y : Nat } → x ≤ y → (_3↑_ f x) 3⊆ (_3↑_ f y) 3↑< {f} {x} {y} x<y = lemma x y 0 x<y where lemma : (x y i : Nat) → x ≤ y → (3↑22 f x i ) 3⊆ (3↑22 f y i ) lemma 0 y i z≤n with f i lemma Zero Zero i z≤n | i0 = refl lemma Zero (Suc y) i z≤n | i0 = 3⊆-[] {3↑22 f (Suc y) i} lemma Zero Zero i z≤n | i1 = refl lemma Zero (Suc y) i z≤n | i1 = 3⊆-[] {3↑22 f (Suc y) i} lemma (Suc x) (Suc y) i (s≤s x<y) with f i lemma (Suc x) (Suc y) i (s≤s x<y) | i0 = lemma x y (Suc i) x<y lemma (Suc x) (Suc y) i (s≤s x<y) | i1 = lemma x y (Suc i) x<y Finite3b : (p : List (Maybe Two) ) → Bool Finite3b [] = true Finite3b (just _ ∷ f) = Finite3b f Finite3b (nothing ∷ f) = false finite3cov : (p : List (Maybe Two) ) → List (Maybe Two) finite3cov [] = [] finite3cov (just y ∷ x) = just y ∷ finite3cov x finite3cov (nothing ∷ x) = just i0 ∷ finite3cov x Dense-3 : F-Dense (List (Maybe Two) ) (λ x → One) _3⊆_ _3∩_ Dense-3 = record { dense = λ x → Finite3b x ≡ true ; d⊆P = OneObj ; dense-f = λ x → finite3cov x ; dense-d = λ {p} d → lemma1 p ; dense-p = λ {p} d → lemma2 p } where lemma1 : (p : List (Maybe Two) ) → Finite3b (finite3cov p) ≡ true lemma1 [] = refl lemma1 (just i0 ∷ p) = lemma1 p lemma1 (just i1 ∷ p) = lemma1 p lemma1 (nothing ∷ p) = lemma1 p lemma2 : (p : List (Maybe Two)) → p 3⊆ finite3cov p lemma2 [] = refl lemma2 (just i0 ∷ p) = lemma2 p lemma2 (just i1 ∷ p) = lemma2 p lemma2 (nothing ∷ p) = lemma2 p -- min = Data.Nat._⊓_ -- m≤m⊔n = Data.Nat._⊔_ -- open import Data.Nat.Properties
{ "alphanum_fraction": 0.4838137009, "avg_line_length": 42, "ext": "agda", "hexsha": "48d67d08f9f8e97d14e13d052555f46038a609b4", "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": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "shinji-kono/zf-in-agda", "max_forks_repo_path": "src/partfunc.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "shinji-kono/zf-in-agda", "max_issues_repo_path": "src/partfunc.agda", "max_line_length": 111, "max_stars_count": 5, "max_stars_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "shinji-kono/zf-in-agda", "max_stars_repo_path": "src/partfunc.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-10T13:27:48.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-02T13:46:23.000Z", "num_tokens": 4991, "size": 9576 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Pointwise lifting of a predicate to a binary tree ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Tree.Binary.Relation.Unary.All where open import Level open import Data.Tree.Binary as Tree using (Tree; leaf; node) open import Relation.Unary private variable a b p q : Level A : Set a B : Set b data All {A : Set a} (P : A → Set p) : Tree A → Set (a ⊔ p) where leaf : All P leaf node : ∀ {l m r} → All P l → P m → All P r → All P (node l m r) module _ {P : A → Set p} {Q : A → Set q} where map : ∀[ P ⇒ Q ] → ∀[ All P ⇒ All Q ] map f leaf = leaf map f (node l m r) = node (map f l) (f m) (map f r)
{ "alphanum_fraction": 0.4810281518, "avg_line_length": 27.2333333333, "ext": "agda", "hexsha": "3af499e8b8ed0bc88742c299068ad93c8b69c9d4", "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/Tree/Binary/Relation/Unary/All.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/Tree/Binary/Relation/Unary/All.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/Tree/Binary/Relation/Unary/All.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": 229, "size": 817 }
{-# OPTIONS --without-K #-} -- -- Implementation of Sets using lists -- open import Prelude module Sets {i} (A : Set i) (eqdecA : eqdec A) where valid : list A → Set i valid l = ∀ x → has-all-paths (x ∈-list l) set = Σ (list A) (λ l → valid l) valid-nil : valid nil valid-nil _ () Ø : set Ø = nil , valid-nil valid-singleton : ∀ (x : A) → valid (nil :: x) valid-singleton x y (inr p) (inr q) = ap inr (is-prop-has-all-paths (eqdec-is-set eqdecA y x) p q) singleton : ∀ A → set singleton x = (nil :: x) , valid-singleton x add-carrier : list A → A → list A add-carrier l a with dec-∈-list eqdecA a l ... | inl _ = l ... | inr _ = l :: a add-valid : ∀ (s : set) a → valid (add-carrier (fst s) a) add-valid (l , valid-l) a x b b' with dec-∈-list eqdecA a l ... | inl x∈l = valid-l x b b' ... | inr x∉l with eqdecA x a add-valid (l , valid-l) a .a (inl x∈l) b' | inr x∉l | inl idp = ⊥-elim (x∉l x∈l) add-valid (l , valid-l) a .a (inr _) (inl x∈l) | inr x∉l | inl idp = ⊥-elim (x∉l x∈l) add-valid (l , valid-l) a .a (inr p) (inr q) | inr x∉l | inl idp = ap inr (is-prop-has-all-paths (eqdec-is-set eqdecA a a) p q) add-valid (l , valid-l) a x (inl x∈l) (inl x∈'l) | inr x∉l | inr _ = ap inl (valid-l x x∈l x∈'l) add-valid (l , valid-l) a x (inl x∈l) (inr x=a) | inr x∉l | inr x≠a = ⊥-elim (x≠a x=a) add-valid (l , valid-l) a x (inr x=a) b' | inr x∉l | inr x≠a = ⊥-elim (x≠a x=a) add : ∀ (s : set) → A → set add s a = add-carrier (fst s) a , add-valid s a _∈-set_ : A → set → Set i a ∈-set s = a ∈-list (fst s) has-all-paths-∈-set : ∀ a s → has-all-paths (a ∈-set s) has-all-paths-∈-set a s = snd s a is-prop-∈-set : ∀ a s → is-prop (a ∈-set s) is-prop-∈-set a s = has-all-paths-is-prop (has-all-paths-∈-set a s) add+ : set → list A → set add+ s nil = s add+ s (l :: a) = add (add+ s l) a -- -- Very inefficient implementation of the union of sets -- _∪-set_ : set → set → set -- s ∪-set s' = add+ s (fst s') set-of-list : list A → set set-of-list l = add+ Ø l -- -- being in the list or in its set are logically equivalent -- -- but being in the set is a proposition -- -- achieves the construction of propositional truncation in a reduced way ∈-set-∈-list : ∀ a l → a ∈-set set-of-list l → a ∈-list l ∈-set-∈-list a (l :: b) a∈s with dec-∈-list eqdecA b (fst (add+ Ø l)) ... | inl _ = inl (∈-set-∈-list a l a∈s) ... | inr _ with eqdecA a b ... | inl idp = inr idp ∈-set-∈-list a (l :: b) (inl a∈s) | inr _ | inr _ = inl (∈-set-∈-list a l a∈s) ∈-set-∈-list a (l :: b) (inr idp) | inr _ | inr b≠b = inl (⊥-elim (b≠b idp)) ∈-list-∈-set : ∀ a l → a ∈-list l → a ∈-set (set-of-list l) ∈-list-∈-set a (l :: b) a∈l+ with eqdecA a b ∈-list-∈-set a (l :: b) (inr a=b) | inr a≠b = ⊥-elim (a≠b a=b) ∈-list-∈-set a (l :: b) (inl a∈l) | inr a≠b with dec-∈-list eqdecA b (fst (add+ Ø l)) ... | inl _ = ∈-list-∈-set a l a∈l ... | inr _ = inl (∈-list-∈-set a l a∈l) ∈-list-∈-set a (l :: b) a∈l+ | inl idp with dec-∈-list eqdecA b (fst (add+ Ø l)) ... | inl a∈l = a∈l ... | inr _ = inr idp -- Note that these are not *really* sets : the order matters -- In particular the identity types are not correct _∪-set_ : set → set → set (s , _) ∪-set (s' , _) = set-of-list (s ++ s') _⊂_ : set → set → Set i A ⊂ B = ∀ x → x ∈-set A → x ∈-set B has-all-paths-→ : ∀ {i} (A B : Set i) → has-all-paths B → has-all-paths (A → B) has-all-paths-→ A B paths-B f g = funext f g (λ x → paths-B (f x) (g x)) has-all-paths-∀ : ∀ {i} (A : Set i) (B : A → Set i) → (∀ a → has-all-paths (B a)) → has-all-paths (∀ a → B a) has-all-paths-∀ A B paths-B f g = funext-dep f g λ a → paths-B a (f a) (g a) is-prop-→ : ∀ {i} A B → is-prop {i} B → is-prop (A → B) is-prop-→ A B prop-B = has-all-paths-is-prop (has-all-paths-→ A B (is-prop-has-all-paths prop-B)) is-prop-∀ : ∀ {i} (A : Set i) (B : A → Set i) → (∀ a → is-prop (B a)) → is-prop (∀ a → B a) is-prop-∀ A B prop-B = has-all-paths-is-prop (has-all-paths-∀ A B (λ a → is-prop-has-all-paths (prop-B a))) is-prop-⊂ : ∀ A B → is-prop (A ⊂ B) is-prop-⊂ A B = is-prop-∀ _ _ λ a → is-prop-→ _ _ (is-prop-∈-set a B) _≗_ : set → set → Set i A ≗ B = (A ⊂ B) × (B ⊂ A) has-all-paths-≗ : ∀ A B → has-all-paths (A ≗ B) has-all-paths-≗ A B (A⊂B , B⊂A) (A⊂'B , B⊂'A) = ,= (is-prop-has-all-paths (is-prop-⊂ A B) A⊂B A⊂'B) ((is-prop-has-all-paths (is-prop-⊂ B A) B⊂A B⊂'A)) is-prop-≗ : ∀ A B → is-prop (A ≗ B) is-prop-≗ A B = has-all-paths-is-prop (has-all-paths-≗ A B) dec-∈ : ∀ A a → dec (a ∈-set A) dec-∈ (A , _) a with dec-∈-list eqdecA a A ... | inl a∈A = inl a∈A ... | inr a∉A = inr a∉A ∈++₁ : ∀ l l' (a : A) → a ∈-list l → a ∈-list (l ++ l') ∈++₁ l nil a x = x ∈++₁ l (l' :: a₁) a x = inl (∈++₁ l l' a x) ∈++₂ : ∀ l l' (a : A) → a ∈-list l' → a ∈-list (l ++ l') ∈++₂ l (l' :: a₁) a (inl a∈l') = inl (∈++₂ l l' a a∈l') ∈++₂ l (l' :: a₁) a (inr idp) = inr idp ∈++ : ∀ l l' (a : A) → a ∈-list (l ++ l') → (a ∈-list l) + (a ∈-list l') ∈++ l nil a x = inl x ∈++ l (l' :: a₁) a (inl x) with ∈++ l l' a x ... | inl a∈l = inl a∈l ... | inr a∈l' = inr (inl a∈l') ∈++ l (l' :: a₁) a (inr p) = inr (inr p) ∈-∪₁ : ∀ {A B a} → a ∈-set A → (a ∈-set (A ∪-set B)) ∈-∪₁ {A , _} {B = nil , _} {a} a∈A = ∈-list-∈-set a (A ++ nil) a∈A ∈-∪₁ {A , _} {(B :: b) , _} {a} a∈A = ∈-list-∈-set a (A ++ (B :: b)) (inl (∈++₁ A B a a∈A)) ∈-∪₂ : ∀ {A B a} → a ∈-set B → (a ∈-set (A ∪-set B)) ∈-∪₂ {A , _} {B = nil , _} {a} () ∈-∪₂ {A , _} {(B :: b) , _} {a} (inl a∈B) = ∈-list-∈-set a (A ++ (B :: b)) (inl (∈++₂ A B a a∈B)) ∈-∪₂ {A , _} {(B :: b) , _} {a} (inr idp) = ∈-list-∈-set a (A ++ (B :: b)) (inr idp) ∉-∪ : ∀ {A B a} → ¬ (a ∈-set A) → ¬ (a ∈-set B) → ¬ (a ∈-set (A ∪-set B)) ∉-∪ {A , _} {B , _} {a} a∉A a∉B a∈A∪B with ∈++ A B a (∈-set-∈-list _ _ a∈A∪B) ... | inl x = a∉A x ... | inr x = a∉B x ∈-∪ : ∀ {A B a} → a ∈-set (A ∪-set B) → (a ∈-set A) + (a ∈-set B) ∈-∪ {A , _} {B , _} {a} a∈A∪B with ∈++ A B a (∈-set-∈-list _ _ a∈A∪B) ... | inl x = inl x ... | inr x = inr x ⊂-∪ : ∀ {A B C D} → A ⊂ B → C ⊂ D → (A ∪-set C) ⊂ (B ∪-set D) ⊂-∪ {A} {B} {C} {D} A⊂B C⊂D a a∈A∪C with dec-∈ A a | dec-∈ C a ... | inl a∈A | _ = ∈-∪₁ {B} {D} {a} (A⊂B _ a∈A) ... | inr a∉A | inl a∈C = ∈-∪₂ {B} {D} {a} (C⊂D _ a∈C) ... | inr a∉A | inr a∉C = ⊥-elim (∉-∪ {A} {C} {a} a∉A a∉C a∈A∪C) ∪-factor : ∀ A B C → (A ∪-set (B ∪-set C)) ≗ ((A ∪-set B) ∪-set (A ∪-set C)) fst (∪-factor A B C) x x∈A∪B∪C with ∈-∪ {A} {B ∪-set C} {x} x∈A∪B∪C ... | inl x∈A = ∈-∪₁ {A ∪-set B} {A ∪-set C} {x} (∈-∪₁ {A} {B} {x} x∈A) ... | inr x∈A∪B with ∈-∪ {B} {C} {x} x∈A∪B ... | inl x∈B = ∈-∪₁ {A ∪-set B} {A ∪-set C} {x} (∈-∪₂ {A} {B} {x} x∈B) ... | inr x∈C = ∈-∪₂ {A ∪-set B} {A ∪-set C} {x} (∈-∪₂ {A} {C} {x} x∈C) snd (∪-factor A B C) x x∈A∪B∪A∪C with ∈-∪ {A ∪-set B} {A ∪-set C} {x} x∈A∪B∪A∪C snd (∪-factor A B C) x x∈A∪B∪A∪C | inl x∈A∪B with ∈-∪ {A} {B} {x} x∈A∪B ... | inl x∈A = ∈-∪₁ {A} {B ∪-set C} {x} x∈A ... | inr x∈B = ∈-∪₂ {A} {B ∪-set C} {x} (∈-∪₁ {B} {C} {x} x∈B) snd (∪-factor A B C) x x∈A∪B∪A∪C | inr x∈A∪C with ∈-∪ {A} {C} {x} x∈A∪C ... | inl x∈A = ∈-∪₁ {A} {B ∪-set C} {x} x∈A ... | inr x∈C = ∈-∪₂ {A} {B ∪-set C} {x} (∈-∪₂ {B} {C} {x} x∈C) ≗-⊂ : ∀ {A B C} → A ≗ B → B ⊂ C → A ⊂ C ≗-⊂ (A⊂B , _) B⊂C _ a∈A = B⊂C _ (A⊂B _ a∈A) ⊂-trans : ∀ {A B C} → A ⊂ B → B ⊂ C → A ⊂ C ⊂-trans A⊂B B⊂C _ a∈A = B⊂C _ (A⊂B _ a∈A) ∈-singleton : ∀ a → a ∈-set (singleton a) ∈-singleton a = inr idp ∈-Ø : ∀ {x} → ¬ (x ∈-set Ø) ∈-Ø () A∪B⊂A∪B∪C : ∀ A B C → (A ∪-set B) ⊂ (A ∪-set (B ∪-set C)) A∪B⊂A∪B∪C A B C x x∈A∪B with ∈-∪ {A} {B} x∈A∪B ... | inl x∈A = ∈-∪₁ {A} {B ∪-set C} x∈A ... | inr x∈B = ∈-∪₂ {A} {B ∪-set C} (∈-∪₁ {B} {C} x∈B)
{ "alphanum_fraction": 0.4356836297, "avg_line_length": 40.775, "ext": "agda", "hexsha": "4ab95ea4ae4ba111765a0cb55f592176ba0ff27c", "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": "ed45935b38d6a86fa662f561866140122ee3dcef", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ThiBen/catt-formalization", "max_forks_repo_path": "Sets.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ed45935b38d6a86fa662f561866140122ee3dcef", "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": "ThiBen/catt-formalization", "max_issues_repo_path": "Sets.agda", "max_line_length": 152, "max_stars_count": 2, "max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thibautbenjamin/catt-formalization", "max_stars_repo_path": "Sets.agda", "max_stars_repo_stars_event_max_datetime": "2020-05-20T00:41:09.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-01T08:26:53.000Z", "num_tokens": 4248, "size": 8155 }
{-# OPTIONS --cubical --safe #-} module Algebra.Construct.Free.Semilattice.Relation.Unary.Membership where open import Prelude hiding (⊥; ⊤) open import Algebra.Construct.Free.Semilattice.Eliminators open import Algebra.Construct.Free.Semilattice.Definition open import Cubical.Foundations.HLevels open import Data.Empty.UniversePolymorphic open import HITs.PropositionalTruncation.Sugar open import HITs.PropositionalTruncation.Properties open import HITs.PropositionalTruncation open import Data.Unit.UniversePolymorphic open import Algebra.Construct.Free.Semilattice.Relation.Unary.Any.Def private variable p : Level infixr 5 _∈_ _∈_ : {A : Type a} → A → 𝒦 A → Type a x ∈ xs = ◇ (_≡ x) xs
{ "alphanum_fraction": 0.7994269341, "avg_line_length": 31.7272727273, "ext": "agda", "hexsha": "e8172ffbdadc89cbf7770c3232fbc56d27956f27", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z", "max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-playground", "max_forks_repo_path": "Algebra/Construct/Free/Semilattice/Relation/Unary/Membership.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Algebra/Construct/Free/Semilattice/Relation/Unary/Membership.agda", "max_line_length": 73, "max_stars_count": 6, "max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-playground", "max_stars_repo_path": "Algebra/Construct/Free/Semilattice/Relation/Unary/Membership.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 201, "size": 698 }
{-# OPTIONS --cubical --save-metas #-} open import Agda.Builtin.IO open import Agda.Builtin.String open import Agda.Builtin.Unit open import Erased-cubical-Pattern-matching-Cubical open import Erased-cubical-Pattern-matching-Erased postulate putStr : String → IO ⊤ {-# FOREIGN GHC import qualified Data.Text.IO #-} {-# COMPILE GHC putStr = Data.Text.IO.putStr #-} {-# COMPILE JS putStr = function (x) { return function(cb) { process.stdout.write(x); cb(0); }; } #-} main : IO ⊤ main = putStr (f c₁)
{ "alphanum_fraction": 0.6832061069, "avg_line_length": 23.8181818182, "ext": "agda", "hexsha": "a6a7c65e596440845524405ba172fd9fcfc85c35", "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": "b5b3b1657556f720a7310cb7744edb1fac71eaf4", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "Seanpm2001-Agda-lang/agda", "max_forks_repo_path": "test/Compiler/simple/Erased-cubical-Pattern-matching.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4", "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": "Seanpm2001-Agda-lang/agda", "max_issues_repo_path": "test/Compiler/simple/Erased-cubical-Pattern-matching.agda", "max_line_length": 51, "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/Compiler/simple/Erased-cubical-Pattern-matching.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": 147, "size": 524 }
------------------------------------------------------------------------------ -- Unary naturales numbers ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Data.Nat.UnaryNumbers where open import FOTC.Base ------------------------------------------------------------------------------ 0' = zero 1' = succ₁ 0' 2' = succ₁ 1' 3' = succ₁ 2' 4' = succ₁ 3' 5' = succ₁ 4' 6' = succ₁ 5' 7' = succ₁ 6' 8' = succ₁ 7' 9' = succ₁ 8' {-# ATP definitions 0' 1' 2' 3' 4' 5' 6' 7' 8' 9' #-} 10' = succ₁ 9' 11' = succ₁ 10' 12' = succ₁ 11' 13' = succ₁ 12' 14' = succ₁ 13' 15' = succ₁ 14' 16' = succ₁ 15' 17' = succ₁ 16' 18' = succ₁ 17' 19' = succ₁ 18' {-# ATP definition 10' 11' 12' 13' 14' 15' 16' 17' 18' 19' #-} 20' = succ₁ 19' 21' = succ₁ 20' 22' = succ₁ 21' 23' = succ₁ 22' 24' = succ₁ 23' 25' = succ₁ 24' 26' = succ₁ 25' 27' = succ₁ 26' 28' = succ₁ 27' 29' = succ₁ 28' {-# ATP definition 20' 21' 22' 23' 24' 25' 26' 27' 28' 29' #-} 30' = succ₁ 29' 31' = succ₁ 30' 32' = succ₁ 31' 33' = succ₁ 32' 34' = succ₁ 33' 35' = succ₁ 34' 36' = succ₁ 35' 37' = succ₁ 36' 38' = succ₁ 37' 39' = succ₁ 38' {-# ATP definition 30' 31' 32' 33' 34' 35' 36' 37' 38' 39' #-} 40' = succ₁ 39' 41' = succ₁ 40' 42' = succ₁ 41' 43' = succ₁ 42' 44' = succ₁ 43' 45' = succ₁ 44' 46' = succ₁ 45' 47' = succ₁ 46' 48' = succ₁ 47' 49' = succ₁ 48' {-# ATP definition 40' 41' 42' 43' 44' 45' 46' 47' 48' 49' #-} 50' = succ₁ 49' 51' = succ₁ 50' 52' = succ₁ 51' 53' = succ₁ 52' 54' = succ₁ 53' 55' = succ₁ 54' 56' = succ₁ 55' 57' = succ₁ 56' 58' = succ₁ 57' 59' = succ₁ 58' {-# ATP definition 50' 51' 52' 53' 54' 55' 56' 57' 58' 59' #-} 60' = succ₁ 59' 61' = succ₁ 60' 62' = succ₁ 61' 63' = succ₁ 62' 64' = succ₁ 63' 65' = succ₁ 64' 66' = succ₁ 65' 67' = succ₁ 66' 68' = succ₁ 67' 69' = succ₁ 68' {-# ATP definition 60' 61' 62' 63' 64' 65' 66' 67' 68' 69' #-} 70' = succ₁ 69' 71' = succ₁ 70' 72' = succ₁ 71' 73' = succ₁ 72' 74' = succ₁ 73' 75' = succ₁ 74' 76' = succ₁ 75' 77' = succ₁ 76' 78' = succ₁ 77' 79' = succ₁ 78' {-# ATP definition 70' 71' 72' 73' 74' 75' 76' 77' 78' 79' #-} 80' = succ₁ 79' 81' = succ₁ 80' 82' = succ₁ 81' 83' = succ₁ 82' 84' = succ₁ 83' 85' = succ₁ 84' 86' = succ₁ 85' 87' = succ₁ 86' 88' = succ₁ 87' 89' = succ₁ 88' {-# ATP definition 80' 81' 82' 83' 84' 85' 86' 87' 88' 89' #-} 90' = succ₁ 89' 91' = succ₁ 90' 92' = succ₁ 91' 93' = succ₁ 92' 94' = succ₁ 93' 95' = succ₁ 94' 96' = succ₁ 95' 97' = succ₁ 96' 98' = succ₁ 97' 99' = succ₁ 98' {-# ATP definition 90' 91' 92' 93' 94' 95' 96' 97' 98' 99' #-} 100' = succ₁ 99' 101' = succ₁ 100' 102' = succ₁ 101' 103' = succ₁ 102' 104' = succ₁ 103' 105' = succ₁ 104' 106' = succ₁ 105' 107' = succ₁ 106' 108' = succ₁ 107' 109' = succ₁ 108' {-# ATP definition 100' 101' 102' 103' 104' 105' 106' 107' 108' 109' #-} 110' = succ₁ 109' 111' = succ₁ 110' {-# ATP definition 110' 111' #-}
{ "alphanum_fraction": 0.505897772, "avg_line_length": 18.8395061728, "ext": "agda", "hexsha": "04540d89c7520754acbc944ffa8586e5afc8a01a", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Data/Nat/UnaryNumbers.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Data/Nat/UnaryNumbers.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Data/Nat/UnaryNumbers.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 1350, "size": 3052 }
{-# OPTIONS --universe-polymorphism #-} module Support.FinSet where open import Support open import Support.Nat unbound : ∀ {n} (m : Fin n) → ℕ unbound zero = zero unbound {suc n} (suc y) = suc (unbound {n} y) .Fin-is-bounded : ∀ (n : ℕ) (m : Fin n) → (unbound m < n) Fin-is-bounded .(suc n) (zero {n}) = Z<Sn Fin-is-bounded .(suc n) (suc {n} y) = raise< (Fin-is-bounded n y) enlarge : ∀ {a} (b : Fin (suc a)) (c : Fin (unbound b)) → Fin a enlarge {zero} zero () enlarge {zero} (suc ()) c enlarge {suc a′} zero () enlarge {suc a′} (suc b′) zero = zero enlarge {suc a′} (suc b′) (suc c′) = suc (enlarge b′ c′) widen-by : ∀ {a} {b} (a≤b : a < suc b) (c : Fin a) → Fin b widen-by Z<Sn () widen-by (raise< Z<Sn) zero = zero widen-by (raise< (raise< n<m)) zero = zero widen-by (raise< Z<Sn) (suc ()) widen-by (raise< (raise< n<m)) (suc y') = suc (widen-by (raise< n<m) y') widen-+ : (b : ℕ) → ∀ {a} (c : Fin a) → Fin (a + b) widen-+ b zero = zero widen-+ b (suc y) = suc (widen-+ b y) shift : (a : ℕ) → ∀ {b} (c : Fin b) → Fin (a + b) shift zero c = c shift (suc y) c = suc (shift y c) _bounded-by_ : (m : ℕ) → ∀ {n} (m<n : m < n) → Fin n .0 bounded-by Z<Sn = zero .(suc n) bounded-by (raise< {n} n<m) = suc (n bounded-by n<m) unbound-unbounds-bounded-by : ∀ (m n : ℕ) (m<n : m < n) → unbound (m bounded-by m<n) ≣ m unbound-unbounds-bounded-by .0 .(suc n) (Z<Sn {n}) = ≣-refl unbound-unbounds-bounded-by .(suc n) .(suc m) (raise< {n} {m} n<m) = ≣-cong suc (unbound-unbounds-bounded-by n m n<m) _lessen_ : (n : ℕ) → (m : Fin (suc n)) → ℕ n lessen zero = n .0 lessen suc {zero} () .(suc y) lessen suc {suc y} y' = y lessen y' lessen-is-subtraction₁ : ∀ (n : ℕ) (m : Fin (suc n)) → (unbound m + (n lessen m)) ≣ n lessen-is-subtraction₁ n zero = ≣-refl lessen-is-subtraction₁ .0 (suc {zero} ()) lessen-is-subtraction₁ .(suc y) (suc {suc y} y') = ≣-cong suc (lessen-is-subtraction₁ y y') lessen-is-subtraction₂ : ∀ (n m : ℕ) → ((n + m) lessen (n bounded-by (+-is-nondecreasingʳ n m)) ≣ m) lessen-is-subtraction₂ zero m = ≣-refl lessen-is-subtraction₂ (suc y) m = lessen-is-subtraction₂ y m _split_ : ∀ {n} (k : Fin n) (m : Fin (suc n)) → Either (Fin (unbound m)) (Fin (n lessen m)) k split zero = inr k zero split suc y = inl zero suc y split suc y' = left suc (y split y') _chops_ : (n : ℕ) → ∀ {m} (k : Fin (n + m)) → Either (Fin n) (Fin m) 0 chops k = inr k suc n chops zero = inl zero suc n chops suc k = left suc (n chops k) rejoin-chops : (n m : ℕ) (k : Fin (n + m)) → either₀ (widen-+ m) (shift n) (n chops k) ≣ k rejoin-chops zero _ _ = ≣-refl rejoin-chops (suc _) _ zero = ≣-refl rejoin-chops (suc n') m (suc k') with n' chops k' | rejoin-chops n' m k' rejoin-chops (suc _) _ (suc ._) | inl _ | ≣-refl = ≣-refl rejoin-chops (suc _) _ (suc ._) | inr _ | ≣-refl = ≣-refl chop-widen-+ : (n m : ℕ) (k : Fin n) → n chops widen-+ m k ≣ inl k chop-widen-+ zero _ () chop-widen-+ (suc n') _ zero = ≣-refl chop-widen-+ (suc n') m (suc k') with n' chops widen-+ m k' | chop-widen-+ n' m k' chop-widen-+ (suc n') m (suc ._) | inl k' | ≣-refl = ≣-refl chop-widen-+ (suc n') m (suc _) | inr _ | () chop-shift : (n m : ℕ) (k : Fin m) → n chops shift n k ≣ inr k chop-shift zero m k = ≣-refl chop-shift (suc n') m k = ≣-cong (left suc) (chop-shift n' m k) _cat₀_ : ∀ {ℓ} {n m} {A : Set ℓ} (f : Fin n → A) (g : Fin m → A) → Fin (n + m) → A _cat₀_ {n = n} {m} f g i = either₀ f g (n chops i) ∙-dist-cat₀ : ∀ {ℓ ℓ′} {n m} {A : Set ℓ} {A′ : Set ℓ′} (f : Fin n → A) (g : Fin m → A) (h : A → A′) {i : Fin (n + m)} → (h ∙ (f cat₀ g)) i ≣ ((h ∙ f) cat₀ (h ∙ g)) i ∙-dist-cat₀ {n = n} {A′ = A′} f g h {i} = answer where open ≣-reasoning A′ split-i = n chops i answer = begin ((h ∙ (f cat₀ g)) i) ≈⟨ ≣-refl ⟩ (h ((f cat₀ g) i)) ≈⟨ ≣-cong h ≣-refl ⟩ h (either₀ f g split-i) ≈⟨ ≣-refl ⟩ (h ∙ either₀ f g) split-i ≈⟨ ∙-dist-either₀ f g h {split-i} ⟩ either₀ (h ∙ f) (h ∙ g) split-i ≈⟨ ≣-refl ⟩ ((h ∙ f) cat₀ (h ∙ g)) i ∎ _cat_ : ∀ {ℓ} {n m} {A : Fin n → Set ℓ} {B : Fin m → Set ℓ} (f : (i : Fin n) → A i) (g : (j : Fin m) → B j) → (k : Fin (n + m)) → (A cat₀ B) k _cat_ {n = n} f g i = either f g (n chops i) _cat′_ : ∀ {ℓ} {n m} {A : Fin (n + m) → Set ℓ} (f : (i : Fin n) → A (widen-+ m i)) (g : (j : Fin m) → A (shift n j)) → (k : Fin (n + m)) → A k _cat′_ {n = n} {m = m} {A = T} f g k = ≣-subst T (rejoin-chops n m k) (either′ {A = T ∙ either₀ (widen-+ m) (shift n)} f g (n chops k)) _✂_ : ∀ {n} (m : Fin (suc n)) {ℓ} {A : Set ℓ} (f : Fin n → A) → (Fin (unbound m) → A) × (Fin (n lessen m) → A) _✂_ {n = n} m f = f ∙ enlarge m , f ∙ (≣-subst Fin (lessen-is-subtraction₁ n m) ∙ shift (unbound m)) _✂₀′_ : (m : ℕ) → ∀ {ℓ} {A : Set ℓ} {n} (f : Fin (m + n) → A) → (Fin m → A) × (Fin n → A) _✂₀′_ m {n = n} f = f ∙ widen-+ n , f ∙ shift m _✂′_ : (m : ℕ) → ∀ {ℓ} {n} {A : Fin (m + n) → Set ℓ} (f : (k : Fin (m + n)) → A k) → uncurry₀ _×_ (⟨ (λ Aˡ → (i : Fin m) → Aˡ i) , (λ Aʳ → (j : Fin n) → Aʳ j) ⟩ (m ✂₀′ A)) _✂′_ m {n = n} f = f ∙ widen-+ n , f ∙ shift m
{ "alphanum_fraction": 0.5219988055, "avg_line_length": 40.5080645161, "ext": "agda", "hexsha": "325b1c857aed11ec840e159d94dcbea6332c8070", "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/Support/FinSet.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/Support/FinSet.agda", "max_line_length": 171, "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/Support/FinSet.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": 2356, "size": 5023 }
------------------------------------------------------------------------------ -- Miscellaneous properties ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.SortList.Properties.MiscellaneousI where open import Common.FOL.Relation.Binary.EqReasoning open import FOTC.Base open import FOTC.Base.List open import FOTC.Data.Bool open import FOTC.Data.Bool.PropertiesI open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.List.PropertiesI open import FOTC.Data.Nat.List.Type open import FOTC.Data.Nat.Type open import FOTC.Data.List open import FOTC.Data.List.PropertiesI open import FOTC.Program.SortList.Properties.Totality.BoolI open import FOTC.Program.SortList.SortList ------------------------------------------------------------------------------ -- This is a weird result but recall that "the relation ≤ between -- lists is only an ordering if nil is excluded" (Burstall 1969, -- p. 46). -- xs≤[] : ∀ {is} → ListN is → OrdList is → LE-Lists is [] -- xs≤[] lnnil _ = ≤-Lists-[] [] -- xs≤[] (lncons {i} {is} Ni LNis) LOconsL = -- begin -- ≤-Lists (i ∷ is) [] -- ≡⟨ ≤-Lists-∷ i is [] ⟩ -- ≤-ItemList i [] && ≤-Lists is [] -- ≡⟨ subst (λ t → ≤-ItemList i [] && ≤-Lists is [] ≡ t && ≤-Lists is []) -- (≤-ItemList-[] i) -- refl -- ⟩ -- true && ≤-Lists is [] -- ≡⟨ subst (λ t → true && ≤-Lists is [] ≡ true && t) -- (xs≤[] LNis (subList-OrdList Ni LNis LOconsL)) -- refl -- ⟩ -- true && true -- ≡⟨ &&-tt ⟩ -- true -- ∎ x≤ys++zs→x≤zs : ∀ {i js ks} → N i → ListN js → ListN ks → ≤-ItemList i (js ++ ks) → ≤-ItemList i ks x≤ys++zs→x≤zs {i} {ks = ks} Ni lnnil LNks i≤[]++ks = subst (≤-ItemList i) (++-leftIdentity ks) i≤[]++ks x≤ys++zs→x≤zs {i} {ks = ks} Ni (lncons {j} {js} Nj LNjs) LNks i≤j∷js++ks = x≤ys++zs→x≤zs Ni LNjs LNks lemma₂ where lemma₁ : le i j && le-ItemList i (js ++ ks) ≡ true lemma₁ = le i j && le-ItemList i (js ++ ks) ≡⟨ sym (le-ItemList-∷ i j (js ++ ks)) ⟩ le-ItemList i (j ∷ (js ++ ks)) ≡⟨ subst (λ t → le-ItemList i (j ∷ (js ++ ks)) ≡ le-ItemList i t) (sym (++-∷ j js ks)) refl ⟩ le-ItemList i ((j ∷ js) ++ ks) ≡⟨ i≤j∷js++ks ⟩ true ∎ lemma₂ : ≤-ItemList i (js ++ ks) lemma₂ = &&-list₂-t₂ (le-Bool Ni Nj) (le-ItemList-Bool Ni (++-ListN LNjs LNks)) lemma₁ xs++ys-OrdList→xs≤ys : ∀ {is js} → ListN is → ListN js → OrdList (is ++ js) → ≤-Lists is js xs++ys-OrdList→xs≤ys {js = js} lnnil LNjs OLis++js = le-Lists-[] js xs++ys-OrdList→xs≤ys {js = js} (lncons {i} {is} Ni LNis) LNjs OLis++js = le-Lists (i ∷ is) js ≡⟨ le-Lists-∷ i is js ⟩ le-ItemList i js && le-Lists is js ≡⟨ subst (λ t → le-ItemList i js && le-Lists is js ≡ t && le-Lists is js) (x≤ys++zs→x≤zs Ni LNis LNjs lemma₁) refl ⟩ true && le-Lists is js ≡⟨ subst (λ t → true && le-Lists is js ≡ true && t) (xs++ys-OrdList→xs≤ys LNis LNjs lemma₂) --IH. refl ⟩ true && true ≡⟨ t&&x≡x true ⟩ true ∎ where lemma₀ : le-ItemList i (is ++ js) && ordList (is ++ js) ≡ true lemma₀ = trans (sym (ordList-∷ i (is ++ js))) (trans (subst (λ t → ordList (i ∷ is ++ js) ≡ ordList t) (sym (++-∷ i is js)) refl) OLis++js) helper₁ : Bool (le-ItemList i (is ++ js)) helper₁ = le-ItemList-Bool Ni (++-ListN LNis LNjs) helper₂ : Bool (ordList (is ++ js)) helper₂ = ordList-Bool (++-ListN LNis LNjs) lemma₁ : le-ItemList i (is ++ js) ≡ true lemma₁ = &&-list₂-t₁ helper₁ helper₂ lemma₀ lemma₂ : ordList (is ++ js) ≡ true lemma₂ = &&-list₂-t₂ helper₁ helper₂ lemma₀ x≤ys→x≤zs→x≤ys++zs : ∀ {i js ks} → N i → ListN js → ListN ks → ≤-ItemList i js → ≤-ItemList i ks → ≤-ItemList i (js ++ ks) x≤ys→x≤zs→x≤ys++zs {i} {ks = ks} Ni lnnil LNks _ i≤k = subst (≤-ItemList i) (sym (++-leftIdentity ks)) i≤k x≤ys→x≤zs→x≤ys++zs {i} {ks = ks} Ni (lncons {j} {js} Nj LNjs) LNks i≤j∷js i≤k = le-ItemList i ((j ∷ js) ++ ks) ≡⟨ subst (λ t → le-ItemList i ((j ∷ js) ++ ks) ≡ le-ItemList i t) (++-∷ j js ks) refl ⟩ le-ItemList i (j ∷ (js ++ ks)) ≡⟨ le-ItemList-∷ i j (js ++ ks) ⟩ le i j && le-ItemList i (js ++ ks) ≡⟨ subst₂ (λ t₁ t₂ → le i j && le-ItemList i (js ++ ks) ≡ t₁ && t₂) (&&-list₂-t₁ helper₁ helper₂ helper₃) (x≤ys→x≤zs→x≤ys++zs Ni LNjs LNks (&&-list₂-t₂ helper₁ helper₂ helper₃) i≤k) refl ⟩ true && true ≡⟨ t&&x≡x true ⟩ true ∎ where helper₁ : Bool (le i j) helper₁ = le-Bool Ni Nj helper₂ : Bool (le-ItemList i js) helper₂ = le-ItemList-Bool Ni LNjs helper₃ : le i j && (le-ItemList i js) ≡ true helper₃ = trans (sym (le-ItemList-∷ i j js)) i≤j∷js xs≤ys→xs≤zs→xs≤ys++zs : ∀ {is js ks} → ListN is → ListN js → ListN ks → ≤-Lists is js → ≤-Lists is ks → ≤-Lists is (js ++ ks) xs≤ys→xs≤zs→xs≤ys++zs lnnil LNjs LNks _ _ = le-Lists-[] _ xs≤ys→xs≤zs→xs≤ys++zs {js = js} {ks} (lncons {i} {is} Ni LNis) LNjs LNks i∷is≤js i∷is≤ks = le-Lists (i ∷ is) (js ++ ks) ≡⟨ le-Lists-∷ i is (js ++ ks) ⟩ le-ItemList i (js ++ ks) && le-Lists is (js ++ ks) ≡⟨ subst (λ t → le-ItemList i (js ++ ks) && le-Lists is (js ++ ks) ≡ t && le-Lists is (js ++ ks)) (x≤ys→x≤zs→x≤ys++zs Ni LNjs LNks (&&-list₂-t₁ helper₁ helper₂ helper₃) (&&-list₂-t₁ helper₄ helper₅ helper₆)) refl ⟩ true && le-Lists is (js ++ ks) ≡⟨ subst (λ t → true && le-Lists is (js ++ ks) ≡ true && t) (xs≤ys→xs≤zs→xs≤ys++zs LNis LNjs LNks (&&-list₂-t₂ helper₁ helper₂ helper₃) (&&-list₂-t₂ helper₄ helper₅ helper₆)) refl ⟩ true && true ≡⟨ t&&x≡x true ⟩ true ∎ where helper₁ = le-ItemList-Bool Ni LNjs helper₂ = le-Lists-Bool LNis LNjs helper₃ = trans (sym (le-Lists-∷ i is js)) i∷is≤js helper₄ = le-ItemList-Bool Ni LNks helper₅ = le-Lists-Bool LNis LNks helper₆ = trans (sym (le-Lists-∷ i is ks)) i∷is≤ks xs≤zs→ys≤zs→xs++ys≤zs : ∀ {is js ks} → ListN is → ListN js → ListN ks → ≤-Lists is ks → ≤-Lists js ks → ≤-Lists (is ++ js) ks xs≤zs→ys≤zs→xs++ys≤zs {js = js} {ks} lnnil LNjs LNks is≤ks js≤ks = subst (λ t → ≤-Lists t ks) (sym (++-leftIdentity js)) js≤ks xs≤zs→ys≤zs→xs++ys≤zs {js = js} {ks} (lncons {i} {is} Ni LNis) LNjs LNks i∷is≤ks js≤ks = le-Lists ((i ∷ is) ++ js) ks ≡⟨ subst (λ t → le-Lists ((i ∷ is) ++ js) ks ≡ le-Lists t ks) (++-∷ i is js) refl ⟩ le-Lists (i ∷ (is ++ js)) ks ≡⟨ le-Lists-∷ i (is ++ js) ks ⟩ le-ItemList i ks && le-Lists (is ++ js) ks ≡⟨ subst₂ (λ x y → le-ItemList i ks && le-Lists (is ++ js) ks ≡ x && y) ≤-ItemList-i-ks ≤-Lists-is++js-ks refl ⟩ true && true ≡⟨ t&&x≡x true ⟩ true ∎ where helper₁ = le-ItemList-Bool Ni LNks helper₂ = le-Lists-Bool LNis LNks helper₃ = trans (sym (le-Lists-∷ i is ks)) i∷is≤ks ≤-ItemList-i-ks : ≤-ItemList i ks ≤-ItemList-i-ks = &&-list₂-t₁ helper₁ helper₂ helper₃ ≤-Lists-is++js-ks : ≤-Lists (is ++ js) ks ≤-Lists-is++js-ks = xs≤zs→ys≤zs→xs++ys≤zs LNis LNjs LNks (&&-list₂-t₂ helper₁ helper₂ helper₃) js≤ks ------------------------------------------------------------------------------ -- References -- -- Burstall, R. M. (1969). Proving properties of programs by -- structural induction. The Computer Journal 12.1, pp. 41–48.
{ "alphanum_fraction": 0.4748510131, "avg_line_length": 36.008583691, "ext": "agda", "hexsha": "1dd786b98dec4a0fbd57f028c21054090a0789eb", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Program/SortList/Properties/MiscellaneousI.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Program/SortList/Properties/MiscellaneousI.agda", "max_line_length": 79, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Program/SortList/Properties/MiscellaneousI.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 3058, "size": 8390 }
-- We use Kalmar's lemma to show completeness. See -- https://iep.utm.edu/prop-log/ -- http://comet.lehman.cuny.edu/mendel/Adlogic/sem5.pdf {-# OPTIONS --without-K --safe #-} module Kalmar where -- imports from stdlib. import Data.Empty as DE open import Data.Bool using (Bool ; not ; false ; true) open import Data.Nat using (ℕ ; _≟_) open import Data.Nat.Properties using (≡-decSetoid) open import Data.Product renaming (_,_ to _,'_) using (_×_) open import Data.List using (List ; map ; _++_ ; deduplicate ; _∷_ ; []) open import Data.List.Relation.Unary.Unique.DecSetoid ≡-decSetoid using (Unique ; [] ; _∷_) open import Data.List.Membership.DecPropositional _≟_ renaming (_∈_ to _∈ℕ_) using (_∉_) open import Relation.Nullary as RN using (yes ; no) open import Data.List.Relation.Unary.Any using (Any ; here ; there) open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; cong₂) -- imports from my files. open import PropLogic -- ---------------------------------------------------------------------- -- Inspect. -- When "f x" evaluates to some "y", pattern matching on "Inspect (f -- x)" gives "y" and the proof that "f x ≡ y". We use this vesion of -- inspect instead of the one in PropositionalEquality for convenience. data Inspect {A : Set}(x : A) : Set where it : (y : A) -> x ≡ y -> Inspect x inspect : {A : Set}(x : A) -> Inspect x inspect x = it x refl -- ---------------------------------------------------------------------- -- Definitons and lemmas. -- Fix a formula by possibly negating it such that under the given -- assignment, the fixed formula is true. fix-formula : Assign -> Formula -> Formula fix-formula a f with interp a f ... | true = f ... | false = ¬ f -- Fix a symbol by possibly negating it such that under the given -- assignment, the fixed symbol is true. We call a natural number a -- "symbol". (Recall P n is the nth propositional symbol) fix-sym : Assign -> ℕ -> Formula fix-sym a n with a n ... | true = P n ... | false = ¬ (P n) -- Given an assignment and a list of symbols, return a context -- consisting of "fixed symbols". We call a list of natural numbers -- "symbol context" or "sctx". (recall context is a list of -- formulas) fix-sctx : Assign -> List ℕ -> Context fix-sctx a = map (fix-sym a) -- Given an assignment "a", and a symbol "v", return an new -- assignment that negate "a v", and is the same as "a" in all other -- symbols. negate-assign-at : Assign -> ℕ -> (ℕ -> Bool) negate-assign-at a m n with m ≟ n ... | no ¬p = a n ... | yes p = not (a n) -- Lemmas about negate-assign-at. lemma1-negate-assign-at : ∀ {a m n} -> RN.¬ (m ≡ n) -> negate-assign-at a m n ≡ a n lemma1-negate-assign-at {a} {m} {n} neq with (m ≟ n) ... | yes p = DE.⊥-elim (neq p) ... | no _ = refl lemma2-negate-assign-at : ∀ {a m n} -> (m ≡ n) -> negate-assign-at a m n ≡ not (a n) lemma2-negate-assign-at {a} {m} {.m} refl with m ≟ m ... | no ¬p = DE.⊥-elim (¬p refl) ... | yes p = refl lemma-fix-sym : ∀ {a m n} -> RN.¬ m ≡ n -> fix-sym (negate-assign-at a m) n ≡ fix-sym a n lemma-fix-sym {a} {m} {n} neq rewrite lemma1-negate-assign-at {a} {m} {n} neq = refl lemma-fix-sym-neg : ∀ {a n} -> (a n ≡ false) -> fix-sym (negate-assign-at a n) n ≡ (P n) lemma-fix-sym-neg {a} {n} eq with lemma2-negate-assign-at {a} {n} {n} refl ... | hyp rewrite hyp | eq = refl lemma-fix-sym-pos : ∀ {a n} -> (a n ≡ true) -> fix-sym (negate-assign-at a n) n ≡ ¬ (P n) lemma-fix-sym-pos {a} {n} eq with lemma2-negate-assign-at {a} {n} {n} refl ... | hyp rewrite hyp | eq = refl -- A lemma about fix-sctx. lemma-fix-sctx : ∀ {a ns n} -> n ∉ ns -> fix-sctx (negate-assign-at a n) ns ≡ fix-sctx a ns lemma-fix-sctx {a} {Empty} {n} nin = refl lemma-fix-sctx {a} {ns , x} {n} nin = cong₂ _,_ (lemma-fix-sctx n∉ns) (lemma-fix-sym claim) where open import Data.List.Relation.Unary.Any using (there ; here) n∉ns : n ∉ ns n∉ns = λ x₁ → nin (there x₁) claim : RN.¬ n ≡ x claim = λ x₁ → nin (here x₁) -- Given a formula, return the list of all the symbol in it -- (allowing repeation). syms-of-formula : Formula -> List ℕ syms-of-formula (P x) = x ∷ [] syms-of-formula (A ∧ B) = (syms-of-formula A) ++ (syms-of-formula B) syms-of-formula (A ⇒ B) = (syms-of-formula A) ++ (syms-of-formula B) syms-of-formula ⊥ = [] syms-of-formula ⊤ = [] syms-of-formula (¬ f) = syms-of-formula f syms-of-formula (A ∨ B) = (syms-of-formula A) ++ (syms-of-formula B) -- De Morgan's law. demorg : ∀ {Γ A B} -> Γ ⊢ (¬ A) ∧ (¬ B) -> Γ ⊢ ¬ (A ∨ B) demorg der = ¬-intro (∨-elim (assump ∈-base) (¬-elim (∧-elim1 (weakening der (λ z → ∈-step (∈-step z)))) (assump ∈-base)) ((¬-elim (∧-elim2 (weakening der (λ z → ∈-step (∈-step z)))) (assump ∈-base)))) demorg1 : ∀ {Γ A B} -> Γ ⊢ (¬ A) ∨ (¬ B) -> Γ ⊢ ¬ (A ∧ B) demorg1 der = ¬-intro (∨-elim (weakening der ∈-step) (¬-elim (assump ∈-base) (∧-elim1 (assump (∈-step ∈-base)))) ((¬-elim (assump ∈-base) (∧-elim2 (assump (∈-step ∈-base)))))) -- Implication with a null hypothesis is always syntactically valid. null-hyp : ∀ {Γ A B} -> Γ ⊢ (¬ A) -> Γ ⊢ A ⇒ B null-hyp der = ⇒-intro (⊥-elim (¬-elim (weakening der ∈-step) (assump ∈-base))) -- Implication with a null conclusion is always syntactically invalid. null-conclusion : ∀ {Γ A B} -> Γ ⊢ A -> Γ ⊢ (¬ B) -> Γ ⊢ ¬ (A ⇒ B) null-conclusion der1 der2 = ¬-intro (¬-elim (weakening der2 ∈-step) (⇒-elim (assump ∈-base) (weakening der1 ∈-step))) -- Double negation of "A" is valid if "A" is valid. double-negate : ∀ {Γ A} -> Γ ⊢ A -> Γ ⊢ ¬ (¬ A) double-negate der = ¬-intro (¬-elim (assump ∈-base) (weakening der ∈-step)) -- ---------------------------------------------------------------------- -- List containment. -- In file "Logic", membership and context containment are defined -- similarly but differently from the one in stdlib. we have to do a -- translation. infix 3 _⊂_ _⊂_ : List ℕ -> List ℕ -> Set xs ⊂ ys = ∀ {x} -> x ∈ℕ xs -> x ∈ℕ ys -- Lemma: membership is functorial. lemma-fix-sym-∈ : ∀ {ρ} {x} {ys} -> x ∈ℕ ys -> fix-sym ρ x ∈ fix-sctx ρ ys lemma-fix-sym-∈ {ρ} {x} {.(_ , x₁)} (here {x₁} px) rewrite px = ∈-base lemma-fix-sym-∈ {ρ} {x} {.(xs , x₁)} (there {x₁} {xs} hyp) = ∈-step (lemma-fix-sym-∈ hyp) -- Lemma: removing the head element preserves containment. lemma-⊂-rh : ∀ {x : ℕ} {xs ys} -> (x ∷ xs) ⊂ ys -> xs ⊂ ys lemma-⊂-rh {x} {.(_ , _)} {ys} sub (here px) rewrite px = sub (there (here refl)) lemma-⊂-rh {x} {.(_ , _)} {ys} sub (there hyp) = sub (there (there hyp)) -- Lemma: List containment is functorial. lemma-map : ∀ {ρ xs ys} -> xs ⊂ ys -> fix-sctx ρ xs ⊆ fix-sctx ρ ys lemma-map {ρ} {Empty} {ys} sub = λ {()} lemma-map {ρ} {xs , x} {ys} sub = λ { ∈-base → lemma-fix-sym-∈ (sub (here refl)) ; (∈-step x₁) → lemma-map (lemma-⊂-rh sub) x₁} -- ---------------------------------------------------------------------- -- Kalmar's Lemma. mutual -- We use aux to abstract over similar codes. aux : ∀ ρ F G -> let Γ = fix-sctx ρ (syms-of-formula F ++ syms-of-formula G) in Γ ⊢ (fix-formula ρ F) × Γ ⊢ (fix-formula ρ G) aux ρ F G = let vl = syms-of-formula F in let vr = syms-of-formula G in weakening (lemma-Kalmar {F} ρ) (lemma-map {ρ} {vl} {vl ++ vr} ∈-++⁺ˡ) ,' weakening (lemma-Kalmar {G} ρ) (lemma-map {ρ} {vr} {vl ++ vr} (∈-++⁺ʳ vl {ys = vr})) where open import Data.List.Membership.Propositional.Properties using (∈-++⁺ˡ ; ∈-++⁺ʳ) lemma-Kalmar : ∀ {F} ρ -> fix-sctx ρ (syms-of-formula F) ⊢ fix-formula ρ F lemma-Kalmar {P x} ρ with ρ x ... | true = assump ∈-base ... | false = assump ∈-base lemma-Kalmar {F ∧ F₁} ρ with inspect (interp ρ F) | inspect (interp ρ F₁) | aux ρ F F₁ ... | it false x | it false x₁ | iha ,' ihb rewrite x | x₁ = demorg1 (∨-intro2 ihb) ... | it false x | it true x₁ | iha ,' ihb rewrite x | x₁ = demorg1 (∨-intro1 iha) ... | it true x | it false x₁ | iha ,' ihb rewrite x | x₁ = demorg1 (∨-intro2 ihb) ... | it true x | it true x₁ | iha ,' ihb rewrite x | x₁ = ∧-intro iha ihb lemma-Kalmar {F ⇒ F₁} ρ with inspect (interp ρ F) | inspect (interp ρ F₁) | aux ρ F F₁ ... | it true x | it true x₁ | iha ,' ihb rewrite x | x₁ = ⇒-intro (weakening ihb ∈-step) ... | it false x | it true x₁ | iha ,' ihb rewrite x | x₁ = ⇒-intro (weakening ihb ∈-step) ... | it true x | it false x₁ | iha ,' ihb rewrite x | x₁ = null-conclusion iha ihb ... | it false x | it false x₁ | iha ,' ihb rewrite x | x₁ = null-hyp iha lemma-Kalmar {F ∨ F₁} ρ with inspect (interp ρ F) | inspect (interp ρ F₁) | aux ρ F F₁ ... | it true x | it true x₁ | iha ,' ihb rewrite x | x₁ = ∨-intro1 iha ... | it false x | it true x₁ | iha ,' ihb rewrite x | x₁ = ∨-intro2 ihb ... | it true x | it false x₁ | iha ,' ihb rewrite x | x₁ = ∨-intro1 iha ... | it false x | it false x₁ | iha ,' ihb rewrite x | x₁ = demorg (∧-intro iha ihb) lemma-Kalmar {⊥} ρ = ¬-intro (assump ∈-base) lemma-Kalmar {⊤} ρ = ⊤-intro lemma-Kalmar {¬ F} ρ with inspect (interp ρ F) | lemma-Kalmar {F} ρ ... | it false x | ih rewrite x = ih ... | it true x | ih rewrite x = double-negate ih -- ---------------------------------------------------------------------- -- Unique symbol context. -- The idea is that the deduplicated symbol context is as strong as -- the original one. For the former, we can make two assignments such -- that they only differs at one symbol, i.e. the head symbol. Then by -- using ∨-elim we can reduce the symbol context by removing the head. -- Lemma: "symbol context version" of weakening. weakening-sym : ∀ {ρ xs ys F} -> xs ⊂ ys -> fix-sctx ρ xs ⊢ F -> fix-sctx ρ ys ⊢ F weakening-sym {ρ} {xs} {ys} {F} sub hyp = weakening hyp (lemma-map sub) -- Lemma: Deduplicated symbol ctx is as strong as the original ctx. lemma-dedup : ∀ {ρ xs F} -> fix-sctx ρ xs ⊢ F -> fix-sctx ρ (deduplicate _≟_ xs) ⊢ F lemma-dedup {xs = xs} = weakening-sym λ x → ∈-deduplicate⁺ _≟_ {xs} x where open import Data.List.Membership.Propositional.Properties using (∈-deduplicate⁺) -- law of excluded middle is derivable. ex-mid : ∀ {A} -> Empty ⊢ (¬ A) ∨ A ex-mid {A} = ∨-elim step (∨-intro1 (¬-intro (⇒-elim (assump (∈-step ∈-base)) (assump ∈-base)))) (∨-intro2 (double-negation (⇒-intro (⇒-elim (assump (∈-step ∈-base)) (¬-intro (⇒-elim (assump (∈-step ∈-base)) (assump ∈-base))))))) where demorgan : ∀ {A B} -> Empty ⊢ ((A ∧ B) ⇒ ⊥) ⇒ (A ⇒ ⊥) ∨ (B ⇒ ⊥) demorgan = ⇒-intro (double-negation (⇒-intro (⇒-elim (assump ∈-base) (∨-intro1 (⇒-intro (⇒-elim (assump (∈-step ∈-base)) (∨-intro2 (⇒-intro (⇒-elim (assump (∈-step (∈-step (∈-step ∈-base)))) (∧-intro (assump (∈-step ∈-base)) (assump ∈-base))))))))))) step : Empty ⊢ ((A ⇒ ⊥) ∨ ((¬ A) ⇒ ⊥)) step = ⇒-elim (demorgan {A} {¬ A}) (⇒-intro (¬-elim (∧-elim2 (assump ∈-base)) (∧-elim1 (assump ∈-base)))) -- ∨-elim instantiated using excluded middle. ∨-elim-exmid : ∀ {Γ A B} -> Γ , ¬ A ⊢ B -> Γ , A ⊢ B -> Γ ⊢ B ∨-elim-exmid {Γ} {A} {b} d e = ∨-elim (weakening ex-mid lemma-⊆-empty) d e -- Lemma: Removing one symbol from symbol context. lemma-sctx-reduce : ∀ {ρ ns n F} -> (n ∉ ns) -> fix-sctx ρ (n ∷ ns) ⊢ F -> fix-sctx (negate-assign-at ρ n) (n ∷ ns) ⊢ F -> fix-sctx ρ ns ⊢ F lemma-sctx-reduce {ρ} {ns} {n} {F} nin h1 h2 with inspect (ρ n) ... | it false pf rewrite (lemma-fix-sctx {a = ρ} nin) | lemma-fix-sym-neg {ρ} {n} pf | pf = ∨-elim-exmid h1 h2 ... | it true pf rewrite (lemma-fix-sctx {a = ρ} nin) | lemma-fix-sym-pos {ρ} {n} pf | pf = ∨-elim-exmid h2 h1 -- lemma: if the symbol ctx is unique, we can repeatedly use -- lemma-sctx-reduce to get an Empty context. lemma-unique-ctx-reduce : ∀ {F} {ns : List ℕ} -> Unique (ns) -> (∀ ρ -> fix-sctx ρ ns ⊢ F) -> Empty ⊢ F lemma-unique-ctx-reduce {F} {.Empty} [] hyp = hyp (λ _ → false) lemma-unique-ctx-reduce {F} {.(xs , x₁)} (_∷_ {x = x₁} {xs = xs} x uns) hyp = ih where open import Data.List.Relation.Unary.All open import Function anyAll : ∀ {ys : List ℕ} {Pd : ℕ -> Set} -> Any Pd ys -> RN.¬ (All (RN.¬_ ∘ Pd) ys) anyAll {.(_ , _)} {Pd} (here px) (px₁ ∷ all₁) = px₁ px anyAll {.(xs , _)} {Pd} (there {xs = xs} any₁) (px ∷ all₁) = anyAll {xs} {Pd} any₁ all₁ x₁∉xs : x₁ ∉ xs x₁∉xs h = anyAll h x ih : Empty ⊢ F ih = lemma-unique-ctx-reduce {F} {xs} uns λ ρ → lemma-sctx-reduce {ρ} {xs} {x₁} {F} x₁∉xs (hyp ρ) (hyp (negate-assign-at ρ x₁)) -- ---------------------------------------------------------------------- -- Completeness. -- lemma-Kalmar instantiated with semantical entailment. lemma-Kalmar-⊧ : ∀ {ρ F} -> Empty ⊧ F -> fix-sctx ρ (syms-of-formula F) ⊢ F lemma-Kalmar-⊧ {ρ} {F} st with lemma-Kalmar {F} ρ | st ρ refl ... | kal | Ft rewrite Ft = kal -- lemma-dedup instantiated with semantical entailment. lemma-dedup-⊧ : ∀ {F} -> Empty ⊧ F -> (∀ ρ -> fix-sctx ρ (deduplicate _≟_ (syms-of-formula F)) ⊢ F) lemma-dedup-⊧ st = λ ρ → lemma-dedup (lemma-Kalmar-⊧ (λ ρ _ → st ρ refl)) -- | Completeness in empty context. completeness-empty : ∀ {F} -> Empty ⊧ F -> Empty ⊢ F completeness-empty {F} st = lemma-unique-ctx-reduce (deduplicate-! ≡-decSetoid (syms-of-formula F)) (lemma-dedup-⊧ {F} st) where open import Data.List.Relation.Unary.Unique.DecSetoid.Properties using (deduplicate-!) -- | completeness-property. completeness : ∀ Γ A -> Γ ⊧ A -> Γ ⊢ A completeness Empty A hyp = completeness-empty {A} hyp completeness (Γ , B) A hyp = ⇒-elim (weakening (completeness Γ (B ⇒ A) (lemma-⇒-intro Γ B A hyp)) ∈-step) (assump ∈-base)
{ "alphanum_fraction": 0.5815893349, "avg_line_length": 47.6134751773, "ext": "agda", "hexsha": "4833ce2c8de838964884390028e0855fb06cc2b1", "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": "646ccb162cf01fa0d1edafcc830db6750099ed21", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "onestruggler/Kalmar", "max_forks_repo_path": "Kalmar.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "646ccb162cf01fa0d1edafcc830db6750099ed21", "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": "onestruggler/Kalmar", "max_issues_repo_path": "Kalmar.agda", "max_line_length": 256, "max_stars_count": null, "max_stars_repo_head_hexsha": "646ccb162cf01fa0d1edafcc830db6750099ed21", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "onestruggler/Kalmar", "max_stars_repo_path": "Kalmar.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4989, "size": 13427 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.ZCohomology.Groups.Sn where open import Cubical.ZCohomology.Base open import Cubical.ZCohomology.Properties open import Cubical.ZCohomology.Groups.Unit open import Cubical.ZCohomology.Groups.Connected open import Cubical.ZCohomology.GroupStructure open import Cubical.ZCohomology.Groups.Prelims open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv open import Cubical.Foundations.Function open import Cubical.Foundations.Prelude open import Cubical.Foundations.Structure open import Cubical.Foundations.Pointed open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.HITs.Pushout open import Cubical.HITs.Sn open import Cubical.HITs.S1 open import Cubical.HITs.Susp open import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2 ; map to sMap) open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; elim to pElim ; elim2 to pElim2 ; ∥_∥ to ∥_∥₁ ; ∣_∣ to ∣_∣₁) hiding (map) open import Cubical.Data.Bool open import Cubical.Data.Sigma open import Cubical.Data.Int renaming (_+_ to _+ℤ_; +-comm to +ℤ-comm ; +-assoc to +ℤ-assoc) open import Cubical.Data.Nat open import Cubical.HITs.Truncation renaming (elim to trElim ; map to trMap ; rec to trRec) open import Cubical.Data.Unit open import Cubical.Homotopy.Connected open import Cubical.Algebra.Group infixr 31 _□_ _□_ : _ _□_ = compGroupIso open GroupEquiv open vSES open GroupIso open GroupHom open BijectionIso Sn-connected : (n : ℕ) (x : typ (S₊∙ (suc n))) → ∥ pt (S₊∙ (suc n)) ≡ x ∥₁ Sn-connected zero = toPropElim (λ _ → propTruncIsProp) ∣ refl ∣₁ Sn-connected (suc zero) = suspToPropElim base (λ _ → propTruncIsProp) ∣ refl ∣₁ Sn-connected (suc (suc n)) = suspToPropElim north (λ _ → propTruncIsProp) ∣ refl ∣₁ H⁰-Sⁿ≅ℤ : (n : ℕ) → GroupIso (coHomGr 0 (S₊ (suc n))) intGroup H⁰-Sⁿ≅ℤ zero = H⁰-connected base (Sn-connected 0) H⁰-Sⁿ≅ℤ (suc n) = H⁰-connected north (Sn-connected (suc n)) -- -- ---------------------------------------------------------------------- --- We will need to switch between Sⁿ defined using suspensions and using pushouts --- in order to apply Mayer Vietoris. S1Iso : Iso S¹ (Pushout {A = Bool} (λ _ → tt) λ _ → tt) S1Iso = S¹IsoSuspBool ⋄ invIso PushoutSuspIsoSusp coHomPushout≅coHomSn : (n m : ℕ) → GroupIso (coHomGr m (S₊ (suc n))) (coHomGr m (Pushout {A = S₊ n} (λ _ → tt) λ _ → tt)) coHomPushout≅coHomSn zero m = Iso+Hom→GrIso (setTruncIso (domIso S1Iso)) (sElim2 (λ _ _ → isSet→isGroupoid setTruncIsSet _ _) (λ _ _ → refl)) coHomPushout≅coHomSn (suc n) m = Iso+Hom→GrIso (setTruncIso (domIso (invIso PushoutSuspIsoSusp))) (sElim2 (λ _ _ → isSet→isGroupoid setTruncIsSet _ _) (λ _ _ → refl)) -------------------------- H⁰(S⁰) ----------------------------- S0→Int : (a : Int × Int) → S₊ 0 → Int S0→Int a true = fst a S0→Int a false = snd a H⁰-S⁰≅ℤ×ℤ : GroupIso (coHomGr 0 (S₊ 0)) (dirProd intGroup intGroup) fun (map H⁰-S⁰≅ℤ×ℤ) = sRec (isSet× isSetInt isSetInt) λ f → (f true) , (f false) isHom (map H⁰-S⁰≅ℤ×ℤ) = sElim2 (λ _ _ → isSet→isGroupoid (isSet× isSetInt isSetInt) _ _) λ a b → refl inv H⁰-S⁰≅ℤ×ℤ a = ∣ S0→Int a ∣₂ rightInv H⁰-S⁰≅ℤ×ℤ _ = refl leftInv H⁰-S⁰≅ℤ×ℤ = sElim (λ _ → isSet→isGroupoid setTruncIsSet _ _) λ f → cong ∣_∣₂ (funExt (λ {true → refl ; false → refl})) ------------------------- H¹(S⁰) ≅ 0 ------------------------------- private Hⁿ-S0≃Kₙ×Kₙ : (n : ℕ) → Iso (S₊ 0 → coHomK (suc n)) (coHomK (suc n) × coHomK (suc n)) Iso.fun (Hⁿ-S0≃Kₙ×Kₙ n) f = (f true) , (f false) Iso.inv (Hⁿ-S0≃Kₙ×Kₙ n) (a , b) true = a Iso.inv (Hⁿ-S0≃Kₙ×Kₙ n) (a , b) false = b Iso.rightInv (Hⁿ-S0≃Kₙ×Kₙ n) a = refl Iso.leftInv (Hⁿ-S0≃Kₙ×Kₙ n) b = funExt λ {true → refl ; false → refl} isContrHⁿ-S0 : (n : ℕ) → isContr (coHom (suc n) (S₊ 0)) isContrHⁿ-S0 n = isContrRetract (Iso.fun (setTruncIso (Hⁿ-S0≃Kₙ×Kₙ n))) (Iso.inv (setTruncIso (Hⁿ-S0≃Kₙ×Kₙ n))) (Iso.leftInv (setTruncIso (Hⁿ-S0≃Kₙ×Kₙ n))) (isContrHelper n) where isContrHelper : (n : ℕ) → isContr (∥ (coHomK (suc n) × coHomK (suc n)) ∥₂) fst (isContrHelper zero) = ∣ (0₁ , 0₁) ∣₂ snd (isContrHelper zero) = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ y → elim2 {B = λ x y → ∣ (0₁ , 0₁) ∣₂ ≡ ∣(x , y) ∣₂ } (λ _ _ → isOfHLevelPlus {n = 2} 2 setTruncIsSet _ _) (toPropElim2 (λ _ _ → setTruncIsSet _ _) refl) (fst y) (snd y) isContrHelper (suc zero) = ∣ (0₂ , 0₂) ∣₂ , sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ y → elim2 {B = λ x y → ∣ (0₂ , 0₂) ∣₂ ≡ ∣(x , y) ∣₂ } (λ _ _ → isOfHLevelPlus {n = 2} 3 setTruncIsSet _ _) (suspToPropElim2 base (λ _ _ → setTruncIsSet _ _) refl) (fst y) (snd y) isContrHelper (suc (suc n)) = ∣ (0ₖ (3 + n) , 0ₖ (3 + n)) ∣₂ , sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ y → elim2 {B = λ x y → ∣ (0ₖ (3 + n) , 0ₖ (3 + n)) ∣₂ ≡ ∣(x , y) ∣₂ } (λ _ _ → isProp→isOfHLevelSuc (4 + n) (setTruncIsSet _ _)) (suspToPropElim2 north (λ _ _ → setTruncIsSet _ _) refl) (fst y) (snd y) H¹-S⁰≅0 : (n : ℕ) → GroupIso (coHomGr (suc n) (S₊ 0)) trivialGroup H¹-S⁰≅0 n = IsoContrGroupTrivialGroup (isContrHⁿ-S0 n) ------------------------- H²(S¹) ≅ 0 ------------------------------- Hⁿ-S¹≅0 : (n : ℕ) → GroupIso (coHomGr (2 + n) (S₊ 1)) trivialGroup Hⁿ-S¹≅0 n = IsoContrGroupTrivialGroup (isOfHLevelRetractFromIso 0 helper (_ , helper2)) where helper : Iso ⟨ coHomGr (2 + n) (S₊ 1)⟩ ∥ Σ (hLevelTrunc (4 + n) (S₊ (2 + n))) (λ x → ∥ x ≡ x ∥₂) ∥₂ helper = compIso (setTruncIso IsoFunSpaceS¹) IsoSetTruncateSndΣ helper2 : (x : ∥ Σ (hLevelTrunc (4 + n) (S₊ (2 + n))) (λ x → ∥ x ≡ x ∥₂) ∥₂) → ∣ ∣ north ∣ , ∣ refl ∣₂ ∣₂ ≡ x helper2 = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) (uncurry (trElim (λ _ → isOfHLevelΠ (4 + n) λ _ → isProp→isOfHLevelSuc (3 + n) (setTruncIsSet _ _)) (suspToPropElim (ptSn (suc n)) (λ _ → isPropΠ λ _ → setTruncIsSet _ _) (sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ p → cong ∣_∣₂ (ΣPathP (refl , isContr→isProp helper3 _ _)))))) where helper4 : isConnected (n + 3) (hLevelTrunc (4 + n) (S₊ (2 + n))) helper4 = subst (λ m → isConnected m (hLevelTrunc (4 + n) (S₊ (2 + n)))) (+-comm 3 n) (isOfHLevelRetractFromIso 0 (invIso (truncOfTruncIso (3 + n) 1)) (sphereConnected (2 + n))) helper3 : isContr ∥ ∣ north ∣ ≡ ∣ north ∣ ∥₂ helper3 = isOfHLevelRetractFromIso 0 setTruncTrunc2Iso (isConnectedPath 2 (isConnectedSubtr 3 n helper4) _ _) -- --------------- H¹(Sⁿ), n ≥ 1 -------------------------------------------- H¹-Sⁿ≅0 : (n : ℕ) → GroupIso (coHomGr 1 (S₊ (2 + n))) trivialGroup H¹-Sⁿ≅0 zero = IsoContrGroupTrivialGroup isContrH¹S² where isContrH¹S² : isContr ⟨ coHomGr 1 (S₊ 2) ⟩ isContrH¹S² = ∣ (λ _ → ∣ base ∣) ∣₂ , coHomPointedElim 0 north (λ _ → setTruncIsSet _ _) λ f p → cong ∣_∣₂ (funExt λ x → sym p ∙∙ sym (spoke f north) ∙∙ spoke f x) H¹-Sⁿ≅0 (suc n) = IsoContrGroupTrivialGroup isContrH¹S³⁺ⁿ where anIso : Iso ⟨ coHomGr 1 (S₊ (3 + n)) ⟩ ∥ (S₊ (3 + n) → hLevelTrunc (4 + n) (coHomK 1)) ∥₂ anIso = setTruncIso (codomainIso (invIso (truncIdempotentIso (4 + n) (isOfHLevelPlus' {n = 1 + n} 3 (isOfHLevelTrunc 3))))) isContrH¹S³⁺ⁿ-ish : (f : (S₊ (3 + n) → hLevelTrunc (4 + n) (coHomK 1))) → ∣ (λ _ → ∣ ∣ base ∣ ∣) ∣₂ ≡ ∣ f ∣₂ isContrH¹S³⁺ⁿ-ish f = ind (f north) refl where ind : (x : hLevelTrunc (4 + n) (coHomK 1)) → x ≡ f north → ∣ (λ _ → ∣ ∣ base ∣ ∣) ∣₂ ≡ ∣ f ∣₂ ind = trElim (λ _ → isOfHLevelΠ (4 + n) λ _ → isOfHLevelPlus' {n = (3 + n)} 1 (setTruncIsSet _ _)) (trElim (λ _ → isOfHLevelΠ 3 λ _ → isOfHLevelPlus {n = 1} 2 (setTruncIsSet _ _)) (toPropElim (λ _ → isPropΠ λ _ → setTruncIsSet _ _) λ p → cong ∣_∣₂ (funExt λ x → p ∙∙ sym (spoke f north) ∙∙ spoke f x))) isContrH¹S³⁺ⁿ : isContr ⟨ coHomGr 1 (S₊ (3 + n)) ⟩ isContrH¹S³⁺ⁿ = isOfHLevelRetractFromIso 0 anIso (∣ (λ _ → ∣ ∣ base ∣ ∣) ∣₂ , sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) isContrH¹S³⁺ⁿ-ish) --------- H¹(S¹) ≅ ℤ ------- {- Idea : H¹(S¹) := ∥ S¹ → K₁ ∥₂ ≃ ∥ S¹ → S¹ ∥₂ ≃ ∥ S¹ × ℤ ∥₂ ≃ ∥ S¹ ∥₂ × ∥ ℤ ∥₂ ≃ ℤ -} coHom1S1≃ℤ : GroupIso (coHomGr 1 (S₊ 1)) intGroup coHom1S1≃ℤ = theIso where F = Iso.fun S¹→S¹≡S¹×Int F⁻ = Iso.inv S¹→S¹≡S¹×Int theIso : GroupIso (coHomGr 1 (S₊ 1)) intGroup fun (map theIso) = sRec isSetInt (λ f → snd (F f)) isHom (map theIso) = coHomPointedElimS¹2 _ (λ _ _ → isSetInt _ _) λ p q → (λ i → winding (guy ∣ base ∣ (cong S¹map (help p q i)))) ∙∙ (λ i → winding (guy ∣ base ∣ (congFunct S¹map p q i))) ∙∙ winding-hom (guy ∣ base ∣ (cong S¹map p)) (guy ∣ base ∣ (cong S¹map q)) where guy = basechange2⁻ ∘ S¹map help : (p q : Path (coHomK 1) ∣ base ∣ ∣ base ∣) → cong₂ _+ₖ_ p q ≡ p ∙ q help p q = cong₂Funct _+ₖ_ p q ∙ (λ i → cong (λ x → rUnitₖ 1 x i) p ∙ cong (λ x → lUnitₖ 1 x i) q) inv theIso a = ∣ (F⁻ (base , a)) ∣₂ rightInv theIso a = cong snd (Iso.rightInv S¹→S¹≡S¹×Int (base , a)) leftInv theIso = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ f → cong ((sRec setTruncIsSet ∣_∣₂) ∘ sRec setTruncIsSet λ x → ∣ F⁻ (x , (snd (F f))) ∣₂) (Iso.inv PathIdTrunc₀Iso (isConnectedS¹ (fst (F f)))) ∙ cong ∣_∣₂ (Iso.leftInv S¹→S¹≡S¹×Int f) ---------------------------- Hⁿ(Sⁿ) ≅ ℤ , n ≥ 1 ------------------- {- The proof of the inductive step below is a compact version of the following equations. Let n ≥ 1. Hⁿ⁺¹(Sⁿ⁺¹) := ∥ Sⁿ⁺¹ → Kₙ₊₁ ∥₂ ≅ ∥ Σ[ (a , b) ∈ Kₙ₊₁ ] (Sⁿ → a ≡ b) ∥₂ (characterisation of functions from suspensions) ≅ ∥ Kₙ₊₁ × Kₙ₊₁ × (Sⁿ → ΩKₙ₊₁) ∥₂ (base change in ΩKₙ₊₁) ≅ ∥ Kₙ₊₁ ∥₂ × ∥ Kₙ₊₁ ∥₂ × ∥ (Sⁿ → ΩKₙ₊₁) ∥₂ ≅ ∥ Sⁿ → ΩKₙ₊₁ ∥₂ (connectivity of Kₙ₊₁) ≅ ∥ Sⁿ → Kₙ ∥₂ (ΩKₙ₊₁ ≃ Kₙ) := Hⁿ(Sⁿ) ≅ ℤ (ind. hyp) The inverse function Hⁿ(Sⁿ) → Hⁿ⁺¹(Sⁿ⁺¹) is just the function d from Mayer-Vietoris. However, we can construct d⁻¹ directly in this case, thus avoiding computationally heavier proofs concerning exact sequences. -} Hⁿ-Sⁿ≅ℤ : (n : ℕ) → GroupIso (coHomGr (suc n) (S₊ (suc n))) intGroup Hⁿ-Sⁿ≅ℤ zero = coHom1S1≃ℤ Hⁿ-Sⁿ≅ℤ (suc n) = invGroupIso helper □ invGroupIso (coHom≅coHomΩ (suc n) _) □ (Hⁿ-Sⁿ≅ℤ n) where basePointInd : (p : _) (a : _) → (p (ptSn (suc n)) ≡ refl) → sym (rCancelₖ (2 + n) ∣ north ∣) ∙∙ (λ i → (elimFunSⁿ (suc n) n p) ((merid a ∙ sym (merid (ptSn (suc n)))) i) +ₖ ∣ north ∣) ∙∙ rCancelₖ (2 + n) ∣ north ∣ ≡ p a basePointInd p a prefl = cong (λ z → sym z ∙∙ ((λ i → (elimFunSⁿ (suc n) n p) ((merid a ∙ sym (merid (ptSn (suc n)))) i) +ₖ ∣ north ∣)) ∙∙ z) (transportRefl refl) ∙∙ sym (rUnit _) ∙∙ (λ j i → rUnitₖ (2 + n) (elimFunSⁿ (suc n) n p ((merid a ∙ sym (merid (ptSn (suc n)))) i)) j) ∙∙ congFunct (elimFunSⁿ (suc n) n p) (merid a) (sym (merid (ptSn (suc n)))) ∙∙ (cong (p a ∙_) (cong sym prefl) ∙ sym (rUnit (p a))) helper : GroupIso (coHomGrΩ (suc n) (S₊ (suc n))) (coHomGr (2 + n) (S₊ (2 + n))) fun (map helper) = sMap λ f → λ { north → ∣ north ∣ ; south → ∣ north ∣ ; (merid a i) → f a i} isHom (map helper) = sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ f g → cong ∣_∣₂ (funExt λ { north → refl ; south → refl ; (merid a i) j → ∙≡+₂ n (f a) (g a) j i}) inv helper = sMap λ f x → sym (rCancelₖ (2 + n) (f north)) ∙∙ (λ i → f ((merid x ∙ sym (merid (ptSn (suc n)))) i) -ₖ f north) ∙∙ rCancelₖ (2 + n) (f north) rightInv helper = coHomPointedElimSⁿ (suc n) n (λ _ → setTruncIsSet _ _) λ p → trRec (isProp→isOfHLevelSuc n (setTruncIsSet _ _)) (λ prefl → cong ∣_∣₂ (funExt λ {north → refl ; south → refl ; (merid a i) j → basePointInd p a prefl j i})) (Iso.fun (PathIdTruncIso _) (isOfHLevelSuc 0 (isConnectedPathKn _ ∣ north ∣ ∣ north ∣) (∣ p (ptSn (suc n)) ∣) ∣ refl ∣)) leftInv helper = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ f → (trRec (isProp→isOfHLevelSuc n (setTruncIsSet _ _)) (λ frefl → cong ∣_∣₂ (funExt λ x → basePointInd f x frefl)) ((Iso.fun (PathIdTruncIso _) (isOfHLevelSuc 0 (isConnectedPathKn _ ∣ north ∣ ∣ north ∣) (∣ f (ptSn (suc n)) ∣) ∣ refl ∣))))
{ "alphanum_fraction": 0.5234589288, "avg_line_length": 48.1041666667, "ext": "agda", "hexsha": "78cf91d4390713b4dabcfb1ff16ff90509926f0c", "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/ZCohomology/Groups/Sn.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/ZCohomology/Groups/Sn.agda", "max_line_length": 146, "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/ZCohomology/Groups/Sn.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5544, "size": 13854 }
id : Set → Set id A = A F : Set → Set → Set F _*_ = G where G : Set → Set G _*_ = id _*_ G : Set → Set → Set G _*_ = λ _*_ → id _*_ H : Set → Set → Set H = λ _*_ _*_ → id _*_
{ "alphanum_fraction": 0.4619565217, "avg_line_length": 12.2666666667, "ext": "agda", "hexsha": "7c18ea75d2def7a16365ddf4b875c080a1dee45f", "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/Issue1681.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/Issue1681.agda", "max_line_length": 22, "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/Issue1681.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": 84, "size": 184 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra where open import Cubical.Algebra.Base public open import Cubical.Algebra.Definitions public open import Cubical.Algebra.Structures public open import Cubical.Algebra.Bundles public open import Cubical.Classes public
{ "alphanum_fraction": 0.8122866894, "avg_line_length": 29.3, "ext": "agda", "hexsha": "58d75b6bec6ef57052224f17c24f5ad4b02de611", "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.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.agda", "max_line_length": 50, "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.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 68, "size": 293 }
open import agdaExamples public open import Blockchain public open import Crypto public open import examples public open import lambdaCalculus open import Ledger public open import proofsTXTree public open import RawTransactions public open import RawTXTree public open import Transactions public open import TXTree public open import Utils public
{ "alphanum_fraction": 0.8649425287, "avg_line_length": 26.7692307692, "ext": "agda", "hexsha": "529bc807a19aec7ce946f4cacc59f8debc74e052", "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": "ac91e00abca9a26678d0cbc1bedecf8abef6b703", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "guilhermehas/cripto-agda", "max_forks_repo_path": "src/Everything.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ac91e00abca9a26678d0cbc1bedecf8abef6b703", "max_issues_repo_issues_event_max_datetime": "2019-11-03T14:31:16.000Z", "max_issues_repo_issues_event_min_datetime": "2019-11-01T11:36:06.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "guilhermehas/cripto-agda", "max_issues_repo_path": "src/Everything.agda", "max_line_length": 34, "max_stars_count": 4, "max_stars_repo_head_hexsha": "ac91e00abca9a26678d0cbc1bedecf8abef6b703", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "guilhermehas/crypto-agda", "max_stars_repo_path": "src/Everything.agda", "max_stars_repo_stars_event_max_datetime": "2021-03-22T19:27:12.000Z", "max_stars_repo_stars_event_min_datetime": "2020-02-13T16:56:47.000Z", "num_tokens": 69, "size": 348 }
------------------------------------------------------------------------ -- Parallel substitutions (defined using an inductive family) ------------------------------------------------------------------------ open import Data.Universe.Indexed module deBruijn.Substitution.Data {i u e} {Uni : IndexedUniverse i u e} where import deBruijn.Context; open deBruijn.Context Uni open import Function as F using (_$_) open import Level using (_⊔_) import Relation.Binary.PropositionalEquality as P open P.≡-Reasoning -- This module reexports some other modules. open import deBruijn.Substitution.Data.Application public open import deBruijn.Substitution.Data.Basics public open import deBruijn.Substitution.Data.Map public open import deBruijn.Substitution.Data.Simple public ------------------------------------------------------------------------ -- Instantiations and code for facilitating instantiations -- Renamings (variable substitutions). module Renaming where -- Variables support all of the operations above. simple : Simple Var simple = record { weaken = weaken∋ ; var = [id] ; weaken-var = λ _ → P.refl } application : Application Var Var application = record { app = app∋ } application₁ : Application₁ Var application₁ = record { simple = simple ; application₂₂ = record { application₂₁ = record { application = application ; trans-weaken = λ _ → P.refl ; trans-var = λ _ → P.refl ; var-/⊢ = λ _ _ → P.refl } ; var-/⊢⋆-↑⁺⋆-⇒-/⊢⋆-↑⁺⋆ = λ _ _ hyp → hyp ; /⊢-wk = Simple./∋-wk simple } } open Application₁ application₁ public hiding (simple; application) ≅-∋-⇒-≅-⊢ : ∀ {Γ₁ σ₁} {x₁ : Γ₁ ∋ σ₁} {Γ₂ σ₂} {x₂ : Γ₂ ∋ σ₂} → x₁ ≅-∋ x₂ → Term-like._≅-⊢_ Var x₁ x₂ ≅-∋-⇒-≅-⊢ P.refl = P.refl ≅-⊢-⇒-≅-∋ : ∀ {Γ₁ σ₁} {x₁ : Γ₁ ∋ σ₁} {Γ₂ σ₂} {x₂ : Γ₂ ∋ σ₂} → Term-like._≅-⊢_ Var x₁ x₂ → x₁ ≅-∋ x₂ ≅-⊢-⇒-≅-∋ P.refl = P.refl -- A translation of T₁'s to T₂'s, plus a bit more. record _↦_ {t₁} (T₁ : Term-like t₁) {t₂} (T₂ : Term-like t₂) : Set (i ⊔ u ⊔ e ⊔ t₁ ⊔ t₂) where field -- Translates T₁'s to T₂'s. trans : [ T₁ ⟶⁼ T₂ ] -- Simple substitutions for T₁'s. simple : Simple T₁ open Simple simple public open Term-like T₁ renaming (⟦_⟧ to ⟦_⟧₁) open Term-like T₂ renaming (⟦_⟧ to ⟦_⟧₂) /̂∋-⟦⟧⇨ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (x : Γ ∋ σ) (ρ : Sub T₁ ρ̂) → x /̂∋ ⟦ ρ ⟧⇨ ≅-Value ⟦ trans · (x /∋ ρ) ⟧₂ /̂∋-⟦⟧⇨ x ρ = begin [ x /̂∋ ⟦ ρ ⟧⇨ ] ≡⟨ corresponds (app∋ ρ) x ⟩ [ ⟦ x /∋ ρ ⟧₁ ] ≡⟨ corresponds trans (x /∋ ρ) ⟩ [ ⟦ trans · (x /∋ ρ) ⟧₂ ] ∎ -- "Term" substitutions. -- For simplicity I have chosen to use the universe level (i ⊔ u ⊔ e) -- here; this is the level of Var. The code could perhaps be made more -- general. record Substitution₁ (T : Term-like (i ⊔ u ⊔ e)) : Set (Level.suc (i ⊔ u ⊔ e)) where open Term-like T field -- Takes variables to terms. var : [ Var ⟶⁼ T ] -- Applies substitutions, which contain things which can be -- translated to terms, to terms. app′ : {T′ : Term-like (i ⊔ u ⊔ e)} → T′ ↦ T → ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Sub T′ ρ̂ → [ T ⟶ T ] ρ̂ -- A property relating app′ and var. app′-var : ∀ {T′ : Term-like (i ⊔ u ⊔ e)} {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (T′↦T : T′ ↦ T) (x : Γ ∋ σ) (ρ : Sub T′ ρ̂) → app′ T′↦T ρ · (var · x) ≅-⊢ _↦_.trans T′↦T · (x /∋ ρ) -- Variables can be translated into terms. private Var-↦′ : Var ↦ T Var-↦′ = record { trans = var ; simple = Renaming.simple } -- Renamings can be applied to terms. app-renaming : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Sub Var ρ̂ → [ T ⟶ T ] ρ̂ app-renaming = app′ Var-↦′ -- This gives us a way to define the weakening operation. simple : Simple T simple = record { weaken = app-renaming Renaming.wk ; var = var ; weaken-var = weaken-var } where abstract weaken-var : ∀ {Γ σ τ} (x : Γ ∋ τ) → app-renaming (Renaming.wk[_] σ) · (var · x) ≅-⊢ var · suc[ σ ] x weaken-var x = begin [ app-renaming Renaming.wk · (var · x) ] ≡⟨ app′-var Var-↦′ x Renaming.wk ⟩ [ var · (x /∋ Renaming.wk) ] ≡⟨ ·-cong (var ∎-⟶) (Renaming./∋-wk x) ⟩ [ var · suc x ] ∎ -- A translation of T′'s to T's, plus a bit more. record Translation-from (T′ : Term-like (i ⊔ u ⊔ e)) : Set (i ⊔ u ⊔ e) where field translation : T′ ↦ T open _↦_ translation using (trans) renaming (simple to simple′; var to var′; weaken[_] to weaken′[_]) field trans-weaken : ∀ {Γ σ τ} (t : Term-like._⊢_ T′ Γ τ) → trans · (weaken′[ σ ] · t) ≅-⊢ Simple.weaken[_] simple σ · (trans · t) trans-var : ∀ {Γ σ} (x : Γ ∋ σ) → trans · (var′ · x) ≅-⊢ var · x -- An Application₂₁ record. application₂₁ : Application₂₁ simple′ simple trans application₂₁ = record { application = record { app = app′ translation } ; trans-weaken = trans-weaken ; trans-var = trans-var ; var-/⊢ = app′-var translation } open _↦_ translation public open Application₂₁ application₂₁ public hiding (trans-weaken; trans-var) -- Variables can be translated into terms. Var-↦ : Translation-from Var Var-↦ = record { translation = Var-↦′ ; trans-weaken = trans-weaken ; trans-var = λ _ → P.refl } where abstract trans-weaken : ∀ {Γ σ τ} (x : Γ ∋ τ) → var · suc[ σ ] x ≅-⊢ Simple.weaken[_] simple σ · (var · x) trans-weaken x = P.sym $ Simple.weaken-var simple x -- Terms can be translated into terms. no-translation : Translation-from T no-translation = record { translation = record { trans = [id]; simple = simple } ; trans-weaken = λ _ → P.refl ; trans-var = λ _ → P.refl } record Substitution₂ (T : Term-like (i ⊔ u ⊔ e)) : Set (Level.suc (i ⊔ u ⊔ e)) where open Term-like T field substitution₁ : Substitution₁ T open Substitution₁ substitution₁ field -- Lifts equalities valid for all variables and liftings to -- arbitrary terms. var-/⊢⋆-↑⁺⋆-⇒-/⊢⋆-↑⁺⋆′ : {T₁ T₂ : Term-like (i ⊔ u ⊔ e)} (T₁↦T : Translation-from T₁) (T₂↦T : Translation-from T₂) → let open Translation-from T₁↦T using () renaming (_↑⁺⋆_ to _↑⁺⋆₁_; _/⊢⋆_ to _/⊢⋆₁_) open Translation-from T₂↦T using () renaming (_↑⁺⋆_ to _↑⁺⋆₂_; _/⊢⋆_ to _/⊢⋆₂_) in ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} (ρs₁ : Subs T₁ ρ̂) (ρs₂ : Subs T₂ ρ̂) → (∀ Γ⁺ {σ} (x : Γ ++⁺ Γ⁺ ∋ σ) → var · x /⊢⋆₁ ρs₁ ↑⁺⋆₁ Γ⁺ ≅-⊢ var · x /⊢⋆₂ ρs₂ ↑⁺⋆₂ Γ⁺) → ∀ Γ⁺ {σ} (t : Γ ++⁺ Γ⁺ ⊢ σ) → t /⊢⋆₁ ρs₁ ↑⁺⋆₁ Γ⁺ ≅-⊢ t /⊢⋆₂ ρs₂ ↑⁺⋆₂ Γ⁺ -- Given a well-behaved translation from something with simple -- substitutions one can define an Application₂₂ record. application₂₂ : {T′ : Term-like (i ⊔ u ⊔ e)} (T′↦T : Translation-from T′) → let open Translation-from T′↦T using (trans) renaming (simple to simple′) in Application₂₂ simple′ simple trans application₂₂ T′↦T = record { application₂₁ = Translation-from.application₂₁ T′↦T ; var-/⊢⋆-↑⁺⋆-⇒-/⊢⋆-↑⁺⋆ = var-/⊢⋆-↑⁺⋆-⇒-/⊢⋆-↑⁺⋆′ T′↦T T′↦T ; /⊢-wk = /⊢-wk } where open Translation-from T′↦T using () renaming ( _↑⁺_ to _↑⁺′_; _↑⁺⋆_ to _↑⁺⋆′_ ; wk to wk′; wk[_] to wk′[_] ; _/⊢_ to _/⊢′_; _/⊢⋆_ to _/⊢⋆′_ ) open Translation-from Var-↦ using () renaming ( _↑⁺_ to _↑⁺-renaming_; _↑⁺⋆_ to _↑⁺⋆-renaming_ ; _/⊢_ to _/⊢-renaming_; _/⊢⋆_ to _/⊢⋆-renaming_ ) abstract /⊢-wk : ∀ {Γ σ τ} (t : Γ ⊢ τ) → t /⊢′ wk′[ σ ] ≅-⊢ t /⊢-renaming Renaming.wk[_] σ /⊢-wk = var-/⊢⋆-↑⁺⋆-⇒-/⊢⋆-↑⁺⋆′ T′↦T Var-↦ (ε ▻ wk′) (ε ▻ Renaming.wk) (λ Γ⁺ x → begin [ var · x /⊢⋆′ (ε ▻ wk′) ↑⁺⋆′ Γ⁺ ] ≡⟨ Translation-from./⊢⋆-ε-▻-↑⁺⋆ T′↦T Γ⁺ (var · x) wk′ ⟩ [ var · x /⊢′ wk′ ↑⁺′ Γ⁺ ] ≡⟨ Translation-from.var-/⊢-wk-↑⁺ T′↦T Γ⁺ x ⟩ [ var · (lift weaken∋ Γ⁺ · x) ] ≡⟨ P.sym $ Translation-from.var-/⊢-wk-↑⁺ Var-↦ Γ⁺ x ⟩ [ var · x /⊢-renaming Renaming.wk ↑⁺-renaming Γ⁺ ] ≡⟨ P.sym $ Translation-from./⊢⋆-ε-▻-↑⁺⋆ Var-↦ Γ⁺ (var · x) Renaming.wk ⟩ [ var · x /⊢⋆-renaming (ε ▻ Renaming.wk) ↑⁺⋆-renaming Γ⁺ ] ∎) ε -- An Application₂₂ record for renamings. application₂₂-renaming : Application₂₂ Renaming.simple simple var application₂₂-renaming = application₂₂ Var-↦ -- We can apply substitutions to terms. application₁ : Application₁ T application₁ = record { simple = simple ; application₂₂ = application₂₂ no-translation } open Application₁ application₁ public hiding (var; simple; application₂₂) open Substitution₁ substitution₁ public
{ "alphanum_fraction": 0.4982437467, "avg_line_length": 31.9557823129, "ext": "agda", "hexsha": "72a5687361b4c4efeac6d7387720e60782c37e3c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/dependently-typed-syntax", "max_forks_repo_path": "deBruijn/Substitution/Data.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/dependently-typed-syntax", "max_issues_repo_path": "deBruijn/Substitution/Data.agda", "max_line_length": 128, "max_stars_count": 5, "max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/dependently-typed-syntax", "max_stars_repo_path": "deBruijn/Substitution/Data.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z", "num_tokens": 3645, "size": 9395 }
module Issue493 where module M where postulate A B C : Set module M₁ = M renaming (B to Y) hiding (A) module M₂ = M using (A) using (B) module M₃ = M hiding (A) hiding (B) open M using (A) public
{ "alphanum_fraction": 0.6683168317, "avg_line_length": 16.8333333333, "ext": "agda", "hexsha": "5dd590a75d142fcd1bd46262deb0e6f3ae1e4c32", "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/Issue493.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/Issue493.agda", "max_line_length": 42, "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/Issue493.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": 69, "size": 202 }
{-# OPTIONS --without-K #-} module well-typed-syntax-helpers where open import common open import well-typed-syntax infixl 3 _‘'’ₐ_ infixr 1 _‘→'’_ infixl 3 _‘t’_ infixl 3 _‘t’₁_ infixl 3 _‘t’₂_ infixr 2 _‘∘’_ WS∀ : ∀ {Γ T T' A B} {a : Term {Γ = Γ} T} → Term {Γ = Γ ▻ T'} (W ((A ‘→’ B) ‘’ a)) → Term {Γ ▻ T'} (W ((A ‘’ a) ‘→’ (B ‘’₁ a))) WS∀ = weakenTyp-substTyp-tProd _‘→'’_ : ∀ {Γ} → Typ Γ → Typ Γ → Typ Γ _‘→'’_ {Γ = Γ} A B = _‘→’_ {Γ = Γ} A (W {Γ = Γ} {A = A} B) _‘'’ₐ_ : ∀ {Γ A B} → Term {Γ} (A ‘→'’ B) → Term A → Term B _‘'’ₐ_ {Γ} {A} {B} f x = SW (_‘’ₐ_ {Γ} {A} {W B} f x) _‘t’_ : ∀ {Γ A} {B : Typ (Γ ▻ A)} → (b : Term {Γ = Γ ▻ A} B) → (a : Term {Γ} A) → Term {Γ} (B ‘’ a) b ‘t’ a = ‘λ∙’ b ‘’ₐ a substTyp-tProd : ∀ {Γ T A B} {a : Term {Γ} T} → Term {Γ} ((A ‘→’ B) ‘’ a) → Term {Γ} (_‘→’_ {Γ = Γ} (A ‘’ a) (B ‘’₁ a)) substTyp-tProd {Γ} {T} {A} {B} {a} x = SW ((WS∀ (w x)) ‘t’ a) S∀ = substTyp-tProd ‘λ'∙’ : ∀ {Γ A B} → Term {Γ ▻ A} (W B) -> Term (A ‘→'’ B) ‘λ'∙’ f = ‘λ∙’ f SW1V : ∀ {Γ A T} → Term {Γ ▻ A} (W1 T ‘’ ‘VAR₀’) → Term {Γ ▻ A} T SW1V = substTyp-weakenTyp1-VAR₀ S₁∀ : ∀ {Γ T T' A B} {a : Term {Γ} T} → Term {Γ ▻ T' ‘’ a} ((A ‘→’ B) ‘’₁ a) → Term {Γ ▻ T' ‘’ a} ((A ‘’₁ a) ‘→’ (B ‘’₂ a)) S₁∀ = substTyp1-tProd un‘λ∙’ : ∀ {Γ A B} → Term (A ‘→’ B) → Term {Γ ▻ A} B un‘λ∙’ f = SW1V (weakenTyp-tProd (w f) ‘’ₐ ‘VAR₀’) weakenProd : ∀ {Γ A B C} → Term {Γ} (A ‘→’ B) → Term {Γ = Γ ▻ C} (W A ‘→’ W1 B) weakenProd {Γ} {A} {B} {C} x = weakenTyp-tProd (w x) w∀ = weakenProd w1 : ∀ {Γ A B C} → Term {Γ = Γ ▻ B} C → Term {Γ = Γ ▻ A ▻ W {Γ = Γ} {A = A} B} (W1 {Γ = Γ} {A = A} {B = B} C) w1 x = un‘λ∙’ (weakenTyp-tProd (w (‘λ∙’ x))) _‘t’₁_ : ∀ {Γ A B C} → (c : Term {Γ = Γ ▻ A ▻ B} C) → (a : Term {Γ} A) → Term {Γ = Γ ▻ B ‘’ a} (C ‘’₁ a) f ‘t’₁ x = un‘λ∙’ (S∀ (‘λ∙’ (‘λ∙’ f) ‘’ₐ x)) _‘t’₂_ : ∀ {Γ A B C D} → (c : Term {Γ = Γ ▻ A ▻ B ▻ C} D) → (a : Term {Γ} A) → Term {Γ = Γ ▻ B ‘’ a ▻ C ‘’₁ a} (D ‘’₂ a) f ‘t’₂ x = un‘λ∙’ (S₁∀ (un‘λ∙’ (S∀ (‘λ∙’ (‘λ∙’ (‘λ∙’ f)) ‘’ₐ x)))) S₁₀W' : ∀ {Γ C T A} {a : Term {Γ} C} {b : Term {Γ} (T ‘’ a)} → Term {Γ} (A ‘’ a) → Term {Γ} (W A ‘’₁ a ‘’ b) S₁₀W' = substTyp1-substTyp-weakenTyp-inv S₁₀W : ∀ {Γ C T A} {a : Term {Γ} C} {b : Term {Γ} (T ‘’ a)} → Term {Γ} (W A ‘’₁ a ‘’ b) → Term {Γ} (A ‘’ a) S₁₀W = substTyp1-substTyp-weakenTyp substTyp1-substTyp-weakenTyp-weakenTyp : ∀ {Γ T A} {B : Typ (Γ ▻ A)} → {a : Term {Γ} A} → {b : Term {Γ} (B ‘’ a)} → Term {Γ} (W (W T) ‘’₁ a ‘’ b) → Term {Γ} T substTyp1-substTyp-weakenTyp-weakenTyp x = SW (S₁₀W x) S₁₀WW = substTyp1-substTyp-weakenTyp-weakenTyp S₂₁₀W : ∀ {Γ A B C T} {a : Term {Γ} A} {b : Term {Γ} (B ‘’ a)} {c : Term {Γ} (C ‘’₁ a ‘’ b)} → Term {Γ} (W T ‘’₂ a ‘’₁ b ‘’ c) → Term {Γ} (T ‘’₁ a ‘’ b) S₂₁₀W = substTyp2-substTyp1-substTyp-weakenTyp substTyp2-substTyp1-substTyp-weakenTyp-weakenTyp : ∀ {Γ A B C T} {a : Term {Γ} A} {b : Term {Γ} (B ‘’ a)} {c : Term {Γ} (C ‘’₁ a ‘’ b)} → Term {Γ} (W (W T) ‘’₂ a ‘’₁ b ‘’ c) → Term {Γ} (T ‘’ a) substTyp2-substTyp1-substTyp-weakenTyp-weakenTyp x = S₁₀W (S₂₁₀W x) S₂₁₀WW = substTyp2-substTyp1-substTyp-weakenTyp-weakenTyp W1W : ∀ {Γ A B C} → Term {Γ ▻ A ▻ W B} (W1 (W C)) → Term {Γ ▻ A ▻ W B} (W (W C)) W1W = weakenTyp1-weakenTyp W1W1W : ∀ {Γ A B C T} → Term {Γ ▻ A ▻ B ▻ W (W C)} (W1 (W1 (W T))) → Term {Γ ▻ A ▻ B ▻ W (W C)} (W1 (W (W T))) W1W1W = weakenTyp1-weakenTyp1-weakenTyp weakenTyp-tProd-nd : ∀ {Γ A B C} → Term {Γ = Γ ▻ C} (W (A ‘→'’ B)) → Term {Γ = Γ ▻ C} (W A ‘→'’ W B) weakenTyp-tProd-nd x = ‘λ'∙’ (W1W (SW1V (weakenTyp-tProd (w (weakenTyp-tProd x)) ‘’ₐ ‘VAR₀’))) weakenProd-nd : ∀ {Γ A B C} → Term (A ‘→'’ B) → Term {Γ = Γ ▻ C} (W A ‘→'’ W B) weakenProd-nd {Γ} {A} {B} {C} x = weakenTyp-tProd-nd (w x) weakenTyp-tProd-nd-tProd-nd : ∀ {Γ A B C D} → Term {Γ = Γ ▻ D} (W (A ‘→'’ B ‘→'’ C)) → Term {Γ = Γ ▻ D} (W A ‘→'’ W B ‘→'’ W C) weakenTyp-tProd-nd-tProd-nd x = ‘λ∙’ (weakenTyp-tProd-inv (‘λ∙’ (W1W1W (SW1V (w∀ (weakenTyp-tProd (weakenTyp-weakenTyp-tProd (w→ (weakenTyp-tProd-nd x) ‘'’ₐ ‘VAR₀’))) ‘’ₐ ‘VAR₀’))))) weakenProd-nd-Prod-nd : ∀ {Γ A B C D} → Term (A ‘→'’ B ‘→'’ C) → Term {Γ = Γ ▻ D} (W A ‘→'’ W B ‘→'’ W C) weakenProd-nd-Prod-nd {Γ} {A} {B} {C} {D} x = weakenTyp-tProd-nd-tProd-nd (w x) w→→ = weakenProd-nd-Prod-nd S₁W1 : ∀ {Γ A B C} {a : Term {Γ} A} → Term {Γ ▻ W B ‘’ a} (W1 C ‘’₁ a) → Term {Γ ▻ B} C S₁W1 = substTyp1-weakenTyp1 W1S₁W' : ∀ {Γ A T'' T' T} {a : Term {Γ} A} → Term {Γ ▻ T'' ▻ W (T' ‘’ a)} (W1 (W (T ‘’ a))) → Term {Γ ▻ T'' ▻ W (T' ‘’ a)} (W1 (W T ‘’₁ a)) W1S₁W' = weakenTyp1-substTyp-weakenTyp1-inv substTyp-weakenTyp1-inv : ∀ {Γ A T' T} {a : Term {Γ} A} → Term {Γ = (Γ ▻ T' ‘’ a)} (W (T ‘’ a)) → Term {Γ = (Γ ▻ T' ‘’ a)} (W T ‘’₁ a) substTyp-weakenTyp1-inv {a = a} x = S₁W1 (W1S₁W' (w1 x) ‘t’₁ a) S₁W' = substTyp-weakenTyp1-inv _‘∘’_ : ∀ {Γ A B C} → Term {Γ} (A ‘→'’ B) → Term {Γ} (B ‘→'’ C) → Term {Γ} (A ‘→'’ C) g ‘∘’ f = ‘λ∙’ (w→ f ‘'’ₐ (w→ g ‘'’ₐ ‘VAR₀’)) WS₀₀W1 : ∀ {Γ T' B A} {b : Term {Γ} B} {a : Term {Γ ▻ B} (W A)} {T : Typ (Γ ▻ A)} → Term {Γ ▻ T'} (W (W1 T ‘’ a ‘’ b)) → Term {Γ ▻ T'} (W (T ‘’ (SW (a ‘t’ b)))) WS₀₀W1 = weakenTyp-substTyp-substTyp-weakenTyp1 WS₀₀W1' : ∀ {Γ T' B A} {b : Term {Γ} B} {a : Term {Γ ▻ B} (W A)} {T : Typ (Γ ▻ A)} → Term {Γ ▻ T'} (W (T ‘’ (SW (a ‘t’ b)))) → Term {Γ ▻ T'} (W (W1 T ‘’ a ‘’ b)) WS₀₀W1' = weakenTyp-substTyp-substTyp-weakenTyp1-inv substTyp-substTyp-weakenTyp1-inv-arr : ∀ {Γ B A} {b : Term {Γ} B} {a : Term {Γ ▻ B} (W A)} {T : Typ (Γ ▻ A)} {X} → Term {Γ} (T ‘’ (SW (a ‘t’ b)) ‘→'’ X) → Term {Γ} (W1 T ‘’ a ‘’ b ‘→'’ X) substTyp-substTyp-weakenTyp1-inv-arr x = ‘λ∙’ (w→ x ‘'’ₐ WS₀₀W1 ‘VAR₀’) S₀₀W1'→ = substTyp-substTyp-weakenTyp1-inv-arr substTyp-substTyp-weakenTyp1-arr-inv : ∀ {Γ B A} {b : Term {Γ} B} {a : Term {Γ ▻ B} (W A)} {T : Typ (Γ ▻ A)} {X} → Term {Γ} (X ‘→'’ T ‘’ (SW (a ‘t’ b))) → Term {Γ} (X ‘→'’ W1 T ‘’ a ‘’ b) substTyp-substTyp-weakenTyp1-arr-inv x = ‘λ∙’ (WS₀₀W1' (un‘λ∙’ x)) S₀₀W1'← = substTyp-substTyp-weakenTyp1-arr-inv substTyp-substTyp-weakenTyp1 : ∀ {Γ B A} {b : Term {Γ} B} {a : Term {Γ ▻ B} (W A)} {T : Typ (Γ ▻ A)} → Term {Γ} (W1 T ‘’ a ‘’ b) → Term {Γ} (T ‘’ (SW (a ‘t’ b))) substTyp-substTyp-weakenTyp1 x = (SW (WS₀₀W1 (w x) ‘t’ x)) S₀₀W1 = substTyp-substTyp-weakenTyp1 SW1W : ∀ {Γ T} {A : Typ Γ} {B : Typ Γ} → {a : Term {Γ = Γ ▻ T} (W {Γ = Γ} {A = T} B)} → Term {Γ = Γ ▻ T} (W1 (W A) ‘’ a) → Term {Γ = Γ ▻ T} (W A) SW1W = substTyp-weakenTyp1-weakenTyp S₂₀₀W1WW : ∀ {Γ A} {T : Typ (Γ ▻ A)} {T' C B} {a : Term {Γ} A} {b : Term {Γ = (Γ ▻ C ‘’ a)} (B ‘’₁ a)} {c : Term {Γ = (Γ ▻ T')} (W (C ‘’ a))} → Term {Γ = (Γ ▻ T')} (W1 (W (W T) ‘’₂ a ‘’ b) ‘’ c) → Term {Γ = (Γ ▻ T')} (W (T ‘’ a)) S₂₀₀W1WW = substTyp2-substTyp-substTyp-weakenTyp1-weakenTyp-weakenTyp S₁₀W2W : ∀ {Γ T' A B T} {a : Term {Γ ▻ T'} (W A)} {b : Term {Γ ▻ T'} (W1 B ‘’ a)} → Term {Γ ▻ T'} (W2 (W T) ‘’₁ a ‘’ b) → Term {Γ ▻ T'} (W1 T ‘’ a) S₁₀W2W = substTyp1-substTyp-weakenTyp2-weakenTyp
{ "alphanum_fraction": 0.4450914015, "avg_line_length": 36.2009803922, "ext": "agda", "hexsha": "348bc3af20658c44ab7b200f21dd5da326e860a7", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JasonGross/lob", "max_forks_repo_path": "internal/well-typed-syntax-helpers.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JasonGross/lob", "max_issues_repo_path": "internal/well-typed-syntax-helpers.agda", "max_line_length": 182, "max_stars_count": 19, "max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JasonGross/lob", "max_stars_repo_path": "internal/well-typed-syntax-helpers.agda", "max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z", "num_tokens": 3908, "size": 7385 }
module Pi-.AuxLemmas where open import Data.Empty open import Data.Unit open import Data.Sum open import Data.Product open import Relation.Binary.Core open import Relation.Binary open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Data.Nat open import Data.Nat.Properties open import Data.List as L open import Function using (_∘_) open import Pi-.Syntax open import Pi-.Opsem Lemma₁ : ∀ {A B C D v v' κ κ'} {c : A ↔ B} {c' : C ↔ D} → [ c ∣ v ∣ κ ]◁ ↦ ⟨ c' ∣ v' ∣ κ' ⟩◁ → A ≡ C × B ≡ D Lemma₁ ↦⃖₁ = refl , refl Lemma₁ ↦⃖₂ = refl , refl Lemma₂ : ∀ {A B v v' κ κ'} {c c' : A ↔ B} → [ c ∣ v ∣ κ ]◁ ↦ ⟨ c' ∣ v' ∣ κ' ⟩◁ → c ≡ c' × κ ≡ κ' Lemma₂ ↦⃖₁ = refl , refl Lemma₂ ↦⃖₂ = refl , refl Lemma₃ : ∀ {A B v v' κ} {c : A ↔ B} → [ c ∣ v ∣ κ ]◁ ↦ ⟨ c ∣ v' ∣ κ ⟩◁ → base c ⊎ A ≡ B Lemma₃ (↦⃖₁ {b = b}) = inj₁ b Lemma₃ ↦⃖₂ = inj₂ refl Lemma₄ : ∀ {A v v' κ} {c : A ↔ A} → [ c ∣ v ∣ κ ]◁ ↦ ⟨ c ∣ v' ∣ κ ⟩◁ → base c ⊎ c ≡ id↔ Lemma₄ (↦⃖₁ {b = b}) = inj₁ b Lemma₄ ↦⃖₂ = inj₂ refl Lemma₅ : ∀ {A B C D v v' κ κ'} {c : A ↔ B} {c' : C ↔ D} → [ c ∣ v ∣ κ ]◁ ↦ [ c' ∣ v' ∣ κ' ]▷ → A ≡ C × B ≡ D Lemma₅ ↦η₁ = refl , refl Lemma₅ ↦η₂ = refl , refl Lemma₆ : ∀ {A B v v' κ κ'} {c c' : A ↔ B} → [ c ∣ v ∣ κ ]◁ ↦ [ c' ∣ v' ∣ κ' ]▷ → c ≡ c' × κ ≡ κ' Lemma₆ ↦η₁ = refl , refl Lemma₆ ↦η₂ = refl , refl Lemma₇ : ∀ {A B v v' κ} {c : A ↔ B} → [ c ∣ v ∣ κ ]◁ ↦ [ c ∣ v' ∣ κ ]▷ → A ≡ 𝟘 Lemma₇ ↦η₁ = refl Lemma₇ ↦η₂ = refl Lemma₈ : ∀ {A B C D v v' κ κ'} {c : A ↔ B} {c' : C ↔ D} → ⟨ c ∣ v ∣ κ ⟩▷ ↦ [ c' ∣ v' ∣ κ' ]▷ → A ≡ C × B ≡ D Lemma₈ ↦⃗₁ = refl , refl Lemma₈ ↦⃗₂ = refl , refl Lemma₉ : ∀ {A B v v' κ κ'} {c c' : A ↔ B} → ⟨ c ∣ v ∣ κ ⟩▷ ↦ [ c' ∣ v' ∣ κ' ]▷ → c ≡ c' × κ ≡ κ' Lemma₉ ↦⃗₁ = refl , refl Lemma₉ ↦⃗₂ = refl , refl Lemma₁₀ : ∀ {A B v v' κ} {c : A ↔ B} → (r : ⟨ c ∣ v ∣ κ ⟩▷ ↦ [ c ∣ v' ∣ κ ]▷) → base c ⊎ A ≡ B Lemma₁₀ (↦⃗₁ {b = b}) = inj₁ b Lemma₁₀ ↦⃗₂ = inj₂ refl Lemma₁₁ : ∀ {A v v' κ} {c : A ↔ A} → (r : ⟨ c ∣ v ∣ κ ⟩▷ ↦ [ c ∣ v' ∣ κ ]▷) → base c ⊎ c ≡ id↔ Lemma₁₁ (↦⃗₁ {b = b}) = inj₁ b Lemma₁₁ ↦⃗₂ = inj₂ refl
{ "alphanum_fraction": 0.4397291196, "avg_line_length": 27.012195122, "ext": "agda", "hexsha": "13760a127671ba6c32015c0ec9e146366d4dbeae", "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": "Pi-/AuxLemmas.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": "Pi-/AuxLemmas.agda", "max_line_length": 55, "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": "Pi-/AuxLemmas.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": 1162, "size": 2215 }
module Logic.Classical where import Lvl open import Data open import Data.Boolean open import Data.Boolean.Stmt open import Data.Boolean.Stmt.Proofs using (module IsTrue ; module IsFalse) open import Data.Boolean.Proofs open import Data.Either as Either using (_‖_) open import Data.Tuple as Tuple using (_⨯_ ; _,_) open import Functional open import Lang.Instance open import Logic open import Logic.Names open import Logic.Propositional open import Logic.Propositional.Theorems open import Logic.Predicate open import Logic.Predicate.Theorems open import Relator.Equals open import Syntax.Type open import Type open import Type.Properties.Inhabited private variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓₒ ℓₒ₁ ℓₒ₂ ℓₒ₃ ℓₗ : Lvl.Level private variable X Y Z : Type{ℓ} -- A proposition is behaving classically when excluded middle holds for it. -- In other words: For the proposition or its negation, if one of them is provable. -- It could be interpreted as: The proposition is either true or false. -- In classical logic, this is always the case for any proposition. -- Note: (∀x. Classical(P(x))) is also called: P is decidable. module _ (P : Stmt{ℓ}) where record Classical : Stmt{ℓ} where -- TODO: Rename to ExcludedMiddle. Define WeakExcludedMiddle = ExcludedMiddle ∘ ¬_ and Classical = ∀ₗ(ExcludedMiddle) constructor intro field ⦃ excluded-middle ⦄ : ExcludedMiddleOn(P) excluded-middle = inst-fn Classical.excluded-middle open Classical ⦃ ... ⦄ hiding (excluded-middle) public ------------------------------------------ -- Classical on predicates. Classical₁ : (X → Stmt{ℓₗ}) → Stmt Classical₁(P) = ∀¹(Classical ∘₁ P) Classical₂ : (X → Y → Stmt{ℓₗ}) → Stmt Classical₂(P) = ∀²(Classical ∘₂ P) Classical₃ : (X → Y → Z → Stmt{ℓₗ}) → Stmt Classical₃(P) = ∀³(Classical ∘₃ P) ------------------------------------------ -- Well-known classical rules. module _ {P : Stmt{ℓ}} ⦃ classical-P : Classical(P) ⦄ where -- Double negation elimination. [¬¬]-elim : (¬¬ P) → P [¬¬]-elim = [¬¬]-elim-from-excluded-middle (excluded-middle(P)) -- A double negated proposition is equivalent to the positive. double-negation : P ↔ (¬¬ P) double-negation = [↔]-intro [¬¬]-elim [¬¬]-intro -- The type signature of the "call/cc or "call-with-current-continuation" subroutine in the programming language Scheme. -- Also known as: "Peirce's law" call-cc-rule : ∀{Q : Stmt{ℓ₂}} → (((P → Q) → P) → P) call-cc-rule (pqp) with excluded-middle(P) ... | ([∨]-introₗ p ) = p ... | ([∨]-introᵣ np) = pqp([⊥]-elim ∘ np) -- When the negative implies the positive, thus implying a contradiction, the positive is true. -- Also called: "Clavius's Law". negative-implies-positive : ((¬ P) → P) → P negative-implies-positive npp with excluded-middle(P) ... | ([∨]-introₗ p ) = p ... | ([∨]-introᵣ np) = npp np module _ (P : Stmt{ℓ}) ⦃ classical : Classical(P) ⦄ where -- Elimination rule for the disjunction in excluded middle. excluded-middle-elim : ∀{Q : Stmt{ℓ₂}} → (P → Q) → ((¬ P) → Q) → Q excluded-middle-elim pq npq = [∨]-elim pq npq (excluded-middle(P)) ------------------------------------------ -- Contraposition rules on implication. module _ {P : Stmt{ℓ₁}} {Q : Stmt{ℓ₂}} ⦃ classical : Classical(Q) ⦄ where -- Contraposition rule in reverse removing negations. contrapositiveₗ : (P → Q) ← ((¬ P) ← (¬ Q)) contrapositiveₗ (npnq) = [¬¬]-elim ∘ (contrapositiveᵣ (npnq)) ∘ [¬¬]-intro contrapositive : (P → Q) ↔ ((¬ P) ← (¬ Q)) contrapositive = [↔]-intro contrapositiveₗ contrapositiveᵣ contrapositive-variant2ᵣ : (P ← (¬ Q)) → ((¬ P) → Q) contrapositive-variant2ᵣ = [¬¬]-elim ∘₂ (swap _∘_) module _ {P : Stmt{ℓ₁}} ⦃ classical : Classical(P) ⦄ {Q : Stmt{ℓ₂}} where contrapositive-variant2ₗ : ((¬ P) → Q) → (P ← (¬ Q)) contrapositive-variant2ₗ = contrapositiveₗ ∘ ([¬¬]-intro ∘_) module _ {P : Stmt{ℓ₁}} ⦃ classic-p : Classical(P) ⦄ {Q : Stmt{ℓ₂}} ⦃ classic-q : Classical(Q) ⦄ where contrapositive-variant2 : (P ← (¬ Q)) ↔ ((¬ P) → Q) contrapositive-variant2 = [↔]-intro contrapositive-variant2ₗ contrapositive-variant2ᵣ one-direction-implication : (P ← Q) ∨ (P → Q) one-direction-implication with excluded-middle(P) | excluded-middle(Q) one-direction-implication | [∨]-introₗ p | [∨]-introₗ q = [∨]-introₗ (const p) one-direction-implication | [∨]-introₗ p | [∨]-introᵣ nq = [∨]-introₗ (const p) one-direction-implication | [∨]-introᵣ np | [∨]-introₗ q = [∨]-introᵣ (const q) one-direction-implication | [∨]-introᵣ np | [∨]-introᵣ nq = [∨]-introᵣ ([⊥]-elim ∘ np) [¬]-injective : (P ↔ Q) ← ((¬ P) ↔ (¬ Q)) [¬]-injective ([↔]-intro nqnp npnq) = [↔]-intro (contrapositiveₗ ⦃ classic-p ⦄ npnq) (contrapositiveₗ ⦃ classic-q ⦄ nqnp) [↔]-negation : (P ↔ Q) ↔ ((¬ P) ↔ (¬ Q)) [↔]-negation = [↔]-intro [¬]-injective [¬]-unaryOperator ------------------------------------------ -- XOR. module _ (P : Stmt{ℓ}) ⦃ classical : Classical(P) ⦄ where xor-negation : P ⊕ (¬ P) xor-negation with excluded-middle(P) ... | [∨]-introₗ p = [⊕]-introₗ p ([¬¬]-intro p) ... | [∨]-introᵣ np = [⊕]-introᵣ np np module _ {P : Stmt{ℓ₁}} {Q : Stmt{ℓ₂}} where classical-from-xorₗ : ⦃ xor : (P ⊕ Q) ⦄ → Classical(P) classical-from-xorₗ ⦃ xor ⦄ = intro ⦃ [⊕]-excluded-middleₗ xor ⦄ classical-from-xorᵣ : ⦃ xor : (P ⊕ Q) ⦄ → Classical(Q) classical-from-xorᵣ ⦃ xor ⦄ = intro ⦃ [⊕]-excluded-middleᵣ xor ⦄ ------------------------------------------ -- Introduction/elimination rules for Classical when combined with logical connectives. module _ {P : Stmt{ℓ}} where [¬]-classical-intro : ⦃ classical : Classical(P) ⦄ → Classical(¬ P) [¬]-classical-intro ⦃ classical-p ⦄ = intro ⦃ proof ⦄ where proof : (¬ P) ∨ (¬¬ P) proof = Either.swap(Either.mapLeft [¬¬]-intro (excluded-middle(P))) excluded-middle-classical-intro : ⦃ _ : Classical(P) ⦄ → Classical(P ∨ (¬ P)) excluded-middle-classical-intro = intro ⦃ [∨]-introₗ (excluded-middle(P)) ⦄ -- [¬]-classical-elim : ⦃ _ : Classical(¬ P) ⦄ → Classical(P) -- [¬]-classical-elim ⦃ classical ⦄ = intro ⦃ excluded-middle-elim(¬ P) ⦃ classical ⦄ [∨]-introᵣ (nnp ↦ [∨]-introₗ {!!}) ⦄ module _ {P : Stmt{ℓ₁}} {Q : Stmt{ℓ₂}} where classical-by-equivalence : (P ↔ Q) → (Classical(P) ↔ Classical(Q)) classical-by-equivalence (xy) = [↔]-intro (cy ↦ intro ⦃ proofₗ(cy) ⦄) (cx ↦ intro ⦃ proofᵣ(cx) ⦄) where proofᵣ : Classical(P) → (Q ∨ (¬ Q)) proofᵣ (classical-p) with excluded-middle(P) ⦃ classical-p ⦄ ... | [∨]-introₗ(p) = [∨]-introₗ([↔]-to-[→] xy p) ... | [∨]-introᵣ(nx) = [∨]-introᵣ(nx ∘ ([↔]-to-[←] xy)) proofₗ : Classical(Q) → (P ∨ (¬ P)) proofₗ (classical-q) with excluded-middle(Q) ⦃ classical-q ⦄ ... | [∨]-introₗ(q) = [∨]-introₗ([↔]-to-[←] xy q) ... | [∨]-introᵣ(ny) = [∨]-introᵣ(ny ∘ ([↔]-to-[→] xy)) instance [∧]-classical-intro : ⦃ classical-p : Classical(P) ⦄ → ⦃ classical-q : Classical(Q) ⦄ → Classical(P ∧ Q) [∧]-classical-intro ⦃ classical-p ⦄ ⦃ classical-q ⦄ = intro ⦃ proof ⦄ where proof : (P ∧ Q) ∨ (¬ (P ∧ Q)) proof with (excluded-middle(P) , excluded-middle(Q)) ... | ([∨]-introₗ(p) , [∨]-introₗ(q)) = [∨]-introₗ([∧]-intro(p)(q)) ... | ([∨]-introₗ(p) , [∨]-introᵣ(ny)) = [∨]-introᵣ(xy ↦ ny([∧]-elimᵣ(xy))) ... | ([∨]-introᵣ(nx) , [∨]-introₗ(q)) = [∨]-introᵣ(xy ↦ nx([∧]-elimₗ(xy))) ... | ([∨]-introᵣ(nx) , [∨]-introᵣ(ny)) = [∨]-introᵣ(xy ↦ nx([∧]-elimₗ(xy))) instance [∨]-classical-intro : ⦃ classical-p : Classical(P) ⦄ → ⦃ classical-q : Classical(Q) ⦄ → Classical(P ∨ Q) [∨]-classical-intro ⦃ classical-p ⦄ ⦃ classical-q ⦄ = intro ⦃ proof ⦄ where proof : (P ∨ Q) ∨ (¬ (P ∨ Q)) proof with (excluded-middle(P) , excluded-middle(Q)) ... | ([∨]-introₗ(p) , [∨]-introₗ(q)) = [∨]-introₗ([∨]-introₗ(p)) ... | ([∨]-introₗ(p) , [∨]-introᵣ(ny)) = [∨]-introₗ([∨]-introₗ(p)) ... | ([∨]-introᵣ(nx) , [∨]-introₗ(q)) = [∨]-introₗ([∨]-introᵣ(q)) ... | ([∨]-introᵣ(nx) , [∨]-introᵣ(ny)) = [∨]-introᵣ(xy ↦ [∨]-elim(nx)(ny) (xy)) instance [→]-classical-intro : ⦃ classical-p : Classical(P) ⦄ → ⦃ classical-q : Classical(Q) ⦄ → Classical(P → Q) [→]-classical-intro ⦃ classical-p ⦄ ⦃ classical-q ⦄ = intro ⦃ proof ⦄ where proof : (P → Q) ∨ (¬ (P → Q)) proof with (excluded-middle(P) , excluded-middle(Q)) ... | ([∨]-introₗ(p) , [∨]-introₗ(q)) = [∨]-introₗ(const(q)) ... | ([∨]-introₗ(p) , [∨]-introᵣ(ny)) = [∨]-introᵣ([¬→][∧]ₗ ([∧]-intro p ny)) ... | ([∨]-introᵣ(nx) , [∨]-introₗ(q)) = [∨]-introₗ(const(q)) ... | ([∨]-introᵣ(nx) , [∨]-introᵣ(ny)) = [∨]-introₗ([⊥]-elim ∘ nx) instance [↔]-classical-intro : ⦃ _ : Classical(P) ⦄ → ⦃ _ : Classical(Q) ⦄ → Classical(P ↔ Q) [↔]-classical-intro ⦃ classical-p ⦄ ⦃ classical-q ⦄ = intro ⦃ proof ⦄ where proof : (P ↔ Q) ∨ (¬ (P ↔ Q)) proof with (excluded-middle(P) , excluded-middle(Q)) ... | ([∨]-introₗ(p) , [∨]-introₗ(q)) = [∨]-introₗ([↔]-intro (const(p)) (const(q))) ... | ([∨]-introₗ(p) , [∨]-introᵣ(ny)) = [∨]-introᵣ(([¬→][∧]ₗ ([∧]-intro p ny)) ∘ [↔]-to-[→]) ... | ([∨]-introᵣ(nx) , [∨]-introₗ(q)) = [∨]-introᵣ(([¬→][∧]ₗ ([∧]-intro q nx)) ∘ [↔]-to-[←]) ... | ([∨]-introᵣ(nx) , [∨]-introᵣ(ny)) = [∨]-introₗ([↔]-intro ([⊥]-elim ∘ ny) ([⊥]-elim ∘ nx)) instance [⊤]-classical-intro : Classical(⊤) [⊤]-classical-intro = intro ⦃ [∨]-introₗ ([⊤]-intro) ⦄ instance [⊥]-classical-intro : Classical(⊥) [⊥]-classical-intro = intro ⦃ [∨]-introᵣ (id) ⦄ module _ {X : Type{ℓ₁}} ⦃ _ : (◊ X) ⦄ {P : X → Stmt{ℓ₂}} where instance [∃]-classical-elim : ⦃ _ : Classical(∃ P) ⦄ → ∃(x ↦ Classical(P(x))) [∃]-classical-elim ⦃ classical-expx ⦄ with excluded-middle(∃ P) ... | [∨]-introₗ(expx) = [∃]-intro([∃]-witness(expx)) ⦃ intro ⦃ [∨]-introₗ([∃]-proof(expx)) ⦄ ⦄ ... | [∨]-introᵣ(nexpx) = [∃]-intro([◊]-existence) ⦃ intro ⦃ [∨]-introᵣ([¬∃]-to-[∀¬] (nexpx) {[◊]-existence}) ⦄ ⦄ ------------------------------------------ -- ??? module _ {P : Stmt{ℓ}} {Q : Stmt{ℓ₂}} ⦃ classical-Q : Classical(Q) ⦄ where -- One direction of the equivalence of implication using conjunction [→][∧]ₗ : (P → Q) ← ¬(P ∧ (¬ Q)) [→][∧]ₗ (nqnp) = [¬¬]-elim ∘ (Tuple.curry(nqnp)) -- ¬(A ∧ ¬B) → (A → ¬¬B) -- ¬(A ∧ (¬ B)) //assumption -- ((A ∧ (B → ⊥)) → ⊥) //Definition: (¬) -- (A → (B → ⊥) → ⊥) //Tuple.curry -- (A → ¬(B → ⊥)) //Definition: (¬) -- (A → ¬(¬ B)) //Definition: (¬) [→][∧] : (P → Q) ↔ ¬(P ∧ (¬ Q)) [→][∧] = [↔]-intro [→][∧]ₗ [→][∧]ᵣ module _ {P : Stmt{ℓ}} ⦃ classical-P : Classical(P) ⦄ where -- One direction of the equivalence of implication using disjunction [→]-disjunctive-formᵣ : ∀{Q : Stmt{ℓ₂}} → (P → Q) → ((¬ P) ∨ Q) [→]-disjunctive-formᵣ (pq) with excluded-middle(P) ... | [∨]-introₗ(p) = [∨]-introᵣ(pq(p)) ... | [∨]-introᵣ(np) = [∨]-introₗ(np) [→]-disjunctive-form : ∀{Q : Stmt{ℓ₂}} → (P → Q) ↔ ((¬ P) ∨ Q) [→]-disjunctive-form = [↔]-intro [→]-disjunctive-formₗ [→]-disjunctive-formᵣ [→]-from-contrary : ∀{Q : Stmt{ℓ₂}} → (Q → (¬ P) → ⊥) → (Q → P) [→]-from-contrary = [¬¬]-elim ∘_ [¬→]-disjunctive-formᵣ : ∀{Q : Stmt{ℓ₂}} → ((¬ P) → Q) → (P ∨ Q) [¬→]-disjunctive-formᵣ npq = excluded-middle-elim P [∨]-introₗ ([∨]-introᵣ ∘ npq) [¬→]-disjunctive-form : ∀{Q : Stmt{ℓ₂}} → ((¬ P) → Q) ↔ (P ∨ Q) [¬→]-disjunctive-form = [↔]-intro [¬→]-disjunctive-formₗ [¬→]-disjunctive-formᵣ -- [↔]-disjunctive-form : ∀{Q : Stmt{ℓ₂}} → (P ↔ Q) ↔ (P ∧ Q) ∨ ((¬ P) ∧ (¬ Q)) -- [↔]-disjunctive-form = [↔]-intro [↔]-disjunctive-formₗ ? module _ {Q : Stmt{ℓ₂}} {R : Stmt{ℓ₃}} where [→][∨]-distributivityₗ : (P → (Q ∨ R)) ↔ ((P → Q) ∨ (P → R)) [→][∨]-distributivityₗ = [↔]-intro [→][∨]-distributivityₗₗ r where r : (P → (Q ∨ R)) → ((P → Q) ∨ (P → R)) r pqr = excluded-middle-elim P ([∨]-elim2 const const ∘ pqr) ([∨]-introₗ ∘ ([⊥]-elim ∘_)) module _ {P : Stmt{ℓ₁}} ⦃ classic-p : Classical(P) ⦄ {Q : Stmt{ℓ₂}} ⦃ classic-q : Classical(Q) ⦄ where [¬→][∧]ᵣ : ¬(P → Q) → (P ∧ (¬ Q)) [¬→][∧]ᵣ = contrapositive-variant2ₗ ⦃ [∧]-classical-intro {P = P}{Q = ¬ Q} ⦃ classical-q = [¬]-classical-intro ⦄ ⦄ ([→][∧]ₗ {Q = Q}) [¬→][∧] : ¬(P → Q) ↔ (P ∧ (¬ Q)) [¬→][∧] = [↔]-intro [¬→][∧]ₗ [¬→][∧]ᵣ classical-topOrBottom : ∀{P : Stmt{ℓ}} → (Classical(P) ↔ TopOrBottom(_↔_)(P)) _⨯_.left (classical-topOrBottom {P = P}) tb = intro ⦃ [∨]-elim2 ([↔]-elimₗ [⊤]-intro) [↔]-to-[→] tb ⦄ _⨯_.right (classical-topOrBottom {P = P}) classical = excluded-middle-elim P ⦃ classical ⦄ ([∨]-introₗ ∘ provable-top-equivalence) (([∨]-introᵣ ∘ unprovable-bottom-equivalence)) ------------------------------------------ -- Negation is almost preserved over the conjunction-dijunction dual (De-morgan's laws). module _ {P : Stmt{ℓ₁}} ⦃ classic-p : Classical(P) ⦄ {Q : Stmt{ℓ₂}} ⦃ classic-q : Classical(Q) ⦄ where [¬]-preserves-[∧][∨]ᵣ : ¬(P ∧ Q) → ((¬ P) ∨ (¬ Q)) [¬]-preserves-[∧][∨]ᵣ npq = [→]-disjunctive-formᵣ {P = P} {Q = ¬ Q} ([→][∧]ₗ ⦃ [¬]-classical-intro ⦄ (npq ∘ (Tuple.mapRight ([¬¬]-elim {P = Q})))) [¬]-preserves-[∧][∨] : ¬(P ∧ Q) ↔ ((¬ P) ∨ (¬ Q)) [¬]-preserves-[∧][∨] = [↔]-intro [¬]-preserves-[∧][∨]ₗ [¬]-preserves-[∧][∨]ᵣ {- TODO: Organize Logic.Classical.DoubleNegated, and this is already proven in there, though this result is more general. module _ {P : Stmt{ℓ₁}} {Q : Stmt{ℓ₂}} where [¬]-preserves-[∧][∨]ᵣ-weak-excluded-middle : (¬(P ∧ Q) → ((¬ P) ∨ (¬ Q))) ← (Classical(¬ P) ∧ Classical(¬ Q)) [¬]-preserves-[∧][∨]ᵣ-weak-excluded-middle ([↔]-intro (intro ⦃ pex ⦄) (intro ⦃ qex ⦄)) npq with pex | qex ... | [∨]-introₗ np | [∨]-introₗ nq = [∨]-introₗ np ... | [∨]-introₗ np | [∨]-introᵣ nnq = [∨]-introₗ np ... | [∨]-introᵣ nnp | [∨]-introₗ nq = [∨]-introᵣ nq ... | [∨]-introᵣ nnp | [∨]-introᵣ nnq with () ← (DoubleNegated.[∧]-intro nnp nnq) npq -} -- TODO: See TODO directly above weak-excluded-middle-[¬]-preserves-[∧][∨]ᵣ : (∀{P : Stmt{ℓ}} → Classical(¬ P)) ↔ (∀{P : Stmt{ℓ}}{Q : Stmt{ℓ}} → ¬(P ∧ Q) → ((¬ P) ∨ (¬ Q))) weak-excluded-middle-[¬]-preserves-[∧][∨]ᵣ = [↔]-intro l r where l : (∀{P} → Classical(¬ P)) ← (∀{P}{Q} → ¬(P ∧ Q) → ((¬ P) ∨ (¬ Q))) l pres {P} = intro ⦃ pres{P}{¬ P} non-contradiction ⦄ r : (∀{P} → Classical(¬ P)) → (∀{P}{Q} → ¬(P ∧ Q) → ((¬ P) ∨ (¬ Q))) r wem {P}{Q} npq with excluded-middle(¬ P) ⦃ wem ⦄ | excluded-middle(¬ Q) ⦃ wem ⦄ ... | [∨]-introₗ np | [∨]-introₗ nq = [∨]-introₗ np ... | [∨]-introₗ np | [∨]-introᵣ nnq = [∨]-introₗ np ... | [∨]-introᵣ nnp | [∨]-introₗ nq = [∨]-introᵣ nq ... | [∨]-introᵣ nnp | [∨]-introᵣ nnq = [∨]-introₗ (p ↦ nnq(q ↦ npq([∧]-intro p q))) ------------------------------------------ -- Predicate logic. module _ {P : Stmt{ℓ}} ⦃ classical-P : Classical(P) ⦄ {X : Type{ℓ₂}} ⦃ pos@(intro ⦃ x ⦄) : (◊ X) ⦄ {Q : X → Stmt{ℓ₃}} where [∃]-unrelatedᵣ-[→]ₗ : ∃(x ↦ (P → Q(x))) ← (P → ∃(x ↦ Q(x))) [∃]-unrelatedᵣ-[→]ₗ pexqx with excluded-middle(P) ... | ([∨]-introₗ p) = [∃]-map-proof (const) (pexqx(p)) ... | ([∨]-introᵣ np) = [∃]-intro(x) ⦃ [⊥]-elim {P = Q(x)} ∘ np ⦄ [∃]-unrelatedᵣ-[→] : ∃(x ↦ (P → Q(x))) ↔ (P → ∃(x ↦ Q(x))) [∃]-unrelatedᵣ-[→] = [↔]-intro [∃]-unrelatedᵣ-[→]ₗ [∃]-unrelatedᵣ-[→]ᵣ module _ {X : Type{ℓ₁}} ⦃ _ : (◊ X) ⦄ {P : X → Stmt{ℓ₂}} ⦃ classical-expx : Classical(∃ P) ⦄ {Q : X → Stmt{ℓ₃}} where [∃][←]-distributivity : ∃(x ↦ (P(x) → Q(x))) ← (∃(x ↦ P(x)) → ∃(x ↦ Q(x))) [∃][←]-distributivity (expx-exqx) = (([∃]-map-proof (\{x} → proof ↦ proof{x}) (([∃]-map-proof (\{x} → [↔]-to-[←] ([∀]-unrelatedₗ-[→] {X = X}{P}{Q(x)})) (([∃]-unrelatedᵣ-[→]ₗ ⦃ classical-expx ⦄ (expx-exqx :of: (∃(x ↦ P(x)) → ∃(x ↦ Q(x)))) ) :of: (∃(x ↦ (∃(x ↦ P(x)) → Q(x))))) ) :of: (∃(x ↦ ∀ₗ(y ↦ (P(y) → Q(x)))))) ) :of: (∃(x ↦ (P(x) → Q(x))))) {- module _ {X : Type{ℓ₁}} ⦃ _ : (◊ X) ⦄ {P : X → Stmt{ℓ₂}} where [¬∀¬]-to-[∃] : (∃ P) ← ¬(∀ₗ(¬_ ∘ P)) [¬∀¬]-to-[∃] x = {!!} -- TODO: When is this true? [∃]-classical-intro : ⦃ _ : Classical(∀ₗ P) ⦄ ⦃ _ : Classical(∀ₗ(¬_ ∘ P)) ⦄ → Classical(∃ P) Classical.excluded-middle ([∃]-classical-intro ⦃ classical-pa ⦄ ⦃ classical-npa ⦄) with excluded-middle(∀ₗ P) | excluded-middle(∀ₗ(¬_ ∘ P)) ... | [∨]-introₗ ap | [∨]-introₗ nap with () ← nap(ap {[◊]-existence}) ... | [∨]-introₗ ap | [∨]-introᵣ nanp = [∨]-introₗ ([∃]-intro [◊]-existence ⦃ ap ⦄) ... | [∨]-introᵣ npa | [∨]-introₗ nap = [∨]-introᵣ ([∀¬]-to-[¬∃] nap) ... | [∨]-introᵣ npa | [∨]-introᵣ nanp = [∨]-introₗ ([¬∀¬]-to-[∃] nanp) -} -- TODO: Maybe try to get rid of the second instance assumption? Idea: Only [¬¬]-elim is needed for that one, so if possible and true, prove: (∀{x} → Classic(P(x)) → P(x)) → (Classic(∃ P) → (∃ P)). No, that is probably not true module _ {X : Type{ℓ₁}}{P : X → Stmt{ℓ₂}} ⦃ classical-proof1 : ∀{x} → Classical(P(x)) ⦄ ⦃ classical-proof2 : Classical(∃(¬_ ∘ P)) ⦄ where [¬∀]-to-[∃¬] : ∃(x ↦ ¬(P(x))) ← ¬(∀ₗ(x ↦ P(x))) [¬∀]-to-[∃¬] (naxpx) = ([¬¬]-elim ⦃ classical-proof2 ⦄ ([¬]-intro {P = ¬ ∃(x ↦ ¬(P(x)))} (nexnpx ↦ (naxpx ([∀][→]-distributivity {X = X}{¬¬_ ∘ P} ((\{x} → [¬¬]-elim ⦃ classical-proof1{x} ⦄) :of: ∀ₗ(x ↦ (¬¬ P(x) → P(x)))) ([¬∃]-to-[∀¬] (nexnpx) :of: ∀ₗ(x ↦ ¬¬ P(x))) :of: ∀ₗ(x ↦ P(x))) ) :of: ⊥ ) :of: (¬¬ ∃(x ↦ ¬ P(x)))) ) :of: ∃(x ↦ ¬ P(x)) -- ¬∀x. P(x) -- • ¬∃x. ¬P(x) -- ¬∃x. ¬P(x) -- ⇒ ∀x. ¬¬P(x) -- ⇒ ∀x. P(x) -- ⇒ ⊥ -- ⇒ ¬¬∃x. ¬P(x) -- ⇒ ∃x. ¬P(x) [∃]-unrelatedₗ-[→]ₗ : ⦃ _ : ◊ X ⦄ → ⦃ _ : Classical(∀ₗ P) ⦄ → ∀{Q : Stmt{ℓ₃}} → ∃(x ↦ (P(x) → Q)) ← (∀ₗ(x ↦ P(x)) → Q) [∃]-unrelatedₗ-[→]ₗ ⦃ pos-x ⦄ ⦃ classical-axpx ⦄ {Q} axpxq with excluded-middle(∀ₗ P) ... | ([∨]-introₗ axpx) = [∃]-intro([◊]-existence) ⦃ const(axpxq (axpx)) ⦄ ... | ([∨]-introᵣ naxpx) = [∃]-map-proof ([⊥]-elim ∘_) ([¬∀]-to-[∃¬] (naxpx)) -- (∀x. P(x)) → Q -- • ∀x. P(x) -- ∀x. P(x) -- ⇒ ∀x. P(x) -- ⇒ Q -- ⇒ P(a) → Q -- ⇒ ∃x. P(x) → Q -- • ¬∀x. P(x) -- ¬∀x. P(x) -- ⇒ ∃x. ¬P(x) -- ⇒ ∃x. P(x) → Q -- Also known as: Drinker paradox drinker-ambiguity : ⦃ _ : ◊ X ⦄ → ⦃ _ : Classical(∀ₗ P) ⦄ → ∃(x ↦ (P(x) → ∀{y} → P(y))) drinker-ambiguity = [∃]-map-proof (\pxap px {y} → pxap px {y}) ([∃]-unrelatedₗ-[→]ₗ id) drinker-ambiguity-equiv : ⦃ _ : Classical(∀ₗ P) ⦄ → ((◊ X) ↔ ∃(x ↦ (P(x) → ∀{y} → P(y)))) drinker-ambiguity-equiv ⦃ classical-axpx ⦄ = [↔]-intro (\ex → intro ⦃ [∃]-witness ex ⦄) (\pos-x → drinker-ambiguity ⦃ pos-x ⦄ ⦃ classical-axpx ⦄)
{ "alphanum_fraction": 0.5131458187, "avg_line_length": 47.616966581, "ext": "agda", "hexsha": "1f128298e993db11634af5bc063e29619aa90888", "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": "Logic/Classical.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": "Logic/Classical.agda", "max_line_length": 227, "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": "Logic/Classical.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": 8321, "size": 18523 }
module SignedBy where open import Data.String open import Relation.Binary.PropositionalEquality open import Data.Nat -- this is easy to write --- but ignoring for now postulate Word512 : Set {- signed by val with noncing by identity == really needs to be part of a freshly generated challenge /uuid string mixed into the response to ensure it can be MIM'd and rerouted to unrelated transactions a related issue is making sure the signeatures at values and on the overall module/transaction unit are 'entangled' together so that manipulations wont validate for manny applications it'd suffice to just do a signed by of a module/program as a whole -} postulate signed_nonced_by_ : {a : Set} -> a -> Word512 -> String -> Set postulate canonicalHash : {a : Set} -> a -> Word512 postulate canonicalNoncedHash : { a : Set} -> a -> Word512 -> Word512 postulate getSignedVal : {a : Set} -> {nonce : Word512 } { sig : String } {v : a} (sigVal : signed v nonced nonce by sig ) -> a postulate getSignedValEta : {a : Set} {v : a} { n : Word512} {i : String} -> (x : signed v nonced n by i ) -> ( v ≡ getSignedVal x ) {- -}
{ "alphanum_fraction": 0.7121346324, "avg_line_length": 36.4193548387, "ext": "agda", "hexsha": "b84e118df18a4e0844a0913b74742dd988907a75", "lang": "Agda", "max_forks_count": 10, "max_forks_repo_forks_event_max_datetime": "2016-09-21T15:11:45.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-26T20:09:07.000Z", "max_forks_repo_head_hexsha": "9dd16246800cf093157a2817ddbbed82d0f20b3d", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "hopper-lang/hopper", "max_forks_repo_path": "models/agda/SignedBy.agda", "max_issues_count": 21, "max_issues_repo_head_hexsha": "9dd16246800cf093157a2817ddbbed82d0f20b3d", "max_issues_repo_issues_event_max_datetime": "2016-06-02T22:26:22.000Z", "max_issues_repo_issues_event_min_datetime": "2016-03-03T16:47:57.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "hopper-lang/hopper", "max_issues_repo_path": "models/agda/SignedBy.agda", "max_line_length": 136, "max_stars_count": 99, "max_stars_repo_head_hexsha": "9dd16246800cf093157a2817ddbbed82d0f20b3d", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "hopper-lang/hopper", "max_stars_repo_path": "models/agda/SignedBy.agda", "max_stars_repo_stars_event_max_datetime": "2017-03-02T11:35:17.000Z", "max_stars_repo_stars_event_min_datetime": "2016-02-26T19:35:15.000Z", "num_tokens": 313, "size": 1129 }
-- Andreas, 2014-10-09, issue reported by Matteo Acerbi module _ where module A where module B (let module F = A) where module C (let module F = A) where -- Complains about duplicate F -- Should work
{ "alphanum_fraction": 0.712195122, "avg_line_length": 15.7692307692, "ext": "agda", "hexsha": "250ff475253c8cf4aec41475d062e7cd5b88a0eb", "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/Issue1299.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/Issue1299.agda", "max_line_length": 55, "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/Issue1299.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": 61, "size": 205 }
-- Andreas, 2012-05-04 Example from Jason Reed, LFMTP 2009 {-# OPTIONS --allow-unsolved-metas #-} -- The option is supplied to force a real error to pass the regression test. module JasonReedPruning where open import Common.Equality open import Common.Product data o : Set where f : o -> o test : let U : o → o U = _ V : o → o V = _ W : o → o W = _ in (x y : o) → U x ≡ f (V (W y)) × V x ≡ U (W y) test x y = refl , refl {- Considering U (W y) = V x, we can prune x from V V x = V' After instantiation U x = f V' (solved) V' = U (W y) (not solved) U = \ x → f V' V' = f V' occurs check fails -}
{ "alphanum_fraction": 0.5324675325, "avg_line_length": 19.25, "ext": "agda", "hexsha": "5e304c0d650de105fbec8223391d5945652814c4", "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": "4383a3d20328a6c43689161496cee8eb479aca08", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dagit/agda", "max_forks_repo_path": "test/fail/JasonReedPruning.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4383a3d20328a6c43689161496cee8eb479aca08", "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": "dagit/agda", "max_issues_repo_path": "test/fail/JasonReedPruning.agda", "max_line_length": 76, "max_stars_count": 1, "max_stars_repo_head_hexsha": "4383a3d20328a6c43689161496cee8eb479aca08", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dagit/agda", "max_stars_repo_path": "test/fail/JasonReedPruning.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-27T07:26:06.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-27T07:26:06.000Z", "num_tokens": 237, "size": 693 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Decidable.Relations where DecidableRelation : {a b : _} {A : Set a} (f : A → Set b) → Set (a ⊔ b) DecidableRelation {A = A} f = (x : A) → (f x) || (f x → False) orDecidable : {a b c : _} {A : Set a} {f : A → Set b} {g : A → Set c} → DecidableRelation f → DecidableRelation g → DecidableRelation (λ x → (f x) || (g x)) orDecidable fDec gDec x with fDec x orDecidable fDec gDec x | inl fx = inl (inl fx) orDecidable fDec gDec x | inr !fx with gDec x orDecidable fDec gDec x | inr !fx | inl gx = inl (inr gx) orDecidable {f = f} {g} fDec gDec x | inr !fx | inr !gx = inr t where t : (f x || g x) → False t (inl x) = !fx x t (inr x) = !gx x andDecidable : {a b c : _} {A : Set a} {f : A → Set b} {g : A → Set c} → DecidableRelation f → DecidableRelation g → DecidableRelation (λ x → (f x) && (g x)) andDecidable fDec gDec x with fDec x andDecidable fDec gDec x | inl fx with gDec x andDecidable fDec gDec x | inl fx | inl gx = inl (fx ,, gx) andDecidable fDec gDec x | inl fx | inr !gx = inr (λ x → !gx (_&&_.snd x)) andDecidable fDec gDec x | inr !fx = inr (λ x → !fx (_&&_.fst x)) notDecidable : {a b : _} {A : Set a} {f : A → Set b} → DecidableRelation f → DecidableRelation (λ x → (f x) → False) notDecidable fDec x with fDec x notDecidable fDec x | inl fx = inr (λ x → x fx) notDecidable fDec x | inr !fx = inl !fx doubleNegation : {a b : _} {A : Set a} {f : A → Set b} → DecidableRelation f → (x : A) → (((f x) → False) → False) → f x doubleNegation fDec x with fDec x doubleNegation fDec x | inl fx = λ _ → fx doubleNegation fDec x | inr !fx = λ p → exFalso (p !fx)
{ "alphanum_fraction": 0.6190201729, "avg_line_length": 45.6578947368, "ext": "agda", "hexsha": "cbd245ea512ae0a440fdcead7e60e43266b0b957", "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": "Decidable/Relations.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": "Decidable/Relations.agda", "max_line_length": 157, "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": "Decidable/Relations.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": 679, "size": 1735 }
-- 2013-06-15 Andreas, issue reported by Stevan Andjelkovic module Issue854 where infixr 1 _⊎_ infixr 2 _×_ infixr 4 _,_ infix 4 _≡_ data ⊥ : Set where ⊥-elim : {A : Set} → ⊥ → A ⊥-elim () record ⊤ : Set where constructor tt data Bool : Set where true false : Bool data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ data Maybe (A : Set) : Set where nothing : Maybe A just : (x : A) → Maybe A data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x data _⊎_ (A : Set) (B : Set) : Set where inj₁ : (x : A) → A ⊎ B inj₂ : (y : B) → A ⊎ B [_,_] : ∀ {A : Set} {B : Set} {C : A ⊎ B → Set} → ((x : A) → C (inj₁ x)) → ((x : B) → C (inj₂ x)) → ((x : A ⊎ B) → C x) [ f , g ] (inj₁ x) = f x [ f , g ] (inj₂ y) = g y [_,_]₁ : ∀ {A : Set} {B : Set} {C : A ⊎ B → Set₁} → ((x : A) → C (inj₁ x)) → ((x : B) → C (inj₂ x)) → ((x : A ⊎ B) → C x) [ f , g ]₁ (inj₁ x) = f x [ f , g ]₁ (inj₂ y) = g y record Σ (A : Set) (B : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ public _×_ : Set → Set → Set A × B = Σ A λ _ → B uncurry₁ : {A : Set} {B : A → Set} {C : Σ A B → Set₁} → ((x : A) → (y : B x) → C (x , y)) → ((p : Σ A B) → C p) uncurry₁ f (x , y) = f x y ------------------------------------------------------------------------ infix 5 _◃_ infixr 1 _⊎C_ infixr 2 _×C_ record Container : Set₁ where constructor _◃_ field Shape : Set Position : Shape → Set open Container public ⟦_⟧ : Container → (Set → Set) ⟦ S ◃ P ⟧ X = Σ S λ s → P s → X idC : Container idC = ⊤ ◃ λ _ → ⊤ constC : Set → Container constC X = X ◃ λ _ → ⊥ 𝟘 = constC ⊥ 𝟙 = constC ⊤ _⊎C_ : Container → Container → Container S ◃ P ⊎C S′ ◃ P′ = (S ⊎ S′) ◃ [ P , P′ ]₁ _×C_ : Container → Container → Container S ◃ P ×C S′ ◃ P′ = (S × S′) ◃ uncurry₁ (λ s s′ → P s ⊎ P′ s′) data μ (C : Container) : Set where ⟨_⟩ : ⟦ C ⟧ (μ C) → μ C _⋆C_ : Container → Set → Container C ⋆C X = constC X ⊎C C _⋆_ : Container → Set → Set C ⋆ X = μ (C ⋆C X) AlgIter : Container → Set → Set AlgIter C X = ⟦ C ⟧ X → X iter : ∀ {C X} → AlgIter C X → μ C → X iter φ ⟨ s , k ⟩ = φ (s , λ p → iter φ (k p)) AlgRec : Container → Set → Set AlgRec C X = ⟦ C ⟧ (μ C × X) → X rec : ∀ {C X} → AlgRec C X → μ C → X rec φ ⟨ s , k ⟩ = φ (s , λ p → (k p , rec φ (k p))) return : ∀ {C X} → X → C ⋆ X return x = ⟨ inj₁ x , ⊥-elim ⟩ do : ∀ {C X} → ⟦ C ⟧ (C ⋆ X) → C ⋆ X do (s , k) = ⟨ inj₂ s , k ⟩ _>>=_ : ∀ {C X Y} → C ⋆ X → (X → C ⋆ Y) → C ⋆ Y _>>=_ {C}{X}{Y} m k = iter φ m where φ : AlgIter (C ⋆C X) (C ⋆ Y) φ (inj₁ x , _) = k x φ (inj₂ s , k) = do (s , k) ------------------------------------------------------------------------ _↠_ : Set → Set → Container I ↠ O = I ◃ λ _ → O State : Set → Container State S = (⊤ ↠ S) -- get ⊎C (S ↠ ⊤) -- put get : ∀ {S} → State S ⋆ S get = do (inj₁ tt , return) put : ∀ {S} → S → State S ⋆ ⊤ put s = do (inj₂ s , return) Homo : Container → Set → Set → Container → Set → Set Homo Σ X I Σ′ Y = AlgRec (Σ ⋆C X) (I → Σ′ ⋆ Y) Pseudohomo : Container → Set → Set → Container → Set → Set Pseudohomo Σ X I Σ′ Y = ⟦ Σ ⋆C X ⟧ (((Σ ⊎C Σ′) ⋆ X) × (I → Σ′ ⋆ Y)) → I → Σ′ ⋆ Y state : ∀ {Σ S X} → Pseudohomo (State S) X S Σ (X × S) state (inj₁ x , _) = λ s → return (x , s) -- return state (inj₂ (inj₁ _) , k) = λ s → proj₂ (k s) s -- get state (inj₂ (inj₂ s) , k) = λ _ → proj₂ (k tt) s -- put Abort : Container Abort = ⊤ ↠ ⊥ aborting : ∀ {X} → Abort ⋆ X aborting = do (tt , ⊥-elim) abort : ∀ {Σ X} → Pseudohomo Abort X ⊤ Σ (Maybe X) abort (inj₁ x , _) _ = return (just x) -- return abort (inj₂ _ , _) _ = return nothing -- abort ------------------------------------------------------------------------ record _⇒_ (C C′ : Container) : Set where field shape : Shape C → Shape C′ position : ∀ {s} → Position C′ (shape s) → Position C s open _⇒_ public idMorph : ∀ {C} → C ⇒ C idMorph = record { shape = λ s → s; position = λ p → p } inlMorph : ∀ {C C′ : Container} → C ⇒ (C ⊎C C′) inlMorph = record { shape = inj₁ ; position = λ p → p } swapMorph : ∀ {C C′} → (C ⊎C C′) ⇒ (C′ ⊎C C) swapMorph {C}{C′}= record { shape = sh ; position = λ {s} p → pos {s} p } where sh : Shape C ⊎ Shape C′ → Shape C′ ⊎ Shape C sh (inj₁ s) = inj₂ s sh (inj₂ s′) = inj₁ s′ pos : ∀ {s} → Position (C′ ⊎C C) (sh s) → Position (C ⊎C C′) s pos {inj₁ s} p = p pos {inj₂ s′} p′ = p′ ⟪_⟫ : ∀ {C C′ X} → C ⇒ C′ → ⟦ C ⟧ X → ⟦ C′ ⟧ X ⟪ m ⟫ xs = shape m (proj₁ xs) , λ p′ → proj₂ xs (position m p′) ⟪_⟫Homo : ∀ {C C′ X} → C ⇒ C′ → Homo C X ⊤ C′ X ⟪ m ⟫Homo (inj₁ x , _) _ = return x ⟪ m ⟫Homo (inj₂ s , k) _ = let (s′ , k′) = ⟪ m ⟫ (s , k) in do (s′ , λ p′ → proj₂ (k′ p′) tt) natural : ∀ {C C′ X} → C ⇒ C′ → C ⋆ X → C′ ⋆ X natural f m = rec ⟪ f ⟫Homo m tt inl : ∀ {C C′ X} → C ⋆ X → (C ⊎C C′) ⋆ X inl = natural inlMorph squeeze : ∀ {Σ Σ′ X} → ((Σ ⊎C Σ′) ⊎C Σ′) ⋆ X → (Σ ⊎C Σ′) ⋆ X squeeze = natural m where m = record { shape = [ (λ x → x) , inj₂ ] ; position = λ { {inj₁ x} p → p ; {inj₂ x} p → p} } lift : ∀ {Σ Σ′ X Y I} → Pseudohomo Σ X I Σ′ Y → Pseudohomo (Σ ⊎C Σ′) X I Σ′ Y lift φ (inj₁ x , _) i = φ (inj₁ x , ⊥-elim) i lift φ (inj₂ (inj₁ s) , k) i = φ (inj₂ s , λ p → let (w , ih) = k p in squeeze w , ih) i lift φ (inj₂ (inj₂ s′) , k′) i = do (s′ , λ p′ → proj₂ (k′ p′) i) weaken : ∀ {Σ Σ′ Σ″ Σ‴ X Y I} → Homo Σ′ X I Σ″ Y → Σ ⇒ Σ′ → Σ″ ⇒ Σ‴ → Homo Σ X I Σ‴ Y weaken {Σ}{Σ′}{Σ″}{Σ‴}{X}{Y} φ f g (s , k) i = w‴ where w : Σ ⋆ X w = ⟨ s , (λ p → proj₁ (k p)) ⟩ w′ : Σ′ ⋆ X w′ = natural f w w″ : Σ″ ⋆ Y w″ = rec φ w′ i w‴ : Σ‴ ⋆ Y w‴ = natural g w″ ⌈_⌉Homo : ∀ {Σ Σ′ X Y I} → Pseudohomo Σ X I Σ′ Y → Homo Σ X I Σ′ Y ⌈ φ ⌉Homo (inj₁ x , _) = φ (inj₁ x , ⊥-elim) ⌈ φ ⌉Homo (inj₂ s , k) = φ (inj₂ s , λ p → let (w , ih) = k p in inl w , ih) run : ∀ {Σ Σ′ Σ″ Σ‴ X Y I} → Pseudohomo Σ X I Σ′ Y → Σ″ ⇒ (Σ ⊎C Σ′) → Σ′ ⇒ Σ‴ → Σ″ ⋆ X → I → Σ‴ ⋆ Y run φ p q = rec (weaken ⌈ lift φ ⌉Homo p q) ------------------------------------------------------------------------ prog : (State ℕ ⊎C Abort) ⋆ Bool prog = ⟨ inj₂ (inj₁ (inj₁ tt)) , (λ n → -- get >>= λ n → ⟨ inj₂ (inj₁ (inj₂ (suc n))) , (λ _ → -- put (suc n) ⟨ inj₂ (inj₂ tt) , (λ _ → -- aborting return true) ⟩) ⟩) ⟩ progA : State ℕ ⋆ Maybe Bool progA = run abort swapMorph idMorph prog tt progS : ℕ → Abort ⋆ (Bool × ℕ) progS = run state idMorph idMorph prog progAS : ℕ → 𝟘 ⋆ (Maybe Bool × ℕ) progAS = run state inlMorph idMorph progA progSA : ℕ → 𝟘 ⋆ Maybe (Bool × ℕ) progSA n = run abort inlMorph idMorph (progS n) tt testSA : progSA zero ≡ return nothing testSA = refl testAS : progAS zero ≡ return (nothing , suc zero) testAS = refl -- The last statement seemed to make the type checker loop. -- But it just created huge terms during the conversion check -- and never finished. -- These terms contained many projection redexes -- (projection applied to record value). -- After changing the strategy, such that these redexes are, -- like beta-redexes, removed immediately in internal syntax, -- the code checks instantaneously.
{ "alphanum_fraction": 0.4646464646, "avg_line_length": 25.2620689655, "ext": "agda", "hexsha": "3914404ba70d090a90d46cc2444d16f2b9167834", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_path": "test/Succeed/Issue854.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "redfish64/autonomic-agda", "max_issues_repo_path": "test/Succeed/Issue854.agda", "max_line_length": 76, "max_stars_count": 3, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Succeed/Issue854.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": 3322, "size": 7326 }
-- Andreas, 2018-09-08, issue #3211 -- -- Bug with parametrized module and constructor rewriting. {-# OPTIONS --rewriting #-} -- {-# OPTIONS -v rewriting.match:90 -v rewriting:90 #-} -- {-# OPTIONS -v tc.getConType:50 #-} module _ (Base : Set) where open import Agda.Builtin.Equality {-# BUILTIN REWRITE _≡_ #-} cong : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {x y} → x ≡ y → f x ≡ f y cong f refl = refl data Form : Set where Atom : (P : Base) → Form _⇒_ : (A B : Form) → Form data Cxt : Set where ε : Cxt _∙_ : (Γ : Cxt) (A : Form) → Cxt infixl 4 _∙_ infix 3 _≤_ data _≤_ : (Γ Δ : Cxt) → Set where id≤ : ∀{Γ} → Γ ≤ Γ weak : ∀{A Γ Δ} (τ : Γ ≤ Δ) → Γ ∙ A ≤ Δ lift : ∀{A Γ Δ} (τ : Γ ≤ Δ) → Γ ∙ A ≤ Δ ∙ A postulate lift-id≤ : ∀{Γ A} → lift id≤ ≡ id≤ {Γ ∙ A} {-# REWRITE lift-id≤ #-} Mon : (P : Cxt → Set) → Set Mon P = ∀{Γ Δ} (τ : Γ ≤ Δ) → P Δ → P Γ infix 2 _⊢_ data _⊢_ (Γ : Cxt) : (A : Form) → Set where impI : ∀{A B} (t : Γ ∙ A ⊢ B) → Γ ⊢ A ⇒ B Tm = λ A Γ → Γ ⊢ A monD : ∀{A} → Mon (Tm A) -- monD : ∀{A Γ Δ} (τ : Γ ≤ Δ) → Tm A Δ → Tm A Γ -- Works -- monD : ∀{A Γ Δ} (τ : Γ ≤ Δ) → Δ ⊢ A → Γ ⊢ A -- Works monD τ (impI t) = impI (monD (lift τ) t) monD-id : ∀{Γ A} (t : Γ ⊢ A) → monD id≤ t ≡ t monD-id (impI t) = cong impI (monD-id t) -- REWRITE lift-id≤ -- -}
{ "alphanum_fraction": 0.4916030534, "avg_line_length": 23.3928571429, "ext": "agda", "hexsha": "a63c103e735e0bf523d1c9e96f27abea9120b1d5", "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/Issue3211a.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/Issue3211a.agda", "max_line_length": 61, "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/Issue3211a.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": 615, "size": 1310 }
{-# OPTIONS --cubical #-} module Type.Cubical.Equiv where import Lvl open import Type.Cubical open import Type.Cubical.Path.Equality import Type.Equiv as Type open import Type private variable ℓ₁ ℓ₂ : Lvl.Level -- `Type.Equiv._≍_` specialized to Path. _≍_ : (A : Type{ℓ₁}) → (B : Type{ℓ₂}) → Type A ≍ B = A Type.≍ B {-# BUILTIN EQUIV _≍_ #-} instance [≍]-reflexivity = \{ℓ} → Type.[≍]-reflexivity {ℓ} ⦃ Path-equiv ⦄ instance [≍]-symmetry = \{ℓ} → Type.[≍]-symmetry {ℓ} ⦃ Path-equiv ⦄ instance [≍]-transitivity = \{ℓ} → Type.[≍]-transitivity {ℓ} ⦃ Path-equiv ⦄ ⦃ Path-congruence₁ ⦄ instance [≍]-equivalence = \{ℓ} → Type.[≍]-equivalence {ℓ} ⦃ Path-equiv ⦄ ⦃ Path-congruence₁ ⦄
{ "alphanum_fraction": 0.6296296296, "avg_line_length": 24.2068965517, "ext": "agda", "hexsha": "a684813675219e3b9927fd6a0a132ca6fb8bccf7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Type/Cubical/Equiv.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Type/Cubical/Equiv.agda", "max_line_length": 89, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Type/Cubical/Equiv.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": 296, "size": 702 }
open import bool open import level open import eq open import product open import product-thms open import relations -- module closures where -- module basics {ℓ ℓ' : level}{A : Set ℓ} (_>A_ : A → A → Set ℓ') where -- data tc : A → A → Set (ℓ ⊔ ℓ') where -- tc-step : ∀{a b : A} → a >A b → tc a b -- tc-trans : ∀{a b c : A} → tc a b → tc b c → tc a c -- data rc : A → A → Set (ℓ ⊔ ℓ') where -- rc-step : ∀{a b : A} → a >A b → rc a b -- rc-refl : ∀{a : A} → rc a a -- tc-transitive : transitive tc -- tc-transitive = tc-trans -- module combinations {ℓ ℓ' : level}{A : Set ℓ} (_>A_ : A → A → Set ℓ') where -- open basics public -- rtc : A → A → Set (ℓ ⊔ ℓ') -- rtc = rc (tc _>A_) -- rtc-refl : reflexive rtc -- rtc-refl = rc-refl -- rtc-trans : transitive rtc -- rtc-trans (rc-step{a}{b} x) (rc-step{.b}{c} x') = rc-step (tc-trans x x') -- rtc-trans (rc-step x) rc-refl = rc-step x -- rtc-trans rc-refl (rc-step x) = rc-step x -- rtc-trans rc-refl rc-refl = rc-refl
{ "alphanum_fraction": 0.5195895522, "avg_line_length": 28.2105263158, "ext": "agda", "hexsha": "14c90209b52176a4d7353a32356eeef956ca13bb", "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": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "heades/AUGL", "max_forks_repo_path": "closures.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "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": "heades/AUGL", "max_issues_repo_path": "closures.agda", "max_line_length": 81, "max_stars_count": null, "max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "heades/AUGL", "max_stars_repo_path": "closures.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 392, "size": 1072 }
------------------------------------------------------------------------ -- Typing and kinding of Fω with interval kinds ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module FOmegaInt.Typing where open import Data.Context.WellFormed open import Data.Fin using (Fin; zero) open import Data.Fin.Substitution open import Data.Fin.Substitution.Lemmas open import Data.Fin.Substitution.ExtraLemmas open import Data.Fin.Substitution.Typed open import Data.Nat using (ℕ) open import Data.Product using (_,_; _×_) open import Level using () renaming (zero to lzero) open import Relation.Binary.PropositionalEquality as PropEq hiding ([_]) open import FOmegaInt.Syntax ------------------------------------------------------------------------ -- Typing derivations. module Typing where open TermCtx open Syntax open Substitution using (_[_]; _Kind[_]; weaken) infix 4 _ctx _⊢_kd _⊢_wf infix 4 _⊢Tp_∈_ _⊢Tm_∈_ _⊢_∈_ infix 4 _⊢_<:_∈_ _⊢_<∷_ _⊢_≤_ infix 4 _⊢_≃_∈_ _⊢_≅_ _⊢_≃_wf _≃_ctx mutual -- Well-formed typing contexts. _ctx : ∀ {n} → Ctx n → Set _ctx = ContextFormation._wf _⊢_wf -- Well-formed type/kind ascriptions in typing contexts. data _⊢_wf {n} (Γ : Ctx n) : TermAsc n → Set where wf-kd : ∀ {a} → Γ ⊢ a kd → Γ ⊢ (kd a) wf wf-tp : ∀ {a} → Γ ⊢Tp a ∈ * → Γ ⊢ (tp a) wf -- Well-formed kinds. data _⊢_kd {n} (Γ : Ctx n) : Kind Term n → Set where kd-⋯ : ∀ {a b} → Γ ⊢Tp a ∈ * → Γ ⊢Tp b ∈ * → Γ ⊢ a ⋯ b kd kd-Π : ∀ {j k} → Γ ⊢ j kd → kd j ∷ Γ ⊢ k kd → Γ ⊢ Π j k kd -- Kinding derivations. data _⊢Tp_∈_ {n} (Γ : Ctx n) : Term n → Kind Term n → Set where ∈-var : ∀ {k} x → Γ ctx → lookup Γ x ≡ kd k → Γ ⊢Tp var x ∈ k ∈-⊥-f : Γ ctx → Γ ⊢Tp ⊥ ∈ * ∈-⊤-f : Γ ctx → Γ ⊢Tp ⊤ ∈ * ∈-∀-f : ∀ {k a} → Γ ⊢ k kd → kd k ∷ Γ ⊢Tp a ∈ * → Γ ⊢Tp Π k a ∈ * ∈-→-f : ∀ {a b} → Γ ⊢Tp a ∈ * → Γ ⊢Tp b ∈ * → Γ ⊢Tp a ⇒ b ∈ * ∈-Π-i : ∀ {j a k} → Γ ⊢ j kd → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp Λ j a ∈ Π j k ∈-Π-e : ∀ {a b j k} → Γ ⊢Tp a ∈ Π j k → Γ ⊢Tp b ∈ j → Γ ⊢Tp a · b ∈ k Kind[ b ] ∈-s-i : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢Tp a ∈ a ⋯ a ∈-⇑ : ∀ {a j k} → Γ ⊢Tp a ∈ j → Γ ⊢ j <∷ k → Γ ⊢Tp a ∈ k -- Subkinding derivations. data _⊢_<∷_ {n} (Γ : Ctx n) : Kind Term n → Kind Term n → Set where <∷-⋯ : ∀ {a₁ a₂ b₁ b₂} → Γ ⊢ a₂ <: a₁ ∈ * → Γ ⊢ b₁ <: b₂ ∈ * → Γ ⊢ a₁ ⋯ b₁ <∷ a₂ ⋯ b₂ <∷-Π : ∀ {j₁ j₂ k₁ k₂} → Γ ⊢ j₂ <∷ j₁ → kd j₂ ∷ Γ ⊢ k₁ <∷ k₂ → Γ ⊢ Π j₁ k₁ kd → Γ ⊢ Π j₁ k₁ <∷ Π j₂ k₂ -- Subtyping derivations. data _⊢_<:_∈_ {n} (Γ : Ctx n) : Term n → Term n → Kind Term n → Set where <:-refl : ∀ {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a <: a ∈ k <:-trans : ∀ {a b c k} → Γ ⊢ a <: b ∈ k → Γ ⊢ b <: c ∈ k → Γ ⊢ a <: c ∈ k <:-β₁ : ∀ {j a k b} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ j → Γ ⊢ (Λ j a) · b <: a [ b ] ∈ k Kind[ b ] <:-β₂ : ∀ {j a k b} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ j → Γ ⊢ a [ b ] <: (Λ j a) · b ∈ k Kind[ b ] <:-η₁ : ∀ {a j k} → Γ ⊢Tp a ∈ Π j k → Γ ⊢ Λ j (weaken a · var zero) <: a ∈ Π j k <:-η₂ : ∀ {a j k} → Γ ⊢Tp a ∈ Π j k → Γ ⊢ a <: Λ j (weaken a · var zero) ∈ Π j k <:-⊥ : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ ⊥ <: a ∈ * <:-⊤ : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ a <: ⊤ ∈ * <:-∀ : ∀ {k₁ k₂ a₁ a₂} → Γ ⊢ k₂ <∷ k₁ → kd k₂ ∷ Γ ⊢ a₁ <: a₂ ∈ * → Γ ⊢Tp Π k₁ a₁ ∈ * → Γ ⊢ Π k₁ a₁ <: Π k₂ a₂ ∈ * <:-→ : ∀ {a₁ a₂ b₁ b₂} → Γ ⊢ a₂ <: a₁ ∈ * → Γ ⊢ b₁ <: b₂ ∈ * → Γ ⊢ a₁ ⇒ b₁ <: a₂ ⇒ b₂ ∈ * <:-λ : ∀ {j₁ j₂ a₁ a₂ j k} → kd j ∷ Γ ⊢ a₁ <: a₂ ∈ k → Γ ⊢Tp Λ j₁ a₁ ∈ Π j k → Γ ⊢Tp Λ j₂ a₂ ∈ Π j k → Γ ⊢ Λ j₁ a₁ <: Λ j₂ a₂ ∈ Π j k <:-· : ∀ {a₁ a₂ b₁ b₂ j k} → Γ ⊢ a₁ <: a₂ ∈ Π j k → Γ ⊢ b₁ ≃ b₂ ∈ j → Γ ⊢ a₁ · b₁ <: a₂ · b₂ ∈ k Kind[ b₁ ] <:-⟨| : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ b <: a ∈ * <:-|⟩ : ∀ {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢ a <: c ∈ * <:-⋯-i : ∀ {a b c d} → Γ ⊢ a <: b ∈ c ⋯ d → Γ ⊢ a <: b ∈ a ⋯ b <:-⇑ : ∀ {a b j k} → Γ ⊢ a <: b ∈ j → Γ ⊢ j <∷ k → Γ ⊢ a <: b ∈ k -- Type equality. data _⊢_≃_∈_ {n} (Γ : Ctx n) : Term n → Term n → Kind Term n → Set where <:-antisym : ∀ {a b k} → Γ ⊢ a <: b ∈ k → Γ ⊢ b <: a ∈ k → Γ ⊢ a ≃ b ∈ k -- Kind equality. data _⊢_≅_ {n} (Γ : Ctx n) : Kind Term n → Kind Term n → Set where <∷-antisym : ∀ {j k} → Γ ⊢ j <∷ k → Γ ⊢ k <∷ j → Γ ⊢ j ≅ k -- Typing derivations. data _⊢Tm_∈_ {n} (Γ : Ctx n) : Term n → Term n → Set where ∈-var : ∀ {a} x → Γ ctx → lookup Γ x ≡ tp a → Γ ⊢Tm var x ∈ a ∈-∀-i : ∀ {k a b} → Γ ⊢ k kd → kd k ∷ Γ ⊢Tm a ∈ b → Γ ⊢Tm Λ k a ∈ Π k b ∈-→-i : ∀ {a b c} → Γ ⊢Tp a ∈ * → tp a ∷ Γ ⊢Tm b ∈ weaken c → -- NOTE. The following premise is a redundant validity -- condition that could be avoided by proving a context -- strengthening lemma (showing that unused variables, -- i.e. variables not appearing freely to the right of the -- turnstyle, can be eliminated from the context). Γ ⊢Tp c ∈ * → Γ ⊢Tm ƛ a b ∈ a ⇒ c ∈-∀-e : ∀ {a b k c} → Γ ⊢Tm a ∈ Π k c → Γ ⊢Tp b ∈ k → Γ ⊢Tm a ⊡ b ∈ c [ b ] ∈-→-e : ∀ {a b c d} → Γ ⊢Tm a ∈ c ⇒ d → Γ ⊢Tm b ∈ c → Γ ⊢Tm a · b ∈ d ∈-⇑ : ∀ {a b c} → Γ ⊢Tm a ∈ b → Γ ⊢ b <: c ∈ * → Γ ⊢Tm a ∈ c -- Combined typing and kinding of terms and types. data _⊢_∈_ {n} (Γ : Ctx n) : Term n → TermAsc n → Set where ∈-tp : ∀ {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a ∈ kd k ∈-tm : ∀ {a b} → Γ ⊢Tm a ∈ b → Γ ⊢ a ∈ tp b -- Combined subtyping and subkinding. data _⊢_≤_ {n} (Γ : Ctx n) : TermAsc n → TermAsc n → Set where ≤-<∷ : ∀ {j k} → Γ ⊢ j <∷ k → Γ ⊢ kd j ≤ kd k ≤-<: : ∀ {a b} → Γ ⊢ a <: b ∈ * → Γ ⊢ tp a ≤ tp b mutual -- Combined kind and type equality, i.e. equality of well-formed -- ascriptions. data _⊢_≃_wf {n} (Γ : Ctx n) : TermAsc n → TermAsc n → Set where ≃wf-≅ : ∀ {j k} → Γ ⊢ j ≅ k → Γ ⊢ kd j ≃ kd k wf ≃wf-≃ : ∀ {a b} → Γ ⊢ a ≃ b ∈ * → Γ ⊢ tp a ≃ tp b wf -- Equality of well-formed contexts. data _≃_ctx : ∀ {n} → Ctx n → Ctx n → Set where ≃-[] : [] ≃ [] ctx ≃-∷ : ∀ {n a b} {Γ Δ : Ctx n} → Γ ⊢ a ≃ b wf → Γ ≃ Δ ctx → a ∷ Γ ≃ b ∷ Δ ctx open PropEq using ([_]) -- A derived variable rule. ∈-var′ : ∀ {n} {Γ : Ctx n} x → Γ ctx → Γ ⊢ var x ∈ lookup Γ x ∈-var′ {Γ = Γ} x Γ-ctx with lookup Γ x | inspect (lookup Γ) x ∈-var′ x Γ-ctx | kd k | [ Γ[x]≡kd-k ] = ∈-tp (∈-var x Γ-ctx Γ[x]≡kd-k) ∈-var′ x Γ-ctx | tp a | [ Γ[x]≡tp-a ] = ∈-tm (∈-var x Γ-ctx Γ[x]≡tp-a) -- A derived subsumption rule. ∈-⇑′ : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a ∈ b → Γ ⊢ b ≤ c → Γ ⊢ a ∈ c ∈-⇑′ (∈-tp a∈b) (≤-<∷ b<∷c) = ∈-tp (∈-⇑ a∈b b<∷c) ∈-⇑′ (∈-tm a∈b) (≤-<: b<:c) = ∈-tm (∈-⇑ a∈b b<:c) open ContextFormation _⊢_wf public hiding (_wf) renaming (_⊢_wfExt to _⊢_ext) ------------------------------------------------------------------------ -- Properties of typings open Syntax open TermCtx open Typing -- Inversion lemmas for _⊢_wf. wf-kd-inv : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ kd k wf → Γ ⊢ k kd wf-kd-inv (wf-kd k-kd) = k-kd wf-tp-inv : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢ tp a wf → Γ ⊢Tp a ∈ * wf-tp-inv (wf-tp a∈*) = a∈* -- An inversion lemma for _⊢_≃_wf. ≃wf-kd-inv : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ kd j ≃ kd k wf → Γ ⊢ j ≅ k ≃wf-kd-inv (≃wf-≅ j≅k) = j≅k -- Kind and type equality imply subkinding and subtyping, respectively. ≅⇒<∷ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ j <∷ k ≅⇒<∷ (<∷-antisym j<∷k k<∷j) = j<∷k ≃⇒<: : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ⊢ a <: b ∈ k ≃⇒<: (<:-antisym a<:b b<:a) = a<:b -- Reflexivity of subkinding. <∷-refl : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k <∷ k <∷-refl (kd-⋯ a∈* b∈*) = <∷-⋯ (<:-refl a∈*) (<:-refl b∈*) <∷-refl (kd-Π j-kd k-kd) = <∷-Π (<∷-refl j-kd) (<∷-refl k-kd) (kd-Π j-kd k-kd) -- Reflexivity of kind equality. ≅-refl : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k ≅ k ≅-refl k-kd = <∷-antisym (<∷-refl k-kd) (<∷-refl k-kd) -- Symmetry of kind equality. ≅-sym : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ⊢ k ≅ j ≅-sym (<∷-antisym j<∷k k<∷j) = <∷-antisym k<∷j j<∷k -- An admissible kind equality rule for interval kinds. ≅-⋯ : ∀ {n} {Γ : Ctx n} {a₁ a₂ b₁ b₂} → Γ ⊢ a₁ ≃ a₂ ∈ * → Γ ⊢ b₁ ≃ b₂ ∈ * → Γ ⊢ a₁ ⋯ b₁ ≅ a₂ ⋯ b₂ ≅-⋯ (<:-antisym a₁<:a₂ a₂<:a₁) (<:-antisym b₁<:b₂ b₂<:b₁) = <∷-antisym (<∷-⋯ a₂<:a₁ b₁<:b₂) (<∷-⋯ a₁<:a₂ b₂<:b₁) -- Type equality is reflexive. ≃-refl : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a ≃ a ∈ k ≃-refl a∈k = <:-antisym (<:-refl a∈k) (<:-refl a∈k) -- Type equality is transitive. ≃-trans : ∀ {n} {Γ : Ctx n} {a b c k} → Γ ⊢ a ≃ b ∈ k → Γ ⊢ b ≃ c ∈ k → Γ ⊢ a ≃ c ∈ k ≃-trans (<:-antisym a<:b b<:a) (<:-antisym b<:c c<:b) = <:-antisym (<:-trans a<:b b<:c) (<:-trans c<:b b<:a) -- Type equality is symmetric. ≃-sym : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ⊢ b ≃ a ∈ k ≃-sym (<:-antisym a<:b b<:a) = <:-antisym b<:a a<:b -- Types inhabiting interval kinds are proper Types. Tp∈-⋯-* : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢Tp a ∈ b ⋯ c → Γ ⊢Tp a ∈ * Tp∈-⋯-* a∈b⋯c = ∈-⇑ (∈-s-i a∈b⋯c) (<∷-⋯ (<:-⊥ a∈b⋯c) (<:-⊤ a∈b⋯c)) -- Well-formedness of the * kind. *-kd : ∀ {n} {Γ : Ctx n} → Γ ctx → Γ ⊢ * kd *-kd Γ-ctx = kd-⋯ (∈-⊥-f Γ-ctx) (∈-⊤-f Γ-ctx) module _ where open Substitution -- An admissible β-rule for type equality. ≃-β : ∀ {n} {Γ : Ctx n} {j a k b} → kd j ∷ Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ j → Γ ⊢ (Λ j a) · b ≃ a [ b ] ∈ k Kind[ b ] ≃-β a∈k b∈j = <:-antisym (<:-β₁ a∈k b∈j) (<:-β₂ a∈k b∈j) -- An admissible η-rule for type equality. ≃-η : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢Tp a ∈ Π j k → Γ ⊢ Λ j (weaken a · var zero) ≃ a ∈ Π j k ≃-η a∈Πjk = <:-antisym (<:-η₁ a∈Πjk) (<:-η₂ a∈Πjk) -- An admissible congruence rule for type equality w.r.t. formation of -- arrow types. ≃-→ : ∀ {n} {Γ : Ctx n} {a₁ a₂ b₁ b₂} → Γ ⊢ a₁ ≃ a₂ ∈ * → Γ ⊢ b₁ ≃ b₂ ∈ * → Γ ⊢ a₁ ⇒ b₁ ≃ a₂ ⇒ b₂ ∈ * ≃-→ (<:-antisym a₁<:a₂∈* a₂<:a₁∈*) (<:-antisym b₁<:b₂∈* b₂<:b₁∈*) = <:-antisym (<:-→ a₂<:a₁∈* b₁<:b₂∈*) (<:-→ a₁<:a₂∈* b₂<:b₁∈*) -- An admissible congruence rule for type equality w.r.t. operator -- abstraction. ≃-λ : ∀ {n} {Γ : Ctx n} {j₁ j₂ a₁ a₂ j k} → kd j ∷ Γ ⊢ a₁ ≃ a₂ ∈ k → Γ ⊢Tp Λ j₁ a₁ ∈ Π j k → Γ ⊢Tp Λ j₂ a₂ ∈ Π j k → Γ ⊢ Λ j₁ a₁ ≃ Λ j₂ a₂ ∈ Π j k ≃-λ (<:-antisym a₁<:a₂∈k a₂<:a₁∈k) Λj₁a₁∈Πjk Λj₂a₂∈Πjk = <:-antisym (<:-λ a₁<:a₂∈k Λj₁a₁∈Πjk Λj₂a₂∈Πjk) (<:-λ a₂<:a₁∈k Λj₂a₂∈Πjk Λj₁a₁∈Πjk) -- An admissible subsumption rule for type equality. ≃-⇑ : ∀ {n} {Γ : Ctx n} {a b j k} → Γ ⊢ a ≃ b ∈ j → Γ ⊢ j <∷ k → Γ ⊢ a ≃ b ∈ k ≃-⇑ (<:-antisym a<:b b<:a) j<∷k = <:-antisym (<:-⇑ a<:b j<∷k) (<:-⇑ b<:a j<∷k) -- NOTE. There are more admissible rules one might want to prove -- here, such as congruence lemmas for type and kind equality -- w.r.t. the remaining type constructors (e.g. Π and _·_) or -- transitivity of subkinding and kind equality. But the proofs of -- these lemmas require context narrowing and/or validity lemmas which -- we have not yet established. We will prove these lemmas once we -- have established validity of the declarative judgments (see the -- Typing.Validity module). -- The contexts of all the above judgments are well-formed. mutual kd-ctx : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ctx kd-ctx (kd-⋯ a∈* b∈*) = Tp∈-ctx a∈* kd-ctx (kd-Π j-kd k-kd) = kd-ctx j-kd Tp∈-ctx : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ctx Tp∈-ctx (∈-var x Γ-ctx Γ[x]≡kd-k) = Γ-ctx Tp∈-ctx (∈-⊥-f Γ-ctx) = Γ-ctx Tp∈-ctx (∈-⊤-f Γ-ctx) = Γ-ctx Tp∈-ctx (∈-∀-f k-kd a∈*) = kd-ctx k-kd Tp∈-ctx (∈-→-f a∈* b∈*) = Tp∈-ctx a∈* Tp∈-ctx (∈-Π-i j-kd a∈k) = kd-ctx j-kd Tp∈-ctx (∈-Π-e a∈Πjk b∈j) = Tp∈-ctx a∈Πjk Tp∈-ctx (∈-s-i a∈b⋯c) = Tp∈-ctx a∈b⋯c Tp∈-ctx (∈-⇑ a∈j j<∷k) = Tp∈-ctx a∈j wf-ctx : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢ a wf → Γ ctx wf-ctx (wf-kd k-kd) = kd-ctx k-kd wf-ctx (wf-tp a∈*) = Tp∈-ctx a∈* <:-ctx : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a <: b ∈ k → Γ ctx <:-ctx (<:-refl a∈k) = Tp∈-ctx a∈k <:-ctx (<:-trans a<:b∈k b<:c∈k) = <:-ctx a<:b∈k <:-ctx (<:-β₁ a∈j b∈k) = Tp∈-ctx b∈k <:-ctx (<:-β₂ a∈j b∈k) = Tp∈-ctx b∈k <:-ctx (<:-η₁ a∈Πjk) = Tp∈-ctx a∈Πjk <:-ctx (<:-η₂ a∈Πjk) = Tp∈-ctx a∈Πjk <:-ctx (<:-⊥ a∈b⋯c) = Tp∈-ctx a∈b⋯c <:-ctx (<:-⊤ a∈b⋯c) = Tp∈-ctx a∈b⋯c <:-ctx (<:-∀ k₂<∷k₁ a₁<:a₂ ∀k₁a₁∈*) = Tp∈-ctx ∀k₁a₁∈* <:-ctx (<:-→ a₂<:a₁ b₁<:b₂) = <:-ctx a₂<:a₁ <:-ctx (<:-λ a₂<:a₁∈Πjk Λa₁k₁∈Πjk Λa₂k₂∈Πjk) = Tp∈-ctx Λa₁k₁∈Πjk <:-ctx (<:-· a₂<:a₁∈Πjk b₂≃b₁∈j) = <:-ctx a₂<:a₁∈Πjk <:-ctx (<:-⟨| a∈b⋯c) = Tp∈-ctx a∈b⋯c <:-ctx (<:-|⟩ a∈b⋯c) = Tp∈-ctx a∈b⋯c <:-ctx (<:-⋯-i a<:b∈c⋯d) = <:-ctx a<:b∈c⋯d <:-ctx (<:-⇑ a<:b∈j j<∷k) = <:-ctx a<:b∈j <∷-ctx : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j <∷ k → Γ ctx <∷-ctx (<∷-⋯ a₂<:a₁ b₁<:b₂) = <:-ctx a₂<:a₁ <∷-ctx (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) = <∷-ctx j₂<∷j₁ ≅-ctx : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j ≅ k → Γ ctx ≅-ctx (<∷-antisym j<∷k k<∷j) = <∷-ctx j<∷k ≃-ctx : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a ≃ b ∈ k → Γ ctx ≃-ctx (<:-antisym a<:b∈k b<:a∈k) = <:-ctx a<:b∈k Tm∈-ctx : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢Tm a ∈ b → Γ ctx Tm∈-ctx (∈-var x Γ-ctx Γ[x]≡tp-a) = Γ-ctx Tm∈-ctx (∈-∀-i k-kd a∈b) = kd-ctx k-kd Tm∈-ctx (∈-→-i a∈* b∈c c∈*) = Tp∈-ctx a∈* Tm∈-ctx (∈-∀-e a∈∀kc b∈k) = Tm∈-ctx a∈∀kc Tm∈-ctx (∈-→-e a∈c⇒d b∈c) = Tm∈-ctx a∈c⇒d Tm∈-ctx (∈-⇑ a∈b b<:c) = Tm∈-ctx a∈b ∈-ctx : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a ∈ b → Γ ctx ∈-ctx (∈-tp a∈k) = Tp∈-ctx a∈k ∈-ctx (∈-tm a∈b) = Tm∈-ctx a∈b ---------------------------------------------------------------------- -- Well-typed substitutions (i.e. substitution lemmas) -- A shorthand for kindings and typings of Ts by kind or type -- ascriptions. TermAscTyping : (ℕ → Set) → Set₁ TermAscTyping T = Typing TermAsc T TermAsc lzero -- Liftings from well-typed Ts to well-typed/kinded terms/types. LiftTo-∈ : ∀ {T} → TermAscTyping T → Set₁ LiftTo-∈ _⊢T_∈_ = LiftTyped Substitution.termAscTermSubst _⊢_wf _⊢T_∈_ _⊢_∈_ -- Helper lemmas about untyped T-substitutions in raw terms and kinds. record TypedSubstAppHelpers {T} (rawLift : Lift T Term) : Set where open Substitution using (weaken; _[_]; _Kind[_]) module A = SubstApp rawLift module L = Lift rawLift field -- Substitutions in kinds and types commute. Kind/-sub-↑ : ∀ {m n} k a (σ : Sub T m n) → k Kind[ a ] A.Kind/ σ ≡ (k A.Kind/ σ L.↑) Kind[ a A./ σ ] /-sub-↑ : ∀ {m n} b a (σ : Sub T m n) → b [ a ] A./ σ ≡ (b A./ σ L.↑) [ a A./ σ ] -- Weakening of terms commutes with substitution in terms. weaken-/ : ∀ {m n} {σ : Sub T m n} a → weaken (a A./ σ) ≡ weaken a A./ σ L.↑ -- Application of generic well-typed T-substitutions to all the judgments. module TypedSubstApp {T : ℕ → Set} (_⊢T_∈_ : TermAscTyping T) (liftTyped : LiftTo-∈ _⊢T_∈_) (helpers : TypedSubstAppHelpers (LiftTyped.rawLift liftTyped)) where open LiftTyped liftTyped renaming (lookup to /∈-lookup) open TypedSubstAppHelpers helpers -- Lift well-kinded Ts to well-kinded types. liftTp : ∀ {n} {Γ : Ctx n} {a k kd-k} → kd-k ≡ kd k → Γ ⊢T a ∈ kd-k → Γ ⊢Tp L.lift a ∈ k liftTp refl a∈kd-k with ∈-lift a∈kd-k liftTp refl a∈kd-k | ∈-tp a∈k = a∈k -- Lift well-typed Ts to well-typed terms. liftTm : ∀ {n} {Γ : Ctx n} {a b tp-b} → tp-b ≡ tp b → Γ ⊢T a ∈ tp-b → Γ ⊢Tm L.lift a ∈ b liftTm refl a∈tp-b with ∈-lift a∈tp-b liftTm refl a∈tp-b | ∈-tm a∈b = a∈b mutual -- Substitutions preserve well-formedness of kinds and -- well-kindedness of types. kd-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {k σ} → Γ ⊢ k kd → Δ ⊢/ σ ∈ Γ → Δ ⊢ k A.Kind/ σ kd kd-/ (kd-⋯ a∈* b∈*) σ∈Γ = kd-⋯ (Tp∈-/ a∈* σ∈Γ) (Tp∈-/ b∈* σ∈Γ) kd-/ (kd-Π j-kd k-kd) σ∈Γ = kd-Π j/σ-kd (kd-/ k-kd (∈-↑ (wf-kd j/σ-kd) σ∈Γ)) where j/σ-kd = kd-/ j-kd σ∈Γ Tp∈-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a k σ} → Γ ⊢Tp a ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢Tp a A./ σ ∈ k A.Kind/ σ Tp∈-/ (∈-var x Γ-ctx Γ[x]≡kd-k) σ∈Γ = liftTp (cong (_/ _) Γ[x]≡kd-k) (/∈-lookup σ∈Γ x) Tp∈-/ (∈-⊥-f Γ-ctx) σ∈Γ = ∈-⊥-f (/∈-wf σ∈Γ) Tp∈-/ (∈-⊤-f Γ-ctx) σ∈Γ = ∈-⊤-f (/∈-wf σ∈Γ) Tp∈-/ (∈-∀-f k-kd a∈*) σ∈Γ = ∈-∀-f k/σ-kd (Tp∈-/ a∈* (∈-↑ (wf-kd k/σ-kd) σ∈Γ)) where k/σ-kd = kd-/ k-kd σ∈Γ Tp∈-/ (∈-→-f a∈* b∈*) σ∈Γ = ∈-→-f (Tp∈-/ a∈* σ∈Γ) (Tp∈-/ b∈* σ∈Γ) Tp∈-/ (∈-Π-i j-kd a∈k) σ∈Γ = ∈-Π-i j/σ-kd (Tp∈-/ a∈k (∈-↑ (wf-kd j/σ-kd) σ∈Γ)) where j/σ-kd = kd-/ j-kd σ∈Γ Tp∈-/ (∈-Π-e {_} {b} {_} {k} a∈Πjk b∈j) σ∈Γ = subst (_ ⊢Tp _ ∈_) (sym (Kind/-sub-↑ k b _)) (∈-Π-e (Tp∈-/ a∈Πjk σ∈Γ) (Tp∈-/ b∈j σ∈Γ)) Tp∈-/ (∈-s-i a∈b⋯c) σ∈Γ = ∈-s-i (Tp∈-/ a∈b⋯c σ∈Γ) Tp∈-/ (∈-⇑ a∈j j<∷k) σ∈Γ = ∈-⇑ (Tp∈-/ a∈j σ∈Γ) (<∷-/ j<∷k σ∈Γ) -- Substitutions commute with subkinding, subtyping and type -- equality. <∷-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k σ} → Γ ⊢ j <∷ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ j A.Kind/ σ <∷ k A.Kind/ σ <∷-/ (<∷-⋯ a₂<:a₁ b₁<:b₂) σ∈Γ = <∷-⋯ (<:-/ a₂<:a₁ σ∈Γ) (<:-/ b₁<:b₂ σ∈Γ) <∷-/ (<∷-Π j₂<∷j₁ k₁<∷k₂ Πj₁k₁-kd) σ∈Γ = <∷-Π (<∷-/ j₂<∷j₁ σ∈Γ) (<∷-/ k₁<∷k₂ (∈-↑ (<∷-/-wf k₁<∷k₂ σ∈Γ) σ∈Γ)) (kd-/ Πj₁k₁-kd σ∈Γ) <:-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b k σ} → Γ ⊢ a <: b ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A./ σ <: b A./ σ ∈ k A.Kind/ σ <:-/ (<:-refl a∈k) σ∈Γ = <:-refl (Tp∈-/ a∈k σ∈Γ) <:-/ (<:-trans a<:b∈k b<:c∈k) σ∈Γ = <:-trans (<:-/ a<:b∈k σ∈Γ) (<:-/ b<:c∈k σ∈Γ) <:-/ (<:-β₁ {j} {a} {k} {b} a∈k b∈j) σ∈Γ = subst₂ (_ ⊢ (Λ j a) · b A./ _ <:_∈_) (sym (/-sub-↑ a b _)) (sym (Kind/-sub-↑ k b _)) (<:-β₁ (Tp∈-/ a∈k (∈-↑ (Tp∈-/-wf a∈k σ∈Γ) σ∈Γ)) (Tp∈-/ b∈j σ∈Γ)) <:-/ (<:-β₂ {j} {a} {k} {b} a∈k b∈j) σ∈Γ = subst₂ (_ ⊢_<: (Λ j a) · b A./ _ ∈_) (sym (/-sub-↑ a b _)) (sym (Kind/-sub-↑ k b _)) (<:-β₂ (Tp∈-/ a∈k (∈-↑ (Tp∈-/-wf a∈k σ∈Γ) σ∈Γ)) (Tp∈-/ b∈j σ∈Γ)) <:-/ {Δ = Δ} {σ = σ} (<:-η₁ {a} {j} {k} a∈Πjk) σ∈Γ = subst (Δ ⊢_<: a A./ σ ∈ Π j k A.Kind/ σ) (cong (Λ _) (cong₂ _·_ (weaken-/ a) (sym (lift-var zero)))) (<:-η₁ (Tp∈-/ a∈Πjk σ∈Γ)) <:-/ {Δ = Δ} {σ = σ} (<:-η₂ {a} {j} {k} a∈Πjk) σ∈Γ = subst (Δ ⊢ a A./ σ <:_∈ Π j k A.Kind/ σ) (cong (Λ _) (cong₂ _·_ (weaken-/ a) (sym (lift-var zero)))) (<:-η₂ (Tp∈-/ a∈Πjk σ∈Γ)) <:-/ (<:-⊥ a∈b⋯c) σ∈Γ = <:-⊥ (Tp∈-/ a∈b⋯c σ∈Γ) <:-/ (<:-⊤ a∈b⋯c) σ∈Γ = <:-⊤ (Tp∈-/ a∈b⋯c σ∈Γ) <:-/ (<:-∀ k₂<∷k₁ a₁<:a₂∈* ∀j₁k₁∈*) σ∈Γ = <:-∀ (<∷-/ k₂<∷k₁ σ∈Γ) (<:-/ a₁<:a₂∈* (∈-↑ (<:-/-wf a₁<:a₂∈* σ∈Γ) σ∈Γ)) (Tp∈-/ ∀j₁k₁∈* σ∈Γ) <:-/ (<:-→ a₂<:a₁∈* b₁<:b₂∈*) σ∈Γ = <:-→ (<:-/ a₂<:a₁∈* σ∈Γ) (<:-/ b₁<:b₂∈* σ∈Γ) <:-/ (<:-λ a₁<:a₂∈k Λj₁a₁∈Πjk Λj₂a₂∈Πjk) σ∈Γ = <:-λ (<:-/ a₁<:a₂∈k (∈-↑ (<:-/-wf a₁<:a₂∈k σ∈Γ) σ∈Γ)) (Tp∈-/ Λj₁a₁∈Πjk σ∈Γ) (Tp∈-/ Λj₂a₂∈Πjk σ∈Γ) <:-/ (<:-· {k = k} a₁<:a₂∈Πjk b₁≃b₂∈j) σ∈Γ = subst (_ ⊢ _ <: _ ∈_) (sym (Kind/-sub-↑ k _ _)) (<:-· (<:-/ a₁<:a₂∈Πjk σ∈Γ) (≃-/ b₁≃b₂∈j σ∈Γ)) <:-/ (<:-⟨| a∈b⋯c) σ∈Γ = <:-⟨| (Tp∈-/ a∈b⋯c σ∈Γ) <:-/ (<:-|⟩ a∈b⋯c) σ∈Γ = <:-|⟩ (Tp∈-/ a∈b⋯c σ∈Γ) <:-/ (<:-⋯-i a<:b∈c⋯d) σ∈Γ = <:-⋯-i (<:-/ a<:b∈c⋯d σ∈Γ) <:-/ (<:-⇑ a<:b∈j j<∷k) σ∈Γ = <:-⇑ (<:-/ a<:b∈j σ∈Γ) (<∷-/ j<∷k σ∈Γ) ≃-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b k σ} → Γ ⊢ a ≃ b ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A./ σ ≃ b A./ σ ∈ k A.Kind/ σ ≃-/ (<:-antisym a<:b∈k b<:a∈k) σ∈Γ = <:-antisym (<:-/ a<:b∈k σ∈Γ) (<:-/ b<:a∈k σ∈Γ) -- Helpers (to satisfy the termination checker). kd-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k σ} → kd j ∷ Γ ⊢ k kd → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf kd-/-wf (kd-⋯ a∈* _) σ∈Γ = Tp∈-/-wf a∈* σ∈Γ kd-/-wf (kd-Π j-kd _) σ∈Γ = kd-/-wf j-kd σ∈Γ Tp∈-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a j k σ} → kd j ∷ Γ ⊢Tp a ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf Tp∈-/-wf (∈-var x (wf-kd k-kd ∷ Γ-ctx) _) σ∈Γ = wf-kd (kd-/ k-kd σ∈Γ) Tp∈-/-wf (∈-⊥-f (wf-kd j-kd ∷ Γ-ctx)) σ∈Γ = wf-kd (kd-/ j-kd σ∈Γ) Tp∈-/-wf (∈-⊤-f (wf-kd j-kd ∷ Γ-ctx)) σ∈Γ = wf-kd (kd-/ j-kd σ∈Γ) Tp∈-/-wf (∈-∀-f k-kd _) σ∈Γ = kd-/-wf k-kd σ∈Γ Tp∈-/-wf (∈-→-f a∈* _) σ∈Γ = Tp∈-/-wf a∈* σ∈Γ Tp∈-/-wf (∈-Π-i j-kd _) σ∈Γ = kd-/-wf j-kd σ∈Γ Tp∈-/-wf (∈-Π-e a∈Πjk _) σ∈Γ = Tp∈-/-wf a∈Πjk σ∈Γ Tp∈-/-wf (∈-s-i a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ Tp∈-/-wf (∈-⇑ a∈b _) σ∈Γ = Tp∈-/-wf a∈b σ∈Γ <:-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b j k σ} → kd j ∷ Γ ⊢ a <: b ∈ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf <:-/-wf (<:-refl a∈k) σ∈Γ = Tp∈-/-wf a∈k σ∈Γ <:-/-wf (<:-trans a<:b _) σ∈Γ = <:-/-wf a<:b σ∈Γ <:-/-wf (<:-β₁ _ b∈j) σ∈Γ = Tp∈-/-wf b∈j σ∈Γ <:-/-wf (<:-β₂ _ b∈j) σ∈Γ = Tp∈-/-wf b∈j σ∈Γ <:-/-wf (<:-η₁ a∈Πjk) σ∈Γ = Tp∈-/-wf a∈Πjk σ∈Γ <:-/-wf (<:-η₂ a∈Πjk) σ∈Γ = Tp∈-/-wf a∈Πjk σ∈Γ <:-/-wf (<:-⊥ a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ <:-/-wf (<:-⊤ a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ <:-/-wf (<:-∀ j₂<∷j₁ _ _) σ∈Γ = <∷-/-wf j₂<∷j₁ σ∈Γ <:-/-wf (<:-→ a₂<:a₁∈* _) σ∈Γ = <:-/-wf a₂<:a₁∈* σ∈Γ <:-/-wf (<:-λ _ Λj₁a₂∈Πjk _) σ∈Γ = Tp∈-/-wf Λj₁a₂∈Πjk σ∈Γ <:-/-wf (<:-· a₁<:a₂∈Πjk _) σ∈Γ = <:-/-wf a₁<:a₂∈Πjk σ∈Γ <:-/-wf (<:-⟨| a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ <:-/-wf (<:-|⟩ a∈b⋯c) σ∈Γ = Tp∈-/-wf a∈b⋯c σ∈Γ <:-/-wf (<:-⋯-i a<:b∈c⋯d) σ∈Γ = <:-/-wf a<:b∈c⋯d σ∈Γ <:-/-wf (<:-⇑ a<:b∈k _) σ∈Γ = <:-/-wf a<:b∈k σ∈Γ <∷-/-wf : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k l σ} → kd j ∷ Γ ⊢ k <∷ l → Δ ⊢/ σ ∈ Γ → Δ ⊢ kd (j A.Kind/ σ) wf <∷-/-wf (<∷-⋯ j₂<:j₁ _) σ∈Γ = <:-/-wf j₂<:j₁ σ∈Γ <∷-/-wf (<∷-Π j₂<∷j₁ _ _) σ∈Γ = <∷-/-wf j₂<∷j₁ σ∈Γ -- Substitutions preserve well-formedness of ascriptions. wf-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a σ} → Γ ⊢ a wf → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A.TermAsc/ σ wf wf-/ (wf-kd k-kd) σ∈Γ = wf-kd (kd-/ k-kd σ∈Γ) wf-/ (wf-tp a∈b) σ∈Γ = wf-tp (Tp∈-/ a∈b σ∈Γ) -- Substitutions commute with kind equality. ≅-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {j k σ} → Γ ⊢ j ≅ k → Δ ⊢/ σ ∈ Γ → Δ ⊢ j A.Kind/ σ ≅ k A.Kind/ σ ≅-/ (<∷-antisym j<∷k k<∷j) σ∈Γ = <∷-antisym (<∷-/ j<∷k σ∈Γ) (<∷-/ k<∷j σ∈Γ) -- Substitutions preserve well-typedness of terms. Tm∈-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} → Γ ⊢Tm a ∈ b → Δ ⊢/ σ ∈ Γ → Δ ⊢Tm a A./ σ ∈ b A./ σ Tm∈-/ (∈-var x Γ-ctx Γ[x]=tp-k) σ∈Γ = liftTm (cong (_/ _) Γ[x]=tp-k) (/∈-lookup σ∈Γ x) Tm∈-/ (∈-∀-i k-kd a∈*) σ∈Γ = ∈-∀-i k/σ-kd (Tm∈-/ a∈* (∈-↑ (wf-kd k/σ-kd) σ∈Γ)) where k/σ-kd = kd-/ k-kd σ∈Γ Tm∈-/ (∈-→-i {c = c} a∈* b∈c c∈*) σ∈Γ = ∈-→-i a/σ∈* (subst (_ ⊢Tm _ ∈_) (sym (weaken-/ c) ) b/σ↑∈c) (Tp∈-/ c∈* σ∈Γ) where a/σ∈* = Tp∈-/ a∈* σ∈Γ b/σ↑∈c = Tm∈-/ b∈c (∈-↑ (wf-tp a/σ∈*) σ∈Γ) Tm∈-/ (∈-∀-e {c = c} a∈∀kc b∈k) σ∈Γ = subst (_ ⊢Tm _ ∈_) (sym (/-sub-↑ c _ _)) (∈-∀-e (Tm∈-/ a∈∀kc σ∈Γ) (Tp∈-/ b∈k σ∈Γ)) Tm∈-/ (∈-→-e a∈c→d b∈c) σ∈Γ = ∈-→-e (Tm∈-/ a∈c→d σ∈Γ) (Tm∈-/ b∈c σ∈Γ) Tm∈-/ (∈-⇑ a∈b b<:c) σ∈Γ = ∈-⇑ (Tm∈-/ a∈b σ∈Γ) (<:-/ b<:c σ∈Γ) -- Substitutions preserve well-kindedness and well-typedness. ∈-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} → Γ ⊢ a ∈ b → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A./ σ ∈ b A.TermAsc/ σ ∈-/ (∈-tp a∈b) σ∈Γ = ∈-tp (Tp∈-/ a∈b σ∈Γ) ∈-/ (∈-tm a∈b) σ∈Γ = ∈-tm (Tm∈-/ a∈b σ∈Γ) -- Substitutions preserve subkinding and subtyping. ≤-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} → Γ ⊢ a ≤ b → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A.TermAsc/ σ ≤ b A.TermAsc/ σ ≤-/ (≤-<∷ a<∷b) σ∈Γ = ≤-<∷ (<∷-/ a<∷b σ∈Γ) ≤-/ (≤-<: a<:b∈k) σ∈Γ = ≤-<: (<:-/ a<:b∈k σ∈Γ) -- Substitutions preserve equality of kind and type ascriptions. ≃wf-/ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} → Γ ⊢ a ≃ b wf → Δ ⊢/ σ ∈ Γ → Δ ⊢ a A.TermAsc/ σ ≃ b A.TermAsc/ σ wf ≃wf-/ (≃wf-≅ j≅k) σ∈Γ = ≃wf-≅ (≅-/ j≅k σ∈Γ) ≃wf-/ (≃wf-≃ a≃b) σ∈Γ = ≃wf-≃ (≃-/ a≃b σ∈Γ) -- Well-kinded/typed type and term substitutions. module TypedSubstitution where open Substitution using (simple; termSubst) open SimpleExt simple using (extension) open TermSubst termSubst using (varLift; termLift) private module S = Substitution module KL = TermLikeLemmas S.termLikeLemmasKind -- Helper lemmas about untyped renamings and substitutions in terms -- and kinds. varHelpers : TypedSubstAppHelpers varLift varHelpers = record { Kind/-sub-↑ = KL./-sub-↑ ; /-sub-↑ = LiftSubLemmas./-sub-↑ S.varLiftSubLemmas ; weaken-/ = LiftAppLemmas.wk-commutes S.varLiftAppLemmas } termHelpers : TypedSubstAppHelpers termLift termHelpers = record { Kind/-sub-↑ = λ k _ _ → KL.sub-commutes k ; /-sub-↑ = λ a _ _ → S.sub-commutes a ; weaken-/ = S.weaken-/ } -- Typed term substitutions. typedTermSubst : TypedTermSubst TermAsc Term lzero TypedSubstAppHelpers typedTermSubst = record { _⊢_wf = _⊢_wf ; _⊢_∈_ = _⊢_∈_ ; termLikeLemmas = S.termLikeLemmasTermAsc ; varHelpers = varHelpers ; termHelpers = termHelpers ; wf-wf = wf-ctx ; ∈-wf = ∈-ctx ; ∈-var = ∈-var′ ; typedApp = TypedSubstApp.∈-/ } open TypedTermSubst typedTermSubst public hiding (_⊢_wf; _⊢_∈_; varHelpers; termHelpers; ∈-var; ∈-/Var; ∈-/) renaming (lookup to /∈-lookup) open TypedSubstApp _⊢Var_∈_ varLiftTyped varHelpers public using () renaming ( wf-/ to wf-/Var ; kd-/ to kd-/Var ; Tp∈-/ to Tp∈-/Var ; <∷-/ to <∷-/Var ; <:-/ to <:-/Var ; ∈-/ to ∈-/Var ; ≤-/ to ≤-/Var ; ≃wf-/ to ≃wf-/Var ) open Substitution using (weaken; weakenKind; weakenTermAsc) -- Weakening preserves the various judgments. wf-weaken : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a wf → Γ ⊢ b wf → (a ∷ Γ) ⊢ weakenTermAsc b wf wf-weaken a-wf b-wf = wf-/Var b-wf (Var∈-wk a-wf) kd-weaken : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢ a wf → Γ ⊢ k kd → (a ∷ Γ) ⊢ weakenKind k kd kd-weaken a-wf k-kd = kd-/Var k-kd (Var∈-wk a-wf) Tp∈-weaken : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢ a wf → Γ ⊢Tp b ∈ k → (a ∷ Γ) ⊢Tp weaken b ∈ weakenKind k Tp∈-weaken a-wf b∈k = Tp∈-/Var b∈k (Var∈-wk a-wf) <∷-weaken : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢ a wf → Γ ⊢ j <∷ k → (a ∷ Γ) ⊢ weakenKind j <∷ weakenKind k <∷-weaken a-wf j<∷k = <∷-/Var j<∷k (Var∈-wk a-wf) <:-weaken : ∀ {n} {Γ : Ctx n} {a b c k} → Γ ⊢ a wf → Γ ⊢ b <: c ∈ k → (a ∷ Γ) ⊢ weaken b <: weaken c ∈ weakenKind k <:-weaken a-wf b<:c∈k = <:-/Var b<:c∈k (Var∈-wk a-wf) ∈-weaken : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a wf → Γ ⊢ b ∈ c → (a ∷ Γ) ⊢ weaken b ∈ weakenTermAsc c ∈-weaken a-wf b∈c = ∈-/Var b∈c (Var∈-wk a-wf) ≤-weaken : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a wf → Γ ⊢ b ≤ c → (a ∷ Γ) ⊢ weakenTermAsc b ≤ weakenTermAsc c ≤-weaken a-wf b≤c = ≤-/Var b≤c (Var∈-wk a-wf) ≃wf-weaken : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ a wf → Γ ⊢ b ≃ c wf → (a ∷ Γ) ⊢ weakenTermAsc b ≃ weakenTermAsc c wf ≃wf-weaken a-wf b≃c = ≃wf-/Var b≃c (Var∈-wk a-wf) open TypedSubstApp _⊢_∈_ termLiftTyped termHelpers public open Substitution using (_/_; _Kind/_; id; sub; _↑⋆_; _[_]; _Kind[_]) -- Substitution of a single well-typed term or well-kinded type -- preserves the various judgments. kd-[] : ∀ {n} {Γ : Ctx n} {a b k} → b ∷ Γ ⊢ k kd → Γ ⊢ a ∈ b → Γ ⊢ k Kind[ a ] kd kd-[] k-kd a∈b = kd-/ k-kd (∈-sub a∈b) Tp∈-[] : ∀ {n} {Γ : Ctx n} {a b k c} → c ∷ Γ ⊢Tp a ∈ k → Γ ⊢ b ∈ c → Γ ⊢Tp a [ b ] ∈ k Kind[ b ] Tp∈-[] a∈k b∈c = Tp∈-/ a∈k (∈-sub b∈c) Tm∈-[] : ∀ {n} {Γ : Ctx n} {a b c d} → d ∷ Γ ⊢Tm a ∈ c → Γ ⊢ b ∈ d → Γ ⊢Tm a [ b ] ∈ c [ b ] Tm∈-[] a∈c b∈d = Tm∈-/ a∈c (∈-sub b∈d) <:-[] : ∀ {n} {Γ : Ctx n} {a b c d k} → d ∷ Γ ⊢ a <: b ∈ k → Γ ⊢ c ∈ d → Γ ⊢ a [ c ] <: b [ c ] ∈ k Kind[ c ] <:-[] a<:b c∈d = <:-/ a<:b (∈-sub c∈d) -- Operations on well-formed contexts that require weakening of -- well-formedness judgments. module WfCtxOps where wfWeakenOps : WellFormedWeakenOps weakenOps wfWeakenOps = record { wf-weaken = TypedSubstitution.wf-weaken } open WellFormedWeakenOps wfWeakenOps public renaming (lookup to lookup-wf) -- Lookup the kind of a type variable in a well-formed context. lookup-kd : ∀ {m} {Γ : Ctx m} {k} x → Γ ctx → TermCtx.lookup Γ x ≡ kd k → Γ ⊢ k kd lookup-kd x Γ-ctx Γ[x]≡kd-k = wf-kd-inv (subst (_ ⊢_wf) Γ[x]≡kd-k (lookup-wf Γ-ctx x)) -- Lookup the type of a term variable in a well-formed context. lookup-tp : ∀ {m} {Γ : Ctx m} {a} x → Γ ctx → TermCtx.lookup Γ x ≡ tp a → Γ ⊢Tp a ∈ * lookup-tp x Γ-ctx Γ[x]≡tp-a = wf-tp-inv (subst (_ ⊢_wf) Γ[x]≡tp-a (lookup-wf Γ-ctx x)) open TypedSubstitution open WfCtxOps ---------------------------------------------------------------------- -- Generation lemmas for kinding -- A generation lemma for kinding of universals. Tp∈-∀-inv : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢Tp Π j a ∈ k → Γ ⊢ j kd × kd j ∷ Γ ⊢Tp a ∈ * Tp∈-∀-inv (∈-∀-f j-kd a∈*) = j-kd , a∈* Tp∈-∀-inv (∈-s-i ∀ka∈b⋯c) = Tp∈-∀-inv ∀ka∈b⋯c Tp∈-∀-inv (∈-⇑ ∀ja∈k k<∷l) = Tp∈-∀-inv ∀ja∈k -- A generation lemma for kinding of arrows. Tp∈-→-inv : ∀ {n} {Γ : Ctx n} {a b k} → Γ ⊢Tp a ⇒ b ∈ k → Γ ⊢Tp a ∈ * × Γ ⊢Tp b ∈ * Tp∈-→-inv (∈-→-f a∈* b∈*) = a∈* , b∈* Tp∈-→-inv (∈-s-i a⇒b∈c⋯d) = Tp∈-→-inv a⇒b∈c⋯d Tp∈-→-inv (∈-⇑ a⇒b∈j j<∷k) = Tp∈-→-inv a⇒b∈j
{ "alphanum_fraction": 0.437765087, "avg_line_length": 39.9773030708, "ext": "agda", "hexsha": "3915a009c16b36f12099e7bdf0b8140d893b6279", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_path": "src/FOmegaInt/Typing.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_path": "src/FOmegaInt/Typing.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_path": "src/FOmegaInt/Typing.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 16022, "size": 29943 }
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Paths module lib.types.Torus where {- data Torus : Type₀ where baseT : Torus loopT1 : baseT == baseT loopT2 : baseT == baseT surfT : loopT1 ∙ loopT2 == loopT2 ∙ loopT1 -} module _ where private data #Torus-aux : Type₀ where #baseT : #Torus-aux data #Torus : Type₀ where #torus : #Torus-aux → (Unit → Unit) → #Torus Torus : Type₀ Torus = #Torus baseT : Torus baseT = #torus #baseT _ postulate -- HIT loopT1 : baseT == baseT loopT2 : baseT == baseT surfT : loopT1 ∙ loopT2 == loopT2 ∙ loopT1 {- Dependent elimination and computation rules -} module TorusElim {i} {P : Torus → Type i} (baseT* : P baseT) (loopT1* : baseT* == baseT* [ P ↓ loopT1 ]) (loopT2* : baseT* == baseT* [ P ↓ loopT2 ]) (surfT* : loopT1* ∙ᵈ loopT2* == loopT2* ∙ᵈ loopT1* [ (λ p → baseT* == baseT* [ P ↓ p ]) ↓ surfT ]) where f : Π Torus P f = f-aux phantom where f-aux : Phantom surfT* → Π Torus P f-aux phantom (#torus #baseT _) = baseT* postulate -- HIT loopT1-β : apd f loopT1 == loopT1* loopT2-β : apd f loopT2 == loopT2* private lhs : apd f (loopT1 ∙ loopT2) == loopT1* ∙ᵈ loopT2* lhs = apd f (loopT1 ∙ loopT2) =⟨ apd-∙ f loopT1 loopT2 ⟩ apd f loopT1 ∙ᵈ apd f loopT2 =⟨ loopT1-β |in-ctx (λ u → u ∙ᵈ apd f loopT2) ⟩ loopT1* ∙ᵈ apd f loopT2 =⟨ loopT2-β |in-ctx (λ u → loopT1* ∙ᵈ u) ⟩ loopT1* ∙ᵈ loopT2* ∎ rhs : apd f (loopT2 ∙ loopT1) == loopT2* ∙ᵈ loopT1* rhs = apd f (loopT2 ∙ loopT1) =⟨ apd-∙ f loopT2 loopT1 ⟩ apd f loopT2 ∙ᵈ apd f loopT1 =⟨ loopT2-β |in-ctx (λ u → u ∙ᵈ apd f loopT1) ⟩ loopT2* ∙ᵈ apd f loopT1 =⟨ loopT1-β |in-ctx (λ u → loopT2* ∙ᵈ u) ⟩ loopT2* ∙ᵈ loopT1* ∎ postulate -- HIT surfT-β : apd (apd f) surfT == lhs ◃ (surfT* ▹! rhs) module TorusRec {i} {A : Type i} (baseT* : A) (loopT1* loopT2* : baseT* == baseT*) (surfT* : loopT1* ∙ loopT2* == loopT2* ∙ loopT1*) where private module M = TorusElim {P = λ _ → A} baseT* (↓-cst-in loopT1*) (↓-cst-in loopT2*) (↓-cst-in-∙ loopT1 loopT2 loopT1* loopT2* !◃ (↓-cst-in2 surfT* ▹ (↓-cst-in-∙ loopT2 loopT1 loopT2* loopT1*))) f : Torus → A f = M.f loopT1-β : ap f loopT1 == loopT1* loopT1-β = apd=cst-in {f = f} M.loopT1-β loopT2-β : ap f loopT2 == loopT2* loopT2-β = apd=cst-in {f = f} M.loopT2-β private lhs : ap f (loopT1 ∙ loopT2) == loopT1* ∙ loopT2* lhs = ap f (loopT1 ∙ loopT2) =⟨ ap-∙ f loopT1 loopT2 ⟩ ap f loopT1 ∙ ap f loopT2 =⟨ loopT1-β |in-ctx (λ u → u ∙ ap f loopT2) ⟩ loopT1* ∙ ap f loopT2 =⟨ loopT2-β |in-ctx (λ u → loopT1* ∙ u) ⟩ loopT1* ∙ loopT2* ∎ rhs : ap f (loopT2 ∙ loopT1) == loopT2* ∙ loopT1* rhs = ap f (loopT2 ∙ loopT1) =⟨ ap-∙ f loopT2 loopT1 ⟩ ap f loopT2 ∙ ap f loopT1 =⟨ loopT2-β |in-ctx (λ u → u ∙ ap f loopT1) ⟩ loopT2* ∙ ap f loopT1 =⟨ loopT1-β |in-ctx (λ u → loopT2* ∙ u) ⟩ loopT2* ∙ loopT1* ∎ postulate -- Does not look easy surfT-β : ap (ap f) surfT == (lhs ∙ surfT*) ∙ (! rhs) -- surfT-β = {!M.surfT-β!} -- module TorusRecType {i} (baseT* : Type i) (loopT1* loopT2* : baseT* ≃ baseT*) -- (surfT* : (x : baseT*) → –> loopT2* (–> loopT2* x) == –> loopT1* (–> loopT2* x)) where -- open TorusRec baseT* (ua loopT1*) (ua loopT2*) {!!} public -- -- TODO
{ "alphanum_fraction": 0.5278779473, "avg_line_length": 32.4774774775, "ext": "agda", "hexsha": "565b6d599c8d4a66610b95c9f20cd69c199ab19a", "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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "lib/types/Torus.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "lib/types/Torus.agda", "max_line_length": 95, "max_stars_count": 1, "max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda", "max_stars_repo_path": "lib/types/Torus.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z", "num_tokens": 1608, "size": 3605 }
{-# OPTIONS --without-K --safe #-} module Experiment.SumFin where open import Data.Empty open import Data.Unit open import Data.Sum open import Data.Nat open import Data.Nat.Properties open import Relation.Binary.PropositionalEquality private variable k : ℕ Fin : ℕ → Set Fin zero = ⊥ Fin (suc n) = ⊤ ⊎ (Fin n) pattern fzero = inj₁ tt pattern fsuc n = inj₂ n finj : Fin k → Fin (suc k) finj {suc k} fzero = fzero finj {suc k} (fsuc n) = fsuc (finj {k} n) toℕ : Fin k → ℕ toℕ {suc k} (inj₁ tt) = zero toℕ {suc k} (inj₂ x) = suc (toℕ {k} x) toℕ-injective : {m n : Fin k} → toℕ m ≡ toℕ n → m ≡ n toℕ-injective {suc k} {fzero} {fzero} _ = refl toℕ-injective {suc k} {fzero} {fsuc x} () toℕ-injective {suc k} {fsuc m} {fzero} () toℕ-injective {suc k} {fsuc m} {fsuc x} p = cong fsuc (toℕ-injective (suc-injective p))
{ "alphanum_fraction": 0.6427718041, "avg_line_length": 22.6216216216, "ext": "agda", "hexsha": "0b3c84ad9b409d3f9033c713da6b0db852c9914a", "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": "Experiment/SumFin.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": "Experiment/SumFin.agda", "max_line_length": 87, "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": "Experiment/SumFin.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": 341, "size": 837 }
{-# OPTIONS --without-K #-} open import HoTT module homotopy.TorusIsProductCircles where surfT' : loopT1 ∙ loopT2 == loopT2 ∙' loopT1 surfT' = surfT ∙ (∙=∙' loopT2 loopT1) private to-surfT : (pair×= loop idp) ∙ (pair×= idp loop) == (pair×= idp loop) ∙ (pair×= loop idp) to-surfT = pair×= loop idp ∙ pair×= idp loop =⟨ ×-∙ loop idp idp loop ⟩ pair×= (loop ∙ idp) (idp ∙ loop) =⟨ ∙-unit-r loop |in-ctx (λ u → pair×= u loop) ⟩ pair×= loop loop =⟨ ! (∙-unit-r loop) |in-ctx (λ u → pair×= loop u) ⟩ pair×= (idp ∙ loop) (loop ∙ idp) =⟨ ! (×-∙ idp loop loop idp) ⟩ pair×= idp loop ∙ pair×= loop idp ∎ module To = TorusRec (base , base) (pair×= loop idp) (pair×= idp loop) to-surfT {- First map -} to : Torus → S¹ × S¹ to = To.f {- Second map -} from-c : S¹ → (S¹ → Torus) from-c = FromC.f module M2 where module FromCBase = S¹Rec baseT loopT2 from-c-base : S¹ → Torus from-c-base = FromCBase.f from-c-loop-loop' : loopT1 ∙ ap from-c-base loop =-= ap from-c-base loop ∙' loopT1 from-c-loop-loop' = loopT1 ∙ ap from-c-base loop =⟪ FromCBase.loop-β |in-ctx (λ u → loopT1 ∙ u) ⟫ loopT1 ∙ loopT2 =⟪ surfT' ⟫ loopT2 ∙' loopT1 =⟪ ! FromCBase.loop-β |in-ctx (λ u → u ∙' loopT1) ⟫ ap from-c-base loop ∙' loopT1 ∎∎ from-c-loop-loop : loopT1 == loopT1 [ (λ x → from-c-base x == from-c-base x) ↓ loop ] from-c-loop-loop = ↓-='-in (↯ from-c-loop-loop') module FromCLoop = S¹Elim loopT1 from-c-loop-loop from-c-loop' = FromCLoop.f from-c-loop = λ= from-c-loop' module FromC = S¹Rec from-c-base from-c-loop from : S¹ × S¹ → Torus from (x , y) = from-c x y open M2 {- First composition -} thing : (y : S¹) → ap (λ x → from-c x y) loop == from-c-loop' y thing y = ap ((λ u → u y) ∘ from-c) loop =⟨ ap-∘ (λ u → u y) from-c loop ⟩ app= (ap from-c loop) y =⟨ FromC.loop-β |in-ctx (λ u → app= u y)⟩ app= (λ= from-c-loop') y =⟨ app=-β from-c-loop' y ⟩ from-c-loop' y ∎ to-from-c : (x y : S¹) → to (from-c x y) == (x , y) to-from-c = {!!} --S¹-elim to-from-c-base (↓-cst→app-in to-from-c-loop) where to-from-c-base-loop' : ap (to ∘ from-c-base) loop =-= ap (λ y → (base , y)) loop to-from-c-base-loop' = ap (to ∘ from-c-base) loop =⟪ ap-∘ to from-c-base loop ⟫ ap to (ap from-c-base loop) =⟪ FromCBase.loop-β |in-ctx ap to ⟫ ap to loopT2 =⟪ To.loopT2-β ⟫ pair×= idp loop =⟪ ! (ap-cst,id _ loop) ⟫ ap (λ y → (base , y)) loop ∎∎ to-from-c-base-loop : idp == idp [ (λ z → to (from-c-base z) == (base , z)) ↓ loop ] to-from-c-base-loop = ↓-='-in (! (↯ to-from-c-base-loop')) module ToFromCBase = S¹Elim idp to-from-c-base-loop -- 1!to-from-c-base-loop : idp == idp [ (λ z → to (from-c-base (fst z)) == z) ↓ (pair×= loop idp) ] -- 1!to-from-c-base-loop = ↓-='-in (! (↯ 1! to-from-c-base-loop')) -- module 1!ToFromCBase!1 = S¹Elim idp 1!to-from-c-base-loop to-from-c-base : (y : S¹) → to (from-c-base y) == (base , y) to-from-c-base = ToFromCBase.f thing2 : (y : S¹) → ap to (from-c-loop' y) == to-from-c-base y ∙ pair×= loop idp ∙' (! (to-from-c-base y)) thing2 = {!S¹-elim To.loopT1-β {!To.loopT1-β!}!} to-from-c-loop : (y : S¹) → to-from-c-base y == to-from-c-base y [ (λ x → to (from-c x y) == (x , y)) ↓ loop ] to-from-c-loop = {!S¹-elim to-from-c-loop-base ?!} where to-from-c-loop-base2 : ap (λ x → (x , base)) loop =-= ap (λ x → to (from-c x base)) loop to-from-c-loop-base2 = ap (λ z → z , base) loop =⟪ {!ap-id,cst _ loop!} ⟫ pair×= loop idp =⟪ ! To.loopT1-β ⟫ ap to loopT1 =⟪ ! (thing base) |in-ctx ap to ⟫ ap to (ap (λ z → from-c z base) loop) =⟪ ! (ap-∘ to (λ z → from-c z base) loop) ⟫ ap (λ z → to (from-c z base)) loop ∎∎ to-from-c-loop-base : idp == idp [ (λ x → to (from-c x base) == (x , base)) ↓ loop ] to-from-c-loop-base = ↓-='-in (↯ to-from-c-loop-base2) lemma : ↯ to-from-c-loop-base2 == ↯ to-from-c-loop-base2 [ (λ y → to-from-c-base y ∙ ap (λ x → x , y) loop == ap (λ x → to (from-c x y)) loop ∙' to-from-c-base y) ↓ loop ] lemma = ↓-=-in ( (↯ to-from-c-loop-base2) ◃ apd (λ y → ap (λ x → to (from-c x y)) loop ∙' to-from-c-base y) loop =⟨ {!!} ⟩ (↯ to-from-c-loop-base2) ◃ ((apd (λ y → ap (λ x → to (from-c x y)) loop) loop) ∙'2 (apd to-from-c-base loop)) =⟨ {!!} ⟩ ((↯ to-from-c-loop-base2) ◃ (apd (λ y → ap (λ x → to (from-c x y)) loop) loop)) ∙'2 (apd to-from-c-base loop) =⟨ {!!} ⟩ ((↯ (to-from-c-loop-base2 !1)) ◃ ((apd (λ y → ap to (ap (λ x → from-c x y) loop)) loop) ▹ (↯ to-from-c-loop-base2 #1))) ∙'2 (apd to-from-c-base loop) =⟨ {!!} ⟩ ((↯ (to-from-c-loop-base2 !2)) ◃ ((apd (λ y → ap to (from-c-loop' y)) loop) ▹ (↯ to-from-c-loop-base2 #2))) ∙'2 (apd to-from-c-base loop) =⟨ {!!} ⟩ ((↯ (to-from-c-loop-base2 !2)) ◃ ((ap↓ (ap to) (apd from-c-loop' loop)) ▹ (↯ to-from-c-loop-base2 #2))) ∙'2 (apd to-from-c-base loop) =⟨ {!!} ⟩ ((↯ (to-from-c-loop-base2 !2)) ◃ ((ap↓ (ap to) from-c-loop-loop) ▹ (↯ to-from-c-loop-base2 #2))) ∙'2 (apd to-from-c-base loop) =⟨ {!!} ⟩ apd (λ y → to-from-c-base y ∙ ap (λ x → x , y) loop) loop ▹ (↯ to-from-c-loop-base2) ∎) {- Have: PathOver (λ z → to (from-c-base z) == to (from-c-base z)) loop (ap (λ x → x , base) loop) (ap (λ x → to (from-c x base)) loop) -} -- lemma2 : apd (λ y → ap (λ x → to (from-c x y)) loop) loop == {!!} -- lemma2 = -- apd (λ y → ap (λ x → to (from-c x y)) loop) loop =⟨ {!!} ⟩ -- apd (λ y → ap to (ap (λ x → from-c x y) loop)) loop =⟨ {!!} ⟩ -- apd (λ y → ap to (from-c-loop' y)) loop =⟨ {!!} ⟩ -- api2 (ap to) (apd from-c-loop' loop) =⟨ {!!} ⟩ -- apd (ap to) surfT =⟨ {!!} ⟩ -- ? ∎ to-from : (x : S¹ × S¹) → to (from x) == x to-from (x , y) = to-from-c x y {- Second composition -} from-to : (x : Torus) → from (to x) == x from-to = {!Torus-elim idp from-to-loopT1 from-to-loopT2 {!!}!} where from-to-loopT1 : idp == idp [ (λ z → from (to z) == z) ↓ loopT1 ] from-to-loopT1 = ↓-∘=idf-in from to (ap from (ap to loopT1) =⟨ To.loopT1-β |in-ctx ap from ⟩ ap from (pair×= loop idp) =⟨ lemma from loop (idp {a = base}) ⟩ ap (λ u → u base) (ap from-c loop) =⟨ FromC.loop-β |in-ctx ap (λ u → u base) ⟩ ap (λ u → u base) (λ= from-c-loop') =⟨ app=-β from-c-loop' base ⟩ loopT1 ∎) where lemma : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A × B → C) {x y : A} (p : x == y) {z t : B} (q : z == t) → ap f (pair×= p q) == app= (ap (curry f) p) z ∙' ap (curry f y) q lemma f idp idp = idp from-to-loopT2 : idp == idp [ (λ z → from (to z) == z) ↓ loopT2 ] from-to-loopT2 = ↓-∘=idf-in from to (ap from (ap to loopT2) =⟨ To.loopT2-β |in-ctx ap from ⟩ ap from (pair×= idp loop) =⟨ lemma' from (idp {a = base}) loop ⟩ ap from-c-base loop =⟨ FromCBase.loop-β ⟩ loopT2 ∎) where lemma' : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A × B → C) {x y : A} (p : x == y) {z t : B} (q : z == t) → ap f (pair×= p q) == ap (curry f x) q ∙' app= (ap (curry f) p) t lemma' f idp idp = idp -- to-from-c-app-base : (y : S¹) → to (from-c y base) == (y , base) -- to-from-c-app-base = S¹-elim {!to (from-c base base) == base , base!} {!!}
{ "alphanum_fraction": 0.5028731792, "avg_line_length": 43.0057471264, "ext": "agda", "hexsha": "4294a1586645c0480685341ee9a5aa19b3ed09d7", "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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "homotopy/TorusIsProductCircles.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "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": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "homotopy/TorusIsProductCircles.agda", "max_line_length": 175, "max_stars_count": 1, "max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda", "max_stars_repo_path": "homotopy/TorusIsProductCircles.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z", "num_tokens": 3097, "size": 7483 }
open import Common.Prelude open import Common.Reflection {-# NON_TERMINATING #-} -- Note that in the body of the unquote, 'loop' really means 'quote loop'. unquoteDecl loop = define (vArg loop) (funDef (def (quote Nat) []) (clause [] (def loop []) ∷ []))
{ "alphanum_fraction": 0.6175438596, "avg_line_length": 25.9090909091, "ext": "agda", "hexsha": "cf7de701f56a5e84905544dc6c9e9d64df19a399", "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/Issue1218.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/Issue1218.agda", "max_line_length": 74, "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/Issue1218.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": 72, "size": 285 }
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.types.Empty open import lib.types.Sigma open import lib.types.Paths module lib.types.Pi where instance Π-level : ∀ {i j} {A : Type i} {B : A → Type j} {n : ℕ₋₂} → ((x : A) → has-level n (B x)) → has-level n (Π A B) Π-level {n = ⟨-2⟩} p = has-level-in ((λ x → contr-center (p x)) , lemma) where abstract lemma = λ f → λ= (λ x → contr-path (p x) (f x)) Π-level {n = S n} p = has-level-in lemma where abstract lemma = λ f g → equiv-preserves-level λ=-equiv {{Π-level (λ x → has-level-apply (p x) (f x) (g x))}} Πi-level : ∀ {i j} {A : Type i} {B : A → Type j} {n : ℕ₋₂} → ((x : A) → has-level n (B x)) → has-level n ({x : A} → B x) Πi-level {A = A} {B} p = equiv-preserves-level e {{Π-level p}} where e : Π A B ≃ ({x : A} → B x) fst e f {x} = f x is-equiv.g (snd e) f x = f is-equiv.f-g (snd e) _ = idp is-equiv.g-f (snd e) _ = idp is-equiv.adj (snd e) _ = idp {- Equivalences in a Π-type -} Π-emap-l : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) → (e : A ≃ B) → Π A (P ∘ –> e) ≃ Π B P Π-emap-l {A = A} {B = B} P e = equiv f g f-g g-f where f : Π A (P ∘ –> e) → Π B P f u b = transport P (<–-inv-r e b) (u (<– e b)) g : Π B P → Π A (P ∘ –> e) g v a = v (–> e a) abstract f-g : ∀ v → f (g v) == v f-g v = λ= λ b → to-transp (apd v (<–-inv-r e b)) g-f : ∀ u → g (f u) == u g-f u = λ= λ a → to-transp $ transport (λ p → u _ == _ [ P ↓ p ]) (<–-inv-adj e a) (↓-ap-in P (–> e) (apd u $ <–-inv-l e a)) Π-emap-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} → (∀ x → B x ≃ C x) → Π A B ≃ Π A C Π-emap-r {A = A} {B = B} {C = C} k = equiv f g f-g g-f where f : Π A B → Π A C f c x = –> (k x) (c x) g : Π A C → Π A B g d x = <– (k x) (d x) abstract f-g : ∀ d → f (g d) == d f-g d = λ= (λ x → <–-inv-r (k x) (d x)) g-f : ∀ c → g (f c) == c g-f c = λ= (λ x → <–-inv-l (k x) (c x)) {- favonia: This part is not used. module _ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : A₀ → Type j₀} {B₁ : A₁ → Type j₁} where Π-emap : (u : A₀ ≃ A₁) (v : ∀ a → B₀ (<– u a) ≃ B₁ a) → Π A₀ B₀ ≃ Π A₁ B₁ Π-emap u v = Π A₀ B₀ ≃⟨ Π-emap-l _ (u ⁻¹) ⁻¹ ⟩ Π A₁ (B₀ ∘ <– u) ≃⟨ Π-emap-r v ⟩ Π A₁ B₁ ≃∎ Π-emap' : (u : A₀ ≃ A₁) (v : ∀ a → B₀ a ≃ B₁ (–> u a)) → Π A₀ B₀ ≃ Π A₁ B₁ Π-emap' u v = Π A₀ B₀ ≃⟨ Π-emap-r v ⟩ Π A₀ (B₁ ∘ –> u) ≃⟨ Π-emap-l _ u ⟩ Π A₁ B₁ ≃∎ -} {- Coversions between functions with implicit and explicit arguments -} expose-equiv : ∀ {i j} {A : Type i} {B : A → Type j} → ({x : A} → B x) ≃ ((x : A) → B x) expose-equiv = (λ f a → f {a}) , is-eq _ (λ f {a} → f a) (λ _ → idp) (λ _ → idp) {- Dependent paths in a Π-type -} module _ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k} where ↓-Π-in : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ pair= p q ]) → (u == u' [ (λ x → Π (B x) (C x)) ↓ p ]) ↓-Π-in {p = idp} f = λ= (λ x → f (idp {a = x})) ↓-Π-out : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → (u == u' [ (λ x → Π (B x) (C x)) ↓ p ]) → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ pair= p q ]) ↓-Π-out {p = idp} q idp = app= q _ ↓-Π-β : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → (f : {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ pair= p q ]) → {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → ↓-Π-out (↓-Π-in f) q == f q ↓-Π-β {p = idp} f idp = app=-β (λ x → f (idp {a = x})) _ ↓-Π-η : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → (q : (u == u' [ (λ x → Π (B x) (C x)) ↓ p ])) → ↓-Π-in (↓-Π-out q) == q ↓-Π-η {p = idp} q = ! (λ=-η q) ↓-Π-equiv : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ pair= p q ]) ≃ (u == u' [ (λ x → Π (B x) (C x)) ↓ p ]) ↓-Π-equiv {p = idp} = equiv ↓-Π-in ↓-Π-out ↓-Π-η (λ u → <– (ap-equiv expose-equiv _ _) (λ= (λ t → <– (ap-equiv expose-equiv _ _) (λ= (λ t' → λ= (↓-Π-β u)))))) {- Dependent paths in a Π-type where the codomain is not dependent on anything Right now, this is defined in terms of the previous one. Maybe it’s a good idea, maybe not. -} module _ {i j k} {A : Type i} {B : A → Type j} {C : Type k} {x x' : A} {p : x == x'} {u : B x → C} {u' : B x' → C} where ↓-app→cst-in : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t') → (u == u' [ (λ x → B x → C) ↓ p ]) ↓-app→cst-in f = ↓-Π-in (λ q → ↓-cst-in (f q)) ↓-app→cst-out : (u == u' [ (λ x → B x → C) ↓ p ]) → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t') ↓-app→cst-out r q = ↓-cst-out (↓-Π-out r q) ↓-app→cst-β : (f : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t')) → {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → ↓-app→cst-out (↓-app→cst-in f) q == f q ↓-app→cst-β f q = ↓-app→cst-out (↓-app→cst-in f) q =⟨ idp ⟩ ↓-cst-out (↓-Π-out (↓-Π-in (λ qq → ↓-cst-in (f qq))) q) =⟨ ↓-Π-β (λ qq → ↓-cst-in (f qq)) q |in-ctx ↓-cst-out ⟩ ↓-cst-out (↓-cst-in {p = pair= p q} (f q)) =⟨ ↓-cst-β (pair= p q) (f q) ⟩ f q =∎ {- favonia: these lemmas are not used anywhere {- Similar to above, with domain being the identity function. -} {- These lemmas were in homotopy.FunctionOver and in different conventions. -} module _ {i j} {A B : Type i} {C : Type j} {u : A → C} {v : B → C} where ↓-idf→cst-in : ∀ (p : A == B) → u == v ∘ coe p → u == v [ (λ x → x → C) ↓ p ] ↓-idf→cst-in idp q = q ↓-idf→cst-ua-in : ∀ (e : A ≃ B) → u == v ∘ –> e → u == v [ (λ x → x → C) ↓ ua e ] ↓-idf→cst-ua-in e q = ↓-idf→cst-in (ua e) (q ∙ ap (v ∘_) (λ= λ a → ! (coe-β e a))) ↓-idf→cst-in' : ∀ (p : A == B) → u ∘ coe! p == v → u == v [ (λ x → x → C) ↓ p ] ↓-idf→cst-in' idp q = q ↓-idf→cst-ua-in' : ∀ (e : A ≃ B) → u ∘ <– e == v → u == v [ (λ x → x → C) ↓ ua e ] ↓-idf→cst-ua-in' e q = ↓-idf→cst-in' (ua e) (ap (u ∘_) (λ= λ a → coe!-β e a) ∙ q) module _ {i j} {A B : Type i} {C : Type j} {u : C → A} {v : C → B} where ↓-cst→idf-in : ∀ (p : A == B) → coe p ∘ u == v → u == v [ (λ x → C → x) ↓ p ] ↓-cst→idf-in idp q = q ↓-cst→idf-ua-in : ∀ (e : A ≃ B) → –> e ∘ u == v → u == v [ (λ x → C → x) ↓ ua e ] ↓-cst→idf-ua-in e q = ↓-cst→idf-in (ua e) (ap (_∘ u) (λ= λ a → coe-β e a) ∙ q) ↓-cst→idf-in' : ∀ (p : A == B) → u == coe! p ∘ v → u == v [ (λ x → C → x) ↓ p ] ↓-cst→idf-in' idp q = q ↓-cst→idf-ua-in' : ∀ (e : A ≃ B) → u == <– e ∘ v → u == v [ (λ x → C → x) ↓ ua e ] ↓-cst→idf-ua-in' e q = ↓-cst→idf-in' (ua e) (q ∙ ap (_∘ v) (λ= λ a → ! (coe!-β e a))) -} {- Dependent paths in an arrow type -} module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {x x' : A} {p : x == x'} {u : B x → C x} {u' : B x' → C x'} where ↓-→-in : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ C ↓ p ]) → (u == u' [ (λ x → B x → C x) ↓ p ]) ↓-→-in f = ↓-Π-in (λ q → ↓-cst2-in p q (f q)) ↓-→-out : (u == u' [ (λ x → B x → C x) ↓ p ]) → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ C ↓ p ]) ↓-→-out r q = ↓-cst2-out p q (↓-Π-out r q) {- Transport form of dependent path in an arrow type -} module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where ↓-→-from-transp : {x x' : A} {p : x == x'} {u : B x → C x} {u' : B x' → C x'} → transport C p ∘ u == u' ∘ transport B p → u == u' [ (λ x → B x → C x) ↓ p ] ↓-→-from-transp {p = idp} q = q ↓-→-to-transp : {x x' : A} {p : x == x'} {u : B x → C x} {u' : B x' → C x'} → u == u' [ (λ x → B x → C x) ↓ p ] → transport C p ∘ u == u' ∘ transport B p ↓-→-to-transp {p = idp} q = q -- Dependent paths in a Π-type where the domain is constant module _ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k} where ↓-Π-cst-app-in : {x x' : A} {p : x == x'} {u : (b : B) → C x b} {u' : (b : B) → C x' b} → ((b : B) → u b == u' b [ (λ x → C x b) ↓ p ]) → (u == u' [ (λ x → (b : B) → C x b) ↓ p ]) ↓-Π-cst-app-in {p = idp} f = λ= f ↓-Π-cst-app-out : {x x' : A} {p : x == x'} {u : (b : B) → C x b} {u' : (b : B) → C x' b} → (u == u' [ (λ x → (b : B) → C x b) ↓ p ]) → ((b : B) → u b == u' b [ (λ x → C x b) ↓ p ]) ↓-Π-cst-app-out {p = idp} q = app= q split-ap2 : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k} (f : Σ A B → C) {x y : A} (p : x == y) {u : B x} {v : B y} (q : u == v [ B ↓ p ]) → ap f (pair= p q) == ↓-app→cst-out (apd (curry f) p) q split-ap2 f idp idp = idp {- Interaction of [apd] with function composition. The basic idea is that [apd (g ∘ f) p == apd g (apd f p)] but the version here is well-typed. Note that we assume a propositional equality [r] between [apd f p] and [q]. -} apd-∘ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k} (g : {a : A} → Π (B a) (C a)) (f : Π A B) {x y : A} (p : x == y) {q : f x == f y [ B ↓ p ]} (r : apd f p == q) → apd (g ∘ f) p == ↓-apd-out C r (apd↓ g q) apd-∘ g f idp idp = idp {- When [g] is nondependent, it’s much simpler -} apd-∘' : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} (g : {a : A} → B a → C a) (f : Π A B) {x y : A} (p : x == y) → apd (g ∘ f) p == ap↓ g (apd f p) apd-∘' g f idp = idp ∘'-apd : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} (g : {a : A} → B a → C a) (f : Π A B) {x y : A} (p : x == y) → ap↓ g (apd f p) == apd (g ∘ f) p ∘'-apd g f idp = idp {- And when [f] is nondependent, it’s also a bit simpler -} apd-∘'' : ∀ {i j k} {A : Type i} {B : Type j} {C : (b : B) → Type k} (g : Π B C) (f : A → B) {x y : A} (p : x == y) {q : f x == f y} (r : ap f p == q) → apd (g ∘ f) p == ↓-ap-out= C f p r (apd g q) --(apd↓ g q) apd-∘'' g f idp idp = idp {- 2-dimensional coherence conditions -} -- lhs : -- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B} -- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} -- (k : (u ◃ apd g p) == (apd f p ▹ v)) -- (h : {a : A} → B a → C a) -- → ap h u ◃ apd (h ∘ g) p == ap↓ h (u ◃ apd g p) -- rhs : -- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B} -- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} -- (k : (u ◃ apd g p) == (apd f p ▹ v)) -- (h : {a : A} → B a → C a) -- → ap↓ h (apd f p ▹ v) == apd (h ∘ f) p ▹ ap h v -- ap↓-↓-=-in : -- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B} -- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} -- (k : (u ◃ apd g p) == (apd f p ▹ v)) -- (h : {a : A} → B a → C a) -- → ap↓ (λ {a} → ap (h {a = a})) (↓-=-in {p = p} {u = u} {v = v} k) -- == ↓-=-in (lhs {f = f} {g = g} k h ∙ ap (ap↓ (λ {a} → h {a = a})) k -- ∙ rhs {f = f} {g = g} k h) {- Commutation of [ap↓ (ap h)] and [↓-swap!]. This is "just" J, but it’s not as easy as it seems. -} -- module Ap↓-swap! {i j k ℓ} {A : Type i} {B : Type j} {C : Type k} -- {D : Type ℓ} (h : C → D) (f : A → C) (g : B → C) -- {a a' : A} {p : a == a'} {b b' : B} {q : b == b'} -- (r : f a == g b') (s : f a' == g b) -- (t : r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ]) -- where -- lhs : ap h (ap f p ∙' s) == ap (h ∘ f) p ∙' ap h s -- lhs = ap-∙' h (ap f p) s ∙ (ap (λ u → u ∙' ap h s) (∘-ap h f p)) -- rhs : ap h (s ∙ ap g q) == ap h s ∙ ap (h ∘ g) q -- rhs = ap-∙ h s (ap g q) ∙ (ap (λ u → ap h s ∙ u) (∘-ap h g q)) -- β : ap↓ (ap h) (↓-swap! f g r s t) == -- lhs ◃ ↓-swap! (h ∘ f) (h ∘ g) (ap h r) (ap h s) (ap↓ (ap h) t ▹ rhs) -- β with a | a' | p | b | b' | q | r | s | t -- β | a | .a | idp | b | .b | idp | r | s | t = coh r s t where -- T : {x x' : C} (r s : x == x') (t : r == s ∙ idp) → Type _ -- T r s t = -- ap (ap h) (∙'-unit-l s ∙ ! (∙-unit-r s) ∙ ! t) == -- (ap-∙' h idp s ∙ idp) -- ∙ -- (∙'-unit-l (ap h s) ∙ -- ! (∙-unit-r (ap h s)) ∙ -- ! -- (ap (ap h) t ∙' -- (ap-∙ h s idp ∙ idp))) -- coh' : {x x' : C} {r s : x == x'} (t : r == s) → T r s (t ∙ ! (∙-unit-r s)) -- coh' {r = idp} {s = .idp} idp = idp -- coh : {x x' : C} (r s : x == x') (t : r == s ∙ idp) → T r s t -- coh r s t = transport (λ t → T r s t) (coh2 t (∙-unit-r s)) (coh' (t ∙ ∙-unit-r s)) where -- coh2 : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → (p ∙ q) ∙ ! q == p -- coh2 idp idp = idp -- module _ {i j k} {A : Type i} {B B' : Type j} {C : Type k} (f : A → C) (g' : B' → B) (g : B → C) where -- abc : {a a' : A} {p : a == a'} {c c' : B'} {q' : c == c'} {q : g' c == g' c'} -- (r : f a == g (g' c')) (s : f a' == g (g' c)) -- (t : q == ap g' q') -- (α : r == s ∙ ap g q [ (λ x → f x == g (g' c')) ↓ p ]) -- → {!(↓-swap! f g r s α ▹ ?) ∙'2ᵈ ?!} == ↓-swap! f (g ∘ g') {p = p} {q = q'} r s (α ▹ ap (λ u → s ∙ u) (ap (ap g) t ∙ ∘-ap g g' q')) -- abc = {!!} {- Functoriality of application and function extensionality -} ∙-app= : ∀ {i j} {A : Type i} {B : A → Type j} {f g h : Π A B} (α : f == g) (β : g == h) → α ∙ β == λ= (λ x → app= α x ∙ app= β x) ∙-app= idp β = λ=-η β ∙-λ= : ∀ {i j} {A : Type i} {B : A → Type j} {f g h : Π A B} (α : f ∼ g) (β : g ∼ h) → λ= α ∙ λ= β == λ= (λ x → α x ∙ β x) ∙-λ= α β = ∙-app= (λ= α) (λ= β) ∙ ap λ= (λ= (λ x → ap (λ w → w ∙ app= (λ= β) x) (app=-β α x) ∙ ap (λ w → α x ∙ w) (app=-β β x)))
{ "alphanum_fraction": 0.3740441801, "avg_line_length": 35.7569620253, "ext": "agda", "hexsha": "f7969b418d30211ded8ad2ddd93d12fd6b81e4b5", "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": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "core/lib/types/Pi.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "timjb/HoTT-Agda", "max_issues_repo_path": "core/lib/types/Pi.agda", "max_line_length": 138, "max_stars_count": null, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "core/lib/types/Pi.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6854, "size": 14124 }
open import Data.Nat module OpenTheory where ---------------------------------------------------------------------- data Vec (A : Set) : ℕ → Set₁ where nil : Vec A zero cons : (n : ℕ) (x : A) (xs : Vec A n) → Vec A (suc n) data Vec2 : Set → ℕ → Set₁ where nil : (A : Set) → Vec2 A zero cons : (A : Set) (n : ℕ) (x : A) (xs : Vec2 A n) → Vec2 A (suc n) elimVec : {A : Set} (P : (n : ℕ) → Vec A n → Set) (pnil : P zero nil) (pcnons : (n : ℕ) (x : A) (xs : Vec A n) → P n xs → P (suc n) (cons n x xs)) (n : ℕ) (xs : Vec A n) → P n xs elimVec P pnil pcons .zero nil = pnil elimVec P pnil pcons .(suc n) (cons n x xs) = pcons n x xs (elimVec P pnil pcons n xs) ---------------------------------------------------------------------- data Tree (A B : Set) : ℕ → ℕ → Set where leaf₁ : A → Tree A B (suc zero) zero leaf₂ : B → Tree A B zero (suc zero) branch : (m n x y : ℕ) → Tree A B m n → Tree A B x y → Tree A B (m + x) (n + y) ----------------------------------------------------------------------
{ "alphanum_fraction": 0.4198250729, "avg_line_length": 33.1935483871, "ext": "agda", "hexsha": "bd0c4360a3b86223a2e8d8c79e8afbfbf22ed737", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:31:22.000Z", "max_forks_repo_forks_event_min_datetime": "2016-05-02T08:56:15.000Z", "max_forks_repo_head_hexsha": "832383d7adf37aa2364213fb0aeb67e9f61a248f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "larrytheliquid/generic-elim", "max_forks_repo_path": "slides/OpenTheory.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "832383d7adf37aa2364213fb0aeb67e9f61a248f", "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/generic-elim", "max_issues_repo_path": "slides/OpenTheory.agda", "max_line_length": 86, "max_stars_count": 11, "max_stars_repo_head_hexsha": "832383d7adf37aa2364213fb0aeb67e9f61a248f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/generic-elim", "max_stars_repo_path": "slides/OpenTheory.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-09T08:46:42.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-02T14:05:20.000Z", "num_tokens": 353, "size": 1029 }
module PiQ.Everything where open import PiQ.Syntax -- Syntax of PiQ open import PiQ.Opsem -- Abstract machine semantics of PiQ open import PiQ.AuxLemmas -- Some auxiliary lemmas about opsem for forward/backward deterministic proof open import PiQ.NoRepeat -- Forward/backward deterministic lemmas and Non-repeating lemma open import PiQ.Invariants -- Some invariants about abstract machine semantics open import PiQ.Eval -- Evaluator for PiQ open import PiQ.Interp -- Big-step intepreter open import PiQ.Properties -- Properties of PiQ open import PiQ.Examples -- Examples open import PiQ.SAT -- SAT solver
{ "alphanum_fraction": 0.7664576803, "avg_line_length": 53.1666666667, "ext": "agda", "hexsha": "15385a79cdc61bb360f2fe2f6b14c224c4b7c380", "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": "PiQ/Everything.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": "PiQ/Everything.agda", "max_line_length": 104, "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": "PiQ/Everything.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": 156, "size": 638 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Setoids.Setoids open import Rings.Definition open import Sets.EquivalenceRelations open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Rings.IntegralDomains.Definition {m n : _} {A : Set n} {S : Setoid {n} {m} A} {_+_ _*_ : A → A → A} (R : Ring S _+_ _*_) where open Setoid S open Equivalence eq open Ring R record IntegralDomain : Set (lsuc m ⊔ n) where field intDom : {a b : A} → (a * b) ∼ (Ring.0R R) → ((a ∼ (Ring.0R R)) → False) → b ∼ (Ring.0R R) nontrivial : Setoid._∼_ S (Ring.1R R) (Ring.0R R) → False decidedIntDom : ({a b : A} → (a * b) ∼ (Ring.0R R) → (a ∼ 0R) || (b ∼ 0R)) → ({a b : A} → (a * b) ∼ 0R → ((a ∼ (Ring.0R R)) → False) → b ∼ (Ring.0R R)) decidedIntDom f ab=0 a!=0 with f ab=0 decidedIntDom f ab=0 a!=0 | inl x = exFalso (a!=0 x) decidedIntDom f ab=0 a!=0 | inr x = x
{ "alphanum_fraction": 0.6085526316, "avg_line_length": 36.48, "ext": "agda", "hexsha": "c38e53f700d1fad0e773740873e513a30b6a6f4f", "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": "Rings/IntegralDomains/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": "Rings/IntegralDomains/Definition.agda", "max_line_length": 151, "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": "Rings/IntegralDomains/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": 376, "size": 912 }
{-# OPTIONS --without-K #-} open import HoTT open import homotopy.HSpace renaming (HSpaceStructure to HSS) open import homotopy.WedgeExtension module homotopy.Pi2HSusp where module Pi2HSusp {i} (A : Type i) (gA : has-level 1 A) (cA : is-connected 0 A) (A-H : HSS A) where {- TODO this belongs somewhere else, but where? -} private Type=-ext : ∀ {i} {A B : Type i} (p q : A == B) → ((x : A) → coe p x == coe q x) → p == q Type=-ext p q α = ! (ua-η p) ∙ ap ua (pair= (λ= α) (prop-has-all-paths-↓ (is-equiv-is-prop (coe q)))) ∙ ua-η q open HSS A-H open ConnectedHSpace A cA A-H P : Suspension A → Type i P x = Trunc 1 (north == x) module Codes = SuspensionRec A A (λ a → ua (μ-e-r-equiv a)) Codes : Suspension A → Type i Codes = Codes.f Codes-level : (x : Suspension A) → has-level 1 (Codes x) Codes-level = Suspension-elim gA gA (λ _ → prop-has-all-paths-↓ has-level-is-prop) encode₀ : {x : Suspension A} → (north == x) → Codes x encode₀ α = transport Codes α e encode : {x : Suspension A} → P x → Codes x encode {x} = Trunc-rec (Codes-level x) encode₀ decode' : A → P north decode' a = [ (merid a ∙ ! (merid e)) ] abstract transport-Codes-mer : (a a' : A) → transport Codes (merid a) a' == μ a a' transport-Codes-mer a a' = coe (ap Codes (merid a)) a' =⟨ Codes.merid-β a |in-ctx (λ w → coe w a') ⟩ coe (ua (μ-e-r-equiv a)) a' =⟨ coe-β (μ-e-r-equiv a) a' ⟩ μ a a' ∎ transport-Codes-mer-e-! : (a : A) → transport Codes (! (merid e)) a == a transport-Codes-mer-e-! a = coe (ap Codes (! (merid e))) a =⟨ ap-! Codes (merid e) |in-ctx (λ w → coe w a) ⟩ coe (! (ap Codes (merid e))) a =⟨ Codes.merid-β e |in-ctx (λ w → coe (! w) a) ⟩ coe (! (ua (μ-e-r-equiv e))) a =⟨ Type=-ext (ua (μ-e-r-equiv e)) idp (λ x → coe-β _ x ∙ μ-e-l x) |in-ctx (λ w → coe (! w) a) ⟩ coe (! idp) a ∎ abstract encode-decode' : (a : A) → encode (decode' a) == a encode-decode' a = transport Codes (merid a ∙ ! (merid e)) e =⟨ trans-∙ {B = Codes} (merid a) (! (merid e)) e ⟩ transport Codes (! (merid e)) (transport Codes (merid a) e) =⟨ transport-Codes-mer a e ∙ μ-e-r a |in-ctx (λ w → transport Codes (! (merid e)) w) ⟩ transport Codes (! (merid e)) a =⟨ transport-Codes-mer-e-! a ⟩ a ∎ abstract homomorphism : (a a' : A) → Path {A = Trunc 1 (north == south)} [ merid (μ a a' ) ] [ merid a' ∙ ! (merid e) ∙ merid a ] homomorphism = WedgeExt.ext args where args : WedgeExt.args {a₀ = e} {b₀ = e} args = record {m = -2; n = -2; cA = cA; cB = cA; P = λ a a' → (_ , Trunc-level {n = 1} _ _); f = λ a → ap [_] $ merid (μ a e) =⟨ ap merid (μ-e-r a) ⟩ merid a =⟨ ap (λ w → w ∙ merid a) (! (!-inv-r (merid e))) ∙ ∙-assoc (merid e) (! (merid e)) (merid a) ⟩ merid e ∙ ! (merid e) ∙ merid a ∎; g = λ a' → ap [_] $ merid (μ e a') =⟨ ap merid (μ-e-l a') ⟩ merid a' =⟨ ! (∙-unit-r (merid a')) ∙ ap (λ w → merid a' ∙ w) (! (!-inv-l (merid e))) ⟩ merid a' ∙ ! (merid e) ∙ merid e ∎ ; p = ap (λ {(p₁ , p₂) → ap [_] $ merid (μ e e) =⟨ p₁ ⟩ merid e =⟨ p₂ ⟩ merid e ∙ ! (merid e) ∙ merid e ∎}) (pair×= (ap (λ x → ap merid x) (! μ-coh)) (coh (merid e)))} where coh : {B : Type i} {b b' : B} (p : b == b') → ap (λ w → w ∙ p) (! (!-inv-r p)) ∙ ∙-assoc p (! p) p == ! (∙-unit-r p) ∙ ap (λ w → p ∙ w) (! (!-inv-l p)) coh idp = idp decode : {x : Suspension A} → Codes x → P x decode {x} = Suspension-elim {P = λ x → Codes x → P x} decode' (λ a → [ merid a ]) (λ a → ↓-→-from-transp (λ= $ STS a)) x where abstract STS : (a a' : A) → transport P (merid a) (decode' a') == [ merid (transport Codes (merid a) a') ] STS a a' = transport P (merid a) [ merid a' ∙ ! (merid e) ] =⟨ transport-Trunc (north ==_) (merid a) _ ⟩ [ transport (north ==_) (merid a) (merid a' ∙ ! (merid e)) ] =⟨ ap [_] (trans-pathfrom {A = Suspension A} (merid a) _) ⟩ [ (merid a' ∙ ! (merid e)) ∙ merid a ] =⟨ ap [_] (∙-assoc (merid a') (! (merid e)) (merid a)) ⟩ [ merid a' ∙ ! (merid e) ∙ merid a ] =⟨ ! (homomorphism a a') ⟩ [ merid (μ a a') ] =⟨ ap ([_] ∘ merid) (! (transport-Codes-mer a a')) ⟩ [ merid (transport Codes (merid a) a') ] ∎ abstract decode-encode : {x : Suspension A} (tα : P x) → decode {x} (encode {x} tα) == tα decode-encode {x} = Trunc-elim {P = λ tα → decode {x} (encode {x} tα) == tα} (λ _ → =-preserves-level 1 Trunc-level) (J (λ y p → decode {y} (encode {y} [ p ]) == [ p ]) (ap [_] (!-inv-r (merid e)))) main-lemma-eq : Trunc 1 (north' A == north) ≃ A main-lemma-eq = equiv encode decode' encode-decode' decode-encode ⊙main-lemma : ⊙Trunc 1 (⊙Ω (⊙Susp (A , e))) == (A , e) ⊙main-lemma = ⊙ua (⊙≃-in main-lemma-eq idp) abstract main-lemma-iso : Ω^S-group 0 (⊙Trunc 1 (⊙Ω (⊙Susp (A , e)))) Trunc-level ≃ᴳ Ω^S-group 0 (⊙Trunc 1 (A , e)) Trunc-level main-lemma-iso = (record {f = f; pres-comp = pres-comp} , ie) where h : fst (⊙Trunc 1 (⊙Ω (⊙Susp (A , e))) ⊙→ ⊙Trunc 1 (A , e)) h = (λ x → [ encode x ]) , idp f : Ω (⊙Trunc 1 (⊙Ω (⊙Susp (A , e)))) → Ω (⊙Trunc 1 (A , e)) f = fst (ap^ 1 h) pres-comp : (p q : Ω^ 1 (⊙Trunc 1 (⊙Ω (⊙Susp (A , e))))) → f (conc^S 0 p q) == conc^S 0 (f p) (f q) pres-comp = ap^S-conc^S 0 h ie : is-equiv f ie = is-equiv-ap^ 1 h (snd $ ((unTrunc-equiv A gA)⁻¹ ∘e main-lemma-eq)) abstract π₂-Suspension : πS 1 (⊙Susp (A , e)) == πS 0 (A , e) π₂-Suspension = πS 1 (⊙Susp (A , e)) =⟨ πS-inner-iso 0 (⊙Susp (A , e)) ⟩ πS 0 (⊙Ω (⊙Susp (A , e))) =⟨ ! (πS-Trunc-shift-iso 0 (⊙Ω (⊙Susp (A , e)))) ⟩ Ω^S-group 0 (⊙Trunc 1 (⊙Ω (⊙Susp (A , e)))) Trunc-level =⟨ group-ua main-lemma-iso ⟩ Ω^S-group 0 (⊙Trunc 1 (A , e)) Trunc-level =⟨ πS-Trunc-shift-iso 0 (A , e) ⟩ πS 0 (A , e) ∎
{ "alphanum_fraction": 0.4596083231, "avg_line_length": 35.9120879121, "ext": "agda", "hexsha": "8231c90cdf4c5aa3abf650e8a9e9e088f026a538", "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/Pi2HSusp.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/Pi2HSusp.agda", "max_line_length": 78, "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/Pi2HSusp.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2640, "size": 6536 }
open import Prelude open import RW.Language.RTerm open import RW.Language.FinTerm module RW.Language.RTermIdx where open Eq {{...}} data RTermᵢ {a}(A : Set a) : Set a where ovarᵢ : (x : A) → RTermᵢ A ivarᵢ : (n : ℕ) → RTermᵢ A rlitᵢ : (l : Literal) → RTermᵢ A rlamᵢ : RTermᵢ A rappᵢ : (n : RTermName) → RTermᵢ A ovarᵢ-inj : ∀{a}{A : Set a}{x y : A} → ovarᵢ x ≡ ovarᵢ y → x ≡ y ovarᵢ-inj refl = refl ivarᵢ-inj : ∀{a}{A : Set a}{x y : ℕ} → ivarᵢ {a} {A} x ≡ ivarᵢ {a} y → x ≡ y ivarᵢ-inj refl = refl rlitᵢ-inj : ∀{a}{A : Set a}{x y : Literal} → rlitᵢ {a} {A} x ≡ rlitᵢ {a} y → x ≡ y rlitᵢ-inj refl = refl rappᵢ-inj : ∀{a}{A : Set a}{x y : RTermName} → rappᵢ {a} {A} x ≡ rappᵢ {a} y → x ≡ y rappᵢ-inj refl = refl _≟-RTermᵢ_ : {A : Set}{{eqA : Eq A}} → (t₁ t₂ : RTermᵢ A) → Dec (t₁ ≡ t₂) _≟-RTermᵢ_ {{eq _≟_}} (ovarᵢ x) (ovarᵢ y) with x ≟ y ...| yes x≡y = yes (cong ovarᵢ x≡y) ...| no x≢y = no (x≢y ∘ ovarᵢ-inj) _≟-RTermᵢ_ (ovarᵢ _) (ivarᵢ _) = no (λ ()) _≟-RTermᵢ_ (ovarᵢ _) (rlitᵢ _) = no (λ ()) _≟-RTermᵢ_ (ovarᵢ _) (rlamᵢ ) = no (λ ()) _≟-RTermᵢ_ (ovarᵢ _) (rappᵢ _) = no (λ ()) _≟-RTermᵢ_ (ivarᵢ _) (ovarᵢ _) = no (λ ()) _≟-RTermᵢ_ (ivarᵢ x) (ivarᵢ y) with x ≟-ℕ y ...| yes x≡y = yes (cong ivarᵢ x≡y) ...| no x≢y = no (x≢y ∘ ivarᵢ-inj) _≟-RTermᵢ_ (ivarᵢ _) (rlitᵢ _) = no (λ ()) _≟-RTermᵢ_ (ivarᵢ _) (rlamᵢ ) = no (λ ()) _≟-RTermᵢ_ (ivarᵢ _) (rappᵢ _) = no (λ ()) _≟-RTermᵢ_ (rlitᵢ _) (ivarᵢ _) = no (λ ()) _≟-RTermᵢ_ (rlitᵢ _) (ovarᵢ _) = no (λ ()) _≟-RTermᵢ_ (rlitᵢ x) (rlitᵢ y) with x ≟-Lit y ...| yes x≡y = yes (cong rlitᵢ x≡y) ...| no x≢y = no (x≢y ∘ rlitᵢ-inj) _≟-RTermᵢ_ (rlitᵢ _) (rlamᵢ ) = no (λ ()) _≟-RTermᵢ_ (rlitᵢ _) (rappᵢ _) = no (λ ()) _≟-RTermᵢ_ (rlamᵢ ) (ovarᵢ _) = no (λ ()) _≟-RTermᵢ_ (rlamᵢ ) (ivarᵢ _) = no (λ ()) _≟-RTermᵢ_ (rlamᵢ ) (rlitᵢ _) = no (λ ()) _≟-RTermᵢ_ (rlamᵢ ) (rlamᵢ ) = yes refl _≟-RTermᵢ_ (rlamᵢ ) (rappᵢ _) = no (λ ()) _≟-RTermᵢ_ (rappᵢ _) (ovarᵢ _) = no (λ ()) _≟-RTermᵢ_ (rappᵢ _) (ivarᵢ _) = no (λ ()) _≟-RTermᵢ_ (rappᵢ _) (rlitᵢ _) = no (λ ()) _≟-RTermᵢ_ (rappᵢ _) (rlamᵢ ) = no (λ ()) _≟-RTermᵢ_ (rappᵢ x) (rappᵢ y) with x ≟-RTermName y ...| yes x≡y = yes (cong rappᵢ x≡y) ...| no x≢y = no (x≢y ∘ rappᵢ-inj) ----------------------------------- -- Utilities out : ∀{a}{A : Set a} → RTerm A → RTermᵢ A × List (RTerm A) out (ovar x) = ovarᵢ x , [] out (ivar n) = ivarᵢ n , [] out (rlit l) = rlitᵢ l , [] out (rlam t) = rlamᵢ , t ∷ [] out (rapp n ts) = rappᵢ n , ts toSymbol : ∀{a}{A : Set a} → RTermᵢ A → Maybe A toSymbol (ovarᵢ a) = just a toSymbol _ = nothing idx-cast : ∀{a b}{A : Set a}{B : Set b} → (i : RTermᵢ A) → (toSymbol i ≡ nothing) → RTermᵢ B idx-cast (ovarᵢ x) () idx-cast (ivarᵢ n) _ = ivarᵢ n idx-cast (rlitᵢ l) _ = rlitᵢ l idx-cast (rlamᵢ ) _ = rlamᵢ idx-cast (rappᵢ n) _ = rappᵢ n instance eq-RTermᵢ : {A : Set}{{eqA : Eq A}} → Eq (RTermᵢ A) eq-RTermᵢ = eq _≟-RTermᵢ_ {- instance RTerm-isTrie : {A : Set}{{eqA : Eq A}}{{enA : Enum A}} → IsTrie (RTerm A) RTerm-isTrie {A} {{enA = enum aℕ ℕa}} = record { Idx = RTermᵢ A ; idx≡ = eq _≟-RTermᵢ_ ; toSym = toSymAux ; fromSym = fromSymAux ; inₜ = inAux ; outₜ = outAux } where postulate fixme : ∀{a}{A : Set a} → A toSymAux : RTermᵢ A → Maybe ℕ toSymAux (ovarᵢ n) = aℕ n toSymAux _ = nothing fromSymAux : ℕ → Maybe (RTermᵢ A) fromSymAux n = maybe (λ x → just (ovarᵢ x)) nothing (ℕa n) inAux : RTermᵢ A × List (RTerm A) → RTerm A inAux (ovarᵢ x , []) = ovar x inAux (ivarᵢ x , []) = ivar x inAux (rlitᵢ l , []) = rlit l inAux (rlamᵢ , t ∷ []) = rlam t inAux (rappᵢ n , ts) = rapp n ts inAux _ = fixme -- maybe using vectors of the correct arity... outAux : RTerm A → RTermᵢ A × List (RTerm A) outAux (ovar x) = ovarᵢ x , [] outAux (ivar n) = ivarᵢ n , [] outAux (rlit l) = rlitᵢ l , [] outAux (rlam t) = rlamᵢ , t ∷ [] outAux (rapp n ts) = rappᵢ n , ts {- RTerm-isTrie : IsTrie (RTerm ⊥) RTerm-isTrie = record { Idx = RTermᵢ ⊥ ; idx≡ = eq _≟-RTermᵢ_ ; toSym = toSymAux ; fromSym = fromSymAux ; inₜ = inAux ; outₜ = outAux } where postulate fixme : ∀{a}{A : Set a} → A toSymAux : RTermᵢ ⊥ → Maybe ℕ toSymAux (ovarᵢ ()) toSymAux (ivarᵢ n) = just n toSymAux _ = nothing fromSymAux : ℕ → Maybe (RTermᵢ ⊥) fromSymAux x = just (ivarᵢ x) inAux : RTermᵢ ⊥ × List (RTerm ⊥) → RTerm ⊥ inAux (ovarᵢ () , []) inAux (ivarᵢ x , []) = ivar x inAux (rlitᵢ l , []) = rlit l inAux (rlamᵢ , t ∷ []) = rlam t inAux (rappᵢ n , ts) = rapp n ts inAux _ = fixme -- maybe using vectors of the correct arity... outAux : RTerm ⊥ → RTermᵢ ⊥ × List (RTerm ⊥) outAux (ovar ()) -- = ovarᵢ x , [] outAux (ivar n) = ivarᵢ n , [] outAux (rlit l) = rlitᵢ l , [] outAux (rlam t) = rlamᵢ , t ∷ [] outAux (rapp n ts) = rappᵢ n , ts -} RTermTrie : (A : Set){{eqA : Eq A}}{{enA : Enum A}} → Set RTermTrie A = BTrie (RTerm A) Name insertTerm : {A : Set}{{eqA : Eq A}}{{enA : Enum A}} → Name → RTerm A → ℕ × RTermTrie A → ℕ × RTermTrie A insertTerm {A} = insert where open import RW.Data.BTrie.Insert (RTerm A) Name lookupTerm : {A : Set}{{eqA : Eq A}}{{enA : Enum A}} → RTerm ⊥ → RTermTrie A → List (ℕmap.to (RTerm A) × Name) lookupTerm {A} t = lookup (replace-A ⊥-elim t) where open import RW.Data.BTrie.Lookup (RTerm A) Name -}
{ "alphanum_fraction": 0.497470489, "avg_line_length": 31.8817204301, "ext": "agda", "hexsha": "8042fde841f1438c68d3d62a320e0176c4cf0224", "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": "2856afd12b7dbbcc908482975638d99220f38bf2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "VictorCMiraldo/agda-rw", "max_forks_repo_path": "RW/Language/RTermIdx.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2", "max_issues_repo_issues_event_max_datetime": "2015-05-28T14:48:03.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-06T15:03:33.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "VictorCMiraldo/agda-rw", "max_issues_repo_path": "RW/Language/RTermIdx.agda", "max_line_length": 86, "max_stars_count": 16, "max_stars_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "VictorCMiraldo/agda-rw", "max_stars_repo_path": "RW/Language/RTermIdx.agda", "max_stars_repo_stars_event_max_datetime": "2019-10-24T17:38:20.000Z", "max_stars_repo_stars_event_min_datetime": "2015-02-09T15:43:38.000Z", "num_tokens": 2908, "size": 5930 }
module Syntax2 where import Level open import Data.Empty open import Data.Unit as Unit renaming (tt to ∗) open import Data.Nat open import Data.List as List renaming ([] to Ø) hiding ([_]) open import NonEmptyList as NList open import Data.Vec as Vec hiding ([_]; _++_) open import Data.Product as Prod open import Categories.Category using (Category) open import Function open import Relation.Binary.PropositionalEquality as PE hiding ([_]) open import Relation.Binary using (module IsEquivalence; Setoid; module Setoid) open ≡-Reasoning open import Common.Context as Context Univ = ⊤ length' : {A : Set} → List A → ℕ length' Ø = 0 length' (x ∷ xs) = suc (length' xs) data FP : Set where μ : FP ν : FP RawCtx : Set RawCtx = Ctx ⊤ RawVar : RawCtx → Set RawVar Γ = Var Γ ∗ TyCtx : Set TyCtx = Ctx RawCtx TyVar : TyCtx → RawCtx → Set TyVar = Var CtxMor : (TyCtx → RawCtx → RawCtx → Set) → RawCtx → RawCtx → Set CtxMor R Γ₁ Γ₂ = Vec (R Ø Γ₁ Ø) (length' Γ₂) FpData : (TyCtx → RawCtx → RawCtx → Set) → TyCtx → RawCtx → Set FpData R Θ Γ = NList (Σ RawCtx (λ Γ' → CtxMor R Γ' Γ × R (Γ ∷ Θ) Γ' Ø)) FpMapData : (TyCtx → RawCtx → RawCtx → Set) → Set FpMapData R = NList (Σ RawCtx λ Γ' → R Ø (∗ ∷ Γ') Ø) -- | Types and objects with their corresponding (untyped) type, object -- variable contexts and parameter contexts. data Raw : TyCtx → RawCtx → RawCtx → Set where ----- Common constructors instRaw : {Θ : TyCtx} {Γ₁ Γ₂ : RawCtx} → Raw Θ Γ₁ (∗ ∷ Γ₂) → Raw Ø Γ₁ Ø → Raw Θ Γ₁ Γ₂ ----- Object constructors unitRaw : (Γ : RawCtx) → Raw Ø Γ Ø objVarRaw : (Γ : RawCtx) → RawVar Γ → Raw Ø Γ Ø dialgRaw : {Γ Γ' : RawCtx} (Δ : RawCtx) → CtxMor Raw Γ' Γ → Raw (Γ ∷ Ø) Γ' Ø → FP → Raw Ø Δ (∗ ∷ Γ') mappingRaw : (Γ Δ : RawCtx) → FpMapData Raw → FP → Raw Ø Δ Γ ----- Type constructors ⊤-Raw : (Θ : TyCtx) (Γ : RawCtx) → Raw Θ Γ Ø tyVarRaw : {Θ : TyCtx} (Γ₁ : RawCtx) {Γ₂ : RawCtx} → TyVar Θ Γ₂ → Raw Θ Γ₁ Γ₂ paramAbstrRaw : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) → Raw Θ (∗ ∷ Γ₁) Γ₂ → Raw Θ Γ₁ (Γ₂ ++ ∗ ∷ Ø) -- | Constructor for fixed points. The first component is intended to be -- the context morphism, the second is the type. fpRaw : {Θ : TyCtx} {Γ₂ : RawCtx} (Γ₁ : RawCtx) → FP → FpData Raw Θ Γ₂ → Raw Θ Γ₁ Γ₂ weaken : {Θ : TyCtx} {Γ₁ Γ₂ : RawCtx} → Raw Θ Γ₁ Γ₂ → Raw Θ (∗ ∷ Γ₁) Γ₂ weaken (instRaw t s) = instRaw (weaken t) (weaken s) weaken (unitRaw Γ) = unitRaw (∗ ∷ Γ) weaken (objVarRaw Γ x) = objVarRaw (∗ ∷ Γ) (succ ∗ x) weaken (dialgRaw Δ f t ρ) = dialgRaw (∗ ∷ Δ) f t ρ weaken (mappingRaw Γ Δ gs ρ) = mappingRaw Γ (∗ ∷ Δ) gs ρ weaken (⊤-Raw Θ Γ) = ⊤-Raw Θ (∗ ∷ Γ) weaken (tyVarRaw Γ₁ X) = tyVarRaw (∗ ∷ Γ₁) X weaken (paramAbstrRaw Γ₁ A) = paramAbstrRaw (∗ ∷ Γ₁) (weaken A) weaken (fpRaw Γ₁ ρ D) = fpRaw (∗ ∷ Γ₁) ρ D ctxid : (Γ : RawCtx) → CtxMor Raw Γ Γ ctxid Ø = [] ctxid (x ∷ Γ) = (objVarRaw (∗ ∷ Γ) zero) ∷ (Vec.map weaken (ctxid Γ)) -- | Build the instantiation "t f" of a raw term t by a context morphism f instWCtxMor : {Θ : TyCtx} {Γ₁ Γ₂ : RawCtx} → Raw Θ Γ₁ Γ₂ → CtxMor Raw Γ₁ Γ₂ → Raw Θ Γ₁ Ø instWCtxMor {Γ₂ = Ø} t [] = t instWCtxMor {Γ₂ = x ∷ Γ₂} t (s ∷ f) = instWCtxMor (instRaw t s) f -- | Retrieve the term to be substituted for a variable from a context morphism get : {R : TyCtx → RawCtx → RawCtx → Set} {Γ₁ Γ₂ : RawCtx} → CtxMor R Γ₂ Γ₁ → RawVar Γ₁ → R Ø Γ₂ Ø get {R} {Ø} [] () get {R} {_ ∷ Γ₁} (M ∷ f) zero = M get {R} {_ ∷ Γ₁} (M ∷ f) (succ .∗ x) = get {R} f x -- | Extends a context morphism to be the identity on a new variable extend : {Γ₁ Γ₂ : RawCtx} → CtxMor Raw Γ₂ Γ₁ → CtxMor Raw (∗ ∷ Γ₂) (∗ ∷ Γ₁) extend f = (objVarRaw _ zero) ∷ (Vec.map weaken f) -- | Substitution on raw terms substRaw : ∀ {Θ Γ₁ Γ Γ₂} → Raw Θ Γ₁ Γ → CtxMor Raw Γ₂ Γ₁ → Raw Θ Γ₂ Γ substRaw (instRaw M N) f = instRaw (substRaw M f) (substRaw N f) substRaw (unitRaw Γ) f = unitRaw _ substRaw (objVarRaw Γ₁ x) f = get {Raw} f x substRaw (dialgRaw Δ g A ρ) f = dialgRaw _ g A ρ substRaw (mappingRaw Γ Δ gs ρ) f = mappingRaw _ _ gs ρ substRaw (⊤-Raw Θ Γ) f = ⊤-Raw Θ _ substRaw (tyVarRaw Γ₁ X) f = tyVarRaw _ X substRaw (paramAbstrRaw Γ₁ A) f = paramAbstrRaw _ (substRaw A (extend f)) substRaw (fpRaw Γ₁ ρ D) f = fpRaw _ ρ D substTyRaw₀ : ∀ {Θ Γ₁ Γ Γ₂} → Raw (Γ ∷ Θ) Γ₁ Γ₂ → Raw Ø Ø Γ → Raw Θ Γ₁ Γ₂ substTyRaw₀ (instRaw A t) B = instRaw (substTyRaw₀ A B) t substTyRaw₀ (⊤-Raw ._ Γ₁) B = ⊤-Raw _ _ substTyRaw₀ (tyVarRaw Γ₁ zero) B = {!!} substTyRaw₀ (tyVarRaw Γ₁ (succ Γ₂ X)) B = {!!} substTyRaw₀ (paramAbstrRaw Γ₁ A) B = {!!} substTyRaw₀ (fpRaw Γ₁ x x₁) B = {!!} -- | Substitute into for type variables substTyRaw : ∀ {Θ₁ Θ₂ Γ₁ Γ Γ₂} → Raw (Θ₁ ++ (Γ ∷ Θ₂)) Γ₁ Γ₂ → Raw Ø Ø Γ → Raw (Θ₁ ++ Θ₂) Γ₁ Γ₂ substTyRaw {Ø} A B = {!!} substTyRaw {x ∷ Θ₁} A B = {!!} -- | Context morphism that projects on arbitrary prefix of a context ctxProjRaw : (Γ₁ Γ₂ : RawCtx) → CtxMor Raw (Γ₂ ++ Γ₁) Γ₁ ctxProjRaw Γ₁ Ø = ctxid Γ₁ ctxProjRaw Γ₁ (x ∷ Γ₂) = Vec.map weaken (ctxProjRaw Γ₁ Γ₂) -- | Extend one step weakening to weakening by arbitrary contexts weaken' : ∀ {Θ Γ₁ Γ₃} → (Γ₂ : RawCtx) → Raw Θ Γ₁ Γ₃ → Raw Θ (Γ₂ ++ Γ₁) Γ₃ weaken' {Γ₁ = Γ₁} Γ₂ t = substRaw t (ctxProjRaw Γ₁ Γ₂) ----------------------------------------- --- Examples ----------------------------------------- _︵_ : {A : Set} → A → A → List A a ︵ b = a ∷ b ∷ Ø -- | Binary product type Prod : (Γ : RawCtx) → Raw (Γ ︵ Γ) Ø Γ Prod Γ = fpRaw {Δ} {Γ} Ø ν D where Δ = Γ ︵ Γ A : TyVar (Γ ∷ Δ) Γ A = succ Γ zero B : TyVar (Γ ∷ Δ) Γ B = succ Γ (succ Γ zero) D₁ = (Γ , ctxid Γ , instWCtxMor (tyVarRaw Γ A) (ctxid Γ)) D₂ = (Γ , ctxid Γ , instWCtxMor (tyVarRaw Γ B) (ctxid Γ)) D : FpData Raw Δ Γ D = D₁ ∷ [ D₂ ] ----------------------------------------- --- Separate types and terms ----------------------------------------- mutual data DecentType : {Θ : TyCtx} {Γ₁ Γ₂ : RawCtx} → Raw Θ Γ₁ Γ₂ → Set where DT-⊤ : (Θ : TyCtx) (Γ : RawCtx) → DecentType (⊤-Raw Θ Γ) DT-tyVar : {Θ : TyCtx} (Γ₁ : RawCtx) {Γ₂ : RawCtx} → (X : TyVar Θ Γ₂) → DecentType (tyVarRaw Γ₁ X) DT-inst : ∀{Θ Γ₁ Γ₂} → (A : Raw Θ Γ₁ (∗ ∷ Γ₂)) → (t : Raw Ø Γ₁ Ø) → DecentType A → DecentTerm t → DecentType (instRaw A t) DT-paramAbstr : ∀{Θ Γ₂} (Γ₁ : RawCtx) → (A : Raw Θ (∗ ∷ Γ₁) Γ₂) → DecentType A → DecentType (paramAbstrRaw Γ₁ A) DT-fp : ∀{Θ Γ₂} (Γ₁ : RawCtx) → (ρ : FP) → (D : FpData Raw Θ Γ₂) → DecentFpData D → DecentType (fpRaw Γ₁ ρ D) data DecentTerm : {Γ₁ Γ₂ : RawCtx} → Raw Ø Γ₁ Γ₂ → Set where DO-unit : (Γ : RawCtx) → DecentTerm (unitRaw Γ) DO-objVar : (Γ : RawCtx) → (x : RawVar Γ) → DecentTerm (objVarRaw Γ x) DO-inst : {Γ₁ Γ₂ : RawCtx} → (t : Raw Ø Γ₁ (∗ ∷ Γ₂)) → (s : Raw Ø Γ₁ Ø) → DecentTerm t → DecentTerm s → DecentTerm (instRaw t s) DO-dialg : {Γ Γ' : RawCtx} (Δ : RawCtx) → (f : CtxMor Raw Γ' Γ) → (A : Raw (Γ ∷ Ø) Γ' Ø) → (ρ : FP) → DecentCtxMor f → DecentType A → DecentTerm (dialgRaw Δ f A ρ) DO-mapping : {Γ : RawCtx} (Δ : RawCtx) → (gs : FpMapData Raw) → (ρ : FP) → DecentTermList gs → DecentTerm (mappingRaw Γ Δ gs ρ) DecentTermList : FpMapData Raw → Set DecentTermList [ (Γ' , t) ] = DecentTerm t DecentTermList ((Γ' , t) ∷ ts) = DecentTerm t × DecentTermList ts DecentCtxMor : {Γ₁ Γ₂ : RawCtx} → CtxMor Raw Γ₁ Γ₂ → Set DecentCtxMor {Γ₂ = Ø} [] = ⊤ DecentCtxMor {Γ₂ = x ∷ Γ₂} (t ∷ f) = DecentTerm t × DecentCtxMor f DecentFpData : ∀{Θ Γ₂} → FpData Raw Θ Γ₂ → Set DecentFpData [ Γ , f , A ] = DecentCtxMor f × DecentType A DecentFpData ((Γ , f , A) ∷ D) = (DecentCtxMor f × DecentType A) × DecentFpData D weakenDO : {Γ₁ Γ₂ : RawCtx} {t : Raw Ø Γ₁ Γ₂} → DecentTerm t → DecentTerm (weaken t) weakenDT : ∀ {Θ Γ₁ Γ₂} {A : Raw Θ Γ₁ Γ₂} → DecentType A → DecentType (weaken A) weakenDT (DT-⊤ Θ Γ) = DT-⊤ Θ _ weakenDT (DT-tyVar Γ₁ X) = DT-tyVar _ X weakenDT (DT-inst A t p q) = DT-inst _ _ (weakenDT p) (weakenDO q) weakenDT (DT-paramAbstr Γ₁ A p) = DT-paramAbstr _ _ (weakenDT p) weakenDT (DT-fp Γ₁ ρ D p) = DT-fp _ ρ D p weakenDO (DO-unit Γ) = DO-unit _ weakenDO (DO-objVar Γ x) = DO-objVar _ (succ ∗ x) weakenDO (DO-inst t s p q) = DO-inst _ _ (weakenDO p) (weakenDO q) weakenDO (DO-dialg Δ f A ρ p q) = DO-dialg _ f _ ρ p q weakenDO (DO-mapping Δ gs ρ p) = DO-mapping _ gs ρ p weakenDecentCtxMor : {Γ₁ Γ₂ : RawCtx} {f : CtxMor Raw Γ₁ Γ₂} → DecentCtxMor f → DecentCtxMor (Vec.map weaken f) weakenDecentCtxMor {Γ₂ = Ø} {f} p = ∗ weakenDecentCtxMor {Γ₂ = x ∷ Γ₂} {t ∷ f} (p , ps) = (weakenDO p , weakenDecentCtxMor ps) ------------------------------------- ------- Pre-types and terms ------------------------------------- PreType : (Θ : TyCtx) (Γ₁ Γ₂ : RawCtx) → Set PreType Θ Γ₁ Γ₂ = Σ (Raw Θ Γ₁ Γ₂) λ A → DecentType A mkPreType : ∀ {Θ Γ₁ Γ₂} {A : Raw Θ Γ₁ Γ₂} → DecentType A → PreType Θ Γ₁ Γ₂ mkPreType {A = A} p = (A , p) PreTerm : (Γ₁ Γ₂ : RawCtx) → Set PreTerm Γ₁ Γ₂ = Σ (Raw Ø Γ₁ Γ₂) λ t → DecentTerm t mkPreTerm : ∀ {Γ₁ Γ₂} {t : Raw Ø Γ₁ Γ₂} → DecentTerm t → PreTerm Γ₁ Γ₂ mkPreTerm {t = t} p = (t , p) CtxMorP = CtxMor (λ _ → PreTerm) FpMapDataP = FpMapData (λ _ → PreTerm) mkCtxMorP : {Γ₁ Γ₂ : RawCtx} {f : CtxMor Raw Γ₁ Γ₂} → DecentCtxMor f → CtxMorP Γ₁ Γ₂ mkCtxMorP {Γ₂ = Ø} p = [] mkCtxMorP {Γ₂ = x ∷ Γ₂} {t ∷ f} (p , ps) = (t , p) ∷ (mkCtxMorP ps) projCtxMor₁ : {Γ₁ Γ₂ : RawCtx} → CtxMorP Γ₂ Γ₁ → CtxMor Raw Γ₂ Γ₁ projCtxMor₁ = Vec.map proj₁ projCtxMor₂ : {Γ₁ Γ₂ : RawCtx} → (f : CtxMorP Γ₂ Γ₁) → DecentCtxMor (projCtxMor₁ f) projCtxMor₂ {Ø} [] = ∗ projCtxMor₂ {x ∷ Γ₁} ((t , p) ∷ f) = (p , projCtxMor₂ f) projPTList₁ : FpMapDataP → FpMapData Raw projPTList₁ = NList.map (Prod.map id proj₁) projPTList₂ : (gs : FpMapDataP) → DecentTermList (projPTList₁ gs) projPTList₂ [ (Γ' , t , p) ] = p projPTList₂ ((Γ' , t , p) ∷ gs) = (p , projPTList₂ gs) ----------------------------------------- ----- Constructors for pre terms ----------------------------------------- unitPT : (Γ : RawCtx) → PreTerm Γ Ø unitPT Γ = mkPreTerm (DO-unit _) varPT : (Γ : RawCtx) → RawVar Γ → PreTerm Γ Ø varPT Γ x = mkPreTerm (DO-objVar _ x) instPT : {Γ₁ : RawCtx} {Γ₂ : RawCtx} → PreTerm Γ₁ (∗ ∷ Γ₂) → PreTerm Γ₁ Ø → PreTerm Γ₁ Γ₂ instPT (t , p) (s , q) = mkPreTerm (DO-inst _ _ p q) dialgPT : {Γ Γ' : RawCtx} (Δ : RawCtx) → CtxMorP Γ' Γ → PreType (Γ ∷ Ø) Γ' Ø → FP → PreTerm Δ (∗ ∷ Γ') dialgPT Δ f (A , p) ρ = mkPreTerm (DO-dialg _ _ _ ρ (projCtxMor₂ f) p) mappingPT : {Γ : RawCtx} (Δ : RawCtx) → FpMapDataP → FP → PreTerm Δ Γ mappingPT Δ gs ρ = mkPreTerm (DO-mapping _ _ ρ (projPTList₂ gs)) instWCtxMorP : {Γ₁ Γ₂ : RawCtx} → PreTerm Γ₁ Γ₂ → CtxMorP Γ₁ Γ₂ → PreTerm Γ₁ Ø instWCtxMorP {Γ₂ = Ø} M [] = M instWCtxMorP {Γ₂ = x ∷ Γ₂} M (N ∷ f) = instWCtxMorP (instPT M N) f ----------------------------------------------------- ------ Meta operations on pre-terms and pre-types ----------------------------------------------------- weakenPT : ∀ {Θ Γ₁ Γ₂} → PreType Θ Γ₁ Γ₂ → PreType Θ (∗ ∷ Γ₁) Γ₂ weakenPT (A , p) = (weaken A , weakenDT p) weakenPO : {Γ₁ Γ₂ : RawCtx} → PreTerm Γ₁ Γ₂ → PreTerm (∗ ∷ Γ₁) Γ₂ weakenPO (t , p) = (weaken t , weakenDO p) get' : {Γ₁ Γ₂ : RawCtx} → (f : CtxMor (λ _ → PreTerm) Γ₂ Γ₁) → (x : RawVar Γ₁) → DecentTerm (get {Raw} (projCtxMor₁ f) x) get' (t ∷ f) zero = proj₂ t get' (t ∷ f) (succ {b = ∗} .∗ x) = get' f x -- | Lift substitutions to DecentTerm predicate substDO : {Γ₁ Γ Γ₂ : RawCtx} {t : Raw Ø Γ₁ Γ} → (f : CtxMorP Γ₂ Γ₁) → DecentTerm t → DecentTerm (substRaw t (projCtxMor₁ f)) substDO f (DO-unit Γ₁) = DO-unit _ substDO f (DO-objVar Γ₁ x) = get' f x substDO f (DO-inst t s p q) = DO-inst _ _ (substDO f p) (substDO f q) substDO f (DO-dialg Γ₁ g A ρ p q) = DO-dialg _ _ _ _ p q substDO f (DO-mapping Γ₁ gs ρ p) = DO-mapping _ _ _ p -- | Lift substRaw to pre terms substP : {Γ₁ Γ Γ₂ : RawCtx} → PreTerm Γ₁ Γ → CtxMorP Γ₂ Γ₁ → PreTerm Γ₂ Γ substP (t , p) f = (substRaw t (projCtxMor₁ f) , substDO f p) -- | Context identity is a decent context morphism ctxidDO : (Γ : RawCtx) → DecentCtxMor (ctxid Γ) ctxidDO Ø = ∗ ctxidDO (x ∷ Γ) = (DO-objVar _ zero , weakenDecentCtxMor (ctxidDO Γ)) mkCtxMorP₁ : {Γ₁ Γ₂ : RawCtx} {f : CtxMor Raw Γ₁ Γ₂} → (p : DecentCtxMor f) → projCtxMor₁ (mkCtxMorP p) ≡ f mkCtxMorP₁ {Γ₂ = Ø} {[]} p = refl mkCtxMorP₁ {Γ₂ = x ∷ Γ₂} {t ∷ f} (p , ps) = begin projCtxMor₁ ((t , p) ∷ mkCtxMorP ps) ≡⟨ refl ⟩ t ∷ projCtxMor₁ (mkCtxMorP ps) ≡⟨ cong (λ u → t ∷ u) (mkCtxMorP₁ ps) ⟩ t ∷ f ∎ ctxidP : (Γ : RawCtx) → CtxMorP Γ Γ ctxidP Γ = mkCtxMorP (ctxidDO Γ) -- | Context projection is a decent context morphism ctxProjDO : (Γ₁ Γ₂ : RawCtx) → DecentCtxMor (ctxProjRaw Γ₁ Γ₂) ctxProjDO Γ₁ Ø = ctxidDO Γ₁ ctxProjDO Γ₁ (x ∷ Γ₂) = weakenDecentCtxMor (ctxProjDO Γ₁ Γ₂) ctxProjP : (Γ₁ Γ₂ : RawCtx) → CtxMorP (Γ₂ ++ Γ₁) Γ₁ ctxProjP Γ₁ Γ₂ = mkCtxMorP (ctxProjDO Γ₁ Γ₂) weakenDO' : {Γ₁ Γ₃ : RawCtx} {t : Raw Ø Γ₁ Γ₃} → (Γ₂ : RawCtx) → DecentTerm t → DecentTerm (weaken' Γ₂ t) weakenDO' {Γ₁} {t = t} Γ₂ p = subst DecentTerm (cong (substRaw t) (mkCtxMorP₁ (ctxProjDO Γ₁ Γ₂))) (substDO (ctxProjP Γ₁ Γ₂) p) weakenPO' : {Γ₁ Γ₃ : RawCtx} → (Γ₂ : RawCtx) → PreTerm Γ₁ Γ₃ → PreTerm (Γ₂ ++ Γ₁) Γ₃ weakenPO' Γ₂ (t , p) = (weaken' Γ₂ t , weakenDO' Γ₂ p) weakenPO'' : {Γ₁ Γ₃ : RawCtx} → (Γ₂ Γ₂' : RawCtx) → PreTerm Γ₁ Γ₃ → PreTerm (Γ₂' ++ Γ₁ ++ Γ₂) Γ₃ weakenPO'' = {!!} -- | Project a specific variable out projVar : (Γ₁ Γ₂ : RawCtx) → PreTerm (Γ₂ ++ ∗ ∷ Γ₁) Ø projVar Γ₁ Ø = varPT _ zero projVar Γ₁ (∗ ∷ Γ₂) = weakenPO (projVar Γ₁ Γ₂) ----------------------------------------------------- ---- Action of types on terms ----------------------------------------------------- shift-lemma : {A : Set} → (x y : List A) → (a : A) → x ++ (a ∷ y) ≡ (x ++ a ∷ Ø) ++ y shift-lemma Ø y a = refl shift-lemma (b ∷ x) y a = cong (_∷_ b) (shift-lemma x y a) Args : TyCtx → Set Args Ø = ⊥ Args (Γ ∷ Θ) = (PreTerm (∗ ∷ Γ) Ø) × (Args Θ) getArg : ∀ {Θ Γ₁} → TyVar Θ Γ₁ → Args Θ → PreTerm (∗ ∷ Γ₁) Ø getArg zero (t , ts) = t getArg (succ Γ₁ X) (t , ts) = getArg X ts substArgCodomTypes : ∀ {Θ Γ Γ₁} → Args Θ → PreType (Γ ∷ Θ) Γ₁ Ø → PreType (Γ ∷ Ø) Γ₁ Ø substArgCodomTypes {Ø} () A substArgCodomTypes {Γ ∷ Θ} (M , a) A = {!!} {-# NON_TERMINATING #-} ⟪_⟫ : ∀ {Θ Γ₁ Γ₂} → PreType Θ Γ₁ Γ₂ → Args Θ → PreTerm (∗ ∷ Γ₂ ++ Γ₁) Ø ⟪_⟫ {Θ} {Γ₁} (instRaw {Γ₂ = Γ₂} A t , DT-inst .A .t dt-A do-t) ts = substP (⟪ A , dt-A ⟫ ts) f where -- | Substitute t for the second variable, i.e., f = (id, t, x). f : CtxMorP (∗ ∷ Γ₂ ++ Γ₁) (∗ ∷ ∗ ∷ Γ₂ ++ Γ₁) f = (varPT (∗ ∷ Γ₂ ++ Γ₁) zero) ∷ weakenPO' (∗ ∷ Γ₂) (t , do-t) ∷ ctxProjP (Γ₂ ++ Γ₁) (∗ ∷ Ø) ⟪ unitRaw Γ , () ⟫ ts ⟪ objVarRaw Γ x , () ⟫ ts ⟪ dialgRaw Δ x A x₁ , () ⟫ ts ⟪ mappingRaw Γ Δ x x₁ , () ⟫ ts ⟪ ⊤-Raw Θ Γ , DT-⊤ .Θ .Γ ⟫ ts = ((objVarRaw (∗ ∷ Γ) zero) , (DO-objVar _ _)) ⟪ tyVarRaw Γ₁ X , DT-tyVar .Γ₁ .X ⟫ ts = weakenPO'' Γ₁ Ø (getArg X ts) ⟪ paramAbstrRaw {Γ₂ = Γ₂} Γ₁ A , DT-paramAbstr .Γ₁ .A p ⟫ ts = subst (λ u → PreTerm u Ø) (cong (_∷_ ∗) (shift-lemma Γ₂ Γ₁ ∗)) (⟪ A , p ⟫ ts) ⟪ fpRaw {Θ} {Γ₂} Γ₁ μ D , DT-fp .Γ₁ .μ .D p ⟫ ts = instWCtxMorP (mappingPT _ (gs D p) μ) (ctxidP _) where -- Construction of gₖ = αₖ id (⟪ Bₖ ⟫ (ts, id)) mkBase : ∀{Γ'} (x : CtxMor Raw Γ' Γ₂ × Raw (Γ₂ ∷ Θ) Γ' Ø) → (f : DecentCtxMor (proj₁ x)) → (A : DecentType (proj₂ x)) → Σ RawCtx (λ Γ' → PreTerm (∗ ∷ Γ') Ø) mkBase {Γ'} x f A = (Γ' , instWCtxMorP α r) where B : PreType (Γ₂ ∷ Θ) Γ' Ø B = mkPreType A A₂ : PreType (Γ₂ ∷ Ø) Γ' Ø A₂ = substArgCodomTypes ts B α : PreTerm (∗ ∷ Γ') (∗ ∷ Γ') α = dialgPT _ (mkCtxMorP f) A₂ μ r : CtxMorP (∗ ∷ Γ') (∗ ∷ Γ') r = (⟪ B ⟫ ((varPT _ zero) , ts)) ∷ ctxProjP Γ' (∗ ∷ Ø) -- Construct the g₁, ..., gₙ used in the recursion gs : (D : FpData Raw Θ Γ₂) → DecentFpData D → FpMapDataP gs [ Γ' , x ] (f , A) = [ mkBase x f A ] gs ((Γ' , x) ∷ D₁) ((f , A) , p₁) = mkBase x f A ∷ gs D₁ p₁ ⟪_⟫ (fpRaw Γ₁ ν x₁ , DT-fp .Γ₁ .ν .x₁ x) ts = {!!} ----------------------------------------------------- ---- Reduction relation on pre-types and pre-terms ----------------------------------------------------- data _≻_ : {Γ₁ Γ₂ : RawCtx} → (t s : PreTerm Γ₁ Γ₂) → Set where contract-rec : {Γ : RawCtx} → (gs : NList (PreTerm (∗ ∷ Γ) Ø)) → instPT (mappingPT {!!} {!!} μ) (instPT (dialgPT {!!} {!!} {!!} μ) {!!}) ≻ {!!}
{ "alphanum_fraction": 0.5366887263, "avg_line_length": 36.2652631579, "ext": "agda", "hexsha": "f65b72521dee2ca5354015a84fc39d6c7974ec9d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hbasold/Sandbox", "max_forks_repo_path": "TypeTheory/FibDataTypes/Syntax2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hbasold/Sandbox", "max_issues_repo_path": "TypeTheory/FibDataTypes/Syntax2.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hbasold/Sandbox", "max_stars_repo_path": "TypeTheory/FibDataTypes/Syntax2.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 7166, "size": 17226 }
open import Nat open import Prelude open import contexts open import core module dynamics-core where open core public mutual -- identity substitution, substitition environments data env : Set where Id : (Γ : tctx) → env Subst : (d : ihexp) → (y : Nat) → env → env -- internal expressions data ihexp : Set where N : Nat → ihexp _·+_ : ihexp → ihexp → ihexp X : Nat → ihexp ·λ_·[_]_ : Nat → htyp → ihexp → ihexp _∘_ : ihexp → ihexp → ihexp inl : htyp → ihexp → ihexp inr : htyp → ihexp → ihexp case : ihexp → Nat → ihexp → Nat → ihexp → ihexp ⟨_,_⟩ : ihexp → ihexp → ihexp fst : ihexp → ihexp snd : ihexp → ihexp ⦇-⦈⟨_⟩ : (Nat × env) → ihexp ⦇⌜_⌟⦈⟨_⟩ : ihexp → (Nat × env) → ihexp _⟨_⇒_⟩ : ihexp → htyp → htyp → ihexp _⟨_⇒⦇-⦈⇏_⟩ : ihexp → htyp → htyp → ihexp -- convenient notation for chaining together two agreeable casts _⟨_⇒_⇒_⟩ : ihexp → htyp → htyp → htyp → ihexp d ⟨ t1 ⇒ t2 ⇒ t3 ⟩ = d ⟨ t1 ⇒ t2 ⟩ ⟨ t2 ⇒ t3 ⟩ -- notation for a triple to match the CMTT syntax _::_[_] : Nat → htyp → tctx → (Nat × (tctx × htyp)) u :: τ [ Γ ] = u , (Γ , τ) -- the hole name u does not appear in the term e data hole-name-new : hexp → Nat → Set where HNNum : ∀{n u} → hole-name-new (N n) u HNPlus : ∀{e1 e2 u} → hole-name-new e1 u → hole-name-new e2 u → hole-name-new (e1 ·+ e2) u HNAsc : ∀{e τ u} → hole-name-new e u → hole-name-new (e ·: τ) u HNVar : ∀{x u} → hole-name-new (X x) u HNLam1 : ∀{x e u} → hole-name-new e u → hole-name-new (·λ x e) u HNLam2 : ∀{x e u τ} → hole-name-new e u → hole-name-new (·λ x ·[ τ ] e) u HNAp : ∀{e1 e2 u} → hole-name-new e1 u → hole-name-new e2 u → hole-name-new (e1 ∘ e2) u HNInl : ∀{e u} → hole-name-new e u → hole-name-new (inl e) u HNInr : ∀{e u} → hole-name-new e u → hole-name-new (inr e) u HNCase : ∀{e x e1 y e2 u} → hole-name-new e u → hole-name-new e1 u → hole-name-new e2 u → hole-name-new (case e x e1 y e2) u HNPair : ∀{e1 e2 u} → hole-name-new e1 u → hole-name-new e2 u → hole-name-new ⟨ e1 , e2 ⟩ u HNFst : ∀{e u} → hole-name-new e u → hole-name-new (fst e) u HNSnd : ∀{e u} → hole-name-new e u → hole-name-new (snd e) u HNHole : ∀{u u'} → u' ≠ u → hole-name-new (⦇-⦈[ u' ]) u HNNEHole : ∀{u u' e} → u' ≠ u → hole-name-new e u → hole-name-new (⦇⌜ e ⌟⦈[ u' ]) u -- two terms that do not share any hole names data holes-disjoint : hexp → hexp → Set where HDNum : ∀{n e} → holes-disjoint (N n) e HDPlus : ∀{e1 e2 e3} → holes-disjoint e1 e3 → holes-disjoint e2 e3 → holes-disjoint (e1 ·+ e2) e3 HDAsc : ∀{e1 e2 τ} → holes-disjoint e1 e2 → holes-disjoint (e1 ·: τ) e2 HDVar : ∀{x e} → holes-disjoint (X x) e HDLam1 : ∀{x e1 e2} → holes-disjoint e1 e2 → holes-disjoint (·λ x e1) e2 HDLam2 : ∀{x e1 e2 τ} → holes-disjoint e1 e2 → holes-disjoint (·λ x ·[ τ ] e1) e2 HDAp : ∀{e1 e2 e3} → holes-disjoint e1 e3 → holes-disjoint e2 e3 → holes-disjoint (e1 ∘ e2) e3 HDInl : ∀{e1 e2} → holes-disjoint e1 e2 → holes-disjoint (inl e1) e2 HDInr : ∀{e1 e2} → holes-disjoint e1 e2 → holes-disjoint (inr e1) e2 HDCase : ∀{e x e1 y e2 e3} → holes-disjoint e e3 → holes-disjoint e1 e3 → holes-disjoint e2 e3 → holes-disjoint (case e x e1 y e2) e3 HDPair : ∀{e1 e2 e3} → holes-disjoint e1 e3 → holes-disjoint e2 e3 → holes-disjoint ⟨ e1 , e2 ⟩ e3 HDFst : ∀{e1 e2} → holes-disjoint e1 e2 → holes-disjoint (fst e1) e2 HDSnd : ∀{e1 e2} → holes-disjoint e1 e2 → holes-disjoint (snd e1) e2 HDHole : ∀{u e2} → hole-name-new e2 u → holes-disjoint (⦇-⦈[ u ]) e2 HDNEHole : ∀{u e1 e2} → hole-name-new e2 u → holes-disjoint e1 e2 → holes-disjoint (⦇⌜ e1 ⌟⦈[ u ]) e2 -- all hole names in the term are unique data holes-unique : hexp → Set where HUNum : ∀{n} → holes-unique (N n) HUPlus : ∀{e1 e2} → holes-unique e1 → holes-unique e2 → holes-disjoint e1 e2 → holes-unique (e1 ·+ e2) HUAsc : ∀{e τ} → holes-unique e → holes-unique (e ·: τ) HUVar : ∀{x} → holes-unique (X x) HULam1 : ∀{x e} → holes-unique e → holes-unique (·λ x e) HULam2 : ∀{x e τ} → holes-unique e → holes-unique (·λ x ·[ τ ] e) HUAp : ∀{e1 e2} → holes-unique e1 → holes-unique e2 → holes-disjoint e1 e2 → holes-unique (e1 ∘ e2) HUInl : ∀{e} → holes-unique e → holes-unique (inl e) HUInr : ∀{e} → holes-unique e → holes-unique (inr e) HUCase : ∀{e x e1 y e2} → holes-unique e → holes-unique e1 → holes-unique e2 → holes-disjoint e e1 → holes-disjoint e e2 → holes-disjoint e1 e2 → holes-unique (case e x e1 y e2) HUPair : ∀{e1 e2} → holes-unique e1 → holes-unique e2 → holes-disjoint e1 e2 → holes-unique ⟨ e1 , e2 ⟩ HUFst : ∀{e} → holes-unique e → holes-unique (fst e) HUSnd : ∀{e} → holes-unique e → holes-unique (snd e) HUHole : ∀{u} → holes-unique (⦇-⦈[ u ]) HUNEHole : ∀{u e} → holes-unique e → hole-name-new e u → holes-unique (⦇⌜ e ⌟⦈[ u ]) -- freshness for external expressions data freshh : Nat → hexp → Set where FRHNum : ∀{x n} → freshh x (N n) FRHPlus : ∀{x d1 d2} → freshh x d1 → freshh x d2 → freshh x (d1 ·+ d2) FRHAsc : ∀{x e τ} → freshh x e → freshh x (e ·: τ) FRHVar : ∀{x y} → x ≠ y → freshh x (X y) FRHLam1 : ∀{x y e} → x ≠ y → freshh x e → freshh x (·λ y e) FRHLam2 : ∀{x τ e y} → x ≠ y → freshh x e → freshh x (·λ y ·[ τ ] e) FRHAp : ∀{x e1 e2} → freshh x e1 → freshh x e2 → freshh x (e1 ∘ e2) FRHInl : ∀{x d} → freshh x d → freshh x (inl d) FRHInr : ∀{x d} → freshh x d → freshh x (inr d) FRHCase : ∀{x d y d1 z d2} → freshh x d → x ≠ y → freshh x d1 → x ≠ z → freshh x d2 → freshh x (case d y d1 z d2) FRHPair : ∀{x d1 d2} → freshh x d1 → freshh x d2 → freshh x ⟨ d1 , d2 ⟩ FRHFst : ∀{x d} → freshh x d → freshh x (fst d) FRHSnd : ∀{x d} → freshh x d → freshh x (snd d) FRHEHole : ∀{x u} → freshh x (⦇-⦈[ u ]) FRHNEHole : ∀{x u e} → freshh x e → freshh x (⦇⌜ e ⌟⦈[ u ]) -- those internal expressions without holes data _dcomplete : ihexp → Set where DCNum : ∀{n} → (N n) dcomplete DCPlus : ∀{d1 d2} → d1 dcomplete → d2 dcomplete → (d1 ·+ d2) dcomplete DCVar : ∀{x} → (X x) dcomplete DCLam : ∀{x τ d} → d dcomplete → τ tcomplete → (·λ x ·[ τ ] d) dcomplete DCAp : ∀{d1 d2} → d1 dcomplete → d2 dcomplete → (d1 ∘ d2) dcomplete DCInl : ∀{τ d} → τ tcomplete → d dcomplete → (inl τ d) dcomplete DCInr : ∀{τ d} → τ tcomplete → d dcomplete → (inr τ d) dcomplete DCCase : ∀{d x d1 y d2} → d dcomplete → d1 dcomplete → d2 dcomplete → (case d x d1 y d2) dcomplete DCPair : ∀{d1 d2} → d1 dcomplete → d2 dcomplete → ⟨ d1 , d2 ⟩ dcomplete DCFst : ∀{d} → d dcomplete → (fst d) dcomplete DCSnd : ∀{d} → d dcomplete → (snd d) dcomplete DCCast : ∀{d τ1 τ2} → d dcomplete → τ1 tcomplete → τ2 tcomplete → (d ⟨ τ1 ⇒ τ2 ⟩) dcomplete -- expansion mutual -- synthesis data _⊢_⇒_~>_⊣_ : (Γ : tctx) (e : hexp) (τ : htyp) (d : ihexp) (Δ : hctx) → Set where ESNum : ∀{Γ n} → Γ ⊢ (N n) ⇒ num ~> (N n) ⊣ ∅ ESPlus : ∀{Γ e1 e2 d1 d2 Δ1 Δ2 τ1 τ2} → holes-disjoint e1 e2 → Δ1 ## Δ2 → Γ ⊢ e1 ⇐ num ~> d1 :: τ1 ⊣ Δ1 → Γ ⊢ e2 ⇐ num ~> d2 :: τ2 ⊣ Δ2 → Γ ⊢ e1 ·+ e2 ⇒ num ~> (d1 ⟨ τ1 ⇒ num ⟩) ·+ (d2 ⟨ τ2 ⇒ num ⟩) ⊣ (Δ1 ∪ Δ2) ESAsc : ∀{Γ e τ d τ' Δ} → Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ → Γ ⊢ (e ·: τ) ⇒ τ ~> d ⟨ τ' ⇒ τ ⟩ ⊣ Δ ESVar : ∀{Γ x τ} → (x , τ) ∈ Γ → Γ ⊢ X x ⇒ τ ~> X x ⊣ ∅ ESLam : ∀{Γ x τ1 τ2 e d Δ} → x # Γ → (Γ ,, (x , τ1)) ⊢ e ⇒ τ2 ~> d ⊣ Δ → Γ ⊢ ·λ x ·[ τ1 ] e ⇒ (τ1 ==> τ2) ~> ·λ x ·[ τ1 ] d ⊣ Δ ESAp : ∀{Γ e1 τ τ1 τ1' τ2 τ2' d1 Δ1 e2 d2 Δ2} → holes-disjoint e1 e2 → Δ1 ## Δ2 → Γ ⊢ e1 => τ1 → τ1 ▸arr τ2 ==> τ → Γ ⊢ e1 ⇐ (τ2 ==> τ) ~> d1 :: τ1' ⊣ Δ1 → Γ ⊢ e2 ⇐ τ2 ~> d2 :: τ2' ⊣ Δ2 → Γ ⊢ e1 ∘ e2 ⇒ τ ~> (d1 ⟨ τ1' ⇒ τ2 ==> τ ⟩) ∘ (d2 ⟨ τ2' ⇒ τ2 ⟩) ⊣ (Δ1 ∪ Δ2) ESPair : ∀{Γ e1 τ1 d1 Δ1 e2 τ2 d2 Δ2} → holes-disjoint e1 e2 → Δ1 ## Δ2 → Γ ⊢ e1 ⇒ τ1 ~> d1 ⊣ Δ1 → Γ ⊢ e2 ⇒ τ2 ~> d2 ⊣ Δ2 → Γ ⊢ ⟨ e1 , e2 ⟩ ⇒ τ1 ⊠ τ2 ~> ⟨ d1 , d2 ⟩ ⊣ (Δ1 ∪ Δ2) ESFst : ∀{Γ e τ τ' d τ1 τ2 Δ} → Γ ⊢ e => τ → τ ▸prod τ1 ⊠ τ2 → Γ ⊢ e ⇐ τ1 ⊠ τ2 ~> d :: τ' ⊣ Δ → Γ ⊢ fst e ⇒ τ1 ~> fst (d ⟨ τ' ⇒ τ1 ⊠ τ2 ⟩) ⊣ Δ ESSnd : ∀{Γ e τ τ' d τ1 τ2 Δ} → Γ ⊢ e => τ → τ ▸prod τ1 ⊠ τ2 → Γ ⊢ e ⇐ τ1 ⊠ τ2 ~> d :: τ' ⊣ Δ → Γ ⊢ snd e ⇒ τ2 ~> snd (d ⟨ τ' ⇒ τ1 ⊠ τ2 ⟩) ⊣ Δ ESEHole : ∀{Γ u} → Γ ⊢ ⦇-⦈[ u ] ⇒ ⦇-⦈ ~> ⦇-⦈⟨ u , Id Γ ⟩ ⊣ ■ (u :: ⦇-⦈ [ Γ ]) ESNEHole : ∀{Γ e τ d u Δ} → Δ ## (■ (u , Γ , ⦇-⦈)) → Γ ⊢ e ⇒ τ ~> d ⊣ Δ → Γ ⊢ ⦇⌜ e ⌟⦈[ u ] ⇒ ⦇-⦈ ~> ⦇⌜ d ⌟⦈⟨ u , Id Γ ⟩ ⊣ (Δ ,, u :: ⦇-⦈ [ Γ ]) -- analysis data _⊢_⇐_~>_::_⊣_ : (Γ : tctx) (e : hexp) (τ : htyp) (d : ihexp) (τ' : htyp) (Δ : hctx) → Set where EASubsume : ∀{e Γ τ' d Δ τ} → ((u : Nat) → e ≠ ⦇-⦈[ u ]) → ((e' : hexp) (u : Nat) → e ≠ ⦇⌜ e' ⌟⦈[ u ]) → Γ ⊢ e ⇒ τ' ~> d ⊣ Δ → τ ~ τ' → Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ EALam : ∀{Γ x τ τ1 τ2 e d τ2' Δ} → x # Γ → τ ▸arr τ1 ==> τ2 → (Γ ,, (x , τ1)) ⊢ e ⇐ τ2 ~> d :: τ2' ⊣ Δ → Γ ⊢ ·λ x e ⇐ τ ~> ·λ x ·[ τ1 ] d :: τ1 ==> τ2' ⊣ Δ EAInl : ∀{Γ τ τ1 τ2 e d τ1' Δ} → τ ▸sum τ1 ⊕ τ2 → Γ ⊢ e ⇐ τ1 ~> d :: τ1' ⊣ Δ → Γ ⊢ inl e ⇐ τ ~> inl τ2 d :: τ1' ⊕ τ2 ⊣ Δ EAInr : ∀{Γ τ τ1 τ2 e d τ2' Δ} → τ ▸sum τ1 ⊕ τ2 → Γ ⊢ e ⇐ τ2 ~> d :: τ2' ⊣ Δ → Γ ⊢ inr e ⇐ τ ~> inr τ1 d :: τ1 ⊕ τ2' ⊣ Δ EACase : ∀{Γ e τ+ d Δ τ1 τ2 τ x e1 d1 τr1 Δ1 y e2 d2 τr2 Δ2} → holes-disjoint e e1 → holes-disjoint e e2 → holes-disjoint e1 e2 → Δ ## Δ1 → Δ ## Δ2 → Δ1 ## Δ2 → x # Γ → y # Γ → Γ ⊢ e ⇒ τ+ ~> d ⊣ Δ → τ+ ▸sum τ1 ⊕ τ2 → (Γ ,, (x , τ1)) ⊢ e1 ⇐ τ ~> d1 :: τr1 ⊣ Δ1 → (Γ ,, (y , τ2)) ⊢ e2 ⇐ τ ~> d2 :: τr2 ⊣ Δ2 → Γ ⊢ case e x e1 y e2 ⇐ τ ~> case (d ⟨ τ+ ⇒ τ1 ⊕ τ2 ⟩) x (d1 ⟨ τr1 ⇒ τ ⟩) y (d2 ⟨ τr2 ⇒ τ ⟩) :: τ ⊣ (Δ ∪ (Δ1 ∪ Δ2)) EAEHole : ∀{Γ u τ} → Γ ⊢ ⦇-⦈[ u ] ⇐ τ ~> ⦇-⦈⟨ u , Id Γ ⟩ :: τ ⊣ ■ (u :: τ [ Γ ]) EANEHole : ∀{Γ e u τ d τ' Δ} → Δ ## (■ (u , Γ , τ)) → Γ ⊢ e ⇒ τ' ~> d ⊣ Δ → Γ ⊢ ⦇⌜ e ⌟⦈[ u ] ⇐ τ ~> ⦇⌜ d ⌟⦈⟨ u , Id Γ ⟩ :: τ ⊣ (Δ ,, u :: τ [ Γ ]) mutual -- substitution typing data _,_⊢_:s:_ : hctx → tctx → env → tctx → Set where STAId : ∀{Γ Γ' Δ} → ((x : Nat) (τ : htyp) → (x , τ) ∈ Γ' → (x , τ) ∈ Γ) → Δ , Γ ⊢ Id Γ' :s: Γ' STASubst : ∀{Γ Δ σ y Γ' d τ} → Δ , Γ ,, (y , τ) ⊢ σ :s: Γ' → Δ , Γ ⊢ d :: τ → Δ , Γ ⊢ Subst d y σ :s: Γ' -- type assignment data _,_⊢_::_ : (Δ : hctx) (Γ : tctx) (d : ihexp) (τ : htyp) → Set where TANum : ∀{Δ Γ n} → Δ , Γ ⊢ (N n) :: num TAPlus : ∀{Δ Γ d1 d2} → Δ , Γ ⊢ d1 :: num → Δ , Γ ⊢ d2 :: num → Δ , Γ ⊢ (d1 ·+ d2) :: num TAVar : ∀{Δ Γ x τ} → (x , τ) ∈ Γ → Δ , Γ ⊢ X x :: τ TALam : ∀{Δ Γ x τ1 d τ2} → x # Γ → Δ , (Γ ,, (x , τ1)) ⊢ d :: τ2 → Δ , Γ ⊢ ·λ x ·[ τ1 ] d :: (τ1 ==> τ2) TAAp : ∀{Δ Γ d1 d2 τ1 τ} → Δ , Γ ⊢ d1 :: τ1 ==> τ → Δ , Γ ⊢ d2 :: τ1 → Δ , Γ ⊢ d1 ∘ d2 :: τ TAInl : ∀{Δ Γ d τ1 τ2} → Δ , Γ ⊢ d :: τ1 → Δ , Γ ⊢ inl τ2 d :: τ1 ⊕ τ2 TAInr : ∀{Δ Γ d τ1 τ2} → Δ , Γ ⊢ d :: τ2 → Δ , Γ ⊢ inr τ1 d :: τ1 ⊕ τ2 TACase : ∀{Δ Γ d τ1 τ2 τ x d1 y d2} → Δ , Γ ⊢ d :: τ1 ⊕ τ2 → x # Γ → Δ , (Γ ,, (x , τ1)) ⊢ d1 :: τ → y # Γ → Δ , (Γ ,, (y , τ2)) ⊢ d2 :: τ → Δ , Γ ⊢ case d x d1 y d2 :: τ TAPair : ∀{Δ Γ d1 d2 τ1 τ2} → Δ , Γ ⊢ d1 :: τ1 → Δ , Γ ⊢ d2 :: τ2 → Δ , Γ ⊢ ⟨ d1 , d2 ⟩ :: τ1 ⊠ τ2 TAFst : ∀{Δ Γ d τ1 τ2} → Δ , Γ ⊢ d :: τ1 ⊠ τ2 → Δ , Γ ⊢ fst d :: τ1 TASnd : ∀{Δ Γ d τ1 τ2} → Δ , Γ ⊢ d :: τ1 ⊠ τ2 → Δ , Γ ⊢ snd d :: τ2 TAEHole : ∀{Δ Γ σ u Γ' τ} → (u , (Γ' , τ)) ∈ Δ → Δ , Γ ⊢ σ :s: Γ' → Δ , Γ ⊢ ⦇-⦈⟨ u , σ ⟩ :: τ TANEHole : ∀{Δ Γ d τ' Γ' u σ τ} → (u , (Γ' , τ)) ∈ Δ → Δ , Γ ⊢ d :: τ' → Δ , Γ ⊢ σ :s: Γ' → Δ , Γ ⊢ ⦇⌜ d ⌟⦈⟨ u , σ ⟩ :: τ TACast : ∀{Δ Γ d τ1 τ2} → Δ , Γ ⊢ d :: τ1 → τ1 ~ τ2 → Δ , Γ ⊢ d ⟨ τ1 ⇒ τ2 ⟩ :: τ2 TAFailedCast : ∀{Δ Γ d τ1 τ2} → Δ , Γ ⊢ d :: τ1 → τ1 ground → τ2 ground → τ1 ≠ τ2 → Δ , Γ ⊢ d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩ :: τ2 -- substitution [_/_]_ : ihexp → Nat → ihexp → ihexp [ d / y ] (N n) = N n [ d / y ] (d1 ·+ d2) = ([ d / y ] d1) ·+ ([ d / y ] d2) [ d / y ] X x with natEQ x y [ d / y ] X .y | Inl refl = d [ d / y ] X x | Inr neq = X x [ d / y ] (·λ x ·[ x₁ ] d') with natEQ x y [ d / y ] (·λ .y ·[ τ ] d') | Inl refl = ·λ y ·[ τ ] d' [ d / y ] (·λ x ·[ τ ] d') | Inr x₁ = ·λ x ·[ τ ] ( [ d / y ] d') [ d / y ] (d1 ∘ d2) = ([ d / y ] d1) ∘ ([ d / y ] d2) [ d / y ] (inl τ d') = inl τ ([ d / y ] d') [ d / y ] (inr τ d') = inr τ ([ d / y ] d') [ d / y ] (case d' x d1 z d2) with natEQ x y | natEQ z y ... | Inl refl | Inl refl = case ([ d / y ] d') x d1 z d2 ... | Inl refl | Inr neq = case ([ d / y ] d') x d1 z ([ d / y ] d2) ... | Inr neq | Inl refl = case ([ d / y ] d') x ([ d / y ] d1) z d2 ... | Inr neq1 | Inr neq2 = case ([ d / y ] d') x ([ d / y ] d1) z ([ d / y ] d2) [ d / y ] ⟨ d1 , d2 ⟩ = ⟨ [ d / y ] d1 , [ d / y ] d2 ⟩ [ d / y ] (fst d') = fst ([ d / y ] d') [ d / y ] (snd d') = snd ([ d / y ] d') [ d / y ] ⦇-⦈⟨ u , σ ⟩ = ⦇-⦈⟨ u , Subst d y σ ⟩ [ d / y ] ⦇⌜ d' ⌟⦈⟨ u , σ ⟩ = ⦇⌜ [ d / y ] d' ⌟⦈⟨ u , Subst d y σ ⟩ [ d / y ] (d' ⟨ τ1 ⇒ τ2 ⟩ ) = ([ d / y ] d') ⟨ τ1 ⇒ τ2 ⟩ [ d / y ] (d' ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩ ) = ([ d / y ] d') ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩ -- applying an environment to an expression apply-env : env → ihexp → ihexp apply-env (Id Γ) d = d apply-env (Subst d y σ) d' = [ d / y ] ( apply-env σ d') -- values data _val : (d : ihexp) → Set where VNum : ∀{n} → (N n) val VLam : ∀{x τ d} → (·λ x ·[ τ ] d) val VInl : ∀{d τ} → d val → (inl τ d) val VInr : ∀{d τ} → d val → (inr τ d) val VPair : ∀{d1 d2} → d1 val → d2 val → ⟨ d1 , d2 ⟩ val -- boxed values data _boxedval : (d : ihexp) → Set where BVVal : ∀{d} → d val → d boxedval BVInl : ∀{d τ} → d boxedval → (inl τ d) boxedval BVInr : ∀{d τ} → d boxedval → (inr τ d) boxedval BVPair : ∀{d1 d2} → d1 boxedval → d2 boxedval → ⟨ d1 , d2 ⟩ boxedval BVArrCast : ∀{d τ1 τ2 τ3 τ4} → τ1 ==> τ2 ≠ τ3 ==> τ4 → d boxedval → d ⟨ (τ1 ==> τ2) ⇒ (τ3 ==> τ4) ⟩ boxedval BVSumCast : ∀{d τ1 τ2 τ3 τ4} → τ1 ⊕ τ2 ≠ τ3 ⊕ τ4 → d boxedval → d ⟨ (τ1 ⊕ τ2) ⇒ (τ3 ⊕ τ4) ⟩ boxedval BVProdCast : ∀{d τ1 τ2 τ3 τ4} → τ1 ⊠ τ2 ≠ τ3 ⊠ τ4 → d boxedval → d ⟨ (τ1 ⊠ τ2) ⇒ (τ3 ⊠ τ4) ⟩ boxedval BVHoleCast : ∀{τ d} → τ ground → d boxedval → d ⟨ τ ⇒ ⦇-⦈ ⟩ boxedval mutual -- indeterminate forms data _indet : (d : ihexp) → Set where IPlus1 : ∀{d1 d2} → d1 indet → d2 final → (d1 ·+ d2) indet IPlus2 : ∀{d1 d2} → d1 final → d2 indet → (d1 ·+ d2) indet IAp : ∀{d1 d2} → ((τ1 τ2 τ3 τ4 : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨(τ1 ==> τ2) ⇒ (τ3 ==> τ4)⟩)) → d1 indet → d2 final → (d1 ∘ d2) indet IInl : ∀{d τ} → d indet → (inl τ d) indet IInr : ∀{d τ} → d indet → (inr τ d) indet ICase : ∀{d x d1 y d2} → ((τ : htyp) (d' : ihexp) → d ≠ inl τ d') → ((τ : htyp) (d' : ihexp) → d ≠ inr τ d') → ((τ1 τ2 τ1' τ2' : htyp) (d' : ihexp) → d ≠ (d' ⟨(τ1 ⊕ τ2) ⇒ (τ1' ⊕ τ2')⟩)) → d indet → (case d x d1 y d2) indet IPair1 : ∀{d1 d2} → d1 indet → d2 final → ⟨ d1 , d2 ⟩ indet IPair2 : ∀{d1 d2} → d1 final → d2 indet → ⟨ d1 , d2 ⟩ indet IFst : ∀{d} → ((d1 d2 : ihexp) → d ≠ ⟨ d1 , d2 ⟩) → ((τ1 τ2 τ1' τ2' : htyp) (d' : ihexp) → d ≠ (d' ⟨(τ1 ⊠ τ2) ⇒ (τ1' ⊠ τ2')⟩)) → d indet → (fst d) indet ISnd : ∀{d} → ((d1 d2 : ihexp) → d ≠ ⟨ d1 , d2 ⟩) → ((τ1 τ2 τ1' τ2' : htyp) (d' : ihexp) → d ≠ (d' ⟨(τ1 ⊠ τ2) ⇒ (τ1' ⊠ τ2')⟩)) → d indet → (snd d) indet IEHole : ∀{u σ} → ⦇-⦈⟨ u , σ ⟩ indet INEHole : ∀{d u σ} → d final → ⦇⌜ d ⌟⦈⟨ u , σ ⟩ indet ICastArr : ∀{d τ1 τ2 τ3 τ4} → τ1 ==> τ2 ≠ τ3 ==> τ4 → d indet → d ⟨ (τ1 ==> τ2) ⇒ (τ3 ==> τ4) ⟩ indet ICastSum : ∀{d τ1 τ2 τ3 τ4} → τ1 ⊕ τ2 ≠ τ3 ⊕ τ4 → d indet → d ⟨ (τ1 ⊕ τ2) ⇒ (τ3 ⊕ τ4) ⟩ indet ICastProd : ∀{d τ1 τ2 τ3 τ4} → τ1 ⊠ τ2 ≠ τ3 ⊠ τ4 → d indet → d ⟨ (τ1 ⊠ τ2) ⇒ (τ3 ⊠ τ4) ⟩ indet ICastGroundHole : ∀{τ d} → τ ground → d indet → d ⟨ τ ⇒ ⦇-⦈ ⟩ indet ICastHoleGround : ∀{d τ} → ((d' : ihexp) (τ' : htyp) → d ≠ (d' ⟨ τ' ⇒ ⦇-⦈ ⟩)) → d indet → τ ground → d ⟨ ⦇-⦈ ⇒ τ ⟩ indet IFailedCast : ∀{d τ1 τ2} → d final → τ1 ground → τ2 ground → τ1 ≠ τ2 → d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩ indet -- final expressions data _final : (d : ihexp) → Set where FBoxedVal : ∀{d} → d boxedval → d final FIndet : ∀{d} → d indet → d final -- contextual dynamics -- evaluation contexts data ectx : Set where ⊙ : ectx _·+₁_ : ectx → ihexp → ectx _·+₂_ : ihexp → ectx → ectx _∘₁_ : ectx → ihexp → ectx _∘₂_ : ihexp → ectx → ectx inl : htyp → ectx → ectx inr : htyp → ectx → ectx case : ectx → Nat → ihexp → Nat → ihexp → ectx ⟨_,_⟩₁ : ectx → ihexp → ectx ⟨_,_⟩₂ : ihexp → ectx → ectx fst : ectx → ectx snd : ectx → ectx ⦇⌜_⌟⦈⟨_⟩ : ectx → (Nat × env ) → ectx _⟨_⇒_⟩ : ectx → htyp → htyp → ectx _⟨_⇒⦇-⦈⇏_⟩ : ectx → htyp → htyp → ectx -- note: this judgement is redundant: in the absence of the premises in -- the red brackets, all syntactically well formed ectxs are valid. with -- finality premises, that's not true, and that would propagate through -- additions to the calculus. so we leave it here for clarity but note -- that, as written, in any use case it's either trival to prove or -- provides no additional information --ε is an evaluation context data _evalctx : (ε : ectx) → Set where ECDot : ⊙ evalctx ECPlus1 : ∀{d ε} → ε evalctx → (ε ·+₁ d) evalctx ECPlus2 : ∀{d ε} → -- d final → -- red brackets ε evalctx → (d ·+₂ ε) evalctx ECAp1 : ∀{d ε} → ε evalctx → (ε ∘₁ d) evalctx ECAp2 : ∀{d ε} → -- d final → -- red brackets ε evalctx → (d ∘₂ ε) evalctx ECInl : ∀{τ ε} → ε evalctx → (inl τ ε) evalctx ECInr : ∀{τ ε} → ε evalctx → (inr τ ε) evalctx ECCase : ∀{ε x d1 y d2} → ε evalctx → (case ε x d1 y d2) evalctx ECPair1 : ∀{d ε} → ε evalctx → ⟨ ε , d ⟩₁ evalctx ECPair2 : ∀{d ε} → -- d final → -- red brackets ε evalctx → ⟨ d , ε ⟩₂ evalctx ECFst : ∀{ε} → (fst ε) evalctx ECSnd : ∀{ε} → (snd ε) evalctx ECNEHole : ∀{ε u σ} → ε evalctx → ⦇⌜ ε ⌟⦈⟨ u , σ ⟩ evalctx ECCast : ∀{ε τ1 τ2} → ε evalctx → (ε ⟨ τ1 ⇒ τ2 ⟩) evalctx ECFailedCast : ∀{ε τ1 τ2} → ε evalctx → ε ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩ evalctx -- d is the result of filling the hole in ε with d' data _==_⟦_⟧ : (d : ihexp) (ε : ectx) (d' : ihexp) → Set where FHOuter : ∀{d} → d == ⊙ ⟦ d ⟧ FHPlus1 : ∀{d1 d1' d2 ε} → d1 == ε ⟦ d1' ⟧ → (d1 ·+ d2) == (ε ·+₁ d2) ⟦ d1' ⟧ FHPlus2 : ∀{d1 d2 d2' ε} → -- d1 final → -- red brackets d2 == ε ⟦ d2' ⟧ → (d1 ·+ d2) == (d1 ·+₂ ε) ⟦ d2' ⟧ FHAp1 : ∀{d1 d1' d2 ε} → d1 == ε ⟦ d1' ⟧ → (d1 ∘ d2) == (ε ∘₁ d2) ⟦ d1' ⟧ FHAp2 : ∀{d1 d2 d2' ε} → -- d1 final → -- red brackets d2 == ε ⟦ d2' ⟧ → (d1 ∘ d2) == (d1 ∘₂ ε) ⟦ d2' ⟧ FHInl : ∀{d d' ε τ} → d == ε ⟦ d' ⟧ → (inl τ d) == (inl τ ε) ⟦ d' ⟧ FHInr : ∀{d d' ε τ} → d == ε ⟦ d' ⟧ → (inr τ d) == (inr τ ε) ⟦ d' ⟧ FHCase : ∀{d d' x d1 y d2 ε} → d == ε ⟦ d' ⟧ → (case d x d1 y d2) == (case ε x d1 y d2) ⟦ d' ⟧ FHPair1 : ∀{d1 d1' d2 ε} → d1 == ε ⟦ d1' ⟧ → ⟨ d1 , d2 ⟩ == ⟨ ε , d2 ⟩₁ ⟦ d1' ⟧ FHPair2 : ∀{d1 d2 d2' ε} → d2 == ε ⟦ d2' ⟧ → ⟨ d1 , d2 ⟩ == ⟨ d1 , ε ⟩₂ ⟦ d2' ⟧ FHFst : ∀{d d' ε} → d == ε ⟦ d' ⟧ → fst d == (fst ε) ⟦ d' ⟧ FHSnd : ∀{d d' ε} → d == ε ⟦ d' ⟧ → snd d == (snd ε) ⟦ d' ⟧ FHNEHole : ∀{d d' ε u σ} → d == ε ⟦ d' ⟧ → ⦇⌜ d ⌟⦈⟨ (u , σ ) ⟩ == ⦇⌜ ε ⌟⦈⟨ (u , σ ) ⟩ ⟦ d' ⟧ FHCast : ∀{d d' ε τ1 τ2} → d == ε ⟦ d' ⟧ → d ⟨ τ1 ⇒ τ2 ⟩ == ε ⟨ τ1 ⇒ τ2 ⟩ ⟦ d' ⟧ FHFailedCast : ∀{d d' ε τ1 τ2} → d == ε ⟦ d' ⟧ → (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) == (ε ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) ⟦ d' ⟧ -- matched ground types data _▸gnd_ : htyp → htyp → Set where MGArr : ∀{τ1 τ2} → (τ1 ==> τ2) ≠ (⦇-⦈ ==> ⦇-⦈) → (τ1 ==> τ2) ▸gnd (⦇-⦈ ==> ⦇-⦈) MGSum : ∀{τ1 τ2} → (τ1 ⊕ τ2) ≠ (⦇-⦈ ⊕ ⦇-⦈) → (τ1 ⊕ τ2) ▸gnd (⦇-⦈ ⊕ ⦇-⦈) MGProd : ∀{τ1 τ2} → (τ1 ⊠ τ2) ≠ (⦇-⦈ ⊠ ⦇-⦈) → (τ1 ⊠ τ2) ▸gnd (⦇-⦈ ⊠ ⦇-⦈) -- instruction transition judgement data _→>_ : (d d' : ihexp) → Set where ITPlus : ∀{n1 n2 n3} → (n1 nat+ n2) == n3 → ((N n1) ·+ (N n2)) →> (N n3) ITLam : ∀{x τ d1 d2} → -- d2 final → -- red brackets ((·λ x ·[ τ ] d1) ∘ d2) →> ([ d2 / x ] d1) ITApCast : ∀{d1 d2 τ1 τ2 τ1' τ2'} → -- d1 final → -- red brackets -- d2 final → -- red brackets ((d1 ⟨ (τ1 ==> τ2) ⇒ (τ1' ==> τ2')⟩) ∘ d2) →> ((d1 ∘ (d2 ⟨ τ1' ⇒ τ1 ⟩)) ⟨ τ2 ⇒ τ2' ⟩) ITCaseInl : ∀{d τ x d1 y d2} → -- d final → -- red brackets, (case (inl τ d) x d1 y d2) →> ([ d / x ] d1) ITCaseInr : ∀{d τ x d1 y d2} → -- d final → -- red brackets, (case (inr τ d) x d1 y d2) →> ([ d / y ] d2) ITCaseCast : ∀{d τ1 τ2 τ1' τ2' x d1 y d2} → -- d final → -- red brackets (case (d ⟨ τ1 ⊕ τ2 ⇒ τ1' ⊕ τ2' ⟩) x d1 y d2) →> (case d x ([ (X x) ⟨ τ1 ⇒ τ1' ⟩ / x ] d1) y ([ (X y) ⟨ τ2 ⇒ τ2' ⟩ / y ] d2)) ITFstPair : ∀{d1 d2} → -- d1 final → -- red brackets -- d2 final → -- red brackets fst ⟨ d1 , d2 ⟩ →> d1 ITFstCast : ∀{d τ1 τ2 τ1' τ2' } → -- d final → -- red brackets fst (d ⟨ τ1 ⊠ τ2 ⇒ τ1' ⊠ τ2' ⟩) →> ((fst d) ⟨ τ1 ⇒ τ1' ⟩) ITSndPair : ∀{d1 d2} → -- d1 final → -- red brackets -- d2 final → -- red brackets snd ⟨ d1 , d2 ⟩ →> d2 ITSndCast : ∀{d τ1 τ2 τ1' τ2' } → -- d final → -- red brackets snd (d ⟨ τ1 ⊠ τ2 ⇒ τ1' ⊠ τ2' ⟩) →> ((snd d) ⟨ τ2 ⇒ τ2' ⟩) ITCastID : ∀{d τ} → -- d final → -- red brackets (d ⟨ τ ⇒ τ ⟩) →> d ITCastSucceed : ∀{d τ} → -- d final → -- red brackets τ ground → (d ⟨ τ ⇒ ⦇-⦈ ⇒ τ ⟩) →> d ITCastFail : ∀{d τ1 τ2} → -- d final → -- red brackets τ1 ground → τ2 ground → τ1 ≠ τ2 → (d ⟨ τ1 ⇒ ⦇-⦈ ⇒ τ2 ⟩) →> (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) ITGround : ∀{d τ τ'} → -- d final → -- red brackets τ ▸gnd τ' → (d ⟨ τ ⇒ ⦇-⦈ ⟩) →> (d ⟨ τ ⇒ τ' ⇒ ⦇-⦈ ⟩) ITExpand : ∀{d τ τ'} → -- d final → -- red brackets τ ▸gnd τ' → (d ⟨ ⦇-⦈ ⇒ τ ⟩) →> (d ⟨ ⦇-⦈ ⇒ τ' ⇒ τ ⟩) -- single step (in contextual evaluation sense) data _↦_ : (d d' : ihexp) → Set where Step : ∀{d d0 d' d0' ε} → d == ε ⟦ d0 ⟧ → d0 →> d0' → d' == ε ⟦ d0' ⟧ → d ↦ d' -- reflexive transitive closure of single steps into multi steps data _↦*_ : (d d' : ihexp) → Set where MSRefl : ∀{d} → d ↦* d MSStep : ∀{d d' d''} → d ↦ d' → d' ↦* d'' → d ↦* d'' -- those internal expressions where every cast is the identity cast and -- there are no failed casts data cast-id : ihexp → Set where CINum : ∀{n} → cast-id (N n) CIPlus : ∀{d1 d2} → cast-id d1 → cast-id d2 → cast-id (d1 ·+ d2) CIVar : ∀{x} → cast-id (X x) CILam : ∀{x τ d} → cast-id d → cast-id (·λ x ·[ τ ] d) CIAp : ∀{d1 d2} → cast-id d1 → cast-id d2 → cast-id (d1 ∘ d2) CIInl : ∀{τ d} → cast-id d → cast-id (inl τ d) CIInr : ∀{τ d} → cast-id d → cast-id (inr τ d) CICase : ∀{d x d1 y d2} → cast-id d → cast-id d1 → cast-id d2 → cast-id (case d x d1 y d2) CIPair : ∀{d1 d2} → cast-id d1 → cast-id d2 → cast-id ⟨ d1 , d2 ⟩ CIFst : ∀{d} → cast-id d → cast-id (fst d) CISnd : ∀{d} → cast-id d → cast-id (snd d) CIHole : ∀{u} → cast-id (⦇-⦈⟨ u ⟩) CINEHole : ∀{d u} → cast-id d → cast-id (⦇⌜ d ⌟⦈⟨ u ⟩) CICast : ∀{d τ} → cast-id d → cast-id (d ⟨ τ ⇒ τ ⟩) -- freshness mutual -- ... with respect to a hole context data envfresh : Nat → env → Set where EFId : ∀{x Γ} → x # Γ → envfresh x (Id Γ) EFSubst : ∀{x d σ y} → fresh x d → envfresh x σ → x ≠ y → envfresh x (Subst d y σ) -- ... for internal expressions data fresh : Nat → ihexp → Set where FNum : ∀{x n} → fresh x (N n) FPlus : ∀{x d1 d2} → fresh x d1 → fresh x d2 → fresh x (d1 ·+ d2) FVar : ∀{x y} → x ≠ y → fresh x (X y) FLam : ∀{x y τ d} → x ≠ y → fresh x d → fresh x (·λ y ·[ τ ] d) FAp : ∀{x d1 d2} → fresh x d1 → fresh x d2 → fresh x (d1 ∘ d2) FInl : ∀{x d τ} → fresh x d → fresh x (inl τ d) FInr : ∀{x d τ} → fresh x d → fresh x (inr τ d) FCase : ∀{x d y d1 z d2} → fresh x d → x ≠ y → fresh x d1 → x ≠ z → fresh x d2 → fresh x (case d y d1 z d2) FPair : ∀{x d1 d2} → fresh x d1 → fresh x d2 → fresh x ⟨ d1 , d2 ⟩ FFst : ∀{x d} → fresh x d → fresh x (fst d) FSnd : ∀{x d} → fresh x d → fresh x (snd d) FHole : ∀{x u σ} → envfresh x σ → fresh x (⦇-⦈⟨ u , σ ⟩) FNEHole : ∀{x d u σ} → envfresh x σ → fresh x d → fresh x (⦇⌜ d ⌟⦈⟨ u , σ ⟩) FCast : ∀{x d τ1 τ2} → fresh x d → fresh x (d ⟨ τ1 ⇒ τ2 ⟩) FFailedCast : ∀{x d τ1 τ2} → fresh x d → fresh x (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) -- x is not used in a binding site in d mutual data unbound-in-σ : Nat → env → Set where UBσId : ∀{x Γ} → unbound-in-σ x (Id Γ) UBσSubst : ∀{x d y σ} → unbound-in x d → unbound-in-σ x σ → x ≠ y → unbound-in-σ x (Subst d y σ) data unbound-in : (x : Nat) (d : ihexp) → Set where UBNum : ∀{x n} → unbound-in x (N n) UBPlus : ∀{x d1 d2} → unbound-in x d1 → unbound-in x d2 → unbound-in x (d1 ·+ d2) UBVar : ∀{x y} → unbound-in x (X y) UBLam2 : ∀{x d y τ} → x ≠ y → unbound-in x d → unbound-in x (·λ y ·[ τ ] d) UBAp : ∀{x d1 d2} → unbound-in x d1 → unbound-in x d2 → unbound-in x (d1 ∘ d2) UBInl : ∀{x d τ} → unbound-in x d → unbound-in x (inl τ d) UBInr : ∀{x d τ} → unbound-in x d → unbound-in x (inr τ d) UBCase : ∀{x d y d1 z d2} → unbound-in x d → x ≠ y → unbound-in x d1 → x ≠ z → unbound-in x d2 → unbound-in x (case d y d1 z d2) UBPair : ∀{x d1 d2} → unbound-in x d1 → unbound-in x d2 → unbound-in x ⟨ d1 , d2 ⟩ UBFst : ∀{x d} → unbound-in x d → unbound-in x (fst d) UBSnd : ∀{x d} → unbound-in x d → unbound-in x (snd d) UBHole : ∀{x u σ} → unbound-in-σ x σ → unbound-in x (⦇-⦈⟨ u , σ ⟩) UBNEHole : ∀{x u σ d} → unbound-in-σ x σ → unbound-in x d → unbound-in x (⦇⌜ d ⌟⦈⟨ u , σ ⟩) UBCast : ∀{x d τ1 τ2} → unbound-in x d → unbound-in x (d ⟨ τ1 ⇒ τ2 ⟩) UBFailedCast : ∀{x d τ1 τ2} → unbound-in x d → unbound-in x (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) mutual data binders-disjoint-σ : env → ihexp → Set where BDσId : ∀{Γ d} → binders-disjoint-σ (Id Γ) d BDσSubst : ∀{d1 d2 y σ} → binders-disjoint d2 d1 → binders-disjoint-σ σ d2 → unbound-in y d2 → binders-disjoint-σ (Subst d1 y σ) d2 -- two terms that do not share any binders data binders-disjoint : ihexp → ihexp → Set where BDNum : ∀{d n} → binders-disjoint (N n) d BDPlus : ∀{d1 d2 d3} → binders-disjoint d1 d3 → binders-disjoint d2 d3 → binders-disjoint (d1 ·+ d2) d3 BDVar : ∀{x d} → binders-disjoint (X x) d BDLam : ∀{x τ d1 d2} → binders-disjoint d1 d2 → unbound-in x d2 → binders-disjoint (·λ x ·[ τ ] d1) d2 BDAp : ∀{d1 d2 d3} → binders-disjoint d1 d3 → binders-disjoint d2 d3 → binders-disjoint (d1 ∘ d2) d3 BDInl : ∀{d1 d2 τ} → binders-disjoint d1 d2 → binders-disjoint (inl τ d1) d2 BDInr : ∀{d1 d2 τ} → binders-disjoint d1 d2 → binders-disjoint (inr τ d1) d2 BDCase : ∀{d x d1 y d2 d3} → binders-disjoint d d3 → unbound-in x d3 → binders-disjoint d1 d3 → unbound-in y d3 → binders-disjoint d2 d3 → binders-disjoint (case d x d1 y d2) d3 BDPair : ∀{d1 d2 d3} → binders-disjoint d1 d3 → binders-disjoint d2 d3 → binders-disjoint ⟨ d1 , d2 ⟩ d3 BDFst : ∀{d1 d2} → binders-disjoint d1 d2 → binders-disjoint (fst d1) d2 BDSnd : ∀{d1 d2} → binders-disjoint d1 d2 → binders-disjoint (snd d1) d2 BDHole : ∀{u σ d2} → binders-disjoint-σ σ d2 → binders-disjoint (⦇-⦈⟨ u , σ ⟩) d2 BDNEHole : ∀{u σ d1 d2} → binders-disjoint-σ σ d2 → binders-disjoint d1 d2 → binders-disjoint (⦇⌜ d1 ⌟⦈⟨ u , σ ⟩) d2 BDCast : ∀{d1 d2 τ1 τ2} → binders-disjoint d1 d2 → binders-disjoint (d1 ⟨ τ1 ⇒ τ2 ⟩) d2 BDFailedCast : ∀{d1 d2 τ1 τ2} → binders-disjoint d1 d2 → binders-disjoint (d1 ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) d2 mutual -- each term has to be binders unique, and they have to be pairwise -- disjoint with the collection of bound vars data binders-unique-σ : env → Set where BUσId : ∀{Γ} → binders-unique-σ (Id Γ) BUσSubst : ∀{d y σ} → binders-unique d → binders-unique-σ σ → binders-disjoint-σ σ d → binders-unique-σ (Subst d y σ) -- all the variable names in the term are unique data binders-unique : ihexp → Set where BUNum : ∀{n} → binders-unique (N n) BUPlus : ∀{d1 d2} → binders-unique d1 → binders-unique d2 → binders-disjoint d1 d2 → binders-unique (d1 ·+ d2) BUVar : ∀{x} → binders-unique (X x) BULam : {x : Nat} {τ : htyp} {d : ihexp} → binders-unique d → unbound-in x d → binders-unique (·λ x ·[ τ ] d) BUEHole : ∀{u σ} → binders-unique-σ σ → binders-unique (⦇-⦈⟨ u , σ ⟩) BUNEHole : ∀{u σ d} → binders-unique d → binders-unique-σ σ → binders-unique (⦇⌜ d ⌟⦈⟨ u , σ ⟩) BUAp : ∀{d1 d2} → binders-unique d1 → binders-unique d2 → binders-disjoint d1 d2 → binders-unique (d1 ∘ d2) BUInl : ∀{d τ} → binders-unique d → binders-unique (inl τ d) BUInr : ∀{d τ} → binders-unique d → binders-unique (inr τ d) BUCase : ∀{d x d1 y d2} → binders-unique d → binders-unique d1 → binders-unique d2 → binders-disjoint d d1 → binders-disjoint d d2 → binders-disjoint d1 d2 → unbound-in x d → unbound-in x d1 → unbound-in x d2 → unbound-in y d → unbound-in y d1 → unbound-in y d2 → binders-unique (case d x d1 y d2) BUPair : ∀{d1 d2} → binders-unique d1 → binders-unique d2 → binders-disjoint d1 d2 → binders-unique ⟨ d1 , d2 ⟩ BUFst : ∀{d} → binders-unique d → binders-unique (fst d) BUSnd : ∀{d} → binders-unique d → binders-unique (snd d) BUCast : ∀{d τ1 τ2} → binders-unique d → binders-unique (d ⟨ τ1 ⇒ τ2 ⟩) BUFailedCast : ∀{d τ1 τ2} → binders-unique d → binders-unique (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩)
{ "alphanum_fraction": 0.3491270611, "avg_line_length": 35.3687821612, "ext": "agda", "hexsha": "d5a791bfdab3364d8978b31c3a530399d55e39fe", "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": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-agda", "max_forks_repo_path": "dynamics-core.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": "hazelgrove/hazelnut-agda", "max_issues_repo_path": "dynamics-core.agda", "max_line_length": 95, "max_stars_count": null, "max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-agda", "max_stars_repo_path": "dynamics-core.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 15873, "size": 41240 }
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Group.Base where import Cubical.Core.Glue as G open import Cubical.Foundations.Prelude hiding ( comp ) import Cubical.Foundations.Isomorphism as I import Cubical.Foundations.Equiv as E import Cubical.Foundations.HAEquiv as HAE record isGroup {ℓ} (A : Type ℓ) : Type ℓ where constructor group-struct field id : A inv : A → A comp : A → A → A lUnit : ∀ a → comp id a ≡ a rUnit : ∀ a → comp a id ≡ a assoc : ∀ a b c → comp (comp a b) c ≡ comp a (comp b c) lCancel : ∀ a → comp (inv a) a ≡ id rCalcel : ∀ a → comp a (inv a) ≡ id record Group {ℓ} : Type (ℓ-suc ℓ) where constructor group field type : Type ℓ setStruc : isSet type groupStruc : isGroup type isMorph : ∀ {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) → (f : (Group.type G → Group.type H)) → Type (ℓ-max ℓ ℓ') isMorph (group G Gset (group-struct _ _ _⊙_ _ _ _ _ _)) (group H Hset (group-struct _ _ _∘_ _ _ _ _ _)) f = (g0 g1 : G) → f (g0 ⊙ g1) ≡ (f g0) ∘ (f g1) morph : ∀ {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) → Type (ℓ-max ℓ ℓ') morph G H = Σ (Group.type G → Group.type H) (isMorph G H) record Iso {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where constructor iso field fun : morph G H inv : morph H G rightInv : I.section (fun .fst) (inv .fst) leftInv : I.retract (fun .fst) (inv .fst) record Iso' {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where constructor iso' field isoSet : I.Iso (Group.type G) (Group.type H) isoSetMorph : isMorph G H (I.Iso.fun isoSet) _≃_ : ∀ {ℓ ℓ'} (A : Group {ℓ}) (B : Group {ℓ'}) → Type (ℓ-max ℓ ℓ') A ≃ B = Σ (morph A B) \ f → (G.isEquiv (f .fst)) Iso'→Iso : ∀ {ℓ ℓ'} {G : Group {ℓ}} {H : Group {ℓ'}} → Iso' G H → Iso G H Iso'→Iso {G = group G Gset Ggroup} {H = group H Hset Hgroup} i = iso (fun , funMorph) (inv , invMorph) rightInv leftInv where G_ : Group G_ = (group G Gset Ggroup) H_ : Group H_ = (group H Hset Hgroup) open Iso' fun : G → H fun = I.Iso.fun (isoSet i) inv : H → G inv = I.Iso.inv (isoSet i) rightInv : I.section fun inv rightInv = I.Iso.rightInv (isoSet i) leftInv : I.retract fun inv leftInv = I.Iso.leftInv (isoSet i) e' : G G.≃ H e' = E.isoToEquiv (I.iso fun inv rightInv leftInv) funMorph : isMorph G_ H_ fun funMorph = isoSetMorph i _∘_ : H → H → H _∘_ = isGroup.comp Hgroup _⊙_ : G → G → G _⊙_ = isGroup.comp Ggroup invMorph : isMorph H_ G_ inv invMorph h0 h1 = E.invEq (HAE.congEquiv e') (fun (inv (h0 ∘ h1)) ≡⟨ rightInv (h0 ∘ h1) ⟩ h0 ∘ h1 ≡⟨ cong (λ x → x ∘ h1) (sym (rightInv h0)) ⟩ (fun (inv h0)) ∘ h1 ≡⟨ cong (λ x → fun (inv h0) ∘ x) (sym (rightInv h1)) ⟩ (fun (inv h0)) ∘ (fun (inv h1)) ≡⟨ sym (funMorph (inv h0) (inv h1)) ⟩ fun ((inv h0) ⊙ (inv h1)) ∎ ) Equiv→Iso' : ∀ {ℓ ℓ'} {G : Group {ℓ}} {H : Group {ℓ'}} → G ≃ H → Iso' G H Equiv→Iso' {G = group G Gset Ggroup} {H = group H Hset Hgroup} e = iso' i' (e .fst .snd) where e' : G G.≃ H e' = (e .fst .fst) , (e .snd) i' : I.Iso G H i' = E.equivToIso e' compMorph : ∀ {ℓ} {F G H : Group {ℓ}} (I : morph F G) (J : morph G H) → morph F H compMorph {ℓ} {group F Fset (group-struct _ _ _⊙_ _ _ _ _ _)} {group G Gset (group-struct _ _ _∙_ _ _ _ _ _)} {group H Hset (group-struct _ _ _∘_ _ _ _ _ _)} (i , ic) (j , jc) = k , kc where k : F → H k f = j (i f) kc : (g0 g1 : F) → k (g0 ⊙ g1) ≡ (k g0) ∘ (k g1) kc g0 g1 = j (i (g0 ⊙ g1)) ≡⟨ cong j (ic _ _) ⟩ j (i g0 ∙ i g1) ≡⟨ jc _ _ ⟩ j (i g0) ∘ j (i g1) ∎ compIso : ∀ {ℓ} {F G H : Group {ℓ}} (I : Iso F G) (J : Iso G H) → Iso F H compIso {ℓ} {F} {G} {H} (iso F→G G→F fg gf) (iso G→H H→G gh hg ) = iso F→H H→F sec ret where F→H : morph F H F→H = compMorph {ℓ} {F} {G} {H} F→G G→H H→F : morph H F H→F = compMorph {ℓ} {H} {G} {F} H→G G→F open Group f→h : F .type → H .type f→h = F→H .fst f→g : F .type → G .type f→g = F→G .fst g→h : G .type → H .type g→h = G→H .fst h→f : H .type → F .type h→f = H→F .fst h→g : H .type → G .type h→g = H→G .fst g→f : G .type → F .type g→f = G→F .fst sec : I.section f→h h→f sec h = f→h (h→f h) ≡⟨ cong g→h (fg (h→g h)) ⟩ g→h (h→g h) ≡⟨ gh _ ⟩ h ∎ ret : I.retract f→h h→f ret f = h→f (f→h f) ≡⟨ cong g→f (hg (f→g f)) ⟩ g→f (f→g f) ≡⟨ gf _ ⟩ f ∎
{ "alphanum_fraction": 0.502693385, "avg_line_length": 28.1272727273, "ext": "agda", "hexsha": "75e97b4e8c15e5fcd82ed8fc9904ce556646fe17", "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": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cj-xu/cubical", "max_forks_repo_path": "Cubical/Data/Group/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "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": "cj-xu/cubical", "max_issues_repo_path": "Cubical/Data/Group/Base.agda", "max_line_length": 119, "max_stars_count": null, "max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cj-xu/cubical", "max_stars_repo_path": "Cubical/Data/Group/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2043, "size": 4641 }
{-# OPTIONS --safe --without-K #-} open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; sym) open import Relation.Nullary using (Dec; yes; no) import Data.Bool as Bool import Data.Empty as Empty import Data.Unit as Unit import Data.Sum as Sum import Data.Product as Product import Data.Nat as ℕ import Data.Nat.Properties as ℕₚ open Empty using (⊥) open Unit using (⊤; tt) open Sum using (inj₁; inj₂) open Product using (∃-syntax; _×_; _,_) open ℕ using (ℕ) open import PiCalculus.LinearTypeSystem.Algebras module PiCalculus.LinearTypeSystem.Algebras.Linear where open Bool using (Bool; true; false) public pattern zero = false pattern one = true data _≔_∙_ : Bool → Bool → Bool → Set where skip : zero ≔ zero ∙ zero right : one ≔ zero ∙ one left : one ≔ one ∙ zero ∙-computeʳ : ∀ x y → Dec (∃[ z ] (x ≔ y ∙ z)) ∙-computeʳ zero zero = yes (zero , skip) ∙-computeʳ zero one = no λ () ∙-computeʳ one zero = yes (one , right) ∙-computeʳ one one = yes (zero , left) ∙-unique : ∀ {x' x y z} → x' ≔ y ∙ z → x ≔ y ∙ z → x' ≡ x ∙-unique skip skip = refl ∙-unique right right = refl ∙-unique left left = refl ∙-uniqueˡ : ∀ {x y' y z} → x ≔ y' ∙ z → x ≔ y ∙ z → y' ≡ y ∙-uniqueˡ skip skip = refl ∙-uniqueˡ right right = refl ∙-uniqueˡ left left = refl ∙-idˡ : ∀ {x} → x ≔ zero ∙ x ∙-idˡ {zero} = skip ∙-idˡ {one} = right ∙-comm : ∀ {x y z} → x ≔ y ∙ z → x ≔ z ∙ y ∙-comm skip = skip ∙-comm right = left ∙-comm left = right ∙-assoc : ∀ {x y z u v} → x ≔ y ∙ z → y ≔ u ∙ v → ∃-syntax (λ w → (x ≔ u ∙ w) × (w ≔ v ∙ z)) ∙-assoc skip skip = zero , skip , skip ∙-assoc right skip = one , right , right ∙-assoc left right = one , right , left ∙-assoc left left = zero , left , skip Linear : Algebra Bool Algebra.1∙ Linear = true Algebra.0∙ Linear = false Algebra._≔_∙_ Linear = _≔_∙_ Algebra.∙-computeʳ Linear = ∙-computeʳ Algebra.∙-unique Linear = ∙-unique Algebra.∙-uniqueˡ Linear = ∙-uniqueˡ Algebra.0∙-minˡ Linear skip = refl Algebra.∙-idˡ Linear = ∙-idˡ Algebra.∙-comm Linear = ∙-comm Algebra.∙-assoc Linear = ∙-assoc
{ "alphanum_fraction": 0.6374269006, "avg_line_length": 27.36, "ext": "agda", "hexsha": "6352ddf253dbe76775f0257f0d7f67318d204057", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z", "max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "guilhermehas/typing-linear-pi", "max_forks_repo_path": "src/PiCalculus/LinearTypeSystem/Algebras/Linear.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a", "max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z", "max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "guilhermehas/typing-linear-pi", "max_issues_repo_path": "src/PiCalculus/LinearTypeSystem/Algebras/Linear.agda", "max_line_length": 92, "max_stars_count": 26, "max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "guilhermehas/typing-linear-pi", "max_stars_repo_path": "src/PiCalculus/LinearTypeSystem/Algebras/Linear.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z", "num_tokens": 817, "size": 2052 }
{-# OPTIONS --safe #-} module Cubical.Data.Nat.Order.Recursive where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Transport open import Cubical.Data.Empty as Empty open import Cubical.Data.Sigma open import Cubical.Data.Sum as Sum open import Cubical.Data.Unit open import Cubical.Data.Nat.Base open import Cubical.Data.Nat.Properties open import Cubical.Induction.WellFounded open import Cubical.Relation.Nullary infix 4 _≤_ _<_ _≤_ : ℕ → ℕ → Type₀ zero ≤ _ = Unit suc m ≤ zero = ⊥ suc m ≤ suc n = m ≤ n _<_ : ℕ → ℕ → Type₀ m < n = suc m ≤ n _≤?_ : (m n : ℕ) → Dec (m ≤ n) zero ≤? _ = yes tt suc m ≤? zero = no λ () suc m ≤? suc n = m ≤? n data Trichotomy (m n : ℕ) : Type₀ where lt : m < n → Trichotomy m n eq : m ≡ n → Trichotomy m n gt : n < m → Trichotomy m n private variable ℓ : Level R : Type ℓ P : ℕ → Type ℓ k l m n : ℕ isProp≤ : isProp (m ≤ n) isProp≤ {zero} = isPropUnit isProp≤ {suc m} {zero} = isProp⊥ isProp≤ {suc m} {suc n} = isProp≤ {m} {n} ≤-k+ : m ≤ n → k + m ≤ k + n ≤-k+ {k = zero} m≤n = m≤n ≤-k+ {k = suc k} m≤n = ≤-k+ {k = k} m≤n ≤-+k : m ≤ n → m + k ≤ n + k ≤-+k {m} {n} {k} m≤n = transport (λ i → +-comm k m i ≤ +-comm k n i) (≤-k+ {m} {n} {k} m≤n) ≤-refl : ∀ m → m ≤ m ≤-refl zero = _ ≤-refl (suc m) = ≤-refl m ≤-trans : k ≤ m → m ≤ n → k ≤ n ≤-trans {zero} _ _ = _ ≤-trans {suc k} {suc m} {suc n} = ≤-trans {k} {m} {n} ≤-antisym : m ≤ n → n ≤ m → m ≡ n ≤-antisym {zero} {zero} _ _ = refl ≤-antisym {suc m} {suc n} m≤n n≤m = cong suc (≤-antisym m≤n n≤m) ≤-k+-cancel : k + m ≤ k + n → m ≤ n ≤-k+-cancel {k = zero} m≤n = m≤n ≤-k+-cancel {k = suc k} m≤n = ≤-k+-cancel {k} m≤n ≤-+k-cancel : m + k ≤ n + k → m ≤ n ≤-+k-cancel {m} {k} {n} = ≤-k+-cancel {k} {m} {n} ∘ transport λ i → +-comm m k i ≤ +-comm n k i ¬m<m : ¬ m < m ¬m<m {suc m} = ¬m<m {m} ≤0→≡0 : n ≤ 0 → n ≡ 0 ≤0→≡0 {zero} _ = refl ¬m+n<m : ¬ m + n < m ¬m+n<m {suc m} = ¬m+n<m {m} <-weaken : m < n → m ≤ n <-weaken {zero} _ = _ <-weaken {suc m} {suc n} = <-weaken {m} <-trans : k < m → m < n → k < n <-trans {k} {m} {n} k<m m<n = ≤-trans {suc k} {m} {n} k<m (<-weaken {m} m<n) <-asym : m < n → ¬ n < m <-asym {m} m<n n<m = ¬m<m {m} (<-trans {m} {_} {m} m<n n<m) <→≢ : n < m → ¬ n ≡ m <→≢ {n} {m} p q = ¬m<m {m = m} (subst {x = n} (_< m) q p) Trichotomy-suc : Trichotomy m n → Trichotomy (suc m) (suc n) Trichotomy-suc (lt m<n) = lt m<n Trichotomy-suc (eq m≡n) = eq (cong suc m≡n) Trichotomy-suc (gt n<m) = gt n<m _≟_ : ∀ m n → Trichotomy m n zero ≟ zero = eq refl zero ≟ suc n = lt _ suc m ≟ zero = gt _ suc m ≟ suc n = Trichotomy-suc (m ≟ n) k≤k+n : ∀ k → k ≤ k + n k≤k+n zero = _ k≤k+n (suc k) = k≤k+n k n≤k+n : ∀ n → n ≤ k + n n≤k+n {k} n = transport (λ i → n ≤ +-comm n k i) (k≤k+n n) ≤-split : m ≤ n → (m < n) ⊎ (m ≡ n) ≤-split {zero} {zero} m≤n = inr refl ≤-split {zero} {suc n} m≤n = inl _ ≤-split {suc m} {suc n} m≤n = Sum.map (idfun _) (cong suc) (≤-split {m} {n} m≤n) module WellFounded where wf-< : WellFounded _<_ wf-rec-< : ∀ n → WFRec _<_ (Acc _<_) n wf-< n = acc (wf-rec-< n) wf-rec-< (suc n) m m≤n with ≤-split {m} {n} m≤n ... | inl m<n = wf-rec-< n m m<n ... | inr m≡n = subst⁻ (Acc _<_) m≡n (wf-< n) wf-elim : (∀ n → (∀ m → m < n → P m) → P n) → ∀ n → P n wf-elim = WFI.induction WellFounded.wf-< wf-rec : (∀ n → (∀ m → m < n → R) → R) → ℕ → R wf-rec {R = R} = wf-elim {P = λ _ → R} module Minimal where Least : ∀{ℓ} → (ℕ → Type ℓ) → (ℕ → Type ℓ) Least P m = P m × (∀ n → n < m → ¬ P n) isPropLeast : (∀ m → isProp (P m)) → ∀ m → isProp (Least P m) isPropLeast pP m = isPropΣ (pP m) (λ _ → isPropΠ3 λ _ _ _ → isProp⊥) Least→ : Σ _ (Least P) → Σ _ P Least→ = map-snd fst search : (∀ m → Dec (P m)) → ∀ n → (Σ[ m ∈ ℕ ] Least P m) ⊎ (∀ m → m < n → ¬ P m) search dec zero = inr (λ _ b _ → b) search {P = P} dec (suc n) with search dec n ... | inl tup = inl tup ... | inr ¬P<n with dec n ... | yes Pn = inl (n , Pn , ¬P<n) ... | no ¬Pn = inr λ m m≤n → case ≤-split m≤n of λ where (inl m<n) → ¬P<n m m<n (inr m≡n) → subst⁻ (¬_ ∘ P) m≡n ¬Pn →Least : (∀ m → Dec (P m)) → Σ _ P → Σ _ (Least P) →Least dec (n , Pn) with search dec n ... | inl least = least ... | inr ¬P<n = n , Pn , ¬P<n Least-unique : ∀ m n → Least P m → Least P n → m ≡ n Least-unique m n (Pm , ¬P<m) (Pn , ¬P<n) with m ≟ n ... | lt m<n = Empty.rec (¬P<n m m<n Pm) ... | eq m≡n = m≡n ... | gt n<m = Empty.rec (¬P<m n n<m Pn) isPropΣLeast : (∀ m → isProp (P m)) → isProp (Σ _ (Least P)) isPropΣLeast pP (m , LPm) (n , LPn) = ΣPathP λ where .fst → Least-unique m n LPm LPn .snd → isOfHLevel→isOfHLevelDep 1 (isPropLeast pP) LPm LPn (Least-unique m n LPm LPn) Decidable→Collapsible : (∀ m → isProp (P m)) → (∀ m → Dec (P m)) → Collapsible (Σ ℕ P) Decidable→Collapsible pP dP = λ where .fst → Least→ ∘ →Least dP .snd x y → cong Least→ (isPropΣLeast pP (→Least dP x) (→Least dP y)) open Minimal using (Decidable→Collapsible) public
{ "alphanum_fraction": 0.5136292835, "avg_line_length": 26.6113989637, "ext": "agda", "hexsha": "f35d5674b8ed81a77385d8b9fb3a04f9dbfb911d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thomas-lamiaux/cubical", "max_forks_repo_path": "Cubical/Data/Nat/Order/Recursive.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "thomas-lamiaux/cubical", "max_issues_repo_path": "Cubical/Data/Nat/Order/Recursive.agda", "max_line_length": 73, "max_stars_count": 1, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Data/Nat/Order/Recursive.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "num_tokens": 2418, "size": 5136 }