hexsha
stringlengths
40
40
size
int64
3
1.05M
ext
stringclasses
163 values
lang
stringclasses
53 values
max_stars_repo_path
stringlengths
3
945
max_stars_repo_name
stringlengths
4
112
max_stars_repo_head_hexsha
stringlengths
40
78
max_stars_repo_licenses
listlengths
1
10
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
3
945
max_issues_repo_name
stringlengths
4
113
max_issues_repo_head_hexsha
stringlengths
40
78
max_issues_repo_licenses
listlengths
1
10
max_issues_count
float64
1
116k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
3
945
max_forks_repo_name
stringlengths
4
113
max_forks_repo_head_hexsha
stringlengths
40
78
max_forks_repo_licenses
listlengths
1
10
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
3
1.05M
avg_line_length
float64
1
966k
max_line_length
int64
1
977k
alphanum_fraction
float64
0
1
65dfc6f885b523a87a84eb64b19bbe406bedf12c
863
agda
Agda
src/data/lib/prim/Agda/Primitive.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
src/data/lib/prim/Agda/Primitive.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
null
null
null
src/data/lib/prim/Agda/Primitive.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
-- The Agda primitives (preloaded). module Agda.Primitive where ------------------------------------------------------------------------ -- Universe levels ------------------------------------------------------------------------ infixl 6 _⊔_ -- Level is the first thing we need to define. -- The other postulates can only be checked if built-in Level is known. postulate Level : Set -- MAlonzo compiles Level to (). This should be safe, because it is -- not possible to pattern match on levels. {-# COMPILED_TYPE Level () #-} {-# BUILTIN LEVEL Level #-} postulate lzero : Level lsuc : (ℓ : Level) → Level _⊔_ : (ℓ₁ ℓ₂ : Level) → Level {-# COMPILED lzero () #-} {-# COMPILED lsuc (\_ -> ()) #-} {-# COMPILED _⊔_ (\_ _ -> ()) #-} {-# BUILTIN LEVELZERO lzero #-} {-# BUILTIN LEVELSUC lsuc #-} {-# BUILTIN LEVELMAX _⊔_ #-}
24.657143
72
0.511008
7c122044cd7e023fc76b55c74e382d1d40d100ec
517
agda
Agda
agda/Path/Reasoning.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
4
2021-01-05T14:07:44.000Z
2021-01-05T15:32:14.000Z
agda/Path/Reasoning.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Path/Reasoning.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
1
2021-01-05T14:05:30.000Z
2021-01-05T14:05:30.000Z
{-# OPTIONS --cubical --safe #-} module Path.Reasoning where open import Prelude infixr 2 ≡˘⟨⟩-syntax _≡⟨⟩_ ≡⟨∙⟩-syntax ≡˘⟨⟩-syntax : ∀ (x : A) {y z} → y ≡ z → y ≡ x → x ≡ z ≡˘⟨⟩-syntax _ y≡z y≡x = sym y≡x ; y≡z syntax ≡˘⟨⟩-syntax x y≡z y≡x = x ≡˘⟨ y≡x ⟩ y≡z ≡⟨∙⟩-syntax : ∀ (x : A) {y z} → y ≡ z → x ≡ y → x ≡ z ≡⟨∙⟩-syntax _ y≡z x≡y = x≡y ; y≡z syntax ≡⟨∙⟩-syntax x y≡z x≡y = x ≡⟨ x≡y ⟩ y≡z _≡⟨⟩_ : ∀ (x : A) {y} → x ≡ y → x ≡ y _ ≡⟨⟩ x≡y = x≡y infix 2.5 _∎ _∎ : ∀ {A : Type a} (x : A) → x ≡ x _∎ x = refl
20.68
53
0.441006
586f964af4dd05843248cf5ec187a1796c182674
23,608
agda
Agda
src/meta-vars.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
src/meta-vars.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
src/meta-vars.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
import cedille-options open import general-util module meta-vars (options : cedille-options.options) {mF : Set → Set} {{_ : monad mF}} where open import lib open import functions open import cedille-types open import constants open import conversion open import ctxt open import is-free open import rename open import spans options {mF} open import subst open import syntax-util open import to-string options -- TODO propose adding these to the standard lib module helpers where -- src/spans.agda _≫=spane_ : ∀ {A B : Set} → spanM (error-t A) → (A → spanM (error-t B)) → spanM (error-t B) (s₁ ≫=spane f) = s₁ ≫=span λ { (no-error x) → f x ; (yes-error x) → spanMr (yes-error x)} -- sum.agda is-inj₁ : ∀ {a b} {A : Set a} {B : Set b} → A ∨ B → 𝔹 is-inj₁ (inj₁ x) = tt is-inj₁ (inj₂ y) = ff open helpers -- misc ---------------------------------------------------------------------- -- Meta-variables, prototypes, decorated types -- ================================================== record meta-var-sol (A : Set) : Set where constructor mk-meta-var-sol field sol : A src : checking-mode data meta-var-sort : Set where meta-var-tp : (k : kind) → (mtp : maybe $ meta-var-sol type) → meta-var-sort meta-var-tm : (tp : type) → (mtm : maybe $ meta-var-sol term) → meta-var-sort record meta-var : Set where constructor meta-var-mk field name : string sort : meta-var-sort loc : span-location open meta-var pattern meta-var-mk-tp x k mtp l = meta-var-mk x (meta-var-tp k mtp) l record meta-vars : Set where constructor meta-vars-mk field order : 𝕃 var varset : trie meta-var open meta-vars data prototype : Set where proto-maybe : maybe type → prototype proto-arrow : maybeErased → prototype → prototype data decortype : Set where decor-type : type → decortype decor-arrow : maybeErased → type → decortype → decortype decor-decor : maybeErased → posinfo → bvar → meta-var-sort → decortype → decortype decor-stuck : type → prototype → decortype decor-error : type → prototype → decortype -- Simple definitions and accessors -- -------------------------------------------------- meta-var-name : meta-var → var meta-var-name X = meta-var.name X meta-vars-get-varlist : meta-vars → 𝕃 var meta-vars-get-varlist Xs = map (name ∘ snd) (trie-mappings (varset Xs)) meta-var-solved? : meta-var → 𝔹 meta-var-solved? (meta-var-mk n (meta-var-tp k nothing) _) = ff meta-var-solved? (meta-var-mk n (meta-var-tp k (just _)) _) = tt meta-var-solved? (meta-var-mk n (meta-var-tm tp nothing) _) = ff meta-var-solved? (meta-var-mk n (meta-var-tm tp (just _)) _) = tt meta-vars-empty : meta-vars meta-vars-empty = meta-vars-mk [] empty-trie meta-vars-empty? : meta-vars → 𝔹 meta-vars-empty? Xs = ~ (trie-nonempty (varset Xs )) meta-vars-solved? : meta-vars → 𝔹 meta-vars-solved? Xs = trie-all meta-var-solved? (varset Xs) meta-vars-filter : (meta-var → 𝔹) → meta-vars → meta-vars meta-vars-filter f Xs = meta-vars-mk or vs where vs = trie-filter f (varset Xs) or = filter (trie-contains vs) (order Xs) meta-var-sort-eq? : ctxt → (=S =T : meta-var-sort) → 𝔹 meta-var-sort-eq? Γ (meta-var-tp k₁ mtp₁) (meta-var-tp k₂ mtp₂) with conv-kind Γ k₁ k₂ ... | ff = ff ... | tt = maybe-equal? sol-eq mtp₁ mtp₂ where sol-eq : (sol₁ sol₂ : meta-var-sol type) → 𝔹 sol-eq (mk-meta-var-sol sol₁ src) (mk-meta-var-sol sol₂ src₁) = conv-type Γ sol₁ sol₂ meta-var-sort-eq? _ _ _ = ff -- TODO terms not supported -- meta-var-sol-eq? (meta-var-tm tp mtm) (meta-var-tm tp₁ mtm₁) = {!!} meta-var-equal? : ctxt → (X Y : meta-var) → 𝔹 meta-var-equal? Γ (meta-var-mk name₁ sol₁ _) (meta-var-mk name₂ sol₂ _) = name₁ =string name₂ && meta-var-sort-eq? Γ sol₁ sol₂ meta-vars-equal? : ctxt → (Xs Ys : meta-vars) → 𝔹 meta-vars-equal? Γ Xs Ys = trie-equal? (meta-var-equal? Γ) (meta-vars.varset Xs) (meta-vars.varset Ys) meta-vars-lookup : meta-vars → var → maybe meta-var meta-vars-lookup Xs x = trie-lookup (varset Xs) x meta-vars-lookup-with-kind : meta-vars → var → maybe (meta-var × kind) meta-vars-lookup-with-kind Xs x with meta-vars-lookup Xs x ... | nothing = nothing ... | (just X@(meta-var-mk-tp _ k _ _)) = just $ X , k ... | (just X) = nothing meta-var-set-src : meta-var → checking-mode → meta-var meta-var-set-src (meta-var-mk-tp name₁ k (just sol) loc₁) m = meta-var-mk-tp name₁ k (just (record sol { src = m })) loc₁ meta-var-set-src (meta-var-mk-tp name₁ k nothing loc₁) m = meta-var-mk-tp name₁ k nothing loc₁ meta-var-set-src (meta-var-mk name₁ (meta-var-tm tp (just sol)) loc₁) m = meta-var-mk name₁ (meta-var-tm tp (just (record sol { src = m }))) loc₁ meta-var-set-src (meta-var-mk name₁ (meta-var-tm tp nothing) loc₁) m = meta-var-mk name₁ (meta-var-tm tp nothing) loc₁ meta-vars-lookup-kind : meta-vars → var → maybe kind meta-vars-lookup-kind Xs x with meta-vars-lookup Xs x ... | nothing = nothing ... | (just (meta-var-mk-tp _ k _ _)) = just k ... | (just X) = nothing -- conversion to types, terms, tks -- -------------------------------------------------- meta-var-sort-to-tk : meta-var-sort → tk meta-var-sort-to-tk (meta-var-tp k mtp) = Tkk k meta-var-sort-to-tk (meta-var-tm tp mtm) = Tkt tp meta-var-to-type : meta-var → maybe type meta-var-to-type (meta-var-mk-tp x k (just tp) _) = just (meta-var-sol.sol tp) meta-var-to-type (meta-var-mk-tp x k nothing _) = just (TpVar posinfo-gen x) meta-var-to-type (meta-var-mk x (meta-var-tm tp mtm) _) = nothing meta-var-to-term : meta-var → maybe term meta-var-to-term (meta-var-mk-tp x k mtp _) = nothing meta-var-to-term (meta-var-mk x (meta-var-tm tp (just tm)) _) = just (meta-var-sol.sol tm) meta-var-to-term (meta-var-mk x (meta-var-tm tp nothing) _) = just (Var posinfo-gen x) meta-var-to-type-unsafe : meta-var → type meta-var-to-type-unsafe X with meta-var-to-type X ... | just tp = tp ... | nothing = TpVar posinfo-gen (meta-var-name X) meta-var-to-term-unsafe : meta-var → term meta-var-to-term-unsafe X with meta-var-to-term X ... | just tm = tm ... | nothing = Var posinfo-gen (meta-var-name X) prototype-to-maybe : prototype → maybe type prototype-to-maybe (proto-maybe mtp) = mtp prototype-to-maybe (proto-arrow _ _) = nothing prototype-to-checking : prototype → checking-mode prototype-to-checking = maybe-to-checking ∘ prototype-to-maybe decortype-to-type : decortype → type decortype-to-type (decor-type tp) = tp decortype-to-type (decor-arrow at tp dt) = TpArrow tp at (decortype-to-type dt) decortype-to-type (decor-decor b pi x sol dt) = Abs pi b posinfo-gen x (meta-var-sort-to-tk sol) (decortype-to-type dt) decortype-to-type (decor-stuck tp pt) = tp decortype-to-type (decor-error tp pt) = tp -- hnf for decortype -- -------------------------------------------------- hnf-decortype : ctxt → unfolding → decortype → (is-head : 𝔹) → decortype hnf-decortype Γ uf (decor-type tp) ish = decor-type (hnf Γ uf tp ish) hnf-decortype Γ uf (decor-arrow e? tp dt) ish = decor-arrow e? (hnf Γ uf tp ff) (hnf-decortype Γ uf dt ff) hnf-decortype Γ uf (decor-decor e? pi x sol dt) ish = decor-decor e? pi x sol (hnf-decortype Γ uf dt ff) hnf-decortype Γ uf dt@(decor-stuck _ _) ish = dt hnf-decortype Γ uf (decor-error tp pt) ish = decor-error (hnf Γ uf tp ff) pt -- substitutions -- -------------------------------------------------- substh-meta-var-sort : substh-ret-t meta-var-sort substh-meta-var-sort Γ ρ σ (meta-var-tp k mtp) = meta-var-tp (substh Γ ρ σ k) ((flip maybe-map) mtp λ sol → record sol { sol = substh Γ ρ σ (meta-var-sol.sol sol) }) substh-meta-var-sort Γ ρ σ (meta-var-tm tp mtm) = meta-var-tm (substh Γ ρ σ tp) (flip maybe-map mtm λ sol → record sol { sol = substh Γ ρ σ (meta-var-sol.sol sol) }) subst-meta-var-sort : subst-ret-t meta-var-sort subst-meta-var-sort Γ t x (meta-var-tp k mtp) = meta-var-tp (subst Γ t x k) $ (flip maybe-map) mtp λ sol → record sol { sol = subst Γ t x $ meta-var-sol.sol sol } subst-meta-var-sort Γ t x (meta-var-tm tp mtm) = meta-var-tm (subst Γ t x tp) $ (flip maybe-map) mtm λ where (mk-meta-var-sol sol src) → mk-meta-var-sol (subst Γ t x sol) src meta-vars-get-sub : meta-vars → trie type meta-vars-get-sub Xs = trie-catMaybe (trie-map meta-var-to-type (varset Xs)) meta-vars-subst-type' : (unfold : 𝔹) → ctxt → meta-vars → type → type meta-vars-subst-type' u Γ Xs tp = let tp' = substh Γ empty-renamectxt (meta-vars-get-sub Xs) tp in if u then hnf Γ (unfolding-elab unfold-head) tp' tt else tp' meta-vars-subst-type : ctxt → meta-vars → type → type meta-vars-subst-type = meta-vars-subst-type' tt meta-vars-subst-kind : ctxt → meta-vars → kind → kind meta-vars-subst-kind Γ Xs k = hnf Γ (unfolding-elab unfold-head) (substh Γ empty-renamectxt (meta-vars-get-sub Xs) k) tt -- string and span helpers -- -------------------------------------------------- meta-var-to-string : meta-var → strM meta-var-to-string (meta-var-mk-tp name k nothing sl) = strMetaVar name sl ≫str strAdd " : " ≫str to-stringh k meta-var-to-string (meta-var-mk-tp name k (just tp) sl) = strMetaVar name sl ≫str strAdd " : " ≫str to-stringh k ≫str strAdd " = " ≫str to-stringh (meta-var-sol.sol tp) -- tp meta-var-to-string (meta-var-mk name (meta-var-tm tp nothing) sl) = strMetaVar name sl ≫str strAdd " : " ≫str to-stringh tp meta-var-to-string (meta-var-mk name (meta-var-tm tp (just tm)) sl) = strMetaVar name sl ≫str strAdd " : " ≫str to-stringh tp ≫str strAdd " = " ≫str to-stringh (meta-var-sol.sol tm) -- tm meta-vars-to-stringh : 𝕃 meta-var → strM meta-vars-to-stringh [] = strEmpty meta-vars-to-stringh (v :: []) = meta-var-to-string v meta-vars-to-stringh (v :: vs) = meta-var-to-string v ≫str strAdd ", " ≫str meta-vars-to-stringh vs meta-vars-to-string : meta-vars → strM meta-vars-to-string Xs = meta-vars-to-stringh ((flip map) (order Xs) λ x → case trie-lookup (varset Xs) x of λ where nothing → meta-var-mk (x ^ "-missing!") (meta-var-tp (Star posinfo-gen) nothing) missing-span-location (just X) → X) prototype-to-string : prototype → strM prototype-to-string (proto-maybe nothing) = strAdd "⁇" prototype-to-string (proto-maybe (just tp)) = to-stringh tp prototype-to-string (proto-arrow e? pt) = strAdd "⁇" ≫str strAdd (arrowtype-to-string e?) ≫str prototype-to-string pt decortype-to-string : decortype → strM decortype-to-string (decor-type tp) = strAdd "[" ≫str to-stringh tp ≫str strAdd "]" decortype-to-string (decor-arrow e? tp dt) = to-stringh tp ≫str strAdd (arrowtype-to-string e?) ≫str decortype-to-string dt decortype-to-string (decor-decor e? pi x sol dt) = strAdd (binder e? sol) ≫str meta-var-to-string (meta-var-mk x sol missing-span-location) ≫str strAdd " . " ≫str decortype-to-string dt where binder : maybeErased → meta-var-sort → string binder Erased sol = "∀ " binder Pi (meta-var-tm tp mtm) = "Π " -- vv clause below "shouldn't" happen binder Pi (meta-var-tp k mtp) = "∀ " decortype-to-string (decor-stuck tp pt) = strAdd "(" ≫str to-stringh tp ≫str strAdd " , " ≫str prototype-to-string pt ≫str strAdd ")" decortype-to-string (decor-error tp pt) = strAdd "([" ≫str (to-stringh tp) ≫str strAdd "] ‼ " ≫str prototype-to-string pt ≫str strAdd ")" meta-vars-data-h : ctxt → string → kind ∨ (meta-var-sol type) → tagged-val meta-vars-data-h Γ X (inj₁ k) = strRunTag "meta-vars-intro" Γ (strAdd (unqual-local X ^ " ") ≫str to-stringh k) meta-vars-data-h Γ X (inj₂ sol) = strRunTag "meta-vars-sol" Γ $ strAdd (unqual-local X ^ " ") ≫str strAdd (checking-to-string (meta-var-sol.src sol) ^ " ") ≫str (to-stringh ∘ meta-var-sol.sol $ sol) meta-vars-data-all : ctxt → meta-vars → 𝕃 tagged-val meta-vars-data-all Γ = foldr (uncurry λ where _ (meta-var-mk X (meta-var-tp kd nothing) loc) xs → meta-vars-data-h Γ X (inj₁ kd) :: xs _ (meta-var-mk X (meta-var-tp kd (just tp)) loc) xs → meta-vars-data-h Γ X (inj₁ kd) :: meta-vars-data-h Γ X (inj₂ tp) :: xs _ _ xs → xs) [] ∘ (trie-mappings ∘ meta-vars.varset) meta-vars-intro-data : ctxt → meta-vars → 𝕃 tagged-val meta-vars-intro-data Γ = map (h ∘ snd) ∘ (trie-mappings ∘ meta-vars.varset) where h : meta-var → tagged-val h (meta-var-mk X (meta-var-tp kd mtp) loc) = meta-vars-data-h Γ X (inj₁ kd) h (meta-var-mk X (meta-var-tm tp mtm) loc) = meta-vars-data-h Γ X (inj₂ (mk-meta-var-sol (TpVar posinfo-gen "unimplemented") untyped)) meta-vars-sol-data : ctxt → meta-vars → meta-vars → 𝕃 tagged-val meta-vars-sol-data Γ Xsₒ Xsₙ = foldr (λ X xs → maybe-else xs (_:: xs) (h (snd X))) [] (trie-mappings (meta-vars.varset Xsₙ)) where h : meta-var → maybe tagged-val h (meta-var-mk X (meta-var-tp kd (just tp)) loc) with trie-lookup (meta-vars.varset Xsₒ) X ...| just (meta-var-mk _ (meta-var-tp _ (just _)) _) = nothing ...| _ = just (meta-vars-data-h Γ X (inj₂ tp) ) h (meta-var-mk X (meta-var-tp kd nothing) loc) = nothing h (meta-var-mk X (meta-var-tm tp mtm) loc) = just (meta-vars-data-h Γ X (inj₂ (mk-meta-var-sol (TpVar posinfo-gen "unimplemented") untyped))) meta-vars-check-type-mismatch : ctxt → string → type → meta-vars → type → 𝕃 tagged-val × err-m meta-vars-check-type-mismatch Γ s tp Xs tp' = (expected-type Γ tp :: [ type-data Γ tp'' ]) , (if conv-type Γ tp tp'' then nothing else just ("The expected type does not match the " ^ s ^ " type.")) where tp'' = meta-vars-subst-type' ff Γ Xs tp' meta-vars-check-type-mismatch-if : maybe type → ctxt → string → meta-vars → type → 𝕃 tagged-val × err-m meta-vars-check-type-mismatch-if (just tp) Γ s Xs tp' = meta-vars-check-type-mismatch Γ s tp Xs tp' meta-vars-check-type-mismatch-if nothing Γ s Xs tp' = [ type-data Γ tp″ ] , nothing where tp″ = meta-vars-subst-type' ff Γ Xs tp' decortype-data : ctxt → decortype → tagged-val decortype-data Γ dt = strRunTag "head decoration" Γ (decortype-to-string dt) prototype-data : ctxt → prototype → tagged-val prototype-data Γ pt = strRunTag "head prototype" Γ (prototype-to-string pt) -- collecting, merging, matching -- -------------------------------------------------- meta-var-fresh-t : (S : Set) → Set meta-var-fresh-t S = meta-vars → var → span-location → S → meta-var meta-var-fresh : meta-var-fresh-t meta-var-sort meta-var-fresh Xs x sl sol with rename-away-from (meta-var-pfx-str ^ x) (trie-contains (varset Xs)) empty-renamectxt ... | x' = meta-var-mk x' sol sl meta-var-fresh-tp : meta-var-fresh-t (kind × maybe (meta-var-sol type)) meta-var-fresh-tp Xs x sl (k , msol) = meta-var-fresh Xs x sl (meta-var-tp k msol) meta-var-fresh-tm : meta-var-fresh-t (type × maybe (meta-var-sol term)) meta-var-fresh-tm Xs x sl (tp , mtm) = meta-var-fresh Xs x sl (meta-var-tm tp mtm) private meta-vars-set : meta-vars → meta-var → meta-vars meta-vars-set Xs X = record Xs { varset = trie-insert (varset Xs) (name X) X } -- add a meta-var meta-vars-add : meta-vars → meta-var → meta-vars meta-vars-add Xs X = record (meta-vars-set Xs X) { order = (order Xs) ++ [ name X ] } meta-vars-add* : meta-vars → 𝕃 meta-var → meta-vars meta-vars-add* Xs [] = Xs meta-vars-add* Xs (Y :: Ys) = meta-vars-add* (meta-vars-add Xs Y) Ys meta-vars-from-list : 𝕃 meta-var → meta-vars meta-vars-from-list Xs = meta-vars-add* meta-vars-empty Xs meta-vars-remove : meta-vars → meta-var → meta-vars meta-vars-remove (meta-vars-mk or vs) X = let x = meta-var-name X in meta-vars-mk (remove _=string_ x or) (trie-remove vs x) meta-vars-in-type : meta-vars → type → meta-vars meta-vars-in-type Xs tp = (flip meta-vars-filter) Xs λ X → are-free-in-type check-erased (trie-single (name X) triv) tp meta-vars-unsolved : meta-vars → meta-vars meta-vars-unsolved = meta-vars-filter λ where (meta-var-mk x (meta-var-tp k mtp) _) → ~ isJust mtp (meta-var-mk x (meta-var-tm tp mtm) _) → ~ isJust mtm meta-vars-are-free-in-type : meta-vars → type → 𝔹 meta-vars-are-free-in-type Xs tp = are-free-in-type check-erased (varset Xs) tp -- Unfolding a type with meta-vars -- ================================================== -- ... in order to reveal a term or type application -- "View" data structures -- -------------------------------------------------- -- The decorated type is really an arrow record is-tmabsd : Set where constructor mk-tmabsd field is-tmabsd-dt : decortype is-tmabsd-e? : maybeErased is-tmabsd-var : var is-tmabsd-dom : type is-tmabsd-var-in-body : 𝔹 is-tmabsd-cod : decortype open is-tmabsd public is-tmabsd? = decortype ∨ is-tmabsd pattern yes-tmabsd dt e? x dom occ cod = inj₂ (mk-tmabsd dt e? x dom occ cod) pattern not-tmabsd tp = inj₁ tp record is-tpabsd : Set where constructor mk-tpabsd field is-tpabsd-dt : decortype is-tpabsd-e? : maybeErased is-tpabsd-var : var is-tpabsd-kind : kind is-tpabsd-sol : maybe type is-tpabsd-body : decortype open is-tpabsd public is-tpabsd? = decortype ∨ is-tpabsd pattern yes-tpabsd dt e? x k mtp dt' = inj₂ (mk-tpabsd dt e? x k mtp dt') pattern not-tpabsd dt = inj₁ dt {-# TERMINATING #-} num-arrows-in-type : ctxt → type → ℕ num-arrows-in-type Γ tp = nait Γ (hnf' Γ tp) 0 tt where hnf' : ctxt → type → type hnf' Γ tp = hnf Γ (unfolding-elab unfold-head) tp tt nait : ctxt → type → (acc : ℕ) → 𝔹 → ℕ -- definitely another arrow nait Γ (Abs _ _ _ _ (Tkk _) tp) acc uf = nait Γ tp acc ff nait Γ (Abs _ _ _ _ (Tkt _) tp) acc uf = nait Γ tp (1 + acc) ff nait Γ (TpArrow _ _ tp) acc uf = nait Γ tp (1 + acc) ff -- definitely not another arrow nait Γ (Iota _ _ _ _ _) acc uf = acc nait Γ (Lft _ _ _ _ _) acc uf = acc nait Γ (TpEq _ _ _ _) acc uf = acc nait Γ (TpHole _) acc uf = acc nait Γ (TpLambda _ _ _ _ _) acc uf = acc nait Γ (TpVar x₁ x₂) acc tt = acc nait Γ (TpApp tp₁ tp₂) acc tt = acc nait Γ (TpAppt tp₁ x₁) acc tt = acc -- not sure nait Γ (NoSpans tp _) acc uf = nait Γ tp acc uf nait Γ (TpLet _ (DefTerm _ x _ tm) tp) acc uf = nait Γ (subst Γ tm x tp) acc uf nait Γ (TpLet _ (DefType _ x _ tp-let) tp-in) acc uf = nait Γ (subst Γ tp-let x tp-in) acc uf nait Γ (TpParens _ tp _) acc uf = nait Γ tp acc uf nait Γ tp acc ff = nait Γ (hnf' Γ tp) acc tt -- Utilities for match-types in classify.agda -- ================================================== -- -- Match a type with meta-variables in it to one without -- errors -- -------------------------------------------------- match-error-data = string × 𝕃 tagged-val match-error-t : ∀ {a} → Set a → Set a match-error-t A = match-error-data ∨ A pattern match-error e = inj₁ e pattern match-ok a = inj₂ a module meta-vars-match-errors where -- boilerplate match-error-msg = "Matching failed" -- tagged values for error messages match-lhs : {ed : exprd} → ctxt → ⟦ ed ⟧ → tagged-val match-lhs = to-string-tag "expected lhs" match-rhs : {ed : exprd} → ctxt → ⟦ ed ⟧ → tagged-val match-rhs = to-string-tag "computed rhs" the-meta-var : var → tagged-val the-meta-var x = "the meta-var" , [[ x ]] , [] the-solution : ctxt → type → tagged-val the-solution = to-string-tag "the solution" fst-snd-sol : {ed : exprd} → ctxt → (t₁ t₂ : ⟦ ed ⟧) → 𝕃 tagged-val fst-snd-sol Γ t₁ t₂ = to-string-tag "first solution" Γ t₁ :: [ to-string-tag "second solution" Γ t₂ ] lhs-rhs : {ed : exprd} → ctxt → (t₁ t₂ : ⟦ ed ⟧) → 𝕃 tagged-val lhs-rhs Γ t₁ t₂ = match-lhs Γ t₁ :: [ match-rhs Γ t₂ ] -- error-data e-solution-ineq : ctxt → (tp₁ tp₂ : type) → var → match-error-data e-solution-ineq Γ tp₁ tp₂ X = match-error-msg ^ " because it produced two incovertible solutions for a meta-variable" , the-meta-var X :: fst-snd-sol Γ tp₁ tp₂ e-match-failure : match-error-data e-match-failure = "The expected argument type is not a (first-order) match of the computed type" , [] e-matchk-failure : match-error-data e-matchk-failure = "The expected argument kind is not a (first-order) match of the computed kind" , [] e-meta-scope : ctxt → (X tp : type) → match-error-data -- e-meta-scope : ctxt → (x : var) → (tp₁ tp₂ : type) → match-error-data e-meta-scope Γ X tp = match-error-msg ^ " because the solution contains a bound variable of the computed argument type" , to-string-tag "the meta var" Γ X :: [ to-string-tag "the solution" Γ tp ] e-bad-sol-kind : ctxt → (X : var) → (sol : type) → match-error-data e-bad-sol-kind Γ X sol = "The meta-variable was matched to a type whose kind does not match its own" , the-meta-var X :: [ the-solution Γ sol ] open meta-vars-match-errors -- meta-vars-match auxiliaries -- -------------------------------------------------- local-vars = stringset meta-vars-solve-tp : ctxt → meta-vars → var → type → checking-mode → match-error-t meta-vars meta-vars-solve-tp Γ Xs x tp m with trie-lookup (varset Xs) x ... | nothing = match-error $ x ^ " is not a meta-var!" , [] ... | just (meta-var-mk _ (meta-var-tm tp' mtm) _) = match-error $ x ^ " is a term meta-var!" , [] ... | just (meta-var-mk-tp _ k nothing sl) = match-ok (meta-vars-set Xs (meta-var-mk-tp x k (just (mk-meta-var-sol tp m)) sl)) ... | just (meta-var-mk-tp _ k (just sol) _) = let mk-meta-var-sol tp' src = sol in err⊎-guard (~ conv-type Γ tp tp') (e-solution-ineq Γ tp tp x) ≫⊎ match-ok Xs -- update the kinds of HO meta-vars with -- solutions meta-vars-update-kinds : ctxt → (Xs Xsₖ : meta-vars) → meta-vars meta-vars-update-kinds Γ Xs Xsₖ = record Xs { varset = (flip trie-map) (varset Xs) λ where (meta-var-mk-tp x k mtp sl) → meta-var-mk-tp x (meta-vars-subst-kind Γ Xsₖ k) mtp sl sol → sol } hnf-elab-if : {ed : exprd} → 𝔹 → ctxt → ⟦ ed ⟧ → 𝔹 → ⟦ ed ⟧ hnf-elab-if b Γ t b' = if b then hnf Γ (unfolding-elab unfold-head) t b' else t -- Legacy for elaboration.agda -- ================================================== -- TODO: remove dependency and delete code meta-vars-add-from-tpabs : ctxt → span-location → meta-vars → is-tpabs → meta-var × meta-vars meta-vars-add-from-tpabs Γ sl Xs (mk-tpabs e? x k tp) = let Y = meta-var-fresh-tp Xs x sl (k , nothing) Xs' = meta-vars-add Xs Y tp' = subst Γ (meta-var-to-type-unsafe Y) x tp in Y , Xs' {-# TERMINATING #-} -- subst of a meta-var does not increase distance to arrow meta-vars-peel : ctxt → span-location → meta-vars → type → (𝕃 meta-var) × type meta-vars-peel Γ sl Xs (Abs pi e? pi' x tk@(Tkk k) tp) with meta-vars-add-from-tpabs Γ sl Xs (mk-tpabs e? x k tp) ... | (Y , Xs') with subst Γ (meta-var-to-type-unsafe Y) x tp ... | tp' = let ret = meta-vars-peel Γ sl Xs' tp' ; Ys = fst ret ; rtp = snd ret in (Y :: Ys , rtp) meta-vars-peel Γ sl Xs (NoSpans tp _) = meta-vars-peel Γ sl Xs tp meta-vars-peel Γ sl Xs (TpParens _ tp _) = meta-vars-peel Γ sl Xs tp meta-vars-peel Γ sl Xs tp = [] , tp meta-vars-unfold-tpapp : ctxt → meta-vars → type → is-tpabs? meta-vars-unfold-tpapp Γ Xs tp with meta-vars-subst-type Γ Xs tp ... | Abs _ b _ x (Tkk k) tp' = yes-tpabs b x k tp' ... | tp' = not-tpabs tp' meta-vars-unfold-tmapp : ctxt → span-location → meta-vars → type → 𝕃 meta-var × is-tmabs? meta-vars-unfold-tmapp Γ sl Xs tp with meta-vars-peel Γ sl Xs (meta-vars-subst-type Γ Xs tp) ... | Ys , Abs _ b _ x (Tkt dom) cod = Ys , yes-tmabs b x dom (is-free-in check-erased x cod) cod ... | Ys , TpArrow dom e? cod = Ys , yes-tmabs e? "_" dom ff cod ... | Ys , tp' = Ys , not-tmabs tp'
35.715582
101
0.629617
d12e87376a5600992d99bd9e5c071cbd1b99cdd1
58
agda
Agda
test/Fail/WrongHidingInLHS.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/WrongHidingInLHS.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/WrongHidingInLHS.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module WrongHidingInLHS where f : Set -> Set f {x} = x
8.285714
29
0.637931
2e39fc626a82d8dac3141c46911332825172e90a
1,795
agda
Agda
test/Fail/MixingCoPatternsAndCoConstructors.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Fail/MixingCoPatternsAndCoConstructors.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/Fail/MixingCoPatternsAndCoConstructors.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS --copatterns #-} module MixingCoPatternsAndCoConstructors where data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ module MStream where record Stream (A : Set) : Set where coinductive constructor _∷_ field head : A tail : Stream A open Stream weird : (n : ℕ) → Stream ℕ head (weird zero) = zero tail (weird zero) = weird zero head (weird (suc n)) = n tail (weird (suc n)) = tail (weird n) weird' : (n : ℕ) → Stream ℕ head (weird' zero) = zero tail (weird' zero) = weird' zero weird' (suc n) = n ∷ tail (weird' n) -- BAD: weird'' : (n : ℕ) → Stream ℕ weird'' zero = zero ∷ weird'' zero weird'' (suc n) = n ∷ tail (weird'' n) -- productive, but not strongly normalizing, -- should be rejected by termination checker: repeat : {A : Set}(a : A) → Stream A head (repeat a) = a tail (repeat a) = a ∷ tail (repeat a) module Coinduction where import Common.Level open import Common.Coinduction record Stream (A : Set) : Set where inductive constructor _∷_ field head : A tail : ∞ (Stream A) open Stream weird'' : (n : ℕ) → Stream ℕ weird'' zero = zero ∷ (♯ weird'' zero) weird'' (suc n) = n ∷ tail (weird'' n) module CoList where mutual data CoList (A : Set) : Set where [] : CoList A _∷_ : (x : A)(xs : CoList∞ A) → CoList A record CoList∞ (A : Set) : Set where coinductive constructor delay field force : CoList A open CoList∞ downFrom : (n : ℕ) → CoList ℕ downFrom zero = [] downFrom (suc n) = n ∷ delay (downFrom n) down : (n : ℕ) → CoList∞ ℕ force (down zero) = [] force (down (suc n)) = n ∷ delay (force (down n)) -- weird detour: delay (force ... to test termination checker
21.117647
65
0.576045
65c711dbbe5a0da2d5bfa08a2c2245f2cdd68b1f
471
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Relation/Subset/Setoid.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Subset/Setoid.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Subset/Setoid.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Binary.Subset.Setoid directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Data.List.Relation.Subset.Setoid {c ℓ} (S : Setoid c ℓ) where open import Data.List.Relation.Binary.Subset.Setoid S public
29.4375
72
0.507431
4d806423de6fe7056c442d578299ed911c8475b8
1,672
agda
Agda
Definition/LogicalRelation/Substitution/Weakening.agda
fhlkfy/logrel-mltt
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
[ "MIT" ]
30
2017-05-20T03:05:21.000Z
2022-03-30T18:01:07.000Z
Definition/LogicalRelation/Substitution/Weakening.agda
fhlkfy/logrel-mltt
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
[ "MIT" ]
4
2017-06-22T12:49:23.000Z
2021-02-22T10:37:24.000Z
Definition/LogicalRelation/Substitution/Weakening.agda
fhlkfy/logrel-mltt
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
[ "MIT" ]
8
2017-10-18T14:18:20.000Z
2021-11-27T15:58:33.000Z
{-# OPTIONS --without-K --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution.Weakening {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.Untyped.Properties open import Definition.LogicalRelation open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Substitution open import Tools.Nat open import Tools.Product import Tools.PropositionalEquality as PE private variable n : Nat Γ : Con Term n -- Weakening of valid types by one. wk1ᵛ : ∀ {A F l} ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ]) → Γ ⊩ᵛ⟨ l ⟩ A / [Γ] → Γ ∙ F ⊩ᵛ⟨ l ⟩ wk1 A / [Γ] ∙ [F] wk1ᵛ {A = A} [Γ] [F] [A] ⊢Δ [σ] = let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ])) [σA]′ = irrelevance′ (PE.sym (subst-wk A)) [σA] in [σA]′ , (λ [σ′] [σ≡σ′] → irrelevanceEq″ (PE.sym (subst-wk A)) (PE.sym (subst-wk A)) [σA] [σA]′ (proj₂ ([A] ⊢Δ (proj₁ [σ])) (proj₁ [σ′]) (proj₁ [σ≡σ′]))) -- Weakening of valid type equality by one. wk1Eqᵛ : ∀ {A B F l} ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ]) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) ([A≡B] : Γ ⊩ᵛ⟨ l ⟩ A ≡ B / [Γ] / [A]) → Γ ∙ F ⊩ᵛ⟨ l ⟩ wk1 A ≡ wk1 B / [Γ] ∙ [F] / wk1ᵛ {A = A} {F} [Γ] [F] [A] wk1Eqᵛ {A = A} {B} [Γ] [F] [A] [A≡B] ⊢Δ [σ] = let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ])) [σA]′ = irrelevance′ (PE.sym (subst-wk A)) [σA] in irrelevanceEq″ (PE.sym (subst-wk A)) (PE.sym (subst-wk B)) [σA] [σA]′ ([A≡B] ⊢Δ (proj₁ [σ]))
31.54717
83
0.5
73eb3fa8b18ba92e392e1d0e2abe22d85e8845ab
6,171
agda
Agda
src/Categories/Object/Product/Core.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
src/Categories/Object/Product/Core.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
src/Categories/Object/Product/Core.agda
glittershark/agda-categories
2128fab9e8d341364cbf784bb17c547bf73891de
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} open import Categories.Category module Categories.Object.Product.Core {o ℓ e} (𝒞 : Category o ℓ e) where open import Level open import Function using (flip; _$_) open import Categories.Morphism 𝒞 open import Categories.Morphism.Reasoning 𝒞 open Category 𝒞 open HomReasoning private variable A B C D X Y Z : Obj h i j : A ⇒ B -- Borrowed from Dan Doel's definition of products record Product (A B : Obj) : Set (o ⊔ ℓ ⊔ e) where infix 10 ⟨_,_⟩ field A×B : Obj π₁ : A×B ⇒ A π₂ : A×B ⇒ B ⟨_,_⟩ : C ⇒ A → C ⇒ B → C ⇒ A×B project₁ : π₁ ∘ ⟨ h , i ⟩ ≈ h project₂ : π₂ ∘ ⟨ h , i ⟩ ≈ i unique : π₁ ∘ h ≈ i → π₂ ∘ h ≈ j → ⟨ i , j ⟩ ≈ h open Equiv g-η : ⟨ π₁ ∘ h , π₂ ∘ h ⟩ ≈ h g-η = unique refl refl η : ⟨ π₁ , π₂ ⟩ ≈ id η = unique identityʳ identityʳ ⟨⟩-cong₂ : ∀ {f f′ : C ⇒ A} {g g′ : C ⇒ B} → f ≈ f′ → g ≈ g′ → ⟨ f , g ⟩ ≈ ⟨ f′ , g′ ⟩ ⟨⟩-cong₂ f≡f′ g≡g′ = unique (project₁ ○ ⟺ f≡f′) (project₂ ○ ⟺ g≡g′) ∘-distribʳ-⟨⟩ : ∀ {f : C ⇒ A} {g : C ⇒ B} {q : D ⇒ C} → ⟨ f , g ⟩ ∘ q ≈ ⟨ f ∘ q , g ∘ q ⟩ ∘-distribʳ-⟨⟩ = ⟺ $ unique (pullˡ project₁) (pullˡ project₂) unique′ : π₁ ∘ h ≈ π₁ ∘ i → π₂ ∘ h ≈ π₂ ∘ i → h ≈ i unique′ eq₁ eq₂ = trans (sym (unique eq₁ eq₂)) g-η module _ {A B : Obj} where open Product {A} {B} renaming (⟨_,_⟩ to _⟨_,_⟩) repack : (p₁ p₂ : Product A B) → A×B p₁ ⇒ A×B p₂ repack p₁ p₂ = p₂ ⟨ π₁ p₁ , π₂ p₁ ⟩ repack∘ : (p₁ p₂ p₃ : Product A B) → repack p₂ p₃ ∘ repack p₁ p₂ ≈ repack p₁ p₃ repack∘ p₁ p₂ p₃ = ⟺ $ unique p₃ (glueTrianglesʳ (project₁ p₃) (project₁ p₂)) (glueTrianglesʳ (project₂ p₃) (project₂ p₂)) repack≡id : (p : Product A B) → repack p p ≈ id repack≡id = η repack-cancel : (p₁ p₂ : Product A B) → repack p₁ p₂ ∘ repack p₂ p₁ ≈ id repack-cancel p₁ p₂ = repack∘ p₂ p₁ p₂ ○ repack≡id p₂ up-to-iso : ∀ (p₁ p₂ : Product A B) → Product.A×B p₁ ≅ Product.A×B p₂ up-to-iso p₁ p₂ = record { from = repack p₁ p₂ ; to = repack p₂ p₁ ; iso = record { isoˡ = repack-cancel p₂ p₁ ; isoʳ = repack-cancel p₁ p₂ } } transport-by-iso : ∀ (p : Product A B) → ∀ {X} → Product.A×B p ≅ X → Product A B transport-by-iso p {X} p≅X = record { A×B = X ; π₁ = π₁ ∘ to ; π₂ = π₂ ∘ to ; ⟨_,_⟩ = λ h₁ h₂ → from ∘ ⟨ h₁ , h₂ ⟩ ; project₁ = cancelInner isoˡ ○ project₁ ; project₂ = cancelInner isoˡ ○ project₂ ; unique = λ {_ i l r} pf₁ pf₂ → begin from ∘ ⟨ l , r ⟩ ≈˘⟨ refl⟩∘⟨ ⟨⟩-cong₂ pf₁ pf₂ ⟩ from ∘ ⟨ (π₁ ∘ to) ∘ i , (π₂ ∘ to) ∘ i ⟩ ≈⟨ refl⟩∘⟨ unique sym-assoc sym-assoc ⟩ from ∘ to ∘ i ≈⟨ cancelˡ isoʳ ⟩ i ∎ } where open Product p open _≅_ p≅X Reversible : (p : Product A B) → Product B A Reversible p = record { A×B = A×B ; π₁ = π₂ ; π₂ = π₁ ; ⟨_,_⟩ = flip ⟨_,_⟩ ; project₁ = project₂ ; project₂ = project₁ ; unique = flip unique } where open Product p Commutative : (p₁ : Product A B) (p₂ : Product B A) → Product.A×B p₁ ≅ Product.A×B p₂ Commutative p₁ p₂ = up-to-iso p₁ (Reversible p₂) Associable : ∀ (p₁ : Product X Y) (p₂ : Product Y Z) (p₃ : Product X (Product.A×B p₂)) → Product (Product.A×B p₁) Z Associable p₁ p₂ p₃ = record { A×B = A×B p₃ ; π₁ = p₁ ⟨ π₁ p₃ , π₁ p₂ ∘ π₂ p₃ ⟩ ; π₂ = π₂ p₂ ∘ π₂ p₃ ; ⟨_,_⟩ = λ f g → p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩ ; project₁ = λ {_ f g} → begin p₁ ⟨ π₁ p₃ , π₁ p₂ ∘ π₂ p₃ ⟩ ∘ p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩ ≈⟨ ∘-distribʳ-⟨⟩ p₁ ⟩ p₁ ⟨ π₁ p₃ ∘ p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩ , (π₁ p₂ ∘ π₂ p₃) ∘ p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ p₁ (project₁ p₃) (glueTrianglesˡ (project₁ p₂) (project₂ p₃)) ⟩ p₁ ⟨ π₁ p₁ ∘ f , π₂ p₁ ∘ f ⟩ ≈⟨ g-η p₁ ⟩ f ∎ ; project₂ = λ {_ f g} → glueTrianglesˡ (project₂ p₂) (project₂ p₃) ; unique = λ {_ i f g} pf₁ pf₂ → begin p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ p₃ (∘-resp-≈ʳ (sym pf₁)) (⟨⟩-cong₂ p₂ (∘-resp-≈ʳ (sym pf₁)) (sym pf₂)) ⟩ p₃ ⟨ π₁ p₁ ∘ p₁ ⟨ π₁ p₃ , π₁ p₂ ∘ π₂ p₃ ⟩ ∘ i , p₂ ⟨ π₂ p₁ ∘ p₁ ⟨ π₁ p₃ , π₁ p₂ ∘ π₂ p₃ ⟩ ∘ i , (π₂ p₂ ∘ π₂ p₃) ∘ i ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ p₃ (pullˡ (project₁ p₁)) (⟨⟩-cong₂ p₂ (trans (pullˡ (project₂ p₁)) assoc) assoc) ⟩ p₃ ⟨ π₁ p₃ ∘ i , p₂ ⟨ π₁ p₂ ∘ π₂ p₃ ∘ i , π₂ p₂ ∘ π₂ p₃ ∘ i ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ p₃ refl (g-η p₂) ⟩ p₃ ⟨ π₁ p₃ ∘ i , π₂ p₃ ∘ i ⟩ ≈⟨ g-η p₃ ⟩ i ∎ } where open Product renaming (⟨_,_⟩ to _⟨_,_⟩) open Equiv Associative : ∀ (p₁ : Product X Y) (p₂ : Product Y Z) (p₃ : Product X (Product.A×B p₂)) (p₄ : Product (Product.A×B p₁) Z) → (Product.A×B p₃) ≅ (Product.A×B p₄) Associative p₁ p₂ p₃ p₄ = up-to-iso (Associable p₁ p₂ p₃) p₄ Mobile : ∀ {A₁ B₁ A₂ B₂} (p : Product A₁ B₁) → A₁ ≅ A₂ → B₁ ≅ B₂ → Product A₂ B₂ Mobile p A₁≅A₂ B₁≅B₂ = record { A×B = A×B ; π₁ = from A₁≅A₂ ∘ π₁ ; π₂ = from B₁≅B₂ ∘ π₂ ; ⟨_,_⟩ = λ h k → ⟨ to A₁≅A₂ ∘ h , to B₁≅B₂ ∘ k ⟩ ; project₁ = begin (from A₁≅A₂ ∘ π₁) ∘ ⟨ to A₁≅A₂ ∘ _ , to B₁≅B₂ ∘ _ ⟩ ≈⟨ pullʳ project₁ ⟩ from A₁≅A₂ ∘ (to A₁≅A₂ ∘ _) ≈⟨ cancelˡ (isoʳ A₁≅A₂) ⟩ _ ∎ ; project₂ = begin (from B₁≅B₂ ∘ π₂) ∘ ⟨ to A₁≅A₂ ∘ _ , to B₁≅B₂ ∘ _ ⟩ ≈⟨ pullʳ project₂ ⟩ from B₁≅B₂ ∘ (to B₁≅B₂ ∘ _) ≈⟨ cancelˡ (isoʳ B₁≅B₂) ⟩ _ ∎ ; unique = λ pfˡ pfʳ → unique (switch-fromtoˡ A₁≅A₂ (sym-assoc ○ pfˡ)) (switch-fromtoˡ B₁≅B₂ (sym-assoc ○ pfʳ)) } where open Product p open _≅_
37.4
150
0.456814
ed6332e1b31ebcfb43c86d4e4dad168b2900ea7a
507
agda
Agda
test/Succeed/Issue259.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue259.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue259.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Eta contraction didn't consider hiding when contracting, -- leading to the following module not type checking. module Issue259 where postulate A : Set B : A → Set foo : (∀ x → B x) → A q : ∀ {x} → B x foo′ : (∀ {x} → B x) → A bar : A bar = foo (λ y → q {y}) Baz : B bar → Set → Set Baz b C with C Baz b C | _ = C -- In fact you're not allowed to eta contract hidden lambdas at all. bar′ : A bar′ = foo′ (λ {y} → q {y}) Baz′ : B bar′ → Set → Set Baz′ b C with C Baz′ b C | _ = C
18.777778
68
0.56213
7c7cb8dff62919494147d3da1c92c307de1d6838
622
agda
Agda
Cubical/Data/Nat/Literals.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Data/Nat/Literals.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Data/Nat/Literals.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{- Importing and re-exporting this module allows for (constrained) natural number and negative integer literals for any type (e.g. Int, ℕ₋₁, ℕ₋₂, ℕ₊₁). -} {-# OPTIONS --no-exact-split --safe #-} module Cubical.Data.Nat.Literals where open import Agda.Builtin.FromNat public renaming (Number to HasFromNat) open import Agda.Builtin.FromNeg public renaming (Negative to HasFromNeg) open import Cubical.Data.Unit.Base public -- Natural number literals for ℕ open import Agda.Builtin.Nat renaming (Nat to ℕ) instance fromNatℕ : HasFromNat ℕ fromNatℕ = record { Constraint = λ _ → Unit ; fromNat = λ n → n }
27.043478
80
0.733119
36fb96893d39ece27e09ecf628f7697c9b421629
679
agda
Agda
test/Succeed/Issue1946-1.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1946-1.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1946-1.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- This test case seems to be due to Andreas Abel, Andrea Vezzosi and -- NAD. The code below should be rejected. {-# OPTIONS --sized-types #-} open import Agda.Builtin.Size data SizeLt (i : Size) : Set where size : (j : Size< i) → SizeLt i -- Legal again in 2.5.1 getSize : ∀{i} → SizeLt i → Size getSize (size j) = j -- Structurally inductive (c), coinductive via sizes. data U (i : Size) : Set where c : ((s : SizeLt i) → U (getSize s)) → U i data ⊥ : Set where empty : U ∞ → ⊥ empty (c f) = empty (f (size ∞)) -- f x <= f < c f -- If U is a data type this should not be possible: inh : ∀ i → U i inh i = c λ{ (size j) → inh j } absurd : ⊥ absurd = empty (inh ∞)
22.633333
69
0.603829
65c8b6f964c584d78a262d36424f6060b4da37e0
1,528
agda
Agda
examples/outdated-and-incorrect/cbs/Interp.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/outdated-and-incorrect/cbs/Interp.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/outdated-and-incorrect/cbs/Interp.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Proc module Interp (param : Param) where import Hear open import Basics private open module P = Process param open module H = Hear param open Tran data Result {a : U}(p : Proc a) : Set where speak : forall {w q} -> p -! w !-> q -> Result p refuse : Silent p -> Result p upR : {a b : U}{p : Proc b}(φ : Tran a b) -> Result p -> Result (φ /| p) upR φ (speak s) = speak (tx-/| s) upR φ (refuse s) = refuse (silent-/| s) Oracle : Set Oracle = Nat -> LR prophecy : Oracle -> LR prophecy ol = ol zero nextOracle : Oracle -> Oracle nextOracle ol = ol % suc anyOracle : Oracle anyOracle _ = left ocons : LR -> Oracle -> Oracle ocons l or zero = l ocons l or (suc n) = or n step : {a : U}{p : Proc a} -> Guard p -> Oracle -> Result p step og _ = refuse silent-o step (>g _) _ = refuse silent-> step (w !g p) _ = speak tx-! step (w ! p +g f) _ = speak tx-+ step (defg x g) ol with step g ol ... | refuse s1 = refuse (silent-def s1) ... | speak s1 = speak (tx-def s1) step (g1 ||g g2) ol with step g1 (nextOracle ol) | step g2 (nextOracle ol) | prophecy ol ... | refuse s1 | refuse s2 | _ = refuse (silent-|| s1 s2) ... | speak s1 | refuse s2 | _ = speak (tx-!| s1 (sound g2)) ... | refuse s1 | speak s2 | _ = speak (tx-|! (sound g1) s2) ... | speak s1 | speak _ | left = speak (tx-!| s1 (sound g2)) ... | speak _ | speak s2 | right = speak (tx-|! (sound g1) s2) step (φ /|g g) ol = upR φ (step g ol)
27.781818
72
0.556283
64d2d2e343be30772bef3b710341b0e964b2d553
689
agda
Agda
LibraBFT/ImplShared/Base/Types.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
4
2020-12-16T19:43:41.000Z
2021-12-18T19:24:05.000Z
LibraBFT/ImplShared/Base/Types.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
72
2021-02-04T05:04:33.000Z
2022-03-25T05:36:11.000Z
LibraBFT/ImplShared/Base/Types.agda
oracle/bft-consensus-agda
49f8b1b70823be805d84ffc3157c3b880edb1e92
[ "UPL-1.0" ]
6
2020-12-16T19:43:52.000Z
2022-02-18T01:04:32.000Z
{- 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 -} module LibraBFT.ImplShared.Base.Types where open import LibraBFT.Prelude open import LibraBFT.Hash NodeId : Set NodeId = ℕ _≟NodeId_ : (n1 n2 : NodeId) → Dec (n1 ≡ n2) _≟NodeId_ = _≟ℕ_ UID : Set UID = Hash _≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁) _≟UID_ = _≟Hash_ -- Just in case RoundManager is at a higher level in future ℓ-RoundManager : Level ℓ-RoundManager = 0ℓ ℓ-VSFP : Level ℓ-VSFP = 1ℓ ℓ⊔ ℓ-RoundManager
23.758621
111
0.689405
3f688f384bbed4e8ea1c1fa10a98678740095c96
4,080
agda
Agda
src/Data/List/Membership/Setoid/Distinct.agda
tizmd/agda-distinct-disjoint
d4cd2a3442a9b58e6139499d16a2b31268f27f80
[ "MIT" ]
null
null
null
src/Data/List/Membership/Setoid/Distinct.agda
tizmd/agda-distinct-disjoint
d4cd2a3442a9b58e6139499d16a2b31268f27f80
[ "MIT" ]
null
null
null
src/Data/List/Membership/Setoid/Distinct.agda
tizmd/agda-distinct-disjoint
d4cd2a3442a9b58e6139499d16a2b31268f27f80
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --without-K #-} open import Relation.Binary module Data.List.Membership.Setoid.Distinct where open import Data.List as List using (List; []; _∷_; _++_) open import Data.List.Any as Any hiding (map; head; tail) open import Data.List.Any.Properties open import Relation.Binary.PropositionalEquality as P using (_≡_) open import Function open import Function.Equivalence using (_⇔_; equivalence) open import Function.Equality using (_⟨$⟩_) open import Function.Inverse using () open import Function.Injection using (_↣_; Injection) open import Data.Product hiding (map) open import Data.Sum hiding (map) import Level as L open import Data.Fin as Fin using (Fin) open import Data.Nat as ℕ module _ {a p} {S : Setoid a p} where open Setoid S renaming (Carrier to A) open import Data.List.Membership.Setoid (S) open import Data.List.Membership.Setoid.Properties open import Data.List.Membership.Setoid.Disjoint (S) renaming (Disjoint to _⋈_) open import Data.List.Membership.Setoid.Trans (S) open import Data.Empty data Distinct : List A → Set (a L.⊔ p) where distinct-[] : Distinct [] _distinct-∷_by_ : ∀ x {xs} → Distinct xs → x ∉ xs → Distinct (x ∷ xs) head : ∀ {x}{xs : List A} → Distinct (x ∷ xs) → A head (x distinct-∷ _ by _) = x tail : ∀ {x}{xs : List A} → Distinct (x ∷ xs) → Distinct xs tail (_ distinct-∷ dis by _) = dis head∉tail : ∀ {x}{xs : List A} → Distinct (x ∷ xs) → x ∉ xs head∉tail (_ distinct-∷ _ by x∉xs) = x∉xs distinct-[_] : ∀ x → Distinct (List.[ x ]) distinct-[ x ] = x distinct-∷ distinct-[] by (λ ()) ⋈-++ : ∀ (xs ys : List A) → Distinct (xs ++ ys) ⇔ (Distinct xs × Distinct ys × xs ⋈ ys) ⋈-++ xs ys = equivalence to from where to : ∀ {xs ys : List A} → Distinct (xs ++ ys) → (Distinct xs × Distinct ys × xs ⋈ ys) to {[]} dys = distinct-[] , dys , disjoint-[]ʳ to {x ∷ xs} {ys} (.x distinct-∷ dis by x∉xsys) with to {xs = xs} dis ... | dxs , dys , xs⋈ys = x distinct-∷ dxs by (λ x∈xs → x∉xsys (++⁺ˡ x∈xs)) , dys , λ { (here px) ∈ys → x∉xsys (++⁺ʳ xs (≈-trans-∈ (sym px) ∈ys)) ; (there ∈xs) ∈ys → xs⋈ys ∈xs ∈ys} from : ∀ {xs ys : List A} → (Distinct xs × Distinct ys × xs ⋈ ys) → Distinct (xs ++ ys) from (distinct-[] , dys , xs⋈ys) = dys from {xs = .x ∷ xs} ((x distinct-∷ dxs by x∉xs) , dys , xxs⋈ys) with from (dxs , dys , xxs⋈ys ∘ there) ... | dxsys = x distinct-∷ dxsys by λ x∈xsys → case ++⁻ xs x∈xsys of λ { (inj₁ x∈xs) → x∉xs x∈xs ; (inj₂ x∈ys) → xxs⋈ys (here refl) x∈ys} lookup-injective : {xs : List A}(dxs : Distinct xs) → ∀ {i j} → List.lookup xs i ≡ List.lookup xs j → i ≡ j lookup-injective distinct-[] {()} {()} _ lookup-injective (x distinct-∷ dxs by x∉xs) {Fin.zero} {Fin.zero} _ = P.refl lookup-injective (x distinct-∷ dxs by x∉xs) {Fin.suc i} {Fin.suc j} eq = P.cong Fin.suc (lookup-injective dxs eq) lookup-injective {xs} (x distinct-∷ dxs by x∉xs) {Fin.zero} {Fin.suc j} eq rewrite eq = ⊥-elim (x∉xs (∈-lookup S _ j)) lookup-injective (x distinct-∷ dxs by x∉xs) {Fin.suc i} {Fin.zero} eq rewrite P.sym eq = ⊥-elim (x∉xs (∈-lookup S _ i)) module _ {a₁ a₂ p₁ p₂}{S₁ : Setoid a₁ p₁} {S₂ : Setoid a₂ p₂} where open Setoid S₁ renaming (Carrier to A) using () open Setoid S₂ renaming (Carrier to B) using () open import Data.List.Membership.Setoid (S₂) renaming (_∉_ to _∉₂_) using () open import Data.List.Membership.Setoid.Properties open import Data.List.Membership.Setoid.Trans (S₁) map : (f : Injection S₁ S₂) → ∀ {xs : List A} → Distinct {S = S₁} xs → Distinct {S = S₂} (List.map (Injection.to f ⟨$⟩_) xs) map f {[]} distinct-[] = distinct-[] map f {.x ∷ xs} (x distinct-∷ dis by x∉xs) = fx distinct-∷ map f dis by lemma where fx = Injection.to f ⟨$⟩ x lemma : fx ∉₂ List.map (Injection.to f ⟨$⟩_) xs lemma p with ∈-map⁻ S₁ S₂ p ... | _ , y∈xs , fx≈fy = x∉xs (≈-trans-∈ (Injection.injective f fx≈fy) y∈xs)
48
136
0.596569
edbbf5ae73758795f3fe90df5701a7d6cf5dcb43
2,393
agda
Agda
src/Lemmachine/Resource/Universe.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
56
2015-01-20T02:11:42.000Z
2021-12-21T17:02:19.000Z
src/Lemmachine/Resource/Universe.agda
larrytheliquid/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
1
2022-03-12T12:17:51.000Z
2022-03-12T12:17:51.000Z
src/Lemmachine/Resource/Universe.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
3
2015-07-21T16:37:58.000Z
2022-03-12T11:54:10.000Z
module Lemmachine.Resource.Universe where open import Lemmachine.Request open import Lemmachine.Response open import Data.Maybe open import Data.List open import Data.Product open import Data.Bool open import Data.String AuthHead = Bool MediaType = String Handler = String Charset = String CharsetConverter = String Encoding = String Encoder = String MovedURI = String DateTime = String ETag = String data Code : Set where resourceExists serviceAvailable isAuthorized : Code forbidden allowMissingPost malformedRequest : Code uriTooLong knownContentType validContentHeaders : Code validEntityLength options allowedMethods : Code knownMethods deleteResource deleteCompleted : Code postIsCreate createPath processPost : Code contentTypesProvided languageAvailable contentTypesAccepted : Code charsetsProvided encodingsProvided variances : Code isConflict multipleChoices previouslyExisted : Code movedPermanently movedTemporarily lastModified : Code expires generateETag finishRequest body : Code El : Code → Set El resourceExists = Request → Bool El serviceAvailable = Request → Bool El isAuthorized = Request → AuthHead El forbidden = Request → Bool El allowMissingPost = Request → Bool El malformedRequest = Request → Bool El uriTooLong = Request → Bool El knownContentType = Request → Bool El validContentHeaders = Request → Bool El validEntityLength = Request → Bool El options = Request → List ResponseHeader El allowedMethods = Request → List Method El knownMethods = Request → List Method El deleteResource = Request → Bool El deleteCompleted = Request → Bool El postIsCreate = Request → Bool El createPath = Request → Maybe Path El processPost = Request → Bool El contentTypesProvided = Request → List MediaType El languageAvailable = Request → Bool El contentTypesAccepted = Request → List (MediaType × Handler) El charsetsProvided = Request → List (Charset × CharsetConverter) El encodingsProvided = Request → List (Encoding × Encoder) El variances = Request → List RequestHeader El isConflict = Request → Bool El multipleChoices = Request → Bool El previouslyExisted = Request → Bool El movedPermanently = Request → Maybe MovedURI El movedTemporarily = Request → Maybe MovedURI El lastModified = Request → Maybe DateTime El expires = Request → Maybe DateTime El generateETag = Request → Maybe ETag El finishRequest = Request → Bool El body = Status → String
34.681159
68
0.799833
143cb059bbc9916b7abdc0aa2f7f8cbdeaedd6a2
15,374
agda
Agda
dialectica-cats/DeDial2Sets.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
dialectica-cats/DeDial2Sets.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
dialectica-cats/DeDial2Sets.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
----------------------------------------------------------------------- -- This file defines Degenerate Dial₂(Sets) and shows that it is a -- -- CCC. -- ----------------------------------------------------------------------- module DeDial2Sets where open import prelude data UnitType : Set₁ where unit : UnitType mod : UnitType -- comp : UnitType → UnitType → UnitType ⟦_⟧ : UnitType → Set ⟦ unit ⟧ = ⊤ ⟦ mod ⟧ = (⊤ *) × (⊤ *) -- ⟦ comp t₁ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧ Obj⊤ : Set₁ Obj⊤ = Σ[ U ∈ Set ] (Σ[ X ∈ UnitType ](U → ⟦ X ⟧ → Set)) Hom⊤ : Obj⊤ → Obj⊤ → Set Hom⊤ (U , X , α) (V , Y , β) = Σ[ f ∈ (U → V) ] (Σ[ F ∈ (⟦ Y ⟧ → ⟦ X ⟧) ] (∀{u : U}{y : ⟦ Y ⟧} → α u (F y) → β (f u) y)) comp⊤ : {A B C : Obj⊤} → Hom⊤ A B → Hom⊤ B C → Hom⊤ A C comp⊤ {(U , X , α)} {(V , Y , β)} {(W , Z , γ)} (f , F , p₁) (g , G , p₂) = (g ∘ f , F ∘ G , (λ {u z} p-α → p₂ (p₁ p-α))) infixl 5 _○⊤_ _○⊤_ = comp⊤ -- The contravariant hom-functor: Hom⊤ₐ : {A' A B B' : Obj⊤} → Hom⊤ A' A → Hom⊤ B B' → Hom⊤ A B → Hom⊤ A' B' Hom⊤ₐ f h g = comp⊤ f (comp⊤ g h) -- The identity function: id⊤ : {A : Obj⊤} → Hom⊤ A A id⊤ {(U , X , α)} = (id-set , id-set , id-set) -- In this formalization we will only worry about proving that the -- data of morphisms are equivalent, and not worry about the morphism -- conditions. This will make proofs shorter and faster. -- -- If we have parallel morphisms (f,F) and (g,G) in which we know that -- f = g and F = G, then the condition for (f,F) will imply the -- condition of (g,G) and vice versa. Thus, we can safly ignore it. infix 4 _≡h⊤_ _≡h⊤_ : {A B : Obj⊤} → (f g : Hom⊤ A B) → Set _≡h⊤_ {(U , X , α)}{(V , Y , β)} (f , F , p₁) (g , G , p₂) = f ≡ g × F ≡ G ≡h⊤-refl : {A B : Obj⊤}{f : Hom⊤ A B} → f ≡h⊤ f ≡h⊤-refl {U , X , α}{V , Y , β}{f , F , _} = refl , refl ≡h⊤-trans : ∀{A B}{f g h : Hom⊤ A B} → f ≡h⊤ g → g ≡h⊤ h → f ≡h⊤ h ≡h⊤-trans {U , X , α}{V , Y , β}{f , F , _}{g , G , _}{h , H , _} (p₁ , p₂) (p₃ , p₄) rewrite p₁ | p₂ | p₃ | p₄ = refl , refl ≡h⊤-sym : ∀{A B}{f g : Hom⊤ A B} → f ≡h⊤ g → g ≡h⊤ f ≡h⊤-sym {U , X , α}{V , Y , β}{f , F , _}{g , G , _} (p₁ , p₂) rewrite p₁ | p₂ = refl , refl ≡h⊤-subst-○ : ∀{A B C : Obj⊤}{f₁ f₂ : Hom⊤ A B}{g₁ g₂ : Hom⊤ B C}{j : Hom⊤ A C} → f₁ ≡h⊤ f₂ → g₁ ≡h⊤ g₂ → f₂ ○⊤ g₂ ≡h⊤ j → f₁ ○⊤ g₁ ≡h⊤ j ≡h⊤-subst-○ {U , X , α} {V , Y , β} {W , Z , γ} {f₁ , F₁ , _} {f₂ , F₂ , _} {g₁ , G₁ , _} {g₂ , G₂ , _} {j , J , _} (p₅ , p₆) (p₇ , p₈) (p₉ , p₁₀) rewrite p₅ | p₆ | p₇ | p₈ | p₉ | p₁₀ = refl , refl ○⊤-assoc : ∀{A B C D}{f : Hom⊤ A B}{g : Hom⊤ B C}{h : Hom⊤ C D} → f ○⊤ (g ○⊤ h) ≡h⊤ (f ○⊤ g) ○⊤ h ○⊤-assoc {U , X , α}{V , Y , β}{W , Z , γ}{S , T , ι} {f , F , _}{g , G , _}{h , H , _} = refl , refl ○⊤-idl : ∀{A B}{f : Hom⊤ A B} → id⊤ ○⊤ f ≡h⊤ f ○⊤-idl {U , X , _}{V , Y , _}{f , F , _} = refl , refl ○⊤-idr : ∀{A B}{f : Hom⊤ A B} → f ○⊤ id⊤ ≡h⊤ f ○⊤-idr {U , X , _}{V , Y , _}{f , F , _} = refl , refl _⊗ᵣ_ : ∀{U V : Set}{X Y : UnitType} → (α : U → ⟦ X ⟧ → Set) → (β : V → ⟦ Y ⟧ → Set) → Σ U (λ x → V) → Σ ⟦ X ⟧ (λ x → ⟦ Y ⟧) → Set (α ⊗ᵣ β) (u , v) (l₁ , l₂) = (α u l₁) × (β v l₂) _⊗ₒ_ : (A B : Obj⊤) → Obj⊤ (U , unit , α) ⊗ₒ (V , unit , β) = (U × V) , unit , (λ p t → (α (fst p) triv) × (β (snd p) triv)) (U , unit , α) ⊗ₒ (V , mod , β) = (U × V) , (mod , (λ p t → (α (fst p) triv) × (β (snd p) t))) (U , mod , α) ⊗ₒ (V , unit , β) = (U × V) , (mod , (λ p t → (α (fst p) t) × (β (snd p) triv))) (U , mod , α) ⊗ₒ (V , mod , β) = (U × V) , (mod , (λ p t → (α (fst p) t) × (β (snd p) t))) -- F⊗ : ∀{S Z W T V X U Y : Set ℓ}{f : U → W}{F : Z → X}{g : V → S}{G : T → Y} → (S → Z) × (W → T) → (V → X) × (U → Y) -- F⊗ {f = f}{F}{g}{G} (h₁ , h₂) = (λ v → F(h₁ (g v))) , (λ u → G(h₂ (f u))) -- _⊗ₐ_ : {A B C D : Obj} → Hom A C → Hom B D → Hom (A ⊗ₒ B) (C ⊗ₒ D) -- _⊗ₐ_ {(U , X , α)}{(V , Y , β)}{(W , Z , γ)}{(S , T , δ)} (f , F , p₁) (g , G , p₂) = ⟨ f , g ⟩ , F⊗ {f = f}{F}{g}{G} , (λ {u y} → cond {u}{y}) -- where -- cond : {u : Σ U (λ x → V)} {y : Σ (S → Z) (λ x → W → T)} → -- ((α ⊗ᵣ β) u (F⊗ {f = f}{F}{g}{G} y)) ≤L ((γ ⊗ᵣ δ) (⟨ f , g ⟩ u) y) -- cond {u , v}{h , j} = l-mul-funct {p = mproset l-pf} (p₁ {u}{h (g v)}) (p₂ {v}{j (f u)}) -- □ᵣ : {U : Set}{X : UnitType} → (U → ⟦ X ⟧ → Set) → U → 𝕃 ⟦ X ⟧ → Set -- □ᵣ α u [] = ⊤ -- □ᵣ {U}{X} α u (x :: l) = (α u x) × (□ᵣ {U}{X} α u l) -- □ₒ : Obj⊤ → Obj⊤ -- □ₒ (U , X , α) = U , seq X , □ᵣ {U}{X} α -- □ₐ : {A B : Obj⊤} → Hom⊤ A B → Hom⊤ (□ₒ A) (□ₒ B) -- □ₐ {U , n₁ , α}{V , n₂ , β} (f , F , p) = f , map F , {!!} π₁ : {A B : Obj⊤} → Hom⊤ (A ⊗ₒ B) A π₁ {U , unit , α} {V , unit , β} = fst , id-set , (λ {u y} → aux {u}{y}) where aux : {u : Σ U (λ x → V)} {y : ⊤} → Σ (α (fst u) triv) (λ x → β (snd u) triv) → α (fst u) y aux {u , v}{triv} = fst π₁ {U , mod , α} {V , unit , β} = fst , id-set , (λ {u y} → aux {u}{y}) where aux : {u : Σ U (λ x → V)} {y : Σ (𝕃 ⊤) (λ x → 𝕃 ⊤)} → Σ (α (fst u) y) (λ x → β (snd u) triv) → α (fst u) y aux {u , v}{l₁ , l₂} = fst π₁ {U , unit , α} {V , mod , β} = fst , (λ x → [ x ] , [ x ]) , (λ {u y} → aux {u}{y}) where aux : {u : Σ U (λ x → V)} {y : ⊤} → Σ (α (fst u) triv) (λ x → β (snd u) (y :: [] , y :: [])) → α (fst u) y aux {u , v}{triv} = fst π₁ {U , mod , α} {V , mod , β} = fst , id-set , (λ {u y} → aux {u}{y}) where aux : {u : Σ U (λ x → V)} {y : Σ (𝕃 ⊤) (λ x → 𝕃 ⊤)} → Σ (α (fst u) y) (λ x → β (snd u) y) → α (fst u) y aux {u , v}{l} = fst π₂ : {A B : Obj⊤} → Hom⊤ (A ⊗ₒ B) B π₂ {U , unit , α} {V , unit , β} = snd , {!!} , {!!} π₂ {U , mod , α} {V , unit , β} = snd , {!!} , {!!} π₂ {U , unit , α} {V , mod , β} = snd , {!!} , {!!} π₂ {U , mod , α} {V , mod , β} = snd , {!!} , {!!} postulate rel-++ : ∀{W : Set}{w : W}{γ : W → 𝕃 (⊤ {lzero}) → Set}{l₁ l₂ : 𝕃 ⊤} → γ w (l₁ ++ l₂) → ((γ w l₁) × (γ w l₂)) cart-ar : {A B C : Obj⊤} → (f : Hom⊤ C A) → (g : Hom⊤ C B) → Hom⊤ C (A ⊗ₒ B) cart-ar {U , unit , α} {V , unit , β} {W , unit , γ} (f , F , p₁) (g , G , p₂) = trans-× f g , id-set , (λ {u y} → aux {u}{y}) where aux : {u : W} {y : ⊤} → γ u y → Σ (α (f u) triv) (λ x → β (g u) triv) aux {w}{triv} p with p₁ {w}{triv} | p₂ {w}{triv} ... | p₃ | p₄ with F triv | G triv ... | triv | triv = p₃ p , p₄ p cart-ar {U , unit , α} {V , unit , β} {W , mod , γ} (f , F , p₁) (g , G , p₂) = trans-× f g , (λ x → (fst (F x)) ++ (snd (F x)) , (fst (G x)) ++ (snd (G x))) , {!!} cart-ar {U , unit , α} {V , mod , β} {W , unit , γ} (f , F , p₁) (g , G , p₂) = trans-× f g , {!!} , {!!} cart-ar {U , unit , α} {V , mod , β} {W , mod , γ} (f , F , p₁) (g , G , p₂) = trans-× f g , {!!} , {!!} cart-ar {U , mod , α} {V , unit , β} {W , unit , γ} (f , F , p₁) (g , G , p₂) = trans-× f g , {!!} , {!!} cart-ar {U , mod , α} {V , unit , β} {W , mod , γ} (f , F , p₁) (g , G , p₂) = trans-× f g , {!!} , {!!} cart-ar {U , mod , α} {V , mod , β} {W , unit , γ} (f , F , p₁) (g , G , p₂) = trans-× f g , {!!} , {!!} cart-ar {U , mod , α} {V , mod , β} {W , mod , γ} (f , F , p₁) (g , G , p₂) = trans-× f g , {!!} , {!!} cart-diag₁ : ∀{A B C : Obj⊤} → {f : Hom⊤ C A} → {g : Hom⊤ C B} → (cart-ar f g) ○⊤ π₁ ≡h⊤ f cart-diag₁ {U , unit , α} {V , unit , β} {W , unit , γ} {f , F , p₁} {g , G , p₂} = refl , {!!} cart-diag₁ {U , unit , α} {V , unit , β} {W , mod , γ} {f , F , p₁} {g , G , p₂} = refl , {!!} cart-diag₁ {U , unit , α} {V , mod , β} {W , unit , γ} {f , F , p₁} {g , G , p₂} = {!!} cart-diag₁ {U , unit , α} {V , mod , β} {W , mod , γ} {f , F , p₁} {g , G , p₂} = {!!} cart-diag₁ {U , mod , α} {V , unit , β} {W , unit , γ} {f , F , p₁} {g , G , p₂} = {!!} cart-diag₁ {U , mod , α} {V , unit , β} {W , mod , γ} {f , F , p₁} {g , G , p₂} = {!!} cart-diag₁ {U , mod , α} {V , mod , β} {W , unit , γ} {f , F , p₁} {g , G , p₂} = {!!} cart-diag₁ {U , mod , α} {V , mod , β} {W , mod , γ} {f , F , p₁} {g , G , p₂} = {!!} -- cart-diag₂ : ∀{A B C : Obj⊤} -- → {f : Hom (toObj C) (toObj A)} -- → {g : Hom (toObj C) (toObj B)} -- → (cart-ar f g) ○ π₂ ≡h g -- cart-diag₂ {U , α}{V , β}{W , γ}{f , F , p₁}{g , G , p₂} = refl , ext-set ctr -- where -- ctr : {a : ⊤} → triv ≡ G a -- ctr {triv} with G triv -- ... | triv = refl -- □ₒ-cond : ∀{U X : Set} -- → (U → X → Set) -- → U -- → (X *) -- → Set -- □ₒ-cond {U} α u l = all-pred (α u) l -- fromObj : (A : Obj) → Σ[ B ∈ Obj⊤ ]( A ≡ toObj(B)) → Obj⊤ -- fromObj _ ((a , b) , b₁) = a , b -- □ₒ : Obj → Obj -- □ₒ (U , X , α) = (U , X * , □ₒ-cond α) -- □ₐ : {A B : Obj} → Hom A B → Hom (□ₒ A) (□ₒ B) -- □ₐ {U , X , α}{V , Y , β} (f , F , p) = f , map F , cond -- where -- cond : {u : U} {y : 𝕃 Y} → all-pred (α u) (map F y) → all-pred (β (f u)) y -- cond {y = []} x = triv -- cond {y = x :: y} (a , b) = p a , cond b -- □-ε : ∀{A : Obj} → Hom (□ₒ A) A -- □-ε {U , X , α} = id-set , (λ x → [ x ] ) , aux -- where -- aux : {u : U} {y : X} → Σ (α u y) (λ x → ⊤) → α u y -- aux (a , b) = a -- □-δ : ∀{A : Obj} → Hom (□ₒ A) (□ₒ (□ₒ A)) -- □-δ {U , X , α} = id-set , (foldr _++_ []) , cond -- where -- cond : {u : U} {y : 𝕃 (𝕃 X)} → all-pred (α u) (foldr _++_ [] y) → all-pred (λ l → all-pred (α u) l) y -- cond {y = []} p = triv -- cond {u}{y = y :: y₁} p rewrite -- (all-pred-append {X}{α u}{y}{foldr _++_ [] y₁} ∧-unit ∧-assoc) -- with p -- ... | p₁ , p₂ = p₁ , cond p₂ -- comonand-diag₁ : ∀{A : Obj} -- → (□-δ {A}) ○ (□ₐ (□-δ {A})) ≡h (□-δ {A}) ○ (□-δ { □ₒ (A)}) -- comonand-diag₁ {U , X , α} = refl , ext-set (λ {a} → ctr {a}) -- where -- ctr : {a : 𝕃 (𝕃 (𝕃 X))} → foldr _++_ [] (map (foldr _++_ []) a) ≡ foldr _++_ [] (foldr _++_ [] a) -- ctr {[]} = refl -- ctr {a :: a₁} rewrite sym (foldr-append {l₁ = a}{foldr _++_ [] a₁}) | ctr {a₁} = refl -- comonand-diag₂ : ∀{A : Obj} -- → (□-δ {A}) ○ (□-ε { □ₒ A}) ≡h (□-δ {A}) ○ (□ₐ (□-ε {A})) -- comonand-diag₂ {U , X , α} = refl , ext-set (λ {a} → cond {a}) -- where -- cond : {a : 𝕃 X} → a ++ [] ≡ foldr _++_ [] (map (λ x → x :: []) a) -- cond {a} rewrite ++[] a = foldr-map -- □-ctr : {U V : Set} → 𝕃 (Σ (V → ⊤) (λ x → U → ⊤)) → Σ (V → 𝕃 ⊤) (λ x → U → 𝕃 ⊤) -- □-ctr [] = (λ x → [ triv ]) , (λ x → [ triv ]) -- □-ctr ((a , b) :: l) = (λ v → a v :: (fst (□-ctr l)) v) , (λ u → b u :: (snd (□-ctr l)) u) -- □-m : {A B : Obj⊤} → Hom ((□ₒ (toObj A)) ⊗ₒ (□ₒ (toObj B))) (□ₒ ((toObj A) ⊗ₒ (toObj B))) -- □-m {U , α}{V , β} = id-set , □-ctr , cond -- where -- cond : {u : Σ U (λ x → V)} {y : 𝕃 (Σ (V → ⊤) (λ x → U → ⊤))} → -- ((λ u₁ l → all-pred (α u₁) l) ⊗ᵣ (λ u₁ l → all-pred (β u₁) l)) u -- (□-ctr y) → all-pred ((α ⊗ᵣ β) u) y -- cond {a , b} {[]} x = triv -- cond {a , b} {(a₁ , b₁) :: y} ((a₂ , b₂) , a₃ , b₃) with cond {a , b}{y} -- ... | IH with □-ctr y -- ... | c , d = (a₂ , a₃) , IH (b₂ , b₃) -- □-m-nat : ∀{A A' B B' : Obj⊤} -- → (f : Hom (toObj A) (toObj A')) -- → (g : Hom (toObj B) (toObj B')) -- → ((□ₐ f) ⊗ₐ (□ₐ g)) ○ □-m ≡h □-m ○ (□ₐ (f ⊗ₐ g)) -- □-m-nat {U , α}{U' , α'}{V , β}{V' , β'} (f , F , p₁) (g , G , p₂) = refl , ext-set (λ {a} → aux {a}) -- where -- aux : {a : 𝕃 (Σ (V' → ⊤) (λ x → U' → ⊤))} → F⊗ {V'}{𝕃 ⊤}{U'}{𝕃 ⊤}{V}{𝕃 ⊤}{U}{𝕃 ⊤}{f}{map F}{g}{map G} (□-ctr a) ≡ □-ctr (map (F⊗ {V'} {⊤} {U'} {⊤} {V} {⊤} {U} {⊤} {f} {F} {g} {G}) a) -- aux {[]} with G triv | F triv -- ... | triv | triv = refl -- aux {(a , b) :: a₁} = eq-× (ext-set aux₁) (ext-set aux₄) -- where -- aux₂ : ∀{v}{l : 𝕃 (Σ (V' → ⊤) (λ x → U' → ⊤))} → map F (fst (□-ctr l) (g v)) ≡ fst (□-ctr (map (F⊗ {V'} {⊤} {U'} {⊤} {V} {⊤} {U} {⊤} {f} {F} {g} {G}) l)) v -- aux₂ {_}{[]} with F triv -- ... | triv = refl -- aux₂ {v}{(a₂ , b₁) :: l} rewrite aux₂ {v}{l} = refl -- aux₁ : {a₂ : V} → F (a (g a₂)) :: map F (fst (□-ctr a₁) (g a₂)) ≡ F (a (g a₂)) :: fst (□-ctr (map (F⊗ {V'} {⊤} {U'} {⊤} {V} {⊤} {U} {⊤} {f} {F} {g} {G}) a₁)) a₂ -- aux₁ {v} with F (a (g v)) -- ... | triv rewrite aux₂ {v}{a₁} = refl -- aux₃ : ∀{u l} → map G (snd (□-ctr l) (f u)) ≡ snd (□-ctr (map (F⊗ {V'} {⊤} {U'} {⊤} {V} {⊤} {U} {⊤} {f} {F} {g} {G}) l)) u -- aux₃ {u}{[]} with G triv -- ... | triv = refl -- aux₃ {u}{(a₂ , b₁) :: l} rewrite aux₃ {u}{l} = refl -- aux₄ : {a₂ : U} → G (b (f a₂)) :: map G (snd (□-ctr a₁) (f a₂)) ≡ G (b (f a₂)) :: snd (□-ctr (map (F⊗ {V'} {⊤} {U'} {⊤} {V} {⊤} {U} {⊤} {f} {F} {g} {G}) a₁)) a₂ -- aux₄ {u} rewrite aux₃ {u}{a₁} = refl -- □-m-I : Hom I (□ₒ I) -- □-m-I = id-set , (λ _ → triv) , cond -- where -- cond : {u : ⊤} {y : 𝕃 ⊤} → ι u triv → all-pred (ι u) y -- cond {triv} {[]} x = triv -- cond {triv} {triv :: y} triv = triv , cond triv -- π-□-ctr : {U V : Set} → 𝕃 ⊤ → Σ (V → 𝕃 ⊤) (λ _ → U → 𝕃 ⊤) -- π-□-ctr [] = (λ x → [ triv ]) , (λ x → [ triv ]) -- π-□-ctr {U}{V} (triv :: l) = (λ v → triv :: fst (π-□-ctr {U}{V} l) v) , ((λ v → triv :: snd (π-□-ctr {U}{V} l) v)) -- π₁-□ : ∀{U α V β} → Hom ((□ₒ (U , ⊤ , α)) ⊗ₒ (□ₒ (V , ⊤ , β))) (□ₒ (U , ⊤ , α)) -- π₁-□ {U}{α}{V}{β} = fst , π-□-ctr , cond -- where -- cond : {u : Σ U (λ x → V)} {y : 𝕃 ⊤} → -- ((λ u₁ l → all-pred (α u₁) l) ⊗ᵣ (λ u₁ l → all-pred (β u₁) l)) u -- (π-□-ctr y) → -- all-pred (α (fst u)) y -- cond {a , b} {[]} x = triv -- cond {a , b} {triv :: y} ((a₁ , b₁) , a₂ , b₂) with cond {a , b} {y} -- ... | IH with π-□-ctr {U}{V} y -- ... | c , d = a₁ , IH (b₁ , b₂) -- □-prod₁ : ∀{U α V β} → _≡h_ {((□ₒ (U , ⊤ , α)) ⊗ₒ (□ₒ (V , ⊤ , β)))} -- {(□ₒ (U , ⊤ , α))} -- (_○_ {(□ₒ (U , ⊤ , α)) ⊗ₒ (□ₒ (V , ⊤ , β))}{□ₒ ((U , ⊤ , α) ⊗ₒ (V , ⊤ , β))}{□ₒ (U , ⊤ , α)} (□-m {U , α}{V , β}) (□ₐ {(U , ⊤ , α) ⊗ₒ (V , ⊤ , β)}{U , ⊤ , α} (π₁ {U , α}{V , β}))) -- (π₁-□ {U}{α}{V}{β}) -- □-prod₁ {U}{α}{V}{β} = refl , ext-set (λ {a} → aux {a}) -- where -- aux : {a : 𝕃 ⊤} → □-ctr {U}{V} (map π-ctr a) ≡ π-□-ctr a -- aux {[]} = refl -- aux {triv :: a} rewrite aux {a} = refl -- π₂-□ : ∀{U α V β} → Hom ((□ₒ (U , ⊤ , α)) ⊗ₒ (□ₒ (V , ⊤ , β))) (□ₒ (V , ⊤ , β)) -- π₂-□ {U}{α}{V}{β} = snd , π-□-ctr , cond -- where -- cond : {u : Σ U (λ x → V)} {y : 𝕃 ⊤} → -- ((λ u₁ l → all-pred (α u₁) l) ⊗ᵣ (λ u₁ l → all-pred (β u₁) l)) u -- (π-□-ctr y) → -- all-pred (β (snd u)) y -- cond {a , b} {[]} x = triv -- cond {a , b} {triv :: y} ((a₁ , b₁) , a₂ , b₂) with cond {a , b}{y} -- ... | IH with π-□-ctr {U}{V} y -- ... | c , d = a₂ , (IH (b₁ , b₂)) -- □-prod₂ : ∀{U α V β} → _≡h_ {((□ₒ (U , ⊤ , α)) ⊗ₒ (□ₒ (V , ⊤ , β)))} -- {(□ₒ (V , ⊤ , β))} -- (_○_ {(□ₒ (U , ⊤ , α)) ⊗ₒ (□ₒ (V , ⊤ , β))}{□ₒ ((U , ⊤ , α) ⊗ₒ (V , ⊤ , β))}{□ₒ (V , ⊤ , β)} (□-m {U , α}{V , β}) (□ₐ {(U , ⊤ , α) ⊗ₒ (V , ⊤ , β)}{V , ⊤ , β} (π₂ {U , α}{V , β}))) -- (π₂-□ {U}{α}{V}{β}) -- □-prod₂ {U}{α}{V}{β} = refl , (ext-set (λ {a} → aux {a})) -- where -- aux : {a : 𝕃 ⊤} → □-ctr {U}{V} (map π-ctr a) ≡ π-□-ctr a -- aux {[]} = refl -- aux {triv :: a} rewrite aux {a} = refl -- cart-ar-□ : {A B C : Obj⊤} -- → (f : Hom (□ₒ (toObj C)) (□ₒ (toObj A))) -- → (g : Hom (□ₒ (toObj C)) (□ₒ (toObj B))) -- → Hom (□ₒ (toObj C)) ((□ₒ (toObj A)) ⊗ₒ (□ₒ (toObj B))) -- cart-ar-□ {U , α}{V , β}{W , γ} (f , F , p₁) (g , G , p₂) = trans-× f g , {!!} , {!!} -- where -- -}
43.064426
210
0.361194
3665ef34e52261fc1baf71b6d975baa479ca7441
800
agda
Agda
Common/Semantics.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
Common/Semantics.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
Common/Semantics.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
module Common.Semantics where open import Common.Context public -- Special products for glueing. infix 5 _⅋_ record Glue (Syn : Set) (Sem : Set) : Set where constructor _⅋_ field syn : Syn sem : Sem open Glue public -- Contexts as concrete worlds. module ConcreteWorlds (U : Set) where record World : Set where constructor wrap field Γ : Cx U unwrap : World → Cx U unwrap (wrap Γ) = Γ data _≤_ : World → World → Set where wrap : ∀ {Γ Γ′} → Γ ⊆ Γ′ → wrap Γ ≤ wrap Γ′ unwrap≤ : ∀ {Γ Γ′} → wrap Γ ≤ wrap Γ′ → Γ ⊆ Γ′ unwrap≤ (wrap η) = η refl≤ : ∀ {w} → w ≤ w refl≤ = wrap refl⊆ trans≤ : ∀ {w w′ w″} → w ≤ w′ → w′ ≤ w″ → w ≤ w″ trans≤ (wrap η) (wrap η′) = wrap (trans⊆ η η′) weak≤ : ∀ {A w} → w ≤ wrap (unwrap w , A) weak≤ = wrap weak⊆
18.604651
50
0.56
36f320262a1948d3ed37463ec44ce8ae371f2f3a
2,252
agda
Agda
Cubical/Homotopy/Group/Pi4S3/S3PushoutIso2.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Homotopy/Group/Pi4S3/S3PushoutIso2.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Homotopy/Group/Pi4S3/S3PushoutIso2.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Homotopy.Group.Pi4S3.S3PushoutIso2 where open import Cubical.Homotopy.Group.Base open import Cubical.Homotopy.Group.Pi4S3.S3PushoutIso open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence open import Cubical.Data.Nat open import Cubical.Algebra.Group open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Group.GroupPath open import Cubical.HITs.Sn open import Cubical.HITs.Susp renaming (toSusp to σ) open import Cubical.HITs.Pushout open import Cubical.HITs.Truncation renaming (rec to trRec ; elim to trElim ; elim2 to trElim2 ; map to trMap) open import Cubical.HITs.S2 ≡→Pushout⋁↪fold⋁≡ : ∀ {ℓ} {A B : Pointed ℓ} → (A ≡ B) → Pushout⋁↪fold⋁∙ A ≡ Pushout⋁↪fold⋁∙ B ≡→Pushout⋁↪fold⋁≡ = cong Pushout⋁↪fold⋁∙ private ∙≃→π≅ : ∀ {ℓ} {A B : Pointed ℓ} (n : ℕ) → (e : typ A ≃ typ B) → fst e (pt A) ≡ pt B → GroupEquiv (πGr n A) (πGr n B) ∙≃→π≅ {A = A} {B = B} n e = EquivJ (λ A e → (a : A) → fst e a ≡ pt B → GroupEquiv (πGr n (A , a)) (πGr n B)) (λ b p → J (λ b p → GroupEquiv (πGr n (typ B , b)) (πGr n B)) idGroupEquiv (sym p)) e (pt A) {- π₄(S³) ≅ π₃((S² × S²) ⊔ᴬ S²) where A = S² ∨ S² -} π₄S³≅π₃PushS² : GroupIso (πGr 3 (S₊∙ 3)) (πGr 2 (Pushout⋁↪fold⋁∙ (S₊∙ 2))) π₄S³≅π₃PushS² = compGroupIso (GroupEquiv→GroupIso (∙≃→π≅ 3 (compEquiv (isoToEquiv (invIso IsoS³S3)) S³≃SuspS²) refl)) (compGroupIso (invGroupIso (GrIso-πΩ-π 2)) (compGroupIso (πTruncGroupIso 2) (compGroupIso (GroupEquiv→GroupIso (∙≃→π≅ {B = _ , ∣ inl (base , base) ∣ₕ} 2 (isoToEquiv IsoΩ∥SuspS²∥₅∥Pushout⋁↪fold⋁S²∥₅) encode∙)) (compGroupIso (invGroupIso (πTruncGroupIso 2)) (GroupEquiv→GroupIso (invEq (GroupPath _ _) (cong (πGr 2) (cong Pushout⋁↪fold⋁∙ (ua∙ S²≃SuspS¹ refl))))))))) where encode∙ : encode ∣ north ∣ refl ≡ ∣ inl (base , base) ∣ encode∙ = transportRefl _
33.117647
72
0.632327
3fc68f6969f7c78fde520b171a850af9780998b6
14,091
agda
Agda
complexity/complexity-final/Pilot-WithFlatrec.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
2
2016-04-26T20:22:22.000Z
2019-08-08T12:27:18.000Z
complexity/complexity-final/Pilot-WithFlatrec.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
1
2020-03-23T08:39:04.000Z
2020-05-12T00:32:45.000Z
complexity/complexity-final/Pilot-WithFlatrec.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
null
null
null
open import Preliminaries module Pilot-WithFlatrec where data CTp : Set where unit : CTp nat : CTp -- discrete natural numbers ♭nat, where we interpret ≤ as = _->c_ : CTp → CTp → CTp _×c_ : CTp → CTp → CTp list : CTp → CTp bool : CTp C : CTp rnat : CTp -- natural numbers with ≤ actually interpreted as ≤ data CTpM : CTp → Set where runit : CTpM unit rn : CTpM rnat _×cm_ : ∀ {τ1 τ2} → CTpM τ1 → CTpM τ2 → CTpM (τ1 ×c τ2) _->cm_ : ∀ {τ1 τ2} → CTpM τ2 → CTpM (τ1 ->c τ2) -- represent a context as a list of types Ctx = List CTp -- de Bruijn indices (for free variables) data _∈_ : CTp → Ctx → Set where i0 : ∀ {Γ τ} → τ ∈ (τ :: Γ) iS : ∀ {Γ τ τ1} → τ ∈ Γ → τ ∈ (τ1 :: Γ) rctx : Ctx → Ctx → Set rctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → τ ∈ Γ r-extend : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ') data _|-_ : Ctx → CTp → Set sctx : Ctx → Ctx → Set sctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → Γ |- τ _∙rr_ : ∀ {A B C} → rctx A B → rctx B C → rctx A C _rs_ : ∀ {A B C} → rctx A B → sctx B C → sctx A C ren : ∀ {Γ Γ' τ} → Γ' |- τ → rctx Γ Γ' → Γ |- τ subst : ∀ {Γ Γ' τ} → Γ' |- τ → sctx Γ Γ' → Γ |- τ _ss_ : ∀ {A B C} → sctx A B → sctx B C → sctx A C _sr_ : ∀ {A B C} → sctx A B → rctx B C → sctx A C data _≤s_ : ∀ {Γ T} → Γ |- T → Γ |- T → Set rename-var : ∀ {Γ Γ' τ} → rctx Γ Γ' → τ ∈ Γ' → τ ∈ Γ idr : ∀ {Γ} → rctx Γ Γ p∙ : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) Γ' p : ∀ {Γ τ} → rctx (τ :: Γ) Γ rename-var-ident : ∀ {Γ τ} → (x : τ ∈ Γ) → rename-var idr x == x rename-var-∙ : ∀ {A B C τ} → (r1 : rctx A B) (r2 : rctx B C) (x : τ ∈ C) → rename-var r1 (rename-var r2 x) == rename-var (r1 ∙rr r2) x ∙rr-assoc : ∀ {A B C D} → (r1 : rctx A B) (r2 : rctx B C) (r3 : rctx C D) → _==_ {_} {rctx A D} (r1 ∙rr (r2 ∙rr r3)) ((r1 ∙rr r2) ∙rr r3) extend-ren-comp-lemma : ∀ {Γ Γ' Γ'' τ τ'} → (x : τ ∈ τ' :: Γ'') (ρ1 : rctx Γ Γ') (ρ2 : rctx Γ' Γ'') → Id {_} {_} ((r-extend ρ1 ∙rr r-extend ρ2) x) (r-extend (ρ1 ∙rr ρ2) x) extend-ren-comp : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'') → Id {_} {rctx (τ :: Γ) (τ :: Γ'')} (r-extend ρ1 ∙rr r-extend ρ2) (r-extend (ρ1 ∙rr ρ2)) wkn : ∀ {Γ τ1 τ2} → Γ |- τ2 → (τ1 :: Γ) |- τ2 s-extend : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) (τ :: Γ') ids : ∀ {Γ} → sctx Γ Γ q∙ : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) Γ' lem3' : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ |- τ → sctx Γ (τ :: Γ') q : ∀ {Γ τ} → Γ |- τ → sctx Γ (τ :: Γ) svar : ∀ {Γ1 Γ2 τ} → sctx Γ1 Γ2 → τ ∈ Γ2 → Γ1 |- τ lem4' : ∀ {Γ Γ' τ1 τ2} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ')) lem4 : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ)) lem5' : ∀ {Γ Γ' τ1 τ2 τ3} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → Γ |- τ3 → sctx Γ (τ1 :: (τ2 :: (τ3 :: Γ'))) lem5 : ∀ {Γ τ1 τ2 τ3} → Γ |- τ1 → Γ |- τ2 → Γ |- τ3 → sctx Γ (τ1 :: (τ2 :: (τ3 :: Γ))) data _|-_ where unit : ∀ {Γ} → Γ |- unit 0C : ∀ {Γ} → Γ |- C 1C : ∀ {Γ}→ Γ |- C plusC : ∀ {Γ} → Γ |- C → Γ |- C → Γ |- C var : ∀ {Γ τ} → τ ∈ Γ → Γ |- τ z : ∀ {Γ} → Γ |- nat s : ∀ {Γ} → (e : Γ |- nat) → Γ |- nat rec : ∀ {Γ τ} → Γ |- nat → Γ |- τ → (nat :: (τ :: Γ)) |- τ → Γ |- τ lam : ∀ {Γ τ ρ} → (ρ :: Γ) |- τ → Γ |- (ρ ->c τ) app : ∀ {Γ τ1 τ2} → Γ |- (τ2 ->c τ1) → Γ |- τ2 → Γ |- τ1 rz : ∀ {Γ} → Γ |- rnat rsuc : ∀ {Γ} → Γ |- rnat → Γ |- rnat rrec : ∀ {Γ τ} → Γ |- rnat → (Z' : Γ |- τ) → (S' : Γ |- (rnat ->c (τ ->c τ))) → (P : Z' ≤s (app (app S' rz) Z')) → Γ |- τ prod : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → Γ |- (τ1 ×c τ2) l-proj : ∀ {Γ τ1 τ2} → Γ |- (τ1 ×c τ2) → Γ |- τ1 r-proj : ∀ {Γ τ1 τ2} → Γ |- (τ1 ×c τ2) → Γ |- τ2 nil : ∀ {Γ τ} → Γ |- list τ _::c_ : ∀ {Γ τ} → Γ |- τ → Γ |- list τ → Γ |- list τ listrec : ∀ {Γ τ τ'} → Γ |- list τ → Γ |- τ' → (τ :: (list τ :: (τ' :: Γ))) |- τ' → Γ |- τ' true : ∀ {Γ} → Γ |- bool false : ∀ {Γ} → Γ |- bool max : ∀ {Γ τ} → CTpM τ → Γ |- τ → Γ |- τ → Γ |- τ {-[ Θ ]s : Monotone [ Γ ] [ Γ' ] [ ρ ]r : same interpE ren e ρ k == interpE e (interpR ρ) k interp commutes with renaming and substitution equations that define ren and subst are true in the semantics-} --also add axioms for max-l/r etc. data _≤s_ where refl-s : ∀ {Γ T} → {e : Γ |- T} → e ≤s e trans-s : ∀ {Γ T} → {e e' e'' : Γ |- T} → e ≤s e' → e' ≤s e'' → e ≤s e'' cong-refl : ∀ {Γ τ} {e e' : Γ |- τ} → e == e' → e ≤s e' +-unit-l : ∀ {Γ} {e : Γ |- C} → (plusC 0C e) ≤s e +-unit-l' : ∀ {Γ} {e : Γ |- C} → e ≤s (plusC 0C e) +-unit-r : ∀ {Γ} {e : Γ |- C} → (plusC e 0C) ≤s e +-unit-r' : ∀ {Γ} {e : Γ |- C} → e ≤s (plusC e 0C) +-assoc : ∀ {Γ} {e1 e2 e3 : Γ |- C} → (plusC e1 (plusC e2 e3)) ≤s (plusC (plusC e1 e2) e3) +-assoc' : ∀ {Γ} {e1 e2 e3 : Γ |- C} → (plusC (plusC e1 e2) e3) ≤s (plusC e1 (plusC e2 e3)) refl-+ : ∀ {Γ} {e0 e1 : Γ |- C} → (plusC e0 e1) ≤s (plusC e1 e0) cong-+ : ∀ {Γ} {e0 e1 e0' e1' : Γ |- C} → e0 ≤s e0' → e1 ≤s e1' → (plusC e0 e1) ≤s (plusC e0' e1') cong-lproj : ∀ {Γ τ τ'} {e e' : Γ |- (τ ×c τ')} → e ≤s e' → (l-proj e) ≤s (l-proj e') cong-rproj : ∀ {Γ τ τ'} {e e' : Γ |- (τ ×c τ')} → e ≤s e' → (r-proj e) ≤s (r-proj e') cong-app : ∀ {Γ τ τ'} {e e' : Γ |- (τ ->c τ')} {e1 : Γ |- τ} → e ≤s e' → (app e e1) ≤s (app e' e1) ren-cong : ∀ {Γ Γ' τ} {e1 e2 : Γ' |- τ} {ρ : rctx Γ Γ'} → e1 ≤s e2 → (ren e1 ρ) ≤s (ren e2 ρ) subst-cong : ∀ {Γ Γ' τ} {e1 e2 : Γ' |- τ} {Θ : sctx Γ Γ'} → e1 ≤s e2 → (subst e1 Θ) ≤s (subst e2 Θ) subst-cong2 : ∀ {Γ Γ' τ} {Θ Θ' : sctx Γ Γ'} {e : Γ' |- τ} → (∀ τ → (x : τ ∈ Γ') → Θ x ≤s Θ' x) → subst e Θ ≤s subst e Θ' cong-rec : ∀ {Γ τ} {e e' : Γ |- nat} {e0 : Γ |- τ} {e1 : (nat :: (τ :: Γ)) |- τ} → e ≤s e' → rec e e0 e1 ≤s rec e' e0 e1 cong-listrec : ∀ {Γ τ τ'} {e e' : Γ |- list τ} {e0 : Γ |- τ'} {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'} → e ≤s e' → listrec e e0 e1 ≤s listrec e' e0 e1 lam-s : ∀ {Γ T T'} → {e : (T :: Γ) |- T'} → {e2 : Γ |- T} → subst e (q e2) ≤s app (lam e) e2 l-proj-s : ∀ {Γ T1 T2} → {e1 : Γ |- T1} {e2 : Γ |- T2} → e1 ≤s (l-proj (prod e1 e2)) r-proj-s : ∀ {Γ T1 T2} → {e1 : Γ |- T1} → {e2 : Γ |- T2} → e2 ≤s (r-proj (prod e1 e2)) rec-steps-z : ∀ {Γ T} → {e0 : Γ |- T} → {e1 : (nat :: (T :: Γ)) |- T} → e0 ≤s (rec z e0 e1) rec-steps-s : ∀ {Γ T} → {e : Γ |- nat} → {e0 : Γ |- T} → {e1 : (nat :: (T :: Γ)) |- T} → subst e1 (lem4 e (rec e e0 e1)) ≤s (rec (s e) e0 e1) listrec-steps-nil : ∀ {Γ τ τ'} → {e0 : Γ |- τ'} → {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'} → e0 ≤s (listrec nil e0 e1) listrec-steps-cons : ∀ {Γ τ τ'} → {h : Γ |- τ} {t : Γ |- list τ} → {e0 : Γ |- τ'} → {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'} → subst e1 (lem5 h t (listrec t e0 e1)) ≤s (listrec (h ::c t) e0 e1) ren-comp-l : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'') → (e : Γ'' |- τ) → (ren (ren e ρ2) ρ1) ≤s (ren e (ρ1 ∙rr ρ2)) ren-comp-r : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'') → (e : Γ'' |- τ) → (ren e (ρ1 ∙rr ρ2)) ≤s (ren (ren e ρ2) ρ1) subst-id-l : ∀ {Γ τ} → (e : Γ |- τ) → e ≤s subst e ids subst-id-r : ∀ {Γ τ} → (e : Γ |- τ) → subst e ids ≤s e subst-rs-l : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B) (e : B |- τ) → ren (subst e Θ) ρ ≤s subst e (ρ rs Θ) subst-rs-r : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B) (e : B |- τ) → subst e (ρ rs Θ) ≤s ren (subst e Θ) ρ subst-sr-l : ∀ {Γ Γ' Γ'' τ} → (Θ : sctx Γ Γ') → (ρ : rctx Γ' Γ'') → (e : Γ'' |- τ) → (subst (ren e ρ) Θ) ≤s subst e (Θ sr ρ) subst-sr-r : ∀ {Γ Γ' Γ'' τ} → (Θ : sctx Γ Γ') → (ρ : rctx Γ' Γ'') → (e : Γ'' |- τ) → subst e (Θ sr ρ) ≤s (subst (ren e ρ) Θ) subst-ss-l : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C) (e : C |- τ) → subst e (Θ1 ss Θ2) ≤s subst (subst e Θ2) Θ1 subst-ss-r : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C) (e : C |- τ) → subst (subst e Θ2) Θ1 ≤s subst e (Θ1 ss Θ2) subst-compose-l : ∀ {Γ Γ' τ τ1} (Θ : sctx Γ Γ') (v : Γ |- τ) (e : (τ :: Γ' |- τ1) ) → subst (subst e (s-extend Θ)) (q v) ≤s subst e (lem3' Θ v) subst-compose-r : ∀ {Γ Γ' τ τ1} (Θ : sctx Γ Γ') (v : Γ |- τ) (e : (τ :: Γ' |- τ1) ) → subst e (lem3' Θ v) ≤s subst (subst e (s-extend Θ)) (q v) subst-compose2-l : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2) → subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2) ≤s subst e1 (lem4' Θ v1 v2) subst-compose2-r : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2) → subst e1 (lem4' Θ v1 v2) ≤s subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2) subst-compose3-l : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2) → subst (subst e1 (lem4 v1 v2)) Θ ≤s subst e1 (lem4' Θ (subst v1 Θ) (subst v2 Θ)) subst-compose3-r : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2) → subst e1 (lem4' Θ (subst v1 Θ) (subst v2 Θ)) ≤s subst (subst e1 (lem4 v1 v2)) Θ subst-compose4-l : ∀ {Γ Γ' τ} (Θ : sctx Γ Γ') (v' : Γ |- nat) (r : Γ |- τ) (e2 : (nat :: (τ :: Γ')) |- τ) → subst (subst e2 (s-extend (s-extend Θ))) (lem4 v' r) ≤s subst e2 (lem4' Θ v' r) subst-compose4-r : ∀ {Γ Γ' τ} (Θ : sctx Γ Γ') (v' : Γ |- nat) (r : Γ |- τ) (e2 : (nat :: (τ :: Γ')) |- τ) → subst e2 (lem4' Θ v' r) ≤s subst (subst e2 (s-extend (s-extend Θ))) (lem4 v' r) subst-compose5-l : ∀ {Γ Γ' τ τ1 τ2 τ3} (Θ : sctx Γ Γ') (e : (τ1 :: (τ2 :: (τ3 :: Γ'))) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) → subst (subst e (s-extend (s-extend (s-extend (Θ))))) (lem5 v1 v2 v3) ≤s subst e (lem5' Θ v1 v2 v3) subst-compose5-r : ∀ {Γ Γ' τ τ1 τ2 τ3} (Θ : sctx Γ Γ') (e : (τ1 :: (τ2 :: (τ3 :: Γ'))) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) → subst e (lem5' Θ v1 v2 v3) ≤s subst (subst e (s-extend (s-extend (s-extend (Θ))))) (lem5 v1 v2 v3) -- r-extend : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ') r-extend ρ i0 = i0 r-extend ρ (iS x) = iS (ρ x) -- _∙rr_ : ∀ {A B C} → rctx A B → rctx B C → rctx A C ρ1 ∙rr ρ2 = ρ1 o ρ2 rename-var ρ a = ρ a idr x = x p∙ ρ = λ x → iS (ρ x) p = p∙ idr --free stuff rename-var-ident _ = Refl rename-var-∙ _ _ _ = Refl ∙rr-assoc r1 r2 r3 = Refl ren unit ρ = unit ren 0C ρ = 0C ren 1C ρ = 1C ren (plusC e e₁) ρ = plusC (ren e ρ) (ren e₁ ρ) ren (var x) ρ = var (ρ x) ren z ρ = z ren (s e) ρ = s (ren e ρ) ren (rec e e₁ e₂) ρ = rec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend ρ))) ren (lam e) ρ = lam (ren e (r-extend ρ)) ren (app e e₁) ρ = app (ren e ρ) (ren e₁ ρ) ren (prod e1 e2) ρ = prod (ren e1 ρ) (ren e2 ρ) ren (l-proj e) ρ = l-proj (ren e ρ) ren (r-proj e) ρ = r-proj (ren e ρ) ren nil ρ = nil ren (x ::c xs) ρ = ren x ρ ::c ren xs ρ ren true ρ = true ren false ρ = false ren (listrec e e₁ e₂) ρ = listrec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend (r-extend ρ)))) ren rz ρ = rz ren (rsuc e) ρ = rsuc (ren e ρ) ren (rrec e e₁ e₂ p) ρ = rrec (ren e ρ) (ren e₁ ρ) (ren e₂ ρ) (ren-cong p) ren (max τ e1 e2) ρ = max τ (ren e1 ρ) (ren e2 ρ) extend-ren-comp-lemma i0 ρ1 ρ2 = Refl extend-ren-comp-lemma (iS x) ρ1 ρ2 = Refl extend-ren-comp ρ1 ρ2 = λ=i (λ τ → λ= (λ x → extend-ren-comp-lemma x ρ1 ρ2)) -- weakening a context wkn e = ren e iS -- parallel extension s-extend Θ i0 = var i0 s-extend Θ (iS x) = wkn (Θ x) -- identity substitution ids x = var x -- weakening with substitution q∙ Θ = λ x → wkn (Θ x) lem3' Θ e i0 = e lem3' Θ e (iS i) = Θ i --lem3 q e = lem3' ids e -- subst-var svar Θ i = q (Θ i) i0 lem4' Θ a b = lem3' (lem3' Θ b) a lem4 e1 e2 = lem4' ids e1 e2 lem5' Θ a b c = lem3' (lem3' (lem3' Θ c) b) a lem5 e1 e2 e3 = lem5' ids e1 e2 e3 subst unit Θ = unit subst 0C Θ = 0C subst 1C Θ = 1C subst (plusC e e₁) Θ = plusC (subst e Θ) (subst e₁ Θ) subst (var x) Θ = Θ x subst z Θ = z subst (s e) Θ = s (subst e Θ) subst (rec e e₁ e₂) Θ = rec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend Θ))) subst (lam e) Θ = lam (subst e (s-extend Θ)) subst (app e e₁) Θ = app (subst e Θ) (subst e₁ Θ) subst (prod e1 e2) Θ = prod (subst e1 Θ) (subst e2 Θ) subst (l-proj e) Θ = l-proj (subst e Θ) subst (r-proj e) Θ = r-proj (subst e Θ) subst nil Θ = nil subst (x ::c xs) Θ = subst x Θ ::c subst xs Θ subst true Θ = true subst false Θ = false subst (listrec e e₁ e₂) Θ = listrec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend (s-extend Θ)))) subst rz Θ = rz subst (rsuc e) Θ = rsuc (subst e Θ) subst (rrec e e₁ e₂ p) Θ = rrec (subst e Θ) (subst e₁ Θ) (subst e₂ Θ) (subst-cong p) subst (max τ e1 e2) Θ = max τ (subst e1 Θ) (subst e2 Θ) subst1 : ∀ {Γ τ τ1} → Γ |- τ1 → (τ1 :: Γ) |- τ → Γ |- τ subst1 e e' = subst e' (q e) _rs_ ρ Θ x = ren (subst (var x) Θ) ρ _ss_ Θ1 Θ2 x = subst (subst (var x) Θ2) Θ1 _sr_ Θ ρ x = subst (ren (var x) ρ) Θ extend-id-once-lemma : ∀ {Γ τ τ'} → (x : τ ∈ τ' :: Γ) → _==_ {_} {τ' :: Γ |- τ} (ids {τ' :: Γ} {τ} x) (s-extend {Γ} {Γ} {τ'} (ids {Γ}) {τ} x) extend-id-once-lemma i0 = Refl extend-id-once-lemma (iS x) = Refl extend-id-once : ∀ {Γ τ} → Id {_} {sctx (τ :: Γ) (τ :: Γ)} (ids {τ :: Γ}) (s-extend ids) extend-id-once = λ=i (λ τ → λ= (λ x → extend-id-once-lemma x)) extend-id-twice : ∀ {Γ τ1 τ2} → Id {_} {sctx (τ1 :: τ2 :: Γ) (τ1 :: τ2 :: Γ)} (ids {τ1 :: τ2 :: Γ}) (s-extend (s-extend ids)) extend-id-twice = ap s-extend extend-id-once ∘ extend-id-once _+C_ : ∀ {Γ τ} → Γ |- C → Γ |- (C ×c τ)→ Γ |- (C ×c τ) c +C e = prod (plusC c (l-proj e)) (r-proj e) _trans_ : ∀ {Γ T} → {e e' e'' : Γ |- T} → e ≤s e' → e' ≤s e'' → e ≤s e'' _trans_ = trans-s infixr 10 _trans_
49.616197
173
0.44312
0d7df635d46c8cce0d46316206a62f825ebff5f9
3,051
agda
Agda
src/LibraBFT/Impl/Consensus/ConsensusTypes/ProposalMsg.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Consensus/ConsensusTypes/ProposalMsg.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Consensus/ConsensusTypes/ProposalMsg.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Types import LibraBFT.Impl.Consensus.ConsensusTypes.Block as Block import LibraBFT.Impl.Consensus.ConsensusTypes.TimeoutCertificate as TimeoutCertificate open import LibraBFT.Impl.OBM.Logging.Logging open import LibraBFT.ImplShared.Base.Types open import LibraBFT.ImplShared.Consensus.Types open import Optics.All open import Util.Hash open import Util.Prelude ------------------------------------------------------------------------------ open import Data.String using (String) module LibraBFT.Impl.Consensus.ConsensusTypes.ProposalMsg where verifyWellFormed : ProposalMsg → Either ErrLog Unit verifyWellFormed self = do lcheck (not (Block.isNilBlock (self ^∙ pmProposal))) (here' ("Proposal for a NIL block" ∷ [])) withErrCtx' ("Failed to verify ProposalMsg's block" ∷ []) (Block.verifyWellFormed (self ^∙ pmProposal)) lcheck (self ^∙ pmProposal ∙ bRound >? 0) (here' ("Proposal for has round <= 0" ∷ [])) lcheck (self ^∙ pmProposal ∙ bEpoch == self ^∙ pmSyncInfo ∙ siEpoch) (here' ("ProposalMsg has different epoch than SyncInfo" ∷ [])) -- lsSI (self ^∙ pmSyncInfo) lcheck (self ^∙ pmProposal ∙ bParentId == self ^∙ pmSyncInfo ∙ siHighestQuorumCert ∙ qcCertifiedBlock ∙ biId) (here' ( "Proposal SyncInfo HQC CertifiedBlock id not eq to block parent id" ∷ [])) -- lsSI (self ^∙ pmSyncInfo) let previousRound = self ^∙ pmProposal ∙ bRound ∸ 1 -- NOTE: monus usage let highestCertifiedRound = max (self ^∙ pmProposal ∙ bQuorumCert ∙ qcCertifiedBlock ∙ biRound) (maybe 0 (_^∙ tcRound) (self ^∙ pmSyncInfo ∙ siHighestTimeoutCert)) lcheck (previousRound == highestCertifiedRound) (here' ("Proposal does not have a certified round" ∷ [])) -- lsMTC (self ^∙ pmSyncInfo ∙ siHighestTimeoutCert) lcheck (is-just (self ^∙ pmProposal ∙ bAuthor)) (here' ("Proposal does not have an author" ∷ [])) -- LBFT-DIFF : this check used to live in EventProcessor ∙ processProposedBlockM -- TODO: is it needed? -- Safety invariant: For any valid proposed block -- , its parent block == the block pointed to by its QC. lcheck (self ^∙ pmProposal ∙ bParentId == self ^∙ pmProposal ∙ bQuorumCert ∙ qcCertifiedBlock ∙ biId) (here' ("parent id /= qcCB" ∷ [])) -- show (self ^∙ pmProposal) where here' : List String → List String here' t = "ProposalMsg" ∷ "verifyWellFormed" {-∷ lsPM self-} ∷ t verify : ProposalMsg → ValidatorVerifier → Either ErrLog Unit verify self validator = do Block.validateSignature (self ^∙ pmProposal) validator TimeoutCertificate.verify' (self ^∙ pmSyncInfo ∙ siHighestTimeoutCert) validator verifyWellFormed self
50.016393
111
0.662406
72824ed3012a9753c24b91c107f5d6cf498905b1
4,163
agda
Agda
Agda/Ag02.agda
Brethland/LEARNING-STUFF
eb2cef0556efb9a4ce11783f8516789ea48cc344
[ "MIT" ]
2
2020-02-03T05:05:52.000Z
2020-03-11T10:35:42.000Z
Agda/Ag02.agda
Brethland/LEARNING-STUFF
eb2cef0556efb9a4ce11783f8516789ea48cc344
[ "MIT" ]
null
null
null
Agda/Ag02.agda
Brethland/LEARNING-STUFF
eb2cef0556efb9a4ce11783f8516789ea48cc344
[ "MIT" ]
1
2019-12-13T04:50:46.000Z
2019-12-13T04:50:46.000Z
module Ag02 where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong; sym) open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎) open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _^_) +-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p) +-assoc zero n p = begin (zero + n) + p ≡⟨⟩ n + p ≡⟨⟩ zero + (n + p) ∎ +-assoc (suc m) n p = begin (suc m + n) + p ≡⟨⟩ suc (m + n) + p ≡⟨⟩ suc ((m + n) + p) ≡⟨ cong suc (+-assoc m n p) ⟩ suc (m + (n + p)) ≡⟨⟩ suc m + (n + p) ∎ +-identityʳ : ∀ (m : ℕ) → m + 0 ≡ m +-identityʳ zero = begin zero + 0 ≡⟨⟩ zero ∎ +-identityʳ (suc m) = begin suc m + zero ≡⟨⟩ suc (m + zero) ≡⟨ cong suc (+-identityʳ m) ⟩ suc m ∎ +-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n) +-suc zero n = begin zero + suc n ≡⟨⟩ suc n ≡⟨⟩ suc (zero + n) ∎ +-suc (suc m) n = begin suc m + suc n ≡⟨⟩ suc (m + suc n) ≡⟨ cong suc (+-suc m n) ⟩ suc (suc (m + n)) ≡⟨⟩ suc (suc m + n) ∎ +-comm : ∀ (m n : ℕ) → m + n ≡ n + m +-comm m zero = begin m + zero ≡⟨ +-identityʳ m ⟩ m ≡⟨⟩ zero + m ∎ +-comm m (suc n) = begin m + suc n ≡⟨ +-suc m n ⟩ suc (m + n) ≡⟨ cong suc (+-comm m n) ⟩ suc (n + m) ≡⟨⟩ suc n + m ∎ +-rearrange : ∀ (m n p q : ℕ) → (m + n) + (p + q) ≡ m + (n + p) + q +-rearrange m n p q = begin (m + n) + (p + q) ≡⟨ +-assoc m n (p + q) ⟩ m + (n + (p + q)) ≡⟨ cong (m +_) (sym (+-assoc n p q)) ⟩ m + ((n + p) + q) ≡⟨ sym (+-assoc m (n + p) q) ⟩ m + (n + p) + q ∎ +-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p) +-assoc′ zero n p = refl +-assoc′ (suc m) n p rewrite +-assoc′ m n p = refl +-swap : ∀ (m n p : ℕ) → m + (n + p) ≡ n + (m + p) +-swap m n p rewrite sym (+-assoc m n p) | +-comm m n | +-assoc n m p = refl *-distrib-+ : ∀ (m n p : ℕ) → (m + n) * p ≡ m * p + n * p *-distrib-+ 0 n p = refl *-distrib-+ (suc m) n p rewrite *-distrib-+ m n p | +-assoc p (m * p) (n * p) = refl *-assoc : ∀ (m n p : ℕ) → (m * n) * p ≡ m * (n * p) *-assoc 0 n p = refl *-assoc (suc m) n p rewrite *-distrib-+ n (m * n) p | *-assoc m n p = refl *-identityʳ : ∀ (n : ℕ) → n * 0 ≡ 0 *-identityʳ 0 = refl *-identityʳ (suc n) rewrite *-identityʳ n = refl *-suc : ∀ (m n : ℕ) → m * (suc n) ≡ m + m * n *-suc 0 n = refl *-suc (suc m) n rewrite *-suc m n | +-swap n m (m * n) = refl *-comm : ∀ (m n : ℕ) → m * n ≡ n * m *-comm 0 n rewrite *-identityʳ n = refl *-comm (suc m) n rewrite *-comm m n | *-suc n m = refl ∸-n : ∀ (n : ℕ) → 0 ∸ n ≡ 0 ∸-n zero = refl ∸-n (suc n) = refl ∸-+-assoc : ∀ (m n p : ℕ) → m ∸ n ∸ p ≡ m ∸ (n + p) ∸-+-assoc zero n p rewrite ∸-n n | ∸-n p | ∸-n (n + p) = refl ∸-+-assoc (suc m) zero p = refl ∸-+-assoc (suc m) (suc n) p rewrite ∸-+-assoc m n p = refl ^-distrib-+ : ∀ (m n p : ℕ) → m ^ (n + p) ≡ (m ^ n) * (m ^ p) ^-distrib-+ m 0 p rewrite +-identityʳ (m ^ p) = refl ^-distrib-+ m (suc n) p rewrite ^-distrib-+ m n p | *-assoc m (m ^ n) (m ^ p) = refl ^-distrib-* : ∀ (m n p : ℕ) → (m * n) ^ p ≡ (m ^ p) * (n ^ p) ^-distrib-* m n zero = refl ^-distrib-* m n (suc p) rewrite ^-distrib-* m n p | sym (*-assoc (m * n) (m ^ p) (n ^ p)) | *-assoc m n (m ^ p) | *-comm n (m ^ p) | *-assoc m ((m ^ p) * n) (n ^ p) | *-assoc (m ^ p) n (n ^ p) | *-assoc m (m ^ p) (n * (n ^ p)) = refl ^-identity : ∀ (p : ℕ) → 1 ^ p ≡ 1 ^-identity zero = refl ^-identity (suc p) rewrite ^-identity p = refl ^-*-plus : ∀ (m n p : ℕ) → m ^ (n * p) ≡ (m ^ n) ^ p ^-*-plus m zero p rewrite ^-identity p = refl ^-*-plus m (suc n) p rewrite ^-distrib-+ m p (n * p) | ^-*-plus m n p | sym (^-distrib-* m (m ^ n) p) = refl data Bin : Set where nil : Bin x0_ : Bin → Bin x1_ : Bin → Bin inc : Bin → Bin inc nil = x1 nil inc (x1 b) = x0 (inc b) inc (x0 b) = x1 b to : ℕ → Bin to zero = nil to (suc m) = inc (to m) from : Bin → ℕ from nil = zero from (x1 b) = suc (2 * (from b)) from (x0 b) = 2 * (from b) inc-suc : ∀ (x : Bin) → from (inc x) ≡ suc (from x) inc-suc nil = refl inc-suc (x0 x) = refl inc-suc (x1 x) rewrite inc-suc x | +-suc (from x) (from x + 0) = refl
23.38764
108
0.444631
6539f2b8627983a0e3cd95ca0a1455502612e969
1,601
agda
Agda
TypeTheory/Nat/Mono/Structure.agda
rei1024/agda-misc
37200ea91d34a6603d395d8ac81294068303f577
[ "MIT" ]
3
2020-04-07T17:49:42.000Z
2020-04-21T00:03:43.000Z
TypeTheory/Nat/Mono/Structure.agda
rei1024/agda-misc
37200ea91d34a6603d395d8ac81294068303f577
[ "MIT" ]
null
null
null
TypeTheory/Nat/Mono/Structure.agda
rei1024/agda-misc
37200ea91d34a6603d395d8ac81294068303f577
[ "MIT" ]
null
null
null
module TypeTheory.Nat.Mono.Structure where open import Level renaming (zero to lzero; suc to lsuc) open import Data.Empty using (⊥) open import Data.Product using (Σ; _×_; _,_) open import Relation.Binary using (Rel) open import Relation.Binary.PropositionalEquality open import Relation.Nullary using (¬_) record Nat : Set₁ where field N : Set zero : N suc : N → N ind : (P : N → Set) → P zero → (∀ k → P k → P (suc k)) → ∀ n → P n ind-zero : ∀ P P-zero P-suc → ind P P-zero P-suc zero ≡ P-zero ind-suc : ∀ P P-zero P-suc n → ind P P-zero P-suc (suc n) ≡ P-suc n (ind P P-zero P-suc n) s≢z : ∀ {n} → suc n ≢ zero 0N : N 0N = zero 1N : N 1N = suc zero z≢s : ∀ {n} → zero ≢ suc n z≢s = ≢-sym s≢z rec : {A : Set} → A → (A → A) → N → A rec {A} z s = ind (λ _ → A) z (λ _ → s) rec-zero : ∀ {A} (z : A) s → rec z s zero ≡ z rec-zero z s = ind-zero _ _ _ rec-suc : ∀ {A} (z : A) s n → rec z s (suc n) ≡ s (rec z s n) rec-suc z s n = ind-suc _ _ _ _ infixl 6 _+_ infixl 7 _*_ infix 4 _≤_ _<_ _≥_ _>_ _≰_ -- Arithematic -- Addition _+_ : N → N → N m + n = rec n suc m -- Multiplication _*_ : N → N → N m * n = rec zero (n +_) m -- Order _≤_ : Rel N lzero m ≤ n = Σ N λ o → m + o ≡ n _<_ : Rel N lzero m < n = suc m ≤ n _≥_ : Rel N lzero m ≥ n = n ≤ m _>_ : Rel N lzero m > n = n < m _≰_ : Rel N lzero m ≰ n = ¬ m ≤ n _≮_ : Rel N lzero m ≮ n = ¬ m < n _≱_ : Rel N lzero m ≱ n = ¬ m ≥ n _≯_ : Rel N lzero m ≯ n = ¬ m > n
21.065789
75
0.494691
fdad32d6a95835df3288059fb7f9a4f3d0921355
1,178
agda
Agda
prototyping/PrettyPrinter.agda
Tr4shh/Roblox-Luau
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
[ "MIT" ]
null
null
null
prototyping/PrettyPrinter.agda
Tr4shh/Roblox-Luau
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
[ "MIT" ]
null
null
null
prototyping/PrettyPrinter.agda
Tr4shh/Roblox-Luau
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
[ "MIT" ]
null
null
null
module PrettyPrinter where open import Agda.Builtin.IO using (IO) open import Agda.Builtin.Int using (pos) open import Agda.Builtin.Unit using (⊤) open import FFI.IO using (getContents; putStrLn; _>>=_; _>>_) open import FFI.Data.Aeson using (Value; eitherDecode) open import FFI.Data.Either using (Left; Right) open import FFI.Data.String using (String; _++_) open import FFI.Data.Text.Encoding using (encodeUtf8) open import FFI.System.Exit using (exitWith; ExitFailure) open import Luau.Syntax using (Block) open import Luau.Syntax.FromJSON using (blockFromJSON) open import Luau.Syntax.ToString using (blockToString) runBlock : ∀ {a} → Block a → IO ⊤ runBlock block = putStrLn (blockToString block) runJSON : Value → IO ⊤ runJSON value with blockFromJSON(value) runJSON value | (Left err) = putStrLn ("Luau error: " ++ err) >> exitWith (ExitFailure (pos 1)) runJSON value | (Right block) = runBlock block runString : String → IO ⊤ runString txt with eitherDecode (encodeUtf8 txt) runString txt | (Left err) = putStrLn ("JSON error: " ++ err) >> exitWith (ExitFailure (pos 1)) runString txt | (Right value) = runJSON value main : IO ⊤ main = getContents >>= runString
35.69697
95
0.741935
ed840e09574b9daa124f997fce42fb21af052da0
2,001
agda
Agda
src/fot/FOTC/Program/ABP/Fair/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/FOTC/Program/ABP/Fair/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/FOTC/Program/ABP/Fair/PropertiesATP.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Fair properties ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.ABP.Fair.PropertiesATP where open import FOTC.Base open import FOTC.Base.List open import FOTC.Data.List open import FOTC.Program.ABP.Fair.Type open import FOTC.Program.ABP.Terms ------------------------------------------------------------------------------ -- Because a greatest post-fixed point is a fixed-point, then the Fair -- predicate is also a pre-fixed point of the functional FairF, i.e. -- -- FairF Fair ≤ Fair (see FOTC.Program.ABP.Fair). -- See Issue https://github.com/asr/apia/issues/81 . Fair-inA : D → Set Fair-inA os = ∃[ ft ] ∃[ os' ] F*T ft ∧ os ≡ ft ++ os' ∧ Fair os' {-# ATP definition Fair-inA #-} Fair-in : ∀ {os} → ∃[ ft ] ∃[ os' ] F*T ft ∧ os ≡ ft ++ os' ∧ Fair os' → Fair os Fair-in h = Fair-coind Fair-inA h' h where postulate h' : ∀ {os} → Fair-inA os → ∃[ ft ] ∃[ os' ] F*T ft ∧ os ≡ ft ++ os' ∧ Fair-inA os' {-# ATP prove h' #-} head-tail-Fair : ∀ {os} → Fair os → os ≡ T ∷ tail₁ os ∨ os ≡ F ∷ tail₁ os head-tail-Fair {os} Fos with Fair-out Fos ... | (.(T ∷ []) , os' , f*tnil , h , Fos') = prf where postulate prf : os ≡ T ∷ tail₁ os ∨ os ≡ F ∷ tail₁ os {-# ATP prove prf #-} ... | (.(F ∷ ft) , os' , f*tcons {ft} FTft , h , Fos') = prf where postulate prf : os ≡ T ∷ tail₁ os ∨ os ≡ F ∷ tail₁ os {-# ATP prove prf #-} tail-Fair : ∀ {os} → Fair os → Fair (tail₁ os) tail-Fair {os} Fos with Fair-out Fos ... | .(T ∷ []) , os' , f*tnil , h , Fos' = prf where postulate prf : Fair (tail₁ os) {-# ATP prove prf #-} ... | .(F ∷ ft) , os' , f*tcons {ft} FTft , h , Fos' = prf where postulate prf : Fair (tail₁ os) {-# ATP prove prf Fair-in #-}
33.35
78
0.497251
a0ba43fc2a436c95ec11f2ed18ca88bde8648b51
417
agda
Agda
test/Succeed/EtaAndMetas.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/EtaAndMetas.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/EtaAndMetas.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS --show-implicit #-} -- {-# OPTIONS -v tc:20 -v tc.pos.occ:20 -v tc.mod.apply:80 -v tc.signature:30 #-} module EtaAndMetas where record ⊤ : Set where record Functor {_ : ⊤} : Set₁ where field F : Set → Set eta : Functor → Functor eta S = record { F = F } where open Functor S postulate Π : (To : Functor) → Set mkΠ : (B : Functor) → Π (eta B) To : Functor π : Π (eta To) π = mkΠ _
18.954545
82
0.58753
64177b8ecb7bc25eb0dcbe46928347572cf1c308
8,271
agda
Agda
test/epic/tests/Cat.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
null
null
null
test/epic/tests/Cat.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
null
null
null
test/epic/tests/Cat.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
null
null
null
{- An adaptation of Edwin Brady and Kevin Hammond's paper Scrapping your inefficient engine ... -} {-# OPTIONS --type-in-type #-} module tests.Cat where open import Prelude.Bool open import Prelude.Bot open import Prelude.IO open import Prelude.Fin open import Prelude.Eq open import Prelude.Nat open import Prelude.Product open import Prelude.String open import Prelude.Unit open import Prelude.Vec record Top : Set where constructor tt data Ty : Set where TyUnit : Ty TyBool : Ty TyLift : Set -> Ty TyHandle : Nat -> Ty interpTy : Ty -> Set interpTy TyUnit = Unit interpTy TyBool = Bool interpTy (TyLift A) = A interpTy (TyHandle n) = Fin n data Purpose : Set where Reading : Purpose Writing : Purpose getMode : Purpose -> String getMode Reading = "r" getMode Writing = "w" data FileState : Set where Open : Purpose -> FileState Closed : FileState postulate EpicFile : Set static[_] : {A : Set} → A → A static[ x ] = x {-# STATIC static[_] #-} FileVec : Nat -> Set FileVec n = Vec FileState n data FileHandle : FileState -> Set where OpenFile : ∀{p} -> EpicFile -> FileHandle (Open p) ClosedFile : FileHandle Closed data Env : ∀{n} -> FileVec n -> Set where Empty : Env [] Extend : {n : Nat}{T : FileState}{G : FileVec n} -> (res : FileHandle T) -> Env G -> Env (T :: G) addEnd : ∀{n T}{G : FileVec n} -> Env G -> FileHandle T -> Env (snoc G T) addEnd Empty fh = Extend fh Empty addEnd (Extend x xs) fh = Extend x (addEnd xs fh) updateEnv : ∀{n T}{G : FileVec n} -> Env G -> (i : Fin n) -> (fh : FileHandle T) -> Env (G [ i ]= T) updateEnv (Extend x xs) fz e = Extend e xs updateEnv (Extend x xs) (fs n) e = Extend x (updateEnv xs n e) updateEnv Empty () e bound : ∀{n : Nat} -> Fin (S n) bound {Z} = fz bound {S n} = fs (bound {n}) _==P_ : Purpose -> Purpose -> Set Reading ==P Reading = Top Reading ==P Writing = Bot Writing ==P Reading = Bot Writing ==P Writing = Top OpenH : ∀{n} -> Fin n -> Purpose -> FileVec n -> Set OpenH fz p (Open p' :: as) = p ==P p' OpenH fz p (Closed :: as) = Bot OpenH (fs i) p ( a :: as) = OpenH i p as getFile : ∀{n}{i : Fin n}{p : Purpose}{ts : FileVec n}{ope : OpenH i p ts} -> Env ts -> EpicFile getFile {Z} {()} env getFile {S y} {fz} (Extend (OpenFile y') y0) = y' getFile {S y} {fz} {ope = ()} (Extend ClosedFile y') getFile {S y} {fs y'} {ope = ope} (Extend res y0) = getFile {y} {y'} {ope = ope} y0 getPurpose : {n : Nat} -> Fin n -> FileVec n -> Purpose getPurpose f ts with ts ! f ... | Open p = p ... | Closed = Reading -- Should not happen right? FilePath : Set FilePath = String data File : ∀{n n'} -> FileVec n -> FileVec n' -> Ty -> Set where ACTION : ∀{a l}{ts : FileVec l} -> IO (interpTy a) -> File ts ts a RETURN : ∀{a l}{ts : FileVec l} -> interpTy a -> File ts ts a WHILE : ∀{l}{ts : FileVec l} -> File ts ts TyBool -> File ts ts TyUnit -> File ts ts TyUnit IF : ∀{a l}{ts : FileVec l} -> Bool -> File ts ts a -> File ts ts a -> File ts ts a BIND : ∀{a b l l' l''}{ts : FileVec l}{ts' : FileVec l'}{ts'' : FileVec l''} -> File ts ts' a -> (interpTy a -> File ts' ts'' b) -> File ts ts'' b OPEN : ∀{l}{ts : FileVec l} -> (p : Purpose) -> (fd : FilePath) -> File ts (snoc ts (Open p)) (TyHandle (S l)) CLOSE : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> {p : OpenH i (getPurpose i ts) ts} -> File ts (ts [ i ]= Closed) TyUnit GETLINE : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> {p : OpenH i Reading ts} -> File ts ts (TyLift String) EOF : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> {p : OpenH i Reading ts} -> File ts ts TyBool PUTLINE : ∀ {l}{ts : FileVec l} -> (i : Fin l) -> (str : String) -> {p : OpenH i Writing ts} -> File ts ts TyUnit postulate while : IO Bool -> IO Unit -> IO Unit fopen : FilePath -> String -> IO EpicFile fclose : EpicFile -> IO Unit fread : EpicFile -> IO String feof : EpicFile -> IO Bool fwrite : EpicFile -> String -> IO Unit {-# COMPILED_EPIC while (add : Any, body : Any, u : Unit) -> Any = %while (add(u), body(u)) #-} {-# COMPILED_EPIC fopen (fp : Any, mode : Any, u : Unit) -> Ptr = foreign Ptr "fopen" (mkString(fp) : String, mkString(mode) : String) #-} {-# COMPILED_EPIC fclose (file : Ptr, u : Unit) -> Unit = foreign Int "fclose" (file : Ptr); unit #-} {-# COMPILED_EPIC fread (file : Ptr, u : Unit) -> Any = frString(foreign String "freadStrChunk" (file : Ptr)) #-} {-# COMPILED_EPIC feof (file : Ptr, u : Unit) -> Bool = foreign Int "feof" (file : Ptr) #-} {-# COMPILED_EPIC fwrite (file : Ptr, str : Any, u : Unit) -> Unit = foreign Unit "fputs" (mkString(str) : String, file : Ptr) #-} fmap : {A B : Set} -> (A -> B) -> IO A -> IO B fmap f io = x <- io , return (f x) data MIO (A : Set) : Set where Return : A -> MIO A ABind : {B : Set} -> IO B -> (B -> MIO A) -> MIO A -- While : MIO Bool -> MIO Unit -> MIO Unit MBind : {A B : Set} -> MIO A -> (A -> MIO B) -> MIO B MBind (Return x) f = f x MBind (ABind io k) f = ABind io (λ x -> MBind (k x) f) -- MBind (While b u) f = mmap : {A B : Set} -> (A -> B) -> MIO A -> MIO B mmap f mio = MBind mio (λ x -> Return (f x)) runMIO : {A : Set} -> MIO A -> IO A runMIO (Return x) = return x runMIO (ABind io f) = x <- io , runMIO (f x) interp : ∀{n n' T}{ts : FileVec n}{ts' : FileVec n'} -> Env ts -> File ts ts' T -> MIO (Env ts' × interpTy T) interp env (ACTION io) = ABind io (λ x -> Return (env , x)) interp env (RETURN val) = Return (env , val) interp env (WHILE add body) = ABind (while (runMIO (mmap snd (interp env add))) (runMIO (mmap snd (interp env body)))) (λ _ -> Return (env , unit)) interp env (IF b t f) = if b then interp env t else interp env f interp env (BIND code k) = MBind (interp env code) (λ v -> interp (fst v) (k (snd v))) interp env (OPEN p fpath) = ABind (fopen fpath (getMode p)) (λ fh -> Return (addEnd env (OpenFile fh), bound)) interp env (CLOSE i {p = p}) = ABind (fclose (getFile {_} {i} {ope = p} env)) (\ _ -> Return (updateEnv env i ClosedFile , unit)) interp env (GETLINE i {p = p}) = ABind (fread (getFile {_} {i} {ope = p} env)) (λ x -> Return (env , x)) interp env (EOF i {p = p}) = ABind (feof (getFile {_} {i} {ope = p} env)) (\ e -> Return (env , e)) interp env (PUTLINE i str {p = p}) = ABind (fwrite (getFile {i = i} {ope = p} env) str) (λ _ -> ABind (fwrite (getFile {i = i} {ope = p} env) "\n") (λ x -> Return (env , unit))) allClosed : (n : Nat) -> FileVec n allClosed Z = [] allClosed (S n) = Closed :: allClosed n syntax BIND e (\ x -> f) = x := e % f infixl 0 BIND _%%_ : ∀{a b l l' l''}{ts : FileVec l}{ts' : FileVec l'}{ts'' : FileVec l''} -> File ts ts' a -> File ts' ts'' b -> File ts ts'' b m %% k = BIND m (λ _ -> k) infixr 0 _%%_ {- cat : File [] (Closed :: []) TyUnit cat = ( fz := OPEN Reading "tests/Cat.out" % WHILE (b := EOF fz % RETURN (not b)) ( str := GETLINE fz % ACTION (putStrLn str) ) %% CLOSE fz ) cont : Fin 1 -> File (Open Reading :: []) (Closed :: []) TyUnit cont (fs ()) cont fz = BIND (WHILE (BIND (EOF fz) (\b -> RETURN (not b))) (BIND (GETLINE fz) (\str -> ACTION (putStrLn str)) ) ) (λ x → CLOSE fz) cat : File [] (Closed :: []) TyUnit cat = BIND (OPEN Reading "hej") cont -} cont : Fin 1 -> File (Open Reading :: []) (Closed :: []) TyUnit cont (fs ()) cont fz = WHILE ( b := EOF fz % RETURN (not b)) ( str := GETLINE fz % ACTION (putStr str) ) %% CLOSE fz cat : File [] (Closed :: []) TyUnit cat = BIND (OPEN Reading "tests/Cat.out") cont copy : File [] (Closed :: Closed :: []) TyUnit copy = BIND (OPEN Reading "copy/input") (λ _ → BIND (OPEN Writing "copy/output") (λ _ → BIND (WHILE (BIND (EOF fz) (λ b → RETURN (not b))) (BIND (GETLINE fz) (λ str → PUTLINE (fs fz) str))) (λ _ → BIND (CLOSE fz) (λ _ → CLOSE (fs fz))))) runProg : {n : Nat} -> File [] (allClosed n) TyUnit -> IO Unit runProg p = runMIO (mmap snd (interp Empty p)) {-# STATIC runProg #-} main : IO Unit main = runProg cat -- static[ runProg cat ] -- main = runProg cat
33.084
138
0.562689
730601879cdcea3fc4f14d1da9cfc27916e8520b
10,656
agda
Agda
src/Tactic/By/Id.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
3
2020-05-21T22:58:50.000Z
2021-09-02T17:18:15.000Z
src/Tactic/By/Id.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
src/Tactic/By/Id.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Some tactics aimed at making equational reasoning proofs more -- readable for the cubical identity type ------------------------------------------------------------------------ {-# OPTIONS --erased-cubical --safe #-} module Tactic.By.Id where import Agda.Builtin.Cubical.Id open import Equality.Id open import Prelude open import List equality-with-J as L open import Maybe equality-with-J open import Monad equality-with-J open import Tactic.By equality-with-J as TB open import TC-monad equality-with-J as TC hiding (Type) open TB public using (⟨_⟩) private -- Constructs the type of equalities between its two arguments. equality : Term → Term → TC.Type equality lhs rhs = def (quote _≡_) (varg lhs ∷ varg rhs ∷ []) -- An illustration of what the cong functions constructed by -- make-cong-called look like. cong₃′ : ∀ {a b c d : Level} {A : Type a} {B : Type b} {C : Type c} {D : Type d} {x₁ y₁ x₂ y₂ x₃ y₃} (f : A → B → C → D) → x₁ ≡ y₁ → x₂ ≡ y₂ → x₃ ≡ y₃ → f x₁ x₂ x₃ ≡ f y₁ y₂ y₃ cong₃′ f eq₁ eq₂ eq₃ = trans (cong (λ x → f x _ _) eq₁) (trans (cong (λ x → f _ x _) eq₂) (trans (cong (λ x → f _ _ x) eq₃) refl)) -- Constructs a "cong" function, with the given name, for functions -- with the given number of arguments. Note that the size of the raw -- code of the generated function is quadratic in the number. make-cong-called : Name → ℕ → TC ⊤ make-cong-called name-of-cong n = do declareDef (varg name-of-cong) (type-of-cong equality n) defineFun name-of-cong (the-clause ∷ []) where body : ℕ → Term body zero = def (quote refl) [] body (suc m) = def (quote trans) (varg (def (quote cong) (varg (lam visible $ abs "x" $ var (1 + n) $ replicate (n ∸ suc m) (varg unknown) ++ varg (var 0 []) ∷ replicate m (varg unknown)) ∷ varg (var m []) ∷ [])) ∷ varg (body m) ∷ []) the-clause = clause (("f" , varg unknown) ∷ replicate n ("eq" , varg unknown)) (varg (var n) ∷ L.map (varg ∘ var) (nats-< n)) (body n) unquoteDecl cong₃ = make-cong-called cong₃ 3 unquoteDecl cong₄ = make-cong-called cong₄ 4 unquoteDecl cong₅ = make-cong-called cong₅ 5 unquoteDecl cong₆ = make-cong-called cong₆ 6 unquoteDecl cong₇ = make-cong-called cong₇ 7 unquoteDecl cong₈ = make-cong-called cong₈ 8 unquoteDecl cong₉ = make-cong-called cong₉ 9 unquoteDecl cong₁₀ = make-cong-called cong₁₀ 10 -- Constructs a "cong" function (similar to cong and cong₂ in -- Equality) for functions with the given number of arguments. The -- name of the constructed function is returned (for 1 and 2 the -- functions in Equality are returned). The cong functions for -- functions with 3 up to 10 arguments are cached to avoid creating -- lots of copies of the same functions. make-cong : ℕ → TC Name make-cong 1 = return (quote cong) make-cong 2 = return (quote cong₂) make-cong 3 = return (quote cong₃) make-cong 4 = return (quote cong₄) make-cong 5 = return (quote cong₅) make-cong 6 = return (quote cong₆) make-cong 7 = return (quote cong₇) make-cong 8 = return (quote cong₈) make-cong 9 = return (quote cong₉) make-cong 10 = return (quote cong₁₀) make-cong n = do cong ← freshName "cong" make-cong-called cong n return cong open Tactics (λ where (def (quote Agda.Builtin.Cubical.Id.Id) (arg _ a ∷ arg _ A ∷ arg _ x ∷ arg _ y ∷ [])) → return $ just (a , A , x , y) _ → return nothing) equality (λ a A x → def (quote refl) (harg a ∷ harg A ∷ harg x ∷ [])) (λ p → def (quote sym) (varg p ∷ [])) (λ lhs rhs f p → def (quote cong) (replicate 4 (harg unknown) ++ harg lhs ∷ harg rhs ∷ varg f ∷ varg p ∷ [])) false make-cong true public ------------------------------------------------------------------------ -- Some unit tests private module Tests (assumption : 48 ≡ 42) (lemma : ∀ n → n + 8 ≡ n + 2) (f : ℕ → ℕ → ℕ → ℕ) where g : ℕ → ℕ → ℕ → ℕ g zero _ _ = 12 g (suc _) _ _ = 12 fst : ∀ {a b} {A : Type a} {B : A → Type b} → Σ A B → A fst = proj₁ {-# NOINLINE fst #-} record R (F : Type → Type) : Type₁ where field p : {A : Type} {x : F A} → x ≡ x open R ⦃ … ⦄ public -- Tests for by. module By-tests where test₁ : 40 + 2 ≡ 42 test₁ = by definition test₂ : 48 ≡ 42 → 42 ≡ 48 test₂ eq = by eq test₃ : (f : ℕ → ℕ) → f 42 ≡ f 48 test₃ f = by assumption test₄ : (f : ℕ → ℕ) → f 48 ≡ f 42 test₄ f = by assumption test₅ : (f : ℕ → ℕ → ℕ) → f 42 48 ≡ f 48 42 test₅ f = by assumption test₆ : (f : ℕ → ℕ → ℕ → ℕ) → f 42 45 48 ≡ f 48 45 42 test₆ f = by assumption test₇ : f 48 (f 42 45 48) 42 ≡ f 48 (f 48 45 42) 48 test₇ = by assumption test₈ : ∀ n → g n (g n 45 48) 42 ≡ g n (g n 45 42) 48 test₈ n = by assumption test₉ : (f : ℕ → ℕ) → f 42 ≡ f 48 test₉ f = by (lemma 40) test₁₀ : (f : ℕ → ℕ) → f 42 ≡ f 48 test₁₀ f = by (λ (_ : ⊤) → assumption) test₁₁ : (f : ℕ × ℕ → ℕ × ℕ) → (∀ x → ⟨ _≡_ ⟩ (f x) x) → fst (f (12 , 73)) ≡ fst {B = λ _ → ℕ} (12 , 73) test₁₁ _ hyp = by hyp -- Two test cases for the extra check in try-refl. -- test₁₂ : (h : ℕ → Maybe ℕ) → -- ((xs : ℕ) → h xs ≡ just xs) → -- (xs : ℕ) → suc ⟨$⟩ h xs ≡ suc ⟨$⟩ return xs -- test₁₂ h hyp xs = -- suc ⟨$⟩ h xs ≡⟨ by (hyp xs) ⟩∎ -- suc ⟨$⟩ return xs ∎ -- test₁₃ : (h : List ⊤ → Maybe (List ⊤)) → -- ((xs : List ⊤) → h xs ≡ just xs) → -- (x : ⊤) (xs : List ⊤) → _ -- test₁₃ h hyp x xs = -- _∷_ ⟨$⟩ return x ⊛ h xs ≡⟨ by (hyp xs) ⟩∎ -- _∷_ ⟨$⟩ return x ⊛ return xs ∎ -- This test case fails if "refl a A lhs" is replaced by -- "refl unknown unknown lhs" in try-refl. test₁₅ : (F : Type → Type → Type) (G : Bool → Type → Type) → ((A : Type) → F (G false A) A ≡ G false (F A A)) → (A : Type) → G false (F (G false A) A) ≡ G false (G false (F A A)) test₁₅ F G hyp A = G false (F (G false A) A) ≡⟨ by hyp ⟩∎ G false (G false (F A A)) ∎ -- test₁₇ : -- (P : ℕ → Type) -- (f : ∀ {n} → P n → P n) -- (p : P 0) → -- f (subst P refl p) ≡ f p -- test₁₇ P _ _ = by (subst-refl P) test₁₈ : (subst′ : ∀ {a p} {A : Type a} {x y : A} (P : A → Type p) → x ≡ y → P x → P y) → (∀ {a p} {A : Type a} {x : A} (P : A → Type p) (p : P x) → subst′ P refl p ≡ p) → (P : ℕ → Type) (f : ∀ {n} → P n → P n) (p : P 0) → f (subst′ P refl p) ≡ f p test₁₈ _ subst′-refl P _ _ = by (subst′-refl P) -- test₁₉ : -- {F : Type → Type} ⦃ r : R F ⦄ {A : Type} {x₁ x₂ : F A} -- (p₁ p₂ : x₁ ≡ x₂) (assumption : p₁ ≡ p₂) → -- trans p p₁ ≡ trans p p₂ -- test₁₉ p₁ p₂ assumption = -- trans p p₁ ≡⟨ by assumption ⟩∎ -- trans p p₂ ∎ -- Tests for ⟨by⟩. module ⟨By⟩-tests where test₁ : ⟨ 40 + 2 ⟩ ≡ 42 test₁ = ⟨by⟩ refl test₂ : 48 ≡ 42 → ⟨ 42 ⟩ ≡ 48 test₂ eq = ⟨by⟩ eq test₃ : (f : ℕ → ℕ) → f ⟨ 42 ⟩ ≡ f 48 test₃ f = ⟨by⟩ assumption test₄ : (f : ℕ → ℕ) → f ⟨ 48 ⟩ ≡ f 42 test₄ f = ⟨by⟩ assumption test₅ : (f : ℕ → ℕ → ℕ) → f ⟨ 42 ⟩ ⟨ 42 ⟩ ≡ f 48 48 test₅ f = ⟨by⟩ assumption test₆ : (f : ℕ → ℕ → ℕ → ℕ) → f ⟨ 48 ⟩ 45 ⟨ 48 ⟩ ≡ f 42 45 42 test₆ f = ⟨by⟩ assumption test₇ : f ⟨ 48 ⟩ (f ⟨ 48 ⟩ 45 ⟨ 48 ⟩) ⟨ 48 ⟩ ≡ f 42 (f 42 45 42) 42 test₇ = ⟨by⟩ assumption test₈ : ∀ n → g n (g n 45 ⟨ 48 ⟩) ⟨ 48 ⟩ ≡ g n (g n 45 42) 42 test₈ n = ⟨by⟩ assumption test₉ : (f : ℕ → ℕ) → f ⟨ 42 ⟩ ≡ f 48 test₉ f = ⟨by⟩ (lemma 40) test₁₀ : (f : ℕ → ℕ) → f ⟨ 42 ⟩ ≡ f 48 test₁₀ f = ⟨by⟩ (λ (_ : ⊤) → assumption) test₁₁ : (f : ℕ × ℕ → ℕ × ℕ) → (∀ x → ⟨ _≡_ ⟩ (f x) x) → fst ⟨ f (12 , 73) ⟩ ≡ fst {B = λ _ → ℕ} (12 , 73) test₁₁ _ hyp = ⟨by⟩ hyp test₁₂ : (h : ℕ → Maybe ℕ) → ((xs : ℕ) → h xs ≡ just xs) → (xs : ℕ) → suc ⟨$⟩ h xs ≡ suc ⟨$⟩ return xs test₁₂ h hyp xs = suc ⟨$⟩ ⟨ h xs ⟩ ≡⟨ ⟨by⟩ (hyp xs) ⟩∎ suc ⟨$⟩ return xs ∎ test₁₃ : (h : List ⊤ → Maybe (List ⊤)) → ((xs : List ⊤) → h xs ≡ just xs) → (x : ⊤) (xs : List ⊤) → _ test₁₃ h hyp x xs = _∷_ ⟨$⟩ return x ⊛ ⟨ h xs ⟩ ≡⟨ ⟨by⟩ (hyp xs) ⟩∎ _∷_ ⟨$⟩ return x ⊛ return xs ∎ test₁₄ : (h : List ℕ → Maybe (List ℕ)) → ((xs : List ℕ) → h xs ≡ just xs) → (x : ℕ) (xs : List ℕ) → _ test₁₄ h hyp x xs = _∷_ ⟨$⟩ ⟨ h xs ⟩ ≡⟨ ⟨by⟩ (hyp xs) ⟩∎ _∷_ ⟨$⟩ return xs ∎ test₁₅ : (F : Type → Type → Type) (G : Bool → Type → Type) → ((A : Type) → F (G false A) A ≡ G false (F A A)) → (A : Type) → G false (F (G false A) A) ≡ G false (G false (F A A)) test₁₅ F G hyp A = G false ⟨ F (G false A) A ⟩ ≡⟨ ⟨by⟩ hyp ⟩∎ G false (G false (F A A)) ∎ test₁₆ : 48 ≡ 42 → _≡_ {A = ℕ → ℕ} (λ x → x + ⟨ 42 ⟩) (λ x → x + 48) test₁₆ hyp = ⟨by⟩ hyp test₁₇ : (P : ℕ → Type) (f : ∀ {n} → P n → P n) (p : P 0) → f ⟨ subst P refl p ⟩ ≡ f p test₁₇ P _ _ = ⟨by⟩ (subst-refl P) test₁₈ : (subst′ : ∀ {a p} {A : Type a} {x y : A} (P : A → Type p) → x ≡ y → P x → P y) → (∀ {a p} {A : Type a} {x : A} (P : A → Type p) (p : P x) → subst′ P refl p ≡ p) → (P : ℕ → Type) (f : ∀ {n} → P n → P n) (p : P 0) → f ⟨ subst′ P refl p ⟩ ≡ f p test₁₈ _ subst′-refl _ _ _ = ⟨by⟩ subst′-refl test₁₉ : {F : Type → Type} ⦃ r : R F ⦄ {A : Type} {x₁ x₂ : F A} (p₁ p₂ : x₁ ≡ x₂) (assumption : p₁ ≡ p₂) → trans p p₁ ≡ trans p p₂ test₁₉ p₁ p₂ assumption = trans p p₁ ≡⟨⟩ trans p ⟨ p₁ ⟩ ≡⟨ ⟨by⟩ assumption ⟩∎ trans p p₂ ∎
30.797688
73
0.455518
119ee55e9a3ee14782778d4b7ff61ff975af10cb
532
agda
Agda
test/asset/agda-stdlib-1.0/Relation/Binary/StrictPartialOrderReasoning.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/StrictPartialOrderReasoning.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Relation/Binary/StrictPartialOrderReasoning.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use the -- Relation.Binary.Reasoning.StrictPartialOrder module directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Relation.Binary.StrictPartialOrderReasoning {p₁ p₂ p₃} (S : StrictPartialOrder p₁ p₂ p₃) where open import Relation.Binary.Reasoning.StrictPartialOrder S public
33.25
72
0.554511
fd2cb85734e977f589c421f3bb3bd74135151bf0
593
agda
Agda
empty.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
empty.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
empty.agda
heades/AUGL
b33c6a59d664aed46cac8ef77d34313e148fecc2
[ "MIT" ]
null
null
null
module empty where open import level ---------------------------------------------------------------------- -- datatypes ---------------------------------------------------------------------- data ⊥ {ℓ : Level} : Set ℓ where ---------------------------------------------------------------------- -- syntax ---------------------------------------------------------------------- ---------------------------------------------------------------------- -- theorems ---------------------------------------------------------------------- ⊥-elim : ∀{ℓ} → ⊥ {ℓ} → ∀{ℓ'}{P : Set ℓ'} → P ⊥-elim ()
28.238095
70
0.151771
4e524c411050875356a1117aac74c4616a6163ba
312
agda
Agda
test/epic/Prelude/Char.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/epic/Prelude/Char.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/epic/Prelude/Char.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Prelude.Char where open import Prelude.Bool postulate Char : Set {-# BUILTIN CHAR Char #-} private primitive primCharEquality : (c c' : Char) -> Bool postulate eof : Char {-# COMPILED_EPIC eof () -> Int = foreign Int "eof" () #-} charEq : Char -> Char -> Bool charEq = primCharEquality
13.565217
58
0.653846
3fdf2f1dc6f041d30e8c77d9987ba33e9af58060
6,578
agda
Agda
Cubical/Foundations/Transport.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Foundations/Transport.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Foundations/Transport.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{- Basic theory about transport: - transport is invertible - transport is an equivalence ([transportEquiv]) -} {-# OPTIONS --safe #-} module Cubical.Foundations.Transport where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Function using (_∘_) -- Direct definition of transport filler, note that we have to -- explicitly tell Agda that the type is constant (like in CHM) transpFill : ∀ {ℓ} {A : Type ℓ} (φ : I) (A : (i : I) → Type ℓ [ φ ↦ (λ _ → A) ]) (u0 : outS (A i0)) → -------------------------------------- PathP (λ i → outS (A i)) u0 (transp (λ i → outS (A i)) φ u0) transpFill φ A u0 i = transp (λ j → outS (A (i ∧ j))) (~ i ∨ φ) u0 transport⁻ : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → B → A transport⁻ p = transport (λ i → p (~ i)) subst⁻ : ∀ {ℓ ℓ'} {A : Type ℓ} {x y : A} (B : A → Type ℓ') (p : x ≡ y) → B y → B x subst⁻ B p pa = transport⁻ (λ i → B (p i)) pa transport-fillerExt : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → PathP (λ i → A → p i) (λ x → x) (transport p) transport-fillerExt p i x = transport-filler p x i transport⁻-fillerExt : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → PathP (λ i → p i → A) (λ x → x) (transport⁻ p) transport⁻-fillerExt p i x = transp (λ j → p (i ∧ ~ j)) (~ i) x transport-fillerExt⁻ : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → PathP (λ i → p i → B) (transport p) (λ x → x) transport-fillerExt⁻ p = symP (transport⁻-fillerExt (sym p)) transport⁻-fillerExt⁻ : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → PathP (λ i → B → p i) (transport⁻ p) (λ x → x) transport⁻-fillerExt⁻ p = symP (transport-fillerExt (sym p)) transport⁻-filler : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) (x : B) → PathP (λ i → p (~ i)) x (transport⁻ p x) transport⁻-filler p x = transport-filler (λ i → p (~ i)) x transport⁻Transport : ∀ {ℓ} {A B : Type ℓ} → (p : A ≡ B) → (a : A) → transport⁻ p (transport p a) ≡ a transport⁻Transport p a j = transport⁻-fillerExt p (~ j) (transport-fillerExt p (~ j) a) transportTransport⁻ : ∀ {ℓ} {A B : Type ℓ} → (p : A ≡ B) → (b : B) → transport p (transport⁻ p b) ≡ b transportTransport⁻ p b j = transport-fillerExt⁻ p j (transport⁻-fillerExt⁻ p j b) -- Transport is an equivalence isEquivTransport : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → isEquiv (transport p) isEquivTransport {A = A} {B = B} p = transport (λ i → isEquiv (transport-fillerExt p i)) (idIsEquiv A) transportEquiv : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → A ≃ B transportEquiv p = (transport p , isEquivTransport p) substEquiv : ∀ {ℓ ℓ'} {A : Type ℓ} {a a' : A} (P : A → Type ℓ') (p : a ≡ a') → P a ≃ P a' substEquiv P p = (subst P p , isEquivTransport (λ i → P (p i))) liftEquiv : ∀ {ℓ ℓ'} {A B : Type ℓ} (P : Type ℓ → Type ℓ') (e : A ≃ B) → P A ≃ P B liftEquiv P e = substEquiv P (ua e) transpEquiv : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) → ∀ i → p i ≃ B transpEquiv P i .fst = transp (λ j → P (i ∨ j)) i transpEquiv P i .snd = transp (λ k → isEquiv (transp (λ j → P (i ∨ (j ∧ k))) (i ∨ ~ k))) i (idIsEquiv (P i)) uaTransportη : ∀ {ℓ} {A B : Type ℓ} (P : A ≡ B) → ua (transportEquiv P) ≡ P uaTransportη P i j = Glue (P i1) λ where (j = i0) → P i0 , transportEquiv P (i = i1) → P j , transpEquiv P j (j = i1) → P i1 , idEquiv (P i1) pathToIso : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → Iso A B Iso.fun (pathToIso x) = transport x Iso.inv (pathToIso x) = transport⁻ x Iso.rightInv (pathToIso x) = transportTransport⁻ x Iso.leftInv (pathToIso x) = transport⁻Transport x isInjectiveTransport : ∀ {ℓ : Level} {A B : Type ℓ} {p q : A ≡ B} → transport p ≡ transport q → p ≡ q isInjectiveTransport {p = p} {q} α i = hcomp (λ j → λ { (i = i0) → retEq univalence p j ; (i = i1) → retEq univalence q j }) (invEq univalence ((λ a → α i a) , t i)) where t : PathP (λ i → isEquiv (λ a → α i a)) (pathToEquiv p .snd) (pathToEquiv q .snd) t = isProp→PathP (λ i → isPropIsEquiv (λ a → α i a)) _ _ transportUaInv : ∀ {ℓ} {A B : Type ℓ} (e : A ≃ B) → transport (ua (invEquiv e)) ≡ transport (sym (ua e)) transportUaInv e = cong transport (uaInvEquiv e) -- notice that transport (ua e) would reduce, thus an alternative definition using EquivJ can give -- refl for the case of idEquiv: -- transportUaInv e = EquivJ (λ _ e → transport (ua (invEquiv e)) ≡ transport (sym (ua e))) refl e isSet-subst : ∀ {ℓ ℓ′} {A : Type ℓ} {B : A → Type ℓ′} → (isSet-A : isSet A) → ∀ {a : A} → (p : a ≡ a) → (x : B a) → subst B p x ≡ x isSet-subst {B = B} isSet-A p x = subst (λ p′ → subst B p′ x ≡ x) (isSet-A _ _ refl p) (substRefl {B = B} x) -- substituting along a composite path is equivalent to substituting twice substComposite : ∀ {ℓ ℓ′} {A : Type ℓ} → (B : A → Type ℓ′) → {x y z : A} (p : x ≡ y) (q : y ≡ z) (u : B x) → subst B (p ∙ q) u ≡ subst B q (subst B p u) substComposite B p q Bx i = transport (cong B (compPath-filler' p q (~ i))) (transport-fillerExt (cong B p) i Bx) -- substitution commutes with morphisms in slices substCommSlice : ∀ {ℓ ℓ′} {A : Type ℓ} → (B C : A → Type ℓ′) → (F : ∀ i → B i → C i) → {x y : A} (p : x ≡ y) (u : B x) → subst C p (F x u) ≡ F y (subst B p u) substCommSlice B C F p Bx i = transport-fillerExt⁻ (cong C p) i (F _ (transport-fillerExt (cong B p) i Bx)) -- transporting over (λ i → B (p i) → C (p i)) divides the transport into -- transports over (λ i → C (p i)) and (λ i → B (p (~ i))) funTypeTransp : ∀ {ℓ ℓ'} {A : Type ℓ} (B C : A → Type ℓ') {x y : A} (p : x ≡ y) (f : B x → C x) → PathP (λ i → B (p i) → C (p i)) f (subst C p ∘ f ∘ subst B (sym p)) funTypeTransp B C {x = x} p f i b = transp (λ j → C (p (j ∧ i))) (~ i) (f (transp (λ j → B (p (i ∧ ~ j))) (~ i) b)) -- transports between loop spaces preserve path composition overPathFunct : ∀ {ℓ} {A : Type ℓ} {x y : A} (p q : x ≡ x) (P : x ≡ y) → transport (λ i → P i ≡ P i) (p ∙ q) ≡ transport (λ i → P i ≡ P i) p ∙ transport (λ i → P i ≡ P i) q overPathFunct p q = J (λ y P → transport (λ i → P i ≡ P i) (p ∙ q) ≡ transport (λ i → P i ≡ P i) p ∙ transport (λ i → P i ≡ P i) q) (transportRefl (p ∙ q) ∙ cong₂ _∙_ (sym (transportRefl p)) (sym (transportRefl q)))
43.853333
113
0.537853
734759d2f968b4a5979b2afdf98a9a67c83b3c33
1,485
agda
Agda
Parametric/Change/Derive.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
10
2015-03-04T06:09:20.000Z
2019-07-19T07:06:59.000Z
Parametric/Change/Derive.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
6
2015-07-01T18:09:31.000Z
2017-05-04T13:53:59.000Z
Parametric/Change/Derive.agda
inc-lc/ilc-agda
39bb081c6f192bdb87bd58b4a89291686d2d7d03
[ "MIT" ]
1
2016-02-18T12:26:44.000Z
2016-02-18T12:26:44.000Z
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- Incrementalization as term-to-term transformation (Fig. 4g). ------------------------------------------------------------------------ import Parametric.Syntax.Type as Type import Parametric.Syntax.Term as Term import Parametric.Change.Type as ChangeType module Parametric.Change.Derive {Base : Type.Structure} (Const : Term.Structure Base) (ΔBase : ChangeType.Structure Base) where open Type.Structure Base open Term.Structure Base Const open ChangeType.Structure Base ΔBase -- Extension point: Incrementalization of primitives. Structure : Set Structure = ∀ {τ} → Const τ → Term ∅ (ΔType τ) module Structure (derive-const : Structure) where fit : ∀ {τ Γ} → Term Γ τ → Term (ΔContext Γ) τ fit = weaken Γ≼ΔΓ -- In the paper, we transform "x" to "dx". Here, we work with -- de Bruijn indices, so we have to manipulate the indices to -- account for a bigger context after transformation. deriveVar : ∀ {τ Γ} → Var Γ τ → Var (ΔContext Γ) (ΔType τ) deriveVar this = this deriveVar (that x) = that (that (deriveVar x)) -- We provide: Incrementalization of arbitrary terms. derive : ∀ {τ Γ} → Term Γ τ → Term (ΔContext Γ) (ΔType τ) derive (var x) = var (deriveVar x) derive (app s t) = app (app (derive s) (fit t)) (derive t) derive (abs t) = abs (abs (derive t)) derive {Γ = Γ} (const c) = weaken (∅≼Γ {ΔContext Γ}) (derive-const c)
33.75
72
0.620202
21dfa592547f27245eae7190bfa5312d343959a1
254
agda
Agda
test/Fail/Issue3314.agda
phadej/agda
2fa8ede09451d43647f918dbfb24ff7b27c52edc
[ "BSD-3-Clause" ]
null
null
null
test/Fail/Issue3314.agda
phadej/agda
2fa8ede09451d43647f918dbfb24ff7b27c52edc
[ "BSD-3-Clause" ]
null
null
null
test/Fail/Issue3314.agda
phadej/agda
2fa8ede09451d43647f918dbfb24ff7b27c52edc
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --cubical #-} module _ where open import Agda.Primitive.Cubical open import Agda.Builtin.Cubical.Path data S1 : Set where base : S1 loop : base ≡ base postulate weird : S1 → I bad : (x : S1) → I bad base = {!!} bad (loop x) = {!!}
14.111111
37
0.625984
1bd9c0893bd04a40d28d086b5ce3398444bef7ab
3,360
agda
Agda
lib/Haskell/Prim/Show.agda
JonathanBrouwer/agda2hs
dcf63cc7ce51a325a97ac58bdd0aeace24c08b15
[ "MIT" ]
55
2020-10-20T13:36:25.000Z
2022-03-26T21:57:56.000Z
lib/Haskell/Prim/Show.agda
SNU-2D/agda2hs
160478a51bc78b0fdab07b968464420439f9fed6
[ "MIT" ]
63
2020-10-22T05:19:27.000Z
2022-02-25T15:47:30.000Z
lib/Haskell/Prim/Show.agda
SNU-2D/agda2hs
160478a51bc78b0fdab07b968464420439f9fed6
[ "MIT" ]
18
2020-10-21T22:19:09.000Z
2022-03-12T11:42:52.000Z
module Haskell.Prim.Show where open import Agda.Builtin.Char open import Agda.Builtin.Nat import Agda.Builtin.String as Str open import Haskell.Prim open import Haskell.Prim.String open import Haskell.Prim.List open import Haskell.Prim.Word open import Haskell.Prim.Double open import Haskell.Prim.Maybe open import Haskell.Prim.Eq open import Haskell.Prim.Tuple open import Haskell.Prim.Ord open import Haskell.Prim.Either open import Haskell.Prim.Integer open import Haskell.Prim.Bool open import Haskell.Prim.Int open import Haskell.Prim.Foldable -------------------------------------------------- -- Show ShowS : Set ShowS = String → String showChar : Char → ShowS showChar = _∷_ showString : String → ShowS showString = _++_ showParen : Bool → ShowS → ShowS showParen false s = s showParen true s = showString "(" ∘ s ∘ showString ")" record Show (a : Set) : Set where field showsPrec : Int → a → ShowS showList : List a → ShowS shows : a → ShowS shows = showsPrec 0 show : a → String show x = shows x "" defaultShowList : (a → ShowS) → List a → ShowS defaultShowList _ [] = showString "[]" defaultShowList shows (x ∷ xs) = showString "[" ∘ foldl (λ s x → s ∘ showString "," ∘ shows x) (shows x) xs ∘ showString "]" open Show ⦃ ... ⦄ public {-# COMPILE AGDA2HS Show existing-class #-} private makeShow : (a → String) → Show a makeShow sh .showsPrec _ = showString ∘ sh makeShow sh .showList = defaultShowList (showString ∘ sh) makeShowsPrec : (Int → a → ShowS) → Show a makeShowsPrec shp .showsPrec = shp makeShowsPrec shp .showList = defaultShowList (shp 0) instance iShowNat : Show Nat iShowNat = makeShow (Str.primStringToList ∘ Str.primShowNat) iShowInteger : Show Integer iShowInteger = makeShow showInteger iShowInt : Show Int iShowInt = makeShow showInt iShowWord : Show Word iShowWord = makeShow showWord iShowDouble : Show Double iShowDouble = makeShow (Str.primStringToList ∘ primShowFloat) iShowBool : Show Bool iShowBool = makeShow λ where false → "False"; true → "True" iShowChar : Show Char iShowChar .showsPrec _ = showString ∘ Str.primStringToList ∘ Str.primShowChar iShowChar .showList = showString ∘ Str.primStringToList ∘ Str.primShowString ∘ Str.primStringFromList iShowList : ⦃ Show a ⦄ → Show (List a) iShowList .showsPrec _ = showList iShowList .showList = defaultShowList showList private showApp₁ : ⦃ Show a ⦄ → Int → String → a → ShowS showApp₁ p tag x = showParen (p > 10) $ showString tag ∘ showString " " ∘ showsPrec 11 x instance iShowMaybe : ⦃ Show a ⦄ → Show (Maybe a) iShowMaybe = makeShowsPrec λ where p Nothing → showString "Nothing" p (Just x) → showApp₁ p "Just" x iShowEither : ⦃ Show a ⦄ → ⦃ Show b ⦄ → Show (Either a b) iShowEither = makeShowsPrec λ where p (Left x) → showApp₁ p "Left" x p (Right y) → showApp₁ p "Right" y private -- Minus the parens showTuple : ∀ {as} → ⦃ All Show as ⦄ → Tuple as → ShowS showTuple [] = showString "" showTuple ⦃ allCons ⦄ (x ∷ []) = shows x showTuple ⦃ allCons ⦄ (x ∷ xs) = shows x ∘ showString "," ∘ showTuple xs instance iShowTuple : ∀ {as} → ⦃ All Show as ⦄ → Show (Tuple as) iShowTuple = makeShowsPrec λ _ → showParen true ∘ showTuple
28.474576
124
0.666369
648531b7b483957c6a7874465d4ede21a7f0cbf7
2,289
agda
Agda
src/Numeric/Nat/Divide.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
111
2015-01-05T11:28:15.000Z
2022-02-12T23:29:26.000Z
src/Numeric/Nat/Divide.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
59
2016-02-09T05:36:44.000Z
2022-01-14T07:32:36.000Z
src/Numeric/Nat/Divide.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
24
2015-03-12T18:03:45.000Z
2021-04-22T06:10:41.000Z
module Numeric.Nat.Divide where open import Prelude open import Control.WellFounded open import Numeric.Nat.Properties open import Numeric.Nat.DivMod open import Tactic.Nat --- Divides predicate --- data _Divides_ (a b : Nat) : Set where factor : ∀ q (eq : q * a ≡ b) → a Divides b pattern factor! q = factor q refl get-factor : ∀ {a b} → a Divides b → Nat get-factor (factor q _) = q dividesToDivMod : ∀ {a b} {{_ : NonZero b}} → b Divides a → DivMod a b dividesToDivMod {b = zero } {{}} dividesToDivMod {b = suc b} (factor q eq) = qr q 0 auto (by eq) mod-divides : ∀ {a b} {{_ : NonZero a}} → a Divides b → b mod a ≡ 0 mod-divides {zero} {{}} mod-divides {suc a} {b} (factor q eq) = rem-unique (b divmod suc a) (dividesToDivMod (factor q eq)) div-divides : ∀ {a b} {{_ : NonZero a}} → a Divides b → (b div a) * a ≡ b div-divides {a} {b} a|b with divmod-sound a b ... | eq rewrite mod-divides a|b = by eq private safediv : Nat → Nat → Nat safediv a 0 = 0 safediv a (suc b) = a div suc b divides-safediv : ∀ {a b} → a Divides b → safediv b a * a ≡ b divides-safediv {zero } (factor! _) = auto divides-safediv {suc a} a|b = div-divides a|b fast-divides : ∀ {a b} → a Divides b → a Divides b fast-divides {a} {b} a|b = factor (safediv b a) (eraseEquality (divides-safediv a|b)) private no-divides-suc-mod : ∀ {a b} q {r} → LessNat (suc r) a → q * a + suc r ≡ b → ¬ (a Divides b) no-divides-suc-mod {zero} _ (diff _ ()) no-divides-suc-mod {suc a} q {r} lt eq (factor q′ eq′) = refute (rem-unique (dividesToDivMod (factor q′ eq′)) (qr q (suc r) lt eq)) no-divides-zero : ∀ {a} → ¬ (0 Divides suc a) no-divides-zero {a} (factor q eq) = refute eq _divides?_ : ∀ a b → Dec (a Divides b) a divides? zero = yes (factor! 0) zero divides? suc b = no no-divides-zero suc a divides? suc b with suc b divmod suc a suc a divides? suc b | qr q zero _ eq = yes (factor q (by eq)) suc a divides? suc b | qr q (suc r) lt eq₁ = no (no-divides-suc-mod q lt eq₁) --- Instances --- instance SmashDivides : ∀ {a b} {{_ : NonZero a}} → Smashed (a Divides b) SmashDivides {0} {{}} smashed {{SmashDivides {a@(suc _)}}} {factor q eq} {factor q₁ refl} = case mul-inj₁ q q₁ (suc _) eq of λ where refl → factor q $≡ smashed
32.7
94
0.615116
033d8650632c431ce06d438397872b50a0036999
478
agda
Agda
Cubical/HITs/SetTruncation/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:29:00.000Z
2022-03-05T00:29:00.000Z
Cubical/HITs/SetTruncation/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/HITs/SetTruncation/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
{- This file contains: - Definition of set truncations -} {-# OPTIONS --safe #-} module Cubical.HITs.SetTruncation.Base where open import Cubical.Core.Primitives open import Cubical.Foundations.Pointed -- set truncation as a higher inductive type: data ∥_∥₂ {ℓ} (A : Type ℓ) : Type ℓ where ∣_∣₂ : A → ∥ A ∥₂ squash₂ : ∀ (x y : ∥ A ∥₂) (p q : x ≡ y) → p ≡ q -- Pointed version ∥_∥₂∙ : ∀ {ℓ} (A : Pointed ℓ) → Pointed ℓ fst ∥ A ∥₂∙ = ∥ fst A ∥₂ snd ∥ A ∥₂∙ = ∣ pt A ∣₂
19.916667
50
0.608787
738c5289fdd242c32bb63899de746e726e5631e1
2,332
agda
Agda
Data/RBTree.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Data/RBTree.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Data/RBTree.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe --postfix-projections #-} open import Prelude open import Relation.Binary module Data.RBTree {e} {E : Type e} {r₁ r₂} (totalOrder : TotalOrder E r₁ r₂) where open import Relation.Binary.Construct.Bounded totalOrder open TotalOrder totalOrder using (_≤?_) data Colour : Type where red black : Colour add-black : Colour → ℕ → ℕ add-black red = λ n → n add-black black = suc private variable n : ℕ data Tree (lb ub : [∙]) : ℕ → Type (e ℓ⊔ r₂) where leaf : lb [≤] ub → Tree lb ub n node : (x : E) → (c : Colour) → Tree lb [ x ] n → Tree [ x ] ub n → Tree lb ub (add-black c n) private variable lb ub : [∙] IsBlack : Tree lb ub n → Type IsBlack (leaf x) = ⊤ IsBlack (node x red tr tr₁) = ⊥ IsBlack (node x black tr tr₁) = ⊤ Valid-rec : Tree lb ub n → Type Valid-rec (leaf x) = ⊤ Valid-rec (node x red xs ys) = IsBlack xs × IsBlack ys × Valid-rec xs × Valid-rec ys Valid-rec (node x black xs ys) = Valid-rec xs × Valid-rec ys Valid : Tree lb ub n → Type Valid tr = IsBlack tr × Valid-rec tr -- insertWithin : (x : E) → -- (lb [≤] [ x ]) → -- ([ x ] [≤] ub) → -- (tr : Tree lb ub n) → -- Valid-rec tr → -- ∃ c Σ (Tree lb ub (add-black c n)) Valid-rec -- insertWithin x lb≤x x≤ub (leaf _) val = red , node x red (leaf lb≤x) (leaf x≤ub) , tt , tt , tt , tt -- insertWithin x lb≤x x≤ub (node y c ls rs) val with x ≤? y -- insertWithin x lb≤x x≤ub (node y red ls rs) val | inl x≤y with insertWithin x lb≤x x≤y ls (fst (snd (snd val))) -- insertWithin x lb≤x x≤ub (node y red ls rs) val | inl x≤y | red , ls′ , val′ = black , node y black ls′ rs , val′ , snd (snd (snd val)) -- insertWithin x lb≤x x≤ub (node y red ls rs) val | inl x≤y | black , ls′ , val′ = {!{!!} , node y {!!} ls′ rs , {!!}!} -- insertWithin x lb≤x x≤ub (node y black ls rs) val | inl x≤y with insertWithin x lb≤x x≤y ls (fst val) -- insertWithin x lb≤x x≤ub (node y black ls rs) val | inl x≤y | res = {!!} -- insertWithin x lb≤x x≤ub (node y c ls rs) val | inr y≤x = {!!} -- -- insertWithin x lb≤x x≤ub (node y ls rs) with x ≤? y -- -- insertWithin x lb≤x x≤ub (node y ls rs) | inl x≤y = node y (insertWithin x lb≤x x≤y ls) rs -- -- insertWithin x lb≤x x≤ub (node y ls rs) | inr y≤x = node y ls (insertWithin x y≤x x≤ub rs)
37.015873
143
0.582762
1ead12ae2237f7f87bf9f5f966716193a23102c9
1,951
agda
Agda
Categories/Monad/Strong.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
Categories/Monad/Strong.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
Categories/Monad/Strong.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} -- Define Strong Monad; use the Wikipedia definition -- https://en.wikipedia.org/wiki/Strong_monad -- At the nLab, https://ncatlab.org/nlab/show/strong+monad -- there are two further definitions; the 2-categorical version is too complicated -- and the Moggi definition is a special case of the one here module Categories.Monad.Strong where open import Level open import Data.Product using (_,_) open import Categories.Category open import Categories.Functor renaming (id to idF) open import Categories.Category.Monoidal open import Categories.Category.Product open import Categories.NaturalTransformation hiding (id) -- open import Categories.NaturalTransformation.NaturalIsomorphism open import Categories.Monad private variable o ℓ e : Level record Strength {C : Category o ℓ e} (V : Monoidal C) (m : Monad C) : Set (o ⊔ ℓ ⊔ e) where open Category C open Monoidal V open Monad m using (F) module M = Monad m open NaturalTransformation M.η using (η) open NaturalTransformation M.μ renaming (η to μ) open Functor F field strengthen : NaturalTransformation (⊗ ∘F (idF ⁂ F)) (F ∘F ⊗) private module t = NaturalTransformation strengthen field -- strengthening with 1 is irrelevant identityˡ : {A : Obj} → F₁ (unitorˡ.from) ∘ t.η (unit , A) ≈ unitorˡ.from -- commutes with unit (of monad) η-comm : {A B : Obj} → t.η (A , B) ∘ (id ⊗₁ η B) ≈ η (A ⊗₀ B) -- strength commutes with multiplication μ-η-comm : {A B : Obj} → μ (A ⊗₀ B) ∘ F₁ (t.η (A , B)) ∘ t.η (A , F₀ B) ≈ t.η (A , B) ∘ id ⊗₁ μ B -- consecutive applications of strength commute (i.e. strength is associative) strength-assoc : {A B C : Obj} → F₁ associator.from ∘ t.η (A ⊗₀ B , C) ≈ t.η (A , B ⊗₀ C) ∘ id ⊗₁ t.η (B , C) ∘ associator.from record StrongMonad {C : Category o ℓ e} (V : Monoidal C) : Set (o ⊔ ℓ ⊔ e) where field m : Monad C strength : Strength V m
34.839286
91
0.672476
355fe32b3e3966c725e6240995fe12e64864fc61
655
agda
Agda
notes/DataBase.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/DataBase.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/DataBase.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- Nils' idea about databases in the Agda mailing list. -- http://thread.gmane.org/gmane.comp.lang.agda/2911/focus=2917 module DataBase where infixr 7 _,_ _,′_ infixr 5 _∧_ data _∧_ (A B : Set) : Set where _,_ : A → B → A ∧ B _,′_ : ∀ {A B} → A → B → A ∧ B _,′_ = _,_ postulate P Q R S : Set h₁ : P → Q h₂ : Q → R h₃ : R → S postulate thm₁ : P → S {-# ATP prove thm₁ h₁ h₂ h₃ #-} db = h₁ ,′ h₂ ,′ h₃ postulate thm₂ : P → S {-# ATP prove thm₂ db #-}
19.848485
63
0.525191
ed3c45de4aabcb7200c9e5e9a66599f987477f90
32
agda
Agda
Categories/Comonad.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
1
2018-12-29T21:51:57.000Z
2018-12-29T21:51:57.000Z
Categories/Comonad.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
null
null
null
Categories/Comonad.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
null
null
null
module Categories.Comonad where
16
31
0.875
52d85cc3c75d37e000c452cb324bffa98fc5f3cf
2,089
agda
Agda
test/Succeed/Issue2713.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2713.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2713.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --instance-search-depth=10 #-} open import Agda.Primitive it : ∀ {a} {A : Set a} {{x : A}} -> A it {{x}} = x infixr 5 _,_ postulate Pair : ∀ {a} (A : Set a) {b} (B : Set b) -> Set (a ⊔ b) _,_ : ∀ {a} {A : Set a} {b} {B : Set b} -> A -> B -> Pair A B data Constraint {a} {A : Set a} (x : A) : Set where mkConstraint : Constraint x record Inner {l a} {A : Set a} (x : A) (_ : Constraint x) (C : Set l) : Set l where field value : C Class : ∀ {l a} {A : Set a} (x : A) (C : Set l) -> Set l Class x C = Inner x mkConstraint C FunctionClass = λ {a} (A : Set a) -> Class A (A -> A) DiagonalClass = λ {i} {I : Set i} {r} (R : I -> I -> Set r) x -> Class (R , x) (R x x) DiagonalFunctionClass = λ {i} {I : Set i} {r} (R : I -> I -> Set r) x -> Class (R , x) (R x x -> R x x) postulate toDiagonalFunctionClass : ∀ {i} {I : Set i} {r} {R : I -> I -> Set r} {{iD : ∀ {x} -> DiagonalClass R x}} -> ∀ {x} -> DiagonalFunctionClass R x DiagonalPropertyType = λ {i r p} {I : Set i} (R : I -> I -> Set r) (P : ∀ x -> R x x -> Set p) -> ∀ x (d : R x x) -> P _ d DiagonalPropertyClass = λ {i r p} {I : Set i} (R : I -> I -> Set r) (P : ∀ x -> R x x -> Set p) (C : FunctionClass I) -> Class (R , P , C) (DiagonalPropertyType R P) diagonalProperty : ∀ {i r p} {I : Set i} {R : I -> I -> Set r} {P : ∀ x -> R x x -> Set p} {{C : FunctionClass I}} {{iDP : DiagonalPropertyClass R P C}} -> DiagonalPropertyType R P diagonalProperty {{iDP = iDP}} = Inner.value iDP -- works-1 works-2 fails : ∀ {r p} {I : Set} {R : I -> I -> Set r} {P : ∀ x -> R x x -> Set p} (C : FunctionClass I) {{iDP : DiagonalPropertyClass R P C}} -> DiagonalPropertyType R P -- works-1 C x d = -- let instance iC = C -- in diagonalProperty _ d -- works-2 C x d = -- let instance iC = C -- iDF = toDiagonalFunctionClass -- in diagonalProperty {{it}} _ d fails C x d = let instance iC = C iDF = toDiagonalFunctionClass in diagonalProperty _ d -- Instance search depth exhausted
22.956044
83
0.520345
cc542e207cef68ddb83a5880208e89db9acaa4bc
649
agda
Agda
core/lib/types/Empty.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
core/lib/types/Empty.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
core/lib/types/Empty.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Basics module lib.types.Empty where Empty-rec : ∀ {i} {A : Type i} → (Empty → A) Empty-rec = Empty-elim ⊥-rec : ∀ {i} {A : Type i} → (⊥ → A) ⊥-rec = Empty-rec Empty-is-prop : is-prop Empty Empty-is-prop = Empty-elim ⊥-is-prop : is-prop ⊥ ⊥-is-prop = Empty-is-prop negated-equiv-Empty : ∀ {i} (A : Type i) → (¬ A) → (Empty ≃ A) negated-equiv-Empty A notA = equiv Empty-elim notA (λ a → Empty-elim {P = λ _ → Empty-elim (notA a) == a} (notA a)) (Empty-elim {P = λ e → notA (Empty-elim e) == e})
27.041667
99
0.494607
ccbf2eb7d86a098b6f9810fa140f27acbf92be38
303
agda
Agda
Syntax/Type.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Syntax/Type.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Syntax/Type.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Syntax.Type where open import Type -- Assures that a value has a certain type type-ascript : ∀{ℓ} → (T : Type{ℓ}) → T → T type-ascript T x = x {-# INLINE type-ascript #-} _:-[_] = type-ascript infixr 0.98 _:-[_] {-# INLINE _:-[_] #-} infixl 10 type-ascript syntax type-ascript T x = x :of: T
18.9375
43
0.633663
72363726ec2492d8778d4ac18b3e139b1b830927
27,022
agda
Agda
Cubical/Homotopy/Group/LES.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Homotopy/Group/LES.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Homotopy/Group/LES.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} {- This file contains: 1. The long exact sequence of loop spaces Ωⁿ (fib f) → Ωⁿ A → Ωⁿ B 2. The long exact sequence of homotopy groups πₙ(fib f) → πₙ A → πₙ B 3. Some lemmas relating the map in the sequence to maps using the other definition of πₙ (maps from Sⁿ) -} module Cubical.Homotopy.Group.LES where open import Cubical.Homotopy.Loopspace open import Cubical.Homotopy.Group.Base open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed open import Cubical.Foundations.Pointed.Homogeneous open import Cubical.Foundations.HLevels open import Cubical.Foundations.GroupoidLaws renaming (assoc to ∙assoc) open import Cubical.Foundations.Path open import Cubical.Foundations.Isomorphism open Iso open import Cubical.Foundations.Equiv open import Cubical.Foundations.Function open import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2 ; map to sMap) open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec) open import Cubical.Data.Sigma open import Cubical.Data.Nat open import Cubical.Algebra.Group open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Group.GroupPath -- We will need an explicitly defined equivalence -- (PathP (λ i → p i ≡ y) q q) ≃ (sym q ∙∙ p ∙∙ q ≡ refl) -- This is given by →∙∙lCancel below module _ {ℓ : Level} {A : Type ℓ} {x y : A} (p : x ≡ x) (q : x ≡ y) where →∙∙lCancel-fill : PathP (λ i → p i ≡ y) q q → I → I → I → A →∙∙lCancel-fill PP k i j = hfill (λ k → λ {(i = i0) → doubleCompPath-filler (sym q) p q k j ; (i = i1) → y ; (j = i0) → q (i ∨ k) ; (j = i1) → q (i ∨ k)}) (inS (PP j i)) k ←∙∙lCancel-fill : sym q ∙∙ p ∙∙ q ≡ refl → I → I → I → A ←∙∙lCancel-fill PP k i j = hfill (λ k → λ {(i = i0) → q (j ∨ ~ k) ; (i = i1) → q (j ∨ ~ k) ; (j = i0) → doubleCompPath-filler (sym q) p q (~ k) i ; (j = i1) → y}) (inS (PP j i)) k →∙∙lCancel : PathP (λ i → p i ≡ y) q q → sym q ∙∙ p ∙∙ q ≡ refl →∙∙lCancel PP i j = →∙∙lCancel-fill PP i1 i j ←∙∙lCancel : sym q ∙∙ p ∙∙ q ≡ refl → PathP (λ i → p i ≡ y) q q ←∙∙lCancel PP i j = ←∙∙lCancel-fill PP i1 i j ←∙∙lCancel→∙∙lCancel : (PP : PathP (λ i → p i ≡ y) q q) → ←∙∙lCancel (→∙∙lCancel PP) ≡ PP ←∙∙lCancel→∙∙lCancel PP r i j = hcomp (λ k → λ {(r = i0) → ←∙∙lCancel-fill (→∙∙lCancel PP) k i j ; (r = i1) → PP i j ; (j = i0) → doubleCompPath-filler (sym q) p q (~ k ∧ ~ r) i ; (j = i1) → y ; (i = i0) → q (j ∨ ~ k ∧ ~ r) ; (i = i1) → q (j ∨ ~ k ∧ ~ r)}) (hcomp (λ k → λ {(r = i0) → →∙∙lCancel-fill PP k j i ; (r = i1) → PP i j ; (j = i0) → doubleCompPath-filler (sym q) p q (k ∧ ~ r) i ; (j = i1) → y ; (i = i0) → q (j ∨ k ∧ ~ r) ; (i = i1) → q (j ∨ k ∧ ~ r)}) (PP i j)) →∙∙lCancel←∙∙lCancel : (PP : sym q ∙∙ p ∙∙ q ≡ refl) → →∙∙lCancel (←∙∙lCancel PP) ≡ PP →∙∙lCancel←∙∙lCancel PP r i j = hcomp (λ k → λ {(r = i0) → →∙∙lCancel-fill (←∙∙lCancel PP) k i j ; (r = i1) → PP i j ; (j = i0) → q (i ∨ k ∨ r) ; (j = i1) → q (i ∨ k ∨ r) ; (i = i0) → doubleCompPath-filler (sym q) p q (r ∨ k) j ; (i = i1) → y}) (hcomp (λ k → λ {(r = i0) → ←∙∙lCancel-fill PP k j i ; (r = i1) → PP i j ; (j = i0) → q (i ∨ r ∨ ~ k) ; (j = i1) → q (i ∨ r ∨ ~ k) ; (i = i0) → doubleCompPath-filler (sym q) p q (r ∨ ~ k) j ; (i = i1) → y}) (PP i j)) ←∙∙lCancel-refl-refl : {ℓ : Level} {A : Type ℓ} {x : A} (p : refl {x = x} ≡ refl) → ←∙∙lCancel {x = x} {y = x} refl refl (sym (rUnit refl) ∙ p) ≡ flipSquare p ←∙∙lCancel-refl-refl p k i j = hcomp (λ r → λ { (i = i0) → p i0 i0 ; (i = i1) → p i0 i0 ; (j = i0) → rUnit (λ _ → p i0 i0) (~ r) i ; (j = i1) → p i0 i0 ; (k = i0) → ←∙∙lCancel-fill refl refl (sym (rUnit refl) ∙ p) r i j ; (k = i1) → compPath-filler' (sym (rUnit refl)) p (~ r) j i}) ((sym (rUnit refl) ∙ p) j i) {- We need an iso Ω(fib f) ≅ fib(Ω f) -} ΩFibreIso : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) → Iso (typ (Ω (fiber (fst f) (pt B) , (pt A) , snd f))) (fiber (Ω→ f .fst) refl) fun (ΩFibreIso f) p = (cong fst p) , →∙∙lCancel (cong (fst f) (cong fst p)) (snd f) (cong snd p) fst (inv (ΩFibreIso f) (p , q) i) = p i snd (inv (ΩFibreIso f) (p , q) i) = ←∙∙lCancel (cong (fst f) p) (snd f) q i rightInv (ΩFibreIso f) (p , q) = ΣPathP (refl , →∙∙lCancel←∙∙lCancel _ _ q) fst (leftInv (ΩFibreIso f) p i j) = fst (p j) snd (leftInv (ΩFibreIso f) p i j) k = ←∙∙lCancel→∙∙lCancel _ _ (cong snd p) i j k {- Some homomorphism properties of the above iso -} ΩFibreIsopres∙fst : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) → (p q : (typ (Ω (fiber (fst f) (pt B) , (pt A) , snd f)))) → fst (fun (ΩFibreIso f) (p ∙ q)) ≡ fst (fun (ΩFibreIso f) p) ∙ fst (fun (ΩFibreIso f) q) ΩFibreIsopres∙fst f p q = cong-∙ fst p q ΩFibreIso⁻pres∙snd : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) (p q : typ (Ω (Ω B))) → inv (ΩFibreIso f) (refl , (Ω→ f .snd ∙ p ∙ q)) ≡ inv (ΩFibreIso f) (refl , Ω→ f .snd ∙ p) ∙ inv (ΩFibreIso f) (refl , Ω→ f .snd ∙ q) ΩFibreIso⁻pres∙snd {A = A} {B = B}= →∙J (λ b₀ f → (p q : typ (Ω (Ω (fst B , b₀)))) → inv (ΩFibreIso f) (refl , (Ω→ f .snd ∙ p ∙ q)) ≡ inv (ΩFibreIso f) (refl , Ω→ f .snd ∙ p) ∙ inv (ΩFibreIso f) (refl , Ω→ f .snd ∙ q)) ind where ind : (f : typ A → typ B) (p q : typ (Ω (Ω (fst B , f (pt A))))) → inv (ΩFibreIso (f , refl)) (refl , (sym (rUnit refl) ∙ p ∙ q)) ≡ inv (ΩFibreIso (f , refl)) (refl , sym (rUnit refl) ∙ p) ∙ inv (ΩFibreIso (f , refl)) (refl , sym (rUnit refl) ∙ q) fst (ind f p q i j) = (rUnit refl ∙ sym (cong-∙ fst (inv (ΩFibreIso (f , refl)) (refl , sym (rUnit refl) ∙ p)) (inv (ΩFibreIso (f , refl)) (refl , sym (rUnit refl) ∙ q)))) i j snd (ind f p q i j) k = hcomp (λ r → λ {(i = i0) → ←∙∙lCancel-refl-refl (p ∙ q) (~ r) j k -- ; (i = i1) → snd (compPath-filler (inv (ΩFibreIso (f , refl)) (refl , sym (rUnit refl) ∙ p)) (inv (ΩFibreIso (f , refl)) (refl , sym (rUnit refl) ∙ q)) r j) k ; (j = i0) → f (snd A) ; (j = i1) → snd (inv (ΩFibreIso (f , refl)) (refl , sym (rUnit refl) ∙ q) (r ∨ ~ i)) k ; (k = i0) → main r i j ; (k = i1) → f (snd A)}) (hcomp (λ r → λ {(i = i0) → (p ∙ q) k j ; (i = i1) → ←∙∙lCancel-refl-refl p (~ r) j k ; (j = i0) → f (snd A) ; (j = i1) → ←∙∙lCancel-refl-refl q (~ r) (~ i) k ; (k = i0) → f (pt A) ; (k = i1) → f (snd A)}) (hcomp (λ r → λ {(i = i0) → (compPath-filler' p q r) k j ; (i = i1) → p (k ∨ ~ r) j ; (j = i0) → f (snd A) ; (j = i1) → q k (~ i) ; (k = i0) → p (k ∨ ~ r) j ; (k = i1) → f (snd A)}) (q k (~ i ∧ j)))) where P = (inv (ΩFibreIso (f , refl)) (refl , sym (rUnit refl) ∙ p)) Q = (inv (ΩFibreIso (f , refl)) (refl , sym (rUnit refl) ∙ q)) main : I → I → I → fst B main r i j = hcomp (λ k → λ {(i = i0) → f (snd A) ; (i = i1) → f (fst (compPath-filler P Q (r ∨ ~ k) j)) ; (j = i0) → f (snd A) ; (j = i1) → f (snd A) ; (r = i0) → f (fst (compPath-filler P Q (i ∧ ~ k) j)) ; (r = i1) → f ((rUnit refl ∙ sym (cong-∙ fst P Q)) i j)}) (hcomp (λ k → λ {(i = i0) → f (rUnit (λ _ → pt A) (~ k ∧ r) j) ; (i = i1) → f (fst ((P ∙ Q) j)) ; (j = i0) → f (snd A) ; (j = i1) → f (snd A) ; (r = i0) → f (fst (compPath-filler P Q i j)) ; (r = i1) → f ((compPath-filler' (rUnit refl) (sym (cong-∙ fst P Q)) k) i j)}) (hcomp (λ k → λ {(i = i0) → f (rUnit (λ _ → pt A) (k ∧ r) j) ; (i = i1) → f (fst (compPath-filler P Q k j)) ; (j = i0) → f (snd A) ; (j = i1) → f (snd A) ; (r = i0) → f (fst (compPath-filler P Q (i ∧ k) j)) ; (r = i1) → f ((cong-∙∙-filler fst refl P Q) k (~ i) j)}) (f (snd A)))) ΩFibreIso∙ : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) → Iso.fun (ΩFibreIso f) refl ≡ (refl , (∙∙lCancel (snd f))) ΩFibreIso∙ {A = A} {B = B} = →∙J (λ b f → Iso.fun (ΩFibreIso f) refl ≡ (refl , (∙∙lCancel (snd f)))) λ f → ΣPathP (refl , help f) where help : (f : fst A → fst B) → →∙∙lCancel (λ i → f (snd A)) refl (λ i → refl) ≡ ∙∙lCancel refl help f i j r = hcomp (λ k → λ {(i = i0) → →∙∙lCancel-fill (λ _ → f (snd A)) refl refl k j r ; (i = i1) → ∙∙lCancel-fill (λ _ → f (snd A)) j r k ; (j = i0) → rUnit (λ _ → f (snd A)) k r ; (j = i1) → f (snd A) ; (r = i1) → f (snd A) ; (r = i0) → f (snd A)}) (f (snd A)) ΩFibreIso⁻∙ : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) → Iso.inv (ΩFibreIso f) (refl , (∙∙lCancel (snd f))) ≡ refl ΩFibreIso⁻∙ f = cong (Iso.inv (ΩFibreIso f)) (sym (ΩFibreIso∙ f)) ∙ leftInv (ΩFibreIso f) refl {- Ωⁿ (fib f) ≃∙ fib (Ωⁿ f) -} Ω^Fibre≃∙ : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B) → ((Ω^ n) (fiber (fst f) (pt B) , (pt A) , snd f)) ≃∙ ((fiber (Ω^→ n f .fst) (snd ((Ω^ n) B))) , (snd ((Ω^ n) A)) , (Ω^→ n f .snd)) Ω^Fibre≃∙ zero f = (idEquiv _) , refl Ω^Fibre≃∙ (suc n) f = compEquiv∙ (Ω≃∙ (Ω^Fibre≃∙ n f)) ((isoToEquiv (ΩFibreIso (Ω^→ n f))) , ΩFibreIso∙ (Ω^→ n f)) {- Its inverse iso directly defined -} Ω^Fibre≃∙⁻ : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B) → ((fiber (Ω^→ n f .fst) (snd ((Ω^ n) B))) , (snd ((Ω^ n) A)) , (Ω^→ n f .snd)) ≃∙ ((Ω^ n) (fiber (fst f) (pt B) , (pt A) , snd f)) Ω^Fibre≃∙⁻ zero f = (idEquiv _) , refl Ω^Fibre≃∙⁻ (suc n) f = compEquiv∙ ((isoToEquiv (invIso (ΩFibreIso (Ω^→ n f)))) , (ΩFibreIso⁻∙ (Ω^→ n f))) (Ω≃∙ (Ω^Fibre≃∙⁻ n f)) isHomogeneousΩ^→fib : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B) → isHomogeneous ((fiber (Ω^→ (suc n) f .fst) (snd ((Ω^ (suc n)) B))) , (snd ((Ω^ (suc n)) A)) , (Ω^→ (suc n) f .snd)) isHomogeneousΩ^→fib n f = subst isHomogeneous (ua∙ ((fst (Ω^Fibre≃∙ (suc n) f))) (snd (Ω^Fibre≃∙ (suc n) f))) (isHomogeneousPath _ _) Ω^Fibre≃∙sect : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B) → (≃∙map (Ω^Fibre≃∙⁻ n f) ∘∙ ≃∙map (Ω^Fibre≃∙ n f)) ≡ idfun∙ _ Ω^Fibre≃∙sect zero f = ΣPathP (refl , (sym (rUnit refl))) Ω^Fibre≃∙sect (suc n) f = →∙Homogeneous≡ (isHomogeneousPath _ _) (funExt λ p → cong (fst (fst (Ω≃∙ (Ω^Fibre≃∙⁻ n f)))) (leftInv (ΩFibreIso (Ω^→ n f)) ((fst (fst (Ω≃∙ (Ω^Fibre≃∙ n f))) p))) ∙ sym (Ω→∘ (≃∙map (Ω^Fibre≃∙⁻ n f)) (≃∙map (Ω^Fibre≃∙ n f)) p) ∙ (λ i → (Ω→ (Ω^Fibre≃∙sect n f i)) .fst p) ∙ sym (rUnit p)) Ω^Fibre≃∙retr : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B) → (≃∙map (Ω^Fibre≃∙ n f) ∘∙ ≃∙map (Ω^Fibre≃∙⁻ n f)) ≡ idfun∙ _ Ω^Fibre≃∙retr zero f = ΣPathP (refl , (sym (rUnit refl))) Ω^Fibre≃∙retr (suc n) f = →∙Homogeneous≡ (isHomogeneousΩ^→fib n f) (funExt (λ p → cong (fun (ΩFibreIso (Ω^→ n f))) ((sym (Ω→∘ (≃∙map (Ω^Fibre≃∙ n f)) (≃∙map (Ω^Fibre≃∙⁻ n f)) (inv (ΩFibreIso (Ω^→ n f)) p))) ∙ (λ i → Ω→ (Ω^Fibre≃∙retr n f i) .fst (inv (ΩFibreIso (Ω^→ n f)) p)) ∙ sym (rUnit (inv (ΩFibreIso (Ω^→ n f)) p))) ∙ rightInv (ΩFibreIso (Ω^→ n f)) p)) Ω^Fibre≃∙' : {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B) → ((Ω^ n) (fiber (fst f) (pt B) , (pt A) , snd f)) ≃∙ ((fiber (Ω^→ n f .fst) (snd ((Ω^ n) B))) , (snd ((Ω^ n) A)) , (Ω^→ n f .snd)) Ω^Fibre≃∙' zero f = idEquiv _ , refl Ω^Fibre≃∙' (suc zero) f = (isoToEquiv (ΩFibreIso (Ω^→ zero f))) , ΩFibreIso∙ (Ω^→ zero f) Ω^Fibre≃∙' (suc (suc n)) f = compEquiv∙ (Ω≃∙ (Ω^Fibre≃∙ (suc n) f)) ((isoToEquiv (ΩFibreIso (Ω^→ (suc n) f))) , ΩFibreIso∙ (Ω^→ (suc n) f)) -- The long exact sequence of loop spaces. module ΩLES {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) where {- Fibre of f -} fibf : Pointed _ fibf = fiber (fst f) (pt B) , (pt A , snd f) {- Fibre of Ωⁿ f -} fibΩ^f : (n : ℕ) → Pointed _ fst (fibΩ^f n) = fiber (Ω^→ n f .fst) (snd ((Ω^ n) B)) snd (fibΩ^f n) = (snd ((Ω^ n) A)) , (Ω^→ n f .snd) Ω^fibf : (n : ℕ) → Pointed _ Ω^fibf n = (Ω^ n) fibf {- Helper function fib (Ωⁿ f) → Ωⁿ A -} fibΩ^f→A : (n : ℕ) → fibΩ^f n →∙ (Ω^ n) A fst (fibΩ^f→A n) = fst snd (fibΩ^f→A n) = refl {- The main function Ωⁿ(fib f) → Ωⁿ A, which is just the composition Ωⁿ(fib f) ≃ fib (Ωⁿ f) → Ωⁿ A, where the last function is fibΩ^f→A. Hence most proofs will concern fibΩ^f→A, since it is easier to work with. -} Ω^fibf→A : (n : ℕ) → Ω^fibf n →∙ (Ω^ n) A Ω^fibf→A n = fibΩ^f→A n ∘∙ ≃∙map (Ω^Fibre≃∙ n f) {- The function preserves path composition -} Ω^fibf→A-pres∙ : (n : ℕ) → (p q : Ω^fibf (suc n) .fst) → Ω^fibf→A (suc n) .fst (p ∙ q) ≡ Ω^fibf→A (suc n) .fst p ∙ Ω^fibf→A (suc n) .fst q Ω^fibf→A-pres∙ n p q = cong (fst (fibΩ^f→A (suc n))) (cong (fun (ΩFibreIso (Ω^→ n f))) (Ω→pres∙ (≃∙map (Ω^Fibre≃∙ n f)) p q)) ∙ ΩFibreIsopres∙fst (Ω^→ n f) (fst (Ω→ (≃∙map (Ω^Fibre≃∙ n f))) p) (fst (Ω→ (≃∙map (Ω^Fibre≃∙ n f))) q) {- The function Ωⁿ A → Ωⁿ B -} A→B : (n : ℕ) → (Ω^ n) A →∙ (Ω^ n) B A→B n = Ω^→ n f {- It preserves path composition -} A→B-pres∙ : (n : ℕ) → (p q : typ ((Ω^ (suc n)) A)) → fst (A→B (suc n)) (p ∙ q) ≡ fst (A→B (suc n)) p ∙ fst (A→B (suc n)) q A→B-pres∙ n p q = Ω^→pres∙ f n p q {- Helper function Ωⁿ⁺¹ B → fib (Ωⁿ f) -} ΩB→fibΩ^f : (n : ℕ) → ((Ω^ (suc n)) B) →∙ fibΩ^f n fst (ΩB→fibΩ^f n) x = (snd ((Ω^ n) A)) , (Ω^→ n f .snd ∙ x) snd (ΩB→fibΩ^f n) = ΣPathP (refl , (sym (rUnit _))) {- The main function Ωⁿ⁺¹ B → Ωⁿ (fib f), factoring through the above function -} ΩB→Ω^fibf : (n : ℕ) → (Ω^ (suc n)) B →∙ Ω^fibf n ΩB→Ω^fibf n = (≃∙map (Ω^Fibre≃∙⁻ n f)) ∘∙ ΩB→fibΩ^f n {- It preserves path composition -} ΩB→Ω^fibf-pres∙ : (n : ℕ) → (p q : typ ((Ω^ (2 + n)) B)) → fst (ΩB→Ω^fibf (suc n)) (p ∙ q) ≡ fst (ΩB→Ω^fibf (suc n)) p ∙ fst (ΩB→Ω^fibf (suc n)) q ΩB→Ω^fibf-pres∙ n p q = cong (fst (fst (Ω^Fibre≃∙⁻ (suc n) f))) refl ∙ cong (fst (fst (Ω≃∙ (Ω^Fibre≃∙⁻ n f)))) (cong (fun (invIso (ΩFibreIso (Ω^→ n f)))) (λ _ → snd ((Ω^ suc n) A) , Ω^→ (suc n) f .snd ∙ p ∙ q)) ∙ cong (fst (fst (Ω≃∙ (Ω^Fibre≃∙⁻ n f)))) (ΩFibreIso⁻pres∙snd (Ω^→ n f) p q) ∙ Ω≃∙pres∙ (Ω^Fibre≃∙⁻ n f) (inv (ΩFibreIso (Ω^→ n f)) (refl , Ω→ (Ω^→ n f) .snd ∙ p)) (inv (ΩFibreIso (Ω^→ n f)) (refl , Ω→ (Ω^→ n f) .snd ∙ q)) {- Hence we have our sequence ... → Ωⁿ⁺¹B → Ωⁿ(fib f) → Ωⁿ A → Ωⁿ B → ... (*) We first prove the exactness properties for the helper functions ΩB→fibΩ^f and fibΩ^f→A, and then deduce exactness of the whole sequence by noting that the functions in (*) are just ΩB→fibΩ^f, fibΩ^f→A but composed with equivalences -} private Im-fibΩ^f→A⊂Ker-A→B : (n : ℕ) (x : _) → isInIm∙ (fibΩ^f→A n) x → isInKer∙ (A→B n) x Im-fibΩ^f→A⊂Ker-A→B n x = uncurry λ p → J (λ x _ → isInKer∙ (A→B n) x) (snd p) Ker-fibΩ^f→A⊂Im-ΩB→fibΩ^f : (n : ℕ) (x : _) → isInKer∙ (fibΩ^f→A n) x → isInIm∙ (ΩB→fibΩ^f n) x Ker-fibΩ^f→A⊂Im-ΩB→fibΩ^f n x ker = (sym (Ω^→ n f .snd) ∙ cong (Ω^→ n f .fst) (sym ker) ∙ snd x) , ΣPathP ((sym ker) , ((∙assoc (Ω^→ n f .snd) (sym (Ω^→ n f .snd)) (sym (cong (Ω^→ n f .fst) ker) ∙ snd x) ∙∙ cong (_∙ (sym (cong (Ω^→ n f .fst) ker) ∙ snd x)) (rCancel (Ω^→ n f .snd)) ∙∙ sym (lUnit (sym (cong (Ω^→ n f .fst) ker) ∙ snd x))) ◁ (λ i j → compPath-filler' (cong (Ω^→ n f .fst) (sym ker)) (snd x) (~ i) j))) Im-A→B⊂Ker-ΩB→fibΩ^f : (n : ℕ) (x : fst (((Ω^ (suc n)) B))) → isInIm∙ (A→B (suc n)) x → isInKer∙ (ΩB→fibΩ^f n) x Im-A→B⊂Ker-ΩB→fibΩ^f n x = uncurry λ p → J (λ x _ → isInKer∙ (ΩB→fibΩ^f n) x) (ΣPathP (p , (((λ i → (λ j → Ω^→ n f .snd (j ∧ ~ i)) ∙ ((λ j → Ω^→ n f .snd (~ j ∧ ~ i)) ∙∙ cong (Ω^→ n f .fst) p ∙∙ Ω^→ n f .snd)) ∙ sym (lUnit (cong (Ω^→ n f .fst) p ∙ Ω^→ n f .snd))) ◁ λ i j → compPath-filler' (cong (Ω^→ n f .fst) p) (Ω^→ n f .snd) (~ i) j))) Ker-ΩB→fibΩ^f⊂Im-A→B : (n : ℕ) (x : fst (((Ω^ (suc n)) B))) → isInKer∙ (ΩB→fibΩ^f n) x → isInIm∙ (A→B (suc n)) x fst (Ker-ΩB→fibΩ^f⊂Im-A→B n x inker) = cong fst inker snd (Ker-ΩB→fibΩ^f⊂Im-A→B n x inker) = lem where lem : fst (A→B (suc n)) (λ i → fst (inker i)) ≡ x lem i j = hcomp (λ k → λ { (i = i0) → doubleCompPath-filler (sym (snd (Ω^→ n f))) ((λ i → Ω^→ n f .fst (fst (inker i)))) (snd (Ω^→ n f)) k j ; (i = i1) → compPath-filler' (Ω^→ n f .snd) x (~ k) j ; (j = i0) → snd (Ω^→ n f) k ; (j = i1) → snd (Ω^→ n f) (k ∨ i)}) (hcomp (λ k → λ { (i = i0) → (snd (inker j)) (~ k) ; (i = i1) → ((Ω^→ n f .snd) ∙ x) (j ∨ ~ k) ; (j = i0) → ((Ω^→ n f .snd) ∙ x) (~ k) ; (j = i1) → snd (Ω^→ n f) (i ∨ ~ k)}) (snd ((Ω^ n) B))) {- Finally, we get exactness of the sequence we are interested in -} Im-Ω^fibf→A⊂Ker-A→B : (n : ℕ) (x : _) → isInIm∙ (Ω^fibf→A n) x → isInKer∙ (A→B n) x Im-Ω^fibf→A⊂Ker-A→B n x x₁ = Im-fibΩ^f→A⊂Ker-A→B n x (((fst (fst (Ω^Fibre≃∙ n f))) (fst x₁)) , snd x₁) Ker-A→B⊂Im-Ω^fibf→A : (n : ℕ) (x : _) → isInKer∙ (A→B n) x → isInIm∙ (Ω^fibf→A n) x Ker-A→B⊂Im-Ω^fibf→A n x ker = invEq (fst (Ω^Fibre≃∙ n f)) (x , ker) , (cong fst (secEq (fst (Ω^Fibre≃∙ n f)) (x , ker))) Ker-Ω^fibf→A⊂Im-ΩB→Ω^fibf : (n : ℕ) (x : _) → isInKer∙ (Ω^fibf→A n) x → isInIm∙ (ΩB→Ω^fibf n) x Ker-Ω^fibf→A⊂Im-ΩB→Ω^fibf n x p = fst r , cong (fst ((fst (Ω^Fibre≃∙⁻ n f)))) (snd r) ∙ funExt⁻ (cong fst (Ω^Fibre≃∙sect n f)) x where r : isInIm∙ (ΩB→fibΩ^f n) (fst (fst (Ω^Fibre≃∙ n f)) x) r = Ker-fibΩ^f→A⊂Im-ΩB→fibΩ^f n (fst (fst (Ω^Fibre≃∙ n f)) x) p Im-ΩB→Ω^fibf⊂Ker-Ω^fibf→A : (n : ℕ) (x : _) → isInIm∙ (ΩB→Ω^fibf n) x → isInKer∙ (Ω^fibf→A n) x Im-ΩB→Ω^fibf⊂Ker-Ω^fibf→A n x = uncurry λ p → J (λ x _ → isInKer∙ (Ω^fibf→A n) x) (cong (fst (fibΩ^f→A n)) (funExt⁻ (cong fst (Ω^Fibre≃∙retr n f)) _)) Im-A→B⊂Ker-ΩB→Ω^fibf : (n : ℕ) (x : fst (((Ω^ (suc n)) B))) → isInIm∙ (A→B (suc n)) x → isInKer∙ (ΩB→Ω^fibf n) x Im-A→B⊂Ker-ΩB→Ω^fibf n x p = cong (fst ((fst (Ω^Fibre≃∙⁻ n f)))) (Im-A→B⊂Ker-ΩB→fibΩ^f n x p) ∙ snd (Ω^Fibre≃∙⁻ n f) Ker-ΩB→Ω^fibf⊂Im-A→B : (n : ℕ) (x : fst (((Ω^ (suc n)) B))) → isInKer∙ (ΩB→Ω^fibf n) x → isInIm∙ (A→B (suc n)) x Ker-ΩB→Ω^fibf⊂Im-A→B n x p = Ker-ΩB→fibΩ^f⊂Im-A→B n x (funExt⁻ (cong fst (sym (Ω^Fibre≃∙retr n f))) (ΩB→fibΩ^f n .fst x) ∙ cong (fst (fst (Ω^Fibre≃∙ n f))) p ∙ snd (Ω^Fibre≃∙ n f)) {- Some useful lemmas for converting the above sequence a a sequence of homotopy groups -} module setTruncLemmas {ℓ ℓ' ℓ'' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} {C : Pointed ℓ''} (n m l : ℕ) (f : (Ω ((Ω^ n) A)) →∙ (Ω ((Ω^ m) B))) (g : (Ω ((Ω^ m) B)) →∙ (Ω ((Ω^ l) C))) (e₁ : IsGroupHom (snd (πGr n A)) (sMap (fst f)) (snd (πGr m B))) (e₂ : IsGroupHom (snd (πGr m B)) (sMap (fst g)) (snd (πGr l C))) where ker⊂im : ((x : typ (Ω ((Ω^ m) B))) → isInKer∙ g x → isInIm∙ f x) → (x : π (suc m) B) → isInKer (_ , e₂) x → isInIm (_ , e₁) x ker⊂im ind = sElim (λ _ → isSetΠ λ _ → isProp→isSet squash₁) λ p ker → pRec squash₁ (λ ker∙ → ∣ ∣ ind p ker∙ .fst ∣₂ , cong ∣_∣₂ (ind p ker∙ .snd) ∣₁ ) (fun PathIdTrunc₀Iso ker) im⊂ker : ((x : typ (Ω ((Ω^ m) B))) → isInIm∙ f x → isInKer∙ g x) → (x : π (suc m) B) → isInIm (_ , e₁) x → isInKer (_ , e₂) x im⊂ker ind = sElim (λ _ → isSetΠ λ _ → isSetPathImplicit) λ p → pRec (squash₂ _ _) (uncurry (sElim (λ _ → isSetΠ λ _ → isSetPathImplicit) λ a q → pRec (squash₂ _ _) (λ q → cong ∣_∣₂ (ind p (a , q))) (fun PathIdTrunc₀Iso q))) {- The long exact sequence of homotopy groups -} module πLES {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} (f : A →∙ B) where module Ωs = ΩLES f open Ωs renaming (A→B to A→B') fib = fibf fib→A : (n : ℕ) → GroupHom (πGr n fib) (πGr n A) fst (fib→A n) = sMap (fst (Ω^fibf→A (suc n))) snd (fib→A n) = makeIsGroupHom (sElim2 (λ _ _ → isSetPathImplicit) λ p q → cong ∣_∣₂ (Ω^fibf→A-pres∙ n p q)) A→B : (n : ℕ) → GroupHom (πGr n A) (πGr n B) fst (A→B n) = sMap (fst (A→B' (suc n))) snd (A→B n) = makeIsGroupHom (sElim2 (λ _ _ → isSetPathImplicit) λ g h → cong ∣_∣₂ (Ω^→pres∙ f n g h)) B→fib : (n : ℕ) → GroupHom (πGr (suc n) B) (πGr n fib) fst (B→fib n) = sMap (fst (ΩB→Ω^fibf (suc n))) snd (B→fib n) = makeIsGroupHom (sElim2 (λ _ _ → isSetPathImplicit) λ p q → cong ∣_∣₂ (ΩB→Ω^fibf-pres∙ n p q)) Ker-A→B⊂Im-fib→A : (n : ℕ) (x : π (suc n) A) → isInKer (A→B n) x → isInIm (fib→A n) x Ker-A→B⊂Im-fib→A n = setTruncLemmas.ker⊂im n n n (Ω^fibf→A (suc n)) (A→B' (suc n)) (snd (fib→A n)) (snd (A→B n)) (Ker-A→B⊂Im-Ω^fibf→A (suc n)) Im-fib→A⊂Ker-A→B : (n : ℕ) (x : π (suc n) A) → isInIm (fib→A n) x → isInKer (A→B n) x Im-fib→A⊂Ker-A→B n = setTruncLemmas.im⊂ker n n n (Ω^fibf→A (suc n)) (A→B' (suc n)) (snd (fib→A n)) (snd (A→B n)) (Im-Ω^fibf→A⊂Ker-A→B (suc n)) Ker-fib→A⊂Im-B→fib : (n : ℕ) (x : π (suc n) fib) → isInKer (fib→A n) x → isInIm (B→fib n) x Ker-fib→A⊂Im-B→fib n = setTruncLemmas.ker⊂im (suc n) n n (ΩB→Ω^fibf (suc n)) (Ω^fibf→A (suc n)) (snd (B→fib n)) (snd (fib→A n)) (Ker-Ω^fibf→A⊂Im-ΩB→Ω^fibf (suc n)) Im-B→fib⊂Ker-fib→A : (n : ℕ) (x : π (suc n) fib) → isInIm (B→fib n) x → isInKer (fib→A n) x Im-B→fib⊂Ker-fib→A n = setTruncLemmas.im⊂ker (suc n) n n (ΩB→Ω^fibf (suc n)) (Ω^fibf→A (suc n)) (snd (B→fib n)) (snd (fib→A n)) (Im-ΩB→Ω^fibf⊂Ker-Ω^fibf→A (suc n)) Im-A→B⊂Ker-B→fib : (n : ℕ) (x : π (suc (suc n)) B) → isInIm (A→B (suc n)) x → isInKer (B→fib n) x Im-A→B⊂Ker-B→fib n = setTruncLemmas.im⊂ker (suc n) (suc n) n (A→B' (suc (suc n))) (ΩB→Ω^fibf (suc n)) (snd (A→B (suc n))) (snd (B→fib n)) (Im-A→B⊂Ker-ΩB→Ω^fibf (suc n)) Ker-B→fib⊂Im-A→B : (n : ℕ) (x : π (suc (suc n)) B) → isInKer (B→fib n) x → isInIm (A→B (suc n)) x Ker-B→fib⊂Im-A→B n = setTruncLemmas.ker⊂im (suc n) (suc n) n (A→B' (suc (suc n))) (ΩB→Ω^fibf (suc n)) (snd (A→B (suc n))) (snd (B→fib n)) (Ker-ΩB→Ω^fibf⊂Im-A→B (suc n)) {- We prove that the map Ωⁿ(fib f) → Ωⁿ A indeed is just the map Ωⁿ fst -} private Ω^fibf→A-ind : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B) → ΩLES.Ω^fibf→A f (suc n) ≡ Ω→ (ΩLES.Ω^fibf→A f n) Ω^fibf→A-ind {A = A} {B = B} n f = (λ _ → πLES.Ωs.fibΩ^f→A f (suc n) ∘∙ ≃∙map (Ω^Fibre≃∙ (suc n) f)) ∙ →∙Homogeneous≡ (isHomogeneousPath _ _) (funExt λ p → (λ j → cong fst (Ω→ (≃∙map (Ω^Fibre≃∙ n f)) .fst p)) ∙ rUnit ((λ i → fst (Ω→ (≃∙map (Ω^Fibre≃∙ n f)) .fst p i))) ∙ sym (Ω→∘ (πLES.Ωs.fibΩ^f→A f n) (≃∙map (Ω^Fibre≃∙ n f)) p)) Ω^fibf→A≡ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B) → ΩLES.Ω^fibf→A f n ≡ Ω^→ n (fst , refl) Ω^fibf→A≡ zero f = ΣPathP (refl , (sym (lUnit refl))) Ω^fibf→A≡ (suc n) f = Ω^fibf→A-ind n f ∙ cong Ω→ (Ω^fibf→A≡ n f) {- We now get a nice characterisation of the functions in the induced LES of homotopy groups defined using (Sⁿ →∙ A) -} π∘∙A→B-PathP : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B) → PathP (λ i → GroupHomπ≅π'PathP A B n i) (πLES.A→B f n) (π'∘∙Hom n f) π∘∙A→B-PathP n f = toPathP (Σ≡Prop (λ _ → isPropIsGroupHom _ _) (π'∘∙Hom'≡π'∘∙fun n f)) π∘∙fib→A-PathP : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B) → PathP (λ i → GroupHomπ≅π'PathP (ΩLES.fibf f) A n i) (πLES.fib→A f n) (π'∘∙Hom n (fst , refl)) π∘∙fib→A-PathP {A = A} {B = B} n f = toPathP (Σ≡Prop (λ _ → isPropIsGroupHom _ _) (cong (transport (λ i → (fst (GroupPath _ _) (GroupIso→GroupEquiv (π'Gr≅πGr n (ΩLES.fibf f))) (~ i)) .fst → (fst (GroupPath _ _) (GroupIso→GroupEquiv (π'Gr≅πGr n A)) (~ i)) .fst)) lem ∙ π'∘∙Hom'≡π'∘∙fun n (fst , refl))) where lem : πLES.fib→A f n .fst ≡ sMap (Ω^→ (suc n) (fst , refl) .fst) lem = cong sMap (cong fst (Ω^fibf→A≡ (suc n) f))
40.391629
80
0.443935
116cd6dc6f0ab1f471536f436245e03bff6cb612
4,824
agda
Agda
Relational Logic/RL.agda
andyfreeyy/agda_and_math
76b9ef64626b6d3bbb7ace4f1a16aeb447c54328
[ "MIT" ]
2
2020-03-23T09:01:42.000Z
2020-05-24T10:56:36.000Z
Relational Logic/RL.agda
andyfreeyy/agda_and_math
76b9ef64626b6d3bbb7ace4f1a16aeb447c54328
[ "MIT" ]
null
null
null
Relational Logic/RL.agda
andyfreeyy/agda_and_math
76b9ef64626b6d3bbb7ace4f1a16aeb447c54328
[ "MIT" ]
null
null
null
-- --------------------------------- -- this is the agda file implementing my own work on logic, viz. a relational -- framework for logic. -- These codes have been checked by Agda 2.6.0 -- --------------------------------- module RL where -- this file use agda standard library open import Agda.Builtin.Equality open import Relation.Nullary open import Data.Empty open import Data.Product -- --------------------------------- -- Logical Frame -- --------------------------------- record Frame : Set₁ where field Φ : Set -- the set of language bot : Φ -- contradiction top : Φ -- validity _⇌_ : Φ → Φ → Set -- ⇌ is interpreted as consistency relation symm : ∀ (x y : Φ) → x ⇌ y → y ⇌ x -- ⇌ is symmetric alre : ∀ (x : Φ) → ¬ (x ≡ bot) → x ⇌ x -- except for ⊥, ⇌ is reflexive ⊥-contra : ∀ (x : Φ) → ¬ (x ⇌ bot) -- ⊥ is in-⇌ with any x∈Φ ⊤-validi : ∀ (x : Φ) → ¬ (x ≡ bot) → (x ⇌ top) -- ⊤ ⇌ everything e.x. ⊥ substitution : {A : Frame} (x y z : Frame.Φ A) -- ∀x,y,z∈Φ.(x≡y ∧ x⇌z → y⇌z) → x ≡ y → Frame._⇌_ A x z → Frame._⇌_ A y z substitution {A} x y z p q rewrite p = q cons→non-contra : {A : Frame} (x : Frame.Φ A) -- ∀x∈Φ.(∃y∈Φ.(x⇌y) → x≠⊥) → ∃[ y ] Frame._⇌_ A x y → ¬ (x ≡ Frame.bot A) cons→non-contra {A} x (y , f) q = Frame.⊥-contra A y w where s : Frame._⇌_ A (Frame.bot A) y s = substitution {A} x (Frame.bot A) y q f w : Frame._⇌_ A y (Frame.bot A) w = Frame.symm A (Frame.bot A) y s module Example₁ where data tf : Set where 𝟘x 𝟙x : tf data _↔_ : tf → tf → Set where t-t : 𝟙x ↔ 𝟙x symm-tf : ∀ (x y : tf) → x ↔ y → y ↔ x symm-tf 𝟙x 𝟙x t-t = t-t alre-tf : ∀ (x : tf) → ¬ (x ≡ 𝟘x) → x ↔ x alre-tf 𝟙x _ = t-t alre-tf 𝟘x p = ⊥-elim (p refl) 𝟙x-validi : ∀ (x : tf) → ¬ (x ≡ 𝟘x) → (x ↔ 𝟙x) 𝟙x-validi 𝟙x _ = t-t 𝟙x-validi 𝟘x ¬p = ⊥-elim (¬p refl) 𝟘x-contra : ∀ (x : tf) → ¬ (x ↔ 𝟘x) 𝟘x-contra x () tfFrame : Frame -- the smallest possible normal frame tfFrame = record { Φ = tf ; bot = 𝟘x ; top = 𝟙x ; _⇌_ = _↔_ ; symm = symm-tf ; alre = alre-tf ; ⊥-contra = 𝟘x-contra ; ⊤-validi = 𝟙x-validi } -- --------------------------------- -- Logical Consequence -- --------------------------------- record _⊢_ {A : Frame} (a b : Frame.Φ A) : Set where -- logical consequence field -- a⊢b ⇔ ∀x∈Φ.(x⇌a → x⇌b) fromCons : ∀ (x : Frame.Φ A) → Frame._⇌_ A x a → Frame._⇌_ A x b -- --------------------------------- -- properties of ⊢ refl-⊢ : {A : Frame} (a : Frame.Φ A) → _⊢_ {A} a a -- reflexive refl-⊢ {A} a = record { fromCons = p } where p : ∀ (x : Frame.Φ A) → Frame._⇌_ A x a → Frame._⇌_ A x a p x q = q trans-⊢ : {A : Frame} (a b c : Frame.Φ A) -- transitive → _⊢_ {A} a b → _⊢_ {A} b c → _⊢_ {A} a c trans-⊢ {A} a b c p q = record { fromCons = f } where f : ∀ (x : Frame.Φ A) → Frame._⇌_ A x a → Frame._⇌_ A x c f x h = _⊢_.fromCons q x (_⊢_.fromCons p x h) -- --------------------------------- -- --------------------------------- -- ∀x∈Φ.(⊥⊢x) bot-cons : {A : Frame} (x : Frame.Φ A) -- ∀x∈Φ.∀y∈Φ.(y⇌⊥ → y⇌x) → ∀ (y : Frame.Φ A) → Frame._⇌_ A y (Frame.bot A) → Frame._⇌_ A y x bot-cons {A} x y p = ⊥-elim (Frame.⊥-contra A y p) bot-to-every : {A : Frame} (x : Frame.Φ A) → _⊢_ {A} (Frame.bot A) x bot-to-every {A} x = record { fromCons = bot-cons {A} x } -- --------------------------------- -- --------------------------------- -- ∀x∈Φ.(x⊢⊤) top-cons : {A : Frame} (y x : Frame.Φ A) -- ∀y∈Φ.∀x∈Φ.(x⇌y → x⇌⊤) → Frame._⇌_ A x y → Frame._⇌_ A x (Frame.top A) top-cons {A} y x p = Frame.⊤-validi A x (cons→non-contra {A} x (y , p)) top-from-every : {A : Frame} (x : Frame.Φ A) → _⊢_ {A} x (Frame.top A) top-from-every {A} x = record { fromCons = top-cons {A} x } -- --------------------------------- -- --------------------------------- -- the criteria for a Reasoning frame -- --------------------------------- record Reasoning (A : Frame) : Set₁ where field -- basically, reas says every consistent pair is testified reas : ∀ (x y : Frame.Φ A) → Frame._⇌_ A x y → ∃[ z ] ((¬ (z ≡ Frame.bot A)) × ((_⊢_ {A} z x) × (_⊢_ {A} z y))) module Example₂ where open Example₁ 𝟘x⊢𝟘x : _⊢_ {tfFrame} 𝟘x 𝟘x 𝟘x⊢𝟘x = refl-⊢ {tfFrame} 𝟘x 𝟘x⊢𝟙x : _⊢_ {tfFrame} 𝟘x 𝟙x 𝟘x⊢𝟙x = bot-to-every {tfFrame} 𝟙x 𝟙x⊢𝟙x : _⊢_ {tfFrame} 𝟙x 𝟙x 𝟙x⊢𝟙x = refl-⊢ {tfFrame} 𝟙x reas-tf : ∀ (x y : tf) → (x ↔ y) → ∃[ z ] ((¬ (z ≡ 𝟘x)) × ((_⊢_ {tfFrame} z x) × (_⊢_ {tfFrame} z y))) reas-tf 𝟘x _ () reas-tf 𝟙x 𝟙x _ = (𝟙x , (p , (𝟙x⊢𝟙x , 𝟙x⊢𝟙x))) where p : ¬ (𝟙x ≡ 𝟘x) p () Reasoning-tf : Reasoning tfFrame Reasoning-tf = record { reas = reas-tf }
32.375839
81
0.456053
0dde1de65ec7cbbb68beaab71131c3d3d77f6634
79
agda
Agda
test/Fail/Issue329b.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/fail/Issue329b.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/fail/Issue329b.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Issue329b where abstract infixl 0 D Undeclared data D : Set where
11.285714
23
0.746835
72020ee26d973f71fa125658fc6191aa994e5e28
2,042
agda
Agda
internal/modal-logic-lob-reduced.agda
JasonGross/lob
716129208eaf4fe3b5f629f95dde4254805942b3
[ "MIT" ]
19
2015-07-17T17:53:30.000Z
2021-03-17T14:04:53.000Z
internal/modal-logic-lob-reduced.agda
JasonGross/lob
716129208eaf4fe3b5f629f95dde4254805942b3
[ "MIT" ]
1
2015-07-17T20:20:43.000Z
2015-07-17T20:20:43.000Z
internal/modal-logic-lob-reduced.agda
JasonGross/lob
716129208eaf4fe3b5f629f95dde4254805942b3
[ "MIT" ]
1
2015-07-17T18:53:37.000Z
2015-07-17T18:53:37.000Z
module modal-lob-reduced where data TYP : Set where ARR : TYP → TYP → TYP -- the type of implications, or function types BOX : TYP → TYP -- the modal □ operator, denoted to TERM LӦB-SENTENCE : TYP → TYP -- the Lӧbian sentence "If this sentence is provable, then A" -- this is the modal fixpoint of λ Ψ. □ Ψ → A data TERM : TYP → Set where k : {A : TYP} → TERM A → TERM (BOX A) -- from A, we deduce □ A distr : {A B : TYP} → TERM (ARR (BOX (ARR A B)) (ARR (BOX A) (BOX B))) -- we deduce □ (A → B) → □ A → □ B s4 : {A : TYP} → TERM (ARR (BOX A) (BOX (BOX A))) -- we deduce □ A → □ □ A app : {A B : TYP} → TERM (ARR A B) → TERM A → TERM B -- from A → B, and A, we deduce B lӧb→ : {A : TYP} → TERM (ARR (LӦB-SENTENCE A) (ARR (BOX (LӦB-SENTENCE A)) A)) -- LӦB-SENTENCE A is Ψ such that Ψ → (□ Ψ → A) lӧb← : {A : TYP} → TERM (ARR (ARR (BOX (LӦB-SENTENCE A)) A) (LӦB-SENTENCE A)) -- LӦB-SENTENCE A is Ψ such that (□ Ψ → A) → Ψ compose : {A B C : TYP} → TERM (ARR A B) → TERM (ARR B C) → TERM (ARR A C) -- from A → B and B → C, we deduce A → C compose2 : {A B C : TYP} → TERM (ARR A B) → TERM (ARR A (ARR B C)) → TERM (ARR A C) -- from A → B and A → B → C, we deduce A → C ⟦_⟧ᵀ : TYP → Set ⟦ ARR A B ⟧ᵀ = ⟦ A ⟧ᵀ → ⟦ B ⟧ᵀ ⟦ BOX T ⟧ᵀ = TERM T ⟦ LӦB-SENTENCE A ⟧ᵀ = TERM (LӦB-SENTENCE A) → ⟦ A ⟧ᵀ ⟦_⟧ᵗ : {T : TYP} → TERM T → ⟦ T ⟧ᵀ ⟦ k e ⟧ᵗ = e ⟦ distr ⟧ᵗ box-a-b box-a = app box-a-b box-a ⟦ s4 ⟧ᵗ = k ⟦ app f x ⟧ᵗ = ⟦ f ⟧ᵗ ⟦ x ⟧ᵗ ⟦ lӧb→ ⟧ᵗ = λ x → x -- this implication is true because on denotation, the two are judgmentally equal ⟦ lӧb← ⟧ᵗ = λ x → x -- this implication is true because on denotation, the two are judgmentally equal ⟦ compose f g ⟧ᵗ = λ x → ⟦ g ⟧ᵗ (⟦ f ⟧ᵗ x) ⟦ compose2 f g ⟧ᵗ = λ x → ⟦ g ⟧ᵗ x (⟦ f ⟧ᵗ x) Lӧb′s-Theorem : {A : TYP} → TERM (ARR (BOX A) A) → TERM A -- from □ A → A, we deduce A Lӧb′s-Theorem {A} interp = app prog (k (app lӧb← prog)) where prog : TERM (ARR (BOX (LӦB-SENTENCE A)) A) prog = compose (compose2 s4 (compose (app distr (k lӧb→)) distr)) interp
55.189189
130
0.554358
721c8b1da69a44323bb281ff964a7bf03c368dfa
195
agda
Agda
Cubical/Data/NatMinusOne.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Data/NatMinusOne.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Data/NatMinusOne.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.NatMinusOne where open import Cubical.Data.NatMinusOne.Base public open import Cubical.Data.NatMinusOne.Properties public
27.857143
54
0.789744
14fbaa54b09c87bb8a8dc6b117b8cbb87a016eb4
3,609
agda
Agda
agda-stdlib/src/Relation/Binary/Reflection.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Relation/Binary/Reflection.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Relation/Binary/Reflection.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Helpers intended to ease the development of "tactics" which use -- proof by reflection ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Data.Fin.Base open import Data.Nat.Base open import Data.Vec.Base as Vec open import Function.Base open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence using (module Equivalence) open import Level open import Relation.Binary import Relation.Binary.PropositionalEquality as P -- Think of the parameters as follows: -- -- * Expr: A representation of code. -- * var: The Expr type should support a notion of variables. -- * ⟦_⟧: Computes the semantics of an expression. Takes an -- environment mapping variables to something. -- * ⟦_⇓⟧: Computes the semantics of the normal form of the -- expression. -- * correct: Normalisation preserves the semantics. -- -- Given these parameters two "tactics" are returned, prove and solve. -- -- For an example of the use of this module, see Algebra.RingSolver. module Relation.Binary.Reflection {e a s} {Expr : ℕ → Set e} {A : Set a} (Sem : Setoid a s) (var : ∀ {n} → Fin n → Expr n) (⟦_⟧ ⟦_⇓⟧ : ∀ {n} → Expr n → Vec A n → Setoid.Carrier Sem) (correct : ∀ {n} (e : Expr n) ρ → ⟦ e ⇓⟧ ρ ⟨ Setoid._≈_ Sem ⟩ ⟦ e ⟧ ρ) where open import Data.Vec.N-ary open import Data.Product import Relation.Binary.Reasoning.Setoid as Eq open Setoid Sem open Eq Sem -- If two normalised expressions are semantically equal, then their -- non-normalised forms are also equal. prove : ∀ {n} (ρ : Vec A n) e₁ e₂ → ⟦ e₁ ⇓⟧ ρ ≈ ⟦ e₂ ⇓⟧ ρ → ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ prove ρ e₁ e₂ hyp = begin ⟦ e₁ ⟧ ρ ≈⟨ sym (correct e₁ ρ) ⟩ ⟦ e₁ ⇓⟧ ρ ≈⟨ hyp ⟩ ⟦ e₂ ⇓⟧ ρ ≈⟨ correct e₂ ρ ⟩ ⟦ e₂ ⟧ ρ ∎ -- Applies the function to all possible "variables". close : ∀ {A : Set e} n → N-ary n (Expr n) A → A close n f = f $ⁿ Vec.map var (allFin n) -- A variant of prove which should in many cases be easier to use, -- because variables and environments are handled in a less explicit -- way. -- -- If the type signature of solve is a bit daunting, then it may be -- helpful to instantiate n with a small natural number and normalise -- the remainder of the type. solve : ∀ n (f : N-ary n (Expr n) (Expr n × Expr n)) → Eqʰ n _≈_ (curryⁿ ⟦ proj₁ (close n f) ⇓⟧) (curryⁿ ⟦ proj₂ (close n f) ⇓⟧) → Eq n _≈_ (curryⁿ ⟦ proj₁ (close n f) ⟧) (curryⁿ ⟦ proj₂ (close n f) ⟧) solve n f hyp = curryⁿ-cong _≈_ ⟦ proj₁ (close n f) ⟧ ⟦ proj₂ (close n f) ⟧ (λ ρ → prove ρ (proj₁ (close n f)) (proj₂ (close n f)) (curryⁿ-cong⁻¹ _≈_ ⟦ proj₁ (close n f) ⇓⟧ ⟦ proj₂ (close n f) ⇓⟧ (Eqʰ-to-Eq n _≈_ hyp) ρ)) -- A variant of solve which does not require that the normal form -- equality is proved for an arbitrary environment. solve₁ : ∀ n (f : N-ary n (Expr n) (Expr n × Expr n)) → ∀ⁿ n (curryⁿ λ ρ → ⟦ proj₁ (close n f) ⇓⟧ ρ ≈ ⟦ proj₂ (close n f) ⇓⟧ ρ → ⟦ proj₁ (close n f) ⟧ ρ ≈ ⟦ proj₂ (close n f) ⟧ ρ) solve₁ n f = Equivalence.from (uncurry-∀ⁿ n) ⟨$⟩ λ ρ → P.subst id (P.sym (left-inverse (λ _ → _ ≈ _ → _ ≈ _) ρ)) (prove ρ (proj₁ (close n f)) (proj₂ (close n f))) -- A variant of _,_ which is intended to make uses of solve and solve₁ -- look a bit nicer. infix 4 _⊜_ _⊜_ : ∀ {n} → Expr n → Expr n → Expr n × Expr n _⊜_ = _,_
34.371429
77
0.579385
1445b7642baa4f2c0e7c77f0d677d12cd66755d6
29,276
agda
Agda
Cubical/Algebra/Group/ZAction.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/Group/ZAction.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
Cubical/Algebra/Group/ZAction.agda
thomas-lamiaux/cubical
58c0b83bb0fed0dc683f3d29b1709effe51c1689
[ "MIT" ]
null
null
null
-- Left ℤ-multiplication on groups and some of its properties -- TODO: lots of the content here should be moved elsewhere {-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Algebra.Group.ZAction where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Powerset open import Cubical.Data.Sigma open import Cubical.Data.Int renaming (_·_ to _*_ ; _+_ to _+ℤ_ ; _-_ to _-ℤ_ ; pos·pos to pos·) hiding (·Assoc) open import Cubical.Data.Nat renaming (_·_ to _·ℕ_ ; _+_ to _+ℕ_) open import Cubical.Data.Nat.Mod open import Cubical.Data.Nat.Order open import Cubical.Data.Empty renaming (rec to ⊥-rec) open import Cubical.Data.Sum renaming (rec to ⊎-rec) open import Cubical.Data.Unit open import Cubical.Data.Fin hiding (_/_) open import Cubical.Data.Fin.Arithmetic open import Cubical.HITs.SetQuotients renaming (_/_ to _/s_ ; rec to sRec ; elim to sElim) open import Cubical.HITs.PropositionalTruncation as Prop open import Cubical.Algebra.Group.Base open import Cubical.Algebra.Group.Properties open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Group.Instances.Int open import Cubical.Algebra.Group.Instances.Unit open import Cubical.Algebra.Group.Instances.IntMod open import Cubical.Algebra.Group.DirProd open import Cubical.Algebra.Group.Subgroup open import Cubical.Algebra.Group.GroupPath open import Cubical.Algebra.Group.IsomorphismTheorems open import Cubical.Algebra.Group.QuotientGroup open import Cubical.Algebra.Group.Exact open import Cubical.Relation.Nullary private variable ℓ ℓ' : Level open Iso open GroupStr open IsGroupHom open Exact4 _ℤ[_]·_ : ℤ → (G : Group ℓ) → fst G → fst G pos zero ℤ[ G' ]· g = 1g (snd G') pos (suc n) ℤ[ G' ]· g = _·_ (snd G') g (pos n ℤ[ G' ]· g) negsuc zero ℤ[ G' ]· g = inv (snd G') g negsuc (suc n) ℤ[ G' ]· g = _·_ (snd G') (inv (snd G') g) (negsuc n ℤ[ G' ]· g) homPresℤ· : {G : Group ℓ} {H : Group ℓ'} → (ϕ : GroupHom G H) → (x : fst G) (z : ℤ) → fst ϕ (z ℤ[ G ]· x) ≡ (z ℤ[ H ]· fst ϕ x) homPresℤ· (ϕ , ϕhom) x (pos zero) = pres1 ϕhom homPresℤ· {H = H} (ϕ , ϕhom) x (pos (suc n)) = pres· ϕhom _ _ ∙ cong (_·_ (snd H) (ϕ x)) (homPresℤ· (ϕ , ϕhom) x (pos n)) homPresℤ· (ϕ , ϕhom) x (negsuc zero) = presinv ϕhom _ homPresℤ· {H = H} (ϕ , ϕhom) x (negsuc (suc n)) = pres· ϕhom _ _ ∙ cong₂ (_·_ (snd H)) (presinv ϕhom x) (homPresℤ· (ϕ , ϕhom) x (negsuc n)) rUnitℤ· : (G : Group ℓ) (x : ℤ) → (x ℤ[ G ]· 1g (snd G)) ≡ 1g (snd G) rUnitℤ· G (pos zero) = refl rUnitℤ· G (pos (suc n)) = cong (_·_ (snd G) (1g (snd G))) (rUnitℤ· G (pos n)) ∙ ·IdL (snd G) (1g (snd G)) rUnitℤ· G (negsuc zero) = GroupTheory.inv1g G rUnitℤ· G (negsuc (suc n)) = cong₂ (_·_ (snd G)) (GroupTheory.inv1g G) (rUnitℤ· G (negsuc n)) ∙ ·IdL (snd G) (1g (snd G)) rUnitℤ·ℤ : (x : ℤ) → (x ℤ[ ℤGroup ]· 1) ≡ x rUnitℤ·ℤ (pos zero) = refl rUnitℤ·ℤ (pos (suc n)) = cong (pos 1 +ℤ_) (rUnitℤ·ℤ (pos n)) ∙ sym (pos+ 1 n) rUnitℤ·ℤ (negsuc zero) = refl rUnitℤ·ℤ (negsuc (suc n)) = cong (-1 +ℤ_) (rUnitℤ·ℤ (negsuc n)) ∙ +Comm (negsuc 0) (negsuc n) private precommℤ : (G : Group ℓ) (g : fst G) (y : ℤ) → (snd G · (y ℤ[ G ]· g)) g ≡ (sucℤ y ℤ[ G ]· g) precommℤ G g (pos zero) = ·IdL (snd G) g ∙ sym (·IdR (snd G) g) precommℤ G g (pos (suc n)) = sym (·Assoc (snd G) _ _ _) ∙ cong ((snd G · g)) (precommℤ G g (pos n)) precommℤ G g (negsuc zero) = ·InvL (snd G) g precommℤ G g (negsuc (suc n)) = sym (·Assoc (snd G) _ _ _) ∙ cong ((snd G · inv (snd G) g)) (precommℤ G g (negsuc n)) ∙ negsucLem n where negsucLem : (n : ℕ) → (snd G · inv (snd G) g) (sucℤ (negsuc n) ℤ[ G ]· g) ≡ (sucℤ (negsuc (suc n)) ℤ[ G ]· g) negsucLem zero = (·IdR (snd G) _) negsucLem (suc n) = refl module _ (G : Group ℓ) (g : fst G) where private lem : (y : ℤ) → (predℤ y ℤ[ G ]· g) ≡ (snd G · inv (snd G) g) (y ℤ[ G ]· g) lem (pos zero) = sym (·IdR (snd G) _) lem (pos (suc n)) = sym (·IdL (snd G) ((pos n ℤ[ G ]· g))) ∙∙ cong (λ x → _·_ (snd G) x (pos n ℤ[ G ]· g)) (sym (·InvL (snd G) g)) ∙∙ sym (·Assoc (snd G) _ _ _) lem (negsuc n) = refl distrℤ· : (x y : ℤ) → ((x +ℤ y) ℤ[ G ]· g) ≡ _·_ (snd G) (x ℤ[ G ]· g) (y ℤ[ G ]· g) distrℤ· (pos zero) y = cong (_ℤ[ G ]· g) (+Comm 0 y) ∙ sym (·IdL (snd G) _) distrℤ· (pos (suc n)) (pos n₁) = cong (_ℤ[ G ]· g) (sym (pos+ (suc n) n₁)) ∙ cong (_·_ (snd G) g) (cong (_ℤ[ G ]· g) (pos+ n n₁) ∙ distrℤ· (pos n) (pos n₁)) ∙ ·Assoc (snd G) _ _ _ distrℤ· (pos (suc n)) (negsuc zero) = distrℤ· (pos n) 0 ∙ ((·IdR (snd G) (pos n ℤ[ G ]· g) ∙ sym (·IdL (snd G) (pos n ℤ[ G ]· g))) ∙ cong (λ x → _·_ (snd G) x (pos n ℤ[ G ]· g)) (sym (·InvL (snd G) g)) ∙ sym (·Assoc (snd G) _ _ _)) ∙ (·Assoc (snd G) _ _ _) ∙ cong (λ x → _·_ (snd G) x (pos n ℤ[ G ]· g)) (·InvL (snd G) g) ∙ ·IdL (snd G) _ ∙ sym (·IdR (snd G) _) ∙ (cong (_·_ (snd G) (pos n ℤ[ G ]· g)) (sym (·InvR (snd G) g)) ∙ ·Assoc (snd G) _ _ _) ∙ cong (λ x → _·_ (snd G) x (inv (snd G) g)) (precommℤ G g (pos n)) distrℤ· (pos (suc n)) (negsuc (suc n₁)) = cong (_ℤ[ G ]· g) (predℤ+negsuc n₁ (pos (suc n))) ∙∙ distrℤ· (pos n) (negsuc n₁) ∙∙ (cong (λ x → _·_ (snd G) x (negsuc n₁ ℤ[ G ]· g)) ((sym (·IdR (snd G) (pos n ℤ[ G ]· g)) ∙ cong (_·_ (snd G) (pos n ℤ[ G ]· g)) (sym (·InvR (snd G) g))) ∙∙ ·Assoc (snd G) _ _ _ ∙∙ cong (λ x → _·_ (snd G) x (inv (snd G) g)) (precommℤ G g (pos n))) ∙ sym (·Assoc (snd G) _ _ _)) distrℤ· (negsuc zero) y = cong (_ℤ[ G ]· g) (+Comm -1 y) ∙ lem y distrℤ· (negsuc (suc n)) y = cong (_ℤ[ G ]· g) (+Comm (negsuc (suc n)) y) ∙∙ lem (y +negsuc n) ∙∙ cong (snd G · inv (snd G) g) (cong (_ℤ[ G ]· g) (+Comm y (negsuc n)) ∙ distrℤ· (negsuc n) y) ∙ (·Assoc (snd G) _ _ _) GroupHomℤ→ℤpres- : (e : GroupHom ℤGroup ℤGroup) (a : ℤ) → fst e (- a) ≡ - fst e a GroupHomℤ→ℤpres- e a = presinv (snd e) a ℤ·≡· : (a b : ℤ) → a * b ≡ (a ℤ[ ℤGroup ]· b) ℤ·≡· (pos zero) b = refl ℤ·≡· (pos (suc n)) b = cong (b +ℤ_) (ℤ·≡· (pos n) b) ℤ·≡· (negsuc zero) b = refl ℤ·≡· (negsuc (suc n)) b = cong (λ X → - b +ℤ X) (ℤ·≡· (negsuc n) b) GroupHomℤ→ℤPres· : (e : GroupHom ℤGroup ℤGroup) (a b : ℤ) → fst e (a * b) ≡ a * fst e b GroupHomℤ→ℤPres· e a b = cong (fst e) (ℤ·≡· a b) ∙∙ homPresℤ· e b a ∙∙ sym (ℤ·≡· a (fst e b)) -- Generators in terms of ℤ-multiplication -- TODO : generalise and develop theory of cyclic groups gen₁-by : (G : Group ℓ) → (g : fst G) → Type _ gen₁-by G g = (h : fst G) → Σ[ a ∈ ℤ ] h ≡ (a ℤ[ G ]· g) gen₂-by : ∀ {ℓ} (G : Group ℓ) → (g₁ g₂ : fst G) → Type _ gen₂-by G g₁ g₂ = (h : fst G) → Σ[ a ∈ ℤ × ℤ ] h ≡ _·_ (snd G) ((fst a) ℤ[ G ]· g₁) ((snd a) ℤ[ G ]· g₂) Iso-pres-gen₁ : ∀ {ℓ ℓ'} (G : Group ℓ) (H : Group ℓ') (g : fst G) → gen₁-by G g → (e : GroupIso G H) → gen₁-by H (fun (fst e) g) Iso-pres-gen₁ G H g genG is h = (fst (genG (inv (fst is) h))) , (sym (rightInv (fst is) h) ∙∙ cong (fun (fst is)) (snd (genG (inv (fst is) h))) ∙∙ (homPresℤ· (_ , snd is) g (fst (genG (inv (fst is) h))))) Iso-pres-gen₂ : (G : Group ℓ) (H : Group ℓ') (g₁ g₂ : fst G) → gen₂-by G g₁ g₂ → (e : GroupIso G H) → gen₂-by H (fun (fst e) g₁) (fun (fst e) g₂) fst (Iso-pres-gen₂ G H g₁ g₂ genG is h) = genG (inv (fst is) h) .fst snd (Iso-pres-gen₂ G H g₁ g₂ genG is h) = sym (rightInv (fst is) h) ∙∙ cong (fun (fst is)) (snd (genG (inv (fst is) h))) ∙∙ (pres· (snd is) _ _ ∙ cong₂ (_·_ (snd H)) (homPresℤ· (_ , snd is) g₁ (fst (fst (genG (inv (fst is) h))))) (homPresℤ· (_ , snd is) g₂ (snd (fst (genG (inv (fst is) h)))))) -- TODO: upstream and express using divisibility? ¬1=x·suc-suc : (n : ℕ) (x : ℤ) → ¬ pos 1 ≡ x * pos (suc (suc n)) ¬1=x·suc-suc n (pos zero) p = snotz (injPos p) ¬1=x·suc-suc n (pos (suc n₁)) p = snotz (injPos (sym (cong predℤ (snd (intLem₂ n n₁))) ∙ sym (cong predℤ p))) where intLem₂ : (n x : ℕ) → Σ[ a ∈ ℕ ] ((pos (suc x)) * pos (suc (suc n)) ≡ pos (suc (suc a))) intLem₂ n zero = n , refl intLem₂ n (suc x) = lem _ _ (intLem₂ n x) where lem : (x : ℤ) (n : ℕ) → Σ[ a ∈ ℕ ] (x ≡ pos (suc (suc a))) → Σ[ a ∈ ℕ ] pos n +ℤ x ≡ pos (suc (suc a)) lem x n (a , p) = n +ℕ a , cong (pos n +ℤ_) p ∙ cong sucℤ (sucℤ+pos a (pos n)) ∙ sucℤ+pos a (pos (suc n)) ∙ (sym (pos+ (suc (suc n)) a)) ¬1=x·suc-suc n (negsuc n₁) p = posNotnegsuc _ _ (p ∙ intLem₁ _ _ .snd) where intLem₁ : (n m : ℕ) → Σ[ a ∈ ℕ ] (negsuc n * pos (suc m)) ≡ negsuc a intLem₁ n zero = n , ·Comm (negsuc n) (pos 1) intLem₁ n (suc m) = lem _ _ .fst , (·Comm (negsuc n) (pos (suc (suc m))) ∙∙ cong (negsuc n +ℤ_) (·Comm (pos (suc m)) (negsuc n) ∙ (intLem₁ n m .snd)) ∙∙ lem _ _ .snd) where lem : (x y : ℕ) → Σ[ a ∈ ℕ ] negsuc x +ℤ negsuc y ≡ negsuc a lem zero zero = 1 , refl lem zero (suc y) = (suc (suc y)) , +Comm (negsuc zero) (negsuc (suc y)) lem (suc x) zero = (suc (suc x)) , refl lem (suc x) (suc y) = (lem (suc (suc x)) y .fst) , (predℤ+negsuc y (negsuc (suc x)) ∙ snd ((lem (suc (suc x))) y)) GroupEquivℤ-pres1 : (e : GroupEquiv ℤGroup ℤGroup) (x : ℤ) → (fst (fst e) 1) ≡ x → abs (fst (fst e) 1) ≡ 1 GroupEquivℤ-pres1 e (pos zero) p = ⊥-rec (snotz (injPos (sym (retEq (fst e) 1) ∙∙ (cong (fst (fst (invGroupEquiv e))) p) ∙∙ pres1 (snd (invGroupEquiv e))))) GroupEquivℤ-pres1 e (pos (suc zero)) p = cong abs p GroupEquivℤ-pres1 e (pos (suc (suc n))) p = ⊥-rec (¬1=x·suc-suc _ _ (h3 ∙ ·Comm (pos (suc (suc n))) (invEq (fst e) 1))) where h3 : pos 1 ≡ _ h3 = sym (retEq (fst e) 1) ∙∙ cong (fst (fst (invGroupEquiv e))) (p ∙ ·Comm 1 (pos (suc (suc n)))) ∙∙ GroupHomℤ→ℤPres· (_ , snd (invGroupEquiv e)) (pos (suc (suc n))) 1 GroupEquivℤ-pres1 e (negsuc zero) p = cong abs p GroupEquivℤ-pres1 e (negsuc (suc n)) p = ⊥-rec (¬1=x·suc-suc _ _ lem₂) where lem₁ : fst (fst e) (negsuc zero) ≡ pos (suc (suc n)) lem₁ = GroupHomℤ→ℤpres- (_ , snd e) (pos 1) ∙ cong -_ p compGroup : GroupEquiv ℤGroup ℤGroup fst compGroup = isoToEquiv (iso -_ -_ -Involutive -Involutive) snd compGroup = makeIsGroupHom -Dist+ compHom : GroupEquiv ℤGroup ℤGroup compHom = compGroupEquiv compGroup e lem₂ : pos 1 ≡ invEq (fst compHom) (pos 1) * pos (suc (suc n)) lem₂ = sym (retEq (fst compHom) (pos 1)) ∙∙ cong (invEq (fst compHom)) lem₁ ∙∙ (cong (invEq (fst compHom)) (·Comm (pos 1) (pos (suc (suc n)))) ∙ GroupHomℤ→ℤPres· (_ , (snd (invGroupEquiv compHom))) (pos (suc (suc n))) (pos 1) ∙ ·Comm (pos (suc (suc n))) (invEq (fst compHom) (pos 1))) groupEquivPresGen : ∀ {ℓ} (G : Group ℓ) (ϕ : GroupEquiv G ℤGroup) (x : fst G) → (fst (fst ϕ) x ≡ 1) ⊎ (fst (fst ϕ) x ≡ - 1) → (ψ : GroupEquiv G ℤGroup) → (fst (fst ψ) x ≡ 1) ⊎ (fst (fst ψ) x ≡ - 1) groupEquivPresGen G (ϕeq , ϕhom) x (inl r) (ψeq , ψhom) = abs→⊎ _ _ (cong abs (cong (fst ψeq) (sym (retEq ϕeq x) ∙ cong (invEq ϕeq) r)) ∙ GroupEquivℤ-pres1 (compGroupEquiv (invGroupEquiv (ϕeq , ϕhom)) (ψeq , ψhom)) _ refl) groupEquivPresGen G (ϕeq , ϕhom) x (inr r) (ψeq , ψhom) = abs→⊎ _ _ (cong abs (cong (fst ψeq) (sym (retEq ϕeq x) ∙ cong (invEq ϕeq) r)) ∙ cong abs (presinv (snd (compGroupEquiv (invGroupEquiv (ϕeq , ϕhom)) (ψeq , ψhom))) 1) ∙ absLem _ (GroupEquivℤ-pres1 (compGroupEquiv (invGroupEquiv (ϕeq , ϕhom)) (ψeq , ψhom)) _ refl)) where absLem : ∀ x → abs x ≡ 1 → abs (- x) ≡ 1 absLem (pos zero) p = ⊥-rec (snotz (sym p)) absLem (pos (suc zero)) p = refl absLem (pos (suc (suc n))) p = ⊥-rec (snotz (cong predℕ p)) absLem (negsuc zero) p = refl absLem (negsuc (suc n)) p = ⊥-rec (snotz (cong predℕ p)) gen₂ℤ×ℤ : gen₂-by (DirProd ℤGroup ℤGroup) (1 , 0) (0 , 1) fst (gen₂ℤ×ℤ (x , y)) = x , y snd (gen₂ℤ×ℤ (x , y)) = ΣPathP ((cong₂ _+ℤ_ ((·Comm 1 x) ∙ cong fst (sym (distrLem 1 0 x))) ((·Comm 0 y) ∙ cong fst (sym (distrLem 0 1 y)))) , +Comm y 0 ∙ cong₂ _+ℤ_ (·Comm 0 x ∙ cong snd (sym (distrLem 1 0 x))) (·Comm 1 y ∙ cong snd (sym (distrLem 0 1 y)))) where ℤ×ℤ = DirProd ℤGroup ℤGroup _+''_ = GroupStr._·_ (snd ℤ×ℤ) distrLem : (x y : ℤ) (z : ℤ) → Path (ℤ × ℤ) (z ℤ[ ℤ×ℤ ]· (x , y)) (z * x , z * y) distrLem x y (pos zero) = refl distrLem x y (pos (suc n)) = (cong ((x , y) +''_) (distrLem x y (pos n))) distrLem x y (negsuc zero) = refl distrLem x y (negsuc (suc n)) = cong₂ _+''_ refl ((distrLem x y (negsuc n))) gen₁ℤGroup-⊎ : (g : ℤ) → gen₁-by ℤGroup g → (g ≡ 1) ⊎ (g ≡ -1) gen₁ℤGroup-⊎ (pos zero) h = ⊥-rec (negsucNotpos 0 0 (h (negsuc 0) .snd ∙ rUnitℤ· ℤGroup _)) gen₁ℤGroup-⊎ (pos (suc zero)) h = inl refl gen₁ℤGroup-⊎ (pos (suc (suc n))) h = ⊥-rec (¬1=x·suc-suc n _ (rem (pos 1))) where rem : (x : ℤ) → x ≡ fst (h x) * pos (suc (suc n)) rem x = h x .snd ∙ sym (ℤ·≡· (fst (h x)) (pos (suc (suc n)))) gen₁ℤGroup-⊎ (negsuc zero) h = inr refl gen₁ℤGroup-⊎ (negsuc (suc n)) h = ⊥-rec (¬1=x·suc-suc n _ (rem (pos 1) ∙ ℤ·negsuc (fst (h (pos 1))) (suc n) ∙ -DistL· _ _)) where rem : (x : ℤ) → x ≡ fst (h x) * negsuc (suc n) rem x = h x .snd ∙ sym (ℤ·≡· (fst (h x)) (negsuc (suc n))) -- Properties of homomorphisms of ℤ wrt generators (should be moved) module _ (ϕ : GroupHom ℤGroup ℤGroup) where ℤHomId : fst ϕ 1 ≡ 1 → fst ϕ ≡ idfun _ ℤHomId p = funExt rem where remPos : (x : ℕ) → fst ϕ (pos x) ≡ idfun ℤ (pos x) remPos zero = pres1 (snd ϕ) remPos (suc zero) = p remPos (suc (suc n)) = pres· (snd ϕ) (pos (suc n)) 1 ∙ cong₂ _+ℤ_ (remPos (suc n)) p rem : (x : ℤ) → fst ϕ x ≡ idfun ℤ x rem (pos n) = remPos n rem (negsuc zero) = presinv (snd ϕ) 1 ∙ cong -_ p rem (negsuc (suc n)) = presinv (snd ϕ) (pos (suc (suc n))) ∙ cong -_ (remPos (suc (suc n))) ℤHomId- : fst ϕ -1 ≡ -1 → fst ϕ ≡ idfun _ ℤHomId- p = ℤHomId (presinv (snd ϕ) (negsuc 0) ∙ cong -_ p) ℤHom1- : fst ϕ 1 ≡ -1 → fst ϕ ≡ -_ ℤHom1- p = funExt rem where rem-1 : fst ϕ (negsuc zero) ≡ pos 1 rem-1 = presinv (snd ϕ) (pos 1) ∙ cong -_ p rem : (n : ℤ) → fst ϕ n ≡ - n rem (pos zero) = pres1 (snd ϕ) rem (pos (suc zero)) = p rem (pos (suc (suc n))) = pres· (snd ϕ) (pos (suc n)) (pos 1) ∙ cong₂ _+ℤ_ (rem (pos (suc n))) p rem (negsuc zero) = rem-1 rem (negsuc (suc n)) = pres· (snd ϕ) (negsuc n) -1 ∙ cong₂ _+ℤ_ (rem (negsuc n)) rem-1 ℤHom-1 : fst ϕ -1 ≡ 1 → fst ϕ ≡ -_ ℤHom-1 p = ℤHom1- (presinv (snd ϕ) -1 ∙ cong -_ p) -- Properties of equivalences of ℤ wrt generators (should be moved) module _ (ϕ : GroupEquiv ℤGroup ℤGroup) where ℤEquiv1 : (groupEquivFun ϕ 1 ≡ 1) ⊎ (groupEquivFun ϕ 1 ≡ -1) ℤEquiv1 = groupEquivPresGen ℤGroup (compGroupEquiv ϕ (invGroupEquiv ϕ)) (pos 1) (inl (funExt⁻ (cong fst (invEquiv-is-rinv (ϕ .fst))) (pos 1))) ϕ ℤEquivIsIdOr- : (g : ℤ) → (groupEquivFun ϕ g ≡ g) ⊎ (groupEquivFun ϕ g ≡ - g) ℤEquivIsIdOr- g = ⊎-rec (λ h → inl (funExt⁻ (ℤHomId (_ , ϕ .snd) h) g)) (λ h → inr (funExt⁻ (ℤHom1- (_ , ϕ .snd) h) g)) ℤEquiv1 absℤEquiv : (g : ℤ) → abs g ≡ abs (fst (fst ϕ) g) absℤEquiv g = ⊎-rec (λ h → sym (cong abs h)) (λ h → sym (abs- _) ∙ sym (cong abs h)) (ℤEquivIsIdOr- g) -- A few consequences of the above lemmas characℤ≅ℤ : (e : GroupEquiv ℤGroup ℤGroup) → (e ≡ idGroupEquiv) ⊎ (e ≡ negEquivℤ) characℤ≅ℤ e = ⊎-rec (λ p → inl (Σ≡Prop (λ _ → isPropIsGroupHom _ _) (Σ≡Prop (λ _ → isPropIsEquiv _) (funExt λ x → cong (e .fst .fst) (·Comm 1 x) ∙ GroupHomℤ→ℤPres· (fst (fst e) , snd e) x 1 ∙ cong (x *_) p ∙ ·Comm x 1)))) (λ p → inr (Σ≡Prop (λ _ → isPropIsGroupHom _ _) (Σ≡Prop (λ _ → isPropIsEquiv _) (funExt λ x → cong (fst (fst e)) (sym (·Rid x)) ∙ GroupHomℤ→ℤPres· ((fst (fst e)) , (snd e)) x 1 ∙ cong (x *_) p ∙ ·Comm x -1 )))) (ℤEquiv1 e) absGroupEquivℤGroup : {G : Group₀} (ϕ ψ : GroupEquiv ℤGroup G) (g : fst G) → abs (invEq (fst ϕ) g) ≡ abs (invEq (fst ψ) g) absGroupEquivℤGroup = GroupEquivJ (λ G ϕ → (ψ : GroupEquiv ℤGroup G) (g : fst G) → abs (invEq (fst ϕ) g) ≡ abs (invEq (fst ψ) g)) (λ ψ → absℤEquiv (invGroupEquiv ψ)) GroupEquivℤ-isEquiv : {G : Group₀} → GroupEquiv ℤGroup G → (g : fst G) → gen₁-by G g → (ϕ : GroupHom G ℤGroup) → (fst ϕ g ≡ 1) ⊎ (fst ϕ g ≡ -1) → isEquiv (fst ϕ) GroupEquivℤ-isEquiv {G = G} = GroupEquivJ (λ G _ → (g : fst G) → gen₁-by G g → (ϕ : GroupHom G ℤGroup) → (fst ϕ g ≡ 1) ⊎ (fst ϕ g ≡ -1) → isEquiv (fst ϕ)) rem where rem : (g : ℤ) → gen₁-by ℤGroup g → (ϕ : GroupHom ℤGroup ℤGroup) → (fst ϕ g ≡ 1) ⊎ (fst ϕ g ≡ -1) → isEquiv (fst ϕ) rem g gen ϕ (inl h₁) = ⊎-rec (λ h₂ → subst isEquiv (sym (ℤHomId ϕ (sym (cong (fst ϕ) h₂) ∙ h₁))) (idIsEquiv _)) (λ h₂ → subst isEquiv (sym (ℤHom-1 ϕ (sym (cong (fst ϕ) h₂) ∙ h₁))) isEquiv-) (gen₁ℤGroup-⊎ g gen) rem g gen ϕ (inr h₁) = ⊎-rec (λ h₂ → subst isEquiv (sym (ℤHom1- ϕ (sym (cong (fst ϕ) h₂) ∙ h₁))) isEquiv-) (λ h₂ → subst isEquiv (sym (ℤHomId- ϕ (sym (cong (fst ϕ) h₂) ∙ h₁))) (idIsEquiv _)) (gen₁ℤGroup-⊎ g gen) -- Characterisation of ℤ→ℤ characGroupHomℤ : (e : GroupHom ℤGroup ℤGroup) → e ≡ ℤHom (fst e (pos 1)) characGroupHomℤ e = Σ≡Prop (λ _ → isPropIsGroupHom _ _) (funExt λ { (pos n) → lem n ; (negsuc n) → presinv (snd e) (pos (suc n)) ∙ cong -_ (lem (suc n)) ∙ sym (ℤ·negsuc (fst e 1) n) }) where lem : (n : ℕ) → fst e (pos n) ≡ fst e 1 * (pos n) lem zero = pres1 (snd e) ∙ ·Comm 0 (fst e 1) lem (suc zero) = ·Comm 1 (fst e 1) lem (suc (suc n)) = pres· (snd e) (pos (suc n)) 1 ∙ cong (_+ℤ fst e 1) (lem (suc n)) ∙ cong (fst e (pos 1) * pos (suc n) +ℤ_) (·Comm 1 (fst e 1)) ∙ sym (·DistR+ (fst e 1) (pos (suc n)) 1) imℤHomSubGroup : (f : GroupHom ℤGroup ℤGroup) → NormalSubgroup ℤGroup imℤHomSubGroup f = imNormalSubgroup f +Comm -- Equivalence between ℤ/ (abs (f 1)) and ℤ/ (im f) using the two different -- definitions of ℤ quotients. We start with the case f 1 ≥ 0. module _ (f : GroupHom ℤGroup ℤGroup) where trivHom→ℤ≅ℤ/im : fst f 1 ≡ 0 → GroupIso ℤGroup (ℤGroup / imℤHomSubGroup f) trivHom→ℤ≅ℤ/im q = trivialRelIso (imℤHomSubGroup f) λ x y → Prop.rec (isSetℤ _ _) λ {(c , p) → GroupTheory.invUniqueL ℤGroup {g = x} {h = (GroupStr.inv (snd ℤGroup) y)} (sym p ∙ (funExt⁻ (cong fst (characGroupHomℤ f ∙ cong ℤHom q)) c)) ∙ GroupTheory.invInv ℤGroup y} ℤHom→ℤ/im≅ℤ/im1 : (n : ℕ) → fst f 1 ≡ pos (suc n) → BijectionIso (ℤGroup / imℤHomSubGroup f) (ℤGroup/ (suc n)) fst (BijectionIso.fun (ℤHom→ℤ/im≅ℤ/im1 n p)) = sRec isSetFin (ℤ→Fin n) λ a b → rec (isSetFin _ _) (uncurry λ x q → (cong (ℤ→Fin n) (cancel-lem a b _ (sym q ∙ funExt⁻ (cong fst (characGroupHomℤ f ∙ cong ℤHom p)) x))) ∙ pres· (isHomℤ→Fin n) (pos (suc n) * x) b ∙ cong (_+ₘ ℤ→Fin n b) (lem x) ∙ GroupStr.·IdL (snd (ℤGroup/ (suc n))) (ℤ→Fin n b)) where lem : (x : ℤ) → ℤ→Fin n (pos (suc n) * x) ≡ 0 lem (pos x) = cong (ℤ→Fin n) (sym (pos· (suc n) x)) ∙ Σ≡Prop (λ _ → isProp≤) (cong (_mod (suc n)) (·-comm (suc n) x) ∙ zero-charac-gen (suc n) x) lem (negsuc x) = cong (ℤ→Fin n) (pos·negsuc (suc n) x ∙ cong -_ (sym (pos· (suc n) (suc x)))) ∙∙ cong -ₘ_ (Σ≡Prop (λ _ → isProp≤) (cong (_mod (suc n)) (·-comm (suc n) (suc x)) ∙ zero-charac-gen (suc n) (suc x))) ∙∙ GroupTheory.inv1g (ℤGroup/ (suc n)) cancel-lem : (a b x : ℤ) → a +ℤ (- b) ≡ x → a ≡ x +ℤ b cancel-lem a b x p = sym (minusPlus b a) ∙ cong (_+ℤ b) p snd (BijectionIso.fun (ℤHom→ℤ/im≅ℤ/im1 n p)) = makeIsGroupHom (elimProp2 (λ _ _ → isSetFin _ _) (pres· (isHomℤ→Fin n))) BijectionIso.inj (ℤHom→ℤ/im≅ℤ/im1 n p) = elimProp (λ _ → isPropΠ λ _ → squash/ _ _) (λ { (pos x) q → eq/ (pos x) 0 ∣ (((pos (quotient x / (suc n)))) , (funExt⁻ (cong fst (characGroupHomℤ f ∙ cong ℤHom p)) ((pos (quotient x / (suc n)))) ∙ sym (pos· (suc n) (quotient x / (suc n))) ∙ cong pos ((λ i → q (~ i) .fst +ℕ suc n ·ℕ (quotient x / suc n))) ∙ cong pos (≡remainder+quotient (suc n) x))) ∣₁ ; (negsuc x) q → eq/ (negsuc x) 0 ∣ (((- pos (quotient suc x / (suc n)))) , presinv (snd f) (pos (quotient suc x / (suc n))) ∙ (cong -_ (funExt⁻ (cong fst (characGroupHomℤ f ∙ cong ℤHom p)) (pos (quotient (suc x) / (suc n)))) ∙∙ cong -_ (sym (pos· (suc n) (quotient suc x / (suc n))) ∙ (λ i → pos (fst ((sym (GroupTheory.invInv (ℤGroup/ (suc n)) ((suc x mod suc n) , mod< n (suc x))) ∙ cong -ₘ_ q ∙ GroupTheory.inv1g (ℤGroup/ (suc n))) (~ i)) +ℕ suc n ·ℕ quotient (suc x) / suc n))) ∙∙ cong -_ (cong pos (≡remainder+quotient (suc n) (suc x))))) ∣₁}) BijectionIso.surj (ℤHom→ℤ/im≅ℤ/im1 n p) x = ∣ [ pos (fst x) ] , (Σ≡Prop (λ _ → isProp≤) (modIndBase n (fst x) (snd x))) ∣₁ -- main result ℤ/imIso : (f : GroupHom ℤGroup ℤGroup) → GroupIso (ℤGroup / imℤHomSubGroup f) (ℤGroup/ abs (fst f 1)) ℤ/imIso f = helpIso _ refl where helpIso : (a : ℤ) → fst f 1 ≡ a → GroupIso (ℤGroup / imℤHomSubGroup f) (ℤGroup/ abs a) helpIso (pos zero) p = invGroupIso (trivHom→ℤ≅ℤ/im f p) helpIso (pos (suc n)) p = BijectionIso→GroupIso (ℤHom→ℤ/im≅ℤ/im1 f n p) helpIso (negsuc n) p = subst ((λ x → GroupIso (ℤGroup / x) (ℤGroup/ abs (negsuc n)))) (sym lem1) (BijectionIso→GroupIso (ℤHom→ℤ/im≅ℤ/im1 extendHom n (cong -_ p))) where extendHom : GroupHom ℤGroup ℤGroup extendHom = compGroupHom f (fst (fst negEquivℤ) , snd negEquivℤ) lem1 : imℤHomSubGroup f ≡ imℤHomSubGroup extendHom lem1 = Σ≡Prop (λ _ → isPropIsNormal _) (Σ≡Prop (λ _ → isPropIsSubgroup _ _) (funExt λ x → Σ≡Prop (λ _ → isPropIsProp) (isoToPath (iso (Prop.map (λ { (x , q) → (- x) , cong -_ (presinv (snd f) x) ∙ GroupTheory.invInv ℤGroup (fst f x) ∙ q })) (Prop.map (λ { (x , q) → (- x) , (presinv (snd f) x ∙ q) })) ((λ _ → squash₁ _ _)) (λ _ → squash₁ _ _))))) -- Goal: given G -ᶠ→ H → L → Unit exact, with G ≅ H ≅ ℤ, we get -- an iso ℤ/abs (f 1) ≅ H, where f 1 and 1 are viewed as integers -- via the isomorphisms. We start with the case when G = H = ℤ module _ (f : GroupHom ℤGroup ℤGroup) (G : Group₀) (g : GroupHom ℤGroup G) (ex : Exact4 ℤGroup ℤGroup G UnitGroup₀ f g (→UnitHom G)) where private imf≡kerg : imℤHomSubGroup f ≡ kerNormalSubgroup g imf≡kerg = Σ≡Prop (λ _ → isPropIsNormal _) (Σ≡Prop (λ _ → isPropIsSubgroup _ _) (funExt λ x → Σ≡Prop (λ _ → isPropIsProp) (isoToPath (isProp→Iso (isPropIsInIm _ _) (isPropIsInKer _ _) (ImG→H⊂KerH→L ex x) (KerH→L⊂ImG→H ex x))))) ℤ/im≅ℤ/ker : GroupIso (ℤGroup / imℤHomSubGroup f) (ℤGroup / kerNormalSubgroup g) ℤ/im≅ℤ/ker = GroupEquiv→GroupIso (invEq (GroupPath _ _) (cong (ℤGroup /_) imf≡kerg)) GroupIsoℤ/abs : GroupIso (ℤGroup/ abs (fst f (pos 1))) G GroupIsoℤ/abs = compGroupIso (invGroupIso (ℤ/imIso f)) (compGroupIso ℤ/im≅ℤ/ker (compGroupIso (invGroupIso (isoThm1 g)) (surjImIso g λ a → KerL→R⊂ImH→L ex a refl))) -- The general case GroupEquivℤ/abs-gen : (G H L : Group₀) → (e : GroupEquiv ℤGroup G) → (r : GroupEquiv ℤGroup H) → (f : GroupHom G H) (g : GroupHom H L) → Exact4 G H L UnitGroup₀ f g (→UnitHom L) → GroupEquiv (ℤGroup/ abs (invEq (fst r) (fst f (fst (fst e) 1)))) L GroupEquivℤ/abs-gen G H L = GroupEquivJ (λ G e → (r : GroupEquiv ℤGroup H) → (f : GroupHom G H) (g : GroupHom H L) → Exact4 G H L UnitGroup₀ f g (→UnitHom L) → GroupEquiv (ℤGroup/ abs (invEq (fst r) (fst f (fst (fst e) 1)))) L) (GroupEquivJ (λ H r → (f : GroupHom ℤGroup H) (g : GroupHom H L) → Exact4 ℤGroup H L UnitGroup₀ f g (→UnitHom L) → GroupEquiv (ℤGroup/ abs (invEq (fst r) (fst f 1))) L) λ f g ex → GroupIso→GroupEquiv (GroupIsoℤ/abs f L g ex)) -- for type checking reasons, let's also do it with an abstract type abstract abstractℤGroup/_ : ℕ → Group₀ abstractℤGroup/_ n = ℤGroup/ n abstractℤ/≡ℤ : abstractℤGroup/_ ≡ ℤGroup/_ abstractℤ/≡ℤ = refl abstractℤ/≅ℤ : (n : ℕ) → GroupEquiv (abstractℤGroup/_ n) (ℤGroup/ n) abstractℤ/≅ℤ n = idGroupEquiv GroupEquiv-abstractℤ/abs-gen : (G H L : Group₀) → (e : GroupEquiv ℤGroup G) → (r : GroupEquiv ℤGroup H) → (f : GroupHom G H) (g : GroupHom H L) → Exact4 G H L UnitGroup₀ f g (→UnitHom L) → (n : ℕ) → abs (invEq (fst r) (fst f (fst (fst e) 1))) ≡ n → GroupEquiv (abstractℤGroup/_ n) L GroupEquiv-abstractℤ/abs-gen G H L e r f g ex n p = main where abstract main : GroupEquiv (abstractℤGroup/_ n) L main = transport (λ i → GroupEquiv (abstractℤ/≡ℤ (~ i) (p i)) L) (GroupEquivℤ/abs-gen G H L e r f g ex) 1∈Im→isEquivℤ : (h : GroupHom ℤGroup ℤGroup) → isInIm h (pos 1) → isEquiv (fst h) 1∈Im→isEquivℤ h = Prop.rec (isPropIsEquiv _) λ p → GroupEquivℤ-isEquiv idGroupEquiv 1 (λ r → r , (·Comm 1 r ∙ ℤ·≡· r 1)) h (main p) where main : Σ[ x ∈ ℤ ] fst h x ≡ 1 → (fst h 1 ≡ 1) ⊎ (fst h 1 ≡ -1) main (n , p) = ≡±1-id n (fst h (pos 1)) h1-id (λ q → snotz (injPos (sym p ∙∙ cong (fst h) q ∙∙ IsGroupHom.pres1 (snd h)))) λ q → snotz (injPos (sym p ∙∙ cong (fst h) (·Comm 1 n ∙ ℤ·≡· n 1) ∙∙ homPresℤ· h 1 n ∙ (cong (n ℤ[ ℤGroup ]·_) q) ∙∙ sym (ℤ·≡· n 0) ∙∙ ·Comm n 0)) where h1-id : pos 1 ≡ n * fst h (pos 1) h1-id = sym p ∙ cong (fst h) (sym (ℤ·≡· 1 n) ∙∙ ·Comm 1 n ∙∙ ℤ·≡· n 1) ∙ (homPresℤ· h 1 n) ∙ sym (ℤ·≡· n (fst h 1)) ≡±1-id : (a b : ℤ) → 1 ≡ a * b → ¬ (a ≡ 0) → ¬ (b ≡ 0) → (b ≡ 1) ⊎ (b ≡ -1) ≡±1-id a (pos zero) p a≠0 b≠0 = ⊥-rec (b≠0 refl) ≡±1-id a (pos (suc zero)) p a≠0 b≠0 = inl refl ≡±1-id (pos zero) (pos (suc (suc n))) p a≠0 b≠0 = ⊥-rec (a≠0 refl) ≡±1-id (pos (suc n₁)) (pos (suc (suc n))) p a≠0 b≠0 = ⊥-rec (snotz (cong predℕ (injPos ((pos· (suc n₁) (suc (suc n)) ∙ sym p))))) ≡±1-id (negsuc n₁) (pos (suc (suc n))) p a≠0 b≠0 = ⊥-rec (snotz (sym (injNegsuc (cong (predℤ ∘ predℤ) (p ∙ negsuc·pos n₁ (suc (suc n)) ∙ cong (-_) (sym (pos· (suc n₁) (suc (suc n))))))))) ≡±1-id a (negsuc zero) p a≠0 b≠0 = inr refl ≡±1-id (pos zero) (negsuc (suc n)) p a≠0 b≠0 = ⊥-rec (a≠0 refl) ≡±1-id (pos (suc n₁)) (negsuc (suc n)) p a≠0 b≠0 = ⊥-rec (snotz (sym (injNegsuc (cong (predℤ ∘ predℤ) (p ∙ pos·negsuc (suc n₁) (suc n) ∙ cong (-_) (sym (pos· (suc n₁) (suc (suc n))))))))) ≡±1-id (negsuc n₁) (negsuc (suc n)) p a≠0 b≠0 = ⊥-rec (snotz (injPos (sym (cong predℤ (p ∙ negsuc·negsuc n₁ (suc n) ∙ sym (pos· (suc n₁) (suc (suc n)))))))) 1∈Im→isEquiv : ∀ (G : Group₀) (e : GroupEquiv ℤGroup G) → (h : GroupHom G ℤGroup) → isInIm (_ , snd h) 1 → isEquiv (fst h) 1∈Im→isEquiv G = GroupEquivJ (λ H _ → (h : GroupHom H ℤGroup) → isInIm (_ , snd h) 1 → isEquiv (fst h)) 1∈Im→isEquivℤ
40.548476
123
0.515576
1d2eb63e9e1ce07c28ca1d74a0564dd3f0d1aa3c
1,341
agda
Agda
test/succeed/Issue354.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T04:41:05.000Z
2019-11-27T04:41:05.000Z
test/succeed/Issue354.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/Issue354.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
{-# OPTIONS --universe-polymorphism #-} module Issue354 where ------------------------------------------------------------------------ -- Preliminaries postulate Level : Set zero : Level suc : (i : Level) → Level _⊔_ : Level → Level → Level {-# BUILTIN LEVEL Level #-} {-# BUILTIN LEVELZERO zero #-} {-# BUILTIN LEVELSUC suc #-} {-# BUILTIN LEVELMAX _⊔_ #-} data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x _≗_ : ∀ {a b} {A : Set a} {B : Set b} (f g : A → B) → Set (a ⊔ b) f ≗ g = ∀ x → f x ≡ g x ------------------------------------------------------------------------ -- Example postulate a : Level A : Set a P : A → Set x : A f : ∀ {a} {A : Set a} → A → A g : A → A lemma : f ≗ g p : f x ≡ g x p with f x | lemma x ... | .(g x) | refl = refl -- The code above fails to type check, even though lemma x has the -- type f x ≡ g x. However, if A is given the type Set zero, then the -- code checks. -- Excerpt from agda -vtc.with:100 --show-implicit Bug.agda: -- -- checkWithFunction -- delta1 = -- delta2 = -- gamma = -- as = [A, _≡_ {a} {A} (f {a ⊔ a} {A} x) (g x)] -- vs = [f {a} {A} x, lemma x] -- b = _≡_ {a} {A} (f {a} {A} x) (g x) -- qs = [] -- perm = -> -- -- Notice the occurrence of a ⊔ a.
22.728814
72
0.431767
5e4761a0e315cae09755e53eb733c864bab1cdaf
1,406
agda
Agda
nouse_CollatzProof.agda
righ1113/collatzProof
7e3f7a76b8cb0db264175392ff5e584a26930379
[ "MIT" ]
1
2018-02-25T14:44:08.000Z
2018-02-25T14:44:08.000Z
nouse_CollatzProof.agda
righ1113/collatzProof
7e3f7a76b8cb0db264175392ff5e584a26930379
[ "MIT" ]
null
null
null
nouse_CollatzProof.agda
righ1113/collatzProof
7e3f7a76b8cb0db264175392ff5e584a26930379
[ "MIT" ]
null
null
null
module nouse_CollatzProof where open import Data.Nat -- 偽 data ⊥ : Set where -- 真 record ⊤ : Set where -- 選言 data _∨_ (P Q : Set) : Set where ∨Intro1 : P → P ∨ Q ∨Intro2 : Q → P ∨ Q ∨Elim : {P Q R : Set} → P ∨ Q → (P → R) → (Q → R) → R ∨Elim (∨Intro1 a) prfP _ = prfP a ∨Elim (∨Intro2 b) _ prfQ = prfQ b -- 否定 ¬ : Set → Set ¬ p = p → ⊥ ⊥Elim : {P : Set} → ⊥ → P ⊥Elim () postulate LEM : (P : Set) → (P ∨ ¬ P) smaller : ℕ → Set -- n:左端からの連続するビット1 -- k+2で小さくならない→k+1で小さくならない lemma1-3 : (k : ℕ) → ¬ (smaller (suc (suc k))) → ¬ (smaller (suc k)) lemma2 : smaller 0 -- evenは小さくなる lemma3 : smaller 1 -- 4x+1は小さくなる -- 二重否定除去 DNE1 : {p : Set} → p → ¬ (¬ p) DNE1 p q = q p DNE2 : {p : Set} → ¬ (¬ p) → p DNE2 {p0} p1 = ∨Elim (LEM p0) (λ y → y) (λ z → ⊥Elim (p1 z)) -- 対偶 contraposition : {A B : Set} → (A → B) → (¬ B → ¬ A) contraposition = λ f g x → g (f x) contraposition2 : {A B : Set} → (¬ B → ¬ A) → (A → B) contraposition2 p a = let t = (contraposition p) (DNE1 a) in DNE2 t -- 本論 -- n:最下位からの連続するビット1 proof : (n : ℕ) → smaller n proof zero = lemma2 -- even proof (suc zero) = lemma3 -- 4x+1 proof (suc (suc n)) = part n (proof (suc n)) where -- (k+2で小さくならない→k+1で小さくならない)→(k+1で小さくなる→k+2で小さくなる) part : (k : ℕ) → smaller (suc k) → smaller (suc (suc k)) part k = contraposition2 (lemma1-3 k)
23.830508
71
0.510669
1139e52a1edf95efa105f3fcf0b7e2d5189a58c0
3,423
agda
Agda
Cubical/DStructures/Experiments.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/DStructures/Experiments.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/DStructures/Experiments.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe --guardedness #-} module Cubical.DStructures.Experiments where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Path open import Cubical.Functions.FunExtEquiv open import Cubical.Homotopy.Base open import Cubical.Data.Sigma open import Cubical.Data.Unit open import Cubical.Data.Maybe open import Cubical.Relation.Binary open import Cubical.Structures.Subtype open import Cubical.Structures.LeftAction open import Cubical.Algebra.Group open import Cubical.Algebra.Group.Semidirect -- this file also serves as Everything.agda open import Cubical.DStructures.Base open import Cubical.DStructures.Meta.Properties open import Cubical.DStructures.Meta.Isomorphism open import Cubical.DStructures.Structures.Action open import Cubical.DStructures.Structures.Category open import Cubical.DStructures.Structures.Constant open import Cubical.DStructures.Structures.Group -- open import Cubical.DStructures.Structures.Higher open import Cubical.DStructures.Structures.Nat open import Cubical.DStructures.Structures.PeifferGraph open import Cubical.DStructures.Structures.ReflGraph open import Cubical.DStructures.Structures.SplitEpi open import Cubical.DStructures.Structures.Strict2Group open import Cubical.DStructures.Structures.Type -- open import Cubical.DStructures.Structures.Universe open import Cubical.DStructures.Structures.VertComp open import Cubical.DStructures.Structures.XModule open import Cubical.DStructures.Equivalences.GroupSplitEpiAction open import Cubical.DStructures.Equivalences.PreXModReflGraph open import Cubical.DStructures.Equivalences.XModPeifferGraph open import Cubical.DStructures.Equivalences.PeifferGraphS2G private variable ℓ ℓ' ℓ'' ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓA ℓA' ℓ≅A ℓ≅A' ℓB ℓB' ℓ≅B ℓC ℓ≅C ℓ≅ᴰ ℓ≅ᴰ' ℓ≅B' : Level open Kernel open GroupHom -- such .fun! open GroupLemmas open MorphismLemmas {- record Hom-𝒮 {A : Type ℓA} {ℓ≅A : Level} (𝒮-A : URGStr A ℓ≅A) {B : Type ℓB} {ℓ≅B : Level} (𝒮-B : URGStr B ℓ≅B) : Type (ℓ-max (ℓ-max ℓA ℓB) (ℓ-max ℓ≅A ℓ≅B)) where constructor hom-𝒮 open URGStr field fun : A → B fun-≅ : {a a' : A} → (p : _≅_ 𝒮-A a a') → _≅_ 𝒮-B (fun a) (fun a') fun-ρ : {a : A} → fun-≅ (ρ 𝒮-A a) ≡ ρ 𝒮-B (fun a) ∫𝒮ᴰ-π₁ : {A : Type ℓA} {𝒮-A : URGStr A ℓ≅A} {B : A → Type ℓB} (𝒮ᴰ-B : URGStrᴰ 𝒮-A B ℓ≅B) → Hom-𝒮 (∫⟨ 𝒮-A ⟩ 𝒮ᴰ-B) 𝒮-A Hom-𝒮.fun (∫𝒮ᴰ-π₁ 𝒮ᴰ-B) = fst Hom-𝒮.fun-≅ (∫𝒮ᴰ-π₁ 𝒮ᴰ-B) = fst Hom-𝒮.fun-ρ (∫𝒮ᴰ-π₁ 𝒮ᴰ-B) = refl module _ {ℓ : Level} {A : Type ℓ} (𝒮-A : URGStr A ℓ) where 𝒮ᴰ-toHom : Iso (Σ[ B ∈ (A → Type ℓ) ] (URGStrᴰ 𝒮-A B ℓ)) (Σ[ B ∈ (Type ℓ) ] Σ[ 𝒮-B ∈ (URGStr B ℓ) ] (Hom-𝒮 𝒮-B 𝒮-A)) Iso.fun 𝒮ᴰ-toHom (B , 𝒮ᴰ-B) = (Σ[ a ∈ A ] B a) , {!!} , {!!} Iso.inv 𝒮ᴰ-toHom (B , 𝒮ᴰ-B , F) = (λ a → Σ[ b ∈ B ] F .fun b ≡ a) , {!!} where open Hom-𝒮 Iso.leftInv 𝒮ᴰ-toHom (B , 𝒮ᴰ-B) = ΣPathP ((funExt (λ a → {!!})) , {!!}) Iso.rightInv 𝒮ᴰ-toHom (B , 𝒮ᴰ-B , F) = {!!} -} -- Older Experiments -- -- needs --guardedness flag module _ where record Hierarchy {A : Type ℓ} (𝒮-A : URGStr A ℓ) : Type (ℓ-suc ℓ) where coinductive field B : A → Type ℓ 𝒮ᴰ-B : URGStrᴰ 𝒮-A B ℓ ℋ : Maybe (Hierarchy {A = Σ A B} (∫⟨ 𝒮-A ⟩ 𝒮ᴰ-B))
30.837838
118
0.695297
4329e05a97c083f895f3b4fc5569bd52b1e4396c
2,111
agda
Agda
Cubical/Homotopy/Group/Pi4S3/S3PushoutIso2.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:28:39.000Z
2022-03-05T00:28:39.000Z
Cubical/Homotopy/Group/Pi4S3/S3PushoutIso2.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/Homotopy/Group/Pi4S3/S3PushoutIso2.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Homotopy.Group.Pi4S3.S3PushoutIso2 where open import Cubical.Homotopy.Group.Base open import Cubical.Homotopy.Group.Pi4S3.S3PushoutIso open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence open import Cubical.Data.Nat open import Cubical.Algebra.Group open import Cubical.HITs.Sn open import Cubical.HITs.Susp renaming (toSusp to σ) open import Cubical.HITs.Pushout open import Cubical.HITs.Truncation renaming (rec to trRec ; elim to trElim ; elim2 to trElim2 ; map to trMap) open import Cubical.HITs.S2 ≡→Pushout⋁↪fold⋁≡ : ∀ {ℓ} {A B : Pointed ℓ} → (A ≡ B) → Pushout⋁↪fold⋁∙ A ≡ Pushout⋁↪fold⋁∙ B ≡→Pushout⋁↪fold⋁≡ = cong Pushout⋁↪fold⋁∙ private ∙≃→π≅ : ∀ {ℓ} {A B : Pointed ℓ} (n : ℕ) → (e : typ A ≃ typ B) → fst e (pt A) ≡ pt B → GroupEquiv (πGr n A) (πGr n B) ∙≃→π≅ {A = A} {B = B} n e = EquivJ (λ A e → (a : A) → fst e a ≡ pt B → GroupEquiv (πGr n (A , a)) (πGr n B)) (λ b p → J (λ b p → GroupEquiv (πGr n (typ B , b)) (πGr n B)) idGroupEquiv (sym p)) e (pt A) {- π₄(S³) ≅ π₃((S² × S²) ⊔ᴬ S²) where A = S² ∨ S² -} π₄S³≅π₃PushS² : GroupIso (πGr 3 (S₊∙ 3)) (πGr 2 (Pushout⋁↪fold⋁∙ (S₊∙ 2))) π₄S³≅π₃PushS² = compGroupIso (GroupEquiv→GroupIso (∙≃→π≅ 3 (compEquiv (isoToEquiv (invIso IsoS³S3)) S³≃SuspS²) refl)) (compGroupIso (invGroupIso (GrIso-πΩ-π 2)) (compGroupIso (πTruncGroupIso 2) (compGroupIso (GroupEquiv→GroupIso (∙≃→π≅ {B = _ , ∣ inl (base , base) ∣ₕ} 2 (isoToEquiv IsoΩ∥SuspS²∥₅∥Pushout⋁↪fold⋁S²∥₅) encode∙)) (compGroupIso (invGroupIso (πTruncGroupIso 2)) (GroupEquiv→GroupIso (invEq (GroupPath _ _) (cong (πGr 2) (cong Pushout⋁↪fold⋁∙ (ua∙ S²≃SuspS¹ refl))))))))) where encode∙ : encode ∣ north ∣ refl ≡ ∣ inl (base , base) ∣ encode∙ = transportRefl _
32.476923
72
0.616296
fd1d9bd2bf2a03c2d34ca05e7adea51ce8eef990
1,016
agda
Agda
examples/outdated-and-incorrect/StackLanguage.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/outdated-and-incorrect/StackLanguage.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/outdated-and-incorrect/StackLanguage.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{- A simple stack language example. Illustrating that one wants dependent elimination of inductive families. -} module StackLanguage where open import Lib.Nat open import Lib.Vec open import Lib.Id data Prog (A : Set) : Nat -> Set where init : Prog A 0 push : forall {n} -> A -> Prog A n -> Prog A (suc n) pop : forall {n} -> Prog A (suc n) -> Prog A n ⟦_⟧ : forall {A n} -> Prog A n -> Vec A n ⟦ init ⟧ = ε ⟦ push x p ⟧ = x ► ⟦ p ⟧ ⟦ pop p ⟧ with ⟦ p ⟧ ... | x ► xs = xs reify : forall {A n} -> Vec A n -> Prog A n reify ε = init reify (x ► xs) = push x (reify xs) normalise : forall {A n} -> Prog A n -> Prog A n normalise p = reify ⟦ p ⟧ _≅_ : forall {A n} -> Prog A n -> Prog A n -> Set p₁ ≅ p₂ = ⟦ p₁ ⟧ == ⟦ p₂ ⟧ sound : forall {A n} -> (p : Prog A n) -> normalise p ≅ p sound init = refl sound (push x p) = cong (_►_ x) (sound p) sound (pop p) with ⟦ p ⟧ | sound p ... | x ► xs | ih with ⟦ reify xs ⟧ sound (pop p) | x ► xs | refl | .xs = refl
25.4
57
0.542323
6529dc26ad80ee41a3c25fecc1bf8da8b905dcd7
10,010
agda
Agda
src/Tactic/By/Propositional.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
3
2020-05-21T22:58:50.000Z
2021-09-02T17:18:15.000Z
src/Tactic/By/Propositional.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
src/Tactic/By/Propositional.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Some tactics aimed at making equational reasoning proofs more -- readable for propositional equality ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Tactic.By.Propositional where open import Equality.Propositional open import Prelude open import List equality-with-J open import Maybe equality-with-J open import Monad equality-with-J open import Tactic.By equality-with-J as TB open import TC-monad equality-with-J as TC hiding (Type) open TB public using (⟨_⟩) private -- Constructs the type of equalities between its two arguments. equality : Term → Term → TC.Type equality lhs rhs = def (quote _≡_) (varg lhs ∷ varg rhs ∷ []) -- An illustration of what the cong functions constructed by -- make-cong-called look like. cong₃′ : ∀ {a b c d : Level} {A : Type a} {B : Type b} {C : Type c} {D : Type d} {x₁ y₁ x₂ y₂ x₃ y₃} (f : A → B → C → D) → x₁ ≡ y₁ → x₂ ≡ y₂ → x₃ ≡ y₃ → f x₁ x₂ x₃ ≡ f y₁ y₂ y₃ cong₃′ f refl refl refl = refl -- Constructs a "cong" function (similar to cong and cong₂ in -- Equality), with the given name, for functions with the given -- number of arguments. make-cong-called : Name → ℕ → TC ⊤ make-cong-called cong n = do declareDef (varg cong) (type-of-cong equality n) defineFun cong (the-clause ∷ []) where the-clause = clause (("f" , varg unknown) ∷ []) (varg (var 0) ∷ replicate n (varg (con (quote refl) []))) (con (quote refl) []) unquoteDecl cong₃ = make-cong-called cong₃ 3 unquoteDecl cong₄ = make-cong-called cong₄ 4 unquoteDecl cong₅ = make-cong-called cong₅ 5 unquoteDecl cong₆ = make-cong-called cong₆ 6 unquoteDecl cong₇ = make-cong-called cong₇ 7 unquoteDecl cong₈ = make-cong-called cong₈ 8 unquoteDecl cong₉ = make-cong-called cong₉ 9 unquoteDecl cong₁₀ = make-cong-called cong₁₀ 10 -- Constructs a "cong" function (similar to cong and cong₂ in -- Equality) for functions with the given number of arguments. The -- name of the constructed function is returned (for 1 and 2 the -- functions in Equality are returned). The cong functions for -- functions with 3 up to 10 arguments are cached to avoid creating -- lots of copies of the same functions. make-cong : ℕ → TC Name make-cong 1 = return (quote cong) make-cong 2 = return (quote cong₂) make-cong 3 = return (quote cong₃) make-cong 4 = return (quote cong₄) make-cong 5 = return (quote cong₅) make-cong 6 = return (quote cong₆) make-cong 7 = return (quote cong₇) make-cong 8 = return (quote cong₈) make-cong 9 = return (quote cong₉) make-cong 10 = return (quote cong₁₀) make-cong n = do cong ← freshName "cong" make-cong-called cong n return cong open Tactics (λ where (def (quote _≡_) (arg _ a ∷ arg _ A ∷ arg _ x ∷ arg _ y ∷ [])) → return $ just (a , A , x , y) _ → return nothing) equality (λ a A x → con (quote refl) (harg a ∷ harg A ∷ harg x ∷ [])) (λ p → def (quote sym) (varg p ∷ [])) (λ lhs rhs f p → def (quote cong) (replicate 4 (harg unknown) ++ harg lhs ∷ harg rhs ∷ varg f ∷ varg p ∷ [])) false make-cong true public ------------------------------------------------------------------------ -- Some unit tests private module Tests (assumption : 48 ≡ 42) (lemma : ∀ n → n + 8 ≡ n + 2) (f : ℕ → ℕ → ℕ → ℕ) where g : ℕ → ℕ → ℕ → ℕ g zero _ _ = 12 g (suc _) _ _ = 12 fst : ∀ {a b} {A : Type a} {B : A → Type b} → Σ A B → A fst = proj₁ {-# NOINLINE fst #-} record R (F : Type → Type) : Type₁ where field p : {A : Type} {x : F A} → x ≡ x open R ⦃ … ⦄ public -- Tests for by. module By-tests where test₁ : 40 + 2 ≡ 42 test₁ = by definition test₂ : 48 ≡ 42 → 42 ≡ 48 test₂ eq = by eq test₃ : (f : ℕ → ℕ) → f 42 ≡ f 48 test₃ f = by assumption test₄ : (f : ℕ → ℕ) → f 48 ≡ f 42 test₄ f = by assumption test₅ : (f : ℕ → ℕ → ℕ) → f 42 48 ≡ f 48 42 test₅ f = by assumption test₆ : (f : ℕ → ℕ → ℕ → ℕ) → f 42 45 48 ≡ f 48 45 42 test₆ f = by assumption test₇ : f 48 (f 42 45 48) 42 ≡ f 48 (f 48 45 42) 48 test₇ = by assumption test₈ : ∀ n → g n (g n 45 48) 42 ≡ g n (g n 45 42) 48 test₈ n = by assumption test₉ : (f : ℕ → ℕ) → f 42 ≡ f 48 test₉ f = by (lemma 40) test₁₀ : (f : ℕ → ℕ) → f 42 ≡ f 48 test₁₀ f = by (λ (_ : ⊤) → assumption) test₁₁ : (f : ℕ × ℕ → ℕ × ℕ) → (∀ x → ⟨ _≡_ ⟩ (f x) x) → fst (f (12 , 73)) ≡ fst {B = λ _ → ℕ} (12 , 73) test₁₁ _ hyp = by hyp -- Two test cases for the extra check in try-refl. -- test₁₂ : (h : ℕ → Maybe ℕ) → -- ((xs : ℕ) → h xs ≡ just xs) → -- (xs : ℕ) → suc ⟨$⟩ h xs ≡ suc ⟨$⟩ return xs -- test₁₂ h hyp xs = -- suc ⟨$⟩ h xs ≡⟨ by (hyp xs) ⟩∎ -- suc ⟨$⟩ return xs ∎ -- test₁₃ : (h : List ⊤ → Maybe (List ⊤)) → -- ((xs : List ⊤) → h xs ≡ just xs) → -- (x : ⊤) (xs : List ⊤) → _ -- test₁₃ h hyp x xs = -- _∷_ ⟨$⟩ return x ⊛ h xs ≡⟨ by (hyp xs) ⟩∎ -- _∷_ ⟨$⟩ return x ⊛ return xs ∎ -- This test case fails if "refl a A lhs" is replaced by -- "refl unknown unknown lhs" in try-refl. test₁₅ : (F : Type → Type → Type) (G : Bool → Type → Type) → ((A : Type) → F (G false A) A ≡ G false (F A A)) → (A : Type) → G false (F (G false A) A) ≡ G false (G false (F A A)) test₁₅ F G hyp A = G false (F (G false A) A) ≡⟨ by hyp ⟩∎ G false (G false (F A A)) ∎ -- test₁₇ : -- (P : ℕ → Type) -- (f : ∀ {n} → P n → P n) -- (p : P 0) → -- f (subst P refl p) ≡ f p -- test₁₇ P _ _ = by (subst-refl P) test₁₈ : (subst′ : ∀ {a p} {A : Type a} {x y : A} (P : A → Type p) → x ≡ y → P x → P y) → (∀ {a p} {A : Type a} {x : A} (P : A → Type p) (p : P x) → subst′ P refl p ≡ p) → (P : ℕ → Type) (f : ∀ {n} → P n → P n) (p : P 0) → f (subst′ P refl p) ≡ f p test₁₈ _ subst′-refl P _ _ = by (subst′-refl P) -- test₁₉ : -- {F : Type → Type} ⦃ r : R F ⦄ {A : Type} {x₁ x₂ : F A} -- (p₁ p₂ : x₁ ≡ x₂) (assumption : p₁ ≡ p₂) → -- trans p p₁ ≡ trans p p₂ -- test₁₉ p₁ p₂ assumption = -- trans p p₁ ≡⟨ by assumption ⟩∎ -- trans p p₂ ∎ -- Tests for ⟨by⟩. module ⟨By⟩-tests where -- At the time of writing the following test case works if the -- "cong-with-lhs-and-rhs" argument is true, but then test₁₈ -- fails. -- test₁ : ⟨ 40 + 2 ⟩ ≡ 42 -- test₁ = ⟨by⟩ refl test₂ : 48 ≡ 42 → ⟨ 42 ⟩ ≡ 48 test₂ eq = ⟨by⟩ eq test₃ : (f : ℕ → ℕ) → f ⟨ 42 ⟩ ≡ f 48 test₃ f = ⟨by⟩ assumption test₄ : (f : ℕ → ℕ) → f ⟨ 48 ⟩ ≡ f 42 test₄ f = ⟨by⟩ assumption test₅ : (f : ℕ → ℕ → ℕ) → f ⟨ 42 ⟩ ⟨ 42 ⟩ ≡ f 48 48 test₅ f = ⟨by⟩ assumption test₆ : (f : ℕ → ℕ → ℕ → ℕ) → f ⟨ 48 ⟩ 45 ⟨ 48 ⟩ ≡ f 42 45 42 test₆ f = ⟨by⟩ assumption test₇ : f ⟨ 48 ⟩ (f ⟨ 48 ⟩ 45 ⟨ 48 ⟩) ⟨ 48 ⟩ ≡ f 42 (f 42 45 42) 42 test₇ = ⟨by⟩ assumption test₈ : ∀ n → g n (g n 45 ⟨ 48 ⟩) ⟨ 48 ⟩ ≡ g n (g n 45 42) 42 test₈ n = ⟨by⟩ assumption test₉ : (f : ℕ → ℕ) → f ⟨ 42 ⟩ ≡ f 48 test₉ f = ⟨by⟩ (lemma 40) test₁₀ : (f : ℕ → ℕ) → f ⟨ 42 ⟩ ≡ f 48 test₁₀ f = ⟨by⟩ (λ (_ : ⊤) → assumption) test₁₁ : (f : ℕ × ℕ → ℕ × ℕ) → (∀ x → ⟨ _≡_ ⟩ (f x) x) → fst ⟨ f (12 , 73) ⟩ ≡ fst {B = λ _ → ℕ} (12 , 73) test₁₁ _ hyp = ⟨by⟩ hyp test₁₂ : (h : ℕ → Maybe ℕ) → ((xs : ℕ) → h xs ≡ just xs) → (xs : ℕ) → suc ⟨$⟩ h xs ≡ suc ⟨$⟩ return xs test₁₂ h hyp xs = suc ⟨$⟩ ⟨ h xs ⟩ ≡⟨ ⟨by⟩ (hyp xs) ⟩∎ suc ⟨$⟩ return xs ∎ test₁₃ : (h : List ⊤ → Maybe (List ⊤)) → ((xs : List ⊤) → h xs ≡ just xs) → (x : ⊤) (xs : List ⊤) → _ test₁₃ h hyp x xs = _∷_ ⟨$⟩ return x ⊛ ⟨ h xs ⟩ ≡⟨ ⟨by⟩ (hyp xs) ⟩∎ _∷_ ⟨$⟩ return x ⊛ return xs ∎ test₁₄ : (h : List ℕ → Maybe (List ℕ)) → ((xs : List ℕ) → h xs ≡ just xs) → (x : ℕ) (xs : List ℕ) → _ test₁₄ h hyp x xs = _∷_ ⟨$⟩ ⟨ h xs ⟩ ≡⟨ ⟨by⟩ (hyp xs) ⟩∎ _∷_ ⟨$⟩ return xs ∎ test₁₅ : (F : Type → Type → Type) (G : Bool → Type → Type) → ((A : Type) → F (G false A) A ≡ G false (F A A)) → (A : Type) → G false (F (G false A) A) ≡ G false (G false (F A A)) test₁₅ F G hyp A = G false ⟨ F (G false A) A ⟩ ≡⟨ ⟨by⟩ hyp ⟩∎ G false (G false (F A A)) ∎ test₁₆ : 48 ≡ 42 → _≡_ {A = ℕ → ℕ} (λ x → x + ⟨ 42 ⟩) (λ x → x + 48) test₁₆ hyp = ⟨by⟩ hyp test₁₇ : (P : ℕ → Type) (f : ∀ {n} → P n → P n) (p : P 0) → f ⟨ subst P refl p ⟩ ≡ f p test₁₇ P _ _ = ⟨by⟩ (subst-refl P) test₁₈ : (subst′ : ∀ {a p} {A : Type a} {x y : A} (P : A → Type p) → x ≡ y → P x → P y) → (∀ {a p} {A : Type a} {x : A} (P : A → Type p) (p : P x) → subst′ P refl p ≡ p) → (P : ℕ → Type) (f : ∀ {n} → P n → P n) (p : P 0) → f ⟨ subst′ P refl p ⟩ ≡ f p test₁₈ _ subst′-refl _ _ _ = ⟨by⟩ subst′-refl test₁₉ : {F : Type → Type} ⦃ r : R F ⦄ {A : Type} {x₁ x₂ : F A} (p₁ p₂ : x₁ ≡ x₂) (assumption : p₁ ≡ p₂) → trans p p₁ ≡ trans p p₂ test₁₉ p₁ p₂ assumption = trans p p₁ ≡⟨⟩ trans p ⟨ p₁ ⟩ ≡⟨ ⟨by⟩ assumption ⟩∎ trans p p₂ ∎
30.518293
73
0.463836
217ce689042fb6ba6ffc8fde87a5b16c8970f432
1,216
agda
Agda
src/Human/Nat.agda
MaisaMilena/JuiceMaker
b509eb4c4014605facfb4ee5c807cd07753d4477
[ "MIT" ]
6
2019-03-29T17:35:20.000Z
2020-11-28T05:46:27.000Z
src/Human/Nat.agda
MaisaMilena/AgdaCalculator
e977a5f2a005682cee123568b49462dd7d7b11ad
[ "MIT" ]
null
null
null
src/Human/Nat.agda
MaisaMilena/AgdaCalculator
e977a5f2a005682cee123568b49462dd7d7b11ad
[ "MIT" ]
null
null
null
module Human.Nat where open import Human.Bool data Nat : Set where zero : Nat suc : Nat → Nat {-# BUILTIN NATURAL Nat #-} infix 4 _==_ _<_ infixl 6 _+_ _-_ infixl 7 _*_ -- add theses guys on infixl 7: _div_ _%_ _+_ : Nat → Nat → Nat zero + m = m suc n + m = suc (n + m) {-# BUILTIN NATPLUS _+_ #-} _-_ : Nat → Nat → Nat n - zero = n zero - suc m = zero suc n - suc m = n - m {-# BUILTIN NATMINUS _-_ #-} _*_ : Nat → Nat → Nat zero * m = zero suc n * m = m + n * m {-# BUILTIN NATTIMES _*_ #-} _==_ : Nat → Nat → Bool zero == zero = true suc n == suc m = n == m _ == _ = false {-# BUILTIN NATEQUALS _==_ #-} _<_ : Nat → Nat → Bool _ < zero = false zero < suc _ = true suc n < suc m = n < m {-# BUILTIN NATLESS _<_ #-} div-helper : (k m n j : Nat) → Nat div-helper k m zero j = k div-helper k m (suc n) zero = div-helper (suc k) m n m div-helper k m (suc n) (suc j) = div-helper k m n j {-# BUILTIN NATDIVSUCAUX div-helper #-} mod-helper : (k m n j : Nat) → Nat mod-helper k m zero j = k mod-helper k m (suc n) zero = mod-helper 0 m n m mod-helper k m (suc n) (suc j) = mod-helper (suc k) m n j {-# BUILTIN NATMODSUCAUX mod-helper #-}
19.612903
57
0.550987
6470798e28e7750b6639dc66d62aab4a6052311f
448
agda
Agda
test/asset/agda-stdlib-1.0/Data/ReflexiveClosure.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/ReflexiveClosure.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/ReflexiveClosure.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Reflexive closures -- -- This module is DEPRECATED. Please use the -- Relation.Binary.Construct.Closure.Reflexive module directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.ReflexiveClosure where open import Relation.Binary.Construct.Closure.Reflexive public
29.866667
72
0.515625
1a06f1ca47dc9b4943297b138f9ba956e2d743d1
3,469
agda
Agda
notes/thesis/report/LogicalFramework/Existential.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/thesis/report/LogicalFramework/Existential.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/thesis/report/LogicalFramework/Existential.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module LogicalFramework.Existential where module LF where postulate D : Set -- Disjunction. _∨_ : Set → Set → Set inj₁ : {A B : Set} → A → A ∨ B inj₂ : {A B : Set} → B → A ∨ B case : {A B C : Set} → (A → C) → (B → C) → A ∨ B → C -- The existential quantifier type on D. ∃ : (A : D → Set) → Set _,_ : {A : D → Set}(t : D) → A t → ∃ A ∃-proj₁ : {A : D → Set} → ∃ A → D ∃-proj₂ : {A : D → Set}(h : ∃ A) → A (∃-proj₁ h) ∃-elim : {A : D → Set}{B : Set} → ∃ A → (∀ {x} → A x → B) → B syntax ∃ (λ x → e) = ∃[ x ] e module FOL-Examples where -- Using the projections. ∃∀₁ : {A : D → D → Set} → ∃[ x ](∀ y → A x y) → ∀ y → ∃[ x ] A x y ∃∀₁ h y = ∃-proj₁ h , (∃-proj₂ h) y ∃∨₁ : {A B : D → Set} → ∃[ x ](A x ∨ B x) → (∃[ x ] A x) ∨ (∃[ x ] B x) ∃∨₁ h = case (λ Ax → inj₁ (∃-proj₁ h , Ax)) (λ Bx → inj₂ (∃-proj₁ h , Bx)) (∃-proj₂ h) -- Using the elimination. ∃∀₂ : {A : D → D → Set} → ∃[ x ](∀ y → A x y) → ∀ y → ∃[ x ] A x y ∃∀₂ h y = ∃-elim h (λ {x} ah → x , ah y) ∃∨₂ : {A B : D → Set} → ∃[ x ](A x ∨ B x) → (∃[ x ] A x) ∨ (∃[ x ] B x) ∃∨₂ h = ∃-elim h (λ {x} ah → case (λ Ax → inj₁ (x , Ax)) (λ Bx → inj₂ (x , Bx)) ah) module NonFOL-Examples where -- Using the projections. non-FOL₁ : {A : D → Set} → ∃ A → D non-FOL₁ h = ∃-proj₁ h -- Using the elimination. non-FOL₂ : {A : D → Set} → ∃ A → D non-FOL₂ h = ∃-elim h (λ {x} _ → x) module Inductive where open import Common.FOL.FOL -- The existential proyections. ∃-proj₁ : ∀ {A} → ∃ A → D ∃-proj₁ (x , _) = x ∃-proj₂ : ∀ {A} → (h : ∃ A) → A (∃-proj₁ h) ∃-proj₂ (_ , Ax) = Ax -- The existential elimination. ∃-elim : {A : D → Set}{B : Set} → ∃ A → (∀ {x} → A x → B) → B ∃-elim (_ , Ax) h = h Ax module FOL-Examples where -- Using the projections. ∃∀₁ : {A : D → D → Set} → ∃[ x ](∀ y → A x y) → ∀ y → ∃[ x ] A x y ∃∀₁ h y = ∃-proj₁ h , (∃-proj₂ h) y ∃∨₁ : {A B : D → Set} → ∃[ x ](A x ∨ B x) → (∃[ x ] A x) ∨ (∃[ x ] B x) ∃∨₁ h = case (λ Ax → inj₁ (∃-proj₁ h , Ax)) (λ Bx → inj₂ (∃-proj₁ h , Bx)) (∃-proj₂ h) -- Using the elimination. ∃∀₂ : {A : D → D → Set} → ∃[ x ](∀ y → A x y) → ∀ y → ∃[ x ] A x y ∃∀₂ h y = ∃-elim h (λ {x} ah → x , ah y) ∃∨₂ : {A B : D → Set} → ∃[ x ](A x ∨ B x) → (∃[ x ] A x) ∨ (∃[ x ] B x) ∃∨₂ h = ∃-elim h (λ {x} ah → case (λ Ax → inj₁ (x , Ax)) (λ Bx → inj₂ (x , Bx)) ah) -- Using pattern matching. ∃∀₃ : {A : D → D → Set} → ∃[ x ](∀ y → A x y) → ∀ y → ∃[ x ] A x y ∃∀₃ (x , Ax) y = x , Ax y ∃∨₃ : {A B : D → Set} → ∃[ x ](A x ∨ B x) → (∃[ x ] A x) ∨ (∃[ x ] B x) ∃∨₃ (x , inj₁ Ax) = inj₁ (x , Ax) ∃∨₃ (x , inj₂ Bx) = inj₂ (x , Bx) module NonFOL-Examples where -- Using the projections. non-FOL₁ : {A : D → Set} → ∃ A → D non-FOL₁ h = ∃-proj₁ h -- Using the elimination. non-FOL₂ : {A : D → Set} → ∃ A → D non-FOL₂ h = ∃-elim h (λ {x} _ → x) -- Using the pattern matching. non-FOL₃ : {A : D → Set} → ∃ A → D non-FOL₃ (x , _) = x
31.252252
75
0.388873
4b1ea372ff07c0017da7c001c6fe12632a5e0342
662
agda
Agda
Source/ALL/Languages/FILL/TypeSyntax.agda
heades/Agda-LLS
c83f5d8201362b26a749138f6dbff2dd509f85b1
[ "BSD-3-Clause" ]
3
2017-04-09T20:53:53.000Z
2019-08-02T23:41:23.000Z
Source/ALL/Languages/FILL/TypeSyntax.agda
heades/Agda-LLS
c83f5d8201362b26a749138f6dbff2dd509f85b1
[ "BSD-3-Clause" ]
2
2017-03-27T14:52:46.000Z
2017-04-05T17:30:16.000Z
Source/ALL/Languages/FILL/TypeSyntax.agda
heades/Agda-LLS
c83f5d8201362b26a749138f6dbff2dd509f85b1
[ "BSD-3-Clause" ]
null
null
null
module Languages.FILL.TypeSyntax where open import Utils.HaskellTypes {-# IMPORT Languages.FILL.TypeSyntax #-} data Type : Set where TVar : String → Type Top : Type Bottom : Type Imp : Type → Type → Type Tensor : Type → Type → Type Par : Type → Type → Type {-# COMPILED_DATA Type Languages.FILL.TypeSyntax.Type Languages.FILL.TypeSyntax.TVar Languages.FILL.TypeSyntax.Top Languages.FILL.TypeSyntax.Bottom Languages.FILL.TypeSyntax.Imp Languages.FILL.TypeSyntax.Tensor Languages.FILL.TypeSyntax.Par #-}
30.090909
56
0.592145
7221a9b014332cdf3c83b634b1595168480b2e3a
5,681
agda
Agda
Cubical/Data/FinSet/Constructors.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:29:41.000Z
2022-03-05T00:29:41.000Z
Cubical/Data/FinSet/Constructors.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/Data/FinSet/Constructors.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
{- Closure properties of FinSet under several type constructors. -} {-# OPTIONS --safe #-} module Cubical.Data.FinSet.Constructors where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv open import Cubical.HITs.PropositionalTruncation renaming (rec to TruncRec) open import Cubical.Data.Nat open import Cubical.Data.Unit open import Cubical.Data.Empty renaming (rec to EmptyRec) open import Cubical.Data.Sum open import Cubical.Data.Sigma open import Cubical.Data.Fin open import Cubical.Data.SumFin renaming (Fin to SumFin) hiding (discreteFin) open import Cubical.Data.FinSet.Base open import Cubical.Data.FinSet.Properties open import Cubical.Data.FinSet.FiniteChoice open import Cubical.Relation.Nullary open import Cubical.Functions.Embedding open import Cubical.Functions.Surjection private variable ℓ ℓ' ℓ'' ℓ''' : Level module _ (X : Type ℓ)(p : ≃Fin X) where ≃Fin∥∥ : ≃Fin ∥ X ∥ ≃Fin∥∥ = ≃SumFin→Fin (_ , compEquiv (propTrunc≃ (≃Fin→SumFin p .snd)) (SumFin∥∥≃ _)) module _ (X : Type ℓ )(p : ≃Fin X) (Y : Type ℓ')(q : ≃Fin Y) where ≃Fin⊎ : ≃Fin (X ⊎ Y) ≃Fin⊎ = ≃SumFin→Fin (_ , compEquiv (⊎-equiv (≃Fin→SumFin p .snd) (≃Fin→SumFin q .snd)) (SumFin⊎≃ _ _)) ≃Fin× : ≃Fin (X × Y) ≃Fin× = ≃SumFin→Fin (_ , compEquiv (Σ-cong-equiv (≃Fin→SumFin p .snd) (λ _ → ≃Fin→SumFin q .snd)) (SumFin×≃ _ _)) module _ (X : Type ℓ )(p : ≃Fin X) (Y : X → Type ℓ')(q : (x : X) → ≃Fin (Y x)) where private p' = ≃Fin→SumFin p m = p' .fst e = p' .snd q' : (x : X) → ≃SumFin (Y x) q' x = ≃Fin→SumFin (q x) f : (x : X) → ℕ f x = q' x .fst ≃SumFinΣ : ≃SumFin (Σ X Y) ≃SumFinΣ = _ , Σ-cong-equiv {B' = λ x → Y (invEq (p' .snd) x)} (p' .snd) (transpFamily p') ⋆ Σ-cong-equiv-snd (λ x → q' (invEq e x) .snd) ⋆ SumFinΣ≃ _ _ ≃SumFinΠ : ≃SumFin ((x : X) → Y x) ≃SumFinΠ = _ , equivΠ {B' = λ x → Y (invEq (p' .snd) x)} (p' .snd) (transpFamily p') ⋆ equivΠCod (λ x → q' (invEq e x) .snd) ⋆ SumFinΠ≃ _ _ ≃FinΣ : ≃Fin (Σ X Y) ≃FinΣ = ≃SumFin→Fin ≃SumFinΣ ≃FinΠ : ≃Fin ((x : X) → Y x) ≃FinΠ = ≃SumFin→Fin ≃SumFinΠ module _ (X : FinSet ℓ) (Y : X .fst → FinSet ℓ') where isFinSetΣ : isFinSet (Σ (X .fst) (λ x → Y x .fst)) isFinSetΣ = elim2 (λ _ _ → isPropIsFinSet {A = Σ (X .fst) (λ x → Y x .fst)}) (λ p q → ∣ ≃FinΣ (X .fst) p (λ x → Y x .fst) q ∣) (X .snd) (choice X (λ x → ≃Fin (Y x .fst)) (λ x → Y x .snd)) isFinSetΠ : isFinSet ((x : X .fst) → Y x .fst) isFinSetΠ = elim2 (λ _ _ → isPropIsFinSet {A = ((x : X .fst) → Y x .fst)}) (λ p q → ∣ ≃FinΠ (X .fst) p (λ x → Y x .fst) q ∣) (X .snd) (choice X (λ x → ≃Fin (Y x .fst)) (λ x → Y x .snd)) module _ (X : FinSet ℓ) (Y : X .fst → FinSet ℓ') (Z : (x : X .fst) → Y x .fst → FinSet ℓ'') where isFinSetΠ2 : isFinSet ((x : X .fst) → (y : Y x .fst) → Z x y .fst) isFinSetΠ2 = isFinSetΠ X (λ x → _ , isFinSetΠ (Y x) (Z x)) module _ (X : FinSet ℓ) (Y : X .fst → FinSet ℓ') (Z : (x : X .fst) → Y x .fst → FinSet ℓ'') (W : (x : X .fst) → (y : Y x .fst) → Z x y .fst → FinSet ℓ''') where isFinSetΠ3 : isFinSet ((x : X .fst) → (y : Y x .fst) → (z : Z x y .fst) → W x y z .fst) isFinSetΠ3 = isFinSetΠ X (λ x → _ , isFinSetΠ2 (Y x) (Z x) (W x)) module _ (X : FinSet ℓ) where isFinSet≡ : (a b : X .fst) → isFinSet (a ≡ b) isFinSet≡ a b = isDecProp→isFinSet (isFinSet→isSet (X .snd) a b) (isFinSet→Discrete (X .snd) a b) isFinSetIsContr : isFinSet (isContr (X .fst)) isFinSetIsContr = isFinSetΣ X (λ x → _ , (isFinSetΠ X (λ y → _ , isFinSet≡ x y))) isFinSet∥∥ : isFinSet ∥ X .fst ∥ isFinSet∥∥ = TruncRec isPropIsFinSet (λ p → ∣ ≃Fin∥∥ (X .fst) p ∣) (X .snd) module _ (X : FinSet ℓ ) (Y : FinSet ℓ') (f : X .fst → Y .fst) where isFinSetFiber : (y : Y .fst) → isFinSet (fiber f y) isFinSetFiber y = isFinSetΣ X (λ x → _ , isFinSet≡ Y (f x) y) isFinSetIsEquiv : isFinSet (isEquiv f) isFinSetIsEquiv = EquivPresIsFinSet (invEquiv (isEquiv≃isEquiv' f)) (isFinSetΠ Y (λ y → _ , isFinSetIsContr (_ , isFinSetFiber y))) module _ (X : FinSet ℓ ) (Y : FinSet ℓ') where isFinSet⊎ : isFinSet (X .fst ⊎ Y .fst) isFinSet⊎ = elim2 (λ _ _ → isPropIsFinSet) (λ p q → ∣ ≃Fin⊎ (X .fst) p (Y .fst) q ∣) (X .snd) (Y .snd) isFinSet× : isFinSet (X .fst × Y .fst) isFinSet× = elim2 (λ _ _ → isPropIsFinSet) (λ p q → ∣ ≃Fin× (X .fst) p (Y .fst) q ∣) (X .snd) (Y .snd) isFinSet→ : isFinSet (X .fst → Y .fst) isFinSet→ = isFinSetΠ X (λ _ → Y) isFinSet≃ : isFinSet (X .fst ≃ Y .fst) isFinSet≃ = isFinSetΣ (_ , isFinSet→) (λ f → _ , isFinSetIsEquiv X Y f) module _ (X : FinSet ℓ) where isFinSet¬ : isFinSet (¬ (X .fst)) isFinSet¬ = isFinSet→ X (⊥ , ∣ 0 , uninhabEquiv (λ x → x) ¬Fin0 ∣) module _ (X : FinSet ℓ) where isFinSetNonEmpty : isFinSet (NonEmpty (X .fst)) isFinSetNonEmpty = isFinSet¬ (_ , isFinSet¬ X) module _ (X : FinSet ℓ ) (Y : FinSet ℓ') (f : X .fst → Y .fst) where isFinSetIsEmbedding : isFinSet (isEmbedding f) isFinSetIsEmbedding = isFinSetΠ2 X (λ _ → X) (λ a b → _ , isFinSetIsEquiv (_ , isFinSet≡ X a b) (_ , isFinSet≡ Y (f a) (f b)) (cong f)) isFinSetIsSurjection : isFinSet (isSurjection f) isFinSetIsSurjection = isFinSetΠ Y (λ y → _ , isFinSet∥∥ (_ , isFinSetFiber X Y f y)) module _ (X : FinSet ℓ ) (Y : FinSet ℓ') where isFinSet↪ : isFinSet (X .fst ↪ Y .fst) isFinSet↪ = isFinSetΣ (_ , isFinSet→ X Y) (λ f → _ , isFinSetIsEmbedding X Y f) isFinSet↠ : isFinSet (X .fst ↠ Y .fst) isFinSet↠ = isFinSetΣ (_ , isFinSet→ X Y) (λ f → _ , isFinSetIsSurjection X Y f)
28.837563
115
0.582644
65018fec56aa8bd1bee8a54723d6169cd91e062b
2,043
agda
Agda
Test01.agda
righ1113/Agda
9117b6bec9880d8c0a5d6ee4399fd841c3544d84
[ "MIT" ]
null
null
null
Test01.agda
righ1113/Agda
9117b6bec9880d8c0a5d6ee4399fd841c3544d84
[ "MIT" ]
null
null
null
Test01.agda
righ1113/Agda
9117b6bec9880d8c0a5d6ee4399fd841c3544d84
[ "MIT" ]
null
null
null
module Test01 where hoge : {A : Set} → A → A hoge x = x open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; subst) open import Function using (id) lemma1 : {X Y : Set} → (X ≡ (X → Y)) → X lemma1 p rewrite p = (λ x → let f = subst id p x in f x) curry : {X Y : Set} → (X ≡ (X → Y)) → Y curry p = (let f = subst id p (lemma1 p) in f (lemma1 p)) open import Data.Bool open import Data.Nat open import Data.Empty postulate First : ℕ → Set All : ℕ → Set fToA : ((n : ℕ) → First n) → ((n : ℕ) → All n) fToA2 : (z : ℕ) → (First z → All z) tekito : (z : ℕ) → ((All z → ⊥) → (First z → ⊥)) → First (suc z) contra : (z : ℕ) → ((All z → ⊥) → (First z → ⊥)) → (First z → All z) mutual -- 失敗 contraFirstToAll : (z : ℕ) → ((All z → ⊥) → (First z → ⊥)) -- contraFirstToAll z allToVoid _ = let foo = (contra z (contraFirstToAll z)) (limitedDivSeq z) in allToVoid foo contraFirstToAll z allToVoid _ = let foo = fToA (λ k → limitedDivSeq k) in allToVoid (foo z) limitedDivSeq : (n : ℕ) → First n limitedDivSeq zero = {! !} limitedDivSeq (suc n) = let bar = contraFirstToAll n in tekito n bar -- Idris {- postulate foo : (t : Nat) -> LT' t (S t) contraFirstToAll : (z : Nat) -> (((AllLimited . B.allDivSeq) z -> Void) -> ((FirstLimited . B.allDivSeq) z -> Void)) contraFirstToAll Z allToVoid _ = allToVoid IsAllLimited00 contraFirstToAll (S z) _ _ = wfInd {P=(\z=>Void)} {rel=LT'} step (S z) where step : (x : Nat) -> ((y : Nat) -> LT' y x -> Void) -> Void step Z _ = believe_me "ここには来ない" step (S x) rs = rs x (foo x) -- ?rhs1 が書けない!! contraFirstToAll : (z : Nat) -> (((AllLimited . B.allDivSeq) z -> Void) -> ((FirstLimited . B.allDivSeq) z -> Void)) contraFirstToAll Z allToVoid _ = allToVoid IsAllLimited00 contraFirstToAll (S z) _ _ = step (S z) SIsNotZ (wellFounded {rel=LT'} (S z)) where step : (x : Nat) -> Not (x = Z) -> Accessible LT' x -> Void step Z p _ = void (p Refl) step (S x) p (Access rs) = step x ?rhs1 (rs x (foo x)) -}
37.145455
115
0.582477
651dec7e6c5f0bff8fac0b2aa7a73bedb86c63b2
315
agda
Agda
test/Succeed/Issue3109.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
1
2021-07-07T10:49:57.000Z
2021-07-07T10:49:57.000Z
test/Succeed/Issue3109.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue3109.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --allow-unsolved-metas #-} postulate Nat : Set Fin : Nat → Set Foo : (n : Nat) → Fin n → Set Bar : ∀ {n m} → Foo n m → Set variable n : Nat m : Fin _ k : Foo _ m l : Foo n m open import Agda.Builtin.Equality postulate goal-type-error : Bar k foo : Bar _ foo = goal-type-error _ _
14.318182
38
0.587302
ccac0d822a4460c969100d433711a4f3d659f49b
2,366
agda
Agda
src/Data/Maybe/Instance.agda
banacorn/FAM
e5e562e4cde2face1f3f5b6d0486c8c56a47b435
[ "MIT" ]
null
null
null
src/Data/Maybe/Instance.agda
banacorn/FAM
e5e562e4cde2face1f3f5b6d0486c8c56a47b435
[ "MIT" ]
null
null
null
src/Data/Maybe/Instance.agda
banacorn/FAM
e5e562e4cde2face1f3f5b6d0486c8c56a47b435
[ "MIT" ]
null
null
null
module Data.Maybe.Instance where open import Category.FAM open import Data.Maybe open import Function using (_∘_; id) open import Relation.Binary.PropositionalEquality instance MaybeFunctor : ∀ {ℓ} → Functor {ℓ} Maybe MaybeFunctor {ℓ} = record { _<$>_ = map ; isFunctor = record { identity = identity ; homo = homo } } where identity : ∀ {A : Set ℓ} (a : Maybe A) → map id a ≡ a identity (just x) = refl identity nothing = refl homo : ∀ {A B C : Set ℓ} (f : B → C) (g : A → B) (a : Maybe A) → map (f ∘ g) a ≡ map f (map g a) homo _ _ (just x) = refl homo _ _ nothing = refl MaybeApplicative : ∀ {ℓ} → Applicative {ℓ} Maybe MaybeApplicative {ℓ} = record { pure = just ; _⊛_ = ap ; isApplicative = record { identity = identity ; compose = compose ; homo = λ _ _ → refl ; interchange = interchange } } where open ≡-Reasoning open import Function ap : {A B : Set ℓ} → Maybe (A → B) → Maybe A → Maybe B ap (just f) x = map f x ap nothing x = nothing identity : {A : Set ℓ} (x : Maybe A) → map id x ≡ x identity (just x) = refl identity nothing = refl compose : {A B C : Set ℓ} (fs : Maybe (B → C)) (gs : Maybe (A → B)) → (xs : Maybe A) → ap (ap (map _∘′_ fs) gs) xs ≡ ap fs (ap gs xs) compose {A} {B} {C} (just fs) (just gs) (just xs) = refl compose {A} {B} {C} (just fs) (just gs) nothing = refl compose {A} {B} {C} (just fs) nothing (just xs) = refl compose {A} {B} {C} (just fs) nothing nothing = refl compose {A} {B} {C} nothing (just gs) (just xs) = refl compose {A} {B} {C} nothing (just gs) nothing = refl compose {A} {B} {C} nothing nothing (just xs) = refl compose {A} {B} {C} nothing nothing nothing = refl interchange : {A B : Set ℓ} (fs : Maybe (A → B)) (x : A) → ap fs (just x) ≡ ap (just (λ f → f x)) fs interchange {A} {B} (just f) x = refl interchange {A} {B} nothing x = refl
35.848485
112
0.470414
4e920f84871f3e8832a094fb38fd3045fb1ce2bc
1,709
agda
Agda
examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Nat.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T04:41:05.000Z
2019-11-27T04:41:05.000Z
examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Nat.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Nat.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
module Data.Nat where import Prelude import Data.Bool as Bool open Prelude open Bool data Nat : Set where zero : Nat suc : Nat -> Nat {-# BUILTIN NATURAL Nat #-} {-# BUILTIN SUC suc #-} {-# BUILTIN ZERO zero #-} infix 40 _==_ _<_ _≤_ _>_ _≥_ infixl 60 _+_ _-_ infixl 70 _*_ infixr 80 _^_ infix 100 _! _+_ : Nat -> Nat -> Nat zero + m = m suc n + m = suc (n + m) _-_ : Nat -> Nat -> Nat zero - m = zero suc n - zero = suc n suc n - suc m = n - m _*_ : Nat -> Nat -> Nat zero * m = zero suc n * m = m + n * m _^_ : Nat -> Nat -> Nat n ^ zero = 1 n ^ suc m = n * n ^ m _! : Nat -> Nat zero ! = 1 suc n ! = suc n * n ! {-# BUILTIN NATPLUS _+_ #-} {-# BUILTIN NATMINUS _-_ #-} {-# BUILTIN NATTIMES _*_ #-} _==_ : Nat -> Nat -> Bool zero == zero = true zero == suc _ = false suc _ == zero = false suc n == suc m = n == m _<_ : Nat -> Nat -> Bool n < zero = false zero < suc m = true suc n < suc m = n < m _≤_ : Nat -> Nat -> Bool n ≤ m = n < suc m _>_ = flip _<_ _≥_ = flip _≤_ {-# BUILTIN NATEQUALS _==_ #-} {-# BUILTIN NATLESS _<_ #-} divSuc : Nat -> Nat -> Nat divSuc zero _ = zero divSuc (suc n) m = 1 + divSuc (n - m) m modSuc : Nat -> Nat -> Nat modSuc zero _ = zero modSuc (suc n) m = ! n ≤ m => suc n ! otherwise modSuc (n - m) m {-# BUILTIN NATDIVSUC divSuc #-} -- {-# BUILTIN NATMODSUC modSuc #-} div : Nat -> Nat -> Nat div n zero = zero div n (suc m) = divSuc n m mod : Nat -> Nat -> Nat mod n zero = zero mod n (suc m) = modSuc n m gcd : Nat -> Nat -> Nat gcd a 0 = a gcd a b = gcd b (mod a b) lcm : Nat -> Nat -> Nat lcm a b = div (a * b) (gcd a b) even : Nat -> Bool even n = mod n 2 == 0 odd : Nat -> Bool odd n = mod n 2 == 1
16.592233
39
0.53306
6510b9a955a5169d447aef69bc848e4a7c7ab6a8
2,271
agda
Agda
out/STLC/Model.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
39
2021-11-09T20:39:55.000Z
2022-03-19T17:33:12.000Z
out/STLC/Model.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
1
2021-11-21T12:19:32.000Z
2021-11-21T12:19:32.000Z
out/STLC/Model.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
4
2021-11-09T20:39:59.000Z
2022-01-24T12:49:17.000Z
-- Environment model of the STLC module STLC.Model where open import SOAS.Common open import SOAS.Context open import SOAS.Variable open import SOAS.Families.Core open import SOAS.Families.Build open import SOAS.ContextMaps.Inductive open import SOAS.Abstract.Monoid open import SOAS.Coalgebraic.Lift open import STLC.Signature open import STLC.Syntax open import SOAS.Metatheory.SecondOrder.Metasubstitution Λ:Syn open import SOAS.Metatheory.SecondOrder.Equality Λ:Syn open import SOAS.Metatheory.FreeMonoid Λ:Syn open import SOAS.Syntax.Arguments open import Data.Nat private variable α β γ τ : ΛT Γ Δ Π : Ctx 𝔛 : Familyₛ Λᴳ : Familyₛ Λᴳ = Λ Ø -- Interpretation of types and contexts ⟦_⟧ : ΛT → Set ⟦ N ⟧ = ℕ ⟦ α ↣ β ⟧ = ⟦ α ⟧ → ⟦ β ⟧ ⟦_⟧ᶜ : Ctx → Set ⟦ Γ ⟧ᶜ = {α : ΛT} → ℐ α Γ → ⟦ α ⟧ _⁺_ : ⟦ α ⟧ → ⟦ Γ ⟧ᶜ → ⟦ α ∙ Γ ⟧ᶜ _⁺_ x γ new = x _⁺_ x γ (old v) = γ v infixr 10 _⁺_ -- Environment model Env : Familyₛ Env α Γ = ⟦ Γ ⟧ᶜ → ⟦ α ⟧ ΣEnvᴹ : ΣMon Env ΣEnvᴹ = record { ᵐ = record { η = λ v γ → γ v ; μ = λ t σ δ → t (λ v → σ v δ) ; lunit = refl ; runit = refl ; assoc = refl } ; 𝑎𝑙𝑔 = λ{ (appₒ ⋮ f , a) γ → f γ (a γ) ; (lamₒ ⋮ b) γ → λ a → b (a ⁺ γ) } ; μ⟨𝑎𝑙𝑔⟩ = λ{ (appₒ ⋮ _) → refl ; (lamₒ ⋮ b) → ext² λ δ a → cong b (dext (λ { new → refl ; (old y) → refl })) } } module Env = FΣM Ø ΣEnvᴹ (λ ()) eval : Λ Ø ⇾̣ Env eval = Env.𝕖𝕩𝕥 evalᶜ : Λ Ø α ∅ → ⟦ α ⟧ evalᶜ t = eval t (λ ()) _ : evalᶜ {N ↣ N ↣ N} (ƛ ƛ x₁) ≡ λ x y → x _ = refl open Theory Ø -- Operational semantics of the STLC data Value : Λᴳ α Γ → Set where lamⱽ : {b : Λᴳ β (α ∙ Γ)} → Value (ƛ b) data _⟿_ : Λᴳ α Γ → Λᴳ α Γ → Set where ζ-$₁ : {f g : Λᴳ (α ↣ β) Γ}{a : Λᴳ α Γ} → f ⟿ g → f $ a ⟿ g $ a ζ-$₂ : {f : Λᴳ (α ↣ β) Γ}{a b : Λᴳ α Γ} → Value f → a ⟿ b → f $ a ⟿ f $ b β-ƛ : {b : Λᴳ β (α ∙ Γ)}{t : Λᴳ α Γ} → Value t → ((ƛ b) $ t) ⟿ [ t /] b infix 2 _⟿_ -- Evaluation preserves the meaning of terms sound : {t s : Λᴳ α Γ} → t ⟿ s → (γ : ⟦ Γ ⟧ᶜ) → eval t γ ≡ eval s γ sound (ζ-$₁ r) γ rewrite sound r γ = refl sound (ζ-$₂ _ r) γ rewrite sound r γ = refl sound (β-ƛ {b = b}{t} x) γ rewrite Env.𝕖𝕩𝕥ᵐ⇒.sub-lemma t b = cong (eval b) (dext λ{ new → refl ; (old v) → refl })
24.159574
68
0.55218
72b2382f7bb7a41f02d8d7408a6158ca80113e0c
524
agda
Agda
test/Fail/TerminationCheckUnquoteDecl.agda
vlopezj/agda
ff4d89e75970cf27599fb9f572bd43c9455cbb56
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Fail/TerminationCheckUnquoteDecl.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Fail/TerminationCheckUnquoteDecl.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
-- Check that unquoted functions are termination checked. module _ where open import Common.Prelude hiding (_>>=_) open import Common.Reflection `⊥ : Type `⊥ = def (quote ⊥) [] {- Generate aux : ⊥ aux = aux loop : ⊥ loop = aux -} makeLoop : QName → TC ⊤ makeLoop loop = freshName "aux" >>= λ aux → declareDef (vArg aux) `⊥ >>= λ _ → defineFun aux (clause [] (def aux []) ∷ []) >>= λ _ → declareDef (vArg loop) `⊥ >>= λ _ → defineFun loop (clause [] (def aux []) ∷ []) unquoteDecl loop = makeLoop loop
19.407407
57
0.603053
3702b53373e38bd4a593c2701e84b83ac841e0cf
3,273
agda
Agda
Definition/LogicalRelation/Substitution/Introductions/Application.agda
fhlkfy/logrel-mltt
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
[ "MIT" ]
30
2017-05-20T03:05:21.000Z
2022-03-30T18:01:07.000Z
Definition/LogicalRelation/Substitution/Introductions/Application.agda
fhlkfy/logrel-mltt
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
[ "MIT" ]
4
2017-06-22T12:49:23.000Z
2021-02-22T10:37:24.000Z
Definition/LogicalRelation/Substitution/Introductions/Application.agda
fhlkfy/logrel-mltt
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
[ "MIT" ]
8
2017-10-18T14:18:20.000Z
2021-11-27T15:58:33.000Z
{-# OPTIONS --without-K --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution.Introductions.Application {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped hiding (_∷_) open import Definition.Untyped.Properties open import Definition.Typed open import Definition.LogicalRelation open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Properties open import Definition.LogicalRelation.Application open import Definition.LogicalRelation.Substitution open import Definition.LogicalRelation.Substitution.Introductions.SingleSubst open import Tools.Nat open import Tools.Product import Tools.PropositionalEquality as PE private variable n : Nat Γ : Con Term n -- Application of valid terms. appᵛ : ∀ {F G t u l} ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ]) ([ΠFG] : Γ ⊩ᵛ⟨ l ⟩ Π F ▹ G / [Γ]) ([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ Π F ▹ G / [Γ] / [ΠFG]) ([u] : Γ ⊩ᵛ⟨ l ⟩ u ∷ F / [Γ] / [F]) → Γ ⊩ᵛ⟨ l ⟩ t ∘ u ∷ G [ u ] / [Γ] / substSΠ {F = F} {G} {u} BΠ [Γ] [F] [ΠFG] [u] appᵛ {F = F} {G} {t} {u} [Γ] [F] [ΠFG] [t] [u] {σ = σ} ⊢Δ [σ] = let [G[u]] = substSΠ {F = F} {G} {u} BΠ [Γ] [F] [ΠFG] [u] [σF] = proj₁ ([F] ⊢Δ [σ]) [σΠFG] = proj₁ ([ΠFG] ⊢Δ [σ]) [σt] = proj₁ ([t] ⊢Δ [σ]) [σu] = proj₁ ([u] ⊢Δ [σ]) [σG[u]] = proj₁ ([G[u]] ⊢Δ [σ]) [σG[u]]′ = irrelevance′ (singleSubstLift G u) [σG[u]] in irrelevanceTerm′ (PE.sym (singleSubstLift G u)) [σG[u]]′ [σG[u]] (appTerm [σF] [σG[u]]′ [σΠFG] [σt] [σu]) , (λ [σ′] [σ≡σ′] → let [σu′] = convTerm₂ [σF] (proj₁ ([F] ⊢Δ [σ′])) (proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′]) (proj₁ ([u] ⊢Δ [σ′])) in irrelevanceEqTerm′ (PE.sym (singleSubstLift G u)) [σG[u]]′ [σG[u]] (app-congTerm [σF] [σG[u]]′ [σΠFG] (proj₂ ([t] ⊢Δ [σ]) [σ′] [σ≡σ′]) [σu] [σu′] (proj₂ ([u] ⊢Δ [σ]) [σ′] [σ≡σ′]))) -- Application congruence of valid terms. app-congᵛ : ∀ {F G t u a b l} ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ]) ([ΠFG] : Γ ⊩ᵛ⟨ l ⟩ Π F ▹ G / [Γ]) ([t≡u] : Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ Π F ▹ G / [Γ] / [ΠFG]) ([a] : Γ ⊩ᵛ⟨ l ⟩ a ∷ F / [Γ] / [F]) ([b] : Γ ⊩ᵛ⟨ l ⟩ b ∷ F / [Γ] / [F]) ([a≡b] : Γ ⊩ᵛ⟨ l ⟩ a ≡ b ∷ F / [Γ] / [F]) → Γ ⊩ᵛ⟨ l ⟩ t ∘ a ≡ u ∘ b ∷ G [ a ] / [Γ] / substSΠ {F = F} {G} {a} BΠ [Γ] [F] [ΠFG] [a] app-congᵛ {F = F} {G} {a = a} [Γ] [F] [ΠFG] [t≡u] [a] [b] [a≡b] ⊢Δ [σ] = let [σF] = proj₁ ([F] ⊢Δ [σ]) [G[a]] = proj₁ (substSΠ {F = F} {G} {a} BΠ [Γ] [F] [ΠFG] [a] ⊢Δ [σ]) [G[a]]′ = irrelevance′ (singleSubstLift G a) [G[a]] [σΠFG] = proj₁ ([ΠFG] ⊢Δ [σ]) [σa] = proj₁ ([a] ⊢Δ [σ]) [σb] = proj₁ ([b] ⊢Δ [σ]) in irrelevanceEqTerm′ (PE.sym (singleSubstLift G a)) [G[a]]′ [G[a]] (app-congTerm [σF] [G[a]]′ [σΠFG] ([t≡u] ⊢Δ [σ]) [σa] [σb] ([a≡b] ⊢Δ [σ]))
41.961538
99
0.436908
22568721623b7f733ff899ee8e0dd1ea178578f5
20,476
agda
Agda
src/Generics/Reflection.agda
flupe/generics
db764f858d908aa39ea4901669a6bbce1525f757
[ "MIT" ]
11
2021-04-08T15:10:20.000Z
2022-02-05T09:35:17.000Z
src/Generics/Reflection.agda
flupe/generics
db764f858d908aa39ea4901669a6bbce1525f757
[ "MIT" ]
4
2021-09-13T07:33:50.000Z
2022-01-14T10:48:30.000Z
src/Generics/Reflection.agda
flupe/generics
db764f858d908aa39ea4901669a6bbce1525f757
[ "MIT" ]
3
2021-04-08T08:32:42.000Z
2022-01-14T10:35:16.000Z
{-# OPTIONS --safe #-} module Generics.Reflection where open import Function.Base import Data.Unit as ⊤ import Data.Product as Product import Relation.Binary.PropositionalEquality as Eq open import Data.Nat.Base hiding (_⊔_) open import Data.List.Base as List hiding (_++_) import Data.Vec.Base as Vec open import Data.String as S using (String; _++_) open import Data.Bool.Base open import Data.Maybe.Base using (Maybe; just; nothing; maybe) open import Agda.Builtin.Reflection renaming ( primQNameEquality to _Name≈_ ) open import Reflection.Abstraction using (unAbs) open import Reflection.Argument using (_⟨∷⟩_; _⟅∷⟆_) open import Reflection.Term hiding (Telescope; var) open import Relation.Nullary using (yes; no) open import Category.Monad as Monad import Data.List.Categorical as List import Data.Nat.Induction as Nat import Data.Char as C open import Reflection.TypeChecking.Monad.Instances using (tcMonad) open import Reflection.Traversal hiding (_,_) open import Generics.Prelude open import Generics.Telescope open import Generics.Desc renaming (_,_ to _,ω_) import Generics.Accessibility as Accessibility open import Generics.HasDesc import Function.Identity.Categorical as Identity open List.TraversableM ⦃...⦄ open Monad.RawMonad ⦃...⦄ tErr : Term → TC ⊤ tErr = typeError ∘ [_] ∘ termErr sErr : String → TC ⊤ sErr = typeError ∘ [_] ∘ strErr open Actions -- `liftN n f` maps numbers 0..(n-1) to themselves, and numbers -- `n + k` to `n + (f k)` liftN : ℕ → (ℕ → ℕ) → (ℕ → ℕ) liftN zero f k = f k liftN (suc n) f zero = zero liftN (suc n) f (suc k) = suc (liftN n f k) mapVars : (ℕ → ℕ) → Term → Term mapVars f = traverseTerm Identity.applicative actions (0 Reflection.Traversal., []) where actions : Actions Identity.applicative actions .onVar ctx = liftN (ctx .Cxt.len) f actions .onMeta _ = id actions .onCon _ = id actions .onDef _ = id prettyName : Name → String prettyName f = maybe id "" (List.last (S.wordsBy ('.' C.≟_) (showName f))) {- When converting types to telescopes variables are converted to context lookups: Given K := [(oₒ : Oₒ) ⋯ (o₁ : O₁)] "forced" arguments (reversed) P := [A₁ ⋯ Aₙ] parameters I := [B₁ ⋯ Bₘ] indices, we want to replace a term in context (Γ , O₁ , ⋯ , Oₒ , A₁ , ⋯ , Aₙ , B₁ , ⋯ , Bₘ , C₁ , ⋯ , Cₚ) into a term in context (Γ , Σ P I , C₁ , ⋯ , Cₚ) A term (var k) should be replaced by: - (var k) if k < p - (proj₂ (proj₂ (var p))) if p <= k < p + m (inside I) (proj₂ (proj₁ (proj₂ (var p)))) ... (proj₂ (proj₁ (proj₁ (proj₂ (var p))))) ... - (proj₂ (proj₁ (var p)) if p + m <= k < p + m + n (inside P) - (proj₂ (proj₁ (proj₁ (var p))) ... - (proj₂ (proj₁ (proj₁ (proj₁ (var p)))) ... - K[k - (n + m + p)] if p + m + n <= k < p + m + n + o - var (k + 1 - n - m - o) if p + m + n + o <= k -} -- o: position of (PI : Σ P I) in the context -- (i.e number of locally bound variables) mkVar : (o k : ℕ) → Name → List (Arg Term) → Term mkVar o k t args = def (quote proj₂) (aux o k ⟨∷⟩ args) where aux : (o k : ℕ) → Term aux o zero = def t (var o [] ⟨∷⟩ []) aux o (suc k) = def (quote proj₁) (aux o k ⟨∷⟩ []) mkPVar : (o k : ℕ) → List (Arg Term) → Term mkPVar o k = mkVar o k (quote proj₁) mkIVar : (o k : ℕ) → List (Arg Term) → Term mkIVar o k = mkVar o k (quote proj₂) -- TODO: telescopize should account for forced arguments module _ (fargs : List Term) (nP nI : ℕ) where telescopize : ℕ → Term → Term telescopizeSort : ℕ → Sort → Sort telescopizeArgs : ℕ → List (Arg Term) → List (Arg Term) telescopizeTel : ℕ → List (String × Arg Type) → List (String × Arg Type) telescopizeClause : ℕ → List Clause → List Clause lookupForced : List Term → ℕ → ℕ → List (Arg Term) → Term lookupForced [] n o = var (suc (n + o)) -- WARN: we ignore args, this should go alright -- ALSO, we might/should lift everything up, probably lookupForced (x ∷ xs) zero o = const (mapVars (λ n → n + suc o) x) lookupForced (x ∷ xs) (suc n) o = lookupForced xs n o telescopize o (var k args) = let args′ = telescopizeArgs o args in if k <ᵇ o then var k args′ else if k ∸ o <ᵇ nI then mkIVar o (k ∸ o ) args′ else if k ∸ o <ᵇ nI + nP then mkPVar o (k ∸ o ∸ nI) args′ else lookupForced fargs (k ∸ (nI + nP + o)) o args -- else var (k ∸ pred (nP + nI)) args′ telescopize o (con c args) = con c (telescopizeArgs o args) telescopize o (def f args) = def f (telescopizeArgs o args) telescopize o (lam v (abs s t)) = lam v (abs s (telescopize (suc o) t)) telescopize o (pat-lam cs args) = pat-lam (telescopizeClause o cs) (telescopizeArgs o args) telescopize o (Π[ s ∶ arg i a ] b) = Π[ s ∶ arg i (telescopize o a) ] telescopize (suc o) b telescopize o (sort s) = sort (telescopizeSort o s) telescopize o (lit l) = lit l telescopize o (meta x args) = meta x (telescopizeArgs o args) telescopize o unknown = unknown telescopizeSort o (set t) = set (telescopize o t) telescopizeSort o (prop t) = prop (telescopize o t) telescopizeSort o x = x telescopizeArgs o [] = [] telescopizeArgs o (arg i x ∷ xs) = arg i (telescopize o x) ∷ telescopizeArgs o xs telescopizeTel o [] = [] telescopizeTel o ((s , arg i t) ∷ xs) = (s , arg i (telescopize o t)) ∷ telescopizeTel (suc o) xs telescopizeClause o [] = [] telescopizeClause o (clause tel ps t ∷ xs) -- careful: telescopes bring (length tel) variables in scope = clause (telescopizeTel o tel) ps (telescopize (o + length tel) t) ∷ telescopizeClause o xs telescopizeClause o (absurd-clause tel ps ∷ xs) = absurd-clause (telescopizeTel o tel) ps ∷ telescopizeClause o xs -- sanity check private module TelescopizeTests where t : Term t = var 4 [] -- locally bound variable t₁ : Term t₁ = telescopize [] 0 0 5 t t₁-ok : t₁ ≡ var 4 [] t₁-ok = refl -- retrieving var in index telescope, 4 variable locally-bound t₂ : Term t₂ = telescopize [] 2 1 4 t t₂-ok : t₂ ≡ def (quote proj₂) (def (quote proj₂) (var 4 [] ⟨∷⟩ []) ⟨∷⟩ []) t₂-ok = refl -- retrieving var in parameter telescope, 2 variable locally-bound t₃ : Term t₃ = telescopize [] 1 2 2 t t₃-ok : t₃ ≡ def (quote proj₂) (def (quote proj₁) (var 2 [] ⟨∷⟩ []) ⟨∷⟩ []) t₃-ok = refl -- retrieving var outside parameter & index telescope t₄ : Term t₄ = telescopize [] 1 1 2 t t₄-ok : t₄ ≡ var 3 [] t₄-ok = refl -- retrieving 4th var in index telescope t₅ : Term t₅ = telescopize [] 0 5 1 t t₅-ok : t₅ ≡ def (quote proj₂) (def (quote proj₁) (def (quote proj₁) (def (quote proj₁) (def (quote proj₂) (var 1 [] ⟨∷⟩ []) ⟨∷⟩ []) ⟨∷⟩ []) ⟨∷⟩ []) ⟨∷⟩ []) t₅-ok = refl ----------------------------- -- Deriving telescopes getIndexTel : List Term → ℕ → Type → TC Term getIndexTel fargs nP ty = aux ty 0 (con (quote ε) []) where aux : Type → ℕ → Term → TC Term aux (agda-sort s) n I = return I aux (Π[ s ∶ arg i a ] b) n I = do i′ ← quoteTC i >>= normalise aux b (suc n) (con (quote _⊢<_>_) (I ⟨∷⟩ con (quote Product._,_) (lit (string s) ⟨∷⟩ i′ ⟨∷⟩ []) ⟨∷⟩ vLam "PI" (telescopize fargs nP n 0 a) ⟨∷⟩ [])) aux _ _ _ = typeError [ strErr "ill-formed type signature when deriving index telescope" ] getTels : List Term → ℕ → Type → TC (Term × Term) getTels fargs nP ty = aux nP ty 0 (quoteTerm (ε {A = ⊤})) where aux : ℕ → Type → ℕ → Term → TC (Term × Term) aux zero ty _ P = (P ,_) <$> getIndexTel fargs nP ty aux (suc nP) (Π[ s ∶ arg i a ] b) n P = do i′ ← quoteTC i >>= normalise aux nP b (suc n) (con (quote _⊢<_>_) (P ⟨∷⟩ con (quote Product._,_) (lit (string s) ⟨∷⟩ i′ ⟨∷⟩ []) ⟨∷⟩ vLam "PI" (telescopize fargs 0 n 0 a) ⟨∷⟩ [])) aux _ _ _ _ = typeError [ strErr "ill-formed type signature when deriving parameter telescope" ] ----------------------------- -- Deriving descriptions -- we cannot unquote things in Setω directly -- so we can't unquote Terms of type Telescope directly -- instead we produce skeletons to ease code generation data Skel : Set where Cκ : Skel Cπ : ArgInfo → Skel → Skel _C⊗_ : Skel → Skel → Skel dropPis : ℕ → Type → Type dropPis (suc n) (pi a (abs _ b)) = dropPis n b dropPis _ t = t module _ (fargs : List Term) (dt : Name) (nP : ℕ) where toIndex : ℕ → List (Arg Term) → Term toIndex nV xs = vLam "PV" $ foldl cons (quoteTerm ⊤.tt) (drop (nP + List.length fargs) xs) where cons : Term → Arg Term → Term cons x (arg _ y) = con (quote Product._,_) ( x ⟨∷⟩ telescopize fargs nP nV 0 y ⟨∷⟩ []) getRecDesc : ℕ → Type → TC (Maybe (Term × Skel)) getRecDesc n (def nm args) = do if nm Name≈ dt then return (just (con (quote ConDesc.var) (toIndex n args ⟨∷⟩ []) , Cκ)) else return nothing getRecDesc n (Π[ s ∶ arg i a ] b) = do getRecDesc (suc n) b >>= λ where (just (right , skright)) → do i′ ← quoteTC i >>= normalise return $ just ( con (quote ConDesc.π) (con (quote Product._,_) (lit (string s) ⟨∷⟩ i′ ⟨∷⟩ []) ⟨∷⟩ vLam "PV" (telescopize fargs nP n 0 a) ⟨∷⟩ right ⟨∷⟩ []) , Cπ i skright ) nothing → return nothing getRecDesc n ty = return nothing getDesc : (ℕ → ℕ) → ℕ → Type → TC (Term × Skel) getDesc f n (def nm args) = -- we're gonna assume nm == dt -- TODO: why does this work??? -- surely args contain parameters return (con (quote ConDesc.var) (toIndex n (List.map (Arg.map (mapVars f)) args) ⟨∷⟩ []) , Cκ) getDesc f n (Π[ s ∶ arg i a ] b) = getRecDesc n (mapVars f a) >>= λ where -- (possibly higher order) inductive argument (just (left , skleft)) → do -- we cannot depend on inductive argument (for now) -- note: inductive arguments are relevant (for now) -- /!\ inductive arguments to not bind a variable, so we strengthen the term (right , skright) ← getDesc ((_- 1) ∘ f) n b return (con (quote ConDesc._⊗_) (left ⟨∷⟩ right ⟨∷⟩ []) , (skleft C⊗ skright)) -- plain old argument nothing → do (right , skright) ← getDesc (liftN 1 f) (suc n) b i′ ← quoteTC i >>= normalise return ( con (quote ConDesc.π) (con (quote Product._,_) (lit (string s) ⟨∷⟩ i′ ⟨∷⟩ []) ⟨∷⟩ vLam "PV" (telescopize fargs nP n 0 a) ⟨∷⟩ right ⟨∷⟩ []) , Cπ i skright ) getDesc _ _ _ = typeError [ strErr "ill-formed constructor type" ] -- TODO: the reason we do this is that I've failed to make the PI arguments -- implicit in the reflection code record HD {P} {I : ExTele P} {ℓ} (A : Indexed P I ℓ) : Setω where constructor mkHD A′ : ⟦ P , I ⟧xtel → Set ℓ A′ = uncurry P I A field {n} : ℕ D : DataDesc P I n names : Vec String n constr : ∀ pi → ⟦ D ⟧Data A′ pi → A′ pi split : ∀ pi → A′ pi → ⟦ D ⟧Data A′ pi split∘constr : ∀ pi → (x : ⟦ D ⟧Data A′ pi) → split pi (constr pi x) ≡ω x constr∘split : ∀ pi → (x : A′ pi ) → constr pi (split pi x) ≡ x open Accessibility A D (λ {pi} → split pi) field wf : ∀ pi (x : A′ pi) → Acc x badconvert : ∀ {P} {I : ExTele P} {ℓ} {A : Indexed P I ℓ} → HD {P} {I} {ℓ} A → HasDesc {P} {I} {ℓ} A badconvert d = record { D = HD.D d ; names = HD.names d ; constr = λ {PI} → HD.constr d PI ; split = λ {PI} → HD.split d PI ; split∘constr = λ {PI} → HD.split∘constr d PI ; constr∘split = λ {PI} → HD.constr∘split d PI ; wf = λ {PI} → HD.wf d PI } withAI : ArgInfo → Term → Term withAI i t with relevance i ... | relevant = t ... | irrelevant = con (quote irrv) [ vArg t ] patAI : ArgInfo → Pattern → Pattern patAI i t with relevance i ... | relevant = t ... | irrelevant = con (quote irrv) [ vArg t ] deriveThings : (gargs : List (Arg Term)) (nP : ℕ) (qconstr qsplit qsplitconstr qconstrsplit qwf : Name) (cons : List (Name × Skel)) → TC ⊤ deriveThings gargs nP qconstr qsplit qsplitconstr qconstrsplit qwf cons = do let clauses = deriveDef cons -- TODO: use some n-ary magic let (constr_cls , rest ) = unzip clauses let (split_cls , rest ) = unzip rest let (splitconstr_cls , rest ) = unzip rest let (constrsplit_cls , wf_cls) = unzip rest defineFun qconstr constr_cls defineFun qsplit split_cls defineFun qsplitconstr splitconstr_cls defineFun qconstrsplit constrsplit_cls defineFun qwf wf_cls where deriveIndArg : Skel → ℕ × List (String × Arg Type) × List (Arg Pattern) × List (Arg Term) deriveIndArg Cκ = 0 , [] , [] , [] deriveIndArg (Cπ ia C) = let (o , tel , pat , args) = deriveIndArg C in suc o , ("x" , vArg unknown) ∷ tel , arg ia (var o) ∷ pat , arg ia (var o []) ∷ args -- WARNING: intentionally wrong, never used when deriving descriptions deriveIndArg (A C⊗ B) = 0 , [] , [] , [] deriveCon : Skel → ℕ × List (String × Arg Type) -- variable types × Pattern -- pattern for ⟦_⟧Data × List (Arg Pattern) -- pattern for arguments of A′ cons × List (Arg Term) -- arguments for constructor × Term -- return value for split × Term -- body of wf deriveCon Cκ = 0 , [] -- we bind zero vars , con (quote Eq.refl) [] , [] , [] , con (quote Eq.refl) [] , def (quote ttω) [] deriveCon (Cπ ia C) = let (o , vars , datapat , apat , cargs , sval , wfval) = deriveCon C in suc o , ("s" , arg ia unknown) ∷ vars -- TODO: unsure about ia here , con (quote Product._,_) (patAI ia (var o) ⟨∷⟩ datapat ⟨∷⟩ []) , arg ia (var o) ∷ apat , arg ia (var o []) ∷ cargs , con (quote Product._,_) (withAI ia (var o []) ⟨∷⟩ sval ⟨∷⟩ []) , wfval deriveCon (A C⊗ B) = let (ro , rtel , rpat , rargs) = deriveIndArg A in let (o , vars , datapat , apat , cargs , sval , wfval) = deriveCon B in suc o , ("x" , vArg unknown) ∷ vars -- we only support visible relevant inductive args , con (quote Product._,_) (var o ⟨∷⟩ datapat ⟨∷⟩ []) , var o ⟨∷⟩ apat , var o [] ⟨∷⟩ cargs , con (quote Product._,_) (var o [] ⟨∷⟩ sval ⟨∷⟩ []) , def (quote _ω,ω_) (pat-lam [ clause rtel rpat (def qwf (unknown -- PI of inductive argument ⟨∷⟩ var (o + ro) rargs ⟨∷⟩ [])) ] [] ⟨∷⟩ wfval ⟨∷⟩ []) -- TODOOOO deriveClause : Pattern → Term → Name × Skel → Clause × Clause × Clause × Clause × Clause deriveClause kp kt (consname , shape) = let (o , vars , datapat , apat , cargs , sval , wfval) = deriveCon shape in clause (("pi" , vArg unknown) ∷ vars) (var o ⟨∷⟩ con (quote _,ω_) (kp ⟨∷⟩ datapat ⟨∷⟩ []) ⟨∷⟩ []) (con consname (nP ⋯⟅∷⟆ cargs)) -- TODO: maybe forced args go here , clause (("pi" , vArg unknown) ∷ vars) (var o ⟨∷⟩ con consname apat ⟨∷⟩ []) (con (quote _,ω_) (kt ⟨∷⟩ sval ⟨∷⟩ [])) , clause (("pi" , vArg unknown) ∷ vars) (var o ⟨∷⟩ con (quote _,ω_) (kp ⟨∷⟩ datapat ⟨∷⟩ []) ⟨∷⟩ []) (def (quote reflω) []) , clause (("pi" , vArg unknown) ∷ vars) (var o ⟨∷⟩ con consname apat ⟨∷⟩ []) (con (quote Eq.refl) []) , clause (("pi" , vArg unknown) ∷ vars) (var o ⟨∷⟩ con consname apat ⟨∷⟩ []) (con (quote Accessibility.Acc.acc) (wfval ⟨∷⟩ [])) deriveClauses : Pattern -- pattern for index of constructor → Term -- term for index constructor → List (Name × Skel) → List (Clause × Clause × Clause × Clause × Clause) deriveClauses _ _ [] = [] deriveClauses kp kt (x ∷ xs) = deriveClause kp kt x ∷ deriveClauses (con (quote Fin.suc) (kp ⟨∷⟩ [])) (con (quote Fin.suc) (kt ⟨∷⟩ [])) xs deriveDef : List (Name × Skel) → List (Clause × Clause × Clause × Clause × Clause) deriveDef [] = [ cls , cls , cls , cls , cls ] where cls = absurd-clause (("PI" , hArg unknown) ∷ ("x" , vArg unknown) ∷ []) (var 1 ⟨∷⟩ absurd 0 ⟨∷⟩ [] ) deriveDef xs = deriveClauses (con (quote Fin.zero) []) (con (quote Fin.zero) []) xs macro deriveDesc : Term → Term → TC ⊤ deriveDesc t hole = do -- Arguments are used for enabling universe-polymorphic defintions -- these arguments should be prepended to every use of nm as a type def nm gargs ← return t where _ → typeError [ strErr "Expected name with arguments." ] let fargs = reverse (List.map Arg.unArg gargs) data-type nP cs ← getDefinition nm where _ → typeError [ strErr "Name given is not a datatype." ] let nCons = List.length cs let nArgs = List.length gargs names ← quoteTC (Vec.fromList (List.map prettyName cs)) -- we get the type of the family, with the provided arguments removed ty ← getType nm >>= normalise <&> dropPis nArgs >>= normalise -- (nP - nArgs) is the amount of actual parameters we consider in our encoding -- the remaining Pi types are indices (P , I) ← getTels fargs (nP - nArgs) ty descs&skels ← forM cs λ cn → do -- get the type of current constructor, with explicit arguments and parameters stripped conTyp ← getType cn >>= normalise <&> dropPis nP (desc , skel) ← getDesc fargs nm (nP - nArgs) id 0 conTyp return $ (cn , skel) , desc let descs = List.map proj₂ descs&skels let skels = List.map proj₁ descs&skels let D = foldr (λ C D → con (quote DataDesc._∷_) (C ⟨∷⟩ D ⟨∷⟩ [])) (con (quote DataDesc.[]) []) descs qconstr ← freshName "constr" qsplit ← freshName "split" qsplitconstr ← freshName "split∘constr" qconstrsplit ← freshName "constr∘split" qwf ← freshName "wf" declareDef (vArg qconstr) (pi (vArg (def (quote ⟦_,_⟧xtel) (P ⟨∷⟩ I ⟨∷⟩ []))) (abs "PI" (pi (vArg unknown) (abs "x" unknown)))) declareDef (vArg qsplit) (pi (vArg (def (quote ⟦_,_⟧xtel) (P ⟨∷⟩ I ⟨∷⟩ []))) (abs "PI" (pi (vArg unknown) (abs "x" unknown)))) declareDef (vArg qconstrsplit) (pi (vArg (def (quote ⟦_,_⟧xtel) (P ⟨∷⟩ I ⟨∷⟩ []))) (abs "PI" (pi (vArg unknown) (abs "x" unknown)))) declareDef (vArg qsplitconstr) (pi (vArg (def (quote ⟦_,_⟧xtel) (P ⟨∷⟩ I ⟨∷⟩ []))) (abs "PI" (pi (vArg unknown) (abs "x" unknown)))) declareDef (vArg qwf) (pi (vArg (def (quote ⟦_,_⟧xtel) (P ⟨∷⟩ I ⟨∷⟩ []))) (abs "PI" (pi (vArg unknown) (abs "x" unknown)))) deriveThings gargs (nP - nArgs) qconstr qsplit qsplitconstr qconstrsplit qwf skels unify hole (def (quote badconvert) ((con (quote mkHD) ( P -- P ⟅∷⟆ I -- I ⟅∷⟆ unknown -- ℓ ⟅∷⟆ def nm gargs -- A ⟅∷⟆ lit (nat nCons) -- n ⟅∷⟆ D -- D ⟨∷⟩ names -- names ⟨∷⟩ def qconstr [] ⟨∷⟩ def qsplit [] ⟨∷⟩ def qsplitconstr [] ⟨∷⟩ def qconstrsplit [] ⟨∷⟩ def qwf [] ⟨∷⟩ [])) ⟨∷⟩ []))
37.988868
104
0.535261
64a3a4b47f13193529bcb0aad8526a5a891a1d17
15,290
agda
Agda
src/Fragment/Extensions/CSemigroup/Monomial.agda
yallop/agda-fragment
f2a6b1cf4bc95214bd075a155012f84c593b9496
[ "MIT" ]
18
2021-06-15T15:45:39.000Z
2022-01-17T17:26:09.000Z
src/Fragment/Extensions/CSemigroup/Monomial.agda
yallop/agda-fragment
f2a6b1cf4bc95214bd075a155012f84c593b9496
[ "MIT" ]
1
2021-06-16T09:44:31.000Z
2021-06-16T10:24:15.000Z
src/Fragment/Extensions/CSemigroup/Monomial.agda
yallop/agda-fragment
f2a6b1cf4bc95214bd075a155012f84c593b9496
[ "MIT" ]
3
2021-06-15T15:34:50.000Z
2021-06-16T08:04:31.000Z
{-# OPTIONS --without-K --exact-split --safe #-} module Fragment.Extensions.CSemigroup.Monomial where open import Fragment.Equational.Theory.Bundles open import Fragment.Algebra.Signature open import Fragment.Algebra.Free Σ-magma hiding (_~_) open import Fragment.Algebra.Homomorphism Σ-magma open import Fragment.Algebra.Algebra Σ-magma using (Algebra; IsAlgebra; Interpretation; Congruence) open import Fragment.Equational.Model Θ-csemigroup open import Fragment.Setoid.Morphism using (_↝_) open import Fragment.Extensions.CSemigroup.Nat open import Data.Nat using (ℕ; zero; suc; _≟_) open import Data.Fin using (Fin; #_; zero; suc; toℕ; fromℕ) open import Data.Vec using (Vec; []; _∷_) open import Data.Vec.Relation.Binary.Pointwise.Inductive using ([]; _∷_) open import Relation.Nullary using (yes ; no) open import Relation.Binary.PropositionalEquality as PE using (_≡_) open import Relation.Binary using (Setoid; IsEquivalence) import Relation.Binary.Reasoning.Setoid as Reasoning data Monomial : ℕ → Set where leaf : ∀ {n} → ℕ⁺ → Monomial (suc n) skip : ∀ {n} → Monomial n → Monomial (suc n) cons : ∀ {n} → ℕ⁺ → Monomial n → Monomial (suc n) lift : ∀ {n} → Monomial n → Monomial (suc n) lift (leaf x) = leaf x lift (skip x) = skip (lift x) lift (cons x xs) = cons x (lift xs) _⊗_ : ∀ {n} → Monomial n → Monomial n → Monomial n leaf x ⊗ leaf y = leaf (x + y) leaf x ⊗ skip y = cons x y leaf x ⊗ cons y ys = cons (x + y) ys skip x ⊗ leaf y = cons y x skip x ⊗ skip y = skip (x ⊗ y) skip x ⊗ cons y ys = cons y (x ⊗ ys) cons x xs ⊗ leaf y = cons (x + y) xs cons x xs ⊗ skip y = cons x (xs ⊗ y) cons x xs ⊗ cons y ys = cons (x + y) (xs ⊗ ys) ⊗-cong : ∀ {n} {x y z w : Monomial n} → x ≡ y → z ≡ w → x ⊗ z ≡ y ⊗ w ⊗-cong = PE.cong₂ _⊗_ ⊗-comm : ∀ {n} (x y : Monomial n) → x ⊗ y ≡ y ⊗ x ⊗-comm (leaf x) (leaf y) = PE.cong leaf (+-comm x y) ⊗-comm (leaf x) (skip y) = PE.refl ⊗-comm (leaf x) (cons y ys) = PE.cong₂ cons (+-comm x y) PE.refl ⊗-comm (skip x) (leaf y) = PE.refl ⊗-comm (skip x) (skip y) = PE.cong skip (⊗-comm x y) ⊗-comm (skip x) (cons y ys) = PE.cong (cons y) (⊗-comm x ys) ⊗-comm (cons x xs) (leaf y) = PE.cong₂ cons (+-comm x y) PE.refl ⊗-comm (cons x xs) (skip y) = PE.cong (cons x) (⊗-comm xs y) ⊗-comm (cons x xs) (cons y ys) = PE.cong₂ cons (+-comm x y) (⊗-comm xs ys) ⊗-assoc : ∀ {n} (x y z : Monomial n) → (x ⊗ y) ⊗ z ≡ x ⊗ (y ⊗ z) ⊗-assoc (leaf x) (leaf y) (leaf z) = PE.cong leaf (+-assoc x y z) ⊗-assoc (leaf x) (leaf y) (skip z) = PE.refl ⊗-assoc (leaf x) (leaf y) (cons z zs) = PE.cong₂ cons (+-assoc x y z) PE.refl ⊗-assoc (leaf x) (skip y) (leaf z) = PE.refl ⊗-assoc (leaf x) (skip y) (skip z) = PE.refl ⊗-assoc (leaf x) (skip y) (cons z zs) = PE.refl ⊗-assoc (leaf x) (cons y ys) (leaf z) = PE.cong₂ cons (+-assoc x y z) PE.refl ⊗-assoc (leaf x) (cons y ys) (skip z) = PE.refl ⊗-assoc (leaf x) (cons y ys) (cons z zs) = PE.cong₂ cons (+-assoc x y z) PE.refl ⊗-assoc (skip x) (leaf y) (leaf z) = PE.refl ⊗-assoc (skip x) (leaf y) (skip z) = PE.refl ⊗-assoc (skip x) (leaf y) (cons z zs) = PE.refl ⊗-assoc (skip x) (skip y) (leaf z) = PE.refl ⊗-assoc (skip x) (skip y) (skip z) = PE.cong skip (⊗-assoc x y z) ⊗-assoc (skip x) (skip y) (cons z zs) = PE.cong (cons z) (⊗-assoc x y zs) ⊗-assoc (skip x) (cons y ys) (leaf z) = PE.refl ⊗-assoc (skip x) (cons y ys) (skip z) = PE.cong (cons y) (⊗-assoc x ys z) ⊗-assoc (skip x) (cons y ys) (cons z zs) = PE.cong (cons (y + z)) (⊗-assoc x ys zs) ⊗-assoc (cons x xs) (leaf y) (leaf z) = PE.cong₂ cons (+-assoc x y z) PE.refl ⊗-assoc (cons x xs) (leaf y) (skip z) = PE.refl ⊗-assoc (cons x xs) (leaf y) (cons z zs) = PE.cong₂ cons (+-assoc x y z) PE.refl ⊗-assoc (cons x xs) (skip y) (leaf z) = PE.refl ⊗-assoc (cons x xs) (skip y) (skip z) = PE.cong (cons x) (⊗-assoc xs y z) ⊗-assoc (cons x xs) (skip y) (cons z zs) = PE.cong (cons (x + z)) (⊗-assoc xs y zs) ⊗-assoc (cons x xs) (cons y ys) (leaf z) = PE.cong₂ cons (+-assoc x y z) PE.refl ⊗-assoc (cons x xs) (cons y ys) (skip z) = PE.cong (cons (x + y)) (⊗-assoc xs ys z) ⊗-assoc (cons x xs) (cons y ys) (cons z zs) = PE.cong₂ cons (+-assoc x y z) (⊗-assoc xs ys zs) module _ (n : ℕ) where private Monomial/≡ : Setoid _ _ Monomial/≡ = PE.setoid (Monomial n) Monomial⟦_⟧ : Interpretation Monomial/≡ Monomial⟦ • ⟧ (x ∷ y ∷ []) = x ⊗ y Monomial⟦_⟧-cong : Congruence Monomial/≡ Monomial⟦_⟧ Monomial⟦ • ⟧-cong (p ∷ q ∷ []) = PE.cong₂ _⊗_ p q Monomial/≡-isAlgebra : IsAlgebra (Monomial/≡) Monomial/≡-isAlgebra = record { ⟦_⟧ = Monomial⟦_⟧ ; ⟦⟧-cong = Monomial⟦_⟧-cong } Monomial/≡-algebra : Algebra Monomial/≡-algebra = record { ∥_∥/≈ = Monomial/≡ ; ∥_∥/≈-isAlgebra = Monomial/≡-isAlgebra } Monomial/≡-models : Models Monomial/≡-algebra Monomial/≡-models comm θ = ⊗-comm (θ (# 0)) (θ (# 1)) Monomial/≡-models assoc θ = ⊗-assoc (θ (# 0)) (θ (# 1)) (θ (# 2)) Monomial/≡-isModel : IsModel Monomial/≡ Monomial/≡-isModel = record { isAlgebra = Monomial/≡-isAlgebra ; models = Monomial/≡-models } J' : Model J' = record { ∥_∥/≈ = Monomial/≡ ; isModel = Monomial/≡-isModel } private module _ {n : ℕ} where open Setoid ∥ J n ∥/≈ using (_≈_) _·_ : ∥ J n ∥ → ∥ J n ∥ → ∥ J n ∥ x · y = term • (x ∷ y ∷ []) ·-cong : ∀ {x y z w} → x ≈ y → z ≈ w → x · z ≈ y · w ·-cong p q = cong • (p ∷ q ∷ []) ·-comm : ∀ x y → x · y ≈ y · x ·-comm x y = axiom comm (env {A = ∥ J n ∥ₐ} (x ∷ y ∷ [])) ·-assoc : ∀ x y z → (x · y) · z ≈ x · (y · z) ·-assoc x y z = axiom assoc (env {A = ∥ J n ∥ₐ} (x ∷ y ∷ z ∷ [])) module _ (n : ℕ) where open Setoid ∥ J (suc n) ∥/≈ using (_≈_) exp : ℕ⁺ → ∥ J (suc n) ∥ exp one = atomise n exp (suc k) = atomise n · exp k exp-hom : ∀ {j k} → exp j · exp k ≈ exp (j + k) exp-hom {one} {k} = refl exp-hom {suc j} {k} = begin (atomise n · exp j) · exp k ≈⟨ ·-assoc (atomise n) (exp j) (exp k) ⟩ atomise n · (exp j · exp k) ≈⟨ ·-cong refl exp-hom ⟩ atomise n · exp (j + k) ∎ where open Reasoning ∥ J (suc n) ∥/≈ ∣syn∣ : ∀ {n} → ∥ J' n ∥ → ∥ J n ∥ ∣syn∣ {suc n} (leaf k) = exp n k ∣syn∣ {suc n} (skip x) = ∣ raise ∣ (∣syn∣ x) ∣syn∣ {suc n} (cons k xs) = exp n k · ∣ raise ∣ (∣syn∣ xs) ∣syn∣-cong : ∀ {n} → Congruent _≡_ ≈[ J n ] ∣syn∣ ∣syn∣-cong {n} p = Setoid.reflexive ∥ J n ∥/≈ (PE.cong ∣syn∣ p) ∣syn∣⃗ : ∀ {n} → ∥ J' n ∥/≈ ↝ ∥ J n ∥/≈ ∣syn∣⃗ {n} = record { ∣_∣ = ∣syn∣ {n} ; ∣_∣-cong = ∣syn∣-cong {n} } ∣syn∣-hom : ∀ {n} → Homomorphic ∥ J' n ∥ₐ ∥ J n ∥ₐ ∣syn∣ ∣syn∣-hom {suc n} • (leaf x ∷ leaf y ∷ []) = exp-hom n ∣syn∣-hom {suc n} • (leaf x ∷ skip y ∷ []) = refl ∣syn∣-hom {suc n} • (leaf x ∷ cons y ys ∷ []) = begin exp n x · (exp n y · ∣ raise ∣ (∣syn∣ ys)) ≈⟨ sym (·-assoc (exp n x) (exp n y) _) ⟩ (exp n x · exp n y) · ∣ raise ∣ (∣syn∣ ys) ≈⟨ ·-cong (exp-hom n) refl ⟩ exp n (x + y) · ∣ raise ∣ (∣syn∣ ys) ∎ where open Reasoning ∥ J (suc n) ∥/≈ ∣syn∣-hom {suc n} • (skip x ∷ leaf y ∷ []) = ·-comm _ (exp n y) ∣syn∣-hom {suc n} • (skip x ∷ skip y ∷ []) = begin ∣ raise ∣ (∣syn∣ x) · ∣ raise ∣ (∣syn∣ y) ≈⟨ ∣ raise ∣-hom • (∣syn∣ x ∷ ∣syn∣ y ∷ []) ⟩ ∣ raise ∣ (∣syn∣ x · ∣syn∣ y) ≈⟨ ∣ raise ∣-cong (∣syn∣-hom • (x ∷ y ∷ [])) ⟩ ∣ raise ∣ (∣syn∣ (x ⊗ y)) ∎ where open Reasoning ∥ J (suc n) ∥/≈ ∣syn∣-hom {suc n} • (skip x ∷ cons y ys ∷ []) = begin ∣ raise ∣ (∣syn∣ x) · (exp n y · ∣ raise ∣ (∣syn∣ ys)) ≈⟨ sym (·-assoc _ (exp n y) _) ⟩ (∣ raise ∣ (∣syn∣ x) · exp n y) · ∣ raise ∣ (∣syn∣ ys) ≈⟨ ·-cong (·-comm _ (exp n y)) refl ⟩ (exp n y · ∣ raise ∣ (∣syn∣ x)) · ∣ raise ∣ (∣syn∣ ys) ≈⟨ ·-assoc (exp n y) _ _ ⟩ exp n y · (∣ raise ∣ (∣syn∣ x) · ∣ raise ∣ (∣syn∣ ys)) ≈⟨ ·-cong refl (∣ raise ∣-hom • (∣syn∣ x ∷ ∣syn∣ ys ∷ [])) ⟩ exp n y · ∣ raise ∣ (∣syn∣ x · ∣syn∣ ys) ≈⟨ ·-cong refl (∣ raise ∣-cong (∣syn∣-hom • (x ∷ ys ∷ []))) ⟩ exp n y · ∣ raise ∣ (∣syn∣ (x ⊗ ys)) ∎ where open Reasoning ∥ J (suc n) ∥/≈ ∣syn∣-hom {suc n} • (cons x xs ∷ leaf y ∷ []) = begin (exp n x · ∣ raise ∣ (∣syn∣ xs)) · exp n y ≈⟨ ·-assoc (exp n x) _ (exp n y) ⟩ exp n x · (∣ raise ∣ (∣syn∣ xs) · exp n y) ≈⟨ ·-cong refl (·-comm _ (exp n y)) ⟩ exp n x · (exp n y · ∣ raise ∣ (∣syn∣ xs)) ≈⟨ sym (·-assoc (exp n x) (exp n y) _) ⟩ (exp n x · exp n y) · ∣ raise ∣ (∣syn∣ xs) ≈⟨ ·-cong (exp-hom n) refl ⟩ exp n (x + y) · ∣ raise ∣ (∣syn∣ xs) ∎ where open Reasoning ∥ J (suc n) ∥/≈ ∣syn∣-hom {suc n} • (cons x xs ∷ skip y ∷ []) = begin (exp n x · ∣ raise ∣ (∣syn∣ xs)) · ∣ raise ∣ (∣syn∣ y) ≈⟨ ·-assoc (exp n x) _ _ ⟩ exp n x · (∣ raise ∣ (∣syn∣ xs) · ∣ raise ∣ (∣syn∣ y)) ≈⟨ ·-cong refl (∣ raise ∣-hom • (∣syn∣ xs ∷ ∣syn∣ y ∷ [])) ⟩ exp n x · ∣ raise ∣ (∣syn∣ xs · ∣syn∣ y) ≈⟨ ·-cong refl (∣ raise ∣-cong (∣syn∣-hom • (xs ∷ y ∷ []))) ⟩ exp n x · ∣ raise ∣ (∣syn∣ (xs ⊗ y)) ∎ where open Reasoning ∥ J (suc n) ∥/≈ ∣syn∣-hom {suc n} • (cons x xs ∷ cons y ys ∷ []) = begin (exp n x · ∣ raise ∣ (∣syn∣ xs)) · (exp n y · ∣ raise ∣ (∣syn∣ ys)) ≈⟨ ·-assoc (exp n x) _ _ ⟩ exp n x · (∣ raise ∣ (∣syn∣ xs) · (exp n y · ∣ raise ∣ (∣syn∣ ys))) ≈⟨ ·-cong refl (sym (·-assoc _ (exp n y) _)) ⟩ exp n x · ((∣ raise ∣ (∣syn∣ xs) · exp n y) · ∣ raise ∣ (∣syn∣ ys)) ≈⟨ ·-cong refl (·-cong (·-comm (∣ raise ∣ (∣syn∣ xs)) _) refl) ⟩ exp n x · ((exp n y · ∣ raise ∣ (∣syn∣ xs)) · ∣ raise ∣ (∣syn∣ ys)) ≈⟨ ·-cong refl (·-assoc (exp n y) _ _) ⟩ exp n x · (exp n y · (∣ raise ∣ (∣syn∣ xs) · ∣ raise ∣ (∣syn∣ ys))) ≈⟨ sym (·-assoc (exp n x) (exp n y) _) ⟩ (exp n x · exp n y) · (∣ raise ∣ (∣syn∣ xs) · ∣ raise ∣ (∣syn∣ ys)) ≈⟨ ·-cong (exp-hom n) (∣ raise ∣-hom • (∣syn∣ xs ∷ ∣syn∣ ys ∷ [])) ⟩ exp n (x + y) · ∣ raise ∣ (∣syn∣ xs · ∣syn∣ ys) ≈⟨ ·-cong refl (∣ raise ∣-cong (∣syn∣-hom • (xs ∷ ys ∷ []))) ⟩ exp n (x + y) · ∣ raise ∣ (∣syn∣ (xs ⊗ ys)) ∎ where open Reasoning ∥ J (suc n) ∥/≈ syn : ∀ {n} → ∥ J' n ∥ₐ ⟿ ∥ J n ∥ₐ syn = record { ∣_∣⃗ = ∣syn∣⃗ ; ∣_∣-hom = ∣syn∣-hom } private tab : ∀ {n} → Fin n → ∥ J' n ∥ tab {suc zero} zero = leaf one tab {suc (suc n)} zero = skip (tab {suc n} zero) tab {suc (suc n)} (suc k) = lift (tab {suc n} k) norm : ∀ {n} → ∥ J n ∥ₐ ⟿ ∥ J' n ∥ₐ norm {n} = interp (J' n) tab private step-exp : ∀ {n} → (k : ℕ⁺) → ≈[ J (suc (suc n)) ] (exp (suc n) k) (∣ step ∣ (exp n k)) step-exp one = refl step-exp (suc k) = ·-cong refl (step-exp k) step-lift : ∀ {n} → (x : ∥ J' n ∥) → ≈[ J (suc n) ] (∣ syn ∣ (lift x)) (∣ step ∣ (∣ syn ∣ x)) step-lift {suc n} (leaf x) = step-exp x step-lift {suc n} (skip x) = begin ∣ raise ∣ (∣ syn ∣ (lift x)) ≈⟨ ∣ raise ∣-cong (step-lift x) ⟩ ∣ raise ∣ (∣ step ∣ (∣ syn ∣ x)) ≈⟨ sym (step-raise {x = ∣ syn ∣ x}) ⟩ ∣ step ∣ (∣ raise ∣ (∣ syn ∣ x)) ∎ where open Reasoning ∥ J (suc (suc n)) ∥/≈ step-lift {suc n} (cons x xs) = begin exp (suc n) x · ∣ raise ∣ (∣ syn ∣ (lift xs)) ≈⟨ ·-cong refl (∣ raise ∣-cong (step-lift xs)) ⟩ exp (suc n) x · ∣ raise ∣ (∣ step ∣ (∣ syn ∣ xs)) ≈⟨ ·-cong (step-exp x) (sym (step-raise {x = ∣ syn ∣ xs})) ⟩ ∣ step ∣ (exp n x) · ∣ step ∣ (∣ raise ∣ (∣ syn ∣ xs)) ≈⟨ ∣ step ∣-hom • (exp n x ∷ (∣ raise ∣ (∣ syn ∣ xs)) ∷ []) ⟩ ∣ step ∣ (exp n x · ∣ raise ∣ (∣ syn ∣ xs)) ∎ where open Reasoning ∥ J (suc (suc n)) ∥/≈ syn-tab : ∀ {n} → (k : Fin n) → ≈[ J n ] (∣ syn ∣ (tab k)) (atom (dyn k)) syn-tab {suc zero} zero = refl syn-tab {suc (suc n)} zero = ∣ raise ∣-cong (syn-tab zero) syn-tab {suc (suc n)} (suc k) = begin ∣ syn ∣ (lift (tab {suc n} k)) ≈⟨ step-lift (tab {suc n} k) ⟩ ∣ step ∣ (∣ syn ∣ (tab {suc n} k)) ≈⟨ ∣ step ∣-cong (syn-tab k) ⟩ ∣ step ∣ (atom (dyn k)) ∎ where open Reasoning ∥ J (suc (suc n)) ∥/≈ syn⊙norm≗id : ∀ {n} → syn {n} ⊙ norm {n} ≗ id syn⊙norm≗id {n} {atom (dyn k)} = syn-tab k syn⊙norm≗id {n} {term • (x ∷ y ∷ [])} = begin ∣ syn ∣ (∣ norm ∣ x ⊗ ∣ norm ∣ y) ≈⟨ sym (∣ syn ∣-hom • (∣ norm ∣ x ∷ ∣ norm ∣ y ∷ [])) ⟩ ∣ syn ∣ (∣ norm ∣ x) · ∣ syn ∣ (∣ norm ∣ y) ≈⟨ ·-cong syn⊙norm≗id syn⊙norm≗id ⟩ x · y ∎ where open Reasoning ∥ J n ∥/≈ private tab-diag : ∀ n → tab {suc n} (fromℕ n) ≡ leaf one tab-diag zero = PE.refl tab-diag (suc n) = PE.cong lift (tab-diag n) norm-exp : ∀ {n} (k : ℕ⁺) → ∣ norm ∣ (exp n k) ≡ leaf k norm-exp {n} one = tab-diag n norm-exp {n} (suc k) = begin ∣ norm ∣ (atomise n · exp n k) ≈⟨ PE.sym (∣ norm ∣-hom • (atomise n ∷ exp n k ∷ [])) ⟩ ∣ norm ∣ (atomise n) ⊗ ∣ norm ∣ (exp n k) ≈⟨ ⊗-cong (tab-diag n) (norm-exp k) ⟩ leaf one ⊗ leaf k ∎ where open Reasoning ∥ J' (suc n) ∥/≈ tab-skip : ∀ {n} → (k : Fin n) → tab {suc n} (up k) ≡ skip (tab {n} k) tab-skip {suc zero} zero = PE.refl tab-skip {suc (suc n)} zero = PE.refl tab-skip {suc (suc n)} (suc k) = PE.cong lift (tab-skip k) norm-raise : ∀ {n x} → ∣ norm {suc n} ∣ (∣ raise ∣ x) ≡ skip (∣ norm {n} ∣ x) norm-raise {n} {atom (dyn k)} = tab-skip k norm-raise {n} {term • (x ∷ y ∷ [])} = begin ∣ norm ∣ (∣ raise ∣ (x · y)) ≡⟨ ∣ norm ∣-cong (sym (∣ raise ∣-hom • (x ∷ y ∷ []))) ⟩ ∣ norm ∣ (∣ raise ∣ x · ∣ raise ∣ y) ≡⟨ PE.sym (∣ norm ∣-hom • (∣ raise ∣ x ∷ ∣ raise ∣ y ∷ [])) ⟩ ∣ norm ∣ (∣ raise ∣ x) ⊗ ∣ norm ∣ (∣ raise ∣ y) ≡⟨ ⊗-cong (norm-raise {x = x}) (norm-raise {x = y}) ⟩ skip (∣ norm ∣ x ⊗ ∣ norm ∣ y) ≡⟨ PE.cong skip (∣ norm ∣-hom • (x ∷ y ∷ [])) ⟩ skip (∣ norm ∣ (x · y)) ∎ where open PE.≡-Reasoning norm⊙syn≗id : ∀ {n} → norm {n} ⊙ syn {n} ≗ id norm⊙syn≗id {suc n} {leaf x} = norm-exp x norm⊙syn≗id {suc n} {skip x} = begin ∣ norm ∣ (∣ raise ∣ (∣ syn ∣ x)) ≈⟨ norm-raise {x = ∣ syn ∣ x} ⟩ skip (∣ norm ∣ (∣ syn ∣ x)) ≈⟨ PE.cong skip norm⊙syn≗id ⟩ skip x ∎ where open Reasoning ∥ J' (suc n) ∥/≈ norm⊙syn≗id {suc n} {cons x xs} = begin ∣ norm ∣ (exp n x · ∣ raise ∣ (∣ syn ∣ xs)) ≈⟨ PE.sym (∣ norm ∣-hom • (exp n x ∷ ∣ raise ∣ (∣ syn ∣ xs) ∷ [])) ⟩ ∣ norm ∣ (exp n x) ⊗ ∣ norm ∣ (∣ raise ∣ (∣ syn ∣ xs)) ≈⟨ ⊗-cong (norm-exp x) (norm-raise {x = ∣ syn ∣ xs}) ⟩ leaf x ⊗ skip (∣ norm ∣ (∣ syn ∣ xs)) ≈⟨ ⊗-cong (PE.refl {x = leaf x}) (PE.cong skip (norm⊙syn≗id {x = xs})) ⟩ leaf x ⊗ skip xs ∎ where open Reasoning ∥ J' (suc n) ∥/≈ iso : ∀ {n} → ∥ J n ∥ₐ ≃ ∥ J' n ∥ₐ iso = record { _⃗ = norm ; _⃖ = syn ; invˡ = norm⊙syn≗id ; invʳ = syn⊙norm≗id }
39.104859
94
0.47155
72e65171c96d464e4972b1d0a1610811bb04aa77
43
agda
Agda
test/Fail/Issue2788a.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2788a.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2788a.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where {-# BUILTIN INTERVAL I #-}
10.75
26
0.651163
cc26ed971332ade95bb015b4ce26fd937b3fddd8
556
agda
Agda
examples/outdated-and-incorrect/Subset.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/outdated-and-incorrect/Subset.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/outdated-and-incorrect/Subset.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Proof irrelevance is nice when you want to work with subsets. module Subset where data True : Prop where tt : True data False : Prop where data (|) (A:Set)(P:A -> Prop) : Set where sub : (x:A) -> P x -> A | P data Nat : Set where zero : Nat suc : Nat -> Nat mutual IsEven : Nat -> Prop IsEven zero = True IsEven (suc n) = IsOdd n IsOdd : Nat -> Prop IsOdd zero = False IsOdd (suc n) = IsEven n Even : Set Even = Nat | IsEven Odd : Set Odd = Nat | IsOdd (+) : Nat -> Nat -> Nat zero + m = m suc n + m = suc (n + m)
15.444444
64
0.580935
7c82ca7cad697d39801ef1db38f70342528ad083
581
agda
Agda
test/Succeed/Issue1345.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1345.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1345.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS -v reify:80 #-} open import Common.Prelude open import Common.Reflection open import Common.Equality open import Agda.Builtin.Sigma module Issue1345 (A : Set) where -- Andreas, 2016-07-17 -- Also test correct handling of abstract abstract unquoteDecl idNat = define (vArg idNat) (funDef (pi (vArg (def (quote Nat) [])) (abs "" (def (quote Nat) []))) (clause (("", vArg unknown) ∷ []) (vArg (var 0) ∷ []) (var 0 []) ∷ [])) -- This raised the UselessAbstract error in error. -- Should work. abstract thm : ∀ n → idNat n ≡ n thm n = refl
25.26087
83
0.633391
14c43ec6324f32324896b3dd088e9a0df53ff340
278
agda
Agda
test/Succeed/Issue1652-2.agda
zliu41/agda
73405f70bced057d24dd4bf122d53f9548544aba
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue1652-2.agda
zliu41/agda
73405f70bced057d24dd4bf122d53f9548544aba
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue1652-2.agda
zliu41/agda
73405f70bced057d24dd4bf122d53f9548544aba
[ "BSD-3-Clause" ]
null
null
null
{- Example by Andreas (2015-09-18) -} {-# OPTIONS --rewriting --local-confluence-check #-} open import Common.Prelude open import Common.Equality {-# BUILTIN REWRITE _≡_ #-} module _ (A : Set) where postulate plus0p : ∀{x} → (x + zero) ≡ x {-# REWRITE plus0p #-}
17.375
52
0.625899
0d35553d0482701a9edefe10d648a7c06d7373df
8,151
agda
Agda
agda/DsubReduced.agda
HuStmpHrrr/popl20-artifact
48214a55ebb484fd06307df4320813d4a002535b
[ "MIT" ]
1
2021-09-23T08:40:28.000Z
2021-09-23T08:40:28.000Z
agda/DsubReduced.agda
HuStmpHrrr/popl20-artifact
48214a55ebb484fd06307df4320813d4a002535b
[ "MIT" ]
null
null
null
agda/DsubReduced.agda
HuStmpHrrr/popl20-artifact
48214a55ebb484fd06307df4320813d4a002535b
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} -- This module defines an intermediate calculus that is set up in the D<: universe -- which bridges F<:- and D<:. The goal here is purely technical - to simply reduce -- duplication. module DsubReduced where open import Data.List as List open import Data.List.All as All open import Data.Nat as ℕ open import Data.Maybe as Maybe open import Data.Product open import Function open import Data.Maybe.Properties as Maybeₚ open import Data.Nat.Properties as ℕₚ open import Relation.Nullary open import Relation.Binary.PropositionalEquality as ≡ open import DsubDef open import FsubMinus open import FsubMinus2 open import Utils -- D<: Reduced -- -- This judgment for contexts and types in D<: defines a corresponding calculus after -- interpreting F<:⁻ into D<:. That is, D<: reduced is the image derivation of -- interpreting F<:⁻ in D<:. infix 4 _⊢ᵣ_<:_ data _⊢ᵣ_<:_ : Env → Typ → Typ → Set where drtop : ∀ {Γ T} → Covar T → Γ ⊢ᵣ T <: ⊤ drrefl : ∀ {Γ T} → Covar T → Γ ⊢ᵣ T <: T drall : ∀ {Γ S U S′ U′} → Covar S → Covar U → Covar S′ → Covar U′ → (S′<:S : Γ ⊢ᵣ S′ <: S) → (U<:U′ : ⟨A: ⊥ ⋯ S′ ⟩ ∷ Γ ⊢ᵣ U <: U′) → Γ ⊢ᵣ Π ⟨A: ⊥ ⋯ S ⟩ ∙ U <: Π ⟨A: ⊥ ⋯ S′ ⟩ ∙ U′ drsel : ∀ {Γ n U U′} → (T∈Γ : env-lookup Γ n ≡ just ⟨A: ⊥ ⋯ U ⟩) → Covar U → Γ ⊢ᵣ U <: U′ → Γ ⊢ᵣ n ∙A <: U′ module FsubMinusToDsubR where open FsubMinus.FsubMinus renaming (Env to Env′ ; _↑_ to _⇑_) hiding (env-lookup) infix 5 ⟦_⟧ ⟪_⟫ ⟦_⟧ : Ftyp → Typ ⟦ ⊤ ⟧ = ⊤ ⟦ var x ⟧ = x ∙A ⟦ Π<: S ∙ U ⟧ = Π ⟨A: ⊥ ⋯ ⟦ S ⟧ ⟩ ∙ ⟦ U ⟧ ⟪_⟫ : Env′ → Env ⟪ [] ⟫ = [] ⟪ T ∷ Γ ⟫ = ⟨A: ⊥ ⋯ ⟦ T ⟧ ⟩ ∷ ⟪ Γ ⟫ module ⟦⟧-Bijective where open import Function.Bijection open import Function.Surjection open import Function.Equality CovTyp : Set CovTyp = ∃ λ T → Covar T ⟦⟧-covar : ∀ T → Covar ⟦ T ⟧ ⟦⟧-covar ⊤ = cv⊤ ⟦⟧-covar (var x) = cv∙A _ ⟦⟧-covar (Π<: S ∙ U) = cvΠ (⟦⟧-covar S) (⟦⟧-covar U) ⟦⟧-func : ≡.setoid Ftyp ⟶ ≡.setoid CovTyp ⟦⟧-func = record { _⟨$⟩_ = < ⟦_⟧ , ⟦⟧-covar > ; cong = ≡.cong < ⟦_⟧ , ⟦⟧-covar > } ⟦⟧-injective : ∀ {S U} → ⟦ S ⟧ ≡ ⟦ U ⟧ → S ≡ U ⟦⟧-injective {⊤} {⊤} eq = refl ⟦⟧-injective {⊤} {var x} () ⟦⟧-injective {⊤} {Π<: _ ∙ _} () ⟦⟧-injective {var x} {⊤} () ⟦⟧-injective {var x} {var .x} refl = refl ⟦⟧-injective {var x} {Π<: _ ∙ _} () ⟦⟧-injective {Π<: _ ∙ _} {⊤} () ⟦⟧-injective {Π<: _ ∙ _} {var x} () ⟦⟧-injective {Π<: S₁ ∙ U₁} {Π<: S₂ ∙ U₂} eq with ⟦ S₁ ⟧ | ⟦ S₂ ⟧ | ⟦ U₁ ⟧ | ⟦ U₂ ⟧ | ⟦⟧-injective {S₁} {S₂} | ⟦⟧-injective {U₁} {U₂} ⟦⟧-injective {Π<: S₁ ∙ U₁} {Π<: S₂ ∙ U₂} refl | _ | _ | _ | _ | rec₁ | rec₂ = ≡.cong₂ Π<:_∙_ (rec₁ refl) (rec₂ refl) ⟦⟧-func-injective : ∀ {S U} → (CovTyp ∋ (⟦ S ⟧ , ⟦⟧-covar S)) ≡ (⟦ U ⟧ , ⟦⟧-covar U) → S ≡ U ⟦⟧-func-injective {S} {U} eq with ⟦ S ⟧ | ⟦⟧-covar S | ⟦ U ⟧ | ⟦⟧-covar U | ⟦⟧-injective {S} {U} ⟦⟧-func-injective {S} {U} refl | _ | _ | _ | _ | inj = inj refl infix 5 ⟦_⟧⁻¹ ⟦_⟧⁻¹ : CovTyp → Ftyp ⟦ _ , cv⊤ ⟧⁻¹ = ⊤ ⟦ _ , cv∙A x ⟧⁻¹ = var x ⟦ _ , cvΠ S U ⟧⁻¹ = Π<: ⟦ -, S ⟧⁻¹ ∙ ⟦ -, U ⟧⁻¹ ⟦⟧-func-inv : ≡.setoid CovTyp ⟶ ≡.setoid Ftyp ⟦⟧-func-inv = record { _⟨$⟩_ = ⟦_⟧⁻¹ ; cong = ≡.cong ⟦_⟧⁻¹ } ⟦⟧-left-inverse-⟦⟧⁻¹ : ∀ {T} (cT : Covar T) → (⟦ ⟦ -, cT ⟧⁻¹ ⟧ , ⟦⟧-covar ⟦ -, cT ⟧⁻¹) ≡ (CovTyp ∋ (-, cT)) ⟦⟧-left-inverse-⟦⟧⁻¹ cv⊤ = refl ⟦⟧-left-inverse-⟦⟧⁻¹ (cv∙A n) = refl ⟦⟧-left-inverse-⟦⟧⁻¹ (cvΠ S U) with ⟦ ⟦ -, S ⟧⁻¹ ⟧ | ⟦ ⟦ -, U ⟧⁻¹ ⟧ | ⟦⟧-covar ⟦ -, S ⟧⁻¹ | ⟦⟧-covar ⟦ -, U ⟧⁻¹ | ⟦⟧-left-inverse-⟦⟧⁻¹ S | ⟦⟧-left-inverse-⟦⟧⁻¹ U ... | _ | _ | _ | _ | refl | refl = refl ⟦⟧-bijective : Bijective ⟦⟧-func ⟦⟧-bijective = record { injective = ⟦⟧-func-injective ; surjective = record { from = ⟦⟧-func-inv ; right-inverse-of = λ { (_ , T) → ⟦⟧-left-inverse-⟦⟧⁻¹ T } } } open ⟦⟧-Bijective using (⟦⟧-covar ; ⟦⟧-injective) public ⟪⟫-contraEnv : ∀ Γ → ContraEnv ⟪ Γ ⟫ ⟪⟫-contraEnv [] = [] ⟪⟫-contraEnv (T ∷ Γ) = ctt (⟦⟧-covar T) ∷ ⟪⟫-contraEnv Γ ⟦⟧-↑-comm : ∀ T n → ⟦ T ⟧ ↑ n ≡ ⟦ T ⇑ n ⟧ ⟦⟧-↑-comm ⊤ n = refl ⟦⟧-↑-comm (var x) n with n ≤? x ... | yes n≤x = refl ... | no n>x = refl ⟦⟧-↑-comm (Π<: S ∙ U) n rewrite ⟦⟧-↑-comm S n | ⟦⟧-↑-comm U (suc n) = refl <:∈⇒env-lookup : ∀ {n T Γ} → n <: T ∈ Γ → env-lookup ⟪ Γ ⟫ n ≡ just ⟨A: ⊥ ⋯ ⟦ T ⟧ ⟩ <:∈⇒env-lookup {_} {_} {T ∷ ._} hd rewrite ⟦⟧-↑-comm T 0 = refl <:∈⇒env-lookup {suc n} {_} {._ ∷ Γ} (tl {_} {T} T∈Γ) with lookupOpt ⟪ Γ ⟫ n | <:∈⇒env-lookup T∈Γ ... | nothing | () ... | just _ | eq rewrite sym $ ⟦⟧-↑-comm T 0 = cong (just ∘ (_↑ 0)) (just-injective eq) F<:⇒D<:ᵣ : ∀ {Γ S U} → Γ ⊢F S <: U → ⟪ Γ ⟫ ⊢ᵣ ⟦ S ⟧ <: ⟦ U ⟧ F<:⇒D<:ᵣ ftop = drtop (⟦⟧-covar _) F<:⇒D<:ᵣ fvrefl = drrefl (cv∙A _) F<:⇒D<:ᵣ (fbinds T∈Γ T<:U) = drsel (<:∈⇒env-lookup T∈Γ) (⟦⟧-covar _) (F<:⇒D<:ᵣ T<:U) F<:⇒D<:ᵣ (fall S′<:S U<:U′) = drall (⟦⟧-covar _) (⟦⟧-covar _) (⟦⟧-covar _) (⟦⟧-covar _) (F<:⇒D<:ᵣ S′<:S) (F<:⇒D<:ᵣ U<:U′) env-lookup⇒<:∈ : ∀ {n T Γ} → env-lookup Γ n ≡ just ⟨A: ⊥ ⋯ T ⟩ → ∀ {Γ′} → Γ ≡ ⟪ Γ′ ⟫ → ∃ λ T′ → T ≡ ⟦ T′ ⟧ × n <: T′ ∈ Γ′ env-lookup⇒<:∈ T∈Γ eqΓ = aux (lookup⇒↦∈ T∈Γ) refl eqΓ where aux : ∀ {n T Γ} → n ↦ T ∈ Γ → ∀ {U Γ′} → T ≡ ⟨A: ⊥ ⋯ U ⟩ → Γ ≡ ⟪ Γ′ ⟫ → ∃ λ U′ → U ≡ ⟦ U′ ⟧ × n <: U′ ∈ Γ′ aux hd {_} {[]} eqT () aux hd {_} {T ∷ Γ′} refl refl rewrite ⟦⟧-↑-comm T 0 = T ⇑ zero , refl , hd aux (tl T∈Γ) {_} {[]} eqT () aux (tl {T = ⊤} T∈Γ) {_} {_ ∷ Γ′} () refl aux (tl {T = ⊥} T∈Γ) {_} {_ ∷ Γ′} () refl aux (tl {T = n ∙A} T∈Γ) {_} {_ ∷ Γ′} () refl aux (tl {T = Π S ∙ U} T∈Γ) {_} {_ ∷ Γ′} () refl aux (tl {T = ⟨A: ⊤ ⋯ U ⟩} T∈Γ) {_} {_ ∷ Γ′} () refl aux (tl {T = ⟨A: ⊥ ⋯ U ⟩} T∈Γ) {_} {_ ∷ Γ′} refl refl with aux T∈Γ refl refl ... | U′ , refl , U′∈Γ′ rewrite ⟦⟧-↑-comm U′ 0 = U′ ⇑ zero , refl , tl U′∈Γ′ aux (tl {T = ⟨A: _ ∙A ⋯ U ⟩} T∈Γ) {_} {_ ∷ Γ′} () refl aux (tl {T = ⟨A: Π _ ∙ _ ⋯ U ⟩} T∈Γ) {_} {_ ∷ Γ′} () refl aux (tl {T = ⟨A: ⟨A: _ ⋯ _ ⟩ ⋯ U ⟩} T∈Γ) {_} {_ ∷ Γ′} () refl D<:ᵣ⇒F<: : ∀ {Γ′ S′ U′} → Γ′ ⊢ᵣ S′ <: U′ → ∀ {Γ S U} → Γ′ ≡ ⟪ Γ ⟫ → S′ ≡ ⟦ S ⟧ → U′ ≡ ⟦ U ⟧ → Γ ⊢F S <: U D<:ᵣ⇒F<: (drtop S′) {Γ} {S} {⊤} eqΓ eqS refl = ftop D<:ᵣ⇒F<: (drtop S′) {Γ} {S} {var x} eqΓ eqS () D<:ᵣ⇒F<: (drtop S′) {Γ} {S} {Π<: U ∙ U₁} eqΓ eqS () D<:ᵣ⇒F<: (drrefl S′) {Γ} {S} {U} eqΓ eqS eqU rewrite ⟦⟧-injective (≡.trans (sym eqS) eqU) = <:-refl Γ U D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {⊤} {⊤} eqΓ () eqU D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {⊤} {var x} eqΓ () eqU D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {⊤} {Π<: U ∙ U₁} eqΓ () eqU D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {var _} {⊤} eqΓ () eqU D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {var _} {var _} eqΓ () eqU D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {var _} {Π<: _ ∙ _} eqΓ () eqU D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {Π<: _ ∙ _} {⊤} eqΓ refl () D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {Π<: _ ∙ _} {var _} eqΓ refl () D<:ᵣ⇒F<: (drall cS cU cS′ cU′ S′<:S U<:U′) {Γ} {Π<: S ∙ U} {Π<: S′ ∙ U′} eqΓ refl refl = fall (D<:ᵣ⇒F<: S′<:S eqΓ refl refl) (D<:ᵣ⇒F<: U<:U′ (cong (⟨A: ⊥ ⋯ ⟦ S′ ⟧ ⟩ ∷_) eqΓ) refl refl) D<:ᵣ⇒F<: (drsel T∈Γ cT S<:U) {Γ} {⊤} {U} eqΓ () eqU D<:ᵣ⇒F<: (drsel T∈Γ cT S<:U) {Γ} {var x} {U} eqΓ refl eqU with env-lookup⇒<:∈ T∈Γ eqΓ ... | U′ , eqU′ , T′∈Γ = fbinds T′∈Γ (D<:ᵣ⇒F<: S<:U eqΓ eqU′ eqU) D<:ᵣ⇒F<: (drsel T∈Γ cT S<:U) {Γ} {Π<: _ ∙ _} {U} eqΓ () eqU
38.814286
111
0.419212
11e9e7da84e9afb1d156ffbd2c0f879dc8369363
1,430
agda
Agda
test/Fail/Issue585.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Fail/Issue585.agda
Blaisorblade/Agda
802a28aa8374f15fe9d011ceb80317fdb1ec0949
[ "BSD-3-Clause" ]
null
null
null
test/Fail/Issue585.agda
Blaisorblade/Agda
802a28aa8374f15fe9d011ceb80317fdb1ec0949
[ "BSD-3-Clause" ]
null
null
null
-- {-# OPTIONS -v tc.conv:50 -v tc.reduce:100 -v tc:50 -v tc.term.expr.coind:15 -v tc.meta:20 #-} -- 2012-03-15, reported by Nisse module Issue585 where open import Common.Coinduction data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ data Fin : ℕ → Set where zero : ∀ {n} → Fin (suc n) suc : ∀ {n} → Fin n → Fin (suc n) infixr 5 _∷_ data Vec (A : Set) : ℕ → Set where [] : Vec A zero _∷_ : ∀ {n} → A → Vec A n → Vec A (suc n) lookup : ∀ {n A} → Fin n → Vec A n → A lookup zero (x ∷ xs) = x lookup (suc i) (x ∷ xs) = lookup i xs infixl 9 _·_ data Tm (n : ℕ) : Set where var : Fin n → Tm n ƛ : Tm (suc n) → Tm n _·_ : Tm n → Tm n → Tm n infixr 8 _⇾_ data Ty : Set where _⇾_ : ∞ Ty → ∞ Ty → Ty Ctxt : ℕ → Set Ctxt n = Vec Ty n infix 4 _⊢_∈_ data _⊢_∈_ {n} (Γ : Ctxt n) : Tm n → Ty → Set where var : ∀ {x} → Γ ⊢ var x ∈ lookup x Γ ƛ : ∀ {t σ τ} → ♭ σ ∷ Γ ⊢ t ∈ ♭ τ → Γ ⊢ ƛ t ∈ σ ⇾ τ _·_ : ∀ {t₁ t₂ σ τ} → Γ ⊢ t₁ ∈ σ ⇾ τ → Γ ⊢ t₂ ∈ ♭ σ → Γ ⊢ t₁ · t₂ ∈ ♭ τ Ω : Tm zero Ω = ω · ω where ω = ƛ (var zero · var zero) Ω-has-any-type : ∀ τ → [] ⊢ Ω ∈ τ Ω-has-any-type τ = _·_ {σ = σ} {τ = ♯ _} (ƛ (var · var)) (ƛ (var · var)) where σ : ∞ Ty σ = ♯ (σ ⇾ ♯ _) -- τ) -- If the last -- underscore is replaced by τ, then the code checks successfully. -- WAS: Agda seems to loop when checking Ω-has-any-type. -- NOW: this should leave metas unsolved.
22
97
0.504196
cc86d24c2f084a59c3581f72f86a0283b0f429f3
15,815
agda
Agda
src/Tactic/Deriving/Eq.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
src/Tactic/Deriving/Eq.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
src/Tactic/Deriving/Eq.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
open import Prelude hiding (abs) open import Prelude.Variables open import Container.Traversable open import Tactic.Reflection hiding (substArgs) renaming (unify to unifyTC) open import Tactic.Reflection.Equality open import Tactic.Deriving module Tactic.Deriving.Eq where _∋_ : ∀ {a} (A : Set a) → A → A A ∋ x = x private -- Pattern synonyms -- infix 5 _`≡_ pattern _`≡_ x y = def₂ (quote _≡_) x y pattern `subst x y z = def₃ (quote transport) x y z pattern `refl = con (quote refl) [] pattern `Eq a = def (quote Eq) (vArg a ∷ []) pattern vLam s t = lam visible (abs s t) -- Helper functions -- nLam : Telescope → Term → Term nLam [] t = t nLam ((x , arg (arg-info v _) s) ∷ tel) t = lam v (abs x (nLam tel t)) nPi : Telescope → Term → Term nPi [] t = t nPi ((x , arg i _) ∷ tel) t = pi (arg i unknown) (abs x (nPi tel t)) newVars' : (Nat → A) → List (Arg B) → List (Arg A) newVars' {A = A} {B = B} mkVar tel = newArgsFrom (length tel) tel where newArgsFrom : Nat → List (Arg B) → List (Arg A) newArgsFrom (suc n) (arg i _ ∷ tel) = arg i (mkVar n) ∷ newArgsFrom n tel newArgsFrom _ _ = [] newVars : List (Arg A) → List (Arg Term) newVars = newVars' (λ x → var x []) newPatVars : List (Arg A) → List (Arg Pattern) newPatVars = newVars' var hideTel : Telescope → Telescope hideTel [] = [] hideTel ((x , arg (arg-info _ r) t) ∷ tel) = (x , arg (arg-info hidden r) t) ∷ hideTel tel weakenTelFrom : (from n : Nat) → Telescope → Telescope weakenTelFrom from n [] = [] weakenTelFrom from n (t ∷ tel) = weakenFrom from n t ∷ weakenTelFrom (suc from) n tel weakenTel : (n : Nat) → Telescope → Telescope weakenTel 0 = id weakenTel n = weakenTelFrom 0 n #pars : (d : Name) → TC Nat #pars = getParameters argsTel : (c : Name) → TC Telescope argsTel c = caseM telView <$> getType c of λ { (tel , def d ixs) → flip drop tel <$> #pars d ; (tel , _ ) → pure tel } #args : (c : Name) → TC Nat #args c = length <$> argsTel c params : (c : Name) → TC Telescope params c = telView <$> getType c >>= λ { (tel , def d ixs) → flip take tel <$> #pars d ; _ → pure [] } -- Parallel substitution -- Substitution : Set Substitution = List (Nat × Term) underLambda : Substitution → Substitution underLambda = map (λ { (i , t) → suc i , weaken 1 t }) {-# TERMINATING #-} subst : Substitution → Term → Term apply : Term → List (Arg Term) → Term substArgs : Substitution → List (Arg Term) → List (Arg Term) subst sub (var x args) = case (lookup sub x) of λ { (just s) → apply s (substArgs sub args) ; nothing → var x (substArgs sub args) } subst sub (con c args) = con c (substArgs sub args) subst sub (def f args) = def f (substArgs sub args) subst sub (lam v t) = lam v (fmap (subst (underLambda sub)) t) subst sub (lit l) = lit l subst sub _ = unknown -- TODO apply f [] = f apply (var x args) xs = var x (args ++ xs) apply (con c args) xs = con c (args ++ xs) apply (def f args) xs = def f (args ++ xs) apply (lam _ (abs _ t)) (arg _ x ∷ xs) = case (strengthen 1 (subst ((0 , weaken 1 x) ∷ []) t)) of λ { (just f) → apply f xs ; nothing → unknown } apply _ _ = unknown -- TODO substArgs sub = map (fmap (subst sub)) -- Unification of datatype indices -- data Unify : Set where positive : List (Nat × Term) → Unify negative : Unify failure : ∀ {a} {A : Set a} → String → TC A failure s = typeErrorS ("Unification error when deriving Eq: " & s) _&U_ : Unify → Unify → Unify (positive xs) &U (positive ys) = positive (xs ++ ys) (positive _) &U negative = negative negative &U (positive _) = negative negative &U negative = negative {-# TERMINATING #-} unify : Term → Term → TC Unify unifyArgs : List (Arg Term) → List (Arg Term) → TC Unify unify s t with s == t unify s t | yes _ = pure (positive []) unify (var x []) (var y []) | no _ = if (x <? y) -- In var-var case, instantiate the one that is bound the closest to us. then pure (positive ((x , var y []) ∷ [])) else pure (positive ((y , var x []) ∷ [])) unify (var x []) t | no _ = if (elem x (freeVars t)) then failure "cyclic occurrence" -- We don't currently know if the occurrence is rigid or not else pure (positive ((x , t) ∷ [])) unify t (var x []) | no _ = if (elem x (freeVars t)) then failure "cyclic occurrence" else pure (positive ((x , t) ∷ [])) unify (con c₁ xs₁) (con c₂ xs₂) | no _ = if (isYes (c₁ == c₂)) then unifyArgs xs₁ xs₂ else pure negative unify _ _ | no _ = failure "not a constructor or a variable" unifyArgs [] [] = pure (positive []) unifyArgs [] (_ ∷ _) = failure "panic: different number of arguments" unifyArgs (_ ∷ _) [] = failure "panic: different number of arguments" unifyArgs (arg v₁ x ∷ xs) (arg v₂ y ∷ ys) = if isYes (_==_ {{EqArgInfo}} v₁ v₂) then (unify x y >>= λ { (positive sub) → (positive sub &U_) <$> unifyArgs (substArgs sub xs) (substArgs sub ys) ; negative → pure negative }) else failure "panic: hiding mismatch" unifyIndices : (c₁ c₂ : Name) → TC Unify unifyIndices c₁ c₂ = do let panic = failure "panic: constructor type doesn't end in a def" tel₁ , def d₁ xs₁ ← telView <$> getType c₁ where _ → panic tel₂ , def d₂ xs₂ ← telView <$> getType c₂ where _ → panic n₁ ← #pars d₁ n₂ ← #pars d₂ let ixs₁ = drop n₁ xs₁ ixs₂ = drop n₂ xs₂ unifyArgs (weaken (length tel₂ - n₂) ixs₁) -- weaken all variables of first constructor by number of arguments of second constructor (weakenFrom (length tel₂ - n₂) (length tel₁ - n₁) ixs₂) -- weaken parameters of second constructor by number of arguments of first constructor -- Analysing constructor types -- forcedArgs : (c : Name) → TC (List Nat) forcedArgs c = caseM (unifyIndices c c) of λ { (positive xs) → pure (map fst xs) ; _ → pure [] } data Forced : Set where forced free : Forced instance DeBruijnForced : DeBruijn Forced strengthenFrom {{DeBruijnForced}} _ _ = just weakenFrom {{DeBruijnForced}} _ _ = id RemainingArgs : Nat → Set RemainingArgs = Vec (Arg (Forced × Term × Term)) leftArgs : ∀ {n} → RemainingArgs n → List (Arg Term) leftArgs = map (fmap (fst ∘ snd)) ∘ vecToList rightArgs : ∀ {n} → RemainingArgs n → List (Arg Term) rightArgs = map (fmap (snd ∘ snd)) ∘ vecToList classifyArgs : (c : Name) → TC (Σ Nat RemainingArgs) classifyArgs c = do #argsc ← #args c forcedc ← forcedArgs c let #freec = #argsc - length forcedc _,_ _ ∘ classify #freec forcedc (#argsc - 1) (#freec - 1) <$> argsTel c -- The final argument should be (weakenTel (#argsc + #freec) (argsTel c)), -- but we don't really care about the types of the arguments anyway. where classify : Nat → List Nat → (m n : Nat) (tel : Telescope) → RemainingArgs (length tel) classify _ _ m n [] = [] classify #freec forcedc m n ((_ , arg i ty) ∷ tel) = if (elem m forcedc) then arg i (forced , var (#freec + m) [] , var (#freec + m) []) ∷ classify #freec forcedc (m - 1) n tel else arg i (free , var (#freec + m) [] , var n []) ∷ classify #freec forcedc (m - 1) (n - 1) tel rightArgsFree : ∀ {n} → RemainingArgs n → List (Arg Term) rightArgsFree [] = [] rightArgsFree (arg _ (forced , _ , _) ∷ xs) = rightArgsFree xs rightArgsFree (arg i (free , _ , x) ∷ xs) = arg i x ∷ rightArgsFree xs countFree : ∀ {n} → RemainingArgs n → Nat countFree xs = length (rightArgsFree xs) refreshArgs : ∀ {n} → RemainingArgs n → RemainingArgs n refreshArgs xs = refresh (nfree - 1) xs where nfree = countFree xs refresh : ∀ {n} → Nat → RemainingArgs n → RemainingArgs n refresh n [] = [] refresh n (arg i (forced , x , y) ∷ xs) = arg i (forced , x , y) ∷ refresh n xs refresh n (arg i (free , x , y) ∷ xs) = arg i (free , x , var n []) ∷ refresh (n - 1) xs -- Matching constructor case -- caseDec : ∀ {a b} {A : Set a} {B : Set b} → Dec A → (A → B) → (¬ A → B) → B caseDec (yes x) y n = y x caseDec (no x) y n = n x checkEqArgs : ∀ {n} (c : Name) (xs : List (Arg Term)) (ys : RemainingArgs n) → Term checkEqArgs c xs (arg i (forced , y , z) ∷ args) = checkEqArgs c (xs ++ [ arg i y ]) args checkEqArgs {suc remainingArgs} c xs (arg i (free , y , z) ∷ args) = def₃ (quote caseDec) (def₂ (quote _==_) y z) (vLam "x≡y" checkEqArgsYes) (vLam "x≢y" checkEqArgsNo) where remainingFree = countFree args wk : {A : Set} {{_ : DeBruijn A}} → Nat → A → A wk k = weaken (k + remainingFree) checkEqArgsYes : Term checkEqArgsYes = def (quote transport) ( (vArg (vLam "x" (nPi (map ("x" ,_) (rightArgsFree args)) (def₁ (quote Dec) (wk 2 (con c (xs ++ arg i y ∷ (leftArgs args))) `≡ con c (wk 2 xs ++ arg i (var remainingFree []) ∷ rightArgs (refreshArgs (wk 2 args)))))))) ∷ (vArg (var 0 [])) ∷ (vArg (nLam (map ("x" ,_) (rightArgsFree args)) (checkEqArgs c (wk 1 (xs ++ [ arg i y ])) (refreshArgs (wk 1 args))))) ∷ weaken 1 (rightArgsFree args)) checkEqArgsNo : Term checkEqArgsNo = con₁ (quote no) (vLam "eq" (var 1 (vArg (def₃ (quote _∋_) (nPi (hideTel (("_" , arg i z) ∷ map ("_" ,_) (rightArgsFree args))) (weaken (3 + remainingFree) (con c (xs ++ arg i y ∷ leftArgs args)) `≡ con c (wk 3 xs ++ arg i (var remainingFree []) ∷ rightArgs (refreshArgs (wk 3 args))) `→ wk 4 y `≡ var (1 + remainingFree) [])) (pat-lam (clause [] (replicate (1 + remainingFree) (hArg (dot unknown)) ++ vArg `refl ∷ []) `refl ∷ []) []) (var 0 [])) ∷ []))) checkEqArgs _ _ _ = con₁ (quote yes) (con₀ (quote refl)) matchingClause : (c : Name) → TC Clause matchingClause c = do _ , args ← classifyArgs c let #cargs-total = length (vecToList args) #cargs-free = countFree args paramTel ← hideTel <$> params c let paramPats = weaken (#cargs-total + #cargs-free) $ newPatVars $ map snd paramTel let paramArgs = weaken (#cargs-total + #cargs-free) $ newVars $ map snd paramTel pure (clause (paramTel ++ ctel-total args ++ ctel-free args) (paramPats ++ vArg (con c (makeLeftPattern args (#cargs-total + #cargs-free))) ∷ vArg (con c (makeRightPattern args #cargs-free)) ∷ []) (checkEqArgs c paramArgs args)) where ctel-total : RemainingArgs n → Telescope ctel-total [] = [] ctel-total (arg i _ ∷ args) = ("_" , arg i unknown) ∷ ctel-total args ctel-free : RemainingArgs n → Telescope ctel-free [] = [] ctel-free (arg i (forced , _) ∷ args) = ctel-free args ctel-free (arg i (free , _) ∷ args) = ("_" , arg i unknown) ∷ ctel-free args makeLeftPattern : ∀ {n} → RemainingArgs n → Nat → List (Arg Pattern) makeLeftPattern (arg i x ∷ xs) (suc n) = arg i (var n) ∷ makeLeftPattern xs n makeLeftPattern _ _ = [] makeRightPattern : ∀ {n} → RemainingArgs n → Nat → List (Arg Pattern) makeRightPattern (arg i (forced , _ , _) ∷ xs) n = arg i (dot unknown) ∷ makeRightPattern xs n makeRightPattern (arg i (free , _ , _) ∷ xs) (suc n) = arg i (var n) ∷ makeRightPattern xs n makeRightPattern _ _ = [] -- Mismatching constructor case -- mismatchingClause : (c₁ c₂ : Name) (fs : List Nat) → TC Clause mismatchingClause c₁ c₂ fs = do tel₁ ← argsTel c₁ tel₂ ← argsTel c₂ let #args₁ = length tel₁ #args₂ = length tel₂ free-tel₁ = makeFreeTel (#args₁ + #args₂) tel₁ free-tel₂ = makeFreeTel #args₂ tel₂ #free-args₁ = length free-tel₁ #free-args₂ = length free-tel₂ pure (clause (free-tel₁ ++ free-tel₂) (vArg (con c₁ (makePattern (#args₁ + #args₂) (#free-args₁ + #free-args₂) tel₁)) ∷ vArg (con c₂ (makePattern #args₂ #free-args₂ tel₂)) ∷ []) (con (quote no) ([ vArg (pat-lam ([ absurd-clause [ "()" , vArg unknown ] ([ vArg absurd ]) ]) []) ]))) where makeFreeTel : (k : Nat) → Telescope → Telescope makeFreeTel (suc k) ((x , a) ∷ xs) = if (elem k fs) then [] else [ x , (unknown <$ a) ] ++ makeFreeTel k xs makeFreeTel _ _ = [] makePattern : (k : Nat) (n : Nat) (tel : Telescope) → List (Arg Pattern) makePattern (suc k) n ((_ , arg i _) ∷ args) = if (elem k fs) then arg i (dot unknown) ∷ makePattern k n args else arg i (var (n - 1)) ∷ makePattern k (n - 1) args makePattern k n _ = [] -- Clauses -- makeClause : (c₁ c₂ : Name) → TC (List Clause) makeClause c₁ c₂ = case (c₁ == c₂) of λ { (yes _) → _∷ [] <$> matchingClause c₁ ; (no _) → caseM (unifyIndices c₁ c₂) of λ { (positive fs) → _∷ [] <$> mismatchingClause c₁ c₂ (map fst fs) ; _ → pure [] } } constructorPairs : (d : Name) → TC (List (Name × Name)) constructorPairs d = caseM getDefinition d of λ { (data-type _ cs) → pure $ concat (map (λ c₁ → map (_,_ c₁) cs) cs) ; _ → pure [] } eqDefinition : (d : Name) → TC (List Clause) eqDefinition d = concat <$> (mapM (uncurry makeClause) =<< constructorPairs d) makeArgs : Nat → List (Arg Nat) → List (Arg Term) makeArgs n xs = reverse $ map (fmap (λ i → var (n - i - 1) [])) xs computeInstanceType : Nat → List (Arg Nat) → Type → Maybe Term computeInstanceType n xs (agda-sort _) = just (`Eq (var n (makeArgs n xs))) computeInstanceType n xs (pi a (abs s b)) = pi (hArg (unArg a)) ∘ abs s <$> computeInstanceType (suc n) ((n <$ a) ∷ xs) b computeInstanceType _ _ _ = nothing computeType : Name → Nat → List (Arg Nat) → Telescope → Telescope → Term computeType d n xs is [] = telPi (reverse is) $ def d (makeArgs (n + k) xs) `→ def d (makeArgs (n + k + 1) xs) `→ def₁ (quote Dec) (var 1 [] `≡ var 0 []) where k = length is computeType d n xs is ((x , a) ∷ tel) = unArg a `→ʰ (case computeInstanceType 0 [] (weaken 1 $ unArg a) of λ { (just i) → computeType d (1 + n) ((n <$ a) ∷ xs) ((x , iArg (weaken (length is) i)) ∷ weaken 1 is) tel ; nothing → computeType d (1 + n) ((n <$ a) ∷ xs) (weaken 1 is) tel }) eqType : Name → TC Type eqType d = computeType d 0 [] [] ∘ fst ∘ telView <$> getType d macro deriveEqType : Name → Tactic deriveEqType d hole = unifyTC hole =<< (computeType d 0 [] [] ∘ fst ∘ telView <$> getType d) deriveEqDef : Name → Name → TC ⊤ deriveEqDef i d = defineFun i =<< eqDefinition d declareEqInstance : Name → Name → TC ⊤ declareEqInstance iname d = declareDef (iArg iname) =<< instanceType d (quote Eq) defineEqInstance : Name → Name → TC ⊤ defineEqInstance iname d = do fname ← freshName ("_==[" & show d & "]_") declareDef (vArg fname) =<< eqType d dictCon ← recordConstructor (quote Eq) defineFun iname (clause [] [] (con₁ dictCon (def₀ fname)) ∷ []) defineFun fname =<< eqDefinition d return _ deriveEq : Name → Name → TC ⊤ deriveEq iname d = declareEqInstance iname d >> defineEqInstance iname d
37.476303
122
0.565729
3fcb9609604ec2f0702fc707b05187d0de9edd31
14,847
agda
Agda
src/syntax-util.agda
zmthy/cedille
9df4b85b55b57f97466242fdbb499adbd3bca893
[ "MIT" ]
null
null
null
src/syntax-util.agda
zmthy/cedille
9df4b85b55b57f97466242fdbb499adbd3bca893
[ "MIT" ]
null
null
null
src/syntax-util.agda
zmthy/cedille
9df4b85b55b57f97466242fdbb499adbd3bca893
[ "MIT" ]
null
null
null
module syntax-util where open import cedille-types open import general-util open import constants open import json posinfo-gen : posinfo posinfo-gen = "generated" pi-gen = posinfo-gen first-position : posinfo first-position = "1" dummy-var : var dummy-var = "_dummy" id-term : term id-term = Lam ff "x" nothing (Var "x") tt-term = Lam ff "t" nothing (Lam ff "f" nothing (Var "t")) ff-term = Lam ff "t" nothing (Lam ff "f" nothing (Var "f")) compileFailType : type compileFailType = TpAbs tt "X" (Tkk KdStar) (TpVar "X") qualif-info : Set qualif-info = var × args qualif : Set qualif = trie qualif-info tag : Set tag = string × json tagged-val : Set tagged-val = string × rope × 𝕃 tag tags-to-json : 𝕃 tag → 𝕃 json tags-to-json [] = [] tags-to-json ts = [ json-object ts ] tagged-val-to-json : tagged-val → string × json tagged-val-to-json (t , v , tags) = t , json-array (json-rope v :: tags-to-json tags) tagged-vals-to-json : 𝕃 tagged-val → json tagged-vals-to-json = json-object ∘ map tagged-val-to-json make-tag : (name : string) → (values : 𝕃 tag) → (start : ℕ) → (end : ℕ) → tag make-tag name vs start end = name , json-object (("start" , json-nat start) :: ("end" , json-nat end) :: vs) posinfo-to-ℕ : posinfo → ℕ posinfo-to-ℕ pi with string-to-ℕ pi posinfo-to-ℕ pi | just n = n posinfo-to-ℕ pi | nothing = 0 -- should not happen posinfo-plus : posinfo → ℕ → posinfo posinfo-plus pi n = ℕ-to-string (posinfo-to-ℕ pi + n) posinfo-plus-str : posinfo → string → posinfo posinfo-plus-str pi s = posinfo-plus pi (string-length s) -- qualify variable by module name _#_ : string → string → string fn # v = fn ^ qual-global-str ^ v _%_ : posinfo → var → string pi % v = pi ^ qual-local-str ^ v compileFail : var compileFail = "compileFail" compileFail-qual = "" % compileFail tk-is-type : tpkd → 𝔹 tk-is-type = either-else (const tt) (const ff) tT-is-term : tmtp → 𝔹 tT-is-term = either-else (const tt) (const ff) tk-start-pos : ex-tk → posinfo term-start-pos : ex-tm → posinfo type-start-pos : ex-tp → posinfo kind-start-pos : ex-kd → posinfo term-start-pos (ExApp t x t₁) = term-start-pos t term-start-pos (ExAppTp t tp) = term-start-pos t term-start-pos (ExHole pi) = pi term-start-pos (ExLam pi x _ x₁ x₂ t) = pi term-start-pos (ExLet pi _ _ _) = pi term-start-pos (ExOpen pi _ _ _ _) = pi term-start-pos (ExParens pi t pi') = pi term-start-pos (ExVar pi x₁) = pi term-start-pos (ExBeta pi _ _) = pi term-start-pos (ExIotaPair pi _ _ _ _) = pi term-start-pos (ExIotaProj t _ _) = term-start-pos t term-start-pos (ExEpsilon pi _ _ _) = pi term-start-pos (ExPhi pi _ _ _ _) = pi term-start-pos (ExRho pi _ _ _ _ _) = pi term-start-pos (ExChi pi _ _) = pi term-start-pos (ExDelta pi _ _) = pi term-start-pos (ExSigma pi _) = pi term-start-pos (ExTheta pi _ _ _) = pi term-start-pos (ExMu pi _ _ _ _ _ _) = pi type-start-pos (ExTpAbs pi _ _ _ _ _) = pi type-start-pos (ExTpLam pi _ _ _ _) = pi type-start-pos (ExTpIota pi _ _ _ _) = pi type-start-pos (ExTpApp t t₁) = type-start-pos t type-start-pos (ExTpAppt t x) = type-start-pos t type-start-pos (ExTpArrow t _ t₁) = type-start-pos t type-start-pos (ExTpEq pi _ _ pi') = pi type-start-pos (ExTpParens pi _ pi') = pi type-start-pos (ExTpVar pi x₁) = pi type-start-pos (ExTpNoSpans t _) = type-start-pos t -- we are not expecting this on input type-start-pos (ExTpHole pi) = pi --ACG type-start-pos (ExTpLet pi _ _) = pi kind-start-pos (ExKdAbs pi _ x x₁ k) = pi kind-start-pos (ExKdArrow atk k₁) = tk-start-pos atk kind-start-pos (ExKdHole pi) = pi kind-start-pos (ExKdParens pi k pi') = pi kind-start-pos (ExKdVar pi x₁ _) = pi kind-start-pos (ExKdStar pi) = pi tk-start-pos (ExTkt t) = type-start-pos t tk-start-pos (ExTkk k) = kind-start-pos k term-end-pos : ex-tm → posinfo type-end-pos : ex-tp → posinfo kind-end-pos : ex-kd → posinfo tk-end-pos : ex-tk → posinfo lterms-end-pos : posinfo → 𝕃 lterm → posinfo args-end-pos : posinfo → ex-args → posinfo arg-end-pos : ex-arg → posinfo kvar-end-pos : posinfo → var → ex-args → posinfo params-end-pos : posinfo → ex-params → posinfo param-end-pos : ex-param → posinfo term-end-pos (ExApp t x t') = term-end-pos t' term-end-pos (ExAppTp t tp) = type-end-pos tp term-end-pos (ExHole pi) = posinfo-plus pi 1 term-end-pos (ExLam pi x _ x₁ x₂ t) = term-end-pos t term-end-pos (ExLet _ _ _ t) = term-end-pos t term-end-pos (ExOpen pi _ _ _ t) = term-end-pos t term-end-pos (ExParens pi t pi') = pi' term-end-pos (ExVar pi x) = posinfo-plus-str pi x term-end-pos (ExBeta pi _ (just (PosTm t pi'))) = pi' term-end-pos (ExBeta pi (just (PosTm t pi')) nothing) = pi' term-end-pos (ExBeta pi nothing nothing) = posinfo-plus pi 1 term-end-pos (ExIotaPair _ _ _ _ pi) = pi term-end-pos (ExIotaProj _ _ pi) = pi term-end-pos (ExEpsilon pi _ _ t) = term-end-pos t term-end-pos (ExPhi _ _ _ _ pi) = pi term-end-pos (ExRho pi _ _ _ t t') = term-end-pos t' term-end-pos (ExChi pi T t') = term-end-pos t' term-end-pos (ExDelta pi oT t) = term-end-pos t term-end-pos (ExSigma pi t) = term-end-pos t term-end-pos (ExTheta _ _ t ls) = lterms-end-pos (term-end-pos t) ls term-end-pos (ExMu _ _ _ _ _ _ pi) = pi type-end-pos (ExTpAbs pi _ _ _ _ t) = type-end-pos t type-end-pos (ExTpLam _ _ _ _ t) = type-end-pos t type-end-pos (ExTpIota _ _ _ _ tp) = type-end-pos tp type-end-pos (ExTpApp t t') = type-end-pos t' type-end-pos (ExTpAppt t x) = term-end-pos x type-end-pos (ExTpArrow t _ t') = type-end-pos t' type-end-pos (ExTpEq pi _ _ pi') = pi' type-end-pos (ExTpParens pi _ pi') = pi' type-end-pos (ExTpVar pi x) = posinfo-plus-str pi x type-end-pos (ExTpHole pi) = posinfo-plus pi 1 type-end-pos (ExTpNoSpans t pi) = pi type-end-pos (ExTpLet _ _ t) = type-end-pos t kind-end-pos (ExKdAbs pi _ x x₁ k) = kind-end-pos k kind-end-pos (ExKdArrow atk k) = kind-end-pos k kind-end-pos (ExKdHole pi) = posinfo-plus pi 1 kind-end-pos (ExKdParens pi k pi') = pi' kind-end-pos (ExKdVar pi x ys) = args-end-pos (posinfo-plus-str pi x) ys kind-end-pos (ExKdStar pi) = posinfo-plus pi 1 tk-end-pos (ExTkt T) = type-end-pos T tk-end-pos (ExTkk k) = kind-end-pos k args-end-pos pi (x :: ys) = args-end-pos (arg-end-pos x) ys args-end-pos pi [] = pi arg-end-pos (ExTmArg me t) = term-end-pos t arg-end-pos (ExTpArg T) = type-end-pos T kvar-end-pos pi v = args-end-pos (posinfo-plus-str pi v) params-end-pos pi [] = pi params-end-pos pi (p :: ps) = params-end-pos (param-end-pos p) ps param-end-pos (ExParam pi me pi' x atk pi'') = pi'' lterms-end-pos pi [] = pi lterms-end-pos pi (Lterm _ t :: ls) = lterms-end-pos (term-end-pos t) ls {- return the end position of the given term if it is there, otherwise the given posinfo -} optTerm-end-pos : posinfo → maybe pos-tm → posinfo optTerm-end-pos pi nothing = pi optTerm-end-pos pi (just (PosTm x x₁)) = x₁ optTerm-end-pos-beta : posinfo → maybe pos-tm → maybe pos-tm → posinfo optTerm-end-pos-beta pi _ (just (PosTm x pi')) = pi' optTerm-end-pos-beta pi (just (PosTm x pi')) nothing = pi' optTerm-end-pos-beta pi nothing nothing = posinfo-plus pi 1 optAs-or : maybe import-as → posinfo → var → posinfo × var optAs-or nothing pi x = pi , x optAs-or (just (ImportAs pi x)) _ _ = pi , x TpApp-tk : type → var → tpkd → type TpApp-tk tp x (Tkk _) = TpAppTp tp (TpVar x) TpApp-tk tp x (Tkt _) = TpAppTm tp (Var x) -- checking-sythesizing enum data checking-mode : Set where checking : checking-mode synthesizing : checking-mode untyped : checking-mode maybe-to-checking : {A : Set} → maybe A → checking-mode maybe-to-checking (just _) = checking maybe-to-checking nothing = synthesizing eq-checking-mode : (m₁ m₂ : checking-mode) → 𝔹 eq-checking-mode checking checking = tt eq-checking-mode synthesizing synthesizing = tt eq-checking-mode untyped untyped = tt eq-checking-mode _ _ = ff ------------------------------------------------------ -- functions intended for building terms for testing ------------------------------------------------------ mlam : var → term → term mlam x t = Lam ff x nothing t mall : var → tpkd → type → type mall = TpAbs tt mpi : var → tpkd → type → type mpi = TpAbs ff imps-to-cmds : imports → cmds imps-to-cmds = map CmdImport cmds-to-imps : cmds → imports cmds-to-imps [] = [] cmds-to-imps (CmdImport i :: cs) = i :: cmds-to-imps cs cmds-to-imps (_ :: cs) = cmds-to-imps cs ex-cmds-to-imps : ex-cmds → ex-imports ex-cmds-to-imps [] = [] ex-cmds-to-imps (ExCmdImport i :: cs) = i :: ex-cmds-to-imps cs ex-cmds-to-imps (_ :: cs) = ex-cmds-to-imps cs split-var-h : 𝕃 char → 𝕃 char × 𝕃 char split-var-h [] = [] , [] split-var-h (qual-global-chr :: xs) = [] , xs split-var-h (x :: xs) with split-var-h xs ... | xs' , ys = (x :: xs') , ys split-var : var → var × var split-var v with split-var-h (reverse (string-to-𝕃char v)) ... | xs , ys = 𝕃char-to-string (reverse ys) , 𝕃char-to-string (reverse xs) var-suffix : var → maybe var var-suffix v with split-var v ... | "" , _ = nothing ... | _ , sfx = just sfx -- unique qualif domain prefixes qual-pfxs : qualif → 𝕃 var qual-pfxs q = uniq (prefixes (trie-strings q)) where uniq : 𝕃 var → 𝕃 var uniq vs = stringset-strings (stringset-insert* empty-stringset vs) prefixes : 𝕃 var → 𝕃 var prefixes [] = [] prefixes (v :: vs) with split-var v ... | "" , sfx = vs ... | pfx , sfx = pfx :: prefixes vs unqual-prefix : qualif → 𝕃 var → var → var → var unqual-prefix q [] sfx v = v unqual-prefix q (pfx :: pfxs) sfx v with trie-lookup q (pfx # sfx) ... | just (v' , _) = if v =string v' then pfx # sfx else v ... | nothing = v unqual-bare : qualif → var → var → var unqual-bare q sfx v with trie-lookup q sfx ... | just (v' , _) = if v =string v' then sfx else v ... | nothing = v unqual-local : var → var unqual-local v = f' (string-to-𝕃char v) where f : 𝕃 char → maybe (𝕃 char) f [] = nothing f ('@' :: t) = f t maybe-or just t f (h :: t) = f t f' : 𝕃 char → string f' (meta-var-pfx :: t) = maybe-else' (f t) v (𝕃char-to-string ∘ _::_ meta-var-pfx) f' t = maybe-else' (f t) v 𝕃char-to-string unqual-all : qualif → var → string unqual-all q v with var-suffix v ... | nothing = v ... | just sfx = unqual-bare q sfx (unqual-prefix q (qual-pfxs q) sfx v) -- Given a qualified variable and a function that renames it, -- we strip away the qualification prefix, call the function, -- then prepend the prefix to the result reprefix : (var → var) → var → var reprefix f x = maybe-else' (pfx (string-to-𝕃char x) []) (f x) $ uncurry λ p s → p ^ f s where ret : 𝕃 char → 𝕃 char → maybe (var × var) ret pfx sfx = just (𝕃char-to-string (reverse pfx) , 𝕃char-to-string sfx) pfx : 𝕃 char → 𝕃 char → maybe (var × var) pfx (qual-global-chr :: xs) acc = pfx xs (qual-global-chr :: acc) maybe-or ret (qual-global-chr :: acc) xs pfx (qual-local-chr :: xs) acc = pfx xs (qual-local-chr :: acc) maybe-or ret (qual-local-chr :: acc) xs pfx (x :: xs) acc = pfx xs (x :: acc) pfx [] pfx = nothing data-to/ = reprefix ("to/" ^_) data-Is/ = reprefix ("Is/" ^_) data-is/ = reprefix ("is/" ^_) mu-Type/ = reprefix ("Type/" ^_) mu-isType/ = reprefix ("isType/" ^_) mu-isType/' = reprefix ("is" ^_) -- Generated during elaboration data-TypeF/ = reprefix ("F/" ^_) data-IndF/ = reprefix ("IndF/" ^_) data-fmap/ = reprefix ("fmap/" ^_) -- num-gt : num → ℕ → 𝕃 string num-gt n n' = maybe-else [] (λ n'' → if n'' > n' then [ n ] else []) (string-to-ℕ n) nums-gt : 𝕃 num → ℕ → 𝕃 string nums-gt [] n' = [] nums-gt (n :: ns) n' = maybe-else [] (λ n'' → if n'' > n' || iszero n'' then [ n ] else []) (string-to-ℕ n) ++ nums-gt ns n' nums-to-stringset : 𝕃 num → stringset × 𝕃 string {- Repeated numbers -} nums-to-stringset [] = empty-stringset , [] nums-to-stringset (n :: ns) with nums-to-stringset ns ...| ss , rs = if stringset-contains ss n then ss , n :: rs else stringset-insert ss n , rs optNums-to-stringset : maybe (𝕃 num) → maybe stringset × (ℕ → maybe string) optNums-to-stringset nothing = nothing , λ _ → nothing optNums-to-stringset (just ns) with nums-to-stringset ns ...| ss , [] = just ss , λ n → case nums-gt ns n of λ where [] → nothing ns-g → just ("Occurrences not found: " ^ 𝕃-to-string id ", " ns-g ^ " (total occurrences: " ^ ℕ-to-string n ^ ")") ...| ss , rs = just ss , λ n → just ("The list of occurrences contains the following repeats: " ^ 𝕃-to-string id ", " rs) def-var : ex-def → var def-var (ExDefTerm _ x _ _) = x def-var (ExDefType _ x _ _) = x -- expression descriptor data exprd : Set where TERM : exprd TYPE : exprd KIND : exprd -- TPKD : exprd ⟦_⟧ : exprd → Set ⟦ TERM ⟧ = term ⟦ TYPE ⟧ = type ⟦ KIND ⟧ = kind --⟦ TPKD ⟧ = tpkd ⟦_⟧' : exprd → Set ⟦ TERM ⟧' = ex-tm ⟦ TYPE ⟧' = ex-tp ⟦ KIND ⟧' = ex-kd --⟦ TPKD ⟧' = ex-tk exprd-name : exprd → string exprd-name TERM = "term" exprd-name TYPE = "type" exprd-name KIND = "kind" infixl 12 _-tk_ _-tk'_ _-tT_ _-tT'_ _-arg_ _-arg'_ _-tk_ : (∀ {ed} → ⟦ ed ⟧ → ⟦ ed ⟧) → tpkd → tpkd f -tk Tkt T = Tkt (f T) f -tk Tkk k = Tkk (f k) _-tk'_ : ∀ {X : Set} → (∀ {ed : exprd} → ⟦ ed ⟧ → X) → tpkd → X f -tk' Tkt T = f T f -tk' Tkk k = f k _-tT_ : (∀ {ed} → ⟦ ed ⟧ → ⟦ ed ⟧) → tmtp → tmtp f -tT Ttm t = Ttm (f t) f -tT Ttp T = Ttp (f T) _-tT'_ : ∀ {X : Set} → (∀ {ed : exprd} → ⟦ ed ⟧ → X) → tmtp → X f -tT' Ttm t = f t f -tT' Ttp T = f T _-arg_ : (∀ {ed} → ⟦ ed ⟧ → ⟦ ed ⟧) → arg → arg f -arg Arg t = Arg (f t) f -arg ArgE tT = ArgE (f -tT tT) _-arg'_ : ∀ {X : Set} → (∀ {ed : exprd} → ⟦ ed ⟧ → X) → arg → X f -arg' Arg t = f t f -arg' ArgE tT = f -tT' tT pos-tm-to-tm : pos-tm → ex-tm pos-tm-to-tm (PosTm t pi) = t ex-case-arg-erased : ex-case-arg-sym → erased? ex-case-arg-erased ExCaseArgTm = ff ex-case-arg-erased _ = tt ex-case-ctr : ex-case → var ex-case-ctr (ExCase pi x cas t) = x start-modname : ex-file → string start-modname (ExModule _ _ _ mn _ _ _) = mn {- traverse-internal : ∀ {ed} {X} → (∀ {ed} → X → ⟦ ed ⟧ → X × ⟦ ed ⟧) → X → ⟦ ed ⟧ → ⟦ ed ⟧ traverse-internal {_} {X} f = h (fr ff) where fr : ∀ {ed} → 𝔹 → (X → ⟦ ed ⟧ → ⟦ ed ⟧) fr tt = f fr ff = λ x t → t h : ∀ {ed} → (∀ {ed} → X → ⟦ ed ⟧ → X × ⟦ ed ⟧) → X → ⟦ ed ⟧ → ⟦ ed ⟧ h {TERM} f (App t t') = ? h {TERM} f (AppE t tT) = ? h {TERM} f (Beta t t') = ? h {TERM} f (Delta T t) = ? h {TERM} f (Hole pi) = ? h {TERM} f (Internal r t) = ? h {TERM} f (IotaPair t t' x T) =? h {TERM} f (IotaProj t n) = ? h {TERM} f (Lam me x tk t) = ? h {TERM} f (LetTm me x T? t t') = ? h {TERM} f (LetTp x k T t) = ? h {TERM} f (Phi tₑ t₁ t₂) = ? h {TERM} f (Rho t x T t') = ? h {TERM} f (Sigma t) = ? h {TERM} f (Mu μ t T t~ cs) = ? h {TERM} f (Var x) = ? h {TYPE} f (TpAbs me x tk T) = ? h {TYPE} f (TpIota x T₁ T₂) = ? h {TYPE} f (TpApp T tT) = ? h {TYPE} f (TpEq t₁ t₂) = ? h {TYPE} f (TpHole pi) = ? h {TYPE} f (TpLam x tk T) = ? h {TYPE} f (TpVar x) = ? h {KIND} f KdStar = ? h {KIND} f (KdHole pi) = ? h {KIND} f (KdAbs x tk k) = ? -}
31.256842
116
0.619048
72b4328ffd0b744c5fc6de93eb65a2c067ada08d
321
agda
Agda
test/interaction/Issue642.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/interaction/Issue642.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/interaction/Issue642.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
module Issue642 where module M₁ (X : Set) where postulate F : X → Set module M₂ (X : Set) where open M₁ X public postulate A : Set x : A open M₂ A foo : F x foo = {!!} -- The goal was displayed as M₁.F A x rather than F x. If "open M₂ A" -- is replaced by "open M₁ A", then the goal is displayed correctly.
16.05
69
0.64486
346183f569ea537c782232a9cbf131fb26993c46
4,341
agda
Agda
Relation/Binary/Construct/Symmetrize.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
Relation/Binary/Construct/Symmetrize.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
Relation/Binary/Construct/Symmetrize.agda
rei1024/agda-categories
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} -- Take a relation that is already reflexive and transitive -- and make it symmetric. -- (Borrowed from Categories/Support/ZigZag from copumpkin's Categories library module Relation.Binary.Construct.Symmetrize where open import Level open import Relation.Binary open import Relation.Binary.Construct.On using () renaming (isEquivalence to on-preserves-equivalence) data Direction : Set where ↘ ↗ : Direction rotate : Direction → Direction rotate ↘ = ↗ rotate ↗ = ↘ private variable c ℓ₁ ℓ₂ : Level Carrier : Set c data ZigZag′ (_∼_ : Rel Carrier ℓ₂) : (x y : Carrier) (begin end : Direction) → Set (levelOfTerm x ⊔ ℓ₂) where zig : ∀ {x y z e} (first : x ∼ y) (rest : ZigZag′ _∼_ y z ↗ e) → ZigZag′ _∼_ x z ↘ e zag : ∀ {x y z e} (first : y ∼ x) (rest : ZigZag′ _∼_ y z ↘ e) → ZigZag′ _∼_ x z ↗ e slish : ∀ {x y} (last : x ∼ y) → ZigZag′ _∼_ x y ↘ ↘ slash : ∀ {x y} (last : y ∼ x) → ZigZag′ _∼_ x y ↗ ↗ data Alternating′ (_∼_ : Carrier -> Carrier -> Set ℓ₂) (x y : Carrier) : Set (levelOfTerm x ⊔ ℓ₂) where disorient : ∀ {begin end} (zz : ZigZag′ _∼_ x y begin end) → Alternating′ _∼_ x y module _ (Base : Preorder c ℓ₁ ℓ₂) where ZigZag : (x y : Preorder.Carrier Base) (begin end : Direction) → Set (c ⊔ ℓ₂) ZigZag = ZigZag′ (Preorder._∼_ Base) private sym′ : {x y z : Preorder.Carrier Base} {begin middle end : Direction} → ZigZag y z middle end → ZigZag y x middle begin → ZigZag z x (rotate end) begin sym′ (zig first rest) accum = sym′ rest (zag first accum) sym′ (zag first rest) accum = sym′ rest (zig first accum) sym′ (slish last) accum = zag last accum sym′ (slash last) accum = zig last accum sym : ∀ {x y begin end} → ZigZag x y begin end → ZigZag y x (rotate end) (rotate begin) sym (zig first rest) = sym′ rest (slash first) sym (zag first rest) = sym′ rest (slish first) sym (slish last) = slash last sym (slash last) = slish last trans : ∀ {x y z begin end begin′ end′} → ZigZag x y begin end → ZigZag y z begin′ end′ → ZigZag x z begin end′ trans (zig first rest) yz = zig first (trans rest yz) trans (zag first rest) yz = zag first (trans rest yz) trans (slish last) (zig first rest) = zig (Preorder.trans Base last first) rest trans (slish last) (zag first rest) = zig last (zag first rest) trans (slish last) (slish only) = slish (Preorder.trans Base last only) trans (slish last) (slash only) = zig last (slash only) trans (slash last) (zig first rest) = zag last (zig first rest) trans (slash last) (zag first rest) = zag (Preorder.trans Base first last) rest trans (slash last) (slish only) = zag last (slish only) trans (slash last) (slash only) = slash (Preorder.trans Base only last) Alternating : (x y : Preorder.Carrier Base) → Set (c ⊔ ℓ₂) Alternating = Alternating′ (Preorder._∼_ Base) private is-equivalence : IsEquivalence Alternating is-equivalence = record { refl = disorient (slash (Preorder.refl Base)) ; sym = λ where (disorient zz) → disorient (sym zz) ; trans = λ where (disorient ij) (disorient jk) → disorient (trans ij jk) } setoid : Setoid c (c ⊔ ℓ₂) setoid = record { Carrier = Preorder.Carrier Base ; _≈_ = Alternating ; isEquivalence = is-equivalence } -- the main eliminators for Alternating -- they prove that any equivalence that -- respects the base preorder also respects its Alternating completion. locally-minimal : ∀ {ℓ′} {_≈_ : Rel (Preorder.Carrier Base) ℓ′} (≈-isEquivalence : IsEquivalence _≈_) → (Preorder._∼_ Base ⇒ _≈_) → (Alternating ⇒ _≈_) locally-minimal {_} {_≋_} isEq inj (disorient zz) = impl zz where open IsEquivalence isEq renaming (sym to >sym; trans to _>trans>_) impl : {i j : Preorder.Carrier Base} {b e : Direction} → ZigZag i j b e → i ≋ j impl (zig first rest) = inj first >trans> impl rest impl (zag first rest) = >sym (inj first) >trans> impl rest impl (slish last) = inj last impl (slash last) = >sym (inj last) minimal : ∀ {c′ ℓ′} (Dest : Setoid c′ ℓ′) (f : Preorder.Carrier Base → Setoid.Carrier Dest) → (Preorder._∼_ Base =[ f ]⇒ Setoid._≈_ Dest) → (Alternating =[ f ]⇒ Setoid._≈_ Dest) minimal Dest f inj = locally-minimal (on-preserves-equivalence f (Setoid.isEquivalence Dest)) inj
43.848485
113
0.648929
9a9c934212d8506ec51a8035dd9a4322496d5bb8
201
agda
Agda
Cubical/HITs/SmashProduct.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/HITs/SmashProduct.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/HITs/SmashProduct.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.SmashProduct where open import Cubical.HITs.SmashProduct.Base public -- open import Cubical.HITs.SmashProduct.Properties public
28.714286
58
0.781095
ccb97f26d9d336da3ab4e6f754f2d68813c79d02
313
agda
Agda
src/Generic/Lib/Data/Nat.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
30
2016-07-19T21:10:54.000Z
2022-02-05T10:19:38.000Z
src/Generic/Lib/Data/Nat.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
9
2017-04-06T18:58:09.000Z
2022-01-04T15:43:14.000Z
src/Generic/Lib/Data/Nat.agda
iblech/Generic
380554b20e0991290d1864ddf81f0587ec1647ed
[ "MIT" ]
4
2017-07-17T07:23:39.000Z
2021-01-27T12:57:09.000Z
module Generic.Lib.Data.Nat where open import Data.Nat.Base hiding (_⊔_; _^_) public open import Generic.Lib.Decidable instance ℕEq : Eq ℕ ℕEq = viaBase Nat._≟_ where import Data.Nat as Nat foldℕ : ∀ {α} {A : Set α} -> (A -> A) -> A -> ℕ -> A foldℕ f x 0 = x foldℕ f x (suc n) = f (foldℕ f x n)
20.866667
52
0.610224
73d54c80009cf9a3bfc8ba809ca1473612b93874
619
agda
Agda
old/Homotopy/PullbackIsPullback.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
old/Homotopy/PullbackIsPullback.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
old/Homotopy/PullbackIsPullback.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K #-} open import Base open import Homotopy.PullbackDef module Homotopy.PullbackIsPullback {i} (d : pullback-diag i) where open pullback-diag d import Homotopy.PullbackUP as PullbackUP open PullbackUP d (λ _ → unit) pullback-cone : cone (pullback d) pullback-cone = (pullback.a d , pullback.b d , pullback.h d) factor-pullback : (E : Set i) → (cone E → (E → pullback d)) factor-pullback E (top→A , top→B , h) x = (top→A x , top→B x , h x) pullback-is-pullback : is-pullback (pullback d) pullback-cone pullback-is-pullback E = iso-is-eq _ (factor-pullback E) (λ y → refl) (λ f → refl)
25.791667
67
0.686591
302b52143b713e8a731fb0447e838c45d21708d8
990
agda
Agda
test/Compiler/simple/Coind.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
4
2017-02-24T16:53:22.000Z
2019-12-23T04:56:23.000Z
test/Compiler/simple/Coind.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
6
2017-02-24T19:27:31.000Z
2017-02-24T19:38:17.000Z
test/Compiler/simple/Coind.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS --universe-polymorphism #-} module Coind where open import Common.IO open import Common.Level open import Common.Nat open import Common.Unit open import Common.Coinduction renaming (♯_ to sharp; ♭ to flat) {- infix 1000 sharp_ postulate Infinity : ∀ {a} (A : Set a) → Set a sharp_ : ∀ {a} {A : Set a} → A → Infinity A flat : ∀ {a} {A : Set a} → Infinity A → A {-# BUILTIN INFINITY Infinity #-} {-# BUILTIN SHARP sharp_ #-} {-# BUILTIN FLAT flat #-} -} data Stream (A : Set) : Set where _::_ : (x : A) (xs : ∞ (Stream A)) → Stream A ones : Stream Nat ones = 1 :: (sharp ones) twos : Stream Nat twos = 2 :: (sharp twos) incr : Nat -> Stream Nat incr n = n :: (sharp (incr (n + 1))) printStream : Nat -> Stream Nat -> IO Unit printStream zero _ = putStrLn "" printStream (suc steps) (n :: ns) = printNat n ,, printStream steps (flat ns) main : IO Unit main = printStream 10 twos ,, printStream 10 ones ,, printStream 10 (incr zero)
21.521739
64
0.620202
2e9bb0b89120a95609ce5cacc69f08263c93b676
10,731
agda
Agda
nicolai/pseudotruncations/LoopsAndSpheres.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
nicolai/pseudotruncations/LoopsAndSpheres.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
nicolai/pseudotruncations/LoopsAndSpheres.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.NType2 open import lib.PathGroupoid open import lib.types.Bool open import lib.types.IteratedSuspension open import lib.types.Lift open import lib.types.LoopSpace open import lib.types.Nat open import lib.types.Paths open import lib.types.Pi open import lib.types.Pointed open import lib.types.Sigma open import lib.types.Suspension open import lib.types.TLevel open import lib.types.Unit open SuspensionRec public using () renaming (f to Susp-rec) open import nicolai.pseudotruncations.Preliminary-definitions open import nicolai.pseudotruncations.Liblemmas open import nicolai.pseudotruncations.pointed-O-Sphere module nicolai.pseudotruncations.LoopsAndSpheres where {- We greatly benefit from Evan Cavallo's code - thank you! -} open import homotopy.PtdAdjoint open import homotopy.SuspAdjointLoop isNull : ∀ {i j} {A : Type i} {B : Type j} (b : B) (f : A → B) → Type _ isNull {A = A} b f = (a : A) → f a == b module null {i} {j} { : Ptd i} {B̂ : Ptd j} (ĝ :  →̇ B̂) where A = fst  a₀ = snd  B = fst B̂ b₀ = snd B̂ g = fst ĝ p = snd ĝ -- derived isNull isNulld = (a : fst Â) → g a == b₀ -- pointed isNull; we state it in the equivalence form (slightly easier to handle) isNull∙' = Σ ((a : A) → g a == b₀) λ pr → pr a₀ == p -- the 'real' pointed isNull isNull∙ = ĝ == ((λ _ → b₀) , idp) {- The two versions are equivalent -} isNull-equiv : isNull∙ ≃ isNull∙' isNull-equiv = ĝ == ((λ _ → b₀) , idp) ≃⟨ (=Σ-eqv _ _) ⁻¹ ⟩ =Σ ĝ ((λ _ → b₀) , idp) ≃⟨ equiv-Σ' {A₀ = g == λ _ → b₀} app=-equiv (λ h → (p == idp [ (λ f → f a₀ == b₀) ↓ h ]) ≃⟨ to-transp-equiv _ _ ⟩ (transport (λ f → f a₀ == b₀) h p) == idp ≃⟨ coe-equiv (ap (λ x → x == idp) (trans-ap₁ (λ f → f a₀) b₀ h p)) ⟩ (! (app= h a₀) ∙ p) == idp ≃⟨ adhoc-=-eqv (app= h a₀) p ⟩ (app= h a₀ == p) ≃∎) ⟩ (Σ ((a : A) → g a == b₀) λ pr → pr a₀ == p) ≃∎ -- Lemma 4.4: pointed and non-pointed 'nullness' are logically equivalent; -- First, one direction: null-lequiv : isNulld → isNull∙' null-lequiv isnull = (λ a → isnull a ∙ ! (isnull a₀) ∙ p) , ( isnull a₀ ∙ ! (isnull a₀) ∙ p =⟨ ! (∙-assoc (isnull a₀) _ _) ⟩ (isnull a₀ ∙ ! (isnull a₀)) ∙ p =⟨ ap (λ t → t ∙ p) (!-inv-r (isnull a₀)) ⟩ p ∎) -- The other direction is very easy; we do it using the non-prime variant: null-lequiv-easy : isNull∙ → isNulld null-lequiv-easy isn = app= (ap fst isn) -- uncomment this if you want to wait forever for typechecking... -- Σ⊣Ω-unitCounit : CounitUnitAdjoint Σ⊣Ω.SuspFunctor Σ⊣Ω.LoopFunctor Σ⊣Ω-unitCounit = Σ⊣Ω.adj Σ⊣Ω-homset : ∀ {i} → HomAdjoint {i} {i} Σ⊣Ω.SuspFunctor Σ⊣Ω.LoopFunctor Σ⊣Ω-homset = counit-unit-to-hom Σ⊣Ω-unitCounit module hom-adjoint {i} ( : Ptd i) (B̂ : Ptd i) where A = fst  B = fst B̂ a₀ = snd  b₀ = snd B̂ Φeq : (⊙Susp  →̇ B̂) ≃ ( →̇ ⊙Ω B̂) Φeq = HomAdjoint.eq Σ⊣Ω-homset  B̂ {- This is Lemma 4.1 -} Φ : (⊙Susp  →̇ B̂) → ( →̇ ⊙Ω B̂) Φ = –> Φeq Φ⁻¹ : ( →̇ ⊙Ω B̂) → (⊙Susp  →̇ B̂) Φ⁻¹ = <– Φeq open PtdFunctor open Σ⊣Ω open CounitUnitAdjoint {- Some lemmas which are easy on paper and thus not explicitly mentioned in the paper. It still takes some effort to formalize them. -} module simplify where simpl-⊙ap : (⊙ap {X = obj SuspFunctor Â} ((λ _ → b₀) , idp)) == ((λ _ → idp) , idp) simpl-⊙ap = →̇-maps-to ⊙ap ((λ _ → b₀) , idp) ((λ _ → idp) , idp) (λ= (λ _ → ap-cst b₀ _)) ((app= (λ= (λ _ → ap-cst b₀ _)) _) ∙ idp =⟨ ∙-unit-r _ ⟩ app= (λ= (λ _ → ap-cst b₀ _)) _ =⟨ app=-β _ _ ⟩ ap-cst b₀ (idp {a = snd B̂}) =⟨ idp ⟩ -- ! idp =⟨ idp ⟩ -- ! snd (⊙ap {X = obj SuspFunctor Â} ((λ _ → b₀) , idp)) ∎ ) simpl-comp : ((λ (_ : Ω (⊙Susp Â)) → idp {a = b₀}) , idp) ⊙∘ (⊙η Â) == (λ _ → idp) , idp simpl-comp = pair= idp ((ap-cst idp (snd (⊙η Â))) ∙ᵣ idp) open simplify {- Lemma 4.2 -} Φ-is-pointed-map : Φ ((λ _ → b₀) , idp) == ((λ _ → idp) , idp) Φ-is-pointed-map = Φ ((λ _ → b₀) , idp) =⟨ idp ⟩ ( arr LoopFunctor ((λ _ → b₀) , idp) ⊙∘ (CounitUnitAdjoint.η adj Â)) =⟨ idp ⟩ ( (⊙ap {X = obj SuspFunctor Â} ((λ _ → b₀) , idp) ⊙∘ (⊙η Â))) =⟨ ap (λ f → f ⊙∘ (⊙η Â)) simpl-⊙ap ⟩ ((λ _ → idp) , idp) ⊙∘ (⊙η Â) =⟨ simpl-comp ⟩ (λ _ → idp) , idp ∎ -- fix i module _ {i} where open hom-adjoint open HomAdjoint open null -- Lemma 4.3 Φ-snd-nat : { B̂ Ĉ : Ptd i} (f : ⊙Susp  →̇ B̂) (g : B̂ →̇ Ĉ) → Φ Â Ĉ (g ⊙∘ f) == ⊙ap g ⊙∘ Φ Â B̂ f Φ-snd-nat {Â} {B̂} {Ĉ} f g = ! (nat-cod Σ⊣Ω-homset  {B̂} {Ĉ} g f) -- Lemma 4.4 is above (before 4.2). -- Lemma 4.5 isnull-Φ : { B̂ : Ptd i} (g : ⊙Susp  →̇ B̂) → (isNull∙ g) ≃ isNull∙ (Φ Â B̂ g) isnull-Φ {Â} {B̂} g = isNull∙ g ≃⟨ equiv-ap (Φeq  B̂) _ _ ⟩ (Φ Â B̂ g) == Φ Â B̂ ((λ _ → snd B̂) , idp) ≃⟨ coe-equiv {A = (Φ Â B̂ g) == Φ Â B̂ ((λ _ → snd B̂) , idp)} {B = (Φ Â B̂ g) == (λ _ → idp) , idp} (ap (λ q → (Φ Â B̂ g == q)) (Φ-is-pointed-map _ _ )) ⟩ (Φ Â B̂ g) == (λ _ → idp) , idp ≃∎ -- combination of 4.3 and 4.5 combine-isnull-nat : { B̂ Ĉ : Ptd i} (f : ⊙Susp  →̇ B̂) (g : B̂ →̇ Ĉ) → (isNull∙ (g ⊙∘ f)) ≃ (isNull∙ (⊙ap g ⊙∘ Φ Â B̂ f)) -- combine-isnull-nat {Â} {B̂} {Ĉ} f g = isNull∙ (g ⊙∘ f) ≃⟨ isnull-Φ _ ⟩ isNull∙ (Φ Â Ĉ (g ⊙∘ f)) ≃⟨ coe-equiv (ap (λ q → isNull∙ q) (Φ-snd-nat f g)) ⟩ isNull∙ (⊙ap g ⊙∘ Φ Â B̂ f) ≃∎ combine-isnull-nat' : { B̂ Ĉ : Ptd i} (f :  →̇ ⊙Ω B̂) (g : B̂ →̇ Ĉ) → (isNull∙ (g ⊙∘ (Φ⁻¹  B̂ f))) ≃ (isNull∙ (⊙ap g ⊙∘ f)) combine-isnull-nat' {Â} {B̂} {Ĉ} f g = isNull∙ (g ⊙∘ (Φ⁻¹  B̂ f)) ≃⟨ combine-isnull-nat (Φ⁻¹  B̂ f) g ⟩ isNull∙ (⊙ap g ⊙∘ (Φ Â B̂ (Φ⁻¹  B̂ f))) ≃⟨ coe-equiv (ap (λ h → isNull∙ (⊙ap g ⊙∘ h)) (<–-inv-r (Φeq  B̂) f)) ⟩ isNull∙ (⊙ap g ⊙∘ f) ≃∎ module _ {i} where open hom-adjoint -- This was tricky (todo: could explain why) Φ-iter : ( B̂ : Ptd i) (n : Nat) → ((⊙Susp-iter' n Â) →̇ B̂) → ( →̇ (⊙Ω^ n B̂)) Φ-iter  B̂ O f = f Φ-iter  B̂ (S n) f = Φ Â (⊙Ω^ n B̂) (Φ-iter (⊙Susp Â) B̂ n f) Φ-iter-equiv : ( B̂ : Ptd i) (n : Nat) → is-equiv (Φ-iter  B̂ n) Φ-iter-equiv  B̂ O = snd (ide _) Φ-iter-equiv  B̂ (S n) = snd ((Φeq  (⊙Ω^ n B̂)) ∘e ((Φ-iter (⊙Susp Â) B̂ n) , Φ-iter-equiv (⊙Susp Â) B̂ n) ) module _ {i} where open null open hom-adjoint -- Lemma 4.7 -- generalized, because we need to do it for Susp first before it works for Sphere! isNull-Φ-many : (m : Nat) → ( B̂ Ĉ : Ptd i) → (f : ⊙Susp-iter' m  →̇ B̂) (g : B̂ →̇ Ĉ) → isNull∙ (g ⊙∘ f) ≃ isNull∙ ((ap^ m g) ⊙∘ Φ-iter  B̂ m f) isNull-Φ-many O  B̂ Ĉ f g = ide _ isNull-Φ-many (S m)  B̂ Ĉ f g = isNull∙ (g ⊙∘ f) ≃⟨ isNull-Φ-many m (⊙Susp Â) B̂ Ĉ f g ⟩ isNull∙ ((ap^ m g) ⊙∘ Φ-iter (⊙Susp Â) B̂ m f) ≃⟨ combine-isnull-nat (Φ-iter (⊙Susp Â) B̂ m f) (ap^ m g) ⟩ (isNull∙ (⊙ap (ap^ m g) ⊙∘ Φ Â (⊙Ω^ m B̂) (Φ-iter (⊙Susp Â) B̂ m f))) ≃∎ -- Lemma 4.7 (special with k = 0) module _ {B̂ Ĉ : Ptd i} (m : Nat) (f : ⊙Sphere' {i} m →̇ B̂) (g : B̂ →̇ Ĉ) where isNull-Φ-Sphere : isNull∙ (g ⊙∘ f) ≃ isNull∙ ((ap^ m g) ⊙∘ Φ-iter (⊙Sphere' {i} O) B̂ m f) isNull-Φ-Sphere = isNull-Φ-many m _ _ _ f g open bool-neutral module _ {B̂ Ĉ : Ptd i} (m : Nat) (g : B̂ →̇ Ĉ) where c₀ = snd (⊙Ω^ m Ĉ) {- Lemma 4.8 -} null-on-pspaces : ((f : (⊙Sphere' {i} m) →̇ B̂) → isNull∙ (g ⊙∘ f)) ≃ isNulld (ap^ m g) null-on-pspaces = -- {!equiv-Π-l!} ((f : (⊙Sphere' {i} m) →̇ B̂) → isNull∙ (g ⊙∘ f)) ≃⟨ equiv-Π-r (λ f → isNull-Φ-Sphere m f g) ⟩ ((f : (⊙Sphere' {i} m) →̇ B̂) → isNull∙ ((ap^ m g) ⊙∘ Φ-iter (⊙Sphere' {i} O) B̂ m f)) ≃⟨ equiv-Π-l {A = (⊙Sphere' {i} m) →̇ B̂} {B = (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)} (λ f' → isNull∙ ((ap^ m g) ⊙∘ f')) {h = Φ-iter (⊙Sphere' {i} O) B̂ m} (Φ-iter-equiv _ _ m) ⟩ ((f' : (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)) → isNull∙ ((ap^ m g) ⊙∘ f')) ≃⟨ equiv-Π-r {A = ⊙Sphere' {i} O →̇ (⊙Ω^ m B̂)} (λ _ → isNull-equiv _) ⟩ ((f' : (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)) → isNull∙' ((ap^ m g) ⊙∘ f')) ≃⟨ ide _ ⟩ ((f' : (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)) → Σ ((x : bool) → fst ((ap^ m g) ⊙∘ f') x == _) λ h → h tt₀ == _) ≃⟨ equiv-Π-r {A = ⊙Sphere' {i} O →̇ (⊙Ω^ m B̂)} (λ fp → reduction (λ b → fst (ap^ m g ⊙∘ fp) b == null.b₀ (ap^ m g ⊙∘ fp)) _) ⟩ ((f' : (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)) → fst ((ap^ m g) ⊙∘ f') ff₀ == _) ≃⟨ ide _ ⟩ ((f' : (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)) → fst (ap^ m g) (fst f' ff₀) == _) ≃⟨ equiv-Π-l {A = (⊙Sphere' {i} O) →̇ (⊙Ω^ m B̂)} {B = fst (⊙Ω^ m B̂)} _ (snd (reduction (λ _ → fst (⊙Ω^ m B̂)) _)) ⟩ ((x : fst (⊙Ω^ m B̂)) → fst (ap^ m g) x == c₀) ≃⟨ ide _ ⟩ isNulld (ap^ m g) ≃∎
31.285714
110
0.406952
21bf38678c83efeff1e9340db8e84f4239ab967b
44
agda
Agda
test/interaction/Issue2592/C.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2592/C.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2592/C.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- also importing warnings from A import A
11
33
0.75
7c5dbe7ecc603c9d74a30aa96135e0440177f4d6
1,453
agda
Agda
test/Fail/Issue5706.agda
thiagofelicissimo/agda
a0b3eea0c19c47ffbe2be525316311f5795d760d
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue5706.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue5706.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2021-12-22, issue #5706 reported by Trebor-Huang -- In Agda <= 2.6.2.1, Int overflow can be exploited. -- Basically just a modified version of Russell's paradox found at -- http://liamoc.net/posts/2015-09-10-girards-paradox.html. -- -- This 64bit Int overflow got us Set:Set. -- WTF : Set₀ -- WTF = Set₁₈₄₄₆₇₄₄₀₇₃₇₀₉₅₅₁₆₁₅ -- -- 18446744073709551615 = 2^64 - 1 -- Some preliminaries, just to avoid any library imports: data _≡_ {ℓ : _} {A : Set ℓ} : A → A → Set where refl : ∀ {a} → a ≡ a record ∃ {A : Set} (P : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : P proj₁ open ∃ data ⊥ : Set where -- The rest follows the linked development of Russell's paradox. -- Naive sets (tree representation), accepted with --type-in-type. data SET : Set where set : (X : Set₁₈₄₄₆₇₄₄₀₇₃₇₀₉₅₅₁₆₁₅) → (X → SET) → SET -- Elementhood _∈_ : SET → SET → Set a ∈ set X f = ∃ λ x → a ≡ f x _∉_ : SET → SET → Set a ∉ b = (a ∈ b) → ⊥ -- The set Δ of sets that do not contain themselves. Δ : SET Δ = set (∃ λ s → s ∉ s) proj₁ -- Any member of Δ does not contain itself. x∈Δ→x∉x : ∀ {X} → X ∈ Δ → X ∉ X x∈Δ→x∉x ((Y , Y∉Y) , refl) = Y∉Y -- Δ does not contain itself. Δ∉Δ : Δ ∉ Δ Δ∉Δ Δ∈Δ = x∈Δ→x∉x Δ∈Δ Δ∈Δ -- Any set that does not contain itself lives in Δ. x∉x→x∈Δ : ∀ {X} → X ∉ X → X ∈ Δ x∉x→x∈Δ {X} X∉X = (X , X∉X) , refl -- So Δ must live in Δ, which is absurd. falso : ⊥ falso = Δ∉Δ (x∉x→x∈Δ Δ∉Δ)
22.353846
66
0.594632
0d783bfaa635673e2c6bcaaba1b4d217caae6c77
1,303
agda
Agda
agda-stdlib/src/Algebra/Operations/Ring.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Algebra/Operations/Ring.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Algebra/Operations/Ring.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Some defined operations over Rings ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} -- This module gives the definition of _^_ which is used throughout -- the library. It's a little different from the normal definition: -- -- x ^ zero = 1# -- x ^ suc i = x * x ^ i -- -- This is for two reasons. First, we want to avoid unnecessarily -- multiplying by 1# if possible: -- -- Standard definition: x ^ 2 = x * x * 1# -- Our definition: x ^ 2 = x * x -- -- This speeds up typechecking and makes for much more readable -- proofs. -- -- Secondly, we want to associate to the left: -- -- Standard definition: x ^ 3 = x * (x * (x * 1#)) -- Our definition: x ^ 2 = (x * x) * x -- -- As counterintuitive as it may seem, this also speeds up -- typechecking. open import Algebra module Algebra.Operations.Ring {ℓ₁ ℓ₂} (ring : RawRing ℓ₁ ℓ₂) where open import Data.Nat.Base as ℕ using (ℕ; suc; zero) open RawRing ring infixr 8 _^_+1 _^_+1 : Carrier → ℕ → Carrier x ^ zero +1 = x x ^ suc n +1 = (x ^ n +1) * x infixr 8 _^_ _^_ : Carrier → ℕ → Carrier x ^ zero = 1# x ^ suc i = x ^ i +1 {-# INLINE _^_ #-}
25.057692
72
0.542594
30815210922d4a2b1b421dc5aa6e29a390116cea
736
agda
Agda
agda-stdlib-0.9/src/Data/Char/Core.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Data/Char/Core.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/Char/Core.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Core definitions for Characters ------------------------------------------------------------------------ module Data.Char.Core where open import Data.Nat using (ℕ) open import Data.Bool using (Bool; true; false) ------------------------------------------------------------------------ -- The type postulate Char : Set {-# BUILTIN CHAR Char #-} {-# COMPILED_TYPE Char Char #-} ------------------------------------------------------------------------ -- Primitive operations primitive primCharToNat : Char → ℕ primCharEquality : Char → Char → Bool -- primShowChar is in Data.String.Core for break an import cycle.
26.285714
72
0.429348
65e3585c36767889a9acbb33114c166212fc67bd
12,551
agda
Agda
Cubical/HITs/CumulativeHierarchy/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/HITs/CumulativeHierarchy/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/HITs/CumulativeHierarchy/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} {- Builds bismulation for the cumulative hierarchy and shows that it is equivalent to equality though it lives in a lower universe. -} module Cubical.HITs.CumulativeHierarchy.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Univalence open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Function open import Cubical.Foundations.Transport open import Cubical.Foundations.HLevels open import Cubical.Foundations.Structure open import Cubical.Functions.Embedding open import Cubical.Functions.Logic as L open import Cubical.Data.Sigma open import Cubical.HITs.PropositionalTruncation as P hiding (elim; elim2) open import Cubical.HITs.SetQuotients as Q using (_/_; setQuotUniversal; eq/; squash/) open import Cubical.HITs.CumulativeHierarchy.Base renaming (elim to elimInternal) import Cubical.HITs.PropositionalTruncation.Monad as PropMonad private variable ℓ ℓ' : Level X Y : Type ℓ a b : V ℓ infix 4 _≊_ infix 7 _∈ₛ_ _⊆_ _⊆ₛ_ ------------ -- "bisimulation" ----------- -- bisimulation is needed to define a quotient in the correct universe when -- implementing the map : V ℓ → Σ[ X : Type ℓ ] (X → V ℓ) -- Quotienting by Path (V ℓ) or via eqImage would lead to X : Type (ℓ-suc ℓ) _∼_ : (s t : V ℓ) → hProp ℓ _∼_ = elim2 eliminator where goalProp : (X : Type ℓ) (ix : X → V ℓ) → (Y : Type ℓ) (iy : Y → V ℓ) → (rec : X → Y → hProp ℓ) → hProp ℓ goalProp X ix Y iy rec = (∀[ a ∶ X ] ∃[ b ∶ Y ] rec a b) ⊓ (∀[ b ∶ Y ] ∃[ a ∶ X ] rec a b) ⇔-swap : X ⊓′ Y → Y ⊓′ X ⇔-swap (p , q) = (q , p) open PropMonad lemma : {X₁ X₂ Y : Type ℓ} {ix₁ : X₁ → V ℓ} {ix₂ : X₂ → V ℓ} (iy : Y → V ℓ) → {rec₁ : X₁ → Y → hProp ℓ} {rec₂ : X₂ → Y → hProp ℓ} → (rec₁→₂ : (x₁ : X₁) → ∃[ (x₂ , p) ∈ fiber ix₂ (ix₁ x₁) ] rec₂ x₂ ≡ rec₁ x₁) → (rec₂→₁ : (x₂ : X₂) → ∃[ (x₁ , p) ∈ fiber ix₁ (ix₂ x₂) ] rec₁ x₁ ≡ rec₂ x₂) → ⟨ goalProp X₁ ix₁ Y iy rec₁ ⇒ goalProp X₂ ix₂ Y iy rec₂ ⟩ lemma _ rec₁→₂ rec₂→₁ (X₁→Y , Y→X₁) = (λ x₂ → do ((x₁ , c_) , xr₁) ← rec₂→₁ x₂ (y , yr) ← X₁→Y x₁ ∣ y , subst fst (λ i → xr₁ i y) yr ∣₁ ) , (λ y → do (x₁ , xr₁) ← Y→X₁ y ((x₂ , _) , xr₂) ← rec₁→₂ x₁ ∣ x₂ , subst fst (λ i → xr₂ (~ i) y) xr₁ ∣₁ ) open Elim2Set eliminator : Elim2Set (λ _ _ → isSetHProp) ElimSett2 eliminator = goalProp ElimEqSnd eliminator X ix Y₁ Y₂ iy₁ iy₂ eq rec₁ rec₂ rec₁→₂ rec₂→₁ = ⇔toPath (⇔-swap ∘ lemma ix rec₁→₂ rec₂→₁ ∘ ⇔-swap) (⇔-swap ∘ lemma ix rec₂→₁ rec₁→₂ ∘ ⇔-swap) ElimEqFst eliminator X₁ X₂ ix₁ ix₂ eq Y iy rec₁ rec₂ rec₁→₂ rec₂→₁ = ⇔toPath (lemma iy rec₁→₂ rec₂→₁) (lemma iy rec₂→₁ rec₁→₂) _≊_ : (s t : V ℓ) → Type ℓ s ≊ t = ⟨ s ∼ t ⟩ ∼refl : (a : V ℓ) → a ≊ a ∼refl = elimProp (λ a → isProp⟨⟩ (a ∼ a)) (λ X ix rec → (λ x → ∣ x , rec x ∣₁) , (λ x → ∣ x , rec x ∣₁)) -- keep in mind that the left and right side here live in different universes identityPrinciple : (a ≊ b) ≃ (a ≡ b) identityPrinciple {a = a} {b = b} = isoToEquiv (iso from into (λ _ → setIsSet _ _ _ _) (λ _ → isProp⟨⟩ (a ∼ b) _ _)) where open PropMonad eqImageXY : {X Y : Type ℓ} {ix : X → V ℓ} {iy : Y → V ℓ} → (∀ x y → ⟨ ix x ∼ iy y ⟩ → ix x ≡ iy y) → ⟨ sett X ix ∼ sett Y iy ⟩ → eqImage ix iy eqImageXY rec rel = (λ x → do (y , y∼x) ← fst rel x ; ∣ y , sym (rec _ _ y∼x) ∣₁) , (λ y → do (x , x∼y) ← snd rel y ; ∣ x , rec _ _ x∼y ∣₁) from : a ≊ b → a ≡ b from = elimProp propB eliminator a b where prop∼ : {a : V ℓ} → ∀ b → isProp (a ≊ b → a ≡ b) prop∼ {a = a} b = isPropΠ λ _ → setIsSet a b propB : (a : V ℓ) → isProp (∀ b → a ≊ b → a ≡ b) propB a = isPropΠ prop∼ eliminator : ∀ (X : Type _) (ix : X → V _) → ((x : X) (b₁ : V _) → ix x ≊ b₁ → ix x ≡ b₁) → (b₁ : V _) → sett X ix ≊ b₁ → sett X ix ≡ b₁ eliminator X ix rec = elimProp prop∼ λ Y iy _ → seteq X Y ix iy ∘ eqImageXY (λ x y → rec x (iy y)) into : a ≡ b → a ≊ b into = J (λ b _ → a ≊ b) (∼refl a) ------------ -- Monic presentation of sets ----------- -- like fiber, but in a lower universe repFiber : (f : X → V ℓ) (b : V ℓ) → Type _ repFiber f b = Σ[ a ∈ _ ] f a ≊ b repFiber≃fiber : (f : X → V ℓ) (b : V ℓ) → repFiber f b ≃ fiber f b repFiber≃fiber f b = Σ-cong-equiv (idEquiv _) (λ _ → identityPrinciple) -- projecting out a representing type together with the embedding MonicPresentation : (a : V ℓ) → Type (ℓ-suc ℓ) MonicPresentation {ℓ} a = Σ[ (X , ix , _) ∈ Embedding (V ℓ) ℓ ] (a ≡ sett X ix) isPropMonicPresentation : (a : V ℓ) → isProp (MonicPresentation a) isPropMonicPresentation a ((X₁ , ix₁ , isEmb₁) , p) ((X₂ , ix₂ , isEmb₂) , q) = ΣPathP ( equivFun (EmbeddingIP _ _) (fiberwise1 , fiberwise2) , isProp→PathP (λ i → setIsSet a _) p q) where open PropMonad fiberwise1 : ∀ b → fiber ix₁ b → fiber ix₂ b fiberwise1 b fbx₁ = proof (_ , isEmbedding→hasPropFibers isEmb₂ b) by subst (λ A → ⟨ b ∈ A ⟩) (sym p ∙ q) ∣ fbx₁ ∣₁ fiberwise2 : ∀ b → fiber ix₂ b → fiber ix₁ b fiberwise2 b fbx₂ = proof (_ , isEmbedding→hasPropFibers isEmb₁ b) by subst (λ A → ⟨ b ∈ A ⟩) (sym q ∙ p) ∣ fbx₂ ∣₁ sett-repr : (X : Type ℓ) (ix : X → V ℓ) → MonicPresentation (sett X ix) sett-repr {ℓ} X ix = (Rep , ixRep , isEmbIxRep) , seteq X Rep ix ixRep eqImIxRep where Kernel : X → X → Type ℓ Kernel x y = ix x ≊ ix y Rep : Type ℓ Rep = X / Kernel ixRep : Rep → V ℓ ixRep = invEq (setQuotUniversal setIsSet) (ix , λ _ _ → equivFun identityPrinciple) isEmbIxRep : isEmbedding ixRep isEmbIxRep = hasPropFibers→isEmbedding propFibers where propFibers : ∀ y → (a b : Σ[ p ∈ Rep ] (ixRep p ≡ y)) → a ≡ b propFibers y (p₁ , m) (p₂ , n) = ΣPathP {B = λ _ p → ixRep p ≡ y} (goal , isProp→PathP (λ _ → setIsSet _ _) _ _) where lemma : ∀ {p₁ p₂} → (p : ixRep Q.[ p₁ ] ≡ y) (q : ixRep Q.[ p₂ ] ≡ y) → Kernel p₁ p₂ lemma m n = invEquiv identityPrinciple .fst (m ∙ sym n) prop₁ : ∀ p₁ → isProp ((ixRep p₁ ≡ y) → p₁ ≡ p₂) prop₁ p₁ = isPropΠ λ eq → squash/ p₁ p₂ prop₂ : ∀ {p₁} p₂ → isProp ((ixRep p₂ ≡ y) → Q.[ p₁ ] ≡ p₂) prop₂ {p₁} p₂ = isPropΠ λ eq → squash/ Q.[ p₁ ] p₂ goal : p₁ ≡ p₂ goal = Q.elimProp prop₁ (λ p₁ m → Q.elimProp prop₂ (λ p₂ n → eq/ p₁ p₂ (lemma m n)) p₂ n) p₁ m eqImIxRep : eqImage ix ixRep eqImIxRep = (λ x → ∣ Q.[ x ] , refl ∣₁) , Q.elimProp (λ _ → P.squash₁) (λ b → ∣ b , refl ∣₁) data DeepMonicPresentation (a : V ℓ) : Type (ℓ-suc ℓ) where dmp : (mp@((_ , ix , _) , _) : MonicPresentation a) → (rec : ∀ x → DeepMonicPresentation (ix x)) → DeepMonicPresentation a isPropDeepMonicPresentation : (a : V ℓ) → isProp (DeepMonicPresentation a) isPropDeepMonicPresentation a (dmp mx rx) (dmp my ry) i = dmp (mx≡my i) (recprop i) where mx≡my : mx ≡ my mx≡my = isPropMonicPresentation a mx my recprop : PathP (λ i → (x : mx≡my i .fst .fst) → DeepMonicPresentation (mx≡my i .fst .snd .fst x)) rx ry recprop = toPathP (funExt λ x → isPropDeepMonicPresentation _ _ _) V-deeprepr : (a : V ℓ) → DeepMonicPresentation a V-deeprepr = elimProp isPropDeepMonicPresentation λ X ix rec → dmp (sett-repr X ix) (Q.elimProp (λ _ → isPropDeepMonicPresentation _) rec) V-repr : (a : V ℓ) → MonicPresentation a -- "Cannot eliminate fibrant type DeepMonicPresentation a -- unless target type is also fibrant" -- V-repr = let (dmp mp _) = (V-deeprepr a) in mp V-repr a = case (V-deeprepr a) return (λ _ → MonicPresentation a) of λ { (dmp mp _) → mp } private MonicDataF : Type (ℓ-suc ℓ) → Type (ℓ-suc ℓ) MonicDataF {ℓ} T = Embedding T ℓ V-fixpoint : V ℓ ≃ MonicDataF (V ℓ) V-fixpoint {ℓ} = V ℓ ≃⟨ invEquiv (Σ-contractSnd λ a → inhProp→isContr (V-repr a) (isPropMonicPresentation a)) ⟩ (Σ[ a ∈ V ℓ ] MonicPresentation a) ≃⟨ boringswap ⟩ (Σ[ (X , ix , _) ∈ MonicDataF (V ℓ) ] singl (sett X ix)) ≃⟨ Σ-contractSnd (λ _ → isContrSingl _) ⟩ MonicDataF (V ℓ) ■ where boringswap : (Σ[ a ∈ V ℓ ] MonicPresentation a) ≃ (Σ[ (X , ix , _) ∈ MonicDataF (V ℓ) ] singl (sett X ix)) boringswap = isoToEquiv (iso (λ (a , (X , ix , emb) , p) → (X , ix , emb) , a , sym p) (λ ((X , ix , emb) , a , p) → a , (X , ix , emb) , sym p) (λ _ → refl) λ _ → refl) -- note the problem of making this a datatype directly: MonicDataF is *not* strictly positive! -- an elimination principle based on the monic presentation elim : (B : V ℓ → Type ℓ') → ((X : Type ℓ) (ix : X → V ℓ) (emb : isEmbedding ix) (rec : ∀ x → B (ix x)) → B (sett X ix)) → (a : V ℓ) → B a elim B alg = elimDMP ∘ V-deeprepr where elimDMP : ∀ {a} → DeepMonicPresentation a → B a elimDMP (dmp ((X , ix , emb) , p) rec) = subst B (sym p) (alg X ix emb (λ x → elimDMP (rec x))) ⟪_⟫ : (s : V ℓ) → Type ℓ ⟪ X ⟫ = V-repr X .fst .fst ⟪_⟫↪ : (s : V ℓ) → ⟪ s ⟫ → V ℓ ⟪ X ⟫↪ = V-repr X .fst .snd .fst isEmb⟪_⟫↪ : (s : V ℓ) → isEmbedding ⟪ s ⟫↪ isEmb⟪ X ⟫↪ = V-repr X .fst .snd .snd ⟪_⟫-represents : (s : V ℓ) → s ≡ sett ⟪ s ⟫ ⟪ s ⟫↪ ⟪ X ⟫-represents = V-repr X .snd isPropRepFiber : (a b : V ℓ) → isProp (repFiber ⟪ a ⟫↪ b) isPropRepFiber a b = Embedding-into-isProp→isProp (Equiv→Embedding (repFiber≃fiber ⟪ a ⟫↪ b)) (isEmbedding→hasPropFibers isEmb⟪ a ⟫↪ b) -- while ∈ is hProp (ℓ-suc ℓ), ∈ₛ is in ℓ _∈ₛ_ : (a b : V ℓ) → hProp ℓ a ∈ₛ b = repFiber ⟪ b ⟫↪ a , isPropRepFiber b a ∈-asFiber : {a b : V ℓ} → ⟨ a ∈ b ⟩ → fiber ⟪ b ⟫↪ a ∈-asFiber {a = a} {b = b} = subst (λ br → ⟨ a ∈ br ⟩ → fiber ⟪ b ⟫↪ a) (sym ⟪ b ⟫-represents) asRep where asRep : ⟨ a ∈ sett ⟪ b ⟫ ⟪ b ⟫↪ ⟩ → fiber ⟪ b ⟫↪ a asRep = P.propTruncIdempotent≃ (isEmbedding→hasPropFibers isEmb⟪ b ⟫↪ a) .fst ∈-fromFiber : {a b : V ℓ} → fiber ⟪ b ⟫↪ a → ⟨ a ∈ b ⟩ ∈-fromFiber {a = a} {b = b} = subst (λ br → ⟨ a ∈ br ⟩) (sym ⟪ b ⟫-represents) ∘ ∣_∣₁ ∈∈ₛ : {a b : V ℓ} → ⟨ a ∈ b ⇔ a ∈ₛ b ⟩ ∈∈ₛ {a = a} {b = b} = leftToRight , rightToLeft where repEquiv : repFiber ⟪ b ⟫↪ a ≃ fiber ⟪ b ⟫↪ a repEquiv = repFiber≃fiber ⟪ b ⟫↪ a leftToRight : ⟨ (a ∈ b) ⇒ a ∈ₛ b ⟩ leftToRight a∈b = invEq repEquiv (∈-asFiber {b = b} a∈b) rightToLeft : ⟨ a ∈ₛ b ⇒ (a ∈ b) ⟩ rightToLeft a∈ₛb = ∈-fromFiber {b = b} (equivFun repEquiv a∈ₛb) ix∈ₛ : {X : Type ℓ} {ix : X → V ℓ} → (x : X) → ⟨ ix x ∈ₛ sett X ix ⟩ ix∈ₛ {X = X} {ix = ix} x = ∈∈ₛ {a = ix x} {b = sett X ix} .fst ∣ x , refl ∣₁ ∈ₛ⟪_⟫↪_ : (a : V ℓ) (ix : ⟪ a ⟫) → ⟨ ⟪ a ⟫↪ ix ∈ₛ a ⟩ ∈ₛ⟪ a ⟫↪ ix = ix , ∼refl (⟪ a ⟫↪ ix) -- also here, the left side is in level (ℓ-suc ℓ) while the right is in ℓ presentation : (a : V ℓ) → (Σ[ v ∈ V ℓ ] ⟨ v ∈ₛ a ⟩) ≃ ⟪ a ⟫ presentation a = isoToEquiv (iso into from (λ _ → refl) retr) where into : Σ[ v ∈ V _ ] ⟨ v ∈ₛ a ⟩ → ⟪ a ⟫ into = fst ∘ snd from : ⟪ a ⟫ → Σ[ v ∈ V _ ] ⟨ v ∈ₛ a ⟩ from ⟪a⟫ = ⟪ a ⟫↪ ⟪a⟫ , ∈ₛ⟪ a ⟫↪ ⟪a⟫ retr : retract into from retr s = Σ≡Prop (λ v → (v ∈ₛ a) .snd) (equivFun identityPrinciple (s .snd .snd)) -- subset relation, once in level (ℓ-suc ℓ) and once in ℓ _⊆_ : (a b : V ℓ) → hProp (ℓ-suc ℓ) a ⊆ b = ∀[ x ] x ∈ₛ a ⇒ x ∈ₛ b ⊆-refl : (a : V ℓ) → ⟨ a ⊆ a ⟩ ⊆-refl a = λ _ xa → xa _⊆ₛ_ : (a b : V ℓ) → hProp ℓ a ⊆ₛ b = ∀[ x ] ⟪ a ⟫↪ x ∈ₛ b ⊆⇔⊆ₛ : (a b : V ℓ) → ⟨ a ⊆ b ⇔ a ⊆ₛ b ⟩ ⊆⇔⊆ₛ a b = (λ s → invEq curryEquiv s ∘ invEq (presentation a)) , (λ s x xa → subst (λ x → ⟨ x ∈ₛ b ⟩) (equivFun identityPrinciple (xa .snd)) (s (xa .fst))) -- the homotopy definition of equality as an hProp, we know this is equivalent to bisimulation infix 4 _≡ₕ_ _≡ₕ_ : (a b : V ℓ) → hProp (ℓ-suc ℓ) _≡ₕ_ a b = (a ≡ b) , setIsSet a b -- extensionality extensionality : ⟨ ∀[ a ∶ V ℓ ] ∀[ b ] (a ⊆ b) ⊓ (b ⊆ a) ⇒ (a ≡ₕ b) ⟩ extensionality {ℓ = ℓ} a b imeq = ⟪ a ⟫-represents ∙∙ settab ∙∙ sym ⟪ b ⟫-represents where abpth : Path (Embedding _ _) (⟪ a ⟫ , ⟪ a ⟫↪ , isEmb⟪ a ⟫↪) (⟪ b ⟫ , ⟪ b ⟫↪ , isEmb⟪ b ⟫↪) abpth = equivFun (EmbeddingIP _ _) ( (λ p → equivFun (repFiber≃fiber ⟪ b ⟫↪ p) ∘ imeq .fst p ∘ invEq (repFiber≃fiber ⟪ a ⟫↪ p)) , (λ p → equivFun (repFiber≃fiber ⟪ a ⟫↪ p) ∘ imeq .snd p ∘ invEq (repFiber≃fiber ⟪ b ⟫↪ p)) ) settab : sett ⟪ a ⟫ ⟪ a ⟫↪ ≡ sett ⟪ b ⟫ ⟪ b ⟫↪ settab i = sett (abpth i .fst) (abpth i .snd .fst) extInverse : ⟨ ∀[ a ∶ V ℓ ] ∀[ b ] (a ≡ₕ b) ⇒ (a ⊆ b) ⊓ (b ⊆ a) ⟩ extInverse a b a≡b = subst (λ b → ⟨ (a ⊆ b) ⊓ (b ⊆ a) ⟩) a≡b (⊆-refl a , ⊆-refl a) set≡-characterization : {a b : V ℓ} → (a ≡ₕ b) ≡ (a ⊆ b) ⊓ (b ⊆ a) set≡-characterization = ⇔toPath (extInverse _ _) (extensionality _ _)
39.971338
138
0.560832
527a8dba4a5959d36dd305257d63926252050d77
237
agda
Agda
test/Fail/Issue142.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue142.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue142.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Builtin.Nat data Sing : Nat → Set where i : (k : Nat) → Sing k toSing : (n : Nat) → Sing n toSing n = i n fun : (n : Nat) → Nat fun n with toSing n fun .n | i n with toSing n fun .(n + n) | i .n | i n = {!!}
16.928571
32
0.540084
2ecbfe82fc6d1a52646995066d65f7af709df2c8
1,726
agda
Agda
src/Injection.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
3
2020-05-21T22:58:50.000Z
2021-09-02T17:18:15.000Z
src/Injection.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
src/Injection.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Injections ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Equality module Injection {reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where open Derived-definitions-and-properties eq open import Prelude as P hiding (id) renaming (_∘_ to _⊚_) ------------------------------------------------------------------------ -- Injections -- The property of being injective. Injective : ∀ {a b} {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b) Injective f = ∀ {x y} → f x ≡ f y → x ≡ y infix 0 _↣_ -- Injections. record _↣_ {f t} (From : Type f) (To : Type t) : Type (f ⊔ t) where field to : From → To injective : Injective to ------------------------------------------------------------------------ -- Preorder -- _↣_ is a preorder. id : ∀ {a} {A : Type a} → A ↣ A id = record { to = P.id ; injective = P.id } infixr 9 _∘_ _∘_ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} → B ↣ C → A ↣ B → A ↣ C f ∘ g = record { to = to′ ; injective = injective′ } where open _↣_ to′ = to f ⊚ to g injective′ : Injective to′ injective′ = injective g ⊚ injective f -- "Equational" reasoning combinators. infix -1 finally-↣ infixr -2 step-↣ -- For an explanation of why step-↣ is defined in this way, see -- Equality.step-≡. step-↣ : ∀ {a b c} (A : Type a) {B : Type b} {C : Type c} → B ↣ C → A ↣ B → A ↣ C step-↣ _ = _∘_ syntax step-↣ A B↣C A↣B = A ↣⟨ A↣B ⟩ B↣C finally-↣ : ∀ {a b} (A : Type a) (B : Type b) → A ↣ B → A ↣ B finally-↣ _ _ A↣B = A↣B syntax finally-↣ A B A↣B = A ↣⟨ A↣B ⟩□ B □
22.415584
72
0.451333
7c16e42dbdbf8ec6ab3b525255a2909bb993784a
293
agda
Agda
test/Succeed/Issue107.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue107.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue107.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS -v tc.inj.check:30 #-} {-# OPTIONS --allow-unsolved-metas #-} module Issue107 where data Bool : Set where true : Bool false : Bool data False : Set where record True : Set where T : Bool -> Set T false = False T _ = True foo : ((a : Bool) -> T a) -> True foo f = f _
14.65
38
0.604096
643af521b909cdbabe11f817f8cf1c1eb8de7ba1
1,088
agda
Agda
Cubical/HITs/Truncation/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/HITs/Truncation/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/HITs/Truncation/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{- A simpler definition of truncation ∥ A ∥ n from n ≥ -1 Note that this uses the HoTT book's indexing, so it will be off from `∥_∥_` in HITs.Truncation.Base by -2 -} {-# OPTIONS --safe #-} module Cubical.HITs.Truncation.Base where open import Cubical.Data.NatMinusOne open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.HITs.Sn.Base open import Cubical.Data.Nat.Base open import Cubical.Data.Unit.Base open import Cubical.Data.Empty -- this definition is off by one. Use hLevelTrunc or ∥_∥ for truncations -- (off by 2 w.r.t. the HoTT-book) data HubAndSpoke {ℓ} (A : Type ℓ) (n : ℕ) : Type ℓ where ∣_∣ : A → HubAndSpoke A n hub : (f : S₊ n → HubAndSpoke A n) → HubAndSpoke A n spoke : (f : S₊ n → HubAndSpoke A n) (x : S₊ n) → hub f ≡ f x hLevelTrunc : ∀ {ℓ} (n : ℕ) (A : Type ℓ) → Type ℓ hLevelTrunc zero A = Unit* hLevelTrunc (suc n) A = HubAndSpoke A n ∥_∥_ : ∀ {ℓ} (A : Type ℓ) (n : ℕ) → Type ℓ ∥ A ∥ n = hLevelTrunc n A ∣_∣ₕ : ∀ {ℓ} {A : Type ℓ} {n : ℕ} → A → ∥ A ∥ n ∣_∣ₕ {n = zero} a = tt* ∣_∣ₕ {n = suc n} a = ∣ a ∣
29.405405
72
0.642463
14aff16bba66fe3f1cd237ce89cfdedac4fa4e36
2,416
agda
Agda
Data/Fin/Properties.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Data/Fin/Properties.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Data/Fin/Properties.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe --postfix-projections #-} module Data.Fin.Properties where open import Prelude open import Data.Fin.Base import Data.Nat.Properties as ℕ open import Data.Nat.Properties using (+-comm) open import Data.Nat open import Function.Injective open import Agda.Builtin.Nat renaming (_<_ to _<ᵇ_) private variable n m : ℕ suc-natfin : Σ[ m ⦂ ℕ ] × (m ℕ.< n) → Σ[ m ⦂ ℕ ] × (m ℕ.< suc n) suc-natfin (m , p) = suc m , p Fin-to-Nat-lt : Fin n → Σ[ m ⦂ ℕ ] × (m ℕ.< n) Fin-to-Nat-lt {n = suc n} f0 = zero , tt Fin-to-Nat-lt {n = suc n} (fs x) = suc-natfin (Fin-to-Nat-lt x) Fin-from-Nat-lt : ∀ m → m ℕ.< n → Fin n Fin-from-Nat-lt {n = suc n} zero p = f0 Fin-from-Nat-lt {n = suc n} (suc m) p = fs (Fin-from-Nat-lt m p) Fin-Nat-lt-rightInv : ∀ m → (p : m ℕ.< n) → Fin-to-Nat-lt {n = n} (Fin-from-Nat-lt m p) ≡ (m , p) Fin-Nat-lt-rightInv {n = suc n} zero p = refl Fin-Nat-lt-rightInv {n = suc n} (suc m) p = cong (suc-natfin {n = n}) (Fin-Nat-lt-rightInv {n = n} m p) Fin-Nat-lt-leftInv : (x : Fin n) → uncurry Fin-from-Nat-lt (Fin-to-Nat-lt x) ≡ x Fin-Nat-lt-leftInv {n = suc n} f0 = refl Fin-Nat-lt-leftInv {n = suc n} (fs x) = cong fs (Fin-Nat-lt-leftInv x) Fin-Nat-lt : Fin n ⇔ Σ[ m ⦂ ℕ ] × (m ℕ.< n) Fin-Nat-lt .fun = Fin-to-Nat-lt Fin-Nat-lt .inv = uncurry Fin-from-Nat-lt Fin-Nat-lt .rightInv = uncurry Fin-Nat-lt-rightInv Fin-Nat-lt .leftInv = Fin-Nat-lt-leftInv FinToℕ : Fin n → ℕ FinToℕ {n = suc n} f0 = zero FinToℕ {n = suc n} (fs x) = suc (FinToℕ x) FinToℕ-injective : ∀ {k} {m n : Fin k} → FinToℕ m ≡ FinToℕ n → m ≡ n FinToℕ-injective {suc k} {f0} {f0} _ = refl FinToℕ-injective {suc k} {f0} {fs x} p = ⊥-elim (ℕ.znots p) FinToℕ-injective {suc k} {fs m} {f0} p = ⊥-elim (ℕ.snotz p) FinToℕ-injective {suc k} {fs m} {fs x} p = cong fs (FinToℕ-injective (ℕ.injSuc p)) pred : Fin (suc n) → Fin (suc (ℕ.pred n)) pred f0 = f0 pred {n = suc n} (fs m) = m discreteFin : ∀ {k} → Discrete (Fin k) discreteFin {k = suc _} f0 f0 = yes refl discreteFin {k = suc _} f0 (fs fk) = no (ℕ.znots ∘ cong FinToℕ) discreteFin {k = suc _} (fs fj) f0 = no (ℕ.snotz ∘ cong FinToℕ) discreteFin {k = suc _} (fs fj) (fs fk) = iff-dec (cong fs iff cong (λ { f0 → fk ; (fs x) → x})) (discreteFin fj fk) isSetFin : isSet (Fin n) isSetFin = Discrete→isSet discreteFin FinFromℕ : (n m : ℕ) → T (n <ᵇ m) → Fin m FinFromℕ zero (suc m) p = f0 FinFromℕ (suc n) (suc m) p = fs (FinFromℕ n m p)
35.014493
103
0.609272
14cf98350b17391ac9e6f5899e35a3064856ef3f
9,865
agda
Agda
test/asset/agda-stdlib-1.0/Data/Graph/Acyclic.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Graph/Acyclic.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/Graph/Acyclic.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Directed acyclic multigraphs ------------------------------------------------------------------------ -- A representation of DAGs, based on the idea underlying Martin -- Erwig's FGL. Note that this representation does not aim to be -- efficient. {-# OPTIONS --without-K --safe #-} module Data.Graph.Acyclic where open import Level using (_⊔_) open import Data.Nat.Base as Nat using (ℕ; zero; suc; _<′_) import Data.Nat.Properties as Nat open import Data.Fin as Fin using (Fin; Fin′; zero; suc; #_; toℕ; _≟_) renaming (_ℕ-ℕ_ to _-_) import Data.Fin.Properties as FP import Data.Fin.Permutation.Components as PC open import Data.Product as Prod using (∃; _×_; _,_) open import Data.Maybe.Base using (Maybe; nothing; just) open import Data.Empty open import Data.Unit.Base using (⊤; tt) open import Data.Vec as Vec using (Vec; []; _∷_) open import Data.List.Base as List using (List; []; _∷_) open import Function open import Induction.Nat using (<′-rec; <′-Rec) open import Relation.Nullary open import Relation.Binary.PropositionalEquality as P using (_≡_) ------------------------------------------------------------------------ -- A lemma private lemma : ∀ n (i : Fin n) → n - suc i <′ n lemma zero () lemma (suc n) i = Nat.≤⇒≤′ $ Nat.s≤s $ FP.nℕ-ℕi≤n n i ------------------------------------------------------------------------ -- Node contexts record Context {ℓ e} (Node : Set ℓ) (Edge : Set e) (n : ℕ) : Set (ℓ ⊔ e) where constructor context field label : Node successors : List (Edge × Fin n) open Context public -- Map for contexts. module _ {ℓ₁ e₁} {N₁ : Set ℓ₁} {E₁ : Set e₁} {ℓ₂ e₂} {N₂ : Set ℓ₂} {E₂ : Set e₂} where cmap : ∀ {n} → (N₁ → N₂) → (List (E₁ × Fin n) → List (E₂ × Fin n)) → Context N₁ E₁ n → Context N₂ E₂ n cmap f g c = context (f (label c)) (g (successors c)) ------------------------------------------------------------------------ -- Graphs infixr 3 _&_ -- The DAGs are indexed on the number of nodes. data Graph {ℓ e} (Node : Set ℓ) (Edge : Set e) : ℕ → Set (ℓ ⊔ e) where ∅ : Graph Node Edge 0 _&_ : ∀ {n} (c : Context Node Edge n) (g : Graph Node Edge n) → Graph Node Edge (suc n) private example : Graph ℕ ℕ 5 example = context 0 [] & context 1 ((10 , # 1) ∷ (11 , # 1) ∷ []) & context 2 ((12 , # 0) ∷ []) & context 3 [] & context 4 [] & ∅ ------------------------------------------------------------------------ -- Higher-order functions module _ {ℓ e} {N : Set ℓ} {E : Set e} {t} where -- "Fold right". foldr : (T : ℕ → Set t) → (∀ {n} → Context N E n → T n → T (suc n)) → T 0 → ∀ {m} → Graph N E m → T m foldr T _∙_ x ∅ = x foldr T _∙_ x (c & g) = c ∙ foldr T _∙_ x g -- "Fold left". foldl : ∀ {n} (T : ℕ → Set t) → ((i : Fin n) → T (toℕ i) → Context N E (n - suc i) → T (suc (toℕ i))) → T 0 → Graph N E n → T n foldl T f x ∅ = x foldl T f x (c & g) = foldl (T ∘′ suc) (f ∘ suc) (f zero x c) g module _ {ℓ₁ e₁} {N₁ : Set ℓ₁} {E₁ : Set e₁} {ℓ₂ e₂} {N₂ : Set ℓ₂} {E₂ : Set e₂} where -- Maps over node contexts. map : (∀ {n} → Context N₁ E₁ n → Context N₂ E₂ n) → ∀ {n} → Graph N₁ E₁ n → Graph N₂ E₂ n map f = foldr _ (λ c → f c &_) ∅ -- Maps over node labels. nmap : ∀ {ℓ₁ ℓ₂ e} {N₁ : Set ℓ₁} {N₂ : Set ℓ₂} {E : Set e} → ∀ {n} → (N₁ → N₂) → Graph N₁ E n → Graph N₂ E n nmap f = map (cmap f id) -- Maps over edge labels. emap : ∀ {ℓ e₁ e₂} {N : Set ℓ} {E₁ : Set e₁} {E₂ : Set e₂} → ∀ {n} → (E₁ → E₂) → Graph N E₁ n → Graph N E₂ n emap f = map (cmap id (List.map (Prod.map f id))) -- Zips two graphs with the same number of nodes. Note that one of the -- graphs has a type which restricts it to be completely disconnected. zipWith : ∀ {ℓ₁ ℓ₂ ℓ e} {N₁ : Set ℓ₁} {N₂ : Set ℓ₂} {N : Set ℓ} {E : Set e} → ∀ {n} → (N₁ → N₂ → N) → Graph N₁ ⊥ n → Graph N₂ E n → Graph N E n zipWith _∙_ ∅ ∅ = ∅ zipWith _∙_ (c₁ & g₁) (c₂ & g₂) = context (label c₁ ∙ label c₂) (successors c₂) & zipWith _∙_ g₁ g₂ ------------------------------------------------------------------------ -- Specific graphs -- A completeley disconnected graph. disconnected : ∀ n → Graph ⊤ ⊥ n disconnected zero = ∅ disconnected (suc n) = context tt [] & disconnected n -- A complete graph. complete : ∀ n → Graph ⊤ ⊤ n complete zero = ∅ complete (suc n) = context tt (List.map (tt ,_) $ Vec.toList (Vec.allFin n)) & complete n ------------------------------------------------------------------------ -- Queries module _ {ℓ e} {N : Set ℓ} {E : Set e} where -- The top-most context. head : ∀ {n} → Graph N E (suc n) → Context N E n head (c & g) = c -- The remaining graph. tail : ∀ {n} → Graph N E (suc n) → Graph N E n tail (c & g) = g -- Finds the context and remaining graph corresponding to a given node -- index. _[_] : ∀ {n} → Graph N E n → (i : Fin n) → Graph N E (suc (n - suc i)) ∅ [ () ] (c & g) [ zero ] = c & g (c & g) [ suc i ] = g [ i ] -- The nodes of the graph (node number relative to "topmost" node × -- node label). nodes : ∀ {n} → Graph N E n → Vec (Fin n × N) n nodes = Vec.zip (Vec.allFin _) ∘ foldr (Vec N) (λ c → label c ∷_) [] private test-nodes : nodes example ≡ (# 0 , 0) ∷ (# 1 , 1) ∷ (# 2 , 2) ∷ (# 3 , 3) ∷ (# 4 , 4) ∷ [] test-nodes = P.refl module _ {ℓ e} {N : Set ℓ} {E : Set e} where -- Topological sort. Gives a vector where earlier nodes are never -- successors of later nodes. topSort : ∀ {n} → Graph N E n → Vec (Fin n × N) n topSort = nodes -- The edges of the graph (predecessor × edge label × successor). -- -- The predecessor is a node number relative to the "topmost" node in -- the graph, and the successor is a node number relative to the -- predecessor. edges : ∀ {n} → Graph N E n → List (∃ λ i → E × Fin (n - suc i)) edges {n} = foldl (λ _ → List (∃ λ i → E × Fin (n - suc i))) (λ i es c → es List.++ List.map (i ,_) (successors c)) [] private test-edges : edges example ≡ (# 1 , 10 , # 1) ∷ (# 1 , 11 , # 1) ∷ (# 2 , 12 , # 0) ∷ [] test-edges = P.refl -- The successors of a given node i (edge label × node number relative -- to i). sucs : ∀ {ℓ e} {N : Set ℓ} {E : Set e} → ∀ {n} → Graph N E n → (i : Fin n) → List (E × Fin (n - suc i)) sucs g i = successors $ head (g [ i ]) private test-sucs : sucs example (# 1) ≡ (10 , # 1) ∷ (11 , # 1) ∷ [] test-sucs = P.refl -- The predecessors of a given node i (node number relative to i × -- edge label). preds : ∀ {ℓ e} {N : Set ℓ} {E : Set e} → ∀ {n} → Graph N E n → (i : Fin n) → List (Fin′ i × E) preds g zero = [] preds (c & g) (suc i) = List._++_ (List.mapMaybe (p i) $ successors c) (List.map (Prod.map suc id) $ preds g i) where p : ∀ {e} {E : Set e} {n} (i : Fin n) → E × Fin n → Maybe (Fin′ (suc i) × E) p i (e , j) with i ≟ j p i (e , .i) | yes P.refl = just (zero , e) p i (e , j) | no _ = nothing private test-preds : preds example (# 3) ≡ (# 1 , 10) ∷ (# 1 , 11) ∷ (# 2 , 12) ∷ [] test-preds = P.refl ------------------------------------------------------------------------ -- Operations -- Weakens a node label. weaken : ∀ {n} {i : Fin n} → Fin (n - suc i) → Fin n weaken {n} {i} j = Fin.inject≤ j (FP.nℕ-ℕi≤n n (suc i)) -- Labels each node with its node number. number : ∀ {ℓ e} {N : Set ℓ} {E : Set e} → ∀ {n} → Graph N E n → Graph (Fin n × N) E n number {N = N} {E} = foldr (λ n → Graph (Fin n × N) E n) (λ c g → cmap (zero ,_) id c & nmap (Prod.map suc id) g) ∅ private test-number : number example ≡ (context (# 0 , 0) [] & context (# 1 , 1) ((10 , # 1) ∷ (11 , # 1) ∷ []) & context (# 2 , 2) ((12 , # 0) ∷ []) & context (# 3 , 3) [] & context (# 4 , 4) [] & ∅) test-number = P.refl -- Reverses all the edges in the graph. reverse : ∀ {ℓ e} {N : Set ℓ} {E : Set e} → ∀ {n} → Graph N E n → Graph N E n reverse {N = N} {E} g = foldl (Graph N E) (λ i g' c → context (label c) (List.map (Prod.swap ∘ Prod.map PC.reverse id) $ preds g i) & g') ∅ g private test-reverse : reverse (reverse example) ≡ example test-reverse = P.refl ------------------------------------------------------------------------ -- Views -- Expands the subgraph induced by a given node into a tree (thus -- losing all sharing). data Tree {ℓ e} (N : Set ℓ) (E : Set e) : Set (ℓ ⊔ e) where node : (label : N) (successors : List (E × Tree N E)) → Tree N E module _ {ℓ e} {N : Set ℓ} {E : Set e} where toTree : ∀ {n} → Graph N E n → Fin n → Tree N E toTree g i = <′-rec Pred expand _ (g [ i ]) where Pred = λ n → Graph N E (suc n) → Tree N E expand : (n : ℕ) → <′-Rec Pred n → Pred n expand n rec (c & g) = node (label c) (List.map (Prod.map id (λ i → rec (n - suc i) (lemma n i) (g [ i ]))) (successors c)) -- Performs the toTree expansion once for each node. toForest : ∀ {n} → Graph N E n → Vec (Tree N E) n toForest g = Vec.map (toTree g) (Vec.allFin _) private test-toForest : toForest example ≡ let n3 = node 3 [] in node 0 [] ∷ node 1 ((10 , n3) ∷ (11 , n3) ∷ []) ∷ node 2 ((12 , n3) ∷ []) ∷ node 3 [] ∷ node 4 [] ∷ [] test-toForest = P.refl
29.272997
78
0.477141
6473dc10d7f3fe3f5adcf9282776a3897fd66623
4,425
agda
Agda
function/isomorphism/core.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
27
2015-04-14T15:47:03.000Z
2022-01-09T07:26:57.000Z
function/isomorphism/core.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
2
2015-02-11T11:14:59.000Z
2015-02-11T15:20:34.000Z
function/isomorphism/core.agda
HoTT/M-types
beebe176981953ab48f37de5eb74557cfc5402f4
[ "BSD-3-Clause" ]
4
2015-04-11T17:19:12.000Z
2019-02-26T06:17:38.000Z
{-# OPTIONS --without-K #-} module function.isomorphism.core where open import level using (_⊔_) open import equality.core open import equality.groupoid open import equality.reasoning open import function.core open import function.overloading open import sum open import function.extensionality.core open import overloading.core -- isomorphisms record _≅_ {i j}(X : Set i)(Y : Set j) : Set (i ⊔ j) where constructor iso field to : X → Y from : Y → X iso₁ : (x : X) → from (to x) ≡ x iso₂ : (y : Y) → to (from y) ≡ y infix 5 _≅_ ≅-struct-iso : ∀ {i j}{X : Set i}{Y : Set j} → (X ≅ Y) ≅ ( Σ (X → Y) λ f → Σ (Y → X) λ g → ((x : X) → g (f x) ≡ x) × ((y : Y) → f (g y) ≡ y) ) ≅-struct-iso = record { to = λ { (iso f g α β) → f , g , α , β } ; from = λ { (f , g , α , β) → iso f g α β } ; iso₁ = λ _ → refl ; iso₂ = λ _ → refl } refl≅ : ∀ {i}{X : Set i} → X ≅ X refl≅ = iso id id (λ _ → refl) (λ _ → refl) ≡⇒≅ : ∀ {i}{X Y : Set i} → X ≡ Y → X ≅ Y ≡⇒≅ refl = refl≅ sym≅ : ∀ {i j}{X : Set i}{Y : Set j} → X ≅ Y → Y ≅ X sym≅ (iso f g H K) = iso g f K H trans≅ : ∀ {i j k}{X : Set i}{Y : Set j}{Z : Set k} → X ≅ Y → Y ≅ Z → X ≅ Z trans≅ {X = X}{Z = Z} (iso f g H K) (iso f' g' H' K') = record { to = f' ∘ f ; from = g ∘ g' ; iso₁ = iso₁ ; iso₂ = iso₂ } where abstract iso₁ : (x : X) → g (g' (f' (f x))) ≡ x iso₁ x = ap g (H' (f x)) · H x iso₂ : (z : Z) → f' (f (g (g' z))) ≡ z iso₂ y = ap f' (K (g' y)) · K' y _·≅_ : ∀ {i j k}{X : Set i}{Y : Set j}{Z : Set k} → X ≅ Y → Y ≅ Z → X ≅ Z _·≅_ = trans≅ infixl 9 _·≅_ module ≅-Reasoning where infix 4 _IsRelatedTo_ infix 2 _∎ infixr 2 _≅⟨_⟩_ infixr 2 _≡⟨_⟩_ infix 1 begin_ data _IsRelatedTo_ {i j}(x : Set i)(y : Set j) : Set (i ⊔ j) where relTo : x ≅ y → x IsRelatedTo y begin_ : ∀ {i j}{X : Set i}{Y : Set j} → X IsRelatedTo Y → X ≅ Y begin relTo p = p _≅⟨_⟩_ : ∀ {i j k} (X : Set i) {Y : Set j}{Z : Set k} → X ≅ Y → Y IsRelatedTo Z → X IsRelatedTo Z _ ≅⟨ p ⟩ relTo q = relTo (trans≅ p q) _≡⟨_⟩_ : ∀ {i j} (X : Set i) {Y : Set i} {Z : Set j} → X ≡ Y → Y IsRelatedTo Z → X IsRelatedTo Z _ ≡⟨ p ⟩ relTo q = relTo (trans≅ (≡⇒≅ p) q) _∎ : ∀ {i} (X : Set i) → X IsRelatedTo X _∎ _ = relTo refl≅ injective : ∀ {i j}{X : Set i}{Y : Set j} → (f : X → Y) → Set _ injective f = ∀ {x x'} → f x ≡ f x' → x ≡ x' retraction : ∀ {i j}{X : Set i}{Y : Set j} → (f : X → Y) → Set _ retraction {X = X}{Y = Y} f = (y : Y) → Σ X λ x → f x ≡ y _↣_ : ∀ {i j} → Set i → Set j → Set _ A ↣ B = Σ (A → B) injective -- composition of injections: _∘i_ : ∀ {i j k}{A : Set i}{B : Set j}{C : Set k} → (B ↣ C) → (A ↣ B) → (A ↣ C) (g , p) ∘i (f , q) = g ∘ f , q ∘ p _↠_ : ∀ {i j} → Set i → Set j → Set _ A ↠ B = Σ (A → B) retraction private module properties {i j}{X : Set i}{Y : Set j} where apply≅ : (X ≅ Y) → X → Y apply≅ = _≅_.to invert≅ : (X ≅ Y) → Y → X invert≅ = _≅_.from instance iso-is-fun : Coercion (X ≅ Y) (X → Y) iso-is-fun = record { coerce = _≅_.to } iso-is-iso : Coercion (X ≅ Y) (X ≅ Y) iso-is-iso = coerce-self _ inj-is-fun : Coercion (X ↣ Y) (X → Y) inj-is-fun = record { coerce = proj₁ } srj-is-fun : Coercion (X ↠ Y) (X → Y) srj-is-fun = record { coerce = proj₁ } private module iso-methods {k}{Source : Set k} ⦃ c : Coercion Source (X ≅ Y) ⦄ where private module with-source (source : Source) where private target = coerce c source open _≅_ target public using () renaming (from to invert) open with-source public open iso-methods public iso⇒inj : (iso : X ≅ Y) → injective (apply iso) iso⇒inj f {x}{x'} q = (iso₁ x) ⁻¹ · ap from q · iso₁ x' where open _≅_ f iso⇒retr : (iso : X ≅ Y) → retraction (apply iso) iso⇒retr f y = from y , iso₂ y where open _≅_ f inj+retr⇒iso : (f : X → Y) → injective f → retraction f → X ≅ Y inj+retr⇒iso f inj-f retr-f = iso f g H K where g : Y → X g y = proj₁ (retr-f y) H : (x : X) → g (f x) ≡ x H x = inj-f (proj₂ (retr-f (f x))) K : (y : Y) → f (g y) ≡ y K y = proj₂ (retr-f y) open properties public
26.656627
68
0.470056
524fe7df459cd260e60b9488a79df9a437225883
25
agda
Agda
test/interaction/Issue2447/M.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2447/M.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2447/M.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue2447.M where
12.5
24
0.84
14f2dc07d69c2735f88f25c992d2fe9491527fba
323
agda
Agda
test/Fail/Issue4586LetPatternAbsurd.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue4586LetPatternAbsurd.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue4586LetPatternAbsurd.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2020-04-15, issue #4586 -- Better error for invalid let pattern. test : Set₁ test = let () = Set in Set -- WAS: -- Set₁ should be empty, but that's not obvious to me -- when checking that the pattern () has type Set₁ -- EXPECTED: -- Not a valid let pattern -- when scope checking let () = Set in Set
21.533333
53
0.656347
6440fe6a3c8ddcd9b69e8fcc6b5f1724f929e9c7
90
agda
Agda
archive/agda-2/Oscar/Data/List.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-2/Oscar/Data/List.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-2/Oscar/Data/List.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
module Oscar.Data.List where open import Agda.Builtin.List public using (List; []; _∷_)
18
58
0.733333