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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
22ff552eb7ef647791edf5246b1e83a9862ccf14
| 21,407
|
agda
|
Agda
|
src/to-string.agda
|
ice1000/cedille
|
bf62d3d338809a30bc21a1affed07936b1ac60ac
|
[
"MIT"
] | null | null | null |
src/to-string.agda
|
ice1000/cedille
|
bf62d3d338809a30bc21a1affed07936b1ac60ac
|
[
"MIT"
] | null | null | null |
src/to-string.agda
|
ice1000/cedille
|
bf62d3d338809a30bc21a1affed07936b1ac60ac
|
[
"MIT"
] | null | null | null |
import cedille-options
module to-string (options : cedille-options.options) where
open import cedille-types
open import constants
open import syntax-util
open import ctxt
open import rename
open import general-util
open import datatype-util
open import type-util
open import free-vars
open import json
data expr-side : Set where
left : expr-side
right : expr-side
neither : expr-side
is-left : expr-side → 𝔹
is-left left = tt
is-left _ = ff
is-right : expr-side → 𝔹
is-right right = tt
is-right _ = ff
exprd-eq : exprd → exprd → 𝔹
exprd-eq TERM TERM = tt
exprd-eq TYPE TYPE = tt
exprd-eq KIND KIND = tt
exprd-eq _ _ = ff
is-eq-op : {ed : exprd} → ⟦ ed ⟧ → 𝔹
is-eq-op{TERM} (VarSigma _) = tt
is-eq-op{TERM} (Rho _ _ _ _) = tt
is-eq-op{TERM} (Phi _ _ _) = tt
is-eq-op{TERM} (Delta _ _ _) = tt
is-eq-op _ = ff
pattern arrow-var = "_arrow_"
pattern TpArrow tp me tp' = TpAbs me arrow-var (Tkt tp) tp'
pattern KdArrow tk kd = KdAbs arrow-var tk kd
is-arrow : {ed : exprd} → ⟦ ed ⟧ → 𝔹
is-arrow {TYPE} (TpArrow _ _ _) = tt
is-arrow {KIND} (KdArrow _ _) = tt
is-arrow _ = ff
is-type-level-app : ∀ {ed} → ⟦ ed ⟧ → 𝔹
is-type-level-app {TYPE} (TpApp T tT) = tt
is-type-level-app _ = ff
{- need-parens e1 e2 s
returns tt iff we need parens when e1 occurs as the given
side s of parent expression e2. -}
need-parens : {ed : exprd} → {ed' : exprd} → ⟦ ed ⟧ → ⟦ ed' ⟧ → expr-side → 𝔹
need-parens {TYPE} {TYPE} (TpAbs _ _ _ _) (TpArrow _ _ _) left = tt
need-parens {TYPE} {TYPE} (TpIota _ _ _) (TpArrow _ _ _) left = tt
need-parens {KIND} {KIND} (KdAbs _ _ _) (KdArrow _ _) left = tt
need-parens {TYPE} {KIND} (TpAbs _ _ _ _) (KdArrow _ _) left = tt
need-parens {TYPE} {KIND} (TpIota _ _ _) (KdArrow _ _) left = tt
need-parens {TERM} {_} (Var x) p lr = ff
need-parens {TERM} {_} (Hole pi) p lr = ff
need-parens {TERM} {_} (IotaPair t₁ t₂ x Tₓ) p lr = ff
need-parens {TERM} {_} (IotaProj t n) p lr = ff
need-parens {TYPE} {_} (TpVar x) p lr = ff
need-parens {TYPE} {_} (TpEq t₁ t₂) p lr = ff
need-parens {TYPE} {_} (TpHole pi) p lr = ff
need-parens {KIND} {_} (KdHole pi) p lr = ff
need-parens {KIND} {_} KdStar p lr = ff
need-parens {_} {TERM} _ (IotaPair t₁ t₂ x Tₓ) lr = ff
need-parens {_} {TYPE} _ (TpEq t₁ t₂) lr = ff
need-parens {_} {TERM} _ (Beta ot ot') lr = ff
need-parens {_} {TERM} _ (Phi tₑ t₁ t₂) lr = is-left lr
need-parens {_} {TERM} _ (Rho _ _ _ _) right = ff
need-parens {_} {TERM} _ (Delta _ _ _) right = ff
need-parens {_} {TERM} _ (LetTm _ _ _ _ _) lr = ff
need-parens {_} {TERM} _ (LetTp _ _ _ _) lr = ff
need-parens {_} {TERM} _ (Lam _ _ _ _) lr = ff
need-parens {_} {TERM} _ (Mu _ _ _ _ _) right = ff
need-parens {_} {TYPE} _ (TpLam _ _ _) lr = ff
need-parens {_} {TYPE} _ (TpAbs _ _ _ _) lr = ff
need-parens {_} {KIND} _ (KdAbs _ _ _) neither = ff
need-parens {_} {TYPE} _ (TpIota _ _ _) lr = ff
need-parens {TERM} {_} (App t t') p lr = tt
need-parens {TERM} {_} (AppE t tT) p lr = tt
need-parens {TERM} {_} (Beta ot ot') p lr = ff
need-parens {TERM} {_} (Delta _ T t) p lr = tt
need-parens {TERM} {_} (Lam me x tk? t) p lr = tt
need-parens {TERM} {_} (LetTm me x T t t') p lr = tt
need-parens {TERM} {_} (LetTp x T t t') p lr = tt
need-parens {TERM} {_} (Phi tₑ t₁ t₂) p lr = tt
need-parens {TERM} {_} (Rho tₑ x Tₓ t) p lr = tt
need-parens {TERM} {_} (VarSigma t) p lr = ~ is-eq-op p
need-parens {TERM} {_} (Mu _ _ _ _ _) p lr = tt
need-parens {TERM} {_} (Sigma _ _ _ _ _) p lr = tt
need-parens {TYPE} {e} (TpAbs me x tk T) p lr = ~ exprd-eq e TYPE || ~ is-arrow p || is-left lr
need-parens {TYPE} {_} (TpIota x T₁ T₂) p lr = tt
need-parens {TYPE} {_} (TpApp T tT) p lr = ~ is-arrow p && (~ is-type-level-app p || is-right lr)
need-parens {TYPE} {_} (TpLam x tk T) p lr = tt
need-parens {KIND} {_} (KdAbs x tk k) p lr = ~ is-arrow p || is-left lr
pattern ced-ops-drop-spine = cedille-options.options.mk-options _ _ _ _ ff _ _ _ ff _ _
pattern ced-ops-conv-arr = cedille-options.options.mk-options _ _ _ _ _ _ _ _ ff _ _
pattern ced-ops-conv-abs = cedille-options.options.mk-options _ _ _ _ _ _ _ _ tt _ _
drop-spine : cedille-options.options → {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
drop-spine ops @ ced-ops-drop-spine = h
where
drop-mod-argse : (mod : args) → (actual : args) → args
drop-mod-argse (ArgE _ :: asₘ) (ArgE _ :: asₐ) = drop-mod-argse asₘ asₐ
drop-mod-argse (Arg _ :: asₘ) (Arg t :: asₐ) = drop-mod-argse asₘ asₐ
drop-mod-argse (_ :: asₘ) asₐ@(Arg t :: _) = drop-mod-argse asₘ asₐ
-- ^ Relevant term arg, so wait until we find its corresponding relevant module arg ^
drop-mod-argse _ asₐ = asₐ
drop-mod-args-term : ctxt → var × args → term
drop-mod-args-term Γ (v , as) =
let uqv = unqual-all (ctxt.qual Γ) v in
flip recompose-apps (Var uqv) $
maybe-else' (ifMaybe (~ v =string uqv) $ ctxt-get-qi Γ uqv)
as λ qi → drop-mod-argse (snd qi) as
drop-mod-args-type : ctxt → var × 𝕃 tmtp → type
drop-mod-args-type Γ (v , as) =
let uqv = unqual-all (ctxt.qual Γ) v in
flip recompose-tpapps (TpVar uqv) $
maybe-else' (ifMaybe (~ v =string uqv) $ ctxt-qualif-args-length Γ Erased uqv)
as λ n → drop n as
h : {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
h {TERM} Γ t = maybe-else' (decompose-var-headed t) t (drop-mod-args-term Γ)
h {TYPE} Γ T = maybe-else' (decompose-tpvar-headed T) T (drop-mod-args-type Γ)
h Γ x = x
drop-spine ops Γ x = x
to-string-rewrite : {ed : exprd} → ctxt → cedille-options.options → ⟦ ed ⟧ → Σi exprd ⟦_⟧
to-string-rewrite{TYPE} Γ ced-ops-conv-arr (TpAbs me x (Tkt T) T') = , TpAbs me (if is-free-in x T' then x else arrow-var) (Tkt T) T'
to-string-rewrite{KIND} Γ ced-ops-conv-arr (KdAbs x tk k) = , KdAbs (if is-free-in x k then x else arrow-var) tk k
to-string-rewrite{TERM} Γ ops (VarSigma t) with to-string-rewrite Γ ops t
...| ,_ {TERM} (VarSigma t') = , t'
...| t? = , VarSigma t
to-string-rewrite Γ ops x = , drop-spine ops Γ x
-------------------------------
open import pretty
use-newlines : 𝔹
use-newlines =
~ iszero (cedille-options.options.pretty-print-columns options)
&& cedille-options.options.pretty-print options
doc-to-rope : DOC → rope
doc-to-rope = if use-newlines
then pretty (cedille-options.options.pretty-print-columns options)
else flatten-out
strM : Set
strM = {ed : exprd} → DOC → ℕ → 𝕃 tag → ctxt → maybe ⟦ ed ⟧ → expr-side → DOC × ℕ × 𝕃 tag
strEmpty : strM
strEmpty s n ts Γ pe lr = s , n , ts
to-stringh : {ed : exprd} → ⟦ ed ⟧ → strM
strM-Γ : (ctxt → strM) → strM
strM-Γ f s n ts Γ = f Γ s n ts Γ
infixr 2 _>>str_
_>>str_ : strM → strM → strM
(m >>str m') s n ts Γ pe lr with m s n ts Γ pe lr
(m >>str m') s n ts Γ pe lr | s' , n' , ts' = m' s' n' ts' Γ pe lr
strAdd : string → strM
strAdd s s' n ts Γ pe lr = s' <> TEXT [[ s ]] , n + string-length s , ts
strLine : strM
strLine s n ts Γ pe lr = s <> LINE , suc n , ts
strNest : ℕ → strM → strM
strNest i m s n ts Γ pe lr with m nil n ts Γ pe lr
...| s' , n' , ts' = s <> nest i s' , n' , ts'
strFold' : (ℕ → ℕ) → {ed : exprd} → 𝕃 (ℕ × strM) → ℕ → 𝕃 tag → ctxt → maybe ⟦ ed ⟧ → expr-side → 𝕃 (ℕ × DOC) × ℕ × 𝕃 tag
strFold' l [] n ts Γ pe lr = [] , n , ts
strFold' l ((i , x) :: []) n ts Γ pe lr with x nil n ts Γ pe lr
...| sₓ , nₓ , tsₓ = [ i , sₓ ] , nₓ , tsₓ
strFold' l ((i , x) :: xs) n ts Γ pe lr with x nil n ts Γ pe lr
...| sₓ , nₓ , tsₓ with strFold' l xs (l nₓ) tsₓ Γ pe lr
...| sₓₛ , nₓₛ , tsₓₛ = (i , sₓ) :: sₓₛ , nₓₛ , tsₓₛ
strFold : (ℕ → ℕ) → (𝕃 (ℕ × DOC) → DOC) → 𝕃 (ℕ × strM) → strM
strFold l f ms s n ts Γ pe lr with strFold' l ms n ts Γ pe lr
...| s' , n' , ts' = s <> f s' , n' , ts'
strFoldi : ℕ → (ℕ → ℕ) → (𝕃 DOC → DOC) → 𝕃 strM → strM
strFoldi i l f = strNest i ∘' strFold suc (f ∘' map snd) ∘' map (_,_ 0)
-- Either fit all args on one line, or give each their own line
strList : ℕ → 𝕃 strM → strM
strList i = strFoldi i suc λ ms → flatten (spread ms) :<|> stack ms
-- Fit as many args on each line as possible
-- (n = number of strM args)
-- (𝕃 strM so that optional args (nil) are possible)
strBreak : (n : ℕ) → fold n strM λ X → ℕ → 𝕃 strM → X
strBreak = h [] where
h : 𝕃 (ℕ × strM) → (n : ℕ) → fold n strM λ X → ℕ → 𝕃 strM → X
h ms (suc n) i m = h (map (_,_ i) m ++ ms) n
h ms zero = strFold suc filln $ reverse ms
strBracket : char → strM → char → strM
strBracket l m r s n ts Γ pe lr with m nil (suc (suc n)) ts Γ pe lr
...| s' , n' , ts' = s <> bracket (char-to-string l) s' (char-to-string r) , suc (suc n') , ts'
strΓ' : defScope → var → strM → strM
strΓ' ds v m s n ts Γ =
let gl = ds iff globalScope
v' = if gl then (ctxt.mn Γ # v) else v in
m s n ts
(record Γ {
qual = qualif-insert-params (ctxt.qual Γ) v' (unqual-local v) (if gl then ctxt.ps Γ else []);
i = trie-insert (ctxt.i Γ) v' (var-decl , missing-location)
})
strΓ : var → strM → strM
strΓ x m s n ts Γ = m s n ts (ctxt-var-decl x Γ)
ctxt-get-file-id : ctxt → (filename : string) → ℕ
ctxt-get-file-id = trie-lookup-else 0 ∘ ctxt.id-map
make-loc-tag : ctxt → (filename start-to end-to : string) → (start-from end-from : ℕ) → tag
make-loc-tag Γ fn s e = make-tag "loc"
(("fn" , json-nat (ctxt-get-file-id Γ fn)) ::
("s" , json-raw [[ s ]]) :: ("e" , json-raw [[ e ]]) :: [])
var-loc-tag : ctxt → location → var → 𝕃 (string × 𝕃 tag)
var-loc-tag Γ ("missing" , "missing") x = []
var-loc-tag Γ ("" , _) x = []
var-loc-tag Γ (_ , "") x = []
var-loc-tag Γ (fn , pi) x =
let fn-tag = "fn" , json-nat (ctxt-get-file-id Γ fn)
s-tag = "s" , json-raw [[ pi ]]
e-tag = "e" , json-raw [[ posinfo-plus-str pi x ]] in
[ "loc" , fn-tag :: s-tag :: e-tag :: [] ]
var-tags : ctxt → var → var → 𝕃 (string × 𝕃 tag)
var-tags Γ qv uqv =
(if qv =string qualif-var Γ uqv then id else ("shadowed" , []) ::_)
(var-loc-tag Γ (ctxt-var-location Γ qv) uqv)
strAddTags : string → 𝕃 (string × 𝕃 tag) → strM
strAddTags sₙ tsₙ sₒ n tsₒ Γ pe lr =
let n' = n + string-length sₙ in
sₒ <> TEXT [[ sₙ ]] , n' , map (uncurry λ k vs → make-tag k vs n n') tsₙ ++ tsₒ
strVar : var → strM
strVar v = strM-Γ λ Γ →
let uqv = unqual-local v -- $ unqual-all (ctxt-get-qualif Γ) v
uqv' = if cedille-options.options.show-qualified-vars options then v else uqv in
strAddTags uqv' (var-tags Γ (qualif-var Γ v) uqv)
strKvar : var → strM
strKvar v = strM-Γ λ Γ → strVar (unqual-all (ctxt.qual Γ) v)
-- Only necessary to unqual-local because of module parameters
strBvar : var → (class body : strM) → strM
strBvar v cm bm = strAdd (unqual-local v) >>str cm >>str strΓ' localScope v bm
strMetaVar : var → span-location → strM
strMetaVar x (fn , pi , pi') s n ts Γ pe lr =
let n' = n + string-length x in
s <> TEXT [[ x ]] , n' , make-loc-tag Γ fn pi pi' n n' :: ts
{-# TERMINATING #-}
term-to-stringh : term → strM
type-to-stringh : type → strM
kind-to-stringh : kind → strM
ctr-to-string : ctr → strM
case-to-string : case → strM
cases-to-string : cases → strM
caseArgs-to-string : case-args → strM → strM
params-to-string : params → strM
params-to-string' : strM → params → strM
params-to-string'' : params → strM → strM
optTerm-to-string : maybe term → char → char → 𝕃 strM
optClass-to-string : maybe tpkd → strM
optType-to-string : maybe char → maybe type → 𝕃 strM
arg-to-string : arg → strM
args-to-string : args → strM
binder-to-string : erased? → string
lam-to-string : erased? → string
arrowtype-to-string : erased? → string
vars-to-string : 𝕃 var → strM
bracketL : erased? → string
bracketR : erased? → string
braceL : erased? → string
braceR : erased? → string
opacity-to-string : opacity → string
hole-to-string : posinfo → strM
to-string-ed : {ed : exprd} → ⟦ ed ⟧ → strM
to-string-ed{TERM} = term-to-stringh
to-string-ed{TYPE} = type-to-stringh
to-string-ed{KIND} = kind-to-stringh
to-stringh' : {ed : exprd} → expr-side → ⟦ ed ⟧ → strM
to-stringh' {ed} lr t {ed'} s n ts Γ mp lr' =
elim-Σi (to-string-rewrite Γ options t) λ t' →
parens-if (maybe𝔹 mp (λ pe → need-parens t' pe lr)) (to-string-ed t') s n ts Γ (just t') lr
where
parens-if : 𝔹 → strM → strM
parens-if p s = if p then (strAdd "(" >>str strNest 1 s >>str strAdd ")") else s
to-stringl : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringr : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringl = to-stringh' left
to-stringr = to-stringh' right
to-stringh = to-stringh' neither
set-parent : ∀ {ed} → ⟦ ed ⟧ → strM → strM
set-parent t m s n ts Γ _ lr = m s n ts Γ (just t) lr
apps-to-string : ∀ {ll : 𝔹} → (if ll then term else type) → strM
apps-to-string {tt} t with decompose-apps t
...| tₕ , as = set-parent t $ strList 2
(to-stringl tₕ :: map arg-to-string as)
apps-to-string {ff} T with decompose-tpapps T
...| Tₕ , as = set-parent T $ strList 2
(to-stringl Tₕ :: map arg-to-string (tmtps-to-args ff as))
lams-to-string : term → strM
lams-to-string t =
elim-pair (decompose-lams-pretty t) λ xs b →
set-parent t $ strFold suc filln $ foldr {B = 𝕃 (ℕ × strM)}
(λ {(x , me , oc) r →
(1 , (strAdd (lam-to-string me) >>str strAdd " " >>str
strBvar x (strNest 4 (optClass-to-string oc)) (strAdd " ."))) ::
map (map-snd $ strΓ' localScope x) r}) [ 2 , to-stringr b ] xs
where
decompose-lams-pretty : term → 𝕃 (var × erased? × maybe tpkd) × term
decompose-lams-pretty = h [] where
h : 𝕃 (var × erased? × maybe tpkd) → term → 𝕃 (var × erased? × maybe tpkd) × term
h acc (Lam me x oc t) = h ((x , me , oc) :: acc) t
h acc t = reverse acc , t
term-to-stringh (App t t') = apps-to-string (App t t')
term-to-stringh (AppE t tT) = apps-to-string (AppE t tT)
term-to-stringh (Beta t t') = strBreak 3
0 [ strAdd "β" ]
2 [ strAdd "<" >>str to-stringh (erase t ) >>str strAdd ">" ]
2 [ strAdd "{" >>str to-stringh (erase t') >>str strAdd "}" ]
term-to-stringh (Delta _ T t) = strBreak 3
0 [ strAdd "δ" ]
2 [ to-stringl T >>str strAdd " -" ]
1 [ to-stringr t ]
term-to-stringh (Hole pi) = hole-to-string pi
term-to-stringh (IotaPair t₁ t₂ x Tₓ) = strBreak 3
1 [ strAdd "[ " >>str to-stringh t₁ >>str strAdd "," ]
1 [ to-stringh t₂ ]
1 [ strAdd "@ " >>str
strBvar x (strAdd " . ") (strNest (5 + string-length x) (to-stringh Tₓ)) >>str
strAdd " ]" ]
term-to-stringh (IotaProj t n) = to-stringh t >>str strAdd (if n iff ι1 then ".1" else ".2")
term-to-stringh (Lam me x oc t) = lams-to-string (Lam me x oc t)
term-to-stringh (LetTm me x T t t') = strBreak 4
1 [ strAdd (bracketL me) >>str strAdd (unqual-local x) ]
5 ( optType-to-string (just ':') T )
3 [ strAdd "= " >>str to-stringh t >>str strAdd (bracketR me) ]
1 [ strΓ' localScope x (to-stringr t') ]
term-to-stringh (LetTp x k T t) = strBreak 4
1 [ strAdd (bracketL NotErased) >>str strAdd (unqual-local x) ]
5 [ strAdd ": " >>str to-stringh k ]
3 [ strAdd "= " >>str to-stringh T >>str strAdd (bracketR NotErased) ]
1 [ strΓ' localScope x (to-stringr t) ]
term-to-stringh (Phi tₑ t₁ t₂) = strBreak 3
0 [ strAdd "φ " >>str to-stringl tₑ >>str strAdd " -" ]
2 [ to-stringh t₁ ]
2 [ strAdd "{ " >>str to-stringr (erase t₂) >>str strAdd " }" ]
term-to-stringh (Rho tₑ x Tₓ t) = strBreak 3
0 [ strAdd "ρ " >>str to-stringl tₑ ]
1 [ strAdd "@ " >>str strBvar x (strAdd " . ") (to-stringh (erase Tₓ)) ]
1 [ strAdd "- " >>str strNest 2 (to-stringr t) ]
term-to-stringh (VarSigma t) = strAdd "ς " >>str to-stringh t
term-to-stringh (Var x) = strVar x
term-to-stringh (Mu x t ot t~ cs) =
strAdd "μ " >>str
strBvar x
(strAdd " . " >>str strBreak 2
2 [ to-stringl t ]
3 ( optType-to-string (just '@') ot ))
(strAdd " " >>str strBracket '{' (cases-to-string cs) '}')
term-to-stringh (Sigma ot t oT t~ cs) =
strAdd "σ " >>str strBreak 3
2 (maybe-else' {B = 𝕃 strM} ot []
λ t → [ strAdd "<" >>str to-stringh t >>str strAdd ">" ])
2 [ to-stringl t ]
3 ( optType-to-string (just '@') oT ) >>str
strAdd " " >>str strBracket '{' (cases-to-string cs) '}'
type-to-stringh (TpArrow T a T') = strBreak 2
2 [ to-stringl T >>str strAdd (arrowtype-to-string a) ]
2 [ to-stringr T' ]
type-to-stringh (TpAbs me x tk T) = strBreak 2
3 [ strAdd (binder-to-string me ^ " ") >>str
strBvar x (strAdd " : " >>str to-stringl -tk' tk >>str strAdd " .") strEmpty ]
1 [ strΓ' localScope x (to-stringh T) ]
type-to-stringh (TpIota x T₁ T₂) = strBreak 2
2 [ strAdd "ι " >>str
strBvar x (strAdd " : " >>str to-stringh T₁ >>str strAdd " .") strEmpty ]
2 [ strΓ' localScope x (to-stringh T₂) ]
type-to-stringh (TpApp T tT) = apps-to-string (TpApp T tT)
type-to-stringh (TpEq t₁ t₂) = strBreak 2
2 [ strAdd "{ " >>str to-stringh (erase t₁) ]
2 [ strAdd "≃ " >>str to-stringh (erase t₂) >>str strAdd " }" ]
type-to-stringh (TpHole pi) = hole-to-string pi
type-to-stringh (TpLam x tk T) = strBreak 2
3 [ strAdd "λ " >>str
strBvar x (strAdd " : " >>str to-stringh -tk' tk >>str strAdd " .") strEmpty ]
1 [ strΓ' localScope x (to-stringr T) ]
type-to-stringh (TpVar x) = strVar x
kind-to-stringh (KdArrow k k') = strBreak 2
2 [ to-stringl -tk' k >>str strAdd " ➔" ]
2 [ to-stringr k' ]
kind-to-stringh (KdAbs x tk k) = strBreak 2
4 [ strAdd "Π " >>str
strBvar x (strAdd " : " >>str to-stringl -tk' tk >>str strAdd " .") strEmpty ]
1 [ strΓ' localScope x (to-stringh k) ]
kind-to-stringh (KdHole pi) = hole-to-string pi
kind-to-stringh KdStar = strAdd "★"
hole-to-string pi = strM-Γ λ Γ → strAddTags "●" (var-loc-tag Γ (split-var pi) "●")
optTerm-to-string nothing c1 c2 = []
optTerm-to-string (just t) c1 c2 =
[ strAdd (𝕃char-to-string (c1 :: [ ' ' ])) >>str
to-stringh t >>str
strAdd (𝕃char-to-string (' ' :: [ c2 ])) ]
optClass-to-string nothing = strEmpty
optClass-to-string (just atk) = strAdd " : " >>str to-stringh -tk' atk
optType-to-string pfx nothing = []
optType-to-string pfx (just T) =
[ maybe-else strEmpty (λ pfx → strAdd (𝕃char-to-string (pfx :: [ ' ' ]))) pfx >>str to-stringh T ]
arg-to-string (Arg t) = to-stringr t
arg-to-string (ArgE (Ttm t)) = strAdd "-" >>str strNest 1 (to-stringr t)
arg-to-string (ArgE (Ttp T)) = strAdd "·" >>str strNest 2 (to-stringr T)
args-to-string = set-parent (App (Hole pi-gen) (Hole pi-gen)) ∘ foldr' strEmpty λ t x → strAdd " " >>str arg-to-string t >>str x
binder-to-string tt = "∀"
binder-to-string ff = "Π"
lam-to-string tt = "Λ"
lam-to-string ff = "λ"
arrowtype-to-string ff = " ➔"
arrowtype-to-string tt = " ➾"
opacity-to-string opacity-open = ""
opacity-to-string opacity-closed = "opaque "
vars-to-string [] = strEmpty
vars-to-string (v :: []) = strVar v
vars-to-string (v :: vs) = strVar v >>str strAdd " " >>str vars-to-string vs
ctr-to-string (Ctr x T) = strAdd x >>str strAdd " : " >>str to-stringh T
case-to-string (Case x as t _) =
strM-Γ λ Γ →
let as-f = λ x as → strVar x >>str caseArgs-to-string as (strAdd " ➔ " >>str to-stringr t) in
case (env-lookup Γ x , options) of uncurry λ where
(just (ctr-def mps T _ _ _ , _ , _)) ced-ops-drop-spine →
as-f (unqual-all (ctxt.qual Γ) x) as
_ _ → as-f x as
cases-to-string = h use-newlines where
h : 𝔹 → cases → strM
h _ [] = strEmpty
h tt (m :: []) = strAdd "| " >>str case-to-string m
h tt (m :: ms) = strAdd "| " >>str case-to-string m >>str strLine >>str h tt ms
h ff (m :: []) = case-to-string m
h ff (m :: ms) = case-to-string m >>str strAdd " | " >>str h ff ms
caseArgs-to-string [] m = m
caseArgs-to-string (CaseArg _ x (just (Tkk _)) :: as) m = strAdd " ·" >>str strBvar x strEmpty (caseArgs-to-string as m)
caseArgs-to-string (CaseArg ff x _ :: as) m = strAdd " " >>str strBvar x strEmpty (caseArgs-to-string as m)
caseArgs-to-string (CaseArg tt x _ :: as) m = strAdd " -" >>str strBvar x strEmpty (caseArgs-to-string as m)
braceL me = if me then "{" else "("
braceR me = if me then "}" else ")"
bracketL me = if me then "{ " else "[ "
bracketR me = if me then " } -" else " ] -"
param-to-string : param → (strM → strM) × strM
param-to-string (Param me v atk) =
strΓ' localScope v ,
(strAdd (braceL me) >>str
strAdd (unqual-local v) >>str
strAdd " : " >>str
to-stringh -tk' atk >>str
strAdd (braceR me))
params-to-string'' ps f = elim-pair (foldr (λ p → uncurry λ g ms → elim-pair (param-to-string p) λ h m → g ∘ h , m :: map h ms) (id , []) ps) λ g ms → strList 2 (strEmpty :: ms) >>str g f
params-to-string' f [] = f
params-to-string' f (p :: []) = elim-pair (param-to-string p) λ g m → m >>str g f
params-to-string' f (p :: ps) = elim-pair (param-to-string p) λ g m → m >>str strAdd " " >>str params-to-string' (g f) ps
params-to-string = params-to-string' strEmpty
strRun : ctxt → strM → rope
strRun Γ m = doc-to-rope $ fst $ m {TERM} NIL 0 [] Γ nothing neither
strRunTag : (name : string) → ctxt → strM → tagged-val
strRunTag name Γ m with m {TERM} NIL 0 [] Γ nothing neither
...| s , n , ts = name , doc-to-rope s , ts
to-stringe : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringe = to-stringh ∘' (if cedille-options.options.erase-types options then erase else id)
to-string-tag : {ed : exprd} → string → ctxt → ⟦ ed ⟧ → tagged-val
to-string-tag name Γ t = strRunTag name Γ (to-stringe t)
to-string : {ed : exprd} → ctxt → ⟦ ed ⟧ → rope
to-string Γ t = strRun Γ (to-stringh t)
tpkd-to-stringe : tpkd → strM
tpkd-to-stringe = to-stringe -tk'_
tpkd-to-string : ctxt → tpkd → rope
tpkd-to-string Γ atk = strRun Γ (tpkd-to-stringe atk)
params-to-string-tag : string → ctxt → params → tagged-val
params-to-string-tag name Γ ps = strRunTag name Γ (params-to-string ps)
| 36.972366
| 187
| 0.607558
|
2222cc8169baf9b81a23e491999280ae5ddd70af
| 3,060
|
agda
|
Agda
|
OutsideIn/Inference/Separator.agda
|
liamoc/outside-in
|
fc1fc1bba2af95806d9075296f9ed1074afa4c24
|
[
"BSD-3-Clause"
] | 2
|
2015-09-14T05:22:15.000Z
|
2020-11-19T14:30:07.000Z
|
OutsideIn/Inference/Separator.agda
|
liamoc/outside-in
|
fc1fc1bba2af95806d9075296f9ed1074afa4c24
|
[
"BSD-3-Clause"
] | null | null | null |
OutsideIn/Inference/Separator.agda
|
liamoc/outside-in
|
fc1fc1bba2af95806d9075296f9ed1074afa4c24
|
[
"BSD-3-Clause"
] | null | null | null |
open import OutsideIn.Prelude
open import OutsideIn.X
module OutsideIn.Inference.Separator(x : X) where
import OutsideIn.Constraints as C
open C(x)
open X(x)
open import Data.List hiding (map)
mutual
data SeparatedConstraint (n : Set) : Shape → Set where
SC : ∀ {s} → QConstraint n → Implications n s → SeparatedConstraint n s
data Implications (n : Set) : Shape → Set where
imp-ε : Implications n Nullary
imp : ∀ {s} → Implication (λ n → SeparatedConstraint n s) n → Implications n (Unary s)
_imp-∧_ : ∀ {s₁ s₂} → Implications n s₁ → Implications n s₂ → Implications n (Binary s₁ s₂)
mutual
data _simpl:_ {n : Set} : Constraint n Flat → QConstraint n → Set where
Simpl-QC : ∀ {c} → QC c simpl: c
Simpl-∧ : ∀ {a b}{a′ b′} → a simpl: a′ → b simpl: b′ → (a ∧′ b) simpl: (a′ ∧ b′)
Simpl-Imp : ∀ {i} → Imp i simpl: ε
data _separate:_,_ {n : Set} : Constraint n Flat → (r : Shape) → SeparatedConstraint n r → Set where
Separate : ∀ {C}{Q}{r}{I} → C simpl: Q → C implic: r , I → C separate: r , SC Q I
data _implic:_,_ {n : Set} : Constraint n Flat → (r : Shape) → Implications n r → Set where
Implic-Qc : ∀ {c} → QC c implic: Nullary , imp-ε
Implic-∧ : ∀{a b}{r₁ r₂}{a′}{b′} → a implic: r₁ , a′ → b implic: r₂ , b′ → (a ∧′ b) implic: Binary r₁ r₂ , (a′ imp-∧ b′)
Implic-I : ∀{n}{Q}{C}{s}{v} → C separate: s , v → Imp (∃ n · Q ⊃ C) implic: Unary s , imp (∃ n · Q ⊃ v)
simpl : ∀ {n} → (C : Constraint n Flat) → ∃ (λ Q → C simpl: Q)
simpl (QC c) = _ , Simpl-QC
simpl (a ∧′ b) with simpl a | simpl b
... | q₁ , p₁ | q₂ , p₂ = _ , Simpl-∧ p₁ p₂
simpl (Imp _) = _ , Simpl-Imp
separate : ∀ {n} → (C : Constraint n Flat) → ∃ (λ r → ∃ (λ S → C separate: r , S))
implic : ∀ {n} → (C : Constraint n Flat) → ∃ (λ r → ∃ (λ I → C implic: r , I ))
separate c with implic c | simpl c
... | s , v , p | q , p′ = _ , _ , Separate p′ p
implic (QC c) = _ , _ , Implic-Qc
implic (a ∧′ b) with implic a | implic b
... | s , v , p | s′ , v′ , p′ = _ , _ , Implic-∧ p p′
implic (Imp (∃ n · Q ⊃ C)) with separate C
... | s , v , p = _ , _ , Implic-I p
-- Substitution for separated constraints
substituteSep : ∀ {s}{a b} → (a → Type b) → SeparatedConstraint a s → SeparatedConstraint b s
substituteImp : ∀ {s}{a b} → (a → Type b) → Implications a s → Implications b s
substituteSep f (SC qc imps) = SC (qc-substitute f qc) (substituteImp f imps)
where open Monad (type-is-monad)
open Functor (type-is-functor)
substituteImp f (imp-ε) = imp-ε
substituteImp {Unary s} f (imp (∃ n · Q ⊃ C)) = imp (∃ n · constraint-types (join ∘ map f) Q
⊃ substituteSep f′ C)
where module PlusN-f = Functor (Monad.is-functor (PlusN-is-monad {n}))
open Monad (type-is-monad)
open Functor (type-is-functor)
f′ = sequence-PlusN {n = n} ⦃ type-is-monad ⦄ ∘ PlusN-f.map f
substituteImp f (a imp-∧ b) = substituteImp f a imp-∧ substituteImp f b
| 51
| 127
| 0.558497
|
580c1caf1c0dc1691c654c29770b0a102c6489bb
| 1,309
|
agda
|
Agda
|
LibraBFT/Concrete/System/Parameters.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Concrete/System/Parameters.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Concrete/System/Parameters.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Base.Types
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.NetworkMsg
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Impl.Handle sha256 sha256-cr
open EpochConfig
open import LibraBFT.Yasm.Base (ℓ+1 0ℓ) EpochConfig epochId authorsN
-- In this module, we instantiate the system model with parameters to
-- model a system using the simple implementation model we have so
-- far, which aims to obey the VotesOnceRule, but not LockedRoundRule
-- yet. This will evolve as we build out a model of a real
-- implementation.
module LibraBFT.Concrete.System.Parameters where
ConcSysParms : SystemParameters
ConcSysParms = mkSysParms
NodeId
_≟NodeId_
EventProcessor
fakeEP
NetworkMsg
Vote
sig-Vote
_⊂Msg_
(_^∙ vEpoch)
initialEventProcessorAndMessages
peerStepWrapper
| 36.361111
| 111
| 0.686784
|
22d96b16ee01b0ecde767f97499e680e7b06fa92
| 2,846
|
agda
|
Agda
|
src/Sphere.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Sphere.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Sphere.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Spheres
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
-- This module follows the HoTT book rather closely.
import Equality.Path as P
module Sphere
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Equality.Path.Isomorphisms eq
open import Equality.Tactic equality-with-J
import Equivalence equality-with-J as Equiv
open import Function-universe equality-with-J as F hiding (_∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import Nat equality-with-J as Nat
open import Pointed-type equality-with-J
open import Suspension eq as Suspension
private
variable
a b : Level
A B : Type a
C : Pointed-type a
x : A
n : ℕ
-- Spheres.
𝕊[_-1] : ℕ → Type
𝕊[ zero -1] = ⊥
𝕊[ suc n -1] = Susp 𝕊[ n -1]
-- Spheres with non-negative dimensions.
𝕊 : ℕ → Type
𝕊 n = 𝕊[ 1 + n -1]
-- The booleans are isomorphic to the 0-dimensional sphere.
Bool↔𝕊⁰ : Bool ↔ 𝕊 0
Bool↔𝕊⁰ = Bool↔Susp-⊥
-- Based maps from spheres with non-negative dimensions (using north
-- as the point) are isomorphic to iterated loop spaces.
𝕊→ᴮ↔ : ∀ n → (𝕊 n , north) →ᴮ C ↔ proj₁ (Ω[ n ] C)
𝕊→ᴮ↔ {C = C} = lemma zero
where
lemma : ∀ m n → (𝕊 n , north) →ᴮ Ω[ m ] C ↔ proj₁ (Ω[ m + n ] C)
lemma m zero =
(𝕊 0 , north) →ᴮ Ω[ m ] C ↝⟨ Σ-cong (→-cong ext (inverse Bool↔𝕊⁰) F.id) (λ _ → F.id) ⟩
(Bool , true) →ᴮ Ω[ m ] C ↝⟨ Bool→ᴮ↔ ext ⟩
proj₁ (Ω[ m ] C) ↝⟨ ≡⇒↝ _ $ cong (λ n → proj₁ (Ω[ n ] C)) $ sym $ Nat.+-right-identity {n = m} ⟩□
proj₁ (Ω[ m + 0 ] C) □
lemma m (suc n) =
(𝕊 (suc n) , north) →ᴮ Ω[ m ] C ↝⟨ Susp→ᴮ↔ ⟩
(𝕊 n , north) →ᴮ Ω[ suc m ] C ↝⟨ lemma (suc m) n ⟩
proj₁ (Ω[ suc m + n ] C) ↝⟨ ≡⇒↝ _ $ cong (λ n → proj₁ (Ω[ n ] C)) $ Nat.suc+≡+suc m ⟩□
proj₁ (Ω[ m + suc n ] C) □
-- A corollary.
+↔∀contractible𝕊→ᴮ :
H-level (1 + n) A ↔
(∀ x → Contractible ((𝕊 n , north) →ᴮ (A , x)))
+↔∀contractible𝕊→ᴮ {n = n} {A = A} =
H-level (1 + n) A ↔⟨ _↔_.to (Equiv.⇔↔≃ ext (H-level-propositional ext _)
(Π-closure ext 1 λ _ →
H-level-propositional ext _))
(+⇔∀contractible-Ω[] _) ⟩
(∀ x → Contractible (proj₁ $ Ω[ n ] (A , x))) ↝⟨ (∀-cong ext λ _ → H-level-cong ext 0 (inverse $ 𝕊→ᴮ↔ _)) ⟩□
(∀ x → Contractible ((𝕊 n , north) →ᴮ (A , x))) □
| 33.482353
| 113
| 0.504216
|
3dbd896d2b21a89d97152f7523d609c90fea7db2
| 6,745
|
agda
|
Agda
|
Ex6AgdaSetup.agda
|
clarkdm/CS410
|
523a8749f49c914bcd28402116dcbe79a78dbbf4
|
[
"CC0-1.0"
] | null | null | null |
Ex6AgdaSetup.agda
|
clarkdm/CS410
|
523a8749f49c914bcd28402116dcbe79a78dbbf4
|
[
"CC0-1.0"
] | null | null | null |
Ex6AgdaSetup.agda
|
clarkdm/CS410
|
523a8749f49c914bcd28402116dcbe79a78dbbf4
|
[
"CC0-1.0"
] | null | null | null |
module Ex6AgdaSetup where
{- This file contains all the basic types you need for the editor. You should
read and understand the Agda in this file, but not bother too much about
the funny compiler directives. -}
open import CS410-Prelude
open import CS410-Nat
record _**_ (S T : Set) : Set where
constructor _,_
field
outl : S
outr : T
open _**_
{-# COMPILED_DATA _**_ (,) (,) #-}
infixr 4 _**_ _,_
_<=_ : Nat -> Nat -> Two
zero <= y = tt
suc x <= zero = ff
suc x <= suc y = x <= y
_++_ : {A : Set} -> List A -> List A -> List A
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
{- Here are backward lists, which are useful when the closest element is
conceptually at the right end. They aren't really crucial as you could use
ordinary lists but think of the data as being reversed, but I prefer to
keep my thinking straight and use data which look like what I have in mind. -}
data Bwd (X : Set) : Set where
[] : Bwd X
_<:_ : Bwd X -> X -> Bwd X
infixl 3 _<:_
{- You will need access to characters, imported from Haskell. You can write
character literals like 'c'. You also get strings, with String literals like
"fred" -}
postulate -- Haskell has a monad for doing IO, which we use at the top level
IO : Set -> Set
return : {A : Set} -> A -> IO A
_>>=_ : {A B : Set} -> IO A -> (A -> IO B) -> IO B
infixl 1 _>>=_
{-# BUILTIN IO IO #-}
{-# COMPILED_TYPE IO IO #-}
{-# COMPILED return (\ _ -> return) #-}
{-# COMPILED _>>=_ (\ _ _ -> (>>=)) #-}
{- Here's the characterization of keys I give you -}
data Direction : Set where up down left right : Direction
data Modifier : Set where normal shift control : Modifier
data Key : Set where
char : Char -> Key
arrow : Modifier -> Direction -> Key
enter : Key
backspace : Key
delete : Key
escape : Key
tab : Key
data Event : Set where
key : (k : Key) -> Event
resize : (w h : Nat) -> Event
{- This type classifies the difference between two editor states. -}
data Change : Set where
allQuiet : Change -- the buffer should be exactly the same
cursorMove : Change -- the cursor has moved but the text is the same
lineEdit : Change -- only the text on the current line has changed
bigChange : Change -- goodness knows!
{- This type collects the things you're allowed to do with the text window. -}
data Action : Set where
goRowCol : Nat -> Nat -> Action -- send the cursor somewhere
sendText : List Char -> Action -- send some text
move : Direction -> Nat -> Action -- which way and how much
fgText : Colour -> Action
bgText : Colour -> Action
{- I wire all of that stuff up to its Haskell counterpart. -}
{-# IMPORT ANSIEscapes #-}
{-# IMPORT HaskellSetup #-}
{-# COMPILED_DATA Direction
ANSIEscapes.Dir
ANSIEscapes.DU ANSIEscapes.DD ANSIEscapes.DL ANSIEscapes.DR #-}
{-# COMPILED_DATA Modifier
HaskellSetup.Modifier
HaskellSetup.Normal HaskellSetup.Shift HaskellSetup.Control #-}
{-# COMPILED_DATA Key
HaskellSetup.Key
HaskellSetup.Char HaskellSetup.Arrow HaskellSetup.Enter
HaskellSetup.Backspace HaskellSetup.Delete HaskellSetup.Escape
HaskellSetup.Tab #-}
{-# COMPILED_DATA Event
HaskellSetup.Event
HaskellSetup.Key HaskellSetup.Resize #-}
{-# COMPILED_DATA Change
HaskellSetup.Change
HaskellSetup.AllQuiet HaskellSetup.CursorMove HaskellSetup.LineEdit
HaskellSetup.BigChange #-}
{-# COMPILED_DATA Action HaskellSetup.Action
HaskellSetup.GoRowCol HaskellSetup.SendText HaskellSetup.Move
HaskellSetup.FgText HaskellSetup.BgText #-}
{- This is the bit of code I wrote to animate your code. -}
postulate
mainLoop : {B : Set} -> -- buffer type
-- INITIALIZER
(List (List Char) -> B) -> -- make a buffer from some lines of text
-- KEYSTROKE HANDLER
(Key -> B -> -- keystroke and buffer in
Change ** B) -> -- change report and buffer out
-- RENDERER
((Nat ** Nat) -> -- height and width of screen
(Nat ** Nat) -> -- top line number, left column number
(Change ** B) -> -- change report and buffer to render
(List Action ** -- how to update the display
(Nat ** Nat))) -> -- new top line number, left column number
-- PUT 'EM TOGETHER AND YOU'VE GOT AN EDITOR!
IO One
{-# COMPILED mainLoop (\ _ -> HaskellSetup.mainLoop) #-}
{- You can use this to put noisy debug messages in Agda code. So
trace "fred" tt
evaluates to tt, but prints "fred" in the process. -}
postulate
trace : {A : Set} -> String -> A -> A
{-# IMPORT Debug.Trace #-}
{-# COMPILED trace (\ _ -> Debug.Trace.trace) #-}
{- You can use this to print an error message when you don't know what else to do.
It's very useful for filling in unfinished holes to persuade the compiler to
compile your code even though it isn't finished: you get an error if you try
to run a missing bit. -}
postulate
error : {A : Set} -> String -> A
{-# COMPILED error (\ _ -> error) #-}
{- Equality -}
{- x == y is a type whenever x and y are values in the same type -}
{-
data _==_ {X : Set}(x : X) : X -> Set where
refl : x == x -- and x == y has a constructor only when y actually is x!
infixl 1 _==_
-- {-# BUILTIN EQUALITY _==_ #-}
-- {-# BUILTIN REFL refl #-}
{-# COMPILED_DATA _==_ HaskellSetup.EQ HaskellSetup.Refl #-}
within_turn_into_because_ :
{X Y : Set}(f : X -> Y)(x x' : X) ->
x == x' -> f x == f x'
within f turn x into .x because refl = refl
-- the dot tells Agda that *only* x can go there
symmetry : {X : Set}{x x' : X} -> x == x' -> x' == x
symmetry refl = refl
transitivity : {X : Set}{x0 x1 x2 : X} -> x0 == x1 -> x1 == x2 -> x0 == x2
transitivity refl refl = refl
-}
within_turn_into_because_ :
{X Y : Set}(f : X -> Y)(x x' : X) ->
x == x' -> f x == f x'
within f turn x into .x because refl = refl
{-
postulate
_==_ : {X : Set} -> X -> X -> Set -- the evidence that two X-values are equal
refl : {X : Set}{x : X} -> x == x
symmetry : {X : Set}{x x' : X} -> x == x' -> x' == x
transitivity : {X : Set}{x0 x1 x2 : X} -> x0 == x1 -> x1 == x2 -> x0 == x2
within_turn_into_because_ :
{X Y : Set}(f : X -> Y)(x x' : X) ->
x == x' -> f x == f x'
infix 1 _==_
{-# COMPILED_TYPE _==_ HaskellSetup.EQ #-}
{- Here's an example. -}
additionAssociative : (x y z : Nat) -> (x + y) + z == x + (y + z)
additionAssociative zero y z = refl
additionAssociative (suc x) y z
= within suc turn ((x + y) + z) into (x + (y + z))
because additionAssociative x y z
-}
| 34.948187
| 82
| 0.606968
|
3d84499ce129672577d60e93ffc5685cc5ef34dc
| 797
|
agda
|
Agda
|
Cubical/Categories/Instances/RingAlgebras.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Categories/Instances/RingAlgebras.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Instances/RingAlgebras.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.RingAlgebras where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Algebra
open import Cubical.Categories.Category
open Category
open AlgebraHoms
private
variable
ℓ ℓ' : Level
module _ (R : Ring ℓ) where
AlgebrasCategory : Category (ℓ-suc (ℓ-max ℓ ℓ')) (ℓ-max ℓ ℓ')
ob AlgebrasCategory = Algebra R _
Hom[_,_] AlgebrasCategory = AlgebraHom
id AlgebrasCategory {A} = idAlgebraHom A
_⋆_ AlgebrasCategory = compAlgebraHom
⋆IdL AlgebrasCategory = compIdAlgebraHom
⋆IdR AlgebrasCategory = idCompAlgebraHom
⋆Assoc AlgebrasCategory = compAssocAlgebraHom
isSetHom AlgebrasCategory = isSetAlgebraHom _ _
| 27.482759
| 63
| 0.759097
|
4176843ee1ab02be9fea91a03fc8d7c2e16c9e49
| 10,532
|
agda
|
Agda
|
Cubical/Algebra/CommRing/Localisation/Base.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Localisation/Base.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/CommRing/Localisation/Base.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
-- We define the localisation of a commutative ring
-- at a multiplicatively closed subset and show that it
-- has a commutative ring structure.
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Localisation.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Transport
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; _^_ to _^ℕ_
; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
open import Cubical.Data.Vec
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRingSolver.Reflection
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
open Iso
private
variable
ℓ ℓ' : Level
A : Type ℓ
-- A multiplicatively closed subset is assumed to contain 1
record isMultClosedSubset (R' : CommRing ℓ) (S' : ℙ (fst R')) : Type ℓ where
constructor
multclosedsubset
field
containsOne : (R' .snd .CommRingStr.1r) ∈ S'
multClosed : ∀ {s t} → s ∈ S' → t ∈ S' → ((snd R') .CommRingStr._·_ s t) ∈ S'
module Loc (R' : CommRing ℓ) (S' : ℙ (fst R')) (SMultClosedSubset : isMultClosedSubset R' S') where
open isMultClosedSubset
private R = fst R'
open CommRingStr (snd R')
open RingTheory (CommRing→Ring R')
open CommRingTheory R'
S = Σ[ s ∈ R ] (s ∈ S')
-- We define the localisation of R by S by quotienting by the following relation:
_≈_ : R × S → R × S → Type ℓ
(r₁ , s₁) ≈ (r₂ , s₂) = Σ[ s ∈ S ] (fst s · r₁ · fst s₂ ≡ fst s · r₂ · fst s₁)
S⁻¹R = (R × S) / _≈_
-- now define addition for S⁻¹R
open BinaryRelation
locRefl : isRefl _≈_
locRefl _ = (1r , SMultClosedSubset .containsOne) , refl
locSym : isSym _≈_
locSym (r , s , s∈S') (r' , s' , s'∈S') (u , p) = u , sym p
locTrans : isTrans _≈_
locTrans (r , s , s∈S') (r' , s' , s'∈S') (r'' , s'' , s''∈S') ((u , u∈S') , p) ((v , v∈S') , q) =
((u · v · s') , SMultClosedSubset .multClosed (SMultClosedSubset .multClosed u∈S' v∈S') s'∈S')
, path
where
eq1 : (r s r' s' r'' s'' u v : R) → u · v · s' · r · s'' ≡ u · r · s' · v · s''
eq1 = solve R'
eq2 : (r s r' s' r'' s'' u v : R) → u · r' · s · v · s'' ≡ u · s · (v · r' · s'')
eq2 = solve R'
eq3 : (r s r' s' r'' s'' u v : R) → u · s · (v · r'' · s') ≡ u · v · s' · r'' · s
eq3 = solve R'
path : u · v · s' · r · s'' ≡ u · v · s' · r'' · s
path = u · v · s' · r · s'' ≡⟨ eq1 r s r' s' r'' s'' u v ⟩ -- not just ≡⟨ solve R' ⟩
u · r · s' · v · s'' ≡⟨ cong (λ x → x · v · s'') p ⟩
u · r' · s · v · s'' ≡⟨ eq2 r s r' s' r'' s'' u v ⟩
u · s · (v · r' · s'') ≡⟨ cong (u · s ·_) q ⟩
u · s · (v · r'' · s') ≡⟨ eq3 r s r' s' r'' s'' u v ⟩
u · v · s' · r'' · s ∎
locIsEquivRel : isEquivRel _≈_
isEquivRel.reflexive locIsEquivRel = locRefl
isEquivRel.symmetric locIsEquivRel = locSym
isEquivRel.transitive locIsEquivRel = locTrans
_+ₗ_ : S⁻¹R → S⁻¹R → S⁻¹R
_+ₗ_ = setQuotSymmBinOp locRefl locTrans _+ₚ_
(λ a b → subst (λ x → (a +ₚ b) ≈ x) (+ₚ-symm a b) (locRefl (a +ₚ b))) θ
where
_+ₚ_ : R × S → R × S → R × S
(r₁ , s₁ , s₁∈S) +ₚ (r₂ , s₂ , s₂∈S) =
(r₁ · s₂ + r₂ · s₁) , (s₁ · s₂) , SMultClosedSubset .multClosed s₁∈S s₂∈S
+ₚ-symm : (a b : R × S) → (a +ₚ b) ≡ (b +ₚ a)
+ₚ-symm (r₁ , s₁ , s₁∈S) (r₂ , s₂ , s₂∈S) =
ΣPathP (+Comm _ _ , Σ≡Prop (λ x → S' x .snd) (·Comm _ _))
θ : (a a' b : R × S) → a ≈ a' → (a +ₚ b) ≈ (a' +ₚ b)
θ (r₁ , s₁ , s₁∈S) (r'₁ , s'₁ , s'₁∈S) (r₂ , s₂ , s₂∈S) ((s , s∈S) , p) = (s , s∈S) , path
where
eq1 : (r₁ s₁ r'₁ s'₁ s'₁ r₂ s₂ s : R)
→ s · (r₁ · s₂ + r₂ · s₁) · (s'₁ · s₂) ≡ s · r₁ · s'₁ · s₂ · s₂ + s · r₂ · s₁ · s'₁ · s₂
eq1 = solve R'
eq2 : (r₁ s₁ r'₁ s'₁ s'₁ r₂ s₂ s : R)
→ s · r'₁ · s₁ · s₂ · s₂ + s · r₂ · s₁ · s'₁ · s₂ ≡ s · (r'₁ · s₂ + r₂ · s'₁) · (s₁ · s₂)
eq2 = solve R'
path : s · (r₁ · s₂ + r₂ · s₁) · (s'₁ · s₂) ≡ s · (r'₁ · s₂ + r₂ · s'₁) · (s₁ · s₂)
path = s · (r₁ · s₂ + r₂ · s₁) · (s'₁ · s₂)
≡⟨ eq1 r₁ s₁ r'₁ s'₁ s'₁ r₂ s₂ s ⟩
s · r₁ · s'₁ · s₂ · s₂ + s · r₂ · s₁ · s'₁ · s₂
≡⟨ cong (λ x → x · s₂ · s₂ + s · r₂ · s₁ · s'₁ · s₂) p ⟩
s · r'₁ · s₁ · s₂ · s₂ + s · r₂ · s₁ · s'₁ · s₂
≡⟨ eq2 r₁ s₁ r'₁ s'₁ s'₁ r₂ s₂ s ⟩
s · (r'₁ · s₂ + r₂ · s'₁) · (s₁ · s₂) ∎
-- check group-laws for addition
+ₗ-assoc : (x y z : S⁻¹R) → x +ₗ (y +ₗ z) ≡ (x +ₗ y) +ₗ z
+ₗ-assoc = SQ.elimProp3 (λ _ _ _ → squash/ _ _) +ₗ-assoc[]
where
+ₗ-assoc[] : (a b c : R × S) → [ a ] +ₗ ([ b ] +ₗ [ c ]) ≡ ([ a ] +ₗ [ b ]) +ₗ [ c ]
+ₗ-assoc[] (r , s , s∈S) (r' , s' , s'∈S) (r'' , s'' , s''∈S) =
cong [_] (ΣPathP ((path r s r' s' r'' s'') , Σ≡Prop (λ x → ∈-isProp S' x) (·Assoc _ _ _)))
where
path : (r s r' s' r'' s'' : R)
→ r · (s' · s'') + (r' · s'' + r'' · s') · s ≡ (r · s' + r' · s) · s'' + r'' · (s · s')
path = solve R'
0ₗ : S⁻¹R
0ₗ = [ 0r , 1r , SMultClosedSubset .containsOne ]
+ₗ-rid : (x : S⁻¹R) → x +ₗ 0ₗ ≡ x
+ₗ-rid = SQ.elimProp (λ _ → squash/ _ _) +ₗ-rid[]
where
+ₗ-rid[] : (a : R × S) → [ a ] +ₗ 0ₗ ≡ [ a ]
+ₗ-rid[] (r , s , s∈S) = path
where
eq1 : (r s : R) → r · 1r + 0r · s ≡ r
eq1 = solve R'
path : [ r · 1r + 0r · s , s · 1r , SMultClosedSubset .multClosed s∈S
(SMultClosedSubset .containsOne) ]
≡ [ r , s , s∈S ]
path = cong [_] (ΣPathP (eq1 r s , Σ≡Prop (λ x → ∈-isProp S' x) (·IdR _)))
-ₗ_ : S⁻¹R → S⁻¹R
-ₗ_ = SQ.rec squash/ -ₗ[] -ₗWellDef
where
-ₗ[] : R × S → S⁻¹R
-ₗ[] (r , s) = [ - r , s ]
-ₗWellDef : (a b : R × S) → a ≈ b → -ₗ[] a ≡ -ₗ[] b
-ₗWellDef (r , s , _) (r' , s' , _) ((u , u∈S) , p) = eq/ _ _ ((u , u∈S) , path)
where
eq1 : (u r s' : R) → u · - r · s' ≡ - (u · r · s')
eq1 = solve R'
eq2 : (u r' s : R) → - (u · r' · s) ≡ u · - r' · s
eq2 = solve R'
path : u · - r · s' ≡ u · - r' · s
path = eq1 u r s' ∙∙ cong -_ p ∙∙ eq2 u r' s
+ₗ-rinv : (x : S⁻¹R) → x +ₗ (-ₗ x) ≡ 0ₗ
+ₗ-rinv = SQ.elimProp (λ _ → squash/ _ _) +ₗ-rinv[]
where
+ₗ-rinv[] : (a : R × S) → ([ a ] +ₗ (-ₗ [ a ])) ≡ 0ₗ
+ₗ-rinv[] (r , s , s∈S) = eq/ _ _ ((1r , SMultClosedSubset .containsOne) , path r s)
where
path : (r s : R) → 1r · (r · s + - r · s) · 1r ≡ 1r · 0r · (s · s)
path = solve R'
+ₗ-comm : (x y : S⁻¹R) → x +ₗ y ≡ y +ₗ x
+ₗ-comm = SQ.elimProp2 (λ _ _ → squash/ _ _) +ₗ-comm[]
where
+ₗ-comm[] : (a b : R × S) → ([ a ] +ₗ [ b ]) ≡ ([ b ] +ₗ [ a ])
+ₗ-comm[] (r , s , s∈S) (r' , s' , s'∈S) =
cong [_] (ΣPathP ((+Comm _ _) , Σ≡Prop (λ x → ∈-isProp S' x) (·Comm _ _)))
-- Now for multiplication
_·ₗ_ : S⁻¹R → S⁻¹R → S⁻¹R
_·ₗ_ = setQuotSymmBinOp locRefl locTrans _·ₚ_
(λ a b → subst (λ x → (a ·ₚ b) ≈ x) (·ₚ-symm a b) (locRefl (a ·ₚ b))) θ
where
_·ₚ_ : R × S → R × S → R × S
(r₁ , s₁ , s₁∈S) ·ₚ (r₂ , s₂ , s₂∈S) =
(r₁ · r₂) , ((s₁ · s₂) , SMultClosedSubset .multClosed s₁∈S s₂∈S)
·ₚ-symm : (a b : R × S) → (a ·ₚ b) ≡ (b ·ₚ a)
·ₚ-symm (r₁ , s₁ , s₁∈S) (r₂ , s₂ , s₂∈S) =
ΣPathP (·Comm _ _ , Σ≡Prop (λ x → S' x .snd) (·Comm _ _))
θ : (a a' b : R × S) → a ≈ a' → (a ·ₚ b) ≈ (a' ·ₚ b)
θ (r₁ , s₁ , s₁∈S) (r'₁ , s'₁ , s'₁∈S) (r₂ , s₂ , s₂∈S) ((s , s∈S) , p) = (s , s∈S) , path
where
eq1 : (r₁ s₁ r'₁ s'₁ r₂ s₂ s : R)
→ s · (r₁ · r₂) · (s'₁ · s₂) ≡ s · r₁ · s'₁ · r₂ · s₂
eq1 = solve R'
eq2 : (r₁ s₁ r'₁ s'₁ r₂ s₂ s : R)
→ s · r'₁ · s₁ · r₂ · s₂ ≡ s · (r'₁ · r₂) · (s₁ · s₂)
eq2 = solve R'
path : s · (r₁ · r₂) · (s'₁ · s₂) ≡ s · (r'₁ · r₂) · (s₁ · s₂)
path = eq1 r₁ s₁ r'₁ s'₁ r₂ s₂ s ∙∙ cong (λ x → x · r₂ · s₂) p ∙∙ eq2 r₁ s₁ r'₁ s'₁ r₂ s₂ s
-- checking laws for multiplication
1ₗ : S⁻¹R
1ₗ = [ 1r , 1r , SMultClosedSubset .containsOne ]
·ₗ-assoc : (x y z : S⁻¹R) → x ·ₗ (y ·ₗ z) ≡ (x ·ₗ y) ·ₗ z
·ₗ-assoc = SQ.elimProp3 (λ _ _ _ → squash/ _ _) ·ₗ-assoc[]
where
·ₗ-assoc[] : (a b c : R × S) → [ a ] ·ₗ ([ b ] ·ₗ [ c ]) ≡ ([ a ] ·ₗ [ b ]) ·ₗ [ c ]
·ₗ-assoc[] (r , s , s∈S) (r' , s' , s'∈S) (r'' , s'' , s''∈S) =
cong [_] (ΣPathP ((·Assoc _ _ _) , Σ≡Prop (λ x → ∈-isProp S' x) (·Assoc _ _ _)))
·ₗ-rid : (x : S⁻¹R) → x ·ₗ 1ₗ ≡ x
·ₗ-rid = SQ.elimProp (λ _ → squash/ _ _) ·ₗ-rid[]
where
·ₗ-rid[] : (a : R × S) → ([ a ] ·ₗ 1ₗ) ≡ [ a ]
·ₗ-rid[] (r , s , s∈S) = cong [_] (ΣPathP ((·IdR _) , Σ≡Prop (λ x → ∈-isProp S' x) (·IdR _)))
·ₗ-rdist-+ₗ : (x y z : S⁻¹R) → x ·ₗ (y +ₗ z) ≡ (x ·ₗ y) +ₗ (x ·ₗ z)
·ₗ-rdist-+ₗ = SQ.elimProp3 (λ _ _ _ → squash/ _ _) ·ₗ-rdist-+ₗ[]
where
·ₗ-rdist-+ₗ[] : (a b c : R × S) → [ a ] ·ₗ ([ b ] +ₗ [ c ]) ≡ ([ a ] ·ₗ [ b ]) +ₗ ([ a ] ·ₗ [ c ])
·ₗ-rdist-+ₗ[] (r , s , s∈S) (r' , s' , s'∈S) (r'' , s'' , s''∈S) =
eq/ _ _ ((1r , (SMultClosedSubset .containsOne)) , path r s r' s' r'' s'')
where
-- could be shortened even further
path : (r s r' s' r'' s'' : R)
→ 1r · (r · (r' · s'' + r'' · s')) · (s · s' · (s · s''))
≡ 1r · (r · r' · (s · s'') + r · r'' · (s · s')) · (s · (s' · s''))
path = solve R'
·ₗ-comm : (x y : S⁻¹R) → x ·ₗ y ≡ y ·ₗ x
·ₗ-comm = SQ.elimProp2 (λ _ _ → squash/ _ _) ·ₗ-comm[]
where
·ₗ-comm[] : (a b : R × S) → [ a ] ·ₗ [ b ] ≡ [ b ] ·ₗ [ a ]
·ₗ-comm[] (r , s , s∈S) (r' , s' , s'∈S) =
cong [_] (ΣPathP ((·Comm _ _) , Σ≡Prop (λ x → ∈-isProp S' x) (·Comm _ _)))
-- Commutative ring structure on S⁻¹R
S⁻¹RAsCommRing : CommRing ℓ
S⁻¹RAsCommRing = S⁻¹R , S⁻¹RCommRingStr
where
open CommRingStr
S⁻¹RCommRingStr : CommRingStr S⁻¹R
0r S⁻¹RCommRingStr = 0ₗ
1r S⁻¹RCommRingStr = 1ₗ
_+_ S⁻¹RCommRingStr = _+ₗ_
_·_ S⁻¹RCommRingStr = _·ₗ_
- S⁻¹RCommRingStr = -ₗ_
isCommRing S⁻¹RCommRingStr = makeIsCommRing squash/ +ₗ-assoc +ₗ-rid +ₗ-rinv +ₗ-comm
·ₗ-assoc ·ₗ-rid ·ₗ-rdist-+ₗ ·ₗ-comm
| 36.442907
| 101
| 0.476738
|
587a0fc6fd1221bbbb6342d1757fbb08c84ab058
| 1,057
|
agda
|
Agda
|
SDG/SDG.agda
|
wrrnhttn/agda-sdg
|
6814e6f0baffff35efe14ef70d469343cd9b3ba0
|
[
"MIT"
] | 1
|
2020-11-13T09:36:38.000Z
|
2020-11-13T09:36:38.000Z
|
SDG/SDG.agda
|
wrrnhttn/agda-sdg
|
6814e6f0baffff35efe14ef70d469343cd9b3ba0
|
[
"MIT"
] | 1
|
2019-07-18T20:00:23.000Z
|
2019-09-18T15:47:49.000Z
|
SDG/SDG.agda
|
wrrnhttn/agda-sdg
|
6814e6f0baffff35efe14ef70d469343cd9b3ba0
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import SDG.Extra.OrderedAlgebra
module SDG.SDG {r₁ r₂} (R : OrderedCommutativeRing r₁ r₂) where
open OrderedCommutativeRing R renaming (Carrier to Rc)
open import Data.Product
open import Data.Sum
open import Algebra
-- note: SDG should probably be a record if i need to
-- use some particular topos model
--nilsqr : {!!}
nilsqr = λ x → (x * x) ≈ 0#
nilsqr-0# : nilsqr 0#
nilsqr-0# = zeroˡ 0#
--D : {!!}
D = Σ[ x ∈ Rc ] (nilsqr x)
D→R : D → Rc
D→R d = proj₁ d
R→D : (x : Rc) → nilsqr x → D
R→D x nilsqr = x , nilsqr
d0 : D
d0 = R→D 0# nilsqr-0#
postulate
kock-lawvere : ∀ (g : D → Rc) →
∃! _≈_ (λ b → ∀ (d : D) → ((g d) ≈ ((g d0) + (D→R d * b))))
-- these definitions are modified from previous development based on Bell:
gₓ : ∀ (f : Rc → Rc) (x : Rc) → (D → Rc)
gₓ f x d = f (x + D→R d)
∃!b : ∀ (f : Rc → Rc) (x : Rc) → ∃! _≈_ (λ b → ∀ (d : D) → ((gₓ f x d) ≈ ((gₓ f x d0) + (D→R d * b))))
∃!b f x = kock-lawvere (gₓ f x)
_′ : (f : Rc → Rc) → (Rc → Rc)
(f ′) x = proj₁ (∃!b f x)
| 21.571429
| 102
| 0.53737
|
2293081f33f40677c4540163cac255dfc828037e
| 51,464
|
agda
|
Agda
|
test/Hit.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | 3
|
2020-07-31T18:15:26.000Z
|
2022-02-19T12:15:21.000Z
|
test/Hit.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
test/Hit.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts #-}
module Hit where
-- open import Cubical.Core.Everything
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ)
-- open import Cubical.Foundations.Equiv.HalfAdjoint
-- open import Cubical.Data.Sigma.Properties
-- https://en.wikipedia.org/wiki/Inductive_type#Higher_inductive_types
-- private
-- ℓ : Level
_ : (A B : Type₀) → Type₁
_ = λ a b → a ≡ b
-- https://www.youtube.com/watch?v=AZ8wMIar-_c
-- List becomes a normal form of this
data FreeMonoid' (A : Type₀) : Type₀ where
[_]' : A → FreeMonoid' A
ε' : FreeMonoid' A
_*'_ : FreeMonoid' A → FreeMonoid' A → FreeMonoid' A
assoc' : ∀ x y z → x *' (y *' z) ≡ (x *' y) *' z
data List (A : Type) : Type where
[] : List A
_∷_ : A → List A → List A
-- debug fonts
-- see which fonts are "in effect" with
-- fc-match --verbose
-- https://wiki.archlinux.org/index.php/X_Logical_Font_Description
-- Two different font systems are used by X11:
-- - the older or core X Logical Font Description, XLFD,
-- - and the newer X FreeType, Xft, systems (see An Xft Tutorial for font names format).
-- https://keithp.com/~keithp/render/Xft.tutorial
-- λ-calculus
-- Cockx 2019 - Hack your type theory with rewrite rules
-- https://jesper.sikanda.be/posts/hack-your-type-theory.html
-- email thread from Georgi Lyubenov (24.03.20, 23:28 ff) about sized lambdas "How can I implement naive sized lambdas?"
-- email thread from Joey Eremondi (22.04.20, 06:07 ff) about variable binding "What do you use for variable binding in 2020?"
-- literate agda markdown -> latex
-- https://lists.chalmers.se/pipermail/agda/2019/011286.html
-- https://stackoverflow.com/questions/58339725/literate-agda-in-markdown-format-to-latex-via-pandoc
-- https://jesper.sikanda.be/posts/literate-agda.html
-- Jesper Cockx' mail from 09.07.19, 18:35
-- an example file/paper that shows how to use cubical:
-- /home/christianl/agda/cubical/Cubical/Papers/Synthetic.agda
-- Cubical synthetic homotopy theory
-- Mörtberg and Pujet, „Cubical synthetic homotopy theory“.
-- https://dl.acm.org/doi/abs/10.1145/3372885.3373825
-- the github repository recommends
-- Vezzosi 2019 - Cubical Agda: A Dependently Typed ProgrammingLanguage with Univalence and Higher Inductive Types
-- https://dl.acm.org/doi/pdf/10.1145/3341691
-- there is also the very comprehensive
-- https://arxiv.org/pdf/1911.00580.pdf
-- Martín Hötzel Escardó 2020 - Introduction to Univalent Foundations of Mathematics with Agda
-- clickable html version: https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html
-- https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#sns
-- A structure identity principle for a standard notion of structure
-- some useful, recent stuff from the mailing list:
-- https://ncatlab.org/nlab/show/archimedean+field
-- An archimedean field is an ordered field in which every element is bounded above by a natural number.
-- Q: why refl {x} and refl {_} {_} {x} behave differently according to context
-- A: (U. Norell 01.05.20, 23:08)
-- pattern reflpv x = refl {x = x}
-- you are not allowed to pattern match on datatype parameters, since they are not stored in the constructor. In a right-hand side you can give the parameters to guide the type checker, but they are thrown out during elaboration.
-- Andreas Nuyts 26.04.20, 22:34
-- a case in a pattern matching definition gets a light grey background when it doesn't hold as a definitional equation, typically because it is a fallthrough case and further matching of the arguments is necessary to establish that none of the prior cases apply
-- Q: what do I assume/not assume when using --cubical?
-- A: (Andreas Abel 24.04.20, 15:04) That is a long story. One thing is that in --cubical, the identity type is a primitive (not a data), and you cannot match on refl.
-- https://agda.readthedocs.io/en/v2.6.1/tools/command-line-options.html?highlight=infective#consistency-checking-of-options-used
-- An infective option is an option that if used in one module, must be used in all modules that depend on this module.
-- A coinfective option is an option that if used in one module, must be used in all modules that this module depends on.
-- (Orestis Melkonian 22.12.19, 21:11) inspect MAlonzo haskell code's variable names with https://github.com/agda/agda-ghc-names
-- (James Wood 22.12.19, 21:28)
-- Note that record field names can also overlap if they are applied directly to a record value.
-- The theory behind this is in bidirectional type checking, and how a term having its type checked (rather than inferred) may be ambiguous without the information from the type.
-- The same mechanism allows λ to be reused for dimension abstraction in cubical Agda (because it is a constructor).
-- In short, overloading is fine in the following cases:
-- - Everything being overloaded is a constructor, and there is an obvious type to check the resulting construction against.
-- - Everything being overloaded is a field, and there is an obvious record type that the field is destructing.
-- Outside of these cases, overloading fails.
-- You might notice also that the agda2-infer-type command will usually fail to infer the type of a construction of which the head is an overloaded constructor.
-- This is because Agda really wants to check the construction, rather than inferring a type for it.
-- It just happens that when the constructor is not overloaded, it's easier to make progress, because that gives just enough to check the construction against.
-- Q: Copattern match in emacs
-- A: (James Wood 05.11.19, 22:41) If I understand the question correctly, it's the usual C-c C-c for case-splitting, but on an empty hole and followed immediately by RET, rather than entering a variable name. The intermediate prompt is “pattern variables to case (empty for split on result)”. It's splitting on the result that you want.
-- Constructor names can overlap; the right one will be chosen on usage depending on the expected type.
-- Note that other kind of names cannot overlap (e.g. definition names, etc..).
-- the cubical std-lib is described in a blog post from Andreas Mörtberg
-- https://homotopytypetheory.org/2018/12/06/cubical-agda/
-- isomorphisms are equivalences (i.e. have contractible fibers)
-- Hedberg’s theorem (types with decidable equality are sets)
-- The main things that the CCHM cubical type theory extends dependent type theory with are:
-- 1. An interval pretype
-- 2. Kan operations
-- 3. Glue types
-- 4. Cubical identity types
open import Cubical.Structures.CommRing
open import Cubical.Relation.Nullary.Base -- ¬_
open import Cubical.Relation.Binary.Base
-- open import Cubical.Data.Prod.Base renaming (_×_ to _×'_)
-- NOTE: Cubical.Core.Sigma uses Agda.Builtin.Sigma
-- open import Agda.Builtin.Sigma renaming (_×_ to _×ᵇ_)
open import Cubical.Data.Sum.Base
open import Cubical.Data.Sigma.Base -- Σ-types are defined in Core/Primitives as they are needed for Glue types.
-- PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ
--
-- We have a variable name in `(λ i → A)` as a hint for case splitting.
--
-- Path : ∀ {ℓ} (A : Set ℓ) → A → A → Set ℓ
-- Path A a b = PathP (λ _ → A) a b
--
-- _≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
-- _≡_ {A = A} = PathP (λ i → A)
-- Cubical.Foundations.Id
--
-- transport : ∀ (B : A → Type ℓ') {x y : A} → x ≡ y → B x → B y
-- transport B {x} p b = J (λ y p → B y) b p
--
-- _⁻¹ : {x y : A} → x ≡ y → y ≡ x
-- _⁻¹ {x = x} p = J (λ z _ → z ≡ x) refl p
--
-- ap : ∀ {B : Type ℓ'} (f : A → B) → ∀ {x y : A} → x ≡ y → f x ≡ f y
-- ap f {x} = J (λ z _ → f x ≡ f z) refl
--
-- _∙_ : ∀ {x y z : A} → x ≡ y → y ≡ z → x ≡ z
-- _∙_ {x = x} p = J (λ y _ → x ≡ y) p
refl1 : ∀ {ℓ} {A : Type ℓ} {x : A} → Path A x x
refl1 {x = x} = λ i → x
refl2 : ∀ {ℓ} {A : Type ℓ} {x : A} → PathP (λ _ → A) x x
refl2 {x = x} = λ i → x
refl3 : ∀{ℓ} {A : Type ℓ} {x : A} → PathP (λ _ → A) x x
refl3 {x = x} = λ _ → x
sym1 : ∀ {ℓ} {A : Type ℓ} {x y : A} → x ≡ y → y ≡ x
sym1 p = λ i → p (~ i)
cong1 : ∀ {ℓ} {A : Type ℓ} {x y : A} {B : A → Type ℓ}
(f : (a : A) → B a)
(p : x ≡ y)
--------------------------------------------
→ PathP (λ i → B (p i)) (f x) (f y)
cong1 f p i = f (p i)
cong2 : ∀ {ℓ} {A : Type ℓ} {x y : A} {B : A → Type ℓ}
(f : (a : A) → B a)
(p : PathP (λ i → A ) x y )
----------------------------------------------
→ ( PathP (λ i → B (p i)) (f x) (f y))
cong2 f p i = f (p i)
-- see "Propositional truncation" https://homotopytypetheory.org/2018/12/06/cubical-agda for
-- data ∥_∥ {ℓ} (A : Set ℓ) : Set ℓ where
-- ∣_∣ : A → ∥ A ∥
-- squash : ∀ (x y : ∥ A ∥) → x ≡ y
-- see https://planetmath.org/37propositionaltruncation
open import Cubical.HITs.PropositionalTruncation -- for `|_|` and `squash`
test1 : {Carrier : Type} -> ∃[ x ∈ Carrier ] x ≡ x → Carrier
test1 ∣ x , x≡x ∣ = x
-- Goal: Carrier
-- ———— Boundary ——————————————————————————————————————————————
-- i = i0 ⊢ test1 x
-- i = i1 ⊢ test1 y
-- ———— Constraints ———————————————————————————————————————————
-- test1 x = ?0 (i = i0) : Carrier
-- test1 y = ?0 (i = i1) : Carrier
test1 (squash x y i) = {! test1 x!}
test2 : {A : Type} → (x y : A) → x ≡ y → A
-- test2 x y x≡y = {! x≡y!}
test2 x y p = p i0
-- test4 : I → Type
-- test4 i = {!!}
test5a : {A : Type} {P : A → Type} → (x y : A) → x ≡ y → P x → P y
test5a {A} {P} x y p px = transport (λ i → P (p i)) px
test5b : {A : Type}
→ {P : A → Type}
→ (x y : A)
→ PathP (λ _ → A) x y -- x ≡ y
→ P x
--------------------------
→ P y
test5b {A} {P} x y x≡y Px = transport {A = P x} Px≡Py Px where
-- transport gives us `P x → P y`, but we need to feed it `P x ≡ P y`
Px≡Py : P x ≡ P y
Px≡Py = cong P x≡y
-- this is almost what `isProp P` would give us
-- isProp : ∀ {ℓ} → Type ℓ → Type ℓ
-- isProp A = (x y : A) → x ≡ y
-- but we need something like `∀(x y : A) → P x ≡ P y`
-- well, no. `cong P x≡y` gives us `P x ≡ P y`
-- it is different from non-cubical agda, where `x ≡ y` was sufficient, no matter what P is
-- there, we could just pattern match on refl and "change" the goal to `P x` instead of `P y`
-- well, in some sense we are already changing the goal as this approach could be "at the end" of a sequence of equational reasoning
-- ... just without pattern matching
test5c : {A : Type}
→ {P : A → Type}
→ (x y : A)
→ PathP (λ _ → A) x y -- x ≡ y
→ P x
--------------------------
→ P y
test5c {A} {P} x y x≡y Px = transport {A = P x} Px≡Py Px where
-- once again, without `cong`
Px≡Py : P x ≡ P y
-- we need to build a path that is `P x` at i0 and `P y` at i1
-- with `x≡y` we have given a path that is `x` at i0 and `y` at i1
-- therefore `x≡y(i)` behaves in the correct way and we just plug this into `P`
Px≡Py i = P (x≡y i)
-- the short version, collapsing all intermediates
test5f : ∀{ℓ ℓ'} {A : Type ℓ} {P : A → Type ℓ'} {x y : A} → (x ≡ y) → (P x) → P y
test5f {P = P} p px = transport (λ i → P (p i)) px
--primitive
-- transp : ∀ {ℓ} (A : (i : I) → Set (ℓ i)) (φ : I) (a : A i0) → A i1
transport1 : ∀{ℓ} {A B : Type ℓ} → A ≡ B → A → B
transport1 p a = transp (λ i → p i) i0 a
test5d : {A : Type} {P : A → Type} → (x y : A) → x ≡ y → P x → P y
test5d {A} {P} x y x≡y Px = transport (cong P x≡y) Px
module Utils where
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : A → Type ℓ
C : (a : A) → B a → Type ℓ
D : (a : A) → (b : B a) → C a b → Type ℓ
cong₁ : ∀ (f : (a : A) → B a)
→ {x : A} {y : A} (p : PathP (λ i → A) x y) -- (p : x ≡ y)
----------------------------------
→ PathP (λ i → B (p i)) (f x) (f y)
cong₁ f p i = f (p i)
{-# INLINE cong₁ #-}
cong₂' : ∀ {F : (a : A) → (b : B a) → Type ℓ}
→ (f : (a : A) → (b : B a) → F a b)
→ {x : A } {y : A } (p : PathP (λ i → A ) x y) -- (p : x ≡ y)
→ {u : B x } {v : B y } (q : PathP (λ i → B (p i) ) u v) -- ? u ≡ v given x ≡ y ?
---------------------------------------------
→ PathP (λ i → F (p i) (q i)) (f x u) (f y v)
cong₂' f p q i = f (p i) (q i)
{-# INLINE cong₂' #-}
cong₃ : ∀{F : (a : A) → (b : B a) → (c : C a b) → Type ℓ}
→ (f : (a : A) → (b : B a) → (c : C a b) → F a b c)
→ {x : A } {y : A } (p : PathP (λ i → A ) x y) -- (p : x ≡ y)
→ {u : B x } {v : B y } (q : PathP (λ i → B (p i) ) u v) -- ? u ≡ v given x ≡ y ?
→ {m : C x u} {n : C y v} (r : PathP (λ i → C (p i) (q i)) m n) -- ? m ≡ n given x ≡ y and u ≡ v ?
--------------------------------------------
→ PathP (λ i → F (p i) (q i) (r i)) (f x u m) (f y v n)
cong₃ f p q r i = f (p i) (q i) (r i)
{-# INLINE cong₃ #-}
cong₄ : ∀{F : (a : A) → (b : B a) → (c : C a b) → (d : D a b c) → Type ℓ}
→ (f : (a : A) → (b : B a) → (c : C a b) → (d : D a b c) → F a b c d)
→ {x : A } {y : A } (p : PathP (λ i → A ) x y) -- (p : x ≡ y)
→ {u : B x } {v : B y } (q : PathP (λ i → B (p i) ) u v) -- ? u ≡ v given x ≡ y ?
→ {m : C x u } {n : C y v } (r : PathP (λ i → C (p i) (q i) ) m n) -- ? m ≡ n given x ≡ y and u ≡ v ?
→ {k : D x u m} {l : D y v n} (s : PathP (λ i → D (p i) (q i) (r i)) k l) -- ? k ≡ l given x ≡ y and u ≡ v and m ≡ n?
--------------------------------------------
→ PathP (λ i → F (p i) (q i) (r i) (s i)) (f x u m k) (f y v n l)
cong₄ f p q r s i = f (p i) (q i) (r i) (s i)
{-# INLINE cong₄ #-}
open Utils using (cong₃; cong₄)
-- slide 18 of http://www.cse.chalmers.se/~abela/esslli2016/talkESSLLI3.pdf
fullelim : (A : Type)
→ (C : (x y : A) → (p : x ≡ y) → Type)
→ (M N : A)
→ (P : M ≡ N)
→ (O : (z : A) → C z z refl)
------------------------
→ C M N P
fullelim A C M N P O = transport along (O M) where
along : C M M refl ≡ C M N P
-- the "obvious" idea would be to show equality on every argument
-- and then use a brute force `cong₃` to apply these equalities
along = cong₃ C (refl {x = M}) P refl≡P where
-- the first two arguments are easy, and the hole of the third argument rewards us with a signature to implement:
refl≡P : PathP (λ i → M ≡ (P i)) refl P
-- here, we need to build a path that is refl on i0 and P on i1 just with the things we have given
-- refl : ∀{ℓ} {A : Type ℓ} {x : A} x ≡ x
-- refl {x = x} = λ _ → x
-- _≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
-- _≡_ {A = A} = PathP (λ i → A)
-- therefore, we have
-- refl : ∀{ℓ} {A : Type ℓ} {x : A} → PathP (λ i → A) M M
-- refl {x = x} = λ _ → x
-- P : PathP (λ i → A) M N
-- Goal: M ≡ P i
-- Goal: PathP (λ j → A) M (P i)
refl≡P i = λ j → P (i ∧ j)
-- I could not come up with the solution myself, but I was able to pick it off ...
-- ... of `J` under "Kan operations" at https://homotopytypetheory.org/2018/12/06/cubical-agda/
-- so, how does this work? These are the cases:
-- i | j | i∧j | P(i∧j) | λ j → P(i∧j) | λ i → λ j → P(i∧j)
-- i0 | i0 | i0 | M : A | M≡M : M ≡ M | p : (M≡M) ≡ (M≡N)
-- i0 | i1 | i0 | M : A | | which is "like"
-- i1 | i0 | i0 | M : A | M≡N : M ≡ N | p : refl ≡ P
-- i1 | i1 | i1 | N : A | |
-- and indeed, they work out
-- we could not write `refl ≡ P` but instead have `PathP _ refl P`
fullelim2 : (A : Type)
→ (C : (x y : A) → (p : x ≡ y) → Type)
→ (M N : A)
→ (P : M ≡ N)
→ (O : (z : A) → C z z refl)
------------------------
→ C M N P
-- we can unfold `transport` as in the blog post
-- transport : {A B : Type ℓ} → A ≡ B → A → B
-- transport p a = transp (λ i → p i) i0 a
fullelim2 A C M N P O = transp (λ i → along i) i0 (O M) where
-- and we can directly "set up" the path without using `cong₃`
along : C M M refl ≡ C M N P
along i = C (refl {x = M} i) (P i) (λ j → P (i ∧ j) )
--
-- see favonia: [Agda] Equational Reasoning
-- https://favonia.org/courses/hdtt2020/agda/agda-0305-eqreasoning.agda
-- Kraus 2013 - Generalizations of Hedberg’s Theorem
-- https://www.cs.bham.ac.uk/~mhe/papers/hedberg.pdf
-- Although the identity types in Martin-Löf type theory (MLTT) are defined byone constructor refl and by one eliminator J that matches the constructor, the statement that every identity type has at most one inhabitant is not provable [9].
-- Thus,uniqueness of identity proofs(UIP), or, equivalently, Streicher’s axiom K are principles that have to be assumed, and have often been assumed, as additional rules of MLTT.
-- ...
-- we do not assume the principle of unique identity proofs.
-- However, certain types do satisfy it naturally, and such types are often called h-sets.
-- A sufficient condition for a type to be an h-set, given by Hedberg [8], isthat it has decidable propositional equality.
-- In Section 3, we analyze Hedberg’s original argument, which consists of two steps:
-- 1. A type X is an h-set iff for all x, y : X there is a constant map x = y → x = y.
-- 2. If X has decidable equality then such constant endomaps exist
-- Decidable equality means that, for all x and y, we have (x = y) + (x ≠ y).
-- Thus, a natural weakening is ¬¬-separated equality, ¬¬(x = y) → x = y, which occurs often in constructive mathematics.
-- In this case we say that the type X is separated.
-- For example, going beyond MLTT, the reals and the Cantorspace in Bishop mathematics and topos theory are separated.
-- In MLTT, the Cantortype of functions from natural numbers to booleans is separated under the assumption of functional extensionality,
-- ∀ f g : X → Y, (∀ x : X, f x = g x) → f = g.
-- We observe that under functional extensionality, a separated type X is an h-set, because there is always a constant map x = y → x = y.
-- In order to obtain a further characterization of the notion of h-set, we consider truncations
-- (also known as bracket or squash types), written ‖X‖in accordance with recent HoTT notation.
-- The idea is to collapse all inhabitants of X so that ‖X‖ has at most one inhabitant.
-- We refer the reader to the technical development for a precise definition.
-- cites
-- Altenkirch 2012 - On h-Propositional Reflection and Hedberg’s Theorem
-- https://homotopytypetheory.org/2012/11/27/on-h-propositional-reflection-and-hedbergs-theorem/
-- Bracket-Type https://ncatlab.org/nlab/show/bracket+type
-- By contrast, in the paradigm that may be called propositions as some types, every proposition is a type, but not every type is a proposition.
-- The types which are propositions are generally those which “have at most one inhabitant” — in homotopy type theory this is called being of h-level 1 or being a (-1)-type.
-- ...
-- For A a type, the support of A denoted supp(A) or isInhab(A) or τ₋₁ A or ‖A‖₋₁ or ‖A‖ or, lastly, [A],
-- is the higher inductive type defined by the two constructors
-- a : A ⊢ isinhab(a) : supp(A)
-- x : supp(A), y : supp(A) ⊢ inpath(x,y) : (x = y),
-- where in the last sequent on the right we have the identity type.
-- https://github.com/agda/cubical/issues/286
-- It could also be a good idea to axiomatize the notion of a Caucy-complete Archimedean ordered field, as in Auke Booij's thesis, and show that Dedekind reals are an instance. The HoTT reals are then another instance. (Can cubical Agda handle the HoTT reals as a HIIT yet?)
-- https://www.cs.bham.ac.uk/~abb538/thesis-first_submission.pdf
-- Booij 2020 - Analysis in Univalent Type Theory
-- 4.1 Algebraic structure of numbers
--
-- Fields have the property that nonzero numbers have a multiplicative inverse, or more precisely, that
-- (∀ x : F) x ≠ 0 ⇒ (∃ y : F) x · y = 1.
--
-- Remark 4.1.1.
-- If we require the collection of numbers to form a set in the sense of Definition 2.5.4, and satisfy the ring axioms, then multiplicative inverses are unique, so that the above is equivalent to the proposition
-- (Π x : F) x ≠ 0 ⇒ (Σ y : F) x · y = 1.
--
-- Definition 4.1.2.
-- A classical field is a set F with points 0, 1 : F, operations +, · : F → F → F, which is a commutative ring with unit, such that
-- (∀ x : F) x ≠ 0 ⇒ (∃ y : F) x · y = 1.
private
variable
ℓ ℓ' ℓ'' : Level
module ClassicalFieldModule where -- NOTE: one might want to put this into another file to omit the name-clashing
record IsClassicalField {F : Type ℓ}
(0f : F) (1f : F) (_+_ : F → F → F) (_·_ : F → F → F) (-_ : F → F) (_⁻¹ᶠ : (x : F) → {{¬(x ≡ 0f)}} → F) : Type ℓ where
constructor isclassicalfield
field
isCommRing : IsCommRing 0f 1f _+_ _·_ -_
·-rinv : (x : F) → (p : ¬(x ≡ 0f)) → x · (_⁻¹ᶠ x {{p}}) ≡ 1f
·-linv : (x : F) → (p : ¬(x ≡ 0f)) → (_⁻¹ᶠ x {{p}}) · x ≡ 1f
open IsCommRing {0r = 0f} {1r = 1f} isCommRing public
record ClassicalField : Type (ℓ-suc ℓ) where
field
Carrier : Type ℓ
0f : Carrier
1f : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
_⁻¹ᶠ : (x : Carrier) → {{¬(x ≡ 0f)}} → Carrier
isClassicalField : IsClassicalField 0f 1f _+_ _·_ -_ _⁻¹ᶠ
infix 9 _⁻¹ᶠ
infix 8 -_
infixl 7 _·_
infixl 6 _+_
open IsClassicalField isClassicalField public
-- Remark 4.1.3.
-- As in the classical case, by proving that additive and multiplicative inverses are unique, we also obtain the negation and division operations.
--
-- For the reals, the assumption x ≠ 0 does not give us any information allowing us to bound x away from 0, which we would like in order to compute multiplicative inverses.
-- Hence, we give a variation on the denition of fields in which the underlying set comes equipped with an apartness relation #, which satises x # y ⇒ x ≠ y, although the converse implication may not hold.
-- This apartness relation allows us to make appropriate error bounds and compute multiplicative inverses based on the assumption x # 0.
--
-- Definition 4.1.4.
-- - An apartness relation, denoted by #, is an irreflexive symmetric cotransitive relation.
-- - A strict partial order, denoted by <, is an irreflexive transitive cotransitive relation.
IsIrrefl : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ')
IsIrrefl {A = A} R = (a b : A) → R a b → ¬(R b a)
IsCotrans : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ')
IsCotrans {A = A} R = (a b : A) → R a b → (∀(x : A) → (R a x) ⊎ (R x b))
-- NOTE: these `IsX` definitions are in the style of the standard library and do not make `a` and `b` to be implicit arguments
-- when using them, we can just use `_` as in `isIrrefl _ _ a#b`
-- NOTE: module parameters "add" to the contained function's arguments
-- see https://agda.readthedocs.io/en/v2.6.0.1/language/module-system.html#parameterised-modules
-- IsApartnessRel : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ')
-- IsApartnessRel R = IsIrrefl R × BinaryRelation.isSym R × IsCotrans R
record IsApartnessRel {ℓ ℓ' : Level} {A : Type ℓ} (R : Rel A A ℓ') : Type (ℓ-max ℓ ℓ') where
field
isIrrefl : IsIrrefl R
isSym : BinaryRelation.isSym R
isCotrans : IsCotrans R
-- IsStrictPartialOrder : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ')
-- IsStrictPartialOrder R = IsIrrefl R × BinaryRelation.isTrans R × IsCotrans R
record IsStrictPartialOrder {ℓ ℓ' : Level} {A : Type ℓ} (R : Rel A A ℓ') : Type (ℓ-max ℓ ℓ') where
field
isIrrefl : IsIrrefl R
isTrans : BinaryRelation.isTrans R
isCotrans : IsCotrans R
-- Definition 4.1.5.
-- A constructive field is a set F with points 0, 1 : F, binary operations +, · : F → F → F, and a binary relation # such that
-- 1. (F, 0, 1, +, ·) is a commutative ring with unit;
-- 2. x : F has a multiplicative inverse iff x # 0;
-- 3. + is #-extensional, that is, for all w, x, y, z : F
-- w + x # y + z ⇒ w # y ∨ x # z.
{- NOTE: about naming in the standard library
with `isCommRing : IsCommRing 0f 1f _+_ _·_ -_` we import
is-set : (x y : Carrier) (x₁ y₁ : x ≡ y) → x₁ ≡ y₁ -- NOTE: this is imported from +-isAbGroup and explicitly hidden from ·-isMonoid
isCommRing : IsCommRing 0f 1f _+_ _·_ -_
isRing : IsRing 0f 1f _+_ _·_ -_
+-isAbGroup : IsAbGroup 0f _+_ -_
+-assoc : (x y z : Carrier) → x + (y + z) ≡ x + y + z
+-identity : (x : Carrier) → (x + 0f ≡ x) × (0f + x ≡ x)
+-rid : (x : Carrier) → x + 0f ≡ x
+-lid : (x : Carrier) → 0f + x ≡ x
+-inv : (x : Carrier) → (x + - x ≡ 0f) × (- x + x ≡ 0f)
+-linv : (x : Carrier) → - x + x ≡ 0f
+-rinv : (x : Carrier) → x + - x ≡ 0f
+-comm : (x y : Carrier) → x + y ≡ y + x
+-isSemigroup : IsSemigroup _+_
+-isMonoid : IsMonoid 0f _+_
+-isGroup : IsGroup 0f _+_ -_
·-isSemigroup : IsSemigroup _·_
·-isMonoid : IsMonoid 1f _·_
·-comm : (x y : Carrier) → x · y ≡ y · x
·-assoc : (x y z : Carrier) → x + (y + z) ≡ x + y + z
·-identity : (x : Carrier) → (x · 1f ≡ x) × (1f · x ≡ x)
·-lid : (x : Carrier) → 1f · x ≡ x
·-rid : (x : Carrier) → x · 1f ≡ x
dist : (x y z : Carrier) → (x · (y + z) ≡ x · y + x · z) × ((x + y) · z ≡ x · z + y · z)
·-rdist-+ : (x y z : Carrier) → x · (y + z) ≡ x · y + x · z
·-ldist-+ : (x y z : Carrier) → (x + y) · z ≡ x · z + y · z
there is
module GroupLemmas (G : Group {ℓ}) where
record MonoidEquiv (M N : Monoid {ℓ}) : Type ℓ where
module SemigroupΣTheory {ℓ} where
module CommRingΣTheory {ℓ} where
module MonoidΣTheory {ℓ} where
module MonoidTheory {ℓ} (M' : Monoid {ℓ}) where
module GroupΣTheory {ℓ} where
module AbGroupΣTheory {ℓ} where
module RingΣTheory {ℓ} where
module Theory (R' : Ring {ℓ}) where
module PosetReasoning (P : Poset ℓ₀ ℓ₁) where
there is a syntax for https://agda.readthedocs.io/en/latest/language/module-system.html?highlight=module#parameterised-modules
module SortNat = Sort Nat leqNat
the non-cubical standard library has a lot of machinery that is missing in the cubical-stdlib
module Function.Base where
-- Binary application
_⟨_⟩_ : A → (A → B → C) → B → C
x ⟨ f ⟩ y = f x y
-- Composition of a binary function with a unary function
_on_ : (B → B → C) → (A → B) → (A → A → C)
_*_ on f = λ x y → f x * f y
-- Flipped application (aka pipe-forward)
_|>_ : ∀ {A : Set a} {B : A → Set b} → (a : A) → (∀ a → B a) → B a
-- Construct an element of the given type by instance search.
it : {A : Set a} → {{A}} → A
it {{x}} = x
module Relation.Binary.Core where
infix 4 _⇒_ _⇔_ _=[_]⇒_
-- Implication/containment - could also be written _⊆_.
-- and corresponding notion of equivalence
_⇒_ : REL A B ℓ₁ → REL A B ℓ₂ → Set _
P ⇒ Q = ∀ {x y} → P x y → Q x y
_⇔_ : REL A B ℓ₁ → REL A B ℓ₂ → Set _
P ⇔ Q = P ⇒ Q × Q ⇒ P
-- Generalised implication - if P ≡ Q it can be read as "f preserves P".
_=[_]⇒_ : Rel A ℓ₁ → (A → B) → Rel B ℓ₂ → Set _
P =[ f ]⇒ Q = P ⇒ (Q on f)
-- A synonym for _=[_]⇒_.
_Preserves_⟶_ : (A → B) → Rel A ℓ₁ → Rel B ℓ₂ → Set _
f Preserves P ⟶ Q = P =[ f ]⇒ Q
-- A binary variant of _Preserves_⟶_.
_Preserves₂_⟶_⟶_ : (A → B → C) → Rel A ℓ₁ → Rel B ℓ₂ → Rel C ℓ₃ → Set _
_∙_ Preserves₂ P ⟶ Q ⟶ R = ∀ {x y u v} → P x y → Q u v → R (x ∙ u) (y ∙ v)
module Algebra.Definitions
Congruent₁ : Op₁ A → Set _
Congruent₁ f = f Preserves _≈_ ⟶ _≈_
Congruent₂ : Op₂ A → Set _
Congruent₂ ∙ = ∙ Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_
LeftCongruent : Op₂ A → Set _
LeftCongruent _∙_ = ∀ {x} → (x ∙_) Preserves _≈_ ⟶ _≈_
RightCongruent : Op₂ A → Set _
RightCongruent _∙_ = ∀ {x} → (_∙ x) Preserves _≈_ ⟶ _≈_
the non-cubical standard library makes more use of unicode, e.g. in invˡ and invʳ
for the inverse, we have in the non-cubical standard library
inverseˡ : LeftInverse ε _⁻¹ _∙_
inverseˡ = proj₁ inverse
inverseʳ : RightInverse ε _⁻¹ _∙_
inverseʳ = proj₂ inverse
uniqueˡ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → x ≈ (y ⁻¹)
uniqueˡ-⁻¹ = Consequences.assoc+id+invʳ⇒invˡ-unique
setoid ∙-cong assoc identity inverseʳ
uniqueʳ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → y ≈ (x ⁻¹)
uniqueʳ-⁻¹ = Consequences.assoc+id+invˡ⇒invʳ-unique
setoid ∙-cong assoc identity inverseˡ
interestingly, this follows from just one field `inverse : Inverse ε _⁻¹ _∙_`
there is `module Algebra.Consequences.Setoid` for such results ("consequences")
there are open pull requests which might have some more information about the "intended" style
https://github.com/agda/cubical/pull/331
Algebras and modules #331
https://github.com/agda/cubical/pull/365
Mayer-Vietoris and some cohomology groups #365
https://github.com/agda/cubical/pull/325
Denial field #325
A denial field is a commutative ring where every non-zero element has an inverse. See #301 for a discussion of other notions of 'field' in constructive algebra.
https://github.com/felixwellen/cubical/tree/denial-field
https://github.com/agda/cubical/issues/301
Add Field to Cubical.Structures #301
In the style of Ring, etc. from #284. I think it would be good to have this so we could show ℚ is a field.
https://github.com/agda/cubical/pull/284
Newstructures #284
Adding some new structures (semigroups, groups, abelian groups and rngs) and a new folder of Algebra, in order to produce results about these new Algebraic structures.
https://github.com/agda/cubical/commit/8cf91aeb49ebf26d4cf4e6795e8b56041e28c7a1
Rewrite Group, AbGroup, Ring and CommRing to be records instead of nested Sigma types
https://github.com/agda/cubical/pull/324
Ideals and quotient rings #324
- define (left-, right- and two-sided) ideals
- define quotient by a two-sided ideal
- construct the ring structure on the quotient
-}
record IsConstructiveField {F : Type ℓ}
(0f : F) (1f : F) (_+_ : F → F → F) (_·_ : F → F → F) (-_ : F → F) (_#_ : Rel F F ℓ') (_⁻¹ᶠ : (x : F) → {{x # 0f}} → F) : Type (ℓ-max ℓ ℓ') where
constructor isconstructivefield
field
isCommRing : IsCommRing 0f 1f _+_ _·_ -_
·-rinv : (x : F) → (p : x # 0f) → x · (_⁻¹ᶠ x {{p}}) ≡ 1f
·-linv : (x : F) → (p : x # 0f) → (_⁻¹ᶠ x {{p}}) · x ≡ 1f
-- ·-inv : (x : F) → (p : x # 0f) → x · (let instance p = p in (x ⁻¹ᶠ)) ≡ 1f -- this does also work
-- ·-inv : (x : F) → ({{p}} : x # 0f) → x · (x ⁻¹ᶠ) ≡ 1f -- this does not do the right thing
-- ·-inv-back : (x : F) → ∃[ y ∈ F ] (x · y ≡ 1f) → x # 0f
·-inv-back : (x y : F) → (x · y ≡ 1f) → x # 0f × y # 0f
+-#-extensional : (w x y z : F) → (w + x) # (y + z) → (w # y) ⊎ (x # z)
isApartnessRel : IsApartnessRel _#_
open IsCommRing {0r = 0f} {1r = 1f} isCommRing public
open IsApartnessRel isApartnessRel public
renaming
( isIrrefl to #-irrefl
; isSym to #-sym
; isCotrans to #-cotrans )
_ = {!!}
record ConstructiveField : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
Carrier : Type ℓ
0f : Carrier
1f : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
_#_ : Rel Carrier Carrier ℓ'
_⁻¹ᶠ : (x : Carrier) → {{x # 0f}} → Carrier
isConstructiveField : IsConstructiveField 0f 1f _+_ _·_ -_ _#_ _⁻¹ᶠ
infix 9 _⁻¹ᶠ
infixl 7 _·_
infix 6 -_
infixl 5 _+_
infixl 4 _#_
open IsConstructiveField isConstructiveField public
open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim`
-- Lemma 4.1.6.
-- For a constructive field (F, 0, 1, +, ·, #), the following hold.
-- 1. 1 # 0.
-- 2. Addition + is #-compatible in the sense that for all x, y, z : F
-- x # y ⇔ x + z # y + z.
-- 3. Multiplication · is #-extensional in the sense that for all w, x, y, z : F
-- w · x # y · z ⇒ w # y ∨ x # z.
module Lemmas-4-6-1 {{F : ConstructiveField {ℓ} {ℓ'}}} where
--open ConstructiveField {{...}} public -- creates additional `ConstructiveField.foo F` in the "Goal/Have-previews"
open ConstructiveField F -- works
open import Cubical.Structures.Ring
-- NOTE: this also creates additional `Ring.Carrier (makeRing ...)` in the "Goal/Have-previews", except when using C-u C-u C-... then these get normalized fine
-- can we do something with pragmas here? https://agda.readthedocs.io/en/latest/language/pragmas.html?highlight=INLINE#the-inline-and-noinline-pragmas
-- or maybe with macros? https://github.com/alhassy/gentle-intro-to-reflection
-- using this `R` makes it a little better
R = (makeRing 0f 1f _+_ _·_ -_ is-set +-assoc +-rid +-rinv +-comm ·-assoc ·-rid ·-lid ·-rdist-+ ·-ldist-+)
open Cubical.Structures.Ring.Theory R
-- 0-rightNullifies
-- open Ring {{...}} public
{-
module ReflectionTest where
open import Data.Nat as Nat hiding (_⊓_)
open import Data.List as List
open import Data.Char as Char
open import Data.String as String
open import Reflection hiding (name; Type)
open import Reflection.Term as Term public hiding (Type)
test06 = (quoteTC 0-rightNullifies)
test07 : _
unquoteDef test07 = defineFun test07
[ clause
( [] ) -- hidden arguments `{x}`
( [] ) -- visible arguments `{y}`
(quoteTerm 0f) -- the "Term" at the right hand side of the `=`
]
-- {-# INLINE test07 #-}
-- {-# NOINLINE test07 #-}
proof07 : test07 ≡ 0f
proof07 = {!!}
-}
{-
-- NOTE: it might be possible with --overlapping-instances to resolve this "Goal/Have-preview" issue
-- but it is mentioned that this "might lead to an exponential slowdown in instance resolution and possibly (apparent) looping behaviour"
-- also the OPTION pragma to apply --overlapping-instances can only be set per file (and not per module)
-- so it might be a good idea to have a separate "Theory.agda" or "Properties.agda" (as it is called in the standard library)
-- well, in a test with --overlapping instances, I got the issue that -_ is defined multiple times
-- to be fair, the result we have implemented might fit better in a more general Ring context
-- so one might think about this and until then, I guess, the best solution is to just omit multiple instances
module InstanceTest where
-- taken from https://agda.readthedocs.io/en/latest/language/instance-arguments.html#defining-type-classes
-- open import Algebra
open import Agda.Builtin.Nat
open import Data.List renaming (List to BList)
record Monoid {a} (A : Type a) : Type a where
field
mempty : A
_<>_ : A → A → A
open Monoid {{...}} public
instance
ListMonoid : ∀ {a} {A : Type a} → Monoid (BList A)
-- normal: provide "implementation" in a single term
-- ListMonoid = record { mempty = []; _<>_ = _++_ }
-- with copatterns: provide "implementation" with patterns
mempty {{ListMonoid}} = []
_<>_ {{ListMonoid}} xs ys = xs ++ ys
mconcat : ∀ {a} {A : Type a} → {{Monoid A}} → BList A → A
mconcat [] = mempty
mconcat (x ∷ xs) = x <> mconcat xs
sum1 : BList Nat → Nat
sum1 xs =
let instance -- NOTE: IMPORTANT: the instance-block needs to be more indented (!) than the `instance` keyword
NatMonoid : Monoid Nat
NatMonoid = record { mempty = 0; _<>_ = Agda.Builtin.Nat._+_ }
in mconcat xs
itest2 =
let
instance
rr = R
in {! 0-rightNullifies!}
-- To restrict an instance to the current module, you can mark it as private. For instance,
-- https://agda.readthedocs.io/en/latest/language/instance-arguments.html#restricting-instance-search
-}
{-
https://agda.readthedocs.io/en/latest/language/abstract-definitions.html
Abstract definitions
Definitions can be marked as abstract, for the purpose of hiding implementation details, or to speed up type-checking of other parts. In essence, abstract definitions behave like postulates, thus, do not reduce/compute. For instance, proofs whose content does not matter could be marked abstract, to prevent Agda from unfolding them (which might slow down type-checking).
-}
-- anonymous modules `module _ params where` automatically open themselves
-- they are not well documented but there is this usage example
-- Anonymous modules or sections #735
-- https://github.com/agda/agda/issues/735
-- I often want to use something like sections in Coq. I usually use parametrized modules but this has at least two issues that Coq does not have:
-- 1) I need to give a name to the module, and there is often no meaningful name to be given
-- 2) It exports the module, so I cannot define a module in another file with the same name
-- the following code
-- module _ params where
-- declarations
-- would be translated to:
-- private
-- module Fresh params where
-- declarations
-- open Fresh public
-- where Fresh is a new name.
-- NOTE: this gives a hint on the use of "sections" in mathematical writing
-- it suggests, that these introduce variable-but-fixed parameter dependencies to all definitions (in the way the `variable` keyword does)
-- the difference between an anonymous module and a variable seems to be that the module adds all parameters, where `variable` only adds parameters when used
-- also, in the module we have more flexibility with opening other modules and hiding names with the `private` keyword, etc.
-- and there is
-- https://github.com/agda/agda/issues/1145
-- Allow multiple layout keywords on the same line #1145
-- NOTE: IMPORTANT: when in a hole, with C-c C-o one can list "module contents"
-- if given `F` here, we can see the contents of F
-- I guess, since every inherited member is included with `open ... public`,
-- we can continue with just `isConstructiveField`
-- and even `isCommRing`
-- and even `isRing`
-- this greatly helps to investigate available
{-
test3 : ∃[ x ∈ Carrier ] x · x ≡ x → Carrier
test3 ∥_∥.∣ Σx-x·x≡x ∣ = {!!}
--test ∥_∥.∣ x , x·x≡x ∣ = x
test3 (∥_∥.squash Σx-x·x≡x₁ Σx-x·x≡x₂ i) = {!!}
test3b : {A : Type} → ∃[ x ∈ A ] ∃[ y ∈ A ] x ≡ y → A
test3b ∥_∥.∣ fst₁ , ∥_∥.∣ fst₂ , snd₁ ∣ ∣ = {!!}
test3b ∥_∥.∣ fst₁ , ∥_∥.squash snd₁ ∥_∥.∣ x ∣ i ∣ = {!!}
test3b ∥_∥.∣ fst₁ , ∥_∥.squash snd₁ (∥_∥.squash snd₂ ∥_∥.∣ x ∣ i₁) i ∣ = {!!}
test3b ∥_∥.∣ fst₁ , ∥_∥.squash snd₁ (∥_∥.squash snd₂ (∥_∥.squash snd₃ snd₄ i₂) i₁) i ∣ = {!!}
test3b (∥_∥.squash ∥_∥.∣ x ∣ ∥_∥.∣ x₁ ∣ i) = {!!}
test3b (∥_∥.squash ∥_∥.∣ x ∣ (∥_∥.squash x₁ x₂ i₁) i) = {!!}
test3b (∥_∥.squash (∥_∥.squash x x₂ i₁) x₁ i) = {!!}
-}
-- ∃ : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')
-- ∃ A B = ∥ Σ A B ∥
-- infix 2 ∃-syntax
-- ∃-syntax : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')
-- ∃-syntax = ∃
-- syntax ∃-syntax A (λ x → B) = ∃[ x ∈ A ] B
-- Lemma 4.1.6.1
1f#0f : 1f # 0f
1f#0f with ·-identity 1f
-- 1f#0f | 1·1≡1 , _ = ·-inv-back 1f ∣ (1f , 1·1≡1) ∣ -- need additional ∣_∣ resp. \|_\| around the tuple
1f#0f | 1·1≡1 , _ = fst (·-inv-back _ _ 1·1≡1)
_ = Cubical.Data.Sigma.Base._×_ -- fst and snd
a+b-b≡a : ∀ a b → a ≡ (a + b) - b
-- NOTE: about workflow
-- one can investigate some single term in the hole (C-c C-.), but not a second one
-- therefore, we can move a term temporarily into a let-clause and work on another term in the hole
-- ... is there equational reasoning in --cubical ?
-- NOTE: Yes! it is in Cubical.Foundations.Id
a+b-b≡a a b = let P = sym (fst (+-inv b))
Q = sym (fst (+-identity a))
R = transport (λ i → a ≡ a + P i) Q
S = transport (λ i → a ≡ (+-assoc a b (- b)) i ) R
in S
+-preserves-≡ : ∀{a b} → ∀ c → a ≡ b → a + c ≡ b + c
+-preserves-≡ c a≡b i = a≡b i + c
+-preserves-≡-l : ∀{a b} → ∀ c → a ≡ b → c + a ≡ c + b
+-preserves-≡-l c a≡b i = c + a≡b i
a+b≡0→a≡-b : ∀{a b} → a + b ≡ 0f → a ≡ - b
a+b≡0→a≡-b {a} {b} a+b≡0 = transport
(λ i →
let RHS = snd (+-identity (- b))
LHS₁ : a + (b + - b) ≡ a + 0f
LHS₁ = +-preserves-≡-l a (fst (+-inv b))
LHS₂ : (a + b) - b ≡ a
LHS₂ = transport (λ j → (+-assoc a b (- b)) j ≡ fst (+-identity a) j) LHS₁
in LHS₂ i ≡ RHS i
) (+-preserves-≡ (- b) a+b≡0)
a·-b≡-a·b : ∀ a b → a · (- b) ≡ - a · b
a·-b≡-a·b a b =
let P : a · 0f ≡ 0f
P = 0-rightNullifies a
Q : a · (- b + b) ≡ 0f
Q = transport (λ i → a · snd (+-inv b) (~ i) ≡ 0f) P
R : a · (- b) + a · b ≡ 0f
R = transport (λ i → ·-rdist-+ a (- b) b i ≡ 0f) Q
in a+b≡0→a≡-b R
a·b-a·c≡a·[b-c] : ∀ a b c → a · b - a · c ≡ a · (b - c)
a·b-a·c≡a·[b-c] a b c =
let P : a · b + a · (- c) ≡ a · (b + - c)
P = sym (·-rdist-+ a b (- c))
Q : a · b - a · c ≡ a · (b + - c)
Q = transport (λ i → a · b + a·-b≡-a·b a c i ≡ a · (b + - c) ) P
in Q
-- Lemma 4.1.6.2
-- For #-compatibility of +, suppose x # y, that is, (x +z) −z # (y +z) −z.
-- Then #-extensionality gives (x + z # y + z) ∨ (−z # −z), where the latter case is excluded by irreflexivity of #.
+-#-compatible : ∀(x y z : Carrier) → x # y → x + z # y + z
+-#-compatible x y z x#y with
let P = transport (λ i → a+b-b≡a x z i # a+b-b≡a y z i ) x#y
in +-#-extensional _ _ _ _ P
... | inl x+z#y+z = x+z#y+z
... | inr -z#-z = ⊥-elim (#-irrefl _ _ -z#-z -z#-z)
-- The other direction is similar.
+-#-compatible-inv : ∀(x y z : Carrier) → x + z # y + z → x # y
+-#-compatible-inv _ _ _ x+z#y+z with +-#-extensional _ _ _ _ x+z#y+z
... | inl x#y = x#y
... | inr z#z = ⊥-elim (#-irrefl _ _ z#z z#z)
-- _ = {!!} ≃⟨ {!!} ⟩ {!!} ■
-- open import
-- _ = {!!} ≡[ i ]⟨ {!!} ⟩ {!!} ∎
--_≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → x ≡ z
--_ ≡⟨ x≡y ⟩ y≡z = x≡y ∙ y≡z
-- for a list of unicode symbols in agda, see https://people.inf.elte.hu/divip/AgdaTutorial/Symbols.html
infix 3 _◼
infixr 2 _⇒⟨_⟩_
_⇒⟨_⟩_ : ∀{ℓ ℓ' ℓ''} {Q : Type ℓ'} {R : Type ℓ''} → (P : Type ℓ) → (P → Q) → (Q → R) → (P → R)
_ ⇒⟨ pq ⟩ qr = qr ∘ pq
_◼ : ∀{ℓ} (A : Type ℓ) → A → A
_ ◼ = λ x → x
f : Carrier → Carrier
f x with +-inv x
... | fst₁ , snd₁ = {!!}
-- see https://agda.readthedocs.io/en/latest/language/instance-arguments.html
it : ∀ {a} {A : Type a} → {{A}} → A
it {{x}} = x -- instance search
-- Lemma 4.1.6.3
-- TODO: there is equational resoning in Cubical.Foundations.Id, use this
-- P = _ ≡⟨ _ ⟩ _ ∎
-- P = _ ≡[ i ] _ ∎
-- syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y
-- in general this module offers a lot of useful equational machinery
-- it already makes use of path concatenation with ∙ and ∙∙
-- there is also Cubical.Foundations.Equiv
-- P = _ ≃⟨ _ ⟩ _ ■
·-#-extensional-case1 : ∀(w x y z : Carrier) → w · x # y · z → w · x # w · z → x # z
·-#-extensional-case1 w x y z w·x#y·z w·x#w·z =
let P : w · x + - w · x # w · z + - w · x
P = +-#-compatible _ _ (- (w · x)) w·x#w·z
Q : 0f # w · (z + - x)
Q = transport (λ i → (fst (+-inv (w · x)) i) # a·b-a·c≡a·[b-c] w z x i) P
instance -- NOTE: this allows to use ⁻¹ᶠ without an instance argument
q = #-sym _ _ Q
-- see https://agda.readthedocs.io/en/latest/language/instance-arguments.html
it : ∀ {a} {A : Type a} → {{A}} → A
it {{x}} = x -- instance search
R : w · (z - x) · (w · (z - x)) ⁻¹ᶠ ≡ 1f
R = ·-rinv (w · (z - x)) it -- (#-sym _ _ Q)
S : (z + - x) · w · (w · (z + - x)) ⁻¹ᶠ ≡ 1f
S = transport (λ i → ·-comm w (z - x) i · (w · (z - x)) ⁻¹ᶠ ≡ 1f) R
T : (z + - x) · (w · (w · (z + - x)) ⁻¹ᶠ) ≡ 1f
T = transport (λ i → ·-assoc (z + - x) w ((w · (z + - x)) ⁻¹ᶠ) (~ i) ≡ 1f) S
U : z - x # 0f
U = fst (·-inv-back _ _ T)
V : z - x + x # 0f + x
V = (+-#-compatible _ _ x) (fst (·-inv-back _ _ T)) -- (+-#-compatible _ _ x U)
-- workflow:
-- start with `transport (λ i → z - x + x # 0f + x) V` in the hole (i.e. a constant transport)
-- and then fiddle with the path and look what comes out
W : z + (- x + x) # x
W = transport (λ i → +-assoc z (- x) x (~ i) # snd (+-identity x) i) V
X : z + 0f # x
X = transport (λ i → z + snd (+-inv x) i # x) W
in (#-sym _ _ (transport (λ i → fst (+-identity z) i # x) X))
·-#-extensional : ∀(w x y z : Carrier) → w · x # y · z → (w # y) ⊎ (x # z)
·-#-extensional w x y z w·x#y·z with #-cotrans _ _ w·x#y·z (w · z)
... | inl w·x#w·z = inr (·-#-extensional-case1 w x y z w·x#y·z w·x#w·z) -- first case
... | inr w·z#y·z = let z·w≡z·y = (transport (λ i → ·-comm w z i # ·-comm y z i) w·z#y·z)
in inl (·-#-extensional-case1 _ _ _ _ z·w≡z·y z·w≡z·y) -- second case reduced to first case
-- for an example to use equational reasoning in this topic, see https://github.com/felixwellen/cubical/blob/field/Cubical/Structures/Field.agda
-- we do not do equational reasoning here but "implicational" reasoning instead
-- the special syntax should make it more readable and omit giving names to every intermediate step
-- but giving names to intermediates in a `let` or `where` clause might just be the way it's done
-- c.f. with more elaborate proofs e.g. in https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#combining-structures
-- also see the elaborate proof in https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#381519
-- which uses equational reasoning, but still names the single steps i, ii, iii, iv, v, vi, ... and resolves them in a `where` clause
-- also see https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#391417
-- "We consider rings without unit, called rngs, and with unit, called rings."
-- this work of Martín Escardó was prepared for the
-- Midlands Graduate School in the Foundations of Computing Science (University of Birmingham, UK, 14 - 18 April, 2019)
-- http://events.cs.bham.ac.uk/mgs2019/
-- Introductory Courses:
-- - Lambda Calculus (course notes) by Venanzio Capretta (University of Nottingham)
-- - Category Theory (course notes) by Thorsten Altenkirch (University of Nottingham)
-- - Univalent Type Theory in Agda (course notes) by Martín Escardó (University of Birmingham)
·-#-extensional-case1' : ∀(w x y z : Carrier) → w · x # y · z → w · x # w · z → x # z
·-#-extensional-case1' w x y z w·x#y·z w·x#w·z =
let
instance -- this allows to use ⁻¹ᶠ without an instance argument
w·[z-x]#0f =
( w · x # w · z ⇒⟨ +-#-compatible _ _ (- (w · x)) ⟩
w · x - w · x # w · z - w · x ⇒⟨ transport (λ i → (fst (+-inv (w · x)) i) # a·b-a·c≡a·[b-c] w z x i) ⟩
0f # w · (z - x) ⇒⟨ #-sym _ _ ⟩
w · (z - x) # 0f ◼) w·x#w·z
in ( w · (z - x) # 0f ⇒⟨ (λ _ → ·-rinv (w · (z - x)) it ) ⟩ -- NOTE: "plugging in" the instance did not work, ∴ `it`
w · (z - x) · (w · (z - x)) ⁻¹ᶠ ≡ 1f ⇒⟨ transport (λ i → ·-comm w (z - x) i · (w · (z - x)) ⁻¹ᶠ ≡ 1f) ⟩
(z - x) · w · (w · (z - x)) ⁻¹ᶠ ≡ 1f ⇒⟨ transport (λ i → ·-assoc (z - x) w ((w · (z - x)) ⁻¹ᶠ) (~ i) ≡ 1f) ⟩
(z - x) · (w · (w · (z - x)) ⁻¹ᶠ) ≡ 1f ⇒⟨ fst ∘ (·-inv-back _ _) ⟩
z - x # 0f ⇒⟨ +-#-compatible _ _ x ⟩
(z - x) + x # 0f + x ⇒⟨ transport (λ i → +-assoc z (- x) x (~ i) # snd (+-identity x) i) ⟩
z + (- x + x) # x ⇒⟨ transport (λ i → z + snd (+-inv x) i # x) ⟩
z + 0f # x ⇒⟨ transport (λ i → fst (+-identity z) i # x) ⟩
z # x ⇒⟨ #-sym _ _ ⟩
x # z ◼) it -- conceptually we would plug `w·[z-x]#0f` in, but this breaks the very first step
--
-- Lemma 4.1.7.
-- Given a strict partial order < on a set X:
-- 1. we have an apartness relation defined by
-- x # y := (x < y) ∨ (y < x), and
-- 2. we have a preorder defined by
-- x ≤ y := ¬(y < x).
--
-- Definition 4.1.8.
-- Let (A, ≤) be a partial order, and let min, max : A → A → A be binary operators on A. We say that (A, ≤, min, max) is a lattice if min computes greatest lower bounds in the sense that for every x, y, z : A, we have
-- z ≤ min(x,y) ⇔ z ≤ x ∧ z ≤ y,
-- and max computes least upper bounds in the sense that for every x, y, z : A, we have
-- max(x,y) ≤ z ⇔ x ≤ z ∧ y ≤ z.
--
-- Remark 4.1.9.
-- 1. From the fact that (A, ≤, min, max) is a lattice, it does not follow that for every x and y, min(x,y) = x ∨ min(x,y) = y. However, we can characterize min as
-- z < min(x,y) ⇔ z < x ∨ z < y
-- and similarly for max, see Lemma 6.7.1.
-- 2. In a partial order, for two fixed elements a and b, all joins and meets of a, b are equal, so that Lemma 2.6.20 the type of joins and the type of meets are propositions. Hence, providing the maps min and max as in the above definition is equivalent to the showing the existenceof all binary joins and meets.
--
-- The following definition is modified from on The Univalent Foundations Program [89, Definition 11.2.7].
--
-- Definition 4.1.10.
-- An ordered field is a set F together with constants 0, 1, operations +, ·, min, max, and a binary relation < such that:
-- 1. (F, 0, 1, +, ·) is a commutative ring with unit;
-- 2. < is a strict order;
-- 3. x : F has a multiplicative inverse iff x # 0, recalling that # is defined as in Lemma 4.1.7;
-- 4. ≤, as in Lemma 4.1.7, is antisymmetric, so that (F, ≤) is a partial order;
-- 5. (F, ≤, min, max) is a lattice.
-- 6. for all x, y, z, w : F:
-- x + y < z + w ⇒ x < z ∨ y < w, (†)
-- 0 < z ∧ x < y ⇒ x z < y z. (∗)
-- Our notion of ordered fields coincides with The Univalent Foundations Program [89, Definition 11.2.7].
--
-- Lemma 4.1.11.
-- In the presence of the first five axioms of Definition 4.1.10, conditions (†) and (∗) are together equivalent to the condition that for all x, y, z : F,
-- 1. x ≤ y ⇔ ¬(y < x),
-- 2. x # y ⇔ (x < y) ∨ (y < x)
-- 3. x ≤ y ⇔ x + z ≤ y + z,
-- 4. x < y ⇔ x + z < y + z,
-- 5. 0 < x + y ⇒ 0 < x ∨ 0 < y,
-- 6. x < y ≤ z ⇒ x < z,
-- 7. x ≤ y < z ⇒ x < z,
-- 8. x ≤ y ∧ 0 ≤ z ⇒ x z ≤ y z,
-- 9. 0 < z ⇒ (x < y ⇔ x z < y z),
-- 10. 0 < 1.
-- we have in cubical
-- import Cubical.HITs.Rationals.HITQ
-- ℚ as a higher inductive type
-- import Cubical.HITs.Rationals.QuoQ
-- ℚ as a set quotient of ℤ × ℕ₊₁ (as in the HoTT book)
-- import Cubical.HITs.Rationals.SigmaQ
-- ℚ as the set of coprime pairs in ℤ × ℕ₊₁
| 49.247847
| 375
| 0.574227
|
5967b522b3ad928c4f85fff6c2e34dda3bf46fc7
| 918
|
agda
|
Agda
|
test/Compiler/simple/Issue2879-2.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Compiler/simple/Issue2879-2.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/Issue2879-2.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --sized-types #-}
open import Agda.Builtin.IO
open import Agda.Builtin.Nat
open import Agda.Builtin.Size
open import Agda.Builtin.Unit
mutual
data Delay (A : Set) (i : Size) : Set where
now : A → Delay A i
later : Delay′ A i → Delay A i
record Delay′ (A : Set) (i : Size) : Set where
coinductive
field
force : {j : Size< i} → Delay A j
open Delay′ public
delay : ∀ {A i} → Nat → A → Delay A i
delay zero x = now x
delay (suc n) x = later λ { .force → delay n x }
data Maybe (A : Set) : Set where
nothing : Maybe A
just : A → Maybe A
{-# COMPILE GHC Maybe = data Maybe (Nothing | Just) #-}
run : ∀ {A} → Nat → Delay A ∞ → Maybe A
run zero _ = nothing
run (suc n) (now x) = just x
run (suc n) (later x) = run n (force x)
postulate
wrapper : Maybe Nat → IO ⊤
{-# COMPILE GHC wrapper = print #-}
main : IO ⊤
main = wrapper (run 10 (delay 5 12))
| 21.348837
| 55
| 0.592593
|
3d219df6fed750f6e14b5e7bd801921bc713d36e
| 123
|
agda
|
Agda
|
src/Lemmachine/Default.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
src/Lemmachine/Default.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
src/Lemmachine/Default.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
module Lemmachine.Default where
open import Lemmachine
resource : Hooks
resource = []
main = runResolve (toApp resource)
| 15.375
| 34
| 0.780488
|
dfb48363f18780b1dc698f7a2ece994f17e96416
| 438
|
agda
|
Agda
|
agda/Analysis.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 28
|
2017-04-21T09:08:52.000Z
|
2022-03-04T18:04:07.000Z
|
agda/Analysis.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 1
|
2020-11-13T01:26:20.000Z
|
2020-11-17T00:58:55.000Z
|
agda/Analysis.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 3
|
2019-01-12T17:02:36.000Z
|
2020-11-10T04:04:40.000Z
|
{-# OPTIONS --cubical --safe #-}
module Analysis where
open import Data.List using (List; []; _∷_; map)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Harmony
open import Music
open import Note
open import Pitch
-- test of analysis
accompF : List Pitch
accompF = f 4 ∷ a 4 ∷ c 5 ∷ []
xx = pitchClassListToSet (map pitchToClass accompF)
--yy = showPitchClassSet xx
zz : xx ≡ IV-maj
zz = refl
| 18.25
| 67
| 0.703196
|
410f71e8fbdd02929432d59d4002b1d9e0d62840
| 4,070
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Cubical/Glue.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2021-06-14T11:08:59.000Z
|
2021-06-14T11:08:59.000Z
|
src/data/lib/prim/Agda/Builtin/Cubical/Glue.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2020-05-29T19:45:38.000Z
|
2020-05-29T19:45:38.000Z
|
src/data/lib/prim/Agda/Builtin/Cubical/Glue.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2021-04-18T13:34:07.000Z
|
2021-04-18T13:34:07.000Z
|
{-# OPTIONS --cubical --safe --no-sized-types --no-guardedness
--no-subtyping #-}
module Agda.Builtin.Cubical.Glue where
open import Agda.Primitive
open import Agda.Builtin.Sigma
open import Agda.Primitive.Cubical renaming (primINeg to ~_; primIMax to _∨_; primIMin to _∧_;
primHComp to hcomp; primTransp to transp; primComp to comp;
itIsOne to 1=1)
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Cubical.Sub renaming (Sub to _[_↦_]; primSubOut to ouc)
import Agda.Builtin.Cubical.HCompU as HCompU
module Helpers = HCompU.Helpers
open Helpers
-- We make this a record so that isEquiv can be proved using
-- copatterns. This is good because copatterns don't get unfolded
-- unless a projection is applied so it should be more efficient.
record isEquiv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) : Set (ℓ ⊔ ℓ') where
no-eta-equality
field
equiv-proof : (y : B) → isContr (fiber f y)
open isEquiv public
infix 4 _≃_
_≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ ⊔ ℓ')
A ≃ B = Σ (A → B) \ f → (isEquiv f)
equivFun : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → A ≃ B → A → B
equivFun e = fst e
-- Improved version of equivProof compared to Lemma 5 in CCHM. We put
-- the (φ = i0) face in contr' making it be definitionally c in this
-- case. This makes the computational behavior better, in particular
-- for transp in Glue.
equivProof : ∀ {la lt} (T : Set la) (A : Set lt) → (w : T ≃ A) → (a : A)
→ ∀ ψ → (Partial ψ (fiber (w .fst) a)) → fiber (w .fst) a
equivProof A B w a ψ fb = contr' {A = fiber (w .fst) a} (w .snd .equiv-proof a) ψ fb
where
contr' : ∀ {ℓ} {A : Set ℓ} → isContr A → (φ : I) → (u : Partial φ A) → A
contr' {A = A} (c , p) φ u = hcomp (λ i → λ { (φ = i1) → p (u 1=1) i
; (φ = i0) → c }) c
{-# BUILTIN EQUIV _≃_ #-}
{-# BUILTIN EQUIVFUN equivFun #-}
{-# BUILTIN EQUIVPROOF equivProof #-}
primitive
primGlue : ∀ {ℓ ℓ'} (A : Set ℓ) {φ : I}
→ (T : Partial φ (Set ℓ')) → (e : PartialP φ (λ o → T o ≃ A))
→ Set ℓ'
prim^glue : ∀ {ℓ ℓ'} {A : Set ℓ} {φ : I}
→ {T : Partial φ (Set ℓ')} → {e : PartialP φ (λ o → T o ≃ A)}
→ (t : PartialP φ T) → (a : A) → primGlue A T e
prim^unglue : ∀ {ℓ ℓ'} {A : Set ℓ} {φ : I}
→ {T : Partial φ (Set ℓ')} → {e : PartialP φ (λ o → T o ≃ A)}
→ primGlue A T e → A
module _ {ℓ : I → Level} (P : (i : I) → Set (ℓ i)) where
private
E : (i : I) → Set (ℓ i)
E = λ i → P i
~E : (i : I) → Set (ℓ (~ i))
~E = λ i → P (~ i)
A = P i0
B = P i1
f : A → B
f x = transp E i0 x
g : B → A
g y = transp ~E i0 y
u : ∀ i → A → E i
u i x = transp (λ j → E (i ∧ j)) (~ i) x
v : ∀ i → B → E i
v i y = transp (λ j → ~E ( ~ i ∧ j)) i y
fiberPath : (y : B) → (xβ0 xβ1 : fiber f y) → xβ0 ≡ xβ1
fiberPath y (x0 , β0) (x1 , β1) k = ω , λ j → δ (~ j) where
module _ (j : I) where
private
sys : A → ∀ i → PartialP (~ j ∨ j) (λ _ → E (~ i))
sys x i (j = i0) = v (~ i) y
sys x i (j = i1) = u (~ i) x
ω0 = comp ~E (sys x0) ((β0 (~ j)))
ω1 = comp ~E (sys x1) ((β1 (~ j)))
θ0 = fill ~E (sys x0) (inc (β0 (~ j)))
θ1 = fill ~E (sys x1) (inc (β1 (~ j)))
sys = λ {j (k = i0) → ω0 j ; j (k = i1) → ω1 j}
ω = hcomp sys (g y)
θ = hfill sys (inc (g y))
δ = λ (j : I) → comp E
(λ i → λ { (j = i0) → v i y ; (k = i0) → θ0 j (~ i)
; (j = i1) → u i ω ; (k = i1) → θ1 j (~ i) })
(θ j)
γ : (y : B) → y ≡ f (g y)
γ y j = comp E (λ i → λ { (j = i0) → v i y
; (j = i1) → u i (g y) }) (g y)
pathToisEquiv : isEquiv f
pathToisEquiv .equiv-proof y .fst .fst = g y
pathToisEquiv .equiv-proof y .fst .snd = sym (γ y)
pathToisEquiv .equiv-proof y .snd = fiberPath y _
pathToEquiv : A ≃ B
pathToEquiv .fst = f
pathToEquiv .snd = pathToisEquiv
| 33.360656
| 104
| 0.488698
|
581dcf84137f72aee68d3ad009c20eedaaeed3d9
| 9,254
|
agda
|
Agda
|
agda-stdlib/src/Data/List/NonEmpty.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/List/NonEmpty.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/NonEmpty.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Non-empty lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.NonEmpty where
open import Level using (Level)
open import Category.Monad
open import Data.Bool.Base using (Bool; false; true; not; T)
open import Data.Bool.Properties
open import Data.List.Base as List using (List; []; _∷_)
open import Data.Maybe.Base using (Maybe ; nothing; just)
open import Data.Nat.Base as ℕ
open import Data.Product as Prod using (∃; _×_; proj₁; proj₂; _,_; -,_)
open import Data.These.Base as These using (These; this; that; these)
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂)
open import Data.Unit
open import Data.Vec.Base as Vec using (Vec; []; _∷_)
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence
using () renaming (module Equivalence to Eq)
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_; refl)
open import Relation.Nullary.Decidable using (isYes)
private
variable
a b c : Level
A : Set a
B : Set b
C : Set c
------------------------------------------------------------------------
-- Non-empty lists
infixr 5 _∷_
record List⁺ (A : Set a) : Set a where
constructor _∷_
field
head : A
tail : List A
open List⁺ public
-- Basic combinators
uncons : List⁺ A → A × List A
uncons (hd ∷ tl) = hd , tl
[_] : A → List⁺ A
[ x ] = x ∷ []
infixr 5 _∷⁺_
_∷⁺_ : A → List⁺ A → List⁺ A
x ∷⁺ y ∷ xs = x ∷ y ∷ xs
length : List⁺ A → ℕ
length (x ∷ xs) = suc (List.length xs)
------------------------------------------------------------------------
-- Conversion
toList : List⁺ A → List A
toList (x ∷ xs) = x ∷ xs
fromList : List A → Maybe (List⁺ A)
fromList [] = nothing
fromList (x ∷ xs) = just (x ∷ xs)
fromVec : ∀ {n} → Vec A (suc n) → List⁺ A
fromVec (x ∷ xs) = x ∷ Vec.toList xs
toVec : (xs : List⁺ A) → Vec A (length xs)
toVec (x ∷ xs) = x ∷ Vec.fromList xs
lift : (∀ {m} → Vec A (suc m) → ∃ λ n → Vec B (suc n)) →
List⁺ A → List⁺ B
lift f xs = fromVec (proj₂ (f (toVec xs)))
------------------------------------------------------------------------
-- Other operations
map : (A → B) → List⁺ A → List⁺ B
map f (x ∷ xs) = (f x ∷ List.map f xs)
replicate : ∀ n → n ≢ 0 → A → List⁺ A
replicate n n≢0 a = a ∷ List.replicate (pred n) a
-- Right fold. Note that s is only applied to the last element (see
-- the examples below).
foldr : (A → B → B) → (A → B) → List⁺ A → B
foldr {A = A} {B = B} c s (x ∷ xs) = foldr′ x xs
where
foldr′ : A → List A → B
foldr′ x [] = s x
foldr′ x (y ∷ xs) = c x (foldr′ y xs)
-- Right fold.
foldr₁ : (A → A → A) → List⁺ A → A
foldr₁ f = foldr f id
-- Left fold. Note that s is only applied to the first element (see
-- the examples below).
foldl : (B → A → B) → (A → B) → List⁺ A → B
foldl c s (x ∷ xs) = List.foldl c (s x) xs
-- Left fold.
foldl₁ : (A → A → A) → List⁺ A → A
foldl₁ f = foldl f id
-- Append (several variants).
infixr 5 _⁺++⁺_ _++⁺_ _⁺++_
_⁺++⁺_ : List⁺ A → List⁺ A → List⁺ A
(x ∷ xs) ⁺++⁺ (y ∷ ys) = x ∷ (xs List.++ y ∷ ys)
_⁺++_ : List⁺ A → List A → List⁺ A
(x ∷ xs) ⁺++ ys = x ∷ (xs List.++ ys)
_++⁺_ : List A → List⁺ A → List⁺ A
xs ++⁺ ys = List.foldr _∷⁺_ ys xs
concat : List⁺ (List⁺ A) → List⁺ A
concat (xs ∷ xss) = xs ⁺++ List.concat (List.map toList xss)
concatMap : (A → List⁺ B) → List⁺ A → List⁺ B
concatMap f = concat ∘′ map f
-- Reverse
reverse : List⁺ A → List⁺ A
reverse = lift (-,_ ∘′ Vec.reverse)
-- Align and Zip
alignWith : (These A B → C) → List⁺ A → List⁺ B → List⁺ C
alignWith f (a ∷ as) (b ∷ bs) = f (these a b) ∷ List.alignWith f as bs
zipWith : (A → B → C) → List⁺ A → List⁺ B → List⁺ C
zipWith f (a ∷ as) (b ∷ bs) = f a b ∷ List.zipWith f as bs
unalignWith : (A → These B C) → List⁺ A → These (List⁺ B) (List⁺ C)
unalignWith f = foldr (These.alignWith mcons mcons ∘′ f)
(These.map [_] [_] ∘′ f)
where mcons : ∀ {e} {E : Set e} → These E (List⁺ E) → List⁺ E
mcons = These.fold [_] id _∷⁺_
unzipWith : (A → B × C) → List⁺ A → List⁺ B × List⁺ C
unzipWith f (a ∷ as) = Prod.zip _∷_ _∷_ (f a) (List.unzipWith f as)
align : List⁺ A → List⁺ B → List⁺ (These A B)
align = alignWith id
zip : List⁺ A → List⁺ B → List⁺ (A × B)
zip = zipWith _,_
unalign : List⁺ (These A B) → These (List⁺ A) (List⁺ B)
unalign = unalignWith id
unzip : List⁺ (A × B) → List⁺ A × List⁺ B
unzip = unzipWith id
-- Snoc.
infixl 5 _∷ʳ_ _⁺∷ʳ_
_∷ʳ_ : List A → A → List⁺ A
[] ∷ʳ y = [ y ]
(x ∷ xs) ∷ʳ y = x ∷ (xs List.∷ʳ y)
_⁺∷ʳ_ : List⁺ A → A → List⁺ A
xs ⁺∷ʳ x = toList xs ∷ʳ x
-- A snoc-view of non-empty lists.
infixl 5 _∷ʳ′_
data SnocView {A : Set a} : List⁺ A → Set a where
_∷ʳ′_ : (xs : List A) (x : A) → SnocView (xs ∷ʳ x)
snocView : (xs : List⁺ A) → SnocView xs
snocView (x ∷ xs) with List.initLast xs
snocView (x ∷ .[]) | [] = [] ∷ʳ′ x
snocView (x ∷ .(xs List.∷ʳ y)) | xs List.∷ʳ' y = (x ∷ xs) ∷ʳ′ y
-- The last element in the list.
last : List⁺ A → A
last xs with snocView xs
last .(ys ∷ʳ y) | ys ∷ʳ′ y = y
-- Groups all contiguous elements for which the predicate returns the
-- same result into lists.
split : (p : A → Bool) → List A →
List (List⁺ (∃ (T ∘ p)) ⊎ List⁺ (∃ (T ∘ not ∘ p)))
split p [] = []
split p (x ∷ xs) with p x | P.inspect p x | split p xs
... | true | P.[ px≡t ] | inj₁ xs′ ∷ xss = inj₁ ((x , Eq.from T-≡ ⟨$⟩ px≡t) ∷⁺ xs′) ∷ xss
... | true | P.[ px≡t ] | xss = inj₁ [ x , Eq.from T-≡ ⟨$⟩ px≡t ] ∷ xss
... | false | P.[ px≡f ] | inj₂ xs′ ∷ xss = inj₂ ((x , Eq.from T-not-≡ ⟨$⟩ px≡f) ∷⁺ xs′) ∷ xss
... | false | P.[ px≡f ] | xss = inj₂ [ x , Eq.from T-not-≡ ⟨$⟩ px≡f ] ∷ xss
-- If we flatten the list returned by split, then we get the list we
-- started with.
flatten : ∀ {p q} {P : A → Set p} {Q : A → Set q} →
List (List⁺ (∃ P) ⊎ List⁺ (∃ Q)) → List A
flatten = List.concat ∘
List.map Sum.[ toList ∘ map proj₁ , toList ∘ map proj₁ ]
flatten-split : (p : A → Bool) (xs : List A) → flatten (split p xs) ≡ xs
flatten-split p [] = refl
flatten-split p (x ∷ xs)
with p x | P.inspect p x | split p xs | flatten-split p xs
... | true | P.[ _ ] | [] | hyp = P.cong (_∷_ x) hyp
... | true | P.[ _ ] | inj₁ _ ∷ _ | hyp = P.cong (_∷_ x) hyp
... | true | P.[ _ ] | inj₂ _ ∷ _ | hyp = P.cong (_∷_ x) hyp
... | false | P.[ _ ] | [] | hyp = P.cong (_∷_ x) hyp
... | false | P.[ _ ] | inj₁ _ ∷ _ | hyp = P.cong (_∷_ x) hyp
... | false | P.[ _ ] | inj₂ _ ∷ _ | hyp = P.cong (_∷_ x) hyp
-- Groups all contiguous elements /not/ satisfying the predicate into
-- lists. Elements satisfying the predicate are dropped.
wordsBy : (A → Bool) → List A → List (List⁺ A)
wordsBy p =
List.mapMaybe Sum.[ const nothing , just ∘′ map proj₁ ] ∘ split p
------------------------------------------------------------------------
-- Examples
-- Note that these examples are simple unit tests, because the type
-- checker verifies them.
private
module Examples {A B : Set}
(_⊕_ : A → B → B)
(_⊗_ : B → A → B)
(_⊙_ : A → A → A)
(f : A → B)
(a b c : A)
where
hd : head (a ∷⁺ b ∷⁺ [ c ]) ≡ a
hd = refl
tl : tail (a ∷⁺ b ∷⁺ [ c ]) ≡ b ∷ c ∷ []
tl = refl
mp : map f (a ∷⁺ b ∷⁺ [ c ]) ≡ f a ∷⁺ f b ∷⁺ [ f c ]
mp = refl
right : foldr _⊕_ f (a ∷⁺ b ∷⁺ [ c ]) ≡ (a ⊕ (b ⊕ f c))
right = refl
right₁ : foldr₁ _⊙_ (a ∷⁺ b ∷⁺ [ c ]) ≡ (a ⊙ (b ⊙ c))
right₁ = refl
left : foldl _⊗_ f (a ∷⁺ b ∷⁺ [ c ]) ≡ ((f a ⊗ b) ⊗ c)
left = refl
left₁ : foldl₁ _⊙_ (a ∷⁺ b ∷⁺ [ c ]) ≡ ((a ⊙ b) ⊙ c)
left₁ = refl
⁺app⁺ : (a ∷⁺ b ∷⁺ [ c ]) ⁺++⁺ (b ∷⁺ [ c ]) ≡
a ∷⁺ b ∷⁺ c ∷⁺ b ∷⁺ [ c ]
⁺app⁺ = refl
⁺app : (a ∷⁺ b ∷⁺ [ c ]) ⁺++ (b ∷ c ∷ []) ≡
a ∷⁺ b ∷⁺ c ∷⁺ b ∷⁺ [ c ]
⁺app = refl
app⁺ : (a ∷ b ∷ c ∷ []) ++⁺ (b ∷⁺ [ c ]) ≡
a ∷⁺ b ∷⁺ c ∷⁺ b ∷⁺ [ c ]
app⁺ = refl
conc : concat ((a ∷⁺ b ∷⁺ [ c ]) ∷⁺ [ b ∷⁺ [ c ] ]) ≡
a ∷⁺ b ∷⁺ c ∷⁺ b ∷⁺ [ c ]
conc = refl
rev : reverse (a ∷⁺ b ∷⁺ [ c ]) ≡ c ∷⁺ b ∷⁺ [ a ]
rev = refl
snoc : (a ∷ b ∷ c ∷ []) ∷ʳ a ≡ a ∷⁺ b ∷⁺ c ∷⁺ [ a ]
snoc = refl
snoc⁺ : (a ∷⁺ b ∷⁺ [ c ]) ⁺∷ʳ a ≡ a ∷⁺ b ∷⁺ c ∷⁺ [ a ]
snoc⁺ = refl
split-true : split (const true) (a ∷ b ∷ c ∷ []) ≡
inj₁ ((a , tt) ∷⁺ (b , tt) ∷⁺ [ c , tt ]) ∷ []
split-true = refl
split-false : split (const false) (a ∷ b ∷ c ∷ []) ≡
inj₂ ((a , tt) ∷⁺ (b , tt) ∷⁺ [ c , tt ]) ∷ []
split-false = refl
split-≡1 :
split (ℕ._≡ᵇ 1) (1 ∷ 2 ∷ 3 ∷ 1 ∷ 1 ∷ 2 ∷ 1 ∷ []) ≡
inj₁ [ 1 , tt ] ∷ inj₂ ((2 , tt) ∷⁺ [ 3 , tt ]) ∷
inj₁ ((1 , tt) ∷⁺ [ 1 , tt ]) ∷ inj₂ [ 2 , tt ] ∷ inj₁ [ 1 , tt ] ∷
[]
split-≡1 = refl
wordsBy-true : wordsBy (const true) (a ∷ b ∷ c ∷ []) ≡ []
wordsBy-true = refl
wordsBy-false : wordsBy (const false) (a ∷ b ∷ c ∷ []) ≡
(a ∷⁺ b ∷⁺ [ c ]) ∷ []
wordsBy-false = refl
wordsBy-≡1 :
wordsBy (ℕ._≡ᵇ 1) (1 ∷ 2 ∷ 3 ∷ 1 ∷ 1 ∷ 2 ∷ 1 ∷ []) ≡
(2 ∷⁺ [ 3 ]) ∷ [ 2 ] ∷ []
wordsBy-≡1 = refl
| 28.12766
| 94
| 0.479684
|
3d4f37abb4010a392a951db94d99f6d572433c24
| 1,403
|
agda
|
Agda
|
src/CF/Transform/Compile/ToJVM.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | 6
|
2020-10-07T14:07:17.000Z
|
2021-02-28T21:49:08.000Z
|
src/CF/Transform/Compile/ToJVM.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | null | null | null |
src/CF/Transform/Compile/ToJVM.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | 1
|
2021-12-28T17:37:15.000Z
|
2021-12-28T17:37:15.000Z
|
{-# OPTIONS --safe #-}
{- A typeclass for converting between type disciplines #-}
module CF.Transform.Compile.ToJVM where
open import Level
open import Function
open import Data.Product as P
open import Data.List as L
open import Data.List.Properties as LP
open import Data.List.Membership.Propositional
open import Data.List.Membership.Propositional.Properties
open import Relation.Binary.PropositionalEquality
open import Relation.Ternary.Morphisms
open import CF.Types as CF
open import CF.Contexts.Lexical
open import JVM.Types as JVM
record To {l r} (L : Set l) (R : Set r) : Set (l ⊔ r) where
field
⟦_⟧ : L → R
open To {{...}} public
instance ⟦⟧-list : ∀ {a} {A B : Set a} {{_ : To A B}} → To (List A) (List B)
To.⟦_⟧ ⟦⟧-list = L.map ⟦_⟧
instance ⟦⟧-prod : ∀ {a} {A B C D : Set a} {{_ : To A B}} {{_ : To C D}} → To (A × C) (B × D)
To.⟦_⟧ ⟦⟧-prod = P.map ⟦_⟧ ⟦_⟧
instance cfToJvm-ty : To CF.Ty JVM.Ty
To.⟦_⟧ cfToJvm-ty = ‵_
where
‵_ : CF.Ty → JVM.Ty
‵ void = boolean
‵ int = int
‵ bool = boolean
instance cfToJvm-var : ∀ {ℓ} {A B : Set ℓ} {{_ : To A B}} {a : A} {as} →
To (a ∈ as) (⟦ a ⟧ ∈ ⟦ as ⟧)
To.⟦_⟧ cfToJvm-var = ∈-map⁺ ⟦_⟧
private
module _ {t} {T : Set t} where
open import JVM.Model T public
instance on-intf : ∀ {ℓ} {A B : Set ℓ} {{_ : To A B}} → To (Intf {T = A}) (Intf {T = B})
To.⟦ on-intf ⟧ (u ⇅ d) = ⟦ u ⟧ ⇅ ⟦ d ⟧
| 28.06
| 93
| 0.595153
|
1c0ad3acf58efa84553cf3a2ad9ced9369f50afc
| 6,268
|
agda
|
Agda
|
LP/Example.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
LP/Example.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
LP/Example.agda
|
hbasold/Sandbox
|
8fc7a6cd878f37f9595124ee8dea62258da28aa4
|
[
"MIT"
] | null | null | null |
module Example where
import Level
open import Signature
open import Function
open import Data.Empty
open import Data.Unit
open import Data.Nat
open import Data.Fin
open import Data.Product as Prod renaming (Σ to ⨿)
open import Data.Sum as Sum
open import Relation.Nullary
open import Relation.Unary hiding (_⇒_)
open import Relation.Binary.PropositionalEquality hiding ([_])
open ≡-Reasoning
postulate
ext : Extensionality Level.zero Level.zero
------
-- Examples
-----
module NatProg where
Σ : Sig
∥ Σ ∥ = Fin 3
ar Σ zero = Fin 0 -- 0
ar Σ (suc zero) = Fin 1 -- succ
ar Σ (suc (suc _)) = Fin 1 -- nat
open import Terms Σ
V = ℕ
Z S N : ∥ Σ ∥
Z = # 0
S = # 1
N = # 2
z : T V
z = μ (ι (Z , (λ ())))
s nat : T V → T V
s t = μ (ι (S , (λ _ → t)))
nat t = μ (ι (N , (λ _ → t)))
z∞ : T∞ V
z∞ = χ z
s∞ nat∞ : ∀{X} → T∞ X → T∞ X
s∞ t = μ∞ (ι∞ (S , (λ _ → t)))
nat∞ t = μ∞ (ι∞ (N , (λ _ → t)))
inf : T∞ ⊥
inf = corec (λ x → inj₁ (S , (λ _ → tt))) tt
inf-nat : T∞ ⊥
inf-nat = nat∞ inf
open import Program Σ V
-- | Program consisting of
-- ⇒ nat(0)
-- nat(n) ⇒ nat(s n)
P : Program
P = ((0 , (λ ())) , ( , clauses))
where
clauses : Fin 2 → Clause
clauses zero = (0 , (λ ())) ⊢ nat z
clauses (suc _) = (1 , b) ⊢ nat (s n)
where
n = η 0
b : Fin 1 → T V
b _ = nat n
open import Herbrand Σ V P
lem : ¬ (∃ λ σ → (inf ~ app∞ σ (χ (geth-ν P (# 0)))))
lem (σ , p) with out~ p
lem (σ , p) | () , _
bad-ν : inf-nat ∈ Herbrand-ν
bw-closed bad-ν = inj₁ p
where
p : (i : dom-ν P) {σ : V → T∞ ⊥} →
inf-nat ~ (app∞ σ (χ (geth-ν P i))) →
(j : dom (getb-ν P i)) →
app∞ σ (χ (get (getb-ν P i) j)) ∈ Herbrand-ν
{-
p i {σ} p j with out inf-nat | out (σ 0) | out~ p
p i p j | inj₁ (zero , α) | v | r = {!!}
p i p j | inj₁ (suc zero , α) | v | r = {!!}
p i p j | inj₁ (suc (suc _) , α) | v | r = {!!}
p i p j | inj₂ () | v | r
-}
p i {σ} p j with out (σ 0) | out~ p
p zero p () | u | refl , r
p (suc i) p zero | inj₁ (zero , _) | refl , r = {!!}
p (suc i) p zero | inj₁ (suc zero , _) | refl , r = {!!}
p (suc i) p zero | inj₁ (suc (suc _) , proj₂) | refl , r = {!!}
p (suc i) p zero | inj₂ () | refl , r
p (suc _) p (suc ()) | u | refl , r
{-
f : ?
f i {σ} p j with out~ p
... | u = ?
-}
bad : inf-nat ∈ Herbrand-μ
bad = coind-μ bad-ν
{-
module BitList where
Σ : Sig
∥ Σ ∥ = Fin 6
ar Σ zero = Fin 0 -- 0
ar Σ (suc zero) = Fin 0 -- 1
ar Σ (suc (suc zero)) = Fin 1 -- bit(x)
ar Σ (suc (suc (suc zero))) = Fin 1 -- blist(x)
ar Σ (suc (suc (suc (suc zero)))) = Fin 0 -- nil
ar Σ (suc (suc (suc (suc (suc f))))) = Fin 2 -- cons(x,y)
open import Terms Σ
V = ℕ
Z O Bit BList Nil Cons : ∥ Σ ∥
Z = # 0
O = # 1
Bit = # 2
BList = # 3
Nil = # 4
Cons = # 5
z o nil : T V
z = μ (ι (Z , (λ ())))
o = μ (ι (O , (λ ())))
nil = μ (ι (Nil , (λ ())))
bit blist : T V → T V
bit t = μ (ι (Bit , (λ _ → t)))
blist t = μ (ι (BList , (λ _ → t)))
bin-branch : {X : Set} → X → X → Fin 2 → X
bin-branch x y zero = x
bin-branch x y (suc _) = y
cons-br-distr : ∀{X Y} (t s : X) (f : X → Y) →
f ∘ bin-branch t s ≡ bin-branch (f t) (f s)
cons-br-distr t s f = ext p
where
p : (i : Fin 2) → f (bin-branch t s i) ≡ bin-branch (f t) (f s) i
p zero = refl
p (suc _) = refl
cons : T V → T V → T V
cons t s = μ (ι (Cons , bin-branch t s))
bit0 bit1 : T V
bit0 = bit z
bit1 = bit o
open import Program Σ V
-- | Program consisting of
-- ⇒ bit(0)
-- ⇒ bit(1)
-- ⇒ blist(nil)
-- bit(x), blist(y) ⇒ blist(cons(x,y))
P : Program
P = , clauses
where
clauses : Fin 4 → Clause
clauses zero = (0 , (λ ())) ⊢ bit0
clauses (suc zero) = (0 , (λ ())) ⊢ bit1
clauses (suc (suc zero)) = (0 , (λ ())) ⊢ nil
clauses (suc (suc (suc c))) = (2 , b) ⊢ blist (cons (η 0) (η 1))
where
b : Fin 2 → T V
b zero = bit (η 0)
b (suc i) = blist (η 1)
open import Rewrite Σ V P
X S bitX : T V
X = η 0
S = blist (cons X (cons X nil))
bitX = bit X
bitX-val : Val bitX
bitX-val zero () x
bitX-val (suc zero) () x
bitX-val (suc (suc zero)) () x
bitX-val (suc (suc (suc _))) zero ()
bitX-val (suc (suc (suc _))) (suc _) ()
step1 : S ⟿ bitX
step1 = rew-step (# 3) (# 0) {σ} σ-match
where
σ : Subst V V
σ zero = X
σ (suc zero) = cons X nil
σ (suc (suc n)) = η (suc (suc n))
σ-match : matches (geth P (# 3)) S σ
σ-match =
begin
app σ (blist (cons X (η 1)))
≡⟨ refl ⟩
μ (T₁ σ (blist (cons X (η 1))))
≡⟨ refl ⟩
μ (T₁ σ (μ (ι (BList , (λ _ → (cons X (η 1)))))))
≡⟨ refl ⟩
μ (μ (ι (BList , (λ _ → T₁ σ (cons X (η 1))))))
≡⟨ refl ⟩
μ (μ (ι (BList , (λ _ → T₁ σ (μ (ι (Cons , bin-branch X (η 1))))))))
≡⟨ refl ⟩
μ (μ (ι (BList , (λ _ → μ (ι (Cons , T₁ σ ∘ (bin-branch X (η 1))))))))
≡⟨ cong (λ u → μ (μ (ι (BList , (λ _ → μ (ι (Cons , u)))))))
(cons-br-distr X (η 1) (T₁ σ)) ⟩
μ (μ (ι (BList , (λ _ →
μ (ι (Cons , (bin-branch (T₁ σ X) (T₁ σ (η 1)))))))))
≡⟨ refl ⟩
μ (μ (ι (BList , (λ _ →
μ (ι (Cons , (bin-branch (η (σ 0)) (η (σ 1)))))))))
≡⟨ cong (λ u → μ (μ (ι (BList , (λ _ → μ (ι (Cons , u)))))))
(sym (cons-br-distr (σ 0) (σ 1) η)) ⟩
μ (μ (ι (BList , (λ _ →
μ (ι (Cons , (η ∘ (bin-branch (σ 0) (σ 1)))))))))
≡⟨ refl ⟩
blist (cons (σ 0) (σ 1))
≡⟨ refl ⟩
blist (cons X (cons X nil))
≡⟨ refl ⟩
S
∎
term1 : S ↓ bitX
term1 = step bitX bitX (val bitX-val) step1
-- Problem: The substitution needs to match _all_ leaves!!!
-}
| 25.583673
| 80
| 0.424697
|
126624536733f1411c6ad87f0e6cdb262da08472
| 3,300
|
agda
|
Agda
|
notes/fomega/gadts/ScottVec.agda
|
Quantum-One-DLT/zerepoch
|
c8cf4619e6e496930c9092cf6d64493eff300177
|
[
"Apache-2.0"
] | null | null | null |
notes/fomega/gadts/ScottVec.agda
|
Quantum-One-DLT/zerepoch
|
c8cf4619e6e496930c9092cf6d64493eff300177
|
[
"Apache-2.0"
] | null | null | null |
notes/fomega/gadts/ScottVec.agda
|
Quantum-One-DLT/zerepoch
|
c8cf4619e6e496930c9092cf6d64493eff300177
|
[
"Apache-2.0"
] | 2
|
2021-11-13T21:25:19.000Z
|
2022-02-21T16:38:59.000Z
|
-- This document shows how to encode GADTs using `IFix`.
{-# OPTIONS --type-in-type #-}
module ScottVec where
-- The kind of church-encoded type-level natural numbers.
Nat = (Set -> Set) -> Set -> Set
zero : Nat
zero = λ f z -> z
suc : Nat -> Nat
suc = λ n f z -> f (n f z)
plus : Nat -> Nat -> Nat
plus = λ n m f z -> n f (m f z)
-- Our old friend.
{-# NO_POSITIVITY_CHECK #-}
record IFix {I : Set} (F : (I -> Set) -> I -> Set) (i : I) : Set where
constructor wrap
field unwrap : F (IFix F) i
open IFix
-- Scott-encoded vectors (a vector is a list with statically-known length).
-- As usually the pattern vector of a Scott-encoded data type encodes pattern-matching.
VecF : Set -> (Nat -> Set) -> Nat -> Set
VecF
= λ A Rec n
-> (R : Nat -> Set) -- The type of the result depends on the vector's length.
-> (∀ p -> A -> Rec p -> R (suc p)) -- The encoded `cons` constructor.
-> R zero -- The encoded `nil` constructor.
-> R n
Vec : Set -> Nat -> Set
Vec = λ (A : Set) -> IFix (VecF A)
nil : ∀ A -> Vec A zero
nil = λ A -> wrap λ R f z -> z
cons : ∀ A n -> A -> Vec A n -> Vec A (suc n)
cons = λ A n x xs -> wrap λ R f z -> f n x xs
open import Data.Empty
open import Data.Unit.Base
open import Data.Nat.Base using (ℕ; _+_)
-- Type-safe `head`.
head : ∀ A n -> Vec A (suc n) -> A
head A n xs =
unwrap
xs
(λ p -> p (λ _ -> A) ⊤) -- `p (λ _ -> A) ⊤` returns `A` when `p` is `suc p'` for some `p'`
-- and `⊤` when `p` is `zero`
(λ p x xs' -> x) -- In the `cons` case `suc p (λ _ -> A) ⊤` reduces to `A`,
-- hence we return the list element of type `A`.
tt -- In the `nil` case `zero (λ _ -> A) ⊤` reduces to `⊤`,
-- hence we return the only value of that type.
{- Note [Type-safe `tail`]
It's not obvious if type-safe `tail` can be implemented with this setup. This is because even
though `Vec` is Scott-encoded, the type-level natural are Church-encoded (obviously we could
have Scott-encoded type-level naturals in Agda just as well, but not in Zerepoch Core), which
makes `pred` hard, which makes `tail` non-trivial.
I did try using Scott-encoded naturals in Agda, that makes `tail` even more straightforward
than `head`:
tail : ∀ A n -> Vec A (suc n) -> Vec A n
tail A n xs =
unwrap
xs
(λ p -> ((B : ℕ -> Set) -> B (pred p) -> B n) -> Vec A n)
(λ p x xs' coe -> coe (Vec A) xs')
(λ coe -> coe (Vec A) (nil A))
(λ B x -> x)
-}
-- Here we pattern-match on `xs` and if it's non-empty, i.e. of type `Vec ℕ (suc p)` for some `p`,
-- then we also get access to a coercion function that allows us to coerce the second list from
-- `Vec ℕ n` to the same `Vec ℕ (suc p)` and call the type-safe `head` over it.
-- Note that we don't even need to encode the `n ~ suc p` and `n ~ zero` equality constraints in
-- the definition of `vecF` and can recover coercions along those constraints by adding the
-- `Vec ℕ n -> Vec ℕ p` argument to the motive.
sumHeadsOr0 : ∀ n -> Vec ℕ n -> Vec ℕ n -> ℕ
sumHeadsOr0 n xs ys =
unwrap
xs
(λ p -> (Vec ℕ n -> Vec ℕ p) -> ℕ)
(λ p i _ coe -> i + head ℕ p (coe ys))
(λ _ -> 0)
(λ x -> x)
| 34.736842
| 98
| 0.564848
|
583b88bc2a1e43f53c27d9b9015e23bd09233d3f
| 5,100
|
agda
|
Agda
|
lib/types/Cover.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/Cover.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/Cover.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.NConnected
open import lib.types.TLevel
open import lib.NType2
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.Pointed
open import lib.types.LoopSpace
open import lib.types.Truncation
open import lib.types.PathSet
module lib.types.Cover where
{-
The definition of covering spaces.
-}
record Cover {i} (A : Type i) j : Type (lmax i (lsucc j)) where
constructor cover
field
Fiber : A → Type j
Fiber-level : ∀ a → is-set (Fiber a)
Fiber-is-set = Fiber-level
TotalSpace = Σ A Fiber
-- Basic lemmas
module _ {i} {A : Type i} {j} where
open Cover
-- Equality between covers.
private
cover=′ : {c₁ c₂ : Cover A j} → Fiber c₁ == Fiber c₂ → c₁ == c₂
cover=′ {cover f _} {cover .f _} idp = ap (cover f) $
prop-has-all-paths (Π-is-prop λ _ → is-set-is-prop) _ _
cover= : {c₁ c₂ : Cover A j} → (∀ a → Fiber c₁ a ≃ Fiber c₂ a)
→ c₁ == c₂
cover= F≃ = cover=′ (λ= λ a → ua $ F≃ a)
-- The definition of universality in terms of connectedness.
is-universal : Cover A j → Type (lmax i j)
is-universal cov = is-connected ⟨1⟩ $ TotalSpace cov
-- In terms of connectedness
UniversalCover : Type (lmax i (lsucc j))
UniversalCover = Σ (Cover A j) is-universal
-- Theorem: A covering space keeps higher homotopy groups.
module _ {i} (A∙ : Ptd i)
{j} (c : Cover (fst A∙) j)
(a↑ : Cover.Fiber c (snd A∙)) where
open Cover c
private
F = Cover.Fiber c
F-level = Cover.Fiber-level c
A = fst A∙
a = snd A∙
private
-- The projection map with one end free (in order to apply J).
to′ : ∀ {p⇑ : _==_ {A = Σ A F} (a , a↑) (a , a↑)}
→ idp == p⇑ → idp == fst= p⇑
to′ idp=p⇑ = ap fst= idp=p⇑
-- The projection map from Ω²(Σ A F) to Ω²(A).
to : Ω^ 2 ⊙[ Σ A F , (a , a↑) ] → Ω^ 2 A∙
to p²⇑ = to′ {p⇑ = idp} p²⇑
-- Auxiliary synthesized path for injection.
idp=p↑ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}
→ (idp=p : idp == p)
→ idp == p↑
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ]
idp=p↑ idp = prop-has-all-paths (F-level a _ _) _ _
-- The injection map with some ends free (in order to apply J).
from′ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}
→ (idp=p : idp == p)
→ idp == p↑ -- aux
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ]
→ idp == pair= p p↑
from′ idp=p idp=p↑ = pair== idp=p idp=p↑
-- The injection map from Ω²(A) to Ω²(Σ A F).
from : Ω^ 2 A∙ → Ω^ 2 ⊙[ Σ A F , (a , a↑) ]
from p² = from′ {p = idp} {p↑ = idp} p² (idp=p↑ p²)
-- Injection is left-inverse to projection (with some ends free).
from′-to′ : ∀ {p⇑ : _==_ {A = Σ A F} (a , a↑) (a , a↑)}
→ (idp=p⇑ : idp == p⇑)
→ (idp=snd=p⇑ : idp == snd= p⇑ -- aux
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ to′ idp=p⇑ ])
→ from′ (to′ idp=p⇑) idp=snd=p⇑ == idp=p⇑
[ (λ p⇑ → idp == p⇑) ↓ ! (pair=-η p⇑) ]
from′-to′ idp idp=snd=p⇑ = ap (from′ idp)
$ contr-has-all-paths (F-level a _ _ _ _) _ _
-- Injection is left-inverse to projection.
from-to : ∀ p²⇑ → from (to p²⇑) == p²⇑
from-to p²⇑ = from′-to′ {p⇑ = idp} p²⇑ (idp=p↑ (to′ p²⇑))
-- Injection is right-inverse to projection (with some ends free).
to′-from′ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}
→ (idp=p : idp == p)
→ (idp=p↑ : idp == p↑ -- aux
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ])
→ to′ (from′ idp=p idp=p↑) == idp=p
[ (λ p → idp == p) ↓ fst=-β p p↑ ]
to′-from′ idp idp = idp
-- Injection is right-inverse to projection.
to-from : ∀ p² → to (from p²) == p²
to-from p² = to′-from′ p² (idp=p↑ p²)
-- The theorem.
Ω²ΣAFiber≃Ω²A : Ω^ 2 (Σ A F , (a , a↑)) ≃ Ω^ 2 A∙
Ω²ΣAFiber≃Ω²A = to , is-eq to from to-from from-to
-- A natural way to construct a G-set from covering spaces.
module _ {i} {A : Type i} where
open Cover
cover-trace : ∀ {j} (cov : Cover A j) {a₁ a₂}
→ Fiber cov a₁ → a₁ =₀ a₂
→ Fiber cov a₂
cover-trace cov a↑ p =
transport₀ (Fiber cov) (Fiber-is-set cov _) p a↑
abstract
cover-trace-idp₀ : ∀ {j} (cov : Cover A j) {a₁}
→ (a↑ : Fiber cov a₁)
→ cover-trace cov a↑ idp₀ == a↑
cover-trace-idp₀ cov a↑ = idp
cover-paste : ∀ {j} (cov : Cover A j) {a₁ a₂}
→ (a↑ : Fiber cov a₁)
→ (loop : a₁ =₀ a₁)
→ (p : a₁ =₀ a₂)
→ cover-trace cov (cover-trace cov a↑ loop) p
== cover-trace cov a↑ (loop ∙₀ p)
cover-paste cov a↑ loop p = ! $ trans₀-∙₀ (λ {a} → Fiber-is-set cov a) loop p a↑
-- Path sets form a covering space
module _ {i} (A∙ : Ptd i) where
path-set-cover : Cover (fst A∙) i
path-set-cover = record
{ Fiber = λ a → snd A∙ =₀ a
; Fiber-level = λ a → Trunc-level
}
-- Cover morphisms
CoverHom : ∀ {i} {A : Type i} {j₁ j₂}
→ (cov1 : Cover A j₁)
→ (cov2 : Cover A j₂)
→ Type (lmax i (lmax j₁ j₂))
CoverHom (cover F₁ _) (cover F₂ _) = ∀ a → F₁ a → F₂ a
| 31.875
| 84
| 0.515098
|
a1655f385f50f4351875c40e9cc9918969c56ad0
| 16,082
|
agda
|
Agda
|
Cubical/HITs/PropositionalTruncation/Properties.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/HITs/PropositionalTruncation/Properties.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/HITs/PropositionalTruncation/Properties.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-
This file contains:
- Eliminator for propositional truncation
-}
{-# OPTIONS --safe #-}
module Cubical.HITs.PropositionalTruncation.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.Data.Sum hiding (rec ; elim ; map)
open import Cubical.HITs.PropositionalTruncation.Base
private
variable
ℓ ℓ′ : Level
A B C : Type ℓ
A′ : Type ℓ′
∥∥-isPropDep : (P : A → Type ℓ) → isOfHLevelDep 1 (λ x → ∥ P x ∥)
∥∥-isPropDep P = isOfHLevel→isOfHLevelDep 1 (λ _ → squash)
rec : {P : Type ℓ} → isProp P → (A → P) → ∥ A ∥ → P
rec Pprop f ∣ x ∣ = f x
rec Pprop f (squash x y i) = Pprop (rec Pprop f x) (rec Pprop f y) i
rec2 : {P : Type ℓ} → isProp P → (A → B → P) → ∥ A ∥ → ∥ B ∥ → P
rec2 Pprop f ∣ x ∣ ∣ y ∣ = f x y
rec2 Pprop f ∣ x ∣ (squash y z i) = Pprop (rec2 Pprop f ∣ x ∣ y) (rec2 Pprop f ∣ x ∣ z) i
rec2 Pprop f (squash x y i) z = Pprop (rec2 Pprop f x z) (rec2 Pprop f y z) i
-- Old version
-- rec2 : ∀ {P : Type ℓ} → isProp P → (A → A → P) → ∥ A ∥ → ∥ A ∥ → P
-- rec2 Pprop f = rec (isProp→ Pprop) (λ a → rec Pprop (f a))
elim : {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a))
→ ((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a
elim Pprop f ∣ x ∣ = f x
elim Pprop f (squash x y i) =
isOfHLevel→isOfHLevelDep 1 Pprop
(elim Pprop f x) (elim Pprop f y) (squash x y) i
elim2 : {P : ∥ A ∥ → ∥ B ∥ → Type ℓ}
(Pprop : (x : ∥ A ∥) (y : ∥ B ∥) → isProp (P x y))
(f : (a : A) (b : B) → P ∣ a ∣ ∣ b ∣)
(x : ∥ A ∥) (y : ∥ B ∥) → P x y
elim2 Pprop f =
elim (λ _ → isPropΠ (λ _ → Pprop _ _))
(λ a → elim (λ _ → Pprop _ _) (f a))
elim3 : {P : ∥ A ∥ → ∥ B ∥ → ∥ C ∥ → Type ℓ}
(Pprop : ((x : ∥ A ∥) (y : ∥ B ∥) (z : ∥ C ∥) → isProp (P x y z)))
(g : (a : A) (b : B) (c : C) → P (∣ a ∣) ∣ b ∣ ∣ c ∣)
(x : ∥ A ∥) (y : ∥ B ∥) (z : ∥ C ∥) → P x y z
elim3 Pprop g = elim2 (λ _ _ → isPropΠ (λ _ → Pprop _ _ _))
(λ a b → elim (λ _ → Pprop _ _ _) (g a b))
isPropPropTrunc : isProp ∥ A ∥
isPropPropTrunc x y = squash x y
propTruncIdempotent≃ : isProp A → ∥ A ∥ ≃ A
propTruncIdempotent≃ {A = A} hA = isoToEquiv f
where
f : Iso ∥ A ∥ A
Iso.fun f = rec hA (idfun A)
Iso.inv f x = ∣ x ∣
Iso.rightInv f _ = refl
Iso.leftInv f = elim (λ _ → isProp→isSet isPropPropTrunc _ _) (λ _ → refl)
propTruncIdempotent : isProp A → ∥ A ∥ ≡ A
propTruncIdempotent hA = ua (propTruncIdempotent≃ hA)
-- We could also define the eliminator using the recursor
elim' : {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a)) →
((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a
elim' {P = P} Pprop f a =
rec (Pprop a) (λ x → transp (λ i → P (squash ∣ x ∣ a i)) i0 (f x)) a
map : (A → B) → (∥ A ∥ → ∥ B ∥)
map f = rec squash (∣_∣ ∘ f)
map2 : (A → B → C) → (∥ A ∥ → ∥ B ∥ → ∥ C ∥)
map2 f = rec (isPropΠ λ _ → squash) (map ∘ f)
-- The propositional truncation can be eliminated into non-propositional
-- types as long as the function used in the eliminator is 'coherently
-- constant.' The details of this can be found in the following paper:
--
-- https://arxiv.org/pdf/1411.2682.pdf
module SetElim (Bset : isSet B) where
Bset' : isSet' B
Bset' = isSet→isSet' Bset
rec→Set : (f : A → B) (kf : 2-Constant f) → ∥ A ∥ → B
helper : (f : A → B) (kf : 2-Constant f) → (t u : ∥ A ∥)
→ rec→Set f kf t ≡ rec→Set f kf u
rec→Set f kf ∣ x ∣ = f x
rec→Set f kf (squash t u i) = helper f kf t u i
helper f kf ∣ x ∣ ∣ y ∣ = kf x y
helper f kf (squash t u i) v
= Bset' (helper f kf t v) (helper f kf u v) (helper f kf t u) refl i
helper f kf t (squash u v i)
= Bset' (helper f kf t u) (helper f kf t v) refl (helper f kf u v) i
kcomp : (f : ∥ A ∥ → B) → 2-Constant (f ∘ ∣_∣)
kcomp f x y = cong f (squash ∣ x ∣ ∣ y ∣)
Fset : isSet (A → B)
Fset = isSetΠ (const Bset)
Kset : (f : A → B) → isSet (2-Constant f)
Kset f = isSetΠ (λ _ → isSetΠ (λ _ → isProp→isSet (Bset _ _)))
setRecLemma
: (f : ∥ A ∥ → B)
→ rec→Set (f ∘ ∣_∣) (kcomp f) ≡ f
setRecLemma f i t
= elim {P = λ t → rec→Set (f ∘ ∣_∣) (kcomp f) t ≡ f t}
(λ t → Bset _ _) (λ x → refl) t i
mkKmap : (∥ A ∥ → B) → Σ (A → B) 2-Constant
mkKmap f = f ∘ ∣_∣ , kcomp f
fib : (g : Σ (A → B) 2-Constant) → fiber mkKmap g
fib (g , kg) = rec→Set g kg , refl
eqv : (g : Σ (A → B) 2-Constant) → ∀ fi → fib g ≡ fi
eqv g (f , p) =
Σ≡Prop (λ f → isOfHLevelΣ 2 Fset Kset _ _)
(cong (uncurry rec→Set) (sym p) ∙ setRecLemma f)
trunc→Set≃ : (∥ A ∥ → B) ≃ (Σ (A → B) 2-Constant)
trunc→Set≃ .fst = mkKmap
trunc→Set≃ .snd .equiv-proof g = fib g , eqv g
-- The strategy of this equivalence proof follows the paper more closely.
-- It is used further down for the groupoid version, because the above
-- strategy does not generalize so easily.
e : B → Σ (A → B) 2-Constant
e b = const b , λ _ _ → refl
eval : A → (γ : Σ (A → B) 2-Constant) → B
eval a₀ (g , _) = g a₀
e-eval : ∀ (a₀ : A) γ → e (eval a₀ γ) ≡ γ
e-eval a₀ (g , kg) i .fst a₁ = kg a₀ a₁ i
e-eval a₀ (g , kg) i .snd a₁ a₂ = Bset' refl (kg a₁ a₂) (kg a₀ a₁) (kg a₀ a₂) i
e-isEquiv : A → isEquiv (e {A = A})
e-isEquiv a₀ = isoToIsEquiv (iso e (eval a₀) (e-eval a₀) λ _ → refl)
preEquiv₁ : ∥ A ∥ → B ≃ Σ (A → B) 2-Constant
preEquiv₁ t = e , rec (isPropIsEquiv e) e-isEquiv t
preEquiv₂ : (∥ A ∥ → Σ (A → B) 2-Constant) ≃ Σ (A → B) 2-Constant
preEquiv₂ = isoToEquiv (iso to const (λ _ → refl) retr)
where
to : (∥ A ∥ → Σ (A → B) 2-Constant) → Σ (A → B) 2-Constant
to f .fst x = f ∣ x ∣ .fst x
to f .snd x y i = f (squash ∣ x ∣ ∣ y ∣ i) .snd x y i
retr : retract to const
retr f i t .fst x = f (squash ∣ x ∣ t i) .fst x
retr f i t .snd x y
= Bset'
(λ j → f (squash ∣ x ∣ ∣ y ∣ j) .snd x y j)
(f t .snd x y)
(λ j → f (squash ∣ x ∣ t j) .fst x)
(λ j → f (squash ∣ y ∣ t j) .fst y)
i
trunc→Set≃₂ : (∥ A ∥ → B) ≃ Σ (A → B) 2-Constant
trunc→Set≃₂ = compEquiv (equivΠCod preEquiv₁) preEquiv₂
open SetElim public using (rec→Set; trunc→Set≃)
elim→Set
: {P : ∥ A ∥ → Type ℓ}
→ (∀ t → isSet (P t))
→ (f : (x : A) → P ∣ x ∣)
→ (kf : ∀ x y → PathP (λ i → P (squash ∣ x ∣ ∣ y ∣ i)) (f x) (f y))
→ (t : ∥ A ∥) → P t
elim→Set {A = A} {P = P} Pset f kf t
= rec→Set (Pset t) g gk t
where
g : A → P t
g x = transp (λ i → P (squash ∣ x ∣ t i)) i0 (f x)
gk : 2-Constant g
gk x y i = transp (λ j → P (squash (squash ∣ x ∣ ∣ y ∣ i) t j)) i0 (kf x y i)
RecHProp : (P : A → hProp ℓ) (kP : ∀ x y → P x ≡ P y) → ∥ A ∥ → hProp ℓ
RecHProp P kP = rec→Set isSetHProp P kP
module GpdElim (Bgpd : isGroupoid B) where
Bgpd' : isGroupoid' B
Bgpd' = isGroupoid→isGroupoid' Bgpd
module _ (f : A → B) (3kf : 3-Constant f) where
open 3-Constant 3kf
rec→Gpd : ∥ A ∥ → B
pathHelper : (t u : ∥ A ∥) → rec→Gpd t ≡ rec→Gpd u
triHelper₁
: (t u v : ∥ A ∥)
→ Square (pathHelper t u) (pathHelper t v) refl (pathHelper u v)
triHelper₂
: (t u v : ∥ A ∥)
→ Square (pathHelper t v) (pathHelper u v) (pathHelper t u) refl
rec→Gpd ∣ x ∣ = f x
rec→Gpd (squash t u i) = pathHelper t u i
pathHelper ∣ x ∣ ∣ y ∣ = link x y
pathHelper (squash t u j) v = triHelper₂ t u v j
pathHelper ∣ x ∣ (squash u v j) = triHelper₁ ∣ x ∣ u v j
triHelper₁ ∣ x ∣ ∣ y ∣ ∣ z ∣ = coh₁ x y z
triHelper₁ (squash s t i) u v
= Bgpd'
(triHelper₁ s u v)
(triHelper₁ t u v)
(triHelper₂ s t u)
(triHelper₂ s t v)
(λ i → refl)
(λ i → pathHelper u v)
i
triHelper₁ ∣ x ∣ (squash t u i) v
= Bgpd'
(triHelper₁ ∣ x ∣ t v)
(triHelper₁ ∣ x ∣ u v)
(triHelper₁ ∣ x ∣ t u)
(λ i → pathHelper ∣ x ∣ v)
(λ i → refl)
(triHelper₂ t u v)
i
triHelper₁ ∣ x ∣ ∣ y ∣ (squash u v i)
= Bgpd'
(triHelper₁ ∣ x ∣ ∣ y ∣ u)
(triHelper₁ ∣ x ∣ ∣ y ∣ v)
(λ i → link x y)
(triHelper₁ ∣ x ∣ u v)
(λ i → refl)
(triHelper₁ ∣ y ∣ u v)
i
triHelper₂ ∣ x ∣ ∣ y ∣ ∣ z ∣ = coh₂ x y z
triHelper₂ (squash s t i) u v
= Bgpd'
(triHelper₂ s u v)
(triHelper₂ t u v)
(triHelper₂ s t v)
(λ i → pathHelper u v)
(triHelper₂ s t u)
(λ i → refl)
i
triHelper₂ ∣ x ∣ (squash t u i) v
= Bgpd'
(triHelper₂ ∣ x ∣ t v)
(triHelper₂ ∣ x ∣ u v)
(λ i → pathHelper ∣ x ∣ v)
(triHelper₂ t u v)
(triHelper₁ ∣ x ∣ t u)
(λ i → refl)
i
triHelper₂ ∣ x ∣ ∣ y ∣ (squash u v i)
= Bgpd'
(triHelper₂ ∣ x ∣ ∣ y ∣ u)
(triHelper₂ ∣ x ∣ ∣ y ∣ v)
(triHelper₁ ∣ x ∣ u v)
(triHelper₁ ∣ y ∣ u v)
(λ i → link x y)
(λ i → refl)
i
preEquiv₁ : (∥ A ∥ → Σ (A → B) 3-Constant) ≃ Σ (A → B) 3-Constant
preEquiv₁ = isoToEquiv (iso fn const (λ _ → refl) retr)
where
open 3-Constant
fn : (∥ A ∥ → Σ (A → B) 3-Constant) → Σ (A → B) 3-Constant
fn f .fst x = f ∣ x ∣ .fst x
fn f .snd .link x y i = f (squash ∣ x ∣ ∣ y ∣ i) .snd .link x y i
fn f .snd .coh₁ x y z i j
= f (squash ∣ x ∣ (squash ∣ y ∣ ∣ z ∣ i) j) .snd .coh₁ x y z i j
retr : retract fn const
retr f i t .fst x = f (squash ∣ x ∣ t i) .fst x
retr f i t .snd .link x y j
= f (squash (squash ∣ x ∣ ∣ y ∣ j) t i) .snd .link x y j
retr f i t .snd .coh₁ x y z
= Bgpd'
(λ k j → f (cb k j i0) .snd .coh₁ x y z k j )
(λ k j → f (cb k j i1) .snd .coh₁ x y z k j)
(λ k j → f (cb i0 j k) .snd .link x y j)
(λ k j → f (cb i1 j k) .snd .link x z j)
(λ _ → refl)
(λ k j → f (cb j i1 k) .snd .link y z j)
i
where
cb : I → I → I → ∥ _ ∥
cb i j k = squash (squash ∣ x ∣ (squash ∣ y ∣ ∣ z ∣ i) j) t k
e : B → Σ (A → B) 3-Constant
e b .fst _ = b
e b .snd = record
{ link = λ _ _ _ → b
; coh₁ = λ _ _ _ _ _ → b
}
eval : A → Σ (A → B) 3-Constant → B
eval a₀ (g , _) = g a₀
module _ where
open 3-Constant
e-eval : ∀(a₀ : A) γ → e (eval a₀ γ) ≡ γ
e-eval a₀ (g , 3kg) i .fst x = 3kg .link a₀ x i
e-eval a₀ (g , 3kg) i .snd .link x y = λ j → 3kg .coh₁ a₀ x y j i
e-eval a₀ (g , 3kg) i .snd .coh₁ x y z
= Bgpd'
(λ _ _ → g a₀)
(3kg .coh₁ x y z)
(λ k j → 3kg .coh₁ a₀ x y j k)
(λ k j → 3kg .coh₁ a₀ x z j k)
(λ _ → refl)
(λ k j → 3kg .coh₁ a₀ y z j k)
i
e-isEquiv : A → isEquiv (e {A = A})
e-isEquiv a₀ = isoToIsEquiv (iso e (eval a₀) (e-eval a₀) λ _ → refl)
preEquiv₂ : ∥ A ∥ → B ≃ Σ (A → B) 3-Constant
preEquiv₂ t = e , rec (isPropIsEquiv e) e-isEquiv t
trunc→Gpd≃ : (∥ A ∥ → B) ≃ Σ (A → B) 3-Constant
trunc→Gpd≃ = compEquiv (equivΠCod preEquiv₂) preEquiv₁
open GpdElim using (rec→Gpd; trunc→Gpd≃) public
squashᵗ
: ∀(x y z : A)
→ Square (squash ∣ x ∣ ∣ y ∣) (squash ∣ x ∣ ∣ z ∣) refl (squash ∣ y ∣ ∣ z ∣)
squashᵗ x y z i = squash ∣ x ∣ (squash ∣ y ∣ ∣ z ∣ i)
elim→Gpd
: (P : ∥ A ∥ → Type ℓ)
→ (∀ t → isGroupoid (P t))
→ (f : (x : A) → P ∣ x ∣)
→ (kf : ∀ x y → PathP (λ i → P (squash ∣ x ∣ ∣ y ∣ i)) (f x) (f y))
→ (3kf : ∀ x y z
→ SquareP (λ i j → P (squashᵗ x y z i j)) (kf x y) (kf x z) refl (kf y z))
→ (t : ∥ A ∥) → P t
elim→Gpd {A = A} P Pgpd f kf 3kf t = rec→Gpd (Pgpd t) g 3kg t
where
g : A → P t
g x = transp (λ i → P (squash ∣ x ∣ t i)) i0 (f x)
open 3-Constant
3kg : 3-Constant g
3kg .link x y i
= transp (λ j → P (squash (squash ∣ x ∣ ∣ y ∣ i) t j)) i0 (kf x y i)
3kg .coh₁ x y z i j
= transp (λ k → P (squash (squashᵗ x y z i j) t k)) i0 (3kf x y z i j)
RecHSet : (P : A → TypeOfHLevel ℓ 2) → 3-Constant P → ∥ A ∥ → TypeOfHLevel ℓ 2
RecHSet P 3kP = rec→Gpd (isOfHLevelTypeOfHLevel 2) P 3kP
∥∥-IdempotentL-⊎-≃ : ∥ ∥ A ∥ ⊎ A′ ∥ ≃ ∥ A ⊎ A′ ∥
∥∥-IdempotentL-⊎-≃ = isoToEquiv ∥∥-IdempotentL-⊎-Iso
where ∥∥-IdempotentL-⊎-Iso : Iso (∥ ∥ A ∥ ⊎ A′ ∥) (∥ A ⊎ A′ ∥)
Iso.fun ∥∥-IdempotentL-⊎-Iso x = rec squash lem x
where lem : ∥ A ∥ ⊎ A′ → ∥ A ⊎ A′ ∥
lem (inl x) = map (λ a → inl a) x
lem (inr x) = ∣ inr x ∣
Iso.inv ∥∥-IdempotentL-⊎-Iso x = map lem x
where lem : A ⊎ A′ → ∥ A ∥ ⊎ A′
lem (inl x) = inl ∣ x ∣
lem (inr x) = inr x
Iso.rightInv ∥∥-IdempotentL-⊎-Iso x = squash (Iso.fun ∥∥-IdempotentL-⊎-Iso (Iso.inv ∥∥-IdempotentL-⊎-Iso x)) x
Iso.leftInv ∥∥-IdempotentL-⊎-Iso x = squash (Iso.inv ∥∥-IdempotentL-⊎-Iso (Iso.fun ∥∥-IdempotentL-⊎-Iso x)) x
∥∥-IdempotentL-⊎ : ∥ ∥ A ∥ ⊎ A′ ∥ ≡ ∥ A ⊎ A′ ∥
∥∥-IdempotentL-⊎ = ua ∥∥-IdempotentL-⊎-≃
∥∥-IdempotentR-⊎-≃ : ∥ A ⊎ ∥ A′ ∥ ∥ ≃ ∥ A ⊎ A′ ∥
∥∥-IdempotentR-⊎-≃ = isoToEquiv ∥∥-IdempotentR-⊎-Iso
where ∥∥-IdempotentR-⊎-Iso : Iso (∥ A ⊎ ∥ A′ ∥ ∥) (∥ A ⊎ A′ ∥)
Iso.fun ∥∥-IdempotentR-⊎-Iso x = rec squash lem x
where lem : A ⊎ ∥ A′ ∥ → ∥ A ⊎ A′ ∥
lem (inl x) = ∣ inl x ∣
lem (inr x) = map (λ a → inr a) x
Iso.inv ∥∥-IdempotentR-⊎-Iso x = map lem x
where lem : A ⊎ A′ → A ⊎ ∥ A′ ∥
lem (inl x) = inl x
lem (inr x) = inr ∣ x ∣
Iso.rightInv ∥∥-IdempotentR-⊎-Iso x = squash (Iso.fun ∥∥-IdempotentR-⊎-Iso (Iso.inv ∥∥-IdempotentR-⊎-Iso x)) x
Iso.leftInv ∥∥-IdempotentR-⊎-Iso x = squash (Iso.inv ∥∥-IdempotentR-⊎-Iso (Iso.fun ∥∥-IdempotentR-⊎-Iso x)) x
∥∥-IdempotentR-⊎ : ∥ A ⊎ ∥ A′ ∥ ∥ ≡ ∥ A ⊎ A′ ∥
∥∥-IdempotentR-⊎ = ua ∥∥-IdempotentR-⊎-≃
∥∥-Idempotent-⊎ : {A : Type ℓ} {A′ : Type ℓ′} → ∥ ∥ A ∥ ⊎ ∥ A′ ∥ ∥ ≡ ∥ A ⊎ A′ ∥
∥∥-Idempotent-⊎ {A = A} {A′} = ∥ ∥ A ∥ ⊎ ∥ A′ ∥ ∥ ≡⟨ ∥∥-IdempotentR-⊎ ⟩
∥ ∥ A ∥ ⊎ A′ ∥ ≡⟨ ∥∥-IdempotentL-⊎ ⟩
∥ A ⊎ A′ ∥ ∎
∥∥-IdempotentL-×-≃ : ∥ ∥ A ∥ × A′ ∥ ≃ ∥ A × A′ ∥
∥∥-IdempotentL-×-≃ = isoToEquiv ∥∥-IdempotentL-×-Iso
where ∥∥-IdempotentL-×-Iso : Iso (∥ ∥ A ∥ × A′ ∥) (∥ A × A′ ∥)
Iso.fun ∥∥-IdempotentL-×-Iso x = rec squash lem x
where lem : ∥ A ∥ × A′ → ∥ A × A′ ∥
lem (a , a′) = map2 (λ a a′ → a , a′) a ∣ a′ ∣
Iso.inv ∥∥-IdempotentL-×-Iso x = map lem x
where lem : A × A′ → ∥ A ∥ × A′
lem (a , a′) = ∣ a ∣ , a′
Iso.rightInv ∥∥-IdempotentL-×-Iso x = squash (Iso.fun ∥∥-IdempotentL-×-Iso (Iso.inv ∥∥-IdempotentL-×-Iso x)) x
Iso.leftInv ∥∥-IdempotentL-×-Iso x = squash (Iso.inv ∥∥-IdempotentL-×-Iso (Iso.fun ∥∥-IdempotentL-×-Iso x)) x
∥∥-IdempotentL-× : ∥ ∥ A ∥ × A′ ∥ ≡ ∥ A × A′ ∥
∥∥-IdempotentL-× = ua ∥∥-IdempotentL-×-≃
∥∥-IdempotentR-×-≃ : ∥ A × ∥ A′ ∥ ∥ ≃ ∥ A × A′ ∥
∥∥-IdempotentR-×-≃ = isoToEquiv ∥∥-IdempotentR-×-Iso
where ∥∥-IdempotentR-×-Iso : Iso (∥ A × ∥ A′ ∥ ∥) (∥ A × A′ ∥)
Iso.fun ∥∥-IdempotentR-×-Iso x = rec squash lem x
where lem : A × ∥ A′ ∥ → ∥ A × A′ ∥
lem (a , a′) = map2 (λ a a′ → a , a′) ∣ a ∣ a′
Iso.inv ∥∥-IdempotentR-×-Iso x = map lem x
where lem : A × A′ → A × ∥ A′ ∥
lem (a , a′) = a , ∣ a′ ∣
Iso.rightInv ∥∥-IdempotentR-×-Iso x = squash (Iso.fun ∥∥-IdempotentR-×-Iso (Iso.inv ∥∥-IdempotentR-×-Iso x)) x
Iso.leftInv ∥∥-IdempotentR-×-Iso x = squash (Iso.inv ∥∥-IdempotentR-×-Iso (Iso.fun ∥∥-IdempotentR-×-Iso x)) x
∥∥-IdempotentR-× : ∥ A × ∥ A′ ∥ ∥ ≡ ∥ A × A′ ∥
∥∥-IdempotentR-× = ua ∥∥-IdempotentR-×-≃
∥∥-Idempotent-× : {A : Type ℓ} {A′ : Type ℓ′} → ∥ ∥ A ∥ × ∥ A′ ∥ ∥ ≡ ∥ A × A′ ∥
∥∥-Idempotent-× {A = A} {A′} = ∥ ∥ A ∥ × ∥ A′ ∥ ∥ ≡⟨ ∥∥-IdempotentR-× ⟩
∥ ∥ A ∥ × A′ ∥ ≡⟨ ∥∥-IdempotentL-× ⟩
∥ A × A′ ∥ ∎
| 35.345055
| 118
| 0.482838
|
57541db688aab5a75f2ad4bc90a653ca301dc51d
| 1,216
|
agda
|
Agda
|
test/Succeed/Issue5923-OP.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | null | null | null |
test/Succeed/Issue5923-OP.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | null | null | null |
test/Succeed/Issue5923-OP.agda
|
favonia/agda
|
8d433b967567c08afe15d04a5cb63b6f6d8884ee
|
[
"BSD-2-Clause"
] | null | null | null |
{-# OPTIONS --type-in-type --rewriting #-}
module _ where
postulate
_≡_ : {A : Set} → A → A → Set
{-# BUILTIN REWRITE _≡_ #-}
record ⊤ : Set where
constructor []
open ⊤
postulate
ID : (Δ : Set) (δ₀ δ₁ : Δ) → Set
ID⊤ : (δ₀ δ₁ : ⊤) → ID ⊤ δ₀ δ₁ ≡ ⊤
Id : {Δ : Set} (A : Δ → Set) {δ₀ δ₁ : Δ} (δ₂ : ID Δ δ₀ δ₁) (a₀ : A δ₀) (a₁ : A δ₁) → Set
ap : {Δ : Set} {A : Δ → Set} (f : (δ : Δ) → A δ) {δ₀ δ₁ : Δ} (δ₂ : ID Δ δ₀ δ₁) → Id A δ₂ (f δ₀) (f δ₁)
AP : {Θ Δ : Set} (f : Θ → Δ) {t₀ t₁ : Θ} (t₂ : ID Θ t₀ t₁) → ID Δ (f t₀) (f t₁)
Id-AP : {Θ Δ : Set} (f : Θ → Δ) {t₀ t₁ : Θ} (t₂ : ID Θ t₀ t₁) (A : Δ → Set) (a₀ : A (f t₀)) (a₁ : A (f t₁)) →
Id A (AP f t₂) a₀ a₁ ≡ Id (λ w → A (f w)) t₂ a₀ a₁
Copy : Set → Set
uncopy : {A : Set} → Copy A → A
{-# REWRITE ID⊤ #-}
{-# REWRITE Id-AP #-}
postulate
utr→ : {Δ : Set} (A : Δ → Set) {δ₀ δ₁ : Δ} (δ₂ : ID Δ δ₀ δ₁) (a₁ a₁' : A δ₁) → Id {⊤} (λ _ → A δ₁) [] a₁ a₁'
IdU : {Δ : Set} {δ₀ δ₁ : Δ} (δ₂ : ID Δ δ₀ δ₁) (A B : Set) →
Id {Δ} (λ _ → Set) δ₂ A B ≡ Copy ((b₀ : B) (b₁ : B) → Id {⊤} (λ _ → B) [] b₀ b₁)
{-# REWRITE IdU #-}
postulate
apU : {Δ : Set} (A : Δ → Set) {δ₀ δ₁ : Δ} (δ₂ : ID Δ δ₀ δ₁) → uncopy (ap A δ₂) ≡ utr→ A δ₂
{-# REWRITE apU #-}
| 31.179487
| 111
| 0.449013
|
50cd7f79029681dace27e5584b4127fc1d3d8968
| 3,935
|
agda
|
Agda
|
src/Relation/Binary/Reduction.agda
|
Blaisorblade/f-omega-int-agda
|
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
|
[
"MIT"
] | 12
|
2017-06-13T16:05:35.000Z
|
2021-09-27T05:53:06.000Z
|
src/Relation/Binary/Reduction.agda
|
Blaisorblade/f-omega-int-agda
|
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
|
[
"MIT"
] | 1
|
2021-05-14T08:09:40.000Z
|
2021-05-14T08:54:39.000Z
|
src/Relation/Binary/Reduction.agda
|
Blaisorblade/f-omega-int-agda
|
ae20dac2a5e0c18dff2afda4c19954e24d73a24f
|
[
"MIT"
] | 2
|
2021-05-13T22:29:48.000Z
|
2021-05-14T10:25:05.000Z
|
------------------------------------------------------------------------
-- Generic support for reduction relations.
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module Relation.Binary.Reduction where
open import Data.Fin using (Fin)
open import Data.Fin.Substitution
open import Data.Nat using (ℕ; _+_)
open import Function using (_∘_)
open import Relation.Binary
open import Relation.Binary.Construct.Closure.Equivalence
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
as Star using (Star; ε; _◅_)
import Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties
as StarProp
open import Relation.Binary.Construct.Closure.Symmetric using (fwd)
import Relation.Binary.PropositionalEquality as PropEq
import Relation.Binary.Reasoning.Setoid as SetoidReasoning
-- Binary relations over abstract terms (i.e. ℕ-indexed sets).
TRel : ∀ (T : ℕ → Set) → Set₁
TRel T = ∀ {n} → T n → T n → Set
----------------------------------------------------------------------
-- Generic reduction and equivalence relations
record Reduction (T : ℕ → Set) : Set₁ where
infix 5 _→1_ _→*_ _↔_
-- One-step reduction.
field _→1_ : TRel T
-- The reflexive transitive closure of _→1_, i.e. finite sequences
-- of reduction steps.
_→*_ : TRel T
_→*_ = Star _→1_
-- The reflexive, transitive and symmetric closure (aka the
-- equivalence closure) of _→1_.
_↔_ : TRel T
_↔_ = EqClosure _→1_
-- All remaining submodules are parametrized by a given reduction.
module _ {T} (reduction : Reduction T) where
open Reduction reduction
----------------------------------------------------------------------
-- Properties of the reductions/equivalence
-- Inclusions.
→1⇒→* : ∀ {n} {a b : T n} → a →1 b → a →* b
→1⇒→* a→b = a→b ◅ ε
→*⇒↔ : ∀ {n} {a b : T n} → a →* b → a ↔ b
→*⇒↔ a→*b = Star.map fwd a→*b
→1⇒↔ : ∀ {n} {a b : T n} → a →1 b → a ↔ b
→1⇒↔ = →*⇒↔ ∘ →1⇒→*
-- Reductions are preorders.
→*-preorder : ℕ → Preorder _ _ _
→*-preorder n = StarProp.preorder (_→1_ {n})
-- Preorder reasoning for reductions.
module →*-Reasoning {n} = StarProp.StarReasoning (_→1_ {n})
-- Terms together with equivalence form a setoid.
↔-setoid : ℕ → Setoid _ _
↔-setoid n = setoid (_→1_ {n})
-- Equational reasoning for ↔-equivalence.
module ↔-Reasoning {n : ℕ} where
open SetoidReasoning (↔-setoid n) public
open Setoid (↔-setoid n) using (sym)
infixr 2 _→⟨_⟩_ _←⟨_⟩_ _→*⟨_⟩_ _←*⟨_⟩_
_→⟨_⟩_ : ∀ a {b c} → a →1 b → b IsRelatedTo c → a IsRelatedTo c
a →⟨ a→b ⟩ b≡c = a ≈⟨ →1⇒↔ a→b ⟩ b≡c
_←⟨_⟩_ : ∀ a {b c} → b →1 a → b IsRelatedTo c → a IsRelatedTo c
a ←⟨ a←b ⟩ b≡c = a ≈⟨ sym (→1⇒↔ a←b) ⟩ b≡c
_→*⟨_⟩_ : ∀ a {b c} → a →* b → b IsRelatedTo c → a IsRelatedTo c
a →*⟨ a→*b ⟩ b≡c = a ≈⟨ →*⇒↔ a→*b ⟩ b≡c
_←*⟨_⟩_ : ∀ a {b c} → b →* a → b IsRelatedTo c → a IsRelatedTo c
a ←*⟨ a←*b ⟩ b≡c = a ≈⟨ sym (→*⇒↔ a←*b) ⟩ b≡c
----------------------------------------------------------------------
-- Substitutions in reductions/equivalence
--
-- The applications _/→1_, _/→*_ and _/↔_ below may be considered
-- substitution lemmas, i.e. they establish the commutativity of the
-- respective reductions/equivalence with substitutions.
record RedSubstApp {T′} (app : Application T T′) : Set where
open Application app
open PropEq
infixl 8 _/→1_ _/→*_ _/↔_
field
-- Substitution commutes with one-step reduction.
_/→1_ : ∀ {m n a b} → a →1 b → (σ : Sub T′ m n) → a / σ →1 b / σ
-- Substitution commutes with β-reduction.
_/→*_ : ∀ {m n a b} → a →* b → (σ : Sub T′ m n) → a / σ →* b / σ
a→*b /→* σ = Star.gmap (λ a → a / σ) (λ a→b → a→b /→1 σ) a→*b
-- Substitution commutes with β-equivalence.
_/↔_ : ∀ {m n a b} → a ↔ b → (σ : Sub T′ m n) → a / σ ↔ b / σ
a≡b /↔ σ = gmap (λ a → a / σ) (λ a→b → a→b /→1 σ) a≡b
| 32.254098
| 72
| 0.547903
|
410324c1fc06c4df7fc4574efd0a03493f3c61e7
| 4,733
|
agda
|
Agda
|
agda-stdlib/src/Data/Fin/Substitution.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Fin/Substitution.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Fin/Substitution.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Substitutions
------------------------------------------------------------------------
-- Uses a variant of Conor McBride's technique from "Type-Preserving
-- Renaming and Substitution".
-- See Data.Fin.Substitution.Example for an example of how this module
-- can be used: a definition of substitution for the untyped
-- λ-calculus.
{-# OPTIONS --without-K --safe #-}
module Data.Fin.Substitution where
open import Data.Nat hiding (_⊔_)
open import Data.Fin.Base using (Fin; zero; suc)
open import Data.Vec.Base
open import Function as Fun using (flip)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
as Star using (Star; ε; _◅_)
open import Level using (Level; _⊔_)
import Level as L
open import Relation.Unary using (Pred)
------------------------------------------------------------------------
-- General functionality
-- A Sub T m n is a substitution which, when applied to something with
-- at most m variables, yields something with at most n variables.
Sub : ∀ {ℓ} → Pred ℕ ℓ → ℕ → ℕ → Set ℓ
Sub T m n = Vec (T n) m
-- A /reversed/ sequence of matching substitutions.
Subs : ∀ {ℓ} → Pred ℕ ℓ → ℕ → ℕ → Set ℓ
Subs T = flip (Star (flip (Sub T)))
-- Some simple substitutions.
record Simple {ℓ : Level} (T : Pred ℕ ℓ) : Set ℓ where
infix 10 _↑
infixl 10 _↑⋆_ _↑✶_
field
var : ∀ {n} → Fin n → T n -- Takes variables to Ts.
weaken : ∀ {n} → T n → T (suc n) -- Weakens Ts.
-- Lifting.
_↑ : ∀ {m n} → Sub T m n → Sub T (suc m) (suc n)
ρ ↑ = var zero ∷ map weaken ρ
_↑⋆_ : ∀ {m n} → Sub T m n → ∀ k → Sub T (k + m) (k + n)
ρ ↑⋆ zero = ρ
ρ ↑⋆ suc k = (ρ ↑⋆ k) ↑
_↑✶_ : ∀ {m n} → Subs T m n → ∀ k → Subs T (k + m) (k + n)
ρs ↑✶ k = Star.gmap (_+_ k) (λ ρ → ρ ↑⋆ k) ρs
-- The identity substitution.
id : ∀ {n} → Sub T n n
id {zero} = []
id {suc n} = id ↑
-- Weakening.
wk⋆ : ∀ k {n} → Sub T n (k + n)
wk⋆ zero = id
wk⋆ (suc k) = map weaken (wk⋆ k)
wk : ∀ {n} → Sub T n (suc n)
wk = wk⋆ 1
-- A substitution which only replaces the first variable.
sub : ∀ {n} → T n → Sub T (suc n) n
sub t = t ∷ id
-- Application of substitutions.
record Application {ℓ₁ ℓ₂ : Level} (T₁ : Pred ℕ ℓ₁) (T₂ : Pred ℕ ℓ₂) :
Set (ℓ₁ ⊔ ℓ₂) where
infixl 8 _/_ _/✶_
infixl 9 _⊙_
-- Post-application of substitutions to things.
field _/_ : ∀ {m n} → T₁ m → Sub T₂ m n → T₁ n
-- Reverse composition. (Fits well with post-application.)
_⊙_ : ∀ {m n k} → Sub T₁ m n → Sub T₂ n k → Sub T₁ m k
ρ₁ ⊙ ρ₂ = map (λ t → t / ρ₂) ρ₁
-- Application of multiple substitutions.
_/✶_ : ∀ {m n} → T₁ m → Subs T₂ m n → T₁ n
_/✶_ = Star.gfold Fun.id _ (flip _/_) {k = zero}
-- A combination of the two records above.
record Subst {ℓ : Level} (T : Pred ℕ ℓ) : Set ℓ where
field
simple : Simple T
application : Application T T
open Simple simple public
open Application application public
-- Composition of multiple substitutions.
⨀ : ∀ {m n} → Subs T m n → Sub T m n
⨀ ε = id
⨀ (ρ ◅ ε) = ρ -- Convenient optimisation; simplifies some proofs.
⨀ (ρ ◅ ρs) = ⨀ ρs ⊙ ρ
------------------------------------------------------------------------
-- Instantiations and code for facilitating instantiations
-- Liftings from T₁ to T₂.
record Lift {ℓ₁ ℓ₂ : Level} (T₁ : Pred ℕ ℓ₁) (T₂ : Pred ℕ ℓ₂) :
Set (ℓ₁ ⊔ ℓ₂) where
field
simple : Simple T₁
lift : ∀ {n} → T₁ n → T₂ n
open Simple simple public
-- Variable substitutions (renamings).
module VarSubst where
subst : Subst Fin
subst = record
{ simple = record { var = Fun.id; weaken = suc }
; application = record { _/_ = flip lookup }
}
open Subst subst public
-- "Term" substitutions.
record TermSubst (T : Pred ℕ L.zero) : Set₁ where
field
var : ∀ {n} → Fin n → T n
app : ∀ {T′ : Pred ℕ L.zero} → Lift T′ T → ∀ {m n} → T m → Sub T′ m n → T n
module Lifted {T′ : Pred ℕ L.zero} (lift : Lift T′ T) where
application : Application T T′
application = record { _/_ = app lift }
open Lift lift public
open Application application public
varLift : Lift Fin T
varLift = record { simple = VarSubst.simple; lift = var }
infix 8 _/Var_
_/Var_ : ∀ {m n} → T m → Sub Fin m n → T n
_/Var_ = app varLift
simple : Simple T
simple = record
{ var = var
; weaken = λ t → t /Var VarSubst.wk
}
termLift : Lift T T
termLift = record { simple = simple; lift = Fun.id }
subst : Subst T
subst = record
{ simple = simple
; application = Lifted.application termLift
}
open Subst subst public hiding (var; simple)
| 25.583784
| 79
| 0.56011
|
3d69989bcce7036a1ea878b36e0938e0f8605d60
| 222
|
agda
|
Agda
|
test/Fail/Issue274.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue274.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue274.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Issue274 where
-- data ⊥ : Set where
record U : Set where
inductive
constructor roll
field ap : U → U
-- lemma : U → ⊥
-- lemma (roll u) = lemma (u (roll u))
-- bottom : ⊥
-- bottom = lemma (roll λ x → x)
| 14.8
| 38
| 0.585586
|
1c9a9d1215c2c504d8c2355c3a49be8f78f698dc
| 9,278
|
agda
|
Agda
|
lib/PathOver.agda
|
sattlerc/HoTT-Agda
|
c8fb8da3354fc9e0c430ac14160161759b4c5b37
|
[
"MIT"
] | null | null | null |
lib/PathOver.agda
|
sattlerc/HoTT-Agda
|
c8fb8da3354fc9e0c430ac14160161759b4c5b37
|
[
"MIT"
] | null | null | null |
lib/PathOver.agda
|
sattlerc/HoTT-Agda
|
c8fb8da3354fc9e0c430ac14160161759b4c5b37
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Base
open import lib.PathGroupoid
open import lib.Equivalences
open import lib.Univalence
open import lib.Funext
{- Structural lemmas about paths over paths
The lemmas here have the form
[↓-something-in] : introduction rule for the something
[↓-something-out] : elimination rule for the something
[↓-something-β] : β-reduction rule for the something
[↓-something-η] : η-reduction rule for the something
The possible somethings are:
[cst] : constant fibration
[cst2] : fibration constant in the second argument
[cst2×] : fibration constant and nondependent in the second argument
[ap] : the path below is of the form [ap f p]
[fst×] : the fibration is [fst] (nondependent product)
[snd×] : the fibration is [snd] (nondependent product)
You can also go back and forth between dependent paths and homogeneous paths
with a transport on one side with the functions
[to-transp], [from-transp], [to-transp-β]
[to-transp!], [from-transp!], [to-transp!-β]
More lemmas about paths over paths are present in the lib.types.* modules
(depending on the type constructor of the fibration)
-}
module lib.PathOver where
{- Dependent paths in a constant fibration -}
module _ {i j} {A : Type i} {B : Type j} where
↓-cst-in : {x y : A} {p : x == y} {u v : B}
→ u == v
→ u == v [ (λ _ → B) ↓ p ]
↓-cst-in {p = idp} q = q
↓-cst-out : {x y : A} {p : x == y} {u v : B}
→ u == v [ (λ _ → B) ↓ p ]
→ u == v
↓-cst-out {p = idp} q = q
↓-cst-β : {x y : A} (p : x == y) {u v : B} (q : u == v)
→ (↓-cst-out (↓-cst-in {p = p} q) == q)
↓-cst-β idp q = idp
{- Interaction of [↓-cst-in] with [_∙_] -}
↓-cst-in-∙ : {x y z : A} (p : x == y) (q : y == z) {u v w : B}
(p' : u == v) (q' : v == w)
→ ↓-cst-in {p = p ∙ q} (p' ∙ q')
== ↓-cst-in {p = p} p' ∙ᵈ ↓-cst-in {p = q} q'
↓-cst-in-∙ idp idp idp idp = idp
{- Introduction of an equality between [↓-cst-in]s (used to deduce the
recursor from the eliminator in HIT with 2-paths) -}
↓-cst-in2 : {a a' : A} {u v : B}
{p₀ : a == a'} {p₁ : a == a'} {q₀ q₁ : u == v} {q : p₀ == p₁}
→ q₀ == q₁
→ (↓-cst-in {p = p₀} q₀ == ↓-cst-in {p = p₁} q₁ [ (λ p → u == v [ (λ _ → B) ↓ p ]) ↓ q ])
↓-cst-in2 {p₀ = idp} {p₁ = .idp} {q₀} {q₁} {idp} k = k
-- Dependent paths in a fibration constant in the second argument
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where
↓-cst2-in : {x y : A} (p : x == y) {b : C x} {c : C y}
(q : b == c [ C ↓ p ]) {u : B x} {v : B y}
→ u == v [ B ↓ p ]
→ u == v [ (λ xy → B (fst xy)) ↓ (pair= p q) ]
↓-cst2-in idp idp r = r
↓-cst2-out : {x y : A} (p : x == y) {b : C x} {c : C y}
(q : b == c [ C ↓ p ]) {u : B x} {v : B y}
→ u == v [ (λ xy → B (fst xy)) ↓ (pair= p q) ]
→ u == v [ B ↓ p ]
↓-cst2-out idp idp r = r
-- Dependent paths in a fibration constant and non dependent in the
-- second argument
module _ {i j k} {A : Type i} {B : A → Type j} {C : Type k} where
↓-cst2×-in : {x y : A} (p : x == y) {b c : C}
(q : b == c) {u : B x} {v : B y}
→ u == v [ B ↓ p ]
→ u == v [ (λ xy → B (fst xy)) ↓ (pair×= p q) ]
↓-cst2×-in idp idp r = r
↓-cst2×-out : {x y : A} (p : x == y) {b c : C}
(q : b == c) {u : B x} {v : B y}
→ u == v [ (λ xy → B (fst xy)) ↓ (pair×= p q) ]
→ u == v [ B ↓ p ]
↓-cst2×-out idp idp r = r
-- Dependent paths over [ap f p]
module _ {i j k} {A : Type i} {B : Type j} (C : B → Type k) (f : A → B) where
↓-ap-in : {x y : A} {p : x == y} {u : C (f x)} {v : C (f y)}
→ u == v [ C ∘ f ↓ p ]
→ u == v [ C ↓ ap f p ]
↓-ap-in {p = idp} idp = idp
↓-ap-out : {x y : A} (p : x == y) {u : C (f x)} {v : C (f y)}
→ u == v [ C ↓ ap f p ]
→ u == v [ C ∘ f ↓ p ]
↓-ap-out idp idp = idp
apd↓ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k}
(f : {a : A} (b : B a) → C a b) {x y : A} {p : x == y}
{u : B x} {v : B y} (q : u == v [ B ↓ p ])
→ f u == f v [ (λ xy → C (fst xy) (snd xy)) ↓ pair= p q ]
apd↓ f {p = idp} idp = idp
apd↓=apd : ∀ {i j} {A : Type i} {B : A → Type j} (f : (a : A) → B a) {x y : A}
(p : x == y) → (apd f p == ↓-ap-out _ _ p (apd↓ {A = Unit} f {p = idp} p))
apd↓=apd f idp = idp
-- Paths in the fibrations [fst] and [snd]
module _ {i j} where
↓-fst×-out : {A A' : Type i} {B B' : Type j} (p : A == A') (q : B == B')
{u : A} {v : A'}
→ u == v [ fst ↓ pair×= p q ]
→ u == v [ (λ X → X) ↓ p ]
↓-fst×-out idp idp h = h
↓-snd×-in : {A A' : Type i} {B B' : Type j} (p : A == A') (q : B == B')
{u : B} {v : B'}
→ u == v [ (λ X → X) ↓ q ]
→ u == v [ snd ↓ pair×= p q ]
↓-snd×-in idp idp h = h
-- Mediating dependent paths with the transport version
module _ {i j} {A : Type i} where
from-transp : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'}
→ (transport B p u == v)
→ (u == v [ B ↓ p ])
from-transp B idp idp = idp
to-transp : {B : A → Type j} {a a' : A} {p : a == a'}
{u : B a} {v : B a'}
→ (u == v [ B ↓ p ])
→ (transport B p u == v)
to-transp {p = idp} idp = idp
to-transp-β : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'}
(q : transport B p u == v)
→ to-transp (from-transp B p q) == q
to-transp-β B idp idp = idp
to-transp-η : {B : A → Type j} {a a' : A} {p : a == a'}
{u : B a} {v : B a'}
(q : u == v [ B ↓ p ])
→ from-transp B p (to-transp q) == q
to-transp-η {p = idp} idp = idp
to-transp-equiv : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'} → (u == v [ B ↓ p ]) ≃ (transport B p u == v)
to-transp-equiv B p =
equiv to-transp (from-transp B p) (to-transp-β B p) (to-transp-η)
from-transp! : (B : A → Type j)
{a a' : A} (p : a == a')
{u : B a} {v : B a'}
→ (u == transport! B p v)
→ (u == v [ B ↓ p ])
from-transp! B idp idp = idp
to-transp! : {B : A → Type j}
{a a' : A} {p : a == a'}
{u : B a} {v : B a'}
→ (u == v [ B ↓ p ])
→ (u == transport! B p v)
to-transp! {p = idp} idp = idp
to-transp!-β : (B : A → Type j)
{a a' : A} (p : a == a')
{u : B a} {v : B a'}
(q : u == transport! B p v)
→ to-transp! (from-transp! B p q) == q
to-transp!-β B idp idp = idp
to-transp!-η : {B : A → Type j} {a a' : A} {p : a == a'}
{u : B a} {v : B a'}
(q : u == v [ B ↓ p ])
→ from-transp! B p (to-transp! q) == q
to-transp!-η {p = idp} idp = idp
to-transp!-equiv : (B : A → Type j) {a a' : A} (p : a == a')
{u : B a} {v : B a'} → (u == v [ B ↓ p ]) ≃ (u == transport! B p v)
to-transp!-equiv B p =
equiv to-transp! (from-transp! B p) (to-transp!-β B p) (to-transp!-η)
{- Various other lemmas -}
{- Used for defining the recursor from the eliminator for 1-HIT -}
apd=cst-in : ∀ {i j} {A : Type i} {B : Type j} {f : A → B}
{a a' : A} {p : a == a'} {q : f a == f a'}
→ apd f p == ↓-cst-in q → ap f p == q
apd=cst-in {p = idp} x = x
↓-apd-out : ∀ {i j k} {A : Type i} {B : A → Type j} (C : (a : A) → B a → Type k)
{f : Π A B} {x y : A} {p : x == y}
{q : f x == f y [ B ↓ p ]} (r : apd f p == q)
{u : C x (f x)} {v : C y (f y)}
→ u == v [ uncurry C ↓ pair= p q ]
→ u == v [ (λ z → C z (f z)) ↓ p ]
↓-apd-out C {p = idp} idp idp = idp
-- No idea what that is
to-transp-weird : ∀ {i j} {A : Type i} {B : A → Type j}
{u v : A} {d : B u} {d' d'' : B v} {p : u == v}
(q : d == d' [ B ↓ p ]) (r : transport B p d == d'')
→ (from-transp B p r ∙'ᵈ (! r ∙ to-transp q)) == q
to-transp-weird {p = idp} idp idp = idp
-- Something not really clear yet
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A → C) (g : B → C)
where
↓-swap : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
(r : f a == g b') (s : f a' == g b)
→ (ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ])
→ (r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ])
↓-swap {p = idp} {q = idp} r s t = (! t) ∙ ∙'-unit-l s ∙ ! (∙-unit-r s)
↓-swap! : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
(r : f a == g b') (s : f a' == g b)
→ (r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ])
→ (ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ])
↓-swap! {p = idp} {q = idp} r s t = ∙'-unit-l s ∙ ! (∙-unit-r s) ∙ (! t)
↓-swap-β : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
(r : f a == g b') (s : f a' == g b)
(t : ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ])
→ ↓-swap! r s (↓-swap r s t) == t
↓-swap-β {p = idp} {q = idp} r s t = coh (∙'-unit-l s) (∙-unit-r s) t where
coh : ∀ {i} {X : Type i} {x y z t : X} (p : x == y) (q : z == y) (r : x == t)
→ p ∙ ! q ∙ ! (! r ∙ p ∙ ! q) == r
coh idp idp idp = idp
{- Dependent paths over function spaces -}
↓-→-is-square : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
{x y : A} (f : B x → C x) (g : B y → C y) (p : x == y)
→ ((transport C p ∘ f) == (g ∘ transport B p))
== (f == g [ (λ z → B z → C z) ↓ p ])
↓-→-is-square _ _ idp = idp
trans-↓ : ∀ {i j} {A : Type i} (P : A → Type j) {a₁ a₂ : A}
(p : a₁ == a₂) (y : P a₂) → transport P (! p) y == y [ P ↓ p ]
trans-↓ _ idp _ = idp
trans-ap-↓ : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) (h : A → B)
{a₁ a₂ : A} (p : a₁ == a₂) (y : P (h a₂))
→ transport P (! (ap h p)) y == y [ P ∘ h ↓ p ]
trans-ap-↓ _ _ idp _ = idp
| 34.490706
| 93
| 0.441367
|
577278358495e9bc736dd11129dffc381c2fdd62
| 987
|
agda
|
Agda
|
lib/types/Bool.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
lib/types/Bool.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/Bool.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Pointed
module lib.types.Bool where
data Bool : Type₀ where
true : Bool
false : Bool
⊙Bool : Ptd₀
⊙Bool = ⊙[ Bool , true ]
if_then_else_ : ∀ {i} {A : Bool → Type i}
(b : Bool) (t : A true) (e : A false)
→ A b
if true then t else e = t
if false then t else e = e
private
Bool-true≠false-type : Bool → Type₀
Bool-true≠false-type true = Unit
Bool-true≠false-type false = Empty
abstract
Bool-true≠false : true ≠ false
Bool-true≠false p = transport Bool-true≠false-type p unit
Bool-false≠true : false ≠ true
Bool-false≠true p = transport Bool-true≠false-type (! p) unit
Bool-has-dec-eq : has-dec-eq Bool
Bool-has-dec-eq true true = inl idp
Bool-has-dec-eq true false = inr Bool-true≠false
Bool-has-dec-eq false true = inr Bool-false≠true
Bool-has-dec-eq false false = inl idp
Bool-is-set : is-set Bool
Bool-is-set = dec-eq-is-set Bool-has-dec-eq
Bool-level = Bool-is-set
| 22.953488
| 63
| 0.670719
|
1c833049ad15f67cb79ab8957c4e415335d17437
| 2,752
|
agda
|
Agda
|
Cubical/Functions/Surjection.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Functions/Surjection.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Functions/Surjection.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Functions.Surjection where
open import Cubical.Core.Everything
open import Cubical.Data.Sigma
open import Cubical.Data.Unit
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Functions.Embedding
open import Cubical.HITs.PropositionalTruncation as PropTrunc
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
f : A → B
isSurjection : (A → B) → Type _
isSurjection f = ∀ b → ∥ fiber f b ∥
_↠_ : Type ℓ → Type ℓ' → Type (ℓ-max ℓ ℓ')
A ↠ B = Σ[ f ∈ (A → B) ] isSurjection f
section→isSurjection : {g : B → A} → section f g → isSurjection f
section→isSurjection {g = g} s b = ∣ g b , s b ∣
isPropIsSurjection : isProp (isSurjection f)
isPropIsSurjection = isPropΠ λ _ → squash
isEquiv→isSurjection : isEquiv f → isSurjection f
isEquiv→isSurjection e b = ∣ fst (equiv-proof e b) ∣
isEquiv→isEmbedding×isSurjection : isEquiv f → isEmbedding f × isSurjection f
isEquiv→isEmbedding×isSurjection e = isEquiv→isEmbedding e , isEquiv→isSurjection e
isEmbedding×isSurjection→isEquiv : isEmbedding f × isSurjection f → isEquiv f
equiv-proof (isEmbedding×isSurjection→isEquiv {f = f} (emb , sur)) b =
inhProp→isContr (PropTrunc.rec fib' (λ x → x) fib) fib'
where
hpf : hasPropFibers f
hpf = isEmbedding→hasPropFibers emb
fib : ∥ fiber f b ∥
fib = sur b
fib' : isProp (fiber f b)
fib' = hpf b
isEquiv≃isEmbedding×isSurjection : isEquiv f ≃ isEmbedding f × isSurjection f
isEquiv≃isEmbedding×isSurjection = isoToEquiv (iso
isEquiv→isEmbedding×isSurjection
isEmbedding×isSurjection→isEquiv
(λ _ → isOfHLevelΣ 1 isPropIsEmbedding (\ _ → isPropIsSurjection) _ _)
(λ _ → isPropIsEquiv _ _ _))
-- obs: for epi⇒surjective to go through we require a stronger
-- hypothesis that one would expect:
-- f must cancel functions from a higher universe.
rightCancellable : (f : A → B) → Type _
rightCancellable {ℓ} {A} {ℓ'} {B} f = ∀ {C : Type (ℓ-suc (ℓ-max ℓ ℓ'))}
→ ∀ (g g' : B → C) → (∀ x → g (f x) ≡ g' (f x)) → ∀ y → g y ≡ g' y
-- This statement is in Mac Lane & Moerdijk (page 143, corollary 5).
epi⇒surjective : (f : A → B) → rightCancellable f → isSurjection f
epi⇒surjective f rc y = transport (fact₂ y) tt*
where hasPreimage : (A → B) → B → _
hasPreimage f y = ∥ fiber f y ∥
fact₁ : ∀ x → Unit* ≡ hasPreimage f (f x)
fact₁ x = hPropExt isPropUnit*
isPropPropTrunc
(λ _ → ∣ (x , refl) ∣)
(λ _ → tt*)
fact₂ : ∀ y → Unit* ≡ hasPreimage f y
fact₂ = rc _ _ fact₁
| 33.975309
| 83
| 0.660247
|
58b9197326d21852e004ebe6f91509f560a2dbba
| 29,577
|
agda
|
Agda
|
Cubical/ZCohomology/RingStructure/RingLaws.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/RingStructure/RingLaws.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/RingStructure/RingLaws.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.RingStructure.RingLaws where
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Path
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.Foundations.GroupoidLaws hiding (assoc)
open import Cubical.Data.Nat
open import Cubical.Data.Int
renaming (_+_ to _ℤ+_ ; _·_ to _ℤ∙_ ; +Comm to +ℤ-comm ; ·Comm to ∙-comm ; +Assoc to ℤ+-assoc ; -_ to -ℤ_)
hiding (_+'_ ; +'≡+)
open import Cubical.Data.Sigma
open import Cubical.HITs.SetTruncation as ST
open import Cubical.HITs.Truncation as T
open import Cubical.HITs.S1 hiding (_·_)
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.Homotopy.Loopspace
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.RingStructure.CupProduct
private
variable
ℓ : Level
open PlusBis
-- Some boring lemmas
·₀≡·ℤ : (x y : ℤ) → _·₀_ {n = zero} x y ≡ x ℤ∙ y
·₀≡·ℤ (pos zero) y = refl
·₀≡·ℤ (pos (suc n)) y = cong (y ℤ+_) (·₀≡·ℤ (pos n) y)
·₀≡·ℤ (negsuc zero) (pos zero) = refl
·₀≡·ℤ (negsuc zero) (pos (suc n)) = -AntiComm 0 (pos (suc n))
·₀≡·ℤ (negsuc zero) (negsuc n) = -AntiComm 0 (negsuc n)
·₀≡·ℤ (negsuc (suc n)) (pos m) =
(cong ((_ℤ+ (pos 0 - pos m))) (·₀≡·ℤ (negsuc n) (pos m))
∙ cong ((negsuc n ℤ∙ (pos m)) ℤ+_)
(-AntiComm 0 (pos m) ∙ cong (-ℤ_) (help m)))
∙ sym (+ℤ-comm (-ℤ (pos m)) (negsuc n ℤ∙ (pos m)))
where
help : (m : ℕ) → (pos m - 0) ≡ pos m
help zero = refl
help (suc m) = refl
·₀≡·ℤ (negsuc (suc n)) (negsuc m) =
+ℤ-comm (_·₀_{n = zero} (negsuc n) (negsuc m)) (pos 0 - (negsuc m))
∙∙ cong ((pos 0 - negsuc m) ℤ+_) (·₀≡·ℤ (negsuc n) (negsuc m))
∙∙ cong (_ℤ+ (negsuc n ℤ∙ negsuc m)) (help m)
where
help : (m : ℕ) → (pos 0 - negsuc m) ≡ pos (suc m)
help zero = refl
help (suc n) = cong sucℤ (help n)
comm-·₀ : (x y : ℤ) → _·₀_ {n = 0} x y ≡ y ·₀ x
comm-·₀ x y = ·₀≡·ℤ x y ∙∙ ∙-comm x y ∙∙ sym (·₀≡·ℤ y x)
-- Zero multiplication
⌣ₖ-0ₖ : (n m : ℕ) → (x : coHomK n)
→ x ⌣ₖ (0ₖ _) ≡ 0ₖ _
⌣ₖ-0ₖ n m x = snd (⌣ₖ∙ n m x)
0ₖ-⌣ₖ : (n m : ℕ) → (x : coHomK m) →
(0ₖ _) ⌣ₖ x ≡ 0ₖ _
0ₖ-⌣ₖ n m = funExt⁻ (cong fst (snd (⌣ₖ∙∙ n m)))
⌣ₖ-0ₖ≡0ₖ-⌣ₖ : (n m : ℕ) → ⌣ₖ-0ₖ n m (0ₖ _) ≡ 0ₖ-⌣ₖ n m (0ₖ _)
⌣ₖ-0ₖ≡0ₖ-⌣ₖ zero zero = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ zero (suc m) = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ (suc n) zero = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ (suc zero) (suc m) = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ (suc (suc n)) (suc m) = refl
-- Left distributivity
private
⌣ₖ-distrFun : -- z ⌣ₖ (x +ₖ y)
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (m +' n)
fst (⌣ₖ-distrFun n m x y) z =
z ⌣ₖ (x +ₖ y)
snd (⌣ₖ-distrFun n m x y) =
0ₖ-⌣ₖ m n (x +ₖ y)
⌣ₖ-distrFun2 : -- z ⌣ₖ x +ₖ z ⌣ₖ y
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (m +' n)
fst (⌣ₖ-distrFun2 n m x y) z =
z ⌣ₖ x +ₖ z ⌣ₖ y
snd (⌣ₖ-distrFun2 n m x y) =
cong₂ _+ₖ_ (0ₖ-⌣ₖ m n x) (0ₖ-⌣ₖ m n y) ∙ rUnitₖ _ _
leftDistr-⌣ₖ· : (n m : ℕ) (x y : coHomK (suc n))
→ ⌣ₖ-distrFun (suc n) (suc m) x y ≡ ⌣ₖ-distrFun2 (suc n) (suc m) x y
leftDistr-⌣ₖ· n m =
T.elim2 (λ _ _ → isOfHLevelSuc (2 + n) (hLevHelp n m _ _))
main
where
hLevHelp : (n m : ℕ) (x y : _)
→ isOfHLevel (2 + n) ( ⌣ₖ-distrFun (suc n) (suc m) x y ≡ ⌣ₖ-distrFun2 (suc n) (suc m) x y)
hLevHelp n m x y =
(subst (isOfHLevel (3 + n))
(λ i → (coHomK-ptd (suc m) →∙ coHomK-ptd (suc (suc (+-comm n m i)))))
(isOfHLevel↑∙ (suc n) m)) _ _
left-fst : (n : ℕ) (x : S₊ (suc n)) →
fst (⌣ₖ-distrFun (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ x ∣) ≡
fst (⌣ₖ-distrFun2 (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ x ∣)
left-fst zero y =
(funExt (λ z → sym (lUnitₖ _ (z ⌣ₖ ∣ y ∣)) ∙ λ i → ⌣ₖ-0ₖ _ _ z (~ i) +ₖ z ⌣ₖ ∣ y ∣))
left-fst (suc n) y =
(funExt (λ z → sym (lUnitₖ _ (z ⌣ₖ ∣ y ∣)) ∙ λ i → ⌣ₖ-0ₖ _ _ z (~ i) +ₖ z ⌣ₖ ∣ y ∣))
right-fst : (n : ℕ) (x : S₊ (suc n)) →
fst (⌣ₖ-distrFun (suc n) (suc m) ∣ x ∣ (0ₖ _)) ≡
fst (⌣ₖ-distrFun2 (suc n) (suc m) ∣ x ∣ (0ₖ _))
right-fst n x = funExt (λ z → (cong (z ⌣ₖ_) (rUnitₖ _ ∣ x ∣) ∙∙ sym (rUnitₖ _ _) ∙∙ λ i → z ⌣ₖ ∣ x ∣ +ₖ ⌣ₖ-0ₖ _ (suc n) z (~ i)))
helper : (n : ℕ) (x : coHomK (suc n)) (p : 0ₖ _ ≡ x)
→ sym (lUnitₖ _ x) ∙ cong (_+ₖ x) p ≡ sym (rUnitₖ _ x) ∙ cong (x +ₖ_) p
helper n x = J (λ x p → sym (lUnitₖ _ x) ∙ cong (_+ₖ x) p ≡ sym (rUnitₖ _ x) ∙ cong (x +ₖ_) p)
(helper' n)
where
helper' : (n : ℕ) → (λ i → lUnitₖ (suc n) (0ₖ (suc n)) (~ i)) ∙
(λ i → 0ₖ (suc n) +ₖ 0ₖ (suc n))
≡
(λ i → rUnitₖ (suc n) (0ₖ (suc n)) (~ i)) ∙
(λ i → 0ₖ (suc n) +ₖ 0ₖ (suc n))
helper' zero = refl
helper' (suc n) = refl
left-fst≡right-fst : (n : ℕ) → left-fst n (ptSn _) ≡ right-fst n (ptSn _)
left-fst≡right-fst zero i j z = helper _ (z ⌣ₖ ∣ base ∣) (sym (⌣ₖ-0ₖ _ _ z)) i j
left-fst≡right-fst (suc n) i j z = helper _ (z ⌣ₖ ∣ north ∣) (sym (⌣ₖ-0ₖ _ (suc (suc n)) z)) i j
main : (a b : S₊ (suc n)) →
⌣ₖ-distrFun (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ ≡
⌣ₖ-distrFun2 (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ
main =
wedgeconFun n n
(λ x y → subst (λ l → isOfHLevel l ((⌣ₖ-distrFun (suc n) (suc m) ∣ x ∣ ∣ y ∣)
≡ ⌣ₖ-distrFun2 (suc n) (suc m) ∣ x ∣ ∣ y ∣))
(+-suc n (suc n))
(isOfHLevelPlus {n = 2 + n} n (hLevHelp n m ∣ x ∣ ∣ y ∣)))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (left-fst n x))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (right-fst n x))
(cong (→∙Homogeneous≡ (isHomogeneousKn _)) (sym (left-fst≡right-fst n)))
-- Distributivity for 0 dimensional cases
leftDistr₀n : (n : ℕ) → (z : coHomK 0) (x y : coHomK n)
→ z ·₀ (x +[ n ]ₖ y) ≡ z ·₀ x +[ n ]ₖ (z ·₀ y)
leftDistr₀n n (pos zero) x y = sym (rUnitₖ n (0ₖ _))
leftDistr₀n n (pos (suc z)) x y =
cong ((x +ₖ y) +ₖ_) (leftDistr₀n n (pos z) x y)
∙∙ sym (assocₖ n x y (pos z ·₀ x +[ n ]ₖ (pos z ·₀ y)))
∙∙ cong (x +ₖ_) (assocₖ n y (pos z ·₀ x) (pos z ·₀ y)
∙∙ cong (_+ₖ (pos z ·₀ y)) (commₖ n y (pos z ·₀ x))
∙∙ sym (assocₖ n (pos z ·₀ x) y (pos z ·₀ y)))
∙ assocₖ n x _ _
leftDistr₀n n (negsuc zero) x y = -distrₖ n x y
leftDistr₀n n (negsuc (suc z)) x y =
cong₂ (_+ₖ_) (leftDistr₀n n (negsuc z) x y) (-distrₖ n x y)
∙∙ assocₖ n ((negsuc z ·₀ x) +ₖ (negsuc z ·₀ y)) (-ₖ x) (-ₖ y)
∙∙ cong (_-ₖ y) (sym (assocₖ n (negsuc z ·₀ x) (negsuc z ·₀ y) (-ₖ x))
∙∙ cong ((negsuc z ·₀ x) +ₖ_) (commₖ n (negsuc z ·₀ y) (-ₖ x))
∙∙ assocₖ n (negsuc z ·₀ x) (-ₖ x) (negsuc z ·₀ y))
∙ sym (assocₖ n (negsuc (suc z) ·₀ x) _ _)
leftDistrn₀ : (n : ℕ) → (z : coHomK n) (x y : coHomK 0)
→ (x ℤ+ y) ·₀ z ≡ x ·₀ z +[ n ]ₖ (y ·₀ z)
leftDistrn₀ n z x (pos zero) = sym (rUnitₖ n (x ·₀ z))
leftDistrn₀ n z x (pos (suc y)) =
lem (x +pos y)
∙∙ cong (z +ₖ_) (leftDistrn₀ n z x (pos y) ∙ commₖ n _ _)
∙∙ assocₖ n z _ _
∙ commₖ n _ _
where
lem : (a : ℤ) → (sucℤ a) ·₀ z ≡ z +ₖ (a ·₀ z)
lem (pos zero) = refl
lem (pos (suc a)) = cong (z +ₖ_) (lem (pos a))
lem (negsuc zero) = sym (rCancelₖ n z)
lem (negsuc (suc a)) = sym (-cancelLₖ n z (negsuc a ·₀ z)) ∙ sym (assocₖ n z (negsuc a ·₀ z) (-ₖ z))
leftDistrn₀ n z x (negsuc y) = main y
where
help : (x : ℤ) → predℤ x ·₀ z ≡ (x ·₀ z -ₖ z)
help (pos zero) = sym (lUnitₖ n (-ₖ z))
help (pos (suc x)) = sym (-cancelLₖ n z (pos x ·₀ z))
help (negsuc x) = refl
main : (y : _) → (x ℤ+ negsuc y) ·₀ z ≡ (x ·₀ z) +ₖ (negsuc y ·₀ z)
main zero = help x
main (suc y) =
help (x +negsuc y)
∙∙ cong (_-ₖ z) (main y)
∙∙ sym (assocₖ n _ _ _)
leftDistr-⌣ₖ : (n m : ℕ) (z : coHomK n) (x y : coHomK m)
→ z ⌣ₖ (x +ₖ y) ≡ (z ⌣ₖ x +ₖ z ⌣ₖ y)
leftDistr-⌣ₖ zero m z x y = leftDistr₀n m z x y
leftDistr-⌣ₖ (suc n) zero z x y = leftDistrn₀ (suc n) z x y
leftDistr-⌣ₖ (suc n) (suc m) z x y = funExt⁻ (cong fst (leftDistr-⌣ₖ· m n x y)) z
-- Right distributivity
private
⌣ₖ-distrFun-r : -- (x +ₖ y) ⌣ₖ z
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (n +' m)
fst (⌣ₖ-distrFun-r n m x y) z =
(x +ₖ y) ⌣ₖ z
snd (⌣ₖ-distrFun-r n m x y) =
⌣ₖ-0ₖ n m (x +ₖ y) -- ⌣ₖ-0ₖ m n (x +ₖ y)
⌣ₖ-distrFun2-r :
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (n +' m)
fst (⌣ₖ-distrFun2-r n m x y) z =
x ⌣ₖ z +ₖ y ⌣ₖ z
snd (⌣ₖ-distrFun2-r n m x y) =
cong₂ _+ₖ_ (⌣ₖ-0ₖ n m x) (⌣ₖ-0ₖ n m y) ∙ rUnitₖ _ _
rightDistr-⌣ₖ· : (n m : ℕ) (x y : coHomK (suc n))
→ ⌣ₖ-distrFun-r (suc n) (suc m) x y ≡ ⌣ₖ-distrFun2-r (suc n) (suc m) x y
rightDistr-⌣ₖ· n m =
T.elim2 (λ _ _ → isOfHLevelPath (3 + n) (isOfHLevel↑∙ (suc n) m) _ _)
main
where
fst-left : (n : ℕ) (y : S₊ (suc n)) →
fst (⌣ₖ-distrFun-r (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ y ∣) ≡
fst (⌣ₖ-distrFun2-r (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ y ∣)
fst-left n y =
funExt (λ z
→ cong (_⌣ₖ z) (lUnitₖ _ ∣ y ∣)
∙∙ sym (lUnitₖ _ (∣ y ∣ ⌣ₖ z))
∙∙ cong (_+ₖ (∣ y ∣ ⌣ₖ z)) (sym (0ₖ-⌣ₖ _ _ z)))
fst-right : (n : ℕ) (x : S₊ (suc n)) →
fst (⌣ₖ-distrFun-r (suc n) (suc m) ∣ x ∣ ∣ ptSn (suc n) ∣) ≡
fst (⌣ₖ-distrFun2-r (suc n) (suc m) ∣ x ∣ ∣ ptSn (suc n) ∣)
fst-right n x =
funExt λ z
→ cong (_⌣ₖ z) (rUnitₖ _ ∣ x ∣)
∙∙ sym (rUnitₖ _ _)
∙∙ cong (∣ x ∣ ⌣ₖ z +ₖ_) (sym (0ₖ-⌣ₖ _ _ z))
left≡right : (n : ℕ) → fst-left n (ptSn (suc n)) ≡ fst-right n (ptSn (suc n))
left≡right zero = refl
left≡right (suc n) = refl
main : (a b : S₊ (suc n)) →
⌣ₖ-distrFun-r (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ ≡
⌣ₖ-distrFun2-r (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ
main =
wedgeconFun n n
(λ x y → subst (λ l → isOfHLevel l ((⌣ₖ-distrFun-r (suc n) (suc m) ∣ x ∣ ∣ y ∣)
≡ ⌣ₖ-distrFun2-r (suc n) (suc m) ∣ x ∣ ∣ y ∣))
(+-suc n (suc n))
(isOfHLevelPlus {n = 2 + n} n (isOfHLevel↑∙ (suc n) m _ _)))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (fst-left n x))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (fst-right n x))
(cong (→∙Homogeneous≡ (isHomogeneousKn _)) (sym (left≡right n)))
rightDistr-⌣ₖ : (n m : ℕ) (x y : coHomK n) (z : coHomK m)
→ (x +ₖ y) ⌣ₖ z ≡ (x ⌣ₖ z +ₖ y ⌣ₖ z)
rightDistr-⌣ₖ zero zero x y z =
comm-·₀ (x ℤ+ y) z
∙∙ leftDistr-⌣ₖ zero zero z x y
∙∙ cong₂ _+ₖ_ (sym (comm-·₀ x z)) (sym (comm-·₀ y z))
rightDistr-⌣ₖ zero (suc m) x y z = leftDistr-⌣ₖ _ zero z x y
rightDistr-⌣ₖ (suc n) zero x y z = leftDistr-⌣ₖ zero (suc n) z x y
rightDistr-⌣ₖ (suc n) (suc m) x y z = (funExt⁻ (cong fst (rightDistr-⌣ₖ· n m x y))) z
-- Associativity
private
-- We need to give the two associators as (doubly) pointed functions
assocer : (n m k : ℕ) → coHomK (suc n)
→ coHomK-ptd (suc m)
→∙ (coHomK-ptd (suc k)
→∙ coHomK-ptd ((suc n) +' ((suc m) +' (suc k))) ∙)
fst (fst (assocer n m k x) y) z = x ⌣ₖ (y ⌣ₖ z)
snd (fst (assocer n m k x) y) = cong (x ⌣ₖ_) (⌣ₖ-0ₖ _ (suc k) y) ∙ ⌣ₖ-0ₖ _ _ x
snd (assocer n m k x) =
ΣPathP (funExt (λ z → cong (x ⌣ₖ_) (0ₖ-⌣ₖ (suc m) (suc k) z) ∙ ⌣ₖ-0ₖ (suc n) _ x)
, help)
where
h : (n m k : ℕ) (x : coHomK (suc n)) → cong (_⌣ₖ_ x) (⌣ₖ-0ₖ (suc m) (suc k) (0ₖ _)) ≡
(λ i → x ⌣ₖ 0ₖ-⌣ₖ (suc m) (suc k) (0ₖ _) i)
h zero zero k x = refl
h zero (suc m) k x = refl
h (suc n) zero k x = refl
h (suc n) (suc m) k x = refl
help : PathP (λ i → (cong (x ⌣ₖ_) (0ₖ-⌣ₖ (suc m) (suc k) (0ₖ _)) ∙ ⌣ₖ-0ₖ (suc n) _ x) i ≡ 0ₖ _)
(cong (x ⌣ₖ_) (⌣ₖ-0ₖ (suc m) (suc k) (0ₖ _)) ∙ ⌣ₖ-0ₖ (suc n) _ x) refl
help = compPathR→PathP
(cong (_∙ ⌣ₖ-0ₖ (suc n) ((suc m) +' (suc k)) x) (h n m k x)
∙∙ rUnit _
∙∙ cong ((cong (x ⌣ₖ_) (0ₖ-⌣ₖ (suc m) (suc k) (0ₖ _)) ∙ ⌣ₖ-0ₖ (suc n) _ x) ∙_) (rUnit refl))
assoc2-sub : (n m k : ℕ) → _ → _
assoc2-sub n m k = subst coHomK (sym (+'-assoc n m k))
assoc2-sub-0 : (n m k : ℕ) → assoc2-sub n m k (0ₖ _) ≡ 0ₖ _
assoc2-sub-0 zero zero zero = refl
assoc2-sub-0 zero zero (suc zero) = refl
assoc2-sub-0 zero zero (suc (suc k)) = refl
assoc2-sub-0 zero (suc zero) zero = refl
assoc2-sub-0 zero (suc zero) (suc k) = refl
assoc2-sub-0 zero (suc (suc m)) zero = refl
assoc2-sub-0 zero (suc (suc m)) (suc k) = refl
assoc2-sub-0 (suc zero) zero zero = refl
assoc2-sub-0 (suc zero) zero (suc k) = refl
assoc2-sub-0 (suc (suc n)) zero zero = refl
assoc2-sub-0 (suc (suc n)) zero (suc k) = refl
assoc2-sub-0 (suc zero) (suc m) zero = refl
assoc2-sub-0 (suc (suc n)) (suc m) zero = refl
assoc2-sub-0 (suc zero) (suc m) (suc k) = refl
assoc2-sub-0 (suc (suc n)) (suc m) (suc k) = refl
assocer2 : (n m k : ℕ)
→ coHomK (suc n)
→ coHomK-ptd (suc m) →∙ (coHomK-ptd (suc k) →∙ coHomK-ptd ((suc n) +' ((suc m) +' (suc k))) ∙)
fst (fst (assocer2 n m k x) y) z =
subst coHomK (sym (+'-assoc (suc n) (suc m) (suc k))) ((x ⌣ₖ y) ⌣ₖ z) --
snd (fst (assocer2 zero m k x) y) =
cong (subst coHomK (sym (+'-assoc 1 (suc m) (suc k)))) (⌣ₖ-0ₖ _ _ (x ⌣ₖ y))
snd (fst (assocer2 (suc n) m k x) y) =
cong (subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k)))) (⌣ₖ-0ₖ _ _ (x ⌣ₖ y))
fst (snd (assocer2 zero m k x) i) z =
subst coHomK (sym (+'-assoc (suc zero) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ x i ⌣ₖ z)
snd (snd (assocer2 zero m k x) i) j =
subst coHomK (sym (+'-assoc (suc zero) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ (⌣ₖ-0ₖ _ _ x i) j)
fst (snd (assocer2 (suc n) m k x) i) z =
subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ x i ⌣ₖ z)
snd (snd (assocer2 (suc n) m k x) i) j =
subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ (⌣ₖ-0ₖ _ _ x i) j)
assocer-helpFun : (n m : ℕ) → coHomK (suc n) → coHomK-ptd (suc m) →∙ Ω (coHomK-ptd (3 + (n + m)))
fst (assocer-helpFun n m a) b = Kn→ΩKn+1 _ (a ⌣ₖ b)
snd (assocer-helpFun n m a) = cong (Kn→ΩKn+1 _) (⌣ₖ-0ₖ (suc n) (suc m) a) ∙ Kn→ΩKn+10ₖ _
assocer-helpFun2 : (n m : ℕ) → coHomK (suc n) → coHomK-ptd (suc m) →∙ Ω (coHomK-ptd (3 + (n + m)))
fst (assocer-helpFun2 n m a) b i = (Kn→ΩKn+1 _ a i) ⌣ₖ b
snd (assocer-helpFun2 n m a) i j = ⌣ₖ-0ₖ _ (suc m) (Kn→ΩKn+1 _ a j) i
-- Key lemma for associativity
assocer-helpFun≡ : (n m : ℕ) → (x : coHomK (suc n)) → assocer-helpFun n m x ≡ assocer-helpFun2 n m x
assocer-helpFun≡ n m =
T.elim (λ _ → isOfHLevelPath (3 + n) (hLev-assocer-helpFun n m) _ _)
λ a → →∙Homogeneous≡ (subst isHomogeneous Kn≃ΩKn+1∙ (isHomogeneousKn _))
(funExt (main n a))
where
hLev-assocer-helpFun : (n m : ℕ) → isOfHLevel (3 + n) (coHomK-ptd (suc m) →∙ Ω (coHomK-ptd (3 + (n + m))))
hLev-assocer-helpFun n m =
subst (isOfHLevel (3 + n)) (cong (coHomK-ptd (suc m) →∙_)
(Kn≃ΩKn+1∙))
(isOfHLevel↑∙ (suc n) m)
main : (n : ℕ) (a : S₊ (suc n)) (b : _)
→ fst (assocer-helpFun n m ∣ a ∣) b ≡ fst (assocer-helpFun2 n m ∣ a ∣) b
main zero a b k i =
hcomp
(λ r → λ {(i = i0) → 0ₖ _
; (i = i1) → ∣ rCancel (merid north) r (~ k) ∣
; (k = i0) → Kn→ΩKn+1 _ (∣ a ∣ ⌣ₖ b) i
; (k = i1) → (Kn→ΩKn+1 _ ∣ a ∣ i) ⌣ₖ b})
(∣ compPath-filler (merid a) (sym (merid base)) k i ∣ ⌣ₖ b)
main (suc n) a b k i =
hcomp
(λ r → λ {(i = i0) → 0ₖ _
; (i = i1) → ∣ rCancel (merid north) r (~ k) ∣
; (k = i0) → Kn→ΩKn+1 _ (∣ a ∣ ⌣ₖ b) i
; (k = i1) → (Kn→ΩKn+1 _ ∣ a ∣ i) ⌣ₖ b})
(∣ compPath-filler (merid a) (sym (merid north)) k i ∣ ⌣ₖ b)
assoc-helper : (n m : ℕ) (x : coHomK (suc n)) (y : coHomK (suc m))
→ Kn→ΩKn+1 _ (x ⌣ₖ y) ≡ λ i → (Kn→ΩKn+1 _ x i) ⌣ₖ y
assoc-helper n m x y = funExt⁻ (cong fst (assocer-helpFun≡ n m x)) y
assoc-⌣ₖ· : (n m k : ℕ) → (x : coHomK (suc n)) → assocer n m k x ≡ assocer2 n m k x
assoc-⌣ₖ· n m k =
T.elim (λ _ → isOfHLevelPath (3 + n)
(transport (λ i → isOfHLevel (3 + n)
(coHomK-ptd (suc m) →∙ (coHomK-ptd (suc k) →∙ coHomK-ptd (h (~ i)) ∙)))
(isOfHLevel↑∙∙ m k (suc n))) _ _)
λ a → →∙Homogeneous≡ (isHomogeneous→∙ (isHomogeneousKn _))
(funExt λ b → →∙Homogeneous≡ (isHomogeneousKn _)
(funExt (main n m k a b)))
where
h : (suc n) +' ((suc m) +' (suc k)) ≡ suc (suc (suc n + m + k))
h = cong (2 +_) (+-suc n (m + k)) ∙ λ i → suc (suc (suc (+-assoc n m k i)))
main : (n m k : ℕ) (a : S₊ (suc n)) (b : coHomK (suc m)) (c : coHomK (suc k))
→ ∣ a ∣ ⌣ₖ b ⌣ₖ c ≡
(subst coHomK (λ i → +'-assoc (suc n) (suc m) (suc k) (~ i))
((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
main zero m k a b c = goal a ∙ sym (funExt⁻ t ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
where
t : subst coHomK (λ i → +'-assoc 1 (suc m) (suc k) (~ i)) ≡ idfun _
t = cong (subst coHomK) (isSetℕ _ _ (+'-assoc 1 (suc m) (suc k)) refl) ∙ funExt transportRefl
goal : (a : _) → ∣ a ∣ ⌣ₖ b ⌣ₖ c ≡ (∣ a ∣ ⌣ₖ b) ⌣ₖ c
goal base = refl
goal (loop i) j = assoc-helper m k b c j i
main (suc n) m k north b c = refl
main (suc n) m k south b c = refl
main (suc n) m k (merid a i) b c j = help2 j i
where
transpLem : (n m : ℕ) (p : n ≡ m) → subst coHomK p (0ₖ _) ≡ 0ₖ _
transpLem zero m = J (λ m p → subst coHomK p (0ₖ _) ≡ 0ₖ _) refl
transpLem (suc zero) m = J (λ m p → subst coHomK p (0ₖ _) ≡ 0ₖ _) refl
transpLem (suc (suc n)) m = J (λ m p → subst coHomK p (0ₖ _) ≡ 0ₖ _) refl
transpLem-refl : transpLem (suc (suc (suc (suc (n + m + k)))))
(suc (suc n +' (suc m +' suc k)))
(λ i₃ → +'-assoc (2 + n) (suc m) (suc k) (~ i₃)) ≡ refl
transpLem-refl = transportRefl refl
moveTransports : (n m : ℕ) (x : coHomK n) (p : n ≡ m) (q : (suc n) ≡ suc m)
→ PathP (λ i → transpLem _ _ q (~ i) ≡ transpLem _ _ q (~ i))
(Kn→ΩKn+1 _ (subst coHomK p x))
(cong (subst coHomK q) (Kn→ΩKn+1 _ x))
moveTransports n m x =
J (λ m p → (q : (suc n) ≡ suc m)
→ PathP (λ i → transpLem _ _ q (~ i) ≡ transpLem _ _ q (~ i))
(Kn→ΩKn+1 _ (subst coHomK p x))
(cong (subst coHomK q) (Kn→ΩKn+1 _ x)))
λ q → transport (λ j → PathP (λ i → transpLem (suc n) (suc n) (isSetℕ _ _ refl q j) (~ i)
≡ transpLem (suc n) (suc n) (isSetℕ _ _ refl q j) (~ i))
(Kn→ΩKn+1 _ (subst coHomK refl x))
(cong (subst coHomK (isSetℕ _ _ refl q j)) (Kn→ΩKn+1 _ x)))
(h2 n x)
where
h2 : (n : ℕ) (x : _)
→ PathP (λ i₁ →
transpLem (suc n) (suc n) (λ _ → suc n) (~ i₁) ≡
transpLem (suc n) (suc n) (λ _ → suc n) (~ i₁))
(Kn→ΩKn+1 n (subst coHomK (λ _ → n) x))
(λ i₁ → subst coHomK (λ _ → suc n) (Kn→ΩKn+1 n x i₁))
h2 zero x k i =
hcomp (λ j → λ {(i = i0) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (i = i1) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (k = i0) → Kn→ΩKn+1 _ (transportRefl x j) i
; (k = i1) → transportRefl (Kn→ΩKn+1 _ x i) (~ j)})
(Kn→ΩKn+1 _ x i)
h2 (suc n) x k i =
hcomp (λ j → λ {(i = i0) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (i = i1) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (k = i0) → Kn→ΩKn+1 _ (transport refl x) i
; (k = i1) → transportRefl (Kn→ΩKn+1 _ x i) (~ j)})
(Kn→ΩKn+1 _ (transportRefl x k) i)
finalTransp : (n : ℕ) (a : _) → Kn→ΩKn+1 _ (subst coHomK (λ i₁ → +'-assoc (suc n) (suc m) (suc k) (~ i₁)) ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
≡ cong (subst coHomK (λ i₁ → +'-assoc (2 + n) (suc m) (suc k) (~ i₁))) (Kn→ΩKn+1 _ ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
finalTransp n a =
rUnit _
∙∙ (λ i → (λ j → transpLem (suc (suc (suc (suc (n + m + k)))))
(suc (suc n +' (suc m +' suc k)))
(λ i₃ → +'-assoc (2 + n) (suc m) (suc k) (~ i₃)) (i ∧ j))
∙∙ moveTransports _ _ ((∣ a ∣ ⌣ₖ b) ⌣ₖ c)
(sym (+'-assoc (suc n) (suc m) (suc k)))
(sym (+'-assoc (2 + n) (suc m) (suc k))) i
∙∙ λ j → transpLem (suc (suc (suc (suc (n + m + k)))))
(suc (suc n +' (suc m +' suc k)))
(λ i₃ → +'-assoc (2 + n) (suc m) (suc k) (~ i₃)) (i ∧ ~ j))
∙∙ (λ i → transportRefl refl i
∙∙ cong (subst coHomK (λ i₁ → +'-assoc (2 + n) (suc m) (suc k) (~ i₁))) (Kn→ΩKn+1 _ ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
∙∙ transportRefl refl i)
∙ sym (rUnit _)
help2 : cong (λ x → (∣ x ∣) ⌣ₖ (b ⌣ₖ c)) (merid a) ≡ cong (assoc2-sub (2 + n) (suc m) (suc k)) (cong (λ x → (∣ x ∣ ⌣ₖ b) ⌣ₖ c) (merid a))
help2 = ((λ r → Kn→ΩKn+1 _ (main n m k a b c r)))
∙∙ finalTransp n a
∙∙ λ r i → subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k))) (assoc-helper _ _ (∣ a ∣ ⌣ₖ b) c r i)
-- Some key distributivity lemmas
-Distₗ : (n m : ℕ) (x : coHomK n) (y : coHomK m) → (-ₖ (x ⌣ₖ y)) ≡ (-ₖ x) ⌣ₖ y
-Distₗ n m x y =
sym (rUnitₖ _ (-ₖ (x ⌣ₖ y)))
∙∙ cong ((-ₖ (x ⌣ₖ y)) +ₖ_) (sym (rCancelₖ _ (x ⌣ₖ y)))
∙∙ assocₖ _ (-ₖ (x ⌣ₖ y)) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y))
∙∙ cong (_-ₖ (x ⌣ₖ y)) help
∙∙ sym (assocₖ _ ((-ₖ x) ⌣ₖ y) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y)))
∙∙ cong ((-ₖ x) ⌣ₖ y +ₖ_) (rCancelₖ _ (x ⌣ₖ y))
∙∙ rUnitₖ _ ((-ₖ x) ⌣ₖ y)
where
help : (-ₖ (x ⌣ₖ y)) +ₖ (x ⌣ₖ y) ≡ (-ₖ x) ⌣ₖ y +ₖ (x ⌣ₖ y)
help = lCancelₖ _ _
∙∙ sym (0ₖ-⌣ₖ _ _ y)
∙ cong (_⌣ₖ y) (sym (lCancelₖ _ x))
∙∙ rightDistr-⌣ₖ _ _ (-ₖ x) x y
-Distᵣ : (n m : ℕ) (x : coHomK n) (y : coHomK m) → (-ₖ (x ⌣ₖ y)) ≡ x ⌣ₖ (-ₖ y)
-Distᵣ n m x y =
sym (rUnitₖ _ (-ₖ (x ⌣ₖ y)))
∙∙ cong ((-ₖ (x ⌣ₖ y)) +ₖ_) (sym (rCancelₖ _ (x ⌣ₖ y)))
∙∙ assocₖ _ (-ₖ (x ⌣ₖ y)) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y))
∙∙ cong (_-ₖ (x ⌣ₖ y)) help
∙∙ sym (assocₖ _ (x ⌣ₖ (-ₖ y)) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y)))
∙∙ cong (x ⌣ₖ (-ₖ y) +ₖ_) (rCancelₖ _ (x ⌣ₖ y))
∙∙ rUnitₖ _ (x ⌣ₖ (-ₖ y))
where
help : (-ₖ (x ⌣ₖ y)) +ₖ (x ⌣ₖ y) ≡ x ⌣ₖ (-ₖ y) +ₖ (x ⌣ₖ y)
help = lCancelₖ _ _
∙∙ sym (⌣ₖ-0ₖ _ _ x)
∙∙ cong (x ⌣ₖ_) (sym (lCancelₖ _ y))
∙ leftDistr-⌣ₖ _ _ x (-ₖ y) y
assoc₀ : (m k : ℕ) (x : ℤ) (y : coHomK m) (z : coHomK k) → _⌣ₖ_{n = zero} x (y ⌣ₖ z) ≡ (_⌣ₖ_{n = zero} {m = m} x y) ⌣ₖ z
assoc₀ m k x y z = main x
where
h : subst coHomK (sym (+'-assoc zero m k)) ≡ idfun _
h = cong (subst coHomK) (isSetℕ _ _ _ refl) ∙ funExt transportRefl
mainPos : (x : ℕ) → _⌣ₖ_ {n = zero} (pos x) (y ⌣ₖ z) ≡ ((_⌣ₖ_ {n = zero} {m = m} (pos x) y) ⌣ₖ z)
mainPos zero = sym (0ₖ-⌣ₖ _ _ z) ∙ cong (_⌣ₖ z) (sym (0ₖ-⌣ₖ _ _ y))
mainPos (suc n) =
cong (y ⌣ₖ z +ₖ_) (mainPos n)
∙∙ sym (rightDistr-⌣ₖ _ _ y (_⌣ₖ_ {n = zero} {m = m} (pos n) y) z)
∙∙ (λ i → (y +ₖ (_⌣ₖ_ {n = zero} {m = m} (pos n) y)) ⌣ₖ z)
main : (x : ℤ) → x ⌣ₖ y ⌣ₖ z ≡ ((_⌣ₖ_ {n = zero} {m = m} x y) ⌣ₖ z)
main (pos n) = mainPos n
main (negsuc n) =
(λ i → _⌣ₖ_ {n = zero} (+ℤ-comm (negsuc n) 0 i) (y ⌣ₖ z))
∙∙ sym (-Distₗ zero _ (pos (suc n)) (y ⌣ₖ z))
∙ cong (-ₖ_) (mainPos (suc n))
∙∙ -Distₗ _ _ (pos (suc n) ⌣ₖ y) z
∙∙ cong (_⌣ₖ z) ((-Distₗ zero _ (pos (suc n)) y))
∙∙ λ i → (_⌣ₖ_ {n = zero} (+ℤ-comm (negsuc n) 0 (~ i)) y) ⌣ₖ z
assoc-⌣ₖ : (n m k : ℕ) (x : coHomK n) (y : coHomK m) (z : coHomK k)
→ x ⌣ₖ y ⌣ₖ z ≡ subst coHomK (sym (+'-assoc n m k)) ((x ⌣ₖ y) ⌣ₖ z)
assoc-⌣ₖ zero m k x y z = assoc₀ _ _ x y z ∙ sym (funExt⁻ h ((x ⌣ₖ y) ⌣ₖ z))
where
h : subst coHomK (sym (+'-assoc zero m k)) ≡ idfun _
h = cong (subst coHomK) (isSetℕ _ _ _ refl) ∙ funExt transportRefl
assoc-⌣ₖ (suc n) zero k x y z =
help y
∙∙ sym (transportRefl ((x ⌣ₖ y) ⌣ₖ z))
∙∙ λ i → transport (λ j → coHomK ((isSetℕ _ _ ((sym (+'-assoc (suc n) zero k))) refl (~ i) j)))
((_⌣ₖ_ {m = zero} x y) ⌣ₖ z)
where
helpPos : (y : ℕ) → x ⌣ₖ (_⌣ₖ_ {n = zero} (pos y) z) ≡
((_⌣ₖ_ {m = zero} x (pos y)) ⌣ₖ z)
helpPos zero =
(⌣ₖ-0ₖ _ _ x)
∙∙ (sym (0ₖ-⌣ₖ _ _ z))
∙∙ cong (_⌣ₖ z) (sym (⌣ₖ-0ₖ _ _ x))
helpPos (suc y) =
leftDistr-⌣ₖ _ _ x z (_⌣ₖ_{n = zero} (pos y) z)
∙∙ cong ((x ⌣ₖ z) +ₖ_) (helpPos y)
∙∙ sym (rightDistr-⌣ₖ _ _ x (_⌣ₖ_{n = zero} (pos y) x) z)
help : (y : ℤ) → x ⌣ₖ (_⌣ₖ_ {n = zero} y z) ≡
((_⌣ₖ_ {m = zero} x y) ⌣ₖ z)
help (pos n) = helpPos n
help (negsuc n) =
(λ i → x ⌣ₖ (_⌣ₖ_ {n = zero} (+ℤ-comm (negsuc n) 0 i) z))
∙∙ cong (x ⌣ₖ_) (sym (-Distₗ zero _ (pos (suc n)) z))
∙∙ sym (-Distᵣ _ _ x _)
∙∙ cong -ₖ_ (helpPos (suc n))
∙∙ -Distₗ _ _ _ z
∙∙ cong (_⌣ₖ z) (-Distᵣ _ zero x (pos (suc n)))
∙∙ λ i → (_⌣ₖ_ {m = zero} x (+ℤ-comm (negsuc n) 0 (~ i))) ⌣ₖ z
assoc-⌣ₖ (suc n) (suc m) zero x y z =
(assoc-⌣ₖ (suc n) zero (suc m) x z y)
∙∙ cong (subst coHomK (sym (+'-assoc (suc n) zero (suc m))))
(sym (assoc₀ _ _ z x y))
∙∙ (funExt⁻ (sym h) (_⌣ₖ_ {n = zero} z (x ⌣ₖ y)))
where
h : subst coHomK (sym (+'-assoc (suc n) (suc m) zero))
≡ subst coHomK (λ i → +'-assoc (suc n) zero (suc m) (~ i))
h = cong (subst coHomK) (isSetℕ _ _ _ _)
assoc-⌣ₖ (suc n) (suc m) (suc k) x y z =
funExt⁻ (cong fst (funExt⁻ (cong fst (assoc-⌣ₖ· n m k x)) y)) z
-- Ring laws for ⌣
module _ {A : Type ℓ} (n m : ℕ) where
⌣-0ₕ : (f : coHom n A) → (f ⌣ 0ₕ m) ≡ 0ₕ _
⌣-0ₕ = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → ⌣ₖ-0ₖ n m (f x))
0ₕ-⌣ : (f : coHom m A) → (0ₕ n ⌣ f) ≡ 0ₕ _
0ₕ-⌣ = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → 0ₖ-⌣ₖ n m (f x))
leftDistr-⌣ : (f : coHom n A) (g h : coHom m A)
→ f ⌣ (g +ₕ h) ≡ f ⌣ g +ₕ f ⌣ h
leftDistr-⌣ =
ST.elim (λ _ → isSetΠ2 λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → ST.elim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ g h → cong ∣_∣₂ (funExt λ x → leftDistr-⌣ₖ n m (f x) (g x) (h x))
rightDistr-⌣ : (g h : coHom n A) (f : coHom m A) → (g +ₕ h) ⌣ f ≡ g ⌣ f +ₕ h ⌣ f
rightDistr-⌣ =
ST.elim2 (λ _ _ → isSetΠ (λ _ → isOfHLevelPath 2 squash₂ _ _))
λ g h → ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → rightDistr-⌣ₖ n m (g x) (h x) (f x))
assoc-⌣ : (l : ℕ) (f : coHom n A) (g : coHom m A) (h : coHom l A)
→ f ⌣ g ⌣ h ≡ subst (λ x → coHom x A) (sym (+'-assoc n m l)) ((f ⌣ g) ⌣ h)
assoc-⌣ l =
ST.elim (λ _ → isSetΠ2 λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → ST.elim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 squash₂ _ _)
λ g → ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _) λ h →
cong ∣_∣₂ ((funExt (λ x → assoc-⌣ₖ n m l (f x) (g x) (h x)
∙ cong (subst coHomK (sym (+'-assoc n m l)))
λ i → (f (transportRefl x (~ i)) ⌣ₖ g (transportRefl x (~ i)))
⌣ₖ (h (transportRefl x (~ i))))))
-- Additive unit(s)
0⌣ : ∀ {ℓ} {A : Type ℓ} (n m : ℕ) (x : coHom n A)
→ x ⌣ (0ₕ m) ≡ 0ₕ _
0⌣ n m = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → ⌣ₖ-0ₖ n m (f x))
⌣0 : ∀ {ℓ} {A : Type ℓ} (n m : ℕ) (x : coHom n A)
→ (0ₕ m) ⌣ x ≡ 0ₕ _
⌣0 n m = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → 0ₖ-⌣ₖ m n (f x))
-- Multiplicative unit
1⌣ : ∀ {ℓ} {A : Type ℓ} → coHom 0 A
1⌣ = ∣ (λ _ → 1) ∣₂
lUnit⌣ₖ : (n : ℕ) (x : coHomK n) → _⌣ₖ_ {n = 0} (pos 1) x ≡ x
lUnit⌣ₖ zero = λ _ → refl
lUnit⌣ₖ (suc n) x = rUnitₖ _ x
lUnit⌣ : ∀ {ℓ} {A : Type ℓ} (n : ℕ) (x : coHom n A)
→ x ⌣ 1⌣ ≡ subst (λ n → coHom n A) (sym (+'-rid n)) x
lUnit⌣ zero = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt (λ x → comm-·₀ (f x) (pos 1))) ∙ sym (transportRefl ∣ f ∣₂)
lUnit⌣ (suc n) =
ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt (λ x → cong (f x +ₖ_) (0ₖ-⌣ₖ zero _ (f x)) ∙ rUnitₖ _ (f x)))
∙ sym (transportRefl ∣ f ∣₂)
rUnit⌣ : ∀ {ℓ} {A : Type ℓ} (n : ℕ) (x : coHom n A)
→ 1⌣ ⌣ x ≡ x
rUnit⌣ zero = ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → refl
rUnit⌣ (suc n) =
ST.elim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → rUnitₖ _ (f x))
-ₕDistᵣ : ∀ {ℓ} {A : Type ℓ} (n m : ℕ)
(x : coHom n A) (y : coHom m A) → (-ₕ (x ⌣ y)) ≡ x ⌣ (-ₕ y)
-ₕDistᵣ n m =
ST.elim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f g → cong ∣_∣₂ (funExt λ x → -Distᵣ n m (f x) (g x))
-ₕDistₗ : ∀ {ℓ} {A : Type ℓ} (n m : ℕ)
(x : coHom n A) (y : coHom m A) → (-ₕ (x ⌣ y)) ≡ (-ₕ x) ⌣ y
-ₕDistₗ n m =
ST.elim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f g → cong ∣_∣₂ (funExt λ x → -Distₗ n m (f x) (g x))
-ₕDistₗᵣ : ∀ {ℓ} {A : Type ℓ} (n m : ℕ)
(x : coHom n A) (y : coHom m A) → (-ₕ x) ⌣ (-ₕ y) ≡ x ⌣ y
-ₕDistₗᵣ n m x y =
sym (-ₕDistₗ n m x (-ₕ y))
∙∙ cong -ₕ_ (sym (-ₕDistᵣ n m x y))
∙∙ ST.elim2 {C = λ x y → (-ₕ (-ₕ (x ⌣ y))) ≡ x ⌣ y}
(λ _ _ → isSetPathImplicit)
(λ f g → cong ∣_∣₂ (funExt λ _ → -ₖ^2 _)) x y
| 43.495588
| 143
| 0.479156
|
319b5160941f08a0daf129896412ac392349b0a5
| 256
|
agda
|
Agda
|
archive/agda-1/Foundation/Primitive.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
archive/agda-1/Foundation/Primitive.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | 1
|
2019-04-29T00:35:04.000Z
|
2019-05-11T23:33:04.000Z
|
archive/agda-1/Foundation/Primitive.agda
|
m0davis/oscar
|
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
|
[
"RSA-MD"
] | null | null | null |
module Foundation.Primitive where
open import Agda.Primitive
infix -65536 ℞_
℞_ : ∀ ℓ → Set _
℞_ ℓ = Set ℓ
⟰ : Level → Level
⟰ = lsuc
infix -65536 ℞₁_
℞₁_ : ∀ ℓ → Set _
℞₁_ ℓ = ℞ ⟰ ℓ
𝟘 : Level
𝟘 = lzero
open import Agda.Primitive using (_⊔_) public
| 12.190476
| 45
| 0.628906
|
0ef9241cac1dfc31468ddf49de11acb4d652493c
| 973
|
agda
|
Agda
|
test/Succeed/Issue826-2.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue826-2.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/Issue826-2.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
module Issue826-2 where
open import Common.Coinduction
data _≡_ {A : Set} (x y : A) : Set where
data D : Set where
c : ∞ D → D
delay : D → ∞ D
delay x = ♯ x
data P : D → Set where
o : (x : ∞ D) → P (♭ x) → P (c x)
postulate
h : (x : D) → P x → P x
f : (x : D) → P (c (delay x)) → P x
f x (o .(delay x) p) = h x p
g : (x : D) → P x → P (c (delay x))
g x p = h (c (delay x)) (o (delay x) p)
postulate
bar : (x : ∞ D) (p : P (♭ x)) →
h (c x) (o x (h (♭ x) p)) ≡ o x p
foo : (x : D) (p : P (c (delay x))) → g x (f x p) ≡ p
foo x (o .(delay x) p) = goal
where
x′ = _
goal : _ ≡ o x′ p
goal = bar x′ p
-- The following error message seems to indicate that an expression is
-- not forced properly:
--
-- Bug.agda:30,26-30
-- ♭ (.Bug.♯-0 x) != x of type D
-- when checking that the expression goal has type
-- g x (f x (o (.Bug.♯-0 x) p)) ≡ o (.Bug.♯-0 x) p
--
-- Thus it seems as if this problem affects plain type-checking as
-- well.
| 20.702128
| 70
| 0.509764
|
d0daef1cf43cec50a44d4916e8163af0f444bb1a
| 520
|
agda
|
Agda
|
Agda/subrings.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 333
|
2018-09-26T08:33:30.000Z
|
2022-03-22T23:50:15.000Z
|
Agda/subrings.agda
|
UlrikBuchholtz/HoTT-Intro
|
1e1f8def50f9359928e52ebb2ee53ed1166487d9
|
[
"CC-BY-4.0"
] | 8
|
2019-06-18T04:16:04.000Z
|
2020-10-16T15:27:01.000Z
|
Agda/subrings.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 #-}
module subrings where
import rings
open rings public
--------------------------------------------------------------------------------
{- Subrings -}
subset-Ring :
(l : Level) {l1 : Level} → Ring l1 → UU ((lsuc l) ⊔ l1)
subset-Ring l R = type-Ring R → UU-Prop l
is-additive-subset-Ring :
{l l1 : Level} (R : Ring l1) (S : subset-Ring l R) → UU _
is-additive-subset-Ring R S =
(x y : type-Ring R) →
type-Prop (S x) → type-Prop (S y) → type-Prop (S (add-Ring R x y))
| 24.761905
| 80
| 0.513462
|
3de5919dcb02720d3ef7d172e70d92b665f47b95
| 1,965
|
agda
|
Agda
|
src/Nat/Class.agda
|
iblech/agda-quotients
|
1b51e83acf193a556a61d44a4585a6467a383fa3
|
[
"MIT"
] | 1
|
2021-04-29T13:10:27.000Z
|
2021-04-29T13:10:27.000Z
|
src/Nat/Class.agda
|
iblech/agda-quotients
|
1b51e83acf193a556a61d44a4585a6467a383fa3
|
[
"MIT"
] | null | null | null |
src/Nat/Class.agda
|
iblech/agda-quotients
|
1b51e83acf193a556a61d44a4585a6467a383fa3
|
[
"MIT"
] | 1
|
2021-04-28T12:49:47.000Z
|
2021-04-28T12:49:47.000Z
|
module Nat.Class where
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
record Nat (ℕ : Set) : Set₁ where
field
zero : ℕ
succ : ℕ → ℕ
ind : (P : ℕ → Set) → P zero → (∀ {k} → P k → P (succ k)) → ∀ n → P n
_+_ : ℕ → ℕ → ℕ
+-zero : ∀ {n} → zero + n ≡ n
+-succ : ∀ {m n} → succ m + n ≡ m + succ n
module _ {ℕ : Set} {{nn : Nat ℕ}} where
open Nat nn
+-succˡ : {m n : ℕ} → succ m + n ≡ succ (m + n)
+-succˡ {m} {n} = ind Succˡ Succˡ-zero Succˡ-succ m n
where
Succˡ : ℕ → Set
Succˡ m′ = ∀ n′ → succ m′ + n′ ≡ succ (m′ + n′)
Succˡ-zero : Succˡ zero
Succˡ-zero n′ =
begin
succ zero + n′
≡⟨ +-succ ⟩
zero + succ n′
≡⟨ +-zero ⟩
succ n′
≡⟨ cong succ (sym +-zero) ⟩
succ (zero + n′)
∎
Succˡ-succ : ∀ {m′} → Succˡ m′ → Succˡ (succ m′)
Succˡ-succ {m′} ih n′ =
begin
succ (succ m′) + n′
≡⟨ +-succ ⟩
succ m′ + succ n′
≡⟨ ih (succ n′) ⟩
succ (m′ + succ n′)
≡⟨ cong succ (sym +-succ) ⟩
succ (succ m′ + n′)
∎
+-succʳ : {m n : ℕ} → m + succ n ≡ succ (m + n)
+-succʳ = trans (sym +-succ) +-succˡ
+-assoc : {m n p : ℕ} → (m + n) + p ≡ m + (n + p)
+-assoc {m} {n} {p} = ind Assoc Assoc-zero Assoc-succ m
where
Assoc : ℕ → Set
Assoc k = (k + n) + p ≡ k + (n + p)
Assoc-zero : Assoc zero
Assoc-zero =
begin
(zero + n) + p
≡⟨ cong (_+ p) +-zero ⟩
n + p
≡⟨ sym +-zero ⟩
zero + (n + p)
∎
Assoc-succ : ∀ {k} → Assoc k → Assoc (succ k)
Assoc-succ {k} ih =
begin
(succ k + n) + p
≡⟨ cong (_+ p) +-succˡ ⟩
succ (k + n) + p
≡⟨ +-succˡ ⟩
succ ((k + n) + p)
≡⟨ cong succ ih ⟩
succ (k + (n + p))
≡⟨ sym +-succˡ ⟩
succ k + (n + p)
∎
| 23.963415
| 73
| 0.398982
|
2f201525dcde7a91c5b74009ca20c89911322162
| 4,930
|
agda
|
Agda
|
Soundness/agda/Soundness.agda
|
halfaya/Music
|
5d9a1bbfbe52f55acf33d960763dce0872689c2b
|
[
"MIT"
] | 1
|
2020-11-10T04:05:28.000Z
|
2020-11-10T04:05:28.000Z
|
Soundness/agda/Soundness.agda
|
halfaya/Music
|
5d9a1bbfbe52f55acf33d960763dce0872689c2b
|
[
"MIT"
] | null | null | null |
Soundness/agda/Soundness.agda
|
halfaya/Music
|
5d9a1bbfbe52f55acf33d960763dce0872689c2b
|
[
"MIT"
] | 1
|
2020-11-10T04:05:31.000Z
|
2020-11-10T04:05:31.000Z
|
{-# OPTIONS --without-K --erased-cubical --no-import-sorts #-}
module Soundness where
open import Prelude
open import Instruments
open import MakeTracks using (makeTrackList)
open import Motif using (motif; levels)
open import SUtil
----------------
macro
getDef : Name → Term → TC ⊤
getDef n h = do
d ← getDefinition n
t ← quoteTC d
unify h t
record Line : Type where
constructor line
field
lhs : List Name
rhs : List Name
open Line
Proof : Type
Proof = List Line
-- Get only visible constructor names
getNamesP : List (Arg Pattern) → List Name
getNamesP [] = []
getNamesP (arg (arg-info v m) (Pattern.dot t) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info v m) (Pattern.var x₁) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info v m) (Pattern.lit l) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info v m) (Pattern.proj f) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info v m) (Pattern.absurd x₁) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info hidden m) (Pattern.con n _) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info instance′ m) (Pattern.con n _) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info visible m) (Pattern.con n _) ∷ ps) = n ∷ getNamesP ps
{-# TERMINATING #-}
getNamesT : Term → List Name
getNamesAT : Arg Term → List Name
getNamesT (con n args) = n ∷ concatMap getNamesAT args
getNamesT (def n args) = n ∷ concatMap getNamesAT args
getNamesT (var x₁ args) = concatMap getNamesAT args
getNamesT (pat-lam cs args) = concatMap getNamesAT args
getNamesT (lam v t) = []
getNamesT (pi a b) = []
getNamesT (agda-sort s) = []
getNamesT (lit l) = []
getNamesT (meta x₁ x₂) = []
getNamesT unknown = []
getNamesAT (arg i t) = getNamesT t
getNamesC : Clause → Line
getNamesC (Clause.clause tel ps t) = line (getNamesP ps) (getNamesT t)
getNamesC (Clause.absurd-clause tel ps) = line (getNamesP ps) []
getNamesD : Definition → List Line
getNamesD (function cs) = map getNamesC cs
getNamesD (data-type pars cs) = []
getNamesD (record-type c fs) = []
getNamesD (data-cons d) = []
getNamesD axiom = []
getNamesD prim-fun = []
----------------
data TopLevel : Type where
s↑ : TopLevel
s↓ : TopLevel
sc↑ : TopLevel
sc↓ : TopLevel
sct↑ : TopLevel
sct↓ : TopLevel
topLevelName : TopLevel → Name
topLevelName s↑ = quote soundness~↑
topLevelName s↓ = quote soundness~↓
topLevelName sc↑ = quote soundnessConv↑
topLevelName sc↓ = quote soundnessConv↓
topLevelName sct↑ = quote soundnessConv↑Term
topLevelName sct↓ = quote soundnessConv↓Term
isTopLevel : Name → Maybe TopLevel
isTopLevel n =
if n == quote soundness~↑ then just s↑
else if n == quote soundness~↓ then just s↓
else if n == quote soundnessConv↑ then just sc↑
else if n == quote soundnessConv↓ then just sc↓
else if n == quote soundnessConv↑Term then just sct↑
else if n == quote soundnessConv↓Term then just sct↓
else nothing
topLevelDef : TopLevel → Definition
topLevelDef s↑ = getDef soundness~↑
topLevelDef s↓ = getDef soundness~↓
topLevelDef sc↑ = getDef soundnessConv↑
topLevelDef sc↓ = getDef soundnessConv↓
topLevelDef sct↑ = getDef soundnessConv↑Term
topLevelDef sct↓ = getDef soundnessConv↓Term
topLevelProof : TopLevel → Proof
topLevelProof = getNamesD ∘ topLevelDef
---------------
-- Number of tracks to create
tracks : ℕ
tracks = 4
{-# TERMINATING #-}
-- First argument n is current level (0 is bottom level; no recursive calls allowed)
-- Second argument m is exponent for doubling speed (2^m)
proof→notes : ℕ → ℕ → TopLevel → List (List Note)
line→notes : ℕ → ℕ → Line → List (List Note)
names→notes : ℕ → ℕ → List Name → List (List Note)
-- starts with proof name
proof→notes n m t =
zipFull (2ⁿSpeed m (motif (topLevelName t)) ∷ [])
(concatMap (line→notes n m) (topLevelProof t))
-- just use rhs for now
line→notes n m (line lhs rhs) = names→notes n m rhs
names→notes _ m [] = [] ∷ []
names→notes zero m ns@(_ ∷ _) = 2ⁿSpeed m (concatMap motif ns) ∷ []
names→notes (suc k) m (n ∷ ns) with isTopLevel n
... | just t = proof→notes k (suc m) t ++ names→notes (suc k) m ns
... | nothing = (2ⁿSpeed m (motif n) ∷ []) ++ names→notes (suc k) m ns
proof→notesTop : ℕ → TopLevel → List (List Note)
proof→notesTop level = proof→notes level 0
---------------
instruments : Vec InstrumentNumber-1 maxChannels
instruments =
drawbarOrgan ∷ -- 1
piano ∷ -- 2
electricPiano1 ∷ -- 3
churchOrgan ∷ -- 4
piano ∷ -- 5
piano ∷ -- 6
piano ∷ -- 7
piano ∷ -- 8
piano ∷ -- 9
drums ∷ -- 10 (percussion)
piano ∷ -- 11
piano ∷ -- 12
piano ∷ -- 13
piano ∷ -- 14
piano ∷ -- 15
piano ∷ -- 16
[]
music : Vec (List Note) tracks
music = foldIntoVector (proof→notesTop levels s↑)
tempo : ℕ
tempo = 160
soundTracks : List MidiTrack
soundTracks = makeTrackList instruments tempo music
| 28.830409
| 84
| 0.648682
|
df6277ea7e10158eaac8f5682675f007f660f09d
| 393
|
agda
|
Agda
|
test/Fail/Issue526.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue526.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue526.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v 100 -v tc.meta.name:100 -v interactive.meta:10 #-}
module Issue526 where
-- Don't just write _49,
-- include the corresponding implicit variable name as well (if any)
postulate
f : {A : Set} → {a : A} → Set1 → {B : Set} → Set
test : Set
test = f Set
test₁ : Set
test₁ = f {A = _} Set
postulate
g : (B : Set) → Set
test₂ : Set
test₂ = g _
test₃ : _ → Set
test₃ ()
| 15.72
| 68
| 0.608142
|
57ec711c9d5bf581d801b48fd7fc9c583f84bbf7
| 8,863
|
agda
|
Agda
|
LibraBFT/Base/ByteString.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/Base/ByteString.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/Base/ByteString.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
-- To enable reasoning about algorithms that concatenate
-- ByteStrings and pass the result to a cryptographic hash
-- function (as LibraBFT does), it is critical to have an
-- injective bitstring concat function ('bs-concat', below).
--
-- To see why, suppose we hash a data structure that contains two
-- fields of type ByteString by passing its fields to a hash
-- function like this:
--
-- > h : String -> String -> Hash
-- > h a b = hash (concat [a , b])
--
-- This function is /NOT/ collision resistant:
--
-- > h "xx" "x" == hash (concat ["xx" , "x"])
-- > == hash "xxx"
-- > == hash (concat ["x" , "xx"]) == h "x" "xx"
--
-- We cannot solve the problem simply by using an arbitrary field
-- separator, because an arbitrary ByteString might contain the
-- separator. For example, if we define:
--
-- > h a b = hash (concat [ a , ";" , b ])
--
-- Then, we still have:
--
-- > h "x;x" "x" == h "x" "x;x"
--
-- Two possible approaches to defining an injective `concat`
-- function are:
--
-- 1) Use some length-prefixed encoding where we know the size of
-- each field. This approach will work in practice but we won't
-- be able to prove its injectivity for arbitrary ByteStrings in
-- Agda: Regardless of how many bytes we reserve for size
-- information, there are some inputs that require more.
--
-- 2) Encoding the arguments' list structure in the result of
-- concat; inverting the concat function then becomes parsing a
-- list of values. This approach is analogous to:
--
-- > concat : List ByteString -> BitString
-- > concat = serialize . toJSON
--
-- We take the second approach.
module LibraBFT.Base.ByteString where
-- A BitString is a list of bits
BitString : Set
BitString = List Bool
_≟BitString_ : (bs1 bs2 : BitString) → Dec (bs1 ≡ bs2)
_≟BitString_ = List-≡-dec _≟Bool_
-- A ByteString is a list of bytes
ByteString : Set
ByteString = List (Vec Bool 8)
_≟ByteString_ : (bs1 bs2 : ByteString) → Dec (bs1 ≡ bs2)
_≟ByteString_ = List-≡-dec (Vec-≡-dec _≟Bool_)
-- Concatenates ByteString prepending '11' to each byte.
toBitString-pad' : ByteString → BitString
toBitString-pad' = concat ∘ List-map (λ v → true ∷ true ∷ Vec-toList v)
-- Concatenates a ByteString distinguishing an empty list from a non-empty list
toBitString-pad : ByteString → BitString
toBitString-pad [] = false ∷ false ∷ []
toBitString-pad (b ∷ bs) = true ∷ false ∷ Vec-toList b ++ toBitString-pad' bs
-- Here's our injective concat function for ByteString
bs-concat : List ByteString -> BitString
bs-concat = concat ∘ List-map toBitString-pad
------------------------------------------------------------------------------
-- operations
-- TODO-1: these are prefixed with "BS∙" because they conflict with the
-- versions in List that are imported via Prelude.
-- It is possible to rename the List versions when importing them
-- but that will make a big diff of the following proofs that
-- should (IF renaming is done) in a separate PR.
postulate -- to prove these operations
BS∙drop : ℕ → ByteString → ByteString
BS∙isPrefixOf : ByteString → ByteString → Bool
BS∙length : ByteString → ℕ
-----------------------
-- Injectivity Proof --
-----------------------
-- The proof is straightforward once we figure out the core reasoning principle:
-- Any non-injective cases would be some variation on:
--
-- bs-concat ([a] ∷ c) ≡ bs-concat ([b₀ , b₁] ∷ d)
--
-- <==> toBitString-pad [a] ++ bs-concat c ≡ toBitString-pad [b₀ , b₁] ++ bs-concat d
--
-- <==> 1 1 a₀ ⋯ a₇ ++ bs-concat c ≡ 1 1 b₀₀ ⋯ b₀₇ 1 0 b₁₀ ⋯ b₁₇ ++ bs-concat d
--
-- { ++ is injective for same-length prefixes }
--
-- <==> aᵢ ≡ b₀ᵢ × bs-concat c ≡ 1 0 b₁₀ ⋯ b₁₇ ++ bs-concat d
--
-- { impossible, bs-concat c is either empty or starts with 11 }
--
-- <==> ⊥
--
-- The actual Agda is a little more involved; but this covers the intuition.
-- Appending two lists of the same length is injective.
++-len-injective : ∀{a}{A : Set a}(xs₀ ys₀ : List A){xs₁ ys₁ : List A}
→ length xs₀ ≡ length ys₀
→ xs₀ ++ xs₁ ≡ ys₀ ++ ys₁
→ xs₀ ≡ ys₀ × xs₁ ≡ ys₁
++-len-injective [] [] len hyp = refl , hyp
++-len-injective (x ∷ xs0) (y ∷ ys0) len hyp
= let x≡y , tails≡ = ∷-injective hyp
a , b = ++-len-injective xs0 ys0 (suc-injective len) tails≡
in cong₂ _∷_ x≡y a , b
Vec-toList-length : ∀{a n}{A : Set a}(x : Vec A n) → length (Vec-toList x) ≡ n
Vec-toList-length [] = refl
Vec-toList-length (_ ∷ xs) = cong suc (Vec-toList-length xs)
Vec-toList-inj : ∀{a n}{A : Set a}{x y : Vec A n}
→ Vec-toList x ≡ Vec-toList y → x ≡ y
Vec-toList-inj {x = []} {[]} hyp = refl
Vec-toList-inj {x = x ∷ xs} {y ∷ ys} hyp
= let x≡y , xs≡ys = ∷-injective hyp
in cong₂ _∷_ x≡y (Vec-toList-inj xs≡ys)
-- In general, _++_ is not injective. However, we can
-- characterize it universally with a /Prefix/ property.
data _≺_ {a}{A : Set a} : List A → List A → Set where
z≺n : ∀{xs} → [] ≺ xs
s≺s : ∀{x xs ys} → xs ≺ ys → (x ∷ xs) ≺ (x ∷ ys)
-- Returns the tail of ys; after dropping the prefix xs.
≺-drop : ∀{a}{A : Set a}{xs ys : List A} → xs ≺ ys → List A
≺-drop {ys = ys} z≺n = ys
≺-drop (s≺s a) = ≺-drop a
++-≺ : ∀{a}{A : Set a}(xs ws : List A){ys zs : List A}
→ xs ++ ys ≡ ws ++ zs
→ Σ (xs ≺ ws) (λ prf → ≺-drop prf ++ zs ≡ ys)
⊎ Σ (ws ≺ xs) (λ prf → ≺-drop prf ++ ys ≡ zs)
++-≺ [] ys hyp = inj₁ (z≺n , sym hyp)
++-≺ (x ∷ xs) [] hyp = inj₂ (z≺n , hyp)
++-≺ (x ∷ xs) (y ∷ ys) hyp
with ∷-injective hyp
...| refl , xs≡ys
with ++-≺ xs ys xs≡ys
...| inj₁ (ok , prf) = inj₁ (s≺s ok , prf)
...| inj₂ (ok , prf) = inj₂ (s≺s ok , prf)
≺-respects-++-len
: ∀{a}{A : Set a}(xs₀ ys₀ : List A){xs₁ ys₁ : List A}
→ (p : (xs₀ ++ xs₁) ≺ (ys₀ ++ ys₁))
→ length xs₀ ≡ length ys₀
→ xs₀ ≡ ys₀ × Σ (xs₁ ≺ ys₁) (λ p' → ≺-drop p ≡ ≺-drop p')
≺-respects-++-len [] [] prf hyp = refl , (prf , refl)
≺-respects-++-len (x ∷ xs) (.x ∷ ys) (s≺s prf) hyp
with ≺-respects-++-len xs ys prf (suc-injective hyp)
...| xs≡ys , res , ok = cong (x ∷_) xs≡ys , res , ok
bs-concat-[]⊎tf : ∀ as {bs} → true ∷ true ∷ bs ≢ bs-concat as
bs-concat-[]⊎tf ([] ∷ as) ()
bs-concat-[]⊎tf ((_ ∷ _) ∷ as) ()
toBitString-pad'-≺
: ∀{a b}
→ (a≺bbs : toBitString-pad' a ≺ toBitString-pad' b)
→ a ≡ b ⊎ ∃[ tail ] (≺-drop a≺bbs ≡ true ∷ true ∷ tail)
toBitString-pad'-≺ {[]} {[]} prf = inj₁ refl
toBitString-pad'-≺ {[]} {x ∷ bs} z≺n = inj₂ (Vec-toList x ++ toBitString-pad' bs , refl)
toBitString-pad'-≺ {a ∷ as} {b ∷ bs} (s≺s (s≺s prf))
with ≺-respects-++-len (Vec-toList a) (Vec-toList b) prf
(trans (Vec-toList-length a) (sym (Vec-toList-length b)))
...| a≡b , prf' , drop≡
with toBitString-pad'-≺ {as} {bs} prf'
...| inj₁ ok = inj₁ (cong₂ _∷_ (Vec-toList-inj a≡b) ok)
...| inj₂ ok = inj₂ (proj₁ ok , trans drop≡ (proj₂ ok))
toBitString-pad-≺
: ∀{a b}
→ (a≺bbs : toBitString-pad a ≺ toBitString-pad b)
→ a ≡ b ⊎ ∃[ tail ] (≺-drop a≺bbs ≡ true ∷ true ∷ tail)
toBitString-pad-≺ {[]} {[]} prf = inj₁ refl
toBitString-pad-≺ {a ∷ as} {b ∷ bs} (s≺s (s≺s prf))
with ≺-respects-++-len (Vec-toList a) (Vec-toList b) prf
(trans (Vec-toList-length a) (sym (Vec-toList-length b)))
...| a≡b , prf' , drop≡
with toBitString-pad'-≺ {as} {bs} prf'
...| inj₁ ok = inj₁ (cong₂ _∷_ (Vec-toList-inj a≡b) ok)
...| inj₂ ok = inj₂ (proj₁ ok , trans drop≡ (proj₂ ok))
bs-concat-inj : ∀ bs₁ bs₂ → bs-concat bs₁ ≡ bs-concat bs₂ → bs₁ ≡ bs₂
bs-concat-inj [] [] hyp = refl
bs-concat-inj ([] ∷ as) [] ()
bs-concat-inj [] ([] ∷ bs) ()
bs-concat-inj [] ((_ ∷ _) ∷ bs) ()
bs-concat-inj ((_ ∷ _) ∷ as) [] ()
bs-concat-inj (a ∷ as) (b ∷ bs) hyp -- TODO-1: Eliminate catchall warning or explain why we don't.
with ++-≺ (toBitString-pad a) (toBitString-pad b) hyp
...| inj₁ (a≺b , prf)
with toBitString-pad-≺ a≺b
...| inj₁ refl = cong (a ∷_) (bs-concat-inj as bs (proj₂ (++-len-injective (toBitString-pad a) _ refl hyp)))
...| inj₂ (tail , aux) rewrite aux = ⊥-elim (bs-concat-[]⊎tf as prf)
bs-concat-inj (a ∷ as) (b ∷ bs) hyp
| inj₂ (b≺a , prf)
with toBitString-pad-≺ b≺a
...| inj₁ refl = cong (a ∷_) (bs-concat-inj as bs (proj₂ (++-len-injective (toBitString-pad a) _ refl hyp)))
...| inj₂ (tail , aux) rewrite aux = ⊥-elim (bs-concat-[]⊎tf bs prf)
| 39.744395
| 111
| 0.573959
|
57b488aa066f504f645028c0c1dac9087970d3cf
| 5,767
|
agda
|
Agda
|
test/epic/RunTests.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | null | null | null |
test/epic/RunTests.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | null | null | null |
test/epic/RunTests.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --no-termination-check #-}
module RunTests where
open import Prelude.Bool
open import Prelude.Char
open import Prelude.Nat
open import Prelude.List
open import Prelude.IO
open import Prelude.String
open import Prelude.Unit
open import Prelude.Product
postulate
Stream : Set
popen : String -> String -> IO Stream
pclose : Stream -> IO Unit
readChar : Stream -> IO Char
strLen : String -> Nat
charAt : (s : String) -> Nat -> Char
_`_`_ : {A B C : Set}(x : A)(f : A -> B -> C)(y : B) -> C
x ` f ` y = f x y
infixr 9 _∘_
_∘_ : {A : Set}{B : A -> Set}{C : (x : A) -> B x -> Set}
(f : {a : A}(b : B a)-> C a b)
(g : (a : A) -> B a)(x : A) -> C x (g x)
f ∘ g = λ x -> f (g x)
infixr 1 _$_
_$_ : {A : Set}{B : A -> Set}(f : (x : A) -> B x)(x : A) -> B x
f $ x = f x
{-# COMPILED_EPIC popen (s : String, m : String, u : Unit) -> Ptr = foreign Ptr "popen" (mkString(s) : String, mkString(m) : String) #-}
{-# COMPILED_EPIC pclose (s : Ptr, u : Unit) -> Unit = foreign Int "pclose" (s : Ptr) ; u #-}
{-# COMPILED_EPIC readChar (s : Ptr, u : Unit) -> Int = foreign Int "fgetc" (s : Ptr) #-}
{-# COMPILED_EPIC strLen (s : Any) -> BigInt = foreign BigInt "intToBig" (foreign Int "strlen" (mkString(s) : String) : Int) #-}
{-# COMPILED_EPIC charAt (s : Any, n : BigInt) -> Int = foreign Int "charAtBig" (mkString(s) : String, n : BigInt) #-}
readStream : Stream -> IO (List Char)
readStream stream =
c <- readChar stream ,
if' charEq eof c
then pclose stream ,, return []
else ( cs <- readStream stream
, return (c :: cs))
system : String -> IO (List Char)
system s =
putStrLn $ "system " +S+ s ,,
x <- popen s "r" ,
y <- readStream x ,
return y
span : {A : Set} -> (p : A -> Bool) -> List A -> List A × List A
span p [] = [] , []
span p (a :: as) with p a
... | false = [] , a :: as
... | true with span p as
... | xs , ys = (a :: xs) , ys
groupBy : {A : Set} -> (A -> A -> Bool) -> List A -> List (List A)
groupBy _ [] = []
groupBy eq (x :: xs) with span (eq x) xs
... | ys , zs = (x :: ys) :: groupBy eq zs
comparing : {A B : Set} -> (A -> B) -> (B -> B -> Bool) -> A -> A -> Bool
comparing f _==_ x y = f x == f y
FilePath : Set
FilePath = String
and : List Bool -> Bool
and [] = true
and (true :: xs) = and xs
and (false :: _) = false
sequence : {A : Set} -> List (IO A) -> IO (List A)
sequence [] = return []
sequence (x :: xs) =
r <- x ,
rs <- sequence xs ,
return (r :: rs)
mapM : {A B : Set} -> (A -> IO B) -> List A -> IO (List B)
mapM f xs = sequence (map f xs)
printList : List Char -> IO Unit
printList xs =
mapM printChar xs ,,
printChar '\n'
printResult : FilePath -> List Char -> List Char -> IO Unit
printResult filename l1 l2 with l1 ` listEq charEq ` l2
... | true = putStrLn (filename +S+ ": Success!")
... | false = putStrLn (filename +S+ ": Fail!") ,,
putStrLn "Expected:" ,,
printList l2 ,,
putStrLn "Got:" ,,
printList l1
compile : FilePath -> FilePath -> IO Unit
compile dir file =
system $ "agda --epic --compile-dir=" +S+ dir +S+ "bin/ " +S+ dir +S+ file ,,
return unit
readFile : FilePath -> IO (List Char)
readFile file = system $ "cat " +S+ file
-- This won't work because of a bug in Epic...
{-
validFile : List Char -> Bool
validFile f with span (not ∘ charEq '.') f
... | _ , ('.' :: 'a' :: 'g' :: 'd' :: 'a' :: []) = true
... | _ , ('.' :: 'o' :: 'u' :: 't' :: []) = true
... | _ = false
-}
stripFileEnding : FilePath -> FilePath
stripFileEnding fp = fromList $ fst $ span (not ∘ charEq '.') (fromString fp)
testFile : FilePath -> FilePath -> FilePath -> IO Bool
testFile outdir agdafile outfile =
compile outdir (agdafile) ,,
out <- system $ outdir +S+ "bin/" +S+ stripFileEnding agdafile ,
expected <- readFile (outdir +S+ outfile) ,
printResult agdafile out expected ,,
return (out ` listEq charEq ` expected)
testFile' : FilePath -> List (List Char) -> IO Bool
testFile' outdir (agdafile :: outfile :: _) = testFile outdir (fromList agdafile) (fromList outfile)
testFile' _ _ = return true
isNewline : Char -> Bool
isNewline '\n' = true
isNewline _ = false
lines : List Char -> List (List Char)
lines list with span (not ∘ isNewline) list
... | l , [] = l :: []
... | l , _ :: s' = l :: lines s'
getFiles : FilePath -> IO (List (List Char))
getFiles dir =
out <- system $ "ls " +S+ dir ,
putStrLn "getFiles after ls" ,,
-- mapM (printList ∘ snd) $ map (span (not ∘ charEq '.')) $ lines out ,,
return $ lines out -- filter validFile $ lines out
isDot : Char -> Bool
isDot '.' = true
isDot _ = false
testFiles : FilePath -> IO Bool
testFiles dir =
files <- getFiles dir ,
putStrLn "Found the following files in the tests directory:" ,,
mapM printList files ,,
res <- mapM (testFile' dir) (groupBy (comparing (fst ∘ span (not ∘ isDot)) (listEq charEq)) files) ,
return $ and res
getCurrentDirectory : IO FilePath
getCurrentDirectory =
fromList <$> system "pwd"
main : IO Unit
main =
dir' <- getCurrentDirectory ,
putStrLn (fromList (fromString dir')) ,,
putStrLn "hello" ,,
putStrLn (fromList (tail ('h' :: 'e' :: 'j' :: []))) ,,
printList (fromString "hej igen") ,,
putStrLn (fromList (tail (fromString "hello"))) ,,
dir <- fromList ∘ init ∘ fromString <$> getCurrentDirectory ,
putStrLn dir ,,
system ("rm " +S+ dir +S+ "/tests/*.agdai") ,,
res <- testFiles (dir +S+ "/tests/") ,
(if res
then putStrLn "All tests succeeded! "
else putStrLn "Not all tests succeeded ")
| 31.342391
| 136
| 0.556268
|
12f402ad5e6697cd8b9d0e337fcc96bac9a97e36
| 1,103
|
agda
|
Agda
|
examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Real/Base.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/AIM6/Cat/lib/Data/Real/Base.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/AIM6/Cat/lib/Data/Real/Base.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Data.Real.Base where
import Prelude
import Data.Rational
import Data.Nat as Nat
import Data.Bits
import Data.Bool
import Data.Maybe
import Data.Integer
import Data.List
import Data.Real.Gauge
open Prelude
open Data.Rational hiding (_-_; !_!)
open Data.Bits
open Data.Bool
open Data.List
open Data.Integer
hiding (-_; _+_; _≥_; _≤_; _>_; _<_; _==_)
renaming ( _*_ to _*'_ )
open Nat using (Nat; zero; suc)
open Data.Real.Gauge using (Gauge)
Base = Rational
bitLength : Int -> Int
bitLength x = pos (nofBits ! x !) - pos 1
approxBase : Base -> Gauge -> Base
approxBase x e = help err
where
num = numerator e
den = denominator e
err = bitLength (den - pos 1) - bitLength num
help : Int -> Base
help (pos (suc n)) = round (x * fromNat k) % pos k
where
k = shiftL 1 (suc n)
help (pos 0) = x
help (neg n) = fromInt $ (round $ x / fromInt k) *' k
where
k = pos (shiftL 1 ! neg n !)
powers : Nat -> Base -> List Base
powers n x = iterate n (_*_ x) x
sumBase : List Base -> Base
sumBase xs = foldr _+_ (fromNat 0) xs
| 20.811321
| 57
| 0.629193
|
292100f630b8f2baf01bdc3b27639d67f81ee656
| 1,584
|
agda
|
Agda
|
Cubical/Structures/TypeEqvTo.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Structures/TypeEqvTo.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/Structures/TypeEqvTo.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Structures.TypeEqvTo where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Data.Prod hiding (_×_) renaming (_×Σ_ to _×_)
open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS)
open import Cubical.Foundations.Pointed
open import Cubical.Structures.Pointed
private
variable
ℓ ℓ' ℓ'' : Level
TypeEqvTo : (ℓ : Level) (X : Type ℓ') → Type (ℓ-max (ℓ-suc ℓ) ℓ')
TypeEqvTo ℓ X = TypeWithStr ℓ (λ Y → ∥ Y ≃ X ∥)
PointedEqvTo : (ℓ : Level) (X : Type ℓ') → Type (ℓ-max (ℓ-suc ℓ) ℓ')
PointedEqvTo ℓ X = TypeWithStr ℓ (λ Y → Y × ∥ Y ≃ X ∥)
module _ (X : Type ℓ') where
PointedEqvTo-structure : Type ℓ → Type (ℓ-max ℓ ℓ')
PointedEqvTo-structure = add-to-structure pointed-structure (λ Y _ → ∥ Y ≃ X ∥)
PointedEqvTo-iso : StrIso PointedEqvTo-structure ℓ''
PointedEqvTo-iso = add-to-iso pointed-structure pointed-iso (λ Y _ → ∥ Y ≃ X ∥)
PointedEqvTo-is-SNS : SNS {ℓ} PointedEqvTo-structure PointedEqvTo-iso
PointedEqvTo-is-SNS = add-axioms-SNS pointed-structure pointed-iso (λ Y _ → ∥ Y ≃ X ∥)
(λ _ _ → squash)
pointed-is-SNS
PointedEqvTo-SIP : (A B : PointedEqvTo ℓ X) → A ≃[ PointedEqvTo-iso ] B ≃ (A ≡ B)
PointedEqvTo-SIP = SIP PointedEqvTo-structure PointedEqvTo-iso PointedEqvTo-is-SNS
PointedEqvTo-sip : (A B : PointedEqvTo ℓ X) → A ≃[ PointedEqvTo-iso ] B → (A ≡ B)
PointedEqvTo-sip A B = equivFun (PointedEqvTo-SIP A B)
| 37.714286
| 88
| 0.661616
|
588b6b85031bd33f53ff1cacbc50a275e9f2805a
| 481
|
agda
|
Agda
|
test/interaction/Issue1790.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/interaction/Issue1790.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | null | null | null |
test/interaction/Issue1790.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- Andreas, 2016-01-22, issue 1790
-- Projections should be highlighted as such everywhere,
-- even in the parts of a record declaration that
-- make the record constructor type.
record Σ A (B : A → Set) : Set where
field
fst : A
snd : B fst -- fst should be highlighted as projection here
-- Should also work under 'mutual'.
mutual
record IOInterface : Set₁ where
constructor ioInterface
field Command : Set
Response : (m : Command) → Set
| 26.722222
| 64
| 0.673597
|
57afbd3a87871b4aa6661de6ad9394ec40d3018f
| 617
|
agda
|
Agda
|
test/fail/NoPanic.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T04:41:05.000Z
|
2019-11-27T04:41:05.000Z
|
test/fail/NoPanic.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/NoPanic.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module NoPanic where
postulate
Level : Set
lzero : Level
lsuc : Level → Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO lzero #-}
{-# BUILTIN LEVELSUC lsuc #-}
module M {A : Set} where
postulate
I : A → ∀ a → Set a
i : ∀ (x : A) {a} → I x a
f : {B : Set} → B
a : A
Foo : Set₁
Foo with i (f a)
Foo | _ = Set
-- Old (bad) error message:
-- NoPanic.agda:24,3-16
-- Panic: Pattern match failure in do expression at
-- src/full/Agda/TypeChecking/Rules/Term.hs:646:7-18
-- when checking that the expression _22 {A} has type Level
| 19.28125
| 59
| 0.604538
|
0e1af70fc12820388e59a4a026d8f4cad4d8f449
| 23,883
|
agda
|
Agda
|
src/Finite-subset/Kuratowski.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Finite-subset/Kuratowski.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Finite-subset/Kuratowski.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Kuratowski finite subsets
------------------------------------------------------------------------
-- Based on Frumin, Geuvers, Gondelman and van der Weide's "Finite
-- Sets in Homotopy Type Theory".
{-# OPTIONS --cubical --safe #-}
import Equality.Path as P
module Finite-subset.Kuratowski
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
import Finite-subset.Listed eq as L
open import Function-universe equality-with-J hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Truncation.Propositional eq as Trunc
using (∥_∥; _∥⊎∥_)
open import Monad equality-with-J as M using (Raw-monad; Monad)
private
variable
a b p : Level
A B : Type a
P : A → Type p
f g : (x : A) → P x
l x y z : A
m n : ℕ
------------------------------------------------------------------------
-- Kuratowski finite subsets
-- Kuratowski finite subsets of a given type.
infixr 5 _∪_
data Finite-subset-of (A : Type a) : Type a where
∅ : Finite-subset-of A
singleton : A → Finite-subset-of A
_∪_ : Finite-subset-of A → Finite-subset-of A →
Finite-subset-of A
∅∪ᴾ : ∅ ∪ x P.≡ x
idem-sᴾ : singleton x ∪ singleton x P.≡ singleton x
assocᴾ : x ∪ (y ∪ z) P.≡ (x ∪ y) ∪ z
commᴾ : x ∪ y P.≡ y ∪ x
is-setᴾ : P.Is-set (Finite-subset-of A)
-- Variants of some of the constructors.
∅∪ : ∅ ∪ x ≡ x
∅∪ = _↔_.from ≡↔≡ ∅∪ᴾ
idem-s : singleton x ∪ singleton x ≡ singleton x
idem-s = _↔_.from ≡↔≡ idem-sᴾ
assoc : x ∪ (y ∪ z) ≡ (x ∪ y) ∪ z
assoc = _↔_.from ≡↔≡ assocᴾ
comm : x ∪ y ≡ y ∪ x
comm = _↔_.from ≡↔≡ commᴾ
is-set : Is-set (Finite-subset-of A)
is-set = _↔_.from (H-level↔H-level 2) is-setᴾ
-- ∅ is a right identity for _∪_.
∪∅ : x ∪ ∅ ≡ x
∪∅ {x = x} =
x ∪ ∅ ≡⟨ comm ⟩
∅ ∪ x ≡⟨ ∅∪ ⟩∎
x ∎
------------------------------------------------------------------------
-- Eliminators
-- A dependent eliminator, expressed using paths.
record Elimᴾ {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
field
∅ʳ : P ∅
singletonʳ : ∀ x → P (singleton x)
∪ʳ : P x → P y → P (x ∪ y)
∅∪ʳ : (p : P x) →
P.[ (λ i → P (∅∪ᴾ {x = x} i)) ] ∪ʳ ∅ʳ p ≡ p
idem-sʳ : ∀ x →
P.[ (λ i → P (idem-sᴾ {x = x} i)) ]
∪ʳ (singletonʳ x) (singletonʳ x) ≡ singletonʳ x
assocʳ : (p : P x) (q : P y) (r : P z) →
P.[ (λ i → P (assocᴾ {x = x} {y = y} {z = z} i)) ]
∪ʳ p (∪ʳ q r) ≡ ∪ʳ (∪ʳ p q) r
commʳ : (p : P x) (q : P y) →
P.[ (λ i → P (commᴾ {x = x} {y = y} i)) ]
∪ʳ p q ≡ ∪ʳ q p
is-setʳ : ∀ x → P.Is-set (P x)
open Elimᴾ public
elimᴾ : Elimᴾ P → (x : Finite-subset-of A) → P x
elimᴾ {A = A} {P = P} e = helper
where
module E = Elimᴾ e
helper : (x : Finite-subset-of A) → P x
helper ∅ = E.∅ʳ
helper (singleton x) = E.singletonʳ x
helper (x ∪ y) = E.∪ʳ (helper x) (helper y)
helper (∅∪ᴾ {x = x} i) = E.∅∪ʳ (helper x) i
helper (idem-sᴾ i) = E.idem-sʳ _ i
helper (assocᴾ {x = x} {y = y} {z = z} i) = E.assocʳ
(helper x) (helper y)
(helper z) i
helper (commᴾ {x = x} {y = y} i) = E.commʳ
(helper x) (helper y) i
helper (is-setᴾ x y i j) =
P.heterogeneous-UIP E.is-setʳ (is-setᴾ x y)
(λ i → helper (x i)) (λ i → helper (y i)) i j
-- A non-dependent eliminator, expressed using paths.
record Recᴾ (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
∅ʳ : B
singletonʳ : A → B
∪ʳ : Finite-subset-of A → Finite-subset-of A → B → B → B
∅∪ʳ : ∀ x p → ∪ʳ ∅ x ∅ʳ p P.≡ p
idem-sʳ : ∀ x →
∪ʳ (singleton x) (singleton x)
(singletonʳ x) (singletonʳ x) P.≡
singletonʳ x
assocʳ : ∀ p q r →
∪ʳ x (y ∪ z) p (∪ʳ y z q r) P.≡
∪ʳ (x ∪ y) z (∪ʳ x y p q) r
commʳ : ∀ p q → ∪ʳ x y p q P.≡ ∪ʳ y x q p
is-setʳ : P.Is-set B
open Recᴾ public
recᴾ : Recᴾ A B → Finite-subset-of A → B
recᴾ r = elimᴾ e
where
module R = Recᴾ r
e : Elimᴾ _
e .∅ʳ = R.∅ʳ
e .singletonʳ = R.singletonʳ
e .∪ʳ {x = x} {y = y} = R.∪ʳ x y
e .∅∪ʳ {x = x} = R.∅∪ʳ x
e .idem-sʳ = R.idem-sʳ
e .assocʳ = R.assocʳ
e .commʳ = R.commʳ
e .is-setʳ _ = R.is-setʳ
-- A dependent eliminator, expressed using equality.
record Elim {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
field
∅ʳ : P ∅
singletonʳ : ∀ x → P (singleton x)
∪ʳ : P x → P y → P (x ∪ y)
∅∪ʳ : (p : P x) → subst P (∅∪ {x = x}) (∪ʳ ∅ʳ p) ≡ p
idem-sʳ : ∀ x →
subst P (idem-s {x = x})
(∪ʳ (singletonʳ x) (singletonʳ x)) ≡
singletonʳ x
assocʳ : (p : P x) (q : P y) (r : P z) →
subst P (assoc {x = x} {y = y} {z = z})
(∪ʳ p (∪ʳ q r)) ≡
∪ʳ (∪ʳ p q) r
commʳ : (p : P x) (q : P y) →
subst P (comm {x = x} {y = y}) (∪ʳ p q) ≡ ∪ʳ q p
is-setʳ : ∀ x → Is-set (P x)
open Elim public
elim : Elim P → (x : Finite-subset-of A) → P x
elim e = elimᴾ e′
where
module E = Elim e
e′ : Elimᴾ _
e′ .∅ʳ = E.∅ʳ
e′ .singletonʳ = E.singletonʳ
e′ .∪ʳ = E.∪ʳ
e′ .∅∪ʳ p = subst≡→[]≡ (E.∅∪ʳ p)
e′ .idem-sʳ x = subst≡→[]≡ (E.idem-sʳ x)
e′ .assocʳ p q r = subst≡→[]≡ (E.assocʳ p q r)
e′ .commʳ p q = subst≡→[]≡ (E.commʳ p q)
e′ .is-setʳ x = _↔_.to (H-level↔H-level 2) (E.is-setʳ x)
-- A non-dependent eliminator, expressed using equality.
record Rec (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
∅ʳ : B
singletonʳ : A → B
∪ʳ : Finite-subset-of A → Finite-subset-of A → B → B → B
∅∪ʳ : ∀ x p → ∪ʳ ∅ x ∅ʳ p ≡ p
idem-sʳ : ∀ x →
∪ʳ (singleton x) (singleton x)
(singletonʳ x) (singletonʳ x) ≡
singletonʳ x
assocʳ : ∀ p q r →
∪ʳ x (y ∪ z) p (∪ʳ y z q r) ≡
∪ʳ (x ∪ y) z (∪ʳ x y p q) r
commʳ : ∀ p q → ∪ʳ x y p q ≡ ∪ʳ y x q p
is-setʳ : Is-set B
open Rec public
rec : Rec A B → Finite-subset-of A → B
rec r = recᴾ r′
where
module R = Rec r
r′ : Recᴾ _ _
r′ .∅ʳ = R.∅ʳ
r′ .singletonʳ = R.singletonʳ
r′ .∪ʳ = R.∪ʳ
r′ .∅∪ʳ x p = _↔_.to ≡↔≡ (R.∅∪ʳ x p)
r′ .idem-sʳ x = _↔_.to ≡↔≡ (R.idem-sʳ x)
r′ .assocʳ p q r = _↔_.to ≡↔≡ (R.assocʳ p q r)
r′ .commʳ p q = _↔_.to ≡↔≡ (R.commʳ p q)
r′ .is-setʳ = _↔_.to (H-level↔H-level 2) R.is-setʳ
-- A dependent eliminator for propositions.
record Elim-prop {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
field
∅ʳ : P ∅
singletonʳ : ∀ x → P (singleton x)
∪ʳ : P x → P y → P (x ∪ y)
is-propositionʳ : ∀ x → Is-proposition (P x)
open Elim-prop public
elim-prop : Elim-prop P → (x : Finite-subset-of A) → P x
elim-prop e = elim e′
where
module E = Elim-prop e
e′ : Elim _
e′ .∅ʳ = E.∅ʳ
e′ .singletonʳ = E.singletonʳ
e′ .∪ʳ = E.∪ʳ
e′ .∅∪ʳ _ = E.is-propositionʳ _ _ _
e′ .idem-sʳ _ = E.is-propositionʳ _ _ _
e′ .assocʳ _ _ _ = E.is-propositionʳ _ _ _
e′ .commʳ _ _ = E.is-propositionʳ _ _ _
e′ .is-setʳ _ = mono₁ 1 (E.is-propositionʳ _)
-- A non-dependent eliminator for propositions.
record Rec-prop (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
∅ʳ : B
singletonʳ : A → B
∪ʳ : Finite-subset-of A → Finite-subset-of A →
B → B → B
is-propositionʳ : Is-proposition B
open Rec-prop public
rec-prop : Rec-prop A B → Finite-subset-of A → B
rec-prop r = elim-prop e
where
module R = Rec-prop r
e : Elim-prop _
e .∅ʳ = R.∅ʳ
e .singletonʳ = R.singletonʳ
e .∪ʳ {x = x} {y = y} = R.∪ʳ x y
e .is-propositionʳ _ = R.is-propositionʳ
------------------------------------------------------------------------
-- Definitions related to listed finite subsets
private
-- Some definitions used in the implementation of Listed≃Kuratowski
-- below.
to : L.Finite-subset-of A → Finite-subset-of A
to L.[] = ∅
to (x L.∷ y) = singleton x ∪ to y
to (L.dropᴾ {x = x} {y = y} i) =
(singleton x ∪ (singleton x ∪ to y) P.≡⟨ assocᴾ ⟩
(singleton x ∪ singleton x) ∪ to y P.≡⟨ P.cong (_∪ to y) idem-sᴾ ⟩∎
singleton x ∪ to y ∎) i
to (L.swapᴾ {x = x} {y = y} {z = z} i) =
(singleton x ∪ (singleton y ∪ to z) P.≡⟨ assocᴾ ⟩
(singleton x ∪ singleton y) ∪ to z P.≡⟨ P.cong (_∪ to z) commᴾ ⟩
(singleton y ∪ singleton x) ∪ to z P.≡⟨ P.sym assocᴾ ⟩∎
singleton y ∪ (singleton x ∪ to z) ∎) i
to (L.is-setᴾ x y i j) =
is-setᴾ (λ i → to (x i)) (λ i → to (y i)) i j
to-∪ : (x : L.Finite-subset-of A) → to (x L.∪ y) ≡ to x ∪ to y
to-∪ {y = y} = L.elim-prop e
where
e : L.Elim-prop _
e .L.is-propositionʳ _ = is-set
e .L.[]ʳ =
to y ≡⟨ sym ∅∪ ⟩∎
∅ ∪ to y ∎
e .L.∷ʳ {y = z} x hyp =
singleton x ∪ to (z L.∪ y) ≡⟨ cong (singleton x ∪_) hyp ⟩
singleton x ∪ (to z ∪ to y) ≡⟨ assoc ⟩∎
(singleton x ∪ to z) ∪ to y ∎
-- Listed finite subsets are equivalent to Kuratowski finite subsets.
Listed≃Kuratowski : L.Finite-subset-of A ≃ Finite-subset-of A
Listed≃Kuratowski {A = A} = from-bijection (record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
})
where
from : Finite-subset-of A → L.Finite-subset-of A
from ∅ = L.[]
from (singleton x) = x L.∷ L.[]
from (x ∪ y) = from x L.∪ from y
from (∅∪ᴾ {x = x} _) = from x
from (idem-sᴾ {x = x} i) = L.dropᴾ {x = x} {y = L.[]} i
from (assocᴾ {x = x} {y = y} {z = z} i) =
_↔_.to ≡↔≡ (L.assoc {y = from y} {z = from z} (from x)) i
from (commᴾ {x = x} {y = y} i) =
_↔_.to ≡↔≡ (L.comm {y = from y} (from x)) i
from (is-setᴾ x y i j) =
L.is-setᴾ (λ i → from (x i)) (λ i → from (y i)) i j
to∘from : ∀ x → to (from x) ≡ x
to∘from = elim-prop e
where
e : Elim-prop _
e .is-propositionʳ _ = is-set
e .∅ʳ = refl _
e .singletonʳ _ = ∪∅
e .∪ʳ {x = x} {y = y} hyp₁ hyp₂ =
to (from x L.∪ from y) ≡⟨ to-∪ (from x) ⟩
to (from x) ∪ to (from y) ≡⟨ cong₂ _∪_ hyp₁ hyp₂ ⟩∎
x ∪ y ∎
from∘to : ∀ x → from (to x) ≡ x
from∘to = L.elim-prop e
where
e : L.Elim-prop _
e .L.is-propositionʳ _ = L.is-set
e .L.[]ʳ = refl _
e .L.∷ʳ {y = y} x hyp =
x L.∷ from (to y) ≡⟨ cong (x L.∷_) hyp ⟩∎
x L.∷ y ∎
-- The forward direction of Listed≃Kuratowski is homomorphic with
-- respect to L._∪_/_∪_.
to-Listed≃Kuratowski-∪ :
(x : L.Finite-subset-of A) →
_≃_.to Listed≃Kuratowski (x L.∪ y) ≡
_≃_.to Listed≃Kuratowski x ∪ _≃_.to Listed≃Kuratowski y
to-Listed≃Kuratowski-∪ = to-∪
-- The other direction of Listed≃Kuratowski is definitionally
-- homomorphic with respect to _∪_/L._∪_.
_ :
_≃_.from Listed≃Kuratowski (x ∪ y) ≡
_≃_.from Listed≃Kuratowski x L.∪ _≃_.from Listed≃Kuratowski y
_ = refl _
-- A list-like dependent eliminator for Finite-subset-of, for
-- propositions.
record List-elim-prop
{A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
field
[]ʳ : P ∅
∷ʳ : ∀ x → P y → P (singleton x ∪ y)
is-propositionʳ : ∀ x → Is-proposition (P x)
open List-elim-prop public
list-elim-prop : List-elim-prop P → (x : Finite-subset-of A) → P x
list-elim-prop {P = P} l x =
subst P (_≃_.right-inverse-of Listed≃Kuratowski x)
(L.elim-prop e (_≃_.from Listed≃Kuratowski x))
where
module E = List-elim-prop l
e : L.Elim-prop (P ∘ _≃_.to Listed≃Kuratowski)
e .L.[]ʳ = E.[]ʳ
e .L.∷ʳ x = E.∷ʳ x
e .L.is-propositionʳ _ = E.is-propositionʳ _
-- A list-like non-dependent eliminator for Finite-subset-of,
-- expressed using paths.
record List-recᴾ (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
[]ʳ : B
∷ʳ : A → Finite-subset-of A → B → B
dropʳ : ∀ x y p →
∷ʳ x (singleton x ∪ y) (∷ʳ x y p) P.≡ ∷ʳ x y p
swapʳ : ∀ x y z p →
∷ʳ x (singleton y ∪ z) (∷ʳ y z p) P.≡
∷ʳ y (singleton x ∪ z) (∷ʳ x z p)
is-setʳ : P.Is-set B
open List-recᴾ public
list-recᴾ : List-recᴾ A B → Finite-subset-of A → B
list-recᴾ l = L.recᴾ r ∘ _≃_.from Listed≃Kuratowski
where
module E = List-recᴾ l
r : L.Recᴾ _ _
r .L.[]ʳ = E.[]ʳ
r .L.∷ʳ x y = E.∷ʳ x (_≃_.to Listed≃Kuratowski y)
r .L.dropʳ x y = E.dropʳ x (_≃_.to Listed≃Kuratowski y)
r .L.swapʳ x y z = E.swapʳ x y (_≃_.to Listed≃Kuratowski z)
r .L.is-setʳ = E.is-setʳ
-- Unit tests documenting some of the computational behaviour of
-- list-recᴾ.
_ : list-recᴾ l ∅ ≡ l .[]ʳ
_ = refl _
_ : list-recᴾ l (singleton x) ≡ l .∷ʳ x ∅ (l .[]ʳ)
_ = refl _
_ : let y′ = _≃_.to Listed≃Kuratowski (_≃_.from Listed≃Kuratowski y) in
list-recᴾ l (singleton x ∪ y) ≡ l .∷ʳ x y′ (list-recᴾ l y)
_ = refl _
-- A list-like non-dependent eliminator for Finite-subset-of,
-- expressed using equality.
record List-rec (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
[]ʳ : B
∷ʳ : A → Finite-subset-of A → B → B
dropʳ : ∀ x y p →
∷ʳ x (singleton x ∪ y) (∷ʳ x y p) ≡ ∷ʳ x y p
swapʳ : ∀ x y z p →
∷ʳ x (singleton y ∪ z) (∷ʳ y z p) ≡
∷ʳ y (singleton x ∪ z) (∷ʳ x z p)
is-setʳ : Is-set B
open List-rec public
list-rec : List-rec A B → Finite-subset-of A → B
list-rec l = list-recᴾ l′
where
module R = List-rec l
l′ : List-recᴾ _ _
l′ .[]ʳ = R.[]ʳ
l′ .∷ʳ = R.∷ʳ
l′ .dropʳ x y p = _↔_.to ≡↔≡ (R.dropʳ x y p)
l′ .swapʳ x y z p = _↔_.to ≡↔≡ (R.swapʳ x y z p)
l′ .is-setʳ = _↔_.to (H-level↔H-level 2) R.is-setʳ
-- Unit tests documenting some of the computational behaviour of
-- list-rec.
_ : list-rec l ∅ ≡ l .[]ʳ
_ = refl _
_ : list-rec l (singleton x) ≡ l .∷ʳ x ∅ (l .[]ʳ)
_ = refl _
_ : let y′ = _≃_.to Listed≃Kuratowski (_≃_.from Listed≃Kuratowski y) in
list-rec l (singleton x ∪ y) ≡ l .∷ʳ x y′ (list-rec l y)
_ = refl _
------------------------------------------------------------------------
-- Membership
-- Membership.
infix 4 _∈_
_∈_ : {A : Type a} → A → Finite-subset-of A → Type a
x ∈ y = x L.∈ _≃_.from Listed≃Kuratowski y
-- Membership is propositional.
∈-propositional : ∀ y → Is-proposition (x ∈ y)
∈-propositional _ = L.∈-propositional
-- A lemma characterising ∅.
∈∅≃ : (x ∈ ∅) ≃ ⊥₀
∈∅≃ = L.∈[]≃
-- A lemma characterising singleton.
∈singleton≃ : (x ∈ singleton y) ≃ ∥ x ≡ y ∥
∈singleton≃ = L.∈singleton≃
-- If x is a member of y, then x is a member of y ∪ z.
∈→∈∪ˡ : ∀ y z → x ∈ y → x ∈ y ∪ z
∈→∈∪ˡ {x = x} y z =
x ∈ y ↔⟨⟩
x L.∈ _≃_.from Listed≃Kuratowski y ↝⟨ L.∈→∈∪ˡ ⟩
x L.∈ _≃_.from Listed≃Kuratowski y L.∪ _≃_.from Listed≃Kuratowski z ↔⟨⟩
x L.∈ _≃_.from Listed≃Kuratowski (y ∪ z) ↔⟨⟩
x ∈ y ∪ z □
-- If x is a member of z, then x is a member of y ∪ z.
∈→∈∪ʳ : ∀ y z → x ∈ z → x ∈ y ∪ z
∈→∈∪ʳ {x = x} y z =
x ∈ z ↔⟨⟩
x L.∈ _≃_.from Listed≃Kuratowski z ↝⟨ L.∈→∈∪ʳ (_≃_.from Listed≃Kuratowski y) ⟩
x L.∈ _≃_.from Listed≃Kuratowski y L.∪ _≃_.from Listed≃Kuratowski z ↔⟨⟩
x ∈ y ∪ z □
-- Membership of a union of two subsets can be expressed in terms of
-- membership of the subsets.
∈∪≃ : ∀ y z → (x ∈ y ∪ z) ≃ (x ∈ y ∥⊎∥ x ∈ z)
∈∪≃ {x = x} y z =
x ∈ y ∪ z ↔⟨⟩
x L.∈ _≃_.from Listed≃Kuratowski y L.∪ _≃_.from Listed≃Kuratowski z ↝⟨ L.∈∪≃ ⟩
x L.∈ _≃_.from Listed≃Kuratowski y ∥⊎∥
x L.∈ _≃_.from Listed≃Kuratowski z ↔⟨⟩
x ∈ y ∥⊎∥ x ∈ z □
-- If truncated equality is decidable, then membership is also
-- decidable.
member? :
((x y : A) → Dec ∥ x ≡ y ∥) →
(x : A) (y : Finite-subset-of A) → Dec (x ∈ y)
member? equal? x = L.member? equal? x ∘ _≃_.from Listed≃Kuratowski
-- Subsets.
_⊆_ : {A : Type a} → Finite-subset-of A → Finite-subset-of A → Type a
x ⊆ y = ∀ z → z ∈ x → z ∈ y
-- The subset property can be expressed using _∪_ and _≡_.
⊆≃∪≡ : (x ⊆ y) ≃ (x ∪ y ≡ y)
⊆≃∪≡ {x = x} {y = y} =
x ⊆ y ↝⟨ L.⊆≃∪≡ (_≃_.from Listed≃Kuratowski x) ⟩
_≃_.from Listed≃Kuratowski x L.∪ _≃_.from Listed≃Kuratowski y ≡
_≃_.from Listed≃Kuratowski y ↔⟨⟩
_≃_.from Listed≃Kuratowski (x ∪ y) ≡ _≃_.from Listed≃Kuratowski y ↝⟨ Eq.≃-≡ (inverse Listed≃Kuratowski) ⟩□
x ∪ y ≡ y □
-- Extensionality.
extensionality :
(x ≡ y) ≃ (∀ z → z ∈ x ⇔ z ∈ y)
extensionality {x = x} {y = y} =
x ≡ y ↝⟨ inverse $ Eq.≃-≡ (inverse Listed≃Kuratowski) ⟩
_≃_.from Listed≃Kuratowski x ≡ _≃_.from Listed≃Kuratowski y ↝⟨ L.extensionality ⟩□
(∀ z → z ∈ x ⇔ z ∈ y) □
------------------------------------------------------------------------
-- A law
-- Union is idempotent.
idem : x ∪ x ≡ x
idem {x = x} = _≃_.from extensionality λ y →
y ∈ x ∪ x ↔⟨ ∈∪≃ x x ⟩
y ∈ x ∥⊎∥ y ∈ x ↔⟨ Trunc.idempotent ⟩
∥ y ∈ x ∥ ↔⟨ Trunc.∥∥↔ (∈-propositional x) ⟩□
y ∈ x □
------------------------------------------------------------------------
-- Some operations
-- A map function.
map : (A → B) → Finite-subset-of A → Finite-subset-of B
map f = recᴾ r
where
r : Recᴾ _ _
r .∅ʳ = ∅
r .singletonʳ x = singleton (f x)
r .∪ʳ _ _ = _∪_
r .∅∪ʳ _ _ = ∅∪ᴾ
r .idem-sʳ _ = idem-sᴾ
r .assocʳ _ _ _ = assocᴾ
r .commʳ _ _ = commᴾ
r .is-setʳ = is-setᴾ
-- A filter function.
filter : (A → Bool) → Finite-subset-of A → Finite-subset-of A
filter p = rec r
where
r : Rec _ _
r .∅ʳ = ∅
r .singletonʳ x = if p x then singleton x else ∅
r .∪ʳ _ _ = _∪_
r .∅∪ʳ _ _ = ∅∪
r .idem-sʳ _ = idem
r .assocʳ _ _ _ = assoc
r .commʳ _ _ = comm
r .is-setʳ = is-set
-- Join.
join : Finite-subset-of (Finite-subset-of A) → Finite-subset-of A
join = rec r
where
r : Rec _ _
r .∅ʳ = ∅
r .singletonʳ = id
r .∪ʳ _ _ = _∪_
r .∅∪ʳ _ _ = ∅∪
r .idem-sʳ _ = idem
r .assocʳ _ _ _ = assoc
r .commʳ _ _ = comm
r .is-setʳ = is-set
-- A universe-polymorphic variant of bind.
infixl 5 _>>=′_
_>>=′_ :
Finite-subset-of A → (A → Finite-subset-of B) → Finite-subset-of B
x >>=′ f = join (map f x)
-- Bind distributes from the right over union.
_ : (x ∪ y) >>=′ f ≡ (x >>=′ f) ∪ (y >>=′ f)
_ = refl _
-- Bind distributes from the left over union.
>>=-left-distributive :
∀ x → (x >>=′ λ x → f x ∪ g x) ≡ (x >>=′ f) ∪ (x >>=′ g)
>>=-left-distributive {f = f} {g = g} = elim-prop e
where
e : Elim-prop _
e .∅ʳ = ∅ ≡⟨ sym idem ⟩∎
∅ ∪ ∅ ∎
e .singletonʳ _ = refl _
e .is-propositionʳ _ = is-set
e .∪ʳ {x = x} {y = y} hyp₁ hyp₂ =
(x ∪ y) >>=′ (λ x → f x ∪ g x) ≡⟨⟩
(x >>=′ λ x → f x ∪ g x) ∪ (y >>=′ λ x → f x ∪ g x) ≡⟨ cong₂ _∪_ hyp₁ hyp₂ ⟩
((x >>=′ f) ∪ (x >>=′ g)) ∪ ((y >>=′ f) ∪ (y >>=′ g)) ≡⟨ sym assoc ⟩
(x >>=′ f) ∪ ((x >>=′ g) ∪ ((y >>=′ f) ∪ (y >>=′ g))) ≡⟨ cong ((x >>=′ f) ∪_) assoc ⟩
(x >>=′ f) ∪ (((x >>=′ g) ∪ (y >>=′ f)) ∪ (y >>=′ g)) ≡⟨ cong (((x >>=′ f) ∪_) ∘ (_∪ (y >>=′ g))) comm ⟩
(x >>=′ f) ∪ (((y >>=′ f) ∪ (x >>=′ g)) ∪ (y >>=′ g)) ≡⟨ cong ((x >>=′ f) ∪_) (sym assoc) ⟩
(x >>=′ f) ∪ ((y >>=′ f) ∪ ((x >>=′ g) ∪ (y >>=′ g))) ≡⟨ assoc ⟩
((x >>=′ f) ∪ (y >>=′ f)) ∪ ((x >>=′ g) ∪ (y >>=′ g)) ≡⟨⟩
((x ∪ y) >>=′ f) ∪ ((x ∪ y) >>=′ g) ∎
-- Monad laws.
_ : singleton x >>=′ f ≡ f x
_ = refl _
>>=-singleton : x >>=′ singleton ≡ x
>>=-singleton = elim-prop e _
where
e : Elim-prop (λ x → x >>=′ singleton ≡ x)
e .∅ʳ = refl _
e .singletonʳ _ = refl _
e .is-propositionʳ _ = is-set
e .∪ʳ {x = x} {y = y} hyp₁ hyp₂ =
(x ∪ y) >>=′ singleton ≡⟨⟩
(x >>=′ singleton) ∪ (y >>=′ singleton) ≡⟨ cong₂ _∪_ hyp₁ hyp₂ ⟩∎
x ∪ y ∎
>>=-assoc : ∀ x → x >>=′ (λ x → f x >>=′ g) ≡ x >>=′ f >>=′ g
>>=-assoc {f = f} {g = g} = elim-prop e
where
e : Elim-prop _
e .∅ʳ = refl _
e .singletonʳ _ = refl _
e .is-propositionʳ _ = is-set
e .∪ʳ {x = x} {y = y} hyp₁ hyp₂ =
(x ∪ y) >>=′ (λ x → f x >>=′ g) ≡⟨⟩
(x >>=′ λ x → f x >>=′ g) ∪ (y >>=′ λ x → f x >>=′ g) ≡⟨ cong₂ _∪_ hyp₁ hyp₂ ⟩
(x >>=′ f >>=′ g) ∪ (y >>=′ f >>=′ g) ≡⟨⟩
(x ∪ y) >>=′ f >>=′ g ∎
-- A monad instance.
instance
raw-monad : Raw-monad {d = a} Finite-subset-of
raw-monad .M.return = singleton
raw-monad .M._>>=_ = _>>=′_
monad : Monad {d = a} Finite-subset-of
monad .M.Monad.raw-monad = raw-monad
monad .M.Monad.left-identity _ _ = refl _
monad .M.Monad.right-identity _ = >>=-singleton
monad .M.Monad.associativity x _ _ = >>=-assoc x
------------------------------------------------------------------------
-- Size
-- Size.
infix 4 ∣_∣≡_
∣_∣≡_ : {A : Type a} → Finite-subset-of A → ℕ → Type a
∣ x ∣≡ n = L.∣ _≃_.from Listed≃Kuratowski x ∣≡ n
-- The size predicate is propositional.
∣∣≡-propositional :
(x : Finite-subset-of A) → Is-proposition (∣ x ∣≡ n)
∣∣≡-propositional = L.∣∣≡-propositional ∘ _≃_.from Listed≃Kuratowski
-- Unit tests documenting some of the computational behaviour of
-- ∣_∣≡_.
_ : (∣ ∅ {A = A} ∣≡ n) ≡ ↑ _ (n ≡ 0)
_ = refl _
_ : ∀ {A : Type a} {x : A} {y} →
(∣ singleton x ∪ y ∣≡ zero) ≡ (x ∈ y × ∣ y ∣≡ zero ⊎ ⊥)
_ = refl _
_ : (∣ singleton x ∪ y ∣≡ suc n) ≡
(x ∈ y × ∣ y ∣≡ suc n ⊎ ¬ x ∈ y × ∣ y ∣≡ n)
_ = refl _
-- The size predicate is functional.
∣∣≡-functional :
(x : Finite-subset-of A) → ∣ x ∣≡ m → ∣ x ∣≡ n → m ≡ n
∣∣≡-functional = L.∣∣≡-functional ∘ _≃_.from Listed≃Kuratowski
-- If truncated equality is decidable, then one can compute the size
-- of a finite subset.
size :
((x y : A) → Dec ∥ x ≡ y ∥) →
(x : Finite-subset-of A) → ∃ λ n → ∣ x ∣≡ n
size equal? = L.size equal? ∘ _≃_.from Listed≃Kuratowski
| 30.540921
| 114
| 0.455805
|
31d19632181f2dc8f0f19464b4439ed34a914000
| 4,858
|
agda
|
Agda
|
src/logic.agda
|
shinji-kono/HyperReal-in-agda
|
64d5f1ec0a6d81b7b9c45a289f669bbf32c9c891
|
[
"MIT"
] | null | null | null |
src/logic.agda
|
shinji-kono/HyperReal-in-agda
|
64d5f1ec0a6d81b7b9c45a289f669bbf32c9c891
|
[
"MIT"
] | null | null | null |
src/logic.agda
|
shinji-kono/HyperReal-in-agda
|
64d5f1ec0a6d81b7b9c45a289f669bbf32c9c891
|
[
"MIT"
] | null | null | null |
module logic where
open import Level
open import Relation.Nullary
open import Relation.Binary hiding (_⇔_ )
open import Data.Empty
data Bool : Set where
true : Bool
false : Bool
record _∧_ {n m : Level} (A : Set n) ( B : Set m ) : Set (n ⊔ m) where
constructor ⟪_,_⟫
field
proj1 : A
proj2 : B
data _∨_ {n m : Level} (A : Set n) ( B : Set m ) : Set (n ⊔ m) where
case1 : A → A ∨ B
case2 : B → A ∨ B
_⇔_ : {n m : Level } → ( A : Set n ) ( B : Set m ) → Set (n ⊔ m)
_⇔_ A B = ( A → B ) ∧ ( B → A )
∧-exch : {n m : Level} {A : Set n} { B : Set m } → A ∧ B → B ∧ A
∧-exch p = ⟪ _∧_.proj2 p , _∧_.proj1 p ⟫
∨-exch : {n m : Level} {A : Set n} { B : Set m } → A ∨ B → B ∨ A
∨-exch (case1 x) = case2 x
∨-exch (case2 x) = case1 x
contra-position : {n m : Level } {A : Set n} {B : Set m} → (A → B) → ¬ B → ¬ A
contra-position {n} {m} {A} {B} f ¬b a = ¬b ( f a )
double-neg : {n : Level } {A : Set n} → A → ¬ ¬ A
double-neg A notnot = notnot A
double-neg2 : {n : Level } {A : Set n} → ¬ ¬ ¬ A → ¬ A
double-neg2 notnot A = notnot ( double-neg A )
de-morgan : {n : Level } {A B : Set n} → A ∧ B → ¬ ( (¬ A ) ∨ (¬ B ) )
de-morgan {n} {A} {B} and (case1 ¬A) = ⊥-elim ( ¬A ( _∧_.proj1 and ))
de-morgan {n} {A} {B} and (case2 ¬B) = ⊥-elim ( ¬B ( _∧_.proj2 and ))
dont-or : {n m : Level} {A : Set n} { B : Set m } → A ∨ B → ¬ A → B
dont-or {A} {B} (case1 a) ¬A = ⊥-elim ( ¬A a )
dont-or {A} {B} (case2 b) ¬A = b
dont-orb : {n m : Level} {A : Set n} { B : Set m } → A ∨ B → ¬ B → A
dont-orb {A} {B} (case2 b) ¬B = ⊥-elim ( ¬B b )
dont-orb {A} {B} (case1 a) ¬B = a
infixr 130 _∧_
infixr 140 _∨_
infixr 150 _⇔_
_/\_ : Bool → Bool → Bool
true /\ true = true
_ /\ _ = false
_\/_ : Bool → Bool → Bool
false \/ false = false
_ \/ _ = true
not_ : Bool → Bool
not true = false
not false = true
_<=>_ : Bool → Bool → Bool
true <=> true = true
false <=> false = true
_ <=> _ = false
open import Relation.Binary.PropositionalEquality
record Bijection {n m : Level} (R : Set n) (S : Set m) : Set (n Level.⊔ m) where
field
fun← : S → R
fun→ : R → S
fiso← : (x : R) → fun← ( fun→ x ) ≡ x
fiso→ : (x : S ) → fun→ ( fun← x ) ≡ x
injection : {n m : Level} (R : Set n) (S : Set m) (f : R → S ) → Set (n Level.⊔ m)
injection R S f = (x y : R) → f x ≡ f y → x ≡ y
¬t=f : (t : Bool ) → ¬ ( not t ≡ t)
¬t=f true ()
¬t=f false ()
infixr 130 _\/_
infixr 140 _/\_
≡-Bool-func : {A B : Bool } → ( A ≡ true → B ≡ true ) → ( B ≡ true → A ≡ true ) → A ≡ B
≡-Bool-func {true} {true} a→b b→a = refl
≡-Bool-func {false} {true} a→b b→a with b→a refl
... | ()
≡-Bool-func {true} {false} a→b b→a with a→b refl
... | ()
≡-Bool-func {false} {false} a→b b→a = refl
bool-≡-? : (a b : Bool) → Dec ( a ≡ b )
bool-≡-? true true = yes refl
bool-≡-? true false = no (λ ())
bool-≡-? false true = no (λ ())
bool-≡-? false false = yes refl
¬-bool-t : {a : Bool} → ¬ ( a ≡ true ) → a ≡ false
¬-bool-t {true} ne = ⊥-elim ( ne refl )
¬-bool-t {false} ne = refl
¬-bool-f : {a : Bool} → ¬ ( a ≡ false ) → a ≡ true
¬-bool-f {true} ne = refl
¬-bool-f {false} ne = ⊥-elim ( ne refl )
¬-bool : {a : Bool} → a ≡ false → a ≡ true → ⊥
¬-bool refl ()
lemma-∧-0 : {a b : Bool} → a /\ b ≡ true → a ≡ false → ⊥
lemma-∧-0 {true} {true} refl ()
lemma-∧-0 {true} {false} ()
lemma-∧-0 {false} {true} ()
lemma-∧-0 {false} {false} ()
lemma-∧-1 : {a b : Bool} → a /\ b ≡ true → b ≡ false → ⊥
lemma-∧-1 {true} {true} refl ()
lemma-∧-1 {true} {false} ()
lemma-∧-1 {false} {true} ()
lemma-∧-1 {false} {false} ()
bool-and-tt : {a b : Bool} → a ≡ true → b ≡ true → ( a /\ b ) ≡ true
bool-and-tt refl refl = refl
bool-∧→tt-0 : {a b : Bool} → ( a /\ b ) ≡ true → a ≡ true
bool-∧→tt-0 {true} {true} refl = refl
bool-∧→tt-0 {false} {_} ()
bool-∧→tt-1 : {a b : Bool} → ( a /\ b ) ≡ true → b ≡ true
bool-∧→tt-1 {true} {true} refl = refl
bool-∧→tt-1 {true} {false} ()
bool-∧→tt-1 {false} {false} ()
bool-or-1 : {a b : Bool} → a ≡ false → ( a \/ b ) ≡ b
bool-or-1 {false} {true} refl = refl
bool-or-1 {false} {false} refl = refl
bool-or-2 : {a b : Bool} → b ≡ false → (a \/ b ) ≡ a
bool-or-2 {true} {false} refl = refl
bool-or-2 {false} {false} refl = refl
bool-or-3 : {a : Bool} → ( a \/ true ) ≡ true
bool-or-3 {true} = refl
bool-or-3 {false} = refl
bool-or-31 : {a b : Bool} → b ≡ true → ( a \/ b ) ≡ true
bool-or-31 {true} {true} refl = refl
bool-or-31 {false} {true} refl = refl
bool-or-4 : {a : Bool} → ( true \/ a ) ≡ true
bool-or-4 {true} = refl
bool-or-4 {false} = refl
bool-or-41 : {a b : Bool} → a ≡ true → ( a \/ b ) ≡ true
bool-or-41 {true} {b} refl = refl
bool-and-1 : {a b : Bool} → a ≡ false → (a /\ b ) ≡ false
bool-and-1 {false} {b} refl = refl
bool-and-2 : {a b : Bool} → b ≡ false → (a /\ b ) ≡ false
bool-and-2 {true} {false} refl = refl
bool-and-2 {false} {false} refl = refl
| 28.080925
| 87
| 0.502264
|
2920760d05b33f9ce78cf7293983e1e478a34dde
| 1,442
|
agda
|
Agda
|
Setoids/DirectSum.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Setoids/DirectSum.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Setoids/DirectSum.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Sets.EquivalenceRelations
open import Setoids.Setoids
module Setoids.DirectSum {m n o p : _} {A : Set m} {B : Set n} (R : Setoid {m} {o} A) (S : Setoid {n} {p} B) where
directSumSetoid : Setoid {m ⊔ n} (A || B)
Setoid._∼_ directSumSetoid (inl x) (inl y) = embedLevel {o} {p} (Setoid._∼_ R x y)
Setoid._∼_ directSumSetoid (inl x) (inr y) = False'
Setoid._∼_ directSumSetoid (inr x) (inl y) = False'
Setoid._∼_ directSumSetoid (inr x) (inr y) = embedLevel {p} {o} (Setoid._∼_ S x y)
Equivalence.reflexive (Setoid.eq directSumSetoid) {inl x} = Equivalence.reflexive (Setoid.eq R) {x} ,, record {}
Equivalence.reflexive (Setoid.eq directSumSetoid) {inr x} = Equivalence.reflexive (Setoid.eq S) {x} ,, record {}
Equivalence.symmetric (Setoid.eq directSumSetoid) {inl x} {inl y} (x=y ,, _) = (Equivalence.symmetric (Setoid.eq R) x=y) ,, record {}
Equivalence.symmetric (Setoid.eq directSumSetoid) {inr x} {inr y} (x=y ,, _) = (Equivalence.symmetric (Setoid.eq S) x=y) ,, record {}
Equivalence.transitive (Setoid.eq directSumSetoid) {inl x} {inl y} {inl z} (x=y ,, _) (y=z ,, _) = Equivalence.transitive (Setoid.eq R) x=y y=z ,, record {}
Equivalence.transitive (Setoid.eq directSumSetoid) {inr x} {inr y} {inr z} (x=y ,, _) (y=z ,, _) = Equivalence.transitive (Setoid.eq S) x=y y=z ,, record {}
| 68.666667
| 156
| 0.677531
|
22631d8622c2e30eb542419ea50c184394168738
| 13,166
|
agda
|
Agda
|
Cubical/ZCohomology/MayerVietorisUnreduced.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/ZCohomology/MayerVietorisUnreduced.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/ZCohomology/MayerVietorisUnreduced.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.ZCohomology.MayerVietorisUnreduced where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.GroupStructure
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Path
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Sigma
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn
open import Cubical.HITs.S1
open import Cubical.HITs.Susp
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to sRec2 ; elim to sElim ; elim2 to sElim2)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; elim to pElim ; elim2 to pElim2 ; ∥_∥ to ∥_∥₁ ; ∣_∣ to ∣_∣₁)
open import Cubical.Data.Nat
open import Cubical.Algebra.Group
open import Cubical.HITs.Truncation renaming (elim to trElim ; map to trMap ; rec to trRec ; elim3 to trElim3)
open IsGroupHom
module MV {ℓ ℓ' ℓ''} (A : Type ℓ) (B : Type ℓ') (C : Type ℓ'') (f : C → A) (g : C → B) where
-- Proof from Brunerie 2016.
-- We first define the three morphisms involved: i, Δ and d.
private
i* : (n : ℕ) → coHom n (Pushout f g) → coHom n A × coHom n B
i* n = sRec (isSet× isSetSetTrunc isSetSetTrunc) λ δ → ∣ (λ x → δ (inl x)) ∣₂ , ∣ (λ x → δ (inr x)) ∣₂
iIsHom : (n : ℕ) → IsGroupHom (coHomGr n (Pushout f g) .snd) (i* n) (×coHomGr n A B .snd)
iIsHom n =
makeIsGroupHom (sElim2 (λ _ _ → isOfHLevelPath 2 (isSet× isSetSetTrunc isSetSetTrunc) _ _) λ _ _ → refl)
i : (n : ℕ) → GroupHom (coHomGr n (Pushout f g)) (×coHomGr n A B)
fst (i n) = i* n
snd (i n) = iIsHom n
private
distrLem : (n : ℕ) (x y z w : coHomK n) → (x +[ n ]ₖ y) -[ n ]ₖ (z +[ n ]ₖ w) ≡ (x -[ n ]ₖ z) +[ n ]ₖ (y -[ n ]ₖ w)
distrLem n x y z w = cong (λ z → (x +[ n ]ₖ y) +[ n ]ₖ z) (-distrₖ n z w)
∙∙ sym (assocₖ n x y ((-[ n ]ₖ z) +[ n ]ₖ (-[ n ]ₖ w)))
∙∙ cong (λ y → x +[ n ]ₖ y) (commₖ n y ((-[ n ]ₖ z) +[ n ]ₖ (-[ n ]ₖ w)) ∙ sym (assocₖ n _ _ _))
∙∙ assocₖ n _ _ _
∙∙ cong (λ y → (x -[ n ]ₖ z) +[ n ]ₖ y) (commₖ n (-[ n ]ₖ w) y)
Δ' : (n : ℕ) → coHom n A × coHom n B → coHom n C
Δ' n (α , β) = coHomFun n f α -[ n ]ₕ coHomFun n g β
Δ'-isMorph : (n : ℕ) → IsGroupHom (×coHomGr n A B .snd) (Δ' n) (coHomGr n C .snd)
Δ'-isMorph n =
makeIsGroupHom
(prodElim2 (λ _ _ → isOfHLevelPath 2 isSetSetTrunc _ _ )
λ f' x1 g' x2 i → ∣ (λ x → distrLem n (f' (f x)) (g' (f x)) (x1 (g x)) (x2 (g x)) i) ∣₂)
Δ : (n : ℕ) → GroupHom (×coHomGr n A B) (coHomGr n C)
fst (Δ n) = Δ' n
snd (Δ n) = Δ'-isMorph n
d-pre : (n : ℕ) → (C → coHomK n) → Pushout f g → coHomK (suc n)
d-pre n γ (inl x) = 0ₖ (suc n)
d-pre n γ (inr x) = 0ₖ (suc n)
d-pre n γ (push a i) = Kn→ΩKn+1 n (γ a) i
dHomHelper : (n : ℕ) (h l : C → coHomK n) (x : Pushout f g)
→ d-pre n (λ x → h x +[ n ]ₖ l x) x ≡ d-pre n h x +[ suc n ]ₖ d-pre n l x
dHomHelper n h l (inl x) = sym (rUnitₖ (suc n) (0ₖ (suc n)))
dHomHelper n h l (inr x) = sym (lUnitₖ (suc n) (0ₖ (suc n)))
dHomHelper n h l (push a i) j =
hcomp (λ k → λ { (i = i0) → rUnitₖ (suc n) (0ₖ (suc n)) (~ j)
; (i = i1) → lUnitₖ (suc n) (0ₖ (suc n)) (~ j)
; (j = i0) → Kn→ΩKn+1-hom n (h a) (l a) (~ k) i
; (j = i1) → cong₂Funct (λ x y → x +[ (suc n) ]ₖ y) (Kn→ΩKn+1 n (h a)) (Kn→ΩKn+1 n (l a)) (~ k) i })
(hcomp (λ k → λ { (i = i0) → rUnitₖ (suc n) (0ₖ (suc n)) (~ j)
; (i = i1) → lUnitₖ (suc n) (Kn→ΩKn+1 n (l a) k) (~ j)})
(hcomp (λ k → λ { (i = i0) → rUnitₖ (suc n) (0ₖ (suc n)) (~ j)
; (i = i1) → lUnitₖ≡rUnitₖ (suc n) (~ k) (~ j)
; (j = i0) → Kn→ΩKn+1 n (h a) i
; (j = i1) → (Kn→ΩKn+1 n (h a) i) +[ (suc n) ]ₖ coHom-pt (suc n)})
(rUnitₖ (suc n) (Kn→ΩKn+1 n (h a) i) (~ j))))
dIsHom : (n : ℕ) → IsGroupHom (coHomGr n C .snd) (sRec isSetSetTrunc λ a → ∣ d-pre n a ∣₂) (coHomGr (suc n) (Pushout f g) .snd)
dIsHom n =
makeIsGroupHom
(sElim2 (λ _ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
λ f g i → ∣ funExt (λ x → dHomHelper n f g x) i ∣₂)
d : (n : ℕ) → GroupHom (coHomGr n C) (coHomGr (suc n) (Pushout f g))
fst (d n) = sRec isSetSetTrunc λ a → ∣ d-pre n a ∣₂
snd (d n) = dIsHom n
-- The long exact sequence
Im-d⊂Ker-i : (n : ℕ) (x : ⟨ (coHomGr (suc n) (Pushout f g)) ⟩)
→ isInIm (d n) x
→ isInKer (i (suc n)) x
Im-d⊂Ker-i n = sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 (isSet× isSetSetTrunc isSetSetTrunc) _ _)
λ a → pRec (isOfHLevelPath' 1 (isSet× isSetSetTrunc isSetSetTrunc) _ _)
(sigmaElim (λ _ → isOfHLevelPath 2 (isSet× isSetSetTrunc isSetSetTrunc) _ _)
λ δ b i → sRec (isSet× isSetSetTrunc isSetSetTrunc)
(λ δ → ∣ (λ x → δ (inl x)) ∣₂ , ∣ (λ x → δ (inr x)) ∣₂ ) (b (~ i)))
Ker-i⊂Im-d : (n : ℕ) (x : ⟨ coHomGr (suc n) (Pushout f g) ⟩)
→ isInKer (i (suc n)) x
→ isInIm (d n) x
Ker-i⊂Im-d n =
sElim (λ _ → isSetΠ λ _ → isProp→isSet isPropPropTrunc)
λ a p → pRec {A = (λ x → a (inl x)) ≡ λ _ → 0ₖ (suc n)}
(isProp→ isPropPropTrunc)
(λ p1 → pRec isPropPropTrunc λ p2 → ∣ ∣ (λ c → ΩKn+1→Kn n (sym (cong (λ F → F (f c)) p1)
∙∙ cong a (push c)
∙∙ cong (λ F → F (g c)) p2)) ∣₂
, cong ∣_∣₂ (funExt (λ δ → helper a p1 p2 δ)) ∣₁)
(Iso.fun PathIdTrunc₀Iso (cong fst p))
(Iso.fun PathIdTrunc₀Iso (cong snd p))
where
helper : (F : (Pushout f g) → coHomK (suc n))
(p1 : Path (_ → coHomK (suc n)) (λ a₁ → F (inl a₁)) (λ _ → coHom-pt (suc n)))
(p2 : Path (_ → coHomK (suc n)) (λ a₁ → F (inr a₁)) (λ _ → coHom-pt (suc n)))
→ (δ : Pushout f g)
→ d-pre n (λ c → ΩKn+1→Kn n ((λ i₁ → p1 (~ i₁) (f c))
∙∙ cong F (push c)
∙∙ cong (λ F → F (g c)) p2)) δ
≡ F δ
helper F p1 p2 (inl x) = sym (cong (λ f → f x) p1)
helper F p1 p2 (inr x) = sym (cong (λ f → f x) p2)
helper F p1 p2 (push a i) j =
hcomp (λ k → λ { (i = i0) → p1 (~ j) (f a)
; (i = i1) → p2 (~ j) (g a)
; (j = i0) → Iso.rightInv (Iso-Kn-ΩKn+1 n) ((λ i₁ → p1 (~ i₁) (f a))
∙∙ cong F (push a)
∙∙ cong (λ F₁ → F₁ (g a)) p2) (~ k) i
; (j = i1) → F (push a i)})
(doubleCompPath-filler (sym (cong (λ F → F (f a)) p1)) (cong F (push a)) (cong (λ F → F (g a)) p2) (~ j) i)
Im-i⊂Ker-Δ : (n : ℕ) (x : ⟨ ×coHomGr n A B ⟩)
→ isInIm (i n) x
→ isInKer (Δ n) x
Im-i⊂Ker-Δ n (Fa , Fb) =
sElim {B = λ Fa → (Fb : _) → isInIm (i n) (Fa , Fb)
→ isInKer (Δ n) (Fa , Fb)}
(λ _ → isSetΠ2 λ _ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
(λ Fa → sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
λ Fb → pRec (isSetSetTrunc _ _)
(sigmaElim (λ x → isProp→isSet (isSetSetTrunc _ _))
λ Fd p → helper n Fa Fb Fd p))
Fa
Fb
where
helper : (n : ℕ) (Fa : A → coHomK n) (Fb : B → coHomK n) (Fd : (Pushout f g) → coHomK n)
→ (fst (i n) ∣ Fd ∣₂ ≡ (∣ Fa ∣₂ , ∣ Fb ∣₂))
→ (fst (Δ n)) (∣ Fa ∣₂ , ∣ Fb ∣₂) ≡ 0ₕ n
helper n Fa Fb Fd p = cong (fst (Δ n)) (sym p)
∙∙ (λ i → ∣ (λ x → Fd (inl (f x))) ∣₂ -[ n ]ₕ ∣ (λ x → Fd (push x (~ i))) ∣₂ )
∙∙ rCancelₕ n ∣ (λ x → Fd (inl (f x))) ∣₂
Ker-Δ⊂Im-i : (n : ℕ) (a : ⟨ ×coHomGr n A B ⟩)
→ isInKer (Δ n) a
→ isInIm (i n) a
Ker-Δ⊂Im-i n = prodElim (λ _ → isSetΠ (λ _ → isProp→isSet isPropPropTrunc))
(λ Fa Fb p → pRec isPropPropTrunc
(λ q → ∣ ∣ helpFun Fa Fb q ∣₂ , refl ∣₁)
(helper Fa Fb p))
where
helper : (Fa : A → coHomK n) (Fb : B → coHomK n)
→ fst (Δ n) (∣ Fa ∣₂ , ∣ Fb ∣₂) ≡ 0ₕ n
→ ∥ Path (_ → _) (λ c → Fa (f c)) (λ c → Fb (g c)) ∥₁
helper Fa Fb p = Iso.fun PathIdTrunc₀Iso
(sym (cong ∣_∣₂ (funExt (λ x → sym (assocₖ n _ _ _)
∙∙ cong (λ y → Fa (f x) +[ n ]ₖ y) (lCancelₖ n (Fb (g x)))
∙∙ rUnitₖ n (Fa (f x)))))
∙∙ cong (λ x → x +[ n ]ₕ ∣ (λ c → Fb (g c)) ∣₂) p
∙∙ lUnitₕ n _)
helpFun : (Fa : A → coHomK n) (Fb : B → coHomK n)
→ ((λ c → Fa (f c)) ≡ (λ c → Fb (g c)))
→ Pushout f g → coHomK n
helpFun Fa Fb p (inl x) = Fa x
helpFun Fa Fb p (inr x) = Fb x
helpFun Fa Fb p (push a i) = p i a
private
distrHelper : (n : ℕ) (p q : _)
→ ΩKn+1→Kn n p +[ n ]ₖ (-[ n ]ₖ ΩKn+1→Kn n q) ≡ ΩKn+1→Kn n (p ∙ sym q)
distrHelper n p q = cong (λ x → ΩKn+1→Kn n p +[ n ]ₖ x) helper ∙ sym (ΩKn+1→Kn-hom n _ _)
where
helper : -[ n ]ₖ ΩKn+1→Kn n q ≡ ΩKn+1→Kn n (sym q)
helper =
sym (rUnitₖ n _)
∙∙ cong (λ x → (-[ n ]ₖ (ΩKn+1→Kn n q)) +[ n ]ₖ x) (sym helper2)
∙∙ (assocₖ n _ _ _ ∙∙ cong (λ x → x +[ n ]ₖ (ΩKn+1→Kn n (sym q))) (lCancelₖ n _) ∙∙ lUnitₖ n _)
where
helper2 : ΩKn+1→Kn n q +[ n ]ₖ (ΩKn+1→Kn n (sym q)) ≡ coHom-pt n
helper2 = sym (ΩKn+1→Kn-hom n q (sym q)) ∙∙ cong (ΩKn+1→Kn n) (rCancel q) ∙∙ ΩKn+1→Kn-refl n
Ker-d⊂Im-Δ : (n : ℕ) (a : coHom n C)
→ isInKer (d n) a
→ isInIm (Δ n) a
Ker-d⊂Im-Δ n =
sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 isPropPropTrunc)
λ Fc p → pRec isPropPropTrunc (λ p → ∣ (∣ (λ a → ΩKn+1→Kn n (cong (λ f → f (inl a)) p)) ∣₂ ,
∣ (λ b → ΩKn+1→Kn n (cong (λ f → f (inr b)) p)) ∣₂) ,
Iso.inv (PathIdTrunc₀Iso) ∣ funExt (λ c → helper2 Fc p c) ∣₁ ∣₁)
(Iso.fun (PathIdTrunc₀Iso) p)
where
helper2 : (Fc : C → coHomK n)
(p : d-pre n Fc ≡ (λ _ → coHom-pt (suc n))) (c : C)
→ ΩKn+1→Kn n (λ i₁ → p i₁ (inl (f c))) -[ n ]ₖ (ΩKn+1→Kn n (λ i₁ → p i₁ (inr (g c)))) ≡ Fc c
helper2 Fc p c = distrHelper n _ _ ∙∙ cong (ΩKn+1→Kn n) helper3 ∙∙ Iso.leftInv (Iso-Kn-ΩKn+1 n) (Fc c)
where
helper3 : (λ i₁ → p i₁ (inl (f c))) ∙ sym (λ i₁ → p i₁ (inr (g c))) ≡ Kn→ΩKn+1 n (Fc c)
helper3 = cong ((λ i₁ → p i₁ (inl (f c))) ∙_) (lUnit _) ∙ sym (PathP→compPathR (cong (λ f → cong f (push c)) p))
Im-Δ⊂Ker-d : (n : ℕ) (a : coHom n C)
→ isInIm (Δ n) a
→ isInKer (d n) a
Im-Δ⊂Ker-d n =
sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
λ Fc → pRec (isOfHLevelPath' 1 isSetSetTrunc _ _)
(sigmaProdElim (λ _ → isOfHLevelPath 2 isSetSetTrunc _ _)
λ Fa Fb p → pRec (isOfHLevelPath' 1 isSetSetTrunc _ _)
(λ q → ((λ i → fst (d n) ∣ (q (~ i)) ∣₂) ∙ dΔ-Id n Fa Fb))
(Iso.fun (PathIdTrunc₀Iso) p))
where
d-preLeftId : (n : ℕ) (Fa : A → coHomK n)(d : (Pushout f g))
→ d-pre n (Fa ∘ f) d ≡ 0ₖ (suc n)
d-preLeftId n Fa (inl x) = Kn→ΩKn+1 n (Fa x)
d-preLeftId n Fa (inr x) = refl
d-preLeftId n Fa (push a i) j = Kn→ΩKn+1 n (Fa (f a)) (j ∨ i)
d-preRightId : (n : ℕ) (Fb : B → coHomK n) (d : (Pushout f g))
→ d-pre n (Fb ∘ g) d ≡ 0ₖ (suc n)
d-preRightId n Fb (inl x) = refl
d-preRightId n Fb (inr x) = sym (Kn→ΩKn+1 n (Fb x))
d-preRightId n Fb (push a i) j = Kn→ΩKn+1 n (Fb (g a)) (~ j ∧ i)
dΔ-Id : (n : ℕ) (Fa : A → coHomK n) (Fb : B → coHomK n)
→ fst (d n) (fst (Δ n) (∣ Fa ∣₂ , ∣ Fb ∣₂)) ≡ 0ₕ (suc n)
dΔ-Id n Fa Fb = -distrLemma n (suc n) (d n) ∣ Fa ∘ f ∣₂ ∣ Fb ∘ g ∣₂
∙∙ (λ i → ∣ (λ x → d-preLeftId n Fa x i) ∣₂ -[ (suc n) ]ₕ ∣ (λ x → d-preRightId n Fb x i) ∣₂)
∙∙ rCancelₕ (suc n) (0ₕ (suc n))
| 52.454183
| 133
| 0.442352
|
1da4b47799c2d9fdafa63a17c47f652b26840505
| 7,225
|
agda
|
Agda
|
Structure/OrderedField.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/OrderedField.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/OrderedField.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Structure.OrderedField where
import Lvl
open import Data.Boolean
open import Data.Boolean.Proofs
import Data.Either as Either
open import Data.Tuple as Tuple
open import Functional
open import Logic
open import Logic.Classical
open import Logic.IntroInstances
open import Logic.Propositional
open import Logic.Predicate
open import Numeral.Natural using (ℕ)
import Numeral.Natural.Relation.Order as ℕ
open import Relator.Ordering
import Relator.Ordering.Proofs as OrderingProofs
open import Structure.Setoid
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Function.Ordering
open import Structure.Operator.Field
open import Structure.Operator.Monoid
open import Structure.Operator.Group
open import Structure.Operator.Proofs
open import Structure.Operator.Properties
open import Structure.Operator.Ring.Proofs
open import Structure.Operator.Ring
open import Structure.Operator
open import Structure.Relator
open import Structure.Relator.Ordering
open Structure.Relator.Ordering.Weak.Properties
open import Structure.Relator.Properties
open import Structure.Relator.Proofs
open import Syntax.Implication
open import Syntax.Transitivity
open import Type
private variable ℓ ℓₗ ℓₑ : Lvl.Level
private variable F : Type{ℓ}
-- TODO: Generalize so that this does not neccessarily need a rng. See linearly ordered groups and partially ordered groups. See also ordered semigroups and monoids where the property is called "compatible".
record Ordered ⦃ equiv : Equiv{ℓₑ}(F) ⦄ (_+_ _⋅_ : F → F → F) ⦃ rng : Rng(_+_)(_⋅_) ⦄ (_≤_ : F → F → Stmt{ℓₗ}) : Type{Lvl.of(F) Lvl.⊔ ℓₗ Lvl.⊔ ℓₑ} where
open From-[≤] (_≤_) public
open Rng(rng)
field
⦃ [≤]-totalOrder ⦄ : Weak.TotalOrder(_≤_)(_≡_)
[≤][+]ₗ-preserve : ∀{x y z} → (x ≤ y) → ((x + z) ≤ (y + z))
[≤][⋅]-zero : ∀{x y} → (𝟎 ≤ x) → (𝟎 ≤ y) → (𝟎 ≤ (x ⋅ y)) -- TODO: Rename to preserve-sign
⦃ [≤]-binaryRelator ⦄ : BinaryRelator(_≤_)
-- TODO: Move this to Structure.Relator.Order or something
instance
[≡][≤]-sub : (_≡_) ⊆₂ (_≤_)
_⊆₂_.proof [≡][≤]-sub p = substitute₂ᵣ(_≤_) p (reflexivity(_≤_))
open Weak.TotalOrder([≤]-totalOrder) public
open OrderingProofs.From-[≤] (_≤_) public
record NonNegative (x : F) : Stmt{ℓₗ} where
constructor intro
field proof : (x ≥ 𝟎)
record Positive (x : F) : Stmt{ℓₗ} where
constructor intro
field proof : (x > 𝟎)
[≤][+]ᵣ-preserve : ∀{x y z} → (y ≤ z) → ((x + y) ≤ (x + z))
[≤][+]ᵣ-preserve {x}{y}{z} yz =
x + y 🝖[ _≡_ ]-[ commutativity(_+_) ]-sub
y + x 🝖[ _≤_ ]-[ [≤][+]ₗ-preserve yz ]
z + x 🝖[ _≡_ ]-[ commutativity(_+_) ]-sub
x + z 🝖-end
[≤][+]-preserve : ∀{x₁ x₂ y₁ y₂} → (x₁ ≤ x₂) → (y₁ ≤ y₂) → ((x₁ + y₁) ≤ (x₂ + y₂))
[≤][+]-preserve {x₁}{x₂}{y₁}{y₂} px py =
x₁ + y₁ 🝖[ _≤_ ]-[ [≤][+]ₗ-preserve px ]
x₂ + y₁ 🝖[ _≤_ ]-[ [≤][+]ᵣ-preserve py ]
x₂ + y₂ 🝖[ _≤_ ]-end
[≤]-flip-positive : ∀{x} → (𝟎 ≤ x) ↔ ((− x) ≤ 𝟎)
[≤]-flip-positive {x} = [↔]-intro l r where
l = \p →
𝟎 🝖[ _≡_ ]-[ symmetry(_≡_) (inverseFunctionᵣ(_+_)(−_)) ]-sub
x + (− x) 🝖[ _≤_ ]-[ [≤][+]ᵣ-preserve p ]
x + 𝟎 🝖[ _≡_ ]-[ identityᵣ(_+_)(𝟎) ]-sub
x 🝖-end
r = \p →
− x 🝖[ _≡_ ]-[ symmetry(_≡_) (identityₗ(_+_)(𝟎)) ]-sub
𝟎 + (− x) 🝖[ _≤_ ]-[ [≤][+]ₗ-preserve p ]
x + (− x) 🝖[ _≡_ ]-[ inverseFunctionᵣ(_+_)(−_) ]-sub
𝟎 🝖-end
[≤]-non-negative-difference : ∀{x y} → (𝟎 ≤ (y − x)) → (x ≤ y)
[≤]-non-negative-difference {x}{y} 𝟎yx =
x 🝖[ _≡_ ]-[ symmetry(_≡_) (identityₗ(_+_)(𝟎)) ]-sub
𝟎 + x 🝖[ _≤_ ]-[ [≤][+]ₗ-preserve 𝟎yx ]
(y − x) + x 🝖[ _≤_ ]-[]
(y + (− x)) + x 🝖[ _≡_ ]-[ associativity(_+_) ]-sub
y + ((− x) + x) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(_) (inverseFunctionₗ(_+_)(−_)) ]-sub
y + 𝟎 🝖[ _≡_ ]-[ identityᵣ(_+_)(𝟎) ]-sub
y 🝖-end
[≤]-non-positive-difference : ∀{x y} → ((x − y) ≤ 𝟎) → (x ≤ y)
[≤]-non-positive-difference {x}{y} xy𝟎 =
x 🝖[ _≡_ ]-[ symmetry(_≡_) (identityᵣ(_+_)(𝟎)) ]-sub
x + 𝟎 🝖[ _≡_ ]-[ symmetry(_≡_) (congruence₂ᵣ(_+_)(_) (inverseFunctionₗ(_+_)(−_))) ]-sub
x + ((− y) + y) 🝖[ _≡_ ]-[ symmetry(_≡_) (associativity(_+_)) ]-sub
(x + (− y)) + y 🝖[ _≤_ ]-[]
(x − y) + y 🝖[ _≤_ ]-[ [≤][+]ₗ-preserve xy𝟎 ]
𝟎 + y 🝖[ _≡_ ]-[ identityₗ(_+_)(𝟎) ]-sub
y 🝖-end
[≤]-with-[−] : ∀{x y} → (x ≤ y) → ((− y) ≤ (− x))
[≤]-with-[−] {x}{y} xy = [≤]-non-positive-difference proof3 where
proof3 : (((− y) − (− x)) ≤ 𝟎)
proof3 =
(− y) − (− x) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(_) (involution(−_)) ]-sub
(− y) + x 🝖[ _≡_ ]-[ commutativity(_+_) ]-sub
x − y 🝖[ _≤_ ]-[ [≤][+]ₗ-preserve xy ]
y − y 🝖[ _≡_ ]-[ inverseFunctionᵣ(_+_)(−_) ]-sub
𝟎 🝖-end
[≤]-flip-negative : ∀{x} → (x ≤ 𝟎) ↔ (𝟎 ≤ (− x))
[≤]-flip-negative {x} = [↔]-intro l r where
r = \p →
𝟎 🝖[ _≡_ ]-[ symmetry(_≡_) [−]-of-𝟎 ]-sub
− 𝟎 🝖[ _≤_ ]-[ [≤]-with-[−] {x}{𝟎} p ]
− x 🝖-end
l = \p →
x 🝖[ _≡_ ]-[ symmetry(_≡_) (involution(−_)) ]-sub
−(− x) 🝖[ _≤_ ]-[ [≤]-with-[−] p ]
− 𝟎 🝖[ _≡_ ]-[ [−]-of-𝟎 ]-sub
𝟎 🝖-end
[≤][−]ₗ-preserve : ∀{x y z} → (x ≤ y) → ((x − z) ≤ (y − z))
[≤][−]ₗ-preserve = [≤][+]ₗ-preserve
[≤][−]ᵣ-preserve : ∀{x y z} → (z ≤ y) → ((x − y) ≤ (x − z))
[≤][−]ᵣ-preserve = [≤][+]ᵣ-preserve ∘ [≤]-with-[−]
[≤][+]-withoutᵣ : ∀{x₁ x₂ y} → ((x₁ + y) ≤ (x₂ + y)) → (x₁ ≤ x₂)
[≤][+]-withoutᵣ {x₁}{x₂}{y} p =
x₁ 🝖[ _≡_ ]-[ symmetry(_≡_) (inverseOperᵣ(_+_)(_−_)) ]-sub
(x₁ + y) − y 🝖[ _≤_ ]-[ [≤][−]ₗ-preserve p ]
(x₂ + y) − y 🝖[ _≡_ ]-[ inverseOperᵣ(_+_)(_−_) ]-sub
x₂ 🝖-end
[≤][+]-withoutₗ : ∀{x y₁ y₂} → ((x + y₁) ≤ (x + y₂)) → (y₁ ≤ y₂)
[≤][+]-withoutₗ {x}{y₁}{y₂} p =
y₁ 🝖[ _≡_ ]-[ symmetry(_≡_) (inversePropₗ(_+_)(−_)) ]-sub
(− x) + (x + y₁) 🝖[ _≤_ ]-[ [≤][+]ᵣ-preserve p ]
(− x) + (x + y₂) 🝖[ _≡_ ]-[ inversePropₗ(_+_)(−_) ]-sub
y₂ 🝖-end
[<][+]-preserveₗ : ∀{x₁ x₂ y} → (x₁ < x₂) → ((x₁ + y) < (x₂ + y))
[<][+]-preserveₗ {x₁}{x₂}{y} px p = px ([≤][+]-withoutᵣ p)
[<][+]-preserveᵣ : ∀{x y₁ y₂} → (y₁ < y₂) → ((x + y₁) < (x + y₂))
[<][+]-preserveᵣ {x₁}{x₂}{y} px p = px ([≤][+]-withoutₗ p)
[<][+]-preserve : ∀{x₁ x₂ y₁ y₂} → (x₁ < x₂) → (y₁ < y₂) → ((x₁ + y₁) < (x₂ + y₂))
[<][+]-preserve {x₁}{x₂}{y₁}{y₂} px py =
x₁ + y₁ 🝖[ _<_ ]-[ [<][+]-preserveₗ px ]
x₂ + y₁ 🝖-semiend
x₂ + y₂ 🝖[ _<_ ]-end-from-[ [<][+]-preserveᵣ py ]
postulate [<][+]-preserve-subₗ : ∀{x₁ x₂ y₁ y₂} → (x₁ ≤ x₂) → (y₁ < y₂) → ((x₁ + y₁) < (x₂ + y₂))
postulate [<][+]-preserve-subᵣ : ∀{x₁ x₂ y₁ y₂} → (x₁ < x₂) → (y₁ ≤ y₂) → ((x₁ + y₁) < (x₂ + y₂))
-- Theory defining the axioms of an ordered field (a field with a weak total order).
record OrderedField ⦃ equiv : Equiv{ℓₑ}(F) ⦄ (_+_ _⋅_ : F → F → F) (_≤_ : F → F → Stmt{ℓₗ}) : Type{Lvl.of(F) Lvl.⊔ ℓₗ Lvl.⊔ ℓₑ} where
field
⦃ [+][⋅]-field ⦄ : Field(_+_)(_⋅_)
⦃ ordered ⦄ : Ordered(_+_)(_⋅_)(_≤_)
open Field([+][⋅]-field) public
open Ordered(ordered) public
| 39.917127
| 207
| 0.505052
|
4dd08a6a469b53f09b204d9e2045cefa41681e20
| 4,752
|
agda
|
Agda
|
BasicT/Metatheory/GentzenNormalForm-Unknown.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicT/Metatheory/GentzenNormalForm-Unknown.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicT/Metatheory/GentzenNormalForm-Unknown.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
module BasicT.Metatheory.GentzenNormalForm-Unknown where
open import BasicT.Syntax.GentzenNormalForm public
-- Forcing. (In a particular model?)
infix 3 _⊩_
_⊩_ : Cx Ty → Ty → Set
Γ ⊩ α P = Γ ⊢ⁿᶠ α P
Γ ⊩ A ▻ B = Γ ⊢ⁿᵉ A ▻ B ⊎ ∀ {Γ′} → Γ ⊆ Γ′ → Γ′ ⊩ A → Γ′ ⊩ B
Γ ⊩ A ∧ B = Γ ⊢ⁿᵉ A ∧ B ⊎ Γ ⊩ A × Γ ⊩ B
Γ ⊩ ⊤ = Γ ⊢ⁿᶠ ⊤
Γ ⊩ BOOL = Γ ⊢ⁿᶠ BOOL
Γ ⊩ NAT = Γ ⊢ⁿᶠ NAT
infix 3 _⊩⋆_
_⊩⋆_ : Cx Ty → Cx Ty → Set
Γ ⊩⋆ ∅ = 𝟙
Γ ⊩⋆ Ξ , A = Γ ⊩⋆ Ξ × Γ ⊩ A
-- Monotonicity with respect to context inclusion.
mono⊩ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩ A → Γ′ ⊩ A
mono⊩ {α P} η t = mono⊢ⁿᶠ η t
mono⊩ {A ▻ B} η (ι₁ t) = ι₁ (mono⊢ⁿᵉ η t)
mono⊩ {A ▻ B} η (ι₂ s) = ι₂ (λ η′ a → s (trans⊆ η η′) a)
mono⊩ {A ∧ B} η (ι₁ t) = ι₁ (mono⊢ⁿᵉ η t)
mono⊩ {A ∧ B} η (ι₂ s) = ι₂ (mono⊩ {A} η (π₁ s) , mono⊩ {B} η (π₂ s))
mono⊩ {⊤} η t = mono⊢ⁿᶠ η t
mono⊩ {BOOL} η t = mono⊢ⁿᶠ η t
mono⊩ {NAT} η t = mono⊢ⁿᶠ η t
mono⊩⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊩⋆ Ξ → Γ′ ⊩⋆ Ξ
mono⊩⋆ {∅} η ∙ = ∙
mono⊩⋆ {Ξ , A} η (γ , a) = mono⊩⋆ {Ξ} η γ , mono⊩ {A} η a
-- Soundness and completeness. (With respect to a particular model?)
reflect : ∀ {A Γ} → Γ ⊢ⁿᵉ A → Γ ⊩ A
reflect {α P} t = neⁿᶠ t
reflect {A ▻ B} t = ι₁ t
reflect {A ∧ B} t = ι₁ t
reflect {⊤} t = neⁿᶠ t
reflect {BOOL} t = neⁿᶠ t
reflect {NAT} t = neⁿᶠ t
reify : ∀ {A Γ} → Γ ⊩ A → Γ ⊢ⁿᶠ A
reify {α P} t = t
reify {A ▻ B} (ι₁ t) = neⁿᶠ t
reify {A ▻ B} (ι₂ s) = lamⁿᶠ (reify (s weak⊆ (reflect {A} (varⁿᵉ top))))
reify {A ∧ B} (ι₁ t) = neⁿᶠ t
reify {A ∧ B} (ι₂ s) = pairⁿᶠ (reify (π₁ s)) (reify (π₂ s))
reify {⊤} t = t
reify {BOOL} t = t
reify {NAT} t = t
reflect⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ⁿᵉ Ξ → Γ ⊩⋆ Ξ
reflect⋆ {∅} ∙ = ∙
reflect⋆ {Ξ , A} (ts , t) = reflect⋆ ts , reflect t
reify⋆ : ∀ {Ξ Γ} → Γ ⊩⋆ Ξ → Γ ⊢⋆ⁿᶠ Ξ
reify⋆ {∅} ∙ = ∙
reify⋆ {Ξ , A} (ts , t) = reify⋆ ts , reify t
-- Additional useful equipment.
_⟪$⟫_ : ∀ {A B w} → w ⊩ A ▻ B → w ⊩ A → w ⊩ B
ι₁ t ⟪$⟫ a = reflect (appⁿᵉ t (reify a))
ι₂ s ⟪$⟫ a = s refl⊆ a
⟪π₁⟫ : ∀ {A B w} → w ⊩ A ∧ B → w ⊩ A
⟪π₁⟫ (ι₁ t) = reflect (fstⁿᵉ t)
⟪π₁⟫ (ι₂ s) = π₁ s
⟪π₂⟫ : ∀ {A B w} → w ⊩ A ∧ B → w ⊩ B
⟪π₂⟫ (ι₁ t) = reflect (sndⁿᵉ t)
⟪π₂⟫ (ι₂ s) = π₂ s
⟪if⟫ : ∀ {C w} → w ⊩ BOOL → w ⊩ C → w ⊩ C → w ⊩ C
⟪if⟫ {C} (neⁿᶠ t) s₂ s₃ = reflect {C} (ifⁿᵉ t (reify s₂) (reify s₃))
⟪if⟫ {C} trueⁿᶠ s₂ s₃ = s₂
⟪if⟫ {C} falseⁿᶠ s₂ s₃ = s₃
⟪it⟫ : ∀ {C w} → w ⊩ NAT → w ⊩ C ▻ C → w ⊩ C → w ⊩ C
⟪it⟫ {C} (neⁿᶠ t) s₂ s₃ = reflect {C} (itⁿᵉ t (reify s₂) (reify s₃))
⟪it⟫ {C} zeroⁿᶠ s₂ s₃ = s₃
⟪it⟫ {C} (sucⁿᶠ t) s₂ s₃ = s₂ ⟪$⟫ ⟪it⟫ t s₂ s₃
⟪rec⟫ : ∀ {C w} → w ⊩ NAT → w ⊩ NAT ▻ C ▻ C → w ⊩ C → w ⊩ C
⟪rec⟫ {C} (neⁿᶠ t) s₂ s₃ = reflect {C} (recⁿᵉ t (reify s₂) (reify s₃))
⟪rec⟫ {C} zeroⁿᶠ s₂ s₃ = s₃
⟪rec⟫ {C} (sucⁿᶠ t) s₂ s₃ = (s₂ ⟪$⟫ t) ⟪$⟫ ⟪rec⟫ t s₂ s₃
-- Forcing for sequents. (In a particular world of a particular model?)
infix 3 _⊩_⇒_
_⊩_⇒_ : Cx Ty → Cx Ty → Ty → Set
w ⊩ Γ ⇒ A = w ⊩⋆ Γ → w ⊩ A
infix 3 _⊩_⇒⋆_
_⊩_⇒⋆_ : Cx Ty → Cx Ty → Cx Ty → Set
w ⊩ Γ ⇒⋆ Ξ = w ⊩⋆ Γ → w ⊩⋆ Ξ
-- Entailment. (Forcing in all worlds of all models, for sequents?)
infix 3 _⊨_
_⊨_ : Cx Ty → Ty → Set
Γ ⊨ A = ∀ {w : Cx Ty} → w ⊩ Γ ⇒ A
infix 3 _⊨⋆_
_⊨⋆_ : Cx Ty → Cx Ty → Set
Γ ⊨⋆ Ξ = ∀ {w : Cx Ty} → w ⊩ Γ ⇒⋆ Ξ
-- Additional useful equipment, for sequents.
lookup : ∀ {A Γ w} → A ∈ Γ → w ⊩ Γ ⇒ A
lookup top (γ , a) = a
lookup (pop i) (γ , b) = lookup i γ
-- Evaluation. (Soundness with respect to all models?)
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (lam t) γ = ι₂ (λ η a → eval t (mono⊩⋆ η γ , a))
eval (app t u) γ = eval t γ ⟪$⟫ eval u γ
eval (pair t u) γ = ι₂ (eval t γ , eval u γ)
eval (fst t) γ = ⟪π₁⟫ (eval t γ)
eval (snd t) γ = ⟪π₂⟫ (eval t γ)
eval unit γ = unitⁿᶠ
eval true γ = trueⁿᶠ
eval false γ = trueⁿᶠ
eval (if {C} t u v) γ = ⟪if⟫ {C} (eval t γ) (eval u γ) (eval v γ)
eval zero γ = zeroⁿᶠ
eval (suc t) γ = sucⁿᶠ (eval t γ)
eval (it {C} t u v) γ = ⟪it⟫ {C} (eval t γ) (eval u γ) (eval v γ)
eval (rec {C} t u v) γ = ⟪rec⟫ {C} (eval t γ) (eval u γ) (eval v γ)
eval⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊨⋆ Ξ
eval⋆ {∅} ∙ γ = ∙
eval⋆ {Ξ , A} (ts , t) γ = eval⋆ ts γ , eval t γ
-- Reflexivity and transitivity.
refl⊩⋆ : ∀ {Γ} → Γ ⊩⋆ Γ
refl⊩⋆ = reflect⋆ refl⊢⋆ⁿᵉ
trans⊩⋆ : ∀ {Γ Γ′ Γ″} → Γ ⊩⋆ Γ′ → Γ′ ⊩⋆ Γ″ → Γ ⊩⋆ Γ″
trans⊩⋆ ts us = eval⋆ (trans⊢⋆ (nf→tm⋆ (reify⋆ ts)) (nf→tm⋆ (reify⋆ us))) refl⊩⋆
-- Quotation. (Completeness with respect to all models?)
quot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A
quot s = nf→tm (reify (s refl⊩⋆))
-- Normalisation by evaluation.
norm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A
norm = quot ∘ eval
-- TODO: Correctness of normalisation with respect to conversion.
| 27.468208
| 80
| 0.481481
|
505cf2e4dffd5df6256f07ca776f249a85888023
| 1,599
|
agda
|
Agda
|
Cubical/HITs/FiniteMultiset/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/HITs/FiniteMultiset/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/FiniteMultiset/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | 1
|
2021-11-22T02:02:01.000Z
|
2021-11-22T02:02:01.000Z
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.FiniteMultiset.Base where
open import Cubical.Foundations.Prelude
open import Cubical.HITs.SetTruncation
open import Cubical.Foundations.HLevels
private
variable
ℓ : Level
A : Type ℓ
infixr 5 _∷_
data FMSet (A : Type ℓ) : Type ℓ where
[] : FMSet A
_∷_ : (x : A) → (xs : FMSet A) → FMSet A
comm : ∀ x y xs → x ∷ y ∷ xs ≡ y ∷ x ∷ xs
trunc : isSet (FMSet A)
pattern [_] x = x ∷ []
module Elim {ℓ'} {B : FMSet A → Type ℓ'}
([]* : B []) (_∷*_ : (x : A) {xs : FMSet A} → B xs → B (x ∷ xs))
(comm* : (x y : A) {xs : FMSet A} (b : B xs)
→ PathP (λ i → B (comm x y xs i)) (x ∷* (y ∷* b)) (y ∷* (x ∷* b)))
(trunc* : (xs : FMSet A) → isSet (B xs)) where
f : (xs : FMSet A) → B xs
f [] = []*
f (x ∷ xs) = x ∷* f xs
f (comm x y xs i) = comm* x y (f xs) i
f (trunc xs zs p q i j) =
isOfHLevel→isOfHLevelDep 2 trunc* (f xs) (f zs) (cong f p) (cong f q) (trunc xs zs p q) i j
module ElimProp {ℓ'} {B : FMSet A → Type ℓ'} (BProp : {xs : FMSet A} → isProp (B xs))
([]* : B []) (_∷*_ : (x : A) {xs : FMSet A} → B xs → B (x ∷ xs)) where
f : (xs : FMSet A) → B xs
f = Elim.f []* _∷*_
(λ x y {xs} b →
toPathP (BProp (transp (λ i → B (comm x y xs i)) i0 (x ∷* (y ∷* b))) (y ∷* (x ∷* b))))
(λ xs → isProp→isSet BProp)
module Rec {ℓ'} {B : Type ℓ'} (BType : isSet B)
([]* : B) (_∷*_ : A → B → B)
(comm* : (x y : A) (b : B) → x ∷* (y ∷* b) ≡ y ∷* (x ∷* b)) where
f : FMSet A → B
f = Elim.f []* (λ x b → x ∷* b) (λ x y b → comm* x y b) (λ _ → BType)
| 31.352941
| 96
| 0.484678
|
0b1222e2250b2c163aec6deaaf6fb91cff471331
| 8,142
|
agda
|
Agda
|
Cubical/HITs/Cylinder/Base.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/HITs/Cylinder/Base.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Cylinder/Base.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.HITs.Cylinder.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
open import Cubical.Data.Unit
open import Cubical.Data.Sum using (_⊎_; inl; inr)
open import Cubical.HITs.PropositionalTruncation using (∥_∥₁; ∣_∣₁; squash₁)
open import Cubical.HITs.Interval using (Interval; zero; one; seg)
-- Cylinder A is a cylinder object in the category of cubical types.
--
-- https://ncatlab.org/nlab/show/cylinder+object
data Cylinder {ℓ} (A : Type ℓ) : Type ℓ where
inl : A → Cylinder A
inr : A → Cylinder A
cross : ∀ x → inl x ≡ inr x
-- Dual to this is the cocylinder or path space object.
--
-- https://ncatlab.org/nlab/show/path+space+object
Cocylinder : ∀ {ℓ} → Type ℓ → Type ℓ
Cocylinder A = Interval → A
module _ {ℓ} {A : Type ℓ} where
-- The cylinder is part of a factorization of the obvious mapping
-- of type A ⊎ A → A into a pair of mappings:
--
-- A ⊎ A → Cylinder A ≃ A
--
-- include is the first part of the factorization.
include : A ⊎ A → Cylinder A
include (inl x) = inl x
include (inr x) = inr x
-- The above inclusion is surjective
includeSurjective : ∀ c → ∃[ s ∈ A ⊎ A ] include s ≡ c
includeSurjective (inl x) = ∣ inl x , refl ∣₁
includeSurjective (inr x) = ∣ inr x , refl ∣₁
includeSurjective (cross x i) =
squash₁
∣ inl x , (λ j → cross x (i ∧ j)) ∣₁
∣ inr x , (λ j → cross x (i ∨ ~ j)) ∣₁
i
elim
: ∀{ℓ'} {B : Cylinder A → Type ℓ'}
→ (f : (x : A) → B (inl x))
→ (g : (x : A) → B (inr x))
→ (p : ∀ x → PathP (λ i → B (cross x i)) (f x) (g x))
→ (c : Cylinder A) → B c
elim f _ _ (inl x) = f x
elim _ g _ (inr x) = g x
elim _ _ p (cross x i) = p x i
private
out : Cylinder A → A
out (inl x) = x
out (inr x) = x
out (cross x i) = x
inl-out : (c : Cylinder A) → inl (out c) ≡ c
inl-out (inl x) = refl
inl-out (inr x) = cross x
inl-out (cross x i) = λ j → cross x (i ∧ j)
out-inl : ∀(x : A) → out (inl x) ≡ x
out-inl x = refl
-- The second part of the factorization above.
CylinderA≃A : Cylinder A ≃ A
CylinderA≃A = isoToEquiv (iso out inl out-inl inl-out)
-- The cocylinder has a similar equivalence that is part
-- of factorizing the diagonal mapping.
private
inco : A → Cocylinder A
inco x _ = x
outco : Cocylinder A → A
outco f = f zero
A→CocylinderA→A : (x : A) → outco (inco x) ≡ x
A→CocylinderA→A x = refl
CocylinderA→A→CocylinderA : (c : Cocylinder A) → inco (outco c) ≡ c
CocylinderA→A→CocylinderA c j zero = c zero
CocylinderA→A→CocylinderA c j one = c (seg j)
CocylinderA→A→CocylinderA c j (seg i) = c (seg (j ∧ i))
A≃CocylinderA : A ≃ Cocylinder A
A≃CocylinderA =
isoToEquiv (iso inco outco CocylinderA→A→CocylinderA A→CocylinderA→A)
project : Cocylinder A → A × A
project c = c zero , c one
-- Since we can construct cylinders for every type, Cylinder actually
-- constitutes a cylinder functor:
--
-- https://ncatlab.org/nlab/show/cylinder+functor
--
-- e₀ = inl
-- e₁ = inr
-- σ = out
module Functorial where
private
variable
ℓa ℓb ℓc : Level
A : Type ℓa
B : Type ℓb
C : Type ℓc
map : (A → B) → Cylinder A → Cylinder B
map f (inl x) = inl (f x)
map f (inr x) = inr (f x)
map f (cross x i) = cross (f x) i
mapId : map (λ(x : A) → x) ≡ (λ x → x)
mapId i (inl x) = inl x
mapId i (inr x) = inr x
mapId i (cross x j) = cross x j
map∘
: (f : A → B) → (g : B → C)
→ map (λ x → g (f x)) ≡ (λ x → map g (map f x))
map∘ f g i (inl x) = inl (g (f x))
map∘ f g i (inr x) = inr (g (f x))
map∘ f g i (cross x j) = cross (g (f x)) j
-- There is an adjunction between the cylinder and coyclinder
-- functors.
--
-- Cylinder ⊣ Cocylinder
adj₁ : (Cylinder A → B) → A → Cocylinder B
adj₁ f x zero = f (inl x)
adj₁ f x one = f (inr x)
adj₁ f x (seg i) = f (cross x i)
adj₂ : (A → Cocylinder B) → Cylinder A → B
adj₂ g (inl x) = g x zero
adj₂ g (inr x) = g x one
adj₂ g (cross x i) = g x (seg i)
adj₁₂ : (g : A → Cocylinder B) → adj₁ (adj₂ g) ≡ g
adj₁₂ g _ x zero = g x zero
adj₁₂ g _ x one = g x one
adj₁₂ g _ x (seg i) = g x (seg i)
adj₂₁ : (f : Cylinder A → B) → adj₂ (adj₁ f) ≡ f
adj₂₁ f j (inl x) = f (inl x)
adj₂₁ f j (inr x) = f (inr x)
adj₂₁ f j (cross x i) = f (cross x i)
module IntervalEquiv where
-- There is an equivalence between the interval and the
-- cylinder over the unit type.
Interval→CylinderUnit : Interval → Cylinder Unit
Interval→CylinderUnit zero = inl _
Interval→CylinderUnit one = inr _
Interval→CylinderUnit (seg i) = cross _ i
CylinderUnit→Interval : Cylinder Unit → Interval
CylinderUnit→Interval (inl _) = zero
CylinderUnit→Interval (inr _) = one
CylinderUnit→Interval (cross _ i) = seg i
Interval→CylinderUnit→Interval
: ∀ i → CylinderUnit→Interval (Interval→CylinderUnit i) ≡ i
Interval→CylinderUnit→Interval zero = refl
Interval→CylinderUnit→Interval one = refl
Interval→CylinderUnit→Interval (seg i) = refl
CylinderUnit→Interval→CylinderUnit
: ∀ c → Interval→CylinderUnit (CylinderUnit→Interval c) ≡ c
CylinderUnit→Interval→CylinderUnit (inl _) = refl
CylinderUnit→Interval→CylinderUnit (inr _) = refl
CylinderUnit→Interval→CylinderUnit (cross _ i) = refl
CylinderUnit≃Interval : Cylinder Unit ≃ Interval
CylinderUnit≃Interval =
isoToEquiv (iso CylinderUnit→Interval Interval→CylinderUnit Interval→CylinderUnit→Interval CylinderUnit→Interval→CylinderUnit)
-- More generally, there is an equivalence between the cylinder
-- over any type A and the product of A and the interval.
module _ {ℓ} {A : Type ℓ} where
private
Cyl : Type ℓ
Cyl = A × Interval
CylinderA→A×Interval : Cylinder A → Cyl
CylinderA→A×Interval (inl x) = x , zero
CylinderA→A×Interval (inr x) = x , one
CylinderA→A×Interval (cross x i) = x , seg i
A×Interval→CylinderA : Cyl → Cylinder A
A×Interval→CylinderA (x , zero) = inl x
A×Interval→CylinderA (x , one) = inr x
A×Interval→CylinderA (x , seg i) = cross x i
A×Interval→CylinderA→A×Interval
: ∀ c → CylinderA→A×Interval (A×Interval→CylinderA c) ≡ c
A×Interval→CylinderA→A×Interval (x , zero) = refl
A×Interval→CylinderA→A×Interval (x , one) = refl
A×Interval→CylinderA→A×Interval (x , seg i) = refl
CylinderA→A×Interval→CylinderA
: ∀ c → A×Interval→CylinderA (CylinderA→A×Interval c) ≡ c
CylinderA→A×Interval→CylinderA (inl x) = refl
CylinderA→A×Interval→CylinderA (inr x) = refl
CylinderA→A×Interval→CylinderA (cross x i) = refl
CylinderA≃A×Interval : Cylinder A ≃ Cyl
CylinderA≃A×Interval =
isoToEquiv
(iso CylinderA→A×Interval
A×Interval→CylinderA
A×Interval→CylinderA→A×Interval
CylinderA→A×Interval→CylinderA)
-- The cylinder is also the pushout of the identity on A with itself.
module Push {ℓ} {A : Type ℓ} where
open import Cubical.HITs.Pushout
private
Push : Type ℓ
Push = Pushout (λ(x : A) → x) (λ x → x)
Cyl : Type ℓ
Cyl = Cylinder A
Cylinder→Pushout : Cyl → Push
Cylinder→Pushout (inl x) = inl x
Cylinder→Pushout (inr x) = inr x
Cylinder→Pushout (cross x i) = push x i
Pushout→Cylinder : Push → Cyl
Pushout→Cylinder (inl x) = inl x
Pushout→Cylinder (inr x) = inr x
Pushout→Cylinder (push x i) = cross x i
Pushout→Cylinder→Pushout : ∀ p → Cylinder→Pushout (Pushout→Cylinder p) ≡ p
Pushout→Cylinder→Pushout (inl x) = refl
Pushout→Cylinder→Pushout (inr x) = refl
Pushout→Cylinder→Pushout (push x i) = refl
Cylinder→Pushout→Cylinder : ∀ c → Pushout→Cylinder (Cylinder→Pushout c) ≡ c
Cylinder→Pushout→Cylinder (inl x) = refl
Cylinder→Pushout→Cylinder (inr x) = refl
Cylinder→Pushout→Cylinder (cross x i) = refl
Pushout≃Cylinder : Push ≃ Cyl
Pushout≃Cylinder =
isoToEquiv
(iso Pushout→Cylinder
Cylinder→Pushout
Cylinder→Pushout→Cylinder
Pushout→Cylinder→Pushout)
| 30.380597
| 130
| 0.633014
|
5814af5d6f6444f3c3fa158b708322333324e12f
| 12,686
|
agda
|
Agda
|
theorems/cw/cohomology/ReconstructedCochainsEquivCellularCochains.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
theorems/cw/cohomology/ReconstructedCochainsEquivCellularCochains.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
theorems/cw/cohomology/ReconstructedCochainsEquivCellularCochains.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cw.CW
open import cw.FinCW
open import cw.FinBoundary
open import cohomology.Theory
open import cohomology.ChainComplex
module cw.cohomology.ReconstructedCochainsEquivCellularCochains
(OT : OrdinaryTheory lzero) where
open OrdinaryTheory OT
open import cw.cohomology.cellular.ChainComplex as CCC
open import cw.cohomology.reconstructed.cochain.Complex OT as RCC
open import cw.cohomology.ReconstructedCochainsIsoCellularCochains OT
open import cw.cohomology.cochainequiv.AugmentCommSquare OT
open import cw.cohomology.cochainequiv.FirstCoboundaryCommSquare OT
open import cw.cohomology.cochainequiv.HigherCoboundaryCommSquare OT
private
frcc-comm-fccc-Type : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n)
{m} (m≤n? : Dec (m ≤ n)) (Sm≤n? : Dec (S m ≤ n))
(coboundary : AbGroup.grp (RCC.cochain-template ⊙⦉ ⊙fin-skel ⦊ m≤n?)
→ᴳ AbGroup.grp (RCC.cochain-template ⊙⦉ ⊙fin-skel ⦊ Sm≤n?))
(boundary : AbGroup.grp (CCC.chain-template ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ Sm≤n?)
→ᴳ AbGroup.grp (CCC.chain-template ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ m≤n?))
→ Type₀
frcc-comm-fccc-Type {n} ⊙fin-skel {m} m≤n? Sm≤n? coboundary boundary =
CommSquareᴳ
coboundary
(pre∘ᴳ-hom (C2-abgroup 0) boundary)
(GroupIso.f-hom (rcc-iso-ccc-template ⊙⦉ ⊙fin-skel ⦊ m≤n?
(⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero)))
(GroupIso.f-hom (rcc-iso-ccc-template ⊙⦉ ⊙fin-skel ⦊ Sm≤n?
(⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero)))
CCC-boundary-template' : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n)
→ {m : ℕ} (m≤n? : Dec (m ≤ n)) (Sm≤n? : Dec (S m ≤ n))
→ AbGroup.grp (CCC.chain-template ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ Sm≤n?)
→ᴳ AbGroup.grp (CCC.chain-template ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊ m≤n?)
CCC-boundary-template' ⊙fin-skel =
CCC.boundary-template ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))
RCC-coboundary-template' : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n)
→ {m : ℕ} (m≤n? : Dec (m ≤ n)) (Sm≤n? : Dec (S m ≤ n))
→ AbGroup.grp (RCC.cochain-template ⊙⦉ ⊙fin-skel ⦊ m≤n?)
→ᴳ AbGroup.grp (RCC.cochain-template ⊙⦉ ⊙fin-skel ⦊ Sm≤n?)
RCC-coboundary-template' ⊙fin-skel = RCC.coboundary-template ⊙⦉ ⊙fin-skel ⦊
abstract
{- This can be directly generalized to the non-finite cases. -}
frcc-comm-fccc-above : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n)
{m} (m≤n? : Dec (m ≤ n)) (Sm≰n : ¬ (S m ≤ n))
→ frcc-comm-fccc-Type ⊙fin-skel m≤n? (inr Sm≰n)
(RCC-coboundary-template' ⊙fin-skel m≤n? (inr Sm≰n))
(CCC-boundary-template' ⊙fin-skel m≤n? (inr Sm≰n))
frcc-comm-fccc-above ⊙fin-skel m≤n? Sm≰n =
(comm-sqrᴳ λ g → group-hom= $ λ= λ _ →
! $ GroupHom.pres-ident
(GroupIso.f
(rcc-iso-ccc-template ⊙⦉ ⊙fin-skel ⦊ m≤n?
(⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero)) g))
frcc-comm-fccc-nth-zero : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) (0≤n : 0 ≤ n) (1≤n : 1 ≤ n)
→ frcc-comm-fccc-Type ⊙fin-skel (inl 0≤n) (inl 1≤n)
(RCC-coboundary-template' ⊙fin-skel (inl 0≤n) (inl 1≤n))
(CCC-boundary-template' ⊙fin-skel (inl 0≤n) (inl 1≤n))
frcc-comm-fccc-nth-zero ⊙fin-skel (inl idp) (inl 1=0) = ⊥-rec (ℕ-S≠O O 1=0)
frcc-comm-fccc-nth-zero ⊙fin-skel (inl idp) (inr ())
frcc-comm-fccc-nth-zero ⊙fin-skel (inr ltS) (inl 1=1) =
transport!
(λ 1=1 → frcc-comm-fccc-Type ⊙fin-skel (inl lteS) (inl (inl 1=1))
(RCC-coboundary-template' ⊙fin-skel (inl lteS) (inl (inl 1=1)))
(CCC-boundary-template' ⊙fin-skel (inl lteS) (inl (inl 1=1))))
(prop-has-all-paths 1=1 idp)
(coe!
(ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel {m = O} (inl (inr ltS)) (inl (inl idp)) p₁ p₂)
(RCC.coboundary-first-template-β ⊙⦉ ⊙fin-skel ⦊)
(CCC.boundary-template-β ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))))
(fst (first-coboundary-comm-sqrᴳ ⊙fin-skel)))
frcc-comm-fccc-nth-zero ⊙fin-skel (inr ltS) (inr (ltSR ()))
frcc-comm-fccc-nth-zero ⊙fin-skel (inr (ltSR 0<n)) (inl 1=Sn) = ⊥-rec (<-to-≠ (<-ap-S 0<n) 1=Sn)
frcc-comm-fccc-nth-zero ⊙fin-skel (inr (ltSR ltS)) (inr 1<2) =
transport!
(λ 1<2 → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr 1<2))
(RCC-coboundary-template' ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr 1<2)))
(CCC-boundary-template' ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr 1<2))))
(prop-has-all-paths 1<2 ltS)
(coe!
(ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr ltS)) p₁ p₂)
(RCC.coboundary-first-template-descend-from-two ⊙⦉ ⊙fin-skel ⦊)
(CCC.boundary-template-descend-from-two-above ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))))
(frcc-comm-fccc-nth-zero (⊙fcw-init ⊙fin-skel) (inr ltS) (inl idp)))
frcc-comm-fccc-nth-zero ⊙fin-skel (inr (ltSR (ltSR ()))) (inr ltS)
frcc-comm-fccc-nth-zero ⊙fin-skel (inr (ltSR (ltSR 0<n))) (inr (ltSR 1<Sn)) =
(coe!
(ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR (ltSR 0<n)))) (inl (inr (ltSR 1<Sn))) p₁ p₂)
(RCC.coboundary-first-template-descend-from-far ⊙⦉ ⊙fin-skel ⦊ (ltSR 0<n) 1<Sn)
(CCC.boundary-template-descend-from-far ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))
(ltSR 0<n) 1<Sn))
(frcc-comm-fccc-nth-zero (⊙fcw-init ⊙fin-skel) (inr (ltSR 0<n)) (inr 1<Sn)))
frcc-comm-fccc-nth-higher : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) {m} (Sm≤n : S m ≤ n) (SSm≤n : S (S m) ≤ n)
→ frcc-comm-fccc-Type ⊙fin-skel (inl Sm≤n) (inl SSm≤n)
(RCC-coboundary-template' ⊙fin-skel (inl Sm≤n) (inl SSm≤n))
(CCC-boundary-template' ⊙fin-skel (inl Sm≤n) (inl SSm≤n))
frcc-comm-fccc-nth-higher ⊙fin-skel (inl idp) (inl SSm=Sm) = ⊥-rec (<-to-≠ ltS (! SSm=Sm))
frcc-comm-fccc-nth-higher ⊙fin-skel (inl idp) (inr SSm<Sm) = ⊥-rec (<-to-≠ (<-trans SSm<Sm ltS) idp)
frcc-comm-fccc-nth-higher ⊙fin-skel {m} (inr ltS) (inl SSm=SSm) =
transport!
(λ SSm=SSm → frcc-comm-fccc-Type ⊙fin-skel (inl lteS) (inl (inl SSm=SSm))
(RCC-coboundary-template' ⊙fin-skel (inl lteS) (inl (inl SSm=SSm)))
(CCC-boundary-template' ⊙fin-skel (inl lteS) (inl (inl SSm=SSm))))
(prop-has-all-paths SSm=SSm idp)
(coe!
(ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel {m = S m} (inl (inr ltS)) (inl (inl idp)) p₁ p₂)
(RCC.coboundary-higher-template-β ⊙⦉ ⊙fin-skel ⦊)
(CCC.boundary-template-β ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))))
(fst (higher-coboundary-comm-sqrᴳ ⊙fin-skel)))
frcc-comm-fccc-nth-higher ⊙fin-skel (inr ltS) (inr SSm<SSm) = ⊥-rec (<-to-≠ SSm<SSm idp)
frcc-comm-fccc-nth-higher ⊙fin-skel (inr (ltSR Sm<n)) (inl SSm=Sn) = ⊥-rec (<-to-≠ (<-ap-S Sm<n) SSm=Sn)
frcc-comm-fccc-nth-higher ⊙fin-skel (inr (ltSR ltS)) (inr SSm<SSSm) =
transport!
(λ SSm<SSSm → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr SSm<SSSm))
(RCC-coboundary-template' ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr SSm<SSSm)))
(CCC-boundary-template' ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr SSm<SSSm))))
(prop-has-all-paths SSm<SSSm ltS)
(coe!
(ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR ltS))) (inl (inr ltS)) p₁ p₂)
(RCC.coboundary-higher-template-descend-from-one-above ⊙⦉ ⊙fin-skel ⦊)
(CCC.boundary-template-descend-from-two-above ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))))
(frcc-comm-fccc-nth-higher (⊙fcw-init ⊙fin-skel) (inr ltS) (inl idp)))
frcc-comm-fccc-nth-higher ⊙fin-skel (inr (ltSR (ltSR Sm<Sm))) (inr ltS) = ⊥-rec (<-to-≠ Sm<Sm idp)
frcc-comm-fccc-nth-higher ⊙fin-skel (inr (ltSR (ltSR Sm<n))) (inr (ltSR SSm<Sn)) =
(coe!
(ap2 (λ p₁ p₂ → frcc-comm-fccc-Type ⊙fin-skel (inl (inr (ltSR (ltSR Sm<n)))) (inl (inr (ltSR SSm<Sn))) p₁ p₂)
(RCC.coboundary-higher-template-descend-from-far ⊙⦉ ⊙fin-skel ⦊ (ltSR Sm<n) SSm<Sn)
(CCC.boundary-template-descend-from-far ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))
(ltSR Sm<n) SSm<Sn))
(frcc-comm-fccc-nth-higher (⊙fcw-init ⊙fin-skel) (inr (ltSR Sm<n)) (inr SSm<Sn)))
frcc-comm-fccc-template : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n)
{m} (m≤n? : Dec (m ≤ n)) (Sm≤n? : Dec (S m ≤ n))
→ frcc-comm-fccc-Type ⊙fin-skel m≤n? Sm≤n?
(RCC-coboundary-template' ⊙fin-skel m≤n? Sm≤n?)
(CCC-boundary-template' ⊙fin-skel m≤n? Sm≤n?)
frcc-comm-fccc-template ⊙fin-skel m≤n? (inr Sm≰n) = frcc-comm-fccc-above ⊙fin-skel m≤n? Sm≰n
frcc-comm-fccc-template ⊙fin-skel (inr m≰n) (inl Sm≤n) = ⊥-rec $ m≰n (≤-trans lteS Sm≤n)
frcc-comm-fccc-template ⊙fin-skel {m = O} (inl m≤n) (inl Sm≤n) = frcc-comm-fccc-nth-zero ⊙fin-skel m≤n Sm≤n
frcc-comm-fccc-template ⊙fin-skel {m = S m} (inl Sm≤n) (inl SSm≤n) = frcc-comm-fccc-nth-higher ⊙fin-skel Sm≤n SSm≤n
frcc-comm-fccc : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) m
→ frcc-comm-fccc-Type ⊙fin-skel (≤-dec m n) (≤-dec (S m) n)
(RCC-coboundary-template' ⊙fin-skel (≤-dec m n) (≤-dec (S m) n))
(CCC-boundary-template' ⊙fin-skel (≤-dec m n) (≤-dec (S m) n))
frcc-comm-fccc {n} ⊙fin-skel m =
frcc-comm-fccc-template ⊙fin-skel {m} (≤-dec m n) (≤-dec (S m) n)
frcc-comm-fccc-augment : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n)
→ CommSquareᴳ
(CochainComplex.augment (RCC.cochain-complex ⊙⦉ ⊙fin-skel ⦊))
(pre∘ᴳ-hom (C2-abgroup 0) (FreeAbGroup-extend (Lift-abgroup {j = lzero} ℤ-abgroup) λ _ → lift 1))
(GroupIso.f-hom rhead-iso-chead)
(GroupIso.f-hom (rcc-iso-ccc-template ⊙⦉ ⊙fin-skel ⦊ (inl (O≤ n))
(⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero)))
frcc-comm-fccc-augment {n = O} ⊙fin-skel =
fst (augment-comm-sqrᴳ ⊙fin-skel)
frcc-comm-fccc-augment {n = S O} ⊙fin-skel =
frcc-comm-fccc-augment (⊙fcw-init ⊙fin-skel)
frcc-comm-fccc-augment {n = S (S n)} ⊙fin-skel =
frcc-comm-fccc-augment (⊙fcw-init ⊙fin-skel)
frcc-equiv-fccc : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) →
CochainComplexEquiv
(RCC.cochain-complex ⊙⦉ ⊙fin-skel ⦊)
(CCC.cochain-complex ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))
(C2-abgroup 0))
frcc-equiv-fccc {n} ⊙fin-skel = record
{ head = rhead-iso-chead
; cochain = λ m → rcc-iso-ccc ⊙⦉ ⊙fin-skel ⦊ m (⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero)
; augment = frcc-comm-fccc-augment ⊙fin-skel
; coboundary = frcc-comm-fccc ⊙fin-skel}
frc-iso-fcc : ∀ {n} (⊙fin-skel : ⊙FinSkeleton n) (m : ℤ)
→ cohomology-group (RCC.cochain-complex ⊙⦉ ⊙fin-skel ⦊) m
≃ᴳ cohomology-group
(CCC.cochain-complex ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))
(C2-abgroup 0))
m
frc-iso-fcc ⊙fin-skel = cohomology-group-emap (frcc-equiv-fccc ⊙fin-skel)
| 60.409524
| 121
| 0.590966
|
c7b035d7a9772cfa2fe12b5809254600aad53267
| 3,953
|
agda
|
Agda
|
Categories/Category/Monoidal/Core.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Monoidal/Core.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Monoidal/Core.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- Definition of Monoidal Category
-- Big design decision that differs from the previous version:
-- Do not go through "Functor.Power" to encode variables and work
-- at the level of NaturalIsomorphisms, instead work at the object/morphism
-- level, via the more direct _⊗₀_ _⊗₁_ _⊗- -⊗_.
-- The original design needed quite a few contortions to get things working,
-- but these are simply not needed when working directly with the morphisms.
--
-- Smaller design decision: export some items with long names
-- (unitorˡ, unitorʳ and associator), but internally work with the more classical
-- short greek names (λ, ρ and α respectively).
module Categories.Category.Monoidal.Core {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Function using (_$_)
open import Data.Product using (_×_; _,_; curry′)
open import Categories.Category.Product
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Bifunctor using (Bifunctor; appˡ; appʳ)
open import Categories.Functor.Properties using ([_]-resp-≅)
open import Categories.NaturalTransformation renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism
hiding (unitorˡ; unitorʳ; associator; _≃_)
open import Categories.Morphism C using (_≅_; module ≅)
open import Categories.Morphism.IsoEquiv C using (_≃_; ⌞_⌟)
open import Categories.Morphism.Isomorphism C using (_∘ᵢ_; lift-triangle′; lift-pentagon′)
open import Categories.Morphism.Reasoning C
private
module C = Category C
open C hiding (id; identityˡ; identityʳ; assoc)
open Commutation
private
variable
X Y Z W A B : Obj
f g h i a b : X ⇒ Y
record Monoidal : Set (o ⊔ ℓ ⊔ e) where
infixr 10 _⊗₀_ _⊗₁_
field
⊗ : Bifunctor C C C
unit : Obj
open Functor ⊗
_⊗₀_ : Obj → Obj → Obj
_⊗₀_ = curry′ F₀
-- this is also 'curry', but a very-dependent version
_⊗₁_ : X ⇒ Y → Z ⇒ W → X ⊗₀ Z ⇒ Y ⊗₀ W
f ⊗₁ g = F₁ (f , g)
_⊗- : Obj → Functor C C
X ⊗- = appˡ ⊗ X
-⊗_ : Obj → Functor C C
-⊗ X = appʳ ⊗ X
field
unitorˡ : unit ⊗₀ X ≅ X
unitorʳ : X ⊗₀ unit ≅ X
associator : (X ⊗₀ Y) ⊗₀ Z ≅ X ⊗₀ (Y ⊗₀ Z)
module unitorˡ {X} = _≅_ (unitorˡ {X = X})
module unitorʳ {X} = _≅_ (unitorʳ {X = X})
module associator {X} {Y} {Z} = _≅_ (associator {X} {Y} {Z})
-- for exporting, it makes sense to use the above long names, but for
-- internal consumption, the traditional (short!) categorical names are more
-- convenient. However, they are not symmetric, even though the concepts are, so
-- we'll use ⇒ and ⇐ arrows to indicate that
private
λ⇒ = unitorˡ.from
λ⇐ = unitorˡ.to
ρ⇒ = unitorʳ.from
ρ⇐ = unitorʳ.to
-- eta expansion fixes a problem in 2.6.1, will be reported
α⇒ = λ {X} {Y} {Z} → associator.from {X} {Y} {Z}
α⇐ = λ {X} {Y} {Z} → associator.to {X} {Y} {Z}
field
unitorˡ-commute-from : CommutativeSquare (C.id ⊗₁ f) λ⇒ λ⇒ f
unitorˡ-commute-to : CommutativeSquare f λ⇐ λ⇐ (C.id ⊗₁ f)
unitorʳ-commute-from : CommutativeSquare (f ⊗₁ C.id) ρ⇒ ρ⇒ f
unitorʳ-commute-to : CommutativeSquare f ρ⇐ ρ⇐ (f ⊗₁ C.id)
assoc-commute-from : CommutativeSquare ((f ⊗₁ g) ⊗₁ h) α⇒ α⇒ (f ⊗₁ (g ⊗₁ h))
assoc-commute-to : CommutativeSquare (f ⊗₁ (g ⊗₁ h)) α⇐ α⇐ ((f ⊗₁ g) ⊗₁ h)
triangle : [ (X ⊗₀ unit) ⊗₀ Y ⇒ X ⊗₀ Y ]⟨
α⇒ ⇒⟨ X ⊗₀ (unit ⊗₀ Y) ⟩
C.id ⊗₁ λ⇒
≈ ρ⇒ ⊗₁ C.id
⟩
pentagon : [ ((X ⊗₀ Y) ⊗₀ Z) ⊗₀ W ⇒ X ⊗₀ Y ⊗₀ Z ⊗₀ W ]⟨
α⇒ ⊗₁ C.id ⇒⟨ (X ⊗₀ Y ⊗₀ Z) ⊗₀ W ⟩
α⇒ ⇒⟨ X ⊗₀ (Y ⊗₀ Z) ⊗₀ W ⟩
C.id ⊗₁ α⇒
≈ α⇒ ⇒⟨ (X ⊗₀ Y) ⊗₀ Z ⊗₀ W ⟩
α⇒
⟩
| 35.936364
| 90
| 0.587655
|
5862f116dfc1fec464774c58da223427ef80d0e8
| 41,822
|
agda
|
Agda
|
Cubical/Homotopy/Group/Base.agda
|
MatthiasHu/cubical
|
58f2d0dd07e51f8aa5b348a522691097b6695d1c
|
[
"MIT"
] | 1
|
2022-03-05T00:29:00.000Z
|
2022-03-05T00:29:00.000Z
|
Cubical/Homotopy/Group/Base.agda
|
snu-development/cubical
|
58f2d0dd07e51f8aa5b348a522691097b6695d1c
|
[
"MIT"
] | null | null | null |
Cubical/Homotopy/Group/Base.agda
|
snu-development/cubical
|
58f2d0dd07e51f8aa5b348a522691097b6695d1c
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.Group.Base where
open import Cubical.Homotopy.Loopspace
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.GroupoidLaws renaming (assoc to ∙assoc)
open import Cubical.Foundations.Path
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Function
open import Cubical.Foundations.Transport
open import Cubical.Functions.Morphism
open import Cubical.HITs.SetTruncation
renaming (rec to sRec ; rec2 to sRec2
; elim to sElim ; elim2 to sElim2 ; elim3 to sElim3
; map to sMap)
open import Cubical.HITs.Truncation
renaming (rec to trRec ; elim to trElim ; elim2 to trElim2)
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp renaming (toSusp to σ)
open import Cubical.HITs.S1
open import Cubical.Data.Sigma
open import Cubical.Data.Nat
open import Cubical.Data.Bool
open import Cubical.Data.Unit
open import Cubical.Algebra.Group
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open Iso
open IsGroup
open IsSemigroup
open IsMonoid
open GroupStr
{- Homotopy group -}
π : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → Type ℓ
π n A = ∥ typ ((Ω^ n) A) ∥₂
{- Alternative formulation. This will be given a group structure in
the Properties file -}
π' : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → Type ℓ
π' n A = ∥ S₊∙ n →∙ A ∥₂
{- π as a group -}
1π : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π n A
1π zero {A = A} = ∣ pt A ∣₂
1π (suc n) = ∣ refl ∣₂
·π : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π (suc n) A → π (suc n) A → π (suc n) A
·π n = sRec2 squash₂ λ p q → ∣ p ∙ q ∣₂
-π : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π (suc n) A → π (suc n) A
-π n = sMap sym
π-rUnit : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π (suc n) A)
→ (·π n x (1π (suc n))) ≡ x
π-rUnit n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ rUnit p (~ i) ∣₂
π-lUnit : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π (suc n) A)
→ (·π n (1π (suc n)) x) ≡ x
π-lUnit n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ lUnit p (~ i) ∣₂
π-rCancel : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π (suc n) A)
→ (·π n x (-π n x)) ≡ 1π (suc n)
π-rCancel n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ rCancel p i ∣₂
π-lCancel : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π (suc n) A)
→ (·π n (-π n x) x) ≡ 1π (suc n)
π-lCancel n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ lCancel p i ∣₂
π-assoc : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x y z : π (suc n) A)
→ ·π n x (·π n y z) ≡ ·π n (·π n x y) z
π-assoc n = sElim3 (λ _ _ _ → isSetPathImplicit) λ p q r i → ∣ ∙assoc p q r i ∣₂
π-comm : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x y : π (suc (suc n)) A)
→ ·π (suc n) x y ≡ ·π (suc n) y x
π-comm n = sElim2 (λ _ _ → isSetPathImplicit) λ p q i → ∣ EH n p q i ∣₂
-- πₙ₊₁
πGr : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → Group ℓ
fst (πGr n A) = π (suc n) A
1g (snd (πGr n A)) = 1π (suc n)
GroupStr._·_ (snd (πGr n A)) = ·π n
inv (snd (πGr n A)) = -π n
is-set (isSemigroup (isMonoid (isGroup (snd (πGr n A))))) = squash₂
assoc (isSemigroup (isMonoid (isGroup (snd (πGr n A))))) = π-assoc n
identity (isMonoid (isGroup (snd (πGr n A)))) x = (π-rUnit n x) , (π-lUnit n x)
inverse (isGroup (snd (πGr n A))) x = (π-rCancel n x) , (π-lCancel n x)
-- Group operations on π'.
-- We define the corresponding structure on the untruncated
-- (S₊∙ n →∙ A).
∙Π : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (S₊∙ n →∙ A)
→ (S₊∙ n →∙ A)
→ (S₊∙ n →∙ A)
∙Π {A = A} {n = zero} p q = (λ _ → pt A) , refl
fst (∙Π {A = A} {n = suc zero} (f , p) (g , q)) base = pt A
fst (∙Π {A = A} {n = suc zero} (f , p) (g , q)) (loop j) =
((sym p ∙∙ cong f loop ∙∙ p) ∙ (sym q ∙∙ cong g loop ∙∙ q)) j
snd (∙Π {A = A} {n = suc zero} (f , p) (g , q)) = refl
fst (∙Π {A = A} {n = suc (suc n)} (f , p) (g , q)) north = pt A
fst (∙Π {A = A} {n = suc (suc n)} (f , p) (g , q)) south = pt A
fst (∙Π {A = A} {n = suc (suc n)} (f , p) (g , q)) (merid a j) =
((sym p ∙∙ cong f (merid a ∙ sym (merid (ptSn (suc n)))) ∙∙ p)
∙ (sym q ∙∙ cong g (merid a ∙ sym (merid (ptSn (suc n)))) ∙∙ q)) j
snd (∙Π {A = A} {n = suc (suc n)} (f , p) (g , q)) = refl
-Π : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (S₊∙ n →∙ A)
→ (S₊∙ n →∙ A)
-Π {n = zero} f = f
fst (-Π {A = A} {n = suc zero} f) base = fst f base
fst (-Π {A = A} {n = suc zero} f) (loop j) = fst f (loop (~ j))
snd (-Π {A = A} {n = suc zero} f) = snd f
fst (-Π {A = A} {n = suc (suc n)} f) north = fst f north
fst (-Π {A = A} {n = suc (suc n)} f) south = fst f north
fst (-Π {A = A} {n = suc (suc n)} f) (merid a j) =
fst f ((merid a ∙ sym (merid (ptSn _))) (~ j))
snd (-Π {A = A} {n = suc (suc n)} f) = snd f
-- to prove that this gives a group structure on π', we first
-- prove that Ωⁿ A ≃ (Sⁿ →∙ A).
-- We use the following map
mutual
Ω→SphereMap : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ}
→ typ ((Ω^ n) A) → (S₊∙ n →∙ A)
fst (Ω→SphereMap zero a) false = a
fst (Ω→SphereMap zero {A = A} a) true = pt A
snd (Ω→SphereMap zero a) = refl
fst (Ω→SphereMap (suc zero) {A = A} p) base = pt A
fst (Ω→SphereMap (suc zero) p) (loop i) = p i
snd (Ω→SphereMap (suc zero) p) = refl
fst (Ω→SphereMap (suc (suc n)) {A = A} p) north = pt A
fst (Ω→SphereMap (suc (suc n)) {A = A} p) south = pt A
fst (Ω→SphereMap (suc (suc n)) p) (merid a i) =
(sym (Ω→SphereMapId (suc n) a)
∙∙ (λ i → Ω→SphereMap (suc n) (p i) .fst a)
∙∙ Ω→SphereMapId (suc n) a) i
snd (Ω→SphereMap (suc (suc n)) p) = refl
Ω→SphereMapId : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (a : _)
→ Ω→SphereMap n {A = A} (pt ((Ω^ n) A)) .fst a ≡ pt A
Ω→SphereMapId zero false = refl
Ω→SphereMapId zero true = refl
Ω→SphereMapId (suc zero) base = refl
Ω→SphereMapId (suc zero) (loop i) = refl
Ω→SphereMapId (suc (suc n)) north = refl
Ω→SphereMapId (suc (suc n)) south = refl
Ω→SphereMapId (suc (suc n)) {A = A} (merid a i) j =
∙∙lCancel (Ω→SphereMapId (suc n) {A = A} a) j i
Ω→SphereMapId2 : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ}
→ Ω→SphereMap n {A = A} (pt ((Ω^ n) A)) ≡ ((λ _ → pt A) , refl)
fst (Ω→SphereMapId2 n {A = A} i) a = funExt (Ω→SphereMapId n {A = A}) i a
snd (Ω→SphereMapId2 zero {A = A} i) = refl
snd (Ω→SphereMapId2 (suc zero) {A = A} i) = refl
snd (Ω→SphereMapId2 (suc (suc n)) {A = A} i) = refl
-- Pointed version
Ω→SphereMap∙ : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ}
→ ((Ω^ n) A) →∙ (S₊∙ n →∙ A ∙)
Ω→SphereMap∙ n .fst = Ω→SphereMap n
Ω→SphereMap∙ n .snd = Ω→SphereMapId2 n
-- We define the following maps which will be used to
-- show that Ω→SphereMap is an equivalence
Ω→SphereMapSplit₁ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ typ ((Ω^ (suc n)) A)
→ typ (Ω (S₊∙ n →∙ A ∙))
Ω→SphereMapSplit₁ n = Ω→ (Ω→SphereMap∙ n) .fst
ΩSphereMap : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ typ (Ω (S₊∙ n →∙ A ∙))
→ (S₊∙ (suc n) →∙ A)
fst (ΩSphereMap {A = A} zero p) base = p i0 .fst false
fst (ΩSphereMap {A = A} zero p) (loop i) = p i .fst false
snd (ΩSphereMap {A = A} zero p) = refl
ΩSphereMap {A = A} (suc n) = fun IsoΩFunSuspFun
-- Functoriality
-- The homogeneity assumption is not necessary but simplifying
isNaturalΩSphereMap : ∀ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ')
(homogB : isHomogeneous B) (f : A →∙ B) (n : ℕ)
→ ∀ g → f ∘∙ ΩSphereMap n g ≡ ΩSphereMap n (Ω→ (post∘∙ (S₊∙ n) f) .fst g)
isNaturalΩSphereMap A B homogB f 0 g =
→∙Homogeneous≡ homogB (funExt lem)
where
lem : ∀ x → f .fst (ΩSphereMap 0 g .fst x)
≡ ΩSphereMap 0 (Ω→ (post∘∙ (S₊∙ 0) f) .fst g) .fst x
lem base = f .snd
lem (loop i) j =
hfill
(λ j → λ
{ (i = i0) → post∘∙ _ f .snd j
; (i = i1) → post∘∙ _ f .snd j
})
(inS (f ∘∙ g i))
j .fst false
isNaturalΩSphereMap A B homogB f (n@(suc _)) g =
→∙Homogeneous≡ homogB (funExt lem)
where
lem : ∀ x → f .fst (ΩSphereMap n g .fst x)
≡ ΩSphereMap n (Ω→ (post∘∙ (S₊∙ n) f) .fst g) .fst x
lem north = f .snd
lem south = f .snd
lem (merid a i) j =
hfill
(λ j → λ
{ (i = i0) → post∘∙ _ f .snd j
; (i = i1) → post∘∙ _ f .snd j
})
(inS (f ∘∙ g i))
j .fst a
SphereMapΩ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (S₊∙ (suc n) →∙ A)
→ typ (Ω (S₊∙ n →∙ A ∙))
SphereMapΩ {A = A} zero (f , p) =
ΣPathP ((funExt λ { false → sym p ∙∙ cong f loop ∙∙ p
; true → refl})
, refl)
SphereMapΩ {A = A} (suc n) = inv IsoΩFunSuspFun
SphereMapΩIso : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (S₊∙ (suc n) →∙ A)
(typ (Ω (S₊∙ n →∙ A ∙)))
fun (SphereMapΩIso n) = SphereMapΩ n
inv (SphereMapΩIso n) = ΩSphereMap n
fst (rightInv (SphereMapΩIso zero) f i j) false = rUnit (λ j → fst (f j) false) (~ i) j
fst (rightInv (SphereMapΩIso {A = A} zero) f i j) true = snd (f j) (~ i)
snd (rightInv (SphereMapΩIso {A = A} zero) f i j) k = snd (f j) (~ i ∨ k)
rightInv (SphereMapΩIso (suc n)) = leftInv IsoΩFunSuspFun
leftInv (SphereMapΩIso zero) f =
ΣPathP ((funExt (λ { base → sym (snd f)
; (loop i) j → doubleCompPath-filler
(sym (snd f))
(cong (fst f) loop)
(snd f) (~ j) i}))
, λ i j → snd f (~ i ∨ j))
leftInv (SphereMapΩIso (suc n)) = rightInv IsoΩFunSuspFun
{-
In order to show that Ω→SphereMap is an equivalence, we show that it factors
Ω→SphereMapSplit₁ ΩSphereMap
Ωⁿ⁺¹A ----------------> Ω (Sⁿ →∙ A) -----------> (Sⁿ⁺¹ →∙ A)
-}
Ω→SphereMap-split : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (p : typ ((Ω^ (suc n)) A))
→ Ω→SphereMap (suc n) p ≡ ΩSphereMap n (Ω→SphereMapSplit₁ n p)
Ω→SphereMap-split {A = A} zero p =
ΣPathP ((funExt (λ { base → refl
; (loop i) j → lem (~ j) i}))
, refl)
where
lem : funExt⁻ (cong fst (Ω→SphereMapSplit₁ zero p)) false ≡ p
lem = (λ i → funExt⁻ (cong-∙∙ fst (sym (Ω→SphereMapId2 zero))
(cong (Ω→SphereMap zero) p)
(Ω→SphereMapId2 zero) i) false)
∙ sym (rUnit _)
Ω→SphereMap-split {A = A} (suc n) p =
ΣPathP ((funExt (λ { north → refl
; south → refl
; (merid a i) j → lem₂ a j i}))
, refl)
where
lem : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (a : S₊ (suc n))
→ Ω→SphereMapId (suc n) {A = A} a
≡ (λ i → fst (Ω→SphereMapId2 (suc n) {A = A} i) a)
lem zero base = refl
lem zero (loop i) = refl
lem (suc n) north = refl
lem (suc n) south = refl
lem (suc n) (merid a i) = refl
lem₂ : (a : S₊ (suc n))
→ ((λ i₁ → Ω→SphereMapId (suc n) {A = A} a (~ i₁))
∙∙ (λ i₁ → Ω→SphereMap (suc n) (p i₁) .fst a)
∙∙ Ω→SphereMapId (suc n) a)
≡ (λ i → Ω→SphereMapSplit₁ (suc n) p i .fst a)
lem₂ a = cong (λ x → sym x
∙∙ funExt⁻ (cong fst (λ i → Ω→SphereMap (suc n) (p i))) a
∙∙ x)
(lem n a)
∙∙ sym (cong-∙∙ (λ x → x a)
(cong fst (λ i → Ω→SphereMapId2 (suc n) (~ i)))
(cong fst (λ i → Ω→SphereMap (suc n) (p i)))
(cong fst (Ω→SphereMapId2 (suc n))))
∙∙ (λ i → funExt⁻ (cong-∙∙ fst (sym (Ω→SphereMapId2 (suc n)))
(cong (Ω→SphereMap (suc n)) p)
(Ω→SphereMapId2 (suc n)) (~ i)) a)
isEquiv-Ω→SphereMap₀ : ∀ {ℓ} {A : Pointed ℓ}
→ isEquiv (Ω→SphereMap 0 {A = A})
isEquiv-Ω→SphereMap₀ {A = A} =
isoToIsEquiv
(iso _ (λ f → fst f false)
(λ f → ΣPathP ((funExt (λ { false → refl ; true → sym (snd f)}))
, λ i j → snd f (~ i ∨ j)))
λ p → refl)
isEquiv-Ω→SphereMap : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ}
→ isEquiv (Ω→SphereMap n {A = A})
isEquiv-Ω→SphereMap zero {A = A} =
(isoToIsEquiv
(iso _ (λ f → fst f false)
(λ f → ΣPathP ((funExt (λ { false → refl
; true → sym (snd f)}))
, λ i j → snd f (~ i ∨ j)))
λ _ → refl))
isEquiv-Ω→SphereMap (suc zero) {A = A} =
isoToIsEquiv (iso _ invFun sec λ p → sym (rUnit p))
where
invFun : S₊∙ 1 →∙ A → typ (Ω A)
invFun (f , p) = sym p ∙∙ cong f loop ∙∙ p
sec : section (Ω→SphereMap 1) invFun
sec (f , p) =
ΣPathP ((funExt (λ { base → sym p
; (loop i) j → doubleCompPath-filler
(sym p) (cong f loop) p (~ j) i}))
, λ i j → p (~ i ∨ j))
isEquiv-Ω→SphereMap (suc (suc n)) =
subst isEquiv (sym (funExt (Ω→SphereMap-split (suc n))))
(snd (compEquiv
((Ω→SphereMapSplit₁ (suc n)) ,
(isEquivΩ→ (Ω→SphereMap (suc n) , Ω→SphereMapId2 (suc n))
(isEquiv-Ω→SphereMap (suc n))))
(invEquiv (isoToEquiv (SphereMapΩIso (suc n))))))
IsoΩSphereMap : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (typ ((Ω^ n) A)) (S₊∙ n →∙ A)
IsoΩSphereMap n = equivToIso (_ , isEquiv-Ω→SphereMap n)
IsoSphereMapΩ : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (S₊∙ n →∙ A) (fst ((Ω^ n) A))
IsoSphereMapΩ {A = A} n =
invIso (IsoΩSphereMap n)
SphereMap→Ω : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ S₊∙ n →∙ A → fst ((Ω^ n) A)
SphereMap→Ω n = fun (IsoSphereMapΩ n)
isHom-Ω→SphereMap : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (p q : _)
→ Ω→SphereMap (suc n) {A = A} (p ∙ q)
≡ ∙Π (Ω→SphereMap (suc n) {A = A} p)
(Ω→SphereMap (suc n) {A = A} q)
isHom-Ω→SphereMap zero {A = A} p q =
ΣPathP ((funExt (λ { base → refl
; (loop i) j → (rUnit p j ∙ rUnit q j) i}))
, refl)
isHom-Ω→SphereMap (suc n) {A = A} p q =
ΣPathP ((funExt (λ { north → refl
; south → refl
; (merid a i) j → main a j i}))
, refl)
where
doubleComp-lem : ∀ {ℓ} {A : Type ℓ} {x y : A} (p : x ≡ y) (q r : y ≡ y)
→ (p ∙∙ q ∙∙ sym p) ∙ (p ∙∙ r ∙∙ sym p)
≡ (p ∙∙ (q ∙ r) ∙∙ sym p)
doubleComp-lem p q r i j =
hcomp (λ k → λ { (i = i0) → (doubleCompPath-filler p q (sym p) k
∙ doubleCompPath-filler p r (sym p) k) j
; (i = i1) → doubleCompPath-filler p (q ∙ r) (sym p) k j
; (j = i0) → p (~ k)
; (j = i1) → p (~ k)})
((q ∙ r) j)
lem : (p : typ ((Ω^ (suc (suc n))) A))
→ cong (fst (Ω→SphereMap (suc (suc n)) p)) (merid (ptSn _)) ≡ refl
lem p =
cong (sym (Ω→SphereMapId (suc n) (ptSn _)) ∙∙_∙∙ Ω→SphereMapId (suc n) (ptSn _))
(rUnit _ ∙ (λ j → (λ i → Ω→SphereMap (suc n) {A = A} refl .snd (i ∧ j))
∙∙ (λ i → Ω→SphereMap (suc n) {A = A} (p i) .snd j)
∙∙ λ i → Ω→SphereMap (suc n) {A = A} refl .snd (~ i ∧ j))
∙ ∙∙lCancel _)
∙ ∙∙lCancel _
main : (a : S₊ (suc n))
→ sym (Ω→SphereMapId (suc n) a)
∙∙ funExt⁻ (cong fst (cong (Ω→SphereMap (suc n)) (p ∙ q))) a
∙∙ Ω→SphereMapId (suc n) a
≡ cong (fst (∙Π (Ω→SphereMap (suc (suc n)) p) (Ω→SphereMap (suc (suc n)) q))) (merid a)
main a = (cong (sym (Ω→SphereMapId (suc n) a) ∙∙_∙∙ (Ω→SphereMapId (suc n) a))
(cong-∙ (λ x → Ω→SphereMap (suc n) x .fst a) p q)
∙ sym (doubleComp-lem (sym (Ω→SphereMapId (suc n) a)) _ _))
∙∙ cong₂ _∙_ (sym (cong (cong (fst (Ω→SphereMap (suc (suc n)) p)) (merid a) ∙_)
(cong sym (lem p)) ∙ sym (rUnit _)))
(sym (cong (cong (fst (Ω→SphereMap (suc (suc n)) q)) (merid a) ∙_)
(cong sym (lem q)) ∙ sym (rUnit _)))
∙∙ λ i → (rUnit (cong-∙ (fst (Ω→SphereMap (suc (suc n)) p))
(merid a) (sym (merid (ptSn _))) (~ i)) i)
∙ (rUnit (cong-∙ (fst (Ω→SphereMap (suc (suc n)) q))
(merid a) (sym (merid (ptSn _)))(~ i)) i)
-- The iso is structure preserving
IsoSphereMapΩ-pres∙Π : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ) (f g : S₊∙ (suc n) →∙ A)
→ SphereMap→Ω (suc n) (∙Π f g)
≡ SphereMap→Ω (suc n) f ∙ SphereMap→Ω (suc n) g
IsoSphereMapΩ-pres∙Π n =
morphLemmas.isMorphInv _∙_ ∙Π (Ω→SphereMap (suc n))
(isHom-Ω→SphereMap n)
(SphereMap→Ω (suc n))
(leftInv (IsoSphereMapΩ (suc n)))
(rightInv (IsoSphereMapΩ (suc n)))
-- It is useful to define the ``Group Structure'' on (S₊∙ n →∙ A)
-- before doing it on π'. These will be the equivalents of the
-- usual groupoid laws on Ω A.
1Π : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ} → (S₊∙ n →∙ A)
fst (1Π {A = A}) _ = pt A
snd (1Π {A = A}) = refl
∙Π-rUnit : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f : S₊∙ (suc n) →∙ A)
→ ∙Π f 1Π ≡ f
fst (∙Π-rUnit {A = A} {n = zero} f i) base = snd f (~ i)
fst (∙Π-rUnit {A = A} {n = zero} f i) (loop j) = help i j
where
help : PathP (λ i → snd f (~ i) ≡ snd f (~ i))
(((sym (snd f)) ∙∙ (cong (fst f) loop) ∙∙ snd f)
∙ (refl ∙ refl))
(cong (fst f) loop)
help = (cong ((sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f) ∙_)
(sym (rUnit refl)) ∙ sym (rUnit _))
◁ λ i j → doubleCompPath-filler (sym (snd f))
(cong (fst f) loop) (snd f) (~ i) j
snd (∙Π-rUnit {A = A} {n = zero} f i) j = snd f (~ i ∨ j)
fst (∙Π-rUnit {A = A} {n = suc n} f i) north = snd f (~ i)
fst (∙Π-rUnit {A = A} {n = suc n} f i) south =
(sym (snd f) ∙ cong (fst f) (merid (ptSn (suc n)))) i
fst (∙Π-rUnit {A = A} {n = suc n} f i) (merid a j) = help i j
where
help : PathP (λ i → snd f (~ i)
≡ (sym (snd f) ∙ cong (fst f) (merid (ptSn (suc n)))) i)
(((sym (snd f))
∙∙ (cong (fst f) (merid a ∙ sym (merid (ptSn (suc n)))))
∙∙ snd f)
∙ (refl ∙ refl))
(cong (fst f) (merid a))
help = (cong (((sym (snd f))
∙∙ (cong (fst f) (merid a ∙ sym (merid (ptSn (suc n)))))
∙∙ snd f) ∙_)
(sym (rUnit refl))
∙ sym (rUnit _))
◁ λ i j → hcomp (λ k →
λ { (j = i0) → snd f (~ i ∧ k)
; (j = i1) → compPath-filler' (sym (snd f))
(cong (fst f) (merid (ptSn (suc n)))) k i
; (i = i0) → doubleCompPath-filler (sym (snd f))
(cong (fst f)
(merid a ∙ sym (merid (ptSn (suc n)))))
(snd f) k j
; (i = i1) → fst f (merid a j)})
(fst f (compPath-filler (merid a)
(sym (merid (ptSn _))) (~ i) j))
snd (∙Π-rUnit {A = A} {n = suc n} f i) j = snd f (~ i ∨ j)
∙Π-lUnit : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f : S₊∙ (suc n) →∙ A)
→ ∙Π 1Π f ≡ f
fst (∙Π-lUnit {n = zero} f i) base = snd f (~ i)
fst (∙Π-lUnit {n = zero} f i) (loop j) = s i j
where
s : PathP (λ i → snd f (~ i) ≡ snd f (~ i))
((refl ∙ refl) ∙ (sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f))
(cong (fst f) loop)
s = (cong (_∙ (sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f))
(sym (rUnit refl)) ∙ sym (lUnit _))
◁ λ i j → doubleCompPath-filler (sym (snd f))
(cong (fst f) loop) (snd f) (~ i) j
snd (∙Π-lUnit {n = zero} f i) j = snd f (~ i ∨ j)
fst (∙Π-lUnit {n = suc n} f i) north = snd f (~ i)
fst (∙Π-lUnit {n = suc n} f i) south =
(sym (snd f) ∙ cong (fst f) (merid (ptSn _))) i
fst (∙Π-lUnit {n = suc n} f i) (merid a j) = help i j
where
help : PathP (λ i → snd f (~ i)
≡ (sym (snd f) ∙ cong (fst f) (merid (ptSn (suc n)))) i)
((refl ∙ refl) ∙ ((sym (snd f))
∙∙ (cong (fst f) (merid a ∙ sym (merid (ptSn (suc n)))))
∙∙ snd f))
(cong (fst f) (merid a))
help =
(cong (_∙ ((sym (snd f))
∙∙ (cong (fst f) (merid a ∙ sym (merid (ptSn (suc n)))))
∙∙ snd f))
(sym (rUnit refl))
∙ sym (lUnit _))
◁ λ i j → hcomp (λ k →
λ { (j = i0) → snd f (~ i ∧ k)
; (j = i1) → compPath-filler' (sym (snd f))
(cong (fst f) (merid (ptSn (suc n)))) k i
; (i = i0) → doubleCompPath-filler (sym (snd f))
(cong (fst f) (merid a ∙ sym (merid (ptSn (suc n)))))
(snd f) k j
; (i = i1) → fst f (merid a j)})
(fst f (compPath-filler (merid a) (sym (merid (ptSn _))) (~ i) j))
snd (∙Π-lUnit {n = suc n} f i) j = snd f (~ i ∨ j)
∙Π-rCancel : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f : S₊∙ (suc n) →∙ A)
→ ∙Π f (-Π f) ≡ 1Π
fst (∙Π-rCancel {A = A} {n = zero} f i) base = pt A
fst (∙Π-rCancel {A = A} {n = zero} f i) (loop j) =
rCancel (sym (snd f) ∙∙ cong (fst f) loop ∙∙ snd f) i j
snd (∙Π-rCancel {A = A} {n = zero} f i) = refl
fst (∙Π-rCancel {A = A} {n = suc n} f i) north = pt A
fst (∙Π-rCancel {A = A} {n = suc n} f i) south = pt A
fst (∙Π-rCancel {A = A} {n = suc n} f i) (merid a i₁) = lem i i₁
where
pl = (sym (snd f)
∙∙ cong (fst f) (merid a ∙ sym (merid (ptSn _)))
∙∙ snd f)
lem : pl
∙ ((sym (snd f)
∙∙ cong (fst (-Π f)) (merid a ∙ sym (merid (ptSn _)))
∙∙ snd f)) ≡ refl
lem = cong (pl ∙_) (cong (sym (snd f) ∙∙_∙∙ (snd f))
(cong-∙ (fst (-Π f)) (merid a) (sym (merid (ptSn _)))
∙∙ cong₂ _∙_ refl
(cong (cong (fst f)) (rCancel (merid (ptSn _))))
∙∙ sym (rUnit _)))
∙ rCancel pl
snd (∙Π-rCancel {A = A} {n = suc n} f i) = refl
∙Π-lCancel : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f : S₊∙ (suc n) →∙ A)
→ ∙Π (-Π f) f ≡ 1Π
fst (∙Π-lCancel {A = A} {n = zero} f i) base = pt A
fst (∙Π-lCancel {A = A} {n = zero} f i) (loop j) =
rCancel (sym (snd f) ∙∙ cong (fst f) (sym loop) ∙∙ snd f) i j
fst (∙Π-lCancel {A = A} {n = suc n} f i) north = pt A
fst (∙Π-lCancel {A = A} {n = suc n} f i) south = pt A
fst (∙Π-lCancel {A = A} {n = suc n} f i) (merid a j) = lem i j
where
pl = (sym (snd f)
∙∙ cong (fst f) (merid a ∙ sym (merid (ptSn _)))
∙∙ snd f)
lem : (sym (snd f)
∙∙ cong (fst (-Π f)) (merid a ∙ sym (merid (ptSn _)))
∙∙ snd f) ∙ pl
≡ refl
lem = cong (_∙ pl) (cong (sym (snd f) ∙∙_∙∙ (snd f))
(cong-∙ (fst (-Π f)) (merid a) (sym (merid (ptSn _)))
∙∙ cong₂ _∙_ refl (cong (cong (fst f)) (rCancel (merid (ptSn _))))
∙∙ sym (rUnit _)))
∙ lCancel pl
snd (∙Π-lCancel {A = A} {n = zero} f i) = refl
snd (∙Π-lCancel {A = A} {n = suc n} f i) = refl
∙Π-assoc : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f g h : S₊∙ (suc n) →∙ A)
→ ∙Π f (∙Π g h) ≡ ∙Π (∙Π f g) h
∙Π-assoc {n = n} f g h =
sym (leftInv (IsoSphereMapΩ (suc n)) (∙Π f (∙Π g h)))
∙∙ cong (Ω→SphereMap (suc n)) (IsoSphereMapΩ-pres∙Π n f (∙Π g h)
∙∙ cong (SphereMap→Ω (suc n) f ∙_) (IsoSphereMapΩ-pres∙Π n g h)
∙∙ ∙assoc (SphereMap→Ω (suc n) f) (SphereMap→Ω (suc n) g) (SphereMap→Ω (suc n) h)
∙∙ cong (_∙ SphereMap→Ω (suc n) h) (sym (IsoSphereMapΩ-pres∙Π n f g))
∙∙ sym (IsoSphereMapΩ-pres∙Π n (∙Π f g) h))
∙∙ leftInv (IsoSphereMapΩ (suc n)) (∙Π (∙Π f g) h)
∙Π-comm : ∀ {ℓ} {A : Pointed ℓ} {n : ℕ}
→ (f g : S₊∙ (suc (suc n)) →∙ A)
→ ∙Π f g ≡ ∙Π g f
∙Π-comm {A = A} {n = n} f g =
sym (leftInv (IsoSphereMapΩ (suc (suc n))) (∙Π f g))
∙∙ cong (Ω→SphereMap (suc (suc n))) (IsoSphereMapΩ-pres∙Π (suc n) f g
∙∙ EH _ _ _
∙∙ sym (IsoSphereMapΩ-pres∙Π (suc n) g f))
∙∙ leftInv (IsoSphereMapΩ (suc (suc n))) (∙Π g f)
{- π'' as a group -}
1π' : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π' n A
1π' n {A = A} = ∣ 1Π ∣₂
·π' : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π' (suc n) A → π' (suc n) A → π' (suc n) A
·π' n = sRec2 squash₂ λ p q → ∣ ∙Π p q ∣₂
-π' : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} → π' (suc n) A → π' (suc n) A
-π' n = sMap -Π
π'-rUnit : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π' (suc n) A)
→ (·π' n x (1π' (suc n))) ≡ x
π'-rUnit n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ ∙Π-rUnit p i ∣₂
π'-lUnit : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π' (suc n) A)
→ (·π' n (1π' (suc n)) x) ≡ x
π'-lUnit n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ ∙Π-lUnit p i ∣₂
π'-rCancel : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π' (suc n) A)
→ (·π' n x (-π' n x)) ≡ 1π' (suc n)
π'-rCancel n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ ∙Π-rCancel p i ∣₂
π'-lCancel : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x : π' (suc n) A)
→ (·π' n (-π' n x) x) ≡ 1π' (suc n)
π'-lCancel n = sElim (λ _ → isSetPathImplicit) λ p i → ∣ ∙Π-lCancel p i ∣₂
π'-assoc : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x y z : π' (suc n) A)
→ ·π' n x (·π' n y z) ≡ ·π' n (·π' n x y) z
π'-assoc n = sElim3 (λ _ _ _ → isSetPathImplicit) λ p q r i → ∣ ∙Π-assoc p q r i ∣₂
π'-comm : ∀ {ℓ} (n : ℕ) {A : Pointed ℓ} (x y : π' (suc (suc n)) A)
→ ·π' (suc n) x y ≡ ·π' (suc n) y x
π'-comm n = sElim2 (λ _ _ → isSetPathImplicit) λ p q i → ∣ ∙Π-comm p q i ∣₂
-- We finally get the group definition
π'Gr : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → Group ℓ
fst (π'Gr n A) = π' (suc n) A
1g (snd (π'Gr n A)) = 1π' (suc n)
GroupStr._·_ (snd (π'Gr n A)) = ·π' n
inv (snd (π'Gr n A)) = -π' n
is-set (isSemigroup (isMonoid (isGroup (snd (π'Gr n A))))) = squash₂
assoc (isSemigroup (isMonoid (isGroup (snd (π'Gr n A))))) = π'-assoc n
identity (isMonoid (isGroup (snd (π'Gr n A)))) x = (π'-rUnit n x) , (π'-lUnit n x)
inverse (isGroup (snd (π'Gr n A))) x = (π'-rCancel n x) , (π'-lCancel n x)
-- and finally, the Iso
π'Gr≅πGr : ∀ {ℓ} (n : ℕ) (A : Pointed ℓ) → GroupIso (π'Gr n A) (πGr n A)
fst (π'Gr≅πGr n A) = setTruncIso (IsoSphereMapΩ (suc n))
snd (π'Gr≅πGr n A) =
makeIsGroupHom (sElim2 (λ _ _ → isSetPathImplicit)
λ p q i → ∣ IsoSphereMapΩ-pres∙Π n p q i ∣₂)
{- Proof of πₙ(ΩA) = πₙ₊₁(A) -}
Iso-πΩ-π : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (π n (Ω A)) (π (suc n) A)
Iso-πΩ-π {A = A} n = setTruncIso (invIso (flipΩIso n))
GrIso-πΩ-π : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ GroupIso (πGr n (Ω A)) (πGr (suc n) A)
fst (GrIso-πΩ-π n) = Iso-πΩ-π _
snd (GrIso-πΩ-π n) =
makeIsGroupHom
(sElim2 (λ _ _ → isSetPathImplicit)
λ p q → cong ∣_∣₂ (flipΩIso⁻pres· n p q))
{- Proof that πₙ(A) ≅ πₙ(∥ A ∥ₙ) -}
isContrΩTrunc : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ isContr (typ ((Ω^ n) (hLevelTrunc∙ n A)))
isContrΩTrunc {A = A} zero = isContrUnit*
isContrΩTrunc {A = A} (suc n) =
subst isContr main (isContrΩTrunc {A = Ω A} n)
where
lem₁ : (n : ℕ) → fun (PathIdTruncIso n) (λ _ → ∣ pt A ∣)
≡ snd (hLevelTrunc∙ n (Ω A))
lem₁ zero = refl
lem₁ (suc n) = transportRefl ∣ refl ∣
lem₂ : hLevelTrunc∙ n (Ω A) ≡ (Ω (hLevelTrunc∙ (suc n) A))
lem₂ = sym (ua∙ (isoToEquiv (PathIdTruncIso n))
(lem₁ n))
main : (typ ((Ω^ n) (hLevelTrunc∙ n (Ω A))))
≡ (typ ((Ω^ suc n) (hLevelTrunc∙ (suc n) A)))
main = (λ i → typ ((Ω^ n) (lem₂ i)))
∙ sym (isoToPath (flipΩIso n))
mutual
ΩTruncSwitchFun : ∀ {ℓ} {A : Pointed ℓ} (n m : ℕ) →
(hLevelTrunc∙ (suc (suc m)) ((Ω^ n) A))
→∙ ((Ω^ n) (hLevelTrunc∙ (suc n + suc m) A))
ΩTruncSwitchFun {A = A} n m =
((λ x → transport
(λ i → fst ((Ω^ n) (hLevelTrunc∙ (+-suc n (suc m) i) A)))
(Iso.fun (ΩTruncSwitch {A = A} n (suc (suc m))) x))
, cong (transport
(λ i → fst ((Ω^ n) (hLevelTrunc∙ (+-suc n (suc m) i) A))))
(ΩTruncSwitch∙ n (suc (suc m)))
∙ λ j → transp
(λ i → fst ((Ω^ n) (hLevelTrunc∙ (+-suc n (suc m) (i ∨ j)) A)))
j (snd ((Ω^ n) (hLevelTrunc∙ (+-suc n (suc m) j) A))))
ΩTruncSwitchLem :
∀ {ℓ} {A : Pointed ℓ} (n m : ℕ)
→ Iso
(typ (Ω (hLevelTrunc∙ (suc (suc m)) ((Ω^ n) A))))
(typ ((Ω^ suc n) (hLevelTrunc∙ (suc n + suc m) A)))
ΩTruncSwitchLem {A = A} n m =
(equivToIso
(Ω→ (ΩTruncSwitchFun n m) .fst
, isEquivΩ→ _ (compEquiv (isoToEquiv (ΩTruncSwitch {A = A} n (suc (suc m))))
(transportEquiv
(λ i → typ ((Ω^ n) (hLevelTrunc∙ (+-suc n (suc m) i) A)))) .snd)))
ΩTruncSwitch : ∀ {ℓ} {A : Pointed ℓ} (n m : ℕ)
→ Iso (hLevelTrunc m (fst ((Ω^ n) A)))
(typ ((Ω^ n) (hLevelTrunc∙ (n + m) A)))
ΩTruncSwitch {A = A} n zero =
equivToIso
(invEquiv
(isContr→≃Unit*
(subst isContr
(λ i → (typ ((Ω^ n) (hLevelTrunc∙ (+-comm zero n i) A))))
(isContrΩTrunc n))))
ΩTruncSwitch {A = A} zero (suc m) = idIso
ΩTruncSwitch {A = A} (suc n) (suc m) =
compIso (invIso (PathIdTruncIso _))
(ΩTruncSwitchLem n m)
ΩTruncSwitch∙ : ∀ {ℓ} {A : Pointed ℓ} (n m : ℕ)
→ Iso.fun (ΩTruncSwitch {A = A} n m) (snd (hLevelTrunc∙ m ((Ω^ n) A)))
≡ pt ((Ω^ n) (hLevelTrunc∙ (n + m) A))
ΩTruncSwitch∙ {A = A} n zero =
isContr→isProp
((subst isContr
(λ i → (typ ((Ω^ n) (hLevelTrunc∙ (+-comm zero n i) A))))
(isContrΩTrunc n))) _ _
ΩTruncSwitch∙ {A = A} zero (suc m) = refl
ΩTruncSwitch∙ {A = A} (suc n) (suc m) = ∙∙lCancel _
ΩTruncSwitch-hom : ∀ {ℓ} {A : Pointed ℓ} (n m : ℕ) (p q : _)
→ Iso.fun (ΩTruncSwitch {A = A} (suc n) (suc m)) ∣ p ∙ q ∣
≡ Iso.fun (ΩTruncSwitch {A = A} (suc n) (suc m)) ∣ p ∣
∙ Iso.fun (ΩTruncSwitch {A = A} (suc n) (suc m)) ∣ q ∣
ΩTruncSwitch-hom {A = A} n m p q =
cong (Iso.fun (ΩTruncSwitchLem {A = A} n m))
(cong-∙ ∣_∣ₕ p q)
∙ Ω→pres∙ (ΩTruncSwitchFun n m) (cong ∣_∣ₕ p) (cong ∣_∣ₕ q)
2TruncΩIso : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (hLevelTrunc 2 (fst ((Ω^ n) A)))
(typ ((Ω^ n) (hLevelTrunc∙ (2 + n) A)))
2TruncΩIso zero = idIso
2TruncΩIso {A = A} (suc n) =
compIso
(ΩTruncSwitch (suc n) 2)
(pathToIso λ i → typ ((Ω^ suc n) (hLevelTrunc∙ (+-comm (suc n) 2 i) A)))
hLevΩ+ : ∀ {ℓ} {A : Pointed ℓ} (n m : ℕ)
→ isOfHLevel (m + n) (typ A) → isOfHLevel n (typ ((Ω^ m) A))
hLevΩ+ n zero p = p
hLevΩ+ {A = A} zero (suc zero) p = refl , λ _ → isProp→isSet p _ _ _ _
hLevΩ+ {A = A} zero (suc (suc zero)) p =
refl , λ y → isOfHLevelSuc 2 p _ _ _ _ refl y
hLevΩ+ {A = A} zero (suc (suc (suc m))) p =
transport
(λ i → isContr (typ (Ω (ua∙
(isoToEquiv (flipΩIso {A = A} (suc m))) (flipΩrefl m) (~ i)))))
(hLevΩ+ {A = Ω A} zero (suc (suc m))
(subst (λ x → isOfHLevel x (typ (Ω A)))
(+-comm zero (suc (suc m)))
(lem (pt A) (pt A))))
where
lem : isOfHLevel (3 + m) (typ A)
lem = subst (λ x → isOfHLevel x (typ A))
(λ i → suc (+-comm (2 + m) zero i)) p
hLevΩ+ {A = A} (suc n) (suc m) p =
subst (isOfHLevel (suc n))
(sym (ua (isoToEquiv (flipΩIso {A = A} m))))
(hLevΩ+ {A = Ω A} (suc n) m
(isOfHLevelPath' (m + suc n) p _ _))
isSetΩTrunc : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ (isSet (typ (Ω ((Ω^ n) (hLevelTrunc∙ (suc (suc (suc n))) A)))))
isSetΩTrunc {A = A} zero = isOfHLevelTrunc 3 _ _
isSetΩTrunc {A = A} (suc n) =
hLevΩ+ 2 (suc (suc n))
(transport
(λ i → isOfHLevel (+-comm 2 (2 + n) i) (hLevelTrunc (4 + n) (typ A)))
(isOfHLevelTrunc (suc (suc (suc (suc n))))))
πTruncIso : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ Iso (π n A) (π n (hLevelTrunc∙ (2 + n) A))
πTruncIso {A = A} zero =
compIso (invIso (setTruncIdempotentIso squash₂))
(setTruncIso setTruncTrunc2Iso)
πTruncIso {A = A} (suc n) =
compIso setTruncTrunc2Iso
(compIso
(2TruncΩIso (suc n))
(invIso (setTruncIdempotentIso (isSetΩTrunc n))))
πTruncGroupIso : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ GroupIso (πGr n A) (πGr n (hLevelTrunc∙ (3 + n) A))
fst (πTruncGroupIso n) = πTruncIso (suc n)
snd (πTruncGroupIso {A = A} n) =
makeIsGroupHom
(sElim2 (λ _ _ → isSetPathImplicit)
λ a b
→ cong (inv (setTruncIdempotentIso (isSetΩTrunc n)))
(cong
(transport
(λ i → typ ((Ω^ suc n) (hLevelTrunc∙ (+-comm (suc n) 2 i) A))))
(ΩTruncSwitch-hom n 1 a b)
∙ transpΩTruncSwitch
(λ w → ((Ω^ n) (hLevelTrunc∙ w A))) (+-comm (suc n) 2) _ _))
where
transpΩTruncSwitch : ∀ {ℓ} (A : ℕ → Pointed ℓ) {n m : ℕ}
(r : n ≡ m) (p q : typ (Ω (A n)))
→ subst (λ n → typ (Ω (A n))) r (p ∙ q)
≡ subst (λ n → typ (Ω (A n))) r p
∙ subst (λ n → typ (Ω (A n))) r q
transpΩTruncSwitch A {n = n} =
J (λ m r → (p q : typ (Ω (A n)))
→ subst (λ n → typ (Ω (A n))) r (p ∙ q)
≡ subst (λ n → typ (Ω (A n))) r p
∙ subst (λ n → typ (Ω (A n))) r q)
λ p q → transportRefl _ ∙ cong₂ _∙_
(sym (transportRefl p)) (sym (transportRefl q))
-- Often, we prefer thinking of Ωⁿ A as (Sⁿ →∙ A).
-- The goal of the following lemmas is to show that the maps
-- Ωⁿ A → Ωⁿ B and Ωⁿ (fib f) →∙ Ωⁿ A get sent to post composition
-- under the equivalence Ωⁿ A as (Sⁿ →∙ A). This also gives a proof
-- that post composition induces a homomorphism of homotopy groups.
-- The following lemmas is not pretty but very helpful
private
bigLemma : ∀ {ℓ ℓ'} {A₁ B₁ C₁ : Type ℓ} {A₂ B₂ C₂ : Type ℓ'}
(A₁→B₁ : A₁ ≃ B₁) (B₁→C₁ : B₁ ≃ C₁)
(A₂→B₂ : A₂ ≃ B₂) (B₂→C₂ : B₂ ≃ C₂)
(A₁→A₂ : A₁ → A₂)
(B₁→B₂ : B₁ → B₂)
(C₁→C₂ : C₁ → C₂)
→ (B₁→B₂ ∘ (fst A₁→B₁)) ≡ (fst A₂→B₂ ∘ A₁→A₂)
→ C₁→C₂ ∘ fst B₁→C₁ ≡ fst B₂→C₂ ∘ B₁→B₂
→ C₁→C₂ ∘ fst B₁→C₁ ∘ fst A₁→B₁
≡ fst B₂→C₂ ∘ fst A₂→B₂ ∘ A₁→A₂
bigLemma {B₁ = B₁} {C₁ = C₁} {A₂ = A₂} {B₂ = B₂} {C₂ = C₂} =
EquivJ
(λ A₁ A₁→B₁ → (B₁→C₁ : B₁ ≃ C₁) (A₂→B₂ : A₂ ≃ B₂)
(B₂→C₂ : B₂ ≃ C₂) (A₁→A₂ : A₁ → A₂) (B₁→B₂ : B₁ → B₂)
(C₁→C₂ : C₁ → C₂) →
B₁→B₂ ∘ fst A₁→B₁ ≡ fst A₂→B₂ ∘ A₁→A₂ →
C₁→C₂ ∘ fst B₁→C₁ ≡ fst B₂→C₂ ∘ B₁→B₂ →
C₁→C₂ ∘ fst B₁→C₁ ∘ fst A₁→B₁ ≡ fst B₂→C₂ ∘ fst A₂→B₂ ∘ A₁→A₂)
(EquivJ (λ B₁ B₁→C₁ → (A₂→B₂ : A₂ ≃ B₂) (B₂→C₂ : B₂ ≃ C₂)
(A₁→A₂ : B₁ → A₂) (B₁→B₂ : B₁ → B₂) (C₁→C₂ : C₁ → C₂) →
(B₁→B₂) ≡ (fst A₂→B₂ ∘ A₁→A₂) →
(C₁→C₂ ∘ (fst B₁→C₁)) ≡ (fst B₂→C₂ ∘ (B₁→B₂)) →
(C₁→C₂ ∘ (fst B₁→C₁)) ≡ (fst B₂→C₂ ∘ (fst A₂→B₂ ∘ A₁→A₂)))
(EquivJ (λ A₂ A₂→B₂ → (B₂→C₂ : B₂ ≃ C₂) (A₁→A₂ : C₁ → A₂)
(B₁→B₂ : C₁ → B₂) (C₁→C₂ : C₁ → C₂) →
B₁→B₂ ≡ (fst A₂→B₂ ∘ A₁→A₂) →
(C₁→C₂) ≡ (fst B₂→C₂ ∘ B₁→B₂) →
(C₁→C₂) ≡ fst B₂→C₂ ∘ (fst A₂→B₂ ∘ A₁→A₂))
(EquivJ (λ B₂ B₂→C₂ → (A₁→A₂ B₁→B₂ : C₁ → B₂) (C₁→C₂ : C₁ → C₂) →
B₁→B₂ ≡ A₁→A₂ →
C₁→C₂ ≡ (fst B₂→C₂ ∘ B₁→B₂) →
C₁→C₂ ≡ (fst B₂→C₂ ∘ A₁→A₂))
λ _ _ _ p q → q ∙ p)))
{-
We want to show that the following square
commutes.
Ωⁿ f
Ωⁿ A ----------→ Ωⁿ B
| |
| |
v f∘_ v
(Sⁿ→∙A) ------> (Sⁿ→∙B)
-}
Ω^→≈post∘∙ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ)
→ (f : A →∙ B)
→ Path ((Ω^ (suc n)) A →∙ (S₊∙ (suc n) →∙ B ∙))
(post∘∙ (S₊∙ (suc n)) f ∘∙ Ω→SphereMap∙ (suc n))
(Ω→SphereMap∙ (suc n) ∘∙ Ω^→ (suc n) f)
Ω^→≈post∘∙ {A = A} {B = B} zero f =
→∙Homogeneous≡
(subst isHomogeneous
(ua∙ (Ω→SphereMap 1 , (isEquiv-Ω→SphereMap 1))
(Ω→SphereMap∙ 1 {A = B} .snd))
(isHomogeneousPath _ _))
(funExt λ p →
ΣPathP ((funExt (λ { base → snd f
; (loop i) j →
doubleCompPath-filler
(sym (snd f)) (cong (fst f) p) (snd f) j i}))
, (sym (lUnit (snd f)) ◁ λ i j → snd f (i ∨ j))))
Ω^→≈post∘∙ {A = A} {B = B} (suc n) f =
→∙Homogeneous≡
(subst isHomogeneous
(ua∙ (Ω→SphereMap (2 + n) , (isEquiv-Ω→SphereMap (2 + n)))
(Ω→SphereMap∙ (2 + n) {A = B} .snd))
(isHomogeneousPath _ _))
((funExt λ p
→ (λ i → post∘∙ (S₊∙ (2 + n)) f .fst (Ω→SphereMap-split (suc n) p i))
∙∙ funExt⁻
(bigLemma
(Ω→SphereMapSplit₁ (suc n)
, isEquivΩ→ _ (isEquiv-Ω→SphereMap (suc n)))
(ΩSphereMap (suc n) , isoToIsEquiv (invIso (SphereMapΩIso (suc n))))
(Ω→SphereMapSplit₁ (suc n)
, isEquivΩ→ _ (isEquiv-Ω→SphereMap (suc n)))
(ΩSphereMap (suc n) , isoToIsEquiv (invIso (SphereMapΩIso (suc n))))
(Ω^→ (2 + n) f .fst) (Ω→ (post∘∙ (S₊∙ (suc n)) f) .fst)
(post∘∙ (S₊∙ (2 + n)) f .fst)
(funExt topSquare)
(sym (funExt (bottomSquare f))))
p
∙∙ sym (Ω→SphereMap-split (suc n) (Ω^→ (2 + n) f .fst p))))
where
topSquare : (p : typ ((Ω^ (2 + n)) A))
→ Path (typ (Ω ((S₊∙ (suc n)) →∙ B ∙)))
((Ω→ (post∘∙ (S₊∙ (suc n)) f) .fst ∘ Ω→ (Ω→SphereMap∙ (suc n)) .fst) p)
(((Ω→ (Ω→SphereMap∙ (suc n))) .fst ∘ (Ω^→ (suc (suc n)) f .fst)) p)
topSquare p = sym (Ω→∘ (post∘∙ (S₊∙ (suc n)) f) (Ω→SphereMap∙ (suc n)) p)
∙ (λ i → Ω→ (Ω^→≈post∘∙ {A = A} {B = B} n f i) .fst p)
∙ Ω→∘ (Ω→SphereMap∙ (suc n)) (Ω^→ (suc n) f) p
bottomSquare : (f : A →∙ B) (g : typ (Ω (S₊∙ (suc n) →∙ A ∙)))
→ Path (S₊∙ (2 + n) →∙ B)
(ΩSphereMap (suc n) (Ω→ (post∘∙ (S₊∙ (suc n)) f) .fst g))
((post∘∙ (S₊∙ (2 + n)) f .fst ∘ ΩSphereMap (suc n)) g)
bottomSquare =
→∙J (λ b₀ f → (g : typ (Ω (S₊∙ (suc n) →∙ A ∙)))
→ Path (S₊∙ (suc (suc n)) →∙ (fst B , b₀))
(ΩSphereMap (suc n) (Ω→ (post∘∙ (S₊∙ (suc n)) f) .fst g))
((post∘∙ (S₊∙ (suc (suc n))) f .fst ∘ ΩSphereMap (suc n)) g))
λ f g → ΣPathP ((funExt (λ { north → refl
; south → refl
; (merid a i) j → lem f g a j i}))
, lUnit refl)
where
lem : (f : typ A → typ B) (g : typ (Ω (S₊∙ (suc n) →∙ A ∙)))
→ (a : S₊ (suc n))
→ cong (fst (ΩSphereMap (suc n)
(Ω→ (post∘∙ (S₊∙ (suc n)) (f , refl)) .fst g)))
(merid a)
≡ cong (fst ((f , refl) ∘∙ ΩSphereMap (suc n) g)) (merid a)
lem f g a =
(λ i → funExt⁻
(cong-∙∙ fst (sym (snd (post∘∙ (S₊∙ (suc n)) (f , (λ _ → f (snd A))))))
(cong (fst (post∘∙ (S₊∙ (suc n)) (f , (λ _ → f (snd A))))) g)
(snd (post∘∙ (S₊∙ (suc n)) (f , (λ _ → f (snd A))))) i) a)
∙ sym (rUnit (λ i → f (fst (g i) a)))
{- We can use this to define prove that post composition induces a homomorphism
πₙ A → πₙ B-}
π'∘∙fun : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B)
→ π' (suc n) A → π' (suc n) B
π'∘∙fun n f = sMap (f ∘∙_)
GroupHomπ≅π'PathP : ∀ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ') (n : ℕ)
→ GroupHom (πGr n A) (πGr n B) ≡ GroupHom (π'Gr n A) (π'Gr n B)
GroupHomπ≅π'PathP A B n i =
GroupHom (fst (GroupPath _ _) (GroupIso→GroupEquiv (π'Gr≅πGr n A)) (~ i))
(fst (GroupPath _ _) (GroupIso→GroupEquiv (π'Gr≅πGr n B)) (~ i))
πFun : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B)
→ π (suc n) A → π (suc n) B
πFun n f = sMap (fst (Ω^→ (suc n) f))
πHom : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B)
→ GroupHom (πGr n A) (πGr n B)
fst (πHom n f) = πFun n f
snd (πHom n f) =
makeIsGroupHom
(sElim2 (λ _ _ → isSetPathImplicit)
λ p q → cong ∣_∣₂ (Ω^→pres∙ f n p q))
π'∘∙Hom' : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B)
→ GroupHom (π'Gr n A) (π'Gr n B)
π'∘∙Hom' {A = A} {B = B} n f =
transport (λ i → GroupHomπ≅π'PathP A B n i)
(πHom n f)
π'∘∙Hom'≡π'∘∙fun : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'}
(n : ℕ) (f : A →∙ B) → π'∘∙Hom' n f .fst ≡ π'∘∙fun n f
π'∘∙Hom'≡π'∘∙fun n f =
funExt (sElim (λ _ → isSetPathImplicit)
λ g → cong ∣_∣₂
((λ i → inv (IsoSphereMapΩ (suc n))
(transportRefl (Ω^→ (suc n) f .fst
(transportRefl (fun (IsoSphereMapΩ (suc n)) g) i)) i))
∙ sym (funExt⁻ (cong fst (Ω^→≈post∘∙ n f))
(fun (IsoSphereMapΩ (suc n)) g))
∙ cong (f ∘∙_) (leftInv (IsoSphereMapΩ (suc n)) g)))
π'∘∙Hom : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'} (n : ℕ) (f : A →∙ B)
→ GroupHom (π'Gr n A) (π'Gr n B)
fst (π'∘∙Hom n f) = sMap (f ∘∙_)
snd (π'∘∙Hom {A = A} {B = B} n f) = isHom∘∙
where
abstract
isHom∘∙ : IsGroupHom (π'Gr n A .snd) (fst (π'∘∙Hom n f)) (π'Gr n B .snd)
isHom∘∙ =
transport (λ i → IsGroupHom (π'Gr n A .snd)
(π'∘∙Hom'≡π'∘∙fun n f i)
(π'Gr n B .snd))
(π'∘∙Hom' n f .snd)
-- post composition with an equivalence induces an
-- isomorphism of homotopy groups
π'eqFun : ∀ {ℓ} {A : Pointed ℓ} {B : Pointed ℓ} (n : ℕ)
→ A ≃∙ B
→ (π' (suc n) A) → π' (suc n) B
π'eqFun n p = π'∘∙fun n (≃∙map p)
π'eqFun-idEquiv : ∀ {ℓ} {A : Pointed ℓ} (n : ℕ)
→ π'eqFun n (idEquiv (fst A) , (λ _ → pt A))
≡ idfun _
π'eqFun-idEquiv n =
funExt (sElim (λ _ → isSetPathImplicit)
λ f → cong ∣_∣₂ (∘∙-idʳ f))
π'eqFunIsEquiv :
∀ {ℓ} {A : Pointed ℓ} {B : Pointed ℓ} (n : ℕ)
→ (e : A ≃∙ B)
→ isEquiv (π'eqFun n e)
π'eqFunIsEquiv {B = B} n =
Equiv∙J (λ A e → isEquiv (π'eqFun n e))
(subst isEquiv (sym (π'eqFun-idEquiv n))
(idIsEquiv (π' (suc n) B)))
π'eqFunIsHom : ∀ {ℓ} {A B : Pointed ℓ}(n : ℕ)
→ (e : A ≃∙ B)
→ IsGroupHom (π'Gr n A .snd) (π'eqFun n e)
(π'Gr n B .snd)
π'eqFunIsHom {B = B} n =
Equiv∙J (λ A e → IsGroupHom (π'Gr n A .snd) (π'eqFun n e) (π'Gr n B .snd))
(subst (λ x → IsGroupHom (π'Gr n B .snd) x (π'Gr n B .snd))
(sym (π'eqFun-idEquiv n))
(makeIsGroupHom λ _ _ → refl))
π'Iso : ∀ {ℓ} {A : Pointed ℓ} {B : Pointed ℓ} (n : ℕ)
→ A ≃∙ B
→ GroupEquiv (π'Gr n A) (π'Gr n B)
fst (fst (π'Iso n e)) = π'eqFun n e
snd (fst (π'Iso n e)) = π'eqFunIsEquiv n e
snd (π'Iso n e) = π'eqFunIsHom n e
πIso : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'}
→ (A ≃∙ B)
→ (n : ℕ)
→ GroupEquiv (πGr n A) (πGr n B)
fst (fst (πIso e n)) = fst (πHom n (≃∙map e))
snd (fst (πIso e n)) =
isoToIsEquiv
(setTruncIso
(equivToIso (_ , isEquivΩ^→ (suc n) (≃∙map e) (snd (fst e)))))
snd (πIso e n) = snd (πHom n (≃∙map e))
| 39.529301
| 97
| 0.482186
|
c5f6623984dab95eb06e4ae898cec03e62fb3ab6
| 512
|
agda
|
Agda
|
test/Fail/Issue2723.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2723.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2723.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2017-08-28, issue #2723, reported by Andrea
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS --warning=error #-}
-- {-# OPTIONS -v tc.cover:30 #-}
record Test : Set1 where
field
one two : Set
open Test
foo : Test
foo .one = {!!}
foo = {!!}
foo .two = {!!}
-- WAS: internal error in clause compiler
-- THEN: warning about unreachable clause
-- NOW: error:
-- Cannot split into projections because not all clauses have a
-- projection copattern
-- when checking the definition of foo
| 19.692308
| 63
| 0.658203
|
c59c45abdcf0725c2a4916c93210d4d8e8a71c54
| 814
|
agda
|
Agda
|
Categories/Category.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Categories.Category where
open import Level
-- The main definitions are in:
open import Categories.Category.Core public
-- Convenience functions for working over mupliple categories at once:
-- C [ x , y ] (for x y objects of C) - Hom_C(x , y)
-- C [ f ≈ g ] (for f g arrows of C) - that f and g are equivalent arrows
-- C [ f ∘ g ] (for f g composables arrows of C) - composition in C
infix 10 _[_,_] _[_≈_] _[_∘_]
_[_,_] : ∀ {o ℓ e} → (C : Category o ℓ e) → (X : Category.Obj C) → (Y : Category.Obj C) → Set ℓ
_[_,_] = Category._⇒_
_[_≈_] : ∀ {o ℓ e} → (C : Category o ℓ e) → ∀ {X Y} (f g : C [ X , Y ]) → Set e
_[_≈_] = Category._≈_
_[_∘_] : ∀ {o ℓ e} → (C : Category o ℓ e) → ∀ {X Y Z} (f : C [ Y , Z ]) → (g : C [ X , Y ]) → C [ X , Z ]
_[_∘_] = Category._∘_
| 35.391304
| 105
| 0.562654
|
227a5b13dd7f25afe79aca4e4402cc7814faef67
| 3,416
|
agda
|
Agda
|
src/Relation/Ternary/Separation/Monad/State/Heap.agda
|
laMudri/linear.agda
|
461077552d88141ac1bba044aa55b65069c3c6c0
|
[
"MIT"
] | 34
|
2019-12-20T13:57:50.000Z
|
2021-02-03T15:22:33.000Z
|
src/Relation/Ternary/Separation/Monad/State/Heap.agda
|
laMudri/linear.agda
|
461077552d88141ac1bba044aa55b65069c3c6c0
|
[
"MIT"
] | null | null | null |
src/Relation/Ternary/Separation/Monad/State/Heap.agda
|
laMudri/linear.agda
|
461077552d88141ac1bba044aa55b65069c3c6c0
|
[
"MIT"
] | 2
|
2020-01-30T14:15:14.000Z
|
2020-05-23T00:34:36.000Z
|
open import Data.List
open import Data.Unit
open import Relation.Unary hiding (_∈_)
open import Relation.Unary.PredicateTransformer using (Pt)
open import Relation.Ternary.Separation
open import Relation.Ternary.Separation.Construct.Market
open import Relation.Ternary.Separation.Monad
open import Relation.Ternary.Separation.Morphisms
module Relation.Ternary.Separation.Monad.State.Heap
{ℓ}
-- value types
{T : Set ℓ}
-- stored values
(V : T → Pred (List T) ℓ)
where
open import Level hiding (Lift)
open import Function using (_∘_; case_of_)
import Relation.Binary.HeterogeneousEquality as HEq
open import Relation.Unary.PredicateTransformer hiding (_⊔_; [_])
open import Relation.Binary.PropositionalEquality using (refl; _≡_)
open import Relation.Ternary.Separation.Construct.Product
open import Relation.Ternary.Separation.Construct.List T
open import Relation.Ternary.Separation.Morphisms
open import Relation.Ternary.Separation.Monad
open import Relation.Ternary.Separation.Allstar
open import Data.Product
open import Data.List.Relation.Ternary.Interleaving.Propositional as I
module HeapOps
-- inner monad
(M : Pt (Market (List T)) ℓ)
{{monad : Monads.Monad ⊤ ℓ (λ _ _ → M) }}
where
Cells : Pred (List T × List T) ℓ
Cells (Σ , Φ) = Allstar V Σ Φ
open import Relation.Ternary.Separation.Monad.State
open StateTransformer M public
open Monads using (str)
open Monads.Monad {{...}}
-- Creating a reference to a new cell, filled with a given value.
-- Note that in the market monoid this is pure!
-- Because we get a reference that consumes the freshly created resource.
newref : ∀ {a} → ∀[ V a ⇒ StateT M Cells (Just a) ]
app (newref v) (lift st σ₁) (offerᵣ σ₂) =
let _ , τ₁ , τ₂ = ⊎-assoc (⊎-comm σ₂) σ₁
in return (
inj refl
×⟨ offerᵣ ⊎-∙ ⟩
lift (cons (v ×⟨ τ₂ ⟩ st)) (⊎-∙ₗ τ₁))
-- A linear read on a store: you lose the reference.
-- This is pure, because with the reference being lost, the cell is destroyed: no resources leak.
read : ∀ {a} → ∀[ Just a ⇒ StateT M Cells (V a) ]
app (read refl) (lift st σ₁) (offerᵣ σ₂) with ⊎-assoc σ₂ σ₁
... | _ , σ₃ , σ₄ with repartition σ₃ st
... | cons (v ×⟨ σ₅ ⟩ nil) ×⟨ σ₆ ⟩ st' with ⊎-id⁻ʳ σ₅ | ⊎-assoc (⊎-comm σ₆) (⊎-comm σ₄)
... | refl | _ , τ₁ , τ₂ = return (inj v ×⟨ offerᵣ τ₂ ⟩ lift st' (⊎-comm τ₁))
-- Writing into a cell, returning the current contents
write : ∀ {a b} → ∀[ Just b ✴ (V a) ⇒ StateT M Cells (Just a ✴ V b) ]
app (write (refl ×⟨ σ₁ ⟩ v)) (lift st σ₂) (offerᵣ σ₃) with ⊎-assoc (⊎-comm σ₁) σ₃
-- first we reassociate the arguments in the order that we want to piece it back together
... | _ , τ₁ , τ₂ with ⊎-assoc (⊎-comm τ₁) σ₂
... | _ , τ₃ , τ₄ with ⊎-assoc τ₂ τ₃
... | _ , τ₅ , τ₆
-- then we reorganize the store internally to take out the unit value
with repartition τ₅ st
... | cons (vb ×⟨ σ₅ ⟩ nil) ×⟨ σ₆ ⟩ st' rewrite ⊎-id⁻ʳ σ₅ =
let
_ , κ₁ , κ₂ = ⊎-unassoc τ₄ (⊎-comm σ₆)
_ , κ₃ , κ₄ = ⊎-assoc κ₂ (⊎-comm τ₆)
in return (
inj (refl ×⟨ consˡ ⊎-idˡ ⟩ vb)
×⟨ offerᵣ (consˡ κ₄) ⟩
lift (cons (v ×⟨ κ₁ ⟩ st')) (⊎-∙ₗ (⊎-comm κ₃)))
-- A linear (strong) update on the store
update! : ∀ {a b} → ∀[ Just a ⇒ (V a ─✴ StateT M Cells (V b)) ─✴ StateT M Cells (Just b) ]
app (update! ptr) f σ = do
a ×⟨ σ₁ ⟩ f ← read ptr &⟨ σ ⟩ f
b ← app f a (⊎-comm σ₁)
newref b
| 37.538462
| 99
| 0.643443
|
129b20e931d2ae83feeb6438703247423470e654
| 2,495
|
agda
|
Agda
|
agda-stdlib/src/Data/Maybe/Relation/Unary/Any.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Maybe/Relation/Unary/Any.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Maybe/Relation/Unary/Any.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Maybes where one of the elements satisfies a given property
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Maybe.Relation.Unary.Any where
open import Data.Maybe.Base using (Maybe; just; nothing)
open import Data.Product as Prod using (∃; _,_; -,_)
open import Function.Base using (id)
open import Function.Equivalence using (_⇔_; equivalence)
open import Level
open import Relation.Binary.PropositionalEquality as P using (_≡_; cong)
open import Relation.Unary
open import Relation.Nullary hiding (Irrelevant)
import Relation.Nullary.Decidable as Dec
------------------------------------------------------------------------
-- Definition
data Any {a p} {A : Set a} (P : Pred A p) : Pred (Maybe A) (a ⊔ p) where
just : ∀ {x} → P x → Any P (just x)
------------------------------------------------------------------------
-- Basic operations
module _ {a p} {A : Set a} {P : Pred A p} where
drop-just : ∀ {x} → Any P (just x) → P x
drop-just (just px) = px
just-equivalence : ∀ {x} → P x ⇔ Any P (just x)
just-equivalence = equivalence just drop-just
map : ∀ {q} {Q : Pred A q} → P ⊆ Q → Any P ⊆ Any Q
map f (just px) = just (f px)
satisfied : ∀ {x} → Any P x → ∃ P
satisfied (just p) = -, p
------------------------------------------------------------------------
-- (un/)zip(/With)
module _ {a p q r} {A : Set a} {P : Pred A p} {Q : Pred A q} {R : Pred A r} where
zipWith : P ∩ Q ⊆ R → Any P ∩ Any Q ⊆ Any R
zipWith f (just px , just qx) = just (f (px , qx))
unzipWith : P ⊆ Q ∩ R → Any P ⊆ Any Q ∩ Any R
unzipWith f (just px) = Prod.map just just (f px)
module _ {a p q} {A : Set a} {P : Pred A p} {Q : Pred A q} where
zip : Any P ∩ Any Q ⊆ Any (P ∩ Q)
zip = zipWith id
unzip : Any (P ∩ Q) ⊆ Any P ∩ Any Q
unzip = unzipWith id
------------------------------------------------------------------------
-- Seeing Any as a predicate transformer
module _ {a p} {A : Set a} {P : Pred A p} where
dec : Decidable P → Decidable (Any P)
dec P-dec nothing = no λ ()
dec P-dec (just x) = Dec.map just-equivalence (P-dec x)
irrelevant : Irrelevant P → Irrelevant (Any P)
irrelevant P-irrelevant (just p) (just q) = cong just (P-irrelevant p q)
satisfiable : Satisfiable P → Satisfiable (Any P)
satisfiable P-satisfiable = Prod.map just just P-satisfiable
| 32.402597
| 81
| 0.521042
|
3d75ba8f5c0ad68ce5be70b8ceccf6359446a423
| 503
|
agda
|
Agda
|
test/succeed/Epic.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/succeed/Epic.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | null | null | null |
test/succeed/Epic.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
module Epic where
data Nat : Set where
Z : Nat
S : Nat -> Nat
_+_ : Nat -> Nat -> Nat
Z + m = m
S n + m = S (n + m)
_*_ : Nat -> Nat -> Nat
Z * m = Z
S n * m = m + (n * m)
{-# BUILTIN NATURAL Nat #-}
{-# BUILTIN NATPLUS _+_ #-}
{-# BUILTIN NATTIMES _*_ #-}
data Unit : Set where
unit : Unit
postulate
IO : Set -> Set
printNat : Nat -> IO Unit
{-# COMPILED_EPIC printNat (a : BigInt, u : Unit) -> Unit = putStrLn (bigIntToStr(a)) #-}
main : IO Unit
main = printNat (7 * 191)
| 16.225806
| 89
| 0.540755
|
1cb1faac6f3735b9c1f677b1fd7a0da507f1ec9f
| 415
|
agda
|
Agda
|
test/Fail/Issue3124.agda
|
alhassy/agda
|
6043e77e4a72518711f5f808fb4eb593cbf0bb7c
|
[
"BSD-3-Clause"
] | 1
|
2021-07-07T10:49:57.000Z
|
2021-07-07T10:49:57.000Z
|
test/Fail/Issue3124.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/Issue3124.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
-- Andreas, 2018-06-10, issue #3124
-- Wrong context for error IrrelevantDatatype in the coverage checker.
data Squash (A : Set) : Prop where
squash : A → Squash A
test : ∀{A} → Squash (Squash A → A)
test = squash λ{ (squash y) → y }
-- WAS: de Bruijn index in error message
-- Expected error:
-- Cannot split on argument of irrelevant datatype (Squash .A)
-- when checking the definition of .extendedlambda0
| 27.666667
| 70
| 0.698795
|
3d0a12e4cd489739dba01e2b6000ad839e13fefe
| 3,864
|
agda
|
Agda
|
Categories/Category/Monoidal/Closed/IsClosed/Dinatural.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Monoidal/Closed/IsClosed/Dinatural.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
Categories/Category/Monoidal/Closed/IsClosed/Dinatural.agda
|
rei1024/agda-categories
|
89d163f72caa7deeac9413f27bc1b4ed7f9e025b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Category.Monoidal
open import Categories.Category.Monoidal.Closed
module Categories.Category.Monoidal.Closed.IsClosed.Dinatural
{o ℓ e} {C : Category o ℓ e} {M : Monoidal C} (Cl : Closed M) where
open import Data.Product using (Σ; _,_)
open import Function using (_$_) renaming (_∘_ to _∙_)
open import Function.Equality as Π using (Π)
open import Categories.Category.Product
open import Categories.Category.Monoidal.Properties M
open import Categories.Morphism C
open import Categories.Morphism.Properties C
open import Categories.Morphism.Reasoning C
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Bifunctor
open import Categories.Functor.Bifunctor.Properties
open import Categories.NaturalTransformation hiding (id)
open import Categories.NaturalTransformation.Dinatural hiding (_∘ʳ_)
open import Categories.NaturalTransformation.NaturalIsomorphism as NI hiding (refl)
import Categories.Category.Closed as Cls
open Closed Cl
private
open Category C
α⇒ = associator.from
α⇐ = associator.to
module ℱ = Functor
module ⊗ = Functor ⊗
open HomReasoning
open Π.Π
open adjoint renaming (unit to η; counit to ε; Ladjunct to 𝕃; Ladjunct-comm′ to 𝕃-comm′;
Ladjunct-resp-≈ to 𝕃-resp-≈)
open import Categories.Category.Monoidal.Closed.IsClosed.Identity Cl
open import Categories.Category.Monoidal.Closed.IsClosed.L Cl
private
id² : {S T : Obj} → [ S , T ]₀ ⇒ [ S , T ]₀
id² = [ id , id ]₁
L-dinatural-comm : ∀ {X′ Y Z X f} → [ [ f , id ]₁ , id² ]₁ ∘ L X′ Y Z ≈ [ id² , [ f , id ]₁ ]₁ ∘ L X Y Z
L-dinatural-comm {X′} {Y} {Z} {X} {f} = begin
[ fˡ , id² ]₁ ∘ L X′ Y Z ≈⟨ [-,-].F-resp-≈ (refl , [-,-].identity) ⟩∘⟨refl ⟩
[ fˡ , id ]₁ ∘ L X′ Y Z ≈˘⟨ pushˡ [ [-,-] ]-commute ⟩
([ id , 𝕃 L-inner ]₁ ∘ [ fˡ , id ]₁) ∘ η.η YZ ≈˘⟨ pushʳ (mate.commute₁ [ f , id ]₁) ⟩
[ id , 𝕃 L-inner ]₁ ∘ 𝕃 (id ⊗₁ fˡ) ≈˘⟨ pushˡ (ℱ.homomorphism [ XY ,-]) ⟩
𝕃 (𝕃 L-inner ∘ id ⊗₁ fˡ) ≈˘⟨ 𝕃-resp-≈ 𝕃-comm′ ⟩
𝕃 (𝕃 $ L-inner ∘ (id ⊗₁ fˡ) ⊗₁ id) ≈⟨ 𝕃-resp-≈ $ 𝕃-resp-≈ push-f-right ⟩
𝕃 (𝕃 $ L-inner ∘ (id ⊗₁ id) ⊗₁ f) ≈⟨ 𝕃-resp-≈ $ pushˡ (ℱ.homomorphism [ X′ ,-]) ⟩
𝕃 ([ id , L-inner {X} ]₁ ∘ 𝕃 ((id ⊗₁ id) ⊗₁ f)) ≈⟨ 𝕃-resp-≈ $ ∘-resp-≈ʳ (∘-resp-≈ˡ (X′-resp-≈ (⊗.F-resp-≈ (⊗.identity , refl))) ○ mate.commute₁ f) ⟩
𝕃 ([ id , L-inner {X} ]₁ ∘ fˡ ∘ η.η (YZ ⊗₀ XY)) ≈⟨ 𝕃-resp-≈ $ pullˡ [ [-,-] ]-commute ○ assoc ⟩
𝕃 (fˡ ∘ 𝕃 L-inner) ≈⟨ ∘-resp-≈ˡ (ℱ.homomorphism [ XY ,-]) ○ assoc ⟩
[ id , fˡ ]₁ ∘ L X Y Z ≈˘⟨ [-,-].F-resp-≈ ([-,-].identity , refl) ⟩∘⟨refl ⟩
[ id² , fˡ ]₁ ∘ L X Y Z ∎
where
fˡ : ∀ {W} → [ X , W ]₀ ⇒ [ X′ , W ]₀
fˡ = [ f , id ]₁
XY = [ X , Y ]₀
YZ = [ Y , Z ]₀
X′-resp-≈ = ℱ.F-resp-≈ [ X′ ,-]
L-inner : ∀ {W} → ([ Y , Z ]₀ ⊗₀ [ W , Y ]₀) ⊗₀ W ⇒ Z
L-inner {W} = ε.η Z ∘ (id ⊗₁ ε.η {W} Y) ∘ α⇒
push-f-right : (ε.η Z ∘ (id ⊗₁ ε.η Y) ∘ α⇒) ∘ (id ⊗₁ fˡ) ⊗₁ id ≈ (ε.η Z ∘ (id ⊗₁ ε.η Y) ∘ α⇒) ∘ (id ⊗₁ id) ⊗₁ f
push-f-right = begin
(ε.η Z ∘ (id ⊗₁ ε.η Y) ∘ α⇒) ∘ (id ⊗₁ fˡ) ⊗₁ id ≈⟨ pull-last assoc-commute-from ⟩
ε.η Z ∘ (id ⊗₁ ε.η Y) ∘ id ⊗₁ fˡ ⊗₁ id ∘ α⇒ ≈˘⟨ refl⟩∘⟨ pushˡ (ℱ.homomorphism (YZ ⊗-)) ⟩
ε.η Z ∘ id ⊗₁ (ε.η Y ∘ fˡ ⊗₁ id) ∘ α⇒ ≈⟨ refl⟩∘⟨ ℱ.F-resp-≈ (YZ ⊗-) (mate.commute₂ f) ⟩∘⟨refl ⟩
ε.η Z ∘ id ⊗₁ (ε.η Y ∘ id ⊗₁ f) ∘ α⇒ ≈⟨ refl⟩∘⟨ ℱ.homomorphism (YZ ⊗-) ⟩∘⟨refl ⟩
ε.η Z ∘ (id ⊗₁ ε.η Y ∘ id ⊗₁ id ⊗₁ f) ∘ α⇒ ≈⟨ center⁻¹ refl (⟺ assoc-commute-from) ○ pullˡ assoc ⟩
(ε.η Z ∘ id ⊗₁ ε.η Y ∘ α⇒) ∘ (id ⊗₁ id) ⊗₁ f ∎
| 49.538462
| 156
| 0.527174
|
2287ab5653500353be0cebfeb8c85251e4713d2a
| 346
|
agda
|
Agda
|
test/Fail/TerminationInfiniteRecord.agda
|
hborum/agda
|
aac88412199dd4cbcb041aab499d8a6b7e3f4a2e
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Fail/TerminationInfiniteRecord.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Fail/TerminationInfiniteRecord.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
-- 2010-10-02, see issue 334
module TerminationInfiniteRecord where
record Empty : Set where
inductive
constructor empty
field
fromEmpty : Empty
elimEmpty : Empty -> Set
elimEmpty (empty e) = elimEmpty e
-- this no longer termination checks
-- and it should not, since it is translated to
-- elimEmpty e' = elimEmpty (fromEmpty e')
| 20.352941
| 47
| 0.731214
|
12a28add40ad5648cd3ef98c0392a376f11ae551
| 395
|
agda
|
Agda
|
test/interaction/Issue4160.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue4160.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue4160.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --show-implicit #-}
data Bool : Set where
true : Bool
false : Bool
data D : Set where
d : D
data E : Set where
e : E
HSet : Set₁
HSet = {b : Bool} → Set
-- Here HA is HSet
-- The output of this function is the set E, for input HSet G.
⊨_ : HSet → Set
⊨_ HA = HA {true}
G : HSet
G {true} = E
G {false} = D
noo : ⊨ G {false}
noo = {!!}
boo : ⊨ λ {b} → G {b}
boo = {!!}
| 13.166667
| 62
| 0.546835
|
2254c1a431bc1b864f4888ffc61787b08c97eb69
| 23
|
agda
|
Agda
|
test/Succeed/installed-libs/Installed.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/installed-libs/Installed.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/installed-libs/Installed.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Installed where
| 11.5
| 22
| 0.869565
|
3d051057746c25a0f008c09f9481148700a13725
| 16,746
|
agda
|
Agda
|
Cubical/Data/BinNat/BinNat.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/Data/BinNat/BinNat.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/Data/BinNat/BinNat.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{- Binary natural numbers (Anders Mörtberg, Jan. 2019)
This file defines two representations of binary numbers. We prove that
they are equivalent to unary numbers and univalence is then used to
transport both programs and properties between the representations.
This is an example of how having computational univalence can be
useful for practical programming.
The first definition is [Binℕ] and the numbers are essentially lists
of 0/1 with no trailing zeroes (in little-endian format). The main
definitions and examples are:
- Equivalence between Binℕ and ℕ ([Binℕ≃ℕ]) with an equality obtained
using univalence ([Binℕ≡ℕ]).
- Addition on Binℕ defined by transporting addition on ℕ to Binℕ
([_+Binℕ_]) along Binℕ≡ℕ together with a proof that addition on Binℕ
is associative obtained by transporting the proof for ℕ ([+Binℕ-assoc]).
- Functions testing whether a binary number is odd or even in O(1)
([oddBinℕ], [evenBinℕ]) and the corresponding functions for ℕ
obtained by transport. Proof that odd numbers are not even
transported from Binℕ to ℕ ([oddℕnotEvenℕ]).
- An example of the structure identity principle for natural number
structures ([NatImpl]). We first prove that Binℕ≡ℕ lifts to natural
number structures ([NatImplℕ≡Binℕ]) and we then use this to
transport "+-suc : m + suc n ≡ suc (m + n)" from ℕ to Binℕ ([+Binℕ-suc]).
- An example of program/data refinement using the structure identity
principle where we transport a property that is infeasible to prove
by computation for ℕ ([propDoubleℕ]):
2^20 * 2^10 = 2^5 * (2^15 * 2^10)
from the corresponding result on Binℕ which is proved instantly by
refl ([propDoubleBinℕ]).
These examples are inspired from an old cubicaltt formalization:
https://github.com/mortberg/cubicaltt/blob/master/examples/binnat.ctt
which itself is based on an even older cubical formalization (from 2014):
https://github.com/simhu/cubical/blob/master/examples/binnat.cub
The second representation is more non-standard and inspired by:
https://github.com/RedPRL/redtt/blob/master/library/cool/nats.red
Only some of the experiments have been done for this representation,
but it has the virtue of being a bit simpler to prove equivalent to
ℕ. The same representation can be found in:
http://www.cs.bham.ac.uk/~mhe/agda-new/BinaryNaturals.html
-}
{-# OPTIONS --cubical --no-exact-split --safe #-}
module Cubical.Data.BinNat.BinNat where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Nat
open import Cubical.Data.Bool
open import Cubical.Data.Empty
open import Cubical.Relation.Nullary
data Binℕ : Type₀
data Pos : Type₀
-- Binary natural numbers
data Binℕ where
binℕ0 : Binℕ
binℕpos : Pos → Binℕ
-- Positive binary numbers
data Pos where
x0 : Pos → Pos
x1 : Binℕ → Pos
pattern pos1 = x1 binℕ0
pattern x1-pos n = x1 (binℕpos n)
-- Note on notation:
-- We use "⇒" for functions that are equivalences (and therefore
-- they don't preserve the numerical value where the ranges don't
-- match, as with Binℕ⇒Pos).
--
-- We use "→" for the opposite situation (numerical value is preserved,
-- but the function is not necessarily an equivalence)
Binℕ⇒Pos : Binℕ → Pos
sucPos : Pos → Pos
Binℕ⇒Pos binℕ0 = pos1
Binℕ⇒Pos (binℕpos n) = sucPos n
sucPos (x0 ps) = x1-pos ps
sucPos (x1 ps) = x0 (Binℕ⇒Pos ps)
Binℕ→ℕ : Binℕ → ℕ
Pos⇒ℕ : Pos → ℕ
Pos→ℕ : Pos → ℕ
Binℕ→ℕ binℕ0 = zero
Binℕ→ℕ (binℕpos x) = Pos→ℕ x
Pos→ℕ ps = suc (Pos⇒ℕ ps)
Pos⇒ℕ (x0 ps) = suc (doubleℕ (Pos⇒ℕ ps))
Pos⇒ℕ (x1 ps) = doubleℕ (Binℕ→ℕ ps)
posInd : {P : Pos → Type₀} → P pos1 → ((p : Pos) → P p → P (sucPos p)) → (p : Pos) → P p
posInd {P} h1 hs ps = f ps
where
H : (p : Pos) → P (x0 p) → P (x0 (sucPos p))
H p hx0p = hs (x1-pos p) (hs (x0 p) hx0p)
f : (ps : Pos) → P ps
f pos1 = h1
f (x0 ps) = posInd (hs pos1 h1) H ps
f (x1-pos ps) = hs (x0 ps) (posInd (hs pos1 h1) H ps)
Binℕ⇒Pos⇒ℕ : (p : Binℕ) → Pos⇒ℕ (Binℕ⇒Pos p) ≡ Binℕ→ℕ p
Binℕ⇒Pos⇒ℕ binℕ0 = refl
Binℕ⇒Pos⇒ℕ (binℕpos (x0 p)) = refl
Binℕ⇒Pos⇒ℕ (binℕpos (x1 x)) = λ i → suc (doubleℕ (Binℕ⇒Pos⇒ℕ x i))
Pos⇒ℕsucPos : (p : Pos) → Pos⇒ℕ (sucPos p) ≡ suc (Pos⇒ℕ p)
Pos⇒ℕsucPos p = Binℕ⇒Pos⇒ℕ (binℕpos p)
Pos→ℕsucPos : (p : Pos) → Pos→ℕ (sucPos p) ≡ suc (Pos→ℕ p)
Pos→ℕsucPos p = cong suc (Binℕ⇒Pos⇒ℕ (binℕpos p))
ℕ⇒Pos : ℕ → Pos
ℕ⇒Pos zero = pos1
ℕ⇒Pos (suc n) = sucPos (ℕ⇒Pos n)
ℕ→Pos : ℕ → Pos
ℕ→Pos zero = pos1
ℕ→Pos (suc n) = ℕ⇒Pos n
Pos⇒ℕ⇒Pos : (p : Pos) → ℕ⇒Pos (Pos⇒ℕ p) ≡ p
Pos⇒ℕ⇒Pos p = posInd refl hs p
where
hs : (p : Pos) → ℕ⇒Pos (Pos⇒ℕ p) ≡ p → ℕ⇒Pos (Pos⇒ℕ (sucPos p)) ≡ sucPos p
hs p hp =
ℕ⇒Pos (Pos⇒ℕ (sucPos p)) ≡⟨ cong ℕ⇒Pos (Pos⇒ℕsucPos p) ⟩
sucPos (ℕ⇒Pos (Pos⇒ℕ p)) ≡⟨ cong sucPos hp ⟩
sucPos p ∎
ℕ⇒Pos⇒ℕ : (n : ℕ) → Pos⇒ℕ (ℕ⇒Pos n) ≡ n
ℕ⇒Pos⇒ℕ zero = refl
ℕ⇒Pos⇒ℕ (suc n) =
Pos⇒ℕ (ℕ⇒Pos (suc n)) ≡⟨ Pos⇒ℕsucPos (ℕ⇒Pos n) ⟩
suc (Pos⇒ℕ (ℕ⇒Pos n)) ≡⟨ cong suc (ℕ⇒Pos⇒ℕ n) ⟩
suc n ∎
ℕ→Binℕ : ℕ → Binℕ
ℕ→Binℕ zero = binℕ0
ℕ→Binℕ (suc n) = binℕpos (ℕ⇒Pos n)
ℕ→Binℕ→ℕ : (n : ℕ) → Binℕ→ℕ (ℕ→Binℕ n) ≡ n
ℕ→Binℕ→ℕ zero = refl
ℕ→Binℕ→ℕ (suc n) = cong suc (ℕ⇒Pos⇒ℕ n)
Binℕ→ℕ→Binℕ : (n : Binℕ) → ℕ→Binℕ (Binℕ→ℕ n) ≡ n
Binℕ→ℕ→Binℕ binℕ0 = refl
Binℕ→ℕ→Binℕ (binℕpos p) = cong binℕpos (Pos⇒ℕ⇒Pos p)
Binℕ≃ℕ : Binℕ ≃ ℕ
Binℕ≃ℕ = isoToEquiv (iso Binℕ→ℕ ℕ→Binℕ ℕ→Binℕ→ℕ Binℕ→ℕ→Binℕ)
-- Use univalence (in fact only "ua") to get an equality from the
-- above equivalence
Binℕ≡ℕ : Binℕ ≡ ℕ
Binℕ≡ℕ = ua Binℕ≃ℕ
sucBinℕ : Binℕ → Binℕ
sucBinℕ x = binℕpos (Binℕ⇒Pos x)
Binℕ→ℕsuc : (x : Binℕ) → suc (Binℕ→ℕ x) ≡ Binℕ→ℕ (sucBinℕ x)
Binℕ→ℕsuc binℕ0 = refl
Binℕ→ℕsuc (binℕpos x) = sym (Pos→ℕsucPos x)
-- We can transport addition on ℕ to Binℕ
_+Binℕ_ : Binℕ → Binℕ → Binℕ
_+Binℕ_ = transport (λ i → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i)) _+_
-- Test: 4 + 1 = 5
private
_ : binℕpos (x0 (x0 pos1)) +Binℕ binℕpos pos1 ≡ binℕpos (x1-pos (x0 pos1))
_ = refl
-- It is easy to test if binary numbers are odd
oddBinℕ : Binℕ → Bool
oddBinℕ binℕ0 = false
oddBinℕ (binℕpos (x0 _)) = false
oddBinℕ (binℕpos (x1 _)) = true
evenBinℕ : Binℕ → Bool
evenBinℕ n = oddBinℕ (sucBinℕ n)
-- And prove the following property (without induction)
oddBinℕnotEvenBinℕ : (n : Binℕ) → oddBinℕ n ≡ not (evenBinℕ n)
oddBinℕnotEvenBinℕ binℕ0 = refl
oddBinℕnotEvenBinℕ (binℕpos (x0 x)) = refl
oddBinℕnotEvenBinℕ (binℕpos (x1 x)) = refl
-- It is also easy to define and prove the property for unary numbers,
-- however the definition uses recursion and the proof induction
private
oddn : ℕ → Bool
oddn zero = true
oddn (suc x) = not (oddn x)
evenn : ℕ → Bool
evenn n = not (oddn n)
oddnSuc : (n : ℕ) → oddn n ≡ not (evenn n)
oddnSuc zero = refl
oddnSuc (suc n) = cong not (oddnSuc n)
-- So what we can do instead is to transport the odd test from Binℕ to
-- ℕ along the equality
oddℕ : ℕ → Bool
oddℕ = transport (λ i → Binℕ≡ℕ i → Bool) oddBinℕ
evenℕ : ℕ → Bool
evenℕ = transport (λ i → Binℕ≡ℕ i → Bool) evenBinℕ
-- We can then also transport the property
oddℕnotEvenℕ : (n : ℕ) → oddℕ n ≡ not (evenℕ n)
oddℕnotEvenℕ =
let -- We first build a path from oddBinℕ to oddℕ. When i=1 this is
-- "transp (λ j → Binℕ≡ℕ j → Bool) i0 oddBinℕ" (i.e. oddℕ)
oddp : PathP (λ i → Binℕ≡ℕ i → Bool) oddBinℕ oddℕ
oddp i = transp (λ j → Binℕ≡ℕ (i ∧ j) → Bool) (~ i) oddBinℕ
-- We then build a path from evenBinℕ to evenℕ
evenp : PathP (λ i → Binℕ≡ℕ i → Bool) evenBinℕ evenℕ
evenp i = transp (λ j → Binℕ≡ℕ (i ∧ j) → Bool) (~ i) evenBinℕ
in -- Then transport oddBinℕnotEvenBinℕ in a suitable equality type
-- When i=0 this is "(n : Binℕ) → oddBinℕ n ≡ not (evenBinℕ n)"
-- When i=1 this is "(n : ℕ) → oddℕ n ≡ not (evenℕ n)"
transport (λ i → (n : Binℕ≡ℕ i) → oddp i n ≡ not (evenp i n)) oddBinℕnotEvenBinℕ
-- We can do the same for natural numbers:
-- First construct the path
addp : PathP (λ i → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i)) _+_ _+Binℕ_
addp i = transp (λ j → Binℕ≡ℕ (~ i ∨ ~ j) → Binℕ≡ℕ (~ i ∨ ~ j) → Binℕ≡ℕ (~ i ∨ ~ j)) (~ i) _+_
-- Then transport associativity:
+Binℕ-assoc : ∀ m n o → m +Binℕ (n +Binℕ o) ≡ (m +Binℕ n) +Binℕ o
+Binℕ-assoc =
transport (λ i → (m n o : Binℕ≡ℕ (~ i))
→ addp i m (addp i n o) ≡ addp i (addp i m n) o) +-assoc
-- We can also define what it means to be an implementation of natural
-- numbers and use this to transport properties between different
-- implementation of natural numbers. This can be seen as a special
-- case of the structure identity principle: any property that holds
-- for one structure also holds for an equivalent one.
-- An implementation of natural numbers (i.e. a "natural number
-- structure") has a zero and successor.
record NatImpl (A : Type₀) : Type₀ where
field
z : A
s : A → A
open NatImpl
NatImplℕ : NatImpl ℕ
z NatImplℕ = zero
s NatImplℕ = suc
NatImplBinℕ : NatImpl Binℕ
z NatImplBinℕ = binℕ0
s NatImplBinℕ = sucBinℕ
-- Using the equality between binary and unary numbers we can get an
-- equality between the two implementations of the NatImpl interface
NatImplℕ≡Binℕ : PathP (λ i → NatImpl (Binℕ≡ℕ (~ i))) NatImplℕ NatImplBinℕ
z (NatImplℕ≡Binℕ i) = transp (λ j → Binℕ≡ℕ (~ i ∨ ~ j)) (~ i) zero
s (NatImplℕ≡Binℕ i) =
λ x → glue (λ { (i = i0) → suc x
; (i = i1) → sucBinℕ x })
-- We need to do use and hcomp to do and endpoint
-- correction as "suc (unglue x)" connects "suc x"
-- with "suc (Binℕ→ℕ x)" along i (which makes sense as
-- x varies from ℕ to Binℕ along i), but we need
-- something from "suc x" to "Binℕ→ℕ (sucBinℕ x)" for
-- the glue to be well-formed
(hcomp (λ j → λ { (i = i0) → suc x
; (i = i1) → Binℕ→ℕsuc x j })
(suc (unglue (i ∨ ~ i) x)))
-- We then use this to transport +-suc from unary to binary numbers
+Binℕ-suc : ∀ m n → m +Binℕ sucBinℕ n ≡ sucBinℕ (m +Binℕ n)
+Binℕ-suc =
transport (λ i → (m n : Binℕ≡ℕ (~ i))
→ addp i m (NatImplℕ≡Binℕ i .s n) ≡ NatImplℕ≡Binℕ i .s (addp i m n)) +-suc
-- Doubling experiment: we define a notion of "doubling structure" and
-- transport a proof that is proved directly using refl for binary
-- numbers to unary numbers. This is an example of program/data
-- refinement: we can use univalence to prove properties about
-- inefficient data-structures using efficient ones.
-- Doubling structures
record Double {ℓ} (A : Type ℓ) : Type (ℓ-suc ℓ) where
field
-- doubling function computing 2 * x
double : A → A
-- element to double
elt : A
open Double
-- Compute: 2^n * x
doubles : ∀ {ℓ} {A : Type ℓ} (D : Double A) → ℕ → A → A
doubles D n x = iter n (double D) x
Doubleℕ : Double ℕ
double Doubleℕ = doubleℕ
elt Doubleℕ = n1024
where
-- 1024 = 2^8 * 2^2 = 2^10
n1024 : ℕ
n1024 = doublesℕ 8 4
-- The doubling operation on binary numbers is O(1), while for unary
-- numbers it is O(n). What is of course even more problematic is that
-- we cannot handle very big unary natural numbers, but with binary
-- there is no problem to represent very big numbers
doubleBinℕ : Binℕ → Binℕ
doubleBinℕ binℕ0 = binℕ0
doubleBinℕ (binℕpos x) = binℕpos (x0 x)
DoubleBinℕ : Double Binℕ
double DoubleBinℕ = doubleBinℕ
elt DoubleBinℕ = bin1024
where
-- 1024 = 2^10 = 10000000000₂
bin1024 : Binℕ
bin1024 = binℕpos (x0 (x0 (x0 (x0 (x0 (x0 (x0 (x0 (x0 (x0 pos1))))))))))
-- As these function don't commute strictly we have to prove it
-- separately and insert it in the proof of DoubleBinℕ≡Doubleℕ below
-- (just like we had to in NatImplℕ≡NatImplBinℕ
Binℕ→ℕdouble : (x : Binℕ) → doubleℕ (Binℕ→ℕ x) ≡ Binℕ→ℕ (doubleBinℕ x)
Binℕ→ℕdouble binℕ0 = refl
Binℕ→ℕdouble (binℕpos x) = refl
-- We use the equality between Binℕ and ℕ to get an equality of
-- doubling structures
DoubleBinℕ≡Doubleℕ : PathP (λ i → Double (Binℕ≡ℕ i)) DoubleBinℕ Doubleℕ
double (DoubleBinℕ≡Doubleℕ i) =
λ x → glue (λ { (i = i0) → doubleBinℕ x
; (i = i1) → doubleℕ x })
(hcomp (λ j → λ { (i = i0) → Binℕ→ℕdouble x j
; (i = i1) → doubleℕ x })
(doubleℕ (unglue (i ∨ ~ i) x)))
elt (DoubleBinℕ≡Doubleℕ i) = transp (λ j → Binℕ≡ℕ (i ∨ ~ j)) i (Doubleℕ .elt)
-- We can now use transport to prove a property that is too slow to
-- check with unary numbers. We define the property we want to check
-- as a record so that Agda does not try to unfold it eagerly.
record propDouble {ℓ} {A : Type ℓ} (D : Double A) : Type ℓ where
field
-- 2^20 * e = 2^5 * (2^15 * e)
proof : doubles D 20 (elt D) ≡ doubles D 5 (doubles D 15 (elt D))
open propDouble
-- The property we want to prove takes too long to typecheck for ℕ:
-- propDoubleℕ : propDouble Doubleℕ
-- propDoubleℕ = refl
-- With binary numbers it is instant
propDoubleBinℕ : propDouble DoubleBinℕ
proof propDoubleBinℕ = refl
-- By transporting the proof along the equality we then get it for
-- unary numbers
propDoubleℕ : propDouble Doubleℕ
propDoubleℕ = transport (λ i → propDouble (DoubleBinℕ≡Doubleℕ i)) propDoubleBinℕ
--------------------------------------------------------------------------------
--
-- Alternative encoding of binary natural numbers inspired by:
-- https://github.com/RedPRL/redtt/blob/master/library/cool/nats.red
--
-- This representation makes the equivalence with ℕ a bit easier to
-- prove, but the doubling example wouldn't work as nicely as we
-- cannot define it as an O(1) operation
data binnat : Type₀ where
zero : binnat -- 0
consOdd : binnat → binnat -- 2*n + 1
consEven : binnat → binnat -- 2*{n+1}
binnat→ℕ : binnat → ℕ
binnat→ℕ zero = 0
binnat→ℕ (consOdd n) = suc (doubleℕ (binnat→ℕ n))
binnat→ℕ (consEven n) = suc (suc (doubleℕ (binnat→ℕ n)))
suc-binnat : binnat → binnat
suc-binnat zero = consOdd zero
suc-binnat (consOdd n) = consEven n
suc-binnat (consEven n) = consOdd (suc-binnat n)
ℕ→binnat : ℕ → binnat
ℕ→binnat zero = zero
ℕ→binnat (suc n) = suc-binnat (ℕ→binnat n)
binnat→ℕ-suc : (n : binnat) → binnat→ℕ (suc-binnat n) ≡ suc (binnat→ℕ n)
binnat→ℕ-suc zero = refl
binnat→ℕ-suc (consOdd n) = refl
binnat→ℕ-suc (consEven n) = λ i → suc (doubleℕ (binnat→ℕ-suc n i))
ℕ→binnat→ℕ : (n : ℕ) → binnat→ℕ (ℕ→binnat n) ≡ n
ℕ→binnat→ℕ zero = refl
ℕ→binnat→ℕ (suc n) = (binnat→ℕ-suc (ℕ→binnat n)) ∙ (cong suc (ℕ→binnat→ℕ n))
suc-ℕ→binnat-double : (n : ℕ) → suc-binnat (ℕ→binnat (doubleℕ n)) ≡ consOdd (ℕ→binnat n)
suc-ℕ→binnat-double zero = refl
suc-ℕ→binnat-double (suc n) = λ i → suc-binnat (suc-binnat (suc-ℕ→binnat-double n i))
binnat→ℕ→binnat : (n : binnat) → ℕ→binnat (binnat→ℕ n) ≡ n
binnat→ℕ→binnat zero = refl
binnat→ℕ→binnat (consOdd n) =
(suc-ℕ→binnat-double (binnat→ℕ n)) ∙ (cong consOdd (binnat→ℕ→binnat n))
binnat→ℕ→binnat (consEven n) =
(λ i → suc-binnat (suc-ℕ→binnat-double (binnat→ℕ n) i)) ∙ (cong consEven (binnat→ℕ→binnat n))
ℕ≃binnat : ℕ ≃ binnat
ℕ≃binnat = isoToEquiv (iso ℕ→binnat binnat→ℕ binnat→ℕ→binnat ℕ→binnat→ℕ)
ℕ≡binnat : ℕ ≡ binnat
ℕ≡binnat = ua ℕ≃binnat
-- We can transport addition on ℕ to binnat
_+binnat_ : binnat → binnat → binnat
_+binnat_ = transport (λ i → ℕ≡binnat i → ℕ≡binnat i → ℕ≡binnat i) _+_
-- Test: 4 + 1 = 5
_ : consEven (consOdd zero) +binnat consOdd zero ≡ consOdd (consEven zero)
_ = refl
oddbinnat : binnat → Bool
oddbinnat zero = false
oddbinnat (consOdd _) = true
oddbinnat (consEven _) = false
oddℕ' : ℕ → Bool
oddℕ' = transport (λ i → ℕ≡binnat (~ i) → Bool) oddbinnat
-- The NatImpl example for this representation of binary numbers
private
NatImplbinnat : NatImpl binnat
z NatImplbinnat = zero
s NatImplbinnat = suc-binnat
-- Note that the s case is a bit simpler as no end-point correction
-- is necessary (things commute strictly)
NatImplℕ≡NatImplbinnat : PathP (λ i → NatImpl (ℕ≡binnat i)) NatImplℕ NatImplbinnat
z (NatImplℕ≡NatImplbinnat i) = transp (λ j → ℕ≡binnat (i ∨ ~ j)) i zero
s (NatImplℕ≡NatImplbinnat i) =
λ x → glue (λ { (i = i0) → suc x
; (i = i1) → suc-binnat x })
(suc-binnat (unglue (i ∨ ~ i) x))
oddSuc : (n : binnat) → oddbinnat n ≡ not (oddbinnat (suc-binnat n))
oddSuc zero = refl
oddSuc (consOdd _) = refl
oddSuc (consEven _) = refl
oddℕSuc' : (n : ℕ) → oddℕ' n ≡ not (oddℕ' (suc n))
oddℕSuc' =
let eq : (i : I) → ℕ≡binnat (~ i) → Bool
eq i = transp (λ j → ℕ≡binnat (~ i ∨ ~ j) → Bool) (~ i) oddbinnat
in transport
(λ i → (n : ℕ≡binnat (~ i)) → eq i n ≡ not (eq i (NatImplℕ≡NatImplbinnat (~ i) .NatImpl.s n)))
oddSuc
| 33.967546
| 104
| 0.645766
|
dcbe4853d786413d9d8249b745de852e217a1e57
| 1,687
|
agda
|
Agda
|
test/Succeed/Issue3296.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3296.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3296.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Generalized variables in datatype (and record) parameters
module _ where
open import Agda.Primitive
open import Agda.Builtin.Nat
module NotParameterised where
variable
ℓ : Level
A : Set ℓ
x y : A
m n : Nat
data Vec (A : Set ℓ) : Nat → Set ℓ where
[] : Vec A zero
_∷_ : A → Vec A n → Vec A (suc n)
variable
xs : Vec A n
-- n should be generalized as an index here
data All (P : A → Set ℓ) : Vec A n → Set ℓ where
[] : All P []
_∷_ : P x → All P xs → All P (x ∷ xs)
infix 2 _∈_
-- need an occurrence of ℓ in the params to not generalize it as an index,
-- so we bind A explicitly
data _∈_ {A : Set ℓ} (x : A) : Vec A n → Set ℓ where
zero : x ∈ x ∷ xs
suc : x ∈ xs → x ∈ y ∷ xs
lookup : {P : A → Set ℓ} → All P xs → x ∈ xs → P x
lookup (x ∷ _) zero = x
lookup (_ ∷ xs) (suc i) = lookup xs i
-- Check that we can do the same in a parameterised module
module Parameterised (Dummy : Set) where
variable
ℓ : Level
A : Set ℓ
x y : A
m n : Nat
data Vec (A : Set ℓ) : Nat → Set ℓ where
[] : Vec A zero
_∷_ : A → Vec A n → Vec A (suc n)
variable
xs : Vec A n
-- n should be generalized as an index here
data All (P : A → Set ℓ) : Vec A n → Set ℓ where
[] : All P []
_∷_ : P x → All P xs → All P (x ∷ xs)
infix 2 _∈_
-- need an occurrence of ℓ in the params to not generalize it as an index,
-- so we bind A explicitly
data _∈_ {A : Set ℓ} (x : A) : Vec A n → Set ℓ where
zero : x ∈ x ∷ xs
suc : x ∈ xs → x ∈ y ∷ xs
lookup : {P : A → Set ℓ} → All P xs → x ∈ xs → P x
lookup (x ∷ _) zero = x
lookup (_ ∷ xs) (suc i) = lookup xs i
| 23.760563
| 76
| 0.548903
|
c782aedd1260222a064a36944bc62baa24f938a8
| 793
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Relation/Binary/Properties/StrictPartialOrder.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
test/asset/agda-stdlib-1.0/Relation/Binary/Properties/StrictPartialOrder.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Binary/Properties/StrictPartialOrder.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties satisfied by strict partial orders
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Properties.StrictPartialOrder
{s₁ s₂ s₃} (SPO : StrictPartialOrder s₁ s₂ s₃) where
open Relation.Binary.StrictPartialOrder SPO
renaming (trans to <-trans)
open import Relation.Binary.Construct.StrictToNonStrict _≈_ _<_
------------------------------------------------------------------------
-- Strict partial orders can be converted to posets
poset : Poset _ _ _
poset = record
{ isPartialOrder = isPartialOrder isStrictPartialOrder
}
open Poset poset public
| 29.37037
| 72
| 0.551072
|
4dcaf0c3519f6020f7229765d7bb2e7c78caa340
| 1,426
|
agda
|
Agda
|
lib/Haskell/Prim/Word.agda
|
JonathanBrouwer/agda2hs
|
dcf63cc7ce51a325a97ac58bdd0aeace24c08b15
|
[
"MIT"
] | 55
|
2020-10-20T13:36:25.000Z
|
2022-03-26T21:57:56.000Z
|
lib/Haskell/Prim/Word.agda
|
SNU-2D/agda2hs
|
160478a51bc78b0fdab07b968464420439f9fed6
|
[
"MIT"
] | 63
|
2020-10-22T05:19:27.000Z
|
2022-02-25T15:47:30.000Z
|
lib/Haskell/Prim/Word.agda
|
SNU-2D/agda2hs
|
160478a51bc78b0fdab07b968464420439f9fed6
|
[
"MIT"
] | 18
|
2020-10-21T22:19:09.000Z
|
2022-03-12T11:42:52.000Z
|
module Haskell.Prim.Word where
open import Agda.Builtin.Nat
open import Agda.Builtin.Bool
open import Agda.Builtin.List
open import Agda.Builtin.Char
open import Agda.Builtin.String
open import Agda.Builtin.Unit
open import Agda.Builtin.Int using (pos; negsuc)
import Agda.Builtin.Word renaming (Word64 to Word; primWord64ToNat to w2n; primWord64FromNat to n2w)
open Agda.Builtin.Word
open Agda.Builtin.Word public using (Word)
open import Haskell.Prim
open import Haskell.Prim.Integer
--------------------------------------------------
-- Literals
private
2⁶⁴ : Nat
2⁶⁴ = 18446744073709551616
instance
iNumberWord : Number Word
iNumberWord .Number.Constraint n = IsTrue (n < 2⁶⁴)
iNumberWord .fromNat n = n2w n
--------------------------------------------------
-- Arithmetic
negateWord : Word → Word
negateWord a = n2w (2⁶⁴ - w2n a)
addWord : Word → Word → Word
addWord a b = n2w (w2n a + w2n b)
subWord : Word → Word → Word
subWord a b = addWord a (negateWord b)
mulWord : Word → Word → Word
mulWord a b = n2w (w2n a * w2n b)
eqWord : Word → Word → Bool
eqWord a b = w2n a == w2n b
ltWord : Word → Word → Bool
ltWord a b = w2n a < w2n b
showWord : Word → List Char
showWord a = primStringToList (primShowNat (w2n a))
integerToWord : Integer → Word
integerToWord (pos n) = n2w n
integerToWord (negsuc n) = negateWord (n2w (suc n))
wordToInteger : Word → Integer
wordToInteger n = pos (w2n n)
| 22.634921
| 100
| 0.675316
|
3d8d371cf1d54491a427382446c87e8a97f8dc11
| 170
|
agda
|
Agda
|
examples/AIM6/Path/All.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/AIM6/Path/All.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/AIM6/Path/All.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module All where
import Prelude
import Star
import Nat
import List
import Vec
import Elem
import Fin
import Modal
import Lambda
import Span
import MapTm
import Examples
| 11.333333
| 16
| 0.835294
|
0b0b3cd4157eb2397de86eb04ab0596df4bcf880
| 3,170
|
agda
|
Agda
|
Cubical/Categories/Morphism.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Morphism.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Morphism.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Categories.Morphism where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Sigma
open import Cubical.Categories.Category
private
variable
ℓ ℓ' : Level
module _ {C : Precategory ℓ ℓ'} where
open Precategory C
private
variable
x y z w : ob
isMonic : (Hom[ x , y ]) → Type (ℓ-max ℓ ℓ')
isMonic {x} {y} f = ∀ {z : ob} {a a' : Hom[ z , x ]}
→ (f ∘ a ≡ f ∘ a') → (a ≡ a')
isEpic : (Hom[ x , y ]) → Type (ℓ-max ℓ ℓ')
isEpic {x} {y} g = ∀ {z : ob} {b b' : Hom[ y , z ]}
→ (b ∘ g ≡ b' ∘ g) → (b ≡ b')
-- A morphism is split monic if it has a *retraction*
isSplitMon : (Hom[ x , y ]) → Type ℓ'
isSplitMon {x} {y} f = ∃[ r ∈ Hom[ y , x ] ] r ∘ f ≡ id x
-- A morphism is split epic if it has a *section*
isSplitEpi : (Hom[ x , y ]) → Type ℓ'
isSplitEpi {x} {y} g = ∃[ s ∈ Hom[ y , x ] ] g ∘ s ≡ id y
record areInv (f : Hom[ x , y ]) (g : Hom[ y , x ]) : Type ℓ' where
field
sec : g ⋆ f ≡ id y
ret : f ⋆ g ≡ id x
open areInv
symAreInv : ∀ {f : Hom[ x , y ]} {g : Hom[ y , x ]}
→ areInv f g
→ areInv g f
symAreInv record { sec = sec ; ret = ret } = record { sec = ret ; ret = sec }
-- equational reasoning with inverses
invMoveR : ∀ {f : Hom[ x , y ]} {g : Hom[ y , x ]} {h : Hom[ z , x ]} {k : Hom[ z , y ]}
→ areInv f g
→ h ⋆ f ≡ k
→ h ≡ k ⋆ g
invMoveR {f = f} {g} {h} {k} ai p
= h
≡⟨ sym (⋆IdR _) ⟩
(h ⋆ id _)
≡⟨ cong (h ⋆_) (sym (ai .ret)) ⟩
(h ⋆ (f ⋆ g))
≡⟨ sym (⋆Assoc _ _ _) ⟩
((h ⋆ f) ⋆ g)
≡⟨ cong (_⋆ g) p ⟩
k ⋆ g
∎
invMoveL : ∀ {f : Hom[ x , y ]} {g : Hom[ y , x ]} {h : Hom[ y , z ]} {k : Hom[ x , z ]}
→ areInv f g
→ f ⋆ h ≡ k
→ h ≡ g ⋆ k
invMoveL {f = f} {g} {h} {k} ai p
= h
≡⟨ sym (⋆IdL _) ⟩
id _ ⋆ h
≡⟨ cong (_⋆ h) (sym (ai .sec)) ⟩
(g ⋆ f) ⋆ h
≡⟨ ⋆Assoc _ _ _ ⟩
g ⋆ (f ⋆ h)
≡⟨ cong (g ⋆_) p ⟩
(g ⋆ k)
∎
record isIso (f : Hom[ x , y ]) : Type ℓ' where
field
inv : Hom[ y , x ]
sec : inv ⋆ f ≡ id y
ret : f ⋆ inv ≡ id x
open isIso
isIso→areInv : ∀ {f : Hom[ x , y ]}
→ (isI : isIso f)
→ areInv f (isI .inv)
isIso→areInv record { inv = inv ; sec = sec ; ret = ret } = record { sec = sec ; ret = ret }
open CatIso
-- isIso agrees with CatIso
isIso→CatIso : ∀ {f : C [ x , y ]}
→ isIso f
→ CatIso {C = C} x y
isIso→CatIso {f = f} record { inv = f⁻¹ ; sec = sec ; ret = ret } = catiso f f⁻¹ sec ret
CatIso→isIso : (cIso : CatIso {C = C} x y)
→ isIso (cIso .mor)
CatIso→isIso (catiso mor inv sec ret) = record { inv = inv ; sec = sec ; ret = ret }
CatIso→areInv : (cIso : CatIso {C = C} x y)
→ areInv (cIso .mor) (cIso .inv)
CatIso→areInv cIso = isIso→areInv (CatIso→isIso cIso)
-- reverse of an iso is also an iso
symCatIso : ∀ {x y}
→ CatIso {C = C} x y
→ CatIso {C = C} y x
symCatIso (catiso mor inv sec ret) = catiso inv mor ret sec
| 27.807018
| 94
| 0.460568
|
4d0b752d0a46f7e30b8485ca8551087eb9c447f5
| 187
|
agda
|
Agda
|
src/Impure/STLCRef/Readme.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
src/Impure/STLCRef/Readme.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
src/Impure/STLCRef/Readme.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
module Impure.STLCRef.Readme where
open import Impure.STLCRef.Syntax
open import Impure.STLCRef.Welltyped
open import Impure.STLCRef.Eval
open import Impure.STLCRef.Properties.Soundness
| 26.714286
| 47
| 0.855615
|
581611d1662519059668fdc93d65d5e1acf8eb5c
| 7,024
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Fin/Base.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Fin/Base.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Fin/Base.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Finite sets
------------------------------------------------------------------------
-- Note that elements of Fin n can be seen as natural numbers in the
-- set {m | m < n}. The notation "m" in comments below refers to this
-- natural number view.
{-# OPTIONS --without-K --safe #-}
module Data.Fin.Base where
open import Data.Empty using (⊥-elim)
open import Data.Nat as ℕ
using (ℕ; zero; suc; z≤n; s≤s)
open import Function using (_∘_; _on_)
open import Level using () renaming (zero to ℓ₀)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Decidable using (True; toWitness)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
using (_≡_; _≢_; refl; cong)
------------------------------------------------------------------------
-- Types
-- Fin n is a type with n elements.
data Fin : ℕ → Set where
zero : {n : ℕ} → Fin (suc n)
suc : {n : ℕ} (i : Fin n) → Fin (suc n)
-- A conversion: toℕ "i" = i.
toℕ : ∀ {n} → Fin n → ℕ
toℕ zero = 0
toℕ (suc i) = suc (toℕ i)
-- A Fin-indexed variant of Fin.
Fin′ : ∀ {n} → Fin n → Set
Fin′ i = Fin (toℕ i)
------------------------------------------------------------------------
-- A cast that actually computes on constructors (as opposed to subst)
cast : ∀ {m n} → .(_ : m ≡ n) → Fin m → Fin n
cast {zero} {zero} eq k = k
cast {suc m} {suc n} eq zero = zero
cast {suc m} {suc n} eq (suc k) = suc (cast (cong ℕ.pred eq) k)
cast {zero} {suc n} ()
cast {suc m} {zero} ()
------------------------------------------------------------------------
-- Conversions
-- toℕ is defined above.
-- fromℕ n = "n".
fromℕ : (n : ℕ) → Fin (suc n)
fromℕ zero = zero
fromℕ (suc n) = suc (fromℕ n)
-- fromℕ≤ {m} _ = "m".
fromℕ≤ : ∀ {m n} → m ℕ.< n → Fin n
fromℕ≤ (s≤s z≤n) = zero
fromℕ≤ (s≤s (s≤s m≤n)) = suc (fromℕ≤ (s≤s m≤n))
-- fromℕ≤″ m _ = "m".
fromℕ≤″ : ∀ m {n} → m ℕ.<″ n → Fin n
fromℕ≤″ zero (ℕ.less-than-or-equal refl) = zero
fromℕ≤″ (suc m) (ℕ.less-than-or-equal refl) =
suc (fromℕ≤″ m (ℕ.less-than-or-equal refl))
-- # m = "m".
infix 10 #_
#_ : ∀ m {n} {m<n : True (suc m ℕ.≤? n)} → Fin n
#_ _ {m<n = m<n} = fromℕ≤ (toWitness m<n)
-- raise m "i" = "m + i".
raise : ∀ {m} n → Fin m → Fin (n ℕ.+ m)
raise zero i = i
raise (suc n) i = suc (raise n i)
-- reduce≥ "m + i" _ = "i".
reduce≥ : ∀ {m n} (i : Fin (m ℕ.+ n)) (i≥m : toℕ i ℕ.≥ m) → Fin n
reduce≥ {zero} i i≥m = i
reduce≥ {suc m} zero ()
reduce≥ {suc m} (suc i) (s≤s i≥m) = reduce≥ i i≥m
-- inject⋆ m "i" = "i".
inject : ∀ {n} {i : Fin n} → Fin′ i → Fin n
inject {i = zero} ()
inject {i = suc i} zero = zero
inject {i = suc i} (suc j) = suc (inject j)
inject! : ∀ {n} {i : Fin (suc n)} → Fin′ i → Fin n
inject! {n = zero} {i = suc ()} _
inject! {i = zero} ()
inject! {n = suc _} {i = suc _} zero = zero
inject! {n = suc _} {i = suc _} (suc j) = suc (inject! j)
inject+ : ∀ {m} n → Fin m → Fin (m ℕ.+ n)
inject+ n zero = zero
inject+ n (suc i) = suc (inject+ n i)
inject₁ : ∀ {m} → Fin m → Fin (suc m)
inject₁ zero = zero
inject₁ (suc i) = suc (inject₁ i)
inject≤ : ∀ {m n} → Fin m → m ℕ.≤ n → Fin n
inject≤ zero (s≤s le) = zero
inject≤ (suc i) (s≤s le) = suc (inject≤ i le)
-- lower₁ "i" _ = "i".
lower₁ : ∀ {n} → (i : Fin (suc n)) → (n ≢ toℕ i) → Fin n
lower₁ {zero} zero ne = ⊥-elim (ne refl)
lower₁ {zero} (suc ()) _
lower₁ {suc n} zero _ = zero
lower₁ {suc n} (suc i) ne = suc (lower₁ i λ x → ne (cong suc x))
-- A strengthening injection into the minimal Fin fibre.
strengthen : ∀ {n} (i : Fin n) → Fin′ (suc i)
strengthen zero = zero
strengthen (suc i) = suc (strengthen i)
------------------------------------------------------------------------
-- Operations
-- Folds.
fold : ∀ {t} (T : ℕ → Set t) {m} →
(∀ {n} → T n → T (suc n)) →
(∀ {n} → T (suc n)) →
Fin m → T m
fold T f x zero = x
fold T f x (suc i) = f (fold T f x i)
fold′ : ∀ {n t} (T : Fin (suc n) → Set t) →
(∀ i → T (inject₁ i) → T (suc i)) →
T zero →
∀ i → T i
fold′ T f x zero = x
fold′ {n = zero} T f x (suc ())
fold′ {n = suc n} T f x (suc i) =
f i (fold′ (T ∘ inject₁) (f ∘ inject₁) x i)
-- Lifts functions.
lift : ∀ {m n} k → (Fin m → Fin n) → Fin (k ℕ.+ m) → Fin (k ℕ.+ n)
lift zero f i = f i
lift (suc k) f zero = zero
lift (suc k) f (suc i) = suc (lift k f i)
-- "i" + "j" = "i + j".
infixl 6 _+_
_+_ : ∀ {m n} (i : Fin m) (j : Fin n) → Fin (toℕ i ℕ.+ n)
zero + j = j
suc i + j = suc (i + j)
-- "i" - "j" = "i ∸ j".
infixl 6 _-_
_-_ : ∀ {m} (i : Fin m) (j : Fin′ (suc i)) → Fin (m ℕ.∸ toℕ j)
i - zero = i
zero - suc ()
suc i - suc j = i - j
-- m ℕ- "i" = "m ∸ i".
infixl 6 _ℕ-_
_ℕ-_ : (n : ℕ) (j : Fin (suc n)) → Fin (suc n ℕ.∸ toℕ j)
n ℕ- zero = fromℕ n
zero ℕ- suc ()
suc n ℕ- suc i = n ℕ- i
-- m ℕ-ℕ "i" = m ∸ i.
infixl 6 _ℕ-ℕ_
_ℕ-ℕ_ : (n : ℕ) → Fin (suc n) → ℕ
n ℕ-ℕ zero = n
zero ℕ-ℕ suc ()
suc n ℕ-ℕ suc i = n ℕ-ℕ i
-- pred "i" = "pred i".
pred : ∀ {n} → Fin n → Fin n
pred zero = zero
pred (suc i) = inject₁ i
-- The function f(i,j) = if j>i then j-1 else j
-- This is a variant of the thick function from Conor
-- McBride's "First-order unification by structural recursion".
punchOut : ∀ {m} {i j : Fin (suc m)} → i ≢ j → Fin m
punchOut {_} {zero} {zero} i≢j = ⊥-elim (i≢j refl)
punchOut {_} {zero} {suc j} _ = j
punchOut {zero} {suc ()}
punchOut {suc m} {suc i} {zero} _ = zero
punchOut {suc m} {suc i} {suc j} i≢j = suc (punchOut (i≢j ∘ cong suc))
-- The function f(i,j) = if j≥i then j+1 else j
punchIn : ∀ {m} → Fin (suc m) → Fin m → Fin (suc m)
punchIn zero j = suc j
punchIn (suc i) zero = zero
punchIn (suc i) (suc j) = suc (punchIn i j)
------------------------------------------------------------------------
-- Order relations
infix 4 _≤_ _<_
_≤_ : ∀ {n} → Rel (Fin n) ℓ₀
_≤_ = ℕ._≤_ on toℕ
_<_ : ∀ {n} → Rel (Fin n) ℓ₀
_<_ = ℕ._<_ on toℕ
data _≺_ : ℕ → ℕ → Set where
_≻toℕ_ : ∀ n (i : Fin n) → toℕ i ≺ n
------------------------------------------------------------------------
-- An ordering view.
data Ordering {n : ℕ} : Fin n → Fin n → Set where
less : ∀ greatest (least : Fin′ greatest) →
Ordering (inject least) greatest
equal : ∀ i → Ordering i i
greater : ∀ greatest (least : Fin′ greatest) →
Ordering greatest (inject least)
compare : ∀ {n} (i j : Fin n) → Ordering i j
compare zero zero = equal zero
compare zero (suc j) = less (suc j) zero
compare (suc i) zero = greater (suc i) zero
compare (suc i) (suc j) with compare i j
compare (suc .(inject least)) (suc .greatest) | less greatest least =
less (suc greatest) (suc least)
compare (suc .greatest) (suc .(inject least)) | greater greatest least =
greater (suc greatest) (suc least)
compare (suc .i) (suc .i) | equal i =
equal (suc i)
| 27.015385
| 72
| 0.489749
|
57c03b4c341a1bb31fabe833e57f54941b744ca5
| 301
|
agda
|
Agda
|
src/JVM/Contexts.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | 6
|
2020-10-07T14:07:17.000Z
|
2021-02-28T21:49:08.000Z
|
src/JVM/Contexts.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | null | null | null |
src/JVM/Contexts.agda
|
ajrouvoet/jvm.agda
|
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
|
[
"Apache-2.0"
] | 1
|
2021-12-28T17:37:15.000Z
|
2021-12-28T17:37:15.000Z
|
{-# OPTIONS --safe #-}
module JVM.Contexts where
open import JVM.Types
open import Relation.Ternary.Construct.List.Overlapping Ty public
renaming
( overlap-rel to ctx-rel
; overlap-commutative to ctx-commutative
; overlap-semigroup to ctx-semigroup
; overlap-monoid to ctx-monoid)
| 25.083333
| 65
| 0.737542
|
228a0433738d024bd252b33f998d3b871395f288
| 10,952
|
agda
|
Agda
|
Cubical/Algebra/Group/MorphismProperties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/MorphismProperties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Group/MorphismProperties.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Group.MorphismProperties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Function using (_∘_; id)
open import Cubical.Foundations.GroupoidLaws hiding (_⁻¹)
open import Cubical.Functions.Embedding
open import Cubical.Data.Sigma
open import Cubical.Data.Prod using (isPropProd)
open import Cubical.Algebra
open import Cubical.Algebra.Properties
open import Cubical.Algebra.Group.Morphism
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Structures.Record
open import Cubical.Algebra.Monoid.Properties using (isPropIsMonoid)
open import Cubical.Relation.Binary.Reasoning.Equality
open Iso
private
variable
ℓ ℓ′ ℓ′′ : Level
F : Group ℓ
G : Group ℓ′
H : Group ℓ′′
isPropIsGroupHom : ∀ (G : Group ℓ) (H : Group ℓ′) f → isProp (IsGroupHom G H f)
isPropIsGroupHom G H f (isgrouphom aHom) (isgrouphom bHom) =
cong isgrouphom
(isPropHomomorphic₂ (Group.is-set H) f (Group._•_ G) (Group._•_ H) aHom bHom)
isSetGroupHom : isSet (G ⟶ᴴ H)
isSetGroupHom {G = G} {H = H} = isOfHLevelRespectEquiv 2 equiv
(isSetΣ (isSetΠ λ _ → is-set H)
(λ f → isProp→isSet (isPropIsGroupHom G H f)))
where
open Group
equiv : (Σ[ g ∈ (⟨ G ⟩ → ⟨ H ⟩) ] IsGroupHom G H g) ≃ GroupHom G H
equiv = isoToEquiv (iso (λ (g , m) → grouphom g m)
(λ (grouphom g m) → g , m)
(λ _ → refl) λ _ → refl)
isGroupHomComp : {f : ⟨ F ⟩ → ⟨ G ⟩} {g : ⟨ G ⟩ → ⟨ H ⟩}
→ IsGroupHom F G f → IsGroupHom G H g → IsGroupHom F H (g ∘ f)
isGroupHomComp {g = g} (isgrouphom fHom) (isgrouphom gHom) =
isgrouphom (λ _ _ → cong g (fHom _ _) ∙ gHom _ _)
private
isGroupHomComp′ : (f : F ⟶ᴴ G) (g : G ⟶ᴴ H)
→ IsGroupHom F H (GroupHom.fun g ∘ GroupHom.fun f)
isGroupHomComp′ (grouphom f (isgrouphom fHom)) (grouphom g (isgrouphom gHom)) =
isgrouphom (λ _ _ → cong g (fHom _ _) ∙ gHom _ _)
compGroupHom : (F ⟶ᴴ G) → (G ⟶ᴴ H) → (F ⟶ᴴ H)
compGroupHom f g = grouphom _ (isGroupHomComp′ f g)
compGroupEquiv : F ≃ᴴ G → G ≃ᴴ H → F ≃ᴴ H
compGroupEquiv f g = groupequiv (compEquiv f.eq g.eq) (isGroupHomComp′ f.hom g.hom)
where
module f = GroupEquiv f
module g = GroupEquiv g
isGroupHomId : (G : Group ℓ) → IsGroupHom G G id
isGroupHomId G = record
{ preservesOp = λ _ _ → refl
}
idGroupHom : (G : Group ℓ) → (G ⟶ᴴ G)
idGroupHom G = record
{ fun = id
; isHom = isGroupHomId G
}
idGroupEquiv : (G : Group ℓ) → G ≃ᴴ G
idGroupEquiv G = record
{ eq = idEquiv ⟨ G ⟩
; isHom = isGroupHomId G
}
-- Isomorphism inversion
isGroupHomInv : (eqv : G ≃ᴴ H) → IsGroupHom H G (invEq (GroupEquiv.eq eqv))
isGroupHomInv {G = G} {H = H} (groupequiv eq (isgrouphom hom)) = isgrouphom (λ x y → isInj-f (
f (f⁻¹ (x H.• y)) ≡⟨ retEq eq _ ⟩
x H.• y ≡˘⟨ cong₂ H._•_ (retEq eq x) (retEq eq y) ⟩
f (f⁻¹ x) H.• f (f⁻¹ y) ≡˘⟨ hom (f⁻¹ x) (f⁻¹ y) ⟩
f (f⁻¹ x G.• f⁻¹ y) ∎))
where
module G = Group G
module H = Group H
f = equivFun eq
f⁻¹ = invEq eq
isInj-f : {x y : ⟨ G ⟩} → f x ≡ f y → x ≡ y
isInj-f {x} {y} = invEq (_ , isEquiv→isEmbedding (eq .snd) x y)
invGroupHom : G ≃ᴴ H → (H ⟶ᴴ G)
invGroupHom eq = record { isHom = isGroupHomInv eq }
invGroupEquiv : G ≃ᴴ H → H ≃ᴴ G
invGroupEquiv eq = record
{ eq = invEquiv (GroupEquiv.eq eq)
; isHom = isGroupHomInv eq
}
groupHomEq : {f g : G ⟶ᴴ H} → (GroupHom.fun f ≡ GroupHom.fun g) → f ≡ g
groupHomEq {G = G} {H = H} {grouphom f fm} {grouphom g gm} p i =
grouphom (p i) (p-hom i)
where
p-hom : PathP (λ i → IsGroupHom G H (p i)) fm gm
p-hom = toPathP (isPropIsGroupHom G H _ _ _)
groupEquivEq : {f g : G ≃ᴴ H} → (GroupEquiv.eq f ≡ GroupEquiv.eq g) → f ≡ g
groupEquivEq {G = G} {H = H} {groupequiv f fm} {groupequiv g gm} p i =
groupequiv (p i) (p-hom i)
where
p-hom : PathP (λ i → IsGroupHom G H (p i .fst)) fm gm
p-hom = toPathP (isPropIsGroupHom G H _ _ _)
module GroupΣTheory {ℓ} where
RawGroupStructure : Type ℓ → Type ℓ
RawGroupStructure X = (X → X → X) × X × (X → X)
RawGroupEquivStr = AutoEquivStr RawGroupStructure
rawGroupUnivalentStr : UnivalentStr _ RawGroupEquivStr
rawGroupUnivalentStr = autoUnivalentStr RawGroupStructure
GroupAxioms : (G : Type ℓ) → RawGroupStructure G → Type ℓ
GroupAxioms G (_•_ , ε , _⁻¹) = IsMonoid G _•_ ε × Inverse ε _⁻¹ _•_
GroupStructure : Type ℓ → Type ℓ
GroupStructure = AxiomsStructure RawGroupStructure GroupAxioms
GroupΣ : Type (ℓ-suc ℓ)
GroupΣ = TypeWithStr ℓ GroupStructure
isPropGroupAxioms : (G : Type ℓ) (s : RawGroupStructure G) → isProp (GroupAxioms G s)
isPropGroupAxioms G (_•_ , ε , _⁻¹) = isPropΣ isPropIsMonoid
λ isMonG → isPropInverse (IsMonoid.is-set isMonG) _•_ _⁻¹ ε
GroupEquivStr : StrEquiv GroupStructure ℓ
GroupEquivStr = AxiomsEquivStr RawGroupEquivStr GroupAxioms
GroupAxiomsIsoIsGroup : {G : Type ℓ} (s : RawGroupStructure G) →
Iso (GroupAxioms G s) (IsGroup G (s .fst) (s .snd .fst) (s .snd .snd))
fun (GroupAxiomsIsoIsGroup s) (x , y) = isgroup x y
inv (GroupAxiomsIsoIsGroup s) (isgroup x y) = (x , y)
rightInv (GroupAxiomsIsoIsGroup s) _ = refl
leftInv (GroupAxiomsIsoIsGroup s) _ = refl
GroupAxioms≡IsGroup : {G : Type ℓ} (s : RawGroupStructure G) →
GroupAxioms G s ≡ IsGroup G (s .fst) (s .snd .fst) (s .snd .snd)
GroupAxioms≡IsGroup s = isoToPath (GroupAxiomsIsoIsGroup s)
Group→GroupΣ : Group ℓ → GroupΣ
Group→GroupΣ (mkgroup G _•_ ε _⁻¹ isGroup) =
G , (_•_ , ε , _⁻¹) , GroupAxiomsIsoIsGroup (_•_ , ε , _⁻¹) .inv isGroup
GroupΣ→Group : GroupΣ → Group ℓ
GroupΣ→Group (G , (_•_ , ε , _⁻¹) , isGroupG) =
mkgroup G _•_ ε _⁻¹ (GroupAxiomsIsoIsGroup (_•_ , ε , _⁻¹) .fun isGroupG)
GroupIsoGroupΣ : Iso (Group ℓ) GroupΣ
GroupIsoGroupΣ =
iso Group→GroupΣ GroupΣ→Group (λ _ → refl) (λ _ → refl)
groupUnivalentStr : UnivalentStr GroupStructure GroupEquivStr
groupUnivalentStr = axiomsUnivalentStr _ isPropGroupAxioms rawGroupUnivalentStr
GroupΣPath : (G H : GroupΣ) → (G ≃[ GroupEquivStr ] H) ≃ (G ≡ H)
GroupΣPath = SIP groupUnivalentStr
GroupEquivΣ : (G H : Group ℓ) → Type ℓ
GroupEquivΣ G H = Group→GroupΣ G ≃[ GroupEquivStr ] Group→GroupΣ H
GroupIsoΣPath : {G H : Group ℓ} → Iso (GroupEquiv G H) (GroupEquivΣ G H)
fun GroupIsoΣPath (groupequiv eq hom) = eq , IsGroupHom.preservesOp hom , IsGroupHom.preservesId hom , IsGroupHom.preservesInv hom
inv GroupIsoΣPath (eq , hom , _) = groupequiv eq (isgrouphom hom)
rightInv (GroupIsoΣPath {H = H}) _ = ΣPathTransport→PathΣ _ _ (refl ,
ΣPathTransport→PathΣ _ _ (transportRefl _ ,
ΣPathTransport→PathΣ _ _
(Group.is-set H _ _ _ _ ,
isPropΠ (λ _ → Group.is-set H _ _) _ _ )
))
leftInv (GroupIsoΣPath {H = H}) _ = refl
GroupPath : (G H : Group ℓ) → (GroupEquiv G H) ≃ (G ≡ H)
GroupPath G H =
GroupEquiv G H ≃⟨ isoToEquiv GroupIsoΣPath ⟩
GroupEquivΣ G H ≃⟨ GroupΣPath _ _ ⟩
Group→GroupΣ G ≡ Group→GroupΣ H ≃⟨ isoToEquiv (invIso (congIso GroupIsoGroupΣ)) ⟩
G ≡ H ■
RawGroupΣ : Type (ℓ-suc ℓ)
RawGroupΣ = TypeWithStr ℓ RawGroupStructure
Group→RawGroupΣ : Group ℓ → RawGroupΣ
Group→RawGroupΣ (mkgroup A _•_ ε _⁻¹ _) = A , _•_ , ε , _⁻¹
InducedGroup : (G : Group ℓ) (H : RawGroupΣ) (e : G .Group.Carrier ≃ H .fst)
→ RawGroupEquivStr (Group→RawGroupΣ G) H e → Group ℓ
InducedGroup G H e r =
GroupΣ→Group (inducedStructure rawGroupUnivalentStr (Group→GroupΣ G) H (e , r))
InducedGroupPath : (G : Group ℓ) (H : RawGroupΣ) (e : G .Group.Carrier ≃ H .fst)
(E : RawGroupEquivStr (Group→RawGroupΣ G) H e) →
G ≡ InducedGroup G H e E
InducedGroupPath G H e E =
GroupPath G (InducedGroup G H e E) .fst (groupequiv e (isgrouphom (E .fst)))
-- We now extract the important results from the above module
open GroupΣTheory public using (InducedGroup; InducedGroupPath)
isPropIsGroup : {G : Type ℓ} {_•_ : Op₂ G} {ε : G} {_⁻¹ : Op₁ G} → isProp (IsGroup G _•_ ε _⁻¹)
isPropIsGroup =
subst isProp (GroupΣTheory.GroupAxioms≡IsGroup (_ , _ , _))
(GroupΣTheory.isPropGroupAxioms _ (_ , _ , _))
GroupPath : (G ≃ᴴ H) ≃ (G ≡ H)
GroupPath = GroupΣTheory.GroupPath _ _
open Group
uaGroup : G ≃ᴴ H → G ≡ H
uaGroup = equivFun GroupPath
carac-uaGroup : {G H : Group ℓ} (f : G ≃ᴴ H) → cong Carrier (uaGroup f) ≡ ua (GroupEquiv.eq f)
carac-uaGroup (groupequiv f m) =
(refl ∙∙ ua f ∙∙ refl) ≡˘⟨ rUnit (ua f) ⟩
ua f ∎
Group≡ : (G H : Group ℓ) → (
Σ[ p ∈ ⟨ G ⟩ ≡ ⟨ H ⟩ ]
Σ[ q ∈ PathP (λ i → p i → p i → p i) (_•_ G) (_•_ H) ]
Σ[ r ∈ PathP (λ i → p i) (ε G) (ε H) ]
Σ[ s ∈ PathP (λ i → p i → p i) (_⁻¹ G) (_⁻¹ H) ]
PathP (λ i → IsGroup (p i) (q i) (r i) (s i)) (isGroup G) (isGroup H))
≃ (G ≡ H)
Group≡ G H = isoToEquiv (iso
(λ (p , q , r , s , t) i → mkgroup (p i) (q i) (r i) (s i) (t i))
(λ p → cong Carrier p , cong _•_ p , cong ε p , cong _⁻¹ p , cong isGroup p)
(λ _ → refl) (λ _ → refl))
caracGroup≡ : {G H : Group ℓ} (p q : G ≡ H) → cong Carrier p ≡ cong Carrier q → p ≡ q
caracGroup≡ {G = G} {H} p q t = cong (fst (Group≡ G H)) (Σ≡Prop (λ _ → isPropΣ
(isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set H) _ _) λ _ → isPropΣ
(isOfHLevelPathP' 1 (is-set H) _ _) λ _ → isPropΣ
(isOfHLevelPathP' 1 (isSetΠ λ _ → is-set H) _ _) λ _ →
isOfHLevelPathP 1 isPropIsGroup _ _)
t)
uaGroupId : (G : Group ℓ) → uaGroup (idGroupEquiv G) ≡ refl
uaGroupId G = caracGroup≡ _ _ (carac-uaGroup (idGroupEquiv G) ∙ uaIdEquiv)
uaCompGroupEquiv : {F G H : Group ℓ} (f : GroupEquiv F G) (g : GroupEquiv G H) → uaGroup (compGroupEquiv f g) ≡ uaGroup f ∙ uaGroup g
uaCompGroupEquiv f g = caracGroup≡ _ _ (
cong Carrier (uaGroup (compGroupEquiv f g))
≡⟨ carac-uaGroup (compGroupEquiv f g) ⟩
ua (eq (compGroupEquiv f g))
≡⟨ uaCompEquiv _ _ ⟩
ua (eq f) ∙ ua (eq g)
≡˘⟨ cong (_∙ ua (eq g)) (carac-uaGroup f) ⟩
cong Carrier (uaGroup f) ∙ ua (eq g)
≡˘⟨ cong (cong Carrier (uaGroup f) ∙_) (carac-uaGroup g) ⟩
cong Carrier (uaGroup f) ∙ cong Carrier (uaGroup g)
≡˘⟨ cong-∙ Carrier (uaGroup f) (uaGroup g) ⟩
cong Carrier (uaGroup f ∙ uaGroup g) ∎)
where open GroupEquiv
| 38.975089
| 133
| 0.61103
|
22af90c78e6f4d538cff1d0be86b142e6ef1f229
| 1,773
|
agda
|
Agda
|
agda-stdlib/src/Data/These/Categorical/Left/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/These/Categorical/Left/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/These/Categorical/Left/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Base definitions for the left-biased universe-sensitive functor and
-- monad instances for These.
--
-- To minimize the universe level of the RawFunctor, we require that
-- elements of B are "lifted" to a copy of B at a higher universe level
-- (a ⊔ b).
-- See the Data.Product.Categorical.Examples for how this is done in a
-- Product-based similar setting.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Level
module Data.These.Categorical.Left.Base {a} (A : Set a) (b : Level) where
open import Data.These.Base
open import Category.Functor
open import Category.Applicative
open import Category.Monad
open import Function
Theseₗ : Set (a ⊔ b) → Set (a ⊔ b)
Theseₗ B = These A B
functor : RawFunctor Theseₗ
functor = record { _<$>_ = map₂ }
------------------------------------------------------------------------
-- Get access to other monadic functions
module _ {F} (App : RawApplicative {a ⊔ b} F) where
open RawApplicative App
sequenceA : ∀ {A} → Theseₗ (F A) → F (Theseₗ A)
sequenceA (this a) = pure (this a)
sequenceA (that b) = that <$> b
sequenceA (these a b) = these a <$> b
mapA : ∀ {A B} → (A → F B) → Theseₗ A → F (Theseₗ B)
mapA f = sequenceA ∘ map₂ f
forA : ∀ {A B} → Theseₗ A → (A → F B) → F (Theseₗ B)
forA = flip mapA
module _ {M} (Mon : RawMonad {a ⊔ b} M) where
private App = RawMonad.rawIApplicative Mon
sequenceM : ∀ {A} → Theseₗ (M A) → M (Theseₗ A)
sequenceM = sequenceA App
mapM : ∀ {A B} → (A → M B) → Theseₗ A → M (Theseₗ B)
mapM = mapA App
forM : ∀ {A B} → Theseₗ A → (A → M B) → M (Theseₗ B)
forM = forA App
| 28.596774
| 73
| 0.565144
|
1232465cf595a8728f2160ca1771d37a220db638
| 1,496
|
agda
|
Agda
|
test/Common/Reflection.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 4
|
2017-02-24T16:53:22.000Z
|
2019-12-23T04:56:23.000Z
|
test/Common/Reflection.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 6
|
2017-02-24T19:27:31.000Z
|
2017-02-24T19:38:17.000Z
|
test/Common/Reflection.agda
|
Blaisorblade/Agda
|
802a28aa8374f15fe9d011ceb80317fdb1ec0949
|
[
"BSD-3-Clause"
] | 1
|
2022-03-12T11:39:14.000Z
|
2022-03-12T11:39:14.000Z
|
module Common.Reflection where
open import Agda.Builtin.Reflection public renaming
( arg-info to argInfo
; function to funDef
; data-type to dataDef
; record-type to recordDef
; agda-sort to sort
; name to qname
; absurd-clause to absurdClause
; pat-lam to extLam
; proj to projP
; instance′ to inst
; Visibility to Hiding
; Name to QName)
open import Common.Level
open import Common.Prelude hiding (_>>=_)
pattern vArg x = arg (argInfo visible relevant) x
pattern hArg x = arg (argInfo hidden relevant) x
pattern iArg x = arg (argInfo inst relevant) x
Args = List (Arg Term)
data FunDef : Set where
funDef : Type → List Clause → FunDef
Tactic = Term → TC ⊤
give : Term → Tactic
give v = λ hole → unify hole v
define : Arg QName → FunDef → TC ⊤
define (arg i f) (funDef a cs) =
bindTC (declareDef (arg i f) a) λ _ →
defineFun f cs
newMeta : Type → TC Term
newMeta a = checkType unknown a
numberOfParameters : QName → TC Nat
numberOfParameters d =
bindTC (getDefinition d) λ
{ (dataDef n _) → returnTC n
; _ → typeError (strErr "Cannot get parameters of non-data type" ∷ nameErr d ∷ [])
}
getConstructors : QName → TC (List QName)
getConstructors d =
bindTC (getDefinition d) λ
{ (dataDef _ cs) → returnTC cs
; (recordDef c) → returnTC (c ∷ [])
; _ → typeError (strErr "Cannot get constructors of non-data or record type" ∷ nameErr d ∷ [])
}
infixl 1 _>>=_
_>>=_ = bindTC
| 25.355932
| 96
| 0.65508
|
1d50c2424b2279a5c2a8d38884acec98b76752cb
| 1,947
|
agda
|
Agda
|
Cubical/Data/DiffInt/Properties.agda
|
ryanorendorff/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/Data/DiffInt/Properties.agda
|
ryanorendorff/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | null | null | null |
Cubical/Data/DiffInt/Properties.agda
|
ryanorendorff/cubical
|
c67854d2e11aafa5677e25a09087e176fafd3e43
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.DiffInt.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Data.DiffInt.Base
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Data.Bool
open import Cubical.Relation.Binary.Base
open import Cubical.Relation.Nullary
open import Cubical.HITs.SetQuotients
open BinaryRelation
relIsEquiv : isEquivRel rel
relIsEquiv = EquivRel {A = ℕ × ℕ} relIsRefl relIsSym relIsTrans
where
relIsRefl : isRefl rel
relIsRefl (a0 , a1) = refl
relIsSym : isSym rel
relIsSym (a0 , a1) (b0 , b1) p = sym p
relIsTrans : isTrans rel
relIsTrans (a0 , a1) (b0 , b1) (c0 , c1) p0 p1 =
inj-m+ {m = (b0 + b1)} ((b0 + b1) + (a0 + c1) ≡⟨ +-assoc (b0 + b1) a0 c1 ⟩
((b0 + b1) + a0) + c1 ≡[ i ]⟨ +-comm b0 b1 i + a0 + c1 ⟩
((b1 + b0) + a0) + c1 ≡[ i ]⟨ +-comm (b1 + b0) a0 i + c1 ⟩
(a0 + (b1 + b0)) + c1 ≡[ i ]⟨ +-assoc a0 b1 b0 i + c1 ⟩
(a0 + b1) + b0 + c1 ≡⟨ sym (+-assoc (a0 + b1) b0 c1) ⟩
(a0 + b1) + (b0 + c1) ≡⟨ cong (λ p → p . fst + p .snd) (transport Σ≡ (p0 , p1))⟩
(b0 + a1) + (c0 + b1) ≡⟨ sym (+-assoc b0 a1 (c0 + b1))⟩
b0 + (a1 + (c0 + b1)) ≡[ i ]⟨ b0 + (a1 + +-comm c0 b1 i) ⟩
b0 + (a1 + (b1 + c0)) ≡[ i ]⟨ b0 + +-comm a1 (b1 + c0) i ⟩
b0 + ((b1 + c0) + a1) ≡[ i ]⟨ b0 + +-assoc b1 c0 a1 (~ i) ⟩
b0 + (b1 + (c0 + a1)) ≡⟨ +-assoc b0 b1 (c0 + a1)⟩
(b0 + b1) + (c0 + a1) ∎ )
relIsProp : BinaryRelation.isPropValued rel
relIsProp a b x y = isSetℕ _ _ _ _
discreteℤ : Discrete ℤ
discreteℤ = discreteSetQuotients (discreteΣ discreteℕ λ _ → discreteℕ) relIsProp relIsEquiv (λ _ _ → discreteℕ _ _)
private
_ : Dec→Bool (discreteℤ [ (3 , 5) ] [ (4 , 6) ]) ≡ true
_ = refl
_ : Dec→Bool (discreteℤ [ (3 , 5) ] [ (4 , 7) ]) ≡ false
_ = refl
| 35.4
| 115
| 0.546482
|
4161353f8f6296cdc723e6706eeda3cddbcfd5b2
| 3,437
|
agda
|
Agda
|
Basic/Compiler/SplitCode.agda
|
AndrasKovacs/SemanticsWithApplications
|
05200d60b4a4b2c6fa37806ced9247055d24db94
|
[
"MIT"
] | 8
|
2016-09-12T04:25:39.000Z
|
2020-02-02T10:01:52.000Z
|
Basic/Compiler/SplitCode.agda
|
AndrasKovacs/SemanticsWithApplications
|
05200d60b4a4b2c6fa37806ced9247055d24db94
|
[
"MIT"
] | null | null | null |
Basic/Compiler/SplitCode.agda
|
AndrasKovacs/SemanticsWithApplications
|
05200d60b4a4b2c6fa37806ced9247055d24db94
|
[
"MIT"
] | null | null | null |
module Basic.Compiler.SplitCode where
open import Basic.Compiler.Code
open import Basic.AST
open import Basic.BigStep
open import Utils.Monoid
open import Data.Vec hiding (_++_; [_]; _∷ʳ_)
open import Data.Bool renaming (if_then_else_ to ifBool_then_else_)
open import Data.Nat
open import Data.List hiding ([_])
open import Relation.Binary.PropositionalEquality
open import Function
open import Data.Product
open import Algebra
import Level as L
private
module LM {a}{A : Set a} = Algebra.Monoid (Data.List.monoid A)
{-
Exercise 3.5
This code logically belongs to either Compiler.Code or Compiler.CorrectFrom.
It has its own module solely because it slows down typechecking for the module
it's in, which is rather annoying.
-}
▷*-split :
∀ {n}{s s' : State n}{e e'} c₁ {c₂}
→ (p : ⟨ c₁ <> c₂ , e , s ⟩▷*⟨ [] , e' , s' ⟩)
→ ∃₂ λ s'' e''
→ ∃₂ λ (p1 : ⟨ c₁ , e , s ⟩▷*⟨ [] , e'' , s'' ⟩)
(p2 : ⟨ c₂ , e'' , s'' ⟩▷*⟨ [] , e' , s' ⟩)
→ ▷*-length p1 + ▷*-length p2 ≡ ▷*-length p
▷*-split [] p = _ , _ , done , p , refl
▷*-split (.ADD ∷ cs) (ADD a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , ADD a b ∷ p1 , p2 , cong suc eqn
▷*-split (.MUL ∷ cs) (MUL a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , MUL a b ∷ p1 , p2 , cong suc eqn
▷*-split (.SUB ∷ cs) (SUB a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , SUB a b ∷ p1 , p2 , cong suc eqn
▷*-split (.EQ ∷ cs) (EQ a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , EQ a b ∷ p1 , p2 , cong suc eqn
▷*-split (.LT ∷ cs) (LT a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , LT a b ∷ p1 , p2 , cong suc eqn
▷*-split (.LTE ∷ cs) (LTE a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , LTE a b ∷ p1 , p2 , cong suc eqn
▷*-split (.AND ∷ cs) (AND a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , AND a b ∷ p1 , p2 , cong suc eqn
▷*-split (.(PUSH n₁) ∷ cs) (PUSH n₁ ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , PUSH n₁ ∷ p1 , p2 , cong suc eqn
▷*-split (.TRUE ∷ cs) (TRUE ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , TRUE ∷ p1 , p2 , cong suc eqn
▷*-split (.FALSE ∷ cs) (FALSE ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , FALSE ∷ p1 , p2 , cong suc eqn
▷*-split (.NOT ∷ cs) (NOT b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , NOT b ∷ p1 , p2 , cong suc eqn
▷*-split (.(FETCH x) ∷ cs) (FETCH x ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , FETCH x ∷ p1 , p2 , cong suc eqn
▷*-split (.(STORE x) ∷ cs) (STORE x ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , STORE x ∷ p1 , p2 , cong suc eqn
▷*-split (.NOOP ∷ cs) (NOOP ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , NOOP ∷ p1 , p2 , cong suc eqn
▷*-split (._ ∷ cs){c₂} (BRANCH{ca}{cb}{._}{t}{e} ∷ p)
rewrite sym $ LM.assoc (ifBool t then ca else cb) cs c₂
with ▷*-split ((ifBool t then ca else cb) <> cs) p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , BRANCH ∷ p1 , p2 , cong suc eqn
▷*-split (._ ∷ cs){c₁} (LOOP{ca}{cb}{._}{e}{s} ∷ p)
rewrite sym $ LM.assoc ca (BRANCH (cb ∷ʳ LOOP ca cb) (NOOP ∷ []) ∷ cs) c₁
with ▷*-split (ca <> (BRANCH (cb ∷ʳ LOOP ca cb) (NOOP ∷ []) ∷ cs)) p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , LOOP ∷ p1 , p2 , cong suc eqn
| 45.826667
| 78
| 0.508001
|
3d5a5c58b3a112b2ea2697f07e8d3237460d5d5a
| 1,915
|
agda
|
Agda
|
old/Sets/ETCS.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
old/Sets/ETCS.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
old/Sets/ETCS.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
import Lvl
-- TODO: Is it possible formalize this like this? Is it even correct?
-- Based on http://www.maths.ed.ac.uk/~tl/edinburgh_yrm/ (2017-11-22)
module Sets.ETCS where
open import Logic.Propositional
module Theory (S : Set(Lvl.𝟎)) (F : S → S → Set(Lvl.𝟎)) (_∘_ : ∀{a b c} → F(b)(c) → F(a)(b) → F(a)(c)) (_≡_ : ∀{a b} → F(a)(b) → F(a)(b) → Stmt{Lvl.𝟎}) where
open import Functional hiding (_∘_)
open import Logic.Predicate{Lvl.𝟎}{Lvl.𝟎}
open import Logic.Propositional.Theorems{Lvl.𝟎}
open import Relator.Equals{Lvl.𝟎} using () renaming (_≡_ to _≡ᵣ_)
open import Type{Lvl.𝟎}
Terminal : S → Stmt
Terminal(x) = (∀{a : S} → (f g : F(a)(x)) → (f ≡ g))
record Axioms : Set(Lvl.𝐒(Lvl.𝟎)) where
field
associativity : ∀{a b c d : S}{f : F(a)(b)}{g : F(b)(c)}{h : F(c)(d)} → ((h ∘ (g ∘ f)) ≡ ((h ∘ g) ∘ f))
identity : ∀{a : S} → ∃{F(a)(a)}(id ↦ (∀{b : S}{f : F(a)(b)} → ((f ∘ id) ≡ f)) ∧ (∀{b : S}{f : F(b)(a)} → ((id ∘ f) ≡ f)))
terminal : ∃(term ↦ Terminal(term))
𝟏 : S
𝟏 = [∃]-witness(terminal)
_∈_ : ∀{a b : S} → F(a)(b) → S → Stmt
_∈_ {a}{b} x X = (a ≡ᵣ 𝟏)∧(b ≡ᵣ X)
_∉_ : ∀{a b : S} → F(a)(b) → S → Stmt
_∉_ x X = ¬(x ∈ X)
field
empty : ∃{S}(∅ ↦ ∀{a b : S}{f : F(a)(b)} → (f ∉ ∅))
-- TODO
module Construction where
open import Data
open import Functional using (_∘_ ; id)
open import Logic.Predicate{Lvl.𝐒(Lvl.𝟎)}{Lvl.𝟎}
open import Logic.Propositional.Theorems{Lvl.𝐒(Lvl.𝟎)}
open import Relator.Equals{Lvl.𝟎}
Terminal : Set → Stmt
Terminal(x) = (∀{a : Set}{f g : a → x} → (f ≡ g))
_∈_ : ∀{a b : Set} → (a → b) → Set → Stmt
_∈_ {a}{b} _ X = (a ≡ Unit)∧(b ≡ X)
∅ : Set
∅ = Empty
-- TODO: Maybe use FunctionEquals instead?
-- TODO: Is this construction working? Try to prove some of the theorems of standard set theory
| 33.017241
| 159
| 0.513838
|
1c5c3ea1b8d36ac97f119198abbca86d4ea0003d
| 7,992
|
agda
|
Agda
|
core/lib/PathGroupoid.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/PathGroupoid.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/PathGroupoid.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Base
module lib.PathGroupoid where
module _ {i} {A : Type i} where
{- Concatenation of paths
There are two different definitions of concatenation of paths, [_∙_] and [_∙'_],
with different definitionnal behaviour. Maybe we should have only one but it’s
sometimes useful to have both (in particular in lib.types.Paths).
-}
infixr 80 _∙_ _∙'_
_∙_ : {x y z : A}
→ (x == y → y == z → x == z)
idp ∙ q = q
_∙'_ : {x y z : A}
→ (x == y → y == z → x == z)
q ∙' idp = q
∙=∙' : {x y z : A} (p : x == y) (q : y == z)
→ p ∙ q == p ∙' q
∙=∙' idp idp = idp
∙'=∙ : {x y z : A} (p : x == y) (q : y == z)
→ p ∙' q == p ∙ q
∙'=∙ idp idp = idp
∙-assoc : {x y z t : A} (p : x == y) (q : y == z) (r : z == t)
→ (p ∙ q) ∙ r == p ∙ (q ∙ r)
∙-assoc idp _ _ = idp
∙'-assoc : {x y z t : A} (p : x == y) (q : y == z) (r : z == t)
→ (p ∙' q) ∙' r == p ∙' (q ∙' r)
∙'-assoc _ _ idp = idp
-- [∙-unit-l] and [∙'-unit-r] are definitional
∙-unit-r : {x y : A} (q : x == y) → q ∙ idp == q
∙-unit-r idp = idp
∙'-unit-l : {x y : A} (q : x == y) → idp ∙' q == q
∙'-unit-l idp = idp
{- Reversal of paths -}
! : {x y : A} → (x == y → y == x)
! idp = idp
!-inv-l : {x y : A} (p : x == y) → (! p) ∙ p == idp
!-inv-l idp = idp
!-inv'-l : {x y : A} (p : x == y) → (! p) ∙' p == idp
!-inv'-l idp = idp
!-inv-r : {x y : A} (p : x == y) → p ∙ (! p) == idp
!-inv-r idp = idp
!-inv'-r : {x y : A} (p : x == y) → p ∙' (! p) == idp
!-inv'-r idp = idp
{- Interactions between operations
A lemma of the form [!-∙ …] gives a result of the form [! (_∙_ …) == …],
and so on.
-}
!-∙ : {x y z : A} (p : x == y) (q : y == z) → ! (p ∙ q) == ! q ∙ ! p
!-∙ idp idp = idp
∙-! : {x y z : A} (q : y == z) (p : x == y) → ! q ∙ ! p == ! (p ∙ q)
∙-! idp idp = idp
!-∙' : {x y z : A} (p : x == y) (q : y == z) → ! (p ∙' q) == ! q ∙' ! p
!-∙' idp idp = idp
∙'-! : {x y z : A} (q : y == z) (p : x == y) → ! q ∙' ! p == ! (p ∙' q)
∙'-! idp idp = idp
!-! : {x y : A} (p : x == y) → ! (! p) == p
!-! idp = idp
{- Horizontal compositions -}
infixr 80 _∙2_ _∙'2_
_∙2_ : {x y z : A} {p p' : x == y} {q q' : y == z} (α : p == p') (β : q == q')
→ p ∙ q == p' ∙ q'
_∙2_ {p = idp} idp β = β
_∙'2_ : {x y z : A} {p p' : x == y} {q q' : y == z} (α : p == p') (β : q == q')
→ p ∙' q == p' ∙' q'
_∙'2_ {q = idp} α idp = α
idp∙2idp : {x y z : A} (p : x == y) (q : y == z)
→ (idp {a = p}) ∙2 (idp {a = q}) == idp
idp∙2idp idp idp = idp
idp∙'2idp : {x y z : A} (p : x == y) (q : y == z)
→ (idp {a = p}) ∙'2 (idp {a = q}) == idp
idp∙'2idp idp idp = idp
{-
Sometimes we need to restart a new section in order to have everything in the
previous one generalized.
-}
module _ {i} {A : Type i} where
{- Whisker and horizontal composition for Eckmann-Hilton argument -}
infixr 80 _∙ᵣ_ _⋆2_ _⋆'2_
infixl 80 _∙ₗ_
_∙ᵣ_ : {x y z : A} {p p' : x == y} (α : p == p') (q : y == z)
→ p ∙ q == p' ∙ q
_∙ᵣ_ {p = p} {p' = p'} α idp = ∙-unit-r p ∙ α ∙ ! (∙-unit-r p')
_∙ₗ_ : {x y z : A} {q q' : y == z} (p : x == y) (β : q == q')
→ p ∙ q == p ∙ q'
_∙ₗ_ {q = q} {q' = q'} idp β = β
_⋆2_ : {x y z : A} {p p' : x == y} {q q' : y == z}
(α : p == p') (β : q == q')
→ p ∙ q == p' ∙ q'
_⋆2_ {p' = p'} {q = q} α β = (α ∙ᵣ q) ∙ (p' ∙ₗ β)
_⋆'2_ : {x y z : A} {p p' : x == y} {q q' : y == z}
(α : p == p') (β : q == q')
→ p ∙ q == p' ∙ q'
_⋆'2_ {p = p} {q' = q'} α β = (p ∙ₗ β) ∙ (α ∙ᵣ q')
⋆2=⋆'2 : {x y z : A} {p p' : x == y} {q q' : y == z}
(α : p == p') (β : q == q')
→ α ⋆2 β == α ⋆'2 β
⋆2=⋆'2 {p = idp} {q = idp} idp idp = idp
module _ {i} {A : Type i} where
anti-whisker-right : {x y z : A} (p : y == z) {q r : x == y}
→ (q ∙ p == r ∙ p → q == r)
anti-whisker-right idp {q} {r} h =
! (∙-unit-r q) ∙ (h ∙ ∙-unit-r r)
anti-whisker-left : {x y z : A} (p : x == y) {q r : y == z}
→ (p ∙ q == p ∙ r → q == r)
anti-whisker-left idp h = h
{- Dependent stuff -}
module _ {i j} {A : Type i} {B : A → Type j} where
{- Dependent constant path -}
idpᵈ : {x : A} {u : B x} → u == u [ B ↓ idp ]
idpᵈ = idp
{- Dependent opposite path -}
!ᵈ : {x y : A} {p : x == y} {u : B x} {v : B y}
→ (u == v [ B ↓ p ] → v == u [ B ↓ (! p)])
!ᵈ {p = idp} = !
{- Dependent concatenation -}
infixr 80 _∙ᵈ_ _∙'ᵈ_ _◃_ _▹_ _!◃_ _▹!_
_∙ᵈ_ : {x y z : A} {p : x == y} {p' : y == z}
{u : B x} {v : B y} {w : B z}
→ (u == v [ B ↓ p ]
→ v == w [ B ↓ p' ]
→ u == w [ B ↓ (p ∙ p') ])
_∙ᵈ_ {p = idp} {p' = idp} q r = q ∙ r
_◃_ = _∙ᵈ_
◃idp : {x : A} {v w : B x} (q : w == v)
→ q ◃ idp == q
◃idp idp = idp
idp◃ : {x y : A} {p : x == y}
{u : B x} {v : B y} (r : u == v [ B ↓ p ])
→ idp ◃ r == r
idp◃ {p = idp} r = idp
_∙'ᵈ_ : {x y z : A} {p : x == y} {p' : y == z}
{u : B x} {v : B y} {w : B z}
→ (u == v [ B ↓ p ]
→ v == w [ B ↓ p' ]
→ u == w [ B ↓ (p ∙' p') ])
_∙'ᵈ_ {p = idp} {p' = idp} q r = q ∙' r
_▹_ = _∙'ᵈ_
{- That’s not perfect, because [q] could be a dependent path. But in that case
this is not well typed… -}
idp▹ : {x : A} {v w : B x} (q : v == w)
→ idp ▹ q == q
idp▹ idp = idp
▹idp : {x y : A} {p : x == y}
{u : B x} {v : B y} (q : u == v [ B ↓ p ])
→ q ▹ idp == q
▹idp {p = idp} idp = idp
_▹!_ : {x y z : A} {p : x == y} {p' : z == y}
{u : B x} {v : B y} {w : B z}
→ u == v [ B ↓ p ]
→ w == v [ B ↓ p' ]
→ u == w [ B ↓ p ∙' (! p') ]
_▹!_ {p' = idp} q idp = q
idp▹! : {x : A} {v w : B x} (q : w == v)
→ idp ▹! q == ! q
idp▹! idp = idp
_!◃_ : {x y z : A} {p : y == x} {p' : y == z}
{u : B x} {v : B y} {w : B z}
→ v == u [ B ↓ p ]
→ v == w [ B ↓ p' ]
→ u == w [ B ↓ (! p) ∙ p' ]
_!◃_ {p = idp} idp q = q
!◃idp :{x : A} {v w : B x} (q : v == w)
→ q !◃ idp == ! q
!◃idp idp = idp
{-
This is some kind of dependent horizontal composition (used in [apd∙]).
-}
infixr 80 _∙2ᵈ_ _∙'2ᵈ_
_∙2ᵈ_ : {x y z : Π A B}
{a a' : A} {p : a == a'} {q : x a == y a} {q' : x a' == y a'}
{r : y a == z a} {r' : y a' == z a'}
→ (q == q' [ (λ a → x a == y a) ↓ p ])
→ (r == r' [ (λ a → y a == z a) ↓ p ])
→ (q ∙ r == q' ∙ r' [ (λ a → x a == z a) ↓ p ])
_∙2ᵈ_ {p = idp} α β = α ∙2 β
_∙'2ᵈ_ : {x y z : Π A B}
{a a' : A} {p : a == a'} {q : x a == y a} {q' : x a' == y a'}
{r : y a == z a} {r' : y a' == z a'}
→ (q == q' [ (λ a → x a == y a) ↓ p ])
→ (r == r' [ (λ a → y a == z a) ↓ p ])
→ (q ∙' r == q' ∙' r' [ (λ a → x a == z a) ↓ p ])
_∙'2ᵈ_ {p = idp} α β = α ∙'2 β
{-
[apd∙] reduces a term of the form [apd (λ a → q a ∙ r a) p], do not confuse it
with [apd-∙] which reduces a term of the form [apd f (p ∙ q)].
-}
apd∙ : {a a' : A} {x y z : Π A B}
(q : (a : A) → x a == y a) (r : (a : A) → y a == z a)
(p : a == a')
→ apd (λ a → q a ∙ r a) p == apd q p ∙2ᵈ apd r p
apd∙ q r idp = ! (idp∙2idp (q _) (r _))
apd∙' : {a a' : A} {x y z : Π A B}
(q : (a : A) → x a == y a) (r : (a : A) → y a == z a)
(p : a == a')
→ apd (λ a → q a ∙' r a) p == apd q p ∙'2ᵈ apd r p
apd∙' q r idp = ! (idp∙'2idp (q _) (r _))
module _ {i j} {A : Type i} {B : A → Type j} where
{- Exchange -}
▹-∙'2ᵈ : {x y z : Π A B}
{a a' a'' : A} {p : a == a'} {p' : a' == a''}
{q0 : x a == y a} {q0' : x a' == y a'}
{r0 : y a == z a} {r0' : y a' == z a'}
{q0'' : x a'' == y a''} {r0'' : y a'' == z a''}
(q : q0 == q0' [ (λ a → x a == y a) ↓ p ])
(r : r0 == r0' [ (λ a → y a == z a) ↓ p ])
(s : q0' == q0'' [ (λ a → x a == y a) ↓ p' ])
(t : r0' == r0'' [ (λ a → y a == z a) ↓ p' ])
→ (q ∙'2ᵈ r) ▹ (s ∙'2ᵈ t) == (q ▹ s) ∙'2ᵈ (r ▹ t)
▹-∙'2ᵈ {p = idp} {p' = idp} {q0} {.q0} {r0} {.r0} idp idp idp idp =
ap (λ u → (idp {a = q0} ∙'2 idp {a = r0}) ∙' u) (idp∙'2idp q0 r0)
| 27.75
| 82
| 0.358609
|
12612c688fac75e20b207f89758fe4af202d918f
| 2,572
|
agda
|
Agda
|
nicolai/anonymousExistence/library/Univalence.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
nicolai/anonymousExistence/library/Univalence.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | null | null | null |
nicolai/anonymousExistence/library/Univalence.agda
|
nicolaikraus/HoTT-Agda
|
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import library.Base
open import library.PathGroupoid
open import library.PathFunctor
open import library.Equivalences
module library.Univalence where
{-
The map [coe-equiv] is the map which is supposed to be an equivalence according
to the univalence axiom. We do not define it directly by path induction because
it may be helpful to know definitionally what are the components.
-}
coe-equiv : ∀ {i} {A B : Type i} → A == B → A ≃ B
coe-equiv p = equiv (coe p) (coe! p) (coe!-inv-r p) (coe!-inv-l p)
{- We postulate the univalence axiom as three separate axioms because it’s more
natural this way. But it doesn’t change anything in practice. -}
postulate -- Univalence axiom
ua : ∀ {i} {A B : Type i} → (A ≃ B) → A == B
coe-equiv-β : ∀ {i} {A B : Type i} (e : A ≃ B) → coe-equiv (ua e) == e
ua-η : ∀ {i} {A B : Type i} (p : A == B) → ua (coe-equiv p) == p
ua-equiv : ∀ {i} {A B : Type i} → (A ≃ B) ≃ (A == B)
ua-equiv = equiv ua coe-equiv ua-η coe-equiv-β
{- Reductions for coercions along a path constructed with the univalence axiom -}
coe-β : ∀ {i} {A B : Type i} (e : A ≃ B) (a : A)
→ coe (ua e) a == –> e a
coe-β e a = ap (λ e → –> e a) (coe-equiv-β e)
coe!-β : ∀ {i} {A B : Type i} (e : A ≃ B) (b : B)
→ coe! (ua e) b == <– e b
coe!-β e a = ap (λ e → <– e a) (coe-equiv-β e)
{- Paths over a path in a universe in the identity fibration reduces -}
↓-idf-ua-out : ∀ {i} {A B : Type i} (e : A ≃ B) {u : A} {v : B}
→ u == v [ (λ x → x) ↓ (ua e) ]
→ –> e u == v
↓-idf-ua-out e p = ! (coe-β e _) ∙ aux (ua e) p where
aux : ∀ {i} {A B : Type i} (p : A == B) {u : A} {v : B}
→ u == v [ (λ x → x) ↓ p ]
→ coe p u == v
aux idp = idf _
↓-idf-ua-in : ∀ {i} {A B : Type i} (e : A ≃ B) {u : A} {v : B}
→ –> e u == v
→ u == v [ (λ x → x) ↓ (ua e) ]
↓-idf-ua-in e p = aux (ua e) (coe-β e _ ∙ p) where
aux : ∀ {i} {A B : Type i} (p : A == B) {u : A} {v : B}
→ coe p u == v
→ u == v [ (λ x → x) ↓ p ]
aux idp = idf _
{- Induction along equivalences
If [P] is a predicate over all equivalences in a universe [Type i] and [d] is a
proof of [P] over all [ide A], then we get a section of [P]
-}
equiv-induction : ∀ {i j} (P : {A B : Type i} (f : A ≃ B) → Type j)
(d : (A : Type i) → P (ide A)) {A B : Type i} (f : A ≃ B)
→ P f
equiv-induction {i} {j} P d f =
transport P (coe-equiv-β f)
(aux P d (ua f)) where
aux : ∀ {j} (P : {A : Type i} {B : Type i} (f : A ≃ B) → Type j)
(d : (A : Type i) → P (ide A)) {A B : Type i} (p : A == B)
→ P (coe-equiv p)
aux P d idp = d _
| 32.974359
| 81
| 0.531104
|
29163360a70a71269dfa046435b5466a1520c953
| 179
|
agda
|
Agda
|
src/Tactic/Reflection/Quote/Class.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 111
|
2015-01-05T11:28:15.000Z
|
2022-02-12T23:29:26.000Z
|
src/Tactic/Reflection/Quote/Class.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 59
|
2016-02-09T05:36:44.000Z
|
2022-01-14T07:32:36.000Z
|
src/Tactic/Reflection/Quote/Class.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 24
|
2015-03-12T18:03:45.000Z
|
2021-04-22T06:10:41.000Z
|
module Tactic.Reflection.Quote.Class where
open import Builtin.Reflection
record Quotable {a} (A : Set a) : Set a where
field
` : A → Term
open Quotable {{...}} public
| 14.916667
| 45
| 0.675978
|
c7bc080f842876b7a6f9640cc85da89d6065a6a6
| 4,804
|
agda
|
Agda
|
agda/book/Programming_Language_Foundations_in_Agda/x07-747Negation.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/book/Programming_Language_Foundations_in_Agda/x07-747Negation.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/book/Programming_Language_Foundations_in_Agda/x07-747Negation.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
module 747Negation where
-- Library
open import Relation.Binary.PropositionalEquality using (_≡_; refl) -- added last
open import Data.Nat using (ℕ; zero; suc)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; proj₁; proj₂)
-- Negation is defined as implying false.
¬_ : Set → Set
¬ A = A → ⊥
-- if both ¬ A and A hold, then ⊥ holds (not surprisingly).
¬-elim : ∀ {A : Set}
→ ¬ A
→ A
---
→ ⊥
¬-elim = {!!}
infix 3 ¬_
-- Double negation introduction.
¬¬-intro : ∀ {A : Set}
→ A
-----
→ ¬ ¬ A
¬¬-intro = {!!}
-- Double negation cannot be eliminated in intuitionistic logic.
-- Triple negation elimination.
¬¬¬-elim : ∀ {A : Set}
→ ¬ ¬ ¬ A
-------
→ ¬ A
¬¬¬-elim = {!!}
-- One direction of the contrapositive.
contraposition : ∀ {A B : Set}
→ (A → B)
-----------
→ (¬ B → ¬ A)
contraposition = {!!}
-- The other direction cannot be proved in intuitionistic logic.
-- not-equal-to.
_≢_ : ∀ {A : Set} → A → A → Set
x ≢ y = ¬ (x ≡ y)
_ : 1 ≢ 2
_ = {!!}
-- One of the first-order Peano axioms.
peano : ∀ {m : ℕ} → zero ≢ suc m
peano = {!!}
-- Copied from 747Isomorphism.
postulate
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
-- Two proofs of ⊥ → ⊥ which look different but are the same
-- (assuming extensionality).
id : ⊥ → ⊥
id x = x
id′ : ⊥ → ⊥
id′ ()
id≡id′ : id ≡ id′
id≡id′ = extensionality (λ())
-- Assuming extensionality, any two proofs of a negation are the same
assimilation : ∀ {A : Set} (¬x ¬x′ : ¬ A) → ¬x ≡ ¬x′
assimilation ¬x ¬x′ = extensionality λ x → ⊥-elim (¬x x)
-- Strict inequality (copied from 747Relations).
infix 4 _<_
data _<_ : ℕ → ℕ → Set where
z<s : ∀ {n : ℕ}
------------
→ zero < suc n
s<s : ∀ {m n : ℕ}
→ m < n
-------------
→ suc m < suc n
-- 747/PLFA exercise: NotFourLTThree (1 point)
-- Show ¬ (4 < 3).
¬4<3 : ¬ (4 < 3)
¬4<3 = {!!}
-- 747/PLFA exercise: LTIrrefl (1 point)
-- < is irreflexive (never reflexive).
¬n<n : ∀ (n : ℕ) → ¬ (n < n)
¬n<n n = {!!}
-- 747/PLFA exercise: LTTrich (3 points)
-- Show that strict inequality satisfies trichotomy,
-- in the sense that exactly one of the three possibilities holds.
-- Here is the expanded definition of trichotomy.
data Trichotomy (m n : ℕ) : Set where
is-< : m < n → ¬ m ≡ n → ¬ n < m → Trichotomy m n
is-≡ : m ≡ n → ¬ m < n → ¬ n < m → Trichotomy m n
is-> : n < m → ¬ m ≡ n → ¬ m < n → Trichotomy m n
<-trichotomy : ∀ (m n : ℕ) → Trichotomy m n
<-trichotomy m n = {!!}
-- PLFA exercise: one of DeMorgan's Laws as isomorphism
-- ⊎-dual-× : ∀ {A B : Set} → ¬ (A ⊎ B) ≃ (¬ A) × (¬ B)
-- Expand negation as implies-false, then look in 747Relations
-- for a law of which this is a special case.
-- What about ¬ (A × B) ≃ (¬ A) ⊎ (¬ B)?
-- Answer: RHS implies LHS but converse cannot be proved in intuitionistic logic.
-- Intuitionistic vs classical logic.
-- The law of the excluded middle (LEM, or just em) cannot be
-- proved in intuitionistic logic.
-- But we can add it, and get classical logic.
-- postulate
-- em : ∀ {A : Set} → A ⊎ ¬ A
-- How do we know this does not give a contradiction?
-- The following theorem of intuitionistic logic demonstrates this.
-- (The proof is compact, but takes some thought.)
em-irrefutable : ∀ {A : Set} → ¬ ¬ (A ⊎ ¬ A)
em-irrefutable = {!!}
-- PLFA exercise: classical equivalences
-- Excluded middle cannot be proved in intuitionistic logic,
-- but adding it is consistent and gives classical logic.
-- Here are four other classical theorems with the same property.
-- You can show that each of them is logically equivalent to all the others.
-- You do not need to prove twenty implications, since implication is transitive.
-- But there is a lot of choice as to how to proceed!
-- Excluded Middle
em = ∀ {A : Set} → A ⊎ ¬ A
-- Double Negation Elimination
dne = ∀ {A : Set} → ¬ ¬ A → A
-- Peirce’s Law
peirce = ∀ {A B : Set} → ((A → B) → A) → A
-- Implication as disjunction
iad = ∀ {A B : Set} → (A → B) → ¬ A ⊎ B
-- De Morgan:
dem = ∀ {A B : Set} → ¬ (¬ A × ¬ B) → A ⊎ B
-- End of classical five exercise.
-- Definition: a formula is stable if double negation holds for it.
Stable : Set → Set
Stable A = ¬ ¬ A → A
-- PLFA exercise: every negated formula is stable.
-- This is triple negation elimination.
-- PLFA exercise: the conjunction of two stable formulas is stable.
-- This is the version of DeMorgan's Law that is a special case, above.
-- Where negation sits in the standard library.
import Relation.Nullary using (¬_)
import Relation.Nullary.Negation using (contraposition)
-- Unicode used in this chapter:
{-
¬ U+00AC NOT SIGN (\neg)
≢ U+2262 NOT IDENTICAL TO (\==n)
-}
| 22.87619
| 81
| 0.598043
|
dc1da6ee49fe5d10a624dc6567741de258045539
| 1,525
|
agda
|
Agda
|
src/fot/Common/FOL/Relation/Binary/PropositionalEquality.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/Common/FOL/Relation/Binary/PropositionalEquality.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/Common/FOL/Relation/Binary/PropositionalEquality.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Propositional equality
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module is re-exported by (some) "base" modules.
module Common.FOL.Relation.Binary.PropositionalEquality where
open import Common.FOL.FOL using ( D )
infix 4 _≡_
------------------------------------------------------------------------------
-- The identity type on the universe of discourse.
data _≡_ (x : D) : D → Set where
refl : x ≡ x
-- Elimination rule.
subst : (A : D → Set) → ∀ {x y} → x ≡ y → A x → A y
subst A refl Ax = Ax
-- Identity properties
sym : ∀ {x y} → x ≡ y → y ≡ x
sym refl = refl
trans : ∀ {x y z} → x ≡ y → y ≡ z → x ≡ z
trans refl h = h
trans₂ : ∀ {w x y z} → w ≡ x → x ≡ y → y ≡ z → w ≡ z
trans₂ refl refl h = h
subst₂ : (A : D → D → Set) → ∀ {x x' y y'} →
x ≡ y → x' ≡ y' →
A x x' →
A y y'
subst₂ A refl refl Axs = Axs
subst₃ : (A : D → D → D → Set) → ∀ {x₁ x₂ x₃ y₁ y₂ y₃} →
x₁ ≡ y₁ → x₂ ≡ y₂ → x₃ ≡ y₃ →
A x₁ x₂ x₃ →
A y₁ y₂ y₃
subst₃ A refl refl refl Axs = Axs
subst₄ : (A : D → D → D → D → Set) → ∀ {x₁ x₂ x₃ x₄ y₁ y₂ y₃ y₄} →
x₁ ≡ y₁ → x₂ ≡ y₂ → x₃ ≡ y₃ → x₄ ≡ y₄ →
A x₁ x₂ x₃ x₄ →
A y₁ y₂ y₃ y₄
subst₄ A refl refl refl refl Axs = Axs
| 27.727273
| 78
| 0.428197
|
58f1dd9d403e48d95ae9f1b23b356dcb2193dfa3
| 833
|
agda
|
Agda
|
test/api/PrettyInterface.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/api/PrettyInterface.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/api/PrettyInterface.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v 20 #-}
-- {-# OPTIONS -v tc.polarity:30 #-}
-- {-# OPTIONS -v tc.decl:30 #-}
-- {-# OPTIONS -v tc.term:30 #-}
-- {-# OPTIONS -v tc.conv.coerce:20 #-}
-- {-# OPTIONS -v tc.signature:30 #-}
-- {-# OPTIONS -v import.iface:100 #-}
module PrettyInterface where
open import Agda.Primitive
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
id : ∀{a} {A : Set a} → A → A
id {A = A} a = a
id2 : ∀{A : id Set} → id A → A
id2 x = x
plus0 : ∀ x → x + 0 ≡ x
plus0 zero = refl
plus0 (suc x) rewrite plus0 x = refl
Identity : ∀{a} {A : Set a} (f : A → A) → Set a
Identity f = ∀ x → f x ≡ x
plus-0 : Identity (_+ 0)
plus-0 = plus0
my-Fun : ∀{a b} (A : Set a) (F : A → Set b) → Set (a ⊔ b)
my-Fun A F = (x : A) → F x
syntax my-Fun A (λ x → B) = [ x ∷ A ]=> B
my-id : [ A ∷ Set ]=> [ x ∷ A ]=> A
my-id A x = x
| 21.921053
| 57
| 0.528211
|
1d71d14468762a1049607a8ce6a921da3f961221
| 2,300
|
agda
|
Agda
|
src/agda/Vehicle.agda
|
vehicle-lang/vehicle
|
25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0
|
[
"BSD-3-Clause"
] | 9
|
2022-02-10T12:56:42.000Z
|
2022-02-17T18:51:05.000Z
|
src/agda/Vehicle.agda
|
vehicle-lang/vehicle
|
25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0
|
[
"BSD-3-Clause"
] | 19
|
2022-03-07T14:09:13.000Z
|
2022-03-31T20:49:39.000Z
|
src/agda/Vehicle.agda
|
vehicle-lang/vehicle
|
25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --allow-exec #-}
open import Agda.Builtin.FromNat
open import Data.Bool.Base using (T; Bool; if_then_else_)
open import Data.String using (String; _++_; lines)
open import Data.Nat.Base using (ℕ)
open import Data.Fin using (Fin)
import Data.Fin.Literals as Fin
import Data.Nat.Literals as Nat
open import Data.Vec.Base using (Vec)
open import Data.Float.Base using (Float; _≤ᵇ_)
open import Data.List.Base using (List; []; _∷_)
open import Data.Unit.Base using (⊤; tt)
open import Relation.Nullary using (does)
open import Relation.Binary.Core using (Rel)
open import Reflection.Argument
open import Reflection.Term
open import Reflection.External
open import Reflection.TypeChecking.Monad
open import Reflection.TypeChecking.Monad.Syntax
open import Reflection.Show using (showTerm)
open import Vehicle.Utils
module Vehicle where
------------------------------------------------------------------------
-- Metadata
------------------------------------------------------------------------
VEHICLE_COMMAND : String
VEHICLE_COMMAND = "vehicle"
------------------------------------------------------------------------
-- Checking
------------------------------------------------------------------------
record CheckArgs : Set where
field
proofCache : String
checkCmd : CheckArgs → CmdSpec
checkCmd checkArgs = cmdSpec VEHICLE_COMMAND
( "check"
∷ ("--proofCache=" ++ proofCache)
∷ []) ""
where open CheckArgs checkArgs
checkSuccessful : String → Bool
checkSuccessful output = "verified" ⊆ output
postulate valid : ∀ {a} {A : Set a} → A
`valid : Term
`valid = def (quote valid) (hArg unknown ∷ [])
checkSpecificationMacro : CheckArgs → Term → TC ⊤
checkSpecificationMacro args hole = do
goal ← inferType hole
-- (showTerm goal)
output ← runCmdTC (checkCmd args)
if checkSuccessful output
then unify hole `valid
else typeError (strErr ("Error: " ++ output) ∷ [])
macro
checkSpecification : CheckArgs → Term → TC ⊤
checkSpecification = checkSpecificationMacro
------------------------------------------------------------------------
-- Other
------------------------------------------------------------------------
instance
finNumber : ∀ {n} -> Number (Fin n)
finNumber {n} = Fin.number n
natNumber : Number ℕ
natNumber = Nat.number
| 28.04878
| 72
| 0.593478
|
06b8f632a53575ac293a5b5ec2c202f53c9fddbf
| 12,986
|
agda
|
Agda
|
core/lib/types/Truncation.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
core/lib/types/Truncation.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
core/lib/types/Truncation.agda
|
timjb/HoTT-Agda
|
66f800adef943afdf08c17b8ecfba67340fead5e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.TLevel
open import lib.types.Pi
open import lib.types.Sigma
open import lib.NType2
module lib.types.Truncation where
module _ {i} where
postulate -- HIT
Trunc : (n : ℕ₋₂) (A : Type i) → Type i
[_] : {n : ℕ₋₂} {A : Type i} → A → Trunc n A
instance Trunc-level : {n : ℕ₋₂} {A : Type i} → has-level n (Trunc n A)
module TruncElim {n : ℕ₋₂} {A : Type i} {j} {P : Trunc n A → Type j}
{{p : (x : Trunc n A) → has-level n (P x)}} (d : (a : A) → P [ a ]) where
postulate -- HIT
f : Π (Trunc n A) P
[_]-β : ∀ a → f [ a ] ↦ d a
{-# REWRITE [_]-β #-}
open TruncElim public renaming (f to Trunc-elim)
module TruncRec {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} {{p : has-level n B}}
(d : A → B) where
private
module M = TruncElim {{λ x → p}} d
f : Trunc n A → B
f = M.f
open TruncRec public renaming (f to Trunc-rec)
module TruncRecType {i j} {n : ℕ₋₂} {A : Type i} (d : A → n -Type j) where
open TruncRec {{n -Type-level j}} d public
flattening-Trunc : Σ (Trunc (S n) A) (fst ∘ f) ≃ Trunc (S n) (Σ A (fst ∘ d))
flattening-Trunc = equiv to from to-from from-to where
to-aux : (x : Trunc (S n) A) → (fst (f x) → Trunc (S n) (Σ A (fst ∘ d)))
to-aux = Trunc-elim (λ a b → [ (a , b) ])
to : Σ (Trunc (S n) A) (fst ∘ f) → Trunc (S n) (Σ A (fst ∘ d))
to (x , y) = to-aux x y
from-aux : Σ A (fst ∘ d) → Σ (Trunc (S n) A) (fst ∘ f)
from-aux (a , b) = ([ a ] , b)
from : Trunc (S n) (Σ A (fst ∘ d)) → Σ (Trunc (S n) A) (fst ∘ f)
from = Trunc-rec {{Σ-level ⟨⟩ (λ x → raise-level _ (snd (f x)))}}
from-aux where
to-from : (x : Trunc (S n) (Σ A (fst ∘ d))) → to (from x) == x
to-from = Trunc-elim (λ _ → idp)
from-to-aux : (a : Trunc (S n) A) (b : fst (f a)) → from (to-aux a b) == (a , b)
from-to-aux = Trunc-elim {{λ _ → Π-level (λ _ → =-preserves-level (Σ-level ⟨⟩ (λ x → raise-level _ (snd (f x)))))}}
(λ a b → idp)
from-to : (x : Σ (Trunc (S n) A) (fst ∘ f)) → from (to x) == x
from-to (a , b) = from-to-aux a b
⊙Trunc : ∀ {i} → ℕ₋₂ → Ptd i → Ptd i
⊙Trunc n ⊙[ A , a ] = ⊙[ Trunc n A , [ a ] ]
module _ {i} {n : ℕ₋₂} {A : Type i} where
Trunc= : (a b : Trunc (S n) A) → n -Type i
Trunc= = Trunc-elim (λ a → Trunc-elim ((λ b → (Trunc n (a == b) , Trunc-level))))
Trunc=-equiv : (a b : Trunc (S n) A) → (a == b) ≃ fst (Trunc= a b)
Trunc=-equiv a b = equiv (to a b) (from a b) (to-from a b) (from-to a b) where
to-aux : (a : Trunc (S n) A) → fst (Trunc= a a)
to-aux = Trunc-elim {{λ x → raise-level _ (snd (Trunc= x x))}}
(λ a → [ idp ])
to : (a b : Trunc (S n) A) → (a == b → fst (Trunc= a b))
to a .a idp = to-aux a
from-aux : (a b : A) → a == b → [ a ] == [ b ] :> Trunc (S n) A
from-aux a .a idp = idp
from : (a b : Trunc (S n) A) → (fst (Trunc= a b) → a == b)
from = Trunc-elim (λ a → Trunc-elim (λ b → Trunc-rec (from-aux a b)))
to-from-aux : (a b : A) → (p : a == b) → to _ _ (from-aux a b p) == [ p ]
to-from-aux a .a idp = idp
to-from : (a b : Trunc (S n) A) (x : fst (Trunc= a b)) → to a b (from a b x) == x
to-from = Trunc-elim {{λ x → Π-level (λ y → Π-level (λ _ → =-preserves-level (raise-level _ (snd (Trunc= x y)))))}}
(λ a → Trunc-elim {{λ x → Π-level (λ _ → =-preserves-level (raise-level _ (snd (Trunc= [ a ] x))))}}
(λ b → Trunc-elim
(to-from-aux a b)))
from-to-aux : (a : Trunc (S n) A) → from a a (to-aux a) == idp
from-to-aux = Trunc-elim (λ _ → idp)
from-to : (a b : Trunc (S n) A) (p : a == b) → from a b (to a b p) == p
from-to a .a idp = from-to-aux a
Trunc=-path : (a b : Trunc (S n) A) → (a == b) == fst (Trunc= a b)
Trunc=-path a b = ua (Trunc=-equiv a b)
{- Universal property -}
abstract
Trunc-rec-is-equiv : ∀ {i j} (n : ℕ₋₂) (A : Type i) (B : Type j)
{{p : has-level n B}} → is-equiv (Trunc-rec {{p}} :> ((A → B) → (Trunc n A → B)))
Trunc-rec-is-equiv n A B {{p}} = is-eq _ (λ f → f ∘ [_])
(λ f → λ= (Trunc-elim (λ a → idp))) (λ f → idp)
Trunc-preserves-level : ∀ {i} {A : Type i} {n : ℕ₋₂} (m : ℕ₋₂)
→ has-level n A → has-level n (Trunc m A)
Trunc-preserves-level {n = ⟨-2⟩} _ p = has-level-in
([ contr-center p ] , Trunc-elim (λ a → ap [_] (contr-path p a)))
Trunc-preserves-level ⟨-2⟩ _ = contr-has-level Trunc-level
Trunc-preserves-level {n = (S n)} (S m) c = has-level-in (λ t₁ t₂ →
Trunc-elim
{{λ s₁ → prop-has-level-S {A = has-level n (s₁ == t₂)} has-level-is-prop}}
(λ a₁ → Trunc-elim
{{λ s₂ → prop-has-level-S {A = has-level n ([ a₁ ] == s₂)} has-level-is-prop}}
(λ a₂ → equiv-preserves-level
((Trunc=-equiv [ a₁ ] [ a₂ ])⁻¹)
{{Trunc-preserves-level {n = n} m (has-level-apply c a₁ a₂)}})
t₂)
t₁)
{- an n-type is equivalent to its n-truncation -}
unTrunc-equiv : ∀ {i} {n : ℕ₋₂} (A : Type i)
{{_ : has-level n A}} → Trunc n A ≃ A
unTrunc-equiv A = equiv f [_] (λ _ → idp) g-f where
f = Trunc-rec (idf _)
g-f = Trunc-elim (λ _ → idp)
⊙unTrunc-equiv : ∀ {i} {n : ℕ₋₂} (X : Ptd i)
{{_ : has-level n (de⊙ X)}} → ⊙Trunc n X ⊙≃ X
⊙unTrunc-equiv {n = n} X = ≃-to-⊙≃ (unTrunc-equiv (de⊙ X)) idp
-- Equivalence associated to the universal property
Trunc-extend-equiv : ∀ {i j} (n : ℕ₋₂) (A : Type i) (B : Type j)
{{p : has-level n B}} → (A → B) ≃ (Trunc n A → B)
Trunc-extend-equiv n A B = (Trunc-rec , Trunc-rec-is-equiv n A B)
Trunc-fmap : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} → ((A → B) → (Trunc n A → Trunc n B))
Trunc-fmap f = Trunc-rec ([_] ∘ f)
⊙Trunc-fmap : ∀ {i j} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j} → ((X ⊙→ Y) → (⊙Trunc n X ⊙→ ⊙Trunc n Y))
⊙Trunc-fmap F = Trunc-fmap (fst F) , ap [_] (snd F)
Trunc-fmap2 : ∀ {i j k} {n : ℕ₋₂} {A : Type i} {B : Type j} {C : Type k}
→ ((A → B → C) → (Trunc n A → Trunc n B → Trunc n C))
Trunc-fmap2 f = Trunc-rec (λ a → Trunc-fmap (f a))
-- XXX What is the naming convention?
Trunc-fpmap : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} {f g : A → B}
→ f ∼ g → Trunc-fmap {n = n} f ∼ Trunc-fmap g
Trunc-fpmap h = Trunc-elim (ap [_] ∘ h)
Trunc-fmap-idf : ∀ {i} {n : ℕ₋₂} {A : Type i}
→ ∀ x → Trunc-fmap {n = n} (idf A) x == x
Trunc-fmap-idf =
Trunc-elim (λ _ → idp)
Trunc-fmap-∘ : ∀ {i j k} {n : ℕ₋₂} {A : Type i} {B : Type j} {C : Type k}
→ (g : B → C) → (f : A → B)
→ ∀ x → Trunc-fmap {n = n} g (Trunc-fmap f x) == Trunc-fmap (g ∘ f) x
Trunc-fmap-∘ g f =
Trunc-elim (λ _ → idp)
Trunc-csmap : ∀ {i₀ i₁ j₀ j₁} {n : ℕ₋₂}
{A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}
{f : A₀ → B₀} {g : A₁ → B₁} {hA : A₀ → A₁} {hB : B₀ → B₁}
→ CommSquare f g hA hB
→ CommSquare (Trunc-fmap {n = n} f) (Trunc-fmap g) (Trunc-fmap hA) (Trunc-fmap hB)
Trunc-csmap (comm-sqr cs) = comm-sqr $ Trunc-elim (ap [_] ∘ cs)
{- Pushing concatentation through Trunc= -}
module _ {i} {n : ℕ₋₂} {A : Type i} where
{- concatenation in Trunc= -}
Trunc=-∙ : {ta tb tc : Trunc (S n) A}
→ fst (Trunc= ta tb) → fst (Trunc= tb tc) → fst (Trunc= ta tc)
Trunc=-∙ {ta = ta} {tb = tb} {tc = tc} =
Trunc-elim {P = λ ta → C ta tb tc}
{{λ ta → level ta tb tc}}
(λ a → Trunc-elim {P = λ tb → C [ a ] tb tc}
{{λ tb → level [ a ] tb tc}}
(λ b → Trunc-elim {P = λ tc → C [ a ] [ b ] tc}
{{λ tc → level [ a ] [ b ] tc}}
(λ c → Trunc-fmap2 _∙_)
tc)
tb)
ta
where
C : (ta tb tc : Trunc (S n) A) → Type i
C ta tb tc = fst (Trunc= ta tb) → fst (Trunc= tb tc) → fst (Trunc= ta tc)
level : (ta tb tc : Trunc (S n) A) → has-level (S n) (C ta tb tc)
level ta tb tc = raise-level _ $
Π-level (λ _ → Π-level (λ _ → snd (Trunc= ta tc)))
{- XXX naming convention -}
Trunc=-∙-comm : {x y z : Trunc (S n) A }
(p : x == y) (q : y == z)
→ –> (Trunc=-equiv x z) (p ∙ q)
== Trunc=-∙ {ta = x} (–> (Trunc=-equiv x y) p) (–> (Trunc=-equiv y z) q)
Trunc=-∙-comm {x = x} idp idp =
Trunc-elim
{P = λ x → –> (Trunc=-equiv x x) idp
== Trunc=-∙ {ta = x} (–> (Trunc=-equiv x x) idp)
(–> (Trunc=-equiv x x) idp)}
{{λ x → raise-level _ $ =-preserves-level (snd (Trunc= x x))}}
(λ a → idp)
x
{- naturality of Trunc=-equiv -}
module _ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} (f : A → B) where
Trunc=-fmap : ∀ (a₀ a₁ : Trunc (S n) A)
→ (fst (Trunc= {n = n} a₀ a₁) → fst (Trunc= {n = n} (Trunc-fmap f a₀) (Trunc-fmap f a₁)))
Trunc=-fmap = Trunc-elim
{P = λ a₀ → ∀ a₁ → (fst (Trunc= a₀ a₁) → fst (Trunc= (Trunc-fmap f a₀) (Trunc-fmap f a₁)))}
{{λ a₀ → Π-level λ a₁ → Π-level λ _ → raise-level _ $ snd (Trunc= (Trunc-fmap f a₀) (Trunc-fmap f a₁))}}
(λ a₀ → Trunc-elim
{P = λ a₁ → (fst (Trunc= [ a₀ ] a₁) → fst (Trunc= [ f a₀ ] (Trunc-fmap f a₁)))}
{{λ a₁ → Π-level λ _ → raise-level _ $ snd (Trunc= [ f a₀ ] (Trunc-fmap f a₁))}}
(λ a₁ → Trunc-fmap (ap f)))
module _ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} (f : A → B) where
Trunc=-equiv-nat : ∀ (a₀ a₁ : Trunc (S n) A) (p : a₀ == a₁)
→ –> (Trunc=-equiv (Trunc-fmap f a₀) (Trunc-fmap f a₁)) (ap (Trunc-fmap f) p)
== Trunc=-fmap f a₀ a₁ (–> (Trunc=-equiv a₀ a₁) p)
Trunc=-equiv-nat a₀ .a₀ idp =
Trunc-elim
{P = λ a
→ –> (Trunc=-equiv (Trunc-fmap f a) (Trunc-fmap f a)) idp
== Trunc=-fmap f a a (–> (Trunc=-equiv a a) idp)}
{{λ a → raise-level _ $ =-preserves-level $ snd ((Trunc= (Trunc-fmap f a) (Trunc-fmap f a)))}}
(λ _ → idp)
a₀
{- Truncation preserves equivalences - more convenient than univalence+ap
- when we need to know the forward or backward function explicitly -}
module _ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} where
Trunc-isemap : {f : A → B} → is-equiv f → is-equiv (Trunc-fmap {n = n} f)
Trunc-isemap {f-orig} ie = is-eq f g f-g g-f where
f = Trunc-fmap f-orig
g = Trunc-fmap (is-equiv.g ie)
f-g : ∀ tb → f (g tb) == tb
f-g = Trunc-elim (ap [_] ∘ is-equiv.f-g ie)
g-f : ∀ ta → g (f ta) == ta
g-f = Trunc-elim (ap [_] ∘ is-equiv.g-f ie)
Trunc-emap : A ≃ B → Trunc n A ≃ Trunc n B
Trunc-emap (f , f-ie) = Trunc-fmap f , Trunc-isemap f-ie
Trunc-csemap : ∀ {i₀ i₁ j₀ j₁} {n : ℕ₋₂}
{A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}
{f : A₀ → B₀} {g : A₁ → B₁} {hA : A₀ → A₁} {hB : B₀ → B₁}
→ CommSquareEquiv f g hA hB
→ CommSquareEquiv (Trunc-fmap {n = n} f) (Trunc-fmap g) (Trunc-fmap hA) (Trunc-fmap hB)
Trunc-csemap (cs , hA-ise , hB-ise) = Trunc-csmap cs , Trunc-isemap hA-ise , Trunc-isemap hB-ise
transport-Trunc : ∀ {i j} {A : Type i} {n : ℕ₋₂} (P : A → Type j)
{x y : A} (p : x == y) (b : P x)
→ transport (Trunc n ∘ P) p [ b ] == [ transport P p b ]
transport-Trunc _ idp _ = idp
Trunc-fuse : ∀ {i} (A : Type i) (m n : ℕ₋₂)
→ Trunc m (Trunc n A) ≃ Trunc (minT m n) A
Trunc-fuse A m n = equiv
(Trunc-rec {{raise-level-≤T (minT≤l m n) Trunc-level}}
(Trunc-rec {{raise-level-≤T (minT≤r m n) Trunc-level}}
[_]))
(Trunc-rec ([_] ∘ [_]))
(Trunc-elim (λ _ → idp))
(Trunc-elim (Trunc-elim
{{λ _ → =-preserves-level (Trunc-preserves-level _ Trunc-level)}}
(λ _ → idp)))
where
instance
l : has-level (minT m n) (Trunc m (Trunc n A))
l with (minT-out m n)
l | inl p = transport (λ k → has-level k (Trunc m (Trunc n A)))
(! p) Trunc-level
l | inr q = Trunc-preserves-level _
(transport (λ k → has-level k (Trunc n A))
(! q) Trunc-level)
Trunc-fuse-≤ : ∀ {i} (A : Type i) {m n : ℕ₋₂} (m≤n : m ≤T n)
→ Trunc m (Trunc n A) ≃ Trunc m A
Trunc-fuse-≤ A m≤n = equiv
(Trunc-rec (Trunc-rec {{raise-level-≤T m≤n Trunc-level}}
[_]))
(Trunc-rec ([_] ∘ [_]))
(Trunc-elim (λ _ → idp))
(Trunc-elim (Trunc-elim
{{λ _ → =-preserves-level (Trunc-preserves-level _ Trunc-level)}}
(λ _ → idp)))
{- Truncating a binary product is equivalent to truncating its components -}
Trunc-×-econv : ∀ {i} {j} (n : ℕ₋₂) (A : Type i) (B : Type j)
→ Trunc n (A × B) ≃ Trunc n A × Trunc n B
Trunc-×-econv n A B = equiv f g f-g g-f
where
f : Trunc n (A × B) → Trunc n A × Trunc n B
f = Trunc-rec (λ {(a , b) → [ a ] , [ b ]})
g : Trunc n A × Trunc n B → Trunc n (A × B)
g (ta , tb) = Trunc-rec (λ a → Trunc-rec (λ b → [ a , b ]) tb) ta
f-g : ∀ p → f (g p) == p
f-g (ta , tb) = Trunc-elim
{P = λ ta → f (g (ta , tb)) == (ta , tb)}
(λ a → Trunc-elim
{P = λ tb → f (g ([ a ] , tb)) == ([ a ] , tb)}
(λ b → idp)
tb)
ta
g-f : ∀ tab → g (f tab) == tab
g-f = Trunc-elim
{P = λ tab → g (f tab) == tab}
(λ ab → idp)
Trunc-×-conv : ∀ {i} {j} (n : ℕ₋₂) (A : Type i) (B : Type j)
→ Trunc n (A × B) == Trunc n A × Trunc n B
Trunc-×-conv n A B = ua (Trunc-×-econv n A B)
| 38.082111
| 119
| 0.5
|
c70f9fbb86e3fbdc6a2b41ef575f5e4ed9160e0d
| 3,308
|
agda
|
Agda
|
src/Categories/Functor/Hom.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Functor/Hom.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Functor/Hom.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Hom where
-- The Hom Functor from C.op × C to Setoids,
-- the two 1-argument version fixing one object
-- and some notation for the version where the category must be made explicit
open import Data.Product
open import Function using () renaming (_∘_ to _∙_)
open import Categories.Category
open import Categories.Functor hiding (id)
open import Categories.Functor.Bifunctor
open import Categories.Category.Instance.Setoids
import Categories.Morphism.Reasoning as MR
open import Relation.Binary using (Setoid)
module Hom {o ℓ e} (C : Category o ℓ e) where
open Category C
open MR C
Hom[-,-] : Bifunctor (Category.op C) C (Setoids ℓ e)
Hom[-,-] = record
{ F₀ = F₀′
; F₁ = λ where
(f , g) → record
{ _⟨$⟩_ = λ h → g ∘ h ∘ f
; cong = ∘-resp-≈ʳ ∙ ∘-resp-≈ˡ
}
; identity = identity′
; homomorphism = homomorphism′
; F-resp-≈ = F-resp-≈′
}
where F₀′ : Obj × Obj → Setoid ℓ e
F₀′ (A , B) = hom-setoid {A} {B}
open HomReasoning
identity′ : {A : Obj × Obj} {x y : uncurry _⇒_ A} → x ≈ y → id ∘ x ∘ id ≈ y
identity′ {A} {x} {y} x≈y = begin
id ∘ x ∘ id ≈⟨ identityˡ ⟩
x ∘ id ≈⟨ identityʳ ⟩
x ≈⟨ x≈y ⟩
y ∎
homomorphism′ : ∀ {X Y Z : Σ Obj (λ x → Obj)}
{f : proj₁ Y ⇒ proj₁ X × proj₂ X ⇒ proj₂ Y}
{g : proj₁ Z ⇒ proj₁ Y × proj₂ Y ⇒ proj₂ Z}
{x y : proj₁ X ⇒ proj₂ X} →
x ≈ y →
(proj₂ g ∘ proj₂ f) ∘ x ∘ proj₁ f ∘ proj₁ g ≈
proj₂ g ∘ (proj₂ f ∘ y ∘ proj₁ f) ∘ proj₁ g
homomorphism′ {f = f₁ , f₂} {g₁ , g₂} {x} {y} x≈y = begin
(g₂ ∘ f₂) ∘ x ∘ f₁ ∘ g₁ ≈⟨ refl⟩∘⟨ sym-assoc ⟩
(g₂ ∘ f₂) ∘ (x ∘ f₁) ∘ g₁ ≈⟨ pullʳ (pullˡ (∘-resp-≈ʳ (∘-resp-≈ˡ x≈y))) ⟩
g₂ ∘ (f₂ ∘ y ∘ f₁) ∘ g₁ ∎
F-resp-≈′ : ∀ {A B : Σ Obj (λ x → Obj)}
{f g : Σ (proj₁ B ⇒ proj₁ A) (λ x → proj₂ A ⇒ proj₂ B)} →
Σ (proj₁ f ≈ proj₁ g) (λ x → proj₂ f ≈ proj₂ g) →
{x y : proj₁ A ⇒ proj₂ A} →
x ≈ y → proj₂ f ∘ x ∘ proj₁ f ≈ proj₂ g ∘ y ∘ proj₁ g
F-resp-≈′ {f = f₁ , f₂} {g₁ , g₂} (f₁≈g₁ , f₂≈g₂) {x} {y} x≈y = begin
f₂ ∘ x ∘ f₁ ≈⟨ f₂≈g₂ ⟩∘⟨ x≈y ⟩∘⟨ f₁≈g₁ ⟩
g₂ ∘ y ∘ g₁ ∎
open Functor Hom[-,-]
open Equiv
open HomReasoning
Hom[_,-] : Obj → Functor C (Setoids ℓ e)
Hom[_,-] = appˡ Hom[-,-]
Hom[-,_] : Obj → Contravariant C (Setoids ℓ e)
Hom[-,_] = appʳ Hom[-,-]
Hom[_,_] : Obj → Obj → Setoid ℓ e
Hom[ A , B ] = hom-setoid {A} {B}
-- Notation for when the ambient Category must be specified explicitly.
module _ {o ℓ e} (C : Category o ℓ e) where
open Category C
open Hom C
Hom[_][-,-] : Bifunctor (Category.op C) C (Setoids ℓ e)
Hom[_][-,-] = Hom[-,-]
Hom[_][_,-] : Obj → Functor C (Setoids ℓ e)
Hom[_][_,-] B = Hom[ B ,-]
Hom[_][-,_] : Obj → Contravariant C (Setoids ℓ e)
Hom[_][-,_] B = Hom[-, B ]
Hom[_][_,_] : Obj → Obj → Setoid ℓ e
Hom[_][_,_] A B = hom-setoid {A} {B}
| 34.458333
| 85
| 0.476421
|
5814a9b79dd221233e777abc8b5205472d162aa3
| 35,894
|
agda
|
Agda
|
agda/paper/2009-Dependent_Types_at_Work-Bove_and_Dybjer/x01.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/paper/2009-Dependent_Types_at_Work-Bove_and_Dybjer/x01.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/paper/2009-Dependent_Types_at_Work-Bove_and_Dybjer/x01.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
import Relation.Binary.PropositionalEquality as PE
module x01 where
import Data.Empty.Polymorphic as DEP
open import Data.Unit.Polymorphic
import Data.Maybe as Maybe
{-
Dependent Types at Work
Ana Bove and Peter Dybjer
Chalmers University of Technology, Göteborg, Sweden
intro to functional programming with dependent types
- simply typed functional programming in style of Haskell and ML
- discuss differences between Agda’s type system and Hindley-Milner type system of Haskell/ML
- how to use dependent types for programming
- explain ideas behind type-checking dependent types
- explain Curry-Howard identification of propositions and types
- show a method to encode partial/general recursive functions
as total functions using dependent types
Dependent types are types that depend on elements of other types (e.g., Vec of length n)
Invariants can be expressed with dependent type (e.g., sorted list)
Agda's dependent type system is an extension of Martin-Löf type theory [20,21,22,25].
Parametrised types
- e.g., [A]
- usually not called dependent types
- they are are families of types indexed by other types
- NOT families of types indexed by ELEMENTS of another type
- however, in dependent type theories, there is a type of small types (a universe),
so that we have a type [A] of lists of elements of a given small type A.
- FORTRAN could define arrays of a given dimension, so a form a dependent type on small type
- simply typed lambda calculus and the Hindley-Milner type system,
(e.g., Haskell/ML) do not include dependent types, only parametrised types
- polymorphic lambda calculus System F [15] has types like
∀X.A where X ranges over all types,
but no quantification over ELEMENTS of other types
development of dependently typed programming languages has
origins in Curry-Howard isomorphism between propositions and types
1930’s : Curry noticed similarity between axioms of implicational logic
P ⊃ Q ⊃ P (P ⊃ Q ⊃ R) ⊃ (P ⊃ Q) ⊃ P ⊃ R
and types of combinators
K and S
A → B → A (A → B → C) → (A → B) → A → C
K can be viewed as a witness (i.e., proof object) of the truth of P ⊃ Q ⊃ P
S can be viewed as a withness of the truth of (P ⊃ Q ⊃ R) ⊃ (P ⊃ Q) ⊃ P ⊃ R
typing rule for application
corresponds to the inference rule modus ponens: from P ⊃ Q and P conclude Q
- f : A → B
- a : A
- f a → B
product types correspond to conjunctions
sum types (disjoint unions) to disjunctions
to extend this correspondence to predicate logic
Howard and de Bruijn introduced dependent types A(x) corresponding to predicates P(x).
They formed
indexed products Π x : D.A(x) : corresponding to universal quantifications ∀x : D.P (x)
indexed sums Σ x : D.A(x) : existential quantifications ∃x : D.P (x)
this gives a Curry-Howard interpretation of intuitionistic predicate logic
one-to-one correspondence between propositions and types
in a type system with dependent types
one-to-one correspondence between
- proofs of a certain proposition in constructive predicate logic, and
- terms of the corresponding type
To accommodate equality in predicate logic
introduce the type a == b of proofs that a and b are equal.
Gives a Curry-Howard interpretation of predicate logic with equality.
Can go further and add natural numbers with addition and multiplication
to obtain a Curry-Howard version of Heyting (intuitionistic) arithmetic.
Curry-Howard interpretation was basis for Martin-Löf’s intuitionistic type theory [20,21,22].
- propositions and types are identified
- intended to be a foundational system for constructive mathematics
- can also be used as a programming language [21]
- from 1980’s and onwards, systems implementing variants of Martin-Löf type theory
- NuPRL [6] : implementing an extensional version of the theory
- Coq [33] : implementing an intensional impredicative version
- Agda : implements an intensional predicative extension
About these Notes
Agda's type-checking algorithm
- Section 5
- ideas first presented by Coquand [7]
- more information
- Norell’s thesis [26]
- Abel, Coquand, and Dybjer [1,2]
- Coquand, Kinoshita, Nordström, and Takeyama [8].
more complete understanding of dependent type theory
- read a book about Martin-Löf type theory and related systems
- Martin-Löf’s “Intuitionistic Type Theory” [22] is a classic
- be aware that it describes an extensional version of the theory
- Nordström, Petersson, and Smith [25]
description of the later intensional theory on which Agda is based
- variants of dependent type theory are
- Thompson [34]
- Constable et al [6] : NuPRL
- Bertot and Casteran [4] : Coq
- lecture notes (Agda wiki [3]) by Norell
- collection of advanced examples of how to use Agda for dependently typed programming
- Geuvers’ lecture notes : introduction to type theory
- including Barendregt’s pure type systems and important meta-theoretic properties
- Bertot’s notes : how dependent types (in Coq) can be used for
implementing a number of concepts of programming language theory
- focus on abstract interpretation
- Barthe, Grégoire, and Riba’s notes
- method for making termination-checkers
Section 2 : ordinary functional programming
Section 3 : basic dependent types and shows how to use them
Section 4 : Curry-Howard isomorphism
Section 5 : aspects of type-checking and pattern matching with dependent types
Section 6 : use Agda as a programming logic
Section 7 : how to represent general recursion and partial functions as total functions in Agda
------------------------------------------------------------------------------
2 Simply Typed Functional Programming in Agda
2.1 Truth Values
-}
data Bool : Set where
true : Bool
false : Bool
{-
states
- Bool is a data type with the two (no-arg) constructors
- “:” denotes type membership
- Bool is a member of the type Set
- Set
- the type of sets (using a terminology introduced by Martin-Löf [22])
or small types (mentioned in the introduction).
- Bool is a small type, but Set itself is not, it is a large type.
- allowing Set : Set, would make the system inconsistent
-}
not : Bool -> Bool
not true = false
not false = true
{-
Agda cannot generally infer types.
Because Agda type-checking done via normalisation (simplification)
- without the normality restriction it may not terminate
-}
equiv : Bool -> Bool -> Bool
equiv false false = true
equiv true false = false
equiv false true = false
equiv true true = true
_||_ : Bool -> Bool -> Bool
true || _ = true
false || true = true
false || false = false
infixl 60 _||_
-- EXERCISE: Define some more truth functions, such as conjunction and implication/TODO.
_&&_ : Bool -> Bool -> Bool
false && _ = false
true && false = false
true && true = true
-- infixl ?? _&&_
-- 2.2 Natural Numbers
-- such data types known as recursive in Haskell
-- in constructive type theory, referred to as inductive types or inductively defined types
data Nat : Set where
zero : Nat
succ : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
pred : Nat -> Nat
pred zero = zero
pred (succ n) = n
_+_ : Nat -> Nat -> Nat
zero + m = m
succ n + m = succ (n + m)
{-# BUILTIN NATPLUS _+_ #-}
_*_ : Nat -> Nat -> Nat
zero * n = zero
succ n * m = (n * m) + m
{-# BUILTIN NATTIMES _*_ #-}
infixl 6 _+_ _∸_
infixl 7 _*_
_ : (2 * 3) + 10 PE.≡ 16
_ = PE.refl
{-
+ and * are defined by PRIMITIVE RECURSION in FIRST ARG.
- PRIMITIVE RECURSIION :
- upper bound of number of iterations of every loop can be determined before entering loop
- time complexity of PR functions bounded by the input size
- base case for zero
- step case for non zero defined recursively
Given a first order data type
- distinguish between
- canonical form
- built by constructors only
- e.g., true, false, zero, succ zero, succ (succ zero), ...
- non-canonical forms
- whereas non-canonical elements might contain defined functions
- e.g., not true, zero + zero, zero * zero, succ (zero + zero)
Martin-Löf [21] instead considers lazy canonical forms
- a term begins with a constructor to be considered a canonical form
- e.g., succ (zero + zero) is a lazy canonical form, but not a “full” canonical form
- Lazy canonical forms are appropriate for lazy functional programming languages (e.g., Haskell)
-- EXERCISE: Write the cut-off subtraction function
-- the function on natural numbers, which returns 0
-- if the second argument is greater than or equal to the first.
-}
_∸_ : Nat -> Nat -> Nat
zero ∸ _ = zero
succ n ∸ zero = succ n
succ n ∸ succ m = n ∸ m
_ : 0 ∸ 0 PE.≡ 0
_ = PE.refl
_ : 0 ∸ 10 PE.≡ 0
_ = PE.refl
_ : 10 ∸ 0 PE.≡ 10
_ = PE.refl
_ : 10 ∸ 10 PE.≡ 0
_ = PE.refl
_ : 10 ∸ 9 PE.≡ 1
_ = PE.refl
-- EXERCISE: Also write some more numerical functions like < or <=
_<_ : Nat -> Nat -> Bool
zero < zero = false
zero < succ _ = true
succ _ < zero = false
succ n < succ m = n < m
_ : 9 < 10 PE.≡ true
_ = PE.refl
_ : 10 < 10 PE.≡ false
_ = PE.refl
_<=_ : Nat -> Nat -> Bool
zero <= zero = true
zero <= succ _ = true
succ _ <= zero = false
succ n <= succ m = n <= m
_ : 9 <= 10 PE.≡ true
_ = PE.refl
_ : 10 <= 10 PE.≡ true
_ = PE.refl
_>_ : Nat -> Nat -> Bool
zero > zero = false
zero > succ _ = false
succ _ > zero = true
succ n > succ m = n > m
{-
2.3 Lambda Notation and Polymorphism
Agda is based on the typed lambda calculus.
APPLICATION is juxtaposition
lambda ABSTRACTION written either
- Curry-style (without a type label)
\x -> e
- Church-style (with a type label)
\(x : A) -> e
a family of identity functions, one for each small type:
-}
-- idE(xplicit)
idE : (A : Set) -> A -> A
idE = \(A : Set) -> \(x : A) -> x
{-
apply this “generic” identity function id to a type argument A
to obtain the identity function from A to A
1st use of dependent types: type A -> A depends on variable A : Set
- ranging over the small types
Agda’s notation for dependent function types
- if A is a type and B[x] is a type which depends on (is indexed by) (x : A)
then (x : A) -> B[x] is the type of functions f mapping arguments (x : A) to values f x : B[x].
If the type-checker can figure out value of an arg, can use a wild card character:
id _ x : A
K and S combinators in Agda (uses telescopic notation (A B : Set)
-}
K : (A B : Set) -> A -> B -> A
K _ _ x _ = x
S : (A B C : Set) -> (A -> B -> C) -> (A -> B) -> A -> C
S _ _ _ f g x = f x (g x)
{-
2.4 Implicit Arguments : declared by enclosing typings in curly brackets
-}
id : {A : Set} -> A -> A
id x = x
-- implicit arguments are omitted in applications
_ : id zero PE.≡ zero
_ = PE.refl
-- can explicitly write an implicit argument by using curly brackets if needed
_ : id {Nat} zero PE.≡ zero
_ = PE.refl
_ : id {_} zero PE.≡ zero
_ = PE.refl
{-
2.5 Gödel System T is a subsystem of Agda.
System of primitive recursive functionals [16]
- important in logic and a precursor to Martin-Löf type theory
recursion restricted to primitive recursion : to make sure programs terminate
Gödel System T
- based on simply typed lambda calculus
- with two base types : truth values and natural numbers
- (some formulations code truth values as 0 and 1)
- constants for constructors true, false, zero
- conditional and primitive recursion combinators
-}
-- conditional
if_then_else_ : {C : Set} -> Bool -> C -> C -> C
if true then x else _ = x
if false then _ else y = y
-- primitive recursion combinator for natural numbers
-- natrec is a higher-order function defined by primitive recursion with args
-- - (implicit) return type
-- - c : element returned in base case
-- - 𝕟→c→c : step function
-- - the Nat on which to perform the recursion
natrec : {C : Set} -> C -> (Nat -> C -> C) -> Nat -> C
natrec c 𝕟→c→c zero = c
natrec c 𝕟→c→c (succ n) = 𝕟→c→c n (natrec c 𝕟→c→c n)
-- natrec definitions of addition and multiplication
_plus_ : Nat -> Nat -> Nat
_plus_ n m = natrec m (\x y -> succ y) n
_mult_ : Nat -> Nat -> Nat
_mult_ n m = natrec zero (\x y -> y plus m) n
-- compare plus/mult to _+_/_*_
_ : succ (succ zero) + 2 PE.≡
succ (succ zero + 2)
_ = PE.refl
_ : succ (succ zero + 2) PE.≡
succ (succ (zero + 2))
_ = PE.refl
_ : succ (succ (zero + 2)) PE.≡
succ (succ 2 )
_ = PE.refl
_ : succ (succ zero) plus 2 PE.≡
natrec 2 (\x y -> succ y) (succ (succ zero))
_ = PE.refl
_ : natrec 2 (\x y -> succ y) (succ (succ zero)) PE.≡
(\x y -> succ y) (succ zero) (natrec 2 (\x y -> succ y) (succ zero))
_ = PE.refl
_ : (\x y -> succ y) (succ zero) (natrec 2 (\x y -> succ y) (succ zero)) PE.≡
(\ y -> succ y) (natrec 2 (\x y -> succ y) (succ zero))
_ = PE.refl
_ : (\ y -> succ y) (natrec 2 (\x y -> succ y) (succ zero)) PE.≡
succ (natrec 2 (\x y -> succ y) (succ zero))
_ = PE.refl
_ : succ (natrec 2 (\x y -> succ y) (succ zero)) PE.≡
succ ((\x y -> succ y) zero (natrec 2 (\x y -> succ y) zero))
_ = PE.refl
_ : succ ((\x y -> succ y) zero (natrec 2 (\x y -> succ y) zero)) PE.≡
succ ((\ y -> succ y) (natrec 2 (\x y -> succ y) zero))
_ = PE.refl
_ : succ ((\ y -> succ y) (natrec 2 (\x y -> succ y) zero)) PE.≡
succ ( succ (natrec 2 (\x y -> succ y) zero))
_ = PE.refl
_ : succ ( succ (natrec 2 (\x y -> succ y) zero)) PE.≡
succ ( succ 2 )
_ = PE.refl
{-
to stay entirely in Gödel system T
- use terms built up by variables, application, lambda abstraction,
- and constants true, false, zero, succ, if_then_else_, natrec
Gödel system T has unusual property (for a programming language)
- all typable programs terminate
not only do terms in base types Bool and Nat terminate whatever reduction is chosen,
but also terms of function type terminate
reduction rules
- β-reduction
- defining equations for if_then_else and natrec
reductions can be performed anywhere in a term,
so there may be several ways to reduce a term
therefore, Gödel system T is strongly normalising
- any typable term reaches a normal form whatever reduction strategy is chosen
Even in this restrictive Gödel system T, possible to define many numerical functions.
Can define all primitive recursive functions
(in the usual sense without higher-order functions).
Can also define functions which are not primitive recursive, such as the Ackermann function.
Gödel system T is important in the history of ideas that led to
the Curry-Howard isomorphism and Martin-Löf type theory.
Gödel system T
- is the simply typed kernel of Martin-Löf’s constructive type theory,
Martin-Löf type theory
- is the foundational system from which Agda grew
relationship between Agda and Martin-Löf type theory is much like the
relationship between Haskell and the simply typed lambda calculus.
Or compare it with the relationship between Haskell and Plotkin’s PCF [30].
Like Gödel system T,
PCF is based on the simply typed lambda calculus with truth values and natural numbers.
But PCF includes a fixed point combinator
- used for encoding arbitrary general recursive definitions
- therefore can define non-terminating functions in PCF.
-}
-- Exercise/TODO: Define all functions previously given in the text in Gödel System T.
-- induction principle for booleans (from Mimram)
Bool-rec : (P : Bool → Set) → P false → P true → (b : Bool) → P b
Bool-rec P Pf Pt false = Pf
Bool-rec P Pf Pt true = Pt
not' : Bool -> Bool
not' b = Bool-rec (λ bool → Bool) true false b
_ : not' false PE.≡ not false
_ = PE.refl
_ : not' true PE.≡ not true
_ = PE.refl
equiv' : Bool -> Bool -> Bool
equiv' b false = Bool-rec (λ bool → Bool) true false b
equiv' b true = Bool-rec (λ bool → Bool) false true b
_ : equiv' false false PE.≡ equiv false false
_ = PE.refl
_ : equiv' true false PE.≡ equiv true false
_ = PE.refl
_ : equiv' false true PE.≡ equiv false true
_ = PE.refl
_ : equiv' true true PE.≡ equiv true true
_ = PE.refl
_||'_ : Bool -> Bool -> Bool
b ||' false = Bool-rec (λ bool → Bool) b b b
b ||' true = Bool-rec (λ bool → Bool) (not b) b b
_ : false ||' false PE.≡ false || false
_ = PE.refl
_ : false ||' true PE.≡ false || true
_ = PE.refl
_ : true ||' false PE.≡ true || false
_ = PE.refl
_ : true ||' true PE.≡ true || true
_ = PE.refl
_&&'_ : Bool -> Bool -> Bool
b &&' false = Bool-rec (λ bool → Bool) false false b
b &&' true = Bool-rec (λ bool → Bool) b b b
_ : false &&' false PE.≡ false && false
_ = PE.refl
_ : false &&' true PE.≡ false && true
_ = PE.refl
_ : true &&' false PE.≡ true && false
_ = PE.refl
_ : true &&' true PE.≡ true && true
_ = PE.refl
pred' : Nat -> Nat
pred' zero = natrec zero (\x y -> zero) zero
pred' (succ n) = natrec zero (\_ _ -> n) n
-- test after List def
{-
2.6 Parametrised Types
Haskell parametrised types : [a]
-}
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
infixr 5 _::_
{-# BUILTIN LIST List #-}
{-
(A : Set) to the left of the colon
- tells Agda that A is a parameter
- and it becomes an implicit argument to the constructors:
[] : {A : Set} -> List A
_::_ : {A : Set} -> A -> List A -> List A
def only allows defining lists with elements in arbitrary SMALL types
- cannot define lists of sets using this definition, since sets form a large type
-}
-- test for pred'
_ : (pred' 0 :: pred' 1 :: pred' 2 :: pred' 101 :: []) PE.≡ (pred 0 :: pred 1 :: pred 2 :: pred 101 :: [])
_ = PE.refl
mapL : {A B : Set} -> (A -> B) -> List A -> List B
mapL f [] = []
mapL f (x :: xs) = f x :: mapL f xs
_ : mapL succ (1 :: 2 :: []) PE.≡ (2 :: 3 :: [])
_ = PE.refl
-- Exercise: Define some more list combinators like for example foldl or filter.
filter : {A : Set} -> (A -> Bool) -> List A -> List A
filter f [] = []
filter f (x :: xs) = let tail = filter f xs in if f x then x :: tail else tail
_ : filter (_< 4) (5 :: 4 :: 3 :: 2 :: 1 :: []) PE.≡ (3 :: 2 :: 1 :: [])
_ = PE.refl
foldl : {A B : Set} -> (B -> A -> B) -> B -> List A -> B
foldl _ b [] = b
foldl f b (a :: as) = foldl f (f b a) as
foldr : {A B : Set} -> (A -> B -> B) -> B -> List A -> B
foldr f b [] = b
foldr f b (a :: as) = f a (foldr f b as)
_ : foldl _+_ 0 (3 :: 2 :: 1 :: []) PE.≡ 6
_ = PE.refl
_ : foldl _∸_ 0 (3 :: 1 :: []) PE.≡ 0
_ = PE.refl
_ : foldr _∸_ 0 (3 :: 1 :: []) PE.≡ 2
_ = PE.refl
-- Exercise: define list recursion combinator listrec (like natrec, but for lists)
-- from Mimram
List-rec
: {A : Set}
→ (P : List A → Set)
→ P []
→ ((x : A) → (xs : List A) → P xs → P (x :: xs))
→ (xs : List A)
→ P xs
List-rec P Pe Pc [] = Pe
List-rec P Pe Pc (x :: xs) = Pc x xs (List-rec P Pe Pc xs)
mapL' : {A B : Set} -> (A -> B) -> List A -> List B
mapL' {_} {B} f xs = List-rec (λ _ → List B) [] (λ a _ bs → f a :: bs) xs
_ : mapL' succ (1 :: 2 :: []) PE.≡ mapL succ (1 :: 2 :: [])
_ = PE.refl
filter' : {A : Set} -> (A -> Bool) -> List A -> List A
filter' {A} f xs = List-rec (λ _ → List A) [] (λ a _ as' → if f a then a :: as' else as') xs
_ : filter' (_< 4) (5 :: 4 :: 3 :: 2 :: 1 :: []) PE.≡ filter (_< 4) (5 :: 4 :: 3 :: 2 :: 1 :: [])
_ = PE.refl
foldl' : {A B : Set} -> (B -> A -> B) -> B -> List A -> B
foldl' {_} {B} f b as = List-rec (λ _ → B) b (λ a _ b → f b a) as
_ : foldl' _+_ 0 (3 :: 2 :: 1 :: []) PE.≡ foldl _+_ 0 (3 :: 2 :: 1 :: [])
_ = PE.refl
foldr' : {A B : Set} -> (A -> B -> B) -> B -> List A -> B
foldr' {A} {B} f b as = List-rec (λ _ → B) b (λ a as b → f a b) as
_ : foldr' _∸_ 0 (3 :: 1 :: []) PE.≡ foldr _∸_ 0 (3 :: 1 :: [])
_ = PE.refl
-- binary Cartesian product AKA pair
data _X_ (A B : Set) : Set where
<_,_> : A -> B -> A X B
-- prime because these are never used but are redeinfed later
fst' : {A B : Set} -> A X B -> A
fst' < a , b > = a
snd' : {A B : Set} -> A X B -> B
snd' < a , b > = b
-- Usually want to zip lists of equal length.
-- Can fix that with runtime Maybe or compiletime dependent types (later).
zipL : {A B : Set} -> List A -> List B -> List (A X B)
zipL [] _ = []
zipL (_ :: _) [] = []
zipL (x :: xs) (y :: ys) = < x , y > :: zipL xs ys
-- Exercise: Define the sum A + B of two small types with constructors: inl, inr.
data Either (A B : Set) : Set where
inl : A -> Either A B
inr : B -> Either A B
-- Exercise: Define a function from A + B to a small type C by cases.
toC : {A B C : Set} → (A -> C) -> (B -> C) -> (Either A B) -> C
toC ac _ (inl a) = ac a
toC _ bc (inr b) = bc b
{-
2.7 Termination-checking
General recursion allowed in most languages.
Therefore possible to define "partial" functions (e.g., divide by 0)
How to ensure functions terminate?
- one solution : restrict recursion to primitive recursion (like in Gödel system T)
- the approach taken in Martin-Löf type theory
where primitive recursion as a kind of structural recursion on well-founded data types
(see Martin-Löf’s book [22] and Dybjer’s schema for inductive definitions [10])
- but structural recursion (in one argument at a time) is often inconvenient
Agda’s termination-checker
- generalisation of primitive recursion which is practically useful
- enables doing pattern matching on several arguments simultaneously
- and having recursive calls to structurally smaller arguments
But repeated subtraction is rejected by Agda termination-checker although it is terminating.
Because Agda does not recognise the recursive call to (m - n) as structurally smaller.
Because subtraction is not a constructor for natural numbers.
Further reasoning required to deduce the recursive call is on a smaller argument.
Section 7 : describes how partial and general recursive functions can be represented in Agda.
Idea is to replace a partial function by a total function with an extra argument:
a proof that the function terminates on its arguments.
------------------------------------------------------------------------------
3 Dependent Types
3.1 Vectors of a Given Length
2 ways to define
- Recursive family
- by primitive recursion/induction on n
- Inductive family
- as a family of data types by declaring its constructors and the types of constructors
- like def of List, except length info included in types
paper mostly uses inductive families
--------------------------------------------------
Vectors as a Recursive Family
In math : define vectors by induction on n:
A 0 = 1
A n+1 = A × An
In Agda (and Martin-Löf type theory):
-}
-- type with only one element
data Unit : Set where
<> : Unit
VecR : Set -> Nat -> Set
VecR A zero = Unit
VecR A (succ n) = A X VecR A n
{-
Up till now, only used primitive recursion for defining functions
where the range is in a given set (in a given small type).
Here, primitive recursion used for defining a family of sets
- a family of elements in a given large type.
-}
zipR : {A B : Set} {n : Nat} -> VecR A n -> VecR B n -> VecR (A X B) n
zipR {n = zero} _ _ = <>
zipR {n = succ n'} < a , as > < b , bs > = < < a , b > , zipR {n = n'} as bs >
{-
base case : type-correct since the right hand side has type
VecR (A X B) zero = <>
step case : type-correct since the right hand side has type
VecR (A X B) (succ n) = (A X B) X (VecR (A X B) n)
-}
-- Exercise. Write the functions head, tail, and map for the recursive vectors.
headR : {A : Set} {n : Nat} -> VecR A (succ n) -> A
headR < x , _ > = x
tailR : {A : Set} {n : Nat} -> VecR A (succ n) -> VecR A n
tailR < _ , t > = t
mapR : {A B : Set} {n : Nat} -> (A -> B) -> VecR A n -> VecR B n
mapR {n = zero} _ _ = <>
mapR {n = succ n'} f < a , as > = < f a , mapR {n = n'} f as >
_ : mapR succ < 1 , < 2 , < 0 , <> > > > PE.≡ < 2 , < 3 , < 1 , <> > > >
_ = PE.refl
--------------------------------------------------
-- Vectors as an Inductive Family
data Vec (A : Set) : Nat -> Set where
[] : Vec A zero
_::_ : {n : Nat} -> A -> Vec A n -> Vec A (succ n)
{-
this time no induction on length
instead : constructors generate vectors of different lengths
[] : length 0
:: : length (n + 1)
Definition style called an inductive family, or an inductively defined family of sets.
Terminology comes from constructive type theory,
where data types such as Nat and (List A) are called inductive types.
Remark: Beware of terminological confusion:
- In programming languages one talks about recursive types for such data
types defined by declaring the constructors with their types.
- May be confusing since the word recursive family was used for a different notion.
- Reason for terminological distinction between data types in ordinary functional languages,
and data types in languages where all programs terminate.
- In terminating languages, there will not be any non-terminating numbers or non-terminating lists.
- The set-theoretic meaning of such types is therefore simple:
- build the set inductively generated by the constructors, see [9] for details.
- In non-terminating language, the semantic domains are more complex.
- One typically considers various kinds of Scott domains which are complete partially orders.
(Vec A n) has two args:
- small type A of the elements
- A is a parameter in the sense that it remains the same throughout the definition:
for a given A, define the family Vec A : Nat -> Set
- length n of type Nat.
- n is not a parameter since it varies in the types of the constructors
Non-parameters are often called INDICES
- say that Vec A is an inductive family indexed by natural numbers
In Agda data type definitions
- parameters are placed to the left of the colon
and become implicit arguments to the constructors
- indices are placed to the right
-}
zip : {A B : Set} {n : Nat} -> Vec A n -> Vec B n -> Vec (A X B) n
zip {n = zero} [] [] = []
zip {n = succ n'} (x :: xs) (y :: ys) = < x , y > :: zip {n = n'} xs ys
head : {A : Set} {n : Nat} -> Vec A (succ n) -> A
head (x :: _) = x
tail : {A : Set} {n : Nat} -> Vec A (succ n) -> Vec A n
tail (_ :: xs) = xs
map : {A B : Set} {n : Nat} -> (A -> B) -> Vec A n -> Vec B n
map f [] = []
map f (x :: xs) = f x :: map f xs
--------------------------------------------------
-- 3.2 Finite Sets
data Fin : Nat -> Set where
fzero : {n : Nat} -> Fin (succ n)
fsucc : {n : Nat} -> Fin n -> Fin (succ n)
{-
for each n, Fin n contains n elements
e.g., Fin 3 contains fzero, fsucc fzero and fsucc (fsucc fzero)
useful to access element in a vector
- for Vec A n
- position given by (Fin n)
- ensures accessing an element inside the vector
For empty vector n is zero.
So would use (Fin 0) --- which has no elements.
There is no such case.
Expressed in Agda via "absurd" pattern '()'
-}
_!_ : {A : Set} {n : Nat} -> Vec A n -> Fin n -> A
[] ! ()
(x :: _) ! fzero = x
(_ :: xs) ! fsucc i = xs ! i
-- Exercise: Rewrite the function !! so that it has the following type:
-- This eliminates the empty vector case, but other cases are needed.
_!!_ : {A : Set} {n : Nat} -> Vec A (succ n) -> Fin (succ n) -> A
_!!_ {_} {zero} (a :: f_) fzero = a
_!!_ {_} {succ n} (a :: _) fzero = a
_!!_ {_} {succ n} (_ :: as) (fsucc f) = _!!_ {n = n} as f
_!!'_ : {A : Set} {n : Nat} -> Vec A (succ n) -> Fin (succ n) -> A
_!!'_ (a :: _) fzero = a
_!!'_ {_} {succ n} (_ :: as) (fsucc f) = _!!'_ {n = n} as f
_ : (0 :: 1 :: 2 :: []) ! fsucc fzero PE.≡ 1
_ = PE.refl
_ : (0 :: 1 :: 2 :: []) !! fsucc fzero PE.≡ 1
_ = PE.refl
_ : (0 :: 1 :: 2 :: []) !!' fsucc fzero PE.≡ 1
_ = PE.refl
-- Exercise: Give an alternative definition of Fin as a recursive family.
-- from Conal Eliot https://raw.githubusercontent.com/conal/agda-play/main/DependentTypesAtWork/RecVec.agda
FinR : Nat -> Set
FinR zero = DEP.⊥
FinR (succ n) = Maybe.Maybe (FinR n)
f5 : FinR 5
f5 = Maybe.nothing
f5' : FinR 5 PE.≡ Maybe.Maybe (Maybe.Maybe (Maybe.Maybe (Maybe.Maybe (Maybe.Maybe DEP.⊥))))
f5' = PE.refl
f4 : FinR 4
f4 = Maybe.nothing
f3 : FinR 3
f3 = Maybe.nothing
f2 : FinR 2
f2 = Maybe.nothing
f1 : FinR 1
f1 = Maybe.nothing
f1' : FinR 1 PE.≡ Maybe.Maybe DEP.⊥
f1' = PE.refl
--f0 : FinR 0
--f0 = {!!} -- no solution found
f0' : FinR 0 PE.≡ DEP.⊥
f0' = PE.refl
_!'_ : {A : Set} {n : Nat} → VecR A n → FinR n → A
_!'_ {n = succ m} < a , _ > Maybe.nothing = a
_!'_ {n = succ m} < _ , as > (Maybe.just finm) = as !' finm
_ : < 0 , < 1 , < 2 , <> > > > !' Maybe.nothing PE.≡ 0
_ = PE.refl
_ : < 0 , < 1 , < 2 , <> > > > !' Maybe.just Maybe.nothing PE.≡ 1
_ = PE.refl
_ : < 0 , < 1 , < 2 , <> > > > !' Maybe.just (Maybe.just Maybe.nothing) PE.≡ 2
_ = PE.refl
-- (Maybe.Maybe _A_645) !=< DEP.⊥
-- _ : < 0 , < 1 , < 2 , <> > > > !' Maybe.just (Maybe.just (Maybe.just Maybe.nothing)) PE.≡ 100
-- _ = PE.refl
--------------------------------------------------
-- 3.3 More Inductive Families
-- binary trees of a certain height
-- any given (t : DBTree A n) is a perfectly balanced tree
-- with 2n elements and information in the leaves
data DBTree (A : Set) : Nat -> Set where
leaf : A -> DBTree A zero
node : {n : Nat} -> DBTree A n -> DBTree A n -> DBTree A (succ n)
l1 : DBTree Nat 0
l1 = leaf 1
l2 : DBTree Nat 0
l2 = leaf 2
n1-2 : DBTree Nat 1
n1-2 = node l1 l2
l3 : DBTree Nat 0
l3 = leaf 3
l4 : DBTree Nat 0
l4 = leaf 4
n3-4 : DBTree Nat 1
n3-4 = node l3 l4
n1-2-3-4 : DBTree Nat 2
n1-2-3-4 = node n1-2 n3-4
-- Exercise/TODO: Modify DBTree def to define the height balanced binary trees
-- i.e., binary trees where difference between heights of left and right subtree is at most one.
-- Exercise/TODO: Define lambda terms as an inductive family
-- indexed by the maximal number of free variables allowed in the term.
-- Exercise/TODO: define typed lambda terms as an inductive family indexed by the type of the term.
{-
------------------------------------------------------------------------------
Curry, 1930’s : one-to-one correspondence between propositions in propositional logic and types.
1960’s de Bruijn and Howard introduced dependent types to extend Curry’s correspondence to predicate logic.
Scott [31] and Martin-Löf [20], correspondence became building block of foundation for constructive math:
- Martin-Löf’s intuitionistic type theory.
Will now show how intuitionistic predicate logic with equality is a subsystem of
Martin-Löf type theory by realising it as a theory in Agda.
4.1 Propositional Logic
isomorphism : each proposition is interpreted as the set of its proofs.
To emphazie PROOFS here are FIRST-CLASS mathematical object, say PROOF OBJECTS.
aka : CONSTRUCTIONS
proposition
- is true IFF its set of proofs is inhabited
- it is false iff its set of proofs is empty
-}
-- CONJUNCTION (aka AND)
-- A and B are two propositions represented by their sets of proofs.
-- A & B is also a set of proofs, representing the conjunction of A and B.
-- Note : conjunction is same as Cartesian product of two sets.
-- applying & constructor is &-introduction
data _&_ (A B : Set) : Set where
<_,_> : A -> B -> A & B
-- alternate def
_&'_ : Set -> Set -> Set
A &' B = A X B
-- two rules of &-elimination
-- rules state that if A & B is true then A and B are also true
fst : {A B : Set} -> A & B -> A
fst < a , _ > = a
snd : {A B : Set} -> A & B -> B
snd < _ , b > = b
sndP : {A B : Set} -> A &' B -> B
sndP < _ , b > = b
-- DISJUNCTION (aka OR)
-- disjunction corresponds to disjoint union
data _\/_ (A B : Set) : Set where
inl : A -> A \/ B
inr : B -> A \/ B
-- alternate def
_\/'_ : Set -> Set -> Set
A \/' B = Either A B
-- rule of \/-elimination is case analysis for a disjoint union
case : {A B C : Set} -> A \/ B -> (A -> C) -> (B -> C) -> C
case (inl a) d e = d a
case (inr b) d e = e b
-- proposition which is always true
-- corresponds to the unit set (see page 14) according to Curry-Howard:
data True : Set where
<> : True
-- proposition False is the proposition that is false by definition
-- corresponds to the the empty set according to Curry-Howard.
-- This is the set which is defined by stating that it has no canonical elements.
-- sometimes referred as the “absurdity” set and denoted by ⊥
data False : Set where
-- rule of ⊥-elimination states that if False has been proved, then can prove any proposition A.
-- Can only happen by starting with contradictory assumptions.
nocase : {A : Set} -> False -> A
nocase () -- tells agda no cases to consider
{-
Justification of this rule is same as justification of existence of
an empty function from the empty set into an arbitrary set.
Since the empty set has no elements there is nothing to define; it is definition by no cases.
Recall the explanation on page 16 when we used the notation ().
-}
-- In constructive logic
-- - proving negation of a proposition is the same as
-- - proving the proposition leads to absurdity:
Not : Set -> Set
Not A = A -> False
{-
BHK-interpretation says an implication is proved by providing a method for transforming
a proof of A into a proof of B.
When Brouwer pioneered this 100 years ago, there were no computers and no models of computation.
In contemporary constructive mathematics in general, and in Martin-Löf type theory in particular,
a “method” is usually understood as a computable function (or computer program) which transforms proofs.
Implication is defined as function space.
Emphasized via new notation:
-}
_==>_ : (A B : Set) -> Set
A ==> B = A -> B
_ : False ==> False -- T
_ = λ ()
_ : False ==> True -- T
_ = λ ()
_ : True ==> False -- F
_ = λ _ → {!!}
_ : True ==> True -- T
_ = λ _ → <>
{-
Above def not accepted in Martin-Löf’s version of propositions-as-sets.
Because each proposition should be defined by stating what its canonical proofs are.
A canonical proof should always begin with a constructor.
A function in A -> B does not, unless one considers the lambda-sign as a constructor.
Instead, Martin-Löf defines implication as a set with one constructor:
Using this, a canonical proof of A ==>' B always begins with the constructor fun.
-}
data _==>'_ (A B : Set) : Set where
fun : (A -> B) -> A ==>' B
-- rule of ==>-elimination (modus ponens)
apply : {A B : Set} -> A ==>' B -> A -> B
apply (fun f) a = f a
-- equivalence of propositions
_<==>_ : Set -> Set -> Set
A <==> B = (A ==> B) & (B ==> A)
_ : False <==> False
_ = < ( λ () ) , ( λ () ) >
_ : False <==> True
_ = < (λ () ) , (λ { <> → {!!}}) >
_ : True <==> False
_ = < (λ { <> → {!!}}) , (λ () ) >
_ : True <==> True
_ = < (λ _ → <>) , (λ _ → <>) >
{-
Exercise/TODO: Prove your favourite tautology from propositional logic.
Beware that you will not be able to prove the law of the excluded middle A \/ Not A.
This is a consequence of the definition of disjunction, can you explain why?.
The law of the excluded middle is not available in intuitonistic logic, only in classical logic.
-}
le : ∀ {P Q : Set} → (P ==> Q) <==> (Not P \/ Q)
le {P} {Q} = < (λ {P==>Q → {!!} }) , (λ { (inl NotP) p → {!!} ; (inr q) p → q}) >
| 34.055028
| 107
| 0.62601
|
10e8f90d8d74f16d43a01cd75daa2e6f142c4216
| 617
|
agda
|
Agda
|
test/Succeed/Test4687.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Test4687.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Test4687.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Primitive
open import Agda.Builtin.List
open import Agda.Builtin.Maybe
data Coercible (A : Set) (B : Set) : Set where
TrustMe : Coercible A B
postulate coerce : {A B : Set} {{_ : Coercible A B}} → A → B
instance
coerce-fun : {A B : Set} {{_ : Coercible A B}}
→ {C D : Set} {{_ : Coercible C D}}
→ Coercible (B → C) (A → D)
coerce-fun = TrustMe
coerce-refl : {A : Set} → Coercible A A
coerce-refl = TrustMe
postulate
primCatMaybes : {A : Set} → List (Maybe A) → List A
catMaybes : {A : Set} → List (Maybe A) → List A
catMaybes = coerce (primCatMaybes {_})
| 24.68
| 60
| 0.60778
|
1d0dc9bffcde1f2466e2b0dcd55810408de6b61d
| 965
|
agda
|
Agda
|
Cubical/HITs/Rationals/HITQ/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Rationals/HITQ/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/HITs/Rationals/HITQ/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Rationals.HITQ.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Relation.Nullary
open import Cubical.HITs.Ints.QuoInt
open import Cubical.Data.Nat as ℕ hiding (_·_)
open import Cubical.Data.NatPlusOne
open import Cubical.Data.Sigma
-- ℚ as a higher inductive type
data ℚ : Type₀ where
con : (u : ℤ) (a : ℤ) → ¬ (a ≡ pos 0) → ℚ
path : ∀ u a v b {p q} → (u · b) ≡ (v · a) → con u a p ≡ con v b q
trunc : isSet ℚ
[_] : ℤ × ℕ₊₁ → ℚ
[ a , 1+ b ] = con a (pos (suc b)) (ℕ.snotz ∘ cong abs)
-- Natural number and negative integer literals for ℚ
open import Cubical.Data.Nat.Literals public
instance
fromNatℚ : HasFromNat ℚ
fromNatℚ = record { Constraint = λ _ → Unit ; fromNat = λ n → [ pos n , 1 ] }
instance
fromNegℚ : HasFromNeg ℚ
fromNegℚ = record { Constraint = λ _ → Unit ; fromNeg = λ n → [ neg n , 1 ] }
| 26.081081
| 79
| 0.662176
|
c51ff8f647e1390819c6c6e15cf7ecb74c60c87b
| 187
|
agda
|
Agda
|
test/Succeed/Issue1109.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1109.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1109.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2014-05-02 Negative fixities allow now.
module _ where
infix -1 _+_
infix 0 _*_
postulate
_+_ : Set1 → Set2 → Set1
_*_ : Set2 → Set2 → Set2
test = Set + Set1 * Set1
| 14.384615
| 52
| 0.636364
|
1a088d46445671efd86022bcd99bd7065dd0f168
| 299
|
agda
|
Agda
|
src/Human/Equality.agda
|
MaisaMilena/AgdaCalculator
|
e977a5f2a005682cee123568b49462dd7d7b11ad
|
[
"MIT"
] | 1
|
2019-03-29T02:30:10.000Z
|
2019-03-29T02:30:10.000Z
|
src/Human/Equality.agda
|
MaisaMilena/AgdaCalculator
|
e977a5f2a005682cee123568b49462dd7d7b11ad
|
[
"MIT"
] | null | null | null |
src/Human/Equality.agda
|
MaisaMilena/AgdaCalculator
|
e977a5f2a005682cee123568b49462dd7d7b11ad
|
[
"MIT"
] | null | null | null |
module Human.Equality where
data _==_ {A : Set} (x : A) : A -> Set where
refl : x == x
{-# BUILTIN EQUALITY _==_ #-}
sym : {A : Set} (x : A) (y : A) -> x == y -> y == x
sym x .x refl = refl
cong : {A : Set} {B : Set} (x : A) (y : A) (f : A -> B) -> x == y -> f x == f y
cong x y f refl = refl
| 23
| 79
| 0.454849
|
22c98666f8c3dc390041636fec687fbc9c552380
| 580
|
agda
|
Agda
|
out/Empty/Signature.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 39
|
2021-11-09T20:39:55.000Z
|
2022-03-19T17:33:12.000Z
|
out/Empty/Signature.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 1
|
2021-11-21T12:19:32.000Z
|
2021-11-21T12:19:32.000Z
|
out/Empty/Signature.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 4
|
2021-11-09T20:39:59.000Z
|
2022-01-24T12:49:17.000Z
|
{-
This second-order signature was created from the following second-order syntax description:
syntax Empty | E
type
𝟘 : 0-ary
term
abort : 𝟘 -> α
theory
(𝟘η) e : 𝟘 c : α |> abort(e) = c
-}
module Empty.Signature where
open import SOAS.Context
-- Type declaration
data ET : Set where
𝟘 : ET
open import SOAS.Syntax.Signature ET public
open import SOAS.Syntax.Build ET public
-- Operator symbols
data Eₒ : Set where
abortₒ : {α : ET} → Eₒ
-- Term signature
E:Sig : Signature Eₒ
E:Sig = sig λ
{ (abortₒ {α}) → (⊢₀ 𝟘) ⟼₁ α
}
open Signature E:Sig public
| 14.5
| 91
| 0.667241
|
4d069d3b10beb1f0b58008d3800cd378a715c8b3
| 779
|
agda
|
Agda
|
agda-stdlib/src/Data/Nat/Reflection.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Nat/Reflection.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Nat/Reflection.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Reflection utilities for ℕ
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Reflection where
open import Data.Nat.Base as ℕ
open import Data.Fin.Base as Fin
open import Data.List.Base using ([])
open import Reflection.Term
open import Reflection.Argument
------------------------------------------------------------------------
-- Term
toTerm : ℕ → Term
toTerm zero = con (quote ℕ.zero) []
toTerm (suc i) = con (quote ℕ.suc) (toTerm i ⟨∷⟩ [])
toFinTerm : ℕ → Term
toFinTerm zero = con (quote Fin.zero) (1 ⋯⟅∷⟆ [])
toFinTerm (suc i) = con (quote Fin.suc) (1 ⋯⟅∷⟆ toFinTerm i ⟨∷⟩ [])
| 28.851852
| 72
| 0.473684
|
319696614f10c369f4d3a87d64609b941dc95686
| 585
|
agda
|
Agda
|
test/Succeed/Issue1450.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1450.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1450.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
postulate
F : (Set → Set) → Set
!_ : Set → Set
!_,_ : Set → Set → Set
X : Set
syntax F (λ X → A) = X , A
infix 1 F
infix 2 !_
Foo : Set
Foo = ! X , X
-- This expression can be parsed in exactly one way. However, Agda
-- rejects it:
--
-- Expected variable name in binding position
--
-- The error is thrown from pure code in rebuildBinding, and this
-- action circumvents the parser logic.
--
-- The error was introduced in the fix for Issue 1129, and the problem
-- raised in Issue 1129 was introduced in a fix for Issue 1108
-- ("Operator parser performance").
| 22.5
| 70
| 0.65641
|
dfc259d8225004a0c184636d6d8fa4287f22410f
| 4,376
|
agda
|
Agda
|
examples/instance-arguments/13-implicitProofObligations.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2019-11-27T04:41:05.000Z
|
2019-11-27T04:41:05.000Z
|
examples/instance-arguments/13-implicitProofObligations.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
examples/instance-arguments/13-implicitProofObligations.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --universe-polymorphism #-}
module 13-implicitProofObligations where
module Imports where
module L where
postulate
Level : Set
zero : Level
suc : Level → Level
_⊔_ : Level → Level → Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO zero #-}
{-# BUILTIN LEVELSUC suc #-}
{-# BUILTIN LEVELMAX _⊔_ #-}
-- extract from Data.Unit
record ⊤ : Set where
constructor tt
-- extract from Data.Empty
data ⊥ : Set where
⊥-elim : ∀ {w} {Whatever : Set w} → ⊥ → Whatever
⊥-elim ()
-- extract from Function
id : ∀ {a} {A : Set a} → A → A
id x = x
_$_ : ∀ {a b} {A : Set a} {B : A → Set b} →
((x : A) → B x) → ((x : A) → B x)
f $ x = f x
_∘_ : ∀ {a b c}
{A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ∘ g = λ x → f (g x)
-- extract from Data.Bool
data Bool : Set where
true : Bool
false : Bool
not : Bool → Bool
not true = false
not false = true
T : Bool → Set
T true = ⊤
T false = ⊥
-- extract from Relation.Nullary.Decidable and friends
infix 3 ¬_
¬_ : ∀ {ℓ} → Set ℓ → Set ℓ
¬ P = P → ⊥
data Dec {p} (P : Set p) : Set p where
yes : ( p : P) → Dec P
no : (¬p : ¬ P) → Dec P
⌊_⌋ : ∀ {p} {P : Set p} → Dec P → Bool
⌊ yes _ ⌋ = true
⌊ no _ ⌋ = false
False : ∀ {p} {P : Set p} → Dec P → Set
False Q = T (not ⌊ Q ⌋)
-- extract from Relation.Binary.PropositionalEquality
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
cong : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
_≢_ : ∀ {a} {A : Set a} → A → A → Set a
x ≢ y = ¬ x ≡ y
-- extract from Data.Nat
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
{-# BUILTIN NATURAL ℕ #-}
{-# BUILTIN ZERO zero #-}
{-# BUILTIN SUC suc #-}
pred : ℕ → ℕ
pred zero = zero
pred (suc n) = n
infixl 6 _+_
_+_ : ℕ → ℕ → ℕ
-- zero + n = n
-- suc m + n = suc (m + n)
zero + n = n
suc m + n = suc (m + n)
_*_ : ℕ → ℕ → ℕ
zero * n = zero
suc m * n = n + m * n
_≟_ : (x y : ℕ) → Dec (x ≡ y)
zero ≟ zero = yes refl
suc m ≟ suc n with m ≟ n
suc m ≟ suc .m | yes refl = yes refl
suc m ≟ suc n | no prf = no (prf ∘ cong pred)
zero ≟ suc n = no λ()
suc m ≟ zero = no λ()
-- extract from Data.Fin
data Fin : ℕ → Set where
zero : {n : ℕ} → Fin (suc n)
suc : {n : ℕ} (i : Fin n) → Fin (suc n)
-- A conversion: toℕ "n" = n.
toℕ : ∀ {n} → Fin n → ℕ
toℕ zero = 0
toℕ (suc i) = suc (toℕ i)
-- extract from Data.Product
record Σ {a b} (A : Set a) (B : A → Set b) : Set (a L.⊔ b) where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
_×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a L.⊔ b)
A × B = Σ A (λ (_ : A) → B)
-- extract from Data.Nat.DivMod
data DivMod : ℕ → ℕ → Set where
result : {divisor : ℕ} (q : ℕ) (r : Fin divisor) →
DivMod (toℕ r + q * divisor) divisor
data DivMod' (dividend divisor : ℕ) : Set where
result : (q : ℕ) (r : Fin divisor)
(eq : dividend ≡ (toℕ r + q * divisor)) →
DivMod' dividend divisor
postulate
_div_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → ℕ
_divMod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod dividend divisor
_divMod'_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod' dividend divisor
open Imports
-- Begin of actual example!
postulate
d : ℕ
d≢0 : d ≢ 0
-- d≢0' : d ≢ 0
fromWitnessFalse : ∀ {p} {P : Set p} {Q : Dec P} → ¬ P → False Q
fromWitnessFalse {Q = yes p} ¬P = ⊥-elim $ ¬P p
fromWitnessFalse {Q = no ¬p} ¬P = tt
⋯ : {A : Set} → {{v : A}} → A
⋯ {{v}} = v
_divMod′_ : (dividend divisor : ℕ) {{ ≢0 : divisor ≢ 0 }} → ℕ × ℕ
_divMod′_ a d {{_}} with _divMod_ a d { fromWitnessFalse ⋯ }
._ divMod′ d | (result q r) = q , toℕ r
_div′_ : (dividend divisor : ℕ) {{ ≢0 : divisor ≢ 0 }} → ℕ
_div′_ a b {{_}} with a divMod′ b
a div′ b | (q , _) = q
--Agda can't resolve hiddens
-- test : {d≢0 : False (d ≟ 0)} → ℕ
-- test = 5 div d
-- test2 : {{d≢0 : d ≢ 0}} → ℕ
-- test2 = 5 div′ d
test3 = 5 div 2
test4 = 5 div′ 2
where nz : 2 ≢ 0
nz ()
| 23.153439
| 67
| 0.48149
|
58fd14861092bce37bc6823ada5a24db427d7b9b
| 372
|
agda
|
Agda
|
prototyping/FFI/Data/Maybe.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | 1
|
2022-03-18T04:10:20.000Z
|
2022-03-18T04:10:20.000Z
|
prototyping/FFI/Data/Maybe.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
prototyping/FFI/Data/Maybe.agda
|
JohnnyMorganz/luau
|
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
|
[
"MIT"
] | null | null | null |
module FFI.Data.Maybe where
open import Agda.Builtin.Equality using (_≡_; refl)
{-# FOREIGN GHC import qualified Data.Maybe #-}
data Maybe (A : Set) : Set where
nothing : Maybe A
just : A → Maybe A
{-# COMPILE GHC Maybe = data Data.Maybe.Maybe (Data.Maybe.Nothing|Data.Maybe.Just) #-}
just-inv : ∀ {A} {x y : A} → (just x ≡ just y) → (x ≡ y)
just-inv refl = refl
| 24.8
| 86
| 0.650538
|
3d3182f0fccd7f6d9fc741a869f7083e8ba92e93
| 257
|
agda
|
Agda
|
test/Fail/Issue2758b.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2758b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2758b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --experimental-irrelevance #-}
open import Agda.Builtin.Bool
data Box (A : Set) : ..(x : A) → Set where
c : (x : A) → Box A x
unbox : {A : Set} → .(x : A) → Box A x → A
unbox a (c b) = b
postulate
.b : Bool
b' : Bool
b' = unbox b (c _)
| 16.0625
| 42
| 0.536965
|
59035d50ceec4ed5a208605a7728f901b1a37783
| 39
|
agda
|
Agda
|
Structure/Topology/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Structure/Topology/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Structure/Topology/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Structure.Topology.Proofs where
| 19.5
| 38
| 0.871795
|
29c0f50481276b7c34edd3832a3dd0990aec811b
| 307
|
agda
|
Agda
|
test/Common/Size.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | null | null | null |
test/Common/Size.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | null | null | null |
test/Common/Size.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
------------------------------------------------------------------------
-- From the Agda standard library
--
-- Sizes for Agda's sized types
------------------------------------------------------------------------
module Common.Size where
open import Agda.Builtin.Size public
| 27.909091
| 72
| 0.37785
|
a18feb3bfc3e2f6b7410ed8b97baf02286935875
| 17,514
|
agda
|
Agda
|
imper-repeat.agda
|
JimFixGroupResearch/imper-ial
|
80d9411b2869614cae488cd4a6272894146c9f3c
|
[
"MIT"
] | null | null | null |
imper-repeat.agda
|
JimFixGroupResearch/imper-ial
|
80d9411b2869614cae488cd4a6272894146c9f3c
|
[
"MIT"
] | null | null | null |
imper-repeat.agda
|
JimFixGroupResearch/imper-ial
|
80d9411b2869614cae488cd4a6272894146c9f3c
|
[
"MIT"
] | null | null | null |
module imper-repeat where
open import lib
open import eq-reasoning
data Singleton {a} {A : Set a} (x : A) : Set a where
_with≡_ : (y : A) → x ≡ y → Singleton x
inspect : ∀ {a} {A : Set a} (x : A) → Singleton x
inspect x = x with≡ refl
-- Unicode notes. I use:
-- \Mix, \Mie, \MiF etc for meta-variables 𝑥, 𝑒, 𝐹 etc.
-- \mapsto for variable frame bindings and update.
-- \| for the frame update operation.
-- \|- turnstile ⊢ is used for the semantics relations.
-- (\|-n for its negation ⊬)
-- \d= for code literal values e.g. ⇓ 42 and ⇓true
-- The down arrow is also used for the eval relation.
-- \u= for code variable lookups like ⇑ "x" and ⇑ "y"
-- superscripts of items with \^e as ᵉ, \c^c as ᶜ
-- ↩ for sequencing. This is \lefthookarrow.
-- ∷= which is \:: followed by =
--
-- variable identifiers
--
Id : Set
Id = string
_=Id_ : Id → Id → 𝔹
_=Id_ = _=string_
--
-- values (just natural numbers here)
--
Val : Set
Val = ℕ
--
-- value and variable expressions
--
data Expn : Set where
⇓_ : Val → Expn
⇑_ : Id → Expn
_+ᵉ_ : Expn → Expn → Expn
_-ᵉ_ : Expn → Expn → Expn
_*ᵉ⇓_ : Expn → Val → Expn
--
-- conditions on values and variables
--
data Cond : Set where
⇓true : Cond
⇓false : Cond
_∧ᶜ_ : Cond → Cond → Cond
_∨ᶜ_ : Cond → Cond → Cond
¬ᶜ_ : Cond → Cond
[_<ᶜ_] : Expn → Expn → Cond
[_=ᶜ_] : Expn → Expn → Cond
--
-- stack frames containing variable bindings
--
Frm : Set
Frm = 𝕃 (Id × Val)
[_↦_] : Id → Val → Frm
[ 𝑥 ↦ 𝑣 ] = [(𝑥 , 𝑣)]
[-↦0] : Frm
[-↦0] = []
--
-- program statements that transform a frame
--
data Stmt : Set where
skip : Stmt
_∷=_ : Id → Expn → Stmt
_↩_ : Stmt → Stmt → Stmt
if_then_else_end : Cond → Stmt → Stmt → Stmt
by_repeat_end : Id → Stmt → Stmt
returns_ : Expn → Stmt
infix 10 ⇑_ ⇓_
infix 9 _*ᵉ⇓_
infixl 8 _+ᵉ_ _-ᵉ_
infix 7 ¬ᶜ_
infixl 6 _∨ᶜ_
infixl 5 _∧ᶜ_
infix 4 _∷=_
infix 3 returns_
infixl 2 _↩_
--
-- functional SEMANTICS of frames
--
_∥_ : Frm → Id → Val
[] ∥ 𝑥 = 0
((𝑦 , 𝑤) :: 𝐹) ∥ 𝑥 = if (𝑥 =Id 𝑦) then 𝑤 else (𝐹 ∥ 𝑥)
_∣_↦_ : Frm → Id → Val → Frm
[] ∣ 𝑥 ↦ 𝑣 = [ 𝑥 ↦ 𝑣 ]
((𝑦 , 𝑤) :: 𝐹) ∣ 𝑥 ↦ 𝑣
= if (𝑥 =Id 𝑦)
then (𝑦 , 𝑣) :: 𝐹
else (𝑦 , 𝑤) :: (𝐹 ∣ 𝑥 ↦ 𝑣)
--
-- functional SEMANTICS of expressions
--
⟦_⟧ᵉ_ : Expn → Frm → Val
⟦ ⇓ 𝑣 ⟧ᵉ _ = 𝑣
⟦ ⇑ 𝑥 ⟧ᵉ 𝐹 = 𝐹 ∥ 𝑥
⟦ 𝑒₁ +ᵉ 𝑒₂ ⟧ᵉ 𝐹 = (⟦ 𝑒₁ ⟧ᵉ 𝐹) + (⟦ 𝑒₂ ⟧ᵉ 𝐹)
⟦ 𝑒₁ -ᵉ 𝑒₂ ⟧ᵉ 𝐹 = (⟦ 𝑒₁ ⟧ᵉ 𝐹) ∸ (⟦ 𝑒₂ ⟧ᵉ 𝐹)
⟦ 𝑒₁ *ᵉ⇓ 𝑣₂ ⟧ᵉ 𝐹 = (⟦ 𝑒₁ ⟧ᵉ 𝐹) * 𝑣₂
--
-- functional SEMANTICS of conditions
--
⟦_⟧ᶜ_ : Cond → Frm → 𝔹
⟦ ⇓true ⟧ᶜ _ = tt
⟦ ⇓false ⟧ᶜ _ = ff
⟦ 𝒸₁ ∧ᶜ 𝒸₂ ⟧ᶜ 𝐹 = (⟦ 𝒸₁ ⟧ᶜ 𝐹) && (⟦ 𝒸₂ ⟧ᶜ 𝐹)
⟦ 𝒸₁ ∨ᶜ 𝒸₂ ⟧ᶜ 𝐹 = (⟦ 𝒸₁ ⟧ᶜ 𝐹) || (⟦ 𝒸₂ ⟧ᶜ 𝐹)
⟦ ¬ᶜ 𝒸 ⟧ᶜ 𝐹 = ~ (⟦ 𝒸 ⟧ᶜ 𝐹)
⟦ [ 𝑒₁ <ᶜ 𝑒₂ ] ⟧ᶜ 𝐹 = (⟦ 𝑒₁ ⟧ᵉ 𝐹) < (⟦ 𝑒₂ ⟧ᵉ 𝐹)
⟦ [ 𝑒₁ =ᶜ 𝑒₂ ] ⟧ᶜ 𝐹 = (⟦ 𝑒₁ ⟧ᵉ 𝐹) =ℕ (⟦ 𝑒₂ ⟧ᵉ 𝐹)
--
-- functional SEMANTICS of program execution
--
⟦_∣_∷=_…0⟧ˢ_ : Stmt → Id → ℕ → Frm → Frm
⟦_⟧ˢ_ : Stmt → Frm → Frm
⟦ 𝑠 ∣ 𝑥 ∷= 0 …0⟧ˢ 𝐹 = 𝐹
⟦ 𝑠 ∣ 𝑥 ∷= (suc 𝑛) …0⟧ˢ 𝐹
= ⟦ 𝑠 ∣ 𝑥 ∷= 𝑛 …0⟧ˢ ((⟦ 𝑠 ⟧ˢ 𝐹) ∣ 𝑥 ↦ 𝑛)
⟦ skip ⟧ˢ 𝐹 = 𝐹
⟦ 𝑥 ∷= 𝑒 ⟧ˢ 𝐹 = (𝐹 ∣ 𝑥 ↦ (⟦ 𝑒 ⟧ᵉ 𝐹))
⟦ 𝑠₁ ↩ 𝑠₂ ⟧ˢ 𝐹 = (⟦ 𝑠₂ ⟧ˢ (⟦ 𝑠₁ ⟧ˢ 𝐹))
⟦ if 𝒸 then 𝑠₁ else 𝑠₂ end ⟧ˢ 𝐹 = if (⟦ 𝒸 ⟧ᶜ 𝐹) then (⟦ 𝑠₁ ⟧ˢ 𝐹) else (⟦ 𝑠₂ ⟧ˢ 𝐹)
⟦ by 𝑥 repeat 𝑠 end ⟧ˢ 𝐹 = ⟦ 𝑠 ∣ 𝑥 ∷= (⟦ ⇑ 𝑥 ⟧ᵉ 𝐹) …0⟧ˢ 𝐹
⟦ returns 𝑒 ⟧ˢ 𝐹 = 𝐹 ∣ "retval" ↦ (⟦ 𝑒 ⟧ᵉ 𝐹)
--
-- SEMANTICS of stack bindings as a relation
--
infixl 7 _⊢ᶠ_↦_
infixl 5 _∣_↦_
infixl 4 _⊢ᵉ_⇓_
infixl 3 _⊢ᶜ_ _⊬ᶜ_ -- _↦_
data _⊢ᶠ_↦_ : Frm → Id → Val → Set where
var-undef : ∀ {𝑥 : Id}
----------------
→ [] ⊢ᶠ 𝑥 ↦ 0
var-match : ∀ {𝑥 𝑦 : Id} {𝐹 : Frm} {𝑤 : Val}
→ (𝑥 =string 𝑦) ≡ tt
---------------------------
→ ((𝑦 , 𝑤) :: 𝐹) ⊢ᶠ 𝑥 ↦ 𝑤
var-mismatch : ∀ {𝑥 𝑦 : Id} {𝐹 : Frm} {𝑣 𝑤 : Val}
→ (𝑥 =string 𝑦) ≡ ff
→ 𝐹 ⊢ᶠ 𝑥 ↦ 𝑣
-------------------------
→ ((𝑦 , 𝑤) :: 𝐹) ⊢ᶠ 𝑥 ↦ 𝑣
if-tt-then : ∀{A : Set} {b : 𝔹} {a1 a2 : A}
→ b ≡ tt → if b then a1 else a2 ≡ a1
if-tt-then{A}{b}{a1}{a2} b≡tt =
begin
if b then a1 else a2
≡⟨ cong3 if_then_else_ b≡tt refl refl ⟩
if tt then a1 else a2
≡⟨ refl ⟩
a1
∎
postulate
if-ff-then : ∀{A : Set}{b : 𝔹}{a1 a2 : A}
→ b ≡ ff → if b then a1 else a2 ≡ a2
var-thm-fwd : ∀{x : Id}{F : Frm}{v : Val}
→ F ⊢ᶠ x ↦ v → F ∥ x ≡ v
var-thm-fwd{x}{[]}{0} var-undef =
begin
[] ∥ x
≡⟨ refl ⟩
0
∎
var-thm-fwd (var-match{x}{y}{F}{w} x≡y) =
begin
((y , w) :: F) ∥ x
≡⟨ refl ⟩
if (x =Id y) then w else (F ∥ x)
≡⟨ if-tt-then x≡y ⟩
w
∎
var-thm-fwd (var-mismatch{x}{y}{F}{v}{w} x≢y x↦v) =
let
F∥x≡v : F ∥ x ≡ v
F∥x≡v = var-thm-fwd x↦v
in begin
((y , w) :: F) ∥ x
≡⟨ refl ⟩
if (x =Id y) then w else (F ∥ x)
≡⟨ if-ff-then x≢y ⟩
F ∥ x
≡⟨ F∥x≡v ⟩
v
∎
var-thm-rev : ∀{x : Id}{F : Frm}{v : Val}
→ F ∥ x ≡ v → F ⊢ᶠ x ↦ v
var-thm-rev{x}{[]}{v} []∥x≡v =
let v≡0 : v ≡ 0
v≡0 = begin
v
≡⟨ sym []∥x≡v ⟩
[] ∥ x
≡⟨ refl ⟩
0
∎
in cong-pred (λ xxx → [] ⊢ᶠ x ↦ xxx) (sym v≡0) var-undef
var-thm-rev{x}{(y , w) :: F}{v} y,w::F∥x≡v
with inspect (x =string y)
... | tt with≡ same =
let v≡w : v ≡ w
v≡w = begin
v
≡⟨ sym y,w::F∥x≡v ⟩
((y , w) :: F) ∥ x
≡⟨ refl ⟩
if x =string y then w else F ∥ x
≡⟨ cong3 if_then_else_ same refl refl ⟩
if tt then w else F ∥ x
≡⟨ refl ⟩
w
∎
in cong-pred (λ xxx → ((y , w) :: F) ⊢ᶠ x ↦ xxx) (sym v≡w) (var-match same)
... | ff with≡ diff =
let v≡F∥x : v ≡ F ∥ x
v≡F∥x = begin
v
≡⟨ sym y,w::F∥x≡v ⟩
((y , w) :: F) ∥ x
≡⟨ refl ⟩
if x =string y then w else F ∥ x
≡⟨ cong3 if_then_else_ diff refl refl ⟩
if ff then w else F ∥ x
≡⟨ refl ⟩
F ∥ x
∎
in (var-mismatch diff (var-thm-rev (sym v≡F∥x)))
--
-- SEMANTICS of expression evaluation as a relation
--
data _⊢ᵉ_⇓_ : Frm → Expn → Val → Set where
e-val : ∀ {𝑣 : Val} {𝐹 : Frm}
----------------
→ 𝐹 ⊢ᵉ (⇓ 𝑣) ⇓ 𝑣
e-var : ∀ {𝑥 : Id} {𝐹 : Frm} {𝑣 : Val}
→ 𝐹 ⊢ᶠ 𝑥 ↦ 𝑣
---------------
→ 𝐹 ⊢ᵉ (⇑ 𝑥) ⇓ 𝑣
e-add : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val}
→ 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁
→ 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂
---------------------------
→ 𝐹 ⊢ᵉ (𝑒₁ +ᵉ 𝑒₂) ⇓ (𝑣₁ + 𝑣₂)
e-sub : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val}
→ 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁
→ 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂
---------------------------
→ 𝐹 ⊢ᵉ (𝑒₁ -ᵉ 𝑒₂) ⇓ (𝑣₁ ∸ 𝑣₂)
e-scale : ∀ {𝑒₁ : Expn} {𝑣₁ 𝑣₂ : Val} {𝐹 : Frm}
→ 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁
---------------------------
→ 𝐹 ⊢ᵉ ( 𝑒₁ *ᵉ⇓ 𝑣₂) ⇓ (𝑣₁ * 𝑣₂)
e-thm-fwd : ∀{𝑒 : Expn}{𝐹 : Frm}{𝑣 : Val}
→ (𝐹 ⊢ᵉ 𝑒 ⇓ 𝑣) → ((⟦ 𝑒 ⟧ᵉ 𝐹) ≡ 𝑣)
e-thm-fwd (e-val{v}{F}) =
begin
⟦ ⇓ v ⟧ᵉ F
≡⟨ refl ⟩
v
∎
e-thm-fwd (e-var{x}{F}{v} x↦v) =
begin
⟦ ⇑ x ⟧ᵉ F
≡⟨ var-thm-fwd x↦v ⟩
v
∎
e-thm-fwd (e-add{e1}{e2}{F}{v1}{v2} e1⇓v1 e2⇓v2) =
let
⟦e1⟧≡v1 = e-thm-fwd e1⇓v1
⟦e2⟧≡v2 = e-thm-fwd e2⇓v2
in begin
⟦ e1 +ᵉ e2 ⟧ᵉ F
≡⟨ refl ⟩
⟦ e1 ⟧ᵉ F + ⟦ e2 ⟧ᵉ F
≡⟨ cong2 _+_ ⟦e1⟧≡v1 ⟦e2⟧≡v2 ⟩
v1 + v2
∎
e-thm-fwd (e-sub{e1}{e2}{F}{v1}{v2} e1⇓v1 e2⇓v2) =
let
⟦e1⟧≡v1 = e-thm-fwd e1⇓v1
⟦e2⟧≡v2 = e-thm-fwd e2⇓v2
in begin
⟦ e1 -ᵉ e2 ⟧ᵉ F
≡⟨ refl ⟩
⟦ e1 ⟧ᵉ F ∸ ⟦ e2 ⟧ᵉ F
≡⟨ cong2 _∸_ ⟦e1⟧≡v1 ⟦e2⟧≡v2 ⟩
v1 ∸ v2
∎
e-thm-fwd (e-scale{e1}{v1}{v2}{F} e1⇓v1) =
let
⟦e1⟧≡v1 = e-thm-fwd e1⇓v1
in begin
⟦ e1 *ᵉ⇓ v2 ⟧ᵉ F
≡⟨ refl ⟩
⟦ e1 ⟧ᵉ F * v2
≡⟨ cong2 _*_ ⟦e1⟧≡v1 refl ⟩
v1 * v2
∎
e-thm-rev : ∀{𝑒 : Expn}{𝐹 : Frm}{𝑣 : Val}
→ ((⟦ 𝑒 ⟧ᵉ 𝐹) ≡ 𝑣) → (𝐹 ⊢ᵉ 𝑒 ⇓ 𝑣)
e-thm-rev{e}{F}{v} ⟦e⟧F≡v
with e
... | ⇓ w = cong-pred (λ xxx → F ⊢ᵉ (⇓ w) ⇓ xxx) ⟦e⟧F≡v e-val
... | ⇑ x = let v≡F∥x : v ≡ F ∥ x
v≡F∥x = begin
v
≡⟨ sym ⟦e⟧F≡v ⟩
⟦ ⇑ x ⟧ᵉ F
≡⟨ refl ⟩
F ∥ x
∎
in e-var (var-thm-rev (sym v≡F∥x))
... | e1 +ᵉ e2 = {!!}
... | e1 -ᵉ e2 = {!!}
... | e1 *ᵉ⇓ v2 = {!!}
--
-- SEMANTICS of conditions as a decidable relation
--
data _⊢ᶜ_ : Frm → Cond → Set
data _⊬ᶜ_ : Frm → Cond → Set
data _⊢ᶜ_ where
c-tt : ∀ {𝐹 : Frm}
-----------
→ 𝐹 ⊢ᶜ ⇓true
c-and : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm}
→ 𝐹 ⊢ᶜ 𝒸₁
→ 𝐹 ⊢ᶜ 𝒸₂
-----------------
→ 𝐹 ⊢ᶜ (𝒸₁ ∧ᶜ 𝒸₂)
c-or₁ : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm}
→ 𝐹 ⊢ᶜ 𝒸₁
---------------
→ 𝐹 ⊢ᶜ (𝒸₁ ∨ᶜ 𝒸₂)
c-or₂ : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm}
→ 𝐹 ⊢ᶜ 𝒸₂
----------------
→ 𝐹 ⊢ᶜ (𝒸₁ ∨ᶜ 𝒸₂)
c-less : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val}
→ 𝑣₁ < 𝑣₂ ≡ tt
→ 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁
→ 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂
-------------------
→ 𝐹 ⊢ᶜ [ 𝑒₁ <ᶜ 𝑒₂ ]
c-eq : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val}
→ 𝑣₁ =ℕ 𝑣₂ ≡ tt
→ 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁
→ 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂
-------------------
→ 𝐹 ⊢ᶜ [ 𝑒₁ =ᶜ 𝑒₂ ]
c-not : ∀ {𝒸 : Cond} {𝐹 : Frm}
→ 𝐹 ⊬ᶜ 𝒸
-------------
→ 𝐹 ⊢ᶜ (¬ᶜ 𝒸)
data _⊬ᶜ_ where
~c-ff : ∀ {𝐹 : Frm}
--------------
→ 𝐹 ⊬ᶜ ⇓false
~c-or : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm}
→ 𝐹 ⊬ᶜ 𝒸₁
→ 𝐹 ⊬ᶜ 𝒸₂
----------------
→ 𝐹 ⊬ᶜ (𝒸₁ ∨ᶜ 𝒸₂)
~c-and₁ : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm}
→ 𝐹 ⊬ᶜ 𝒸₁
-----------------
→ 𝐹 ⊬ᶜ (𝒸₁ ∧ᶜ 𝒸₂)
~c-and₂ : ∀ {𝒸₁ 𝒸₂ : Cond} {𝐹 : Frm}
→ 𝐹 ⊬ᶜ 𝒸₂
-----------------
→ 𝐹 ⊬ᶜ (𝒸₁ ∧ᶜ 𝒸₂)
~c-eq : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val}
→ 𝑣₁ =ℕ 𝑣₂ ≡ ff
→ 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁
→ 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂
-------------------
→ 𝐹 ⊬ᶜ [ 𝑒₁ =ᶜ 𝑒₂ ]
~c-less : ∀ {𝑒₁ 𝑒₂ : Expn} {𝐹 : Frm} {𝑣₁ 𝑣₂ : Val}
→ 𝑣₁ < 𝑣₂ ≡ ff
→ 𝐹 ⊢ᵉ 𝑒₁ ⇓ 𝑣₁
→ 𝐹 ⊢ᵉ 𝑒₂ ⇓ 𝑣₂
-------------------
→ 𝐹 ⊬ᶜ [ 𝑒₁ <ᶜ 𝑒₂ ]
~c-not : ∀ {𝒸 : Cond} {𝐹 : Frm}
→ 𝐹 ⊢ᶜ 𝒸
-------------
→ 𝐹 ⊬ᶜ (¬ᶜ 𝒸)
test3 : [] ⊢ᶜ (⇓true ∧ᶜ (¬ᶜ ⇓false))
test3 = c-and c-tt (c-not ~c-ff)
c-thm-fwd : ∀{𝒸 : Cond}{𝐹 : Frm} → 𝐹 ⊢ᶜ 𝒸 → (⟦ 𝒸 ⟧ᶜ 𝐹 ≡ tt)
~c-thm-fwd : ∀{𝒸 : Cond}{𝐹 : Frm} → 𝐹 ⊬ᶜ 𝒸 → (⟦ 𝒸 ⟧ᶜ 𝐹 ≡ ff)
c-thm-fwd (c-tt{F}) =
begin
⟦ ⇓true ⟧ᶜ F
≡⟨ refl ⟩
tt
∎
c-thm-fwd (c-and{c1}{c2}{F} dat1 dat2) =
let
⟦c1⟧F≡tt : ⟦ c1 ⟧ᶜ F ≡ tt
⟦c1⟧F≡tt = c-thm-fwd dat1
⟦c2⟧F≡tt : ⟦ c2 ⟧ᶜ F ≡ tt
⟦c2⟧F≡tt = c-thm-fwd dat2
in begin
⟦ c1 ∧ᶜ c2 ⟧ᶜ F
≡⟨ refl ⟩
(⟦ c1 ⟧ᶜ F) && (⟦ c2 ⟧ᶜ F)
≡⟨ cong2 _&&_ ⟦c1⟧F≡tt ⟦c2⟧F≡tt ⟩
tt && tt
≡⟨ refl ⟩
tt
∎
c-thm-fwd (c-or₁{c1}{c2}{F} dat1) =
let
⟦c1⟧F≡tt : ⟦ c1 ⟧ᶜ F ≡ tt
⟦c1⟧F≡tt = c-thm-fwd dat1
in begin
⟦ c1 ∨ᶜ c2 ⟧ᶜ F
≡⟨ refl ⟩
(⟦ c1 ⟧ᶜ F) || (⟦ c2 ⟧ᶜ F)
≡⟨ cong2 _||_ ⟦c1⟧F≡tt refl ⟩
tt || (⟦ c2 ⟧ᶜ F)
≡⟨ refl ⟩
tt
∎
c-thm-fwd (c-or₂{c1}{c2}{F} dat2) =
let
⟦c2⟧F≡tt : ⟦ c2 ⟧ᶜ F ≡ tt
⟦c2⟧F≡tt = c-thm-fwd dat2
in begin
⟦ c1 ∨ᶜ c2 ⟧ᶜ F
≡⟨ refl ⟩
(⟦ c1 ⟧ᶜ F) || (⟦ c2 ⟧ᶜ F)
≡⟨ cong2 _||_ refl ⟦c2⟧F≡tt ⟩
(⟦ c1 ⟧ᶜ F) || tt
≡⟨ ||-tt (⟦ c1 ⟧ᶜ F) ⟩
tt
∎
c-thm-fwd (c-less{e1}{e2}{F}{v1}{v2} v1<v2 e1⇓v1 e2⇓v2) =
let
⟦e1⟧F≡v1 : ⟦ e1 ⟧ᵉ F ≡ v1
⟦e1⟧F≡v1 = e-thm-fwd e1⇓v1
⟦e2⟧F≡v2 : ⟦ e2 ⟧ᵉ F ≡ v2
⟦e2⟧F≡v2 = e-thm-fwd e2⇓v2
in
begin
⟦ [ e1 <ᶜ e2 ] ⟧ᶜ F
≡⟨ refl ⟩
⟦ e1 ⟧ᵉ F < ⟦ e2 ⟧ᵉ F
≡⟨ cong2 _<_ ⟦e1⟧F≡v1 ⟦e2⟧F≡v2 ⟩
v1 < v2
≡⟨ v1<v2 ⟩
tt
∎
c-thm-fwd (c-eq{e1}{e2}{F}{v1}{v2} v1≡v2 e1⇓v1 e2⇓v2) =
let
⟦e1⟧F≡v1 : ⟦ e1 ⟧ᵉ F ≡ v1
⟦e1⟧F≡v1 = e-thm-fwd e1⇓v1
⟦e2⟧F≡v2 : ⟦ e2 ⟧ᵉ F ≡ v2
⟦e2⟧F≡v2 = e-thm-fwd e2⇓v2
in begin
⟦ [ e1 =ᶜ e2 ] ⟧ᶜ F
≡⟨ refl ⟩
⟦ e1 ⟧ᵉ F =ℕ ⟦ e2 ⟧ᵉ F
≡⟨ cong2 _=ℕ_ ⟦e1⟧F≡v1 ⟦e2⟧F≡v2 ⟩
v1 =ℕ v2
≡⟨ v1≡v2 ⟩
tt
∎
c-thm-fwd (c-not{c}{F} dat) =
let
⟦c⟧F≡ff : ⟦ c ⟧ᶜ F ≡ ff
⟦c⟧F≡ff = ~c-thm-fwd dat
in begin
begin
⟦ ¬ᶜ c ⟧ᶜ F
≡⟨ refl ⟩
~ ⟦ c ⟧ᶜ F
≡⟨ cong ~_ ⟦c⟧F≡ff ⟩
~ ff
≡⟨ refl ⟩
tt
∎
~c-thm-fwd (~c-ff{F}) =
begin
⟦ ⇓false ⟧ᶜ F
≡⟨ refl ⟩
ff
∎
~c-thm-fwd (~c-or{c1}{c2}{F} dat1 dat2) =
let
⟦c1⟧F≡ff : ⟦ c1 ⟧ᶜ F ≡ ff
⟦c1⟧F≡ff = ~c-thm-fwd dat1
⟦c2⟧F≡ff : ⟦ c2 ⟧ᶜ F ≡ ff
⟦c2⟧F≡ff = ~c-thm-fwd dat2
in begin
⟦ c1 ∨ᶜ c2 ⟧ᶜ F
≡⟨ refl ⟩
(⟦ c1 ⟧ᶜ F) || (⟦ c2 ⟧ᶜ F)
≡⟨ cong2 _||_ ⟦c1⟧F≡ff ⟦c2⟧F≡ff ⟩
ff || ff
≡⟨ refl ⟩
ff
∎
~c-thm-fwd (~c-and₁{c1}{c2}{F} dat1) =
let
⟦c1⟧F≡ff : ⟦ c1 ⟧ᶜ F ≡ ff
⟦c1⟧F≡ff = ~c-thm-fwd dat1
in begin
⟦ c1 ∧ᶜ c2 ⟧ᶜ F
≡⟨ refl ⟩
(⟦ c1 ⟧ᶜ F) && (⟦ c2 ⟧ᶜ F)
≡⟨ cong2 _&&_ ⟦c1⟧F≡ff refl ⟩
ff && (⟦ c2 ⟧ᶜ F)
≡⟨ refl ⟩
ff
∎
~c-thm-fwd (~c-and₂{c1}{c2}{F} dat2) =
let
⟦c2⟧F≡ff : ⟦ c2 ⟧ᶜ F ≡ ff
⟦c2⟧F≡ff = ~c-thm-fwd dat2
in begin
begin
⟦ c1 ∧ᶜ c2 ⟧ᶜ F
≡⟨ refl ⟩
(⟦ c1 ⟧ᶜ F) && (⟦ c2 ⟧ᶜ F)
≡⟨ cong2 _&&_ refl ⟦c2⟧F≡ff ⟩
(⟦ c1 ⟧ᶜ F) && ff
≡⟨ &&-ff (⟦ c1 ⟧ᶜ F) ⟩
ff
∎
~c-thm-fwd (~c-less{e1}{e2}{F}{v1}{v2} v1≮v2 e1⇓v1 e2⇓v2) =
let
⟦e1⟧F≡v1 : ⟦ e1 ⟧ᵉ F ≡ v1
⟦e1⟧F≡v1 = e-thm-fwd e1⇓v1
⟦e2⟧F≡v2 : ⟦ e2 ⟧ᵉ F ≡ v2
⟦e2⟧F≡v2 = e-thm-fwd e2⇓v2
in
begin
⟦ [ e1 <ᶜ e2 ] ⟧ᶜ F
≡⟨ refl ⟩
⟦ e1 ⟧ᵉ F < ⟦ e2 ⟧ᵉ F
≡⟨ cong2 _<_ ⟦e1⟧F≡v1 ⟦e2⟧F≡v2 ⟩
v1 < v2
≡⟨ v1≮v2 ⟩
ff
∎
~c-thm-fwd (~c-eq{e1}{e2}{F}{v1}{v2} v1≢v2 e1⇓v1 e2⇓v2) =
let
⟦e1⟧F≡v1 : ⟦ e1 ⟧ᵉ F ≡ v1
⟦e1⟧F≡v1 = e-thm-fwd e1⇓v1
⟦e2⟧F≡v2 : ⟦ e2 ⟧ᵉ F ≡ v2
⟦e2⟧F≡v2 = e-thm-fwd e2⇓v2
in begin
⟦ [ e1 =ᶜ e2 ] ⟧ᶜ F
≡⟨ refl ⟩
⟦ e1 ⟧ᵉ F =ℕ ⟦ e2 ⟧ᵉ F
≡⟨ cong2 _=ℕ_ ⟦e1⟧F≡v1 ⟦e2⟧F≡v2 ⟩
v1 =ℕ v2
≡⟨ v1≢v2 ⟩
ff
∎
~c-thm-fwd (~c-not{c}{F} ⊢c) =
begin
⟦ ¬ᶜ c ⟧ᶜ F
≡⟨ refl ⟩
~ ⟦ c ⟧ᶜ F
≡⟨ cong ~_ (c-thm-fwd ⊢c) ⟩
~ tt
≡⟨ refl ⟩
ff
∎
-- These can probably be shown just by using
-- the contrapositives of c-thm-fwd and ~c-thm-fwd
postulate
c-thm-rev : ∀{𝒸 : Cond}{𝐹 : Frm} → (⟦ 𝒸 ⟧ᶜ 𝐹 ≡ tt) → 𝐹 ⊢ᶜ 𝒸
~c-thm-rev : ∀{𝒸 : Cond}{𝐹 : Frm} → (⟦ 𝒸 ⟧ᶜ 𝐹 ≡ ff) → 𝐹 ⊬ᶜ 𝒸
--
-- SEMANTICS of program statements
-- as a state transformation relation
--
data _=[_]⇒_ : Frm → Stmt → Frm → Set where
s-skip : ∀ {𝐹 : Frm}
--------------
→ 𝐹 =[ skip ]⇒ 𝐹
s-assign : ∀ {𝑥 : Id} {𝑒 : Expn} {𝐹 : Frm} {𝑣 : Val}
→ 𝐹 ⊢ᵉ 𝑒 ⇓ 𝑣
---------------------------
→ 𝐹 =[ 𝑥 ∷= 𝑒 ]⇒ (𝐹 ∣ 𝑥 ↦ 𝑣)
s-seq : ∀ {𝑠₁ 𝑠₂ : Stmt} {𝐹₀ 𝐹₁ 𝐹₂ : Frm}
→ 𝐹₀ =[ 𝑠₁ ]⇒ 𝐹₁
→ 𝐹₁ =[ 𝑠₂ ]⇒ 𝐹₂
-------------------
→ 𝐹₀ =[ 𝑠₁ ↩ 𝑠₂ ]⇒ 𝐹₂
s-if-then : ∀ {𝒸 : Cond} {𝑠₁ 𝑠₂ : Stmt} {𝐹 𝐹' : Frm}
→ 𝐹 ⊢ᶜ 𝒸
→ 𝐹 =[ 𝑠₁ ]⇒ 𝐹'
→ 𝐹 =[ 𝑠₂ ]⇒ 𝐹'
------------------------------------
→ 𝐹 =[ if 𝒸 then 𝑠₁ else 𝑠₂ end ]⇒ 𝐹'
s-if-else : ∀ {𝒸 : Cond} {𝑠₁ 𝑠₂ : Stmt} {𝐹 𝐹' : Frm}
→ 𝐹 ⊬ᶜ 𝒸
→ 𝐹 =[ 𝑠₂ ]⇒ 𝐹'
------------------------------------
→ 𝐹 =[ if 𝒸 then 𝑠₁ else 𝑠₂ end ]⇒ 𝐹'
s-repeat-0 : ∀ {𝑠 : Stmt} {𝑥 : Id} {𝐹 : Frm}
→ 𝐹 ⊢ᶠ 𝑥 ↦ 0
-----------------------------
→ 𝐹 =[ by 𝑥 repeat 𝑠 end ]⇒ 𝐹
s-repeat-suc : ∀ {𝑛 : ℕ} {𝑠 : Stmt} {𝑥 : Id} {𝐹 𝐹' : Frm}
→ 𝐹 ⊢ᶠ 𝑥 ↦ suc 𝑛
→ 𝐹 =[ 𝑠 ↩ 𝑥 ∷= (⇓ 𝑛) ↩ by 𝑥 repeat 𝑠 end ]⇒ 𝐹'
----------------------------------------------
→ 𝐹 =[ by 𝑥 repeat 𝑠 end ]⇒ 𝐹'
--
-- A lil cheat: "returns" is just assign; doesn't exit
s-return : ∀ {𝑒 : Expn} {𝐹 : Frm} {𝑣 : Val}
→ 𝐹 ⊢ᵉ 𝑒 ⇓ 𝑣
-------------------------------------
→ 𝐹 =[ returns 𝑒 ]⇒ (𝐹 ∣ "retval" ↦ 𝑣)
arg1 : Id
arg1 = "arg1"
arg2 : Id
arg2 = "arg2"
retval : Id
retval = "retval"
W : Id
W = "w"
X : Id
X = "x"
Y : Id
Y = "y"
Z : Id
Z = "z"
pgm0 : Stmt
pgm0 = X ∷= ⇓ 3 ↩
Y ∷= ⇓ 1 ↩
Y ∷= ⇑ Y *ᵉ⇓ 2
pgm1 : Stmt
pgm1 = X ∷= ⇓ 3 ↩
Y ∷= ⇓ 1 ↩
by X repeat
Y ∷= ⇑ Y *ᵉ⇓ 2
end
Z∷=X*Y = W ∷= ⇑ X ↩
Z ∷= ⇓ 0 ↩
by W repeat
Z ∷= ⇑ Z +ᵉ ⇑ Y
end
pgm2 = X ∷= ⇓ 3 ↩
Y ∷= ⇓ 1 ↩
by X repeat
Z∷=X*Y ↩
Y ∷= ⇑ Z
end
fact-pgm : Stmt
fact-pgm =
X ∷= ⇑ arg1 ↩
Y ∷= ⇓ 1 ↩
by X repeat
Z∷=X*Y ↩
Y ∷= ⇑ Z
end ↩
returns ⇑ Y
min-pgm : Stmt
min-pgm = if [ ⇑ arg2 <ᶜ ⇑ arg1 ] then
X ∷= ⇑ arg1 ↩
arg1 ∷= ⇑ arg2 ↩
arg2 ∷= ⇑ X
else
skip
end
result1 = ⟦ pgm1 ⟧ˢ [-↦0]
result2 = ⟦ pgm2 ⟧ˢ [-↦0]
[➊↦_] : Val → Frm
[➊↦ 𝑣 ] = [-↦0] ∣ arg1 ↦ 𝑣
[➊↦_,➋↦_] : Val → Val → Frm
[➊↦ 𝑣₁ ,➋↦ 𝑣₂ ] = (([-↦0] ∣ arg1 ↦ 𝑣₁) ∣ arg2 ↦ 𝑣₂ )
frame6 = ((((( [➊↦ 3 ] ∣ X ↦ 0) ∣ Y ↦ 6) ∣ W ↦ 0) ∣ Z ↦ 6) ∣ retval ↦ 6)
postulate
test6 : [➊↦ 3 ] =[ fact-pgm ]⇒ frame6
exec : Stmt → Frm
exec 𝑠 = ⟦ 𝑠 ⟧ˢ [-↦0]
exec1 : Stmt → Val → Frm
exec1 𝑠 𝑣₁ = ⟦ 𝑠 ⟧ˢ [➊↦ 𝑣₁ ]
exec2 : Stmt → Val → Val → Frm
exec2 𝑠 𝑣₁ 𝑣₂ = ⟦ 𝑠 ⟧ˢ [➊↦ 𝑣₁ ,➋↦ 𝑣₂ ]
test7 = exec2 min-pgm 7 5
test7a : (test7 ∥ arg1) ≡ 5
test7a = refl
test7b : (test7 ∥ arg2) ≡ 7
test7b = refl
postulate
s-thm : ∀ {𝑠 : Stmt } {𝐹 : Frm} → 𝐹 =[ 𝑠 ]⇒ (⟦ 𝑠 ⟧ˢ 𝐹)
postulate
fact-thm : ∀ {n : ℕ} {𝐹 : Frm} → [➊↦ n ] =[ fact-pgm ]⇒ 𝐹 → 𝐹 ⊢ᶠ retval ↦ (factorial n)
| 21.837905
| 89
| 0.387119
|
2fb28ffbdb36790a362f71cf3256beef70af1922
| 7,349
|
agda
|
Agda
|
src/Section6.agda
|
mietek/coquand
|
7c000654c4f97024d2939c412702f64dc821d4ec
|
[
"X11"
] | 4
|
2017-03-27T01:29:58.000Z
|
2017-09-07T12:44:40.000Z
|
src/Section6.agda
|
mietek/coquand
|
7c000654c4f97024d2939c412702f64dc821d4ec
|
[
"X11"
] | null | null | null |
src/Section6.agda
|
mietek/coquand
|
7c000654c4f97024d2939c412702f64dc821d4ec
|
[
"X11"
] | null | null | null |
module Section6 where
open import Section5 public
-- 6. Application to terms
-- =======================
--
-- In practice we may not want to work with proof trees but rather well-typed terms. As an
-- application of the results above we show how to give semantics to a formulation of Martin-
-- Löf’s substitution calculus [13, 20] in the simply typed setting. In this calculus we have a
-- set of untyped terms, `𝕋`, and we define when a term in `𝕋` is well-typed and when two terms
-- of a given type are convertible with each other.
--
-- In order to give semantics to untyped terms, we first define an erasure function that
-- translates a proof tree `M` to an untyped term, denoted `M ⁻`. The main theorem is then to prove
-- that if two proof trees `M, N` erase to the same term, `M ⁻ ≡ N ⁻`, then `M ≅ N`; it follows that
-- `M` and `N` have the same semantics. For this we first prove that `nf M ⁻ ≡ nf N ⁻` implies
-- `M ≅ N`. We also define a reduction on the untyped terms `Γ ⊢ t₁ ⇓ t₂ ∷ A` that is deterministic
-- (i.e., if `Γ ⊢ t ⇓ t₁ ∷ A` and `Γ ⊢ t ⇓ t₂ ∷ A`, then `t₁ ≡ t₂`) such that `Γ ⊢ M ⁻ ⇓ nf M ⁻ ∷ A`.
-- We then prove that if a proof tree `M` erases to a well-typed term `t`, then `t ⇓ nf M ⁻`. Now,
-- if two proof trees `M` and `N` erase to the same well-typed term `t`, then `t ⇓ nf M ⁻` and
-- `t ⇓ nf N ⁻`. Since the reduction is deterministic we have that `nf M ⁻` and `nf N ⁻` are the
-- same, and hence `M ≅ N`. The idea of this proof comes from Streicher [19] (chapter IV).
-- 6.1. Definition of terms
-- ------------------------
--
-- We mutually define the set of terms, `𝕋 : Set`, and substitutions, `𝕊 : Set`. (…)
mutual
data 𝕋 : Set where
ν : Name → 𝕋
ƛ : Name → 𝕋 → 𝕋
_∙_ : 𝕋 → 𝕋 → 𝕋
_▶_ : 𝕋 → 𝕊 → 𝕋
data 𝕊 : Set where
[] : 𝕊
[_,_≔_] : 𝕊 → Name → 𝕋 → 𝕊
_●_ : 𝕊 → 𝕊 → 𝕊
-- 6.2. Typing rules
-- -----------------
--
-- We give the typing rules for terms and substitutions mutually inductively. (…)
mutual
infix 3 _⊢_∷_
data _⊢_∷_ : 𝒞 → 𝕋 → 𝒯 → Set where
↑⟨_⟩⊢∷ : ∀ {Γ Δ A t} →
Γ ⊇ Δ → Δ ⊢ t ∷ A →
Γ ⊢ t ∷ A
ν : ∀ {Γ A} →
(x : Name) → Γ ∋ x ∷ A →
Γ ⊢ ν x ∷ A
ƛ : ∀ {Γ A B t} →
(x : Name) {{_ : T (fresh x Γ)}} → [ Γ , x ∷ A ] ⊢ t ∷ B →
Γ ⊢ ƛ x t ∷ A ⊃ B
_∙_ : ∀ {Γ A B t₁ t₂} →
Γ ⊢ t₁ ∷ A ⊃ B → Γ ⊢ t₂ ∷ A →
Γ ⊢ t₁ ∙ t₂ ∷ B
_▶_ : ∀ {Γ Δ A s t} →
Δ ⊢ t ∷ A → Γ ⋙ s ∷ Δ →
Γ ⊢ t ▶ s ∷ A
infix 3 _⋙_∷_
data _⋙_∷_ : 𝒞 → 𝕊 → 𝒞 → Set where
↑⟨_⟩⋙∷ : ∀ {Γ Δ Θ s} →
Θ ⊇ Γ → Γ ⋙ s ∷ Δ →
Θ ⋙ s ∷ Δ
↓⟨_⟩⋙∷ : ∀ {Γ Δ Θ s} →
Δ ⊇ Θ → Γ ⋙ s ∷ Δ →
Γ ⋙ s ∷ Θ
refl⋙∷ : ∀ {Γ} →
Γ ⋙ [] ∷ Γ
[_,_≔_] : ∀ {Γ Δ A s t} →
Γ ⋙ s ∷ Δ → (x : Name) {{_ : T (fresh x Δ)}} → Γ ⊢ t ∷ A →
Γ ⋙ [ s , x ≔ t ] ∷ [ Δ , x ∷ A ]
_●_ : ∀ {Γ Δ Θ s₁ s₂} →
Δ ⋙ s₂ ∷ Θ → Γ ⋙ s₁ ∷ Δ →
Γ ⋙ s₂ ● s₁ ∷ Θ
module _ where
instance
raise⊢∷ : ∀ {A t} → Raiseable (_⊢ t ∷ A)
raise⊢∷ = record { ↑⟨_⟩ = ↑⟨_⟩⊢∷ }
raise⋙∷ : ∀ {Γ s} → Raiseable (_⋙ s ∷ Γ)
raise⋙∷ = record { ↑⟨_⟩ = ↑⟨_⟩⋙∷ }
lower⋙∷ : ∀ {Δ s} → Lowerable (Δ ⋙ s ∷_)
lower⋙∷ = record { ↓⟨_⟩ = ↓⟨_⟩⋙∷ }
-- 6.3. Convertibility of terms
-- ----------------------------
--
-- We mutually inductively define when two terms are convertible with each other together
-- with the definition of convertibility between substitutions. (…)
mutual
infix 3 _⊢_≊_∷_
data _⊢_≊_∷_ : 𝒞 → 𝕋 → 𝕋 → 𝒯 → Set where
refl≊ : ∀ {Γ A t} →
Γ ⊢ t ≊ t ∷ A
sym≊ : ∀ {Γ A t t′} →
Γ ⊢ t ≊ t′ ∷ A →
Γ ⊢ t′ ≊ t ∷ A
trans≊ : ∀ {Γ A t t′ t″} →
Γ ⊢ t ≊ t′ ∷ A → Γ ⊢ t′ ≊ t″ ∷ A →
Γ ⊢ t ≊ t″ ∷ A
congƛ≊ : ∀ {Γ A B t t′ x} {{_ : T (fresh x Γ)}} →
[ Γ , x ∷ A ] ⊢ t ≊ t′ ∷ B →
Γ ⊢ ƛ x t ≊ ƛ x t′ ∷ A ⊃ B
cong∙≊ : ∀ {Γ A B t t′ u u′} →
Γ ⊢ t ≊ t′ ∷ A ⊃ B → Γ ⊢ u ≊ u′ ∷ A →
Γ ⊢ t ∙ u ≊ t′ ∙ u′ ∷ B
cong▶≊ : ∀ {Γ Δ A t t′ s s′} →
Γ ⊢ t ≊ t′ ∷ A → Δ ⋙ s ≊ₛ s′ ∷ Γ →
Γ ⊢ t ▶ s ≊ t′ ▶ s′ ∷ A
conv₁≊ : ∀ {Γ A t} →
Γ ⊢ t ∷ A →
Γ ⊢ t ≊ t ∷ A
conv₂≊ : ∀ {Γ Δ A B s t₁ t₂ x} {{_ : T (fresh x Δ)}} →
Γ ⋙ s ∷ Δ → [ Δ , x ∷ A ] ⊢ t₁ ∷ B → Γ ⊢ t₂ ∷ A →
Γ ⊢ (ƛ x t₁ ▶ s) ∙ t₂ ≊ t₁ ▶ [ s , x ≔ t₂ ] ∷ B
conv₃≊ : ∀ {Γ A B t x} {{_ : T (fresh x Γ)}} →
Γ ⊢ t ∷ A ⊃ B →
Γ ⊢ t ≊ ƛ x (t ∙ ν x) ∷ A ⊃ B
conv₄≊ : ∀ {Γ Δ A t₁ t₂} →
Γ ⊇ Δ → Δ ⊢ t₁ ≊ t₂ ∷ A →
Γ ⊢ t₁ ≊ t₂ ∷ A
conv₅≊ : ∀ {Γ Δ A s t x} {{_ : T (fresh x Δ)}} →
Γ ⋙ s ∷ Δ → Γ ⊢ t ∷ A →
Γ ⊢ ν x ▶ [ s , x ≔ t ] ≊ t ∷ A
conv₆≊ : ∀ {Γ A t} →
Γ ⊢ t ∷ A →
Γ ⊢ t ▶ [] ≊ t ∷ A
conv₇≊ : ∀ {Γ Δ A B s t₁ t₂} →
Δ ⊢ t₁ ∷ A ⊃ B → Δ ⊢ t₂ ∷ A → Γ ⋙ s ∷ Δ →
Γ ⊢ (t₁ ∙ t₂) ▶ s ≊ (t₁ ▶ s) ∙ (t₂ ▶ s) ∷ B
conv₈≊ : ∀ {Γ₁ Γ₂ Γ₃ A s₁ s₂ t} →
Γ₂ ⋙ s₁ ∷ Γ₃ → Γ₁ ⋙ s₂ ∷ Γ₂ → Γ₃ ⊢ t ∷ A →
Γ₁ ⊢ (t ▶ s₁) ▶ s₂ ≊ t ▶ (s₁ ● s₂) ∷ A
data _⋙_≊ₛ_∷_ : 𝒞 → 𝕊 → 𝕊 → 𝒞 → Set where
refl≊ₛ : ∀ {Γ Δ s} →
Δ ⋙ s ≊ₛ s ∷ Γ
sym≊ₛ : ∀ {Γ Δ s s′} →
Δ ⋙ s ≊ₛ s′ ∷ Γ →
Δ ⋙ s′ ≊ₛ s ∷ Γ
trans≊ₛ : ∀ {Γ Δ s s′ s″} →
Δ ⋙ s ≊ₛ s′ ∷ Γ → Δ ⋙ s′ ≊ₛ s″ ∷ Γ →
Δ ⋙ s ≊ₛ s″ ∷ Γ
cong≔≊ₛ : ∀ {Γ Δ A s s′ t t′ x} {{_ : T (fresh x Δ)}} →
Γ ⋙ s ≊ₛ s′ ∷ Δ → Γ ⊢ t ≊ t′ ∷ A →
Γ ⋙ [ s , x ≔ t ] ≊ₛ [ s′ , x ≔ t′ ] ∷ [ Δ , x ∷ A ]
cong●≊ₛ : ∀ {Γ Δ Θ s₁ s₁′ s₂ s₂′} →
Δ ⋙ s₂ ≊ₛ s₂′ ∷ Θ → Γ ⋙ s₁ ≊ₛ s₁′ ∷ Δ →
Γ ⋙ s₂ ● s₁ ≊ₛ s₂′ ● s₁′ ∷ Θ
conv₁≊ₛ : ∀ {Γ₁ Γ₂ Δ s₁ s₂} →
Γ₁ ⊇ Γ₂ → Γ₂ ⋙ s₁ ≊ₛ s₂ ∷ Δ →
Γ₁ ⋙ s₁ ≊ₛ s₂ ∷ Δ
conv₂≊ₛ : ∀ {Γ Δ₁ Δ₂ s₁ s₂} →
Δ₁ ⊇ Δ₂ → Γ ⋙ s₁ ≊ₛ s₂ ∷ Δ₁ →
Γ ⋙ s₁ ≊ₛ s₂ ∷ Δ₂
conv₃≊ₛ : ∀ {Γ Δ s} →
Γ ⋙ s ∷ Δ →
Γ ⋙ s ● [] ≊ₛ s ∷ Δ
conv₄≊ₛ : ∀ {Γ₁ Γ₂ Γ₃ Δ s₁ s₂ s₃} →
Γ₁ ⋙ s₃ ∷ Γ₂ → Γ₂ ⋙ s₂ ∷ Γ₃ → Γ₃ ⋙ s₁ ∷ Δ →
Γ₃ ⋙ (s₁ ● s₂) ● s₃ ≊ₛ s₁ ● (s₂ ● s₃) ∷ Δ
conv₅≊ₛ : ∀ {Γ₁ Γ₂ Δ A s₁ s₂ t x} {{_ : T (fresh x Δ)}} →
Γ₁ ⋙ s₂ ∷ Γ₂ → Γ₂ ⋙ s₁ ∷ Δ → Γ₂ ⊢ t ∷ A →
Γ₁ ⋙ [ s₁ , x ≔ t ] ● s₂ ≊ₛ [ s₁ ● s₂ , x ≔ t ▶ s₂ ] ∷ [ Δ , x ∷ A ]
conv₆≊ₛ : ∀ {Γ s} →
Γ ⋙ s ∷ [] →
Γ ⋙ s ≊ₛ [] ∷ []
conv₇≊ₛ : ∀ {Γ Δ A s x} {{_ : T (fresh x Δ)}} →
Γ ⋙ s ∷ [ Δ , x ∷ A ] →
Γ ⋙ s ≊ₛ [ s , x ≔ ν x ▶ s ] ∷ [ Δ , x ∷ A ]
conv₈≊ₛ : ∀ {Γ Δ A s t x} {{_ : T (fresh x Δ)}} →
Γ ⋙ s ∷ Δ → Δ ⊢ t ∷ A →
Γ ⋙ [ s , x ≔ t ] ≊ₛ s ∷ Δ
conv₉≊ₛ : ∀ {Γ Δ s} →
Γ ⋙ s ∷ Δ →
Γ ⋙ [] ● s ≊ₛ s ∷ Δ
-- It is straightforward to prove that if two terms (substitutions) are convertible with each
-- other, then they are also well-typed.
-- TODO: What to do about the above paragraph?
| 36.745
| 101
| 0.375289
|
589bdf404b3e25092d7e0e15ffd11deb9d7e3d91
| 3,678
|
agda
|
Agda
|
fracGC/PiPointed.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 14
|
2015-08-18T21:40:15.000Z
|
2021-05-05T01:07:57.000Z
|
fracGC/PiPointed.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 4
|
2018-06-07T16:27:41.000Z
|
2021-10-29T20:41:23.000Z
|
fracGC/PiPointed.agda
|
JacquesCarette/pi-dual
|
003835484facfde0b770bc2b3d781b42b76184c1
|
[
"BSD-2-Clause"
] | 3
|
2016-05-29T01:56:33.000Z
|
2019-09-10T09:47:13.000Z
|
{-# OPTIONS --without-K --safe #-}
module PiPointed where
open import Data.Empty
open import Data.Unit
open import Data.Sum
open import Data.Product renaming (map to map×)
open import Relation.Binary.PropositionalEquality
open import Singleton
open import PlainPi
infixr 90 _#_
------------------------------------------------------------------------------
-- Pointed types and singleton types
data ∙𝕌 : Set where
_#_ : (t : 𝕌) → (v : ⟦ t ⟧) → ∙𝕌
_∙×ᵤ_ : ∙𝕌 → ∙𝕌 → ∙𝕌
_∙+ᵤl_ : ∙𝕌 → ∙𝕌 → ∙𝕌
_∙+ᵤr_ : ∙𝕌 → ∙𝕌 → ∙𝕌
Singᵤ : ∙𝕌 → ∙𝕌
∙⟦_⟧ : ∙𝕌 → Σ[ A ∈ Set ] A
∙⟦ t # v ⟧ = ⟦ t ⟧ , v
∙⟦ T₁ ∙×ᵤ T₂ ⟧ = zip _×_ _,_ ∙⟦ T₁ ⟧ ∙⟦ T₂ ⟧
∙⟦ T₁ ∙+ᵤl T₂ ⟧ = zip _⊎_ (λ x _ → inj₁ x) ∙⟦ T₁ ⟧ ∙⟦ T₂ ⟧
∙⟦ T₁ ∙+ᵤr T₂ ⟧ = zip _⊎_ (λ _ y → inj₂ y) ∙⟦ T₁ ⟧ ∙⟦ T₂ ⟧
∙⟦ Singᵤ T ⟧ = < uncurry Singleton , (λ y → proj₂ y , refl) > ∙⟦ T ⟧
data _∙⟶_ : ∙𝕌 → ∙𝕌 → Set where
∙c : {t₁ t₂ : 𝕌} {v : ⟦ t₁ ⟧} → (c : t₁ ⟷ t₂) →
t₁ # v ∙⟶ t₂ # (eval c v)
∙id⟷ : {T : ∙𝕌} → T ∙⟶ T
_∙⊚_ : {T₁ T₂ T₃ : ∙𝕌} → (T₁ ∙⟶ T₂) → (T₂ ∙⟶ T₃) → (T₁ ∙⟶ T₃)
∙Singᵤ : (T₁ T₂ : ∙𝕌) → (T₁ ∙⟶ T₂) → (Singᵤ T₁ ∙⟶ Singᵤ T₂)
-- monad
return : (T : ∙𝕌) → T ∙⟶ Singᵤ T
join : (T : ∙𝕌) → Singᵤ (Singᵤ T) ∙⟶ Singᵤ T
tensorl : (T₁ T₂ : ∙𝕌) → (Singᵤ T₁ ∙×ᵤ T₂) ∙⟶ Singᵤ (T₁ ∙×ᵤ T₂)
tensorr : (T₁ T₂ : ∙𝕌) → (T₁ ∙×ᵤ Singᵤ T₂) ∙⟶ Singᵤ (T₁ ∙×ᵤ T₂)
tensor : (T₁ T₂ : ∙𝕌) → (Singᵤ T₁ ∙×ᵤ Singᵤ T₂) ∙⟶ Singᵤ (T₁ ∙×ᵤ T₂)
untensor : (T₁ T₂ : ∙𝕌) → Singᵤ (T₁ ∙×ᵤ T₂) ∙⟶ (Singᵤ T₁ ∙×ᵤ Singᵤ T₂)
plusl : (T₁ T₂ : ∙𝕌) → (Singᵤ T₁ ∙+ᵤl T₂) ∙⟶ Singᵤ (T₁ ∙+ᵤl T₂)
plusr : (T₁ T₂ : ∙𝕌) → (T₁ ∙+ᵤr Singᵤ T₂) ∙⟶ Singᵤ (T₁ ∙+ᵤr T₂)
-- plus : (T₁ T₂ : ∙𝕌) → (Singᵤ T₁ ∙+ᵤl Singᵤ T₂) ∙⟶ Singᵤ (T₁ ∙+ᵤl T₂) -- lobsided, feels wrong
-- comonad
extract : (T : ∙𝕌) → Singᵤ T ∙⟶ T
duplicate : (T : ∙𝕌) → Singᵤ T ∙⟶ Singᵤ (Singᵤ T)
cotensorl : (T₁ T₂ : ∙𝕌) → Singᵤ (T₁ ∙×ᵤ T₂) ∙⟶ (Singᵤ T₁ ∙×ᵤ T₂)
cotensorr : (T₁ T₂ : ∙𝕌) → Singᵤ (T₁ ∙×ᵤ T₂) ∙⟶ (T₁ ∙×ᵤ Singᵤ T₂)
coplusl : (T₁ T₂ : ∙𝕌) → Singᵤ (T₁ ∙+ᵤl T₂) ∙⟶ (Singᵤ T₁ ∙+ᵤl T₂)
coplusr : (T₁ T₂ : ∙𝕌) → Singᵤ (T₁ ∙+ᵤr T₂) ∙⟶ (T₁ ∙+ᵤr Singᵤ T₂)
∙eval : {T₁ T₂ : ∙𝕌} → (C : T₁ ∙⟶ T₂) →
let (t₁ , v₁) = ∙⟦ T₁ ⟧
(t₂ , v₂) = ∙⟦ T₂ ⟧
in Σ (t₁ → t₂) (λ f → f v₁ ≡ v₂)
∙eval ∙id⟷ = (λ x → x) , refl
∙eval (∙c c) = eval c , refl
∙eval (C₁ ∙⊚ C₂) with ∙eval C₁ | ∙eval C₂
... | (f , p) | (g , q) = (λ x → g (f x)) , trans (cong g p) q
∙eval (∙Singᵤ T₁ T₂ C) with ∙⟦ T₁ ⟧ | ∙⟦ T₂ ⟧ | ∙eval C
... | t₁ , v₁ | t₂ , .(f v₁) | f , refl = (λ {(x , refl) → f x , refl}) , refl
∙eval (return T) = (λ _ → proj₂ ∙⟦ T ⟧ , refl) , refl
∙eval (join T) = (λ { (._ , refl) → (proj₂ ∙⟦ T ⟧) , refl} ) , refl
∙eval (tensorl T₁ T₂) = (λ {_ → (proj₂ ∙⟦ T₁ ⟧ , proj₂ ∙⟦ T₂ ⟧) , refl}) , refl
∙eval (tensorr T₁ T₂) = (λ {_ → (proj₂ ∙⟦ T₁ ⟧ , proj₂ ∙⟦ T₂ ⟧) , refl}) , refl
∙eval (tensor T₁ T₂) = (λ {_ → (proj₂ ∙⟦ T₁ ⟧ , proj₂ ∙⟦ T₂ ⟧) , refl}) , refl
∙eval (untensor T₁ T₂) = (λ _ → ((proj₂ ∙⟦ T₁ ⟧ , refl) , (proj₂ ∙⟦ T₂ ⟧ , refl))) , refl
∙eval (plusl T₁ T₂) = (λ _ → inj₁ (proj₂ ∙⟦ T₁ ⟧) , refl) , refl
∙eval (plusr T₁ T₂) = (λ _ → inj₂ (proj₂ ∙⟦ T₂ ⟧) , refl) , refl
-- ∙eval (plus T₁ T₂) with ∙⟦ T₁ ⟧ | ∙⟦ T₂ ⟧
-- ... | t₁ , v₁ | t₂ , v₂ = (λ _ → inj₁ v₁ , refl) , refl
∙eval (extract T) = (λ {(w , refl) → w}) , refl
∙eval (duplicate T) = (λ {(w , refl) → (w , refl) , refl}) , refl
∙eval (cotensorl T₁ T₂) = (λ _ → ((proj₂ ∙⟦ T₁ ⟧ , refl) , proj₂ ∙⟦ T₂ ⟧)) , refl
∙eval (cotensorr T₁ T₂) = (λ _ → (proj₂ ∙⟦ T₁ ⟧ , (proj₂ ∙⟦ T₂ ⟧) , refl)) , refl
∙eval (coplusl T₁ T₂) = (λ _ → inj₁ (proj₂ ∙⟦ T₁ ⟧ , refl)) , refl
∙eval (coplusr T₁ T₂) = (λ _ → inj₂ (proj₂ ∙⟦ T₂ ⟧ , refl)) , refl
-----------------------------------------------------------------------------
| 43.270588
| 102
| 0.461936
|
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.