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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7c83cfd415098bd11e5657894cb2a99b4f9d0676
| 36,643
|
agda
|
Agda
|
src/interactive-cmds.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 328
|
2018-09-14T20:06:09.000Z
|
2022-03-26T10:33:07.000Z
|
src/interactive-cmds.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 123
|
2018-09-17T10:53:20.000Z
|
2022-01-12T03:51:28.000Z
|
src/interactive-cmds.agda
|
mb64/cedille
|
d0f69cc6fbfb69d7ef83a436b623d612328eb016
|
[
"MIT"
] | 34
|
2018-09-17T11:51:36.000Z
|
2022-02-20T18:33:16.000Z
|
import cedille-options
module interactive-cmds (options : cedille-options.options) where
open import functions
open import cedille-types
open import ial-datatypes
open import conversion (cedille-options.options.disable-conv options)
using (ctxt-term-def ; ctxt-type-def ; hnf ; unfold-head-no-defs ; unfold-all ; conv-type ; conv-kind ; unfold-head ; unfold-no-defs ; unfold-head-elab ; conv-term)
open import constants
open import ctxt
open import general-util
open import spans options {Id}
open import subst
open import syntax-util
open import type-util
open import to-string options
open import toplevel-state options {IO}
open import untyped-spans options {Id}
open import parser
open import resugar
open import rewriting
open import rename
open import classify options {Id} (λ _ → return triv)
import spans options {IO} as io-spans
open import datatype-util
open import free-vars
open import json
private
elab-typed-err : ∀ {ed} → ctxt → ⟦ ed ⟧' → ⟦ ed ⟧ × 𝔹
elab-typed-err {TERM} Γ t =
map-snd spans-have-error $ map-fst fst $ id-out $ check-term Γ t nothing empty-spans
elab-typed-err {TYPE} Γ T =
map-snd spans-have-error $ map-fst fst $ id-out $ check-type Γ T nothing empty-spans
elab-typed-err {KIND} Γ k =
map-snd spans-have-error $ id-out $ check-kind Γ k empty-spans
elab-typed : ∀ {ed} → ctxt → ⟦ ed ⟧' → ⟦ ed ⟧
elab-typed Γ = fst ∘ elab-typed-err Γ
elab-untyped : ∀ {ed} → ctxt → ⟦ ed ⟧' → ⟦ ed ⟧
elab-untyped {TERM} Γ t = fst $ id-out $ untyped-term Γ t empty-spans
elab-untyped {TYPE} Γ T = fst $ id-out $ untyped-type Γ T empty-spans
elab-untyped {KIND} Γ k = fst $ id-out $ untyped-kind Γ k empty-spans
elab-untyped-no-params : ∀ {ed} → ctxt → ⟦ ed ⟧' → ⟦ ed ⟧
elab-untyped-no-params Γ =
elab-untyped (record Γ {qual = trie-map (map-snd λ _ → []) (ctxt.qual Γ)})
{- Parsing -}
ll-ind : ∀ {X : exprd → Set} → X TERM → X TYPE → X KIND → (ll : exprd) → X ll
ll-ind t T k TERM = t
ll-ind t T k TYPE = T
ll-ind t T k KIND = k
ll-ind' : ∀ {X : Σ exprd ⟦_⟧ → Set} → (s : Σ exprd ⟦_⟧) → ((t : term) → X (TERM , t)) → ((T : type) → X (TYPE , T)) → ((k : kind) → X (KIND , k)) → X s
ll-ind' (TERM , t) tf Tf kf = tf t
ll-ind' (TYPE , T) tf Tf kf = Tf T
ll-ind' (KIND , k) tf Tf kf = kf k
ll-disambiguate : ctxt → ex-tm → maybe ex-tp
ll-disambiguate Γ (ExVar pi x) = ctxt-lookup-type-var Γ x >>= λ _ → just (ExTpVar pi x)
ll-disambiguate Γ (ExApp t NotErased t') = ll-disambiguate Γ t >>= λ T →
just (ExTpAppt T t')
ll-disambiguate Γ (ExAppTp t T') = ll-disambiguate Γ t >>= λ T → just (ExTpApp T T')
ll-disambiguate Γ (ExLam pi ff pi' x (just atk) t) =
ll-disambiguate (ctxt-tk-decl pi' x (case atk of λ {(ExTkt _) → Tkt (TpHole pi'); (ExTkk _) → Tkk KdStar}) Γ) t >>= λ T →
just (ExTpLam pi pi' x atk T)
ll-disambiguate Γ (ExParens pi t pi') = ll-disambiguate Γ t
ll-disambiguate Γ (ExLet pi _ d t) =
ll-disambiguate (Γ' d) t >>= λ T → just (ExTpLet pi d T)
where
Γ' : ex-def → ctxt
Γ' (ExDefTerm pi' x T? t) = ctxt-term-def pi' localScope opacity-open x (just (Hole pi')) (TpHole pi') Γ
Γ' (ExDefType pi' x k T) = ctxt-type-def pi' localScope opacity-open x (just (TpHole pi')) KdStar Γ
ll-disambiguate Γ t = nothing
parse-string : (ll : exprd) → string → maybe ⟦ ll ⟧'
parse-string ll s = case ll-ind {λ ll → string → Either string ⟦ ll ⟧'}
parseTerm parseType parseKind ll s of λ {(Left e) → nothing; (Right e) → just e}
ttk = "term, type, or kind"
parse-err-msg : (failed-to-parse : string) → (as-a : string) → string
parse-err-msg failed-to-parse "" =
"Failed to parse \\\\\"" ^ failed-to-parse ^ "\\\\\""
parse-err-msg failed-to-parse as-a =
"Failed to parse \\\\\"" ^ failed-to-parse ^ "\\\\\" as a " ^ as-a
infixr 7 _>>nothing_ _-_!_>>parse_ _!_>>error_
_>>nothing_ : ∀{ℓ}{A : Set ℓ} → maybe A → maybe A → maybe A
(nothing >>nothing m₂) = m₂
(m₁ >>nothing m₂) = m₁
_-_!_>>parse_ : ∀{A B : Set} → (string → maybe A) → string →
(error-msg : string) → (A → string ⊎ B) → string ⊎ B
(f - s ! e >>parse f') = maybe-else (inj₁ (parse-err-msg s e)) f' (f s)
_!_>>error_ : ∀{E A B : Set} → maybe A → E → (A → E ⊎ B) → E ⊎ B
(just a ! e >>error f) = f a
(nothing ! e >>error f) = inj₁ e
parse-try : ∀ {X : Set} → ctxt → string → maybe
(((ll : exprd) → ⟦ ll ⟧' → X) → X)
parse-try Γ s =
maybe-map (λ t f → maybe-else (f TERM t) (f TYPE) (ll-disambiguate Γ t))
(parse-string TERM s) >>nothing
maybe-map (λ T f → f TYPE T) (parse-string TYPE s) >>nothing
maybe-map (λ k f → f KIND k) (parse-string KIND s)
string-to-𝔹 : string → maybe 𝔹
string-to-𝔹 "tt" = just tt
string-to-𝔹 "ff" = just ff
string-to-𝔹 _ = nothing
parse-ll : string → maybe exprd
parse-ll "term" = just TERM
parse-ll "type" = just TYPE
parse-ll "kind" = just KIND
parse-ll _ = nothing
{- Local Context -}
record lci : Set where
constructor mk-lci
field ll : string; x : var; t : string; T : string; fn : string; pi : posinfo
data 𝕃ₛ {ℓ} (A : Set ℓ) : Set ℓ where
[_]ₛ : A → 𝕃ₛ A
_::ₛ_ : A → 𝕃ₛ A → 𝕃ₛ A
headₛ : ∀ {ℓ} {A : Set ℓ} → 𝕃ₛ A → A
headₛ [ a ]ₛ = a
headₛ (a ::ₛ as) = a
𝕃ₛ-to-𝕃 : ∀ {ℓ} {A : Set ℓ} → 𝕃ₛ A → 𝕃 A
𝕃ₛ-to-𝕃 [ a ]ₛ = [ a ]
𝕃ₛ-to-𝕃 (a ::ₛ as) = a :: 𝕃ₛ-to-𝕃 as
merge-lcis-ctxt-tvs : ctxt → 𝕃 string → ctxt × 𝕃 tagged-val
merge-lcis-ctxt-tvs c =
foldl merge-lcis-ctxt' (c , [])
∘ (sort-lcis ∘ strings-to-lcis)
where
strings-to-lcis : 𝕃 string → 𝕃 lci
strings-to-lcis ss = strings-to-lcis-h ss [] where
strings-to-lcis-h : 𝕃 string → 𝕃 lci → 𝕃 lci
strings-to-lcis-h (ll :: x :: t :: T :: fn :: pi :: tl) items =
strings-to-lcis-h tl (mk-lci ll x t T fn pi :: items)
strings-to-lcis-h _ items = items
-- TODO: Local context information does not pass Δ information!
-- When users are using BR-explorer to rewrite with the rec function,
-- if they call it upon "μ' [SUBTERM] {...}", it won't work unless they say
-- "μ'<rec/mu> [SUBTERM] {...}".
decl-lci : posinfo → var → ctxt → ctxt
decl-lci pi x Γ =
record Γ { qual = trie-insert (ctxt.qual Γ) x (pi % x , []) }
exprd-type-of : exprd → exprd
exprd-type-of TERM = TYPE
exprd-type-of _ = KIND
merge-lci-ctxt : lci → ctxt × 𝕃 tagged-val → ctxt × 𝕃 tagged-val
merge-lci-ctxt (mk-lci ll v t T fn pi) (Γ , tvs) =
maybe-else (Γ , tvs) (map-snd (λ tv → tvs ++ [ tv ]))
(parse-ll ll >>= λ ll →
parse-string (exprd-type-of ll) T >>=
h ll (parse-string ll t))
where
h : (ll : exprd) → maybe ⟦ ll ⟧' → ⟦ exprd-type-of ll ⟧' → maybe (ctxt × tagged-val)
h TERM (just t) T =
let t = elab-untyped Γ t
T = elab-typed Γ T in
return2 (ctxt-term-def pi localScope opacity-open v (just t) T Γ)
(binder-data Γ pi v (Tkt T) ff (just t) "0" "0")
h TYPE (just T) k =
let T = elab-untyped Γ T
k = elab-typed Γ k in
return2 (ctxt-type-def pi localScope opacity-open v (just T) k Γ)
(binder-data Γ pi v (Tkk k) ff (just T) "0" "0")
h TERM nothing T =
let T = elab-typed Γ T in
return2 (ctxt-term-decl pi v T Γ)
(binder-data Γ pi v (Tkt T) ff nothing "0" "0")
h TYPE nothing k =
let k = elab-typed Γ k in
return2 (ctxt-type-decl pi v k Γ)
(binder-data Γ pi v (Tkk k) ff nothing "0" "0")
h _ _ _ = nothing
merge-lcis-ctxt' : 𝕃ₛ lci → ctxt × 𝕃 tagged-val → ctxt × 𝕃 tagged-val
merge-lcis-ctxt' ls (Γ , tvs) =
let ls' = 𝕃ₛ-to-𝕃 ls in
foldr merge-lci-ctxt (foldr (λ l → decl-lci (lci.pi l) (lci.x l)) Γ ls' , tvs) ls'
sort-eq : ∀ {ℓ} {A : Set ℓ} → (A → A → compare-t) → 𝕃 A → 𝕃 (𝕃ₛ A)
sort-eq {_} {A} c = foldr insert [] where
insert : A → 𝕃 (𝕃ₛ A) → 𝕃 (𝕃ₛ A)
insert n [] = [ [ n ]ₛ ]
insert n (a :: as) with c (headₛ a) n
...| compare-eq = n ::ₛ a :: as
...| compare-gt = [ n ]ₛ :: a :: as
...| compare-lt = a :: insert n as
sort-lcis : 𝕃 lci → 𝕃 (𝕃ₛ lci)
sort-lcis = sort-eq λ l₁ l₂ →
compare (posinfo-to-ℕ $ lci.pi l₁) (posinfo-to-ℕ $ lci.pi l₂)
{-
sort-lcis = list-merge-sort.merge-sort lci λ l l' →
posinfo-to-ℕ (lci.pi l) > posinfo-to-ℕ (lci.pi l')
where import list-merge-sort
-}
merge-lcis-ctxt : ctxt → 𝕃 string → ctxt
merge-lcis-ctxt Γ ls = fst $ merge-lcis-ctxt-tvs Γ ls
get-local-ctxt-tvs : ctxt → (pos : ℕ) → (local-ctxt : 𝕃 string) → ctxt × 𝕃 tagged-val
get-local-ctxt-tvs Γ pi =
merge-lcis-ctxt-tvs (foldr (flip ctxt-clear-symbol ∘ fst) Γ
(flip filter (trie-mappings (ctxt.i Γ)) λ {(x , ci , fn' , pi') →
ctxt.fn Γ =string fn' && posinfo-to-ℕ pi' > pi}))
get-local-ctxt : ctxt → (pos : ℕ) → (local-ctxt : 𝕃 string) → ctxt
get-local-ctxt Γ pi ls = fst (get-local-ctxt-tvs Γ pi ls)
{- Helpers -}
step-reduce : ∀ {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
step-reduce Γ t =
let t' = erase t in maybe-else t' id (step-reduceh Γ t') where
step-reduceh : ∀ {ed : exprd} → ctxt → ⟦ ed ⟧ → maybe ⟦ ed ⟧
step-reduceh{TERM} Γ (Var x) = ctxt-lookup-term-var-def Γ x
step-reduceh{TYPE} Γ (TpVar x) = ctxt-lookup-type-var-def Γ x
step-reduceh{TERM} Γ (App (Lam ff x nothing t) t') = just (subst Γ t' x t)
step-reduceh{TYPE} Γ (TpApp (TpLam x (Tkk _) T) (Ttp T')) = just (subst Γ T' x T)
step-reduceh{TYPE} Γ (TpApp (TpLam x (Tkt _) T) (Ttm t)) = just (subst Γ t x T)
step-reduceh{TERM} Γ (App t t') = step-reduceh Γ t >>= λ t → just (App t t')
step-reduceh{TYPE} Γ (TpApp T tT) = step-reduceh Γ T >>= λ T → just (TpApp T tT)
step-reduceh{TERM} Γ (Lam ff x nothing t) = step-reduceh (ctxt-var-decl x Γ) t >>= λ t → just (Lam ff x nothing t)
step-reduceh{TYPE} Γ (TpLam x atk T) = step-reduceh (ctxt-var-decl x Γ) T >>= λ T → just (TpLam x atk T)
step-reduceh{TERM} Γ (LetTm ff x T t' t) = just (subst Γ t' x t)
step-reduceh{TERM} Γ t @ (Mu μ s Tₘ f~ ms) with
decompose-var-headed s >>=c λ sₕ sₐs → env-lookup Γ sₕ
...| just (ctr-def _ _ _ _ _ , _) = just (hnf Γ unfold-head-no-defs t)
...| _ = step-reduceh Γ s >>= λ s → just (Mu μ s Tₘ f~ ms)
step-reduceh Γ t = nothing
parse-norm : erased? → string → maybe (∀ {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧)
parse-norm me "all" = just λ Γ → hnf Γ (record unfold-all {unfold-erase = me})
parse-norm me "head" = just λ Γ → hnf Γ (record unfold-head-elab {unfold-erase = me})
parse-norm me "once" = just λ Γ → step-reduce Γ ∘ erase
parse-norm _ _ = nothing
parse-norm-err = "normalization method (all, head, once)"
{- Command Executors -}
normalize-cmd : ctxt → (str ll pi norm : string) → 𝕃 string → string ⊎ tagged-val
normalize-cmd Γ str ll pi norm ls =
parse-ll - ll ! "language-level" >>parse λ ll' →
string-to-ℕ - pi ! "natural number" >>parse λ sp →
parse-norm tt - norm ! parse-norm-err >>parse λ norm →
parse-string ll' - str ! ll >>parse λ t →
let Γ' = get-local-ctxt Γ sp ls in
inj₂ (to-string-tag "" Γ' (norm Γ' (elab-untyped Γ' t)))
normalize-prompt : ctxt → (str norm : string) → 𝕃 string → string ⊎ tagged-val
normalize-prompt Γ str norm ls =
parse-norm tt - norm ! parse-norm-err >>parse λ norm →
let Γ' = merge-lcis-ctxt Γ ls in
parse-try Γ' - str ! ttk >>parse λ f → f λ ll t →
inj₂ (to-string-tag "" Γ' (norm Γ' (elab-untyped Γ' t)))
erase-cmd : ctxt → (str ll pi : string) → 𝕃 string → string ⊎ tagged-val
erase-cmd Γ str ll pi ls =
parse-ll - ll ! "language-level" >>parse λ ll' →
string-to-ℕ - pi ! "natural number" >>parse λ sp →
parse-string ll' - str ! ll >>parse λ t →
let Γ' = get-local-ctxt Γ sp ls in
inj₂ (to-string-tag "" Γ' (erase (elab-untyped Γ' t)))
erase-prompt : ctxt → (str : string) → 𝕃 string → string ⊎ tagged-val
erase-prompt Γ str ls =
let Γ' = merge-lcis-ctxt Γ ls in
parse-try Γ' - str ! ttk >>parse λ f → f λ ll t →
inj₂ (to-string-tag "" Γ' (erase (elab-untyped Γ' t)))
-- private
-- cmds-to-escaped-string : cmds → strM
-- cmds-to-escaped-string (c :: cs) = cmd-to-string c $ strAdd "\\n\\n" >>str cmds-to-escaped-string cs
-- cmds-to-escaped-string [] = strEmpty
-- data-cmd : ctxt → (encoding name ps is cs : string) → string ⊎ tagged-val
-- data-cmd Γ encodingₛ x psₛ isₛ csₛ =
-- string-to-𝔹 - encodingₛ ! "boolean" >>parse λ encoding →
-- parse-string KIND - psₛ ! "kind" >>parse λ psₖ →
-- parse-string KIND - isₛ ! "kind" >>parse λ isₖ →
-- parse-string KIND - csₛ ! "kind" >>parse λ csₖ →
-- let ps = map (λ {(Index x atk) → Decl posinfo-gen posinfo-gen Erased x atk posinfo-gen}) $ kind-to-indices Γ psₖ
-- cs = map (λ {(Index x (Tkt T)) → Ctr posinfo-gen x T; (Index x (Tkk k)) → Ctr posinfo-gen x $ mtpvar "ErrorExpectedTypeNotKind"}) $ kind-to-indices empty-ctxt csₖ
-- is = kind-to-indices (add-ctrs-to-ctxt cs $ add-params-to-ctxt ps Γ) isₖ
-- picked-encoding = if encoding then mendler-encoding else mendler-simple-encoding
-- defs = datatype-encoding.mk-defs picked-encoding Γ $ Data x ps is cs in
-- inj₂ $ strRunTag "" Γ $ cmds-to-escaped-string $ fst defs
-- pretty-cmd : filepath → filepath → IO string
-- pretty-cmd src-fn dest-fn =
-- readFiniteFile src-fn >>= λ src →
-- case parseStart src of λ where
-- (Left (Left p)) → return ("Lexical error at position " ^ p)
-- (Left (Right p)) → return ("Parse error at position " ^ p)
-- (Right file) → writeFile dest-fn "" >> writeRopeToFile dest-fn (to-string.strRun empty-ctxt (to-string.file-to-string file)) >> return "Finished"
-- where import to-string (record options {pretty-print = tt}) as to-string
{- Commands -}
tv-to-json : string ⊎ tagged-val → json
tv-to-json (inj₁ s) = json-object [ "error" , json-string s ] -- [[ "{\"error\":\"" ]] ⊹⊹ [[ s ]] ⊹⊹ [[ "\"}" ]]
tv-to-json (inj₂ (_ , v , ts)) = tagged-vals-to-json [ "value" , v , ts ]
interactive-cmd-h : ctxt → 𝕃 string → string ⊎ tagged-val
interactive-cmd-h Γ ("normalize" :: input :: ll :: sp :: norm :: lc) =
normalize-cmd Γ input ll sp norm lc
interactive-cmd-h Γ ("erase" :: input :: ll :: sp :: lc) =
erase-cmd Γ input ll sp lc
interactive-cmd-h Γ ("normalizePrompt" :: input :: norm :: lc) =
normalize-prompt Γ input norm lc
interactive-cmd-h Γ ("erasePrompt" :: input :: lc) =
erase-prompt Γ input lc
-- interactive-cmd-h Γ ("data" :: encoding :: x :: ps :: is :: cs :: []) =
-- data-cmd Γ encoding x ps is cs
interactive-cmd-h Γ cs =
inj₁ ("Unknown interactive cmd: " ^ 𝕃-to-string (λ s → s) ", " cs)
record br-history : Set where
inductive
constructor mk-br-history
field
Γ : ctxt
t : term
Tₗₗ : exprd
T : ⟦ Tₗₗ ⟧
Tᵤ : string
f : term → 𝕃 (ctr × term) → term
Γₗ : 𝕃 tagged-val
undo : 𝕃 br-history
redo : 𝕃 br-history
data br-history2 : Set where
br-node : br-history → 𝕃 (ctr × br-history2) → br-history2
br-get-h : br-history2 → br-history
br-get-h (br-node h hs) = h
br-lookup : 𝕃 ℕ → br-history2 → maybe br-history
br-lookup xs h = maybe-map br-get-h $
foldl (λ x h? → h? >>= λ {(br-node h hs) → maybe-map snd $ head2 (nthTail x hs)}) (just h) xs
{-# TERMINATING #-}
br-cmd2 : ctxt → string → string → string → 𝕃 string → IO ⊤
br-cmd2 Γ Tₛ tₛ sp ls =
(string-to-ℕ - sp ! "natural number" >>parse inj₂) >>parseIO λ sp →
elim-pair (get-local-ctxt-tvs Γ sp ls) λ Γ Γₗ →
(parse-try Γ - Tₛ ! ttk >>parse inj₂) >>parseIO λ Tf → Tf λ Tₗₗ T →
(parse-string TERM - tₛ ! "term" >>parse inj₂) >>parseIO λ t →
let T = elab-untyped Γ T
Tₑ = erase T
t = elab-typed Γ t in -- TODO: Probably should switch back to ex-tm so if this doesn't currently check it won't elaborate to a hole!
putJson (tv-to-json $ inj₂ $ ts-tag Γ Tₑ) >>
await (br-node (mk-br-history Γ t Tₗₗ T (rope-to-string $ ts2.to-string Γ Tₑ) const Γₗ [] []) [])
where
import to-string (record options {erase-types = ff}) as ts2
import to-string (record options {erase-types = ff; pretty-print = tt}) as pretty2s
ts-tag : ∀ {ed} → ctxt → ⟦ ed ⟧ → tagged-val
ts-tag = ts2.to-string-tag ""
infixr 6 _>>parseIO_
_>>parseIO_ : ∀ {A : Set} → string ⊎ A → (A → IO ⊤) → IO ⊤
inj₁ e >>parseIO f = putJson $ tv-to-json $ inj₁ e
inj₂ a >>parseIO f = f a
replace-substring : string → string → ℕ → ℕ → string × string
replace-substring sₒ sᵣ fm to with string-to-𝕃char sₒ | string-to-𝕃char sᵣ
...| csₒ | csᵣ =
𝕃char-to-string (take fm csₒ ++ csᵣ ++ drop to csₒ) ,
𝕃char-to-string (take (to ∸ fm) $ drop fm csₒ)
replace : string → string → ℕ → ℕ → string
replace sₒ sᵣ fm to = fst $ replace-substring sₒ sᵣ fm to
substring : string → ℕ → ℕ → string
substring s fm to = snd $ replace-substring s "" fm to
escape-rope : rope → rope
escape-rope [[ s ]] = [[ escape-string s ]]
escape-rope (r₁ ⊹⊹ r₂) = escape-rope r₁ ⊹⊹ escape-rope r₂
parse-path : string → maybe (𝕃 ℕ)
parse-path "" = just []
parse-path s with string-split s ' ' | foldr (λ n ns → ns >>= λ ns → string-to-ℕ n >>= λ n → just (n :: ns)) (just [])
...| "" :: ss | f = f ss
...| path | f = f path
write-history : 𝕃 ℕ → br-history → br-history2 → br-history2
write-history [] h (br-node _ hs) = br-node h hs
write-history (n :: ns) h (br-node hₒ hs) = br-node hₒ $ writeh n hs where
writeh : ℕ → 𝕃 (ctr × br-history2) → 𝕃 (ctr × br-history2)
writeh _ [] = []
writeh zero ((c , h') :: hs) = (c , write-history ns h h') :: hs
writeh (suc n) (h' :: hs) = h' :: writeh n hs
write-children : 𝕃 ℕ → 𝕃 (ctr × br-history) → br-history2 → br-history2
write-children [] hs (br-node h _) = br-node h (map (uncurry λ c h → c , br-node h []) hs)
write-children (n :: ns) hs (br-node h hsₒ) = br-node h $ writeh n hsₒ where
writeh : ℕ → 𝕃 (ctr × br-history2) → 𝕃 (ctr × br-history2)
writeh _ [] = []
writeh zero ((c , h') :: hs') = (c , write-children ns hs h') :: hs'
writeh (suc n) (h' :: hs) = h' :: writeh n hs
outline : br-history2 → term
-- outline (br-node (mk-br-history Γ t TYPE T Tₛ f Γₗ undo redo) []) =
-- elim-pair (id-out $ check-term Γ t (just T) empty-spans) λ t~ ss → f t~ []
-- outline (br-node (mk-br-history Γ t Tₗₗ T Tₛ f Γₗ undo redo) []) = f (elab-untyped-no-params Γ t) []
-- outline (br-node (mk-br-history Γ t Tₗₗ T Tₛ f Γₗ undo redo) hs) =
-- f (elab-typed Γ t) (map (uncurry λ c h → c , outline h) hs)
outline (br-node (mk-br-history Γ t Tₗₗ T Tₛ f Γₗ undo redo) hs) =
f t (map-snd outline <$> hs)
make-case : ctxt → params → term → case-args × term
make-case = h [] where
h : params → ctxt → params → term → case-args × term
h acc Γ (Param me x atk :: ps) (Lam me' x' oc' t') =
h (Param me x' atk :: acc) (ctxt-var-decl x' Γ) (substh-params Γ (renamectxt-single x x') empty-trie ps) t'
h acc Γ ps (Hole pi) = params-to-case-args (reverse acc ++ ps) , Hole pi
h acc Γ ps t = params-to-case-args (reverse acc ++ ps) , params-to-apps ps t
await : br-history2 → IO ⊤
awaith : br-history2 → 𝕃 string → IO ⊤
await his =
getLine >>= λ input →
let input = undo-escape-string input
as = string-split input delimiter in
awaith his as
awaith his as =
let put = putJson ∘ tv-to-json
err = (_>> await his) ∘' put ∘' inj₁ in
case as of λ where -- TODO: for these commands, do not add TYPES/KINDS of local decls to context, as they are probably just bound by foralls/pis/lambdas, not _really_ in scope!
("br" :: path :: as) →
maybe-else' (parse-path path) (err ("Could not parse " ^ path ^ " as a list of space-delimited natural numbers")) λ path →
let await-with = await ∘ flip (write-history path) his in
maybe-else' (br-lookup path his) (err "Beta-reduction pointer does not exist") λ where
this @ (mk-br-history Γ t Tₗₗ T Tᵤ f Γₗ undo redo) → case as of λ where
("undo" :: []) → case undo of λ where
[] → err "No undo history"
(u :: us) →
put (inj₂ $ "" , [[ "Undo" ]] , []) >>
await-with (record u {undo = us; redo = this :: redo})
--u (await Γ t Tₗₗ T Tᵤ f undo redo :: redo)
("redo" :: []) → case redo of λ where
[] → err "No redo history"
(r :: rs) →
put (inj₂ $ "" , [[ "Redo" ]] , []) >>
await-with (record r {undo = this :: undo; redo = rs})
--r
("get" :: []) →
put (inj₂ $ "" , [[ Tᵤ ]] , []) >>
await his
("parse" :: []) →
(_>> await his) $
maybe-else' (parse-string Tₗₗ Tᵤ)
(putJson $ spans-to-json $ global-error "Parse error" nothing)
λ T → putJson $ spans-to-json $ snd $ id-out $ ll-ind {λ ll → ctxt → ⟦ ll ⟧' → spanM ⟦ ll ⟧}
untyped-term untyped-type untyped-kind Tₗₗ (record Γ { fn = "missing" }) T empty-spans
("context" :: []) →
putJson (json-object [ "value" , json-array [ tagged-vals-to-json Γₗ ] ]) >> await his
("check" :: t?) →
let await-set = maybe-else (await his) λ t → await-with $ record this
{t = t; undo = this :: undo; redo = []} in
(λ e → either-else' e
(uncurry λ t? e → put (inj₁ e) >> await-set t?)
(uncurry λ t? m → put (inj₂ $ "value" , [[ m ]] , []) >> await-set t?)) $
ll-ind' {λ T → (maybe term × string) ⊎ (maybe term × string)} (Tₗₗ , T)
(λ _ → inj₁ $ nothing , "Expression must be a type, not a term!")
(λ T →
(case t? of λ where
[] → inj₂ nothing
(t :: []) → maybe-else' (parse-string TERM t)
(inj₁ $ nothing , parse-err-msg t "term")
(inj₂ ∘ just)
_ → inj₁ $ nothing ,
"To many arguments given to beta-reduction command 'check'")
>>= λ t? →
elim-pair (maybe-else' t? (elim-pair (id-out (check-term (qualified-ctxt Γ) (resugar t) (just T) empty-spans)) λ t~ ss → nothing , spans-have-error ss)
λ t → elim-pair (id-out (check-term Γ t (just T) empty-spans))
λ t~ ss → just t~ , spans-have-error ss) λ t~? e? →
let fail = inj₁ (just (maybe-else' t~? t id) , "Type error")
try-β = elim-pair (id-out (check-term Γ (ExBeta pi-gen nothing nothing) (just T) empty-spans)) λ β~ ss → if spans-have-error ss then inj₁ (nothing , "Type error") else inj₂ (just β~ , "Equal by beta") in
if e?
then if isJust t? then fail else try-β
else inj₂ (t~? , "Type inhabited"))
(λ _ → inj₁ $ nothing , "Expression must be a type, not a kind!")
("rewrite" :: fm :: to :: eq :: ρ+? :: lc) →
let Γ' = merge-lcis-ctxt Γ lc in
either-else'
(parse-string TERM - eq ! "term" >>parse λ eqₒ →
string-to-𝔹 - ρ+? ! "boolean" >>parse λ ρ+? →
string-to-ℕ - fm ! "natural number" >>parse λ fm →
string-to-ℕ - to ! "natural number" >>parse λ to →
parse-try Γ' - substring Tᵤ fm to ! ttk >>parse λ Tf → Tf λ ll Tₗ →
elim-pair (id-out (check-term Γ' eqₒ nothing empty-spans)) $ uncurry λ eq Tₑ ss →
is-eq-tp? Tₑ ! "Synthesized a non-equational type from the proof"
>>error uncurry λ t₁ t₂ →
err⊎-guard (spans-have-error ss) "Proof does not type check" >>
let Tₑ = TpEq t₁ t₂
x = fresh-var Γ' "x"
Tₗ = elab-untyped-no-params Γ' Tₗ in
elim-pair (map-snd snd $ rewrite-exprd Tₗ Γ' ρ+? nothing (just eq) t₁ x 0) λ Tᵣ n →
err⊎-guard (iszero n) "No rewrites could be performed" >>
parse-string Tₗₗ - replace Tᵤ
(rope-to-string $ [[ "(" ]] ⊹⊹ ts2.to-string Γ' Tᵣ ⊹⊹ [[ ")" ]]) fm to
! ll-ind "term" "type" "kind" Tₗₗ >>parse λ Tᵤ →
let Tᵤ = elab-untyped-no-params (ctxt-var-decl x Γ) Tᵤ in
ll-ind' {λ {(ll , T) → ⟦ ll ⟧ → string ⊎ ⟦ ll ⟧ × (term → term)}}
(Tₗₗ , Tᵤ)
(λ t T → inj₂ $ rewrite-mk-phi x eq T (subst Γ t₂ x t) , id)
(λ Tᵤ _ → inj₂ $ post-rewrite (ctxt-var-decl x Γ) x eq t₂ Tᵤ ,
Rho eq x Tᵤ)
(λ k _ → inj₂ $ subst Γ t₂ x k , id)
T) err $ uncurry λ T' fₜ →
put (inj₂ $ ts-tag Γ $ erase T') >>
await-with (record this {T = T'; Tᵤ = rope-to-string $ ts2.to-string Γ $ erase T'; f = f ∘ fₜ; undo = this :: undo; redo = []})
("normalize" :: fm :: to :: norm :: lc) →
either-else'
(let Γ' = merge-lcis-ctxt Γ lc in
string-to-ℕ - fm ! "natural number" >>parse λ fm →
string-to-ℕ - to ! "natural number" >>parse λ to →
let tₛ = substring Tᵤ fm to in
parse-try Γ' - tₛ ! ttk >>parse λ t → t λ ll t →
parse-norm ff - norm ! parse-norm-err >>parse λ norm →
let s = norm Γ' $ elab-untyped-no-params Γ' t
rs = rope-to-string $ [[ "(" ]] ⊹⊹ ts2.to-string Γ' s ⊹⊹ [[ ")" ]]
Tᵤ' = replace Tᵤ rs fm to in
parse-string Tₗₗ - Tᵤ' ! ll-ind "term" "type" "kind" Tₗₗ >>parse λ Tᵤ' →
let Tᵤ' = elab-untyped-no-params Γ' Tᵤ' in
inj₂ Tᵤ')
err λ Tᵤ' →
put (inj₂ $ ts-tag Γ Tᵤ') >>
await-with (record this {T = Tᵤ' {-Checks?-}; Tᵤ = rope-to-string $ ts2.to-string Γ $ erase Tᵤ'; undo = this :: undo; redo = []})
("conv" :: ll :: fm :: to :: t' :: ls) →
let Γ' = merge-lcis-ctxt Γ ls in
either-else'
(parse-ll - ll ! "language level" >>parse λ ll →
string-to-ℕ - fm ! "natural number" >>parse λ fm →
string-to-ℕ - to ! "natural number" >>parse λ to →
let t = substring Tᵤ fm to in
parse-string ll - t ! ll-ind "term" "type" "kind" ll >>parse λ t →
parse-string ll - t' ! ll-ind "term" "type" "kind" ll >>parse λ t' →
let t = elab-untyped-no-params Γ' t; t' = elab-untyped-no-params Γ' t' in
err⊎-guard (~ ll-ind {λ ll → ctxt → ⟦ ll ⟧ → ⟦ ll ⟧ → 𝔹}
conv-term conv-type conv-kind ll Γ' t t') "Inconvertible" >>
let rs = [[ "(" ]] ⊹⊹ ts2.to-string Γ' (erase t') ⊹⊹ [[ ")" ]]
Tᵤ = replace Tᵤ (rope-to-string rs) fm to in
parse-string Tₗₗ - Tᵤ ! ll-ind "term" "type" "kind" Tₗₗ >>parse λ Tᵤ →
inj₂ (elab-untyped-no-params Γ Tᵤ)) err λ Tᵤ' →
put (inj₂ $ ts-tag Γ $ erase Tᵤ') >>
await-with (record this {Tᵤ = rope-to-string $ ts2.to-string Γ $ erase Tᵤ'; undo = this :: undo; redo = []})
("bind" :: xᵤ :: []) →
let Γₚᵢ = ℕ-to-string (length Γₗ) in
either-else'
(ll-ind' {λ {(ll , _) → string ⊎ ctxt × erased? × tpkd × ⟦ ll ⟧ × (term → term)}} (Tₗₗ , T)
(λ t' →
let R = string ⊎ ctxt × erased? × tpkd × term × (term → term) in
(case_of_ {B = (erased? → var → maybe tpkd → term → R) → R}
(t' , hnf Γ unfold-head t') $ uncurry λ where
(Lam me x oc body) _ f → f me x oc body
_ (Lam me x oc body) f → f me x oc body
_ _ _ → inj₁ "Not a term abstraction") λ me x oc body →
inj₂ $ ctxt-var-decl-loc Γₚᵢ xᵤ Γ ,
me ,
maybe-else' oc (Tkt $ TpHole pi-gen) id ,
rename-var (ctxt-var-decl-loc Γₚᵢ xᵤ Γ) x xᵤ body ,
Lam me xᵤ oc)
(λ T → Γ ⊢ T =β= λ where
(TpAbs me x dom cod) →
let Γ' = ctxt-tk-decl Γₚᵢ xᵤ dom Γ in
inj₂ $ Γ' ,
me ,
dom ,
rename-var Γ' x (Γₚᵢ % xᵤ) cod ,
Lam me xᵤ (just dom)
_ → inj₁ "Not a type abstraction")
(λ k → inj₁ "Expression must be a term or a type"))
err λ where
(Γ' , me , dom , cod , fₜ) →
let tv = binder-data Γ' Γₚᵢ xᵤ dom me nothing "0" "0" in
-- putJson (json-object [ "value" , json-array (json-array (json-rope (fst (snd tv)) :: json-rope (to-string Γ' $ erase cod) :: []) :: []) ]) >>
putJson (json-object [ "value" , json-array [ json-rope (to-string Γ' $ erase cod) ] ]) >>
await-with (record this
{Γ = Γ' ;
T = cod;
Tᵤ = rope-to-string $ ts2.to-string Γ' $ erase cod;
f = f ∘ fₜ;
Γₗ = Γₗ ++ [ tv ];
undo = this :: undo;
redo = []})
("case" :: scrutinee :: rec :: motive?) → -- TODO: Motive?
let Γₚᵢ = ℕ-to-string (length Γₗ) in
either-else'
(parse-string TERM - scrutinee ! "term" >>parse λ scrutinee →
elim-pair (id-out (check-term Γ scrutinee nothing empty-spans)) $ uncurry λ tₛ Tₛ ss →
if (spans-have-error ss) then inj₁ "Error synthesizing a type from the input term"
else
let Tₛ = hnf Γ unfold-no-defs Tₛ in
case decompose-ctr-type Γ Tₛ of λ where
(TpVar Xₛ , [] , as) →
ll-ind' {λ T → string ⊎ (term × term × 𝕃 (ctr × type) × type × ctxt × 𝕃 tagged-val × datatype-info)} (Tₗₗ , T)
(λ t → inj₁ "Expression must be a type to case split")
(λ T → maybe-else' (data-lookup Γ Xₛ as)
(inj₁ "The synthesized type of the input term is not a datatype")
λ d → let mk-data-info X _ asₚ asᵢ ps kᵢ k cs csₚₛ _ _ = d
is' = kind-to-indices (add-params-to-ctxt ps Γ) kᵢ
is = drop-last 1 is'
Tₘ = refine-motive Γ is' (asᵢ ++ [ Ttm tₛ ]) T
sM' = ctxt-mu-decls Γ tₛ is Tₘ d Γₚᵢ "0" "0" rec
σ = λ y → inst-ctrs Γ ps asₚ (map-snd (rename-var {TYPE} Γ X y) <$> cs)
sM = if rec =string ""
then (σ X , const spanMok , Γ , [] , empty-renamectxt , (λ Γ t T → t) , (λ Γ T k → T))
else (σ (Γₚᵢ % mu-Type/ rec) , sM')
mu = sigma-build-evidence Xₛ d in
case sM of λ where
(σ-cs , _ , Γ' , ts , ρ , tf , Tf) →
if spans-have-error (snd $ id-out $
check-type (qualified-ctxt Γ) (resugar Tₘ) (just kᵢ) empty-spans)
then inj₁ "Computed an ill-typed motive"
else inj₂ (
tₛ ,
mu ,
map (λ {(Ctr x T) →
let T' = hnf Γ' unfold-head-elab T in
Ctr x T ,
(case decompose-ctr-type Γ' T' of λ {(Tₕ , ps' , as) →
params-to-alls ps' $ hnf Γ' unfold-head-no-defs (TpApp
(recompose-tpapps (drop (length ps) as) Tₘ)
(Ttm (recompose-apps (params-to-args ps') $
recompose-apps asₚ (Var x))))})})
σ-cs ,
Tₘ ,
Γ' ,
ts ,
d))
(λ k → inj₁ "Expression must be a type to case split")
(Tₕ , [] , as) → inj₁ "Synthesized a non-datatype from the input term"
(Tₕ , ps , as) →
inj₁ "Case splitting is currently restricted to datatypes")
err $ λ where
(scrutinee , mu , cs , Tₘ , Γ , ts , d) →
let json = json-object [ "value" , json-array
[ json-object (map
(λ {(Ctr x _ , T) → unqual-all (ctxt.qual Γ) x ,
json-rope (to-string Γ (erase T))})
cs) ] ] in -- ) ] ] in
putJson json >>
let shallow = iszero (string-length rec)
mk-cs = map λ where
(Ctr x T , t) →
let T' = hnf Γ unfold-head-elab T in
case decompose-ctr-type Γ T' of λ where
(Tₕ , ps , as) →
elim-pair (make-case Γ ps t) λ cas t → Case x cas t []
f'' = λ t cs → (if shallow then Mu rec else Sigma (just mu)) t (just Tₘ) d (mk-cs cs)
f' = λ t cs → f (f'' t cs) cs
mk-hs = map $ map-snd λ T'' →
mk-br-history Γ t TYPE T''
(rope-to-string $ to-string Γ $ erase T'')
(λ t cs → t) (Γₗ ++ ts) [] [] in
await (write-children path (mk-hs cs) $
write-history path (record this
{f = f';
Γ = Γ;
t = scrutinee;
Γₗ = Γₗ ++ ts;-- TODO: Should we really do this?
undo = this :: undo;
redo = []})
his)
("print" :: tab :: []) →
either-else' (string-to-ℕ - tab ! "natural number" >>parse inj₂) err λ tab →
putRopeLn (escape-rope (json-to-rope (tv-to-json (inj₂ $ pretty2s.strRunTag "" Γ $ pretty2s.strNest (suc {-left paren-} tab) (pretty2s.to-stringh $ outline his))))) >> await his
("quit" :: []) → put $ inj₂ $ strRunTag "" Γ $ strAdd "Quitting beta-reduction mode..."
_ → err $ foldl (λ a s → s ^ char-to-string delimiter ^ a)
"Unknown beta-reduction command: " as
_ → err "A beta-reduction buffer is still open"
interactive-cmd : 𝕃 string → toplevel-state → IO ⊤
interactive-cmd ("br2" :: T :: t :: sp :: lc) ts = br-cmd2 (toplevel-state.Γ ts) T t sp lc
--interactive-cmd ("pretty" :: src :: dest :: []) ts = pretty-cmd src dest >>= putStrLn
interactive-cmd ls ts = putRopeLn (json-to-rope (tv-to-json (interactive-cmd-h (toplevel-state.Γ ts) ls)))
interactive-not-br-cmd-msg = tv-to-json $ inj₁ "Beta-reduction mode has been terminated"
| 50.264746
| 227
| 0.496684
|
7c825ccbf628fcf7ba7b51eefcb7e506d511ee25
| 486
|
agda
|
Agda
|
test/fail/Issue555b.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/fail/Issue555b.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/Issue555b.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
-- Andreas, 2012-01-13
module Issue555b where
data Empty : Set where
record Unit : Set where
constructor tt
-- Do we want to allow this?
data Exp (A : Set) : Set1
data Exp where -- ? needs to report that too few parameters are given
var : Exp Empty
app : {A B : Set} → Exp (A → B) → Exp A → Exp B
-- Basically, A is first declared as a parameter, but later,
-- in the definition, it is turned into an index.
bla : {A : Set} → Exp A → Unit
bla var = tt
bla (app f a) = bla f
| 23.142857
| 69
| 0.654321
|
d1659aadf84e832df950b7bb2dde4df4a14d3145
| 3,553
|
agda
|
Agda
|
agda-stdlib/src/Function/Structures.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Function/Structures.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Function/Structures.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Structures for types of functions
------------------------------------------------------------------------
-- The contents of this file should usually be accessed from `Function`.
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Function.Structures
{a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} (_≈₁_ : Rel A ℓ₁) (_≈₂_ : Rel B ℓ₂)
where
open import Data.Product using (∃; _×_; _,_)
open import Function.Base
open import Function.Definitions
open import Level using (_⊔_)
------------------------------------------------------------------------
-- Definitions
record IsCongruent (f : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
cong : Congruent _≈₁_ _≈₂_ f
isEquivalence₁ : IsEquivalence _≈₁_
isEquivalence₂ : IsEquivalence _≈₂_
module Eq₁ where
setoid : Setoid a ℓ₁
setoid = record
{ isEquivalence = isEquivalence₁
}
open Setoid setoid public
module Eq₂ where
setoid : Setoid b ℓ₂
setoid = record
{ isEquivalence = isEquivalence₂
}
open Setoid setoid public
record IsInjection (f : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
isCongruent : IsCongruent f
injective : Injective _≈₁_ _≈₂_ f
open IsCongruent isCongruent public
record IsSurjection (f : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
isCongruent : IsCongruent f
surjective : Surjective _≈₁_ _≈₂_ f
open IsCongruent isCongruent public
record IsBijection (f : A → B) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
isInjection : IsInjection f
surjective : Surjective _≈₁_ _≈₂_ f
open IsInjection isInjection public
bijective : Bijective _≈₁_ _≈₂_ f
bijective = injective , surjective
isSurjection : IsSurjection f
isSurjection = record
{ isCongruent = isCongruent
; surjective = surjective
}
record IsLeftInverse (f : A → B) (g : B → A) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
isCongruent : IsCongruent f
cong₂ : Congruent _≈₂_ _≈₁_ g
inverseˡ : Inverseˡ _≈₁_ _≈₂_ f g
open IsCongruent isCongruent public
renaming (cong to cong₁)
record IsRightInverse (f : A → B) (g : B → A) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
isCongruent : IsCongruent f
cong₂ : Congruent _≈₂_ _≈₁_ g
inverseʳ : Inverseʳ _≈₁_ _≈₂_ f g
open IsCongruent isCongruent public
renaming (cong to cong₁)
record IsBiEquivalence
(f : A → B) (g₁ : B → A) (g₂ : B → A) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f-isCongruent : IsCongruent f
cong₂ : Congruent _≈₂_ _≈₁_ g₁
cong₃ : Congruent _≈₂_ _≈₁_ g₂
open IsCongruent f-isCongruent public
renaming (cong to cong₁)
record IsBiInverse
(f : A → B) (g₁ : B → A) (g₂ : B → A) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f-isCongruent : IsCongruent f
cong₂ : Congruent _≈₂_ _≈₁_ g₁
inverseˡ : Inverseˡ _≈₁_ _≈₂_ f g₁
cong₃ : Congruent _≈₂_ _≈₁_ g₂
inverseʳ : Inverseʳ _≈₁_ _≈₂_ f g₂
open IsCongruent f-isCongruent public
renaming (cong to cong₁)
record IsInverse (f : A → B) (g : B → A) : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
isLeftInverse : IsLeftInverse f g
inverseʳ : Inverseʳ _≈₁_ _≈₂_ f g
open IsLeftInverse isLeftInverse public
isRightInverse : IsRightInverse f g
isRightInverse = record
{ isCongruent = isCongruent
; cong₂ = cong₂
; inverseʳ = inverseʳ
}
inverse : Inverseᵇ _≈₁_ _≈₂_ f g
inverse = inverseˡ , inverseʳ
| 25.198582
| 75
| 0.594709
|
7c214579c8bbfabc4b51aab519b603d77fce3b46
| 12,177
|
agda
|
Agda
|
eval-checks.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | 1
|
2019-12-19T23:42:31.000Z
|
2019-12-19T23:42:31.000Z
|
eval-checks.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | null | null | null |
eval-checks.agda
|
hazelgrove/hazelnat-myth
|
a8f9299090d95f4ef1a6c2f15954c2981c0ee25c
|
[
"MIT"
] | null | null | null |
open import Nat
open import Prelude
open import List
open import contexts
open import core
open import lemmas-general
open import preservation
module eval-checks where
eval-unicity : ∀{⛽ Δ Σ' Γ E e τ r r' K K'} →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' , Γ ⊢ e :: τ →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ K →
E ⊢ e ⌊ ⛽ ⌋⇒ r' ⊣ K' →
r == r' ∧ K == K'
xc-unicity : ∀{Δ Σ' r1 r2 τ K K'} →
Δ , Σ' ⊢ r1 ·: τ →
Δ , Σ' ⊢ r2 ·: τ →
Constraints⦃ r1 , r2 ⦄:= K →
Constraints⦃ r1 , r2 ⦄:= K' →
K == K'
eval-unicity Γ⊢E (TAFix _) EFix EFix = refl , refl
eval-unicity Γ⊢E (TAVar _) (EVar h) (EVar h') = ctxunicity h h' , refl
eval-unicity Γ⊢E (TAApp _ ta-f ta-arg) (EAppFix f1 form eval-f eval-arg eval) (EAppFix f2 form' eval-f' eval-arg' eval')
rewrite form | form'
with eval-unicity Γ⊢E ta-f eval-f eval-f' | eval-unicity Γ⊢E ta-arg eval-arg eval-arg'
... | refl , refl | refl , refl
with preservation Γ⊢E ta-f eval-f
... | TAFix Γ'⊢Ef (TAFix ta-ef)
rewrite Fuel-depletion-unicity f1 f2
with eval-unicity (EnvInd (EnvInd Γ'⊢Ef (preservation Γ⊢E ta-f eval-f)) (preservation Γ⊢E ta-arg eval-arg)) ta-ef eval eval'
... | refl , refl = refl , refl
eval-unicity Γ⊢E TAUnit EUnit EUnit = refl , refl
eval-unicity Γ⊢E (TAApp x ta-e ta-e₁) (EAppFix x₁ form eval eval₁ eval₂) (EAppUnfinished eval' nf eval'')
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl
rewrite form
= abort (nf refl)
eval-unicity Γ⊢E (TAApp x ta-e ta-e₁) (EAppUnfinished eval nf eval₁) (EAppFix x₂ form eval' eval'' eval''')
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl
rewrite form
= abort (nf refl)
eval-unicity Γ⊢E (TAApp x ta-f ta-arg) (EAppUnfinished eval-f x₁ eval-arg) (EAppUnfinished eval-f' x₂ eval-arg')
with eval-unicity Γ⊢E ta-f eval-f eval-f' | eval-unicity Γ⊢E ta-arg eval-arg eval-arg'
... | refl , refl | refl , refl = refl , refl
eval-unicity Γ⊢E (TAPair x ta-e1 ta-e2) (EPair eval1 eval2) (EPair eval1' eval2')
with eval-unicity Γ⊢E ta-e1 eval1 eval1' | eval-unicity Γ⊢E ta-e2 eval2 eval2'
... | refl , refl | refl , refl = refl , refl
eval-unicity Γ⊢E (TAFst ta-e) (EFst eval) (EFst eval')
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = refl , refl
eval-unicity Γ⊢E (TAFst ta-e) (EFst eval) (EFstUnfinished eval' np)
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = abort (np refl)
eval-unicity Γ⊢E (TAFst ta-e) (EFstUnfinished eval np) (EFst eval')
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = abort (np refl)
eval-unicity Γ⊢E (TAFst ta-e) (EFstUnfinished eval x) (EFstUnfinished eval' x₁)
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = refl , refl
eval-unicity Γ⊢E (TASnd ta-e) (ESnd eval) (ESnd eval')
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = refl , refl
eval-unicity Γ⊢E (TASnd ta-e) (ESnd eval) (ESndUnfinished eval' np)
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = abort (np refl)
eval-unicity Γ⊢E (TASnd ta-e) (ESndUnfinished eval np) (ESnd eval')
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = abort (np refl)
eval-unicity Γ⊢E (TASnd ta-e) (ESndUnfinished eval x) (ESndUnfinished eval' x₁)
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = refl , refl
eval-unicity Γ⊢E (TACtor x x₁ ta-e) (ECtor eval) (ECtor eval')
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = refl , refl
eval-unicity Γ⊢E (TACase d∈σ' ta-e x₁ ta-rules) (EMatch f1 form eval-e eval-ec) (EMatch f2 form' eval'-e eval'-ec)
with eval-unicity Γ⊢E ta-e eval-e eval'-e
... | refl , refl
with ctxunicity form form'
... | refl
with ta-rules form
... | _ , _ , _ , c∈cctx , ta-ec
with preservation Γ⊢E ta-e eval-e
... | TACtor d∈'σ' c∈'cctx ta-r'
rewrite ctxunicity d∈σ' d∈'σ' | ctxunicity c∈cctx c∈'cctx | Fuel-depletion-unicity f1 f2
with eval-unicity (EnvInd Γ⊢E ta-r') ta-ec eval-ec eval'-ec
... | refl , refl = refl , refl
eval-unicity Γ⊢E (TACase x ta-e x₁ x₂) (EMatch x₃ x₄ eval eval₁) (EMatchUnfinished eval' nc)
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = abort (nc refl)
eval-unicity Γ⊢E (TACase x ta-e x₁ x₂) (EMatchUnfinished eval nc) (EMatch x₄ x₅ eval' eval'')
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = abort (nc refl)
eval-unicity Γ⊢E (TACase x ta-e x₁ x₂) (EMatchUnfinished eval x₃) (EMatchUnfinished eval' x₄)
with eval-unicity Γ⊢E ta-e eval eval'
... | refl , refl = refl , refl
eval-unicity Γ⊢E (TAHole x) EHole EHole = refl , refl
eval-unicity Γ⊢E (TAAsrt x ta-e1 ta-e2) (EAsrt eval1 eval2 xc) (EAsrt eval1' eval2' xc')
with eval-unicity Γ⊢E ta-e1 eval1 eval1' | eval-unicity Γ⊢E ta-e2 eval2 eval2'
... | refl , refl | refl , refl
rewrite xc-unicity (preservation Γ⊢E ta-e1 eval1) (preservation Γ⊢E ta-e2 eval2) xc xc'
= refl , refl
xc-unicity ta1 ta2 RCRefl RCRefl = refl
xc-unicity ta1 ta2 RCRefl (RCPair x rc2 rc3) = abort (x refl)
xc-unicity ta1 ta2 RCRefl (RCCtor x rc2) = abort (x refl)
xc-unicity ta1 ta2 RCRefl (RCVal1 x x₁ x₂ x₃) = abort (x refl)
xc-unicity ta1 ta2 RCRefl (RCVal2 x x₁ x₂ x₃) = abort (x refl)
xc-unicity ta1 ta2 (RCPair x rc1 rc2) RCRefl = abort (x refl)
xc-unicity (TAPair ta1 ta2) (TAPair ta3 ta4) (RCPair x rc1 rc2) (RCPair x₁ rc3 rc4)
rewrite xc-unicity ta1 ta3 rc1 rc3 | xc-unicity ta2 ta4 rc2 rc4
= refl
xc-unicity ta1 ta2 (RCPair x rc1 rc2) (RCVal1 x₁ (Inl x₂) x₃ x₄) = abort (x₂ refl)
xc-unicity ta1 ta2 (RCPair x rc1 rc2) (RCVal1 x₁ (Inr x₂) x₃ x₄) = abort (x₂ refl)
xc-unicity ta1 ta2 (RCPair x rc1 rc2) (RCVal2 x₁ (Inl x₂) x₃ x₄) = abort (x₂ refl)
xc-unicity ta1 ta2 (RCPair x rc1 rc2) (RCVal2 x₁ (Inr x₂) x₃ x₄) = abort (x₂ refl)
xc-unicity ta1 ta2 (RCCtor x rc1) RCRefl = abort (x refl)
xc-unicity (TACtor d∈σ' c∈cctx ta1) (TACtor d∈'σ' c∈'cctx ta2) (RCCtor x rc1) (RCCtor x₁ rc2)
rewrite ctxunicity d∈σ' d∈'σ' | ctxunicity c∈cctx c∈'cctx
= xc-unicity ta1 ta2 rc1 rc2
xc-unicity ta1 ta2 (RCCtor x rc1) (RCVal1 x₁ x₂ (Inl x₃) x₄) = abort (x₃ refl)
xc-unicity ta1 ta2 (RCCtor x rc1) (RCVal1 x₁ x₂ (Inr x₃) x₄) = abort (x₃ refl)
xc-unicity ta1 ta2 (RCCtor x rc1) (RCVal2 x₁ x₂ (Inl x₃) x₄) = abort (x₃ refl)
xc-unicity ta1 ta2 (RCCtor x rc1) (RCVal2 x₁ x₂ (Inr x₃) x₄) = abort (x₃ refl)
xc-unicity ta1 ta2 (RCVal1 x x₁ x₂ x₃) RCRefl = abort (x refl)
xc-unicity ta1 ta2 (RCVal1 x (Inl x₁) x₂ x₃) (RCPair x₄ rc2 rc3) = abort (x₁ refl)
xc-unicity ta1 ta2 (RCVal1 x (Inr x₁) x₂ x₃) (RCPair x₄ rc2 rc3) = abort (x₁ refl)
xc-unicity ta1 ta2 (RCVal1 x _ (Inl x₁) x₃) (RCCtor x₄ rc2) = abort (x₁ refl)
xc-unicity ta1 ta2 (RCVal1 x _ (Inr x₁) x₃) (RCCtor x₄ rc2) = abort (x₁ refl)
xc-unicity ta1 ta2 (RCVal1 x x₁ x₂ x₃) (RCVal1 x₄ x₅ x₆ x₇)
rewrite Coerce-unicity x₃ x₇
= refl
xc-unicity TAUnit TAUnit (RCVal1 x x₁ x₂ x₃) (RCVal2 x₄ x₅ x₆ x₇) = abort (x₄ refl)
xc-unicity (TAPair ta1 ta2) (TAPair ta3 ta4) (RCVal1 x (Inl x₂) _ x₃) (RCVal2 x₄ x₅ x₆ x₇) = abort (x₂ refl)
xc-unicity (TAPair ta1 ta2) (TAPair ta3 ta4) (RCVal1 x (Inr x₂) _ x₃) (RCVal2 x₄ x₅ x₆ x₇) = abort (x₂ refl)
xc-unicity (TACtor x₈ x₉ ta1) (TACtor x₁₀ x₁₁ ta2) (RCVal1 x x₁ (Inl h) x₃) (RCVal2 x₄ x₅ x₆ x₇) = abort (h refl)
xc-unicity (TACtor x₈ x₉ ta1) (TACtor x₁₀ x₁₁ ta2) (RCVal1 x x₁ (Inr h) x₃) (RCVal2 x₄ x₅ x₆ x₇) = abort (h refl)
xc-unicity ta1 ta2 (RCVal2 x x₁ x₂ x₃) RCRefl = abort (x refl)
xc-unicity ta1 ta2 (RCVal2 x (Inl x₁) x₂ x₃) (RCPair x₄ rc2 rc3) = abort (x₁ refl)
xc-unicity ta1 ta2 (RCVal2 x (Inr x₁) x₂ x₃) (RCPair x₄ rc2 rc3) = abort (x₁ refl)
xc-unicity ta1 ta2 (RCVal2 x x₁ (Inl x₂) x₃) (RCCtor x₄ rc2) = abort (x₂ refl)
xc-unicity ta1 ta2 (RCVal2 x x₁ (Inr x₂) x₃) (RCCtor x₄ rc2) = abort (x₂ refl)
xc-unicity TAUnit TAUnit (RCVal2 x x₁ x₂ x₃) (RCVal1 x₄ x₅ x₆ x₇) = abort (x refl)
xc-unicity (TAPair ta1 ta2) (TAPair ta3 ta4) (RCVal2 x (Inl h) x₂ x₃) (RCVal1 x₄ x₅ x₆ x₇) = abort (h refl)
xc-unicity (TAPair ta1 ta2) (TAPair ta3 ta4) (RCVal2 x (Inr h) x₂ x₃) (RCVal1 x₄ x₅ x₆ x₇) = abort (h refl)
xc-unicity (TACtor x₈ x₉ ta1) (TACtor x₁₀ x₁₁ ta2) (RCVal2 x x₁ (Inl h) x₃) (RCVal1 x₄ x₅ x₆ x₇) = abort (h refl)
xc-unicity (TACtor x₈ x₉ ta1) (TACtor x₁₀ x₁₁ ta2) (RCVal2 x x₁ (Inr h) x₃) (RCVal1 x₄ x₅ x₆ x₇) = abort (h refl)
xc-unicity ta1 ta2 (RCVal2 x x₁ x₂ x₃) (RCVal2 x₄ x₅ x₆ x₇)
rewrite Coerce-unicity x₃ x₇
= refl
-- useful in practice, since threading type-checks around everywhere can be a pain
-- note that this does not prove unicity of constraints, which isn't true for poorly-typed terms
untyped-eval-unicity : ∀{⛽ E e r r' K K'} →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ K →
E ⊢ e ⌊ ⛽ ⌋⇒ r' ⊣ K' →
r == r'
untyped-eval-unicity EFix EFix = refl
untyped-eval-unicity (EVar h) (EVar h') = ctxunicity h h'
untyped-eval-unicity (EAppFix f1 form eval-f eval-arg eval) (EAppFix f2 form' eval-f' eval-arg' eval')
rewrite form | form'
with untyped-eval-unicity eval-f eval-f' | untyped-eval-unicity eval-arg eval-arg'
... | refl | refl
rewrite Fuel-depletion-unicity f1 f2 | untyped-eval-unicity eval eval'
= refl
untyped-eval-unicity EUnit EUnit = refl
untyped-eval-unicity (EAppFix x₁ form eval eval₁ eval₂) (EAppUnfinished eval' nf eval'')
rewrite untyped-eval-unicity eval eval' | form
= abort (nf refl)
untyped-eval-unicity (EAppUnfinished eval nf eval₁) (EAppFix x₂ form eval' eval'' eval''')
rewrite untyped-eval-unicity eval eval' | form
= abort (nf refl)
untyped-eval-unicity (EAppUnfinished eval-f x₁ eval-arg) (EAppUnfinished eval-f' x₂ eval-arg')
rewrite untyped-eval-unicity eval-f eval-f' | untyped-eval-unicity eval-arg eval-arg'
= refl
untyped-eval-unicity (EPair eval1 eval2) (EPair eval1' eval2')
rewrite untyped-eval-unicity eval1 eval1' | untyped-eval-unicity eval2 eval2'
= refl
untyped-eval-unicity (EFst eval) (EFst eval')
with untyped-eval-unicity eval eval'
... | refl = refl
untyped-eval-unicity (EFst eval) (EFstUnfinished eval' np)
with untyped-eval-unicity eval eval'
... | refl = abort (np refl)
untyped-eval-unicity (EFstUnfinished eval np) (EFst eval')
with untyped-eval-unicity eval eval'
... | refl = abort (np refl)
untyped-eval-unicity (EFstUnfinished eval x) (EFstUnfinished eval' x₁)
with untyped-eval-unicity eval eval'
... | refl = refl
untyped-eval-unicity (ESnd eval) (ESnd eval')
with untyped-eval-unicity eval eval'
... | refl = refl
untyped-eval-unicity (ESnd eval) (ESndUnfinished eval' np)
with untyped-eval-unicity eval eval'
... | refl = abort (np refl)
untyped-eval-unicity (ESndUnfinished eval np) (ESnd eval')
with untyped-eval-unicity eval eval'
... | refl = abort (np refl)
untyped-eval-unicity (ESndUnfinished eval x) (ESndUnfinished eval' x₁)
with untyped-eval-unicity eval eval'
... | refl = refl
untyped-eval-unicity (ECtor eval) (ECtor eval')
with untyped-eval-unicity eval eval'
... | refl = refl
untyped-eval-unicity (EMatch f1 form eval-e eval-ec) (EMatch f2 form' eval'-e eval'-ec)
with untyped-eval-unicity eval-e eval'-e
... | refl
with ctxunicity form form'
... | refl
rewrite Fuel-depletion-unicity f1 f2
with untyped-eval-unicity eval-ec eval'-ec
... | refl = refl
untyped-eval-unicity (EMatch x₃ x₄ eval eval₁) (EMatchUnfinished eval' nc)
with untyped-eval-unicity eval eval'
... | refl = abort (nc refl)
untyped-eval-unicity (EMatchUnfinished eval nc) (EMatch x₄ x₅ eval' eval'')
with untyped-eval-unicity eval eval'
... | refl = abort (nc refl)
untyped-eval-unicity (EMatchUnfinished eval x₃) (EMatchUnfinished eval' x₄)
with untyped-eval-unicity eval eval'
... | refl = refl
untyped-eval-unicity EHole EHole = refl
untyped-eval-unicity (EAsrt eval1 eval2 xc) (EAsrt eval1' eval2' xc')
with untyped-eval-unicity eval1 eval1' | untyped-eval-unicity eval2 eval2'
... | refl | refl = refl
| 52.487069
| 128
| 0.643098
|
1302b0fdeb923e11937d2bb0ad44a885a752684a
| 5,886
|
agda
|
Agda
|
Cubical/Relation/Binary/Construct/Intersection.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Binary/Construct/Intersection.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Binary/Construct/Intersection.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Construct.Intersection where
open import Cubical.Core.Everything
open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Logic using (_⊓_)
open import Cubical.Data.Sigma
open import Cubical.Data.Sum.Base using (_⊎_; inl; inr; rec)
open import Cubical.Relation.Binary
open import Cubical.Relation.Nullary using (yes; no; Dec)
------------------------------------------------------------------------
-- Definition
_∩_ : ∀ {a b ℓ₁ ℓ₂} {A : Type a} {B : Type b} →
REL A B ℓ₁ → REL A B ℓ₂ → REL A B (ℓ-max ℓ₁ ℓ₂)
L ∩ R = λ i j → L i j ⊓ R i j
------------------------------------------------------------------------
-- Properties
module _ {a ℓ₁ ℓ₂} {A : Type a} (L : Rel A ℓ₁) (R : Rel A ℓ₂) where
reflexive : Reflexive L → Reflexive R → Reflexive (L ∩ R)
reflexive L-refl R-refl = L-refl , R-refl
symmetric : Symmetric L → Symmetric R → Symmetric (L ∩ R)
symmetric L-sym R-sym = map-× L-sym R-sym
transitive : Transitive L → Transitive R → Transitive (L ∩ R)
transitive L-trans R-trans (xLy , xRy) (yLz , yRz) = L-trans xLy yLz , R-trans xRy yRz
respects : ∀ {p} (P : A → hProp p) →
P Respects L ⊎ P Respects R → P Respects (L ∩ R)
respects P resp (Lxy , Rxy) = rec (λ x → x Lxy) (λ x → x Rxy) resp
min : ∀ {⊤} → Minimum L ⊤ → Minimum R ⊤ → Minimum (L ∩ R) ⊤
min L-min R-min x = L-min x , R-min x
max : ∀ {⊥} → Maximum L ⊥ → Maximum R ⊥ → Maximum (L ∩ R) ⊥
max L-max R-max x = L-max x , R-max x
toNotEq : ToNotEq L ⊎ ToNotEq R → ToNotEq (L ∩ R)
toNotEq tonoteq (Lxy , Rxy) x≡y = rec (λ x → x Lxy x≡y) (λ y → y Rxy x≡y) tonoteq
irreflexive : Irreflexive L ⊎ Irreflexive R → Irreflexive (L ∩ R)
irreflexive irrefl (xLx , xRx) = rec (λ x → x xLx) (λ y → y xRx) irrefl
antisymmetric : Antisymmetric L ⊎ Antisymmetric R → Antisymmetric (L ∩ R)
antisymmetric (inl L-antisym) (Lxy , _) (Lyx , _) = L-antisym Lxy Lyx
antisymmetric (inr R-antisym) (_ , Rxy) (_ , Ryx) = R-antisym Rxy Ryx
module _ {a b ℓ₁ ℓ₂ ℓ₃} {A : Type a} {B : Type b}
(≈ : REL A B ℓ₁) {L : REL A B ℓ₂} {R : REL A B ℓ₃} where
implies : (≈ ⇒ L) → (≈ ⇒ R) → ≈ ⇒ (L ∩ R)
implies ≈⇒L ≈⇒R ≈ = ≈⇒L ≈ , ≈⇒R ≈
module _ {a ℓ₁ ℓ₂ ℓ₃} {A : Type a}
(≈ : Rel A ℓ₁) (L : Rel A ℓ₂) (R : Rel A ℓ₃) where
respectsˡ : L Respectsˡ ≈ → R Respectsˡ ≈ → (L ∩ R) Respectsˡ ≈
respectsˡ L-resp R-resp x≈y = map-× (L-resp x≈y) (R-resp x≈y)
respectsʳ : L Respectsʳ ≈ → R Respectsʳ ≈ → (L ∩ R) Respectsʳ ≈
respectsʳ L-resp R-resp x≈y = map-× (L-resp x≈y) (R-resp x≈y)
respects₂ : L Respects₂ ≈ → R Respects₂ ≈ → (L ∩ R) Respects₂ ≈
respects₂ (Lʳ , Lˡ) (Rʳ , Rˡ) = respectsʳ Lʳ Rʳ , respectsˡ Lˡ Rˡ
module _ {a b ℓ₁ ℓ₂} {A : Type a} {B : Type b} (L : REL A B ℓ₁) (R : REL A B ℓ₂) where
decidable : Decidable L → Decidable R → Decidable (L ∩ R)
decidable L? R? x y = ×-dec (L? x y) (R? x y)
where
×-dec : ∀ {a b} {A : Type a} {B : Type b} → Dec A → Dec B → Dec (A × B)
×-dec (yes a) (yes b) = yes (a , b)
×-dec _ (no ¬b) = no (¬b ∘ snd)
×-dec (no ¬a) _ = no (¬a ∘ fst)
------------------------------------------------------------------------
-- Structures
module _ {a ℓ₁ ℓ₂} {A : Type a} {L : Rel A ℓ₁} {R : Rel A ℓ₂} where
isPartialEquivalence : IsPartialEquivalence L → IsPartialEquivalence R → IsPartialEquivalence (L ∩ R)
isPartialEquivalence eqₗ eqᵣ = record
{ symmetric = symmetric L R Eqₗ.symmetric Eqᵣ.symmetric
; transitive = transitive L R Eqₗ.transitive Eqᵣ.transitive
}
where module Eqₗ = IsPartialEquivalence eqₗ; module Eqᵣ = IsPartialEquivalence eqᵣ
isEquivalence : IsEquivalence L → IsEquivalence R → IsEquivalence (L ∩ R)
isEquivalence eqₗ eqᵣ = record
{ isPartialEquivalence = isPartialEquivalence Eqₗ.isPartialEquivalence Eqᵣ.isPartialEquivalence
; reflexive = reflexive L R Eqₗ.reflexive Eqᵣ.reflexive
}
where module Eqₗ = IsEquivalence eqₗ; module Eqᵣ = IsEquivalence eqᵣ
isDecEquivalence : IsDecEquivalence L → IsDecEquivalence R → IsDecEquivalence (L ∩ R)
isDecEquivalence eqₗ eqᵣ = record
{ isEquivalence = isEquivalence Eqₗ.isEquivalence Eqᵣ.isEquivalence
; _≟_ = decidable L R Eqₗ._≟_ Eqᵣ._≟_
}
where module Eqₗ = IsDecEquivalence eqₗ; module Eqᵣ = IsDecEquivalence eqᵣ
isPreorder : IsPreorder L → IsPreorder R → IsPreorder (L ∩ R)
isPreorder Oₗ Oᵣ = record
{ reflexive = reflexive L R Oₗ.reflexive Oᵣ.reflexive
; transitive = transitive L R Oₗ.transitive Oᵣ.transitive
}
where module Oₗ = IsPreorder Oₗ; module Oᵣ = IsPreorder Oᵣ
isPartialOrderˡ : IsPartialOrder L → IsPreorder R → IsPartialOrder (L ∩ R)
isPartialOrderˡ Oₗ Oᵣ = record
{ isPreorder = isPreorder Oₗ.isPreorder Oᵣ
; antisym = antisymmetric L R (inl Oₗ.antisym)
}
where module Oₗ = IsPartialOrder Oₗ; module Oᵣ = IsPreorder Oᵣ
isPartialOrderʳ : IsPreorder L → IsPartialOrder R → IsPartialOrder (L ∩ R)
isPartialOrderʳ Oₗ Oᵣ = record
{ isPreorder = isPreorder Oₗ Oᵣ.isPreorder
; antisym = antisymmetric L R (inr Oᵣ.antisym)
}
where module Oₗ = IsPreorder Oₗ; module Oᵣ = IsPartialOrder Oᵣ
isStrictPartialOrderˡ : IsStrictPartialOrder L → Transitive R → IsStrictPartialOrder (L ∩ R)
isStrictPartialOrderˡ Oₗ transitiveᵣ = record
{ irrefl = irreflexive L R (inl Oₗ.irrefl)
; transitive = transitive L R Oₗ.transitive transitiveᵣ
}
where module Oₗ = IsStrictPartialOrder Oₗ
isStrictPartialOrderʳ : Transitive L → IsStrictPartialOrder R → IsStrictPartialOrder (L ∩ R)
isStrictPartialOrderʳ transitiveₗ Oᵣ = record
{ irrefl = irreflexive L R (inr Oᵣ.irrefl)
; transitive = transitive L R transitiveₗ Oᵣ.transitive
}
where module Oᵣ = IsStrictPartialOrder Oᵣ
| 41.450704
| 103
| 0.621475
|
1bb585490c7d4bd038a8e9bfe384fb82617ef4d2
| 20,039
|
agda
|
Agda
|
src/Delay-monad/Bisimilarity/Negative.agda
|
nad/delay-monad
|
495f9996673d0f1f34ce202902daaa6c39f8925e
|
[
"MIT"
] | null | null | null |
src/Delay-monad/Bisimilarity/Negative.agda
|
nad/delay-monad
|
495f9996673d0f1f34ce202902daaa6c39f8925e
|
[
"MIT"
] | null | null | null |
src/Delay-monad/Bisimilarity/Negative.agda
|
nad/delay-monad
|
495f9996673d0f1f34ce202902daaa6c39f8925e
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Some negative results related to weak bisimilarity and expansion
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
module Delay-monad.Bisimilarity.Negative {a} {A : Type a} where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude.Size
open import Function-universe equality-with-J hiding (id; _∘_)
open import Delay-monad
open import Delay-monad.Bisimilarity
open import Delay-monad.Termination
------------------------------------------------------------------------
-- Lemmas stating that functions of certain types can be defined iff A
-- is uninhabited
-- The computation now x is an expansion of
-- later (record { force = now x }) for every x : A iff A is
-- uninhabited.
Now≳later-now = (x : A) → now x ≳ later (record { force = now x })
now≳later-now⇔uninhabited : Now≳later-now ⇔ ¬ A
now≳later-now⇔uninhabited = record
{ to = Now≳later-now ↝⟨ (λ hyp x → case hyp x of λ ()) ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ hyp _ → hyp _ _) ⟩□
Now≳later-now □
}
-- A variant of laterˡ⁻¹ for (fully defined) expansion can be defined
-- iff A is uninhabited.
Laterˡ⁻¹-≳ = ∀ {x} {y : Delay A ∞} → later x ≳ y → force x ≳ y
laterˡ⁻¹-≳⇔uninhabited : Laterˡ⁻¹-≳ ⇔ ¬ A
laterˡ⁻¹-≳⇔uninhabited = record
{ to = Laterˡ⁻¹-≳ ↝⟨ (λ hyp _ → hyp (reflexive _)) ⟩
Now≳later-now ↝⟨ _⇔_.to now≳later-now⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ hyp {_ _} _ → hyp _ _) ⟩□
Laterˡ⁻¹-≳ □
}
-- The following variants of transitivity can be proved iff A is
-- uninhabited.
Transitivity-≈≳≳ = {x y z : Delay A ∞} → x ≈ y → y ≳ z → x ≳ z
Transitivity-≳≈≳ = {x y z : Delay A ∞} → x ≳ y → y ≈ z → x ≳ z
transitive-≈≳≳⇔uninhabited : Transitivity-≈≳≳ ⇔ ¬ A
transitive-≈≳≳⇔uninhabited = record
{ to = Transitivity-≈≳≳ ↝⟨ (λ trans → trans (laterʳ (reflexive _))) ⟩
Laterˡ⁻¹-≳ ↝⟨ _⇔_.to laterˡ⁻¹-≳⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ hyp {_ _ _} _ _ → hyp _ _) ⟩□
Transitivity-≈≳≳ □
}
transitive-≳≈≳⇔uninhabited : Transitivity-≳≈≳ ⇔ ¬ A
transitive-≳≈≳⇔uninhabited = record
{ to = Transitivity-≳≈≳ ↝⟨ (λ trans {_ y} lx≳y → later⁻¹ {y = record { force = y }}
(trans lx≳y (laterʳ (reflexive _)))) ⟩
Laterˡ⁻¹-≳ ↝⟨ _⇔_.to laterˡ⁻¹-≳⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ hyp {_ _ _} _ _ → hyp _ _) ⟩□
Transitivity-≳≈≳ □
}
------------------------------------------------------------------------
-- Lemmas stating that certain size-preserving functions can be
-- defined iff A is uninhabited
-- A variant of laterˡ⁻¹ in which one occurrence of weak bisimilarity
-- is replaced by strong bisimilarity, and both arguments are
-- specialised, can be made size-preserving iff A is uninhabited.
--
-- This lemma is used to prove all other similar results below
-- (directly or indirectly), with the exception that an alternative,
-- more direct proof is also given for one of the results.
Laterˡ⁻¹-∼≈ = ∀ {i} {x : A} →
[ i ] later (λ { .force → now x }) ∼ never →
[ i ] now x ≈ never
size-preserving-laterˡ⁻¹-∼≈⇔uninhabited : Laterˡ⁻¹-∼≈ ⇔ ¬ A
size-preserving-laterˡ⁻¹-∼≈⇔uninhabited = record
{ to = Laterˡ⁻¹-∼≈ ↝⟨ (λ laterˡ⁻¹-∼≈ x → contradiction (laterˡ⁻¹-∼≈ {_}) x ∞) ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _} _ → trivial _ _) ⟩□
Laterˡ⁻¹-∼≈ □
}
where
module _ (laterˡ⁻¹-∼≈ : Laterˡ⁻¹-∼≈) (x : A) where
mutual
now≈never : ∀ {i} → [ i ] now x ≈ never
now≈never = laterˡ⁻¹-∼≈ (later now∼never)
now∼never : ∀ {i} → [ i ] now x ∼′ never
force now∼never {j = j} = ⊥-elim (contradiction j)
contradiction : Size → ⊥
contradiction i = now≉never (now≈never {i = i})
-- A variant of Laterˡ⁻¹-∼≈ which it is sometimes easier to work with.
Laterˡ⁻¹-∼≈′ = ∀ {i} {x : A} →
[ i ] later (record { force = now x }) ∼ never →
[ i ] now x ≈ never
size-preserving-laterˡ⁻¹-∼≈′⇔uninhabited : Laterˡ⁻¹-∼≈′ ⇔ ¬ A
size-preserving-laterˡ⁻¹-∼≈′⇔uninhabited =
Laterˡ⁻¹-∼≈′ ↝⟨ record { to = _∘ transitive-∼ʳ (later λ { .force → now })
; from = _∘ transitive-∼ʳ (later λ { .force → now })
} ⟩
Laterˡ⁻¹-∼≈ ↝⟨ size-preserving-laterˡ⁻¹-∼≈⇔uninhabited ⟩□
¬ A □
-- A variant of laterʳ⁻¹ for weak bisimilarity in which one occurrence
-- of weak bisimilarity is replaced by strong bisimilarity, and both
-- arguments are specialised, can be made size-preserving iff A is
-- uninhabited.
Laterʳ⁻¹-∼≈ = ∀ {i} {x : A} →
[ i ] never ∼ later (record { force = now x }) →
[ i ] never ≈ now x
size-preserving-laterʳ⁻¹-∼≈⇔uninhabited : Laterʳ⁻¹-∼≈ ⇔ ¬ A
size-preserving-laterʳ⁻¹-∼≈⇔uninhabited =
Laterʳ⁻¹-∼≈ ↝⟨ record { to = λ laterʳ⁻¹ → symmetric ∘ laterʳ⁻¹ ∘ symmetric
; from = λ laterˡ⁻¹ → symmetric ∘ laterˡ⁻¹ ∘ symmetric
} ⟩
Laterˡ⁻¹-∼≈′ ↝⟨ size-preserving-laterˡ⁻¹-∼≈′⇔uninhabited ⟩□
¬ A □
-- A variant of laterʳ⁻¹ for expansion in which one occurrence of the
-- expansion relation is replaced by strong bisimilarity, and both
-- arguments are specialised, can be made size-preserving iff A is
-- uninhabited.
Laterʳ⁻¹-∼≳ = ∀ {i} {x : A} →
[ i ] never ∼ later (record { force = now x }) →
[ i ] never ≳ now x
size-preserving-laterʳ⁻¹-∼≳⇔uninhabited : Laterʳ⁻¹-∼≳ ⇔ ¬ A
size-preserving-laterʳ⁻¹-∼≳⇔uninhabited = record
{ to = Laterʳ⁻¹-∼≳ ↝⟨ ≳→ ∘_ ⟩
Laterʳ⁻¹-∼≈ ↝⟨ _⇔_.to size-preserving-laterʳ⁻¹-∼≈⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _} _ → trivial _ _) ⟩□
Laterʳ⁻¹-∼≳ □
}
-- The function laterˡ⁻¹ can be made size-preserving iff A is
-- uninhabited.
Laterˡ⁻¹-≈ = ∀ {i x} {y : Delay A ∞} →
[ i ] later x ≈ y → [ i ] force x ≈ y
size-preserving-laterˡ⁻¹-≈⇔uninhabited : Laterˡ⁻¹-≈ ⇔ ¬ A
size-preserving-laterˡ⁻¹-≈⇔uninhabited = record
{ to = Laterˡ⁻¹-≈ ↝⟨ _∘ ∼→ ⟩
Laterˡ⁻¹-∼≈ ↝⟨ _⇔_.to size-preserving-laterˡ⁻¹-∼≈⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _} _ → trivial _ _) ⟩□
Laterˡ⁻¹-≈ □
}
-- The function laterʳ⁻¹ can be made size-preserving for weak
-- bisimilarity iff A is uninhabited.
Laterʳ⁻¹-≈ = ∀ {i} {x : Delay A ∞} {y} →
[ i ] x ≈ later y → [ i ] x ≈ force y
size-preserving-laterʳ⁻¹-≈⇔uninhabited : Laterʳ⁻¹-≈ ⇔ ¬ A
size-preserving-laterʳ⁻¹-≈⇔uninhabited =
Laterʳ⁻¹-≈ ↝⟨ record { to = λ laterʳ⁻¹ → symmetric ∘ laterʳ⁻¹ ∘ symmetric
; from = λ laterˡ⁻¹ → symmetric ∘ laterˡ⁻¹ ∘ symmetric
} ⟩
Laterˡ⁻¹-≈ ↝⟨ size-preserving-laterˡ⁻¹-≈⇔uninhabited ⟩□
¬ A □
-- The function laterʳ⁻¹ can be made size-preserving for expansion iff
-- A is uninhabited.
Laterʳ⁻¹-≳ = ∀ {i} {x : Delay A ∞} {y} →
[ i ] x ≳ later y → [ i ] x ≳ force y
size-preserving-laterʳ⁻¹-≳⇔uninhabited : Laterʳ⁻¹-≳ ⇔ ¬ A
size-preserving-laterʳ⁻¹-≳⇔uninhabited = record
{ to = Laterʳ⁻¹-≳ ↝⟨ _∘ ∼→ ⟩
Laterʳ⁻¹-∼≳ ↝⟨ _⇔_.to size-preserving-laterʳ⁻¹-∼≳⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _} _ → trivial _ _) ⟩□
Laterʳ⁻¹-≳ □
}
-- A variant of ⇓-respects-≈ in which _≈_ is replaced by _∼_ can be
-- made size-preserving in the second argument iff A is uninhabited.
⇓-Respects-∼ʳ = ∀ {i x y} {z : A} →
x ⇓ z → [ i ] x ∼ y → Terminates i y z
size-preserving-⇓-respects-∼ʳ⇔uninhabited : ⇓-Respects-∼ʳ ⇔ ¬ A
size-preserving-⇓-respects-∼ʳ⇔uninhabited = record
{ to = ⇓-Respects-∼ʳ ↝⟨ (λ resp → resp (laterʳ now)) ⟩
Laterˡ⁻¹-∼≈ ↝⟨ _⇔_.to size-preserving-laterˡ⁻¹-∼≈⇔uninhabited ⟩
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
⇓-Respects-∼ʳ □
}
-- The lemma ⇓-respects-≈ can be made size-preserving in the second
-- argument iff A is uninhabited.
⇓-Respects-≈ʳ = ∀ {i x y} {z : A} →
x ⇓ z → [ i ] x ≈ y → Terminates i y z
size-preserving-⇓-respects-≈ʳ⇔uninhabited : ⇓-Respects-≈ʳ ⇔ ¬ A
size-preserving-⇓-respects-≈ʳ⇔uninhabited = record
{ to = ⇓-Respects-≈ʳ ↝⟨ (λ resp x⇓z → resp x⇓z ∘ ∼→) ⟩
⇓-Respects-∼ʳ ↝⟨ _⇔_.to size-preserving-⇓-respects-∼ʳ⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
⇓-Respects-≈ʳ □
}
-- There is a transitivity-like proof, taking weak bisimilarity and
-- strong bisimilarity to weak bisimilarity, that preserves the size
-- of the second argument iff A is uninhabited.
Transitivity-≈∼ʳ = ∀ {i} {x y z : Delay A ∞} →
x ≈ y → [ i ] y ∼ z → [ i ] x ≈ z
size-preserving-transitivity-≈∼ʳ⇔uninhabited : Transitivity-≈∼ʳ ⇔ ¬ A
size-preserving-transitivity-≈∼ʳ⇔uninhabited = record
{ to = Transitivity-≈∼ʳ ↝⟨ (λ trans → trans) ⟩
⇓-Respects-∼ʳ ↝⟨ _⇔_.to size-preserving-⇓-respects-∼ʳ⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≈∼ʳ □
}
-- There is a transitivity-like proof, taking strong bisimilarity and
-- weak bisimilarity to weak bisimilarity, that preserves the size of
-- the first argument iff A is uninhabited.
Transitivity-∼≈ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ∼ y → y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-∼≈ˡ⇔uninhabited : Transitivity-∼≈ˡ ⇔ ¬ A
size-preserving-transitivity-∼≈ˡ⇔uninhabited =
Transitivity-∼≈ˡ ↝⟨ record { to = λ trans {_ _ _ _} p q →
symmetric (trans (symmetric q) (symmetric p))
; from = λ trans {_ _ _ _} p q →
symmetric (trans (symmetric q) (symmetric p))
} ⟩
Transitivity-≈∼ʳ ↝⟨ size-preserving-transitivity-≈∼ʳ⇔uninhabited ⟩□
¬ A □
-- There is a transitivity-like proof, taking strong bisimilarity and
-- expansion to expansion, that preserves the size of the first
-- argument iff A is uninhabited.
Transitivity-∼≳ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ∼ y → y ≳ z → [ i ] x ≳ z
size-preserving-transitivity-∼≳ˡ⇔uninhabited : Transitivity-∼≳ˡ ⇔ ¬ A
size-preserving-transitivity-∼≳ˡ⇔uninhabited = record
{ to = Transitivity-∼≳ˡ ↝⟨ (λ trans never∼lnx → trans never∼lnx (laterˡ now)) ⟩
Laterʳ⁻¹-∼≳ ↝⟨ _⇔_.to size-preserving-laterʳ⁻¹-∼≳⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-∼≳ˡ □
}
-- There is a transitivity proof for weak bisimilarity that preserves
-- the size of the second argument iff A is uninhabited.
Transitivity-≈ʳ = ∀ {i} {x y z : Delay A ∞} →
x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-≈ʳ⇔uninhabited : Transitivity-≈ʳ ⇔ ¬ A
size-preserving-transitivity-≈ʳ⇔uninhabited = record
{ to = Transitivity-≈ʳ ↝⟨ (λ trans → trans) ⟩
⇓-Respects-≈ʳ ↝⟨ _⇔_.to size-preserving-⇓-respects-≈ʳ⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≈ʳ □
}
-- There is a transitivity proof for weak bisimilarity that preserves
-- the size of the first argument iff A is uninhabited.
Transitivity-≈ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-≈ˡ⇔uninhabited : Transitivity-≈ˡ ⇔ ¬ A
size-preserving-transitivity-≈ˡ⇔uninhabited =
Transitivity-≈ˡ ↝⟨ record { to = λ trans {_ _ _ _} p q →
symmetric (trans (symmetric q) (symmetric p))
; from = λ trans {_ _ _ _} p q →
symmetric (trans (symmetric q) (symmetric p))
} ⟩
Transitivity-≈ʳ ↝⟨ size-preserving-transitivity-≈ʳ⇔uninhabited ⟩□
¬ A □
-- There is a transitivity proof for expansion that preserves the size
-- of the first argument iff A is uninhabited.
Transitivity-≳ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → y ≳ z → [ i ] x ≳ z
size-preserving-transitivity-≳ˡ⇔uninhabited : Transitivity-≳ˡ ⇔ ¬ A
size-preserving-transitivity-≳ˡ⇔uninhabited = record
{ to = Transitivity-≳ˡ ↝⟨ _∘ ∼→ ⟩
Transitivity-∼≳ˡ ↝⟨ _⇔_.to size-preserving-transitivity-∼≳ˡ⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≳ˡ □
}
-- There is a fully size-preserving transitivity proof for weak
-- bisimilarity iff A is uninhabited.
Transitivity-≈ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-≈⇔uninhabited : Transitivity-≈ ⇔ ¬ A
size-preserving-transitivity-≈⇔uninhabited = record
{ to = Transitivity-≈ ↝⟨ (λ trans → trans) ⟩
Transitivity-≈ˡ ↝⟨ _⇔_.to size-preserving-transitivity-≈ˡ⇔uninhabited ⟩
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≈ □
}
-- The following two lemmas provide an alternative proof of one
-- direction of the previous lemma (with a small change to one of the
-- types).
-- If there is a transitivity proof for weak bisimilarity that is
-- size-preserving in both arguments, then weak bisimilarity is
-- trivial.
size-preserving-transitivity-≈→trivial :
(∀ {i} x {y z : Delay A ∞} →
[ i ] x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z) →
∀ {i} (x y : Delay A ∞) → [ i ] x ≈ y
size-preserving-transitivity-≈→trivial _≈⟨_⟩ʷ_ x y =
(x ≈⟨ laterʳ (x ∎ʷ) ⟩ʷ
(later (λ { .force → x }) ≈⟨ later (λ { .force → size-preserving-transitivity-≈→trivial _≈⟨_⟩ʷ_ x y }) ⟩ʷ
(later (λ { .force → y }) ≈⟨ laterˡ (y ∎ʷ) ⟩ʷ
(y ∎ʷ))))
where
_∎ʷ = reflexive
-- If there is a transitivity proof for weak bisimilarity that is
-- size-preserving in both arguments, then the carrier type A is not
-- inhabited.
size-preserving-transitivity-≈→uninhabited :
(∀ {i} x {y z : Delay A ∞} →
[ i ] x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z) →
¬ A
size-preserving-transitivity-≈→uninhabited trans x =
now≉never (size-preserving-transitivity-≈→trivial trans (now x) never)
-- There is a fully size-preserving transitivity proof for expansion
-- iff A is uninhabited.
Transitivity-≳ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → [ i ] y ≳ z → [ i ] x ≳ z
size-preserving-transitivity-≳⇔uninhabited : Transitivity-≳ ⇔ ¬ A
size-preserving-transitivity-≳⇔uninhabited = record
{ to = Transitivity-≳ ↝⟨ id ⟩
Transitivity-≳ˡ ↝⟨ _⇔_.to size-preserving-transitivity-≳ˡ⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≳ □
}
-- There is a transitivity-like proof, taking expansion and weak
-- bisimilarity to weak bisimilarity, that preserves the size of the
-- first argument iff A is uninhabited.
Transitivity-≳≈ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-≳≈ˡ⇔uninhabited : Transitivity-≳≈ˡ ⇔ ¬ A
size-preserving-transitivity-≳≈ˡ⇔uninhabited = record
{ to = Transitivity-≳≈ˡ ↝⟨ _∘ ∼→ ⟩
Transitivity-∼≈ˡ ↝⟨ _⇔_.to size-preserving-transitivity-∼≈ˡ⇔uninhabited ⟩
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≳≈ˡ □
}
-- There is a transitivity-like proof, taking expansion and weak
-- bisimilarity to weak bisimilarity, that preserves the size of both
-- arguments iff A is uninhabited.
Transitivity-≳≈ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → [ i ] y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-≳≈⇔uninhabited : Transitivity-≳≈ ⇔ ¬ A
size-preserving-transitivity-≳≈⇔uninhabited = record
{ to = Transitivity-≳≈ ↝⟨ id ⟩
Transitivity-≳≈ˡ ↝⟨ _⇔_.to size-preserving-transitivity-≳≈ˡ⇔uninhabited ⟩
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≳≈ □
}
-- There is a transitivity-like proof, taking weak bisimilarity and
-- the converse of expansion to weak bisimilarity, that preserves the
-- size of the second argument iff A is uninhabited.
Transitivity-≈≲ʳ = ∀ {i} {x y z : Delay A ∞} →
x ≈ y → [ i ] y ≲ z → [ i ] x ≈ z
size-preserving-transitivity-≈≲ʳ⇔uninhabited : Transitivity-≈≲ʳ ⇔ ¬ A
size-preserving-transitivity-≈≲ʳ⇔uninhabited =
Transitivity-≈≲ʳ ↝⟨ record { to = λ trans x≳y y≈z → symmetric (trans (symmetric y≈z) x≳y)
; from = λ trans x≈y y≲z → symmetric (trans y≲z (symmetric x≈y))
} ⟩
Transitivity-≳≈ˡ ↝⟨ size-preserving-transitivity-≳≈ˡ⇔uninhabited ⟩□
¬ A □
-- There is a transitivity-like proof, taking weak bisimilarity and
-- the converse of expansion to weak bisimilarity, that preserves the
-- size of both arguments iff A is uninhabited.
Transitivity-≈≲ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → [ i ] y ≲ z → [ i ] x ≈ z
size-preserving-transitivity-≈≲⇔uninhabited : Transitivity-≈≲ ⇔ ¬ A
size-preserving-transitivity-≈≲⇔uninhabited =
Transitivity-≈≲ ↝⟨ record { to = λ trans x≳y y≈z → symmetric (trans (symmetric y≈z) x≳y)
; from = λ trans x≈y y≲z → symmetric (trans y≲z (symmetric x≈y))
} ⟩
Transitivity-≳≈ ↝⟨ size-preserving-transitivity-≳≈⇔uninhabited ⟩□
¬ A □
-- There is a transitivity-like proof, taking weak bisimilarity and
-- expansion to weak bisimilarity, that preserves the size of the
-- first argument iff A is uninhabited.
Transitivity-≈≳ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → y ≳ z → [ i ] x ≈ z
size-preserving-transitivity-≈≳ˡ⇔uninhabited : Transitivity-≈≳ˡ ⇔ ¬ A
size-preserving-transitivity-≈≳ˡ⇔uninhabited = record
{ to = Transitivity-≈≳ˡ ↝⟨ (λ trans x≈ly → trans x≈ly (laterˡ (reflexive _))) ⟩
Laterʳ⁻¹-≈ ↝⟨ _⇔_.to size-preserving-laterʳ⁻¹-≈⇔uninhabited ⟩
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≈≳ˡ □
}
| 40.564777
| 108
| 0.532262
|
2ebbc63550ca63037c6f1e4213e3e41505a3041d
| 656
|
agda
|
Agda
|
test/Fail/Issue2791.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2791.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2791.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Issue #2791, reported by Ulf 2017-10-05
-- Reported fixed by Victor 2018-08-11
open import Agda.Builtin.Nat
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
IF : Bool → Set → Set → Set
IF true X Y = X
IF false X Y = Y
postulate
F : (A : Set) (x : A) (B : Set) (y : B) → Set
mutual
?b : Bool
?b = _
IFb = IF ?b Nat Bool
?X : IFb
?X = _
?Y : Nat
?Y = _
foo : F Bool true Nat ?Y ≡ F IFb ?X IFb ?X
foo = refl
-- ?Y gets solved with 'true'
error : ?Y + 1 ≡ 3
error = refl
-- Expected failure:
-- Nat != Bool of type Set
-- when checking that the expression refl has type
-- F Bool true Nat ?Y ≡ F IFb ?X IFb ?X
| 16.820513
| 50
| 0.602134
|
0db770dad7b449278dcf4b3e09dc135756884698
| 304
|
agda
|
Agda
|
test/Succeed/fol-theorems/Issue28.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 10
|
2015-09-03T20:54:16.000Z
|
2019-12-03T13:44:25.000Z
|
test/Succeed/fol-theorems/Issue28.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 121
|
2015-01-25T13:22:12.000Z
|
2018-04-22T06:01:44.000Z
|
test/Succeed/fol-theorems/Issue28.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 4
|
2016-05-10T23:06:19.000Z
|
2016-08-03T03:54:55.000Z
|
postulate
D : Set
∃ : (A : D → Set) → Set
vx : D
Q₂ : D → D → Set
postulate
foo : (∃ λ x → Q₂ vx x) → (∃ λ x → Q₂ vx x)
{-# ATP prove foo #-}
-- $ apia Bug.agda
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/Apia/Utils/AgdaAPI/DeBruijn.hs:68
| 20.266667
| 63
| 0.578947
|
30906128a86c09a529accd02e6dd52831f25cd0f
| 140
|
agda
|
Agda
|
test/succeed/builtinInModule.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/succeed/builtinInModule.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/succeed/builtinInModule.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module builtinInModule where
module Int where
postulate I : Set
{-# BUILTIN INTEGER I #-}
primitive primIntegerPlus : I -> I -> I
| 14
| 41
| 0.678571
|
7c5659267dd1d3ee21f73a7286c024107cb8eb91
| 18,156
|
agda
|
Agda
|
Everything.agda
|
sstucki/agda-categories
|
602ed2ae05dd449d77fc299c07a1cdd02ee5b823
|
[
"MIT"
] | null | null | null |
Everything.agda
|
sstucki/agda-categories
|
602ed2ae05dd449d77fc299c07a1cdd02ee5b823
|
[
"MIT"
] | null | null | null |
Everything.agda
|
sstucki/agda-categories
|
602ed2ae05dd449d77fc299c07a1cdd02ee5b823
|
[
"MIT"
] | null | null | null |
import Categories.2-Category
import Categories.2-Functor
import Categories.Adjoint
import Categories.Adjoint.AFT
import Categories.Adjoint.AFT.SolutionSet
import Categories.Adjoint.Alternatives
import Categories.Adjoint.Compose
import Categories.Adjoint.Construction.EilenbergMoore
import Categories.Adjoint.Construction.Kleisli
import Categories.Adjoint.Equivalence
import Categories.Adjoint.Equivalence.Properties
import Categories.Adjoint.Equivalents
import Categories.Adjoint.Instance.0-Truncation
import Categories.Adjoint.Instance.01-Truncation
import Categories.Adjoint.Instance.Core
import Categories.Adjoint.Instance.PathsOf
import Categories.Adjoint.Instance.PosetCore
import Categories.Adjoint.Instance.StrictCore
import Categories.Adjoint.Instance.StrictDiscrete
import Categories.Adjoint.Mate
import Categories.Adjoint.Monadic
import Categories.Adjoint.Monadic.Crude
import Categories.Adjoint.Monadic.Properties
import Categories.Adjoint.Properties
import Categories.Adjoint.RAPL
import Categories.Adjoint.Relative
import Categories.Adjoint.TwoSided
import Categories.Adjoint.TwoSided.Compose
import Categories.Bicategory
import Categories.Bicategory.Bigroupoid
import Categories.Bicategory.Construction.1-Category
import Categories.Bicategory.Construction.Spans
import Categories.Bicategory.Construction.Spans.Properties
import Categories.Bicategory.Extras
import Categories.Bicategory.Instance.Cats
import Categories.Bicategory.Instance.EnrichedCats
import Categories.Bicategory.Monad
import Categories.Bicategory.Monad.Properties
import Categories.Bicategory.Opposite
import Categories.Category
import Categories.Category.BicartesianClosed
import Categories.Category.BinaryProducts
import Categories.Category.CMonoidEnriched
import Categories.Category.Cartesian
import Categories.Category.Cartesian.Bundle
import Categories.Category.Cartesian.Monoidal
import Categories.Category.Cartesian.Properties
import Categories.Category.Cartesian.SymmetricMonoidal
import Categories.Category.CartesianClosed
import Categories.Category.CartesianClosed.Canonical
import Categories.Category.CartesianClosed.Locally
import Categories.Category.CartesianClosed.Locally.Properties
import Categories.Category.CartesianClosed.Properties
import Categories.Category.Closed
import Categories.Category.Cocartesian
import Categories.Category.Cocartesian.Bundle
import Categories.Category.Cocomplete
import Categories.Category.Cocomplete.Finitely
import Categories.Category.Cocomplete.Finitely.Properties
import Categories.Category.Cocomplete.Properties
import Categories.Category.Complete
import Categories.Category.Complete.Finitely
import Categories.Category.Complete.Finitely.Properties
import Categories.Category.Complete.Properties
import Categories.Category.Complete.Properties.Construction
import Categories.Category.Complete.Properties.SolutionSet
import Categories.Category.Concrete
import Categories.Category.Concrete.Properties
import Categories.Category.Construction.0-Groupoid
import Categories.Category.Construction.Adjoints
import Categories.Category.Construction.Arrow
import Categories.Category.Construction.Cocones
import Categories.Category.Construction.Comma
import Categories.Category.Construction.Cones
import Categories.Category.Construction.Coproduct
import Categories.Category.Construction.Core
import Categories.Category.Construction.Cowedges
import Categories.Category.Construction.EilenbergMoore
import Categories.Category.Construction.Elements
import Categories.Category.Construction.EnrichedFunctors
import Categories.Category.Construction.F-Algebras
import Categories.Category.Construction.Fin
import Categories.Category.Construction.Functors
import Categories.Category.Construction.Grothendieck
import Categories.Category.Construction.GroupAsCategory
import Categories.Category.Construction.KanComplex
import Categories.Category.Construction.KaroubiEnvelope
import Categories.Category.Construction.KaroubiEnvelope.Properties
import Categories.Category.Construction.Kleisli
import Categories.Category.Construction.LT-Models
import Categories.Category.Construction.MonoidAsCategory
import Categories.Category.Construction.MonoidalFunctors
import Categories.Category.Construction.Monoids
import Categories.Category.Construction.ObjectRestriction
import Categories.Category.Construction.Path
import Categories.Category.Construction.PathCategory
import Categories.Category.Construction.Presheaves
import Categories.Category.Construction.Properties.Comma
import Categories.Category.Construction.Properties.EilenbergMoore
import Categories.Category.Construction.Properties.Functors
import Categories.Category.Construction.Properties.Kleisli
import Categories.Category.Construction.Properties.Presheaves
import Categories.Category.Construction.Properties.Presheaves.Cartesian
import Categories.Category.Construction.Properties.Presheaves.CartesianClosed
import Categories.Category.Construction.Properties.Presheaves.Complete
import Categories.Category.Construction.Properties.Presheaves.FromCartesianCCC
import Categories.Category.Construction.Pullbacks
import Categories.Category.Construction.SetoidDiscrete
import Categories.Category.Construction.Spans
import Categories.Category.Construction.StrictDiscrete
import Categories.Category.Construction.Thin
import Categories.Category.Construction.TwistedArrow
import Categories.Category.Construction.Wedges
import Categories.Category.Core
import Categories.Category.Dagger
import Categories.Category.Dagger.Construction.Discrete
import Categories.Category.Dagger.Instance.Rels
import Categories.Category.Diagram.Span
import Categories.Category.Discrete
import Categories.Category.Duality
import Categories.Category.Equivalence
import Categories.Category.Equivalence.Preserves
import Categories.Category.Equivalence.Properties
import Categories.Category.Finite
import Categories.Category.Finite.Fin
import Categories.Category.Finite.Fin.Construction.Discrete
import Categories.Category.Finite.Fin.Construction.Poset
import Categories.Category.Finite.Fin.Instance.Parallel
import Categories.Category.Finite.Fin.Instance.Span
import Categories.Category.Finite.Fin.Instance.Triangle
import Categories.Category.Groupoid
import Categories.Category.Groupoid.Properties
import Categories.Category.Helper
import Categories.Category.Indiscrete
import Categories.Category.Instance.Cartesians
import Categories.Category.Instance.Cats
import Categories.Category.Instance.EmptySet
import Categories.Category.Instance.FamilyOfSetoids
import Categories.Category.Instance.FinCatShapes
import Categories.Category.Instance.FinSetoids
import Categories.Category.Instance.Globe
import Categories.Category.Instance.Groupoids
import Categories.Category.Instance.KanComplexes
import Categories.Category.Instance.LawvereTheories
import Categories.Category.Instance.Monoidals
import Categories.Category.Instance.Nat
import Categories.Category.Instance.One
import Categories.Category.Instance.PartialFunctions
import Categories.Category.Instance.PointedSets
import Categories.Category.Instance.Posets
import Categories.Category.Instance.Properties.Cats
import Categories.Category.Instance.Properties.Posets
import Categories.Category.Instance.Properties.Setoids
import Categories.Category.Instance.Properties.Setoids.CCC
import Categories.Category.Instance.Properties.Setoids.Cocomplete
import Categories.Category.Instance.Properties.Setoids.Complete
import Categories.Category.Instance.Properties.Setoids.LCCC
import Categories.Category.Instance.Properties.Setoids.Limits.Canonical
import Categories.Category.Instance.Quivers
import Categories.Category.Instance.Rels
import Categories.Category.Instance.Setoids
import Categories.Category.Instance.Sets
import Categories.Category.Instance.Simplex
import Categories.Category.Instance.SimplicialSet
import Categories.Category.Instance.SimplicialSet.Properties
import Categories.Category.Instance.SingletonSet
import Categories.Category.Instance.Span
import Categories.Category.Instance.StrictCats
import Categories.Category.Instance.StrictGroupoids
import Categories.Category.Instance.Zero
import Categories.Category.Inverse
import Categories.Category.Lift
import Categories.Category.Monoidal
import Categories.Category.Monoidal.Braided
import Categories.Category.Monoidal.Braided.Properties
import Categories.Category.Monoidal.Bundle
import Categories.Category.Monoidal.Closed
import Categories.Category.Monoidal.Closed.IsClosed
import Categories.Category.Monoidal.Closed.IsClosed.Diagonal
import Categories.Category.Monoidal.Closed.IsClosed.Dinatural
import Categories.Category.Monoidal.Closed.IsClosed.Identity
import Categories.Category.Monoidal.Closed.IsClosed.L
import Categories.Category.Monoidal.Closed.IsClosed.Pentagon
import Categories.Category.Monoidal.CompactClosed
import Categories.Category.Monoidal.Construction.Minus2
import Categories.Category.Monoidal.Construction.Product
import Categories.Category.Monoidal.Core
import Categories.Category.Monoidal.Instance.Cats
import Categories.Category.Monoidal.Instance.One
import Categories.Category.Monoidal.Instance.Rels
import Categories.Category.Monoidal.Instance.Setoids
import Categories.Category.Monoidal.Instance.Sets
import Categories.Category.Monoidal.Instance.StrictCats
import Categories.Category.Monoidal.Interchange
import Categories.Category.Monoidal.Interchange.Braided
import Categories.Category.Monoidal.Interchange.Symmetric
import Categories.Category.Monoidal.Properties
import Categories.Category.Monoidal.Reasoning
import Categories.Category.Monoidal.Rigid
import Categories.Category.Monoidal.Star-Autonomous
import Categories.Category.Monoidal.Symmetric
import Categories.Category.Monoidal.Traced
import Categories.Category.Monoidal.Utilities
import Categories.Category.Product
import Categories.Category.Product.Properties
import Categories.Category.Regular
import Categories.Category.Restriction
import Categories.Category.Restriction.Construction.Trivial
import Categories.Category.Restriction.Instance.PartialFunctions
import Categories.Category.Restriction.Properties
import Categories.Category.RigCategory
import Categories.Category.Site
import Categories.Category.Slice
import Categories.Category.Slice.Properties
import Categories.Category.Species
import Categories.Category.Species.Constructions
import Categories.Category.SubCategory
import Categories.Category.Topos
import Categories.Category.Unbundled
import Categories.Category.Unbundled.Properties
import Categories.Category.Unbundled.Utilities
import Categories.CoYoneda
import Categories.Comonad
import Categories.Comonad.Relative
import Categories.Diagram.Cocone
import Categories.Diagram.Cocone.Properties
import Categories.Diagram.Coend
import Categories.Diagram.Coend.Properties
import Categories.Diagram.Coequalizer
import Categories.Diagram.Coequalizer.Properties
import Categories.Diagram.Colimit
import Categories.Diagram.Colimit.DualProperties
import Categories.Diagram.Colimit.Lan
import Categories.Diagram.Colimit.Properties
import Categories.Diagram.Cone
import Categories.Diagram.Cone.Properties
import Categories.Diagram.Cowedge
import Categories.Diagram.Cowedge.Properties
import Categories.Diagram.Duality
import Categories.Diagram.End
import Categories.Diagram.End.Properties
import Categories.Diagram.Equalizer
import Categories.Diagram.Equalizer.Indexed
import Categories.Diagram.Equalizer.Limit
import Categories.Diagram.Equalizer.Properties
import Categories.Diagram.Finite
import Categories.Diagram.KernelPair
import Categories.Diagram.Limit
import Categories.Diagram.Limit.Properties
import Categories.Diagram.Limit.Ran
import Categories.Diagram.Pullback
import Categories.Diagram.Pullback.Limit
import Categories.Diagram.Pullback.Properties
import Categories.Diagram.Pushout
import Categories.Diagram.Pushout.Properties
import Categories.Diagram.ReflexivePair
import Categories.Diagram.SubobjectClassifier
import Categories.Diagram.Wedge
import Categories.Diagram.Wedge.Properties
import Categories.Enriched.Category
import Categories.Enriched.Category.Opposite
import Categories.Enriched.Category.Underlying
import Categories.Enriched.Functor
import Categories.Enriched.NaturalTransformation
import Categories.Enriched.NaturalTransformation.NaturalIsomorphism
import Categories.Enriched.Over.One
import Categories.Enriched.Over.Setoids
import Categories.Functor
import Categories.Functor.Algebra
import Categories.Functor.Bifunctor
import Categories.Functor.Bifunctor.Properties
import Categories.Functor.Cartesian
import Categories.Functor.Cartesian.Properties
import Categories.Functor.Coalgebra
import Categories.Functor.Construction.Constant
import Categories.Functor.Construction.Diagonal
import Categories.Functor.Construction.FromDiscrete
import Categories.Functor.Construction.LiftSetoids
import Categories.Functor.Construction.Limit
import Categories.Functor.Construction.ObjectRestriction
import Categories.Functor.Construction.PathsOf
import Categories.Functor.Construction.SubCategory
import Categories.Functor.Construction.SubCategory.Properties
import Categories.Functor.Construction.Zero
import Categories.Functor.Core
import Categories.Functor.Duality
import Categories.Functor.Equivalence
import Categories.Functor.Fibration
import Categories.Functor.Groupoid
import Categories.Functor.Hom
import Categories.Functor.Hom.Properties
import Categories.Functor.Hom.Properties.Contra
import Categories.Functor.Hom.Properties.Covariant
import Categories.Functor.IdentityOnObjects
import Categories.Functor.Instance.0-Truncation
import Categories.Functor.Instance.01-Truncation
import Categories.Functor.Instance.Core
import Categories.Functor.Instance.Discrete
import Categories.Functor.Instance.SetoidDiscrete
import Categories.Functor.Instance.StrictCore
import Categories.Functor.Instance.Twisted
import Categories.Functor.Instance.UnderlyingQuiver
import Categories.Functor.Limits
import Categories.Functor.Monoidal
import Categories.Functor.Monoidal.Braided
import Categories.Functor.Monoidal.Construction.Product
import Categories.Functor.Monoidal.Properties
import Categories.Functor.Monoidal.Symmetric
import Categories.Functor.Monoidal.Tensor
import Categories.Functor.Power
import Categories.Functor.Power.Functorial
import Categories.Functor.Power.NaturalTransformation
import Categories.Functor.Presheaf
import Categories.Functor.Profunctor
import Categories.Functor.Properties
import Categories.Functor.Representable
import Categories.Functor.Restriction
import Categories.Functor.Slice
import Categories.GlobularSet
import Categories.Kan
import Categories.Kan.Duality
import Categories.Minus2-Category
import Categories.Minus2-Category.Construction.Indiscrete
import Categories.Minus2-Category.Instance.One
import Categories.Minus2-Category.Properties
import Categories.Monad
import Categories.Monad.Duality
import Categories.Monad.Idempotent
import Categories.Monad.Relative
import Categories.Monad.Strong
import Categories.Morphism
import Categories.Morphism.Cartesian
import Categories.Morphism.Duality
import Categories.Morphism.HeterogeneousIdentity
import Categories.Morphism.HeterogeneousIdentity.Properties
import Categories.Morphism.Idempotent
import Categories.Morphism.Idempotent.Bundles
import Categories.Morphism.IsoEquiv
import Categories.Morphism.Isomorphism
import Categories.Morphism.Normal
import Categories.Morphism.Notation
import Categories.Morphism.Properties
import Categories.Morphism.Reasoning
import Categories.Morphism.Reasoning.Core
import Categories.Morphism.Reasoning.Iso
import Categories.Morphism.Regular
import Categories.Morphism.Universal
import Categories.Multi.Category.Indexed
import Categories.NaturalTransformation
import Categories.NaturalTransformation.Core
import Categories.NaturalTransformation.Dinatural
import Categories.NaturalTransformation.Equivalence
import Categories.NaturalTransformation.Extranatural
import Categories.NaturalTransformation.Hom
import Categories.NaturalTransformation.Monoidal
import Categories.NaturalTransformation.Monoidal.Braided
import Categories.NaturalTransformation.Monoidal.Symmetric
import Categories.NaturalTransformation.NaturalIsomorphism
import Categories.NaturalTransformation.NaturalIsomorphism.Equivalence
import Categories.NaturalTransformation.NaturalIsomorphism.Functors
import Categories.NaturalTransformation.NaturalIsomorphism.Monoidal
import Categories.NaturalTransformation.NaturalIsomorphism.Monoidal.Braided
import Categories.NaturalTransformation.NaturalIsomorphism.Monoidal.Symmetric
import Categories.NaturalTransformation.NaturalIsomorphism.Properties
import Categories.NaturalTransformation.Properties
import Categories.Object.Biproduct
import Categories.Object.Cokernel
import Categories.Object.Coproduct
import Categories.Object.Duality
import Categories.Object.Exponential
import Categories.Object.Initial
import Categories.Object.Kernel
import Categories.Object.Kernel.Properties
import Categories.Object.Monoid
import Categories.Object.NaturalNumber
import Categories.Object.NaturalNumber.Properties.F-Algebras
import Categories.Object.Product
import Categories.Object.Product.Construction
import Categories.Object.Product.Core
import Categories.Object.Product.Indexed
import Categories.Object.Product.Indexed.Properties
import Categories.Object.Product.Limit
import Categories.Object.Product.Morphisms
import Categories.Object.Subobject
import Categories.Object.Subobject.Properties
import Categories.Object.Terminal
import Categories.Object.Terminal.Limit
import Categories.Object.Zero
import Categories.Pseudofunctor
import Categories.Pseudofunctor.Composition
import Categories.Pseudofunctor.Hom
import Categories.Pseudofunctor.Identity
import Categories.Pseudofunctor.Instance.EnrichedUnderlying
import Categories.Tactic.Category
import Categories.Theory.Lawvere
import Categories.Theory.Lawvere.Instance.Identity
import Categories.Theory.Lawvere.Instance.Triv
import Categories.Utils.EqReasoning
import Categories.Utils.Product
import Categories.Yoneda
import Categories.Yoneda.Continuous
import Categories.Yoneda.Properties
import Data.Quiver
import Data.Quiver.Morphism
import Data.Quiver.Paths
import Relation.Binary.PropositionalEquality.Subst.Properties
| 44.609337
| 78
| 0.892267
|
8b30ce12150aa29ab4ebd3259fc4754b2af6963b
| 242
|
agda
|
Agda
|
prototyping/Properties.agda
|
morgoth990/luau
|
dbdf91f3cad8ea9e881b8cf99931f654faf65c2e
|
[
"MIT"
] | 1
|
2022-03-18T04:10:20.000Z
|
2022-03-18T04:10:20.000Z
|
prototyping/Properties.agda
|
morgoth990/luau
|
dbdf91f3cad8ea9e881b8cf99931f654faf65c2e
|
[
"MIT"
] | null | null | null |
prototyping/Properties.agda
|
morgoth990/luau
|
dbdf91f3cad8ea9e881b8cf99931f654faf65c2e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting #-}
module Properties where
import Properties.Contradiction
import Properties.Dec
import Properties.Equality
import Properties.Remember
import Properties.Step
import Properties.StrictMode
import Properties.TypeCheck
| 20.166667
| 31
| 0.842975
|
fde4d608d512dd5a528403d560428d57bc6b628b
| 3,431
|
agda
|
Agda
|
theorems/homotopy/RibbonCover.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
theorems/homotopy/RibbonCover.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
theorems/homotopy/RibbonCover.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
{-
Ribbon is an explicit covering space construction.
This construction is given by Daniel Grayson, Favonia
and Guillaume Brunerie together.
-}
open import HoTT
-- A is the pointed base space.
-- El is intended to be a (group-)set,
module homotopy.RibbonCover {i : ULevel} where
-- The HIT ribbon---reconstructed covering space
module _ (X : Ptd i) {j} (gs : GroupSet (πS 0 X) j) (a₂ : de⊙ X) where
private
A = de⊙ X
a₁ = pt X
El = GroupSet.El gs
El-level = GroupSet.El-level gs
infix 80 _⊙_
_⊙_ = GroupSet.act gs
RibbonSet : Type (lmax i j)
RibbonSet = El × (a₁ =₀ a₂)
data RibbonRel : RibbonSet → RibbonSet → Type (lmax i j) where
ribbon-rel : ∀ el loop (p : a₁ =₀ a₂)
→ RibbonRel (el ⊙ loop , p) (el , loop ∙₀ p)
Ribbon : Type (lmax i j)
Ribbon = SetQuot RibbonRel
module _ {X : Ptd i} {j} {gs : GroupSet (πS 0 X) j} {a₂ : de⊙ X} where
private
A = de⊙ X
a = pt X
El = GroupSet.El gs
El-level = GroupSet.El-level gs
infix 80 _⊙_
_⊙_ = GroupSet.act gs
-- A point in the fiber [a₂].
{-
[e] is a point in the [fiber a], and
[p] is a path to transport [y] to fiber [a₂].
-}
trace : El → a =₀ a₂ → Ribbon X gs a₂
trace el p = q[ el , p ]
{-
A loop based at [a] can used as a group action
or for concatination. Both should be equivalent.
-}
paste : ∀ el loop (p : a =₀ a₂) → trace (el ⊙ loop) p == trace el (loop ∙₀ p)
paste el loop p = quot-rel (ribbon-rel el loop p)
{-
Make each fiber a set and cancel all higher structures
due to [paste].
-}
Ribbon-level : is-set (Ribbon X gs a₂)
Ribbon-level = SetQuot-level
Ribbon-is-set = Ribbon-level
-- Elimination rules.
module RibbonElim {j} {P : Ribbon X gs a₂ → Type j}
(P-level : ∀ r → is-set (P r))
(trace* : ∀ el p → P (trace el p))
(paste* : ∀ el loop p
→ trace* (el ⊙ loop) p == trace* el (loop ∙₀ p)
[ P ↓ paste el loop p ]) where
private
q[_]* : (α : RibbonSet X gs a₂) → P q[ α ]
q[ el , p ]* = trace* el p
rel* : ∀ {α₁ α₂} (r : RibbonRel X gs a₂ α₁ α₂) → q[ α₁ ]* == q[ α₂ ]* [ P ↓ quot-rel r ]
rel* (ribbon-rel el loop p) = paste* el loop p
module M = SetQuotElim P-level q[_]* rel*
f : Π (Ribbon X gs a₂) P
f = M.f
open RibbonElim public using () renaming (f to Ribbon-elim)
module RibbonRec {j} {P : Type j}
(P-level : is-set P)
(trace* : ∀ el p → P)
(paste* : ∀ el loop p
→ trace* (el ⊙ loop) p == trace* el (loop ∙₀ p)) where
private
module M = RibbonElim (λ _ → P-level) trace*
(λ el loop p → ↓-cst-in (paste* el loop p))
f : Ribbon X gs a₂ → P
f = M.f
open RibbonRec public using () renaming (f to Ribbon-rec)
-- This data structure gives a cover.
Ribbon-cover : ∀ (X : Ptd i) {j} (gs : GroupSet (πS 0 X) j)
→ Cover (de⊙ X) (lmax i j)
Ribbon-cover X gs = record
{ Fiber = Ribbon X gs
; Fiber-level = λ a → Ribbon-level
}
transp-trace : ∀ {A : Type i} {a₁} {j}
{gs : GroupSet (πS 0 ⊙[ A , a₁ ]) j}
{a₂} (q : a₁ == a₂) y p
→ transport (Ribbon ⊙[ A , a₁ ] gs) q (trace y p) == trace y (p ∙₀ [ q ])
transp-trace idp y p = ap (trace y) $ ! $ ∙₀-unit-r p
| 28.591667
| 96
| 0.537161
|
0dbcbcf515a4a6afd3f11e9f5546c7164a7591f3
| 14,413
|
agda
|
Agda
|
Cubical/Algebra/CommRing/Properties.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Properties.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Properties.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.GroupoidLaws hiding (_⁻¹)
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Path
open import Cubical.Data.Sigma
open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; _^_ to _^ℕ_
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Structures.Macro
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing.Base
open import Cubical.HITs.PropositionalTruncation
private
variable
ℓ ℓ' ℓ'' : Level
module Units (R' : CommRing ℓ) where
open CommRingStr (snd R')
open RingTheory (CommRing→Ring R')
private R = fst R'
inverseUniqueness : (r : R) → isProp (Σ[ r' ∈ R ] r · r' ≡ 1r)
inverseUniqueness r (r' , rr'≡1) (r'' , rr''≡1) = Σ≡Prop (λ _ → is-set _ _) path
where
path : r' ≡ r''
path = r' ≡⟨ sym (·Rid _) ⟩
r' · 1r ≡⟨ cong (r' ·_) (sym rr''≡1) ⟩
r' · (r · r'') ≡⟨ ·Assoc _ _ _ ⟩
(r' · r) · r'' ≡⟨ cong (_· r'') (·Comm _ _) ⟩
(r · r') · r'' ≡⟨ cong (_· r'') rr'≡1 ⟩
1r · r'' ≡⟨ ·Lid _ ⟩
r'' ∎
Rˣ : ℙ R
Rˣ r = (Σ[ r' ∈ R ] r · r' ≡ 1r) , inverseUniqueness r
-- some notation using instance arguments
_⁻¹ : (r : R) → ⦃ r ∈ Rˣ ⦄ → R
_⁻¹ r ⦃ r∈Rˣ ⦄ = r∈Rˣ .fst
infix 9 _⁻¹
-- some results about inverses
·-rinv : (r : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ → r · r ⁻¹ ≡ 1r
·-rinv r ⦃ r∈Rˣ ⦄ = r∈Rˣ .snd
·-linv : (r : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ → r ⁻¹ · r ≡ 1r
·-linv r ⦃ r∈Rˣ ⦄ = ·Comm _ _ ∙ r∈Rˣ .snd
RˣMultClosed : (r r' : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ ⦃ r'∈Rˣ : r' ∈ Rˣ ⦄
→ (r · r') ∈ Rˣ
RˣMultClosed r r' = (r ⁻¹ · r' ⁻¹) , path
where
path : r · r' · (r ⁻¹ · r' ⁻¹) ≡ 1r
path = r · r' · (r ⁻¹ · r' ⁻¹) ≡⟨ cong (_· (r ⁻¹ · r' ⁻¹)) (·Comm _ _) ⟩
r' · r · (r ⁻¹ · r' ⁻¹) ≡⟨ ·Assoc _ _ _ ⟩
r' · r · r ⁻¹ · r' ⁻¹ ≡⟨ cong (_· r' ⁻¹) (sym (·Assoc _ _ _)) ⟩
r' · (r · r ⁻¹) · r' ⁻¹ ≡⟨ cong (λ x → r' · x · r' ⁻¹) (·-rinv _) ⟩
r' · 1r · r' ⁻¹ ≡⟨ cong (_· r' ⁻¹) (·Rid _) ⟩
r' · r' ⁻¹ ≡⟨ ·-rinv _ ⟩
1r ∎
RˣContainsOne : 1r ∈ Rˣ
RˣContainsOne = 1r , ·Lid _
RˣInvClosed : (r : R) ⦃ _ : r ∈ Rˣ ⦄ → r ⁻¹ ∈ Rˣ
RˣInvClosed r = r , ·-linv _
UnitsAreNotZeroDivisors : (r : R) ⦃ _ : r ∈ Rˣ ⦄
→ ∀ r' → r' · r ≡ 0r → r' ≡ 0r
UnitsAreNotZeroDivisors r r' p = r' ≡⟨ sym (·Rid _) ⟩
r' · 1r ≡⟨ cong (r' ·_) (sym (·-rinv _)) ⟩
r' · (r · r ⁻¹) ≡⟨ ·Assoc _ _ _ ⟩
r' · r · r ⁻¹ ≡⟨ cong (_· r ⁻¹) p ⟩
0r · r ⁻¹ ≡⟨ 0LeftAnnihilates _ ⟩
0r ∎
-- laws keeping the instance arguments
1⁻¹≡1 : ⦃ 1∈Rˣ' : 1r ∈ Rˣ ⦄ → 1r ⁻¹ ≡ 1r
1⁻¹≡1 ⦃ 1∈Rˣ' ⦄ = (sym (·Lid _)) ∙ 1∈Rˣ' .snd
⁻¹-dist-· : (r r' : R) ⦃ r∈Rˣ : r ∈ Rˣ ⦄ ⦃ r'∈Rˣ : r' ∈ Rˣ ⦄ ⦃ rr'∈Rˣ : (r · r') ∈ Rˣ ⦄
→ (r · r') ⁻¹ ≡ r ⁻¹ · r' ⁻¹
⁻¹-dist-· r r' ⦃ r∈Rˣ ⦄ ⦃ r'∈Rˣ ⦄ ⦃ rr'∈Rˣ ⦄ =
sym path ∙∙ cong (r ⁻¹ · r' ⁻¹ ·_) (rr'∈Rˣ .snd) ∙∙ (·Rid _)
where
path : r ⁻¹ · r' ⁻¹ · (r · r' · (r · r') ⁻¹) ≡ (r · r') ⁻¹
path = r ⁻¹ · r' ⁻¹ · (r · r' · (r · r') ⁻¹)
≡⟨ ·Assoc _ _ _ ⟩
r ⁻¹ · r' ⁻¹ · (r · r') · (r · r') ⁻¹
≡⟨ cong (λ x → r ⁻¹ · r' ⁻¹ · x · (r · r') ⁻¹) (·Comm _ _) ⟩
r ⁻¹ · r' ⁻¹ · (r' · r) · (r · r') ⁻¹
≡⟨ cong (_· (r · r') ⁻¹) (sym (·Assoc _ _ _)) ⟩
r ⁻¹ · (r' ⁻¹ · (r' · r)) · (r · r') ⁻¹
≡⟨ cong (λ x → r ⁻¹ · x · (r · r') ⁻¹) (·Assoc _ _ _) ⟩
r ⁻¹ · (r' ⁻¹ · r' · r) · (r · r') ⁻¹
≡⟨ cong (λ x → r ⁻¹ · (x · r) · (r · r') ⁻¹) (·-linv _) ⟩
r ⁻¹ · (1r · r) · (r · r') ⁻¹
≡⟨ cong (λ x → r ⁻¹ · x · (r · r') ⁻¹) (·Lid _) ⟩
r ⁻¹ · r · (r · r') ⁻¹
≡⟨ cong (_· (r · r') ⁻¹) (·-linv _) ⟩
1r · (r · r') ⁻¹
≡⟨ ·Lid _ ⟩
(r · r') ⁻¹ ∎
unitCong : {r r' : R} → r ≡ r' → ⦃ r∈Rˣ : r ∈ Rˣ ⦄ ⦃ r'∈Rˣ : r' ∈ Rˣ ⦄ → r ⁻¹ ≡ r' ⁻¹
unitCong {r = r} {r' = r'} p ⦃ r∈Rˣ ⦄ ⦃ r'∈Rˣ ⦄ =
PathPΣ (inverseUniqueness r' (r ⁻¹ , subst (λ x → x · r ⁻¹ ≡ 1r) p (r∈Rˣ .snd)) r'∈Rˣ) .fst
⁻¹-eq-elim : {r r' r'' : R} ⦃ r∈Rˣ : r ∈ Rˣ ⦄ → r' ≡ r'' · r → r' · r ⁻¹ ≡ r''
⁻¹-eq-elim {r = r} {r'' = r''} p = cong (_· r ⁻¹) p
∙ sym (·Assoc _ _ _)
∙ cong (r'' ·_) (·-rinv _)
∙ ·Rid _
-- some convenient notation
_ˣ : (R' : CommRing ℓ) → ℙ (R' .fst)
R' ˣ = Units.Rˣ R'
module _ where
open RingHoms
idCommRingHom : (R : CommRing ℓ) → CommRingHom R R
idCommRingHom R = idRingHom (CommRing→Ring R)
compCommRingHom : (R : CommRing ℓ) (S : CommRing ℓ') (T : CommRing ℓ'')
→ CommRingHom R S → CommRingHom S T → CommRingHom R T
compCommRingHom R S T = compRingHom {R = CommRing→Ring R} {CommRing→Ring S} {CommRing→Ring T}
_∘cr_ : {R : CommRing ℓ} {S : CommRing ℓ'} {T : CommRing ℓ''}
→ CommRingHom S T → CommRingHom R S → CommRingHom R T
g ∘cr f = compCommRingHom _ _ _ f g
compIdCommRingHom : {R S : CommRing ℓ} (f : CommRingHom R S)
→ compCommRingHom _ _ _ (idCommRingHom R) f ≡ f
compIdCommRingHom = compIdRingHom
idCompCommRingHom : {R S : CommRing ℓ} (f : CommRingHom R S)
→ compCommRingHom _ _ _ f (idCommRingHom S) ≡ f
idCompCommRingHom = idCompRingHom
compAssocCommRingHom : {R S T U : CommRing ℓ}
(f : CommRingHom R S) (g : CommRingHom S T) (h : CommRingHom T U)
→ compCommRingHom _ _ _ (compCommRingHom _ _ _ f g) h
≡ compCommRingHom _ _ _ f (compCommRingHom _ _ _ g h)
compAssocCommRingHom = compAssocRingHom
open Iso
injCommRingIso : {R : CommRing ℓ} {S : CommRing ℓ'} (f : CommRingIso R S)
→ (x y : R .fst) → f .fst .fun x ≡ f .fst .fun y → x ≡ y
injCommRingIso f x y h = sym (f .fst .leftInv x) ∙∙ cong (f .fst .inv) h ∙∙ f .fst .leftInv y
module CommRingEquivs where
open RingEquivs
compCommRingEquiv : {A : CommRing ℓ} {B : CommRing ℓ'} {C : CommRing ℓ''}
→ CommRingEquiv A B → CommRingEquiv B C → CommRingEquiv A C
compCommRingEquiv {A = A} {B = B} {C = C} = compRingEquiv {A = CommRing→Ring A}
{B = CommRing→Ring B}
{C = CommRing→Ring C}
invCommRingEquiv : (A : CommRing ℓ) → (B : CommRing ℓ') → CommRingEquiv A B → CommRingEquiv B A
fst (invCommRingEquiv A B e) = invEquiv (fst e)
snd (invCommRingEquiv A B e) = isRingHomInv e
module CommRingHomTheory {A' B' : CommRing ℓ} (φ : CommRingHom A' B') where
open Units A' renaming (Rˣ to Aˣ ; _⁻¹ to _⁻¹ᵃ ; ·-rinv to ·A-rinv ; ·-linv to ·A-linv)
private A = fst A'
open CommRingStr (snd A') renaming (_·_ to _·A_ ; 1r to 1a)
open Units B' renaming (Rˣ to Bˣ ; _⁻¹ to _⁻¹ᵇ ; ·-rinv to ·B-rinv)
open CommRingStr (snd B') renaming ( _·_ to _·B_ ; 1r to 1b
; ·Lid to ·B-lid ; ·Rid to ·B-rid
; ·Assoc to ·B-assoc)
private
f = fst φ
open IsRingHom (φ .snd)
RingHomRespInv : (r : A) ⦃ r∈Aˣ : r ∈ Aˣ ⦄ → f r ∈ Bˣ
RingHomRespInv r = f (r ⁻¹ᵃ) , (sym (pres· r (r ⁻¹ᵃ)) ∙∙ cong (f) (·A-rinv r) ∙∙ pres1)
φ[x⁻¹]≡φ[x]⁻¹ : (r : A) ⦃ r∈Aˣ : r ∈ Aˣ ⦄ ⦃ φr∈Bˣ : f r ∈ Bˣ ⦄
→ f (r ⁻¹ᵃ) ≡ (f r) ⁻¹ᵇ
φ[x⁻¹]≡φ[x]⁻¹ r ⦃ r∈Aˣ ⦄ ⦃ φr∈Bˣ ⦄ =
f (r ⁻¹ᵃ) ≡⟨ sym (·B-rid _) ⟩
f (r ⁻¹ᵃ) ·B 1b ≡⟨ cong (f (r ⁻¹ᵃ) ·B_) (sym (·B-rinv _)) ⟩
f (r ⁻¹ᵃ) ·B ((f r) ·B (f r) ⁻¹ᵇ) ≡⟨ ·B-assoc _ _ _ ⟩
f (r ⁻¹ᵃ) ·B (f r) ·B (f r) ⁻¹ᵇ ≡⟨ cong (_·B (f r) ⁻¹ᵇ) (sym (pres· _ _)) ⟩
f (r ⁻¹ᵃ ·A r) ·B (f r) ⁻¹ᵇ ≡⟨ cong (λ x → f x ·B (f r) ⁻¹ᵇ) (·A-linv _) ⟩
f 1a ·B (f r) ⁻¹ᵇ ≡⟨ cong (_·B (f r) ⁻¹ᵇ) (pres1) ⟩
1b ·B (f r) ⁻¹ᵇ ≡⟨ ·B-lid _ ⟩
(f r) ⁻¹ᵇ ∎
module Exponentiation (R' : CommRing ℓ) where
open CommRingStr (snd R')
private R = fst R'
-- introduce exponentiation
_^_ : R → ℕ → R
f ^ zero = 1r
f ^ suc n = f · (f ^ n)
infix 9 _^_
-- and prove some laws
1ⁿ≡1 : (n : ℕ) → 1r ^ n ≡ 1r
1ⁿ≡1 zero = refl
1ⁿ≡1 (suc n) = ·Lid _ ∙ 1ⁿ≡1 n
·-of-^-is-^-of-+ : (f : R) (m n : ℕ) → (f ^ m) · (f ^ n) ≡ f ^ (m +ℕ n)
·-of-^-is-^-of-+ f zero n = ·Lid _
·-of-^-is-^-of-+ f (suc m) n = sym (·Assoc _ _ _) ∙ cong (f ·_) (·-of-^-is-^-of-+ f m n)
^-ldist-· : (f g : R) (n : ℕ) → (f · g) ^ n ≡ (f ^ n) · (g ^ n)
^-ldist-· f g zero = sym (·Lid 1r)
^-ldist-· f g (suc n) = path
where
path : f · g · ((f · g) ^ n) ≡ f · (f ^ n) · (g · (g ^ n))
path = f · g · ((f · g) ^ n) ≡⟨ cong (f · g ·_) (^-ldist-· f g n) ⟩
f · g · ((f ^ n) · (g ^ n)) ≡⟨ ·Assoc _ _ _ ⟩
f · g · (f ^ n) · (g ^ n) ≡⟨ cong (_· (g ^ n)) (sym (·Assoc _ _ _)) ⟩
f · (g · (f ^ n)) · (g ^ n) ≡⟨ cong (λ r → (f · r) · (g ^ n)) (·Comm _ _) ⟩
f · ((f ^ n) · g) · (g ^ n) ≡⟨ cong (_· (g ^ n)) (·Assoc _ _ _) ⟩
f · (f ^ n) · g · (g ^ n) ≡⟨ sym (·Assoc _ _ _) ⟩
f · (f ^ n) · (g · (g ^ n)) ∎
^-rdist-·ℕ : (f : R) (n m : ℕ) → f ^ (n ·ℕ m) ≡ (f ^ n) ^ m
^-rdist-·ℕ f zero m = sym (1ⁿ≡1 m)
^-rdist-·ℕ f (suc n) m = sym (·-of-^-is-^-of-+ f m (n ·ℕ m))
∙∙ cong (f ^ m ·_) (^-rdist-·ℕ f n m)
∙∙ sym (^-ldist-· f (f ^ n) m)
-- interaction of exponentiation and units
open Units R'
^-presUnit : ∀ (f : R) (n : ℕ) → f ∈ Rˣ → f ^ n ∈ Rˣ
^-presUnit f zero f∈Rˣ = RˣContainsOne
^-presUnit f (suc n) f∈Rˣ = RˣMultClosed f (f ^ n) ⦃ f∈Rˣ ⦄ ⦃ ^-presUnit f n f∈Rˣ ⦄
-- like in Ring.Properties we provide helpful lemmas here
module CommRingTheory (R' : CommRing ℓ) where
open CommRingStr (snd R')
private R = fst R'
·CommAssocl : (x y z : R) → x · (y · z) ≡ y · (x · z)
·CommAssocl x y z = ·Assoc x y z ∙∙ cong (_· z) (·Comm x y) ∙∙ sym (·Assoc y x z)
·CommAssocr : (x y z : R) → x · y · z ≡ x · z · y
·CommAssocr x y z = sym (·Assoc x y z) ∙∙ cong (x ·_) (·Comm y z) ∙∙ ·Assoc x z y
·CommAssocr2 : (x y z : R) → x · y · z ≡ z · y · x
·CommAssocr2 x y z = ·CommAssocr _ _ _ ∙∙ cong (_· y) (·Comm _ _) ∙∙ ·CommAssocr _ _ _
·CommAssocSwap : (x y z w : R) → (x · y) · (z · w) ≡ (x · z) · (y · w)
·CommAssocSwap x y z w =
·Assoc (x · y) z w ∙∙ cong (_· w) (·CommAssocr x y z) ∙∙ sym (·Assoc (x · z) y w)
-- the CommRing version of uaCompEquiv
module CommRingUAFunctoriality where
open CommRingStr
open CommRingEquivs
CommRing≡ : (A B : CommRing ℓ) → (
Σ[ p ∈ ⟨ A ⟩ ≡ ⟨ B ⟩ ]
Σ[ q0 ∈ PathP (λ i → p i) (0r (snd A)) (0r (snd B)) ]
Σ[ q1 ∈ PathP (λ i → p i) (1r (snd A)) (1r (snd B)) ]
Σ[ r+ ∈ PathP (λ i → p i → p i → p i) (_+_ (snd A)) (_+_ (snd B)) ]
Σ[ r· ∈ PathP (λ i → p i → p i → p i) (_·_ (snd A)) (_·_ (snd B)) ]
Σ[ s ∈ PathP (λ i → p i → p i) (-_ (snd A)) (-_ (snd B)) ]
PathP (λ i → IsCommRing (q0 i) (q1 i) (r+ i) (r· i) (s i)) (isCommRing (snd A)) (isCommRing (snd B)))
≃ (A ≡ B)
CommRing≡ A B = isoToEquiv theIso
where
open Iso
theIso : Iso _ _
fun theIso (p , q0 , q1 , r+ , r· , s , t) i = p i
, commringstr (q0 i) (q1 i) (r+ i) (r· i) (s i) (t i)
inv theIso x = cong ⟨_⟩ x , cong (0r ∘ snd) x , cong (1r ∘ snd) x
, cong (_+_ ∘ snd) x , cong (_·_ ∘ snd) x , cong (-_ ∘ snd) x , cong (isCommRing ∘ snd) x
rightInv theIso _ = refl
leftInv theIso _ = refl
caracCommRing≡ : {A B : CommRing ℓ} (p q : A ≡ B) → cong ⟨_⟩ p ≡ cong ⟨_⟩ q → p ≡ q
caracCommRing≡ {A = A} {B = B} p q P =
sym (transportTransport⁻ (ua (CommRing≡ A B)) p)
∙∙ cong (transport (ua (CommRing≡ A B))) helper
∙∙ transportTransport⁻ (ua (CommRing≡ A B)) q
where
helper : transport (sym (ua (CommRing≡ A B))) p ≡ transport (sym (ua (CommRing≡ A B))) q
helper = Σ≡Prop
(λ _ → isPropΣ
(isOfHLevelPathP' 1 (is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ λ _ → is-set (snd B)) _ _)
λ _ → isOfHLevelPathP 1 (isPropIsCommRing _ _ _ _ _) _ _)
(transportRefl (cong ⟨_⟩ p) ∙ P ∙ sym (transportRefl (cong ⟨_⟩ q)))
uaCompCommRingEquiv : {A B C : CommRing ℓ} (f : CommRingEquiv A B) (g : CommRingEquiv B C)
→ uaCommRing (compCommRingEquiv f g) ≡ uaCommRing f ∙ uaCommRing g
uaCompCommRingEquiv f g = caracCommRing≡ _ _ (
cong ⟨_⟩ (uaCommRing (compCommRingEquiv f g))
≡⟨ uaCompEquiv _ _ ⟩
cong ⟨_⟩ (uaCommRing f) ∙ cong ⟨_⟩ (uaCommRing g)
≡⟨ sym (cong-∙ ⟨_⟩ (uaCommRing f) (uaCommRing g)) ⟩
cong ⟨_⟩ (uaCommRing f ∙ uaCommRing g) ∎)
open CommRingEquivs
open CommRingUAFunctoriality
recPT→CommRing : {A : Type ℓ'} (𝓕 : A → CommRing ℓ)
→ (σ : ∀ x y → CommRingEquiv (𝓕 x) (𝓕 y))
→ (∀ x y z → σ x z ≡ compCommRingEquiv (σ x y) (σ y z))
------------------------------------------------------
→ ∥ A ∥ → CommRing ℓ
recPT→CommRing 𝓕 σ compCoh = GpdElim.rec→Gpd isGroupoidCommRing 𝓕
(3-ConstantCompChar 𝓕 (λ x y → uaCommRing (σ x y))
λ x y z → sym ( cong uaCommRing (compCoh x y z)
∙ uaCompCommRingEquiv (σ x y) (σ y z)))
| 41.18
| 105
| 0.472976
|
7cfbd97bd7fc01bfe8a543c9d4e1309862f4f3ce
| 3,118
|
agda
|
Agda
|
Cubical/Homotopy/Group/Pi4S3/Summary.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Homotopy/Group/Pi4S3/Summary.agda
|
snu-development/cubical
|
58f2d0dd07e51f8aa5b348a522691097b6695d1c
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Group/Pi4S3/Summary.agda
|
snu-development/cubical
|
58f2d0dd07e51f8aa5b348a522691097b6695d1c
|
[
"MIT"
] | null | null | null |
{-
This file contains a summary of the proof that π₄(S³) ≡ ℤ/2ℤ
The --experimental-lossy-unification flag is used to speed up type checking.
The file still type checks without it, but it's a lot slower (about 10 times).
-}
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.Group.Pi4S3.Summary where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Data.Nat.Base
open import Cubical.Data.Sigma.Base
open import Cubical.HITs.Sn
open import Cubical.HITs.SetTruncation
open import Cubical.Homotopy.HopfInvariant.Base
open import Cubical.Homotopy.HopfInvariant.Homomorphism
open import Cubical.Homotopy.HopfInvariant.HopfMap
open import Cubical.Homotopy.HopfInvariant.Brunerie
open import Cubical.Homotopy.Whitehead
open import Cubical.Homotopy.Group.Base hiding (π)
open import Cubical.Homotopy.Group.Pi3S2
open import Cubical.Homotopy.Group.Pi4S3.BrunerieNumber
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Instances.Bool
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.GroupPath
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Int
open import Cubical.Algebra.Group.Instances.IntMod
open import Cubical.Algebra.Group.ZAction
-- Homotopy groups (shifted version of π'Gr to get nicer numbering)
π : ℕ → Pointed₀ → Group₀
π n X = π'Gr (predℕ n) X
-- Nicer notation for the spheres (as pointed types)
𝕊² 𝕊³ : Pointed₀
𝕊² = S₊∙ 2
𝕊³ = S₊∙ 3
-- The Brunerie number; defined in Cubical.Homotopy.Group.Pi4S3.BrunerieNumber
-- as "abs (HopfInvariant-π' 0 ([ (∣ idfun∙ _ ∣₂ , ∣ idfun∙ _ ∣₂) ]×))"
β : ℕ
β = Brunerie
-- The connection to π₄(S³) is then also proved in the BrunerieNumber
-- file following Corollary 3.4.5 in Guillaume Brunerie's PhD thesis.
βSpec : GroupEquiv (π 4 𝕊³) (ℤ/ β)
βSpec = BrunerieIso
-- Ideally one could prove that β is 2 by normalization, but this does
-- not seem to terminate before we run out of memory. To try normalize
-- this use "C-u C-c C-n β≡2" (which normalizes the term, ignoring
-- abstract's). So instead we prove this by hand as in the second half
-- of Guillaume's thesis.
β≡2 : β ≡ 2
β≡2 = Brunerie≡2
-- This involves a lot of theory, for example that π₃(S²) ≃ ℤ where
-- the underlying map is induced by the Hopf invariant (which involves
-- the cup product on cohomology).
_ : GroupEquiv (π 3 𝕊²) ℤ
_ = hopfInvariantEquiv
-- Which is a consequence of the fact that π₃(S²) is generated by the
-- Hopf map.
_ : gen₁-by (π 3 𝕊²) ∣ HopfMap ∣₂
_ = π₂S³-gen-by-HopfMap
-- etc. For more details see the proof of "Brunerie≡2".
-- Combining all of this gives us the desired equivalence of groups:
π₄S³≃ℤ/2ℤ : GroupEquiv (π 4 𝕊³) (ℤ/ 2)
π₄S³≃ℤ/2ℤ = subst (GroupEquiv (π 4 𝕊³)) (cong ℤ/_ β≡2) βSpec
-- By the SIP this induces an equality of groups:
π₄S³≡ℤ/2ℤ : π 4 𝕊³ ≡ ℤ/ 2
π₄S³≡ℤ/2ℤ = GroupPath _ _ .fst π₄S³≃ℤ/2ℤ
-- As a sanity check we also establish the equality with Bool:
π₄S³≡Bool : π 4 𝕊³ ≡ Bool
π₄S³≡Bool = π₄S³≡ℤ/2ℤ ∙ GroupPath _ _ .fst (GroupIso→GroupEquiv ℤ/2≅Bool)
| 31.494949
| 78
| 0.749519
|
3770447b5a9246a211db49fbcd237a10c2a2ef92
| 3,000
|
agda
|
Agda
|
misc/RecursiveDescent/Inductive/Lib.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 7
|
2016-12-13T05:23:14.000Z
|
2021-06-22T05:35:31.000Z
|
misc/RecursiveDescent/Inductive/Lib.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | 1
|
2018-01-22T22:21:41.000Z
|
2018-01-24T16:39:37.000Z
|
misc/RecursiveDescent/Inductive/Lib.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Some defined parsers, collected in a library
------------------------------------------------------------------------
-- Recursive parsers cannot be defined simply as functions, but have
-- to be defined in terms of a grammar.
-- Non-recursive parsers can either be defined directly or by using a
-- grammar. The grammar version may be harder to use in some cases,
-- but has the potential advantage of increased sharing/less memory
-- usage.
module RecursiveDescent.Inductive.Lib (tok : Set) where
open import RecursiveDescent.Index
open import RecursiveDescent.Inductive
open import RecursiveDescent.Inductive.SimpleLib
open import Utilities
open import Data.Bool
open import Data.List
open import Data.Nat
open import Data.Product.Record using (_,_)
open import Data.Product renaming (_,_ to pair)
-- The index of atLeast can only be partly inferred.
atLeast-index : Corners -> ℕ -> Index
atLeast-index c zero = _
atLeast-index c (suc n) = _
private
-- Note that the parsers are parameterised on other parsers.
data NT (nt : ParserType₁) : ParserType₁ where
many : forall {c r} ->
Parser tok nt (false , c) r ->
NT nt _ (List r)
many₁ : forall {c r} ->
Parser tok nt (false , c) r ->
NT nt _ (List r)
atLeast' : forall {c r} (n : ℕ) ->
Parser tok nt (false , c) r ->
NT nt (atLeast-index c n) (List r)
chain≥' : forall {c₁ i₂ r} (n : ℕ) ->
Assoc ->
Parser tok nt (false , c₁) r ->
Parser tok nt i₂ (r -> r -> r) ->
NT nt _ r
Nonterminal : ParserType₁ -> ParserType₁
Nonterminal = NT
module Combinators
{nt} (lib : forall {i r} -> Nonterminal nt i r -> nt i r)
where
infix 55 _⋆ _+
_⋆ : forall {c r} ->
Parser tok nt (false , c) r ->
Parser tok nt _ (List r)
p ⋆ = ! lib (many p)
_+ : forall {c r} ->
Parser tok nt (false , c) r ->
Parser tok nt _ (List r)
p + = ! lib (many₁ p)
-- At least n occurrences of p.
atLeast : forall {c r} (n : ℕ) ->
Parser tok nt (false , c) r ->
Parser tok nt _ (List r)
atLeast n p = ! lib (atLeast' n p)
-- Chains at least n occurrences of op, in an a-associative
-- manner. The ops are surrounded by ps.
chain≥ : forall {c₁ i₂ r} (n : ℕ) ->
Assoc ->
Parser tok nt (false , c₁) r ->
Parser tok nt i₂ (r -> r -> r) ->
Parser tok nt _ r
chain≥ n a p op = ! lib (chain≥' n a p op)
library : forall {i r} -> Nonterminal nt i r -> Parser tok nt i r
library (many p) = return [] ∣ p +
library (many₁ p) = _∷_ <$> p ⊛ p ⋆
library (atLeast' zero p) = p ⋆
library (atLeast' (suc n) p) = _∷_ <$> p ⊛ atLeast n p
library (chain≥' n a p op) = chain≥-combine a <$>
p ⊛ atLeast n (op ⊗! p)
| 31.578947
| 72
| 0.543
|
361dc9bfb991a9738c8247764865ff682c25019e
| 10,582
|
agda
|
Agda
|
src/Univalence-axiom/Isomorphism-is-equality/Monoid.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Univalence-axiom/Isomorphism-is-equality/Monoid.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Univalence-axiom/Isomorphism-is-equality/Monoid.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Isomorphism of monoids on sets coincides with equality (assuming
-- univalence)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- This module has been developed in collaboration with Thierry
-- Coquand.
open import Equality
module Univalence-axiom.Isomorphism-is-equality.Monoid
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Bijection eq using (_↔_; Σ-≡,≡↔≡; ↑↔)
open Derived-definitions-and-properties eq
open import Equivalence eq as Eq using (_≃_)
open import Function-universe eq hiding (id)
open import H-level eq
open import H-level.Closure eq
open import Prelude hiding (id)
open import Univalence-axiom eq
-- Monoid laws (including the assumption that the carrier type is a
-- set).
Is-monoid : (C : Type) → (C → C → C) → C → Type
Is-monoid C _∙_ id =
-- C is a set.
Is-set C ×
-- Left and right identity laws.
(∀ x → (id ∙ x) ≡ x) ×
(∀ x → (x ∙ id) ≡ x) ×
-- Associativity.
(∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z))
-- Monoids (on sets).
Monoid : Type₁
Monoid =
-- Carrier.
Σ Type λ C →
-- Binary operation.
Σ (C → C → C) λ _∙_ →
-- Identity.
Σ C λ id →
-- Laws.
Is-monoid C _∙_ id
-- The carrier type.
Carrier : Monoid → Type
Carrier M = proj₁ M
-- The binary operation.
op : (M : Monoid) → Carrier M → Carrier M → Carrier M
op M = proj₁ (proj₂ M)
-- The identity element.
id : (M : Monoid) → Carrier M
id M = proj₁ (proj₂ (proj₂ M))
-- The monoid laws.
laws : (M : Monoid) → Is-monoid (Carrier M) (op M) (id M)
laws M = proj₂ (proj₂ (proj₂ M))
-- Monoid morphisms.
Is-homomorphism :
(M₁ M₂ : Monoid) → (Carrier M₁ → Carrier M₂) → Type
Is-homomorphism M₁ M₂ f =
(∀ x y → f (op M₁ x y) ≡ op M₂ (f x) (f y)) ×
(f (id M₁) ≡ id M₂)
-- Monoid isomorphisms.
_≅_ : Monoid → Monoid → Type
M₁ ≅ M₂ =
Σ (Carrier M₁ ↔ Carrier M₂) λ f →
Is-homomorphism M₁ M₂ (_↔_.to f)
-- The monoid laws are propositional (assuming extensionality).
laws-propositional :
Extensionality (# 0) (# 0) →
(M : Monoid) →
Is-proposition (Is-monoid (Carrier M) (op M) (id M))
laws-propositional ext M =
×-closure 1 (H-level-propositional ext 2)
(×-closure 1 (Π-closure ext 1 λ _ →
is-set)
(×-closure 1 (Π-closure ext 1 λ _ →
is-set)
(Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
is-set)))
where is-set = proj₁ (laws M)
-- Monoid equality is isomorphic to equality of the carrier sets,
-- binary operations and identity elements, suitably transported
-- (assuming extensionality).
equality-triple-lemma :
Extensionality (# 0) (# 0) →
(M₁ M₂ : Monoid) →
M₁ ≡ M₂ ↔
Σ (Carrier M₁ ≡ Carrier M₂) λ C-eq →
subst (λ C → C → C → C) C-eq (op M₁) ≡ op M₂ ×
subst (λ C → C) C-eq (id M₁) ≡ id M₂
equality-triple-lemma
ext (C₁ , op₁ , id₁ , laws₁) (C₂ , op₂ , id₂ , laws₂) =
((C₁ , op₁ , id₁ , laws₁) ≡ (C₂ , op₂ , id₂ , laws₂)) ↔⟨ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ bij ⟩
(((C₁ , op₁ , id₁) , laws₁) ≡ ((C₂ , op₂ , id₂) , laws₂)) ↝⟨ inverse $ ignore-propositional-component $
laws-propositional ext (C₂ , op₂ , id₂ , laws₂) ⟩
((C₁ , op₁ , id₁) ≡ (C₂ , op₂ , id₂)) ↝⟨ inverse Σ-≡,≡↔≡ ⟩
(Σ (C₁ ≡ C₂) λ C-eq →
subst (λ C → (C → C → C) × C) C-eq (op₁ , id₁) ≡ (op₂ , id₂)) ↝⟨ ∃-cong (λ _ → ≡⇒↝ _ $ cong (λ x → x ≡ _) $
push-subst-, (λ C → C → C → C) (λ C → C)) ⟩
(Σ (C₁ ≡ C₂) λ C-eq →
(subst (λ C → C → C → C) C-eq op₁ , subst (λ C → C) C-eq id₁) ≡
(op₂ , id₂)) ↝⟨ ∃-cong (λ _ → inverse ≡×≡↔≡) ⟩□
(Σ (C₁ ≡ C₂) λ C-eq →
subst (λ C → C → C → C) C-eq op₁ ≡ op₂ ×
subst (λ C → C) C-eq id₁ ≡ id₂) □
where
bij =
(Σ Type λ C → Σ (C → C → C) λ op → Σ C λ id → Is-monoid C op id) ↝⟨ ∃-cong (λ _ → Σ-assoc) ⟩
(Σ Type λ C → Σ ((C → C → C) × C) λ { (op , id) →
Is-monoid C op id }) ↝⟨ Σ-assoc ⟩□
(Σ (Σ Type λ C → (C → C → C) × C) λ { (C , op , id) →
Is-monoid C op id }) □
-- If two monoids are isomorphic, then they are equal (assuming
-- univalence).
isomorphic-equal :
Univalence (# 0) →
Univalence (# 1) →
(M₁ M₂ : Monoid) → M₁ ≅ M₂ → M₁ ≡ M₂
isomorphic-equal univ univ₁ M₁ M₂ (bij , bij-op , bij-id) = goal
where
open _≃_
-- Our goal:
goal : M₁ ≡ M₂
-- Extensionality follows from univalence.
ext : Extensionality (# 0) (# 0)
ext = dependent-extensionality univ₁ univ
-- Hence the goal follows from monoids-equal-if, if we can prove
-- three equalities.
C-eq : Carrier M₁ ≡ Carrier M₂
op-eq : subst (λ A → A → A → A) C-eq (op M₁) ≡ op M₂
id-eq : subst (λ A → A) C-eq (id M₁) ≡ id M₂
goal = _↔_.from (equality-triple-lemma ext M₁ M₂)
(C-eq , op-eq , id-eq)
-- Our bijection can be converted into an equivalence.
equiv : Carrier M₁ ≃ Carrier M₂
equiv = Eq.↔⇒≃ bij
-- Hence the first equality follows directly from univalence.
C-eq = ≃⇒≡ univ equiv
-- For the second equality, let us first define a "cast" operator.
cast₂ : {A B : Type} → A ≃ B → (A → A → A) → (B → B → B)
cast₂ eq f = λ x y → to eq (f (from eq x) (from eq y))
-- The transport theorem implies that cast₂ equiv can be expressed
-- using subst.
cast₂-equiv-is-subst :
∀ f → cast₂ equiv f ≡ subst (λ A → A → A → A) C-eq f
cast₂-equiv-is-subst f =
transport-theorem (λ A → A → A → A) cast₂ refl univ equiv f
-- The second equality op-eq follows from extensionality,
-- cast₂-equiv-is-subst, and the fact that the bijection is a
-- monoid homomorphism.
op-eq = apply-ext ext λ x → apply-ext ext λ y →
subst (λ A → A → A → A) C-eq (op M₁) x y ≡⟨ cong (λ f → f x y) $ sym $ cast₂-equiv-is-subst (op M₁) ⟩
to equiv (op M₁ (from equiv x) (from equiv y)) ≡⟨ bij-op (from equiv x) (from equiv y) ⟩
op M₂ (to equiv (from equiv x)) (to equiv (from equiv y)) ≡⟨ cong₂ (op M₂) (right-inverse-of equiv x) (right-inverse-of equiv y) ⟩∎
op M₂ x y ∎
-- The development above can be repeated for the identity
-- elements.
cast₀ : {A B : Type} → A ≃ B → A → B
cast₀ eq x = to eq x
cast₀-equiv-is-subst : ∀ x → cast₀ equiv x ≡ subst (λ A → A) C-eq x
cast₀-equiv-is-subst x =
transport-theorem (λ A → A) cast₀ refl univ equiv x
id-eq =
subst (λ A → A) C-eq (id M₁) ≡⟨ sym $ cast₀-equiv-is-subst (id M₁) ⟩
to equiv (id M₁) ≡⟨ bij-id ⟩∎
id M₂ ∎
-- Equality of monoids is in fact in bijective correspondence with
-- isomorphism of monoids (assuming univalence).
isomorphism-is-equality :
Univalence (# 0) →
Univalence (# 1) →
(M₁ M₂ : Monoid) → (M₁ ≅ M₂) ↔ (M₁ ≡ M₂)
isomorphism-is-equality univ univ₁
(C₁ , op₁ , id₁ , laws₁) (C₂ , op₂ , id₂ , laws₂) =
(Σ (C₁ ↔ C₂) λ f → Is-homomorphism M₁ M₂ (_↔_.to f)) ↝⟨ Σ-cong (Eq.↔↔≃ ext C₁-set) (λ _ → _ □) ⟩
(Σ (C₁ ≃ C₂) λ C-eq → Is-homomorphism M₁ M₂ (_≃_.to C-eq)) ↝⟨ ∃-cong (λ C-eq → op-lemma C-eq ×-cong id-lemma C-eq) ⟩
(Σ (C₁ ≃ C₂) λ C-eq →
subst (λ C → C → C → C) (≃⇒≡ univ C-eq) op₁ ≡ op₂ ×
subst (λ C → C) (≃⇒≡ univ C-eq) id₁ ≡ id₂) ↝⟨ inverse $ Σ-cong (≡≃≃ univ) (λ C-eq → ≡⇒↝ _ $
cong (λ eq → subst (λ C → C → C → C) eq op₁ ≡ op₂ ×
subst (λ C → C) eq id₁ ≡ id₂) $ sym $
_≃_.left-inverse-of (≡≃≃ univ) C-eq) ⟩
(Σ (C₁ ≡ C₂) λ C-eq →
subst (λ C → C → C → C) C-eq op₁ ≡ op₂ ×
subst (λ C → C) C-eq id₁ ≡ id₂) ↝⟨ inverse $ equality-triple-lemma ext M₁ M₂ ⟩
((C₁ , op₁ , id₁ , laws₁) ≡ (C₂ , op₂ , id₂ , laws₂)) □
where
-- The two monoids.
M₁ = (C₁ , op₁ , id₁ , laws₁)
M₂ = (C₂ , op₂ , id₂ , laws₂)
-- Extensionality follows from univalence.
ext : Extensionality (# 0) (# 0)
ext = dependent-extensionality univ₁ univ
-- C₁ is a set.
C₁-set : Is-set C₁
C₁-set = proj₁ laws₁
module _ (C-eq : C₁ ≃ C₂) where
open _≃_ C-eq
-- Two component lemmas.
op-lemma :
(∀ x y → to (op₁ x y) ≡ op₂ (to x) (to y)) ↔
subst (λ C → C → C → C) (≃⇒≡ univ C-eq) op₁ ≡ op₂
op-lemma =
(∀ x y → to (op₁ x y) ≡ op₂ (to x) (to y)) ↔⟨ ∀-cong ext (λ _ → Eq.extensionality-isomorphism ext) ⟩
(∀ x → (λ y → to (op₁ x y)) ≡ (λ y → op₂ (to x) (to y))) ↝⟨ ∀-cong ext (λ _ → inverse $ ∘from≡↔≡∘to ext C-eq) ⟩
(∀ x → (λ y → to (op₁ x (from y))) ≡ (λ y → op₂ (to x) y)) ↔⟨ Eq.extensionality-isomorphism ext ⟩
((λ x y → to (op₁ x (from y))) ≡ (λ x y → op₂ (to x) y)) ↝⟨ inverse $ ∘from≡↔≡∘to ext C-eq ⟩
((λ x y → to (op₁ (from x) (from y))) ≡ (λ x y → op₂ x y)) ↝⟨ ≡⇒↝ _ $ cong (λ o → o ≡ op₂) $
transport-theorem
(λ C → C → C → C)
(λ eq f x y → _≃_.to eq (f (_≃_.from eq x) (_≃_.from eq y)))
refl univ C-eq op₁ ⟩
(subst (λ C → C → C → C) (≃⇒≡ univ C-eq) op₁ ≡ op₂) □
id-lemma : (to id₁ ≡ id₂) ↔
(subst (λ C → C) (≃⇒≡ univ C-eq) id₁ ≡ id₂)
id-lemma =
(to id₁ ≡ id₂) ↝⟨ ≡⇒↝ _ $ cong (λ i → i ≡ id₂) $
transport-theorem (λ C → C) _≃_.to refl univ C-eq id₁ ⟩□
(subst (λ C → C) (≃⇒≡ univ C-eq) id₁ ≡ id₂) □
-- Equality of monoids is thus equal to equality (assuming
-- univalence).
isomorphism-is-equal-to-equality :
Univalence (# 0) →
Univalence (# 1) →
(M₁ M₂ : Monoid) → ↑ _ (M₁ ≅ M₂) ≡ (M₁ ≡ M₂)
isomorphism-is-equal-to-equality univ univ₁ M₁ M₂ =
≃⇒≡ univ₁ $ Eq.↔⇒≃ (
↑ _ (M₁ ≅ M₂) ↝⟨ ↑↔ ⟩
(M₁ ≅ M₂) ↝⟨ isomorphism-is-equality univ univ₁ M₁ M₂ ⟩□
(M₁ ≡ M₂) □)
| 33.381703
| 136
| 0.485541
|
2198fdee3bb9b94e757ce7e62f9a346e1236e69e
| 15,214
|
agda
|
Agda
|
Cubical/Homotopy/Whitehead.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Homotopy/Whitehead.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Whitehead.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.Whitehead 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.Pointed
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Data.Unit
open import Cubical.HITs.Susp renaming (toSusp to σ)
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn
open import Cubical.HITs.Join
open import Cubical.HITs.Wedge
open import Cubical.HITs.SetTruncation
open import Cubical.Homotopy.Group.Base
open Iso
open 3x3-span
joinTo⋁ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'}
→ join (typ A) (typ B)
→ (Susp (typ A) , north) ⋁ (Susp (typ B) , north)
joinTo⋁ (inl x) = inr north
joinTo⋁ (inr x) = inl north
joinTo⋁ {A = A} {B = B} (push a b i) =
((λ i → inr (σ B b i))
∙∙ sym (push tt)
∙∙ λ i → inl (σ A a i)) i
-- Whitehead product (main definition)
[_∣_] : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ (S₊∙ (suc n) →∙ X)
→ (S₊∙ (suc m) →∙ X)
→ S₊∙ (suc (n + m)) →∙ X
fst ([_∣_] {X = X} {n = n} {m = m} f g) x =
_∨→_ (f ∘∙ (inv (IsoSucSphereSusp n) , IsoSucSphereSusp∙ n))
(g ∘∙ (inv (IsoSucSphereSusp m) , IsoSucSphereSusp∙ m))
(joinTo⋁ {A = S₊∙ n} {B = S₊∙ m}
(inv (IsoSphereJoin n m) x))
snd ([_∣_] {n = n} {m = m} f g) =
cong (_∨→_ (f ∘∙ (inv (IsoSucSphereSusp n) , IsoSucSphereSusp∙ n))
(g ∘∙ (inv (IsoSucSphereSusp m) , IsoSucSphereSusp∙ m)))
(cong (joinTo⋁ {A = S₊∙ n} {B = S₊∙ m}) (IsoSphereJoin⁻Pres∙ n m))
∙ cong (fst g) (IsoSucSphereSusp∙ m)
∙ snd g
-- For Sⁿ, Sᵐ with n, m ≥ 2, we can avoid some bureaucracy. We make
-- a separate definition and prove it equivalent.
[_∣_]-pre : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ (S₊∙ (suc (suc n)) →∙ X)
→ (S₊∙ (suc (suc m)) →∙ X)
→ join (typ (S₊∙ (suc n))) (typ (S₊∙ (suc m))) → fst X
[_∣_]-pre {n = n} {m = m} f g x =
_∨→_ f g
(joinTo⋁ {A = S₊∙ (suc n)} {B = S₊∙ (suc m)}
x)
[_∣_]₂ : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ (S₊∙ (suc (suc n)) →∙ X)
→ (S₊∙ (suc (suc m)) →∙ X)
→ S₊∙ (suc ((suc n) + (suc m))) →∙ X
fst ([_∣_]₂ {n = n} {m = m} f g) x =
[ f ∣ g ]-pre (inv (IsoSphereJoin (suc n) (suc m)) x)
snd ([_∣_]₂ {n = n} {m = m} f g) =
cong ([ f ∣ g ]-pre) (IsoSphereJoin⁻Pres∙ (suc n) (suc m))
∙ snd g
[]≡[]₂ : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ (f : (S₊∙ (suc (suc n)) →∙ X))
→ (g : (S₊∙ (suc (suc m)) →∙ X))
→ [ f ∣ g ] ≡ [ f ∣ g ]₂
[]≡[]₂ {n = n} {m = m} f g =
ΣPathP (
(λ i x → _∨→_ (∘∙-idˡ f i)
(∘∙-idˡ g i)
(joinTo⋁ {A = S₊∙ (suc n)} {B = S₊∙ (suc m)}
(inv (IsoSphereJoin (suc n) (suc m)) x)))
, (cong (cong (_∨→_ (f ∘∙ idfun∙ _)
(g ∘∙ idfun∙ _))
(cong (joinTo⋁ {A = S₊∙ (suc n)} {B = S₊∙ (suc m)})
(IsoSphereJoin⁻Pres∙ (suc n) (suc m))) ∙_)
(sym (lUnit (snd g)))
◁ λ j → (λ i → _∨→_ (∘∙-idˡ f j)
(∘∙-idˡ g j)
( joinTo⋁ {A = S₊∙ (suc n)} {B = S₊∙ (suc m)}
((IsoSphereJoin⁻Pres∙ (suc n) (suc m)) i))) ∙ snd g))
-- Homotopy group version
[_∣_]π' : ∀ {ℓ} {X : Pointed ℓ} {n m : ℕ}
→ π' (suc n) X → π' (suc m) X
→ π' (suc (n + m)) X
[_∣_]π' = elim2 (λ _ _ → squash₂) λ f g → ∣ [ f ∣ g ] ∣₂
-- We prove that the function joinTo⋁ used in the definition of the whitehead
-- product gives an equivalence between (Susp A × Susp B) and the
-- appropriate cofibre of joinTo⋁ (last two theorems in the following
-- module).
module _ (A B : Type) (a₀ : A) (b₀ : B) where
private
W = joinTo⋁ {A = (A , a₀)} {B = (B , b₀)}
A∨B = (Susp A , north) ⋁ (Susp B , north)
σB = σ (B , b₀)
σA = σ (A , a₀)
cofibW = Pushout W λ _ → tt
whitehead3x3 : 3x3-span
A00 whitehead3x3 = Susp A
A02 whitehead3x3 = B
A04 whitehead3x3 = Unit
A20 whitehead3x3 = B
A22 whitehead3x3 = A × B
A24 whitehead3x3 = A
A40 whitehead3x3 = B
A42 whitehead3x3 = B
A44 whitehead3x3 = Unit
f10 whitehead3x3 _ = south
f12 whitehead3x3 = snd
f14 whitehead3x3 _ = tt
f30 whitehead3x3 = idfun B
f32 whitehead3x3 = snd
f34 whitehead3x3 _ = tt
f01 whitehead3x3 _ = north
f21 whitehead3x3 = snd
f41 whitehead3x3 = idfun B
f03 whitehead3x3 _ = tt
f23 whitehead3x3 = fst
f43 whitehead3x3 _ = tt
H11 whitehead3x3 x = merid (fst x)
H13 whitehead3x3 _ = refl
H31 whitehead3x3 _ = refl
H33 whitehead3x3 _ = refl
A0□→A∨B : A0□ whitehead3x3 → A∨B
A0□→A∨B (inl x) = inl x
A0□→A∨B (inr x) = inr north
A0□→A∨B (push a i) = (push tt ∙ λ i → inr (σB a (~ i))) i
A∨B→A0□ : A∨B → A0□ whitehead3x3
A∨B→A0□ (inl x) = inl x
A∨B→A0□ (inr north) = inl north
A∨B→A0□ (inr south) = inl north
A∨B→A0□ (inr (merid b i)) = (push b₀ ∙ sym (push b)) i
A∨B→A0□ (push a i) = inl north
Iso-A0□-⋁ : Iso (A0□ whitehead3x3) A∨B
fun Iso-A0□-⋁ = A0□→A∨B
inv Iso-A0□-⋁ = A∨B→A0□
rightInv Iso-A0□-⋁ (inl x) = refl
rightInv Iso-A0□-⋁ (inr north) = push tt
rightInv Iso-A0□-⋁ (inr south) = push tt ∙ λ i → inr (merid b₀ i)
rightInv Iso-A0□-⋁ (inr (merid a i)) j = lem j i
where
lem : PathP (λ i → push tt i ≡ (push tt ∙ (λ i → inr (merid b₀ i))) i)
(cong A0□→A∨B (cong A∨B→A0□ λ i → inr (merid a i)))
(λ i → inr (merid a i))
lem = (cong-∙ A0□→A∨B (push b₀) (sym (push a))
∙ cong₂ _∙_ (cong (push tt ∙_)
(λ j i → inr (rCancel (merid b₀) j (~ i)))
∙ sym (rUnit (push tt)))
(symDistr (push tt) (λ i → inr (σB a (~ i)))))
◁ λ i j → hcomp (λ k →
λ { (i = i0) → compPath-filler' (push tt)
(compPath-filler (λ i → inr (σB a i))
(sym (push tt)) k) k j
; (i = i1) → inr (merid a j)
; (j = i0) → push tt (i ∨ ~ k)
; (j = i1) → compPath-filler' (push tt)
(λ i → inr (merid b₀ i)) k i})
(inr (compPath-filler (merid a)
(sym (merid b₀)) (~ i) j))
rightInv Iso-A0□-⋁ (push a i) j = push tt (i ∧ j)
leftInv Iso-A0□-⋁ (inl x) = refl
leftInv Iso-A0□-⋁ (inr tt) = push b₀
leftInv Iso-A0□-⋁ (push b i) j = help j i
where
help : PathP (λ i → inl north ≡ push b₀ i)
(cong A∨B→A0□ (cong A0□→A∨B (push b)))
(push b)
help = (cong-∙ A∨B→A0□ (push tt) (λ i → inr (σB b (~ i)))
∙ (λ i → lUnit (sym (cong-∙ (A∨B→A0□ ∘ inr)
(merid b) (sym (merid b₀)) i)) (~ i))
∙ cong sym (cong ((push b₀ ∙ sym (push b)) ∙_)
(cong sym (rCancel (push b₀))))
∙ cong sym (sym (rUnit (push b₀ ∙ sym (push b)))))
◁ λ i j → compPath-filler' (push b₀) (sym (push b)) (~ i) (~ j)
Iso-A2□-join : Iso (A2□ whitehead3x3) (join A B)
fun Iso-A2□-join (inl x) = inr x
fun Iso-A2□-join (inr x) = inl x
fun Iso-A2□-join (push (a , b) i) = push a b (~ i)
inv Iso-A2□-join (inl x) = inr x
inv Iso-A2□-join (inr x) = inl x
inv Iso-A2□-join (push a b i) = push (a , b) (~ i)
rightInv Iso-A2□-join (inl x) = refl
rightInv Iso-A2□-join (inr x) = refl
rightInv Iso-A2□-join (push a b i) = refl
leftInv Iso-A2□-join (inl x) = refl
leftInv Iso-A2□-join (inr x) = refl
leftInv Iso-A2□-join (push a i) = refl
isContrA4□ : isContr (A4□ whitehead3x3)
fst isContrA4□ = inr tt
snd isContrA4□ (inl x) = sym (push x)
snd isContrA4□ (inr x) = refl
snd isContrA4□ (push a i) j = push a (i ∨ ~ j)
A4□≃Unit : A4□ whitehead3x3 ≃ Unit
A4□≃Unit = isContr→≃Unit isContrA4□
Iso-A□0-Susp : Iso (A□0 whitehead3x3) (Susp A)
fun Iso-A□0-Susp (inl x) = x
fun Iso-A□0-Susp (inr x) = north
fun Iso-A□0-Susp (push a i) = merid a₀ (~ i)
inv Iso-A□0-Susp x = inl x
rightInv Iso-A□0-Susp x = refl
leftInv Iso-A□0-Susp (inl x) = refl
leftInv Iso-A□0-Susp (inr x) = (λ i → inl (merid a₀ i)) ∙ push x
leftInv Iso-A□0-Susp (push a i) j =
hcomp (λ k → λ { (i = i0) → inl (merid a₀ (k ∨ j))
; (i = i1) → compPath-filler
(λ i₁ → inl (merid a₀ i₁))
(push (idfun B a)) k j
; (j = i0) → inl (merid a₀ (~ i ∧ k))
; (j = i1) → push a (i ∧ k)})
(inl (merid a₀ j))
Iso-A□2-Susp× : Iso (A□2 whitehead3x3) (Susp A × B)
fun Iso-A□2-Susp× (inl x) = north , x
fun Iso-A□2-Susp× (inr x) = south , x
fun Iso-A□2-Susp× (push a i) = merid (fst a) i , (snd a)
inv Iso-A□2-Susp× (north , y) = inl y
inv Iso-A□2-Susp× (south , y) = inr y
inv Iso-A□2-Susp× (merid a i , y) = push (a , y) i
rightInv Iso-A□2-Susp× (north , snd₁) = refl
rightInv Iso-A□2-Susp× (south , snd₁) = refl
rightInv Iso-A□2-Susp× (merid a i , snd₁) = refl
leftInv Iso-A□2-Susp× (inl x) = refl
leftInv Iso-A□2-Susp× (inr x) = refl
leftInv Iso-A□2-Susp× (push a i) = refl
Iso-A□4-Susp : Iso (A□4 whitehead3x3) (Susp A)
fun Iso-A□4-Susp (inl x) = north
fun Iso-A□4-Susp (inr x) = south
fun Iso-A□4-Susp (push a i) = merid a i
inv Iso-A□4-Susp north = inl tt
inv Iso-A□4-Susp south = inr tt
inv Iso-A□4-Susp (merid a i) = push a i
rightInv Iso-A□4-Susp north = refl
rightInv Iso-A□4-Susp south = refl
rightInv Iso-A□4-Susp (merid a i) = refl
leftInv Iso-A□4-Susp (inl x) = refl
leftInv Iso-A□4-Susp (inr x) = refl
leftInv Iso-A□4-Susp (push a i) = refl
Iso-PushSusp×-Susp×Susp :
Iso (Pushout {A = Susp A × B} fst fst) (Susp A × Susp B)
Iso-PushSusp×-Susp×Susp = theIso
where
F : Pushout {A = Susp A × B} fst fst
→ Susp A × Susp B
F (inl x) = x , north
F (inr x) = x , north
F (push (x , b) i) = x , σB b i
G : Susp A × Susp B → Pushout {A = Susp A × B} fst fst
G (a , north) = inl a
G (a , south) = inr a
G (a , merid b i) = push (a , b) i
retr : retract F G
retr (inl x) = refl
retr (inr x) = push (x , b₀)
retr (push (a , b) i) j = help j i
where
help : PathP (λ i → Path (Pushout fst fst) (inl a) (push (a , b₀) i))
(cong G (λ i → a , σB b i))
(push (a , b))
help = cong-∙ (λ x → G (a , x)) (merid b) (sym (merid b₀))
◁ λ i j → compPath-filler
(push (a , b))
(sym (push (a , b₀)))
(~ i) j
theIso : Iso (Pushout fst fst) (Susp A × Susp B)
fun theIso = F
inv theIso = G
rightInv theIso (a , north) = refl
rightInv theIso (a , south) = ΣPathP (refl , merid b₀)
rightInv theIso (a , merid b i) j =
a , compPath-filler (merid b) (sym (merid b₀)) (~ j) i
leftInv theIso = retr
Iso-A□○-PushSusp× :
Iso (A□○ whitehead3x3) (Pushout {A = Susp A × B} fst fst)
Iso-A□○-PushSusp× =
pushoutIso _ _ fst fst
(isoToEquiv Iso-A□2-Susp×)
(isoToEquiv Iso-A□0-Susp)
(isoToEquiv Iso-A□4-Susp)
(funExt (λ { (inl x) → refl
; (inr x) → merid a₀
; (push a i) j → help₁ a j i}))
(funExt λ { (inl x) → refl
; (inr x) → refl
; (push a i) j
→ fun Iso-A□4-Susp (rUnit (push (fst a)) (~ j) i)})
where
help₁ : (a : A × B)
→ PathP (λ i → north ≡ merid a₀ i)
(cong (fun Iso-A□0-Susp)
(cong (f□1 whitehead3x3) (push a)))
(merid (fst a))
help₁ a =
(cong-∙∙ (fun Iso-A□0-Susp)
(λ i → inl (merid (fst a) i))
(push (snd a))
refl)
◁ (λ i j → hcomp (λ k → λ {(i = i1) → merid (fst a) (j ∨ ~ k)
; (j = i0) → merid (fst a) (~ k)
; (j = i1) → merid a₀ i})
(merid a₀ (i ∨ ~ j)))
Iso-A□○-Susp×Susp : Iso (A□○ whitehead3x3) (Susp A × Susp B)
Iso-A□○-Susp×Susp = compIso Iso-A□○-PushSusp× Iso-PushSusp×-Susp×Susp
Iso-A○□-cofibW : Iso (A○□ whitehead3x3) cofibW
Iso-A○□-cofibW =
pushoutIso _ _
W (λ _ → tt)
(isoToEquiv Iso-A2□-join) (isoToEquiv Iso-A0□-⋁)
A4□≃Unit
(funExt lem)
λ _ _ → tt
where
lem : (x : A2□ whitehead3x3)
→ A0□→A∨B (f1□ whitehead3x3 x) ≡ W (fun Iso-A2□-join x)
lem (inl x) = (λ i → inl (merid a₀ (~ i)))
lem (inr x) = refl
lem (push (a , b) i) j = help j i
where
help : PathP (λ i → Path (Pushout (λ _ → north) (λ _ → north))
((inl (merid a₀ (~ i))))
(inr north))
(cong A0□→A∨B (cong (f1□ whitehead3x3) (push (a , b))))
(cong W (cong (fun Iso-A2□-join) (push (a , b))))
help = (cong-∙∙ A0□→A∨B (λ i → inl (merid a (~ i))) (push b) refl
∙ λ j → (λ i₂ → inl (merid a (~ i₂)))
∙∙ compPath-filler (push tt) (λ i → inr (σB b (~ i))) (~ j)
∙∙ λ i → inr (σB b (~ i ∧ j)))
◁ (λ j → (λ i → inl (sym (compPath-filler
(merid a) (sym (merid a₀)) j) i))
∙∙ push tt
∙∙ λ i → inr (σB b (~ i)))
Iso₁-Susp×Susp-cofibW : Iso (Susp A × Susp B) cofibW
Iso₁-Susp×Susp-cofibW =
compIso (invIso Iso-A□○-Susp×Susp)
(compIso (3x3-Iso whitehead3x3) Iso-A○□-cofibW)
-- Main iso
Iso-Susp×Susp-cofibJoinTo⋁ : Iso (Susp A × Susp B) cofibW
Iso-Susp×Susp-cofibJoinTo⋁ =
compIso (Σ-cong-iso-snd (λ _ → invSuspIso))
Iso₁-Susp×Susp-cofibW
-- The induced function A ∨ B → Susp A × Susp B satisfies
-- the following identity
Susp×Susp→cofibW≡ : Path (A∨B → Susp A × Susp B)
(Iso.inv Iso-Susp×Susp-cofibJoinTo⋁ ∘ inl)
⋁↪
Susp×Susp→cofibW≡ =
funExt λ { (inl x) → ΣPathP (refl , (sym (merid b₀)))
; (inr north) → ΣPathP (refl , (sym (merid b₀)))
; (inr south) → refl
; (inr (merid a i)) j → lem₂ a j i
; (push a i) j → north , (merid b₀ (~ j))}
where
f₁ = fun Iso-PushSusp×-Susp×Susp
f₂ = fun Iso-A□○-PushSusp×
f₃ = backward-l whitehead3x3
f₄ = fun (Σ-cong-iso-snd (λ _ → invSuspIso))
lem : (b : B)
→ cong (f₁ ∘ f₂ ∘ f₃) (push b)
≡ (λ i → north , σB b i)
lem b = cong (cong f₁) (sym (rUnit (push (north , b))))
lem₂ : (a : B)
→ PathP (λ i → (north , merid b₀ (~ i)) ≡ (north , south))
(cong (f₄ ∘ f₁ ∘ f₂ ∘ f₃ ∘ A∨B→A0□ ∘ inr) (merid a))
λ i → north , merid a i
lem₂ a =
cong (cong f₄) (cong-∙ (f₁ ∘ f₂ ∘ f₃) (push b₀) (sym (push a))
∙∙ cong₂ _∙_ (lem b₀ ∙ (λ j i → north , rCancel (merid b₀) j i))
(cong sym (lem a))
∙∙ sym (lUnit (λ i₁ → north , σB a (~ i₁))))
∙ (λ i j → north , cong-∙ invSusp (merid a) (sym (merid b₀)) i (~ j) )
◁ λ i j → north , compPath-filler (sym (merid a)) (merid b₀) (~ i) (~ j)
| 37.017032
| 80
| 0.491521
|
37ee4f8bb3b99af8b9ab22b6065cf1350ca3d457
| 1,356
|
agda
|
Agda
|
Cubical/Relation/Nullary/HLevels.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Nullary/HLevels.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Relation/Nullary/HLevels.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.Relation.Nullary.HLevels where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Functions.Fixpoint
open import Cubical.Relation.Nullary
private
variable
ℓ : Level
A : Type ℓ
isPropPopulated : isProp (Populated A)
isPropPopulated = isPropΠ λ x → 2-Constant→isPropFixpoint (x .fst) (x .snd)
isPropHSeparated : isProp (HSeparated A)
isPropHSeparated f g i x y a = HSeparated→isSet f x y (f x y a) (g x y a) i
isPropCollapsible≡ : isProp (Collapsible≡ A)
isPropCollapsible≡ {A = A} f = (isPropΠ2 λ x y → isPropCollapsiblePointwise) f where
sA : isSet A
sA = Collapsible≡→isSet f
gA : isGroupoid A
gA = isSet→isGroupoid sA
isPropCollapsiblePointwise : ∀ {x y} → isProp (Collapsible (x ≡ y))
isPropCollapsiblePointwise {x} {y} (a , ca) (b , cb) = λ i → endoFunction i , endoFunctionIsConstant i where
endoFunction : a ≡ b
endoFunction = funExt λ p → sA _ _ (a p) (b p)
isProp2-Constant : (k : I) → isProp (2-Constant (endoFunction k))
isProp2-Constant k = isPropΠ2 λ r s → gA x y (endoFunction k r) (endoFunction k s)
endoFunctionIsConstant : PathP (λ i → 2-Constant (endoFunction i)) ca cb
endoFunctionIsConstant = isProp→PathP isProp2-Constant ca cb
| 37.666667
| 110
| 0.716814
|
1b615ecba2d0518d50fbd642073e9440627a16e2
| 1,191
|
agda
|
Agda
|
agda-stdlib-0.9/src/Data/W/Indexed.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/W/Indexed.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Data/W/Indexed.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Indexed W-types aka Petersson-Synek trees
------------------------------------------------------------------------
module Data.W.Indexed where
open import Level
open import Data.Container.Indexed.Core
open import Data.Product
open import Relation.Unary
-- The family of indexed W-types.
module _ {ℓ c r} {O : Set ℓ} (C : Container O O c r) where
open Container C
data W (o : O) : Set (ℓ ⊔ c ⊔ r) where
sup : ⟦ C ⟧ W o → W o
-- Projections.
head : W ⊆ Command
head (sup (c , _)) = c
tail : ∀ {o} (w : W o) (r : Response (head w)) → W (next (head w) r)
tail (sup (_ , k)) r = k r
-- Induction, (primitive) recursion and iteration.
ind : ∀ {ℓ} (P : Pred (Σ O W) ℓ) →
(∀ {o} (cs : ⟦ C ⟧ W o) → □ C P (o , cs) → P (o , sup cs)) →
∀ {o} (w : W o) → P (o , w)
ind P φ (sup (c , k)) = φ (c , k) (λ r → ind P φ (k r))
rec : ∀ {ℓ} {X : Pred O ℓ} → (⟦ C ⟧ (W ∩ X) ⊆ X) → W ⊆ X
rec φ (sup (c , k))= φ (c , λ r → (k r , rec φ (k r)))
iter : ∀ {ℓ} {X : Pred O ℓ} → (⟦ C ⟧ X ⊆ X) → W ⊆ X
iter φ (sup (c , k))= φ (c , λ r → iter φ (k r))
| 27.697674
| 72
| 0.439966
|
06ce802cafd4077083cef06084dd7c463ea48fd2
| 963
|
agda
|
Agda
|
test/Succeed/Issue1796.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue1796.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue1796.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
-- Andreas, 2016-01-23, issue 1796
-- Need to run size constraint solver before with-abstraction
open import Common.Size
postulate
anything : ∀{A : Set} → A
mutual
record IO i : Set where
coinductive
field force : ∀{j : Size< i} → IO' j
data IO' i : Set where
cons : IO i → IO' i
mutual
record All i (s : IO ∞) : Set where
field force : ∀{j : Size< i} → All' j (IO.force s)
data All' i : (s : IO' ∞) → Set where
always : ∀ e → All' i (cons e)
runIO : ∀{i} (s : IO ∞) → IO i
IO.force (runIO s) with IO.force s
... | cons e = cons e
-- With abstraction fails when _ in IO.force s {_}
-- has not been solved to ∞.
test : ∀ i s → All i (runIO s)
All.force (test i s) with IO.force s -- works with {∞} added
All.force (test i s) | cons e = always e
-- cons e != IO.force (runIO {∞} s) {∞} | IO.force s of type IO' ∞
-- when checking that the expression always e has type
-- All' .j (IO.force (runIO {∞} s) {∞} | IO.force s)
| 24.075
| 66
| 0.590862
|
fd8cf7913d3e757fdbb6ac99ad68ce062e49675c
| 176
|
agda
|
Agda
|
Multidimensional/Data/Extra/Nat/Base.agda
|
wrrnhttn/agda-cubical-multidimensional
|
55709dd950e319c4a105ace33ddaf8b955354add
|
[
"MIT"
] | null | null | null |
Multidimensional/Data/Extra/Nat/Base.agda
|
wrrnhttn/agda-cubical-multidimensional
|
55709dd950e319c4a105ace33ddaf8b955354add
|
[
"MIT"
] | 4
|
2019-06-19T20:40:07.000Z
|
2019-07-02T16:24:01.000Z
|
Multidimensional/Data/Extra/Nat/Base.agda
|
wrrnhttn/agda-cubical-multidimensional
|
55709dd950e319c4a105ace33ddaf8b955354add
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-exact-split --safe #-}
module Multidimensional.Data.Extra.Nat.Base where
open import Cubical.Data.Nat
sucn : (n : ℕ) → (ℕ → ℕ)
sucn n = iter n suc
| 22
| 49
| 0.670455
|
1dbdaea0b8d485ac67631dde40b76b12e98c95a2
| 4,860
|
agda
|
Agda
|
src/Algebra/Theorems.agda
|
asr/alga
|
01f5f9f53ea81f692215300744aa77e26d8bf332
|
[
"MIT"
] | null | null | null |
src/Algebra/Theorems.agda
|
asr/alga
|
01f5f9f53ea81f692215300744aa77e26d8bf332
|
[
"MIT"
] | null | null | null |
src/Algebra/Theorems.agda
|
asr/alga
|
01f5f9f53ea81f692215300744aa77e26d8bf332
|
[
"MIT"
] | null | null | null |
module Algebra.Theorems where
open import Algebra
open import Reasoning
+pre-idempotence : ∀ {A} {x : Graph A} -> x + x + ε ≡ x
+pre-idempotence {_} {x} =
begin
(x + x) + ε ≡⟨ L (L (symmetry *right-identity)) ⟩
(x * ε + x) + ε ≡⟨ L (R (symmetry *right-identity)) ⟩
(x * ε + x * ε) + ε ≡⟨ R (symmetry *right-identity) ⟩
(x * ε + x * ε) + ε * ε ≡⟨ symmetry decomposition ⟩
(x * ε) * ε ≡⟨ *right-identity ⟩
x * ε ≡⟨ *right-identity ⟩
x
∎
+identity : ∀ {A} {x : Graph A} -> x + ε ≡ x
+identity {_} {x} =
begin
x + ε ≡⟨ symmetry +pre-idempotence ⟩
((x + ε) + (x + ε)) + ε ≡⟨ L +associativity ⟩
(((x + ε) + x) + ε) + ε ≡⟨ L (L (symmetry +associativity)) ⟩
((x + (ε + x)) + ε) + ε ≡⟨ L (L (R +commutativity)) ⟩
((x + (x + ε)) + ε) + ε ≡⟨ L (L +associativity) ⟩
(((x + x) + ε) + ε) + ε ≡⟨ L (symmetry +associativity) ⟩
((x + x) + (ε + ε)) + ε ≡⟨ symmetry +associativity ⟩
(x + x) + ((ε + ε) + ε) ≡⟨ R +pre-idempotence ⟩
(x + x) + ε ≡⟨ +pre-idempotence ⟩
x
∎
+idempotence : ∀ {A} {x : Graph A} -> x + x ≡ x
+idempotence = transitivity (symmetry +identity) +pre-idempotence
saturation : ∀ {A} {x : Graph A} -> x * x * x ≡ x * x
saturation {_} {x} =
begin
(x * x) * x ≡⟨ decomposition ⟩
(x * x + x * x) + x * x ≡⟨ L +idempotence ⟩
x * x + x * x ≡⟨ +idempotence ⟩
x * x
∎
absorption : ∀ {A} {x y : Graph A} -> x * y + x + y ≡ x * y
absorption {_} {x} {y} =
begin
(x * y + x) + y ≡⟨ L (R (symmetry *right-identity)) ⟩
(x * y + x * ε) + y ≡⟨ R (symmetry *right-identity) ⟩
(x * y + x * ε) + y * ε ≡⟨ symmetry decomposition ⟩
(x * y) * ε ≡⟨ *right-identity ⟩
x * y
∎
-- Subgraph relation
⊆reflexivity : ∀ {A} {x : Graph A} -> x ⊆ x
⊆reflexivity = +idempotence
⊆antisymmetry : ∀ {A} {x y : Graph A} -> x ⊆ y -> y ⊆ x -> x ≡ y
⊆antisymmetry p q = symmetry q -- x = y + x
>> +commutativity -- y + x = x + y
>> p -- x + y = y
⊆transitivity : ∀ {A} {x y z : Graph A} -> x ⊆ y -> y ⊆ z -> x ⊆ z
⊆transitivity p q = symmetry
(symmetry q -- z = y + z
>> L (symmetry p) -- y + z = (x + y) + z
>> symmetry +associativity -- (x + y) + z = x + (y + z)
>> R q) -- x + (y + z) = x + z
⊆least-element : ∀ {A} {x : Graph A} -> ε ⊆ x
⊆least-element = +commutativity >> +identity
⊆overlay : ∀ {A} {x y : Graph A} -> x ⊆ (x + y)
⊆overlay = +associativity >> L +idempotence
⊆connect : ∀ {A} {x y : Graph A} -> (x + y) ⊆ (x * y)
⊆connect = +commutativity >> +associativity >> absorption
⊆left-overlay-monotony : ∀ {A} {x y z : Graph A} -> x ⊆ y -> (x + z) ⊆ (y + z)
⊆left-overlay-monotony {_} {x} {y} {z} p =
begin
(x + z) + (y + z) ≡⟨ symmetry +associativity ⟩
x + (z + (y + z)) ≡⟨ R +commutativity ⟩
x + ((y + z) + z) ≡⟨ R (symmetry +associativity) ⟩
x + (y + (z + z)) ≡⟨ R (R +idempotence) ⟩
x + (y + z) ≡⟨ +associativity ⟩
(x + y) + z ≡⟨ L p ⟩
y + z
∎
⊆right-overlay-monotony : ∀ {A} {x y z : Graph A} -> x ⊆ y -> (z + x) ⊆ (z + y)
⊆right-overlay-monotony {_} {x} {y} {z} p =
begin
(z + x) + (z + y) ≡⟨ +associativity ⟩
((z + x) + z) + y ≡⟨ L +commutativity ⟩
(z + (z + x)) + y ≡⟨ L +associativity ⟩
((z + z) + x) + y ≡⟨ L (L +idempotence) ⟩
(z + x) + y ≡⟨ symmetry +associativity ⟩
z + (x + y) ≡⟨ R p ⟩
z + y
∎
⊆left-connect-monotony : ∀ {A} {x y z : Graph A} -> x ⊆ y -> (x * z) ⊆ (y * z)
⊆left-connect-monotony {_} {x} {y} {z} p =
begin
(x * z) + (y * z) ≡⟨ symmetry right-distributivity ⟩
(x + y) * z ≡⟨ L p ⟩
y * z
∎
⊆right-connect-monotony : ∀ {A} {x y z : Graph A} -> x ⊆ y -> (z * x) ⊆ (z * y)
⊆right-connect-monotony {_} {x} {y} {z} p =
begin
(z * x) + (z * y) ≡⟨ symmetry left-distributivity ⟩
z * (x + y) ≡⟨ R p ⟩
z * y
∎
⊆left-monotony : ∀ {A} {op : BinaryOperator} {x y z : Graph A} -> x ⊆ y -> apply op x z ⊆ apply op y z
⊆left-monotony {_} {+op} {x} {y} {z} p = ⊆left-overlay-monotony p
⊆left-monotony {_} {*op} {x} {y} {z} p = ⊆left-connect-monotony p
⊆right-monotony : ∀ {A} {op : BinaryOperator} {x y z : Graph A} -> x ⊆ y -> apply op z x ⊆ apply op z y
⊆right-monotony {_} {+op} {x} {y} {z} p = ⊆right-overlay-monotony p
⊆right-monotony {_} {*op} {x} {y} {z} p = ⊆right-connect-monotony p
| 38.267717
| 103
| 0.417284
|
191899c2d1a8f44bb8fb4671babae43bb7529447
| 627
|
agda
|
Agda
|
test/Succeed/Issue3211.agda
|
alhassy/agda
|
6043e77e4a72518711f5f808fb4eb593cbf0bb7c
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue3211.agda
|
alhassy/agda
|
6043e77e4a72518711f5f808fb4eb593cbf0bb7c
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue3211.agda
|
alhassy/agda
|
6043e77e4a72518711f5f808fb4eb593cbf0bb7c
|
[
"BSD-3-Clause"
] | null | null | null |
-- 2018-09-05, reported by Andreas Abel
-- The new type-directed rewriting was using the wrong type for
-- constructors of parametrized datatypes.
{-# OPTIONS --rewriting #-}
module _ (Form : Set) where
open import Agda.Builtin.Equality
{-# BUILTIN REWRITE _≡_ #-}
data Cxt : Set where
_∙_ : (Γ : Cxt) (A : Form) → Cxt
data _≤_ : (Γ Δ : Cxt) → Set where
id≤ : ∀{Γ} → Γ ≤ Γ
lift : ∀{A Γ Δ} (τ : Γ ≤ Δ) → (Γ ∙ A) ≤ (Δ ∙ A)
postulate
lift-id≤ : ∀{Γ A} → lift id≤ ≡ id≤ {Γ ∙ A}
{-# REWRITE lift-id≤ #-}
_•_ : ∀{Γ Δ Φ} (τ : Γ ≤ Δ) (σ : Δ ≤ Φ) → Γ ≤ Φ
id≤ • σ = σ
lift τ • id≤ = lift τ
lift τ • lift σ = lift (τ • σ)
| 22.392857
| 63
| 0.551834
|
310dff09c69121a8929557ecdbb3d472c1e5fa27
| 119
|
agda
|
Agda
|
test/Fail/UnequalSorts.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/UnequalSorts.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/UnequalSorts.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module UnequalSorts where
data One : Set where one : One
data One' : Set1 where one' : One'
err : One
err = one'
| 11.9
| 34
| 0.655462
|
0ddfa2177f55a154962e3a8da3fb1530578fac88
| 224
|
agda
|
Agda
|
test/fail/NoTerminationCheck3.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/fail/NoTerminationCheck3.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/NoTerminationCheck3.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- 2012-03-08 Andreas
module NoTerminationCheck3 where
data Bool : Set where
true false : Bool
f : Bool -> Bool
f true = true
{-# NO_TERMINATION_CHECK #-}
f false = false
-- error: cannot place pragma inbetween clauses
| 17.230769
| 47
| 0.71875
|
365b4fd1f3866b3e9c144e9d869753d4b4e61bd8
| 272
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Word/Properties.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
src/data/lib/prim/Agda/Builtin/Word/Properties.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
src/data/lib/prim/Agda/Builtin/Word/Properties.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness #-}
module Agda.Builtin.Word.Properties where
open import Agda.Builtin.Word
open import Agda.Builtin.Equality
primitive
primWord64ToNatInjective : ∀ a b → primWord64ToNat a ≡ primWord64ToNat b → a ≡ b
| 24.727273
| 82
| 0.746324
|
d1083a00739c6f6e4a02b4ac8029fc9f3e629716
| 105
|
agda
|
Agda
|
Both.agda
|
brunoczim/ual
|
ea0260e1a0612ba581e4283dfb187f531a944dfd
|
[
"MIT"
] | null | null | null |
Both.agda
|
brunoczim/ual
|
ea0260e1a0612ba581e4283dfb187f531a944dfd
|
[
"MIT"
] | null | null | null |
Both.agda
|
brunoczim/ual
|
ea0260e1a0612ba581e4283dfb187f531a944dfd
|
[
"MIT"
] | null | null | null |
module Ual.Both where
infix 10 _∧_
record _∧_ (A B : Set) : Set where
field
andL : A
andR : B
| 13.125
| 34
| 0.6
|
19dee97ed338800ee5c360a55418773c431cf8d5
| 448
|
agda
|
Agda
|
test/interaction/Issue3264.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue3264.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue3264.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2018-10-15, issue #3264 reported by Guillaume Brunerie
-- Refine should not say "cannot refine" just because of a termination error.
f : Set → Set
f A = {!f!} -- C-c C-r
-- EXPECTED ANSWER:
--
-- ?1 : Set
-- ———— Errors ————————————————————————————————————————————————
-- Termination checking failed for the following functions:
-- f
-- Problematic calls:
-- f (?1 (A = A))
-- when checking that the expression f ? has type Set
| 26.352941
| 77
| 0.578125
|
43dca3ea0c157c367b34167bc62f23f00705ed6e
| 11,332
|
agda
|
Agda
|
Cubical/Foundations/HLevels.agda
|
oisdk/cubical
|
a01973ef7264f9454a40697313a2073c51a6b77a
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/HLevels.agda
|
oisdk/cubical
|
a01973ef7264f9454a40697313a2073c51a6b77a
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/HLevels.agda
|
oisdk/cubical
|
a01973ef7264f9454a40697313a2073c51a6b77a
|
[
"MIT"
] | null | null | null |
{-
Basic theory about h-levels/n-types:
- Basic properties of isContr, isProp and isSet (definitions are in Prelude)
- Hedberg's theorem can be found in Cubical/Relation/Nullary/DecidableEq
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.HLevels where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.FunExtEquiv
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.Transport
open import Cubical.Foundations.HAEquiv using (congEquiv)
open import Cubical.Foundations.Univalence using (ua; univalence)
open import Cubical.Data.Sigma using (ΣPathP; sigmaPath→pathSigma; pathSigma≡sigmaPath; _Σ≡T_)
open import Cubical.Data.Nat.Base using (ℕ; zero; suc; _+_)
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : A → Type ℓ
x y : A
n : ℕ
-- uses an inlined version of +-comm to avoid cyclic imports from using Cubical.Data.Nat.Properties
private
+-zero : ∀ m → m + 0 ≡ m
+-zero zero = refl
+-zero (suc m) = cong suc (+-zero m)
+-suc : ∀ m n → m + suc n ≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n = cong suc (+-suc m n)
+-comm : ∀ m n → m + n ≡ n + m
+-comm m zero = +-zero m
+-comm m (suc n) = (+-suc m n) ∙ (cong suc (+-comm m n))
hProp : ∀ ℓ → Type (ℓ-suc ℓ)
hProp ℓ = Σ (Type ℓ) isProp
isOfHLevel : ℕ → Type ℓ → Type ℓ
isOfHLevel 0 A = isContr A
isOfHLevel 1 A = isProp A
isOfHLevel (suc (suc n)) A = (x y : A) → isOfHLevel (suc n) (x ≡ y)
HLevel : ∀ ℓ → ℕ → Type (ℓ-suc ℓ)
HLevel ℓ n = Σ[ A ∈ Type ℓ ] (isOfHLevel n A)
inhProp→isContr : A → isProp A → isContr A
inhProp→isContr x h = x , h x
isContrPartial→isContr : ∀ {ℓ} {A : Type ℓ}
→ (extend : ∀ φ → Partial φ A → A)
→ (∀ u → u ≡ (extend i1 λ { _ → u}))
→ isContr A
isContrPartial→isContr {A = A} extend law
= ex , λ y → law ex ∙ (λ i → Aux.v y i) ∙ sym (law y)
where ex = extend i0 empty
module Aux (y : A) (i : I) where
φ = ~ i ∨ i
u : Partial φ A
u = λ { (i = i0) → ex ; (i = i1) → y }
v = extend φ u
-- Dependent h-level over a type
isOfHLevelDep : ℕ → {A : Type ℓ} (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')
isOfHLevelDep 0 {A = A} B = {a : A} → Σ[ b ∈ B a ] ({a' : A} (b' : B a') (p : a ≡ a') → PathP (λ i → B (p i)) b b')
isOfHLevelDep 1 {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) (p : a0 ≡ a1) → PathP (λ i → B (p i)) b0 b1
isOfHLevelDep (suc (suc n)) {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) → isOfHLevelDep (suc n) {A = a0 ≡ a1} (λ p → PathP (λ i → B (p i)) b0 b1)
isOfHLevel→isOfHLevelDep : (n : ℕ)
→ {A : Type ℓ} {B : A → Type ℓ'} (h : (a : A) → isOfHLevel n (B a)) → isOfHLevelDep n {A = A} B
isOfHLevel→isOfHLevelDep 0 h {a} =
(h a .fst , λ b' p → isProp→PathP (λ i → isContr→isProp (h (p i))) (h a .fst) b')
isOfHLevel→isOfHLevelDep 1 h = λ b0 b1 p → isProp→PathP (λ i → h (p i)) b0 b1
isOfHLevel→isOfHLevelDep (suc (suc n)) {A = A} {B} h {a0} {a1} b0 b1 =
isOfHLevel→isOfHLevelDep (suc n) (λ p → helper a1 p b1)
where
helper : (a1 : A) (p : a0 ≡ a1) (b1 : B a1) →
isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1)
helper a1 p b1 = J
(λ a1 p → ∀ b1 → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1))
(λ _ → h _ _ _) p b1
-- Fillers for cubes from h-level
isSet→isSet' : isSet A → isSet' A
isSet→isSet' {A = A} Aset a₀₋ a₁₋ a₋₀ a₋₁ =
transport⁻ (PathP≡Path (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋) (Aset _ _ _ _)
isSet'→isSet : isSet' A → isSet A
isSet'→isSet {A = A} Aset' x y p q = Aset' p q refl refl
isGroupoid→isGroupoid' : {A : Type ℓ} → isGroupoid A → isGroupoid' A
isGroupoid→isGroupoid' {A = A} Agpd a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁ =
transport⁻ (PathP≡Path (λ i → Square (a₋₀₋ i) (a₋₁₋ i) (a₋₋₀ i) (a₋₋₁ i)) a₀₋₋ a₁₋₋)
(isGroupoid→isPropSquare _ _ _ _ _ _)
where
isGroupoid→isPropSquare :
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ isProp (Square a₀₋ a₁₋ a₋₀ a₋₁)
isGroupoid→isPropSquare a₀₋ a₁₋ a₋₀ a₋₁ =
transport⁻
(cong isProp (PathP≡Path (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋))
(Agpd _ _ _ _)
isGroupoid'→isGroupoid : isGroupoid' A → isGroupoid A
isGroupoid'→isGroupoid Agpd' x y p q r s = Agpd' r s refl refl refl refl
-- hlevels are preserved by retracts (and consequently equivalences)
retractIsContr
: ∀ {B : Type ℓ}
→ (f : A → B) (g : B → A)
→ (h : retract f g)
→ (v : isContr B) → isContr A
retractIsContr f g h (b , p) = (g b , λ x → (cong g (p (f x))) ∙ (h x))
retractIsProp
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isProp B → isProp A
retractIsProp f g h p x y i =
hcomp
(λ j → λ
{ (i = i0) → h x j
; (i = i1) → h y j})
(g (p (f x) (f y) i))
retractIsOfHLevel
: (n : ℕ) {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isOfHLevel n B → isOfHLevel n A
retractIsOfHLevel 0 = retractIsContr
retractIsOfHLevel 1 = retractIsProp
retractIsOfHLevel (suc (suc n)) f g h ofLevel x y =
retractIsOfHLevel (suc n)
(cong f)
(λ q i →
hcomp
(λ j → λ
{ (i = i0) → h x j
; (i = i1) → h y j})
(g (q i)))
(λ p k i →
hcomp
(λ j → λ
{ (i = i0) → h x (j ∨ k)
; (i = i1) → h y (j ∨ k)
; (k = i1) → p i})
(h (p i) k))
(ofLevel (f x) (f y))
hLevelRespectEquiv : {A : Type ℓ} {B : Type ℓ'} → (n : ℕ) → A ≃ B → isOfHLevel n A → isOfHLevel n B
hLevelRespectEquiv n eq = retractIsOfHLevel n (invEq eq) (eq .fst) (retEq eq)
-- hlevel of path and dependent path types
isProp→isPropPathP : {A : I → Type ℓ} (isPropA : ∀ i → isProp (A i))
(g : A i0) (h : A i1)
→ isProp (PathP A g h)
isProp→isPropPathP {A = A} isPropA g h =
transport⁻ (λ i → isProp (PathP≡Path A g h i)) (isProp→isSet (isPropA i1) _ _)
isProp→isContrPathP : {A : I → Type ℓ} (isPropA : ∀ i → isProp (A i))
(g : A i0) (h : A i1)
→ isContr (PathP A g h)
isProp→isContrPathP isPropA g h =
inhProp→isContr (isProp→PathP isPropA g h) (isProp→isPropPathP isPropA g h)
-- inhProp→isContr (isProp→PathP (λ i → isPropB (m i)) g h) (isProp→isPropPathP isPropB m g h)
isProp→isContr≡ : isProp A → (x y : A) → isContr (x ≡ y)
isProp→isContr≡ isPropA x y = inhProp→isContr (isPropA x y) (isProp→isSet isPropA x y)
isContrPath : isContr A → (x y : A) → isContr (x ≡ y)
isContrPath cA = isProp→isContr≡ (isContr→isProp cA)
hLevelPath : (n : ℕ) → isOfHLevel (suc n) A → (x y : A) → isOfHLevel n (x ≡ y)
hLevelPath zero h = isProp→isContr≡ h
hLevelPath (suc n) h = h
-- h-level of Σ-types
isContrSigma
: isContr A
→ ((x : A) → isContr (B x))
→ isContr (Σ[ x ∈ A ] B x)
isContrSigma {A = A} {B = B} (a , p) q =
let h : (x : A) (y : B x) → (q x) .fst ≡ y
h x y = (q x) .snd y
in (( a , q a .fst)
, ( λ x i → p (x .fst) i
, h (p (x .fst) i) (transp (λ j → B (p (x .fst) (i ∨ ~ j))) i (x .snd)) i))
ΣProp≡
: ((x : A) → isProp (B x)) → {u v : Σ[ a ∈ A ] B a}
→ (p : u .fst ≡ v .fst) → u ≡ v
ΣProp≡ pB {u} {v} p i = (p i) , isProp→PathP (λ i → pB (p i)) (u .snd) (v .snd) i
isPropSigma : isProp A → ((x : A) → isProp (B x)) → isProp (Σ[ x ∈ A ] B x)
isPropSigma pA pB t u = ΣProp≡ pB (pA (t .fst) (u .fst))
isOfHLevelΣ : ∀ n → isOfHLevel n A → ((x : A) → isOfHLevel n (B x))
→ isOfHLevel n (Σ A B)
isOfHLevelΣ 0 = isContrSigma
isOfHLevelΣ 1 = isPropSigma
isOfHLevelΣ {B = B} (suc (suc n)) h1 h2 x y =
let h3 : isOfHLevel (suc n) (x Σ≡T y)
h3 = isOfHLevelΣ (suc n) (h1 (fst x) (fst y)) λ p → h2 (p i1)
(subst B p (snd x)) (snd y)
in transport (λ i → isOfHLevel (suc n) (pathSigma≡sigmaPath x y (~ i))) h3
-- h-level of Π-types
propPi : (h : (x : A) → isProp (B x)) → isProp ((x : A) → B x)
propPi h f0 f1 i x = h x (f0 x) (f1 x) i
hLevelPi
: ∀ n
→ ((x : A) → isOfHLevel n (B x))
→ isOfHLevel n ((x : A) → B x)
hLevelPi 0 h = (λ x → fst (h x)) , λ f i y → snd (h y) (f y) i
hLevelPi {B = B} 1 h f g i x = (h x) (f x) (g x) i
hLevelPi (suc (suc n)) h f g =
subst (isOfHLevel (suc n)) funExtPath (hLevelPi (suc n) λ x → h x (f x) (g x))
isSetPi : ((x : A) → isSet (B x)) → isSet ((x : A) → B x)
isSetPi Bset = hLevelPi 2 (λ a → Bset a)
-- lower h-levels imply higher h-levels
hLevelSuc : (n : ℕ) (A : Type ℓ) → isOfHLevel n A → isOfHLevel (suc n) A
hLevelSuc 0 A = isContr→isProp
hLevelSuc 1 A = isProp→isSet
hLevelSuc (suc (suc n)) A h a b = hLevelSuc (suc n) (a ≡ b) (h a b)
hLevelLift : (m : ℕ) (hA : isOfHLevel n A) → isOfHLevel (m + n) A
hLevelLift zero hA = hA
hLevelLift {A = A} (suc m) hA = hLevelSuc _ A (hLevelLift m hA)
-- h-level of isOfHLevel
isPropIsProp : isProp (isProp A)
isPropIsProp f g i a b = isProp→isSet f a b (f a b) (g a b) i
isPropIsOfHLevel : (n : ℕ) (A : Type ℓ) → isProp (isOfHLevel n A)
isPropIsOfHLevel 0 A = isPropIsContr
isPropIsOfHLevel 1 A = isPropIsProp
isPropIsOfHLevel (suc (suc n)) A f g i a b =
isPropIsOfHLevel (suc n) (a ≡ b) (f a b) (g a b) i
isPropIsSet : isProp (isSet A)
isPropIsSet {A = A} = isPropIsOfHLevel 2 A
-- h-level of A ≃ B and A ≡ B
hLevel≃ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≃ B)
hLevel≃ zero {A = A} {B = B} hA hB = A≃B , contr
where
A≃B : A ≃ B
A≃B = isoToEquiv (iso (λ _ → fst hB) (λ _ → fst hA) (snd hB ) (snd hA))
contr : (y : A ≃ B) → A≃B ≡ y
contr y = ΣProp≡ isPropIsEquiv (funExt (λ a → snd hB (fst y a)))
hLevel≃ (suc n) hA hB =
isOfHLevelΣ (suc n) (hLevelPi (suc n) (λ _ → hB))
(λ a → subst (λ n → isOfHLevel n (isEquiv a)) (+-comm n 1) (hLevelLift n (isPropIsEquiv a)))
hLevel≡ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) →
isOfHLevel n (A ≡ B)
hLevel≡ n hA hB = hLevelRespectEquiv n (invEquiv univalence) (hLevel≃ n hA hB)
-- h-level of HLevel
HLevel≡ : ∀ {A B : Type ℓ} {hA : isOfHLevel n A} {hB : isOfHLevel n B} →
(A ≡ B) ≡ ((A , hA) ≡ (B , hB))
HLevel≡ {n = n} {A = A} {B = B} {hA} {hB} =
isoToPath (iso intro elim intro-elim elim-intro)
where
intro : A ≡ B → (A , hA) ≡ (B , hB)
intro eq = ΣProp≡ (λ A → isPropIsOfHLevel n _) eq
elim : (A , hA) ≡ (B , hB) → A ≡ B
elim = cong fst
intro-elim : ∀ x → intro (elim x) ≡ x
intro-elim eq = cong ΣPathP (ΣProp≡ (λ e →
J (λ B e →
∀ k → (x y : PathP (λ i → isOfHLevel n (e i)) hA k) → x ≡ y)
(λ k → isProp→isSet (isPropIsOfHLevel n _) _ _) e hB) refl)
elim-intro : ∀ x → elim (intro x) ≡ x
elim-intro eq = refl
isPropHContr : isProp (HLevel ℓ 0)
isPropHContr x y = ΣProp≡ (λ _ → isPropIsContr) ((hLevel≡ 0 (x .snd) (y .snd) .fst))
hLevelHLevel : ∀ n → isOfHLevel (suc n) (HLevel ℓ n)
hLevelHLevel 0 = isPropHContr
hLevelHLevel (suc n) x y = subst (λ e → isOfHLevel (suc n) e) HLevel≡ (hLevel≡ (suc n) (snd x) (snd y))
isSetHProp : isSet (hProp ℓ)
isSetHProp = hLevelHLevel 1
-- h-level of lifted type
isOfHLevelLift : ∀ {ℓ ℓ'} (n : ℕ) {A : Type ℓ} → isOfHLevel n A → isOfHLevel n (Lift {j = ℓ'} A)
isOfHLevelLift n = retractIsOfHLevel n lower lift λ _ → refl
| 34.760736
| 150
| 0.560272
|
52d244cbeca51f2af18ff7086cd58ba2c1bce9ca
| 441
|
agda
|
Agda
|
test/fail/ATPBadLocalHint3.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | 1
|
2016-03-17T01:45:59.000Z
|
2016-03-17T01:45:59.000Z
|
test/fail/ATPBadLocalHint3.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | null | null | null |
test/fail/ATPBadLocalHint3.agda
|
asr/eagda
|
7220bebfe9f64297880ecec40314c0090018fdd0
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- An ATP local hint can be only a postulate, function or a data
-- constructor.
-- This error is detected by Syntax.Translation.ConcreteToAbstract.
module ATPBadLocalHint3 where
postulate
D : Set
_≡_ : D → D → Set
zero : D
succ : D → D
data N : D → Set where
zN : N zero
sN : ∀ {n} → N n → N (succ n)
refl : ∀ n → N n → n ≡ n
refl n Nn = prf
where
postulate prf : n ≡ n
{-# ATP prove prf Nn #-}
| 19.173913
| 67
| 0.580499
|
38ff777486a62f4f78f59eccb6a579ed3fb676a5
| 953
|
agda
|
Agda
|
agda/MorePropAlgebra/Properties/AbGroup.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | 3
|
2020-07-31T18:15:26.000Z
|
2022-02-19T12:15:21.000Z
|
agda/MorePropAlgebra/Properties/AbGroup.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
agda/MorePropAlgebra/Properties/AbGroup.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts #-}
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Function.Base using (_∋_)
open import MorePropAlgebra.Bundles
import Cubical.Algebra.AbGroup as Std
module MorePropAlgebra.Properties.AbGroup {ℓ} (assumptions : AbGroup {ℓ}) where
open AbGroup assumptions renaming (Carrier to G)
import MorePropAlgebra.Properties.Group
module Group'Properties = MorePropAlgebra.Properties.Group (record { AbGroup assumptions })
module Group' = Group (record { AbGroup assumptions })
( Group') = Group ∋ (record { AbGroup assumptions })
stdIsAbGroup : Std.IsAbGroup 0g _+_ (-_)
stdIsAbGroup .Std.IsAbGroup.isGroup = Group'Properties.stdIsGroup
stdIsAbGroup .Std.IsAbGroup.comm = is-comm
stdAbGroup : Std.AbGroup {ℓ}
stdAbGroup = record { AbGroup assumptions ; isAbGroup = stdIsAbGroup }
| 41.434783
| 93
| 0.700944
|
3463427f0f7d0f4b5ca2fef2a2ceb9284e44f406
| 6,044
|
agda
|
Agda
|
src/rkt.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
src/rkt.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
src/rkt.agda
|
xoltar/cedille
|
acf691e37210607d028f4b19f98ec26c4353bfb5
|
[
"MIT"
] | null | null | null |
import cedille-options
module rkt (options : cedille-options.options) where
open import string
open import char
open import io
open import maybe
open import ctxt
open import list
open import trie
open import general-util
open import monad-instances
open import toplevel-state options {IO}
open import unit
open import bool
open import functions
open import product
open import cedille-types
open import syntax-util
private
rkt-dbg-flag = ff
rkt-dbg : string → rope → rope
rkt-dbg msg out = [[ if rkt-dbg-flag then ("; " ^ msg ^ "\n") else "" ]] ⊹⊹ out
-- constructs the name of a .racket directory for the given original directory
rkt-dirname : string → string
rkt-dirname dir = combineFileNames dir ".racket"
-- constructs the fully-qualified name of a .rkt file for a .ced file at the given ced-path
{-rkt-filename : (ced-path : string) → string
rkt-filename ced-path =
let dir = takeDirectory ced-path in
let unit-name = base-filename (takeFileName ced-path) in
combineFileNames (rkt-dirname dir) (unit-name ^ ".rkt")-}
-- sanitize a Cedille identifier for Racket
-- Racket does not allow "'" as part of a legal identifier,
-- so swamp this out for "."
rkt-iden : var → var
rkt-iden = 𝕃char-to-string
∘ ((map λ c → if c =char '\'' then '.' else c)
∘ string-to-𝕃char)
-- Racket string from erase Cedile term
rkt-from-term : term → rope
rkt-from-term (Lam _ KeptLam _ v _ tm)
= [[ "(lambda (" ]] ⊹⊹ [[ rkt-iden v ]] ⊹⊹ [[ ")" ]] ⊹⊹ rkt-from-term tm ⊹⊹ [[ ")" ]]
-- TODO untested
rkt-from-term (Let _ (DefTerm _ v _ tm-def) tm-body)
= [[ "(let ([" ]] ⊹⊹ [[ rkt-iden v ]] ⊹⊹ [[ " " ]] ⊹⊹ rkt-from-term tm-def ⊹⊹ [[ "]) " ]] ⊹⊹ rkt-from-term tm-body ⊹⊹ [[ ")\n" ]]
rkt-from-term (Var _ v)
= [[ rkt-iden v ]]
rkt-from-term (App tm₁ x tm₂)
= [[ "(" ]] ⊹⊹ rkt-from-term tm₁ ⊹⊹ [[ " " ]] ⊹⊹ rkt-from-term tm₂ ⊹⊹ [[ ")" ]]
rkt-from-term (Hole x)
= [[ "(error 'cedille-hole)" ]]
rkt-from-term (Beta _ _ NoTerm)
= [[ "(lambda (x) x)\n" ]]
rkt-from-term _
= rkt-dbg "unsupported/unknown term" [[]]
-- Racket define form from var, term
rkt-define : var → term → rope
rkt-define v tm = [[ "(define " ]] ⊹⊹ [[ rkt-iden v ]] ⊹⊹ rkt-from-term tm ⊹⊹ [[ ")" ]] ⊹⊹ [[ "\n" ]]
-- Racket require form from file
rkt-require-file : string → rope
rkt-require-file fp = [[ "(require (file \"" ]] ⊹⊹ [[ fp ]] ⊹⊹ [[ "\"))" ]]
-- Racket term from Cedille term sym-info
rkt-from-sym-info : string → sym-info → rope
rkt-from-sym-info n (term-def (just (ParamsCons (Decl _ _ _ v _ _) _)) _ tm ty , _)
-- TODO not tested
= rkt-dbg "term-def: paramsCons:" (rkt-define n tm)
rkt-from-sym-info n (term-def (just ParamsNil) _ tm ty , _)
= rkt-dbg "term-def: paramsNil:" (rkt-define n tm)
rkt-from-sym-info n (term-def nothing _ tm ty , b)
-- TODO not tested
= rkt-dbg "term-def: nothing:" (rkt-define n tm)
rkt-from-sym-info n (term-udef _ _ tm , _)
= rkt-dbg "term-udef:" (rkt-define n tm)
rkt-from-sym-info n (term-decl x , _)
= rkt-dbg "term-decl" [[]]
rkt-from-sym-info n (type-decl x , _)
= rkt-dbg "type-decl:" [[]]
rkt-from-sym-info n (type-def _ _ _ _ , _)
= rkt-dbg "type-def:" [[]]
rkt-from-sym-info n (kind-def _ _ , _)
= rkt-dbg "kind-def:" [[]]
rkt-from-sym-info n (rename-def v , _)
-- TODO Not implemented!
= rkt-dbg ("rename-def: " ^ v) [[]]
rkt-from-sym-info n (var-decl , _)
= rkt-dbg "var-decl:" [[]]
rkt-from-sym-info n (const-def _ , _)
= rkt-dbg "const-def:" [[]]
rkt-from-sym-info n (datatype-def _ _ , _)
= rkt-dbg "datatype-def:" [[]]
to-rkt-file : (ced-path : string) → ctxt → include-elt → ((cede-filename : string) → string) → rope
to-rkt-file ced-path (mk-ctxt _ (syms , _) i sym-occurences _) ie rkt-filename =
rkt-header ⊹⊹ rkt-body
where
cdle-pair = trie-lookup𝕃2 syms ced-path
cdle-mod = fst cdle-pair
cdle-defs = snd cdle-pair
qual-name : string → string
qual-name name = cdle-mod ^ "." ^ name
-- lang pragma, imports, and provides
rkt-header rkt-body : rope
rkt-header =
[[ "#lang racket\n\n" ]] ⊹⊹
foldr (λ fn x → rkt-require-file (rkt-filename fn) ⊹⊹ x)
[[ "\n" ]] (include-elt.deps ie) ⊹⊹
[[ "(provide (all-defined-out))\n\n" ]]
-- in reverse order: lookup symbol defs from file,
-- pair name with info, and convert to racket
rkt-body = foldr (λ {(n , s) x → x ⊹⊹
[[ "\n" ]] ⊹⊹ rkt-from-sym-info (qual-name n) s}) [[]]
(drop-nothing (map
(λ name → maybe-map (λ syminf → name , syminf)
(trie-lookup i (qual-name name)))
cdle-defs))
{-
-- write a Racket file to .racket subdirectory from Cedille file path,
-- context, and include-elt
write-rkt-file : (ced-path : string) → ctxt → include-elt → ((cede-filename : string) → string) → IO ⊤
write-rkt-file ced-path (mk-ctxt _ (syms , _) i sym-occurences) ie rkt-filename =
let dir = takeDirectory ced-path
in createDirectoryIfMissing tt (rkt-dirname dir) >>
writeFile (rkt-filename ced-path)
(rkt-header ^ rkt-body)
where
cdle-mod = fst (trie-lookup𝕃2 syms ced-path)
cdle-defs = snd (trie-lookup𝕃2 syms ced-path)
qual-name : string → string
qual-name name = cdle-mod ^ "." ^ name
-- lang pragma, imports, and provides
rkt-header rkt-body : string
rkt-header = "#lang racket\n\n"
^ (string-concat-sep "\n"
(map (rkt-require-file ∘ rkt-filename)
(include-elt.deps ie))) ^ "\n"
^ "(provide (all-defined-out))\n\n"
-- in reverse order: lookup symbol defs from file,
-- pair name with info, and convert to racket
rkt-body = string-concat-sep "\n"
(map (λ { (n , s) → rkt-from-sym-info (qual-name n) s})
(reverse (drop-nothing
(map (λ name →
maybe-map (λ syminf → name , syminf)
(trie-lookup i (qual-name name)))
cdle-defs))))
-}
| 36.630303
| 131
| 0.588021
|
0dc9c5dcc182723d6247555fe7cc8fc936c1ad8c
| 18,546
|
agda
|
Agda
|
core.agda
|
hazelgrove/agda-popl17
|
db3d21a1e3f17ef77ad557ed12374979f381b6b7
|
[
"MIT"
] | 14
|
2016-07-01T22:44:11.000Z
|
2019-07-11T12:30:50.000Z
|
core.agda
|
hazelgrove/agda-popl17
|
db3d21a1e3f17ef77ad557ed12374979f381b6b7
|
[
"MIT"
] | 37
|
2016-07-07T16:23:11.000Z
|
2016-11-09T18:13:55.000Z
|
core.agda
|
hazelgrove/agda-popl17
|
db3d21a1e3f17ef77ad557ed12374979f381b6b7
|
[
"MIT"
] | 1
|
2021-07-03T03:45:07.000Z
|
2021-07-03T03:45:07.000Z
|
open import Nat
open import Prelude
module core where
-- types
data τ̇ : Set where
num : τ̇
⦇-⦈ : τ̇
_==>_ : τ̇ → τ̇ → τ̇
-- expressions, prefixed with a · to distinguish name clashes with agda
-- built-ins
data ė : Set where
_·:_ : ė → τ̇ → ė
X : Nat → ė
·λ : Nat → ė → ė
N : Nat → ė
_·+_ : ė → ė → ė
⦇-⦈ : ė
⦇⌜_⌟⦈ : ė → ė
_∘_ : ė → ė → ė
---- contexts and some operations on them
-- variables are named with naturals in ė. therefore we represent
-- contexts as functions from names for variables (nats) to possible
-- bindings.
·ctx : Set
·ctx = Nat → Maybe τ̇
-- convenient shorthand for the (unique up to fun. ext.) empty context
∅ : ·ctx
∅ _ = None
-- add a new binding to the context, clobbering anything that might have
-- been there before.
_,,_ : ·ctx → (Nat × τ̇) → ·ctx
(Γ ,, (x , t)) y with natEQ x y
(Γ ,, (x , t)) .x | Inl refl = Some t
(Γ ,, (x , t)) y | Inr neq = Γ y
-- membership, or presence, in a context
_∈_ : (p : Nat × τ̇) → (Γ : ·ctx) → Set
(x , t) ∈ Γ = (Γ x) == Some t
-- apartness for contexts, so that we can follow barendregt's convention
_#_ : (n : Nat) → (Γ : ·ctx) → Set
x # Γ = (Γ x) == None
-- without: remove a variable from a context
_/_ : ·ctx → Nat → ·ctx
(Γ / x) y with natEQ x y
(Γ / x) .x | Inl refl = None
(Γ / x) y | Inr neq = Γ y
-- the type consistency judgement
data _~_ : (t1 : τ̇) → (t2 : τ̇) → Set where
TCRefl : {t : τ̇} → t ~ t
TCHole1 : {t : τ̇} → t ~ ⦇-⦈
TCHole2 : {t : τ̇} → ⦇-⦈ ~ t
TCArr : {t1 t2 t1' t2' : τ̇} →
t1 ~ t1' →
t2 ~ t2' →
(t1 ==> t2) ~ (t1' ==> t2')
-- type inconsistency. a judgmental version and associated proofs are in
-- judgemental-inconsistency.agda. each definition implies the other, but
-- the two are isomorphic only if you treat proofs of inconsistency at
-- arrow types as being proof-irrelevant---that is, if you don't
-- distinguish between cases where the inconsistency between a pair of
-- function types stems from the domain, range, or both. we use the form
-- below throughout the rest of the development because we do not care to
-- make that distinction.
_~̸_ : τ̇ → τ̇ → Set
t1 ~̸ t2 = (t1 ~ t2) → ⊥
--- matching for arrows
data _▸arr_ : τ̇ → τ̇ → Set where
MAHole : ⦇-⦈ ▸arr (⦇-⦈ ==> ⦇-⦈)
MAArr : {t1 t2 : τ̇} → (t1 ==> t2) ▸arr (t1 ==> t2)
-- matching produces unique answers
matcharrunicity : ∀{ t t2 t3 } →
t ▸arr t2 →
t ▸arr t3 →
t2 == t3
matcharrunicity MAHole MAHole = refl
matcharrunicity MAArr MAArr = refl
-- if a type matches, then it's consistent with the least restrictive
-- function type
matchconsist : ∀{t t'} →
t ▸arr t' →
t ~ (⦇-⦈ ==> ⦇-⦈)
matchconsist MAHole = TCHole2
matchconsist MAArr = TCArr TCHole1 TCHole1
matchnotnum : ∀{t1 t2} → num ▸arr (t1 ==> t2) → ⊥
matchnotnum ()
-- bidirectional type checking judgements for ė
mutual
-- synthesis
data _⊢_=>_ : (Γ : ·ctx) → (e : ė) → (t : τ̇) → Set where
SAsc : {Γ : ·ctx} {e : ė} {t : τ̇} →
Γ ⊢ e <= t →
Γ ⊢ (e ·: t) => t
SVar : {Γ : ·ctx} {t : τ̇} {n : Nat} →
(n , t) ∈ Γ →
Γ ⊢ X n => t
SAp : {Γ : ·ctx} {e1 e2 : ė} {t t' t2 : τ̇} →
Γ ⊢ e1 => t →
t ▸arr (t2 ==> t') →
Γ ⊢ e2 <= t2 →
Γ ⊢ (e1 ∘ e2) => t'
SNum : {Γ : ·ctx} {n : Nat} →
Γ ⊢ N n => num
SPlus : {Γ : ·ctx} {e1 e2 : ė} →
Γ ⊢ e1 <= num →
Γ ⊢ e2 <= num →
Γ ⊢ (e1 ·+ e2) => num
SEHole : {Γ : ·ctx} → Γ ⊢ ⦇-⦈ => ⦇-⦈
SNEHole : {Γ : ·ctx} {e : ė} {t : τ̇} →
Γ ⊢ e => t →
Γ ⊢ ⦇⌜ e ⌟⦈ => ⦇-⦈
-- analysis
data _⊢_<=_ : (Γ : ·ctx) → (e : ė) → (t : τ̇) → Set where
ASubsume : {Γ : ·ctx} {e : ė} {t t' : τ̇} →
Γ ⊢ e => t' →
t ~ t' →
Γ ⊢ e <= t
ALam : {Γ : ·ctx} {e : ė} {t t1 t2 : τ̇} {x : Nat} →
x # Γ →
t ▸arr (t1 ==> t2) →
(Γ ,, (x , t1)) ⊢ e <= t2 →
Γ ⊢ (·λ x e) <= t
----- some theorems about the rules and judgement presented so far.
-- a variable is apart from any context from which it is removed
aar : (Γ : ·ctx) (x : Nat) → x # (Γ / x)
aar Γ x with natEQ x x
aar Γ x | Inl refl = refl
aar Γ x | Inr x≠x = abort (x≠x refl)
-- contexts give at most one binding for each variable
ctxunicity : {Γ : ·ctx} {n : Nat} {t t' : τ̇} →
(n , t) ∈ Γ →
(n , t') ∈ Γ →
t == t'
ctxunicity {n = n} p q with natEQ n n
ctxunicity p q | Inl refl = someinj (! p · q)
ctxunicity _ _ | Inr x≠x = abort (x≠x refl)
-- type consistency is symmetric
~sym : {t1 t2 : τ̇} → t1 ~ t2 → t2 ~ t1
~sym TCRefl = TCRefl
~sym TCHole1 = TCHole2
~sym TCHole2 = TCHole1
~sym (TCArr p1 p2) = TCArr (~sym p1) (~sym p2)
-- type consistency isn't transitive
not-trans : ((t1 t2 t3 : τ̇) → t1 ~ t2 → t2 ~ t3 → t1 ~ t3) → ⊥
not-trans t with t (num ==> num) ⦇-⦈ num TCHole1 TCHole2
... | ()
-- if the domain or codomain of a pair of arrows isn't consistent, the
-- whole arrow isn't consistent.
lemarr1 : {t1 t2 t3 t4 : τ̇} → (t1 ~ t3 → ⊥) → (t1 ==> t2) ~ (t3 ==> t4) → ⊥
lemarr1 v TCRefl = v TCRefl
lemarr1 v (TCArr p _) = v p
lemarr2 : {t1 t2 t3 t4 : τ̇} → (t2 ~ t4 → ⊥) → (t1 ==> t2) ~ (t3 ==> t4) → ⊥
lemarr2 v TCRefl = v TCRefl
lemarr2 v (TCArr _ p) = v p
-- every pair of types is either consistent or not consistent
~dec : (t1 t2 : τ̇) → ((t1 ~ t2) + (t1 ~̸ t2))
-- this takes care of all hole cases, so we don't consider them below
~dec _ ⦇-⦈ = Inl TCHole1
~dec ⦇-⦈ _ = Inl TCHole2
-- num cases
~dec num num = Inl TCRefl
~dec num (t2 ==> t3) = Inr (λ ())
-- arrow cases
~dec (t1 ==> t2) num = Inr (λ ())
~dec (t1 ==> t2) (t3 ==> t4) with ~dec t1 t3 | ~dec t2 t4
... | Inl x | Inl y = Inl (TCArr x y)
... | Inl _ | Inr y = Inr (lemarr2 y)
... | Inr x | _ = Inr (lemarr1 x)
-- theorem: no pair of types is both consistent and not consistent. this
-- is immediate from our encoding of the ~̸ judgement in the formalism
-- here; in the exact mathematics presented in the paper, this would
-- require induction to relate the two judgements.
~apart : {t1 t2 : τ̇} → (t1 ~̸ t2) → (t1 ~ t2) → ⊥
~apart v p = v p
-- synthesis only produces equal types. note that there is no need for an
-- analagous theorem for analytic positions because we think of
-- the type as an input
synthunicity : {Γ : ·ctx} {e : ė} {t t' : τ̇} →
(Γ ⊢ e => t)
→ (Γ ⊢ e => t')
→ t == t'
synthunicity (SAsc _) (SAsc _) = refl
synthunicity {Γ = G} (SVar in1) (SVar in2) = ctxunicity {Γ = G} in1 in2
synthunicity (SAp D1 MAHole b) (SAp D2 MAHole y) = refl
synthunicity (SAp D1 MAHole b) (SAp D2 MAArr y) with synthunicity D1 D2
... | ()
synthunicity (SAp D1 MAArr b) (SAp D2 MAHole y) with synthunicity D1 D2
... | ()
synthunicity (SAp D1 MAArr b) (SAp D2 MAArr y) with synthunicity D1 D2
... | refl = refl
synthunicity SNum SNum = refl
synthunicity (SPlus _ _ ) (SPlus _ _ ) = refl
synthunicity SEHole SEHole = refl
synthunicity (SNEHole _) (SNEHole _) = refl
----- the zippered form of the forms above and the rules for actions on them
-- those types without holes anywhere
tcomplete : τ̇ → Set
tcomplete num = ⊤
tcomplete ⦇-⦈ = ⊥
tcomplete (t1 ==> t2) = (tcomplete t1) × (tcomplete t2)
-- similarly to the complete types, the complete expressions
ecomplete : ė → Set
ecomplete (e1 ·: t) = ecomplete e1 × tcomplete t
ecomplete (X _) = ⊤
ecomplete (·λ _ e1) = ecomplete e1
ecomplete (N x) = ⊤
ecomplete (e1 ·+ e2) = ecomplete e1 × ecomplete e2
ecomplete ⦇-⦈ = ⊥
ecomplete ⦇⌜ e1 ⌟⦈ = ⊥
ecomplete (e1 ∘ e2) = ecomplete e1 × ecomplete e2
-- zippered form of types
data τ̂ : Set where
▹_◃ : τ̇ → τ̂
_==>₁_ : τ̂ → τ̇ → τ̂
_==>₂_ : τ̇ → τ̂ → τ̂
-- zippered form of expressions
data ê : Set where
▹_◃ : ė → ê
_·:₁_ : ê → τ̇ → ê
_·:₂_ : ė → τ̂ → ê
·λ : Nat → ê → ê
_∘₁_ : ê → ė → ê
_∘₂_ : ė → ê → ê
_·+₁_ : ê → ė → ê
_·+₂_ : ė → ê → ê
⦇⌜_⌟⦈ : ê → ê
-- erasure of cursor for types and expressions, judgementally. see
-- jugemental-erase.agda for an argument that this defines an isomorphic
-- object to the direct metafunction provided in the text of the paper
data erase-t : τ̂ → τ̇ → Set where
ETTop : ∀{t} → erase-t (▹ t ◃) t
ETArrL : ∀{t1 t1' t2} → erase-t t1 t1' → erase-t (t1 ==>₁ t2) (t1' ==> t2)
ETArrR : ∀{t1 t2 t2'} → erase-t t2 t2' → erase-t (t1 ==>₂ t2) (t1 ==> t2')
data erase-e : ê → ė → Set where
EETop : ∀{x} → erase-e (▹ x ◃) x
EEAscL : ∀{e e' t} → erase-e e e' → erase-e (e ·:₁ t) (e' ·: t)
EEAscR : ∀{e t t'} → erase-t t t' → erase-e (e ·:₂ t) (e ·: t')
EELam : ∀{x e e'} → erase-e e e' → erase-e (·λ x e) (·λ x e')
EEApL : ∀{e1 e1' e2} → erase-e e1 e1' → erase-e (e1 ∘₁ e2) (e1' ∘ e2)
EEApR : ∀{e1 e2 e2'} → erase-e e2 e2' → erase-e (e1 ∘₂ e2) (e1 ∘ e2')
EEPlusL : ∀{e1 e1' e2} → erase-e e1 e1' → erase-e (e1 ·+₁ e2) (e1' ·+ e2)
EEPlusR : ∀{e1 e2 e2'} → erase-e e2 e2' → erase-e (e1 ·+₂ e2) (e1 ·+ e2')
EENEHole : ∀{e e'} → erase-e e e' → erase-e ⦇⌜ e ⌟⦈ ⦇⌜ e' ⌟⦈
-- the three grammars that define actions
data direction : Set where
child : Nat → direction
parent : direction
data shape : Set where
arrow : shape
num : shape
asc : shape
var : Nat → shape
lam : Nat → shape
ap : shape
numlit : Nat → shape
plus : shape
nehole : shape
data action : Set where
move : direction → action
construct : shape → action
del : action
finish : action
-- type actions
data _+_+>_ : (t : τ̂) → (α : action) → (t' : τ̂) → Set where
TMArrChild1 : {t1 t2 : τ̇} →
▹ t1 ==> t2 ◃ + move (child 1) +> (▹ t1 ◃ ==>₁ t2)
TMArrChild2 : {t1 t2 : τ̇} →
▹ t1 ==> t2 ◃ + move (child 2) +> (t1 ==>₂ ▹ t2 ◃)
TMArrParent1 : {t1 t2 : τ̇} →
(▹ t1 ◃ ==>₁ t2) + move parent +> ▹ t1 ==> t2 ◃
TMArrParent2 : {t1 t2 : τ̇} →
(t1 ==>₂ ▹ t2 ◃) + move parent +> ▹ t1 ==> t2 ◃
TMDel : {t : τ̇} →
(▹ t ◃) + del +> (▹ ⦇-⦈ ◃)
TMConArrow : {t : τ̇} →
(▹ t ◃) + construct arrow +> (t ==>₂ ▹ ⦇-⦈ ◃)
TMConNum : (▹ ⦇-⦈ ◃) + construct num +> (▹ num ◃)
TMArrZip1 : {t1 t1' : τ̂} {t2 : τ̇} {α : action} →
(t1 + α +> t1') →
((t1 ==>₁ t2) + α +> (t1' ==>₁ t2))
TMArrZip2 : {t2 t2' : τ̂} {t1 : τ̇} {α : action} →
(t2 + α +> t2') →
((t1 ==>₂ t2) + α +> (t1 ==>₂ t2'))
-- expression movement
data _+_+>e_ : (e : ê) → (α : action) → (e' : ê) → Set where
-- rules for ascriptions
EMAscChild1 : {e : ė} {t : τ̇} →
(▹ e ·: t ◃) + move (child 1) +>e (▹ e ◃ ·:₁ t)
EMAscChild2 : {e : ė} {t : τ̇} →
(▹ e ·: t ◃) + move (child 2) +>e (e ·:₂ ▹ t ◃)
EMAscParent1 : {e : ė} {t : τ̇} →
(▹ e ◃ ·:₁ t) + move parent +>e (▹ e ·: t ◃)
EMAscParent2 : {e : ė} {t : τ̇} →
(e ·:₂ ▹ t ◃) + move parent +>e (▹ e ·: t ◃)
-- rules for lambdas
EMLamChild1 : {e : ė} {x : Nat} →
▹ (·λ x e) ◃ + move (child 1) +>e ·λ x (▹ e ◃)
EMLamParent : {e : ė} {x : Nat} →
·λ x (▹ e ◃) + move parent +>e ▹ (·λ x e) ◃
-- rules for 2-ary constructors
EMPlusChild1 : {e1 e2 : ė} →
(▹ e1 ·+ e2 ◃) + move (child 1) +>e (▹ e1 ◃ ·+₁ e2)
EMPlusChild2 : {e1 e2 : ė} →
(▹ e1 ·+ e2 ◃) + move (child 2) +>e (e1 ·+₂ ▹ e2 ◃)
EMPlusParent1 : {e1 e2 : ė} →
(▹ e1 ◃ ·+₁ e2) + move parent +>e (▹ e1 ·+ e2 ◃)
EMPlusParent2 : {e1 e2 : ė} →
(e1 ·+₂ ▹ e2 ◃) + move parent +>e (▹ e1 ·+ e2 ◃)
EMApChild1 : {e1 e2 : ė} →
(▹ e1 ∘ e2 ◃) + move (child 1)+>e (▹ e1 ◃ ∘₁ e2)
EMApChild2 : {e1 e2 : ė} →
(▹ e1 ∘ e2 ◃) + move (child 2) +>e (e1 ∘₂ ▹ e2 ◃)
EMApParent1 : {e1 e2 : ė} →
(▹ e1 ◃ ∘₁ e2) + move parent +>e (▹ e1 ∘ e2 ◃)
EMApParent2 : {e1 e2 : ė} →
(e1 ∘₂ ▹ e2 ◃) + move parent +>e (▹ e1 ∘ e2 ◃)
-- rules for non-empty holes
EMNEHoleChild1 : {e : ė} →
(▹ ⦇⌜ e ⌟⦈ ◃) + move (child 1) +>e ⦇⌜ ▹ e ◃ ⌟⦈
EMNEHoleParent : {e : ė} →
⦇⌜ ▹ e ◃ ⌟⦈ + move parent +>e (▹ ⦇⌜ e ⌟⦈ ◃)
mutual
-- synthetic action expressions
data _⊢_=>_~_~>_=>_ : (Γ : ·ctx) → (e1 : ê) → (t1 : τ̇)
→ (α : action) → (e2 : ê) → (t2 : τ̇) → Set where
SAMove : {δ : direction} {e e' : ê} {Γ : ·ctx} {t : τ̇} →
(e + move δ +>e e') →
Γ ⊢ e => t ~ move δ ~> e' => t
SADel : {Γ : ·ctx} {e : ė} {t : τ̇} →
Γ ⊢ ▹ e ◃ => t ~ del ~> ▹ ⦇-⦈ ◃ => ⦇-⦈
SAConAsc : {Γ : ·ctx} {e : ė} {t : τ̇} →
Γ ⊢ ▹ e ◃ => t ~ construct asc ~> (e ·:₂ ▹ t ◃ ) => t
SAConVar : {Γ : ·ctx} {x : Nat} {t : τ̇} →
(p : (x , t) ∈ Γ) →
Γ ⊢ ▹ ⦇-⦈ ◃ => ⦇-⦈ ~ construct (var x) ~> ▹ X x ◃ => t
SAConLam : {Γ : ·ctx} {x : Nat} →
(x # Γ) →
Γ ⊢ ▹ ⦇-⦈ ◃ => ⦇-⦈ ~ construct (lam x) ~>
((·λ x ⦇-⦈) ·:₂ (▹ ⦇-⦈ ◃ ==>₁ ⦇-⦈)) => (⦇-⦈ ==> ⦇-⦈)
SAConApArr : {Γ : ·ctx} {t t1 t2 : τ̇} {e : ė} →
t ▸arr (t1 ==> t2) →
Γ ⊢ ▹ e ◃ => t ~ construct ap ~> e ∘₂ ▹ ⦇-⦈ ◃ => t2
SAConApOtw : {Γ : ·ctx} {t : τ̇} {e : ė} →
(t ~̸ (⦇-⦈ ==> ⦇-⦈)) →
Γ ⊢ ▹ e ◃ => t ~ construct ap ~> ⦇⌜ e ⌟⦈ ∘₂ ▹ ⦇-⦈ ◃ => ⦇-⦈
SAConNumlit : {Γ : ·ctx} {n : Nat} →
Γ ⊢ ▹ ⦇-⦈ ◃ => ⦇-⦈ ~ construct (numlit n) ~> ▹ N n ◃ => num
SAConPlus1 : {Γ : ·ctx} {e : ė} {t : τ̇} →
(t ~ num) →
Γ ⊢ ▹ e ◃ => t ~ construct plus ~> e ·+₂ ▹ ⦇-⦈ ◃ => num
SAConPlus2 : {Γ : ·ctx} {e : ė} {t : τ̇} →
(t ~̸ num) →
Γ ⊢ ▹ e ◃ => t ~ construct plus ~> ⦇⌜ e ⌟⦈ ·+₂ ▹ ⦇-⦈ ◃ => num
SAConNEHole : {Γ : ·ctx} {e : ė} {t : τ̇} →
Γ ⊢ ▹ e ◃ => t ~ construct nehole ~> ⦇⌜ ▹ e ◃ ⌟⦈ => ⦇-⦈
SAFinish : {Γ : ·ctx} {e : ė} {t : τ̇} →
(Γ ⊢ e => t) →
Γ ⊢ ▹ ⦇⌜ e ⌟⦈ ◃ => ⦇-⦈ ~ finish ~> ▹ e ◃ => t
SAZipAsc1 : {Γ : ·ctx} {e e' : ê} {α : action} {t : τ̇} →
(Γ ⊢ e ~ α ~> e' ⇐ t) →
Γ ⊢ (e ·:₁ t) => t ~ α ~> (e' ·:₁ t) => t
SAZipAsc2 : {Γ : ·ctx} {e : ė} {α : action} {t t' : τ̂} {t◆ t'◆ : τ̇} →
(t + α +> t') →
(erase-t t' t'◆) →
(erase-t t t◆) →
(Γ ⊢ e <= t'◆) →
Γ ⊢ (e ·:₂ t) => t◆ ~ α ~> (e ·:₂ t') => t'◆
SAZipApArr : {Γ : ·ctx} {t t1 t2 t3 t4 : τ̇} {α : action} {eh eh' : ê} {e eh◆ : ė} →
(t ▸arr (t3 ==> t4)) →
(erase-e eh eh◆) →
(Γ ⊢ (eh◆) => t2) →
(Γ ⊢ eh => t2 ~ α ~> eh' => t) →
(Γ ⊢ e <= t3) →
Γ ⊢ (eh ∘₁ e) => t1 ~ α ~> (eh' ∘₁ e) => t4
SAZipApAna : {Γ : ·ctx} {t' t2 t : τ̇} {e : ė} {eh eh' : ê} {α : action} →
(t' ▸arr (t2 ==> t)) →
(Γ ⊢ e => t') →
(Γ ⊢ eh ~ α ~> eh' ⇐ t2) →
Γ ⊢ (e ∘₂ eh) => t ~ α ~> (e ∘₂ eh') => t
SAZipPlus1 : {Γ : ·ctx} {e : ė} {eh eh' : ê} {α : action} →
(Γ ⊢ eh ~ α ~> eh' ⇐ num) →
Γ ⊢ (eh ·+₁ e) => num ~ α ~> (eh' ·+₁ e) => num
SAZipPlus2 : {Γ : ·ctx} {e : ė} {eh eh' : ê} {α : action} →
(Γ ⊢ eh ~ α ~> eh' ⇐ num) →
Γ ⊢ (e ·+₂ eh) => num ~ α ~> (e ·+₂ eh') => num
SAZipHole : {Γ : ·ctx} {e e' : ê} {t t' : τ̇} {α : action} {e◆ : ė} →
(erase-e e e◆) →
(Γ ⊢ e◆ => t) →
(Γ ⊢ e => t ~ α ~> e' => t') →
Γ ⊢ ⦇⌜ e ⌟⦈ => ⦇-⦈ ~ α ~> ⦇⌜ e' ⌟⦈ => ⦇-⦈
-- analytic action expressions
data _⊢_~_~>_⇐_ : (Γ : ·ctx) → (e : ê) → (α : action) →
(e' : ê) → (t : τ̇) → Set where
AASubsume : {Γ : ·ctx} {e e' : ê} {t t' t'' : τ̇} {α : action} {e◆ : ė} →
(erase-e e e◆) →
(Γ ⊢ e◆ => t') →
(Γ ⊢ e => t' ~ α ~> e' => t'') →
(t ~ t'') →
Γ ⊢ e ~ α ~> e' ⇐ t
AAMove : {e e' : ê} {δ : direction} {Γ : ·ctx} {t : τ̇} →
(e + move δ +>e e') →
Γ ⊢ e ~ move δ ~> e' ⇐ t
AADel : {e : ė} {Γ : ·ctx} {t : τ̇} →
Γ ⊢ ▹ e ◃ ~ del ~> ▹ ⦇-⦈ ◃ ⇐ t
AAConAsc : {Γ : ·ctx} {e : ė} {t : τ̇} →
Γ ⊢ ▹ e ◃ ~ construct asc ~> (e ·:₂ ▹ t ◃) ⇐ t
AAConVar : {Γ : ·ctx} {t t' : τ̇} {x : Nat} →
(t ~̸ t') →
(p : (x , t') ∈ Γ) →
Γ ⊢ ▹ ⦇-⦈ ◃ ~ construct (var x) ~> ⦇⌜ ▹ X x ◃ ⌟⦈ ⇐ t
AAConLam1 : {Γ : ·ctx} {x : Nat} {t t1 t2 : τ̇} →
(x # Γ) →
(t ▸arr (t1 ==> t2)) →
Γ ⊢ ▹ ⦇-⦈ ◃ ~ construct (lam x) ~>
·λ x (▹ ⦇-⦈ ◃) ⇐ t
AAConLam2 : {Γ : ·ctx} {x : Nat} {t : τ̇} →
(x # Γ) →
(t ~̸ (⦇-⦈ ==> ⦇-⦈)) →
Γ ⊢ ▹ ⦇-⦈ ◃ ~ construct (lam x) ~>
⦇⌜ ·λ x ⦇-⦈ ·:₂ (▹ ⦇-⦈ ◃ ==>₁ ⦇-⦈) ⌟⦈ ⇐ t
AAConNumlit : {Γ : ·ctx} {t : τ̇} {n : Nat} →
(t ~̸ num) →
Γ ⊢ ▹ ⦇-⦈ ◃ ~ construct (numlit n) ~> ⦇⌜ ▹ (N n) ◃ ⌟⦈ ⇐ t
AAFinish : {Γ : ·ctx} {e : ė} {t : τ̇} →
(Γ ⊢ e <= t) →
Γ ⊢ ▹ ⦇⌜ e ⌟⦈ ◃ ~ finish ~> ▹ e ◃ ⇐ t
AAZipLam : {Γ : ·ctx} {x : Nat} {t t1 t2 : τ̇} {e e' : ê} {α : action} →
x # Γ →
(t ▸arr (t1 ==> t2)) →
((Γ ,, (x , t1)) ⊢ e ~ α ~> e' ⇐ t2) →
Γ ⊢ (·λ x e) ~ α ~> (·λ x e') ⇐ t
| 39.044211
| 92
| 0.407797
|
7ca4cdca84232603cd1af2addb20962547ef88a8
| 559
|
agda
|
Agda
|
test/Fail/Issue2253.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2253.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2253.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-08-24, issue #2253
--
-- Better error message for matching on abstract constructor.
-- {-# OPTIONS -v tc.lhs.split:30 #-}
-- {-# OPTIONS -v tc.lhs:30 #-}
-- {-# OPTIONS -v tc.lhs.flex:60 #-}
abstract
data B : Set where
x : B
data C : Set where
c : B → C
f : C → C
f (c x) = c x
-- WAS:
--
-- Not in scope:
-- AbstractPatternShadowsConstructor.B.x
-- (did you mean 'x'?)
-- when checking that the pattern c x has type C
-- Expected:
--
-- Cannot split on abstract data type B
-- when checking that the pattern x has type B
| 18.633333
| 61
| 0.613596
|
43014719abbb1e56727573588132745f3edf89b8
| 3,206
|
agda
|
Agda
|
prototyping/FFI/Data/Aeson.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | 1
|
2021-11-06T08:03:00.000Z
|
2021-11-06T08:03:00.000Z
|
prototyping/FFI/Data/Aeson.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
prototyping/FFI/Data/Aeson.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting #-}
module FFI.Data.Aeson where
open import Agda.Builtin.Equality using (_≡_)
open import Agda.Builtin.Equality.Rewrite using ()
open import Agda.Builtin.Bool using (Bool)
open import Agda.Builtin.String using (String)
open import FFI.Data.ByteString using (ByteString)
open import FFI.Data.HaskellString using (HaskellString; pack)
open import FFI.Data.Maybe using (Maybe; just; nothing)
open import FFI.Data.Either using (Either; mapL)
open import FFI.Data.Scientific using (Scientific)
open import FFI.Data.Vector using (Vector)
open import Properties.Equality using (_≢_)
{-# FOREIGN GHC import qualified Data.Aeson #-}
{-# FOREIGN GHC import qualified Data.Aeson.Key #-}
{-# FOREIGN GHC import qualified Data.Aeson.KeyMap #-}
postulate
KeyMap : Set → Set
Key : Set
fromString : String → Key
toString : Key → String
empty : ∀ {A} → KeyMap A
singleton : ∀ {A} → Key → A → (KeyMap A)
insert : ∀ {A} → Key → A → (KeyMap A) → (KeyMap A)
delete : ∀ {A} → Key → (KeyMap A) → (KeyMap A)
unionWith : ∀ {A} → (A → A → A) → (KeyMap A) → (KeyMap A) → (KeyMap A)
lookup : ∀ {A} → Key -> KeyMap A -> Maybe A
{-# POLARITY KeyMap ++ #-}
{-# COMPILE GHC KeyMap = type Data.Aeson.KeyMap.KeyMap #-}
{-# COMPILE GHC Key = type Data.Aeson.Key.Key #-}
{-# COMPILE GHC fromString = Data.Aeson.Key.fromText #-}
{-# COMPILE GHC toString = Data.Aeson.Key.toText #-}
{-# COMPILE GHC empty = \_ -> Data.Aeson.KeyMap.empty #-}
{-# COMPILE GHC singleton = \_ -> Data.Aeson.KeyMap.singleton #-}
{-# COMPILE GHC insert = \_ -> Data.Aeson.KeyMap.insert #-}
{-# COMPILE GHC delete = \_ -> Data.Aeson.KeyMap.delete #-}
{-# COMPILE GHC unionWith = \_ -> Data.Aeson.KeyMap.unionWith #-}
{-# COMPILE GHC lookup = \_ -> Data.Aeson.KeyMap.lookup #-}
postulate lookup-insert : ∀ {A} k v (m : KeyMap A) → (lookup k (insert k v m) ≡ just v)
postulate lookup-empty : ∀ {A} k → (lookup {A} k empty ≡ nothing)
postulate lookup-insert-not : ∀ {A} j k v (m : KeyMap A) → (j ≢ k) → (lookup k m ≡ lookup k (insert j v m))
postulate singleton-insert-empty : ∀ {A} k (v : A) → (singleton k v ≡ insert k v empty)
postulate insert-swap : ∀ {A} j k (v w : A) m → (j ≢ k) → insert j v (insert k w m) ≡ insert k w (insert j v m)
postulate insert-over : ∀ {A} j k (v w : A) m → (j ≡ k) → insert j v (insert k w m) ≡ insert j v m
postulate to-from : ∀ k → toString(fromString k) ≡ k
postulate from-to : ∀ k → fromString(toString k) ≡ k
{-# REWRITE lookup-insert lookup-empty singleton-insert-empty #-}
data Value : Set where
object : KeyMap Value → Value
array : Vector Value → Value
string : String → Value
number : Scientific → Value
bool : Bool → Value
null : Value
{-# COMPILE GHC Value = data Data.Aeson.Value (Data.Aeson.Object|Data.Aeson.Array|Data.Aeson.String|Data.Aeson.Number|Data.Aeson.Bool|Data.Aeson.Null) #-}
Object = KeyMap Value
Array = Vector Value
postulate
decode : ByteString → Maybe Value
eitherHDecode : ByteString → Either HaskellString Value
{-# COMPILE GHC decode = Data.Aeson.decodeStrict #-}
{-# COMPILE GHC eitherHDecode = Data.Aeson.eitherDecodeStrict #-}
eitherDecode : ByteString → Either String Value
eitherDecode bytes = mapL pack (eitherHDecode bytes)
| 41.102564
| 154
| 0.674672
|
0487c1383326e10304ab8051155937a05aff8d94
| 6,861
|
agda
|
Agda
|
src/Unification.agda
|
wenkokke/AutoInAgda
|
f384b5c236645fcf8ab93179723a7355383a8716
|
[
"MIT"
] | 22
|
2017-07-18T18:14:09.000Z
|
2021-03-20T15:04:47.000Z
|
src/Unification.agda
|
wenkokke/AutoInAgda
|
f384b5c236645fcf8ab93179723a7355383a8716
|
[
"MIT"
] | 1
|
2017-11-03T09:46:19.000Z
|
2017-11-06T16:49:27.000Z
|
src/Unification.agda
|
wenkokke/AutoInAgda
|
f384b5c236645fcf8ab93179723a7355383a8716
|
[
"MIT"
] | 2
|
2018-07-10T10:47:30.000Z
|
2019-07-07T07:37:07.000Z
|
open import Function using (_∘_)
open import Category.Monad using (module RawMonad)
open import Data.Fin using (Fin; suc; zero)
open import Data.Fin.Properties renaming (_≟_ to _≟-Fin_)
open import Data.List as List using (List; _∷_; [])
open import Data.List.Properties renaming (∷-injective to ∷-inj)
open import Data.Maybe as Maybe using (Maybe; just; nothing)
open import Data.Nat using (ℕ; suc; zero)
open import Data.Product as Prod using (∃; _×_; _,_; proj₁; proj₂)
open import Relation.Nullary using (Dec; yes; no)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; cong₂)
module Unification
(Name : Set) (_≟-Name_ : (x y : Name) → Dec (x ≡ y))
(Literal : Set) (_≟-Literal_ : (x y : Literal) → Dec (x ≡ y))
where
open RawMonad {{...}} using (_<$>_; _>>=_; return)
private
instance
MaybeMonad = Maybe.monad
data Term (n : ℕ) : Set where
var : (x : Fin n) → Term n
con : (s : Name) (ts : List (Term n)) → Term n
lit : (l : Literal) → Term n
-- ext : (x : Fin (suc n)) (t : Term (suc n)) → Term n
var-inj : ∀ {n x₁ x₂} → var {n} x₁ ≡ var {n} x₂ → x₁ ≡ x₂
var-inj refl = refl
con-inj : ∀ {n s₁ s₂ ts₁ ts₂} → con {n} s₁ ts₁ ≡ con {n} s₂ ts₂ → s₁ ≡ s₂ × ts₁ ≡ ts₂
con-inj refl = (refl , refl)
lit-inj : ∀ {n x₁ x₂} → lit {n} x₁ ≡ lit {n} x₂ → x₁ ≡ x₂
lit-inj refl = refl
mutual
_≟-Term_ : ∀ {n} → (t₁ t₂ : Term n) → Dec (t₁ ≡ t₂)
_≟-Term_ (var _) (lit _) = no (λ ())
_≟-Term_ (var _) (con _ _) = no (λ ())
_≟-Term_ (var x₁) (var x₂) with x₁ ≟-Fin x₂
... | yes x₁=x₂ = yes (cong var x₁=x₂)
... | no x₁≠x₂ = no (x₁≠x₂ ∘ var-inj)
_≟-Term_ (con _ _) (var _) = no (λ ())
_≟-Term_ (con _ _) (lit _) = no (λ ())
_≟-Term_ (con s₁ ts₁) (con s₂ ts₂) with s₁ ≟-Name s₂
... | no s₁≠s₂ = no (s₁≠s₂ ∘ proj₁ ∘ con-inj)
... | yes s₁=s₂ rewrite s₁=s₂ with ts₁ ≟-Terms ts₂
... | no ts₁≠ts₂ = no (ts₁≠ts₂ ∘ proj₂ ∘ con-inj)
... | yes ts₁=ts₂ = yes (cong (con s₂) ts₁=ts₂)
_≟-Term_ (lit _) (var _) = no (λ ())
_≟-Term_ (lit _) (con _ _) = no (λ ())
_≟-Term_ (lit x₁) (lit x₂) with x₁ ≟-Literal x₂
... | yes x₁=x₂ = yes (cong lit x₁=x₂)
... | no x₁≠x₂ = no (x₁≠x₂ ∘ lit-inj)
_≟-Terms_ : ∀ {n} (xs ys : List (Term n)) → Dec (xs ≡ ys)
_≟-Terms_ [] [] = yes refl
_≟-Terms_ [] (_ ∷ _) = no (λ ())
_≟-Terms_ (_ ∷ _) [] = no (λ ())
_≟-Terms_ (x ∷ xs) (y ∷ ys) with x ≟-Term y
... | no x≠y = no (x≠y ∘ proj₁ ∘ ∷-inj)
... | yes x=y with xs ≟-Terms ys
... | no xs≠ys = no (xs≠ys ∘ proj₂ ∘ ∷-inj)
... | yes xs=ys = yes (cong₂ _∷_ x=y xs=ys)
-- defining thick and thin
thin : {n : ℕ} → Fin (suc n) → Fin n → Fin (suc n)
thin zero y = suc y
thin (suc x) zero = zero
thin (suc x) (suc y) = suc (thin x y)
thick : {n : ℕ} → (x y : Fin (suc n)) → Maybe (Fin n)
thick zero zero = nothing
thick zero (suc y) = just y
thick {zero} (suc ()) _
thick {suc n} (suc x) zero = just zero
thick {suc n} (suc x) (suc y) = suc <$> thick x y
-- defining replacement function (written _◂ in McBride, 2003)
replace : ∀ {n m} → (Fin n → Term m) → Term n → Term m
replace _ (lit l) = lit l
replace f (var i) = f i
replace f (con s ts) = con s (replaceChildren f ts)
where
replaceChildren : ∀ {n m} → (Fin n → Term m) → (List (Term n) → List (Term m))
replaceChildren f [] = []
replaceChildren f (x ∷ xs) = replace f x ∷ (replaceChildren f xs)
-- defining replacement composition
_◇_ : ∀ {m n l} (f : Fin m → Term n) (g : Fin l → Term m) → Fin l → Term n
_◇_ f g = replace f ∘ g
-- defining an occurs check (**check** in McBride, 2003)
check : ∀ {n} (x : Fin (suc n)) (t : Term (suc n)) → Maybe (Term n)
check _ (lit l) = just (lit l)
check x₁ (var x₂) = var <$> thick x₁ x₂
check x₁ (con s ts) = con s <$> checkChildren x₁ ts
where
checkChildren : ∀ {n} (x : Fin (suc n)) (ts : List (Term (suc n))) → Maybe (List (Term n))
checkChildren x₁ [] = just []
checkChildren x₁ (t ∷ ts) = check x₁ t >>= λ t' →
checkChildren x₁ ts >>= λ ts' → return (t' ∷ ts')
-- datatype for substitutions (AList in McBride, 2003)
data Subst : ℕ → ℕ → Set where
nil : ∀ {n} → Subst n n
snoc : ∀ {m n} → (s : Subst m n) → (t : Term m) → (x : Fin (suc m)) → Subst (suc m) n
-- substitutes t for x (**for** in McBride, 2003)
_for_ : ∀ {n} (t : Term n) (x : Fin (suc n)) → Fin (suc n) → Term n
_for_ t x y with thick x y
_for_ t x y | just y' = var y'
_for_ t x y | nothing = t
-- substitution application (**sub** in McBride, 2003)
sub : ∀ {m n} → Subst m n → Fin m → Term n
sub nil = var
sub (snoc s t x) = (sub s) ◇ (t for x)
-- composes two substitutions
_++_ : ∀ {l m n} → Subst m n → Subst l m → Subst l n
s₁ ++ nil = s₁
s₁ ++ (snoc s₂ t x) = snoc (s₁ ++ s₂) t x
flexRigid : ∀ {n} → Fin n → Term n → Maybe (∃ (Subst n))
flexRigid {zero} () t
flexRigid {suc n} x t with check x t
flexRigid {suc n} x t | nothing = nothing
flexRigid {suc n} x t | just t' = just (n , snoc nil t' x)
flexFlex : ∀ {n} → (x y : Fin n) → ∃ (Subst n)
flexFlex {zero} () j
flexFlex {suc n} x y with thick x y
flexFlex {suc n} x y | nothing = (suc n , nil)
flexFlex {suc n} x y | just z = (n , snoc nil (var z) x)
mutual
unifyAcc : ∀ {m} → (t₁ t₂ : Term m) → ∃ (Subst m) → Maybe (∃ (Subst m))
unifyAcc (lit x₁) (lit x₂) (n , nil) with x₁ ≟-Literal x₂
... | yes x₁=x₂ rewrite x₁=x₂ = just (n , nil)
... | no x₁≠x₂ = nothing
unifyAcc (con s ts) (lit x) (n , nil) = nothing
unifyAcc (lit x) (con s ts) (n , nil) = nothing
unifyAcc (con s₁ ts₁) (con s₂ ts₂) acc with s₁ ≟-Name s₂
... | yes s₁=s₂ rewrite s₁=s₂ = unifyAccChildren ts₁ ts₂ acc
... | no s₁≠s₂ = nothing
unifyAcc (var x₁) (var x₂) (n , nil) = just (flexFlex x₁ x₂)
unifyAcc t (var x) (n , nil) = flexRigid x t
unifyAcc (var x) t (n , nil) = flexRigid x t
unifyAcc t₁ t₂ (n , snoc s t′ x) =
( λ s → proj₁ s , snoc (proj₂ s) t′ x )
<$> unifyAcc (replace (t′ for x) t₁) (replace (t′ for x) t₂) (n , s)
unifyAccChildren : ∀ {n} → (ts₁ ts₂ : List (Term n)) → ∃ (Subst n) → Maybe (∃ (Subst n))
unifyAccChildren [] [] acc = just acc
unifyAccChildren [] _ _ = nothing
unifyAccChildren _ [] _ = nothing
unifyAccChildren (t₁ ∷ ts₁) (t₂ ∷ ts₂) acc = unifyAcc t₁ t₂ acc >>= unifyAccChildren ts₁ ts₂
unify : ∀ {m} → (t₁ t₂ : Term m) → Maybe (∃ (Subst m))
unify {m} t₁ t₂ = unifyAcc t₁ t₂ (m , nil)
| 41.331325
| 96
| 0.521207
|
fda1d5b2e71f26f5d21f0b047232625978d488ff
| 858
|
agda
|
Agda
|
examples/Termination/StructuralOrder.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/Termination/StructuralOrder.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/Termination/StructuralOrder.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- some examples for structural order in the termination checker
module StructuralOrder where
data Nat : Set where
zero : Nat
succ : Nat -> Nat
-- c t > t for any term t
-- e.g., succ (succ y) > succ y
plus : Nat -> Nat -> Nat
plus x (succ (succ y)) = succ (plus x (succ y))
plus x (succ zero) = succ x
plus x zero = x
-- constructor names do not matter
-- c (c' t) > c'' t
-- e.g. c0 (c1 x) > c0 x
-- c0 (c0 x) > c1 x
-- Actually constructor names does matter until the non-mattering is
-- implemented properly.
{- TEMPORARILY REMOVED by Ulf since there are problems with the constructor-name ignoring
data Bin : Set where
eps : Bin
c0 : Bin -> Bin
c1 : Bin -> Bin
foo : Bin -> Nat
foo eps = zero
foo (c0 eps) = zero
foo (c0 (c1 x)) = succ (foo (c0 x))
foo (c0 (c0 x)) = succ (foo (c1 x))
foo (c1 x) = succ (foo x)
-}
| 23.189189
| 89
| 0.614219
|
21c4b2d92ea754580f4507822da460d403f90a94
| 238
|
agda
|
Agda
|
Cubical/Codata/Stream/Base.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/Codata/Stream/Base.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/Codata/Stream/Base.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe --guardedness #-}
module Cubical.Codata.Stream.Base where
open import Cubical.Core.Everything
record Stream (A : Type₀) : Type₀ where
coinductive
constructor _,_
field
head : A
tail : Stream A
| 19.833333
| 46
| 0.701681
|
3088328fee06dad4ae2d5a191155f26419190a1a
| 1,822
|
agda
|
Agda
|
src/Categories/Functor/Instance/Twisted.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Functor/Instance/Twisted.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Functor/Instance/Twisted.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using (Category; module Definitions)
-- Definition of the "Twisted" Functor between certain Functor Categories
module Categories.Functor.Instance.Twisted {o ℓ e o′ ℓ′ e′} (𝒞 : Category o ℓ e) (𝒟 : Category o′ ℓ′ e′) where
import Categories.Category.Construction.TwistedArrow as TW
open import Categories.Category.Product
open import Categories.Category.Construction.Functors
open import Categories.Functor
open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper)
open import Data.Product using (_,_)
private
module C = Category 𝒞
Twist : Functor (Product C.op 𝒞) 𝒟 → Functor (TW.TwistedArrow 𝒞) 𝒟
Twist F = record
{ F₀ = λ x → F₀ (dom x , cod x)
; F₁ = λ f → F₁ (dom⇐ f , cod⇒ f)
; identity = identity
; homomorphism = homomorphism
; F-resp-≈ = F-resp-≈
}
where
open Functor F
open TW.Morphism
open TW.Morphism⇒
Twist′ : Functor (Product C.op 𝒞) 𝒟 → Functor (Category.op (TW.TwistedArrow C.op)) 𝒟
Twist′ F = record
{ F₀ = λ x → F₀ (dom x , cod x)
; F₁ = λ f → F₁ (dom⇐ f , cod⇒ f)
; identity = identity
; homomorphism = homomorphism
; F-resp-≈ = F-resp-≈
}
where
open Functor F
open TW.Morphism
open TW.Morphism⇒
Twisted : Functor (Functors (Product C.op 𝒞) 𝒟) (Functors (TW.TwistedArrow 𝒞) 𝒟)
Twisted = record
{ F₀ = Twist
; F₁ = Nat
; identity = D.Equiv.refl
; homomorphism = D.Equiv.refl
; F-resp-≈ = λ f≈g → f≈g
}
where
open TW.Morphism
open TW.Morphism⇒
module D = Category 𝒟
Nat : {F G : Functor (Product C.op 𝒞) 𝒟} → NaturalTransformation F G → NaturalTransformation (Twist F) (Twist G)
Nat nt = ntHelper record
{ η = λ x → η nt (dom x , cod x)
; commute = λ f → commute nt (dom⇐ f , cod⇒ f)
}
where
open NaturalTransformation
| 28.920635
| 114
| 0.672338
|
35ec09586cdfae7c0c3e48cfb9d4755b79c8166b
| 1,506
|
agda
|
Agda
|
Cubical/Data/Graph/Base.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Data/Graph/Base.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Data/Graph/Base.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Data.Graph.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
private variable ℓv ℓv' ℓv'' ℓe ℓe' ℓe'' ℓd ℓd' : Level
-- The type of directed multigraphs (with loops)
record Graph ℓv ℓe : Type (ℓ-suc (ℓ-max ℓv ℓe)) where
field
Obj : Type ℓv
Hom : Obj → Obj → Type ℓe
open Graph public
_ᵒᵖ : Graph ℓv ℓe → Graph ℓv ℓe
Obj (G ᵒᵖ) = Obj G
Hom (G ᵒᵖ) x y = Hom G y x
TypeGr : ∀ ℓ → Graph (ℓ-suc ℓ) ℓ
Obj (TypeGr ℓ) = Type ℓ
Hom (TypeGr ℓ) A B = A → B
-- Graph functors/homomorphisms
record GraphHom (G : Graph ℓv ℓe ) (G' : Graph ℓv' ℓe')
: Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-max ℓv' ℓe'))) where
field
_$_ : Obj G → Obj G'
_<$>_ : ∀ {x y : Obj G} → Hom G x y → Hom G' (_$_ x) (_$_ y)
open GraphHom public
GraphGr : ∀ ℓv ℓe → Graph _ _
Obj (GraphGr ℓv ℓe) = Graph ℓv ℓe
Hom (GraphGr ℓv ℓe) G G' = GraphHom G G'
-- Diagrams are (graph) functors with codomain Type
Diag : ∀ ℓd (G : Graph ℓv ℓe) → Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd)))
Diag ℓd G = GraphHom G (TypeGr ℓd)
record DiagMor {G : Graph ℓv ℓe} (F : Diag ℓd G) (F' : Diag ℓd' G)
: Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc (ℓ-max ℓd ℓd')))) where
field
nat : ∀ (x : Obj G) → F $ x → F' $ x
comSq : ∀ {x y : Obj G} (f : Hom G x y) → nat y ∘ F <$> f ≡ F' <$> f ∘ nat x
open DiagMor public
DiagGr : ∀ ℓd (G : Graph ℓv ℓe) → Graph _ _
Obj (DiagGr ℓd G) = Diag ℓd G
Hom (DiagGr ℓd G) = DiagMor
| 26.892857
| 80
| 0.586985
|
1a3ca2e30681a9acba0d3a34f0046f3c04534e20
| 1,578
|
agda
|
Agda
|
src/Leftovers/Examples.agda
|
JoeyEremondi/AgdaLeftovers
|
01b60b405009feaada181af175f019ceb89e42b2
|
[
"BSD-3-Clause"
] | null | null | null |
src/Leftovers/Examples.agda
|
JoeyEremondi/AgdaLeftovers
|
01b60b405009feaada181af175f019ceb89e42b2
|
[
"BSD-3-Clause"
] | null | null | null |
src/Leftovers/Examples.agda
|
JoeyEremondi/AgdaLeftovers
|
01b60b405009feaada181af175f019ceb89e42b2
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS -v 2 #-}
module Leftovers.Examples where
open import Leftovers.Utils
open import Leftovers.Leftovers
open import Leftovers.Equality
open import Data.Bool
open import Relation.Binary.PropositionalEquality
open import Data.Nat
open import Data.Product
open import Data.Unit
-- notNot : ∀ b → not (not b) ≡ b
-- notNot = (by {A = ∀ b → not (not b) ≡ b} (cases (quote Bool)) {!!}) -- (refl , refl)
-- applyTo : ∀ {ℓ1 ℓ2} {X : Set ℓ1} { Y : Set ℓ2 } → (X → Y) → X → Y
-- applyTo f x = f x
-- infixr 40 applyTo
-- syntax applyTo e₁ (λ x → e₂) = x ≔ e₁ ︔ e₂
plusZero : ∀ n → n ≡ n + 0
plusZero =
getNormal (by {A = ∀ n → n ≡ n + 0} (cases (quote ℕ)) ((λ x → cong suc (plusZero x)) , refl))
-- (by {A = ∀ n → n ≡ n + 0} (cases (quote ℕ)) ((λ x → cong suc (plusZero x)) , refl))
-- plusZero' : ∀ n → n ≡ n + 0
-- plusZero' = getNormal
-- ((the ((zero ≡ zero × (∀ x → suc x ≡ suc x + 0)) → ∀ n → n ≡ n + 0) λ h → identity (λ { zero → proj₁ h ; (suc x) → (proj₂ h) x }))
-- (refl , λ x → cong suc (plusZero' x)))
-- -- plusZero'' : ∀ n → n ≡ n + 0
-- -- plusZero'' = (the (zero ≡ zero → (∀ x → suc x ≡ suc x + 0) → ∀ n → n ≡ n + 0) λ h1 h2 → (λ { zero → h1 ; (suc x) → h2 x})) refl ((the (Dummy → ∀ x → suc x ≡ suc x + 0) (λ {dummy → λ x → cong suc (plusZero'' x)})) dummy)
-- -- plusZero' =
-- -- let
-- -- h : (zero ≡ zero × ∀ n → suc n ≡ (suc n) + 0)
-- -- h = refl , λ n → cong suc (plusZero' n)
-- -- in λ { zero → proj₁ h ; (suc x) → (proj₂ h) x}
-- -- plusZeroR : ∀ n → n + 0 ≡ n
-- -- plusZeroR = by (refl-cases (quote ℕ)) ?
| 30.346154
| 226
| 0.516477
|
522f57d683e26504dd7634e3b80887110d4df7da
| 6,294
|
agda
|
Agda
|
FormalLanguage.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
FormalLanguage.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
FormalLanguage.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --sized-types #-}
module FormalLanguage {ℓ} where
import Lvl
open import Sized.Data.List renaming (∅ to [])
open import Lang.Size
open import Data.Boolean
open import Data.Boolean.Operators
open Data.Boolean.Operators.Programming
open import Data.Boolean.Stmt
open import Functional
open import Relator.Equals
open import Type
-- Definitions:
-- A language is a set of words.
-- A word in a language is a list of valid symbols in the language.
-- A valid symbol in the language is an element in the alphabet of the language.
-- An alphabet of a language is a set.
-- A string is a word.
-- Standard conventions for variable naming in languages:
-- L is a language
-- Σ is an alphabet
Alphabet = Type{ℓ}
Word = List
-- Language is defined as a trie: (LHS is using the definition of Language, RHS is using the usual "semantics" of languages as sets):
-- For a language L
-- accepts-ε:
-- (accepts-ε(L) = 𝑇) ↔ (ε ∈ L)
-- accepts-ε(L) returns a boolean determining whether the empty word is accepted in the language.
-- suffix-lang:
-- ∀word∀c. (word ∈ suffix-lang(L)(c)) ↔ ((c 𝁼 word) ∈ L)
-- suffix-lang(L)(c) is the language that consists of the rest of the words when a word is starting with c in L.
-- Copied (with modifications) from: http://agda.readthedocs.io/en/v2.5.2/language/sized-types.html (2017-05-13)
-- which links the following paper: "Formal Languages, Formally and Coinductively, Dmitriy Traytel, FSCD (2016)" [https://www21.in.tum.de/~traytel/papers/fscd16-coind_lang/paper.pdf]
-- Example:
-- A language 𝔏 consists of 6 words:
-- 𝔏 = {"" , "aa" , "aaa" , "aab" , "aba" , "aaab"}
-- accepts-ε (𝔏) = 𝑇
-- suffix-lang(𝔏)(a) = {"a" , "aa" , "ab" , "ba" , "aab"}
-- accepts-ε (suffix-lang(𝔏)(a)) = 𝐹
-- suffix-lang(suffix-lang(𝔏)(a))(a) = {"" , "a" , "b" , "ab"}
-- suffix-lang(suffix-lang(𝔏)(a))(b) = {"a"}
record Language (Σ : Alphabet) {s : Size} : Type{ℓ} where
constructor intro
coinductive
field
accepts-ε : Bool
suffix-lang : ∀{sₛ : <ˢⁱᶻᵉ s} → Σ → Language(Σ){sₛ}
module Oper {Σ} where
infixl 1003 _∪_
infixl 1002 _∩_
infixl 1001 _𝁼_
infixl 1000 _*
-- The empty language.
-- The language that does not include any word at all.
∅ : ∀{s} → Language(Σ){s}
Language.accepts-ε ∅ = 𝐹
Language.suffix-lang ∅ _ = ∅
-- The empty word language.
-- The language with only the empty word.
ε : ∀{s} → Language(Σ){s}
Language.accepts-ε ε = 𝑇
Language.suffix-lang ε _ = ∅
-- The language of length 1 words that only accepts some symbols of its alphabet
alphabet-filter : ∀{s} → (Σ → Bool) → Language(Σ){s}
Language.accepts-ε (alphabet-filter f) = 𝐹
Language.suffix-lang (alphabet-filter f) c = if f(c) then ε else ∅
-- The single symbol language.
-- The language consisting of a single word with a single letter
-- Note: This is only possible when Alphabet has a computably decidable equality relation
single : ⦃ _ : ComputablyDecidable(_≡_) ⦄ → ∀{s} → Σ → Language(Σ){s}
single(a) = alphabet-filter(ComputablyDecidable.decide(_≡_) a)
-- The sublanguage filtered by a decidable predicate.
filter : ∀{s} → (Word(Σ) → Bool) → Language(Σ){s} → Language(Σ){s}
Language.accepts-ε (filter P(𝔏)) = P(List.∅)
Language.suffix-lang (filter P(𝔏)) c = filter (P ∘ tail) (Language.suffix-lang(𝔏)(c))
-- The language where every letter in the alphabet is applied to a function.
unmap : ∀{Σ₂}{s} → (Σ → Σ₂) → Language(Σ₂){s} → Language(Σ){s}
Language.accepts-ε (unmap f(𝔏)) = Language.accepts-ε (𝔏)
Language.suffix-lang (unmap f(𝔏)) c = unmap f(Language.suffix-lang(𝔏)(f(c)))
-- Union.
-- The language that includes any words that the two languages have.
_∪_ : ∀{s} → Language(Σ){s} → Language(Σ){s} → Language(Σ){s}
Language.accepts-ε (L₁ ∪ L₂) = Language.accepts-ε(L₁) || Language.accepts-ε(L₂)
Language.suffix-lang (L₁ ∪ L₂) c = Language.suffix-lang(L₁)(c) ∪ Language.suffix-lang(L₂)(c)
-- Intersection.
-- The language that only includes the words that both languages have in common.
_∩_ : ∀{s} → Language(Σ){s} → Language(Σ){s} → Language(Σ){s}
Language.accepts-ε (L₁ ∩ L₂) = Language.accepts-ε(L₁) && Language.accepts-ε(L₂)
Language.suffix-lang (L₁ ∩ L₂) c = Language.suffix-lang(L₁)(c) ∩ Language.suffix-lang(L₂)(c)
-- Concatenation.
-- The language that includes words that start with a word the first language and end in a word from the second language.
_𝁼_ : ∀{s} → Language(Σ){s} → Language(Σ){s} → Language(Σ){s}
Language.accepts-ε (L₁ 𝁼 L₂) = Language.accepts-ε(L₁) && Language.accepts-ε(L₂)
Language.suffix-lang (L₁ 𝁼 L₂) c =
if Language.accepts-ε(L₁)
then (Language.suffix-lang(L₁)(c) 𝁼 L₂) ∪ Language.suffix-lang(L₂)(c)
else (Language.suffix-lang(L₁)(c) 𝁼 L₂)
-- Star/Closure
-- The language that includes words in any number of concatenations with itself.
_* : ∀{s} → Language(Σ){s} → Language(Σ){s}
Language.accepts-ε (L *) = 𝑇
Language.suffix-lang (L *) c = Language.suffix-lang(L)(c) 𝁼 (L *)
-- Complement
-- The language that includes all words that a language does not have.
∁_ : ∀{s} → Language(Σ){s} → Language(Σ){s}
Language.accepts-ε (∁ L) = !(Language.accepts-ε(L))
Language.suffix-lang (∁ L) c = ∁(Language.suffix-lang(L)(c))
-- The universal language.
-- The language that includes all words in any combination of the alphabet.
-- The largest language (with most words) with a certain alphabet.
𝐔 : ∀{s} → Language(Σ){s}
𝐔 = ∁(∅)
-- Containment check
-- Checks whether a word is in the language.
_∈?_ : ∀{s} → Word{s = s}(Σ) → Language(Σ) → Bool
_∈?_ [] L = Language.accepts-ε(L)
_∈?_ (_⊰_ {sₗ} c w) L = _∈?_ {s = sₗ} w (Language.suffix-lang L c)
-- Containment
-- The relation of whether a word is in the language or not.
_∈_ : ∀{s} → Word{s = s}(Σ) → Language(Σ) → Type
_∈_ {s} a b = IsTrue(_∈?_ {s} a b)
[_]_∈_ : ∀(s) → Word{s = s}(Σ) → Language(Σ) → Type
[ s ] a ∈ b = _∈_ {s} a b
-- Uncontainment
-- The relation of whether a word is not in the language or not.
_∉_ : ∀{s} → Word{s = s}(Σ) → Language(Σ) → Type
_∉_ {s} a b = IsFalse(_∈?_ {s} a b)
[_]_∉_ : ∀(s) → Word{s = s}(Σ) → Language(Σ) → Type
[ s ] a ∉ b = _∉_ {s} a b
| 41.137255
| 182
| 0.636638
|
1b541614b363b26c0e99f54918925738586fcd10
| 15,543
|
agda
|
Agda
|
Structure/Logic/Constructive/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/Logic/Constructive/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/Logic/Constructive/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Structure.Logic.Constructive.Proofs where
open import Functional as Fn
open import Lang.Instance
open import Logic.Propositional as Logic using (_←_ ; _↔_)
open import Logic.Predicate as Logic hiding (∀ₗ)
import Lvl
import Structure.Logic.Constructive.BoundedPredicate
import Structure.Logic.Constructive.Predicate
import Structure.Logic.Constructive.Propositional
open import Syntax.Function
open import Type
private variable ℓ ℓₗ ℓₘₗ ℓₒ ℓₚ : Lvl.Level
private variable Formula : Type{ℓₗ}
private variable Proof : Formula → Type{ℓₘₗ}
private variable Predicate : Type{ℓₚ}
private variable Domain : Type{ℓₒ}
module _ (Proof : Formula → Type{ℓₘₗ}) where
open Structure.Logic.Constructive.Propositional(Proof)
private variable X Y Z : Formula
{-
module _ ⦃ logic : ConstructiveLogic ⦄ where
[⟵][⟶][∧]-[⟷]-equivalence : Proof(X ⟷ Y) ↔ (Proof(X ⟵ Y) Logic.∧ Proof(X ⟶ Y))
[⟵][⟶][∧]-[⟷]-equivalence {X} {Y} = Logic.[↔]-intro
(p ↦ ⟷.intro (⟵.elim(Logic.[∧]-elimₗ p)) (⟶.elim(Logic.[∧]-elimᵣ p)))
(p ↦ Logic.[∧]-intro (⟵.intro (⟷.elimₗ p)) (⟶.intro (⟷.elimᵣ p)))
-}
[⟶]-redundancyₗ : ⦃ impl : ∃(Implication) ⦄ → Proof(X ⟶ (X ⟶ Y)) → Proof(X ⟶ Y)
[⟶]-redundancyₗ = ⟶.intro ∘ swap apply₂ ∘ (⟶.elim ∘₂ ⟶.elim)
[⟷]-reflexivity : ∀{_⟷_} → ⦃ Equivalence(_⟷_) ⦄ → Proof(X ⟷ X)
[⟷]-reflexivity = ⟷.intro id id
[⟵]-to-[⟶] : ⦃ con : ∃(Consequence) ⦄ → ∃(Implication)
∃.witness [⟵]-to-[⟶] = swap(_⟵_)
Implication.intro (∃.proof [⟵]-to-[⟶]) = ⟵.intro
Implication.elim (∃.proof [⟵]-to-[⟶]) = ⟵.elim
[⟶]-to-[⟵] : ⦃ impl : ∃(Implication) ⦄ → ∃(Consequence)
∃.witness [⟶]-to-[⟵] = swap(_⟶_)
Consequence.intro (∃.proof [⟶]-to-[⟵]) = ⟶.intro
Consequence.elim (∃.proof [⟶]-to-[⟵]) = ⟶.elim
[⟵][⟶][∧]-to-[⟷] : ⦃ con : ∃(Consequence) ⦄ → ⦃ impl : ∃(Implication) ⦄ → ⦃ or : ∃(Conjunction) ⦄ → ∃(Equivalence)
∃.witness [⟵][⟶][∧]-to-[⟷] X Y = (X ⟵ Y) ∧ (X ⟶ Y)
Equivalence.intro (∃.proof [⟵][⟶][∧]-to-[⟷]) yx xy = ∧.intro (⟵.intro yx) (⟶.intro xy)
Equivalence.elimₗ (∃.proof [⟵][⟶][∧]-to-[⟷]) = ⟵.elim ∘ ∧.elimₗ
Equivalence.elimᵣ (∃.proof [⟵][⟶][∧]-to-[⟷]) = ⟶.elim ∘ ∧.elimᵣ
[⟶][⟷]-to-[∧] : ⦃ impl : ∃(Implication) ⦄ → ⦃ eq : ∃(Equivalence) ⦄ → ∃(Conjunction)
∃.witness [⟶][⟷]-to-[∧] X Y = (X ⟶ Y) ⟷ X
Conjunction.intro (∃.proof [⟶][⟷]-to-[∧]) x y = ⟷.intro (const(⟶.intro(const y))) (const x)
Conjunction.elimₗ (∃.proof [⟶][⟷]-to-[∧]) xyx = ⟷.elimᵣ xyx (⟶.intro(swap apply₂(⟶.elim ∘ ⟷.elimₗ xyx)))
Conjunction.elimᵣ (∃.proof [⟶][⟷]-to-[∧]) xyx = apply₂(⟷.elimᵣ xyx (⟶.intro(swap apply₂ (⟶.elim ∘ ⟷.elimₗ xyx)))) (⟶.elim ∘ (⟷.elimₗ xyx))
[∨][⟷]-to-[⟶] : ⦃ or : ∃(Disjunction) ⦄ → ⦃ eq : ∃(Equivalence) ⦄ → ∃(Implication)
∃.witness [∨][⟷]-to-[⟶] X Y = (X ∨ Y) ⟷ Y
Implication.intro (∃.proof [∨][⟷]-to-[⟶]) = ⟷.intro ∨.introᵣ ∘ swap ∨.elim id
Implication.elim (∃.proof [∨][⟷]-to-[⟶]) xyy x = ⟷.elimᵣ xyy (∨.introₗ x)
[∧][⟷]-to-[⟶] : ⦃ and : ∃(Conjunction) ⦄ → ⦃ eq : ∃(Equivalence) ⦄ → ∃(Implication)
∃.witness [∧][⟷]-to-[⟶] X Y = (X ∧ Y) ⟷ X
Implication.intro (∃.proof [∧][⟷]-to-[⟶]) xy = ⟷.intro (x ↦ ∧.intro x (xy x)) ∧.elimₗ
Implication.elim (∃.proof [∧][⟷]-to-[⟶]) xyx x = ∧.elimᵣ(⟷.elimₗ xyx x)
[¬][⊤]-to-[⊥] : ⦃ neg : ∃(Negation) ⦄ → ⦃ top : ∃(Top) ⦄ → ∃(Bottom)
∃.witness [¬][⊤]-to-[⊥] = ¬ ⊤
Bottom.elim (∃.proof [¬][⊤]-to-[⊥]) = ¬.elim ⊤.intro
[¬][⊥]-to-[⊤] : ⦃ neg : ∃(Negation) ⦄ → ⦃ bot : ∃(Bottom) ⦄ → ∃(Top)
∃.witness [¬][⊥]-to-[⊤] = ¬ ⊥
Top.intro (∃.proof [¬][⊥]-to-[⊤]) = ¬.intro{Y = ⊥} ⊥.elim ⊥.elim
[⟷]-to-[⊤] : Formula → ⦃ eq : ∃(Equivalence) ⦄ → ∃(Top)
∃.witness ([⟷]-to-[⊤] φ) = φ ⟷ φ
Top.intro (∃.proof ([⟷]-to-[⊤] φ)) = [⟷]-reflexivity
[⟷][⊥]-to-[¬] : ⦃ eq : ∃(Equivalence) ⦄ → ⦃ bot : ∃(Bottom) ⦄ → ∃(Negation)
∃.witness [⟷][⊥]-to-[¬] = _⟷ ⊥
Negation.intro (∃.proof [⟷][⊥]-to-[¬]) xy xy⊥ = ⟷.intro ⊥.elim ((⟷.elimᵣ ∘ xy⊥) ∘ₛ xy)
Negation.elim (∃.proof [⟷][⊥]-to-[¬]) = ⊥.elim ∘₂ swap ⟷.elimᵣ
[∨][⟷][⊥]-adequacy : ⦃ or : ∃(Disjunction) ⦄ → ⦃ eq : ∃(Equivalence) ⦄ → ⦃ bot : ∃(Bottom) ⦄ → Logic
Logic.top [∨][⟷][⊥]-adequacy = [⟷]-to-[⊤] ⊥
Logic.implication [∨][⟷][⊥]-adequacy = [∨][⟷]-to-[⟶]
Logic.negation [∨][⟷][⊥]-adequacy = [⟷][⊥]-to-[¬]
Logic.conjunction [∨][⟷][⊥]-adequacy = [⟶][⟷]-to-[∧] where instance _ = Logic.implication [∨][⟷][⊥]-adequacy
Logic.consequence [∨][⟷][⊥]-adequacy = [⟶]-to-[⟵] where instance _ = Logic.implication [∨][⟷][⊥]-adequacy
module _ (Proof : Formula → Type{ℓₘₗ}) where
open Structure.Logic.Constructive.Propositional(Proof)
private variable X Y Z : Formula
open import Data.Tuple as Tuple using ()
[⊤]-preserving-type : ⦃ top : ∃(Top) ⦄ → Proof(⊤) ↔ Logic.⊤
Tuple.left [⊤]-preserving-type = const ⊤.intro
Tuple.right [⊤]-preserving-type = const Logic.[⊤]-intro
[∧]-preserving-type : ⦃ and : ∃(Conjunction) ⦄ → Proof(X ∧ Y) ↔ (Proof(X) Logic.∧ Proof(Y))
Tuple.left [∧]-preserving-type (Logic.[∧]-intro x y) = ∧.intro x y
Tuple.right [∧]-preserving-type xy = Logic.[∧]-intro (∧.elimₗ xy) (∧.elimᵣ xy)
[∨]-preserving-type : ⦃ or : ∃(Disjunction) ⦄ → Proof(X ∨ Y) ← (Proof(X) Logic.∨ Proof(Y))
[∨]-preserving-type = Logic.[∨]-elim ∨.introₗ ∨.introᵣ
[⟶]-preserving-type : ⦃ impl : ∃(Implication) ⦄ → Proof(X ⟶ Y) ↔ (Proof(X) → Proof(Y))
Tuple.left [⟶]-preserving-type = ⟶.intro
Tuple.right [⟶]-preserving-type = ⟶.elim
[⟵]-preserving-type : ⦃ cons : ∃(Consequence) ⦄ → Proof(X ⟵ Y) ↔ (Proof(X) ← Proof(Y))
Tuple.left [⟵]-preserving-type = ⟵.intro
Tuple.right [⟵]-preserving-type = ⟵.elim
[⟷]-preserving-type : ⦃ eq : ∃(Equivalence) ⦄ → Proof(X ⟷ Y) ↔ (Proof(X) ↔ Proof(Y))
Tuple.left [⟷]-preserving-type xy = ⟷.intro (Logic.[↔]-to-[←] xy) (Logic.[↔]-to-[→] xy)
Tuple.right [⟷]-preserving-type xy = Logic.[↔]-intro (⟷.elimₗ xy) (⟷.elimᵣ xy)
{-
module Test ⦃ logic : Logic ⦄ where
pure : ∀{A : Formula} → Proof(A) → Proof(A)
pure = id
_<*>_ : ∀{A B : Formula} → Proof(A ⟶ B) → Proof(A) → Proof(B)
_<*>_ = ⟶.elim
test : ∀{A B} → Proof(A ⟶ (A ⟶ B)) → Proof(A) → Proof(B)
test ab a = ⦇ ab a a ⦈
module Test2 ⦃ logic : ConstructiveLogic ⦄ {Obj : Type{ℓ}} where
private variable P : Obj → Formula
module _ ⦃ all : ∃(Universal) ⦄ where
pure : ∀{A : Formula} → Proof(A) → Proof(A)
pure = id
_<*>_ : ∀{P : Obj → Formula} → Proof(∀ₗ P) → (x : Obj) → Proof(P(x))
_<*>_ = ∀ₗ.elim
test : ∀{A : Obj → Obj → Formula} → Proof(∀ₗ(x ↦ ∀ₗ(y ↦ A x y))) → (x : Obj) → Proof(A x x)
test a x = ⦇ a x x ⦈
-}
module _ where
open import Data
open import Data.Tuple
open import Data.Either as Either
open Structure.Logic.Constructive.BoundedPredicate renaming (Logic to BoundedPredicateLogic)
open Structure.Logic.Constructive.Predicate renaming (Logic to PredicateLogic)
open Structure.Logic.Constructive.Propositional renaming (Logic to PropositionalLogic)
instance
typePropositionalLogic : PropositionalLogic{Formula = Type{ℓ}} id
PropositionalLogic.bottom typePropositionalLogic = [∃]-intro Empty ⦃ record{elim = empty} ⦄
PropositionalLogic.top typePropositionalLogic = [∃]-intro Unit ⦃ record{intro = <>} ⦄
PropositionalLogic.implication typePropositionalLogic = [∃]-intro _→ᶠ_ ⦃ record{intro = _$_ ; elim = id} ⦄
PropositionalLogic.conjunction typePropositionalLogic = [∃]-intro _⨯_ ⦃ record{intro = _,_ ; elimₗ = left ; elimᵣ = right} ⦄
PropositionalLogic.disjunction typePropositionalLogic = [∃]-intro _‖_ ⦃ record{introₗ = Left ; introᵣ = Right ; elim = Either.map1} ⦄
PropositionalLogic.consequence typePropositionalLogic = [∃]-intro _←ᶠ_ ⦃ record{intro = id ; elim = _$_} ⦄
PropositionalLogic.equivalence typePropositionalLogic = [∃]-intro Logic._↔_ ⦃ record{intro = _,_ ; elimₗ = left ; elimᵣ = right} ⦄
PropositionalLogic.negation typePropositionalLogic = [∃]-intro Logic.¬_ ⦃ record{intro = Fn.swap(_∘ₛ_) ; elim = empty ∘₂ apply} ⦄
instance
typePredicateLogic : ∀{T : Type{ℓₒ}} → PredicateLogic{Formula = Type{ℓₒ Lvl.⊔ ℓₗ}} id {Predicate = T → Type{ℓₒ Lvl.⊔ ℓₗ}} {Domain = T} id
PredicateLogic.universal typePredicateLogic = [∃]-intro Logic.∀ₗ ⦃ record{intro = id ; elim = id} ⦄
PredicateLogic.existential typePredicateLogic = [∃]-intro Logic.∃ ⦃ record{intro = \{_}{x} p → Logic.[∃]-intro x ⦃ p ⦄ ; elim = Logic.[∃]-elim} ⦄
open import Type.Dependent
instance
typeBoundedPredicateLogic : ∀{T : Type{ℓₒ}} → BoundedPredicateLogic{Formula = Type{ℓₒ Lvl.⊔ ℓₗ}} id {Predicate = (x : T) → ∀{B : T → Type{ℓₒ Lvl.⊔ ℓₗ}} → B(x) → Type{ℓₒ Lvl.⊔ ℓₗ}} {Domain = T} id
BoundedPredicateLogic.universal typeBoundedPredicateLogic = [∃]-intro (\B P → ∀{x} → (bx : B(x)) → P(x){B}(bx)) ⦃ record{intro = \p bx → p bx ; elim = \p bx → p bx} ⦄
BoundedPredicateLogic.existential typeBoundedPredicateLogic = [∃]-intro (\B P → Logic.∃(x ↦ Σ(B(x)) (P(x){B}))) ⦃ record{intro = \{_}{x} bx p → Logic.[∃]-intro x ⦃ intro bx p ⦄ ; elim = \p → Logic.[∃]-elim (\(intro bx px) → p bx px)} ⦄
{- TODO: Maybe have some more assumptions
boundedPredicateLogic-to-predicateLogic : ∀{Formula Domain Predicate : Type{ℓₒ}}{Proof : Formula → Type}{_$_} → BoundedPredicateLogic{Formula = Formula} Proof {Predicate = Predicate} {Domain = Domain} (_$_) → PredicateLogic{Formula = Formula} Proof {Predicate = (Domain → Formula) ⨯ Predicate} {Domain = Σ(Predicate ⨯ Domain) (\(P , x) → Proof((P $ x) {{!!}} {!!}))} {!!}
PredicateLogic.propositional (boundedPredicateLogic-to-predicateLogic L) = BoundedPredicateLogic.propositional L
∃.witness (PredicateLogic.universal (boundedPredicateLogic-to-predicateLogic L)) (B , P) = ∃.witness (BoundedPredicateLogic.universal L) B P
Universal.intro (∃.proof (PredicateLogic.universal (boundedPredicateLogic-to-predicateLogic L))) {B , P} p = BoundedUniversal.intro
(∃.proof (BoundedPredicateLogic.universal L)) (\{x} pp → p{intro (P , x) {!!}})
Universal.elim (∃.proof (PredicateLogic.universal (boundedPredicateLogic-to-predicateLogic L))) = {!!}
∃.witness (PredicateLogic.existential (boundedPredicateLogic-to-predicateLogic L)) (B , P) = ∃.witness (BoundedPredicateLogic.existential L) B P
Existential.intro (∃.proof (PredicateLogic.existential (boundedPredicateLogic-to-predicateLogic L))) = {!!}
Existential.elim (∃.proof (PredicateLogic.existential (boundedPredicateLogic-to-predicateLogic L))) = {!!}
-}
{- TODO: Seems to need a duplicate (Domain → Formula) in Predicate. Also, does not work with this generality
boundedPredicateLogic-to-predicateLogic : ∀{_$_} → BoundedPredicateLogic{Formula = Formula} Proof {Predicate = Predicate} {Domain = Domain} (_$_) → PredicateLogic{Formula = Formula} Proof {Predicate = Predicate} {Domain = Σ((Domain → Formula) ⨯ Domain) (\(B , x) → Proof(B(x)))} (\P (intro(B , x) bx) → (P $ x) {B} bx)
PredicateLogic.propositional (boundedPredicateLogic-to-predicateLogic L) = BoundedPredicateLogic.propositional L
PredicateLogic.universal (boundedPredicateLogic-to-predicateLogic L) = [∃]-intro {!!} ⦃ record{intro = {!!} ; elim = {!!}} ⦄
PredicateLogic.existential (boundedPredicateLogic-to-predicateLogic L) = [∃]-intro {!!} ⦃ record{intro = {!!} ; elim = {!!}} ⦄
-}
{-instance
typeBoundedPredicateLogic : ∀{T : Type{ℓₒ}}{B : T → Type{ℓ}} → PredicateLogic{Formula = Type{ℓₒ Lvl.⊔ ℓₗ Lvl.⊔ ℓ}} id {Predicate = (x : T) → ⦃ B(x) ⦄ → Type{ℓₒ Lvl.⊔ ℓₗ Lvl.⊔ ℓ}} {Domain = Σ T B} (\f (intro x b) → f x ⦃ b ⦄)
PredicateLogic.universal (typeBoundedPredicateLogic {B = B}) = [∃]-intro (f ↦ (∀{x} ⦃ bx ⦄ → f(x) ⦃ bx ⦄)) ⦃ record{intro = \px → px ; elim = \{P} px {x} → px{Σ.left x} ⦃ Σ.right x ⦄} ⦄
PredicateLogic.existential (typeBoundedPredicateLogic {B = B}) = [∃]-intro (f ↦ Logic.∃(x ↦ Σ(B(x)) (bx ↦ f x ⦃ bx ⦄)) ) ⦃ record{intro = {!!} ; elim = {!!}} ⦄
-}
import Logic.Classical.DoubleNegated as DoubleNegated
open import Logic.Names
import Logic.Propositional.Theorems as Logic
instance
doubleNegatedTypeLogic : PropositionalLogic{ℓₘₗ = Lvl.𝟎}(Logic.¬¬_)
PropositionalLogic.bottom doubleNegatedTypeLogic = Logic.[∃]-intro Logic.⊥ ⦃ record{elim = DoubleNegated.[⊥]-elim} ⦄
PropositionalLogic.top doubleNegatedTypeLogic = Logic.[∃]-intro Logic.⊤ ⦃ record{intro = DoubleNegated.[⊤]-intro} ⦄
PropositionalLogic.implication doubleNegatedTypeLogic = Logic.[∃]-intro (_→ᶠ_) ⦃ record{intro = DoubleNegated.[→]-intro ; elim = DoubleNegated.[→]-elim} ⦄
PropositionalLogic.conjunction doubleNegatedTypeLogic = Logic.[∃]-intro (Logic._∧_) ⦃ record{intro = DoubleNegated.[∧]-intro ; elimₗ = DoubleNegated.[∧]-elimₗ ; elimᵣ = DoubleNegated.[∧]-elimᵣ} ⦄
PropositionalLogic.disjunction doubleNegatedTypeLogic = Logic.[∃]-intro (Logic._∨_) ⦃ record{introₗ = DoubleNegated.[∨]-introₗ ; introᵣ = DoubleNegated.[∨]-introᵣ ; elim = DoubleNegated.[∨]-elim} ⦄
PropositionalLogic.consequence doubleNegatedTypeLogic = Logic.[∃]-intro (Logic._←_) ⦃ record{intro = DoubleNegated.[←]-intro ; elim = DoubleNegated.[→]-elim} ⦄
PropositionalLogic.equivalence doubleNegatedTypeLogic = Logic.[∃]-intro (Logic._↔_) ⦃ record{intro = DoubleNegated.[↔]-intro ; elimₗ = DoubleNegated.[↔]-elimₗ ; elimᵣ = DoubleNegated.[↔]-elimᵣ} ⦄
PropositionalLogic.negation doubleNegatedTypeLogic = Logic.[∃]-intro (Logic.¬_) ⦃ record{intro = Fn.swap(_∘ₛ_) ; elim = const ∘₂ apply} ⦄
open import Data.Boolean
import Data.Boolean.Operators
open Data.Boolean.Operators.Programming
open import Data.Boolean.Stmt
open import Data.Boolean.Stmt.Proofs
instance
booleanLogic : PropositionalLogic IsTrue
PropositionalLogic.bottom booleanLogic = [∃]-intro 𝐹 ⦃ record{elim = Logic.[⊥]-elim ∘ IsTrue.[𝐹]-elim} ⦄
PropositionalLogic.top booleanLogic = [∃]-intro 𝑇 ⦃ record{intro = IsTrue.[𝑇]-intro} ⦄
PropositionalLogic.conjunction booleanLogic = [∃]-intro _&&_ ⦃ record{intro = IsTrue.[∧]-intro ; elimₗ = IsTrue.[∧]-elimₗ ; elimᵣ = IsTrue.[∧]-elimᵣ} ⦄
PropositionalLogic.disjunction booleanLogic = [∃]-intro _||_ ⦃ record{introₗ = IsTrue.[∨]-introₗ ; introᵣ = IsTrue.[∨]-introᵣ ; elim = IsTrue.[∨]-elim} ⦄
PropositionalLogic.negation booleanLogic = [∃]-intro ! ⦃ record{intro = IsTrue.[!]-intro ; elim = IsTrue.[!]-elim} ⦄
PropositionalLogic.implication booleanLogic = [∃]-intro _→?_ ⦃ record{intro = IsTrue.[→?]-intro ; elim = IsTrue.[→?]-elim} ⦄
PropositionalLogic.consequence booleanLogic = [∃]-intro _←?_ ⦃ record{intro = IsTrue.[←?]-intro ; elim = IsTrue.[←?]-elim} ⦄
PropositionalLogic.equivalence booleanLogic = [∃]-intro _==_ ⦃ record{intro = IsTrue.[==]-intro ; elimₗ = IsTrue.[==]-elimₗ ; elimᵣ = IsTrue.[==]-elimᵣ} ⦄
booleanPredicateLogic : ∀{T : Type{ℓ}}{all exist : (T → Bool) → Bool} → (∀{P} → (∀{x} → IsTrue(P(x))) ↔ IsTrue(all P)) → (∀{P} → (Logic.∃(x ↦ IsTrue(P(x)))) ↔ IsTrue(exist P)) → PredicateLogic IsTrue {Domain = T} id
PredicateLogic.universal (booleanPredicateLogic {all = all} {exist = exist} all-eq exist-eq) = [∃]-intro all ⦃ record{intro = Logic.[↔]-to-[→] all-eq ; elim = Logic.[↔]-to-[←] all-eq} ⦄
PredicateLogic.existential (booleanPredicateLogic {all = all} {exist = exist} all-eq exist-eq) = [∃]-intro exist ⦃ record{intro = Logic.[↔]-to-[→] exist-eq ∘ (p ↦ [∃]-intro _ ⦃ p ⦄) ; elim = p ↦ ep ↦ p(Logic.[∃]-proof(Logic.[↔]-to-[←] exist-eq ep))} ⦄
| 65.582278
| 373
| 0.606897
|
37606314b2a1dc7c8b78d3f4c7cd65e883934c5c
| 8,672
|
agda
|
Agda
|
agda/paper/2012-Stephanie_Weirich_and_Casinghino-Generic_Programming_with_Dependent_Types/z.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/paper/2012-Stephanie_Weirich_and_Casinghino-Generic_Programming_with_Dependent_Types/z.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/paper/2012-Stephanie_Weirich_and_Casinghino-Generic_Programming_with_Dependent_Types/z.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
{-# OPTIONS --type-in-type #-}
module z where
{-
Generic Programming with Dependent Types
Stephanie Weirich and Chris Casinghino, University of Pennsylvania, {sweirich,ccasin}@cis.upenn.edu
ccasin@cis.upenn.edu
2010 : https://www.seas.upenn.edu/~sweirich/papers/aritygen.pdf
2012 : https://www.cis.upenn.edu/~sweirich/papers/ssgip-journal.pdf
------------------------------------------------------------------------------
-- Abstract and Intro
2 types of genericity
- datatype
- operate on type structure of data
- so no need to define for each new type
- arity
- enables functions to be applied to a variable number of args.
e.g., generalize arity of map
repeat :: a → [a]
map :: (a → b) → [a] → [b]
zipWith :: (a → b → c) → [a] → [b] → [c]
zipWith3 :: (a → b → c → d) → [a] → [b] → [c] → [d]
code : http://www.seas.upenn.edu/~sweirich/papers/aritygen-lncs.tar.gz
tested with : Agda version 2.2.10
------------------------------------------------------------------------------
2 SIMPLE TYPE-GENERIC PROGRAMMING IN AGDA
using Agda with flags (which implies cannot do proofs)
{-# OPTIONS --type-in-type #-}
–no-termination-check
{-# OPTIONS --no-positivity-check #-}
-}
data Bool : Set where
true : Bool
false : Bool
¬ : Bool → Bool
¬ true = false
¬ false = true
_∧_ : Bool → Bool → Bool
true ∧ true = true
_ ∧ _ = false
if_then_else : ∀ {A : Set} → Bool → A → A → A
if true then a1 else a2 = a1
if false then a1 else a2 = a2
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
_+_ : ℕ → ℕ → ℕ
zero + m = m
suc n + m = suc (n + m)
infixl 40 _+_
data List (A : Set) : Set where
[] : List A
_::_ : A → List A → List A
infixr 5 _::_ -- https://agda.github.io/agda-stdlib/Data.Vec.Functional.html
replicate : ∀ {A} → ℕ → A → List A
replicate zero _ = []
replicate (suc n) x = x :: replicate n x
data Vec (A : Set) : ℕ → Set where
[] : Vec A zero
_::_ : ∀ {n} → A → (Vec A n) → Vec A (suc n)
repeat : ∀ {n} {A} → A → Vec A n
repeat {zero} x = []
repeat {suc n} x = x :: repeat x
------------------------------------------------------------------------------
-- 2.1 BASIC TYPE-GENERIC PROGRAMMING
eq-bool : Bool → Bool → Bool
eq-bool true true = true
eq-bool false false = true
eq-bool _ _ = false
eq-nat : ℕ → ℕ → Bool
eq-nat zero zero = true
eq-nat (suc n) (suc m) = eq-nat n m
eq-nat _ _ = false
{-
Structural equality functions, like above, motivate type-generic programming:
- enables defining functions that observe and use structure of types
In a dependently typed language, type-generic is accomplished using universes [17, 21].
E.G., universe of natural number, boolean and product types
-}
-- datatype 'Type', called a "universe"
data Type : Set where
TNat : Type
TBool : Type
TProd : Type → Type → Type
open import Data.Product
-- define an interpretation function '⟨_⟩'
-- maps elements of this universe to Agda types
⟨_⟩ : Type → Set
⟨ TNat ⟩ = ℕ
⟨ TBool ⟩ = Bool
⟨ TProd t1 t2 ⟩ = ⟨ t1 ⟩ × ⟨ t2 ⟩
geq : (t : Type) → ⟨ t ⟩ → ⟨ t ⟩ → Bool
geq TNat n1 n2 = eq-nat n1 n2
geq TBool b1 b2 = eq-bool b1 b2
geq (TProd a b) (a1 , b1) (a2 , b2) = geq a a1 a2 ∧ geq b b1 b2
geqEx : Bool
geqEx = geq (TProd TNat TBool) (1 , false) (1 , false)
{-
------------------------------------------------------------------------------
-- 3 ARITY-GENERIC PROGRAMMING : generalize over number of arguments
e.g., map-like (above), +, foldl, foldr
e.g., generalize following functions into one definition : maps for vectors
-}
-- infix zipping application, pronounced “zap” for “zip with apply”
_⊗_ : {A B : Set} {n : ℕ} → Vec (A → B) n → Vec A n → Vec B n
[] ⊗ [] = []
(a :: As) ⊗ (b :: Bs) = a b :: As ⊗ Bs
infixl 40 _⊗_
map0 : {m : ℕ} {A : Set} → A → Vec A m
map0 = repeat
map1 : {m : ℕ} {A B : Set} → (A → B) → Vec A m → Vec B m
map1 f x = repeat f ⊗ x
map2 : {m : ℕ} {A B C : Set} → (A → B → C) → Vec A m → Vec B m → Vec C m
map2 f x1 x2 = repeat f ⊗ x1 ⊗ x2
{-
Intuitively, each map defined by a application of repeat and n copies of _⊗_.
nvec-map f n v1 v2 ... vn = repeat f ⊗ v1 ⊗ v2 ⊗ ... ⊗ vn
-- recursion on n in accumulator style
-- after repeating f : have a vector of functions
-- then zap this vector across n argument vectors
-- NEEDS type declaration - given below (in Arity section)
nvec-map n f = g n (repeat f)
where
g0 a = a
g (suc n) f = (λ a → g n (f ⊗ a))
--------------------------------------------------
3.1 Typing Arity-Generic Vector Map
arity-generic map : instances have different types
Given arity n, generate corresponding type in the sequence
Part of the difficulty is that generic function is curried in both its type and term args.
This subsection starts with an initial def that takes
- all of the type args in a vector,
- curries term arguments
next subsection, shows how to uncurry type args
ℕ for arity
store types in vector of Agda types, Bool :: N :: [].
vector has type Vec Set 2, so can use standard vector operations (such as _⊗_)
(given in OPTIONS at top of file)
--type-in-type : gives Set the type Set
- simplifies presentation by hiding Agda’s infinite hierarchy of Set levels
- at cost of making Agda’s logic inconsistent
-}
-- folds arrow type constructor (→) over vector of types
-- used to construct the type of 1sr arg to nvec-map
arrTy : {n : ℕ} → Vec Set (suc n) → Set
arrTy {0} (A :: []) = A
arrTy {suc n} (A :: As) = A → arrTy As
arrTyTest : Set
arrTyTest = arrTy (ℕ :: ℕ :: Bool :: [])
-- C-c C-n arrTyTest
-- ℕ → ℕ → Bool
-- Constructs result type of arity-generic map for vectors.
-- Map Vec constructor onto the vector of types, then placing arrows between them.
-- There are two indices:
-- - n : number of types (the arity)
-- - m : length of vectors to be mapped over
arrTyVec : {n : ℕ} → ℕ → Vec Set (suc n) → Set
arrTyVec m As = arrTy (repeat (λ A → Vec A m) ⊗ As)
{- alternate type sigs of previous mapN examples:
map0' : {m : ℕ} {A : Set} → arrTy (A :: []) → arrTyVec m (A :: [])
map1' : {m : ℕ} {A B : Set} → arrTy (A :: B :: []) → arrTyVec m (A :: B :: [])
map2' : {m : ℕ} {A B C : Set} → arrTy (A :: B :: C :: []) → arrTyVec m (A :: B :: C :: [])
-}
nvec-map : {m : ℕ}
→ (n : ℕ) → {As : Vec Set (suc n)}
→ arrTy As → arrTyVec m As
nvec-map n f = g n (repeat f)
where
g : {m : ℕ}
→ (n : ℕ) → {As : Vec Set (suc n)}
→ Vec (arrTy As) m → arrTyVec m As
g 0 {A :: []} a = a
g (suc n) {A :: As} f = (λ a → g n (f ⊗ a))
nvec-map-Test : Vec ℕ 2 -- 11 :: 15 :: []
nvec-map-Test = nvec-map 1 { ℕ :: ℕ :: [] } (λ x → 10 + x) (1 :: 5 :: [])
{-
annoying : must explicitly supply types
next section : enable inference
--------------------------------------------------
3.2 A Curried Vector Map
Curry type args so they are supplied individually (rather than a ector).
Enables inference (usually).
-}
-- quantify : creates curried version of a type which depends on a vector
∀⇒ : {n : ℕ} {A : Set} → (Vec A n → Set)
→ Set
∀⇒ {zero} B = B []
∀⇒ {suc n} {A} B = (a : A) → ∀⇒ {n} (λ as → B (a :: as))
-- curry : creates curried version of a corresponding function term
λ⇒ : {n : ℕ} {A : Set} {B : Vec A n → Set}
→ ((X : Vec A n) → B X)
→ (∀⇒ B)
λ⇒ {zero} f = f []
λ⇒ {suc n} {A} f = (λ a → λ⇒ {n} (λ as → f (a :: as))) -- **** HERE
-- 'a' is implicit in paper
-- Victor says 'hidden' lambdas are magic.
-- see: Eliminating the problems of hidden-lambda insertion
-- https://www.cse.chalmers.se/~abela/MScThesisJohanssonLloyd.pdf
-- uncurry (from 2010 paper)
/⇒ : (n : ℕ) → {K : Set} {B : Vec K n → Set}
→ (∀⇒ B)
→ (A : Vec K n)
→ B A
/⇒ (zero) f [] = f
/⇒ (suc n) f (a :: as) = /⇒ n (f a) as
-- arity-generic map
nmap : {m : ℕ}
→ (n : ℕ) -- specifies arity
→ ∀⇒ (λ (As : Vec Set (suc n)) → arrTy As → arrTyVec m As)
nmap {m} n = λ⇒ (λ As → nvec-map {m} n {As})
{-
nmap 1
has type
{m : N} → {A B : Set} → (A → B) → (Vec A m) → (Vec B m)
C-c C-d
(a a₁ : Set) → (a → a₁) → arrTyVec _m_193 (a :: a₁ :: [])
nmap 1 (λ x → 10 + x) (10 :: 5 :: [])
evaluates to
11 :: 15 :: []
C-c C-d
(x : ℕ) → ℕ !=< Set
when checking that the expression λ x → 10 + x has type Set
nmap 2
has type
{m : N} → {ABC : Set} → (A → B → C) → Vec A m → Vec B m → Vec C m
C-c C-d
(a a₁ a₂ : Set) → (a → a₁ → a₂) → arrTyVec _m_193 (a :: a₁ :: a₂ :: [])
nmap 2 ( , ) (1 :: 2 :: 3 :: []) (4 :: 5 :: 6 :: [])
evaluates to
(1 , 4) :: (2 , 5) :: (3 , 6) :: []
now : do not need to explicitly specify type of data in vectors
-}
| 28.526316
| 99
| 0.551315
|
c7447f00bb86016821370d30bb51779693e16b10
| 1,403
|
agda
|
Agda
|
homotopy/JoinComm.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
homotopy/JoinComm.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
homotopy/JoinComm.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
module homotopy.JoinComm where
module _ {i j} {A : Type i} {B : Type j} where
swap : A * B → B * A
swap = Swap.f module SwapM where
swap-glue : (a : A) (b : B) → right a == left b
swap-glue a b = ! (glue (b , a))
module Swap = PushoutRec right left (uncurry swap-glue)
{- ∞TT:
swap : A * B → B * A
swap (left a) = right a
swap (right b) = left b
ap swap (glue (a , b)) = ! (glue (b , a))
-}
module _ {i j} {A : Type i} {B : Type j} where
swap-swap : (x : A * B) → swap (swap x) == x
swap-swap = Pushout-elim (λ a → idp) (λ b → idp) (λ c → ↓-∘=idf-in swap swap
(swap-swap-glue c)) where
swap-swap-glue : (c : A × B) → ap swap (ap swap (glue c)) == glue c
swap-swap-glue (a , b) =
ap swap (ap swap (glue (a , b))) =⟨ SwapM.Swap.glue-β (a , b) |in-ctx ap swap ⟩
ap swap (! (glue (b , a))) =⟨ ap-! swap (glue (b , a)) ⟩
! (ap swap (glue (b , a))) =⟨ SwapM.Swap.glue-β (b , a) |in-ctx ! ⟩
! (! (glue (a , b))) =⟨ !-! (glue (a , b)) ⟩
glue (a , b) ∎
{- ∞TT:
swap-swap : (x : A * B) → swap (swap x) == x
swap-swap (left a) = idp
swap-swap (right b) = idp
apd swap-swap (glue (a , b)) = !-! (glue (a , b))
-}
module _ {i j} {A : Type i} {B : Type j} where
swap-equiv : (A * B) ≃ (B * A)
swap-equiv = equiv swap swap swap-swap swap-swap
| 27.509804
| 87
| 0.493229
|
0dd5d8d42cf9f2c807bd289777812c1c8788789d
| 10,639
|
agda
|
Agda
|
src/Erased/Counterexamples/Cubical.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Erased/Counterexamples/Cubical.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Erased/Counterexamples/Cubical.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Some properties that hold for Erased do not hold for every
-- accessible modality
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
import Equality.Path as P
module Erased.Counterexamples.Cubical
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J as B using (_↔_)
open import Erased.Cubical eq
using (Σ-closed-reflective-subuniverse; Accessible)
open import Equality.Decision-procedures equality-with-J
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Equivalence.Path-split equality-with-J as PS
using (_-Null_; Is-∞-extendable-along-[_])
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as T
using (∥_∥; ∣_∣; Axiom-of-choice)
open import Preimage equality-with-J using (_⁻¹_)
private
variable
a b ℓ ℓ′ p : Level
A : Type a
-- A type is modal with respect to the modality ∥_∥ if it is a
-- proposition.
∥∥-modal : Type ℓ → Type ℓ
∥∥-modal = Is-proposition
-- Propositional truncation is a Σ-closed reflective subuniverse.
--
-- This proof is based on "Modalities in Homotopy Type Theory" by
-- Rijke, Shulman and Spitters.
∥∥-modality : Σ-closed-reflective-subuniverse ℓ
∥∥-modality {ℓ = ℓ} = λ where
.◯ → ∥_∥
.η → ∣_∣
.Is-modal → ∥∥-modal
.Is-modal-propositional → λ ext → H-level-propositional ext 1
.Is-modal-◯ → T.truncation-is-proposition
.Is-modal-respects-≃ → H-level-cong _ 1
.extendable-along-η → extendable
.Σ-closed → Σ-closure 1
where
open Σ-closed-reflective-subuniverse
extendable :
{A B : Type ℓ} →
Is-proposition B →
Is-∞-extendable-along-[ ∣_∣ ] (λ (_ : ∥ A ∥) → B)
extendable {A = A} {B = B} =
Is-proposition B →⟨ (λ prop →
_≃_.is-equivalence $
Eq.↔→≃
_
(T.rec prop)
refl
(λ f → ⟨ext⟩ $
T.elim
_
(λ _ → ⇒≡ 1 prop)
(λ _ → refl _))) ⟩
Is-equivalence (λ (f : ∥ A ∥ → B) → f ∘ ∣_∣) ↔⟨ inverse $ PS.Is-∞-extendable-along≃Is-equivalence ext ⟩□
Is-∞-extendable-along-[ ∣_∣ ] (λ (_ : ∥ A ∥) → B) □
-- The propositional truncation modality is accessible.
--
-- This proof is based on "Modalities in Homotopy Type Theory" by
-- Rijke, Shulman and Spitters.
∥∥-accessible : Accessible ℓ′ (∥∥-modality {ℓ = ℓ})
∥∥-accessible {ℓ′ = ℓ′} {ℓ = ℓ} =
↑ ℓ′ ⊤
, (λ _ → ↑ ℓ′ Bool)
, (λ A →
Is-proposition A ↝⟨ record { from = from; to = to } ⟩
(λ _ → ↑ ℓ′ Bool) -Null A ↔⟨ inverse $ PS.Π-Is-∞-extendable-along≃Null ext ⟩□
(↑ ℓ′ ⊤ → Is-∞-extendable-along-[ _ ] (λ _ → A)) □)
where
to : Is-proposition A → (λ _ → ↑ ℓ′ Bool) -Null A
to prop _ =
_≃_.is-equivalence $
Eq.⇔→≃
prop
(Π-closure ext 1 λ _ → prop)
_
(_$ lift true)
from : (λ _ → ↑ ℓ′ Bool) -Null A → Is-proposition A
from {A = A} null x y =
x ≡⟨⟩
case true ⦂ Bool of if_then x else y ≡⟨ cong (_$ true) $ sym $ E.right-inverse-of _ ⟩
E.to (E.from (if_then x else y)) true ≡⟨⟩
E.from (if_then x else y) ≡⟨⟩
E.to (E.from (if_then x else y)) false ≡⟨ cong (_$ false) $ E.right-inverse-of _ ⟩
case false ⦂ Bool of if_then x else y ≡⟨⟩
y ∎
where
≃Bool→ : A ≃ (Bool → A)
≃Bool→ =
A ↝⟨ Eq.⟨ _ , null _ ⟩ ⟩
(↑ ℓ′ Bool → A) ↝⟨ Eq.↔→≃ (_∘ lift) (_∘ lower) refl refl ⟩□
(Bool → A) □
module E = _≃_ ≃Bool→
-- It is not the case that, for all types A and B and functions
-- f : A → B, "f is ∥∥-connected" implies ∥ Is-equivalence f ∥.
¬[∥∥-connected→∥Is-equivalence∥] :
¬ ({A : Type a} {B : Type b} {f : A → B} →
(∀ y → Contractible ∥ f ⁻¹ y ∥) → ∥ Is-equivalence f ∥)
¬[∥∥-connected→∥Is-equivalence∥] hyp =
$⟨ (λ _ → ∣ lift true , refl _ ∣) ⟩
((y : ↑ _ ⊤) → ∥ (const (lift tt) ⦂ (↑ _ Bool → ↑ _ ⊤)) ⁻¹ y ∥) →⟨ (∀-cong _ λ _ →
propositional⇒inhabited⇒contractible T.truncation-is-proposition) ⟩
((y : ↑ _ ⊤) →
Contractible ∥ (const (lift tt) ⦂ (↑ _ Bool → ↑ _ ⊤)) ⁻¹ y ∥) →⟨ hyp ⟩
∥ Is-equivalence (const (lift tt) ⦂ (↑ _ Bool → ↑ _ ⊤)) ∥ ↔⟨ T.∥∥↔ (Eq.propositional ext _) ⟩
Is-equivalence (const (lift tt) ⦂ (↑ _ Bool → ↑ _ ⊤)) →⟨ Eq.⟨ _ ,_⟩ ⟩
↑ _ Bool ≃ ↑ _ ⊤ →⟨ (λ eq → Eq.↔⇒≃ B.↑↔ F.∘ eq F.∘ Eq.↔⇒≃ (inverse B.↑↔)) ⟩
Bool ≃ ⊤ →⟨ (λ eq → H-level-cong _ 1 (inverse eq) (mono₁ 0 ⊤-contractible)) ⟩
Is-proposition Bool →⟨ ¬-Bool-propositional ⟩□
⊥ □
-- It is not the case that, for all types A and B and functions
-- f : A → B, "f is ∥∥-connected" is equivalent to
-- ∥ Is-equivalence f ∥.
--
-- Compare with
-- Erased.Level-1.[]-cong₂-⊔.Erased-connected↔Erased-Is-equivalence.
¬[∥∥-connected≃∥Is-equivalence∥] :
¬ ({A : Type a} {B : Type b} {f : A → B} →
(∀ y → Contractible ∥ f ⁻¹ y ∥) ≃ ∥ Is-equivalence f ∥)
¬[∥∥-connected≃∥Is-equivalence∥] hyp =
¬[∥∥-connected→∥Is-equivalence∥] (_≃_.to hyp)
-- If (x : A) → ∥ P x ∥ implies ∥ ((x : A) → P x) ∥ for all types A
-- and type families P over A, then the axiom of choice holds.
[Π∥∥→∥Π∥]→Axiom-of-choice :
({A : Type a} {P : A → Type p} →
((x : A) → ∥ P x ∥) → ∥ ((x : A) → P x) ∥) →
Axiom-of-choice a p
[Π∥∥→∥Π∥]→Axiom-of-choice hyp = λ _ → hyp
-- If ∥ ((x : A) → P x) ∥ is isomorphic to (x : A) → ∥ P x ∥ for all
-- types A and type families P over A, then the axiom of choice holds.
--
-- Compare with Erased.Level-1.Erased-Π↔Π.
[∥Π∥↔Π∥∥]→Axiom-of-choice :
({A : Type a} {P : A → Type p} →
∥ ((x : A) → P x) ∥ ↔ ((x : A) → ∥ P x ∥)) →
Axiom-of-choice a p
[∥Π∥↔Π∥∥]→Axiom-of-choice hyp =
[Π∥∥→∥Π∥]→Axiom-of-choice (_↔_.from hyp)
-- If ∥ A ∥ → ∥ B ∥ implies ∥ (A → B) ∥ for all types A and B in the
-- same universe, then ∥ (∥ A ∥ → A) ∥ holds for every type A in this
-- universe. This is a variant of the axiom of choice of which Kraus
-- et al. state that "We expect that this makes it possible to show
-- that, in MLTT with weak propositional truncation, [a logically
-- equivalent variant of the axiom] is not derivable" (see "Notions of
-- Anonymous Existence in Martin-Löf Type Theory").
[[∥∥→∥∥]→∥→∥]→Axiom-of-choice :
({A B : Type a} → (∥ A ∥ → ∥ B ∥) → ∥ (A → B) ∥) →
({A : Type a} → ∥ (∥ A ∥ → A) ∥)
[[∥∥→∥∥]→∥→∥]→Axiom-of-choice hyp {A = A} =
$⟨ T.rec T.truncation-is-proposition id ⟩
(∥ ∥ A ∥ ∥ → ∥ A ∥) →⟨ hyp ⟩□
∥ (∥ A ∥ → A) ∥ □
-- If ∥ (A → B) ∥ is isomorphic to ∥ A ∥ → ∥ B ∥ for all types A and B
-- in the same universe, then ∥ (∥ A ∥ → A) ∥ holds for every type A
-- in this universe. This is a variant of the axiom of choice of which
-- Kraus et al. state that "We expect that this makes it possible to
-- show that, in MLTT with weak propositional truncation, [a logically
-- equivalent variant of the axiom] is not derivable" (see "Notions of
-- Anonymous Existence in Martin-Löf Type Theory").
--
-- Compare with Erased.Level-1.Erased-Π↔Π-Erased.
[∥→∥↔[∥∥→∥∥]]→Axiom-of-choice :
({A B : Type a} → ∥ (A → B) ∥ ↔ (∥ A ∥ → ∥ B ∥)) →
({A : Type a} → ∥ (∥ A ∥ → A) ∥)
[∥→∥↔[∥∥→∥∥]]→Axiom-of-choice hyp =
[[∥∥→∥∥]→∥→∥]→Axiom-of-choice (_↔_.from hyp)
-- It is not the case that, for every type A, if A is ∥∥-modal, then A
-- is (λ (A : Type a) → ∥∥-modal A)-null.
¬[∥∥-modal→∥∥-modal-Null] :
¬ ({A : Type a} → ∥∥-modal A → (λ (A : Type a) → ∥∥-modal A) -Null A)
¬[∥∥-modal→∥∥-modal-Null] hyp = $⟨ ⊥-propositional ⟩
Is-proposition ⊥ →⟨ hyp ⟩
(∀ A → Is-equivalence (const ⦂ (⊥ → Is-proposition A → ⊥))) →⟨ _$ _ ⟩
Is-equivalence (const ⦂ (⊥ → Is-proposition (↑ _ Bool) → ⊥)) →⟨ Eq.⟨ _ ,_⟩ ⟩
⊥ ≃ (Is-proposition (↑ _ Bool) → ⊥) →⟨ →-cong ext
(Eq.↔⇒≃ $ inverse $
B.⊥↔uninhabited (¬-Bool-propositional ∘ ↑⁻¹-closure 1))
Eq.id F.∘_ ⟩
⊥ ≃ (⊥₀ → ⊥) →⟨ Π⊥↔⊤ ext F.∘_ ⟩
⊥ ≃ ⊤ →⟨ (λ eq → ⊥-elim $ _≃_.from eq _) ⟩□
⊥ □
-- It is not the case that, for every type A, there is an equivalence
-- between "A is ∥∥-modal" and (λ (A : Type a) → ∥∥-modal A) -Null A.
--
-- Compare with Erased.Stability.Very-stable≃Very-stable-Null.
¬[∥∥-modal≃∥∥-modal-Null] :
¬ ({A : Type a} → ∥∥-modal A ≃ (λ (A : Type a) → ∥∥-modal A) -Null A)
¬[∥∥-modal≃∥∥-modal-Null] hyp =
¬[∥∥-modal→∥∥-modal-Null] (_≃_.to hyp)
-- It is not the case that, for every type A : Type a and proof of
-- Extensionality a a, there is an equivalence between "A is ∥∥-modal"
-- and (λ (A : Type a) → ∥∥-modal A) -Null A.
--
-- Compare with Erased.Stability.Very-stable≃Very-stable-Null.
¬[∥∥-modal≃∥∥-modal-Null]′ :
¬ ({A : Type a} →
Extensionality a a →
∥∥-modal A ≃ (λ (A : Type a) → ∥∥-modal A) -Null A)
¬[∥∥-modal≃∥∥-modal-Null]′ hyp =
¬[∥∥-modal≃∥∥-modal-Null] (hyp ext)
| 41.721569
| 138
| 0.468183
|
7c726d5394d85911bf06b8181ba5a0b48ca2317c
| 4,375
|
agda
|
Agda
|
examples/SimpleTypes.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/SimpleTypes.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/SimpleTypes.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-
A simple bidirectional type checker for simply typed lambda calculus which is
sound by construction.
-}
module SimpleTypes where
infix 10 _==_
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
data Maybe (A : Set) : Set where
nothing : Maybe A
just : A -> Maybe A
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Fin : Nat -> Set where
fzero : {n : Nat} -> Fin (suc n)
fsuc : {n : Nat} -> Fin n -> Fin (suc n)
data List (A : Set) : Set where
ε : List A
_,_ : List A -> A -> List A
length : forall {A} -> List A -> Nat
length ε = zero
length (xs , x) = suc (length xs)
infixl 25 _,_
-- Raw terms
data Expr : Set where
varʳ : Nat -> Expr
_•ʳ_ : Expr -> Expr -> Expr
ƛʳ_ : Expr -> Expr
infixl 90 _•ʳ_
infix 50 ƛʳ_
-- Types
data Type : Set where
ι : Type
_⟶_ : Type -> Type -> Type
infixr 40 _⟶_
-- Typed terms
Ctx = List Type
data Var : Ctx -> Type -> Set where
vz : forall {Γ τ} -> Var (Γ , τ) τ
vs : forall {Γ τ σ} -> Var Γ τ -> Var (Γ , σ) τ
data Term : Ctx -> Type -> Set where
var : forall {Γ τ} -> Var Γ τ -> Term Γ τ
_•_ : forall {Γ τ σ} -> Term Γ (τ ⟶ σ) -> Term Γ τ -> Term Γ σ
ƛ_ : forall {Γ τ σ} -> Term (Γ , σ) τ -> Term Γ (σ ⟶ τ)
infixl 90 _•_
infix 50 ƛ_
-- Type erasure
⌊_⌋ˣ : forall {Γ τ} -> Var Γ τ -> Nat
⌊ vz ⌋ˣ = zero
⌊ vs x ⌋ˣ = suc ⌊ x ⌋ˣ
⌊_⌋ : forall {Γ τ} -> Term Γ τ -> Expr
⌊ var v ⌋ = varʳ ⌊ v ⌋ˣ
⌊ s • t ⌋ = ⌊ s ⌋ •ʳ ⌊ t ⌋
⌊ ƛ t ⌋ = ƛʳ ⌊ t ⌋
-- Type equality
infix 30 _≟_
_≟_ : (σ τ : Type) -> Maybe (σ == τ)
ι ≟ ι = just refl
σ₁ ⟶ τ₁ ≟ σ₂ ⟶ τ₂ with σ₁ ≟ σ₂ | τ₁ ≟ τ₂
σ ⟶ τ ≟ .σ ⟶ .τ | just refl | just refl = just refl
_ ⟶ _ ≟ _ ⟶ _ | _ | _ = nothing
_ ≟ _ = nothing
-- The type checked view
-- ok : forall {Γ τ e} -> Check ⌊ e ⌋ -- unsolved metas with no range!
data Check (Γ : Ctx)(τ : Type) : Expr -> Set where
ok : (t : Term Γ τ) -> Check Γ τ ⌊ t ⌋
bad : {e : Expr} -> Check Γ τ e
data Infer (Γ : Ctx) : Expr -> Set where
yes : (τ : Type)(t : Term Γ τ) -> Infer Γ ⌊ t ⌋
no : {e : Expr} -> Infer Γ e
data Lookup (Γ : Ctx) : Nat -> Set where
found : (τ : Type)(x : Var Γ τ) -> Lookup Γ ⌊ x ⌋ˣ
outofscope : {n : Nat} -> Lookup Γ n
lookup : (Γ : Ctx)(n : Nat) -> Lookup Γ n
lookup ε n = outofscope
lookup (Γ , τ) zero = found τ vz
lookup (Γ , σ) (suc n) with lookup Γ n
lookup (Γ , σ) (suc .(⌊ x ⌋ˣ)) | found τ x = found τ (vs x)
lookup (Γ , σ) (suc n) | outofscope = outofscope
infix 20 _⊢_∋_ _⊢_∈
_⊢_∈ : (Γ : Ctx)(e : Expr) -> Infer Γ e
_⊢_∋_ : (Γ : Ctx)(τ : Type)(e : Expr) -> Check Γ τ e
Γ ⊢ ι ∋ ƛʳ e = bad
Γ ⊢ (σ ⟶ τ) ∋ ƛʳ e with Γ , σ ⊢ τ ∋ e
Γ ⊢ (σ ⟶ τ) ∋ ƛʳ .(⌊ t ⌋) | ok t = ok (ƛ t)
Γ ⊢ (σ ⟶ τ) ∋ ƛʳ _ | bad = bad
Γ ⊢ τ ∋ e with Γ ⊢ e ∈
Γ ⊢ τ ∋ .(⌊ t ⌋) | yes σ t with τ ≟ σ
Γ ⊢ τ ∋ .(⌊ t ⌋) | yes .τ t | just refl = ok t
Γ ⊢ τ ∋ .(⌊ t ⌋) | yes σ t | nothing = bad
Γ ⊢ τ ∋ e | no = bad
Γ ⊢ varʳ i ∈ with lookup Γ i
Γ ⊢ varʳ .(⌊ x ⌋ˣ) ∈ | found τ x = yes τ (var x)
Γ ⊢ varʳ _ ∈ | outofscope = no
Γ ⊢ e₁ •ʳ e₂ ∈ with Γ ⊢ e₁ ∈
Γ ⊢ e₁ •ʳ e₂ ∈ | no = no
Γ ⊢ .(⌊ t₁ ⌋) •ʳ e₂ ∈ | yes ι t₁ = no
Γ ⊢ .(⌊ t₁ ⌋) •ʳ e₂ ∈ | yes (σ ⟶ τ) t₁ with Γ ⊢ σ ∋ e₂
Γ ⊢ .(⌊ t₁ ⌋) •ʳ .(⌊ t₂ ⌋) ∈ | yes (σ ⟶ τ) t₁ | ok t₂ = yes τ (t₁ • t₂)
Γ ⊢ .(⌊ t₁ ⌋) •ʳ _ ∈ | yes (σ ⟶ τ) t₁ | bad = no
Γ ⊢ ƛʳ e ∈ = no
-- Proving completeness (for normal terms)
-- Needs magic with
{-
mutual
data Nf : forall {Γ τ} -> Term Γ τ -> Set where
ƛ-nf : forall {Γ σ τ} -> {t : Term (Γ , σ) τ} -> Nf t -> Nf (ƛ t)
ne-nf : forall {Γ τ} -> {t : Term Γ τ} -> Ne t -> Nf t
data Ne : forall {Γ τ} -> Term Γ τ -> Set where
•-ne : forall {Γ σ τ} ->
{t₁ : Term Γ (σ ⟶ τ)} -> Ne t₁ ->
{t₂ : Term Γ σ} -> Nf t₂ -> Ne (t₁ • t₂)
var-ne : forall {Γ τ} -> {x : Var Γ τ} -> Ne (var x)
mutual
complete-check : forall {Γ τ} -> (t : Term Γ τ) -> Nf t ->
Γ ⊢ τ ∋ ⌊ t ⌋ == ok t
complete-check ._ (ƛ-nf t) = {! !}
complete-check _ (ne-nf n) with complete-infer _ n
complete-check t (ne-nf n) | p = {! !}
complete-infer : forall {Γ τ} -> (t : Term Γ τ) -> Ne t ->
Γ ⊢ ⌊ t ⌋ ∈ == yes τ t
complete-infer t ne = {! !}
-}
-- Testing
test1 = ε ⊢ ι ⟶ ι ∋ ƛʳ varʳ zero
test2 = ε , ι , ι ⟶ ι ⊢ varʳ zero •ʳ varʳ (suc zero) ∈
| 25.143678
| 79
| 0.478629
|
374ea88a99c03ac8ec0e809a3bf10ea11051f33a
| 1,519
|
agda
|
Agda
|
htype-decidable.agda
|
hazelgrove/hazelnut-dynamics-agda
|
229dfb06ea51ebe91cb3b1c973c2f2792e66797c
|
[
"MIT"
] | 16
|
2018-03-12T14:32:03.000Z
|
2021-12-19T02:50:23.000Z
|
htype-decidable.agda
|
hazelgrove/hazelnut-dynamics-agda
|
229dfb06ea51ebe91cb3b1c973c2f2792e66797c
|
[
"MIT"
] | 54
|
2017-06-29T20:53:34.000Z
|
2018-11-29T16:32:40.000Z
|
htype-decidable.agda
|
hazelgrove/hazelnut-dynamics-agda
|
229dfb06ea51ebe91cb3b1c973c2f2792e66797c
|
[
"MIT"
] | 1
|
2019-09-13T18:20:02.000Z
|
2019-09-13T18:20:02.000Z
|
open import Nat
open import Prelude
open import core
open import contexts
module htype-decidable where
lemma-l : ∀{t1 t2 t4} → t1 ==> t2 == t1 ==> t4 → t2 == t4
lemma-l refl = refl
lemma-r : ∀{t1 t2 t3} → t1 ==> t2 == t3 ==> t2 → t1 == t3
lemma-r refl = refl
lemma-b : ∀{t1 t2 t3 t4} → t1 ==> t2 == t3 ==> t4 → t1 == t3
lemma-b refl = refl
htype-dec : (t1 t2 : htyp) → t1 == t2 + (t1 == t2 → ⊥)
htype-dec b b = Inl refl
htype-dec b ⦇-⦈ = Inr (λ ())
htype-dec b (t2 ==> t3) = Inr (λ ())
htype-dec ⦇-⦈ b = Inr (λ ())
htype-dec ⦇-⦈ ⦇-⦈ = Inl refl
htype-dec ⦇-⦈ (t2 ==> t3) = Inr (λ ())
htype-dec (t1 ==> t2) b = Inr (λ ())
htype-dec (t1 ==> t2) ⦇-⦈ = Inr (λ ())
htype-dec (t1 ==> t2) (t3 ==> t4) with htype-dec t1 t3 | htype-dec t2 t4
htype-dec (t1 ==> t2) (.t1 ==> .t2) | Inl refl | Inl refl = Inl refl
htype-dec (t1 ==> t2) (.t1 ==> t4) | Inl refl | Inr x₁ = Inr (λ x → x₁ (lemma-l x))
htype-dec (t1 ==> t2) (t3 ==> .t2) | Inr x | Inl refl = Inr (λ x₁ → x (lemma-r x₁))
htype-dec (t1 ==> t2) (t3 ==> t4) | Inr x | Inr x₁ = Inr (λ x₂ → x (lemma-b x₂))
-- if an arrow is disequal, it disagrees in the first or second argument
ne-factor : ∀{τ1 τ2 τ3 τ4} → (τ1 ==> τ2) ≠ (τ3 ==> τ4) → (τ1 ≠ τ3) + (τ2 ≠ τ4)
ne-factor {τ1} {τ2} {τ3} {τ4} ne with htype-dec τ1 τ3 | htype-dec τ2 τ4
ne-factor ne | Inl refl | Inl refl = Inl (λ x → ne refl)
ne-factor ne | Inl x | Inr x₁ = Inr x₁
ne-factor ne | Inr x | Inl x₁ = Inl x
ne-factor ne | Inr x | Inr x₁ = Inl x
| 39.973684
| 89
| 0.523371
|
522047ed567b63da5df3fa8f97311b93b30ee859
| 5,770
|
agda
|
Agda
|
GSeTT/Dec-Type-Checking.agda
|
thibautbenjamin/catt-formalization
|
3a02010a869697f4833c9bc6047d66ca27b87cf2
|
[
"MIT"
] | null | null | null |
GSeTT/Dec-Type-Checking.agda
|
thibautbenjamin/catt-formalization
|
3a02010a869697f4833c9bc6047d66ca27b87cf2
|
[
"MIT"
] | null | null | null |
GSeTT/Dec-Type-Checking.agda
|
thibautbenjamin/catt-formalization
|
3a02010a869697f4833c9bc6047d66ca27b87cf2
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting --without-K #-}
open import Agda.Primitive
open import Prelude
open import GSeTT.Syntax
open import GSeTT.Rules
{- Decidability of type cheking for the type theory for globular sets -}
module GSeTT.Dec-Type-Checking where
dec-⊢C : ∀ Γ → dec (Γ ⊢C)
dec-⊢T : ∀ Γ A → dec (Γ ⊢T A)
dec-⊢t : ∀ Γ A t → dec (Γ ⊢t t # A)
dec-⊢S : ∀ Δ Γ γ → dec (Δ ⊢S γ > Γ)
private
Γ+⊢→Γ⊢ : ∀ {Γ x A} → (Γ :: (x , A)) ⊢C → Γ ⊢C
Γ+⊢→Γ⊢ (cc Γ⊢ _ idp) = Γ⊢
Γ+⊢→x=l : ∀ {Γ x A} → (Γ :: (x , A)) ⊢C → x == length Γ
Γ+⊢→x=l (cc _ _ idp) = idp
Γ+⊢→Γ⊢A : ∀ {Γ x A} → (Γ :: (x , A)) ⊢C → Γ ⊢T A
Γ+⊢→Γ⊢A (cc _ Γ⊢A _) = Γ⊢A
Γ⊢t⇒u→Γ⊢A : ∀ {Γ A t u} → Γ ⊢T ⇒ A t u → Γ ⊢T A
Γ⊢t⇒u→Γ⊢A (ar Γ⊢t:A Γ⊢u:A) = Γ⊢t:A→Γ⊢A Γ⊢t:A
Γ⊢t⇒u→Γ⊢t : ∀ {Γ A t u} → Γ ⊢T ⇒ A t u → Γ ⊢t t # A
Γ⊢t⇒u→Γ⊢t (ar Γ⊢t:A Γ⊢u:A) = Γ⊢t:A
Γ⊢t⇒u→Γ⊢u : ∀ {Γ A t u} → Γ ⊢T ⇒ A t u → Γ ⊢t u # A
Γ⊢t⇒u→Γ⊢u (ar Γ⊢t:A Γ⊢u:A) = Γ⊢u:A
Γ⊢x:A→x∈Γ : ∀ {Γ x A} → Γ ⊢t Var x # A → x # A ∈ Γ
Γ⊢x:A→x∈Γ (var _ x∈Γ) = x∈Γ
Δ⊢<>:Γ→Γ=nil : ∀ {Δ Γ} → Δ ⊢S nil > Γ → Γ == nil
Δ⊢<>:Γ→Γ=nil (es _) = idp
Δ⊢γ:⊘→γ=nil : ∀ {Δ γ} → Δ ⊢S γ > nil → γ == nil
Δ⊢γ:⊘→γ=nil (es _) = idp
Δ⊢γ+:Γ+→x=y : ∀ {Δ Γ x A γ y t} → Δ ⊢S (γ :: (y , t)) > (Γ :: (x , A)) → x == y
Δ⊢γ+:Γ+→x=y (sc _ _ _ idp) = idp
Δ⊢γ+:Γ+→Δ⊢t : ∀ {Δ Γ x A γ y t} → Δ ⊢S (γ :: (y , t)) > (Γ :: (x , A)) → Δ ⊢t t # (A [ γ ]Pre-Ty)
Δ⊢γ+:Γ+→Δ⊢t (sc _ _ Δ⊢t idp) = Δ⊢t
Δ⊢γ+:Γ+→Δ⊢γ : ∀ {Δ Γ x A γ y t} → Δ ⊢S (γ :: (y , t)) > (Γ :: (x , A)) → Δ ⊢S γ > Γ
Δ⊢γ+:Γ+→Δ⊢γ (sc Δ⊢γ:Γ _ _ idp) = Δ⊢γ:Γ
eqdec-Ty : eqdec Pre-Ty
eqdec-Tm : eqdec Pre-Tm
eqdec-Ty ∗ ∗ = inl idp
eqdec-Ty ∗ (⇒ _ _ _) = inr λ{()}
eqdec-Ty (⇒ _ _ _) ∗ = inr λ{()}
eqdec-Ty (⇒ A t u) (⇒ B t' u') with eqdec-Ty A B | eqdec-Tm t t' | eqdec-Tm u u'
... | inl idp | inl idp | inl idp = inl idp
... | inl idp | inl idp | inr u≠u' = inr λ p → u≠u' (snd (=⇒ p))
... | inl idp | inr t≠t' | _ = inr λ p → t≠t' (snd (fst (=⇒ p)))
... | inr A≠B | _ | _ = inr λ p → A≠B (fst (fst (=⇒ p)))
eqdec-Tm (Var x) (Var y) with eqdecℕ x y
... | inl idp = inl idp
... | inr x≠y = inr λ p → x≠y (=Var p)
dec-∈ : ∀ Γ x A → dec (x # A ∈ Γ)
dec-∈ nil x A = inr λ x → x
dec-∈ (Γ :: (y , B)) x A with (eqdecℕ y x) | (eqdec-Ty B A)
... | inl idp | inl idp = inl (inr (idp , idp))
... | inl idp | inr B≠A with dec-∈ Γ x A
... | inl x∈Γ = inl (inl x∈Γ)
... | inr x∉Γ = inr λ {(inl x∈Γ) → x∉Γ x∈Γ ; (inr (_ , A=B)) → B≠A (A=B ^)}
dec-∈ (Γ :: (y , B)) x A | inr y≠x | _ with dec-∈ Γ x A
... | inl x∈Γ = inl (inl x∈Γ)
... | inr x∉Γ = inr λ{ (inl x∈Γ) → x∉Γ x∈Γ ; (inr (x=y , _)) → y≠x (x=y ^)}
dec-⊢C nil = inl ec
dec-⊢C (Γ :: (x , A)) with dec-⊢C Γ | eqdecℕ x (length Γ) | dec-⊢T Γ A
... | inl Γ⊢ | inl idp | inl Γ⊢A = inl (cc Γ⊢ Γ⊢A idp)
... | inl _ | inl idp | inr Γ⊬A = inr λ Γ+⊢ → Γ⊬A (Γ+⊢→Γ⊢A Γ+⊢)
... | inl Γ⊢ | inr n≠l | _ = inr λ Γ+⊢ → n≠l (Γ+⊢→x=l Γ+⊢)
... | inr Γ⊬ | _ | _ = inr λ Γ+⊢ → Γ⊬ (Γ+⊢→Γ⊢ Γ+⊢)
dec-⊢T Γ ∗ with dec-⊢C Γ
... | inl Γ⊢ = inl (ob Γ⊢)
... | inr Γ⊬ = inr λ Γ⊢* → Γ⊬ (Γ⊢A→Γ⊢ Γ⊢*)
dec-⊢T Γ (⇒ A t u) with dec-⊢t Γ A t | dec-⊢t Γ A u
... | inl Γ⊢t:A | inl Γ⊢u:A = inl (ar Γ⊢t:A Γ⊢u:A)
... | inl _ | inr Γ⊬u:A = inr λ Γ⊢t⇒u → Γ⊬u:A (Γ⊢t⇒u→Γ⊢u Γ⊢t⇒u)
... | inr Γ⊬t:A | _ = inr λ Γ⊢t⇒u → Γ⊬t:A (Γ⊢t⇒u→Γ⊢t Γ⊢t⇒u)
dec-⊢t Γ A (Var x) with dec-⊢C Γ | dec-∈ Γ x A
... | inl Γ⊢ | inl x∈Γ = inl (var Γ⊢ x∈Γ)
... | inl _ | inr x∉Γ = inr λ Γ⊢x:A → x∉Γ (Γ⊢x:A→x∈Γ Γ⊢x:A)
... | inr Γ⊬ | _ = inr λ Γ⊢x:A → Γ⊬ (Γ⊢t:A→Γ⊢ Γ⊢x:A)
dec-⊢S Δ nil nil with dec-⊢C Δ
... | inl Δ⊢ = inl (es Δ⊢)
... | inr Δ⊬ = inr λ Δ⊢<>:⊘ → Δ⊬ (Δ⊢γ:Γ→Δ⊢ Δ⊢<>:⊘)
dec-⊢S Δ (Γ :: _) nil = inr λ Δ⊢<>:Γ → cons≠nil (Δ⊢<>:Γ→Γ=nil Δ⊢<>:Γ)
dec-⊢S Δ nil (γ :: a) = inr λ Δ⊢γ:⊘ → cons≠nil (Δ⊢γ:⊘→γ=nil Δ⊢γ:⊘)
dec-⊢S Δ (Γ :: (x , A)) (γ :: (y , t)) with dec-⊢S Δ Γ γ | dec-⊢C (Γ :: (x , A)) | dec-⊢t Δ (A [ γ ]Pre-Ty) t | eqdecℕ x y
... | inl Δ⊢γ:Γ | inl Γ+⊢ | inl Δ⊢t | inl idp = inl (sc Δ⊢γ:Γ Γ+⊢ Δ⊢t idp)
... | inl _ | inl _ | inl _ | inr x≠y = inr λ Δ⊢γ+:Γ+ → x≠y (Δ⊢γ+:Γ+→x=y Δ⊢γ+:Γ+)
... | inl _ | inl _ | inr Δ⊬t | _ = inr λ Δ⊢γ+:Γ+ → Δ⊬t (Δ⊢γ+:Γ+→Δ⊢t Δ⊢γ+:Γ+)
... | inl _ | inr Γ+⊬ | _ | _ = inr λ Δ⊢γ+:Γ+ → Γ+⊬ (Δ⊢γ:Γ→Γ⊢ Δ⊢γ+:Γ+)
... | inr Δ⊬γ | _ | _ | _ = inr λ Δ⊢γ+:Γ+ → Δ⊬γ (Δ⊢γ+:Γ+→Δ⊢γ Δ⊢γ+:Γ+)
| 51.981982
| 168
| 0.311785
|
3882c2189058953d92c486473d80301f3e3a01a5
| 5,352
|
agda
|
Agda
|
Data/Either/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Data/Either/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Data/Either/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Data.Either.Proofs where
import Lvl
open import Data
open import Data.Either as Either
open import Data.Either.Equiv
open import Function.Equals
open import Functional
open import Logic.Propositional
open import Logic.Predicate
open import Structure.Setoid
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Function.Domain.Proofs
open import Structure.Function.Multi
open import Structure.Operator
open import Structure.Relator.Properties
open import Syntax.Transitivity
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₑ₄ ℓₑ₅ ℓₑ₆ : Lvl.Level
private variable A B C A₁ A₂ A₃ B₁ B₂ B₃ : Type{ℓ}
module _ ⦃ equiv-C : Equiv{ℓₑ₃}(C) ⦄ where
map1-values : {f : A → C}{g : B → C}{e : A ‖ B} → (∃(x ↦ map1 f g e ≡ f(x)) ∨ ∃(x ↦ map1 f g e ≡ g(x)))
map1-values {e = Either.Left a} = [∨]-introₗ ([∃]-intro a ⦃ reflexivity(_≡_) ⦄)
map1-values {e = Either.Right b} = [∨]-introᵣ ([∃]-intro b ⦃ reflexivity(_≡_) ⦄)
module _ where
module _ ⦃ _ : Equiv{ℓₑ}(A ‖ B) ⦄ where
mapLeft-preserves-id : Names.Preserving₀ ⦃ [⊜]-equiv ⦄ (mapLeft {A₁ = A}{B = B})(id)(id)
_⊜_.proof (mapLeft-preserves-id) {Left x} = reflexivity(_≡_)
_⊜_.proof (mapLeft-preserves-id) {Right x} = reflexivity(_≡_)
mapRight-preserves-id : Names.Preserving₀ ⦃ [⊜]-equiv ⦄ (mapRight {A = A}{B₁ = B})(id)(id)
_⊜_.proof (mapRight-preserves-id) {Left x} = reflexivity(_≡_)
_⊜_.proof (mapRight-preserves-id) {Right x} = reflexivity(_≡_)
swap-involution : (Either.swap ∘ Either.swap {A = A}{B = B} ⊜ id)
_⊜_.proof swap-involution {Left _} = reflexivity(_≡_)
_⊜_.proof swap-involution {Right _} = reflexivity(_≡_)
module _ ⦃ _ : let _ = A₁ ; _ = A₂ ; _ = A₃ ; _ = B in Equiv{ℓₑ}(A₃ ‖ B) ⦄ {f : A₂ → A₃} {g : A₁ → A₂} where
mapLeft-preserves-[∘] : (mapLeft(f ∘ g) ⊜ (mapLeft f) ∘ (mapLeft g))
_⊜_.proof mapLeft-preserves-[∘] {Left x} = reflexivity(_≡_)
_⊜_.proof mapLeft-preserves-[∘] {Right x} = reflexivity(_≡_)
module _ ⦃ _ : let _ = A ; _ = B₁ ; _ = B₂ ; _ = B₃ in Equiv{ℓₑ}(A ‖ B₃) ⦄ {f : B₂ → B₃} {g : B₁ → B₂} where
mapRight-preserves-[∘] : (mapRight(f ∘ g) ⊜ (mapRight f) ∘ (mapRight g))
_⊜_.proof mapRight-preserves-[∘] {Left x} = reflexivity(_≡_)
_⊜_.proof mapRight-preserves-[∘] {Right x} = reflexivity(_≡_)
module _ ⦃ _ : Equiv{ℓₑ}(A ‖ B) ⦄ where
map-preserves-id : (map id id ⊜ id)
_⊜_.proof map-preserves-id {Left x} = reflexivity(_≡_)
_⊜_.proof map-preserves-id {Right x} = reflexivity(_≡_)
module _
⦃ equiv-A₁ : Equiv{ℓₑ₁}(A₁) ⦄
⦃ equiv-B₁ : Equiv{ℓₑ₂}(B₁) ⦄
⦃ equiv-A₂ : Equiv{ℓₑ₃}(A₂) ⦄
⦃ equiv-B₂ : Equiv{ℓₑ₄}(B₂) ⦄
⦃ equiv-AB₁ : Equiv{ℓₑ₅}(A₁ ‖ B₁) ⦄ ⦃ ext-AB₁ : Extensionality(equiv-AB₁) ⦄
⦃ equiv-AB₂ : Equiv{ℓₑ₆}(A₂ ‖ B₂) ⦄ ⦃ ext-AB₂ : Extensionality(equiv-AB₂) ⦄
{f : A₁ → A₂}
{g : B₁ → B₂}
where
open Extensionality ⦃ … ⦄
instance
map-function : BinaryOperator(Either.map {A₁ = A₁}{A₂ = A₂}{B₁ = B₁}{B₂ = B₂})
_⊜_.proof (BinaryOperator.congruence map-function (intro p₁) (intro p₂)) {Left _} = congruence₁(Left) p₁
_⊜_.proof (BinaryOperator.congruence map-function (intro p₁) (intro p₂)) {Right _} = congruence₁(Right) p₂
instance
map-injective : ⦃ inj-f : Injective(f) ⦄ → ⦃ inj-g : Injective(g) ⦄ → Injective(Either.map f g)
Injective.proof map-injective {Left x} {Left y} p = congruence₁(Either.Left) (injective(f) (injective(Either.Left) p))
Injective.proof map-injective {Left x} {Right y} p with () ← Left-Right-inequality p
Injective.proof map-injective {Right x} {Left y} p with () ← Left-Right-inequality (symmetry(_≡_) p)
Injective.proof map-injective {Right x} {Right y} p = congruence₁(Either.Right) (injective(g) (injective(Either.Right) p))
instance
map-surjective : ⦃ surj-f : Surjective(f) ⦄ → ⦃ surj-g : Surjective(g) ⦄ → Surjective(Either.map f g)
Surjective.proof map-surjective {Left y} with [∃]-intro x ⦃ p ⦄ ← surjective(f){y} = [∃]-intro (Left x) ⦃ congruence₁(Left) p ⦄
Surjective.proof map-surjective {Right y} with [∃]-intro x ⦃ p ⦄ ← surjective(g){y} = [∃]-intro (Right x) ⦃ congruence₁(Right) p ⦄
instance
map-bijective : ⦃ bij-f : Bijective(f) ⦄ → ⦃ bij-g : Bijective(g) ⦄ → Bijective(Either.map f g)
map-bijective = injective-surjective-to-bijective(Either.map f g) where
instance
inj-f : Injective(f)
inj-f = bijective-to-injective(f)
instance
inj-g : Injective(g)
inj-g = bijective-to-injective(g)
instance
surj-f : Surjective(f)
surj-f = bijective-to-surjective(f)
instance
surj-g : Surjective(g)
surj-g = bijective-to-surjective(g)
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
⦃ equiv-AB : Equiv{ℓₑ}(A ‖ B) ⦄ ⦃ ext-AB : Extensionality(equiv-AB) ⦄
where
map-mapLeft-mapRight : ∀{f : B → A}{g : C → B} → (map f g ≡ mapLeft f ∘ mapRight g)
_⊜_.proof (map-mapLeft-mapRight) {[∨]-introₗ _} = reflexivity(_≡_)
_⊜_.proof (map-mapLeft-mapRight) {[∨]-introᵣ _} = reflexivity(_≡_)
instance
map1-function : ⦃ equiv-C : Equiv{ℓₑ₃}(C) ⦄ → BinaryOperator{B = (A ‖ B) → C}(map1)
_⊜_.proof (BinaryOperator.congruence map1-function (intro p₁) (intro p₂)) {Left _} = p₁
_⊜_.proof (BinaryOperator.congruence map1-function (intro p₁) (intro p₂)) {Right _} = p₂
| 45.355932
| 134
| 0.634529
|
7c1aaf3e2973be2e08ba3ca63405afeb39f96313
| 518
|
agda
|
Agda
|
lib/types/Join.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
lib/types/Join.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
lib/types/Join.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Sigma
open import lib.types.Span
open import lib.types.Pointed
open import lib.types.Pushout
module lib.types.Join where
module _ {i j} (A : Type i) (B : Type j) where
*-span : Span
*-span = span A B (A × B) fst snd
infix 80 _*_
_*_ : Type _
_*_ = Pushout *-span
module _ {i j} (X : Ptd i) (Y : Ptd j) where
*-⊙span : ⊙Span
*-⊙span = ⊙span X Y (X ⊙× Y) ⊙fst ⊙snd
infix 80 _⊙*_
_⊙*_ : Ptd _
_⊙*_ = ⊙Pushout *-⊙span
| 17.266667
| 46
| 0.600386
|
381b53b2469eadef174e24933c209c1295fff1d1
| 52,614
|
agda
|
Agda
|
Agda/10-fundamental-theorem.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 333
|
2018-09-26T08:33:30.000Z
|
2022-03-22T23:50:15.000Z
|
Agda/10-fundamental-theorem.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 8
|
2019-06-18T04:16:04.000Z
|
2020-10-16T15:27:01.000Z
|
Agda/10-fundamental-theorem.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 30
|
2018-09-26T09:08:57.000Z
|
2022-03-16T00:33:50.000Z
|
{-# OPTIONS --without-K --exact-split --safe #-}
module 10-fundamental-theorem where
import 09-contractible-types
open 09-contractible-types public
--------------------------------------------------------------------------------
-- Section 8.1 Families of equivalences
{- Any family of maps induces a map on the total spaces. -}
tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x → C x) → ( Σ A B → Σ A C)
tot f t = pair (pr1 t) (f (pr1 t) (pr2 t))
{- We show that for any family of maps, the fiber of the induced map on total
spaces are equivalent to the fibers of the maps in the family. -}
fib-ftr-fib-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
fib (tot f) t → fib (f (pr1 t)) (pr2 t)
fib-ftr-fib-tot f .(pair x (f x y)) (pair (pair x y) refl) = pair y refl
fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
fib (f (pr1 t)) (pr2 t) → fib (tot f) t
fib-tot-fib-ftr F (pair a .(F a y)) (pair y refl) = pair (pair a y) refl
issec-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
((fib-ftr-fib-tot f t) ∘ (fib-tot-fib-ftr f t)) ~ id
issec-fib-tot-fib-ftr f (pair x .(f x y)) (pair y refl) = refl
isretr-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
((fib-tot-fib-ftr f t) ∘ (fib-ftr-fib-tot f t)) ~ id
isretr-fib-tot-fib-ftr f .(pair x (f x y)) (pair (pair x y) refl) = refl
abstract
is-equiv-fib-ftr-fib-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
is-equiv (fib-ftr-fib-tot f t)
is-equiv-fib-ftr-fib-tot f t =
is-equiv-has-inverse
( fib-tot-fib-ftr f t)
( issec-fib-tot-fib-ftr f t)
( isretr-fib-tot-fib-ftr f t)
abstract
is-equiv-fib-tot-fib-ftr :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → (t : Σ A C) →
is-equiv (fib-tot-fib-ftr f t)
is-equiv-fib-tot-fib-ftr f t =
is-equiv-has-inverse
( fib-ftr-fib-tot f t)
( isretr-fib-tot-fib-ftr f t)
( issec-fib-tot-fib-ftr f t)
{- Now that we have shown that the fibers of the induced map on total spaces
are equivalent to the fibers of the maps in the family, it follows that
the induced map on total spaces is an equivalence if and only if each map
in the family is an equivalence. -}
is-fiberwise-equiv :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x → C x) → UU (i ⊔ (j ⊔ k))
is-fiberwise-equiv f = (x : _) → is-equiv (f x)
abstract
is-equiv-tot-is-fiberwise-equiv :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
{f : (x : A) → B x → C x} → is-fiberwise-equiv f →
is-equiv (tot f )
is-equiv-tot-is-fiberwise-equiv {f = f} H =
is-equiv-is-contr-map
( λ t → is-contr-is-equiv _
( fib-ftr-fib-tot f t)
( is-equiv-fib-ftr-fib-tot f t)
( is-contr-map-is-equiv (H _) (pr2 t)))
abstract
is-fiberwise-equiv-is-equiv-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
(f : (x : A) → B x → C x) → is-equiv (tot f) →
is-fiberwise-equiv f
is-fiberwise-equiv-is-equiv-tot {A = A} {B} {C} f is-equiv-tot-f x =
is-equiv-is-contr-map
( λ z → is-contr-is-equiv'
( fib (tot f) (pair x z))
( fib-ftr-fib-tot f (pair x z))
( is-equiv-fib-ftr-fib-tot f (pair x z))
( is-contr-map-is-equiv is-equiv-tot-f (pair x z)))
equiv-tot :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k} →
((x : A) → B x ≃ C x) → (Σ A B) ≃ (Σ A C)
equiv-tot e =
pair
( tot (λ x → map-equiv (e x)))
( is-equiv-tot-is-fiberwise-equiv (λ x → is-equiv-map-equiv (e x)))
{- In the second part of this section we show that any equivalence f on base
types also induces an equivalence on total spaces. -}
Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
Σ A (λ x → C (f x)) → Σ B C
Σ-map-base-map f C s = pair (f (pr1 s)) (pr2 s)
{- The proof is similar to the previous part: we show that the fibers of f
and Σ-kap-base-map f C are equivalent. -}
fib-Σ-map-base-map-fib :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → fib f (pr1 t) → fib (Σ-map-base-map f C) t
fib-Σ-map-base-map-fib f C (pair .(f x) z) (pair x refl) =
pair (pair x z) refl
fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → fib (Σ-map-base-map f C) t → fib f (pr1 t)
fib-fib-Σ-map-base-map f C .(pair (f x) z) (pair (pair x z) refl) =
pair x refl
issec-fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) →
( (fib-Σ-map-base-map-fib f C t) ∘ (fib-fib-Σ-map-base-map f C t)) ~ id
issec-fib-fib-Σ-map-base-map f C .(pair (f x) z) (pair (pair x z) refl) =
refl
isretr-fib-fib-Σ-map-base-map :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) →
( (fib-fib-Σ-map-base-map f C t) ∘ (fib-Σ-map-base-map-fib f C t)) ~ id
isretr-fib-fib-Σ-map-base-map f C (pair .(f x) z) (pair x refl) = refl
abstract
is-equiv-fib-Σ-map-base-map-fib :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → is-equiv (fib-Σ-map-base-map-fib f C t)
is-equiv-fib-Σ-map-base-map-fib f C t =
is-equiv-has-inverse
( fib-fib-Σ-map-base-map f C t)
( issec-fib-fib-Σ-map-base-map f C t)
( isretr-fib-fib-Σ-map-base-map f C t)
equiv-fib-Σ-map-base-map-fib :
{ l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : B → UU l3) →
( t : Σ B C) → (fib f (pr1 t)) ≃ (fib (Σ-map-base-map f C) t)
equiv-fib-Σ-map-base-map-fib f C t =
pair ( fib-Σ-map-base-map-fib f C t)
( is-equiv-fib-Σ-map-base-map-fib f C t)
abstract
is-contr-map-Σ-map-base-map :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) →
is-contr-map f → is-contr-map (Σ-map-base-map f C)
is-contr-map-Σ-map-base-map C f is-contr-f (pair y z) =
is-contr-is-equiv'
( fib f y)
( fib-Σ-map-base-map-fib f C (pair y z))
( is-equiv-fib-Σ-map-base-map-fib f C (pair y z))
( is-contr-f y)
abstract
is-equiv-Σ-map-base-map :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (C : B → UU l3) (f : A → B) →
is-equiv f → is-equiv (Σ-map-base-map f C)
is-equiv-Σ-map-base-map C f is-equiv-f =
is-equiv-is-contr-map
( is-contr-map-Σ-map-base-map C f (is-contr-map-is-equiv is-equiv-f))
{- Now we combine the two parts of this section. -}
toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
Σ A C → Σ B D
toto D f g t = pair (f (pr1 t)) (g (pr1 t) (pr2 t))
{- A special case of toto is the functoriality of the cartesian product. -}
{- We construct the functoriality of cartesian products. -}
functor-prod :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) → (A × B) → (C × D)
functor-prod f g (pair a b) = pair (f a) (g b)
functor-prod-pr1 :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) → (pr1 ∘ (functor-prod f g)) ~ (f ∘ pr1)
functor-prod-pr1 f g (pair a b) = refl
functor-prod-pr2 :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) → (pr2 ∘ (functor-prod f g)) ~ (g ∘ pr2)
functor-prod-pr2 f g (pair a b) = refl
{- For our convenience we show that the functorial action of cartesian products
preserves identity maps, compositions, homotopies, and equivalences. -}
functor-prod-id :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
(functor-prod (id {A = A}) (id {A = B})) ~ id
functor-prod-id (pair a b) = refl
functor-prod-comp :
{l1 l2 l3 l4 l5 l6 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
{E : UU l5} {F : UU l6} (f : A → C) (g : B → D) (h : C → E) (k : D → F) →
functor-prod (h ∘ f) (k ∘ g) ~ ((functor-prod h k) ∘ (functor-prod f g))
functor-prod-comp f g h k (pair a b) = refl
functor-prod-htpy :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
{f f' : A → C} (H : f ~ f') {g g' : B → D} (K : g ~ g') →
functor-prod f g ~ functor-prod f' g'
functor-prod-htpy {f = f} {f'} H {g} {g'} K (pair a b) =
eq-pair-triv (pair (H a) (K b))
abstract
is-equiv-functor-prod :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → C) (g : B → D) →
is-equiv f → is-equiv g → is-equiv (functor-prod f g)
is-equiv-functor-prod f g
( pair (pair sf issec-sf) (pair rf isretr-rf))
( pair (pair sg issec-sg) (pair rg isretr-rg)) =
pair
( pair
( functor-prod sf sg)
( ( htpy-inv (functor-prod-comp sf sg f g)) ∙h
( (functor-prod-htpy issec-sf issec-sg) ∙h functor-prod-id)))
( pair
( functor-prod rf rg)
( ( htpy-inv (functor-prod-comp f g rf rg)) ∙h
( (functor-prod-htpy isretr-rf isretr-rg) ∙h functor-prod-id)))
{- triangle -}
triangle-toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
(toto D f g) ~ ((Σ-map-base-map f D) ∘ (tot g))
triangle-toto D f g t = refl
abstract
is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
is-equiv f → (is-fiberwise-equiv g) →
is-equiv (toto D f g)
is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map
D f g is-equiv-f is-fiberwise-equiv-g =
is-equiv-comp
( toto D f g)
( Σ-map-base-map f D)
( tot g)
( triangle-toto D f g)
( is-equiv-tot-is-fiberwise-equiv is-fiberwise-equiv-g)
( is-equiv-Σ-map-base-map D f is-equiv-f)
equiv-toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (e : A ≃ B) (g : (x : A) → C x ≃ D (map-equiv e x)) →
Σ A C ≃ Σ B D
equiv-toto D e g =
pair
( toto D (map-equiv e) (λ x → map-equiv (g x)))
( is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map D
( map-equiv e)
( λ x → map-equiv (g x))
( is-equiv-map-equiv e)
( λ x → is-equiv-map-equiv (g x)))
abstract
is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : A → UU l3}
(D : B → UU l4) (f : A → B) (g : (x : A) → C x → D (f x)) →
is-equiv f → is-equiv (toto D f g) → is-fiberwise-equiv g
is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map
D f g is-equiv-f is-equiv-toto-fg =
is-fiberwise-equiv-is-equiv-tot g
( is-equiv-right-factor
( toto D f g)
( Σ-map-base-map f D)
( tot g)
( triangle-toto D f g)
( is-equiv-Σ-map-base-map D f is-equiv-f)
( is-equiv-toto-fg))
--------------------------------------------------------------------------------
-- Section 8.2 The fundamental theorem
-- The general form of the fundamental theorem of identity types
abstract
fundamental-theorem-id :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
is-contr (Σ A B) → (f : (x : A) → Id a x → B x) → is-fiberwise-equiv f
fundamental-theorem-id {A = A} a b is-contr-AB f =
is-fiberwise-equiv-is-equiv-tot f
( is-equiv-is-contr (tot f) (is-contr-total-path a) is-contr-AB)
abstract
fundamental-theorem-id' :
{i j : Level} {A : UU i} {B : A → UU j}
(a : A) (b : B a) (f : (x : A) → Id a x → B x) →
is-fiberwise-equiv f → is-contr (Σ A B)
fundamental-theorem-id' {A = A} {B = B} a b f is-fiberwise-equiv-f =
is-contr-is-equiv'
( Σ A (Id a))
( tot f)
( is-equiv-tot-is-fiberwise-equiv is-fiberwise-equiv-f)
( is-contr-total-path a)
-- The canonical form of the fundamental theorem of identity types
abstract
fundamental-theorem-id-J :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
is-contr (Σ A B) → is-fiberwise-equiv (ind-Id a (λ x p → B x) b)
fundamental-theorem-id-J {i} {j} {A} {B} a b is-contr-AB =
fundamental-theorem-id a b is-contr-AB (ind-Id a (λ x p → B x) b)
-- The converse of the fundamental theorem of identity types
abstract
fundamental-theorem-id-J' :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-fiberwise-equiv (ind-Id a (λ x p → B x) b)) → is-contr (Σ A B)
fundamental-theorem-id-J' {i} {j} {A} {B} a b H =
is-contr-is-equiv'
( Σ A (Id a))
( tot (ind-Id a (λ x p → B x) b))
( is-equiv-tot-is-fiberwise-equiv H)
( is-contr-total-path a)
-- We characterize the identity type of the natural numbers.
center-total-Eq-ℕ :
(m : ℕ) → Σ ℕ (Eq-ℕ m)
center-total-Eq-ℕ m = pair m (refl-Eq-ℕ m)
map-total-Eq-ℕ :
(m : ℕ) → Σ ℕ (Eq-ℕ m) → Σ ℕ (Eq-ℕ (succ-ℕ m))
map-total-Eq-ℕ m (pair n e) = pair (succ-ℕ n) e
contraction-total-Eq-ℕ :
(m : ℕ) (x : Σ ℕ (Eq-ℕ m)) → Id (center-total-Eq-ℕ m) x
contraction-total-Eq-ℕ zero-ℕ (pair zero-ℕ star) = refl
contraction-total-Eq-ℕ (succ-ℕ m) (pair (succ-ℕ n) e) =
ap (map-total-Eq-ℕ m) (contraction-total-Eq-ℕ m (pair n e))
is-contr-total-Eq-ℕ :
(m : ℕ) → is-contr (Σ ℕ (Eq-ℕ m))
is-contr-total-Eq-ℕ m =
pair (center-total-Eq-ℕ m) (contraction-total-Eq-ℕ m)
is-equiv-Eq-ℕ-eq :
{m n : ℕ} → is-equiv (Eq-ℕ-eq {m} {n})
is-equiv-Eq-ℕ-eq {m} {n} =
fundamental-theorem-id m
( refl-Eq-ℕ m)
( is-contr-total-Eq-ℕ m)
( λ y → Eq-ℕ-eq {m} {y})
( n)
-- As an application we show that equivalences are embeddings.
is-emb :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j)
is-emb f = (x y : _) → is-equiv (ap f {x} {y})
_↪_ :
{i j : Level} → UU i → UU j → UU (i ⊔ j)
A ↪ B = Σ (A → B) is-emb
map-emb :
{i j : Level} {A : UU i} {B : UU j} → A ↪ B → A → B
map-emb f = pr1 f
is-emb-map-emb :
{ i j : Level} {A : UU i} {B : UU j} (f : A ↪ B) → is-emb (map-emb f)
is-emb-map-emb f = pr2 f
eq-emb :
{i j : Level} {A : UU i} {B : UU j} (f : A ↪ B) →
{x y : A} → Id (map-emb f x) (map-emb f y) → Id x y
eq-emb f {x} {y} = inv-is-equiv (is-emb-map-emb f x y)
abstract
is-emb-is-equiv :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) → is-equiv f → is-emb f
is-emb-is-equiv {i} {j} {A} {B} f is-equiv-f x =
fundamental-theorem-id x refl
( is-contr-equiv
( fib f (f x))
( equiv-tot (λ y → equiv-inv (f x) (f y)))
( is-contr-map-is-equiv is-equiv-f (f x)))
( λ y p → ap f p)
emb-equiv :
{i j : Level} {A : UU i} {B : UU j} → (A ≃ B) → (A ↪ B)
emb-equiv e =
pair (map-equiv e) (is-emb-is-equiv (map-equiv e) (is-equiv-map-equiv e))
emb-id :
{i : Level} {A : UU i} → (A ↪ A)
emb-id {i} {A} = emb-equiv (equiv-id A)
equiv-ap :
{i j : Level} {A : UU i} {B : UU j} (e : A ≃ B) (x y : A) →
(Id x y) ≃ (Id (map-equiv e x) (map-equiv e y))
equiv-ap e x y =
pair
( ap (map-equiv e) {x} {y})
( is-emb-is-equiv (map-equiv e) (is-equiv-map-equiv e) x y)
-- Section 7.3 Identity systems
IND-identity-system :
{i j : Level} (k : Level) {A : UU i} (B : A → UU j) (a : A) (b : B a) → UU _
IND-identity-system k {A} B a b =
( P : (x : A) (y : B x) → UU k) →
sec (λ (h : (x : A) (y : B x) → P x y) → h a b)
fam-Σ :
{i j k : Level} {A : UU i} {B : A → UU j} (C : (x : A) → B x → UU k) →
Σ A B → UU k
fam-Σ C (pair x y) = C x y
abstract
ind-identity-system :
{i j k : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) (P : (x : A) → B x → UU k) →
P a b → (x : A) (y : B x) → P x y
ind-identity-system a b is-contr-AB P p x y =
tr
( fam-Σ P)
( eq-is-contr is-contr-AB (pair a b) (pair x y))
( p)
comp-identity-system :
{i j k : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) →
(P : (x : A) → B x → UU k) (p : P a b) →
Id (ind-identity-system a b is-contr-AB P p a b) p
comp-identity-system a b is-contr-AB P p =
ap
( λ t → tr (fam-Σ P) t p)
( eq-is-contr
( is-prop-is-contr is-contr-AB (pair a b) (pair a b))
( eq-is-contr is-contr-AB (pair a b) (pair a b))
( refl))
Ind-identity-system :
{i j : Level} (k : Level) {A : UU i} {B : A → UU j} (a : A) (b : B a) →
(is-contr-AB : is-contr (Σ A B)) →
IND-identity-system k B a b
Ind-identity-system k a b is-contr-AB P =
pair
( ind-identity-system a b is-contr-AB P)
( comp-identity-system a b is-contr-AB P)
contraction-total-space-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b →
(t : Σ A B) → Id (pair a b) t
contraction-total-space-IND-identity-system a b ind (pair x y) =
pr1 (ind (λ x' y' → Id (pair a b) (pair x' y'))) refl x y
abstract
is-contr-total-space-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b → is-contr (Σ A B)
is-contr-total-space-IND-identity-system a b ind =
pair
( pair a b)
( contraction-total-space-IND-identity-system a b ind)
abstract
fundamental-theorem-id-IND-identity-system :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) (b : B a) →
IND-identity-system (i ⊔ j) B a b →
(f : (x : A) → Id a x → B x) → (x : A) → is-equiv (f x)
fundamental-theorem-id-IND-identity-system a b ind f =
fundamental-theorem-id a b (is-contr-total-space-IND-identity-system a b ind) f
--------------------------------------------------------------------------------
-- Section 7.4 Disjointness of coproducts
-- Raising universe levels
data raise (l : Level) {l1 : Level} (A : UU l1) : UU (l1 ⊔ l) where
map-raise : A → raise l A
inv-map-raise :
{l l1 : Level} {A : UU l1} → raise l A → A
inv-map-raise (map-raise x) = x
issec-inv-map-raise :
{l l1 : Level} {A : UU l1} (x : raise l A) →
Id (map-raise (inv-map-raise x)) x
issec-inv-map-raise (map-raise x) = refl
isretr-inv-map-raise :
{l l1 : Level} {A : UU l1} (x : A) →
Id (inv-map-raise {l} (map-raise x)) x
isretr-inv-map-raise x = refl
is-equiv-map-raise :
(l : Level) {l1 : Level} (A : UU l1) → is-equiv (map-raise {l} {l1} {A})
is-equiv-map-raise l A =
is-equiv-has-inverse
inv-map-raise
( issec-inv-map-raise)
( isretr-inv-map-raise {l})
equiv-raise :
(l : Level) {l1 : Level} (A : UU l1) → A ≃ raise l A
equiv-raise l A = pair map-raise (is-equiv-map-raise l A)
Raise :
(l : Level) {l1 : Level} (A : UU l1) → Σ (UU (l1 ⊔ l)) (λ X → A ≃ X)
Raise l A = pair (raise l A) (equiv-raise l A)
-- Lemmas about coproducts
left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2)
(C : coprod A B → UU l3) → Σ (coprod A B) C →
coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y)))
left-distributive-coprod-Σ-map A B C (pair (inl x) z) = inl (pair x z)
left-distributive-coprod-Σ-map A B C (pair (inr y) z) = inr (pair y z)
inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2)
(C : coprod A B → UU l3) →
coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y))) → Σ (coprod A B) C
inv-left-distributive-coprod-Σ-map A B C (inl (pair x z)) = pair (inl x) z
inv-left-distributive-coprod-Σ-map A B C (inr (pair y z)) = pair (inr y) z
issec-inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
( (left-distributive-coprod-Σ-map A B C) ∘
(inv-left-distributive-coprod-Σ-map A B C)) ~ id
issec-inv-left-distributive-coprod-Σ-map A B C (inl (pair x z)) = refl
issec-inv-left-distributive-coprod-Σ-map A B C (inr (pair y z)) = refl
isretr-inv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
( (inv-left-distributive-coprod-Σ-map A B C) ∘
(left-distributive-coprod-Σ-map A B C)) ~ id
isretr-inv-left-distributive-coprod-Σ-map A B C (pair (inl x) z) = refl
isretr-inv-left-distributive-coprod-Σ-map A B C (pair (inr y) z) = refl
abstract
is-equiv-left-distributive-coprod-Σ-map :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
is-equiv (left-distributive-coprod-Σ-map A B C)
is-equiv-left-distributive-coprod-Σ-map A B C =
is-equiv-has-inverse
( inv-left-distributive-coprod-Σ-map A B C)
( issec-inv-left-distributive-coprod-Σ-map A B C)
( isretr-inv-left-distributive-coprod-Σ-map A B C)
equiv-left-distributive-coprod-Σ :
{l1 l2 l3 : Level} (A : UU l1) (B : UU l2) (C : coprod A B → UU l3) →
Σ (coprod A B) C ≃ coprod (Σ A (λ x → C (inl x))) (Σ B (λ y → C (inr y)))
equiv-left-distributive-coprod-Σ A B C =
pair ( left-distributive-coprod-Σ-map A B C)
( is-equiv-left-distributive-coprod-Σ-map A B C)
abstract
is-equiv-map-to-empty :
{l : Level} {A : UU l} (f : A → empty) → is-equiv f
is-equiv-map-to-empty f =
is-equiv-has-inverse
ind-empty
ind-empty
( λ x → ind-empty {P = λ t → Id (ind-empty (f x)) x} (f x))
map-Σ-empty-fam :
{l : Level} (A : UU l) → Σ A (λ x → empty) → empty
map-Σ-empty-fam A (pair x ())
abstract
is-equiv-map-Σ-empty-fam :
{l : Level} (A : UU l) → is-equiv (map-Σ-empty-fam A)
is-equiv-map-Σ-empty-fam A = is-equiv-map-to-empty (map-Σ-empty-fam A)
equiv-Σ-empty-fam :
{l : Level} (A : UU l) → Σ A (λ x → empty) ≃ empty
equiv-Σ-empty-fam A =
pair (map-Σ-empty-fam A) (is-equiv-map-Σ-empty-fam A)
-- The identity types of coproducts
Eq-coprod :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
coprod A B → coprod A B → UU (l1 ⊔ l2)
Eq-coprod {l1} {l2} A B (inl x) (inl y) = raise (l1 ⊔ l2) (Id x y)
Eq-coprod {l1} {l2} A B (inl x) (inr y) = raise (l1 ⊔ l2) empty
Eq-coprod {l1} {l2} A B (inr x) (inl y) = raise (l1 ⊔ l2) empty
Eq-coprod {l1} {l2} A B (inr x) (inr y) = raise (l1 ⊔ l2) (Id x y)
reflexive-Eq-coprod :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
(t : coprod A B) → Eq-coprod A B t t
reflexive-Eq-coprod {l1} {l2} A B (inl x) = map-raise refl
reflexive-Eq-coprod {l1} {l2} A B (inr x) = map-raise refl
Eq-coprod-eq :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
(s t : coprod A B) → Id s t → Eq-coprod A B s t
Eq-coprod-eq A B s .s refl = reflexive-Eq-coprod A B s
abstract
is-contr-total-Eq-coprod-inl :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : A) →
is-contr (Σ (coprod A B) (Eq-coprod A B (inl x)))
is-contr-total-Eq-coprod-inl A B x =
is-contr-equiv
( coprod
( Σ A (λ y → Eq-coprod A B (inl x) (inl y)))
( Σ B (λ y → Eq-coprod A B (inl x) (inr y))))
( equiv-left-distributive-coprod-Σ A B (Eq-coprod A B (inl x)))
( is-contr-equiv'
( coprod
( Σ A (Id x))
( Σ B (λ y → empty)))
( equiv-functor-coprod
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( equiv-tot (λ y → equiv-raise _ empty)))
( is-contr-equiv
( coprod (Σ A (Id x)) empty)
( equiv-functor-coprod
( equiv-id (Σ A (Id x)))
( equiv-Σ-empty-fam B))
( is-contr-equiv'
( Σ A (Id x))
( right-unit-law-coprod (Σ A (Id x)))
( is-contr-total-path x))))
abstract
is-contr-total-Eq-coprod-inr :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : B) →
is-contr (Σ (coprod A B) (Eq-coprod A B (inr x)))
is-contr-total-Eq-coprod-inr A B x =
is-contr-equiv
( coprod
( Σ A (λ y → Eq-coprod A B (inr x) (inl y)))
( Σ B (λ y → Eq-coprod A B (inr x) (inr y))))
( equiv-left-distributive-coprod-Σ A B (Eq-coprod A B (inr x)))
( is-contr-equiv'
( coprod (Σ A (λ y → empty)) (Σ B (Id x)))
( equiv-functor-coprod
( equiv-tot (λ y → equiv-raise _ empty))
( equiv-tot (λ y → equiv-raise _ (Id x y))))
( is-contr-equiv
( coprod empty (Σ B (Id x)))
( equiv-functor-coprod
( equiv-Σ-empty-fam A)
( equiv-id (Σ B (Id x))))
( is-contr-equiv'
( Σ B (Id x))
( left-unit-law-coprod (Σ B (Id x)))
( is-contr-total-path x))))
abstract
is-equiv-Eq-coprod-eq-inl :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : A) →
is-fiberwise-equiv (Eq-coprod-eq A B (inl x))
is-equiv-Eq-coprod-eq-inl A B x =
fundamental-theorem-id
( inl x)
( reflexive-Eq-coprod A B (inl x))
( is-contr-total-Eq-coprod-inl A B x)
( Eq-coprod-eq A B (inl x))
abstract
is-equiv-Eq-coprod-eq-inr :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (x : B) →
is-fiberwise-equiv (Eq-coprod-eq A B (inr x))
is-equiv-Eq-coprod-eq-inr A B x =
fundamental-theorem-id
( inr x)
( reflexive-Eq-coprod A B (inr x))
( is-contr-total-Eq-coprod-inr A B x)
( Eq-coprod-eq A B (inr x))
abstract
is-equiv-Eq-coprod-eq :
{l1 l2 : Level} (A : UU l1) (B : UU l2)
(s : coprod A B) → is-fiberwise-equiv (Eq-coprod-eq A B s)
is-equiv-Eq-coprod-eq A B (inl x) = is-equiv-Eq-coprod-eq-inl A B x
is-equiv-Eq-coprod-eq A B (inr x) = is-equiv-Eq-coprod-eq-inr A B x
map-compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → Id (inl {B = B} x) (inl {B = B} x') → Id x x'
map-compute-eq-coprod-inl-inl x x' =
( inv-is-equiv (is-equiv-map-raise _ (Id x x'))) ∘
( Eq-coprod-eq _ _ (inl x) (inl x'))
abstract
is-equiv-map-compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → is-equiv (map-compute-eq-coprod-inl-inl {B = B} x x')
is-equiv-map-compute-eq-coprod-inl-inl x x' =
is-equiv-comp
( map-compute-eq-coprod-inl-inl x x')
( inv-is-equiv (is-equiv-map-raise _ (Id x x')))
( Eq-coprod-eq _ _ (inl x) (inl x'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inl x) (inl x'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ (Id x x')))
compute-eq-coprod-inl-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x x' : A) → (Id (inl {B = B} x) (inl x')) ≃ (Id x x')
compute-eq-coprod-inl-inl x x' =
pair
( map-compute-eq-coprod-inl-inl x x')
( is-equiv-map-compute-eq-coprod-inl-inl x x')
map-compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → Id (inl x) (inr y') → empty
map-compute-eq-coprod-inl-inr x y' =
( inv-is-equiv (is-equiv-map-raise _ empty)) ∘
( Eq-coprod-eq _ _ (inl x) (inr y'))
abstract
is-equiv-map-compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → is-equiv (map-compute-eq-coprod-inl-inr x y')
is-equiv-map-compute-eq-coprod-inl-inr x y' =
is-equiv-comp
( map-compute-eq-coprod-inl-inr x y')
( inv-is-equiv (is-equiv-map-raise _ empty))
( Eq-coprod-eq _ _ (inl x) (inr y'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inl x) (inr y'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ empty))
compute-eq-coprod-inl-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(x : A) (y' : B) → (Id (inl x) (inr y')) ≃ empty
compute-eq-coprod-inl-inr x y' =
pair
( map-compute-eq-coprod-inl-inr x y')
( is-equiv-map-compute-eq-coprod-inl-inr x y')
map-compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → (Id (inr {A = A} y) (inl x')) → empty
map-compute-eq-coprod-inr-inl y x' =
( inv-is-equiv (is-equiv-map-raise _ empty)) ∘
( Eq-coprod-eq _ _ (inr y) (inl x'))
abstract
is-equiv-map-compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → is-equiv (map-compute-eq-coprod-inr-inl y x')
is-equiv-map-compute-eq-coprod-inr-inl y x' =
is-equiv-comp
( map-compute-eq-coprod-inr-inl y x')
( inv-is-equiv (is-equiv-map-raise _ empty))
( Eq-coprod-eq _ _ (inr y) (inl x'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inr y) (inl x'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ empty))
compute-eq-coprod-inr-inl :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y : B) (x' : A) → (Id (inr y) (inl x')) ≃ empty
compute-eq-coprod-inr-inl y x' =
pair
( map-compute-eq-coprod-inr-inl y x')
( is-equiv-map-compute-eq-coprod-inr-inl y x')
map-compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → (Id (inr {A = A} y) (inr y')) → Id y y'
map-compute-eq-coprod-inr-inr y y' =
( inv-is-equiv (is-equiv-map-raise _ (Id y y'))) ∘
( Eq-coprod-eq _ _ (inr y) (inr y'))
abstract
is-equiv-map-compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → is-equiv (map-compute-eq-coprod-inr-inr {A = A} y y')
is-equiv-map-compute-eq-coprod-inr-inr y y' =
is-equiv-comp
( map-compute-eq-coprod-inr-inr y y')
( inv-is-equiv (is-equiv-map-raise _ (Id y y')))
( Eq-coprod-eq _ _ (inr y) (inr y'))
( refl-htpy)
( is-equiv-Eq-coprod-eq _ _ (inr y) (inr y'))
( is-equiv-inv-is-equiv (is-equiv-map-raise _ (Id y y')))
compute-eq-coprod-inr-inr :
{l1 l2 : Level} {A : UU l1} {B : UU l2}
(y y' : B) → (Id (inr {A = A} y) (inr y')) ≃ (Id y y')
compute-eq-coprod-inr-inr y y' =
pair
( map-compute-eq-coprod-inr-inr y y')
( is-equiv-map-compute-eq-coprod-inr-inr y y')
--------------------------------------------------------------------------------
-- Exercises
-- Exercise 7.1
abstract
is-emb-empty :
{i : Level} (A : UU i) → is-emb (ind-empty {P = λ x → A})
is-emb-empty A = ind-empty
-- Exercise 7.2
eq-transpose-equiv :
{i j : Level} {A : UU i} {B : UU j} (e : A ≃ B) (x : A) (y : B) →
(Id (map-equiv e x) y) ≃ (Id x (inv-map-equiv e y))
eq-transpose-equiv e x y =
( inv-equiv (equiv-ap e x (inv-map-equiv e y))) ∘e
( equiv-concat'
( map-equiv e x)
( inv (issec-inv-map-equiv e y)))
map-eq-transpose-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) {x : A} {y : B} →
Id (map-equiv e x) y → Id x (inv-map-equiv e y)
map-eq-transpose-equiv e {x} {y} = map-equiv (eq-transpose-equiv e x y)
triangle-eq-transpose-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) {x : A} {y : B}
(p : Id (map-equiv e x) y) →
Id ( ( ap (map-equiv e) (map-eq-transpose-equiv e p)) ∙
( issec-inv-map-equiv e y))
( p)
triangle-eq-transpose-equiv e {x} {y} p =
( ap ( concat' (map-equiv e x) (issec-inv-map-equiv e y))
( issec-inv-map-equiv
( equiv-ap e x (inv-map-equiv e y))
( p ∙ inv (issec-inv-map-equiv e y)))) ∙
( ( assoc p (inv (issec-inv-map-equiv e y)) (issec-inv-map-equiv e y)) ∙
( ( ap (concat p y) (left-inv (issec-inv-map-equiv e y))) ∙ right-unit))
map-eq-transpose-equiv' :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) {a : A} {b : B} →
Id b (map-equiv e a) → Id (inv-map-equiv e b) a
map-eq-transpose-equiv' e p = inv (map-eq-transpose-equiv e (inv p))
triangle-eq-transpose-equiv' :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) {x : A} {y : B} →
(p : Id y (map-equiv e x)) →
Id ( (issec-inv-map-equiv e y) ∙ p)
( ap (map-equiv e) (map-eq-transpose-equiv' e p))
triangle-eq-transpose-equiv' e {x} {y} p =
inv-map-equiv
( equiv-ap
( equiv-inv (map-equiv e (inv-map-equiv e y)) (map-equiv e x))
( (issec-inv-map-equiv e y) ∙ p)
( ap (map-equiv e) (map-eq-transpose-equiv' e p)))
( ( distributive-inv-concat (issec-inv-map-equiv e y) p) ∙
( ( inv
( con-inv
( ap (map-equiv e) (inv (map-eq-transpose-equiv' e p)))
( issec-inv-map-equiv e y)
( inv p)
( ( ap ( concat' (map-equiv e x) (issec-inv-map-equiv e y))
( ap ( ap (map-equiv e))
( inv-inv
( inv-map-equiv
( equiv-ap e x (inv-map-equiv e y))
( ( inv p) ∙
( inv (issec-inv-map-equiv e y))))))) ∙
( triangle-eq-transpose-equiv e (inv p))))) ∙
( ap-inv (map-equiv e) (map-eq-transpose-equiv' e p))))
-- Exercise 7.3
abstract
is-equiv-top-is-equiv-left-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
is-equiv i → is-equiv f → is-equiv g → is-equiv h
is-equiv-top-is-equiv-left-square f g h i H is-equiv-i is-equiv-f is-equiv-g =
is-equiv-right-factor (i ∘ f) g h H is-equiv-g
( is-equiv-comp' i f is-equiv-f is-equiv-i)
abstract
is-emb-htpy :
{i j : Level} {A : UU i} {B : UU j} (f g : A → B) → (f ~ g) →
is-emb g → is-emb f
is-emb-htpy f g H is-emb-g x y =
is-equiv-top-is-equiv-left-square
( ap g)
( concat' (f x) (H y))
( ap f)
( concat (H x) (g y))
( htpy-nat H)
( is-equiv-concat (H x) (g y))
( is-emb-g x y)
( is-equiv-concat' (f x) (H y))
abstract
is-emb-htpy' :
{i j : Level} {A : UU i} {B : UU j} (f g : A → B) → (f ~ g) →
is-emb f → is-emb g
is-emb-htpy' f g H is-emb-f =
is-emb-htpy g f (htpy-inv H) is-emb-f
-- Exercise 7.4
abstract
is-emb-comp :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) → is-emb g →
is-emb h → is-emb f
is-emb-comp f g h H is-emb-g is-emb-h =
is-emb-htpy f (g ∘ h) H
( λ x y → is-equiv-comp (ap (g ∘ h)) (ap g) (ap h) (ap-comp g h)
( is-emb-h x y)
( is-emb-g (h x) (h y)))
abstract
is-emb-comp' :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(g : B → X) (h : A → B) → is-emb g → is-emb h → is-emb (g ∘ h)
is-emb-comp' g h = is-emb-comp (g ∘ h) g h refl-htpy
abstract
is-emb-right-factor :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) → is-emb g →
is-emb f → is-emb h
is-emb-right-factor f g h H is-emb-g is-emb-f x y =
is-equiv-right-factor
( ap (g ∘ h))
( ap g)
( ap h)
( ap-comp g h)
( is-emb-g (h x) (h y))
( is-emb-htpy (g ∘ h) f (htpy-inv H) is-emb-f x y)
abstract
is-emb-triangle-is-equiv :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (e : A → B) (H : f ~ (g ∘ e)) →
is-equiv e → is-emb g → is-emb f
is-emb-triangle-is-equiv f g e H is-equiv-e is-emb-g =
is-emb-comp f g e H is-emb-g (is-emb-is-equiv e is-equiv-e)
abstract
is-emb-triangle-is-equiv' :
{i j k : Level} {A : UU i} {B : UU j} {X : UU k}
(f : A → X) (g : B → X) (e : A → B) (H : f ~ (g ∘ e)) →
is-equiv e → is-emb f → is-emb g
is-emb-triangle-is-equiv' f g e H is-equiv-e is-emb-f =
is-emb-triangle-is-equiv g f
( inv-is-equiv is-equiv-e)
( triangle-section f g e H
( pair
( inv-is-equiv is-equiv-e)
( issec-inv-is-equiv is-equiv-e)))
( is-equiv-inv-is-equiv is-equiv-e)
( is-emb-f)
-- Exercise 7.5
abstract
is-emb-inl :
{i j : Level} (A : UU i) (B : UU j) → is-emb (inl {A = A} {B = B})
is-emb-inl A B x =
fundamental-theorem-id x refl
( is-contr-is-equiv
( Σ A (λ y → Eq-coprod A B (inl x) (inl y)))
( tot (λ y → Eq-coprod-eq A B (inl x) (inl y)))
( is-equiv-tot-is-fiberwise-equiv
( λ y → is-equiv-Eq-coprod-eq A B (inl x) (inl y)))
( is-contr-equiv'
( Σ A (Id x))
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( is-contr-total-path x)))
( λ y → ap inl)
abstract
is-emb-inr :
{i j : Level} (A : UU i) (B : UU j) → is-emb (inr {A = A} {B = B})
is-emb-inr A B x =
fundamental-theorem-id x refl
( is-contr-is-equiv
( Σ B (λ y → Eq-coprod A B (inr x) (inr y)))
( tot (λ y → Eq-coprod-eq A B (inr x) (inr y)))
( is-equiv-tot-is-fiberwise-equiv
( λ y → is-equiv-Eq-coprod-eq A B (inr x) (inr y)))
( is-contr-equiv'
( Σ B (Id x))
( equiv-tot (λ y → equiv-raise _ (Id x y)))
( is-contr-total-path x)))
( λ y → ap inr)
-- Exercise 7.6
-- Exercise 7.7
tot-htpy :
{i j k : Level} {A : UU i} {B : A → UU j} {C : A → UU k}
{f g : (x : A) → B x → C x} → (H : (x : A) → f x ~ g x) → tot f ~ tot g
tot-htpy H (pair x y) = eq-pair refl (H x y)
tot-id :
{i j : Level} {A : UU i} (B : A → UU j) →
(tot (λ x (y : B x) → y)) ~ id
tot-id B (pair x y) = refl
tot-comp :
{i j j' j'' : Level}
{A : UU i} {B : A → UU j} {B' : A → UU j'} {B'' : A → UU j''}
(f : (x : A) → B x → B' x) (g : (x : A) → B' x → B'' x) →
tot (λ x → (g x) ∘ (f x)) ~ ((tot g) ∘ (tot f))
tot-comp f g (pair x y) = refl
-- Exercise 7.8
abstract
fundamental-theorem-id-retr :
{i j : Level} {A : UU i} {B : A → UU j} (a : A) →
(i : (x : A) → B x → Id a x) → (R : (x : A) → retr (i x)) →
is-fiberwise-equiv i
fundamental-theorem-id-retr {_} {_} {A} {B} a i R =
is-fiberwise-equiv-is-equiv-tot i
( is-equiv-is-contr (tot i)
( is-contr-retract-of (Σ _ (λ y → Id a y))
( pair (tot i)
( pair (tot λ x → pr1 (R x))
( ( htpy-inv (tot-comp i (λ x → pr1 (R x)))) ∙h
( ( tot-htpy λ x → pr2 (R x)) ∙h (tot-id B)))))
( is-contr-total-path a))
( is-contr-total-path a))
abstract
is-equiv-sec-is-equiv :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (sec-f : sec f) →
is-equiv (pr1 sec-f) → is-equiv f
is-equiv-sec-is-equiv {A = A} {B = B} f (pair g issec-g) is-equiv-sec-f =
let h : A → B
h = inv-is-equiv is-equiv-sec-f
in
is-equiv-htpy h
( ( htpy-left-whisk f (htpy-inv (issec-inv-is-equiv is-equiv-sec-f))) ∙h
( htpy-right-whisk issec-g h))
( is-equiv-inv-is-equiv is-equiv-sec-f)
abstract
fundamental-theorem-id-sec :
{i j : Level} {A : UU i} {B : A → UU j} (a : A)
(f : (x : A) → Id a x → B x) → ((x : A) → sec (f x)) →
is-fiberwise-equiv f
fundamental-theorem-id-sec {A = A} {B = B} a f sec-f x =
let i : (x : A) → B x → Id a x
i = λ x → pr1 (sec-f x)
retr-i : (x : A) → retr (i x)
retr-i = λ x → pair (f x) (pr2 (sec-f x))
is-fiberwise-equiv-i : is-fiberwise-equiv i
is-fiberwise-equiv-i = fundamental-theorem-id-retr a i retr-i
in is-equiv-sec-is-equiv (f x) (sec-f x) (is-fiberwise-equiv-i x)
-- Exercise 7.9
abstract
is-emb-sec-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) →
((x y : A) → sec (ap f {x = x} {y = y})) → is-emb f
is-emb-sec-ap f sec-ap-f x =
fundamental-theorem-id-sec x (λ y → ap f {y = y}) (sec-ap-f x)
-- Exercise 7.10
coherence-is-half-adjoint-equivalence :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) (g : B → A)
(G : (f ∘ g) ~ id) (H : (g ∘ f) ~ id) → UU (l1 ⊔ l2)
coherence-is-half-adjoint-equivalence f g G H =
( htpy-right-whisk G f) ~ (htpy-left-whisk f H)
is-half-adjoint-equivalence :
{l1 l2 : Level} {A : UU l1} {B : UU l2} → (A → B) → UU (l1 ⊔ l2)
is-half-adjoint-equivalence {A = A} {B = B} f =
Σ (B → A)
( λ g → Σ ((f ∘ g) ~ id)
( λ G → Σ ((g ∘ f) ~ id) (coherence-is-half-adjoint-equivalence f g G)))
is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} → (A → B) → UU (l1 ⊔ l2)
is-path-split {A = A} {B = B} f =
sec f × ((x y : A) → sec (ap f {x = x} {y = y}))
abstract
is-path-split-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-equiv f → is-path-split f
is-path-split-is-equiv f is-equiv-f =
pair (pr1 is-equiv-f) (λ x y → pr1 (is-emb-is-equiv f is-equiv-f x y))
abstract
is-half-adjoint-equivalence-is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-path-split f → is-half-adjoint-equivalence f
is-half-adjoint-equivalence-is-path-split {A = A} {B = B} f
( pair (pair g issec-g) sec-ap-f) =
let φ : ((x : A) → fib (ap f) (issec-g (f x))) →
Σ ((g ∘ f) ~ id)
( λ H → (htpy-right-whisk issec-g f) ~ (htpy-left-whisk f H))
φ = ( tot (λ H' → htpy-inv)) ∘
( λ s → pair (λ x → pr1 (s x)) (λ x → pr2 (s x)))
in
pair g
( pair issec-g
( φ (λ x → pair
( pr1 (sec-ap-f (g (f x)) x) (issec-g (f x)))
( pr2 (sec-ap-f (g (f x)) x) (issec-g (f x))))))
abstract
is-equiv-is-half-adjoint-equivalence :
{ l1 l2 : Level} {A : UU l1} {B : UU l2}
(f : A → B) → is-half-adjoint-equivalence f → is-equiv f
is-equiv-is-half-adjoint-equivalence f (pair g (pair G (pair H K))) =
is-equiv-has-inverse g G H
abstract
is-equiv-is-path-split :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-path-split f → is-equiv f
is-equiv-is-path-split f =
( is-equiv-is-half-adjoint-equivalence f) ∘
( is-half-adjoint-equivalence-is-path-split f)
abstract
is-half-adjoint-equivalence-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-equiv f → is-half-adjoint-equivalence f
is-half-adjoint-equivalence-is-equiv f =
( is-half-adjoint-equivalence-is-path-split f) ∘ (is-path-split-is-equiv f)
-- Exercise 7.11
abstract
is-equiv-top-is-equiv-bottom-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv f) → (is-equiv g) → (is-equiv i) → (is-equiv h)
is-equiv-top-is-equiv-bottom-square
f g h i H is-equiv-f is-equiv-g is-equiv-i =
is-equiv-right-factor (i ∘ f) g h H is-equiv-g
( is-equiv-comp' i f is-equiv-f is-equiv-i)
abstract
is-equiv-bottom-is-equiv-top-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv f) → (is-equiv g) → (is-equiv h) → (is-equiv i)
is-equiv-bottom-is-equiv-top-square
f g h i H is-equiv-f is-equiv-g is-equiv-h =
is-equiv-left-factor' i f
( is-equiv-comp (i ∘ f) g h H is-equiv-h is-equiv-g) is-equiv-f
abstract
is-equiv-left-is-equiv-right-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv h) → (is-equiv i) → (is-equiv g) → (is-equiv f)
is-equiv-left-is-equiv-right-square
f g h i H is-equiv-h is-equiv-i is-equiv-g =
is-equiv-right-factor' i f is-equiv-i
( is-equiv-comp (i ∘ f) g h H is-equiv-h is-equiv-g)
abstract
is-equiv-right-is-equiv-left-square :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : C → D) (h : A → C) (i : B → D) (H : (i ∘ f) ~ (g ∘ h)) →
(is-equiv h) → (is-equiv i) → (is-equiv f) → (is-equiv g)
is-equiv-right-is-equiv-left-square
f g h i H is-equiv-h is-equiv-i is-equiv-f =
is-equiv-left-factor (i ∘ f) g h H
( is-equiv-comp' i f is-equiv-f is-equiv-i)
( is-equiv-h)
fib-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h))
(x : X) → (fib f x) → (fib g x)
fib-triangle f g h H .(f a) (pair a refl) = pair (h a) (inv (H a))
square-tot-fib-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(h ∘ (Σ-fib-to-domain f)) ~
((Σ-fib-to-domain g) ∘ (tot (fib-triangle f g h H)))
square-tot-fib-triangle f g h H (pair .(f a) (pair a refl)) = refl
abstract
is-fiberwise-equiv-is-equiv-triangle :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(E : is-equiv h) → is-fiberwise-equiv (fib-triangle f g h H)
is-fiberwise-equiv-is-equiv-triangle f g h H E =
is-fiberwise-equiv-is-equiv-tot
( fib-triangle f g h H)
( is-equiv-top-is-equiv-bottom-square
( Σ-fib-to-domain f)
( Σ-fib-to-domain g)
( tot (fib-triangle f g h H))
( h)
( square-tot-fib-triangle f g h H)
( is-equiv-Σ-fib-to-domain f)
( is-equiv-Σ-fib-to-domain g)
( E))
abstract
is-equiv-triangle-is-fiberwise-equiv :
{i j k : Level} {X : UU i} {A : UU j} {B : UU k}
(f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
(E : is-fiberwise-equiv (fib-triangle f g h H)) → is-equiv h
is-equiv-triangle-is-fiberwise-equiv f g h H E =
is-equiv-bottom-is-equiv-top-square
( Σ-fib-to-domain f)
( Σ-fib-to-domain g)
( tot (fib-triangle f g h H))
( h)
( square-tot-fib-triangle f g h H)
( is-equiv-Σ-fib-to-domain f)
( is-equiv-Σ-fib-to-domain g)
( is-equiv-tot-is-fiberwise-equiv E)
-- Extra material
{- In order to show that the total space of htpy-cone is contractible, we give
a general construction that helps us characterize the identity type of
a structure. This construction is called
is-contr-total-Eq-structure.
We first give some definitions that help us with the construction of
is-contr-total-Eq-structure. -}
swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
Σ (Σ A B) (λ t → Σ (C (pr1 t)) (D (pr1 t) (pr2 t))) →
Σ (Σ A C) (λ t → Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t)))
swap-total-Eq-structure B C D (pair (pair a b) (pair c d)) =
pair (pair a c) (pair b d)
htpy-swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
( ( swap-total-Eq-structure B C D) ∘
( swap-total-Eq-structure C B (λ x z y → D x y z))) ~ id
htpy-swap-total-Eq-structure B C D (pair (pair a b) (pair c d)) = refl
abstract
is-equiv-swap-total-Eq-structure :
{l1 l2 l3 l4 : Level} {A : UU l1} (B : A → UU l2) (C : A → UU l3)
(D : (x : A) → B x → C x → UU l4) →
is-equiv (swap-total-Eq-structure B C D)
is-equiv-swap-total-Eq-structure B C D =
is-equiv-has-inverse
( swap-total-Eq-structure C B (λ x z y → D x y z))
( htpy-swap-total-Eq-structure B C D)
( htpy-swap-total-Eq-structure C B (λ x z y → D x y z))
abstract
is-contr-Σ :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-contr A → ((x : A) → is-contr (B x)) → is-contr (Σ A B)
is-contr-Σ {A = A} {B = B} is-contr-A is-contr-B =
is-contr-equiv'
( B (center is-contr-A))
( left-unit-law-Σ B is-contr-A)
( is-contr-B (center is-contr-A))
abstract
is-contr-Σ' :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-contr A → (a : A) → is-contr (B a) → is-contr (Σ A B)
is-contr-Σ' {A = A} {B} is-contr-A a is-contr-B =
is-contr-is-equiv'
( B a)
( left-unit-law-Σ-map-gen B is-contr-A a)
( is-equiv-left-unit-law-Σ-map-gen B is-contr-A a)
( is-contr-B)
abstract
is-contr-total-Eq-structure :
{ l1 l2 l3 l4 : Level} { A : UU l1} {B : A → UU l2} {C : A → UU l3}
( D : (x : A) → B x → C x → UU l4) →
( is-contr-AC : is-contr (Σ A C)) →
( t : Σ A C) →
is-contr (Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t))) →
is-contr (Σ (Σ A B) (λ t → Σ (C (pr1 t)) (D (pr1 t) (pr2 t))))
is-contr-total-Eq-structure
{A = A} {B = B} {C = C} D is-contr-AC t is-contr-BD =
is-contr-is-equiv
( Σ (Σ A C) (λ t → Σ (B (pr1 t)) (λ y → D (pr1 t) y (pr2 t))))
( swap-total-Eq-structure B C D)
( is-equiv-swap-total-Eq-structure B C D)
( is-contr-Σ' is-contr-AC t is-contr-BD)
-- Characterizing the identity type of a fiber as the fiber of the action on
-- paths
fib-ap-eq-fib-fiberwise :
{i j : Level} {A : UU i} {B : UU j}
(f : A → B) {b : B} (s t : fib f b) (p : Id (pr1 s) (pr1 t)) →
(Id (tr (λ (a : A) → Id (f a) b) p (pr2 s)) (pr2 t)) →
(Id (ap f p) ((pr2 s) ∙ (inv (pr2 t))))
fib-ap-eq-fib-fiberwise f (pair .x' p) (pair x' refl) refl =
inv ∘ (concat right-unit refl)
abstract
is-fiberwise-equiv-fib-ap-eq-fib-fiberwise :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B} (s t : fib f b) →
is-fiberwise-equiv (fib-ap-eq-fib-fiberwise f s t)
is-fiberwise-equiv-fib-ap-eq-fib-fiberwise
f (pair x y) (pair .x refl) refl =
is-equiv-comp
( fib-ap-eq-fib-fiberwise f (pair x y) (pair x refl) refl)
( inv)
( concat right-unit refl)
( refl-htpy)
( is-equiv-concat right-unit refl)
( is-equiv-inv (y ∙ refl) refl)
fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B}
(s t : fib f b) → Id s t →
fib (ap f {x = pr1 s} {y = pr1 t}) ((pr2 s) ∙ (inv (pr2 t)))
fib-ap-eq-fib f s .s refl = pair refl (inv (right-inv (pr2 s)))
triangle-fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B)
{b : B} (s t : fib f b) →
(fib-ap-eq-fib f s t) ~ ((tot (fib-ap-eq-fib-fiberwise f s t)) ∘ (pair-eq {s = s} {t}))
triangle-fib-ap-eq-fib f (pair x refl) .(pair x refl) refl = refl
abstract
is-equiv-fib-ap-eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) {b : B}
(s t : fib f b) → is-equiv (fib-ap-eq-fib f s t)
is-equiv-fib-ap-eq-fib f s t =
is-equiv-comp
( fib-ap-eq-fib f s t)
( tot (fib-ap-eq-fib-fiberwise f s t))
( pair-eq {s = s} {t})
( triangle-fib-ap-eq-fib f s t)
( is-equiv-pair-eq s t)
( is-equiv-tot-is-fiberwise-equiv
( is-fiberwise-equiv-fib-ap-eq-fib-fiberwise f s t))
eq-fib-fib-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (x y : A)
(q : Id (f x) (f y)) →
Id (pair x q) (pair y (refl {x = f y})) → fib (ap f {x = x} {y = y}) q
eq-fib-fib-ap f x y q = (tr (fib (ap f)) right-unit) ∘ (fib-ap-eq-fib f (pair x q) (pair y refl))
abstract
is-equiv-eq-fib-fib-ap :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (x y : A)
(q : Id (f x) (f y)) → is-equiv (eq-fib-fib-ap f x y q)
is-equiv-eq-fib-fib-ap f x y q =
is-equiv-comp
( eq-fib-fib-ap f x y q)
( tr (fib (ap f)) right-unit)
( fib-ap-eq-fib f (pair x q) (pair y refl))
( refl-htpy)
( is-equiv-fib-ap-eq-fib f (pair x q) (pair y refl))
( is-equiv-tr (fib (ap f)) right-unit)
-- Comparing fib and fib'
fib'-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
fib f y → fib' f y
fib'-fib f y t = tot (λ x → inv) t
abstract
is-equiv-fib'-fib :
{i j : Level} {A : UU i} {B : UU j}
(f : A → B) → is-fiberwise-equiv (fib'-fib f)
is-equiv-fib'-fib f y =
is-equiv-tot-is-fiberwise-equiv (λ x → is-equiv-inv (f x) y)
{-
-- Equivalent finite sets have the same cardinality
skip-Fin :
{n : ℕ} → Fin (succ-ℕ n) → Fin n → Fin (succ-ℕ n)
skip-Fin {succ-ℕ n} (inl x) (inl y) = inl (skip-Fin x y)
skip-Fin {succ-ℕ n} (inl x) (inr y) = inr star
skip-Fin {succ-ℕ n} (inr x) y = inl y
swap-top-two-Fin :
{n : ℕ} → Fin (succ-ℕ (succ-ℕ n)) → Fin (succ-ℕ (succ-ℕ n))
swap-top-two-Fin (inl (inl x)) = inl (inl x)
swap-top-two-Fin (inl (inr star)) = inr star
swap-top-two-Fin (inr star) = inl (inr star)
idempotent-top-two-Fin :
{n : ℕ} (x : Fin (succ-ℕ (succ-ℕ n))) →
Id (swap-top-two-Fin (swap-top-two-Fin x)) x
idempotent-top-two-Fin (inl (inl x)) = refl
idempotent-top-two-Fin (inl (inr star)) = refl
idempotent-top-two-Fin (inr star) = refl
is-equiv-swap-top-two-Fin :
{n : ℕ} → is-equiv (swap-top-two-Fin {n})
is-equiv-swap-top-two-Fin =
is-equiv-has-inverse
swap-top-two-Fin
idempotent-top-two-Fin
idempotent-top-two-Fin
{-
swap-top-Fin :
{n : ℕ} → Fin (succ-ℕ n) → Fin (succ-ℕ n) → Fin (succ-ℕ n)
swap-top-Fin {zero-ℕ} x y = x
swap-top-Fin {succ-ℕ n} (inl (inl x)) (inl (inl y)) = swap-top-two-Fin (inl (swap-top-Fin (inl x) (inl y)))
swap-top-Fin {succ-ℕ n} (inl (inr x)) (inl (inl y)) = inl (inl y)
swap-top-Fin {succ-ℕ n} (inl (inl x)) (inl (inr star)) = inl (inr star)
swap-top-Fin {succ-ℕ n} (inl (inr x)) (inl (inr star)) = inr star
swap-top-Fin {succ-ℕ n} (inl x) (inr y) = inl x
swap-top-Fin {succ-ℕ n} (inr x) y = y
idempotent-swap-top-Fin :
{n : ℕ} (x : Fin (succ-ℕ n)) →
((swap-top-Fin x) ∘ (swap-top-Fin x)) ~ id
idempotent-swap-top-Fin {zero-ℕ} (inr star) (inr star) = refl
idempotent-swap-top-Fin {succ-ℕ n} (inl x) (inl y) = {!!}
idempotent-swap-top-Fin {succ-ℕ n} (inl (inl x)) (inr star) = {!!}
idempotent-swap-top-Fin {succ-ℕ n} (inl (inr star)) (inr star) = refl
idempotent-swap-top-Fin {succ-ℕ n} (inr x) (inl y) = refl
idempotent-swap-top-Fin {succ-ℕ n} (inr x) (inr y) = refl
eq-ℕ-equiv-Fin :
{m n : ℕ} → (Fin m ≃ Fin n) → Id m n
eq-ℕ-equiv-Fin {zero-ℕ} {zero-ℕ} e = refl
eq-ℕ-equiv-Fin {zero-ℕ} {succ-ℕ n} e = ind-empty (inv-map-equiv e (inr star))
eq-ℕ-equiv-Fin {succ-ℕ m} {zero-ℕ} e = ind-empty (map-equiv e (inr star))
eq-ℕ-equiv-Fin {succ-ℕ m} {succ-ℕ n} e = {!!}
-}
-}
| 35.840599
| 107
| 0.52984
|
21a2c05fb810308dfb216bd0d18956daa3434ef5
| 2,980
|
agda
|
Agda
|
Cubical/Categories/Monoidal/Base.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Monoidal/Base.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Monoidal/Base.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
-- Monoidal categories
{-# OPTIONS --safe #-}
module Cubical.Categories.Monoidal.Base where
open import Cubical.Categories.Category.Base
open import Cubical.Categories.Constructions.BinProduct
open import Cubical.Categories.Functor.Base
open import Cubical.Categories.Functor.BinProduct
open import Cubical.Categories.Morphism
open import Cubical.Categories.NaturalTransformation.Base
open import Cubical.Foundations.Prelude
module _ {ℓ ℓ' : Level} (C : Category ℓ ℓ') where
open Category C
private
record TensorStr : Type (ℓ-max ℓ ℓ') where
field
─⊗─ : Functor (C × C) C
unit : ob
open Functor
-- Useful tensor product notation
_⊗_ : ob → ob → ob
x ⊗ y = ─⊗─ .F-ob (x , y)
_⊗ₕ_ : ∀ {x y z w} → Hom[ x , y ] → Hom[ z , w ]
→ Hom[ x ⊗ z , y ⊗ w ]
f ⊗ₕ g = ─⊗─ .F-hom (f , g)
record StrictMonStr : Type (ℓ-max ℓ ℓ') where
field
tenstr : TensorStr
open TensorStr tenstr public
field
-- Axioms - strict
assoc : ∀ x y z → x ⊗ (y ⊗ z) ≡ (x ⊗ y) ⊗ z
idl : ∀ x → unit ⊗ x ≡ x
idr : ∀ x → x ⊗ unit ≡ x
record MonoidalStr : Type (ℓ-max ℓ ℓ') where
field
tenstr : TensorStr
open TensorStr tenstr public
private
-- Private names to make the axioms below look nice
x⊗[y⊗z] : Functor (C × C × C) C
x⊗[y⊗z] = ─⊗─ ∘F (𝟙⟨ C ⟩ ×F ─⊗─)
[x⊗y]⊗z : Functor (C × C × C) C
[x⊗y]⊗z = ─⊗─ ∘F (─⊗─ ×F 𝟙⟨ C ⟩) ∘F (×C-assoc C C C)
x = 𝟙⟨ C ⟩
1⊗x = ─⊗─ ∘F (rinj C C unit)
x⊗1 = ─⊗─ ∘F (linj C C unit)
field
-- "Axioms" - up to natural isomorphism
α : x⊗[y⊗z] ≅ᶜ [x⊗y]⊗z
η : 1⊗x ≅ᶜ x
ρ : x⊗1 ≅ᶜ x
open NatIso
-- More nice notations
α⟨_,_,_⟩ : (x y z : ob) → Hom[ x ⊗ (y ⊗ z) , (x ⊗ y) ⊗ z ]
α⟨ x , y , z ⟩ = α .trans ⟦ ( x , y , z ) ⟧
η⟨_⟩ : (x : ob) → Hom[ unit ⊗ x , x ]
η⟨ x ⟩ = η .trans ⟦ x ⟧
ρ⟨_⟩ : (x : ob) → Hom[ x ⊗ unit , x ]
ρ⟨ x ⟩ = ρ .trans ⟦ x ⟧
field
-- Coherence conditions
pentagon : ∀ w x y z →
id ⊗ₕ α⟨ x , y , z ⟩ ⋆ α⟨ w , x ⊗ y , z ⟩ ⋆ α⟨ w , x , y ⟩ ⊗ₕ id
≡ α⟨ w , x , y ⊗ z ⟩ ⋆ α⟨ w ⊗ x , y , z ⟩
triangle : ∀ x y →
α⟨ x , unit , y ⟩ ⋆ ρ⟨ x ⟩ ⊗ₕ id ≡ id ⊗ₕ η⟨ y ⟩
open isIso
-- Inverses of α, η, ρ for convenience
α⁻¹⟨_,_,_⟩ : (x y z : ob) → Hom[ (x ⊗ y) ⊗ z , x ⊗ (y ⊗ z) ]
α⁻¹⟨ x , y , z ⟩ = α .nIso (x , y , z) .inv
η⁻¹⟨_⟩ : (x : ob) → Hom[ x , unit ⊗ x ]
η⁻¹⟨ x ⟩ = η .nIso (x) .inv
ρ⁻¹⟨_⟩ : (x : ob) → Hom[ x , x ⊗ unit ]
ρ⁻¹⟨ x ⟩ = ρ .nIso (x) .inv
record StrictMonCategory ℓ ℓ' : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
C : Category ℓ ℓ'
sms : StrictMonStr C
open Category C public
open StrictMonStr sms public
record MonoidalCategory ℓ ℓ' : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
C : Category ℓ ℓ'
monstr : MonoidalStr C
open Category C public
open MonoidalStr monstr public
| 24.42623
| 76
| 0.502685
|
0d792a4841f632f5177e3f3be94feb5f3faf1db8
| 441
|
agda
|
Agda
|
src/Morphism/Structures.agda
|
Akshobhya1234/agda-NonAssociativeAlgebra
|
443e831e536b756acbd1afd0d6bae7bc0d288048
|
[
"MIT"
] | 2
|
2021-08-15T06:16:13.000Z
|
2021-08-17T09:14:03.000Z
|
src/Morphism/Structures.agda
|
Akshobhya1234/agda-NonAssociativeAlgebra
|
443e831e536b756acbd1afd0d6bae7bc0d288048
|
[
"MIT"
] | 2
|
2021-10-04T05:30:30.000Z
|
2021-10-09T08:24:56.000Z
|
src/Morphism/Structures.agda
|
Akshobhya1234/agda-NonAssociativeAlgebra
|
443e831e536b756acbd1afd0d6bae7bc0d288048
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Core
module Morphism.Structures where
open import Algebra
import Algebra.Morphism.Definitions as MorphismDefinitions
open import Level using (Level; _⊔_)
import Function.Definitions as FunctionDefinitions
open import Relation.Binary.Morphism.Structures
open import Quasigroup
open import Loop
open import Algebra.Morphism.Structures
private
variable
a b ℓ₁ ℓ₂ : Level
| 23.210526
| 58
| 0.807256
|
43196c0d0b30e52027468c53aebbed3889274f54
| 353
|
agda
|
Agda
|
test/Succeed/Issue1834b.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1834b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1834b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas & James, 2016-04-18 pre-AIM XXIII
-- order of clauses should not matter here!
{-# OPTIONS --exact-split #-}
open import Common.Equality
open import Common.Prelude
open import Common.Product
thing : Bool → Bool × Bool
proj₁ (thing true) = false
proj₁ (thing false) = true
proj₂ (thing b) = b
test : ∀ b → proj₂ (thing b) ≡ b
test b = refl
| 20.764706
| 44
| 0.691218
|
21eaba1fcbd948f687b22b7c8e98dcd7fc6069b4
| 1,276
|
agda
|
Agda
|
theorems/homotopy/Bouquet.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
theorems/homotopy/Bouquet.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
theorems/homotopy/Bouquet.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.FinWedge
module homotopy.Bouquet where
Rose : ∀ {i} (I : Type i) → Type i
Rose I = BigWedge {A = I} (λ _ → ⊙S¹)
Bouquet-family : ∀ {i} (I : Type i) (m : ℕ) → (I → Ptd₀)
Bouquet-family I m _ = ⊙Sphere m
Bouquet : ∀ {i} (I : Type i) (m : ℕ) → Type i
Bouquet I m = BigWedge (Bouquet-family I m)
⊙Bouquet : ∀ {i} (I : Type i) (m : ℕ) → Ptd i
⊙Bouquet I m = ⊙BigWedge (Bouquet-family I m)
BouquetLift-family : ∀ {i} (I : Type i) (m : ℕ) → (I → Ptd i)
BouquetLift-family {i} I m _ = ⊙Lift {j = i} (⊙Sphere m)
BouquetLift : ∀ {i} (I : Type i) (m : ℕ) → Type i
BouquetLift {i} I m = BigWedge (BouquetLift-family I m)
⊙BouquetLift : ∀ {i} (I : Type i) (m : ℕ) → Ptd i
⊙BouquetLift {i} I m = ⊙BigWedge (BouquetLift-family I m)
FinBouquetLift-family : ∀ {i} (I m : ℕ) → (Fin I → Ptd i)
FinBouquetLift-family {i} I m _ = ⊙Lift {j = i} (⊙Sphere m)
⊙FinBouquetLift : ∀ {i} (I m : ℕ) → Ptd i
⊙FinBouquetLift I m = ⊙FinWedge (FinBouquetLift-family I m)
FinBouquet-family : (I m : ℕ) → (Fin I → Ptd₀)
FinBouquet-family I m _ = ⊙Sphere m
FinBouquet : (I m : ℕ) → Type₀
FinBouquet I m = FinWedge (FinBouquet-family I m)
⊙FinBouquet : (I m : ℕ) → Ptd₀
⊙FinBouquet I m = ⊙FinWedge (FinBouquet-family I m)
| 29.674419
| 61
| 0.608934
|
7c9e0252a98b78ae3c4e70a38aebf8acf8ecf44d
| 531
|
agda
|
Agda
|
test/Succeed/Issue5334.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue5334.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue5334.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2021-04-21, issue #5334
-- Improve sorting of constructors to data for interleaved mutual blocks.
{-# OPTIONS --allow-unsolved-metas #-}
module Issue5334 where
module Works where
data Nat : Set where
zero : Nat
data Fin : Nat → Set where
zero : Fin {!!}
interleaved mutual
data Nat : Set
data Fin : Nat → Set
data _ where
zero : Nat
data _ where
zero : Fin {!!} -- should work
-- Error was:
-- Could not find a matching data signature for constructor zero
-- There was no candidate.
| 19.666667
| 73
| 0.66855
|
fd613ccbdfd1f3f463509668ed6f61efbc3b2ca6
| 66
|
agda
|
Agda
|
test/Compiler/simple/Cubical-is-not-supported.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Compiler/simple/Cubical-is-not-supported.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Compiler/simple/Cubical-is-not-supported.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --cubical -van-extra-option-just-to-test-a-hack:0 #-}
| 33
| 65
| 0.666667
|
1be27f2b9269c6b6ed1d8033aa7208d2bd609093
| 2,740
|
agda
|
Agda
|
src/Categories/Functor/Construction/PathsOf.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Functor/Construction/PathsOf.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Functor/Construction/PathsOf.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Construction.PathsOf where
-- "Free Category on a Quiver" Construction, i.e. the category of paths of the quiver.
-- Note the use of Categories.Morphism.HeterogeneousIdentity as well as
-- Relation.Binary.PropositionalEquality.Subst.Properties which are needed
-- for F-resp-≈.
open import Level
open import Function using (_$_)
open import Relation.Binary.PropositionalEquality using (refl; sym)
open import Relation.Binary.PropositionalEquality.Subst.Properties using (module TransportStar)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties
open import Data.Quiver
open import Data.Quiver.Morphism
open import Data.Quiver.Paths using (module Paths)
open import Categories.Category
import Categories.Category.Construction.PathCategory as PC
open import Categories.Category.Instance.Quivers
open import Categories.Category.Instance.StrictCats
open import Categories.Functor using (Functor)
open import Categories.Functor.Equivalence using (_≡F_)
import Categories.Morphism.HeterogeneousIdentity as HId
import Categories.Morphism.Reasoning as MR
private
variable
o o′ ℓ ℓ′ e e′ : Level
G₁ G₂ : Quiver o ℓ e
⇒toPathF : {G₁ G₂ : Quiver o ℓ e} → Morphism G₁ G₂ → Functor (PC.PathCategory G₁) (PC.PathCategory G₂)
⇒toPathF {G₁ = G₁} {G₂} G⇒ = record
{ F₀ = F₀ G⇒
; F₁ = qmap G⇒
; identity = Paths.refl G₂
; homomorphism = λ {_} {_} {_} {f} {g} → Paths.≡⇒≈* G₂ $ gmap-◅◅ (F₀ G⇒) (F₁ G⇒) f g
; F-resp-≈ = λ { {f = f} → map-resp G⇒ f}
}
where open Morphism
⇒toPathF-resp-≃ : {f g : Morphism G₁ G₂} → f ≃ g → ⇒toPathF f ≡F ⇒toPathF g
⇒toPathF-resp-≃ {G₂ = G} {f} {g} f≈g = record
{ eq₀ = λ _ → F₀≡
; eq₁ = λ h →
let open Category.HomReasoning (PC.PathCategory G)
open HId (PC.PathCategory G)
open TransportStar (Quiver._⇒_ G)
in begin
qmap f h ◅◅ (hid F₀≡) ≈˘⟨ hid-subst-cod (qmap f h) F₀≡ ⟩
qmap f h ▸* F₀≡ ≈⟨ map-F₁≡ f≈g h ⟩
F₀≡ ◂* qmap g h ≈⟨ hid-subst-dom F₀≡ (qmap g h) ⟩
hid F₀≡ ◅◅ qmap g h ∎
}
where
open _≃_ f≈g
PathsOf : Functor (Quivers o ℓ e) (StrictCats o (o ⊔ ℓ) (o ⊔ ℓ ⊔ e))
PathsOf = record
{ F₀ = PC.PathCategory
; F₁ = ⇒toPathF
; identity = λ {G} → record
{ eq₀ = λ _ → refl
; eq₁ = λ f → toSquare (PC.PathCategory G) (Paths.≡⇒≈* G $ gmap-id f)
}
; homomorphism = λ {_} {_} {G} {f} {g} → record
{ eq₀ = λ _ → refl
; eq₁ = λ h → toSquare (PC.PathCategory G) (Paths.≡⇒≈* G (sym $ gmap-∘ (F₀ g) (F₁ g) (F₀ f) (F₁ f) h) )
}
; F-resp-≈ = ⇒toPathF-resp-≃
}
where
open Morphism using (F₀; F₁)
open MR using (toSquare)
| 35.584416
| 107
| 0.656204
|
213d8074525fda6943e78c85959f1bb10f892940
| 3,335
|
agda
|
Agda
|
src/Categories/Object/Product/Limit.agda
|
jaykru/agda-categories
|
a4053cf700bcefdf73b857c3352f1eae29382a60
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Object/Product/Limit.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Object/Product/Limit.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category.Core
module Categories.Object.Product.Limit {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Data.Nat.Base using (ℕ)
open import Data.Fin.Base using (Fin)
open import Data.Fin.Patterns
open import Categories.Category.Lift
open import Categories.Category.Finite.Fin
open import Categories.Category.Finite.Fin.Construction.Discrete
open import Categories.Object.Product C
open import Categories.Diagram.Limit
open import Categories.Functor.Core
import Categories.Category.Construction.Cones as Co
import Categories.Morphism.Reasoning as MR
private
module C = Category C
open C
open MR C
open HomReasoning
module _ {o′ ℓ′ e′} {F : Functor (liftC o′ ℓ′ e′ (Discrete 2)) C} where
private
module F = Functor F
open F
limit⇒product : Limit F → Product (F₀ (lift 0F)) (F₀ (lift 1F))
limit⇒product L = record
{ A×B = apex
; π₁ = proj (lift 0F)
; π₂ = proj (lift 1F)
; ⟨_,_⟩ = λ f g → rep record
{ apex = record
{ ψ = λ { (lift 0F) → f
; (lift 1F) → g }
; commute = λ { {lift 0F} {lift 0F} (lift 0F) → elimˡ identity
; {lift 1F} {lift 1F} (lift 0F) → elimˡ identity }
}
}
; project₁ = commute
; project₂ = commute
; unique = λ {_} {h} eq eq′ → terminal.!-unique record
{ arr = h
; commute = λ { {lift 0F} → eq
; {lift 1F} → eq′ }
}
}
where open Limit L
module _ o′ ℓ′ e′ A B where
open Equiv
product⇒limit-F : Functor (liftC o′ ℓ′ e′ (Discrete 2)) C
product⇒limit-F = record
{ F₀ = λ { (lift 0F) → A
; (lift 1F) → B }
; F₁ = λ { {lift 0F} {lift 0F} _ → C.id
; {lift 1F} {lift 1F} _ → C.id }
; identity = λ { {lift 0F} → refl
; {lift 1F} → refl }
; homomorphism = λ { {lift 0F} {lift 0F} {lift 0F} → sym identity²
; {lift 1F} {lift 1F} {lift 1F} → sym identity² }
; F-resp-≈ = λ { {lift 0F} {lift 0F} _ → refl
; {lift 1F} {lift 1F} _ → refl }
}
module _ o′ ℓ′ e′ {A B} (p : Product A B) where
open Product p
private
F = product⇒limit-F o′ ℓ′ e′ A B
open Functor F
product⇒limit : Limit F
product⇒limit = record
{ terminal = record
{ ⊤ = record
{ N = A×B
; apex = record
{ ψ = λ { (lift 0F) → π₁
; (lift 1F) → π₂ }
; commute = λ { {lift 0F} {lift 0F} (lift 0F) → identityˡ
; {lift 1F} {lift 1F} (lift 0F) → identityˡ }
}
}
; ⊤-is-terminal = record
{ ! = λ {K} →
let open Co.Cone F K
in record
{ arr = ⟨ ψ (lift 0F) , ψ (lift 1F) ⟩
; commute = λ { {lift 0F} → project₁
; {lift 1F} → project₂ }
}
; !-unique = λ {K} f →
let module K = Co.Cone F K
module f = Co.Cone⇒ F f
in begin
⟨ K.ψ (lift 0F) , K.ψ (lift 1F) ⟩ ≈˘⟨ ⟨⟩-cong₂ f.commute f.commute ⟩
⟨ π₁ ∘ f.arr , π₂ ∘ f.arr ⟩ ≈⟨ g-η ⟩
f.arr ∎
}
}
}
| 30.59633
| 80
| 0.489355
|
7c3d41c54287b85768e669c14d4a122f3128fa03
| 57
|
agda
|
Agda
|
test/Succeed/LineEndings/Unix.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/LineEndings/Unix.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/LineEndings/Unix.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module LineEndings.Unix where
postulate ThisWorks : Set
| 14.25
| 29
| 0.824561
|
1b9d6808c918281eb86ef37f4cc605a6bc678fde
| 7,811
|
agda
|
Agda
|
Cubical/Codata/Conat/Bounded.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Codata/Conat/Bounded.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Codata/Conat/Bounded.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe --guardedness #-}
module Cubical.Codata.Conat.Bounded where
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Codata.Conat.Base
renaming (zero to czero; suc to csuc)
open import Cubical.Codata.Conat.Properties
open import Cubical.Data.Empty as Empty
open import Cubical.Data.Sigma
open import Cubical.Data.Sum hiding (rec)
open import Cubical.Data.Unit
open import Cubical.Relation.Nullary
open import Cubical.Data.Nat as Nat
import Cubical.Data.Fin.Recursive as Fin
private variable ℓ : Level
_≺_ : ℕ → Conat → Type _
_≺′_ : ℕ → Conat′ → Type _
n ≺ c = n ≺′ force c
_ ≺′ czero = ⊥
zero ≺′ csuc _ = Unit
suc n ≺′ csuc c = n ≺ c
isProp≺ : ∀ n c → isProp (n ≺ c)
isProp≺′ : ∀ n c → isProp (n ≺′ c)
isProp≺ n c = isProp≺′ n (force c)
isProp≺′ n czero = isProp⊥
isProp≺′ zero (csuc _) = isPropUnit
isProp≺′ (suc n) (csuc c') = isProp≺ n c'
isPropDep≺ : ∀ c → isPropDep (_≺ c)
isPropDep≺ c = isOfHLevel→isOfHLevelDep 1 (λ n → isProp≺ n c) {_} {_}
isPropDep≺′ : ∀ c → isPropDep (_≺′ c)
isPropDep≺′ c = isOfHLevel→isOfHLevelDep 1 (λ n → isProp≺′ n c) {_} {_}
private
apart : ℕ → ℕ → Type
apart zero zero = ⊥
apart (suc m) (suc n) = apart m n
apart _ _ = Unit
≢→apart : (i j : ℕ) → ¬ i ≡ j → apart i j
≢→apart zero zero ¬p = ¬p refl
≢→apart (suc i) (suc j) ¬p = ≢→apart i j (¬p ∘ cong suc)
≢→apart zero (suc j) _ = _
≢→apart (suc i) zero _ = _
apart→≢ : (i j : ℕ) → apart i j → ¬ i ≡ j
apart→≢ (suc i) zero _ = snotz
apart→≢ zero (suc j) _ = znots
apart→≢ (suc i) (suc j) i#j = apart→≢ i j i#j ∘ cong predℕ
isPropApart : ∀ m n → isProp (apart m n)
isPropApart 0 0 = isProp⊥
isPropApart (suc m) (suc n) = isPropApart m n
isPropApart (suc _) 0 = isPropUnit
isPropApart 0 (suc _) = isPropUnit
_#_ : ∀{P : ℕ → Type ℓ} → (l r : Σ ℕ P) → Type
(m , _) # (n , _) = apart m n
#→≢ : ∀{P : ℕ → Type ℓ} → (l r : Σ ℕ P) → l # r → ¬ l ≡ r
#→≢ (i , _) (j , _) d = apart→≢ i j d ∘ cong fst
isProp# : ∀{P : ℕ → Type ℓ} (l r : Σ ℕ P) → isProp (l # r)
isProp# (m , _) (n , _) = isPropApart m n
isProp#Depᵣ : ∀{P : ℕ → Type ℓ} (r : Σ ℕ P) → isPropDep (_# r)
isProp#Depᵣ r = isOfHLevel→isOfHLevelDep 1 (λ l → isProp# l r) {_} {_}
Bounded : Conat → Type
Bounded m = Σ[ n ∈ ℕ ] n ≺ m
Bounded′ : Conat′ → Type
Bounded′ m = Σ[ n ∈ ℕ ] n ≺′ m
discreteB′ : ∀ m → (i j : Bounded′ m) → (i ≡ j) ⊎ (i # j)
discreteB′ m (i , i≺m) (j , j≺m) with discreteℕ i j
... | yes p = inl λ i → p i , isPropDep≺′ m i≺m j≺m p i
... | no ¬p = inr (≢→apart i j ¬p)
≺∞ : ∀ n → n ≺ ∞
≺∞ zero = _
≺∞ (suc n) = ≺∞ n
Σ≺∞≃ℕ : Bounded ∞ ≃ ℕ
Σ≺∞≃ℕ = isoToEquiv λ where
.fun → fst
.inv n → n , ≺∞ n
.rightInv _ → refl
.leftInv (n , p) i → λ where
.fst → n
.snd → isProp≺ n ∞ (≺∞ n) p i
where open Iso
Σ≺∞≡ℕ : Bounded ∞ ≡ ℕ
Σ≺∞≡ℕ = ua Σ≺∞≃ℕ
_≺?_ : ∀ n c → Dec (n ≺ c)
n ≺? c with force c
_ ≺? c | czero = no (idfun ⊥)
zero ≺? c | csuc d = yes _
suc n ≺? c | csuc d = n ≺? d
≺-pred : ∀ n c → suc n ≺ c → n ≺ c
≺-pred n c sn≺c with force c
≺-pred zero c sn≺c | csuc d = _
≺-pred (suc n) c sn≺c | csuc d = ≺-pred n d sn≺c
≺?-yes : ∀ n c → (p : n ≺ c) → n ≺? c ≡ yes p
≺?-yes n c p with force c
≺?-yes zero c p | csuc c' = refl
≺?-yes (suc n) c p | csuc c' = ≺?-yes n c' p
∀≺-same : ∀ m n → (∀ k → (k ≺ m) ≡ (k ≺ n)) → m ≡ n
∀≺-same m n ∀≺ i .force with force m | force n
... | czero | czero = czero
... | csuc o | csuc p = csuc (∀≺-same o p (∀≺ ∘ suc) i)
... | csuc o | czero
= Empty.rec {A = csuc o ≡ czero} (transport (∀≺ 0) _) i
... | czero | csuc p
= Empty.rec {A = czero ≡ csuc p} (transport⁻ (∀≺ 0) _) i
Bounded→Fin : ∀ m → Bounded (embed m) → Fin.Fin m
Bounded→Fin (suc m) (0 , 0≺m) = Fin.zero
Bounded→Fin (suc m) (suc n , n≺m) = Fin.suc (Bounded→Fin m (n , n≺m))
module Untangle
{m n}
(f : Bounded′ (csuc m) → Bounded′ (csuc n))
(g : Bounded′ (csuc n) → Bounded′ (csuc m))
(rinv : section f g)
(linv : retract f g)
where
bzro : ∀{k} → Bounded′ (csuc k)
bzro = (zero , _)
bsuc : ∀{k} → Bounded k → Bounded′ (csuc k)
bsuc (l , l≺k) = (suc l , l≺k)
#-f : ∀ v u → v # u → f v # f u
#-f v u v#u with discreteB′ (csuc n) (f v) (f u)
... | inr fv#fu = fv#fu
... | inl fv≡fu
= rec (#→≢ v u v#u (sym (linv v) ∙∙ cong g (fv≡fu) ∙∙ linv u))
#-g : ∀ v u → v # u → g v # g u
#-g v u v#u with discreteB′ (csuc m) (g v) (g u)
... | inr gv#gu = gv#gu
... | inl gv≡gu
= rec (#→≢ v u v#u (sym (rinv v) ∙∙ cong f (gv≡gu) ∙∙ rinv u))
#-fg : ∀ v u → v # u → f (g v) # f (g u)
#-fg v u = #-f (g v) (g u) ∘ #-g v u
#-gf : ∀ v u → v # u → g (f v) # g (f u)
#-gf v u = #-g (f v) (f u) ∘ #-f v u
default : ∀{k} → (v d : Bounded′ (csuc k)) → v # d → Bounded k
default (suc l , l≺n) d _ = (l , l≺n)
default (0 , _) (suc l , l≺n) _ = (l , l≺n)
f- : Bounded m → Bounded n
f- v = default (f (bsuc v)) (f bzro) (#-f (bsuc v) bzro _)
g- : Bounded n → Bounded m
g- v = default (g (bsuc v)) (g bzro) (#-g (bsuc v) bzro _)
g-f-z : ∀ v u → g bzro ≡ bsuc v → g (bsuc u) ≡ bzro → g- u ≡ v
g-f-z (l , l≺m) u p q with g (bsuc u) | g bzro | #-g (bsuc u) bzro _
... | zero , _ | suc k , k≺m | #gf = λ where
i .fst → predℕ (p i .fst)
i .snd → isPropDep≺ m k≺m l≺m (cong (predℕ ∘ fst) p) i
... | w@(suc k , k≺m) | dg | #gf = rec (snotz (cong fst q))
g-f-s : ∀ v u → g (bsuc u) ≡ bsuc v → g- u ≡ v
g-f-s (l , l≺m) u p with g (bsuc u) | #-g (bsuc u) bzro _
... | suc k , k≺m | #gf = λ where
i .fst → predℕ (p i .fst)
i .snd → isPropDep≺ m k≺m l≺m (cong (predℕ ∘ fst) p) i
... | zero , k≺m | #gf = rec (znots (cong fst p))
g-f- : ∀ v → g- (f- v) ≡ v
g-f- v@(i , i≺m)
with f (bsuc v) | linv (bsuc v) | #-f (bsuc v) bzro _
... | suc j , j≺m | p | #f = g-f-s v (j , j≺m) p
... | zero , _ | p | #f with f bzro | linv bzro
... | suc k , k≺n | q = g-f-z v (k , k≺n) p q
f-g-z : ∀ v u → f bzro ≡ bsuc v → f (bsuc u) ≡ bzro → f- u ≡ v
f-g-z (l , l≺n) u p q with f (bsuc u) | f bzro | #-f (bsuc u) bzro _
... | zero , _ | suc k , k≺n | #fg = λ where
i .fst → predℕ (p i .fst)
i .snd → isPropDep≺ n k≺n l≺n (cong (predℕ ∘ fst) p) i
... | w@(suc k , k≺m) | df | #fg = rec (snotz (cong fst q))
f-g-s : ∀ v u → f (bsuc u) ≡ bsuc v → f- u ≡ v
f-g-s (l , l≺n) u p with f (bsuc u) | #-f (bsuc u) bzro _
... | suc k , k≺n | _ = λ where
i .fst → predℕ (p i .fst)
i .snd → isPropDep≺ n k≺n l≺n (cong (predℕ ∘ fst) p) i
... | zero , k≺m | _ = rec (znots (cong fst p))
f-g- : ∀ v → f- (g- v) ≡ v
f-g- v@(i , i≺n)
with g (bsuc v) | rinv (bsuc v) | #-g (bsuc v) bzro _
... | suc j , j≺m | p | #g = f-g-s v (j , j≺m) p
... | zero , _ | p | #g with g bzro | rinv bzro
... | suc k , k≺m | q = f-g-z v (k , k≺m) p q
open Iso
iso- : Iso (Bounded m) (Bounded n)
iso- .fun = f-
iso- .inv = g-
iso- .rightInv = f-g-
iso- .leftInv = g-f-
untangled
: ∀{m n}
→ Iso (Bounded′ (csuc m)) (Bounded′ (csuc n))
→ Iso (Bounded m) (Bounded n)
untangled isom = Untangle.iso- fun inv rightInv leftInv
where open Iso isom
Bounded-inj-iso : ∀ m n → Iso (Bounded m) (Bounded n) → m ≡ n
Bounded-inj-iso m n theIso i .force with force m | force n
... | czero | czero = czero
... | csuc l | csuc r
= csuc (Bounded-inj-iso l r (untangled theIso) i)
... | czero | csuc r
= rec {A = czero ≡ csuc r} (Iso.inv theIso (zero , _) .snd) i
... | csuc l | czero
= rec {A = csuc l ≡ czero} (Iso.fun theIso (zero , _) .snd) i
Bounded-inj : ∀ m n → Bounded m ≡ Bounded n → m ≡ n
Bounded-inj m n = Bounded-inj-iso m n ∘ pathToIso
| 31.244
| 71
| 0.52234
|
1bd287c63f25bc032e51f34dae6ba4fe8dd8e406
| 10,167
|
agda
|
Agda
|
Structure/Operator/Names.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/Operator/Names.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/Operator/Names.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Structure.Operator.Names where
open import Functional.Dependent
open import Function.Names
import Lvl
open import Logic
open import Logic.Propositional
open import Logic.Predicate
open import Structure.Function.Names
open import Structure.Setoid
open import Syntax.Function
open import Syntax.Transitivity
open import Type
private variable ℓ ℓₑ ℓ₁ ℓ₂ ℓ₃ ℓᵣ₂ ℓᵣ₃ ℓᵣ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₑᵣ : Lvl.Level
module _ {T₁ : Type{ℓ₁}} {T₂ : Type{ℓ₂}} ⦃ _ : Equiv{ℓₑ₂}(T₂) ⦄ where
-- Definition of commutativity of specific elements.
-- The binary operation swapped yields the same result.
-- Example: For any x, (x ▫ x) always commutes.
Commuting : (T₁ → T₁ → T₂) → T₁ → T₁ → Stmt
Commuting(_▫_) = pointwise₂,₂(_≡_) (_▫_) (swap(_▫_))
-- Definition of commutativity.
-- Order of application for the operation does not matter for equality.
-- Example: Addition of the natural numbers (_+_ : ℕ → ℕ → ℕ).
Commutativity : (T₁ → T₁ → T₂) → Stmt
Commutativity = ∀² ∘ Commuting
-- Definition of an left identity element.
-- Example: Top implies a proposition in boolean logic (⊤ →_).
Identityₗ : (T₁ → T₂ → T₂) → T₁ → Stmt
Identityₗ (_▫_) id = ∀{x : T₂} → (id ▫ x) ≡ x
-- Definition of a right absorber element
-- Also called "right neutral element" or "right annihilator"
-- Applying the operation on this element to the right always yields itself.
-- Example: A proposition implies top in boolean logic (_→ ⊤).
Absorberᵣ : (T₁ → T₂ → T₂) → T₂ → Stmt
Absorberᵣ (_▫_) null = ∀{x : T₁} → (x ▫ null) ≡ null
ConverseAbsorberᵣ : (T₁ → T₂ → T₂) → T₂ → Stmt
ConverseAbsorberᵣ (_▫_)(a) = ∀{x y} → (x ▫ y ≡ a) → (y ≡ a)
module _ {T₁ : Type{ℓ₁}} ⦃ _ : Equiv{ℓₑ₁}(T₁) ⦄ {T₂ : Type{ℓ₂}} where
-- Definition of an right identity element
-- Example: Subtracting 0 for integers (_− 0).
Identityᵣ : (T₁ → T₂ → T₁) → T₂ → Stmt
Identityᵣ(_▫_) id = Identityₗ(swap(_▫_)) id
-- Definition of a left absorber element
-- Also called "left neutral element" or "left annihilator"
-- Example: Subtraction (monus) of 0 for natural numbers (0 − ).
Absorberₗ : (T₁ → T₂ → T₁) → T₁ → Stmt
Absorberₗ(_▫_) null = Absorberᵣ(swap(_▫_)) null
ConverseAbsorberₗ : (T₁ → T₂ → T₁) → T₁ → Stmt
ConverseAbsorberₗ (_▫_)(a) = ∀{x y} → (x ▫ y ≡ a) → (x ≡ a)
module _ {T : Type{ℓ}} ⦃ _ : Equiv{ℓₑ}(T) ⦄ where
-- Definition of an identity element
-- Example: 0 for addition of integers, 1 for multiplication of integers.
Identity : (T → T → T) → T → Stmt
Identity (_▫_) id = (Identityₗ (_▫_) id) ∧ (Identityᵣ (_▫_) id)
-- Definition of idempotence.
Idempotence : (T → T → T) → Stmt
Idempotence (_▫_) = ∀{x : T} → (x ▫ x ≡ x)
-- Example: 0 for addition of natural numbers, 1 for multiplication of natural numbers.
ConverseAbsorber : (T → T → T) → T → Stmt
ConverseAbsorber (_▫_)(a) = ∀{x y} → (x ▫ y ≡ a) → (x ≡ a)∧(y ≡ a)
-- Example: 0 for multiplication of natural numbers.
WeakConverseAbsorber : (T → T → T) → T → Stmt
WeakConverseAbsorber (_▫_)(a) = ∀{x y} → (x ▫ y ≡ a) → (x ≡ a)∨(y ≡ a)
module _ {T₊ : Type{ℓ₁}} {T₋ : Type{ℓ₂}} {Tᵣ : Type{ℓ₃}} ⦃ _ : Equiv{ℓₑᵣ}(Tᵣ) ⦄ where
-- Definition of a left inverse element.
InverseElementₗ : (T₋ → T₊ → Tᵣ) → Tᵣ → T₊ → T₋ → Stmt
InverseElementₗ (_▫_) id x x⁻¹ = ((x⁻¹ ▫ x) ≡ id)
-- Definition of a right inverse element
InverseElementᵣ : (T₊ → T₋ → Tᵣ) → Tᵣ → T₊ → T₋ → Stmt
InverseElementᵣ (_▫_) id x x⁻¹ = ((x ▫ x⁻¹) ≡ id)
-- Definition of a left inverse function
InverseFunctionₗ : (T₋ → T₊ → Tᵣ) → Tᵣ → (T₊ → T₋) → Stmt
InverseFunctionₗ (_▫_) id inv = ∀{x : T₊} → InverseElementₗ(_▫_) id x (inv x)
-- Definition of a right inverse function
InverseFunctionᵣ : (T₊ → T₋ → Tᵣ) → Tᵣ → (T₊ → T₋) → Stmt
InverseFunctionᵣ (_▫_) id inv = ∀{x : T₊} → InverseElementᵣ(_▫_) id x (inv x)
module _ {T : Type{ℓ₁}} {Tᵣ : Type{ℓ₂}} ⦃ _ : Equiv{ℓₑᵣ}(Tᵣ) ⦄ where
-- Definition of an invertible element
InverseElement : (T → T → Tᵣ) → Tᵣ → T → T → Stmt
InverseElement (_▫_) id x x⁻¹ = (InverseElementₗ(_▫_) id x x⁻¹) ∧ (InverseElementᵣ(_▫_) id x x⁻¹)
-- Definition of a function which returns the inverse element of the other side of the operation
InverseFunction : (T → T → Tᵣ) → Tᵣ → (T → T) → Stmt
InverseFunction (_▫_) id inv = (InverseFunctionₗ (_▫_) id inv) ∧ (InverseFunctionᵣ (_▫_) id inv)
module _ {T₁ : Type{ℓ₁}} {T₂ : Type{ℓ₂}} ⦃ _ : Equiv{ℓₑ₂}(T₂) ⦄ {T₃ : Type{ℓ₃}} ⦃ _ : Equiv{ℓₑ₃}(T₃) ⦄ where
-- Definition of right cancellation of a specific object
-- ∀{a b : T₂} → ((x ▫ a) ≡ (x ▫ b)) → (a ≡ b)
CancellationOnₗ : (T₁ → T₂ → T₃) → T₁ → Stmt
CancellationOnₗ (_▫_) (x) = Injective(x ▫_)
-- Definition of left cancellation (Injectivity for the right param)
-- ∀{x : T₁}{a b : T₂} → ((x ▫ a) ≡ (x ▫ b)) → (a ≡ b)
Cancellationₗ : (T₁ → T₂ → T₃) → Stmt
Cancellationₗ (_▫_) = (∀{x : T₁} → CancellationOnₗ(_▫_)(x))
module _ {T₁ : Type{ℓ₁}} ⦃ _ : Equiv{ℓₑ₁}(T₁) ⦄ {T₂ : Type{ℓ₂}} {T₃ : Type{ℓ₃}} ⦃ _ : Equiv{ℓₑ₃}(T₃) ⦄ where
-- Definition of right cancellation of a specific object
-- ∀{a b : T₁} → ((a ▫ x) ≡ (b ▫ x)) → (a ≡ b)
CancellationOnᵣ : (T₁ → T₂ → T₃) → T₂ → Stmt
CancellationOnᵣ (_▫_) (x) = Injective(_▫ x)
-- Definition of right cancellation (Injectivity for the left param)
-- ∀{x : T₂}{a b : T₁} → ((a ▫ x) ≡ (b ▫ x)) → (a ≡ b)
Cancellationᵣ : (T₁ → T₂ → T₃) → Stmt
Cancellationᵣ (_▫_) = (∀{x : T₂} → CancellationOnᵣ (_▫_)(x))
module _ {T₁ : Type{ℓ₁}} {T₂ : Type{ℓ₂}} {T₃ : Type{ℓ₃}} ⦃ _ : Equiv{ℓₑ₂}(T₂) ⦄ where
-- Definition of the left inverse property
InverseOperatorOnₗ : (T₁ → T₂ → T₃) → (T₁ → T₃ → T₂) → T₁ → T₂ → Stmt
InverseOperatorOnₗ (_▫₁_) (_▫₂_) x y = (x ▫₂ (x ▫₁ y) ≡ y)
InverseOperatorₗ : (T₁ → T₂ → T₃) → (T₁ → T₃ → T₂) → Stmt
InverseOperatorₗ (_▫₁_)(_▫₂_) = ∀{x y} → InverseOperatorOnₗ(_▫₁_)(_▫₂_) x y
module _ {T₁ : Type{ℓ₁}} {T₂ : Type{ℓ₂}} {T₃ : Type{ℓ₃}} ⦃ _ : Equiv{ℓₑ₁}(T₁) ⦄ where
-- Definition of the right inverse property
InverseOperatorOnᵣ : (T₁ → T₂ → T₃) → (T₃ → T₂ → T₁) → T₁ → T₂ → Stmt
InverseOperatorOnᵣ (_▫₁_) (_▫₂_) x y = ((x ▫₁ y) ▫₂ y ≡ x)
InverseOperatorᵣ : (T₁ → T₂ → T₃) → (T₃ → T₂ → T₁) → Stmt
InverseOperatorᵣ (_▫₁_)(_▫₂_) = ∀{x y} → InverseOperatorOnᵣ(_▫₁_)(_▫₂_) x y
module _ {T₁ : Type{ℓ₁}} {T₂ : Type{ℓ₂}} ⦃ _ : Equiv{ℓₑ₂}(T₂) ⦄ where
InversePropertyₗ : (T₁ → T₂ → T₂) → (T₁ → T₁) → Stmt
InversePropertyₗ (_▫_) inv = InverseOperatorₗ(_▫_)(a ↦ b ↦ inv(a) ▫ b)
InversePropertyᵣ : (T₂ → T₁ → T₂) → (T₁ → T₁) → Stmt
InversePropertyᵣ (_▫_) inv = InverseOperatorᵣ(_▫_)(a ↦ b ↦ a ▫ inv(b))
---------------------------------------------------------
-- Patterns
module _ {T₁ : Type{ℓ₁}}{T₂ : Type{ℓ₂}}{T₃ : Type{ℓ₃}}{Tᵣ₂ : Type{ℓᵣ₂}}{Tᵣ₃ : Type{ℓᵣ₃}}{Tᵣ : Type{ℓᵣ}} ⦃ _ : Equiv{ℓₑᵣ}(Tᵣ) ⦄ where
AssociativityPattern : (T₁ → T₂ → Tᵣ₃) → (Tᵣ₃ → T₃ → Tᵣ) → (T₁ → Tᵣ₂ → Tᵣ) → (T₂ → T₃ → Tᵣ₂)→ Stmt
AssociativityPattern (_▫₁_) (_▫₂_) (_▫₃_) (_▫₄_) =
∀{x : T₁}{y : T₂}{z : T₃} → ((x ▫₁ y) ▫₂ z) ≡ (x ▫₃ (y ▫₄ z))
module _ {T₁ : Type{ℓ₁}} {T₂ : Type{ℓ₂}} {T₃ : Type{ℓ₃}} ⦃ _ : Equiv{ℓₑ₃}(T₃) ⦄ where
DistributivityPatternₗ : (T₁ → T₂ → T₃) → (T₂ → T₂ → T₂) → (T₃ → T₃ → T₃) → Stmt
DistributivityPatternₗ (_▫₁_) (_▫₂_) (_▫₃_) =
∀{x : T₁} {y z : T₂} → (x ▫₁ (y ▫₂ z)) ≡ ((x ▫₁ y) ▫₃ (x ▫₁ z))
DistributivityPatternᵣ : (T₁ → T₂ → T₃) → (T₁ → T₁ → T₁) → (T₃ → T₃ → T₃) → Stmt
DistributivityPatternᵣ (_▫₁_) (_▫₂_) (_▫₃_) =
∀{x y : T₁} {z : T₂} → ((x ▫₂ y) ▫₁ z) ≡ ((x ▫₁ z) ▫₃ (y ▫₁ z))
---------------------------------------------------------
-- Derived
module _ {T : Type{ℓ}} ⦃ _ : Equiv{ℓₑ}(T) ⦄ where
-- Definition of associativity for a binary operation
Associativity : (T → T → T) → Stmt
Associativity (_▫_) = AssociativityPattern (_▫_) (_▫_) (_▫_) (_▫_)
-- {x y z : T} → ((x ▫ y) ▫ z) ≡ (x ▫ (y ▫ z))
module _ {T₁ : Type{ℓ₁}} {T₂ : Type{ℓ₂}} ⦃ _ : Equiv{ℓₑ₂}(T₂) ⦄ where
-- Definition of compatibility for a binary operation
Compatibility : (T₁ → T₁ → T₁) → (T₁ → T₂ → T₂) → Stmt -- TODO: https://en.wikipedia.org/wiki/Semigroup_action
Compatibility (_▫₁_) (_▫₂_) = AssociativityPattern (_▫₁_) (_▫₂_) (_▫₂_) (_▫₂_)
-- {x₁ x₂ : T₁}{y : T₂} → ((x₁ ▫₁ x₂) ▫₂ y) ≡ (x₁ ▫₂ (x₂ ▫₂ y))
-- Definition of left distributivity for a binary operation
Distributivityₗ : (T₁ → T₂ → T₂) → (T₂ → T₂ → T₂) → Stmt
Distributivityₗ (_▫₁_) (_▫₂_) = DistributivityPatternₗ (_▫₁_) (_▫₂_) (_▫₂_)
-- ∀{x : T₁} {y z : T₂} → (x ▫₁ (y ▫₂ z)) ≡ (x ▫₁ y) ▫₂ (x ▫₁ z)
-- Definition of right distributivity for a binary operation
Distributivityᵣ : (T₂ → T₁ → T₂) → (T₂ → T₂ → T₂) → Stmt
Distributivityᵣ (_▫₁_) (_▫₂_) = DistributivityPatternᵣ (_▫₁_) (_▫₂_) (_▫₂_)
-- ∀{x y : T₂} {z : T₁} → ((x ▫₂ y) ▫₁ z) ≡ (x ▫₁ z) ▫₂ (y ▫₁ z)
module _ {T₁ : Type{ℓ₁}} {T₂ : Type{ℓ₂}} {T₃ : Type{ℓ₃}} ⦃ _ : Equiv{ℓₑ₁}(T₁) ⦄ where
-- Definition of left absorption for two binary operators
Absorptionₗ : (T₁ → T₃ → T₁) → (T₁ → T₂ → T₃) → Stmt
Absorptionₗ (_▫₁_)(_▫₂_) = ∀{x : T₁}{y : T₂} → (x ▫₁ (x ▫₂ y) ≡ x)
module _ {T₁ : Type{ℓ₁}} {T₂ : Type{ℓ₂}} {T₃ : Type{ℓ₃}} ⦃ _ : Equiv{ℓₑ₂}(T₂) ⦄ where
-- Definition of right absorption for two binary operators
Absorptionᵣ : (T₃ → T₂ → T₂) → (T₁ → T₂ → T₃) → Stmt
Absorptionᵣ (_▫₁_)(_▫₂_) = ∀{x : T₁}{y : T₂} → ((x ▫₂ y) ▫₁ y ≡ y)
---------------------------------------------------------
-- Functions (TODO: Move to Structure.Operator.Proofs)
{-
open import Relator.Equals{ℓ₁}{ℓ₂}
open import Relator.Equals.Proofs{ℓ₁}{ℓ₂}
-- Returns a commuted LHS of an equality
commuteₗ : ∀{T}{_▫_}{x y z} → ⦃ _ : Commutativity {T} {T} (_▫_) ⦄ → ((x ▫ y) ≡ z) → ((y ▫ x) ≡ z)
commuteₗ ⦃ comm ⦄ stmt = comm 🝖 stmt
-- Returns a commuted RHS of an equality
commuteᵣ : ∀{T}{_▫_}{x y z} → ⦃ _ : Commutativity {T} {T} (_▫_) ⦄ → (z ≡ (x ▫ y)) → (z ≡ (y ▫ x))
commuteᵣ ⦃ comm ⦄ stmt = stmt 🝖 comm
commuteBoth : ∀{T₁ T₂}{_▫_}{a₁ a₂ b₁ b₂} → Commutativity{T₁}{T₂}(_▫_) → (a₁ ▫ a₂ ≡ b₁ ▫ b₂) → (a₂ ▫ a₁ ≡ b₂ ▫ b₁)
commuteBoth {_}{_} {a₁} {a₂} {b₁} {b₂} commutativity (a₁▫a₂≡b₁▫b₂) =
(symmetry ⦃ [≡]-symmetry ⦄ (commutativity {a₁} {a₂}))
🝖' (a₁▫a₂≡b₁▫b₂)
🝖' (commutativity {b₁} {b₂})
where
_🝖'_ = _🝖_ ⦃ [≡]-transitivity ⦄
infixl 1000 _🝖'_
-}
| 45.388393
| 132
| 0.57667
|
34e6691f0cc06481f241a5be29d07ba78eca4a56
| 19,425
|
agda
|
Agda
|
prototyping/Properties/Subtyping.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | 1
|
2021-12-05T21:53:03.000Z
|
2021-12-05T21:53:03.000Z
|
prototyping/Properties/Subtyping.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
prototyping/Properties/Subtyping.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --rewriting #-}
module Properties.Subtyping where
open import Agda.Builtin.Equality using (_≡_; refl)
open import FFI.Data.Either using (Either; Left; Right; mapLR; swapLR; cond)
open import FFI.Data.Maybe using (Maybe; just; nothing)
open import Luau.Subtyping using (_<:_; _≮:_; Tree; Language; ¬Language; witness; unknown; never; scalar; function; scalar-function; scalar-function-ok; scalar-function-err; scalar-scalar; function-scalar; function-ok; function-err; left; right; _,_)
open import Luau.Type using (Type; Scalar; nil; number; string; boolean; never; unknown; _⇒_; _∪_; _∩_; skalar)
open import Properties.Contradiction using (CONTRADICTION; ¬; ⊥)
open import Properties.Equality using (_≢_)
open import Properties.Functions using (_∘_)
open import Properties.Product using (_×_; _,_)
-- Language membership is decidable
dec-language : ∀ T t → Either (¬Language T t) (Language T t)
dec-language nil (scalar number) = Left (scalar-scalar number nil (λ ()))
dec-language nil (scalar boolean) = Left (scalar-scalar boolean nil (λ ()))
dec-language nil (scalar string) = Left (scalar-scalar string nil (λ ()))
dec-language nil (scalar nil) = Right (scalar nil)
dec-language nil function = Left (scalar-function nil)
dec-language nil (function-ok t) = Left (scalar-function-ok nil)
dec-language nil (function-err t) = Left (scalar-function-err nil)
dec-language boolean (scalar number) = Left (scalar-scalar number boolean (λ ()))
dec-language boolean (scalar boolean) = Right (scalar boolean)
dec-language boolean (scalar string) = Left (scalar-scalar string boolean (λ ()))
dec-language boolean (scalar nil) = Left (scalar-scalar nil boolean (λ ()))
dec-language boolean function = Left (scalar-function boolean)
dec-language boolean (function-ok t) = Left (scalar-function-ok boolean)
dec-language boolean (function-err t) = Left (scalar-function-err boolean)
dec-language number (scalar number) = Right (scalar number)
dec-language number (scalar boolean) = Left (scalar-scalar boolean number (λ ()))
dec-language number (scalar string) = Left (scalar-scalar string number (λ ()))
dec-language number (scalar nil) = Left (scalar-scalar nil number (λ ()))
dec-language number function = Left (scalar-function number)
dec-language number (function-ok t) = Left (scalar-function-ok number)
dec-language number (function-err t) = Left (scalar-function-err number)
dec-language string (scalar number) = Left (scalar-scalar number string (λ ()))
dec-language string (scalar boolean) = Left (scalar-scalar boolean string (λ ()))
dec-language string (scalar string) = Right (scalar string)
dec-language string (scalar nil) = Left (scalar-scalar nil string (λ ()))
dec-language string function = Left (scalar-function string)
dec-language string (function-ok t) = Left (scalar-function-ok string)
dec-language string (function-err t) = Left (scalar-function-err string)
dec-language (T₁ ⇒ T₂) (scalar s) = Left (function-scalar s)
dec-language (T₁ ⇒ T₂) function = Right function
dec-language (T₁ ⇒ T₂) (function-ok t) = mapLR function-ok function-ok (dec-language T₂ t)
dec-language (T₁ ⇒ T₂) (function-err t) = mapLR function-err function-err (swapLR (dec-language T₁ t))
dec-language never t = Left never
dec-language unknown t = Right unknown
dec-language (T₁ ∪ T₂) t = cond (λ p → cond (Left ∘ _,_ p) (Right ∘ right) (dec-language T₂ t)) (Right ∘ left) (dec-language T₁ t)
dec-language (T₁ ∩ T₂) t = cond (Left ∘ left) (λ p → cond (Left ∘ right) (Right ∘ _,_ p) (dec-language T₂ t)) (dec-language T₁ t)
-- ¬Language T is the complement of Language T
language-comp : ∀ {T} t → ¬Language T t → ¬(Language T t)
language-comp t (p₁ , p₂) (left q) = language-comp t p₁ q
language-comp t (p₁ , p₂) (right q) = language-comp t p₂ q
language-comp t (left p) (q₁ , q₂) = language-comp t p q₁
language-comp t (right p) (q₁ , q₂) = language-comp t p q₂
language-comp (scalar s) (scalar-scalar s p₁ p₂) (scalar s) = p₂ refl
language-comp (scalar s) (function-scalar s) (scalar s) = language-comp function (scalar-function s) function
language-comp (scalar s) never (scalar ())
language-comp function (scalar-function ()) function
language-comp (function-ok t) (scalar-function-ok ()) (function-ok q)
language-comp (function-ok t) (function-ok p) (function-ok q) = language-comp t p q
language-comp (function-err t) (function-err p) (function-err q) = language-comp t q p
-- ≮: is the complement of <:
¬≮:-impl-<: : ∀ {T U} → ¬(T ≮: U) → (T <: U)
¬≮:-impl-<: {T} {U} p t q with dec-language U t
¬≮:-impl-<: {T} {U} p t q | Left r = CONTRADICTION (p (witness t q r))
¬≮:-impl-<: {T} {U} p t q | Right r = r
<:-impl-¬≮: : ∀ {T U} → (T <: U) → ¬(T ≮: U)
<:-impl-¬≮: p (witness t q r) = language-comp t r (p t q)
<:-impl-⊇ : ∀ {T U} → (T <: U) → ∀ t → ¬Language U t → ¬Language T t
<:-impl-⊇ {T} p t q with dec-language T t
<:-impl-⊇ {_} p t q | Left r = r
<:-impl-⊇ {_} p t q | Right r = CONTRADICTION (language-comp t q (p t r))
-- reflexivity
≮:-refl : ∀ {T} → ¬(T ≮: T)
≮:-refl (witness t p q) = language-comp t q p
<:-refl : ∀ {T} → (T <: T)
<:-refl = ¬≮:-impl-<: ≮:-refl
-- transititivity
≮:-trans-≡ : ∀ {S T U} → (S ≮: T) → (T ≡ U) → (S ≮: U)
≮:-trans-≡ p refl = p
≡-trans-≮: : ∀ {S T U} → (S ≡ T) → (T ≮: U) → (S ≮: U)
≡-trans-≮: refl p = p
≮:-trans : ∀ {S T U} → (S ≮: U) → Either (S ≮: T) (T ≮: U)
≮:-trans {T = T} (witness t p q) = mapLR (witness t p) (λ z → witness t z q) (dec-language T t)
<:-trans : ∀ {S T U} → (S <: T) → (T <: U) → (S <: U)
<:-trans p q t r = q t (p t r)
<:-trans-≮: : ∀ {S T U} → (S <: T) → (S ≮: U) → (T ≮: U)
<:-trans-≮: p (witness t q r) = witness t (p t q) r
≮:-trans-<: : ∀ {S T U} → (S ≮: U) → (T <: U) → (S ≮: T)
≮:-trans-<: (witness t p q) r = witness t p (<:-impl-⊇ r t q)
-- Properties of union
<:-union : ∀ {R S T U} → (R <: T) → (S <: U) → ((R ∪ S) <: (T ∪ U))
<:-union p q t (left r) = left (p t r)
<:-union p q t (right r) = right (q t r)
<:-∪-left : ∀ {S T} → S <: (S ∪ T)
<:-∪-left t p = left p
<:-∪-right : ∀ {S T} → T <: (S ∪ T)
<:-∪-right t p = right p
<:-∪-lub : ∀ {S T U} → (S <: U) → (T <: U) → ((S ∪ T) <: U)
<:-∪-lub p q t (left r) = p t r
<:-∪-lub p q t (right r) = q t r
<:-∪-symm : ∀ {T U} → (T ∪ U) <: (U ∪ T)
<:-∪-symm t (left p) = right p
<:-∪-symm t (right p) = left p
<:-∪-assocl : ∀ {S T U} → (S ∪ (T ∪ U)) <: ((S ∪ T) ∪ U)
<:-∪-assocl t (left p) = left (left p)
<:-∪-assocl t (right (left p)) = left (right p)
<:-∪-assocl t (right (right p)) = right p
<:-∪-assocr : ∀ {S T U} → ((S ∪ T) ∪ U) <: (S ∪ (T ∪ U))
<:-∪-assocr t (left (left p)) = left p
<:-∪-assocr t (left (right p)) = right (left p)
<:-∪-assocr t (right p) = right (right p)
≮:-∪-left : ∀ {S T U} → (S ≮: U) → ((S ∪ T) ≮: U)
≮:-∪-left (witness t p q) = witness t (left p) q
≮:-∪-right : ∀ {S T U} → (T ≮: U) → ((S ∪ T) ≮: U)
≮:-∪-right (witness t p q) = witness t (right p) q
-- Properties of intersection
<:-intersect : ∀ {R S T U} → (R <: T) → (S <: U) → ((R ∩ S) <: (T ∩ U))
<:-intersect p q t (r₁ , r₂) = (p t r₁ , q t r₂)
<:-∩-left : ∀ {S T} → (S ∩ T) <: S
<:-∩-left t (p , _) = p
<:-∩-right : ∀ {S T} → (S ∩ T) <: T
<:-∩-right t (_ , p) = p
<:-∩-glb : ∀ {S T U} → (S <: T) → (S <: U) → (S <: (T ∩ U))
<:-∩-glb p q t r = (p t r , q t r)
<:-∩-symm : ∀ {T U} → (T ∩ U) <: (U ∩ T)
<:-∩-symm t (p₁ , p₂) = (p₂ , p₁)
≮:-∩-left : ∀ {S T U} → (S ≮: T) → (S ≮: (T ∩ U))
≮:-∩-left (witness t p q) = witness t p (left q)
≮:-∩-right : ∀ {S T U} → (S ≮: U) → (S ≮: (T ∩ U))
≮:-∩-right (witness t p q) = witness t p (right q)
-- Distribution properties
<:-∩-distl-∪ : ∀ {S T U} → (S ∩ (T ∪ U)) <: ((S ∩ T) ∪ (S ∩ U))
<:-∩-distl-∪ t (p₁ , left p₂) = left (p₁ , p₂)
<:-∩-distl-∪ t (p₁ , right p₂) = right (p₁ , p₂)
∩-distl-∪-<: : ∀ {S T U} → ((S ∩ T) ∪ (S ∩ U)) <: (S ∩ (T ∪ U))
∩-distl-∪-<: t (left (p₁ , p₂)) = (p₁ , left p₂)
∩-distl-∪-<: t (right (p₁ , p₂)) = (p₁ , right p₂)
<:-∩-distr-∪ : ∀ {S T U} → ((S ∪ T) ∩ U) <: ((S ∩ U) ∪ (T ∩ U))
<:-∩-distr-∪ t (left p₁ , p₂) = left (p₁ , p₂)
<:-∩-distr-∪ t (right p₁ , p₂) = right (p₁ , p₂)
∩-distr-∪-<: : ∀ {S T U} → ((S ∩ U) ∪ (T ∩ U)) <: ((S ∪ T) ∩ U)
∩-distr-∪-<: t (left (p₁ , p₂)) = (left p₁ , p₂)
∩-distr-∪-<: t (right (p₁ , p₂)) = (right p₁ , p₂)
<:-∪-distl-∩ : ∀ {S T U} → (S ∪ (T ∩ U)) <: ((S ∪ T) ∩ (S ∪ U))
<:-∪-distl-∩ t (left p) = (left p , left p)
<:-∪-distl-∩ t (right (p₁ , p₂)) = (right p₁ , right p₂)
∪-distl-∩-<: : ∀ {S T U} → ((S ∪ T) ∩ (S ∪ U)) <: (S ∪ (T ∩ U))
∪-distl-∩-<: t (left p₁ , p₂) = left p₁
∪-distl-∩-<: t (right p₁ , left p₂) = left p₂
∪-distl-∩-<: t (right p₁ , right p₂) = right (p₁ , p₂)
<:-∪-distr-∩ : ∀ {S T U} → ((S ∩ T) ∪ U) <: ((S ∪ U) ∩ (T ∪ U))
<:-∪-distr-∩ t (left (p₁ , p₂)) = left p₁ , left p₂
<:-∪-distr-∩ t (right p) = (right p , right p)
∪-distr-∩-<: : ∀ {S T U} → ((S ∪ U) ∩ (T ∪ U)) <: ((S ∩ T) ∪ U)
∪-distr-∩-<: t (left p₁ , left p₂) = left (p₁ , p₂)
∪-distr-∩-<: t (left p₁ , right p₂) = right p₂
∪-distr-∩-<: t (right p₁ , p₂) = right p₁
-- Properties of functions
<:-function : ∀ {R S T U} → (R <: S) → (T <: U) → (S ⇒ T) <: (R ⇒ U)
<:-function p q function function = function
<:-function p q (function-ok t) (function-ok r) = function-ok (q t r)
<:-function p q (function-err s) (function-err r) = function-err (<:-impl-⊇ p s r)
<:-function-∩-∪ : ∀ {R S T U} → ((R ⇒ T) ∩ (S ⇒ U)) <: ((R ∪ S) ⇒ (T ∪ U))
<:-function-∩-∪ function (function , function) = function
<:-function-∩-∪ (function-ok t) (function-ok p₁ , function-ok p₂) = function-ok (right p₂)
<:-function-∩-∪ (function-err _) (function-err p₁ , function-err q₂) = function-err (p₁ , q₂)
<:-function-∩ : ∀ {S T U} → ((S ⇒ T) ∩ (S ⇒ U)) <: (S ⇒ (T ∩ U))
<:-function-∩ function (function , function) = function
<:-function-∩ (function-ok t) (function-ok p₁ , function-ok p₂) = function-ok (p₁ , p₂)
<:-function-∩ (function-err s) (function-err p₁ , function-err p₂) = function-err p₂
<:-function-∪ : ∀ {R S T U} → ((R ⇒ S) ∪ (T ⇒ U)) <: ((R ∩ T) ⇒ (S ∪ U))
<:-function-∪ function (left function) = function
<:-function-∪ (function-ok t) (left (function-ok p)) = function-ok (left p)
<:-function-∪ (function-err s) (left (function-err p)) = function-err (left p)
<:-function-∪ (scalar s) (left (scalar ()))
<:-function-∪ function (right function) = function
<:-function-∪ (function-ok t) (right (function-ok p)) = function-ok (right p)
<:-function-∪ (function-err s) (right (function-err x)) = function-err (right x)
<:-function-∪ (scalar s) (right (scalar ()))
<:-function-∪-∩ : ∀ {R S T U} → ((R ∩ S) ⇒ (T ∪ U)) <: ((R ⇒ T) ∪ (S ⇒ U))
<:-function-∪-∩ function function = left function
<:-function-∪-∩ (function-ok t) (function-ok (left p)) = left (function-ok p)
<:-function-∪-∩ (function-ok t) (function-ok (right p)) = right (function-ok p)
<:-function-∪-∩ (function-err s) (function-err (left p)) = left (function-err p)
<:-function-∪-∩ (function-err s) (function-err (right p)) = right (function-err p)
≮:-function-left : ∀ {R S T U} → (R ≮: S) → (S ⇒ T) ≮: (R ⇒ U)
≮:-function-left (witness t p q) = witness (function-err t) (function-err q) (function-err p)
≮:-function-right : ∀ {R S T U} → (T ≮: U) → (S ⇒ T) ≮: (R ⇒ U)
≮:-function-right (witness t p q) = witness (function-ok t) (function-ok p) (function-ok q)
-- Properties of scalars
skalar-function-ok : ∀ {t} → (¬Language skalar (function-ok t))
skalar-function-ok = (scalar-function-ok number , (scalar-function-ok string , (scalar-function-ok nil , scalar-function-ok boolean)))
scalar-<: : ∀ {S T} → (s : Scalar S) → Language T (scalar s) → (S <: T)
scalar-<: number p (scalar number) (scalar number) = p
scalar-<: boolean p (scalar boolean) (scalar boolean) = p
scalar-<: string p (scalar string) (scalar string) = p
scalar-<: nil p (scalar nil) (scalar nil) = p
scalar-∩-function-<:-never : ∀ {S T U} → (Scalar S) → ((T ⇒ U) ∩ S) <: never
scalar-∩-function-<:-never number .(scalar number) (() , scalar number)
scalar-∩-function-<:-never boolean .(scalar boolean) (() , scalar boolean)
scalar-∩-function-<:-never string .(scalar string) (() , scalar string)
scalar-∩-function-<:-never nil .(scalar nil) (() , scalar nil)
function-≮:-scalar : ∀ {S T U} → (Scalar U) → ((S ⇒ T) ≮: U)
function-≮:-scalar s = witness function function (scalar-function s)
scalar-≮:-function : ∀ {S T U} → (Scalar U) → (U ≮: (S ⇒ T))
scalar-≮:-function s = witness (scalar s) (scalar s) (function-scalar s)
unknown-≮:-scalar : ∀ {U} → (Scalar U) → (unknown ≮: U)
unknown-≮:-scalar s = witness (function-ok (scalar s)) unknown (scalar-function-ok s)
scalar-≮:-never : ∀ {U} → (Scalar U) → (U ≮: never)
scalar-≮:-never s = witness (scalar s) (scalar s) never
scalar-≢-impl-≮: : ∀ {T U} → (Scalar T) → (Scalar U) → (T ≢ U) → (T ≮: U)
scalar-≢-impl-≮: s₁ s₂ p = witness (scalar s₁) (scalar s₁) (scalar-scalar s₁ s₂ p)
scalar-≢-∩-<:-never : ∀ {T U V} → (Scalar T) → (Scalar U) → (T ≢ U) → (T ∩ U) <: V
scalar-≢-∩-<:-never s t p u (scalar s₁ , scalar s₂) = CONTRADICTION (p refl)
skalar-scalar : ∀ {T} (s : Scalar T) → (Language skalar (scalar s))
skalar-scalar number = left (scalar number)
skalar-scalar boolean = right (right (right (scalar boolean)))
skalar-scalar string = right (left (scalar string))
skalar-scalar nil = right (right (left (scalar nil)))
-- Properties of unknown and never
unknown-≮: : ∀ {T U} → (T ≮: U) → (unknown ≮: U)
unknown-≮: (witness t p q) = witness t unknown q
never-≮: : ∀ {T U} → (T ≮: U) → (T ≮: never)
never-≮: (witness t p q) = witness t p never
unknown-≮:-never : (unknown ≮: never)
unknown-≮:-never = witness (scalar nil) unknown never
function-≮:-never : ∀ {T U} → ((T ⇒ U) ≮: never)
function-≮:-never = witness function function never
<:-never : ∀ {T} → (never <: T)
<:-never t (scalar ())
≮:-never-left : ∀ {S T U} → (S <: (T ∪ U)) → (S ≮: T) → (S ∩ U) ≮: never
≮:-never-left p (witness t q₁ q₂) with p t q₁
≮:-never-left p (witness t q₁ q₂) | left r = CONTRADICTION (language-comp t q₂ r)
≮:-never-left p (witness t q₁ q₂) | right r = witness t (q₁ , r) never
≮:-never-right : ∀ {S T U} → (S <: (T ∪ U)) → (S ≮: U) → (S ∩ T) ≮: never
≮:-never-right p (witness t q₁ q₂) with p t q₁
≮:-never-right p (witness t q₁ q₂) | left r = witness t (q₁ , r) never
≮:-never-right p (witness t q₁ q₂) | right r = CONTRADICTION (language-comp t q₂ r)
<:-unknown : ∀ {T} → (T <: unknown)
<:-unknown t p = unknown
<:-everything : unknown <: ((never ⇒ unknown) ∪ skalar)
<:-everything (scalar s) p = right (skalar-scalar s)
<:-everything function p = left function
<:-everything (function-ok t) p = left (function-ok unknown)
<:-everything (function-err s) p = left (function-err never)
-- A Gentle Introduction To Semantic Subtyping (https://www.cduce.org/papers/gentle.pdf)
-- defines a "set-theoretic" model (sec 2.5)
-- Unfortunately we don't quite have this property, due to uninhabited types,
-- for example (never -> T) is equivalent to (never -> U)
-- when types are interpreted as sets of syntactic values.
_⊆_ : ∀ {A : Set} → (A → Set) → (A → Set) → Set
(P ⊆ Q) = ∀ a → (P a) → (Q a)
_⊗_ : ∀ {A B : Set} → (A → Set) → (B → Set) → ((A × B) → Set)
(P ⊗ Q) (a , b) = (P a) × (Q b)
Comp : ∀ {A : Set} → (A → Set) → (A → Set)
Comp P a = ¬(P a)
Lift : ∀ {A : Set} → (A → Set) → (Maybe A → Set)
Lift P nothing = ⊥
Lift P (just a) = P a
set-theoretic-if : ∀ {S₁ T₁ S₂ T₂} →
-- This is the "if" part of being a set-theoretic model
-- though it uses the definition from Frisch's thesis
-- rather than from the Gentle Introduction. The difference
-- being the presence of Lift, (written D_Ω in Defn 4.2 of
-- https://www.cduce.org/papers/frisch_phd.pdf).
(Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂)) →
(∀ Q → Q ⊆ Comp((Language S₁) ⊗ Comp(Lift(Language T₁))) → Q ⊆ Comp((Language S₂) ⊗ Comp(Lift(Language T₂))))
set-theoretic-if {S₁} {T₁} {S₂} {T₂} p Q q (t , just u) Qtu (S₂t , ¬T₂u) = q (t , just u) Qtu (S₁t , ¬T₁u) where
S₁t : Language S₁ t
S₁t with dec-language S₁ t
S₁t | Left ¬S₁t with p (function-err t) (function-err ¬S₁t)
S₁t | Left ¬S₁t | function-err ¬S₂t = CONTRADICTION (language-comp t ¬S₂t S₂t)
S₁t | Right r = r
¬T₁u : ¬(Language T₁ u)
¬T₁u T₁u with p (function-ok u) (function-ok T₁u)
¬T₁u T₁u | function-ok T₂u = ¬T₂u T₂u
set-theoretic-if {S₁} {T₁} {S₂} {T₂} p Q q (t , nothing) Qt- (S₂t , _) = q (t , nothing) Qt- (S₁t , λ ()) where
S₁t : Language S₁ t
S₁t with dec-language S₁ t
S₁t | Left ¬S₁t with p (function-err t) (function-err ¬S₁t)
S₁t | Left ¬S₁t | function-err ¬S₂t = CONTRADICTION (language-comp t ¬S₂t S₂t)
S₁t | Right r = r
not-quite-set-theoretic-only-if : ∀ {S₁ T₁ S₂ T₂} →
-- We don't quite have that this is a set-theoretic model
-- it's only true when Language T₁ and ¬Language T₂ t₂ are inhabited
-- in particular it's not true when T₁ is never, or T₂ is unknown.
∀ s₂ t₂ → Language S₂ s₂ → ¬Language T₂ t₂ →
-- This is the "only if" part of being a set-theoretic model
(∀ Q → Q ⊆ Comp((Language S₁) ⊗ Comp(Lift(Language T₁))) → Q ⊆ Comp((Language S₂) ⊗ Comp(Lift(Language T₂)))) →
(Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂))
not-quite-set-theoretic-only-if {S₁} {T₁} {S₂} {T₂} s₂ t₂ S₂s₂ ¬T₂t₂ p = r where
Q : (Tree × Maybe Tree) → Set
Q (t , just u) = Either (¬Language S₁ t) (Language T₁ u)
Q (t , nothing) = ¬Language S₁ t
q : Q ⊆ Comp((Language S₁) ⊗ Comp(Lift(Language T₁)))
q (t , just u) (Left ¬S₁t) (S₁t , ¬T₁u) = language-comp t ¬S₁t S₁t
q (t , just u) (Right T₂u) (S₁t , ¬T₁u) = ¬T₁u T₂u
q (t , nothing) ¬S₁t (S₁t , _) = language-comp t ¬S₁t S₁t
r : Language (S₁ ⇒ T₁) ⊆ Language (S₂ ⇒ T₂)
r function function = function
r (function-err s) (function-err ¬S₁s) with dec-language S₂ s
r (function-err s) (function-err ¬S₁s) | Left ¬S₂s = function-err ¬S₂s
r (function-err s) (function-err ¬S₁s) | Right S₂s = CONTRADICTION (p Q q (s , nothing) ¬S₁s (S₂s , λ ()))
r (function-ok t) (function-ok T₁t) with dec-language T₂ t
r (function-ok t) (function-ok T₁t) | Left ¬T₂t = CONTRADICTION (p Q q (s₂ , just t) (Right T₁t) (S₂s₂ , language-comp t ¬T₂t))
r (function-ok t) (function-ok T₁t) | Right T₂t = function-ok T₂t
-- A counterexample when the argument type is empty.
set-theoretic-counterexample-one : (∀ Q → Q ⊆ Comp((Language never) ⊗ Comp(Lift(Language number))) → Q ⊆ Comp((Language never) ⊗ Comp(Lift(Language string))))
set-theoretic-counterexample-one Q q ((scalar s) , u) Qtu (scalar () , p)
set-theoretic-counterexample-two : (never ⇒ number) ≮: (never ⇒ string)
set-theoretic-counterexample-two = witness
(function-ok (scalar number)) (function-ok (scalar number))
(function-ok (scalar-scalar number string (λ ())))
-- At some point we may deal with overloaded function resolution, which should fix this problem...
-- The reason why this is connected to overloaded functions is that currently we have that the type of
-- f(x) is (tgt T) where f:T. Really we should have the type depend on the type of x, that is use (tgt T U),
-- where U is the type of x. In particular (tgt (S => T) (U & V)) should be the same as (tgt ((S&U) => T) V)
-- and tgt(never => T) should be unknown. For example
--
-- tgt((number => string) & (string => bool))(number)
-- is tgt(number => string)(number) & tgt(string => bool)(number)
-- is tgt(number => string)(number) & tgt(string => bool)(number&unknown)
-- is tgt(number => string)(number) & tgt(string&number => bool)(unknown)
-- is tgt(number => string)(number) & tgt(never => bool)(unknown)
-- is string & unknown
-- is string
--
-- there's some discussion of this in the Gentle Introduction paper.
| 46.140143
| 250
| 0.593925
|
375d5a75dbbc19f2f5d4664569d7a2128e8a250b
| 903
|
agda
|
Agda
|
src/Categories/Morphism/Extremal.agda
|
maxsnew/agda-categories
|
8f3c844d929508040dfa21f681fa260056214b73
|
[
"MIT"
] | null | null | null |
src/Categories/Morphism/Extremal.agda
|
maxsnew/agda-categories
|
8f3c844d929508040dfa21f681fa260056214b73
|
[
"MIT"
] | null | null | null |
src/Categories/Morphism/Extremal.agda
|
maxsnew/agda-categories
|
8f3c844d929508040dfa21f681fa260056214b73
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
{-
Extremal Mono and Epimorphisms.
https://ncatlab.org/nlab/show/extremal+epimorphism
-}
open import Categories.Category.Core
module Categories.Morphism.Extremal {o ℓ e} (𝒞 : Category o ℓ e) where
open import Level
open import Categories.Morphism 𝒞
open Category 𝒞
IsExtremalEpi : ∀ {A B} {f : A ⇒ B} → Epi f → Set (o ⊔ ℓ ⊔ e)
IsExtremalEpi {A = A} {B = B} {f = f} epi =
∀ {X} {i : X ⇒ B} {g : A ⇒ X} → Mono i → f ≈ i ∘ g → IsIso i
IsExtremalMono : ∀ {A B} {f : A ⇒ B} → Mono f → Set (o ⊔ ℓ ⊔ e)
IsExtremalMono {A = A} {B = B} {f = f} mono =
∀ {X} {g : X ⇒ B} {i : A ⇒ X} → Epi i → f ≈ g ∘ i → IsIso i
record ExtremalEpi {A B} (f : A ⇒ B) : Set (o ⊔ ℓ ⊔ e) where
field
epi : Epi f
extremal : IsExtremalEpi epi
record ExtremalMono {A B} (f : A ⇒ B) : Set (o ⊔ ℓ ⊔ e) where
field
mono : Mono f
extremal : IsExtremalMono mono
| 25.083333
| 70
| 0.572536
|
3689c36514f8a5a1fadc2cef4368e85dfdd02b58
| 261
|
agda
|
Agda
|
test/Succeed/Issue4384.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue4384.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue4384.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --cubical --rewriting #-}
open import Agda.Builtin.Cubical.Path
open import Agda.Primitive.Cubical
data A : Set where
a : A
eq : a ≡ a
ok : ∀ i → eq i ≡ a
ok i j = eq (primIMin i (primINeg j))
{-# BUILTIN REWRITE _≡_ #-}
{-# REWRITE ok #-}
| 17.4
| 37
| 0.613027
|
9ae01399226f732a011a1efe4e9b179f69c80687
| 230
|
agda
|
Agda
|
Cubical/Data/Queue/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Data/Queue/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Data/Queue/Base.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --no-exact-split --safe #-}
module Cubical.Data.Queue.Base where
open import Cubical.Data.Queue.1List public
open import Cubical.Data.Queue.Truncated2List public
open import Cubical.Data.Queue.Untruncated2List public
| 32.857143
| 54
| 0.804348
|
0d9b4c5ccb2a99a52e6b21ce37677a917ab9187c
| 2,617
|
agda
|
Agda
|
src/fot/FOTC/Data/List/WF-Relation/LT-Length/PropertiesI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Data/List/WF-Relation/LT-Length/PropertiesI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Data/List/WF-Relation/LT-Length/PropertiesI.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Properties for the relation LTL
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.List.WF-Relation.LT-Length.PropertiesI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesI as Nat using ()
open import FOTC.Data.List
open import FOTC.Data.List.PropertiesI
open import FOTC.Data.List.WF-Relation.LT-Length
------------------------------------------------------------------------------
xs<[]→⊥ : ∀ {xs} → List xs → ¬ (LTL xs [])
xs<[]→⊥ Lxs xs<[] = lg-xs<lg-[]→⊥ Lxs xs<[]
x∷xs<y∷ys→xs<ys : ∀ {x xs y ys} → List xs → List ys →
LTL (x ∷ xs) (y ∷ ys) → LTL xs ys
x∷xs<y∷ys→xs<ys {x} {xs} {y} {ys} Lxs Lys x∷xs<y∷ys = Nat.Sx<Sy→x<y helper
where
helper : succ₁ (length xs) < succ₁ (length ys)
helper =
lt (succ₁ (length xs)) (succ₁ (length ys))
≡⟨ subst₂ (λ t t' → lt (succ₁ (length xs)) (succ₁ (length ys)) ≡ lt t t')
(sym (length-∷ x xs))
(sym (length-∷ y ys))
refl
⟩
lt (length (x ∷ xs)) (length (y ∷ ys))
≡⟨ x∷xs<y∷ys ⟩
true ∎
<-trans : ∀ {xs ys zs} → List xs → List ys → List zs →
LTL xs ys → LTL ys zs → LTL xs zs
<-trans Lxs Lys Lzs xs<ys ys<zs =
Nat.<-trans (lengthList-N Lxs) (lengthList-N Lys) (lengthList-N Lzs) xs<ys ys<zs
lg-xs≡lg-ys→ys<zx→xs<zs : ∀ {xs ys zs} → length xs ≡ length ys →
LTL ys zs → LTL xs zs
lg-xs≡lg-ys→ys<zx→xs<zs {xs} {ys} {zs} h ys<zs =
lt (length xs) (length zs)
≡⟨ subst (λ t → lt (length xs) (length zs) ≡ lt t (length zs)) h refl ⟩
lt (length ys) (length zs)
≡⟨ ys<zs ⟩
true ∎
xs<y∷ys→xs<ys∨lg-xs≡lg-ys : ∀ {xs y ys} → List xs → List ys →
LTL xs (y ∷ ys) →
LTL xs ys ∨ length xs ≡ length ys
xs<y∷ys→xs<ys∨lg-xs≡lg-ys {xs} {y} {ys} Lxs Lys xs<y∷ys =
Nat.x<Sy→x<y∨x≡y (lengthList-N Lxs) (lengthList-N Lys) helper
where
helper : length xs < succ₁ (length ys)
helper =
lt (length xs) (succ₁ (length ys))
≡⟨ subst (λ t → lt (length xs) (succ₁ (length ys)) ≡ lt (length xs) t)
(sym (length-∷ y ys))
refl
⟩
lt (length xs) (length (y ∷ ys))
≡⟨ xs<y∷ys ⟩
true ∎
| 35.364865
| 82
| 0.495606
|
1e6220ecb2344163c905f2b03863fddd78699e5e
| 899
|
agda
|
Agda
|
agda/InsertSort/Impl2/Correctness/Permutation/Base.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/InsertSort/Impl2/Correctness/Permutation/Base.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/InsertSort/Impl2/Correctness/Permutation/Base.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
open import Relation.Binary.Core
module InsertSort.Impl2.Correctness.Permutation.Base {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Data.List
open import Data.Sum
open import InsertSort.Impl2 _≤_ tot≤
open import List.Permutation.Base A
open import OList _≤_
lemma-forget-insert : {b : Bound} → (x : A) → (b≤x : LeB b (val x)) → (xs : OList b) → forget (insert b≤x xs) / x ⟶ forget xs
lemma-forget-insert x b≤x onil = /head
lemma-forget-insert x b≤x (:< {x = y} b≤y ys)
with tot≤ x y
... | inj₁ x≤y = /head
... | inj₂ y≤x = /tail (lemma-forget-insert x (lexy y≤x) ys)
theorem-insertSort∼ : (xs : List A) → xs ∼ forget (insertSort xs)
theorem-insertSort∼ [] = ∼[]
theorem-insertSort∼ (x ∷ xs) = ∼x /head (lemma-forget-insert x lebx (insertSort xs)) (theorem-insertSort∼ xs)
| 35.96
| 125
| 0.641824
|
8be83a61c776bb4bd17967d976173a45e5d4b974
| 400
|
agda
|
Agda
|
test/Succeed/Issue2573.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2573.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2573.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting #-}
open import Agda.Builtin.Equality
{-# BUILTIN REWRITE _≡_ #-}
data Bool : Set where true false : Bool
op : Bool → Set → Set
op false _ = Bool
op true A = A
postulate
id : Bool → Bool
id-comp : ∀ y → id y ≡ y
{-# REWRITE id-comp #-}
postulate
A : Set
law : (i : Bool) → op (id i) A ≡ Bool
{-# REWRITE law #-}
ok : (i : Bool) → op i A ≡ Bool
ok i = refl
| 16
| 39
| 0.57
|
7c48000ef756ff5483045971dd3335bd64c52a44
| 7,044
|
agda
|
Agda
|
Cubical/Data/Nat/Order.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Data/Nat/Order.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Data/Nat/Order.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 --no-exact-split --safe #-}
module Cubical.Data.Nat.Order where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Sigma
open import Cubical.Data.Sum as ⊎
open import Cubical.Data.Nat.Base
open import Cubical.Data.Nat.Properties
open import Cubical.Induction.WellFounded
open import Cubical.Relation.Nullary
infix 4 _≤_ _<_
_≤_ : ℕ → ℕ → Type₀
m ≤ n = Σ[ k ∈ ℕ ] k + m ≡ n
_<_ : ℕ → ℕ → Type₀
m < n = suc m ≤ n
data Trichotomy (m n : ℕ) : Type₀ where
lt : m < n → Trichotomy m n
eq : m ≡ n → Trichotomy m n
gt : n < m → Trichotomy m n
private
variable
k l m n : ℕ
private
witness-prop : ∀ j → isProp (j + m ≡ n)
witness-prop {m} {n} j = isSetℕ (j + m) n
m≤n-isProp : isProp (m ≤ n)
m≤n-isProp {m} {n} (k , p) (l , q)
= Σ≡Prop witness-prop lemma
where
lemma : k ≡ l
lemma = inj-+m (p ∙ (sym q))
zero-≤ : 0 ≤ n
zero-≤ {n} = n , +-zero n
suc-≤-suc : m ≤ n → suc m ≤ suc n
suc-≤-suc (k , p) = k , (+-suc k _) ∙ (cong suc p)
≤-+k : m ≤ n → m + k ≤ n + k
≤-+k {m} {k = k} (i , p)
= i , +-assoc i m k ∙ cong (_+ k) p
≤-k+ : m ≤ n → k + m ≤ k + n
≤-k+ {m} {n} {k}
= subst (_≤ k + n) (+-comm m k)
∘ subst (m + k ≤_) (+-comm n k)
∘ ≤-+k
pred-≤-pred : suc m ≤ suc n → m ≤ n
pred-≤-pred (k , p) = k , injSuc ((sym (+-suc k _)) ∙ p)
≤-refl : m ≤ m
≤-refl = 0 , refl
≤-suc : m ≤ n → m ≤ suc n
≤-suc (k , p) = suc k , cong suc p
≤-predℕ : predℕ n ≤ n
≤-predℕ {zero} = ≤-refl
≤-predℕ {suc n} = ≤-suc ≤-refl
≤-trans : k ≤ m → m ≤ n → k ≤ n
≤-trans {k} {m} {n} (i , p) (j , q) = i + j , l2 ∙ (l1 ∙ q)
where
l1 : j + i + k ≡ j + m
l1 = (sym (+-assoc j i k)) ∙ (cong (j +_) p)
l2 : i + j + k ≡ j + i + k
l2 = cong (_+ k) (+-comm i j)
≤-antisym : m ≤ n → n ≤ m → m ≡ n
≤-antisym {m} (i , p) (j , q) = (cong (_+ m) l3) ∙ p
where
l1 : j + i + m ≡ m
l1 = (sym (+-assoc j i m)) ∙ ((cong (j +_) p) ∙ q)
l2 : j + i ≡ 0
l2 = m+n≡n→m≡0 l1
l3 : 0 ≡ i
l3 = sym (snd (m+n≡0→m≡0×n≡0 l2))
≤-k+-cancel : k + m ≤ k + n → m ≤ n
≤-k+-cancel {k} {m} (l , p) = l , inj-m+ (sub k m ∙ p)
where
sub : ∀ k m → k + (l + m) ≡ l + (k + m)
sub k m = +-assoc k l m ∙ cong (_+ m) (+-comm k l) ∙ sym (+-assoc l k m)
≤-+k-cancel : m + k ≤ n + k → m ≤ n
≤-+k-cancel {m} {k} {n} (l , p) = l , cancelled
where
cancelled : l + m ≡ n
cancelled = inj-+m (sym (+-assoc l m k) ∙ p)
<-k+-cancel : k + m < k + n → m < n
<-k+-cancel {k} {m} {n} = ≤-k+-cancel ∘ subst (_≤ k + n) (sym (+-suc k m))
¬-<-zero : ¬ m < 0
¬-<-zero (k , p) = snotz ((sym (+-suc k _)) ∙ p)
¬m<m : ¬ m < m
¬m<m {m} = ¬-<-zero ∘ ≤-+k-cancel {k = m}
≤0→≡0 : n ≤ 0 → n ≡ 0
≤0→≡0 {zero} ineq = refl
≤0→≡0 {suc n} ineq = ⊥.rec (¬-<-zero ineq)
predℕ-≤-predℕ : m ≤ n → (predℕ m) ≤ (predℕ n)
predℕ-≤-predℕ {zero} {zero} ineq = ≤-refl
predℕ-≤-predℕ {zero} {suc n} ineq = zero-≤
predℕ-≤-predℕ {suc m} {zero} ineq = ⊥.rec (¬-<-zero ineq)
predℕ-≤-predℕ {suc m} {suc n} ineq = pred-≤-pred ineq
¬m+n<m : ¬ m + n < m
¬m+n<m {m} {n} = ¬-<-zero ∘ <-k+-cancel ∘ subst (m + n <_) (sym (+-zero m))
<-weaken : m < n → m ≤ n
<-weaken (k , p) = suc k , sym (+-suc k _) ∙ p
≤<-trans : l ≤ m → m < n → l < n
≤<-trans {l} {m} {n} (i , p) (j , q) = (j + i) , reason
where
reason : j + i + suc l ≡ n
reason = j + i + suc l ≡⟨ sym (+-assoc j i (suc l)) ⟩
j + (i + suc l) ≡⟨ cong (j +_) (+-suc i l) ⟩
j + (suc (i + l)) ≡⟨ cong (_+_ j ∘ suc) p ⟩
j + suc m ≡⟨ q ⟩
n ∎
<≤-trans : l < m → m ≤ n → l < n
<≤-trans {l} {m} {n} (i , p) (j , q) = j + i , reason
where
reason : j + i + suc l ≡ n
reason = j + i + suc l ≡⟨ sym (+-assoc j i (suc l)) ⟩
j + (i + suc l) ≡⟨ cong (j +_) p ⟩
j + m ≡⟨ q ⟩
n ∎
<-trans : l < m → m < n → l < n
<-trans p = ≤<-trans (<-weaken p)
<-asym : m < n → ¬ n ≤ m
<-asym m<n = ¬m<m ∘ <≤-trans m<n
Trichotomy-suc : Trichotomy m n → Trichotomy (suc m) (suc n)
Trichotomy-suc (lt m<n) = lt (suc-≤-suc m<n)
Trichotomy-suc (eq m=n) = eq (cong suc m=n)
Trichotomy-suc (gt n<m) = gt (suc-≤-suc n<m)
_≟_ : ∀ m n → Trichotomy m n
zero ≟ zero = eq refl
zero ≟ suc n = lt (n , +-comm n 1)
suc m ≟ zero = gt (m , +-comm m 1)
suc m ≟ suc n = Trichotomy-suc (m ≟ n)
<-split : m < suc n → (m < n) ⊎ (m ≡ n)
<-split {n = zero} = inr ∘ snd ∘ m+n≡0→m≡0×n≡0 ∘ snd ∘ pred-≤-pred
<-split {zero} {suc n} = λ _ → inl (suc-≤-suc zero-≤)
<-split {suc m} {suc n} = ⊎.map suc-≤-suc (cong suc) ∘ <-split ∘ pred-≤-pred
private
acc-suc : Acc _<_ n → Acc _<_ (suc n)
acc-suc a
= acc λ y y<sn
→ case <-split y<sn of λ
{ (inl y<n) → access a y y<n
; (inr y≡n) → subst _ (sym y≡n) a
}
<-wellfounded : WellFounded _<_
<-wellfounded zero = acc λ _ → ⊥.rec ∘ ¬-<-zero
<-wellfounded (suc n) = acc-suc (<-wellfounded n)
module _
(b₀ : ℕ)
(P : ℕ → Type₀)
(base : ∀ n → n < suc b₀ → P n)
(step : ∀ n → P n → P (suc b₀ + n))
where
open WFI (<-wellfounded)
private
dichotomy : ∀ b n → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m)
dichotomy b n
= case n ≟ b return (λ _ → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m)) of λ
{ (lt o) → inl o
; (eq p) → inr (0 , p ∙ sym (+-zero b))
; (gt (m , p)) → inr (suc m , sym p ∙ +-suc m b ∙ +-comm (suc m) b)
}
dichotomy<≡ : ∀ b n → (n<b : n < b) → dichotomy b n ≡ inl n<b
dichotomy<≡ b n n<b
= case dichotomy b n return (λ d → d ≡ inl n<b) of λ
{ (inl x) → cong inl (m≤n-isProp x n<b)
; (inr (m , p)) → ⊥.rec (<-asym n<b (m , sym (p ∙ +-comm b m)))
}
dichotomy+≡ : ∀ b m n → (p : n ≡ b + m) → dichotomy b n ≡ inr (m , p)
dichotomy+≡ b m n p
= case dichotomy b n return (λ d → d ≡ inr (m , p)) of λ
{ (inl n<b) → ⊥.rec (<-asym n<b (m , +-comm m b ∙ sym p))
; (inr (m' , q))
→ cong inr (Σ≡Prop (λ x → isSetℕ n (b + x)) (inj-m+ {m = b} (sym q ∙ p)))
}
b = suc b₀
lemma₁ : ∀{x y z} → x ≡ suc z + y → y < x
lemma₁ {y = y} {z} p = z , +-suc z y ∙ sym p
subStep : (n : ℕ) → (∀ m → m < n → P m) → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m) → P n
subStep n _ (inl l) = base n l
subStep n rec (inr (m , p))
= transport (cong P (sym p)) (step m (rec m (lemma₁ p)))
wfStep : (n : ℕ) → (∀ m → m < n → P m) → P n
wfStep n rec = subStep n rec (dichotomy b n)
wfStepLemma₀ : ∀ n (n<b : n < b) rec → wfStep n rec ≡ base n n<b
wfStepLemma₀ n n<b rec = cong (subStep n rec) (dichotomy<≡ b n n<b)
wfStepLemma₁ : ∀ n rec → wfStep (b + n) rec ≡ step n (rec n (lemma₁ refl))
wfStepLemma₁ n rec
= cong (subStep (b + n) rec) (dichotomy+≡ b n (b + n) refl)
∙ transportRefl _
+induction : ∀ n → P n
+induction = induction wfStep
+inductionBase : ∀ n → (l : n < b) → +induction n ≡ base n l
+inductionBase n l = induction-compute wfStep n ∙ wfStepLemma₀ n l _
+inductionStep : ∀ n → +induction (b + n) ≡ step n (+induction n)
+inductionStep n = induction-compute wfStep (b + n) ∙ wfStepLemma₁ n _
| 28.518219
| 84
| 0.482538
|
1a9c993fbbfd08efbead8128d7623f6ab381ba06
| 1,079
|
agda
|
Agda
|
agda-stdlib/src/Data/List/Relation/Binary/Equality/Propositional.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/List/Relation/Binary/Equality/Propositional.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/Relation/Binary/Equality/Propositional.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Pointwise equality over lists using propositional equality
------------------------------------------------------------------------
-- Note think carefully about using this module as pointwise
-- propositional equality can usually be replaced with propositional
-- equality.
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Data.List.Relation.Binary.Equality.Propositional {a} {A : Set a} where
open import Data.List.Base
import Data.List.Relation.Binary.Equality.Setoid as SetoidEquality
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------
-- Re-export everything from setoid equality
open SetoidEquality (P.setoid A) public
------------------------------------------------------------------------
-- ≋ is propositional
≋⇒≡ : _≋_ ⇒ _≡_
≋⇒≡ [] = P.refl
≋⇒≡ (P.refl ∷ xs≈ys) = P.cong (_ ∷_) (≋⇒≡ xs≈ys)
≡⇒≋ : _≡_ ⇒ _≋_
≡⇒≋ P.refl = ≋-refl
| 30.828571
| 77
| 0.511585
|
0421cecc065cd2bee1df5a19996bb4f04a5a4114
| 5,090
|
agda
|
Agda
|
examples/outdated-and-incorrect/iird/IID-Proof-Setup.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
examples/outdated-and-incorrect/iird/IID-Proof-Setup.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/outdated-and-incorrect/iird/IID-Proof-Setup.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
module IID-Proof-Setup where
open import LF
open import Identity
open import IID
open import IIDr
open import DefinitionalEquality
OPg : Set -> Set1
OPg I = OP I I
-- Encoding indexed inductive types as non-indexed types.
ε : {I : Set}(γ : OPg I) -> OPr I
ε (ι i) j = σ (i == j) (\_ -> ι ★)
ε (σ A γ) j = σ A (\a -> ε (γ a) j)
ε (δ H i γ) j = δ H i (ε γ j)
-- Adds a reflexivity proof.
g→rArgs : {I : Set}(γ : OPg I)(U : I -> Set)
(a : Args γ U) ->
rArgs (ε γ) U (index γ U a)
g→rArgs (ι e) U arg = (refl , ★)
g→rArgs (σ A γ) U arg = (π₀ arg , g→rArgs (γ (π₀ arg)) U (π₁ arg))
g→rArgs (δ H i γ) U arg = (π₀ arg , g→rArgs γ U (π₁ arg))
-- Strips the equality proof.
r→gArgs : {I : Set}(γ : OPg I)(U : I -> Set)
(i : I)(a : rArgs (ε γ) U i) ->
Args γ U
r→gArgs (ι i) U j _ = ★
r→gArgs (σ A γ) U j arg = (π₀ arg , r→gArgs (γ (π₀ arg)) U j (π₁ arg))
r→gArgs (δ H i γ) U j arg = (π₀ arg , r→gArgs γ U j (π₁ arg))
-- Converting an rArgs to a gArgs and back is (provably, not definitionally)
-- the identity.
r←→gArgs-subst :
{I : Set}(γ : OPg I)(U : I -> Set)
(C : (i : I) -> rArgs (ε γ) U i -> Set)
(i : I)(a : rArgs (ε γ) U i) ->
(C (index γ U (r→gArgs γ U i a))
(g→rArgs γ U (r→gArgs γ U i a))
) -> C i a
r←→gArgs-subst {I} (ι i) U C j arg m =
elim== i (\k q -> C k (q , ★)) m j (π₀ arg)
r←→gArgs-subst (σ A γ) U C j arg m =
r←→gArgs-subst (γ (π₀ arg)) U (\i c -> C i (π₀ arg , c)) j (π₁ arg) m
r←→gArgs-subst (δ H i γ) U C j arg m =
r←→gArgs-subst γ U (\i c -> C i (π₀ arg , c)) j (π₁ arg) m
-- r←→gArgs-subst eliminates the identity proof stored in the rArgs. If this proof is
-- by reflexivity r←→gArgs-subst is a definitional identity. This is the case
-- when a = g→rArgs a'
r←→gArgs-subst-identity :
{I : Set}(γ : OPg I)(U : I -> Set)
(C : (i : I) -> rArgs (ε γ) U i -> Set)
(a' : Args γ U) ->
let a = g→rArgs γ U a'
i = index γ U a' in
(h : C (index γ U (r→gArgs γ U i a))
(g→rArgs γ U (r→gArgs γ U i a))
) -> r←→gArgs-subst γ U C i a h ≡ h
r←→gArgs-subst-identity (ι i) U C _ h = refl-≡
r←→gArgs-subst-identity (σ A γ) U C arg h = r←→gArgs-subst-identity (γ (π₀ arg)) U C' (π₁ arg) h
where C' = \i c -> C i (π₀ arg , c)
r←→gArgs-subst-identity (δ H i γ) U C arg h = r←→gArgs-subst-identity γ U C' (π₁ arg) h
where C' = \i c -> C i (π₀ arg , c)
-- Going the other way around is definitionally the identity.
g←→rArgs-identity :
{I : Set}(γ : OPg I)(U : I -> Set)
(a : Args γ U) ->
r→gArgs γ U (index γ U a) (g→rArgs γ U a) ≡ a
g←→rArgs-identity (ι i) U _ = refl-≡
g←→rArgs-identity (σ A γ) U arg = cong-≡ (\ ∙ -> (π₀ arg , ∙)) (g←→rArgs-identity (γ (π₀ arg)) U (π₁ arg))
g←→rArgs-identity (δ H i γ) U arg = cong-≡ (\ ∙ -> (π₀ arg , ∙)) (g←→rArgs-identity γ U (π₁ arg))
-- Corresponding conversion functions for assumptions to inductive occurrences.
-- Basically an identity function.
g→rIndArg : {I : Set}(γ : OPg I)(U : I -> Set)
(i : I)(a : rArgs (ε γ) U i) ->
IndArg γ U (r→gArgs γ U i a) -> IndArg (ε γ i) U a
g→rIndArg (ι j) U i _ ()
g→rIndArg (σ A γ) U i arg v = g→rIndArg (γ (π₀ arg)) U i (π₁ arg) v
g→rIndArg (δ A j γ) U i arg (inl a) = inl a
g→rIndArg (δ A j γ) U i arg (inr v) = inr (g→rIndArg γ U i (π₁ arg) v)
-- Basically we can substitute general inductive occurences for the encoded
-- restricted inductive occurrences.
g→rIndArg-subst :
{I : Set}(γ : OPg I)(U : I -> Set)
(C : (i : I) -> U i -> Set)
(i : I)(a : rArgs (ε γ) U i)
(v : IndArg γ U (r→gArgs γ U i a)) ->
C (IndIndex (ε γ i) U a (g→rIndArg γ U i a v))
(Ind (ε γ i) U a (g→rIndArg γ U i a v)) ->
C (IndIndex γ U (r→gArgs γ U i a) v)
(Ind γ U (r→gArgs γ U i a) v)
g→rIndArg-subst (ι j) U C i _ () h
g→rIndArg-subst (σ A γ) U C i arg v h = g→rIndArg-subst (γ (π₀ arg)) U C i (π₁ arg) v h
g→rIndArg-subst (δ A j γ) U C i arg (inl a) h = h
g→rIndArg-subst (δ A j γ) U C i arg (inr v) h = g→rIndArg-subst γ U C i (π₁ arg) v h
-- g→rIndArg-subst is purely book-keeping. On the object level it's definitional identity.
g→rIndArg-subst-identity :
{I : Set}(γ : OPg I)(U : I -> Set)
(C : (i : I) -> U i -> Set)
(i : I)(a : rArgs (ε γ) U i)
(v : IndArg γ U (r→gArgs γ U i a))
(h : C (IndIndex (ε γ i) U a (g→rIndArg γ U i a v))
(Ind (ε γ i) U a (g→rIndArg γ U i a v))
) -> g→rIndArg-subst γ U C i a v h ≡ h
g→rIndArg-subst-identity (ι j) U C i _ () h
g→rIndArg-subst-identity (σ A γ) U C i arg v h =
g→rIndArg-subst-identity (γ (π₀ arg)) U C i (π₁ arg) v h
g→rIndArg-subst-identity (δ A j γ) U C i arg (inl a) h = refl-≡
g→rIndArg-subst-identity (δ A j γ) U C i arg (inr v) h =
g→rIndArg-subst-identity γ U C i (π₁ arg) v h
-- And finally conversion of induction hypotheses. This goes the other direction.
r→gIndHyp :
{I : Set}(γ : OPg I)(U : I -> Set)
(C : (i : I) -> U i -> Set)
(i : I)(a : rArgs (ε γ) U i) ->
IndHyp (ε γ i) U C a -> IndHyp γ U C (r→gArgs γ U i a)
r→gIndHyp γ U C i a h v = g→rIndArg-subst γ U C i a v (h (g→rIndArg γ U i a v))
| 38.854962
| 108
| 0.548723
|
7c8fc7167b9f7de8de6de4fd41a4580244548b5f
| 2,433
|
agda
|
Agda
|
EuclideanDomain.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
EuclideanDomain.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
EuclideanDomain.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
-- This file defines the Euclidean Domain structure.
{-# OPTIONS --without-K --safe #-}
module EuclideanDomain where
-- We comply to the definition format in stdlib, i.e. define an
-- IsSomething predicate then define the bundle.
open import Relation.Binary using (Rel; Setoid; IsEquivalence)
module Structures
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality relation
where
open import Algebra.Structures _≈_
open import Algebra.Core
open import Algebra.Definitions _≈_
import Algebra.Consequences.Setoid as Consequences
open import Data.Product using (_,_; proj₁; proj₂)
open import Level using (_⊔_)
open import Data.Nat using (ℕ ; _<_)
open import Data.Product using (∃ ; _×_)
open import Relation.Nullary using (¬_)
-- We only require leftcancellative since we have required the
-- domain to be commutative. An Euclidean domain is a commutative
-- domain with a div, mod, and rank function satisfy euc-eq and
-- euc-rank.
record IsEuclideanDomain
(+ * : Op₂ A) (- : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
isCommutativeRing : IsCommutativeRing + * - 0# 1#
*-alc : AlmostLeftCancellative 0# *
div : ∀ (n d : A) -> ¬ d ≈ 0# -> A
mod : ∀ (n d : A) -> ¬ d ≈ 0# -> A
rank : A → ℕ
euc-eq : ∀ (n d : A) -> (n0 : ¬ d ≈ 0#) ->
let r = mod n d n0 in let q = div n d n0 in
n ≈ + r (* q d)
euc-rank : ∀ (n d : A) -> (n0 : ¬ d ≈ 0#) ->
let r = mod n d n0 in let q = div n d n0 in
rank r < rank d
module Bundles where
open Structures
open import Algebra.Core
open import Algebra.Structures
open import Relation.Binary
open import Function.Base
import Relation.Nullary as N
open import Level
record EuclideanDomainBundle c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 -_
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
-_ : Op₁ Carrier
0# : Carrier
1# : Carrier
isEuclideanDomain : IsEuclideanDomain _≈_ _+_ _*_ -_ 0# 1#
open IsEuclideanDomain isEuclideanDomain public
| 33.328767
| 70
| 0.560625
|
22c1d2b683ce415b6cb08bce25a075519d2f5128
| 3,555
|
agda
|
Agda
|
StructurallyRecursiveDescentParsing/DepthFirst.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 7
|
2016-12-13T05:23:14.000Z
|
2021-06-22T05:35:31.000Z
|
StructurallyRecursiveDescentParsing/DepthFirst.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 1
|
2018-01-22T22:21:41.000Z
|
2018-01-24T16:39:37.000Z
|
StructurallyRecursiveDescentParsing/DepthFirst.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- A depth-first backend
------------------------------------------------------------------------
-- Based on the parser combinators in Wadler's "How to Replace Failure
-- by a List of Successes".
module StructurallyRecursiveDescentParsing.DepthFirst where
open import Data.Bool
open import Data.Product as Prod
open import Data.BoundedVec.Inefficient
import Data.List as L; open L using (List)
import Data.List.Categorical
open import Data.Nat
open import Function
open import Category.Applicative.Indexed
open import Category.Monad.Indexed
open import Category.Monad.State
open import Coinduction
import Level
open import StructurallyRecursiveDescentParsing.Simplified
------------------------------------------------------------------------
-- Parser monad
private
P : Set → IFun ℕ Level.zero
P Tok = IStateT (BoundedVec Tok) List
open module M₁ {Tok : Set} =
RawIMonadPlus (StateTIMonadPlus (BoundedVec Tok)
Data.List.Categorical.monadPlus)
using ()
renaming ( return to return′
; _>>=_ to _>>=′_
; _>>_ to _>>′_
; ∅ to fail′
; _∣_ to _∣′_
)
open module M₂ {Tok : Set} =
RawIMonadState (StateTIMonadState (BoundedVec Tok)
Data.List.Categorical.monad)
using ()
renaming ( get to get′
; put to put′
; modify to modify′
)
------------------------------------------------------------------------
-- Run function for the parsers
-- For every successful parse the run function returns the remaining
-- string. (Since there can be several successful parses a list of
-- strings is returned.)
-- This function is structurally recursive with respect to the
-- following lexicographic measure:
--
-- 1) The upper bound of the length of the input string.
-- 2) The parser's proper left corner tree.
mutual
parse↓ : ∀ {Tok e R} n → Parser Tok e R →
P Tok n (if e then n else pred n) R
parse↓ n (return x) = return′ x
parse↓ n fail = fail′
parse↓ n (_∣_ {true} p₁ p₂) = parse↓ n p₁ ∣′ parse↑ n p₂
parse↓ n (_∣_ {false} {true} p₁ p₂) = parse↑ n p₁ ∣′ parse↓ n p₂
parse↓ n (_∣_ {false} {false} p₁ p₂) = parse↓ n p₁ ∣′ parse↓ n p₂
parse↓ n (p₁ ?>>= p₂) = parse↓ n p₁ >>=′ λ x → parse↓ n (p₂ x)
parse↓ zero (p₁ !>>= p₂) = fail′
parse↓ (suc n) (p₁ !>>= p₂) = parse↓ (suc n) p₁ >>=′ λ x → parse↑ n (♭ (p₂ x))
parse↓ n token = get′ >>=′ eat
where
eat : ∀ {Tok n} → BoundedVec Tok n → P Tok n (pred n) Tok
eat [] = fail′
eat (c ∷ s) = put′ s >>′ return′ c
parse↑ : ∀ {e Tok R} n → Parser Tok e R → P Tok n n R
parse↑ {true} n p = parse↓ n p
parse↑ {false} zero p = fail′
parse↑ {false} (suc n) p = parse↓ (suc n) p >>=′ λ r →
modify′ ↑ >>′
return′ r
-- Exported run function.
parse : ∀ {Tok i R} → Parser Tok i R → List Tok → List (R × List Tok)
parse p s = L.map (Prod.map id toList) (parse↓ _ p (fromList s))
-- A variant which only returns parses which leave no remaining input.
parseComplete : ∀ {Tok i R} → Parser Tok i R → List Tok → List R
parseComplete p s =
L.map proj₁ (L.boolFilter (L.null ∘ proj₂) (parse p s))
| 35.55
| 95
| 0.5173
|
d15dff65fb964982477d94db1bc54530326e9b3f
| 290
|
agda
|
Agda
|
test/Fail/Issue1976-constraints2.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1976-constraints2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1976-constraints2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2016-12-31, re issue #1976
-- Allow projection pattern disambiguation by parameters
postulate
A B : Set
module M (_ : Set) where
record R : Set₂ where
field
F : Set₁
open R public
module ShouldFail where
open M _
open M A
test : M.R B
F test = Set
| 13.809524
| 56
| 0.651724
|
7c44bf48fd8a932a3a0cb9d1bca78815351aea8a
| 126
|
agda
|
Agda
|
test/Succeed/Issue2320.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue2320.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue2320.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
record R₁ : Set₁ where
field
A : Set
open R₁ ⦃ … ⦄
record R₂ : Set₁ where
field
⦃ r₁ ⦄ : R₁
B : Set
B = A
| 9
| 22
| 0.507937
|
43e5ac67ca4fb846a1faca7cfe0537e05196793d
| 128
|
agda
|
Agda
|
test/Fail/ShouldBeApplicationOf.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/ShouldBeApplicationOf.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/ShouldBeApplicationOf.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module ShouldBeApplicationOf where
data One : Set where one : One
data Two : Set where two : Two
f : One -> Two
f two = two
| 12.8
| 34
| 0.6875
|
43677e8ab235078ba00a19e0c73da0c203bb01a7
| 227
|
agda
|
Agda
|
base/agda/Base/Prelude.agda
|
FreeProving/free-compiler
|
6931b9ca652a185a92dd824373f092823aea4ea9
|
[
"BSD-3-Clause"
] | 36
|
2020-02-06T11:03:34.000Z
|
2021-08-21T13:38:23.000Z
|
base/agda/Base/Prelude.agda
|
FreeProving/free-compiler
|
6931b9ca652a185a92dd824373f092823aea4ea9
|
[
"BSD-3-Clause"
] | 120
|
2020-04-09T09:40:39.000Z
|
2020-12-08T07:46:01.000Z
|
base/agda/Base/Prelude.agda
|
FreeProving/free-compiler
|
6931b9ca652a185a92dd824373f092823aea4ea9
|
[
"BSD-3-Clause"
] | 3
|
2020-04-08T11:23:46.000Z
|
2021-05-14T07:48:41.000Z
|
module Base.Prelude where
open import Base.Prelude.Bool public
open import Base.Prelude.Integer public
open import Base.Prelude.List public
open import Base.Prelude.Pair public
open import Base.Prelude.Unit public
| 28.375
| 39
| 0.792952
|
7c406e489f98fd747a292c1c3eb9fed081c5c056
| 568
|
agda
|
Agda
|
test/Succeed/Issue1009.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1009.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1009.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- 2013-12-28 Andreas, issue reported by Christian Sattler
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS -v tc.cc:15 #-} -- Keep! Debug printing triggered the problem.
record Σ (A : Set) (B : A → Set) : Set where
field
fst : A
snd : B fst
test : {A : Set} → Σ A (λ {_ → A})
test = _
-- This used to trigger an internal error
-- (funnily only at -v tc.cc:15 verbosity)
-- because adding the clause to an
-- extended lambda failed. Reason:
-- Extended lambda was registered as Axiom
-- during first checking, not Defn as
-- checkFunDef' now expects.
| 27.047619
| 74
| 0.660211
|
7c21f2d119a34e943cd17288ae55e73126fff28a
| 727
|
agda
|
Agda
|
metatheory/test/StringLiteral.agda
|
greggdourgarian/plutus
|
07a2fbef515b988ca3401d38e1464a36ca80b641
|
[
"Apache-2.0"
] | 1
|
2019-02-22T12:34:17.000Z
|
2019-02-22T12:34:17.000Z
|
metatheory/test/StringLiteral.agda
|
greggdourgarian/plutus
|
07a2fbef515b988ca3401d38e1464a36ca80b641
|
[
"Apache-2.0"
] | 1
|
2019-02-06T12:42:31.000Z
|
2019-02-06T12:42:31.000Z
|
metatheory/test/StringLiteral.agda
|
greggdourgarian/plutus
|
07a2fbef515b988ca3401d38e1464a36ca80b641
|
[
"Apache-2.0"
] | null | null | null |
module test.StringLiteral where
open import Type
open import Declarative
open import Builtin
open import Builtin.Constant.Type
open import Builtin.Constant.Term Ctx⋆ Kind * # _⊢⋆_ con size⋆
-- plutus/language-plutus-core/test/data/stringLiteral.plc
postulate str1 : ByteString
{-# FOREIGN GHC import qualified Data.ByteString.Lazy.Char8 as BS #-}
{-# COMPILE GHC str1 = BS.pack "4321758fabce1aa4780193f" #-}
open import Relation.Binary.PropositionalEquality
open import Agda.Builtin.TrustMe
lemma1 : length str1 ≡ 23
lemma1 = primTrustMe
open import Data.Nat
lemma1' : BoundedB 100 str1
lemma1' rewrite lemma1 = gen _ _ _
stringLit : ∀{Γ} → Γ ⊢ con bytestring (size⋆ 100)
stringLit = con (bytestring 100 str1 lemma1')
| 25.964286
| 69
| 0.766162
|
7c1a66f17b14de6ad54a98ed96dfb6612885bbac
| 12,342
|
agda
|
Agda
|
Preservation.agda
|
danelahman/aeff-agda
|
71ebed9f90a3eb37ae6cd209457bae23a4d122d1
|
[
"MIT"
] | 4
|
2020-07-17T00:15:00.000Z
|
2021-03-22T22:48:48.000Z
|
Preservation.agda
|
danelahman/aeff-agda
|
71ebed9f90a3eb37ae6cd209457bae23a4d122d1
|
[
"MIT"
] | null | null | null |
Preservation.agda
|
danelahman/aeff-agda
|
71ebed9f90a3eb37ae6cd209457bae23a4d122d1
|
[
"MIT"
] | null | null | null |
open import Data.List hiding ([_]) renaming (_∷_ to _∷ₗ_)
open import Data.Maybe
open import Data.Product
open import AEff
open import EffectAnnotations
open import Renamings
open import Substitutions
open import Types
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Relation.Nullary
module Preservation where
-- BINDING CONTEXTS
BCtx = List VType
-- WELL-TYPED EVALUATION CONTEXTS
data _⊢E[_]⦂_ (Γ : Ctx) : (Δ : BCtx) → CType → Set where
[-] : {C : CType} →
-------------
Γ ⊢E[ [] ]⦂ C
let=_`in_ : {Δ : BCtx}
{X Y : VType}
{o : O}
{i : I} →
Γ ⊢E[ Δ ]⦂ X ! (o , i) →
Γ ∷ X ⊢M⦂ Y ! (o , i) →
------------------------
Γ ⊢E[ Δ ]⦂ Y ! (o , i)
↑ : {Δ : BCtx}
{X : VType}
{o : O}
{i : I} →
(op : Σₛ) →
op ∈ₒ o →
Γ ⊢V⦂ ``(payload op) →
Γ ⊢E[ Δ ]⦂ X ! (o , i) →
------------------------
Γ ⊢E[ Δ ]⦂ X ! (o , i)
↓ : {Δ : BCtx}
{X : VType}
{o : O}
{i : I}
(op : Σₛ) →
Γ ⊢V⦂ ``(payload op) →
Γ ⊢E[ Δ ]⦂ X ! (o , i) →
---------------------------
Γ ⊢E[ Δ ]⦂ X ! op ↓ₑ (o , i)
promise_∣_↦_`in_ : {Δ : BCtx}
{X Y : VType}
{o o' : O}
{i i' : I} →
(op : Σₛ) →
lkpᵢ op i ≡ just (o' , i') →
Γ ∷ ``(payload op) ⊢M⦂ ⟨ X ⟩ ! (o' , i') →
Γ ∷ ⟨ X ⟩ ⊢E[ Δ ]⦂ Y ! (o , i) →
------------------------------------------
Γ ⊢E[ X ∷ₗ Δ ]⦂ Y ! (o , i)
coerce : {Δ : BCtx}
{X : VType}
{o o' : O}
{i i' : I} →
o ⊑ₒ o' →
i ⊑ᵢ i' →
Γ ⊢E[ Δ ]⦂ X ! (o , i) →
------------------------
Γ ⊢E[ Δ ]⦂ X ! (o' , i')
-- MERGING AN ORDINARY CONTEXT AND A BINDING CONTEXT
infix 30 _⋈_
_⋈_ : Ctx → BCtx → Ctx
Γ ⋈ [] = Γ
Γ ⋈ (X ∷ₗ Δ) = (Γ ∷ ⟨ X ⟩) ⋈ Δ
-- FINDING THE TYPE OF THE HOLE OF A WELL-TYPED EVALUATION CONTEXT
hole-ty-e : {Γ : Ctx} {Δ : BCtx} {C : CType} → Γ ⊢E[ Δ ]⦂ C → CType
hole-ty-e {_} {_} {C} [-] =
C
hole-ty-e (let= E `in M) =
hole-ty-e E
hole-ty-e (↑ op p V E) =
hole-ty-e E
hole-ty-e (↓ op V E) =
hole-ty-e E
hole-ty-e (promise op ∣ p ↦ M `in E) =
hole-ty-e E
hole-ty-e (coerce p q E) =
hole-ty-e E
-- FILLING A WELL-TYPED EVALUATION CONTEXT
{- LEMMA 3.5 -}
infix 30 _[_]
_[_] : {Γ : Ctx} {Δ : BCtx} {C : CType} → (E : Γ ⊢E[ Δ ]⦂ C) → Γ ⋈ Δ ⊢M⦂ (hole-ty-e E) → Γ ⊢M⦂ C
[-] [ M ] =
M
(let= E `in N) [ M ] =
let= (E [ M ]) `in N
↑ op p V E [ M ] =
↑ op p V (E [ M ])
↓ op V E [ M ] =
↓ op V (E [ M ])
(promise op ∣ p ↦ N `in E) [ M ] =
promise op ∣ p ↦ N `in (E [ M ])
coerce p q E [ M ] =
coerce p q (E [ M ])
-- STRENGTHENING OF GROUND VALUES WRT BOUND PROMISES
strengthen-var : {Γ : Ctx} → (Δ : BCtx) → {A : BType} → `` A ∈ Γ ⋈ Δ → `` A ∈ Γ
strengthen-var [] x = x
strengthen-var (y ∷ₗ Δ) x with strengthen-var Δ x
... | Tl p = p
strengthen-val : {Γ : Ctx} {Δ : BCtx} {A : BType} → Γ ⋈ Δ ⊢V⦂ `` A → Γ ⊢V⦂ `` A
strengthen-val {_} {Δ} (` x) =
` strengthen-var Δ x
strengthen-val (``_ c) =
``_ c
strengthen-val-[] : {Γ : Ctx}
{A : BType} →
(V : Γ ⋈ [] ⊢V⦂ `` A) →
--------------------
strengthen-val {Δ = []} V ≡ V
strengthen-val-[] (` x) =
refl
strengthen-val-[] (``_ c) =
refl
-- SMALL-STEP OPERATIONAL SEMANTICS FOR WELL-TYPED COMPUTATIONS
-- (ADDITIONALLY SERVES AS THE PRESERVATION THEOREM)
{- THEOREM 3.6 -}
infix 10 _↝_
data _↝_ {Γ : Ctx} : {C : CType} → Γ ⊢M⦂ C → Γ ⊢M⦂ C → Set where
-- COMPUTATIONAL RULES
apply : {X : VType}
{C : CType} →
(M : Γ ∷ X ⊢M⦂ C) →
(V : Γ ⊢V⦂ X) →
----------------------
(ƛ M) · V
↝
M [ id-subst [ V ]s ]m
let-return : {X Y : VType}
{o : O}
{i : I} →
(V : Γ ⊢V⦂ X) →
(N : Γ ∷ X ⊢M⦂ Y ! (o , i)) →
-----------------------------
let= (return V) `in N
↝
N [ id-subst [ V ]s ]m
let-↑ : {X Y : VType}
{o : O}
{i : I}
{op : Σₛ} →
(p : op ∈ₒ o) →
(V : Γ ⊢V⦂ ``(payload op)) →
(M : Γ ⊢M⦂ X ! (o , i)) →
(N : Γ ∷ X ⊢M⦂ Y ! (o , i)) →
-----------------------------
let= (↑ op p V M) `in N
↝
↑ op p V (let= M `in N)
let-promise : {X Y Z : VType}
{o o' : O}
{i i' : I}
{op : Σₛ} →
(p : lkpᵢ op i ≡ just (o' , i')) →
(M₁ : Γ ∷ ``(payload op) ⊢M⦂ ⟨ X ⟩ ! (o' , i')) →
(M₂ : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)) →
(N : Γ ∷ Y ⊢M⦂ Z ! (o , i)) →
---------------------------------------------------------------------------
let= (promise op ∣ p ↦ M₁ `in M₂) `in N
↝
(promise op ∣ p ↦ M₁ `in (let= M₂ `in (M-rename (comp-ren exchange wk₁) N)))
letrec-unfold : {X : VType}
{C D : CType}
(M : Γ ∷ (X ⇒ C) ∷ X ⊢M⦂ C) →
(N : Γ ∷ (X ⇒ C) ⊢M⦂ D) →
----------------------------------------
(letrec M `in N)
↝
N [ id-subst [ ƛ (letrec M-rename wk₃ M `in M-rename exchange M) ]s ]m
promise-↑ : {X Y : VType}
{o o' : O}
{i i' : I}
{op op' : Σₛ} →
(p : lkpᵢ op i ≡ just (o' , i')) →
(q : op' ∈ₒ o) →
(V : Γ ∷ ⟨ X ⟩ ⊢V⦂ ``(payload op')) →
(M : Γ ∷ ``(payload op) ⊢M⦂ ⟨ X ⟩ ! (o' , i')) →
(N : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)) →
--------------------------------------------
(promise op ∣ p ↦ M `in (↑ op' q V N))
↝
↑ op' q (strengthen-val {Δ = X ∷ₗ []} V) (promise op ∣ p ↦ M `in N)
↓-return : {X : VType}
{o : O}
{i : I}
{op : Σₛ} →
(V : Γ ⊢V⦂ ``(payload op)) →
(W : Γ ⊢V⦂ X) →
----------------------------------------------------------------
↓ {o = o} {i = i} op V (return W)
↝
return {o = proj₁ (op ↓ₑ (o , i))} {i = proj₂ (op ↓ₑ (o , i))} W
↓-↑ : {X : VType}
{o : O}
{i : I}
{op : Σₛ}
{op' : Σₛ} →
(p : op' ∈ₒ o) →
(V : Γ ⊢V⦂ ``(payload op)) →
(W : Γ ⊢V⦂ ``(payload op')) →
(M : Γ ⊢M⦂ X ! (o , i)) →
-------------------------------
↓ op V (↑ op' p W M)
↝
↑ op' (↓ₑ-⊑ₒ op' p) W (↓ op V M)
↓-promise-op : {X Y : VType}
{o o' : O}
{i i' : I}
{op : Σₛ} →
(p : lkpᵢ op i ≡ just (o' , i')) →
(V : Γ ⊢V⦂ ``(payload op)) →
(M : Γ ∷ ``(payload op) ⊢M⦂ ⟨ X ⟩ ! (o' , i')) →
(N : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)) →
---------------------------------------------------------------------------------------
↓ op V (promise op ∣ p ↦ M `in N )
↝
(let= (coerce (↓ₑ-⊑ₒ-o' {o} p) (↓ₑ-⊑ₒ-i' {o} p) (M [ id-subst [ V ]s ]m)) `in
↓ op (V-rename wk₁ V) ((M-rename (comp-ren exchange wk₁) N) [ id-subst [ ` Hd ]s ]m))
↓-promise-op' : {X Y : VType}
{o o' : O}
{i i' : I}
{op op' : Σₛ} →
(p : ¬ op ≡ op') →
(q : lkpᵢ op' i ≡ just (o' , i')) →
(V : Γ ⊢V⦂ ``(payload op)) →
(M : Γ ∷ ``(payload op') ⊢M⦂ ⟨ X ⟩ ! (o' , i')) →
(N : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)) →
------------------------------------------------------------------------------------------
↓ op V (promise op' ∣ q ↦ M `in N )
↝
promise_∣_↦_`in_ {o' = proj₁ (lkpᵢ-↓ₑ-neq {o = o} {i = i} p q)}
{i' = proj₁ (proj₂ (lkpᵢ-↓ₑ-neq {o = o} {i = i} p q))}
op'
(proj₁ (proj₂ (proj₂ (lkpᵢ-↓ₑ-neq {o = o} {i = i} p q))))
(coerce (proj₁ (proj₂ (proj₂ (proj₂ (lkpᵢ-↓ₑ-neq {o = o} {i = i} p q)))))
(proj₂ (proj₂ (proj₂ (proj₂ (lkpᵢ-↓ₑ-neq {o = o} {i = i} p q)))))
M)
(↓ op (V-rename wk₁ V) N)
await-promise : {X : VType}
{C : CType} →
(V : Γ ⊢V⦂ X) →
(M : Γ ∷ X ⊢M⦂ C) →
--------------------
await ⟨ V ⟩ until M
↝
M [ id-subst [ V ]s ]m
-- EVALUATION CONTEXT RULE
context : {Δ : BCtx}
{C : CType} →
(E : Γ ⊢E[ Δ ]⦂ C) →
{M N : Γ ⋈ Δ ⊢M⦂ (hole-ty-e E)} →
M ↝ N →
-------------------------------
E [ M ] ↝ E [ N ]
-- COERCION RULES
-- (THE RESULT OF WORKING WITH WELL-TYPED SYNTAX AND MAKING SUBSUMPTION INTO AN EXPLICIT COERCION)
coerce-return : {X : VType}
{o o' : O}
{i i' : I}
{p : o ⊑ₒ o'}
{q : i ⊑ᵢ i'} →
(V : Γ ⊢V⦂ X) →
--------------------------------
coerce p q (return V) ↝ return V
coerce-↑ : {X : VType}
{o o' : O}
{i i' : I}
{p : o ⊑ₒ o'}
{q : i ⊑ᵢ i'}
{op : Σₛ} →
(r : op ∈ₒ o) →
(V : Γ ⊢V⦂ ``(payload op)) →
(M : Γ ⊢M⦂ X ! (o , i)) →
-------------------------------
coerce p q (↑ op r V M)
↝
↑ op (p op r) V (coerce p q M)
coerce-promise : {X Y : VType}
{o o' o'' : O}
{i i' i'' : I}
{p : o ⊑ₒ o'}
{q : i ⊑ᵢ i'}
{op : Σₛ} →
(r : lkpᵢ op i ≡ just (o'' , i''))
(M : Γ ∷ ``(payload op) ⊢M⦂ ⟨ X ⟩ ! (o'' , i'')) →
(N : Γ ∷ ⟨ X ⟩ ⊢M⦂ Y ! (o , i)) →
------------------------------------------------------------------
coerce p q (promise op ∣ r ↦ M `in N)
↝
promise_∣_↦_`in_ {o' = lkpᵢ-nextₒ q r}
{i' = lkpᵢ-nextᵢ q r}
op
(lkpᵢ-next-eq q r)
(coerce (lkpᵢ-next-⊑ₒ q r) (lkpᵢ-next-⊑ᵢ q r) M)
(coerce p q N)
| 34.571429
| 110
| 0.259682
|
35ed10549a54a07e82ecbaa41495d67f7be829e9
| 1,315
|
agda
|
Agda
|
test/Succeed/Issue1264.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue1264.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue1264.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- Andreas, 2014-08-30, reported by asr
-- All of the following corecursive functions from Data.Stream
-- should pass the termination checker.
{-# OPTIONS --without-K #-}
-- {-# OPTIONS -v term:20 #-}
open import Common.Coinduction
open import Common.Prelude renaming (Nat to ℕ) hiding (_∷_; map)
infixr 5 _∷_
data Stream (A : Set) : Set where
_∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A
map : ∀ {A B} → (A → B) → Stream A → Stream B
map f (x ∷ xs) = f x ∷ ♯ map f (♭ xs)
zipWith : ∀ {A B C} →
(A → B → C) → Stream A → Stream B → Stream C
zipWith _∙_ (x ∷ xs) (y ∷ ys) = (x ∙ y) ∷ ♯ zipWith _∙_ (♭ xs) (♭ ys)
drop : ∀ {A} → ℕ → Stream A → Stream A
drop zero xs = xs
drop (suc n) (x ∷ xs) = drop n (♭ xs)
repeat : ∀ {A} → A → Stream A
repeat x = x ∷ ♯ repeat x
iterate : ∀ {A} → (A → A) → A → Stream A
iterate f x = x ∷ ♯ iterate f (f x)
-- Interleaves the two streams.
infixr 5 _⋎_
_⋎_ : ∀ {A} → Stream A → Stream A → Stream A
(x ∷ xs) ⋎ ys = x ∷ ♯ (ys ⋎ ♭ xs)
mutual
-- Takes every other element from the stream, starting with the
-- first one.
evens : ∀ {A} → Stream A → Stream A
evens (x ∷ xs) = x ∷ ♯ odds (♭ xs)
-- Takes every other element from the stream, starting with the
-- second one.
odds : ∀ {A} → Stream A → Stream A
odds (x ∷ xs) = evens (♭ xs)
| 24.811321
| 69
| 0.563498
|
3722377e712b3d0ecf7d803f3eddc37cdc0f0b4a
| 3,603
|
agda
|
Agda
|
test/LibSucceed/Issue846/OldDivMod.agda
|
vlopezj/agda
|
ff4d89e75970cf27599fb9f572bd43c9455cbb56
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
test/LibSucceed/Issue846/OldDivMod.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/LibSucceed/Issue846/OldDivMod.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Integer division
------------------------------------------------------------------------
module Issue846.OldDivMod where
open import Data.Nat as Nat
open import Data.Nat.Properties
open import Data.Nat.Solver
open +-*-Solver
open import Data.Fin as Fin using (Fin; zero; suc; toℕ; fromℕ)
import Data.Fin.Properties as Fin
open import Induction.Nat
open import Relation.Nullary.Decidable
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Function
------------------------------------------------------------------------
-- Some boring lemmas
private
lem₁ : (m k : ℕ) →
Nat.suc m ≡ suc (toℕ (Fin.inject+ k (fromℕ m)) + 0)
lem₁ m k = cong suc $ begin
m
≡⟨ sym $ Fin.toℕ-fromℕ m ⟩
toℕ (fromℕ m)
≡⟨ Fin.toℕ-inject+ k (fromℕ m) ⟩
toℕ (Fin.inject+ k (fromℕ m))
≡⟨ solve 1 (λ x → x := x :+ con 0) refl _ ⟩
toℕ (Fin.inject+ k (fromℕ m)) + 0
∎
lem₂ : ∀ n → _
lem₂ = solve 1 (λ n → con 1 :+ n := con 1 :+ (n :+ con 0)) refl
lem₃ : ∀ n k q (r : Fin n) eq → suc n + k ≡ toℕ r + suc q * n
lem₃ n k q r eq = begin
suc n + k
≡⟨ solve 2 (λ n k → con 1 :+ n :+ k := n :+ (con 1 :+ k))
refl n k ⟩
n + suc k
≡⟨ cong (_+_ n) eq ⟩
n + (toℕ r + q * n)
≡⟨ solve 3 (λ n r q → n :+ (r :+ q :* n) :=
r :+ (con 1 :+ q) :* n)
refl n (toℕ r) q ⟩
toℕ r + suc q * n
∎
------------------------------------------------------------------------
-- Division
infixl 7 _divMod_ _div_ _mod_
-- A specification of integer division.
record DivMod (dividend divisor : ℕ) : Set where
constructor result
field
quotient : ℕ
remainder : Fin divisor
property : dividend ≡ toℕ remainder + quotient * divisor
-- Integer division with remainder.
-- Note that Induction.Nat.<-rec is used to establish termination of
-- division. The run-time complexity of this implementation of integer
-- division should be linear in the size of the dividend, assuming
-- that well-founded recursion and the equality type are optimised
-- properly (see "Inductive Families Need Not Store Their Indices"
-- (Brady, McBride, McKinna, TYPES 2003)).
_divMod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod dividend divisor
_divMod_ m n {≢0} = <′-rec Pred dm m n {≢0}
where
Pred : ℕ → Set
Pred dividend = (divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod dividend divisor
1+_ : ∀ {k n} → DivMod (suc k) n → DivMod (suc n + k) n
1+_ {k} {n} (result q r eq) = result (1 + q) r (lem₃ n k q r eq)
dm : (dividend : ℕ) → <′-Rec Pred dividend → Pred dividend
dm m rec zero {≢0 = ()}
dm zero rec (suc n) = result 0 zero refl
dm (suc m) rec (suc n) with compare m n
dm (suc m) rec (suc .(suc m + k)) | less .m k = result 0 r (lem₁ m k)
where r = suc (Fin.inject+ k (fromℕ m))
dm (suc m) rec (suc .m) | equal .m = result 1 zero (lem₂ m)
dm (suc .(suc n + k)) rec (suc n) | greater .n k =
1+ rec (suc k) le (suc n)
where le = s≤′s (s≤′s (n≤′m+n n k))
-- Integer division.
_div_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → ℕ
_div_ m n {≢0} = DivMod.quotient $ _divMod_ m n {≢0}
-- The remainder after integer division.
_mod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → Fin divisor
_mod_ m n {≢0} = DivMod.remainder $ _divMod_ m n {≢0}
| 33.055046
| 79
| 0.522342
|
37ea5fc731b32ac0084d4312e445eb2f1f3bff6a
| 716
|
agda
|
Agda
|
archive/agda-3/src/Oscar/Class/Prefunctor.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-3/src/Oscar/Class/Prefunctor.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-3/src/Oscar/Class/Prefunctor.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
open import Oscar.Prelude
open import Oscar.Class.IsPrefunctor
open import Oscar.Class.Smap
open import Oscar.Class.Surjection
open import Oscar.Class.Transitivity
module Oscar.Class.Prefunctor where
record Prefunctor 𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂ : Ø ↑̂ (𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂) where
constructor ∁
field
{𝔒₁} : Ø 𝔬₁
_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁
_∼̇₁_ : ∀ {x y} → x ∼₁ y → x ∼₁ y → Ø ℓ₁
_↦₁_ : Transitivity.type _∼₁_
{𝔒₂} : Ø 𝔬₂
_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂
_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂
_↦₂_ : Transitivity.type _∼₂_
{μ} : Surjection.type 𝔒₁ 𝔒₂
prefunctor-smap : Smap.type _∼₁_ _∼₂_ μ μ
⦃ `IsPrefunctor ⦄ : IsPrefunctor _∼₁_ _∼̇₁_ _↦₁_ _∼₂_ _∼̇₂_ _↦₂_ prefunctor-smap
| 29.833333
| 84
| 0.614525
|
21a5efdab7a7723955d61511e65abff98e7feb5b
| 8,003
|
agda
|
Agda
|
Cubical/Functions/FunExtEquiv.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Functions/FunExtEquiv.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Functions/FunExtEquiv.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Functions.FunExtEquiv where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.CartesianKanOps
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Vec.Base
open import Cubical.Data.Vec.NAry
open import Cubical.Data.Nat
open import Cubical.Reflection.StrictEquiv
private
variable
ℓ ℓ₁ ℓ₂ ℓ₃ : Level
-- Function extensionality is an equivalence
module _ {A : Type ℓ} {B : A → I → Type ℓ₁}
{f : (x : A) → B x i0} {g : (x : A) → B x i1} where
funExtEquiv : (∀ x → PathP (B x) (f x) (g x)) ≃ PathP (λ i → ∀ x → B x i) f g
unquoteDef funExtEquiv = defStrictEquiv funExtEquiv funExt funExt⁻
funExtPath : (∀ x → PathP (B x) (f x) (g x)) ≡ PathP (λ i → ∀ x → B x i) f g
funExtPath = ua funExtEquiv
funExtIso : Iso (∀ x → PathP (B x) (f x) (g x)) (PathP (λ i → ∀ x → B x i) f g)
funExtIso = iso funExt funExt⁻ (λ x → refl {x = x}) (λ x → refl {x = x})
-- Function extensionality for binary functions
funExt₂ : {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → I → Type ℓ₂}
{f : (x : A) → (y : B x) → C x y i0}
{g : (x : A) → (y : B x) → C x y i1}
→ ((x : A) (y : B x) → PathP (C x y) (f x y) (g x y))
→ PathP (λ i → ∀ x y → C x y i) f g
funExt₂ p i x y = p x y i
-- Function extensionality for binary functions is an equivalence
module _ {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → I → Type ℓ₂}
{f : (x : A) → (y : B x) → C x y i0}
{g : (x : A) → (y : B x) → C x y i1} where
private
appl₂ : PathP (λ i → ∀ x y → C x y i) f g → ∀ x y → PathP (C x y) (f x y) (g x y)
appl₂ eq x y i = eq i x y
funExt₂Equiv : (∀ x y → PathP (C x y) (f x y) (g x y)) ≃ (PathP (λ i → ∀ x y → C x y i) f g)
unquoteDef funExt₂Equiv = defStrictEquiv funExt₂Equiv funExt₂ appl₂
funExt₂Path : (∀ x y → PathP (C x y) (f x y) (g x y)) ≡ (PathP (λ i → ∀ x y → C x y i) f g)
funExt₂Path = ua funExt₂Equiv
-- Function extensionality for ternary functions
funExt₃ : {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → Type ℓ₂}
{D : (x : A) → (y : B x) → C x y → I → Type ℓ₃}
{f : (x : A) → (y : B x) → (z : C x y) → D x y z i0}
{g : (x : A) → (y : B x) → (z : C x y) → D x y z i1}
→ ((x : A) (y : B x) (z : C x y) → PathP (D x y z) (f x y z) (g x y z))
→ PathP (λ i → ∀ x y z → D x y z i) f g
funExt₃ p i x y z = p x y z i
-- Function extensionality for ternary functions is an equivalence
module _ {A : Type ℓ} {B : A → Type ℓ₁} {C : (x : A) → B x → Type ℓ₂}
{D : (x : A) → (y : B x) → C x y → I → Type ℓ₃}
{f : (x : A) → (y : B x) → (z : C x y) → D x y z i0}
{g : (x : A) → (y : B x) → (z : C x y) → D x y z i1} where
private
appl₃ : PathP (λ i → ∀ x y z → D x y z i) f g → ∀ x y z → PathP (D x y z) (f x y z) (g x y z)
appl₃ eq x y z i = eq i x y z
funExt₃Equiv : (∀ x y z → PathP (D x y z) (f x y z) (g x y z)) ≃ (PathP (λ i → ∀ x y z → D x y z i) f g)
unquoteDef funExt₃Equiv = defStrictEquiv funExt₃Equiv funExt₃ appl₃
funExt₃Path : (∀ x y z → PathP (D x y z) (f x y z) (g x y z)) ≡ (PathP (λ i → ∀ x y z → D x y z i) f g)
funExt₃Path = ua funExt₃Equiv
-- n-ary non-dependent funext
nAryFunExt : {X : Type ℓ} {Y : I → Type ℓ₁} (n : ℕ) (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1))
→ ((xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs))
→ PathP (λ i → nAryOp n X (Y i)) fX fY
nAryFunExt zero fX fY p = p []
nAryFunExt (suc n) fX fY p i x = nAryFunExt n (fX x) (fY x) (λ xs → p (x ∷ xs)) i
-- n-ary funext⁻
nAryFunExt⁻ : (n : ℕ) {X : Type ℓ} {Y : I → Type ℓ₁} (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1))
→ PathP (λ i → nAryOp n X (Y i)) fX fY
→ ((xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs))
nAryFunExt⁻ zero fX fY p [] = p
nAryFunExt⁻ (suc n) fX fY p (x ∷ xs) = nAryFunExt⁻ n (fX x) (fY x) (λ i → p i x) xs
nAryFunExtEquiv : (n : ℕ) {X : Type ℓ} {Y : I → Type ℓ₁} (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1))
→ ((xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs)) ≃ PathP (λ i → nAryOp n X (Y i)) fX fY
nAryFunExtEquiv n {X} {Y} fX fY = isoToEquiv (iso (nAryFunExt n fX fY) (nAryFunExt⁻ n fX fY)
(linv n fX fY) (rinv n fX fY))
where
linv : (n : ℕ) (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1))
(p : PathP (λ i → nAryOp n X (Y i)) fX fY)
→ nAryFunExt n fX fY (nAryFunExt⁻ n fX fY p) ≡ p
linv zero fX fY p = refl
linv (suc n) fX fY p i j x = linv n (fX x) (fY x) (λ k → p k x) i j
rinv : (n : ℕ) (fX : nAryOp n X (Y i0)) (fY : nAryOp n X (Y i1))
(p : (xs : Vec X n) → PathP Y (fX $ⁿ xs) (fY $ⁿ map (λ x → x) xs))
→ nAryFunExt⁻ n fX fY (nAryFunExt n fX fY p) ≡ p
rinv zero fX fY p i [] = p []
rinv (suc n) fX fY p i (x ∷ xs) = rinv n (fX x) (fY x) (λ ys i → p (x ∷ ys) i) i xs
-- Funext when the domain also depends on the interval
funExtDep : {A : I → Type ℓ} {B : (i : I) → A i → Type ℓ₁}
{f : (x : A i0) → B i0 x} {g : (x : A i1) → B i1 x}
→ ({x₀ : A i0} {x₁ : A i1} (p : PathP A x₀ x₁) → PathP (λ i → B i (p i)) (f x₀) (g x₁))
→ PathP (λ i → (x : A i) → B i x) f g
funExtDep {A = A} {B} {f} {g} h i x =
comp
(λ k → B i (coei→i A i x k))
(λ k → λ
{ (i = i0) → f (coei→i A i0 x k)
; (i = i1) → g (coei→i A i1 x k)
})
(h (λ j → coei→j A i j x) i)
funExtDep⁻ : {A : I → Type ℓ} {B : (i : I) → A i → Type ℓ₁}
{f : (x : A i0) → B i0 x} {g : (x : A i1) → B i1 x}
→ PathP (λ i → (x : A i) → B i x) f g
→ ({x₀ : A i0} {x₁ : A i1} (p : PathP A x₀ x₁) → PathP (λ i → B i (p i)) (f x₀) (g x₁))
funExtDep⁻ q p i = q i (p i)
funExtDepEquiv : {A : I → Type ℓ} {B : (i : I) → A i → Type ℓ₁}
{f : (x : A i0) → B i0 x} {g : (x : A i1) → B i1 x}
→ ({x₀ : A i0} {x₁ : A i1} (p : PathP A x₀ x₁) → PathP (λ i → B i (p i)) (f x₀) (g x₁))
≃ PathP (λ i → (x : A i) → B i x) f g
funExtDepEquiv {A = A} {B} {f} {g} = isoToEquiv isom
where
open Iso
isom : Iso _ _
isom .fun = funExtDep
isom .inv = funExtDep⁻
isom .rightInv q m i x =
comp
(λ k → B i (coei→i A i x (k ∨ m)))
(λ k → λ
{ (i = i0) → f (coei→i A i0 x (k ∨ m))
; (i = i1) → g (coei→i A i1 x (k ∨ m))
; (m = i1) → q i x
})
(q i (coei→i A i x m))
isom .leftInv h m p i =
comp
(λ k → B i (lemi→i m k))
(λ k → λ
{ (i = i0) → f (lemi→i m k)
; (i = i1) → g (lemi→i m k)
; (m = i1) → h p i
})
(h (λ j → lemi→j j m) i)
where
lemi→j : ∀ j → coei→j A i j (p i) ≡ p j
lemi→j j =
coei→j (λ k → coei→j A i k (p i) ≡ p k) i j (coei→i A i (p i))
lemi→i : PathP (λ m → lemi→j i m ≡ p i) (coei→i A i (p i)) refl
lemi→i =
sym (coei→i (λ k → coei→j A i k (p i) ≡ p k) i (coei→i A i (p i)))
◁ λ m k → lemi→j i (m ∨ k)
heteroHomotopy≃Homotopy : {A : I → Type ℓ} {B : (i : I) → Type ℓ₁}
{f : A i0 → B i0} {g : A i1 → B i1}
→ ({x₀ : A i0} {x₁ : A i1} → PathP A x₀ x₁ → PathP B (f x₀) (g x₁))
≃ ((x₀ : A i0) → PathP B (f x₀) (g (transport (λ i → A i) x₀)))
heteroHomotopy≃Homotopy {A = A} {B} {f} {g} = isoToEquiv isom
where
open Iso
isom : Iso _ _
isom .fun h x₀ = h (isContrSinglP A x₀ .fst .snd)
isom .inv k {x₀} {x₁} p =
subst (λ fib → PathP B (f x₀) (g (fib .fst))) (isContrSinglP A x₀ .snd (x₁ , p)) (k x₀)
isom .rightInv k = funExt λ x₀ →
cong (λ α → subst (λ fib → PathP B (f x₀) (g (fib .fst))) α (k x₀))
(isProp→isSet isPropSinglP (isContrSinglP A x₀ .fst) _
(isContrSinglP A x₀ .snd (isContrSinglP A x₀ .fst))
refl)
∙ transportRefl (k x₀)
isom .leftInv h j {x₀} {x₁} p =
transp
(λ i → PathP B (f x₀) (g (isContrSinglP A x₀ .snd (x₁ , p) (i ∨ j) .fst)))
j
(h (isContrSinglP A x₀ .snd (x₁ , p) j .snd))
| 41.252577
| 106
| 0.496189
|
fde0b93c08bd4c978581745191f18acfc78435b1
| 520
|
agda
|
Agda
|
agda/Confluence.agda
|
anqurvanillapy/fpl
|
9576d5b76e6a868992dbe52930712ac67697bed2
|
[
"MIT"
] | 1
|
2019-08-24T22:47:47.000Z
|
2019-08-24T22:47:47.000Z
|
agda/Confluence.agda
|
anqurvanillapy/fpl
|
9576d5b76e6a868992dbe52930712ac67697bed2
|
[
"MIT"
] | null | null | null |
agda/Confluence.agda
|
anqurvanillapy/fpl
|
9576d5b76e6a868992dbe52930712ac67697bed2
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Confluence where
open import Relation.Binary.PropositionalEquality
using (_≡_; refl)
cong : ∀ {A B : Set} {x y : A} (f : A → B) → x ≡ y → f x ≡ f y
cong f refl = refl
data ℕ : Set where
Z : ℕ
S : ℕ → ℕ
add : ℕ → ℕ → ℕ
add n Z = n
add n (S m) = S (add n m)
_ : ∀ {a : ℕ} → add a Z ≡ a
_ = refl
thm : ∀ {a : ℕ} → add Z a ≡ a
thm {a = Z} = refl
thm {a = (S m)} = cong S thm
-- Confluence checking is not supported;
-- Check out Jesper Cockx's Phd thesis for overlapping patterns.
| 19.259259
| 64
| 0.567308
|
7cca65047465e84f79ed2c893080230b44b4c345
| 1,793
|
agda
|
Agda
|
tree.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 29
|
2019-02-06T13:09:31.000Z
|
2022-03-04T15:05:12.000Z
|
tree.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 8
|
2018-07-09T22:53:38.000Z
|
2022-03-22T03:43:34.000Z
|
tree.agda
|
rfindler/ial
|
f3f0261904577e930bd7646934f756679a6cbba6
|
[
"MIT"
] | 17
|
2018-12-03T22:38:15.000Z
|
2021-11-28T20:13:21.000Z
|
module tree where
open import bool
open import eq
open import level
open import list
open import list-to-string
open import nat
open import nat-thms
open import string
----------------------------------------------------------------------
-- datatype
----------------------------------------------------------------------
-- nonempty trees
data 𝕋 {ℓ} (A : Set ℓ) : Set ℓ where
node : A → 𝕃 (𝕋 A) → 𝕋 A
----------------------------------------------------------------------
-- tree operations
----------------------------------------------------------------------
leaf : ∀ {ℓ}{A : Set ℓ} → A → 𝕋 A
leaf a = node a []
𝕋-to-string : ∀ {ℓ}{A : Set ℓ} → (f : A → string) → (t : 𝕋 A) → string
𝕋s-to-string : ∀ {ℓ}{A : Set ℓ} → (f : A → string) → (ts : 𝕃 (𝕋 A)) → string
𝕋-to-string f (node a []) = f a
𝕋-to-string f (node a ts) = "(" ^ (f a) ^ (𝕋s-to-string f ts) ^ ")"
𝕋s-to-string f [] = ""
𝕋s-to-string f (t :: ts) = " " ^ (𝕋-to-string f t) ^ (𝕋s-to-string f ts)
perfect-binary-tree : ∀ {ℓ}{A : Set ℓ} → ℕ → A → 𝕋 A
perfect-binary-tree 0 a = (node a [])
perfect-binary-tree (suc n) a = let t = perfect-binary-tree n a in
(node a (t :: t :: []))
size𝕋 : ∀ {ℓ}{A : Set ℓ} → 𝕋 A → ℕ
size𝕋s : ∀ {ℓ}{A : Set ℓ} → 𝕃 (𝕋 A) → ℕ
size𝕋 (node a ts) = suc (size𝕋s ts)
size𝕋s [] = 0
size𝕋s (t :: ts) = size𝕋 t + size𝕋s ts
size-perfect : ∀ {ℓ}{A : Set ℓ}(n : ℕ)(a : A) → (size𝕋 (perfect-binary-tree n a)) ≡ pred (2 pow (suc n))
size-perfect 0 a = refl
size-perfect (suc n) a with (size𝕋 (perfect-binary-tree n a)) | size-perfect n a
... | s | ps rewrite ps with 2 pow n | nonzero-pow 2 n refl
... | x | px rewrite +0 x with x + x | (iszerosum2 x x px)
... | x2 | q rewrite +0 x2 | +0 (pred x2) | sym (+suc (pred x2) (pred x2)) | sucpred q | pred+ x2 x2 q = refl
| 35.156863
| 109
| 0.467373
|
fde2d227f0f6b16d9452f1d3df2dfdc3fc257148
| 7,862
|
agda
|
Agda
|
papers/unraveling-recursion/code/src/Type/Lemmas.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 1,299
|
2018-10-02T13:41:39.000Z
|
2022-03-28T01:10:02.000Z
|
papers/unraveling-recursion/code/src/Type/Lemmas.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 2,493
|
2018-09-28T19:28:17.000Z
|
2022-03-31T15:31:31.000Z
|
papers/unraveling-recursion/code/src/Type/Lemmas.agda
|
imikushin/plutus
|
2c5bda20fb94b0f3737ba1a236ef5d7a7fd9f631
|
[
"Apache-2.0"
] | 399
|
2018-10-05T09:36:10.000Z
|
2022-03-31T11:18:25.000Z
|
module Type.Lemmas where
open import Context
open import Type.Core
open import Function
open import Data.Unit.Base
open import Relation.Binary.PropositionalEquality
foldlᶜ-▻-ε : ∀ {α} {A : Set α} -> (Θ : Con A) -> foldlᶜ _▻_ ε Θ ≡ Θ
foldlᶜ-▻-ε ε = refl
foldlᶜ-▻-ε (Γ ▻ σ) = cong (_▻ σ) (foldlᶜ-▻-ε Γ)
-- Same as `mapᶜ f (Γ ▻▻ Δ) ≡ mapᶜ f Γ ▻▻ mapᶜ f Δ`, but we fully inline the definitions,
-- because the REWRITE pragma requires that.
mapᶜ-▻▻
: ∀ {α β} {A : Set α} {B : Set β} {f : A -> B} {Γ : Con A}
-> ∀ Δ ->
foldlᶜ (λ Ξ σ -> Ξ ▻ f σ) ε (foldlᶜ _▻_ Γ Δ)
≡ foldlᶜ _▻_ (foldlᶜ (λ Ξ σ -> Ξ ▻ f σ) ε Γ) (foldlᶜ (λ Ξ σ -> Ξ ▻ f σ) ε Δ)
mapᶜ-▻▻ ε = refl
mapᶜ-▻▻ (Δ ▻ τ) = cong (_▻ _) (mapᶜ-▻▻ Δ)
keep-id : ∀ {α} {A : Set α} {Γ : Con A} {σ τ} -> (v : σ ∈ Γ ▻ τ) -> keep id v ≡ v
keep-id vz = refl
keep-id (vs v) = refl
keep-keep
: ∀ {α} {A : Set α} {Γ Δ Ξ : Con A} {σ τ}
-> (κ : Δ ⊆ Ξ) -> (ι : Γ ⊆ Δ) -> (v : σ ∈ Γ ▻ τ) -> keep κ (keep ι v) ≡ keep (κ ∘ ι) v
keep-keep κ ι vz = refl
keep-keep κ ι (vs v) = refl
dupl-keep-vs
: ∀ {α} {A : Set α} {Γ Δ : Con A} {σ τ}
-> (ι : Γ ⊆ Δ) -> (v : σ ∈ Γ ▻ τ) -> dupl (keep (vs_ ∘ ι) v) ≡ keep ι v
dupl-keep-vs ι vz = refl
dupl-keep-vs ι (vs v) = refl
inject-foldr-poly
: ∀ {α β γ} {A : Set α} {B : Set β} {yᶠ yᵍ}
-> (C : B -> Set γ)
-> (h : ∀ {yʰ} -> C yʰ -> C yʰ -> C yʰ)
-> (g : C yᶠ -> C yᵍ)
-> (∀ {y z} -> h (g y) (g z) ≡ g (h y z))
-> (f : A -> C yᶠ)
-> (Γ : Con A)
-> (z : C yᶠ)
-> g (foldrᶜ (h ∘ f) z Γ) ≡ foldrᶜ (h ∘ g ∘ f) (g z) Γ
inject-foldr-poly C h g dist f ε y = refl
inject-foldr-poly C h g dist f (Γ ▻ x) y
rewrite dist {f x} {y} = inject-foldr-poly C h g dist f Γ (h (f x) y)
inject-foldr-mono
: ∀ {α β} {A : Set α} {B : Set β}
-> (h : B -> B -> B)
-> (g : B -> B)
-> (∀ {y z} -> h (g y) (g z) ≡ g (h y z))
-> (f : A -> B)
-> (Γ : Con A)
-> (y : B)
-> g (foldrᶜ (h ∘ f) y Γ) ≡ foldrᶜ (h ∘ g ∘ f) (g y) Γ
inject-foldr-mono h g dist f Γ y = inject-foldr-poly {B = ⊤} _ h g dist f Γ y
keep-eq
: ∀ {α} {A : Set α} {Θ Ξ : Con A} {σ} (ι κ : Θ ⊆ Ξ)
-> (∀ {τ} -> (v : τ ∈ Θ) -> renᵛ ι v ≡ renᵛ κ v)
-> (∀ {τ} -> (v : τ ∈ Θ ▻ σ) -> renᵛ (keep ι) v ≡ renᵛ (keep κ) v)
keep-eq ι κ q vz = refl
keep-eq ι κ q (vs v) = cong vs_ (q v)
renᵗ-ext
: ∀ {Θ Ξ σ} (ι κ : Θ ⊆ Ξ) (α : Θ ⊢ᵗ σ)
-> (∀ {τ} -> (v : τ ∈ Θ) -> renᵛ ι v ≡ renᵛ κ v)
-> renᵗ ι α ≡ renᵗ κ α
renᵗ-ext ι κ (Var v) q = cong Var (q v)
renᵗ-ext ι κ (Lam β) q = cong Lam_ (renᵗ-ext (keep ι) (keep κ) β (keep-eq ι κ q))
renᵗ-ext ι κ (φ ∙ α) q = cong₂ _∙_ (renᵗ-ext ι κ φ q) (renᵗ-ext ι κ α q)
renᵗ-ext ι κ (α ⇒ β) q = cong₂ _⇒_ (renᵗ-ext ι κ α q) (renᵗ-ext ι κ β q)
renᵗ-ext ι κ (π σ β) q = cong (π σ) (renᵗ-ext (keep ι) (keep κ) β (keep-eq ι κ q))
renᵗ-ext ι κ (μ ψ α) q = cong₂ μ (renᵗ-ext ι κ ψ q) (renᵗ-ext ι κ α q)
renᵗ-keep-keep
: ∀ {Θ Ξ Ω σ τ} (κ : Ξ ⊆ Ω) (ι : Θ ⊆ Ξ) (β : Θ ▻ σ ⊢ᵗ τ)
-> renᵗ (keep κ ∘ keep ι) β ≡ renᵗ (keep (κ ∘ ι)) β
renᵗ-keep-keep κ ι β = renᵗ-ext (keep κ ∘ keep ι) (keep (κ ∘ ι)) β λ
{ vz -> refl
; (vs v) -> refl
}
renᵗ-∘
: ∀ {Θ Ξ Ω σ} (κ : Ξ ⊆ Ω) (ι : Θ ⊆ Ξ) (α : Θ ⊢ᵗ σ)
-> renᵗ κ (renᵗ ι α) ≡ renᵗ (κ ∘ ι) α
renᵗ-∘ κ ι (Var v) = refl
renᵗ-∘ κ ι (Lam β) = cong Lam_ (trans (renᵗ-∘ (keep κ) (keep ι) β) (renᵗ-keep-keep κ ι β))
renᵗ-∘ κ ι (f ∙ α) = cong₂ _∙_ (renᵗ-∘ κ ι f) (renᵗ-∘ κ ι α)
renᵗ-∘ κ ι (α ⇒ β) = cong₂ _⇒_ (renᵗ-∘ κ ι α) (renᵗ-∘ κ ι β)
renᵗ-∘ κ ι (π σ β) = cong (π σ) (trans (renᵗ-∘ (keep κ) (keep ι) β) (renᵗ-keep-keep κ ι β))
renᵗ-∘ κ ι (μ ψ α) = cong₂ μ (renᵗ-∘ κ ι ψ) (renᵗ-∘ κ ι α)
renᵗ-keep-id
: ∀ {Θ σ τ} (β : Θ ▻ σ ⊢ᵗ τ)
-> renᵗ (keep id) β ≡ renᵗ id β
renᵗ-keep-id β = renᵗ-ext (keep id) id β λ
{ vz -> refl
; (vs v) -> refl
}
renᵗ-id : ∀ {Θ σ} (α : Θ ⊢ᵗ σ) -> renᵗ id α ≡ α
renᵗ-id (Var v) = refl
renᵗ-id (Lam β) = cong Lam_ (trans (renᵗ-keep-id β) (renᵗ-id β))
renᵗ-id (φ ∙ α) = cong₂ _∙_ (renᵗ-id φ) (renᵗ-id α)
renᵗ-id (α ⇒ β) = cong₂ _⇒_ (renᵗ-id α) (renᵗ-id β)
renᵗ-id (π σ β) = cong (π σ) (trans (renᵗ-keep-id β) (renᵗ-id β))
renᵗ-id (μ ψ α) = cong₂ μ (renᵗ-id ψ) (renᵗ-id α)
module EnvironmentLemmas
{α β} {A : Set α} {_◆_ : Con A -> A -> Set β}
(environment : Environment _◆_) where
open Environment environment
keepᵉ-eq
: ∀ {Θ Ξ : Con A} {σ} (ρ χ : Ξ ⊢ᵉ Θ)
-> (∀ {τ} -> (v : τ ∈ Θ) -> lookupᵉ v ρ ≡ lookupᵉ v χ )
-> (∀ {τ} -> (v : τ ∈ Θ ▻ σ) -> lookupᵉ v (keepᵉ ρ) ≡ lookupᵉ v (keepᵉ χ))
keepᵉ-eq ρ χ q vz = refl
keepᵉ-eq ρ χ q (vs v) = cong (renᵈ vs_) (q v)
module _ where
open TypeEnv
open EnvironmentLemmas environmentᵗ
subᵗ-ext
: ∀ {Θ Ξ σ} (ρ χ : Ξ ⊢ᵗᵉ Θ) (α : Θ ⊢ᵗ σ)
-> (∀ {τ} -> (v : τ ∈ Θ) -> lookupᵉ v ρ ≡ lookupᵉ v χ)
-> subᵗ ρ α ≡ subᵗ χ α
subᵗ-ext ρ χ (Var v) q = q v
subᵗ-ext ρ χ (Lam β) q = cong Lam_ (subᵗ-ext (keepᵉ ρ) (keepᵉ χ) β (keepᵉ-eq ρ χ q))
subᵗ-ext ρ χ (φ ∙ α) q = cong₂ _∙_ (subᵗ-ext ρ χ φ q) (subᵗ-ext ρ χ α q)
subᵗ-ext ρ χ (α ⇒ β) q = cong₂ _⇒_ (subᵗ-ext ρ χ α q) (subᵗ-ext ρ χ β q)
subᵗ-ext ρ χ (π σ β) q = cong (π σ) (subᵗ-ext (keepᵉ ρ) (keepᵉ χ) β (keepᵉ-eq ρ χ q))
subᵗ-ext ρ χ (μ ψ α) q = cong₂ μ (subᵗ-ext ρ χ ψ q) (subᵗ-ext ρ χ α q)
subᵗ-keepᵉ-keep
: ∀ {Θ Ξ Ω σ τ} (ρ : Ω ⊢ᵗᵉ Ξ) (ι : Θ ⊆ Ξ) (β : Θ ▻ σ ⊢ᵗ τ)
-> subᵗ (keepᵉ ρ ∘ᵉ keep ι) β ≡ subᵗ (keepᵉ (ρ ∘ᵉ ι)) β
subᵗ-keepᵉ-keep ρ ι β = subᵗ-ext (keepᵉ ρ ∘ᵉ keep ι) (keepᵉ (ρ ∘ᵉ ι)) β λ
{ vz -> refl
; (vs v) -> refl
}
subᵗ-renᵗ
: ∀ {Θ Ξ Ω σ} (ρ : Ω ⊢ᵗᵉ Ξ) (ι : Θ ⊆ Ξ) (α : Θ ⊢ᵗ σ)
-> subᵗ ρ (renᵗ ι α) ≡ subᵗ (ρ ∘ᵉ ι) α
subᵗ-renᵗ ρ ι (Var v) = refl
subᵗ-renᵗ ρ ι (Lam β) = cong Lam_ (trans (subᵗ-renᵗ (keepᵉ ρ) (keep ι) β) (subᵗ-keepᵉ-keep ρ ι β))
subᵗ-renᵗ ρ ι (φ ∙ α) = cong₂ _∙_ (subᵗ-renᵗ ρ ι φ) (subᵗ-renᵗ ρ ι α)
subᵗ-renᵗ ρ ι (α ⇒ β) = cong₂ _⇒_ (subᵗ-renᵗ ρ ι α) (subᵗ-renᵗ ρ ι β)
subᵗ-renᵗ ρ ι (π σ β) = cong (π σ) (trans (subᵗ-renᵗ (keepᵉ ρ) (keep ι) β) (subᵗ-keepᵉ-keep ρ ι β))
subᵗ-renᵗ ρ ι (μ ψ α) = cong₂ μ (subᵗ-renᵗ ρ ι ψ) (subᵗ-renᵗ ρ ι α)
subᵗ-keepᵉ-idᵉ
: ∀ {Θ σ τ} (β : Θ ▻ σ ⊢ᵗ τ)
-> subᵗ (keepᵉ idᵉ) β ≡ subᵗ idᵉ β
subᵗ-keepᵉ-idᵉ β = subᵗ-ext (keepᵉ idᵉ) idᵉ β λ
{ vz -> refl
; (vs v) -> refl
}
subᵗ-idᵉ
: ∀ {Θ σ} (α : Θ ⊢ᵗ σ)
-> subᵗ idᵉ α ≡ α
subᵗ-idᵉ (Var v) = refl
subᵗ-idᵉ (Lam β) = cong Lam_ (trans (subᵗ-keepᵉ-idᵉ β) (subᵗ-idᵉ β))
subᵗ-idᵉ (φ ∙ α) = cong₂ _∙_ (subᵗ-idᵉ φ) (subᵗ-idᵉ α)
subᵗ-idᵉ (α ⇒ β) = cong₂ _⇒_ (subᵗ-idᵉ α) (subᵗ-idᵉ β)
subᵗ-idᵉ (π σ β) = cong (π σ) (trans (subᵗ-keepᵉ-idᵉ β) (subᵗ-idᵉ β))
subᵗ-idᵉ (μ ψ α) = cong₂ μ (subᵗ-idᵉ ψ) (subᵗ-idᵉ α)
subᵗ-keepᵉ-Var
: ∀ {Θ Ξ σ τ} (ι : Θ ⊆ Ξ) (β : Θ ▻ σ ⊢ᵗ τ)
-> subᵗ (keepᵉ (PackEnv (Var ∘ ι))) β ≡ subᵗ (PackEnv (Var ∘ keep ι)) β
subᵗ-keepᵉ-Var ι β = subᵗ-ext (keepᵉ (PackEnv (Var ∘ ι))) (PackEnv (Var ∘ keep ι)) β λ
{ vz -> refl
; (vs v) -> refl
}
subᵗ-Var
: ∀ {Θ Ξ σ} (ι : Θ ⊆ Ξ) (α : Θ ⊢ᵗ σ)
-> subᵗ (PackEnv (Var ∘ ι)) α ≡ renᵗ ι α
subᵗ-Var ι (Var v) = refl
subᵗ-Var ι (Lam β) = cong Lam_ (trans (subᵗ-keepᵉ-Var ι β) (subᵗ-Var (keep ι) β))
subᵗ-Var ι (φ ∙ α) = cong₂ _∙_ (subᵗ-Var ι φ) (subᵗ-Var ι α)
subᵗ-Var ι (α ⇒ β) = cong₂ _⇒_ (subᵗ-Var ι α) (subᵗ-Var ι β)
subᵗ-Var ι (π σ β) = cong (π σ) (trans (subᵗ-keepᵉ-Var ι β) (subᵗ-Var (keep ι) β))
subᵗ-Var ι (μ ψ α) = cong₂ μ (subᵗ-Var ι ψ) (subᵗ-Var ι α)
inject-foldr-⇒-renᵗ
: ∀ {Θ Ξ Ω} {f : Star Θ -> Star Ξ}
-> ∀ Δ
-> (ι : Ξ ⊆ Ω)
-> (β : Star Ξ)
-> renᵗ ι (conToTypeBy f Δ β) ≡ conToTypeBy (renᵗ ι ∘ f) Δ (renᵗ ι β)
inject-foldr-⇒-renᵗ Δ ι β = inject-foldr-poly Star _⇒_ (renᵗ ι) refl _ Δ β
inject-foldr-⇒-subᵗ
: ∀ {Θ Ξ Ω} {f : Star Θ -> Star Ξ}
-> ∀ Δ
-> (ρ : Ω TypeEnv.⊢ᵉ Ξ)
-> (β : Star Ξ)
-> subᵗ ρ (conToTypeBy f Δ β) ≡ conToTypeBy (subᵗ ρ ∘ f) Δ (subᵗ ρ β)
inject-foldr-⇒-subᵗ Δ ρ β = inject-foldr-poly Star _⇒_ (subᵗ ρ) refl _ Δ β
| 36.910798
| 101
| 0.500254
|
36609349a3661c103f3845a2a6e4b0626c35b386
| 5,946
|
agda
|
Agda
|
theorems/homotopy/EilenbergMacLane.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
theorems/homotopy/EilenbergMacLane.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
theorems/homotopy/EilenbergMacLane.agda
|
cmknapp/HoTT-Agda
|
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.HSpace renaming (HSpaceStructure to HSS)
open import homotopy.Freudenthal
open import homotopy.IterSuspensionStable
open import homotopy.Pi2HSusp
open import homotopy.EM1HSpace
module homotopy.EilenbergMacLane where
-- EM(G,n) when G is π₁(A,a₀)
module EMImplicit {i} (A : Type i) (cA : is-connected 0 A)
(gA : has-level 1 A) (A-H : HSS A) where
private
a₀ = HSS.e A-H
X = ⊙[ A , a₀ ]
⊙EM : (n : ℕ) → Ptd i
⊙EM O = ⊙Ω X
⊙EM (S n) = ⊙Trunc ⟨ S n ⟩ (⊙Susp^ n X)
module _ (n : ℕ) where
EM = fst (⊙EM n)
embase = snd (⊙EM n)
EM-level : (n : ℕ) → has-level ⟨ n ⟩ (fst (⊙EM n))
EM-level O = gA a₀ a₀
EM-level (S n) = Trunc-level
EM-conn : (n : ℕ) → is-connected ⟨ n ⟩ (EM (S n))
EM-conn n = Trunc-preserves-conn ⟨ S n ⟩
(transport (λ t → is-connected t (fst (⊙Susp^ n X)))
(+2+0 ⟨ n ⟩₋₂) (⊙Susp^-conn n cA))
{-
π (S k) (EM (S n)) (embase (S n)) == π k (EM n) (embase n)
where k > 0 and n = S (S n')
-}
module Stable (k n : ℕ) (indexing : S k ≤ S (S n))
where
private
SSn : ℕ
SSn = S (S n)
lte : ⟨ S k ⟩ ≤T ⟨ SSn ⟩
lte = ⟨⟩-monotone-≤ $ indexing
Skle : S k ≤ (S n) *2
Skle = ≤-trans indexing (lemma n)
where lemma : (n' : ℕ) → S (S n') ≤ (S n') *2
lemma O = inl idp
lemma (S n') = ≤-trans (≤-ap-S (lemma n')) (inr ltS)
private
module SS = Susp^StableSucc X cA k (S n) Skle
abstract
stable : πS (S k) (⊙EM (S SSn))
== πS k (⊙EM SSn)
stable =
πS (S k) (⊙EM (S SSn))
=⟨ πS-below-trunc _ _ _ (≤T-ap-S lte) ⟩
πS (S k) (⊙Susp^ SSn X)
=⟨ SS.stable ⟩
πS k (⊙Susp^ (S n) X)
=⟨ ! (πS-below-trunc _ _ _ lte) ⟩
πS k (⊙EM SSn) ∎
module BelowDiagonal where
π₁ : (n : ℕ) → πS 0 (⊙EM (S (S n))) == Lift-Unit-group
π₁ n =
contr-is-0ᴳ (πS 0 (⊙EM (S (S n))))
(connected-at-level-is-contr
(raise-level-≤T (≤T-ap-S (≤T-ap-S (-2≤T ⟨ n ⟩₋₂)))
(Trunc-level {n = 0}))
(Trunc-preserves-conn 0 (path-conn (EM-conn (S n)))))
-- some clutter here arises from the definition of <;
-- any simple way to avoid this?
πS-below : (k n : ℕ) → (S k < n)
→ πS k (⊙EM n) == Lift-Unit-group
πS-below 0 .2 ltS = π₁ 0
πS-below 0 .3 (ltSR ltS) = π₁ 1
πS-below 0 (S (S n)) (ltSR (ltSR _)) = π₁ n
πS-below (S k) ._ ltS =
Stable.stable k k (inr ltS)
∙ πS-below k _ ltS
πS-below (S k) ._ (ltSR ltS) =
Stable.stable k (S k) (inr (ltSR ltS))
∙ πS-below k _ (ltSR ltS)
πS-below (S k) ._ (ltSR (ltSR ltS)) =
Stable.stable k (S (S k)) (inr (ltSR (ltSR ltS)))
∙ πS-below k _ (ltSR (ltSR ltS))
πS-below (S k) (S (S (S n))) (ltSR (ltSR (ltSR lt))) =
Stable.stable k n
(inr (<-cancel-S (ltSR (ltSR (ltSR lt)))))
∙ πS-below k _ (<-cancel-S (ltSR (ltSR (ltSR lt))))
module OnDiagonal where
π₁ : πS 0 (⊙EM 1) == πS 0 X
π₁ = πS-below-trunc 0 1 X ≤T-refl
private
module Π₂ = Pi2HSusp A gA cA A-H
π₂ : πS 1 (⊙EM 2) == πS 0 X
π₂ =
πS-below-trunc 1 2 (⊙Susp X) ≤T-refl
∙ Π₂.π₂-Suspension
πS-diag : (n : ℕ) → πS n (⊙EM (S n)) == πS 0 X
πS-diag 0 = π₁
πS-diag 1 = π₂
πS-diag (S (S n)) =
Stable.stable (S n) n ≤-refl
∙ πS-diag (S n)
module AboveDiagonal where
πS-above : (k n : ℕ) → (n < S k)
→ πS k (⊙EM n) == Lift-Unit-group
πS-above k n lt =
contr-is-0ᴳ (πS k (⊙EM n))
(inhab-prop-is-contr
[ idp^ (S k) ]
(Trunc-preserves-level 0 (Ω^-level-in -1 (S k) _
(raise-level-≤T (lemma lt) (EM-level n)))))
where lemma : {k n : ℕ} → n < k → ⟨ n ⟩ ≤T (⟨ k ⟩₋₂ +2+ -1)
lemma ltS = inl (! (+2+-comm _ -1))
lemma (ltSR lt) = ≤T-trans (lemma lt) (inr ltS)
module Spectrum where
private
module Π₂ = Pi2HSusp A gA cA A-H
spectrum0 : ⊙Ω (⊙EM 1) == ⊙EM 0
spectrum0 =
⊙Ω (⊙EM 1)
=⟨ ⊙ua (⊙≃-in (Trunc=-equiv _ _) idp) ⟩
⊙Trunc 0 (⊙Ω X)
=⟨ ⊙ua (⊙≃-in (unTrunc-equiv _ (gA a₀ a₀)) idp) ⟩
⊙Ω X ∎
spectrum1 : ⊙Ω (⊙EM 2) == ⊙EM 1
spectrum1 =
⊙Ω (⊙EM 2)
=⟨ ⊙ua (⊙≃-in (Trunc=-equiv _ _) idp) ⟩
⊙Trunc 1 (⊙Ω (⊙Susp X))
=⟨ Π₂.⊙main-lemma ⟩
X
=⟨ ! (⊙ua (⊙≃-in (unTrunc-equiv _ gA) idp)) ⟩
⊙EM 1 ∎
private
sconn : (n : ℕ) → is-connected ⟨ S n ⟩ (fst (⊙Susp^ (S n) X))
sconn n = transport (λ t → is-connected t (fst (⊙Susp^ (S n) X)))
(+2+0 ⟨ n ⟩₋₁) (⊙Susp^-conn (S n) cA)
kle : (n : ℕ) → ⟨ S (S n) ⟩ ≤T ⟨ n ⟩ +2+ ⟨ n ⟩
kle O = inl idp
kle (S n) = ≤T-trans (≤T-ap-S (kle n))
(≤T-trans (inl (! (+2+-βr ⟨ n ⟩ ⟨ n ⟩)))
(inr ltS))
module FS (n : ℕ) =
FreudenthalEquiv ⟨ n ⟩₋₁ ⟨ S (S n) ⟩ (kle n)
(fst (⊙Susp^ (S n) X)) (snd (⊙Susp^ (S n) X)) (sconn n)
spectrumSS : (n : ℕ)
→ ⊙Ω (⊙EM (S (S (S n)))) == ⊙EM (S (S n))
spectrumSS n =
⊙Ω (⊙EM (S (S (S n))))
=⟨ ⊙ua (⊙≃-in (Trunc=-equiv _ _) idp) ⟩
⊙Trunc ⟨ S (S n) ⟩ (⊙Ω (⊙Susp^ (S (S n)) X))
=⟨ ! (FS.⊙path n) ⟩
⊙EM (S (S n)) ∎
abstract
spectrum : (n : ℕ) → ⊙Ω (⊙EM (S n)) == ⊙EM n
spectrum 0 = spectrum0
spectrum 1 = spectrum1
spectrum (S (S n)) = spectrumSS n
module EMExplicit {i} (G : Group i) (G-abelian : is-abelian G) where
module K₁ = EM₁ G
module HSpace = EM₁HSpace G G-abelian
open EMImplicit K₁.EM₁ K₁.EM₁-conn K₁.emlevel HSpace.H-EM₁ public
open BelowDiagonal public using (πS-below)
πS-diag : (n : ℕ) → πS n (⊙EM (S n)) == G
πS-diag n = OnDiagonal.πS-diag n ∙ K₁.π₁.π₁-iso
open AboveDiagonal public using (πS-above)
open Spectrum public using (spectrum)
| 29.29064
| 71
| 0.480491
|
fdaebb196f18a0040742d3acfcfbc7cc8c958e42
| 178
|
agda
|
Agda
|
test/Succeed/Issue427.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue427.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue427.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue427 where
data T : Set where
tt : T
test = (λ {s : T} {t : T} → t) {tt} {tt}
f : {s t : T} → T
f = tt
test₂ = (let x = tt in λ {s : T} {t : T} → x) {tt} {tt}
| 12.714286
| 55
| 0.449438
|
34678a23735c93bcd85c0bc75be53012962f5a4d
| 16,533
|
agda
|
Agda
|
Integer/EucDomain2.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
Integer/EucDomain2.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
Integer/EucDomain2.agda
|
onestruggler/EucDomain
|
7e268e8354065fde734c9c2d9998d2cfd4a21f71
|
[
"CC0-1.0"
] | null | null | null |
-- We show by allowing the reminder of integer division to be
-- negative, we can get more precise estimation of the rank of the
-- remainder: rank reminder ≤ (rank divisor) / 2.
{-# OPTIONS --without-K --safe #-}
module Integer.EucDomain2 where
-- ----------------------------------------------------------------------
-- ℕ is an "Euclidean SemiRing".
module NatESR where
-- ℕ satisfy the euc-eq and euc-rank property with the usual div and
-- mod function. Still we need to do the translation from non-equality
-- to NonZero predicate.
-- imports form stdlib.
open import Relation.Nullary using (¬_)
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
open import Data.Nat as Nat using (ℕ ; zero ; suc)
import Data.Nat.DivMod as NDM
import Data.Nat.Properties as NatP
-- imports from local.
open import Instances
-- We already make ℕ an instance of Rank. For convinence we restate it
-- here.
rank' : ℕ -> ℕ
rank' x = x
-- Division with the annoying translation from ¬ d ≡ 0 to NonZero
-- predicate.
div : ∀ (n d : ℕ) -> ¬ d ≡ 0 -> ℕ
div n zero n0 with n0 refl
... | ()
div n (suc d) n0 = NDM._/_ n (suc d)
-- Reminder.
mod : ∀ (n d : ℕ) -> ¬ d ≡ 0 -> ℕ
mod n zero n0 with n0 refl
... | ()
mod n (suc d) n0 = NDM._%_ n (suc d)
-- Dividend = reminder + quotient * divisor.
euc-eq : ∀ (n d : ℕ) (n0 : ¬ d ≡ 0) ->
let r = mod n d n0 in let q = div n d n0 in
n ≡ r + q * d
euc-eq n zero n0 with n0 refl
... | ()
euc-eq n (suc d) n0 = NDM.m≡m%n+[m/n]*n n (suc d)
-- rank reminder < rank divisor.
euc-rank : ∀ (n d : ℕ) (n0 : ¬ d ≡ 0) ->
let r = mod n d n0 in let q = div n d n0 in
rank r < rank d
euc-rank n zero n0 with n0 refl
... | ()
euc-rank n (suc d) n0 = NDM.m%n<n n (suc d)
-- ----------------------------------------------------------------------
-- Allow Integer division to have negative reminder
-- Let n, d be integers and d nonzero, by the usual divison with
-- reminder we have q, r such that n = r + q * d and ∣ r ∣ < ∣ d ∣.
-- What we want is q' and r' such that n = r' + q' * d and ∣ r' ∣ ≤ ∣
-- d ∣ / 2. Asssume d > 0, an easy calculation shows if ∣ r ∣ ≤ ∣ d ∣
-- / 2, we let q' = q and r' = r, and if ∣ r ∣ > ∣ d ∣ / 2, we let q'
-- = q + 1 and r' = r - d. The case when d < 0 is similar.
-- imports from stdlib.
open import Relation.Nullary using (yes ; no ; ¬_)
open import Relation.Binary.PropositionalEquality as PE
using (_≡_ ; refl ; sym ; cong ; trans)
open import Data.Empty using (⊥-elim)
open import Data.Sum using (_⊎_ ; inj₁ ; inj₂)
open import Data.Bool using (T ; not)
open import Data.Nat as Nat using (ℕ ; suc ; s≤s ; zero ; z≤n)
import Data.Nat.DivMod as NDM
import Data.Nat.Properties as NatP
open import Data.Integer as Int
using (ℤ ; ∣_∣ ; +_ ; +[1+_] ; -[1+_] ; 1ℤ ; _◃_ ; +<+ ; -<- ; -≤- ; -<+ ; -≤+ ; +≤+ ; 0ℤ)
import Data.Integer.Properties as IntP
open import Data.Integer.DivMod
using (_div_ ; _mod_ ; a≡a%n+[a/n]*n ; n%d<d)
open import Data.Integer.Solver
-- imports from local.
open import Instances
-- Aother integer division allowing negative reminder.
div' : ∀ (n d : ℤ) -> ¬ d ≡ 0ℤ -> ℤ
div' n (+_ zero) n0 with n0 refl
... | ()
div' n d@(+[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = n div d
... | no np = 1ℤ + n div d
div' n d@(-[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = n div d
... | no np = - 1ℤ + n div d
-- Another integer mod allowing negative reminder.
mod' : ∀ (n d : ℤ) -> ¬ d ≡ 0ℤ -> ℤ
mod' n (+_ zero) n0 with n0 refl
... | ()
mod' n d@(+[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = + (n mod d)
... | no np = + (n mod d) - d
mod' n d@(-[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = + (n mod d)
... | no np = + (n mod d) + d
-- Dividend = reminder + quotient * divisor.
euc-eq' : ∀ (n d : ℤ) (n0 : ¬ d ≡ 0ℤ) ->
let r = mod' n d n0 in let q = div' n d n0 in
n ≡ r + q * d
euc-eq' n (+_ zero) n0 with n0 refl
... | ()
euc-eq' n d@(+[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = a≡a%n+[a/n]*n n d
... | no np = claim
where
claim : n ≡ (+ (n mod d) - d) + (1ℤ + n div d) * d
claim = begin
n ≡⟨ a≡a%n+[a/n]*n n d ⟩
+ (n mod d) + (n div d) * d ≡⟨ solve 3 (\ x y z -> x :+ y :* z := x :- z :+ (con 1ℤ :+ y) :* z) refl (+ (n mod d)) (n div d) d ⟩
(+ (n mod d) - d) + (1ℤ + n div d) * d ∎
where
open +-*-Solver
open PE.≡-Reasoning
euc-eq' n d@(-[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = a≡a%n+[a/n]*n n d
... | no np = claim
where
claim : n ≡ (+ (n mod d) + d) + (- 1ℤ + n div d) * d
claim = begin
n ≡⟨ a≡a%n+[a/n]*n n d ⟩
+ (n mod d) + (n div d) * d ≡⟨ solve 3 (\ x y z -> x :+ y :* z := x :+ z :+ (con (- 1ℤ) :+ y) :* z) refl (+ (n mod d)) (n div d) d ⟩
(+ (n mod d) + d) + (- 1ℤ + n div d) * d ∎
where
open +-*-Solver
open PE.≡-Reasoning
-- rank reminder ≤ (rank divisor) / 2.
euc-rank' : ∀ (n d : ℤ) (n0 : ¬ d ≡ 0ℤ) ->
let r = mod' n d n0 in let q = div' n d n0 in
∣ r ∣ ≤ ∣ d ∣ / 2
euc-rank' n (+_ zero) n0 with n0 refl
... | ()
euc-rank' n d@(+[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = pr
... | no ¬p = claim
where
r = + (n mod d) - d
d≠0 : ¬ ∣ d ∣ ≡ 0
d≠0 = λ ()
-- We follow the steps to show ∣ r ∣ ≤ ∣ d ∣ / 2, in the current case, i.e. ∣
-- n % d - d ∣ ≤ d / 2. We follows the steps below:
-- 1) d / 2 < n % d
-- 2) d / 2 - d < n % d - d
-- 3) n % d - d < 0, hence d / 2 - d < n % d - d < 0
-- 4) ∣ d / 2 - d ∣ > ∣ n % d - d ∣
-- 5) d / 2 - d ≡ - d / 2 or d / 2 - d ≡ - (d / 2 + 1)
-- 6) ∣ d / 2 - d ∣ ≡ d / 2 or ∣ d / 2 - d ∣ ≡ d / 2 + 1
-- 7) d / 2 > ∣ n % d - d ∣ or d / 2 + 1 > ∣ n % d - d ∣
-- 8) d / 2 ≥ ∣ n % d - d ∣
-- By negate ¬p, we can show ∣ d ∣ / 2 < n mod d.
-- By negation of ¬p (we are using the decidable order).
open import Relation.Binary using (tri< ; tri≈ ; tri>)
step1 : ∣ d ∣ / 2 < n mod d
step1 with NatP.<-cmp (n mod d) (∣ d ∣ / 2)
... | tri< a ¬b ¬c = ⊥-elim (¬p (NatP.<⇒≤ a))
... | tri≈ ¬a b ¬c = ⊥-elim (¬p (NatP.≤-reflexive b))
... | tri> ¬a ¬b c = c
where
notle : ¬ (n mod d ≤ ∣ d ∣ / 2)
notle = ¬p
-- Step 2. ∣ d ∣ / 2 - ∣ d ∣ < n mod d - ∣ d ∣. Subtracting ∣ d ∣
-- from both sides of step1 preserves the inequality.
step2 : + (∣ d ∣ / 2) - + ∣ d ∣ < + (n mod d) - + ∣ d ∣
step2 = IntP.+-monoʳ-< (- (+ ∣ d ∣)) (+<+ step1)
-- Step 3. n mod d - ∣ d ∣ < 0
-- Some auxillary.
n-n=0 : ∀ {n} -> n - n ≡ 0ℤ
n-n=0 {n} = IntP.+-inverseʳ n
step3 : + (n mod d) - (+ ∣ d ∣) < 0ℤ
step3 rewrite (sym (n-n=0 {+ ∣ d ∣})) = r-d<d-d
where
-- n mod d < ∣ d ∣, by Euclidean property of integers.
r<∣d∣ : + (n mod d) < + ∣ d ∣
r<∣d∣ = +<+ (n%d<d n d)
-- Substract ∣ d ∣ on both sides of n mod d < ∣ d ∣.
r-d<d-d : + (n mod d) - (+ ∣ d ∣) < (+ ∣ d ∣) - (+ ∣ d ∣)
r-d<d-d = IntP.+-monoʳ-< (- + ∣ d ∣) r<∣d∣
-- Step 4. ∣ d / 2 - d ∣ > ∣ n % d - d ∣. By 2, we have
-- d / 2 - d < n % d - d < 0. By taking absolute values, we show
-- ∣ d / 2 - d ∣ > ∣ n % d - d ∣.
-- Some lemmas about take absolute value of negative and nonpositive
-- numbers.
lemma-∣neg∣ : ∀ {a : ℤ} -> a < 0ℤ -> + ∣ a ∣ ≡ - a
lemma-∣neg∣ -<+ = refl
lemma-∣non-pos∣ : ∀ {a : ℤ} -> a ≤ 0ℤ -> + ∣ a ∣ ≡ - a
lemma-∣non-pos∣ {.(-[1+ _ ])} -≤+ = refl
lemma-∣non-pos∣ {.(+ zero)} (+≤+ z≤n) = refl
-- The injection of natural numbers into integers reflect order.
lemma-inj-reflect-ord : ∀ {a b} -> + a < + b -> a < b
lemma-inj-reflect-ord (+<+ m<n) = m<n
lemma-inj-reflect-ord' : ∀ {a b} -> + a ≤ + b -> a ≤ b
lemma-inj-reflect-ord' (+≤+ m<n) = m<n
-- Taking absolute value on both sides of a strict inequality of
-- negative numbers (can relax this to non-positive numbers)
-- reverses the order.
lemma-∣neg<neg∣ : ∀ {a b} -> a < 0ℤ -> b < a -> ∣ a ∣ < ∣ b ∣
lemma-∣neg<neg∣ {a} {b} a<0 b<a = lemma-inj-reflect-ord claim where
0<b : b < 0ℤ
0<b = IntP.<-trans b<a a<0
claim : (+ ∣ a ∣) < (+ ∣ b ∣)
claim = begin-strict
+ ∣ a ∣ ≡⟨ lemma-∣neg∣ {a} a<0 ⟩
- a <⟨ IntP.neg-mono-< b<a ⟩
- b ≡⟨ sym (lemma-∣neg∣ 0<b) ⟩
+ ∣ b ∣ ∎
where open IntP.≤-Reasoning
-- Goal step4 achieved.
step4 : ∣ + (n mod d) - d ∣ < ∣ + (∣ d ∣ / 2) - d ∣
step4 = lemma-∣neg<neg∣ step3 step2
-- Step 5. d / 2 - d ≡ - d / 2 or d / 2 - d ≡ - (d / 2 + 1)
-- Natural number version of Step 5.
step5-nat : ∣ d ∣ / 2 + ∣ d ∣ / 2 ≡ ∣ d ∣ ⊎ suc (∣ d ∣ / 2 + ∣ d ∣ / 2) ≡ ∣ d ∣
step5-nat = lemma-div-by-2 ∣ d ∣
where
-- An easy and useful fact.
*2+ : ∀ {a} -> a * 2 ≡ a + a
*2+ {zero} = refl
*2+ {suc a} rewrite *2+ {a} | NatP.+-comm a (suc a) = refl
-- Either d / 2 + d / 2 ≡ d or d / 2 + d / 2 + 1 ≡ d.
lemma-div-by-2 : ∀ d -> let hd = d / 2 in
hd + hd ≡ d ⊎ suc (hd + hd) ≡ d
lemma-div-by-2 d with d / 2 | d % 2 | NatESR.euc-eq d 2 (λ { ()}) | NatESR.euc-rank d 2 (λ { ()})
... | hd | zero | proj₁₁ | pr rewrite *2+ {hd} = inj₁ (sym proj₁₁)
... | hd | suc zero | proj₁₁ | pr rewrite *2+ {hd} = inj₂ (sym proj₁₁)
... | hd | suc (suc r₁) | proj₁₁ | pr = ⊥-elim ((c1 r₁) pr )
where
c1 : ∀ a -> ¬ (suc (suc (suc a)) ≤ 2)
c1 a = λ { (s≤s (s≤s ()))}
-- Next we need inject naturals to integers. We do the two
-- identities separately.
-- Step 5a. If (d / 2) + (d / 2) ≡ d, we show d / 2 - d ≡ - d / 2.
step5a : ∀ d -> (d / 2) + (d / 2) ≡ d -> let -_ = λ x -> - (+ x) in
+ (d / 2) - (+ d) ≡ - (d / 2)
step5a d hyp = sym claim4
where
open PE.≡-Reasoning
claim : + (d / 2 + d / 2) ≡ + d
claim = cong +_ hyp
claim2 : + (d / 2) + + (d / 2) ≡ + d
claim2 = begin
+ (d / 2) + + (d / 2) ≡⟨ IntP.pos-+-commute (d / 2) (d / 2) ⟩
+ (d / 2 + d / 2) ≡⟨ cong +_ hyp ⟩
+ d ∎
claim3 : + (d / 2) ≡ + d - + (d / 2)
claim3 = begin
+ (d / 2) ≡⟨ (solve 1 (λ a -> a := a :+ a :- a) refl) (+ (d / 2)) ⟩
+ (d / 2) + + (d / 2) - + (d / 2) ≡⟨ cong (_- + (d / 2)) claim2 ⟩
+ d - + (d / 2) ∎
where open +-*-Solver
claim4 : let -_ = λ x -> - (+ x) in
- (d / 2) ≡ + (d / 2) - + d
claim4 = begin
- (+ (d / 2)) ≡⟨ cong -_ claim3 ⟩
- (+ d - + (d / 2)) ≡⟨ (solve 2 (λ a b -> :- (a :- b) := b :- a) refl) (+ d) (+ (d / 2)) ⟩
+ (d / 2) - + d ∎
where open +-*-Solver
-- Step 5b. If (d / 2) + (d / 2) + 1 ≡ d, we show d / 2 - d ≡ - (d
-- / 2 + 1). (Note that we change the sign of the equality)
step5b : ∀ d -> suc ((d / 2) + (d / 2)) ≡ d -> let -_ = λ x -> - (+ x) in
(+ d) - + (d / 2) ≡ + (d / 2) + 1ℤ
step5b d hyp = begin
+ d - + (d / 2) ≡⟨ cong (λ x → + x - + (d / 2)) (sym hyp) ⟩
+ (suc (d / 2 + d / 2)) - + (d / 2) ≡⟨ refl ⟩
+ (1 + (d / 2 + d / 2)) - + (d / 2) ≡⟨ cong (_- + (d / 2)) (IntP.pos-+-commute 1 (d / 2 + d / 2)) ⟩
+ 1 + + (d / 2 + d / 2) - + (d / 2) ≡⟨ cong (λ x → + 1 + x - + (d / 2)) (IntP.pos-+-commute (d / 2) (d / 2)) ⟩
+ 1 + + (d / 2) + + (d / 2) - + (d / 2) ≡⟨ solve 1 (λ x → (con 1ℤ) :+ (x :+ x) :- x := x :+ con 1ℤ) refl (+ (d / 2)) ⟩
+ (d / 2) + 1ℤ ∎
where
open +-*-Solver
open PE.≡-Reasoning
-- Goal 5.
step5 : let -_ = λ x -> - (+ x) in
+ (∣ d ∣ / 2) - d ≡ - (∣ d ∣ / 2) ⊎ d - + (∣ d ∣ / 2) ≡ + (∣ d ∣ / 2) + 1ℤ
step5 with step5-nat
... | inj₁ x = inj₁ (step5a ∣ d ∣ x)
... | inj₂ y = inj₂ (step5b ∣ d ∣ y)
-- Step 6. ∣ d / 2 - d ∣ ≡ d / 2 or ∣ d / 2 - d ∣ ≡ d / 2 + 1
step6 : let -_ = λ x -> - (+ x) in
∣ + (∣ d ∣ / 2) - d ∣ ≡ ∣ d ∣ / 2 ⊎ ∣ d - + (∣ d ∣ / 2) ∣ ≡ ∣ d ∣ / 2 + 1
step6 with step5
... | inj₁ x rewrite x = inj₁ (trans ∣-d/2∣≡∣d/2∣ ∣d/2∣≡d/2)
where
∣-d/2∣≡∣d/2∣ : ∣ - (+ (∣ d ∣ / 2)) ∣ ≡ ∣ + (∣ d ∣ / 2) ∣
∣-d/2∣≡∣d/2∣ = IntP.∣-i∣≡∣i∣ (+ (∣ d ∣ / 2))
∣d/2∣≡d/2 : ∣ + (∣ d ∣ / 2) ∣ ≡ (∣ d ∣ / 2)
∣d/2∣≡d/2 = refl
... | inj₂ y rewrite y = inj₂ claim
where
claim : ∣ + (∣ d ∣ / 2) + 1ℤ ∣ ≡ ∣ d ∣ / 2 + 1
claim = begin
∣ + (∣ d ∣ / 2) + 1ℤ ∣ ≡⟨ refl ⟩
∣ + ((∣ d ∣ / 2) + 1) ∣ ≡⟨ refl ⟩
∣ d ∣ / 2 + 1 ∎
where
open PE.≡-Reasoning
-- Step 7. d / 2 > ∣ n % d - d ∣ or d / 2 + 1 > ∣ n % d - d ∣
step7 : ∣ + (n mod d) - d ∣ < ∣ d ∣ / 2 ⊎ ∣ + (n mod d) - d ∣ < ∣ d ∣ / 2 + 1
step7 with step6
... | inj₁ x = inj₁ claim
where
claim : ∣ + (n mod d) - d ∣ < ∣ d ∣ / 2
claim = begin-strict
∣ + (n mod d) - d ∣ <⟨ step4 ⟩
∣ + (∣ d ∣ / 2) - d ∣ ≡⟨ x ⟩
∣ d ∣ / 2 ∎
where
open NatP.≤-Reasoning
... | inj₂ y = inj₂ claim
where
claim : ∣ + (n mod d) - d ∣ < ∣ d ∣ / 2 + 1
claim = begin-strict
∣ + (n mod d) - d ∣ <⟨ step4 ⟩
∣ + (∣ d ∣ / 2) - d ∣ ≡⟨ IntP.∣i-j∣≡∣j-i∣ (+ (∣ d ∣ / 2)) d ⟩
∣ d - + (∣ d ∣ / 2) ∣ ≡⟨ y ⟩
∣ d ∣ / 2 + 1 ∎
where
open NatP.≤-Reasoning
-- Step 8. d / 2 ≥ ∣ n % d - d ∣
step8 : ∣ + (n mod d) - d ∣ ≤ ∣ d ∣ / 2
step8 with step7
... | inj₁ x = NatP.<⇒≤ x
... | inj₂ y = m<sucn⇒m≤n claim
where
m<sucn⇒m≤n : ∀ {m n : ℕ} → m < suc n → m ≤ n
m<sucn⇒m≤n (s≤s le) = le
lemma-+1 : ∀ {a : ℕ} -> a + 1 ≡ suc a
lemma-+1 {zero} = refl
lemma-+1 {suc a} = cong suc (lemma-+1 {a})
claim : ∣ + (n mod d) - d ∣ < suc (∣ d ∣ / 2)
claim = begin-strict
∣ + (n mod d) - d ∣ <⟨ y ⟩
∣ d ∣ / 2 + 1 ≡⟨ lemma-+1 ⟩
suc (∣ d ∣ / 2) ∎
where
open NatP.≤-Reasoning
claim : ∣ r ∣ ≤ ∣ d ∣ / 2
claim = step8
-- This case is solved by recursive call with argument n and - d.
euc-rank' n d@(-[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2 | euc-rank' n (+[1+ e ]) (λ {()})
... | yes pr | hyp = pr
... | no ¬p | hyp = hyp
-- We can relax the estimation.
euc-rank'' : ∀ (n d : ℤ) (n0 : ¬ d ≡ 0ℤ) ->
let r = mod' n d n0 in let q = div' n d n0 in
∣ r ∣ < ∣ d ∣
euc-rank'' n d n0 = let r = mod' n d n0 in let q = div' n d n0 in
begin-strict
∣ r ∣ ≤⟨ euc-rank' n d n0 ⟩
∣ d ∣ / 2 <⟨ aux ∣ d ∣ ∣d∣≠0 ⟩
∣ d ∣ ∎
where
open NatP.≤-Reasoning
aux : ∀ n -> ¬ n ≡ 0 -> n / 2 < n
aux zero n0 with n0 refl
... | ()
aux (suc n) n0 = NDM.m/n<m (suc n) 2 (s≤s (s≤s z≤n))
∣d∣≠0 : ¬ ∣ d ∣ ≡ 0
∣d∣≠0 x = n0 (IntP.∣i∣≡0⇒i≡0 x)
-- ----------------------------------------------------------------------
-- Alternative Euclidean Structure
-- The newly defined div' and mod' together with euc-eq' and
-- euc-rank'' make ℤ an Euclidean Domain with more precise estimate on
-- the rank of the reminder.
open import Integer.EucDomain
using (+-*-isEuclideanDomain ; +-*-euclideanDomain)
import EuclideanDomain
open EuclideanDomain.Bundles
-- We update the old Euclidean structure in EucDomain.
+-*-isEuclideanDomain' = record +-*-isEuclideanDomain
{ div = div'
; mod = mod'
; euc-eq = euc-eq'
; euc-rank = euc-rank''
}
-- Bundle.
+-*-euclideanDomain' : EuclideanDomainBundle _ _
+-*-euclideanDomain' = record
{ isEuclideanDomain = +-*-isEuclideanDomain'
}
-- ----------------------------------------------------------------------
-- Make a new instance for DivMod ℤ
-- Translation between two nonzeros.
nz : ∀ (x : ℤ) -> .{{NonZero x}} -> ¬ x ≡ 0#
nz +[1+ n ] ()
-- We use the newly defined div and mod function.
instance
new-DMℤ : DivMod ℤ
new-DMℤ .NZT = NZTℤ
new-DMℤ ._/_ n d = div' n d (nz d)
new-DMℤ ._%_ n d = mod' n d (nz d)
| 36.019608
| 139
| 0.417166
|
4e3531d045577139ec7843147485a2de19a88c09
| 868
|
agda
|
Agda
|
notes/FOT/Agsy/DataBase.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
notes/FOT/Agsy/DataBase.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
notes/FOT/Agsy/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 #-}
-- Tested with the development version of the Agda standard library on
-- 27 May 2011.
-- Nils' idea about databases in the Agda mailing list.
-- http://thread.gmane.org/gmane.comp.lang.agda/2911/focus=2917
module FOT.Agsy.DataBase where
open import Data.Nat
open import Data.Product
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
postulate
right-identity : ∀ n → n + 0 ≡ n
move-suc : ∀ m n → suc (m + n) ≡ m + suc n
db = right-identity ,′ move-suc
comm : ∀ m n → m + n ≡ n + m -- Via auto {!-c db!}
comm zero n = sym (proj₁ db n)
comm (suc n) n' =
begin
suc (n + n') ≡⟨ cong suc (comm n n') ⟩
suc (n' + n) ≡⟨ proj₂ db n' n ⟩ (n' + suc n)
∎
| 26.30303
| 70
| 0.59447
|
7cb9e080dd42a518558c4128a6b42f0a1b0779a9
| 193
|
agda
|
Agda
|
test/Fail/Issue5558.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue5558.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue5558.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
interleaved mutual
-- we don't do `data A : Set`
data A where
-- you don't have to actually define any constructor to trigger the error, the "where" is enough
data B where
b : B
| 24.125
| 100
| 0.668394
|
38d01f8a3d08504ce80b05fa6eaee101a70ec1d0
| 648
|
agda
|
Agda
|
Cubical/Relation/Binary/Reasoning/StrictPartialOrder.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Binary/Reasoning/StrictPartialOrder.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Binary/Reasoning/StrictPartialOrder.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Relation.Binary.Raw
module Cubical.Relation.Binary.Reasoning.StrictPartialOrder
{a ℓ} {A : Type a} (S : StrictPartialOrder A ℓ) where
open StrictPartialOrder S
import Cubical.Relation.Binary.Raw.Construct.StrictToNonStrict _<_ as NonStrict
------------------------------------------------------------------------
-- Publicly re-export the contents of the base module
open import Cubical.Relation.Binary.Reasoning.Base.Double
(NonStrict.isPreorder transitive)
transitive
NonStrict.<⇒≤
(NonStrict.<-≤-trans transitive)
public
| 30.857143
| 79
| 0.688272
|
0dc6f7714f27bc6851afc02f9b34224ad63ecab4
| 14,752
|
agda
|
Agda
|
Cubical/Data/Sigma/Properties.agda
|
antoinevanmuylder/cubical
|
5b40df813434aa11631ac240409ca2c4d849453c
|
[
"MIT"
] | null | null | null |
Cubical/Data/Sigma/Properties.agda
|
antoinevanmuylder/cubical
|
5b40df813434aa11631ac240409ca2c4d849453c
|
[
"MIT"
] | null | null | null |
Cubical/Data/Sigma/Properties.agda
|
antoinevanmuylder/cubical
|
5b40df813434aa11631ac240409ca2c4d849453c
|
[
"MIT"
] | null | null | null |
{-
Basic properties about Σ-types
- Action of Σ on functions ([map-fst], [map-snd])
- Characterization of equality in Σ-types using dependent paths ([ΣPath{Iso,≃,≡}PathΣ], [Σ≡Prop])
- Proof that discrete types are closed under Σ ([discreteΣ])
- Commutativity and associativity ([Σ-swap-*, Σ-assoc-*])
- Distributivity of Π over Σ ([Σ-Π-*])
- Action of Σ on isomorphisms, equivalences, and paths ([Σ-cong-fst], [Σ-cong-snd], ...)
- Characterization of equality in Σ-types using transport ([ΣPathTransport{≃,≡}PathΣ])
- Σ with a contractible base is its fiber ([Σ-contractFst, ΣUnit])
-}
{-# OPTIONS --safe #-}
module Cubical.Data.Sigma.Properties where
open import Cubical.Data.Sigma.Base
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Path
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Relation.Nullary
open import Cubical.Data.Unit.Base
open import Cubical.Data.Empty.Base
open import Cubical.Reflection.StrictEquiv
open Iso
private
variable
ℓ ℓ' ℓ'' : Level
A A' : Type ℓ
B B' : (a : A) → Type ℓ
C : (a : A) (b : B a) → Type ℓ
map-fst : {B : Type ℓ} → (f : A → A') → A × B → A' × B
map-fst f (a , b) = (f a , b)
map-snd : (∀ {a} → B a → B' a) → Σ A B → Σ A B'
map-snd f (a , b) = (a , f b)
map-× : {B : Type ℓ} {B' : Type ℓ'} → (A → A') → (B → B') → A × B → A' × B'
map-× f g (a , b) = (f a , g b)
≡-× : {A : Type ℓ} {B : Type ℓ'} {x y : A × B} → fst x ≡ fst y → snd x ≡ snd y → x ≡ y
≡-× p q i = (p i) , (q i)
-- Characterization of paths in Σ using dependent paths
module _ {A : I → Type ℓ} {B : (i : I) → A i → Type ℓ'}
{x : Σ (A i0) (B i0)} {y : Σ (A i1) (B i1)}
where
ΣPathP : Σ[ p ∈ PathP A (fst x) (fst y) ] PathP (λ i → B i (p i)) (snd x) (snd y)
→ PathP (λ i → Σ (A i) (B i)) x y
ΣPathP eq i = fst eq i , snd eq i
PathPΣ : PathP (λ i → Σ (A i) (B i)) x y
→ Σ[ p ∈ PathP A (fst x) (fst y) ] PathP (λ i → B i (p i)) (snd x) (snd y)
PathPΣ eq = (λ i → fst (eq i)) , (λ i → snd (eq i))
-- allows one to write
-- open PathPΣ somePathInΣAB renaming (fst ... )
module PathPΣ (p : PathP (λ i → Σ (A i) (B i)) x y) where
open Σ (PathPΣ p) public
ΣPathIsoPathΣ : Iso (Σ[ p ∈ PathP A (fst x) (fst y) ] (PathP (λ i → B i (p i)) (snd x) (snd y)))
(PathP (λ i → Σ (A i) (B i)) x y)
fun ΣPathIsoPathΣ = ΣPathP
inv ΣPathIsoPathΣ = PathPΣ
rightInv ΣPathIsoPathΣ _ = refl
leftInv ΣPathIsoPathΣ _ = refl
unquoteDecl ΣPath≃PathΣ = declStrictIsoToEquiv ΣPath≃PathΣ ΣPathIsoPathΣ
ΣPath≡PathΣ : (Σ[ p ∈ PathP A (fst x) (fst y) ] (PathP (λ i → B i (p i)) (snd x) (snd y)))
≡ (PathP (λ i → Σ (A i) (B i)) x y)
ΣPath≡PathΣ = ua ΣPath≃PathΣ
×≡Prop : isProp A' → {u v : A × A'} → u .fst ≡ v .fst → u ≡ v
×≡Prop pB {u} {v} p i = (p i) , (pB (u .snd) (v .snd) i)
-- Useful lemma to prove unique existence
uniqueExists : (a : A) (b : B a) (h : (a' : A) → isProp (B a')) (H : (a' : A) → B a' → a ≡ a') → ∃![ a ∈ A ] B a
fst (uniqueExists a b h H) = (a , b)
snd (uniqueExists a b h H) (a' , b') = ΣPathP (H a' b' , isProp→PathP (λ i → h (H a' b' i)) b b')
-- Characterization of dependent paths in Σ
module _ {A : I → Type ℓ} {B : (i : I) → (a : A i) → Type ℓ'}
{x : Σ (A i0) (B i0)} {y : Σ (A i1) (B i1)}
where
ΣPathPIsoPathPΣ :
Iso (Σ[ p ∈ PathP A (x .fst) (y .fst) ] PathP (λ i → B i (p i)) (x .snd) (y .snd))
(PathP (λ i → Σ (A i) (B i)) x y)
ΣPathPIsoPathPΣ .fun (p , q) i = p i , q i
ΣPathPIsoPathPΣ .inv pq .fst i = pq i .fst
ΣPathPIsoPathPΣ .inv pq .snd i = pq i .snd
ΣPathPIsoPathPΣ .rightInv _ = refl
ΣPathPIsoPathPΣ .leftInv _ = refl
unquoteDecl ΣPathP≃PathPΣ = declStrictIsoToEquiv ΣPathP≃PathPΣ ΣPathPIsoPathPΣ
ΣPathP≡PathPΣ = ua ΣPathP≃PathPΣ
-- Σ of discrete types
discreteΣ : Discrete A → ((a : A) → Discrete (B a)) → Discrete (Σ A B)
discreteΣ {B = B} Adis Bdis (a0 , b0) (a1 , b1) = discreteΣ' (Adis a0 a1)
where
discreteΣ' : Dec (a0 ≡ a1) → Dec ((a0 , b0) ≡ (a1 , b1))
discreteΣ' (yes p) = J (λ a1 p → ∀ b1 → Dec ((a0 , b0) ≡ (a1 , b1))) (discreteΣ'') p b1
where
discreteΣ'' : (b1 : B a0) → Dec ((a0 , b0) ≡ (a0 , b1))
discreteΣ'' b1 with Bdis a0 b0 b1
... | (yes q) = yes (transport ΣPath≡PathΣ (refl , q))
... | (no ¬q) = no (λ r → ¬q (subst (λ X → PathP (λ i → B (X i)) b0 b1) (Discrete→isSet Adis a0 a0 (cong fst r) refl) (cong snd r)))
discreteΣ' (no ¬p) = no (λ r → ¬p (cong fst r))
module _ {A : Type ℓ} {A' : Type ℓ'} where
Σ-swap-Iso : Iso (A × A') (A' × A)
fun Σ-swap-Iso (x , y) = (y , x)
inv Σ-swap-Iso (x , y) = (y , x)
rightInv Σ-swap-Iso _ = refl
leftInv Σ-swap-Iso _ = refl
unquoteDecl Σ-swap-≃ = declStrictIsoToEquiv Σ-swap-≃ Σ-swap-Iso
module _ {A : Type ℓ} {B : A → Type ℓ'} {C : ∀ a → B a → Type ℓ''} where
Σ-assoc-Iso : Iso (Σ[ (a , b) ∈ Σ A B ] C a b) (Σ[ a ∈ A ] Σ[ b ∈ B a ] C a b)
fun Σ-assoc-Iso ((x , y) , z) = (x , (y , z))
inv Σ-assoc-Iso (x , (y , z)) = ((x , y) , z)
rightInv Σ-assoc-Iso _ = refl
leftInv Σ-assoc-Iso _ = refl
unquoteDecl Σ-assoc-≃ = declStrictIsoToEquiv Σ-assoc-≃ Σ-assoc-Iso
Σ-Π-Iso : Iso ((a : A) → Σ[ b ∈ B a ] C a b) (Σ[ f ∈ ((a : A) → B a) ] ∀ a → C a (f a))
fun Σ-Π-Iso f = (fst ∘ f , snd ∘ f)
inv Σ-Π-Iso (f , g) x = (f x , g x)
rightInv Σ-Π-Iso _ = refl
leftInv Σ-Π-Iso _ = refl
unquoteDecl Σ-Π-≃ = declStrictIsoToEquiv Σ-Π-≃ Σ-Π-Iso
Σ-cong-iso-fst : (isom : Iso A A') → Iso (Σ A (B ∘ fun isom)) (Σ A' B)
fun (Σ-cong-iso-fst isom) x = fun isom (x .fst) , x .snd
inv (Σ-cong-iso-fst {B = B} isom) x = inv isom (x .fst) , subst B (sym (ε (x .fst))) (x .snd)
where
ε = isHAEquiv.rinv (snd (iso→HAEquiv isom))
rightInv (Σ-cong-iso-fst {B = B} isom) (x , y) = ΣPathP (ε x , toPathP goal)
where
ε = isHAEquiv.rinv (snd (iso→HAEquiv isom))
goal : subst B (ε x) (subst B (sym (ε x)) y) ≡ y
goal = sym (substComposite B (sym (ε x)) (ε x) y)
∙∙ cong (λ x → subst B x y) (lCancel (ε x))
∙∙ substRefl {B = B} y
leftInv (Σ-cong-iso-fst {A = A} {B = B} isom) (x , y) = ΣPathP (leftInv isom x , toPathP goal)
where
ε = isHAEquiv.rinv (snd (iso→HAEquiv isom))
γ = isHAEquiv.com (snd (iso→HAEquiv isom))
lem : (x : A) → sym (ε (fun isom x)) ∙ cong (fun isom) (leftInv isom x) ≡ refl
lem x = cong (λ a → sym (ε (fun isom x)) ∙ a) (γ x) ∙ lCancel (ε (fun isom x))
goal : subst B (cong (fun isom) (leftInv isom x)) (subst B (sym (ε (fun isom x))) y) ≡ y
goal = sym (substComposite B (sym (ε (fun isom x))) (cong (fun isom) (leftInv isom x)) y)
∙∙ cong (λ a → subst B a y) (lem x)
∙∙ substRefl {B = B} y
Σ-cong-equiv-fst : (e : A ≃ A') → Σ A (B ∘ equivFun e) ≃ Σ A' B
-- we could just do this:
-- Σ-cong-equiv-fst e = isoToEquiv (Σ-cong-iso-fst (equivToIso e))
-- but the following reduces slightly better
Σ-cong-equiv-fst {A = A} {A' = A'} {B = B} e = intro , isEqIntro
where
intro : Σ A (B ∘ equivFun e) → Σ A' B
intro (a , b) = equivFun e a , b
isEqIntro : isEquiv intro
isEqIntro .equiv-proof x = ctr , isCtr where
PB : ∀ {x y} → x ≡ y → B x → B y → Type _
PB p = PathP (λ i → B (p i))
open Σ x renaming (fst to a'; snd to b)
open Σ (equivCtr e a') renaming (fst to ctrA; snd to α)
ctrB : B (equivFun e ctrA)
ctrB = subst B (sym α) b
ctrP : PB α ctrB b
ctrP = symP (transport-filler (λ i → B (sym α i)) b)
ctr : fiber intro x
ctr = (ctrA , ctrB) , ΣPathP (α , ctrP)
isCtr : ∀ y → ctr ≡ y
isCtr ((r , s) , p) = λ i → (a≡r i , b!≡s i) , ΣPathP (α≡ρ i , coh i) where
open PathPΣ p renaming (fst to ρ; snd to σ)
open PathPΣ (equivCtrPath e a' (r , ρ)) renaming (fst to a≡r; snd to α≡ρ)
b!≡s : PB (cong (equivFun e) a≡r) ctrB s
b!≡s i = comp (λ k → B (α≡ρ i (~ k))) (λ k → (λ
{ (i = i0) → ctrP (~ k)
; (i = i1) → σ (~ k)
})) b
coh : PathP (λ i → PB (α≡ρ i) (b!≡s i) b) ctrP σ
coh i j = fill (λ k → B (α≡ρ i (~ k))) (λ k → (λ
{ (i = i0) → ctrP (~ k)
; (i = i1) → σ (~ k)
})) (inS b) (~ j)
Σ-cong-fst : (p : A ≡ A') → Σ A (B ∘ transport p) ≡ Σ A' B
Σ-cong-fst {B = B} p i = Σ (p i) (B ∘ transp (λ j → p (i ∨ j)) i)
Σ-cong-iso-snd : ((x : A) → Iso (B x) (B' x)) → Iso (Σ A B) (Σ A B')
fun (Σ-cong-iso-snd isom) (x , y) = x , fun (isom x) y
inv (Σ-cong-iso-snd isom) (x , y') = x , inv (isom x) y'
rightInv (Σ-cong-iso-snd isom) (x , y) = ΣPathP (refl , rightInv (isom x) y)
leftInv (Σ-cong-iso-snd isom) (x , y') = ΣPathP (refl , leftInv (isom x) y')
Σ-cong-equiv-snd : (∀ a → B a ≃ B' a) → Σ A B ≃ Σ A B'
Σ-cong-equiv-snd h = isoToEquiv (Σ-cong-iso-snd (equivToIso ∘ h))
Σ-cong-snd : ((x : A) → B x ≡ B' x) → Σ A B ≡ Σ A B'
Σ-cong-snd {A = A} p i = Σ[ x ∈ A ] (p x i)
Σ-cong-iso : (isom : Iso A A')
→ ((x : A) → Iso (B x) (B' (fun isom x)))
→ Iso (Σ A B) (Σ A' B')
Σ-cong-iso isom isom' = compIso (Σ-cong-iso-snd isom') (Σ-cong-iso-fst isom)
Σ-cong-equiv : (e : A ≃ A')
→ ((x : A) → B x ≃ B' (equivFun e x))
→ Σ A B ≃ Σ A' B'
Σ-cong-equiv e e' = isoToEquiv (Σ-cong-iso (equivToIso e) (equivToIso ∘ e'))
Σ-cong' : (p : A ≡ A') → PathP (λ i → p i → Type ℓ') B B' → Σ A B ≡ Σ A' B'
Σ-cong' p p' = cong₂ (λ (A : Type _) (B : A → Type _) → Σ A B) p p'
-- Alternative version for path in Σ-types, as in the HoTT book
ΣPathTransport : (a b : Σ A B) → Type _
ΣPathTransport {B = B} a b = Σ[ p ∈ (fst a ≡ fst b) ] transport (λ i → B (p i)) (snd a) ≡ snd b
IsoΣPathTransportPathΣ : (a b : Σ A B) → Iso (ΣPathTransport a b) (a ≡ b)
IsoΣPathTransportPathΣ {B = B} a b =
compIso (Σ-cong-iso-snd (λ p → invIso (PathPIsoPath (λ i → B (p i)) _ _)))
ΣPathIsoPathΣ
ΣPathTransport≃PathΣ : (a b : Σ A B) → ΣPathTransport a b ≃ (a ≡ b)
ΣPathTransport≃PathΣ {B = B} a b = isoToEquiv (IsoΣPathTransportPathΣ a b)
ΣPathTransport→PathΣ : (a b : Σ A B) → ΣPathTransport a b → (a ≡ b)
ΣPathTransport→PathΣ a b = Iso.fun (IsoΣPathTransportPathΣ a b)
PathΣ→ΣPathTransport : (a b : Σ A B) → (a ≡ b) → ΣPathTransport a b
PathΣ→ΣPathTransport a b = Iso.inv (IsoΣPathTransportPathΣ a b)
ΣPathTransport≡PathΣ : (a b : Σ A B) → ΣPathTransport a b ≡ (a ≡ b)
ΣPathTransport≡PathΣ a b = ua (ΣPathTransport≃PathΣ a b)
Σ-contractFstIso : (c : isContr A) → Iso (Σ A B) (B (c .fst))
fun (Σ-contractFstIso {B = B} c) p = subst B (sym (c .snd (fst p))) (snd p)
inv (Σ-contractFstIso {B = B} c) b = _ , b
rightInv (Σ-contractFstIso {B = B} c) b =
cong (λ p → subst B p b) (isProp→isSet (isContr→isProp c) _ _ _ _) ∙ transportRefl _
fst (leftInv (Σ-contractFstIso {B = B} c) p j) = c .snd (fst p) j
snd (leftInv (Σ-contractFstIso {B = B} c) p j) =
transp (λ i → B (c .snd (fst p) (~ i ∨ j))) j (snd p)
Σ-contractFst : (c : isContr A) → Σ A B ≃ B (c .fst)
Σ-contractFst {B = B} c = isoToEquiv (Σ-contractFstIso c)
-- a special case of the above
module _ (A : Unit → Type ℓ) where
ΣUnit : Σ Unit A ≃ A tt
unquoteDef ΣUnit = defStrictEquiv ΣUnit snd (λ { x → (tt , x) })
Σ-contractSnd : ((a : A) → isContr (B a)) → Σ A B ≃ A
Σ-contractSnd c = isoToEquiv isom
where
isom : Iso _ _
isom .fun = fst
isom .inv a = a , c a .fst
isom .rightInv _ = refl
isom .leftInv (a , b) = cong (a ,_) (c a .snd b)
isEmbeddingFstΣProp : ((x : A) → isProp (B x))
→ {u v : Σ A B}
→ isEquiv (λ (p : u ≡ v) → cong fst p)
isEmbeddingFstΣProp {B = B} pB {u = u} {v = v} .equiv-proof x = ctr , isCtr
where
ctrP : u ≡ v
ctrP = ΣPathP (x , isProp→PathP (λ _ → pB _) _ _)
ctr : fiber (λ (p : u ≡ v) → cong fst p) x
ctr = ctrP , refl
isCtr : ∀ z → ctr ≡ z
isCtr (z , p) = ΣPathP (ctrP≡ , cong (sym ∘ snd) fzsingl) where
fzsingl : Path (singl x) (x , refl) (cong fst z , sym p)
fzsingl = isContrSingl x .snd (cong fst z , sym p)
ctrSnd : SquareP (λ i j → B (fzsingl i .fst j)) (cong snd ctrP) (cong snd z) _ _
ctrSnd = isProp→SquareP (λ _ _ → pB _) _ _ _ _
ctrP≡ : ctrP ≡ z
ctrP≡ i = ΣPathP (fzsingl i .fst , ctrSnd i)
Σ≡PropEquiv : ((x : A) → isProp (B x)) → {u v : Σ A B}
→ (u .fst ≡ v .fst) ≃ (u ≡ v)
Σ≡PropEquiv pB = invEquiv (_ , isEmbeddingFstΣProp pB)
Σ≡Prop : ((x : A) → isProp (B x)) → {u v : Σ A B}
→ (p : u .fst ≡ v .fst) → u ≡ v
Σ≡Prop pB p = equivFun (Σ≡PropEquiv pB) p
≃-× : ∀ {ℓ'' ℓ'''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {D : Type ℓ'''} → A ≃ C → B ≃ D → A × B ≃ C × D
≃-× eq1 eq2 =
map-× (fst eq1) (fst eq2)
, record
{ equiv-proof
= λ {(c , d) → ((eq1⁻ c .fst .fst
, eq2⁻ d .fst .fst)
, ≡-× (eq1⁻ c .fst .snd)
(eq2⁻ d .fst .snd))
, λ {((a , b) , p) → ΣPathP (≡-× (cong fst (eq1⁻ c .snd (a , cong fst p)))
(cong fst (eq2⁻ d .snd (b , cong snd p)))
, λ i → ≡-× (snd ((eq1⁻ c .snd (a , cong fst p)) i))
(snd ((eq2⁻ d .snd (b , cong snd p)) i)))}}}
where
eq1⁻ = equiv-proof (eq1 .snd)
eq2⁻ = equiv-proof (eq2 .snd)
{- Some simple ismorphisms -}
prodIso : ∀ {ℓ ℓ' ℓ'' ℓ'''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {D : Type ℓ'''}
→ Iso A C
→ Iso B D
→ Iso (A × B) (C × D)
Iso.fun (prodIso iAC iBD) (a , b) = (Iso.fun iAC a) , Iso.fun iBD b
Iso.inv (prodIso iAC iBD) (c , d) = (Iso.inv iAC c) , Iso.inv iBD d
Iso.rightInv (prodIso iAC iBD) (c , d) = ΣPathP ((Iso.rightInv iAC c) , (Iso.rightInv iBD d))
Iso.leftInv (prodIso iAC iBD) (a , b) = ΣPathP ((Iso.leftInv iAC a) , (Iso.leftInv iBD b))
toProdIso : {B C : A → Type ℓ}
→ Iso ((a : A) → B a × C a) (((a : A) → B a) × ((a : A) → C a))
Iso.fun toProdIso = λ f → (λ a → fst (f a)) , (λ a → snd (f a))
Iso.inv toProdIso (f , g) = λ a → (f a) , (g a)
Iso.rightInv toProdIso (f , g) = refl
Iso.leftInv toProdIso b = refl
module _ {A : Type ℓ} {B : A → Type ℓ'} {C : ∀ a → B a → Type ℓ''} where
curryIso : Iso (((a , b) : Σ A B) → C a b) ((a : A) → (b : B a) → C a b)
Iso.fun curryIso f a b = f (a , b)
Iso.inv curryIso f a = f (fst a) (snd a)
Iso.rightInv curryIso a = refl
Iso.leftInv curryIso f = refl
unquoteDecl curryEquiv = declStrictIsoToEquiv curryEquiv curryIso
-- Sigma type with empty base
module _ (A : ⊥ → Type ℓ) where
open Iso
ΣEmptyIso : Iso (Σ ⊥ A) ⊥
fun ΣEmptyIso (* , _) = *
ΣEmpty : Σ ⊥ A ≃ ⊥
ΣEmpty = isoToEquiv ΣEmptyIso
| 38.821053
| 140
| 0.539656
|
1b19c3736c0c4c1feb43d874fccd48f8538dfc98
| 9,428
|
agda
|
Agda
|
Categories/2-Category.agda
|
copumpkin/categories
|
36f4181d751e2ecb54db219911d8c69afe8ba892
|
[
"BSD-3-Clause"
] | 98
|
2015-04-15T14:57:33.000Z
|
2022-03-08T05:20:36.000Z
|
Categories/2-Category.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 19
|
2015-05-23T06:47:10.000Z
|
2019-08-09T16:31:40.000Z
|
Categories/2-Category.agda
|
p-pavel/categories
|
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
|
[
"BSD-3-Clause"
] | 23
|
2015-02-05T13:03:09.000Z
|
2021-11-11T13:50:56.000Z
|
{-# OPTIONS --universe-polymorphism #-}
module Categories.2-Category where
open import Level
open import Data.Product using (curry; _,_)
open import Function using () renaming (_∘_ to _·_)
open import Categories.Support.PropositionalEquality
open import Categories.Category
open import Categories.Categories
open import Categories.Object.Terminal
open import Categories.Terminal
open import Categories.Functor using (Functor) renaming (_∘_ to _∘F_; _≡_ to _≡F_; id to idF)
open import Categories.Bifunctor using (Bifunctor; reduce-×)
open import Categories.Product using (assocʳ; πˡ; πʳ)
record 2-Category (o ℓ t e : Level) : Set (suc (o ⊔ ℓ ⊔ t ⊔ e)) where
open Terminal (One {ℓ} {t} {e})
infix 4 _⇒_
infixr 9 _∘_
field
Obj : Set o
_⇒_ : (A B : Obj) → Category ℓ t e
id : {A : Obj} → Functor ⊤ (A ⇒ A)
—∘— : {A B C : Obj} → Bifunctor (B ⇒ C) (A ⇒ B) (A ⇒ C)
_∘_ : {A B C : Obj} {L R : Category ℓ t e} → Functor L (B ⇒ C) → Functor R (A ⇒ B) → Bifunctor L R (A ⇒ C)
_∘_ {A} {B} {C} F G = reduce-× {D₁ = B ⇒ C} {D₂ = A ⇒ B} —∘— F G
field
.assoc : ∀ {A B C D : Obj} → ((—∘— ∘ idF) ∘F assocʳ (C ⇒ D) (B ⇒ C) (A ⇒ B)) ≡F (idF ∘ —∘—)
.identityˡ : {A B : Obj} → (id {B} ∘ idF {C = A ⇒ B}) ≡F πʳ {C = ⊤} {A ⇒ B}
.identityʳ : {A B : Obj} → (idF {C = A ⇒ B} ∘ id {A}) ≡F πˡ {C = A ⇒ B} {⊤}
-- convenience?
module _⇒_ (A B : Obj) = Category (A ⇒ B)
open _⇒_ public using () renaming (Obj to _⇒₁_)
private module imp⇒ {X Y : Obj} = Category (X ⇒ Y)
open imp⇒ public using () renaming (_⇒_ to _⇒₂_; id to id₂; _∘_ to _•_; assoc to vassoc′; identityˡ to videntityˡ′; identityʳ to videntityʳ′; ∘-resp-≡ to •-resp-≡′; ∘-resp-≡ˡ to •-resp-≡′ˡ; ∘-resp-≡ʳ to •-resp-≡′ʳ; hom-setoid to hom₂′-setoid; _≡_ to _≡′_; equiv to equiv′; module Equiv to Equiv′)
module Equiv {X Y : Obj} = Heterogeneous (X ⇒ Y)
open Equiv public using () renaming (_∼_ to _≡_; ≡⇒∼ to loosely)
id₁ : ∀ {A} → A ⇒₁ A
id₁ {A} = Functor.F₀ (id {A}) unit
id₁₂ : ∀ {A} → id₁ {A} ⇒₂ id₁ {A}
id₁₂ {A} = id₂ {A = id₁ {A}}
infixr 9 _∘₁_
_∘₁_ : ∀ {A B C} → B ⇒₁ C → A ⇒₁ B → A ⇒₁ C
_∘₁_ = curry (Functor.F₀ —∘—)
-- horizontal composition
infixr 9 _∘₂_
_∘₂_ : ∀ {A B C} {g g′ : B ⇒₁ C} {f f′ : A ⇒₁ B} (β : g ⇒₂ g′) (α : f ⇒₂ f′) → (g ∘₁ f) ⇒₂ (g′ ∘₁ f′)
_∘₂_ = curry (Functor.F₁ —∘—)
.∘₂-resp-≡′ : ∀ {A B C} {f h : B ⇒₁ C} {g i : A ⇒₁ B} {α γ : f ⇒₂ h} {β δ : g ⇒₂ i} → α ≡′ γ → β ≡′ δ → α ∘₂ β ≡′ γ ∘₂ δ
∘₂-resp-≡′ = curry (Functor.F-resp-≡ —∘—)
.∘₂-resp-≡ : ∀ {A B C} {f f′ h h′ : B ⇒₁ C} {g g′ i i′ : A ⇒₁ B} {α : f ⇒₂ h} {γ : f′ ⇒₂ h′} {β : g ⇒₂ i} {δ : g′ ⇒₂ i′} → α ≡ γ → β ≡ δ → (α ∘₂ β) ≡ (γ ∘₂ δ)
∘₂-resp-≡ (loosely a) (loosely b) = loosely (∘₂-resp-≡′ a b)
-- left whiskering
infixl 9 _◃_
_◃_ : ∀ {A B C} {g g′ : B ⇒₁ C} → g ⇒₂ g′ → (f : A ⇒₁ B) → (g ∘₁ f) ⇒₂ (g′ ∘₁ f)
β ◃ f = β ∘₂ id₂
-- right whiskering
infixr 9 _▹_
_▹_ : ∀ {A B C} (g : B ⇒₁ C) → {f f′ : A ⇒₁ B} → f ⇒₂ f′ → (g ∘₁ f) ⇒₂ (g ∘₁ f′)
g ▹ α = id₂ ∘₂ α
private
≡F-on-objects : ∀ {o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (F G : Functor C D) → (F ≡F G) → (X : Category.Obj C) → Functor.F₀ F X ≣ Functor.F₀ G X
≡F-on-objects {C = C} F G eq X with Functor.F₀ F X | Functor.F₁ F (Category.id C {X}) | eq (Category.id C {X})
≡F-on-objects {C = C} F G eq X | ._ | _ | Heterogeneous.≡⇒∼ _ = ≣-refl
private
module Laws1A {A B} {f : A ⇒₁ B} where
.assoc₁ : ∀ {C D} {g : B ⇒₁ C} {h : C ⇒₁ D} → ((h ∘₁ g) ∘₁ f) ≣ (h ∘₁ (g ∘₁ f))
assoc₁ {C} {D} {g} {h} = ≡F-on-objects ((—∘— ∘ idF) ∘F assocʳ (C ⇒ D) (B ⇒ C) (A ⇒ B)) (idF ∘ —∘—) assoc (h , g , f)
.identity₁ˡ : {- ∀ {A B} {f : A ⇒₁ B} → -} id₁ ∘₁ f ≣ f
identity₁ˡ = ≡F-on-objects (id {B} ∘ idF {C = A ⇒ B}) (πʳ {C = ⊤} {A ⇒ B}) identityˡ (unit , f)
.identity₁ʳ : ∀ {A B} {f : A ⇒₁ B} → f ∘₁ id₁ ≣ f
identity₁ʳ {A} {B} {f} = ≡F-on-objects (idF {C = A ⇒ B} ∘ id {A}) (πˡ {C = A ⇒ B} {⊤}) identityʳ (f , unit)
.vassoc : ∀ {A B} {f g h i : A ⇒₁ B} {η : f ⇒₂ g} {θ : g ⇒₂ h} {ι : h ⇒₂ i} → ((ι • θ) • η) ≡ (ι • (θ • η))
vassoc = loosely vassoc′
.hidentityˡ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (id₁₂ ∘₂ η) ≡ η
hidentityˡ {A} {B} {f} {f′} {η} = Equiv.trans (loosely (∘₂-resp-≡′ (Equiv′.sym (Functor.identity id)) Equiv′.refl)) (identityˡ (unit , η))
.hidentityʳ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (η ∘₂ id₁₂) ≡ η
hidentityʳ {A} {B} {f} {f′} {η} = Equiv.trans (loosely (∘₂-resp-≡′ Equiv′.refl (Equiv′.sym (Functor.identity id)))) (identityʳ (η , unit))
.im-id₂-closed-under-∘₂′ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → id₂ {A = g} ∘₂ id₂ {A = f} ≡′ id₂ {A = g ∘₁ f}
im-id₂-closed-under-∘₂′ = Functor.identity —∘—
.im-id₂-closed-under-∘₂ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → (id₂ {A = g} ∘₂ id₂ {A = f}) ≡ id₂ {A = g ∘₁ f}
im-id₂-closed-under-∘₂ = loosely im-id₂-closed-under-∘₂′
.lidentityˡ′ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → id₂ {A = g} ◃ f ≡′ id₂
lidentityˡ′ = Functor.identity —∘—
.lidentityˡ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → (id₂ {A = g} ◃ f) ≡ id₂ {A = g ∘₁ f}
lidentityˡ = loosely lidentityˡ′
.ridentityʳ′ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → g ▹ id₂ {A = f} ≡′ id₂
ridentityʳ′ = Functor.identity —∘—
.ridentityʳ : ∀ {A B C} {f : A ⇒₁ B} {g : B ⇒₁ C} → (g ▹ id₂ {A = f}) ≡ id₂ {A = g ∘₁ f}
ridentityʳ = loosely ridentityʳ′
-- .lidentityʳ′ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (η ◃ id₁) ≡′ η
-- lidentityʳ′ = ?
.lidentityʳ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (η ◃ id₁) ≡ η
lidentityʳ {η = η} = Equiv.trans (∘₂-resp-≡ Equiv.refl (Equiv.sym (loosely (Functor.identity id)))) (identityʳ (η , unit))
-- .ridentityˡ′ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (id₁ ▹ η) ≡′ η
-- ridentityˡ′ = ?
.ridentityˡ : ∀ {A B} {f f′ : A ⇒₁ B} {η : f ⇒₂ f′} → (id₁ ▹ η) ≡ η
ridentityˡ {η = η} = Equiv.trans (∘₂-resp-≡ (Equiv.sym (loosely (Functor.identity id))) Equiv.refl) (identityˡ (unit , η))
.interchange′ : ∀ {A B C} {f g h : A ⇒₁ B} {i j k : B ⇒₁ C} {α : f ⇒₂ g} {β : g ⇒₂ h} {γ : i ⇒₂ j} {δ : j ⇒₂ k} → ((δ • γ) ∘₂ (β • α)) ≡′ ((δ ∘₂ β) • (γ ∘₂ α))
interchange′ = Functor.homomorphism —∘—
.interchange : ∀ {A B C} {f g h : A ⇒₁ B} {i j k : B ⇒₁ C} {α : f ⇒₂ g} {β : g ⇒₂ h} {γ : i ⇒₂ j} {δ : j ⇒₂ k} → ((δ • γ) ∘₂ (β • α)) ≡ ((δ ∘₂ β) • (γ ∘₂ α))
interchange = loosely interchange′
.lvdistrib′ : ∀ {A B C} {f : A ⇒₁ B} {g h i : B ⇒₁ C} {η : g ⇒₂ h} {θ : h ⇒₂ i} → (θ • η) ◃ f ≡′ ((θ ◃ f) • (η ◃ f))
lvdistrib′ = Equiv′.trans (∘₂-resp-≡′ Equiv′.refl (Equiv′.sym videntityˡ′)) interchange′
.lvdistrib : ∀ {A B C} {f : A ⇒₁ B} {g h i : B ⇒₁ C} {η : g ⇒₂ h} {θ : h ⇒₂ i} → ((θ • η) ◃ f) ≡ ((θ ◃ f) • (η ◃ f))
lvdistrib = loosely lvdistrib′
.rvdistrib′ : ∀ {A B C} {f g h : A ⇒₁ B} {i : B ⇒₁ C} {η : f ⇒₂ g} {θ : g ⇒₂ h} → (i ▹ (θ • η)) ≡′ ((i ▹ θ) • (i ▹ η))
rvdistrib′ = Equiv′.trans (∘₂-resp-≡′ (Equiv′.sym videntityˡ′) Equiv′.refl) interchange′
.rvdistrib : ∀ {A B C} {f g h : A ⇒₁ B} {i : B ⇒₁ C} {η : f ⇒₂ g} {θ : g ⇒₂ h} → (i ▹ (θ • η)) ≡ ((i ▹ θ) • (i ▹ η))
rvdistrib = loosely rvdistrib′
-- XXX mixed assocs still need proving
{-
-- XXX not well-typed without a subst or something
-- .lhassoc′ : ∀ {A B C D} {f : A ⇒₁ B} {g : B ⇒₁ C} {h i : C ⇒₁ D} {η : h ⇒₂ i} → (η ◃ (g ∘₁ f)) ≡′ {!((η ◃ g) ◃ f)!}
-- lhassoc′ = {!!}
.lhassoc : ∀ {A B C D} {f : A ⇒₁ B} {g : B ⇒₁ C} {h i : C ⇒₁ D} {η : h ⇒₂ i} → (η ◃ (g ∘₁ f)) ≡ ((η ◃ g) ◃ f)
lhassoc = {!!}
-- XXX ditto
-- .rlassoc′ : ∀ {A B C D} {f : A ⇒₁ B} {g h : B ⇒₁ C} {i : C ⇒₁ D} {η : g ⇒₂ h} → (i ▹ (η ◃ f)) ≡′ {!((i ▹ η) ◃ f)!}
-- rlassoc′ = {!!}
.rlassoc : ∀ {A B C D} {f : A ⇒₁ B} {g h : B ⇒₁ C} {i : C ⇒₁ D} {η : g ⇒₂ h} → (i ▹ (η ◃ f)) ≡ ((i ▹ η) ◃ f)
rlassoc = {!!}
-- XXX tritto
-- .hrassoc′ : ∀ {A B C D} {f g : A ⇒₁ B} {h : B ⇒₁ C} {i : C ⇒₁ D} {η : f ⇒₂ g} → (i ▹ (h ▹ η)) ≡′ {!((i ∘₁ h) ▹ η)!}
-- hrassoc′ = {!!}
.hrassoc : ∀ {A B C D} {f g : A ⇒₁ B} {h : B ⇒₁ C} {i : C ⇒₁ D} {η : f ⇒₂ g} → (i ▹ (h ▹ η)) ≡ ((i ∘₁ h) ▹ η)
hrassoc = {!!}
-}
.lrsmoosh′ : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((θ ◃ g) • (h ▹ η)) ≡′ (θ ∘₂ η)
lrsmoosh′ = Equiv′.trans (Equiv′.sym interchange′) (∘₂-resp-≡′ videntityʳ′ videntityˡ′)
.lrsmoosh : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((θ ◃ g) • (h ▹ η)) ≡ (θ ∘₂ η)
lrsmoosh = loosely lrsmoosh′
.rlsmoosh′ : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((i ▹ η) • (θ ◃ f)) ≡′ (θ ∘₂ η)
rlsmoosh′ = Equiv′.trans (Equiv′.sym interchange′) (∘₂-resp-≡′ videntityˡ′ videntityʳ′)
.rlsmoosh : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((i ▹ η) • (θ ◃ f)) ≡ (θ ∘₂ η)
rlsmoosh = loosely rlsmoosh′
.lrexch′ : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((i ▹ η) • (θ ◃ f)) ≡′ ((θ ◃ g) • (h ▹ η))
lrexch′ = Equiv′.trans rlsmoosh′ (Equiv′.sym lrsmoosh′)
.lrexch : ∀ {A B C} {f g : A ⇒₁ B} {h i : B ⇒₁ C} {η : f ⇒₂ g} {θ : h ⇒₂ i} → ((i ▹ η) • (θ ◃ f)) ≡ ((θ ◃ g) • (h ▹ η))
lrexch = loosely lrexch′
module Hom₁Reasoning = ≣-reasoning
module Hom₂′Reasoning {A B : Obj} {f g : A ⇒₁ B} where
open imp⇒.HomReasoning {A} {B} {f} {g} public renaming (_⟩∘⟨_ to _⟩•⟨_)
-- XXX won't work if Hom₂′Reasoning is frozen
infixr 4 _⟩∘₂⟨_
._⟩∘₂⟨_ : ∀ {C} {h i : C ⇒₁ A} {α β : f ⇒₂ g} {γ δ : h ⇒₂ i} → α ≡′ β → γ ≡′ δ → (α ∘₂ γ) ≡′ (β ∘₂ δ)
_⟩∘₂⟨_ = ∘₂-resp-≡′
| 46.673267
| 298
| 0.470301
|
38bcf1cdd210992af05d43eb9ad3aaea4a0fed01
| 2,742
|
agda
|
Agda
|
Streams/Streams-old.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
Streams/Streams-old.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
Streams/Streams-old.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --copatterns --sized-types #-}
module Streams where
open import Size
open import Function
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P
open ≡-Reasoning
open import Data.List using (List; module List; []; _∷_; _++_; length)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product using (_,_; _×_; proj₁; proj₂)
-- | Streams (with size annotations to ease definitions).
record Stream {i : Size} (A : Set) : Set where
coinductive
constructor _∷_
field
hd : A
tl : ∀ {j : Size< i} → Stream {j} A
open Stream public
-- | Stream equality is bisimilarity
record _~_ {A : Set} (s t : Stream A) : Set where
coinductive
field
hd~ : hd s ≡ hd t
tl~ : (tl s) ~ (tl t)
open _~_ public
-- | Functoriality
map : ∀ {i A B} (f : A → B) (s : Stream {i} A) → Stream {i} B
hd (map f s) = f (hd s)
tl (map {i} f s) {j} = map {j} f (tl s {j})
-- | Coalgebra structure
str-out : ∀{A} → Stream A → A × Stream A
str-out s = (hd s , tl s)
-- | (Weak) Finality
corec : ∀ {A X : Set} → (X → A × X) → (∀ {i} → X → Stream {i} A)
hd (corec f x) = proj₁ (f x)
tl (corec f x) = corec f (proj₂ (f x))
-- | Direct access to elements
_<_> : ∀{A} → Stream A → ℕ → A
s < 0 > = hd s
s < suc n > = (tl s) < n >
-- | Correctness of bisimlarity
~→pw-equal : ∀{A} {s t : Stream A} →
s ~ t → ∀ n → s < n > ≡ t < n >
~→pw-equal p zero = hd~ p
~→pw-equal p (suc n) = ~→pw-equal (tl~ p) n
-- | The usual definition of a bisimulation on streams.
Is-Bisim : ∀{A} → Rel (Stream A) _ → Set
Is-Bisim _R_ = ∀ x y → x R y → hd x ≡ hd y × (tl x) R (tl y)
-- | If R is a bisimulation then all elements related by R are bisimilar.
ex-bisimulation→bisim : ∀{A R} → Is-Bisim {A} R → ∀ {x y} → R x y → x ~ y
hd~ (ex-bisimulation→bisim p {x} {y} xRy) = proj₁ (p x y xRy)
tl~ (ex-bisimulation→bisim p {x} {y} xRy) =
ex-bisimulation→bisim p (proj₂ (p x y xRy))
-- | Generalised bisimulations between arbitrary stream coalgebras.
Is-Bisim' : ∀{A X Y : Set} → (c : X → A × X) (d : Y → A × Y) → REL X Y _ → Set
Is-Bisim' c d _R_ = ∀ x y → x R y →
proj₁ (c x) ≡ proj₁ (d y) ×
(proj₂ (c x)) R (proj₂ (d y))
ex-bisimulation→bisim' : ∀{A X Y R c d} → Is-Bisim' {A} {X} {Y} c d R →
∀ {x y} → R x y → corec c x ~ corec d y
hd~ (ex-bisimulation→bisim' p {x} {y} xRy) = proj₁ (p x y xRy)
tl~ (ex-bisimulation→bisim' p {x} {y} xRy) =
ex-bisimulation→bisim' p (proj₂ (p x y xRy))
~trans : ∀{A} {r s t : Stream A} → r ~ s → s ~ t → r ~ t
hd~ (~trans p q) = trans (hd~ p) (hd~ q)
tl~ (~trans p q) = ~trans (tl~ p) (tl~ q)
~sym : ∀{A} {s t : Stream A} → s ~ t → t ~ s
hd~ (~sym p) = sym (hd~ p)
tl~ (~sym p) = ~sym (tl~ p)
| 31.883721
| 78
| 0.551422
|
4e29f5caee63b7169687e45144c283f914a93060
| 14,430
|
agda
|
Agda
|
examples/outdated-and-incorrect/syntax/Syntax.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/syntax/Syntax.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/syntax/Syntax.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{- An agda file contains a single module. The module name should correspond to
the name and path of the file. The path is relative to the project root. In
this case the project root is the root of Agda II. Modules can be
parameterised, but in this case we choose not to parameterise the top-level
module.
-}
module examples.syntax.Syntax where
-- It is recommended that the body of the top-level module is indented by a
-- small amount, but this is not enforced in the syntax.
-- You can have modules inside modules. The name of a sub-module isn't
-- qualified.
module Expressions (X : Set)(x1, x2 : X) where
-- There are three forms of sorts. Set = Set0.
postulate A1 : Set
A2 : Set3
A3 : Prop
-- Independent function space.
fun1 : X -> X
fun1 x = x
-- Implicit independent function space. This is mostly included for
-- symmetry, I can't come up with an example when this would be useful.
fun2 : {X} -> X
fun2 {x} = x
-- Dependent function space.
fun3 : (A:Set) -> A -> A
fun3 A x = x
-- Implicit dependent function space. 'A' is implicit so we don't have to
-- write it out in the function definition.
fun4 : {A:Set} -> A -> A
fun4 x = x
-- You can also write independent functions using the dependent function
-- space syntax. Not that you'd ever want to.
fun5 : (_:X) -> X
fun5 x = x
-- Lambdas can be domain free.
const1 : {A, B : Set} -> A -> B -> A
const1 = \x y -> x
-- Or completely typed.
const2 = \{A:Set}{B:Set}(x:A)(y:B) -> x -- inferable, no type needed
-- You cannot mix typed and untyped arguments in the same lambda.
const3 : {A, B : Set} -> A -> B -> A
const3 = \{A}{B} -> \(x:A)(y:B) -> x
-- You can have wildcards in lambdas
const4 : {A, B : Set} -> A -> B -> A
const4 = \x _ -> x
-- Implicit arguments can be omitted in applications.
x = const1 x1 x2
-- Or made explicit.
x' = const1 {X} {X} x1 x2
-- Infix operators can be bound by lambdas. See ComplexDeclarations for
-- more information about infix operators.
dup : {A:Set} -> (A -> A -> A) -> A -> A
dup = \(+) x -> x + x
-- The two basic declarations are function definitions and datatype
-- declarations.
module BasicDeclarations (X : Set) where
-- The most common declaration is the function definition. It consists of
-- two parts; a type signature and a set of function clauses. Type
-- signatures have the form 'id : type', no telescopes are allowed at this
-- point. This can be discussed.
id : X -> X
id x = x
-- You can omit the type signature if the type can be inferred.
id' = id
-- Datatypes are introduced with the data keyword.
data Bool : Set where
false : Bool
true : Bool
-- The parameters to the datatype (A in this case) are in scope in the
-- types of the constructors. At the moment inductive families are not
-- supported.
data List (A : Set) : Set where
nil : List A
(::) : A -> List A -> List A
-- When using a constructor as a function, the parameters are hidden
-- arguments.
singleton : X -> List X
singleton x = x :: nil
singleton' : X -> List X
singleton' x = (::) {X} x (nil {X})
-- You can pattern match over elements of a datatype when defining
-- functions (and only then).
null : (A : Set) -> List A -> Bool
null A nil = true
null A (x::xs) = false
-- Patterns can be nested (and functions can be recursive).
and : List Bool -> Bool
and nil = true
and (true::xs) = and xs
and (false::xs) = false
-- Functions can be defined in an infix style. When doing this it must be
-- clear what name is being defined without looking at fixities. Hence we
-- could never remove the parenthesis around x::xs in the second clause.
(++) : List X -> List X -> List X
nil ++ ys = ys
(x::xs) ++ ys = x :: (xs ++ ys)
-- You can also use a combination of infix and prefix.
(@) : {A, B, C : Set} -> (B -> C) -> (A -> B) -> A -> C
(f @ g) x = f (g x)
-- Declarations can appear in many different contexts and not all
-- declarations are allowed everywhere.
module ComplexDeclarations (X : Set) where
-- You can introduce new constants with the postulate declaration. A
-- postulate declaration takes a list of type signatures.
postulate A : Set
a : A
-- Let's introduce some datatypes so we have something to work with. At the
-- same time we illustrate that layout is optional.
data Nat : Set where { zero : Nat; suc : Nat -> Nat }
data Bool : Set where { false : Bool; true : Bool }
{- We can declare the fixity of infix symbols. The fixity is tied to a
particular binding of a name. The binding doesn't have to be in scope
directly (as in the example below), but it should be possible to bring
it into scope by moving the fixity declaration further down in the
current block (but never inside things).
The following wouldn't be allowed:
infixl 15 +
mutual
(+) : Nat -> Nat -> Nat
..
There are three forms: infix, infixl and infixr, for non-associative,
left associative and right associative respectively. The number is the
precedence level.
-}
infixl 15 +, `plus`
(+) : Nat -> Nat -> Nat
n + zero = zero
n + suc m = suc (n + m)
plus = (+)
-- The following code is to stress test the handling of infix applications.
infixl 10 @
infixl 11 @@
infixr 10 #
infixr 11 ##
postulate
(@) : Nat -> Nat -> Nat
(#) : Nat -> Nat -> Nat
(@@) : Nat -> Nat -> Nat
(##) : Nat -> Nat -> Nat
z = zero
test1 = z @ (z # z)
test2 = (z @ z) # z
test3 = z # (z @ z)
test4 = (z # z) @ z
test5 = z ## z # z ## z # z
test6 = z @@ z @ z @@ z @ z
test7 = z # z @@ z @@ z # z
-- Mutually recursive definition are introduced using the 'mutual' keyword.
-- A mutual block can contain function definitions, datatypes
-- (induction-recursion) and fixity declarations.
mutual
even : Nat -> Bool
even zero = true
even (suc n) = odd n
odd : Nat -> Bool
odd zero = false
odd (suc n) = even n
-- If a function is declared abstract the definition of the function is not
-- visible outside the module. For an abstract datatype the constructors
-- are hidden. Definitions that can appear in an abstract block are:
-- function definitions, data declarations, fixity declarations, mutual
-- blocks, open and name space declarations (see NameSpaces).
abstract
data Stack : Set where
nil : Stack
cons : A -> Stack -> Stack
empty : Stack
empty = nil
push : A -> Stack -> Stack
push = cons
-- Local declarations are introduces either with a let or in a where
-- clause. A where clause is attached to a function clause. Everything that
-- can appear in an abstract block can appear in a local declaration, plus
-- abstract blocks. Local functions can be recursive.
foo : (A : Set) -> A -> A
foo A x = let f : Local -> A
f (local y) = y
in f (local x)
where
data Local : Set where
local : A -> Local
-- You can declare things to be private to the current module. This means
-- that they cannot be accessed outside the module (but they're still
-- visible inside the module and its submodules). The only things that
-- cannot appear in a private block are other private blocks and import
-- statements.
private
bar : X -> X
bar x = x
-- Private declarations can go inside mutual and abstract blocks.
mutual
private f : Nat -> Nat
f zero = zero
f (suc n) = g n
g : Nat -> Nat
g n = f n
abstract
Nat' : Set
Nat' = Nat
private h : Nat' -> Nat
h n = n
-- A name space is something that contains names. You can create new
-- name spaces and bring names from a name space into scope.
module NameSpaces where
-- To access definitions from a module in a different file, you have to
-- 'import' this module. Only top-level modules (which have their own
-- files) can be imported.
-- If the imported module is not parameterised a name space with the same
-- name as the module is created.
import examples.syntax.ModuleA
-- We can now refer to things from ModuleA using the created name
-- space. Note that no unqualified names were brought into scope
-- (except, perhaps, the name of the name space). [To bring
-- unqualified names into scope we have to use the 'open'
-- declaration.]
FunnyNat = examples.syntax.ModuleA.Nat
-- If the name of an imported module clashes with a local module we might
-- have to rename the module we are importing
import examples.syntax.ModuleA as A
import examples.syntax.ModuleA as A' using (Nat)
Nat1 = A.Nat
Nat2 = A'.Nat
{- You can't project from a parameterised module. It has to be
instantiated first. The only thing that happens when importing
is that the module name 'examples.syntax.ModuleB' is brought
into scope (and the type checker goes away and type checks this
module).
-}
import examples.syntax.ModuleB
-- To instantiate ModuleB we need something to instantiate it with.
postulate X : Set
(==) : X -> X -> Prop
refl : (x : X) -> x == x
-- To instantiate a module you create a new module and define it as the
-- instantiation in question.
module B = examples.syntax.ModuleB X (==) refl
-- Now the module B contains all the names from ModuleB.
XList = B.List
And = B./\ -- qualified operators are not infix symbols
dummyX = B.SubModule.dummy -- submodules of ModuleB are also in scope
-- This of course works for non-parameterised modules as well.
module B' = B
-- And you can create parameterised modules this way.
module BX ((==) : X -> X -> Prop)(refl : (x : X) -> x == x) = B X (==) refl
-- To bring names from a module into scope you use an open declaration.
open examples.syntax.ModuleA
two : FunnyNat
two = eval (plus (suc zero) (suc zero))
{- In all three declarations (import, module instantiation and open) you
can give modifiers that affect the names which are imported. There are
three modifiers:
using (x1;..;xn) only import x1,..,xn
hiding (x1;..;xn) import everything but x1,..,xn
renaming (x1 to y1;..;xn to yn) import x1,..,xn but call them y1,..,yn
Restrictions:
- a modifier can appear only once
- 'using' and 'hiding' cannot appear together
- imported names must be distinct (e.g. you cannot rename to a name
that is already being imported).
-}
-- B1 only contains True and False
module B1 = B using (True; False)
-- B2 contains True, False and And where And = B./\
module B2 = B using (True; False) renaming (/\ to And)
-- B3 contains everything from B except reflEqList and eqList, plus ===
-- where (===) = B.eqList.
module B3 = B hiding (reflEqList) renaming (eqList to ===)
-- When referring to sub modules you have to be explicitly about it being
-- a module
module B4 = B renaming (module SubModule to Sub)
dummy : X
dummy = B4.Sub.dummy
-- There are two kinds of meta variables; question marks and underscores.
-- Question marks are used for interaction and underscores for implicit
-- arguments.
module MetaVariables where
postulate X : Set
x : X
-- There are two ways of writing a question mark: ? and {! ... !}
-- The type checker will not complain about unsolved question marks (unless
-- you claim you are done).
incomplete : {A:Set} -> A -> A
incomplete x = ?
incomplete' : {A:Set} -> A -> A
incomplete' x = {! you can put anything in here,
even {! nested holes !}
!}
-- Underscores should always be solvable locally. Internally underscores
-- are inserted for implicit arguments, but there are cases where you would
-- like to write them explicitly. For instance, if you want to give one but
-- not all implicit arguments to a function explicitly.
underscore : ({A,B,C:Set} -> (A -> A) -> B -> C) -> X
underscore f = f {_} {X} {_} (\y -> y) x
-- Note that '_' is not an identifier character. The current use of
-- underscore is not the real reason for this. The idea is rather that
-- underscore will be used for subscripts.
id : (A : Set) -> A -> A
id A x = x
x' = id_x -- this means id _ x
-- The parser supports four types of literals. The syntax is the same as in
-- Haskell (since that meant I could steal the lexer for them from ghc).
module Literals where
-- We haven't decided how to handle built-in types.
postulate Integer : Set
Char : Set
String : Set
Float : Set
fortyTwo : Integer
fortyTwo = 42
helloWorld : String
helloWorld = "Hello World!"
escape : Char
escape = '\ESC'
pi : Float
pi = 3.141592
-- There are few things that the parser doesn't implement.
{- Fancy case. I haven't been able to come up with a nice syntax for the
fancy case statement. The difficulty is that we should make it clear
what arguments to the elimination rule will appear as patterns (the
targets). Suggestions are welcome.
Also I'm not sure that we want the fancy case. It would be better to
have a good way of doing actual pattern matching on inductive families.
-}
{- Relative imports. You might want to be able to say
import .ModuleA
to import the module 'current.directory.ModuleA'. Easy to implement but
I'm not sure it's that painful to write the complete name (not a problem
in Haskell for instance). Drawbacks: it looks kind of funny and it adds
an extra bit of syntax to remember.
-}
| 33.714953
| 79
| 0.615246
|
372c1a78194a44f6a4cecc1f5edb68723147f69d
| 331
|
agda
|
Agda
|
test/Succeed/ImportWarningsB.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 1
|
2016-03-17T01:45:59.000Z
|
2016-03-17T01:45:59.000Z
|
test/Succeed/ImportWarningsB.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/ImportWarningsB.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
{-# OPTIONS -W ignore #-}
module ImportWarningsB where
-- all of the following files have warnings, which should be displayed
-- when loading this file
import Issue1988
import Issue2243
import Issue708quote
import OldCompilerPragmas
import RewritingEmptyPragma
import Unreachable
-- this warning will be ignored
{-# REWRITE #-}
| 20.6875
| 70
| 0.791541
|
Subsets and Splits
HTML Code Excluding Scripts
The query retrieves a limited set of HTML content entries that are longer than 8 characters and do not contain script tags, offering only basic filtering with minimal analytical value.