Search is not available for this dataset
text
string
meta
dict
module Not-named-according-to-the-Haskell-lexical-syntax where postulate IO : Set -> Set {-# BUILTIN IO IO #-} {-# COMPILE GHC IO = type IO #-} postulate return : {A : Set} -> A -> IO A {-# COMPILE GHC return = \ _ -> return :: a -> IO a #-} data Unit : Set where unit : Unit {-# COMPILE GHC Unit = data () (()) #-}
{ "alphanum_fraction": 0.5823170732, "avg_line_length": 18.2222222222, "ext": "agda", "hexsha": "9c7d53760bd7088e8156eeec62edaab176123903", "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/compiler/Not-named-according-to-the-Haskell-lexical-syntax.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/compiler/Not-named-according-to-the-Haskell-lexical-syntax.agda", "max_line_length": 62, "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/compiler/Not-named-according-to-the-Haskell-lexical-syntax.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": 95, "size": 328 }
{-# OPTIONS --without-K --rewriting #-} module NotNot where open import Basics open import lib.NType2 {- The definitions here follow Penon's paper "Infinitesimaux et Intuitionisme". -} -- Since double negation is always proposition valued, we just define it that way -- for convenience. ¬¬ : ∀ {i} (A : Type i) → PropT i ¬¬ A = ¬ (¬ A), ¬¬-is-a-prop where ¬¬-is-a-prop : ∀ {i} {A : Type i} → (¬ (¬ A)) is-a-prop ¬¬-is-a-prop = mapping-into-prop-is-a-prop (λ _ → False holds-is-a-prop) continue : ∀ {i j} {A : Type i} {B : A → Type j} (a : A) → ((a : A) → B a) → B a continue a f = f a -- When trying to prove a negation from a double negation, -- You may remove the double negation. ¬¬-elim : ∀ {i j} {A : Type i} (B : (¬¬ A) holds → Type j) (f : (a : A) → ¬ (B (continue a))) → (nna : (¬¬ A) holds) → ¬ (B nna) ¬¬-elim {A = A} B f nna b = nna (λ a → (f a) b') where b' : {a : A} → B (continue a) b' {a} = transport B (prop-path (snd (¬¬ A)) nna (continue a)) b ¬¬-elim' : ∀ {i j} {A : Type i} {B : (¬¬ A) holds → Type j} (f : (a : A) → ¬ (B (continue a))) → (nna : (¬¬ A) holds) → ¬ (B nna) ¬¬-elim' {B = B} f nna = ¬¬-elim B f nna syntax ¬¬-elim B (λ a → t) nna = un¬¬ nna -as- a -in t in-family B syntax ¬¬-elim' (λ a → t) nna = un¬¬ nna -as- a -in t -- The "neighbor relation" -- a is the neighbor of b (a ≈ b) if a is not distinct from b (¬¬ (a == b)) infix 30 _≈_ _≈_ : ∀ {i} {A : Type i} (a b : A) → PropT i a ≈ b = ¬¬ (a == b) refl≈ : ∀ {i} {A : Type i} {a : A} → a ≈ a holds refl≈ = λ nnp → nnp refl trans≈ : ∀ {i} {A : Type i} {a b c : A} → a ≈ b holds → b ≈ c holds → a ≈ c holds trans≈ nnp nnq = un¬¬ nnp -as- p -in un¬¬ nnq -as- q -in (λ npq → npq (p ∙ q)) -- The "neighborhood" of a point of a type is the subtype of all its neighbors. nbhd-prop : ∀ {i} {A} (a : A) → SubtypeProp A i nbhd-prop a = (λ b → a ≈ b holds) , (λ b → a ≈ b holds-is-a-prop) nbhd : ∀ {i} {A : Type i} (a : A) → Type i nbhd {i} {A} a = Subtype (nbhd-prop a) -- The total space neighborhood bundle is the sum of all neighborhoods. nbhd-space : ∀ {i} (A : Type i) → Type i nbhd-space A = Σ A \(a : A) → nbhd a private -- We give the neighborhood space a nickname N = nbhd-space germ : ∀ {i j} {A : Type i} {B : Type j} -- The germ of → (f : A → B) -- a function f → (a : A) -- at a point a → nbhd a → nbhd (f a) -- is a function of this type germ f a (d , nnp) = f d , (un¬¬ nnp -as- p -in (λ ne → ne (ap f p)) in-family (λ _ → ¬ (f a == f d))) chain-rule : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} {f : A → B} {g : B → C} (a : A) → germ (g ∘ f) a == (germ g (f a)) ∘ (germ f a) chain-rule {f = f} {g = g} a = λ= $ λ {(d , p) → Subtype=-out (nbhd-prop (g (f a))) -- It suffices to prove the first terms are equal, refl -- which they are judgementally. } -- A map is etale if all its germs are equivalences. _is-etale : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) → Type (lmax i j) f is-etale = ∀ a → (germ f a) is-an-equiv {- Some universe level error ∘-is-etale : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} {f : A → B} {g : B → C} (p : f is-etale) (q : g is-etale) → (g ∘ f) is-etale ∘-is-etale {i}{j}{k}{A}{B}{C} {f = f} {g = g} p q = λ a → transport (λ (φ : nbhd a → nbhd (g (f (a)))) → φ is-an-equiv) {x = (germ g (f a)) ∘ (germ f a)} {y = germ (g ∘ f) a} (chain-rule a) (((q (f a)) ∘ise (p a)) ) -}
{ "alphanum_fraction": 0.467141726, "avg_line_length": 34.4454545455, "ext": "agda", "hexsha": "a9af7fb813f92e7ecc5e5370246a0329cc99283e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "glangmead/formalization", "max_forks_repo_path": "cohesion/david_jaz_261/NotNot.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "glangmead/formalization", "max_issues_repo_path": "cohesion/david_jaz_261/NotNot.agda", "max_line_length": 91, "max_stars_count": 6, "max_stars_repo_head_hexsha": "497e720a1ddaa2ec713c060f999f4b3ee2fe5e8a", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "glangmead/formalization", "max_stars_repo_path": "cohesion/david_jaz_261/NotNot.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-13T05:51:12.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-06T17:39:22.000Z", "num_tokens": 1492, "size": 3789 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Examples of pretty printing ------------------------------------------------------------------------ module README.Text.Pretty where open import Size open import Data.Bool.Base open import Data.List.Base as List open import Data.List.NonEmpty as List⁺ open import Data.Nat.Base open import Data.Product open import Data.String.Base hiding (parens; _<+>_) open import Data.Vec.Base as Vec open import Function.Base -- We import the pretty printer and pass 80 to say that we do not want to -- have lines longer than 80 characters open import Text.Pretty 80 open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------ -- A small declarative programming language ------------------------------------------------------------------------ -- We define a small programming language where definitions are -- introduced by providing a non-empty list of equations with: -- * the same number of patterns on the LHS -- * a term on the RHS of each equation -- A pattern is either a variable or a constructor applied to a -- list of subpatterns data Pattern (i : Size) : Set where var : String → Pattern i con : ∀ {j : Size< i} → String → List (Pattern j) → Pattern i -- A term is either a (bound) variable, the application of a -- named definition / constructor to a list of arguments or a -- lambda abstraction data Term (i : Size) : Set where var : String → Term i app : ∀ {j : Size< i} → String → List (Term j) → Term i lam : ∀ {j : Size< i} → String → Term j → Term i -- As explained before, a definitions is given by a list of equations infix 1 _by_ record Def : Set where constructor _by_ field name : String {arity} : ℕ equations : List⁺ (Vec (Pattern _) arity × (Term _)) ------------------------------------------------------------------------ -- A pretty printer for this language ------------------------------------------------------------------------ -- First we print patterns. We only wrap a pattern in parentheses if it -- is compound: i.e. if it is a constructor applied to a non-empty list -- of subpatterns -- Lists of patterns are printed separated by a single space. prettyPattern : ∀ {i} → Pattern i → Doc prettyPatterns : ∀ {i} → List (Pattern i) → Doc prettyPattern (var v) = text v prettyPattern (con c []) = text c prettyPattern (con c ps) = parens $ text c <+> prettyPatterns ps prettyPatterns = hsep ∘ List.map prettyPattern -- Next we print terms. The Bool argument tells us whether we are on -- the RHS of an application (in which case it is sensible to wrap -- complex subterms in parentheses). prettyTerm : ∀ {i} → Bool → Term i → Doc prettyTerm l (var v) = text v prettyTerm l (app f []) = text f prettyTerm l (app f es) = if l then parens else id $ text f <+> sep (List.map (prettyTerm true) es) prettyTerm l (lam x b) = if l then parens else id $ text "λ" <+> text x <> text "." <+> prettyTerm false b -- We now have all the pieces to print definitions. -- We print the equations below each other by using vcat. -- -- The LHS is printed as follows: the name of the function followed by -- the space-separated list of patterns (if any) and then an equal sign. -- -- The RHS is printed as a term which is *not* on the RHS of an application. -- -- Finally we can layout the definition in two different manners: -- * either LHS followed by RHS -- * or LHS followed and the RHS as a relative block (indented by 2 spaces) -- on the next line prettyDef : Def → Doc prettyDef (fun by eqs) = vcat $ List⁺.toList $ flip List⁺.map eqs $ uncurry $ λ ps e → let lhs = text fun <+> (case ps of λ where [] → text "=" _ → prettyPatterns (Vec.toList ps) <+> text "=") rhs = prettyTerm false e in lhs <+> rhs <|> lhs $$ (spaces 2 <> rhs) -- The pretty printer is obtained by using the renderer. pretty : Def → String pretty = render ∘ prettyDef ------------------------------------------------------------------------ -- Some examples ------------------------------------------------------------------------ -- Our first example is the identity function defined as a λ-abstraction `id : Def `id = "id" by ([] , lam "x" (var "x")) ∷ [] _ : pretty `id ≡ "id = λ x. x" _ = refl -- If we were to assume that this definition also takes a level (a) and -- a Set at that level (A) as arguments, we can have a slightly more complex -- definition like so. `explicitid : Def `explicitid = "id" by (var "a" ∷ var "A" ∷ [] , lam "x" (var "x")) ∷ [] _ : pretty `explicitid ≡ "id a A = λ x. x" _ = refl -- A more complex example: boolFilter, a function that takes a boolean -- predicate and a list as arguments and returns a list containing only -- the values that satisfy the predicate. -- We use nil and con for [] and _∷_ as our little toy language does not -- support infix notations. `filter : Def `filter = "boolFilter" by ( var "P?" ∷ con "nil" [] ∷ [] , app "nil" [] ) ∷ ( var "P?" ∷ con "con" (var "x" ∷ var "xs" ∷ []) ∷ [] , let rec = app "filter" (var "P?" ∷ var "xs" ∷ []) in app "if" (app "P?" (var "x" ∷ []) ∷ app "con" (var "x" ∷ rec ∷ []) ∷ rec ∷ []) ) ∷ [] _ : pretty `filter ≡ "boolFilter P? nil = nil \ \boolFilter P? (con x xs) = if (P? x) (con x (filter P? xs)) (filter P? xs)" _ = refl -- We can once more revisit this example with its more complex counterpart: -- boolFilter taking its level and set arguments explicitly (idem for the -- list constructors nil and con). -- This time laying out the second equation on a single line would produce a -- string larger than 80 characters long. So the pretty printer decides to -- make the RHS a relative block indented by 2 spaces. `explicitfilter : Def `explicitfilter = "boolFilter" by ( var "a" ∷ var "A" ∷ var "P?" ∷ con "nil" [] ∷ [] , app "nil" (var "a" ∷ var "A" ∷ []) ) ∷ ( var "a" ∷ var "A" ∷ var "P?" ∷ con "con" (var "x" ∷ var "xs" ∷ []) ∷ [] , let rec = app "filter" (var "a" ∷ var "A" ∷ var "P?" ∷ var "xs" ∷ []) in app "if" (app "P?" (var "x" ∷ []) ∷ app "con" (var "a" ∷ var "A" ∷ var "x" ∷ rec ∷ []) ∷ rec ∷ []) ) ∷ [] _ : pretty `explicitfilter ≡ "boolFilter a A P? nil = nil a A \ \boolFilter a A P? (con x xs) = \ \ if (P? x) (con a A x (filter a A P? xs)) (filter a A P? xs)" _ = refl
{ "alphanum_fraction": 0.5806004619, "avg_line_length": 34.1842105263, "ext": "agda", "hexsha": "64f46c8802fa7458833b6acdaebdefb1c3d1b156", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/README/Text/Pretty.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/README/Text/Pretty.agda", "max_line_length": 79, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/README/Text/Pretty.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": 1779, "size": 6495 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Automatic solvers for equations over naturals ------------------------------------------------------------------------ -- See README.Nat for examples of how to use this solver {-# OPTIONS --without-K --safe #-} module Data.Nat.Tactic.RingSolver where open import Agda.Builtin.Reflection open import Data.Maybe.Base using (just; nothing) open import Data.Nat.Base using (zero; suc) open import Data.Nat.Properties open import Level using (0ℓ) open import Data.Unit using (⊤) open import Relation.Binary.PropositionalEquality import Tactic.RingSolver as Solver import Tactic.RingSolver.Core.AlmostCommutativeRing as ACR ------------------------------------------------------------------------ -- A module for automatically solving propositional equivalences -- containing _+_ and _*_ ring : ACR.AlmostCommutativeRing 0ℓ 0ℓ ring = ACR.fromCommutativeSemiring *-+-commutativeSemiring λ { zero → just refl; _ → nothing } macro solve-∀ : Term → TC ⊤ solve-∀ = Solver.solve-∀-macro (quote ring) macro solve : Term → Term → TC ⊤ solve n = Solver.solve-macro n (quote ring)
{ "alphanum_fraction": 0.6135792121, "avg_line_length": 29.825, "ext": "agda", "hexsha": "ab5a38a74fdd0fb91d80278d237f1f9ceacf4ae0", "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/Nat/Tactic/RingSolver.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/Nat/Tactic/RingSolver.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/Nat/Tactic/RingSolver.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": 275, "size": 1193 }
module Data.List.Categorical where import Lvl open import Functional open import Function.Equals open import Data.List open import Data.List.Functions open import Data.List.Proofs open import Data.List.Equiv.Id open import Lang.Instance open import Logic open import Logic.Propositional open import Relator.Equals open import Relator.Equals.Proofs open import Structure.Setoid using (intro) open import Structure.Function open import Structure.Operator.Properties open import Structure.Relator.Properties open import Type open import Type.Category private variable ℓ : Lvl.Level instance map-functor : Functor{ℓ}(List) Functor.map ⦃ map-functor ⦄ = map _⊜_.proof (Function.congruence (Functor.map-function ⦃ map-functor ⦄) {x = f} {y = g} (intro proof)) = map-function-raw proof _⊜_.proof (Functor.op-preserving ⦃ map-functor ⦄) = map-preserves-[∘] _⊜_.proof (Functor.id-preserving ⦃ map-functor ⦄) = map-preserves-id instance concatMap-monad : Monad{ℓ}(List) Monad.η ⦃ concatMap-monad ⦄ _ = singleton Monad.ext ⦃ concatMap-monad ⦄ = concatMap _⊜_.proof (Function.congruence (Monad.ext-function ⦃ concatMap-monad ⦄) (intro proof)) {x} = concatMap-function-raw (proof) {x} Monad.ext-inverse ⦃ concatMap-monad ⦄ = intro concatMap-singleton Monad.ext-identity ⦃ concatMap-monad ⦄ = intro (identityᵣ(_++_)(∅)) Monad.ext-distribute ⦃ concatMap-monad ⦄ {f = f}{g = g} = intro (\{x} → concatMap-[∘] {f = f}{g = g}{x = x})
{ "alphanum_fraction": 0.7341597796, "avg_line_length": 37.2307692308, "ext": "agda", "hexsha": "76bc6ec0c41818de8351e7ccba5291bd766f505b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Data/List/Categorical.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Data/List/Categorical.agda", "max_line_length": 129, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Data/List/Categorical.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": 466, "size": 1452 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Util.Prelude module LibraBFT.Impl.OBM.ECP-LBFT-OBM-Diff.ECP-LBFT-OBM-Diff-0 where enabled : Bool enabled = true
{ "alphanum_fraction": 0.7669376694, "avg_line_length": 28.3846153846, "ext": "agda", "hexsha": "9a277d5f3f42cfdbd15bcf2de6159d6a0e0eca9f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_path": "src/LibraBFT/Impl/OBM/ECP-LBFT-OBM-Diff/ECP-LBFT-OBM-Diff-0.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_path": "src/LibraBFT/Impl/OBM/ECP-LBFT-OBM-Diff/ECP-LBFT-OBM-Diff-0.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_path": "src/LibraBFT/Impl/OBM/ECP-LBFT-OBM-Diff/ECP-LBFT-OBM-Diff-0.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 109, "size": 369 }
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module DiscriminationRules where open import Data.Bool.Base open import Data.List open import Data.Nat open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------------ true≢false : true ≢ false true≢false () 0≠suc : ∀ {n} → 0 ≢ suc n 0≠suc () []≢x∷xs : {A : Set}{x : A}{xs : List A} → [] ≢ x ∷ xs []≢x∷xs ()
{ "alphanum_fraction": 0.5, "avg_line_length": 23.9130434783, "ext": "agda", "hexsha": "557b5280df9977d3ccae851dd548683f7ab8064b", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "notes/discrimination-rules/DiscriminationRules.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "notes/discrimination-rules/DiscriminationRules.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "notes/discrimination-rules/DiscriminationRules.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": 144, "size": 550 }
module Everything where import Prelude import Stack import Syntax import Semantics import Convertibility import Correctness
{ "alphanum_fraction": 0.8582677165, "avg_line_length": 11.5454545455, "ext": "agda", "hexsha": "ff415639752045a3f9a51f1b7b15fc3b070a213f", "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": "54e9a83a8db4e33a33bf5dae5b2d651ad38aa3d5", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/nbe-correctness", "max_forks_repo_path": "src/Everything.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "54e9a83a8db4e33a33bf5dae5b2d651ad38aa3d5", "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/nbe-correctness", "max_issues_repo_path": "src/Everything.agda", "max_line_length": 23, "max_stars_count": 3, "max_stars_repo_head_hexsha": "54e9a83a8db4e33a33bf5dae5b2d651ad38aa3d5", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/nbe-correctness", "max_stars_repo_path": "src/Everything.agda", "max_stars_repo_stars_event_max_datetime": "2017-03-23T18:51:34.000Z", "max_stars_repo_stars_event_min_datetime": "2017-03-23T06:25:23.000Z", "num_tokens": 25, "size": 127 }
-- Axiomatic embedding of guarded recursion in Agda module guarded-recursion.embedding where open import guarded-recursion.prelude renaming (O to zero; S to suc) open Coe module M (▹_ : ∀ {a} → Type_ a → Type_ a) (▸ : ∀ {a} → ▹ (Type_ a) → Type_ a) (next : ∀ {a} {A : Type_ a} → A → ▹ A) (▸-rule : ∀ {a} {A : Type_ a} → ▸ (next A) ≡ ▹ A) (fix : ∀ {a} {A : Type_ a} → (▹ A → A) → A) (fix-rule : ∀ {a} {A : Type_ a} {f : ▹ A → A} → fix f ≡ f (next (fix f))) (_⊛′_ : ∀ {a b} {A : Type_ a} {B : Type_ b} → ▹ (A → B) → ▹ A → ▹ B) (_⊛_ : ∀ {a b} {A : Type_ a} {B : A → Type_ b} → ▹ ((x : A) → B x) → (x : ▹ A) → ▸ (next B ⊛′ x)) (fix-uniq : ∀ {a} {A : Type_ a} (u : A) f → u ≡ f (next u) → u ≡ fix f) (next⊛next : ∀ {a b} {A : Type_ a} {B : Type_ b} (f : A → B) (x : A) → next f ⊛′ next x ≡ next (f x)) where roll▸ : ∀ {a} {A : Type_ a} → ▹ A → ▸ (next A) roll▸ = coe! ▸-rule un▸ : ∀ {a} {A : Type_ a} → ▸ (next A) → ▹ A un▸ = coe ▸-rule ▹Fix : ∀ {a} → Type_ a → Type_ a ▹Fix X = (▹ X → X) → X ▹Endo : ∀ {a} → Type_ a → Type_ a ▹Endo X = ▹ X → X μ : ∀ {a} → Fix (Type_ a) μ F = fix (F ∘ ▸) un : ∀ {a f} → fix {A = Type_ a} f → f (next (fix f)) un = coe fix-rule unμ : ∀ {a} f → μ {a} f → f (▹ μ f) unμ {a} f x rewrite ! (▸-rule {A = μ f}) = un x roll : ∀ {a f} → f (next (fix f)) → fix {A = Type_ a} f roll = coe! fix-rule μ-rule : ∀ {a} f → μ {a} f ≡ f (▹ μ f) μ-rule f = fix-rule ∙ ap f (▸-rule {A = μ f}) rollμ : ∀ {a} f → f (▹ μ f) → μ {a} f rollμ f = coe! (μ-rule f) un₁ : ∀ {a b} {A : Type_ a} {f x} → fix {A = A → Type_ b} f x → f (next (fix f)) x un₁ = coe₁ fix-rule roll₁ : ∀ {a b} {A : Type_ a} {f x} → f (next (fix f)) x → fix {A = A → Type_ b} f x roll₁ = coe₁! fix-rule un₂ : ∀ {a b} {A : Type_ a} {B : Type_ b} {c f x y} → fix {A = A → B → Type_ c} f x y → f (next (fix f)) x y un₂ = coe₂ fix-rule roll₂ : ∀ {a b} {A : Type_ a} {B : Type_ b} {c f x y} → f (next (fix f)) x y → fix {A = A → B → Type_ c} f x y roll₂ = coe₂! fix-rule map▹ : ∀ {a b} {A : Type_ a} {B : Type_ b} → (A → B) → ▹ A → ▹ B map▹ f ▹x = next f ⊛′ ▹x {- alternatively _⊛′′_ : ∀ {a b} {A : Type_ a} {B : A → Type_ b} → ▹ ((x : A) → B x) → (x : A) → ▹ (B x) ▹f ⊛′′ x = map▹ (λ f → f x) ▹f -} {- alternatively _$_ : ∀ {a b} {A : Type_ a} (B : A → Type_ b) → ▹ A → ▹ (Type_ b) f $ ▹x = map▹ f ▹x -} ▹^ : ∀ {a} → ℕ → Type_ a → Type_ a ▹^ zero A = A ▹^ (suc n) A = ▹ ▹^ n A next^ : ∀ {a} {A : Type_ a} n → A → ▹^ n A next^ zero x = x next^ (suc n) x = next (next^ n x) map▹^ : ∀ {a b} {A : Type_ a} {B : Type_ b} n → (A → B) → ▹^ n A → ▹^ n B map▹^ zero f = f map▹^ (suc n) f = map▹ (map▹^ n f) module SimpleStream where F : Type → Type → Type F A X = A × X S : Type → Type S A = μ (F A) μ₁F' : ∀ {a} {A : Type_ a} → ((A → ▹ Type) → A → Type) → (▹(A → Type) → A → Type) μ₁F' F self = F (λ x → (self ⊛′ next x)) μ₁F : ∀ {a} {A : Type_ a} → ((A → Type) → A → Type) → (▹(A → Type) → A → Type) μ₁F F self = F (λ x → ▸ (self ⊛′ next x)) μ₁ : ∀ {a} {A : Type_ a} → ((A → Type) → A → Type) → A → Type μ₁ F = fix (μ₁F F) module μId where μid : Type μid = μ id μid-rule : μid ≡ ▹ μid μid-rule = fix-rule ∙ ▸-rule {A = μ id} ω : μid ω = fix (rollμ id) module CoNat where Coℕ : Type Coℕ = μ Maybe rollNat : Maybe (▹ Coℕ) → Coℕ rollNat = rollμ Maybe ze : Coℕ ze = rollNat nothing su : ▹ Coℕ → Coℕ su x = rollNat (just x) su′ : Coℕ → Coℕ su′ = su ∘ next ω : Coℕ ω = fix su module Neg where {- data X : Type where rollX : Fix X : (X → X) → X -} X : Type X = μ Endo rollX : Endo (▹ X) → X -- : (▹ X → ▹ X) → X rollX = rollμ Endo rollX′ : ▹(Endo X) → X -- : ▹(X → X) → X rollX′ = rollX ∘ _⊛′_ unX : X → Endo (▹ X) unX = unμ Endo -- δ = λ x → x x δ : X → ▹ X δ = λ x → (unX x) (next x) module Neg' where {- data X : Type where c : Fix X : ((X → X) → X) → X -} X : Type X = μ Fix rollX : Fix (▹ X) → X rollX = rollμ Fix unX : X → Fix (▹ X) unX = unμ Fix module μ₁Id where -- μ₁id = ▹∘▹∘…∘▹ -- μ₁id A = ▹ (▹ … (▹ A)) μ₁id : Type → Type μ₁id = μ₁ id betterfix₁ : ∀ {a} {A : Type_ a} {x : A} (F : Endo (A → Type)) → (▹ μ₁ F x → μ₁F F (next (μ₁ F)) x) → μ₁ F x betterfix₁ {a} {A} {x} F f = fix helper where helper : _ → _ helper self = roll₁ (f self) ▹ω-inh' : ∀ {A : Type} {x : A} (F : Endo (A → Type)) → (▸ (next (μ₁ F) ⊛′ next x) → μ₁F F (next (μ₁ F)) x) → μ₁ F x ▹ω-inh' {A} {x} F f = fix helper where helper : _ → _ helper self = roll₁ (f (coe! (ap ▸ (next⊛next (μ₁ F) x)) (roll▸ self))) ▹ω-inh : ∀ {A} → μ₁id A -- ▹ω-inh {A} = fix λ self → roll₁ (coe! (ap ▸ (next⊛next μ₁id A)) (roll▸ self)) ▹ω-inh {A} = betterfix₁ id (λ self → coe! (ap ▸ (next⊛next μ₁id A)) (roll▸ self)) -- ▹ω-inh {A} = fix λ self → {!!} -- (coe! (ap ▸ (next⊛next μ₁idω A)) (roll▸ self)) fix2 : ∀ {a} {A : Type_ a} → (▹ A → A) → A fix2 f = fix (f ∘ next ∘ f) fix≡fix2 : ∀ {a} {A : Type_ a} (f : ▹ A → A) → fix f ≡ fix2 f fix≡fix2 f = fix-uniq (fix f) (f ∘ next ∘ f) (fix-rule ∙ ap (f ∘ next) fix-rule) module Streams where F : Type → Type → Type F A X = A × X -- S : Type → Type -- S A = μ (F A) F^ : ℕ → Type → Type → Type F^ n A X = A × ▹^ n X S^ : ℕ → Type → Type S^ n A = μ (F^ n A) S : Type → Type S = S^ 0 S₂ = S^ 1 unS : ∀ {A} → S A → F A (▹ S A) unS = unμ (F _) rollS : ∀ {A} → F A (▹ S A) → S A rollS = rollμ (F _) unS^ : ∀ {A} n → S^ n A → F^ n A (▹ S^ n A) unS^ n = unμ (F^ n _) rollS^ : ∀ {A} n → F^ n A (▹ S^ n A) → S^ n A rollS^ n = rollμ (F^ n _) hd : ∀ {A} → S A → A hd = fst ∘ unS tl : ∀ {A} → S A → ▹ S A tl = snd ∘ unS cons : ∀ {A} n → A → ▹^ n (▹ (S^ n A)) → S^ n A cons n x xs = rollS^ n (x , xs) infixr 4 _∷_ _∷_ : ∀ {A} → A → ▹ (S A) → S A _∷_ = cons 0 infixr 4 _∷₂_ _∷₂_ : ∀ {A} → A → ▹^ 2 (S₂ A) → S₂ A x ∷₂ xs = roll (x , map▹ roll▸ xs) repeatS : ∀ {A} → A → S A repeatS x = fix λ x… → x ∷ x… module MapS {A B : Type} (f : A → B) where mapSf : ▹(S A → S B) → S A → S B mapSf self s = f (hd s) ∷ self ⊛′ tl s mapS : S A → S B mapS = fix mapSf mapS2f : ▹(S A → S B) → S A → S B mapS2f self s = f (hd s) ∷ map▹ (λ s' → f (hd s') ∷ self ⊛′ tl s') (tl s) mapS2f' : ▹(S A → S B) → S A → S B mapS2f' self = mapSf (next (mapSf self)) mapS2f≡mapS2f' : mapS2f ≡ mapS2f' mapS2f≡mapS2f' = idp mapS2 : S A → S B mapS2 = fix mapS2f mapS2' : S A → S B mapS2' = fix mapS2f' mapS2≡mapS2' : mapS2 ≡ mapS2' mapS2≡mapS2' = idp mapS2'' : S A → S B mapS2'' = fix2 mapSf mapS2≡mapS2'' : mapS2 ≡ mapS2'' mapS2≡mapS2'' = idp mapS≡mapS2 : mapS ≡ mapS2 mapS≡mapS2 = fix≡fix2 mapSf open MapS group2 : S ℕ → ▹ S₂ ℕ² group2 = fix λ self s → map▹ (λ tls → (hd s , hd tls) ∷₂ self ⊛′ tl tls) (tl s) ‼ : ∀ {A} → (n : ℕ) → S A → ▹^ n A ‼ zero = hd ‼ (suc n) = map▹ (‼ n) ∘ tl toFun : ∀ {A} → S A → (n : ℕ) → ▹^ n A toFun s n = ‼ n s fromFun : ∀ {A} → (ℕ → A) → S A fromFun {A} = fix λ self (f : ℕ → A) → f 0 ∷ self ⊛′ next (f ∘ suc) nats : S ℕ nats = fix λ self → 0 ∷ map▹ (mapS suc) self nats2 : S ℕ nats2 = fix λ self → 0 ∷ map▹ (mapS2 suc) self nats≡nats2 : nats ≡ nats2 nats≡nats2 rewrite mapS≡mapS2 suc = idp arrow : ▹ ℕ arrow = ‼ 1 nats module Sim {A : Type} (ℛ : A → A → Type) (ℛ-refl : Reflexive ℛ) where ≈F : ▹(S A × S A → Type) → S A × S A → Type ≈F X (xs , ys) = ℛ (hd xs) (hd ys) × ▸ ((map▹ curry X ⊛′ (tl xs)) ⊛′ tl ys) _≈_ : S A × S A → Type _≈_ = fix ≈F ≈-tail : ∀ {xs ys : S A} → _≈_ (xs , ys) → ▸ ((map▹ curry (next _≈_) ⊛′ tl xs) ⊛′ tl ys) ≈-tail pf = snd (un₁ pf) {- Does not work yet ≈-refl : Reflexive (curry _≈_) ≈-refl {x} = (fix λ pf x → roll₁ {f = ≈F} (ℛ-refl , helper pf x)) x where helper' : _ → _ → _ helper' pf x = map▹ (λ f → f x) pf helper : _ → _ → _ helper pf x = let r = helper' pf x in {!roll▸ r!} -} module DelayedStreams where data F (A : Type) (X : Type) : Type where done : F A X skip : X → F A X yield : A → X → F A X mapF : ∀ {A B X Y} → (A → B) → (X → Y) → F A X → F B Y mapF f g done = done mapF f g (skip x) = skip (g x) mapF f g (yield a x) = yield (f a) (g x) S : Type → Type S A = μ (F A) unS : ∀ {A} → S A → F A (▹ S A) unS = mapF id un▸ ∘ un rollS : ∀ {A} → F A (▹ S A) → S A rollS = roll ∘ mapF id roll▸ unfoldS : ∀ {A X} → (X → F A (▹ X)) → X → S A unfoldS coalg = fix λ self x → rollS (mapF id (λ x′ → self ⊛′ x′) (coalg x)) repeatS : ∀ {A} → A → S A repeatS x = fix λ self → rollS (yield x self) neverS : ∀ {A} → S A neverS = fix λ self → rollS (skip self) -- Co-algebra style... mapS : ∀ {A B} → (A → B) → S A → S B mapS {A} {B} f = unfoldS (mapF f id ∘ unS) filterF : ∀ {A X} → (A → 𝟚) → F A X → F A X filterF f done = done filterF f (skip xs) = skip xs filterF f (yield x xs) = if f x then yield x xs else skip xs filterS : ∀ {A} → (A → 𝟚) → S A → S A filterS f = unfoldS (filterF f ∘ unS) module FuelBased where fix : ∀ {a} {A : Type_ a} → ℕ → (A → A) → A fix zero f = STUCK where postulate STUCK : _ fix (suc n) f = f (fix n f) fix-rule : ∀ {a} {A : Type_ a} (n : ℕ) {f : A → A} → fix n f ≡ f (fix n f) fix-rule zero = ThisIsUnsafeButPlease.trustMe fix-rule (suc n) {f} = ap f (fix-rule n) fix-uniq : ∀ {a} {A : Type_ a} (n : ℕ) (u : A) f → u ≡ f u → u ≡ fix n f fix-uniq zero u f pf = ThisIsUnsafeButPlease.trustMe fix-uniq (suc n) u f pf = pf ∙ ap f (fix-uniq n u f pf) module I (n : ℕ) = M id id id idp (fix n) (fix-rule n) id id (fix-uniq n) (λ _ _ → idp) module HiddenFix {a} {A : Type_ a} (f : A → A) where -- This definition is not intended to termination-check. -- Use with care it's really easy to make the type-checker loop. {-# TERMINATING #-} fix : Hidden A fix = hide f (reveal fix) fix-rule : reveal fix ≡ f (reveal fix) fix-rule = idp {a} {A} {reveal fix} -- This definition is not intended to termination-check. -- Use with care it's really easy to make the type-checker loop. {-# TERMINATING #-} fix-uniq : (u : A) → u ≡ f u → u ≡ reveal fix fix-uniq u pf = pf ∙ ap f (fix-uniq u pf) ∙ ! fix-rule module Test where open HiddenFix open M id id id idp (reveal ∘ fix) (λ {_} {_} {f} → fix-rule f) id id (λ {_} {_} u f → fix-uniq f u) (λ _ _ → idp) public open Streams two : map▹ hd (tl nats) ≡ 1 two = idp -- -} -- -} -- -}
{ "alphanum_fraction": 0.4074679304, "avg_line_length": 28.4627906977, "ext": "agda", "hexsha": "032b45bdd2bd28a740e94c7aeee78fa902481476", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-11-16T16:21:54.000Z", "max_forks_repo_forks_event_min_datetime": "2015-08-19T12:37:53.000Z", "max_forks_repo_head_hexsha": "9fba7d89d8b27e9bb08c27df802608b5fff769e0", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "np/guarded-recursion", "max_forks_repo_path": "guarded-recursion/embedding.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9fba7d89d8b27e9bb08c27df802608b5fff769e0", "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": "np/guarded-recursion", "max_issues_repo_path": "guarded-recursion/embedding.agda", "max_line_length": 123, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9fba7d89d8b27e9bb08c27df802608b5fff769e0", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "np/guarded-recursion", "max_stars_repo_path": "guarded-recursion/embedding.agda", "max_stars_repo_stars_event_max_datetime": "2016-12-06T23:04:56.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-06T23:04:56.000Z", "num_tokens": 5158, "size": 12239 }
module Issue644 where postulate A : Set record R : Set₁ where field P : A → Set module M₁ (r : R) where postulate Foo₁ : ((x : A) → R.P r x) → Set module M₂ (r : R) where open R r postulate Foo₂ : ((x : A) → P x) → Set postulate r : R open R r open M₁ r open M₂ r foo₂ : Set foo₂ = Foo₂ r -- Error message should speak about -- -- (x : A) → P x -- -- not mention -- -- (x : A) → .Bug.M₂._.P r x
{ "alphanum_fraction": 0.5488372093, "avg_line_length": 11.3157894737, "ext": "agda", "hexsha": "8d9707cccdb77cd367efafc71d46ae37b8ebdceb", "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/Issue644.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/Issue644.agda", "max_line_length": 36, "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/Issue644.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": 171, "size": 430 }
{-# OPTIONS --without-K --safe #-} module Categories.Category.Instance.Properties.Setoids.CCC where open import Level open import Data.Product using (Σ ; _,_) open import Function.Equality as ⟶ using (Π; _⟶_) open import Relation.Binary using (Setoid) open import Categories.Category open import Categories.Category.Monoidal.Instance.Setoids open import Categories.Category.CartesianClosed open import Categories.Category.CartesianClosed.Canonical renaming (CartesianClosed to CCartesianClosed) open import Categories.Category.Instance.Setoids open Π module _ ℓ where private S = Setoids ℓ ℓ module S = Category S Setoids-Canonical : CCartesianClosed S Setoids-Canonical = record { ⊤ = ⊤ ; _×_ = _×_ ; ! = ! ; π₁ = π₁ ; π₂ = π₂ ; ⟨_,_⟩ = ⟨_,_⟩ ; !-unique = !-unique ; π₁-comp = λ {_ _ f _ g} → project₁ {h = f} {g} ; π₂-comp = λ {_ _ f _ g} → project₂ {h = f} {g} ; ⟨,⟩-unique = λ {_ _ _ f g h} → unique {h = h} {f} {g} ; _^_ = λ X Y → Y ⟶.⇨ X ; eval = λ {X Y} → record { _⟨$⟩_ = λ { (f , x) → f ⟨$⟩ x } ; cong = λ { (eq₁ , eq₂) → eq₁ eq₂ } } ; curry = λ {C A B} f → record { _⟨$⟩_ = λ c → record { _⟨$⟩_ = λ a → f ⟨$⟩ (c , a) ; cong = λ eq → cong f (Setoid.refl C , eq) } ; cong = λ eq₁ eq₂ → cong f (eq₁ , eq₂) } ; eval-comp = λ {_ _ _ f} → cong f ; curry-resp-≈ = λ eq₁ eq₂ eq → eq₁ (eq₂ , eq) ; curry-unique = λ eq₁ eq₂ eq → eq₁ (eq₂ , eq) } where open Setoids-Cartesian Setoids-CCC : CartesianClosed S Setoids-CCC = Equivalence.fromCanonical S Setoids-Canonical
{ "alphanum_fraction": 0.5497685185, "avg_line_length": 31.4181818182, "ext": "agda", "hexsha": "b56d2c9b5472ea9ad32092af498d9e97dcaecd31", "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": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-categories", "max_forks_repo_path": "src/Categories/Category/Instance/Properties/Setoids/CCC.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "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": "bblfish/agda-categories", "max_issues_repo_path": "src/Categories/Category/Instance/Properties/Setoids/CCC.agda", "max_line_length": 104, "max_stars_count": 5, "max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bblfish/agda-categories", "max_stars_repo_path": "src/Categories/Category/Instance/Properties/Setoids/CCC.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": 577, "size": 1728 }
module Lec8 where open import CS410-Prelude open import CS410-Functor open import CS410-Monoid open import CS410-Nat data Maybe (X : Set) : Set where yes : X -> Maybe X no : Maybe X maybeFunctor : Functor Maybe maybeFunctor = record { map = \ { f (yes x) -> yes (f x) ; f no -> no } ; mapid = \ { (yes x) -> refl ; no -> refl } ; mapcomp = \ { f g (yes x) -> refl ; f g no -> refl } } open Functor maybeFunctor data List (X : Set) : Set where -- X scopes over the whole declaration... [] : List X -- ...so you can use it here... _::_ : X -> List X -> List X -- ...and here. infixr 3 _::_ data Hutton : Set where val : Nat -> Hutton _+H_ : Hutton -> Hutton -> Hutton hif_then_else_ : Hutton -> Hutton -> Hutton -> Hutton fail : Hutton maybeApplicative : Applicative Maybe maybeApplicative = record { pure = yes ; _<*>_ = \ { no mx -> no ; (yes f) no -> no ; (yes f) (yes x) -> yes (f x) } ; identity = \ {(yes x) -> refl ; no -> refl} ; composition = \ { (yes f) (yes g) (yes x) -> refl ; (yes f) (yes g) no -> refl ; (yes x) no mx -> refl ; no mg mx -> refl } ; homomorphism = \ f x -> refl ; interchange = \ { (yes f) y -> refl ; no y → refl } } open Applicative maybeApplicative public cond : Nat -> Nat -> Nat -> Nat cond zero t e = e cond (suc c) t e = t _>>=_ : forall {X Y} -> Maybe X -> (X -> Maybe Y) -> Maybe Y yes x >>= x2my = x2my x no >>= x2my = no eval : Hutton -> Maybe Nat eval (val x) = pure x eval (h +H h') = pure _+N_ <*> eval h <*> eval h' eval (hif c then t else e) -- = pure cond <*> eval c <*> eval t <*> eval e -- oops = eval c >>= \ { zero -> eval e ; (suc _) -> eval t} eval fail = no foo : Hutton foo = hif val 1 then (val 2 +H val 3) else (hif val 0 then val 4 else val 6) goo : Hutton goo = hif val 1 then (val 2 +H val 3) else (hif val 0 then fail else val 6) ap : forall {X Y} -> Maybe (X -> Y) -> Maybe X -> Maybe Y ap mf mx = mf >>= \ f -> mx >>= \ x -> yes (f x)
{ "alphanum_fraction": 0.4629552114, "avg_line_length": 30.6282051282, "ext": "agda", "hexsha": "5931adde7d83016d1b98ebba83cb4dbd1da6d7d1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "clarkdm/CS410", "max_forks_repo_path": "Lec8.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "clarkdm/CS410", "max_issues_repo_path": "Lec8.agda", "max_line_length": 76, "max_stars_count": null, "max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "clarkdm/CS410", "max_stars_repo_path": "Lec8.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 722, "size": 2389 }
open import OutsideIn.Prelude open import OutsideIn.X module OutsideIn.Inference.Separator(x : X) where import OutsideIn.Constraints as C open C(x) open X(x) open import Data.List hiding (map) mutual data SeparatedConstraint (n : Set) : Shape → Set where SC : ∀ {s} → QConstraint n → Implications n s → SeparatedConstraint n s data Implications (n : Set) : Shape → Set where imp-ε : Implications n Nullary imp : ∀ {s} → Implication (λ n → SeparatedConstraint n s) n → Implications n (Unary s) _imp-∧_ : ∀ {s₁ s₂} → Implications n s₁ → Implications n s₂ → Implications n (Binary s₁ s₂) mutual data _simpl:_ {n : Set} : Constraint n Flat → QConstraint n → Set where Simpl-QC : ∀ {c} → QC c simpl: c Simpl-∧ : ∀ {a b}{a′ b′} → a simpl: a′ → b simpl: b′ → (a ∧′ b) simpl: (a′ ∧ b′) Simpl-Imp : ∀ {i} → Imp i simpl: ε data _separate:_,_ {n : Set} : Constraint n Flat → (r : Shape) → SeparatedConstraint n r → Set where Separate : ∀ {C}{Q}{r}{I} → C simpl: Q → C implic: r , I → C separate: r , SC Q I data _implic:_,_ {n : Set} : Constraint n Flat → (r : Shape) → Implications n r → Set where Implic-Qc : ∀ {c} → QC c implic: Nullary , imp-ε Implic-∧ : ∀{a b}{r₁ r₂}{a′}{b′} → a implic: r₁ , a′ → b implic: r₂ , b′ → (a ∧′ b) implic: Binary r₁ r₂ , (a′ imp-∧ b′) Implic-I : ∀{n}{Q}{C}{s}{v} → C separate: s , v → Imp (∃ n · Q ⊃ C) implic: Unary s , imp (∃ n · Q ⊃ v) simpl : ∀ {n} → (C : Constraint n Flat) → ∃ (λ Q → C simpl: Q) simpl (QC c) = _ , Simpl-QC simpl (a ∧′ b) with simpl a | simpl b ... | q₁ , p₁ | q₂ , p₂ = _ , Simpl-∧ p₁ p₂ simpl (Imp _) = _ , Simpl-Imp separate : ∀ {n} → (C : Constraint n Flat) → ∃ (λ r → ∃ (λ S → C separate: r , S)) implic : ∀ {n} → (C : Constraint n Flat) → ∃ (λ r → ∃ (λ I → C implic: r , I )) separate c with implic c | simpl c ... | s , v , p | q , p′ = _ , _ , Separate p′ p implic (QC c) = _ , _ , Implic-Qc implic (a ∧′ b) with implic a | implic b ... | s , v , p | s′ , v′ , p′ = _ , _ , Implic-∧ p p′ implic (Imp (∃ n · Q ⊃ C)) with separate C ... | s , v , p = _ , _ , Implic-I p -- Substitution for separated constraints substituteSep : ∀ {s}{a b} → (a → Type b) → SeparatedConstraint a s → SeparatedConstraint b s substituteImp : ∀ {s}{a b} → (a → Type b) → Implications a s → Implications b s substituteSep f (SC qc imps) = SC (qc-substitute f qc) (substituteImp f imps) where open Monad (type-is-monad) open Functor (type-is-functor) substituteImp f (imp-ε) = imp-ε substituteImp {Unary s} f (imp (∃ n · Q ⊃ C)) = imp (∃ n · constraint-types (join ∘ map f) Q ⊃ substituteSep f′ C) where module PlusN-f = Functor (Monad.is-functor (PlusN-is-monad {n})) open Monad (type-is-monad) open Functor (type-is-functor) f′ = sequence-PlusN {n = n} ⦃ type-is-monad ⦄ ∘ PlusN-f.map f substituteImp f (a imp-∧ b) = substituteImp f a imp-∧ substituteImp f b
{ "alphanum_fraction": 0.558496732, "avg_line_length": 51, "ext": "agda", "hexsha": "2222cc8169baf9b81a23e491999280ae5ddd70af", "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/Inference/Separator.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/Inference/Separator.agda", "max_line_length": 127, "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/Inference/Separator.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": 1102, "size": 3060 }
-- submitted by Nisse, 2011-06-21 module Issue423 where ------------------------------------------------------------------------ -- Prelude data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x record Σ (A : Set) (B : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ -- Andreas: changed lhs variables to lambda-abstractions -- This should be done automatically (internally). curry : {A C : Set} {B : A → Set} → (Σ A B → C) → ((x : A) → B x → C) curry f = \ x y -> f (x , y) uncurry : {A C : Set} {B : A → Set} → ((x : A) → (y : B x) → C) → (Σ A B → C) uncurry f = \ p -> f (Σ.proj₁ p) (Σ.proj₂ p) ------------------------------------------------------------------------ -- Preliminaries postulate U : Set El : U → Set mutual data Ctxt : Set where _▻_ : (Γ : Ctxt) (σ : Type Γ) → Ctxt Type : Ctxt → Set Type Γ = Env Γ → U Env : Ctxt → Set Env (Γ ▻ σ) = Σ (Env Γ) λ γ → El (σ γ) postulate Γ : Ctxt σ : Type Γ ------------------------------------------------------------------------ -- Problem -- The following equality holds definitionally. equal : (τ : (γ : Env Γ) → El (σ γ) → U) → curry (uncurry τ) ≡ τ equal τ = refl -- Bug was: -- However, the two sides behave differently. works : (τ₁ τ₂ : (γ : Env Γ) → El (σ γ) → U) → τ₁ ≡ τ₂ → Set₁ works τ .τ refl = Set works′ : (τ₁ τ₂ : (γ : Env Γ) → El (σ γ) → U) → curry (uncurry τ₁) ≡ τ₂ → Set₁ works′ τ .τ refl = Set fails : (τ₁ τ₂ : (γ : Env Γ) → El (σ γ) → U) → τ₁ ≡ curry (uncurry τ₂) → Set₁ fails τ .τ refl = Set fails′ : (τ₁ τ₂ : (γ : Env Γ) → El (σ γ) → U) → curry (uncurry τ₁) ≡ curry (uncurry τ₂) → Set₁ fails′ τ .τ refl = Set -- Bug was: -- I find it interesting that works′ works, whereas the symmetric -- variant fails fails.
{ "alphanum_fraction": 0.4703947368, "avg_line_length": 22.8, "ext": "agda", "hexsha": "a4f6bfc3558072214e30521b5ebf3a1c06fe42b6", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "test/succeed/Issue423.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "test/succeed/Issue423.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/Issue423.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": 640, "size": 1824 }
module Oscar.Category.Category where open import Oscar.Category.Setoid open import Oscar.Category.Semigroupoid open import Oscar.Level module _ {𝔬 𝔪 𝔮} (semigroupoid : Semigroupoid 𝔬 𝔪 𝔮) where open Semigroupoid semigroupoid record IsCategory (ε : ∀ {x} → x ↦ x) : Set (𝔬 ⊔ 𝔪 ⊔ 𝔮) where instance _ = IsSetoid↦ field left-identity : ∀ {x y} (f : x ↦ y) → ε ∙ f ≋ f right-identity : ∀ {x y} (f : x ↦ y) → f ∙ ε ≋ f open IsCategory ⦃ … ⦄ public record Category 𝔬 𝔪 𝔮 : Set (lsuc (𝔬 ⊔ 𝔪 ⊔ 𝔮)) where constructor _,_ field semigroupoid : Semigroupoid 𝔬 𝔪 𝔮 open Semigroupoid semigroupoid public field ε : ∀ {x} → x ↦ x ⦃ isCategory ⦄ : IsCategory semigroupoid ε open IsCategory isCategory public
{ "alphanum_fraction": 0.6448598131, "avg_line_length": 23.40625, "ext": "agda", "hexsha": "b826af997fb5b534ac60280c8fc7a169e85ba296", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-2/Oscar/Category/Category.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-2/Oscar/Category/Category.agda", "max_line_length": 63, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-2/Oscar/Category/Category.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 297, "size": 749 }
module Diff where open import Data.Nat using (ℕ; zero; suc) open import Data.Float open import Function using (_∘_) postulate post : ∀ {a} {A : Set a} → A -- Need to generalize for bilinear forms data _Is_DiffAt_ (f : Float → Float) : ℕ → Float → Set where continuous : ∀ x → f Is zero DiffAt x d : ∀ f' {n} x → f' Is n DiffAt x → f Is suc n DiffAt x data D (A : Set) : ℕ → A → Set where -- +-diff : ∀ {x} {n} → HasDeriv (x +_) n -- +-diff {x} {zero} = d⁰ -- +-diff {x} {suc n} = d (x +_) (+-diff {x} {n}) instance chain : ∀ {f g n x} → ⦃ f Is n DiffAt x ⦄ → ⦃ g Is n DiffAt g x ⦄ → (f ∘ g) Is n DiffAt x chain = post -‿diff : ∀ {n x} → -_ Is n DiffAt x -‿diff {zero} {x} = continuous x -‿diff {suc n} {x} = d -_ x -‿diff exp-diff : ∀ {n x} → e^_ Is n DiffAt x exp-diff {zero} {x} = continuous x exp-diff {suc n} {x} = d e^_ x exp-diff mutual sin-diff : ∀ {n x} → sin Is n DiffAt x sin-diff {zero} {x} = continuous x sin-diff {suc n} {x} = d cos x cos-diff cos-diff : ∀ {n x} → cos Is n DiffAt x cos-diff {zero} {x} = continuous x cos-diff {suc n} {x} = d (-_ ∘ sin) x (chain { -_} {sin}) -- (chain -_ sin) ∂ : ∀ f x → ⦃ f Is 1 DiffAt x ⦄ → Float ∂ f x ⦃ d f' x _ ⦄ = f' x syntax ∂ (λ x → fx) y = ∂ fx /∂ x at y test : Float → Float test y = ∂ (cos (e^ x)) /∂ x at y -- -- run : (∀ {n} → F₁) → F₁ -- -- run f x = f {zero} x
{ "alphanum_fraction": 0.5215208034, "avg_line_length": 23.2333333333, "ext": "agda", "hexsha": "ccd55c9da1a16c79519fdab3323a8084e7befe6a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "78c3dec24834ffeca5e74cb75578e9b210a5be62", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "cspollard/diff", "max_forks_repo_path": "src/Diff.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "78c3dec24834ffeca5e74cb75578e9b210a5be62", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "cspollard/diff", "max_issues_repo_path": "src/Diff.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "78c3dec24834ffeca5e74cb75578e9b210a5be62", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "cspollard/diff", "max_stars_repo_path": "src/Diff.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 611, "size": 1394 }
-- New NO_POSITIVITY_CHECK pragma for data definitions and mutual -- blocks -- Skipping an old-style mutual block: Before the `mutual` keyword. {-# NO_POSITIVITY_CHECK #-} mutual data Cheat : Set where cheat : Oops → Cheat data Oops : Set where oops : (Cheat → Cheat) → Oops
{ "alphanum_fraction": 0.6989619377, "avg_line_length": 24.0833333333, "ext": "agda", "hexsha": "a736a7f8c95d333e87fb9dd17b6171eebae7de75", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue1614c.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/Issue1614c.agda", "max_line_length": 67, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue1614c.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 77, "size": 289 }
------------------------------------------------------------------------ -- The Agda standard library -- -- The free monad construction on indexed containers ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe --guardedness #-} module Data.Container.Indexed.FreeMonad where open import Level open import Function hiding (const) open import Category.Monad.Predicate open import Data.Container.Indexed open import Data.Container.Indexed.Combinator hiding (id; _∘_) open import Data.Empty open import Data.Sum using (inj₁; inj₂) open import Data.Product open import Data.W.Indexed open import Relation.Unary open import Relation.Unary.PredicateTransformer open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------ infixl 9 _⋆C_ infix 9 _⋆_ _⋆C_ : ∀ {i o c r} {I : Set i} {O : Set o} → Container I O c r → Pred O c → Container I O _ _ C ⋆C X = const X ⊎ C _⋆_ : ∀ {ℓ} {O : Set ℓ} → Container O O ℓ ℓ → Pt O ℓ C ⋆ X = μ (C ⋆C X) pattern returnP x = (inj₁ x , _) pattern doP c k = (inj₂ c , k) inn : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} {X} → ⟦ C ⟧ (C ⋆ X) ⊆ C ⋆ X inn (c , k) = sup (doP c k) rawPMonad : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} → RawPMonad {ℓ = ℓ} (_⋆_ C) rawPMonad {C = C} = record { return? = return ; _=<?_ = _=<<_ } where return : ∀ {X} → X ⊆ C ⋆ X return x = sup (inj₁ x , ⊥-elim ∘ lower) _=<<_ : ∀ {X Y} → X ⊆ C ⋆ Y → C ⋆ X ⊆ C ⋆ Y f =<< sup (returnP x) = f x f =<< sup (doP c k) = inn (c , λ r → f =<< k r) leaf : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} {X : Pred O ℓ} → ⟦ C ⟧ X ⊆ C ⋆ X leaf (c , k) = inn (c , return? ∘ k) where open RawPMonad rawPMonad generic : ∀ {ℓ} {O : Set ℓ} {C : Container O O ℓ ℓ} {o} (c : Command C o) → o ∈ C ⋆ (⋃[ r ∶ Response C c ] { next C c r }) generic c = inn (c , λ r → return? (r , refl)) where open RawPMonad rawPMonad
{ "alphanum_fraction": 0.5157736605, "avg_line_length": 28.9420289855, "ext": "agda", "hexsha": "7cf942c36ee00733c05c086819bddcea8d6c5cc2", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Indexed/FreeMonad.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Indexed/FreeMonad.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Indexed/FreeMonad.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 730, "size": 1997 }
module _ where open import Agda.Builtin.Nat postulate T : Set C₁ : Set instance I₁ : C₁ C₂ : Nat → Set instance I₂ : ∀ {n} → C₂ n it : {A : Set} {{_ : A}} → A it {{x}} = x postulate f₁ : {{_ : Nat → C₁}} → T f₂ : {{_ : ∀ n → C₂ n}} → T works₁ : T works₁ = f₁ -- f₁ {{λ _ → I₁}} fails₁ : T fails₁ = f₁ {{it}} -- internal error works₂ : T works₂ = f₂ -- f₂ {{λ n → I₂ {n}}} fails₂ : T fails₂ = f₂ {{it}} -- internal error
{ "alphanum_fraction": 0.4967602592, "avg_line_length": 14.0303030303, "ext": "agda", "hexsha": "3357c25663b1f4817b1c9330e2f6b62525983202", "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/Issue2034.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/Issue2034.agda", "max_line_length": 42, "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/Issue2034.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": 196, "size": 463 }
module UniDB.Subst.Pair where open import UniDB.Subst.Core open import UniDB.Morph.Pair instance iLkPair : {T : STX} {{apTT : Ap T T}} {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} → Lk T (Pair Ξ Ζ) lk {{iLkPair {T}}} (ξ ⊗ ζ) i = ap {T} ζ (lk {T} ξ i) iLkRenPair : {T : STX} {{vrT : Vr T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} {Ξ : MOR} {{lkIxΞ : Lk Ix Ξ}} {{lkTΞ : Lk T Ξ}} {{lkRenTΞ : LkRen T Ξ}} {Ζ : MOR} {{lkIxΖ : Lk Ix Ζ}} {{lkTΖ : Lk T Ζ}} {{lkRenTΖ : LkRen T Ζ}} {{upΖ : Up Ζ}} → LkRen T (Pair Ξ Ζ) lk-ren {{iLkRenPair {T} {Ξ} {Ζ}}} (ξ ⊗ ζ) i = begin ap {T} ζ (lk {T} ξ i) ≡⟨ cong (ap {T} ζ) (lk-ren {T} ξ i) ⟩ ap {T} ζ (vr (lk {Ix} ξ i)) ≡⟨ ap-vr {T} ζ (lk {Ix} ξ i) ⟩ lk {T} ζ (lk {Ix} ξ i) ≡⟨ lk-ren {T} ζ (lk {Ix} ξ i) ⟩ vr (lk {Ix} ζ (lk {Ix} ξ i)) ∎ iLkHCompPair : {T : STX} {{vrT : Vr T}} {{apTT : Ap T T}} {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} → LkHCompAp T Ξ Ζ (Pair Ξ Ζ) lk-⊡-ap {{iLkHCompPair}} ξ ζ i = refl iLkUpPairRenaming : (T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} (Ξ : MOR) {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{lkUpTΞ : LkUp T Ξ}} {{lkIxΞ : Lk Ix Ξ}} {{lkRenTΞ : LkRen T Ξ}} {{lkUpIxΞ : LkUp Ix Ξ}} (Ζ : MOR) {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {{lkUpTΖ : LkUp T Ζ}} → LkUp T (Pair Ξ Ζ) lk-↑₁-zero {{iLkUpPairRenaming T Ξ Ζ}} (ξ ⊗ ζ) = begin ap {T} (ζ ↑₁) (lk {T} (ξ ↑₁) zero) ≡⟨ cong (ap {T} (ζ ↑₁)) (lk-↑₁-zero ξ) ⟩ ap {T} (ζ ↑₁) (vr zero) ≡⟨ ap-vr {T} (ζ ↑₁) zero ⟩ lk (ζ ↑₁) zero ≡⟨ lk-↑₁-zero ζ ⟩ vr zero ∎ lk-↑₁-suc {{iLkUpPairRenaming T Ξ Ζ}} (ξ ⊗ ζ) i = begin ap {T} (ζ ↑₁) (lk (ξ ↑₁) (suc i)) ≡⟨ cong (ap {T} (ζ ↑₁)) (lk-ren (ξ ↑₁) (suc i)) ⟩ ap {T} (ζ ↑₁) (vr (lk (ξ ↑₁) (suc i))) ≡⟨ ap-vr {T} (ζ ↑₁) (lk (ξ ↑₁) (suc i)) ⟩ lk (ζ ↑₁) (lk (ξ ↑₁) (suc i)) ≡⟨ cong (lk (_↑₁ ζ)) (lk-↑₁-suc ξ i) ⟩ lk (ζ ↑₁) (suc (lk ξ i)) ≡⟨ lk-↑₁-suc ζ (lk ξ i) ⟩ wk₁ (lk ζ (lk ξ i)) ≡⟨ cong wk₁ (sym (ap-vr {T} ζ (lk ξ i))) ⟩ wk₁ (ap {T} ζ (vr (lk ξ i))) ≡⟨ cong wk₁ (cong (ap {T} ζ) (sym (lk-ren ξ i))) ⟩ wk₁ (ap {T} ζ (lk ξ i)) ∎ iLkUpPairSubstitution : (T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} (Ξ : MOR) {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{lkUpTΞ : LkUp T Ξ}} (Ζ : MOR) {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {{lkUpTΖ : LkUp T Ζ}} (ap-wk₁-TΖ : {γ₁ γ₂ : Dom} (ζ : Ζ γ₁ γ₂) (t : T γ₁) → ap {T} (ζ ↑₁) (wk₁ t) ≡ wk₁ (ap {T} ζ t)) → LkUp T (Pair Ξ Ζ) lk-↑₁-zero {{iLkUpPairSubstitution T Ξ Ζ ap-wk₁-TΖ}} (ξ ⊗ ζ) = begin ap {T} (ζ ↑₁) (lk (ξ ↑₁) zero) ≡⟨ cong (ap {T} (ζ ↑₁)) (lk-↑₁-zero ξ) ⟩ ap {T} (ζ ↑₁) (vr zero) ≡⟨ ap-vr {T} (ζ ↑₁) zero ⟩ lk (ζ ↑₁) zero ≡⟨ lk-↑₁-zero ζ ⟩ vr zero ∎ lk-↑₁-suc {{iLkUpPairSubstitution T Ξ Ζ ap-wk₁-TΖ}} (ξ ⊗ ζ) i = begin ap {T} (ζ ↑₁) (lk (ξ ↑₁) (suc i)) ≡⟨ cong (ap {T} (ζ ↑₁)) (lk-↑₁-suc ξ i) ⟩ ap {T} (ζ ↑₁) (wk₁ (lk ξ i)) ≡⟨ ap-wk₁-TΖ ζ (lk ξ i) ⟩ wk₁ (ap {T} ζ (lk ξ i)) ∎ instance iLkUpPair : {T : STX} {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} {{apWkTT : ApWk T T}} {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{lkUpTΞ : LkUp T Ξ}} {Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {{lkUpTΖ : LkUp T Ζ}} → LkUp T (Pair Ξ Ζ) iLkUpPair {T} {Ξ} {Ζ} = iLkUpPairSubstitution T Ξ Ζ (ap-wk₁ {T}) record ApPair (T : STX) {{apTT : Ap T T}} (X : STX) {{apTX : Ap T X}} : Set₁ where field ap-pair : {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {γ₁ γ₂ γ₃ : Dom} (ξ : Ξ γ₁ γ₂) (ζ : Ζ γ₂ γ₃) (x : X γ₁) → ap {T} (ξ ⊗ ζ) x ≡ ap {T} ζ (ap {T} ξ x) open ApPair {{...}} public instance iApPairIxIx : ApPair Ix Ix ap-pair {{iApPairIxIx}} {Ξ} ξ ζ i = refl
{ "alphanum_fraction": 0.4424800797, "avg_line_length": 43.652173913, "ext": "agda", "hexsha": "0bbaae82dcf94a68e789fc714e7253495037fce7", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "skeuchel/unidb-agda", "max_forks_repo_path": "UniDB/Subst/Pair.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "skeuchel/unidb-agda", "max_issues_repo_path": "UniDB/Subst/Pair.agda", "max_line_length": 92, "max_stars_count": null, "max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "skeuchel/unidb-agda", "max_stars_repo_path": "UniDB/Subst/Pair.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2246, "size": 4016 }
-- This file is the source Agda file -- Edit this file not Common.hs -- The warning below will be written to Common.hs {- Description : Property based testing Name Utilities This file contains various naming related utilities used for generating Zerepoch Core types and terms. -} module ZerepochCore.Generators.NEAT.Common where -- warning to be written to Haskell file: {-# FOREIGN AGDA2HS {- !!! THIS FILE IS GENERATED FROM Common.agda !!! DO NOT EDIT THIS FILE. EDIT Common.agda !!! AND THEN RUN agda2hs ON IT. -} #-} {-# FOREIGN AGDA2HS {-# LANGUAGE EmptyCase #-} {-# LANGUAGE EmptyDataDeriving #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} import Control.Enumerable import qualified Data.Stream as Stream import qualified Data.Text as Text import ZerepochCore.Name (Name, TyName (..)) import ZerepochCore.Quote (MonadQuote (..), freshName) #-} -- * Enumerating deBruijn indices -- empty type data Z : Set where {-# COMPILE AGDA2HS Z deriving (Eq, Ord, Show) #-} -- maybe type data S (n : Set) : Set where FZ : S n FS : n → S n {-# COMPILE AGDA2HS S deriving (Eq, Ord, Show, Functor) #-} {-# FOREIGN AGDA2HS instance Enumerable Z where enumerate = datatype [] instance Enumerable n => Enumerable (S n) where enumerate = share $ aconcat [ c0 FZ , c1 FS ] -- |Absurd for the zero type. fromZ :: Z -> a fromZ i = case i of {} -- * Namespaces data NameState n = NameState { nameOf :: n -> Name, freshNameStrings :: Stream.Stream Text.Text } newtype TyNameState n = TyNameState (NameState n) tynameOf :: TyNameState n -> n -> TyName tynameOf (TyNameState NameState{..}) i = TyName (nameOf i) -- |Create an empty name state from a stream of text names. emptyNameState :: Stream.Stream Text.Text -> NameState Z emptyNameState strs = NameState { nameOf = fromZ, freshNameStrings = strs } -- |Extend name state with a fresh name. extNameState :: (MonadQuote m) => NameState n -> m (NameState (S n)) extNameState NameState{..} = liftQuote $ do let str = Stream.head freshNameStrings freshNameStrings' = Stream.tail freshNameStrings name <- freshName str let nameOf' FZ = name nameOf' (FS i) = nameOf i return NameState { nameOf = nameOf', freshNameStrings = freshNameStrings' } -- |Create an empty name state from a stream of text names. emptyTyNameState :: Stream.Stream Text.Text -> TyNameState Z emptyTyNameState strs = TyNameState (emptyNameState strs) -- |Extend type name state with a fresh type name. extTyNameState :: (MonadQuote m) => TyNameState n -> m (TyNameState (S n)) extTyNameState (TyNameState nameState) = TyNameState <$> extNameState nameState -- |Create a stream of names |x0, x1, x2, ...| from a prefix |"x"| mkTextNameStream :: Text.Text -> Stream.Stream Text.Text mkTextNameStream prefix = Stream.map (\n -> prefix <> Text.pack (show n)) (Stream.iterate (+1) (0 :: Integer)) #-}
{ "alphanum_fraction": 0.6816232267, "avg_line_length": 27.3063063063, "ext": "agda", "hexsha": "6e79288fbb471478f7cdc81f9d1e6e43ec6981fb", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-02-21T16:38:59.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-13T21:25:19.000Z", "max_forks_repo_head_hexsha": "c8cf4619e6e496930c9092cf6d64493eff300177", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "Quantum-One-DLT/zerepoch", "max_forks_repo_path": "zerepoch-core/generators/ZerepochCore/Generators/NEAT/Common.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c8cf4619e6e496930c9092cf6d64493eff300177", "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": "Quantum-One-DLT/zerepoch", "max_issues_repo_path": "zerepoch-core/generators/ZerepochCore/Generators/NEAT/Common.agda", "max_line_length": 97, "max_stars_count": null, "max_stars_repo_head_hexsha": "c8cf4619e6e496930c9092cf6d64493eff300177", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "Quantum-One-DLT/zerepoch", "max_stars_repo_path": "zerepoch-core/generators/ZerepochCore/Generators/NEAT/Common.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 833, "size": 3031 }
-- AIM XXXV, 2022-05-06, issue #5891: -- SizeUniv : SizeUniv was causing non-termination and inhabitation of Size< 0. -- This is inconsistent; proof by Jonathan Chan. {-# OPTIONS --sized-types #-} open import Agda.Primitive open import Agda.Builtin.Size data ⊥ : Set where -- Original exploit: -- data False : SizeUniv where False : SizeUniv False = (X : SizeUniv) → X -- Should fail. -- Expected error: -- Setω != SizeUniv -- when checking that the expression (X : SizeUniv) → X has type SizeUniv -- Step 1: Hurken's Paradox with SizeUniv : SizeUniv. ℘ : SizeUniv → SizeUniv ℘ S = S → SizeUniv U : SizeUniv U = ∀ (X : SizeUniv) → (℘ (℘ X) → X) → ℘ (℘ X) τ : ℘ (℘ U) → U τ t = λ X f p → t (λ x → p (f (x X f))) σ : U → ℘ (℘ U) σ s = s U τ Δ : ℘ U Δ y = (∀ p → σ y p → p (τ (σ y))) → False Ω : U Ω = τ (λ p → (∀ x → σ x p → p x)) R : ∀ p → (∀ x → σ x p → p x) → p Ω R _ 𝟙 = 𝟙 Ω (λ x → 𝟙 (τ (σ x))) M : ∀ x → σ x Δ → Δ x M _ 𝟚 𝟛 = 𝟛 Δ 𝟚 (λ p → 𝟛 (λ y → p (τ (σ y)))) L : (∀ p → (∀ x → σ x p → p x) → p Ω) → False L 𝟘 = 𝟘 Δ M (λ p → 𝟘 (λ y → p (τ (σ y)))) -- Prevent unfolding, as this term has no whnf. -- Stops Agda from looping. abstract false : False false = L R -- This gives us a predecessor on Size. size-pred : ∀ i → Size< i size-pred i = false (Size< i) -- Step 2: Size predecessor is inconsistent. -- Jonathan Chan: -- I managed to do so using ∞ but only because it's the only closed -- size expression, not using the ∞ < ∞ property, although the -- principle is the same as for #3026: data _>_ (s : Size) : Size → Set where lt : (r : Size< s) → s > r data Acc (s : Size) : Set where acc : (∀ {r} → s > r → Acc r) → Acc s wf : ∀ s → Acc s wf s = acc λ{ (lt r) → wf r } ¬wf : ∀ s → Acc s → ⊥ ¬wf s (acc p) = ¬wf (size-pred s) (p (lt (size-pred s))) absurd : ⊥ absurd = (¬wf ∞) (wf ∞)
{ "alphanum_fraction": 0.556407448, "avg_line_length": 21.2325581395, "ext": "agda", "hexsha": "370dc712a9c8c14c45094a8eb263e146e68ab246", "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/Issue5891.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/Issue5891.agda", "max_line_length": 79, "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/Issue5891.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 745, "size": 1826 }
{-# OPTIONS --cubical #-} module Demos.Live where
{ "alphanum_fraction": 0.6538461538, "avg_line_length": 10.4, "ext": "agda", "hexsha": "f30a6134e0cd1f6ec962519d71f44b9639200ee5", "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": "Demos/Live.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": "Demos/Live.agda", "max_line_length": 25, "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": "Demos/Live.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": 13, "size": 52 }
module Issue784.RefAPI where open import Issue784.Values public hiding (seq) open import Issue784.Context -- that should be private open import Issue784.Transformer public open import Data.List public using (List; []; _∷_; [_]) open import Data.Nat open import Relation.Binary.PropositionalEquality.TrustMe private postulate _seq_ : ∀ {a b} {A : Set a} {B : Set b} → A → B → B nativeRef : (A : Set) → Set -- create new reference and initialize it with passed value nativeNew-ℕ : ℕ → nativeRef ℕ -- increment value in place nativeInc-ℕ : nativeRef ℕ → Unit nativeGet-ℕ : nativeRef ℕ → ℕ nativeFree-ℕ : nativeRef ℕ → Unit data Exact {ℓ} {A : Set ℓ} : A → Set ℓ where exact : ∀ a → Exact a getExact : ∀ {ℓ} {A : Set ℓ} {a : A} → Exact a → A getExact (exact a) = a ≡-exact : ∀ {ℓ} {A : Set ℓ} {a : A} (e : Exact a) → getExact e ≡ a ≡-exact (exact a) = refl Ref-ℕ : ℕ → Set Ref-ℕ a = Σ[ native ∈ nativeRef ℕ ] nativeGet-ℕ native ≡ a private -- making these private to avoid further using -- which may lead to inconsistency proofNew-ℕ : ∀ a → Ref-ℕ a proofNew-ℕ a = nativeNew-ℕ a , trustMe proofInc-ℕ : ∀ {a} → Ref-ℕ a → Ref-ℕ (suc a) proofInc-ℕ (r , _) = (nativeInc-ℕ r) seq (r , trustMe) proofGet-ℕ : ∀ {a} → Ref-ℕ a → Exact a proofGet-ℕ (r , p) = ≡-elim′ Exact p (exact $ nativeGet-ℕ r) proofFree-ℕ : {a : ℕ} → Ref-ℕ a → Unit proofFree-ℕ (r , _) = nativeFree-ℕ r new-ℕ : ∀ a n → Transformer! [] [(n , Unique (Ref-ℕ a))] new-ℕ a n ctx nr-v []⊆v nr-v∪n = context w , (≡⇒≋ $ ≡-trans p₁ p₂) where v = Context.get ctx w = v ∪ [(n , Unique (Ref-ℕ a) , unique (proofNew-ℕ a))] p₁ : types (v ∪ [(n , Unique (Ref-ℕ a) , _)]) ≡ types v ∪ [(n , Unique (Ref-ℕ a))] p₁ = t-x∪y v [(n , Unique (Ref-ℕ a) , _)] p₂ : types v ∪ [(n , Unique (Ref-ℕ a))] ≡ types v ∖∖ [] ∪ [(n , Unique (Ref-ℕ a))] p₂ = ≡-cong (λ x → x ∪ [(n , Unique (Ref-ℕ a))]) (≡-sym $ t∖[]≡t $ types v) inc-ℕ : ∀ {a} n → Transformer! [(n , Unique (Ref-ℕ a))] [(n , Unique (Ref-ℕ (suc a)))] inc-ℕ {a} n ctx nr-v n⊆v nr-v∪n = context w , (≡⇒≋ $ ≡-trans p₁ p₂) where v = Context.get ctx r = unique ∘ proofInc-ℕ ∘ Unique.get ∘ getBySignature ∘ n⊆v $ here refl w = v ∖∖ [ n ] ∪ [(n , Unique (Ref-ℕ $ suc a) , r)] p₁ : types (v ∖∖ [ n ] ∪ [(n , Unique (Ref-ℕ $ suc a) , r)]) ≡ types (v ∖∖ [ n ]) ∪ [(n , Unique (Ref-ℕ $ suc _))] p₁ = t-x∪y (v ∖∖ [ n ]) _ p₂ : types (v ∖∖ [ n ]) ∪ [(n , Unique (Ref-ℕ $ suc a))] ≡ types v ∖∖ [ n ] ∪ [(n , Unique (Ref-ℕ $ suc _))] p₂ = ≡-cong (λ x → x ∪ [(n , Unique (Ref-ℕ $ suc a))]) (t-x∖y v [ n ]) get-ℕ : (r n : String) {r≢!n : r s-≢! n} {a : ℕ} → Transformer ([(r , Unique (Ref-ℕ a))] , nr-[a]) ((r , Unique (Ref-ℕ a)) ∷ [(n , Pure (Exact a))] , (x≢y⇒x∉l⇒x∉y∷l (s-≢!⇒≢? r≢!n) λ()) ∷ nr-[a]) get-ℕ r n {a = a} ctx nr-v h⊆v _ = context w , ≋-trans p₁ (≋-trans p₂ p₃) where v = Context.get ctx pr : Pure (Exact a) pr = pure ∘ proofGet-ℕ ∘ Unique.get ∘ getBySignature ∘ h⊆v $ here refl w = v ∪ [(n , Pure (Exact a) , pr)] p₁ : types (v ∪ [(n , Pure (Exact a) , pr)]) ≋ types v ∪ [(n , Pure (Exact a))] p₁ = ≡⇒≋ $ t-x∪y v [(n , Pure (Exact a) , pr)] p₂ : types v ∪ [(n , Pure (Exact a))] ≋ (types v ∖∖ [ r ] ∪ [(r , Unique (Ref-ℕ _))]) ∪ [(n , Pure (Exact a))] p₂ = x≋x̀⇒x∪y≋x̀∪y (≋-trans g₁ g₂) [(n , Pure (Exact a))] where g₁ : types v ≋ [(r , Unique (Ref-ℕ _))] ∪ types v ∖∖ [ r ] g₁ = t₁⊆t₂⇒t₂≋t₁∪t₂∖nt₁ nr-[a] (nr-x⇒nr-t-x nr-v) h⊆v g₂ : [(r , Unique (Ref-ℕ _))] ∪ types v ∖∖ [ r ] ≋ types v ∖∖ [ r ] ∪ [(r , Unique (Ref-ℕ _))] g₂ = ∪-sym [(r , Unique (Ref-ℕ _))] (types v ∖∖ [ r ]) p₃ : (types v ∖∖ [ r ] ∪ [(r , Unique (Ref-ℕ a))]) ∪ [(n , Pure (Exact a))] ≋ types v ∖∖ [ r ] ∪ ((r , Unique (Ref-ℕ _)) ∷ [(n , Pure (Exact a))]) p₃ = ≡⇒≋ $ ∪-assoc (types v ∖∖ [ r ]) [(r , Unique (Ref-ℕ _))] [(n , Pure (Exact a))] free-ℕ : (h : String) {a : ℕ} → Transformer! [(h , Unique (Ref-ℕ a))] [] free-ℕ h ctx nr-v h⊆v _ = u seq (context w , ≡⇒≋ p) where v = Context.get ctx u = proofFree-ℕ ∘ Unique.get ∘ getBySignature ∘ h⊆v $ here refl w = v ∖∖ [ h ] p : types (v ∖∖ [ h ]) ≡ types v ∖∖ [ h ] ∪ [] p = ≡-trans (t-x∖y v [ h ]) (≡-sym $ x∪[]≡x (types v ∖∖ [ h ]))
{ "alphanum_fraction": 0.5122123062, "avg_line_length": 45.2978723404, "ext": "agda", "hexsha": "98e90abe684ab87988e30940f390d6d1df4a2578", "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/LibSucceed/Issue784/RefAPI.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/LibSucceed/Issue784/RefAPI.agda", "max_line_length": 150, "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/LibSucceed/Issue784/RefAPI.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1943, "size": 4258 }
------------------------------------------------------------------------------ -- Properties for the bisimilarity relation ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Relation.Binary.Bisimilarity.PropertiesI where open import FOTC.Base open import FOTC.Base.List open import FOTC.Base.List.PropertiesI open import FOTC.Base.PropertiesI open import FOTC.Data.Stream.Type open import FOTC.Relation.Binary.Bisimilarity.Type ------------------------------------------------------------------------------ -- Because a greatest post-fixed point is a fixed-point, the -- bisimilarity relation _≈_ on unbounded lists is also a pre-fixed -- point of the bisimulation functional (see -- FOTC.Relation.Binary.Bisimulation). ≈-in : ∀ {xs ys} → ∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ xs' ≈ ys' → xs ≈ ys ≈-in h = ≈-coind B h' h where B : D → D → Set B xs ys = ∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ xs' ≈ ys' h' : ∀ {xs} {ys} → B xs ys → ∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ B xs' ys' h' (x' , xs' , ys' , prf₁ , prf₂ , xs'≈ys') = x' , xs' , ys' , prf₁ , prf₂ , ≈-out xs'≈ys' ≈-refl : ∀ {xs} → Stream xs → xs ≈ xs ≈-refl {xs} Sxs = ≈-coind B h₁ h₂ where B : D → D → Set B xs ys = Stream xs ∧ xs ≡ ys h₁ : ∀ {xs ys} → B xs ys → ∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ B xs' ys' h₁ (Sxs , refl) with Stream-out Sxs ... | x' , xs' , prf , Sxs' = x' , xs' , xs' , prf , prf , (Sxs' , refl) h₂ : B xs xs h₂ = Sxs , refl ≈-sym : ∀ {xs ys} → xs ≈ ys → ys ≈ xs ≈-sym {xs} {ys} xs≈ys = ≈-coind B h₁ h₂ where B : D → D → Set B xs ys = ys ≈ xs h₁ : ∀ {ys xs} → B ys xs → ∃[ y' ] ∃[ ys' ] ∃[ xs' ] ys ≡ y' ∷ ys' ∧ xs ≡ y' ∷ xs' ∧ B ys' xs' h₁ Bxsys with ≈-out Bxsys ... | y' , ys' , xs' , prf₁ , prf₂ , ys'≈xs' = y' , xs' , ys' , prf₂ , prf₁ , ys'≈xs' h₂ : B ys xs h₂ = xs≈ys ≈-trans : ∀ {xs ys zs} → xs ≈ ys → ys ≈ zs → xs ≈ zs ≈-trans {xs} {ys} {zs} xs≈ys ys≈zs = ≈-coind B h₁ h₂ where B : D → D → Set B xs zs = ∃[ ys ] xs ≈ ys ∧ ys ≈ zs h₁ : ∀ {as} {cs} → B as cs → ∃[ a' ] ∃[ as' ] ∃[ cs' ] as ≡ a' ∷ as' ∧ cs ≡ a' ∷ cs' ∧ B as' cs' h₁ {cs = cs} (bs , as≈bs , bs≈cs) with ≈-out as≈bs ... | a' , as' , bs' , prf₁ , prf₂ , as'≈bs' with ≈-out bs≈cs ... | b' , bs'' , cs' , prf₃ , prf₄ , bs''≈cs' = a' , as' , cs' , prf₁ , subst (λ t → cs ≡ t ∷ cs') b'≡a' prf₄ , (bs' , as'≈bs' , subst (λ t → t ≈ cs') bs''≡bs' bs''≈cs') where b'≡a' : b' ≡ a' b'≡a' = ∧-proj₁ (∷-injective (trans (sym prf₃) prf₂)) bs''≡bs' : bs'' ≡ bs' bs''≡bs' = ∧-proj₂ (∷-injective (trans (sym prf₃) prf₂)) h₂ : B xs zs h₂ = ys , (xs≈ys , ys≈zs) ∷-injective≈ : ∀ {x xs ys} → x ∷ xs ≈ x ∷ ys → xs ≈ ys ∷-injective≈ {x} {xs} {ys} h with ≈-out h ... | x' , xs' , ys' , prf₁ , prf₂ , prf₃ = xs≈ys where xs≡xs' : xs ≡ xs' xs≡xs' = ∧-proj₂ (∷-injective prf₁) ys≡ys' : ys ≡ ys' ys≡ys' = ∧-proj₂ (∷-injective prf₂) xs≈ys : xs ≈ ys xs≈ys = subst (λ t → t ≈ ys) (sym xs≡xs') (subst (_≈_ xs') (sym ys≡ys') prf₃) ∷-rightCong≈ : ∀ {x xs ys} → xs ≈ ys → x ∷ xs ≈ x ∷ ys ∷-rightCong≈ {x} {xs} {ys} h = ≈-in (x , xs , ys , refl , refl , h)
{ "alphanum_fraction": 0.437642369, "avg_line_length": 31.0796460177, "ext": "agda", "hexsha": "2c4d54c1b56764afee4cff0736e6a73bb5cb98ee", "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/Relation/Binary/Bisimilarity/PropertiesI.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/Relation/Binary/Bisimilarity/PropertiesI.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/Relation/Binary/Bisimilarity/PropertiesI.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": 1559, "size": 3512 }
open import Prelude module Implicits.Substitutions.Type where open import Implicits.Syntax.Type open import Data.Fin.Substitution open import Data.Star as Star hiding (map) open import Data.Star.Properties open import Data.Vec module TypeApp {T} (l : Lift T Type) where open Lift l hiding (var) infixl 8 _/_ mutual _simple/_ : ∀ {m n} → SimpleType m → Sub T m n → Type n tc c simple/ σ = simpl (tc c) tvar x simple/ σ = lift (lookup x σ) (a →' b) simple/ σ = simpl ((a / σ) →' (b / σ)) _/_ : ∀ {m n} → Type m → Sub T m n → Type n (simpl c) / σ = (c simple/ σ) (a ⇒ b) / σ = (a / σ) ⇒ (b / σ) (∀' a) / σ = ∀' (a / σ ↑) open Application (record { _/_ = _/_ }) using (_/✶_) →'-/✶-↑✶ : ∀ k {m n a b} (ρs : Subs T m n) → (simpl (a →' b)) /✶ ρs ↑✶ k ≡ simpl ((a /✶ ρs ↑✶ k) →' (b /✶ ρs ↑✶ k)) →'-/✶-↑✶ k ε = refl →'-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (→'-/✶-↑✶ k ρs) refl ⇒-/✶-↑✶ : ∀ k {m n a b} (ρs : Subs T m n) → (a ⇒ b) /✶ ρs ↑✶ k ≡ (a /✶ ρs ↑✶ k) ⇒ (b /✶ ρs ↑✶ k) ⇒-/✶-↑✶ k ε = refl ⇒-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (⇒-/✶-↑✶ k ρs) refl tc-/✶-↑✶ : ∀ k {c m n} (ρs : Subs T m n) → (simpl (tc c)) /✶ ρs ↑✶ k ≡ simpl (tc c) tc-/✶-↑✶ k ε = refl tc-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (tc-/✶-↑✶ k ρs) refl ∀'-/✶-↑✶ : ∀ k {m n a} (ρs : Subs T m n) → (∀' a) /✶ ρs ↑✶ k ≡ ∀' (a /✶ ρs ↑✶ (suc k)) ∀'-/✶-↑✶ k ε = refl ∀'-/✶-↑✶ k (x ◅ ρs) = cong₂ _/_ (∀'-/✶-↑✶ k ρs) refl typeSubst : TermSubst Type typeSubst = record { var = (λ n → simpl (tvar n)); app = TypeApp._/_ } open TermSubst typeSubst public hiding (var) open TypeApp termLift public using (_simple/_) open TypeApp varLift public using () renaming (_simple/_ to _simple/Var_) infix 8 _[/_] -- Shorthand for single-variable type substitutions _[/_] : ∀ {n} → Type (suc n) → Type n → Type n a [/ b ] = a / sub b -- shorthand for type application infixl 8 _∙_ _∙_ : ∀ {ν} → (a : Type ν) → {is∀ : is-∀' a} → Type ν → Type ν _∙_ (simpl (tvar n)) {is∀ = ()} _ _∙_ (simpl (tc c)) b = simpl (tc c) _∙_ (simpl (_ →' _)) {is∀ = ()} _ _∙_ (∀' x) b = x [/ b ] _∙_ (_ ⇒ _) {is∀ = ()} _ stp-weaken : ∀ {ν} → SimpleType ν → SimpleType (suc ν) stp-weaken (tc x) = tc x stp-weaken (tvar n) = tvar (suc n) stp-weaken (a →' b) = weaken a →' weaken b
{ "alphanum_fraction": 0.4903059026, "avg_line_length": 30.5394736842, "ext": "agda", "hexsha": "592519970e2c4af0f76a520f418acf107d57354c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "metaborg/ts.agda", "max_forks_repo_path": "src/Implicits/Substitutions/Type.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "metaborg/ts.agda", "max_issues_repo_path": "src/Implicits/Substitutions/Type.agda", "max_line_length": 83, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "metaborg/ts.agda", "max_stars_repo_path": "src/Implicits/Substitutions/Type.agda", "max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z", "max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z", "num_tokens": 1084, "size": 2321 }
module Thesis.SIRelBigStep.FundamentalProperty where open import Data.Product open import Relation.Binary.PropositionalEquality open import Thesis.SIRelBigStep.IlcSILR rfundamentalV3v : ∀ {Γ τ} (x : Var Γ τ) → (n : ℕ) → ∀ ρ1 dρ ρ2 (ρρ : rrelρ3 Γ ρ1 dρ ρ2 n) → rrelV3 τ (⟦ x ⟧Var ρ1) (D.⟦ x ⟧Var dρ) (⟦ x ⟧Var ρ2) n rfundamentalV3v x n ρ1 dρ ρ2 ρρ = ⟦ x ⟧RelVar3 ρρ rfundamental3constV : ∀ {τ} k (c : Const τ) → rrelV3 τ (eval-const c) (deval (derive-const c) ∅ ∅) (eval-const c) k rfundamental3constV k (lit n) = refl rfundamental3 : ∀ {τ Γ} k (t : Term Γ τ) → ∀ ρ1 dρ ρ2 → (ρρ : rrelρ3 Γ ρ1 dρ ρ2 k) → rrelT3 t (derive-dterm t) t ρ1 dρ ρ2 k rfundamental3svv : ∀ {τ Γ} k (sv : SVal Γ τ) → ∀ ρ1 dρ ρ2 → (ρρ : rrelρ3 Γ ρ1 dρ ρ2 k) → rrelV3 τ (eval sv ρ1) (deval (derive-dsval sv) ρ1 dρ) (eval sv ρ2) k rfundamental3svv k (var x) ρ1 dρ ρ2 ρρ = rfundamentalV3v x k ρ1 dρ ρ2 ρρ rfundamental3svv k (cons sv1 sv2) ρ1 dρ ρ2 ρρ = rfundamental3svv k sv1 ρ1 dρ ρ2 ρρ , rfundamental3svv k sv2 ρ1 dρ ρ2 ρρ rfundamental3svv k (const c) ρ1 dρ ρ2 ρρ rewrite deval-derive-const-inv c ρ1 dρ = rfundamental3constV k c rfundamental3svv k (abs t) ρ1 dρ ρ2 ρρ = (refl , refl) , refl , rrelρ3→⊕ ρ1 dρ ρ2 ρρ , refl , refl , λ j j<k v1 dv v2 vv → -- If we replace abs t by rec t, here we would need to invoke (by -- well-founded recursion) rfundamental3svv on (abs t) at a smaller j, as follows: -- rfundamental3svv j (abs t) ρ1 dρ ρ2 (rrelρ3-mono j k (lt1 j<k) _ _ _ _ ρρ) -- As you'd expect, Agda's termination checker does not accept that call directly. rfundamental3 j t (v1 • ρ1) (dv • dρ) (v2 • ρ2) (vv , rrelρ3-mono j k (lt1 j<k) _ _ _ _ ρρ) rfundamental3sv : ∀ {τ Γ} k (sv : SVal Γ τ) → ∀ ρ1 dρ ρ2 → (ρρ : rrelρ3 Γ ρ1 dρ ρ2 k) → rrelT3 (val sv) (dval (derive-dsval sv)) (val sv) ρ1 dρ ρ2 k rfundamental3sv k sv ρ1 dρ ρ2 ρρ .(eval sv ρ1) .(eval sv ρ2) .0 j<k (val .sv) (val .sv) = deval (derive-dsval sv) ρ1 dρ , dval (derive-dsval sv) , rfundamental3svv k sv ρ1 dρ ρ2 ρρ open import Theorem.Groups-Nehemiah rfundamental3primv : ∀ {σ τ} k p → ∀ v1 dv v2 → (vv : rrelV3 σ v1 dv v2 k) → rrelV3 τ (eval-primitive p v1) (deval-primitive p v1 dv) (eval-primitive p v2) k rfundamental3primv k succ (natV n₁) (bang .(natV n)) (natV n) refl = refl rfundamental3primv k succ (natV n) (dnatV dn) (natV .(dn + n)) refl = +-suc dn n rfundamental3primv k add (pairV (natV a1) (natV b1)) (dpairV (dnatV da) (dnatV db)) (pairV (natV .(da + a1)) (natV .(db + b1))) (refl , refl) = ℕ-mn·pq=mp·nq {da} {db} {a1} {b1} rfundamental3primv k add (pairV a1 b1) (dpairV (dnatV da) (bang b2)) (pairV a2 .b2) (aa , refl) rewrite rrelV3→⊕ a1 (dnatV da) a2 aa = refl rfundamental3primv k add (pairV a1 b1) (dpairV (bang a2) db) (pairV .a2 b2) (refl , bb) rewrite rrelV3→⊕ b1 db b2 bb = refl rfundamental3primv k add (pairV a1 b1) (bang p2) .p2 refl = refl -- Warning: names like ρ1⊢t1↓[j]v1 are all broken, sorry for not fixing them. rfundamental3 k (val sv) = rfundamental3sv k sv rfundamental3 (suc k) (primapp p sv) ρ1 dρ ρ2 ρρ .(eval-primitive p (eval sv ρ1)) .(eval-primitive p (eval sv ρ2)) .1 (s≤s j<k) (primapp .p .sv) (primapp .p .sv) = deval-primitive p (eval sv ρ1) (deval (derive-dsval sv) ρ1 dρ) , dprimapp p sv (derive-dsval sv) , rfundamental3primv k p (eval sv ρ1) (deval (derive-dsval sv) ρ1 dρ) (eval sv ρ2) (rfundamental3svv k sv ρ1 dρ ρ2 (rrelρ3-mono k (suc k) (≤-step ≤-refl) _ ρ1 dρ ρ2 ρρ)) rfundamental3 (suc (suc k)) (app vs vt) ρ1 dρ ρ2 ρρ v1 v2 .(suc j) (s≤s (s≤s j<k)) (app j vtv1 ρ1⊢t1↓[j]v1 ρ1⊢t1↓[j]v2 ρ1⊢t1↓[j]v3) (app n₁ vtv2 ρ2⊢t2↓[n2]v2 ρ2⊢t2↓[n2]v3 ρ2⊢t2↓[n2]v4) with rfundamental3sv (suc (suc k)) vs ρ1 dρ ρ2 ρρ _ _ zero (s≤s z≤n) ρ1⊢t1↓[j]v1 ρ2⊢t2↓[n2]v2 | rfundamental3sv (suc (suc k)) vt ρ1 dρ ρ2 ρρ _ _ zero (s≤s z≤n) ρ1⊢t1↓[j]v2 ρ2⊢t2↓[n2]v3 ... | bang f2 , vs↓dsv , refl | dtv , vt↓dvv , dtvv rewrite sym (rrelV3→⊕ vtv1 dtv vtv2 dtvv) = bang v2 , bangapp vs↓dsv ρ1⊢t1↓[j]v2 vt↓dvv ρ2⊢t2↓[n2]v4 , refl ... | dclosure dt ρ dρ₁ , vs↓dsv , (refl , refl) , refl , refl , refl , refl , dsvv | dtv , vt↓dvv , dtvv with dsvv (suc k) ≤-refl vtv1 dtv vtv2 (rrelV3-mono (suc k) (suc (suc k)) (s≤s (≤-step ≤-refl)) _ vtv1 dtv vtv2 dtvv) v1 v2 j (s≤s j<k) ρ1⊢t1↓[j]v3 ρ2⊢t2↓[n2]v4 ... | dv , ↓dv , dvv = dv , dapp vs↓dsv ρ1⊢t1↓[j]v2 vt↓dvv ↓dv , dvv rfundamental3 (suc (suc k)) (lett s t) ρ1 dρ ρ2 ρρ v1 v2 .(suc (n1 + n2)) (s≤s (s≤s n1+n2≤k)) (lett n1 n2 vs1 .s .t ρ1⊢t1↓[j]v1 ρ1⊢t1↓[j]v2) (lett _ _ vs2 .s .t ρ2⊢t2↓[n2]v2 ρ2⊢t2↓[n2]v3) with rfundamental3 (suc (suc k)) s ρ1 dρ ρ2 ρρ vs1 vs2 n1 (s≤s (≤-trans (≤-trans (m≤m+n n1 n2) n1+n2≤k) (≤-step ≤-refl))) ρ1⊢t1↓[j]v1 ρ2⊢t2↓[n2]v2 ... | dsv , ↓dsv , vsv with rfundamental3 (suc (suc k) ∸ n1) t (vs1 • ρ1) (dsv • dρ) (vs2 • ρ2) (vsv , rrelρ3-mono (suc (suc k) ∸ n1) (suc (suc k)) (m∸n≤m (suc (suc k)) n1) _ _ _ _ ρρ) v1 v2 n2 (sub∸ n1 (suc n2) (suc (suc k)) n1+[1+n2]≤2+k) ρ1⊢t1↓[j]v2 ρ2⊢t2↓[n2]v3 where n1+[1+n2]≤2+k : n1 + suc n2 ≤ suc (suc k) n1+[1+n2]≤2+k rewrite +-suc n1 n2 = ≤-step (s≤s n1+n2≤k) ... | dv , ↓dv , dvv = dv , dlett ρ1⊢t1↓[j]v1 ↓dsv ↓dv , rrelV3-mono (suc k ∸ (n1 + n2)) (suc (suc k) ∸ n1 ∸ n2) 1+k-[n1+n2]≤2+k-n1-n2 _ v1 dv v2 dvv where 1+k-[n1+n2]≤2+k-n1-n2 : suc k ∸ (n1 + n2) ≤ suc (suc k) ∸ n1 ∸ n2 1+k-[n1+n2]≤2+k-n1-n2 rewrite ∸-+-assoc (suc (suc k)) n1 n2 = ∸-mono {suc k} {suc (suc k)} {n1 + n2} {n1 + n2} (≤-step ≤-refl) ≤-refl
{ "alphanum_fraction": 0.6127915452, "avg_line_length": 60.9777777778, "ext": "agda", "hexsha": "f8b7293a741a17ad6b70a12e46d71819c1bec132", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Thesis/SIRelBigStep/FundamentalProperty.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Thesis/SIRelBigStep/FundamentalProperty.agda", "max_line_length": 248, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Thesis/SIRelBigStep/FundamentalProperty.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 2963, "size": 5488 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties satisfied by decidable total orders ------------------------------------------------------------------------ open import Relation.Binary module Relation.Binary.Properties.DecTotalOrder {d₁ d₂ d₃} (DT : DecTotalOrder d₁ d₂ d₃) where open Relation.Binary.DecTotalOrder DT hiding (trans) import Relation.Binary.NonStrictToStrict as Conv open Conv _≈_ _≤_ strictTotalOrder : StrictTotalOrder _ _ _ strictTotalOrder = record { isStrictTotalOrder = record { isEquivalence = isEquivalence ; trans = trans isPartialOrder ; compare = trichotomous Eq.sym _≟_ antisym total ; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈ } } open StrictTotalOrder strictTotalOrder public
{ "alphanum_fraction": 0.5888625592, "avg_line_length": 31.2592592593, "ext": "agda", "hexsha": "13673c0bc6b9373c21d5ec83857c0e2c6be4350d", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Properties/DecTotalOrder.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Properties/DecTotalOrder.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Properties/DecTotalOrder.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 193, "size": 844 }
open import IO main = run (putStr "Hacktoberfest")
{ "alphanum_fraction": 0.7307692308, "avg_line_length": 13, "ext": "agda", "hexsha": "8b76003155c6355617a2a047262424f9c30e1756", "lang": "Agda", "max_forks_count": 7, "max_forks_repo_forks_event_max_datetime": "2021-10-02T05:07:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-10-01T15:13:01.000Z", "max_forks_repo_head_hexsha": "3227a8a458fc7fd3618106ad054f7f3be62d0513", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "5R33CH4/lango", "max_forks_repo_path": "agda.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "3227a8a458fc7fd3618106ad054f7f3be62d0513", "max_issues_repo_issues_event_max_datetime": "2021-10-02T05:38:00.000Z", "max_issues_repo_issues_event_min_datetime": "2021-10-02T01:30:09.000Z", "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "5R33CH4/lango", "max_issues_repo_path": "agda.agda", "max_line_length": 35, "max_stars_count": 2, "max_stars_repo_head_hexsha": "3227a8a458fc7fd3618106ad054f7f3be62d0513", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "5R33CH4/lango", "max_stars_repo_path": "agda.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-03T09:18:09.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-02T05:34:09.000Z", "num_tokens": 15, "size": 52 }
{-# OPTIONS --show-implicit --show-irrelevant #-} -- {-# OPTIONS -v tc.conv.irr:20 -v tc.constr.findInScope:20 -v tc.meta:20 -v tc.conv.type:50 -v tc.conv.term:30 -v tc.conv.atom:50 -v tc.inj.use:20 #-} module Issue631 where import Common.Level -- for debug messages data Bool : Set where false true : Bool F : Bool → Set F true = Bool F false = Bool postulate BAD : ∀ {u} → F u Goal : Set score : .Goal → Set buggy : Set buggy = score _ -- {!!} -- should remain unsolved
{ "alphanum_fraction": 0.6395112016, "avg_line_length": 22.3181818182, "ext": "agda", "hexsha": "526677ea2b52e1cba02866e0a10bce505207c3c4", "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/Issue631.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/Issue631.agda", "max_line_length": 152, "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/Issue631.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": 162, "size": 491 }
{-# OPTIONS --cubical --safe #-} module Data.Vec where open import Prelude private variable n m : ℕ infixr 5 _∷_ data Vec (A : Type a) : ℕ → Type a where [] : Vec A zero _∷_ : A → Vec A n → Vec A (suc n) head : Vec A (suc n) → A head (x ∷ _) = x foldr : (A → B → B) → B → Vec A n → B foldr f b [] = b foldr f b (x ∷ xs) = f x (foldr f b xs)
{ "alphanum_fraction": 0.5378151261, "avg_line_length": 16.2272727273, "ext": "agda", "hexsha": "9b122c143bc9f7f7dbf38de1794d280dffb05b5f", "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/Vec.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/Vec.agda", "max_line_length": 40, "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/Vec.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": 148, "size": 357 }
module GUIgeneric.GUIFeaturesPart3 where open import GUIgeneric.Prelude renaming (addButton to addButton') open import GUIgeneric.GUIDefinitions renaming (add to add'; add' to add) open import GUIgeneric.GUI open import GUIgeneric.GUIExampleLib open import StateSizedIO.GUI.WxGraphicsLibLevel3 renaming (addButton to addButton') open import GUIgeneric.GUIFeatures open import GUIgeneric.GUIFeaturesPart2 hiding ( main ) open import GUIgeneric.GUIExample hiding (main ) open import Data.Product open import Data.Fin liftResultˢ : (S S' : Set) (s2GUI : (s : S') → Frame) (ss' : S → S') (s : S) (m : methodsG (s2GUI (ss' s))) (r : Resultˢ (handlerGUIInterfₛ S (s2GUI ∘ ss')) s m) → Resultˢ (handlerGUIInterfₛ S' s2GUI) (ss' s) m liftResultˢ S S' s2GUI ss' s m noChange = noChange liftResultˢ S S' s2GUI ss' s m (changedState snew) = changedState (ss' snew) extendHandlerGuiInterfₛ : (i : Size) (S S' : Set) (s2GUI : (s : S') → Frame) (ss' : S → S') (s : S) (obj : handlerGUIObjectₛ i S (s2GUI ∘ ss') s) → handlerGUIObjectₛ i S' s2GUI (ss' s) method (extendHandlerGuiInterfₛ i S S' s2GUI ss' s obj) m = x >>= (λ r → return (liftResultˢ S S' s2GUI ss' s m r)) where x : IO GuiLev1Interface ∞ (Resultˢ (handlerGUIInterfₛ S (s2GUI ∘ ss')) s m) x = method obj m lift⊎3 : {A B C : Set} → A ⊎ B → A ⊎ B ⊎ C lift⊎3 (inj₁ x) = inj₁ x lift⊎3 (inj₂ y) = inj₂ (inj₁ y) mapReturnTypeₛ : {A B : Set}(f : A → B) (a : ReturnTypeₛ A) → ReturnTypeₛ B mapReturnTypeₛ f noChange = noChange mapReturnTypeₛ f (changedState snew) = changedState (f snew) mapStateMachineHandl : {S S' : Set}(f : S → S') (p : IO GuiLev1Interface ∞ (ReturnTypeₛ S)) → IO GuiLev1Interface ∞ (ReturnTypeₛ S') mapStateMachineHandl f p = mapIO (mapReturnTypeₛ f) p mapSMachineState : {S S' : Set}(f : S → S')(s : S)(sm : SMachineState S s) → SMachineState S' (f s) mapSMachineState f s sm .fSM = sm .fSM mapSMachineState f s sm .propSM = sm .propSM mapSMachineState f s sm .handlSM m = mapStateMachineHandl f (sm .handlSM m) mapFMachineHandle : {A B C : Set} (a : A ⊎ B)(sm : SMachineState (A ⊎ B) a) → SMachineState (A ⊎ B ⊎ C) (lift⊎3 a) mapFMachineHandle a sm = mapSMachineState lift⊎3 a sm mapIOFeatureM : {A B C : Set} → IO GuiLev1Interface ∞ (ReturnTypeₛ (A ⊎ B)) → IO GuiLev1Interface ∞ (ReturnTypeₛ (A ⊎ B ⊎ C)) mapIOFeatureM p = mapIO (mapReturnTypeₛ lift⊎3) p Cancel : FMachine StateV → FMachine StateV Cancel vm .Features = vm .Features × FeatureCancel Cancel vm .AddStateF = vm .AddStateF ⊎ ⊤ Cancel vm .GUIF (f , yesCancel) (inj₁ s1) = addBtn2StateMachine (mapFMachineHandle (inj₁ s1) (vm .GUIF f (inj₁ s1))) "Cancel" ((inj₂ (inj₂ _))) Cancel vm .GUIF (f , _) (inj₁ s) = mapFMachineHandle (inj₁ s) (vm .GUIF f (inj₁ s)) Cancel vm .GUIF (f , _) (inj₂ (inj₁ x)) = mapFMachineHandle (inj₂ x) (vm .GUIF f (inj₂ x)) Cancel vm .GUIF (f , _) (inj₂ (inj₂ _)) = simpleSMState "Intermediate" (inj₁ s0) Tea : FMachine StateV → FMachine StateV Tea vm .Features = vm .Features × FeatureTea Tea vm .AddStateF = vm .AddStateF ⊎ ⊤ Tea vm .GUIF (f , yeTea) (inj₁ s2) = addBtn2StateMachine (mapFMachineHandle (inj₁ s2) (vm .GUIF f (inj₁ s2))) "Tea" ((inj₂ (inj₂ _))) Tea vm .GUIF (f , _) (inj₁ s) = mapFMachineHandle (inj₁ s) (vm .GUIF f (inj₁ s)) Tea vm .GUIF (f , _) (inj₂ (inj₁ x)) = mapFMachineHandle (inj₂ x) (vm .GUIF f (inj₂ x)) Tea vm .GUIF (f , _) (inj₂ (inj₂ _)) = simpleSMState "Get Your Tea" (inj₁ s0) cancelBase : FMachine StateV cancelBase = Cancel baseF teaCancelBase : FMachine StateV teaCancelBase = Tea cancelBase main : NativeIO Unit main = compileFeatureVM teaCancelBase ((_ , yesCancel) , yesTea) (inj₁ s0) --
{ "alphanum_fraction": 0.6070467335, "avg_line_length": 40.87, "ext": "agda", "hexsha": "bd69d5069bf69cc5b489b0ded0a6ed5adde2143c", "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": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "stephanadls/state-dependent-gui", "max_forks_repo_path": "examples/GUIgeneric/GUIFeaturesPart3.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "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": "stephanadls/state-dependent-gui", "max_issues_repo_path": "examples/GUIgeneric/GUIFeaturesPart3.agda", "max_line_length": 98, "max_stars_count": 2, "max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "stephanadls/state-dependent-gui", "max_stars_repo_path": "examples/GUIgeneric/GUIFeaturesPart3.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z", "num_tokens": 1411, "size": 4087 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties satisfied by strict partial orders ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Relation.Binary.Properties.StrictTotalOrder {s₁ s₂ s₃} (STO : StrictTotalOrder s₁ s₂ s₃) where open Relation.Binary.StrictTotalOrder STO open import Relation.Binary.Construct.StrictToNonStrict _≈_ _<_ import Relation.Binary.Properties.StrictPartialOrder as SPO open import Relation.Binary.Consequences ------------------------------------------------------------------------ -- Strict total orders can be converted to decidable total orders decTotalOrder : DecTotalOrder _ _ _ decTotalOrder = record { isDecTotalOrder = isDecTotalOrder isStrictTotalOrder } open DecTotalOrder decTotalOrder public
{ "alphanum_fraction": 0.6006528836, "avg_line_length": 31.6896551724, "ext": "agda", "hexsha": "7785c5ec6ad4051d3ff55cba0f83b04986be960c", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Properties/StrictTotalOrder.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/Properties/StrictTotalOrder.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Properties/StrictTotalOrder.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 171, "size": 919 }
module parse-tree where open import lib record ParseTreeRec : Set lone where field ParseTreeT : Set isParseTree : ParseTreeT → 𝕃 char → string → Set ParseTreeToString : ParseTreeT → string
{ "alphanum_fraction": 0.7268292683, "avg_line_length": 20.5, "ext": "agda", "hexsha": "723c93f8242128a2f040d53b608c98cd92d7a0e9", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "xoltar/cedille", "max_forks_repo_path": "src/parse-tree.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "xoltar/cedille", "max_issues_repo_path": "src/parse-tree.agda", "max_line_length": 52, "max_stars_count": null, "max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "xoltar/cedille", "max_stars_repo_path": "src/parse-tree.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 57, "size": 205 }
module List where data Bool : Set where true : Bool false : Bool if_then_else_ : {A : Set} -> Bool -> A -> A -> A if true then x else y = x if false then x else y = y boolElim : (P : Bool -> Set) -> P true -> P false -> (b : Bool) -> P b boolElim P t f true = t boolElim P t f false = f data False : Set where data True : Set where tt : True data Or (A B : Set) : Set where inl : (a : A) -> Or A B inr : (b : B) -> Or A B orElim : {A B : Set} -> (C : Or A B -> Set) -> (cl : (a : A) -> C(inl a)) -> (cr : (b : B) -> C(inr b)) -> (ab : Or A B) -> C ab orElim {A} {B} C cl cr (inl a) = cl a orElim {A} {B} C cl cr (inr b) = cr b data Rel(A : Set) : Set1 where rel : (A -> A -> Set) -> Rel A _is_than_ : {A : Set} -> A -> Rel A -> A -> Set x is rel f than y = f x y data Acc {A : Set} (less : Rel A) (x : A) : Set where acc : ((y : A) -> y is less than x -> Acc less y) -> Acc less x data WO {A : Set} (less : Rel A) : Set where wo : ((x : A) -> Acc less x) -> WO less data Nat : Set where Z : Nat S : Nat -> Nat eqNat : Nat -> Nat -> Set eqNat Z Z = True eqNat (S m) (S n) = eqNat m n eqNat _ _ = False substEqNat : (P : Nat -> Set) -> (a b : Nat) -> (e : eqNat a b) -> (P a) -> P b substEqNat P Z Z e pa = pa substEqNat P (S x) (S x') e pa = substEqNat (\n -> P(S n)) x x' e pa ltNat : Nat -> Nat -> Set ltNat Z Z = False ltNat Z (S n) = True ltNat (S m) (S n) = ltNat m n ltNat (S m) Z = False ltZ-elim : (n : Nat) -> ltNat n Z -> {whatever : Set} -> whatever ltZ-elim Z () ltZ-elim (S _) () transNat : (x y z : Nat) -> ltNat x y -> ltNat y z -> ltNat x z transNat x y Z x<y y<z = ltZ-elim y y<z transNat x Z (S z) x<Z Z<Sz = ltZ-elim x x<Z transNat Z (S y) (S z) tt y<z = tt transNat (S x) (S y) (S z) x<y y<z = transNat x y z x<y y<z ltNat-S-Lemma : (x : Nat) -> ltNat x (S x) ltNat-S-Lemma Z = tt ltNat-S-Lemma (S x) = ltNat-S-Lemma x ltNat-S-Lemma2 : (y z : Nat) -> ltNat y (S z) -> Or (eqNat z y) (ltNat y z) ltNat-S-Lemma2 Z Z h = inl tt ltNat-S-Lemma2 Z (S x) h = inr tt ltNat-S-Lemma2 (S x) (S x') h = ltNat-S-Lemma2 x x' h ltNatRel : Rel Nat ltNatRel = rel ltNat less = ltNatRel acc-Lemma1 : (x y : Nat) -> Acc less x -> eqNat x y -> Acc less y acc-Lemma1 x y a e = substEqNat (Acc less ) x y e a acc-Lemma2 : (x y : Nat) -> Acc less x -> ltNat y x -> Acc less y acc-Lemma2 x y (acc h) l = h y l -- postulate woltNat' : (n : Nat) -> Acc less n woltNat' : (n : Nat) -> Acc less n woltNat' Z = acc (\y y<Z -> ltZ-elim y y<Z) woltNat' (S x) = acc (\y y<Sx -> orElim (\w -> Acc less y) (\e -> substEqNat (Acc less ) x y e (woltNat' x ) ) (acc-Lemma2 x y (woltNat' x)) (ltNat-S-Lemma2 y x y<Sx )) woltNat : WO ltNatRel woltNat = wo woltNat' postulate le : Nat -> Nat -> Bool postulate gt : Nat -> Nat -> Bool data List (A : Set) : Set where nil : List A cons : (x : A) -> (xs : List A) -> List A _++_ : {A : Set} -> List A -> List A -> List A nil ++ ys = ys (cons x xs) ++ ys = cons x (xs ++ ys) length : {A : Set} -> List A -> Nat length nil = Z length (cons x xs) = S (length xs) filter : {A : Set} -> (A -> Bool) -> List A -> List A filter p nil = nil filter p (cons x xs) = if p x then cons x rest else rest where rest = filter p xs filterLemma : {A : Set} -> (p : A -> Bool) -> (xs : List A) -> length (filter p xs) is less than S (length xs) filterLemma p nil = tt filterLemma p (cons x xs) = boolElim (\px -> length (if px then cons x (filter p xs) else (filter p xs)) is less than S (S (length xs))) (filterLemma p xs) (transNat (length (filter p xs)) (S (length xs)) (S (S (length xs))) (filterLemma p xs) (ltNat-S-Lemma (length xs ))) (p x) qs : List Nat -> List Nat qs nil = nil qs (cons x xs) = qs (filter (le x) xs) ++ cons x nil ++ qs (filter (gt x) xs) data Measure : Set1 where μ : {M : Set} -> {rel : Rel M} -> (ord : WO rel) -> Measure down1-measure : Measure down1-measure = μ woltNat qs-2-1-hint = \(x : Nat) -> \(xs : List Nat) -> filterLemma (le x) xs qs-2-2-hint = \(x : Nat) -> \(xs : List Nat) -> filterLemma (gt x) xs
{ "alphanum_fraction": 0.5255781359, "avg_line_length": 28.9256756757, "ext": "agda", "hexsha": "ccbe545b191eed0d457cbf80f0c6550f50ca6c4c", "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/Termination/List.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/Termination/List.agda", "max_line_length": 171, "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/Termination/List.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": 1659, "size": 4281 }
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Binary.Permutation.Inductive directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Permutation.Inductive where open import Data.List.Relation.Binary.Permutation.Inductive public {-# WARNING_ON_IMPORT "Data.List.Relation.Permutation.Inductive was deprecated in v1.0. Use Data.List.Relation.Binary.Permutation.Inductive instead." #-}
{ "alphanum_fraction": 0.5892255892, "avg_line_length": 33, "ext": "agda", "hexsha": "353c955e693cf343801e0234a6cb7f1e94ed9da0", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Permutation/Inductive.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Permutation/Inductive.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DreamLinuxer/popl21-artifact", "max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Permutation/Inductive.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": 113, "size": 594 }
------------------------------------------------------------------------ -- A variant of the development in "Internalizing Representation -- Independence with Univalence" (by Angiuli, Cavallo, Mörtberg and -- Zeuner) with support for erasure ------------------------------------------------------------------------ -- This development follows parts of "Internalizing Representation -- Independence with Univalence" (and sometimes the code supporting -- that paper) fairly closely, but with explicit support for erasure, -- and there are some other differences. Note that some things -- discussed in the paper are not included, for instance tactics and -- most examples. -- This formalisation was started because an anonymous reviewer asked -- whether something like this could be done, and when I had made some -- initial experiments Andrea Vezzosi encouraged me to include more in -- the formalisation. {-# OPTIONS --erased-cubical --safe #-} import Equality.Path as P module Structure-identity-principle.Erased {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Logical-equivalence using (_⇔_) open import Prelude open import Bijection equality-with-J as B using (_↔_) open import Equality.Decidable-UIP equality-with-J open import Equality.Path.Isomorphisms eq import Equality.Path.Isomorphisms.Univalence eq as U open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) open import Equivalence.Erased.Cubical eq as EEq using (_≃ᴱ_; Is-equivalenceᴱ) open import Equivalence.Erased.Contractible-preimages.Cubical eq as ECP using (Contractibleᴱ) open import Equivalence-relation equality-with-J open import Erased.Cubical eq as Er hiding (map; map-id) open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J as H-level open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional.Erased eq as T using (∥_∥ᴱ; ∣_∣) import List equality-with-J as L import Maybe equality-with-J as Maybe import Monad equality-with-J as Monad import Nat equality-with-J as Nat open import Quotient.Erased eq as Q using (_/ᴱ_; [_]) open import Univalence-axiom equality-with-J open import Nat.Binary equality-with-J instance-of-[]-cong-axiomatisation as Bin using (Bin) private variable a b c d e r : Level C : Type c A A₁ A₂ B B₁ B₂ Ax F f G g M m N P R R₁ R₂ S x x′ x₁ x₂ y y′ ys z z₁ z₂ : C ------------------------------------------------------------------------ -- The structure identity principle -- Structures. Structure : (a b : Level) → Type (lsuc (a ⊔ b)) Structure a b = Type a → Type b -- Types with a given structure. Type-with : Structure a b → Type (lsuc a ⊔ b) Type-with {a = a} F = ∃ λ (A : Type a) → F A -- Axioms. -- -- Originally I made the argument of type Type-with F erased. After -- feedback from Andrea Vezzosi I instead added a use of Erased in -- _With-the-axioms_ below. Axioms : Structure a b → (c : Level) → Type (lsuc a ⊔ b ⊔ lsuc c) Axioms F c = Type-with F → Type c -- One can add axioms to structures. _With-the-axioms_ : (F : Structure a b) → Axioms F c → Structure a (b ⊔ c) (F With-the-axioms Ax) A = ∃ λ (x : F A) → Erased (Ax (A , x)) -- A type of predicates defining when a given equivalence (with erased -- proofs) is structure-preserving. Structure-preserving-equivalence-predicate : Structure a b → (c : Level) → Type (lsuc a ⊔ b ⊔ lsuc c) Structure-preserving-equivalence-predicate F c = (A B : Type-with F) → proj₁ A ≃ᴱ proj₁ B → Type c -- One can lift a "structure-preserving equivalence predicate" from F -- to F With-the-axioms Ax. Lift-With-the-axioms : Structure-preserving-equivalence-predicate F c → Structure-preserving-equivalence-predicate (F With-the-axioms Ax) c Lift-With-the-axioms P (A , x , _) (B , y , _) = P (A , x) (B , y) -- Structure-preserving equivalences (with erased proofs). infix 4 _≃[_]ᴱ_ _≃[_]ᴱ_ : {F : Structure a b} → Type-with F → @0 Structure-preserving-equivalence-predicate F c → Type-with F → Type (a ⊔ c) A ≃[ P ]ᴱ B = ∃ λ (eq : proj₁ A ≃ᴱ proj₁ B) → Erased (P A B eq) -- Univalent pairs of structures and predicates. record Univalent (@0 F : Structure a b) (@0 P : Structure-preserving-equivalence-predicate F c) : Type (lsuc a ⊔ b ⊔ c) where field -- This field is erased because it uses univalence and EEq.≃ᴱ→≃. @0 univalent : {A B : Type-with F} (eq : proj₁ A ≃ᴱ proj₁ B) → P A B eq ≃ (subst F (≃⇒≡ U.abstract-univ (EEq.≃ᴱ→≃ eq)) (proj₂ A) ≡ proj₂ B) -- If Ax is pointwise propositional, then the functions -- _With-the-axioms Ax and Lift-With-the-axioms preserve -- Univalent univ. -- -- This is a variant of Lemma 3.3 from "Internalizing Representation -- Independence with Univalence". Univalent-With-the-axioms : {@0 P : Structure-preserving-equivalence-predicate F c} → @0 (∀ A → Is-proposition (Ax A)) → Univalent F P → Univalent (F With-the-axioms Ax) (Lift-With-the-axioms P) Univalent-With-the-axioms {F = F} {Ax = Ax} {P = P} prop u .Univalent.univalent {A = A₁ , x₁ , ax₁} {B = A₂ , x₂ , ax₂} eq = P (A₁ , x₁) (A₂ , x₂) eq ↝⟨ u .Univalent.univalent eq ⟩ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁ ≡ x₂ ↔⟨ ignore-propositional-component (H-level-Erased 1 (prop _)) ⟩ (subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁ , _) ≡ (x₂ , ax₂) ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-pair _ _ ⟩□ subst (F With-the-axioms Ax) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (x₁ , ax₁) ≡ (x₂ , ax₂) □ where univ = U.abstract-univ -- The structure identity principle. -- -- This is a variant of Theorem 3.1 from "Internalizing Representation -- Independence with Univalence". Note that the principle is erased. @0 sip : Univalent F P → (A ≃[ P ]ᴱ B) ≃ (A ≡ B) sip {F = F} {P = P} {A = A} {B = B} u = (A ≃[ P ]ᴱ B) ↔⟨⟩ (∃ λ (eq : proj₁ A ≃ᴱ proj₁ B) → Erased (P A B eq)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩ (∃ λ (eq : proj₁ A ≃ᴱ proj₁ B) → P A B eq) ↝⟨ Σ-cong (inverse $ EEq.≃≃≃ᴱ F.∘ ≡≃≃ U.abstract-univ) (u .Univalent.univalent) ⟩ (∃ λ (eq : proj₁ A ≡ proj₁ B) → subst F eq (proj₂ A) ≡ proj₂ B) ↔⟨ B.Σ-≡,≡↔≡ ⟩□ (A ≡ B) □ -- If there is a structure-preserving equivalence (for a univalent -- pair of a structure and a predicate) between two types with -- structures, where one side satisfies some axioms, then the other -- side also satisfies the axioms (in erased contexts), and the -- resulting triple is equivalent (with erased proofs) to the other -- one. -- -- This is a variant of Corollary 3.4 from "Internalizing -- Representation Independence with Univalence". induced-structures : {@0 P : Structure-preserving-equivalence-predicate F c} → @0 Univalent F P → (X@(A , x , _) : Type-with (F With-the-axioms Ax)) → ((B , y) : Type-with F) → (A , x) ≃[ P ]ᴱ (B , y) → ∃ λ (ax : Erased (Ax (B , y))) → X ≃[ Lift-With-the-axioms P ]ᴱ (B , y , ax) induced-structures {Ax = Ax} u (A , x , ax) (B , y) eq = Er.map (subst Ax (_≃_.to (sip u) eq)) ax , eq ------------------------------------------------------------------------ -- Some binary relation combinators, along with some properties -- The converse of a binary relation. infix 10 _⁻¹ _⁻¹ : (A → B → Type c) → (B → A → Type c) (R ⁻¹) x y = R y x -- Propositionally truncated composition of two binary relations (the -- definition uses ∥_∥ᴱ). infixr 9 _;ᴱ_ _;ᴱ_ : {B : Type b} → (A → B → Type d) → (B → C → Type e) → A → C → Type (b ⊔ d ⊔ e) (R ;ᴱ S) x z = ∥ (∃ λ y → R x y × S y z) ∥ᴱ -- Two ways to compose a relation and its converse. infix 10 _⟵ _⟶ _⟵ : {B : Type b} → (A → B → Type c) → A → A → Type (b ⊔ c) R ⟵ = R ;ᴱ R ⁻¹ _⟶ : {A : Type a} → (A → B → Type c) → B → B → Type (a ⊔ c) R ⟶ = R ⁻¹ ;ᴱ R -- If R is a propositional equivalence relation targetting a certain -- universe, then R ⟵ is pointwise logically equivalent (with erased -- proofs) to R. ⟵≃ᴱ : {A : Type a} {R : A → A → Type a} → @0 (∀ x y → Is-proposition (R x y)) → Is-equivalence-relation R → ∀ {x y} → (R ⟵) x y ≃ᴱ R x y ⟵≃ᴱ prop equiv = EEq.⇔→≃ᴱ T.truncation-is-proposition (prop _ _) (T.rec λ where .T.truncation-is-propositionʳ → prop _ _ .T.∣∣ʳ (_ , Rxy , Rzy) → E.transitive Rxy (E.symmetric Rzy)) (λ Rxz → ∣ _ , Rxz , E.reflexive ∣) where module E = Is-equivalence-relation equiv -- If R is a propositional equivalence relation targetting a certain -- universe, then R ⟶ is pointwise logically equivalent (with erased -- proofs) to R. ⟶≃ᴱ : {A : Type a} {R : A → A → Type a} → @0 (∀ x y → Is-proposition (R x y)) → Is-equivalence-relation R → ∀ {x y} → (R ⟶) x y ≃ᴱ R x y ⟶≃ᴱ prop equiv = EEq.⇔→≃ᴱ T.truncation-is-proposition (prop _ _) (T.rec λ where .T.truncation-is-propositionʳ → prop _ _ .T.∣∣ʳ (_ , Ryx , Ryz) → E.transitive (E.symmetric Ryx) Ryz) (λ Rzx → ∣ _ , E.symmetric Rzx , E.reflexive ∣) where module E = Is-equivalence-relation equiv -- If R is a propositional equivalence relation targetting a certain -- universe, then R ⟵ is equal to R (in erased contexts). @0 ⟵≡ : {A : Type a} {R : A → A → Type a} → (∀ x y → Is-proposition (R x y)) → Is-equivalence-relation R → R ⟵ ≡ R ⟵≡ prop equiv = ⟨ext⟩ λ _ → ⟨ext⟩ λ _ → ≃⇒≡ U.univ $ EEq.≃ᴱ→≃ $ ⟵≃ᴱ prop equiv -- If R is a propositional equivalence relation targetting a certain -- universe, then R ⟶ is equal to R (in erased contexts). @0 ⟶≡ : {A : Type a} {R : A → A → Type a} → (∀ x y → Is-proposition (R x y)) → Is-equivalence-relation R → R ⟶ ≡ R ⟶≡ prop equiv = ⟨ext⟩ λ _ → ⟨ext⟩ λ _ → ≃⇒≡ U.univ $ EEq.≃ᴱ→≃ $ ⟶≃ᴱ prop equiv -- The graph of a function. Graph : {A : Type a} {B : Type b} → (A → B) → A → B → Type b Graph f x y = f x ≡ y -- If R is a propositional equivalence relation targetting a certain -- universe, then Graph (Q.[_] {R = R}) ⟵ is equal to R (in erased -- contexts). @0 Graph-[]-⟵≡ : {A : Type a} {R : A → A → Type a} → (∀ x y → Is-proposition (R x y)) → Is-equivalence-relation R → Graph (Q.[_] {R = R}) ⟵ ≡ R Graph-[]-⟵≡ {R = R} prop equiv = ⟨ext⟩ λ x → ⟨ext⟩ λ y → let lemma = Eq.⇔→≃ T.truncation-is-proposition Q./ᴱ-is-set (T.rec λ @0 where .T.truncation-is-propositionʳ → Q./ᴱ-is-set .T.∣∣ʳ (_ , [x]≡z , [y]≡z) → trans [x]≡z (sym [y]≡z)) (λ [x]≡[y] → ∣ _ , [x]≡[y] , refl _ ∣) in ≃⇒≡ U.univ ((Graph [_] ⟵) x y ↝⟨ lemma ⟩ [ x ] ≡ [ y ] ↔⟨ inverse $ Q.related≃[equal] equiv (prop _ _) ⟩□ R x y □) -- If R is a propositional equivalence relation, then -- R ;ᴱ Graph ([_] {R = R}) is equal to Graph ([_] {R = R}) (in erased -- contexts). @0 ;ᴱ-Graph-[]≡Graph-[] : {A : Type a} {R : A → A → Type r} → (∀ x y → Is-proposition (R x y)) → Is-equivalence-relation R → R ;ᴱ Graph ([_] {R = R}) ≡ Graph ([_] {R = R}) ;ᴱ-Graph-[]≡Graph-[] {R = R} prop equiv = ⟨ext⟩ λ x → ⟨ext⟩ λ y → ≃⇒≡ U.univ $ flip (Q.elim-prop {P = λ y → (R ;ᴱ Graph ([_] {R = R})) x y ≃ Graph ([_] {R = R}) x y}) y λ @0 where .Q.is-propositionʳ _ → Eq.left-closure ext 0 $ T.truncation-is-proposition .Q.[]ʳ y → Eq.⇔→≃ T.truncation-is-proposition Q./ᴱ-is-set (T.rec λ @0 where .T.Rec.truncation-is-propositionʳ → Q./ᴱ-is-set .T.Rec.∣∣ʳ (z , Rxz , [z]≡[y]) → [ x ] ≡⟨ Q.[]-respects-relation Rxz ⟩ [ z ] ≡⟨ [z]≡[y] ⟩∎ [ y ] ∎) ([ x ] ≡ [ y ] ↔⟨ inverse $ Q.related≃[equal] equiv (prop _ _) ⟩ R x y ↝⟨ (λ Rxy → ∣ _ , Rxy , refl _ ∣) ⟩ (R ;ᴱ Graph [_]) x [ y ] □) ------------------------------------------------------------------------ -- Quasi-equivalence relations -- Quasi-PERs, or zigzag-complete relations (following Krishnaswami -- and Dreyer, see "Internalizing Relational Parametricity in the -- Extensional Calculus of Constructions"). -- -- Angiuli et al. only define what it means to be a quasi-PER for -- propositional relations. The following definition applies to -- arbitrary relations. Is-QPER : {A : Type a} {B : Type b} → (A → B → Type c) → Type (a ⊔ b ⊔ c) Is-QPER R = ∀ {x x′ y y′} → R x y → R x′ y → R x′ y′ → R x y′ -- Quasi-equivalence relations (QERs), defined using ∥_∥ᴱ instead of -- ∥_∥. Is-QER : {A : Type a} {B : Type b} → (A → B → Type c) → Type (a ⊔ b ⊔ c) Is-QER R = Is-QPER R × (∀ x → ∥ ∃ (λ y → R x y) ∥ᴱ) × (∀ y → ∥ ∃ (λ x → R x y) ∥ᴱ) -- Quasi-equivalence relations (QERs), defined using ∥_∥ᴱ instead of -- ∥_∥, and with some parts erased. Is-QERᴱ : {A : Type a} {B : Type b} → @0 (A → B → Type c) → Type (a ⊔ b ⊔ c) Is-QERᴱ R = Erased (Is-QPER R) × (∀ x → ∥ ∃ (λ y → Erased (R x y)) ∥ᴱ) × (∀ y → ∥ ∃ (λ x → Erased (R x y)) ∥ᴱ) -- Is-QERᴱ can be expressed using Is-QER and Erased. Is-QERᴱ≃Is-QER-Erased : {@0 R : A → B → Type r} → Is-QERᴱ R ≃ Is-QER (λ x y → Erased (R x y)) Is-QERᴱ≃Is-QER-Erased {A = A} {B = B} {R = R} = ×-cong₁ λ _ → Erased (∀ {x x′ y y′} → R x y → R x′ y → R x′ y′ → R x y′) ↝⟨ Erased-cong lemma ⟩ Erased (∀ x x′ y y′ → R x y → R x′ y → R x′ y′ → R x y′) ↔⟨ (∀-cong ext λ _ → (∀-cong ext λ _ → (∀-cong ext λ _ → Erased-Π↔Π) F.∘ Erased-Π↔Π) F.∘ Erased-Π↔Π) F.∘ Erased-Π↔Π ⟩ (∀ x x′ y y′ → Erased (R x y → R x′ y → R x′ y′ → R x y′)) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ → (∀-cong ext λ _ → (∀-cong ext λ _ → Erased-Π↔Π-Erased) F.∘ Erased-Π↔Π-Erased) F.∘ Erased-Π↔Π-Erased) ⟩ (∀ x x′ y y′ → Erased (R x y) → Erased (R x′ y) → Erased (R x′ y′) → Erased (R x y′)) ↝⟨ inverse lemma ⟩□ (∀ {x x′ y y′} → Erased (R x y) → Erased (R x′ y) → Erased (R x′ y′) → Erased (R x y′)) □ where lemma : {P : A → A → B → B → Type r} → (∀ {x x′ y y′} → P x x′ y y′) ≃ (∀ x x′ y y′ → P x x′ y y′) lemma = Eq.↔⇒≃ $ (∀-cong ext λ _ → (∀-cong ext λ _ → (∀-cong ext λ _ → B.implicit-Π↔Π) F.∘ B.implicit-Π↔Π) F.∘ B.implicit-Π↔Π) F.∘ B.implicit-Π↔Π -- Is-QER R implies Is-QERᴱ R. Is-QER→Is-QERᴱ : Is-QER R → Is-QERᴱ R Is-QER→Is-QERᴱ = [_]→ ×-cong (∀-cong _ λ x → T.∥∥ᴱ-map $ ∃-cong λ _ → [_]→) ×-cong (∀-cong _ λ x → T.∥∥ᴱ-map $ ∃-cong λ _ → [_]→) -- In erased contexts Is-QER R is equivalent to Is-QERᴱ R. @0 Is-QER≃Is-QERᴱ : Is-QER R ≃ Is-QERᴱ R Is-QER≃Is-QERᴱ = Eq.↔⇒≃ $ inverse $ Erased↔ .erased ×-cong (∀-cong ext λ x → T.∥∥ᴱ-cong $ ∃-cong λ _ → Erased↔ .erased) ×-cong (∀-cong ext λ x → T.∥∥ᴱ-cong $ ∃-cong λ _ → Erased↔ .erased) -- The forward direction of Is-QER≃Is-QERᴱ {R = R} is definitionally -- equal to Is-QER→Is-QERᴱ. _ : _≃_.to (Is-QER≃Is-QERᴱ {R = R}) ≡ Is-QER→Is-QERᴱ _ = refl _ -- If Is-QER R holds, then R ⟵ is an equivalence relation. Is-QER→Is-equivalence-relation-⟵ : Is-QER R → Is-equivalence-relation (R ⟵) Is-QER→Is-equivalence-relation-⟵ (qper , lr , rl) = λ where .Is-equivalence-relation.reflexive {x = x} → T.∥∥ᴱ-map (λ (y , Rxy) → y , Rxy , Rxy) (lr x) .Is-equivalence-relation.symmetric → T.∥∥ᴱ-map (Σ-map id swap) .Is-equivalence-relation.transitive → T.rec λ where .T.truncation-is-propositionʳ → Π-closure ext 1 λ _ → T.truncation-is-proposition .T.∣∣ʳ (_ , Rx₁y₁ , Rx₂y₁) → T.∥∥ᴱ-map λ (_ , Rx₂y₂ , Rx₃y₂) → _ , qper Rx₁y₁ Rx₂y₁ Rx₂y₂ , Rx₃y₂ -- If Is-QERᴱ R holds, then R ⟵ is an equivalence relation (in erased -- contexts). @0 Is-QERᴱ→Is-equivalence-relation-⟵ : Is-QERᴱ R → Is-equivalence-relation (R ⟵) Is-QERᴱ→Is-equivalence-relation-⟵ {R = R} = Is-QERᴱ R ↔⟨ inverse Is-QER≃Is-QERᴱ ⟩ Is-QER R ↝⟨ Is-QER→Is-equivalence-relation-⟵ ⟩□ Is-equivalence-relation (R ⟵) □ -- If Is-QER R holds, then R ⟶ is an equivalence relation. Is-QER→Is-equivalence-relation-⟶ : Is-QER R → Is-equivalence-relation (R ⟶) Is-QER→Is-equivalence-relation-⟶ (qper , lr , rl) = λ where .Is-equivalence-relation.reflexive {x = y} → T.∥∥ᴱ-map (λ (x , Rxy) → x , Rxy , Rxy) (rl y) .Is-equivalence-relation.symmetric → T.∥∥ᴱ-map (Σ-map id swap) .Is-equivalence-relation.transitive → T.rec λ where .T.truncation-is-propositionʳ → Π-closure ext 1 λ _ → T.truncation-is-proposition .T.∣∣ʳ (_ , Rx₁y₁ , Rx₁y₂) → T.∥∥ᴱ-map λ (_ , Rx₂y₂ , Rx₂y₃) → _ , qper Rx₂y₂ Rx₁y₂ Rx₁y₁ , Rx₂y₃ -- If Is-QERᴱ R holds, then R ⟶ is an equivalence relation (in erased -- contexts). @0 Is-QERᴱ→Is-equivalence-relation-⟶ : Is-QERᴱ R → Is-equivalence-relation (R ⟶) Is-QERᴱ→Is-equivalence-relation-⟶ {R = R} = Is-QERᴱ R ↔⟨ inverse Is-QER≃Is-QERᴱ ⟩ Is-QER R ↝⟨ Is-QER→Is-equivalence-relation-⟶ ⟩□ Is-equivalence-relation (R ⟶) □ -- A propositional QER R can be turned into an equivalence (with -- erased proofs) satisfying a certain (partly erased) condition. -- -- This is a variant of Lemma 5.4 from "Internalizing Representation -- Independence with Univalence". /ᴱ⟵≃ᴱ/ᴱ⟶ : Is-QER R → @0 (∀ x y → Is-proposition (R x y)) → ∃ λ (eq : A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶) → ∀ x y → ∃ λ (f : _≃ᴱ_.to eq [ x ] ≡ [ y ] → R x y) → Erased (Is-equivalence f) /ᴱ⟵≃ᴱ/ᴱ⟶ {A = A} {B = B} {R = R} qer@(qper , lr , rl) prop = EEq.↔→≃ᴱ to from to-from from-to , (λ _ _ → to″ , [ _≃_.is-equivalence $ Eq.⇔→≃ Q./ᴱ-is-set (prop _ _) to″ from″ ]) where to′ : ∥ ∃ (R x) ∥ᴱ → B /ᴱ R ⟶ to′ = _≃_.to (Q.Σ→Erased-Constant≃∥∥ᴱ→ Q./ᴱ-is-set) ( [_] ∘ proj₁ , [ (λ (_ , r₁) (_ , r₂) → Q.[]-respects-relation ∣ _ , r₁ , r₂ ∣) ] ) @0 to′-lemma : R x y → R x′ y → (p : ∥ ∃ (R x) ∥ᴱ) (p′ : ∥ ∃ (R x′) ∥ᴱ) → to′ p ≡ to′ p′ to′-lemma Rxy Rx′y = T.elim λ @0 where .T.truncation-is-propositionʳ _ → Π-closure ext 1 λ _ → Q./ᴱ-is-set .T.∣∣ʳ (y₁ , Rxy₁) → T.elim λ @0 where .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set .T.∣∣ʳ (y₂ , Rx′y₂) → [ y₁ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rxy₁ , qper Rxy Rx′y Rx′y₂ ∣ ⟩∎ [ y₂ ] ∎ to : A /ᴱ R ⟵ → B /ᴱ R ⟶ to = Q.rec λ where .Q.is-setʳ → Q./ᴱ-is-set .Q.[]ʳ → to′ ∘ lr .Q.[]-respects-relationʳ {x = x} {y = x′} → T.elim λ @0 where .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set .T.∣∣ʳ (_ , Rxy , Rx′y) → to′ (lr x) ≡⟨ to′-lemma Rxy Rx′y (lr x) (lr x′) ⟩∎ to′ (lr x′) ∎ from′ : ∥ ∃ ((R ⁻¹) y) ∥ᴱ → A /ᴱ R ⟵ from′ = _≃_.to (Q.Σ→Erased-Constant≃∥∥ᴱ→ Q./ᴱ-is-set) ( [_] ∘ proj₁ , [ (λ (_ , r₁) (_ , r₂) → Q.[]-respects-relation ∣ _ , r₁ , r₂ ∣) ] ) @0 from′-lemma : R x y → R x y′ → (p : ∥ ∃ ((R ⁻¹) y) ∥ᴱ) (p′ : ∥ ∃ ((R ⁻¹) y′) ∥ᴱ) → from′ p ≡ from′ p′ from′-lemma Rxy Rxy′ = T.elim λ @0 where .T.truncation-is-propositionʳ _ → Π-closure ext 1 λ _ → Q./ᴱ-is-set .T.∣∣ʳ (x₁ , Rx₁y) → T.elim λ @0 where .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set .T.∣∣ʳ (x₂ , Rx₂y′) → [ x₁ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rx₁y , qper Rx₂y′ Rxy′ Rxy ∣ ⟩∎ [ x₂ ] ∎ from : B /ᴱ R ⟶ → A /ᴱ R ⟵ from = Q.rec λ where .Q.is-setʳ → Q./ᴱ-is-set .Q.[]ʳ → from′ ∘ rl .Q.[]-respects-relationʳ {x = y} {y = y′} → T.elim λ @0 where .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set .T.∣∣ʳ (_ , Rxy , Rxy′) → from′ (rl y) ≡⟨ from′-lemma Rxy Rxy′ (rl y) (rl y′) ⟩∎ from′ (rl y′) ∎ @0 to′≡[] : R x y → (p : ∥ ∃ (R x) ∥ᴱ) → to′ p ≡ [ y ] to′≡[] {x = x} {y = y} Rxy = T.elim λ @0 where .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set .T.∣∣ʳ (y′ , Rxy′) → [ y′ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rxy′ , Rxy ∣ ⟩∎ [ y ] ∎ @0 to-from′ : ∀ y (p : ∥ ∃ ((R ⁻¹) y) ∥ᴱ) → to (from′ p) ≡ [ y ] to-from′ y = T.elim λ @0 where .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set .T.∣∣ʳ (x , Rxy) → to′ (lr x) ≡⟨ to′≡[] Rxy (lr x) ⟩∎ [ y ] ∎ @0 to-from : ∀ y → to (from y) ≡ y to-from = Q.elim-prop λ @0 where .Q.is-propositionʳ _ → Q./ᴱ-is-set .Q.[]ʳ y → to (from′ (rl y)) ≡⟨ to-from′ y (rl y) ⟩∎ [ y ] ∎ @0 from′≡[] : R x y → (p : ∥ ∃ ((R ⁻¹) y) ∥ᴱ) → from′ p ≡ [ x ] from′≡[] {x = x} {y = y} Rxy = T.elim λ @0 where .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set .T.∣∣ʳ (x′ , Rx′y) → [ x′ ] ≡⟨ Q.[]-respects-relation ∣ _ , Rx′y , Rxy ∣ ⟩∎ [ x ] ∎ @0 from-to′ : ∀ x (p : ∥ ∃ (R x) ∥ᴱ) → from (to′ p) ≡ [ x ] from-to′ x = T.elim λ @0 where .T.truncation-is-propositionʳ _ → Q./ᴱ-is-set .T.∣∣ʳ (y , Rxy) → from′ (rl y) ≡⟨ from′≡[] Rxy (rl y) ⟩∎ [ x ] ∎ @0 from-to : ∀ x → from (to x) ≡ x from-to = Q.elim-prop λ @0 where .Q.is-propositionʳ _ → Q./ᴱ-is-set .Q.[]ʳ x → from (to′ (lr x)) ≡⟨ from-to′ x (lr x) ⟩∎ [ x ] ∎ to″ : to [ x ] ≡ [ y ] → R x y to″ {x = x} {y = y} = to′ (lr x) ≡ [ y ] ↝⟨ flip (T.elim {P = λ p → to′ p ≡ [ y ] → R x y}) (lr x) (λ where .T.truncation-is-propositionʳ _ → Π-closure ext 1 λ _ → prop _ _ .T.∣∣ʳ (y′ , Rxy′) → [ y′ ] ≡ [ y ] ↝⟨ Q.effective (Is-QER→Is-equivalence-relation-⟶ qer) T.truncation-is-proposition ∣ _ , Rxy′ , Rxy′ ∣ ⟩ (R ⟶) y′ y ↝⟨ T.rec (λ where .T.truncation-is-propositionʳ → prop _ _ .T.∣∣ʳ (_ , Rx′y′ , Rx′y) → qper Rxy′ Rx′y′ Rx′y) ⟩□ R x y □) ⟩□ R x y □ @0 from″ : R x y → to [ x ] ≡ [ y ] from″ {x = x} {y = y} Rxy = to′ (lr x) ≡⟨ to′≡[] Rxy (lr x) ⟩∎ [ y ] ∎ -- A propositional QER R (with erased proofs) can be turned into an -- equivalence (with erased proofs) satisfying a certain (erased) -- condition. -- -- This is another variant of Lemma 5.4 from "Internalizing -- Representation Independence with Univalence". /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ : {@0 R : A → B → Type c} → Is-QERᴱ R → @0 (∀ x y → Is-proposition (R x y)) → ∃ λ (eq : A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶) → Erased (∀ x y → (_≃ᴱ_.to eq [ x ] ≡ [ y ]) ≃ R x y) /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ {A = A} {B = B} {R = R} qer prop = $⟨ [ prop ] ⟩ Erased (∀ x y → Is-proposition (R x y)) ↝⟨ (λ ([ hyp ]) x y → H-level-Erased 1 (hyp x y)) ⦂ (_ → _) ⟩ (∀ x y → Is-proposition (Rᴱ x y)) ↝⟨ (λ prop → /ᴱ⟵≃ᴱ/ᴱ⟶ (_≃_.to Is-QERᴱ≃Is-QER-Erased qer) prop) ⟩ (∃ λ (eq : A /ᴱ Rᴱ ⟵ ≃ᴱ B /ᴱ Rᴱ ⟶) → ∀ x y → ∃ λ (f : _≃ᴱ_.to eq [ x ] ≡ [ y ] → Rᴱ x y) → Erased (Is-equivalence f)) ↝⟨ (λ (eq , ok) → drop-ᴱ eq , [ drop-ᴱ-ok eq ok ]) ⟩□ (∃ λ (eq : A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶) → Erased (∀ x y → (_≃ᴱ_.to eq [ x ] ≡ [ y ]) ≃ R x y)) □ where Rᴱ = λ x y → Erased (R x y) @0 lemma : ∀ x y → ((λ x y → Erased (R₁ x y)) ;ᴱ (λ x y → Erased (R₂ x y))) x y ⇔ (R₁ ;ᴱ R₂) x y lemma {R₁ = R₁} {R₂ = R₂} x z = ∥ (∃ λ y → Erased (R₁ x y) × Erased (R₂ y z)) ∥ᴱ ↔⟨ (T.∥∥ᴱ-cong $ ∃-cong λ _ → Erased↔ .erased ×-cong Erased↔ .erased) ⟩□ ∥ (∃ λ y → R₁ x y × R₂ y z) ∥ᴱ □ drop-ᴱ : A /ᴱ Rᴱ ⟵ ≃ᴱ B /ᴱ Rᴱ ⟶ → A /ᴱ R ⟵ ≃ᴱ B /ᴱ R ⟶ drop-ᴱ eq = A /ᴱ R ⟵ ↔⟨ Eq.id Q./ᴱ-cong (λ x y → inverse (lemma {R₁ = R} {R₂ = R ⁻¹} x y)) ⟩ A /ᴱ Rᴱ ⟵ ↝⟨ eq ⟩ B /ᴱ Rᴱ ⟶ ↔⟨ Eq.id Q./ᴱ-cong lemma ⟩□ B /ᴱ R ⟶ □ @0 drop-ᴱ-ok : (eq : A /ᴱ Rᴱ ⟵ ≃ᴱ B /ᴱ Rᴱ ⟶) → (∀ x y → ∃ λ (f : _≃ᴱ_.to eq [ x ] ≡ [ y ] → Rᴱ x y) → Erased (Is-equivalence f)) → ∀ x y → (_≃ᴱ_.to (drop-ᴱ eq) [ x ] ≡ [ y ]) ≃ R x y drop-ᴱ-ok eq ok x y = _≃ᴱ_.to (drop-ᴱ eq) [ x ] ≡ [ y ] ↔⟨⟩ _≃_.to (Eq.id Q./ᴱ-cong lemma) (_≃ᴱ_.to eq [ x ]) ≡ [ y ] ↝⟨ Eq.≃-≡ (Eq.id Q./ᴱ-cong lemma) ⟩ _≃ᴱ_.to eq [ x ] ≡ [ y ] ↝⟨ (let f , [ eq ] = ok x y in Eq.⟨ f , eq ⟩) ⟩ Rᴱ x y ↔⟨ Erased↔ .erased ⟩□ R x y □ ------------------------------------------------------------------------ -- Relation transformers -- Relation transformers for a given structure. Relation-transformer-for : Structure a b → Type (lsuc (a ⊔ b)) Relation-transformer-for {a = a} {b = b} F = ∀ {A B} → (A → B → Type a) → F A → F B → Type b -- A notion of "suitable" relation transformers. record Suitable {F : Structure a b} (@0 G : Relation-transformer-for F) : Type (lsuc a ⊔ b) where field -- F preserves Is-set. @0 preserves-is-set : Is-set A → Is-set (F A) -- G preserves a variant of Is-proposition. @0 preserves-is-proposition : (∀ x y → Is-proposition (R x y)) → ∀ x y → Is-proposition (G R x y) -- G is "symmetric" for propositional relations. @0 symmetric : (∀ x y → Is-proposition (R x y)) → G R x y → G (R ⁻¹) y x -- G is "transitive" for propositional relations. @0 transitive : (∀ x y → Is-proposition (R x y)) → (∀ x y → Is-proposition (S x y)) → G R x y → G S y z → G (R ;ᴱ S) x z -- Descent to quotients. Note that this is the only non-erased -- field of this record type. descent : {@0 R : A → A → Type a} → @0 (∀ x y → Is-proposition (R x y)) → @0 Is-equivalence-relation R → @0 G R x x → Contractibleᴱ (∃ λ (y : F (A /ᴱ R)) → Erased (G (Graph [_]) x y)) -- A variant of transitive. @0 transitive-;ᴱ : (∀ x y → Is-proposition (R x y)) → (∀ x y → Is-proposition (S x y)) → ∀ x z → (G R ;ᴱ G S) x z → G (R ;ᴱ S) x z transitive-;ᴱ R-prop S-prop _ _ = T.rec λ @0 where .T.truncation-is-propositionʳ → preserves-is-proposition (λ _ _ → T.truncation-is-proposition) _ _ .T.∣∣ʳ (_ , GRxy , GSyz) → transitive R-prop S-prop GRxy GSyz -- A variant of Univalent for relation transformers. Univalentᴿ : {F : Structure a b} → @0 Relation-transformer-for F → Type (lsuc a ⊔ b) Univalentᴿ {F = F} G = Suitable G × Univalent F (λ (A , x) (B , y) eq → G (Graph (_≃ᴱ_.to eq)) x y) -- A notion of "acting on functions" for relation transformers. record Acts-on-functions {F : Structure a b} (@0 G : Relation-transformer-for F) : Type (lsuc a ⊔ b) where field -- A map function. map : (A → B) → F A → F B -- Mapping the identity function is the same thing as applying the -- identity function. @0 map-id : map {A = A} id ≡ id -- G respects map in a certain way. @0 map-map : {R₁ : A₁ → B₁ → Type a} {R₂ : A₂ → B₂ → Type a} → (∀ {x y} → R₁ x y → R₂ (f x) (g y)) → G R₁ x y → G R₂ (map f x) (map g y) -- Suitable respects equivalences. Suitable-map : {@0 G H : Relation-transformer-for F} → @0 (∀ {A B} {R : A → B → _} {x y} → G R x y ≃ H R x y) → Suitable G → Suitable H Suitable-map {G = G} {H = H} G≃H s-G = λ where .Suitable.preserves-is-set → S.preserves-is-set .Suitable.preserves-is-proposition {R = R} → (∀ x y → Is-proposition (R x y)) ↝⟨ S.preserves-is-proposition ⟩ (∀ x y → Is-proposition (G R x y)) ↝⟨ (∀-cong _ λ _ → ∀-cong _ λ _ → H-level-cong _ 1 G≃H) ⟩□ (∀ x y → Is-proposition (H R x y)) □ .Suitable.symmetric {R = R} {x = x} {y = y} → (∀ x y → Is-proposition (R x y)) ↝⟨ S.symmetric ⟩ (G R x y → G (R ⁻¹) y x) ↝⟨ →-cong-→ (_≃_.from G≃H) (_≃_.to G≃H) ⟩□ (H R x y → H (R ⁻¹) y x) □ .Suitable.transitive {R = R} {S = S} {x = x} {y = y} {z = z} → curry ((∀ x y → Is-proposition (R x y)) × (∀ x y → Is-proposition (S x y)) ↝⟨ uncurry S.transitive ⟩ (G R x y → G S y z → G (R ;ᴱ S) x z) ↝⟨ →-cong-→ (_≃_.from G≃H) (→-cong-→ (_≃_.from G≃H) (_≃_.to G≃H)) ⟩□ (H R x y → H S y z → H (R ;ᴱ S) x z) □) .Suitable.descent {x = x} {R = R} prop equiv HRxx → $⟨ [ HRxx ] ⟩ Erased (H R x x) ↔⟨ Erased-cong (inverse G≃H) ⟩ Erased (G R x x) ↝⟨ (λ ([ hyp ]) → S.descent prop equiv hyp) ⦂ (_ → _) ⟩ Contractibleᴱ (∃ λ y → Erased (G (Graph [_]) x y)) ↝⟨ ECP.Contractibleᴱ-cong _ (∃-cong λ _ → Erased-cong G≃H) ⟩□ Contractibleᴱ (∃ λ y → Erased (H (Graph [_]) x y)) □ where module S = Suitable s-G -- If R is a propositional QER (with erased proofs) between A and B, G -- is a suitable relation transformer for F, and G R x y holds, then -- there are structures in F (A /ᴱ R ⟵) and F (B /ᴱ R ⟶) that are -- related in a certain way to x and y, respectively, and the two -- structures are also related to each other by /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ in a certain -- way. -- -- This is a variant of Theorem 5.7 from "Internalizing Representation -- Independence with Univalence". Note that quite a few inputs are -- erased, and also parts of the result. Suitable→/ᴱ⟵×/ᴱ⟶ : {F : Structure a b} ((A , x) (B , y) : Type-with F) → {@0 R : A → B → Type a} {@0 G : Relation-transformer-for F} → Suitable G → (qer : Is-QERᴱ R) (@0 prop : ∀ x y → Is-proposition (R x y)) → @0 G R x y → ∃ λ (x′ : F (A /ᴱ R ⟵)) → ∃ λ (y′ : F (B /ᴱ R ⟶)) → Erased (G (Graph [_]) x x′ × G (Graph [_]) y y′ × G (Graph (_≃ᴱ_.to (/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₁))) x′ y′) Suitable→/ᴱ⟵×/ᴱ⟶ {F = F} (A , x) (B , y) {R = R} {G = G} s qer@([ qper ] , _) prop g = x″ , y″ , [ (Gxx″ , Gyy″ , g″) ] where module S = Suitable s @0 x∼x : G (R ⟵) x x x∼x = S.transitive prop (flip prop) g (S.symmetric prop g) @0 y∼y : G (R ⟶) y y y∼y = S.transitive (flip prop) prop (S.symmetric prop g) g x-lemma : Contractibleᴱ (∃ λ (x′ : F (A /ᴱ R ⟵)) → Erased (G (Graph [_]) x x′)) x-lemma = S.descent (λ _ _ → T.truncation-is-proposition) (Is-QERᴱ→Is-equivalence-relation-⟵ qer) x∼x y-lemma : Contractibleᴱ (∃ λ (y′ : F (B /ᴱ R ⟶)) → Erased (G (Graph [_]) y y′)) y-lemma = S.descent (λ _ _ → T.truncation-is-proposition) (Is-QERᴱ→Is-equivalence-relation-⟶ qer) y∼y x″ = x-lemma .proj₁ .proj₁ y″ = y-lemma .proj₁ .proj₁ @0 Gxx″ : G (Graph [_]) x x″ Gxx″ = x-lemma .proj₁ .proj₂ .erased @0 Gyy″ : G (Graph [_]) y y″ Gyy″ = y-lemma .proj₁ .proj₂ .erased @0 g′ : G (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) x″ y″ g′ = S.transitive (λ _ _ → Q./ᴱ-is-set) (λ _ _ → T.truncation-is-proposition) (S.symmetric (λ _ _ → Q./ᴱ-is-set) Gxx″) (S.transitive prop (λ _ _ → Q./ᴱ-is-set) g Gyy″) equiv = /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₁ @0 to : ∀ {x y} → (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) [ x ] [ y ] → R x y to {x = x} {y = y} = T.rec λ @0 where .T.truncation-is-propositionʳ → prop _ _ .T.∣∣ʳ → uncurry λ x′ → uncurry λ [x′]≡[x] → T.rec λ @0 where .T.truncation-is-propositionʳ → prop _ _ .T.∣∣ʳ (y′ , Rx′y′ , [y′]≡[y]) → let R⟵x′x : (R ⟵) x′ x R⟵x′x = _≃_.from (Q.related≃[equal] (Is-QERᴱ→Is-equivalence-relation-⟵ qer) T.truncation-is-proposition) [x′]≡[x] R⟶y′y : (R ⟶) y′ y R⟶y′y = _≃_.from (Q.related≃[equal] (Is-QERᴱ→Is-equivalence-relation-⟶ qer) T.truncation-is-proposition) [y′]≡[y] in flip T.rec R⟵x′x λ @0 where .T.truncation-is-propositionʳ → prop _ _ .T.∣∣ʳ (_ , Rx′x″ , Rxx″) → flip T.rec R⟶y′y λ @0 where .T.truncation-is-propositionʳ → prop _ _ .T.∣∣ʳ (_ , Ry″y′ , Ry″y) → qper Rxx″ Rx′x″ (qper Rx′y′ Ry″y′ Ry″y) @0 from : ∀ {x y} → R x y → (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) [ x ] [ y ] from Rxy = ∣ _ , refl _ , ∣ _ , Rxy , refl _ ∣ ∣ @0 lemma : ∀ x y → (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) x y ≃ Graph (_≃ᴱ_.to equiv) x y lemma = Q.elim-prop λ @0 where .Q.is-propositionʳ _ → Π-closure ext 1 λ _ → Eq.left-closure ext 0 T.truncation-is-proposition .Q.[]ʳ x → Q.elim-prop λ @0 where .Q.is-propositionʳ _ → Eq.left-closure ext 0 T.truncation-is-proposition .Q.[]ʳ y → (Graph [_] ⁻¹ ;ᴱ R ;ᴱ Graph [_]) [ x ] [ y ] ↝⟨ Eq.⇔→≃ T.truncation-is-proposition (prop _ _) to from ⟩ R x y ↝⟨ inverse (/ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₂ .erased _ _) ⟩□ Graph (_≃ᴱ_.to equiv) [ x ] [ y ] □ @0 g″ : G (Graph (_≃ᴱ_.to equiv)) x″ y″ g″ = subst (λ R → G R x″ y″) (⟨ext⟩ λ x → ⟨ext⟩ λ y → ≃⇒≡ U.univ (lemma x y)) g′ -- If R is a propositional QER (with erased proofs) between A and B, G -- is a univalent relation transformer for F, and G R x y holds, then -- there are structures x′ : F (A /ᴱ R ⟵) and y′ : F (B /ᴱ R ⟶) that -- are related in a certain way to x and y, respectively, and -- furthermore the two values A /ᴱ R ⟵ , x′ and B /ᴱ R ⟶ , y′ of type -- Type-with F are equal (in erased contexts). -- -- This is a corollary of Suitable→/ᴱ⟵×/ᴱ⟶, /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ and sip. Univalentᴿ→/ᴱ⟵×/ᴱ⟶ : {F : Structure a b} ((A , x) (B , y) : Type-with F) → {@0 R : A → B → Type a} {@0 G : Relation-transformer-for F} → Univalentᴿ G → (qer : Is-QERᴱ R) (@0 prop : ∀ x y → Is-proposition (R x y)) → @0 G R x y → ∃ λ (x′ : F (A /ᴱ R ⟵)) → ∃ λ (y′ : F (B /ᴱ R ⟶)) → Erased (G (Graph [_]) x x′ × G (Graph [_]) y y′ × _≡_ {A = Type-with F} (A /ᴱ R ⟵ , x′) (B /ᴱ R ⟶ , y′)) Univalentᴿ→/ᴱ⟵×/ᴱ⟶ (A , x) (B , y) {R = R} {G = G} (s , u) qer prop g = let (x′ , y′ , [ x∼x′ , y∼y′ , x′∼y′ ]) = Suitable→/ᴱ⟵×/ᴱ⟶ (A , x) (B , y) s qer prop g in x′ , y′ , [ ( x∼x′ , y∼y′ , ( $⟨ /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ qer prop .proj₁ , [ x′∼y′ ] ⟩ (A /ᴱ R ⟵ , x′) ≃[ (λ (A , x) (B , y) eq → G (Graph (_≃ᴱ_.to eq)) x y) ]ᴱ (B /ᴱ R ⟶ , y′) ↝⟨ sip u ⟩□ (A /ᴱ R ⟵ , x′) ≡ (B /ᴱ R ⟶ , y′) □) ) ] -- If G is a suitable relation transformer (for F) that acts on -- functions, and R is a propositional equivalence relation on A, then -- there is a function from F A /ᴱ G R to F (A /ᴱ R). -- -- This is a variant of Lemma 5.10 from "Internalizing Representation -- Independence with Univalence". Note that quite a few inputs are -- erased. /ᴱ→/ᴱ : {A : Type a} {@0 R : A → A → Type a} (@0 G : Relation-transformer-for F) → Suitable G → Acts-on-functions G → @0 (∀ x y → Is-proposition (R x y)) → @0 Is-equivalence-relation R → F A /ᴱ G R → F (A /ᴱ R) /ᴱ→/ᴱ {F = F} {R = R} G s acts prop equiv = Q.rec λ where .Q.[]ʳ → map [_] .Q.is-setʳ → S.preserves-is-set Q./ᴱ-is-set .Q.[]-respects-relationʳ {x = x} {y = y} GRxy → let GRxx = $⟨ GRxy ⟩ G R x y ↝⟨ (λ GRxy → S.transitive prop (flip prop) GRxy (S.symmetric prop GRxy)) ⟩ G (R ⟵) x x ↝⟨ subst (λ R → G R _ _) (⟵≡ prop equiv) ⟩□ G R x x □ ((z , _) , [ unique ]) = $⟨ GRxx ⟩ G R x x ↝⟨ (λ GRxx → S.descent prop equiv GRxx) ⦂ (_ → _) ⟩□ Contractibleᴱ (∃ λ z → Erased (G (Graph [_]) x z)) □ lemma₁ = $⟨ map-map Q.[]-respects-relation GRxx ⟩ G (Graph [_]) (map id x) (map [_] x) ↝⟨ subst (λ x′ → G (Graph [_]) x′ (map [_] x)) (cong (_$ x) map-id) ⟩□ G (Graph [_]) x (map [_] x) □ lemma₂ = $⟨ map-map Q.[]-respects-relation GRxy ⟩ G (Graph [_]) (map id x) (map [_] y) ↝⟨ subst (λ x → G (Graph [_]) x (map [_] y)) (cong (_$ x) map-id) ⟩□ G (Graph [_]) x (map [_] y) □ in map [_] x ≡⟨ sym $ cong proj₁ (unique (_ , [ lemma₁ ])) ⟩ z ≡⟨ cong proj₁ (unique (_ , [ lemma₂ ])) ⟩∎ map [_] y ∎ where module S = Suitable s open Acts-on-functions acts -- Positive relation transformers. -- -- Angiuli et al. define this notion for suitable relation -- transformers that act on functions. This definition works for -- arbitrary relation transformers G, and instead inludes fields of -- type Suitable G and Acts-on-functions G. (In their source code -- Angiuli et al. take a third approach, with the property -- corresponding to Suitable G as a parameter, and the property -- corresponding to Acts-on-functions G as a field.) record Positive {F : Structure a b} (@0 G : Relation-transformer-for F) : Type (lsuc a ⊔ b) where field -- G is suitable. suitable : Suitable G -- G acts on functions. acts-on-functions : Acts-on-functions G -- G is reflexive for a certain relation. @0 reflexive-∥≡∥ᴱ : G (λ x y → ∥ x ≡ y ∥ᴱ) x x -- The function Suitable.transitive-;ᴱ suitable is an equivalence -- (pointwise). @0 transitive-;ᴱ⁻¹ : {R : A → B → Type a} {S : B → C → Type a} (R-prop : ∀ x y → Is-proposition (R x y)) (S-prop : ∀ x y → Is-proposition (S x y)) (x : F A) (z : F C) → Is-equivalence (Suitable.transitive-;ᴱ suitable R-prop S-prop x z) -- The function /ᴱ→/ᴱ G suitable acts-on-functions is an -- equivalence with erased proofs (pointwise). commutes-with-/ᴱ : {@0 R : A → A → Type a} (@0 prop : ∀ x y → Is-proposition (R x y)) (@0 equiv : Is-equivalence-relation R) → Is-equivalenceᴱ (/ᴱ→/ᴱ G suitable acts-on-functions prop equiv) -- G R is reflexive for propositional equivalence relations R (in -- erased contexts). @0 reflexive : (∀ x y → Is-proposition (R x y)) → Is-equivalence-relation R → ∀ x → G R x x reflexive {R = R} prop equiv x = $⟨ reflexive-∥≡∥ᴱ ⟩ G (λ x y → ∥ x ≡ y ∥ᴱ) x x ↝⟨ A.map-map (T.rec λ @0 where .T.truncation-is-propositionʳ → prop _ _ .T.∣∣ʳ x≡y → subst (R _) x≡y E.reflexive) ⟩ G R (A.map id x) (A.map id x) ↝⟨ subst (uncurry (G R)) (cong (λ f → f x , f x) A.map-id) ⟩□ G R x x □ where module A = Acts-on-functions acts-on-functions module E = Is-equivalence-relation equiv ------------------------------------------------------------------------ -- The Const and Constᴿ combinators, along with some properties -- Constant structures. Const : Type b → Structure a b Const B = λ _ → B -- Relation transformers for Const. Constᴿ : (B : Type b) → Relation-transformer-for (Const {a = a} B) Constᴿ _ _ = _≡_ -- When is an equivalence structure-preserving for Const? Is-Const-equivalence : {B : Type b} → Structure-preserving-equivalence-predicate (Const {a = a} B) b Is-Const-equivalence (_ , x) (_ , y) _ = x ≡ y -- Const and Is-Const-equivalence are univalent. Const-univalent : Univalent (Const {a = a} B) Is-Const-equivalence Const-univalent {B = B} .Univalent.univalent {A = _ , x} {B = _ , y} eq = x ≡ y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ subst-const _ ⟩□ subst (Const B) (≃⇒≡ U.abstract-univ (EEq.≃ᴱ→≃ eq)) x ≡ y □ -- Constᴿ is suitable for sets. Constᴿ-suitable : @0 Is-set B → Suitable (Constᴿ {a = a} B) Constᴿ-suitable set = λ where .Suitable.preserves-is-set _ → set .Suitable.preserves-is-proposition _ _ _ → set .Suitable.symmetric _ → sym .Suitable.transitive _ _ → trans .Suitable.descent _ _ _ → Contractibleᴱ-Erased-other-singleton -- Constᴿ is univalent for sets. Constᴿ-univalent : @0 Is-set B → Univalentᴿ (Constᴿ {a = a} B) Constᴿ-univalent set = Constᴿ-suitable set , Const-univalent -- Constᴿ acts on functions. Constᴿ-acts-on-functions : Acts-on-functions (Constᴿ {a = a} B) Constᴿ-acts-on-functions = λ where .Acts-on-functions.map _ → id .Acts-on-functions.map-id → refl _ .Acts-on-functions.map-map _ → id -- Constᴿ is positive for sets. Constᴿ-positive : @0 Is-set B → Positive (Constᴿ {a = a} B) Constᴿ-positive {B = B} set = λ where .Positive.suitable → Constᴿ-suitable set .Positive.acts-on-functions → Constᴿ-acts-on-functions .Positive.reflexive-∥≡∥ᴱ → refl _ .Positive.transitive-;ᴱ⁻¹ {R = R} {S = S} _ _ x z → _≃_.is-equivalence ((Constᴿ B R ;ᴱ Constᴿ B S) x z ↔⟨⟩ ∥ (∃ λ y → x ≡ y × y ≡ z) ∥ᴱ ↝⟨ Eq.⇔→≃ T.truncation-is-proposition set _ (λ x≡z → ∣ _ , x≡z , refl _ ∣) ⟩ x ≡ z ↔⟨⟩ Constᴿ B (R ;ᴱ S) x z □) .Positive.commutes-with-/ᴱ {A = C} {R = R} prop equiv → _≃ᴱ_.is-equivalence $ EEq.with-other-function (Const B C /ᴱ Constᴿ B R ↔⟨⟩ B /ᴱ _≡_ ↔⟨ Q./ᴱ≡↔ set ⟩ B ↔⟨⟩ Const B (C /ᴱ R) □) (/ᴱ→/ᴱ (Constᴿ B) (Constᴿ-suitable set) Constᴿ-acts-on-functions prop equiv) (Q.elim-prop λ @0 where .Q.is-propositionʳ _ → set .Q.[]ʳ _ → refl _) ------------------------------------------------------------------------ -- The Id and Idᴿ combinators, along with some properties -- Identity structures. Id : Structure a a Id A = A -- Relation transformers for Id. Idᴿ : Relation-transformer-for (Id {a = a}) Idᴿ R = R -- When is an equivalence structure-preserving for Id? Is-Id-equivalence : Structure-preserving-equivalence-predicate Id a Is-Id-equivalence (_ , x) (_ , y) eq = _≃ᴱ_.to eq x ≡ y -- Id and Is-Id-equivalence are univalent. Id-univalent : Univalent (Id {a = a}) Is-Id-equivalence Id-univalent .Univalent.univalent {A = _ , x} {B = _ , y} eq = _≃ᴱ_.to eq x ≡ y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ cong (λ eq → _≃_.to eq x) $ sym $ _≃_.right-inverse-of (≡≃≃ univ) _ ⟩ ≡⇒→ (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ subst-id-in-terms-of-≡⇒↝ equivalence ⟩□ subst Id (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y □ where univ = U.abstract-univ -- Idᴿ is suitable. Idᴿ-suitable : Suitable (Idᴿ {a = a}) Idᴿ-suitable = λ where .Suitable.preserves-is-set → id .Suitable.preserves-is-proposition → id .Suitable.symmetric _ → id .Suitable.transitive _ _ Rxy Syz → ∣ _ , Rxy , Syz ∣ .Suitable.descent _ _ _ → Contractibleᴱ-Erased-other-singleton -- Idᴿ is univalent. Idᴿ-univalent : Univalentᴿ (Idᴿ {a = a}) Idᴿ-univalent = Idᴿ-suitable , Id-univalent -- Idᴿ acts on functions. Idᴿ-acts-on-functions : Acts-on-functions (Idᴿ {a = a}) Idᴿ-acts-on-functions = λ where .Acts-on-functions.map → id .Acts-on-functions.map-id → refl _ .Acts-on-functions.map-map f → f -- Idᴿ is positive. Idᴿ-positive : Positive (Idᴿ {a = a}) Idᴿ-positive = λ where .Positive.suitable → Idᴿ-suitable .Positive.acts-on-functions → Idᴿ-acts-on-functions .Positive.reflexive-∥≡∥ᴱ → ∣ refl _ ∣ .Positive.transitive-;ᴱ⁻¹ {R = R} {S = S} R-prop S-prop x z → _≃_.is-equivalence $ Eq.with-other-function ((Idᴿ R ;ᴱ Idᴿ S) x z ↔⟨⟩ (R ;ᴱ S) x z ↔⟨⟩ Idᴿ (R ;ᴱ S) x z □) (Suitable.transitive-;ᴱ Idᴿ-suitable R-prop S-prop x z) (T.elim λ @0 where .T.truncation-is-propositionʳ _ → H-level.⇒≡ 1 T.truncation-is-proposition .T.∣∣ʳ _ → refl _) .Positive.commutes-with-/ᴱ {A = A} {R = R} prop equiv → _≃ᴱ_.is-equivalence $ EEq.with-other-function (Id A /ᴱ Idᴿ R ↔⟨⟩ A /ᴱ R ↔⟨⟩ Id (A /ᴱ R) □) (/ᴱ→/ᴱ Idᴿ Idᴿ-suitable Idᴿ-acts-on-functions prop equiv) (Q.elim-prop λ @0 where .Q.is-propositionʳ _ → Q./ᴱ-is-set .Q.[]ʳ _ → refl _) ------------------------------------------------------------------------ -- Combinators related to Cartesian products -- Product structures. Product : Structure a b → Structure a c → Structure a (b ⊔ c) Product F G A = F A × G A -- A combinator that, given relation transformers for F and G, -- produces a relation transformer for Product F G. Productᴿ : Relation-transformer-for F → Relation-transformer-for G → Relation-transformer-for (Product F G) Productᴿ S T R = S R ×ᴾ T R -- When is an equivalence structure-preserving for Product F G? Is-Product-equivalence : Structure-preserving-equivalence-predicate F a → Structure-preserving-equivalence-predicate G b → Structure-preserving-equivalence-predicate (Product F G) (a ⊔ b) Is-Product-equivalence Is-F-eq Is-G-eq (A , x₁ , x₂) (B , y₁ , y₂) eq = Is-F-eq (A , x₁) (B , y₁) eq × Is-G-eq (A , x₂) (B , y₂) eq -- If F and G are univalent, then Product F G is univalent. Product-univalent : {@0 F : Structure a b} {@0 G : Structure a c} {@0 Is-F-eq : Structure-preserving-equivalence-predicate F d} {@0 Is-G-eq : Structure-preserving-equivalence-predicate G e} → @0 Univalent F Is-F-eq → @0 Univalent G Is-G-eq → Univalent (Product F G) (Is-Product-equivalence Is-F-eq Is-G-eq) Product-univalent {F = F} {G = G} {Is-F-eq = Is-F-eq} {Is-G-eq = Is-G-eq} u-F u-G .Univalent.univalent {A = A , x₁ , x₂} {B = B , y₁ , y₂} eq = Is-F-eq (A , x₁) (B , y₁) eq × Is-G-eq (A , x₂) (B , y₂) eq ↝⟨ u-F .Univalent.univalent eq ×-cong u-G .Univalent.univalent eq ⟩ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁ ≡ y₁ × subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₂ ≡ y₂ ↔⟨ ≡×≡↔≡ ⟩ ( subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₁ , subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x₂ ) ≡ (y₁ , y₂) ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-, _ _ ⟩□ subst (Product F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (x₁ , x₂) ≡ (y₁ , y₂) □ where univ = U.abstract-univ -- If S and T are suitable, then Productᴿ S T is suitable. Productᴿ-suitable : {@0 S : Relation-transformer-for F} {@0 T : Relation-transformer-for G} → Suitable S → Suitable T → Suitable (Productᴿ S T) Productᴿ-suitable {S = S} {T = T} s-S s-T = λ where .Suitable.preserves-is-set set → ×-closure 2 (s-S .Suitable.preserves-is-set set) (s-T .Suitable.preserves-is-set set) .Suitable.preserves-is-proposition prop _ _ → ×-closure 1 (s-S .Suitable.preserves-is-proposition prop _ _) (s-T .Suitable.preserves-is-proposition prop _ _) .Suitable.symmetric prop → Σ-map (s-S .Suitable.symmetric prop) (s-T .Suitable.symmetric prop) .Suitable.transitive prop₁ prop₂ → Σ-zip (s-S .Suitable.transitive prop₁ prop₂) (s-T .Suitable.transitive prop₁ prop₂) .Suitable.descent {x = x , y} {R = R} prop equiv (SRxx , Tryy) → $⟨ [ SRxx ] , [ Tryy ] ⟩ Erased (S R x x) × Erased (T R y y) ↝⟨ Σ-map (λ ([ SRxx ]) → s-S .Suitable.descent prop equiv SRxx) (λ ([ TRyy ]) → s-T .Suitable.descent prop equiv TRyy) ⟩ Contractibleᴱ (∃ λ x′ → Erased (S (Graph [_]) x x′)) × Contractibleᴱ (∃ λ y′ → Erased (T (Graph [_]) y y′)) ↝⟨ uncurry ECP.Contractibleᴱ-× ⟩ Contractibleᴱ ((∃ λ x′ → Erased (S (Graph [_]) x x′)) × (∃ λ y′ → Erased (T (Graph [_]) y y′))) ↝⟨ ECP.Contractibleᴱ-cong _ $ Σ-assoc F.∘ (∃-cong λ _ → ∃-cong λ _ → inverse Erased-Σ↔Σ) F.∘ (∃-cong λ _ → ∃-comm) F.∘ inverse Σ-assoc ⟩□ Contractibleᴱ (∃ λ p → Erased (Productᴿ S T (Graph [_]) (x , y) p)) □ -- If S and T are univalent, then Productᴿ S T is univalent. Productᴿ-univalent : {@0 S : Relation-transformer-for F} {@0 T : Relation-transformer-for G} → Univalentᴿ S → Univalentᴿ T → Univalentᴿ (Productᴿ S T) Productᴿ-univalent (s-S , u-S) (s-T , u-T) = Productᴿ-suitable s-S s-T , Product-univalent u-S u-T -- If S and T act on functions, then Productᴿ S T acts on functions. Productᴿ-acts-on-functions : {@0 S : Relation-transformer-for F} {@0 T : Relation-transformer-for G} → Acts-on-functions S → Acts-on-functions T → Acts-on-functions (Productᴿ S T) Productᴿ-acts-on-functions {S = S} {T = T} a-S a-T = λ where .Acts-on-functions.map f → Σ-map (a-S .Acts-on-functions.map f) (a-T .Acts-on-functions.map f) .Acts-on-functions.map-id → Σ-map (a-S .Acts-on-functions.map id) (a-T .Acts-on-functions.map id) ≡⟨ cong₂ (λ f g → Σ-map f g) (a-S .Acts-on-functions.map-id) (a-T .Acts-on-functions.map-id) ⟩ Σ-map id id ≡⟨⟩ id ∎ .Acts-on-functions.map-map {f = f} {g = g} {x = x₁ , x₂} {y = y₁ , y₂} {R₁ = R₁} {R₂ = R₂} R₁→R₂ → S R₁ x₁ y₁ × T R₁ x₂ y₂ ↝⟨ a-S .Acts-on-functions.map-map R₁→R₂ ×-cong a-T .Acts-on-functions.map-map R₁→R₂ ⟩□ S R₂ (a-S .Acts-on-functions.map f x₁) (a-S .Acts-on-functions.map g y₁) × T R₂ (a-T .Acts-on-functions.map f x₂) (a-T .Acts-on-functions.map g y₂) □ -- If S and T are positive, then Productᴿ S T is positive. Productᴿ-positive : {@0 S : Relation-transformer-for F} {@0 T : Relation-transformer-for G} → Positive S → Positive T → Positive (Productᴿ S T) Productᴿ-positive {F = F} {G = G} {S = S} {T = T} p-S p-T = λ where .Positive.suitable → suitable .Positive.acts-on-functions → acts-on-functions .Positive.reflexive-∥≡∥ᴱ → SP.reflexive-∥≡∥ᴱ , TP.reflexive-∥≡∥ᴱ .Positive.transitive-;ᴱ⁻¹ {R = R₁} {S = R₂} R₁-prop R₂-prop x@(x₁ , x₂) z@(z₁ , z₂) → _≃_.is-equivalence $ Eq.with-other-function ((Productᴿ S T R₁ ;ᴱ Productᴿ S T R₂) x z ↝⟨ lemma ⟩ (S R₁ ;ᴱ S R₂) x₁ z₁ × (T R₁ ;ᴱ T R₂) x₂ z₂ ↝⟨ Eq.⟨ _ , SP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩ ×-cong Eq.⟨ _ , TP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩ ⟩ S (R₁ ;ᴱ R₂) x₁ z₁ × T (R₁ ;ᴱ R₂) x₂ z₂ ↔⟨⟩ Productᴿ S T (R₁ ;ᴱ R₂) x z □) _ (T.elim λ @0 where .T.truncation-is-propositionʳ _ → H-level.mono₁ 1 $ ×-closure 1 (SS.preserves-is-proposition (λ _ _ → T.truncation-is-proposition) _ _) (TS.preserves-is-proposition (λ _ _ → T.truncation-is-proposition) _ _) .T.∣∣ʳ _ → refl _) .Positive.commutes-with-/ᴱ {A = A} {R = R} prop equiv → _≃ᴱ_.is-equivalence $ EEq.with-other-function (Product F G A /ᴱ Productᴿ S T R ↔⟨⟩ (F A × G A) /ᴱ Productᴿ S T R ↔⟨ Q.×/ᴱ (SP.reflexive prop equiv _) (TP.reflexive prop equiv _) ⟩ F A /ᴱ S R × G A /ᴱ T R ↝⟨ EEq.⟨ _ , SP.commutes-with-/ᴱ prop equiv ⟩ ×-cong EEq.⟨ _ , TP.commutes-with-/ᴱ prop equiv ⟩ ⟩ F (A /ᴱ R) × G (A /ᴱ R) ↔⟨⟩ Product F G (A /ᴱ R) □) _ (Q.elim-prop λ @0 where .Q.is-propositionʳ _ → ×-closure 2 (SS.preserves-is-set Q./ᴱ-is-set) (TS.preserves-is-set Q./ᴱ-is-set) .Q.[]ʳ _ → refl _) where module SP = Positive p-S module SS = Suitable SP.suitable module TP = Positive p-T module TS = Suitable TP.suitable suitable = Productᴿ-suitable SP.suitable TP.suitable acts-on-functions = Productᴿ-acts-on-functions SP.acts-on-functions TP.acts-on-functions @0 lemma : (Productᴿ S T R₁ ;ᴱ Productᴿ S T R₂) (x₁ , x₂) (z₁ , z₂) ≃ ((S R₁ ;ᴱ S R₂) x₁ z₁ × (T R₁ ;ᴱ T R₂) x₂ z₂) lemma = Eq.⇔→≃ T.truncation-is-proposition (×-closure 1 T.truncation-is-proposition T.truncation-is-proposition) (T.rec λ @0 where .T.truncation-is-propositionʳ → ×-closure 1 T.truncation-is-proposition T.truncation-is-proposition .T.∣∣ʳ (_ , (SR₁x₁y₁ , TR₁x₂y₂) , (SR₂y₁z₁ , TR₂y₂z₂)) → ∣ _ , SR₁x₁y₁ , SR₂y₁z₁ ∣ , ∣ _ , TR₁x₂y₂ , TR₂y₂z₂ ∣) (uncurry $ T.rec λ @0 where .T.truncation-is-propositionʳ → Π-closure ext 1 λ _ → T.truncation-is-proposition .T.∣∣ʳ (_ , SR₁x₁y₁ , SR₂y₁z₁) → T.∥∥ᴱ-map λ (_ , TR₁x₂y₂ , TR₂y₂z₂) → _ , (SR₁x₁y₁ , TR₁x₂y₂) , (SR₂y₁z₁ , TR₂y₂z₂)) ------------------------------------------------------------------------ -- Combinators related to Maybe -- A combinator that, given a relation transformer for F, produces a -- relation transformer for Maybe ∘ F. Maybeᴿ : Relation-transformer-for F → Relation-transformer-for (Maybe ∘ F) Maybeᴿ = Maybeᴾ ∘_ -- When is an equivalence structure-preserving for Maybe ∘ F? Is-Maybe-equivalence : Structure-preserving-equivalence-predicate F a → Structure-preserving-equivalence-predicate (Maybe ∘ F) a Is-Maybe-equivalence Is-F-eq = λ where (A , nothing) (B , nothing) eq → ↑ _ ⊤ (A , just x) (B , just y) eq → Is-F-eq (A , x) (B , y) eq (A , _) (B , _) eq → ⊥ -- If F is univalent, then Maybe ∘ F is univalent. Maybe-univalent : {@0 F : Structure a b} {@0 Is-F-eq : Structure-preserving-equivalence-predicate F c} → @0 Univalent F Is-F-eq → Univalent (Maybe ∘ F) (Is-Maybe-equivalence Is-F-eq) Maybe-univalent {F = F} {Is-F-eq = Is-F-eq} u-F .Univalent.univalent {A = A , x} {B = B , y} = lemma x y where univ = U.abstract-univ lemma : (x : Maybe (F A)) (y : Maybe (F B)) → (eq : A ≃ᴱ B) → Is-Maybe-equivalence Is-F-eq (A , x) (B , y) eq ≃ (subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y) lemma nothing nothing eq = ↑ _ ⊤ ↔⟨ B.↑↔ ⟩ ⊤ ↔⟨ inverse tt≡tt↔⊤ ⟩ tt ≡ tt ↔⟨ B.≡↔inj₁≡inj₁ ⟩ nothing ≡ nothing ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₁ _ _ ⟩□ subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) nothing ≡ nothing □ lemma nothing (just y) eq = ⊥ ↔⟨ ⊥↔⊥ ⟩ ⊥ ↔⟨ inverse B.≡↔⊎ ⟩ nothing ≡ just y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₁ _ _ ⟩□ subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) nothing ≡ just y □ lemma (just x) nothing eq = ⊥ ↔⟨ ⊥↔⊥ ⟩ ⊥ ↔⟨ inverse B.≡↔⊎ ⟩ just _ ≡ nothing ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₂ _ _ ⟩□ subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (just x) ≡ nothing □ lemma (just x) (just y) eq = Is-F-eq (A , x) (B , y) eq ↝⟨ u-F .Univalent.univalent eq ⟩ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y ↔⟨ B.≡↔inj₂≡inj₂ ⟩ just (subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x) ≡ just y ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym $ push-subst-inj₂ _ _ ⟩□ subst (Maybe ∘ F) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (just x) ≡ just y □ -- If G is suitable, then Maybeᴿ G is suitable. Maybeᴿ-suitable : {@0 G : Relation-transformer-for F} → Suitable G → Suitable (Maybeᴿ G) Maybeᴿ-suitable {G = G} s-G = λ where .Suitable.preserves-is-set set → Maybe-closure 0 (S.preserves-is-set set) .Suitable.preserves-is-proposition prop → λ @0 where nothing nothing → H-level.mono₁ 0 $ ↑-closure 0 ⊤-contractible nothing (just _) → ⊥-propositional (just _) nothing → ⊥-propositional (just x) (just y) → S.preserves-is-proposition prop x y .Suitable.symmetric {x = nothing} {y = nothing} → _ .Suitable.symmetric {x = just x} {y = just y} → S.symmetric .Suitable.transitive {x = nothing} {y = nothing} {z = nothing} → _ .Suitable.transitive {x = just _} {y = just _} {z = just _} → S.transitive .Suitable.descent {x = nothing} {R = R} prop equiv _ → (nothing , [ _ ]) , [ (λ @0 where (nothing , _) → refl _) ] .Suitable.descent {x = just x} {R = R} prop equiv SRxx → $⟨ [ SRxx ] ⟩ Erased (G R x x) ↝⟨ (λ ([ SRxx ]) → S.descent prop equiv SRxx) ⟩ Contractibleᴱ (∃ λ y → Erased (G (Graph [_]) x y)) ↝⟨ ECP.Contractibleᴱ-cong _ (Eq.↔→≃ (Σ-map just id) (λ where (nothing , ()) (just y , s) → y , s) (λ where (nothing , ()) (just _ , _) → refl _) refl) ⦂ (_ → _) ⟩□ Contractibleᴱ (∃ λ y → Erased (Maybeᴿ G (Graph [_]) (just x) y)) □ where module S = Suitable s-G -- If G is univalent, then Maybeᴿ G is univalent. Maybeᴿ-univalent : {@0 G : Relation-transformer-for F} → Univalentᴿ G → Univalentᴿ (Maybeᴿ G) Maybeᴿ-univalent {F = F} {G = G} (s-G , u-G) = Maybeᴿ-suitable s-G , ( $⟨ Maybe-univalent u-G ⟩ Univalent (Maybe ∘ F) (Is-Maybe-equivalence λ (A , x) (B , y) eq → G (Graph (_≃ᴱ_.to eq)) x y) ↝⟨ substᴱ (Univalent _) (⟨ext⟩ λ p → ⟨ext⟩ λ q → lemma (p .proj₂) (q .proj₂)) ⟩□ Univalent (Maybe ∘ F) (λ (A , x) (B , y) eq → Maybeᴿ G (Graph (_≃ᴱ_.to eq)) x y) □) where @0 lemma : ∀ x y → Is-Maybe-equivalence (λ (A , x) (B , y) eq → G (Graph (_≃ᴱ_.to eq)) x y) (A , x) (B , y) ≡ (λ eq → Maybeᴿ G (Graph (_≃ᴱ_.to eq)) x y) lemma nothing nothing = refl _ lemma nothing (just _) = refl _ lemma (just _) nothing = refl _ lemma (just _) (just _) = refl _ -- If G acts on functions, then Maybeᴿ G acts on functions. Maybeᴿ-acts-on-functions : {@0 G : Relation-transformer-for F} → Acts-on-functions G → Acts-on-functions (Maybeᴿ G) Maybeᴿ-acts-on-functions {G = G} a-G = λ where .Acts-on-functions.map f → Monad.map (A.map f) .Acts-on-functions.map-id → Monad.map (A.map id) ≡⟨ cong Monad.map A.map-id ⟩ Monad.map id ≡⟨ ⟨ext⟩ Monad.map-id ⟩∎ id ∎ .Acts-on-functions.map-map {x = nothing} {y = nothing} → _ .Acts-on-functions.map-map {x = nothing} {y = just _} _ () .Acts-on-functions.map-map {x = just _} {y = nothing} _ () .Acts-on-functions.map-map {x = just _} {y = just _} → A.map-map where module A = Acts-on-functions a-G -- If G is positive, then Maybeᴿ G is positive. Maybeᴿ-positive : {@0 G : Relation-transformer-for F} → Positive G → Positive (Maybeᴿ G) Maybeᴿ-positive {F = F} {G = G} p-G = λ where .Positive.suitable → suitable .Positive.acts-on-functions → acts-on-functions .Positive.reflexive-∥≡∥ᴱ {x = nothing} → _ .Positive.reflexive-∥≡∥ᴱ {x = just _} → SP.reflexive-∥≡∥ᴱ .Positive.transitive-;ᴱ⁻¹ R₁-prop R₂-prop x z → _≃_.is-equivalence $ Eq.with-other-function (lemma R₁-prop R₂-prop x z .proj₁) _ (lemma R₁-prop R₂-prop x z .proj₂) .Positive.commutes-with-/ᴱ {A = A} {R = R} prop equiv → _≃ᴱ_.is-equivalence $ EEq.with-other-function (Maybe (F A) /ᴱ Maybeᴿ G R ↔⟨ Q.Maybe/ᴱ ⟩ Maybe (F A /ᴱ G R) ↝⟨ F.id ⊎-cong EEq.⟨ _ , SP.commutes-with-/ᴱ prop equiv ⟩ ⟩□ Maybe (F (A /ᴱ R)) □) (/ᴱ→/ᴱ (Maybeᴿ G) suitable acts-on-functions prop equiv) (Q.elim-prop λ @0 where .Q.is-propositionʳ _ → Maybe-closure 0 (SS.preserves-is-set Q./ᴱ-is-set) .Q.[]ʳ nothing → refl _ .Q.[]ʳ (just _) → refl _) where module SP = Positive p-G module SS = Suitable SP.suitable suitable = Maybeᴿ-suitable SP.suitable acts-on-functions = Maybeᴿ-acts-on-functions SP.acts-on-functions @0 lemma : (R₁-prop : ∀ x y → Is-proposition (R₁ x y)) → (R₂-prop : ∀ x y → Is-proposition (R₂ x y)) → ∀ x z → ∃ λ (eq : (Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) x z ≃ Maybeᴿ G (R₁ ;ᴱ R₂) x z) → ∀ p → _≃_.to eq p ≡ Suitable.transitive-;ᴱ suitable R₁-prop R₂-prop x z p lemma {R₁ = R₁} {R₂ = R₂} R₁-prop R₂-prop = λ @0 where nothing nothing → ((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) nothing nothing ↝⟨ Eq.⇔→≃ T.truncation-is-proposition (H-level.mono₁ 0 $ ↑-closure 0 ⊤-contractible) _ (λ _ → ∣ nothing , _ ∣) ⟩□ ↑ _ ⊤ □) , (λ _ → refl _) nothing (just z) → ((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) nothing (just z) ↝⟨ Eq.⇔→≃ T.truncation-is-proposition ⊥-propositional (T.rec λ @0 where .T.truncation-is-propositionʳ → ⊥-propositional .T.∣∣ʳ (nothing , _ , ()) .T.∣∣ʳ (just _ , () , _)) ⊥-elim ⟩□ ⊥ □) , (T.elim λ @0 where .T.truncation-is-propositionʳ _ → H-level.⇒≡ 1 $ ⊥-propositional .T.∣∣ʳ (nothing , _ , ()) .T.∣∣ʳ (just _ , () , _)) (just x) nothing → ((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) (just x) nothing ↝⟨ Eq.⇔→≃ T.truncation-is-proposition ⊥-propositional (T.rec λ @0 where .T.truncation-is-propositionʳ → ⊥-propositional .T.∣∣ʳ (nothing , () , _) .T.∣∣ʳ (just _ , _ , ())) ⊥-elim ⟩□ ⊥ □) , (T.elim λ @0 where .T.truncation-is-propositionʳ _ → H-level.⇒≡ 1 $ ⊥-propositional .T.∣∣ʳ (nothing , () , _) .T.∣∣ʳ (just _ , _ , ())) (just x) (just z) → ((Maybeᴿ G R₁ ;ᴱ Maybeᴿ G R₂) (just x) (just z) ↝⟨ Eq.⇔→≃ T.truncation-is-proposition T.truncation-is-proposition (T.∥∥ᴱ-map λ where (nothing , () , ()) (just _ , p) → _ , p) (T.∥∥ᴱ-map (Σ-map just id)) ⟩ (G R₁ ;ᴱ G R₂) x z ↝⟨ Eq.⟨ _ , SP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩ ⟩□ G (R₁ ;ᴱ R₂) x z □) , (T.elim λ @0 where .T.truncation-is-propositionʳ _ → H-level.⇒≡ 1 $ SS.preserves-is-proposition (λ _ _ → T.truncation-is-proposition) _ _ .T.∣∣ʳ (nothing , () , ()) .T.∣∣ʳ (just _ , _) → refl _) ------------------------------------------------------------------------ -- The Function and Functionᴿ combinators, along with some properties -- Function structures. Function : Structure a b → Structure a c → Structure a (b ⊔ c) Function F G A = F A → G A -- A combinator that, given relation transformers for F and G, -- produces a relation transformer for Function F G. Functionᴿ : {F : Structure a b} {G : Structure a c} → Relation-transformer-for F → Relation-transformer-for G → Relation-transformer-for (Function F G) Functionᴿ S T R f g = ∀ {x y} → S R x y → T R (f x) (g y) -- A variant of Functionᴿ ∘ Constᴿ. Function-Constᴿ : {F : Structure b c} (A : Type a) → Relation-transformer-for F → Relation-transformer-for (Function (Const A) F) Function-Constᴿ A G R f g = (x : A) → G R (f x) (g x) -- Function-Constᴿ is pointwise equivalent to Functionᴿ ∘ Constᴿ. Function-Constᴿ≃Functionᴿ∘Constᴿ : {f : A → F B} {g : A → F C} (G : Relation-transformer-for F) → Function-Constᴿ A G R f g ≃ (Functionᴿ ∘ Constᴿ) A G R f g Function-Constᴿ≃Functionᴿ∘Constᴿ {R = R} {f = f} {g = g} G = (∀ x → G R (f x) (g x)) ↝⟨ (∀-cong ext λ _ → ∀-intro _ ext) ⟩ (∀ x y → x ≡ y → G R (f x) (g y)) ↔⟨ inverse (∀-cong ext (λ _ → B.implicit-Π↔Π) F.∘ B.implicit-Π↔Π) ⟩□ (∀ {x y} → x ≡ y → G R (f x) (g y)) □ -- When is an equivalence structure-preserving for Function F G? Is-Function-equivalence : {F : Structure a b} → Structure-preserving-equivalence-predicate F c → Structure-preserving-equivalence-predicate G d → Structure-preserving-equivalence-predicate (Function F G) (b ⊔ c ⊔ d) Is-Function-equivalence Is-F-eq Is-G-eq (A , f) (B , g) eq = ∀ {x y} → Is-F-eq (A , x) (B , y) eq → Is-G-eq (A , f x) (B , g y) eq -- A variant of Is-Function-equivalence. Is-Function-equivalence′ : {F : Structure a b} → (∀ {A B} → A ≃ᴱ B → F A ≃ᴱ F B) → Structure-preserving-equivalence-predicate G c → Structure-preserving-equivalence-predicate (Function F G) (b ⊔ c) Is-Function-equivalence′ F-cong Is-G-eq (A , f) (B , g) eq = ∀ x → Is-G-eq (A , f x) (B , g (_≃ᴱ_.to (F-cong eq) x)) eq -- If F and G are univalent, then Function F G is univalent. Function-univalent : {@0 F : Structure a b} {@0 G : Structure a c} {@0 Is-F-eq : Structure-preserving-equivalence-predicate F d} {@0 Is-G-eq : Structure-preserving-equivalence-predicate G e} → @0 Univalent F Is-F-eq → @0 Univalent G Is-G-eq → Univalent (Function F G) (Is-Function-equivalence Is-F-eq Is-G-eq) Function-univalent {F = F} {G = G} {Is-F-eq = Is-F-eq} {Is-G-eq = Is-G-eq} u-F u-G .Univalent.univalent {A = A , f} {B = B , g} eq = (∀ {x y} → Is-F-eq (A , x) (B , y) eq → Is-G-eq (A , f x) (B , g y) eq) ↔⟨ B.implicit-Π↔Π F.∘ implicit-∀-cong ext B.implicit-Π↔Π ⟩ (∀ x y → Is-F-eq (A , x) (B , y) eq → Is-G-eq (A , f x) (B , g y) eq) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → →-cong ext (u-F .Univalent.univalent eq) (u-G .Univalent.univalent eq)) ⟩ (∀ x y → subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y → subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g y) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → →-cong₁ ext $ ≡⇒≃ (cong (_ ≡_) $ _≃_.left-inverse-of (Eq.subst-as-equivalence _ _) _) F.∘ inverse (Eq.≃-≡ $ inverse $ Eq.subst-as-equivalence _ _) F.∘ from-bijection ≡-comm) ⟩ (∀ x y → subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y ≡ x → subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g y) ↔⟨ Π-comm ⟩ (∀ y x → subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y ≡ x → subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g y) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ eq → ≡⇒≃ $ cong (_≡ _) $ cong (subst G _) $ cong f $ sym eq) ⟩ (∀ y x → subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y ≡ x → subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f (subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y)) ≡ g y) ↝⟨ (∀-cong ext λ _ → inverse $ ∀-intro _ ext) ⟩ (∀ y → subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f (subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) y)) ≡ g y) ↝⟨ (∀-cong ext λ _ → ≡⇒≃ $ cong (_≡ _) $ sym $ subst-→) ⟩ (∀ y → subst (Function F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) f y ≡ g y) ↝⟨ Eq.extensionality-isomorphism ext ⟩□ subst (Function F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) f ≡ g □ where univ = U.abstract-univ -- A variant of Function-univalent that is stated using -- Is-Function-equivalence′ instead of Is-Function-equivalence. Function-univalent′ : {@0 G : Structure a c} {@0 Is-G-eq : Structure-preserving-equivalence-predicate G e} (@0 F-cong : ∀ {A B} → A ≃ᴱ B → F A ≃ᴱ F B) → @0 (∀ {A} (x : F A) → _≃ᴱ_.to (F-cong F.id) x ≡ x) → @0 Univalent G Is-G-eq → Univalent (Function F G) (Is-Function-equivalence′ F-cong Is-G-eq) Function-univalent′ {F = F} {G = G} {Is-G-eq = Is-G-eq} F-cong F-cong-id u-G .Univalent.univalent {A = A , f} {B = B , g} eq = (∀ x → Is-G-eq (A , f x) (B , g (_≃ᴱ_.to (F-cong eq) x)) eq) ↝⟨ (∀-cong ext λ _ → u-G .Univalent.univalent eq) ⟩ (∀ x → subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) (f x) ≡ g (_≃ᴱ_.to (F-cong eq) x)) ↝⟨ Eq.extensionality-isomorphism ext ⟩ subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡ g ∘ _≃ᴱ_.to (F-cong eq) ↝⟨ ≡⇒≃ $ cong (subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡_) $ cong (g ∘_) $ cong _≃ᴱ_.to $ cong F-cong $ sym $ _≃_.right-inverse-of EEq.≃≃≃ᴱ _ ⟩ subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡ g ∘ _≃ᴱ_.to (F-cong $ EEq.≃→≃ᴱ $ EEq.≃ᴱ→≃ eq) ↝⟨ ≡⇒≃ $ cong (subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡_) $ cong (g ∘_) $ ⟨ext⟩ $ transport-theorem F (_≃ᴱ_.to ∘ F-cong ∘ EEq.≃→≃ᴱ) F-cong-id univ (EEq.≃ᴱ→≃ eq) ⟩ subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ≡ g ∘ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ↝⟨ inverse $ Eq.≃-≡ $ →-cong₁ ext $ Eq.subst-as-equivalence _ _ ⟩ subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ∘ subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ≡ g ∘ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ↝⟨ ≡⇒≃ $ cong (subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ∘ subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ≡_) $ cong (g ∘_) $ ⟨ext⟩ $ _≃_.right-inverse-of (Eq.subst-as-equivalence _ _) ⟩ subst G (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) ∘ f ∘ subst F (sym (≃⇒≡ univ (EEq.≃ᴱ→≃ eq))) ≡ g ↝⟨ (≡⇒≃ $ cong (_≡ _) $ sym $ ⟨ext⟩ λ _ → subst-→) ⟩□ subst (Function F G) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) f ≡ g □ where univ = U.abstract-univ -- If S is positive and T is suitable, then Functionᴿ S T is suitable. -- -- This is a variant of Theorem 5.12 from "Internalizing -- Representation Independence with Univalence". Functionᴿ-suitable : {@0 S : Relation-transformer-for F} → {@0 T : Relation-transformer-for G} → Positive S → Suitable T → Suitable (Functionᴿ S T) Functionᴿ-suitable {F = F} {G = G} {S = S} {T = T} p-S s-T = λ where .Suitable.preserves-is-set set → Π-closure ext 2 λ _ → TS.preserves-is-set set .Suitable.preserves-is-proposition prop _ _ → implicit-Π-closure ext 1 λ _ → implicit-Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → TS.preserves-is-proposition prop _ _ .Suitable.symmetric {R = R} {x = f} {y = g} prop S→T {x = x} {y = y} → S (R ⁻¹) x y ↝⟨ SS.symmetric (flip prop) ⟩ S R y x ↝⟨ S→T ⟩ T R (f y) (g x) ↝⟨ TS.symmetric prop ⟩□ T (R ⁻¹) (g x) (f y) □ .Suitable.transitive {R = R₁} {S = R₂} {x = f} {y = g} {z = h} R₁-prop R₂-prop S→T₁ S→T₂ {x = x} {y = y} → S (R₁ ;ᴱ R₂) x y ↔⟨ inverse Eq.⟨ _ , SP.transitive-;ᴱ⁻¹ R₁-prop R₂-prop _ _ ⟩ ⟩ (S R₁ ;ᴱ S R₂) x y ↝⟨ T.∥∥ᴱ-map (Σ-map _ (Σ-map S→T₁ S→T₂)) ⟩ (T R₁ ;ᴱ T R₂) (f x) (h y) ↝⟨ TS.transitive-;ᴱ R₁-prop R₂-prop _ _ ⟩□ T (R₁ ;ᴱ R₂) (f x) (h y) □ .Suitable.descent {A = A} {x = f} {R = R} prop equiv S→T → let d : (x : F A) → Contractibleᴱ (∃ λ y → Erased (T (Graph [_]) (f x) y)) d x = TS.descent prop equiv (S→T (SP.reflexive prop equiv x)) g-[] : F A → G (A /ᴱ R) g-[] x = d x .proj₁ .proj₁ S→T′ : Erased (S R x y → T (Graph [_]) (f x) (g-[] y)) S→T′ = λ {x = x} {y = y} → [ S R x y ↝⟨ S→T ⟩ T R (f x) (f y) ↝⟨ flip (TS.transitive prop (λ _ _ → Q./ᴱ-is-set)) (d y .proj₁ .proj₂ .erased) ⟩ T (R ;ᴱ Graph [_]) (f x) (g-[] y) ↝⟨ subst (λ R → T R (f x) (g-[] y)) (;ᴱ-Graph-[]≡Graph-[] prop equiv) ⟩□ T (Graph [_]) (f x) (g-[] y) □ ] S-[]-map-[] : ∀ {x} → Erased (S (Graph [_]) x (SA.map [_] x)) S-[]-map-[] = λ {x = x} → [ $⟨ SA.map-map Q.[]-respects-relation (SP.reflexive prop equiv x) ⟩ S (Graph [_]) (SA.map id x) (SA.map [_] x) ↝⟨ subst (λ f → S (Graph (Q.[_] {R = R})) (f x) (SA.map Q.[_] x)) SA.map-id ⟩□ S (Graph [_]) x (SA.map [_] x) □ ] g : F A /ᴱ S R → G (A /ᴱ R) g = Q.rec λ where .Q.is-setʳ → TS.preserves-is-set Q./ᴱ-is-set .Q.[]ʳ → g-[] .Q.[]-respects-relationʳ {x = x} {y = y} SRxy → g-[] x ≡⟨ cong proj₁ $ d x .proj₂ .erased (g-[] y , Er.map (_$ SRxy) S→T′) ⟩∎ g-[] y ∎ h : F A /ᴱ S R ≃ᴱ F (A /ᴱ R) h = EEq.⟨ _ , SP.commutes-with-/ᴱ prop equiv ⟩ in ( (F (A /ᴱ R) ↝⟨ _≃ᴱ_.from h ⟩ F A /ᴱ S R ↝⟨ g ⟩□ G (A /ᴱ R) □) , [ (λ {x = x} {y = y} → let lemma : ∀ y → S (Graph [_]) x (_≃ᴱ_.to h y) → T (Graph [_]) (f x) (g y) lemma = Q.elim-prop λ @0 where .Q.is-propositionʳ _ → Π-closure ext 1 λ _ → TS.preserves-is-proposition (λ _ _ → Q./ᴱ-is-set) _ _ .Q.[]ʳ y → let s = $⟨ S-[]-map-[] .erased ⟩ S (Graph [_]) y (SA.map [_] y) ↝⟨ SS.symmetric (λ _ _ → Q./ᴱ-is-set) ⟩□ S (Graph [_] ⁻¹) (SA.map [_] y) y □ in S (Graph [_]) x (SA.map [_] y) ↝⟨ flip (SS.transitive (λ _ _ → Q./ᴱ-is-set) λ _ _ → Q./ᴱ-is-set) s ⟩ S (Graph [_] ⟵) x y ↝⟨ subst (λ R → S R x y) (Graph-[]-⟵≡ prop equiv) ⟩ S R x y ↝⟨ S→T′ .erased ⟩□ T (Graph [_]) (f x) (g-[] y) □ in S (Graph [_]) x y ↝⟨ subst (S (Graph [_]) x) (sym $ _≃ᴱ_.right-inverse-of h _) ⟩ S (Graph [_]) x (_≃ᴱ_.to h (_≃ᴱ_.from h y)) ↝⟨ lemma (_≃ᴱ_.from h y) ⟩□ T (Graph [_]) (f x) (g (_≃ᴱ_.from h y)) □) ] ) , [ (λ (g′ , [ g′-hyp ]) → let lemma : ∀ y → g y ≡ g′ (_≃ᴱ_.to h y) lemma = Q.elim-prop λ @0 where .Q.is-propositionʳ _ → TS.preserves-is-set Q./ᴱ-is-set .Q.[]ʳ y → g-[] y ≡⟨ cong proj₁ $ d y .proj₂ .erased ( g′ (SA.map [_] y) , [ $⟨ S-[]-map-[] .erased ⟩ S (Graph [_]) y (SA.map [_] y) ↝⟨ g′-hyp ⟩□ T (Graph [_]) (f y) (g′ (SA.map [_] y)) □ ] ) ⟩∎ g′ (SA.map [_] y) ∎ in Σ-≡,≡→≡ (⟨ext⟩ λ x → g (_≃ᴱ_.from h x) ≡⟨ lemma (_≃ᴱ_.from h x) ⟩ g′ (_≃ᴱ_.to h (_≃ᴱ_.from h x)) ≡⟨ cong g′ $ _≃ᴱ_.right-inverse-of h _ ⟩∎ g′ x ∎) (H-level-Erased 1 (implicit-Π-closure ext 1 λ _ → implicit-Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → TS.preserves-is-proposition (λ _ _ → Q./ᴱ-is-set) _ _) _ _)) ] where module SP = Positive p-S module SA = Acts-on-functions SP.acts-on-functions module SS = Suitable SP.suitable module TS = Suitable s-T -- If A is a set and G is suitable, then Function-Constᴿ A G is -- suitable. Function-Constᴿ-suitable : {@0 G : Relation-transformer-for F} → @0 Is-set A → Suitable G → Suitable (Function-Constᴿ A G) Function-Constᴿ-suitable {F = F} {A = A} {G = G} set = Suitable G ↝⟨ Functionᴿ-suitable (Constᴿ-positive set) ⟩ Suitable (Functionᴿ (Constᴿ A) G) ↝⟨ Suitable-map (inverse $ Function-Constᴿ≃Functionᴿ∘Constᴿ G) ⟩□ Suitable (Function-Constᴿ A G) □ -- If S is positive and univalent, and T is univalent, then -- Functionᴿ S T is univalent. Functionᴿ-univalent : {@0 S : Relation-transformer-for F} {@0 T : Relation-transformer-for G} → Positive S → Univalentᴿ S → Univalentᴿ T → Univalentᴿ (Functionᴿ S T) Functionᴿ-univalent p-S (_ , u-S) (s-T , u-T) = Functionᴿ-suitable p-S s-T , Function-univalent u-S u-T -- If A is a set and G is univalent, then Function-Constᴿ A G is -- univalent. Function-Constᴿ-univalent : {@0 G : Relation-transformer-for F} → @0 Is-set A → Univalentᴿ G → Univalentᴿ (Function-Constᴿ A G) Function-Constᴿ-univalent set (s-G , u-G) = Function-Constᴿ-suitable set s-G , Function-univalent′ (λ _ → F.id) refl u-G ------------------------------------------------------------------------ -- Combinators related to Erased -- A combinator that, given a relation transformer for F, produces a -- relation transformer for λ A → Erased (F A). -- -- Note that I have not proved that Erasedᴿ G is positive if G is -- positive. Erasedᴿ : {@0 F : Structure a b} → @0 Relation-transformer-for F → Relation-transformer-for (λ A → Erased (F A)) Erasedᴿ G R = Erasedᴾ (G R) -- When is an equivalence structure-preserving for λ A → Erased (F A)? Is-Erased-equivalence : @0 Structure-preserving-equivalence-predicate F a → Structure-preserving-equivalence-predicate (λ A → Erased (F A)) a Is-Erased-equivalence Is-F-eq (_ , [ x ]) (_ , [ y ]) eq = Erased (Is-F-eq (_ , x) (_ , y) eq) -- If F is univalent, then λ A → Erased (F A) is univalent. Erased-univalent : {@0 F : Structure a b} {@0 Is-F-eq : Structure-preserving-equivalence-predicate F c} → @0 Univalent F Is-F-eq → Univalent (λ A → Erased (F A)) (Is-Erased-equivalence Is-F-eq) Erased-univalent {F = F} {Is-F-eq = Is-F-eq} u-F .Univalent.univalent {A = A , [ x ]} {B = B , [ y ]} eq = Erased (Is-F-eq (A , x) (B , y) eq) ↝⟨ Erased-cong (u-F .Univalent.univalent eq) ⟩ Erased (subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ≡ y) ↔⟨ Erased-≡↔[]≡[] ⟩ [ subst F (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) x ] ≡ [ y ] ↝⟨ ≡⇒≃ $ cong (_≡ _) $ sym push-subst-[] ⟩□ subst (λ A → Erased (F A)) (≃⇒≡ univ (EEq.≃ᴱ→≃ eq)) [ x ] ≡ [ y ] □ where univ = U.abstract-univ -- If G is suitable, then Erasedᴿ G is suitable. Erasedᴿ-suitable : {@0 G : Relation-transformer-for F} → @0 Suitable G → Suitable (Erasedᴿ G) Erasedᴿ-suitable {G = G} s-G = λ where .Suitable.preserves-is-set set → H-level-Erased 2 (s-G .Suitable.preserves-is-set set) .Suitable.preserves-is-proposition prop _ _ → H-level-Erased 1 (s-G .Suitable.preserves-is-proposition prop _ _) .Suitable.symmetric prop → Er.map (s-G .Suitable.symmetric prop) .Suitable.transitive R-prop S-prop [ GRxy ] [ GSyz ] → [ s-G .Suitable.transitive R-prop S-prop GRxy GSyz ] .Suitable.descent {x = [ x ]} {R = R} prop equiv [GRxx] → $⟨ [ [GRxx] .erased ] ⟩ Erased (G R x x) ↝⟨ Er.map (λ GRxx → s-G .Suitable.descent prop equiv GRxx) ⟩ Erased (Contractibleᴱ (∃ λ y → Erased (G (Graph [_]) x y))) ↝⟨ ECP.Erased-Contractibleᴱ↔Contractibleᴱ-Erased _ ⟩ Contractibleᴱ (Erased (∃ λ y → Erased (G (Graph [_]) x y))) ↝⟨ ECP.Contractibleᴱ-cong _ Erased-Σ↔Σ ⟩ Contractibleᴱ (∃ λ ([ y ]) → Erased (Erased (G (Graph [_]) x y))) ↔⟨⟩ Contractibleᴱ (∃ λ y → Erased (Erasedᴿ G (Graph [_]) [ x ] y)) □ -- If G is univalent, then Erasedᴿ G is univalent. Erasedᴿ-univalent : {@0 G : Relation-transformer-for F} → @0 Univalentᴿ G → Univalentᴿ (Erasedᴿ G) Erasedᴿ-univalent (s-G , u-G) = Erasedᴿ-suitable s-G , Erased-univalent u-G -- If G acts on functions, then Erasedᴿ G acts on functions. Erasedᴿ-acts-on-functions : {@0 G : Relation-transformer-for F} → @0 Acts-on-functions G → Acts-on-functions (Erasedᴿ G) Erasedᴿ-acts-on-functions {G = G} a-G = λ where .Acts-on-functions.map f → Er.map (a-G .Acts-on-functions.map f) .Acts-on-functions.map-id → Er.map (a-G .Acts-on-functions.map id) ≡⟨ cong (λ f → Er.map f) (a-G .Acts-on-functions.map-id) ⟩ Er.map id ≡⟨⟩ id ∎ .Acts-on-functions.map-map {f = f} {g = g} {x = [ x ]} {y = [ y ]} {R₁ = R₁} {R₂ = R₂} R₁→R₂ → Erased (G R₁ x y) ↝⟨ Er.map (a-G .Acts-on-functions.map-map R₁→R₂) ⟩□ Erased (G R₂ (a-G .Acts-on-functions.map f x) (a-G .Acts-on-functions.map g y)) □ ------------------------------------------------------------------------ -- An example: monoids -- This is a variant of Examples 3.5 and 3.6 from "Internalizing -- Representation Independence with Univalence". module Example₁ where -- Raw monoid structures. Raw-monoid-structure : Structure a a Raw-monoid-structure A = A × (A → A → A) -- Raw-monoid-structure can be expressed using some combinators. _ : Raw-monoid-structure {a = a} ≡ Product Id (Function Id (Function Id Id)) _ = refl _ -- Raw monoids, i.e., monoids without the monoid laws. Raw-monoid : (a : Level) → Type (lsuc a) Raw-monoid _ = Type-with Raw-monoid-structure -- Raw monoid equivalence predicates. Is-raw-monoid-equivalence : Structure-preserving-equivalence-predicate Raw-monoid-structure a Is-raw-monoid-equivalence (_ , id₁ , _∘₁_) (_ , id₂ , _∘₂_) eq = _≃ᴱ_.to eq id₁ ≡ id₂ × (∀ x y → _≃ᴱ_.to eq (x ∘₁ y) ≡ _≃ᴱ_.to eq x ∘₂ _≃ᴱ_.to eq y) -- Is-raw-monoid-equivalence can be expressed using some -- combinators. _ : Is-raw-monoid-equivalence {a = a} ≡ Is-Product-equivalence Is-Id-equivalence (Is-Function-equivalence′ id (Is-Function-equivalence′ id Is-Id-equivalence)) _ = refl _ -- Raw monoid equivalences (with erased proofs). infix 4 _≃ᴿᴹᴱ_ _≃ᴿᴹᴱ_ : Raw-monoid a → Raw-monoid a → Type a _≃ᴿᴹᴱ_ = _≃[ Is-raw-monoid-equivalence ]ᴱ_ -- The combination of Raw-monoid-structure and -- Is-raw-monoid-equivalence is univalent (in erased settings). Is-raw-monoid-equivalence-univalent : Univalent (Raw-monoid-structure {a = a}) Is-raw-monoid-equivalence Is-raw-monoid-equivalence-univalent = Product-univalent Id-univalent (Function-univalent′ id refl (Function-univalent′ id refl Id-univalent)) -- The monoid laws. Monoid-laws : Axioms Raw-monoid-structure a Monoid-laws (A , id , _∘_) = Is-set A × (∀ x → id ∘ x ≡ x) × (∀ x → x ∘ id ≡ x) × (∀ x y z → x ∘ (y ∘ z) ≡ (x ∘ y) ∘ z) -- The monoid laws are propositional. Monoid-laws-propositional : (M : Raw-monoid a) → Is-proposition (Monoid-laws M) Monoid-laws-propositional (A , id , _∘_) = Σ-closure 1 (H-level-propositional ext 2) λ A-set → ×-closure 1 (Π-closure ext 1 λ _ → A-set) $ ×-closure 1 (Π-closure ext 1 λ _ → A-set) $ Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → A-set -- Monoid structures. Monoid-structure : Structure a a Monoid-structure = Raw-monoid-structure With-the-axioms Monoid-laws -- Monoids. Monoid : (a : Level) → Type (lsuc a) Monoid _ = Type-with Monoid-structure -- Monoid equivalence predicates. Is-monoid-equivalence : Structure-preserving-equivalence-predicate Monoid-structure a Is-monoid-equivalence = Lift-With-the-axioms Is-raw-monoid-equivalence -- Monoid equivalences (with erased proofs). infix 4 _≃ᴹᴱ_ _≃ᴹᴱ_ : Monoid a → Monoid a → Type a _≃ᴹᴱ_ = _≃[ Is-monoid-equivalence ]ᴱ_ -- The combination of Monoid-structure and Is-monoid-equivalence is -- univalent (in erased settings). Is-monoid-equivalence-univalent : Univalent (Monoid-structure {a = a}) Is-monoid-equivalence Is-monoid-equivalence-univalent = Univalent-With-the-axioms Monoid-laws-propositional Is-raw-monoid-equivalence-univalent -- The structure identity principle for monoids. @0 sip-for-monoids : (M ≃ᴹᴱ N) ≃ (M ≡ N) sip-for-monoids = sip Is-monoid-equivalence-univalent -- If a raw monoid M₂ is equivalent (with erased proofs) to the -- underlying raw monoid of a monoid M₁, then the monoid laws hold -- for M₂ (in erased contexts), and M₁ is equivalent (with erased -- proofs) to the monoid constructed from M₂ and the laws. induced-monoid : (M₁@(A₁ , ops₁ , _) : Monoid a) (M₂@(A₂ , ops₂) : Raw-monoid a) → (A₁ , ops₁) ≃ᴿᴹᴱ M₂ → ∃ λ (l₂ : Erased (Monoid-laws M₂)) → M₁ ≃ᴹᴱ (A₂ , ops₂ , l₂) induced-monoid = induced-structures Is-raw-monoid-equivalence-univalent -- The unary natural numbers form a monoid. ℕ-monoid : Monoid lzero ℕ-monoid = ℕ , (0 , _+_) , [ ( ℕ-set , refl , (λ _ → Nat.+-right-identity) , (λ m _ _ → Nat.+-assoc m) ) ] -- One variant of binary natural numbers forms a raw monoid. Bin-raw-monoid : Raw-monoid lzero Bin-raw-monoid = Bin , Bin.Operations-for-Bin.zero , Bin.Operations-for-Bin._+_ -- The raw monoid underlying ℕ-monoid is equivalent (with erased -- proofs) to Bin-raw-monoid. ℕ≃ᴿᴹᴱBin : (ℕ , (0 , _+_)) ≃ᴿᴹᴱ Bin-raw-monoid ℕ≃ᴿᴹᴱBin = (ℕ ↔⟨ inverse Bin.Bin↔ℕ ⟩□ Bin □) , [ ( (_↔_.from Bin.Bin↔ℕ 0 ≡⟨ _↔_.to Bin.≡-for-indices↔≡ [ refl _ ] ⟩∎ Bin.Operations-for-Bin.zero ∎) , (λ m n → _↔_.from Bin.Bin↔ℕ (m + n) ≡⟨ _↔_.to Bin.≡-for-indices↔≡ [ refl _ ] ⟩∎ _↔_.from Bin.Bin↔ℕ m Bin.Operations-for-Bin.+ _↔_.from Bin.Bin↔ℕ n ∎) ) ] -- The monoid laws hold for Bin-raw-monoid (in erased contexts). @0 Bin-monoid-laws : Monoid-laws Bin-raw-monoid Bin-monoid-laws = induced-monoid ℕ-monoid Bin-raw-monoid ℕ≃ᴿᴹᴱBin .proj₁ .erased -- One variant of binary natural numbers forms a monoid. Bin-monoid : Monoid lzero Bin-monoid = Bin-raw-monoid .proj₁ , Bin-raw-monoid .proj₂ , [ Bin-monoid-laws ] -- This monoid is equivalent, with erased proofs, to ℕ-monoid. ℕ≃ᴹᴱBin : ℕ-monoid ≃ᴹᴱ Bin-monoid ℕ≃ᴹᴱBin = induced-monoid ℕ-monoid Bin-raw-monoid ℕ≃ᴿᴹᴱBin .proj₂ -- In erased contexts the monoid is equal to ℕ-monoid. @0 ℕ≡Bin : ℕ-monoid ≡ Bin-monoid ℕ≡Bin = _≃_.to sip-for-monoids ℕ≃ᴹᴱBin ------------------------------------------------------------------------ -- Another example: bags -- This is a variant of Examples 5.5 and 5.13 from "Internalizing -- Representation Independence with Univalence". -- The type A is assumed to come with decidable equality. module Example₂ {A : Type a} (_≟_ : Decidable-equality A) where private -- The type A is a set. set : Is-set A set = decidable⇒set _≟_ -- Raw bag structures. Raw-bag-structure : Structure a a Raw-bag-structure Bag = -- An empty bag. Bag × -- Insertion. (A → Bag → Bag) × -- Union. (Bag → Bag → Bag) × -- The number of occurrences of the given element in the given -- bag. (A → Bag → ℕ) -- Raw-bag-structure can be expressed using some combinators. _ : Raw-bag-structure ≡ Product Id (Product (Function (Const A) (Function Id Id)) (Product (Function Id (Function Id Id)) (Function (Const A) (Function Id (Const ℕ))))) _ = refl _ -- Raw bag types. Raw-bag-type : Type (lsuc a) Raw-bag-type = Type-with Raw-bag-structure -- Raw bag equivalence predicates. Is-raw-bag-equivalence : Structure-preserving-equivalence-predicate Raw-bag-structure a Is-raw-bag-equivalence (_ , empty₁ , insert₁ , union₁ , count₁) (_ , empty₂ , insert₂ , union₂ , count₂) eq = _≃ᴱ_.to eq empty₁ ≡ empty₂ × (∀ x xs → _≃ᴱ_.to eq (insert₁ x xs) ≡ insert₂ x (_≃ᴱ_.to eq xs)) × (∀ xs ys → _≃ᴱ_.to eq (union₁ xs ys) ≡ union₂ (_≃ᴱ_.to eq xs) (_≃ᴱ_.to eq ys)) × (∀ x xs → count₁ x xs ≡ count₂ x (_≃ᴱ_.to eq xs)) -- Is-raw-bag-equivalence can be expressed using some combinators. _ : Is-raw-bag-equivalence ≡ Is-Product-equivalence Is-Id-equivalence (Is-Product-equivalence (Is-Function-equivalence′ (λ _ → EEq.id) (Is-Function-equivalence′ id Is-Id-equivalence)) (Is-Product-equivalence (Is-Function-equivalence′ id (Is-Function-equivalence′ id Is-Id-equivalence)) (Is-Function-equivalence′ (λ _ → EEq.id) (Is-Function-equivalence′ id Is-Const-equivalence)))) _ = refl _ -- Raw bag equivalences (with erased proofs). infix 4 _≃ᴮᴱ_ _≃ᴮᴱ_ : Raw-bag-type → Raw-bag-type → Type a _≃ᴮᴱ_ = _≃[ Is-raw-bag-equivalence ]ᴱ_ -- Relation transformers for raw bag types. Raw-bag-typeᴿ : Relation-transformer-for Raw-bag-structure Raw-bag-typeᴿ = Productᴿ Idᴿ (Productᴿ (Function-Constᴿ A (Functionᴿ Idᴿ Idᴿ)) (Productᴿ (Functionᴿ Idᴿ (Functionᴿ Idᴿ Idᴿ)) (Function-Constᴿ A (Functionᴿ Idᴿ (Constᴿ ℕ))))) -- Raw-bag-typeᴿ is univalent. Raw-bag-typeᴿ-univalent : Univalentᴿ Raw-bag-typeᴿ Raw-bag-typeᴿ-univalent = Productᴿ-univalent Idᴿ-univalent (Productᴿ-univalent (Function-Constᴿ-univalent set (Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent Idᴿ-univalent)) (Productᴿ-univalent (Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent (Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent Idᴿ-univalent)) (Function-Constᴿ-univalent set (Functionᴿ-univalent Idᴿ-positive Idᴿ-univalent (Constᴿ-univalent ℕ-set))))) -- One implementation of bags. List-bag : Type a List-bag = List A count₁′ : A → A → ℕ count₁′ x y = if x ≟ y then 1 else 0 count₁ : A → List-bag → ℕ count₁ x = L.foldr (λ y → count₁′ x y +_) 0 Raw-bag-structure-List-bag : Raw-bag-structure List-bag Raw-bag-structure-List-bag = [] , _∷_ , L._++_ , count₁ Raw-bag-type-List-bag : Raw-bag-type Raw-bag-type-List-bag = List-bag , Raw-bag-structure-List-bag -- Another implementation of bags. Assoc-list-bag : Type a Assoc-list-bag = List (ℕ × A) insert : ℕ → A → Assoc-list-bag → Assoc-list-bag insert m x [] = (m , x) ∷ [] insert m x ((n , y) ∷ ys) = if x ≟ y then (m + n , y) ∷ ys else (n , y) ∷ insert m x ys union : Assoc-list-bag → Assoc-list-bag → Assoc-list-bag union = flip (L.foldr (uncurry insert)) count₂′ : A → ℕ × A → ℕ count₂′ x (n , y) = if x ≟ y then n else 0 count₂ : A → Assoc-list-bag → ℕ count₂ x = L.foldr (λ y → count₂′ x y +_) 0 Raw-bag-structure-Assoc-list-bag : Raw-bag-structure Assoc-list-bag Raw-bag-structure-Assoc-list-bag = [] , insert 1 , union , count₂ Raw-bag-type-Assoc-list-bag : Raw-bag-type Raw-bag-type-Assoc-list-bag = Assoc-list-bag , Raw-bag-structure-Assoc-list-bag -- Some properties of count₁. count₁-++ : ∀ xs → count₁ z (xs L.++ ys) ≡ count₁ z xs + count₁ z ys count₁-++ [] = refl _ count₁-++ {z = z} {ys = ys} (x ∷ xs) = count₁′ z x + (count₁ z (xs L.++ ys)) ≡⟨ cong (count₁′ z x +_) $ count₁-++ xs ⟩ count₁′ z x + (count₁ z xs + count₁ z ys) ≡⟨ Nat.+-assoc (count₁′ z x) ⟩∎ (count₁′ z x + count₁ z xs) + count₁ z ys ∎ count₁-replicate : ∀ n → count₁ z (L.replicate n y) ≡ count₂′ z (n , y) count₁-replicate {z = z} {y = y} zero with z ≟ y … | yes _ = refl _ … | no _ = refl _ count₁-replicate {z = z} {y = y} (suc n) = count₁′ z y + count₁ z (L.replicate n y) ≡⟨ cong (count₁′ z y +_) $ count₁-replicate n ⟩ count₁′ z y + count₂′ z (n , y) ≡⟨ lemma ⟩∎ count₂′ z (suc n , y) ∎ where lemma : count₁′ z y + count₂′ z (n , y) ≡ count₂′ z (suc n , y) lemma with z ≟ y … | yes _ = refl _ … | no _ = refl _ -- Some properties of count₂. count₂-insert-≡ : z ≡ x → ∀ ys → count₂ z (insert m x ys) ≡ m + count₂ z ys count₂-insert-≡ {z = z} {x = x} {m = m} z≡x = helper where helper : ∀ ys → count₂ z (insert m x ys) ≡ m + count₂ z ys helper [] with z ≟ x … | yes _ = m + 0 ∎ … | no z≢x = ⊥-elim $ z≢x z≡x helper ((n , y) ∷ ys) with x ≟ y helper ((n , y) ∷ ys) | no x≢y = count₂′ z (n , y) + count₂ z (insert m x ys) ≡⟨ cong (count₂′ z (n , y) +_) $ helper ys ⟩ count₂′ z (n , y) + (m + count₂ z ys) ≡⟨ Nat.+-assoc (count₂′ z (n , y)) ⟩ (count₂′ z (n , y) + m) + count₂ z ys ≡⟨ cong (_+ count₂ z ys) $ sym $ Nat.+-comm m ⟩ (m + count₂′ z (n , y)) + count₂ z ys ≡⟨ sym $ Nat.+-assoc m ⟩∎ m + (count₂′ z (n , y) + count₂ z ys) ∎ helper ((n , y) ∷ ys) | yes x≡y = count₂′ z (m + n , y) + count₂ z ys ≡⟨ cong (_+ _) lemma ⟩ (m + count₂′ z (n , y)) + count₂ z ys ≡⟨ sym $ Nat.+-assoc m ⟩∎ m + (count₂′ z (n , y) + count₂ z ys) ∎ where lemma : count₂′ z (m + n , y) ≡ m + count₂′ z (n , y) lemma with z ≟ y … | yes _ = m + n ∎ … | no z≢y = ⊥-elim $ z≢y (trans z≡x x≡y) count₂-insert-≢ : z ≢ x → ∀ ys → count₂ z (insert m x ys) ≡ count₂ z ys count₂-insert-≢ {z = z} {x = x} {m = m} z≢x = helper where helper : ∀ ys → count₂ z (insert m x ys) ≡ count₂ z ys helper [] with z ≟ x … | no _ = 0 ∎ … | yes z≡x = ⊥-elim $ z≢x z≡x helper ((n , y) ∷ ys) with x ≟ y … | no _ = count₂′ z (n , y) + count₂ z (insert m x ys) ≡⟨ cong (count₂′ z (n , y) +_) $ helper ys ⟩∎ count₂′ z (n , y) + count₂ z ys ∎ … | yes x≡y = count₂′ z (m + n , y) + count₂ z ys ≡⟨ cong (_+ _) lemma ⟩∎ count₂′ z ( n , y) + count₂ z ys ∎ where lemma : count₂′ z (m + n , y) ≡ count₂′ z (n , y) lemma with z ≟ y … | no _ = 0 ∎ … | yes z≡y = ⊥-elim $ z≢x (trans z≡y (sym x≡y)) count₂-insert : ∀ ys → count₂ z (insert m x ys) ≡ count₂′ z (m , x) + count₂ z ys count₂-insert {z = z} {m = m} {x = x} ys with z ≟ x … | yes z≡x = count₂ z (insert m x ys) ≡⟨ count₂-insert-≡ z≡x ys ⟩∎ m + count₂ z ys ∎ … | no z≢x = count₂ z (insert m x ys) ≡⟨ count₂-insert-≢ z≢x ys ⟩∎ count₂ z ys ∎ count₂-union : ∀ xs → count₂ z (union xs ys) ≡ count₂ z xs + count₂ z ys count₂-union {z = z} {ys = ys} [] = count₂ z ys ∎ count₂-union {z = z} {ys = ys} ((m , x) ∷ xs) = count₂ z (insert m x (union xs ys)) ≡⟨ count₂-insert (union xs ys) ⟩ count₂′ z (m , x) + count₂ z (union xs ys) ≡⟨ cong (count₂′ z (m , x) +_) $ count₂-union xs ⟩ count₂′ z (m , x) + (count₂ z xs + count₂ z ys) ≡⟨ Nat.+-assoc (count₂′ z (m , x)) ⟩∎ (count₂′ z (m , x) + count₂ z xs) + count₂ z ys ∎ -- A relation relating values of the two bag types. infix 4 _∼_ _∼_ : List-bag → Assoc-list-bag → Type a xs ∼ ys = ∀ z → count₁ z xs ≡ count₂ z ys -- The relation _∼_ is propositional. ∼-propositional : ∀ xs ys → Is-proposition (xs ∼ ys) ∼-propositional _ _ = Π-closure ext 1 λ _ → ℕ-set -- The relation _∼_ is a QER. ∼-QER : Is-QER _∼_ ∼-QER = (λ {xs₁ xs₂ ys₁ ys₂} xs₁∼ys₁ xs₂∼ys₁ xs₂∼ys₂ z → count₁ z xs₁ ≡⟨ xs₁∼ys₁ z ⟩ count₂ z ys₁ ≡⟨ sym $ xs₂∼ys₁ z ⟩ count₁ z xs₂ ≡⟨ xs₂∼ys₂ z ⟩∎ count₂ z ys₂ ∎) , (λ xs → ∣ to xs , ∼to xs ∣) , (λ ys → ∣ from ys , from∼ ys ∣) where to : List-bag → Assoc-list-bag to = L.foldr (insert 1) [] from : Assoc-list-bag → List-bag from = L.foldr (λ (n , x) → L.replicate n x L.++_) [] ∼to : ∀ xs → xs ∼ to xs ∼to [] _ = refl _ ∼to (x ∷ xs) z = count₁′ z x + count₁ z xs ≡⟨ cong (count₁′ z x +_) $ ∼to xs z ⟩ count₁′ z x + count₂ z (to xs) ≡⟨⟩ count₂′ z (1 , x) + count₂ z (to xs) ≡⟨ sym $ count₂-insert (to xs) ⟩∎ count₂ z (insert 1 x (to xs)) ∎ from∼ : ∀ ys → from ys ∼ ys from∼ [] _ = refl _ from∼ ((n , y) ∷ ys) z = count₁ z (L.replicate n y L.++ from ys) ≡⟨ count₁-++ (L.replicate n y) ⟩ count₁ z (L.replicate n y) + count₁ z (from ys) ≡⟨ cong (count₁ z (L.replicate n y) +_) $ from∼ ys z ⟩ count₁ z (L.replicate n y) + count₂ z ys ≡⟨ cong (_+ count₂ z ys) $ count₁-replicate n ⟩ count₂′ z (n , y) + count₂ z ys ≡⟨⟩ count₂ z ((n , y) ∷ ys) ∎ -- Raw-bag-structure-List-bag and Raw-bag-structure-Assoc-list-bag -- are related by Raw-bag-typeᴿ _∼_. List-bag∼Assoc-list-bag : Raw-bag-typeᴿ _∼_ Raw-bag-structure-List-bag Raw-bag-structure-Assoc-list-bag List-bag∼Assoc-list-bag = (λ z → count₁ z [] ≡⟨⟩ count₂ z [] ∎) , (λ x {x = xs} {y = ys} xs∼ys z → count₁ z (x ∷ xs) ≡⟨⟩ count₁′ z x + count₁ z xs ≡⟨ cong (count₁′ z x +_) (xs∼ys z) ⟩ count₁′ z x + count₂ z ys ≡⟨⟩ count₂′ z (1 , x) + count₂ z ys ≡⟨ sym $ count₂-insert ys ⟩∎ count₂ z (insert 1 x ys) ∎) , (λ {x = xs₁} {y = ys₁} xs₁∼ys₁ {x = xs₂} {y = ys₂} xs₂∼ys₂ z → count₁ z (xs₁ L.++ xs₂) ≡⟨ count₁-++ xs₁ ⟩ count₁ z xs₁ + count₁ z xs₂ ≡⟨ cong₂ _+_ (xs₁∼ys₁ z) (xs₂∼ys₂ z) ⟩ count₂ z ys₁ + count₂ z ys₂ ≡⟨ sym $ count₂-union ys₁ ⟩∎ count₂ z (union ys₁ ys₂) ∎) , (λ x {x = xs} {y = ys} xs∼ys → count₁ x xs ≡⟨ xs∼ys x ⟩∎ count₂ x ys ∎) -- There is an equivalence (with erased proofs) between List-bag -- quotiented by _∼_ ⟵ and Assoc-list-bag quotiented by _∼_ ⟶ -- (where _/ᴱ_ is used for the quotients). List-bag≃ᴱAssoc-list-bag : List-bag /ᴱ _∼_ ⟵ ≃ᴱ Assoc-list-bag /ᴱ _∼_ ⟶ List-bag≃ᴱAssoc-list-bag = /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ (Is-QER→Is-QERᴱ ∼-QER) ∼-propositional .proj₁ -- Lists that are related by List-bag≃ᴱAssoc-list-bag (in a -- certain way) are also related by _∼_. -- -- Note that this definition is not erased: it uses /ᴱ⟵≃ᴱ/ᴱ⟶ -- instead of /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ, and ∼-QER instead of -- Is-QER→Is-QERᴱ ∼-QER. →∼ : ∀ xs ys → _≃ᴱ_.to List-bag≃ᴱAssoc-list-bag [ xs ] ≡ [ ys ] → xs ∼ ys →∼ xs ys = /ᴱ⟵≃ᴱ/ᴱ⟶ ∼-QER ∼-propositional .proj₂ xs ys .proj₁ -- The function →∼ is an equivalence (in erased contexts). @0 →∼-equivalence : ∀ xs ys → Is-equivalence (→∼ xs ys) →∼-equivalence xs ys = /ᴱ⟵≃ᴱ/ᴱ⟶ ∼-QER ∼-propositional .proj₂ xs ys .proj₂ .erased -- The relation _∼_ can be expressed using -- List-bag≃ᴱAssoc-list-bag (in erased contexts). @0 ≃∼ : ∀ xs ys → (_≃ᴱ_.to List-bag≃ᴱAssoc-list-bag [ xs ] ≡ [ ys ]) ≃ (xs ∼ ys) ≃∼ = /ᴱ⟵≃ᴱ/ᴱ⟶ᴱ (Is-QER→Is-QERᴱ ∼-QER) ∼-propositional .proj₂ .erased private instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ = Suitable→/ᴱ⟵×/ᴱ⟶ Raw-bag-type-List-bag Raw-bag-type-Assoc-list-bag (Raw-bag-typeᴿ-univalent .proj₁) (Is-QER→Is-QERᴱ ∼-QER) ∼-propositional List-bag∼Assoc-list-bag -- There is a raw bag structure on List-bag /ᴱ _∼_ ⟵. Raw-bag-structure-List-bag-/ᴱ : Raw-bag-structure (List-bag /ᴱ _∼_ ⟵) Raw-bag-structure-List-bag-/ᴱ = instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₁ Raw-bag-type-List-bag-/ᴱ : Raw-bag-type Raw-bag-type-List-bag-/ᴱ = List-bag /ᴱ _∼_ ⟵ , Raw-bag-structure-List-bag-/ᴱ -- There is a raw bag structure on Assoc-list-bag /ᴱ _∼_ ⟶. Raw-bag-structure-Assoc-list-bag-/ᴱ : Raw-bag-structure (Assoc-list-bag /ᴱ _∼_ ⟶) Raw-bag-structure-Assoc-list-bag-/ᴱ = instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₁ Raw-bag-type-Assoc-list-bag-/ᴱ : Raw-bag-type Raw-bag-type-Assoc-list-bag-/ᴱ = Assoc-list-bag /ᴱ _∼_ ⟶ , Raw-bag-structure-Assoc-list-bag-/ᴱ -- The two raw bag structures are related to the underlying raw -- bag structures (in erased contexts). @0 List∼List-/ᴱ : Raw-bag-typeᴿ (Graph [_]) Raw-bag-structure-List-bag Raw-bag-structure-List-bag-/ᴱ List∼List-/ᴱ = instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₂ .erased .proj₁ @0 Assoc-list∼Assoc-list-/ᴱ : Raw-bag-typeᴿ (Graph [_]) Raw-bag-structure-Assoc-list-bag Raw-bag-structure-Assoc-list-bag-/ᴱ Assoc-list∼Assoc-list-/ᴱ = instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₂ .erased .proj₂ .proj₁ -- They are also related to each other (in erased contexts). @0 List-/ᴱ∼Assoc-list-/ᴱ : Raw-bag-typeᴿ (Graph (_≃ᴱ_.to List-bag≃ᴱAssoc-list-bag)) Raw-bag-structure-List-bag-/ᴱ Raw-bag-structure-Assoc-list-bag-/ᴱ List-/ᴱ∼Assoc-list-/ᴱ = instance-of-Suitable→/ᴱ⟵×/ᴱ⟶ .proj₂ .proj₂ .erased .proj₂ .proj₂ -- Raw-bag-type-List-bag-/ᴱ is equal to -- Raw-bag-type-Assoc-list-bag-/ᴱ (in erased contexts). @0 List-/ᴱ≡Assoc-list-/ᴱ : Raw-bag-type-List-bag-/ᴱ ≡ Raw-bag-type-Assoc-list-bag-/ᴱ List-/ᴱ≡Assoc-list-/ᴱ = Univalentᴿ→/ᴱ⟵×/ᴱ⟶ Raw-bag-type-List-bag Raw-bag-type-Assoc-list-bag Raw-bag-typeᴿ-univalent (Is-QER→Is-QERᴱ ∼-QER) ∼-propositional List-bag∼Assoc-list-bag .proj₂ .proj₂ .erased .proj₂ .proj₂ -- For List-bag /ᴱ _∼_ ⟵ equality of two lists can be expressed in -- terms of the induced count function (in erased contexts). @0 List-≡≃ : let count = Raw-bag-structure-List-bag-/ᴱ .proj₂ .proj₂ .proj₂ in (xs ys : List-bag /ᴱ _∼_ ⟵) → (xs ≡ ys) ≃ (∀ z → count z xs ≡ count z ys) List-≡≃ = Q.elim-prop λ @0 where .Q.is-propositionʳ _ → Π-closure ext 1 λ _ → Eq.left-closure ext 0 $ Q./ᴱ-is-set .Q.[]ʳ xs → Q.elim-prop λ @0 where .Q.is-propositionʳ _ → Eq.left-closure ext 0 $ Q./ᴱ-is-set .Q.[]ʳ ys → ([ xs ] ≡ [ ys ]) ↝⟨ inverse $ Q.related≃[equal] (Is-QER→Is-equivalence-relation-⟵ ∼-QER) T.truncation-is-proposition ⟩ (_∼_ ⟵) xs ys ↝⟨ Eq.⇔→≃ T.truncation-is-proposition (Π-closure ext 1 λ _ → ℕ-set) (T.rec λ @0 where .T.truncation-is-propositionʳ → Π-closure ext 1 λ _ → ℕ-set .T.∣∣ʳ (zs , xs∼zs , ys∼zs) z → count₁ z xs ≡⟨ xs∼zs z ⟩ count₂ z zs ≡⟨ sym $ ys∼zs z ⟩∎ count₁ z ys ∎) (λ xs∼ys → T.∥∥ᴱ-map (λ (zs , xs∼zs) → zs , xs∼zs , λ z → count₁ z ys ≡⟨ sym $ xs∼ys z ⟩ count₁ z xs ≡⟨ xs∼zs z ⟩∎ count₂ z zs ∎) (∼-QER .proj₂ .proj₁ xs)) ⟩□ (∀ z → count₁ z xs ≡ count₁ z ys) □ -- This property can easily be transported to -- Assoc-list-bag /ᴱ _∼_ ⟶. @0 Assoc-list-≡≃ : let count = Raw-bag-structure-Assoc-list-bag-/ᴱ .proj₂ .proj₂ .proj₂ in (xs ys : Assoc-list-bag /ᴱ _∼_ ⟶) → (xs ≡ ys) ≃ (∀ z → count z xs ≡ count z ys) Assoc-list-≡≃ = subst (λ B → let count = B .proj₂ .proj₂ .proj₂ .proj₂ in (xs ys : B .proj₁) → (xs ≡ ys) ≃ (∀ z → count z xs ≡ count z ys)) List-/ᴱ≡Assoc-list-/ᴱ List-≡≃
{ "alphanum_fraction": 0.4792981888, "avg_line_length": 36.6627101879, "ext": "agda", "hexsha": "57ef13a9b6c667e681b5d8a6e4fd17c8c8258ace", "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/Structure-identity-principle/Erased.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/Structure-identity-principle/Erased.agda", "max_line_length": 146, "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/Structure-identity-principle/Erased.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": 41706, "size": 111198 }
{-# OPTIONS --without-K #-} module Leftovers.Leftovers where open import Function using (_$_) open import Data.Bool import Data.String as String open import Leftovers.TraverseTerm open import Leftovers.Utils import Level as Level open import Reflection open import Reflection.Term open import Reflection.TypeChecking.Monad.Instances open import Reflection.Argument using (unArg) open import Data.Fin using (toℕ ; Fin) open import Data.Unit open import Data.Nat as Nat hiding (_⊓_) open import Data.Nat.Show as NShow open import Data.Product open import Data.List as List import Data.Vec as Vec open import Data.Vec using (Vec) import Data.Vec.Categorical as VCat import Data.List.Categorical open Data.List.Categorical.TraversableM {m = Level.zero} tcMonad open import Data.Maybe using (just ; nothing) open import Function.Nary.NonDependent open import Data.Product.Nary.NonDependent open import Category.Monad.State import Category.Monad as Monad open import Level.Literals using (#_) import Data.Fin.Reflection import Leftovers.Monad as L data Holes (n : ℕ) (levels : Levels n) (sets : Sets n levels ) : Set (⨆ n levels) where makeHoles : Product n sets → Holes n levels sets getHoles : ∀ {n ls sets} → Holes n ls sets → Product n sets getHoles (makeHoles p) = p {-# INLINE getHoles #-} nthHole : ∀ n {ls} {as : Sets n ls } k → Holes n ls as → Projₙ as k nthHole n k h = projₙ n k (getHoles h) {-# INLINE nthHole #-} infixr 10 _∥_ _∥_ : ∀ {n : ℕ} {levels : Levels n} {sets : Sets n levels} {ℓ} {X : Set ℓ} → Holes n levels sets → X → Holes (suc n) (ℓ , levels) (X , sets) _∥_ {n = zero} {sets = sets} {X = X} holes x = makeHoles x _∥_ {n = suc n} {sets = sets} {X = X} holes x = makeHoles (x , getHoles holes) -- fillHoles : ∀ {ℓ} {n} {ls} {types : Sets n ls} {T : Set ℓ} → (Holes n ls types → T) → Product n types → T -- fillHoles f args = f (makeHoles args) -- quoteSets {n = suc n} (x Vec.∷ v) = app (app (quoteTerm (_,_ {A = Set} {B = λ x₁ → Sets n (proj₂ nSet)} )) x) (quoteSets v) -- record MetaInContext : Set where -- constructor Cmeta -- field -- context : LCxt -- unapplied : Term -- applied : Term -- -- open import Agda.Builtin.Nat using (_-_) --Given a hole, infer its function type, --taking anything in the hole's context that's not in the current context -- as an argument inferHoleType : L.Hole → TC Type inferHoleType hole = do currentContext ← getContext let numExtras = (List.length (L.Hole.context hole)) - (List.length currentContext) extras = List.take numExtras (L.Hole.context hole) holeType ← inContext (L.Hole.context hole) (inferType (L.Hole.hole hole)) addArrows extras holeType where open import Agda.Builtin.Nat addArrows : List (Arg Type) → Term → TC Type addArrows [] holeType = return holeType addArrows (x ∷ extras) holeType = do rec ← addArrows extras holeType return (pi x (abs "ctx" rec)) data Dummy : Set where dummy : Dummy sep : Term → TC Term sep t = do debugPrint "" 2 (strErr "Finding sep for " ∷ strErr (showTerm t) ∷ []) ty ← inferType t debugPrint "" 2 (strErr "sep got type " ∷ strErr (showTerm ty) ∷ []) let ret = (def (quote identity) [ vArg t ]) ⦂ ty return ret open import Reflection.DeBruijn using (weaken) open import Leftovers.Everywhere tcMonad -- Hack using case-lambda to convince Agda that a term is a definition -- Helps with the termination checker -- makeDef : Term → TC Term -- makeDef t = do -- ty ← inferType t -- let ret = pat-lam [ clause [] [ vArg (con (quote dummy) []) ] t ] [] -- return (app (def (quote the) (vArg (pi (vArg (quoteTerm Dummy)) (abs "_" (weaken 1 ty))) ∷ vArg ret ∷ [])) (quoteTerm dummy)) getMetas : Term → TC (List L.Hole) getMetas t = do -- body <- newMeta goalType debugPrint "Hello" 2 (strErr "Ran macro, body var is " ∷ termErr t ∷ []) -- L.runLeftovers (theMacro body) --Now we see what holes are left let handleMetas : _ → Meta → Data.Maybe.Maybe L.Hole handleMetas ctx m = just (L.mkHole m (meta m (List.map (λ x → vArg (var x [])) (List.downFrom (length ctx )))) (List.map proj₂ ctx)) debugPrint "L" 2 (strErr "After ALLMETAS " ∷ []) -- debugPrint "L" 2 (strErr "ALLMETAS NORM " ∷ List.map termErr normMetas) let metaList = (collectFromSubterms (record { onVar = λ _ _ → nothing ; onMeta = handleMetas ; onCon = λ _ _ → nothing ; onDef = λ _ _ → nothing }) t ) return (List.deduplicate L.equivDec metaList) -- Given the size of the starting context, a hole, -- and the list of parameters to add to the start context, -- Generate a new hole whose context has the new parameters -- inserted into the middle. -- We need this because a meta might occur in a deeper scope than -- where we're inserting the new variables. -- weakenMeta : ℕ → List (Arg Type) → L.Hole → L.Hole -- weakenMeta startSize newParams hole = -- L.mkHole (Reflection.DeBruijn.weakenFrom (numNew + 1) (length newParams) (L.Hole.hole hole)) fullCtx -- where -- numNew = List.length (L.Hole.context hole) - startSize -- fullCtx : List (Arg Type) -- fullCtx with (newCtx , startCtx) ← List.splitAt numNew (L.Hole.context hole) -- = newCtx ++ newParams ++ startCtx -- Given the length of the current context -- and a meta in a possibly deeper context -- return the type of the meta in the original context -- e.g. a function type abstracting over any new variables abstractMetaType : ℕ → (L.Hole × Type) → Type abstractMetaType numStart (hole , ty) = foldr (λ param ty → pi param (abs "arg" ty)) ty (take (length (L.Hole.context hole) - numStart) (L.Hole.context hole)) -- Given the size of the current context and a list of new parameter types to add -- freshen all metas to take new parameters and weaken DeBruijn variables accordingly -- Also forgets any blocked constraints on those metas, since they're replaced by new ones injectParameters : List Type → List Type → Term → TC Term injectParameters currentCtx injectedCtx t = everywhere defaultActions freshenMeta (weaken (length injectedCtx) t) where freshenMeta : Cxt → Term → TC Term freshenMeta innerVars (meta m xs) = do mtype ← inferType (meta m xs) newMeta mtype freshenMeta innerVars t = return t open import Data.Maybe using (Maybe ; just ; nothing) record MacroResult : Set where constructor macroResult field body : Term numMetas : ℕ holes : Vec L.Hole numMetas types : Vec Type numMetas indexFor : Meta → Maybe (Fin numMetas) getMacroHoles : Type → List (Arg Type) → (Term → L.Leftovers ⊤) → TC MacroResult getMacroHoles targetType ctx theMacro = runSpeculative $ do (body , _) ← L.runLeftovers ((L.freshMeta targetType) L.>>= λ hole → theMacro hole L.>> L.pure hole) normBody ← normalise body metas ← getMetas normBody let metaVec = Vec.fromList metas debugPrint "Leftovers" 2 (strErr "All holes " ∷ []) -- debugPrint "Leftovers" 2 (strErr "All holes " ∷ List.map (λ m → termErr (L.Hole.hole m)) metas) -- Now we know how many arguments we need to take debugPrint "Leftovers" 2 (strErr "Unified num holes " ∷ []) -- Get the type of each hole *in its context* types <- VCat.TraversableM.forM {a = Level.zero} {n = length metas} tcMonad (metaVec) λ hole → inContext (L.Hole.context hole ++ ctx) do -- debugPrint "" 2 (strErr "Context : " ∷ strErr (String.intersperse ",, " (List.map (λ x → showTerm (unArg x)) (contextForHole hole))) ∷ []) debugPrint "" 2 (strErr "Getting type of hole " ∷ termErr ( (L.Hole.hole hole) ) ∷ strErr " !" ∷ []) ty ← inferType (L.Hole.hole hole) debugPrint "" 2 [ strErr "got type" ] return ty let indexedHoles = Vec.toList (Vec.zip (Vec.allFin (length metas)) metaVec) debugPrint "" 2 (strErr "Indexed holes: " ∷ List.map (λ x → termErr (meta (L.Hole.holeMeta (proj₂ x)) [])) indexedHoles) let indexForMeta m = Data.Maybe.map proj₁ $ head (filter (λ y → m Meta.≟ L.Hole.holeMeta (proj₂ y)) indexedHoles) debugPrint "Hello" 2 (strErr "normalised MacroBody " ∷ termErr normBody ∷ []) return (macroResult normBody _ metaVec types indexForMeta , false) -- ((body , metas , types) , false) where open import Reflection.Meta as Meta metaToArg : MacroResult → Cxt → Term → TC Term metaToArg results cxt t@(meta m _) with (MacroResult.indexFor results m) ... | just i = do let ithHole = Vec.lookup (MacroResult.holes results) i numNewInContext = length (L.Hole.context ithHole) argNum = (numNewInContext + ((MacroResult.numMetas results - 1) - toℕ i)) debugPrint "" 2 (strErr "Replacing meta " ∷ strErr (showTerm (meta m [])) ∷ strErr " with arg " ∷ strErr (NShow.show argNum) ∷ []) return (var argNum (List.map (λ x → vArg (var x [])) (List.upTo numNewInContext))) ... | nothing = typeError (strErr "Internal Error: unfound meta " ∷ termErr (meta m []) ∷ strErr " when finding Leftover holes" ∷ []) metaToArg _ _ t = return t findLeftovers : ∀ {ℓ} → Set ℓ → (Term → L.Leftovers ⊤) → Term → TC ⊤ findLeftovers targetSet theMacro goal = do startContext ← getContext let startCtxLen = List.length startContext targetType ← quoteTC targetSet -- Unification variable for number of holes, we don't know how many yet numHoles ← newMeta (quoteTerm ℕ) -- Unification variables for the HVec of holes let levelsType = (def (quote Levels) (vArg numHoles ∷ [])) levels ← newMeta levelsType -- def (quote nSet) [ hArg numHoles ] let setsType = (def (quote Sets) (vArg numHoles ∷ vArg levels ∷ [])) sets ← newMeta setsType let productType = def (quote Holes) (vArg numHoles ∷ vArg levels ∷ vArg sets ∷ []) -- Make sure the type of the function we produce matches (unifies with) -- (Holes -> Target Type) let funType = pi (vArg productType) (abs "holes" targetType) checkType goal funType let extContext = vArg productType ∷ startContext let contextForHole : L.Hole → List (Arg Type) contextForHole hole = (L.Hole.context hole) ++ extContext debugPrint "Leftovers" 2 (strErr "Goal function type " ∷ termErr funType ∷ []) -- The return type of the function we're producing -- (argType , goalAbs) ← case funType of λ -- { (pi (arg _ dom) cod) → return (dom , cod) -- ; _ → typeError (strErr "Need to give as argument to applyPartial" ∷ [])} -- unify productType argType -- -- goalType ← extendContext (vArg productType) (newMeta (quoteTerm Set)) -- unify funType (pi (vArg productType) goalAbs) -- Run the given macro on a fresh hole -- in a context extended with the argument with the Holes debugPrint "Leftovers" 2 (strErr "goalType before run theMacro" ∷ termErr targetType ∷ []) result ← getMacroHoles targetType startContext theMacro let numMetas = MacroResult.numMetas result debugPrint "Leftovers" 2 (strErr "Got holes types " ∷ []) -- debugPrint "Hello" 2 (strErr "Got hole types" ∷ List.map termErr (Vec.toList holeTypes)) let abstractedTypes = (Vec.map (abstractMetaType startCtxLen) (Vec.zip (MacroResult.holes result) (MacroResult.types result))) setsFromTypes = quoteSets abstractedTypes debugPrint "Hello" 2 (strErr "Made sets " ∷ strErr (showTerm setsFromTypes) ∷ []) levelsFromTypes ← quoteLevels abstractedTypes debugPrint "Hello" 2 (strErr "Made levels " ∷ strErr (showTerm levelsFromTypes) ∷ []) -- Now we know the types of our holes unify sets setsFromTypes unify levels levelsFromTypes --This gives us enough information to make a function parameterized over the types of holes --We traverse the result of the macro, replacing each meta with a parameter --and wrap the hole thing in an n-ary lambda taking parameters of the hole types funBody ← everywhere defaultActions (metaToArg result) (MacroResult.body result) sepBody ← inContext (List.map vArg (List.reverse $ Vec.toList abstractedTypes) ++ startContext) $ sep funBody -- let sepBody = funBody -- Pair each meta with its index -- let indexedMetas = (Vec.zip (Vec.allFin _) (Vec.fromList {!!})) -- -- Replace the ith meta with the ith element of the HList -- forM (Vec.toList indexedMetas) λ ( i , hole ) → inContext (contextForHole hole) do -- -- TODO is this bad? why re-infer? -- holeType ← inferType (L.Hole.hole hole) -- let -- holeCtx = L.Hole.context hole -- numArgs = length holeCtx -- rhs = -- (def (quote nthHole) -- (vArg (lit (nat (length {!!}))) -- -- ∷ hArg (quoteTerm nSet) -- ∷ hArg (levels ⦂ levelsType) -- ∷ hArg (sets ⦂ setsType) -- ∷ vArg (Data.Fin.Reflection.toTerm i) -- --TODO hidden args for context vars? -- ∷ vArg (var numArgs [] ⦂ productType) -- ∷ (List.map (λ n → vArg (var n [])) (List.upTo numArgs)))) -- debugPrint "Hello" 2 (strErr "Unify LHS " ∷ strErr (showTerm (L.Hole.hole hole)) ∷ [] ) -- debugPrint "Hello" 2 (strErr "Unify RHS " ∷ strErr (showTerm rhs) ∷ [] ) -- unify (L.Hole.hole hole) (rhs ) -- debugPrint "" 2 (strErr "done unify" ∷ []) --Hack to help with termination debugPrint "" 2 (strErr "got fun body " ∷ strErr (showTerm sepBody) ∷ []) nflam ← normalise (naryLam numMetas sepBody ⦂ def (quote _⇉_) (vArg sets ∷ vArg targetType ∷ [])) debugPrint "" 2 (strErr "making fun fun " ∷ strErr (showTerm nflam) ∷ []) --Produce the function that gives the result of the last macro let finalResult = (lam visible (abs "holes" (app (def (quote uncurryₙ) (vArg numHoles ∷ vArg (naryLam numMetas sepBody) ∷ [])) (def (quote getHoles) [ vArg (var 0 []) ]) ))) unify goal finalResult debugPrint "Hello" 2 (strErr "Final Result" ∷ termErr finalResult ∷ []) -- return tt where naryLam : ℕ → Term → Term naryLam 0 x = x naryLam (suc n) x = lam visible (abs ("hole" String.++ NShow.show (suc n)) (naryLam n x)) quoteLevels : ∀ {n} → Vec.Vec Term n → TC Term quoteLevels Vec.[] = return (con (quote Level.lift) (vArg (quoteTerm tt) ∷ [])) quoteLevels {n = suc n} (x Vec.∷ v) = do rec ← quoteLevels {n = n} v typeOfType ← inferType x let theLevel = case typeOfType of λ { (sort (set l)) → l ; (sort (lit l)) → (def (quote #_) (vArg (lit (nat l)) ∷ [] )) ; _ → quoteTerm Level.zero } return (con (quote _,_) (vArg theLevel ∷ vArg rec ∷ [] )) quoteSets : ∀ {n} → Vec.Vec Term n → Term quoteSets Vec.[] = con (quote Level.lift) (vArg (quoteTerm tt) ∷ []) quoteSets {n = suc n} (x Vec.∷ v) = (con (quote _,_) (vArg x ∷ vArg (quoteSets v) ∷ [] )) -- infixr 10 [_⇒_] by : ∀ {ℓ} {A : Set ℓ} {n} {ls} {types : Sets n ls} → (theMacro : Term → L.Leftovers ⊤) → {@(tactic findLeftovers A theMacro) f : Holes n ls types → A} → Product n types → A by {n = n} _ {f} x = f (makeHoles x) by' : ∀ {ℓ} {A : Set ℓ} {n} {ls} {types : Sets n ls} → (theMacro : Term → L.Leftovers ⊤) → {@(tactic findLeftovers A theMacro) f : Holes n ls types → A} → ⊤ → Product n types → A by' {n = n} _ {f} _ x = f (makeHoles x) -- by {n = n} _ {f} = curryₙ n (λ x → f (makeHoles x)) open import Relation.Nullary -- syntax withLeftovers tac x = ► tac ⇒ x ◄ macro getNormal : ∀ {X : Set} → X → Term → TC ⊤ getNormal {X = X} x goal = do t ← quoteTC x ttype ← quoteTC X checkType goal ttype debugPrint "" 2 (strErr "get Normal term " ∷ termErr t ∷ []) debugPrint "" 2 (strErr "get Normal term type " ∷ termErr ttype ∷ []) goalType ← inferType goal debugPrint "" 2 (strErr "get Normal goal type " ∷ termErr goalType ∷ []) unify goalType ttype nf ← normalise t nfSimplified ← everywhere defaultActions action t debugPrint "" 2 (strErr "get Normal term nf " ∷ termErr nf ∷ []) unify goal nfSimplified where open import Reflection.Name as N action : Cxt → Term → TC Term action ctx t@(def gholes (arg _ arg1 ∷ []) ) = do case (gholes N.≟ quote getHoles) of λ { (yes _) → do nf1 ← normalise arg1 case nf1 of λ { (def mholes (arg _ tup ∷ [])) → case (mholes N.≟ quote makeHoles) of λ {(yes _) → normalise tup ; (no _) → return t} ; _ → return t} ; (no _) → return t } action _ t = return t -- applyNormal : ∀ {ℓ1 ℓ2} {X : Set ℓ1} {Y : Set ℓ2} → (X → Y) → X → Term → TC ⊤ -- applyNormal {X = X} {Y} f x goal = do -- goalType ← inferType goal -- tX ← quoteTC X -- tY ← quoteTC Y -- tf ← quoteTC f -- tx ← quoteTC x -- nf ← normalise (app tf tx) -- unify goalType tY -- unify nf goal default : {A : Set} → A → Term → TC ⊤ default x hole = bindTC (quoteTC x) (unify hole)
{ "alphanum_fraction": 0.6280709868, "avg_line_length": 40.5128805621, "ext": "agda", "hexsha": "3b0624478a2fd92f0930fa50820814f9cff86f8b", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "JoeyEremondi/AgdaLeftovers", "max_forks_repo_path": "src/Leftovers/Leftovers.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "JoeyEremondi/AgdaLeftovers", "max_issues_repo_path": "src/Leftovers/Leftovers.agda", "max_line_length": 154, "max_stars_count": null, "max_stars_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "JoeyEremondi/AgdaLeftovers", "max_stars_repo_path": "src/Leftovers/Leftovers.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5272, "size": 17299 }
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Pushout.Base where open import Cubical.Core.Glue open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Data.Unit open import Cubical.HITs.Susp data Pushout {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} (f : A → B) (g : A → C) : Type (ℓ-max ℓ (ℓ-max ℓ' ℓ'')) where inl : B → Pushout f g inr : C → Pushout f g push : (a : A) → inl (f a) ≡ inr (g a) -- Suspension defined as a pushout PushoutSusp : ∀ {ℓ} (A : Type ℓ) → Type ℓ PushoutSusp A = Pushout {A = A} {B = Unit} {C = Unit} (λ _ → tt) (λ _ → tt) PushoutSusp→Susp : ∀ {ℓ} {A : Type ℓ} → PushoutSusp A → Susp A PushoutSusp→Susp (inl _) = north PushoutSusp→Susp (inr _) = south PushoutSusp→Susp (push a i) = merid a i Susp→PushoutSusp : ∀ {ℓ} {A : Type ℓ} → Susp A → PushoutSusp A Susp→PushoutSusp north = inl tt Susp→PushoutSusp south = inr tt Susp→PushoutSusp (merid a i) = push a i Susp→PushoutSusp→Susp : ∀ {ℓ} {A : Type ℓ} (x : Susp A) → PushoutSusp→Susp (Susp→PushoutSusp x) ≡ x Susp→PushoutSusp→Susp north = refl Susp→PushoutSusp→Susp south = refl Susp→PushoutSusp→Susp (merid _ _) = refl PushoutSusp→Susp→PushoutSusp : ∀ {ℓ} {A : Type ℓ} (x : PushoutSusp A) → Susp→PushoutSusp (PushoutSusp→Susp x) ≡ x PushoutSusp→Susp→PushoutSusp (inl _) = refl PushoutSusp→Susp→PushoutSusp (inr _) = refl PushoutSusp→Susp→PushoutSusp (push _ _) = refl PushoutSusp≃Susp : ∀ {ℓ} {A : Type ℓ} → PushoutSusp A ≃ Susp A PushoutSusp≃Susp = isoToEquiv (iso PushoutSusp→Susp Susp→PushoutSusp Susp→PushoutSusp→Susp PushoutSusp→Susp→PushoutSusp) PushoutSusp≡Susp : ∀ {ℓ} {A : Type ℓ} → PushoutSusp A ≡ Susp A PushoutSusp≡Susp = isoToPath (iso PushoutSusp→Susp Susp→PushoutSusp Susp→PushoutSusp→Susp PushoutSusp→Susp→PushoutSusp)
{ "alphanum_fraction": 0.6682464455, "avg_line_length": 35.8301886792, "ext": "agda", "hexsha": "ed18bf81217a7c9d062e1f6f3744fbe596461200", "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/HITs/Pushout/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/HITs/Pushout/Base.agda", "max_line_length": 120, "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/HITs/Pushout/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 706, "size": 1899 }
{- Generic UARel, DUARel, and SubstRel: the path relation is always univalent -} {-# OPTIONS --safe #-} module Cubical.Displayed.Generic where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Transport open import Cubical.Displayed.Base open import Cubical.Displayed.Subst private variable ℓ ℓA ℓA' ℓP ℓ≅A ℓ≅A' ℓB ℓB' ℓ≅B ℓ≅B' ℓC ℓ≅C : Level -- UARel for an arbitrary type 𝒮-generic : (A : Type ℓA) → UARel A ℓA UARel._≅_ (𝒮-generic A) = _≡_ UARel.ua (𝒮-generic A) a a' = idEquiv (a ≡ a') -- DUARel for an arbitrary family 𝒮ᴰ-generic : {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) (B : A → Type ℓB) → DUARel 𝒮-A B ℓB 𝒮ᴰ-generic 𝒮-A B .DUARel._≅ᴰ⟨_⟩_ b p b' = PathP (λ i → B (UARel.≅→≡ 𝒮-A p i)) b b' 𝒮ᴰ-generic 𝒮-A B .DUARel.uaᴰ b p b' = idEquiv _ -- SubstRel for an arbitrary family 𝒮ˢ-generic : {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) (B : A → Type ℓB) → SubstRel 𝒮-A B 𝒮ˢ-generic 𝒮-A B .SubstRel.act p = substEquiv B (UARel.≅→≡ 𝒮-A p) 𝒮ˢ-generic 𝒮-A B .SubstRel.uaˢ p b = refl
{ "alphanum_fraction": 0.6692233941, "avg_line_length": 28.1891891892, "ext": "agda", "hexsha": "d28d705bcf1af92aa86f820ca14c5f47170266b6", "lang": "Agda", "max_forks_count": 134, "max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z", "max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z", "max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "marcinjangrzybowski/cubical", "max_forks_repo_path": "Cubical/Displayed/Generic.agda", "max_issues_count": 584, "max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "marcinjangrzybowski/cubical", "max_issues_repo_path": "Cubical/Displayed/Generic.agda", "max_line_length": 82, "max_stars_count": 301, "max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "marcinjangrzybowski/cubical", "max_stars_repo_path": "Cubical/Displayed/Generic.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z", "num_tokens": 491, "size": 1043 }
{-# OPTIONS --copatterns #-} mutual data D : Set where c : R → D record R : Set where coinductive field out : D open R mutual d : D d = c r r : R out r = d f : D → {A : Set} → A f (c x) = f (out x) -- should not termination check absurd : {A : Set} → A absurd = f d
{ "alphanum_fraction": 0.5165562914, "avg_line_length": 11.6153846154, "ext": "agda", "hexsha": "f5ef5e3b4c8aab914b0cb047f9db007ec32682b1", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "alhassy/agda", "max_forks_repo_path": "test/Fail/TerminationNoCoinductiveProjectionFromVariable.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "alhassy/agda", "max_issues_repo_path": "test/Fail/TerminationNoCoinductiveProjectionFromVariable.agda", "max_line_length": 31, "max_stars_count": 3, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "test/Fail/TerminationNoCoinductiveProjectionFromVariable.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": 118, "size": 302 }
module _ (A : Set) where record R : Set where data D : Set where open R (record {}) F : D → Set₃ F _ with Set₁ F _ | _ = Set₂
{ "alphanum_fraction": 0.5909090909, "avg_line_length": 11, "ext": "agda", "hexsha": "bd3a4c13fef9139fbbef860d83cc65211b9c231a", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue2726.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/Issue2726.agda", "max_line_length": 24, "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/Issue2726.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": 51, "size": 132 }
open import SOAS.Metatheory.Syntax -- Second-order equational logic library module SOAS.Metatheory.SecondOrder.Equality {T : Set} (Syn : Syntax {T}) where open import SOAS.Common open import SOAS.Families.Core {T} open import SOAS.Context open import SOAS.Variable open import SOAS.Metatheory.FreeMonoid Syn open import SOAS.Metatheory.SecondOrder.Metasubstitution Syn open import SOAS.Metatheory.SecondOrder.Unit Syn open import SOAS.ContextMaps.CategoryOfRenamings {T} open import SOAS.Families.Build open import SOAS.Metatheory Syn open Syntax Syn open Theory private variable α β γ : T Γ Δ Π : Ctx 𝔐 𝔑 : MCtx -- Equational reasoning system extended from an axiom relation on terms module EqLogic (_▹_⊢_≋ₐ_ : ∀ 𝔐 Γ {α} → (𝔐 ▷ 𝕋) α Γ → (𝔐 ▷ 𝕋) α Γ → Set) where -- Equality between terms: smallest equivalence relation closed under the axioms -- and parametrised metasubstitution data _▹_⊢_≋_ : (𝔐 : MCtx){α : T}(Γ : Ctx) → (𝔐 ▷ 𝕋) α Γ → (𝔐 ▷ 𝕋) α Γ → Set₁ where ax : {t s : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ₐ s → 𝔐 ▹ Γ ⊢ t ≋ s eq : {t s : (𝔐 ▷ 𝕋) α Γ} → t ≡ s → 𝔐 ▹ Γ ⊢ t ≋ s sy : {t s : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ s → 𝔐 ▹ Γ ⊢ s ≋ t tr : {t s u : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ s → 𝔐 ▹ Γ ⊢ s ≋ u → 𝔐 ▹ Γ ⊢ t ≋ u □ms : {t s : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ s → (ρ : Γ ↝ Δ) → (ζ ξ : MSub Δ 𝔐 𝔑) → (∀{τ Π}(𝔪 : Π ⊩ τ ∈ 𝔐) → 𝔑 ▹ (Π ∔ Δ) ⊢ (ix≀ ζ 𝔪) ≋ (ix≀ ξ 𝔪)) → 𝔑 ▹ Δ ⊢ (□msub≀ t ρ ζ) ≋ (□msub≀ s ρ ξ) -- Reflexivity of ≋ lifted from refl rf : {t : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ t rf = eq refl infix 1 _▹_⊢_≋_ -- Helpers for equational reasoning module ≋-Reasoning where _≋⟨_⟩_ : (t : (𝔐 ▷ 𝕋) α Γ) {s u : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ s → 𝔐 ▹ Γ ⊢ s ≋ u → 𝔐 ▹ Γ ⊢ t ≋ u t ≋⟨ t≋s ⟩ s≋u = tr {t = t} t≋s s≋u _≋⟨_⟩ₛ_ : (t : (𝔐 ▷ 𝕋) α Γ) {s u : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ s ≋ t → 𝔐 ▹ Γ ⊢ s ≋ u → 𝔐 ▹ Γ ⊢ t ≋ u t ≋⟨ s≋t ⟩ₛ s≋u = tr {t = t} (sy s≋t) s≋u _≡⟨_⟩_ : (t : (𝔐 ▷ 𝕋) α Γ){s : (𝔐 ▷ 𝕋) α Γ} {u : (𝔐 ▷ 𝕋) α Γ} → t ≡ s → 𝔐 ▹ Γ ⊢ s ≋ u → 𝔐 ▹ Γ ⊢ t ≋ u t ≡⟨ t≡s ⟩ s≋u = t ≋⟨ eq t≡s ⟩ s≋u _≡⟨⟩_ : (t : (𝔐 ▷ 𝕋) α Γ) {s : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ s → 𝔐 ▹ Γ ⊢ t ≋ s t ≡⟨⟩ t≋s = t ≡⟨ refl ⟩ t≋s begin_ : {t s : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ s → 𝔐 ▹ Γ ⊢ t ≋ s begin t≋s = t≋s _∎ : (t : (𝔐 ▷ 𝕋) α Γ) → 𝔐 ▹ Γ ⊢ t ≋ t t ∎ = rf infix 1 begin_ infixr 2 _≋⟨_⟩_ infixr 2 _≋⟨_⟩ₛ_ infixr 2 _≡⟨_⟩_ infixr 2 _≡⟨⟩_ infix 3 _∎ -- Rewrite two sides of ≋ with ≡ rw : {t t′ s s′ : (𝔐 ▷ 𝕋) α Γ} → t ≡ t′ → s ≡ s′ → 𝔐 ▹ Γ ⊢ t ≋ s → 𝔐 ▹ Γ ⊢ t′ ≋ s′ rw {t = t}{t′}{s}{s′} t≡t′ s≡s′ t≋s = begin t′ ≡⟨ sym t≡t′ ⟩ t ≋⟨ t≋s ⟩ s ≡⟨ s≡s′ ⟩ s′ ∎ where open ≋-Reasoning -- Closure under base metasubstitution ms : {t s : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ s → (ζ ξ : MSub Γ 𝔐 𝔑) → (∀{τ Π}(𝔪 : Π ⊩ τ ∈ 𝔐) → 𝔑 ▹ (Π ∔ Γ) ⊢ (ix≀ ζ 𝔪) ≋ (ix≀ ξ 𝔪)) → 𝔑 ▹ Γ ⊢ msub≀ t ζ ≋ msub≀ s ξ ms {t = t}{s} t≋s ζ ξ ζ≋ξ = rw (□msub-id t (ix≀ ζ)) (□msub-id s (ix≀ ξ)) (□ms t≋s id ζ ξ ζ≋ξ) -- Metasubstitution of same mapping applied to two equivalent terms ms-eq : {t s : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ s → (ζ : MSub Γ 𝔐 𝔑) → 𝔑 ▹ Γ ⊢ msub≀ t ζ ≋ msub≀ s ζ ms-eq {t = t}{s} t≋s ζ = ms t≋s ζ ζ (λ 𝔪 → rf) -- Closure under renaming ren≋ : {t s : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ s → (ρ : Γ ↝ Δ) → 𝔐 ▹ Δ ⊢ 𝕣𝕖𝕟 ∥ 𝔐 ∥ t ρ ≋ 𝕣𝕖𝕟 ∥ 𝔐 ∥ s ρ ren≋ {𝔐}{α}{Γ}{Δ}{t = t}{s} t≋s ρ = begin (𝕣𝕖𝕟 ∥ 𝔐 ∥ t ρ) ≡⟨ sym (□msub-runit t ρ) ⟩ □msub t ρ ms-unit ≡⟨ sym (cong (□msub t ρ) (iext (dext (id≀≈ms-unit Δ)))) ⟩ □msub≀ t ρ (id≀ Δ) ≋⟨ □ms t≋s ρ (id≀ Δ) (id≀ Δ) (λ 𝔪 → rf) ⟩ □msub≀ s ρ (id≀ Δ) ≡⟨ cong (□msub s ρ) (iext (dext (id≀≈ms-unit Δ))) ⟩ □msub s ρ ms-unit ≡⟨ □msub-runit s ρ ⟩ (𝕣𝕖𝕟 ∥ 𝔐 ∥ s ρ) ∎ where open ≋-Reasoning -- Lemma to apply equality to terms attached to the end of a metasubstitution ▹-eq : {Π′ : Ctx}{s u : (𝔑 ▷ 𝕋) β (Π′ ∔ Γ)} → 𝔑 ▹ (Π′ ∔ Γ) ⊢ s ≋ u → (ζ ξ : MSub Γ 𝔐 𝔑) → (∀{τ Π}(𝔪 : Π ⊩ τ ∈ 𝔐) → 𝔑 ▹ (Π ∔ Γ) ⊢ (ix≀ ζ 𝔪) ≋ (ix≀ ξ 𝔪)) → (𝔪 : Π ⊩ α ∈ (𝔐 ⁅ Π′ ⊩ₙ β ⁆)) → 𝔑 ▹ Π ∔ Γ ⊢ ix≀ (ζ ▹ s) 𝔪 ≋ ix≀ (ξ ▹ u) 𝔪 ▹-eq e ◦ ◦ ζ≋ξ ↓ = e ▹-eq e (x ◃ ζ) (y ◃ ξ) ζ≋ξ ↓ = ζ≋ξ ↓ ▹-eq e (x ◃ ζ) (y ◃ ξ) ζ≋ξ (↑ 𝔪) = ▹-eq e ζ ξ (λ 𝔫 → ζ≋ξ (↑ 𝔫)) 𝔪 -- Congruence: metasubstitution of equivalent terms into a term extended with -- a new metavariable cong≋ : (t : (𝔐 ⁅ Π ⊩ₙ β ⁆ ▷ 𝕋) α Γ) → {s u : (𝔐 ▷ 𝕋) β (Π ∔ Γ)} → 𝔐 ▹ (Π ∔ Γ) ⊢ s ≋ u → 𝔐 ▹ Γ ⊢ instₑ t s ≋ instₑ t u cong≋ t {s} {u} s≋u = ms rf (id≀ _ ▹ s) (id≀ _ ▹ u) (▹-eq s≋u (id≀ _) (id≀ _) λ _ → rf) -- Double congruence cong₂≋ : {Π₁ Π₂ : Ctx}{β₁ β₂ : T} (t : ((𝔐 ⁅ Π₁ ⊩ₙ β₁ ⁆) ⁅ Π₂ ⊩ₙ β₂ ⁆ ▷ 𝕋) α Γ) → {s₁ u₁ : (𝔐 ▷ 𝕋) β₁ (Π₁ ∔ Γ)} → {s₂ u₂ : (𝔐 ▷ 𝕋) β₂ (Π₂ ∔ Γ)} → 𝔐 ▹ (Π₁ ∔ Γ) ⊢ s₁ ≋ u₁ → 𝔐 ▹ (Π₂ ∔ Γ) ⊢ s₂ ≋ u₂ → 𝔐 ▹ Γ ⊢ instₑ₂ t s₁ s₂ ≋ instₑ₂ t u₁ u₂ cong₂≋ t {s₁}{u₁}{s₂}{u₂} s≋u₁ s≋u₂ = ms rf ((id≀ _ ▹ s₁) ▹ s₂) ((id≀ _ ▹ u₁) ▹ u₂) (▹-eq s≋u₂ (id≀ _ ▹ s₁) (id≀ _ ▹ u₁) (▹-eq s≋u₁ (id≀ _) (id≀ _) (λ - → rf))) -- Syntactic sugar cong[_]inside_ : {s u : (𝔐 ▷ 𝕋) β (Π ∔ Γ)} → 𝔐 ▹ (Π ∔ Γ) ⊢ s ≋ u → (t : (𝔐 ⁅ Π ⊩ₙ β ⁆ ▷ 𝕋) α Γ) → 𝔐 ▹ Γ ⊢ instₑ t s ≋ instₑ t u cong[ s≋u ]inside t = cong≋ t s≋u infix 05 cong[_]inside_ cong₂[_][_]inside_ : {Π₁ Π₂ : Ctx}{β₁ β₂ : T} → {s₁ u₁ : (𝔐 ▷ 𝕋) β₁ (Π₁ ∔ Γ)} → {s₂ u₂ : (𝔐 ▷ 𝕋) β₂ (Π₂ ∔ Γ)} → 𝔐 ▹ (Π₁ ∔ Γ) ⊢ s₁ ≋ u₁ → 𝔐 ▹ (Π₂ ∔ Γ) ⊢ s₂ ≋ u₂ → (t : ((𝔐 ⁅ Π₁ ⊩ₙ β₁ ⁆) ⁅ Π₂ ⊩ₙ β₂ ⁆ ▷ 𝕋) α Γ) → 𝔐 ▹ Γ ⊢ instₑ₂ t s₁ s₂ ≋ instₑ₂ t u₁ u₂ cong₂[ s≋u₁ ][ s≋u₂ ]inside t = cong₂≋ t s≋u₁ s≋u₂ infix 05 cong₂[_][_]inside_ -- Linear metasubstitution ○ms : {t s : (𝔐 ▷ 𝕋) α Γ} → 𝔐 ▹ Γ ⊢ t ≋ s → (ζ ξ : MSub Δ 𝔐 𝔑) → (∀{τ Π}(𝔪 : Π ⊩ τ ∈ 𝔐) → 𝔑 ▹ (Π ∔ Δ) ⊢ (ix≀ ζ 𝔪) ≋ (ix≀ ξ 𝔪)) → 𝔑 ▹ Γ ∔ Δ ⊢ ○msub≀ t ζ ≋ ○msub≀ s ξ ○ms {Γ = Γ}{𝔑 = 𝔑}{t = t}{s} t≋s ζ ξ ζ≋ξ = □ms t≋s (inl Γ) (inr≀ Γ ζ) (inr≀ Γ ξ) (λ {τ}{Π} 𝔪 → begin ix≀ (inr≀ Γ ζ) 𝔪 ≡⟨ ix-inr≀ ζ 𝔪 ⟩ (𝕣𝕖𝕟 ∥ 𝔑 ∥ (ix≀ ζ 𝔪) (Π ∔∣ inr Γ)) ≋⟨ ren≋ (ζ≋ξ 𝔪) (Π ∔∣ inr Γ) ⟩ (𝕣𝕖𝕟 ∥ 𝔑 ∥ (ix≀ ξ 𝔪) (Π ∔∣ inr Γ)) ≡⟨ sym (ix-inr≀ ξ 𝔪) ⟩ ix≀ (inr≀ Γ ξ) 𝔪 ∎) where open ≋-Reasoning -- Linear metasubstitution of same mapping applied to two equivalent terms ○ms-eq : {t s : (𝔐 ▷ 𝕋) α Π} → 𝔐 ▹ Π ⊢ t ≋ s → (ζ : MSub Γ 𝔐 𝔑) → 𝔑 ▹ Π ∔ Γ ⊢ ○msub≀ t ζ ≋ ○msub≀ s ζ ○ms-eq {t = t}{s} t≋s ζ = ○ms t≋s ζ ζ (λ 𝔪 → rf) -- Application of an axiom as a rewrite rule, and syntactic sugar ax≋ : {t s : (𝔐 ▷ 𝕋) α Π} → 𝔐 ▹ Π ⊢ t ≋ₐ s → (ζ : MSub Γ 𝔐 𝔑) → 𝔑 ▹ Π ∔ Γ ⊢ ○msub≀ t ζ ≋ ○msub≀ s ζ ax≋ a ζ = ○ms-eq (ax a) ζ ax_with《_ : {t s : (𝔐 ▷ 𝕋) α Π} → 𝔐 ▹ Π ⊢ t ≋ₐ s → (ζ : MSub Γ 𝔐 𝔑) → 𝔑 ▹ Π ∔ Γ ⊢ ○msub≀ t ζ ≋ ○msub≀ s ζ ax_with《_ = ax≋ infix 15 ax_with《_ -- Application of an equivalence as a rewrite rule, and syntactic sugar thm_with《_ : {t s : (𝔐 ▷ 𝕋) α Π} → 𝔐 ▹ Π ⊢ t ≋ s → (ζ : MSub Γ 𝔐 𝔑) → 𝔑 ▹ Π ∔ Γ ⊢ ○msub≀ t ζ ≋ ○msub≀ s ζ thm_with《_ = ○ms-eq infix 15 thm_with《_ -- Application of theorem with no metavariables thm : {t s : (⁅⁆ ▷ 𝕋) α Π} → ⁅⁆ ▹ Π ⊢ t ≋ s → 𝔐 ▹ Π ∔ Γ ⊢ ○msub≀ t ◦ ≋ ○msub≀ s ◦ thm e = thm e with《 ◦
{ "alphanum_fraction": 0.4311521477, "avg_line_length": 32.6331877729, "ext": "agda", "hexsha": "a9e569d975c340ad71ab1bba32cc085fd02c1fb6", "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": "b224d31e20cfd010b7c924ce940f3c2f417777e3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "k4rtik/agda-soas", "max_forks_repo_path": "SOAS/Metatheory/SecondOrder/Equality.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b224d31e20cfd010b7c924ce940f3c2f417777e3", "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": "k4rtik/agda-soas", "max_issues_repo_path": "SOAS/Metatheory/SecondOrder/Equality.agda", "max_line_length": 102, "max_stars_count": null, "max_stars_repo_head_hexsha": "b224d31e20cfd010b7c924ce940f3c2f417777e3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "k4rtik/agda-soas", "max_stars_repo_path": "SOAS/Metatheory/SecondOrder/Equality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4636, "size": 7473 }
open import Agda.Builtin.Reflection open import Agda.Builtin.Equality open import Agda.Builtin.Int open import Agda.Builtin.String open import Common.Prelude getFixity = primQNameFixity infixl -1729 _to_ _to_ : Set → Set → Set A to B = A → B data Check : Set₁ where equal : {A : Set} (x y : A) → x ≡ y → Check pattern _==_ x y = equal x y refl check-cons = getFixity (quote _∷_) == fixity right-assoc (related (pos 5)) check-to = getFixity (quote _to_) == fixity left-assoc (related (negsuc 1728)) check-eq = getFixity (quote _≡_) == fixity non-assoc (related (pos 4)) check-list = getFixity (quote List) == fixity non-assoc unrelated showAssoc : Associativity → String showAssoc left-assoc = "infixl" showAssoc right-assoc = "infixr" showAssoc non-assoc = "infix" showFixity : Fixity → String showFixity (fixity a unrelated) = "(no fixity)" showFixity (fixity a (related p)) = showAssoc a +S+ " " +S+ intToString p showFix : Name → String showFix x = showFixity (getFixity x) main : IO Unit main = putStrLn (showFix (quote _∷_)) >>= λ _ → putStrLn (showFix (quote _to_)) >>= λ _ → putStrLn (showFix (quote _≡_)) >>= λ _ → putStrLn (showFix (quote List)) >>= λ _ → return unit
{ "alphanum_fraction": 0.6720647773, "avg_line_length": 29.4047619048, "ext": "agda", "hexsha": "7b1ff72c42fbaa5973822b45530f861a4c0df4b8", "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/Compiler/simple/Issue1664.agda", "max_issues_count": 16, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "alhassy/agda", "max_issues_repo_path": "test/Compiler/simple/Issue1664.agda", "max_line_length": 81, "max_stars_count": 7, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "test/Compiler/simple/Issue1664.agda", "max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z", "max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z", "num_tokens": 410, "size": 1235 }
-- WARNING: This file was generated automatically by Vehicle -- and should not be modified manually! -- Metadata -- - Agda version: 2.6.2 -- - AISEC version: 0.1.0.1 -- - Time generated: ??? {-# OPTIONS --allow-exec #-} open import Vehicle open import Data.Rational as ℝ using () renaming (ℚ to ℝ) module monotonicity-output where private VEHICLE_PROJECT_FILE = "TODO_projectFile" f : ℝ → ℝ f = evaluate record { projectFile = VEHICLE_PROJECT_FILE ; networkUUID = "TODO_networkUUID" } abstract monotonic : ∀ (x1 : ℝ) → ∀ (x2 : ℝ) → x1 ℝ.≤ x2 → f x1 ℝ.≤ f x2 monotonic = checkProperty record { projectFile = VEHICLE_PROJECT_FILE ; propertyUUID = "TODO_propertyUUID" }
{ "alphanum_fraction": 0.68, "avg_line_length": 24.1379310345, "ext": "agda", "hexsha": "b95010e0e774f034e4139ce352dbb8448967ec64", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2021-11-16T14:30:47.000Z", "max_forks_repo_forks_event_min_datetime": "2021-03-15T15:22:31.000Z", "max_forks_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "wenkokke/vehicle", "max_forks_repo_path": "examples/network/monotonicity/monotonicity-output.agda", "max_issues_count": 53, "max_issues_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674", "max_issues_repo_issues_event_max_datetime": "2021-12-15T22:42:01.000Z", "max_issues_repo_issues_event_min_datetime": "2021-04-16T07:26:42.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "wenkokke/vehicle", "max_issues_repo_path": "examples/network/monotonicity/monotonicity-output.agda", "max_line_length": 65, "max_stars_count": 11, "max_stars_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "wenkokke/vehicle", "max_stars_repo_path": "examples/network/monotonicity/monotonicity-output.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-01T01:35:39.000Z", "max_stars_repo_stars_event_min_datetime": "2021-02-24T05:55:15.000Z", "num_tokens": 213, "size": 700 }
-- Operations on natural number {-# OPTIONS --without-K --safe #-} -- agad-stdlib open import Relation.Binary.PropositionalEquality module TypeTheory.Nat.Operations {a} -- | Type of natural number (N : Set a) -- | Zero (zero : N) -- | Successor function (suc : N → N) -- | Induction principle (ind : ∀ {p} (P : N → Set p) → P zero → (∀ k → P k → P (suc k)) → ∀ n → P n) -- | Computation rule for `zero` (ind-base : ∀ {p} (P : N → Set p) P-base P-step → ind P P-base P-step zero ≡ P-base) -- | Computation rule for `suc` (ind-step : ∀ {p} (P : N → Set p) P-base P-step n → ind P P-base P-step (suc n) ≡ P-step n (ind P P-base P-step n)) where -- agda-stdlib open import Level renaming (zero to lzero; suc to lsuc) open import Data.Empty open import Data.Bool using (Bool; true; false) open import Data.Product open import Function.Base private variable A : Set a -- recursion rec : ∀ {l} {A : Set l} → A → (A → A) → N → A rec {l} {A} z s n = ind (λ _ → A) z (λ k x → s x) n caseNat : ∀ {l} {A : Set l} (z s : A) → N → A caseNat {A = A} z s n = ind (λ x → A) z (λ k x → s) n -- predcessor pred : N → N pred n = ind (λ _ → N) zero (λ k x → k) n -- Arithematic infixl 6 _+_ _∸_ infixl 7 _*_ infix 4 _≤_ _≰_ _≥_ _≱_ _<_ _≮_ _>_ _≯_ infix 5 _≤ᵇ_ -- Addition _+_ : N → N → N m + n = rec n suc m -- Multiplication _*_ : N → N → N m * n = rec zero (λ k → n + k) m -- Monus _∸_ : N → N → N m ∸ n = rec m pred n -- Order _≤_ : N → N → Set a m ≤ n = ∃ λ o → m + o ≡ n _≰_ : N → N → Set a m ≰ n = m ≤ n → ⊥ _≥_ : N → N → Set a m ≥ n = n ≤ m _≱_ : N → N → Set a m ≱ n = m ≥ n → ⊥ _<_ : N → N → Set a m < n = suc m ≤ n _≮_ : N → N → Set a m ≮ n = m < n → ⊥ _>_ : N → N → Set a m > n = n < m _≯_ : N → N → Set a m ≯ n = m > n → ⊥ -- Order (Bool) _≤ᵇ_ : N → N → Bool m ≤ᵇ n = caseNat true false (m ∸ n) -- induction ind2 : ∀ {p} (P : N → N → Set p) → P zero zero → (∀ m n → P m n → P m (suc n)) → (∀ m n → P m n → P (suc m) n) → ∀ m n → P m n ind2 P Pzz Pmn→Pms Pmn→Psn m n = ind (λ o → P o n) (ind (λ p → P zero p) Pzz (λ k Pzk → Pmn→Pms zero k Pzk) n) (λ k Pkn → ind (λ r → P (suc k) r) (P[k,0] (suc k)) (λ k₁ P[1+k,k₁] → Pmn→Pms (suc k) k₁ P[1+k,k₁]) n) m where P[k,0] : ∀ k → P k zero P[k,0] = λ k → ind (λ x → P x zero) Pzz (λ k₂ → Pmn→Psn k₂ zero) k -- Constant one : N one = suc zero
{ "alphanum_fraction": 0.5060745706, "avg_line_length": 20.7565217391, "ext": "agda", "hexsha": "96d0583ca9de0ebda83ae97aae5c9054d258ef02", "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/Nat/Operations.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/Nat/Operations.agda", "max_line_length": 78, "max_stars_count": 3, "max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "rei1024/agda-misc", "max_stars_repo_path": "TypeTheory/Nat/Operations.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": 1072, "size": 2387 }
{-# OPTIONS --without-K --rewriting #-} open import PathInduction open import Pushout module JamesSecondComposite {i} (A : Type i) (⋆A : A) where open import JamesTwoMaps A ⋆A public -- Second composite to-ε∞ : to ε∞ == εJ to-ε∞ = idp to-α∞-in∞ : (a : A) (n : ℕ) (x : J n) → to (α∞ a (in∞ n x)) == αJ a (inJ n x) to-α∞-in∞ a n x = inJS-α n a x to-α∞-push∞ : (a : A) (n : ℕ) (x : J n) → Square (ap to (ap (α∞ a) (push∞ n x))) (inJS-α n a x) idp (ap (αJ a) (ap to (push∞ n x))) to-α∞-push∞ = λ a n x → & coh (ap-shape-∙! to (push∞-β {in∞* = α∞-in∞ a} {push∞* = α∞-push∞ a} n x)) (to-push∞-S n (α n a x)) (ap-δJ (inJS-α n a x)) (∘-ap _ _ _) (inJSS-γ n a x) (ap-square (αJ a) (to-push∞ n x)) module Toα∞Push∞ where coh : Coh ({A : Type i} {a c : A} {q : a == c} {d : A} {r : a == d} {b : A} {s : b == d} {p : a == b} (p= : p == r ∙ ! s) {r' : a == d} (y= : r == r') {g : A} {w : d == g} {v : c == g} (sq : Square r' q w v) {e : A} {u : c == e} {s' : b == d} (s= : s == s') {t : b == e} (u= : Square s' t w (! u ∙ v)) {x : c == b} (x= : Square x idp t u) → Square p q idp x) coh = path-induction to-α∞ : (a : A) (x : J∞A) → to (α∞ a x) == αJ a (to x) to-α∞ a = J∞A-elim (to-α∞-in∞ a) (λ n x → ↓-='-from-square (ap-∘ to (α∞ a) (push∞ n x)) (ap-∘ (αJ a) to (push∞ n x)) (square-symmetry (to-α∞-push∞ a n x))) to-δ∞-in∞ : (n : ℕ) (x : J n) → Square (ap to (δ∞ (in∞ n x))) idp (to-α∞ ⋆A (in∞ n x)) (δJ (to (in∞ n x))) to-δ∞-in∞ = λ n x → & coh (∘-ap _ _ _) (ap-square to (δ∞-in∞-β n x)) (to-push∞ n x) (inJS-β n x) module Toδ∞In where coh : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {r r' : b == c} (r= : r == r') {s : a == c} (sq1 : Square p idp r s) {d : A} {t : c == d} {u : a == d} (sq2 : Square s idp t u) {rt : b == d} (rt= : Square r' rt t idp) → Square p idp rt u) coh = path-induction module _ (n : ℕ) (x : J n) where side1 : Square (ap to (push∞ (S n) (α n ⋆A x))) (inJS-α n ⋆A x) (ap (αJ ⋆A) (inJS-α n ⋆A x)) (δJ (αJ ⋆A (inJ n x))) side1 = to-push∞-S n (α n ⋆A x) |∙ idp |∙ ap-δJ (inJS-α n ⋆A x) side2 : Square (ap to (ap (in∞ (S n)) (β n x))) (inJS-α n ⋆A x) (inJS-ι n x) idp side2 = idp |∙ ∘-ap to (in∞ (S n)) (β n x) |∙ inJS-β n x side3 : Square (ap to (ap (in∞ (S (S n))) (ap inr (β n x)))) (ap (αJ ⋆A) (inJS-α n ⋆A x)) (ap (αJ ⋆A) (inJS-ι n x)) (ap (αJ ⋆A) idp) side3 = idp |∙ (∘-ap to (in∞ (S (S n))) _ ∙ ap-inJSS-ι n (β n x)) |∙ ap-square (αJ ⋆A) (inJS-β n x) side4 : Square (ap to (push∞ (S n) (ι n x))) (inJS-ι n x) (ap (λ z → αJ ⋆A z) (inJS-ι n x)) (δJ (αJ ⋆A (inJ n x))) side4 = to-push∞-S n (ι n x) |∙ idp |∙ ap-δJ (inJS-ι n x) side5 : Square (ap to (ap (in∞ (S (S n))) (γ n ⋆A x))) (ap (αJ ⋆A) (inJS-ι n x)) (ap (αJ ⋆A) (inJS-α n ⋆A x)) (γJ ⋆A (inJ n x)) side5 = ∘-ap to (in∞ (S (S n))) (γ n ⋆A x) |∙ inJSS-γ n ⋆A x side6 : Square (ap to (ap (in∞ (S (S n))) (β (S n) (ι n x)))) (ap (αJ ⋆A) (inJS-ι n x)) (ap (αJ ⋆A) (inJS-ι n x)) idp side6 = ∘-ap to (in∞ (S (S n))) _ |∙ inJS-βS n (ι n x) |∙ vid-square side7 : Square (ap to (ap (α∞ ⋆A) (push∞ n x))) (inJS-α n ⋆A x) (ap (αJ ⋆A) (inJS-ι n x)) (ap (αJ ⋆A) (δJ (inJ n x))) side7 = adapt-square (to-α∞-push∞ ⋆A n x ∙□ ap-square (αJ ⋆A) (to-push∞ n x)) ∙idp idp∙ to-push∞-βn : Cube (ap-square to (natural-square (push∞ (S n)) (β n x) idp (ap-∘ (in∞ (S (S n))) inr (β n x)))) hid-square side1 side2 side3 side4 to-push∞-βn = & (ap-square-natural-square to) (β n x) (push∞ (S n)) ∙idp idp -∙³ & natural-square-homotopy (to-push∞-S n) (β n x) |∙³ & (natural-square-∘ (β n x) (inJS n)) δJ idp idp -∙³ & natural-square= δJ idp (coh1 to (in∞ (S n)) (β n x)) (coh2 to (in∞ (S (S n))) inr (β n x) (ap-∘ (αJ ⋆A) (inJS n) (β n x))) |∙³ & natural-cube2 δJ (inJS-β n x) (ap-square-idf (inJS-β n x)) (hid-flatcube _) where coh1 : {A B C : Type i} (g : B → C) (f : A → B) {x y : A} (p : x == y) → Square idp (∘-ap (λ z → z) (g ∘ f) p ∙ ap-∘ g f p) (ap-idf _) (∘-ap g f p) coh1 g f idp = ids coh2 : {A B C D : Type i} (h : C → D) (g : B → C) (f : A → B) {x y : A} (p : x == y) {z : h (g (f x)) == h (g (f y))} (q : ap (h ∘ g ∘ f) p == z) → Square idp (! q ∙ ap-∘ h (g ∘ f) p ∙ ap (ap h) (ap-∘ g f p)) idp (∘-ap h g (ap f p) ∙ ∘-ap (h ∘ g) f p ∙ q) coh2 h g f idp idp = ids to-in∞-η : Cube (ap-square to (ap-square (in∞ (S (S n))) (η n x))) (horiz-degen-square (ηJ (inJ n x))) side5 vid-square side3 side6 to-in∞-η = adapt-cube-idp (∘-ap-square to (in∞ (S (S n))) (η n x) |∙³ inJSS-η n x) idp (& coh1) (& coh2) idp where coh1 : Coh ({A : Type i} {a b : A} {p : a == b} → idp |∙ vid-square {p = p} == vid-square) coh1 = path-induction coh2 : Coh ({A : Type i} {a b c d : A} {p : a == b} {q : a == c} {r : b == d} {s : c == d} {sq : Square p q r s} {p' : a == b} {p= : p' == p} {p'' : a == b} {p=' : p'' == p'} → p=' |∙ p= |∙ sq == idp |∙ (p=' ∙ p=) |∙ sq) coh2 = path-induction coh-last-one : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {q : a == c} → p == q ∙ ! (! p ∙ q)) coh-last-one = path-induction last-one : Cube (horiz-degen-square (ap-shape-∙! to (push∞-β {in∞* = α∞-in∞ ⋆A} {push∞* = α∞-push∞ ⋆A} n x))) (horiz-degen-square (& coh-last-one)) side7 vid-square vid-square (vcomp! side1 side5) last-one = & coh where coh : Coh ({A : Type i} {a : A} {c : A} {q : a == c} {d : A} {r : a == d} {b : A} {s : b == d} {p : a == b} {p= : p == r ∙ ! s} {r' : a == d} {y= : r == r'} {g : A} {w : d == g} {v : c == g} {sq : Square r' q w v} {e : A} {u : c == e} {s' : b == d} {s= : s == s'} {t : b == e} {u= : Square s' t w (! u ∙ v)} {x : c == b} {x= : Square x idp t u} → Cube (horiz-degen-square p=) (horiz-degen-square (& coh-last-one)) (adapt-square (& Toα∞Push∞.coh p= y= sq s= u= x= ∙□ x=) ∙idp idp∙) vid-square vid-square (vcomp! (y= |∙ idp |∙ sq) (s= |∙ u=))) coh = path-induction δ∞Push∞Coh-coh : Coh ({A : Type i} {a b : A} {p : a == b} {d : A} {s : d == b} {c : A} {r : b == c} {f : A} {u : f == c} {e : A} {t : e == c} {w : f == e} {eta : Square w idp t u} {v : d == e} {nat : Square v s t r} {vw : d == f} {vw-eq : vw == v ∙ ! w} {a' : _} {a= : a == a'} {b' : _} {b= : b == b'} {p' : _} {p= : Square p a= b= p'} {d' : _} {d= : d == d'} {s' : _} {s= : Square s d= b= s'} {c' : _} {c= : c == c'} {r' : _} {r= : Square r b= c= r'} {f' : _} {f= : f == f'} {u' : _} {u= : Square u f= c= u'} {e' : _} {e= : e == e'} {t' : _} {t= : Square t e= c= t'} {w' : _} {w= : Square w f= e= w'} {eta' : _} (eta= : Cube eta eta' w= vid-square t= u=) {v' : _} {v= : Square v d= e= v'} {nat' : _} (nat= : Cube nat nat' v= s= t= r=) {vw' : _} {vw= : Square vw d= f= vw'} {vw-eq' : _} (vw-eq= : Cube (horiz-degen-square vw-eq) (horiz-degen-square vw-eq') vw= vid-square vid-square (vcomp! v= w=)) → Cube (& δ∞Push∞.coh p eta nat vw-eq) (& δ∞Push∞.coh p' eta' nat' vw-eq') (vcomp! p= s=) p= vw= (vcomp! r= u=)) δ∞Push∞Coh-coh = path-induction piece1 : FlatCube (ap-square to (& δ∞Push∞.coh (push∞ n x) (ap-square (in∞ (S (S n))) (η n x)) (natural-square (push∞ (S n)) (β n x) idp (ap-∘ _ _ _)) (push∞-β {in∞* = α∞-in∞ ⋆A} {push∞* = α∞-push∞ ⋆A} n x))) (& δ∞Push∞.coh (ap to (push∞ n x)) (ap-square to (ap-square (in∞ (S (S n))) (η n x))) (ap-square to (natural-square (push∞ (S n)) (β n x) idp (ap-∘ (in∞ (S (S n))) (ι (S n)) (β n x)))) (ap-shape-∙! to (push∞-β {in∞* = α∞-in∞ ⋆A} {push∞* = α∞-push∞ ⋆A} n x))) (ap-∙! _ _ _) idp idp (ap-∙! _ _ _) piece1 = & (δ∞Push∞.ap-coh to) {b = in∞ (S n) (ι n x)} {d = in∞ (S n) (α n ⋆A x)} piece2 : Cube (& δ∞Push∞.coh (ap to (push∞ n x)) (ap-square to (ap-square (in∞ (S (S n))) (η n x))) (ap-square to (natural-square (push∞ (S n)) (β n x) idp (ap-∘ (in∞ (S (S n))) inr (β n x)))) (ap-shape-∙! to (push∞-β {in∞* = α∞-in∞ ⋆A} {push∞* = α∞-push∞ ⋆A} n x))) (& δ∞Push∞.coh (δJ (inJ n x)) (horiz-degen-square (ηJ (inJ n x))) hid-square (& coh-last-one)) (vcomp! (to-push∞ n x) side2) (to-push∞ n x) side7 (vcomp! side4 side6) piece2 = & δ∞Push∞Coh-coh to-in∞-η to-push∞-βn last-one piece3 : FlatCube (& δ∞Push∞.coh (δJ (inJ n x)) (horiz-degen-square (ηJ (inJ n x))) hid-square (& coh-last-one)) (ap-δJ (δJ (inJ n x))) ∙idp idp idp ∙idp piece3 = & coh where coh : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {q q' : b == c} {sq : Square p p q q'} → FlatCube (& δ∞Push∞.coh p (horiz-degen-square (& (ηIfy.coh αJ δJ) sq)) hid-square (& coh-last-one)) sq ∙idp idp idp ∙idp) coh = path-induction piece4 : Cube (ap-δJ (ap to (push∞ n x))) (ap-δJ (δJ (inJ n x))) hid-square (to-push∞ n x) (ap-square (αJ ⋆A) (to-push∞ n x)) (ap-δJ (inJS-ι n x)) piece4 = & natural-cube2 δJ (to-push∞ n x) (ap-square-idf _) (hid-flatcube _) to-δ∞-push∞ : Cube (ap-square to (natural-square δ∞ (push∞ n x) (ap-idf _) idp)) (ap-δJ (ap to (push∞ n x))) (to-δ∞-in∞ n x) hid-square (to-α∞-push∞ ⋆A n x) (to-δ∞-in∞ (S n) (ι n x)) to-δ∞-push∞ = adapt-cube (ap (ap-square to) (natural-square-β δ∞ (push∞ n x) (push∞-βd n x)) -∙³ piece1 |∙³ piece2 ∙³x piece3 |∙³ !³ piece4) idp ∙idp !-inv-r !-inv-r (& coh1 (& (coh-flat to) {b = in∞ (S n) (α n ⋆A x)})) (& coh2) (& coh3) (& coh4 (& (coh-flat to) {a = in∞ (S n) (ι n x)})) where flat : Coh ({A : Type i} {a c : A} {s : a == c} {b : A} {r : b == c} {p : a == b} (sq : Square p idp r s) → p == s ∙ ! r) flat = path-induction coh-flat : {A B : Type i} (f : A → B) → Coh ({a c : A} {s : a == c} {b : A} {r : b == c} → & flat (ap-square f (& δ∞Inβ.coh)) == ap-∙! f s r) coh-flat f = path-induction coh1 : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {r r' : b == c} {r= : r == r'} {s : a == c} {sq1 : Square p idp r s} {d : A} {t : c == d} {u : a == d} {sq2 : Square s idp t u} {rt : b == d} {sq3 : Square r' rt t idp} {p= : p == s ∙ ! r} (p== : & flat sq1 == p=) → adapt-square (p= |∙ vcomp! sq2 (idp |∙ r= |∙ sq3) ∙□ ∙idp |∙ !² hid-square) idp ∙idp == & Toδ∞In.coh r= sq1 sq2 sq3) coh1 = path-induction coh2 : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {r : b == c} {s : a == c} {sq : Square p idp r s} → adapt-square (idp |∙ sq ∙□ idp |∙ !² sq) idp !-inv-r == hid-square) coh2 = path-induction coh3 : Coh ({A : Type i} {a b : A} {p : a == b} {c : A} {q : a == c} {s : c == b} {sq1 : Square p q idp s} {d : A} {t : b == d} {u : c == d} {sq2 : Square s idp t u} → adapt-square (idp |∙ adapt-square (sq1 ∙□ sq2) ∙idp idp∙ ∙□ idp |∙ !² sq2) ∙idp !-inv-r == sq1) coh3 = path-induction coh4 : Coh ({A : Type i} {a b c d : A} {p : a == b} {q : a == c} {r : b == d} {s : c == d} {sq : Square p q r s} {p' : a == b} {p=□ : Square p' idp idp p} {t : b == b} {t=□ : t == idp} {t' : b == b} {t=' : t' == t} {pt' : a == b} {pt=2 : Square pt' idp t' p'} {pt= : pt' == p' ∙ ! t'} (pt== : & flat pt=2 == pt=) → adapt-square (pt= |∙ vcomp! (horiz-degen-path p=□ |∙ idp |∙ sq) (t=' |∙ t=□ |∙ vid-square) ∙□ ∙idp |∙ !² sq) !-inv-r !-inv-r == & Toδ∞In.coh t=' pt=2 p=□ (horiz-degen-square t=□)) coh4 = path-induction natural-square-idp-symm : {A B : Type i} {f : A → B} {x y : A} {p : x == y} → natural-square (λ a → idp {a = f a}) p idp idp == square-symmetry hid-square natural-square-idp-symm {p = idp} = idp to-δ∞ : (x : J∞A) → Square (ap to (δ∞ x)) idp (to-α∞ ⋆A x) (δJ (to x)) to-δ∞ = J∞A-elim to-δ∞-in∞ (λ n x → cube-to-↓-path idp (ap-∘ _ _ _) idp (ap-∘ _ _ _) (adapt-cube-idp (cube-rotate (to-δ∞-push∞ n x)) (& (ap-square-natural-square to) (push∞ n x) δ∞ coh ∙idp) (! natural-square-idp-symm) (! (natural-square-β (to-α∞ ⋆A) (push∞ n x) (push∞-βd n x))) (! (& (natural-square-∘ (push∞ n x) to) δJ coh2 (!-inv-l))))) where coh : {A B : Type i} {f : A → B} {x y : A} {p : x == y} → ap-∘ f (λ z → z) p ∙ ap (ap f) (ap-idf p) == idp coh {p = idp} = idp coh2 : {A B : Type i} {f : A → B} {x y : A} {p : x == y} → ∘-ap (λ z → z) f p ∙ idp == ap-idf (ap f p) coh2 {p = idp} = idp to-from : (x : JA) → to (from x) == x to-from = JA-elim to-ε∞ (λ a x y → to-α∞ a (from x) ∙ ap (αJ a) y) (λ x y → ↓-='-from-square (ap-∘ to from (δJ x) ∙ ap (ap to) (δJ-β x)) (ap-idf (δJ x)) (square-symmetry (adapt-square (to-δ∞ (from x) ∙□ ap-δJ y) idp∙ idp)))
{ "alphanum_fraction": 0.4032945186, "avg_line_length": 54.3783783784, "ext": "agda", "hexsha": "0bb1ccb7e6126acc97946fb3fb28fd9f0b2e715a", "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": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "guillaumebrunerie/JamesConstruction", "max_forks_repo_path": "JamesSecondComposite.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b", "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": "guillaumebrunerie/JamesConstruction", "max_issues_repo_path": "JamesSecondComposite.agda", "max_line_length": 211, "max_stars_count": 5, "max_stars_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "guillaumebrunerie/JamesConstruction", "max_stars_repo_path": "JamesSecondComposite.agda", "max_stars_repo_stars_event_max_datetime": "2018-11-16T22:10:16.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-07T04:34:52.000Z", "num_tokens": 6289, "size": 14084 }
module Relation.Ternary.Separation.Bigstar where open import Level open import Data.Bool open import Data.Product open import Relation.Unary open import Relation.Ternary.Separation open import Relation.Ternary.Separation.Monad open import Relation.Ternary.Separation.Monad.Error open import Relation.Ternary.Separation.Morphisms open Monads module _ {a p} {A : Set a} (P : Pred A p) {{ r : RawSep A }} {u} {{ _ : IsUnitalSep r u }} where data Bigstar : SPred (a ⊔ p) where emp : ε[ Bigstar ] cons : ∀[ P ✴ Bigstar ⇒ Bigstar ] module _ {a} {A : Set a} {P : Pred A a} {{ r : RawSep A }} {u} {{ _ : IsUnitalSep r u }} where [_] : ∀[ P ⇒ Bigstar P ] [ px ] = cons (px ×⟨ ⊎-idʳ ⟩ emp) head : ∀[ Bigstar P ⇒ Error (P ✴ Bigstar P) ] head emp = error err head pool@(cons (px ×⟨ σ ⟩ pxs)) = do th₂ ×⟨ σ ⟩ pool' ×⟨ σ₂ ⟩ th₁ ← mapM (head pxs &⟨ ⊎-comm σ ⟩ px) ✴-assocᵣ return (th₂ ×⟨ σ ⟩ cons (th₁ ×⟨ ⊎-comm σ₂ ⟩ pool')) find : (∀ {Φ} → P Φ → Bool) → ∀[ Bigstar P ⇒ Error (P ✴ Bigstar P) ] find f emp = error err find f (cons (px ×⟨ σ ⟩ pxs)) = if f px then return (px ×⟨ σ ⟩ pxs) else do px' ×⟨ σ₁ ⟩ pxs' ×⟨ σ₂ ⟩ px ← mapM (find f pxs &⟨ P ∥ ⊎-comm σ ⟩ px) ✴-assocᵣ return (px' ×⟨ σ₁ ⟩ cons (px ×⟨ ⊎-comm σ₂ ⟩ pxs')) append : ∀[ P ⇒ Bigstar P ─✴ Bigstar P ] app (append px) emp σ rewrite ⊎-id⁻ʳ σ = [ px ] app (append px) (cons (qx ×⟨ σ₁ ⟩ pxs)) σ = let _ , σ₂ , σ₃ = ⊎-unassoc σ (⊎-comm σ₁) qxs = app (append px) pxs σ₂ in cons (qx ×⟨ ⊎-comm σ₃ ⟩ qxs)
{ "alphanum_fraction": 0.5668173015, "avg_line_length": 31.612244898, "ext": "agda", "hexsha": "99f3fdede454e3ea764886954009e0bb36a9b200", "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/Relation/Ternary/Separation/Bigstar.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/Relation/Ternary/Separation/Bigstar.agda", "max_line_length": 85, "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/Relation/Ternary/Separation/Bigstar.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": 643, "size": 1549 }
------------------------------------------------------------------------ -- A partial order ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} open import Prelude module Delay-monad.Partial-order {a} {A : Type a} where open import Equality.Propositional as E open import Logical-equivalence using (_⇔_) open import Prelude.Size open import Bijection equality-with-J using (_↔_) open import Double-negation equality-with-J open import Excluded-middle equality-with-J open import Function-universe equality-with-J hiding (id; _∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import Monad equality-with-J open import Delay-monad open import Delay-monad.Bisimilarity as B hiding (reflexive; symmetric; laterˡ⁻¹; laterʳ⁻¹) open import Delay-monad.Bisimilarity.Alternative open import Delay-monad.Bisimilarity.Negative import Delay-monad.Termination as T -- An ordering relation. -- -- Capretta defines a pointwise logically equivalent relation in -- "General Recursion via Coinductive Types". -- -- Benton, Kennedy and Varming define a relation that is perhaps -- pointwise logically equivalent in "Some Domain Theory and -- Denotational Semantics in Coq". infix 4 [_]_⊑_ [_]_⊑′_ _⊑_ _⊑′_ mutual data [_]_⊑_ (i : Size) : Delay A ∞ → Delay A ∞ → Type a where now : ∀ {x} → [ i ] now x ⊑ now x laterʳ : ∀ {x y} → [ i ] x ⊑ force y → [ i ] x ⊑ later y laterˡ : ∀ {x y} → [ i ] force x ⊑′ y → [ i ] later x ⊑ y record [_]_⊑′_ (i : Size) (x y : Delay A ∞) : Type a where coinductive field force : {j : Size< i} → [ j ] x ⊑ y open [_]_⊑′_ public _⊑_ : Delay A ∞ → Delay A ∞ → Type a _⊑_ = [ ∞ ]_⊑_ _⊑′_ : Delay A ∞ → Delay A ∞ → Type a _⊑′_ = [ ∞ ]_⊑′_ -- A derived "constructor". later-cong : ∀ {i x y} → [ i ] force x ⊑′ force y → [ i ] later x ⊑ later y later-cong p = laterʳ (laterˡ p) -- Termination predicates. Terminates : Size → Delay A ∞ → A → Type a Terminates i x y = [ i ] now y ⊑ x _⇓_ : Delay A ∞ → A → Type a _⇓_ = Terminates ∞ -- If x terminates with the values y and z, then y is equal to z. ⇓→⇓→≡ : ∀ {i x y z} → Terminates i x y → Terminates i x z → y ≡ z ⇓→⇓→≡ now now = refl ⇓→⇓→≡ (laterʳ p) (laterʳ q) = ⇓→⇓→≡ p q -- If x is smaller than or equal to now y, and x terminates, then -- x terminates with the value y. ⊑now→⇓→⇓ : ∀ {i x} {y z : A} → x ⊑ now y → Terminates i x z → Terminates i x y ⊑now→⇓→⇓ now now = now ⊑now→⇓→⇓ (laterˡ p) (laterʳ q) = laterʳ (⊑now→⇓→⇓ (force p) q) -- The notion of termination defined here is pointwise isomorphic to -- the one defined in Delay-monad.Termination. ⇓↔⇓ : ∀ {i x y} → Terminates i x y ↔ T.Terminates i x y ⇓↔⇓ = record { surjection = record { logical-equivalence = record { to = to ; from = from } ; right-inverse-of = to∘from } ; left-inverse-of = from∘to } where to : ∀ {i x y} → Terminates i x y → T.Terminates i x y to now = now to (laterʳ p) = laterʳ (to p) from : ∀ {i x y} → T.Terminates i x y → Terminates i x y from now = now from (laterʳ p) = laterʳ (from p) from∘to : ∀ {i x y} (p : Terminates i x y) → from (to p) ≡ p from∘to now = refl from∘to (laterʳ p) = cong laterʳ (from∘to p) to∘from : ∀ {i x y} (p : T.Terminates i x y) → to (from p) ≡ p to∘from now = refl to∘from (laterʳ p) = cong laterʳ (to∘from p) -- Terminates i is pointwise isomorphic to Terminates ∞. Terminates↔⇓ : ∀ {i x y} → Terminates i x y ↔ x ⇓ y Terminates↔⇓ {i} {x} {y} = Terminates i x y ↝⟨ ⇓↔⇓ ⟩ T.Terminates i x y ↝⟨ T.Terminates↔⇓ ⟩ x T.⇓ y ↝⟨ inverse ⇓↔⇓ ⟩□ x ⇓ y □ -- The computation never is smaller than or equal to all other -- computations. never⊑ : ∀ {i} x → [ i ] never ⊑ x never⊑ (now x) = laterˡ λ { .force → never⊑ (now x) } never⊑ (later x) = later-cong λ { .force → never⊑ (force x) } -- The computation never does not terminate. now⋢never : ∀ {i x} → ¬ Terminates i never x now⋢never (laterʳ p) = now⋢never p -- One can remove later constructors. laterˡ⁻¹ : ∀ {i} {j : Size< i} {x y} → [ i ] later x ⊑ y → [ j ] force x ⊑ y laterˡ⁻¹ (laterʳ p) = laterʳ (laterˡ⁻¹ p) laterˡ⁻¹ (laterˡ p) = force p laterʳ⁻¹ : ∀ {i x y} → [ i ] x ⊑ later y → [ i ] x ⊑ force y laterʳ⁻¹ (laterʳ p) = p laterʳ⁻¹ (laterˡ p) = laterˡ λ { .force → laterʳ⁻¹ (force p) } later-cong⁻¹ : ∀ {i} {j : Size< i} {x y} → [ i ] later x ⊑ later y → [ j ] force x ⊑ force y later-cong⁻¹ p = laterʳ⁻¹ (laterˡ⁻¹ p) -- Weak bisimilarity is contained in the ordering relation. ≈→⊑ : ∀ {i x y} → [ i ] x ≈ y → [ i ] x ⊑ y ≈→⊑ now = now ≈→⊑ (later p) = later-cong λ { .force → ≈→⊑ (force p) } ≈→⊑ (laterˡ p) = laterˡ λ { .force → ≈→⊑ p } ≈→⊑ (laterʳ p) = laterʳ (≈→⊑ p) -- The ordering relation is antisymmetric (with respect to weak -- bisimilarity). antisymmetric : ∀ {i x y} → [ i ] x ⊑ y → [ i ] y ⊑ x → [ i ] x ≈ y antisymmetric {x = now x} {y = now .x} now _ = now antisymmetric {x = now x} {y = later y} (laterʳ p) q = laterʳ (_↔_.to ⇓↔⇓ p) antisymmetric {x = later x} {y = now y} p (laterʳ q) = laterˡ (B.symmetric (_↔_.to ⇓↔⇓ q)) antisymmetric {x = later x} {y = later y} p q = later λ { .force → antisymmetric (later-cong⁻¹ p) (later-cong⁻¹ q) } -- An alternative characterisation of weak bisimilarity. ≈⇔⊑×⊒ : ∀ {i x y} → [ i ] x ≈ y ⇔ ([ i ] x ⊑ y × [ i ] y ⊑ x) ≈⇔⊑×⊒ = record { to = λ p → ≈→⊑ p , ≈→⊑ (B.symmetric p) ; from = uncurry antisymmetric } -- The ordering relation is reflexive. reflexive : ∀ {i} x → [ i ] x ⊑ x reflexive (now x) = now reflexive (later x) = later-cong λ { .force → reflexive (force x) } -- Certain instances of symmetry also hold. symmetric : ∀ {i} {x : A} {y} → Terminates i y x → [ i ] y ⊑ now x symmetric now = now symmetric (laterʳ p) = laterˡ λ { .force → symmetric p } -- The ordering relation is transitive. transitive : ∀ {i} {x y z : Delay A ∞} → [ i ] x ⊑ y → y ⊑ z → [ i ] x ⊑ z transitive p now = p transitive p (laterʳ q) = laterʳ (transitive p q) transitive (laterʳ p) (laterˡ q) = transitive p (force q) transitive (laterˡ p) q = laterˡ λ { .force → transitive (force p) q } -- The termination relation respects weak bisimilarity. ⇓-respects-≈ : ∀ {i x y z} → Terminates i x z → x ≈ y → Terminates i y z ⇓-respects-≈ now q = ≈→⊑ q ⇓-respects-≈ (laterʳ p) q = ⇓-respects-≈ p (B.laterˡ⁻¹ q) -- The ordering relation respects weak bisimilarity. transitive-≈⊑ : ∀ {i x y z} → [ i ] x ≈ y → y ⊑ z → [ i ] x ⊑ z transitive-≈⊑ p q = transitive (≈→⊑ p) q transitive-⊑≈ : ∀ {i x y z} → [ i ] x ⊑ y → y ≈ z → [ i ] x ⊑ z transitive-⊑≈ p now = p transitive-⊑≈ (laterʳ p) (later q) = laterʳ (transitive-⊑≈ p (force q)) transitive-⊑≈ (laterˡ p) q = laterˡ λ { .force → transitive-⊑≈ (force p) q } transitive-⊑≈ (laterʳ p) (laterˡ q) = transitive-⊑≈ p q transitive-⊑≈ p (laterʳ q) = laterʳ (transitive-⊑≈ p q) -- There is a transitivity-like function that produces an ordering -- proof from one weak bisimilarity proof and one ordering proof, in -- such a way that the size of the ordering proof is preserved, iff A -- is uninhabited. Transitivity-≈⊑ʳ = ∀ {i} {x y z : Delay A ∞} → x ≈ y → [ i ] y ⊑ z → [ i ] x ⊑ z size-preserving-transitivity-≈⊑ʳ⇔uninhabited : Transitivity-≈⊑ʳ ⇔ ¬ A size-preserving-transitivity-≈⊑ʳ⇔uninhabited = record { to = Transitivity-≈⊑ʳ ↝⟨ (λ trans {i x} → [ i ] later (record { force = now x }) ∼ never ↝⟨ ≈→⊑ ∘ ∼→ ⟩ [ i ] later (record { force = now x }) ⊑ never ↝⟨ trans (laterʳ now) ⟩ [ i ] now x ⊑ never ↝⟨ _↔_.to ⇓↔⇓ ⟩□ [ i ] now x ≈ never □) ⟩ Laterˡ⁻¹-∼≈′ ↝⟨ _⇔_.to size-preserving-laterˡ⁻¹-∼≈′⇔uninhabited ⟩ ¬ A □ ; from = ¬ A ↝⟨ uninhabited→trivial ⟩ (∀ x y → x ≈ y) ↝⟨ (λ trivial _ _ → ≈→⊑ (trivial _ _)) ⟩ (∀ x y → x ⊑ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□ Transitivity-≈⊑ʳ □ } -- Transitivity can be made size-preserving in the second argument iff -- A is uninhabited. Transitivityʳ = ∀ {i} {x y z : Delay A ∞} → x ⊑ y → [ i ] y ⊑ z → [ i ] x ⊑ z size-preserving-transitivityʳ⇔uninhabited : Transitivityʳ ⇔ ¬ A size-preserving-transitivityʳ⇔uninhabited = record { to = Transitivityʳ ↝⟨ _∘ ≈→⊑ ⟩ Transitivity-≈⊑ʳ ↝⟨ _⇔_.to size-preserving-transitivity-≈⊑ʳ⇔uninhabited ⟩□ ¬ A □ ; from = ¬ A ↝⟨ uninhabited→trivial ⟩ (∀ x y → x ≈ y) ↝⟨ (λ trivial _ _ → ≈→⊑ (trivial _ _)) ⟩ (∀ x y → x ⊑ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□ Transitivityʳ □ } -- There is a transitivity-like function that produces an ordering -- proof from one ordering proof and one weak bisimilarity proof, in -- such a way that the size of the weak bisimilarity proof is -- preserved, iff A is uninhabited. Transitivity-⊑≈ʳ = ∀ {i} {x y z : Delay A ∞} → x ⊑ y → [ i ] y ≈ z → [ i ] x ⊑ z size-preserving-transitivity-⊑≈ʳ⇔uninhabited : Transitivity-⊑≈ʳ ⇔ ¬ A size-preserving-transitivity-⊑≈ʳ⇔uninhabited = record { to = Transitivity-⊑≈ʳ ↝⟨ (λ trans {i x} → [ i ] later (record { force = now x }) ∼ never ↝⟨ ∼→ ⟩ [ i ] later (record { force = now x }) ≈ never ↝⟨ trans (laterʳ now) ⟩ [ i ] now x ⊑ never ↝⟨ _↔_.to ⇓↔⇓ ⟩□ [ i ] now x ≈ never □) ⟩ Laterˡ⁻¹-∼≈′ ↝⟨ _⇔_.to size-preserving-laterˡ⁻¹-∼≈′⇔uninhabited ⟩ ¬ A □ ; from = ¬ A ↝⟨ uninhabited→trivial ⟩ (∀ x y → x ≈ y) ↝⟨ (λ trivial _ _ → ≈→⊑ (trivial _ _)) ⟩ (∀ x y → x ⊑ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□ Transitivity-⊑≈ʳ □ } -- An alternative characterisation of the ordering relation. -- -- Capretta proves a similar result in "General Recursion via -- Coinductive Types". -- -- One might wonder if the equivalence can be made size-preserving in -- some way. However, note that x ⇓ y is in bijective correspondence -- with Terminates i x y for any size i (see Terminates↔⇓). ⊑⇔⇓→⇓ : ∀ {x y} → x ⊑ y ⇔ (∀ z → x ⇓ z → y ⇓ z) ⊑⇔⇓→⇓ = record { to = to ; from = from _ } where to : ∀ {x y} → x ⊑ y → ∀ z → x ⇓ z → y ⇓ z to p z now = p to (laterʳ p) z q = laterʳ (to p z q) to (laterˡ p) z (laterʳ q) = to (force p) z q from : ∀ {i} x {y} → (∀ z → x ⇓ z → y ⇓ z) → [ i ] x ⊑ y from (now x) p = p x now from (later x) p = laterˡ λ { .force → from (force x) (λ z q → p z (laterʳ q)) } -- An alternative characterisation of weak bisimilarity. -- -- Capretta proves a similar result in "General Recursion via -- Coinductive Types". ≈⇔≈₂ : {x y : Delay A ∞} → x ≈ y ⇔ x ≈₂ y ≈⇔≈₂ {x} {y} = x ≈ y ↝⟨ ≈⇔⊑×⊒ ⟩ x ⊑ y × y ⊑ x ↝⟨ ⊑⇔⇓→⇓ ×-cong ⊑⇔⇓→⇓ ⟩ (∀ z → x ⇓ z → y ⇓ z) × (∀ z → y ⇓ z → x ⇓ z) ↝⟨ ∀-cong _ (λ _ → →-cong _ (from-bijection ⇓↔⇓) (from-bijection ⇓↔⇓)) ×-cong ∀-cong _ (λ _ → →-cong _ (from-bijection ⇓↔⇓) (from-bijection ⇓↔⇓)) ⟩ (∀ z → x T.⇓ z → y T.⇓ z) × (∀ z → y T.⇓ z → x T.⇓ z) ↝⟨ record { to = uncurry λ to from z → record { to = to z; from = from z } ; from = λ hyp → _⇔_.to ∘ hyp , _⇔_.from ∘ hyp } ⟩□ (∀ z → x T.⇓ z ⇔ y T.⇓ z) □ -- If A is a set, then every computation is weakly bisimilar to either -- never or now something (assuming excluded middle and -- extensionality). ⇑⊎⇓ : Excluded-middle a → E.Extensionality a a → Is-set A → (x : Delay A ∞) → never ≈ x ⊎ ∃ λ y → x T.⇓ y ⇑⊎⇓ em ext A-set x = ⊎-map (_⇔_.from ≈⇔≈₂) id $ Excluded-middle→Double-negation-elimination em (⊎-closure-propositional (λ { x⇑ (y , x⇓y) → now≉never (now y ≈⟨ x⇓y ⟩ x ≈⟨ B.symmetric (_⇔_.from ≈⇔≈₂ x⇑) ⟩∎ never ∎) }) (≈₂-propositional ext A-set) (T.∃-Terminates-propositional A-set)) (⊎-map (_⇔_.to ≈⇔≈₂) id ⟨$⟩ T.¬¬[⇑⊎⇓] x)
{ "alphanum_fraction": 0.5033634001, "avg_line_length": 36.5418994413, "ext": "agda", "hexsha": "7a629cb9bdc874ecb76f96abf9df02d609084c12", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/delay-monad", "max_forks_repo_path": "src/Delay-monad/Partial-order.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/delay-monad", "max_issues_repo_path": "src/Delay-monad/Partial-order.agda", "max_line_length": 133, "max_stars_count": null, "max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/delay-monad", "max_stars_repo_path": "src/Delay-monad/Partial-order.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5141, "size": 13082 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} open import Cubical.Relation.Binary.Base open import Cubical.Core.Everything module Cubical.Relation.Binary.Structures {a ℓ} {A : Type a} -- The underlying type (_<>_ : Rel A ℓ) -- The relation where open import Cubical.Foundations.Prelude using (refl; sym; isSet) open import Cubical.Foundations.Function using (_∘_; id) open import Cubical.Foundations.Logic hiding (¬_) open import Cubical.Relation.Nullary.Decidable open import Cubical.Relation.Binary.Definitions open import Cubical.Relation.Binary.Properties open import Cubical.HITs.PropositionalTruncation import Cubical.Relation.Binary.Raw.Structures [ _<>_ ] as Raw private variable ℓ₂ : Level ------------------------------------------------------------------------ -- Preorders ------------------------------------------------------------------------ record IsPreorder : Type (ℓ-max a ℓ) where constructor ispreorder field reflexive : Reflexive _<>_ transitive : Transitive _<>_ fromEq : FromEq _<>_ fromEq = reflx→fromeq _<>_ reflexive raw : Raw.IsPreorder raw = record { reflexive = reflexive ; transitive = transitive } ------------------------------------------------------------------------ -- Equivalences ------------------------------------------------------------------------ record IsPartialEquivalence : Type (ℓ-max a ℓ) where constructor ispartialeq field symmetric : Symmetric _<>_ transitive : Transitive _<>_ raw : Raw.IsPartialEquivalence raw = record { symmetric = symmetric ; transitive = transitive } record IsEquivalence : Type (ℓ-max a ℓ) where constructor isequivalence field reflexive : Reflexive _<>_ isPartialEquivalence : IsPartialEquivalence open IsPartialEquivalence isPartialEquivalence public hiding (raw) from-≡ : FromEq _<>_ from-≡ = reflx→fromeq _<>_ reflexive isPreorder : IsPreorder isPreorder = record { reflexive = reflexive ; transitive = transitive } raw : Raw.IsEquivalence raw = record { reflexive = reflexive ; isPartialEquivalence = IsPartialEquivalence.raw isPartialEquivalence } record IsDecEquivalence : Type (ℓ-max a ℓ) where constructor isdeceq infix 4 _≟_ field isEquivalence : IsEquivalence _≟_ : Decidable _<>_ open IsEquivalence isEquivalence public hiding (raw) raw : Raw.IsDecEquivalence raw = record { isEquivalence = IsEquivalence.raw isEquivalence ; _≟_ = _≟_ } ------------------------------------------------------------------------ -- Partial orders ------------------------------------------------------------------------ record IsPartialOrder : Type (ℓ-max a ℓ) where constructor ispartialorder field isPreorder : IsPreorder antisym : Antisymmetric _<>_ open IsPreorder isPreorder public hiding (raw) raw : isSet A → Raw.IsPartialOrder raw isSetA = record { isPreorder = IsPreorder.raw isPreorder ; antisym = λ x y → rec (isSetA _ _) id (antisym x y) } record IsDecPartialOrder : Type (ℓ-max a ℓ) where constructor isdecpartialorder infix 4 _≤?_ field isPartialOrder : IsPartialOrder _≤?_ : Decidable _<>_ open IsPartialOrder isPartialOrder public hiding (raw) private lemma : ∀ {x y} → ¬ ⟨ x <> y ⟩ → ¬ x ≡ y lemma x≰y x≡y = x≰y (fromEq ∣ x≡y ∣) raw : isSet A → Raw.IsDecPartialOrder raw isSetA = record { isPartialOrder = IsPartialOrder.raw isPartialOrder isSetA ; _≤?_ = _≤?_ } record IsStrictPartialOrder : Type (ℓ-max a ℓ) where constructor isstrictpartialorder field irrefl : Irreflexive _<>_ transitive : Transitive _<>_ asym : Asymmetric _<>_ asym {x} {y} = trans∧irr→asym _<>_ transitive irrefl raw : Raw.IsStrictPartialOrder raw = record { irrefl = irrefl ; transitive = transitive } record IsDecStrictPartialOrder : Type (ℓ-max a ℓ) where constructor isdecstrictpartialorder infix 4 _<?_ field isStrictPartialOrder : IsStrictPartialOrder _<?_ : Decidable _<>_ open IsStrictPartialOrder isStrictPartialOrder public hiding (raw) raw : isSet A → Raw.IsDecStrictPartialOrder raw isSetA = record { isStrictPartialOrder = IsStrictPartialOrder.raw isStrictPartialOrder ; _<?_ = _<?_ } ------------------------------------------------------------------------ -- Total orders ------------------------------------------------------------------------ record IsTotalOrder : Type (ℓ-max a ℓ) where constructor istotalorder field isPartialOrder : IsPartialOrder total : Total _<>_ open IsPartialOrder isPartialOrder public hiding (raw) raw : isSet A → Raw.IsTotalOrder raw isSetA = record { isPartialOrder = IsPartialOrder.raw isPartialOrder isSetA ; total = total } record IsDecTotalOrder : Type (ℓ-max a ℓ) where constructor isdectotalorder infix 4 _≤?_ field isTotalOrder : IsTotalOrder _≤?_ : Decidable _<>_ open IsTotalOrder isTotalOrder public hiding (raw) isDecPartialOrder : IsDecPartialOrder isDecPartialOrder = record { isPartialOrder = isPartialOrder ; _≤?_ = _≤?_ } raw : isSet A → Raw.IsDecTotalOrder raw isSetA = record { isTotalOrder = IsTotalOrder.raw isTotalOrder isSetA ; _≤?_ = _≤?_ } -- Note that these orders are decidable. The current implementation -- of `Trichotomous` subsumes irreflexivity and asymmetry. Any reasonable -- definition capturing these three properties implies decidability -- as `Trichotomous` necessarily separates out the equality case. record IsStrictTotalOrder : Type (ℓ-max a ℓ) where constructor isstricttotalorder field transitive : Transitive _<>_ compare : Trichotomous _<>_ infix 4 _<?_ _<?_ : Decidable _<>_ _<?_ = tri→dec< _<>_ compare _≟_ : Discrete A _≟_ = tri→dec≡ _<>_ compare isStrictPartialOrder : IsStrictPartialOrder isStrictPartialOrder = record { irrefl = tri→irr _<>_ compare ; transitive = transitive } isDecStrictPartialOrder : IsDecStrictPartialOrder isDecStrictPartialOrder = record { isStrictPartialOrder = isStrictPartialOrder ; _<?_ = _<?_ } open IsStrictPartialOrder isStrictPartialOrder public hiding (transitive; raw) raw : isSet A → Raw.IsStrictTotalOrder raw isSetA = record { transitive = transitive ; compare = triRaw compare } where import Cubical.Relation.Binary.Raw.Definitions as RawDefinitions triRaw : Trichotomous _<>_ → RawDefinitions.Trichotomous [ _<>_ ] triRaw tri x y with tri x y ... | tri< a b c = RawDefinitions.tri< a b c ... | tri≡ a b c = RawDefinitions.tri≡ a b c ... | tri> a b c = RawDefinitions.tri> a b c
{ "alphanum_fraction": 0.6302090949, "avg_line_length": 25.2361623616, "ext": "agda", "hexsha": "6eff13f11208edd0cbf5393e68f52fefea21f2e7", "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/Relation/Binary/Structures.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/Relation/Binary/Structures.agda", "max_line_length": 80, "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/Relation/Binary/Structures.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1912, "size": 6839 }
{- Formal verification of authenticated append-only skiplists in Agda, version 1.0. Copyright (c) 2020 Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Data.Unit.NonEta open import Data.Empty open import Data.Sum open import Data.Product open import Data.Product.Properties open import Data.Fin hiding (_<_; _≤_) open import Data.Fin.Properties using () renaming (_≟_ to _≟Fin_) open import Data.Nat renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_) open import Data.Nat.Properties open import Data.List renaming (map to List-map) open import Data.List.Properties using (∷-injective; length-map) open import Data.List.Relation.Unary.Any renaming (map to Any-map) open import Data.List.Relation.Unary.All renaming (lookup to All-lookup; map to All-map) open import Data.List.Relation.Unary.All.Properties hiding (All-map) open import Data.List.Relation.Unary.Any.Properties renaming (map⁺ to Any-map⁺) open import Data.List.Relation.Binary.Pointwise using (decidable-≡) open import Data.Bool hiding (_<_; _≤_) open import Data.Maybe renaming (map to Maybe-map) open import Function open import Relation.Binary.PropositionalEquality open import Relation.Binary.Core open import Relation.Nullary open import AAOSL.Lemmas open import AAOSL.Abstract.Hash open import AAOSL.Abstract.DepRel -- This module defines the DepRel type, which represents the class of AAOSLs we -- consider, and proves properties about any DepRel. module AAOSL.Abstract.Advancement -- A Hash function maps a bytestring into a hash. (hash : ByteString → Hash) -- And is collision resistant (hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y) -- Indexes can be encoded in an injective way (encodeI : ℕ → ByteString) (encodeI-inj : (m n : ℕ) → encodeI m ≡ encodeI n → m ≡ n) (dep : DepRel) where -- Brings the DepRel names into scope instantiated -- for the module parameters in question. open DepRel dep hop-prog : ∀{m}(h : HopFrom m) → hop-tgt h ≢ m hop-prog = <⇒≢ ∘ hop-< hop-≤ : ∀{m}(h : HopFrom m) → hop-tgt h ≤ m hop-≤ = <⇒≤ ∘ hop-< depsof : ℕ → List ℕ depsof 0 = [] depsof (suc i) = List-map hop-tgt (nats (lvlof (suc i))) depsof-ne : ∀ m → depsof m ≡ [] → m ≡ 0 depsof-ne 0 hyp = refl depsof-ne (suc m) hyp = let le0 = trans (sym (length-map hop-tgt (nats (lvlof (suc m)))) ) (cong length hyp) le-nz = nats-length (lvlof-s m) in ⊥-elim (1≤0-⊥ (subst (1 ≤_) le0 le-nz)) hopFromZ-⊥ : (h : HopFrom 0) → ⊥ hopFromZ-⊥ h = fin0-⊥ (subst Fin lvlof-z h) where fin0-⊥ : Fin 0 → ⊥ fin0-⊥ () hop-tgt-is-dep : {m : ℕ}(h : HopFrom m) → hop-tgt h ∈ depsof m hop-tgt-is-dep {0} h = ⊥-elim (hopFromZ-⊥ h) hop-tgt-is-dep {suc m} h = Any-map⁺ (Any-map (cong hop-tgt) (nats-correct h)) -- Two simple but useful lemmas made to work over our abstract -- index type. ≤-≢-mon : ∀{i j tgt} → tgt ≢ j → tgt ≤ j → i ≤ tgt → i ≢ j ≤-≢-mon tgt≢j tgt≤j i≤tgt i≡j = tgt≢j (sym (≤-antisym (subst (_≤ _) i≡j i≤tgt) tgt≤j)) ≟ℕ-refl : (s : ℕ) → (s ≟ℕ s) ≡ yes refl ≟ℕ-refl s with s ≟ℕ s ...| no abs = ⊥-elim (abs refl) ...| yes refl = refl ⊥-prop : (a b : ⊥) → a ≡ b ⊥-prop () () ≟ℕ-neg : (m n : ℕ) → (p : m ≢ n) → (m ≟ℕ n) ≡ no p ≟ℕ-neg m n p with m ≟ℕ n ...| yes imp = ⊥-elim (p imp) ...| no r = cong no (fun-ext (λ x → ⊥-prop (r x) (p x))) HopFrom≢0 : ∀{j}(h : HopFrom j) → j ≢ 0 HopFrom≢0 {j} h refl = hopFromZ-⊥ h open WithCryptoHash hash hash-cr -- This function is total, even though we won't always know a hash for every -- index. That's ok, we only use the hashes of the relevant indexes. View : Set View = ℕ → Hash -- An inhabitant of 'Agree s t ixs' is a proof that the views s and t -- agree on the hash of every index i ∈ ixs. Agree : View → View → List ℕ → Set Agree v u = All (λ s → v s ≡ u s) -- Returns the list of hashes that the authenticator -- at the given index depends on. deps-hash : ℕ → View → List Hash deps-hash s tbl = List-map tbl (depsof s) -- TODO-2: Make auth, auth-inj-1 and auth-inj-2 module parameters -- TODO-1: Make sure the names are consistent with the paper -------------------------- -- Defining authenticators -- Authenticators will depend on all p-auths of the -- dependencies of a node. auth : (s : ℕ) → Hash → View → Hash auth s h tbl = hash-concat (hash (encodeI s) ∷ h ∷ deps-hash s tbl) -- We will be using two separate injectivity functions. One is -- for the hash of the data in a node, which can't be the -- initial node! auth-inj-1 : {j : ℕ}{h₁ h₂ : Hash}{t₁ t₂ : View} → j ≢ 0 → auth j h₁ t₁ ≡ auth j h₂ t₂ → HashBroke ⊎ h₁ ≡ h₂ auth-inj-1 {j} {h₁} {h₂} {t₁} {t₂} j≢s₀ hip with hash-concat-inj { hash (encodeI j) ∷ h₁ ∷ deps-hash j t₁ } { hash (encodeI j) ∷ h₂ ∷ deps-hash j t₂ } hip ...| inj₁ hb = inj₁ hb ...| inj₂ r = inj₂ (proj₁ (∷-injective (proj₂ (∷-injective r)))) -- The second one does induction on the list of dependencies. auth-inj-2 : {i : ℕ}{h : Hash}(t₁ t₂ : View) → auth i h t₁ ≡ auth i h t₂ → HashBroke ⊎ Agree t₁ t₂ (depsof i) auth-inj-2 {i} {h} t₁ t₂ hip with hash-concat-inj { hash (encodeI i) ∷ h ∷ deps-hash i t₁ } { hash (encodeI i) ∷ h ∷ deps-hash i t₂ } hip ...| inj₁ hb = inj₁ hb ...| inj₂ r = inj₂ (auth-inj-2-aux t₁ t₂ (depsof i) (proj₂ (∷-injective (proj₂ (∷-injective r))))) where auth-inj-2-aux : (t₁ t₂ : View)(l : List ℕ) → List-map t₁ l ≡ List-map t₂ l → Agree t₁ t₂ l auth-inj-2-aux t1 t2 [] hyp = [] auth-inj-2-aux t1 t2 (x ∷ l) hyp = proj₁ (∷-injective hyp) ∷ auth-inj-2-aux t1 t2 l (proj₂ (∷-injective hyp)) ------------------------ ------------------------ -- Advancement Proofs -- ------------------------ ------------------------ -- Finally, advancement proofs in their simple variant data AdvPath : ℕ → ℕ → Set where AdvDone : ∀{i} → AdvPath i i AdvThere : ∀{j i} → Hash -- datum digest → (h : HopFrom j) → AdvPath (hop-tgt h) i → AdvPath j i -- Override a view with a hash for a specific index. _∪₁_ : View → ℕ × Hash → View _∪₁_ tbl (s , h) s' with s ≟ℕ s' ...| yes _ = h ...| no _ = tbl s' -- The rebuild function is, essentially, a transformer over -- the current view of the skiplog. It is PARAMOUNT to return -- a new 'view' of the world, as we can see in rebuild-⊕ lemma. -- Otherwise, it becomes seriously intricate to express -- that rebuilding the hash of index j "depends on" the rebuilt -- hashes of j's dependencies. rebuild : ∀{i j} → AdvPath j i → View → View rebuild {i} AdvDone tbl = tbl rebuild (AdvThere {j = j} x h prf) tbl = let tbl' = rebuild prf tbl in tbl' ∪₁ (j , auth j x tbl') lemma1 : ∀{j i} → AdvPath j i → i ≤ j lemma1 AdvDone = ≤-refl lemma1 {j} (AdvThere x h a) = ≤-trans (lemma1 a) (hop-≤ h) rebuild-tgt-lemma : ∀{j i}(a : AdvPath j i){t : View} → rebuild a t i ≡ t i rebuild-tgt-lemma AdvDone = refl rebuild-tgt-lemma {j} {i} (AdvThere x h a) rewrite ≟ℕ-neg j i (<⇒≢ (≤-<-trans (lemma1 a) (hop-< h)) ∘ sym) = rebuild-tgt-lemma a lemma2 : ∀{i}(a : AdvPath i i) → a ≡ AdvDone lemma2 AdvDone = refl lemma2 (AdvThere x h a) = ⊥-elim (hop-prog h (sym (≤-antisym (lemma1 a) (hop-≤ h)))) -- Lemma3 states that if a hop exists, then it is not from -- s₀. This is necessary to eliminate some nasty cases. lemma3 : ∀{j i} → (h : HopFrom j) → AdvPath (hop-tgt h) i → j ≢ 0 lemma3 h a = HopFrom≢0 h ---------------------- -- Proof Splitting -- ---------------------- _⊕_ : ∀{j k i} → AdvPath j k → AdvPath k i → AdvPath j i AdvDone ⊕ rest = rest (AdvThere d h a) ⊕ rest = AdvThere d h (a ⊕ rest) ⊕-id-r : ∀{j i}(a : AdvPath j i) → a ⊕ AdvDone ≡ a ⊕-id-r AdvDone = refl ⊕-id-r (AdvThere x h a) = cong (AdvThere x h) (⊕-id-r a) -- A value of type 'i ∈AP a' illustrates index i as a dependency -- of 'a'. data _∈AP_ (i₀ : ℕ) : {j i : ℕ} → AdvPath j i → Set where hereTgtDone : i₀ ∈AP (AdvDone {i₀}) hereTgtThere : ∀{i}{d : Hash}{hop : HopFrom i₀}{a : AdvPath (hop-tgt hop) i} → i₀ ∈AP (AdvThere d hop a) step : ∀{i j}{d : Hash}{hop : HopFrom j}{a : AdvPath (hop-tgt hop) i} → i₀ ≢ j → i₀ ∈AP a → i₀ ∈AP (AdvThere d hop a) ∈AP-src : ∀{j i}{a : AdvPath j i} → j ∈AP a ∈AP-src {a = AdvDone} = hereTgtDone ∈AP-src {a = AdvThere x h a} = hereTgtThere ∈AP-tgt : ∀{j i}{a : AdvPath j i} → i ∈AP a ∈AP-tgt {a = AdvDone} = hereTgtDone ∈AP-tgt {a = AdvThere x h a} = step (<⇒≢ (≤-<-trans (lemma1 a) (hop-< h))) ∈AP-tgt ∈AP-≤ : ∀{j i}{a : AdvPath j i} → {i0 : ℕ} → i0 ∈AP a → i0 ≤ j ∈AP-≤ hereTgtDone = ≤-refl ∈AP-≤ hereTgtThere = ≤-refl ∈AP-≤ (step _ hyp) = ≤-trans (∈AP-≤ hyp) (hop-≤ _) ∈AP-≥ : ∀{j i}{a : AdvPath j i} → {i0 : ℕ} → i0 ∈AP a → i ≤ i0 ∈AP-≥ hereTgtDone = ≤-refl ∈AP-≥ {a = a} hereTgtThere = lemma1 a ∈AP-≥ (step _ hyp) = ∈AP-≥ hyp rebuild-⊕' : ∀{j k i} → {t : View} → (a₁ : AdvPath j k) → (a₂ : AdvPath k i) → ∀{l} → l ∈AP a₂ → rebuild (a₁ ⊕ a₂) t l ≡ rebuild a₂ t l rebuild-⊕' AdvDone a₂ hyp = refl rebuild-⊕' {j} (AdvThere x h a₁) a₂ {l} hyp with j ≟ℕ l ...| yes nope = ⊥-elim (≤-≢-mon (hop-prog h) (hop-≤ h) (≤-trans (∈AP-≤ hyp) (lemma1 a₁)) (sym nope)) ...| no ok = rebuild-⊕' a₁ a₂ hyp ∈AP-cut : ∀{j k i} → (a : AdvPath j i) → k ∈AP a → Σ (AdvPath j k × AdvPath k i) (λ { (x , y) → a ≡ x ⊕ y }) ∈AP-cut AdvDone hereTgtDone = (AdvDone , AdvDone) , refl ∈AP-cut (AdvThere d h a) hereTgtThere = (AdvDone , AdvThere d h a) , refl ∈AP-cut (AdvThere d h a) (step x prf) with ∈AP-cut a prf ...| xy , ind = (AdvThere d h (proj₁ xy) , proj₂ xy) , cong (AdvThere d h) ind ∈AP-cut₁ : ∀{j k i} → (a : AdvPath j i) → k ∈AP a → AdvPath k i ∈AP-cut₁ a prf = proj₂ (proj₁ (∈AP-cut a prf)) ∈AP-∈-cut : ∀{j k i} → (a : AdvPath j i) → (prf : k ∈AP a) → ∀{m} → m ∈AP a → m ≤ k → m ∈AP (∈AP-cut₁ a prf) ∈AP-∈-cut AdvDone hereTgtDone m∈ap hyp = m∈ap ∈AP-∈-cut (AdvThere _ _ _) hereTgtThere m∈ap hyp = m∈ap ∈AP-∈-cut (AdvThere d h a) (step x prf) hereTgtThere hyp = ⊥-elim (<⇒≱ (hop-< h) (≤-trans hyp (∈AP-≤ prf))) ∈AP-∈-cut (AdvThere d h a) (step x prf) (step x₁ m∈ap) hyp = ∈AP-∈-cut a prf m∈ap hyp ∈AP-cut₁-rebuild : ∀{j k i} → (a : AdvPath j i) → (prf : k ∈AP a) → {s : ℕ} → (s ∈AP (∈AP-cut₁ a prf)) → ∀{t} → rebuild a t s ≡ rebuild (∈AP-cut₁ a prf) t s ∈AP-cut₁-rebuild a prf s∈cut {t} with ∈AP-cut a prf ...| (x , y) , refl = rebuild-⊕' x y s∈cut rebuild-⊕ : ∀{j k i} → {t : View} → (a₁ : AdvPath j k) → (a₂ : AdvPath k i) → rebuild (a₁ ⊕ a₂) t k ≡ rebuild a₂ t k rebuild-⊕ {k = k} a₁ AdvDone = rebuild-⊕' a₁ AdvDone {k} hereTgtDone rebuild-⊕ {k = k} {i = i} a₁ (AdvThere .{k} d h p) = rebuild-⊕' a₁ (AdvThere d h p) hereTgtThere ∈AP-⊕ : ∀{j i₁ k i₂ i} → {e : AdvPath j k}{a₁ : AdvPath k i₁} → {a₂ : AdvPath k i₂} → i ∈AP (e ⊕ a₁) → i ∈AP a₂ → i ∈AP a₁ ∈AP-⊕ {e = AdvDone} hyp1 hyp2 = hyp1 ∈AP-⊕ {e = AdvThere x h e} hereTgtThere hyp2 with ≤-antisym (∈AP-≤ hyp2) (lemma1 (AdvThere x h e)) ...| refl = ⊥-elim (hop-prog h (≤-antisym (hop-≤ h) (lemma1 e))) ∈AP-⊕ {e = AdvThere x h e} (step x₁ hyp1) hyp2 = ∈AP-⊕ hyp1 hyp2 ∈AP-point' : ∀{j k i} → {a₁ : AdvPath j k} → {a₂ : AdvPath k i} → {m : ℕ} → m ∈AP a₁ → m ∈AP a₂ → m ≡ k ∈AP-point' hereTgtDone h2 = refl ∈AP-point' {a₁ = AdvThere d h a₁} {a₂} hereTgtThere h2 = ⊥-elim (≤-≢-mon (≤-≢-mon (hop-prog h) (hop-≤ h) (lemma1 a₁) ∘ sym) (∈AP-≤ h2) (lemma1 (AdvThere d h a₁)) refl) ∈AP-point' (step x h1) h2 = ∈AP-point' h1 h2 ∈AP-point'' : ∀{j₁ j₂ i₁ i₂} → {a₁ : AdvPath j₁ i₁} → {a₂ : AdvPath j₂ i₂} → j₂ < i₁ → {i : ℕ} → i ∈AP a₁ → i ∈AP a₂ → ⊥ ∈AP-point'' j<i hereTgtDone h2 = (<⇒≢ j<i) (≤-antisym (<⇒≤ j<i) (∈AP-≤ h2)) ∈AP-point'' {a₁ = a₁} j<i hereTgtThere h2 = (<⇒≢ j<i) (≤-antisym (<⇒≤ j<i) (≤-trans (lemma1 a₁) (∈AP-≤ h2))) ∈AP-point'' j<i (step x h1) h2 = ∈AP-point'' j<i h1 h2 ∈AP-point : ∀{j₁ j₂ i₁ i₂} → {a₁ : AdvPath j₁ i₁} → {a₂ : AdvPath j₂ i₂} → j₂ ≤ i₁ → {i : ℕ} → i ∈AP a₁ → i ∈AP a₂ → j₂ ≡ i₁ × i ≡ j₂ ∈AP-point {j₂ = j₂} {i₁ = i₁} j₂≤i₁ h1 h2 with j₂ ≟ℕ i₁ ...| no abs = ⊥-elim (∈AP-point'' (≤∧≢⇒< j₂≤i₁ abs) h1 h2) ...| yes refl = refl , ∈AP-point' h1 h2 ∈AP-AdvDone-≡ : ∀{i j} → i ∈AP (AdvDone {j}) → i ≡ j ∈AP-AdvDone-≡ hereTgtDone = refl -- It is important that we can split proofs. Here, we know that 'a' -- and the guide are proofs that come from jump from the same source, j. split-⊕ : ∀{J j i} → {H : HopFrom J} → {h : HopFrom j} → j ≤ J → hop-tgt H < hop-tgt h → i ≤ hop-tgt H → (a : AdvPath (hop-tgt h) i) → Σ (AdvPath (hop-tgt h) (hop-tgt H) × AdvPath (hop-tgt H) i) (λ { (x , y) → a ≡ x ⊕ y }) split-⊕ j≤J H<h i≤H AdvDone = ⊥-elim (≤-≢-mon (<⇒≢ H<h) (<⇒≤ H<h) i≤H refl) split-⊕ {i = i} {H} {h} j≤J H<h i≤H (AdvThere d h' a) with hop-tgt h' ≟ℕ hop-tgt H ...| yes sameHop = (AdvThere d h' (subst (AdvPath (hop-tgt h')) sameHop AdvDone) , subst (λ P → AdvPath P i) sameHop a) , aux sameHop a where aux : ∀{i j k}{h : HopFrom j} → (stop : hop-tgt h ≡ k) → (a : AdvPath (hop-tgt h) i) → AdvThere d h a ≡ (AdvThere d h (subst (AdvPath (hop-tgt h)) stop AdvDone) ⊕ subst (λ P → AdvPath P i) stop a) aux refl a = refl ...| no diffHop with ≤-total (hop-tgt h') (hop-tgt H) ...| inj₁ crossover with hops-nested-or-nonoverlapping (≤∧≢⇒< crossover diffHop) H<h ...| abs = ⊥-elim (≤-≢-mon (mmm (hop-≤ h) (hop-prog h) j≤J) (≤-trans (hop-≤ h) j≤J) abs refl) where mmm : ∀{h j J} → h ≤ j → h ≢ j → j ≤ J → h ≢ J mmm h≤j h≢j j≤J refl = h≢j (≤-antisym h≤j j≤J) split-⊕ {i = i} {H} {h} j≤J H<h i≤H (AdvThere d h' a) | no diffHop | inj₂ go with split-⊕ {H = H} (≤-trans (hop-≤ h) j≤J) (≤∧≢⇒< go (diffHop ∘ sym)) i≤H a ...| ((x , y) , prf) = (AdvThere d h' x , y) , cong (AdvThere d h') prf --------------------- -- Evolutionary CR -- --------------------- -- The type 'AgreeOnCommon t₁ t₂ a₁ a₂', or 'AOC' for short, is inhabited if -- and only if the advancement proofs a₁ and a₂ agree on the hash they rebuild -- for every index that is visited by both. Moreover, the views must also -- agree on the dependencies of said indexes. data AOC (t₁ t₂ : View) : ∀{i₁ i₂ j} → AdvPath j i₁ → AdvPath j i₂ → Set where PDoneDone : ∀{i} → t₁ i ≡ t₂ i → AOC t₁ t₂ {i} {i} AdvDone AdvDone -- h -- ⌜⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⁻⌝ -- | | -- | ⌜⁻⁻⁻ a₁ ⁻⁻⁻⁻| -- | | | -- i₂ ⋯ hop-tgt h ≤ i₁ j PDoneL : ∀{j i₁ i₂}{d}{h : HopFrom j} → (a₁ : AdvPath j i₁) → (a₂ : AdvPath (hop-tgt h) i₂) → hop-tgt h ≤ i₁ → rebuild a₁ t₁ j ≡ rebuild (AdvThere d h a₂) t₂ j → AOC t₁ t₂ a₁ (AdvThere d h a₂) PDoneR : ∀{j i₁ i₂}{d}{h : HopFrom j} → (a₁ : AdvPath (hop-tgt h) i₁) → (a₂ : AdvPath j i₂) → hop-tgt h ≤ i₂ → rebuild (AdvThere d h a₁) t₁ j ≡ rebuild a₂ t₂ j → AOC t₁ t₂ (AdvThere d h a₁) a₂ PCong : ∀{j i₁ i₂}{d}{h : HopFrom j} → i₁ ≤ i₂ → (a₁ : AdvPath (hop-tgt h) i₁) → (a₂ : AdvPath (hop-tgt h) i₂) → Agree (rebuild a₁ t₁) (rebuild a₂ t₂) (depsof j) → AOC t₁ t₂ a₁ a₂ → AOC t₁ t₂ (AdvThere d h a₁) (AdvThere d h a₂) PMeetR : ∀{j i₁ i₂ d}{h₁ h₂ : HopFrom j} → (e : AdvPath (hop-tgt h₁) (hop-tgt h₂)) → (a₁ : AdvPath (hop-tgt h₂) i₁) → (a₂ : AdvPath (hop-tgt h₂) i₂) → hop-tgt h₂ < hop-tgt h₁ → Agree (rebuild (e ⊕ a₁) t₁) (rebuild a₂ t₂) (depsof j) → AOC t₁ t₂ a₁ a₂ → AOC t₁ t₂ (AdvThere d h₁ (e ⊕ a₁)) (AdvThere d h₂ a₂) PMeetL : ∀{j i₁ i₂ d}{h₁ h₂ : HopFrom j} → (e : AdvPath (hop-tgt h₂) (hop-tgt h₁)) → (a₁ : AdvPath (hop-tgt h₁) i₁) → (a₂ : AdvPath (hop-tgt h₁) i₂) → hop-tgt h₁ < hop-tgt h₂ → Agree (rebuild a₁ t₁) (rebuild (e ⊕ a₂) t₂) (depsof j) → AOC t₁ t₂ a₁ a₂ → AOC t₁ t₂ (AdvThere d h₁ a₁) (AdvThere d h₂ (e ⊕ a₂)) -- We use the 'TERMINATING' pragma because we use a recursive call on -- an argument that Agda can't infer being structurally smaller. -- TODO-1: provide clear and detailed explanation of this, which argument, why smaller? -- An interesting longer-term TODO-2 would be to use 'Sized Types' to inform -- the typechecker of this fact, or perhaps a custom-made moral equivalent. {-# TERMINATING #-} aoc : ∀{i₁ i₂ j} → i₁ ≤ i₂ -- wlog → (t₁ t₂ : View)(a₁ : AdvPath j i₁)(a₂ : AdvPath j i₂) → rebuild a₁ t₁ j ≡ rebuild a₂ t₂ j → HashBroke ⊎ AOC t₁ t₂ a₁ a₂ aoc _ t1 t2 AdvDone AdvDone hip = inj₂ (PDoneDone hip) aoc _ t1 t2 AdvDone (AdvThere x h a2) hip = inj₂ (PDoneL AdvDone a2 (hop-≤ h) hip) aoc _ t1 t2 (AdvThere x h a1) AdvDone hip = inj₂ (PDoneR a1 AdvDone (hop-≤ h) hip) aoc {i₁} {i₂} {j} k t₁ t₂ (AdvThere d₁ h₁ a₁) (AdvThere d₂ h₂ a₂) hip with ≤-total i₂ (hop-tgt h₁) ...| inj₂ h₁≤i₂ = inj₂ (PDoneR a₁ (AdvThere d₂ h₂ a₂) h₁≤i₂ hip) ...| inj₁ go rewrite ≟ℕ-refl j with auth-inj-1 {j} {d₁} {d₂} (lemma3 h₁ a₁) hip ...| inj₁ hb = inj₁ hb ...| inj₂ refl with auth-inj-2 {j} {d₁} (rebuild a₁ t₁) (rebuild a₂ t₂) hip ...| inj₁ hb = inj₁ hb ...| inj₂ agree with h₁ ≟Hop h₂ ...| yes refl with witness (hop-tgt-is-dep h₁) agree ...| wit rewrite (≟ℕ-refl (hop-tgt h₁)) with aoc k t₁ t₂ a₁ a₂ wit ...| inj₁ hb = inj₁ hb ...| inj₂ rec = inj₂ (PCong k a₁ a₂ agree rec) aoc {i₁} {i₂} {j} k t₁ t₂ (AdvThere d₁ h₁ a₁) (AdvThere d₂ h₂ a₂) hip | inj₁ go | inj₂ refl | inj₂ agree | no diffHop with ≤-total (hop-tgt h₁) (hop-tgt h₂) ...| inj₁ h₁<h₂ with split-⊕ ≤-refl (≤∧≢⇒< h₁<h₂ (diffHop ∘ hop-tgt-inj)) go a₂ ...| ((x , y) , refl) with aoc k t₁ t₂ a₁ y (trans (witness (hop-tgt-is-dep h₁) agree) (rebuild-⊕ x y)) ...| inj₁ hb = inj₁ hb ...| inj₂ res = inj₂ (PMeetL x a₁ y (≤∧≢⇒< h₁<h₂ (diffHop ∘ hop-tgt-inj)) agree res) aoc {j = j} k t₁ t₂ (AdvThere d₁ h₁ a₁) (AdvThere d₂ h₂ a₂) hip | inj₁ go | inj₂ refl | inj₂ agree | no diffHop | inj₂ h₂<h₁ with split-⊕ ≤-refl (≤∧≢⇒< h₂<h₁ (diffHop ∘ hop-tgt-inj ∘ sym)) (≤-trans k (lemma1 a₂)) a₁ ...| ((x , y) , refl) with aoc k t₁ t₂ y a₂ (trans (sym (rebuild-⊕ x y)) (witness (hop-tgt-is-dep h₂) agree)) ...| inj₁ hb = inj₁ hb ...| inj₂ res = inj₂ (PMeetR x y a₂ (≤∧≢⇒< h₂<h₁ (diffHop ∘ hop-tgt-inj ∘ sym)) agree res) -- TODO: rename AGREEONCOMMON for consistency with paper, or comment to make connection aoc-correct : ∀{j i₁ i₂}{a₁ : AdvPath j i₁}{a₂ : AdvPath j i₂} → {t₁ t₂ : View} → AOC t₁ t₂ a₁ a₂ → {i : ℕ} → i ∈AP a₁ → i ∈AP a₂ → HashBroke ⊎ rebuild a₁ t₁ i ≡ rebuild a₂ t₂ i aoc-correct (PDoneDone x) hereTgtDone hereTgtDone = inj₂ x aoc-correct (PDoneL a₁ a₂ x x₁) hyp1 hereTgtThere = inj₂ x₁ aoc-correct {j} {t₁ = t₁} {t₂} (PDoneL {d = d} {h} a₁ a₂ x x₁) {i} hyp1 (step x₂ hyp2) with j ≟ℕ i ...| yes nope = ⊥-elim (x₂ (sym nope)) ...| no ok with a₁ ...| AdvDone rewrite ∈AP-AdvDone-≡ hyp1 = ⊥-elim (x₂ refl) ...| AdvThere d₁ h₁ a₁' with ∈AP-point x hyp1 hyp2 ...| refl , refl with j ≟ℕ hop-tgt h ...| yes nope = ⊥-elim (x₂ (sym nope)) ...| no ok' rewrite ≟ℕ-refl j with auth-inj-1 {h₁ = d₁} {d} (HopFrom≢0 h) x₁ ...| inj₁ hb = inj₁ hb ...| inj₂ refl with auth-inj-2 {j} {d₁} (rebuild a₁' t₁) (rebuild a₂ t₂) x₁ ...| inj₁ hb = inj₁ hb ...| inj₂ r = inj₂ (witness (hop-tgt-is-dep h) r) aoc-correct (PDoneR a₁ a₂ x x₁) hereTgtThere hyp2 = inj₂ x₁ aoc-correct {j} {t₁ = t₁} {t₂} (PDoneR {d = d} {h} a₁ a₂ x x₁) {i} (step x₂ hyp1) hyp2 with j ≟ℕ i ...| yes nope = ⊥-elim (x₂ (sym nope)) ...| no ok with a₂ ...| AdvDone rewrite ∈AP-AdvDone-≡ hyp2 = ⊥-elim (x₂ refl) ...| AdvThere d₂ h₂ a₂' with ∈AP-point x hyp2 hyp1 ...| refl , refl with j ≟ℕ hop-tgt h ...| yes nope = ⊥-elim (x₂ (sym nope)) ...| no ok' rewrite ≟ℕ-refl j with auth-inj-1 {h₁ = d₂} {d} (HopFrom≢0 h) (sym x₁) ...| inj₁ hb = inj₁ hb ...| inj₂ refl with auth-inj-2 {j} {d₂} (rebuild a₁ t₁) (rebuild a₂' t₂) x₁ ...| inj₁ hb = inj₁ hb ...| inj₂ r = inj₂ (witness (hop-tgt-is-dep h) r) aoc-correct {j} {t₁ = t₁} {t₂} (PCong x a₁ a₂ x₁ aoc₁) hereTgtThere hereTgtThere rewrite ≟ℕ-refl j | List-map-≡-All (rebuild a₁ t₁) (rebuild a₂ t₂) (depsof j) x₁ = inj₂ refl aoc-correct (PCong x a₁ a₂ x₁ aoc₁) hereTgtThere (step x₂ hyp2) = ⊥-elim (x₂ refl) aoc-correct (PCong x a₁ a₂ x₁ aoc₁) (step x₂ hyp1) hereTgtThere = ⊥-elim (x₂ refl) aoc-correct {j} (PCong x a₁ a₂ x₁ aoc₁) {i} (step x₂ hyp1) (step x₃ hyp2) with j ≟ℕ i ...| yes nope = ⊥-elim (x₂ (sym nope)) ...| no ok = aoc-correct aoc₁ hyp1 hyp2 aoc-correct {j} {t₁ = t₁} {t₂} (PMeetR e a₁ a₂ x₁ x₂ aoc₁) hereTgtThere hereTgtThere rewrite ≟ℕ-refl j | List-map-≡-All (rebuild (e ⊕ a₁) t₁) (rebuild a₂ t₂) (depsof j) x₂ = inj₂ refl aoc-correct (PMeetR e a₁ a₂ x₁ x₂ aoc₁) hereTgtThere (step x₃ hyp2) = ⊥-elim (x₃ refl) aoc-correct (PMeetR e a₁ a₂ x₁ x₂ aoc₁) (step x₃ hyp1) hereTgtThere = ⊥-elim (x₃ refl) aoc-correct {j} (PMeetR e a₁ a₂ x₁ x₂ aoc₁) {i} (step x₃ hyp1) (step x₄ hyp2) with j ≟ℕ i ...| yes nope = ⊥-elim (x₃ (sym nope)) ...| no ok with aoc-correct aoc₁ (∈AP-⊕ hyp1 hyp2) hyp2 ...| inj₁ hb = inj₁ hb ...| inj₂ r = inj₂ (trans (rebuild-⊕' e a₁ (∈AP-⊕ hyp1 hyp2)) r) aoc-correct {j} {t₁ = t₁} {t₂} (PMeetL e a₁ a₂ x₁ x₂ aoc₁) hereTgtThere hereTgtThere rewrite ≟ℕ-refl j | List-map-≡-All (rebuild a₁ t₁) (rebuild (e ⊕ a₂) t₂) (depsof j) x₂ = inj₂ refl aoc-correct (PMeetL e a₁ a₂ x₁ x₂ aoc₁) hereTgtThere (step x₃ hyp2) = ⊥-elim (x₃ refl) aoc-correct (PMeetL e a₁ a₂ x₁ x₂ aoc₁) (step x₃ hyp1) hereTgtThere = ⊥-elim (x₃ refl) aoc-correct {j} (PMeetL e a₁ a₂ x₁ x₂ aoc₁) {i} (step x₃ hyp1) (step x₄ hyp2) with j ≟ℕ i ...| yes nope = ⊥-elim (x₃ (sym nope)) ...| no ok with aoc-correct aoc₁ hyp1 (∈AP-⊕ hyp2 hyp1) ...| inj₁ hb = inj₁ hb ...| inj₂ r = inj₂ (trans r (sym (rebuild-⊕' e a₂ (∈AP-⊕ hyp2 hyp1)))) AgreeOnCommon : ∀{j i₁ i₂} → {t₁ t₂ : View} → (a₁ : AdvPath j i₁)(a₂ : AdvPath j i₂) → rebuild a₁ t₁ j ≡ rebuild a₂ t₂ j → {i : ℕ} → i ∈AP a₁ → i ∈AP a₂ → HashBroke ⊎ rebuild a₁ t₁ i ≡ rebuild a₂ t₂ i AgreeOnCommon {i₁ = i₁} {i₂} {t₁} {t₂} a₁ a₂ rebuild-to-j i∈a₁ i∈a₂ with ≤-total i₁ i₂ ...| inj₁ i₁≤i₂ with aoc i₁≤i₂ t₁ t₂ a₁ a₂ rebuild-to-j ...| inj₁ hb = inj₁ hb ...| inj₂ xx = aoc-correct xx i∈a₁ i∈a₂ AgreeOnCommon {i₁ = i₁} {i₂} {t₁} {t₂} a₁ a₂ rebuild-to-j i∈a₁ i∈a₂ | inj₂ i₂≤i₁ with aoc i₂≤i₁ t₂ t₁ a₂ a₁ (sym rebuild-to-j) ...| inj₁ hb = inj₁ hb ...| inj₂ xx with aoc-correct xx i∈a₂ i∈a₁ ...| inj₁ hb = inj₁ hb ...| inj₂ xx1 = inj₂ (sym xx1) AgreeOnCommon-∈ : ∀{j₁ j₂ i₁ i₂} → {t₁ t₂ : View} → (a₁ : AdvPath j₁ i₁)(a₂ : AdvPath j₂ i₂) → j₂ ∈AP a₁ → rebuild a₁ t₁ j₂ ≡ rebuild a₂ t₂ j₂ → {i : ℕ} → i ∈AP a₁ → i ∈AP a₂ → HashBroke ⊎ rebuild a₁ t₁ i ≡ rebuild a₂ t₂ i AgreeOnCommon-∈ a₁ a₂ j2∈a1 hyp ia1 ia2 with ∈AP-cut a₁ j2∈a1 ...| ((a₁₁ , a₁₂) , refl) with AgreeOnCommon a₁₂ a₂ (trans (sym (rebuild-⊕' a₁₁ a₁₂ ∈AP-src)) hyp) (∈AP-⊕ ia1 ia2) ia2 ...| inj₁ hb = inj₁ hb ...| inj₂ res = inj₂ (trans (rebuild-⊕' a₁₁ a₁₂ (∈AP-⊕ ia1 ia2)) res) ----------------------- -- Membership Proofs -- ----------------------- -- A membership proof for i is simply an advancement proof from j to i, -- a digest of the data in i and the authenticators that i depends on (which -- come in the view) MembershipProof : ℕ → ℕ → Set MembershipProof j i = AdvPath j i × Hash × i ≢ 0 mbr-datum : ∀{j i} → MembershipProof j i → Hash mbr-datum (_ , d , _) = d mbr-proof : ∀{j i} → MembershipProof j i → AdvPath j i mbr-proof (p , _ , _) = p mbr-not-init : ∀{j i} → MembershipProof j i → i ≢ 0 mbr-not-init (_ , _ , m) = m -- Rebuilding it is the same as rebuilding an advancement proof, but we -- explicitely compute the authenticator at i. rebuildMP : ∀{j i} → MembershipProof j i → View → View rebuildMP {j} {i} mbr t = rebuild (mbr-proof mbr) (t ∪₁ (i , auth i (mbr-datum mbr) t)) semi-evo-cr : ∀{j i₁ i₂}{t₁ t₂ : View} → (a₁ : AdvPath j i₁) → (a₂ : AdvPath j i₂) → rebuild a₁ t₁ j ≡ rebuild a₂ t₂ j → ∀{s₁ s₂ tgt}{u₁ u₂ : View} → (m₁ : MembershipProof s₁ tgt)(m₂ : MembershipProof s₂ tgt) → s₁ ∈AP a₁ → s₂ ∈AP a₂ → tgt ∈AP a₁ → tgt ∈AP a₂ → tgt ≢ 0 → rebuildMP m₁ u₁ s₁ ≡ rebuild a₁ t₁ s₁ → rebuildMP m₂ u₂ s₂ ≡ rebuild a₂ t₂ s₂ → HashBroke ⊎ (mbr-datum m₁ ≡ mbr-datum m₂) semi-evo-cr {t₁ = t₁} {t₂} a₁ a₂ hyp {tgt = tgt} {u₁} {u₂} m₁ m₂ s₁∈a₁ s₂∈a₂ t∈a₁ t∈a₂ t≢0 c₁ c₂ with AgreeOnCommon (mbr-proof m₁) (∈AP-cut₁ a₁ s₁∈a₁) (trans c₁ (∈AP-cut₁-rebuild a₁ s₁∈a₁ ∈AP-src {t₁})) ∈AP-tgt (∈AP-∈-cut a₁ s₁∈a₁ t∈a₁ (lemma1 (mbr-proof m₁))) ...| inj₁ hb = inj₁ hb ...| inj₂ hyp1 with AgreeOnCommon (mbr-proof m₂) (∈AP-cut₁ a₂ s₂∈a₂) (trans c₂ (∈AP-cut₁-rebuild a₂ s₂∈a₂ ∈AP-src {t₂})) ∈AP-tgt (∈AP-∈-cut a₂ s₂∈a₂ t∈a₂ (lemma1 (mbr-proof m₂))) ...| inj₁ hb = inj₁ hb ...| inj₂ hyp2 with AgreeOnCommon a₁ a₂ hyp t∈a₁ t∈a₂ ...| inj₁ hb = inj₁ hb ...| inj₂ hyp3 rewrite sym (∈AP-cut₁-rebuild a₁ s₁∈a₁ (∈AP-∈-cut a₁ s₁∈a₁ t∈a₁ (lemma1 (mbr-proof m₁))) {t₁}) | sym (∈AP-cut₁-rebuild a₂ s₂∈a₂ (∈AP-∈-cut a₂ s₂∈a₂ t∈a₂ (lemma1 (mbr-proof m₂))) {t₂}) with trans hyp1 (trans hyp3 (sym hyp2)) ...| half with rebuild-tgt-lemma (mbr-proof m₁) {u₁ ∪₁ (tgt , auth tgt (mbr-datum m₁) u₁) } | rebuild-tgt-lemma (mbr-proof m₂) {u₂ ∪₁ (tgt , auth tgt (mbr-datum m₂) u₂) } ...| l1 | l2 rewrite ≟ℕ-refl tgt = auth-inj-1 {tgt} {mbr-datum m₁} {mbr-datum m₂} t≢0 (trans (sym l1) (trans half l2))
{ "alphanum_fraction": 0.5256268502, "avg_line_length": 38.5653370014, "ext": "agda", "hexsha": "dd81d13e564aa8a9139d904c21c33badcb7e14df", "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": "8032dd49b4a3803870a3c238abf948c598913f4c", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "VictorCMiraldo/aaosl-agda", "max_forks_repo_path": "AAOSL/Abstract/Advancement.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8032dd49b4a3803870a3c238abf948c598913f4c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "VictorCMiraldo/aaosl-agda", "max_issues_repo_path": "AAOSL/Abstract/Advancement.agda", "max_line_length": 115, "max_stars_count": 1, "max_stars_repo_head_hexsha": "8032dd49b4a3803870a3c238abf948c598913f4c", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "VictorCMiraldo/aaosl-agda", "max_stars_repo_path": "AAOSL/Abstract/Advancement.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-13T17:55:08.000Z", "max_stars_repo_stars_event_min_datetime": "2021-01-13T17:55:08.000Z", "num_tokens": 11461, "size": 28037 }
import Oscar.Class.Transextensionality.Proposequality -- FIXME why not use the instance here? open import Oscar.Class open import Oscar.Class.IsPrecategory open import Oscar.Class.Transextensionality open import Oscar.Class.Transitivity open import Oscar.Data.Proposequality open import Oscar.Prelude open import Oscar.Property.Setoid.Proposequality module Test.ConfusionAboutExtension where module _ {a} {A : Ø a} where instance 𝓣ransextensionalityProposequality : Transextensionality.class Proposequality⟦ A ⟧ Proposequality transitivity -- 𝓣ransextensionalityProposequality = Oscar.Class.Transextensionality.Proposequality.𝓣ransextensionalityProposequality -- using this instead avoids the below-mentioned errors 𝓣ransextensionalityProposequality .⋆ ∅ ∅ = ! module _ {a} {A : Ø a} where testme : Transextensionality.class Proposequality⟦ A ⟧ (Proposequality) (transitivity) testme = ! -- errors instance IsPrecategoryExtension : IsPrecategory Proposequality⟦ A ⟧ Proposequality transitivity IsPrecategoryExtension .IsPrecategory.`𝓣ransextensionality = {!!!} -- FIXME I'd like to use instance search to find this instance, but this errors b/c of IsPrecategoryExtension .IsPrecategory.`𝓣ransassociativity = magic
{ "alphanum_fraction": 0.7973079968, "avg_line_length": 36.0857142857, "ext": "agda", "hexsha": "98a1e91ac33d11d9e8348ddcff6ccb5234df75df", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Test/ConfusionAboutExtension.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Test/ConfusionAboutExtension.agda", "max_line_length": 179, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Test/ConfusionAboutExtension.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 344, "size": 1263 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Heterogeneous N-ary Functions ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Function.Nary.NonDependent where ------------------------------------------------------------------------ -- Concrete examples can be found in README.Nary. This file's comments -- are more focused on the implementation details and the motivations -- behind the design decisions. ------------------------------------------------------------------------ open import Level using (Level; 0ℓ; _⊔_; Lift) open import Data.Nat.Base using (ℕ; zero; suc) open import Data.Fin.Base using (Fin; zero; suc) open import Data.Product using (_×_; _,_) open import Data.Product.Nary.NonDependent open import Function.Base using (_∘′_; _$′_; const; flip) open import Relation.Unary using (IUniversal) open import Relation.Binary.PropositionalEquality private variable a b r : Level A : Set a B : Set b ------------------------------------------------------------------------ -- Re-exporting the basic operations open import Function.Nary.NonDependent.Base public ------------------------------------------------------------------------ -- Additional operations on Levels ltabulate : ∀ n → (Fin n → Level) → Levels n ltabulate zero f = _ ltabulate (suc n) f = f zero , ltabulate n (f ∘′ suc) lreplicate : ∀ n → Level → Levels n lreplicate n ℓ = ltabulate n (const ℓ) 0ℓs : ∀[ Levels ] 0ℓs = lreplicate _ 0ℓ ------------------------------------------------------------------------ -- Congruence module _ n {ls} {as : Sets n ls} {R : Set r} (f : as ⇉ R) where private g : Product n as → R g = uncurryₙ n f -- Congruentₙ : ∀ n. ∀ a₁₁ a₁₂ ⋯ aₙ₁ aₙ₂ → -- a₁₁ ≡ a₁₂ → ⋯ → aₙ₁ ≡ aₙ₂ → -- f a₁₁ ⋯ aₙ₁ ≡ f a₁₂ ⋯ aₙ₂ Congruentₙ : Set (r Level.⊔ ⨆ n ls) Congruentₙ = ∀ {l r} → Equalₙ n l r ⇉ (g l ≡ g r) congₙ : Congruentₙ congₙ = curryₙ n (cong g ∘′ fromEqualₙ n) -- Congruence at a specific location module _ m n {ls ls'} {as : Sets m ls} {bs : Sets n ls'} (f : as ⇉ (A → bs ⇉ B)) where private g : Product m as → A → Product n bs → B g vs a ws = uncurryₙ n (uncurryₙ m f vs a) ws congAt : ∀ {vs ws a₁ a₂} → a₁ ≡ a₂ → g vs a₁ ws ≡ g vs a₂ ws congAt {vs} {ws} = cong (λ a → g vs a ws) ------------------------------------------------------------------------ -- Injectivity module _ n {ls} {as : Sets n ls} {R : Set r} (con : as ⇉ R) where -- Injectiveₙ : ∀ n. ∀ a₁₁ a₁₂ ⋯ aₙ₁ aₙ₂ → -- con a₁₁ ⋯ aₙ₁ ≡ con a₁₂ ⋯ aₙ₂ → -- a₁₁ ≡ a₁₂ × ⋯ × aₙ₁ ≡ aₙ₂ private c : Product n as → R c = uncurryₙ n con Injectiveₙ : Set (r Level.⊔ ⨆ n ls) Injectiveₙ = ∀ {l r} → c l ≡ c r → Product n (Equalₙ n l r) injectiveₙ : (∀ {l r} → c l ≡ c r → l ≡ r) → Injectiveₙ injectiveₙ con-inj eq = toEqualₙ n (con-inj eq)
{ "alphanum_fraction": 0.4883099532, "avg_line_length": 30.2424242424, "ext": "agda", "hexsha": "3485aa2b780d2a9191cecbdd7399d2e22d385900", "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/Function/Nary/NonDependent.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/Function/Nary/NonDependent.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/Function/Nary/NonDependent.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 945, "size": 2994 }
{- Functions building UARels and DUARels on Σ-types -} {-# OPTIONS --safe #-} module Cubical.Displayed.Sigma where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Data.Sigma open import Cubical.Displayed.Base open import Cubical.Displayed.Subst open import Cubical.Displayed.Morphism open import Cubical.Displayed.Constant private variable ℓ ℓA ℓA' ℓP ℓ≅A ℓ≅A' ℓB ℓB' ℓ≅B ℓ≅B' ℓC ℓ≅C : Level -- UARel on a Σ-type ∫ˢ : {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB} (𝒮ˢ-B : SubstRel 𝒮-A B) → UARel (Σ A B) (ℓ-max ℓ≅A ℓB) ∫ˢ 𝒮ˢ-B = ∫ (Subst→DUA 𝒮ˢ-B) _×𝒮_ : {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) {B : Type ℓB} (𝒮-B : UARel B ℓ≅B) → UARel (A × B) (ℓ-max ℓ≅A ℓ≅B) 𝒮-A ×𝒮 𝒮-B = ∫ (𝒮ᴰ-const 𝒮-A 𝒮-B) -- Projection UARel morphisms 𝒮-fst : {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB} {𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B} → UARelHom (∫ 𝒮ᴰ-B) 𝒮-A 𝒮-fst .UARelHom.fun = fst 𝒮-fst .UARelHom.rel = fst 𝒮-fst .UARelHom.ua p = refl 𝒮-snd : {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : Type ℓB} {𝒮-B : UARel B ℓ≅B} → UARelHom (𝒮-A ×𝒮 𝒮-B) 𝒮-B 𝒮-snd .UARelHom.fun = snd 𝒮-snd .UARelHom.rel = snd 𝒮-snd .UARelHom.ua p = refl -- Lift a DUARel to live over a Σ-type 𝒮ᴰ-Lift : {A : Type ℓA} (𝒮-A : UARel A ℓ≅A) {B : A → Type ℓB} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B) {C : A → Type ℓC} (𝒮ᴰ-C : DUARel 𝒮-A C ℓ≅C) → DUARel (∫ 𝒮ᴰ-C) (λ (a , _) → B a) ℓ≅B 𝒮ᴰ-Lift _ 𝒮ᴰ-B _ = 𝒮ᴰ-reindex 𝒮-fst 𝒮ᴰ-B -- DUARel on a Σ-type module _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB} {ℓ≅B : Level} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B) {C : Σ A B → Type ℓC} {ℓ≅C : Level} (𝒮ᴰ-C : DUARel (∫ 𝒮ᴰ-B) C ℓ≅C) where open UARel 𝒮-A private module B = DUARel 𝒮ᴰ-B module C = DUARel 𝒮ᴰ-C 𝒮ᴰ-Σ : DUARel 𝒮-A (λ a → Σ[ b ∈ B a ] C (a , b)) (ℓ-max ℓ≅B ℓ≅C) DUARel._≅ᴰ⟨_⟩_ 𝒮ᴰ-Σ (b , c) p (b' , c') = Σ[ q ∈ b B.≅ᴰ⟨ p ⟩ b' ] (c C.≅ᴰ⟨ p , q ⟩ c') DUARel.uaᴰ 𝒮ᴰ-Σ (b , c) p (b' , c') = compEquiv (Σ-cong-equiv (B.uaᴰ b p b') (λ q → C.uaᴰ c (p , q) c')) ΣPath≃PathΣ -- DUARel on a non-dependent Σ-type module _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB} {ℓ≅B : Level} (𝒮ᴰ-B : DUARel 𝒮-A B ℓ≅B) {C : A → Type ℓC} {ℓ≅C : Level} (𝒮ᴰ-C : DUARel 𝒮-A C ℓ≅C) where _×𝒮ᴰ_ : DUARel 𝒮-A (λ a → B a × C a) (ℓ-max ℓ≅B ℓ≅C) _×𝒮ᴰ_ = 𝒮ᴰ-Σ 𝒮ᴰ-B (𝒮ᴰ-Lift 𝒮-A 𝒮ᴰ-C 𝒮ᴰ-B) -- SubstRel on a Σ-type module _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB} (𝒮ˢ-B : SubstRel 𝒮-A B) {C : Σ A B → Type ℓC} (𝒮ˢ-C : SubstRel (∫ˢ 𝒮ˢ-B) C) where open UARel 𝒮-A open SubstRel private module B = SubstRel 𝒮ˢ-B module C = SubstRel 𝒮ˢ-C 𝒮ˢ-Σ : SubstRel 𝒮-A (λ a → Σ[ b ∈ B a ] C (a , b)) 𝒮ˢ-Σ .act p = Σ-cong-equiv (B.act p) (λ b → C.act (p , refl)) 𝒮ˢ-Σ .uaˢ p _ = fromPathP (DUARel.uaᴰ (𝒮ᴰ-Σ (Subst→DUA 𝒮ˢ-B) (Subst→DUA 𝒮ˢ-C)) _ p _ .fst (refl , refl)) -- SubstRel on a non-dependent product module _ {A : Type ℓA} {𝒮-A : UARel A ℓ≅A} {B : A → Type ℓB} (𝒮ˢ-B : SubstRel 𝒮-A B) {C : A → Type ℓC} (𝒮ˢ-C : SubstRel 𝒮-A C) where open UARel 𝒮-A open SubstRel private module B = SubstRel 𝒮ˢ-B module C = SubstRel 𝒮ˢ-C _×𝒮ˢ_ : SubstRel 𝒮-A (λ a → B a × C a) _×𝒮ˢ_ .act p = ≃-× (B.act p) (C.act p) _×𝒮ˢ_ .uaˢ p (b , c) = ΣPathP (B.uaˢ p b , C.uaˢ p c)
{ "alphanum_fraction": 0.5623659209, "avg_line_length": 27.4201680672, "ext": "agda", "hexsha": "d62834baa122ed177a056a816d3684a3ec92e1ba", "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/Displayed/Sigma.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/Displayed/Sigma.agda", "max_line_length": 87, "max_stars_count": null, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Displayed/Sigma.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1969, "size": 3263 }
-- Martin-Löf identity type without the K axiom -- (we do not assume uniqueness of identity proofs). {-# OPTIONS --without-K --safe #-} module Tools.PropositionalEquality where -- We reexport Agda's builtin equality type. open import Agda.Builtin.Equality public using (_≡_; refl) open import Tools.Empty -- Inequality. infix 4 _≢_ _≢_ : {A : Set} → A → A → Set a ≢ b = a ≡ b → ⊥ -- Symmetry. sym : {A : Set} {a b : A} → a ≡ b → b ≡ a sym refl = refl -- Transitivity. trans : {A : Set} {a b c : A} → a ≡ b → b ≡ c → a ≡ c trans refl refl = refl -- Non-dependent congruence rules. cong : {A B : Set} {a b : A} (f : A → B) → a ≡ b → f a ≡ f b cong f refl = refl cong₂ : ∀ {A B C : Set} {a a′ b b′} (f : A → B → C) → a ≡ a′ → b ≡ b′ → f a b ≡ f a′ b′ cong₂ f refl refl = refl cong₃ : ∀ {A B C D : Set} {a a′ b b′ c c′} (f : A → B → C → D) → a ≡ a′ → b ≡ b′ → c ≡ c′ → f a b c ≡ f a′ b′ c′ cong₃ f refl refl refl = refl cong₄ : ∀ {A B C D E : Set} {a a′ b b′ c c′ d d′} (f : A → B → C → D → E) → a ≡ a′ → b ≡ b′ → c ≡ c′ → d ≡ d′ → f a b c d ≡ f a′ b′ c′ d′ cong₄ f refl refl refl refl = refl -- Substitution (type-cast). subst : {A : Set} {a b : A} {ℓ : Agda.Primitive.Level} (F : A → Set ℓ) → a ≡ b → F a → F b subst F refl f = f -- Two substitutions simultaneously. subst₂ : ∀ {A B : Set} {a a′ b b′} {ℓ : Agda.Primitive.Level} (F : A → B → Set ℓ) → a ≡ a′ → b ≡ b′ → F a b → F a′ b′ subst₂ F refl refl f = f -- Three substitutions simultaneously. subst₃ : ∀ {A B C : Set} {a a′ b b′ c c′} (F : A → B → C → Set) → a ≡ a′ → b ≡ b′ → c ≡ c′ → F a b c → F a′ b′ c′ subst₃ F refl refl refl f = f
{ "alphanum_fraction": 0.508687837, "avg_line_length": 25.2878787879, "ext": "agda", "hexsha": "11cda996f6d611a5abb005758d62f2ae5e3a09d7", "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": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_path": "Tools/PropositionalEquality.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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": "loic-p/logrel-mltt", "max_issues_repo_path": "Tools/PropositionalEquality.agda", "max_line_length": 90, "max_stars_count": null, "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_path": "Tools/PropositionalEquality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 702, "size": 1669 }
{-# OPTIONS --safe #-} open import Cubical.Foundations.Everything renaming (Iso to _≅_) open import Cubical.Data.List open import Cubical.Data.Unit open import Cubical.Data.Prod hiding (map) open import Cubical.Data.Nat module Cubical.Data.List.Dependent where open _≅_ data ListP {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) : (as : List A) → Type (ℓ-max ℓA ℓB) where [] : ListP B [] _∷_ : {x : A} (y : B x) {xs : List A} (ys : ListP B xs) → ListP B (x ∷ xs) -- Represent ListP via known operations in order to derive properties more easily. RepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → Type (ℓ-max ℓA ℓB) RepListP B [] = Lift Unit RepListP B (a ∷ as) = B a × RepListP B as isoRepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → ListP B as ≅ RepListP B as fun (isoRepListP B []) bs = lift tt inv (isoRepListP B []) u = [] rightInv (isoRepListP B []) u = refl leftInv (isoRepListP B []) [] = refl fun (isoRepListP B (a ∷ as)) (b ∷ bs) = b , fun (isoRepListP B as) bs inv (isoRepListP B (a ∷ as)) (b , br) = b ∷ inv (isoRepListP B as) br rightInv (isoRepListP B (a ∷ as)) (b , br) i = b , rightInv (isoRepListP B as) br i leftInv (isoRepListP B (a ∷ as)) (b ∷ bs) i = b ∷ leftInv (isoRepListP B as) bs i equivRepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → ListP B as ≃ RepListP B as equivRepListP B as = isoToEquiv (isoRepListP B as) pathRepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → ListP B as ≡ RepListP B as pathRepListP B as = ua (equivRepListP B as) private isOfHLevelSucSuc-RepListP : ∀ {ℓA ℓB} (n : HLevel) → {A : Type ℓA} → {B : A → Type ℓB} → ((a : A) → isOfHLevel (suc (suc n)) (B a)) → (as : List A) → isOfHLevel (suc (suc n)) (RepListP B as) isOfHLevelSucSuc-RepListP n isHB [] = isOfHLevelLift (suc (suc n)) (isOfHLevelUnit (suc (suc n))) isOfHLevelSucSuc-RepListP n isHB (a ∷ as) = isOfHLevelProd (suc (suc n)) (isHB a) (isOfHLevelSucSuc-RepListP n isHB as) isOfHLevelSucSuc-ListP : ∀ {ℓA ℓB} (n : HLevel) → {A : Type ℓA} → {B : A → Type ℓB} → ((a : A) → isOfHLevel (suc (suc n)) (B a)) → {as : List A} → isOfHLevel (suc (suc n)) (ListP B as) isOfHLevelSucSuc-ListP n {A} {B} isHB {as} = subst⁻ (isOfHLevel (suc (suc n))) (pathRepListP B as) (isOfHLevelSucSuc-RepListP n isHB as) -------------------------- mapP : ∀ {ℓA ℓA' ℓB ℓB'} {A : Type ℓA} {A' : Type ℓA'} {B : A → Type ℓB} {B' : A' → Type ℓB'} (f : A → A') (g : (a : A) → B a → B' (f a)) → ∀ as → ListP B as → ListP B' (map f as) mapP f g [] [] = [] mapP f g (a ∷ as) (b ∷ bs) = g _ b ∷ mapP f g as bs mapOverIdfun : ∀ {ℓA ℓB ℓB'} {A : Type ℓA} {B : A → Type ℓB} {B' : A → Type ℓB'} (g : (a : A) → B a → B' a) → ∀ as → ListP B as → ListP B' as mapOverIdfun g [] [] = [] mapOverIdfun g (a ∷ as) (b ∷ bs) = g a b ∷ mapOverIdfun g as bs mapOverIdfun-idfun : ∀ {ℓA ℓB} {A : Type ℓA} {B : A → Type ℓB} as → mapOverIdfun (λ a → idfun _) as ≡ (idfun (ListP B as)) mapOverIdfun-idfun [] i [] = [] mapOverIdfun-idfun (a ∷ as) i (b ∷ bs) = b ∷ mapOverIdfun-idfun as i bs mapOverIdfun-∘ : ∀ {ℓA ℓB ℓB' ℓB''} {A : Type ℓA} {B : A → Type ℓB} {B' : A → Type ℓB'} {B'' : A → Type ℓB''} (h : (a : A) → B' a → B'' a) (g : (a : A) → B a → B' a) → ∀ as → mapOverIdfun (λ a → h a ∘ g a) as ≡ mapOverIdfun h as ∘ mapOverIdfun g as mapOverIdfun-∘ h g [] i [] = [] mapOverIdfun-∘ h g (a ∷ as) i (b ∷ bs) = h a (g a b) ∷ mapOverIdfun-∘ h g as i bs
{ "alphanum_fraction": 0.5781659389, "avg_line_length": 44.6103896104, "ext": "agda", "hexsha": "1ee3b7c85d5ad571157aa99355376c0f43e357bf", "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/List/Dependent.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/List/Dependent.agda", "max_line_length": 122, "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/List/Dependent.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1565, "size": 3435 }
{-# OPTIONS --safe --cubical #-} module Data.Unit.UniversePolymorphic where open import Level record ⊤ {ℓ} : Type ℓ where constructor tt
{ "alphanum_fraction": 0.7214285714, "avg_line_length": 17.5, "ext": "agda", "hexsha": "d968bf42552bcfc8d57aac2b3d5145cf66af7925", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/Data/Unit/UniversePolymorphic.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/Data/Unit/UniversePolymorphic.agda", "max_line_length": 42, "max_stars_count": 4, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/Data/Unit/UniversePolymorphic.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z", "max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z", "num_tokens": 38, "size": 140 }
{-# OPTIONS --without-K #-} module Formalization where open import Agda.Primitive using (lsuc) open import Relation.Binary.PropositionalEquality open Relation.Binary.PropositionalEquality.≡-Reasoning open import Level -- Recall Lemma 1.12 ind₌ : ∀{a b}{A : Set a} → (C : (x y : A) → (x ≡ y) → Set b) → ((x : A) → C x x refl) → {x y : A} → (p : x ≡ y) → C x y p ind₌ C c {x}{y} p rewrite p = c y -- Types are higher groupoids -- -------------------------- -- This is the *central* idea of HoTT. A Type isn't just an atomic entity, it's a homotopic space. -- An ∞-groupoid consists of -- ∘ a collection of objects -- ∘ a collection of morphisms between objects, and then morphisms between morphisms, and so on -- ∘ equipped with some complex algebraic structure -- -- a morphism at level k is called a k- morphism. Morphisms at each level have -- ∘ identity -- ∘ composition -- ∘ inverse operations -- -- which are weak in the sense that they satisfy the groupoid laws (associativity -- of composition, identity is a unit for composition, inverses cancel) only up -- to morphisms at the next level, and this weakness gives rise to further structure. -- Example -- -- Because associativity of composition of morphisms p (q r) = (p q) r is itself a higher-dimensional morphism -- we need additional operators to talk about them. For example: {- Mac Lane's Pentagon --------------------- All the various ways to reassociate p (q (r s)) /- ((p q) r) s -\ / \ (p (q r)) s (p q) (r s) | | | | p ((q r) s) ----------------- p (q (r s)) -} -- Moreover, all of this higher groupoid structure comes automagically from the induction principle -- on Id. -- "Informally, the induction principle for identity types says that if we -- construct an object (or prove a statement) which depends on an inhabitant -- p : x == y of an identity type, data _==_ {i} {A : Set i} (a : A) : A → Set (lsuc i) where idp : a == a -- then it suffices to perform the construction (or the proof) in -- the special case when x and y are the same (judgmentally) -- and p is the reflexivity element reflx : x = x (judgmentally) -- Lemma 2.1.1 "Paths can be reversed" -- first proof _⁻¹ : ∀ {i} {A : Set i}{x y : A} → (x ≡ y) → (y ≡ x) _⁻¹ {i} {A} = λ p → ind₌ D d p where D : (x y : A) → x ≡ y → Set i D = λ x y p → (y ≡ x) d : (x : A) → D x x refl d = λ x → refl -- second proof inv-sym : ∀ {i} {A : Set i}{x y : A} → (x ≡ y) → (y ≡ x) inv-sym refl = refl -- Lemma 2.1.2 & 2.1.3 "paths can be concatenated (strung together)" -- First proof. We need the type family D : Π (x, y : A) Π (p : x ≡ y) → Type. From that we -- produce an element d : D x x reflₓ (simply identity) then apply the induction -- principle above to D and d. composite : ∀ {i} {A : Set i}{x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z) composite {i} {A} {_}{_}{z} p = ind₌ D d p where D : (x y : A) → (p : x ≡ y) → Set i D x y _ = y ≡ z → x ≡ z d : (x₁ : A) → D x₁ x₁ refl d _ = λ x → x -- Second proof. We need the type family D : Π (x, y : A) Π (p : x ≡ y) → Type again. From that -- we produce an element d (x) : D x x reflₓ again, but rather than the identity we go a -- step further and define E : Π (x z : A) Π (q : x ≡ z) → Type. We then produce an -- element e (x) : E x x reflₓ. Induction on D d then unfolds to induction on D then E e. composite' : ∀ {i} {A : Set i}{x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z) composite' {i} {A} {_}{_}{z} = ind₌ D d where D : (x y : A) → (p : x ≡ y) → Set i D x y _ = y ≡ z → x ≡ z d : (x : A) → D x x refl d x = ind₌ E e where E : (x z : A) → (q : x ≡ z) → Set i E x z _ = x ≡ z e : (x : A) → E x x refl e x = refl -- Third proof. Everything is reflexivity you fool. The hell did you do all that work for before? composite'' : ∀ {i} {A : Set i}{x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z) composite'' refl refl = refl -- Equality | Homotopy | ∞-Groupoid -- reflexivity | constant path | identity morphism -- symmetry | inversion of paths | inverse morphism -- transitivity | concatenation of paths | composition of morphisms open import Function -- Lemma 2.1.4 -- These are all propositional equalities living in the type of identity types. -- Topologically they are paths of paths, and we can form a homotopy between them. -- For my next trick, I will need composition of paths -- Reflexivity right lem-1-r : ∀ {i} {A : Set i}{x y : A}{p : x ≡ y} → p ≡ (composite p refl) lem-1-r {i} {A} {x}{y} {p} = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = p ≡ composite p refl d : (x₁ : A) → D x₁ x₁ refl d = λ x → refl -- Reflexivity left lem-1-l : ∀ {i} {A : Set i}{x y : A}{p : x ≡ y} → p ≡ (composite refl p) lem-1-l {i} {A} {x}{y} {p} = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = p ≡ composite refl p d : (x₁ : A) → D x₁ x₁ refl d = λ x → refl lem-2-l : ∀ {i} {A : Set i}{x y : A}{p : x ≡ y} → composite ((p)⁻¹) p ≡ refl lem-2-l {i} {A} {x}{y} {p} = ind₌ D d p where D : (x y : A) → (p : x ≡ y) → Set i D x y p = composite ((p)⁻¹) p ≡ refl d : (x₁ : A) → D x₁ x₁ refl d = λ x → refl lem-2-r : ∀ {i} {A : Set i}{x y : A}{p : x ≡ y} → composite p ((p)⁻¹) ≡ refl lem-2-r {i} {A} {x}{y} {p} = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = composite p ((p)⁻¹) ≡ refl d : (x₁ : A) → D x₁ x₁ refl d = λ x → refl -- Inversion of identity lem-3 : ∀ {i} {A : Set i}{x y : A}{p : x ≡ y} → ((p)⁻¹)⁻¹ ≡ p lem-3 {i} {A} {x}{y} {p} = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = ((p)⁻¹)⁻¹ ≡ p d : (x₁ : A) → D x₁ x₁ refl d = λ _ → refl {- -- Transitivity of identity lem-4 : ∀ {i} {A : Set i}{x y z w : A}{p : x ≡ y}{q : y ≡ z}{r : z ≡ w} → composite p (composite q r) ≡ composite (composite p q) r lem-4 {i} {A} {_}{_}{z} = ind₌ D₁ d₁ where D₁ : (x y : A) → (x ≡ y) → Set i D₁ x y p = (z w : A)(q : y ≡ z)(r : z ≡ w) → composite p (composite q r) ≡ composite (composite p q) r d₁ : (x₁ : A) → D₁ x₁ x₁ refl d₁ _ = ind₌ D₂ d₂ where D₂ : (x z : A) → (q : x ≡ z) → Set i D₂ x z q = (w : A)(r : z ≡ w) → composite refl (composite q r) ≡ composite (composite refl q) r d₂ : (x₂ : A) → D₂ x₂ x₂ refl d₂ _ = ind₌ D₃ d₃ where D₃ : (x w : A) → (r : x ≡ w) → Set i D₃ x w r = (composite refl (composite refl r)) ≡ (composite (composite refl refl) r) d₃ : (x₃ : A) → D₃ x₃ x₃ refl d₃ _ = composite refl (composite refl refl) ≡ composite (composite refl refl) refl -} -- Lemma 2.1.6 open import Data.Product using (Σ ; _,_ ; proj₁ ; proj₂) open import Data.Nat using (ℕ ; suc) -- We need pointed sets for this part Set• : ∀ i → Set _ Set• i = Σ (Set i) λ X → X -- The loop space of a type is -- - A base point -- - A loop (reflexivity) about that point Ω₁ : ∀ {i} → Set• i → Set• i Ω₁ (X , x) = ((x ≡ x) , refl) -- Construct arbitrary n-dimensional loop spaces Ωⁿ : ∀ {i} → ℕ → Set• i → Set• _ Ωⁿ 0 x = x Ωⁿ (suc n) x = Ωⁿ n (Ω₁ x) -- Projects the type from an n-dimensional loop space Ω : ∀ {i} → ℕ → {X : Set i} → X → Set i Ω n {X} x = proj₁ (Ωⁿ n (X , x)) -- Projects the loop from an n-dimensional loop space loop : ∀ {i} n {X : Set i}(x : X) → Ω n x loop n {X} x = proj₂ (Ωⁿ n (X , x)) -- Composition operation on n-dimensional loop spaces _×_ : ∀ {i} n {A : Set i}{x : A} → Ω n x → Ω n x → Ω n x _×_ n {A} {x} x₁ x₂ = loop n x -- 2.2.1 -- We're type theorists, so we like functor-looking things. -- Paths are functor looking things. -- We like paths -- They respect equality and are all continuous-like ap : ∀ {i j} {A : Set i}{B : Set j}{x y : A}{f : A → B} → (x ≡ y) → (f x ≡ f y) ap {i}{j} {A}{B} {x}{y}{f} p = ind₌ D d p where D : (x y : A) → (p : x ≡ y) → Set j D x y p = f x ≡ f y d : (x : A) → D x x refl d = λ x → refl ap₂ : ∀ {i j k} {A : Set i}{B : Set j}{C : Set k}{x x′ : A}{y y′ : B}(f : A → B → C) → (x ≡ x′) → (y ≡ y′) → (f x y ≡ f x′ y′) ap₂ f p q = composite (ap {f = λ _ → f _ _} p) (ap {f = f _} q) ap' : ∀ {i j} {A : Set i}{B : Set j}{x y : A} → (f : A → B) → ((x ≡ y) → (f x ≡ f y)) ap' f refl = refl -- 2.3 -- The dependently typed version of `ap` takes a type family and relates its instantiations with p transport : ∀ {i} {A : Set i}{P : A → Set i}{x y : A} → (p : x ≡ y) → (P x → P y) transport {i} {A}{P} {x}{y} p = ind₌ D d p where D : (x y : A) → (p : x ≡ y) → Set i D x y p = P x → P y d : (x : A) → D x x refl d = λ x → id -- Topologically, we can view transport as a "path lifting" operation -- That is, we lift the path p to a path in the space ∑[ x ∈ A ] P(x) provided we have a -- base point u in the lifted space. -- -- Basically, P respects equality path-lifting : ∀ {a p}{A : Set a}{x y : A}{P : A → Set p} → (u : P x) → (p : x ≡ y) → (x , u) ≡ (y , u) path-lifting = λ {a} {p} {A} {x} {y} {P} u → cong (λ z → z , u) -- Look, transport works in the "upper" space too! apd : ∀ {i} {A : Set i}{P : A → Set i}{f : (x : A) → P x}{x y : A} → (p : x ≡ y) → (transport p (f x) ≡ f y) apd {i} {A}{P} {f}{x}{y} p = ind₌ D d p where D : (x y : A) → (p : x ≡ y) → Set i D x y p = transport p (f x) ≡ f y d : (x : A) → D x x refl d = λ x → refl -- By induction, it suffices to assume p is refl. Because of course it does. apd' : ∀ {i} {A : Set i}{P : A → Set i}{f : (x : A) → P x}{x y : A} → (p : x ≡ y) → (transport p (f x) ≡ f y) apd' refl = refl -- We can also fix B and make transport work like fmap with equalities. transportconst : ∀ {i} {A : Set i}{B : Set i}{P : A → B}{x y : A} → (p : x ≡ y) → (b : B) → transport p b ≡ b transportconst {i} {A}{B}{P} {x}{y} p b = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = transport p b ≡ b d : (x : A) → D x x refl d = λ x → refl {- lem-2-3-8 : ∀ {i} {A : Set i}{B : Set i}{f : A → B}{x y : A} → (p : x ≡ y) → apd p ≡ transportconst (ap p) (f x) lem-2-3-8 {i} {A}{B}{f} {x}{y} p = ind₌ D d p where D : (x y : A) → (x ≡ y) → Set i D x y p = apd p ≡ transportconst (f x) ∘ ap p d : (x : A) → D x x refl d = refl -} {- lem-2-3-9 : ∀ {i} {A : Set i}{P : A → Set i}{x y z : A} → (p : x ≡ y) → (q : y ≡ z) → (u : P x) → transport q (transport p u) ≡ transport (p ∘ q) u lem-2-3-9 = ? -} -- Homotopies -- Under Propositions-as-Types two functions are the same if they give the same outputs on the -- same inputs. Which looks like this: a type whose terms are proofs of that^ _∼_ : ∀ {a b} {A : Set a}{P : A → Set b} → (f g : (x : A) → P x) → Set (a ⊔ b) _∼_ {a}{b} {A}{P} f g = (x : A) → f x ≡ g x -- 2.4.2 lem-2-4-2 : ∀ {a} {A : Set a}{B : Set a} → (f : A → B) → f ∼ f lem-2-4-2 f = λ _ → refl lem-2-4-2' : ∀ {a} {A : Set a}{B : Set a} → (f g : A → B) → (f ∼ g) → (g ∼ f) lem-2-4-2' f g x x₁ = sym (x x₁) -- For any A and B, a quasi-inverse of f is a triple with -- ∘ A way back (an inverse for the homomorphism) -- ∘ Homotopies: -- ⊚ α : f ∘ g ∼ id -- ⊚ β : g ∘ f ∼ id -- For now, because I am lazy, the presence of a quasi-inverse will count -- as our definition of equivalence for now. Sorry. record IsEquiv {i j}{A : Set i}{B : Set j}(to : A → B) : Set (i ⊔ j) where field from : B → A iso₁ : (x : A) → from (to x) ≡ x iso₂ : (y : B) → to (from y) ≡ y -- Example 2.4.7: Identity is an equivalence. id-is-equiv : ∀ {i} (A : Set i) → IsEquiv (id {i}{A}) id-is-equiv {i} A = record { from = id {i}{A} ; iso₁ = λ _ → refl ; iso₂ = λ _ → refl } -- Type equivalence is also an equivalence, just on the Universe because: -- ∘ id-is-equiv works for it, therefore A ≃ A -- ∘ With A ≃ B, we can always make B ≃ A -- ∘ With A ≃ B and B ≃ C we have A ≃ C _≃_ : ∀ {i j} (A : Set i) (B : Set j) → Set (i ⊔ j) A ≃ B = Σ (A → B) IsEquiv open import Data.Product renaming (_×_ to _×p_) split-path : ∀ {i j}{A : Set i}{B : Set j}{x y : A ×p B} → x ≡ y → (proj₁ x ≡ proj₁ y) ×p (proj₂ x ≡ proj₂ y) split-path p = ap {f = proj₁} p , ap {f = proj₂} p pair₌ : ∀ {i j}{A : Set i}{B : Set j}{x y : A ×p B} → (proj₁ x ≡ proj₁ y) ×p (proj₂ x ≡ proj₂ y) → x ≡ y pair₌ (p , q) = ap₂ _,_ p q instance split-is-equiv : ∀ {i j}{A : Set i}{B : Set j}{x y : A ×p B} → IsEquiv (pair₌ {x = x}{y = y}) split-is-equiv {x = x}{y = y} = record { from = split-path ; iso₁ = λ pq → ind₌ (λ _ _ p → ∀ {b₁ b₂} (q : b₁ ≡ b₂) → split-path (pair₌ (p , q)) ≡ (p , q)) (λ _ q → ind₌ (λ _ _ q → split-path (pair₌ (refl , q)) ≡ (refl , q)) (λ _ → refl) q) (proj₁ pq) (proj₂ pq) ; iso₂ = ind₌ (λ _ _ p → pair₌ (split-path p) ≡ p) (λ _ → refl) } {- happly : ∀ {i}{A : Set i}{f g : A → Set i} → (f ≡ g) → ((x : A) → f x ≡ g x) happly p x = ap' (λ u → u x) -} -- 2.10 -- This says, when you get down to it, id on universes is a -- type family with a total space of pointed types. Turns out -- Ω isn't just for horses. idtoeqv : ∀ {i} {A : Set i}{B : Set i} → (A ≡ B) → (A ≃ B) idtoeqv {_}{A} refl = (id , id-is-equiv A) -- With idtoeqv in hand, we have to ask Agda nicely to make idtoeqv an equivalence. postulate -- Just kidding ua : ∀ {i} {A : Set i}{B : Set i} → (A ≃ B) ≃ (A ≡ B) -- ^This says "equivalent types may be identified" -- 2.12 {- data _⊎_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where inl : (x : A) → A ⊎ B inr : (y : B) → A ⊎ B code : ∀ {a b}{{A : Set a}}{{B : Set b}} → A ⊎ B → Set (a ⊔ b) code (inl a) = ? code (inr b) = ⊥ code-lem : ∀ {a b}{{A : Set a}}{{B : Set b}} → (x : A ⊎ B) → (a₀ : A) → ((inl a₀ ≡ x) ≃ code x) code-lem {{A}} {{B}} x a₀ = ? where encode : (x : A ⊎ B) → (p : inl a₀ ≡ x) → code x encode x p = transport p refl decode : (x : A ⊎ B) → (c : code x) → inl a₀ ≡ x decode x c = ? -} open import Data.Nat open import Data.Unit open import Data.Empty code : ℕ → ℕ → Set code ℕ.zero ℕ.zero = ⊤ code ℕ.zero (ℕ.suc m) = ⊥ code (ℕ.suc n) ℕ.zero = ⊥ code (ℕ.suc n) (ℕ.suc m) = code n m -- 2.13 natcode-lem : ∀ {m n : ℕ} → (m ≡ n) → code m n natcode-lem {x}{y} p = encode {x}{y} p where encode : ∀ {m n : ℕ} → (m ≡ n) → code m n encode {m}{n} p = transport p (r m) where r : (n : ℕ) → code n n r ℕ.zero = tt r (ℕ.suc n) = r n decode : ∀ {m n : ℕ} → code m n → (m ≡ n) decode {ℕ.zero} {ℕ.zero} tt = refl decode {ℕ.zero} {ℕ.suc _} () decode {ℕ.suc _} {ℕ.zero} () decode {ℕ.suc m} {ℕ.suc n} c = cong ℕ.suc (decode c) enc-dec-quasi : ∀ {n : ℕ} → decode {n}{n} (encode {n}{n} refl) ≡ refl enc-dec-quasi {ℕ.zero} = refl enc-dec-quasi {ℕ.suc n₁} = {! !}
{ "alphanum_fraction": 0.5139235385, "avg_line_length": 34.0160550459, "ext": "agda", "hexsha": "3748ed6d4c6858ea4bbe42c3939f826bca8edf79", "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": "3411b253b0a49a5f9c3301df175ae8ecdc563b12", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CodaFi/HoTT-Exercises", "max_forks_repo_path": "Chapter2/Formalization.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12", "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": "CodaFi/HoTT-Exercises", "max_issues_repo_path": "Chapter2/Formalization.agda", "max_line_length": 147, "max_stars_count": null, "max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CodaFi/HoTT-Exercises", "max_stars_repo_path": "Chapter2/Formalization.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6057, "size": 14831 }
module UniDB.Morph.WeakenOne where open import UniDB.Spec -------------------------------------------------------------------------------- data Weaken₁ : MOR where weaken₁ : {γ : Dom} → Weaken₁ γ (suc γ) instance iLkWeaken₁ : {T : STX} {{vrT : Vr T}} → Lk T Weaken₁ lk {{iLkWeaken₁ {T}}} weaken₁ i = vr {T} (suc i) iLkRenWeaken₁ : {T : STX} {{vrT : Vr T}} → LkRen T Weaken₁ lk-ren {{iLkRenWeaken₁}} weaken₁ i = refl --------------------------------------------------------------------------------
{ "alphanum_fraction": 0.4338521401, "avg_line_length": 27.0526315789, "ext": "agda", "hexsha": "94e666464e991873ccf6de5d6b89c370e3f40989", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "skeuchel/unidb-agda", "max_forks_repo_path": "UniDB/Morph/WeakenOne.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "skeuchel/unidb-agda", "max_issues_repo_path": "UniDB/Morph/WeakenOne.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "skeuchel/unidb-agda", "max_stars_repo_path": "UniDB/Morph/WeakenOne.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 155, "size": 514 }
------------------------------------------------------------------------ -- A type for values that should be erased at run-time ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Equality import Erased.Basics import Erased.Level-1 module Erased {c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) (ax : ∀ {ℓ} → Erased.Level-1.[]-cong-axiomatisation eq ℓ) where -- Re-exported definitions. private module E₁ = Erased.Level-1 eq open E₁ public hiding (module Erased-cong; module []-cong; module []-cong₁; module []-cong₂; module []-cong₂-⊔; module Extensionality) open E₁.[]-cong ax public import Erased.Level-2 eq as E₂ open E₂.[]-cong ax public open import Erased.Stability eq as ES public hiding (module []-cong; module []-cong₁; module []-cong₁-lsuc; module []-cong₂; module []-cong₂-⊔₁; module []-cong₂-⊔₂; module Extensionality) open ES.[]-cong ax public
{ "alphanum_fraction": 0.5415841584, "avg_line_length": 28.0555555556, "ext": "agda", "hexsha": "935ff0410d6d2a6ad4e6dcff45cd835a67e385bd", "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/Erased.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/Erased.agda", "max_line_length": 72, "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/Erased.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": 293, "size": 1010 }
open import Common.Level postulate ℓ : Level data D : Set (lsuc ℓ) where c : (ℓ : Level) → Set ℓ → D -- Bad error: -- The type of the constructor does not fit in the sort of the -- datatype, since Set (lsuc ℓ) is not less or equal than Set (lsuc ℓ) -- when checking the constructor c in the declaration of D -- Jesper, 2018-12-09: new, better error: -- Set (lsuc ℓ₁) is not less or equal than Set (lsuc ℓ) -- when checking that the type (ℓ₁ : Level) → Set ℓ₁ → D of the -- constructor c fits in the sort Set (lsuc ℓ) of the datatype.
{ "alphanum_fraction": 0.6789667897, "avg_line_length": 30.1111111111, "ext": "agda", "hexsha": "c1163ee313a4e6748cfb422b034688148d97444a", "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/Issue998e.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/Issue998e.agda", "max_line_length": 70, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue998e.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": 177, "size": 542 }
open import Data.Bool using ( Bool ; true ; false ; if_then_else_ ) open import Data.Product using ( _×_ ; _,_ ) open import Data.Sum using ( inj₁ ; inj₂ ) open import Relation.Unary using ( _∈_ ) open import Web.Semantic.DL.Concept using ( Concept ; ⟨_⟩ ; ¬⟨_⟩ ; ⊤ ; ⊥ ; _⊓_ ; _⊔_ ; ∀[_]_ ; ∃⟨_⟩_ ; ≤1 ; >1 ; neg ) open import Web.Semantic.DL.Concept.Model using ( _⟦_⟧₁ ; ⟦⟧₁-resp-≈ ) open import Web.Semantic.DL.FOL using ( Formula ; true ; false ; _∧_ ; _∈₁_ ; _∈₂_ ; _∈₁_⇒_ ; _∼_ ; _∼_⇒_ ; ∀₁ ) open import Web.Semantic.DL.FOL.Model using ( _⊨f_ ) open import Web.Semantic.DL.Role.Skolemization using ( rskolem ; rskolem⇒ ; rskolem-sound ; rskolem⇒-sound ) open import Web.Semantic.DL.Signature using ( Signature ) open import Web.Semantic.Util using ( True ; tt ) module Web.Semantic.DL.Concept.Skolemization {Σ : Signature} where CSkolems : Set → Concept Σ → Set CSkolems Δ ⟨ c ⟩ = True CSkolems Δ ¬⟨ c ⟩ = True CSkolems Δ ⊤ = True CSkolems Δ ⊥ = True CSkolems Δ (C ⊓ D) = (CSkolems Δ C) × (CSkolems Δ D) CSkolems Δ (C ⊔ D) = (Δ → Bool) × (CSkolems Δ C) × (CSkolems Δ D) CSkolems Δ (∀[ R ] C) = CSkolems Δ C CSkolems Δ (∃⟨ R ⟩ C) = (Δ → Δ) × (CSkolems Δ C) CSkolems Δ (≤1 R) = True CSkolems Δ (>1 R) = (Δ → Δ) × (Δ → Δ) cskolem : ∀ {Δ} C → (CSkolems Δ C) → Δ → Formula Σ Δ cskolem ⟨ c ⟩ Φ x = x ∈₁ c cskolem ¬⟨ c ⟩ Φ x = x ∈₁ c ⇒ false cskolem ⊤ Φ x = true cskolem ⊥ Φ x = false cskolem (C ⊓ D) (Φ , Ψ) x = (cskolem C Φ x) ∧ (cskolem D Ψ x) cskolem (C ⊔ D) (φ , Φ , Ψ) x = if (φ x) then (cskolem C Φ x) else (cskolem D Ψ x) cskolem (∀[ R ] C) Φ x = ∀₁ λ y → rskolem⇒ R x y (cskolem C Φ y) cskolem (∃⟨ R ⟩ C) (φ , Ψ) x = (rskolem R x (φ x)) ∧ (cskolem C Ψ (φ x)) cskolem (≤1 R) Φ x = ∀₁ λ y → ∀₁ λ z → rskolem⇒ R x y (rskolem⇒ R x z (y ∼ z)) cskolem (>1 R) (φ , ψ) x = (rskolem R x (φ x)) ∧ (rskolem R x (ψ x)) ∧ (φ x ∼ ψ x ⇒ false) cskolem-sound : ∀ I C Φ x → (I ⊨f cskolem C Φ x) → (x ∈ I ⟦ C ⟧₁) cskolem-sound I ⟨ c ⟩ Φ x x∈⟦c⟧ = x∈⟦c⟧ cskolem-sound I ¬⟨ c ⟩ Φ x x∉⟦c⟧ = x∉⟦c⟧ cskolem-sound I ⊤ Φ x _ = tt cskolem-sound I ⊥ Φ x () cskolem-sound I (C ⊓ D) (Φ , Ψ) x (Fx , Gx) = (cskolem-sound I C Φ x Fx , cskolem-sound I D Ψ x Gx) cskolem-sound I (C ⊔ D) (φ , Φ , Ψ) x F∨Gx with φ x cskolem-sound I (C ⊔ D) (φ , Φ , Ψ) x Fx | true = inj₁ (cskolem-sound I C Φ x Fx) cskolem-sound I (C ⊔ D) (φ , Φ , Ψ) x Gx | false = inj₂ (cskolem-sound I D Ψ x Gx) cskolem-sound I (∀[ R ] C) Φ x ∀RFx = λ y xy∈R → cskolem-sound I C Φ y (rskolem⇒-sound I R x y (cskolem C Φ y) (∀RFx y) xy∈R) cskolem-sound I (∃⟨ R ⟩ C) (φ , Ψ) x (xy∈R , Fy) = ( φ x , rskolem-sound I R x (φ x) xy∈R , cskolem-sound I C Ψ (φ x) Fy ) cskolem-sound I (≤1 R) Φ x ≤1Rx = λ y z xy∈R xz∈R → rskolem⇒-sound I R x z (y ∼ z) (rskolem⇒-sound I R x y (rskolem⇒ R x z (y ∼ z)) (≤1Rx y z) xy∈R) xz∈R cskolem-sound I (>1 R) (φ , ψ) x (xy∈R , xz∈R , y≁z) = (φ x , ψ x , rskolem-sound I R x (φ x) xy∈R , rskolem-sound I R x (ψ x) xz∈R , y≁z)
{ "alphanum_fraction": 0.5739665186, "avg_line_length": 51.350877193, "ext": "agda", "hexsha": "95923342f8a779e57a853091cf90ee8557e23e09", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z", "max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z", "max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-web-semantic", "max_forks_repo_path": "src/Web/Semantic/DL/Concept/Skolemization.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057", "max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bblfish/agda-web-semantic", "max_issues_repo_path": "src/Web/Semantic/DL/Concept/Skolemization.agda", "max_line_length": 118, "max_stars_count": 9, "max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/agda-web-semantic", "max_stars_repo_path": "src/Web/Semantic/DL/Concept/Skolemization.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z", "num_tokens": 1512, "size": 2927 }
{-# OPTIONS --allow-unsolved-metas #-} module finiteSet where open import Data.Nat hiding ( _≟_ ) open import Data.Fin renaming ( _<_ to _<<_ ) hiding (_≤_) -- open import Data.Fin.Properties hiding ( ≤-refl ) open import Data.Empty open import Relation.Nullary open import Relation.Binary.Definitions open import Relation.Binary.PropositionalEquality open import logic open import nat open import Data.Nat.Properties hiding ( _≟_ ) open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ ) record FiniteSet ( Q : Set ) : Set where field finite : ℕ Q←F : Fin finite → Q F←Q : Q → Fin finite finiso→ : (q : Q) → Q←F ( F←Q q ) ≡ q finiso← : (f : Fin finite ) → F←Q ( Q←F f ) ≡ f exists1 : (m : ℕ ) → m Data.Nat.≤ finite → (Q → Bool) → Bool exists1 zero _ _ = false exists1 ( suc m ) m<n p = p (Q←F (fromℕ< {m} {finite} m<n)) \/ exists1 m (<to≤ m<n) p exists : ( Q → Bool ) → Bool exists p = exists1 finite ≤-refl p open import Data.List list1 : (m : ℕ ) → m Data.Nat.≤ finite → (Q → Bool) → List Q list1 zero _ _ = [] list1 ( suc m ) m<n p with bool-≡-? (p (Q←F (fromℕ< {m} {finite} m<n))) true ... | yes _ = Q←F (fromℕ< {m} {finite} m<n) ∷ list1 m (<to≤ m<n) p ... | no _ = list1 m (<to≤ m<n) p to-list : ( Q → Bool ) → List Q to-list p = list1 finite ≤-refl p equal? : Q → Q → Bool equal? q0 q1 with F←Q q0 ≟ F←Q q1 ... | yes p = true ... | no ¬p = false
{ "alphanum_fraction": 0.5647291942, "avg_line_length": 35.2093023256, "ext": "agda", "hexsha": "0d3fa289a73778f14a3a1bb7a3a7f21e341a7672", "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": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "shinji-kono/automaton-in-agda", "max_forks_repo_path": "src/finiteSet.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "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/automaton-in-agda", "max_issues_repo_path": "src/finiteSet.agda", "max_line_length": 90, "max_stars_count": null, "max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "shinji-kono/automaton-in-agda", "max_stars_repo_path": "src/finiteSet.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 537, "size": 1514 }
import cedille-options open import general-util module spans (options : cedille-options.options) {mF : Set → Set} {{mFm : monad mF}} where open import cedille-types open import constants open import conversion open import ctxt open import free-vars open import syntax-util open import type-util open import to-string options open import subst open import datatype-util open import json -------------------------------------------------- -- span datatype -------------------------------------------------- err-m : Set err-m = maybe string data span : Set where mk-span : string → posinfo → posinfo → 𝕃 tagged-val {- extra information for the span -} → err-m → span span-to-json : span → json span-to-json (mk-span name s e tvs err?) = json-array $ json-string name :: json-raw [[ s ]] :: json-raw [[ e ]] :: [ tagged-vals-to-json (maybe-else' err? tvs λ err → ("error" , [[ err ]] , []) :: tvs) ] data error-span : Set where mk-error-span : string → posinfo → posinfo → 𝕃 tagged-val → string → error-span data spans : Set where regular-spans : maybe error-span → 𝕃 span → spans global-error : string {- error message -} → maybe span → spans is-error-span : span → 𝔹 is-error-span (mk-span _ _ _ _ err) = isJust err get-span-error : span → err-m get-span-error (mk-span _ _ _ _ err) = err get-spans-error : spans → maybe (string × 𝕃 tagged-val) get-spans-error (global-error e _) = just $ e , [] get-spans-error (regular-spans e? _) = maybe-map (λ {(mk-error-span _ _ _ tvs e) → e , tvs}) e? get-tagged-vals : span → 𝕃 tagged-val get-tagged-vals (mk-span _ _ _ tvs _) = tvs spans-have-error : spans → 𝔹 spans-have-error (regular-spans es ss) = isJust es spans-have-error (global-error _ _) = tt empty-spans : spans empty-spans = regular-spans nothing [] spans-to-json' : spans → 𝕃 (string × json) spans-to-json' (regular-spans _ ss) = [ "spans" , json-array (map span-to-json ss) ] spans-to-json' (global-error e s) = ("error" , json-string e) :: maybe-else' s [] λ s → [ "global-error" , span-to-json s ] spans-to-json : spans → json spans-to-json = json-object ∘ spans-to-json' print-file-id-table : ctxt → 𝕃 tagged-val print-file-id-table Γ = h [] (ctxt.id-list Γ) where h : ∀ {i} → 𝕃 tagged-val → 𝕍 string i → 𝕃 tagged-val h ts [] = ts h {i} ts (fn :: fns) = h (strRunTag "fileid" empty-ctxt (strAdd fn) :: ts) fns add-span : span → spans → spans add-span s@(mk-span dsc pi pi' tv nothing) (regular-spans es ss) = regular-spans es (s :: ss) add-span s@(mk-span dsc pi pi' tv (just err)) (regular-spans es ss) = regular-spans (just (mk-error-span dsc pi pi' tv err)) (s :: ss) add-span s (global-error e e') = global-error e e' -------------------------------------------------- -- spanM, a state monad for spans -------------------------------------------------- spanM : Set → Set spanM A = spans → mF (A × spans) instance spanM-monad : monad spanM return ⦃ spanM-monad ⦄ = curry return _>>=_ ⦃ spanM-monad ⦄ m₁ m₂ ss = m₁ ss >>= uncurry m₂ spanM-functor : functor spanM fmap ⦃ spanM-functor ⦄ g m ss = m ss >>= uncurry λ a ss' → return (g a , ss') spanM-applicative : applicative spanM pure ⦃ spanM-applicative ⦄ = return _<*>_ ⦃ spanM-applicative ⦄ mab ma ss = mab ss >>= uncurry λ f ss₁ → ma ss₁ >>= uncurry λ a → return (f a) spanMok : spanM ⊤ spanMok = return triv get-error : ∀ {A : Set} → (maybe error-span → spanM A) → spanM A get-error m ss@(global-error _ _) = m nothing ss get-error m ss@(regular-spans nothing _) = m nothing ss get-error m ss@(regular-spans (just es) _) = m (just es) ss set-error : maybe (error-span) → spanM ⊤ set-error es ss@(global-error _ _) = return2 triv ss set-error es (regular-spans _ ss) = return2 triv (regular-spans es ss) spanM-push : ∀ {A} → mF A → spanM A spanM-push mf ss = mf >>= λ a → return2 a ss -- discard changes made by the first computation _>>=spand_ : ∀{A B : Set} → spanM A → (A → spanM B) → spanM B _>>=spand_{A} m m' ss = m ss >>= λ where (v , _) → m' v ss spanM-add : span → spanM ⊤ spanM-add s ss = return (triv , add-span s ss) infixr 2 [-_-]_ [-_-]_ : ∀ {X} → span → spanM X → spanM X [- s -] m = spanM-add s >> m debug-span : posinfo → posinfo → 𝕃 tagged-val → span debug-span pi pi' tvs = mk-span "Debug" pi pi' tvs nothing spanM-debug : posinfo → posinfo → 𝕃 tagged-val → spanM ⊤ --spanM-debug pi pi' tvs = spanM-add (debug-span pi pi' tvs) spanM-debug pi pi' tvs = spanMok check-ret : ∀ {Y : Set} → maybe Y → Set → Set check-ret {Y} T t = if isJust T then t else (t × Y) return-when : ∀ {X Y} {m : maybe Y} → X → Y → spanM (check-ret m X) return-when {X} {Y} {nothing} x u = return2 x u return-when {X} {Y} {just _} x u = return x case-ret : ∀ {X Y} {m : maybe Y} → spanM (X × Y) → (Y → spanM X) → spanM (check-ret m X) case-ret {X} {Y} {nothing} n j = n case-ret {X} {Y} {just y} n j = j y case-ret-body : ∀ {X Y} {m : maybe Y} → spanM (check-ret m X) → (X → Y → spanM (check-ret m X)) → spanM (check-ret m X) case-ret-body {X} {Y} {nothing} m f = m >>= uncurry f case-ret-body {X} {Y} {just y} m f = m >>= λ x → f x y with-clear-error : ∀ {A} → spanM A → spanM A with-clear-error m = get-error λ es → set-error nothing >> m >>= λ a → set-error es >> return a -------------------------------------------------- -- tagged-val constants -------------------------------------------------- to-string-tag-tk : (tag : string) → ctxt → tpkd → tagged-val to-string-tag-tk t Γ (Tkt T) = to-string-tag t Γ T to-string-tag-tk t Γ (Tkk k) = to-string-tag t Γ k location-data : location → tagged-val location-data (file-name , pi) = strRunTag "location" empty-ctxt (strAdd file-name >>str strAdd " - " >>str strAdd pi) var-location-data : ctxt → var → tagged-val var-location-data Γ x = location-data (maybe-else missing-location snd (trie-lookup (ctxt.i Γ) x ||-maybe trie-lookup (ctxt.i Γ) (qualif-var Γ x))) explain : string → tagged-val explain = strRunTag "explanation" empty-ctxt ∘ strAdd reason : string → tagged-val reason = strRunTag "reason" empty-ctxt ∘ strAdd expected-type : ctxt → type → tagged-val expected-type = to-string-tag "expected-type" expected-type-subterm : ctxt → type → tagged-val expected-type-subterm = to-string-tag "expected-type of the subterm" missing-expected-type : tagged-val missing-expected-type = strRunTag "expected-type" empty-ctxt $ strAdd "[missing]" expected-kind : ctxt → kind → tagged-val expected-kind = to-string-tag "expected kind" expected-kind-if : ctxt → maybe kind → 𝕃 tagged-val expected-kind-if _ nothing = [] expected-kind-if Γ (just k) = [ expected-kind Γ k ] expected-type-if : ctxt → maybe type → 𝕃 tagged-val expected-type-if _ nothing = [] expected-type-if Γ (just tp) = [ expected-type Γ tp ] type-data : ctxt → type → tagged-val type-data = to-string-tag "type" type-data-if : ctxt → maybe type → 𝕃 tagged-val type-data-if Γ = maybe-else [] λ T → [ type-data Γ T ] warning-data : string → tagged-val warning-data = strRunTag "warning" empty-ctxt ∘ strAdd check-for-type-mismatch : ctxt → string → type → type → err-m check-for-type-mismatch Γ s tp tp' = if conv-type Γ tp tp' then nothing else just ("The expected type does not match the " ^ s ^ " type") check-for-type-mismatch-if : ctxt → string → maybe type → type → err-m check-for-type-mismatch-if Γ s T? T = T? >>= check-for-type-mismatch Γ s T check-for-kind-mismatch : ctxt → string → kind → kind → err-m check-for-kind-mismatch Γ s kd kd' = if conv-kind Γ kd kd' then nothing else just ("The expected kind does not match the " ^ s ^ " kind") check-for-kind-mismatch-if : ctxt → string → maybe kind → kind → err-m check-for-kind-mismatch-if Γ s k? k = k? >>= check-for-kind-mismatch Γ s k check-for-tpkd-mismatch-if : ctxt → string → maybe tpkd → tpkd → err-m check-for-tpkd-mismatch-if Γ check tk? tk = tk? >>= either-else (either-else' tk (check-for-type-mismatch Γ check) λ kd tp → just "Expected a kind classifier, but got a type") (either-else' tk (λ tp kd → just "Expected a type classifier, but got a kind") (check-for-kind-mismatch Γ check)) summary-data : {ed : exprd} → (name : string) → ctxt → ⟦ ed ⟧ → tagged-val summary-data name Γ t = strRunTag "summary" Γ (strVar name >>str strAdd " : " >>str to-stringe t) head-kind : ctxt → kind → tagged-val head-kind = to-string-tag "the kind of the head" head-type : ctxt → type → tagged-val head-type = to-string-tag "the type of the head" arg-type : ctxt → type → tagged-val arg-type = to-string-tag "computed arg type" arg-exp-type : ctxt → type → tagged-val arg-exp-type = to-string-tag "expected arg type" type-app-head : ctxt → type → tagged-val type-app-head = to-string-tag "the head" term-app-head : ctxt → term → tagged-val term-app-head = to-string-tag "the head" term-argument : ctxt → term → tagged-val term-argument = to-string-tag "the argument" type-argument : ctxt → type → tagged-val type-argument = to-string-tag "the argument" contextual-type-argument : ctxt → type → tagged-val contextual-type-argument = to-string-tag "contextual type arg" arg-argument : ctxt → arg → tagged-val arg-argument Γ = either-else (term-argument Γ) (type-argument Γ) ∘ arg-to-tmtp kind-data : ctxt → kind → tagged-val kind-data = to-string-tag "kind" kind-data-if : ctxt → maybe kind → 𝕃 tagged-val kind-data-if Γ (just k) = [ kind-data Γ k ] kind-data-if _ nothing = [] super-kind-data : tagged-val super-kind-data = strRunTag "superkind" empty-ctxt $ strAdd "□" symbol-data : string → tagged-val symbol-data = strRunTag "symbol" empty-ctxt ∘ strAdd tk-data : ctxt → tpkd → tagged-val tk-data Γ (Tkk k) = kind-data Γ k tk-data Γ (Tkt t) = type-data Γ t checking-to-string : checking-mode → string checking-to-string checking = "checking" checking-to-string synthesizing = "synthesizing" checking-to-string untyped = "untyped" checking-data : checking-mode → tagged-val checking-data = strRunTag "checking-mode" empty-ctxt ∘' strAdd ∘' checking-to-string checked-meta-var : var → tagged-val checked-meta-var = strRunTag "checked meta-var" empty-ctxt ∘ strAdd ll-data : exprd → tagged-val ll-data = strRunTag "language-level" empty-ctxt ∘' strAdd ∘' exprd-name ll-data-term = ll-data TERM ll-data-type = ll-data TYPE ll-data-kind = ll-data KIND binder-data : ctxt → posinfo → var → (atk : tpkd) → erased? → maybe (if tk-is-type atk then term else type) → (from to : posinfo) → tagged-val binder-data Γ pi x atk me val s e = strRunTag "binder" Γ $ strAdd "symbol:" >>str strAdd x >>str atk-val atk val >>str strAdd "§from:" >>str strAdd s >>str strAdd "§to:" >>str strAdd e >>str loc >>str strErased? where loc : strM loc = strAdd "§fn:" >>str strAdd (ctxt.fn Γ) >>str strAdd "§pos:" >>str strAdd pi strErased? : strM strErased? = strAdd "§erased:" >>str strAdd (if me then "true" else "false") val? : ∀ {ed} → maybe ⟦ ed ⟧ → strM val? = maybe-else strEmpty λ x → strAdd "§value:" >>str to-stringe x atk-val : (atk : tpkd) → maybe (if tk-is-type atk then term else type) → strM atk-val (Tkt T) t? = strAdd "§type:" >>str to-stringe T >>str val? t? atk-val (Tkk k) T? = strAdd "§kind:" >>str to-stringe k >>str val? T? punctuation-data : tagged-val punctuation-data = strRunTag "punctuation" empty-ctxt $ strAdd "true" not-for-navigation : tagged-val not-for-navigation = strRunTag "not-for-navigation" empty-ctxt $ strAdd "true" is-erased : type → 𝔹 is-erased (TpVar _) = tt is-erased _ = ff keywords = "keywords" keyword-application = "application" keyword-locale = "meta-var-locale" keywords-data : 𝕃 string → tagged-val keywords-data kws = keywords , h kws , [] where h : 𝕃 string → rope h [] = [[]] h (k :: []) = [[ k ]] h (k :: ks) = [[ k ]] ⊹⊹ [[ " " ]] ⊹⊹ h ks keywords-app : (is-locale : 𝔹) → tagged-val keywords-app l = keywords-data ([ keyword-application ] ++ (if l then [ keyword-locale ] else [])) keywords-app-if-typed : checking-mode → (is-locale : 𝔹) → 𝕃 tagged-val keywords-app-if-typed untyped l = [] keywords-app-if-typed _ l = [ keywords-app l ] error-if-not-eq : ctxt → type → 𝕃 tagged-val → 𝕃 tagged-val × err-m error-if-not-eq Γ (TpEq t1 t2) tvs = expected-type Γ (TpEq t1 t2) :: tvs , nothing error-if-not-eq Γ tp tvs = expected-type Γ tp :: tvs , just "This term is being checked against the following type, but an equality type was expected" error-if-not-eq-maybe : ctxt → maybe type → 𝕃 tagged-val → 𝕃 tagged-val × err-m error-if-not-eq-maybe Γ (just tp) = error-if-not-eq Γ tp error-if-not-eq-maybe _ _ tvs = tvs , nothing params-data : ctxt → params → 𝕃 tagged-val params-data _ [] = [] params-data Γ ps = [ params-to-string-tag "parameters" Γ ps ] -------------------------------------------------- -- span-creating functions -------------------------------------------------- Star-name : string Star-name = "Star" parens-span : posinfo → posinfo → span parens-span pi pi' = mk-span "parentheses" pi pi' [] nothing data decl-class : Set where decl-param : decl-class decl-index : decl-class decl-class-name : decl-class → string decl-class-name decl-param = "parameter" decl-class-name decl-index = "index" Decl-span : ctxt → decl-class → posinfo → posinfo → var → tpkd → erased? → posinfo → posinfo → span Decl-span Γ dc pi pi' v atk me pi'' pi''' = mk-span ((if tk-is-type atk then "Term " else "Type ") ^ (decl-class-name dc)) pi pi''' [ binder-data Γ pi' v atk me nothing pi'' pi''' ] nothing TpVar-span : ctxt → posinfo → string → checking-mode → 𝕃 tagged-val → err-m → span TpVar-span Γ pi v check tvs = mk-span name pi (posinfo-plus-str pi (unqual-local v)) (checking-data check :: ll-data-type :: var-location-data Γ v :: symbol-data (unqual-local v) :: tvs) where v' = unqual-local v name = if stringset-contains (ctxt.μ̲ Γ) (qualif-var Γ v) then "Datatype variable" else "Type variable" Var-span : ctxt → posinfo → string → checking-mode → 𝕃 tagged-val → err-m → span Var-span Γ pi v check tvs = mk-span name pi (posinfo-plus-str pi v') (checking-data check :: ll-data-term :: var-location-data Γ v :: symbol-data v' :: tvs) where v' = unqual-local v name : string name with qual-lookup Γ v' ...| just (_ , _ , ctr-def _ _ _ _ _ , _) = "Constructor variable" ...| _ = "Term variable" KdVar-span : ctxt → (posinfo × var) → (end-pi : posinfo) → params → checking-mode → 𝕃 tagged-val → err-m → span KdVar-span Γ (pi , v) pi' ps check tvs = mk-span "Kind variable" pi pi' (checking-data check :: ll-data-kind :: var-location-data Γ v :: symbol-data (unqual-local v) :: super-kind-data :: (params-data Γ ps ++ tvs)) var-span-with-tags : erased? → ctxt → posinfo → string → checking-mode → tpkd → 𝕃 tagged-val → err-m → span var-span-with-tags _ Γ pi x check (Tkk k) tags = TpVar-span Γ pi x check ({-keywords-data-var ff ::-} [ kind-data Γ k ] ++ tags) var-span-with-tags e Γ pi x check (Tkt t) tags = Var-span Γ pi x check ({-keywords-data-var e ::-} [ type-data Γ t ] ++ tags) var-span : erased? → ctxt → posinfo → string → checking-mode → tpkd → err-m → span var-span e Γ pi x check tk = var-span-with-tags e Γ pi x check tk [] redefined-var-span : ctxt → posinfo → var → span redefined-var-span Γ pi x = mk-span "Variable definition" pi (posinfo-plus-str pi x) [ var-location-data Γ x ] (just "This symbol was defined already") TpAppt-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span TpAppt-span pi pi' check tvs = mk-span "Application of a type to a term" pi pi' (checking-data check :: ll-data-type :: tvs) TpApp-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span TpApp-span pi pi' check tvs = mk-span "Application of a type to a type" pi pi' (checking-data check :: ll-data-type :: tvs) App-span : (is-locale : 𝔹) → posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span App-span l pi pi' check tvs = mk-span "Application of a term to a term" pi pi' (checking-data check :: ll-data-term :: keywords-app-if-typed check l ++ tvs) AppTp-span : (is-locale : 𝔹) → posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span AppTp-span l pi pi' check tvs = mk-span "Application of a term to a type" pi pi' (checking-data check :: ll-data-term :: keywords-app-if-typed check l ++ tvs) TpQuant-span : ctxt → erased? → posinfo → posinfo → var → tpkd → ex-tp → checking-mode → 𝕃 tagged-val → err-m → span TpQuant-span Γ me pi pi' x atk body check tvs err = let err-if-type-pi = ifMaybej ( ~ (tk-is-type atk || me)) "Π-types must bind a term, not a type (use ∀ instead)" name = if me then "Implicit dependent function type" else "Dependent function type" in mk-span name pi (type-end-pos body) (checking-data check :: ll-data-type :: binder-data Γ pi' x atk me nothing (type-start-pos body) (type-end-pos body) :: tvs) (if isJust err-if-type-pi then err-if-type-pi else err) TpLambda-span : ctxt → posinfo → posinfo → var → tpkd → ex-tp → checking-mode → 𝕃 tagged-val → err-m → span TpLambda-span Γ pi pi' x atk body check tvs = mk-span "Type-level lambda abstraction" pi (type-end-pos body) (checking-data check :: ll-data-type :: binder-data Γ pi' x atk NotErased nothing (type-start-pos body) (type-end-pos body) :: tvs) Iota-span : ctxt → posinfo → posinfo → var → type → ex-tp → checking-mode → 𝕃 tagged-val → err-m → span Iota-span Γ pi pi' x t1 t2 check tvs = mk-span "Iota-abstraction" pi (type-end-pos t2) (explain "A dependent intersection type" :: checking-data check :: binder-data Γ pi' x (Tkt t1) ff nothing (type-start-pos t2) (type-end-pos t2) :: ll-data-type :: tvs) TpArrow-span : ex-tp → ex-tp → checking-mode → 𝕃 tagged-val → err-m → span TpArrow-span t1 t2 check tvs = mk-span "Arrow type" (type-start-pos t1) (type-end-pos t2) (checking-data check :: ll-data-type :: tvs) TpEq-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span TpEq-span pi pi' check tvs = mk-span "Equation" pi pi' (explain "Equation between terms" :: checking-data check :: ll-data-type :: tvs) Star-span : posinfo → checking-mode → err-m → span Star-span pi check = mk-span Star-name pi (posinfo-plus pi 1) (checking-data check :: [ ll-data-kind ]) KdAbs-span : ctxt → posinfo → posinfo → var → tpkd → ex-kd → checking-mode → err-m → span KdAbs-span Γ pi pi' x atk k check = mk-span "Pi kind" pi (kind-end-pos k) (checking-data check :: ll-data-kind :: binder-data Γ pi' x atk ff nothing (kind-start-pos k) (kind-end-pos k) :: [ super-kind-data ]) KdArrow-span : ex-tk → ex-kd → checking-mode → err-m → span KdArrow-span k k' check = mk-span "Arrow kind" (tk-start-pos k) (kind-end-pos k') (checking-data check :: ll-data-kind :: [ super-kind-data ]) {- [[file:../cedille-mode.el::(defun%20cedille-mode-filter-out-special(data)][Frontend]] -} special-tags : 𝕃 string special-tags = "symbol" :: "location" :: "language-level" :: "checking-mode" :: "summary" :: "binder" :: "bound-value" :: "keywords" :: [] error-span-filter-special : error-span → error-span error-span-filter-special (mk-error-span dsc pi pi' tvs msg) = mk-error-span dsc pi pi' tvs' msg where tvs' = (flip filter) tvs λ tag → list-any (_=string (fst tag)) special-tags erasure : ctxt → term → tagged-val erasure Γ t = to-string-tag "erasure" Γ (erase t) erased-marg-span : ctxt → posinfo → posinfo → maybe type → span erased-marg-span Γ pi pi' mtp = mk-span "Erased module parameter" pi pi' (maybe-else [] (λ tp → [ type-data Γ tp ]) mtp) (just "An implicit module parameter variable occurs free in the erasure of the term") Lam-span-erased : erased? → string Lam-span-erased Erased = "Erased lambda abstraction (term-level)" Lam-span-erased NotErased = "Lambda abstraction (term-level)" Lam-span : ctxt → checking-mode → posinfo → posinfo → erased? → var → tpkd → ex-tm → 𝕃 tagged-val → err-m → span Lam-span Γ c pi pi' l x atk t tvs = mk-span (Lam-span-erased l) pi (term-end-pos t) (ll-data-term :: binder-data Γ pi' x atk l nothing (term-start-pos t) (term-end-pos t) :: checking-data c :: tvs) compileFail-in : ctxt → term → 𝕃 tagged-val × err-m compileFail-in Γ t with is-free-in compileFail-qual | t ...| is-free | tₒ with erase tₒ | hnf Γ (record unfold-all { unfold-defs = ff }) tₒ ...| tₑ | tₙ with is-free tₒ ...| ff = [] , nothing ...| tt with is-free tₙ | is-free tₑ ...| tt | _ = [ to-string-tag "normalized term" Γ tₙ ] , just "compileFail occurs in the normalized term" ...| ff | ff = [ to-string-tag "the term" Γ tₒ ] , just "compileFail occurs in an erased position" ...| ff | tt = [] , nothing DefTerm-span : ctxt → posinfo → var → (checked : checking-mode) → maybe type → term → posinfo → 𝕃 tagged-val → span DefTerm-span Γ pi x checked tp t pi' tvs = h ((h-summary tp) ++ ({-erasure Γ t ::-} tvs)) pi x checked tp pi' where h : 𝕃 tagged-val → posinfo → var → (checked : checking-mode) → maybe type → posinfo → span h tvs pi x checking _ pi' = mk-span "Term-level definition (checking)" pi pi' tvs nothing h tvs pi x _ (just tp) pi' = mk-span "Term-level definition (synthesizing)" pi pi' (to-string-tag "synthesized type" Γ tp :: tvs) nothing h tvs pi x _ nothing pi' = mk-span "Term-level definition (synthesizing)" pi pi' ((strRunTag "synthesized type" empty-ctxt $ strAdd "[nothing]") :: tvs) nothing h-summary : maybe type → 𝕃 tagged-val h-summary nothing = [(checking-data synthesizing)] h-summary (just tp) = (checking-data checking :: [ summary-data x Γ tp ]) CheckTerm-span : ctxt → (checked : checking-mode) → maybe type → ex-tm → posinfo → 𝕃 tagged-val → span CheckTerm-span Γ checked tp t pi' tvs = h ({-erasure Γ t ::-} tvs) checked tp (term-start-pos t) pi' where h : 𝕃 tagged-val → (checked : checking-mode) → maybe type → posinfo → posinfo → span h tvs checking _ pi pi' = mk-span "Checking a term" pi pi' (checking-data checking :: tvs) nothing h tvs _ (just tp) pi pi' = mk-span "Synthesizing a type for a term" pi pi' (checking-data synthesizing :: to-string-tag "synthesized type" Γ tp :: tvs) nothing h tvs _ nothing pi pi' = mk-span "Synthesizing a type for a term" pi pi' (checking-data synthesizing :: (strRunTag "synthesized type" empty-ctxt $ strAdd "[nothing]") :: tvs) nothing normalized-type : ctxt → type → tagged-val normalized-type = to-string-tag "normalized type" DefType-span : ctxt → posinfo → var → (checked : checking-mode) → maybe kind → type → posinfo → 𝕃 tagged-val → span DefType-span Γ pi x checked mk tp pi' tvs = h ((h-summary mk) ++ tvs) checked mk where h : 𝕃 tagged-val → checking-mode → maybe kind → span h tvs checking _ = mk-span "Type-level definition (checking)" pi pi' tvs nothing h tvs _ (just k) = mk-span "Type-level definition (synthesizing)" pi pi' (to-string-tag "synthesized kind" Γ k :: tvs) nothing h tvs _ nothing = mk-span "Type-level definition (synthesizing)" pi pi' ( (strRunTag "synthesized kind" empty-ctxt $ strAdd "[nothing]") :: tvs) nothing h-summary : maybe kind → 𝕃 tagged-val h-summary nothing = [(checking-data synthesizing)] h-summary (just k) = (checking-data checking :: [ summary-data x Γ k ]) DefKind-span : ctxt → posinfo → var → kind → posinfo → span DefKind-span Γ pi x k pi' = mk-span "Kind-level definition" pi pi' (kind-data Γ k :: [ summary-data x Γ (Var "□") ]) nothing DefDatatype-span : ctxt → posinfo → posinfo → var → params → (reg Mu bound : kind) → (mu : type) → (cast : type) → ctrs → ex-kd → posinfo → span DefDatatype-span Γ pi pi' x ps k kₘᵤ kₓ Tₘᵤ Tₜₒ cs kₑₓ pi'' = mk-span "Datatype definition" pi pi'' (binder-data Γ pi' x (Tkk kₓ) ff nothing (kind-end-pos kₑₓ) pi'' :: summary-data x Γ k :: summary-data (data-Is/ x) Γ kₘᵤ :: summary-data (data-is/ x) Γ Tₘᵤ :: summary-data (data-to/ x) Γ Tₜₒ :: to-string-tag (data-Is/ x) Γ kₘᵤ :: to-string-tag (data-is/ x) Γ Tₘᵤ :: to-string-tag (data-to/ x) Γ Tₜₒ :: []) nothing {-unchecked-term-span : term → span unchecked-term-span t = mk-span "Unchecked term" (term-start-pos t) (term-end-pos t) (ll-data-term :: not-for-navigation :: [ explain "This term has not been type-checked"]) nothing-} Beta-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span Beta-span pi pi' check tvs = mk-span "Beta axiom" pi pi' (checking-data check :: ll-data-term :: explain "A term constant whose type states that β-equal terms are provably equal" :: tvs) hole-span : ctxt → posinfo → maybe type → checking-mode → 𝕃 tagged-val → span hole-span Γ pi tp check tvs = mk-span "Hole" pi (posinfo-plus pi 1) (checking-data check :: ll-data-term :: expected-type-if Γ tp ++ tvs) (just "This hole remains to be filled in") tp-hole-span : ctxt → posinfo → maybe kind → checking-mode → 𝕃 tagged-val → span tp-hole-span Γ pi k check tvs = mk-span "Hole" pi (posinfo-plus pi 1) (checking-data check :: ll-data-type :: expected-kind-if Γ k ++ tvs) (just "This hole remains to be filled in") kd-hole-span : posinfo → checking-mode → span kd-hole-span pi check = mk-span "Hole" pi (posinfo-plus pi 1) (checking-data check :: ll-data-kind :: []) (just "This hole remains to be filled in") expected-to-string : checking-mode → string expected-to-string checking = "expected" expected-to-string synthesizing = "synthesized" expected-to-string untyped = "untyped" Epsilon-span : posinfo → left-right → minus? → ex-tm → checking-mode → 𝕃 tagged-val → err-m → span Epsilon-span pi lr m t check tvs = mk-span "Epsilon" pi (term-end-pos t) (checking-data check :: ll-data-term :: tvs ++ [ explain ("Normalize " ^ side lr ^ " of the " ^ expected-to-string check ^ " equation, using " ^ maybeMinus-description m ^ " reduction" ) ]) where side : left-right → string side EpsLeft = "the left-hand side" side EpsRight = "the right-hand side" side EpsBoth = "both sides" maybeMinus-description : minus? → string maybeMinus-description EpsHnf = "head" maybeMinus-description EpsHanf = "head-applicative" optGuide-spans : ctxt → maybe ex-guide → checking-mode → spanM ⊤ optGuide-spans Γ nothing _ = spanMok optGuide-spans Γ (just (ExGuide pi x tp)) expected = spanM-add (Var-span Γ pi x expected [] nothing) Rho-span : posinfo → ex-tm → ex-tm → checking-mode → 𝔹 → ℕ ⊎ var → 𝕃 tagged-val → err-m → span Rho-span pi t t' expected r (inj₂ x) tvs = mk-span "Rho" pi (term-end-pos t') (checking-data expected :: ll-data-term :: explain ("Rewrite all places where " ^ x ^ " occurs in the " ^ expected-to-string expected ^ " type, using an equation. ") :: tvs) Rho-span pi t t' expected r (inj₁ numrewrites) tvs err = mk-span "Rho" pi (term-end-pos t') (checking-data expected :: ll-data-term :: tvs ++ (explain ("Rewrite terms in the " ^ expected-to-string expected ^ " type, using an equation. " ^ (if r then "" else "Do not ") ^ "Beta-reduce the type as we look for matches") :: fst h)) (snd h) where h : 𝕃 tagged-val × err-m h = if isJust err then [] , err else if numrewrites =ℕ 0 then [] , just "No rewrites could be performed" else [ strRunTag "Number of rewrites" empty-ctxt (strAdd $ ℕ-to-string numrewrites) ] , err Phi-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span Phi-span pi pi' expected tvs = mk-span "Phi" pi pi' (checking-data expected :: ll-data-term :: tvs) Chi-span : ctxt → posinfo → maybe type → ex-tm → checking-mode → 𝕃 tagged-val → err-m → span Chi-span Γ pi m t' check tvs = mk-span "Chi" pi (term-end-pos t') (ll-data-term :: checking-data check :: tvs ++ helper m) where helper : maybe type → 𝕃 tagged-val helper (just T) = explain ("Check a term against an asserted type") :: [ to-string-tag "the asserted type" Γ T ] helper nothing = [ explain ("Change from checking mode (outside the term) to synthesizing (inside)") ] VarSigma-span : posinfo → ex-tm → checking-mode → 𝕃 tagged-val → err-m → span VarSigma-span pi t check tvs = mk-span "VarSigma" pi (term-end-pos t) (ll-data-term :: checking-data check :: explain "Swap the sides of the equation synthesized for the body of this term" :: tvs) Delta-span : posinfo → ex-tm → checking-mode → 𝕃 tagged-val → err-m → span Delta-span pi t check tvs = mk-span "Delta" pi (term-end-pos t) (ll-data-term :: explain "Prove anything you want from a contradiction" :: checking-data check :: tvs) Opaque-span : posinfo → posinfo → span Opaque-span p₁ p₂ = mk-span "Opaque" p₁ p₂ [ explain "Mark a definition as opaque, for the purposes of conversion checking" ] nothing Open-span : opacity → posinfo → var → ex-tm → checking-mode → 𝕃 tagged-val → err-m → span Open-span o pi x t check tvs = elim-pair (if o then ("Open" , "Open an opaque definition") else ("Close" , "Hide a definition")) λ name expl → mk-span name pi (term-end-pos t) (ll-data-term :: explain expl :: checking-data check :: tvs) motive-label : string motive-label = "the motive" the-motive : ctxt → type → tagged-val the-motive = to-string-tag motive-label Theta-span : ctxt → posinfo → theta → ex-tm → 𝕃 lterm → checking-mode → 𝕃 tagged-val → err-m → span Theta-span Γ pi u t ls check tvs = mk-span "Theta" pi (lterms-end-pos (term-end-pos t) ls) (ll-data-term :: checking-data check :: tvs ++ do-explain u) where do-explain : theta → 𝕃 tagged-val do-explain Abstract = [ explain ("Perform an elimination with the first term, after abstracting it from the expected type") ] do-explain (AbstractVars vs) = [ strRunTag "explanation" Γ (strAdd "Perform an elimination with the first term, after abstracting the listed variables (" >>str vars-to-string vs >>str strAdd ") from the expected type") ] do-explain AbstractEq = [ explain ("Perform an elimination with the first term, after abstracting it with an equation " ^ "from the expected type") ] Mu-span : ctxt → posinfo → posinfo → (motive? : maybe type) → checking-mode → 𝕃 tagged-val → err-m → span Mu-span Γ pi pi' motive? check tvs = mk-span "Mu" pi pi' (ll-data-term :: checking-data check :: explain ("Pattern match on a term" ^ (if isJust motive? then ", with a motive" else "")) :: tvs) Sigma-span : ctxt → posinfo → posinfo → (motive? : maybe type) → checking-mode → 𝕃 tagged-val → err-m → span Sigma-span Γ pi pi' motive? check tvs = mk-span "Sigma" pi pi' (ll-data-term :: checking-data check :: explain ("Pattern match on a term" ^ (if isJust motive? then ", with a motive" else "")) :: tvs) pattern-span : posinfo → var → 𝕃 ex-case-arg → span pattern-span pi x as = mk-span "Pattern" pi (snd $ foldr (λ a r → if fst r then r else (tt , (case a of λ {(ExCaseArg me pi x) → posinfo-plus-str pi x}))) (ff , posinfo-plus-str pi x) as) [] nothing pattern-clause-span : posinfo → ex-tm → 𝕃 tagged-val → span pattern-clause-span pi t tvs = mk-span "Pattern clause" pi (term-end-pos t) tvs nothing pattern-ctr-span : ctxt → posinfo → var → case-args → 𝕃 tagged-val → err-m → span pattern-ctr-span Γ pi x as tvs = mk-span "Pattern constructor" pi (posinfo-plus-str pi x) (checking-data synthesizing :: var-location-data Γ x :: ll-data-term :: symbol-data x :: args-data ++ tvs) where args-data : 𝕃 tagged-val args-data = if iszero (length as) then [] else [ params-to-string-tag "args" Γ (map (λ {(CaseArg me x tk?) → Param me x (maybe-else' tk? (Tkt (TpHole pi-gen)) id)}) as) ] File-span : ctxt → posinfo → posinfo → string → span File-span Γ pi pi' filename = mk-span ("Cedille source file (" ^ filename ^ ")") pi pi' (print-file-id-table Γ) nothing Module-span : posinfo → posinfo → span Module-span pi pi' = mk-span "Module declaration" pi pi' [ not-for-navigation ] nothing Module-header-span : posinfo → posinfo → span Module-header-span pi pi' = mk-span "Module header" pi pi' [ not-for-navigation ] nothing DefDatatype-header-span : posinfo → span DefDatatype-header-span pi = mk-span "Data" pi (posinfo-plus-str pi "data") [ not-for-navigation ] nothing Import-span : posinfo → string → posinfo → 𝕃 tagged-val → err-m → span Import-span pi file pi' tvs = mk-span ("Import of another source file") pi pi' (("Path" , [[ file ]] , []) :: location-data (file , first-position) :: tvs) Import-module-span : ctxt → (posinfo × var) → params → 𝕃 tagged-val → err-m → span Import-module-span Γ (pi , mn) ps tvs = mk-span "Imported module" pi (posinfo-plus-str pi mn) (params-data Γ ps ++ tvs) punctuation-span : string → posinfo → posinfo → span punctuation-span name pi pi' = mk-span name pi pi' ( punctuation-data :: not-for-navigation :: [] ) nothing whitespace-span : posinfo → posinfo → span whitespace-span pi pi' = mk-span "Whitespace" pi pi' [ not-for-navigation ] nothing comment-span : posinfo → posinfo → span comment-span pi pi' = mk-span "Comment" pi pi' [ not-for-navigation ] nothing IotaPair-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span IotaPair-span pi pi' c tvs = mk-span "Iota pair" pi pi' (explain "Inhabit a iota-type (dependent intersection type)" :: checking-data c :: ll-data-term :: tvs) IotaProj-span : ex-tm → posinfo → checking-mode → 𝕃 tagged-val → err-m → span IotaProj-span t pi' c tvs = mk-span "Iota projection" (term-start-pos t) pi' (checking-data c :: ll-data-term :: tvs) Let-span : erased? → posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span Let-span me pi pi' c tvs = mk-span (if me then "Erased Term Let" else "Term Let") pi pi' (ll-data-term :: checking-data c :: tvs) TpLet-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → span TpLet-span pi pi' c tvs = mk-span "Type Let" pi pi' (ll-data-type :: checking-data c :: tvs) nothing
{ "alphanum_fraction": 0.6444925924, "avg_line_length": 46.4680272109, "ext": "agda", "hexsha": "7847477bae85775b8ab9578ec2416aab1e29c621", "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": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ice1k/cedille", "max_forks_repo_path": "src/spans.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "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": "ice1k/cedille", "max_issues_repo_path": "src/spans.agda", "max_line_length": 354, "max_stars_count": null, "max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ice1k/cedille", "max_stars_repo_path": "src/spans.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 10176, "size": 34154 }
{-# OPTIONS --rewriting --confluence-check #-} -- Let us assume that extensionality of functions cannot be proved -- inside "plain" Agda. In that case the code below shows that the -- REWRITE functionality is not a conservative extension, even if we -- only use propositional equality as the rewriting relation, and do -- not use any postulates. -- Jesper, 2019-05-13: This example is not confluent! module RewriteExt-confluence where open import Common.Equality {-# BUILTIN REWRITE _≡_ #-} data Unit : Set where unit : Unit module _ {a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x} (f≡g : ∀ x → f x ≡ g x) where private id : Unit → (x : A) → B x → B x id unit _ x = x f≡g′ : ∀ u x → id u x (f x) ≡ g x f≡g′ unit = f≡g {-# REWRITE f≡g′ #-} ext′ : ∀ u → (λ x → id u x (f x)) ≡ g ext′ u = refl ext : f ≡ g ext = ext′ unit
{ "alphanum_fraction": 0.5959367946, "avg_line_length": 22.7179487179, "ext": "agda", "hexsha": "bacca0d4cc1a0ce04ee3254b231d61a98259b4c2", "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/RewriteExt-confluence.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/RewriteExt-confluence.agda", "max_line_length": 68, "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/RewriteExt-confluence.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": 301, "size": 886 }
module #15 where {- Show that indiscernability of identicals follows from path induction -} open import Data.Product open import Relation.Binary.PropositionalEquality id : ∀{x}{A : Set x} → A → A id x = x ind₌ : ∀{a}{A : Set a} → (C : (x y : A) → (x ≡ y) → Set) → ((x : A) → C x x refl) → (x y : A) → (p : x ≡ y) → C x y p ind₌ C c x y p rewrite p = c y based-ind₌ : ∀{x}{A : Set x} → (a : A) → (C : (x : A) → (a ≡ x) → Set) → C a refl → (x : A) → (p : a ≡ x) → C x p based-ind₌ a C c b p rewrite p = c indiscernability-of-identicals : {A : Set}{C : A → Set} → Σ[ f ∈ ((x y : A) → (x ≡ y) → C x → C y) ]((x : A) → f x x refl ≡ id {A = C x}) indiscernability-of-identicals {A} {C} = transport , (λ _ → refl) where transport : (x y : A) → (p : x ≡ y) → C x → C y transport = ind₌ (λ x y _ → C x → C y) (λ x z → z)
{ "alphanum_fraction": 0.5090252708, "avg_line_length": 34.625, "ext": "agda", "hexsha": "a39cd85acb08bd0e7950a32303432b17c6e7e22a", "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": "3411b253b0a49a5f9c3301df175ae8ecdc563b12", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CodaFi/HoTT-Exercises", "max_forks_repo_path": "Chapter1/#15.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12", "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": "CodaFi/HoTT-Exercises", "max_issues_repo_path": "Chapter1/#15.agda", "max_line_length": 137, "max_stars_count": null, "max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CodaFi/HoTT-Exercises", "max_stars_repo_path": "Chapter1/#15.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 360, "size": 831 }
{-# OPTIONS --safe #-} module Cubical.Categories.Instances.CommRings where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Categories.Category open Category open CommRingHoms CommRingsCategory : ∀ {ℓ} → Category (ℓ-suc ℓ) ℓ ob CommRingsCategory = CommRing _ Hom[_,_] CommRingsCategory = CommRingHom id CommRingsCategory {R} = idCommRingHom R _⋆_ CommRingsCategory {R} {S} {T} = compCommRingHom R S T ⋆IdL CommRingsCategory {R} {S} = compIdCommRingHom {R = R} {S} ⋆IdR CommRingsCategory {R} {S} = idCompCommRingHom {R = R} {S} ⋆Assoc CommRingsCategory {R} {S} {T} {U} = compAssocCommRingHom {R = R} {S} {T} {U} isSetHom CommRingsCategory = isSetRingHom _ _
{ "alphanum_fraction": 0.6765714286, "avg_line_length": 36.4583333333, "ext": "agda", "hexsha": "085fc579cc1be4e5a67be59aaf4bd0de684f57f3", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "63c770b381039c0132c17d7913f4566b35984701", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mzeuner/cubical", "max_forks_repo_path": "Cubical/Categories/Instances/CommRings.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "63c770b381039c0132c17d7913f4566b35984701", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mzeuner/cubical", "max_issues_repo_path": "Cubical/Categories/Instances/CommRings.agda", "max_line_length": 83, "max_stars_count": null, "max_stars_repo_head_hexsha": "63c770b381039c0132c17d7913f4566b35984701", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mzeuner/cubical", "max_stars_repo_path": "Cubical/Categories/Instances/CommRings.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 275, "size": 875 }
open import Data.Bool as Bool using (Bool; false; true; if_then_else_; not) open import Data.String using (String) open import Data.Nat using (ℕ; _+_; _≟_; suc; _>_; _<_; _∸_) open import Relation.Nullary.Decidable using (⌊_⌋) open import Data.List as l using (List; filter; map; take; foldl; length) open import Data.List.Properties open import Data.Maybe using (to-witness) open import Data.Fin using (fromℕ; _-_; zero) open import Data.Product as Prod using (∃; ∃₂; _×_; _,_; Σ) import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong) open Eq.≡-Reasoning open import Level using (Level) open import Data.Vec as v using (Vec; fromList; toList; last; length; []; _∷_; [_]; _∷ʳ_; _++_; lookup; head; initLast; filter; map) open import Data.Vec.Bounded as vb using ([]; _∷_; fromVec; filter; Vec≤) open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_; refl; _≗_; cong₂) open import Data.Nat.Properties using (+-comm) open import Relation.Unary using (Pred; Decidable) open import Relation.Nullary using (does) open import Data.Vec.Bounded.Base using (padRight; ≤-cast) import Data.Nat.Properties as ℕₚ open import Relation.Nullary.Decidable.Core using (dec-false) -- essentially a List String record Todo : Set where field text : String AddTodo : ∀ {n : ℕ} → (Vec Todo n) → String → (Vec Todo (1 + n)) AddTodo todos text = todos ∷ʳ record { text = text } AddTodoAddsNewListItem : ∀ {n : ℕ} → (todos : Vec Todo n) (text : String) → v.length (AddTodo todos text) ≡ v.length todos + 1 AddTodoAddsNewListItem [] text = refl AddTodoAddsNewListItem todos text = +-comm 1 (v.length todos) AddTodoLastAddedElementIsTodo : ∀ {n} (todos : Vec Todo n) (text : String) → last (AddTodo todos text) ≡ record { text = text } AddTodoLastAddedElementIsTodo todos text = vecLast todos where vecLast : ∀ {a} {A : Set a} {l} {n : ℕ} (xs : Vec A n) → last (xs ∷ʳ l) ≡ l vecLast [] = refl vecLast (_ ∷ xs) = P.trans (prop (xs ∷ʳ _)) (vecLast xs) where prop : ∀ {a} {A : Set a} {n x} (xs : Vec A (suc n)) → last (x v.∷ xs) ≡ last xs prop xs with initLast xs ... | _ , _ , refl = refl AddTodoAddedTodoHasGivenText : ∀ {n} (todos : Vec Todo n) (text : String) → Todo.text (last (AddTodo todos text)) ≡ text AddTodoAddedTodoHasGivenText todos text rewrite (AddTodoLastAddedElementIsTodo todos text) = refl
{ "alphanum_fraction": 0.6578419575, "avg_line_length": 35.1126760563, "ext": "agda", "hexsha": "3d714f4877970224ac6f61abf6b5efa39c78f6c2", "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": "506fba1e27d8c1527f06c285762391b00ed03ced", "max_forks_repo_licenses": [ "CC0-1.0", "MIT" ], "max_forks_repo_name": "frankymacster/redux", "max_forks_repo_path": "examples/todomvc/src/logic/base-todos.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "506fba1e27d8c1527f06c285762391b00ed03ced", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0", "MIT" ], "max_issues_repo_name": "frankymacster/redux", "max_issues_repo_path": "examples/todomvc/src/logic/base-todos.agda", "max_line_length": 132, "max_stars_count": null, "max_stars_repo_head_hexsha": "506fba1e27d8c1527f06c285762391b00ed03ced", "max_stars_repo_licenses": [ "CC0-1.0", "MIT" ], "max_stars_repo_name": "frankymacster/redux", "max_stars_repo_path": "examples/todomvc/src/logic/base-todos.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 793, "size": 2493 }
{-# OPTIONS --no-termination-check #-} module optionsPragma where -- Only goes through with the termination checker turned off. Foo : Set Foo = Foo
{ "alphanum_fraction": 0.7333333333, "avg_line_length": 18.75, "ext": "agda", "hexsha": "9821c84ffafb5faa3d908a2cdaf20524c345f4d5", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/optionsPragma.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/optionsPragma.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/optionsPragma.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 32, "size": 150 }
data ⊥ : Set where data Bool : Set where false true : Bool data _≡_ (x : Bool) : Bool → Set where refl : x ≡ x true≠false : false ≡ true → ⊥ true≠false () data Maybe (A : Set) : Set where nothing : Maybe A just : A → Maybe A data Eq {A : Set} (_≈_ : A → A → Set) : Maybe A → Maybe A → Set where just : ∀ {x y} (x≈y : x ≈ y) → Eq _≈_ (just x) (just y) nothing : Eq _≈_ nothing nothing drop-just : ∀ {A : Set} {_≈_ : A → A → Set} {x y : A} → Eq _≈_ (just x) (just y) → x ≈ y drop-just (just x≈y) = x≈y
{ "alphanum_fraction": 0.5280898876, "avg_line_length": 22.25, "ext": "agda", "hexsha": "40201d9001bfda75c1ca7191aa0018785a240376", "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/Issue2235.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/Issue2235.agda", "max_line_length": 69, "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/Issue2235.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": 225, "size": 534 }
module Control.Monad.Writer where open import Prelude open import Control.Monad.Zero open import Control.Monad.Identity open import Control.Monad.Transformer record WriterT {a} (W : Set a) (M : Set a → Set a) (A : Set a) : Set a where no-eta-equality constructor writerT field runWriterT : M (A × W) open WriterT public module _ {a} {W : Set a} {M : Set a → Set a} where instance FunctorWriterT : {{_ : Functor M}} → Functor {a = a} (WriterT W M) runWriterT (fmap {{ FunctorWriterT }} f m) = first f <$> runWriterT m FunctorZeroWriterT : {{_ : FunctorZero M}} → FunctorZero {a = a} (WriterT W M) runWriterT (empty {{FunctorZeroWriterT}}) = empty AlternativeWriterT : {{_ : Alternative M}} → Alternative {a = a} (WriterT W M) runWriterT (_<|>_ {{AlternativeWriterT}} x y) = runWriterT x <|> runWriterT y module _ {{_ : Monoid W}} {{_ : Monad M}} where private bindWriterT : ∀ {A B} → WriterT W M A → (A → WriterT W M B) → WriterT W M B runWriterT (bindWriterT m f) = do (x , w₁) ← runWriterT m (y , w₂) ← (runWriterT (f x)) return (y , w₁ <> w₂) instance ApplicativeWriterT : Applicative {a = a} (WriterT W M) runWriterT (pure {{ApplicativeWriterT}} x) = return (x , mempty) _<*>_ {{ApplicativeWriterT}} = monadAp bindWriterT MonadWriterT : Monad {a = a} (WriterT W M) _>>=_ {{MonadWriterT}} = bindWriterT liftWriterT : {A : Set a} → M A → WriterT W M A runWriterT (liftWriterT m) = (_, mempty) <$> m writer : {A : Set a} → A × W → WriterT W M A runWriterT (writer (x , w)) = return (x , w) tell : W → WriterT W M ⊤′ runWriterT (tell w) = return (tt , w) listens : {A B : Set a} → (W → B) → WriterT W M A → WriterT W M (A × B) runWriterT (listens f m) = do (x , w) ← runWriterT m return ((x , f w) , w) listen : {A : Set a} → WriterT W M A → WriterT W M (A × W) listen = listens id pass : {A : Set a} → WriterT W M (A × (W → W)) → WriterT W M A runWriterT (pass m) = do ((x , f) , w) ← runWriterT m return (x , f w) censor : {A : Set a} → (W → W) → WriterT W M A → WriterT W M A censor f m = pass ((_, f) <$> m) instance TransformerWriterT : ∀ {a} {W : Set a} {{_ : Monoid W}} → Transformer (WriterT W) lift {{TransformerWriterT}} = liftWriterT Writer : ∀ {a} (W : Set a) (A : Set a) → Set a Writer W = WriterT W Identity runWriter : ∀ {a} {W : Set a} {A : Set a} → Writer W A → A × W runWriter m = runIdentity (runWriterT m) execWriter : ∀ {a} {W : Set a} {A : Set a} → Writer W A → W execWriter = snd ∘ runWriter
{ "alphanum_fraction": 0.5828897338, "avg_line_length": 32.0731707317, "ext": "agda", "hexsha": "c1ffb9560cd7ee0db078e9171c3e3508757a0b82", "lang": "Agda", "max_forks_count": 24, "max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z", "max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z", "max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "t-more/agda-prelude", "max_forks_repo_path": "src/Control/Monad/Writer.agda", "max_issues_count": 59, "max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z", "max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "t-more/agda-prelude", "max_issues_repo_path": "src/Control/Monad/Writer.agda", "max_line_length": 83, "max_stars_count": 111, "max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "t-more/agda-prelude", "max_stars_repo_path": "src/Control/Monad/Writer.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z", "num_tokens": 919, "size": 2630 }
------------------------------------------------------------------------------ -- A Peano arithmetic proof without using a where clause ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module LogicalFramework.CommAddition where open import Common.FOL.Relation.Binary.EqReasoning open import PA.Axiomatic.Standard.Base ------------------------------------------------------------------------------ postulate +-rightIdentity : ∀ n → n + zero ≡ n x+Sy≡S[x+y] : ∀ m n → m + succ n ≡ succ (m + n) succCong : ∀ {m n} → m ≡ n → succ m ≡ succ n +-leftIdentity : ∀ n → zero + n ≡ n +-leftIdentity = PA₃ A : ℕ → Set A m = ∀ n → m + n ≡ n + m A0 : A zero A0 n = zero + n ≡⟨ +-leftIdentity n ⟩ n ≡⟨ sym (+-rightIdentity n) ⟩ n + zero ∎ is : ∀ m → A m → A (succ m) is m ih n = succ m + n ≡⟨ PA₄ m n ⟩ succ (m + n) ≡⟨ succCong (ih n) ⟩ succ (n + m) ≡⟨ sym (x+Sy≡S[x+y] n m) ⟩ n + succ m ∎ +-comm : ∀ m n → m + n ≡ n + m +-comm = ℕ-ind A A0 is
{ "alphanum_fraction": 0.4078303426, "avg_line_length": 29.1904761905, "ext": "agda", "hexsha": "3973eafe9462cda3ba36254bc14efdb966434003", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "notes/thesis/report/LogicalFramework/CommAddition.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "notes/thesis/report/LogicalFramework/CommAddition.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "notes/thesis/report/LogicalFramework/CommAddition.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": 360, "size": 1226 }
module 747Decidable where -- Library import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; sym) -- added sym open Eq.≡-Reasoning open import Data.Nat using (ℕ; zero; suc; _≤_; z≤n; s≤s) open import Data.Product using (_×_) renaming (_,_ to ⟨_,_⟩) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Relation.Nullary using (¬_) open import Relation.Nullary.Negation using () renaming (contradiction to ¬¬-intro) open import Data.Unit using (⊤; tt) open import Data.Empty using (⊥; ⊥-elim) -- Copied from 747Isomorphism. record _⇔_ (A B : Set) : Set where field to : A → B from : B → A open _⇔_ -- Copied from 747Relations. infix 4 _<_ data _<_ : ℕ → ℕ → Set where z<s : ∀ {n : ℕ} ------------ → zero < suc n s<s : ∀ {m n : ℕ} → m < n ------------- → suc m < suc n -- Recall that the constructors for _≤_ are z≤n and s≤s. -- Here are a couple of examples to show how to prove inequalities -- (or their negations). 2≤4 : 2 ≤ 4 2≤4 = {!!} ¬4≤2 : ¬ (4 ≤ 2) ¬4≤2 = {!!} -- This should be familiar. data Bool : Set where true : Bool false : Bool -- We can define a Boolean comparison function. infix 4 _≤ᵇ_ _≤ᵇ_ : ℕ → ℕ → Bool m ≤ᵇ n = {!!} -- PLFA steps through these computations using equational reasoning. _ : (2 ≤ᵇ 4) ≡ true _ = refl _ : (4 ≤ᵇ 2) ≡ false _ = refl -- Relating evidence and computation. T : Bool → Set T true = ⊤ T false = ⊥ T→≡ : ∀ (b : Bool) → T b → b ≡ true T→≡ b t = {!!} ≡→T : ∀ {b : Bool} → b ≡ true → T b ≡→T e = {!!} ≤ᵇ→≤ : ∀ (m n : ℕ) → T (m ≤ᵇ n) → m ≤ n ≤ᵇ→≤ m n t = {!!} ≤→≤ᵇ : ∀ {m n : ℕ} → m ≤ n → T (m ≤ᵇ n) ≤→≤ᵇ m≤n = {!!} -- Getting the best of both worlds! data Dec (A : Set) : Set where yes : A → Dec A no : ¬ A → Dec A -- Helpers for defining _≤?_ -- If you don't use these, the examples below won't normalize. ¬s≤z : ∀ {m : ℕ} → ¬ (suc m ≤ zero) ¬s≤z = {!!} ¬s≤s : ∀ {m n : ℕ} → ¬ (m ≤ n) → ¬ (suc m ≤ suc n) ¬s≤s = {!!} -- Decidable ≤. _≤?_ : ∀ (m n : ℕ) → Dec (m ≤ n) m ≤? n = {!!} _ : 2 ≤? 4 ≡ yes (s≤s (s≤s z≤n)) _ = refl _ : 4 ≤? 2 ≡ no (¬s≤s (¬s≤s ¬s≤z)) _ = refl -- We can also evaluate the LHS of these using C-c C-n. -- 747/PLFA exercise: DecLT (3 point) -- Decidable strict equality. -- You will need these helper functions as we did above. ¬z<z : ¬ (zero < zero) ¬z<z = {!!} ¬s<s : ∀ {m n : ℕ} → ¬ (m < n) → ¬ (suc m < suc n) ¬s<s = {!!} ¬s<z : ∀ {n : ℕ} → ¬ (suc n < zero) ¬s<z = {!!} _<?_ : ∀ (m n : ℕ) → Dec (m < n) m <? n = {!!} -- Some tests. _ : 2 <? 4 ≡ yes (s<s (s<s (z<s))) _ = refl _ : 4 <? 2 ≡ no (¬s<s (¬s<s ¬s<z)) _ = refl _ : 3 <? 3 ≡ no (¬s<s (¬s<s (¬s<s ¬z<z))) _ = refl -- 747/PLFA exercise: DecNatEq (3 points) -- Decidable equality for natural numbers. _≡ℕ?_ : ∀ (m n : ℕ) → Dec (m ≡ n) -- split m,n m ≡ℕ? n = {!!} -- Reusing ≤ᵇ and proofs of equivalence with ≤ to decide ≤. _≤?′_ : ∀ (m n : ℕ) → Dec (m ≤ n) m ≤?′ n = {!!} -- Erasing Dec down to Bool (or "isYes"). ⌊_⌋ : ∀ {A : Set} → Dec A → Bool ⌊ yes x ⌋ = true ⌊ no x ⌋ = false _≤ᵇ′_ : ℕ → ℕ → Bool m ≤ᵇ′ n = ⌊ m ≤? n ⌋ -- If D is Dec A, then T ⌊ D ⌋ is inhabited exactly when A is inhabited. toWitness : ∀ {A : Set} {D : Dec A} → T ⌊ D ⌋ → A toWitness t = {!!} fromWitness : ∀ {A : Set} {D : Dec A} → A → T ⌊ D ⌋ fromWitness a = {!!} -- Similar ideas when it is the "no" witnesses we want to handle. isNo : ∀ {A : Set} → Dec A → Bool isNo (yes _) = false isNo (no _) = true toWitnessFalse : ∀ {A : Set} {D : Dec A} → T (isNo D) → ¬ A toWitnessFalse = {!!} fromWitnessFalse : ∀ {A : Set} {D : Dec A} → ¬ A → T (isNo D) fromWitnessFalse = {!!} -- Agda standard library definitions for use of these. True : ∀ {A : Set} → (D : Dec A) → Set True Q = T ⌊ Q ⌋ False : ∀ {A : Set} → (D : Dec A) → Set False Q = T (isNo Q) -- A concrete example. ≤ᵇ′→≤ : ∀ {m n : ℕ} → T (m ≤ᵇ′ n) → m ≤ n ≤ᵇ′→≤ = toWitness ≤→≤ᵇ′ : ∀ {m n : ℕ} → m ≤ n → T (m ≤ᵇ′ n) ≤→≤ᵇ′ = fromWitness -- Conclusion: use Decidables instead of Booleans! -- Logical connectives for Decidables. infixr 6 _∧_ _∧_ : Bool → Bool → Bool true ∧ true = true true ∧ false = false false ∧ y = false infixr 6 _×-dec_ _×-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A × B) da ×-dec db = {!!} infixr 5 _∨_ _∨_ : Bool → Bool → Bool true ∨ y = true false ∨ y = y infixr 5 _⊎-dec_ _⊎-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A ⊎ B) da ⊎-dec db = {!!} not : Bool → Bool not true = false not false = true ¬? : ∀ {A : Set} → Dec A → Dec (¬ A) ¬? da = {!!} -- A Boolean version of implication. _⊃_ : Bool → Bool → Bool true ⊃ true = true true ⊃ false = false false ⊃ y = true _→-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A → B) da →-dec db = {!!} -- 747/PLFA exercise: ErasBoolDec (3 points) -- Erasure relates boolean and decidable operations. ∧-× : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ ∧ ⌊ y ⌋ ≡ ⌊ x ×-dec y ⌋ ∧-× da db = {!!} ∨-× : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ ∨ ⌊ y ⌋ ≡ ⌊ x ⊎-dec y ⌋ ∨-× da db = {!!} not-¬ : ∀ {A : Set} (x : Dec A) → not ⌊ x ⌋ ≡ ⌊ ¬? x ⌋ not-¬ da = {!!} -- 747/PLFA exercise: iff-erasure. _iff_ : Bool → Bool → Bool true iff true = true true iff false = false false iff true = false false iff false = true _⇔-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A ⇔ B) da ⇔-dec db = {!!} iff-⇔ : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ iff ⌊ y ⌋ ≡ ⌊ x ⇔-dec y ⌋ iff-⇔ da db = {!!} -- Proof by reflection. -- Or, getting Agda to construct proofs at compile time. -- A guarded version of monus. minus : (m n : ℕ) (n≤m : n ≤ m) → ℕ minus m zero _ = m minus (suc m) (suc n) (s≤s m≤n) = minus m n m≤n -- But we have to provide proofs. _ : minus 5 3 (s≤s (s≤s (s≤s z≤n))) ≡ 2 _ = refl -- Agda will fill in an implicit record type if it can fill in all fields. -- Since ⊤ is defined as a record type with no fields... -- We can get Agda to compute a value of type True (n ≤? m). _-_ : (m n : ℕ) {n≤m : True (n ≤? m)} → ℕ _-_ m n {n≤m} = minus m n (toWitness n≤m) _ : 5 - 3 ≡ 2 _ = refl -- We will later use this to get Agda to compute parts of proofs -- that would be annoying for us to provide.
{ "alphanum_fraction": 0.5299524044, "avg_line_length": 20.31, "ext": "agda", "hexsha": "72e71509c12418dcbe76ac15850883d74d74da22", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x09-747Decidable.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x09-747Decidable.agda", "max_line_length": 80, "max_stars_count": 36, "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x09-747Decidable.agda", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "num_tokens": 2606, "size": 6093 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import homotopy.SuspProduct open import homotopy.SuspSmash open import homotopy.JoinSusp open import cohomology.Theory module cohomology.SphereProduct {i} (CT : CohomologyTheory i) (n : ℤ) (m : ℕ) (X : Ptd i) where open CohomologyTheory CT open import cohomology.Wedge CT private space-eq : ⊙Susp (⊙Sphere m ⊙× X) ⊙≃ ⊙Sphere (S m) ⊙∨ (⊙Susp X ⊙∨ ⊙Susp^ (S m) X) space-eq = ⊙∨-emap (⊙ide (⊙Sphere (S m))) (⊙∨-emap (⊙ide (⊙Susp X)) (⊙*-Sphere-l m X ⊙∘e SuspSmash.⊙eq (⊙Sphere m) X)) ⊙∘e SuspProduct.⊙eq (⊙Sphere m) X C-Sphere× : C n (⊙Sphere m ⊙× X) ≃ᴳ C n (⊙Lift (⊙Sphere m)) ×ᴳ (C n X ×ᴳ C n (⊙Susp^ m X)) C-Sphere× = C n (⊙Sphere m ⊙× X) ≃ᴳ⟨ C-Susp n (⊙Sphere m ⊙× X) ⁻¹ᴳ ⟩ C (succ n) (⊙Susp (⊙Sphere m ⊙× X)) ≃ᴳ⟨ C-emap (succ n) (space-eq ⊙⁻¹) ⟩ C (succ n) (⊙Sphere (S m) ⊙∨ (⊙Susp X ⊙∨ ⊙Susp^ (S m) X)) ≃ᴳ⟨ C-emap (succ n) (⊙∨-emap (⊙Susp-emap (⊙lower-equiv {X = ⊙Sphere m})) (⊙ide _)) ⟩ C (succ n) (⊙Susp (⊙Lift {j = i} (⊙Sphere m)) ⊙∨ (⊙Susp X ⊙∨ ⊙Susp^ (S m) X)) ≃ᴳ⟨ C-Wedge (succ n) (⊙Susp (⊙Lift (⊙Sphere m))) (⊙Susp X ⊙∨ ⊙Susp^ (S m) X) ⟩ C (succ n) (⊙Susp (⊙Lift (⊙Sphere m))) ×ᴳ C (succ n) (⊙Susp X ⊙∨ ⊙Susp^ (S m) X) ≃ᴳ⟨ ×ᴳ-emap (C-Susp n (⊙Lift (⊙Sphere m))) ( ×ᴳ-emap (C-Susp n X) (C-Susp n (⊙Susp^ m X)) ∘eᴳ C-Wedge (succ n) (⊙Susp X) (⊙Susp^ (S m) X)) ⟩ C n (⊙Lift (⊙Sphere m)) ×ᴳ (C n X ×ᴳ C n (⊙Susp^ m X)) ≃ᴳ∎
{ "alphanum_fraction": 0.5067524116, "avg_line_length": 37.9268292683, "ext": "agda", "hexsha": "1ee81bd289a3cc52c5ff0e053ebfd403cba5feda", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z", "max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "theorems/cohomology/SphereProduct.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/cohomology/SphereProduct.agda", "max_line_length": 90, "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/cohomology/SphereProduct.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 831, "size": 1555 }
module Examples.Parity where open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Data.Empty open import Data.Bool hiding (not) open import Data.Nat open import Data.Fin hiding (_+_) open import Data.Product hiding (map) open import Data.List hiding (and; or; sum; map; [_]) open import Data.Vec hiding (init) import DTGP data Word : Set where not and or : Word pre : Word → ℕ → ℕ pre not n = 1 + n pre and n = 2 + n pre or n = 2 + n post : Word → ℕ → ℕ post not n = 1 + n post and n = 1 + n post or n = 1 + n even : ℕ → Bool even zero = true even (suc zero) = false even (suc (suc zero)) = true even (suc n) = even n trues : ∀ {n} → Vec Bool n → ℕ trues [] = 0 trues (true ∷ xs) = suc (trues xs) trues (false ∷ xs) = trues xs evenParity : ∀ {n} → Vec Bool n → Bool evenParity xs = even (trues xs) open DTGP pre post Data.Nat._≟_ eval : ∀ {inp out} → Term inp out → Vec Bool inp → Vec Bool out eval [] is = is eval (not ∷ xs) is with eval xs is ... | o ∷ os = Data.Bool.not o ∷ os eval (and ∷ xs) is with eval xs is ... | o₂ ∷ o₁ ∷ os = (o₁ ∧ o₂) ∷ os eval (or ∷ xs) is with eval xs is ... | o₂ ∷ o₁ ∷ os = (o₁ ∨ o₂) ∷ os bitEqual : ∀ {m n} → Vec Bool m → Vec Bool n → Bool bitEqual [] [] = true bitEqual (_ ∷ _) [] = false bitEqual [] (_ ∷ _) = false bitEqual (x ∷ xs) (y ∷ ys) = x ∧ y ∧ bitEqual xs ys scores : ∀ {inp out n} → Vec (Vec Bool inp) n → Term inp out → ℕ scores ass xs = sum (map (λ as → if (bitEqual (eval xs as) [ evenParity as ]) then 1 else 0) ass) fitnessCases : Vec (Vec Bool _) _ fitnessCases = (true ∷ true ∷ []) ∷ (true ∷ false ∷ []) ∷ (false ∷ true ∷ []) ∷ (false ∷ false ∷ []) ∷ [] _==_ : ℕ → ℕ → Bool zero == zero = true zero == suc _ = false suc _ == zero = false suc m == suc n = m == n score : Term _ _ → ℕ score xs = scores fitnessCases xs open Evolution score match : (w : Word) (out : ℕ) → Dec (∃ λ n → out ≡ pre w n) match not zero = no ¬p where ¬p : Σ ℕ (λ n → 0 ≡ suc n) → ⊥ ¬p (_ , ()) match not (suc n) = yes (n , refl) match and zero = no ¬p where ¬p : Σ ℕ (λ n → 0 ≡ suc (suc n)) → ⊥ ¬p (_ , ()) match and (suc zero) = no ¬p where ¬p : Σ ℕ (λ n → 1 ≡ suc (suc n)) → ⊥ ¬p (_ , ()) match and (suc (suc n)) = yes (n , refl) match or zero = no ¬p where ¬p : Σ ℕ (λ n → 0 ≡ suc (suc n)) → ⊥ ¬p (_ , ()) match or (suc zero) = no ¬p where ¬p : Σ ℕ (λ n → 1 ≡ suc (suc n)) → ⊥ ¬p (_ , ()) match or (suc (suc n)) = yes (n , refl) open Initialization match choices : List Word choices = not ∷ and ∷ or ∷ [] population : Population _ _ _ population = fromList (init 4 2 1 choices) answer : Population _ _ _ answer = evolve 1337 1 population
{ "alphanum_fraction": 0.5814911952, "avg_line_length": 23.6194690265, "ext": "agda", "hexsha": "9315bd95adac3bcb9de0dd34d944e13b6ec3a998", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:53:14.000Z", "max_forks_repo_forks_event_min_datetime": "2018-04-17T02:02:58.000Z", "max_forks_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "larrytheliquid/dtgp", "max_forks_repo_path": "src/Examples/Parity.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f", "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/dtgp", "max_issues_repo_path": "src/Examples/Parity.agda", "max_line_length": 64, "max_stars_count": 9, "max_stars_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/dtgp", "max_stars_repo_path": "src/Examples/Parity.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-19T21:39:58.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-20T16:46:00.000Z", "num_tokens": 1015, "size": 2669 }
-- Andreas, 2017-02-20, issue #2467 -- Proper error on missing BUILTIN REWRITE {-# OPTIONS --rewriting #-} postulate A : Set {-# REWRITE A #-} -- Should fail with error like
{ "alphanum_fraction": 0.6629213483, "avg_line_length": 16.1818181818, "ext": "agda", "hexsha": "64de029c613f0dba1a89980bf6c88fcebe415b33", "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/Issue2467.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/Issue2467.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/Fail/Issue2467.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": 50, "size": 178 }
-- Andreas, 2019-05-29, issue #3818, reported by Matthew Daggitt -- An external module name, i.e., the object of `import`, -- should not be considered clashing with an internal module name. module _ where module Issue3818 where module M where -- Internal module Issue3818.M. open import Issue3818.M -- Name unambiguous, since referring to file. -- Should succeed instead of complaining about ambiguous Issue3818.M.
{ "alphanum_fraction": 0.7424593968, "avg_line_length": 30.7857142857, "ext": "agda", "hexsha": "db51ac100e7e098b1d8e7d2ec16901ec9cbcaa36", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue3818.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/Issue3818.agda", "max_line_length": 70, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Succeed/Issue3818.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": 104, "size": 431 }
module rewriting where open import cedille-types open import constants open import conversion open import ctxt open import general-util open import free-vars --open import lift open import rename open import subst open import syntax-util open import type-util --open import erase open import datatype-util rewrite-mk-phi : var → (eq t t' : term) → term rewrite-mk-phi x eq t t' = Phi (Rho (VarSigma eq) x (TpEq t t') (Beta t id-term)) t t' rewrite-t : Set → Set rewrite-t T = ctxt → (is-plus : 𝔹) → (nums : maybe stringset) → (eq : maybe term) → (left : term) → (right : var) → (total-matches : ℕ) → T {- Returned value -} × ℕ {- Number of rewrites actually performed -} × ℕ {- Total number of matches, including skipped ones -} instance rewrite-functor : functor rewrite-t rewrite-applicative : applicative rewrite-t rewrite-monad : monad rewrite-t fmap ⦃ rewrite-functor ⦄ g r Γ op on eq t₁ t₂ n with r Γ op on eq t₁ t₂ n ...| a , n' , sn = g a , n' , sn pure ⦃ rewrite-applicative ⦄ a Γ p on eq t₁ t₂ n = a , 0 , n _<*>_ ⦃ rewrite-applicative ⦄ f a Γ op on eq t₁ t₂ n with f Γ op on eq t₁ t₂ n ...| f' , n' , sn with a Γ op on eq t₁ t₂ sn ...| b , n'' , sn' = f' b , n' + n'' , sn' return ⦃ rewrite-monad ⦄ a = pure a _>>=_ ⦃ rewrite-monad ⦄ fa fab Γ op on eq t₁ t₂ n with fa Γ op on eq t₁ t₂ n ...| a' , n' , sn with fab a' Γ op on eq t₁ t₂ sn ...| b , n'' , sn' = b , n' + n'' , sn' infixl 4 _≫rewrite_ _≫rewrite_ = _<*>_ {-# TERMINATING #-} rewrite-term : term → rewrite-t term rewrite-terma : term → rewrite-t term rewrite-termh : term → rewrite-t term rewrite-type : type → rewrite-t type rewrite-typeh : type → rewrite-t type rewrite-kind : kind → rewrite-t kind rewrite-tpkd : tpkd → rewrite-t tpkd rewrite-tmtp : tmtp → rewrite-t tmtp rewrite-exprd : ∀ {ed} → ⟦ ed ⟧ → rewrite-t ⟦ ed ⟧ rewrite-case : maybe (var × var) → case → rewrite-t case rewrite-exprd {TERM} = rewrite-term rewrite-exprd {TYPE} = rewrite-type rewrite-exprd {KIND} = rewrite-kind rewrite-rename-var : ∀ {A} → var → (var → rewrite-t A) → rewrite-t A rewrite-rename-var x r Γ op on eq t₁ t₂ n = let x' = rename-var-if Γ (renamectxt-insert empty-renamectxt t₂ t₂) x t₁ in r x' Γ op on eq t₁ t₂ n rewrite-abs : ∀ {ed} → var → var → (⟦ ed ⟧ → rewrite-t ⟦ ed ⟧) → ⟦ ed ⟧ → rewrite-t ⟦ ed ⟧ rewrite-abs x x' g a Γ = let Γ = ctxt-var-decl x' Γ in g (rename-var Γ x x' a) Γ rewrite-term t Γ op on eq t₁ t₂ sn = case rewrite-terma (erase t) Γ op on eq t₁ t₂ sn of λ where (t' , 0 , sn') → t , 0 , sn' (t' , n , sn') → maybe-else' eq t' (λ eq → rewrite-mk-phi t₂ eq t t') , n , sn' rewrite-terma t Γ op on eq t₁ t₂ sn = case conv-term Γ t t₁ of λ where tt → case on of λ where (just ns) → case trie-contains ns (ℕ-to-string (suc sn)) of λ where tt → Var t₂ , 1 , suc sn -- ρ nums contains n ff → t , 0 , suc sn -- ρ nums does not contain n nothing → Var t₂ , 1 , suc sn ff → case op of λ where tt → case rewrite-termh (hnf Γ unfold-head t) Γ op on eq t₁ t₂ sn of λ where (t' , 0 , sn') → t , 0 , sn' -- if no rewrites were performed, return the pre-hnf t (t' , n' , sn') → t' , n' , sn' ff → rewrite-termh t Γ op on eq t₁ t₂ sn rewrite-termh (App t t') = pure App <*> rewrite-terma t <*> rewrite-terma t' rewrite-termh (Lam NotErased y nothing t) = rewrite-rename-var y λ y' → pure (Lam NotErased y' nothing) <*> rewrite-abs y y' rewrite-terma t rewrite-termh (Var x) = pure (Var x) rewrite-termh (LetTm ff x nothing t t') Γ = rewrite-terma (subst Γ t x t') Γ -- rewrite-rename-var x λ x' → pure (Let pi₁) <*> -- (pure (DefTerm pi₂ x' NoType) <*> rewrite-terma t) <*> -- rewrite-abs x x' rewrite-terma t' -- ^^^ Need to DEFINE "x" as "hnf Γ unfold-head t tt", not just declare it! -- We may instead simply rewrite t' after substituting t for x rewrite-termh (Mu x t nothing t~ ms) = rewrite-rename-var x λ x' → pure (Mu x') <*> rewrite-terma t <*> pure nothing <*> pure t~ <*> foldr (λ c r → pure _::_ <*> rewrite-case (just $ x , x') c <*> r) (pure []) ms rewrite-termh (Sigma tᵢ t nothing t~ ms) = pure (Sigma tᵢ) <*> rewrite-terma t <*> pure nothing <*> pure t~ <*> foldr (λ c r → pure _::_ <*> rewrite-case nothing c <*> r) (pure []) ms rewrite-termh = pure rewrite-case xᵣ? (Case x cas t T) = let f = maybe-else' xᵣ? id (uncurry rewrite-abs) rewrite-terma in pure (uncurry $ Case x) <*> foldr {B = rewrite-t case-args → (term → rewrite-t term) → rewrite-t (case-args × term)} (λ {(CaseArg ff x nothing) r cas fₜ → r (rewrite-rename-var x λ x' → pure _::_ <*> pure (CaseArg ff x' nothing) <*> cas) (λ t → rewrite-rename-var x λ x' → rewrite-abs x x' fₜ t); _ → id}) (λ cas fₜ → pure (_,_ ∘ reverse) <*> cas <*> fₜ t) cas (pure []) f <*> return T rewrite-type T Γ tt on eq t₁ t₂ sn with rewrite-typeh (hnf Γ unfold-head-elab T) Γ tt on eq t₁ t₂ sn ...| T' , 0 , sn' = T , 0 , sn' ...| T' , n , sn' = T' , n , sn' rewrite-type = rewrite-typeh rewrite-typeh (TpAbs me x atk T) = rewrite-rename-var x λ x' → pure (TpAbs me x') <*> rewrite-tpkd atk <*> rewrite-abs x x' rewrite-type T rewrite-typeh (TpIota x T T') = rewrite-rename-var x λ x' → pure (TpIota x') <*> rewrite-type T <*> rewrite-abs x x' rewrite-type T' rewrite-typeh (TpApp T tT) = pure TpApp <*> rewrite-typeh T <*> rewrite-tmtp tT rewrite-typeh (TpEq t₁ t₂) = pure TpEq <*> (pure erase <*> rewrite-term t₁) <*> (pure erase <*> rewrite-term t₂) rewrite-typeh (TpLam x atk T) = rewrite-rename-var x λ x' → pure (TpLam x') <*> rewrite-tpkd atk <*> rewrite-abs x x' rewrite-type T rewrite-typeh (TpHole pi) = pure (TpHole pi) rewrite-typeh (TpVar x) = pure (TpVar x) -- If we ever implement kind-level rewriting, we will need to go through -- all the types of kind pi binding a term or type-to-kind arrow -- if the right-hand side variable is free in the types of the bound variable, -- and substitute each occurence of the term variable (eta-expanding if necessary) -- in the body of the type with itself surrounded by a rewrite back the original -- expected type (unless we lifted a term, then it gets really tricky because -- we may not want to rewrite back?). rewrite-kind = pure rewrite-liftingType = pure rewrite-tpkd (Tkt T) = pure Tkt <*> rewrite-type T rewrite-tpkd (Tkk k) = pure Tkk <*> rewrite-kind k rewrite-tmtp (Ttm t) = pure Ttm <*> rewrite-term t rewrite-tmtp (Ttp T) = pure Ttp <*> rewrite-type T post-rewrite-binder-type : ∀ {ed} → ctxt → var → term → (var → tpkd → ctxt → ctxt) → var → ⟦ ed ⟧ → type → ⟦ ed ⟧ post-rewrite-binder-type Γ x eq tk-decl x' Tₓ Tₓ' with is-free-in x Tₓ' ...| ff = Tₓ ...| tt = subst (tk-decl x' (Tkt Tₓ') Γ) (Rho eq x Tₓ' (Var x')) x' Tₓ post-rewrite-binder-kind : ∀ {ed} → ctxt → var → term → (var → tpkd → ctxt → ctxt) → var → ⟦ ed ⟧ → kind → ⟦ ed ⟧ post-rewrite-binder-kind Γ x eq tk-decl x' Tₓ kₓ' = Tₓ post-rewrite-binder-tk : ∀ {ed} → ctxt → var → term → (var → tpkd → ctxt → ctxt) → var → ⟦ ed ⟧ → tpkd → ⟦ ed ⟧ post-rewrite-binder-tk Γ x eq tk-decl x' Tₓ (Tkt Tₓ') = post-rewrite-binder-type Γ x eq tk-decl x' Tₓ Tₓ' post-rewrite-binder-tk Γ x eq tk-decl x' Tₓ (Tkk kₓ') = post-rewrite-binder-kind Γ x eq tk-decl x' Tₓ kₓ' post-rewriteh : ctxt → var → term → (ctxt → var → term → tpkd → tpkd) → (var → tpkd → ctxt → ctxt) → type → type × kind post-rewriteh Γ x eq prtk tk-decl (TpAbs me x' atk T) = let atk = prtk Γ x eq atk T = fst $ post-rewriteh (tk-decl x' atk Γ) x eq prtk tk-decl T T = post-rewrite-binder-tk Γ x eq tk-decl x' T atk in TpAbs me x' atk T , KdStar post-rewriteh Γ x eq prtk tk-decl (TpIota x' T T') = let T = fst $ post-rewriteh Γ x eq prtk tk-decl T T' = fst $ post-rewriteh (tk-decl x' (Tkt T) Γ) x eq prtk tk-decl T' T' = post-rewrite-binder-type Γ x eq tk-decl x' T' T in TpIota x' T T' , KdStar post-rewriteh Γ x eq prtk tk-decl (TpApp T (Ttp T')) = elim-pair (post-rewriteh Γ x eq prtk tk-decl T') λ T' k' → elim-pair (post-rewriteh Γ x eq prtk tk-decl T) λ where T (KdAbs x' atk k) → TpApp T (Ttp T') , hnf Γ unfold-head-elab (subst Γ T' x' k) T k → TpApp T (Ttp T') , k post-rewriteh Γ x eq prtk tk-decl (TpApp T (Ttm t)) = let t2 T' = if is-free-in x T' then Rho (VarSigma eq) x T' t else t in elim-pair (post-rewriteh Γ x eq prtk tk-decl T) λ where T (KdAbs x' (Tkt T') k) → let t3 = t2 T' in TpApp T (Ttm t3) , hnf Γ unfold-head-elab (subst Γ t3 x' k) T k → TpApp T (Ttm t) , k post-rewriteh Γ x eq prtk tk-decl (TpLam x' atk T) = let atk = prtk Γ x eq atk in elim-pair (post-rewriteh (tk-decl x' atk Γ) x eq prtk tk-decl T) λ T k → let T = post-rewrite-binder-tk Γ x eq tk-decl x' T atk k = post-rewrite-binder-tk Γ x eq tk-decl x' k atk in TpLam x' atk T , KdAbs x' atk k post-rewriteh Γ x eq prtk tk-decl (TpVar x') with env-lookup Γ x' ...| just (type-decl k , _) = TpVar x' , hnf Γ unfold-head-elab k ...| just (type-def mps _ T k , _) = TpVar x' , (hnf Γ unfold-head-elab (maybe-else id abs-expand-kind mps k)) ...| _ = TpVar x' , KdStar post-rewriteh Γ x eq prtk tk-decl T = T , KdStar {-# TERMINATING #-} post-rewrite : ctxt → var → (eq t₂ : term) → type → type post-rewrite Γ x eq t₂ T = subst Γ t₂ x (fst (post-rewriteh Γ x eq prtk tk-decl T)) where prtk : ctxt → var → term → tpkd → tpkd tk-decl : var → tpkd → ctxt → ctxt prtk Γ x t (Tkt T) = Tkt (fst (post-rewriteh Γ x t prtk tk-decl T)) prtk Γ x t (Tkk k) = Tkk (hnf Γ unfold-head-elab k) tk-decl x atk Γ = record Γ { i = trie-insert (ctxt.i Γ) x (either-else' atk term-decl type-decl , "" , "") } -- Functions for substituting the type T in ρ e @ x . T - t rewrite-at-t : Set → Set rewrite-at-t X = ctxt → var → maybe term → 𝔹 → X → X → X {-# TERMINATING #-} rewrite-at : rewrite-at-t type rewrite-at' : ∀ {ed} → rewrite-at-t ⟦ ed ⟧ → rewrite-at-t ⟦ ed ⟧ rewrite-ath : rewrite-at-t type rewrite-atₖ : rewrite-at-t kind rewrite-athₖ : rewrite-at-t kind rewrite-at-tk : rewrite-at-t tpkd rewrite-at-tk Γ x eq b (Tkt T) (Tkt T') = Tkt (rewrite-at Γ x eq b T T') rewrite-at-tk Γ x eq b (Tkk k) (Tkk k') = Tkk (rewrite-atₖ Γ x eq b k k') rewrite-at-tk Γ x eq b atk1 atk2 = atk1 rewrite-at = rewrite-at' rewrite-ath rewrite-atₖ = rewrite-at' rewrite-athₖ rewrite-head-types-match : ∀ {ed} → ctxt → var → (complete partial : ⟦ ed ⟧) → 𝔹 rewrite-head-types-match{TYPE} Γ x (TpApp T _) (TpApp T' _) = conv-type Γ T ([ Γ - Hole pi-gen / x ] T') rewrite-head-types-match Γ x T T' = tt rewrite-at' ra Γ x eq b T T' = if ~ is-free-in x T' then T else if b && ~ rewrite-head-types-match Γ x T T' then ra Γ x eq ff (hnf Γ unfold-head-elab T) (hnf Γ unfold-head-elab T') else ra Γ x eq b T T' rewrite-athₖ Γ x eq b (KdAbs x1 atk1 k1) (KdAbs x2 atk2 k2) = KdAbs x1 (rewrite-at-tk Γ x eq tt atk1 atk2) (rewrite-atₖ (ctxt-var-decl x1 Γ) x eq tt k1 $ rename-var Γ x2 x1 k2) rewrite-athₖ Γ x eq b KdStar KdStar = KdStar rewrite-athₖ Γ x eq tt k1 k2 = rewrite-atₖ Γ x eq ff (hnf Γ unfold-head-elab k1) (hnf Γ unfold-head-elab k2) rewrite-athₖ Γ x eq ff k1 k2 = k1 rewrite-ath Γ x eq b (TpAbs me1 x1 atk1 T1) (TpAbs me2 x2 atk2 T2) = TpAbs me1 x1 (rewrite-at-tk Γ x eq tt atk1 atk2) (rewrite-at (ctxt-var-decl x1 Γ) x eq tt T1 (rename-var Γ x2 x1 T2)) rewrite-ath Γ x eq b (TpIota x1 T1 T1') (TpIota x2 T2 T2') = TpIota x1 (rewrite-at Γ x eq tt T1 T2) (rewrite-at (ctxt-var-decl x1 Γ) x eq tt T1' (rename-var Γ x2 x1 T2')) rewrite-ath Γ x eq b (TpApp T1 (Ttp T1')) (TpApp T2 (Ttp T2')) = TpApp (rewrite-at Γ x eq b T1 T2) (Ttp (rewrite-at Γ x eq tt T1' T2')) rewrite-ath Γ x eq b (TpApp T1 (Ttm t1)) (TpApp T2 (Ttm t2)) = TpApp (rewrite-at Γ x eq b T1 T2) (Ttm (maybe-else' (ifMaybe (is-free-in x t2) eq) t1 λ eq → rewrite-mk-phi x eq t1 t2)) rewrite-ath Γ x eq b (TpEq t1 t1') (TpEq t2 t2') = TpEq t2 t2' rewrite-ath Γ x eq b (TpLam x1 atk1 T1) (TpLam x2 atk2 T2) = TpLam x1 (rewrite-at-tk Γ x eq tt atk1 atk2) (rewrite-at (ctxt-var-decl x1 Γ) x eq tt T1 (rename-var Γ x2 x1 T2)) rewrite-ath Γ x eq b (TpVar x1) (TpVar x2) = TpVar x1 rewrite-ath Γ x eq b (TpHole pi1) (TpHole pi2) = TpHole pi1 rewrite-ath Γ x eq tt T1 T2 = rewrite-at Γ x eq ff (hnf Γ unfold-head-elab T1) (hnf Γ unfold-head-elab T2) rewrite-ath Γ x eq ff T1 T2 = T1 hnf-ctr : ctxt → var → type → type hnf-ctr Γ x T = hnf Γ unfold-no-defs (rewrite-at Γ x nothing tt (hnf Γ (unfold tt ff ff) T) $ hnf Γ (record unfold-all {unfold-erase = ff}) T) {-# TERMINATING #-} refine-term : ctxt → tmtp → var → term → term refine-type : ctxt → tmtp → var → type → type refine-typeh : ctxt → tmtp → var → type → type refine-kind : ctxt → tmtp → var → kind → kind refine : ∀ {ed} → ctxt → tmtp → var → ⟦ ed ⟧ → ⟦ ed ⟧ refine {TERM} = refine-term refine {TYPE} = refine-type refine {KIND} = refine-kind refine-term Γ (Ttp T) to t = t refine-term Γ (Ttm t') to t with rewrite-term t Γ ff nothing nothing t' to 0 ...| t'' , zero , _ = t ...| t'' , suc _ , _ = t'' refine-type Γ fm to T = if either-else' fm (const ff) (conv-type Γ T) then TpVar to else refine-typeh Γ fm to T refine-typeh Γ fm to (TpAbs me x atk T) = let x' = fresh-var Γ x in TpAbs me x' (refine Γ fm to -tk atk) (refine-type (ctxt-var-decl x' Γ) fm to (rename-var Γ x x' T)) refine-typeh Γ fm to (TpIota x T T') = let x' = fresh-var Γ x in TpIota x' (refine-type Γ fm to T) (refine-type (ctxt-var-decl x' Γ) fm to (rename-var Γ x x' T')) refine-typeh Γ fm to (TpApp T tT) = TpApp (refine-type Γ fm to T) (refine Γ fm to -tT tT) refine-typeh Γ fm to (TpEq t₁ t₂) = TpEq (refine-term Γ fm to t₁) (refine-term Γ fm to t₂) refine-typeh Γ fm to (TpLam x atk T) = let x' = fresh-var Γ x in TpLam x' (refine Γ fm to -tk atk) (refine-type (ctxt-var-decl x' Γ) fm to (rename-var Γ x x' T)) refine-typeh Γ fm to (TpHole pi) = TpHole pi refine-typeh Γ fm to (TpVar x) = TpVar x refine-kind Γ fm to (KdAbs x atk k) = let x' = fresh-var Γ x in KdAbs x (refine Γ fm to -tk atk) (refine-kind (ctxt-var-decl x' Γ) fm to (rename-var Γ x x' k)) refine-kind Γ fm to (KdHole pi) = KdHole pi refine-kind Γ fm to KdStar = KdStar refine-motive : ctxt → indices → (asᵢ : 𝕃 tmtp) → (expected : type) → type refine-motive Γ is as = foldr (λ where (Index x atk , ty) f Γ T → let body = f (ctxt-var-decl x Γ) $ refine-type (ctxt-var-decl x Γ) ty x T x' = if is-free-in x body then x else ignored-var in TpLam x' atk body) (λ Γ T → T) (zip (rename-indices Γ is as) as) Γ -- Given a context, the (qualified) scrutinee, the (qualified) datatype name, -- the datatype's indices, the arguments for module parameter instantiation, -- the arguments for the indices in the type of the scrutinee, and the expected type, -- calculate a possibly ill-typed motive that is approximately abstracted over the -- indices and the scrutinee itself. {- refine-motive : ctxt → (scrutinee : term) → (datatype-name : var) → indices → (mod-as : 𝕃 tty) → (idx-as : 𝕃 tty) → (expected : type) → type refine-motive Γ t name is asₚ asᵢ = let x = fresh-var (add-indices-to-ctxt is Γ) "x" atkₓ = Tkt $ indices-to-tpapps is $ recompose-tpapps asₚ $ TpVar pi-gen name as' = asᵢ ++ [ tterm t ] is' = rename? Γ empty-renamectxt (is ++ [ Index x atkₓ ]) as' as = zip is' as' in foldr (λ where (Index x atk , ty) f Γ T → TpLambda pi-gen pi-gen x atk $ f (ctxt-var-decl x Γ) $ refine-type (ctxt-var-decl x Γ) ty x T) (λ Γ T → T) as Γ where get-var : var → tty → var get-var x (tterm (Var _ x')) = maybe-else (unqual-local x') id $ var-suffix x' get-var x (ttype (TpVar _ x')) = maybe-else (unqual-local x') id $ var-suffix x' get-var x _ = x rename? : ctxt → renamectxt → indices → 𝕃 tty → indices rename? Γ ρ (Index x atk :: is) (ty :: tys) = let x' = get-var x ty in Index x' (subst-renamectxt Γ ρ atk) :: rename? (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') is tys rename? _ _ _ _ = [] -}
{ "alphanum_fraction": 0.6237264829, "avg_line_length": 42.8927613941, "ext": "agda", "hexsha": "c873cac951682a0ea78e7c75279d83980b0fef91", "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": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ice1k/cedille", "max_forks_repo_path": "src/rewriting.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "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": "ice1k/cedille", "max_issues_repo_path": "src/rewriting.agda", "max_line_length": 156, "max_stars_count": null, "max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ice1k/cedille", "max_stars_repo_path": "src/rewriting.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5984, "size": 15999 }
open import Agda.Builtin.Nat open import Agda.Builtin.Unit open import Agda.Builtin.Reflection renaming (bindTC to _>>=_) open import Agda.Builtin.List open import Agda.Builtin.Sigma open import Agda.Builtin.Equality infix 0 case_of_ case_of_ : ∀ {a b}{A : Set a}{B : Set b} → A → (A → B) → B case x of f = f x map : ∀ {a b}{A : Set a}{B : Set b} → (A → B) → List A → List B map f [] = [] map f (x ∷ xs) = f x ∷ map f xs reverse : ∀ {a}{A : Set a} → List A → List A reverse {A = A} xs = reverseAcc xs [] where reverseAcc : List A → List A → List A reverseAcc [] a = a reverseAcc (x ∷ xs) a = reverseAcc xs (x ∷ a) data Maybe (X : Set) : Set where nothing : Maybe X just : X → Maybe X data Fin : Nat → Set where zero : ∀ {n} → Fin (suc n) suc : ∀ {n} → Fin n → Fin (suc n) record RVec {a} (X : Set a) (n : Nat) : Set a where constructor vec field sel : Fin n → X test-rvec : Nat → RVec Nat 5 test-rvec x = vec λ _ → x get-len : Definition → TC Term get-len (function (clause _ _ (con (quote vec) (_ ∷ _ ∷ (arg _ a) ∷ _)) ∷ [])) = quoteTC a get-len _ = quoteTC "ERROR" macro def-reg : Name → Term → TC ⊤ def-reg n hole = do d ← getDefinition n l ← get-len d unify hole l def-recons : Name → Term → TC ⊤ def-recons n hole = do d ← withReconstructed (getDefinition n) l ← get-len d unify hole l -- normaliseR perserves reconstructed expressions. def-normR : Name → Term → TC ⊤ def-normR n hole = do (function (clause tel ps t ∷ [])) ← withReconstructed (getDefinition n) where _ → quoteTC "ERROR" >>= unify hole let ctx = map snd tel t ← inContext (reverse ctx) (withReconstructed (normalise t)) let d = function (clause tel ps t ∷ []) get-len d >>= unify hole -- normaliseR perserves reconstructed expressions. def-redR : Name → Term → TC ⊤ def-redR n hole = do (function (clause tel ps t ∷ [])) ← withReconstructed (getDefinition n) where _ → quoteTC "ERROR" >>= unify hole let ctx = map snd tel t ← inContext (reverse ctx) (withReconstructed (reduce t)) let d = function (clause tel ps t ∷ []) get-len d >>= unify hole test₁ : unknown ≡ def-reg test-rvec test₁ = refl test₂ : (lit (nat 5)) ≡ def-recons test-rvec test₂ = refl test₃ : (lit (nat 5)) ≡ def-normR test-rvec test₃ = refl test₄ : (lit (nat 5)) ≡ def-redR test-rvec test₄ = refl pictx : Term → List (Arg Type) pictx (pi a (abs s x)) = a ∷ pictx x pictx _ = [] macro get-ctx : Name → Term → TC ⊤ get-ctx n hole = do t ← getType n let c = pictx t c ← withReconstructed (inContext (reverse c) getContext) quoteTC c >>= unify hole bar : (A : Set) (eq : [] {A = A} ≡ []) (x : Nat) → ⊤ bar _ _ _ = tt -- if getContext were to work incorrectly, this function wouldn't typecheck test₅ : List (Arg Type) test₅ = get-ctx bar data NotAVec (X : Set) (y : Nat) : Set where mk : NotAVec X y f : ∀ {n} → NotAVec Nat n → NotAVec Nat (suc n) f mk = mk macro chk-type : Term → TC ⊤ chk-type hole = do T ← quoteTC (NotAVec Nat 5) t ← quoteTC (mk {X = Nat} {y = 5}) (con _ (_ ∷ arg _ t ∷ [])) ← withReconstructed (checkType t T) where _ → quoteTC "ERROR" >>= unify hole quoteTC t >>= unify hole -- checkType would leave unknown's without the call to withReconstructed test₆ : chk-type ≡ lit (nat 5) test₆ = refl q : [] {A = Nat} ≡ [] {A = Nat} q = refl macro inf-type : Term → TC ⊤ inf-type hole = do (function (clause _ _ b ∷ [])) ← withReconstructed (getDefinition (quote q)) where _ → quoteTC "ERROR" >>= unify hole (def _ (l ∷ L ∷ e₁ ∷ e₂ ∷ [])) ← withReconstructed (inferType b) where _ → quoteTC "ERROR" >>= unify hole (arg _ (con _ (_ ∷ (arg _ N) ∷ []))) ← returnTC e₁ where _ → quoteTC "ERROR" >>= unify hole quoteTC N >>= unify hole -- inferType would not reconstruct the arguments within the type -- without the call to withReconstructed test₇ : inf-type ≡ def (quote Nat) [] test₇ = refl
{ "alphanum_fraction": 0.5981701286, "avg_line_length": 26.2597402597, "ext": "agda", "hexsha": "59237ceac539e1305e37ed6382bd30764d333bd5", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/test-recons.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/test-recons.agda", "max_line_length": 80, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/test-recons.agda", "max_stars_repo_stars_event_max_datetime": "2020-04-26T09:35:17.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-26T09:35:17.000Z", "num_tokens": 1379, "size": 4044 }
module Pi.Invariants where open import Data.Empty open import Data.Unit open import Data.Sum open import Data.Product open import Data.List as L hiding (_∷_) open import Relation.Binary.PropositionalEquality open import Pi.Syntax open import Pi.Opsem open import Pi.NoRepeat -- Get the type of the deepest context get𝕌 : ∀ {A B} → Context {A} {B} → 𝕌 × 𝕌 get𝕌 {A} {B} ☐ = A , B get𝕌 (☐⨾ c₂ • κ) = get𝕌 κ get𝕌 (c₁ ⨾☐• κ) = get𝕌 κ get𝕌 (☐⊕ c₂ • κ) = get𝕌 κ get𝕌 (c₁ ⊕☐• κ) = get𝕌 κ get𝕌 (☐⊗[ c₂ , x ]• κ) = get𝕌 κ get𝕌 ([ c₁ , x ]⊗☐• κ) = get𝕌 κ get𝕌State : (st : State) → 𝕌 × 𝕌 get𝕌State ⟨ c ∣ v ∣ κ ⟩ = get𝕌 κ get𝕌State [ c ∣ v ∣ κ ] = get𝕌 κ -- Reconstruct the whole combinator from context getℂκ : ∀ {A B} → A ↔ B → Context {A} {B} → ∃[ C ] ∃[ D ] (C ↔ D) getℂκ c ☐ = _ , _ , c getℂκ c (☐⨾ c₂ • κ) = getℂκ (c ⨾ c₂) κ getℂκ c (c₁ ⨾☐• κ) = getℂκ (c₁ ⨾ c) κ getℂκ c (☐⊕ c₂ • κ) = getℂκ (c ⊕ c₂) κ getℂκ c (c₁ ⊕☐• κ) = getℂκ (c₁ ⊕ c) κ getℂκ c (☐⊗[ c₂ , x ]• κ) = getℂκ (c ⊗ c₂) κ getℂκ c ([ c₁ , x ]⊗☐• κ) = getℂκ (c₁ ⊗ c) κ getℂ : State → ∃[ A ] ∃[ B ] (A ↔ B) getℂ ⟨ c ∣ _ ∣ κ ⟩ = getℂκ c κ getℂ [ c ∣ _ ∣ κ ] = getℂκ c κ -- The reconstructed combinator stays the same ℂInvariant : ∀ {st st'} → st ↦ st' → getℂ st ≡ getℂ st' ℂInvariant ↦₁ = refl ℂInvariant ↦₂ = refl ℂInvariant ↦₃ = refl ℂInvariant ↦₄ = refl ℂInvariant ↦₅ = refl ℂInvariant ↦₆ = refl ℂInvariant ↦₇ = refl ℂInvariant ↦₈ = refl ℂInvariant ↦₉ = refl ℂInvariant ↦₁₀ = refl ℂInvariant ↦₁₁ = refl ℂInvariant ↦₁₂ = refl ℂInvariant* : ∀ {st st'} → st ↦* st' → getℂ st ≡ getℂ st' ℂInvariant* ◾ = refl ℂInvariant* (r ∷ rs) = trans (ℂInvariant r) (ℂInvariant* rs) -- Append a context to another context appendκ : ∀ {A B} → (ctx : Context {A} {B}) → let (C , D) = get𝕌 ctx in Context {C} {D} → Context {A} {B} appendκ ☐ ctx = ctx appendκ (☐⨾ c₂ • κ) ctx = ☐⨾ c₂ • appendκ κ ctx appendκ (c₁ ⨾☐• κ) ctx = c₁ ⨾☐• appendκ κ ctx appendκ (☐⊕ c₂ • κ) ctx = ☐⊕ c₂ • appendκ κ ctx appendκ (c₁ ⊕☐• κ) ctx = c₁ ⊕☐• appendκ κ ctx appendκ (☐⊗[ c₂ , x ]• κ) ctx = ☐⊗[ c₂ , x ]• appendκ κ ctx appendκ ([ c₁ , x ]⊗☐• κ) ctx = [ c₁ , x ]⊗☐• appendκ κ ctx appendκState : ∀ st → let (A , B) = get𝕌State st in Context {A} {B} → State appendκState ⟨ c ∣ v ∣ κ ⟩ ctx = ⟨ c ∣ v ∣ appendκ κ ctx ⟩ appendκState [ c ∣ v ∣ κ ] ctx = [ c ∣ v ∣ appendκ κ ctx ] -- The type of context does not change during execution 𝕌Invariant : ∀ {st st'} → st ↦ st' → get𝕌State st ≡ get𝕌State st' 𝕌Invariant ↦₁ = refl 𝕌Invariant ↦₂ = refl 𝕌Invariant ↦₃ = refl 𝕌Invariant ↦₄ = refl 𝕌Invariant ↦₅ = refl 𝕌Invariant ↦₆ = refl 𝕌Invariant ↦₇ = refl 𝕌Invariant ↦₈ = refl 𝕌Invariant ↦₉ = refl 𝕌Invariant ↦₁₀ = refl 𝕌Invariant ↦₁₁ = refl 𝕌Invariant ↦₁₂ = refl 𝕌Invariant* : ∀ {st st'} → st ↦* st' → get𝕌State st ≡ get𝕌State st' 𝕌Invariant* ◾ = refl 𝕌Invariant* (r ∷ rs) = trans (𝕌Invariant r) (𝕌Invariant* rs) -- Appending context does not affect reductions appendκ↦ : ∀ {st st'} → (r : st ↦ st') (eq : get𝕌State st ≡ get𝕌State st') → (κ : Context {proj₁ (get𝕌State st)} {proj₂ (get𝕌State st)}) → appendκState st κ ↦ appendκState st' (subst (λ {(A , B) → Context {A} {B}}) eq κ) appendκ↦ ↦₁ refl κ = ↦₁ appendκ↦ ↦₂ refl κ = ↦₂ appendκ↦ ↦₃ refl κ = ↦₃ appendκ↦ ↦₄ refl κ = ↦₄ appendκ↦ ↦₅ refl κ = ↦₅ appendκ↦ ↦₆ refl κ = ↦₆ appendκ↦ ↦₇ refl κ = ↦₇ appendκ↦ ↦₈ refl κ = ↦₈ appendκ↦ ↦₉ refl κ = ↦₉ appendκ↦ ↦₁₀ refl κ = ↦₁₀ appendκ↦ ↦₁₁ refl κ = ↦₁₁ appendκ↦ ↦₁₂ refl κ = ↦₁₂ appendκ↦* : ∀ {st st'} → (rs : st ↦* st') (eq : get𝕌State st ≡ get𝕌State st') → (κ : Context {proj₁ (get𝕌State st)} {proj₂ (get𝕌State st)}) → appendκState st κ ↦* appendκState st' (subst (λ {(A , B) → Context {A} {B}}) eq κ) appendκ↦* ◾ refl ctx = ◾ appendκ↦* (↦₁ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₁ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₂ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₂ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₃ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₃ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₄ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₄ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₅ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₅ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₆ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₆ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₇ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₇ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₈ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₈ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₉ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₉ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₁₀{κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₁₀ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₁₁{κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₁₁ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦₁₂{κ = κ} ∷ rs) eq ctx = appendκ↦ (↦₁₂ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx
{ "alphanum_fraction": 0.5694530444, "avg_line_length": 38.1496062992, "ext": "agda", "hexsha": "4090184ee9b85f5b828c4c47798b9114f0257de1", "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/Invariants.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/Invariants.agda", "max_line_length": 94, "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/Invariants.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": 2393, "size": 4845 }
module Thesis.SIRelBigStep.ArithExtra where open import Relation.Binary.PropositionalEquality open import Data.Nat public open import Data.Nat.Properties public open import Relation.Binary hiding (_⇒_) lt1 : ∀ {k n} → k < n → k ≤ n lt1 (s≤s p) = ≤-step p m∸n≤m : ∀ m n → m ∸ n ≤ m m∸n≤m m zero = ≤-refl m∸n≤m zero (suc n) = z≤n m∸n≤m (suc m) (suc n) = ≤-step (m∸n≤m m n) suc∸ : ∀ m n → n ≤ m → suc (m ∸ n) ≡ suc m ∸ n suc∸ m zero z≤n = refl suc∸ (suc m) (suc n) (s≤s n≤m) = suc∸ m n n≤m sub∸ : ∀ m n o → m + n ≤ o → n ≤ o ∸ m sub∸ m n o n+m≤o rewrite +-comm m n | cong (_≤ o ∸ m) (sym (m+n∸n≡m n m)) = ∸-mono n+m≤o (≤-refl {m})
{ "alphanum_fraction": 0.5687203791, "avg_line_length": 28.7727272727, "ext": "agda", "hexsha": "d6413a375976927831cee07cbf7383e103e4f813", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Thesis/SIRelBigStep/ArithExtra.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Thesis/SIRelBigStep/ArithExtra.agda", "max_line_length": 101, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Thesis/SIRelBigStep/ArithExtra.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 321, "size": 633 }
------------------------------------------------------------------------ -- An implementation of the Fibonacci sequence using tail ------------------------------------------------------------------------ module SingletonChunks where open import Codata.Musical.Notation open import Codata.Musical.Stream as S using (Stream; _≈_; _∷_) open import Data.Bool open import Data.Nat open import Data.Vec as V using (Vec; []; _∷_) import Relation.Binary.PropositionalEquality as P ------------------------------------------------------------------------ -- Stream programs -- StreamP b A encodes programs generating streams in chunks of size -- (at least) 1. The first chunk may be empty if b is false. infixr 5 _∷_ data StreamP : Bool → Set → Set₁ where [_] : ∀ {A} (xs : ∞ (StreamP true A)) → StreamP false A _∷_ : ∀ {A} (x : A) (xs : StreamP false A) → StreamP true A forget : ∀ {A} (xs : StreamP true A) → StreamP false A tail : ∀ {A} (xs : StreamP true A) → StreamP false A zipWith : ∀ {b A B C} (f : A → B → C) (xs : StreamP b A) (ys : StreamP b B) → StreamP b C data StreamW : Bool → Set → Set₁ where [_] : ∀ {A} (xs : StreamP true A) → StreamW false A _∷_ : ∀ {A} (x : A) (xs : StreamW false A) → StreamW true A forgetW : ∀ {A} → StreamW true A → StreamW false A forgetW (x ∷ [ xs ]) = [ x ∷ forget xs ] tailW : ∀ {A} → StreamW true A → StreamW false A tailW (x ∷ xs) = xs zipWithW : ∀ {b A B C} → (A → B → C) → StreamW b A → StreamW b B → StreamW b C zipWithW f [ xs ] [ ys ] = [ zipWith f xs ys ] zipWithW f (x ∷ xs) (y ∷ ys) = f x y ∷ zipWithW f xs ys whnf : ∀ {b A} → StreamP b A → StreamW b A whnf [ xs ] = [ ♭ xs ] whnf (x ∷ xs) = x ∷ whnf xs whnf (forget xs) = forgetW (whnf xs) whnf (tail xs) = tailW (whnf xs) whnf (zipWith f xs ys) = zipWithW f (whnf xs) (whnf ys) mutual ⟦_⟧W : ∀ {A} → StreamW true A → Stream A ⟦ x ∷ [ xs ] ⟧W = x ∷ ♯ ⟦ xs ⟧P ⟦_⟧P : ∀ {A} → StreamP true A → Stream A ⟦ xs ⟧P = ⟦ whnf xs ⟧W ------------------------------------------------------------------------ -- The Fibonacci sequence fib : StreamP true ℕ fib = 0 ∷ [ ♯ (1 ∷ zipWith _+_ (forget fib) (tail fib)) ] ------------------------------------------------------------------------ -- The definition of fib is correct -- ⟦_⟧ is homomorphic with respect to zipWith/S.zipWith. zipWith-hom : ∀ {A B C} (_∙_ : A → B → C) xs ys → ⟦ zipWith _∙_ xs ys ⟧P ≈ S.zipWith _∙_ ⟦ xs ⟧P ⟦ ys ⟧P zipWith-hom _∙_ xs ys with whnf xs | whnf ys zipWith-hom _∙_ xs ys | x ∷ [ xs′ ] | y ∷ [ ys′ ] = P.refl ∷ ♯ zipWith-hom _∙_ xs′ ys′ -- forget is the identity on streams. open import MapIterate as M using (_≈P_; _∷_; _≈⟨_⟩_; _∎) open import Relation.Binary.PropositionalEquality as P using (_≡_; [_]) forget-lemma : ∀ {A} x (xs : StreamP true A) → ⟦ x ∷ forget xs ⟧P ≈P x ∷ ♯ ⟦ xs ⟧P forget-lemma x xs with whnf xs | P.inspect whnf xs ... | y ∷ [ ys ] | [ eq ] = x ∷ ♯ helper eq where helper : whnf xs ≡ y ∷ [ ys ] → ⟦ y ∷ forget ys ⟧P ≈P ⟦ xs ⟧P helper eq rewrite eq = _ ≈⟨ forget-lemma y ys ⟩ (y ∷ ♯ (_ ∎)) -- The stream ⟦ fib ⟧P satisfies its intended defining equation. open import Relation.Binary module SS {A : Set} = Setoid (S.setoid A) fib-correct : ⟦ fib ⟧P ≈ 0 ∷ ♯ (1 ∷ ♯ S.zipWith _+_ ⟦ fib ⟧P (S.tail ⟦ fib ⟧P)) fib-correct = P.refl ∷ ♯ (P.refl ∷ ♯ SS.trans (zipWith-hom _+_ (0 ∷ forget fib′) fib′) (S.zipWith-cong _+_ (SS.trans (M.soundP (forget-lemma 0 fib′)) (P.refl ∷ ♯ SS.refl)) SS.refl)) where fib′ = 1 ∷ zipWith _+_ (forget fib) (tail fib) ------------------------------------------------------------------------ -- An equality proof language infix 4 _≈[_]P_ _≈[_]W_ infix 3 _∎ infixr 2 _≈⟨_⟩_ data _≈[_]P_ : {A : Set} → Stream A → Bool → Stream A → Set₁ where [_] : ∀ {A} {xs ys : Stream A} (xs≈ys : ∞ (xs ≈[ true ]P ys)) → xs ≈[ false ]P ys _∷_ : ∀ {b A} (x : A) {xs ys : ∞ (Stream A)} (xs≈ys : ♭ xs ≈[ b ]P ♭ ys) → x ∷ xs ≈[ true ]P x ∷ ys forget : ∀ {A} {xs ys : Stream A} (xs≈ys : xs ≈[ true ]P ys) → xs ≈[ false ]P ys _≈⟨_⟩_ : ∀ {b A} (xs : Stream A) {ys zs} (xs≈ys : xs ≈[ b ]P ys) (ys≈zs : ys ≈[ b ]P zs) → xs ≈[ b ]P zs _∎ : ∀ {A} (xs : Stream A) → xs ≈[ true ]P xs tail : ∀ {A} {xs ys : Stream A} (xs≈ys : xs ≈[ true ]P ys) → S.tail xs ≈[ false ]P S.tail ys zipWith : ∀ {b A B C} (f : A → B → C) {xs xs′ ys ys′} (xs≈xs′ : xs ≈[ b ]P xs′) (ys≈ys′ : ys ≈[ b ]P ys′) → S.zipWith f xs ys ≈[ b ]P S.zipWith f xs′ ys′ -- Completeness. completeP : ∀ {A : Set} {xs ys : Stream A} → xs ≈ ys → xs ≈[ true ]P ys completeP (P.refl ∷ xs≈ys) = _ ∷ [ ♯ completeP (♭ xs≈ys) ] -- Weak head normal forms. data _≈[_]W_ {A : Set} : Stream A → Bool → Stream A → Set₁ where [_] : {xs ys : Stream A} (xs≈ys : xs ≈[ true ]P ys) → xs ≈[ false ]W ys _∷_ : ∀ (x : A) {xs ys} (xs≈ys : ♭ xs ≈[ true ]P ♭ ys) → x ∷ xs ≈[ true ]W x ∷ ys consW≈ : ∀ {A b} (x : A) {xs ys} → ♭ xs ≈[ b ]W ♭ ys → x ∷ xs ≈[ true ]W x ∷ ys consW≈ x xs≈ys = x ∷ helper xs≈ys where helper : ∀ {A b} {xs ys : Stream A} → xs ≈[ b ]W ys → xs ≈[ true ]P ys helper [ xs≈ys ] = xs≈ys helper (x ∷ xs≈ys) = x ∷ xs≈ys forgetW≈ : ∀ {A} {xs ys : Stream A} → xs ≈[ true ]W ys → xs ≈[ false ]W ys forgetW≈ (x ∷ xs≈ys) = [ x ∷ forget xs≈ys ] transW≈ : ∀ {A b} {xs ys zs : Stream A} → xs ≈[ b ]W ys → ys ≈[ b ]W zs → xs ≈[ b ]W zs transW≈ [ xs≈ys ] [ ys≈zs ] = [ _ ≈⟨ xs≈ys ⟩ ys≈zs ] transW≈ (x ∷ xs≈ys) (.x ∷ ys≈zs) = x ∷ (_ ≈⟨ xs≈ys ⟩ ys≈zs) reflW≈ : ∀ {A} (xs : Stream A) → xs ≈[ true ]W xs reflW≈ (x ∷ xs) = x ∷ (♭ xs ∎) tailW≈ : ∀ {A} {xs ys : Stream A} → xs ≈[ true ]W ys → S.tail xs ≈[ false ]W S.tail ys tailW≈ (x ∷ xs≈ys) = [ xs≈ys ] zipWithW≈ : ∀ {A B C b} (_∙_ : A → B → C) {xs₁ ys₁ xs₂ ys₂} → xs₁ ≈[ b ]W ys₁ → xs₂ ≈[ b ]W ys₂ → S.zipWith _∙_ xs₁ xs₂ ≈[ b ]W S.zipWith _∙_ ys₁ ys₂ zipWithW≈ _∙_ [ xs₁≈ys₁ ] [ xs₂≈ys₂ ] = [ zipWith _∙_ xs₁≈ys₁ xs₂≈ys₂ ] zipWithW≈ _∙_ (x₁ ∷ xs₁≈ys₁) (x₂ ∷ xs₂≈ys₂) = (x₁ ∙ x₂) ∷ zipWith _∙_ xs₁≈ys₁ xs₂≈ys₂ whnf≈ : ∀ {A : Set} {xs ys : Stream A} {b} → xs ≈[ b ]P ys → xs ≈[ b ]W ys whnf≈ [ xs≈ys ] = [ ♭ xs≈ys ] whnf≈ (x ∷ xs≈ys) = consW≈ x (whnf≈ xs≈ys) whnf≈ (forget xs≈ys) = forgetW≈ (whnf≈ xs≈ys) whnf≈ (xs ≈⟨ xs≈ys ⟩ ys≈zs) = transW≈ (whnf≈ xs≈ys) (whnf≈ ys≈zs) whnf≈ (xs ∎) = reflW≈ xs whnf≈ (tail xs≈ys) = tailW≈ (whnf≈ xs≈ys) whnf≈ (zipWith f xs≈xs′ ys≈ys′) = zipWithW≈ f (whnf≈ xs≈xs′) (whnf≈ ys≈ys′) -- Soundness. mutual soundW : {A : Set} {xs ys : Stream A} → xs ≈[ true ]W ys → xs ≈ ys soundW (x ∷ xs≈ys) = P.refl ∷ ♯ soundP xs≈ys soundP : {A : Set} {xs ys : Stream A} → xs ≈[ true ]P ys → xs ≈ ys soundP xs≈ys = soundW (whnf≈ xs≈ys) ------------------------------------------------------------------------ -- The equation given for fib has a unique solution fib-rhs : Stream ℕ → Stream ℕ fib-rhs ns = 0 ∷ ♯ (1 ∷ ♯ S.zipWith _+_ ns (S.tail ns)) fib-unique : ∀ ms ns → ms ≈ fib-rhs ms → ns ≈ fib-rhs ns → ms ≈[ true ]P ns fib-unique ms ns ms≈ ns≈ = ms ≈⟨ completeP ms≈ ⟩ fib-rhs ms ≈⟨ 0 ∷ [ ♯ (1 ∷ zipWith _+_ (forget (fib-unique ms ns ms≈ ns≈)) (tail (fib-unique ms ns ms≈ ns≈))) ] ⟩ fib-rhs ns ≈⟨ completeP (SS.sym ns≈) ⟩ ns ∎
{ "alphanum_fraction": 0.4771707575, "avg_line_length": 36.2583732057, "ext": "agda", "hexsha": "ffe6884ca9994255c6e2303ea3b1122a083b0f2b", "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": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/codata", "max_forks_repo_path": "SingletonChunks.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "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/codata", "max_issues_repo_path": "SingletonChunks.agda", "max_line_length": 79, "max_stars_count": 1, "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/codata", "max_stars_repo_path": "SingletonChunks.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "num_tokens": 3143, "size": 7578 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Sn.Base where open import Cubical.HITs.Susp open import Cubical.Foundations.Pointed open import Cubical.Data.Nat open import Cubical.Data.NatMinusOne open import Cubical.Data.Empty open import Cubical.Foundations.Prelude S : ℕ₋₁ → Type₀ S neg1 = ⊥ S (ℕ→ℕ₋₁ n) = Susp (S (-1+ n)) S₊ : ℕ → Type₀ S₊ n = S (ℕ→ℕ₋₁ n) -- Pointed version S₊∙ : (n : ℕ) → Pointed₀ S₊∙ n = (S₊ n) , north
{ "alphanum_fraction": 0.6791208791, "avg_line_length": 21.6666666667, "ext": "agda", "hexsha": "ffaa31527cd29405a4e1c143a6a097a19d0206f2", "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/HITs/Sn/Base.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/HITs/Sn/Base.agda", "max_line_length": 50, "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/HITs/Sn/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 180, "size": 455 }
module Function.Domains.Functions where import Lvl open import Function.Domains open import Function.Domains.Id open import Structure.Relator.Properties open import Structure.Setoid open import Type open import Type.Dependent private variable ℓₒ₁ ℓₒ₂ ℓₑ₁ ℓₑ₂ : Lvl.Level module _ {X : Type{ℓₒ₁}} {Y : Type{ℓₒ₂}} where module ⊶ where private variable f : X → Y -- The function which shrinks the given function's codomain to its image. shrink : (f : X → Y) → (X → (⊶ f)) shrink f(x) = intro (f(x)) (intro x) -- Applies an argument of type X to a function of type ((⊶ f) → Y) according to the bijection of {X,(⊶ f)} by f. apply : X → ((⊶ f) → Y) → Y apply{f} x imgfn = imgfn (shrink f(x)) fn : (⊶ f) → (X → Y) fn{f} _ = f arg : (⊶ f) → X arg (intro _ (intro x)) = x -- Could be interpreted as an identity function with an enlarged codomain. -- The value of (⊶ f) interpreted as contained in the "set" Y. value : (⊶ f) → Y value (intro y _) = y value-proof : ⦃ equiv-Y : Equiv{ℓₑ₂}(Y) ⦄ → ∀{x} → (value(intro (f(x)) (intro{f = f} x)) ≡ f(x)) value-proof = reflexivity(_≡_) arg-proof : ⦃ equiv-X : Equiv{ℓₑ₁}(X) ⦄ → ∀{x} → (arg(intro (f(x)) (intro{f = f} x)) ≡ x) arg-proof = reflexivity(_≡_) -- TODO: Problem with levels -- TODO: [⊶]-function-surjective : ∀{f : X → Y} → Surjective([⊶]-function(f)) -- .[⊶]-function-surjective : ∀{f : X → Y}{y : (⊶ f)} → ∃(x ↦ [⊶]-arg(([⊶]-fn f)(x)) ≡ [⊶]-arg(y)) -- [⊶]-function-surjective {f} {intro(y-value) ⦃ [∃]-intro (x) ⦃ proof ⦄ ⦄} = -- Lang.Irrelevance.axiom( -- ([∃]-intro (x) -- ⦃ [≡]-with-specific {_}{_} {_}{_} {f(x)} {y-value} -- (expr ↦ \ ⦃ [≡]-intro ⦄ → \ ⦃ [≡]-intro ⦄ → -- (intro -- (expr) -- ⦃ [∃]-intro (x) ⦃ [≡]-intro :of: (f(x) ≡ y-value) ⦄ ⦄ -- ) -- ) -- (proof :of: (f(x) ≡ y-value)) -- ⦄ -- ) -- ) -- ∃(x: X). f(x) ≡ obj(y) //proof: -- Take x: X -- f(x) ≡ obj(y) -- ⇒ intro(f(x)) ⦃ [∃]-intro(x) ⦃ e ⦄ ⦄ ≡ intro(obj(y)) ⦃ [∃]-intro(x) ⦃ e ⦄ ⦄ -- [⊶]-function-injective : ∀{X}{Y}{f : X → Y} → Injective(f) → Injective([⊶]-function(f)) -- [⊶]-function-injective{_}{_}{f} {x₁}{x₂} [≡]-intro = [≡]-intro
{ "alphanum_fraction": 0.5045672031, "avg_line_length": 34.8333333333, "ext": "agda", "hexsha": "40da83183826d6080a712e6cb95fcfcf9a5022e5", "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": "Function/Domains/Functions.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Lolirofle/stuff-in-agda", "max_issues_repo_path": "Function/Domains/Functions.agda", "max_line_length": 116, "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": "Function/Domains/Functions.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z", "num_tokens": 938, "size": 2299 }
-- {-# OPTIONS --show-implicit #-} -- {-# OPTIONS -v tc.meta:50 -v tc.conv:20 -v tc.conv.type:50 #-} module Issue659 where postulate Level : Set lzero : Level lsuc : Level → Level _⊔_ : Level → Level → Level {-# BUILTIN LEVEL Level #-} {-# BUILTIN LEVELZERO lzero #-} {-# BUILTIN LEVELSUC lsuc #-} {-# BUILTIN LEVELMAX _⊔_ #-} record R (ℓ : Level) : Set ℓ where postulate r : ∀ ℓ → R ℓ module M (r : ∀ ℓ → R ℓ) where data D (ℓ : Level) : Set ℓ where id : ∀ {a} {A : Set a} → A → A id x = x data K : Set where k₁ k₂ : K P : ∀ {ℓ} → K → Set ℓ → Set ℓ P k₁ A = A → A P k₂ A = D _ open M r postulate Foo : ∀ {k a} {A : Set a} → P k A → Set Bar : Set Bar = Foo M.id -- Could this error message be improved? -- Setω is not a valid type. -- when checking that the expression M.id has type P M.k₁ _34 -- New error: -- -- ((r₁ : (ℓ : Level) → R ℓ) {a : Level} {A : Set a} → A → A) !=< -- (P {_33} _32 _34) -- because this would result in an invalid use of Setω -- when checking that the expression M.id has type (P {_33} _32 _34)
{ "alphanum_fraction": 0.5640074212, "avg_line_length": 19.962962963, "ext": "agda", "hexsha": "dedcd678c95826899562f6a3efe19783c330e42f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "test/fail/Issue659.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "np/agda-git-experiment", "max_issues_repo_path": "test/fail/Issue659.agda", "max_line_length": 68, "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/Issue659.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": 403, "size": 1078 }
{-# OPTIONS --without-K --safe #-} module Data.Binary.Proofs.Addition where open import Relation.Binary.PropositionalEquality open import Data.Binary.Operations.Unary open import Data.Binary.Operations.Addition open import Data.Binary.Proofs.Unary open import Data.Binary.Proofs.Semantics open import Data.Binary.Definitions open import Data.Binary.Operations.Semantics open import Data.Nat as ℕ using (ℕ; suc; zero) open import Relation.Binary.PropositionalEquality.FasterReasoning import Data.Nat.Properties as ℕ open import Function open import Data.Nat.Reasoning mutual add₀-homo : ∀ xs ys → ⟦ add O xs ys ⇓⟧⁺ ≡ ⟦ xs ⇓⟧⁺ ℕ.+ ⟦ ys ⇓⟧⁺ add₀-homo 1ᵇ 1ᵇ = refl add₀-homo 1ᵇ (O ∷ ys) = refl add₀-homo 1ᵇ (I ∷ ys) = cong 2* (inc⁺⁺-homo ys) ⟨ trans ⟩ ℕ.+-suc (suc ⟦ ys ⇓⟧⁺) _ add₀-homo (O ∷ xs) 1ᵇ = ℕ.+-comm 1 _ add₀-homo (O ∷ xs) (O ∷ ys) = cong 2* (add₀-homo xs ys) ⟨ trans ⟩ 2*-distrib ⟦ xs ⇓⟧⁺ ⟦ ys ⇓⟧⁺ add₀-homo (O ∷ xs) (I ∷ ys) = cong suc (cong 2* (add₀-homo xs ys) ⟨ trans ⟩ 2*-distrib ⟦ xs ⇓⟧⁺ ⟦ ys ⇓⟧⁺) ⟨ trans ⟩ sym (ℕ.+-suc (2* ⟦ xs ⇓⟧⁺) (2* ⟦ ys ⇓⟧⁺)) add₀-homo (I ∷ xs) 1ᵇ = inc⁺⁺-homo (I ∷ xs) ⟨ trans ⟩ cong suc (ℕ.+-comm 1 _) add₀-homo (I ∷ xs) (O ∷ ys) = cong suc (cong 2* (add₀-homo xs ys) ⟨ trans ⟩ 2*-distrib ⟦ xs ⇓⟧⁺ ⟦ ys ⇓⟧⁺) add₀-homo (I ∷ xs) (I ∷ ys) = cong 2* (add₁-homo xs ys) ⟨ trans ⟩ (ℕ.+-suc (suc (⟦ xs ⇓⟧⁺ ℕ.+ ⟦ ys ⇓⟧⁺)) _ ⟨ trans ⟩ cong suc (cong suc (2*-distrib ⟦ xs ⇓⟧⁺ ⟦ ys ⇓⟧⁺))) ⟨ trans ⟩ sym (cong suc (ℕ.+-suc (2* ⟦ xs ⇓⟧⁺) _)) add₁-homo : ∀ xs ys → ⟦ add I xs ys ⇓⟧⁺ ≡ suc (⟦ xs ⇓⟧⁺ ℕ.+ ⟦ ys ⇓⟧⁺) add₁-homo 1ᵇ 1ᵇ = refl add₁-homo 1ᵇ (O ∷ ys) = cong 2* (inc⁺⁺-homo ys) ⟨ trans ⟩ ℕ.+-suc (suc ⟦ ys ⇓⟧⁺) _ add₁-homo 1ᵇ (I ∷ ys) = cong suc (cong 2* (inc⁺⁺-homo ys) ⟨ trans ⟩ ℕ.+-suc (suc ⟦ ys ⇓⟧⁺) _) add₁-homo (O ∷ xs) 1ᵇ = cong 2* (inc⁺⁺-homo xs) ⟨ trans ⟩ (ℕ.+-suc (suc ⟦ xs ⇓⟧⁺) _ ⟨ trans ⟩ cong suc (ℕ.+-comm 1 _)) add₁-homo (O ∷ xs) (O ∷ ys) = cong suc (cong 2* (add₀-homo xs ys) ⟨ trans ⟩ 2*-distrib ⟦ xs ⇓⟧⁺ ⟦ ys ⇓⟧⁺) add₁-homo (O ∷ xs) (I ∷ ys) = cong 2* (add₁-homo xs ys) ⟨ trans ⟩ (ℕ.+-suc (suc (⟦ xs ⇓⟧⁺ ℕ.+ ⟦ ys ⇓⟧⁺)) _ ⟨ trans ⟩ (cong suc (cong suc ((2*-distrib ⟦ xs ⇓⟧⁺ ⟦ ys ⇓⟧⁺))) ⟨ trans ⟩ cong suc (sym (ℕ.+-suc (2* ⟦ xs ⇓⟧⁺) _)) )) add₁-homo (I ∷ xs) 1ᵇ = cong suc (cong 2* (inc⁺⁺-homo xs) ⟨ trans ⟩ cong suc (ℕ.+-suc ⟦ xs ⇓⟧⁺ _ ⟨ trans ⟩ ℕ.+-comm 1 _)) add₁-homo (I ∷ xs) (O ∷ ys) = cong 2* (add₁-homo xs ys) ⟨ trans ⟩ (ℕ.+-suc (suc (⟦ xs ⇓⟧⁺ ℕ.+ ⟦ ys ⇓⟧⁺)) _ ⟨ trans ⟩ cong suc (cong suc (2*-distrib ⟦ xs ⇓⟧⁺ ⟦ ys ⇓⟧⁺))) add₁-homo (I ∷ xs) (I ∷ ys) = cong suc (cong 2* (add₁-homo xs ys) ⟨ trans ⟩ (ℕ.+-suc (suc (⟦ xs ⇓⟧⁺ ℕ.+ ⟦ ys ⇓⟧⁺) ) _ ⟨ trans ⟩ cong suc (cong suc (2*-distrib ⟦ xs ⇓⟧⁺ ⟦ ys ⇓⟧⁺)) ⟨ trans ⟩ cong suc (sym (ℕ.+-suc (2* ⟦ xs ⇓⟧⁺) _)) )) +-homo : ∀ xs ys → ⟦ xs + ys ⇓⟧ ≡ ⟦ xs ⇓⟧ ℕ.+ ⟦ ys ⇓⟧ +-homo 0ᵇ ys = refl +-homo (0< x) 0ᵇ = sym (ℕ.+-identityʳ _) +-homo (0< xs) (0< ys) = add₀-homo xs ys
{ "alphanum_fraction": 0.5376344086, "avg_line_length": 63.3191489362, "ext": "agda", "hexsha": "ed6dcb0aaef838b8e36fa01dcfc37dc4be5b5638", "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": "92af4d620febd47a9791d466d747278dc4a417aa", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/agda-binary", "max_forks_repo_path": "Data/Binary/Proofs/Addition.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa", "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-binary", "max_issues_repo_path": "Data/Binary/Proofs/Addition.agda", "max_line_length": 234, "max_stars_count": 1, "max_stars_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/agda-binary", "max_stars_repo_path": "Data/Binary/Proofs/Addition.agda", "max_stars_repo_stars_event_max_datetime": "2019-03-21T21:30:10.000Z", "max_stars_repo_stars_event_min_datetime": "2019-03-21T21:30:10.000Z", "num_tokens": 1550, "size": 2976 }
open import Relation.Binary.Core module BBHeap.Equality.Properties {A : Set}(_≤_ : A → A → Set) where open import BBHeap _≤_ open import BBHeap.Equality _≤_ open import Bound.Lower A refl≈ : {b : Bound}{h : BBHeap b} → h ≈ h refl≈ {b} {leaf} = ≈leaf refl≈ {b} {left b≤x l⋘r} = ≈left b≤x b≤x l⋘r l⋘r refl≈ refl≈ refl≈ {b} {right b≤x l⋙r} = ≈right b≤x b≤x l⋙r l⋙r refl≈ refl≈ sym≈ : {b b' : Bound}{h : BBHeap b}{h' : BBHeap b'} → h ≈ h' → h' ≈ h sym≈ ≈leaf = ≈leaf sym≈ (≈left b≤x b'≤x' l⋘r l'⋘r' l≈l' r≈r') = ≈left b'≤x' b≤x l'⋘r' l⋘r (sym≈ l≈l') (sym≈ r≈r') sym≈ (≈right b≤x b'≤x' l⋙r l'⋙r' l≈l' r≈r') = ≈right b'≤x' b≤x l'⋙r' l⋙r (sym≈ l≈l') (sym≈ r≈r') trans≈ : {b b' b'' : Bound}{h : BBHeap b}{h' : BBHeap b'}{h'' : BBHeap b''} → h ≈ h' → h' ≈ h'' → h ≈ h'' trans≈ ≈leaf ≈leaf = ≈leaf trans≈ (≈left b≤x b'≤x' l⋘r l'⋘r' l≈l' r≈r') (≈left .b'≤x' b''≤x'' .l'⋘r' l''⋘r'' l'≈l'' r'≈r'') = ≈left b≤x b''≤x'' l⋘r l''⋘r'' (trans≈ l≈l' l'≈l'') (trans≈ r≈r' r'≈r'') trans≈ (≈right b≤x b'≤x' l⋙r l'⋙r' l≈l' r≈r') (≈right .b'≤x' b''≤x'' .l'⋙r' l''⋙r'' l'≈l'' r'≈r'') = ≈right b≤x b''≤x'' l⋙r l''⋙r'' (trans≈ l≈l' l'≈l'') (trans≈ r≈r' r'≈r'') mutual lemma≈≃ : {b b' b'' : Bound}{h : BBHeap b}{h' : BBHeap b'}{h'' : BBHeap b''} → h ≈ h' → h' ≃ h'' → h ≃ h'' lemma≈≃ ≈leaf ≃lf = ≃lf lemma≈≃ (≈left b≤x b'≤x' l⋘r l'⋘r' l≈l' r≈r') (≃nd .b'≤x' b''≤x'' .l'⋘r' l''⋘r'' l'≃r' l''≃r'' l'≃l'') = ≃nd b≤x b''≤x'' l⋘r l''⋘r'' (lemma≈≃ l≈l' (lemma≃≈ l'≃r' (sym≈ r≈r'))) l''≃r'' (lemma≈≃ l≈l' l'≃l'') lemma≃≈ : {b b' b'' : Bound}{h : BBHeap b}{h' : BBHeap b'}{h'' : BBHeap b''} → h ≃ h' → h' ≈ h'' → h ≃ h'' lemma≃≈ ≃lf ≈leaf = ≃lf lemma≃≈ (≃nd b≤x b'≤x' l⋘r l'⋘r' l≃r l'≃r' l≃l') (≈left .b'≤x' b''≤x'' .l'⋘r' l''⋘r'' l'≈l'' r'≈r'') = ≃nd b≤x b''≤x'' l⋘r l''⋘r'' l≃r (lemma≈≃ (sym≈ l'≈l'') (lemma≃≈ l'≃r' r'≈r'')) (lemma≃≈ l≃l' l'≈l'') lemma≈⋗ : {b b' b'' : Bound}{h : BBHeap b}{h' : BBHeap b'}{h'' : BBHeap b''} → h ≈ h' → h' ⋗ h'' → h ⋗ h'' lemma≈⋗ (≈left b≤x .b'≤x' lf⋘ .lf⋘ ≈leaf ≈leaf) (⋗lf b'≤x') = ⋗lf b≤x lemma≈⋗ (≈left b≤x .b'≤x' l⋘r .l'⋘r' l≈l' r≈r') (⋗nd b'≤x' b''≤x'' l'⋘r' l''⋘r'' l'≃r' l''≃r'' l'⋗l'') = ⋗nd b≤x b''≤x'' l⋘r l''⋘r'' (lemma≈≃ l≈l' (lemma≃≈ l'≃r' (sym≈ r≈r'))) l''≃r'' (lemma≈⋗ l≈l' l'⋗l'') lemma⋗≈ : {b b' b'' : Bound}{h : BBHeap b}{h' : BBHeap b'}{h'' : BBHeap b''} → h ⋗ h' → h' ≈ h'' → h ⋗ h'' lemma⋗≈ (⋗lf b≤x) ≈leaf = ⋗lf b≤x lemma⋗≈ (⋗nd b≤x b'≤x' l⋘r l'⋘r' l≃r l'≃r' l⋗l') (≈left .b'≤x' b''≤x'' .l'⋘r' l''⋘r'' l'≈l'' r'≈r'') = ⋗nd b≤x b''≤x'' l⋘r l''⋘r'' l≃r (lemma≈≃ (sym≈ l'≈l'') (lemma≃≈ l'≃r' r'≈r'')) (lemma⋗≈ l⋗l' l'≈l'') lemma≈⋘ : {b b' b'' : Bound}{h : BBHeap b}{h' : BBHeap b'}{h'' : BBHeap b''} → h ≈ h' → h' ⋘ h'' → h ⋘ h'' lemma≈⋘ ≈leaf lf⋘ = lf⋘ lemma≈⋘ (≈left b≤x b'≤x' l⋘r l'⋘r' l≈l' r≈r') (ll⋘ .b'≤x' b''≤x'' .l'⋘r' l''⋘r'' l''≃r'' r'≃l'') = ll⋘ b≤x b''≤x'' l⋘r l''⋘r'' l''≃r'' (lemma≈≃ r≈r' r'≃l'') lemma≈⋘ (≈right b≤x b'≤x' l⋙r l'⋙r' l≈l' r≈r') (lr⋘ .b'≤x' b''≤x'' .l'⋙r' l''⋘r'' l''≃r'' l'⋗l'') = lr⋘ b≤x b''≤x'' l⋙r l''⋘r'' l''≃r'' (lemma≈⋗ l≈l' l'⋗l'') lemma⋘≈ : {b b' b'' : Bound}{h : BBHeap b}{h' : BBHeap b'}{h'' : BBHeap b''} → h ⋘ h' → h' ≈ h'' → h ⋘ h'' lemma⋘≈ lf⋘ ≈leaf = lf⋘ lemma⋘≈ (ll⋘ b≤x b'≤x' l⋘r l'⋘r' l'≃r' r≃l') (≈left .b'≤x' b''≤x'' .l'⋘r' l''⋘r'' l'≈l'' r'≈r'') = ll⋘ b≤x b''≤x'' l⋘r l''⋘r'' (lemma≈≃ (sym≈ l'≈l'') (lemma≃≈ l'≃r' r'≈r'')) (lemma≃≈ r≃l' l'≈l'') lemma⋘≈ (lr⋘ b≤x b'≤x' l⋙r l'⋘r' l'≃r' l⋗l') (≈left .b'≤x' b''≤x'' .l'⋘r' l''⋘r'' l'≈l'' r'≈r'') = lr⋘ b≤x b''≤x'' l⋙r l''⋘r'' (lemma≈≃ (sym≈ l'≈l'') (lemma≃≈ l'≃r' r'≈r'')) (lemma⋗≈ l⋗l' l'≈l'') lemma≈⋙ : {b b' b'' : Bound}{h : BBHeap b}{h' : BBHeap b'}{h'' : BBHeap b''} → h ≈ h' → h' ⋙ h'' → h ⋙ h'' lemma≈⋙ (≈left b≤x b'≤x' lf⋘ lf⋘ ≈leaf ≈leaf) (⋙lf .b'≤x') = ⋙lf b≤x lemma≈⋙ (≈left b≤x b'≤x' l⋘r l'⋘r' l≈l' r≈r') (⋙rl .b'≤x' b'≤x'' .l'⋘r' l'≃r' l''⋘r'' l'⋗r'') = ⋙rl b≤x b'≤x'' l⋘r (lemma≈≃ l≈l' (lemma≃≈ l'≃r' (sym≈ r≈r'))) l''⋘r'' (lemma≈⋗ l≈l' l'⋗r'') lemma≈⋙ (≈left b≤x b'≤x' l⋘r l'⋘r' l≈l' r≈r') (⋙rr .b'≤x' b''≤x'' .l'⋘r' l'≃r' l''⋙r'' l'≃l'') = ⋙rr b≤x b''≤x'' l⋘r (lemma≈≃ l≈l' (lemma≃≈ l'≃r' (sym≈ r≈r'))) l''⋙r'' (lemma≈≃ l≈l' l'≃l'') lemma⋙≈ : {b b' b'' : Bound}{h : BBHeap b}{h' : BBHeap b'}{h'' : BBHeap b''} → h ⋙ h' → h' ≈ h'' → h ⋙ h'' lemma⋙≈ (⋙lf b≤x) ≈leaf = ⋙lf b≤x lemma⋙≈ (⋙rl b≤x b'≤x' l⋘r l≃r l'⋘r' l⋗r') (≈left .b'≤x' b'≤x'' .l'⋘r' l''⋘r'' l'≈l'' r'≈r'') = ⋙rl b≤x b'≤x'' l⋘r l≃r l''⋘r'' (lemma⋗≈ l⋗r' r'≈r'') lemma⋙≈ (⋙rr b≤x b'≤x' l⋘r l≃r l'⋙r' l≃l') (≈right .b'≤x' b''≤x'' .l'⋙r' l'⋙r'' l'≈l'' r'≈r'') = ⋙rr b≤x b''≤x'' l⋘r l≃r l'⋙r'' (lemma≃≈ l≃l' l'≈l'')
{ "alphanum_fraction": 0.4173106646, "avg_line_length": 75.4833333333, "ext": "agda", "hexsha": "74d10e5b7f4cda336effda1878f140bb2aafc95a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_path": "agda/BBHeap/Equality/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bgbianchi/sorting", "max_issues_repo_path": "agda/BBHeap/Equality/Properties.agda", "max_line_length": 207, "max_stars_count": 6, "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_path": "agda/BBHeap/Equality/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "num_tokens": 3415, "size": 4529 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Prelude open import LibraBFT.Base.Types import LibraBFT.Yasm.Base as LYB import LibraBFT.Yasm.Types as LYT -- This module defines a model of a distributed system, parameterized by -- SystemParameters, which establishes various application-dependent types, -- handlers, etc. The model supports a set of peers executing handlers in -- response to messages received; these handlers can update the peer's -- local state and/or send additional messages. The model also enables -- "cheat" steps, which can send arbitrary messages, except that they are -- constrained to prevent a cheat step from introducing a new signature for -- an "honest" public key. The module also contains some structures for -- proving properties of executions of the modeled system. module LibraBFT.Yasm.System (ℓ-PeerState : Level) (ℓ-VSFP : Level) (parms : LYB.SystemParameters ℓ-PeerState) where data InitStatus : Set where uninitd : InitStatus initd : InitStatus open InitStatus uninitd≢initd : uninitd ≢ initd uninitd≢initd = λ () open import LibraBFT.Yasm.Base open SystemParameters parms open import Util.FunctionOverride PeerId _≟PeerId_ open import LibraBFT.Base.PKCS SenderMsgPair : Set SenderMsgPair = PeerId × Msg actionToSMP : PeerId → LYT.Action Msg → Maybe SenderMsgPair actionToSMP pid (LYT.send m) = just (pid , m) SentMessages : Set SentMessages = List SenderMsgPair -- Convert the actions a peer `pid` took to a list of sent messages. -- Non-message actions are discarded. actionsToSentMessages : PeerId → List (LYT.Action Msg) → SentMessages actionsToSentMessages pid = mapMaybe (actionToSMP pid) -- If the sender-message pair `(pid₁ , m)` is associated with the messages that -- were sent as a consequence of the actions `outs` of `pid₂`, then these two -- PIDs are equal and this peer performed a `send` action for that message. senderMsgPair∈⇒send∈ : ∀ {pid₁ pid₂ m} → (outs : List (LYT.Action Msg)) → (pid₁ , m) ∈ (actionsToSentMessages pid₂ outs) → (LYT.send m ∈ outs) × pid₁ ≡ pid₂ senderMsgPair∈⇒send∈ (LYT.send m ∷ outs) (here refl) = (here refl , refl) senderMsgPair∈⇒send∈ (LYT.send m ∷ outs) (there pm∈) with senderMsgPair∈⇒send∈ outs pm∈ ...| m∈outs , refl = (there m∈outs) , refl -- The model supports sending messages that contain some fields that are -- /not/ covered by the message's signature. Therefore, given a message -- with a verifiable signature, it is possible for a propositionally -- different message that verifies against the same signature to have been -- sent before, which is captured by the following definition. record MsgWithSig∈ (pk : PK)(sig : Signature)(pool : SentMessages) : Set where constructor mkMsgWithSig∈ field msgWhole : Msg msgPart : Part msg⊆ : msgPart ⊂Msg msgWhole msgSender : PeerId msg∈pool : (msgSender , msgWhole) ∈ pool msgSigned : WithVerSig pk msgPart msgSameSig : ver-signature msgSigned ≡ sig open MsgWithSig∈ public postulate -- TODO-1: prove it MsgWithSig∈? : ∀ {pk} {sig} {pool} → Dec (MsgWithSig∈ pk sig pool) MsgWithSig∈-++ʳ : ∀{pk sig pool ms} → MsgWithSig∈ pk sig pool → MsgWithSig∈ pk sig (ms ++ pool) MsgWithSig∈-++ʳ {ms = pre} msig = record { msgWhole = msgWhole msig ; msgPart = msgPart msig ; msg⊆ = msg⊆ msig ; msg∈pool = Any-++ʳ pre (msg∈pool msig) ; msgSigned = msgSigned msig ; msgSameSig = msgSameSig msig } MsgWithSig∈-++ˡ : ∀{pk sig pool ms} → MsgWithSig∈ pk sig ms → MsgWithSig∈ pk sig (ms ++ pool) MsgWithSig∈-++ˡ {ms = pre} msig = record { msgWhole = msgWhole msig ; msgPart = msgPart msig ; msg⊆ = msg⊆ msig ; msg∈pool = Any-++ˡ (msg∈pool msig) ; msgSigned = msgSigned msig ; msgSameSig = msgSameSig msig } MsgWithSig∈-transp : ∀{pk sig pool pool'} → (mws : MsgWithSig∈ pk sig pool) → (msgSender mws , msgWhole mws) ∈ pool' → MsgWithSig∈ pk sig pool' MsgWithSig∈-transp msig ∈pool' = record { msgWhole = msgWhole msig ; msgPart = msgPart msig ; msg⊆ = msg⊆ msig ; msg∈pool = ∈pool' ; msgSigned = msgSigned msig ; msgSameSig = msgSameSig msig } -- * Forbidding the Forging of Signatures -- -- Whenever our reasoning must involve digital signatures, it is standard -- to talk about EUF-CMA resistant signature schemes. Informally, this captures -- signatures schemes that cannot be compromised by certain adversaries. -- Formally, it means that for any probabilistic-polynomial-time adversary 𝓐, -- and some security parameter k: -- -- Pr[ EUF-CMA(k) ] ≤ ε(k) for ε a negigible function. -- -- EUF-CMA is defined as: -- -- EUF-CMA(k): | O(m): -- L ← ∅ | σ ← Sign(sk , m) -- (pk, sk) ← Gen(k) | L ← L ∪ { m } -- (m , σ) ← 𝓐ᴼ(pk) | return σ -- return (Verify(pk, m, σ) ∧ m ∉ L) | -- -- This says that 𝓐 cannot create a message that has /not yet been signed/ and -- forge a signature for it. The list 'L' keeps track of the messages that 𝓐 -- asked to be signed by the oracle. -- -- Because the probability of the adversary to win the EUF-CMA(k) game -- approaches 0 as k increases; it is reasonable to assume that winning -- the game is /impossible/ for realistic security parameters. -- -- EUF-CMA security is incorporated into our model by constraining messages -- sent by a cheat step to ensure that for every verifiably signed part of -- such a message, if there is a signature on the part, then it is either for -- a dishonest public key (in which cases it's secret key may have been leaked), -- or a message has been sent with the same signature before (in which case the -- signature is simply being "replayed" from a previous message). -- -- Dishonest (or "cheat") messages are those that are not the result of -- a /handle/ or /init/ call, but rather are the result of a /cheat/ step. -- -- A part of a cheat message can contain a verifiable signature only if it -- is for a dishonest public key, or a message with the same signature has -- been sent before or can be derived from GenesisInfo (a cheater can -- "reuse" an honest signature sent before; it just can't produce a new -- one). Note that this constraint precludes a peer sending a message -- that contains a new verifiable signature for an honest PK, even if the -- PK is the peer's own PK for some epoch (implying that the peer -- possesses the associated secret key). In other words, a peer that is -- honest for a given epoch (by virtue of being a member of that epoch and -- being assigned an honest PK for the epoch), cannot send a message for -- that epoch using a cheat step. CheatPartConstraint : SentMessages → Part → Set CheatPartConstraint pool m = ∀{pk} → (ver : WithVerSig pk m) → ¬ ∈GenInfo (ver-signature ver) → Meta-Dishonest-PK pk ⊎ MsgWithSig∈ pk (ver-signature ver) pool -- The only constraints on messages sent by cheat steps are that: -- * the sender is not an honest member in the epoch of any part of the message -- * the signature on any part of the message satisfies CheatCanSign, meaning -- that it is not a new signature for an honest public key CheatMsgConstraint : SentMessages → Msg → Set CheatMsgConstraint pool m = ∀{part} → part ⊂Msg m → CheatPartConstraint pool part -- * The System State -- -- A system consists in a partial map from PeerId to PeerState, a pool -- of sent messages and a number of available epochs. record SystemState : Set (ℓ+1 ℓ-PeerState) where field peerStates : PeerId → PeerState initialised : PeerId → InitStatus msgPool : SentMessages -- All messages ever sent open SystemState public initialState : SystemState initialState = record { peerStates = const initPS ; initialised = const uninitd ; msgPool = [] } -- * Small Step Semantics -- -- The small step semantics are divided into three datatypes: -- -- i) StepPeerState executes a step through init or handle -- ii) StepPeer executes a step through StepPeerState or cheat -- iii) Step transitions the system state by a StepPeer or by -- bringing a new epoch into existence -- The pre and post states of Honest peers are related iff data StepPeerState (pid : PeerId)(pool : SentMessages) (peerInits : PeerId → InitStatus) (ps : PeerState) : (PeerState × List (LYT.Action Msg)) → Set where -- An uninitialized peer can be initialized step-init : peerInits pid ≡ uninitd → StepPeerState pid pool peerInits ps (init pid genInfo) -- The peer processes a message in the pool step-msg : ∀{m} → m ∈ pool → peerInits pid ≡ initd → StepPeerState pid pool peerInits ps (handle pid (proj₂ m) ps) -- The pre-state of the suplied PeerId is related to the post-state and list of output messages iff: data StepPeer (pre : SystemState) : PeerId → PeerState → List (LYT.Action Msg) → Set ℓ-PeerState where -- it can be obtained by a handle or init call. step-honest : ∀{pid st outs} → StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (st , outs) → StepPeer pre pid st outs -- or the peer decides to cheat. CheatMsgConstraint ensures it cannot -- forge signatures by honest peers. Cheat steps do not modify peer -- state: these are maintained exclusively by the implementation -- handlers. step-cheat : ∀{pid m} → CheatMsgConstraint (msgPool pre) m → StepPeer pre pid (peerStates pre pid) (LYT.send m ∷ []) isCheat : ∀ {pre pid ms outs} → StepPeer pre pid ms outs → Set isCheat (step-honest _) = ⊥ isCheat (step-cheat _) = Unit initStatus : ∀ {pid pre ms outs} → StepPeer pre pid ms outs → InitStatus → InitStatus initStatus {pid} (step-honest _) preinit = initd initStatus {pid} (step-cheat _) preinit = preinit -- Computes the post-sysstate for a given step-peer. StepPeer-post : ∀{pid st' outs}{pre : SystemState } → StepPeer pre pid st' outs → SystemState StepPeer-post {pid} {st'} {outs} {pre} sp = record pre { peerStates = ⟦ peerStates pre , pid ← st' ⟧ ; initialised = ⟦ initialised pre , pid ← initStatus sp (initialised pre pid) ⟧ ; msgPool = actionsToSentMessages pid outs ++ msgPool pre } StepPeer-post-lemma : ∀{pid st' outs}{pre : SystemState} → (pstep : StepPeer pre pid st' outs) → st' ≡ peerStates (StepPeer-post pstep) pid StepPeer-post-lemma pstep = sym override-target-≡ StepPeer-post-lemma2 : ∀{pid}{pre : SystemState}{st outs} → (sps : StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (st , outs)) → initialised (StepPeer-post {pid} {st} {outs} {pre} (step-honest sps)) pid ≡ initd StepPeer-post-lemma2 {pre = pre} _ = override-target-≡ cheatStepDNMPeerStates : ∀{pid st' outs}{pre : SystemState} → (theStep : StepPeer pre pid st' outs) → isCheat theStep → peerStates (StepPeer-post theStep) ≡ peerStates pre cheatStepDNMPeerStates {pid = pid} {pre = pre} (step-cheat _) _ = overrideSameVal-correct-ext {f = peerStates pre} {pid} cheatStepDNMInitialised : ∀{pid st' outs}{pre : SystemState} → (theStep : StepPeer pre pid st' outs) → isCheat theStep → initialised (StepPeer-post theStep) ≡ initialised pre cheatStepDNMInitialised {pid = pid} {pre = pre} (step-cheat _) _ = overrideSameVal-correct-ext cheatStepDNMInitialised₁ : ∀{pid pid' st' outs}{pre : SystemState} → (theStep : StepPeer pre pid st' outs) → isCheat theStep → initialised (StepPeer-post theStep) pid' ≡ initialised pre pid' cheatStepDNMInitialised₁ {pid} {pid'} {pre = pre} (step-cheat _) _ = overrideSameVal-correct pid pid' cheatStepDNMPeerStates₁ : ∀{pid pid' st' outs}{pre : SystemState} → (theStep : StepPeer pre pid st' outs) → isCheat theStep → peerStates (StepPeer-post theStep) pid' ≡ peerStates pre pid' cheatStepDNMPeerStates₁ {pid} {pid'} (step-cheat _) x = overrideSameVal-correct pid pid' pids≢StepDNMPeerStates : ∀{pid pid' s' outs}{pre : SystemState} → (sps : StepPeerState pid' (msgPool pre) (initialised pre) (peerStates pre pid') (s' , outs)) → pid ≢ pid' → peerStates pre pid ≡ peerStates (StepPeer-post {pid'} {s'} {outs} {pre} (step-honest sps)) pid pids≢StepDNMPeerStates sps pids≢ = override-target-≢ pids≢ data Step : SystemState → SystemState → Set (ℓ+1 ℓ-PeerState) where -- TO-NOT-DO: it is tempting to merge this and StepPeer, now that step-peer -- is the only constructor here. I started to do so, but it propagates many -- changes throughout the repo, and it's possible we will in future add steps -- not performed by a specific peer (for example, if we model some notion of -- time to prove liveness properties). step-peer : ∀{pid st' outs}{pre : SystemState} → (pstep : StepPeer pre pid st' outs) → Step pre (StepPeer-post pstep) msgs-stable : ∀ {pre : SystemState} {post : SystemState} {m} → (theStep : Step pre post) → m ∈ msgPool pre → m ∈ msgPool post msgs-stable (step-peer {pid = pid} {outs = outs} _) m∈ = Any-++ʳ (actionsToSentMessages pid outs) m∈ peersRemainInitialized : ∀ {pid} {pre : SystemState} {post : SystemState} → Step pre post → initialised pre pid ≡ initd → initialised post pid ≡ initd peersRemainInitialized {pid} (step-peer {pid'} step) isInitd with pid' ≟PeerId pid ...| no neq = isInitd ...| yes refl with step ... | step-honest {pidS} {st} {outs} stp = refl ... | step-cheat _ = isInitd -- not used yet, but some proofs could probably be cleaned up using this, -- e.g., prevVoteRnd≤-pred-step in Impl.VotesOnce sendMessages-target : ∀ {m : SenderMsgPair} {sm : SentMessages} {ml : List SenderMsgPair} → ¬ (m ∈ sm) → m ∈ (ml ++ sm) → m ∈ ml sendMessages-target {ml = ml} ¬m∈sm m∈++ with Any-++⁻ ml m∈++ ...| inj₁ m∈ml = m∈ml ...| inj₂ m∈sm = ⊥-elim (¬m∈sm m∈sm) -- * Reflexive-Transitive Closure data Step* : SystemState → SystemState → Set (ℓ+1 ℓ-PeerState) where step-0 : ∀{pre : SystemState} → Step* pre pre step-s : ∀{fst : SystemState}{pre : SystemState}{post : SystemState} → Step* fst pre → Step pre post → Step* fst post ReachableSystemState : SystemState → Set (ℓ+1 ℓ-PeerState) ReachableSystemState = Step* initialState peerStatePostSt : ∀ {pid s' s outs} {st : SystemState} → (r : ReachableSystemState st) → (stP : StepPeerState pid (msgPool st) (initialised st) (peerStates st pid) (s' , outs)) → peerStates (StepPeer-post {pre = st} (step-honest stP)) pid ≡ s → s ≡ s' peerStatePostSt _ _ ps≡s = trans (sym ps≡s) override-target-≡ Step*-trans : ∀ {st st' st''} → Step* st st' → Step* st' st'' → Step* st st'' Step*-trans r step-0 = r Step*-trans r (step-s tr x) = step-s (Step*-trans r tr) x Step*-initdStable : ∀{st st' pid} → Step* st st' → initialised st pid ≡ initd → initialised st' pid ≡ initd Step*-initdStable step-0 ini = ini Step*-initdStable {st} {pid = pid} (step-s {pre = pre} tr theStep) ini = peersRemainInitialized theStep (Step*-initdStable tr ini) MsgWithSig∈-Step* : ∀{sig pk}{st : SystemState}{st' : SystemState} → Step* st st' → MsgWithSig∈ pk sig (msgPool st) → MsgWithSig∈ pk sig (msgPool st') MsgWithSig∈-Step* step-0 msig = msig MsgWithSig∈-Step* (step-s tr (step-peer ps)) msig = MsgWithSig∈-++ʳ (MsgWithSig∈-Step* tr msig) MsgWithSig∈-Step*-part : ∀{sig pk}{st : SystemState}{st' : SystemState} → (tr : Step* st st') → (msig : MsgWithSig∈ pk sig (msgPool st)) → msgPart msig ≡ msgPart (MsgWithSig∈-Step* tr msig) MsgWithSig∈-Step*-part step-0 msig = refl MsgWithSig∈-Step*-part (step-s tr (step-peer ps)) msig = MsgWithSig∈-Step*-part tr msig MsgWithSig∈-Step*-sender : ∀{sig pk}{st : SystemState}{st' : SystemState} → (tr : Step* st st') → (msig : MsgWithSig∈ pk sig (msgPool st)) → msgSender msig ≡ msgSender (MsgWithSig∈-Step* tr msig) MsgWithSig∈-Step*-sender step-0 msig = refl MsgWithSig∈-Step*-sender (step-s tr (step-peer ps)) msig = MsgWithSig∈-Step*-sender tr msig ------------------------------------------ -- Type synonym to express a relation over system states; SystemStateRel : ∀ {ℓ} → (SystemState → SystemState → Set (ℓ+1 ℓ-PeerState)) → Set (ℓ+1 (ℓ ℓ⊔ ℓ-PeerState)) SystemStateRel {ℓ} P = ∀{st : SystemState}{st' : SystemState} → P st st' → Set (ℓ ℓ⊔ ℓ-PeerState) -- Just like Data.List.Any maps a predicate over elements to a predicate over lists, -- Any-step maps a relation over steps to a relation over steps in a trace. data Any-Step {ℓ : Level} (P : SystemStateRel {ℓ} Step) : SystemStateRel {ℓ} Step* where step-here : ∀{fst : SystemState}{pre : SystemState}{post : SystemState} → (cont : Step* fst pre) → {this : Step pre post}(prf : P this) → Any-Step P (step-s cont this) step-there : ∀{fst : SystemState}{pre : SystemState}{post : SystemState} → {cont : Step* fst pre} → {this : Step pre post} → (prf : Any-Step {ℓ} P cont) → Any-Step P (step-s cont this) Any-Step-map : ∀ {ℓ}{P P' : SystemStateRel {ℓ} Step} → (∀ {pre : SystemState}{post : SystemState} → (x : Step pre post) → P x → P' x) → ∀ {fst lst} {tr : Step* fst lst} → Any-Step {ℓ} P tr → Any-Step {ℓ} P' tr Any-Step-map p⇒p' (step-here cont {this} prf) = step-here cont (p⇒p' this prf) Any-Step-map p⇒p' (step-there anyStep) = step-there (Any-Step-map p⇒p' anyStep) Any-Step-elim : ∀{ℓ}{ℓ-Q}{st₀ : SystemState}{st₁ : SystemState}{P : SystemStateRel {ℓ} Step}{Q : Set ℓ-Q} → {r : Step* st₀ st₁} → (P⇒Q : ∀{s : SystemState}{s' : SystemState}{st : Step s s'} → P st → Step* s' st₁ → Q) → Any-Step {ℓ} P r → Q Any-Step-elim P⇒Q (step-here cont prf) = P⇒Q prf step-0 Any-Step-elim P⇒Q (step-there {this = this} f) = Any-Step-elim (λ p s → P⇒Q p (step-s s this)) f -- A predicate over peer states, parts and peerIds, representing which peers can send new -- signatures for which PKs. The PeerState is needed to provide access to information the peer has -- about who uses what keys for what parts (in our case, EpochConfigs either derived from genesis -- information or agreed during epoch changes). ValidSenderForPK-type : Set (ℓ+1 ℓ-VSFP ℓ⊔ ℓ+1 ℓ-PeerState) ValidSenderForPK-type = SystemState → Part → PeerId → PK → Set ℓ-VSFP ValidSenderForPK-stable-type : ValidSenderForPK-type → Set (ℓ-VSFP ℓ⊔ ℓ+1 ℓ-PeerState) ValidSenderForPK-stable-type vs4pk = ∀ {pre post part pid pk} → ReachableSystemState pre → Step pre post → vs4pk pre part pid pk → vs4pk post part pid pk ------------------------------------------ module _ (P : SystemState → Set) where Step*-Step-fold : (∀{pid st' outs}{st : SystemState} → ReachableSystemState st → (pstep : StepPeer st pid st' outs) → P st → P (StepPeer-post pstep)) → P initialState → ∀{st : SystemState} → (tr : ReachableSystemState st) → P st Step*-Step-fold fs p₀ step-0 = p₀ Step*-Step-fold fs p₀ (step-s tr (step-peer p)) = fs tr p (Step*-Step-fold fs p₀ tr)
{ "alphanum_fraction": 0.6163067263, "avg_line_length": 45.2086021505, "ext": "agda", "hexsha": "79e1856565f222e40a0d6b2836ecf97784a31c89", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "cwjnkins/bft-consensus-agda", "max_forks_repo_path": "LibraBFT/Yasm/System.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "cwjnkins/bft-consensus-agda", "max_issues_repo_path": "LibraBFT/Yasm/System.agda", "max_line_length": 121, "max_stars_count": null, "max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "cwjnkins/bft-consensus-agda", "max_stars_repo_path": "LibraBFT/Yasm/System.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 6009, "size": 21022 }
{-# OPTIONS --rewriting #-} open import Array open import Array.APL using (reduce-1d) open import Data.Nat as N open import Data.Nat.Properties open import Data.Vec as V hiding (_>>=_; _++_) open import Data.Fin using (Fin; zero; suc; raise; inject+; #_) open import Relation.Binary.PropositionalEquality open import Data.Product open import Function open import Relation.Nullary open import Relation.Nullary.Decidable sum-1d : ∀ {n} → Ar ℕ 1 (n ∷ []) → ℕ sum-1d v = reduce-1d v _+_ 0 zipw : ∀ {a}{X : Set a}{d s} → (X → X → X) → Ar X d s → Ar X d s → Ar X d s zipw _⊕_ (imap a) (imap b) = imap λ iv → a iv ⊕ b iv hd : ∀ {n s : ℕ}{ss : Vec ℕ n} → Ix (suc n) (s ∷ ss) → Fin s hd ix = ix-lookup ix zero vec-mat-mul : ∀ {n m} → Ar ℕ 2 (m ∷ n ∷ []) → Ar ℕ 1 (n ∷ []) → Ar ℕ 1 (m ∷ []) vec-mat-mul (imap a) b = imap λ iv → sum-1d (zipw _*_ (imap λ jv → a (iv ix++ jv)) b) twice : ∀ {n} → (M : Ar ℕ 2 (n ∷ n ∷ [])) → (V : Ar ℕ 1 (n ∷ [])) → Ar ℕ 1 (n ∷ []) twice m v = vec-mat-mul m (vec-mat-mul m v) sum-2d : ∀ {m n} → Ar ℕ 2 (m ∷ n ∷ []) → ℕ sum-2d (imap a) = sum-1d (imap λ i → sum-1d (imap λ j → a $ i ix++ j)) _+'_ : ∀ {m n} → Fin (1 + m) → Fin (1 + n) → Fin (1 + m + n) _+'_ {m} {n} zero j = subst Fin (+-suc m n) (raise m j) _+'_ {suc m} {n} (suc i) j = suc (i +' j) _+''_ : ∀ {m n} → Fin m → Fin n → Fin (m + n ∸ 1) _+''_ {suc m} {suc n} zero j = raise m j _+''_ {suc (suc m)} {suc n} (suc i) j = suc (i +'' j) _ix+2_ : ∀ {m n k p} → Ix 2 (m ∷ n ∷ []) → Ix 2 (k ∷ p ∷ []) → Ix 2 (m + k ∸ 1 ∷ n + p ∸ 1 ∷ []) (x₁ ∷ x₂ ∷ []) ix+2 (y₁ ∷ y₂ ∷ []) = x₁ +'' y₁ ∷ (x₂ +'' y₂) ∷ [] conv-2 : ∀ {m n k p} → Ar ℕ 2 (m + k ∷ n + p ∷ []) → Ar ℕ 2 (k ∷ p ∷ []) → Ar ℕ 2 (1 + m ∷ 1 + n ∷ []) conv-2 {k = k} {p} (imap a) (imap w) = imap (λ iv → sum-2d {m = k} {n = p} (imap λ ov → w ov * a (iv ix+2 ov))) iterate-1 : ∀ {a}{X : Set a}{n} → (Fin n → X) → (X → X → X) → X → X iterate-1 {n = zero} f _⊕_ neut = neut iterate-1 {n = suc n} f _⊕_ neut = f zero ⊕ iterate-1 (f ∘ suc) _⊕_ neut red-iter : ∀ {a}{X : Set a}{n} → (f : Ix 1 (n ∷ []) → X) → (op : X → X → X) → (neut : X) → reduce-1d (imap f) op neut ≡ iterate-1 (λ i → f (i ∷ [])) op neut red-iter {n = zero} f op neut = refl red-iter {n = suc n} f op neut = cong (λ x → op _ x) (red-iter (λ iv → f (suc (hd iv) ∷ [])) op neut) {-# BUILTIN REWRITE _≡_ #-} {-# REWRITE red-iter #-} thm : ∀ {n} → (m : Ar ℕ 2 (n ∷ n ∷ [])) → (v : Ar _ _ (n ∷ [])) → ∀ iv → unimap (twice m v) iv ≡ {!!} thm (imap m) (imap v) (i ∷ []) = {!!} {- -- Reflection business open import Reflection open import Data.List hiding (_++_) open import Data.Bool open import Data.Maybe hiding (_>>=_) open import Data.Unit defToTerm : Name → Definition → List (Arg Term) → Term defToTerm _ (function cs) as = pat-lam cs as defToTerm _ (constructor′ d) as = con d as defToTerm _ _ _ = unknown derefImmediate : Term → TC Term derefImmediate (def f args) = getDefinition f >>= λ f' → return (defToTerm f f' args) derefImmediate x = return x --reflectTerm : TC Term --reflectTerm = (getType (quote f)) >>= λ ty → quoteTC f >>= derefImmediate >>= λ x → checkType x ty macro reflect : Term → Term → TC ⊤ reflect f a = derefImmediate f -- (quoteTerm f) >>= quoteTC >>= unify a reflect-ty : Name → Type → TC ⊤ reflect-ty f a = getType f >>= quoteTC >>= unify a r : Term r = reflect twice open import Data.String open import Data.Nat.Show as Ns open import Data.List as L using (List) data Prog : Set where ok : String → Prog error : String → Prog record State : Set where inductive constructor st field vars : List String defs : List $ String × String cons : List (String × ((List $ Arg Term) → Prog)) var-lkup : State → ℕ → Prog var-lkup s n = hlpr (State.vars s) n where hlpr : _ → _ → _ hlpr [] n = error $ "Variable not found" hlpr (x ∷ l) zero = ok x hlpr (x ∷ l) (suc n) = hlpr l n def-lkup : State → String → Prog def-lkup ss s = hlpr (State.defs ss) s where hlpr : _ → _ → _ hlpr [] s = error $ "Definition `" ++ s ++ "' not found" hlpr ((k , v) ∷ dfs) s with k ≈? s ... | yes p = ok v ... | no ¬p = hlpr dfs s cons-cont : State → String → List (Arg Term) → Prog cons-cont ss s args = {!!} {-hlpr (State.cons ss) s args where hlpr : _ → _ → _ → _ hlpr [] s _ = error $ "Constructor `" ++ s ++ "' not found" hlpr ((k , f) ∷ cs) s args with k ≈? s ... | yes p = f args ... | no ¬p = hlpr cs s args -} infixl 5 _#_ _#_ : Prog → Prog → Prog ok x # ok y = ok $ x ++ y error x # _ = error x _ # error y = error y l→s : List String → String l→s [] = "" l→s (x ∷ l) = x ++ " " ++ l→s l comp-arglist-mask : State → List (Arg Term) → List Bool → Prog comp-arglist : State → List (Arg Term) → Prog comp-clauses : State → List Clause → Prog _at_ : ∀ {a}{X : Set a} → List X → ℕ → Maybe X [] at idx = nothing (x ∷ a) at zero = just x (x ∷ a) at suc idx = a at idx unmaybe : ∀ {a}{X : Set a} → List (Maybe X) → Maybe (List X) unmaybe [] = just [] unmaybe (nothing ∷ xs) = nothing unmaybe (just x ∷ xs) with unmaybe xs unmaybe (just x ∷ xs) | nothing = nothing unmaybe (just x ∷ xs) | just xs' = just $ x ∷ xs' filter-idx : ∀ {a}{X : Set a} → List X → List ℕ → Maybe (List X) filter-idx xs idxs = unmaybe $ L.map (xs at_) idxs _!!_ : ∀ {a}{X : Set a} → (xs : List X) → Fin (L.length xs) → X [] !! () (x ∷ xs) !! zero = x (x ∷ xs) !! suc i = xs !! i mk-mask : (n : ℕ) → List (Fin n) → List Bool mk-mask n xs = V.toList $ go (V.replicate {n = n} false) xs where go : _ → _ → _ go e [] = e go e (x ∷ xs) = go (updateAt x (λ _ → true) e) xs compile : State → Term → Prog compile s (var x args) = ok "V(" # var-lkup s x # ok " " # comp-arglist s args # ok ")" compile s (con c args) with (showName c) compile s (con c args) | "Data.Vec.Base.Vec.[]" = ok "nil" compile s (con c args) | "Array.Base.Ix.[]" = ok "nil" compile s (con c args) | "Data.Vec.Base.Vec._∷_" = ok "(cons " # comp-arglist-mask s args (mk-mask 5 $ # 3 ∷ # 4 ∷ []) # ok ")" compile s (con c args) | "Array.Base.Ix._∷_" = ok "(cons " # comp-arglist-mask s args (mk-mask 5 $ # 3 ∷ # 4 ∷ []) # ok ")" compile s (con c args) | _ = ok ("C(" ++ showName c ++ " ") # comp-arglist s args # ok ")" compile s (def f args) with def-lkup s $ showName f ... | error _ = ok "D(" # ok (showName f) # ok " " # comp-arglist s args ... | d = ok "D(" # d # ok " " # comp-arglist s args # ok ")" compile s (lam v (abs w x)) = ok ("(\\ " ++ w ++ " -> ") # compile (record s {vars = (w ∷ State.vars s)}) x # ok ")" compile s (pat-lam cs []) = ok "PAT-LAM (cl = " # comp-clauses s cs # ok ")" --(args = " # comp-arglist s args # ok ")" compile s (pat-lam cs _) = error "PAT-LAM: I don't know what args to pat-lam are" compile s (pi a b) = ok "PI TYPE" compile s (sort _) = ok "SORT" compile s (lit x) = ok $ showLiteral x compile s (meta x x₁) = ok "META" compile s unknown = ok "_" -- "UNKNOWN" comp-arglist s [] = ok "" comp-arglist s (arg i x ∷ l) = compile s x # ok " " # comp-arglist s l comp-arglist-mask s [] [] = ok "" comp-arglist-mask s [] (x ∷ mask) = error "Incorrect argument mask" comp-arglist-mask s (x ∷ args) [] = error "Incorrect argument mask" comp-arglist-mask s (x ∷ args) (false ∷ mask) = comp-arglist-mask s args mask comp-arglist-mask s (arg i x ∷ args) (true ∷ mask) = compile s x # ok " " # comp-arglist-mask s args mask comp-pats : List (Arg Pattern) → List String comp-pats [] = [] comp-pats (vArg (var x) ∷ l) = x ∷ comp-pats l comp-pats (vArg _ ∷ l) = "_" ∷ comp-pats l comp-pats (_ ∷ l) = "_" ∷ comp-pats l comp-clauses s [] = ok "" comp-clauses s (clause ps t ∷ cs) = let vars = comp-pats ps in ok ("pats = " ++ l→s vars) # compile (record s {vars = (L.reverse vars L.++ State.vars s)}) t comp-clauses s (absurd-clause ps ∷ cs) = error "absurd clause found" test : ∀ {n} (m : Ix 2 (n ∷ n ∷ []) → ℕ) (v : Ix 1 (n ∷ []) → ℕ) (i : Fin n) → ℕ test m v i = iterate-1 (λ i₁ → m (i ∷ i₁ ∷ []) * iterate-1 (λ i₂ → m (i₁ ∷ i₂ ∷ []) * v (i₂ ∷ [])) _+_ 0) _+_ 0 bltin-defs : List $ String × String bltin-defs = ("Agda.Builtin.Nat.Nat" , "nat") ∷ ("Agda.Builtin.Nat._+_" , "plus") ∷ ("Agda.Builtin.Nat._*_" , "mult") ∷ ("Agda.Primitive.lzero" , "tt") ∷ ("BLAS.iterate-1" , "for-loop-acc") ∷ [] bltin-cons : List (String × (List (Arg Term) → Prog)) bltin-cons = ("Data.Vec.Base.Vec.[]" , λ _ → ok "nil") ∷ ("Array.Base.Ix.[]" , λ _ → ok "nil") ∷ ("Array.Base.Ix._∷_" , λ args → {!!}) ∷ [] ct = compile (st [] bltin-defs []) (reflect test) foo : ∀ {n : ℕ} (a b : ℕ) → ℕ foo x = _+ x cr = compile (st [] bltin-defs []) (reflect foo) cconv = compile (st [] bltin-defs []) (reflect conv-2) -} --t : Term --t = reflect-ty (thm) -- PAT-LAM (cl = pats = _ m v i D(BLAS.iterate-1 D(Agda.Primitive.lzero ) D(Agda.Builtin.Nat.Nat ) V(i ) -- (\\ i₁ -> D(Agda.Builtin.Nat._*_ -- V(v C(Array.Base.Ix._∷_ 1 C(Data.Vec.Base.Vec._∷_ UNKNOWN UNKNOWN 0 V(i ) C(Data.Vec.Base.Vec.[] UNKNOWN UNKNOWN ) ) -- V(i ) -- V(_ ) -- C(Array.Base.Ix._∷_ 0 C(Data.Vec.Base.Vec.[] UNKNOWN UNKNOWN ) V(i ) V(i₁ ) C(Array.Base.Ix.[] ) ) ) ) -- D(BLAS.iterate-1 D(Agda.Primitive.lzero ) D(Agda.Builtin.Nat.Nat ) V(i ) -- (\\ i₂ -> D(Agda.Builtin.Nat._*_ -- V(v C(Array.Base.Ix._∷_ 1 C(Data.Vec.Base.Vec._∷_ UNKNOWN UNKNOWN 0 V(i ) C(Data.Vec.Base.Vec.[] UNKNOWN UNKNOWN ) ) -- V(i ) -- V(i₁ ) -- C(Array.Base.Ix._∷_ 0 C(Data.Vec.Base.Vec.[] UNKNOWN UNKNOWN ) -- V(i ) V(i₂ ) C(Array.Base.Ix.[] ) ) ) ) -- V(m C(Array.Base.Ix._∷_ 0 C(Data.Vec.Base.Vec.[] UNKNOWN UNKNOWN ) V(i ) V(i₂ ) C(Array.Base.Ix.[] ) ) ) )) -- D(Agda.Builtin.Nat._+_ ) 0 ) )) -- D(Agda.Builtin.Nat._+_ ) 0 )) (args = ) --compld _ m v i = D(for-loop-acc D(tt ) D(nat ) V(_ ) -- (\\ i₁ -> D(mult V(m (cons V(i ) (cons V(i₁ ) nil ) ) ) -- D(for-loop-acc D(tt ) D(nat ) V(_ ) -- (\\ i₂ -> D(mult V(m (cons V(i₁ ) (cons V(i₂ ) nil ) ) ) -- V(v (cons V(i₂ ) nil ) ) )) -- D(plus ) 0 ) )) -- D(plus ) 0 ) -- A * v = { i → Σ Aᵢ×v } -- A * A * v = { i → Σ Aᵢ×v }
{ "alphanum_fraction": 0.4885688569, "avg_line_length": 35.608974359, "ext": "agda", "hexsha": "3963edfcfe73bf98c6e1f0906f68473485cbe9c5", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2020-10-12T07:19:48.000Z", "max_forks_repo_forks_event_min_datetime": "2020-10-12T07:19:48.000Z", "max_forks_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "ashinkarov/agda-array", "max_forks_repo_path": "BLAS.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "ashinkarov/agda-array", "max_issues_repo_path": "BLAS.agda", "max_line_length": 155, "max_stars_count": 6, "max_stars_repo_head_hexsha": "584fedb30552f820c0668cedae53ec3d926860b5", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "ashinkarov/agda-array", "max_stars_repo_path": "BLAS.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-15T14:21:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-09T13:53:46.000Z", "num_tokens": 4015, "size": 11110 }
-- Compiled things must be a postulate module CompiledMustBePostulate where postulate A : Set foo : Set foo = A {-# COMPILED foo bar #-}
{ "alphanum_fraction": 0.7062937063, "avg_line_length": 11.9166666667, "ext": "agda", "hexsha": "0395961e6f765e0df4216a8eab2593bc096ebfc4", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/fail/CompiledMustBePostulate.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/fail/CompiledMustBePostulate.agda", "max_line_length": 38, "max_stars_count": 1, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Fail/CompiledMustBePostulate.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": 40, "size": 143 }
{-# OPTIONS --cubical --cumulativity #-} module equalities where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence open import Cubical.Data.Equality module _ {a ℓ} {A : Set a} where ≣-Type = A → A → Set ℓ record IsEquality (_≣_ : ≣-Type) : Set (ℓ-suc (ℓ-max a ℓ)) where constructor eq field ≣-≡-≡ : ∀ {x y} → let ℓ₁ = ℓ-max a ℓ x≡y : Type ℓ₁ x≡y = x ≡ y x≣y : Type ℓ₁ x≣y = x ≣ y in _≡_ {ℓ-suc ℓ₁} x≣y x≡y record Equality : Set (ℓ-suc (ℓ-max a ℓ)) where field _≣_ : ≣-Type isEquality : IsEquality _≣_ module _ {a} {A : Set a} where instance ≡-IsEquality : IsEquality {A = A} _≡_ ≡-IsEquality = eq refl instance ≡p-IsEquality : IsEquality {A = A} _≡p_ ≡p-IsEquality = eq (λ {x y} → sym λ i → p-c {x = x} {y = y} i) module _ {ℓ} where univalencePath' : {A B : Type ℓ} → (A ≡ B) ≡ (A ≃ B) univalencePath' {A} {B} = ua {ℓ-suc ℓ} {A ≡ B} {A ≃ B} (compEquiv (univalence {ℓ} {A} {B}) (isoToEquiv (iso {ℓ} {ℓ-suc ℓ} (λ x → x) (λ x → x) (λ b i → b) λ a i → a))) instance ≃-IsEquality : IsEquality {A = Type ℓ} (λ A B → (A ≃ B)) ≃-IsEquality = eq λ {A B} → sym λ i → univalencePath' {A = A} {B = B} i
{ "alphanum_fraction": 0.5576208178, "avg_line_length": 25.8653846154, "ext": "agda", "hexsha": "cdb20a7cedd2922d7ced6b5e2a9082e39d65ccb0", "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": "e1104012d85d2072318656f6c6d31acff75c9460", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "guilhermehas/Equality", "max_forks_repo_path": "equalities.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e1104012d85d2072318656f6c6d31acff75c9460", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "guilhermehas/Equality", "max_issues_repo_path": "equalities.agda", "max_line_length": 79, "max_stars_count": 1, "max_stars_repo_head_hexsha": "e1104012d85d2072318656f6c6d31acff75c9460", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "guilhermehas/Equality", "max_stars_repo_path": "equalities.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-01T06:04:21.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-01T06:04:21.000Z", "num_tokens": 572, "size": 1345 }
import Issue4267.M using () -- foo : {!Issue4267.M.R!} -- cannot give, but this is the solution foo = record { f = Set}
{ "alphanum_fraction": 0.6446280992, "avg_line_length": 24.2, "ext": "agda", "hexsha": "9437f14b00f67b4120f9e9bc2b6027d7fe4db47f", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Succeed/Issue4267a.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/Issue4267a.agda", "max_line_length": 67, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue4267a.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": 36, "size": 121 }
{-# OPTIONS --safe #-} module Cubical.Algebra.Group.Instances.Int where open import Cubical.Foundations.Prelude open import Cubical.Data.Int renaming (ℤ to ℤType ; _+_ to _+ℤ_ ; _-_ to _-ℤ_; -_ to -ℤ_ ; _·_ to _·ℤ_) open import Cubical.Algebra.Group.Base open GroupStr ℤ : Group₀ fst ℤ = ℤType 1g (snd ℤ) = 0 _·_ (snd ℤ) = _+ℤ_ inv (snd ℤ) = _-ℤ_ 0 isGroup (snd ℤ) = isGroupℤ where abstract isGroupℤ : IsGroup (pos 0) _+ℤ_ (_-ℤ_ (pos 0)) isGroupℤ = makeIsGroup isSetℤ +Assoc (λ _ → refl) (+Comm 0) (λ x → +Comm x (pos 0 -ℤ x) ∙ minusPlus x 0) (λ x → minusPlus x 0)
{ "alphanum_fraction": 0.6009463722, "avg_line_length": 28.8181818182, "ext": "agda", "hexsha": "03db1b2f073187f5d725615ee2c629ba930b67f0", "lang": "Agda", "max_forks_count": 134, "max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z", "max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z", "max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "marcinjangrzybowski/cubical", "max_forks_repo_path": "Cubical/Algebra/Group/Instances/Int.agda", "max_issues_count": 584, "max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "marcinjangrzybowski/cubical", "max_issues_repo_path": "Cubical/Algebra/Group/Instances/Int.agda", "max_line_length": 103, "max_stars_count": 301, "max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "marcinjangrzybowski/cubical", "max_stars_repo_path": "Cubical/Algebra/Group/Instances/Int.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z", "num_tokens": 251, "size": 634 }
{- revised nomenclature -} module Oscar.Data4 where record ⊤ : Set where constructor tt Const_ : ∀ {a} {A : Set a} {b} {B : Set b} → B → A → B Const_ x _ = x infixr 20 _∷_ -- List data ⟦_⟧ {a} (A : Set a) : Set a where ∅ : ⟦ A ⟧ _∷_ : A → ⟦ A ⟧ → ⟦ A ⟧ -- Nat ⟦⟧ = ⟦ ⊤ ⟧ infix 21 ¡_ pattern ¡_ ⟦A⟧ = tt ∷ ⟦A⟧ --¡ : ⟦⟧ → ⟦⟧ --¡ ⟦A⟧ = tt ∷ ⟦A⟧ -- Fin (with a payload) data ⟦_⟧[_] {a} (A : ⟦⟧ → Set a) : ⟦⟧ → Set a where ∅ : ∀ {n} → ⟦ A ⟧[ ¡ n ] _∷_ : ∀ {n} → A n → ⟦ A ⟧[ n ] → ⟦ A ⟧[ ¡ n ] ⟦⟧[_] = ⟦ Const ⊤ ⟧[_] -- Vec (with an (optional) index) data ⟦_⟧[_₀] {a} (A : ⟦⟧ → Set a) : ⟦⟧ → Set a where ∅ : ⟦ A ⟧[ ∅ ₀] _∷_ : ∀ {n} → A n → ⟦ A ⟧[ n ₀] → ⟦ A ⟧[ ¡ n ₀] ⟦⟧[_₀] = ⟦ Const ⊤ ⟧[_₀] -- m ≤ n, counting down from n-1 to m data ⟦_⟧[_≤_↓] {a} (A : ⟦⟧ → Set a) (m : ⟦⟧) : ⟦⟧ → Set a where ∅ : ⟦ A ⟧[ m ≤ m ↓] _∷_ : ∀ {n} → A n → ⟦ A ⟧[ m ≤ n ↓] → ⟦ A ⟧[ m ≤ ¡ n ↓] ⟦⟧[_≤_↓] = ⟦ Const ⊤ ⟧[_≤_↓] -- m ≤ n, counting up from m to n-1 data ⟦_⟧[↑_≤_] {a} (A : ⟦⟧ → Set a) (m : ⟦⟧) : ⟦⟧ → Set a where ∅ : ⟦ A ⟧[↑ m ≤ m ] _∷_ : ∀ {n} → A m → ⟦ A ⟧[↑ ¡ m ≤ n ] → ⟦ A ⟧[↑ m ≤ n ] ⟦⟧[↑_≤_] = ⟦ Const ⊤ ⟧[↑_≤_] -- Inj (almost) data ⟦_⟧[↓_≤_↓] {a} (A : ⟦⟧ → ⟦⟧ → Set a) : ⟦⟧ → ⟦⟧ → Set a where ∅ : ∀ {n} → ⟦ A ⟧[↓ ∅ ≤ n ↓] _∷_ : ∀ {m n} → A m n → ⟦ A ⟧[↓ m ≤ n ↓] → ⟦ A ⟧[↓ ¡ m ≤ ¡ n ↓] ⟦⟧[↓_≤_↓] = ⟦ Const Const ⊤ ⟧[↓_≤_↓] infix 21 ‼_ pattern ‼_ ⟦A⟧ = tt ∷ ⟦A⟧ -- tricky, works for all above _∷_ constructors only because it is defined afterwards, won't work for any later-defined constructors testNat : ⟦⟧ testNat = ¡ ∅ testListNat : ⟦ ⟦⟧ ⟧ testListNat = ¡ ∅ ∷ ‼ ∅ ∷ ‼ ‼ ∅ ∷ ∅ ∷ ¡ ¡ ¡ ∅ ∷ ∅ testFin : ⟦⟧[ ¡ ¡ ∅ ] testFin = ‼ ∅ test≤↓ : ⟦⟧[ ‼ ‼ ‼ ∅ ≤ ‼ ‼ ‼ ‼ ‼ ∅ ↓] test≤↓ = ‼ ‼ ∅ ⓪ ⑴ ⑵ : ⟦⟧ ⓪ = ∅ ⑴ = ‼ ∅ ⑵ = ‼ ⑴
{ "alphanum_fraction": 0.384351799, "avg_line_length": 22.164556962, "ext": "agda", "hexsha": "0514a30e9876ac39af1f03d46ddb5a601a2c9293", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-2/Oscar/Data4.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-2/Oscar/Data4.agda", "max_line_length": 158, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-2/Oscar/Data4.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1050, "size": 1751 }
{-# OPTIONS --show-irrelevant --subtyping #-} module Issue2170-unify-subtyping where data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x record Squash (A : Set) : Set where constructor squash field .unsquash : A open Squash record UnSquash (A : Set) (s : A → Squash A) : Set where constructor inverse field inv : Squash A → A prf : {a : A} → inv (s a) ≡ a test : {A : Set} → Squash (UnSquash A squash) test = squash (inverse (λ p@(squash x) → _) refl) -- `refl` is checked at type `_15 A (squash a) ≡ a` -- Before, Agda solved this as `_15 := λ A p → unsquash a`, which -- makes use of the irrelevant projection `unsquash`. -- However, this is not allowed unless `--irrelevant-projections` -- is enabled.
{ "alphanum_fraction": 0.6398362892, "avg_line_length": 27.1481481481, "ext": "agda", "hexsha": "c9cd020cc17e2f2d69b47e264a3f68b4012bf235", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "shlevy/agda", "max_forks_repo_path": "test/Fail/Issue2170-unify-subtyping.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2015-09-15T15:49:15.000Z", "max_issues_repo_issues_event_min_datetime": "2015-09-15T15:49:15.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue2170-unify-subtyping.agda", "max_line_length": 65, "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/Issue2170-unify-subtyping.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-14T11:08:59.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-14T11:08:59.000Z", "num_tokens": 246, "size": 733 }
------------------------------------------------------------------------ -- Normal and neutral terms ------------------------------------------------------------------------ open import Level using (zero) open import Data.Universe module README.DependentlyTyped.NormalForm (Uni₀ : Universe zero zero) where open import Data.Product as Prod renaming (curry to c; uncurry to uc) open import Function hiding (_∋_) renaming (const to k; _∘_ to _⊚_) import README.DependentlyTyped.Term as Term; open Term Uni₀ import Relation.Binary.PropositionalEquality as P -- Atomic types (types for which the normaliser does not do -- η-expansion). data _⊢_atomic-type (Γ : Ctxt) : Type Γ → Set where ⋆ : ∀ {σ} → Γ ⊢ ⋆ , σ atomic-type el : ∀ {σ} → Γ ⊢ el , σ atomic-type -- Two kinds: normal and neutral. data Kind : Set where no ne : Kind mutual -- Γ ⊢ σ ⟨ no ⟩ represents η-long, β-normal terms, Γ ⊢ σ ⟨ ne ⟩ -- represents neutral terms. infixl 9 _·_ infix 3 _⊢_⟨_⟩ data _⊢_⟨_⟩ (Γ : Ctxt) : Type Γ → Kind → Set where ne : ∀ {σ} (σ′ : Γ ⊢ σ atomic-type) (t : Γ ⊢ σ ⟨ ne ⟩) → Γ ⊢ σ ⟨ no ⟩ var : ∀ {σ} (x : Γ ∋ σ) → Γ ⊢ σ ⟨ ne ⟩ ƛ : ∀ {σ τ} (t : Γ ▻ σ ⊢ τ ⟨ no ⟩) → Γ ⊢ Type-π σ τ ⟨ no ⟩ _·_ : ∀ {sp₁ sp₂ σ} (t₁ : Γ ⊢ π sp₁ sp₂ , σ ⟨ ne ⟩) (t₂ : Γ ⊢ fst σ ⟨ no ⟩) → Γ ⊢ snd σ /̂ ŝub ⟦ ⌊ t₂ ⌋ ⟧ ⟨ ne ⟩ -- Normal and neutral terms can be turned into ordinary terms. ⌊_⌋ : ∀ {Γ σ k} → Γ ⊢ σ ⟨ k ⟩ → Γ ⊢ σ ⌊ ne σ′ t ⌋ = ⌊ t ⌋ ⌊ var x ⌋ = var x ⌊ ƛ t ⌋ = ƛ ⌊ t ⌋ ⌊ t₁ · t₂ ⌋ = ⌊ t₁ ⌋ · ⌊ t₂ ⌋ -- Normal and neutral terms are "term-like". Tm-n : Kind → Term-like _ Tm-n k = record { _⊢_ = λ Γ σ → Γ ⊢ σ ⟨ k ⟩; ⟦_⟧ = ⟦_⟧ ⊚ ⌊_⌋ } private open module T {k} = Term-like (Tm-n k) public using ([_]) renaming ( ⟦_⟧ to ⟦_⟧n; _≅-⊢_ to _≅-⊢n_ ; drop-subst-⊢ to drop-subst-⊢n; ⟦⟧-cong to ⟦⟧n-cong ) -- As mentioned above normal and neutral terms can be turned into -- ordinary terms. forget-n : ∀ {k} → [ Tm-n k ⟶⁼ Tm ] forget-n = record { function = λ _ → ⌊_⌋ ; corresponds = λ _ _ → P.refl } -- Various congruences. ne-cong : ∀ {Γ σ} {σ′ : Γ ⊢ σ atomic-type} {t₁ t₂ : Γ ⊢ σ ⟨ ne ⟩} → t₁ ≅-⊢n t₂ → ne σ′ t₁ ≅-⊢n ne σ′ t₂ ne-cong P.refl = P.refl var-n-cong : ∀ {Γ₁ σ₁} {x₁ : Γ₁ ∋ σ₁} {Γ₂ σ₂} {x₂ : Γ₂ ∋ σ₂} → x₁ ≅-∋ x₂ → var x₁ ≅-⊢n var x₂ var-n-cong P.refl = P.refl ƛn-cong : ∀ {Γ₁ σ₁ τ₁} {t₁ : Γ₁ ▻ σ₁ ⊢ τ₁ ⟨ no ⟩} {Γ₂ σ₂ τ₂} {t₂ : Γ₂ ▻ σ₂ ⊢ τ₂ ⟨ no ⟩} → t₁ ≅-⊢n t₂ → ƛ t₁ ≅-⊢n ƛ t₂ ƛn-cong P.refl = P.refl ·n-cong : ∀ {Γ₁ sp₁₁ sp₂₁ σ₁} {t₁₁ : Γ₁ ⊢ π sp₁₁ sp₂₁ , σ₁ ⟨ ne ⟩} {t₂₁ : Γ₁ ⊢ fst σ₁ ⟨ no ⟩} {Γ₂ sp₁₂ sp₂₂ σ₂} {t₁₂ : Γ₂ ⊢ π sp₁₂ sp₂₂ , σ₂ ⟨ ne ⟩} {t₂₂ : Γ₂ ⊢ fst σ₂ ⟨ no ⟩} → t₁₁ ≅-⊢n t₁₂ → t₂₁ ≅-⊢n t₂₂ → t₁₁ · t₂₁ ≅-⊢n t₁₂ · t₂₂ ·n-cong P.refl P.refl = P.refl
{ "alphanum_fraction": 0.4896049896, "avg_line_length": 29.4489795918, "ext": "agda", "hexsha": "cf0a5fe1d57a1657d5c2d4d85aa36830d76a5663", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/dependently-typed-syntax", "max_forks_repo_path": "README/DependentlyTyped/NormalForm.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/dependently-typed-syntax", "max_issues_repo_path": "README/DependentlyTyped/NormalForm.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/dependently-typed-syntax", "max_stars_repo_path": "README/DependentlyTyped/NormalForm.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": 1331, "size": 2886 }
------------------------------------------------------------------------ -- Semantics of the parsers ------------------------------------------------------------------------ -- Currently it is only specified when a string is _accepted_ by a -- parser; semantic actions are not included. module RecursiveDescent.Inductive.Semantics where open import RecursiveDescent.Index open import RecursiveDescent.Inductive open import RecursiveDescent.Inductive.SimpleLib open import Data.List open import Data.Product.Record open import Data.Maybe infix 3 _∈⟦_⟧_ mutual _∈⟦_⟧_ : forall {tok nt i r} -> List tok -> Parser tok nt i r -> Grammar tok nt -> Set1 s ∈⟦ p ⟧ g = Semantics g s p data Semantics {tok : Set} {nt : ParserType₁} (g : Grammar tok nt) : forall {i r} -> List tok -> Parser tok nt i r -> Set1 where !-sem : forall {e c r} s (x : nt (e , c) r) -> s ∈⟦ g x ⟧ g -> s ∈⟦ ! x ⟧ g symbol-sem : forall c -> [ c ] ∈⟦ symbol ⟧ g return-sem : forall {r} (x : r) -> [] ∈⟦ return x ⟧ g -- The following rule should really describe the intended -- semantics of _>>=_, not _⊛_. _!>>=_ should also get a rule. ⊛-sem : forall {i₁ i₂ r₁ r₂ s₁ s₂} {p₁ : Parser tok nt i₁ (r₁ -> r₂)} {p₂ : Parser tok nt i₂ r₁} -> s₁ ∈⟦ p₁ ⟧ g -> s₂ ∈⟦ p₂ ⟧ g -> s₁ ++ s₂ ∈⟦ p₁ ⊛ p₂ ⟧ g ∣ˡ-sem : forall {i₁ i₂ r s} {p₁ : Parser tok nt i₁ r} {p₂ : Parser tok nt i₂ r} -> s ∈⟦ p₁ ⟧ g -> s ∈⟦ p₁ ∣ p₂ ⟧ g ∣ʳ-sem : forall {i₁ i₂ r s} {p₁ : Parser tok nt i₁ r} {p₂ : Parser tok nt i₂ r} -> s ∈⟦ p₂ ⟧ g -> s ∈⟦ p₁ ∣ p₂ ⟧ g ------------------------------------------------------------------------ -- Soundness of recognition data NonEmpty {a : Set} : List a -> Set where nonEmpty : forall x xs -> NonEmpty (x ∷ xs) postulate sound : forall {tok nt i r} (p : Parser tok nt i r) (g : Grammar tok nt) (s : List tok) -> NonEmpty (parse-complete p g s) -> s ∈⟦ p ⟧ g
{ "alphanum_fraction": 0.4652873563, "avg_line_length": 37.5, "ext": "agda", "hexsha": "8af94cc7d5c087608e0776b47444fbad480dc22f", "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/Semantics.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/Semantics.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/Semantics.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": 651, "size": 2175 }
{-# OPTIONS --without-K #-} module algebra.group where open import algebra.group.core public open import algebra.group.morphism public open import algebra.group.gset public open import algebra.group.classifying public
{ "alphanum_fraction": 0.8045454545, "avg_line_length": 27.5, "ext": "agda", "hexsha": "3c8c80372b51c18d414971b000d47a132539e633", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z", "max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pcapriotti/agda-base", "max_forks_repo_path": "src/algebra/group.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_path": "src/algebra/group.agda", "max_line_length": 44, "max_stars_count": 20, "max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pcapriotti/agda-base", "max_stars_repo_path": "src/algebra/group.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z", "num_tokens": 43, "size": 220 }
-- ---------------------------------------------------------------------- -- The Agda σ-library -- -- Substitutions -- ---------------------------------------------------------------------- module Sigma.Subst.Core where open import Sigma.Renaming.Base open import Data.Nat using (ℕ; _+_) open import Data.Fin using (Fin) open import Function using (_∘_) open import Data.Product using (_×_; proj₁; proj₂) renaming ( _,_ to ⟨_,_⟩ ) -- ---------------------------------------------------------------------- open import Sigma.Subst.Base public splitAt : ∀ m { n } { T } → Sub T (m + n) -- ------------- → Sub T m × Sub T n splitAt m σ = ⟨ σ ∘ (id✶ m) , σ ∘ (↑✶ m) ⟩ take : ∀ m { n } { T } → Sub T (m + n) → Sub T m take m σ = proj₁ (splitAt m σ) drop : ∀ m { n } { T } → Sub T (m + n) → Sub T n drop m σ = proj₂ (splitAt m σ)
{ "alphanum_fraction": 0.4169611307, "avg_line_length": 22.9459459459, "ext": "agda", "hexsha": "a52eeca0215a767f91d6dce296f4ced26df407eb", "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": "bb895fa8a3ccbefbd2c4a135c79744ba06895be7", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "johnyob/agda-sigma", "max_forks_repo_path": "src/Sigma/Subst/Core.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bb895fa8a3ccbefbd2c4a135c79744ba06895be7", "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": "johnyob/agda-sigma", "max_issues_repo_path": "src/Sigma/Subst/Core.agda", "max_line_length": 76, "max_stars_count": null, "max_stars_repo_head_hexsha": "bb895fa8a3ccbefbd2c4a135c79744ba06895be7", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "johnyob/agda-sigma", "max_stars_repo_path": "src/Sigma/Subst/Core.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 236, "size": 849 }
{-# OPTIONS --without-K --safe #-} module Util.Relation.Binary.Closure.SymmetricTransitive where open import Relation.Binary using (Rel) open import Util.Prelude data SymTrans {α ρ} {A : Set α} (R : Rel A ρ) : Rel A (α ⊔ℓ ρ) where `base : ∀ {x y} → R x y → SymTrans R x y `sym : ∀ {x y} → SymTrans R y x → SymTrans R x y `trans : ∀ {x y z} → SymTrans R x y → SymTrans R y z → SymTrans R x z
{ "alphanum_fraction": 0.6284289277, "avg_line_length": 30.8461538462, "ext": "agda", "hexsha": "9a9cfcce6d1643c14a1ecbda2af2aaf7f07b222e", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JLimperg/msc-thesis-code", "max_forks_repo_path": "src/Util/Relation/Binary/Closure/SymmetricTransitive.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JLimperg/msc-thesis-code", "max_issues_repo_path": "src/Util/Relation/Binary/Closure/SymmetricTransitive.agda", "max_line_length": 71, "max_stars_count": 5, "max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JLimperg/msc-thesis-code", "max_stars_repo_path": "src/Util/Relation/Binary/Closure/SymmetricTransitive.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z", "num_tokens": 142, "size": 401 }